@stacksjs/stx 0.2.503 → 0.2.506
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/browser-core-imports.d.ts +1 -1
- package/dist/browser-core-imports.js +1 -2
- package/dist/builtins/attrs.d.ts +2 -0
- package/dist/builtins/attrs.js +102 -0
- package/dist/{chunk-3mynjdqr.js → chunk-068ank60.js} +3 -3
- package/dist/{chunk-yvt8zszz.js → chunk-06v0c3fz.js} +1 -1
- package/dist/chunk-0eptxhzy.js +2 -0
- package/dist/{chunk-15w4adyd.js → chunk-0vnr7mz7.js} +8 -8
- package/dist/{chunk-bv7bsdfe.js → chunk-1149d93e.js} +2 -2
- package/dist/chunk-1b7dd8rn.js +2 -0
- package/dist/{chunk-0egg3666.js → chunk-1verz406.js} +5 -5
- package/dist/{chunk-7cbtcdqw.js → chunk-2etevws0.js} +2 -2
- package/dist/chunk-2h4bf7m4.js +2 -0
- package/dist/{chunk-z9fz5dby.js → chunk-2j04bc8c.js} +2 -2
- package/dist/{chunk-40jd0b4h.js → chunk-2wr0sk42.js} +1 -1
- package/dist/chunk-36rwfhnb.js +2 -0
- package/dist/{chunk-b5mcvm6y.js → chunk-38xtsdk9.js} +6 -6
- package/dist/chunk-3c9t71pc.js +2 -0
- package/dist/chunk-3pczp9c0.js +2 -0
- package/dist/{chunk-jwjggr91.js → chunk-3ynfz6h8.js} +2 -2
- package/dist/{chunk-1v86h5vn.js → chunk-46wre9ep.js} +3 -3
- package/dist/{chunk-rhrv2j36.js → chunk-4hz4g5ym.js} +2 -2
- package/dist/chunk-4w358hpx.js +2 -0
- package/dist/{chunk-33snwgdy.js → chunk-5dh041x0.js} +3 -3
- package/dist/{chunk-802qf0vz.js → chunk-5q9rmcp7.js} +1 -1
- package/dist/{chunk-qmcmjdy7.js → chunk-5tbqdz94.js} +7 -7
- package/dist/{chunk-zv0vgamy.js → chunk-5tkzfw4s.js} +3 -3
- package/dist/{chunk-25m2wqsd.js → chunk-5zm23zrb.js} +38 -12
- package/dist/{chunk-szry3s17.js → chunk-68tzytfz.js} +3 -3
- package/dist/chunk-76g4jw9g.js +2 -0
- package/dist/{chunk-93sr9q8g.js → chunk-7p6y0b47.js} +1 -1
- package/dist/chunk-7sjmpfwy.js +18 -0
- package/dist/chunk-7z28hk7r.js +2 -0
- package/dist/chunk-8nx5asjr.js +2 -0
- package/dist/chunk-8ptefdpy.js +2 -0
- package/dist/{chunk-cp7hph6f.js → chunk-8xpyzcq2.js} +1 -1
- package/dist/chunk-8zj1ebs5.js +2 -0
- package/dist/{chunk-c8psbk2e.js → chunk-91y360rc.js} +1 -1
- package/dist/chunk-96kr2xrt.js +2828 -0
- package/dist/{chunk-b77v56fz.js → chunk-9p3rtfbv.js} +9 -9
- package/dist/chunk-9xw416q3.js +2 -0
- package/dist/chunk-9z76qhdm.js +2 -0
- package/dist/{chunk-zqxqdns1.js → chunk-9z8mxp15.js} +1 -1
- package/dist/chunk-ag1j84s6.js +2 -0
- package/dist/{chunk-d4k4nyj0.js → chunk-ba88n1j7.js} +2 -2
- package/dist/chunk-c2vwq6gr.js +2 -0
- package/dist/{chunk-2kyfaa0p.js → chunk-c322rrge.js} +2 -2
- package/dist/chunk-cb1c9mvc.js +2 -0
- package/dist/chunk-ces3vdjp.js +2 -0
- package/dist/{chunk-stvqwzen.js → chunk-cprcfp0j.js} +2 -2
- package/dist/chunk-dn4tww9q.js +2 -0
- package/dist/chunk-dne8n6h3.js +3 -0
- package/dist/chunk-dv94gdv4.js +2 -0
- package/dist/chunk-e4zks32s.js +2 -0
- package/dist/{chunk-h0sd5cda.js → chunk-ea19gveh.js} +5 -5
- package/dist/{chunk-tvag2s5a.js → chunk-eacd5755.js} +1 -1
- package/dist/{chunk-8fb1mqw1.js → chunk-ej46bkaw.js} +1 -1
- package/dist/{chunk-1hpttjgq.js → chunk-fh5rp6wb.js} +1 -1
- package/dist/chunk-fkv8jmse.js +2 -0
- package/dist/{chunk-vtn0gmen.js → chunk-fwvqbx49.js} +8 -8
- package/dist/chunk-g1r4v0mc.js +3 -0
- package/dist/{chunk-2pph3dh0.js → chunk-g495xx4v.js} +5 -5
- package/dist/{chunk-vp827ah7.js → chunk-g7wgpys2.js} +4 -4
- package/dist/chunk-gw9ax7xx.js +2 -0
- package/dist/{chunk-4ssg2hn4.js → chunk-h37bbgg8.js} +1 -1
- package/dist/chunk-h3rrsq05.js +2 -0
- package/dist/{chunk-z6nm6rf1.js → chunk-h6z4s5p3.js} +1 -1
- package/dist/chunk-h87zhtw8.js +2 -0
- package/dist/chunk-h9reptxv.js +45 -0
- package/dist/{chunk-vs0ebfg5.js → chunk-hka18tmt.js} +1 -1
- package/dist/chunk-j08y5n2k.js +2 -0
- package/dist/chunk-j7nd8zfe.js +2 -0
- package/dist/{chunk-z9tvn738.js → chunk-jcmgj8kk.js} +1 -1
- package/dist/chunk-jtwx2xte.js +2 -0
- package/dist/{chunk-gvkfydq5.js → chunk-k2331dfx.js} +1 -1
- package/dist/chunk-k5syze27.js +2 -0
- package/dist/{chunk-258qj7pt.js → chunk-km9g9drp.js} +1 -1
- package/dist/{chunk-t61vdbje.js → chunk-ktvr45qg.js} +6 -6
- package/dist/chunk-kxvtyh05.js +2 -0
- package/dist/chunk-mq6expbd.js +2 -0
- package/dist/chunk-mvqhf6dn.js +2 -0
- package/dist/chunk-mz7snf2b.js +2 -0
- package/dist/chunk-n1hd2fx6.js +2 -0
- package/dist/{chunk-298s08st.js → chunk-n34kagea.js} +2 -2
- package/dist/chunk-nnrtwpvy.js +2 -0
- package/dist/chunk-pecwdp57.js +2 -0
- package/dist/{chunk-tdetcthb.js → chunk-ph1xz7k5.js} +2 -2
- package/dist/chunk-pj562qnx.js +2 -0
- package/dist/chunk-pzcw3trh.js +2 -0
- package/dist/{chunk-4mrgy3ve.js → chunk-qt31at4s.js} +4 -4
- package/dist/{chunk-4c1afy15.js → chunk-qv57r0fa.js} +1 -1
- package/dist/{chunk-qhnpc3ac.js → chunk-r14mvycg.js} +22 -22
- package/dist/chunk-r5fzxtbc.js +2 -0
- package/dist/{chunk-vg9dyc4y.js → chunk-rvwtyrj4.js} +1 -1
- package/dist/{chunk-dve4q9tg.js → chunk-s87qrma5.js} +3 -3
- package/dist/chunk-spg0fzyv.js +2 -0
- package/dist/{chunk-hqvdm4h9.js → chunk-t77pz252.js} +1 -1
- package/dist/chunk-t7djn7zd.js +2 -0
- package/dist/{chunk-tse7jzmz.js → chunk-tf239jvd.js} +1 -1
- package/dist/{chunk-gzt3ghgq.js → chunk-tkagcknf.js} +2 -2
- package/dist/{chunk-xevnx24r.js → chunk-tnxprz69.js} +2 -2
- package/dist/{chunk-81t6zr3m.js → chunk-v74acg2k.js} +2 -2
- package/dist/{chunk-f0prq6yw.js → chunk-vc1m5fr9.js} +1 -1
- package/dist/{chunk-jbvg29t0.js → chunk-vftdacyb.js} +1 -1
- package/dist/{chunk-hktvv0hd.js → chunk-vtxzaj1h.js} +2 -2
- package/dist/chunk-w925gtgg.js +2 -0
- package/dist/chunk-w9kj6t7s.js +2 -0
- package/dist/{chunk-b90y5phw.js → chunk-w9mxt96c.js} +78 -78
- package/dist/{chunk-d19vgjjt.js → chunk-x81vcxzs.js} +2 -2
- package/dist/{chunk-rmavqxd8.js → chunk-xd4zvm4x.js} +2 -2
- package/dist/{chunk-x8mp9yvn.js → chunk-xemsypk7.js} +4 -4
- package/dist/{chunk-71bbv43t.js → chunk-xx2pk2ay.js} +3 -3
- package/dist/{chunk-74j18qk0.js → chunk-y8h823cb.js} +28 -28
- package/dist/chunk-yn2d8x8m.js +3 -0
- package/dist/{chunk-hmyyq2hh.js → chunk-z2775k8r.js} +1 -1
- package/dist/{chunk-1erc0vrb.js → chunk-zz5b1g50.js} +2 -2
- package/dist/cli.js +44 -44
- package/dist/component-renderer.js +84 -36
- package/dist/composables/index.d.ts +4 -0
- package/dist/composables/index.js +5 -1
- package/dist/composables/use-timer.d.ts +8 -0
- package/dist/composables/use-timer.js +4 -0
- package/dist/config.js +24 -7
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/native/bridge/protocol.d.ts +3 -0
- package/dist/native/cli.d.ts +1 -0
- package/dist/native/cli.js +7 -2
- package/dist/native/compiler/bundle.d.ts +1 -0
- package/dist/native/compiler/bundle.js +27 -7
- package/dist/native/compiler/html-to-ir.d.ts +3 -1
- package/dist/native/compiler/html-to-ir.js +13 -0
- package/dist/native/runtime/craft-bridge.js +9 -1
- package/dist/native/runtime/craft.d.ts +2 -0
- package/dist/native/runtime/native-host.d.ts +1 -0
- package/dist/native/runtime/native-host.js +1 -0
- package/dist/native/runtime/shared-screen.d.ts +21 -0
- package/dist/native/runtime/shared-screen.js +43 -0
- package/dist/pwa.js +3 -3
- package/dist/runtime-globals.js +4 -0
- package/dist/signals.js +34 -8
- package/dist/ssg.js +2 -2
- package/dist/stx-module.d.ts +4 -0
- package/dist/stx.d.ts +8 -0
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +12 -2
- package/package.json +6 -6
- package/stx-module.d.ts +4 -0
- package/stx.d.ts +8 -0
- package/dist/chunk-0adrp7qd.js +0 -2
- package/dist/chunk-0vdxchfw.js +0 -2
- package/dist/chunk-1mrn5s5z.js +0 -2
- package/dist/chunk-2gr5zcm3.js +0 -2
- package/dist/chunk-2grygc4b.js +0 -2
- package/dist/chunk-379nn8yc.js +0 -2
- package/dist/chunk-3vqabd10.js +0 -2
- package/dist/chunk-490f2x2r.js +0 -2
- package/dist/chunk-4j2ej7er.js +0 -2
- package/dist/chunk-4rmdngzw.js +0 -2
- package/dist/chunk-52saa2nj.js +0 -2
- package/dist/chunk-69dc3tyz.js +0 -2
- package/dist/chunk-6v3p6cx1.js +0 -2
- package/dist/chunk-78vfptph.js +0 -2
- package/dist/chunk-7e6sxdp6.js +0 -2
- package/dist/chunk-7wxmsv41.js +0 -2
- package/dist/chunk-8qdvhbv7.js +0 -18
- package/dist/chunk-9mh1qq3g.js +0 -2
- package/dist/chunk-9z70zv10.js +0 -33
- package/dist/chunk-b0bgprzs.js +0 -2
- package/dist/chunk-c7cajwd2.js +0 -2
- package/dist/chunk-cg8hg6cs.js +0 -3
- package/dist/chunk-ckrpk6ak.js +0 -2
- package/dist/chunk-en0atzsp.js +0 -2
- package/dist/chunk-fxppbahx.js +0 -2
- package/dist/chunk-hhj1txvj.js +0 -2
- package/dist/chunk-j2q2pp0x.js +0 -2
- package/dist/chunk-jbj6xh7f.js +0 -3
- package/dist/chunk-jh385m2w.js +0 -2
- package/dist/chunk-kxg9q64a.js +0 -2
- package/dist/chunk-m9nr12a1.js +0 -2828
- package/dist/chunk-mdfrm5hv.js +0 -2
- package/dist/chunk-mq7vvaf4.js +0 -2
- package/dist/chunk-nfffn3s0.js +0 -2
- package/dist/chunk-nw7qvyek.js +0 -2
- package/dist/chunk-ny64ezsj.js +0 -2
- package/dist/chunk-qjba655t.js +0 -2
- package/dist/chunk-qjxxd4a0.js +0 -2
- package/dist/chunk-qsy7phd4.js +0 -2
- package/dist/chunk-rfq1jfhf.js +0 -2
- package/dist/chunk-rr41gk8b.js +0 -2
- package/dist/chunk-snyq0jj6.js +0 -2
- package/dist/chunk-sybzayv3.js +0 -2
- package/dist/chunk-v7vkqg8f.js +0 -3
- package/dist/chunk-v8m2khkq.js +0 -2
- package/dist/chunk-vbhykx9z.js +0 -2
- package/dist/chunk-xfxrh6vx.js +0 -2
- package/dist/chunk-xk2mwk61.js +0 -2
- package/dist/chunk-zbzmfqmk.js +0 -2
|
@@ -2,7 +2,7 @@ import { buildStxIndex, componentImportCandidates, resolvePackageDir } from "./c
|
|
|
2
2
|
import { registry } from "./component-registry.js";
|
|
3
3
|
import { processConditionals } from "./conditionals.js";
|
|
4
4
|
import { registerBuiltins } from "./builtins/index.js";
|
|
5
|
-
import { forwardResolvedAttrs, forwardStaticAttrs } from "./builtins/attrs.js";
|
|
5
|
+
import { forwardResolvedAttrs, forwardStaticAttrs, isFallthroughAttribute } from "./builtins/attrs.js";
|
|
6
6
|
import { escapeAttr } from "./builtins/escape.js";
|
|
7
7
|
import { decodeAttributeEntities, decodeStxProp, findComponentTags, parseMultilineAttributes, pascalToKebab, readBracedValue, restoreStashedScripts, stashScriptElements, unwrapBracedExpression, uppercaseHtmlTagSkip } from "./component-processing.js";
|
|
8
8
|
import { maskAtElementPosition, matchHtmlComment } from "./html-masking.js";
|
|
@@ -496,8 +496,9 @@ async function processCustomElementTags(template, context, filePath, options, de
|
|
|
496
496
|
mergedProps[key] = value;
|
|
497
497
|
for (const [key, value] of Object.entries(resolvedProps.serverDynamic))
|
|
498
498
|
mergedProps[key] = value;
|
|
499
|
-
|
|
500
|
-
finalContent =
|
|
499
|
+
const renderMetadata = { declaredProps: new Set };
|
|
500
|
+
let finalContent = await renderComponentWithSlot(componentPath, mergedProps, stashed.restore(tag.content), componentsDir, context, filePath, options, processedComponents, dependencies, [...loopNames], renderMetadata);
|
|
501
|
+
finalContent = forwardHostAttrs(finalContent, resolvedProps, renderMetadata.declaredProps);
|
|
501
502
|
if (Object.keys(resolvedProps.events).length > 0) {
|
|
502
503
|
const root = findRenderedComponentRoot(finalContent);
|
|
503
504
|
if (root) {
|
|
@@ -540,51 +541,56 @@ function emitClientReactiveAttrs(html, clientReactive) {
|
|
|
540
541
|
output = `<template :for="${forExpression.replace(/"/g, """)}">${output}</template>`;
|
|
541
542
|
return output;
|
|
542
543
|
}
|
|
543
|
-
function
|
|
544
|
-
const root =
|
|
544
|
+
function forwardHostAttrs(html, props, declaredProps = new Set) {
|
|
545
|
+
const root = findRenderedComponentHostRoot(html);
|
|
545
546
|
if (!root)
|
|
546
547
|
return html;
|
|
547
|
-
const openingTag = html.slice(root.insertPos, root.tagEnd);
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
for (const key of Object.keys(props.static))
|
|
552
|
-
if (existing.has(props.staticNames[key] ?? key))
|
|
548
|
+
const openingTag = html.slice(root.insertPos, root.tagEnd), isNativeHost = /\bdata-native(?:\s|=)/i.test(openingTag), existing = new Set(Object.keys(parseAllAttributes(openingTag))), consumed = new Set(["class", "className"]);
|
|
549
|
+
for (const key of Object.keys(props.static)) {
|
|
550
|
+
const name = props.staticNames[key] ?? key;
|
|
551
|
+
if (existing.has(name) || !isNativeHost && (declaredProps.has(key) || !isFallthroughAttribute(name)))
|
|
553
552
|
consumed.add(key);
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
}
|
|
554
|
+
for (const key of Object.keys(props.serverDynamic)) {
|
|
555
|
+
const name = props.serverDynamicNames?.[key] ?? key;
|
|
556
|
+
if (existing.has(name) || !isNativeHost && (declaredProps.has(key) || !isFallthroughAttribute(name)))
|
|
556
557
|
consumed.add(key);
|
|
557
|
-
const forwardedTrue = [];
|
|
558
|
-
for (const [key, value] of Object.entries(props.static)) {
|
|
559
|
-
if (consumed.has(key) || value !== !0 && value !== BOOLEAN_ATTRIBUTE_SENTINEL)
|
|
560
|
-
continue;
|
|
561
|
-
consumed.add(key);
|
|
562
|
-
forwardedTrue.push(`${escapeAttr(props.staticNames?.[key] ?? key)}="true"`);
|
|
563
558
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
559
|
+
const forwardedTrue = [];
|
|
560
|
+
if (isNativeHost) {
|
|
561
|
+
for (const [key, value] of Object.entries(props.static)) {
|
|
562
|
+
if (consumed.has(key) || value !== !0 && value !== BOOLEAN_ATTRIBUTE_SENTINEL)
|
|
563
|
+
continue;
|
|
564
|
+
consumed.add(key);
|
|
565
|
+
forwardedTrue.push(`${escapeAttr(props.staticNames?.[key] ?? key)}="true"`);
|
|
566
|
+
}
|
|
567
|
+
for (const [key, value] of Object.entries(props.serverDynamic)) {
|
|
568
|
+
if (consumed.has(key) || value !== !0)
|
|
569
|
+
continue;
|
|
570
|
+
consumed.add(key);
|
|
571
|
+
forwardedTrue.push(`${escapeAttr(props.serverDynamicNames?.[key] ?? key)}="true"`);
|
|
572
|
+
}
|
|
569
573
|
}
|
|
570
574
|
const forwarded = [
|
|
571
575
|
...forwardStaticAttrs(props, consumed),
|
|
572
576
|
...forwardResolvedAttrs(props, consumed),
|
|
573
577
|
...forwardedTrue
|
|
574
578
|
];
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
forwarded.push(`${escapeAttr(name)}="false"`);
|
|
580
|
-
}
|
|
581
|
-
for (const [key, value] of Object.entries(props.serverDynamic)) {
|
|
582
|
-
if (consumed.has(key) || value === null || typeof value !== "object")
|
|
583
|
-
continue;
|
|
584
|
-
const encoded = JSON.stringify(value);
|
|
585
|
-
if (encoded !== void 0) {
|
|
579
|
+
if (isNativeHost) {
|
|
580
|
+
for (const [key, value] of Object.entries(props.serverDynamic)) {
|
|
581
|
+
if (consumed.has(key) || value !== !1)
|
|
582
|
+
continue;
|
|
586
583
|
const name = props.serverDynamicNames?.[key] ?? key;
|
|
587
|
-
forwarded.push(`${escapeAttr(name)}="
|
|
584
|
+
forwarded.push(`${escapeAttr(name)}="false"`);
|
|
585
|
+
}
|
|
586
|
+
for (const [key, value] of Object.entries(props.serverDynamic)) {
|
|
587
|
+
if (consumed.has(key) || value === null || typeof value !== "object")
|
|
588
|
+
continue;
|
|
589
|
+
const encoded = JSON.stringify(value);
|
|
590
|
+
if (encoded !== void 0) {
|
|
591
|
+
const name = props.serverDynamicNames?.[key] ?? key;
|
|
592
|
+
forwarded.push(`${escapeAttr(name)}="${escapeAttr(encoded)}"`);
|
|
593
|
+
}
|
|
588
594
|
}
|
|
589
595
|
}
|
|
590
596
|
if (forwarded.length === 0)
|
|
@@ -630,6 +636,48 @@ function findRenderedComponentRoot(html) {
|
|
|
630
636
|
}
|
|
631
637
|
return null;
|
|
632
638
|
}
|
|
639
|
+
function findRenderedComponentHostRoot(html) {
|
|
640
|
+
const wrapper = findRenderedComponentRoot(html);
|
|
641
|
+
if (!wrapper)
|
|
642
|
+
return null;
|
|
643
|
+
const wrapperOpeningTag = html.slice(wrapper.insertPos, wrapper.tagEnd);
|
|
644
|
+
if (!/\bdata-stx-component-wrapper(?:\s|=|>|$)/i.test(wrapperOpeningTag))
|
|
645
|
+
return wrapper;
|
|
646
|
+
return findFirstRenderedElement(html, wrapper.tagEnd + 1);
|
|
647
|
+
}
|
|
648
|
+
function findFirstRenderedElement(html, start) {
|
|
649
|
+
let cursor = start;
|
|
650
|
+
while (cursor < html.length) {
|
|
651
|
+
const rest = html.slice(cursor), whitespace = rest.match(/^\s+/);
|
|
652
|
+
if (whitespace) {
|
|
653
|
+
cursor += whitespace[0].length;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (rest.startsWith("<!--")) {
|
|
657
|
+
const end = html.indexOf("-->", cursor + 4);
|
|
658
|
+
if (end === -1)
|
|
659
|
+
return null;
|
|
660
|
+
cursor = end + 3;
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const nonRootTag = rest.match(/^<(script|style)\b[^>]*>/i);
|
|
664
|
+
if (nonRootTag) {
|
|
665
|
+
const closeTag = `</${nonRootTag[1].toLowerCase()}>`, end = html.toLowerCase().indexOf(closeTag, cursor + nonRootTag[0].length);
|
|
666
|
+
if (end === -1)
|
|
667
|
+
return null;
|
|
668
|
+
cursor = end + closeTag.length;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const root = rest.match(/^<([a-zA-Z][a-zA-Z0-9-]*)(?:\s|>|\/)/);
|
|
672
|
+
if (!root)
|
|
673
|
+
return null;
|
|
674
|
+
return {
|
|
675
|
+
insertPos: cursor + 1 + root[1].length,
|
|
676
|
+
tagEnd: findOpeningTagEnd(html, cursor + 1 + root[1].length)
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
633
681
|
function findOpeningTagEnd(html, cursor) {
|
|
634
682
|
let quote = "";
|
|
635
683
|
for (let i = cursor;i < html.length; i++) {
|
|
@@ -395,10 +395,14 @@ export {
|
|
|
395
395
|
// Timers
|
|
396
396
|
export {
|
|
397
397
|
useDebounce,
|
|
398
|
+
useDebounceFn,
|
|
398
399
|
useDebouncedValue,
|
|
400
|
+
refDebounced,
|
|
399
401
|
useThrottle,
|
|
402
|
+
useThrottleFn,
|
|
400
403
|
useInterval,
|
|
401
404
|
useTimeout,
|
|
405
|
+
useTimeoutFn,
|
|
402
406
|
type DebouncedFn,
|
|
403
407
|
type ThrottledFn,
|
|
404
408
|
type DebouncedValueRef,
|
|
@@ -216,10 +216,14 @@ export {
|
|
|
216
216
|
} from "./use-meta.js";
|
|
217
217
|
export {
|
|
218
218
|
useDebounce,
|
|
219
|
+
useDebounceFn,
|
|
219
220
|
useDebouncedValue,
|
|
221
|
+
refDebounced,
|
|
220
222
|
useThrottle,
|
|
223
|
+
useThrottleFn,
|
|
221
224
|
useInterval,
|
|
222
|
-
useTimeout
|
|
225
|
+
useTimeout,
|
|
226
|
+
useTimeoutFn
|
|
223
227
|
} from "./use-timer.js";
|
|
224
228
|
export {
|
|
225
229
|
useToggle,
|
|
@@ -51,6 +51,14 @@ export declare function useInterval(interval?: number | ((counter: number) => vo
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export declare function useTimeout(callback: () => void, delay?: number): TimeoutRef;
|
|
54
|
+
/** VueUse-compatible alias for useDebounce. */
|
|
55
|
+
export declare const useDebounceFn: unknown;
|
|
56
|
+
/** VueUse-compatible alias for the existing debounced value ref. */
|
|
57
|
+
export declare const refDebounced: unknown;
|
|
58
|
+
/** VueUse-compatible alias for useThrottle. */
|
|
59
|
+
export declare const useThrottleFn: unknown;
|
|
60
|
+
/** VueUse-compatible alias for useTimeout. */
|
|
61
|
+
export declare const useTimeoutFn: unknown;
|
|
54
62
|
/**
|
|
55
63
|
* useDebounce, useDebouncedValue, useThrottle, useInterval, useTimeout
|
|
56
64
|
*
|
|
@@ -31,6 +31,7 @@ export function useDebounce(fn, delay = 250) {
|
|
|
31
31
|
globalThis.onDestroy(debounced.cancel);
|
|
32
32
|
return debounced;
|
|
33
33
|
}
|
|
34
|
+
export const useDebounceFn = useDebounce;
|
|
34
35
|
export function useDebouncedValue(getter, delay = 250) {
|
|
35
36
|
let current = getter();
|
|
36
37
|
const listeners = new Set;
|
|
@@ -66,6 +67,7 @@ export function useDebouncedValue(getter, delay = 250) {
|
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
69
|
}
|
|
70
|
+
export const refDebounced = useDebouncedValue;
|
|
69
71
|
export function useThrottle(fn, limit = 250) {
|
|
70
72
|
let timer = null, lastRan = 0;
|
|
71
73
|
const throttled = (...args) => {
|
|
@@ -94,6 +96,7 @@ export function useThrottle(fn, limit = 250) {
|
|
|
94
96
|
globalThis.onDestroy(throttled.cancel);
|
|
95
97
|
return throttled;
|
|
96
98
|
}
|
|
99
|
+
export const useThrottleFn = useThrottle;
|
|
97
100
|
export function useInterval(interval = 1000, options = {}) {
|
|
98
101
|
let callback = null;
|
|
99
102
|
if (typeof interval === "function") {
|
|
@@ -191,3 +194,4 @@ export function useTimeout(callback, delay = 1000) {
|
|
|
191
194
|
}
|
|
192
195
|
};
|
|
193
196
|
}
|
|
197
|
+
export const useTimeoutFn = useTimeout;
|
package/dist/config.js
CHANGED
|
@@ -494,13 +494,30 @@ export async function loadStxConfig(cwd) {
|
|
|
494
494
|
if (cached)
|
|
495
495
|
return cached;
|
|
496
496
|
const promise = (async () => {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
497
|
+
const rootConfigExtensions = [".ts", ".js", ".mjs", ".cjs", ".json"], hasRootConfig = rootConfigExtensions.some((ext) => fs.existsSync(path.join(effectiveCwd, `stx.config${ext}`))), hasUiConfig = rootConfigExtensions.some((ext) => fs.existsSync(path.join(effectiveCwd, "config", `ui${ext}`)));
|
|
498
|
+
let loaded;
|
|
499
|
+
if (hasRootConfig && hasUiConfig) {
|
|
500
|
+
const uiResult = await loadConfigWithResult({
|
|
501
|
+
name: "ui",
|
|
502
|
+
cwd: path.join(effectiveCwd, "config"),
|
|
503
|
+
defaultConfig,
|
|
504
|
+
verbose: !1
|
|
505
|
+
});
|
|
506
|
+
loaded = (await loadConfigWithResult({
|
|
507
|
+
name: "stx",
|
|
508
|
+
alias: "ui",
|
|
509
|
+
cwd: effectiveCwd,
|
|
510
|
+
defaultConfig: uiResult.config,
|
|
511
|
+
verbose: !1
|
|
512
|
+
})).config;
|
|
513
|
+
} else
|
|
514
|
+
loaded = (await loadConfigWithResult({
|
|
515
|
+
name: "stx",
|
|
516
|
+
alias: "ui",
|
|
517
|
+
cwd: effectiveCwd,
|
|
518
|
+
defaultConfig,
|
|
519
|
+
verbose: !1
|
|
520
|
+
})).config;
|
|
504
521
|
if (loaded.extends !== void 0 || snapshot) {
|
|
505
522
|
const resolved = await resolveApplicationLayers(effectiveCwd, defaultConfig);
|
|
506
523
|
loaded = resolved.config;
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-tkagcknf.js";import"./chunk-g495xx4v.js";import"./chunk-c57j92td.js";import"./chunk-xd4zvm4x.js";import"./chunk-g1r4v0mc.js";import"./chunk-ba88n1j7.js";import"./chunk-96kr2xrt.js";import"./chunk-9p3rtfbv.js";import"./chunk-5tbqdz94.js";import"./chunk-zz5b1g50.js";import"./chunk-v74acg2k.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import{vd,ko,wd,xd,Co,zr,Eo,Sd,$o,kd,Cd,To,_o,Ro}from"./chunk-r14mvycg.js";import"./chunk-7sjmpfwy.js";import"./chunk-68tzytfz.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{vd as CRAFT_BRIDGE_SCRIPT,zr as CRAFT_COMPONENTS,Sd as CRAFT_COMPONENT_RUNTIME,Eo as CRAFT_COMPONENT_STYLES,Hr as NATIVE_COMPONENTS,To as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ao as compileToNative,Po as createHotReloadServer,ko as generateCraftBridgeScript,V as generateCraftOptimizations,Ro as getAvailableFormats,_o as getAvailableTargets,Cd as getCraftComponents,G as getSSRCacheStats,Co as injectCraftBridge,wd as isCraftEnvironment,Y as prerenderForCraft,$o as processCraftComponents,xd as processCraftDirective,kd as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hr,Ao,Po}from"./chunk-
|
|
2
|
+
import{Hr,Ao,Po}from"./chunk-tkagcknf.js";import"./chunk-g495xx4v.js";import"./chunk-c57j92td.js";import"./chunk-xd4zvm4x.js";import"./chunk-g1r4v0mc.js";import"./chunk-ba88n1j7.js";import"./chunk-96kr2xrt.js";import"./chunk-9p3rtfbv.js";import"./chunk-5tbqdz94.js";import"./chunk-zz5b1g50.js";import"./chunk-v74acg2k.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import{vd,ko,wd,xd,Co,zr,Eo,Sd,$o,kd,Cd,To,_o,Ro}from"./chunk-r14mvycg.js";import"./chunk-7sjmpfwy.js";import"./chunk-68tzytfz.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{vd as CRAFT_BRIDGE_SCRIPT,zr as CRAFT_COMPONENTS,Sd as CRAFT_COMPONENT_RUNTIME,Eo as CRAFT_COMPONENT_STYLES,Hr as NATIVE_COMPONENTS,To as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ao as compileToNative,Po as createHotReloadServer,ko as generateCraftBridgeScript,V as generateCraftOptimizations,Ro as getAvailableFormats,_o as getAvailableTargets,Cd as getCraftComponents,G as getSSRCacheStats,Co as injectCraftBridge,wd as isCraftEnvironment,Y as prerenderForCraft,$o as processCraftComponents,xd as processCraftDirective,kd as registerCraftComponent,Q as renderSSR};
|
|
@@ -246,6 +246,9 @@ export declare interface NativeBridgeInterface {
|
|
|
246
246
|
capabilityTimeoutMs?: number
|
|
247
247
|
initialAppState?: 'active' | 'inactive' | 'background'
|
|
248
248
|
colorScheme?: 'light' | 'dark'
|
|
249
|
+
appURL?: string
|
|
250
|
+
appVersion?: string
|
|
251
|
+
appBuild?: string
|
|
249
252
|
postMessage(message: string): void
|
|
250
253
|
onMessage(callback: (message: string) => void): void
|
|
251
254
|
}
|
package/dist/native/cli.d.ts
CHANGED
package/dist/native/cli.js
CHANGED
|
@@ -25,7 +25,12 @@ export function loadNativeScreensConfig(cwd = process.cwd(), configFile) {
|
|
|
25
25
|
const initialScreen = raw.initialScreen || entries[0][0];
|
|
26
26
|
if (!screens[initialScreen])
|
|
27
27
|
throw Error(`Initial screen ${initialScreen} is not in screens`);
|
|
28
|
-
|
|
28
|
+
if (raw.app !== void 0 && typeof raw.app !== "string")
|
|
29
|
+
throw Error(`"app" must name the app script's file`);
|
|
30
|
+
const app = raw.app ? path.resolve(path.dirname(file), raw.app) : void 0;
|
|
31
|
+
if (app && !existsSync(app))
|
|
32
|
+
throw Error(`App script not found: ${app}`);
|
|
33
|
+
return { initialScreen, screens, file, ...app ? { app } : {} };
|
|
29
34
|
}
|
|
30
35
|
export async function runNativeCompile(file, options = {}) {
|
|
31
36
|
const cwd = path.resolve(options.cwd ?? process.cwd()), format = options.format ?? "ir";
|
|
@@ -36,7 +41,7 @@ export async function runNativeCompile(file, options = {}) {
|
|
|
36
41
|
throw Error(`Please specify an input file: stx native compile <file.stx>, or add ${NATIVE_CONFIG_FILES[0]}`);
|
|
37
42
|
let output, diagnostics = [];
|
|
38
43
|
if (format === "bundle") {
|
|
39
|
-
const bundle = config ? await compileNativeBundle({ screens: config.screens, initialScreen: config.initialScreen, minify: options.minify, root: cwd }) : await compileScreenBundle(path.resolve(cwd, file), { minify: options.minify });
|
|
44
|
+
const bundle = config ? await compileNativeBundle({ screens: config.screens, initialScreen: config.initialScreen, minify: options.minify, root: cwd, ...config.app ? { app: config.app } : {} }) : await compileScreenBundle(path.resolve(cwd, file), { minify: options.minify });
|
|
40
45
|
output = bundle.code;
|
|
41
46
|
diagnostics = bundle.diagnostics;
|
|
42
47
|
} else {
|
|
@@ -27,6 +27,7 @@ export declare interface CompileNativeBundleOptions {
|
|
|
27
27
|
routed?: boolean
|
|
28
28
|
outFile?: string
|
|
29
29
|
root?: string
|
|
30
|
+
app?: string
|
|
30
31
|
}
|
|
31
32
|
/** Something the compiler could not translate exactly: an unknown icon or class. */
|
|
32
33
|
export declare interface NativeDiagnostic {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { compileScreenFile } from "./render-screen.js";
|
|
4
|
+
import { NATIVE_APP_ROUTE } from "../runtime/shared-screen.js";
|
|
4
5
|
import { generateSignalsRuntime } from "../../signals.js";
|
|
5
6
|
function nativeRuntimeModule(name) {
|
|
6
7
|
const resolved = [
|
|
@@ -43,8 +44,17 @@ export async function compileNativeBundle(options) {
|
|
|
43
44
|
throw Error(`Screen ${name} must name a .stx file`);
|
|
44
45
|
compiledScreens.push({ name, file, compiled: await compileScreenFile(file, { root }) });
|
|
45
46
|
}
|
|
46
|
-
const runtimeGlobals = nativeRuntimeModule("jsc-globals"), sharedScreen = nativeRuntimeModule("shared-screen"),
|
|
47
|
-
if (
|
|
47
|
+
const runtimeGlobals = nativeRuntimeModule("jsc-globals"), sharedScreen = nativeRuntimeModule("shared-screen"), appFile = options.app ? path.resolve(root, options.app) : null;
|
|
48
|
+
if (appFile && !existsSync(appFile))
|
|
49
|
+
throw Error(`The app script ${options.app} does not exist`);
|
|
50
|
+
if (appFile && !routed)
|
|
51
|
+
throw Error("An app script needs a routed bundle");
|
|
52
|
+
if (appFile && options.screens[NATIVE_APP_ROUTE])
|
|
53
|
+
throw Error(`${NATIVE_APP_ROUTE} is the app script's route, not a screen name`);
|
|
54
|
+
const route = routed ? `var routeName = g.__stxNativeRoute || ${JSON.stringify(initialScreen)};
|
|
55
|
+
var isApp = ${appFile ? `routeName === ${JSON.stringify(NATIVE_APP_ROUTE)}` : "false"};
|
|
56
|
+
if (!isApp && routeNames.indexOf(routeName) === -1) throw new Error(['Unknown native screen:', routeName].join(' '));` : `var routeName = 'main';
|
|
57
|
+
var isApp = false;`, selections = compiledScreens.map(({ name, compiled }, index) => `${index === 0 ? "if" : "else if"} (routeName === ${JSON.stringify(routed ? name : "main")}) {
|
|
48
58
|
nativeDocument = ${JSON.stringify(compiled.document)};
|
|
49
59
|
manifest = ${JSON.stringify(compiled.manifest)};
|
|
50
60
|
}`).join(`
|
|
@@ -53,7 +63,8 @@ ${compiled.setup?.code ?? "g.__stx_latestSetup = null;"}
|
|
|
53
63
|
}`).join(`
|
|
54
64
|
`), contents = `
|
|
55
65
|
import { installJSCGlobals } from ${JSON.stringify(runtimeGlobals)};
|
|
56
|
-
import { prepareSharedNativeScreen } from ${JSON.stringify(sharedScreen)};
|
|
66
|
+
import { prepareNativeApp, prepareSharedNativeScreen } from ${JSON.stringify(sharedScreen)};
|
|
67
|
+
${appFile ? `import * as nativeAppModule from ${JSON.stringify(appFile)};` : "var nativeAppModule = null;"}
|
|
57
68
|
var g = globalThis;
|
|
58
69
|
installJSCGlobals(g);
|
|
59
70
|
var bridge = g.__stxNativeBridge;
|
|
@@ -64,12 +75,21 @@ g.__stxNativeRoute = routeName;
|
|
|
64
75
|
var nativeDocument;
|
|
65
76
|
var manifest;
|
|
66
77
|
${selections}
|
|
67
|
-
var screen =
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
var screen = null;
|
|
79
|
+
var app = null;
|
|
80
|
+
if (isApp) {
|
|
81
|
+
app = prepareNativeApp(bridge, { routeName: routeName, routeNames: routeNames });
|
|
82
|
+
g.__stxNativeUnmount = function() { app.unmount(); };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
screen = prepareSharedNativeScreen(nativeDocument, manifest, bridge, { routeName: routeName, routeNames: routeNames });
|
|
86
|
+
g.__stx_host = screen.host;
|
|
87
|
+
g.__stxNativeUnmount = function() { screen.unmount(); };
|
|
88
|
+
}
|
|
70
89
|
${generateSignalsRuntime()}
|
|
71
90
|
${setups}
|
|
72
|
-
|
|
91
|
+
if (isApp) app.start(nativeAppModule);
|
|
92
|
+
else screen.mount(g.stx, g.__stx_latestSetup || null);
|
|
73
93
|
`, code = await build("stx:native-shared-screens", [{
|
|
74
94
|
name: "stx-native-shared-screens",
|
|
75
95
|
setup(builder) {
|
|
@@ -38,4 +38,6 @@ export type TranslationDiagnosticKind = | 'unmapped-tag'
|
|
|
38
38
|
/** An inline CSS property the IR has no field for. */
|
|
39
39
|
| 'unknown-style'
|
|
40
40
|
/** A value the IR's field cannot hold, so emitting it would brick the screen. */
|
|
41
|
-
| 'non-numeric-style'
|
|
41
|
+
| 'non-numeric-style'
|
|
42
|
+
/** A legacy virtual-list prop has no meaning in the shared-runtime tree. */
|
|
43
|
+
| 'unsupported-list-prop';
|
|
@@ -265,6 +265,13 @@ const STYLE_KEYS = new Set([
|
|
|
265
265
|
"StatusBar",
|
|
266
266
|
"RefreshControl",
|
|
267
267
|
...SVG_NODE_TYPES
|
|
268
|
+
]), SHARED_RUNTIME_UNSUPPORTED_LIST_PROPS = new Map([
|
|
269
|
+
["data", "data"],
|
|
270
|
+
["sections", "sections"],
|
|
271
|
+
["renderitem", "renderItem"],
|
|
272
|
+
["rendersectionheader", "renderSectionHeader"],
|
|
273
|
+
["keyextractor", "keyExtractor"],
|
|
274
|
+
["listrole", "listRole"]
|
|
268
275
|
]), CONTAINER_TYPES = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView"]), ENTITIES = {
|
|
269
276
|
amp: "&",
|
|
270
277
|
lt: "<",
|
|
@@ -491,6 +498,12 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
491
498
|
const icon = compileClassStyles(classes).icon;
|
|
492
499
|
props.symbol = resolveIconName(String(props.symbol || props.name || icon || ""), Boolean(props.symbol)).symbol;
|
|
493
500
|
}
|
|
501
|
+
if (type === "FlatList" || type === "SectionList") {
|
|
502
|
+
const names = new Set([...Object.keys(props), ...Object.keys(bindings)].map((name) => name.toLowerCase()));
|
|
503
|
+
for (const [lowerName, publicName] of SHARED_RUNTIME_UNSUPPORTED_LIST_PROPS)
|
|
504
|
+
if (names.has(lowerName))
|
|
505
|
+
diagnostics.push({ kind: "unsupported-list-prop", tag: type, name: publicName });
|
|
506
|
+
}
|
|
494
507
|
const node = createNode(type, props, style, events);
|
|
495
508
|
node._inlineStyle = inline;
|
|
496
509
|
const bindingId = props["data-stx-b"];
|
|
@@ -40,7 +40,8 @@ function capabilityFlags(capabilities) {
|
|
|
40
40
|
health: capabilities.has("health"),
|
|
41
41
|
dialogs: capabilities.has("dialog"),
|
|
42
42
|
browser: capabilities.has("browser"),
|
|
43
|
-
appleSignIn: capabilities.has("appleSignIn")
|
|
43
|
+
appleSignIn: capabilities.has("appleSignIn"),
|
|
44
|
+
background: capabilities.has("background")
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
function platformUserAgent(platform) {
|
|
@@ -146,6 +147,13 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
146
147
|
};
|
|
147
148
|
if (capabilities.has("browser"))
|
|
148
149
|
craft.browser = { open: (url, options = {}) => ask("Browser", "open", [url, options]) };
|
|
150
|
+
craft.app = {
|
|
151
|
+
url: typeof nativeBridge.appURL === "string" ? nativeBridge.appURL : "",
|
|
152
|
+
version: typeof nativeBridge.appVersion === "string" ? nativeBridge.appVersion : "",
|
|
153
|
+
build: typeof nativeBridge.appBuild === "string" ? nativeBridge.appBuild : ""
|
|
154
|
+
};
|
|
155
|
+
if (capabilities.has("background"))
|
|
156
|
+
craft.background = { complete: (ok = !0, id) => request("Background", "complete", [ok !== !1, typeof id === "string" ? id : null]).then(() => !0, () => !1) };
|
|
149
157
|
if (capabilities.has("appleSignIn"))
|
|
150
158
|
craft.signInWithApple = (options = {}) => ask("Auth", "signInWithApple", [options]);
|
|
151
159
|
if (capabilities.has("linking")) {
|
|
@@ -203,5 +203,7 @@ export declare interface NativeCraft {
|
|
|
203
203
|
onChange: (callback: (state: string) => unknown) => () => void
|
|
204
204
|
}
|
|
205
205
|
deepLinks: { getInitialURL: () => Promise<string | null>, onLink: (callback: (link: unknown) => unknown) => () => void }
|
|
206
|
+
app: { url: string, version: string, build: string }
|
|
207
|
+
background?: { complete: (ok?: boolean, id?: string) => Promise<boolean> }
|
|
206
208
|
}
|
|
207
209
|
export type NativePermissionStatus = 'granted' | 'denied' | 'undetermined';
|
|
@@ -16,6 +16,7 @@ export declare interface NativeHostOptions {
|
|
|
16
16
|
schedule?: (flush: () => void) => void
|
|
17
17
|
}
|
|
18
18
|
export declare interface NativeHost {
|
|
19
|
+
readonly isNative: true
|
|
19
20
|
setColorScheme: (scheme: 'light' | 'dark') => void
|
|
20
21
|
setText: (node: NativeNode, value: unknown) => void
|
|
21
22
|
setAttribute: (node: NativeNode, name: string, value: unknown) => void
|
|
@@ -5,6 +5,9 @@ import type { NativeBridgeInterface } from '../bridge/protocol';
|
|
|
5
5
|
import type { STXDocument } from '../compiler/ir';
|
|
6
6
|
/** Connect translated IR to the ordinary stx signals runtime and native bridge. */
|
|
7
7
|
export declare function prepareSharedNativeScreen(document: STXDocument, manifest: BindingManifest, bridge: NativeBridgeInterface, options?: CraftBridgeOptions): SharedNativeScreen;
|
|
8
|
+
export declare function prepareNativeApp(bridge: NativeBridgeInterface, options?: CraftBridgeOptions): SharedNativeApp;
|
|
9
|
+
/** The route a host names to run the app script rather than a screen. */
|
|
10
|
+
export declare const NATIVE_APP_ROUTE: '__app';
|
|
8
11
|
declare interface SharedSignalsRuntime {
|
|
9
12
|
hydrateHost: (root: unknown, setup: (() => Record<string, unknown>) | Record<string, unknown> | null, manifest: BindingManifest, nodes: Map<number, unknown>) => (() => void)
|
|
10
13
|
}
|
|
@@ -13,3 +16,21 @@ export declare interface SharedNativeScreen {
|
|
|
13
16
|
mount: (runtime: SharedSignalsRuntime, setup: (() => Record<string, unknown>) | null) => void
|
|
14
17
|
unmount: () => void
|
|
15
18
|
}
|
|
19
|
+
export declare interface SharedNativeApp {
|
|
20
|
+
start: (main: NativeAppMain | { default?: NativeAppMain } | null | undefined) => void
|
|
21
|
+
unmount: () => void
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The app script: one context for the app's whole life, with no screen.
|
|
25
|
+
*
|
|
26
|
+
* What a phone app does whatever is on screen lives here: registering for
|
|
27
|
+
* push and following a tapped notification, background refresh, keeping the
|
|
28
|
+
* account's details fresh for the screens. The host runs it from the same
|
|
29
|
+
* bundle as the screens, under the route `__app` (Craft's `nativeApp`), and
|
|
30
|
+
* it gets the same `craft` bridge a screen does, minus drawing. The host's
|
|
31
|
+
* app events - a notification tapped or received, a silent push, a
|
|
32
|
+
* background refresh - arrive as the page's CustomEvents on its global
|
|
33
|
+
* (`craftNotificationResponse`, `craftBackgroundRefresh`, ...), so code
|
|
34
|
+
* shared with the page (`@stacksjs/mobile`) hears them unchanged.
|
|
35
|
+
*/
|
|
36
|
+
export type NativeAppMain = (craft: Record<string, any>) => void | (() => void) | Promise<void | (() => void)>;
|