@stacksjs/stx 0.2.574 → 0.2.576

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.
Files changed (175) hide show
  1. package/README.md +3 -0
  2. package/dist/chunk-08a98yqt.js +2 -0
  3. package/dist/chunk-181m21rg.js +2 -0
  4. package/dist/{chunk-nxw03sy9.js → chunk-1edvsndv.js} +2 -2
  5. package/dist/chunk-1nbn56jw.js +2 -0
  6. package/dist/{chunk-a3w3jc0t.js → chunk-1w9ngqpv.js} +3 -3
  7. package/dist/{chunk-ta50ym5j.js → chunk-1wkpxa58.js} +2 -2
  8. package/dist/{chunk-6z57saf5.js → chunk-2ry2pfpe.js} +1 -1
  9. package/dist/{chunk-ss4h5ch3.js → chunk-32gycb72.js} +1 -1
  10. package/dist/{chunk-g8dx2jew.js → chunk-34fajf1n.js} +100 -99
  11. package/dist/chunk-3bj1w990.js +2 -0
  12. package/dist/{chunk-kcq2ed1d.js → chunk-3gqrv02t.js} +2 -2
  13. package/dist/chunk-4a12azrb.js +2 -0
  14. package/dist/{chunk-e7pjsrfc.js → chunk-4z21afpp.js} +2 -2
  15. package/dist/{chunk-r5ce7mkg.js → chunk-5dm4k229.js} +2 -2
  16. package/dist/chunk-6fpynp8q.js +2 -0
  17. package/dist/{chunk-ytf3qkaw.js → chunk-6q3yszw9.js} +1 -1
  18. package/dist/{chunk-crj0yqc6.js → chunk-6rfm6b1c.js} +1 -1
  19. package/dist/chunk-6ryab0yy.js +2 -0
  20. package/dist/{chunk-3pr388w5.js → chunk-6sasxbv9.js} +1 -1
  21. package/dist/chunk-6w9km7qb.js +2 -0
  22. package/dist/{chunk-4k6cb5fg.js → chunk-6wz6f8d5.js} +3 -3
  23. package/dist/{chunk-cp5903cg.js → chunk-7j9m4d7x.js} +1 -1
  24. package/dist/{chunk-7gxn7mvd.js → chunk-7y73q42g.js} +2 -2
  25. package/dist/chunk-98r9jk2b.js +2 -0
  26. package/dist/chunk-9dgygz8d.js +2 -0
  27. package/dist/chunk-a51f04an.js +2 -0
  28. package/dist/chunk-aa52jhak.js +2 -0
  29. package/dist/chunk-agk478t4.js +3 -0
  30. package/dist/chunk-ambynnzb.js +2 -0
  31. package/dist/chunk-asbq9cgs.js +2 -0
  32. package/dist/{chunk-1n9bxdnh.js → chunk-bbdg3sqq.js} +2 -2
  33. package/dist/{chunk-69k5t6pj.js → chunk-bctjmaxg.js} +53 -53
  34. package/dist/{chunk-9yht5n7g.js → chunk-bks1fe5e.js} +1 -1
  35. package/dist/chunk-bmtsb5mr.js +2 -0
  36. package/dist/chunk-c8rd3573.js +2 -0
  37. package/dist/chunk-d4b8cgvt.js +2 -0
  38. package/dist/chunk-d7skqhrc.js +2 -0
  39. package/dist/{chunk-hqda3vcw.js → chunk-d8ek63nc.js} +1 -1
  40. package/dist/chunk-f2y8bwdd.js +2 -0
  41. package/dist/{chunk-0px2ab3m.js → chunk-fkbthywg.js} +5 -5
  42. package/dist/chunk-g9vtny6q.js +2 -0
  43. package/dist/{chunk-f0mbj8w9.js → chunk-gjp2jxrp.js} +1 -1
  44. package/dist/{chunk-gh0q6jrm.js → chunk-gpb22a8n.js} +2 -2
  45. package/dist/{chunk-anjm087t.js → chunk-h1n43e5n.js} +2 -2
  46. package/dist/{chunk-gdxhe7ae.js → chunk-h72befy4.js} +2 -2
  47. package/dist/chunk-haeb904b.js +3 -0
  48. package/dist/chunk-hcsrj8z6.js +3 -0
  49. package/dist/chunk-hj1bntaa.js +2 -0
  50. package/dist/chunk-hwy3aw5v.js +2 -0
  51. package/dist/chunk-hyafyqy6.js +2 -0
  52. package/dist/{chunk-e27njk86.js → chunk-j4zyq2ap.js} +8 -8
  53. package/dist/chunk-j75hqvgt.js +2 -0
  54. package/dist/chunk-j83ax407.js +2 -0
  55. package/dist/{chunk-e40qpeg5.js → chunk-je0cttam.js} +1 -1
  56. package/dist/{chunk-jwe7yq8m.js → chunk-jgrtvs81.js} +2 -2
  57. package/dist/chunk-k3hfwve1.js +2 -0
  58. package/dist/{chunk-3kc7af8c.js → chunk-kskyfss0.js} +2 -2
  59. package/dist/{chunk-sej3ng5k.js → chunk-mp99h8wh.js} +3 -3
  60. package/dist/{chunk-svvavwp2.js → chunk-n0kw3q6p.js} +1 -1
  61. package/dist/{chunk-0gt7e1ns.js → chunk-n829xbbq.js} +1 -1
  62. package/dist/chunk-nd3qttxh.js +2 -0
  63. package/dist/{chunk-myhh1zsm.js → chunk-ndc1bmj7.js} +1 -1
  64. package/dist/chunk-nn462qm9.js +2 -0
  65. package/dist/chunk-nr07vxm2.js +2 -0
  66. package/dist/{chunk-yhqhv8mp.js → chunk-nskvepjv.js} +414 -162
  67. package/dist/{chunk-8hp6722y.js → chunk-pqkb1m5x.js} +3 -3
  68. package/dist/chunk-q7a5pwaz.js +2 -0
  69. package/dist/{chunk-yf90vn5t.js → chunk-qfb34r6k.js} +3 -3
  70. package/dist/chunk-r51vyhms.js +2 -0
  71. package/dist/{chunk-k5rrp1bt.js → chunk-s68bqf62.js} +1 -1
  72. package/dist/{chunk-32pxa1r0.js → chunk-sf7z2ar9.js} +3 -3
  73. package/dist/{chunk-825m59jr.js → chunk-sn3htx1z.js} +1 -1
  74. package/dist/chunk-svavrmxb.js +2 -0
  75. package/dist/chunk-sw7mvg9p.js +2 -0
  76. package/dist/{chunk-06hx32h4.js → chunk-szfkkbve.js} +1 -1
  77. package/dist/{chunk-c0ewddb3.js → chunk-tasjpnbf.js} +2 -2
  78. package/dist/{chunk-3dr757vb.js → chunk-tybk9hw9.js} +7 -7
  79. package/dist/chunk-tz40t18m.js +2 -0
  80. package/dist/chunk-v1k0bdsg.js +2 -0
  81. package/dist/chunk-vd10tty0.js +2 -0
  82. package/dist/{chunk-501h1mer.js → chunk-vmetcczm.js} +4 -4
  83. package/dist/{chunk-vnh550b5.js → chunk-vnsby98n.js} +1 -1
  84. package/dist/{chunk-zfw39q56.js → chunk-vqkzhd19.js} +1 -1
  85. package/dist/{chunk-bb5a8adb.js → chunk-vw1rmevt.js} +3 -3
  86. package/dist/{chunk-71zwgxws.js → chunk-w1yft5gg.js} +1 -1
  87. package/dist/chunk-w6sa921x.js +2 -0
  88. package/dist/{chunk-1x2x3xgc.js → chunk-wvk932dp.js} +1 -1
  89. package/dist/{chunk-nc0ba89b.js → chunk-x5xwe5nr.js} +6 -6
  90. package/dist/{chunk-76437eb4.js → chunk-xh0808cd.js} +1 -1
  91. package/dist/{chunk-b10n7cpe.js → chunk-xk2v20xe.js} +2 -2
  92. package/dist/{chunk-0ppzstqj.js → chunk-xsxh7h8z.js} +2 -2
  93. package/dist/{chunk-n8hnrgen.js → chunk-y120qq1a.js} +4 -4
  94. package/dist/{chunk-byhsfnkc.js → chunk-zak5xare.js} +1 -1
  95. package/dist/chunk-zcw74jmk.js +2 -0
  96. package/dist/chunk-zxvndwaz.js +2 -0
  97. package/dist/cli.js +58 -58
  98. package/dist/client/signals-context-runtime.js +200 -0
  99. package/dist/client/signals-effect-runtime.js +12 -1
  100. package/dist/client/signals-globals-runtime.js +3 -1
  101. package/dist/client/signals-kept-runtime.d.ts +1 -1
  102. package/dist/client/signals-kept-runtime.js +8 -3
  103. package/dist/client/signals-public-api-runtime.js +2 -0
  104. package/dist/client/signals-reactive-runtime.js +0 -1
  105. package/dist/client/signals-state-runtime.js +53 -20
  106. package/dist/composables/index.d.ts +2 -0
  107. package/dist/composables/index.js +1 -0
  108. package/dist/composables/use-cached-query.js +2 -1
  109. package/dist/craft-entry.js +2 -2
  110. package/dist/craft.js +2 -2
  111. package/dist/includes.js +10 -1
  112. package/dist/index.d.ts +2 -0
  113. package/dist/index.js +1 -0
  114. package/dist/native/runtime/craft-bridge.js +31 -9
  115. package/dist/native/runtime/craft.d.ts +3 -2
  116. package/dist/native/testing.d.ts +115 -0
  117. package/dist/native/testing.js +421 -0
  118. package/dist/offline/query-cache.d.ts +2 -0
  119. package/dist/offline/query-cache.js +43 -33
  120. package/dist/pwa.js +3 -3
  121. package/dist/reactivity.d.ts +36 -1
  122. package/dist/reactivity.js +33 -9
  123. package/dist/runtime-globals.js +2 -0
  124. package/dist/shared-request.d.ts +46 -0
  125. package/dist/shared-request.js +56 -0
  126. package/dist/signals-api.d.ts +32 -6
  127. package/dist/signals-api.js +42 -18
  128. package/dist/signals.js +2 -1
  129. package/dist/ssg.js +3 -3
  130. package/dist/stx-module.d.ts +2 -0
  131. package/package.json +9 -5
  132. package/stx-module.d.ts +2 -0
  133. package/stx.d.ts +54 -4
  134. package/dist/chunk-1m5pagp3.js +0 -2
  135. package/dist/chunk-27ja2rpd.js +0 -2
  136. package/dist/chunk-2b0p7am3.js +0 -2
  137. package/dist/chunk-3k6q1481.js +0 -2
  138. package/dist/chunk-42h0kvng.js +0 -2
  139. package/dist/chunk-4eff1v2p.js +0 -2
  140. package/dist/chunk-5n2v9g2c.js +0 -2
  141. package/dist/chunk-68ygpbta.js +0 -2
  142. package/dist/chunk-6gjfres0.js +0 -2
  143. package/dist/chunk-7debnvz9.js +0 -2
  144. package/dist/chunk-a77gbp9x.js +0 -2
  145. package/dist/chunk-bgbz0wzq.js +0 -2
  146. package/dist/chunk-bgr7fqhs.js +0 -2
  147. package/dist/chunk-bjfrwcfh.js +0 -2
  148. package/dist/chunk-c6jyp7ss.js +0 -3
  149. package/dist/chunk-cdt5pg28.js +0 -2
  150. package/dist/chunk-cfh798k7.js +0 -2
  151. package/dist/chunk-dax3zkmm.js +0 -2
  152. package/dist/chunk-dn676tdp.js +0 -2
  153. package/dist/chunk-dtbj816p.js +0 -2
  154. package/dist/chunk-e23cg45k.js +0 -2
  155. package/dist/chunk-ecwpsjpd.js +0 -2
  156. package/dist/chunk-h8vk3q9n.js +0 -2
  157. package/dist/chunk-hq8vxds5.js +0 -3
  158. package/dist/chunk-j8pamkbh.js +0 -2
  159. package/dist/chunk-mfm7ezh6.js +0 -2
  160. package/dist/chunk-mp16jxcg.js +0 -2
  161. package/dist/chunk-n1c9j5qv.js +0 -2
  162. package/dist/chunk-n61v7e3s.js +0 -2
  163. package/dist/chunk-nf63pk4s.js +0 -2
  164. package/dist/chunk-p5cry5s7.js +0 -2
  165. package/dist/chunk-r8qhex33.js +0 -2
  166. package/dist/chunk-rqvn1s52.js +0 -2
  167. package/dist/chunk-sjsant53.js +0 -2
  168. package/dist/chunk-snzh9z3g.js +0 -3
  169. package/dist/chunk-ty8g61y9.js +0 -2
  170. package/dist/chunk-v1k6w4z5.js +0 -2
  171. package/dist/chunk-vm7zv0gc.js +0 -2
  172. package/dist/chunk-vnxc48en.js +0 -2
  173. package/dist/chunk-y7vbwhh7.js +0 -2
  174. package/dist/chunk-yvyypd92.js +0 -2
  175. package/dist/chunk-zpm02e15.js +0 -2
