@stacksjs/stx 0.2.755 → 0.2.759
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-0dsykna3.js → chunk-00ns0516.js} +5 -5
- package/dist/chunk-055v5qz2.js +2 -0
- package/dist/{chunk-kjfzkac7.js → chunk-06zn167b.js} +7 -7
- package/dist/{chunk-024m1xmd.js → chunk-0dkd26t4.js} +5 -5
- package/dist/{chunk-gzbmfwxr.js → chunk-0e9xdrzx.js} +4 -4
- package/dist/chunk-0j7e56zm.js +2 -0
- package/dist/{chunk-8wbgq43c.js → chunk-0jn79fkt.js} +3 -3
- package/dist/chunk-0y44f9rk.js +2 -0
- package/dist/{chunk-d73hh5ar.js → chunk-11kejz35.js} +1 -1
- package/dist/{chunk-p33w8zst.js → chunk-1mfj2j5g.js} +3 -3
- package/dist/{chunk-vc4jww9y.js → chunk-2x112fxs.js} +13 -13
- package/dist/{chunk-6ywa41tr.js → chunk-3ajnrfa2.js} +2 -2
- package/dist/{chunk-3z38swhv.js → chunk-3cn9y08d.js} +7 -7
- package/dist/chunk-3h2yz805.js +2 -0
- package/dist/chunk-3jfes9b0.js +2 -0
- package/dist/{chunk-nsjkmpjf.js → chunk-3kfbs0mw.js} +1 -1
- package/dist/{chunk-z5kdmget.js → chunk-3nxe5xmy.js} +3 -3
- package/dist/{chunk-p2v0r96k.js → chunk-42hcspws.js} +2 -2
- package/dist/{chunk-0tgrqhkr.js → chunk-465resq9.js} +11 -11
- package/dist/{chunk-m0shnhth.js → chunk-4m8bexrn.js} +3 -3
- package/dist/{chunk-8wbcy0cn.js → chunk-4npabwne.js} +3 -3
- package/dist/{chunk-xrzghjvy.js → chunk-4s9kytdz.js} +2 -2
- package/dist/chunk-4tz00fkp.js +2 -0
- package/dist/{chunk-dvakr9p9.js → chunk-4zw118tn.js} +4 -4
- package/dist/chunk-52q8184e.js +2 -0
- package/dist/chunk-59ytzyp1.js +2 -0
- package/dist/chunk-5ffdtfwg.js +2 -0
- package/dist/{chunk-g223zsce.js → chunk-5ge5h2y3.js} +3 -3
- package/dist/chunk-5q551m4w.js +2 -0
- package/dist/{chunk-cb4ybh7g.js → chunk-5q9ss7ty.js} +4 -4
- package/dist/{chunk-txgd0sj1.js → chunk-6n195hvc.js} +5 -5
- package/dist/chunk-6xt3kvq1.js +2 -0
- package/dist/chunk-75r09rqt.js +2 -0
- package/dist/{chunk-90gx5qxn.js → chunk-76fcwbe1.js} +4 -4
- package/dist/chunk-79y41h1d.js +2 -0
- package/dist/{chunk-9r3ehqtx.js → chunk-7g9vd5fv.js} +2 -2
- package/dist/chunk-7h5d35bf.js +2 -0
- package/dist/{chunk-73b6sst8.js → chunk-7r7j7vwt.js} +3 -3
- package/dist/chunk-82ybmdqk.js +2 -0
- package/dist/{chunk-g22absm0.js → chunk-83ezv8yz.js} +2 -2
- package/dist/chunk-8frs2dtp.js +2 -0
- package/dist/chunk-8n2gj4q2.js +11 -0
- package/dist/chunk-8prq9t3b.js +2 -0
- package/dist/chunk-8sxngenk.js +2 -0
- package/dist/chunk-90er677t.js +2 -0
- package/dist/{chunk-bkkwdh13.js → chunk-93j4atq9.js} +2 -2
- package/dist/{chunk-1a2cwee1.js → chunk-9s1qnf90.js} +2 -2
- package/dist/{chunk-j3d9zknp.js → chunk-a5d888es.js} +6 -6
- package/dist/chunk-aakkjjgr.js +2 -0
- package/dist/chunk-abs1k04e.js +2 -0
- package/dist/{chunk-0vvb78yj.js → chunk-asp7ett1.js} +5 -5
- package/dist/{chunk-7mm5mvg0.js → chunk-b6g24qj0.js} +2 -2
- package/dist/{chunk-7djnbbeb.js → chunk-bsq9zg9j.js} +6 -6
- package/dist/{chunk-7ycf8a8d.js → chunk-c05r0rzw.js} +2 -2
- package/dist/{chunk-g45p4y4v.js → chunk-cehjp06v.js} +3 -3
- package/dist/chunk-cpep999n.js +2 -0
- package/dist/chunk-cvwn6mga.js +2 -0
- package/dist/chunk-davr7z73.js +2 -0
- package/dist/{chunk-vpa4xzz3.js → chunk-dh9aagwm.js} +1 -1
- package/dist/chunk-dqs4bgec.js +2 -0
- package/dist/chunk-e30kgg28.js +2 -0
- package/dist/chunk-e3fkq9gb.js +2 -0
- package/dist/chunk-eab8na0z.js +2 -0
- package/dist/chunk-exg7ry7b.js +2 -0
- package/dist/chunk-f4mmk2cx.js +2 -0
- package/dist/chunk-fhwn8j9p.js +2 -0
- package/dist/chunk-fj105fff.js +2 -0
- package/dist/{chunk-cmaxdd8d.js → chunk-fjxhga6w.js} +2 -2
- package/dist/{chunk-thr1m7k7.js → chunk-fpagqrd1.js} +22 -22
- package/dist/chunk-g387j1qv.js +2 -0
- package/dist/{chunk-zqmvhg37.js → chunk-geb6zyxg.js} +10 -10
- package/dist/chunk-gefpzry6.js +2 -0
- package/dist/chunk-ghzycypz.js +2 -0
- package/dist/{chunk-sj2a5twe.js → chunk-gs373714.js} +2 -2
- package/dist/{chunk-nzy4set0.js → chunk-gs6wc7sr.js} +5 -5
- package/dist/chunk-gvaee1w0.js +170 -0
- package/dist/{chunk-5q2tfrcw.js → chunk-gz38jt5j.js} +2 -2
- package/dist/{chunk-pydmzvpq.js → chunk-h692k9xn.js} +1 -1
- package/dist/{chunk-81ysx0tc.js → chunk-hk98vptc.js} +2 -2
- package/dist/{chunk-xzz36k99.js → chunk-hmae7ha6.js} +2 -2
- package/dist/{chunk-qxrsm48h.js → chunk-hmydy949.js} +5 -5
- package/dist/{chunk-7r5vhqtz.js → chunk-j04v4rgf.js} +4 -4
- package/dist/{chunk-1tmq09ch.js → chunk-j4snweyz.js} +3 -3
- package/dist/{chunk-d2vsw1j7.js → chunk-jb1dk0w7.js} +2 -2
- package/dist/{chunk-5evgz54v.js → chunk-jevd16gq.js} +30 -30
- package/dist/{chunk-41sq06t2.js → chunk-jt28zh50.js} +2 -2
- package/dist/chunk-k37472gm.js +2 -0
- package/dist/chunk-k3wnmpt3.js +2 -0
- package/dist/chunk-kfqdx75m.js +2 -0
- package/dist/{chunk-9q1kkfv1.js → chunk-kpr09x3g.js} +6 -6
- package/dist/{chunk-3ap06zzx.js → chunk-m00c7sh0.js} +1 -1
- package/dist/{chunk-8w0cwcvk.js → chunk-m5fjhrpd.js} +62 -62
- package/dist/{chunk-mpmx0n3q.js → chunk-mcynmrbe.js} +26 -26
- package/dist/chunk-mgx71bfg.js +2 -0
- package/dist/chunk-mmhbn7xt.js +2 -0
- package/dist/{chunk-0md73jp8.js → chunk-myynywry.js} +2 -2
- package/dist/chunk-mzcbfra0.js +2 -0
- package/dist/{chunk-j5p191zq.js → chunk-nv9dy71x.js} +7 -7
- package/dist/chunk-ny2qzraq.js +2 -0
- package/dist/{chunk-q0f28539.js → chunk-pes27snj.js} +2 -2
- package/dist/chunk-pg15tx9c.js +2 -0
- package/dist/chunk-ppc5s12t.js +2 -0
- package/dist/{chunk-0dt7ax79.js → chunk-prej5pk6.js} +2 -2
- package/dist/chunk-ptzzpf97.js +2 -0
- package/dist/{chunk-df8cbgf0.js → chunk-pwmkhs7z.js} +2 -2
- package/dist/chunk-qgsrxyh9.js +2 -0
- package/dist/chunk-qmxcs806.js +2 -0
- package/dist/chunk-qn4gt8sx.js +3 -0
- package/dist/chunk-qryg0hgn.js +2 -0
- package/dist/chunk-qt17792g.js +2 -0
- package/dist/{chunk-236bdf7y.js → chunk-qwds327k.js} +2 -2
- package/dist/{chunk-c3dphs36.js → chunk-qwsgc5rc.js} +1 -1
- package/dist/chunk-qz9fzz5k.js +2 -0
- package/dist/{chunk-5wcgg5t4.js → chunk-r4sawwmp.js} +1 -1
- package/dist/chunk-r5jytt0f.js +20 -0
- package/dist/chunk-rh90yh1c.js +2 -0
- package/dist/chunk-rvc0pb16.js +2 -0
- package/dist/{chunk-fxftc455.js → chunk-s4y26fk6.js} +2 -2
- package/dist/{chunk-v0s52tmv.js → chunk-sgm6tg8h.js} +2 -2
- package/dist/chunk-sj5t0tnv.js +2 -0
- package/dist/{chunk-yd2nj0rv.js → chunk-spjpdymh.js} +1 -1
- package/dist/{chunk-nmy72s6r.js → chunk-t4mpq6t0.js} +2 -2
- package/dist/{chunk-np8knskz.js → chunk-t5gabs4x.js} +1 -1
- package/dist/{chunk-4zta7ay1.js → chunk-t6qn1374.js} +2 -2
- package/dist/{chunk-4fc8zs15.js → chunk-tb56j1zt.js} +5 -5
- package/dist/chunk-tb6jcr2v.js +2 -0
- package/dist/chunk-v20cwjgz.js +17 -0
- package/dist/{chunk-k9m36nyw.js → chunk-v2egd4zh.js} +5 -5
- package/dist/{chunk-0fweckq5.js → chunk-vh1d5eqk.js} +6 -6
- package/dist/{chunk-fa3ygt8c.js → chunk-w8p1y4c0.js} +4 -4
- package/dist/{chunk-j2hm8v8b.js → chunk-wp9y6x33.js} +4 -4
- package/dist/{chunk-g5sctfwa.js → chunk-x1q2ape8.js} +10 -10
- package/dist/{chunk-x5sy0tym.js → chunk-x9haxcsj.js} +6 -6
- package/dist/chunk-xcq41ah8.js +2 -0
- package/dist/chunk-y3jbkk7a.js +2 -0
- package/dist/{chunk-fmxtnva8.js → chunk-yftw25sa.js} +2 -2
- package/dist/chunk-yme43vbp.js +2 -0
- package/dist/{chunk-m6w75sq2.js → chunk-yp6w740k.js} +2 -2
- package/dist/chunk-yv8jeqdn.js +2 -0
- package/dist/{chunk-k4dn3ry6.js → chunk-z8k3fx4r.js} +4 -4
- package/dist/chunk-zq7g0687.js +2 -0
- package/dist/{chunk-c85j39f7.js → chunk-ztdjdxjt.js} +3 -3
- package/dist/cli.js +19 -19
- package/dist/client-module-registry.d.ts +56 -0
- package/dist/client-module-registry.js +249 -9
- package/dist/client-script-bundler.d.ts +17 -0
- package/dist/client-script-bundler.js +58 -11
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/native/compiler/bundle.d.ts +1 -0
- package/dist/native/compiler/bundle.js +102 -11
- package/dist/native/compiler/render-screen.js +13 -6
- package/dist/native/compiler/setup-script.d.ts +1 -0
- package/dist/native/compiler/shared-scripts.d.ts +12 -0
- package/dist/native/compiler/shared-scripts.js +83 -0
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +4 -4
- package/dist/store-loader.d.ts +23 -0
- package/dist/store-loader.js +93 -19
- package/package.json +5 -5
- package/dist/chunk-1gan06yr.js +0 -2
- package/dist/chunk-1menbxwb.js +0 -2
- package/dist/chunk-1n2d3cy5.js +0 -2
- package/dist/chunk-2vc2pkyz.js +0 -2
- package/dist/chunk-33bp9m4c.js +0 -2
- package/dist/chunk-361yezje.js +0 -2
- package/dist/chunk-45cvagp1.js +0 -2
- package/dist/chunk-5f0wwwmw.js +0 -2
- package/dist/chunk-5h71xbzk.js +0 -2
- package/dist/chunk-5z9a1vzw.js +0 -2
- package/dist/chunk-67jf2e8x.js +0 -2
- package/dist/chunk-6b7je8dc.js +0 -2
- package/dist/chunk-6fxjs3ay.js +0 -3
- package/dist/chunk-6n5jnd97.js +0 -2
- package/dist/chunk-6wvnfdqq.js +0 -2
- package/dist/chunk-78jkbaz3.js +0 -2
- package/dist/chunk-7e9hfrtb.js +0 -2
- package/dist/chunk-7tc5fj96.js +0 -2
- package/dist/chunk-82q0fy52.js +0 -2
- package/dist/chunk-8q5ec4s1.js +0 -2
- package/dist/chunk-8ysk095d.js +0 -2
- package/dist/chunk-9vbrj55v.js +0 -2
- package/dist/chunk-bcefawtc.js +0 -2
- package/dist/chunk-bd6s91p9.js +0 -2
- package/dist/chunk-bhkqzz91.js +0 -2
- package/dist/chunk-bx1mjwhb.js +0 -2
- package/dist/chunk-dw0m259e.js +0 -2
- package/dist/chunk-dx4g2ec9.js +0 -2
- package/dist/chunk-evdskc25.js +0 -2
- package/dist/chunk-gppv6fez.js +0 -2
- package/dist/chunk-grjr8shp.js +0 -2
- package/dist/chunk-gz1w4cpp.js +0 -2
- package/dist/chunk-h0qtmmq3.js +0 -2
- package/dist/chunk-h6sewvt2.js +0 -20
- package/dist/chunk-hb34m4pp.js +0 -2
- package/dist/chunk-hwvtpx3p.js +0 -2
- package/dist/chunk-k3kav39s.js +0 -2
- package/dist/chunk-k46j2maz.js +0 -2
- package/dist/chunk-ka2f844k.js +0 -2
- package/dist/chunk-kh4dr6gd.js +0 -2
- package/dist/chunk-myd82d80.js +0 -2
- package/dist/chunk-nek0q523.js +0 -130
- package/dist/chunk-nvbjcgzd.js +0 -2
- package/dist/chunk-p13dxvaj.js +0 -2
- package/dist/chunk-pht5z7wa.js +0 -2
- package/dist/chunk-ppvdbstz.js +0 -11
- package/dist/chunk-pwdk7jbx.js +0 -2
- package/dist/chunk-qekyxjy6.js +0 -2
- package/dist/chunk-r10eadgn.js +0 -2
- package/dist/chunk-r8184e10.js +0 -2
- package/dist/chunk-rshaz0df.js +0 -4
- package/dist/chunk-tcrpa52j.js +0 -2
- package/dist/chunk-vp1p250v.js +0 -2
- package/dist/chunk-vqrg5j83.js +0 -2
- package/dist/chunk-vzdfq3b5.js +0 -2
- package/dist/chunk-wzh4ene8.js +0 -2
- package/dist/chunk-x5vwkccx.js +0 -2
- package/dist/chunk-x6cmj5sa.js +0 -2
- package/dist/chunk-xnrfz4c3.js +0 -2
- package/dist/chunk-yaabhcss.js +0 -2
- package/dist/chunk-yazqtmq4.js +0 -2
- package/dist/chunk-zygpvm1x.js +0 -2
- package/dist/chunk-zz247c1r.js +0 -2
|
@@ -12,31 +12,105 @@ export function registeredModuleIdsIn(...sources) {
|
|
|
12
12
|
}
|
|
13
13
|
return [...ids].sort();
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export function registeredModuleNamesIn(...sources) {
|
|
16
|
+
const result = new Map, read = (id, names) => {
|
|
17
|
+
const current = result.get(id);
|
|
18
|
+
if (current === null)
|
|
19
|
+
return;
|
|
20
|
+
if (names === null) {
|
|
21
|
+
result.set(id, null);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const into = current ?? new Set;
|
|
25
|
+
for (const name of names)
|
|
26
|
+
into.add(name);
|
|
27
|
+
result.set(id, into);
|
|
28
|
+
};
|
|
29
|
+
for (const source of sources) {
|
|
30
|
+
if (!source || !source.includes("__stxModules["))
|
|
31
|
+
continue;
|
|
32
|
+
const bindings = [];
|
|
33
|
+
for (const match of source.matchAll(/([\w$]+)\s*=\s*globalThis\.__stxModules\s*&&\s*globalThis\.__stxModules\["((?:[^"\\]|\\.)*)"\]/g)) {
|
|
34
|
+
let id;
|
|
35
|
+
try {
|
|
36
|
+
id = JSON.parse(`"${match[2]}"`);
|
|
37
|
+
} catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
bindings.push({ variable: match[1], id, start: match.index + match[0].length, end: source.length });
|
|
41
|
+
}
|
|
42
|
+
const total = source.match(/__stxModules\["(?:[^"\\]|\\.)*"\]/g)?.length ?? 0;
|
|
43
|
+
if (bindings.length === 0 || total !== bindings.length) {
|
|
44
|
+
for (const id of registeredModuleIdsIn(source))
|
|
45
|
+
read(id, null);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const [at, binding] of bindings.entries()) {
|
|
49
|
+
const next = bindings.slice(at + 1).find((other) => other.variable === binding.variable);
|
|
50
|
+
binding.end = next ? next.start : source.length;
|
|
51
|
+
}
|
|
52
|
+
for (const binding of bindings) {
|
|
53
|
+
const names = new Set;
|
|
54
|
+
let whole = !1;
|
|
55
|
+
const escaped = binding.variable.replace(/[$]/g, "\\$&"), region = source.slice(binding.start, binding.end);
|
|
56
|
+
for (const use of region.matchAll(new RegExp(`(?<![\\w$.])${escaped}(?![\\w$])`, "g"))) {
|
|
57
|
+
const rest = region.slice(use.index + binding.variable.length, use.index + binding.variable.length + 200), named = /^\s*\[\s*(["'])([A-Za-z_$][\w$]*)\1\s*\]/.exec(rest) ?? /^\s*\.\s*([A-Za-z_$][\w$]*)/.exec(rest);
|
|
58
|
+
if (named) {
|
|
59
|
+
names.add(named[named.length - 1]);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (/^\s*[!=]==?\s*(?:undefined|void 0)\b/.test(rest))
|
|
63
|
+
continue;
|
|
64
|
+
whole = !0;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
read(binding.id, whole ? null : names);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function registryEntry(ids, root, names) {
|
|
73
|
+
const imports = [], registrations = [];
|
|
19
74
|
ids.forEach((id, index) => {
|
|
20
|
-
const specifier = id.startsWith("npm:") ? id.slice(4) : path.resolve(root, id), local = `__stxRegistered${index}`, key = JSON.stringify(id);
|
|
75
|
+
const specifier = id.startsWith("npm:") ? id.slice(4) : path.resolve(root, id), local = `__stxRegistered${index}`, key = JSON.stringify(id), wanted = names?.get(id);
|
|
76
|
+
if (wanted && [...wanted].every((name) => /^[A-Za-z_$][\w$]*$/.test(name))) {
|
|
77
|
+
const list = [...wanted].sort(), bindings = list.map((name, at) => `${name} as ${local}_${at}`);
|
|
78
|
+
imports.push(list.length > 0 ? `import { ${bindings.join(", ")} } from ${JSON.stringify(specifier)};` : `import ${JSON.stringify(specifier)};`);
|
|
79
|
+
const getters = list.map((name, at) => `get ${JSON.stringify(name)}() { return ${local}_${at}; }`).join(", ");
|
|
80
|
+
registrations.push(`if (!globalThis.__stxModules[${key}]) globalThis.__stxModules[${key}] = { ${getters} };`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
21
83
|
imports.push(`import * as ${local} from ${JSON.stringify(specifier)};`);
|
|
22
84
|
registrations.push(`if (!globalThis.__stxModules[${key}]) globalThis.__stxModules[${key}] = ${local};`);
|
|
23
85
|
});
|
|
24
|
-
|
|
86
|
+
return [
|
|
25
87
|
...imports,
|
|
26
88
|
"globalThis.__stxModules = globalThis.__stxModules || {};",
|
|
27
89
|
...registrations
|
|
28
90
|
].join(`
|
|
29
91
|
`);
|
|
30
|
-
|
|
92
|
+
}
|
|
93
|
+
export async function buildModuleRegistryScript(ids, options = {}) {
|
|
94
|
+
if (ids.length === 0)
|
|
95
|
+
return null;
|
|
96
|
+
const root = process.cwd();
|
|
97
|
+
let entry = registryEntry(ids, root, options.names), code;
|
|
31
98
|
try {
|
|
32
|
-
const { bundleClientScript } = await import("./client-script-bundler.js")
|
|
33
|
-
code = await bundleClientScript(entry, path.join(root, ".stx-module-registry.ts"), {
|
|
99
|
+
const { bundleClientScript } = await import("./client-script-bundler.js"), bundle = () => bundleClientScript(entry, path.join(root, ".stx-module-registry.ts"), {
|
|
34
100
|
projectRoot: root,
|
|
35
101
|
minify: options.minify,
|
|
36
102
|
externalizeUserModules: !1,
|
|
37
103
|
collectInputs: options.collectInputs,
|
|
38
104
|
throwOnFailure: !0
|
|
39
105
|
});
|
|
106
|
+
try {
|
|
107
|
+
code = await bundle();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (!options.names)
|
|
110
|
+
throw error;
|
|
111
|
+
entry = registryEntry(ids, root, void 0);
|
|
112
|
+
code = await bundle();
|
|
113
|
+
}
|
|
40
114
|
} catch (error) {
|
|
41
115
|
const { formatBuildFailure } = await import("./build-message.js"), failure = formatBuildFailure(error);
|
|
42
116
|
console.warn(`[stx] could not build the page module registry (#1957): ${failure}`);
|
|
@@ -57,3 +131,169 @@ export async function buildModuleRegistryScript(ids, options = {}) {
|
|
|
57
131
|
].join(`
|
|
58
132
|
`);
|
|
59
133
|
}
|
|
134
|
+
const CHUNK_IMPORT = /^import(?:[ \t]*(\{[^}]*\})[ \t]*from|[ \t]*\*[ \t]*as[ \t]+([\w$]+)[ \t]+from)?[ \t]*["']\.\/(chunk-[\w-]+)\.js["'][ \t]*;?[ \t]*$/gm, MODULE_EXPORT = /^export\s*\{([^}]*)\}\s*;?[ \t]*$/gm, PRELOAD_HELPERS = new Set(["__preload", "__chunks"]), NAMED_SPECIFIER = /^("[^"]*"|[\w$]+)(?:\s+as\s+("[^"]*"|[\w$]+))?$/;
|
|
135
|
+
function parseSplitModule(text) {
|
|
136
|
+
const chunks = [], reads = [];
|
|
137
|
+
let ok = !0, body = text.replace(/^var __chunkGraphs;[\s\S]*?^var __chunks = [\s\S]*?^\};[ \t]*\n?/m, "").replace(/^__chunks\(import\.meta\.url,[^\n]*\);[ \t]*\n?/gm, "").replace(CHUNK_IMPORT, (_all, named, namespace, chunk) => {
|
|
138
|
+
const variable = `__stxChunkExports${chunks.length}`;
|
|
139
|
+
chunks.push(chunk);
|
|
140
|
+
reads.push(`var ${variable} = __stxChunk(${JSON.stringify(chunk)});`);
|
|
141
|
+
if (namespace)
|
|
142
|
+
reads.push(`var ${namespace} = ${variable};`);
|
|
143
|
+
else if (named)
|
|
144
|
+
for (const raw of named.slice(1, -1).split(",")) {
|
|
145
|
+
const specifier = raw.trim();
|
|
146
|
+
if (!specifier)
|
|
147
|
+
continue;
|
|
148
|
+
const match = NAMED_SPECIFIER.exec(specifier);
|
|
149
|
+
if (!match) {
|
|
150
|
+
ok = !1;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (PRELOAD_HELPERS.has(match[1]))
|
|
154
|
+
continue;
|
|
155
|
+
const imported = match[1].startsWith('"') ? JSON.parse(match[1]) : match[1], local = match[2] ?? match[1];
|
|
156
|
+
if (local.startsWith('"')) {
|
|
157
|
+
ok = !1;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
reads.push(`var ${local} = ${variable}[${JSON.stringify(imported)}];`);
|
|
161
|
+
}
|
|
162
|
+
return "";
|
|
163
|
+
});
|
|
164
|
+
if (!ok)
|
|
165
|
+
throw Error("an import it does not read");
|
|
166
|
+
const lazy = [];
|
|
167
|
+
body = body.replace(/\(\s*__preload\([^)]*\)\s*,\s*import\(\s*["']\.\/(chunk-[\w-]+)\.js["']\s*\)\s*\)|\bimport\(\s*["']\.\/(chunk-[\w-]+)\.js["']\s*\)/g, (_all, preloaded, plain) => {
|
|
168
|
+
const chunk = preloaded ?? plain;
|
|
169
|
+
lazy.push(chunk);
|
|
170
|
+
return `Promise.resolve().then(function () { return __stxChunk(${JSON.stringify(chunk)}); })`;
|
|
171
|
+
});
|
|
172
|
+
const exports = [];
|
|
173
|
+
body = body.replace(MODULE_EXPORT, (_all, list) => {
|
|
174
|
+
for (const raw of list.split(",")) {
|
|
175
|
+
const specifier = raw.trim();
|
|
176
|
+
if (!specifier)
|
|
177
|
+
continue;
|
|
178
|
+
const match = NAMED_SPECIFIER.exec(specifier);
|
|
179
|
+
if (!match || match[1].startsWith('"')) {
|
|
180
|
+
ok = !1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (PRELOAD_HELPERS.has(match[1]))
|
|
184
|
+
continue;
|
|
185
|
+
const name = match[2] ?? match[1];
|
|
186
|
+
exports.push([match[1], name.startsWith('"') ? JSON.parse(name) : name]);
|
|
187
|
+
}
|
|
188
|
+
return "";
|
|
189
|
+
});
|
|
190
|
+
const left = [/\bimport\.meta\b/, /\b__chunks\b/, /\b__preload\b/, /^\s*export\s+(?:default\b|const\b|let\b|var\b|function\b|class\b|async\b|\*|\{)/m, /\bfrom\s*["']\.\/chunk-/, /^\s*import\s*["']\.\/chunk-/m].find((pattern) => pattern.test(body));
|
|
191
|
+
if (!ok || left)
|
|
192
|
+
throw Error(`${left ? `${left.source} is left in it` : "an export it does not read"}`);
|
|
193
|
+
return { reads: reads.join(`
|
|
194
|
+
`), chunks, lazy, body, exports };
|
|
195
|
+
}
|
|
196
|
+
export function exportsMutableBinding(source) {
|
|
197
|
+
if (/\bexport\s+(?:let|var)\b/.test(source))
|
|
198
|
+
return !0;
|
|
199
|
+
if (source.length / Math.max(1, source.split(`
|
|
200
|
+
`).length) > 200)
|
|
201
|
+
return !1;
|
|
202
|
+
for (const list of source.matchAll(/\bexport\s*\{([^}]*)\}(?!\s*from\b)/g))
|
|
203
|
+
for (const raw of list[1].split(",")) {
|
|
204
|
+
const local = raw.trim().split(/\s+as\s+/)[0].trim();
|
|
205
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local))
|
|
206
|
+
continue;
|
|
207
|
+
const escaped = local.replace(/[$]/g, "\\$&");
|
|
208
|
+
if (!new RegExp(`(?<![\\w$.])(?:let|var)\\s+${escaped}(?![\\w$])`, "g").test(source))
|
|
209
|
+
continue;
|
|
210
|
+
const assignment = new RegExp(`(?<![\\w$.])${escaped}\\s*(?:=(?![=>])|[-+*/%&|^]=|\\*\\*=|<<=|>>>?=|&&=|\\|\\|=|\\?\\?=|\\+\\+|--)|(?:\\+\\+|--)\\s*${escaped}(?![\\w$])`, "g"), declarations = new RegExp(`(?<![\\w$.])(?:let|var|const)\\s+${escaped}\\s*=`, "g");
|
|
211
|
+
if ((source.match(assignment)?.length ?? 0) > (source.match(declarations)?.length ?? 0))
|
|
212
|
+
return !0;
|
|
213
|
+
}
|
|
214
|
+
return !1;
|
|
215
|
+
}
|
|
216
|
+
export async function buildSharedModuleRegistries(routes, options = {}) {
|
|
217
|
+
const wanted = routes.filter((route) => route.ids.length > 0);
|
|
218
|
+
if (wanted.length === 0)
|
|
219
|
+
return { chunks: new Map, routes: new Map, reads: new Map };
|
|
220
|
+
const root = process.cwd();
|
|
221
|
+
try {
|
|
222
|
+
const { bundleClientEntriesSplit } = await import("./client-script-bundler.js"), inputs = [], split = await bundleClientEntriesSplit(new Map(wanted.map((route) => [route.name, registryEntry(route.ids, root, route.names)])), { projectRoot: root, filePath: path.join(root, ".stx-module-registry.ts"), collectInputs: inputs });
|
|
223
|
+
options.collectInputs?.push(...inputs);
|
|
224
|
+
const { transformAutoImports, generateAutoImportDestructuring } = await import("./client-script.js"), { transformStoreImports } = await import("./store-imports.js"), parsed = new Map;
|
|
225
|
+
for (const [name, text] of [...split.chunks, ...split.entries])
|
|
226
|
+
try {
|
|
227
|
+
parsed.set(name, parseSplitModule(text));
|
|
228
|
+
} catch (error) {
|
|
229
|
+
throw Error(`cannot read ${name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
230
|
+
}
|
|
231
|
+
for (const [name, text] of [...split.chunks, ...split.entries])
|
|
232
|
+
if (/\b__esm\(/.test(text))
|
|
233
|
+
throw Error(`${name} initialises a module lazily`);
|
|
234
|
+
for (const input of inputs)
|
|
235
|
+
if (/\.(?:[cm]?[jt]sx?)$/.test(input) && exportsMutableBinding(await Bun.file(input).text()))
|
|
236
|
+
throw Error(`${input} exports a binding that changes after it is read`);
|
|
237
|
+
const visiting = new Set, settled = new Set, visit = (name) => {
|
|
238
|
+
if (settled.has(name))
|
|
239
|
+
return;
|
|
240
|
+
if (visiting.has(name))
|
|
241
|
+
throw Error(`the chunks import each other (${name})`);
|
|
242
|
+
visiting.add(name);
|
|
243
|
+
for (const dependency of parsed.get(name)?.chunks ?? []) {
|
|
244
|
+
if (!parsed.has(dependency))
|
|
245
|
+
throw Error(`${name} imports ${dependency}, which was not built`);
|
|
246
|
+
visit(dependency);
|
|
247
|
+
}
|
|
248
|
+
for (const dependency of parsed.get(name)?.lazy ?? [])
|
|
249
|
+
if (!parsed.has(dependency))
|
|
250
|
+
throw Error(`${name} imports ${dependency}, which was not built`);
|
|
251
|
+
visiting.delete(name);
|
|
252
|
+
settled.add(name);
|
|
253
|
+
};
|
|
254
|
+
for (const name of parsed.keys())
|
|
255
|
+
visit(name);
|
|
256
|
+
const wrap = (module) => {
|
|
257
|
+
const autoImports = transformAutoImports(module.body);
|
|
258
|
+
return {
|
|
259
|
+
prelude: generateAutoImportDestructuring(autoImports.stxImports, autoImports.browserImports),
|
|
260
|
+
body: transformStoreImports(autoImports.code)
|
|
261
|
+
};
|
|
262
|
+
}, chunks = new Map;
|
|
263
|
+
for (const name of split.chunks.keys()) {
|
|
264
|
+
const module = parsed.get(name), { prelude, body } = wrap(module), getters = module.exports.map(([local, exported]) => `get ${JSON.stringify(exported)}() { return ${local}; }`).join(", ");
|
|
265
|
+
chunks.set(name, `function (__stxChunk) {
|
|
266
|
+
${prelude}
|
|
267
|
+
${module.reads}
|
|
268
|
+
${body}
|
|
269
|
+
return { ${getters} };
|
|
270
|
+
}`);
|
|
271
|
+
}
|
|
272
|
+
const scripts = new Map, reads = new Map;
|
|
273
|
+
for (const name of split.entries.keys()) {
|
|
274
|
+
const module = parsed.get(name), { prelude, body } = wrap(module);
|
|
275
|
+
scripts.set(name, `;(function() {
|
|
276
|
+
var __stxChunk = function (name) { return globalThis.__stxNativeRuntime.chunk(name); };
|
|
277
|
+
${prelude}
|
|
278
|
+
${module.reads}
|
|
279
|
+
${body}
|
|
280
|
+
})();`);
|
|
281
|
+
const reached = new Set, reach = (chunk) => {
|
|
282
|
+
if (reached.has(chunk))
|
|
283
|
+
return;
|
|
284
|
+
reached.add(chunk);
|
|
285
|
+
const next = parsed.get(chunk);
|
|
286
|
+
for (const dependency of [...next.chunks, ...next.lazy])
|
|
287
|
+
reach(dependency);
|
|
288
|
+
};
|
|
289
|
+
for (const chunk of [...module.chunks, ...module.lazy])
|
|
290
|
+
reach(chunk);
|
|
291
|
+
reads.set(name, [...reached].sort());
|
|
292
|
+
}
|
|
293
|
+
return { chunks, routes: scripts, reads };
|
|
294
|
+
} catch (error) {
|
|
295
|
+
const { formatBuildFailure } = await import("./build-message.js");
|
|
296
|
+
console.warn(`[stx] could not share the native routes' modules, building each route's alone: ${formatBuildFailure(error)}`);
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -125,6 +125,18 @@ export declare function bundleClientScript(code: string, filePath: string, optio
|
|
|
125
125
|
* counter let one isolate remove another's output while it was being read.
|
|
126
126
|
*/
|
|
127
127
|
export declare function tempBuildName(hash: string): string;
|
|
128
|
+
/**
|
|
129
|
+
* Bundle several client entries together, the modules more than one of them
|
|
130
|
+
* reaches built once, in chunks of their own (ES modules: `import`/`export`
|
|
131
|
+
* between the files). The entries are virtual sources that import by absolute
|
|
132
|
+
* path, as the module registry's do. Unlike `bundleClientScript`, nothing is
|
|
133
|
+
* cached and nothing is wrapped: the caller turns the files into scripts.
|
|
134
|
+
*
|
|
135
|
+
* The modules are bundled with the same hooks (aliases, the runtime and
|
|
136
|
+
* stores left external, the message stand-ins of `withModuleSubstitutes`) and
|
|
137
|
+
* not minified, so a caller can read the names it finds in the output.
|
|
138
|
+
*/
|
|
139
|
+
export declare function bundleClientEntriesSplit(entries: ReadonlyMap<string, string>, options: { projectRoot: string, filePath: string, collectInputs?: string[] }): Promise<SplitClientBundle>;
|
|
128
140
|
/**
|
|
129
141
|
* Specifier prefix for an import the PAGE serves rather than the bundle
|
|
130
142
|
* inlines (stacksjs/stx#1957).
|
|
@@ -165,5 +177,10 @@ export declare interface BundleFailure {
|
|
|
165
177
|
message: string
|
|
166
178
|
details?: BuildFailureDetail[]
|
|
167
179
|
}
|
|
180
|
+
/** A split build's files: the entries by the name they were given, the chunks they share by file name. */
|
|
181
|
+
export declare interface SplitClientBundle {
|
|
182
|
+
entries: Map<string, string>
|
|
183
|
+
chunks: Map<string, string>
|
|
184
|
+
}
|
|
168
185
|
/** What to do when a client script will not bundle. */
|
|
169
186
|
export type BundlerFallbackMode = 'warn' | 'error';
|
|
@@ -255,11 +255,11 @@ export function withModuleSubstitutes(modules, run) {
|
|
|
255
255
|
export function moduleSubstitutionKey() {
|
|
256
256
|
return moduleSubstitutes.getStore()?.key ?? "";
|
|
257
257
|
}
|
|
258
|
-
function createBundlePlugin(projectRoot, templateDir, tmpEntry, entrySource, inputFiles, externalizeUserModules, registrySpecifiers = new Map, serverApi, substitutes) {
|
|
259
|
-
const toRegistry = (importer, resolved, specifier) => {
|
|
258
|
+
function createBundlePlugin(projectRoot, templateDir, tmpEntry, entrySource, inputFiles, externalizeUserModules, registrySpecifiers = new Map, serverApi, substitutes, moreEntries) {
|
|
259
|
+
const entrySources = new Map([[tmpEntry, entrySource], ...moreEntries ?? []]), isEntry = (file) => file !== void 0 && entrySources.has(file), toRegistry = (importer, resolved, specifier) => {
|
|
260
260
|
if (isPrivateClientSource(resolved, projectRoot, serverApi))
|
|
261
261
|
return null;
|
|
262
|
-
if (!externalizeUserModules || importer
|
|
262
|
+
if (!externalizeUserModules || !isEntry(importer) || !REGISTRY_MODULE_EXTENSION.test(resolved))
|
|
263
263
|
return null;
|
|
264
264
|
try {
|
|
265
265
|
if (!fs.statSync(resolved, { throwIfNoEntry: !1 })?.isFile())
|
|
@@ -272,7 +272,7 @@ function createBundlePlugin(projectRoot, templateDir, tmpEntry, entrySource, inp
|
|
|
272
272
|
registrySpecifiers.set(specifier, registryPath);
|
|
273
273
|
return { path: registryPath, external: !0 };
|
|
274
274
|
}, resolveRelative = (importer, request) => {
|
|
275
|
-
const fromDir = importer
|
|
275
|
+
const fromDir = isEntry(importer) ? templateDir : path.dirname(importer), resolved = path.resolve(fromDir, request);
|
|
276
276
|
return probeModuleFile(resolved) ?? resolved;
|
|
277
277
|
};
|
|
278
278
|
return {
|
|
@@ -287,14 +287,14 @@ function createBundlePlugin(projectRoot, templateDir, tmpEntry, entrySource, inp
|
|
|
287
287
|
external: !0
|
|
288
288
|
}));
|
|
289
289
|
build.onResolve({ filter: /^\// }, (args) => {
|
|
290
|
-
if (args.path
|
|
291
|
-
return { path:
|
|
290
|
+
if (isEntry(args.path))
|
|
291
|
+
return { path: args.path };
|
|
292
292
|
const resolved = probeModuleFile(args.path);
|
|
293
293
|
if (resolved) {
|
|
294
294
|
const registered = toRegistry(args.importer, resolved, args.path);
|
|
295
295
|
if (registered)
|
|
296
296
|
return registered;
|
|
297
|
-
if (resolved
|
|
297
|
+
if (!isEntry(resolved))
|
|
298
298
|
inputFiles.add(resolved);
|
|
299
299
|
return { path: resolved };
|
|
300
300
|
}
|
|
@@ -337,19 +337,19 @@ function createBundlePlugin(projectRoot, templateDir, tmpEntry, entrySource, inp
|
|
|
337
337
|
});
|
|
338
338
|
if (externalizeUserModules)
|
|
339
339
|
build.onResolve({ filter: /^(?!node:|bun:)(?:@[\w.-]+\/)?[\w.-]/ }, (args) => {
|
|
340
|
-
if (args.importer
|
|
340
|
+
if (!isEntry(args.importer))
|
|
341
341
|
return;
|
|
342
342
|
const registryPath = `${MODULE_SPECIFIER_PREFIX}npm:${args.path}`;
|
|
343
343
|
registrySpecifiers.set(args.path, registryPath);
|
|
344
344
|
return { path: registryPath, external: !0 };
|
|
345
345
|
});
|
|
346
346
|
build.onLoad({ filter: /\.(?:[cm]?[jt]sx?|json)$/ }, (args) => {
|
|
347
|
-
if (args.path
|
|
348
|
-
return { contents:
|
|
347
|
+
if (entrySources.has(args.path))
|
|
348
|
+
return { contents: entrySources.get(args.path), loader: "ts" };
|
|
349
349
|
if (isPrivateClientSource(args.path, projectRoot, serverApi))
|
|
350
350
|
throw Error(`Server-only API source cannot be imported by a client script: ${args.path}`);
|
|
351
351
|
const extension = path.extname(args.path).toLowerCase(), loader = extension === ".json" ? "json" : extension === ".tsx" ? "tsx" : extension === ".jsx" ? "jsx" : extension === ".ts" || extension === ".mts" || extension === ".cts" ? "ts" : "js";
|
|
352
|
-
if (args.path
|
|
352
|
+
if (!isEntry(args.path))
|
|
353
353
|
inputFiles.add(args.path);
|
|
354
354
|
const substitute = substitutes?.get(args.path);
|
|
355
355
|
if (substitute !== void 0)
|
|
@@ -433,6 +433,53 @@ export async function bundleClientScript(code, filePath, options = {}) {
|
|
|
433
433
|
export function tempBuildName(hash) {
|
|
434
434
|
return `${hash}-${process.pid}-${randomUUID()}`;
|
|
435
435
|
}
|
|
436
|
+
export async function bundleClientEntriesSplit(entries, options) {
|
|
437
|
+
const { projectRoot } = options, tmpName = tempBuildName(new Bun.CryptoHasher("md5").update([...entries.keys()].join("\x00")).digest("hex").slice(0, 12)), tmpOutDir = path.join(stateDir(projectRoot, "bundle-tmp"), "out", tmpName);
|
|
438
|
+
fs.mkdirSync(tmpOutDir, { recursive: !0 });
|
|
439
|
+
const virtual = new Map, byFile = new Map;
|
|
440
|
+
let index = 0;
|
|
441
|
+
for (const [name, source] of entries) {
|
|
442
|
+
const file = path.join(projectRoot, `.stx-split-${tmpName}-${index++}.ts`);
|
|
443
|
+
virtual.set(file, source);
|
|
444
|
+
byFile.set(path.basename(file).replace(/\.ts$/, ""), name);
|
|
445
|
+
}
|
|
446
|
+
const [firstFile, firstSource] = [...virtual][0], inputFiles = new Set;
|
|
447
|
+
try {
|
|
448
|
+
const result = await Bun.build({
|
|
449
|
+
entrypoints: [...virtual.keys()],
|
|
450
|
+
outdir: tmpOutDir,
|
|
451
|
+
target: "browser",
|
|
452
|
+
format: "esm",
|
|
453
|
+
splitting: !0,
|
|
454
|
+
minify: !1,
|
|
455
|
+
naming: { entry: "[name].js", chunk: "chunk-[hash].js" },
|
|
456
|
+
plugins: [createBundlePlugin(projectRoot, path.dirname(options.filePath), firstFile, firstSource, inputFiles, !1, new Map, void 0, moduleSubstitutes.getStore()?.modules, virtual)],
|
|
457
|
+
define: {
|
|
458
|
+
"process.env.NODE_ENV": '"development"',
|
|
459
|
+
...getPublicEnvDefine()
|
|
460
|
+
},
|
|
461
|
+
root: projectRoot
|
|
462
|
+
});
|
|
463
|
+
if (!result.success)
|
|
464
|
+
throw Error(result.logs.filter((log) => log.level === "error").map((log) => log.message).join(", ") || "Unable to bundle the entries");
|
|
465
|
+
const split = { entries: new Map, chunks: new Map };
|
|
466
|
+
for (const output of result.outputs) {
|
|
467
|
+
const file = path.basename(output.path);
|
|
468
|
+
if (output.kind === "entry-point") {
|
|
469
|
+
const name = byFile.get(file.replace(/\.js$/, ""));
|
|
470
|
+
if (name !== void 0)
|
|
471
|
+
split.entries.set(name, await output.text());
|
|
472
|
+
} else if (output.kind === "chunk")
|
|
473
|
+
split.chunks.set(file.replace(/\.js$/, ""), await output.text());
|
|
474
|
+
}
|
|
475
|
+
options.collectInputs?.push(...inputFiles);
|
|
476
|
+
return split;
|
|
477
|
+
} finally {
|
|
478
|
+
try {
|
|
479
|
+
fs.rmSync(tmpOutDir, { recursive: !0, force: !0 });
|
|
480
|
+
} catch {}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
436
483
|
async function buildBundle(code, filePath, options) {
|
|
437
484
|
const { projectRoot, minify, cacheDir, hash, cachePath, depsPath, externalizeUserModules } = options, tmpDir = stateDir(projectRoot, "bundle-tmp"), tmpName = tempBuildName(hash), tmpEntry = path.join(projectRoot, `.stx-client-${tmpName}.ts`), tmpOutDir = path.join(tmpDir, "out", tmpName);
|
|
438
485
|
fs.mkdirSync(tmpOutDir, { recursive: !0 });
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ho,xa,Sa}from"./chunk-ztdjdxjt.js";import"./chunk-jevd16gq.js";import"./chunk-465resq9.js";import"./chunk-qwds327k.js";import"./chunk-89h4snzd.js";import"./chunk-m5fjhrpd.js";import"./chunk-gs373714.js";import"./chunk-b6g24qj0.js";import"./chunk-yp6w740k.js";import"./chunk-z8k3fx4r.js";import"./chunk-x1q2ape8.js";import"./chunk-3cn9y08d.js";import"./chunk-5q9ss7ty.js";import"./chunk-hmae7ha6.js";import"./chunk-x9haxcsj.js";import"./chunk-fpagqrd1.js";import"./chunk-0e9xdrzx.js";import"./chunk-nv9dy71x.js";import"./chunk-06zn167b.js";import"./chunk-0jn79fkt.js";import"./chunk-jt28zh50.js";import"./chunk-pes27snj.js";import{au,fa,eh,th,ga,mo,Gr,ma,ha,nh,rh,ya,ba,va,wa}from"./chunk-2x112fxs.js";import"./chunk-wp9y6x33.js";import"./chunk-qn4gt8sx.js";import"./chunk-sgm6tg8h.js";import"./chunk-0dkd26t4.js";import"./chunk-3kfbs0mw.js";import"./chunk-1mfj2j5g.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{au as CRAFT_BRIDGE_SCRIPT,mo as CRAFT_COMPONENTS,ma as CRAFT_COMPONENT_RUNTIME,Gr as CRAFT_COMPONENT_STYLES,ho as NATIVE_COMPONENTS,ya as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,xa as compileToNative,Sa as createHotReloadServer,ba as findCraftBinary,fa as generateCraftBridgeScript,V as generateCraftOptimizations,wa as getAvailableFormats,va as getAvailableTargets,rh as getCraftComponents,G as getSSRCacheStats,ga as injectCraftBridge,eh as isCraftEnvironment,Y as prerenderForCraft,ha as processCraftComponents,th as processCraftDirective,nh as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ho,xa,Sa}from"./chunk-ztdjdxjt.js";import"./chunk-jevd16gq.js";import"./chunk-465resq9.js";import"./chunk-qwds327k.js";import"./chunk-89h4snzd.js";import"./chunk-m5fjhrpd.js";import"./chunk-gs373714.js";import"./chunk-b6g24qj0.js";import"./chunk-yp6w740k.js";import"./chunk-z8k3fx4r.js";import"./chunk-x1q2ape8.js";import"./chunk-3cn9y08d.js";import"./chunk-5q9ss7ty.js";import"./chunk-hmae7ha6.js";import"./chunk-x9haxcsj.js";import"./chunk-fpagqrd1.js";import"./chunk-0e9xdrzx.js";import"./chunk-nv9dy71x.js";import"./chunk-06zn167b.js";import"./chunk-0jn79fkt.js";import"./chunk-jt28zh50.js";import"./chunk-pes27snj.js";import{au,fa,eh,th,ga,mo,Gr,ma,ha,nh,rh,ya,ba,va,wa}from"./chunk-2x112fxs.js";import"./chunk-wp9y6x33.js";import"./chunk-qn4gt8sx.js";import"./chunk-sgm6tg8h.js";import"./chunk-0dkd26t4.js";import"./chunk-3kfbs0mw.js";import"./chunk-1mfj2j5g.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{au as CRAFT_BRIDGE_SCRIPT,mo as CRAFT_COMPONENTS,ma as CRAFT_COMPONENT_RUNTIME,Gr as CRAFT_COMPONENT_STYLES,ho as NATIVE_COMPONENTS,ya as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,xa as compileToNative,Sa as createHotReloadServer,ba as findCraftBinary,fa as generateCraftBridgeScript,V as generateCraftOptimizations,wa as getAvailableFormats,va as getAvailableTargets,rh as getCraftComponents,G as getSSRCacheStats,ga as injectCraftBridge,eh as isCraftEnvironment,Y as prerenderForCraft,ha as processCraftComponents,th as processCraftDirective,nh as registerCraftComponent,Q as renderSSR};
|
|
@@ -46,6 +46,7 @@ export declare interface CompileNativeBundleOptions {
|
|
|
46
46
|
browser?: BrowserScreenOptions & { platformModule: string, platformOptions?: Record<string, unknown> }
|
|
47
47
|
routesDir?: string
|
|
48
48
|
sharedRuntime?: boolean
|
|
49
|
+
shareModules?: boolean
|
|
49
50
|
messages?: NativeMessagesOptions
|
|
50
51
|
shareStorage?: Record<string, string>
|
|
51
52
|
styleConfig?: NativeStyleConfig
|