@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/runtime-globals.js
CHANGED
|
@@ -135,6 +135,9 @@ export function templateHasReactiveContext(template, filePath) {
|
|
|
135
135
|
if (!template)
|
|
136
136
|
return !1;
|
|
137
137
|
const live = blankInertHtmlRegions(template);
|
|
138
|
+
return liveTemplateHasReactiveContext(live, filePath);
|
|
139
|
+
}
|
|
140
|
+
function liveTemplateHasReactiveContext(live, filePath) {
|
|
138
141
|
if (TEMPLATE_REACTIVE_PATTERNS.some((pattern) => pattern.test(live)))
|
|
139
142
|
return !0;
|
|
140
143
|
if (usesReactiveRuntime(live))
|
|
@@ -152,7 +155,8 @@ function scriptsImportSignals(template, filePath) {
|
|
|
152
155
|
export function templateNeedsRuntime(template, filePath) {
|
|
153
156
|
if (!template)
|
|
154
157
|
return !1;
|
|
155
|
-
|
|
158
|
+
const live = blankInertHtmlRegions(template);
|
|
159
|
+
return HAS_EVENT_HANDLER.test(live) || liveTemplateHasReactiveContext(live, filePath);
|
|
156
160
|
}
|
|
157
161
|
export const RUNTIME_OWNED_COLON_ATTRS = [
|
|
158
162
|
"if",
|
|
@@ -197,9 +201,30 @@ export const RUNTIME_HANDLED_X_ATTRS = [
|
|
|
197
201
|
export function runtimeHandledXAttrsLiteral() {
|
|
198
202
|
return `{${RUNTIME_HANDLED_X_ATTRS.map((n) => `'${n}':1`).join(",")}}`;
|
|
199
203
|
}
|
|
204
|
+
const BLANK_CACHE_MIN_BYTES = 65536, BLANK_CACHE_MAX_ENTRIES = 4, blankCache = new Map;
|
|
205
|
+
export function clearBlankCache() {
|
|
206
|
+
blankCache.clear();
|
|
207
|
+
}
|
|
200
208
|
export function blankInertHtmlRegions(html) {
|
|
201
209
|
if (!html)
|
|
202
210
|
return html;
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
if (!html.includes("<!--") && !/<(?:pre|code)\b/i.test(html))
|
|
212
|
+
return html;
|
|
213
|
+
const cacheable = html.length >= BLANK_CACHE_MIN_BYTES;
|
|
214
|
+
if (cacheable) {
|
|
215
|
+
const hit = blankCache.get(html);
|
|
216
|
+
if (hit !== void 0)
|
|
217
|
+
return hit;
|
|
218
|
+
}
|
|
219
|
+
const blankText = (segment) => segment.replace(/(<[^>]*>)|([^<]+)/g, (_match, tag, text) => tag ?? " ".repeat(text.length)), blanked = html.replace(/(<pre\b[^>]*>)([\s\S]*?)(<\/pre>)/gi, (_m, open, body, close) => open + blankText(body) + close).replace(/(<code\b[^>]*>)([\s\S]*?)(<\/code>)/gi, (_m, open, body, close) => open + blankText(body) + close).replace(/<!--[\s\S]*?-->/g, (match) => " ".repeat(match.length));
|
|
220
|
+
if (cacheable) {
|
|
221
|
+
while (blankCache.size >= BLANK_CACHE_MAX_ENTRIES) {
|
|
222
|
+
const oldest = blankCache.keys().next();
|
|
223
|
+
if (oldest.done)
|
|
224
|
+
break;
|
|
225
|
+
blankCache.delete(oldest.value);
|
|
226
|
+
}
|
|
227
|
+
blankCache.set(html, blanked);
|
|
228
|
+
}
|
|
229
|
+
return blanked;
|
|
205
230
|
}
|
package/dist/safe-evaluator.d.ts
CHANGED
|
@@ -127,6 +127,21 @@ export declare function safeEvaluateObject(expression: string, context: Record<s
|
|
|
127
127
|
* asked.
|
|
128
128
|
*/
|
|
129
129
|
export declare function freeIdentifiers(expression: string): string[];
|
|
130
|
+
/**
|
|
131
|
+
* Whether `name` can be a `new Function` parameter name.
|
|
132
|
+
*
|
|
133
|
+
* Rejects the three classes JS refuses: non-identifiers (`data-id`, `1bad`),
|
|
134
|
+
* reserved words (`class`, `true`, `if`) and strict-mode-reserved words
|
|
135
|
+
* (`let`, `static`) -- the bodies here are always strict.
|
|
136
|
+
*
|
|
137
|
+
* Exported because every caller that spreads a template context into
|
|
138
|
+
* `new Function` needs exactly this test, and a near-miss copy is worse than
|
|
139
|
+
* none: an `isIdentifier`-only filter in variable-extractor.ts let `true`
|
|
140
|
+
* through, and one such key threw before the function was built, so the whole
|
|
141
|
+
* server script of six shipped components fell back to static extraction on
|
|
142
|
+
* every render (stacksjs/stx#1945 profiling, found via the fallback's cost).
|
|
143
|
+
*/
|
|
144
|
+
export declare function isUsableParamName(name: string): boolean;
|
|
130
145
|
export declare function createSafeFunction(expression: string, contextKeys: string[]): (...args: unknown[]) => unknown;
|
|
131
146
|
export declare function safeEvaluateCode(code: string, context: Record<string, unknown>): unknown;
|
|
132
147
|
/**
|
package/dist/safe-evaluator.js
CHANGED
|
@@ -312,18 +312,19 @@ function compileFunctionBody(params, body) {
|
|
|
312
312
|
export function freeIdentifiers(expression) {
|
|
313
313
|
return expression.replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`/g, " ").replace(/\??\.\s*[a-zA-Z_$][\w$]*/g, " ").replace(/([{,]\s*)[a-zA-Z_$][\w$]*(\s*:)/g, "$1$2").match(/\b[a-zA-Z_$][\w$]*\b/g) || [];
|
|
314
314
|
}
|
|
315
|
+
const VALID_PARAM_IDENT = /^[A-Za-z_$][\w$]*$/;
|
|
316
|
+
export function isUsableParamName(name) {
|
|
317
|
+
return VALID_PARAM_IDENT.test(name) && !RESERVED_PARAM_NAMES.has(name);
|
|
318
|
+
}
|
|
315
319
|
export function createSafeFunction(expression, contextKeys) {
|
|
316
|
-
const sanitizedExpr = sanitizeExpression(expression),
|
|
320
|
+
const sanitizedExpr = sanitizeExpression(expression), validEntries = [];
|
|
317
321
|
for (let i = 0;i < contextKeys.length; i++) {
|
|
318
|
-
|
|
319
|
-
if (!validIdent.test(key))
|
|
320
|
-
continue;
|
|
321
|
-
if (RESERVED_PARAM_NAMES.has(key))
|
|
322
|
+
if (!isUsableParamName(contextKeys[i]))
|
|
322
323
|
continue;
|
|
323
|
-
|
|
324
|
-
filteredKeys.push(key);
|
|
324
|
+
validEntries.push({ key: contextKeys[i], index: i });
|
|
325
325
|
}
|
|
326
|
-
|
|
326
|
+
validEntries.sort((a, b) => a.key.localeCompare(b.key));
|
|
327
|
+
const filteredKeys = validEntries.map((entry) => entry.key), validIndices = validEntries.map((entry) => entry.index), buildFunc = (extraParams) => compileFunctionBody([...filteredKeys, ...extraParams], `
|
|
327
328
|
'use strict';
|
|
328
329
|
try {
|
|
329
330
|
return ${sanitizedExpr};
|
|
@@ -336,7 +337,8 @@ catch (e) {
|
|
|
336
337
|
}
|
|
337
338
|
`);
|
|
338
339
|
let func = buildFunc([]);
|
|
339
|
-
|
|
340
|
+
const alreadyCanonical = validEntries.every((entry, index) => entry.index === index);
|
|
341
|
+
if (filteredKeys.length === contextKeys.length && alreadyCanonical)
|
|
340
342
|
return wrapWithMissingIdentifierRetry(func, filteredKeys, buildFunc);
|
|
341
343
|
return wrapWithMissingIdentifierRetry((...args) => {
|
|
342
344
|
const projected = Array(validIndices.length);
|
|
@@ -364,8 +366,10 @@ function wrapWithMissingIdentifierRetry(initialFunc, filteredKeys, buildFunc, on
|
|
|
364
366
|
return;
|
|
365
367
|
knownNames.add(missingName);
|
|
366
368
|
extraParams.push(missingName);
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
if (onRebuild)
|
|
370
|
+
onRebuild(extraParams);
|
|
371
|
+
else
|
|
372
|
+
func = buildFunc(extraParams);
|
|
369
373
|
}
|
|
370
374
|
return;
|
|
371
375
|
};
|
|
@@ -380,7 +384,7 @@ export function safeEvaluateCode(code, context) {
|
|
|
380
384
|
for (const pattern of DANGEROUS_PATTERNS)
|
|
381
385
|
if (pattern.test(code))
|
|
382
386
|
throw Error("Potentially unsafe code detected");
|
|
383
|
-
const safeContext = createSafeContext(context), keys = Object.keys(safeContext), values =
|
|
387
|
+
const safeContext = createSafeContext(context), keys = Object.keys(safeContext).filter(isUsableParamName), values = keys.map((key) => safeContext[key]);
|
|
384
388
|
return Function(...keys, `
|
|
385
389
|
'use strict';
|
|
386
390
|
${code}
|
package/dist/server-bindings.js
CHANGED
|
@@ -86,7 +86,7 @@ export function processServerBindings(template, context) {
|
|
|
86
86
|
function isProtected(pos) {
|
|
87
87
|
return protectedRanges.some(([start, end]) => pos >= start && pos < end);
|
|
88
88
|
}
|
|
89
|
-
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g, replacements = [];
|
|
89
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g, replacements = [], compiledBindings = new Map, maxCompiledBindings = 256;
|
|
90
90
|
while ((match = tagRegex.exec(output)) !== null) {
|
|
91
91
|
if (isProtected(match.index))
|
|
92
92
|
continue;
|
|
@@ -105,7 +105,15 @@ export function processServerBindings(template, context) {
|
|
|
105
105
|
const contextKeys = Object.keys(context), contextValues = Object.values(context), identMatch = expression.match(/^([a-zA-Z_$][\w$]*)/);
|
|
106
106
|
if (identMatch && !contextKeys.includes(identMatch[1]) && !["true", "false", "null", "undefined", "Math", "JSON", "String", "Number", "Array", "Object", "Date", "parseInt", "parseFloat"].includes(identMatch[1]))
|
|
107
107
|
continue;
|
|
108
|
-
const
|
|
108
|
+
const compileKey = JSON.stringify([contextKeys, expression]);
|
|
109
|
+
let fn = compiledBindings.get(compileKey);
|
|
110
|
+
if (!fn) {
|
|
111
|
+
fn = Function(...contextKeys, `return (${expression})`);
|
|
112
|
+
if (compiledBindings.size >= maxCompiledBindings)
|
|
113
|
+
compiledBindings.clear();
|
|
114
|
+
compiledBindings.set(compileKey, fn);
|
|
115
|
+
}
|
|
116
|
+
const value = fn(...contextValues);
|
|
109
117
|
if (attrName === "class") {
|
|
110
118
|
const classStr = resolveClassBinding(value);
|
|
111
119
|
if (classStr) {
|
|
@@ -147,9 +155,17 @@ export function processServerBindings(template, context) {
|
|
|
147
155
|
});
|
|
148
156
|
}
|
|
149
157
|
}
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
158
|
+
if (replacements.length > 0) {
|
|
159
|
+
const chunks = Array(replacements.length * 2 + 1);
|
|
160
|
+
let cursor = 0;
|
|
161
|
+
for (let i = 0;i < replacements.length; i++) {
|
|
162
|
+
const { start, end, replacement } = replacements[i];
|
|
163
|
+
chunks[i * 2] = output.slice(cursor, start);
|
|
164
|
+
chunks[i * 2 + 1] = replacement;
|
|
165
|
+
cursor = end;
|
|
166
|
+
}
|
|
167
|
+
chunks[replacements.length * 2] = output.slice(cursor);
|
|
168
|
+
output = chunks.join("");
|
|
153
169
|
}
|
|
154
170
|
return output;
|
|
155
171
|
}
|
|
@@ -23,15 +23,25 @@ import type { StxOptions } from './types';
|
|
|
23
23
|
* `skipAttrs` lets callers drop tags whose attribute string contains certain
|
|
24
24
|
* patterns (e.g. `server`, `src=`, `data-stx-scoped`).
|
|
25
25
|
*/
|
|
26
|
+
export interface ScannedScriptTag {
|
|
27
|
+
readonly fullMatch: string;
|
|
28
|
+
readonly attrs: string;
|
|
29
|
+
readonly body: string;
|
|
30
|
+
readonly start: number;
|
|
31
|
+
readonly end: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Drop cached script scans.
|
|
35
|
+
*
|
|
36
|
+
* Nothing in the framework calls this, and nothing needs to. Entries are keyed
|
|
37
|
+
* on the input document itself, so an edited template is a different key and
|
|
38
|
+
* can never be answered with a stale result -- there is no invalidation to
|
|
39
|
+
* perform. It exists for callers that want a cold cache, such as tests.
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearScriptScanCache(): void;
|
|
26
42
|
export declare function scanScriptTags(html: string, opts?: {
|
|
27
43
|
skipAttrs?: RegExp;
|
|
28
|
-
}):
|
|
29
|
-
fullMatch: string;
|
|
30
|
-
attrs: string;
|
|
31
|
-
body: string;
|
|
32
|
-
start: number;
|
|
33
|
-
end: number;
|
|
34
|
-
}>;
|
|
44
|
+
}): ScannedScriptTag[];
|
|
35
45
|
/**
|
|
36
46
|
* Parsed form of a loop expression (`@for` / `@foreach` argument).
|
|
37
47
|
*
|
|
@@ -5,30 +5,48 @@ import { escapeScriptBody } from "./script-emit.js";
|
|
|
5
5
|
import { transformStoreImports } from "./store-imports.js";
|
|
6
6
|
import { shouldTranspileTypeScript, transpileTypeScript } from "./utils.js";
|
|
7
7
|
import { injectSignalsRuntime } from "./runtime-injection.js";
|
|
8
|
-
import { matchScriptElement, scanAtElementPosition } from "./html-masking.js";
|
|
8
|
+
import { evictOldest, matchScriptElement, scanAtElementPosition } from "./html-masking.js";
|
|
9
9
|
import { importOnce } from "./lazy-module.js";
|
|
10
10
|
let signalSetupCounter = 0;
|
|
11
|
-
const TAG_ATTR_RUN = `(?:"[^"]*"|'[^']*'|[^>"'])*`, SINGLE_ELEMENT_RE = /^<([a-zA-Z][a-zA-Z0-9-]*)\b((?:\s+[^=\s>]+(?:=(?:"[^"]*"|'[^']*'|[^\s>]*))?)*\s*)>([\s\S]*)<\/\1>$/s;
|
|
12
|
-
export function
|
|
11
|
+
const TAG_ATTR_RUN = `(?:"[^"]*"|'[^']*'|[^>"'])*`, SINGLE_ELEMENT_RE = /^<([a-zA-Z][a-zA-Z0-9-]*)\b((?:\s+[^=\s>]+(?:=(?:"[^"]*"|'[^']*'|[^\s>]*))?)*\s*)>([\s\S]*)<\/\1>$/s, SCRIPT_SCAN_CACHE_MIN_BYTES = 65536, SCRIPT_SCAN_CACHE_MAX_ENTRIES = 4, scriptScanCache = new Map;
|
|
12
|
+
export function clearScriptScanCache() {
|
|
13
|
+
scriptScanCache.clear();
|
|
14
|
+
}
|
|
15
|
+
function scanScriptTagsUncached(html) {
|
|
13
16
|
const out = [];
|
|
14
17
|
for (const item of scanAtElementPosition(html, matchScriptElement)) {
|
|
15
18
|
const opening = item.token.match(/^<script\b([^>]*)>/i), closing = item.token.match(/<\/script\s*>$/i);
|
|
16
19
|
if (!opening || !closing)
|
|
17
20
|
continue;
|
|
18
|
-
const attrs = opening[1];
|
|
19
|
-
if (opts.skipAttrs) {
|
|
20
|
-
opts.skipAttrs.lastIndex = 0;
|
|
21
|
-
if (opts.skipAttrs.test(attrs))
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
21
|
const bodyStart = opening[0].length, bodyEnd = item.token.length - closing[0].length;
|
|
25
|
-
out.push({
|
|
22
|
+
out.push(Object.freeze({
|
|
26
23
|
fullMatch: item.token,
|
|
27
|
-
attrs,
|
|
24
|
+
attrs: opening[1],
|
|
28
25
|
body: item.token.slice(bodyStart, bodyEnd),
|
|
29
26
|
start: item.start,
|
|
30
27
|
end: item.end
|
|
31
|
-
});
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
export function scanScriptTags(html, opts = {}) {
|
|
33
|
+
const cacheable = html.length >= SCRIPT_SCAN_CACHE_MIN_BYTES;
|
|
34
|
+
let all = cacheable ? scriptScanCache.get(html) : void 0;
|
|
35
|
+
if (all === void 0) {
|
|
36
|
+
all = scanScriptTagsUncached(html);
|
|
37
|
+
if (cacheable) {
|
|
38
|
+
evictOldest(scriptScanCache, SCRIPT_SCAN_CACHE_MAX_ENTRIES);
|
|
39
|
+
scriptScanCache.set(html, all);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const skip = opts.skipAttrs;
|
|
43
|
+
if (!skip)
|
|
44
|
+
return all.slice();
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const tag of all) {
|
|
47
|
+
skip.lastIndex = 0;
|
|
48
|
+
if (!skip.test(tag.attrs))
|
|
49
|
+
out.push(tag);
|
|
32
50
|
}
|
|
33
51
|
return out;
|
|
34
52
|
}
|
|
@@ -324,11 +342,11 @@ const VOID_ELEMENT_TAGS = new Set([
|
|
|
324
342
|
"source",
|
|
325
343
|
"track",
|
|
326
344
|
"wbr"
|
|
327
|
-
]);
|
|
345
|
+
]), RAW_TEXT_OPEN_TAG = /<(script|style)\b/iy, SCRIPT_CLOSE_PREFIX = /<\/script/gi, STYLE_CLOSE_PREFIX = /<\/style/gi;
|
|
328
346
|
function findElementEnd(output, startIdx, tag, startTagEnd) {
|
|
329
347
|
if (VOID_ELEMENT_TAGS.has(tag.toLowerCase()))
|
|
330
348
|
return startTagEnd;
|
|
331
|
-
const lower = tag.toLowerCase(),
|
|
349
|
+
const lower = tag.toLowerCase(), len = output.length;
|
|
332
350
|
let depth = 1, i = startTagEnd;
|
|
333
351
|
while (i < len) {
|
|
334
352
|
const lt = output.indexOf("<", i);
|
|
@@ -342,7 +360,8 @@ function findElementEnd(output, startIdx, tag, startTagEnd) {
|
|
|
342
360
|
i = c + 3;
|
|
343
361
|
continue;
|
|
344
362
|
}
|
|
345
|
-
|
|
363
|
+
RAW_TEXT_OPEN_TAG.lastIndex = i;
|
|
364
|
+
const raw = RAW_TEXT_OPEN_TAG.exec(output);
|
|
346
365
|
if (raw) {
|
|
347
366
|
const startGt = output.indexOf(">", i);
|
|
348
367
|
if (startGt === -1)
|
|
@@ -351,10 +370,12 @@ function findElementEnd(output, startIdx, tag, startTagEnd) {
|
|
|
351
370
|
i = startGt + 1;
|
|
352
371
|
continue;
|
|
353
372
|
}
|
|
354
|
-
const
|
|
355
|
-
|
|
373
|
+
const closeRe = raw[1].toLowerCase() === "script" ? SCRIPT_CLOSE_PREFIX : STYLE_CLOSE_PREFIX;
|
|
374
|
+
closeRe.lastIndex = i;
|
|
375
|
+
const close = closeRe.exec(output);
|
|
376
|
+
if (close === null)
|
|
356
377
|
return -1;
|
|
357
|
-
const gt = output.indexOf(">", close);
|
|
378
|
+
const gt = output.indexOf(">", close.index);
|
|
358
379
|
if (gt === -1)
|
|
359
380
|
return -1;
|
|
360
381
|
i = gt + 1;
|
|
@@ -678,6 +699,67 @@ function dedupeTopLevelDeclarations(code) {
|
|
|
678
699
|
}
|
|
679
700
|
return out.join("");
|
|
680
701
|
}
|
|
702
|
+
const SETUP_MARKER_SKIP_TAGS = new Set(["script", "style", "html", "head", "meta", "link", "title", "!doctype"]);
|
|
703
|
+
function overlapsSignalScript(start, end, ranges) {
|
|
704
|
+
for (const range of ranges) {
|
|
705
|
+
if (range.start >= end)
|
|
706
|
+
return !1;
|
|
707
|
+
if (range.end > start)
|
|
708
|
+
return !0;
|
|
709
|
+
}
|
|
710
|
+
return !1;
|
|
711
|
+
}
|
|
712
|
+
function hasTextOutsideSignalScripts(template, text, ranges) {
|
|
713
|
+
let from = 0;
|
|
714
|
+
while (from < template.length) {
|
|
715
|
+
const index = template.indexOf(text, from);
|
|
716
|
+
if (index === -1)
|
|
717
|
+
return !1;
|
|
718
|
+
if (!overlapsSignalScript(index, index + text.length, ranges))
|
|
719
|
+
return !0;
|
|
720
|
+
from = index + text.length;
|
|
721
|
+
}
|
|
722
|
+
return !1;
|
|
723
|
+
}
|
|
724
|
+
function findSetupMarkerInsertion(template, ranges) {
|
|
725
|
+
if (hasTextOutsideSignalScripts(template, "<body", ranges)) {
|
|
726
|
+
const bodyTagRe = new RegExp(`<body(${TAG_ATTR_RUN})>`, "g");
|
|
727
|
+
let match;
|
|
728
|
+
while ((match = bodyTagRe.exec(template)) !== null)
|
|
729
|
+
if (!overlapsSignalScript(match.index, match.index + match[0].length, ranges))
|
|
730
|
+
return match.index + match[0].length - 1;
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
const openingTagRe = new RegExp(`<([a-zA-Z][a-zA-Z0-9-]*)\\b(${TAG_ATTR_RUN})>`, "gi");
|
|
734
|
+
let match;
|
|
735
|
+
while ((match = openingTagRe.exec(template)) !== null) {
|
|
736
|
+
if (overlapsSignalScript(match.index, match.index + match[0].length, ranges))
|
|
737
|
+
continue;
|
|
738
|
+
if (SETUP_MARKER_SKIP_TAGS.has(match[1].toLowerCase()))
|
|
739
|
+
continue;
|
|
740
|
+
return match.index + match[0].length - 1;
|
|
741
|
+
}
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
function rebuildSetupOwner(template, ranges, markerAt, setupFnName) {
|
|
745
|
+
const chunks = [], marker = ` data-stx="${setupFnName}"`;
|
|
746
|
+
let cursor = 0, markerWritten = !1;
|
|
747
|
+
const appendThrough = (end) => {
|
|
748
|
+
if (markerAt !== null && !markerWritten && markerAt >= cursor && markerAt <= end) {
|
|
749
|
+
chunks.push(template.slice(cursor, markerAt), marker, template.slice(markerAt, end));
|
|
750
|
+
markerWritten = !0;
|
|
751
|
+
} else
|
|
752
|
+
chunks.push(template.slice(cursor, end));
|
|
753
|
+
};
|
|
754
|
+
for (const range of ranges) {
|
|
755
|
+
if (range.start < cursor)
|
|
756
|
+
continue;
|
|
757
|
+
appendThrough(range.start);
|
|
758
|
+
cursor = range.end;
|
|
759
|
+
}
|
|
760
|
+
appendThrough(template.length);
|
|
761
|
+
return chunks.join("");
|
|
762
|
+
}
|
|
681
763
|
export async function processScriptSetup(template, filePath, serverData) {
|
|
682
764
|
const scripts = scanScriptTags(template, {
|
|
683
765
|
skipAttrs: /\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b/
|
|
@@ -687,17 +769,18 @@ export async function processScriptSetup(template, filePath, serverData) {
|
|
|
687
769
|
if (shouldTranspileTypeScript(s.attrs))
|
|
688
770
|
content = transpileTypeScript(content);
|
|
689
771
|
if (SIGNAL_API_RE.test(content)) {
|
|
690
|
-
signalScripts.push({
|
|
772
|
+
signalScripts.push({ content, start: s.start, end: s.end });
|
|
691
773
|
continue;
|
|
692
774
|
}
|
|
693
775
|
if (!hasUserImports(content))
|
|
694
776
|
continue;
|
|
695
777
|
try {
|
|
696
|
-
const
|
|
697
|
-
projectRoot: process.cwd()
|
|
778
|
+
const inlined = await bundleClientScript(injectBrowserCoreAutoImports(content).code, filePath || "", {
|
|
779
|
+
projectRoot: process.cwd(),
|
|
780
|
+
externalizeUserModules: !1
|
|
698
781
|
});
|
|
699
|
-
if (SIGNAL_API_RE.test(
|
|
700
|
-
signalScripts.push({
|
|
782
|
+
if (SIGNAL_API_RE.test(inlined))
|
|
783
|
+
signalScripts.push({ content, start: s.start, end: s.end });
|
|
701
784
|
} catch {}
|
|
702
785
|
}
|
|
703
786
|
if (signalScripts.length === 0)
|
|
@@ -727,23 +810,8 @@ ${escapeScriptBody(`${bridge}${mergedContent}`)}
|
|
|
727
810
|
}
|
|
728
811
|
window.__stx_latestSetup=${setupFnName};
|
|
729
812
|
if(window.stx)window.stx._latestSetup=${setupFnName};
|
|
730
|
-
</script
|
|
731
|
-
|
|
732
|
-
for (const s of signalScripts)
|
|
733
|
-
output = output.split(s.fullMatch).join("");
|
|
734
|
-
if (output.includes("<body"))
|
|
735
|
-
output = output.replace(new RegExp(`<body(${TAG_ATTR_RUN})>`), `<body$1 data-stx="${setupFnName}">`);
|
|
736
|
-
else {
|
|
737
|
-
const skipTags = ["script", "style", "html", "head", "meta", "link", "title", "!doctype"];
|
|
738
|
-
let marked = !1;
|
|
739
|
-
output = output.replace(new RegExp(`<([a-zA-Z][a-zA-Z0-9-]*)\\b(${TAG_ATTR_RUN})>`, "gi"), (match, tag, attrs) => {
|
|
740
|
-
if (marked || skipTags.includes(tag.toLowerCase()))
|
|
741
|
-
return match;
|
|
742
|
-
marked = !0;
|
|
743
|
-
return `<${tag}${attrs} data-stx="${setupFnName}">`;
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
return { output, setupCode };
|
|
813
|
+
</script>`, markerAt = findSetupMarkerInsertion(template, signalScripts);
|
|
814
|
+
return { output: rebuildSetupOwner(template, signalScripts, markerAt, setupFnName), setupCode };
|
|
747
815
|
}
|
|
748
816
|
export function extractExports(setupContent) {
|
|
749
817
|
const code = setupContent, names = [], seen = new Set;
|
|
@@ -963,12 +1031,14 @@ ${setupCode}${output.slice(insertAt)}`;
|
|
|
963
1031
|
output = `${output}
|
|
964
1032
|
${setupCode}`;
|
|
965
1033
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1034
|
+
if (!setupCode) {
|
|
1035
|
+
const bodyMatch = output.replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/<style\b[\s\S]*?<\/style>/gi, "").match(/<body([^>]*)>/i);
|
|
1036
|
+
if (!(bodyMatch && /data-stx/.test(bodyMatch[1])) && bodyMatch && !/data-stx-auto/.test(bodyMatch[1])) {
|
|
1037
|
+
const bodyTagRe = /<body[^>]*>/i, bodyIdx = findMarkupIndexOutsideScripts(output, bodyTagRe);
|
|
1038
|
+
if (bodyIdx !== -1) {
|
|
1039
|
+
const before = output.slice(0, bodyIdx), after = output.slice(bodyIdx).replace(bodyTagRe, (m) => m.replace(/^<body([^>]*)>$/i, "<body$1 data-stx-auto>"));
|
|
1040
|
+
output = before + after;
|
|
1041
|
+
}
|
|
972
1042
|
}
|
|
973
1043
|
}
|
|
974
1044
|
return output;
|
package/dist/signals-api.js
CHANGED
|
@@ -95,8 +95,11 @@ export function effect(fn, options = {}) {
|
|
|
95
95
|
runEffect();
|
|
96
96
|
return () => {
|
|
97
97
|
isDisposed = !0;
|
|
98
|
-
if (cleanup)
|
|
99
|
-
cleanup
|
|
98
|
+
if (cleanup) {
|
|
99
|
+
const pending = cleanup;
|
|
100
|
+
cleanup = void 0;
|
|
101
|
+
pending();
|
|
102
|
+
}
|
|
100
103
|
};
|
|
101
104
|
}
|
|
102
105
|
export function batch(fn) {
|