@stacksjs/stx 0.2.583 → 0.2.584

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 (241) hide show
  1. package/dist/{chunk-ck1yca7g.js → chunk-03qf2z4d.js} +1 -1
  2. package/dist/{chunk-hp9nxva6.js → chunk-07869zev.js} +4 -4
  3. package/dist/chunk-08g5j4fq.js +2 -0
  4. package/dist/chunk-0hpw65yr.js +2 -0
  5. package/dist/chunk-11jmasqb.js +2 -0
  6. package/dist/chunk-2c7ysn9s.js +2 -0
  7. package/dist/chunk-2wb1w0p6.js +2 -0
  8. package/dist/chunk-2wx2aczp.js +2 -0
  9. package/dist/chunk-325dn55d.js +4 -0
  10. package/dist/chunk-34kxj258.js +2 -0
  11. package/dist/{chunk-ktyctev3.js → chunk-3y5tzxm6.js} +2 -2
  12. package/dist/{chunk-h0a2s340.js → chunk-49xtxzr8.js} +2 -2
  13. package/dist/chunk-4efqcpg5.js +2 -0
  14. package/dist/{chunk-5kh5ehfh.js → chunk-4h58as2c.js} +2 -2
  15. package/dist/chunk-4k6h00kk.js +2 -0
  16. package/dist/{chunk-ky1426s1.js → chunk-4myvw20e.js} +10 -10
  17. package/dist/chunk-4szz2esp.js +2 -0
  18. package/dist/chunk-4wkghwag.js +2 -0
  19. package/dist/chunk-53grq69s.js +2 -0
  20. package/dist/chunk-55n8mhq4.js +2 -0
  21. package/dist/chunk-5s229r1e.js +2 -0
  22. package/dist/{chunk-521pe0hb.js → chunk-5zg3xj45.js} +4 -4
  23. package/dist/{chunk-ye66wc53.js → chunk-67m2prah.js} +2 -2
  24. package/dist/chunk-6djvj6hg.js +2 -0
  25. package/dist/chunk-6ebj7gfr.js +2 -0
  26. package/dist/{chunk-4pmgr32a.js → chunk-6hgngmn0.js} +3 -3
  27. package/dist/chunk-71tnfe1n.js +2 -0
  28. package/dist/{chunk-mjj24qpb.js → chunk-794v5crp.js} +2 -2
  29. package/dist/chunk-7dkwf9h5.js +2 -0
  30. package/dist/{chunk-cnknvvwm.js → chunk-7fghm9zy.js} +1 -1
  31. package/dist/{chunk-02qaqamv.js → chunk-7ra30crf.js} +7 -7
  32. package/dist/{chunk-117xss52.js → chunk-7xw1e8t6.js} +2 -2
  33. package/dist/{chunk-w6wtxj54.js → chunk-7ydavm3h.js} +2 -2
  34. package/dist/{chunk-qdyp2zqf.js → chunk-82bttwqm.js} +2 -2
  35. package/dist/chunk-8992smwz.js +2 -0
  36. package/dist/{chunk-qn8gdw21.js → chunk-8s7zbhdd.js} +4 -4
  37. package/dist/chunk-8zn83jfs.js +2 -0
  38. package/dist/{chunk-h3z9b6bw.js → chunk-96zgn94z.js} +11 -11
  39. package/dist/{chunk-6m3me7yj.js → chunk-9cpxzze0.js} +9 -9
  40. package/dist/{chunk-6fc8vw2v.js → chunk-9e091vkf.js} +3 -3
  41. package/dist/chunk-9pk5jhqa.js +3 -0
  42. package/dist/{chunk-09zwhsf9.js → chunk-9r5w6s80.js} +3 -3
  43. package/dist/{chunk-c0h2eqe0.js → chunk-a8n6mt7s.js} +2 -2
  44. package/dist/{chunk-ac6v3s3k.js → chunk-agy4mxn8.js} +2 -2
  45. package/dist/{chunk-mt9x626h.js → chunk-axz1x4r9.js} +5 -5
  46. package/dist/{chunk-07anexcg.js → chunk-b5van393.js} +2 -2
  47. package/dist/{chunk-w3rmepwy.js → chunk-bfbmdjh4.js} +2 -2
  48. package/dist/chunk-bqtph83n.js +2 -0
  49. package/dist/chunk-bs1bdhvp.js +2 -0
  50. package/dist/{chunk-0k5faspy.js → chunk-bsy10tz6.js} +6 -6
  51. package/dist/chunk-c1c4sh7t.js +2 -0
  52. package/dist/{chunk-dvc15djp.js → chunk-c6egfhy6.js} +2 -2
  53. package/dist/chunk-ce2d0hz9.js +2 -0
  54. package/dist/chunk-cjq9k1xb.js +2 -0
  55. package/dist/{chunk-ym1sb5bg.js → chunk-d2jb1rkp.js} +5 -5
  56. package/dist/{chunk-nhd9m8h5.js → chunk-d4awfk42.js} +6 -6
  57. package/dist/chunk-d9vjsqs4.js +2 -0
  58. package/dist/{chunk-e809x7m0.js → chunk-e26pzdxy.js} +1 -1
  59. package/dist/{chunk-kfwmqacd.js → chunk-e556dvy4.js} +3 -3
  60. package/dist/{chunk-cby4mkjf.js → chunk-e6h7pzym.js} +1 -1
  61. package/dist/{chunk-0dfgefjv.js → chunk-ebfpjnf3.js} +2 -2
  62. package/dist/chunk-ede39b7h.js +3 -0
  63. package/dist/chunk-f0fxyh3e.js +2 -0
  64. package/dist/{chunk-4srg0qbv.js → chunk-f29fk7dw.js} +2 -2
  65. package/dist/chunk-fjyhc41r.js +2 -0
  66. package/dist/{chunk-vke73gts.js → chunk-fkq55rh7.js} +1 -1
  67. package/dist/chunk-fn4wwgnc.js +2 -0
  68. package/dist/{chunk-pbwk8tzz.js → chunk-g8mxprxj.js} +1 -1
  69. package/dist/chunk-h2534p6q.js +2 -0
  70. package/dist/{chunk-2nehykbm.js → chunk-h7atbtds.js} +5 -5
  71. package/dist/{chunk-nh3svtvj.js → chunk-h988fxh3.js} +5 -5
  72. package/dist/chunk-hr34x6sx.js +2 -0
  73. package/dist/{chunk-en7xxgtb.js → chunk-hsy9rhct.js} +2 -2
  74. package/dist/chunk-hygxh993.js +2 -0
  75. package/dist/{chunk-s12bnv32.js → chunk-hz11wmx9.js} +2 -2
  76. package/dist/{chunk-wyn5rfzk.js → chunk-j7kcjgxy.js} +115 -26
  77. package/dist/chunk-j87tntna.js +2 -0
  78. package/dist/{chunk-ycj0342k.js → chunk-jqbk6pfk.js} +2 -2
  79. package/dist/{chunk-vkc51n9m.js → chunk-k1szsenr.js} +2 -2
  80. package/dist/{chunk-xp7fxc6p.js → chunk-k3rnpjxf.js} +5 -5
  81. package/dist/{chunk-sv08pd66.js → chunk-k71e38fk.js} +4 -4
  82. package/dist/chunk-kgtnfvqb.js +2 -0
  83. package/dist/chunk-krwrx9x9.js +2 -0
  84. package/dist/{chunk-je1as16r.js → chunk-m3w67x05.js} +5 -5
  85. package/dist/chunk-m5j8hht5.js +2 -0
  86. package/dist/chunk-mc8j6dwa.js +2 -0
  87. package/dist/{chunk-vpdx7qr3.js → chunk-mmbspaqh.js} +2 -2
  88. package/dist/{chunk-hzqyfdpy.js → chunk-n0t938d2.js} +7 -7
  89. package/dist/{chunk-8tq83fq7.js → chunk-n2gy2arh.js} +57 -57
  90. package/dist/chunk-n2j3pn9s.js +2 -0
  91. package/dist/{chunk-sv5nvfmb.js → chunk-np6nm4rq.js} +2 -2
  92. package/dist/chunk-ns1jqzqk.js +2 -0
  93. package/dist/chunk-p973efbe.js +2 -0
  94. package/dist/{chunk-m8tm44rq.js → chunk-pg164sdw.js} +2 -2
  95. package/dist/{chunk-x552npae.js → chunk-pxw4edw8.js} +4 -4
  96. package/dist/{chunk-1r1maqep.js → chunk-q1cvef6b.js} +3 -3
  97. package/dist/chunk-q765v7b2.js +2 -0
  98. package/dist/{chunk-96mb3brj.js → chunk-qebxzf9w.js} +3 -3
  99. package/dist/{chunk-jpqkm8tm.js → chunk-qf3axv86.js} +3 -3
  100. package/dist/{chunk-dhq80e4r.js → chunk-qhr1tkhj.js} +7 -7
  101. package/dist/chunk-qq59xzwc.js +2 -0
  102. package/dist/chunk-r0e743c3.js +2 -0
  103. package/dist/{chunk-qccgncp2.js → chunk-rdm5mfc5.js} +6 -6
  104. package/dist/chunk-s043hpvd.js +2 -0
  105. package/dist/{chunk-m417sp42.js → chunk-s1ptn02h.js} +3 -3
  106. package/dist/{chunk-g9zeybqh.js → chunk-s5vxxwg6.js} +2 -2
  107. package/dist/chunk-sckze59r.js +2 -0
  108. package/dist/chunk-sjkdpsca.js +3 -0
  109. package/dist/chunk-sr1md7vv.js +2845 -0
  110. package/dist/chunk-t431anrx.js +2 -0
  111. package/dist/chunk-t7mxbt40.js +2 -0
  112. package/dist/{chunk-r47cs92n.js → chunk-tc15vkfh.js} +2 -2
  113. package/dist/{chunk-6z3e1tyz.js → chunk-tnafnb23.js} +1 -1
  114. package/dist/{chunk-ah9xyss2.js → chunk-v8ze2q95.js} +2 -2
  115. package/dist/{chunk-xytkfa48.js → chunk-vf15db1j.js} +6 -6
  116. package/dist/chunk-vvqxbhfx.js +2 -0
  117. package/dist/{chunk-dm1qh2vq.js → chunk-w24qmxc3.js} +3 -3
  118. package/dist/chunk-w7zgftez.js +2 -0
  119. package/dist/chunk-wfp36qf4.js +2 -0
  120. package/dist/chunk-wn2gzwmv.js +2 -0
  121. package/dist/{chunk-wwj8zbzc.js → chunk-wywprjc5.js} +5 -5
  122. package/dist/chunk-x5qymgxa.js +2 -0
  123. package/dist/chunk-xfe2nzxd.js +2 -0
  124. package/dist/chunk-xjwgzp6s.js +2 -0
  125. package/dist/chunk-xyepqdjy.js +2 -0
  126. package/dist/chunk-y5ryjdpv.js +122 -0
  127. package/dist/{chunk-3e3dpp7w.js → chunk-y5x8xnnf.js} +3 -3
  128. package/dist/chunk-yhqaafsw.js +2 -0
  129. package/dist/{chunk-4pkpr5cg.js → chunk-z2mg470f.js} +4 -4
  130. package/dist/chunk-z7trbwn3.js +2 -0
  131. package/dist/{chunk-2943qhdt.js → chunk-zgv1h2np.js} +2 -2
  132. package/dist/{chunk-bj29pwm0.js → chunk-zrw1zf54.js} +3 -3
  133. package/dist/chunk-zxf8f71v.js +2 -0
  134. package/dist/chunk-zxt75k06.js +2 -0
  135. package/dist/cli.js +20 -20
  136. package/dist/client/signals-host-runtime.js +52 -1
  137. package/dist/client/signals-manifest-hydration-runtime.js +13 -0
  138. package/dist/client/signals-overlay-runtime.js +29 -6
  139. package/dist/client/signals-public-api-runtime.js +2 -0
  140. package/dist/client/signals-style-runtime.js +1 -1
  141. package/dist/component-renderer.js +26 -6
  142. package/dist/craft-entry.js +2 -2
  143. package/dist/craft.js +2 -2
  144. package/dist/native/compiler/design-tokens.d.ts +4 -0
  145. package/dist/native/compiler/design-tokens.js +28 -0
  146. package/dist/native/compiler/headwind-to-style.d.ts +5 -4
  147. package/dist/native/compiler/headwind-to-style.js +105 -65
  148. package/dist/native/compiler/html-to-ir.d.ts +3 -1
  149. package/dist/native/compiler/html-to-ir.js +47 -243
  150. package/dist/native/compiler/inline-style.d.ts +13 -0
  151. package/dist/native/compiler/inline-style.js +285 -0
  152. package/dist/native/compiler/ir.d.ts +5 -1
  153. package/dist/native/compiler/render-screen.js +3 -1
  154. package/dist/native/compiler/style-variables.d.ts +8 -0
  155. package/dist/native/compiler/style-variables.js +142 -0
  156. package/dist/native/compiler/stylesheet-theme.d.ts +6 -0
  157. package/dist/native/compiler/stylesheet-theme.js +110 -0
  158. package/dist/native/runtime/craft-bridge.js +3 -1
  159. package/dist/native/runtime/native-host.d.ts +13 -2
  160. package/dist/native/runtime/native-host.js +237 -36
  161. package/dist/native/runtime/overlay-presenter.d.ts +29 -0
  162. package/dist/native/runtime/overlay-presenter.js +69 -0
  163. package/dist/native/runtime/shared-screen.js +12 -1
  164. package/dist/native/runtime/view-operations.d.ts +20 -0
  165. package/dist/native/runtime/view-operations.js +35 -0
  166. package/dist/native/testing-mutations.d.ts +4 -0
  167. package/dist/native/testing-mutations.js +64 -0
  168. package/dist/native/testing.d.ts +2 -0
  169. package/dist/native/testing.js +18 -1
  170. package/dist/pwa.js +3 -3
  171. package/dist/ssg.js +9 -9
  172. package/dist/testing.js +2 -0
  173. package/dist/types/config-types.d.ts +2 -0
  174. package/dist/utils.d.ts +1 -1
  175. package/dist/utils.js +25 -5
  176. package/package.json +5 -5
  177. package/dist/chunk-00p22wzr.js +0 -3
  178. package/dist/chunk-0fx3ppnt.js +0 -2
  179. package/dist/chunk-0sfexf9t.js +0 -2
  180. package/dist/chunk-2927nax9.js +0 -2
  181. package/dist/chunk-2rj0ttas.js +0 -2
  182. package/dist/chunk-2rx9d75e.js +0 -4
  183. package/dist/chunk-3ae39ttg.js +0 -2
  184. package/dist/chunk-3x6p9me0.js +0 -2
  185. package/dist/chunk-440yjsk5.js +0 -2
  186. package/dist/chunk-58z26y07.js +0 -2
  187. package/dist/chunk-5db5sxy3.js +0 -3
  188. package/dist/chunk-5r9k9s3m.js +0 -2
  189. package/dist/chunk-76vza4ve.js +0 -2
  190. package/dist/chunk-84f9dnq5.js +0 -2
  191. package/dist/chunk-8tq5x4z8.js +0 -2
  192. package/dist/chunk-8y8bbsh5.js +0 -2
  193. package/dist/chunk-9kzycb15.js +0 -2
  194. package/dist/chunk-agfhb2qd.js +0 -2
  195. package/dist/chunk-ay6dzpt4.js +0 -2
  196. package/dist/chunk-b9njk81d.js +0 -2
  197. package/dist/chunk-bfbcmfww.js +0 -2
  198. package/dist/chunk-br01jvra.js +0 -2
  199. package/dist/chunk-c12y2bet.js +0 -2
  200. package/dist/chunk-c2nwchk0.js +0 -2
  201. package/dist/chunk-cxqrwvc5.js +0 -2
  202. package/dist/chunk-czea8zr1.js +0 -2
  203. package/dist/chunk-d99kfx3k.js +0 -2
  204. package/dist/chunk-dpn1pmxj.js +0 -2
  205. package/dist/chunk-dskrwa8f.js +0 -2
  206. package/dist/chunk-e6ycqvdm.js +0 -2
  207. package/dist/chunk-efgk2xv1.js +0 -2
  208. package/dist/chunk-fj70wq7k.js +0 -2
  209. package/dist/chunk-fvx6pd66.js +0 -2
  210. package/dist/chunk-hrbjapvr.js +0 -2
  211. package/dist/chunk-jc4mxq56.js +0 -2
  212. package/dist/chunk-jdpyxt8j.js +0 -2
  213. package/dist/chunk-k0zev8wc.js +0 -2
  214. package/dist/chunk-mhjwtkx9.js +0 -2
  215. package/dist/chunk-n4e02qdz.js +0 -2838
  216. package/dist/chunk-nx8rf4qd.js +0 -2
  217. package/dist/chunk-pe5bk9ns.js +0 -2
  218. package/dist/chunk-qb2j34sp.js +0 -2
  219. package/dist/chunk-qknfceta.js +0 -2
  220. package/dist/chunk-s932zfjz.js +0 -2
  221. package/dist/chunk-sf98zgw2.js +0 -2
  222. package/dist/chunk-sgsp4dph.js +0 -2
  223. package/dist/chunk-t48ws5j0.js +0 -2
  224. package/dist/chunk-tfxmzat6.js +0 -122
  225. package/dist/chunk-thbc9gtj.js +0 -2
  226. package/dist/chunk-tms7amrb.js +0 -2
  227. package/dist/chunk-tn9v10q2.js +0 -2
  228. package/dist/chunk-v0zgarvv.js +0 -2
  229. package/dist/chunk-v9jd283e.js +0 -2
  230. package/dist/chunk-vczw73ga.js +0 -2
  231. package/dist/chunk-webrqm20.js +0 -2
  232. package/dist/chunk-wg2w7zmt.js +0 -3
  233. package/dist/chunk-wgkxgsqx.js +0 -2
  234. package/dist/chunk-wngqr949.js +0 -2
  235. package/dist/chunk-xyzy84x0.js +0 -2
  236. package/dist/chunk-y1jffvkj.js +0 -2
  237. package/dist/chunk-yas134jv.js +0 -2
  238. package/dist/chunk-yd55vynh.js +0 -2
  239. package/dist/chunk-yygze2s0.js +0 -2
  240. package/dist/chunk-z732tf98.js +0 -2
  241. package/dist/chunk-ze86h6vp.js +0 -2