@@ -25,6 +25,206 @@ export const SIGNALS_CONTEXT_RUNTIME = ` // ===================================
25
25
  });
26
26
  }
27
27
 
28
+ // watch(source, callback, options): the module watch's contract (Vue's).
29
+ // source is a signal, a derived, a getter, a reactive object, or an array of
30
+ // those. callback(next, previous, onCleanup) runs when the value changes
31
+ // (Object.is; structurally with deep), not when the watch is created unless
32
+ // immediate is set, and returns a stop function. once stops after the first
33
+ // call. flush: 'post' (the default, as in the module) calls back after the
34
+ // next render (nextTick), 'pre' on a microtask, 'sync' inside the change;
35
+ // changes before a deferred call land as one, with the latest value. The
36
+ // immediate first call is made at the same timing. The callback is
37
+ // untracked: what it reads does not become something the watch follows, and
38
+ // a callback that throws is reported without stopping the watch.
39
+ //
40
+ // It used to be $watch, which with a getter called back once with the getter
41
+ // itself, and with a signal called back at once with no previous value and
42
+ // again for every write, equal or not. $watch is kept as it was.
43
+ function __stxWatchRead(s) {
44
+ if (typeof s === 'function') return s();
45
+ if (s && typeof s === 'object' && 'value' in s && !Array.isArray(s)) return s.value;
46
+ return s;
47
+ }
48
+ function __stxWatchTraverse(value, seen) {
49
+ if (!value || typeof value !== 'object') return value;
50
+ if (seen.has(value)) return value;
51
+ seen.add(value);
52
+ if (Array.isArray(value)) {
53
+ for (var i = 0; i < value.length; i++) __stxWatchTraverse(value[i], seen);
54
+ }
55
+ else if (value instanceof Map || value instanceof Set) {
56
+ value.forEach(function(v) { __stxWatchTraverse(v, seen); });
57
+ }
58
+ else {
59
+ for (var k in value) __stxWatchTraverse(value[k], seen);
60
+ }
61
+ return value;
62
+ }
63
+ // A copy to compare the next value with: plain objects, arrays, Maps, Sets
64
+ // and Dates are copied, anything else (a DOM node, a class instance) is kept.
65
+ function __stxWatchCopy(value, seen) {
66
+ if (!value || typeof value !== 'object') return value;
67
+ if (seen.has(value)) return seen.get(value);
68
+ var out;
69
+ if (Array.isArray(value)) {
70
+ out = [];
71
+ seen.set(value, out);
72
+ for (var i = 0; i < value.length; i++) out.push(__stxWatchCopy(value[i], seen));
73
+ return out;
74
+ }
75
+ if (value instanceof Date) return new Date(value.getTime());
76
+ if (value instanceof Map) {
77
+ out = new Map();
78
+ seen.set(value, out);
79
+ value.forEach(function(v, k) { out.set(k, __stxWatchCopy(v, seen)); });
80
+ return out;
81
+ }
82
+ if (value instanceof Set) {
83
+ out = new Set();
84
+ seen.set(value, out);
85
+ value.forEach(function(v) { out.add(__stxWatchCopy(v, seen)); });
86
+ return out;
87
+ }
88
+ var proto = Object.getPrototypeOf(value);
89
+ if (proto !== Object.prototype && proto !== null) return value;
90
+ out = {};
91
+ seen.set(value, out);
92
+ for (var k in value) out[k] = __stxWatchCopy(value[k], seen);
93
+ return out;
94
+ }
95
+ function __stxWatchEqual(a, b, seen) {
96
+ if (Object.is(a, b)) return true;
97
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false;
98
+ if (seen.has(a)) return seen.get(a) === b;
99
+ seen.set(a, b);
100
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
101
+ if (a instanceof Date || b instanceof Date) return a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
102
+ if (a instanceof Map || b instanceof Map) {
103
+ if (!(a instanceof Map && b instanceof Map) || a.size !== b.size) return false;
104
+ var same = true;
105
+ a.forEach(function(v, k) { if (same && (!b.has(k) || !__stxWatchEqual(v, b.get(k), seen))) same = false; });
106
+ return same;
107
+ }
108
+ if (a instanceof Set || b instanceof Set) {
109
+ if (!(a instanceof Set && b instanceof Set) || a.size !== b.size) return false;
110
+ var all = true;
111
+ a.forEach(function(v) { if (all && !b.has(v)) all = false; });
112
+ return all;
113
+ }
114
+ var ka = Object.keys(a);
115
+ var kb = Object.keys(b);
116
+ if (ka.length !== kb.length) return false;
117
+ for (var i = 0; i < ka.length; i++) {
118
+ if (!Object.prototype.hasOwnProperty.call(b, ka[i]) || !__stxWatchEqual(a[ka[i]], b[ka[i]], seen)) return false;
119
+ }
120
+ return true;
121
+ }
122
+
123
+ function watch(source, callback, options) {
124
+ options = options || {};
125
+ var flush = options.flush || 'post';
126
+ var multi = Array.isArray(source);
127
+ var deep = !!options.deep;
128
+ var getter;
129
+ if (multi) getter = function() { return source.map(__stxWatchRead); };
130
+ else if (typeof source === 'function') getter = source;
131
+ else if (source && typeof source === 'object' && 'value' in source) getter = function() { return source.value; };
132
+ else if (source && typeof source === 'object') {
133
+ // A reactive object: what changes is inside it, so it is watched deeply.
134
+ getter = function() { return source; };
135
+ deep = options.deep !== false;
136
+ }
137
+ else {
138
+ console.warn('[stx] watch() needs a signal, a getter, a reactive object or an array of those; got', source);
139
+ getter = function() { return source; };
140
+ }
141
+
142
+ var oldValue;
143
+ var first = true;
144
+ var stopped = false;
145
+ var cleanup;
146
+ var queued = false;
147
+ var forceNext = false;
148
+ var latest;
149
+
150
+ function snapshot(value) {
151
+ return deep ? __stxWatchCopy(value, new Map()) : (multi ? value.slice() : value);
152
+ }
153
+ function changed(next, prev) {
154
+ if (deep) return !__stxWatchEqual(next, prev, new Map());
155
+ if (multi) {
156
+ if (!prev || prev.length !== next.length) return true;
157
+ for (var i = 0; i < next.length; i++) if (!Object.is(next[i], prev[i])) return true;
158
+ return false;
159
+ }
160
+ return !Object.is(next, prev);
161
+ }
162
+ function onCleanup(fn) { cleanup = fn; }
163
+ function fire(next) {
164
+ var prev = oldValue;
165
+ oldValue = snapshot(next);
166
+ if (cleanup) {
167
+ var pending = cleanup;
168
+ cleanup = undefined;
169
+ try { pending(); }
170
+ catch (e) { console.error('[stx] watch cleanup error:', e); }
171
+ }
172
+ peek(function() {
173
+ try { callback(next, prev, onCleanup); }
174
+ catch (e) { console.error('[stx] watch callback error:', e); }
175
+ });
176
+ if (options.once) stop();
177
+ }
178
+ function job() {
179
+ queued = false;
180
+ var force = forceNext;
181
+ forceNext = false;
182
+ if (stopped || (!force && !changed(latest, oldValue))) return;
183
+ fire(latest);
184
+ }
185
+ function schedule(next) {
186
+ latest = next;
187
+ if (queued) return;
188
+ queued = true;
189
+ if (flush === 'post') nextTick(job);
190
+ else Promise.resolve().then(job);
191
+ }
192
+
193
+ var dispose = effect(function() {
194
+ var next = getter();
195
+ if (deep) __stxWatchTraverse(next, new Set());
196
+ if (stopped) return;
197
+ if (first) {
198
+ first = false;
199
+ if (!options.immediate) oldValue = snapshot(next);
200
+ else if (flush === 'sync') fire(next);
201
+ else {
202
+ forceNext = true;
203
+ schedule(next);
204
+ }
205
+ return;
206
+ }
207
+ if (flush !== 'sync') schedule(next);
208
+ else if (changed(next, oldValue)) fire(next);
209
+ });
210
+
211
+ // once with immediate stops inside the first run, before dispose exists.
212
+ if (stopped) dispose();
213
+
214
+ function stop() {
215
+ if (stopped) return;
216
+ stopped = true;
217
+ if (dispose) dispose();
218
+ if (cleanup) {
219
+ var pending = cleanup;
220
+ cleanup = undefined;
221
+ try { pending(); }
222
+ catch (e) { console.error('[stx] watch cleanup error:', e); }
223
+ }
224
+ }
225
+ return stop;
226
+ }
227
+
28
228
  // provide() \u2014 share values across components (like Vue's provide/inject)
29
229
  // Usage: provide('Modal', Modal) \u2014 makes Modal accessible in all components
30
230
  //
@@ -140,8 +140,19 @@ catch (e) { console.warn('[stx] dispose error:', e); } });
140
140
  return typeof v === 'function' && v._isDerived === true;
141
141
  }
142
142
 
143
+ // Read a signal (or derived) without subscribing the effect running now: an
144
+ // effect that calls untrack(count) does not run again when count changes.
145
+ // Anything else is returned as it is.
143
146
  function untrack(v) {
144
- return isSignal(v) || (typeof v === 'function' && v._isDerived) ? v() : v;
147
+ if (!(isSignal(v) || (typeof v === 'function' && v._isDerived))) return v;
148
+ const prev = activeEffect;
149
+ activeEffect = null;
150
+ try {
151
+ return v();
152
+ }
153
+ finally {
154
+ activeEffect = prev;
155
+ }
145
156
  }
146
157
 
147
158
  function peek(fn) {
@@ -1,6 +1,7 @@
1
1
  export const SIGNALS_GLOBALS_RUNTIME = ` // Also expose globally for convenience
