@stacksjs/stx 0.2.583 → 0.2.585

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 (243) hide show
  1. package/dist/{chunk-ck1yca7g.js → chunk-03qf2z4d.js} +1 -1
  2. package/dist/{chunk-6m3me7yj.js → chunk-03xsf9jm.js} +9 -9
  3. package/dist/{chunk-sv5nvfmb.js → chunk-048eyjyj.js} +2 -2
  4. package/dist/{chunk-je1as16r.js → chunk-076h7nb9.js} +5 -5
  5. package/dist/{chunk-hp9nxva6.js → chunk-07869zev.js} +4 -4
  6. package/dist/chunk-0hpw65yr.js +2 -0
  7. package/dist/chunk-11jmasqb.js +2 -0
  8. package/dist/chunk-2c7ysn9s.js +2 -0
  9. package/dist/chunk-2wb1w0p6.js +2 -0
  10. package/dist/chunk-2wx2aczp.js +2 -0
  11. package/dist/{chunk-pbwk8tzz.js → chunk-33q5zka4.js} +1 -1
  12. package/dist/chunk-3qmx12d3.js +2845 -0
  13. package/dist/{chunk-ktyctev3.js → chunk-3y5tzxm6.js} +2 -2
  14. package/dist/chunk-3ybbat49.js +2 -0
  15. package/dist/{chunk-2943qhdt.js → chunk-45x4myqe.js} +2 -2
  16. package/dist/chunk-4dpab4j6.js +2 -0
  17. package/dist/{chunk-5kh5ehfh.js → chunk-4h58as2c.js} +2 -2
  18. package/dist/chunk-4vnwge6p.js +2 -0
  19. package/dist/chunk-4w37cqg9.js +2 -0
  20. package/dist/chunk-51pz8cwa.js +2 -0
  21. package/dist/chunk-65agttgm.js +2 -0
  22. package/dist/{chunk-ye66wc53.js → chunk-67m2prah.js} +2 -2
  23. package/dist/{chunk-521pe0hb.js → chunk-6cg03r93.js} +4 -4
  24. package/dist/chunk-6djvj6hg.js +2 -0
  25. package/dist/{chunk-4pmgr32a.js → chunk-6hgngmn0.js} +3 -3
  26. package/dist/{chunk-09zwhsf9.js → chunk-751b5zv9.js} +3 -3
  27. package/dist/{chunk-mjj24qpb.js → chunk-794v5crp.js} +2 -2
  28. package/dist/chunk-7ae40484.js +2 -0
  29. package/dist/chunk-7dkwf9h5.js +2 -0
  30. package/dist/chunk-7dtyf7hq.js +2 -0
  31. package/dist/chunk-7ebt9n43.js +4 -0
  32. package/dist/{chunk-cnknvvwm.js → chunk-7fghm9zy.js} +1 -1
  33. package/dist/{chunk-117xss52.js → chunk-7xw1e8t6.js} +2 -2
  34. package/dist/{chunk-w6wtxj54.js → chunk-7ydavm3h.js} +2 -2
  35. package/dist/chunk-80g8kaes.js +2 -0
  36. package/dist/{chunk-qdyp2zqf.js → chunk-82bttwqm.js} +2 -2
  37. package/dist/chunk-8992smwz.js +2 -0
  38. package/dist/{chunk-qn8gdw21.js → chunk-8s7zbhdd.js} +4 -4
  39. package/dist/{chunk-02qaqamv.js → chunk-91pdg853.js} +7 -7
  40. package/dist/chunk-9j6hk72q.js +2 -0
  41. package/dist/{chunk-96mb3brj.js → chunk-9nt3q23a.js} +3 -3
  42. package/dist/chunk-9pk5jhqa.js +3 -0
  43. package/dist/{chunk-g9zeybqh.js → chunk-9qsnq026.js} +2 -2
  44. package/dist/{chunk-m417sp42.js → chunk-a30mtx17.js} +4 -4
  45. package/dist/chunk-a3k4nfq2.js +2 -0
  46. package/dist/{chunk-c0h2eqe0.js → chunk-a8n6mt7s.js} +2 -2
  47. package/dist/{chunk-xp7fxc6p.js → chunk-awgvt956.js} +5 -5
  48. package/dist/{chunk-mt9x626h.js → chunk-axz1x4r9.js} +5 -5
  49. package/dist/{chunk-8tq83fq7.js → chunk-b217d16p.js} +57 -57
  50. package/dist/{chunk-w3rmepwy.js → chunk-bfbmdjh4.js} +2 -2
  51. package/dist/chunk-bhg4pvtn.js +2 -0
  52. package/dist/{chunk-0k5faspy.js → chunk-bsy10tz6.js} +6 -6
  53. package/dist/{chunk-dvc15djp.js → chunk-c6egfhy6.js} +2 -2
  54. package/dist/chunk-c8fdccgp.js +2 -0
  55. package/dist/chunk-ce2d0hz9.js +2 -0
  56. package/dist/{chunk-4pkpr5cg.js → chunk-cqr5cv7h.js} +4 -4
  57. package/dist/chunk-cw76edds.js +2 -0
  58. package/dist/{chunk-ky1426s1.js → chunk-cy07dhqh.js} +10 -10
  59. package/dist/chunk-czrs87r9.js +2 -0
  60. package/dist/{chunk-ycj0342k.js → chunk-d0tmc6v5.js} +2 -2
  61. package/dist/chunk-d9vjsqs4.js +2 -0
  62. package/dist/chunk-ddgyj88h.js +2 -0
  63. package/dist/chunk-dj90w48e.js +2 -0
  64. package/dist/chunk-dngzks8e.js +2 -0
  65. package/dist/chunk-e01j75cr.js +122 -0
  66. package/dist/{chunk-kfwmqacd.js → chunk-e556dvy4.js} +3 -3
  67. package/dist/chunk-ede39b7h.js +3 -0
  68. package/dist/chunk-emxa2djv.js +2 -0
  69. package/dist/chunk-esj49jvz.js +2 -0
  70. package/dist/chunk-eztvhppz.js +2 -0
  71. package/dist/{chunk-4srg0qbv.js → chunk-f29fk7dw.js} +2 -2
  72. package/dist/{chunk-vke73gts.js → chunk-fkq55rh7.js} +1 -1
  73. package/dist/chunk-h2534p6q.js +2 -0
  74. package/dist/{chunk-2nehykbm.js → chunk-h7atbtds.js} +5 -5
  75. package/dist/chunk-h9gtc6bk.js +2 -0
  76. package/dist/{chunk-h0a2s340.js → chunk-haag5n42.js} +2 -2
  77. package/dist/{chunk-cby4mkjf.js → chunk-hj8tr9g0.js} +1 -1
  78. package/dist/{chunk-en7xxgtb.js → chunk-hsy9rhct.js} +2 -2
  79. package/dist/{chunk-qccgncp2.js → chunk-htcptqtn.js} +6 -6
  80. package/dist/chunk-hwnvfke9.js +2 -0
  81. package/dist/chunk-hygxh993.js +2 -0
  82. package/dist/{chunk-s12bnv32.js → chunk-hz11wmx9.js} +2 -2
  83. package/dist/{chunk-wyn5rfzk.js → chunk-j7kcjgxy.js} +115 -26
  84. package/dist/chunk-j8v5164e.js +2 -0
  85. package/dist/chunk-jqy5q8m0.js +2 -0
  86. package/dist/{chunk-0dfgefjv.js → chunk-jtx74677.js} +2 -2
  87. package/dist/chunk-jy7yzat1.js +2 -0
  88. package/dist/{chunk-vkc51n9m.js → chunk-k1szsenr.js} +2 -2
  89. package/dist/{chunk-sv08pd66.js → chunk-k71e38fk.js} +4 -4
  90. package/dist/{chunk-ac6v3s3k.js → chunk-kfhghjh6.js} +2 -2
  91. package/dist/{chunk-ym1sb5bg.js → chunk-m7ddgrsm.js} +5 -5
  92. package/dist/{chunk-vpdx7qr3.js → chunk-mmbspaqh.js} +2 -2
  93. package/dist/{chunk-6fc8vw2v.js → chunk-mnnxa3r7.js} +7 -7
  94. package/dist/chunk-n7yk4nc1.js +2 -0
  95. package/dist/chunk-ns1jqzqk.js +2 -0
  96. package/dist/chunk-p973efbe.js +2 -0
  97. package/dist/{chunk-m8tm44rq.js → chunk-pg164sdw.js} +2 -2
  98. package/dist/{chunk-x552npae.js → chunk-pxw4edw8.js} +4 -4
  99. package/dist/chunk-q03kn4d1.js +2 -0
  100. package/dist/{chunk-1r1maqep.js → chunk-q1cvef6b.js} +3 -3
  101. package/dist/{chunk-jpqkm8tm.js → chunk-qf3axv86.js} +3 -3
  102. package/dist/{chunk-dhq80e4r.js → chunk-qhr1tkhj.js} +7 -7
  103. package/dist/chunk-qq59xzwc.js +2 -0
  104. package/dist/{chunk-h3z9b6bw.js → chunk-qx0tcsdm.js} +11 -11
  105. package/dist/chunk-r0e743c3.js +2 -0
  106. package/dist/chunk-r90v2jz6.js +2 -0
  107. package/dist/chunk-rtgf9fgc.js +2 -0
  108. package/dist/chunk-s043hpvd.js +2 -0
  109. package/dist/{chunk-hzqyfdpy.js → chunk-s2h601k7.js} +7 -7
  110. package/dist/chunk-shzesarq.js +2 -0
  111. package/dist/chunk-sjkdpsca.js +3 -0
  112. package/dist/chunk-sqpme1hg.js +2 -0
  113. package/dist/{chunk-e809x7m0.js → chunk-t212h9zm.js} +1 -1
  114. package/dist/{chunk-r47cs92n.js → chunk-tc15vkfh.js} +2 -2
  115. package/dist/chunk-thydj877.js +2 -0
  116. package/dist/{chunk-6z3e1tyz.js → chunk-tnafnb23.js} +1 -1
  117. package/dist/{chunk-ah9xyss2.js → chunk-v8ze2q95.js} +2 -2
  118. package/dist/{chunk-xytkfa48.js → chunk-vf15db1j.js} +6 -6
  119. package/dist/chunk-vv1kr9dn.js +2 -0
  120. package/dist/{chunk-dm1qh2vq.js → chunk-w24qmxc3.js} +3 -3
  121. package/dist/{chunk-nhd9m8h5.js → chunk-wkrf41se.js} +6 -6
  122. package/dist/chunk-wm9nzg76.js +2 -0
  123. package/dist/chunk-wn2gzwmv.js +2 -0
  124. package/dist/{chunk-07anexcg.js → chunk-ww28zfwt.js} +2 -2
  125. package/dist/chunk-x5qymgxa.js +2 -0
  126. package/dist/chunk-xfe2nzxd.js +2 -0
  127. package/dist/chunk-xjwgzp6s.js +2 -0
  128. package/dist/chunk-xnbkyj4g.js +2 -0
  129. package/dist/chunk-xyepqdjy.js +2 -0
  130. package/dist/{chunk-wwj8zbzc.js → chunk-y09g63k0.js} +5 -5
  131. package/dist/{chunk-3e3dpp7w.js → chunk-y5x8xnnf.js} +3 -3
  132. package/dist/chunk-y93y2qat.js +2 -0
  133. package/dist/{chunk-nh3svtvj.js → chunk-yhhfxx17.js} +5 -5
  134. package/dist/{chunk-bj29pwm0.js → chunk-zrw1zf54.js} +3 -3
  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/accessibility.d.ts +18 -0
  145. package/dist/native/accessibility.js +89 -0
  146. package/dist/native/compiler/design-tokens.d.ts +4 -0
  147. package/dist/native/compiler/design-tokens.js +28 -0
  148. package/dist/native/compiler/headwind-to-style.d.ts +5 -4
  149. package/dist/native/compiler/headwind-to-style.js +105 -65
  150. package/dist/native/compiler/html-to-ir.d.ts +3 -1
  151. package/dist/native/compiler/html-to-ir.js +49 -243
  152. package/dist/native/compiler/inline-style.d.ts +13 -0
  153. package/dist/native/compiler/inline-style.js +285 -0
  154. package/dist/native/compiler/ir.d.ts +5 -1
  155. package/dist/native/compiler/render-screen.js +3 -1
  156. package/dist/native/compiler/style-variables.d.ts +8 -0
  157. package/dist/native/compiler/style-variables.js +142 -0
  158. package/dist/native/compiler/stylesheet-theme.d.ts +6 -0
  159. package/dist/native/compiler/stylesheet-theme.js +110 -0
  160. package/dist/native/runtime/craft-bridge.js +3 -1
  161. package/dist/native/runtime/native-host.d.ts +13 -2
  162. package/dist/native/runtime/native-host.js +242 -36
  163. package/dist/native/runtime/overlay-presenter.d.ts +29 -0
  164. package/dist/native/runtime/overlay-presenter.js +69 -0
  165. package/dist/native/runtime/shared-screen.js +12 -1
  166. package/dist/native/runtime/view-operations.d.ts +20 -0
  167. package/dist/native/runtime/view-operations.js +35 -0
  168. package/dist/native/testing-mutations.d.ts +4 -0
  169. package/dist/native/testing-mutations.js +64 -0
  170. package/dist/native/testing.d.ts +2 -0
  171. package/dist/native/testing.js +18 -1
  172. package/dist/pwa.js +3 -3
  173. package/dist/ssg.js +9 -9
  174. package/dist/testing.js +2 -0
  175. package/dist/types/config-types.d.ts +2 -0
  176. package/dist/utils.d.ts +1 -1
  177. package/dist/utils.js +25 -5
  178. package/package.json +5 -5
  179. package/dist/chunk-00p22wzr.js +0 -3
  180. package/dist/chunk-0fx3ppnt.js +0 -2
  181. package/dist/chunk-0sfexf9t.js +0 -2
  182. package/dist/chunk-2927nax9.js +0 -2
  183. package/dist/chunk-2rj0ttas.js +0 -2
  184. package/dist/chunk-2rx9d75e.js +0 -4
  185. package/dist/chunk-3ae39ttg.js +0 -2
  186. package/dist/chunk-3x6p9me0.js +0 -2
  187. package/dist/chunk-440yjsk5.js +0 -2
  188. package/dist/chunk-58z26y07.js +0 -2
  189. package/dist/chunk-5db5sxy3.js +0 -3
  190. package/dist/chunk-5r9k9s3m.js +0 -2
  191. package/dist/chunk-76vza4ve.js +0 -2
  192. package/dist/chunk-84f9dnq5.js +0 -2
  193. package/dist/chunk-8tq5x4z8.js +0 -2
  194. package/dist/chunk-8y8bbsh5.js +0 -2
  195. package/dist/chunk-9kzycb15.js +0 -2
  196. package/dist/chunk-agfhb2qd.js +0 -2
  197. package/dist/chunk-ay6dzpt4.js +0 -2
  198. package/dist/chunk-b9njk81d.js +0 -2
  199. package/dist/chunk-bfbcmfww.js +0 -2
  200. package/dist/chunk-br01jvra.js +0 -2
  201. package/dist/chunk-c12y2bet.js +0 -2
  202. package/dist/chunk-c2nwchk0.js +0 -2
  203. package/dist/chunk-cxqrwvc5.js +0 -2
  204. package/dist/chunk-czea8zr1.js +0 -2
  205. package/dist/chunk-d99kfx3k.js +0 -2
  206. package/dist/chunk-dpn1pmxj.js +0 -2
  207. package/dist/chunk-dskrwa8f.js +0 -2
  208. package/dist/chunk-e6ycqvdm.js +0 -2
  209. package/dist/chunk-efgk2xv1.js +0 -2
  210. package/dist/chunk-fj70wq7k.js +0 -2
  211. package/dist/chunk-fvx6pd66.js +0 -2
  212. package/dist/chunk-hrbjapvr.js +0 -2
  213. package/dist/chunk-jc4mxq56.js +0 -2
  214. package/dist/chunk-jdpyxt8j.js +0 -2
  215. package/dist/chunk-k0zev8wc.js +0 -2
  216. package/dist/chunk-mhjwtkx9.js +0 -2
  217. package/dist/chunk-n4e02qdz.js +0 -2838
  218. package/dist/chunk-nx8rf4qd.js +0 -2
  219. package/dist/chunk-pe5bk9ns.js +0 -2
  220. package/dist/chunk-qb2j34sp.js +0 -2
  221. package/dist/chunk-qknfceta.js +0 -2
  222. package/dist/chunk-s932zfjz.js +0 -2
  223. package/dist/chunk-sf98zgw2.js +0 -2
  224. package/dist/chunk-sgsp4dph.js +0 -2
  225. package/dist/chunk-t48ws5j0.js +0 -2
  226. package/dist/chunk-tfxmzat6.js +0 -122
  227. package/dist/chunk-thbc9gtj.js +0 -2
  228. package/dist/chunk-tms7amrb.js +0 -2
  229. package/dist/chunk-tn9v10q2.js +0 -2
  230. package/dist/chunk-v0zgarvv.js +0 -2
  231. package/dist/chunk-v9jd283e.js +0 -2
  232. package/dist/chunk-vczw73ga.js +0 -2
  233. package/dist/chunk-webrqm20.js +0 -2
  234. package/dist/chunk-wg2w7zmt.js +0 -3
  235. package/dist/chunk-wgkxgsqx.js +0 -2
  236. package/dist/chunk-wngqr949.js +0 -2
  237. package/dist/chunk-xyzy84x0.js +0 -2
  238. package/dist/chunk-y1jffvkj.js +0 -2
  239. package/dist/chunk-yas134jv.js +0 -2
  240. package/dist/chunk-yd55vynh.js +0 -2
  241. package/dist/chunk-yygze2s0.js +0 -2
  242. package/dist/chunk-z732tf98.js +0 -2
  243. package/dist/chunk-ze86h6vp.js +0 -2
