@stacksjs/stx 0.2.567 → 0.2.571
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-01mxer9s.js +2 -0
- package/dist/chunk-09gtbb1w.js +2 -0
- package/dist/{chunk-8cpqy9ea.js → chunk-0bt0fbs1.js} +61 -61
- package/dist/{chunk-z06npyzn.js → chunk-0dz1b6a1.js} +3 -3
- package/dist/{chunk-203rr1c8.js → chunk-0g2ybnht.js} +2 -2
- package/dist/{chunk-wsdn5fxe.js → chunk-0q6n3by0.js} +3 -3
- package/dist/chunk-15erabm6.js +2 -0
- package/dist/chunk-194qgkc9.js +2 -0
- package/dist/{chunk-wy4hfmjs.js → chunk-1dg5qxg9.js} +5 -5
- package/dist/{chunk-rgage0vm.js → chunk-1edvsndv.js} +2 -2
- package/dist/{chunk-g1epk002.js → chunk-1n64749x.js} +3 -3
- package/dist/chunk-1z6c6dyk.js +2 -0
- package/dist/{chunk-36aj0yzt.js → chunk-232jswfm.js} +1 -1
- package/dist/chunk-279jv0yf.js +2 -0
- package/dist/chunk-2a1q5y6r.js +2 -0
- package/dist/{chunk-xfpfs9zq.js → chunk-2ads8rw5.js} +2 -2
- package/dist/chunk-2cqbyb8w.js +2 -0
- package/dist/{chunk-9ya4tdpz.js → chunk-2crxkm7j.js} +3 -3
- package/dist/{chunk-6sf4v894.js → chunk-2jjff8kv.js} +5 -5
- package/dist/chunk-2jsnrfc8.js +2 -0
- package/dist/{chunk-ffxwsa94.js → chunk-2z0trbbm.js} +2 -2
- package/dist/{chunk-mt8sew7a.js → chunk-36agnyhe.js} +10 -10
- package/dist/chunk-3gft8zng.js +2 -0
- package/dist/chunk-49gwmcrn.js +2 -0
- package/dist/{chunk-5grx48s2.js → chunk-4bgfpkwx.js} +3 -3
- package/dist/{chunk-tsmbstj6.js → chunk-4easd8da.js} +11 -11
- package/dist/chunk-4ssg5xpq.js +64 -0
- package/dist/chunk-4wfr074d.js +2 -0
- package/dist/{chunk-cbyh8fhn.js → chunk-58tz7tmf.js} +3 -3
- package/dist/chunk-5afw7z6v.js +2 -0
- package/dist/{chunk-7wyyjdks.js → chunk-5dmkkvs7.js} +2 -2
- package/dist/chunk-5fv4g4et.js +2 -0
- package/dist/{chunk-g8tx0yf8.js → chunk-5t1whxxt.js} +6 -6
- package/dist/{chunk-39tkfkp7.js → chunk-5vw8493b.js} +3 -3
- package/dist/chunk-604rs9sq.js +2 -0
- package/dist/chunk-636sfxyj.js +2 -0
- package/dist/chunk-6aq3sm83.js +2 -0
- package/dist/chunk-6f4qrd0s.js +2 -0
- package/dist/chunk-6va5pe2m.js +2 -0
- package/dist/{chunk-tfeenp4h.js → chunk-6wc2t6cd.js} +96 -79
- package/dist/{chunk-gjx5256r.js → chunk-707n4pbz.js} +5 -5
- package/dist/{chunk-5s555c1r.js → chunk-74xwzxwz.js} +3 -3
- package/dist/{chunk-01s01ten.js → chunk-79vdkvhf.js} +5 -5
- package/dist/{chunk-8nr1kras.js → chunk-7bwkeake.js} +6 -6
- package/dist/chunk-7kh4p06d.js +2 -0
- package/dist/{chunk-8cs45k3f.js → chunk-7t3ykgsm.js} +2 -2
- package/dist/chunk-7xrrzqh7.js +2 -0
- package/dist/{chunk-mb59b499.js → chunk-83fdt4yj.js} +6 -6
- package/dist/chunk-8jaw6exk.js +2 -0
- package/dist/chunk-8k61b4ae.js +2 -0
- package/dist/{chunk-tc01jkfc.js → chunk-9k7bq97t.js} +1 -1
- package/dist/chunk-9yar9rfq.js +2 -0
- package/dist/{chunk-jbmhdyzz.js → chunk-a6jq7hex.js} +3 -3
- package/dist/{chunk-7ze47qgv.js → chunk-anjm087t.js} +5 -5
- package/dist/chunk-asbq9cgs.js +2 -0
- package/dist/chunk-b2q8bk8p.js +3 -0
- package/dist/chunk-b7t8jejd.js +2 -0
- package/dist/chunk-b894fxfc.js +2 -0
- package/dist/{chunk-wwn9dh6p.js → chunk-b9r88ysg.js} +2 -2
- package/dist/{chunk-fpa1nq88.js → chunk-beqkrwt1.js} +2 -2
- package/dist/chunk-bm2q1srp.js +2 -0
- package/dist/{chunk-6vnnx536.js → chunk-bpdsdbvg.js} +2 -2
- package/dist/{chunk-2ernwctg.js → chunk-c4zpzxex.js} +6 -6
- package/dist/chunk-cgwyd9aq.js +2 -0
- package/dist/chunk-cvswrbzw.js +2 -0
- package/dist/{chunk-n6va14bt.js → chunk-cyg9w31a.js} +2 -2
- package/dist/chunk-d8206zbp.js +2 -0
- package/dist/chunk-dcpf6kas.js +15 -0
- package/dist/chunk-ensp20xk.js +2 -0
- package/dist/chunk-f10299sf.js +2 -0
- package/dist/chunk-f1apaqfk.js +2 -0
- package/dist/chunk-f4jh9vrj.js +2834 -0
- package/dist/{chunk-3hkv4e7t.js → chunk-g66m3g2r.js} +1 -1
- package/dist/chunk-g6zeqvvb.js +2 -0
- package/dist/chunk-ghy82tsc.js +2 -0
- package/dist/{chunk-c765y72x.js → chunk-gzgc8zk5.js} +4 -4
- package/dist/{chunk-9tcvkbb5.js → chunk-h4k3hyny.js} +2 -2
- package/dist/chunk-jqefcghh.js +31 -0
- package/dist/chunk-jw33eys8.js +2 -0
- package/dist/chunk-jwvzvapp.js +11 -0
- package/dist/{chunk-b76jbdtk.js → chunk-jze68d0z.js} +2 -2
- package/dist/chunk-k6wgh598.js +2 -0
- package/dist/{chunk-7m0r2qs2.js → chunk-k7ht6tqe.js} +2 -2
- package/dist/{chunk-q94wdmdp.js → chunk-kgj852hx.js} +4 -4
- package/dist/{chunk-325p135t.js → chunk-kzjrgh0b.js} +10 -10
- package/dist/chunk-m2a1fxpb.js +2 -0
- package/dist/chunk-m6mxqepz.js +2 -0
- package/dist/chunk-mbmbaj0m.js +2 -0
- package/dist/{chunk-kch9a9v1.js → chunk-mr9c2ej6.js} +2 -2
- package/dist/chunk-mzqyv7s5.js +33 -0
- package/dist/chunk-n61v7e3s.js +2 -0
- package/dist/chunk-n6qp05t9.js +2 -0
- package/dist/chunk-nn174xjh.js +2 -0
- package/dist/chunk-ntgy4e1q.js +2 -0
- package/dist/chunk-nw4axkpx.js +2 -0
- package/dist/chunk-p5chk3s9.js +2 -0
- package/dist/{chunk-ev3qnr9q.js → chunk-phzs239m.js} +4 -4
- package/dist/{chunk-8afnq4qx.js → chunk-pnag11c4.js} +3 -3
- package/dist/{chunk-ss78553t.js → chunk-pqcvh9pp.js} +1 -1
- package/dist/{chunk-k2dgwy05.js → chunk-pveafhzg.js} +2 -2
- package/dist/chunk-pw9verqx.js +2 -0
- package/dist/{chunk-68b64sj4.js → chunk-q79kmad5.js} +1 -1
- package/dist/chunk-q83w8edy.js +3 -0
- package/dist/{chunk-s1xxkzc9.js → chunk-qcymqscj.js} +5 -5
- package/dist/{chunk-saf7kypg.js → chunk-qt3x1sh3.js} +3 -3
- package/dist/chunk-qx6tr8mr.js +2 -0
- package/dist/{chunk-55hfvmvv.js → chunk-qzbzn1yf.js} +23 -23
- package/dist/{chunk-f46a7pvn.js → chunk-r4w1cye7.js} +2 -2
- package/dist/{chunk-ghnkphy4.js → chunk-rfnr4xz6.js} +2 -2
- package/dist/{chunk-8txqk9nq.js → chunk-rrj5m9xv.js} +2 -2
- package/dist/{chunk-d4ybwtqt.js → chunk-s12b57m9.js} +2 -2
- package/dist/chunk-s6sf70ty.js +2 -0
- package/dist/{chunk-1hrj0t0j.js → chunk-sfwprq8q.js} +10 -10
- package/dist/chunk-ta8bhz27.js +2 -0
- package/dist/chunk-tc5r2vmw.js +2 -0
- package/dist/chunk-ts80ktq7.js +2 -0
- package/dist/{chunk-dmf1jmge.js → chunk-tv784gv0.js} +4 -4
- package/dist/{chunk-4zb2ga7p.js → chunk-vp31ff54.js} +2 -2
- package/dist/{chunk-125rc958.js → chunk-vr36s2en.js} +2 -2
- package/dist/chunk-vyg8bvkt.js +2 -0
- package/dist/{chunk-m6m19hwd.js → chunk-wwhxgvr8.js} +4 -4
- package/dist/{chunk-pzasxhwz.js → chunk-xckzvbvn.js} +1 -1
- package/dist/chunk-xq2ck69k.js +2 -0
- package/dist/chunk-y4ajd836.js +2 -0
- package/dist/{chunk-m8qgr307.js → chunk-ydx3mfpp.js} +7 -7
- package/dist/{chunk-n1xcmhjw.js → chunk-yk3wh2xv.js} +3 -3
- package/dist/{chunk-18270qgd.js → chunk-ymawe0y5.js} +2 -2
- package/dist/{chunk-jra9r8fq.js → chunk-zd01r00t.js} +1 -1
- package/dist/chunk-zddzjd60.js +2 -0
- package/dist/chunk-zgxj1q7w.js +2 -0
- package/dist/chunk-zs7qhh40.js +2 -0
- package/dist/{chunk-wm11csdm.js → chunk-zyk12484.js} +2 -2
- package/dist/cli.js +20 -20
- package/dist/client/signals-helpers-runtime.d.ts +1 -1
- package/dist/client/signals-helpers-runtime.js +1 -8
- package/dist/client/signals-notify-runtime.d.ts +2 -0
- package/dist/client/signals-notify-runtime.js +26 -0
- package/dist/client/signals-process-element-runtime.js +8 -4
- package/dist/client/signals-reactive-core-bootstrap-runtime.js +2 -0
- package/dist/client/signals-state-runtime.d.ts +1 -1
- package/dist/client/signals-state-runtime.js +12 -18
- package/dist/client-script-bundler.js +1 -1
- package/dist/composable-loader.js +3 -2
- package/dist/config.d.ts +16 -0
- package/dist/config.js +12 -3
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/env.d.ts +16 -0
- package/dist/env.js +12 -0
- package/dist/native/compiler/bundle.d.ts +2 -0
- package/dist/native/compiler/bundle.js +40 -11
- package/dist/process.js +3 -3
- package/dist/pwa.js +3 -3
- package/dist/reactive-tracking.d.ts +17 -0
- package/dist/reactive-tracking.js +23 -0
- package/dist/reactivity.js +3 -11
- package/dist/signals-api.js +13 -11
- package/dist/signals-notify-runtime.d.ts +2 -0
- package/dist/ssg.js +8 -8
- package/dist/store-loader.js +4 -3
- package/package.json +5 -5
- package/dist/chunk-04qvjcsr.js +0 -2
- package/dist/chunk-2xbrrc5a.js +0 -2
- package/dist/chunk-2yypassp.js +0 -2
- package/dist/chunk-375skn32.js +0 -2
- package/dist/chunk-3wyxe996.js +0 -2
- package/dist/chunk-4mmdpb46.js +0 -2
- package/dist/chunk-4q5d5r7s.js +0 -2
- package/dist/chunk-5ytg0wbc.js +0 -2
- package/dist/chunk-6qyters0.js +0 -2
- package/dist/chunk-6yn90mq9.js +0 -2
- package/dist/chunk-7d2vyre0.js +0 -2
- package/dist/chunk-7pewegtw.js +0 -2
- package/dist/chunk-7w0qa3n0.js +0 -2
- package/dist/chunk-8d788kvt.js +0 -2
- package/dist/chunk-90qywh24.js +0 -31
- package/dist/chunk-bdhtq3vs.js +0 -2
- package/dist/chunk-brnapchc.js +0 -2
- package/dist/chunk-c78327kx.js +0 -2
- package/dist/chunk-d19w3e4x.js +0 -2
- package/dist/chunk-d1mqedk0.js +0 -33
- package/dist/chunk-da649d3k.js +0 -2
- package/dist/chunk-da9avgd9.js +0 -2
- package/dist/chunk-dkyjw3hc.js +0 -3
- package/dist/chunk-e3njkecx.js +0 -2
- package/dist/chunk-efzc1nw8.js +0 -2
- package/dist/chunk-fm4w1r9e.js +0 -2
- package/dist/chunk-gan95hj0.js +0 -2
- package/dist/chunk-hg7amzgz.js +0 -2
- package/dist/chunk-hmk7z0z6.js +0 -2
- package/dist/chunk-hn105xy3.js +0 -2
- package/dist/chunk-jq079mrx.js +0 -2
- package/dist/chunk-jr149mmp.js +0 -2
- package/dist/chunk-k50k9zbw.js +0 -2
- package/dist/chunk-kwxy0e3r.js +0 -2
- package/dist/chunk-kza3nxr0.js +0 -2
- package/dist/chunk-m9cmc6np.js +0 -2
- package/dist/chunk-m9r4x7e6.js +0 -2
- package/dist/chunk-mahv855w.js +0 -2
- package/dist/chunk-mbwdn96z.js +0 -2
- package/dist/chunk-mdxg95mq.js +0 -2
- package/dist/chunk-mm1vvk49.js +0 -15
- package/dist/chunk-mqje968d.js +0 -2
- package/dist/chunk-n2g9mj2h.js +0 -2
- package/dist/chunk-n2nha538.js +0 -2
- package/dist/chunk-nebw444s.js +0 -2
- package/dist/chunk-ngcjy2dj.js +0 -63
- package/dist/chunk-nm0y4qjg.js +0 -11
- package/dist/chunk-nmt7kw0e.js +0 -2
- package/dist/chunk-pq8mz4ma.js +0 -2
- package/dist/chunk-pxcmv1xz.js +0 -2
- package/dist/chunk-pxes1ft6.js +0 -2
- package/dist/chunk-qajc13zq.js +0 -2
- package/dist/chunk-qtnqmw1n.js +0 -2
- package/dist/chunk-r3zdgeah.js +0 -2
- package/dist/chunk-r5htacg5.js +0 -2
- package/dist/chunk-rf2rwddd.js +0 -2
- package/dist/chunk-s833fbvf.js +0 -2
- package/dist/chunk-sgvszh9s.js +0 -2
- package/dist/chunk-t5r3s1wj.js +0 -2
- package/dist/chunk-tjprg6kq.js +0 -2
- package/dist/chunk-v0dzrwg8.js +0 -2
- package/dist/chunk-vtz9empe.js +0 -2
- package/dist/chunk-wa6nzq5b.js +0 -2
- package/dist/chunk-xw8kzm6b.js +0 -2834
- package/dist/chunk-ymdy7b8z.js +0 -3
- package/dist/chunk-ytdzgctp.js +0 -2
- package/dist/chunk-z2n1rtj5.js +0 -2
|
@@ -607,8 +607,12 @@ else if (name === 'ref' || name === ':ref' || name === 'x-ref' || name === 'data
|
|
|
607
607
|
var shorthandFn = parseEventShorthand(value, eventCapturedScope);
|
|
608
608
|
if (shorthandFn) { shorthandFn(handlerEvent); return; }
|
|
609
609
|
// Check if any scope values are signals (x-data pattern)
|
|
610
|
+
// A derived value reads like a signal in a handler, as it does in a
|
|
611
|
+
// binding: \`pick(selectedPackage)\` passes the package. Leaving it
|
|
612
|
+
// out handed the handler the derived's getter function, so
|
|
613
|
+
// \`selectedPackage.trainer_id\` was undefined with nothing said.
|
|
610
614
|
var hasSignals = Object.values(eventCapturedScope).some(function(v) {
|
|
611
|
-
return v && typeof v === 'function' && v._isSignal;
|
|
615
|
+
return v && typeof v === 'function' && (v._isSignal || v._isDerived);
|
|
612
616
|
});
|
|
613
617
|
// Only use signal read/write proxy for DIRECT assignment expressions
|
|
614
618
|
// like "count = count + 1" or "open = !open". Function calls like
|
|
@@ -617,7 +621,7 @@ else if (name === 'ref' || name === ':ref' || name === 'x-ref' || name === 'data
|
|
|
617
621
|
var isDirectAssignment = hasSignals && /^[a-zA-Z_$]\\w*\\s*=/.test(value.trim()) && !value.trim().startsWith('==');
|
|
618
622
|
if (isDirectAssignment) {
|
|
619
623
|
var getVars = Object.keys(eventCapturedScope).map(function(k) {
|
|
620
|
-
return 'var ' + k + ' = __s["' + k + '"] && typeof __s["' + k + '"] === "function" && __s["' + k + '"]._isSignal ? __s["' + k + '"]() : __s["' + k + '"]';
|
|
624
|
+
return 'var ' + k + ' = __s["' + k + '"] && typeof __s["' + k + '"] === "function" && (__s["' + k + '"]._isSignal || __s["' + k + '"]._isDerived) ? __s["' + k + '"]() : __s["' + k + '"]';
|
|
621
625
|
}).join(';');
|
|
622
626
|
var setVars = Object.keys(eventCapturedScope).filter(function(k) {
|
|
623
627
|
var v = eventCapturedScope[k];
|
|
@@ -643,11 +647,11 @@ else if (name === 'ref' || name === ':ref' || name === 'x-ref' || name === 'data
|
|
|
643
647
|
// handler like \`pick(option.value)\` receives the whole item.
|
|
644
648
|
// It is not an error, so it lands silently: the wrong value is
|
|
645
649
|
// stored and only surfaces much later.
|
|
646
|
-
if (v && typeof v === 'function' && v._isSignal && !v._isStxLoopItem
|
|
650
|
+
if (v && typeof v === 'function' && ((v._isSignal && !v._isStxLoopItem) || v._isDerived)
|
|
647
651
|
&& (expressionCallsSignal(value, k) || expressionUsesSignalApi(value, k))) {
|
|
648
652
|
return 'var ' + k + ' = __s["' + k + '"]';
|
|
649
653
|
}
|
|
650
|
-
return 'var ' + k + ' = __s["' + k + '"] && typeof __s["' + k + '"] === "function" && __s["' + k + '"]._isSignal ? __s["' + k + '"]() : __s["' + k + '"]';
|
|
654
|
+
return 'var ' + k + ' = __s["' + k + '"] && typeof __s["' + k + '"] === "function" && (__s["' + k + '"]._isSignal || __s["' + k + '"]._isDerived) ? __s["' + k + '"]() : __s["' + k + '"]';
|
|
651
655
|
}).join(';');
|
|
652
656
|
var fn3 = __stxCompile(['__s', '$event'], unwrapVars + ';' + value);
|
|
653
657
|
fn3(eventCapturedScope, handlerEvent);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SIGNALS_NOTIFY_RUNTIME } from "./signals-notify-runtime.js";
|
|
1
2
|
export function signalsReactiveCoreBootstrapRuntime(cloakRuntime, expressionCompilerRuntime, fetchTransportRuntime) {
|
|
2
3
|
return `${cloakRuntime} // ==========================================================================
|
|
3
4
|
// Reactive Core
|
|
@@ -8,6 +9,7 @@ ${expressionCompilerRuntime}
|
|
|
8
9
|
const effectStack = [];
|
|
9
10
|
const pendingEffects = new Set();
|
|
10
11
|
let isBatching = false;
|
|
12
|
+
${SIGNALS_NOTIFY_RUNTIME}
|
|
11
13
|
|
|
12
14
|
// DevTools Phase 2 (#1747): dev-mode reactivity instrumentation. OFF by
|
|
13
15
|
// default \u2014 even in the dev runtime \u2014 so set()/effect-run stay zero-overhead
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** State and derived primitives embedded in the browser signals runtime. */
|
|
2
|
-
export declare const SIGNALS_STATE_RUNTIME = " // ==========================================================================\n // State Signal\n // ==========================================================================\n\n function state(initialValue) {\n let value = initialValue;\n const subscribers = new Set();\n const effects = new Set();\n\n const signal = () => {\n if (activeEffect) {\n effects.add(activeEffect);\n }\n return value;\n };\n\n signal.set = (newValue) => {\n console.log('[stx] signal.set:', value, '->', newValue, 'effects:', effects.size);\n if (!Object.is(newValue, value)) {\n if (__stxDevtoolsTracking) {\n signal._setCount++;\n __stxDevtoolsStats.signalSets++;\n __stxDevtoolsMutations.push({ sid: signal._stxSignalId, prev: __stxShort(value), next: __stxShort(newValue) });\n if (__stxDevtoolsMutations.length > 100) __stxDevtoolsMutations.shift();\n }\n const prev = value;\n value = newValue;\n subscribers.forEach(cb => {\n try { cb(value, prev); }\n catch (e) { console.error('[stx] subscriber error:', e); }\n });\n
|
|
2
|
+
export declare const SIGNALS_STATE_RUNTIME = " // ==========================================================================\n // State Signal\n // ==========================================================================\n\n function state(initialValue) {\n let value = initialValue;\n const subscribers = new Set();\n const effects = new Set();\n\n const signal = () => {\n if (activeEffect) {\n effects.add(activeEffect);\n }\n return value;\n };\n\n signal.set = (newValue) => {\n console.log('[stx] signal.set:', value, '->', newValue, 'effects:', effects.size);\n if (!Object.is(newValue, value)) {\n if (__stxDevtoolsTracking) {\n signal._setCount++;\n __stxDevtoolsStats.signalSets++;\n __stxDevtoolsMutations.push({ sid: signal._stxSignalId, prev: __stxShort(value), next: __stxShort(newValue) });\n if (__stxDevtoolsMutations.length > 100) __stxDevtoolsMutations.shift();\n }\n const prev = value;\n value = newValue;\n subscribers.forEach(cb => {\n try { cb(value, prev); }\n catch (e) { console.error('[stx] subscriber error:', e); }\n });\n notifySubscribers(effects);\n }\n };\n\n signal.update = (fn) => signal.set(fn(value));\n // Notify as if the value changed, for an array or object mutated in place.\n // set() cannot do it: the value is the same reference, so Object.is skips.\n signal.trigger = () => {\n subscribers.forEach(cb => {\n try { cb(value, value); }\n catch (e) { console.error('[stx] subscriber error:', e); }\n });\n notifySubscribers(effects);\n };\n signal.subscribe = (cb) => {\n subscribers.add(cb);\n return () => subscribers.delete(cb);\n };\n signal._isSignal = true;\n signal._effects = effects; // DevTools: the subscriber set (reactive graph)\n signal._setCount = 0; // DevTools: times set() changed the value (when tracking)\n signal._stxSignalId = ++__stxSignalId; // DevTools: stable id for the mutation log\n\n // Vue-compatible .value getter/setter for templates that use signal.value syntax\n Object.defineProperty(signal, 'value', {\n get() { return signal(); },\n set(v) { signal.set(v); },\n configurable: true\n });\n\n return signal;\n }\n\n // ==========================================================================\n // Derived Signal\n // ==========================================================================\n\n function derived(compute) {\n let cached;\n let isDirty = true;\n const effects = new Set();\n\n // Passes a change on to what read this value. A signal's notification\n // collects through it (_stxCollect) instead of calling it, so an effect\n // reached both directly and through here still runs once.\n const markDirty = () => {\n if (!isDirty) {\n isDirty = true;\n notifySubscribers(effects);\n }\n };\n markDirty._stxCollect = (into) => {\n if (!isDirty) {\n isDirty = true;\n collectSubscribers(effects, into);\n }\n };\n\n const signal = () => {\n if (activeEffect) effects.add(activeEffect);\n if (isDirty) {\n const prev = activeEffect;\n activeEffect = markDirty;\n effectStack.push(markDirty);\n try {\n cached = compute();\n }\nfinally {\n effectStack.pop();\n activeEffect = prev;\n }\n isDirty = false;\n }\n return cached;\n };\n\n signal._isDerived = true;\n signal._effects = effects; // DevTools: the subscriber set (reactive graph)\n\n // Vue-compatible .value getter for templates that use computed.value syntax\n Object.defineProperty(signal, 'value', {\n get() { return signal(); },\n configurable: true\n });\n\n return signal;\n }\n";
|
|
@@ -29,12 +29,7 @@ export const SIGNALS_STATE_RUNTIME = ` // =====================================
|
|
|
29
29
|
try { cb(value, prev); }
|
|
30
30
|
catch (e) { console.error('[stx] subscriber error:', e); }
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
effects.forEach(effect => pendingEffects.add(effect));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
effects.forEach(effect => effect());
|
|
37
|
-
}
|
|
32
|
+
notifySubscribers(effects);
|
|
38
33
|
}
|
|
39
34
|
};
|
|
40
35
|
|
|
@@ -46,12 +41,7 @@ else {
|
|
|
46
41
|
try { cb(value, value); }
|
|
47
42
|
catch (e) { console.error('[stx] subscriber error:', e); }
|
|
48
43
|
});
|
|
49
|
-
|
|
50
|
-
effects.forEach(effect => pendingEffects.add(effect));
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
effects.forEach(effect => effect());
|
|
54
|
-
}
|
|
44
|
+
notifySubscribers(effects);
|
|
55
45
|
};
|
|
56
46
|
signal.subscribe = (cb) => {
|
|
57
47
|
subscribers.add(cb);
|
|
@@ -81,15 +71,19 @@ else {
|
|
|
81
71
|
let isDirty = true;
|
|
82
72
|
const effects = new Set();
|
|
83
73
|
|
|
74
|
+
// Passes a change on to what read this value. A signal's notification
|
|
75
|
+
// collects through it (_stxCollect) instead of calling it, so an effect
|
|
76
|
+
// reached both directly and through here still runs once.
|
|
84
77
|
const markDirty = () => {
|
|
85
78
|
if (!isDirty) {
|
|
86
79
|
isDirty = true;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
notifySubscribers(effects);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
markDirty._stxCollect = (into) => {
|
|
84
|
+
if (!isDirty) {
|
|
85
|
+
isDirty = true;
|
|
86
|
+
collectSubscribers(effects, into);
|
|
93
87
|
}
|
|
94
88
|
};
|
|
95
89
|
|
|
@@ -291,7 +291,7 @@ export function queueClientBundleBuild(task) {
|
|
|
291
291
|
}
|
|
292
292
|
export async function bundleClientScript(code, filePath, options = {}) {
|
|
293
293
|
const projectRoot = options.projectRoot || process.cwd(), serverApi = (await loadStxConfig(projectRoot)).serverApi, minify = options.minify ?? !1, externalizeUserModules = options.externalizeUserModules ?? !0, expose = options.expose?.length ? [...new Set(options.expose)].sort() : void 0, cacheDir = options.cacheDir || stateDir(projectRoot, "bundle-cache"), hasher = new Bun.CryptoHasher("md5");
|
|
294
|
-
hasher.update(`${BUNDLE_CACHE_VERSION}\x00${cacheEngineFingerprint()}\x00${JSON.stringify(serverApi ?? !1)}\x00${externalizeUserModules ? "registry" : "inline"}\x00${expose ? expose.join(",") : "*"}\x00${code}\x00${filePath}`);
|
|
294
|
+
hasher.update(`${BUNDLE_CACHE_VERSION}\x00${cacheEngineFingerprint()}\x00${JSON.stringify(serverApi ?? !1)}\x00${externalizeUserModules ? "registry" : "inline"}\x00${expose ? expose.join(",") : "*"}\x00${minify ? "minified" : "readable"}\x00${code}\x00${filePath}`);
|
|
295
295
|
const hash = hasher.digest("hex").slice(0, 12), cachePath = path.join(cacheDir, `${hash}.js`), remembered = bundleMemo.get(cachePath);
|
|
296
296
|
if (remembered) {
|
|
297
297
|
if (depsUnchanged(remembered.files) && remembered.files.every((dep) => !isPrivateClientSource(dep.path, projectRoot, serverApi))) {
|
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { unboundNames } from "./client-parameter-bindings.js";
|
|
3
3
|
import { bundleClientScript, clientBundleDependencies, hasUserImports } from "./client-script-bundler.js";
|
|
4
4
|
import { loadStxConfig } from "./config.js";
|
|
5
|
+
import { isProduction, minifyClassicScript } from "./env.js";
|
|
5
6
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
6
7
|
import { contentKey, renderMemo } from "./render-memo.js";
|
|
7
8
|
import { clearSourceSignatures, readSigned, sourceSignature, writeSigned } from "./source-signature.js";
|
|
@@ -213,7 +214,7 @@ ${code.trim()}`);
|
|
|
213
214
|
`), globalNames = JSON.stringify([...exportedNames]), joinedChunks = chunks.join(`
|
|
214
215
|
|
|
215
216
|
`), runtimeBindings = STX_RUNTIME_GLOBALS.filter((name) => !declaredNames.has(name) && new RegExp(`\\b${name}\\b`).test(joinedChunks)).map((name) => `var ${name} = __stx[${JSON.stringify(name)}];`).join(`
|
|
216
|
-
`), bundleKey = JSON.stringify(new Bun.CryptoHasher("md5").update(`${globalNames}\x00${joinedChunks}`).digest("hex").slice(0, 12)),
|
|
217
|
+
`), bundleKey = JSON.stringify(new Bun.CryptoHasher("md5").update(`${globalNames}\x00${joinedChunks}`).digest("hex").slice(0, 12)), assembled = `;(function(){
|
|
217
218
|
var __bundles = window.__stxComposableBundles || (window.__stxComposableBundles = {});
|
|
218
219
|
if (__bundles[${bundleKey}]) return;
|
|
219
220
|
__bundles[${bundleKey}] = true;
|
|
@@ -238,7 +239,7 @@ ${assignments}
|
|
|
238
239
|
window[__n] = __c[__n];
|
|
239
240
|
__published[__n] = true;
|
|
240
241
|
}
|
|
241
|
-
})()
|
|
242
|
+
})();`, code = isProduction() ? minifyClassicScript(assembled) : assembled;
|
|
242
243
|
signature = sourceSignature(composableInputs());
|
|
243
244
|
writeSigned(_cachedComposableScripts, cacheKey, signature, code);
|
|
244
245
|
return code;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StxConfig, StxOptions } from './types';
|
|
2
|
+
import { loadConfigWithResult } from 'bunfig';
|
|
2
3
|
export declare const defaultConfig: StxConfig;
|
|
3
4
|
/**
|
|
4
5
|
* Resolve `root`, `pagesDir` and the template directories, in place.
|
|
@@ -28,6 +29,21 @@ export declare const defaultConfig: StxConfig;
|
|
|
28
29
|
* (absolute wins) or use it as the base of a `path.join` (unaffected).
|
|
29
30
|
*/
|
|
30
31
|
export declare function resolveStxDirectories(loaded: StxConfig, cwd: string): StxConfig;
|
|
32
|
+
/**
|
|
33
|
+
* A project's stx config, or the defaults when it has none.
|
|
34
|
+
*
|
|
35
|
+
* bunfig's result API rejects with ConfigNotFoundError when no file exists
|
|
36
|
+
* (its documented contract). Until 0.15.21 its published build never matched
|
|
37
|
+
* that error by name, so the rejection never fired and every project without
|
|
38
|
+
* an stx.config fell back to defaults by accident; with the fix, loading such
|
|
39
|
+
* a project threw. Absence is the normal case here. Matched by name: a
|
|
40
|
+
* bundled copy of bunfig has its own error classes.
|
|
41
|
+
*/
|
|
42
|
+
export declare function discoverConfig<T>(options: Parameters<typeof loadConfigWithResult<T>>[0], load?: (options: Parameters<typeof loadConfigWithResult<T>>[0]) => Promise<{
|
|
43
|
+
config: T;
|
|
44
|
+
}>): Promise<{
|
|
45
|
+
config: T;
|
|
46
|
+
}>;
|
|
31
47
|
/**
|
|
32
48
|
* Load the stx config for a project.
|
|
33
49
|
*
|
package/dist/config.js
CHANGED
|
@@ -457,6 +457,15 @@ function applyStateDir(loaded) {
|
|
|
457
457
|
let _config = null;
|
|
458
458
|
const _cwdConfigCache = new Map, _layerSnapshots = new Map;
|
|
459
459
|
let _configPromise = null;
|
|
460
|
+
export async function discoverConfig(options, load = loadConfigWithResult) {
|
|
461
|
+
try {
|
|
462
|
+
return await load(options);
|
|
463
|
+
} catch (error) {
|
|
464
|
+
if (error instanceof Error && error.name === "ConfigNotFoundError")
|
|
465
|
+
return { config: options.defaultConfig };
|
|
466
|
+
throw error;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
460
469
|
export async function loadStxConfig(cwd) {
|
|
461
470
|
const effectiveCwd = cwd ? path.resolve(cwd) : process.cwd(), snapshot = _layerSnapshots.get(effectiveCwd);
|
|
462
471
|
if (snapshot && snapshot.signature !== layerSignature(snapshot.graph)) {
|
|
@@ -497,13 +506,13 @@ export async function loadStxConfig(cwd) {
|
|
|
497
506
|
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
507
|
let loaded;
|
|
499
508
|
if (hasRootConfig && hasUiConfig) {
|
|
500
|
-
const uiResult = await
|
|
509
|
+
const uiResult = await discoverConfig({
|
|
501
510
|
name: "ui",
|
|
502
511
|
cwd: path.join(effectiveCwd, "config"),
|
|
503
512
|
defaultConfig,
|
|
504
513
|
verbose: !1
|
|
505
514
|
});
|
|
506
|
-
loaded = (await
|
|
515
|
+
loaded = (await discoverConfig({
|
|
507
516
|
name: "stx",
|
|
508
517
|
alias: "ui",
|
|
509
518
|
cwd: effectiveCwd,
|
|
@@ -511,7 +520,7 @@ export async function loadStxConfig(cwd) {
|
|
|
511
520
|
verbose: !1
|
|
512
521
|
})).config;
|
|
513
522
|
} else
|
|
514
|
-
loaded = (await
|
|
523
|
+
loaded = (await discoverConfig({
|
|
515
524
|
name: "stx",
|
|
516
525
|
alias: "ui",
|
|
517
526
|
cwd: effectiveCwd,
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Gr,No,Lo}from"./chunk-0q6n3by0.js";import"./chunk-ydx3mfpp.js";import"./chunk-vp31ff54.js";import"./chunk-phzs239m.js";import"./chunk-k7ht6tqe.js";import"./chunk-s12b57m9.js";import"./chunk-f4jh9vrj.js";import"./chunk-sfwprq8q.js";import"./chunk-36agnyhe.js";import"./chunk-rfnr4xz6.js";import"./chunk-rrj5m9xv.js";import"./chunk-1edvsndv.js";import"./chunk-tv784gv0.js";import"./chunk-qt3x1sh3.js";import{Td,Ro,$d,Rd,Ao,qr,Po,Ad,Io,Pd,Id,Oo,Do,Mo}from"./chunk-qzbzn1yf.js";import"./chunk-gzgc8zk5.js";import"./chunk-pnag11c4.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{Td as CRAFT_BRIDGE_SCRIPT,qr as CRAFT_COMPONENTS,Ad as CRAFT_COMPONENT_RUNTIME,Po as CRAFT_COMPONENT_STYLES,Gr as NATIVE_COMPONENTS,Oo as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,No as compileToNative,Lo as createHotReloadServer,Ro as generateCraftBridgeScript,V as generateCraftOptimizations,Mo as getAvailableFormats,Do as getAvailableTargets,Id as getCraftComponents,G as getSSRCacheStats,Ao as injectCraftBridge,$d as isCraftEnvironment,Y as prerenderForCraft,Io as processCraftComponents,Rd as processCraftDirective,Pd as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Gr,No,Lo}from"./chunk-0q6n3by0.js";import"./chunk-ydx3mfpp.js";import"./chunk-vp31ff54.js";import"./chunk-phzs239m.js";import"./chunk-k7ht6tqe.js";import"./chunk-s12b57m9.js";import"./chunk-f4jh9vrj.js";import"./chunk-sfwprq8q.js";import"./chunk-36agnyhe.js";import"./chunk-rfnr4xz6.js";import"./chunk-rrj5m9xv.js";import"./chunk-1edvsndv.js";import"./chunk-tv784gv0.js";import"./chunk-qt3x1sh3.js";import{Td,Ro,$d,Rd,Ao,qr,Po,Ad,Io,Pd,Id,Oo,Do,Mo}from"./chunk-qzbzn1yf.js";import"./chunk-gzgc8zk5.js";import"./chunk-pnag11c4.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{Td as CRAFT_BRIDGE_SCRIPT,qr as CRAFT_COMPONENTS,Ad as CRAFT_COMPONENT_RUNTIME,Po as CRAFT_COMPONENT_STYLES,Gr as NATIVE_COMPONENTS,Oo as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,No as compileToNative,Lo as createHotReloadServer,Ro as generateCraftBridgeScript,V as generateCraftOptimizations,Mo as getAvailableFormats,Do as getAvailableTargets,Id as getCraftComponents,G as getSSRCacheStats,Ao as injectCraftBridge,$d as isCraftEnvironment,Y as prerenderForCraft,Io as processCraftComponents,Rd as processCraftDirective,Pd as registerCraftComponent,Q as renderSSR};
|
package/dist/env.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
export declare function isProduction(): boolean;
|
|
2
2
|
export declare function isDevelopment(): boolean;
|
|
3
3
|
export declare function isTest(): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Whether the client code a render produces ships minified: a static build
|
|
6
|
+
* (`compile`), and every production render. A Stacks app renders production
|
|
7
|
+
* pages in `serve` mode under NODE_ENV=production, and gating minification
|
|
8
|
+
* on `compile` alone sent production its stores, composables and module
|
|
9
|
+
* registry readable (hq.training's home page: a 2.9 MB store bundle of
|
|
10
|
+
* 61,843 lines, comments included).
|
|
11
|
+
*/
|
|
12
|
+
export declare function minifiesClientCode(buildMode?: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* A classic script minified by Bun: whitespace and comments gone. Its
|
|
15
|
+
* top-level names can be the page's globals, so identifiers keep their
|
|
16
|
+
* names (Bun renames bundled modules' locals already). Readable code is
|
|
17
|
+
* still correct, so a script Bun cannot parse ships as it is.
|
|
18
|
+
*/
|
|
19
|
+
export declare function minifyClassicScript(code: string): string;
|
package/dist/env.js
CHANGED
|
@@ -10,3 +10,15 @@ export function isTest() {
|
|
|
10
10
|
const { NODE_ENV } = process.env;
|
|
11
11
|
return NODE_ENV === "test";
|
|
12
12
|
}
|
|
13
|
+
export function minifiesClientCode(buildMode) {
|
|
14
|
+
return buildMode === "compile" || isProduction();
|
|
15
|
+
}
|
|
16
|
+
export function minifyClassicScript(code) {
|
|
17
|
+
if (!code)
|
|
18
|
+
return code;
|
|
19
|
+
try {
|
|
20
|
+
return new Bun.Transpiler({ loader: "js", minifyWhitespace: !0 }).transformSync(code).trim();
|
|
21
|
+
} catch {
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -30,6 +30,7 @@ export declare interface CompileNativeBundleOptions {
|
|
|
30
30
|
root?: string
|
|
31
31
|
app?: string
|
|
32
32
|
browser?: BrowserScreenOptions & { platformModule: string, platformOptions?: Record<string, unknown> }
|
|
33
|
+
routesDir?: string
|
|
33
34
|
}
|
|
34
35
|
/** Something the compiler could not translate exactly: an unknown icon or class. */
|
|
35
36
|
export declare interface NativeDiagnostic {
|
|
@@ -40,6 +41,7 @@ export declare interface NativeBundleResult {
|
|
|
40
41
|
dependencies: string[]
|
|
41
42
|
code: string
|
|
42
43
|
outFile?: string
|
|
44
|
+
routes?: Record<string, string>
|
|
43
45
|
diagnostics: NativeDiagnostic[]
|
|
44
46
|
}
|
|
45
47
|
/** @deprecated Use `CompileNativeBundleOptions`. */
|
|
@@ -35,6 +35,9 @@ ${messages}`);
|
|
|
35
35
|
}
|
|
36
36
|
return (await result.outputs[0].text()).trim();
|
|
37
37
|
}
|
|
38
|
+
function runtimeDocument(document) {
|
|
39
|
+
return { ...document, script: { exports: document.script.exports, functions: [], code: "" } };
|
|
40
|
+
}
|
|
38
41
|
export async function compileNativeBundle(options) {
|
|
39
42
|
const names = Object.keys(options.screens);
|
|
40
43
|
if (names.length === 0)
|
|
@@ -56,14 +59,19 @@ export async function compileNativeBundle(options) {
|
|
|
56
59
|
throw Error("An app script needs a routed bundle");
|
|
57
60
|
if (appFile && options.screens[NATIVE_APP_ROUTE])
|
|
58
61
|
throw Error(`${NATIVE_APP_ROUTE} is the app script's route, not a screen name`);
|
|
59
|
-
const browser = options.browser
|
|
62
|
+
const browser = options.browser;
|
|
63
|
+
if (browser && options.routesDir)
|
|
64
|
+
throw Error("A browser screen is one route; routesDir is for device hosts");
|
|
65
|
+
const entry = (bundled, withApp) => {
|
|
66
|
+
const route = routed ? `var routeName = g.__stxNativeRoute || ${JSON.stringify(initialScreen)};
|
|
60
67
|
var isApp = ${appFile ? `routeName === ${JSON.stringify(NATIVE_APP_ROUTE)}` : "false"};
|
|
61
|
-
if (!isApp && routeNames.indexOf(routeName) === -1) throw new Error(['Unknown native screen:', routeName].join(' '))
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
if (!isApp && routeNames.indexOf(routeName) === -1) throw new Error(['Unknown native screen:', routeName].join(' '));
|
|
69
|
+
if (isApp ? ${!withApp} : ${JSON.stringify(bundled.map(({ name }) => name))}.indexOf(routeName) === -1) throw new Error(['This bundle does not hold the native screen', routeName].join(' '));` : `var routeName = 'main';
|
|
70
|
+
var isApp = false;`, selections = bundled.map(({ name, compiled }, index) => `${index === 0 ? "if" : "else if"} (routeName === ${JSON.stringify(routed ? name : "main")}) {
|
|
71
|
+
nativeDocument = ${JSON.stringify(runtimeDocument(compiled.document))};
|
|
64
72
|
manifest = ${JSON.stringify(compiled.manifest)};
|
|
65
73
|
}`).join(`
|
|
66
|
-
`), setups =
|
|
74
|
+
`), setups = bundled.map(({ name, compiled }, index) => `${index === 0 ? "if" : "else if"} (routeName === ${JSON.stringify(routed ? name : "main")}) {
|
|
67
75
|
g.__stx_latestSetup = null;
|
|
68
76
|
${compiled.scripts.map((script) => script.owner ? ` g.__STX_SETUP_ROOT__ = screen && screen.scopeRoot(${JSON.stringify(script.owner)});
|
|
69
77
|
try {
|
|
@@ -72,12 +80,13 @@ ${script.code}
|
|
|
72
80
|
finally { g.__STX_SETUP_ROOT__ = null; }` : script.code).join(`
|
|
73
81
|
`)}
|
|
74
82
|
}`).join(`
|
|
75
|
-
`), browserRuntime = browser ? nativeRuntimeModule("browser-screen") : null, platformModule = browser ? Bun.resolveSync(browser.platformModule, root) : null
|
|
83
|
+
`), app = withApp && appFile, browserRuntime = browser ? nativeRuntimeModule("browser-screen") : null, platformModule = browser ? Bun.resolveSync(browser.platformModule, root) : null;
|
|
84
|
+
return `
|
|
76
85
|
import { installJSCGlobals } from ${JSON.stringify(runtimeGlobals)};
|
|
77
86
|
import { prepareNativeApp, prepareSharedNativeScreen } from ${JSON.stringify(sharedScreen)};
|
|
78
87
|
${browser ? `import { createBrowserScreenBridge } from ${JSON.stringify(browserRuntime)};
|
|
79
88
|
import { createBrowserPlatform } from ${JSON.stringify(platformModule)};` : ""}
|
|
80
|
-
${
|
|
89
|
+
${app ? `import * as nativeAppModule from ${JSON.stringify(appFile)};` : "var nativeAppModule = null;"}
|
|
81
90
|
${browser ? "(async function() {" : ""}
|
|
82
91
|
var g = globalThis;
|
|
83
92
|
installJSCGlobals(g);
|
|
@@ -113,22 +122,42 @@ var ended = false;
|
|
|
113
122
|
g.__stxNativeUnmount = function() { if (ended) return; ended = true; if (typeof stopApp === 'function') stopApp(); unmount(); browserBridge.dispose(); };
|
|
114
123
|
g.addEventListener('pagehide', function(event) { if (!event.persisted) g.__stxNativeUnmount(); });
|
|
115
124
|
})().catch(function(error) { console.error('[stx browser screen]', error); var node = document.querySelector(${JSON.stringify(browser.container)}); if (node) { node.textContent = 'This screen could not start. Reload to try again.'; node.setAttribute('role', 'alert'); } });` : ""}
|
|
116
|
-
|
|
125
|
+
`;
|
|
126
|
+
}, plugin = (contents) => ({
|
|
117
127
|
name: "stx-native-shared-screens",
|
|
118
128
|
setup(builder) {
|
|
119
129
|
builder.onResolve({ filter: /^stx:native-shared-screens$/ }, () => ({ path: "entry", namespace: "stx-native-shared-screens" }));
|
|
120
130
|
builder.onLoad({ filter: /.*/, namespace: "stx-native-shared-screens" }, () => ({ contents, loader: "js" }));
|
|
121
131
|
}
|
|
122
|
-
}, dependencies = new Set(compiledScreens.flatMap(({ compiled }) => compiled.dependencies)),
|
|
132
|
+
}), dependencies = new Set(compiledScreens.flatMap(({ compiled }) => compiled.dependencies)), diagnostics = compiledScreens.flatMap(({ compiled }) => compiled.diagnostics).map((diagnostic) => ({
|
|
123
133
|
level: "warning",
|
|
124
134
|
message: [diagnostic.kind, diagnostic.tag, diagnostic.name].filter(Boolean).join(": ")
|
|
125
|
-
}));
|
|
135
|
+
})), minify = options.minify ?? !1;
|
|
136
|
+
let routes;
|
|
137
|
+
if (options.routesDir) {
|
|
138
|
+
const dir = path.resolve(root, options.routesDir);
|
|
139
|
+
mkdirSync(dir, { recursive: !0 });
|
|
140
|
+
const targets = [
|
|
141
|
+
...compiledScreens.map((screen) => ({ name: screen.name, screens: [screen], app: !1 })),
|
|
142
|
+
...appFile ? [{ name: NATIVE_APP_ROUTE, screens: [], app: !0 }] : []
|
|
143
|
+
];
|
|
144
|
+
routes = {};
|
|
145
|
+
for (let next = 0;next < targets.length; next += 6)
|
|
146
|
+
await Promise.all(targets.slice(next, next + 6).map(async (target) => {
|
|
147
|
+
const file = path.join(dir, `${target.name}.js`);
|
|
148
|
+
await Bun.write(file, await build("stx:native-shared-screens", [plugin(entry(target.screens, target.app))], minify, dependencies));
|
|
149
|
+
routes[target.name] = file;
|
|
150
|
+
}));
|
|
151
|
+
if (!options.outFile)
|
|
152
|
+
return { code: "", routes, diagnostics, dependencies: [...dependencies] };
|
|
153
|
+
}
|
|
154
|
+
const code = await build("stx:native-shared-screens", [plugin(entry(compiledScreens, !0))], minify, dependencies);
|
|
126
155
|
if (!options.outFile)
|
|
127
156
|
return { code, diagnostics, dependencies: [...dependencies] };
|
|
128
157
|
const outFile = path.resolve(root, options.outFile);
|
|
129
158
|
mkdirSync(path.dirname(outFile), { recursive: !0 });
|
|
130
159
|
await Bun.write(outFile, code);
|
|
131
|
-
return { code, outFile, diagnostics, dependencies: [...dependencies] };
|
|
160
|
+
return { code, outFile, ...routes ? { routes } : {}, diagnostics, dependencies: [...dependencies] };
|
|
132
161
|
}
|
|
133
162
|
export async function compileSharedScreenBundle(file, options = {}) {
|
|
134
163
|
return compileNativeBundle({ ...options, screens: { main: file }, routed: !1 });
|
package/dist/process.js
CHANGED
|
@@ -56,7 +56,7 @@ import { processInlineAssets } from "./inline-assets.js";
|
|
|
56
56
|
import { addCloakToConditionalDirectives, addCloakToUnresolvedExpressions, processJsonDirective, processMemoDirective, processOnceDirective, processRefAttributes } from "./misc-directives.js";
|
|
57
57
|
import { validateClientScript } from "./script-validation.js";
|
|
58
58
|
import { safeEvaluate } from "./safe-evaluator.js";
|
|
59
|
-
import { isProduction, isTest } from "./env.js";
|
|
59
|
+
import { isProduction, isTest, minifiesClientCode } from "./env.js";
|
|
60
60
|
import { warnUnbalancedTags } from "./template-tag-balance.js";
|
|
61
61
|
import { deriveLayoutGroup } from "stx-router/layout-metadata";
|
|
62
62
|
import { initializeComponentClientFactories, injectComponentClientFactories } from "./component-client-factories.js";
|
|
@@ -229,7 +229,7 @@ async function externalBundleTag(attrs, code, options) {
|
|
|
229
229
|
async function buildModulesTag(sources, options, dependencies) {
|
|
230
230
|
try {
|
|
231
231
|
const { registeredModuleIdsIn, buildModuleRegistryScript } = await importOnce("stx/client-module-registry", () => import("./client-module-registry.js")), inputs = [], code = await buildModuleRegistryScript(registeredModuleIdsIn(...sources), {
|
|
232
|
-
minify: options.buildMode
|
|
232
|
+
minify: minifiesClientCode(options.buildMode),
|
|
233
233
|
collectInputs: inputs
|
|
234
234
|
});
|
|
235
235
|
for (const input of inputs)
|
|
@@ -946,7 +946,7 @@ ${runtimeScript}`);
|
|
|
946
946
|
clientScriptsTransformed = !0;
|
|
947
947
|
let processedContent = content;
|
|
948
948
|
validateClientScript(content, filePath, options.strict, context.__originalFilePath);
|
|
949
|
-
const scriptResult = await processClientScript(content, { eventBindings, attrs, hasColonDirectives, templateContent: template, filePath, projectRoot: process.cwd(), production: options.buildMode
|
|
949
|
+
const scriptResult = await processClientScript(content, { eventBindings, attrs, hasColonDirectives, templateContent: template, filePath, projectRoot: process.cwd(), production: minifiesClientCode(options.buildMode), serverData });
|
|
950
950
|
output = output.replace(match, () => scriptResult);
|
|
951
951
|
}
|
|
952
952
|
if (clientScriptsTransformed)
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
2
|
+
import{zn,Le,qo,ec}from"./chunk-2crxkm7j.js";import{Fn,Xr,Ya,Za,Qa}from"./chunk-5t1whxxt.js";import{Uo,Vo,Wo,Ka,Ja}from"./chunk-5dmkkvs7.js";import{ce,yt,Kr}from"./chunk-7t3ykgsm.js";import{nl,rl,sl,ol,br,Cu}from"./chunk-h4k3hyny.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-xq2ck69k.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ce(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=zn(n,t);if(a){let s=Le(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return Xr(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Vo as auditBuildOutput,Uo as auditConfig,re as buildPwaAssets,Wo as calculateAuditResult,Ja as formatAuditResult,Kr as formatSize,j as generateManifest,_ as generateManifestJson,Za as generateManifestLink,F as generateOfflinePage,ce as generatePrecacheManifest,yt as generatePrecacheManifestJs,M as generatePwaIcons,Fn as generatePwaTags,zn as generateServiceWorker,ec as generateServiceWorkerAuto,Ya as generateSwRegistrationScript,Qa as generateThemeColorMeta,N as getExpectedIconPaths,Le as getServiceWorkerFileName,Xr as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,qo as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,br as pwaDirectives,nl as pwaInstallDirective,sl as pwaOfflineDirective,ol as pwaPushDirective,rl as pwaUpdateDirective,Cu as registerPwaDirectives,Ka as runPwaAudit,D as validateManifest};
|