Skip to content

Commit f0a092f

Browse files
committed
fix: svg style bug in @regexper/render
@regexper/render use a stylesheet in svg that cause bugs in whole site. So add regexper in a shadow root
1 parent 3993c8b commit f0a092f

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"@tiptap/pm": "2.1.6",
4343
"@tiptap/starter-kit": "2.1.6",
4444
"@tiptap/vue-3": "2.0.3",
45-
"@types/markdown-it": "^13.0.7",
4645
"@types/figlet": "^1.5.8",
46+
"@types/markdown-it": "^13.0.7",
4747
"@vicons/material": "^0.12.0",
4848
"@vicons/tabler": "^0.12.0",
4949
"@vueuse/core": "^10.3.0",
@@ -95,6 +95,7 @@
9595
"vue": "^3.3.4",
9696
"vue-i18n": "^9.9.1",
9797
"vue-router": "^4.1.6",
98+
"vue-shadow-dom": "^4.2.0",
9899
"vue-tsc": "^1.8.1",
99100
"xml-formatter": "^3.3.2",
100101
"xml-js": "^1.6.11",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createPinia } from 'pinia';
33
import { createHead } from '@vueuse/head';
44

55
import { registerSW } from 'virtual:pwa-register';
6+
import shadow from 'vue-shadow-dom';
67
import { plausible } from './plugins/plausible.plugin';
78

89
import 'virtual:uno.css';
@@ -23,5 +24,6 @@ app.use(i18nPlugin);
2324
app.use(router);
2425
app.use(naive);
2526
app.use(plausible);
27+
app.use(shadow);
2628

2729
app.mount('#app');

src/tools/regex-tester/regex-tester.vue

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import RandExp from 'randexp';
33
import { render } from '@regexper/render';
4+
import type { ShadowRootExpose } from 'vue-shadow-dom';
45
import { matchRegex } from './regex-tester.service';
56
import { useValidation } from '@/composable/validation';
67
import { useQueryParamOrStorage } from '@/composable/queryParams';
@@ -13,7 +14,7 @@ const multiline = ref(false);
1314
const dotAll = ref(true);
1415
const unicode = ref(true);
1516
const unicodeSets = ref(false);
16-
const visualizerSVG = ref() as Ref<SVGSVGElement>;
17+
const visualizerSVG = ref<ShadowRootExpose>();
1718
1819
const regexValidation = useValidation({
1920
source: regex,
@@ -70,12 +71,20 @@ const sample = computed(() => {
7071
watchEffect(
7172
async () => {
7273
const regexValue = regex.value;
73-
const svg = visualizerSVG.value;
74-
svg.childNodes.forEach(n => n.remove());
75-
try {
76-
await render(regexValue, svg);
77-
}
78-
catch (_) {
74+
// shadow root is required:
75+
// @regexper/render append a <defs><style> that broke svg transparency of icons in the whole site
76+
const visualizer = visualizerSVG.value?.shadow_root;
77+
if (visualizer) {
78+
while (visualizer.lastChild) {
79+
visualizer.removeChild(visualizer.lastChild);
80+
}
81+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
82+
try {
83+
await render(regexValue, svg);
84+
}
85+
catch (_) {
86+
}
87+
visualizer.appendChild(svg);
7988
}
8089
},
8190
);
@@ -176,7 +185,9 @@ watchEffect(
176185
</c-card>
177186

178187
<c-card title="Regex Diagram" style="overflow-x: scroll;" mt-3>
179-
<svg ref="visualizerSVG" />
188+
<shadow-root ref="visualizerSVG">
189+
&#xa0;
190+
</shadow-root>
180191
</c-card>
181192
</div>
182193
</template>

0 commit comments

Comments
 (0)