@@ -1,10 +1,15 @@
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";
7
+ import { accessibilityPatch, isAccessibilityAttribute } from "../accessibility.js";
5
8
  import { nativePropName } from "../prop-names.js";
6
9
  import { cloneNativeBindingNode } from "./binding-tree.js";
7
10
  import { NATIVE_FORM_ENTRIES } from "./jsc-globals.js";
11
+ import { createNativeOverlayPresenter } from "./overlay-presenter.js";
12
+ import { nativeViewError } from "./view-operations.js";
8
13
  function irDisplay(value) {
9
14
  return value === "none" || value === "grid" || value === "flex" ? value : "flex";
10
15
  }
@@ -28,6 +33,9 @@ function eventAt(payload, node, type = "") {
28
33
  };
29
34
  }
30
35
  export const HOST_METHODS = [
36
+ "parent",
37
+ "getAttribute",
38
+ "observeChildren",
31
39
  "setText",
32
40
  "setMarkup",
33
41
  "setAttribute",
@@ -47,14 +55,19 @@ export const HOST_METHODS = [
47
55
  "scopesIn"
48
56
  ];
49
57
  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;
58
+ 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;
59
+ let queue = [], scheduled = !1, counter = 0, colorScheme = options.colorScheme ?? "light", stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[colorScheme] ?? []).computed(), disposed = !1;
52
60
  const schedule = options.schedule ?? ((flush) => queueMicrotask(flush)), nextId = (prefix) => `${prefix}${++counter}`;
