@stacksjs/stx 0.2.412 → 0.2.414

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 (350) hide show
  1. package/dist/appearance-bootstrap.js +1 -1
  2. package/dist/binding-manifest.d.ts +1 -1
  3. package/dist/builtins/image-delivery.d.ts +38 -0
  4. package/dist/builtins/image-delivery.js +17 -0
  5. package/dist/builtins/stx-image.js +1 -5
  6. package/dist/bundle-analyzer.js +20 -20
  7. package/dist/chunk-020xyn9q.js +3 -0
  8. package/dist/chunk-04jhmfbz.js +2 -0
  9. package/dist/chunk-10957mcb.js +2 -0
  10. package/dist/chunk-1098mas0.js +2 -0
  11. package/dist/chunk-169n1vpx.js +12 -0
  12. package/dist/chunk-1b6t12hd.js +2 -0
  13. package/dist/chunk-1chw8xsw.js +2 -0
  14. package/dist/chunk-1xdzcy9d.js +14 -0
  15. package/dist/chunk-2ce7f416.js +2 -0
  16. package/dist/chunk-2gr351s0.js +7 -0
  17. package/dist/chunk-2mkcjw08.js +2 -0
  18. package/dist/chunk-2v8wztd5.js +2 -0
  19. package/dist/chunk-340a824p.js +2 -0
  20. package/dist/chunk-39g1134q.js +2 -0
  21. package/dist/chunk-3c74vag1.js +2 -0
  22. package/dist/chunk-3kthfs03.js +3 -0
  23. package/dist/chunk-3qn1wcdg.js +2 -0
  24. package/dist/chunk-3s2vnqcf.js +2 -0
  25. package/dist/chunk-48bwk47q.js +2 -0
  26. package/dist/chunk-4bjravgk.js +2 -0
  27. package/dist/chunk-4jjme6a5.js +2 -0
  28. package/dist/chunk-5g3y8kym.js +2 -0
  29. package/dist/chunk-5gsxpaqk.js +2 -0
  30. package/dist/{chunk-bwsxym3d.js → chunk-5qns2sdz.js} +17 -17
  31. package/dist/chunk-69mc2np8.js +2785 -0
  32. package/dist/chunk-6cfa3g0r.js +2 -0
  33. package/dist/{chunk-bjar18jd.js → chunk-6h38kkjf.js} +46 -52
  34. package/dist/chunk-6hc5vz20.js +3 -0
  35. package/dist/chunk-6q6g76vg.js +499 -0
  36. package/dist/{chunk-dbc5awz9.js → chunk-6sgswrqw.js} +29 -29
  37. package/dist/chunk-6y8hnymb.js +2 -0
  38. package/dist/chunk-74j18qk0.js +930 -0
  39. package/dist/chunk-752hw7cd.js +4 -0
  40. package/dist/{chunk-t5ja7qkn.js → chunk-765e1s44.js} +11 -76
  41. package/dist/chunk-7gkv67ky.js +4 -0
  42. package/dist/chunk-7z2ra0yf.js +2 -0
  43. package/dist/chunk-866n724v.js +2 -0
  44. package/dist/chunk-8nhshfz6.js +5 -0
  45. package/dist/chunk-92ps1xpk.js +2 -0
  46. package/dist/chunk-9g27ybyr.js +3 -0
  47. package/dist/{chunk-xq1acw1r.js → chunk-9pt8fd2n.js} +13 -13
  48. package/dist/{chunk-qvnbnsv9.js → chunk-9vrja6vp.js} +4 -4
  49. package/dist/chunk-9xrbve19.js +2 -0
  50. package/dist/chunk-a688m6js.js +3 -0
  51. package/dist/chunk-afhxw2t8.js +2 -0
  52. package/dist/chunk-ak1cgcah.js +5 -0
  53. package/dist/{chunk-4m7ajama.js → chunk-amd6ey3t.js} +14 -14
  54. package/dist/chunk-apg16xcn.js +2 -0
  55. package/dist/chunk-b52s5z0c.js +2 -0
  56. package/dist/chunk-b84h16er.js +61 -0
  57. package/dist/{chunk-hx998w7n.js → chunk-bay9s6rs.js} +13 -13
  58. package/dist/chunk-bmt7w2pk.js +2 -0
  59. package/dist/chunk-btmhj5t7.js +2 -0
  60. package/dist/chunk-ce1sejr3.js +3 -0
  61. package/dist/chunk-cg8hg6cs.js +3 -0
  62. package/dist/{chunk-8wp64mym.js → chunk-czxt605c.js} +4 -5
  63. package/dist/chunk-d44b9ktb.js +4 -0
  64. package/dist/chunk-daz5aqcf.js +24 -0
  65. package/dist/chunk-dgdm3hy3.js +2 -0
  66. package/dist/chunk-dvgv8nry.js +11 -0
  67. package/dist/chunk-dx7n22ed.js +2 -0
  68. package/dist/chunk-e57rhf65.js +3 -0
  69. package/dist/chunk-eed4fwps.js +3 -0
  70. package/dist/chunk-ej9j6k1q.js +3 -0
  71. package/dist/chunk-et0rr8c7.js +3 -0
  72. package/dist/chunk-f46qsp4m.js +4 -0
  73. package/dist/chunk-f6az0xj5.js +2 -0
  74. package/dist/{chunk-bjcsc6wx.js → chunk-fh1qrp68.js} +21 -21
  75. package/dist/chunk-fjs0a8h7.js +2 -0
  76. package/dist/chunk-fr2txj8q.js +829 -0
  77. package/dist/{chunk-vx86cf4r.js → chunk-ft4p6d28.js} +14 -14
  78. package/dist/chunk-fyzajkrx.js +2 -0
  79. package/dist/chunk-fzapbw9p.js +3 -0
  80. package/dist/chunk-g578mcb0.js +194 -0
  81. package/dist/chunk-gawrg4gb.js +216 -0
  82. package/dist/chunk-gw07qmjk.js +2 -0
  83. package/dist/chunk-h0atqq82.js +32 -0
  84. package/dist/chunk-h6zsqb9r.js +3 -0
  85. package/dist/{chunk-hdysywd8.js → chunk-h85hrwkq.js} +13 -13
  86. package/dist/chunk-hbxz85wy.js +2 -0
  87. package/dist/chunk-hjg3ndgh.js +2 -0
  88. package/dist/chunk-hkxsewzk.js +2 -0
  89. package/dist/chunk-hrbbbtbn.js +2 -0
  90. package/dist/chunk-j03revz2.js +8 -0
  91. package/dist/chunk-j9qcrwbg.js +2 -0
  92. package/dist/chunk-jk4njz0w.js +2 -0
  93. package/dist/chunk-jmabeqfq.js +2 -0
  94. package/dist/chunk-jt0n43mk.js +2 -0
  95. package/dist/chunk-kjbv8a3m.js +2 -0
  96. package/dist/chunk-m1vdghnx.js +2 -0
  97. package/dist/chunk-m4sk62wb.js +5 -0
  98. package/dist/chunk-md8rqn48.js +30 -0
  99. package/dist/chunk-mepdnezf.js +17 -0
  100. package/dist/chunk-mhq0pjws.js +2 -0
  101. package/dist/chunk-mp6hy8g4.js +2 -0
  102. package/dist/chunk-ngc2wke4.js +3 -0
  103. package/dist/chunk-nn2vstke.js +2 -0
  104. package/dist/chunk-p2v2a68k.js +2 -0
  105. package/dist/{chunk-qn5srnj3.js → chunk-pbh4smw3.js} +16 -16
  106. package/dist/chunk-pdt69hpb.js +2 -0
  107. package/dist/chunk-pgzvyrv6.js +29 -0
  108. package/dist/chunk-pj1wg7jg.js +2 -0
  109. package/dist/chunk-pqxzp1bb.js +3 -0
  110. package/dist/chunk-px7fvbj6.js +3 -0
  111. package/dist/chunk-q4c06e8x.js +20 -0
  112. package/dist/chunk-q6vrb2pe.js +2 -0
  113. package/dist/chunk-q7qchkvk.js +2 -0
  114. package/dist/chunk-q9bdh4s5.js +8 -0
  115. package/dist/chunk-qet5gc6s.js +2033 -0
  116. package/dist/chunk-qz519eyp.js +2 -0
  117. package/dist/chunk-r3f9jcf7.js +5 -0
  118. package/dist/chunk-rs4v4fha.js +4 -0
  119. package/dist/chunk-s2x4wcrz.js +2 -0
  120. package/dist/chunk-s5xezjps.js +3 -0
  121. package/dist/chunk-scezfp0w.js +30 -0
  122. package/dist/chunk-sd321bn3.js +2 -0
  123. package/dist/{chunk-eenk6s3t.js → chunk-sd47dzs0.js} +79 -79
  124. package/dist/chunk-se7mwqd1.js +2 -0
  125. package/dist/chunk-shr559s7.js +3 -0
  126. package/dist/chunk-syaw6b75.js +2 -0
  127. package/dist/chunk-t4hzprsm.js +3 -0
  128. package/dist/{chunk-s9za1vvd.js → chunk-t61vdbje.js} +89 -89
  129. package/dist/chunk-tfexmdkt.js +3 -0
  130. package/dist/chunk-thyt8ed8.js +6 -0
  131. package/dist/chunk-v091jft4.js +12 -0
  132. package/dist/chunk-v4vaqxrf.js +33 -0
  133. package/dist/chunk-vgvtnwxa.js +4 -0
  134. package/dist/chunk-x0q32ees.js +3 -0
  135. package/dist/chunk-x5bpeb4a.js +2 -0
  136. package/dist/chunk-x72tv2cg.js +3 -0
  137. package/dist/chunk-xfp7k0v8.js +64 -0
  138. package/dist/chunk-xtdw3692.js +6 -0
  139. package/dist/chunk-y1cmjvk3.js +43 -0
  140. package/dist/chunk-y5310237.js +311 -0
  141. package/dist/chunk-ya0qecph.js +27 -0
  142. package/dist/chunk-yazk54jr.js +8 -0
  143. package/dist/chunk-ydjfar14.js +2 -0
  144. package/dist/chunk-ym95v4nc.js +3 -0
  145. package/dist/chunk-ynvdvbat.js +18 -0
  146. package/dist/chunk-yvx1ap9b.js +3 -0
  147. package/dist/chunk-z0g9jvv0.js +40 -0
  148. package/dist/chunk-z6d0jmjb.js +2 -0
  149. package/dist/{chunk-fpwzacpm.js → chunk-zhxdpzga.js} +4 -4
  150. package/dist/cli.js +110 -110
  151. package/dist/craft-entry.js +7 -7
  152. package/dist/craft.js +7 -7
  153. package/dist/database.js +2 -2
  154. package/dist/image-optimization/component.js +4 -4
  155. package/dist/index.d.ts +2 -0
  156. package/dist/index.js +1 -0
  157. package/dist/media/image/component.js +5 -5
  158. package/dist/media/protected/component.js +2 -2
  159. package/dist/media/video/index.js +4 -4
  160. package/dist/native/bridge/protocol.d.ts +325 -0
  161. package/dist/native/bridge/protocol.js +219 -0
  162. package/dist/native/cli.d.ts +24 -0
  163. package/dist/native/cli.js +52 -0
  164. package/dist/native/compiler/bundle.d.ts +41 -0
  165. package/dist/native/compiler/bundle.js +90 -0
  166. package/dist/native/compiler/client-script.d.ts +8 -0
  167. package/dist/native/compiler/client-script.js +31 -0
  168. package/dist/native/compiler/codegen.d.ts +10 -0
  169. package/dist/native/compiler/codegen.js +145 -0
  170. package/dist/native/compiler/headwind-to-style.d.ts +395 -0
  171. package/dist/native/compiler/headwind-to-style.js +1163 -0
  172. package/dist/native/compiler/html-to-ir.d.ts +41 -0
  173. package/dist/native/compiler/html-to-ir.js +411 -0
  174. package/dist/native/compiler/icons.d.ts +220 -0
  175. package/dist/native/compiler/icons.js +208 -0
  176. package/dist/native/compiler/ir.d.ts +234 -0
  177. package/dist/native/compiler/ir.js +15 -0
  178. package/dist/native/compiler/parser.d.ts +88 -0
  179. package/dist/native/compiler/parser.js +753 -0
  180. package/dist/native/compiler/render-screen.d.ts +26 -0
  181. package/dist/native/compiler/render-screen.js +31 -0
  182. package/dist/native/components/primitives.d.ts +291 -0
  183. package/dist/native/components/primitives.js +22 -0
  184. package/dist/native/hot-reload/client.d.ts +62 -0
  185. package/dist/native/hot-reload/client.js +324 -0
  186. package/dist/native/index.d.ts +90 -0
  187. package/dist/native/index.js +34 -0
  188. package/dist/native/primitives/ActivityIndicator.stx +5 -0
  189. package/dist/native/primitives/Button.stx +5 -0
  190. package/dist/native/primitives/DatePicker.stx +5 -0
  191. package/dist/native/primitives/FlatList.stx +5 -0
  192. package/dist/native/primitives/Image.stx +5 -0
  193. package/dist/native/primitives/ImageBackground.stx +5 -0
  194. package/dist/native/primitives/KeyboardAvoidingView.stx +5 -0
  195. package/dist/native/primitives/Modal.stx +5 -0
  196. package/dist/native/primitives/Picker.stx +5 -0
  197. package/dist/native/primitives/Pressable.stx +5 -0
  198. package/dist/native/primitives/RefreshControl.stx +5 -0
  199. package/dist/native/primitives/SafeAreaView.stx +5 -0
  200. package/dist/native/primitives/ScrollView.stx +5 -0
  201. package/dist/native/primitives/SectionList.stx +5 -0
  202. package/dist/native/primitives/Slider.stx +5 -0
  203. package/dist/native/primitives/StatusBar.stx +5 -0
  204. package/dist/native/primitives/Switch.stx +5 -0
  205. package/dist/native/primitives/Text.stx +5 -0
  206. package/dist/native/primitives/TextInput.stx +5 -0
  207. package/dist/native/primitives/TouchableHighlight.stx +5 -0
  208. package/dist/native/primitives/TouchableOpacity.stx +5 -0
  209. package/dist/native/primitives/View.stx +5 -0
  210. package/dist/native/runtime/craft.d.ts +75 -0
  211. package/dist/native/runtime/craft.js +0 -0
  212. package/dist/native/runtime/entry.d.ts +1 -0
  213. package/dist/native/runtime/entry.js +3 -0
  214. package/dist/native/runtime/index.d.ts +45 -0
  215. package/dist/native/runtime/index.js +165 -0
  216. package/dist/native/runtime/native-host.d.ts +33 -0
  217. package/dist/native/runtime/native-host.js +184 -0
  218. package/dist/native/runtime/screen.d.ts +43 -0
  219. package/dist/native/runtime/screen.js +808 -0
  220. package/dist/pwa/service-worker.js +1 -1
  221. package/dist/pwa/workbox.js +1 -1
  222. package/dist/pwa.js +8 -8
  223. package/dist/site-url.d.ts +1 -1
  224. package/dist/ssg.js +53 -53
  225. package/dist/visual-testing.js +42 -42
  226. package/dist/web-components/reactive-generator.js +2 -2
  227. package/package.json +9 -5
  228. package/dist/chunk-00g9x6w2.js +0 -2
  229. package/dist/chunk-04tgatyy.js +0 -2
  230. package/dist/chunk-097jnwd5.js +0 -2
  231. package/dist/chunk-0btmm4m2.js +0 -147
  232. package/dist/chunk-0c2h69k2.js +0 -4
  233. package/dist/chunk-0pkk226n.js +0 -2
  234. package/dist/chunk-0we9nw1d.js +0 -3
  235. package/dist/chunk-0y46fbkx.js +0 -3
  236. package/dist/chunk-18n1ftn0.js +0 -33
  237. package/dist/chunk-1a0v39k5.js +0 -3
  238. package/dist/chunk-1fs9jvpb.js +0 -2
  239. package/dist/chunk-1qq26zt0.js +0 -2
  240. package/dist/chunk-1te8k8gp.js +0 -3
  241. package/dist/chunk-1ws3xcea.js +0 -1199
  242. package/dist/chunk-213jwgpx.js +0 -3
  243. package/dist/chunk-24w86pek.js +0 -32
  244. package/dist/chunk-27fgag95.js +0 -4
  245. package/dist/chunk-2fw05hs2.js +0 -3
  246. package/dist/chunk-2tbez006.js +0 -2
  247. package/dist/chunk-38wvkv3s.js +0 -2
  248. package/dist/chunk-3rkejwjp.js +0 -2
  249. package/dist/chunk-3t65wb35.js +0 -2
  250. package/dist/chunk-3w6z6tw9.js +0 -2
  251. package/dist/chunk-4q1c6fw2.js +0 -7
  252. package/dist/chunk-50pszj17.js +0 -2
  253. package/dist/chunk-563shnkz.js +0 -3
  254. package/dist/chunk-5h104qh1.js +0 -2
  255. package/dist/chunk-5qjk7drw.js +0 -20
  256. package/dist/chunk-603x5gb2.js +0 -2
  257. package/dist/chunk-6kd5jjwc.js +0 -2
  258. package/dist/chunk-6kdrncsx.js +0 -30
  259. package/dist/chunk-6zggmce7.js +0 -4422
  260. package/dist/chunk-72rwcbp6.js +0 -3
  261. package/dist/chunk-76w34xne.js +0 -3
  262. package/dist/chunk-7dmgt8at.js +0 -2
  263. package/dist/chunk-82pd4b5w.js +0 -2
  264. package/dist/chunk-8d7nf67s.js +0 -2
  265. package/dist/chunk-8w2mqdnv.js +0 -2
  266. package/dist/chunk-90b2vt2n.js +0 -2
  267. package/dist/chunk-9e8t0twa.js +0 -3
  268. package/dist/chunk-9fqp72ze.js +0 -5
  269. package/dist/chunk-9xew0kgf.js +0 -2
  270. package/dist/chunk-a7bnvz91.js +0 -24
  271. package/dist/chunk-akwd34xt.js +0 -29
  272. package/dist/chunk-anydpa34.js +0 -3
  273. package/dist/chunk-aq1xq0r4.js +0 -16
  274. package/dist/chunk-bbt3tp6f.js +0 -499
  275. package/dist/chunk-bn1edb1y.js +0 -47
  276. package/dist/chunk-btd7ds3x.js +0 -2
  277. package/dist/chunk-c4511wng.js +0 -2
  278. package/dist/chunk-c4h579e3.js +0 -2
  279. package/dist/chunk-cj3adc77.js +0 -5
  280. package/dist/chunk-cs54ek9m.js +0 -6
  281. package/dist/chunk-ct1jwd4r.js +0 -2
  282. package/dist/chunk-cxrgxzxc.js +0 -2
  283. package/dist/chunk-de8t7sc9.js +0 -17
  284. package/dist/chunk-fcnrgxck.js +0 -2
  285. package/dist/chunk-fqzcft9d.js +0 -2
  286. package/dist/chunk-gbmeh7jg.js +0 -3
  287. package/dist/chunk-gc06g35w.js +0 -2
  288. package/dist/chunk-gs18069g.js +0 -194
  289. package/dist/chunk-gvbf1mhs.js +0 -930
  290. package/dist/chunk-h564hgzt.js +0 -2
  291. package/dist/chunk-h83jrhfq.js +0 -3
  292. package/dist/chunk-hj4vpyhp.js +0 -2
  293. package/dist/chunk-hrkvsj5c.js +0 -11
  294. package/dist/chunk-hyr4ag1k.js +0 -2
  295. package/dist/chunk-jxvmf02k.js +0 -2
  296. package/dist/chunk-k5ptvy0b.js +0 -4
  297. package/dist/chunk-k80sn8d1.js +0 -2
  298. package/dist/chunk-k8t2cmyd.js +0 -2
  299. package/dist/chunk-kmsyvaex.js +0 -8
  300. package/dist/chunk-kq4b6cwj.js +0 -2
  301. package/dist/chunk-kvmx7dnb.js +0 -2
  302. package/dist/chunk-kxc2h5vn.js +0 -5
  303. package/dist/chunk-mbxehgrq.js +0 -2
  304. package/dist/chunk-mgnq5de2.js +0 -2
  305. package/dist/chunk-mgrckqww.js +0 -2
  306. package/dist/chunk-mq5ewmz6.js +0 -2
  307. package/dist/chunk-mrahwn5v.js +0 -8
  308. package/dist/chunk-n2swas11.js +0 -3
  309. package/dist/chunk-n4299xgy.js +0 -2
  310. package/dist/chunk-naw4jt7j.js +0 -2
  311. package/dist/chunk-ny67c03k.js +0 -3
  312. package/dist/chunk-p4jb9v0w.js +0 -2
  313. package/dist/chunk-p4zrvt5f.js +0 -14
  314. package/dist/chunk-p5wp0ce6.js +0 -43
  315. package/dist/chunk-pcxp4r9n.js +0 -3
  316. package/dist/chunk-pjrn29gg.js +0 -2
  317. package/dist/chunk-prxwsp7n.js +0 -2
  318. package/dist/chunk-py2r6wtv.js +0 -2
  319. package/dist/chunk-q738pwv6.js +0 -2
  320. package/dist/chunk-q9n5swx7.js +0 -3
  321. package/dist/chunk-qmmp5kb5.js +0 -2
  322. package/dist/chunk-qqpqgwvb.js +0 -30
  323. package/dist/chunk-rcv2ehpq.js +0 -18
  324. package/dist/chunk-rq414kn5.js +0 -3
  325. package/dist/chunk-rz9f3zqz.js +0 -7
  326. package/dist/chunk-s6g8wksg.js +0 -2
  327. package/dist/chunk-s8jd13nb.js +0 -3
  328. package/dist/chunk-spxsw4mp.js +0 -2
  329. package/dist/chunk-strcy64y.js +0 -2
  330. package/dist/chunk-t1htzg9e.js +0 -4
  331. package/dist/chunk-t1tdjjht.js +0 -216
  332. package/dist/chunk-tat1cjec.js +0 -2
  333. package/dist/chunk-td08rnk3.js +0 -3
  334. package/dist/chunk-tgadbsd4.js +0 -2
  335. package/dist/chunk-tgrpp58r.js +0 -2
  336. package/dist/chunk-tkyrk66a.js +0 -3
  337. package/dist/chunk-tp8pzf94.js +0 -3
  338. package/dist/chunk-twz64kvy.js +0 -2
  339. package/dist/chunk-v3nwkveg.js +0 -12
  340. package/dist/chunk-vsbmc9kt.js +0 -2
  341. package/dist/chunk-vzgzaw66.js +0 -12
  342. package/dist/chunk-wc66mcn4.js +0 -4367
  343. package/dist/chunk-wkanrfb3.js +0 -2
  344. package/dist/chunk-x8f6wqxd.js +0 -2
  345. package/dist/chunk-xsng1mtq.js +0 -3
  346. package/dist/chunk-xwts5yky.js +0 -4
  347. package/dist/chunk-z5rwnnk1.js +0 -3
  348. package/dist/chunk-zcz9rs6p.js +0 -3
  349. package/dist/chunk-zpcnbdhn.js +0 -64
  350. package/dist/chunk-zq4ssxj9.js +0 -8