@@ -1,10 +1,14 @@
1
1
  import { compileClassStyles } from "../compiler/headwind-to-style.js";
2
2
  import { resolveIconName } from "../compiler/icons.js";
3
+ import { parseNativeStyleLayers } from "../compiler/inline-style.js";
4
+ import { createStyleVariables } from "../compiler/style-variables.js";
3
5
  import { affectsGeometry, parseSvgMarkup, parseViewBox, SVG_NODE_TYPES, svgGeometry } from "../compiler/svg.js";
4
6
  import { NATIVE_EVENT_NAMES } from "../event-names.js";
5
7
  import { nativePropName } from "../prop-names.js";
6
8
  import { cloneNativeBindingNode } from "./binding-tree.js";
7
9
  import { NATIVE_FORM_ENTRIES } from "./jsc-globals.js";
10
+ import { createNativeOverlayPresenter } from "./overlay-presenter.js";
11
+ import { nativeViewError } from "./view-operations.js";
8
12
  function irDisplay(value) {
9
13
  return value === "none" || value === "grid" || value === "flex" ? value : "flex";
10
14
  }
@@ -28,6 +32,9 @@ function eventAt(payload, node, type = "") {
28
32
  };
29
33
  }
30
34
  export const HOST_METHODS = [
35
+ "parent",
36
+ "getAttribute",
37
+ "observeChildren",
31
38
  "setText",
32
39
  "setMarkup",
33
40
  "setAttribute",
@@ -47,14 +54,19 @@ export const HOST_METHODS = [
47
54
  "scopesIn"
48
55
  ];
49
56
  export function createNativeHost(options) {
50
- const records = new Map, attributeObservers = new WeakMap, handlers = new Map, eventRegistrations = new WeakMap, componentListeners = new WeakMap, formControls = new WeakSet, formResetCallbacks = new WeakMap;
51
- let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", disposed = !1;
57
+ const records = new Map, attributeObservers = new WeakMap, childObservers = new WeakMap, handlers = new Map, eventRegistrations = new WeakMap, componentListeners = new WeakMap, controlsWithDefaultListeners = new WeakSet, formResetCallbacks = new WeakMap;
58
+ let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[colorScheme] ?? []).computed(), disposed = !1;
52
59
  const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), nextId = (prefix) => `${prefix}${++counter}`;
