@stacksjs/stx 0.2.544 → 0.2.545
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/chunk-0xydscd9.js +2 -0
- package/dist/chunk-13xhvx68.js +2 -0
- package/dist/chunk-16e1y0dk.js +2 -0
- package/dist/{chunk-bczcm7jk.js → chunk-1b50m7e7.js} +2 -2
- package/dist/chunk-1hqxdn25.js +2 -0
- package/dist/{chunk-r9m4cgq9.js → chunk-1m3k0exr.js} +2 -2
- package/dist/chunk-1v2vehpc.js +2 -0
- package/dist/chunk-1w11d6gq.js +2 -0
- package/dist/chunk-2bpj2dsh.js +2 -0
- package/dist/{chunk-qmza4327.js → chunk-39tkfkp7.js} +3 -3
- package/dist/chunk-3j5bg3xq.js +2 -0
- package/dist/chunk-3m2h76cz.js +2 -0
- package/dist/{chunk-ty1v368m.js → chunk-3nc2fr4q.js} +2 -2
- package/dist/{chunk-hsf7nz8x.js → chunk-3v1av932.js} +2 -2
- package/dist/chunk-5141wftw.js +2 -0
- package/dist/{chunk-66s4nhp7.js → chunk-5fx8m234.js} +2 -2
- package/dist/chunk-5g7d3r7a.js +2 -0
- package/dist/{chunk-tzf7znh0.js → chunk-5ghn1gh5.js} +15 -15
- package/dist/{chunk-h51g1ydb.js → chunk-5hdby5qp.js} +4 -4
- package/dist/{chunk-s3r2pv39.js → chunk-64pbmrqg.js} +1 -1
- package/dist/{chunk-4d925m39.js → chunk-652v9mq4.js} +16 -16
- package/dist/chunk-6bcvd3pg.js +2 -0
- package/dist/chunk-6sa2s18z.js +2 -0
- package/dist/chunk-6w8r81kh.js +2 -0
- package/dist/{chunk-p15j9fzt.js → chunk-6wktqt18.js} +3 -3
- package/dist/chunk-6wpgxryt.js +2 -0
- package/dist/{chunk-292vew7b.js → chunk-74j18qk0.js} +28 -28
- package/dist/{chunk-jjwg83xv.js → chunk-75hb7wg6.js} +1 -1
- package/dist/{chunk-8m1y1kyr.js → chunk-77j26p6r.js} +6 -6
- package/dist/{chunk-0m3sjh3t.js → chunk-7dn3bdeh.js} +5 -5
- package/dist/chunk-7pewegtw.js +2 -0
- package/dist/{chunk-nd8v4xgb.js → chunk-7ze47qgv.js} +5 -5
- package/dist/{chunk-6dtmants.js → chunk-8a4g0mex.js} +5 -5
- package/dist/{chunk-ngxqydsg.js → chunk-8nwzd6eg.js} +3 -3
- package/dist/chunk-8sfdj65f.js +2 -0
- package/dist/{chunk-6abvk7vj.js → chunk-97vj2cqz.js} +2 -2
- package/dist/chunk-a3452td4.js +2 -0
- package/dist/chunk-a5kaw8sc.js +40 -0
- package/dist/{chunk-hvpzy98g.js → chunk-ah7h9q0x.js} +2 -2
- package/dist/{chunk-3bma1215.js → chunk-at2d96rz.js} +4 -4
- package/dist/{chunk-jbfad9cc.js → chunk-avgx6hd9.js} +2 -2
- package/dist/{chunk-wav410fm.js → chunk-b2fkxk6k.js} +3 -3
- package/dist/{chunk-zzphh8g9.js → chunk-b9jb44kv.js} +5 -5
- package/dist/chunk-byjr72wz.js +2 -0
- package/dist/chunk-cg8hg6cs.js +3 -0
- package/dist/{chunk-fq9vhy6b.js → chunk-cr4ab43x.js} +2 -2
- package/dist/chunk-cv8ea5yp.js +2 -0
- package/dist/{chunk-wh7xn313.js → chunk-d0yx9kef.js} +1 -1
- package/dist/{chunk-33bzhsyw.js → chunk-d37enreq.js} +3 -3
- package/dist/chunk-d7mfkc61.js +2 -0
- package/dist/chunk-d8fhthyf.js +2 -0
- package/dist/{chunk-x607yxrc.js → chunk-dyreg5df.js} +2 -2
- package/dist/{chunk-v9vvzdag.js → chunk-e124cgb6.js} +2 -2
- package/dist/{chunk-bpr4bkde.js → chunk-ec8k75ep.js} +2 -2
- package/dist/{chunk-gxedmh17.js → chunk-eeadhr78.js} +1 -1
- package/dist/{chunk-m011s2ha.js → chunk-f1n5napx.js} +3 -3
- package/dist/chunk-f8cs6j3n.js +2 -0
- package/dist/chunk-fprgww47.js +2 -0
- package/dist/{chunk-2kvbg3t5.js → chunk-frgpx23w.js} +4 -4
- package/dist/chunk-ft447y2j.js +2 -0
- package/dist/chunk-fyq2gste.js +2 -0
- package/dist/chunk-fz7dxc1q.js +2 -0
- package/dist/{chunk-m5fw8jq1.js → chunk-gjx5256r.js} +5 -5
- package/dist/{chunk-vfcwvqvd.js → chunk-hmehxwzj.js} +193 -193
- package/dist/chunk-hvs58485.js +2 -0
- package/dist/chunk-hzx0vtw0.js +2 -0
- package/dist/{chunk-y18yvcjb.js → chunk-j2erwdgt.js} +11 -11
- package/dist/chunk-jj4b0y48.js +2 -0
- package/dist/{chunk-tkvp3rz0.js → chunk-jmvp99ay.js} +7 -7
- package/dist/chunk-kb62w54c.js +2 -0
- package/dist/{chunk-xab6b4mt.js → chunk-kch9a9v1.js} +2 -2
- package/dist/chunk-kg8rbkcf.js +2 -0
- package/dist/{chunk-2bvk0qyd.js → chunk-kvmg6r89.js} +2 -2
- package/dist/{chunk-g12j8ahm.js → chunk-m6m19hwd.js} +4 -4
- package/dist/chunk-m9cmc6np.js +2 -0
- package/dist/chunk-m9r4x7e6.js +2 -0
- package/dist/{chunk-aqra6vsk.js → chunk-mbazkfy1.js} +3 -3
- package/dist/chunk-mbwdn96z.js +2 -0
- package/dist/{chunk-2me3dm0z.js → chunk-me81wras.js} +3 -3
- package/dist/chunk-mqje968d.js +2 -0
- package/dist/chunk-mxzge1d8.js +2 -0
- package/dist/chunk-myndj1r8.js +3 -0
- package/dist/{chunk-7tabykst.js → chunk-n1cqg89v.js} +2 -2
- package/dist/{chunk-0vn4gzyb.js → chunk-n77shkpy.js} +1 -1
- package/dist/chunk-njrakvz7.js +2 -0
- package/dist/{chunk-r2sy59wb.js → chunk-nrnq7x7p.js} +2 -2
- package/dist/chunk-pq8mz4ma.js +2 -0
- package/dist/{chunk-90wh9zzy.js → chunk-pz8mf91e.js} +5 -5
- package/dist/{chunk-dyegyt6m.js → chunk-q04fdq91.js} +2 -2
- package/dist/chunk-q24yyt9k.js +2 -0
- package/dist/chunk-qbsnvmj0.js +2 -0
- package/dist/chunk-qdrvx7vh.js +2 -0
- package/dist/chunk-qyj6zygv.js +2 -0
- package/dist/chunk-qzs6q626.js +2 -0
- package/dist/{chunk-d7zterbp.js → chunk-r4199q6x.js} +2 -2
- package/dist/chunk-r63aqsc9.js +2 -0
- package/dist/chunk-rrw61yk5.js +2 -0
- package/dist/chunk-rwgp4vt5.js +2 -0
- package/dist/chunk-sn98t7ef.js +2 -0
- package/dist/{chunk-3zqq3f2b.js → chunk-ssthwjpr.js} +5 -5
- package/dist/{chunk-2qbvsvwc.js → chunk-t61vdbje.js} +6 -6
- package/dist/chunk-te6s2apv.js +2 -0
- package/dist/chunk-tgfpk4ng.js +2 -0
- package/dist/chunk-v02g9244.js +2 -0
- package/dist/{chunk-c56qtne1.js → chunk-v2b8pa86.js} +1 -1
- package/dist/chunk-v2rhpdw3.js +2 -0
- package/dist/{chunk-vb4xxpa6.js → chunk-v39ysweq.js} +2 -2
- package/dist/chunk-v40d4bdy.js +2 -0
- package/dist/{chunk-vjdj0ex3.js → chunk-v79qs0qh.js} +1 -1
- package/dist/{chunk-m56m95gk.js → chunk-vpmb8gcc.js} +4 -4
- package/dist/{chunk-p8qr0q85.js → chunk-vvkfde23.js} +2 -2
- package/dist/{chunk-sgh6zsmc.js → chunk-vyjsrvpr.js} +3 -3
- package/dist/{chunk-150v780g.js → chunk-wcp4tf94.js} +23 -17
- package/dist/{chunk-yn3kp3qy.js → chunk-wy4hfmjs.js} +5 -5
- package/dist/{chunk-r6gxy92f.js → chunk-xya3vdqy.js} +2 -2
- package/dist/{chunk-3r1m3tyr.js → chunk-xzcmh5va.js} +1 -1
- package/dist/chunk-y83we135.js +2 -0
- package/dist/{chunk-0dqxnx20.js → chunk-yq1mvakj.js} +2 -2
- package/dist/{chunk-c2ys6ezs.js → chunk-ys3640vq.js} +9 -9
- package/dist/chunk-zfypzka2.js +2 -0
- package/dist/{chunk-9a73re8k.js → chunk-zmq9hwta.js} +2 -2
- package/dist/cli.js +43 -43
- package/dist/conditionals.js +2 -7
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/expressions.js +57 -4
- package/dist/interpolation-context.d.ts +27 -0
- package/dist/interpolation-context.js +46 -0
- package/dist/native/compiler/bundle.js +7 -1
- package/dist/native/compiler/render-screen.d.ts +2 -1
- package/dist/native/compiler/render-screen.js +7 -4
- package/dist/native/compiler/setup-script.d.ts +7 -0
- package/dist/native/compiler/setup-script.js +13 -2
- package/dist/native/runtime/binding-tree.d.ts +1 -0
- package/dist/native/runtime/binding-tree.js +10 -2
- package/dist/native/runtime/shared-screen.d.ts +2 -0
- package/dist/native/runtime/shared-screen.js +3 -0
- package/dist/pwa.js +3 -3
- package/dist/safe-evaluator.d.ts +1 -1
- package/dist/safe-evaluator.js +171 -66
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-08emfsq3.js +0 -2
- package/dist/chunk-12v4d123.js +0 -2
- package/dist/chunk-2a4szpje.js +0 -3
- package/dist/chunk-2j0h8m7g.js +0 -2
- package/dist/chunk-3bwvaxk7.js +0 -2
- package/dist/chunk-3j4rze3n.js +0 -2
- package/dist/chunk-4hyhr5r7.js +0 -2
- package/dist/chunk-4q7ge545.js +0 -2
- package/dist/chunk-4qts8zk7.js +0 -2
- package/dist/chunk-4y2av4ev.js +0 -2
- package/dist/chunk-5gq8m2m7.js +0 -2
- package/dist/chunk-5rmc52h6.js +0 -2
- package/dist/chunk-69v9cn6n.js +0 -2
- package/dist/chunk-6sd4zdtg.js +0 -2
- package/dist/chunk-6tnh3cyq.js +0 -2
- package/dist/chunk-6va8wt88.js +0 -2
- package/dist/chunk-9a111pet.js +0 -3
- package/dist/chunk-9e1hftmd.js +0 -2
- package/dist/chunk-9etv5vzp.js +0 -2
- package/dist/chunk-9skdekv5.js +0 -2
- package/dist/chunk-c2cdv6rh.js +0 -2
- package/dist/chunk-cp4dr9ch.js +0 -2
- package/dist/chunk-d576yrbj.js +0 -2
- package/dist/chunk-dw5hrb3n.js +0 -2
- package/dist/chunk-ev51qyw1.js +0 -2
- package/dist/chunk-f1fyvqz0.js +0 -2
- package/dist/chunk-frw35d2v.js +0 -2
- package/dist/chunk-fzn7k9kn.js +0 -2
- package/dist/chunk-gsm1y1kb.js +0 -2
- package/dist/chunk-h1kssqxk.js +0 -2
- package/dist/chunk-h4crv0by.js +0 -2
- package/dist/chunk-h5p3h200.js +0 -2
- package/dist/chunk-j9c0yam7.js +0 -2
- package/dist/chunk-jt6p29k1.js +0 -2
- package/dist/chunk-jxbx6dk4.js +0 -2
- package/dist/chunk-kqkja1n4.js +0 -2
- package/dist/chunk-m27w29q6.js +0 -2
- package/dist/chunk-m7ddp1jw.js +0 -2
- package/dist/chunk-m7jmpech.js +0 -2
- package/dist/chunk-m8n9wxba.js +0 -2
- package/dist/chunk-ndv44bgs.js +0 -2
- package/dist/chunk-nssdvec7.js +0 -2
- package/dist/chunk-pkfwxp9n.js +0 -2
- package/dist/chunk-qtgejdvq.js +0 -2
- package/dist/chunk-rdy49a05.js +0 -2
- package/dist/chunk-rx4hz615.js +0 -2
- package/dist/chunk-sb0j0v59.js +0 -2
- package/dist/chunk-shf0hd05.js +0 -2
- package/dist/chunk-t1g1sp2z.js +0 -2
- package/dist/chunk-vdh825gt.js +0 -2
- package/dist/chunk-vhfwnvmc.js +0 -40
- package/dist/chunk-vm2cbysz.js +0 -2
- package/dist/chunk-wzymzex7.js +0 -2
- package/dist/chunk-xey01yna.js +0 -2
- package/dist/chunk-xmd8wp8x.js +0 -2
- package/dist/chunk-xmwd2xm6.js +0 -2
- package/dist/chunk-yw3cqy43.js +0 -2
- package/dist/chunk-zpf9he2x.js +0 -2
package/dist/expressions.js
CHANGED
|
@@ -5,7 +5,8 @@ import { createSafeFunction, getExpressionSafetyRule, safeEvaluate } from "./saf
|
|
|
5
5
|
import { createDetailedErrorMessage } from "./utils.js";
|
|
6
6
|
import { createPlaceholder } from "./placeholder.js";
|
|
7
7
|
import { neutralizeTemplateSyntax } from "./template-syntax-escape.js";
|
|
8
|
-
import {
|
|
8
|
+
import { classifyHtmlInterpolation, UnsafeInterpolationContextError } from "./interpolation-context.js";
|
|
9
|
+
import { isDangerousUrl, sanitizeSubstitutedUrl, schemeWindow, UNSAFE_URL_PREFIX, urlAttributeKind } from "./url-safety.js";
|
|
9
10
|
import { maskAtElementPosition, matchScriptElement, matchStyleElement, restoreStashedScripts, stashScriptElements } from "./html-masking.js";
|
|
10
11
|
import { importsSignalDeclarations } from "./imported-signals.js";
|
|
11
12
|
import { inheritedClientLoopNames, loopBoundNames, readsAnyName } from "./loop-binding.js";
|
|
@@ -297,6 +298,54 @@ export function escapeHtml(unsafe) {
|
|
|
297
298
|
export function escapeHtmlValue(unsafe) {
|
|
298
299
|
return neutralizeTemplateSyntax(escapeHtml(unsafe));
|
|
299
300
|
}
|
|
301
|
+
function escapeUnquotedAttributeValue(escaped) {
|
|
302
|
+
return escaped.replace(/ /g, " ").replace(/\t/g, "	").replace(/\n/g, " ").replace(/\r/g, " ").replace(/\f/g, "").replace(/=/g, "=").replace(/`/g, "`");
|
|
303
|
+
}
|
|
304
|
+
function normalizedCss(value) {
|
|
305
|
+
return value.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\\([\dA-Fa-f]{1,6})\s?/g, (_match, hex) => String.fromCodePoint(Number.parseInt(hex, 16))).replace(/\\([^\r\n])/g, "$1").replace(/[\u0000-\u0020]+/g, "").toLowerCase();
|
|
306
|
+
}
|
|
307
|
+
function assertSafeCssInterpolation(value, attribute) {
|
|
308
|
+
const css = normalizedCss(value);
|
|
309
|
+
if (/@import|expression\(|behavior:|-moz-binding|(?:image-set|cross-fade)\(/.test(css))
|
|
310
|
+
throw new UnsafeInterpolationContextError(attribute, "network-capable or executable CSS is not allowed in an escaped interpolation");
|
|
311
|
+
const urlRe = /url\(([^)]*)\)/g;
|
|
312
|
+
let match;
|
|
313
|
+
while ((match = urlRe.exec(css)) !== null) {
|
|
314
|
+
const url = match[1].replace(/^["']|["']$/g, ""), isLocal = url.startsWith("/") && !url.startsWith("//") || url.startsWith("./") || url.startsWith("../") || url.startsWith("#"), isRasterData = /^data:image\/(?:avif|bmp|gif|jpeg|jpg|png|webp);base64,[a-z\d+/=]+$/i.test(url);
|
|
315
|
+
if (!isLocal && !isRasterData)
|
|
316
|
+
throw new UnsafeInterpolationContextError(attribute, "CSS URLs must be local paths or base64 raster images");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function escapeInterpolatedHtmlValue(source, offset, raw, attributeFragment = !1, interpolationLength = 0) {
|
|
320
|
+
const context = classifyHtmlInterpolation(source, offset, attributeFragment);
|
|
321
|
+
let escaped = escapeHtmlValue(raw);
|
|
322
|
+
if (!context)
|
|
323
|
+
return escaped;
|
|
324
|
+
if (context.kind === "tag-name") {
|
|
325
|
+
if (!/^[A-Za-z][A-Za-z0-9:-]*$/.test(raw))
|
|
326
|
+
throw new UnsafeInterpolationContextError("tag name", "dynamic tag names may contain only letters, digits, colons, and hyphens");
|
|
327
|
+
return raw;
|
|
328
|
+
}
|
|
329
|
+
if (context.kind === "tag") {
|
|
330
|
+
const suffix = source.slice(offset + interpolationLength).trimStart(), booleanAttributes = raw.trim();
|
|
331
|
+
if (!suffix.startsWith("=") && (booleanAttributes === "" || /^(?!on)[A-Za-z_:][\w:.-]*(?:\s+(?!on)[A-Za-z_:][\w:.-]*)*$/.test(booleanAttributes)))
|
|
332
|
+
return booleanAttributes;
|
|
333
|
+
throw new UnsafeInterpolationContextError("tag structure", "only standalone boolean attributes may be interpolated into tag structure");
|
|
334
|
+
}
|
|
335
|
+
const attribute = context.name.toLowerCase();
|
|
336
|
+
if (/^on[a-z]/.test(attribute))
|
|
337
|
+
throw new UnsafeInterpolationContextError(context.name, "native event-handler attributes execute JavaScript; use an @event binding instead");
|
|
338
|
+
if (attribute === "srcdoc")
|
|
339
|
+
escaped = escapeHtmlValue(escaped);
|
|
340
|
+
if (attribute === "style")
|
|
341
|
+
assertSafeCssInterpolation(raw, context.name);
|
|
342
|
+
if (context.quote === null)
|
|
343
|
+
escaped = escapeUnquotedAttributeValue(escaped);
|
|
344
|
+
const urlKind = urlAttributeKind(attribute);
|
|
345
|
+
if (urlKind && context.valuePrefix.trim() === "" && isDangerousUrl(raw, urlKind))
|
|
346
|
+
return UNSAFE_URL_PREFIX + escaped;
|
|
347
|
+
return sanitizeSubstitutedUrl(schemeWindow(source, offset), raw, escaped);
|
|
348
|
+
}
|
|
300
349
|
export function usesSignalsInScript(template, filePath) {
|
|
301
350
|
const { scripts } = stashScriptElements(template);
|
|
302
351
|
for (const script of scripts) {
|
|
@@ -474,8 +523,10 @@ export function interpolateScriptAttributes(attrs, context) {
|
|
|
474
523
|
if (value === null)
|
|
475
524
|
return "";
|
|
476
525
|
const raw = String(value);
|
|
477
|
-
return
|
|
478
|
-
} catch {
|
|
526
|
+
return escapeInterpolatedHtmlValue(output, offset, raw, !0, match.length);
|
|
527
|
+
} catch (error) {
|
|
528
|
+
if (error instanceof UnsafeInterpolationContextError)
|
|
529
|
+
throw error;
|
|
479
530
|
return match;
|
|
480
531
|
}
|
|
481
532
|
});
|
|
@@ -566,8 +617,10 @@ export function processExpressions(template, context, filePath) {
|
|
|
566
617
|
if (value === void 0 || value === null)
|
|
567
618
|
return "";
|
|
568
619
|
const raw = String(value);
|
|
569
|
-
return
|
|
620
|
+
return escapeInterpolatedHtmlValue(output, offset, raw, !1, match.length);
|
|
570
621
|
} catch (error) {
|
|
622
|
+
if (error instanceof UnsafeInterpolationContextError)
|
|
623
|
+
throw error;
|
|
571
624
|
if (firstVarIsClientSignal)
|
|
572
625
|
return match;
|
|
573
626
|
if (hasSignals && !expressionUsesOnlyContextVars(trimmedExpr, context))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface AttributeInterpolationContext {
|
|
2
|
+
kind: 'attribute';
|
|
3
|
+
name: string;
|
|
4
|
+
quote: '"' | "'" | null;
|
|
5
|
+
valuePrefix: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TagInterpolationContext {
|
|
8
|
+
kind: 'tag';
|
|
9
|
+
}
|
|
10
|
+
export interface TagNameInterpolationContext {
|
|
11
|
+
kind: 'tag-name';
|
|
12
|
+
}
|
|
13
|
+
export type HtmlInterpolationContext = AttributeInterpolationContext | TagInterpolationContext | TagNameInterpolationContext | null;
|
|
14
|
+
/**
|
|
15
|
+
* Classify the HTML position occupied by an interpolation.
|
|
16
|
+
*
|
|
17
|
+
* This intentionally answers one narrow question rather than parsing HTML:
|
|
18
|
+
* script/style elements have already been masked by the expression pipeline,
|
|
19
|
+
* and only the current open tag can make an escaped value unsafe. Attribute
|
|
20
|
+
* fragments (the input used by interpolateScriptAttributes) work too because
|
|
21
|
+
* they simply have no leading `<tag` portion.
|
|
22
|
+
*/
|
|
23
|
+
export declare function classifyHtmlInterpolation(source: string, offset: number, attributeFragment?: boolean): HtmlInterpolationContext;
|
|
24
|
+
export declare class UnsafeInterpolationContextError extends Error {
|
|
25
|
+
readonly attribute: string;
|
|
26
|
+
constructor(attribute: string, reason: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function classifyHtmlInterpolation(source, offset, attributeFragment = !1) {
|
|
2
|
+
const before = source.slice(0, offset), openTag = before.lastIndexOf("<"), closeTag = before.lastIndexOf(">");
|
|
3
|
+
if (openTag >= 0 && closeTag > openTag)
|
|
4
|
+
return null;
|
|
5
|
+
if (openTag < 0 && !attributeFragment)
|
|
6
|
+
return null;
|
|
7
|
+
const tail = openTag >= 0 ? before.slice(openTag + 1) : before;
|
|
8
|
+
if (openTag >= 0 && /^\s*[!/?]/.test(tail))
|
|
9
|
+
return /^\s*\/?\s*$/.test(tail) ? { kind: "tag-name" } : null;
|
|
10
|
+
if (openTag >= 0 && /^\s*$/.test(tail))
|
|
11
|
+
return { kind: "tag-name" };
|
|
12
|
+
const doubleQuoted = /(?:^|\s)([^\s"'<>/=]+)\s*=\s*"([^"]*)$/.exec(tail);
|
|
13
|
+
if (doubleQuoted)
|
|
14
|
+
return {
|
|
15
|
+
kind: "attribute",
|
|
16
|
+
name: doubleQuoted[1],
|
|
17
|
+
quote: '"',
|
|
18
|
+
valuePrefix: doubleQuoted[2]
|
|
19
|
+
};
|
|
20
|
+
const singleQuoted = /(?:^|\s)([^\s"'<>/=]+)\s*=\s*'([^']*)$/.exec(tail);
|
|
21
|
+
if (singleQuoted)
|
|
22
|
+
return {
|
|
23
|
+
kind: "attribute",
|
|
24
|
+
name: singleQuoted[1],
|
|
25
|
+
quote: "'",
|
|
26
|
+
valuePrefix: singleQuoted[2]
|
|
27
|
+
};
|
|
28
|
+
const unquoted = /(?:^|\s)([^\s"'<>/=]+)\s*=\s*([^\s"'=<>`]*)$/.exec(tail);
|
|
29
|
+
if (unquoted)
|
|
30
|
+
return {
|
|
31
|
+
kind: "attribute",
|
|
32
|
+
name: unquoted[1],
|
|
33
|
+
quote: null,
|
|
34
|
+
valuePrefix: unquoted[2]
|
|
35
|
+
};
|
|
36
|
+
return openTag >= 0 || /^\s*[^<>]*$/.test(tail) ? { kind: "tag" } : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class UnsafeInterpolationContextError extends Error {
|
|
40
|
+
attribute;
|
|
41
|
+
constructor(attribute, reason) {
|
|
42
|
+
super(`Unsafe interpolation in ${attribute}: ${reason}`);
|
|
43
|
+
this.name = "UnsafeInterpolationContextError";
|
|
44
|
+
this.attribute = attribute;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -64,7 +64,13 @@ var isApp = false;`, selections = compiledScreens.map(({ name, compiled }, index
|
|
|
64
64
|
manifest = ${JSON.stringify(compiled.manifest)};
|
|
65
65
|
}`).join(`
|
|
66
66
|
`), setups = compiledScreens.map(({ name, compiled }, index) => `${index === 0 ? "if" : "else if"} (routeName === ${JSON.stringify(routed ? name : "main")}) {
|
|
67
|
-
|
|
67
|
+
g.__stx_latestSetup = null;
|
|
68
|
+
${compiled.scripts.map((script) => script.owner ? ` g.__STX_SETUP_ROOT__ = screen && screen.scopeRoot(${JSON.stringify(script.owner)});
|
|
69
|
+
try {
|
|
70
|
+
${script.code}
|
|
71
|
+
}
|
|
72
|
+
finally { g.__STX_SETUP_ROOT__ = null; }` : script.code).join(`
|
|
73
|
+
`)}
|
|
68
74
|
}`).join(`
|
|
69
75
|
`), browserRuntime = browser ? nativeRuntimeModule("browser-screen") : null, platformModule = browser ? Bun.resolveSync(browser.platformModule, root) : null, contents = `
|
|
70
76
|
import { installJSCGlobals } from ${JSON.stringify(runtimeGlobals)};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BindingManifest } from '../../binding-manifest';
|
|
2
|
-
import { type GeneratedSetupScript } from './setup-script';
|
|
2
|
+
import { type GeneratedSetupScript, type NativeClientScript } from './setup-script';
|
|
3
3
|
import type { STXDocument } from './ir';
|
|
4
4
|
import type { TranslationDiagnostic } from './html-to-ir';
|
|
5
5
|
/**
|
|
@@ -26,6 +26,7 @@ export declare interface CompiledScreen {
|
|
|
26
26
|
document: STXDocument
|
|
27
27
|
manifest: BindingManifest
|
|
28
28
|
setup: GeneratedSetupScript | null
|
|
29
|
+
scripts: NativeClientScript[]
|
|
29
30
|
diagnostics: TranslationDiagnostic[]
|
|
30
31
|
html: string
|
|
31
32
|
}
|
|
@@ -6,7 +6,7 @@ import { processDirectives } from "../../process.js";
|
|
|
6
6
|
import { processScriptSetup } from "../../signal-processing.js";
|
|
7
7
|
import { translateHtmlToDocument } from "./html-to-ir.js";
|
|
8
8
|
import { extractClientScript } from "./client-script.js";
|
|
9
|
-
import { extractGeneratedSetupScript } from "./setup-script.js";
|
|
9
|
+
import { extractGeneratedSetupScript, extractNativeClientScripts } from "./setup-script.js";
|
|
10
10
|
export function nativePrimitivesDir() {
|
|
11
11
|
const candidates = [
|
|
12
12
|
path.join(import.meta.dir, "..", "primitives"),
|
|
@@ -30,11 +30,14 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
30
30
|
script: extractClientScript(source)
|
|
31
31
|
});
|
|
32
32
|
let setup = extractGeneratedSetupScript(html);
|
|
33
|
+
const scripts = extractNativeClientScripts(html);
|
|
33
34
|
if (extractClientScript(source).code.trim()) {
|
|
34
|
-
const forced = await processScriptSetup(source, filePath, options.context, { forceClientSetup: !0 });
|
|
35
|
-
setup =
|
|
35
|
+
const forced = await processScriptSetup(source, filePath, options.context, { forceClientSetup: !0 }), forcedSetup = extractGeneratedSetupScript(forced.setupCode ?? "");
|
|
36
|
+
setup = forcedSetup ?? setup;
|
|
37
|
+
if (forcedSetup && !scripts.some((script) => script.code === forcedSetup.code))
|
|
38
|
+
scripts.push({ code: forcedSetup.code });
|
|
36
39
|
}
|
|
37
|
-
return { document, manifest, setup, diagnostics, html, dependencies: [...dependencies] };
|
|
40
|
+
return { document, manifest, setup, scripts, diagnostics, html, dependencies: [...dependencies] };
|
|
38
41
|
}
|
|
39
42
|
export async function compileScreenFile(filePath, options = {}) {
|
|
40
43
|
return compileScreenSource(await Bun.file(filePath).text(), filePath, options);
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/** Extract the setup stx generated from a screen's client script. */
|
|
2
2
|
export declare function extractGeneratedSetupScript(html: string): GeneratedSetupScript | null;
|
|
3
|
+
/** Extract the generated page setup plus component factory registrations/calls. */
|
|
4
|
+
export declare function extractNativeClientScripts(html: string): NativeClientScript[];
|
|
3
5
|
export declare interface GeneratedSetupScript {
|
|
4
6
|
name: string
|
|
5
7
|
code: string
|
|
6
8
|
}
|
|
9
|
+
/** One generated script the native bundle must execute before hydration. */
|
|
10
|
+
export declare interface NativeClientScript {
|
|
11
|
+
code: string
|
|
12
|
+
owner?: string
|
|
13
|
+
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
const SCOPED_SCRIPT = /<script\b[^>]*\bdata-stx-scoped\b[^>]
|
|
1
|
+
const SCOPED_SCRIPT = /<script\b([^>]*\bdata-stx-scoped\b[^>]*)>([\s\S]*?)<\/script>/gi, SETUP_NAME = /function\s+(__stx_setup_[\w$]+)\s*\(/, OWNER = /\bdata-stx-owner\s*=\s*["']([^"']+)["']/i;
|
|
2
2
|
export function extractGeneratedSetupScript(html) {
|
|
3
3
|
SCOPED_SCRIPT.lastIndex = 0;
|
|
4
4
|
for (const match of html.matchAll(SCOPED_SCRIPT)) {
|
|
5
|
-
const code = match[
|
|
5
|
+
const code = match[2].trim(), name = SETUP_NAME.exec(code)?.[1];
|
|
6
6
|
if (name)
|
|
7
7
|
return { name, code };
|
|
8
8
|
}
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
+
export function extractNativeClientScripts(html) {
|
|
12
|
+
const scripts = [];
|
|
13
|
+
SCOPED_SCRIPT.lastIndex = 0;
|
|
14
|
+
for (const match of html.matchAll(SCOPED_SCRIPT)) {
|
|
15
|
+
const attrs = match[1], code = match[2].trim(), owner = OWNER.exec(attrs)?.[1], isFactoryPrelude = /\bdata-stx-component-factories\b/i.test(attrs);
|
|
16
|
+
if (!code || !owner && !isFactoryPrelude && !SETUP_NAME.test(code))
|
|
17
|
+
continue;
|
|
18
|
+
scripts.push(owner ? { code, owner } : { code });
|
|
19
|
+
}
|
|
20
|
+
return scripts;
|
|
21
|
+
}
|
|
@@ -91,7 +91,7 @@ export function cloneNativeBindingNode(source, id, onClassChange) {
|
|
|
91
91
|
return createBindingNode(id, source.tagName, bindings, !1, source.className, onClassChange);
|
|
92
92
|
}
|
|
93
93
|
export function materializeNativeBindingTree(document, manifest, host) {
|
|
94
|
-
const entries = new Map(manifest.entries.map((entry) => [entry.id, entry])), nodes = new Map;
|
|
94
|
+
const entries = new Map(manifest.entries.map((entry) => [entry.id, entry])), nodes = new Map, scopes = new Map;
|
|
95
95
|
let sequence = 0;
|
|
96
96
|
function visit(source, parent) {
|
|
97
97
|
const id = `n${sequence++}`, runtimeBindings = [...(source.bindingId === void 0 ? void 0 : entries.get(source.bindingId))?.bindings ?? []];
|
|
@@ -104,6 +104,14 @@ export function materializeNativeBindingTree(document, manifest, host) {
|
|
|
104
104
|
node.parentNode = parent;
|
|
105
105
|
node.parentElement = parent;
|
|
106
106
|
host.adopt(node, source.type, parent, source);
|
|
107
|
+
const scopeId = source.props["data-stx-scope"];
|
|
108
|
+
if (typeof scopeId === "string") {
|
|
109
|
+
node.setAttribute("data-stx-scope", scopeId);
|
|
110
|
+
scopes.set(scopeId, node);
|
|
111
|
+
const serializedProps = source.props["data-stx-props"];
|
|
112
|
+
if (serializedProps !== void 0)
|
|
113
|
+
node.setAttribute("data-stx-props", typeof serializedProps === "string" ? serializedProps : JSON.stringify(serializedProps));
|
|
114
|
+
}
|
|
107
115
|
if (source.bindingId !== void 0) {
|
|
108
116
|
node.setAttribute("data-stx-b", source.bindingId);
|
|
109
117
|
nodes.set(source.bindingId, node);
|
|
@@ -117,5 +125,5 @@ export function materializeNativeBindingTree(document, manifest, host) {
|
|
|
117
125
|
}
|
|
118
126
|
return node;
|
|
119
127
|
}
|
|
120
|
-
return { root: visit(document.root, null), nodes };
|
|
128
|
+
return { root: visit(document.root, null), nodes, scopes };
|
|
121
129
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CraftBridgeOptions } from './craft-bridge';
|
|
2
2
|
import { type NativeHost } from './native-host';
|
|
3
3
|
import type { BindingManifest } from '../../binding-manifest';
|
|
4
|
+
import type { NativeBindingNode } from './binding-tree';
|
|
4
5
|
import type { NativeBridgeInterface } from '../bridge/protocol';
|
|
5
6
|
import type { STXDocument } from '../compiler/ir';
|
|
6
7
|
/** Connect translated IR to the ordinary stx signals runtime and native bridge. */
|
|
@@ -13,6 +14,7 @@ declare interface SharedSignalsRuntime {
|
|
|
13
14
|
}
|
|
14
15
|
export declare interface SharedNativeScreen {
|
|
15
16
|
host: NativeHost
|
|
17
|
+
scopeRoot: (scopeId: string) => NativeBindingNode | null
|
|
16
18
|
mount: (runtime: SharedSignalsRuntime, setup: (() => Record<string, unknown>) | null) => void
|
|
17
19
|
unmount: () => void
|
|
18
20
|
}
|
|
@@ -46,6 +46,9 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
|
|
|
46
46
|
});
|
|
47
47
|
return {
|
|
48
48
|
host,
|
|
49
|
+
scopeRoot(scopeId) {
|
|
50
|
+
return tree.scopes.get(scopeId) ?? null;
|
|
51
|
+
},
|
|
49
52
|
mount(runtime, setup) {
|
|
50
53
|
dispose?.();
|
|
51
54
|
dispose = runtime.hydrateHost(tree.root, setup, manifest, tree.nodes);
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Bn,Ne,Ho,
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
2
|
+
import{Bn,Ne,Ho,Ja}from"./chunk-vpmb8gcc.js";import{jn,qr,Ga,Ka,Xa}from"./chunk-8a4g0mex.js";import{Bo,Fo,zo,Wa,qa}from"./chunk-5fx8m234.js";import{ie,ht,Gr}from"./chunk-97vj2cqz.js";import{Qc,el,tl,nl,hr,vu}from"./chunk-xya3vdqy.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-6w8r81kh.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ie(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Bn(n,t);if(a){let s=Ne(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ie(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Bn(n,t);if(a){let s=Ne(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return qr(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Fo as auditBuildOutput,Bo as auditConfig,re as buildPwaAssets,zo as calculateAuditResult,qa as formatAuditResult,Gr as formatSize,j as generateManifest,_ as generateManifestJson,Ka as generateManifestLink,F as generateOfflinePage,ie as generatePrecacheManifest,ht as generatePrecacheManifestJs,M as generatePwaIcons,jn as generatePwaTags,Bn as generateServiceWorker,Ja as generateServiceWorkerAuto,Ga as generateSwRegistrationScript,Xa as generateThemeColorMeta,N as getExpectedIconPaths,Ne as getServiceWorkerFileName,qr as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Ho as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,hr as pwaDirectives,Qc as pwaInstallDirective,tl as pwaOfflineDirective,nl as pwaPushDirective,el as pwaUpdateDirective,vu as registerPwaDirectives,Wa as runPwaAudit,D as validateManifest};
|
package/dist/safe-evaluator.d.ts
CHANGED
|
@@ -160,7 +160,7 @@ export declare function freeIdentifiers(expression: string): string[];
|
|
|
160
160
|
* every render (stacksjs/stx#1945 profiling, found via the fallback's cost).
|
|
161
161
|
*/
|
|
162
162
|
export declare function isUsableParamName(name: string): boolean;
|
|
163
|
-
export declare function createSafeFunction(expression: string, contextKeys: string[]): (...args: unknown[]) => unknown;
|
|
163
|
+
export declare function createSafeFunction(expression: string, contextKeys: string[], onMissingIdentifier?: (name: string) => void): (...args: unknown[]) => unknown;
|
|
164
164
|
export declare function safeEvaluateCode(code: string, context: Record<string, unknown>): unknown;
|
|
165
165
|
/**
|
|
166
166
|
* Validate a for loop expression for safety
|