@@ -0,0 +1,808 @@
1
+ import { compileClassStyles } from "../compiler/headwind-to-style.js";
2
+ import { resolveIconName } from "../compiler/icons.js";
3
+ const g = globalThis;
4
+ function isExpressionRef(value) {
5
+ return value !== null && typeof value === "object" && typeof value.$x === "number" && Object.keys(value).length === 1;
6
+ }
7
+ function hasExpressions(value) {
8
+ if (isExpressionRef(value))
9
+ return !0;
10
+ if (Array.isArray(value))
11
+ return value.some(hasExpressions);
12
+ if (value && typeof value === "object")
13
+ return Object.keys(value).some((key) => hasExpressions(value[key]));
14
+ return !1;
15
+ }
16
+ const classCache = new Map;
17
+ function classStyles(classes) {
18
+ let cached = classCache.get(classes);
19
+ if (!cached) {
20
+ cached = compileClassStyles(classes);
21
+ classCache.set(classes, cached);
22
+ }
23
+ return cached;
24
+ }
25
+ export function normalizeClass(value) {
26
+ if (value == null || value === !1)
27
+ return "";
28
+ if (typeof value === "string")
29
+ return value;
30
+ if (Array.isArray(value))
31
+ return value.map(normalizeClass).filter(Boolean).join(" ");
32
+ if (typeof value === "object")
33
+ return Object.keys(value).filter((name) => value[name]).join(" ");
34
+ return String(value);
35
+ }
36
+ export function normalizeStyle(value) {
37
+ if (!value)
38
+ return {};
39
+ if (Array.isArray(value))
40
+ return Object.assign({}, ...value.map(normalizeStyle));
41
+ if (typeof value === "object")
42
+ return value;
43
+ const style = {};
44
+ for (const declaration of String(value).split(";")) {
45
+ const colon = declaration.indexOf(":");
46
+ if (colon === -1)
47
+ continue;
48
+ const property = declaration.slice(0, colon).trim().replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()), raw = declaration.slice(colon + 1).trim();
49
+ if (!property || !raw)
50
+ continue;
51
+ const pixels = /^(-?[\d.]+)(px)?$/.exec(raw);
52
+ style[property] = pixels ? Number.parseFloat(pixels[1]) : raw;
53
+ }
54
+ return style;
55
+ }
56
+ export function createRuntime(bridge, options = {}) {
57
+ const routeName = options.routeName ?? "main", routeNames = options.routeNames ?? [routeName], pendingAPI = new Map, appStateHandlers = new Set, deepLinkHandlers = new Set, navButtonHandlers = new Set, navButtonPresses = new Map, scheduleTimeout = typeof g.setTimeout === "function" ? g.setTimeout.bind(g) : null, cancelTimeout = typeof g.clearTimeout === "function" ? g.clearTimeout.bind(g) : null;
58
+ let currentAppState = ["active", "inactive", "background"].includes(bridge.initialAppState) ? bridge.initialAppState : "active", colorScheme = bridge.colorScheme === "dark" ? "dark" : "light", initialDeepLinkClaimed = !1, sequence = 0, screen = null, handlerTable = new Map;
59
+ const mutationProtocolVersion = Number(bridge.mutationProtocolVersion || 0);
60
+ let mutationRevision = 0, mutationsEnabled = mutationProtocolVersion === 1, previousTree = null, latestTree = null;
61
+ function send(type, payload, id) {
62
+ const messageId = id || `js_${++sequence}`;
63
+ bridge.postMessage(JSON.stringify({ id: messageId, type, timestamp: Date.now(), payload, source: "js" }));
64
+ return messageId;
65
+ }
66
+ function evaluate(index, scope, what) {
67
+ try {
68
+ return screen.expressions[index](scope);
69
+ } catch (error) {
70
+ g.console.error(`[stx native] ${what} failed: ${error && error.message ? error.message : error}`);
71
+ return;
72
+ }
73
+ }
74
+ function resolveValue(value, scope, what) {
75
+ if (isExpressionRef(value))
76
+ return evaluate(value.$x, scope, what);
77
+ if (Array.isArray(value))
78
+ return hasExpressions(value) ? value.map((entry) => resolveValue(entry, scope, what)) : value;
79
+ if (value && typeof value === "object" && hasExpressions(value)) {
80
+ const out = {};
81
+ for (const key of Object.keys(value))
82
+ out[key] = resolveValue(value[key], scope, what);
83
+ return out;
84
+ }
85
+ return value;
86
+ }
87
+ function text(value, scope) {
88
+ if (typeof value === "string")
89
+ return value;
90
+ const answer = evaluate(value.$x, scope, "text");
91
+ return answer == null || answer === !1 ? "" : String(answer);
92
+ }
93
+ function nodeKey(node, scope) {
94
+ const raw = node.key ?? node.props.key ?? node.props.testID ?? null, key = resolveValue(raw, scope, "key");
95
+ return key == null || key === "" ? null : String(key);
96
+ }
97
+ function registerHandlers(node, id, scope) {
98
+ const events = {};
99
+ for (const name of Object.keys(node.events || {})) {
100
+ const index = node.events[name], handlerId = `${id}#${name}`;
101
+ events[name] = handlerId;
102
+ handlerTable.set(handlerId, (nativeEvent) => screen.expressions[index](scope, nativeEvent));
103
+ }
104
+ return events;
105
+ }
106
+ function styleFor(node, scope, props) {
107
+ let style = node.style || {};
108
+ if (colorScheme === "dark" && node.darkStyle)
109
+ style = { ...style, ...node.darkStyle };
110
+ const bindings = node.bindings;
111
+ if (bindings && bindings.class !== void 0) {
112
+ const classes = normalizeClass(evaluate(bindings.class, scope, ":class"));
113
+ if (classes) {
114
+ const compiled = classStyles(classes);
115
+ style = { ...style, ...compiled.style };
116
+ if (colorScheme === "dark" && compiled.dark)
117
+ style = { ...style, ...compiled.dark };
118
+ if (compiled.numberOfLines !== void 0 && props.numberOfLines === void 0)
119
+ props.numberOfLines = compiled.numberOfLines;
120
+ if (node.type === "Icon" && compiled.icon && props.symbol === void 0)
121
+ props.symbol = resolveIconName(compiled.icon).symbol;
122
+ }
123
+ }
124
+ if (bindings && bindings.style !== void 0)
125
+ style = { ...style, ...normalizeStyle(evaluate(bindings.style, scope, ":style")) };
126
+ if (node.directives && node.directives.show !== void 0 && !evaluate(node.directives.show, scope, ":show"))
127
+ style = { ...style, display: "none" };
128
+ return resolveValue(style, scope, "style");
129
+ }
130
+ function iconProps(props, final) {
131
+ if (props.name !== void 0) {
132
+ if (props.symbol === void 0) {
133
+ const icon = resolveIconName(props.name);
134
+ props.symbol = icon.symbol;
135
+ if (icon.iconify)
136
+ props.iconify = icon.iconify;
137
+ }
138
+ delete props.name;
139
+ }
140
+ if (final && (props.symbol === void 0 || props.symbol === null || props.symbol === ""))
141
+ props.symbol = "circle";
142
+ }
143
+ function resolveElement(node, id, scope) {
144
+ const isDataList = node.type === "FlatList" && node.props.data !== void 0, props = {};
145
+ for (const key of Object.keys(node.props || {})) {
146
+ if (key === "key")
147
+ continue;
148
+ if (isDataList && (key === "data" || key === "keyExtractor"))
149
+ continue;
150
+ props[key] = resolveValue(node.props[key], scope, key);
151
+ }
152
+ if (node.type === "Icon")
153
+ iconProps(props, !1);
154
+ const style = styleFor(node, scope, props);
155
+ if (node.type === "Icon")
156
+ iconProps(props, !0);
157
+ const events = registerHandlers(node, id, scope);
158
+ if (isDataList) {
159
+ const list = resolveList(node, id, scope, props, style, events);
160
+ if (list)
161
+ return list;
162
+ }
163
+ return { id, type: node.type, props, style, events, children: resolveChildren(node.children || [], id, scope) };
164
+ }
165
+ function resolveChildren(children, parentId, scope) {
166
+ const out = [], elements = children.filter((child) => typeof child === "object" && !isExpressionRef(child)), keyCounts = new Map;
167
+ for (const child of elements) {
168
+ if (child.directives && child.directives.for)
169
+ continue;
170
+ const key = nodeKey(child, scope);
171
+ if (key)
172
+ keyCounts.set(key, (keyCounts.get(key) || 0) + 1);
173
+ }
174
+ let chainOpen = !1, chainTaken = !1;
175
+ children.forEach((child, index) => {
176
+ if (typeof child === "string" || isExpressionRef(child)) {
177
+ out.push(text(child, scope));
178
+ return;
179
+ }
180
+ const node = child, directives = node.directives || {};
181
+ if (directives.for) {
182
+ chainOpen = !1;
183
+ appendLoop(node, `${parentId}/for:${index}`, scope, out);
184
+ return;
185
+ }
186
+ if (directives.if !== void 0) {
187
+ chainOpen = !0;
188
+ chainTaken = !1;
189
+ } else if (directives.elseIf !== void 0 || directives.else) {
190
+ if (!chainOpen) {
191
+ g.console.warn("[stx native] :else without :if");
192
+ return;
193
+ }
194
+ } else
195
+ chainOpen = !1;
196
+ if (directives.if !== void 0 || directives.elseIf !== void 0 || directives.else) {
197
+ if (chainTaken)
198
+ return;
199
+ const condition = directives.if ?? directives.elseIf;
200
+ if (condition !== void 0 && !evaluate(condition, scope, ":if"))
201
+ return;
202
+ chainTaken = !0;
203
+ if (directives.else)
204
+ chainOpen = !1;
205
+ }
206
+ const key = nodeKey(node, scope), id = key && keyCounts.get(key) === 1 ? `${parentId}/key:${key}` : `${parentId}/index:${index}`;
207
+ appendNode(node, id, scope, out);
208
+ });
209
+ return out;
210
+ }
211
+ function appendNode(node, id, scope, out) {
212
+ if (node.type === "Fragment" || node.type === "template") {
213
+ out.push(...resolveChildren(node.children || [], id, scope));
214
+ return;
215
+ }
216
+ out.push(resolveElement(node, id, scope));
217
+ }
218
+ function appendLoop(node, loopId, scope, out) {
219
+ const loop = node.directives.for;
220
+ let source = evaluate(loop.source, scope, ":for");
221
+ if (typeof source === "number")
222
+ source = Array.from({ length: Math.max(0, Math.floor(source)) }, (_, i) => i + 1);
223
+ else if (source && typeof source === "object" && !Array.isArray(source))
224
+ source = typeof source[Symbol.iterator] === "function" ? Array.from(source) : Object.keys(source).map((key) => source[key]);
225
+ if (!Array.isArray(source))
226
+ return;
227
+ const seen = new Map, inner = { ...node, directives: { ...node.directives, for: void 0 } };
228
+ source.forEach((value, position) => {
229
+ const itemScope = { ...scope, [loop.item]: value };
230
+ if (loop.index)
231
+ itemScope[loop.index] = position;
232
+ if (node.directives.if !== void 0 && !evaluate(node.directives.if, itemScope, ":if"))
233
+ return;
234
+ let key = nodeKey(node, itemScope);
235
+ if (key == null)
236
+ key = value && typeof value === "object" && (value.id ?? value.key) != null ? String(value.id ?? value.key) : String(position);
237
+ const encoded = encodeURIComponent(key), occurrence = seen.get(encoded) || 0;
238
+ seen.set(encoded, occurrence + 1);
239
+ const id = `${loopId}/key:${occurrence === 0 ? encoded : `${encoded}#${occurrence}`}`;
240
+ appendNode({ ...inner, directives: { ...inner.directives, if: void 0 } }, id, itemScope, out);
241
+ });
242
+ }
243
+ function listRole(node) {
244
+ return node && typeof node === "object" && !isExpressionRef(node) ? (node.props || {}).listRole || null : null;
245
+ }
246
+ function resolveList(node, id, scope, props, style, events) {
247
+ const data = resolveValue(node.props.data, scope, "data"), templates = (node.children || []).filter((child) => typeof child === "object" && !isExpressionRef(child)), itemTemplates = templates.filter((child) => listRole(child) === "item");
248
+ if (!Array.isArray(data) || itemTemplates.length === 0)
249
+ return null;
250
+ const groups = {
251
+ header: templates.filter((child) => listRole(child) === "header"),
252
+ empty: templates.filter((child) => listRole(child) === "empty"),
253
+ separator: templates.filter((child) => listRole(child) === "separator"),
254
+ footer: templates.filter((child) => listRole(child) === "footer")
255
+ }, children = [], seenKeys = new Map;
256
+ function appendTemplates(entries, role, itemScope, keyPrefix) {
257
+ entries.forEach((template, templateIndex) => {
258
+ const suffix = entries.length === 1 ? "" : `/template:${templateIndex}`, child = resolveElement(template, `${id}/${keyPrefix}${suffix}`, itemScope);
259
+ child.props = { ...child.props, listRole: role };
260
+ children.push(child);
261
+ });
262
+ }
263
+ appendTemplates(groups.header, "header", { ...scope, item: void 0, index: -1 }, "header");
264
+ if (data.length === 0)
265
+ appendTemplates(groups.empty, "empty", { ...scope, item: void 0, index: -1 }, "empty");
266
+ else
267
+ data.forEach((item, index) => {
268
+ const itemScope = { ...scope, item, index };
269
+ let key;
270
+ if (node.props.keyExtractor === void 0)
271
+ key = item && (item.key ?? item.id);
272
+ else {
273
+ key = resolveValue(node.props.keyExtractor, itemScope, "keyExtractor");
274
+ if (typeof key === "function")
275
+ key = key(item, index);
276
+ }
277
+ if (key == null || key === "")
278
+ key = index;
279
+ const encodedKey = encodeURIComponent(String(key)), occurrence = seenKeys.get(encodedKey) || 0;
280
+ seenKeys.set(encodedKey, occurrence + 1);
281
+ const uniqueKey = occurrence === 0 ? encodedKey : `${encodedKey}#${occurrence}`;
282
+ itemTemplates.forEach((template, templateIndex) => {
283
+ const suffix = itemTemplates.length === 1 ? "" : `/template:${templateIndex}`, child = resolveElement(template, `${id}/key:${uniqueKey}${suffix}`, itemScope);
284
+ child.props = { ...child.props, key: String(key), listRole: "item" };
285
+ children.push(child);
286
+ });
287
+ if (index < data.length - 1)
288
+ appendTemplates(groups.separator, "separator", itemScope, `separator:${uniqueKey}`);
289
+ });
290
+ appendTemplates(groups.footer, "footer", { ...scope, item: void 0, index: data.length }, "footer");
291
+ return { id, type: node.type, props: { ...props, itemCount: data.length }, style, events, children };
292
+ }
293
+ function nodeValue(node) {
294
+ return {
295
+ type: node.type,
296
+ props: node.props || {},
297
+ style: node.style || {},
298
+ events: node.events || {},
299
+ children: (node.children || []).filter((child) => typeof child === "string")
300
+ };
301
+ }
302
+ function treeValue(node) {
303
+ return {
304
+ id: node.id,
305
+ ...nodeValue(node),
306
+ children: (node.children || []).map((child) => typeof child === "string" ? child : treeValue(child))
307
+ };
308
+ }
309
+ function flatten(root) {
310
+ const result = new Map;
311
+ function visit(node, parentId, index) {
312
+ const childNodes = (node.children || []).filter((child) => typeof child !== "string");
313
+ result.set(node.id, { node, parentId, index, children: childNodes.map((child) => child.id) });
314
+ childNodes.forEach((child, childIndex) => visit(child, node.id, childIndex));
315
+ }
316
+ visit(root, null, 0);
317
+ return result;
318
+ }
319
+ function createTreeOperations(tree) {
320
+ const nodes = flatten(tree), operations = [];
321
+ nodes.forEach((entry, id) => {
322
+ operations.push({ op: "createNode", id, root: entry.parentId === null, node: nodeValue(entry.node) });
323
+ });
324
+ nodes.forEach((entry, parentId) => {
325
+ entry.children.forEach((childId, index) => operations.push({ op: "insertChild", parentId, childId, index }));
326
+ });
327
+ return operations;
328
+ }
329
+ function equivalent(left, right) {
330
+ return JSON.stringify(left) === JSON.stringify(right);
331
+ }
332
+ function diffTrees(before, after) {
333
+ const oldNodes = flatten(before), newNodes = flatten(after);
334
+ if (Array.from(oldNodes.keys()).some((id) => newNodes.has(id) && oldNodes.get(id).node.type !== newNodes.get(id).node.type))
335
+ return [{ op: "removeNode", id: before.id }].concat(createTreeOperations(after));
336
+ const operations = [], removed = new Set(Array.from(oldNodes.keys()).filter((id) => !newNodes.has(id)));
337
+ oldNodes.forEach((entry, id) => {
338
+ if (!removed.has(id) || entry.parentId && removed.has(entry.parentId))
339
+ return;
340
+ operations.push({ op: "removeNode", id });
341
+ });
342
+ newNodes.forEach((entry, id) => {
343
+ if (!oldNodes.has(id))
344
+ operations.push({ op: "createNode", id, root: entry.parentId === null, node: nodeValue(entry.node) });
345
+ });
346
+ newNodes.forEach((entry, id) => {
347
+ const previous = oldNodes.get(id);
348
+ if (!previous)
349
+ return;
350
+ const oldValue = nodeValue(previous.node), newValue = nodeValue(entry.node), patch = {};
351
+ if (!equivalent(oldValue.props, newValue.props))
352
+ patch.props = newValue.props;
353
+ if (!equivalent(oldValue.style, newValue.style))
354
+ patch.style = newValue.style;
355
+ if (!equivalent(oldValue.events, newValue.events))
356
+ patch.events = newValue.events;
357
+ if (!equivalent(oldValue.children, newValue.children))
358
+ patch.children = newValue.children;
359
+ if (Object.keys(patch).length)
360
+ operations.push({ op: "updateNode", id, patch });
361
+ });
362
+ newNodes.forEach((entry, parentId) => {
363
+ let current = [];
364
+ const previous = oldNodes.get(parentId);
365
+ if (previous)
366
+ current = previous.children.filter((id) => newNodes.has(id) && newNodes.get(id).parentId === parentId);
367
+ entry.children.forEach((childId, index) => {
368
+ if (current[index] === childId)
369
+ return;
370
+ const oldIndex = current.indexOf(childId);
371
+ if (oldIndex >= 0) {
372
+ operations.push({ op: "moveChild", parentId, childId, index });
373
+ current.splice(oldIndex, 1);
374
+ current.splice(index, 0, childId);
375
+ } else {
376
+ operations.push({ op: "insertChild", parentId, childId, index });
377
+ current.splice(index, 0, childId);
378
+ }
379
+ });
380
+ });
381
+ return operations;
382
+ }
383
+ function sendRenderFallback() {
384
+ send("RENDER", { document: treeValue(latestTree), mode: "replace" }, `render_${Date.now()}_${++sequence}`);
385
+ }
386
+ function buildTree() {
387
+ handlerTable = new Map;
388
+ const root = screen.document.root, out = [];
389
+ appendNode(root, "root", {}, out);
390
+ const first = out.find((child) => typeof child !== "string");
391
+ if (first && out.filter((child) => typeof child !== "string").length === 1)
392
+ return first;
393
+ return { id: "root", type: "View", props: {}, style: { flex: 1 }, events: {}, children: out.filter((child) => typeof child !== "string") };
394
+ }
395
+ function render() {
396
+ if (!screen)
397
+ return;
398
+ const nextTree = buildTree();
399
+ latestTree = nextTree;
400
+ if (!mutationsEnabled || !previousTree) {
401
+ if (mutationsEnabled)
402
+ previousTree = nextTree;
403
+ sendRenderFallback();
404
+ return;
405
+ }
406
+ const operations = diffTrees(previousTree, nextTree);
407
+ previousTree = nextTree;
408
+ if (!operations.length)
409
+ return;
410
+ const baseRevision = mutationRevision;
411
+ mutationRevision += 1;
412
+ send("MUTATE", { version: mutationProtocolVersion, batchId: `mutation_${mutationRevision}`, baseRevision, revision: mutationRevision, operations });
413
+ }
414
+ let renderScheduled = !1;
415
+ function scheduleRender() {
416
+ if (renderScheduled)
417
+ return;
418
+ if (!scheduleTimeout) {
419
+ Promise.resolve().then(render);
420
+ return;
421
+ }
422
+ renderScheduled = !0;
423
+ scheduleTimeout(() => {
424
+ renderScheduled = !1;
425
+ render();
426
+ }, 0);
427
+ }
428
+ function redrawAfter(name) {
429
+ const original = g[name];
430
+ if (typeof original !== "function" || original.__stxRedraws)
431
+ return;
432
+ const wrapped = function(callback, delay, ...args) {
433
+ if (typeof callback !== "function")
434
+ return original.call(g, callback, delay, ...args);
435
+ return original.call(g, (...given) => {
436
+ try {
437
+ callback(...given);
438
+ } finally {
439
+ scheduleRender();
440
+ }
441
+ }, delay, ...args);
442
+ };
443
+ wrapped.__stxRedraws = !0;
444
+ g[name] = wrapped;
445
+ }
446
+ redrawAfter("setTimeout");
447
+ redrawAfter("setInterval");
448
+ function runHandler(handler, event) {
449
+ let result;
450
+ try {
451
+ result = handler(event);
452
+ } catch (error) {
453
+ g.console.error(`[stx native] handler failed: ${error && error.message ? error.message : error}`);
454
+ render();
455
+ return;
456
+ }
457
+ if (result && typeof result.then === "function") {
458
+ render();
459
+ return result.then((value) => {
460
+ render();
461
+ return value;
462
+ }, (error) => {
463
+ g.console.error(`[stx native] handler failed: ${error && error.message ? error.message : error}`);
464
+ render();
465
+ });
466
+ }
467
+ render();
468
+ return result;
469
+ }
470
+ function requestAPI(module, method, args) {
471
+ return new Promise((resolve, reject) => {
472
+ const id = `js_${++sequence}`, configuredTimeout = Number(bridge.capabilityTimeoutMs || 30000), timeoutMs = Number.isFinite(configuredTimeout) && configuredTimeout > 0 ? configuredTimeout : 30000, timeout = scheduleTimeout ? scheduleTimeout(() => {
473
+ if (!pendingAPI.delete(id))
474
+ return;
475
+ send("API_CANCEL", { version: 1, requestId: id, reason: "timeout" });
476
+ const error = Error("Native API request timed out");
477
+ error.code = "TIMEOUT";
478
+ reject(error);
479
+ scheduleRender();
480
+ }, timeoutMs) : null;
481
+ pendingAPI.set(id, { resolve, reject, timeout });
482
+ send("API_REQUEST", { version: 1, module, method, args }, id);
483
+ });
484
+ }
485
+ function dispatchSubscription(handlers, value) {
486
+ if (!handlers.size)
487
+ return;
488
+ handlers.forEach((handler) => {
489
+ const result = handler(value);
490
+ if (result && typeof result.then === "function")
491
+ result.then(render, () => {});
492
+ });
493
+ render();
494
+ }
495
+ const craft = g.craft = g.craft || {}, nativeCapabilities = new Set(Array.isArray(bridge.capabilities) ? bridge.capabilities : []);
496
+ craft.platform = bridge.platform || "unknown";
497
+ craft.capabilityProtocolVersion = Number(bridge.capabilityProtocolVersion || 0);
498
+ craft.capabilities = {
499
+ haptics: nativeCapabilities.has("haptics"),
500
+ speechRecognition: !1,
501
+ share: !1,
502
+ camera: !1,
503
+ biometric: nativeCapabilities.has("biometric"),
504
+ pushNotifications: !1,
505
+ secureStorage: nativeCapabilities.has("secureStorage"),
506
+ storage: nativeCapabilities.has("storage"),
507
+ localDatabase: nativeCapabilities.has("database"),
508
+ lifecycle: nativeCapabilities.has("lifecycle"),
509
+ geolocation: !1,
510
+ clipboard: nativeCapabilities.has("clipboard"),
511
+ contacts: !1,
512
+ calendar: !1,
513
+ localNotifications: nativeCapabilities.has("notifications"),
514
+ inAppPurchase: !1,
515
+ keepAwake: !1,
516
+ orientationLock: !1,
517
+ deepLinks: nativeCapabilities.has("deepLinks"),
518
+ flashlight: !1,
519
+ speech: !1,
520
+ network: !1,
521
+ deviceInfo: nativeCapabilities.has("device"),
522
+ fetch: nativeCapabilities.has("fetch"),
523
+ badge: !1,
524
+ appReview: !1
525
+ };
526
+ craft.route = { name: routeName, params: g.__stxNativeParams || {} };
527
+ craft.appearance = { colorScheme: () => colorScheme };
528
+ function navigate(type, target, params) {
529
+ if (!routeNames.includes(target))
530
+ throw Error(`Unknown native screen: ${target}`);
531
+ if (params !== void 0 && (params === null || typeof params !== "object" || Array.isArray(params)))
532
+ throw Error("Navigation params must be an object");
533
+ return send(type, { screen: target, params: params || {} });
534
+ }
535
+ function navigationOptions(options) {
536
+ if (!options || typeof options !== "object")
537
+ throw TypeError("navigation.setOptions needs an object");
538
+ const payload = {};
539
+ for (const key of Object.keys(options))
540
+ if (key === "rightButtons" && Array.isArray(options.rightButtons)) {
541
+ navButtonPresses.clear();
542
+ payload.rightButtons = options.rightButtons.map((button) => {
543
+ const { onPress, ...rest } = button || {};
544
+ if (typeof onPress === "function" && rest.id != null)
545
+ navButtonPresses.set(String(rest.id), onPress);
546
+ return rest;
547
+ });
548
+ } else if (typeof options[key] !== "function")
549
+ payload[key] = options[key];
550
+ return payload;
551
+ }
552
+ const hostSetOptions = craft.navigation && typeof craft.navigation.setOptions === "function" ? craft.navigation.setOptions.bind(craft.navigation) : null;
553
+ craft.navigation = Object.assign(craft.navigation || {}, {
554
+ push: (target, params) => navigate("NAVIGATE", target, params),
555
+ replace: (target, params) => navigate("NAVIGATE_REPLACE", target, params),
556
+ back: () => send("NAVIGATE_BACK", {}),
557
+ open: (path) => {
558
+ if (typeof path !== "string" || !path.trim())
559
+ throw TypeError("navigation.open needs a path, such as /m/workout/42");
560
+ return send("NAVIGATE_OPEN", { path: String(path) });
561
+ },
562
+ setOptions: (options) => {
563
+ const payload = navigationOptions(options);
564
+ if (hostSetOptions)
565
+ return hostSetOptions(payload);
566
+ return send("NAVIGATION_SET_OPTIONS", payload);
567
+ },
568
+ onButton: (callback) => {
569
+ if (typeof callback !== "function")
570
+ throw TypeError("navigation.onButton needs a function");
571
+ navButtonHandlers.add(callback);
572
+ return () => {
573
+ navButtonHandlers.delete(callback);
574
+ };
575
+ }
576
+ });
577
+ craft.device = craft.device || {};
578
+ craft.device.getInfo = () => requestAPI("Device", "getInfo", []);
579
+ craft.clipboard = {
580
+ write: (value) => requestAPI("Clipboard", "write", [value]),
581
+ read: () => requestAPI("Clipboard", "read", [])
582
+ };
583
+ craft.haptic = (style) => requestAPI("Haptics", "impact", [style || "medium"]);
584
+ function hapticFeedback(answer) {
585
+ return answer.then(() => {}, (error) => {
586
+ if (error.code === "CAPABILITY_DISABLED")
587
+ return;
588
+ throw error;
589
+ });
590
+ }
591
+ craft.haptics = {
592
+ impact: (style) => hapticFeedback(craft.haptic(style)),
593
+ notification: (type) => hapticFeedback(craft.haptic(type === "error" ? "heavy" : type === "warning" ? "medium" : "light")),
594
+ selection: () => hapticFeedback(craft.haptic("soft"))
595
+ };
596
+ const syncFallbacks = { getSync: () => null, setSync: () => {
597
+ return;
598
+ } };
599
+ craft.storage = Object.assign({}, syncFallbacks, craft.storage || {}, {
600
+ get: (key) => requestAPI("Storage", "get", [key]),
601
+ set: (key, value) => requestAPI("Storage", "set", [key, value]),
602
+ remove: (key) => requestAPI("Storage", "remove", [key]),
603
+ clear: () => requestAPI("Storage", "clear", []),
604
+ keys: () => requestAPI("Storage", "keys", [])
605
+ });
606
+ craft.biometrics = {
607
+ isAvailable: () => requestAPI("Biometrics", "isAvailable", []),
608
+ getBiometricType: () => requestAPI("Biometrics", "getBiometricType", []),
609
+ authenticate: (reason) => requestAPI("Biometrics", "authenticate", [reason || "Authenticate to continue"])
610
+ };
611
+ craft.secureStorage = Object.assign({ getSync: () => null }, craft.secureStorage || {}, {
612
+ set: (key, value) => requestAPI("SecureStorage", "set", [key, value]),
613
+ get: (key) => requestAPI("SecureStorage", "get", [key]),
614
+ remove: (key) => requestAPI("SecureStorage", "remove", [key]),
615
+ delete: (key) => requestAPI("SecureStorage", "remove", [key]),
616
+ clear: () => requestAPI("SecureStorage", "clear", [])
617
+ });
618
+ craft.snapshots = Object.assign({ get: () => null, set: () => Promise.resolve(!1) }, craft.snapshots || {});
619
+ craft.db = {
620
+ execute: (sql, params) => requestAPI("Database", "execute", [sql, params || []]),
621
+ query: (sql, params) => requestAPI("Database", "query", [sql, params || []]),
622
+ beginTransaction: () => requestAPI("Database", "beginTransaction", []),
623
+ commit: () => requestAPI("Database", "commit", []),
624
+ rollback: () => requestAPI("Database", "rollback", [])
625
+ };
626
+ function onAppStateChange(callback) {
627
+ if (typeof callback !== "function")
628
+ throw TypeError("lifecycle.onStateChange needs a function");
629
+ appStateHandlers.add(callback);
630
+ return () => {
631
+ appStateHandlers.delete(callback);
632
+ };
633
+ }
634
+ craft.lifecycle = { getState: () => currentAppState, onStateChange: onAppStateChange, onChange: onAppStateChange };
635
+ craft.getAppState = craft.lifecycle.getState;
636
+ craft.onAppStateChange = onAppStateChange;
637
+ craft.deepLinks = {
638
+ getInitialURL: () => {
639
+ initialDeepLinkClaimed = !0;
640
+ return requestAPI("DeepLinks", "getInitialURL", []);
641
+ },
642
+ onLink: (callback) => {
643
+ if (typeof callback !== "function")
644
+ throw TypeError("deepLinks.onLink needs a function");
645
+ deepLinkHandlers.add(callback);
646
+ return () => {
647
+ deepLinkHandlers.delete(callback);
648
+ };
649
+ }
650
+ };
651
+ craft.notifications = {
652
+ show: (notification) => requestAPI("Notifications", "schedule", [notification]),
653
+ schedule: (notification) => requestAPI("Notifications", "schedule", [notification]),
654
+ cancel: (id) => requestAPI("Notifications", "cancel", [id]),
655
+ cancelAll: () => requestAPI("Notifications", "cancelAll", []),
656
+ pending: () => requestAPI("Notifications", "pending", [])
657
+ };
658
+ craft.scheduleNotification = craft.notifications.schedule;
659
+ craft.cancelNotification = craft.notifications.cancel;
660
+ craft.cancelAllNotifications = craft.notifications.cancelAll;
661
+ craft.getPendingNotifications = craft.notifications.pending;
662
+ function nativeResponse(data) {
663
+ const headers = data && data.headers && typeof data.headers === "object" ? data.headers : {}, body = data && data.body != null ? String(data.body) : "", status = Number(data && data.status) || 0;
664
+ let bodyUsed = !1;
665
+ function consume() {
666
+ if (bodyUsed)
667
+ return Promise.reject(TypeError("Body has already been consumed"));
668
+ bodyUsed = !0;
669
+ return Promise.resolve(body);
670
+ }
671
+ return {
672
+ type: "basic",
673
+ url: data && data.url || "",
674
+ status,
675
+ statusText: data && data.statusText || "",
676
+ ok: status >= 200 && status < 300,
677
+ redirected: Boolean(data && data.redirected),
678
+ headers: {
679
+ get: (name) => {
680
+ const value = headers[String(name).toLowerCase()];
681
+ return value == null ? null : String(value);
682
+ },
683
+ has: (name) => headers[String(name).toLowerCase()] != null,
684
+ forEach: (callback) => {
685
+ Object.keys(headers).forEach((name) => callback(String(headers[name]), name));
686
+ }
687
+ },
688
+ get bodyUsed() {
689
+ return bodyUsed;
690
+ },
691
+ text: consume,
692
+ json: () => consume().then((value) => JSON.parse(value))
693
+ };
694
+ }
695
+ function nativeFetch(input, init) {
696
+ const options = init || {}, request = input && typeof input === "object" ? input : {}, url = typeof input === "string" ? input : String(request.url || input), method = String(options.method || request.method || "GET").toUpperCase(), headers = {}, source = options.headers || request.headers;
697
+ function addHeader(name, value) {
698
+ headers[String(name).toLowerCase()] = String(value);
699
+ }
700
+ if (Array.isArray(source))
701
+ source.forEach((pair) => addHeader(pair[0], pair[1]));
702
+ else if (source && typeof source.forEach === "function")
703
+ source.forEach((value, name) => addHeader(name, value));
704
+ else if (source && typeof source === "object")
705
+ Object.keys(source).forEach((name) => addHeader(name, source[name]));
706
+ const body = options.body !== void 0 ? options.body : request.body;
707
+ if (body != null && typeof body !== "string")
708
+ return Promise.reject(TypeError("fetch in a native screen sends string bodies only"));
709
+ if (body != null && (method === "GET" || method === "HEAD"))
710
+ return Promise.reject(TypeError("A GET or HEAD request cannot have a body"));
711
+ return requestAPI("Network", "fetch", [{ url, method, headers, body: body == null ? null : body }]).then(nativeResponse, (error) => {
712
+ if (error && error.code === "INVALID_ARGUMENT")
713
+ throw error;
714
+ const failure = TypeError(error && error.message || "Network request failed");
715
+ failure.code = error && error.code || "NETWORK_ERROR";
716
+ throw failure;
717
+ });
718
+ }
719
+ if (nativeCapabilities.has("fetch") && typeof g.fetch !== "function")
720
+ g.fetch = nativeFetch;
721
+ if (!g.console || typeof g.console.log !== "function") {
722
+ const forward = (level) => (...args) => {
723
+ send("CONSOLE", { level, message: args.map((arg) => typeof arg === "string" ? arg : (() => {
724
+ try {
725
+ return JSON.stringify(arg);
726
+ } catch {
727
+ return String(arg);
728
+ }
729
+ })()).join(" ") });
730
+ };
731
+ g.console = { log: forward("log"), info: forward("info"), warn: forward("warn"), error: forward("error"), debug: forward("debug") };
732
+ }
733
+ function dispatchNavButton(event) {
734
+ const id = event && event.id != null ? String(event.id) : "", own = navButtonPresses.get(id);
735
+ if (own)
736
+ runHandler(own, { id });
737
+ navButtonHandlers.forEach((handler) => runHandler(handler, { id }));
738
+ const named = screen && screen.functions && screen.functions.navButton;
739
+ if (named)
740
+ runHandler(named, { id });
741
+ if (!own && !navButtonHandlers.size && !named)
742
+ render();
743
+ }
744
+ bridge.onMessage((raw) => {
745
+ const message = typeof raw === "string" ? JSON.parse(raw) : raw;
746
+ if (message.type === "EVENT") {
747
+ const name = message.payload.handlerName, nativeEvent = message.payload.nativeEvent || {}, handler = handlerTable.get(name);
748
+ if (handler) {
749
+ runHandler(handler, nativeEvent);
750
+ return;
751
+ }
752
+ if (name === "navButton") {
753
+ dispatchNavButton(nativeEvent);
754
+ return;
755
+ }
756
+ const named = screen && screen.functions && screen.functions[name];
757
+ if (typeof named === "function")
758
+ runHandler(named, nativeEvent);
759
+ } else if (message.type === "API_RESPONSE" || message.type === "API_ERROR") {
760
+ const requestId = message.correlationId || message.payload.requestId, pending = pendingAPI.get(requestId);
761
+ if (!pending)
762
+ return;
763
+ pendingAPI.delete(requestId);
764
+ if (pending.timeout !== null && cancelTimeout)
765
+ cancelTimeout(pending.timeout);
766
+ if (message.type === "API_RESPONSE")
767
+ pending.resolve(message.payload.data);
768
+ else {
769
+ const error = Error(message.payload.message || "Native API failed");
770
+ error.code = message.payload.code || "CRAFT_ERROR";
771
+ pending.reject(error);
772
+ }
773
+ scheduleRender();
774
+ } else if (message.type === "APP_STATE") {
775
+ if (message.payload.state === currentAppState)
776
+ return;
777
+ currentAppState = message.payload.state;
778
+ dispatchSubscription(appStateHandlers, message.payload.state);
779
+ } else if (message.type === "DEEP_LINK") {
780
+ if (initialDeepLinkClaimed && message.payload.initial)
781
+ return;
782
+ dispatchSubscription(deepLinkHandlers, message.payload);
783
+ } else if (message.type === "APPEARANCE") {
784
+ const next = message.payload && message.payload.colorScheme === "dark" ? "dark" : "light";
785
+ if (next === colorScheme)
786
+ return;
787
+ colorScheme = next;
788
+ render();
789
+ } else if (message.type === "MUTATION_ERROR") {
790
+ mutationsEnabled = !1;
791
+ mutationRevision = 0;
792
+ previousTree = null;
793
+ sendRenderFallback();
794
+ }
795
+ });
796
+ return {
797
+ mount(definition) {
798
+ screen = definition;
799
+ render();
800
+ }
801
+ };
802
+ }
803
+ export function installRuntime(options = {}) {
804
+ const bridge = g.__stxNativeBridge;
805
+ if (typeof bridge > "u" || bridge === null)
806
+ return { mount() {} };
807
+ return createRuntime(bridge, options);
808
+ }