2
2
  window.state = state;
3
3
  window.derived = derived;
4
+ window.memo = memo;
4
5
  window.effect = effect;
5
6
  window.batch = batch;
6
7
  window.onMount = onMount;
@@ -41,6 +42,7 @@ export const SIGNALS_GLOBALS_RUNTIME = ` // Also expose globally for convenienc
41
42
  window.setKeptScope = setKeptScope;
42
43
  window.flushKeptState = flushKeptState;
43
44
  window.cachedQuery = cachedQuery;
45
+ window.sharedRequest = sharedRequest;
44
46
  window.useEventListener = useEventListener;
45
47
  window.useWebSocket = useWebSocket;
46
48
  window.useColorMode = useColorMode;
@@ -57,7 +59,7 @@ export const SIGNALS_GLOBALS_RUNTIME = ` // Also expose globally for convenienc
57
59
  window.ref = state;
58
60
  window.reactive = reactive;
59
61
  window.computed = derived;
60
- window.watch = $watch;
62
+ window.watch = watch;
61
63
  window.watchEffect = function(fn) { return effect(fn); };
62
64
 
63
65
  // Note: SPA Router and View Transitions CSS are provided by the canonical
@@ -1,2 +1,2 @@
1
1
  /** Kept-state and cached-query helpers used by the generated client runtime. */
