@vmz/plugin-shiki 0.3.14 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Shiki.vmz +9 -2
- package/dist/runtime.d.ts +11 -2
- package/dist/runtime.js +16 -3
- package/package.json +3 -3
package/components/Shiki.vmz
CHANGED
|
@@ -9,11 +9,18 @@ export default class Shiki {
|
|
|
9
9
|
public lang: string = "text";
|
|
10
10
|
public theme: string = "vitesse-dark";
|
|
11
11
|
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* `null` means "no client payload": the sync path only fills it on the
|
|
14
|
+
* server (or after prewarm). Keeping it null lets the resumed host keep the
|
|
15
|
+
* SSR payload instead of replacing tokenized markup with a fallback shell.
|
|
16
|
+
*/
|
|
13
17
|
html: string | null = null;
|
|
14
18
|
|
|
15
19
|
async onMount() {
|
|
16
|
-
|
|
20
|
+
const next = await highlight(this.code, this.lang, this.theme);
|
|
21
|
+
// A degraded payload must not replace the server's tokenized markup:
|
|
22
|
+
// only an actual highlight is an improvement over what SSR wrote.
|
|
23
|
+
if (!next.includes('shiki-fallback')) this.html = next;
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
</script>
|
package/dist/runtime.d.ts
CHANGED
|
@@ -39,8 +39,17 @@ export declare function prewarmShiki(opts?: {
|
|
|
39
39
|
themes?: string[];
|
|
40
40
|
}): Promise<CodeHighlighter>;
|
|
41
41
|
export declare function highlight(code: string, lang?: string, theme?: string | null): Promise<string>;
|
|
42
|
-
/**
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Sync highlight when the runtime is prewarmed.
|
|
44
|
+
*
|
|
45
|
+
* `null` means "this runtime has no payload for this language yet". The server
|
|
46
|
+
* never has a better source than one it cannot resolve, so it degrades to the
|
|
47
|
+
* escaped shell. A browser with a cold cache (or a grammar the shipped generic
|
|
48
|
+
* path cannot resolve) must not invent one: the host may already hold the
|
|
49
|
+
* server's tokenized payload, and replacing it with an un-tokenized shell
|
|
50
|
+
* throws that payload away.
|
|
51
|
+
*/
|
|
52
|
+
export declare function highlightSync(code: string, lang?: string, theme?: string | null): string | null;
|
|
44
53
|
/**
|
|
45
54
|
* Inline-structure sync highlight for embedders that own the `<pre>` chrome
|
|
46
55
|
* (markdown-it fence callback in the document pipeline). Returns the token
|
package/dist/runtime.js
CHANGED
|
@@ -218,10 +218,19 @@ export async function highlight(code, lang = 'text', theme = DEFAULT_THEME) {
|
|
|
218
218
|
return fallbackPre(code);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* Sync highlight when the runtime is prewarmed.
|
|
223
|
+
*
|
|
224
|
+
* `null` means "this runtime has no payload for this language yet". The server
|
|
225
|
+
* never has a better source than one it cannot resolve, so it degrades to the
|
|
226
|
+
* escaped shell. A browser with a cold cache (or a grammar the shipped generic
|
|
227
|
+
* path cannot resolve) must not invent one: the host may already hold the
|
|
228
|
+
* server's tokenized payload, and replacing it with an un-tokenized shell
|
|
229
|
+
* throws that payload away.
|
|
230
|
+
*/
|
|
222
231
|
export function highlightSync(code, lang = 'text', theme = DEFAULT_THEME) {
|
|
223
232
|
if (!cached)
|
|
224
|
-
return fallbackPre(code);
|
|
233
|
+
return isServerRuntime() ? fallbackPre(code) : null;
|
|
225
234
|
try {
|
|
226
235
|
return cached.codeToHtml(code ?? '', {
|
|
227
236
|
lang: normalizeLang(lang),
|
|
@@ -230,9 +239,13 @@ export function highlightSync(code, lang = 'text', theme = DEFAULT_THEME) {
|
|
|
230
239
|
});
|
|
231
240
|
}
|
|
232
241
|
catch {
|
|
233
|
-
return fallbackPre(code);
|
|
242
|
+
return isServerRuntime() ? fallbackPre(code) : null;
|
|
234
243
|
}
|
|
235
244
|
}
|
|
245
|
+
/** No `document` means the serialize path (SSR) — see {@link highlightSync}. */
|
|
246
|
+
function isServerRuntime() {
|
|
247
|
+
return typeof document === 'undefined';
|
|
248
|
+
}
|
|
236
249
|
/**
|
|
237
250
|
* Inline-structure sync highlight for embedders that own the `<pre>` chrome
|
|
238
251
|
* (markdown-it fence callback in the document pipeline). Returns the token
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@vmz/plugin": "0.3.
|
|
3
|
+
"@vmz/plugin": "0.3.15"
|
|
4
4
|
},
|
|
5
5
|
"description": "VMZ Shiki adapter - <Shiki> + code engine registration",
|
|
6
6
|
"devDependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@types/node": "^22.15.0",
|
|
10
10
|
"shiki": "^3.12.2",
|
|
11
11
|
"typescript": "^5.8.3",
|
|
12
|
-
"vmz-textmate": "0.3.
|
|
12
|
+
"vmz-textmate": "0.3.15"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=24.12.0"
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
},
|
|
57
57
|
"type": "module",
|
|
58
58
|
"types": "./dist/vmz.plugin.d.ts",
|
|
59
|
-
"version": "0.3.
|
|
59
|
+
"version": "0.3.15"
|
|
60
60
|
}
|