53
61
  function notifyAttributes(node, name) {
54
62
  for (const observer of attributeObservers.get(node) ?? [])
55
63
  if (observer.names.includes(name))
56
64
  observer.notify();
57
65
  }
66
+ function notifyChildren(node) {
67
+ for (let current = node;current; current = current.__stxOwner)
68
+ for (const notify of childObservers.get(current) ?? [])
69
+ notify();
70
+ }
58
71
  function flush() {
59
72
  scheduled = !1;
60
73
  if (queue.length === 0)
@@ -96,6 +109,7 @@ export function createNativeHost(options) {
96
109
  const record = descriptorOf(node);
97
110
  if (!record)
98
111
  return;
112
+ record.viewEpoch = (record.viewEpoch ?? 0) + 1;
99
113
  for (const handlerId of Object.values(record.events)) {
100
114
  const handler = handlers.get(handlerId);
101
115
  if (!handler)
@@ -207,24 +221,34 @@ export function createNativeHost(options) {
207
221
  callback();
208
222
  }
209
223
  }
210
- function installFormListeners(node) {
224
+ function installControlListeners(node) {
211
225
  const record = descriptorOf(node);
212
- if (!record || formControls.has(node) || !formOwner(node))
226
+ if (!record || controlsWithDefaultListeners.has(node))
227
+ return;
228
+ let delegatedPress = !1;
229
+ if (record.type === "Button" || record.type === "Pressable") {
230
+ for (let owner = node.__stxOwner;owner; owner = owner.__stxOwner)
231
+ if (componentListeners.get(owner)?.some((listener) => (NATIVE_EVENT_NAMES[listener.event.toLowerCase()] ?? listener.event) === "onPress")) {
232
+ delegatedPress = !0;
233
+ break;
234
+ }
235
+ }
236
+ if (!formOwner(node) && !delegatedPress)
213
237
  return;
214
- formControls.add(node);
238
+ controlsWithDefaultListeners.add(node);
215
239
  if (record.type === "TextInput" || record.type === "Picker" || record.type === "Checkbox") {
216
240
  host.listen(node, record.type === "TextInput" ? "input" : "change", () => {});
217
241
  host.listen(node, "focusout", () => {});
218
242
  }
219
- if (record.type === "Button")
243
+ if (record.type === "Button" || record.type === "Pressable")
220
244
  host.listen(node, "click", () => {});
221
245
  }
222
246
  function materialize(node) {
223
247
  const record = recordOf(node);
224
248
  if (record.materialized || node.__stxAnchor !== void 0)
225
249
  return;
226
- installFormListeners(node);
227
- record.style = resolveStyle(record);
250
+ installControlListeners(node);
251
+ record.style = resolveStyle(record, node.__stxId);
228
252
  record.materialized = !0;
229
253
  emit({
230
254
  op: "createNode",
@@ -246,16 +270,82 @@ export function createNativeHost(options) {
246
270
  emit({ op: "insertChild", parentId: node.__stxId, childId: child.__stxId, index: index++ });
247
271
  }
248
272
  }
249
- function resolveStyle(record) {
250
- const classes = compileClassStyles(record.classes);
251
- return { ...classes.style, ...colorScheme === "dark" ? classes.dark : {}, ...record.baseStyle };
273
+ function resolveStyle(record, id) {
274
+ const report = (diagnostic) => {
275
+ console.warn(`[STX Native] ${diagnostic.kind}: ${id}: ${diagnostic.name}`);
276
+ };
277
+ let inherited = record.inheritedVariables;
278
+ for (const source of record.styleAncestors ?? [])
279
+ inherited = parseNativeStyleLayers([source], inherited, report).variables;
280
+ const resolved = parseNativeStyleLayers([record.styleSource, record.boundStyle, record.forwardedStyle], inherited, report);
281
+ record.variables = resolved.variables;
282
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables);
283
+ return { ...classes.style, ...colorScheme === "dark" ? classes.dark : {}, ...resolved.styles[0], ...record.baseStyle, ...resolved.styles[1], ...resolved.styles[2], ...record.visible ? {} : { display: "none" } };
252
284
  }
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]));
285
+ function refreshStyleTree(node, inherited = node.__stxOwner ? descriptorOf(node.__stxOwner)?.variables : stylesheetVariables, appearanceChanged = !1) {
286
+ if (node.__stxAnchor !== void 0)
287
+ return;
288
+ const record = recordOf(node), before = record.variables;
289
+ record.inheritedVariables = inherited;
290
+ applyClasses(node.__stxId, record, !0);
291
+ const after = record.variables;
292
+ if (!appearanceChanged && before?.size === after.size && [...after].every(([name, value]) => before.has(name) && before.get(name) === value))
293
+ return;
294
+ for (const child of record.children)
295
+ refreshStyleTree(child, after, appearanceChanged);
296
+ }
297
+ function forwardedHostRoot(node, name) {
298
+ if (!isBindingNode(node) || !(node.getAttribute("data-stx-native-forward") ?? "").split(/\s+/).includes(name))
299
+ return;
300
+ const find = (candidate) => {
301
+ if (isBindingNode(candidate) && candidate.hasAttribute("data-stx-native-host-root"))
302
+ return candidate;
303
+ for (const child of recordOf(candidate).children) {
304
+ if (isBindingNode(child) && child.hasAttribute("data-stx-component-wrapper"))
305
+ continue;
306
+ const match = find(child);
307
+ if (match)
308
+ return match;
309
+ }
310
+ };
311
+ return find(node);
312
+ }
313
+ function applyForwardedStyle(node, name, value) {
314
+ const record = recordOf(node);
315
+ if (name === "class" || name === "class-name" || name === "className")
316
+ 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 ?? "");
317
+ else if (name === "style")
318
+ record.forwardedStyle = value;
319
+ else
320
+ return !1;
321
+ refreshStyleTree(node);
322
+ return !0;
323
+ }
324
+ function reflectAttribute(node, name, value, remove = !1) {
325
+ if (!isBindingNode(node) || name === "class" || name === "className")
326
+ return;
327
+ if (remove) {
328
+ if (!node.hasAttribute(name))
329
+ return;
330
+ node.removeAttribute(name);
331
+ } else {
332
+ const serialized = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
333
+ if (node.getAttribute(name) === serialized)
334
+ return;
335
+ node.setAttribute(name, serialized);
336
+ }
337
+ notifyAttributes(node, name);
338
+ }
339
+ function applyClasses(id, record, onlyIfChanged = !1) {
340
+ 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
341
  record.style = style;
256
- if (record.materialized)
342
+ if (record.materialized && changed)
257
343
  emit({ op: "updateNode", id, patch: { style: { ...patch, ...style } } });
258
- const classes = compileClassStyles(record.classes);
344
+ const classes = compileClassStyles(`${record.classes} ${record.forwardedClasses ?? ""}`, record.variables), unsupported = new Set(classes.unknown);
345
+ for (const name of unsupported)
346
+ if (!record.reportedClasses?.has(name))
347
+ console.warn(`[STX Native] unknown-class: ${id}: ${name}`);
348
+ record.reportedClasses = unsupported;
259
349
  if (record.type === "Icon" && classes.icon) {
260
350
  const icon = resolveIconName(classes.icon);
261
351
  record.props.symbol = icon.symbol;
@@ -291,6 +381,8 @@ export function createNativeHost(options) {
291
381
  if (target.__stxPositionDecorated)
292
382
  return;
293
383
  Object.defineProperties(target, {
384
+ focus: { configurable: !0, value: (focusOptions) => host.focus(node, focusOptions) },
385
+ measure: { configurable: !0, value: () => host.measure(node) },
294
386
  nextSibling: {
295
387
  configurable: !0,
296
388
  get() {
@@ -313,6 +405,24 @@ export function createNativeHost(options) {
313
405
  });
314
406
  target.__stxPositionDecorated = !0;
315
407
  }
408
+ async function withMountedView(node, request) {
409
+ await Promise.resolve();
410
+ if (disposed)
411
+ throw nativeViewError("SCREEN_CLOSED", "The native screen has closed");
412
+ const record = records.get(node.__stxId);
413
+ if (!record?.materialized || node.__stxAnchor !== void 0 || isBindingNode(node) && !node.isConnected)
414
+ throw nativeViewError("VIEW_NOT_MOUNTED", `Native view ${node.__stxId} is not mounted`);
415
+ if (!options.views)
416
+ throw nativeViewError("UNSUPPORTED", "Native view operations are unavailable");
417
+ const epoch = record.viewEpoch ?? 0;
418
+ flush();
419
+ const result = await request(options.views);
420
+ if (disposed)
421
+ throw nativeViewError("SCREEN_CLOSED", "The native screen has closed");
422
+ if (records.get(node.__stxId) !== record || (record.viewEpoch ?? 0) !== epoch)
423
+ throw nativeViewError("VIEW_NOT_MOUNTED", `Native view ${node.__stxId} changed while the operation was pending`);
424
+ return result;
425
+ }
316
426
  function setConnected(node, connected) {
317
427
  if ("isConnected" in node)
318
428
  node.isConnected = connected;
@@ -339,12 +449,15 @@ export function createNativeHost(options) {
339
449
  const suffix = /(?:^|\D)(\d+)$/.exec(node.__stxId)?.[1];
340
450
  if (suffix)
341
451
  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 = {
452
+ 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
453
  type,
344
454
  key: descriptor?.key,
345
455
  props: { ...descriptor?.props ?? {} },
346
456
  style: { ...descriptor?.style ?? {} },
347
457
  baseStyle,
458
+ styleSource: descriptor?._styleSource,
459
+ styleAncestors: descriptor?._styleAncestors,
460
+ inheritedVariables: owner ? descriptorOf(owner)?.variables : stylesheetVariables,
348
461
  classes,
349
462
  events: { ...descriptor?.events ?? {} },
350
463
  text: descriptor?.children?.find((child) => typeof child === "string"),
@@ -353,7 +466,7 @@ export function createNativeHost(options) {
353
466
  materialized: !0,
354
467
  controlDefaults: { value: descriptor?.props.value ?? "", checked: descriptor?.props.checked ?? descriptor?.props.value ?? !1 }
355
468
  };
356
- record.style = resolveStyle(record);
469
+ record.style = resolveStyle(record, node.__stxId);
357
470
  if (descriptor)
358
471
  descriptor.style = { ...record.style };
359
472
  records.set(node.__stxId, record);
@@ -365,22 +478,82 @@ export function createNativeHost(options) {
365
478
  if (!children.some((child) => child.__stxId === node.__stxId))
366
479
  children.push(node);
367
480
  }
368
- installFormListeners(node);
481
+ installControlListeners(node);
369
482
  return node;
370
483
  }
371
- const host = {
484
+ const overlayPresenter = createNativeOverlayPresenter({
485
+ canFocus: options.views?.capabilities.focus === !0,
486
+ focus: (node, focusOptions) => host.focus(node, focusOptions),
487
+ descendants: collectDescendants,
488
+ hasAutofocus: (node) => {
489
+ const value = descriptorOf(node)?.props.autoFocus;
490
+ return value === !0 || value === "" || value === "true";
491
+ },
492
+ isAvailable: (node) => {
493
+ if (!records.has(node.__stxId) || disabled(recordOf(node)))
494
+ return !1;
495
+ for (let current = node;current; current = current.__stxOwner ?? null) {
496
+ const record = records.get(current.__stxId);
497
+ if (!record?.materialized || !record.visible || record.style.display === "none" || record.type === "Modal" && (record.props.visible === !1 || record.props.visible === "false"))
498
+ return !1;
499
+ }
500
+ return !0;
501
+ },
502
+ type: (node) => descriptorOf(node)?.type,
503
+ setAttribute: (node, name, value) => host.setAttribute(node, name, value),
504
+ setStyle: (node, value) => host.setStyle(node, value),
505
+ listen: (node, event, callback) => host.listen(node, event, callback)
506
+ }), host = {
372
507
  isNative: !0,
508
+ focus: (node, focusOptions) => withMountedView(node, (views) => views.focus(node.__stxId, focusOptions)),
509
+ measure: (node) => withMountedView(node, (views) => views.measure(node.__stxId)),
510
+ syncOverlays: (entries) => overlayPresenter.sync(entries),
511
+ parent(node) {
512
+ return node?.__stxOwner ?? null;
513
+ },
514
+ getAttribute(node, name) {
515
+ if (!node)
516
+ return null;
517
+ if (isBindingNode(node))
518
+ return node.getAttribute(name);
519
+ const value = descriptorOf(node)?.props[nativePropName(name)];
520
+ return value == null || value === !1 ? null : value === !0 ? "" : String(value);
521
+ },
522
+ observeChildren(node, callback) {
523
+ const observers = childObservers.get(node) ?? new Set;
524
+ childObservers.set(node, observers);
525
+ let active = !0, pending = !1;
526
+ const notify = () => {
527
+ if (!active || pending || disposed)
528
+ return;
529
+ pending = !0;
530
+ queueMicrotask(() => {
531
+ pending = !1;
532
+ if (active && !disposed)
533
+ callback();
534
+ });
535
+ };
536
+ observers.add(notify);
537
+ return () => {
538
+ active = !1;
539
+ observers.delete(notify);
540
+ };
541
+ },
373
542
  adopt,
374
543
  setColorScheme(scheme) {
375
544
  if (scheme === colorScheme)
376
545
  return;
377
546
  colorScheme = scheme;
378
- for (const [id, record] of records)
379
- applyClasses(id, record);
547
+ stylesheetVariables = createStyleVariables(options.stylesheetTheme?.[scheme] ?? []).computed();
548
+ const children = new Set([...records.values()].flatMap((record) => record.children.map((child) => child.__stxId)));
549
+ for (const id of records.keys())
550
+ if (!children.has(id))
551
+ refreshStyleTree({ __stxId: id }, stylesheetVariables, !0);
380
552
  },
381
553
  pending: () => queue.length,
382
554
  flush,
383
555
  dispose() {
556
+ overlayPresenter.dispose();
384
557
  disposed = !0;
385
558
  queue = [];
386
559
  handlers.clear();
@@ -391,7 +564,7 @@ export function createNativeHost(options) {
391
564
  const describe = (node) => {
392
565
  const record = recordOf(node);
393
566
  if (!record.materialized)
394
- record.style = resolveStyle(record);
567
+ record.style = resolveStyle(record, node.__stxId);
395
568
  record.materialized = !0;
396
569
  const children = record.children.filter((child) => child.__stxAnchor === void 0).map(describe);
397
570
  return {
@@ -433,12 +606,13 @@ export function createNativeHost(options) {
433
606
  }
434
607
  },
435
608
  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
- }
609
+ const forwarded = forwardedHostRoot(node, name);
610
+ reflectAttribute(node, name, value);
611
+ if (forwarded) {
612
+ reflectAttribute(forwarded, name, value);
613
+ if (applyForwardedStyle(forwarded, name, value))
614
+ return;
615
+ node = forwarded;
442
616
  }
443
617
  if (name === "class" || name === "className") {
444
618
  const record = recordOf(node);
@@ -454,6 +628,8 @@ export function createNativeHost(options) {
454
628
  this.setAttribute(node, "symbol", icon.symbol);
455
629
  }
456
630
  const patch = { [prop]: value };
631
+ if (isAccessibilityAttribute(name))
632
+ Object.assign(patch, Object.assign(record.props, accessibilityPatch(name, value, record.props)));
457
633
  if (SVG_NODE_TYPES.has(record.type)) {
458
634
  if (prop === "strokeDasharray" && value != null && !Array.isArray(value))
459
635
  patch[prop] = record.props[prop] = String(value).split(/[\s,]+/).map(Number).filter(Number.isFinite);
@@ -466,9 +642,13 @@ export function createNativeHost(options) {
466
642
  emit({ op: "updateNode", id: node.__stxId, patch: { props: patch } });
467
643
  },
468
644
  removeAttribute(node, name) {
469
- if (isBindingNode(node) && name !== "class" && name !== "className" && node.hasAttribute(name)) {
470
- node.removeAttribute(name);
471
- notifyAttributes(node, name);
645
+ const forwarded = forwardedHostRoot(node, name);
646
+ reflectAttribute(node, name, void 0, !0);
647
+ if (forwarded) {
648
+ reflectAttribute(forwarded, name, void 0, !0);
649
+ if (applyForwardedStyle(forwarded, name, void 0))
650
+ return;
651
+ node = forwarded;
472
652
  }
473
653
  if (name === "class" || name === "className") {
474
654
  this.setAttribute(node, name, "");
@@ -477,6 +657,8 @@ export function createNativeHost(options) {
477
657
  const prop = nativePropName(name), record = recordOf(node);
478
658
  delete record.props[prop];
479
659
  const patch = { [prop]: null };
660
+ if (isAccessibilityAttribute(name))
661
+ Object.assign(patch, Object.assign(record.props, accessibilityPatch(name, void 0, record.props)));
480
662
  if (affectsGeometry(record.type, prop))
481
663
  patch.geometry = record.props.geometry = svgGeometry(record.type, record.props);
482
664
  if (record.materialized)
@@ -502,13 +684,19 @@ export function createNativeHost(options) {
502
684
  observers.delete(observer);
503
685
  };
504
686
  },
505
- setStyle(node, value) {
687
+ setStyle(node, value, replaceBinding = !1) {
688
+ const record = recordOf(node);
689
+ if (replaceBinding) {
690
+ record.boundStyle = value;
691
+ refreshStyleTree(node);
692
+ return;
693
+ }
506
694
  if (typeof value !== "object" || value === null || Array.isArray(value))
507
695
  return;
508
696
  const style = value;
509
- Object.assign(recordOf(node).baseStyle, style);
510
- Object.assign(recordOf(node).style, style);
511
- if (recordOf(node).materialized)
697
+ Object.assign(record.baseStyle, style);
698
+ Object.assign(record.style, style);
699
+ if (record.materialized)
512
700
  emit({ op: "updateNode", id: node.__stxId, patch: { style } });
513
701
  },
514
702
  emitComponentEvent(node, event) {
@@ -634,6 +822,11 @@ export function createNativeHost(options) {
634
822
  record.events[nativeEvent] = id;
635
823
  if (record.materialized)
636
824
  emit({ op: "updateNode", id: node.__stxId, patch: { events: { [nativeEvent]: id } } });
825
+ if (nativeEvent === "onPress") {
826
+ for (const child of collectDescendants(node))
827
+ if (["Button", "Pressable"].includes(descriptorOf(child)?.type ?? ""))
828
+ installControlListeners(child);
829
+ }
637
830
  },
638
831
  dispatch(handlerId, payload) {
639
832
  handlers.get(handlerId)?.(payload);
@@ -661,7 +854,8 @@ export function createNativeHost(options) {
661
854
  record.baseStyle.display = record.shownDisplay;
662
855
  record.shownDisplay = void 0;
663
856
  }
664
- const display = visible ? irDisplay(resolveStyle(record).display) : "none";
857
+ record.style = resolveStyle(record, node.__stxId);
858
+ const display = visible ? irDisplay(record.style.display) : "none";
665
859
  if (record.materialized)
666
860
  emit({ op: "updateNode", id: node.__stxId, patch: { style: { display } } });
667
861
  return was;
@@ -693,7 +887,14 @@ export function createNativeHost(options) {
693
887
  props: { ...descriptor.props, __stxId: copy.__stxId },
694
888
  style: { ...descriptor.style },
695
889
  baseStyle: { ...descriptor.baseStyle },
890
+ styleSource: descriptor.styleSource,
891
+ styleAncestors: descriptor.styleAncestors,
892
+ inheritedVariables: descriptor.inheritedVariables,
893
+ variables: descriptor.variables,
894
+ boundStyle: descriptor.boundStyle,
696
895
  classes: descriptor.classes,
896
+ forwardedClasses: descriptor.forwardedClasses,
897
+ forwardedStyle: descriptor.forwardedStyle,
697
898
  events: { ...descriptor.events },
698
899
  text: descriptor.text,
699
900
  children: [],
@@ -722,8 +923,12 @@ export function createNativeHost(options) {
722
923
  const index = before ? Math.max(0, record.children.findIndex((child) => child.__stxId === before.__stxId)) : record.children.length;
723
924
  record.children.splice(index, 0, node);
724
925
  node.__stxOwner = parent;
926
+ refreshStyleTree(node, record.variables);
725
927
  insertIntoBindingParent(parent, node, index);
726
928
  setConnected(node, record.materialized);
929
+ if (oldOwner && oldOwner !== parent)
930
+ notifyChildren(oldOwner);
931
+ notifyChildren(parent);
727
932
  if (node.__stxAnchor !== void 0 || !record.materialized)
728
933
  return;
729
934
  materialize(node);
@@ -766,6 +971,7 @@ export function createNativeHost(options) {
766
971
  setConnected(node, !1);
767
972
  releaseHandlers(node);
768
973
  retainDetachedDescriptors(node);
974
+ notifyChildren(owner);
769
975
  if (node.__stxAnchor !== void 0 || !wasMaterialized)
770
976
  return;
771
977
  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
+ }