@stacksjs/stx 0.2.875 → 0.2.880
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-fdjx4vs3.js → chunk-00tq7ghn.js} +2 -2
- package/dist/{chunk-nv4c25zj.js → chunk-02qmvcmv.js} +3 -3
- package/dist/chunk-08cb7cyw.js +2 -0
- package/dist/chunk-0h1dyd38.js +2 -0
- package/dist/{chunk-4m11kcxz.js → chunk-0m4c42qt.js} +10 -10
- package/dist/{chunk-6ykfy7eh.js → chunk-19k15mfc.js} +2 -2
- package/dist/chunk-1avy0p8v.js +2 -0
- package/dist/chunk-1jk46ve0.js +2 -0
- package/dist/chunk-1r612xxs.js +2 -0
- package/dist/chunk-1z6rrqvm.js +2 -0
- package/dist/chunk-2d68p12e.js +2 -0
- package/dist/chunk-2haf7t5h.js +2 -0
- package/dist/{chunk-1q5w3xav.js → chunk-2r0nrvqe.js} +2 -2
- package/dist/chunk-3jp5z1qj.js +2 -0
- package/dist/{chunk-644ckv6e.js → chunk-3q0w0bzd.js} +10 -10
- package/dist/{chunk-eknm4jrm.js → chunk-3sema2js.js} +2 -2
- package/dist/{chunk-vznf808n.js → chunk-3wb82rxw.js} +5 -5
- package/dist/chunk-3zds0gmd.js +2 -0
- package/dist/{chunk-qnwd5bz4.js → chunk-463weehv.js} +1 -1
- package/dist/{chunk-wm029dh0.js → chunk-4fkcn6z5.js} +18 -12
- package/dist/{chunk-976kgb3r.js → chunk-4n45qa0b.js} +9 -9
- package/dist/chunk-4pjqj54a.js +2 -0
- package/dist/{chunk-9anqwafq.js → chunk-4r2rfdmr.js} +5 -5
- package/dist/{chunk-ft6em3wm.js → chunk-50cnypys.js} +6 -6
- package/dist/chunk-53cc06w7.js +2 -0
- package/dist/{chunk-y2e2zm6y.js → chunk-57q4nvs9.js} +3 -3
- package/dist/{chunk-3mz9bdf7.js → chunk-59er0fc7.js} +3 -3
- package/dist/{chunk-dw0ttj6p.js → chunk-5eftxrvv.js} +2 -2
- package/dist/chunk-5p3825qw.js +2 -0
- package/dist/chunk-5rd0an89.js +2 -0
- package/dist/{chunk-pk714ynv.js → chunk-69ezjc8k.js} +4 -4
- package/dist/{chunk-75v0yxeh.js → chunk-6c1vm6bs.js} +2 -2
- package/dist/{chunk-d3q0cg47.js → chunk-6df3j3qq.js} +3 -3
- package/dist/{chunk-kzc2tqzr.js → chunk-6t04tqvh.js} +2 -2
- package/dist/chunk-78zgmqhd.js +2 -0
- package/dist/chunk-7bsrnpmh.js +33 -0
- package/dist/chunk-7dq6ebvp.js +2 -0
- package/dist/chunk-7kqgp3p7.js +2 -0
- package/dist/{chunk-wzvdr4ta.js → chunk-7mcs59pr.js} +2 -2
- package/dist/chunk-83b9k17j.js +2 -0
- package/dist/chunk-86nsbxep.js +61 -0
- package/dist/{chunk-0g2mg8cw.js → chunk-8e1cv1hh.js} +3 -3
- package/dist/chunk-8h5nje66.js +2 -0
- package/dist/{chunk-ae8q4gze.js → chunk-8va3fs07.js} +5 -5
- package/dist/{chunk-fnjm3xbf.js → chunk-93jhfbeg.js} +6 -6
- package/dist/{chunk-xmws1gaf.js → chunk-94ctmp0j.js} +2 -2
- package/dist/chunk-97kgrevs.js +4 -0
- package/dist/{chunk-qvrew79n.js → chunk-9cbf0seq.js} +2 -2
- package/dist/{chunk-mce3g2wb.js → chunk-9f31gs4m.js} +2 -2
- package/dist/chunk-9kza7gxd.js +2 -0
- package/dist/{chunk-b4d4tjvx.js → chunk-a0q0kb0s.js} +5 -5
- package/dist/chunk-a5gnxdfe.js +2 -0
- package/dist/chunk-a60ztvnp.js +3 -0
- package/dist/{chunk-s7fhpkvf.js → chunk-a7ryj8z8.js} +6 -6
- package/dist/{chunk-gqtb53s8.js → chunk-aaea157p.js} +2 -2
- package/dist/{chunk-wp0qpa50.js → chunk-agd2b928.js} +59 -27
- package/dist/chunk-aqxh80vh.js +2 -0
- package/dist/{chunk-az5rh7fs.js → chunk-awp8a3t4.js} +2 -2
- package/dist/chunk-axra1yas.js +2 -0
- package/dist/chunk-az8b0726.js +21 -0
- package/dist/chunk-b7d3n4aw.js +2 -0
- package/dist/{chunk-r2bxjna3.js → chunk-c0g30cjs.js} +2 -2
- package/dist/{chunk-jt5tzddc.js → chunk-c73c0wf9.js} +2 -2
- package/dist/{chunk-88xayf21.js → chunk-cad7e5q1.js} +9 -9
- package/dist/{chunk-bjjfr7qt.js → chunk-care745q.js} +2 -2
- package/dist/chunk-ce0zbpr5.js +2 -0
- package/dist/chunk-cjv89tnb.js +20 -0
- package/dist/chunk-cv1vm1w0.js +2 -0
- package/dist/{chunk-mw0rb1sf.js → chunk-czcx3nbx.js} +6 -6
- package/dist/chunk-d7b30bg6.js +2 -0
- package/dist/{chunk-stn7p7f1.js → chunk-dwyhpbpx.js} +2 -2
- package/dist/{chunk-y75bds1g.js → chunk-e362e615.js} +30 -30
- package/dist/{chunk-ydppkb8y.js → chunk-e41pgmgk.js} +2 -2
- package/dist/{chunk-6az66mrc.js → chunk-ec5q4nnw.js} +66 -66
- package/dist/{chunk-0h6r7nvn.js → chunk-egjmb32c.js} +126 -71
- package/dist/{chunk-q7zc78az.js → chunk-ew3vs3jq.js} +8 -8
- package/dist/{chunk-jqxerj6k.js → chunk-ezna4dhj.js} +2 -2
- package/dist/chunk-f3j1h3ch.js +2 -0
- package/dist/{chunk-vmssv78v.js → chunk-f7znj9xg.js} +3 -3
- package/dist/chunk-fz4c5e9m.js +2 -0
- package/dist/{chunk-esjr9qhe.js → chunk-g2xy0z0e.js} +2 -2
- package/dist/{chunk-fy6ts0n4.js → chunk-g83ph305.js} +2 -2
- package/dist/{chunk-kywe0f1v.js → chunk-gbncp2gp.js} +2 -2
- package/dist/chunk-gm67jt8p.js +2 -0
- package/dist/chunk-gmp10259.js +2 -0
- package/dist/{chunk-0sa9gqmc.js → chunk-h2tq6cbr.js} +11 -11
- package/dist/chunk-h3fv0q25.js +2 -0
- package/dist/{chunk-r09kz9bf.js → chunk-h63ma36g.js} +2 -2
- package/dist/chunk-hkx51atf.js +2 -0
- package/dist/{chunk-95hbmv7k.js → chunk-hmntqqyd.js} +7 -7
- package/dist/{chunk-3w7gacva.js → chunk-hxhmhw23.js} +3 -3
- package/dist/chunk-jghpzx5m.js +2 -0
- package/dist/chunk-k206d3pn.js +2 -0
- package/dist/chunk-k40e0ete.js +4 -0
- package/dist/chunk-k6c5t9we.js +38 -0
- package/dist/{chunk-f4vgagjb.js → chunk-kee5a3ce.js} +3 -3
- package/dist/chunk-kn9tqjgv.js +25 -0
- package/dist/chunk-kna1bdm2.js +54 -0
- package/dist/{chunk-a5yb8w7s.js → chunk-mygsektn.js} +3 -3
- package/dist/chunk-nb6erf75.js +9 -0
- package/dist/chunk-ngzyzcrp.js +2 -0
- package/dist/{chunk-3f9wctns.js → chunk-nysbdr4r.js} +2 -2
- package/dist/chunk-p55a910x.js +1198 -0
- package/dist/chunk-p6hcrg3r.js +3 -0
- package/dist/chunk-p746twww.js +2 -0
- package/dist/chunk-pa2vt2ej.js +2 -0
- package/dist/chunk-pa6kgbmw.js +2 -0
- package/dist/{chunk-saqzk45g.js → chunk-pdprhg5k.js} +1 -1
- package/dist/chunk-pjjrx9pk.js +2 -0
- package/dist/{chunk-g7qpnmbm.js → chunk-pm4rpc4a.js} +23 -23
- package/dist/chunk-pt3rp3zg.js +2 -0
- package/dist/{chunk-4517hny7.js → chunk-q1mb0fbt.js} +2 -2
- package/dist/{chunk-k1ew643q.js → chunk-q74affc4.js} +2 -2
- package/dist/chunk-qd9v1v8z.js +2 -0
- package/dist/chunk-qfwk93fk.js +2 -0
- package/dist/chunk-qg1kw5yf.js +2 -0
- package/dist/chunk-qn6y5ttj.js +2 -0
- package/dist/chunk-qxcc0aar.js +2 -0
- package/dist/{chunk-rzd9hyhv.js → chunk-ram5944w.js} +2 -2
- package/dist/{chunk-p5m1z6e1.js → chunk-rcxer2km.js} +4 -4
- package/dist/chunk-rdxph1tp.js +2 -0
- package/dist/chunk-rnrdngnn.js +2 -0
- package/dist/{chunk-x2ftkaz3.js → chunk-rsxxajv6.js} +2 -2
- package/dist/chunk-rw5sxr5a.js +2 -0
- package/dist/chunk-rzcdwybt.js +26 -0
- package/dist/chunk-s29hp1qw.js +14 -0
- package/dist/chunk-s7xywsqd.js +3 -0
- package/dist/{chunk-d6gqh2wv.js → chunk-satrf398.js} +1 -1
- package/dist/{chunk-zn6n075d.js → chunk-shcnt6aa.js} +3 -3
- package/dist/{chunk-ysfgabpf.js → chunk-sn4ndpd7.js} +3 -3
- package/dist/{chunk-zc8a2erc.js → chunk-ssg6ne5b.js} +4 -4
- package/dist/{chunk-afxfkb60.js → chunk-sv7fdqmc.js} +6 -6
- package/dist/chunk-swz0xprw.js +2 -0
- package/dist/chunk-t8r40wgf.js +2 -0
- package/dist/{chunk-dbvsa5ya.js → chunk-t94y8g35.js} +2 -2
- package/dist/{chunk-g33ycxe3.js → chunk-t9hxyvvc.js} +5 -5
- package/dist/{chunk-cmh0bfkb.js → chunk-tgzs1kbj.js} +5 -5
- package/dist/chunk-tka73egx.js +2 -0
- package/dist/{chunk-xtaq95em.js → chunk-v1s838fe.js} +1 -1
- package/dist/chunk-v3747589.js +12 -0
- package/dist/chunk-v9h2bbhf.js +2 -0
- package/dist/chunk-v9mxhch2.js +2 -0
- package/dist/chunk-vm42j29z.js +2 -0
- package/dist/chunk-w2kdhm7k.js +2 -0
- package/dist/chunk-w5zzwe2f.js +2 -0
- package/dist/chunk-wbmx0rge.js +2 -0
- package/dist/chunk-wjafpvjv.js +2 -0
- package/dist/chunk-ws2h92mm.js +3 -0
- package/dist/chunk-ws9kr80x.js +2 -0
- package/dist/{chunk-45rzd16g.js → chunk-xf0xacc9.js} +44 -44
- package/dist/chunk-xhr35ctb.js +2 -0
- package/dist/chunk-xmmr0916.js +2 -0
- package/dist/{chunk-yxdhz4ps.js → chunk-xpbakn6t.js} +2 -2
- package/dist/chunk-xz4v9tg1.js +3 -0
- package/dist/chunk-y7e61pz3.js +3 -0
- package/dist/{chunk-v0tdg16k.js → chunk-ybjgnnyf.js} +5 -5
- package/dist/chunk-yh2hnt3m.js +12 -0
- package/dist/{chunk-w6pzkcjp.js → chunk-ymqm898x.js} +2 -2
- package/dist/{chunk-2zaatnnh.js → chunk-yp4tn4zn.js} +4 -4
- package/dist/chunk-z7k1xn6k.js +2 -0
- package/dist/{chunk-t4g3ka8c.js → chunk-z9ffr9gy.js} +7 -7
- package/dist/{chunk-nnp6rf4c.js → chunk-zch65qrd.js} +1 -1
- package/dist/{chunk-pbakxcv8.js → chunk-zek9t5za.js} +2 -2
- package/dist/cli.js +23 -23
- package/dist/client/signals-dom-ready-runtime.js +6 -0
- package/dist/client/signals-mount-runtime.js +1 -1
- package/dist/client-module-registry.js +10 -4
- package/dist/client-parameter-bindings.d.ts +5 -0
- package/dist/client-parameter-bindings.js +47 -6
- package/dist/client-script-bundler.js +4 -3
- package/dist/component-library.d.ts +1 -0
- package/dist/component-library.js +42 -14
- package/dist/composable-loader.js +19 -9
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/html-masking.d.ts +2 -0
- package/dist/html-masking.js +10 -0
- package/dist/inherited-context.d.ts +1 -1
- package/dist/inherited-context.js +43 -14
- package/dist/module-syntax.d.ts +2 -0
- package/dist/module-syntax.js +21 -0
- package/dist/native-component-context.js +44 -17
- package/dist/page-module-order.d.ts +10 -0
- package/dist/page-module-order.js +139 -0
- package/dist/process.js +6 -4
- package/dist/pwa.js +3 -3
- package/dist/script-attributes.d.ts +4 -0
- package/dist/script-attributes.js +10 -0
- package/dist/ssg.js +39 -39
- package/dist/strip-literals.d.ts +2 -0
- package/dist/strip-literals.js +12 -6
- package/dist/stx-virtual-ts.d.ts +1 -0
- package/dist/stx-virtual-ts.js +21 -27
- package/dist/typecheck.js +8 -0
- package/package.json +5 -5
- package/dist/chunk-003ph86a.js +0 -2
- package/dist/chunk-027meh1k.js +0 -2
- package/dist/chunk-0bc3mwqd.js +0 -2
- package/dist/chunk-0gv2mmr0.js +0 -2
- package/dist/chunk-0j8zre1m.js +0 -2
- package/dist/chunk-0qwbhv3f.js +0 -33
- package/dist/chunk-1gfg6qmr.js +0 -2
- package/dist/chunk-1tqp2s13.js +0 -2
- package/dist/chunk-1y7kfp5d.js +0 -2
- package/dist/chunk-1ztp5vkh.js +0 -3
- package/dist/chunk-24e4dapm.js +0 -2
- package/dist/chunk-2qb9kp21.js +0 -25
- package/dist/chunk-32wvc376.js +0 -2
- package/dist/chunk-3te2y9qf.js +0 -2
- package/dist/chunk-447jc6zc.js +0 -2
- package/dist/chunk-51ymssz5.js +0 -2
- package/dist/chunk-6dz5za5z.js +0 -2
- package/dist/chunk-6ezt9kbe.js +0 -54
- package/dist/chunk-6grkdknk.js +0 -2
- package/dist/chunk-6q9a5bph.js +0 -2
- package/dist/chunk-6rqef7wp.js +0 -2
- package/dist/chunk-72p5annm.js +0 -33
- package/dist/chunk-74x6j229.js +0 -4
- package/dist/chunk-7j11vgm1.js +0 -3
- package/dist/chunk-7ngfcdv9.js +0 -2
- package/dist/chunk-7njy024g.js +0 -2
- package/dist/chunk-9e3ggwk7.js +0 -2
- package/dist/chunk-9mz2n39m.js +0 -2
- package/dist/chunk-a262spx7.js +0 -2
- package/dist/chunk-a8wn0snv.js +0 -2
- package/dist/chunk-af6m1s2b.js +0 -3
- package/dist/chunk-b1tcym2x.js +0 -2
- package/dist/chunk-b61dq7pz.js +0 -12
- package/dist/chunk-bdh73gxd.js +0 -4
- package/dist/chunk-bs7g6jtt.js +0 -2
- package/dist/chunk-bspj1rf1.js +0 -2
- package/dist/chunk-bx3hpsxn.js +0 -2
- package/dist/chunk-byq488g4.js +0 -2
- package/dist/chunk-c8pzj57b.js +0 -2
- package/dist/chunk-e2b2f502.js +0 -2
- package/dist/chunk-ec6mrad6.js +0 -2
- package/dist/chunk-eh2gec79.js +0 -2
- package/dist/chunk-em31p5pb.js +0 -2
- package/dist/chunk-eqfsw6x4.js +0 -2
- package/dist/chunk-ey1vwfpc.js +0 -24
- package/dist/chunk-fa57bncd.js +0 -2
- package/dist/chunk-fk79jbzn.js +0 -2
- package/dist/chunk-g97krv0d.js +0 -2
- package/dist/chunk-gn16yq49.js +0 -2
- package/dist/chunk-gvs61tqn.js +0 -2
- package/dist/chunk-h2928108.js +0 -2
- package/dist/chunk-hd5bny2c.js +0 -2
- package/dist/chunk-j1ytbd6r.js +0 -1184
- package/dist/chunk-jm7qa3v3.js +0 -2
- package/dist/chunk-jmjgj3nh.js +0 -2
- package/dist/chunk-jqtpzzz4.js +0 -12
- package/dist/chunk-kq8mffgf.js +0 -2
- package/dist/chunk-kx06jzdw.js +0 -2
- package/dist/chunk-n344ss97.js +0 -2
- package/dist/chunk-n5pvdrkb.js +0 -2
- package/dist/chunk-ne8q191s.js +0 -2
- package/dist/chunk-np8wgbsa.js +0 -3
- package/dist/chunk-p4e8myzj.js +0 -17
- package/dist/chunk-pp99rmjm.js +0 -72
- package/dist/chunk-pqmjeea6.js +0 -2
- package/dist/chunk-q0k2gmva.js +0 -2
- package/dist/chunk-qggwr60r.js +0 -2
- package/dist/chunk-qm3v4qb7.js +0 -2
- package/dist/chunk-qrn1nza9.js +0 -2
- package/dist/chunk-qty0t69x.js +0 -2
- package/dist/chunk-rzadf7vx.js +0 -20
- package/dist/chunk-snz2cxqv.js +0 -2
- package/dist/chunk-ts37jw3s.js +0 -2
- package/dist/chunk-vnrbjbrw.js +0 -3
- package/dist/chunk-wkb7dhp7.js +0 -2
- package/dist/chunk-wxyqp6g9.js +0 -2
- package/dist/chunk-x76qvq1n.js +0 -2
- package/dist/chunk-y4hn1qh0.js +0 -2
- package/dist/chunk-yc8ggeh2.js +0 -2
- package/dist/chunk-ydy0tfar.js +0 -2
- package/dist/chunk-yfed67yc.js +0 -2
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { scanHtmlScriptElements } from "./html-masking.js";
|
|
2
|
+
import { clientMethods, componentScriptSource, componentMetadataBlock, componentDirectiveExpression, parseMetadata, parseNativeComponentLoop, typeForProperty } from "./component-library.js";
|
|
3
|
+
import { scriptAttributes, scriptContainsCode } from "./script-attributes.js";
|
|
4
|
+
import { bracketDepths, stripCommentsAndLiterals } from "./strip-literals.js";
|
|
5
|
+
import { collectImportedNames, extractTypeDeclarations } from "./stx-virtual-ts.js";
|
|
3
6
|
export function nativeComponentContext(source, validate) {
|
|
4
|
-
const scannable = componentScriptSource(source);
|
|
5
|
-
if (
|
|
7
|
+
const scannable = componentScriptSource(source), metadataBlock = componentMetadataBlock(source);
|
|
8
|
+
if (!metadataBlock)
|
|
6
9
|
return;
|
|
7
10
|
let metadata;
|
|
8
11
|
try {
|
|
9
12
|
metadata = parseMetadata(source, "component");
|
|
10
13
|
} catch (error) {
|
|
11
|
-
const at =
|
|
14
|
+
const at = metadataBlock.open, message = error instanceof Error ? error.message : "Invalid component metadata";
|
|
12
15
|
return { declarations: "", checks: [{ text: `({})[${JSON.stringify(message)}];`, line: source.slice(0, at).split(`
|
|
13
16
|
`).length, column: at - source.lastIndexOf(`
|
|
14
17
|
`, at - 1), origin: "component" }], project: (code) => ({ code, columns: new Map }) };
|
|
15
18
|
}
|
|
16
|
-
const blocks =
|
|
17
|
-
const
|
|
18
|
-
return
|
|
19
|
-
}).join(`
|
|
20
|
-
`), methods = clientMethods(script, validate), hasState =
|
|
21
|
-
`interface
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const blocks = scanHtmlScriptElements(scannable).filter((block) => {
|
|
20
|
+
const attributes = scriptAttributes(block.attrs);
|
|
21
|
+
return scriptContainsCode(attributes) && attributes.has("client") && !attributes.has("server") && !attributes.has("component") && !attributes.has("stx:component") && !attributes.has("src");
|
|
22
|
+
}), script = blocks.map((block) => source.slice(block.bodyStart, block.bodyEnd)).join(`
|
|
23
|
+
`), methods = clientMethods(script, validate), hasState = extractTypeDeclarations(script).some((type) => type.name === "ComponentState") || collectImportedNames(script).includes("ComponentState"), properties = Object.entries(metadata.properties || metadata.props || {}).map(([name, property]) => `${JSON.stringify(name)}: ${typeForProperty(property)}`).join("; "), names = [...new Set(methods.map((method) => method.name))], declarations = [
|
|
24
|
+
`interface __StxMetadataProperties { ${properties} }`,
|
|
25
|
+
"type __StxNativeProperties = Omit<__StxMetadataProperties, keyof HTMLElement> & Pick<HTMLElement, Extract<keyof __StxMetadataProperties, keyof HTMLElement>>;",
|
|
26
|
+
"type __StxAny<T> = 0 extends (1 & T) ? true : false;",
|
|
27
|
+
"type __StxAnyFields<T> = { [K in keyof T]-?: __StxAny<T[K]> extends true ? K : never }[keyof T];",
|
|
28
|
+
"type __StxSpecific<T> = __StxAny<T> extends true ? false : T extends object ? string extends keyof T ? false : number extends keyof T ? false : symbol extends keyof T ? false : __StxAnyFields<T> extends never ? true : false : false;",
|
|
29
|
+
hasState ? "type __StxState = __StxSpecific<ComponentState> extends true ? ComponentState : {};" : "type __StxState = {};",
|
|
30
|
+
hasState ? 'declare function __stxSpecificState(value: __StxSpecific<ComponentState> extends true ? true : "ComponentState requires named explicit fields without any or index signatures"): void;' : "",
|
|
31
|
+
hasState ? "declare const __stxStateProperties: Pick<ComponentState, Extract<keyof ComponentState, keyof __StxInstanceProperties>>;" : "",
|
|
32
|
+
hasState ? 'declare function __stxStateMethods(value: Extract<keyof ComponentState, __StxMethodNames | "emit" | "requestUpdate" | "updateComplete" | "renderRoot"> extends never ? true : "ComponentState cannot redeclare component methods"): void;' : "",
|
|
33
|
+
`type __StxMethodNames = ${names.map((name) => JSON.stringify(name)).join(" | ") || "never"};`,
|
|
34
|
+
"type __StxInstanceProperties = Omit<HTMLElement, __StxMethodNames | keyof __StxNativeProperties> & __StxNativeProperties;",
|
|
35
|
+
'type __StxPrivateKeys<T> = Exclude<keyof T, keyof HTMLElement | keyof __StxNativeProperties | __StxMethodNames | "emit" | "updateComplete" | "requestUpdate" | "renderRoot">;',
|
|
36
|
+
hasState ? 'declare function __stxOptionalPrivate(value: { [K in __StxPrivateKeys<ComponentState>]-?: {} extends Pick<ComponentState, K> ? never : K }[__StxPrivateKeys<ComponentState>] extends never ? true : "Private ComponentState fields must be optional until initialized"): void;' : "",
|
|
37
|
+
"type __StxRefinedProperties = { [K in keyof __StxNativeProperties]: K extends keyof __StxState ? __StxAny<__StxState[K]> extends true ? __StxNativeProperties[K] : __StxState[K] extends __StxNativeProperties[K] ? __StxState[K] : __StxNativeProperties[K] : __StxNativeProperties[K] };",
|
|
38
|
+
"type __StxNativeComponent = Omit<HTMLElement, keyof __StxNativeProperties | __StxMethodNames> & __StxRefinedProperties & Partial<Pick<__StxState, __StxPrivateKeys<__StxState>>> & {",
|
|
24
39
|
"readonly updateComplete: Promise<void>; requestUpdate(): Promise<void>; readonly renderRoot: HTMLElement | ShadowRoot;",
|
|
25
40
|
"emit<T = unknown>(name: string, detail?: T, options?: CustomEventInit<T>): boolean;",
|
|
26
41
|
...names.map((name) => `${JSON.stringify(name)}: typeof ${name};`),
|
|
@@ -29,17 +44,29 @@ export function nativeComponentContext(source, validate) {
|
|
|
29
44
|
`);
|
|
30
45
|
let stateOffset = -1;
|
|
31
46
|
for (const block of blocks) {
|
|
32
|
-
const bodyStart = block.
|
|
47
|
+
const bodyStart = block.bodyStart, code = source.slice(bodyStart, block.bodyEnd), masked = stripCommentsAndLiterals(code), depths = bracketDepths(masked).depths, found = [...masked.matchAll(/\b(?:interface|type)\s+ComponentState\b/g)].find((match) => depths[match.index] === 0) ?? (collectImportedNames(code).includes("ComponentState") ? /\bComponentState\b/.exec(masked) : void 0);
|
|
33
48
|
if (found) {
|
|
34
49
|
stateOffset = bodyStart + found.index;
|
|
35
50
|
break;
|
|
36
51
|
}
|
|
37
52
|
}
|
|
38
|
-
const checks = hasState && stateOffset >= 0 ? [{ origin: "client", text: "__stxStateProperties satisfies Pick<
|
|
53
|
+
const checks = hasState && stateOffset >= 0 ? [{ origin: "client", text: "__stxSpecificState(true); __stxStateMethods(true); __stxOptionalPrivate(true); __stxStateProperties satisfies Pick<__StxInstanceProperties, Extract<keyof ComponentState, keyof __StxInstanceProperties>>;", line: source.slice(0, stateOffset).split(`
|
|
39
54
|
`).length, column: stateOffset - source.lastIndexOf(`
|
|
40
|
-
`, stateOffset - 1) }] : [];
|
|
55
|
+
`, stateOffset - 1) }] : [], { start: metadataStart, code: raw } = metadataBlock, maskedMetadata = stripCommentsAndLiterals(raw), metadataDepths = bracketDepths(maskedMetadata).depths, positions = new Map;
|
|
56
|
+
let inProperties = !1;
|
|
57
|
+
for (const token of raw.matchAll(/"(?:\\.|[^"\\])*"\s*:/g)) {
|
|
58
|
+
const key = JSON.parse(token[0].slice(0, token[0].lastIndexOf(":")).trim());
|
|
59
|
+
if (metadataDepths[token.index] === 1 && ["properties", "props"].includes(key)) {
|
|
60
|
+
inProperties = !0;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (inProperties && metadataDepths[token.index] === 1)
|
|
64
|
+
inProperties = !1;
|
|
65
|
+
if (inProperties && metadataDepths[token.index] === 2 && !positions.has(key))
|
|
66
|
+
positions.set(key, metadataStart + token.index);
|
|
67
|
+
}
|
|
41
68
|
for (const [name, property] of Object.entries(metadata.properties || metadata.props || {})) {
|
|
42
|
-
const at =
|
|
69
|
+
const at = positions.get(name) ?? metadataStart, line = source.slice(0, at).split(`
|
|
43
70
|
`).length, column = at - source.lastIndexOf(`
|
|
44
71
|
`, at - 1);
|
|
45
72
|
if (!property || typeof property !== "object" || !["string", "number", "boolean", "object", "array"].includes(property.type))
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function usesImportMeta(code: string): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Module tags alone do not order completion when one uses top-level await.
|
|
4
|
+
* Register an explicit promise before each affected module. Subsequent page
|
|
5
|
+
* initializers join that promise chain while retaining their classic scope.
|
|
6
|
+
* The runtime and SPA router await the final promise before hydration.
|
|
7
|
+
* Component setup registrations remain synchronous: their bodies execute at
|
|
8
|
+
* hydration, and structural clones must retain their native setup protocol.
|
|
9
|
+
*/
|
|
10
|
+
export declare function orderPageModules(html: string): string;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { scanHtmlTags } from "./html-masking.js";
|
|
2
|
+
import { scriptAttributes } from "./script-attributes.js";
|
|
3
|
+
import { requiresAsyncBody } from "./module-syntax.js";
|
|
4
|
+
import { stripBindingLiterals } from "./strip-literals.js";
|
|
5
|
+
export function usesImportMeta(code) {
|
|
6
|
+
return /\bimport\s*\.\s*meta\b/.test(stripBindingLiterals(code));
|
|
7
|
+
}
|
|
8
|
+
function pageScripts(html) {
|
|
9
|
+
const tags = scanHtmlTags(html), scripts = [];
|
|
10
|
+
let templateDepth = 0;
|
|
11
|
+
for (let index = 0;index < tags.length; index++) {
|
|
12
|
+
const tag = tags[index], name = tag.name.toLowerCase();
|
|
13
|
+
if (name === "template")
|
|
14
|
+
templateDepth += tag.closing ? -1 : 1;
|
|
15
|
+
if (name !== "script" || tag.closing)
|
|
16
|
+
continue;
|
|
17
|
+
const close = tags[index + 1];
|
|
18
|
+
if (close?.name.toLowerCase() !== "script" || !close.closing)
|
|
19
|
+
continue;
|
|
20
|
+
scripts.push({ start: tag.start, end: close.end, attrs: tag.attributes, body: html.slice(tag.end, close.start), inert: templateDepth > 0 });
|
|
21
|
+
}
|
|
22
|
+
return scripts;
|
|
23
|
+
}
|
|
24
|
+
function renderAttributes(attrs) {
|
|
25
|
+
return [...attrs].map(([name, value]) => value === !0 ? name : `${name}="${value.replace(/"/g, """)}"`).join(" ");
|
|
26
|
+
}
|
|
27
|
+
export function orderPageModules(html) {
|
|
28
|
+
const scripts = pageScripts(html);
|
|
29
|
+
if (scripts.some((script) => scriptAttributes(script.attrs).has("data-stx-module-bootstrap")))
|
|
30
|
+
return html;
|
|
31
|
+
const needsModule = (body) => {
|
|
32
|
+
if (usesImportMeta(body))
|
|
33
|
+
return !0;
|
|
34
|
+
try {
|
|
35
|
+
return requiresAsyncBody(body);
|
|
36
|
+
} catch {
|
|
37
|
+
return !1;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
if (!scripts.some((script) => needsModule(script.body) || scriptAttributes(script.attrs).get("type") === "module"))
|
|
41
|
+
return html;
|
|
42
|
+
const batch = new Bun.CryptoHasher("md5").update(html).digest("hex").slice(0, 16);
|
|
43
|
+
let result = "", cursor = 0, started = !1, index = 0;
|
|
44
|
+
for (const script of scripts) {
|
|
45
|
+
const attrs = scriptAttributes(script.attrs), type = attrs.get("type");
|
|
46
|
+
if (script.inert || attrs.has("data-stx-module-job") || attrs.has("data-stx-runtime") || attrs.has("data-stx-router"))
|
|
47
|
+
continue;
|
|
48
|
+
if (typeof type === "string" && !["module", "text/javascript", "application/javascript"].includes(type.toLowerCase()))
|
|
49
|
+
continue;
|
|
50
|
+
if (![...attrs.keys()].some((name) => /^data-stx-(?:scoped|modules|stores|(?:framework-)?composables)$/.test(name)))
|
|
51
|
+
continue;
|
|
52
|
+
const module = type === "module" || needsModule(script.body);
|
|
53
|
+
if (module)
|
|
54
|
+
started = !0;
|
|
55
|
+
if (!started)
|
|
56
|
+
continue;
|
|
57
|
+
if (!module && (attrs.has("data-stx-owner") || attrs.has("data-stx-instance")))
|
|
58
|
+
continue;
|
|
59
|
+
result += html.slice(cursor, script.start);
|
|
60
|
+
let body = script.body;
|
|
61
|
+
const src = attrs.get("src");
|
|
62
|
+
if (typeof src === "string") {
|
|
63
|
+
attrs.delete("src");
|
|
64
|
+
attrs.set("data-stx-source-url", src);
|
|
65
|
+
body = `${module ? "await" : "return"} new Promise(function(resolve,reject){
|
|
66
|
+
var source=globalThis.__stxExecutingScript,script=document.createElement('script');
|
|
67
|
+
for(var attr of source.attributes)if(!['type','src','data-stx-module-job'].includes(attr.name))script.setAttribute(attr.name,attr.value);
|
|
68
|
+
${module ? "script.type='module';" : ""}
|
|
69
|
+
if(source.nonce)script.nonce=source.nonce;
|
|
70
|
+
script.src=new URL(source.getAttribute('data-stx-source-url'),document.baseURI).href;
|
|
71
|
+
script.onload=function(){${module ? "" : "globalThis.__stxExecutingScript=__stxPreviousScript;"}resolve();};
|
|
72
|
+
script.onerror=function(error){${module ? "" : "globalThis.__stxExecutingScript=__stxPreviousScript;"}reject(error);};
|
|
73
|
+
source.parentNode.insertBefore(script,source);
|
|
74
|
+
});`;
|
|
75
|
+
}
|
|
76
|
+
if (module) {
|
|
77
|
+
const job = `${batch}-${index++}`, key = JSON.stringify(job), bootstrapAttrs = new Map(attrs);
|
|
78
|
+
bootstrapAttrs.delete("type");
|
|
79
|
+
bootstrapAttrs.delete("async");
|
|
80
|
+
bootstrapAttrs.delete("defer");
|
|
81
|
+
bootstrapAttrs.set("data-stx-module-bootstrap", !0);
|
|
82
|
+
result += `<script ${renderAttributes(bootstrapAttrs)}>
|
|
83
|
+
;(function(){
|
|
84
|
+
var resolve,reject,previous=globalThis.__stxPageModulesReady||Promise.resolve();
|
|
85
|
+
var ready=new Promise(function(ok,fail){resolve=ok;reject=fail;});
|
|
86
|
+
var job={previous:previous,resolve:resolve,reject:reject};
|
|
87
|
+
(globalThis.__stxModuleJobs||(globalThis.__stxModuleJobs={}))[${key}]=job;
|
|
88
|
+
job.fail=function(event){
|
|
89
|
+
var script=document.querySelector('script[data-stx-module-job="${job}"]');
|
|
90
|
+
if((event.target&&event.target===script)||(event.filename&&event.filename===(script&&script.src||document.URL))){
|
|
91
|
+
window.removeEventListener('error',job.fail,true);
|
|
92
|
+
if(globalThis.__stxExecutingScript===job.script)globalThis.__stxExecutingScript=job.previousScript;
|
|
93
|
+
reject(event.error||new Error(event.message||'Page module failed to load'));
|
|
94
|
+
delete globalThis.__stxModuleJobs[${key}];
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
window.addEventListener('error',job.fail,true);
|
|
98
|
+
globalThis.__stxPageModulesReady=ready;
|
|
99
|
+
ready.catch(function(error){console.error('[stx] page module failed',error);});
|
|
100
|
+
})();
|
|
101
|
+
</script>`;
|
|
102
|
+
attrs.set("type", "module");
|
|
103
|
+
attrs.delete("async");
|
|
104
|
+
attrs.delete("defer");
|
|
105
|
+
attrs.set("data-stx-module-job", job);
|
|
106
|
+
result += `<script ${renderAttributes(attrs)}>
|
|
107
|
+
await globalThis.__stxModuleJobs[${key}].previous;
|
|
108
|
+
globalThis.__stxModuleJobs[${key}].previousScript=globalThis.__stxExecutingScript;
|
|
109
|
+
globalThis.__stxModuleJobs[${key}].script=document.querySelector('script[data-stx-module-job="${job}"]');
|
|
110
|
+
globalThis.__stxExecutingScript=globalThis.__stxModuleJobs[${key}].script;
|
|
111
|
+
${body}
|
|
112
|
+
globalThis.__stxExecutingScript=globalThis.__stxModuleJobs[${key}].previousScript;
|
|
113
|
+
window.removeEventListener('error',globalThis.__stxModuleJobs[${key}].fail,true);
|
|
114
|
+
globalThis.__stxModuleJobs[${key}].resolve();
|
|
115
|
+
delete globalThis.__stxModuleJobs[${key}];
|
|
116
|
+
</script>`;
|
|
117
|
+
} else
|
|
118
|
+
result += `<script ${renderAttributes(attrs)}>
|
|
119
|
+
;(function(__stxSource){
|
|
120
|
+
globalThis.__stxPageModulesReady=(globalThis.__stxPageModulesReady||Promise.resolve()).then(function(){
|
|
121
|
+
var __stxPreviousScript=globalThis.__stxExecutingScript;
|
|
122
|
+
globalThis.__stxExecutingScript=__stxSource;
|
|
123
|
+
${typeof src === "string" ? body : `var __stxLive=document.createElement('script');
|
|
124
|
+
for(var __stxAttr of __stxSource.attributes)if(!['src','type'].includes(__stxAttr.name))__stxLive.setAttribute(__stxAttr.name,__stxAttr.value);
|
|
125
|
+
if(__stxSource.nonce)__stxLive.nonce=__stxSource.nonce;
|
|
126
|
+
__stxLive.textContent=${JSON.stringify(body).replace(/<\/script/gi, "<\\/script")};
|
|
127
|
+
var __stxFailure;
|
|
128
|
+
function __stxCapture(event){__stxFailure=event.error||new Error(event.message);}
|
|
129
|
+
window.addEventListener('error',__stxCapture);
|
|
130
|
+
try { __stxSource.parentNode.replaceChild(__stxLive,__stxSource); }
|
|
131
|
+
finally { window.removeEventListener('error',__stxCapture); globalThis.__stxExecutingScript=__stxPreviousScript; }
|
|
132
|
+
if(__stxFailure)throw __stxFailure;`}
|
|
133
|
+
});
|
|
134
|
+
})(document.currentScript);
|
|
135
|
+
</script>`;
|
|
136
|
+
cursor = script.end;
|
|
137
|
+
}
|
|
138
|
+
return result + html.slice(cursor);
|
|
139
|
+
}
|
package/dist/process.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { requiresAsyncBody } from "./module-syntax.js";
|
|
2
|
+
import { orderPageModules, usesImportMeta } from "./page-module-order.js";
|
|
1
3
|
import { bodyCloseIndex, headCloseIndex, insertBeforeHeadClose } from "./document-tags.js";
|
|
2
4
|
import fs from "node:fs";
|
|
3
5
|
import path from "node:path";
|
|
@@ -223,7 +225,7 @@ function findScriptBlockByAttribute(html, attribute) {
|
|
|
223
225
|
}
|
|
224
226
|
const EXTERNAL_BUNDLE_MIN_BYTES = 4096;
|
|
225
227
|
async function externalBundleTag(attrs, code, options) {
|
|
226
|
-
if (options.buildMode !== "serve" || code.length < EXTERNAL_BUNDLE_MIN_BYTES)
|
|
228
|
+
if (usesImportMeta(code) || requiresAsyncBody(code) || options.buildMode !== "serve" || code.length < EXTERNAL_BUNDLE_MIN_BYTES)
|
|
227
229
|
return null;
|
|
228
230
|
const { registerServeModuleBundle } = await import("./caching.js");
|
|
229
231
|
return `<script ${attrs} src="${registerServeModuleBundle(code)}"></script>`;
|
|
@@ -242,7 +244,7 @@ export async function buildModulesTag(sources, options, dependencies, built) {
|
|
|
242
244
|
}
|
|
243
245
|
if (!code)
|
|
244
246
|
return null;
|
|
245
|
-
if (options.buildMode === "serve") {
|
|
247
|
+
if (options.buildMode === "serve" && !usesImportMeta(code) && !requiresAsyncBody(code)) {
|
|
246
248
|
const { registerServeModuleBundle } = await import("./caching.js");
|
|
247
249
|
return `<script data-stx-scoped data-stx-run="always" data-stx-modules src="${registerServeModuleBundle(code)}"></script>`;
|
|
248
250
|
}
|
|
@@ -295,7 +297,7 @@ async function buildPageBundles(result, options, dependencies, context) {
|
|
|
295
297
|
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [built.modulesCode ?? built.modulesTag, storeScan, built.frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(options._layerComposableDirs ?? resolvedComposablesDir, result, pending, composableInputs);
|
|
296
298
|
if (composableCode) {
|
|
297
299
|
built.composableCode = composableCode;
|
|
298
|
-
built.composableTag = await externalBundleTag('data-stx-scoped data-stx-run="always" data-stx-composables', composableCode, options) ?? `<script data-stx-scoped data-stx-run="always" data-stx-composables>${composableCode}</script>`;
|
|
300
|
+
built.composableTag = await externalBundleTag('data-stx-scoped data-stx-run="always" data-stx-composables', composableCode, options) ?? `<script data-stx-scoped data-stx-run="always" data-stx-composables>${composableCode.replace(/<\/script/gi, "<\\/script")}</script>`;
|
|
299
301
|
}
|
|
300
302
|
} catch {}
|
|
301
303
|
if (everyStore || !storeLoader)
|
|
@@ -495,7 +497,7 @@ ${tag}`).join(""));
|
|
|
495
497
|
result = result.slice(0, at) + dataTag + result.slice(at);
|
|
496
498
|
}
|
|
497
499
|
}
|
|
498
|
-
return result;
|
|
500
|
+
return isTopLevel ? orderPageModules(result) : result;
|
|
499
501
|
});
|
|
500
502
|
} catch (error) {
|
|
501
503
|
if (error instanceof StxValidationError)
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
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{bo,en,Xl,tm}from"./chunk-69ezjc8k.js";import{yo,ta,Zg,Qg,em}from"./chunk-50cnypys.js";import{ql,Kl,Gl,Jg,Yg}from"./chunk-e41pgmgk.js";import{tt,Fn,na}from"./chunk-02qmvcmv.js";import{nm,rm,sm,om,wo,Vy}from"./chunk-dwyhpbpx.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-rnrdngnn.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=
|
|
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=tt(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=bo(n,t);if(a){let s=en(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 ta(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,Kl as auditBuildOutput,ql as auditConfig,re as buildPwaAssets,Gl as calculateAuditResult,Yg as formatAuditResult,na as formatSize,j as generateManifest,_ as generateManifestJson,Qg as generateManifestLink,F as generateOfflinePage,tt as generatePrecacheManifest,Fn as generatePrecacheManifestJs,M as generatePwaIcons,yo as generatePwaTags,bo as generateServiceWorker,tm as generateServiceWorkerAuto,Zg as generateSwRegistrationScript,em as generateThemeColorMeta,N as getExpectedIconPaths,en as getServiceWorkerFileName,ta as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Xl as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,wo as pwaDirectives,nm as pwaInstallDirective,sm as pwaOfflineDirective,om as pwaPushDirective,rm as pwaUpdateDirective,Vy as registerPwaDirectives,Jg as runPwaAudit,D as validateManifest};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Script mode is an attribute name, never a word inside an attribute value. */
|
|
2
|
+
export declare function scriptAttributes(source: string): Map<string, string | true>;
|
|
3
|
+
/** Authored JavaScript/TypeScript bodies, excluding data and template script types. */
|
|
4
|
+
export declare function scriptContainsCode(attributes: ReadonlyMap<string, string | true>): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function scriptAttributes(source) {
|
|
2
|
+
const attributes = new Map;
|
|
3
|
+
for (const match of source.matchAll(/([^\s=/>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/g))
|
|
4
|
+
attributes.set(match[1].toLowerCase(), match[2] ?? match[3] ?? match[4] ?? !0);
|
|
5
|
+
return attributes;
|
|
6
|
+
}
|
|
7
|
+
export function scriptContainsCode(attributes) {
|
|
8
|
+
const type = attributes.get("type");
|
|
9
|
+
return typeof type !== "string" || !type.trim() || /^(?:module|(?:text|application)\/(?:javascript|typescript|ecmascript))$/i.test(type.trim());
|
|
10
|
+
}
|