@stacksjs/stx 0.2.888 → 0.2.889
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-c0g30cjs.js → chunk-05x1rd86.js} +2 -2
- package/dist/chunk-0g9cceht.js +2 -0
- package/dist/chunk-0k437z3q.js +2 -0
- package/dist/{chunk-1xpq83mc.js → chunk-0ncafcs2.js} +4 -4
- package/dist/chunk-0rpj5t80.js +2 -0
- package/dist/{chunk-btsgt6w3.js → chunk-1gyxxfdf.js} +2 -2
- package/dist/{chunk-vazk5qbh.js → chunk-1knk403z.js} +2 -2
- package/dist/{chunk-6qq3wy3m.js → chunk-1n33yrar.js} +2 -2
- package/dist/chunk-1p4q6t48.js +2 -0
- package/dist/chunk-1z6pqvmf.js +2 -0
- package/dist/{chunk-s29hp1qw.js → chunk-2a5g80mq.js} +3 -3
- package/dist/chunk-2ba4zfa0.js +2 -0
- package/dist/chunk-2gn2nc2j.js +2 -0
- package/dist/chunk-2nqmw4dv.js +2 -0
- package/dist/chunk-2wkpksg1.js +2 -0
- package/dist/{chunk-xw291tn7.js → chunk-3dqfjpz4.js} +34 -29
- package/dist/{chunk-3ed2erm6.js → chunk-3hsv6ejp.js} +4 -4
- package/dist/{chunk-w624s5jf.js → chunk-3qk8vf9m.js} +3 -3
- package/dist/chunk-3yjyjq0m.js +2 -0
- package/dist/chunk-444haxxa.js +2 -0
- package/dist/{chunk-y76znqmh.js → chunk-446tb2th.js} +27 -27
- package/dist/{chunk-qjy5yq25.js → chunk-48rwqchc.js} +10 -10
- package/dist/chunk-4akw3bym.js +2 -0
- package/dist/{chunk-mm1eg2pg.js → chunk-4kmg6g5n.js} +9 -9
- package/dist/chunk-4rvfeee5.js +2 -0
- package/dist/{chunk-605g9qhp.js → chunk-51720m79.js} +5 -5
- package/dist/chunk-53kcqdjj.js +2 -0
- package/dist/{chunk-0dq9svfb.js → chunk-55tc5w32.js} +3 -3
- package/dist/{chunk-7s3j8pqq.js → chunk-58qzyyyv.js} +3 -3
- package/dist/chunk-5aa83bpm.js +2 -0
- package/dist/{chunk-ah6nc29h.js → chunk-5kqezrjt.js} +2 -2
- package/dist/chunk-5ssv10ep.js +2 -0
- package/dist/chunk-67rppc5v.js +2 -0
- package/dist/{chunk-care745q.js → chunk-6gtecbe7.js} +2 -2
- package/dist/{chunk-p33npqjt.js → chunk-6kyqejnq.js} +22 -22
- package/dist/{chunk-vjfp8n6p.js → chunk-6pdy7ajr.js} +3 -3
- package/dist/{chunk-9tecekzq.js → chunk-6pz5gq6v.js} +9 -9
- package/dist/{chunk-wpa3r3b9.js → chunk-700m927w.js} +2 -2
- package/dist/{chunk-2assyczz.js → chunk-7212fwzz.js} +2 -2
- package/dist/chunk-732gb689.js +2 -0
- package/dist/chunk-77c89d23.js +2 -0
- package/dist/chunk-79vbkez0.js +2 -0
- package/dist/{chunk-whsdyf4t.js → chunk-7hpca9c7.js} +6 -6
- package/dist/chunk-80xzjxah.js +2 -0
- package/dist/chunk-8354mzpd.js +2 -0
- package/dist/{chunk-r561zt9v.js → chunk-87g5xmmr.js} +12 -12
- package/dist/{chunk-ry6w43p6.js → chunk-8hwfdwgn.js} +6 -6
- package/dist/chunk-8ygf6jnt.js +2 -0
- package/dist/{chunk-5ymf5c8m.js → chunk-95sd8h5g.js} +7 -7
- package/dist/{chunk-gdtj5rfa.js → chunk-967ydrq4.js} +6 -6
- package/dist/chunk-9afkttvz.js +2 -0
- package/dist/{chunk-55kwxxm5.js → chunk-9d91h636.js} +2 -2
- package/dist/{chunk-kvxdyg7e.js → chunk-9n5h4sqc.js} +2 -2
- package/dist/chunk-9ztn7w4y.js +2 -0
- package/dist/chunk-ah8az9vv.js +2 -0
- package/dist/chunk-ankap9pc.js +2 -0
- package/dist/chunk-asnd03sr.js +2 -0
- package/dist/chunk-b0b5yr97.js +2 -0
- package/dist/chunk-b0e7dgv8.js +3 -0
- package/dist/{chunk-372xh1g1.js → chunk-b15c4g3e.js} +5 -5
- package/dist/{chunk-7hm1tpw0.js → chunk-b6bf0t02.js} +6 -6
- package/dist/chunk-b7jj45bz.js +2 -0
- package/dist/{chunk-r57jz09p.js → chunk-bgfs3mbg.js} +5 -5
- package/dist/{chunk-fepezvdq.js → chunk-bqtj62ys.js} +8 -8
- package/dist/{chunk-wbxmn5gk.js → chunk-bw2m1e7g.js} +5 -5
- package/dist/chunk-bwx6w87c.js +2 -0
- package/dist/{chunk-9qrgdekg.js → chunk-cgfjrgfw.js} +14 -14
- package/dist/{chunk-98mj0es1.js → chunk-ch9028z3.js} +1 -1
- package/dist/{chunk-sbwvvjkc.js → chunk-cmg9x1ka.js} +3 -3
- package/dist/{chunk-9f31gs4m.js → chunk-cz1sdes5.js} +2 -2
- package/dist/{chunk-dj9ztcth.js → chunk-dvjv4c3a.js} +1 -1
- package/dist/{chunk-edysherg.js → chunk-dymck524.js} +5 -5
- package/dist/chunk-dzqfv801.js +3 -0
- package/dist/{chunk-b8528fra.js → chunk-eceeqy74.js} +4 -4
- package/dist/{chunk-52mhrbps.js → chunk-eqffvse2.js} +1 -1
- package/dist/chunk-ery4tty7.js +20 -0
- package/dist/chunk-evwrxsxd.js +3 -0
- package/dist/{chunk-6t04tqvh.js → chunk-eyx92t9n.js} +2 -2
- package/dist/{chunk-c1b0fy70.js → chunk-f3cyghnb.js} +5 -5
- package/dist/chunk-f60k8j9m.js +2 -0
- package/dist/chunk-fdqdz018.js +2 -0
- package/dist/chunk-g6ap4085.js +2 -0
- package/dist/chunk-gz9pknbw.js +1204 -0
- package/dist/{chunk-e1qcfesw.js → chunk-hgf7bc50.js} +6 -6
- package/dist/chunk-hjb4c8g2.js +2 -0
- package/dist/chunk-hk241gt2.js +2 -0
- package/dist/{chunk-wscry63p.js → chunk-hm9d40yf.js} +2 -2
- package/dist/{chunk-vgr7gd8k.js → chunk-hpzje67q.js} +2 -2
- package/dist/{chunk-c3ca056p.js → chunk-htx5yezj.js} +2 -2
- package/dist/{chunk-b0jekg4c.js → chunk-hxws025y.js} +3 -3
- package/dist/chunk-jhbj9ja2.js +2 -0
- package/dist/chunk-k4x680e3.js +2 -0
- package/dist/chunk-k9abxnpa.js +2 -0
- package/dist/{chunk-c73c0wf9.js → chunk-kbbbpae2.js} +2 -2
- package/dist/chunk-kfdmm240.js +2 -0
- package/dist/{chunk-5ysv0499.js → chunk-kj43fbzm.js} +1 -1
- package/dist/{chunk-303vzq80.js → chunk-kk2p2tgv.js} +3 -3
- package/dist/{chunk-r8xper92.js → chunk-ksmn19qw.js} +2 -2
- package/dist/{chunk-v47xc2fr.js → chunk-kx09v9ya.js} +7 -7
- package/dist/{chunk-wm287dz2.js → chunk-m95sygv4.js} +3 -3
- package/dist/{chunk-j51wss7s.js → chunk-mctzpw0w.js} +1 -1
- package/dist/{chunk-2rmqmajd.js → chunk-me4yq8c2.js} +3 -3
- package/dist/{chunk-11fxbd71.js → chunk-mgh5rst1.js} +2 -2
- package/dist/{chunk-1kc0jyhj.js → chunk-mhxg6j6s.js} +1 -1
- package/dist/{chunk-wf8pdjq5.js → chunk-mjp1z9kz.js} +1 -1
- package/dist/{chunk-znnvq1jp.js → chunk-mt8edb75.js} +46 -46
- package/dist/chunk-mvavjydq.js +2 -0
- package/dist/{chunk-s7wp7a2x.js → chunk-mw7hacm3.js} +30 -30
- package/dist/{chunk-e2ws79vt.js → chunk-nbdscgvj.js} +6 -6
- package/dist/{chunk-mk6thhwf.js → chunk-njpva3zq.js} +2 -2
- package/dist/{chunk-q3bkxg2n.js → chunk-nkyff7v6.js} +11 -11
- package/dist/{chunk-zje94z0k.js → chunk-p8shtje2.js} +32 -32
- package/dist/{chunk-0hj5apb9.js → chunk-pctf14yw.js} +1 -1
- package/dist/{chunk-0d7ypcjb.js → chunk-pjj54ddk.js} +3 -3
- package/dist/{chunk-qsnpqa8q.js → chunk-pnmafbv5.js} +1 -1
- package/dist/{chunk-vgsasnwm.js → chunk-pz554g43.js} +3 -3
- package/dist/{chunk-6zq3eh7d.js → chunk-q0y8gv18.js} +2 -2
- package/dist/{chunk-w50yggy3.js → chunk-q9tc9rdv.js} +2 -2
- package/dist/chunk-qqng9545.js +2 -0
- package/dist/{chunk-xavx271y.js → chunk-r5ecgcx2.js} +5 -5
- package/dist/{chunk-v8e2c2r1.js → chunk-ranjkpc8.js} +2 -2
- package/dist/{chunk-zf29ahhd.js → chunk-rb2zbdqd.js} +4 -4
- package/dist/{chunk-4nnmrp7w.js → chunk-rf0smj4c.js} +2 -2
- package/dist/chunk-rjm515e2.js +2 -0
- package/dist/chunk-rye4b2x3.js +2 -0
- package/dist/chunk-ryj8139z.js +2 -0
- package/dist/{chunk-e9tjxnhn.js → chunk-s0mf56y1.js} +5 -5
- package/dist/{chunk-fce8wj3t.js → chunk-s93yh7ed.js} +2 -2
- package/dist/chunk-s9b809n2.js +2 -0
- package/dist/chunk-sb67wg5x.js +2 -0
- package/dist/{chunk-6fsnnj5v.js → chunk-sjjw6y49.js} +6 -6
- package/dist/chunk-snkbn5y8.js +2 -0
- package/dist/{chunk-7mcs59pr.js → chunk-snv80b1b.js} +2 -2
- package/dist/chunk-sqwx2g02.js +2 -0
- package/dist/{chunk-4c9p434g.js → chunk-t0ttxayz.js} +2 -2
- package/dist/chunk-tbh7r1wh.js +2 -0
- package/dist/chunk-tpyekw0q.js +2 -0
- package/dist/chunk-v2627s75.js +2 -0
- package/dist/chunk-v3jyb8k6.js +2 -0
- package/dist/chunk-v98n53nk.js +2 -0
- package/dist/{chunk-pm4kn9h2.js → chunk-vc432a0w.js} +9 -9
- package/dist/{chunk-7nhgpjjw.js → chunk-vf4ejngv.js} +6 -6
- package/dist/{chunk-hxhmhw23.js → chunk-vk2jy6mn.js} +3 -3
- package/dist/chunk-w34vvhm7.js +2 -0
- package/dist/chunk-w82nk19t.js +2 -0
- package/dist/{chunk-mbm3ma63.js → chunk-x5bn2svk.js} +2 -2
- package/dist/chunk-x6565mhk.js +2 -0
- package/dist/{chunk-3fbgpv1d.js → chunk-xvncq3m5.js} +2 -2
- package/dist/chunk-xwgdcc7w.js +2 -0
- package/dist/{chunk-1wkp3pks.js → chunk-xy8smv5e.js} +2 -2
- package/dist/{chunk-y8p59h6c.js → chunk-y1d3j2j7.js} +4 -4
- package/dist/chunk-yjwa7ktk.js +2 -0
- package/dist/{chunk-xy4j8t7w.js → chunk-ytjn0gq2.js} +2 -2
- package/dist/chunk-z47p2gx8.js +2 -0
- package/dist/chunk-z4tdnfxd.js +2 -0
- package/dist/chunk-z6kw6sct.js +4 -0
- package/dist/{chunk-w1q86c89.js → chunk-zf68afyh.js} +3 -3
- package/dist/chunk-zhywjwdr.js +2 -0
- package/dist/{chunk-em6fqvjy.js → chunk-zwwhpxp7.js} +2 -2
- package/dist/cli.js +21 -21
- package/dist/component-library.d.ts +2 -1
- package/dist/component-library.js +17 -296
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/directive-arguments.js +39 -6
- package/dist/parser/tokenizer.d.ts +2 -1
- package/dist/parser/tokenizer.js +7 -5
- package/dist/props-declaration.d.ts +64 -0
- package/dist/props-declaration.js +354 -0
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +5 -5
- package/dist/utils.js +20 -109
- package/package.json +5 -5
- package/dist/chunk-000mwmfq.js +0 -1203
- package/dist/chunk-043d0en0.js +0 -2
- package/dist/chunk-0w66z6eq.js +0 -2
- package/dist/chunk-13wd9gf0.js +0 -3
- package/dist/chunk-1znqedae.js +0 -2
- package/dist/chunk-2drzzjcm.js +0 -2
- package/dist/chunk-3c7nt5qp.js +0 -2
- package/dist/chunk-3zyzhcd9.js +0 -2
- package/dist/chunk-44rb9fk0.js +0 -2
- package/dist/chunk-472j3bhp.js +0 -2
- package/dist/chunk-4acce1m8.js +0 -2
- package/dist/chunk-4kasmp98.js +0 -2
- package/dist/chunk-53kkjn23.js +0 -2
- package/dist/chunk-5gwvy612.js +0 -2
- package/dist/chunk-61vbqrde.js +0 -2
- package/dist/chunk-6fpzwryt.js +0 -2
- package/dist/chunk-7195598h.js +0 -2
- package/dist/chunk-7zvf79vb.js +0 -2
- package/dist/chunk-88a735jw.js +0 -2
- package/dist/chunk-8v7yjq3b.js +0 -2
- package/dist/chunk-97kgrevs.js +0 -4
- package/dist/chunk-a8c9j9cj.js +0 -2
- package/dist/chunk-acw851e8.js +0 -2
- package/dist/chunk-andfvr3g.js +0 -2
- package/dist/chunk-aqxh80vh.js +0 -2
- package/dist/chunk-ay5zkfdg.js +0 -2
- package/dist/chunk-b4gptdtc.js +0 -2
- package/dist/chunk-baaw9w7y.js +0 -2
- package/dist/chunk-bw2p9h2g.js +0 -2
- package/dist/chunk-ce0vv7kz.js +0 -2
- package/dist/chunk-d1yj29g2.js +0 -2
- package/dist/chunk-dbhmbef1.js +0 -20
- package/dist/chunk-dfsykk1r.js +0 -2
- package/dist/chunk-e9p596bp.js +0 -2
- package/dist/chunk-ftecsa8e.js +0 -2
- package/dist/chunk-ge2h5v46.js +0 -2
- package/dist/chunk-gqvnz8a7.js +0 -2
- package/dist/chunk-j41gp8p3.js +0 -2
- package/dist/chunk-jxvccj30.js +0 -2
- package/dist/chunk-k5bbre7d.js +0 -2
- package/dist/chunk-kd47vgs8.js +0 -2
- package/dist/chunk-keqjafdz.js +0 -2
- package/dist/chunk-kz3mejc4.js +0 -2
- package/dist/chunk-ngkh0t5b.js +0 -2
- package/dist/chunk-nx9895m6.js +0 -2
- package/dist/chunk-nxgtt1t1.js +0 -2
- package/dist/chunk-nyw2ztar.js +0 -2
- package/dist/chunk-p5q27adr.js +0 -2
- package/dist/chunk-p6hcrg3r.js +0 -3
- package/dist/chunk-pa2vt2ej.js +0 -2
- package/dist/chunk-pczb7xav.js +0 -2
- package/dist/chunk-ps37r6hj.js +0 -2
- package/dist/chunk-pvbhk17r.js +0 -2
- package/dist/chunk-q252qvsy.js +0 -2
- package/dist/chunk-q5b0vpmm.js +0 -2
- package/dist/chunk-qg1kw5yf.js +0 -2
- package/dist/chunk-sbr85vda.js +0 -2
- package/dist/chunk-tkab24xr.js +0 -2
- package/dist/chunk-vn59yrjh.js +0 -2
- package/dist/chunk-w5zzwe2f.js +0 -2
- package/dist/chunk-wa9q1gyv.js +0 -2
- package/dist/chunk-wpgxhrd7.js +0 -2
- package/dist/chunk-x3azrbpr.js +0 -2
- package/dist/chunk-x50hk1hq.js +0 -2
- package/dist/chunk-xbkbvfcg.js +0 -2
- package/dist/chunk-z55rpt3s.js +0 -3
- package/dist/chunk-zwde52kw.js +0 -2
- package/dist/chunk-zxff7kq9.js +0 -2
|
@@ -6,6 +6,8 @@ import { scriptAttributes, scriptContainsCode } from "./script-attributes.js";
|
|
|
6
6
|
import { topLevelDeclarationSites } from "./client-parameter-bindings.js";
|
|
7
7
|
import { bracketDepths, stripCommentsAndLiterals } from "./strip-literals.js";
|
|
8
8
|
import { Tokenizer } from "./parser/tokenizer.js";
|
|
9
|
+
import { literalValue, parseDefaults, parsePropsDeclaration, skipBalanced, splitTopLevel } from "./props-declaration.js";
|
|
10
|
+
export { parseDefaults } from "./props-declaration.js";
|
|
9
11
|
function reservedMethodMessage(name) {
|
|
10
12
|
if (name === "connectedCallback")
|
|
11
13
|
return `method "${name}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;
|
|
@@ -165,17 +167,18 @@ export function methodDeclaration(method) {
|
|
|
165
167
|
return `${method.name}${method.generic}(${parameters}): ${method.returns || (method.async ? "Promise<unknown>" : "unknown")}`;
|
|
166
168
|
}
|
|
167
169
|
function extractClientMethods(source, file) {
|
|
168
|
-
const methods = {}, declarations = {}, types = [], imports = [], scripts = scanHtmlScriptElements(componentScriptSource(source))
|
|
170
|
+
const methods = {}, declarations = {}, types = [], imports = [], scripts = scanHtmlScriptElements(componentScriptSource(source)).map((script) => ({
|
|
171
|
+
code: source.slice(script.bodyStart, script.bodyEnd),
|
|
172
|
+
attributes: scriptAttributes(script.attrs)
|
|
173
|
+
})).filter(({ attributes }) => !["src", "server", "component", "stx:component"].some((name) => attributes.has(name)) && scriptContainsCode(attributes));
|
|
169
174
|
for (const script of scripts) {
|
|
170
|
-
const code
|
|
171
|
-
if (attributes.has("src") || attributes.has("server") || attributes.has("component") || attributes.has("stx:component") || !scriptContainsCode(attributes))
|
|
172
|
-
continue;
|
|
175
|
+
const { code, attributes } = script;
|
|
173
176
|
try {
|
|
174
177
|
new Bun.Transpiler({ loader: "ts" }).transformSync(code);
|
|
175
178
|
} catch (error) {
|
|
176
179
|
throw Error(`${file}: failed to transpile <script client> (${error.message})`);
|
|
177
180
|
}
|
|
178
|
-
const extracted = attributes.has("client") ? clientMethods(code) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
|
|
181
|
+
const props = attributes.has("client") ? null : parsePropsDeclaration(code), extracted = attributes.has("client") ? clientMethods(code) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
|
|
179
182
|
for (const method of extracted) {
|
|
180
183
|
if (RESERVED_METHODS.has(method.name))
|
|
181
184
|
throw Error(`${file}: client ${reservedMethodMessage(method.name)}`);
|
|
@@ -220,7 +223,13 @@ function extractClientMethods(source, file) {
|
|
|
220
223
|
} catch {}
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
|
-
|
|
226
|
+
const declaration = code.slice(match.index, cursor), declarationStart = match.index, name = /(?:interface|type)\s+([A-Za-z_$][\w$]*)/.exec(match[0])?.[1], remaining = scripts.map((other) => {
|
|
227
|
+
const body = other === script ? code.slice(0, declarationStart) + code.slice(cursor) : other.code;
|
|
228
|
+
return stripCommentsAndLiterals(body.replace(parsePropsDeclaration(other.code)?.text ?? "\x00", ""));
|
|
229
|
+
}).join(`
|
|
230
|
+
`);
|
|
231
|
+
if (!(props?.typeName === name && !/^export\s/.test(declaration) && name && !new RegExp(`\\b${name}\\b`).test(remaining)))
|
|
232
|
+
types.push(declaration.replace(/^export\s+/, "").trim());
|
|
224
233
|
typePattern.lastIndex = cursor + 1;
|
|
225
234
|
}
|
|
226
235
|
}
|
|
@@ -271,21 +280,6 @@ function inferPropertyType(fallback) {
|
|
|
271
280
|
return "string";
|
|
272
281
|
return "object";
|
|
273
282
|
}
|
|
274
|
-
function literalValue(fallback) {
|
|
275
|
-
if (fallback === "true")
|
|
276
|
-
return !0;
|
|
277
|
-
if (fallback === "false")
|
|
278
|
-
return !1;
|
|
279
|
-
if (/^-?\d+(?:\.\d+)?$/.test(fallback))
|
|
280
|
-
return Number(fallback);
|
|
281
|
-
if (/^['"`]/.test(fallback))
|
|
282
|
-
return fallback.slice(1, -1);
|
|
283
|
-
try {
|
|
284
|
-
return JSON.parse(fallback);
|
|
285
|
-
} catch {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
283
|
export function componentDirectiveExpression(source, open) {
|
|
290
284
|
if (source[open] !== "(")
|
|
291
285
|
return null;
|
|
@@ -376,279 +370,6 @@ function compileTemplateToRender(template) {
|
|
|
376
370
|
return parts.join(`
|
|
377
371
|
`);
|
|
378
372
|
}
|
|
379
|
-
function skipBalanced(source, index, open, close) {
|
|
380
|
-
if (source[index] !== open)
|
|
381
|
-
return -1;
|
|
382
|
-
let depth = 0, quote = null;
|
|
383
|
-
for (let i = index;i < source.length; i++) {
|
|
384
|
-
const char = source[i];
|
|
385
|
-
if (quote) {
|
|
386
|
-
if (char === "\\") {
|
|
387
|
-
i++;
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
if (char === quote)
|
|
391
|
-
quote = null;
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (char === "'" || char === '"' || char === "`") {
|
|
395
|
-
quote = char;
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (char === open)
|
|
399
|
-
depth++;
|
|
400
|
-
else if (char === close) {
|
|
401
|
-
if (close === ">" && source[i - 1] === "=")
|
|
402
|
-
continue;
|
|
403
|
-
depth--;
|
|
404
|
-
if (depth === 0)
|
|
405
|
-
return i + 1;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return -1;
|
|
409
|
-
}
|
|
410
|
-
function splitTopLevel(body, separators, angles) {
|
|
411
|
-
const opening = angles ? "([{<" : "([{", closing = angles ? ")]}>" : ")]}", parts = [];
|
|
412
|
-
let depth = 0, quote = null, current = "";
|
|
413
|
-
for (let i = 0;i < body.length; i++) {
|
|
414
|
-
const char = body[i];
|
|
415
|
-
if (quote) {
|
|
416
|
-
current += char;
|
|
417
|
-
if (char === "\\") {
|
|
418
|
-
current += body[++i] ?? "";
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
421
|
-
if (char === quote)
|
|
422
|
-
quote = null;
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
if (char === "'" || char === '"' || char === "`") {
|
|
426
|
-
quote = char;
|
|
427
|
-
current += char;
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
if (opening.includes(char))
|
|
431
|
-
depth++;
|
|
432
|
-
else if (closing.includes(char) && !(angles && char === ">" && body[i - 1] === "="))
|
|
433
|
-
depth--;
|
|
434
|
-
if (depth === 0 && separators.includes(char)) {
|
|
435
|
-
parts.push(current);
|
|
436
|
-
current = "";
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
current += char;
|
|
440
|
-
}
|
|
441
|
-
parts.push(current);
|
|
442
|
-
return parts.map((part) => part.trim()).filter(Boolean);
|
|
443
|
-
}
|
|
444
|
-
function defaultAssignmentIndex(entry) {
|
|
445
|
-
let depth = 0, quote = null;
|
|
446
|
-
for (let i = 0;i < entry.length; i++) {
|
|
447
|
-
const char = entry[i];
|
|
448
|
-
if (quote) {
|
|
449
|
-
if (char === "\\") {
|
|
450
|
-
i++;
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
if (char === quote)
|
|
454
|
-
quote = null;
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (char === "'" || char === '"' || char === "`") {
|
|
458
|
-
quote = char;
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
if ("([{".includes(char))
|
|
462
|
-
depth++;
|
|
463
|
-
else if (")]}".includes(char))
|
|
464
|
-
depth--;
|
|
465
|
-
if (depth !== 0 || char !== "=")
|
|
466
|
-
continue;
|
|
467
|
-
const previous = entry[i - 1];
|
|
468
|
-
if (entry[i + 1] === "=" || previous === "=" || previous === "!" || previous === "<" || previous === ">")
|
|
469
|
-
continue;
|
|
470
|
-
return i;
|
|
471
|
-
}
|
|
472
|
-
return -1;
|
|
473
|
-
}
|
|
474
|
-
function typeFromConstructor(value) {
|
|
475
|
-
switch (value.trim()) {
|
|
476
|
-
case "String":
|
|
477
|
-
return "string";
|
|
478
|
-
case "Number":
|
|
479
|
-
return "number";
|
|
480
|
-
case "Boolean":
|
|
481
|
-
return "boolean";
|
|
482
|
-
case "Array":
|
|
483
|
-
return "unknown[]";
|
|
484
|
-
case "Object":
|
|
485
|
-
return "Record<string, unknown>";
|
|
486
|
-
default:
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function parsePropsDeclaration(code) {
|
|
491
|
-
const call = /\bdefineProps\b/.exec(code);
|
|
492
|
-
if (!call)
|
|
493
|
-
return null;
|
|
494
|
-
const keyword = /(?:^|[\s;{}()])(const|let|var)\s+/g;
|
|
495
|
-
let start = -1;
|
|
496
|
-
for (let found = keyword.exec(code);found && found.index < call.index; found = keyword.exec(code))
|
|
497
|
-
start = found.index + found[0].indexOf(found[1]);
|
|
498
|
-
if (start === -1)
|
|
499
|
-
return null;
|
|
500
|
-
const declared = {}, defaults = {}, propNames = [], propBindings = {};
|
|
501
|
-
let cursor = start + (/^(?:const|let|var)\s+/.exec(code.slice(start))?.[0].length ?? 0);
|
|
502
|
-
const skipSpace = () => {
|
|
503
|
-
while (cursor < code.length && /\s/.test(code[cursor]))
|
|
504
|
-
cursor++;
|
|
505
|
-
};
|
|
506
|
-
let pattern;
|
|
507
|
-
if (code[cursor] === "{") {
|
|
508
|
-
const end = skipBalanced(code, cursor, "{", "}");
|
|
509
|
-
if (end === -1)
|
|
510
|
-
return null;
|
|
511
|
-
pattern = code.slice(cursor, end);
|
|
512
|
-
cursor = end;
|
|
513
|
-
} else {
|
|
514
|
-
const identifier = /^[A-Za-z_$][\w$]*/.exec(code.slice(cursor));
|
|
515
|
-
if (!identifier)
|
|
516
|
-
return null;
|
|
517
|
-
pattern = identifier[0];
|
|
518
|
-
cursor += identifier[0].length;
|
|
519
|
-
}
|
|
520
|
-
skipSpace();
|
|
521
|
-
if (code[cursor] !== "=")
|
|
522
|
-
return null;
|
|
523
|
-
cursor++;
|
|
524
|
-
skipSpace();
|
|
525
|
-
const wrapper = /^withDefaults\s*\(\s*/.exec(code.slice(cursor)), wrapped = Boolean(wrapper);
|
|
526
|
-
if (wrapper)
|
|
527
|
-
cursor += wrapper[0].length;
|
|
528
|
-
const marker = /^defineProps\b/.exec(code.slice(cursor));
|
|
529
|
-
if (!marker)
|
|
530
|
-
return null;
|
|
531
|
-
cursor += marker[0].length;
|
|
532
|
-
let typeText = "";
|
|
533
|
-
skipSpace();
|
|
534
|
-
if (code[cursor] === "<") {
|
|
535
|
-
const end = skipBalanced(code, cursor, "<", ">");
|
|
536
|
-
if (end === -1)
|
|
537
|
-
return null;
|
|
538
|
-
typeText = code.slice(cursor + 1, end - 1).trim();
|
|
539
|
-
cursor = end;
|
|
540
|
-
}
|
|
541
|
-
skipSpace();
|
|
542
|
-
if (code[cursor] !== "(")
|
|
543
|
-
return null;
|
|
544
|
-
const callEnd = skipBalanced(code, cursor, "(", ")");
|
|
545
|
-
if (callEnd === -1)
|
|
546
|
-
return null;
|
|
547
|
-
const runtimeArgument = code.slice(cursor + 1, callEnd - 1).trim();
|
|
548
|
-
cursor = callEnd;
|
|
549
|
-
if (wrapped) {
|
|
550
|
-
skipSpace();
|
|
551
|
-
if (code[cursor] === ",") {
|
|
552
|
-
cursor++;
|
|
553
|
-
skipSpace();
|
|
554
|
-
}
|
|
555
|
-
if (code[cursor] === "{") {
|
|
556
|
-
const end = skipBalanced(code, cursor, "{", "}");
|
|
557
|
-
if (end === -1)
|
|
558
|
-
return null;
|
|
559
|
-
for (const [name, value] of parseDefaults(code.slice(cursor, end)))
|
|
560
|
-
defaults[name] = value;
|
|
561
|
-
cursor = end;
|
|
562
|
-
}
|
|
563
|
-
skipSpace();
|
|
564
|
-
if (code[cursor] === ",") {
|
|
565
|
-
cursor++;
|
|
566
|
-
skipSpace();
|
|
567
|
-
}
|
|
568
|
-
if (code[cursor] === ")")
|
|
569
|
-
cursor++;
|
|
570
|
-
}
|
|
571
|
-
if (code[cursor] === ";")
|
|
572
|
-
cursor++;
|
|
573
|
-
const typeName = /^[A-Za-z_$][\w$]*$/.test(typeText) ? typeText : void 0;
|
|
574
|
-
if (typeText.startsWith("{"))
|
|
575
|
-
for (const member of splitTopLevel(typeText.replace(/^\{/, "").replace(/\}$/, ""), ",;", !0)) {
|
|
576
|
-
const parsed = /^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(member);
|
|
577
|
-
if (parsed)
|
|
578
|
-
declared[parsed[1]] = parsed[2].trim();
|
|
579
|
-
}
|
|
580
|
-
if (runtimeArgument.startsWith("{"))
|
|
581
|
-
for (const [name, value] of parseDefaults(runtimeArgument)) {
|
|
582
|
-
propNames.push(name);
|
|
583
|
-
if (!value.startsWith("{")) {
|
|
584
|
-
const fromConstructor = typeFromConstructor(value);
|
|
585
|
-
if (fromConstructor)
|
|
586
|
-
declared[name] = fromConstructor;
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
for (const [key, inner] of parseDefaults(value))
|
|
590
|
-
if (key === "default")
|
|
591
|
-
defaults[name] = inner;
|
|
592
|
-
else if (key === "type") {
|
|
593
|
-
const fromConstructor = typeFromConstructor(inner);
|
|
594
|
-
if (fromConstructor)
|
|
595
|
-
declared[name] = fromConstructor;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
else if (runtimeArgument.startsWith("["))
|
|
599
|
-
for (const entry of splitTopLevel(runtimeArgument.slice(1, -1), ",", !1))
|
|
600
|
-
propNames.push(entry.replace(/^['"`]/, "").replace(/['"`]$/, ""));
|
|
601
|
-
if (pattern.startsWith("{")) {
|
|
602
|
-
propNames.length = 0;
|
|
603
|
-
for (const entry of splitTopLevel(pattern.replace(/^\{/, "").replace(/\}$/, ""), ",", !1)) {
|
|
604
|
-
const assignment = defaultAssignmentIndex(entry), binding = assignment === -1 ? entry : entry.slice(0, assignment), name = binding.split(":")[0].trim().replace(/^\.\.\./, "");
|
|
605
|
-
if (!name)
|
|
606
|
-
continue;
|
|
607
|
-
propNames.push(name);
|
|
608
|
-
propBindings[name] = binding.trim();
|
|
609
|
-
if (assignment !== -1)
|
|
610
|
-
defaults[name] = entry.slice(assignment + 1).trim();
|
|
611
|
-
}
|
|
612
|
-
} else if (propNames.length === 0)
|
|
613
|
-
propNames.push(...Object.keys(declared));
|
|
614
|
-
return { text: code.slice(start, cursor), propNames, propBindings, defaults, declared, typeName };
|
|
615
|
-
}
|
|
616
|
-
export function parseDefaults(object) {
|
|
617
|
-
const body = object.trim().replace(/^\{/, "").replace(/\}$/, ""), pairs = [];
|
|
618
|
-
let index = 0;
|
|
619
|
-
while (index < body.length) {
|
|
620
|
-
const key = /\s*([A-Za-z_$][\w$]*)\s*:/y;
|
|
621
|
-
key.lastIndex = index;
|
|
622
|
-
const match = key.exec(body);
|
|
623
|
-
if (!match)
|
|
624
|
-
break;
|
|
625
|
-
index = key.lastIndex;
|
|
626
|
-
let depth = 0, quote = "";
|
|
627
|
-
const start = index;
|
|
628
|
-
while (index < body.length) {
|
|
629
|
-
const char = body[index];
|
|
630
|
-
if (quote) {
|
|
631
|
-
if (char === "\\")
|
|
632
|
-
index++;
|
|
633
|
-
else if (char === quote)
|
|
634
|
-
quote = "";
|
|
635
|
-
} else if (char === "'" || char === '"' || char === "`")
|
|
636
|
-
quote = char;
|
|
637
|
-
else if (char === "{" || char === "[" || char === "(")
|
|
638
|
-
depth++;
|
|
639
|
-
else if (char === "}" || char === "]" || char === ")")
|
|
640
|
-
depth--;
|
|
641
|
-
else if (char === "," && depth === 0)
|
|
642
|
-
break;
|
|
643
|
-
index++;
|
|
644
|
-
}
|
|
645
|
-
const value = body.slice(start, index).trim();
|
|
646
|
-
if (value)
|
|
647
|
-
pairs.push([match[1], value]);
|
|
648
|
-
index++;
|
|
649
|
-
}
|
|
650
|
-
return pairs;
|
|
651
|
-
}
|
|
652
373
|
function hoistScriptImports(code) {
|
|
653
374
|
const masked = stripCommentsAndLiterals(code), depths = bracketDepths(masked).depths, imports = [], spans = [];
|
|
654
375
|
for (const match of masked.matchAll(/\bimport\b/g)) {
|
|
@@ -705,7 +426,7 @@ function compileScriptScope(source) {
|
|
|
705
426
|
if (!block)
|
|
706
427
|
return { imports: [], body: "", propNames: [], propBindings: {}, defaults: {}, declared: {} };
|
|
707
428
|
let code = source.slice(block.bodyStart, block.bodyEnd);
|
|
708
|
-
const imports = [], propNames = [], propBindings =
|
|
429
|
+
const imports = [], propNames = [], propBindings = Object.create(null), defaults = Object.create(null), declared = Object.create(null), hoisted = hoistScriptImports(code);
|
|
709
430
|
imports.push(...hoisted.imports);
|
|
710
431
|
code = hoisted.body;
|
|
711
432
|
const props = parsePropsDeclaration(code);
|
|
@@ -714,7 +435,7 @@ function compileScriptScope(source) {
|
|
|
714
435
|
Object.assign(propBindings, props.propBindings);
|
|
715
436
|
Object.assign(defaults, props.defaults);
|
|
716
437
|
Object.assign(declared, props.declared);
|
|
717
|
-
code = code.replace(props.text, "");
|
|
438
|
+
code = code.replace(props.text, props.identifier ? `const ${props.identifier} = this._props();` : "");
|
|
718
439
|
}
|
|
719
440
|
const interfaceMembers = {};
|
|
720
441
|
for (const block of code.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)) {
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
2
|
+
import"./chunk-gz9pknbw.js";import{Vo,Ua,Wa}from"./chunk-cmg9x1ka.js";import"./chunk-mw7hacm3.js";import"./chunk-2a5g80mq.js";import"./chunk-3dqfjpz4.js";import"./chunk-mgh5rst1.js";import"./chunk-vk2jy6mn.js";import"./chunk-9n5h4sqc.js";import"./chunk-eyx92t9n.js";import"./chunk-s93yh7ed.js";import"./chunk-q0y8gv18.js";import"./chunk-eceeqy74.js";import"./chunk-p8shtje2.js";import"./chunk-95sd8h5g.js";import"./chunk-rb2zbdqd.js";import"./chunk-9d91h636.js";import"./chunk-vc432a0w.js";import"./chunk-mt8edb75.js";import"./chunk-hgf7bc50.js";import"./chunk-48rwqchc.js";import"./chunk-4kmg6g5n.js";import"./chunk-dymck524.js";import"./chunk-05x1rd86.js";import"./chunk-pz554g43.js";import{Hu,qa,Xh,Jh,Ka,Uo,hs,Ga,Xa,Yh,Zh,Ja,Ya,Za,Qa}from"./chunk-6kyqejnq.js";import"./chunk-f3cyghnb.js";import"./chunk-b0e7dgv8.js";import"./chunk-5kqezrjt.js";import"./chunk-bqtj62ys.js";import"./chunk-pctf14yw.js";import"./chunk-eqffvse2.js";import"./chunk-58qzyyyv.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{Hu as CRAFT_BRIDGE_SCRIPT,Uo as CRAFT_COMPONENTS,Ga as CRAFT_COMPONENT_RUNTIME,hs as CRAFT_COMPONENT_STYLES,Vo as NATIVE_COMPONENTS,Ja as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ua as compileToNative,Wa as createHotReloadServer,Ya as findCraftBinary,qa as generateCraftBridgeScript,V as generateCraftOptimizations,Qa as getAvailableFormats,Za as getAvailableTargets,Zh as getCraftComponents,G as getSSRCacheStats,Ka as injectCraftBridge,Xh as isCraftEnvironment,Y as prerenderForCraft,Xa as processCraftComponents,Jh as processCraftDirective,Yh as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
2
|
+
import"./chunk-gz9pknbw.js";import{Vo,Ua,Wa}from"./chunk-cmg9x1ka.js";import"./chunk-mw7hacm3.js";import"./chunk-2a5g80mq.js";import"./chunk-3dqfjpz4.js";import"./chunk-mgh5rst1.js";import"./chunk-vk2jy6mn.js";import"./chunk-9n5h4sqc.js";import"./chunk-eyx92t9n.js";import"./chunk-s93yh7ed.js";import"./chunk-q0y8gv18.js";import"./chunk-eceeqy74.js";import"./chunk-p8shtje2.js";import"./chunk-95sd8h5g.js";import"./chunk-rb2zbdqd.js";import"./chunk-9d91h636.js";import"./chunk-vc432a0w.js";import"./chunk-mt8edb75.js";import"./chunk-hgf7bc50.js";import"./chunk-48rwqchc.js";import"./chunk-4kmg6g5n.js";import"./chunk-dymck524.js";import"./chunk-05x1rd86.js";import"./chunk-pz554g43.js";import{Hu,qa,Xh,Jh,Ka,Uo,hs,Ga,Xa,Yh,Zh,Ja,Ya,Za,Qa}from"./chunk-6kyqejnq.js";import"./chunk-f3cyghnb.js";import"./chunk-b0e7dgv8.js";import"./chunk-5kqezrjt.js";import"./chunk-bqtj62ys.js";import"./chunk-pctf14yw.js";import"./chunk-eqffvse2.js";import"./chunk-58qzyyyv.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{Hu as CRAFT_BRIDGE_SCRIPT,Uo as CRAFT_COMPONENTS,Ga as CRAFT_COMPONENT_RUNTIME,hs as CRAFT_COMPONENT_STYLES,Vo as NATIVE_COMPONENTS,Ja as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ua as compileToNative,Wa as createHotReloadServer,Ya as findCraftBinary,qa as generateCraftBridgeScript,V as generateCraftOptimizations,Qa as getAvailableFormats,Za as getAvailableTargets,Zh as getCraftComponents,G as getSSRCacheStats,Ka as injectCraftBridge,Xh as isCraftEnvironment,Y as prerenderForCraft,Xa as processCraftComponents,Jh as processCraftDirective,Yh as registerCraftComponent,Q as renderSSR};
|
|
@@ -74,19 +74,52 @@ export function parseStringLiteral(raw) {
|
|
|
74
74
|
if (quote !== "'" && quote !== '"' && quote !== "`" || text.length < 2 || text.at(-1) !== quote)
|
|
75
75
|
return null;
|
|
76
76
|
let value = "";
|
|
77
|
+
const escapes = { b: "\b", f: "\f", n: `
|
|
78
|
+
`, r: "\r", t: "\t", v: "\v", 0: "\x00" };
|
|
77
79
|
for (let i = 1;i < text.length - 1; i++) {
|
|
78
80
|
const char = text[i];
|
|
79
|
-
if (char === "\\"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
if (char === "\\") {
|
|
82
|
+
if (++i >= text.length - 1)
|
|
83
|
+
return null;
|
|
84
|
+
const next = text[i];
|
|
85
|
+
if (/[1-9]/.test(next) || next === "0" && /\d/.test(text[i + 1] ?? ""))
|
|
86
|
+
return null;
|
|
87
|
+
if (next === `
|
|
88
|
+
` || next === "\u2028" || next === "\u2029")
|
|
89
|
+
continue;
|
|
90
|
+
if (next === "\r") {
|
|
91
|
+
if (text[i + 1] === `
|
|
92
|
+
`)
|
|
93
|
+
i++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (next === "x" || next === "u") {
|
|
97
|
+
const point = next === "u" && text[i + 1] === "{", end = point ? text.indexOf("}", i + 2) : i + (next === "x" ? 2 : 4) + 1, digits = text.slice(i + (point ? 2 : 1), end);
|
|
98
|
+
if (end < 0 || end >= text.length || !/^[\da-f]+$/i.test(digits) || !point && digits.length !== (next === "x" ? 2 : 4))
|
|
99
|
+
return null;
|
|
100
|
+
const code = Number.parseInt(digits, 16);
|
|
101
|
+
if (code > 1114111)
|
|
102
|
+
return null;
|
|
103
|
+
value += String.fromCodePoint(code);
|
|
104
|
+
i = point ? end : end - 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
value += Object.hasOwn(escapes, next) ? escapes[next] : next;
|
|
83
108
|
continue;
|
|
84
109
|
}
|
|
85
|
-
if (char === quote
|
|
110
|
+
if (char === quote || quote !== "`" && (char === `
|
|
111
|
+
` || char === "\r"))
|
|
86
112
|
return null;
|
|
87
113
|
if (quote === "`" && char === "$" && text[i + 1] === "{")
|
|
88
114
|
return null;
|
|
89
|
-
|
|
115
|
+
if (quote === "`" && char === "\r") {
|
|
116
|
+
if (text[i + 1] === `
|
|
117
|
+
`)
|
|
118
|
+
i++;
|
|
119
|
+
value += `
|
|
120
|
+
`;
|
|
121
|
+
} else
|
|
122
|
+
value += char;
|
|
90
123
|
}
|
|
91
124
|
return value;
|
|
92
125
|
}
|
|
@@ -63,7 +63,8 @@ export declare class Tokenizer {
|
|
|
63
63
|
private line;
|
|
64
64
|
private column;
|
|
65
65
|
private tokens;
|
|
66
|
-
|
|
66
|
+
private context;
|
|
67
|
+
constructor(source: string, context?: 'template' | 'javascript');
|
|
67
68
|
tokenize(): Token[];
|
|
68
69
|
private nextToken;
|
|
69
70
|
private readWhitespace;
|
package/dist/parser/tokenizer.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export class Tokenizer {
|
|
2
|
+
context;
|
|
2
3
|
source;
|
|
3
4
|
pos = 0;
|
|
4
5
|
line = 1;
|
|
5
6
|
column = 0;
|
|
6
7
|
tokens = [];
|
|
7
|
-
constructor(source) {
|
|
8
|
+
constructor(source, context = "template") {
|
|
9
|
+
this.context = context;
|
|
8
10
|
this.source = source;
|
|
9
11
|
}
|
|
10
12
|
tokenize() {
|
|
@@ -45,7 +47,7 @@ export class Tokenizer {
|
|
|
45
47
|
return this.readNumber(start, startLine, startColumn);
|
|
46
48
|
if (/[a-z_$]/i.test(char))
|
|
47
49
|
return this.readIdentifier(start, startLine, startColumn);
|
|
48
|
-
if (char === "{") {
|
|
50
|
+
if (this.context === "template" && char === "{") {
|
|
49
51
|
if (this.peek(1) === "{" && this.peek(2) === "{") {
|
|
50
52
|
this.advance(3);
|
|
51
53
|
return { type: "RAW_START", value: "{{{", start, end: this.pos, line: startLine, column: startColumn };
|
|
@@ -59,7 +61,7 @@ export class Tokenizer {
|
|
|
59
61
|
return { type: "RAW_START", value: "{!!", start, end: this.pos, line: startLine, column: startColumn };
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
if (char === "}") {
|
|
64
|
+
if (this.context === "template" && char === "}") {
|
|
63
65
|
if (this.peek(1) === "}" && this.peek(2) === "}") {
|
|
64
66
|
this.advance(3);
|
|
65
67
|
return { type: "RAW_END", value: "}}}", start, end: this.pos, line: startLine, column: startColumn };
|
|
@@ -69,7 +71,7 @@ export class Tokenizer {
|
|
|
69
71
|
return { type: "EXPRESSION_END", value: "}}", start, end: this.pos, line: startLine, column: startColumn };
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
if (char === "!" && this.peek(1) === "!" && this.peek(2) === "}") {
|
|
74
|
+
if (this.context === "template" && char === "!" && this.peek(1) === "!" && this.peek(2) === "}") {
|
|
73
75
|
this.advance(3);
|
|
74
76
|
return { type: "RAW_END", value: "!!}", start, end: this.pos, line: startLine, column: startColumn };
|
|
75
77
|
}
|
|
@@ -249,7 +251,7 @@ export class Tokenizer {
|
|
|
249
251
|
}
|
|
250
252
|
while (this.pos < this.source.length && /[\d_]/.test(this.source[this.pos]))
|
|
251
253
|
this.advance();
|
|
252
|
-
if (this.source[this.pos] === "." && /\d/.test(this.peek(1) || "")) {
|
|
254
|
+
if (this.source[this.pos] === "." && (this.context === "javascript" || /\d/.test(this.peek(1) || ""))) {
|
|
253
255
|
this.advance();
|
|
254
256
|
while (this.pos < this.source.length && /[\d_]/.test(this.source[this.pos]))
|
|
255
257
|
this.advance();
|