@@ -11,20 +11,42 @@ if (typeof window !== "undefined") {
11
11
}
12
12
import type { Theme } from "vitepress"
13
13
import DefaultTheme from "vitepress/theme"
14
- // @ts -expect-error -- ignore
15
14
import Layout from "./Layout.vue"
16
- // @ts -expect-error -- ignore
17
- import ESLintCodeBlock from "./components/eslint-code-block.vue"
18
- // @ts -expect-error -- ignore
19
- import PlaygroundBlock from "./components/playground-block.vue"
20
15
21
16
const theme : Theme = {
22
17
...DefaultTheme ,
23
18
Layout,
24
- enhanceApp ( ctx ) {
19
+ async enhanceApp ( ctx ) {
25
20
DefaultTheme . enhanceApp ( ctx )
21
+
22
+ if ( typeof Intl . Segmenter === "undefined" ) {
23
+ await setupIntlSegmenter ( )
24
+ }
25
+
26
+ const ESLintCodeBlock = await import (
27
+ "./components/eslint-code-block.vue"
28
+ ) . then ( ( m ) => m . default ?? m )
29
+ const PlaygroundBlock = await import (
30
+ "./components/playground-block.vue"
31
+ ) . then ( ( m ) => m . default ?? m )
26
32
ctx . app . component ( "eslint-code-block" , ESLintCodeBlock )
27
33
ctx . app . component ( "playground-block" , PlaygroundBlock )
28
34
} ,
29
35
}
30
36
export default theme
37
+
38
+ // We can remove this polyfill once Firefox supports Intl.Segmenter.
39
+ async function setupIntlSegmenter ( ) {
40
+ // For Firefox
41
+ const [ { createIntlSegmenterPolyfill } , breakIteratorUrl ] =
42
+ await Promise . all ( [
43
+ import ( "intl-segmenter-polyfill" ) ,
44
+ import (
45
+ // @ts -expect-error -- polyfill
46
+ "intl-segmenter-polyfill/dist/break_iterator.wasm?url"
47
+ ) . then ( ( m ) => m . default ?? m ) ,
48
+ ] )
49
+
50
+ // @ts -expect-error -- polyfill
51
+ Intl . Segmenter = await createIntlSegmenterPolyfill ( fetch ( breakIteratorUrl ) )
52
+ }
0 commit comments