2
- export declare function signalsKeptRuntime(createKeptStoreSource: string, indexedDbBackendSource: string, createQueryCacheSource: string, queryTargetMatchesSource: string): string;
2
+ export declare function signalsKeptRuntime(createKeptStoreSource: string, indexedDbBackendSource: string, createQueryCacheSource: string, queryTargetMatchesSource: string, sharedRequestSource: string): string;
@@ -1,5 +1,10 @@
1
- export function signalsKeptRuntime(createKeptStoreSource, indexedDbBackendSource, createQueryCacheSource, queryTargetMatchesSource) {
2
- return ` // A value kept between visits, for a phone app between launches: the tab a
1
+ export function signalsKeptRuntime(createKeptStoreSource, indexedDbBackendSource, createQueryCacheSource, queryTargetMatchesSource, sharedRequestSource) {
2
+ return ` // One request for every caller that wants the same answer: run joins one
3
+ // in flight, fresh waits one out and asks again, latest replaces a request
4
+ // counter. See shared-request.ts; cached queries are built on it.
5
+ var sharedRequest = (${sharedRequestSource});
6
+
7
+ // A value kept between visits, for a phone app between launches: the tab a
3
8
  // user opens right after starting the app draws last time's data at once
4
9
  // and the fresh answer replaces it. Kept under stx:kept:, in a scope such as
5
10
  // the signed-in account, so one person's data is never shown to another. A
@@ -14,7 +19,7 @@ export function signalsKeptRuntime(createKeptStoreSource, indexedDbBackendSource
14
19
  // are read where they are.
15
20
  var STX_KEPT_PREFIX = 'stx:kept:';
16
21
  var __stxKept = (${createKeptStoreSource})(undefined, ${indexedDbBackendSource});
17
- var __stxQueries = (${createQueryCacheSource})({ state: state, kept: __stxKept, prefix: STX_KEPT_PREFIX, matches: ${queryTargetMatchesSource} });
22
+ var __stxQueries = (${createQueryCacheSource})({ state: state, kept: __stxKept, prefix: STX_KEPT_PREFIX, matches: ${queryTargetMatchesSource}, sharedRequest: sharedRequest });
18
23
  function stxKeptPrefix(scope) {
19
24
  return STX_KEPT_PREFIX + (scope === undefined || scope === null || scope === '' ? '' : String(scope) + ':');
20
25
  }
@@ -12,6 +12,7 @@ export function signalsPublicApiRuntime(componentApiRuntime) {
12
12
  hydrateHost,
13
13
  state,
14
14
  derived,
15
+ memo,
15
16
  effect,
16
17
  batch,
17
18
  isSignal,
@@ -73,6 +74,7 @@ export function signalsPublicApiRuntime(componentApiRuntime) {
73
74
  setKeptScope,
74
75
  flushKeptState,
75
76
  cachedQuery,
77
+ sharedRequest,
76
78
  useCookie,
77
79
  useId,
78
80
  useReactiveProp,
@@ -63,5 +63,4 @@ export const SIGNALS_REACTIVE_RUNTIME = ` // Vue-compat aliases
63
63
  return proxy;
64
64
  }
65
65
  var computed = derived;
66
- var watch = $watch;
67
66
  var watchEffect = function(fn) { return effect(fn); };`;
@@ -66,42 +66,69 @@ export const SIGNALS_STATE_RUNTIME = ` // =====================================
66
66
  // Derived Signal
67
67
  // ==========================================================================
68
68
 
69
- function derived(compute) {
69
+ // derived(compute, { equals }): with equals, a change upstream recomputes
70
+ // the value at once (when anything reads it) and passes the change on only
71
+ // when equals(previous, next) is false, so an effect over
72
+ // derived(() => user().id) does not run again for a new user object with the
73
+ // same id. Without it the value is lazy and every upstream change is passed
74
+ // on, as before. memo(compute, equals) is the short form.
75
+ function derived(compute, options) {
70
76
  let cached;
71
77
  let isDirty = true;
78
+ let hasValue = false;
72
79
  const effects = new Set();
80
+ const equals = options && typeof options.equals === 'function' ? options.equals : null;
81
+
82
+ function recompute() {
83
+ const prev = activeEffect;
84
+ activeEffect = markDirty;
85
+ effectStack.push(markDirty);
86
+ try {
87
+ cached = compute();
88
+ hasValue = true;
89
+ }
90
+ finally {
91
+ effectStack.pop();
92
+ activeEffect = prev;
93
+ }
94
+ isDirty = false;
95
+ }
96
+
97
+ // Recompute now and say whether the value changed. A compute that throws
98
+ // counts as a change: the reader recomputes and sees the error.
99
+ function changedNow() {
100
+ const before = cached;
101
+ const had = hasValue;
102
+ try { recompute(); }
103
+ catch (e) { isDirty = true; return true; }
104
+ return !had || !equals(before, cached);
105
+ }
73
106
 
74
107
  // Passes a change on to what read this value. A signal's notification
75
108
  // collects through it (_stxCollect) instead of calling it, so an effect
76
109
  // reached both directly and through here still runs once.
77
110
  const markDirty = () => {
78
- if (!isDirty) {
79
- isDirty = true;
80
- notifySubscribers(effects);
111
+ if (isDirty) return;
112
+ if (equals && effects.size) {
113
+ if (changedNow()) notifySubscribers(effects);
114
+ return;
81
115
  }
116
+ isDirty = true;
117
+ notifySubscribers(effects);
82
118
  };
83
119
  markDirty._stxCollect = (into) => {
84
- if (!isDirty) {
85
- isDirty = true;
86
- collectSubscribers(effects, into);
120
+ if (isDirty) return;
121
+ if (equals && effects.size) {
122
+ if (changedNow()) collectSubscribers(effects, into);
123
+ return;
87
124
  }
125
+ isDirty = true;
126
+ collectSubscribers(effects, into);
88
127
  };
89
128
 
90
129
  const signal = () => {
91
130
  if (activeEffect) effects.add(activeEffect);
92
- if (isDirty) {
93
- const prev = activeEffect;
94
- activeEffect = markDirty;
95
- effectStack.push(markDirty);
96
- try {
97
- cached = compute();
98
- }
99
- finally {
100
- effectStack.pop();
101
- activeEffect = prev;
102
- }
103
- isDirty = false;
104
- }
131
+ if (isDirty) recompute();
105
132
  return cached;
106
133
  };
107
134
 
@@ -116,4 +143,10 @@ finally {
116
143
 
117
144
  return signal;
118
145
  }
146
+
147
+ // A derived value that passes a change on only when it is a different value
148
+ // (Object.is, or the equals given).
149
+ function memo(compute, equals) {
150
+ return derived(compute, { equals: typeof equals === 'function' ? equals : Object.is });
151
+ }
119
152
  `;
@@ -90,6 +90,8 @@ export {
90
90
  type CachedQueryOptions,
91
91
  type KeptScope,
92
92
  } from './use-cached-query';
93
+ // One request for every caller that wants the same answer
94
+ export { sharedRequest, type SharedRequest, type SharedRequestOptions } from '../shared-request';
93
95
  export {
94
96
  useOutbox,
95
97
  type Outbox,
@@ -45,6 +45,7 @@ export {
45
45
  flushKeptState,
46
46
  setKeptScope
47
47
  } from "./use-cached-query.js";
48
+ export { sharedRequest } from "../shared-request.js";
48
49
  export {
49
50
  useOutbox
50
51
  } from "./use-outbox.js";
@@ -1,5 +1,6 @@
1
1
  import { createKeptStore, indexedDbBackend } from "../offline/kept-store.js";
2
2
  import { createQueryCache, queryTargetMatches } from "../offline/query-cache.js";
3
+ import { sharedRequest } from "../shared-request.js";
3
4
  import { state } from "../signals-api.js";
4
5
  let kept = null, queries = null;
5
6
  export function keptStore() {
@@ -9,7 +10,7 @@ export function keptStore() {
9
10
  }
10
11
  export function queryCache() {
11
12
  if (!queries)
12
- queries = createQueryCache({ state, kept: keptStore(), matches: queryTargetMatches });
13
+ queries = createQueryCache({ state, kept: keptStore(), matches: queryTargetMatches, sharedRequest });
13
14
  return queries;
14
15
  }
15
16
  export function cachedQuery(key, options) {
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import{Kr,Lo,jo}from"./chunk-bb5a8adb.js";import"./chunk-yf90vn5t.js";import"./chunk-7hr63cp5.js";import"./chunk-gdxhe7ae.js";import"./chunk-hq8vxds5.js";import"./chunk-4xvbc0mb.js";import"./chunk-g8dx2jew.js";import"./chunk-3dr757vb.js";import"./chunk-nc0ba89b.js";import"./chunk-vde4mtfr.js";import"./chunk-ta50ym5j.js";import"./chunk-nxw03sy9.js";import"./chunk-550q827h.js";import"./chunk-t79xnvzr.js";import{Td,Ao,$d,Rd,Po,Xr,Io,Ad,Oo,Pd,Id,Do,Mo,No}from"./chunk-e27njk86.js";import"./chunk-4k6cb5fg.js";import"./chunk-cp5903cg.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(`
2
+ import{Xr,Lo,jo}from"./chunk-vw1rmevt.js";import"./chunk-qfb34r6k.js";import"./chunk-7hr63cp5.js";import"./chunk-h72befy4.js";import"./chunk-haeb904b.js";import"./chunk-4xvbc0mb.js";import"./chunk-34fajf1n.js";import"./chunk-tybk9hw9.js";import"./chunk-x5xwe5nr.js";import"./chunk-vde4mtfr.js";import"./chunk-1wkpxa58.js";import"./chunk-1edvsndv.js";import"./chunk-550q827h.js";import"./chunk-t79xnvzr.js";import{$d,Ao,Rd,Ad,Po,Kr,Io,Pd,Oo,Id,Od,Do,Mo,No}from"./chunk-j4zyq2ap.js";import"./chunk-6wz6f8d5.js";import"./chunk-7j9m4d7x.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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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,Xr as CRAFT_COMPONENTS,Ad as CRAFT_COMPONENT_RUNTIME,Io as CRAFT_COMPONENT_STYLES,Kr as NATIVE_COMPONENTS,Do as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Lo as compileToNative,jo as createHotReloadServer,Ao as generateCraftBridgeScript,V as generateCraftOptimizations,No as getAvailableFormats,Mo as getAvailableTargets,Id as getCraftComponents,G as getSSRCacheStats,Po as injectCraftBridge,$d as isCraftEnvironment,Y as prerenderForCraft,Oo as processCraftComponents,Rd as processCraftDirective,Pd as registerCraftComponent,Q as renderSSR};
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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{$d as CRAFT_BRIDGE_SCRIPT,Kr as CRAFT_COMPONENTS,Pd as CRAFT_COMPONENT_RUNTIME,Io as CRAFT_COMPONENT_STYLES,Xr as NATIVE_COMPONENTS,Do as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Lo as compileToNative,jo as createHotReloadServer,Ao as generateCraftBridgeScript,V as generateCraftOptimizations,No as getAvailableFormats,Mo as getAvailableTargets,Od as getCraftComponents,G as getSSRCacheStats,Po as injectCraftBridge,Rd as isCraftEnvironment,Y as prerenderForCraft,Oo as processCraftComponents,Ad as processCraftDirective,Id as registerCraftComponent,Q as renderSSR};
package/dist/craft.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import{Kr,Lo,jo}from"./chunk-bb5a8adb.js";import"./chunk-yf90vn5t.js";import"./chunk-7hr63cp5.js";import"./chunk-gdxhe7ae.js";import"./chunk-hq8vxds5.js";import"./chunk-4xvbc0mb.js";import"./chunk-g8dx2jew.js";import"./chunk-3dr757vb.js";import"./chunk-nc0ba89b.js";import"./chunk-vde4mtfr.js";import"./chunk-ta50ym5j.js";import"./chunk-nxw03sy9.js";import"./chunk-550q827h.js";import"./chunk-t79xnvzr.js";import{Td,Ao,$d,Rd,Po,Xr,Io,Ad,Oo,Pd,Id,Do,Mo,No}from"./chunk-e27njk86.js";import"./chunk-4k6cb5fg.js";import"./chunk-cp5903cg.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(`
2
+ import{Xr,Lo,jo}from"./chunk-vw1rmevt.js";import"./chunk-qfb34r6k.js";import"./chunk-7hr63cp5.js";import"./chunk-h72befy4.js";import"./chunk-haeb904b.js";import"./chunk-4xvbc0mb.js";import"./chunk-34fajf1n.js";import"./chunk-tybk9hw9.js";import"./chunk-x5xwe5nr.js";import"./chunk-vde4mtfr.js";import"./chunk-1wkpxa58.js";import"./chunk-1edvsndv.js";import"./chunk-550q827h.js";import"./chunk-t79xnvzr.js";import{$d,Ao,Rd,Ad,Po,Kr,Io,Pd,Oo,Id,Od,Do,Mo,No}from"./chunk-j4zyq2ap.js";import"./chunk-6wz6f8d5.js";import"./chunk-7j9m4d7x.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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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,Xr as CRAFT_COMPONENTS,Ad as CRAFT_COMPONENT_RUNTIME,Io as CRAFT_COMPONENT_STYLES,Kr as NATIVE_COMPONENTS,Do as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Lo as compileToNative,jo as createHotReloadServer,Ao as generateCraftBridgeScript,V as generateCraftOptimizations,No as getAvailableFormats,Mo as getAvailableTargets,Id as getCraftComponents,G as getSSRCacheStats,Po as injectCraftBridge,$d as isCraftEnvironment,Y as prerenderForCraft,Oo as processCraftComponents,Rd as processCraftDirective,Pd as registerCraftComponent,Q as renderSSR};
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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{$d as CRAFT_BRIDGE_SCRIPT,Kr as CRAFT_COMPONENTS,Pd as CRAFT_COMPONENT_RUNTIME,Io as CRAFT_COMPONENT_STYLES,Xr as NATIVE_COMPONENTS,Do as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Lo as compileToNative,jo as createHotReloadServer,Ao as generateCraftBridgeScript,V as generateCraftOptimizations,No as getAvailableFormats,Mo as getAvailableTargets,Od as getCraftComponents,G as getSSRCacheStats,Po as injectCraftBridge,Rd as isCraftEnvironment,Y as prerenderForCraft,Oo as processCraftComponents,Ad as processCraftDirective,Id as registerCraftComponent,Q as renderSSR};
package/dist/includes.js CHANGED
@@ -652,7 +652,10 @@ export async function processIncludes(template, context, filePath, options, depe
652
652
  includeContext.__stx_signals_gate = usesSignalsInScript(partialContent, includeFilePath);
653
653
  for (const [key, value] of Object.entries(localVars))
654
654
  includeContext[key] = value;
655
- const scriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi, scriptMatches = [...partialContent.matchAll(scriptRegex)];
655
+ const scriptRegex = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi, scriptMatches = [...partialContent.matchAll(scriptRegex)].sort((a, b) => {
656
+ const aServer = (a[1] || "").includes("server"), bServer = (b[1] || "").includes("server");
657
+ return Number(bServer) - Number(aServer);
658
+ });
656
659
  let preservedScript = "", signalScopeId = null, declaresSignals = !1, registersBindings = !1;
657
660
  for (const scriptMatch of scriptMatches) {
658
661
  const scriptAttrs = scriptMatch[1] || "";
@@ -695,6 +698,12 @@ export async function processIncludes(template, context, filePath, options, depe
695
698
  scriptContent = stripStxRuntimeImports(scriptContent);
696
699
  }
697
700
  const isSignalScript = hasSignalApis(scriptContent);
701
+ if (!isServerScript) {
702
+ const { extractBridgeData, generateServerDataBridge } = await import("./client-script.js"), bridge = generateServerDataBridge(scriptContent, extractBridgeData(includeContext));
703
+ if (bridge)
704
+ scriptContent = `${bridge}
705
+ ${scriptContent}`;
706
+ }
698
707
  if (isSignalScript && !isServerScript) {
699
708
  declaresSignals = !0;
700
709
  signalScopeId = includeScopeId(includeFilePath, context);
package/dist/index.d.ts CHANGED
@@ -73,6 +73,8 @@ export {
73
73
  type KeptScope,
74
74
  setKeptScope,
75
75
  } from './composables/use-cached-query';
76
+ // One request for every caller: the module twin of window.stx.sharedRequest.
77
+ export { sharedRequest, type SharedRequest, type SharedRequestOptions } from './shared-request';
76
78
  // View composers were unreachable: `runComposers` is wired into the render
77
79
  // pipeline (process.ts:1206) and runs on every render, but the two functions that
78
80
  // PUT anything in the registry were never exported, so the registry was always
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ export {
22
22
  flushKeptState,
23
23
  setKeptScope
24
24
  } from "./composables/use-cached-query.js";
25
+ export { sharedRequest } from "./shared-request.js";
25
26
  export {
26
27
  clearComposers,
27
28
  composer,
@@ -125,16 +125,38 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
125
125
  write: (value) => request("Clipboard", "write", [value]),
126
126
  read: () => request("Clipboard", "read", [])
127
127
  };
128
- craft.haptic = (style) => request("Haptics", "impact", [style || "medium"]);
129
- const feedback = (answer) => answer.then(() => {}, (error) => {
130
- if (error?.code === "CAPABILITY_DISABLED")
131
- return;
132
- throw error;
133
- });
128
+ const settle = (send) => {
129
+ try {
130
+ return Promise.resolve(send()).then(() => {}, () => {});
131
+ } catch {
132
+ return Promise.resolve();
133
+ }
134
+ }, unknownHaptics = new Set, hapticOr = (method, args, impact) => {
135
+ if (unknownHaptics.has(method))
136
+ return settle(() => request("Haptics", "impact", [impact]));
137
+ return settle(() => request("Haptics", method, args).catch((error) => {
138
+ if (error?.code !== "UNKNOWN_ACTION")
139
+ throw error;
140
+ unknownHaptics.add(method);
141
+ return request("Haptics", "impact", [impact]);
142
+ }));
143
+ };
144
+ craft.haptic = (style) => settle(() => request("Haptics", "impact", [style || "medium"]));
134
145
  craft.haptics = {
135
- impact: (style) => feedback(craft.haptic(style)),
136
- notification: (type) => feedback(craft.haptic(type === "error" ? "heavy" : type === "warning" ? "medium" : "light")),
137
- selection: () => feedback(craft.haptic("soft"))
146
+ impact: (style) => craft.haptic(style),
147
+ notification: (type) => {
148
+ const kind = type === "error" || type === "warning" ? type : "success";
149
+ return hapticOr("notification", [kind], kind === "error" ? "heavy" : kind === "warning" ? "medium" : "light");
150
+ },
151
+ selection: () => hapticOr("selection", [], "soft"),
152
+ prepare: (kind) => {
153
+ if (unknownHaptics.has("prepare"))
154
+ return Promise.resolve();
155
+ return settle(() => request("Haptics", "prepare", kind === void 0 ? [] : [kind]).catch((error) => {
156
+ if (error?.code === "UNKNOWN_ACTION")
157
+ unknownHaptics.add("prepare");
158
+ }));
159
+ }
138
160
  };
139
161
  craft.storage = Object.assign({ getSync: () => null, setSync: () => {
140
162
  return;