@stacksjs/stx 0.2.286 → 0.2.288
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/dist/builtins/index.d.ts +4 -3
- package/dist/builtins/index.js +11 -11
- package/dist/{chunk-3bv8h4r6.js → chunk-02af607x.js} +1 -1
- package/dist/chunk-06706a9a.js +2 -0
- package/dist/chunk-0896td83.js +2 -0
- package/dist/chunk-08yja60e.js +2 -0
- package/dist/{chunk-e2w23g2r.js → chunk-13tawjw8.js} +10 -10
- package/dist/{chunk-zn5jgmqw.js → chunk-1e83cj7k.js} +1 -1
- package/dist/chunk-1g6pvs7k.js +11 -0
- package/dist/chunk-1gvebxh4.js +2 -0
- package/dist/{chunk-jbfpc4z7.js → chunk-1t9g3mhg.js} +2 -2
- package/dist/{chunk-0f1kz0x2.js → chunk-2e6xafcm.js} +1 -1
- package/dist/chunk-2rfxs7zm.js +2 -0
- package/dist/{chunk-sskbegsz.js → chunk-2vza9m2x.js} +1 -1
- package/dist/{chunk-pbk8jxe2.js → chunk-2wtn443n.js} +1 -1
- package/dist/{chunk-6cye5m9f.js → chunk-34qkshwh.js} +2 -2
- package/dist/{chunk-2g9jwgs7.js → chunk-3br3pt6k.js} +1 -1
- package/dist/{chunk-kmhr1z0m.js → chunk-3p0n9ryv.js} +1 -1
- package/dist/chunk-437n7hyx.js +2 -0
- package/dist/{chunk-ayrjwkyw.js → chunk-461br5nn.js} +1 -1
- package/dist/chunk-4tr92e0v.js +2 -0
- package/dist/{chunk-t6nseeb9.js → chunk-4vpsvh6x.js} +1 -1
- package/dist/{chunk-nh21517m.js → chunk-5j9tvhpq.js} +2 -2
- package/dist/{chunk-mb518a4n.js → chunk-5yp3vt00.js} +1 -1
- package/dist/{chunk-e4hhz9j3.js → chunk-5zcg61j9.js} +2 -2
- package/dist/{chunk-snknv47x.js → chunk-6085vha7.js} +1 -1
- package/dist/{chunk-9th1wd1d.js → chunk-72c7gyqc.js} +3 -3
- package/dist/chunk-811cxzn4.js +2 -0
- package/dist/{chunk-bz2gytfs.js → chunk-8883pgj8.js} +1 -1
- package/dist/{chunk-vqxmxgaj.js → chunk-8bxtvsgm.js} +1 -1
- package/dist/{chunk-a63y3aa0.js → chunk-8daczchh.js} +1 -1
- package/dist/chunk-91ffbzmh.js +2 -0
- package/dist/chunk-96cqevhm.js +2 -0
- package/dist/chunk-978faewt.js +2 -0
- package/dist/{chunk-g3fy0tw8.js → chunk-9veqmqb6.js} +154 -48
- package/dist/{chunk-7q9mwh4v.js → chunk-a668m28h.js} +1 -1
- package/dist/{chunk-xg57nax9.js → chunk-a9fxxwrv.js} +2 -2
- package/dist/chunk-adkjxvy6.js +2 -0
- package/dist/{chunk-a2qghr2x.js → chunk-agx0620p.js} +1 -1
- package/dist/chunk-ak06mywr.js +2 -0
- package/dist/chunk-ayaz0wcj.js +2 -0
- package/dist/{chunk-ah4e6e09.js → chunk-bphx7ngb.js} +2 -2
- package/dist/chunk-bw48gj8j.js +2 -0
- package/dist/{chunk-7rxtra1g.js → chunk-byq2xpgb.js} +1 -1
- package/dist/chunk-bzsjhyet.js +2 -0
- package/dist/{chunk-rhs51nmz.js → chunk-ch31zddx.js} +2 -2
- package/dist/chunk-cqzqfm7m.js +2 -0
- package/dist/{chunk-9zndrzb3.js → chunk-d0f60jrg.js} +2 -2
- package/dist/{chunk-c0an64km.js → chunk-dcxtrqfy.js} +1 -1
- package/dist/{chunk-bf8wf3r2.js → chunk-drbbt69f.js} +35 -10
- package/dist/chunk-e0aybavh.js +2 -0
- package/dist/chunk-e63a220e.js +28 -0
- package/dist/chunk-e67w1bge.js +2 -0
- package/dist/chunk-e7kd0ny8.js +2 -0
- package/dist/{chunk-y8n174xq.js → chunk-ee2tfpec.js} +2 -2
- package/dist/{chunk-9n0gvfrg.js → chunk-efr3ejqt.js} +1 -1
- package/dist/chunk-evfct6hb.js +2 -0
- package/dist/{chunk-kzyhvrp8.js → chunk-favq46aa.js} +1 -1
- package/dist/{chunk-0fgcnv6y.js → chunk-fcfphfpw.js} +2 -2
- package/dist/{chunk-w95sp0k9.js → chunk-fed3xsp9.js} +2 -2
- package/dist/{chunk-e7jfpyqy.js → chunk-ffmtamm2.js} +1 -1
- package/dist/{chunk-39f40yc4.js → chunk-fv923f7g.js} +1 -1
- package/dist/{chunk-jr3jp3ev.js → chunk-fvh9ca47.js} +1 -1
- package/dist/chunk-fxk9j0rm.js +2 -0
- package/dist/{chunk-fskfes13.js → chunk-gy933rct.js} +1 -1
- package/dist/{chunk-f3hfk78e.js → chunk-h61qt916.js} +1 -1
- package/dist/{chunk-c6fw33zh.js → chunk-h7v70dbp.js} +2 -2
- package/dist/{chunk-bz820epz.js → chunk-hmf9z4jx.js} +1 -1
- package/dist/{chunk-j9g11dzx.js → chunk-hqh7x9h5.js} +2 -2
- package/dist/{chunk-hs0387tm.js → chunk-hv5v6vc2.js} +2 -2
- package/dist/{chunk-xttsqmkm.js → chunk-jem20v5k.js} +1 -1
- package/dist/{chunk-t1k5dpbr.js → chunk-jj6yp7gm.js} +1 -1
- package/dist/{chunk-90qr4f9m.js → chunk-jv91rkhx.js} +1 -1
- package/dist/{chunk-qbeffw17.js → chunk-jyc9eha6.js} +1 -1
- package/dist/{chunk-w3ycm4na.js → chunk-k0y7ta0d.js} +1 -1
- package/dist/chunk-k4jt9t4p.js +2 -0
- package/dist/{chunk-9y0g8kzt.js → chunk-k70fgb2f.js} +1 -1
- package/dist/{chunk-74cv4ta1.js → chunk-k78gvm0g.js} +1 -1
- package/dist/{chunk-jn6m8zf7.js → chunk-kb5j08tq.js} +1 -1
- package/dist/{chunk-a54n1r1q.js → chunk-kf8t2wq7.js} +1 -1
- package/dist/chunk-kfy1jh6p.js +2 -0
- package/dist/chunk-kws4rewx.js +17 -0
- package/dist/{chunk-s67mgegv.js → chunk-mc58fhgm.js} +1 -1
- package/dist/{chunk-n3ggrhb3.js → chunk-mjpqz66q.js} +1 -1
- package/dist/{chunk-mjkfc2v6.js → chunk-mmnqd035.js} +1 -1
- package/dist/{chunk-54st8g2j.js → chunk-mywp77gt.js} +1 -1
- package/dist/{chunk-p396xrew.js → chunk-n0j85038.js} +1 -1
- package/dist/{chunk-gjemavhx.js → chunk-n5y9gh1q.js} +1 -1
- package/dist/{chunk-qd8ggjdx.js → chunk-n9kk3jz1.js} +1 -1
- package/dist/{chunk-49kk0s96.js → chunk-nmkra8q5.js} +2 -2
- package/dist/{chunk-s2284nbk.js → chunk-np5dc1q1.js} +1 -1
- package/dist/chunk-nygtwffe.js +5 -0
- package/dist/{chunk-y6kw0wb7.js → chunk-p0zq5ckb.js} +1 -1
- package/dist/chunk-pb16azfa.js +4 -0
- package/dist/{chunk-nx5qkm8k.js → chunk-ps20v1ah.js} +1 -1
- package/dist/chunk-pv9apyrr.js +2 -0
- package/dist/chunk-qj2s3r1w.js +3756 -0
- package/dist/chunk-qjkzpd68.js +11 -0
- package/dist/chunk-qww39be9.js +2 -0
- package/dist/chunk-r90w3x6h.js +2 -0
- package/dist/chunk-rb87b7kr.js +2 -0
- package/dist/{chunk-an2539bs.js → chunk-rjqfa3g8.js} +2 -2
- package/dist/{chunk-2q630fj4.js → chunk-sag55qv7.js} +1 -1
- package/dist/chunk-srcbkg7g.js +2 -0
- package/dist/chunk-sxderfaa.js +12 -0
- package/dist/{chunk-ysnk7x79.js → chunk-t5c7rk0h.js} +1 -1
- package/dist/chunk-v2z3creg.js +2 -0
- package/dist/chunk-vtjfv7kg.js +2 -0
- package/dist/{chunk-5aq35j2e.js → chunk-vvqe2gaz.js} +2 -2
- package/dist/{chunk-s7pc68jf.js → chunk-vwzqg4fh.js} +2 -2
- package/dist/{chunk-7p9ns60j.js → chunk-vxxxczmn.js} +1 -1
- package/dist/chunk-vzzkhjw7.js +2 -0
- package/dist/{chunk-wcm80anz.js → chunk-wvq1g6gr.js} +1 -1
- package/dist/{chunk-y7m2dpd3.js → chunk-wyxw61az.js} +1 -1
- package/dist/{chunk-kdrpx9ft.js → chunk-xpct12p7.js} +1 -1
- package/dist/chunk-xvndd7h6.js +2 -0
- package/dist/{chunk-d0c3v7ax.js → chunk-y5jjrnfa.js} +1 -1
- package/dist/{chunk-vbdca0k1.js → chunk-ym4ggcpy.js} +1 -1
- package/dist/{chunk-q68xmak4.js → chunk-ymc99r5x.js} +18 -18
- package/dist/{chunk-refwkt87.js → chunk-ynt7y2n5.js} +1 -1
- package/dist/chunk-z6azwfb4.js +2 -0
- package/dist/chunk-zfnabevq.js +2 -0
- package/dist/{chunk-cvnh7dma.js → chunk-zqwmy0av.js} +1 -1
- package/dist/{chunk-phhzfeh9.js → chunk-zvw2qgwt.js} +1 -1
- package/dist/cli.js +14 -14
- package/dist/client-module-registry.d.ts +36 -0
- package/dist/client-module-registry.js +55 -0
- package/dist/client-script-bundler.d.ts +39 -0
- package/dist/client-script-bundler.js +89 -12
- package/dist/client-script.js +15 -8
- package/dist/component-client-factories.js +10 -5
- package/dist/component-processing.d.ts +13 -0
- package/dist/component-processing.js +37 -1
- package/dist/component-renderer.js +34 -15
- package/dist/conditionals.js +14 -3
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/database.js +1 -1
- package/dist/document-shell.d.ts +1 -34
- package/dist/document-shell.js +19 -11
- package/dist/html-masking.d.ts +65 -9
- package/dist/html-masking.js +103 -15
- package/dist/misc-directives.d.ts +1 -1
- package/dist/misc-directives.js +48 -13
- package/dist/process.js +38 -7
- package/dist/pwa.js +2 -2
- package/dist/reactive-bindings.js +2 -0
- package/dist/runtime-globals.d.ts +7 -20
- package/dist/runtime-globals.js +28 -3
- package/dist/safe-evaluator.d.ts +15 -0
- package/dist/safe-evaluator.js +16 -12
- package/dist/server-bindings.js +21 -5
- package/dist/signal-processing.d.ts +17 -7
- package/dist/signal-processing.js +116 -46
- package/dist/signals-api.js +5 -2
- package/dist/signals.js +153 -47
- package/dist/ssg.js +2 -2
- package/dist/store-loader.js +1 -1
- package/dist/strip-literals.d.ts +20 -0
- package/dist/strip-literals.js +16 -0
- package/dist/utils.js +24 -7
- package/dist/variable-extractor.js +17 -47
- package/dist/visual-testing.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-3ehv1by2.js +0 -2
- package/dist/chunk-4cqgbcy7.js +0 -3756
- package/dist/chunk-52mh63sp.js +0 -11
- package/dist/chunk-56ywtaff.js +0 -2
- package/dist/chunk-61sj52qh.js +0 -2
- package/dist/chunk-7ej1d910.js +0 -2
- package/dist/chunk-829pcte9.js +0 -2
- package/dist/chunk-8emkx9ja.js +0 -2
- package/dist/chunk-ajbfeey7.js +0 -2
- package/dist/chunk-areethga.js +0 -2
- package/dist/chunk-b29wbjs5.js +0 -2
- package/dist/chunk-b7tjq91c.js +0 -2
- package/dist/chunk-ba6tthsm.js +0 -2
- package/dist/chunk-e4akvata.js +0 -2
- package/dist/chunk-f4k2a7vs.js +0 -2
- package/dist/chunk-f80wwn5x.js +0 -2
- package/dist/chunk-fjkstnz3.js +0 -2
- package/dist/chunk-j03bare5.js +0 -2
- package/dist/chunk-jg0axas8.js +0 -2
- package/dist/chunk-jrk8rhwt.js +0 -28
- package/dist/chunk-kawk5ve9.js +0 -2
- package/dist/chunk-m3yaa0v5.js +0 -15
- package/dist/chunk-m7xnzt2t.js +0 -2
- package/dist/chunk-mkn6qqc7.js +0 -2
- package/dist/chunk-n3jyv9z6.js +0 -2
- package/dist/chunk-nvgxjvnb.js +0 -2
- package/dist/chunk-qk8tbcwk.js +0 -2
- package/dist/chunk-qp97dx7x.js +0 -2
- package/dist/chunk-qsr3bqav.js +0 -12
- package/dist/chunk-vb10qph4.js +0 -2
- package/dist/chunk-vrvehb01.js +0 -2
- package/dist/chunk-vy8v5xdb.js +0 -2
- package/dist/chunk-w0sqz3cb.js +0 -11
- package/dist/chunk-w8smn72c.js +0 -2
- package/dist/chunk-wxk2pbrh.js +0 -2
- package/dist/chunk-x1nw1p8z.js +0 -2
- package/dist/chunk-xz55q3gr.js +0 -2
- package/dist/chunk-yq1d9hb3.js +0 -2
- package/dist/chunk-ytgnzeeb.js +0 -2
- package/dist/chunk-zfr4d08r.js +0 -2
package/dist/document-shell.d.ts
CHANGED
|
@@ -169,39 +169,6 @@ export declare function generateDocumentShell(content: string, headConfig?: AppH
|
|
|
169
169
|
*/
|
|
170
170
|
colorMode?: ColorModeBootConfig;
|
|
171
171
|
}): string;
|
|
172
|
-
/**
|
|
173
|
-
* Check if HTML already has a document shell (<!DOCTYPE> or <html>).
|
|
174
|
-
* Templates that extend layouts with document shells should not be
|
|
175
|
-
* double-wrapped — the visible artifact of a double-wrap is the user's
|
|
176
|
-
* `<title>` getting nested under the auto-shell's default `stx App`,
|
|
177
|
-
* which then wins for `document.title` because it appears first.
|
|
178
|
-
*
|
|
179
|
-
* The check is permissive on placement: if the rendered output contains
|
|
180
|
-
* a `<!DOCTYPE>` or `<html>` ANYWHERE, the user has supplied a shell.
|
|
181
|
-
* Earlier this only checked the leading bytes after stripping comments,
|
|
182
|
-
* but other directives (signals runtime, scoped scripts, theme guards)
|
|
183
|
-
* happily prepend their own `<script>` tags before any layout markup,
|
|
184
|
-
* which made the check spuriously fail and auto-shell wrap the user's
|
|
185
|
-
* complete HTML doc as if it were just body content.
|
|
186
|
-
*/
|
|
187
|
-
/**
|
|
188
|
-
* Does this string OPEN a full HTML document?
|
|
189
|
-
*
|
|
190
|
-
* Anchored, but tolerant of what stx's own pipeline prepends: whitespace, HTML
|
|
191
|
-
* comments, and `<script>` blocks (the signals runtime, scoped setup scripts,
|
|
192
|
-
* theme guards) all routinely land ahead of a layout's markup.
|
|
193
|
-
*
|
|
194
|
-
* The check used to be `/<!DOCTYPE\b/i` — unanchored — so the literal text
|
|
195
|
-
* `<!DOCTYPE` ANYWHERE made a fragment look like a document and sent it through
|
|
196
|
-
* wrapper-stripping. Easy to hit on any page that documents HTML: a doctype in
|
|
197
|
-
* a comment, in a `<pre><code>` sample, or in a JS string (stacksjs#1787). The
|
|
198
|
-
* `<html>` half was already anchored, so the asymmetry was clearly accidental.
|
|
199
|
-
*
|
|
200
|
-
* Note this is the opposite bias from `hasDocumentShell` in document-shell.ts,
|
|
201
|
-
* which stays permissive on purpose: there, a false negative double-wraps a
|
|
202
|
-
* complete document, so leaning towards "yes, it's a document" is the safe
|
|
203
|
-
* direction. Here a false positive shreds a fragment, so it leans the other way.
|
|
204
|
-
*/
|
|
205
172
|
export declare function startsDocument(html: string): boolean;
|
|
206
173
|
/**
|
|
207
174
|
* Does this output already carry a document wrapper?
|
|
@@ -248,4 +215,4 @@ export declare function injectConfigHeadTags(html: string, headConfig?: AppHeadC
|
|
|
248
215
|
* head here — the caller injects config-only head via `injectConfigHeadTags`,
|
|
249
216
|
* so runtime `useHead` tags aren't double-emitted).
|
|
250
217
|
*/
|
|
251
|
-
export declare function ensureDocumentShell(html: string, headConfig?: AppHeadConfig, options?: Parameters<typeof generateDocumentShell>[2]): string;
|
|
218
|
+
export declare function ensureDocumentShell(html: string, headConfig?: AppHeadConfig, options?: Parameters<typeof generateDocumentShell>[2], alreadyHasShell?: boolean): string;
|
package/dist/document-shell.js
CHANGED
|
@@ -259,30 +259,38 @@ ${bodyParts.join(`
|
|
|
259
259
|
</body>
|
|
260
260
|
</html>`;
|
|
261
261
|
}
|
|
262
|
+
const DOCUMENT_PREFIX_WHITESPACE = /\s+/y, DOCUMENT_PREFIX_PREAMBLE = /<(script|style)\b[^>]*>/iy, DOCUMENT_PREFIX_SCRIPT_CLOSE = /<\/script>/gi, DOCUMENT_PREFIX_STYLE_CLOSE = /<\/style>/gi, DOCUMENT_PREFIX_DOCTYPE = /<!DOCTYPE\b/iy, DOCUMENT_PREFIX_HTML = /<html[\s>]/iy;
|
|
262
263
|
export function startsDocument(html) {
|
|
263
264
|
let i = 0;
|
|
264
265
|
while (i < html.length) {
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
i
|
|
266
|
+
DOCUMENT_PREFIX_WHITESPACE.lastIndex = i;
|
|
267
|
+
if (DOCUMENT_PREFIX_WHITESPACE.exec(html)) {
|
|
268
|
+
i = DOCUMENT_PREFIX_WHITESPACE.lastIndex;
|
|
268
269
|
continue;
|
|
269
270
|
}
|
|
270
|
-
if (
|
|
271
|
+
if (html.startsWith("<!--", i)) {
|
|
271
272
|
const end = html.indexOf("-->", i);
|
|
272
273
|
if (end === -1)
|
|
273
274
|
return !1;
|
|
274
275
|
i = end + 3;
|
|
275
276
|
continue;
|
|
276
277
|
}
|
|
277
|
-
|
|
278
|
+
DOCUMENT_PREFIX_PREAMBLE.lastIndex = i;
|
|
279
|
+
const preamble = DOCUMENT_PREFIX_PREAMBLE.exec(html);
|
|
278
280
|
if (preamble) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
+
const close = preamble[1].toLowerCase() === "script" ? DOCUMENT_PREFIX_SCRIPT_CLOSE : DOCUMENT_PREFIX_STYLE_CLOSE;
|
|
282
|
+
close.lastIndex = DOCUMENT_PREFIX_PREAMBLE.lastIndex;
|
|
283
|
+
const end = close.exec(html);
|
|
284
|
+
if (end === null)
|
|
281
285
|
return !1;
|
|
282
|
-
i = end +
|
|
286
|
+
i = end.index + end[0].length;
|
|
283
287
|
continue;
|
|
284
288
|
}
|
|
285
|
-
|
|
289
|
+
DOCUMENT_PREFIX_DOCTYPE.lastIndex = i;
|
|
290
|
+
if (DOCUMENT_PREFIX_DOCTYPE.test(html))
|
|
291
|
+
return !0;
|
|
292
|
+
DOCUMENT_PREFIX_HTML.lastIndex = i;
|
|
293
|
+
return DOCUMENT_PREFIX_HTML.test(html);
|
|
286
294
|
}
|
|
287
295
|
return !1;
|
|
288
296
|
}
|
|
@@ -323,8 +331,8 @@ export function injectConfigHeadTags(html, headConfig = {}) {
|
|
|
323
331
|
`)}
|
|
324
332
|
${html.slice(headCloseIdx)}`;
|
|
325
333
|
}
|
|
326
|
-
export function ensureDocumentShell(html, headConfig = {}, options = {}) {
|
|
327
|
-
if (hasDocumentShell(html))
|
|
334
|
+
export function ensureDocumentShell(html, headConfig = {}, options = {}, alreadyHasShell) {
|
|
335
|
+
if (alreadyHasShell ?? hasDocumentShell(html))
|
|
328
336
|
return html;
|
|
329
337
|
return generateDocumentShell(html, headConfig, options);
|
|
330
338
|
}
|
package/dist/html-masking.d.ts
CHANGED
|
@@ -43,6 +43,36 @@ export declare function matchHtmlComment(html: string, i: number): number;
|
|
|
43
43
|
* callers never see tag-like text nested inside those regions.
|
|
44
44
|
*/
|
|
45
45
|
export declare function scanAtElementPosition(html: string, match: TokenMatcher): ElementPositionToken[];
|
|
46
|
+
/**
|
|
47
|
+
* Cheap, conservative preflight for the unresolved-expression cloak pass.
|
|
48
|
+
*
|
|
49
|
+
* A mustache in an element's own text needs at least two opening and two
|
|
50
|
+
* closing braces outside tags, comments, and script/style raw text. They may
|
|
51
|
+
* be separated by child elements, so looking only for contiguous `{{` is NOT
|
|
52
|
+
* sufficient. False positives merely run the normal cloak scan; false
|
|
53
|
+
* negatives would leave an unresolved expression visible.
|
|
54
|
+
*/
|
|
55
|
+
export declare function mightContainOwnTextMustache(html: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Drop the oldest entries until there is room for one more.
|
|
58
|
+
*
|
|
59
|
+
* Wholesale `clear()` was the first version and it made the caches useless: a
|
|
60
|
+
* render cycles through more distinct documents than the cap, so hitting the cap
|
|
61
|
+
* wiped the entry that was about to be reused. Measured on the #1945 fixture, one
|
|
62
|
+
* key-and-content pair missed 24 times in a row — computed every time, hit never.
|
|
63
|
+
* A Map iterates in insertion order, so the first key is the oldest.
|
|
64
|
+
*/
|
|
65
|
+
export declare function evictOldest(cache: Map<string, unknown>, maxEntries: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Drop cached mask results.
|
|
68
|
+
*
|
|
69
|
+
* Nothing in the framework calls this, and nothing needs to. Entries are keyed
|
|
70
|
+
* on the input document itself plus the caller's placeholder key, so an edited
|
|
71
|
+
* template is a different key and can never be answered with a stale result --
|
|
72
|
+
* there is no invalidation to perform. It exists for callers that want a cold
|
|
73
|
+
* cache, such as tests.
|
|
74
|
+
*/
|
|
75
|
+
export declare function clearMaskCache(): void;
|
|
46
76
|
/**
|
|
47
77
|
* Mask every token (per `match`) that begins at element position, replacing it
|
|
48
78
|
* with `placeholder(token, index)`. Returns the rewritten string plus the ordered
|
|
@@ -51,19 +81,45 @@ export declare function scanAtElementPosition(html: string, match: TokenMatcher)
|
|
|
51
81
|
* Note: HTML attributes do not use backslash escaping, so a `"`/`'` always
|
|
52
82
|
* toggles the surrounding quote — matching how browsers parse attribute values.
|
|
53
83
|
*/
|
|
54
|
-
export declare function maskAtElementPosition(html: string, match: TokenMatcher, placeholder: (token: string, index: number) => string
|
|
84
|
+
export declare function maskAtElementPosition(html: string, match: TokenMatcher, placeholder: (token: string, index: number) => string,
|
|
85
|
+
/**
|
|
86
|
+
* Opt in to memoisation. Must fully determine what `placeholder` returns for
|
|
87
|
+
* a given index — two calls sharing a key MUST be interchangeable.
|
|
88
|
+
*/
|
|
89
|
+
cacheKey?: string): {
|
|
55
90
|
output: string;
|
|
56
91
|
tokens: string[];
|
|
57
92
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* component scanner doesn't mis-resolve tag-like JS string literals (e.g.
|
|
61
|
-
* `div.innerHTML = '<v:shape>'`) as component references (stacksjs/stx#1730), and
|
|
62
|
-
* so an attribute-embedded `<script>` is never pulled out and restored unescaped.
|
|
63
|
-
*/
|
|
64
|
-
export declare function stashScriptElements(html: string): {
|
|
93
|
+
export interface StashedScripts {
|
|
94
|
+
/** The document with each `<script>` element replaced by a NUL sentinel. */
|
|
65
95
|
output: string;
|
|
96
|
+
/** The removed script elements, in placeholder order. */
|
|
66
97
|
scripts: string[];
|
|
67
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Put the scripts back.
|
|
100
|
+
*
|
|
101
|
+
* Returns the pre-stash document unchanged when `html` is still the masked
|
|
102
|
+
* output. Stashing replaces each script with a sentinel and restoring puts
|
|
103
|
+
* exactly those scripts back at exactly those sentinels, so when nothing
|
|
104
|
+
* edited the masked document in between, the replace pass can only rebuild,
|
|
105
|
+
* character by character, a string the caller already handed us.
|
|
106
|
+
*
|
|
107
|
+
* That is the common case, not a corner: one render of the #1945 fixture
|
|
108
|
+
* reaches this having changed nothing in FOUR of five passes, rebuilding
|
|
109
|
+
* 445,208 bytes to arrive back where it started. The component loop stashes
|
|
110
|
+
* on every pass but only the first pass resolves anything.
|
|
111
|
+
*/
|
|
112
|
+
restore: (html: string) => string;
|
|
113
|
+
}
|
|
114
|
+
export declare function stashScriptElements(html: string): StashedScripts;
|
|
115
|
+
/**
|
|
116
|
+
* Drop cached stash results.
|
|
117
|
+
*
|
|
118
|
+
* Nothing in the framework calls this, and nothing needs to. Entries are keyed
|
|
119
|
+
* on the input document itself, so an edited template is a different key and
|
|
120
|
+
* can never be answered with a stale result -- there is no invalidation to
|
|
121
|
+
* perform. It exists for callers that want a cold cache, such as tests.
|
|
122
|
+
*/
|
|
123
|
+
export declare function clearStashCache(): void;
|
|
68
124
|
/** Restore scripts stashed by {@link stashScriptElements}. */
|
|
69
125
|
export declare function restoreStashedScripts(html: string, scripts: string[]): string;
|
package/dist/html-masking.js
CHANGED
|
@@ -29,17 +29,17 @@ function matchOpaqueRegion(html, i) {
|
|
|
29
29
|
const end = matchHtmlComment(html, i);
|
|
30
30
|
return end === -1 ? html.length : end;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
return
|
|
32
|
+
SCRIPT_OPEN.lastIndex = i;
|
|
33
|
+
if (SCRIPT_OPEN.exec(html)?.index === i) {
|
|
34
|
+
SCRIPT_CLOSE.lastIndex = SCRIPT_OPEN.lastIndex;
|
|
35
|
+
const close = SCRIPT_CLOSE.exec(html);
|
|
36
|
+
return close ? close.index + close[0].length : html.length;
|
|
37
|
+
}
|
|
38
|
+
STYLE_OPEN.lastIndex = i;
|
|
39
|
+
if (STYLE_OPEN.exec(html)?.index === i) {
|
|
40
|
+
STYLE_CLOSE.lastIndex = STYLE_OPEN.lastIndex;
|
|
41
|
+
const close = STYLE_CLOSE.exec(html);
|
|
42
|
+
return close ? close.index + close[0].length : html.length;
|
|
43
43
|
}
|
|
44
44
|
return -1;
|
|
45
45
|
}
|
|
@@ -62,7 +62,10 @@ export function scanAtElementPosition(html, match) {
|
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
64
64
|
if (ch !== "<") {
|
|
65
|
-
i
|
|
65
|
+
const next = html.indexOf("<", i + 1);
|
|
66
|
+
if (next === -1)
|
|
67
|
+
break;
|
|
68
|
+
i = next;
|
|
66
69
|
continue;
|
|
67
70
|
}
|
|
68
71
|
const end = match(html, i);
|
|
@@ -76,13 +79,71 @@ export function scanAtElementPosition(html, match) {
|
|
|
76
79
|
i = opaqueEnd;
|
|
77
80
|
continue;
|
|
78
81
|
}
|
|
79
|
-
|
|
82
|
+
const letter = html.charCodeAt(i + 1);
|
|
83
|
+
if (letter >= 65 && letter <= 90 || letter >= 97 && letter <= 122)
|
|
80
84
|
inTag = !0;
|
|
81
85
|
i++;
|
|
82
86
|
}
|
|
83
87
|
return tokens;
|
|
84
88
|
}
|
|
85
|
-
export function
|
|
89
|
+
export function mightContainOwnTextMustache(html) {
|
|
90
|
+
let opening = 0, closing = 0, i = 0, inTag = !1, quote = null;
|
|
91
|
+
while (i < html.length) {
|
|
92
|
+
if (inTag) {
|
|
93
|
+
const ch = html[i];
|
|
94
|
+
if (quote) {
|
|
95
|
+
if (ch === quote)
|
|
96
|
+
quote = null;
|
|
97
|
+
} else if (ch === '"' || ch === "'")
|
|
98
|
+
quote = ch;
|
|
99
|
+
else if (ch === ">")
|
|
100
|
+
inTag = !1;
|
|
101
|
+
i++;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const lt = html.indexOf("<", i), textEnd = lt === -1 ? html.length : lt;
|
|
105
|
+
while (i < textEnd) {
|
|
106
|
+
const ch = html[i++];
|
|
107
|
+
if (ch === "{")
|
|
108
|
+
opening++;
|
|
109
|
+
else if (ch === "}")
|
|
110
|
+
closing++;
|
|
111
|
+
if (opening >= 2 && closing >= 2)
|
|
112
|
+
return !0;
|
|
113
|
+
}
|
|
114
|
+
if (lt === -1)
|
|
115
|
+
break;
|
|
116
|
+
const opaqueEnd = matchOpaqueRegion(html, lt);
|
|
117
|
+
if (opaqueEnd > lt) {
|
|
118
|
+
i = opaqueEnd;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const first = html.charCodeAt(lt + 1), letter = first === 47 ? html.charCodeAt(lt + 2) : first;
|
|
122
|
+
if (letter >= 65 && letter <= 90 || letter >= 97 && letter <= 122)
|
|
123
|
+
inTag = !0;
|
|
124
|
+
i = lt + 1;
|
|
125
|
+
}
|
|
126
|
+
return !1;
|
|
127
|
+
}
|
|
128
|
+
export function evictOldest(cache, maxEntries) {
|
|
129
|
+
while (cache.size >= maxEntries) {
|
|
130
|
+
const oldest = cache.keys().next();
|
|
131
|
+
if (oldest.done)
|
|
132
|
+
return;
|
|
133
|
+
cache.delete(oldest.value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const MASK_CACHE_MIN_BYTES = 65536, MASK_CACHE_MAX_ENTRIES = 12, maskCache = new Map;
|
|
137
|
+
export function clearMaskCache() {
|
|
138
|
+
maskCache.clear();
|
|
139
|
+
}
|
|
140
|
+
export function maskAtElementPosition(html, match, placeholder, cacheKey) {
|
|
141
|
+
const cacheable = cacheKey !== void 0 && html.length >= MASK_CACHE_MIN_BYTES, key = cacheable ? `${cacheKey}\x00${html}` : "";
|
|
142
|
+
if (cacheable) {
|
|
143
|
+
const hit = maskCache.get(key);
|
|
144
|
+
if (hit)
|
|
145
|
+
return { output: hit.output, tokens: hit.tokens.slice() };
|
|
146
|
+
}
|
|
86
147
|
const matches = scanAtElementPosition(html, match);
|
|
87
148
|
if (matches.length === 0)
|
|
88
149
|
return { output: html, tokens: [] };
|
|
@@ -95,11 +156,38 @@ export function maskAtElementPosition(html, match, placeholder) {
|
|
|
95
156
|
cursor = item.end;
|
|
96
157
|
}
|
|
97
158
|
output += html.slice(cursor);
|
|
159
|
+
if (cacheable) {
|
|
160
|
+
evictOldest(maskCache, MASK_CACHE_MAX_ENTRIES);
|
|
161
|
+
maskCache.set(key, { output, tokens });
|
|
162
|
+
return { output, tokens: tokens.slice() };
|
|
163
|
+
}
|
|
98
164
|
return { output, tokens };
|
|
99
165
|
}
|
|
166
|
+
const STASH_CACHE_MIN_BYTES = 65536, STASH_CACHE_MAX_ENTRIES = 4, stashCache = new Map;
|
|
167
|
+
function stashResult(input, output, scripts) {
|
|
168
|
+
return {
|
|
169
|
+
output,
|
|
170
|
+
scripts,
|
|
171
|
+
restore: (html) => html === output ? input : restoreStashedScripts(html, scripts)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
100
174
|
export function stashScriptElements(html) {
|
|
175
|
+
const cacheable = html.length >= STASH_CACHE_MIN_BYTES;
|
|
176
|
+
if (cacheable) {
|
|
177
|
+
const hit = stashCache.get(html);
|
|
178
|
+
if (hit)
|
|
179
|
+
return stashResult(html, hit.output, hit.scripts.slice());
|
|
180
|
+
}
|
|
101
181
|
const { output, tokens } = maskAtElementPosition(html, matchScriptElement, (_token, index) => `\x00STX_SCRIPT_${index}\x00`);
|
|
102
|
-
|
|
182
|
+
if (cacheable) {
|
|
183
|
+
evictOldest(stashCache, STASH_CACHE_MAX_ENTRIES);
|
|
184
|
+
stashCache.set(html, { output, scripts: tokens });
|
|
185
|
+
return stashResult(html, output, tokens.slice());
|
|
186
|
+
}
|
|
187
|
+
return stashResult(html, output, tokens);
|
|
188
|
+
}
|
|
189
|
+
export function clearStashCache() {
|
|
190
|
+
stashCache.clear();
|
|
103
191
|
}
|
|
104
192
|
export function restoreStashedScripts(html, scripts) {
|
|
105
193
|
if (scripts.length === 0)
|
|
@@ -48,7 +48,7 @@ export declare function processRefAttributes(template: string): string;
|
|
|
48
48
|
* so the raw mustache never flashes.
|
|
49
49
|
*
|
|
50
50
|
* Only the element that actually holds the expression is stamped — see
|
|
51
|
-
* `
|
|
51
|
+
* `ownTextContainsMustache` for why that scoping is the fix rather than a refinement. An
|
|
52
52
|
* element carrying `x-no-cloak` is left visible regardless.
|
|
53
53
|
*/
|
|
54
54
|
export declare function addCloakToUnresolvedExpressions(html: string): string;
|
package/dist/misc-directives.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { errorLogger } from "./error-handling.js";
|
|
2
|
+
import { mightContainOwnTextMustache } from "./html-masking.js";
|
|
2
3
|
import { createSafeFunction, isExpressionSafe } from "./safe-evaluator.js";
|
|
3
4
|
export function processJsonDirective(template, context) {
|
|
4
5
|
let result = template;
|
|
@@ -153,7 +154,13 @@ const VOID_TAGS = new Set([
|
|
|
153
154
|
"source",
|
|
154
155
|
"track",
|
|
155
156
|
"wbr"
|
|
156
|
-
]), NO_CLOAK_RE = /(?:^|\s)x-no-cloak(?:=|\s|\/|>|$)/;
|
|
157
|
+
]), NO_CLOAK_RE = /(?:^|\s)x-no-cloak(?:=|\s|\/|>|$)/, TAG_NAME_AT = /<\/?\s*([a-z][\w-]*)/iy, WHITESPACE = /\s/;
|
|
158
|
+
function isSelfClosingBefore(html, tagEnd) {
|
|
159
|
+
let j = tagEnd - 1;
|
|
160
|
+
while (j >= 0 && WHITESPACE.test(html[j]))
|
|
161
|
+
j--;
|
|
162
|
+
return j >= 0 && html[j] === "/";
|
|
163
|
+
}
|
|
157
164
|
function findTagEnd(html, from) {
|
|
158
165
|
let inSingleQuote = !1, inDoubleQuote = !1;
|
|
159
166
|
for (let i = from;i < html.length; i++) {
|
|
@@ -173,14 +180,40 @@ function findTagEnd(html, from) {
|
|
|
173
180
|
}
|
|
174
181
|
return -1;
|
|
175
182
|
}
|
|
176
|
-
function
|
|
177
|
-
|
|
183
|
+
function ownTextContainsMustache(html, contentStart) {
|
|
184
|
+
if (html.indexOf("{", contentStart) === -1 || html.indexOf("}", contentStart) === -1)
|
|
185
|
+
return !1;
|
|
186
|
+
let depth = 0, i = contentStart, openingBrace = !1, opened = !1, closingBrace = !1;
|
|
178
187
|
while (i < html.length) {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
188
|
+
const nextTag = html.indexOf("<", i), textEnd = nextTag === -1 ? html.length : nextTag;
|
|
189
|
+
if (textEnd > i) {
|
|
181
190
|
if (depth === 0)
|
|
182
|
-
|
|
183
|
-
|
|
191
|
+
while (i < textEnd) {
|
|
192
|
+
const brace = html.indexOf(opened ? "}" : "{", i);
|
|
193
|
+
if (brace === -1 || brace >= textEnd) {
|
|
194
|
+
if (opened)
|
|
195
|
+
closingBrace = !1;
|
|
196
|
+
else
|
|
197
|
+
openingBrace = !1;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (brace > i)
|
|
201
|
+
if (opened)
|
|
202
|
+
closingBrace = !1;
|
|
203
|
+
else
|
|
204
|
+
openingBrace = !1;
|
|
205
|
+
if (opened) {
|
|
206
|
+
if (closingBrace)
|
|
207
|
+
return !0;
|
|
208
|
+
closingBrace = !0;
|
|
209
|
+
} else if (openingBrace) {
|
|
210
|
+
opened = !0;
|
|
211
|
+
closingBrace = !1;
|
|
212
|
+
} else
|
|
213
|
+
openingBrace = !0;
|
|
214
|
+
i = brace + 1;
|
|
215
|
+
}
|
|
216
|
+
i = textEnd;
|
|
184
217
|
continue;
|
|
185
218
|
}
|
|
186
219
|
if (html.startsWith("<!--", i)) {
|
|
@@ -191,18 +224,21 @@ function ownText(html, contentStart) {
|
|
|
191
224
|
const tagEnd = findTagEnd(html, i);
|
|
192
225
|
if (tagEnd === -1)
|
|
193
226
|
break;
|
|
194
|
-
|
|
195
|
-
|
|
227
|
+
TAG_NAME_AT.lastIndex = i;
|
|
228
|
+
const name = TAG_NAME_AT.exec(html)?.[1]?.toLowerCase() ?? "";
|
|
229
|
+
if (html[i + 1] === "/") {
|
|
196
230
|
if (depth === 0)
|
|
197
231
|
break;
|
|
198
232
|
depth--;
|
|
199
|
-
} else if (
|
|
233
|
+
} else if (!isSelfClosingBefore(html, tagEnd) && !VOID_TAGS.has(name))
|
|
200
234
|
depth++;
|
|
201
235
|
i = tagEnd + 1;
|
|
202
236
|
}
|
|
203
|
-
return
|
|
237
|
+
return !1;
|
|
204
238
|
}
|
|
205
239
|
export function addCloakToUnresolvedExpressions(html) {
|
|
240
|
+
if (html.length >= 32768 && !mightContainOwnTextMustache(html))
|
|
241
|
+
return html;
|
|
206
242
|
const tagStartRe = new RegExp(`<(${"div|span|p|h[1-6]|td|th|li|a|button|label|section|article|header|footer|main|nav|aside|dd|dt|figcaption|summary|caption|blockquote|pre|code|em|strong|small|sub|sup|time|mark|abbr|cite|q|s|u|b|i"})\\b`, "gi");
|
|
207
243
|
let result = "", lastIndex = 0, tagMatch;
|
|
208
244
|
while ((tagMatch = tagStartRe.exec(html)) !== null) {
|
|
@@ -233,8 +269,7 @@ export function addCloakToUnresolvedExpressions(html) {
|
|
|
233
269
|
continue;
|
|
234
270
|
if (fullTag.includes("x-cloak"))
|
|
235
271
|
continue;
|
|
236
|
-
|
|
237
|
-
if (/\{\{[\s\S]*?\}\}/.test(textContent)) {
|
|
272
|
+
if (ownTextContainsMustache(html, tagCloseIdx + 1)) {
|
|
238
273
|
result += html.slice(lastIndex, tagCloseIdx) + " x-cloak>";
|
|
239
274
|
lastIndex = tagCloseIdx + 1;
|
|
240
275
|
}
|
package/dist/process.js
CHANGED
|
@@ -240,6 +240,18 @@ function findFirstScriptTag(html) {
|
|
|
240
240
|
}
|
|
241
241
|
return -1;
|
|
242
242
|
}
|
|
243
|
+
async function buildModulesTag(sources, options) {
|
|
244
|
+
try {
|
|
245
|
+
const { registeredModuleIdsIn, buildModuleRegistryScript } = await importOnce("stx/client-module-registry", () => import("./client-module-registry.js")), code = await buildModuleRegistryScript(registeredModuleIdsIn(...sources), {
|
|
246
|
+
minify: options.buildMode === "compile"
|
|
247
|
+
});
|
|
248
|
+
if (!code)
|
|
249
|
+
return null;
|
|
250
|
+
return `<script data-stx-scoped data-stx-run="always" data-stx-modules>${code.replace(/<\/script/gi, "<\\/script")}</script>`;
|
|
251
|
+
} catch {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
243
255
|
function placeSignalsRuntimeBeforeScripts(html) {
|
|
244
256
|
const runtime = findScriptBlockByAttribute(html, "data-stx-runtime");
|
|
245
257
|
if (!runtime)
|
|
@@ -247,6 +259,9 @@ function placeSignalsRuntimeBeforeScripts(html) {
|
|
|
247
259
|
const firstScript = findFirstScriptTag(html);
|
|
248
260
|
if (firstScript === -1 || firstScript === runtime.start)
|
|
249
261
|
return html;
|
|
262
|
+
if (firstScript < runtime.start)
|
|
263
|
+
return html.slice(0, firstScript) + html.slice(runtime.start, runtime.end) + `
|
|
264
|
+
` + html.slice(firstScript, runtime.start) + html.slice(runtime.end);
|
|
250
265
|
const runtimeTag = html.slice(runtime.start, runtime.end), withoutRuntime = html.slice(0, runtime.start) + html.slice(runtime.end), insertionPoint = findFirstScriptTag(withoutRuntime);
|
|
251
266
|
if (insertionPoint === -1)
|
|
252
267
|
return runtimeTag + `
|
|
@@ -302,7 +317,7 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
302
317
|
result = ensureDocumentShell(result, headConfig, {
|
|
303
318
|
...titleIsHtml && { titleIsHtml: !0 },
|
|
304
319
|
...options.app?.colorMode && { colorMode: options.app.colorMode }
|
|
305
|
-
});
|
|
320
|
+
}, alreadyShelled);
|
|
306
321
|
if (alreadyShelled) {
|
|
307
322
|
result = injectConfigHeadTags(result, baseHeadConfig);
|
|
308
323
|
result = applyHtmlAttrs(result, headConfig.htmlAttrs);
|
|
@@ -337,25 +352,34 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
337
352
|
if (isTopLevel) {
|
|
338
353
|
const runtime = findScriptBlockByAttribute(result, "data-stx-runtime");
|
|
339
354
|
if (runtime) {
|
|
340
|
-
let storeTag = null, composableTag = null, frameworkScript = null;
|
|
355
|
+
let modulesTag = null, storeTag = null, composableTag = null, frameworkScript = null;
|
|
341
356
|
try {
|
|
342
357
|
const { getStoreScript } = await importOnce("stx/store-loader", () => import("./store-loader.js")), resolvedStoresDir = options.storesDir, storeCode = await getStoreScript(resolvedStoresDir);
|
|
343
358
|
if (storeCode)
|
|
344
359
|
storeTag = `<script data-stx-stores>${storeCode}</script>`;
|
|
345
360
|
} catch {}
|
|
361
|
+
modulesTag = await buildModulesTag([result, storeTag], options);
|
|
346
362
|
try {
|
|
347
363
|
const { getFrameworkComposableScript } = await importOnce("stx/framework-composables", () => import("./framework-composables.js"));
|
|
348
364
|
frameworkScript = await getFrameworkComposableScript(result);
|
|
349
365
|
} catch {}
|
|
350
366
|
try {
|
|
351
|
-
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(resolvedComposablesDir, result, pending);
|
|
367
|
+
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeTag, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(resolvedComposablesDir, result, pending);
|
|
352
368
|
if (composableCode)
|
|
353
369
|
composableTag = `<script data-stx-composables>${composableCode}</script>`;
|
|
354
370
|
} catch {}
|
|
355
|
-
const tags = [storeTag, composableTag, frameworkScript].filter((text) => text !== null).map((tag) => `
|
|
371
|
+
const tags = [modulesTag, storeTag, composableTag, frameworkScript].filter((text) => text !== null).map((tag) => `
|
|
356
372
|
${tag}`).join("");
|
|
357
373
|
if (tags)
|
|
358
374
|
result = result.slice(0, runtime.end) + tags + result.slice(runtime.end);
|
|
375
|
+
} else {
|
|
376
|
+
const modulesTag = await buildModulesTag([result], options);
|
|
377
|
+
if (modulesTag) {
|
|
378
|
+
const firstReader = result.search(/<script\b[^>]*>(?:(?!<\/script>)[\s\S])*?__stxModules\[/i);
|
|
379
|
+
if (firstReader !== -1)
|
|
380
|
+
result = result.slice(0, firstReader) + modulesTag + `
|
|
381
|
+
` + result.slice(firstReader);
|
|
382
|
+
}
|
|
359
383
|
}
|
|
360
384
|
}
|
|
361
385
|
if (isTopLevel)
|
|
@@ -824,9 +848,16 @@ ${runtimeScript}`);
|
|
|
824
848
|
rangeEnd++;
|
|
825
849
|
serverRemoveRanges.push({ start: script.start, end: rangeEnd });
|
|
826
850
|
}
|
|
827
|
-
|
|
828
|
-
const
|
|
829
|
-
|
|
851
|
+
if (serverRemoveRanges.length > 0) {
|
|
852
|
+
const kept = Array(serverRemoveRanges.length + 1);
|
|
853
|
+
let cursor = 0;
|
|
854
|
+
for (let ri = 0;ri < serverRemoveRanges.length; ri++) {
|
|
855
|
+
const { start, end } = serverRemoveRanges[ri];
|
|
856
|
+
kept[ri] = output.slice(cursor, start);
|
|
857
|
+
cursor = end;
|
|
858
|
+
}
|
|
859
|
+
kept[serverRemoveRanges.length] = output.slice(cursor);
|
|
860
|
+
output = kept.join("");
|
|
830
861
|
}
|
|
831
862
|
}
|
|
832
863
|
const scopedResult = processScopedStyles(output, filePath);
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hk as wq,Ik as dq,Jk as Cq,Kk as mq,Lk as gq}from"./chunk-hpybjwwf.js";import{Mk as S,Nk as Tq,Ok as _q,Pk as z,Qk as D,Rk as P,Sk as kq,Tk as vq,Uk as w,Vk as Iq,Wk as d,Xk as Hq,Yk as Oq,Zk as Mq}from"./chunk-
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-
|
|
2
|
+
import{Hk as wq,Ik as dq,Jk as Cq,Kk as mq,Lk as gq}from"./chunk-hpybjwwf.js";import{Mk as S,Nk as Tq,Ok as _q,Pk as z,Qk as D,Rk as P,Sk as kq,Tk as vq,Uk as w,Vk as Iq,Wk as d,Xk as Hq,Yk as Oq,Zk as Mq}from"./chunk-np5dc1q1.js";import{bv as Aq,cv as bq,dv as Sq,ev as zq,fv as Dq,gv as Pq}from"./chunk-kb5j08tq.js";import{kv as N}from"./chunk-2vza9m2x.js";import p from"fs";import E from"path";import C from"fs";import L from"path";var k=[72,96,128,144,152,192,384,512],v=[120,152,167,180],I=[16,32];async function H(G,B){let q={success:!0,generatedFiles:[],errors:[],warnings:[]},K=G.pwa?.icons;if(!K?.src)return q.errors.push("No source icon specified in pwa.icons.src"),q.success=!1,q;let Y=L.isAbsolute(K.src)?K.src:L.resolve(process.cwd(),K.src);if(!await Bun.file(Y).exists())return q.errors.push(`Source icon not found: ${Y}`),q.success=!1,q;let Q=L.resolve(B,K.outputDir||"pwa-icons");try{C.mkdirSync(Q,{recursive:!0})}catch{return q.errors.push(`Failed to create output directory: ${Q}`),q.success=!1,q}let X=K.sizes||k,j=K.generateWebP??!0,J=K.generateAppleIcons??!0;try{let y;try{y=await import("sharp")}catch{return q.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),q.success=!1,q}let R=await y.default(Y).metadata();if(R.width&&R.width<512)q.warnings.push(`Source icon is ${R.width}x${R.height}. Recommend using at least 512x512 for best quality.`);for(let $ of X){let x=L.join(Q,`icon-${$}x${$}.png`);if(await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x),j){let F=L.join(Q,`icon-${$}x${$}.webp`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(F),q.generatedFiles.push(F)}}if(J){for(let x of v){let F=L.join(Q,`apple-touch-icon-${x}x${x}.png`);await y.default(Y).resize(x,x,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(F),q.generatedFiles.push(F)}let $=L.join(Q,"apple-touch-icon.png");await y.default(Y).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile($),q.generatedFiles.push($)}for(let $ of I){let x=L.join(Q,`favicon-${$}x${$}.png`);await y.default(Y).resize($,$,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(x),q.generatedFiles.push(x)}let U=512,T=L.join(Q,`icon-maskable-${U}x${U}.png`),Z=Math.floor(U*0.1),_=U-Z*2;await y.default(Y).resize(_,_,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:Z,bottom:Z,left:Z,right:Z,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(T),q.generatedFiles.push(T)}catch(y){let V=y instanceof Error?y.message:String(y);q.errors.push(`Icon generation failed: ${V}`),q.success=!1}return q}function n(G){let B=G.sizes||k,q=G.outputDir?`/${G.outputDir}`:"/pwa-icons",K=G.generateWebP??!0,Y=G.generateAppleIcons??!0,Q=[];for(let X of B)if(Q.push(`${q}/icon-${X}x${X}.png`),K)Q.push(`${q}/icon-${X}x${X}.webp`);if(Y){Q.push(`${q}/apple-touch-icon.png`);for(let X of v)Q.push(`${q}/apple-touch-icon-${X}x${X}.png`)}for(let X of I)Q.push(`${q}/favicon-${X}x${X}.png`);return Q.push(`${q}/icon-maskable-512x512.png`),Q}async function O(){try{return await import("sharp"),!0}catch{return!1}}function m(G,B,q,K){let Y=[],Q=K.join(" ");for(let X of G)if(Y.push({src:`${B}/icon-${X}x${X}.png`,sizes:`${X}x${X}`,type:"image/png",purpose:Q}),q)Y.push({src:`${B}/icon-${X}x${X}.webp`,sizes:`${X}x${X}`,type:"image/webp",purpose:Q});return Y}function g(G){return G.map((B)=>({name:B.name,short_name:B.shortName,description:B.description,url:B.url,icons:B.icons?.map((q)=>({src:q.src,sizes:q.sizes,type:q.type}))}))}function h(G){let B=G.pwa?.shareTarget;if(!B?.enabled)return;let q={action:B.action||"/share",method:B.method||"POST",enctype:B.enctype||"multipart/form-data",params:{title:B.params?.title||"title",text:B.params?.text||"text",url:B.params?.url||"url"}};if(B.acceptFiles&&B.acceptFiles.length>0)q.params.files=B.acceptFiles.map((K)=>({name:K.name,accept:K.accept}));return q}function c(G){let B=G.pwa?.fileHandlers;if(!B?.enabled||!B.accept)return;let q=[{action:B.action||"/",accept:B.accept,launch_type:B.launchType||"single-client"}];if(B.icons)q[0].icons=B.icons.map((K)=>({src:K.src,sizes:K.sizes,type:K.type}));return q}function l(G){let B=G.pwa?.protocolHandlers;if(!B||B.length===0)return;return B.map((q)=>({protocol:q.protocol,url:q.url}))}function u(G){let B=G.pwa;if(!B?.enabled||!B.manifest)return null;let{manifest:q,icons:K}=B,Y=K?.sizes||[72,96,128,144,152,192,384,512],Q=K?.outputDir?`/${K.outputDir}`:"/pwa-icons",X=K?.generateWebP??!0,j=K?.purpose||["any","maskable"],J={name:q.name,short_name:q.shortName||q.name,description:q.description,start_url:q.startUrl||"/",display:q.display||"standalone",display_override:q.displayOverride,orientation:q.orientation,theme_color:q.themeColor,background_color:q.backgroundColor,scope:q.scope||"/",lang:q.lang,dir:q.dir,id:q.id,categories:q.categories,icons:m(Y,Q,X,j)};if(q.shortcuts&&q.shortcuts.length>0)J.shortcuts=g(q.shortcuts);if(q.screenshots&&q.screenshots.length>0)J.screenshots=q.screenshots.map((U)=>({src:U.src,sizes:U.sizes,type:U.type,label:U.label,form_factor:U.platform}));let y=h(G);if(y)J.share_target=y;let V=c(G);if(V)J.file_handlers=V;let R=l(G);if(R)J.protocol_handlers=R;if(q.launchHandler)J.launch_handler={client_mode:q.launchHandler};if(q.handleLinks)J.handle_links=q.handleLinks;if(q.edgeSidePanel?.enabled)J.edge_side_panel={preferred_width:q.edgeSidePanel.preferredWidth};return J}function M(G){let B=u(G);if(!B)return"";let q=JSON.parse(JSON.stringify(B));return JSON.stringify(q,null,2)}function i(G,B){return{...B,...G,shortcuts:G.shortcuts||B.shortcuts,screenshots:G.screenshots||B.screenshots,categories:G.categories||B.categories}}function s(G){let B=[],q=G.pwa;if(!q?.enabled)return B;let K=q.manifest;if(!K)return B.push("PWA manifest configuration is missing"),B;if(!K.name)B.push("Manifest name is required");let Y=["fullscreen","standalone","minimal-ui","browser"];if(K.display&&!Y.includes(K.display))B.push(`Invalid display mode: ${K.display}. Must be one of: ${Y.join(", ")}`);let Q=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(K.orientation&&!Q.includes(K.orientation))B.push(`Invalid orientation: ${K.orientation}`);let X=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(K.themeColor&&!X.test(K.themeColor))B.push(`Invalid theme color: ${K.themeColor}. Must be a valid hex color.`);if(K.backgroundColor&&!X.test(K.backgroundColor))B.push(`Invalid background color: ${K.backgroundColor}. Must be a valid hex color.`);if(q.shareTarget?.enabled){if(!q.shareTarget.action)B.push("Share target action URL is required")}if(q.fileHandlers?.enabled){if(!q.fileHandlers.accept||Object.keys(q.fileHandlers.accept).length===0)B.push("File handlers must specify accepted MIME types")}if(q.protocolHandlers)for(let j of q.protocolHandlers){if(!j.protocol)B.push("Protocol handler missing protocol");if(!j.url||!j.url.includes("%s"))B.push(`Protocol handler URL must contain %s placeholder: ${j.protocol}`)}return B}import A from"path";async function b(G){let B=G.pwa?.offline;if(!B?.enabled)return"";if(B.page){let q=A.isAbsolute(B.page)?B.page:A.resolve(process.cwd(),B.page);if(await Bun.file(q).exists())try{let{processDirectives:K}=await import("./chunk-ayaz0wcj.js"),Y=await Bun.file(q).text();return await K(Y,{},q,G,new Set)}catch(K){console.warn(`[PWA] Failed to process custom offline page: ${K}`)}else console.warn(`[PWA] Custom offline page not found: ${q}`)}return f(G)}function f(G){let B=G.pwa?.offline,q=G.pwa?.manifest,K=B?.fallbackTitle||"You are offline",Y=B?.fallbackMessage||"Please check your internet connection and try again.",Q=q?.themeColor||"#4f46e5",X=q?.shortName||q?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -14,6 +14,8 @@ function hasStoreRefs(expression) {
|
|
|
14
14
|
return /\$\w+\./.test(expression);
|
|
15
15
|
}
|
|
16
16
|
export function processReactiveBindings(html) {
|
|
17
|
+
if (!html.includes("{{") || !/\$\w+\./.test(html))
|
|
18
|
+
return { html, bindings: [], stores: new Set };
|
|
17
19
|
const bindings = [], stores = new Set, tagPattern = /<(\w+)([^>]*?)(\s*\/?>)/g;
|
|
18
20
|
let result = html;
|
|
19
21
|
result = result.replace(tagPattern, (match, tagName, attributes, closing) => {
|
|
@@ -225,25 +225,12 @@ export declare const COMPONENT_PASSTHROUGH_X_ATTRS: readonly string[];
|
|
|
225
225
|
/** The `X_HANDLED` lookup the generated runtime embeds, as JS source. */
|
|
226
226
|
export declare function runtimeHandledXAttrsLiteral(): string;
|
|
227
227
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* (stacksjs/stx#1835).
|
|
235
|
-
*
|
|
236
|
-
* Only TEXT is blanked, and only inside `<pre>` / `<code>` and HTML comments.
|
|
237
|
-
* Tags are kept intact, including their attributes, because that is where a
|
|
238
|
-
* directive actually lives:
|
|
239
|
-
*
|
|
240
|
-
* <pre><code><div :if="open"></code></pre> -> blanked, it is text
|
|
241
|
-
* <pre><code><span><div :if="x"></span></pre> -> span kept, text blanked
|
|
242
|
-
* <pre><button @click="go()">run</button></pre> -> kept, it is a real button
|
|
243
|
-
*
|
|
244
|
-
* Dropping whole regions instead would have been simpler and wrong in the
|
|
245
|
-
* expensive direction: a page whose only reactive element sits inside a `<pre>`
|
|
246
|
-
* would lose its runtime and break, which is worse than shipping bytes it does
|
|
247
|
-
* not need.
|
|
228
|
+
* Drop cached blanked documents.
|
|
229
|
+
*
|
|
230
|
+
* Nothing in the framework calls this, and nothing needs to. Entries are keyed
|
|
231
|
+
* on the input document itself, so an edited template is a different key and
|
|
232
|
+
* can never be answered with a stale result -- there is no invalidation to
|
|
233
|
+
* perform. It exists for callers that want a cold cache, such as tests.
|
|
248
234
|
*/
|
|
235
|
+
export declare function clearBlankCache(): void;
|
|
249
236
|
export declare function blankInertHtmlRegions(html: string): string;
|