53
60
  function notifyAttributes(node, name) {
54
61
  for (const observer of attributeObservers.get(node) ?? [])
55
62
  if (observer.names.includes(name))
56
63
  observer.notify();
57
64
  }
65
+ function notifyChildren(node) {
66
+ for (let current = node;current; current = current.__stxOwner)
67
+ for (const notify of childObservers.get(current) ?? [])
68
+ notify();
69
+ }
58
70
  function flush() {
59
71
  scheduled = !1;
60
72
  if (queue.length === 0)
@@ -96,6 +108,7 @@ export function createNativeHost(options) {
96
108
  const record = descriptorOf(node);
97
109
  if (!record)
98
110
  return;
111
+ record.viewEpoch = (record.viewEpoch ?? 0) + 1;
99
112
  for (const handlerId of Object.values(record.events)) {
100
113
  const handler = handlers.get(handlerId);
101
114
  if (!handler)
@@ -207,24 +220,34 @@ export function createNativeHost(options) {
207
220
  callback();
208
221
  }
209
222
  }
210
- function installFormListeners(node) {
223
+ function installControlListeners(node) {
211
224
  const record = descriptorOf(node);
212
- if (!record || formControls.has(node) || !formOwner(node))
225
+ if (!record || controlsWithDefaultListeners.has(node))
226
+ return;
227
+ let delegatedPress = !1;
228
+ if (record.type === "Button" || record.type === "Pressable") {
229
+ for (let owner = node.__stxOwner;owner; owner = owner.__stxOwner)
230
+ if (componentListeners.get(owner)?.some((listener) => (NATIVE_EVENT_NAMES[listener.event.toLowerCase()] ?? listener.event) === "onPress")) {
231
+ delegatedPress = !0;
232
+ break;
233
+ }
234
+ }
235
+ if (!formOwner(node) && !delegatedPress)
213
236
  return;
214
- formControls.add(node);
237
+ controlsWithDefaultListeners.add(node);
215
238
  if (record.type === "TextInput" || record.type === "Picker" || record.type === "Checkbox") {
216
239
  host.listen(node, record.type === "TextInput" ? "input" : "change", () => {});
217
240
  host.listen(node, "focusout", () => {});
218
241
  }
219
- if (record.type === "Button")
242
+ if (record.type === "Button" || record.type === "Pressable")
220
243
  host.listen(node, "click", () => {});
221
244
  }
222
245
  function materialize(node) {
223
246
  const record = recordOf(node);
224
247
  if (record.materialized || node.__stxAnchor !== void 0)
225
248
  return;
226
- installFormListeners(node);
227
- record.style = resolveStyle(record);
249
+ installControlListeners(node);
250
+ record.style = resolveStyle(record, node.__stxId);
228
251
  record.materialized = !0;
229
252
  emit({
230
253
  op: "createNode",
@@ -246,16 +269,82 @@ export function createNativeHost(options) {
246
269
  emit({ op: "insertChild", parentId: node.__stxId, childId: child.__stxId, index: index++ });
247
270
  }
248
271
  }
249
- function resolveStyle(record) {
250
- const classes = compileClassStyles(record.classes);
251
- return { ...classes.style, ...colorScheme === "dark" ? classes.dark : {}, ...record.baseStyle };
272
+ function resolveStyle(record, id) {
273
+ const report = (diagnostic) => {
274
+ console.warn(`[STX Native] ${diagnostic.kind}: ${id}: ${diagnostic.name}`);
275
+ };
276
+ let inherited = record.inheritedVariables;
277
+ for (const source of record.styleAncestors ?? [])
278
+ inherited = parseNativeStyleLayers([source], inherited, report).variables;
279
+ const resolved = parseNativeStyleLayers([record.styleSource, record.boundStyle, record.forwardedStyle], inherited, report);
280
+ record.variables = resolved.variables;
281
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables);
282
+ return { ...classes.style, ...colorScheme === "dark" ? classes.dark : {}, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2], ...record.visible ? {} : { display: "none" } };
252
283
  }
253
- function applyClasses(id, record) {
254
- const style = resolveStyle(record), patch = Object.fromEntries(Object.keys(record.style).filter((key) => !(key in style)).map((key) => [key, null]));
284
+ function refreshStyleTree(node, inherited = node.__stxOwner ? descriptorOf(node.__stxOwner)?.variables : stylesheetVariables, appearanceChanged = !1) {
285
+ if (node.__stxAnchor !== void 0)
286
+ return;
287
+ const record = recordOf(node), before = record.variables;
288
+ record.inheritedVariables = inherited;
289
+ applyClasses(node.__stxId, record, !0);
290
+ const after = record.variables;
291
+ if (!appearanceChanged && before?.size === after.size && [...after].every(([name, value]) => before.has(name) && before.get(name) === value))
292
+ return;
293
+ for (const child of record.children)
294
+ refreshStyleTree(child, after, appearanceChanged);
295
+ }
296
+ function forwardedHostRoot(node, name) {
297
+ if (!isBindingNode(node) || !(node.getAttribute("data-stx-native-forward") ?? "").split(/\s+/).includes(name))
298
+ return;
299
+ const find = (candidate) => {
300
+ if (isBindingNode(candidate) && candidate.hasAttribute("data-stx-native-host-root"))
301
+ return candidate;
302
+ for (const child of recordOf(candidate).children) {
303
+ if (isBindingNode(child) && child.hasAttribute("data-stx-component-wrapper"))
304
+ continue;
305
+ const match = find(child);
306
+ if (match)
307
+ return match;
308
+ }
309
+ };
310
+ return find(node);
311
+ }
312
+ function applyForwardedStyle(node, name, value) {
313
+ const record = recordOf(node);
314
+ if (name === "class" || name === "class-name" || name === "className")
315
+ record.forwardedClasses = Array.isArray(value) ? value.filter(Boolean).join(" ") : value && typeof value === "object" ? Object.entries(value).filter(([, enabled]) => enabled).map(([classes]) => classes).join(" ") : String(value ?? "");
316
+ else if (name === "style")
317
+ record.forwardedStyle = value;
318
+ else
319
+ return !1;
320
+ refreshStyleTree(node);
321
+ return !0;
322
+ }
323
+ function reflectAttribute(node, name, value, remove = !1) {
324
+ if (!isBindingNode(node) || name === "class" || name === "className")
325
+ return;
326
+ if (remove) {
327
+ if (!node.hasAttribute(name))
328
+ return;
329
+ node.removeAttribute(name);
330
+ } else {
331
+ const serialized = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
332
+ if (node.getAttribute(name) === serialized)
333
+ return;
334
+ node.setAttribute(name, serialized);
335
+ }
336
+ notifyAttributes(node, name);
337
+ }
338
+ function applyClasses(id, record, onlyIfChanged = !1) {
339
+ const style = resolveStyle(record, id), patch = Object.fromEntries(Object.keys(record.style).filter((key) => !(key in style)).map((key) => [key, null])), changed = !onlyIfChanged || JSON.stringify(record.style) !== JSON.stringify(style);
255
340
  record.style = style;
256
- if (record.materialized)
341
+ if (record.materialized && changed)
257
342
  emit({ op: "updateNode", id, patch: { style: { ...patch, ...style } } });
258
- const classes = compileClassStyles(record.classes);
343
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables), unsupported = new Set(classes.unknown);
344
+ for (const name of unsupported)
345
+ if (!record.reportedClasses?.has(name))
346
+ console.warn(`[STX Native] unknown-class: ${id}: ${name}`);
347
+ record.reportedClasses = unsupported;
259
348
  if (record.type === "Icon" && classes.icon) {
260
349
  const icon = resolveIconName(classes.icon);
261
350
  record.props.symbol = icon.symbol;
@@ -291,6 +380,8 @@ export function createNativeHost(options) {
291
380
  if (target.__stxPositionDecorated)
292
381
  return;
293
382
  Object.defineProperties(target, {
383
+ focus: { configurable: !0, value: (focusOptions) => host.focus(node, focusOptions) },
384
+ measure: { configurable: !0, value: () => host.measure(node) },
294
385
  nextSibling: {
295
386
  configurable: !0,
296
387
  get() {
@@ -313,6 +404,24 @@ export function createNativeHost(options) {
313
404
  });
314
405
  target.__stxPositionDecorated = !0;
315
406
  }
407
+ async function withMountedView(node, request) {
408
+ await Promise.resolve();
409
+ if (disposed)
410
+ throw nativeViewError("SCREEN_CLOSED", "The native screen has closed");
411
+ const record = records.get(node.__stxId);
412
+ if (!record?.materialized || node.__stxAnchor !== void 0 || isBindingNode(node) && !node.isConnected)
413
+ throw nativeViewError("VIEW_NOT_MOUNTED", `Native view ${node.__stxId} is not mounted`);
414
+ if (!options.views)
415
+ throw nativeViewError("UNSUPPORTED", "Native view operations are unavailable");
416
+ const epoch = record.viewEpoch ?? 0;
417
+ flush();
418
+ const result = await request(options.views);
419
+ if (disposed)
420
+ throw nativeViewError("SCREEN_CLOSED", "The native screen has closed");
421
+ if (records.get(node.__stxId) !== record || (record.viewEpoch ?? 0) !== epoch)
422
+ throw nativeViewError("VIEW_NOT_MOUNTED", `Native view ${node.__stxId} changed while the operation was pending`);
423
+ return result;
424
+ }
316
425
  function setConnected(node, connected) {
317
426
  if ("isConnected" in node)
318
427
  node.isConnected = connected;
@@ -339,12 +448,15 @@ export function createNativeHost(options) {
339
448
  const suffix = /(?:^|\D)(\d+)$/.exec(node.__stxId)?.[1];
340
449
  if (suffix)
341
450
  counter = Math.max(counter, Number(suffix));
342
- const classes = descriptor?._classes ?? "", classStyle = compileClassStyles(classes).style, baseStyle = descriptor?._inlineStyle ? { ...descriptor._inlineStyle } : Object.fromEntries(Object.entries(descriptor?.style ?? {}).filter(([key, value]) => classStyle[key] !== value)), record = {
451
+ const classes = descriptor?._classes ?? "", classStyle = compileClassStyles(classes).style, baseStyle = descriptor?._styleSource !== void 0 ? {} : descriptor?._inlineStyle ? { ...descriptor._inlineStyle } : Object.fromEntries(Object.entries(descriptor?.style ?? {}).filter(([key, value]) => classStyle[key] !== value)), record = {
343
452
  type,
344
453
  key: descriptor?.key,
345
454
  props: { ...descriptor?.props ?? {} },
346
455
  style: { ...descriptor?.style ?? {} },
347
456
  baseStyle,
457
+ styleSource: descriptor?._styleSource,
458
+ styleAncestors: descriptor?._styleAncestors,
459
+ inheritedVariables: owner ? descriptorOf(owner)?.variables : stylesheetVariables,
348
460
  classes,
349
461
  events: { ...descriptor?.events ?? {} },
350
462
  text: descriptor?.children?.find((child) => typeof child === "string"),
@@ -353,7 +465,7 @@ export function createNativeHost(options) {
353
465
  materialized: !0,
354
466
  controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 }
355
467
  };
356
- record.style = resolveStyle(record);
468
+ record.style = resolveStyle(record, node.__stxId);
357
469
  if (descriptor)
358
470
  descriptor.style = { ...record.style };
359
471
  records.set(node.__stxId, record);
@@ -365,22 +477,82 @@ export function createNativeHost(options) {
365
477
  if (!children.some((child) => child.__stxId === node.__stxId))
366
478
  children.push(node);
367
479
  }
368
- installFormListeners(node);
480
+ installControlListeners(node);
369
481
  return node;
370
482
  }
371
- const host = {
483
+ const overlayPresenter = createNativeOverlayPresenter({
484
+ canFocus: options.views?.capabilities.focus === !0,
485
+ focus: (node, focusOptions) => host.focus(node, focusOptions),
486
+ descendants: collectDescendants,
487
+ hasAutofocus: (node) => {
488
+ const value = descriptorOf(node)?.props.autoFocus;
489
+ return value === !0 || value === "" || value === "true";
490
+ },
491
+ isAvailable: (node) => {
492
+ if (!records.has(node.__stxId) || disabled(recordOf(node)))
493
+ return !1;
494
+ for (let current = node;current; current = current.__stxOwner ?? null) {
495
+ const record = records.get(current.__stxId);
496
+ if (!record?.materialized || !record.visible || record.style.display === "none" || record.type === "Modal" && (record.props.visible === !1 || record.props.visible === "false"))
497
+ return !1;
498
+ }
499
+ return !0;
500
+ },
501
+ type: (node) => descriptorOf(node)?.type,
502
+ setAttribute: (node, name, value) => host.setAttribute(node, name, value),
503
+ setStyle: (node, value) => host.setStyle(node, value),
504
+ listen: (node, event, callback) => host.listen(node, event, callback)
505
+ }), host = {
372
506
  isNative: !0,
507
+ focus: (node, focusOptions) => withMountedView(node, (views) => views.focus(node.__stxId, focusOptions)),
508
+ measure: (node) => withMountedView(node, (views) => views.measure(node.__stxId)),
509
+ syncOverlays: (entries) => overlayPresenter.sync(entries),
510
+ parent(node) {
511
+ return node?.__stxOwner ?? null;
512
+ },
513
+ getAttribute(node, name) {
514
+ if (!node)
515
+ return null;
516
+ if (isBindingNode(node))
517
+ return node.getAttribute(name);
518
+ const value = descriptorOf(node)?.props[nativePropName(name)];
519
+ return value == null || value === !1 ? null : value === !0 ? "" : String(value);
520
+ },
521
+ observeChildren(node, callback) {
522
+ const observers = childObservers.get(node) ?? new Set;
523
+ childObservers.set(node, observers);
524
+ let active = !0, pending = !1;
525
+ const notify = () => {
526
+ if (!active || pending || disposed)
527
+ return;
528
+ pending = !0;
529
+ queueMicrotask(() => {
530
+ pending = !1;
531
+ if (active && !disposed)
532
+ callback();
533
+ });
534
+ };
535
+ observers.add(notify);
536
+ return () => {
537
+ active = !1;
538
+ observers.delete(notify);
539
+ };
540
+ },
373
541
  adopt,
374
542
  setColorScheme(scheme) {
375
543
  if (scheme === colorScheme)
376
544
  return;
377
545
  colorScheme = scheme;
378
- for (const [id, record] of records)
379
- applyClasses(id, record);
546
+ stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[scheme] ?? []).computed();
547
+ const children = new Set([...records.values()].flatMap((record) => record.children.map((child) => child.__stxId)));
548
+ for (const id of records.keys())
549
+ if (!children.has(id))
550
+ refreshStyleTree({ __stxId: id }, stylesheetVariables, !0);
380
551
  },
381
552
  pending: () => queue.length,
382
553
  flush,
383
554
  dispose() {
555
+ overlayPresenter.dispose();
384
556
  disposed = !0;
385
557
  queue = [];
386
558
  handlers.clear();
@@ -391,7 +563,7 @@ export function createNativeHost(options) {
391
563
  const describe = (node) => {
392
564
  const record = recordOf(node);
393
565
  if (!record.materialized)
394
- record.style = resolveStyle(record);
566
+ record.style = resolveStyle(record, node.__stxId);
395
567
  record.materialized = !0;
396
568
  const children = record.children.filter((child) => child.__stxAnchor === void 0).map(describe);
397
569
  return {
@@ -433,12 +605,13 @@ export function createNativeHost(options) {
433
605
  }
434
606
  },
435
607
  setAttribute(node, name, value) {
436
- if (isBindingNode(node) && name !== "class" && name !== "className") {
437
- const serialized = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
438
- if (node.getAttribute(name) !== serialized) {
439
- node.setAttribute(name, serialized);
440
- notifyAttributes(node, name);
441
- }
608
+ const forwarded = forwardedHostRoot(node, name);
609
+ reflectAttribute(node, name, value);
610
+ if (forwarded) {
611
+ reflectAttribute(forwarded, name, value);
612
+ if (applyForwardedStyle(forwarded, name, value))
613
+ return;
614
+ node = forwarded;
442
615
  }
443
616
  if (name === "class" || name === "className") {
444
617
  const record = recordOf(node);
@@ -466,9 +639,13 @@ export function createNativeHost(options) {
466
639
  emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
467
640
  },
468
641
  removeAttribute(node, name) {
469
- if (isBindingNode(node) && name !== "class" && name !== "className" && node.hasAttribute(name)) {
470
- node.removeAttribute(name);
471
- notifyAttributes(node, name);
642
+ const forwarded = forwardedHostRoot(node, name);
643
+ reflectAttribute(node, name, void 0, !0);
644
+ if (forwarded) {
645
+ reflectAttribute(forwarded, name, void 0, !0);
646
+ if (applyForwardedStyle(forwarded, name, void 0))
647
+ return;
648
+ node = forwarded;
472
649
  }
473
650
  if (name === "class" || name === "className") {
474
651
  this.setAttribute(node, name, "");
@@ -502,13 +679,19 @@ export function createNativeHost(options) {
502
679
  observers.delete(observer);
503
680
  };
504
681
  },
505
- setStyle(node, value) {
682
+ setStyle(node, value, replaceBinding = !1) {
683
+ const record = recordOf(node);
684
+ if (replaceBinding) {
685
+ record.boundStyle = value;
686
+ refreshStyleTree(node);
687
+ return;
688
+ }
506
689
  if (typeof value !== "object" || value === null || Array.isArray(value))
507
690
  return;
508
691
  const style = value;
509
- Object.assign(recordOf(node).baseStyle, style);
510
- Object.assign(recordOf(node).style, style);
511
- if (recordOf(node).materialized)
692
+ Object.assign(record.baseStyle, style);
693
+ Object.assign(record.style, style);
694
+ if (record.materialized)
512
695
  emit({ op: "updateNode", id: node.__stxId, patch: { style } });
513
696
  },
514
697
  emitComponentEvent(node, event) {
@@ -634,6 +817,11 @@ export function createNativeHost(options) {
634
817
  record.events[nativeEvent] = id;
635
818
  if (record.materialized)
636
819
  emit({ op: "updateNode", id: node.__stxId, patch: { events: { [nativeEvent]: id } } });
820
+ if (nativeEvent === "onPress") {
821
+ for (const child of collectDescendants(node))
822
+ if (["Button", "Pressable"].includes(descriptorOf(child)?.type ?? ""))
823
+ installControlListeners(child);
824
+ }
637
825
  },
638
826
  dispatch(handlerId, payload) {
639
827
  handlers.get(handlerId)?.(payload);
@@ -661,7 +849,8 @@ export function createNativeHost(options) {
661
849
  record.baseStyle.display = record.shownDisplay;
662
850
  record.shownDisplay = void 0;
663
851
  }
664
- const display = visible ? irDisplay(resolveStyle(record).display) : "none";
852
+ record.style = resolveStyle(record, node.__stxId);
853
+ const display = visible ? irDisplay(record.style.display) : "none";
665
854
  if (record.materialized)
666
855
  emit({ op: "updateNode", id: node.__stxId, patch: { style: { display } } });
667
856
  return was;
@@ -693,7 +882,14 @@ export function createNativeHost(options) {
693
882
  props: { ...descriptor.props, __stxId: copy.__stxId },
694
883
  style: { ...descriptor.style },
695
884
  baseStyle: { ...descriptor.baseStyle },
885
+ styleSource: descriptor.styleSource,
886
+ styleAncestors: descriptor.styleAncestors,
887
+ inheritedVariables: descriptor.inheritedVariables,
888
+ variables: descriptor.variables,
889
+ boundStyle: descriptor.boundStyle,
696
890
  classes: descriptor.classes,
891
+ forwardedClasses: descriptor.forwardedClasses,
892
+ forwardedStyle: descriptor.forwardedStyle,
697
893
  events: { ...descriptor.events },
698
894
  text: descriptor.text,
699
895
  children: [],
@@ -722,8 +918,12 @@ export function createNativeHost(options) {
722
918
  const index = before ? Math.max(0, record.children.findIndex((child) => child.__stxId === before.__stxId)) : record.children.length;
723
919
  record.children.splice(index, 0, node);
724
920
  node.__stxOwner = parent;
921
+ refreshStyleTree(node, record.variables);
725
922
  insertIntoBindingParent(parent, node, index);
726
923
  setConnected(node, record.materialized);
924
+ if (oldOwner && oldOwner !== parent)
925
+ notifyChildren(oldOwner);
926
+ notifyChildren(parent);
727
927
  if (node.__stxAnchor !== void 0 || !record.materialized)
728
928
  return;
729
929
  materialize(node);
@@ -766,6 +966,7 @@ export function createNativeHost(options) {
766
966
  setConnected(node, !1);
767
967
  releaseHandlers(node);
768
968
  retainDetachedDescriptors(node);
969
+ notifyChildren(owner);
769
970
  if (node.__stxAnchor !== void 0 || !wasMaterialized)
770
971
  return;
771
972
  emit({ op: "removeNode", id: node.__stxId });
@@ -0,0 +1,29 @@
1
+ import type { NativeFocusOptions } from './view-operations';
2
+ import type { NativeNode } from './native-host';
3
+ export declare function createNativeOverlayPresenter(host: OverlayHost): NativeOverlayPresenter;
4
+ /** Overlay policy stays in the shared runtime; this adapter presents native Modal nodes. */
5
+ export declare interface NativeOverlayEntry {
6
+ id: string
7
+ root: NativeNode | null
8
+ modal: boolean
9
+ zIndex?: number | null
10
+ panel?: FocusTarget
11
+ initialFocus?: FocusTarget
12
+ onRequestClose?: ((event?: unknown) => void) | null
13
+ }
14
+ declare interface OverlayHost {
15
+ canFocus: boolean
16
+ focus: (node: NativeNode, options: NativeFocusOptions) => Promise<true>
17
+ descendants: (node: NativeNode) => NativeNode[]
18
+ hasAutofocus: (node: NativeNode) => boolean
19
+ isAvailable: (node: NativeNode) => boolean
20
+ type: (node: NativeNode) => string | undefined
21
+ setAttribute: (node: NativeNode, name: string, value: unknown) => void
22
+ setStyle: (node: NativeNode, style: Record<string, unknown>) => void
23
+ listen: (node: NativeNode, event: string, callback: (event?: unknown) => void) => void
24
+ }
25
+ export declare interface NativeOverlayPresenter {
26
+ sync: (entries: NativeOverlayEntry[]) => void
27
+ dispose: () => void
28
+ }
29
+ declare type FocusTarget = NativeNode | (() => NativeNode | null) | null;
@@ -0,0 +1,69 @@
1
+ export function createNativeOverlayPresenter(host) {
2
+ let current = [];
3
+ const listening = new WeakSet;
4
+ let focusing = null;
5
+ function focusInitial(entry) {
6
+ if (!host.canFocus) {
7
+ if (entry.initialFocus)
8
+ console.warn(`[stx:overlays] Native initialFocus for "${entry.id}" requires viewFocus support; focus was not moved.`);
9
+ return;
10
+ }
11
+ const controller = focusing = new AbortController;
12
+ queueMicrotask(async () => {
13
+ if (controller.signal.aborted || current.at(-1)?.root !== entry.root)
14
+ return;
15
+ try {
16
+ const resolve = (value) => typeof value === "function" ? value() : value ?? null, panel = resolve(entry.panel) ?? entry.root, explicit = resolve(entry.initialFocus), candidates = [panel, ...host.descendants(panel)].filter((node) => host.isAvailable(node)), target = explicit ?? candidates.find((node) => host.hasAutofocus(node)) ?? candidates.find((node) => ["TextInput", "Button", "Pressable", "Checkbox", "Switch", "Picker", "Slider", "Link"].includes(host.type(node) ?? "")) ?? (host.isAvailable(panel) ? panel : null);
17
+ if (!target || !host.isAvailable(target)) {
18
+ if (explicit)
19
+ console.warn(`[stx:overlays] Native initialFocus for "${entry.id}" must reference a mounted, visible, enabled view; focus was not moved.`);
20
+ return;
21
+ }
22
+ await host.focus(target, { mode: host.type(target) === "TextInput" ? "keyboard" : "accessibility", signal: controller.signal });
23
+ } catch (error) {
24
+ if (!controller.signal.aborted)
25
+ console.warn(`[stx:overlays] Native focus failed for "${entry.id}": ${error instanceof Error ? error.message : String(error)}`);
26
+ }
27
+ });
28
+ }
29
+ function sync(entries) {
30
+ for (const entry of entries)
31
+ if (!entry.root || host.type(entry.root) !== "Modal" || !entry.modal)
32
+ throw Error(`[stx:overlays] Native overlay "${entry.id}" requires a Modal root (data-native="Modal"). Anchored/non-modal popups require a host positioning capability.`);
33
+ const previous = current;
34
+ current = entries.slice();
35
+ for (const entry of previous)
36
+ if (!current.some((next) => next.root === entry.root))
37
+ host.setAttribute(entry.root, "visible", !1);
38
+ for (const [index, entry] of current.entries()) {
39
+ const root = entry.root;
40
+ if (!listening.has(root)) {
41
+ listening.add(root);
42
+ host.listen(root, "request-close", (event) => {
43
+ const top = current.at(-1);
44
+ try {
45
+ if (top?.root === root)
46
+ top.onRequestClose?.(event);
47
+ } finally {
48
+ if (current.some((active) => active.root === root))
49
+ host.setAttribute(root, "visible", !0);
50
+ }
51
+ });
52
+ }
53
+ host.setAttribute(root, "visible", !0);
54
+ host.setStyle(root, { zIndex: (entry.zIndex ?? 1000) + index });
55
+ }
56
+ const top = current.at(-1);
57
+ if (top?.root !== previous.at(-1)?.root) {
58
+ focusing?.abort();
59
+ focusing = null;
60
+ if (top && !previous.some((entry) => entry.root === top.root))
61
+ focusInitial(top);
62
+ }
63
+ }
64
+ return { sync, dispose() {
65
+ focusing?.abort();
66
+ focusing = null;
67
+ current = [];
68
+ } };
69
+ }
@@ -1,14 +1,21 @@
1
+ import { createNode } from "../compiler/ir.js";
1
2
  import { STXBridge } from "../bridge/protocol.js";
2
3
  import { materializeNativeBindingTree } from "./binding-tree.js";
3
4
  import { installCraftBridge } from "./craft-bridge.js";
4
5
  import { createNativeHost } from "./native-host.js";
6
+ import { createNativeViewOperations, nativeViewError } from "./view-operations.js";
5
7
  export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
6
- let revision = 0, generation = 0;
8
+ let revision = 0, generation = 0, rendered = !1;
7
9
  const protocol = new STXBridge;
8
10
  protocol.initialize(bridge);
9
11
  installCraftBridge(protocol, bridge, globalThis, options);
10
12
  const host = createNativeHost({
13
+ views: createNativeViewOperations(protocol, bridge.capabilities ?? [], () => {
14
+ if (!rendered)
15
+ throw nativeViewError("VIEW_NOT_MOUNTED", "The native screen has not rendered");
16
+ }),
11
17
  colorScheme: bridge.colorScheme === "dark" ? "dark" : "light",
18
+ stylesheetTheme: document.root._stylesheetTheme,
12
19
  send(operations) {
13
20
  const baseRevision = revision;
14
21
  revision++;
@@ -28,6 +35,8 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
28
35
  host.setColorScheme(scheme);
29
36
  }
30
37
  });
38
+ if (manifest.entries.find((entry) => entry.id === document.root.bindingId)?.bindings.some((binding) => binding.kind === "if" || binding.kind === "for"))
39
+ document = { ...document, root: createNode("View", {}, { flex: 1 }, {}, [document.root]) };
31
40
  const tree = materializeNativeBindingTree(document, manifest, host);
32
41
  let dispose = null;
33
42
  protocol.on("MUTATION_ERROR", (message) => {
@@ -53,9 +62,11 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
53
62
  dispose?.();
54
63
  dispose = runtime.hydrateHost(tree.root, setup, manifest, tree.nodes);
55
64
  protocol.render(document.root);
65
+ rendered = !0;
56
66
  host.flush();
57
67
  },
58
68
  unmount() {
69
+ rendered = !1;
59
70
  dispose?.();
60
71
  dispose = null;
61
72
  host.dispose();
@@ -0,0 +1,20 @@
1
+ import type { STXBridge } from '../bridge/protocol';
2
+ export declare function nativeViewError(code: string, message: string): Error & { code: string };
3
+ /** Craft #373: stable node ids and logical viewport coordinates, not DOM geometry. */
4
+ export declare function createNativeViewOperations(protocol: Pick<STXBridge, 'callNativeAPI'>, capabilities: readonly string[], beforeRequest: () => void): NativeViewOperations;
5
+ export declare interface NativeFocusOptions { mode?: 'keyboard' | 'accessibility', signal?: AbortSignal }
6
+ export declare interface NativeViewBounds {
7
+ x: number
8
+ y: number
9
+ width: number
10
+ height: number
11
+ viewportWidth: number
12
+ viewportHeight: number
13
+ unit: 'points' | 'dp'
14
+ coordinateSpace: 'screenViewport'
15
+ }
16
+ export declare interface NativeViewOperations {
17
+ readonly capabilities: { focus: boolean, measure: boolean }
18
+ focus: (nodeId: string, options?: NativeFocusOptions) => Promise<true>
19
+ measure: (nodeId: string) => Promise<NativeViewBounds>
20
+ }
@@ -0,0 +1,35 @@
1
+ export function nativeViewError(code, message) {
2
+ return Object.assign(Error(message), { code });
3
+ }
4
+ export function createNativeViewOperations(protocol, capabilities, beforeRequest) {
5
+ const supported = new Set(capabilities);
6
+ function prepare(capability) {
7
+ if (!supported.has(capability))
8
+ throw nativeViewError("UNSUPPORTED", `This Craft host does not advertise ${capability}`);
9
+ beforeRequest();
10
+ }
11
+ return {
12
+ capabilities: { focus: supported.has("viewFocus"), measure: supported.has("viewMeasure") },
13
+ async focus(nodeId, options = {}) {
14
+ if (options.signal?.aborted)
15
+ throw nativeViewError("CANCELLED", "Native focus was cancelled");
16
+ const mode = options.mode ?? "keyboard";
17
+ if (mode !== "keyboard" && mode !== "accessibility")
18
+ throw nativeViewError("INVALID_ARGUMENT", "View.focus mode must be keyboard or accessibility");
19
+ prepare("viewFocus");
20
+ const result = await protocol.callNativeAPI("View", "focus", { nodeId, mode });
21
+ if (options.signal?.aborted)
22
+ throw nativeViewError("CANCELLED", "Native focus was cancelled");
23
+ if (result !== !0)
24
+ throw nativeViewError("INVALID_RESPONSE", "View.focus did not confirm focus");
25
+ return !0;
26
+ },
27
+ async measure(nodeId) {
28
+ prepare("viewMeasure");
29
+ const box = await protocol.callNativeAPI("View", "measure", { nodeId });
30
+ if (!box || !["x", "y", "width", "height", "viewportWidth", "viewportHeight"].every((key) => typeof box[key] === "number" && Number.isFinite(box[key])) || box.width < 0 || box.height < 0 || box.viewportWidth < 0 || box.viewportHeight < 0 || !["points", "dp"].includes(box.unit) || box.coordinateSpace !== "screenViewport")
31
+ throw nativeViewError("INVALID_RESPONSE", "View.measure returned invalid viewport bounds");
32
+ return box;
33
+ }
34
+ };
35
+ }
@@ -0,0 +1,4 @@
1
+ import type { NativeNode, NativeOperation } from './testing';
2
+ /** Preflight topology on a copy: a rejected batch must never partially alter the test phone. */
3
+ export declare function validateTestMutations(source: Map<string, NativeNode>, operations: NativeOperation[]): TestMutationError | null;
4
+ export declare interface TestMutationError { code: string, message: string, operationIndex: number }