@stacksjs/stx 0.2.421 → 0.2.423

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 (251) hide show
  1. package/dist/{chunk-ep5jnqdb.js → chunk-02n071n7.js} +6 -6
  2. package/dist/chunk-03n23sh6.js +2 -0
  3. package/dist/chunk-07mxghsz.js +2 -0
  4. package/dist/{chunk-kjkwycce.js → chunk-0bmc75w6.js} +4 -4
  5. package/dist/{chunk-hyak4dzg.js → chunk-0hhq9hbq.js} +3 -3
  6. package/dist/{chunk-66k7yxnr.js → chunk-12pvnn1e.js} +4 -4
  7. package/dist/chunk-1497wcxc.js +2 -0
  8. package/dist/chunk-17n9e5wk.js +2 -0
  9. package/dist/chunk-1p8hc1ve.js +2 -0
  10. package/dist/chunk-1r3ghgsz.js +2 -0
  11. package/dist/{chunk-r8wze9ym.js → chunk-24e7qjb8.js} +2 -2
  12. package/dist/chunk-259ecbwa.js +2 -0
  13. package/dist/chunk-26gfsa9w.js +2 -0
  14. package/dist/{chunk-3ynkg5dz.js → chunk-2bpjq1qz.js} +2 -2
  15. package/dist/{chunk-11ra3sbc.js → chunk-2x9jd5w0.js} +3 -3
  16. package/dist/{chunk-k31fwm2w.js → chunk-3hmy75tw.js} +5 -5
  17. package/dist/{chunk-12b8akfg.js → chunk-3pxp0r0a.js} +3 -3
  18. package/dist/{chunk-x5ks23vx.js → chunk-3ry9ca1s.js} +2 -2
  19. package/dist/{chunk-th9s15es.js → chunk-45rfv3a5.js} +2 -2
  20. package/dist/chunk-47apfsxp.js +2 -0
  21. package/dist/{chunk-ax58cds3.js → chunk-48kgnqpk.js} +4 -4
  22. package/dist/{chunk-rsxvbnp4.js → chunk-4hd5wb8x.js} +3 -3
  23. package/dist/chunk-535nrr6j.js +2 -0
  24. package/dist/chunk-5mfhk69g.js +2 -0
  25. package/dist/{chunk-aync8qmk.js → chunk-5vwg3h5g.js} +2 -2
  26. package/dist/{chunk-tspmynvh.js → chunk-62chbqev.js} +1 -1
  27. package/dist/chunk-6c7294j8.js +2 -0
  28. package/dist/{chunk-z0ck9t6j.js → chunk-6cbvx87h.js} +5 -5
  29. package/dist/{chunk-kea18wnc.js → chunk-6fsbny9m.js} +3 -3
  30. package/dist/chunk-6gh2rvyz.js +2 -0
  31. package/dist/chunk-6j6gbp0y.js +2 -0
  32. package/dist/chunk-6jgjmycb.js +2 -0
  33. package/dist/{chunk-hjp990p8.js → chunk-6t278w29.js} +2 -2
  34. package/dist/{chunk-5vfyxxrp.js → chunk-6t7mxb0b.js} +2 -2
  35. package/dist/chunk-6wmxrn6x.js +2 -0
  36. package/dist/chunk-6wweqfg7.js +2 -0
  37. package/dist/{chunk-h1h6xe1k.js → chunk-7a9h7ycs.js} +5 -5
  38. package/dist/chunk-7pbv9mg7.js +2 -0
  39. package/dist/{chunk-09hhrjk9.js → chunk-89b2r1q0.js} +6 -6
  40. package/dist/{chunk-0varh725.js → chunk-8a0r2j8f.js} +3 -3
  41. package/dist/{chunk-pzngjk81.js → chunk-8nsbf2mz.js} +1074 -1074
  42. package/dist/{chunk-mg13q1kd.js → chunk-8zf5q1m3.js} +2 -2
  43. package/dist/chunk-9d53d0t6.js +2 -0
  44. package/dist/chunk-9j72har9.js +2 -0
  45. package/dist/chunk-9yqz5ge5.js +2 -0
  46. package/dist/chunk-a5c9n7an.js +2 -0
  47. package/dist/chunk-a836zn7c.js +2 -0
  48. package/dist/{chunk-8vq0qjq9.js → chunk-a8g6y9kw.js} +5 -5
  49. package/dist/{chunk-21a7p956.js → chunk-acwgap78.js} +1 -1
  50. package/dist/{chunk-qx3js9tk.js → chunk-aen2baze.js} +1 -1
  51. package/dist/chunk-ahgrkva8.js +2 -0
  52. package/dist/chunk-akbb6j7s.js +2 -0
  53. package/dist/chunk-avakcrbs.js +2 -0
  54. package/dist/{chunk-tafebmtg.js → chunk-axydabse.js} +2 -2
  55. package/dist/{chunk-4n6c5rp5.js → chunk-b7973zvk.js} +2 -2
  56. package/dist/{chunk-debz86rr.js → chunk-bxwe7wxj.js} +10 -10
  57. package/dist/{chunk-2ewa2sg5.js → chunk-c1dmr865.js} +3 -3
  58. package/dist/chunk-cenq2n6e.js +2 -0
  59. package/dist/{chunk-zvh2nnzr.js → chunk-cf6htz63.js} +1 -1
  60. package/dist/chunk-cnmz9543.js +2 -0
  61. package/dist/{chunk-bh4x090w.js → chunk-cx2rdew4.js} +13 -13
  62. package/dist/{chunk-wg1ttvs5.js → chunk-cznsm2n3.js} +2 -2
  63. package/dist/chunk-d1qzhawc.js +2 -0
  64. package/dist/chunk-d6hnvwre.js +2 -0
  65. package/dist/{chunk-014gmm8w.js → chunk-dcwjxq8n.js} +2 -2
  66. package/dist/chunk-dhqwg62x.js +2 -0
  67. package/dist/{chunk-z521cyfv.js → chunk-dmd6yk2x.js} +5 -5
  68. package/dist/chunk-e18qfegt.js +2 -0
  69. package/dist/chunk-eej89wkt.js +2 -0
  70. package/dist/chunk-ekxffxbd.js +2 -0
  71. package/dist/{chunk-hy9e3ny6.js → chunk-ex0tq6x2.js} +1 -1
  72. package/dist/{chunk-8drvzsk1.js → chunk-fg5ve6ey.js} +2 -2
  73. package/dist/{chunk-3kmhv1kf.js → chunk-fnt1q1sp.js} +11 -11
  74. package/dist/chunk-g67gg66e.js +2 -0
  75. package/dist/chunk-gq16fxc2.js +2 -0
  76. package/dist/{chunk-4e101kjp.js → chunk-h3c7z73m.js} +2 -2
  77. package/dist/chunk-h4avjh3q.js +2 -0
  78. package/dist/chunk-h7qte7ye.js +2 -0
  79. package/dist/{chunk-4mew0ae3.js → chunk-hb9gxad0.js} +3 -3
  80. package/dist/{chunk-0y7x0hvr.js → chunk-hg4k3nkr.js} +1 -1
  81. package/dist/{chunk-dhxbjw6k.js → chunk-hnep9jbj.js} +2 -2
  82. package/dist/chunk-hwycbxg7.js +2 -0
  83. package/dist/{chunk-34gy5zjm.js → chunk-j1q65enz.js} +2 -2
  84. package/dist/chunk-j5myfxe8.js +18 -0
  85. package/dist/{chunk-8jqy69td.js → chunk-j7zywbq0.js} +2 -2
  86. package/dist/{chunk-32y3767j.js → chunk-jbrdebzs.js} +7 -7
  87. package/dist/{chunk-1336h4sv.js → chunk-jj4pyeyj.js} +1 -1
  88. package/dist/{chunk-g1fxmp9z.js → chunk-k8sqs7j2.js} +4 -4
  89. package/dist/chunk-mg7jhx5v.js +2 -0
  90. package/dist/chunk-n16wa755.js +2 -0
  91. package/dist/chunk-ngv1c807.js +2 -0
  92. package/dist/{chunk-krr2vb0s.js → chunk-p2x7tjbt.js} +3 -3
  93. package/dist/{chunk-62r4fa4q.js → chunk-ptjqacjd.js} +2 -2
  94. package/dist/{chunk-rj3hyqff.js → chunk-qm1tt8g1.js} +2334 -2334
  95. package/dist/chunk-r7r5h2eh.js +2 -0
  96. package/dist/chunk-rhkx17d9.js +2 -0
  97. package/dist/{chunk-b1fg9vg7.js → chunk-s28eh0jn.js} +2 -2
  98. package/dist/{chunk-10967rws.js → chunk-s295vp9x.js} +3 -3
  99. package/dist/chunk-sazpw71r.js +4 -0
  100. package/dist/{chunk-20tdz0zs.js → chunk-sbdzqqr1.js} +6 -6
  101. package/dist/{chunk-qby6wxat.js → chunk-spx27cs4.js} +2 -2
  102. package/dist/{chunk-m16h8ea0.js → chunk-stxmwytg.js} +2 -2
  103. package/dist/{chunk-2tfe2g58.js → chunk-t3wh1jbk.js} +6 -6
  104. package/dist/{chunk-802pr252.js → chunk-tfexmdkt.js} +2 -2
  105. package/dist/{chunk-6aqcgrhw.js → chunk-tfz95n7j.js} +5 -5
  106. package/dist/chunk-thdbqsxq.js +2 -0
  107. package/dist/chunk-tpnfcb83.js +2 -0
  108. package/dist/chunk-tqkv4th9.js +2 -0
  109. package/dist/chunk-tznejj9h.js +2 -0
  110. package/dist/{chunk-ap6fehea.js → chunk-vfk725vm.js} +5 -5
  111. package/dist/chunk-vsrm9k7p.js +2 -0
  112. package/dist/chunk-vwms759h.js +2 -0
  113. package/dist/{chunk-xvzxrt9a.js → chunk-w2085fwx.js} +5 -5
  114. package/dist/chunk-w252cgnv.js +30 -0
  115. package/dist/chunk-whdw6dhb.js +2 -0
  116. package/dist/chunk-wtms9jhs.js +3 -0
  117. package/dist/chunk-wtqjfar3.js +2 -0
  118. package/dist/chunk-wx7kfet5.js +2 -0
  119. package/dist/chunk-wy873fy8.js +2 -0
  120. package/dist/{chunk-a4r19yxm.js → chunk-xa3wsmt5.js} +11 -11
  121. package/dist/chunk-xrbqf77j.js +2 -0
  122. package/dist/{chunk-757ec865.js → chunk-yaebdyfr.js} +2 -2
  123. package/dist/chunk-ycpq3gxc.js +2 -0
  124. package/dist/chunk-yd50awqp.js +3 -0
  125. package/dist/{chunk-csjw5esc.js → chunk-ydz7w2mt.js} +2 -2
  126. package/dist/chunk-yjgbxf26.js +2 -0
  127. package/dist/{chunk-jjnfj9nf.js → chunk-yqsza22w.js} +2 -2
  128. package/dist/{chunk-8j8k27xb.js → chunk-zbr333kf.js} +115 -31
  129. package/dist/chunk-zcyjdcpx.js +33 -0
  130. package/dist/{chunk-tqnysw0k.js → chunk-zfzcedw4.js} +4 -4
  131. package/dist/chunk-zm73n103.js +2 -0
  132. package/dist/cli.js +21 -21
  133. package/dist/component-renderer.js +54 -2
  134. package/dist/composables/use-outbox.d.ts +1 -0
  135. package/dist/composables/use-outbox.js +14 -4
  136. package/dist/craft-entry.js +2 -2
  137. package/dist/craft.js +2 -2
  138. package/dist/database.js +2 -2
  139. package/dist/native/bridge/protocol.d.ts +5 -0
  140. package/dist/native/bridge/protocol.js +3 -0
  141. package/dist/native/cli.js +12 -2
  142. package/dist/native/compiler/bundle.d.ts +4 -3
  143. package/dist/native/compiler/bundle.js +46 -51
  144. package/dist/native/compiler/component-mapping.d.ts +5 -0
  145. package/dist/native/compiler/component-mapping.js +90 -0
  146. package/dist/native/compiler/html-to-ir.js +42 -6
  147. package/dist/native/compiler/ir.d.ts +2 -0
  148. package/dist/native/compiler/render-screen.d.ts +4 -0
  149. package/dist/native/compiler/render-screen.js +10 -2
  150. package/dist/native/compiler/setup-script.d.ts +6 -0
  151. package/dist/native/compiler/setup-script.js +10 -0
  152. package/dist/native/components/primitives.d.ts +10 -0
  153. package/dist/native/index.d.ts +6 -24
  154. package/dist/native/index.js +1 -17
  155. package/dist/native/primitives/Button.stx +2 -1
  156. package/dist/native/primitives/Text.stx +2 -1
  157. package/dist/native/primitives/TextInput.stx +3 -1
  158. package/dist/native/prop-names.d.ts +2 -0
  159. package/dist/native/prop-names.js +71 -0
  160. package/dist/native/runtime/binding-tree.d.ts +31 -0
  161. package/dist/native/runtime/binding-tree.js +100 -0
  162. package/dist/native/runtime/craft-bridge.d.ts +9 -0
  163. package/dist/native/runtime/craft-bridge.js +231 -0
  164. package/dist/native/runtime/craft.d.ts +28 -3
  165. package/dist/native/runtime/jsc-globals.d.ts +16 -0
  166. package/dist/native/runtime/jsc-globals.js +64 -0
  167. package/dist/native/runtime/native-host.d.ts +3 -1
  168. package/dist/native/runtime/native-host.js +183 -33
  169. package/dist/native/runtime/shared-screen.d.ts +15 -0
  170. package/dist/native/runtime/shared-screen.js +41 -0
  171. package/dist/pwa.js +3 -3
  172. package/dist/signal-processing.d.ts +3 -1
  173. package/dist/signal-processing.js +4 -3
  174. package/dist/signals.js +104 -20
  175. package/dist/ssg.js +28 -28
  176. package/dist/variable-extractor.js +4 -1
  177. package/package.json +5 -5
  178. package/dist/chunk-0n76c3g8.js +0 -2
  179. package/dist/chunk-10fh9qhe.js +0 -2
  180. package/dist/chunk-18awnp9d.js +0 -2
  181. package/dist/chunk-2hswgxpb.js +0 -2
  182. package/dist/chunk-3zye6eh1.js +0 -2
  183. package/dist/chunk-4488r5j1.js +0 -2
  184. package/dist/chunk-4amznxaq.js +0 -2
  185. package/dist/chunk-5akd7qsb.js +0 -2
  186. package/dist/chunk-5eqd40k0.js +0 -2
  187. package/dist/chunk-6r9y4p81.js +0 -2
  188. package/dist/chunk-75zcwcrt.js +0 -2
  189. package/dist/chunk-89e1d0rz.js +0 -4
  190. package/dist/chunk-8nsqac4z.js +0 -2
  191. package/dist/chunk-8ttvazck.js +0 -2
  192. package/dist/chunk-8y4bqsxz.js +0 -2
  193. package/dist/chunk-ac033b93.js +0 -2
  194. package/dist/chunk-aj43359g.js +0 -2
  195. package/dist/chunk-aj8yq228.js +0 -2
  196. package/dist/chunk-as72dvvm.js +0 -2
  197. package/dist/chunk-awtrcb5m.js +0 -18
  198. package/dist/chunk-b01jqb5f.js +0 -2
  199. package/dist/chunk-b7z2yegr.js +0 -2
  200. package/dist/chunk-bfvaxrq0.js +0 -2
  201. package/dist/chunk-bkaw7sgz.js +0 -2
  202. package/dist/chunk-bmk0s261.js +0 -2
  203. package/dist/chunk-bvbank3z.js +0 -2
  204. package/dist/chunk-cvzkbsds.js +0 -2
  205. package/dist/chunk-cw6j75ck.js +0 -30
  206. package/dist/chunk-d2c5727w.js +0 -2
  207. package/dist/chunk-d5amzers.js +0 -2
  208. package/dist/chunk-dfchrqw5.js +0 -2
  209. package/dist/chunk-dscsvkfa.js +0 -2
  210. package/dist/chunk-eav0pt6d.js +0 -2
  211. package/dist/chunk-hahzjyxc.js +0 -2
  212. package/dist/chunk-hgqcqg1h.js +0 -2
  213. package/dist/chunk-hjdwf9gp.js +0 -2
  214. package/dist/chunk-jjm0ekw8.js +0 -2
  215. package/dist/chunk-jjtzm6dn.js +0 -3
  216. package/dist/chunk-k1am0dyg.js +0 -2
  217. package/dist/chunk-m2jphkdv.js +0 -2
  218. package/dist/chunk-mk7b3qdz.js +0 -2
  219. package/dist/chunk-ncvfjcr2.js +0 -2
  220. package/dist/chunk-p083sckk.js +0 -2
  221. package/dist/chunk-p7b17yr0.js +0 -2
  222. package/dist/chunk-pc178389.js +0 -2
  223. package/dist/chunk-q1v0jwr4.js +0 -2
  224. package/dist/chunk-r5gjb55x.js +0 -2
  225. package/dist/chunk-rj8rdd8n.js +0 -2
  226. package/dist/chunk-s0pmn48x.js +0 -2
  227. package/dist/chunk-s58yz9q0.js +0 -2
  228. package/dist/chunk-srdzwtsq.js +0 -2
  229. package/dist/chunk-tf44jyrh.js +0 -2
  230. package/dist/chunk-tfypkw4y.js +0 -3
  231. package/dist/chunk-vwxasbtx.js +0 -2
  232. package/dist/chunk-wynvh7dc.js +0 -2
  233. package/dist/chunk-x8rckpyz.js +0 -2
  234. package/dist/chunk-y4xs4m7p.js +0 -2
  235. package/dist/chunk-y8rpk1b9.js +0 -2
  236. package/dist/chunk-y9m93qkk.js +0 -2
  237. package/dist/chunk-ya0qecph.js +0 -27
  238. package/dist/chunk-ya9c8nec.js +0 -2
  239. package/dist/chunk-yvq1f313.js +0 -2
  240. package/dist/chunk-yy3dgwfm.js +0 -2
  241. package/dist/chunk-zpcz2kh6.js +0 -2
  242. package/dist/native/compiler/codegen.d.ts +0 -10
  243. package/dist/native/compiler/codegen.js +0 -145
  244. package/dist/native/compiler/parser.d.ts +0 -88
  245. package/dist/native/compiler/parser.js +0 -753
  246. package/dist/native/runtime/entry.d.ts +0 -1
  247. package/dist/native/runtime/entry.js +0 -3
  248. package/dist/native/runtime/index.d.ts +0 -45
  249. package/dist/native/runtime/index.js +0 -165
  250. package/dist/native/runtime/screen.d.ts +0 -43
  251. package/dist/native/runtime/screen.js +0 -808
@@ -1,7 +1,10 @@
1
+ import { nativePropName } from "../prop-names.js";
2
+ import { cloneNativeBindingNode } from "./binding-tree.js";
1
3
  export const HOST_METHODS = [
2
4
  "setText",
3
5
  "setAttribute",
4
6
  "removeAttribute",
7
+ "setStyle",
5
8
  "listen",
6
9
  "scopeOf",
7
10
  "setVisible",
@@ -12,6 +15,21 @@ export const HOST_METHODS = [
12
15
  "descendants",
13
16
  "scopesIn"
14
17
  ];
18
+ const NATIVE_EVENT_NAMES = {
19
+ click: "onPress",
20
+ press: "onPress",
21
+ longpress: "onLongPress",
22
+ contextmenu: "onLongPress",
23
+ input: "onChangeText",
24
+ change: "onValueChange",
25
+ focus: "onFocus",
26
+ focusin: "onFocus",
27
+ blur: "onBlur",
28
+ focusout: "onBlur",
29
+ submit: "onSubmitEditing",
30
+ scroll: "onScroll",
31
+ close: "onRequestClose"
32
+ };
15
33
  export function createNativeHost(options) {
16
34
  const records = new Map, handlers = new Map;
17
35
  let queue = [], scheduled = !1, counter = 0;
@@ -34,11 +52,52 @@ export function createNativeHost(options) {
34
52
  function recordOf(node) {
35
53
  let record = records.get(node.__stxId);
36
54
  if (!record) {
37
- record = { type: "View", props: {}, style: {}, events: {}, children: [], visible: !0 };
55
+ record = { type: "View", props: {}, style: {}, events: {}, children: [], visible: !0, materialized: !0 };
38
56
  records.set(node.__stxId, record);
39
57
  }
40
58
  return record;
41
59
  }
60
+ function descriptorOf(node) {
61
+ return records.get(node.__stxId) ?? node.__stxDetachedRecord;
62
+ }
63
+ function retainDetachedDescriptors(node) {
64
+ const record = records.get(node.__stxId);
65
+ if (!record)
66
+ return;
67
+ node.__stxDetachedRecord = record;
68
+ record.children.forEach(retainDetachedDescriptors);
69
+ records.delete(node.__stxId);
70
+ }
71
+ function releaseHandlers(node) {
72
+ const record = descriptorOf(node);
73
+ if (!record)
74
+ return;
75
+ Object.values(record.events).forEach((handlerId) => handlers.delete(handlerId));
76
+ record.children.forEach(releaseHandlers);
77
+ }
78
+ function materialize(node) {
79
+ const record = recordOf(node);
80
+ if (record.materialized || node.__stxAnchor !== void 0)
81
+ return;
82
+ record.materialized = !0;
83
+ emit({
84
+ op: "createNode",
85
+ id: node.__stxId,
86
+ node: {
87
+ type: record.type,
88
+ props: { ...record.props },
89
+ style: { ...record.style },
90
+ ...record.text === void 0 ? {} : { children: [record.text] }
91
+ }
92
+ });
93
+ let index = 0;
94
+ for (const child of record.children) {
95
+ if (child.__stxAnchor !== void 0)
96
+ continue;
97
+ materialize(child);
98
+ emit({ op: "insertChild", parentId: node.__stxId, childId: child.__stxId, index: index++ });
99
+ }
100
+ }
42
101
  function collectDescendants(node) {
43
102
  const out = [], visit = (current) => {
44
103
  const record = records.get(current.__stxId);
@@ -53,16 +112,79 @@ export function createNativeHost(options) {
53
112
  visit(node);
54
113
  return out;
55
114
  }
56
- function adopt(node, type, owner) {
115
+ function isBindingNode(node) {
116
+ return node.nodeType === 1;
117
+ }
118
+ function decoratePosition(node) {
119
+ const target = node;
120
+ if (target.__stxPositionDecorated)
121
+ return;
122
+ Object.defineProperties(target, {
123
+ nextSibling: {
124
+ configurable: !0,
125
+ get() {
126
+ const owner = target.__stxOwner;
127
+ if (!owner)
128
+ return null;
129
+ const siblings = recordOf(owner).children, index = siblings.findIndex((candidate) => candidate.__stxId === target.__stxId);
130
+ return index === -1 ? null : siblings[index + 1] ?? null;
131
+ }
132
+ },
133
+ nextElementSibling: {
134
+ configurable: !0,
135
+ get() {
136
+ let sibling = target.nextSibling;
137
+ while (sibling && !isBindingNode(sibling))
138
+ sibling = sibling.nextSibling;
139
+ return sibling;
140
+ }
141
+ }
142
+ });
143
+ target.__stxPositionDecorated = !0;
144
+ }
145
+ function setConnected(node, connected) {
146
+ if ("isConnected" in node)
147
+ node.isConnected = connected;
148
+ records.get(node.__stxId)?.children.forEach((child) => setConnected(child, connected));
149
+ }
150
+ function removeFromBindingParent(node) {
151
+ const owner = node.__stxOwner;
152
+ if (!owner || !isBindingNode(owner))
153
+ return;
154
+ owner.childNodes = owner.childNodes.filter((child) => child.__stxId !== node.__stxId);
155
+ owner.children = owner.children.filter((child) => child.__stxId !== node.__stxId);
156
+ }
157
+ function insertIntoBindingParent(parent, node, index) {
158
+ if (!isBindingNode(parent))
159
+ return;
160
+ parent.childNodes.splice(index, 0, node);
161
+ parent.children.splice(index, 0, node);
162
+ if (isBindingNode(node)) {
163
+ node.parentNode = parent;
164
+ node.parentElement = parent;
165
+ }
166
+ }
167
+ function adopt(node, type, owner, descriptor) {
168
+ const suffix = /(?:^|\D)(\d+)$/.exec(node.__stxId)?.[1];
169
+ if (suffix)
170
+ counter = Math.max(counter, Number(suffix));
57
171
  records.set(node.__stxId, {
58
172
  type,
59
- props: {},
60
- style: {},
61
- events: {},
173
+ props: { ...descriptor?.props ?? {} },
174
+ style: { ...descriptor?.style ?? {} },
175
+ events: { ...descriptor?.events ?? {} },
176
+ text: descriptor?.children?.find((child) => typeof child === "string"),
62
177
  children: [],
63
- visible: !0
178
+ visible: !0,
179
+ materialized: !0
64
180
  });
181
+ decoratePosition(node);
65
182
  node.__stxOwner = owner ?? null;
183
+ if (owner) {
184
+ const children = recordOf(owner).children;
185
+ if (!children.some((child) => child.__stxId === node.__stxId))
186
+ children.push(node);
187
+ }
66
188
  return node;
67
189
  }
68
190
  return {
@@ -75,18 +197,27 @@ export function createNativeHost(options) {
75
197
  emit({ op: "updateNode", id: node.__stxId, patch: { children: [text] } });
76
198
  },
77
199
  setAttribute(node, name, value) {
78
- recordOf(node).props[name] = value;
79
- emit({ op: "updateNode", id: node.__stxId, patch: { props: { [name]: value } } });
200
+ const prop = nativePropName(name);
201
+ recordOf(node).props[prop] = value;
202
+ emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: value } } });
80
203
  },
81
204
  removeAttribute(node, name) {
82
- delete recordOf(node).props[name];
83
- emit({ op: "updateNode", id: node.__stxId, patch: { props: { [name]: null } } });
205
+ const prop = nativePropName(name);
206
+ delete recordOf(node).props[prop];
207
+ emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: null } } });
208
+ },
209
+ setStyle(node, value) {
210
+ if (typeof value !== "object" || value === null || Array.isArray(value))
211
+ return;
212
+ const style = value;
213
+ Object.assign(recordOf(node).style, style);
214
+ emit({ op: "updateNode", id: node.__stxId, patch: { style } });
84
215
  },
85
216
  listen(node, event, handler) {
86
- const id = nextId("h");
217
+ const id = nextId("h"), nativeEvent = NATIVE_EVENT_NAMES[event.toLowerCase()] ?? event;
87
218
  handlers.set(id, handler);
88
- recordOf(node).events[event] = id;
89
- emit({ op: "updateNode", id: node.__stxId, patch: { events: { [event]: id } } });
219
+ recordOf(node).events[nativeEvent] = id;
220
+ emit({ op: "updateNode", id: node.__stxId, patch: { events: { [nativeEvent]: id } } });
90
221
  },
91
222
  dispatch(handlerId, payload) {
92
223
  handlers.get(handlerId)?.(payload);
@@ -107,32 +238,35 @@ export function createNativeHost(options) {
107
238
  return was;
108
239
  },
109
240
  anchor(label) {
110
- return { __stxId: nextId("a"), __stxAnchor: label };
241
+ const anchor = { __stxId: nextId("a"), __stxAnchor: label };
242
+ decoratePosition(anchor);
243
+ return anchor;
111
244
  },
112
245
  clone(node) {
113
- const source = records.get(node.__stxId), copy = { __stxId: nextId("n"), __stxOwner: node.__stxOwner };
246
+ const source = descriptorOf(node), id = nextId("n"), copy = isBindingNode(node) ? cloneNativeBindingNode(node, id) : { __stxId: id, __stxOwner: node.__stxOwner };
247
+ decoratePosition(copy);
114
248
  if (node.__stxScope !== void 0)
115
249
  copy.__stxScope = node.__stxScope;
116
- const descriptor = source ?? { type: "View", props: {}, style: {}, events: {}, children: [], visible: !0 };
250
+ const descriptor = source ?? {
251
+ type: "View",
252
+ props: {},
253
+ style: {},
254
+ events: {},
255
+ children: [],
256
+ visible: !0,
257
+ materialized: !0
258
+ };
117
259
  records.set(copy.__stxId, {
118
260
  type: descriptor.type,
119
- props: { ...descriptor.props },
261
+ props: { ...descriptor.props, __stxId: copy.__stxId },
120
262
  style: { ...descriptor.style },
121
263
  events: { ...descriptor.events },
122
264
  text: descriptor.text,
123
265
  children: [],
124
- visible: descriptor.visible
125
- });
126
- emit({
127
- op: "createNode",
128
- id: copy.__stxId,
129
- node: {
130
- type: descriptor.type,
131
- props: { ...descriptor.props },
132
- style: { ...descriptor.style },
133
- ...descriptor.text === void 0 ? {} : { children: [descriptor.text] }
134
- }
266
+ visible: descriptor.visible,
267
+ materialized: !1
135
268
  });
269
+ setConnected(copy, !1);
136
270
  for (const child of descriptor.children) {
137
271
  const childCopy = this.clone(child);
138
272
  this.insert(copy, childCopy);
@@ -140,14 +274,23 @@ export function createNativeHost(options) {
140
274
  return copy;
141
275
  },
142
276
  insert(parent, node, before) {
143
- const record = recordOf(parent), existing = record.children.findIndex((child) => child.__stxId === node.__stxId);
277
+ const record = recordOf(parent), oldOwner = node.__stxOwner, existing = record.children.findIndex((child) => child.__stxId === node.__stxId);
144
278
  if (existing !== -1)
145
279
  record.children.splice(existing, 1);
280
+ else if (oldOwner) {
281
+ const oldRecord = recordOf(oldOwner), oldIndex = oldRecord.children.findIndex((child) => child.__stxId === node.__stxId);
282
+ if (oldIndex !== -1)
283
+ oldRecord.children.splice(oldIndex, 1);
284
+ }
285
+ removeFromBindingParent(node);
146
286
  const index = before ? Math.max(0, record.children.findIndex((child) => child.__stxId === before.__stxId)) : record.children.length;
147
287
  record.children.splice(index, 0, node);
148
288
  node.__stxOwner = parent;
149
- if (node.__stxAnchor !== void 0)
289
+ insertIntoBindingParent(parent, node, index);
290
+ setConnected(node, record.materialized);
291
+ if (node.__stxAnchor !== void 0 || !record.materialized)
150
292
  return;
293
+ materialize(node);
151
294
  emit({
152
295
  op: existing === -1 ? "insertChild" : "moveChild",
153
296
  parentId: parent.__stxId,
@@ -168,15 +311,22 @@ export function createNativeHost(options) {
168
311
  return ids;
169
312
  },
170
313
  remove(node) {
171
- const owner = node.__stxOwner;
314
+ const wasMaterialized = descriptorOf(node)?.materialized === !0, owner = node.__stxOwner;
172
315
  if (owner) {
173
316
  const record = recordOf(owner), at = record.children.findIndex((child) => child.__stxId === node.__stxId);
174
317
  if (at !== -1)
175
318
  record.children.splice(at, 1);
176
319
  }
320
+ removeFromBindingParent(node);
177
321
  node.__stxOwner = null;
178
- records.delete(node.__stxId);
179
- if (node.__stxAnchor !== void 0)
322
+ if (isBindingNode(node)) {
323
+ node.parentNode = null;
324
+ node.parentElement = null;
325
+ }
326
+ setConnected(node, !1);
327
+ releaseHandlers(node);
328
+ retainDetachedDescriptors(node);
329
+ if (node.__stxAnchor !== void 0 || !wasMaterialized)
180
330
  return;
181
331
  emit({ op: "removeNode", id: node.__stxId });
182
332
  }
@@ -0,0 +1,15 @@
1
+ import { type CraftBridgeOptions } from './craft-bridge';
2
+ import { type NativeHost } from './native-host';
3
+ import type { BindingManifest } from '../../binding-manifest';
4
+ import type { NativeBridgeInterface } from '../bridge/protocol';
5
+ import type { STXDocument } from '../compiler/ir';
6
+ /** Connect translated IR to the ordinary stx signals runtime and native bridge. */
7
+ export declare function prepareSharedNativeScreen(document: STXDocument, manifest: BindingManifest, bridge: NativeBridgeInterface, options?: CraftBridgeOptions): SharedNativeScreen;
8
+ declare interface SharedSignalsRuntime {
9
+ hydrateHost: (root: unknown, setup: (() => Record<string, unknown>) | Record<string, unknown> | null, manifest: BindingManifest, nodes: Map<number, unknown>) => (() => void)
10
+ }
11
+ export declare interface SharedNativeScreen {
12
+ host: NativeHost
13
+ mount: (runtime: SharedSignalsRuntime, setup: (() => Record<string, unknown>) | null) => void
14
+ unmount: () => void
15
+ }
@@ -0,0 +1,41 @@
1
+ import { STXBridge } from "../bridge/protocol.js";
2
+ import { materializeNativeBindingTree } from "./binding-tree.js";
3
+ import { installCraftBridge } from "./craft-bridge.js";
4
+ import { createNativeHost } from "./native-host.js";
5
+ export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
6
+ let revision = 0;
7
+ const protocol = new STXBridge;
8
+ protocol.initialize(bridge);
9
+ installCraftBridge(protocol, bridge, globalThis, options);
10
+ const host = createNativeHost({
11
+ send(operations) {
12
+ const baseRevision = revision;
13
+ revision++;
14
+ protocol.mutate({
15
+ version: 1,
16
+ batchId: `mutation_${revision}`,
17
+ baseRevision,
18
+ revision,
19
+ operations
20
+ });
21
+ }
22
+ }), tree = materializeNativeBindingTree(document, manifest, host);
23
+ let dispose = null;
24
+ protocol.on("EVENT", (message) => {
25
+ const handlerId = message.payload?.handlerId ?? message.payload?.handlerName;
26
+ if (typeof handlerId === "string")
27
+ host.dispatch(handlerId, message.payload?.nativeEvent);
28
+ });
29
+ return {
30
+ host,
31
+ mount(runtime, setup) {
32
+ dispose?.();
33
+ protocol.render(document.root);
34
+ dispose = runtime.hydrateHost(tree.root, setup, manifest, tree.nodes);
35
+ },
36
+ unmount() {
37
+ dispose?.();
38
+ dispose = null;
39
+ }
40
+ };
41
+ }
package/dist/pwa.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{An,Pe,Ti,Ra}from"./chunk-kjkwycce.js";import{Rn,Nr,Ea,Ta,_a}from"./chunk-20tdz0zs.js";import{Ci,$i,Ei,Ca,$a}from"./chunk-wg1ttvs5.js";import{ie,dt,Lr}from"./chunk-krr2vb0s.js";import{Ic,Dc,Oc,Mc,or,Qu}from"./chunk-dhxbjw6k.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-3zye6eh1.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>
2
+ import{An,Ie,Ai,Da}from"./chunk-0bmc75w6.js";import{Rn,jr,Aa,Pa,Ia}from"./chunk-sbdzqqr1.js";import{Ti,_i,Ri,_a,Ra}from"./chunk-cznsm2n3.js";import{ie,pt,Br}from"./chunk-p2x7tjbt.js";import{Mc,Nc,Lc,jc,cr,nd}from"./chunk-hnep9jbj.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-d1qzhawc.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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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=ie(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=An(n,t);if(a){let s=Pe(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 Nr(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,$i as auditBuildOutput,Ci as auditConfig,re as buildPwaAssets,Ei as calculateAuditResult,$a as formatAuditResult,Lr as formatSize,j as generateManifest,_ as generateManifestJson,Ta as generateManifestLink,F as generateOfflinePage,ie as generatePrecacheManifest,dt as generatePrecacheManifestJs,M as generatePwaIcons,Rn as generatePwaTags,An as generateServiceWorker,Ra as generateServiceWorkerAuto,Ea as generateSwRegistrationScript,_a as generateThemeColorMeta,N as getExpectedIconPaths,Pe as getServiceWorkerFileName,Nr as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Ti as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,or as pwaDirectives,Ic as pwaInstallDirective,Oc as pwaOfflineDirective,Mc as pwaPushDirective,Dc as pwaUpdateDirective,Qu as registerPwaDirectives,Ca as runPwaAudit,D as validateManifest};
236
+ </html>`}function b(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}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=ie(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=An(n,t);if(a){let s=Ie(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 jr(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,_i as auditBuildOutput,Ti as auditConfig,re as buildPwaAssets,Ri as calculateAuditResult,Ra as formatAuditResult,Br as formatSize,j as generateManifest,_ as generateManifestJson,Pa as generateManifestLink,F as generateOfflinePage,ie as generatePrecacheManifest,pt as generatePrecacheManifestJs,M as generatePwaIcons,Rn as generatePwaTags,An as generateServiceWorker,Da as generateServiceWorkerAuto,Aa as generateSwRegistrationScript,Ia as generateThemeColorMeta,N as getExpectedIconPaths,Ie as getServiceWorkerFileName,jr as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Ai as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,cr as pwaDirectives,Mc as pwaInstallDirective,Lc as pwaOfflineDirective,jc as pwaPushDirective,Nc as pwaUpdateDirective,nd as registerPwaDirectives,_a as runPwaAudit,D as validateManifest};
@@ -176,7 +176,9 @@ export declare function preEvalLiteralReactiveIfs(template: string): string;
176
176
  */
177
177
  export declare function convertServerLoopAttributesToDirectives(template: string, context?: Record<string, any>): string;
178
178
  export declare function convertSignalLoopsToAttributes(template: string, context?: Record<string, any>): string;
179
- export declare function processScriptSetup(template: string, filePath?: string, serverData?: Record<string, unknown>): Promise<{
179
+ export declare function processScriptSetup(template: string, filePath?: string, serverData?: Record<string, unknown>, options?: {
180
+ forceClientSetup?: boolean;
181
+ }): Promise<{
180
182
  output: string;
181
183
  setupCode: string | null;
182
184
  }>;
@@ -806,7 +806,7 @@ function rebuildSetupOwner(template, ranges, markerAt, setupFnName) {
806
806
  appendThrough(template.length);
807
807
  return chunks.join("");
808
808
  }
809
- export async function processScriptSetup(template, filePath, serverData) {
809
+ export async function processScriptSetup(template, filePath, serverData, options = {}) {
810
810
  const scripts = scanScriptTags(template, {
811
811
  skipAttrs: /\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b/
812
812
  }), SIGNAL_API_RE = /\b(?:state|derived|effect|ref|reactive|computed|watch|watchEffect|useStore|useLocalStorage|useSessionStorage|keptState|useCookie|useId|useModel|useReactiveProp|useFetch|useRef|useEventListener|useDebounce|useDebouncedValue|useThrottle|useInterval|useTimeout|useToggle|useCounter|useClickOutside|useFocus|useAsync|useColorMode|useDark|useMediaQuery|useScrollLock|usePreferredDark|usePreferredLight|usePreferredReducedMotion|usePreferredContrast|useWebSocket|useRoute|useSearchParams|onMount|onDestroy|defineProps|withDefaults|defineEmits|defineExpose|defineSlots|useOptimistic)\s*(?:<[^>]*>)?\s*\(/, signalScripts = [], { hasUserImports, bundleClientScript } = await importOnce("stx/client-script-bundler", () => import("./client-script-bundler.js"));
@@ -814,7 +814,7 @@ export async function processScriptSetup(template, filePath, serverData) {
814
814
  let content = s.body;
815
815
  if (shouldTranspileTypeScript(s.attrs))
816
816
  content = transpileTypeScript(content);
817
- if (SIGNAL_API_RE.test(content)) {
817
+ if (options.forceClientSetup || SIGNAL_API_RE.test(content)) {
818
818
  signalScripts.push({ content, start: s.start, end: s.end });
819
819
  continue;
820
820
  }
@@ -836,7 +836,8 @@ export async function processScriptSetup(template, filePath, serverData) {
836
836
  let scriptContent = signalScripts[i].bundled ?? injectBrowserCoreAutoImports(signalScripts[i].content).code;
837
837
  if (!signalScripts[i].bundled && hasUserImports(scriptContent))
838
838
  scriptContent = await bundleClientScript(scriptContent, filePath || "", {
839
- projectRoot: process.cwd()
839
+ projectRoot: process.cwd(),
840
+ externalizeUserModules: options.forceClientSetup ? !1 : void 0
840
841
  });
841
842
  scriptContent = stripStxRuntimeImports(scriptContent);
842
843
  const resolved = transformStoreImports(scriptContent);