@stacksjs/stx 0.2.422 → 0.2.423

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/dist/{chunk-ep5jnqdb.js → chunk-02n071n7.js} +6 -6
  2. package/dist/chunk-03n23sh6.js +2 -0
  3. package/dist/chunk-07mxghsz.js +2 -0
  4. package/dist/{chunk-kjkwycce.js → chunk-0bmc75w6.js} +4 -4
  5. package/dist/{chunk-hyak4dzg.js → chunk-0hhq9hbq.js} +3 -3
  6. package/dist/{chunk-66k7yxnr.js → chunk-12pvnn1e.js} +4 -4
  7. package/dist/chunk-1497wcxc.js +2 -0
  8. package/dist/chunk-17n9e5wk.js +2 -0
  9. package/dist/chunk-1p8hc1ve.js +2 -0
  10. package/dist/chunk-1r3ghgsz.js +2 -0
  11. package/dist/{chunk-681cxw8j.js → chunk-24e7qjb8.js} +2 -2
  12. package/dist/chunk-259ecbwa.js +2 -0
  13. package/dist/chunk-26gfsa9w.js +2 -0
  14. package/dist/{chunk-zp0mg8b2.js → chunk-2bpjq1qz.js} +2 -2
  15. package/dist/{chunk-11ra3sbc.js → chunk-2x9jd5w0.js} +3 -3
  16. package/dist/{chunk-k31fwm2w.js → chunk-3hmy75tw.js} +5 -5
  17. package/dist/{chunk-12b8akfg.js → chunk-3pxp0r0a.js} +3 -3
  18. package/dist/{chunk-x5ks23vx.js → chunk-3ry9ca1s.js} +2 -2
  19. package/dist/{chunk-th9s15es.js → chunk-45rfv3a5.js} +2 -2
  20. package/dist/chunk-47apfsxp.js +2 -0
  21. package/dist/{chunk-w72p2ak0.js → chunk-48kgnqpk.js} +4 -4
  22. package/dist/{chunk-rsxvbnp4.js → chunk-4hd5wb8x.js} +3 -3
  23. package/dist/chunk-535nrr6j.js +2 -0
  24. package/dist/chunk-5mfhk69g.js +2 -0
  25. package/dist/{chunk-aync8qmk.js → chunk-5vwg3h5g.js} +2 -2
  26. package/dist/{chunk-tspmynvh.js → chunk-62chbqev.js} +1 -1
  27. package/dist/chunk-6c7294j8.js +2 -0
  28. package/dist/{chunk-qwgdtrhj.js → chunk-6cbvx87h.js} +5 -5
  29. package/dist/{chunk-q0cehgy2.js → chunk-6fsbny9m.js} +3 -3
  30. package/dist/chunk-6gh2rvyz.js +2 -0
  31. package/dist/chunk-6j6gbp0y.js +2 -0
  32. package/dist/chunk-6jgjmycb.js +2 -0
  33. package/dist/{chunk-w83djypm.js → chunk-6t278w29.js} +2 -2
  34. package/dist/{chunk-5vfyxxrp.js → chunk-6t7mxb0b.js} +2 -2
  35. package/dist/chunk-6wmxrn6x.js +2 -0
  36. package/dist/chunk-6wweqfg7.js +2 -0
  37. package/dist/{chunk-ja7znxnz.js → chunk-7a9h7ycs.js} +5 -5
  38. package/dist/chunk-7pbv9mg7.js +2 -0
  39. package/dist/{chunk-09hhrjk9.js → chunk-89b2r1q0.js} +6 -6
  40. package/dist/{chunk-0varh725.js → chunk-8a0r2j8f.js} +3 -3
  41. package/dist/{chunk-gp8xzbyt.js → chunk-8nsbf2mz.js} +1074 -1074
  42. package/dist/{chunk-mg13q1kd.js → chunk-8zf5q1m3.js} +2 -2
  43. package/dist/chunk-9d53d0t6.js +2 -0
  44. package/dist/chunk-9j72har9.js +2 -0
  45. package/dist/chunk-9yqz5ge5.js +2 -0
  46. package/dist/chunk-a5c9n7an.js +2 -0
  47. package/dist/chunk-a836zn7c.js +2 -0
  48. package/dist/{chunk-kzkjc12e.js → chunk-a8g6y9kw.js} +5 -5
  49. package/dist/{chunk-21a7p956.js → chunk-acwgap78.js} +1 -1
  50. package/dist/{chunk-qx3js9tk.js → chunk-aen2baze.js} +1 -1
  51. package/dist/chunk-ahgrkva8.js +2 -0
  52. package/dist/chunk-akbb6j7s.js +2 -0
  53. package/dist/chunk-avakcrbs.js +2 -0
  54. package/dist/{chunk-tafebmtg.js → chunk-axydabse.js} +2 -2
  55. package/dist/{chunk-4n6c5rp5.js → chunk-b7973zvk.js} +2 -2
  56. package/dist/{chunk-ebkpdc45.js → chunk-bxwe7wxj.js} +10 -10
  57. package/dist/{chunk-2ewa2sg5.js → chunk-c1dmr865.js} +3 -3
  58. package/dist/chunk-cenq2n6e.js +2 -0
  59. package/dist/{chunk-zvh2nnzr.js → chunk-cf6htz63.js} +1 -1
  60. package/dist/chunk-cnmz9543.js +2 -0
  61. package/dist/{chunk-h1585jbm.js → chunk-cx2rdew4.js} +13 -13
  62. package/dist/{chunk-wg1ttvs5.js → chunk-cznsm2n3.js} +2 -2
  63. package/dist/chunk-d1qzhawc.js +2 -0
  64. package/dist/chunk-d6hnvwre.js +2 -0
  65. package/dist/{chunk-7abgzdsm.js → chunk-dcwjxq8n.js} +2 -2
  66. package/dist/chunk-dhqwg62x.js +2 -0
  67. package/dist/{chunk-95e3rz88.js → chunk-dmd6yk2x.js} +5 -5
  68. package/dist/chunk-e18qfegt.js +2 -0
  69. package/dist/chunk-eej89wkt.js +2 -0
  70. package/dist/chunk-ekxffxbd.js +2 -0
  71. package/dist/{chunk-hy9e3ny6.js → chunk-ex0tq6x2.js} +1 -1
  72. package/dist/{chunk-nqr77pxk.js → chunk-fg5ve6ey.js} +2 -2
  73. package/dist/{chunk-dejsjk4h.js → chunk-fnt1q1sp.js} +11 -11
  74. package/dist/chunk-g67gg66e.js +2 -0
  75. package/dist/chunk-gq16fxc2.js +2 -0
  76. package/dist/{chunk-5e9zkd65.js → chunk-h3c7z73m.js} +2 -2
  77. package/dist/chunk-h4avjh3q.js +2 -0
  78. package/dist/chunk-h7qte7ye.js +2 -0
  79. package/dist/{chunk-hmdnn9ja.js → chunk-hb9gxad0.js} +3 -3
  80. package/dist/{chunk-dmxh7zwq.js → chunk-hg4k3nkr.js} +1 -1
  81. package/dist/{chunk-dhxbjw6k.js → chunk-hnep9jbj.js} +2 -2
  82. package/dist/chunk-hwycbxg7.js +2 -0
  83. package/dist/{chunk-34gy5zjm.js → chunk-j1q65enz.js} +2 -2
  84. package/dist/chunk-j5myfxe8.js +18 -0
  85. package/dist/{chunk-8jqy69td.js → chunk-j7zywbq0.js} +2 -2
  86. package/dist/{chunk-788g87ft.js → chunk-jbrdebzs.js} +7 -7
  87. package/dist/{chunk-wr6b99pw.js → chunk-jj4pyeyj.js} +1 -1
  88. package/dist/{chunk-g1fxmp9z.js → chunk-k8sqs7j2.js} +4 -4
  89. package/dist/chunk-mg7jhx5v.js +2 -0
  90. package/dist/chunk-n16wa755.js +2 -0
  91. package/dist/chunk-ngv1c807.js +2 -0
  92. package/dist/{chunk-krr2vb0s.js → chunk-p2x7tjbt.js} +3 -3
  93. package/dist/{chunk-62r4fa4q.js → chunk-ptjqacjd.js} +2 -2
  94. package/dist/{chunk-597rfddk.js → chunk-qm1tt8g1.js} +2334 -2334
  95. package/dist/chunk-r7r5h2eh.js +2 -0
  96. package/dist/chunk-rhkx17d9.js +2 -0
  97. package/dist/{chunk-b1fg9vg7.js → chunk-s28eh0jn.js} +2 -2
  98. package/dist/{chunk-837nb4zv.js → chunk-s295vp9x.js} +3 -3
  99. package/dist/chunk-sazpw71r.js +4 -0
  100. package/dist/{chunk-20tdz0zs.js → chunk-sbdzqqr1.js} +6 -6
  101. package/dist/{chunk-qby6wxat.js → chunk-spx27cs4.js} +2 -2
  102. package/dist/{chunk-n7jjp08m.js → chunk-stxmwytg.js} +2 -2
  103. package/dist/{chunk-2tfe2g58.js → chunk-t3wh1jbk.js} +6 -6
  104. package/dist/{chunk-802pr252.js → chunk-tfexmdkt.js} +2 -2
  105. package/dist/{chunk-2cn8krpp.js → chunk-tfz95n7j.js} +5 -5
  106. package/dist/chunk-thdbqsxq.js +2 -0
  107. package/dist/chunk-tpnfcb83.js +2 -0
  108. package/dist/chunk-tqkv4th9.js +2 -0
  109. package/dist/chunk-tznejj9h.js +2 -0
  110. package/dist/{chunk-ap6fehea.js → chunk-vfk725vm.js} +5 -5
  111. package/dist/chunk-vsrm9k7p.js +2 -0
  112. package/dist/chunk-vwms759h.js +2 -0
  113. package/dist/{chunk-xvzxrt9a.js → chunk-w2085fwx.js} +5 -5
  114. package/dist/chunk-w252cgnv.js +30 -0
  115. package/dist/chunk-whdw6dhb.js +2 -0
  116. package/dist/chunk-wtms9jhs.js +3 -0
  117. package/dist/chunk-wtqjfar3.js +2 -0
  118. package/dist/chunk-wx7kfet5.js +2 -0
  119. package/dist/chunk-wy873fy8.js +2 -0
  120. package/dist/{chunk-d2z6828s.js → chunk-xa3wsmt5.js} +11 -11
  121. package/dist/chunk-xrbqf77j.js +2 -0
  122. package/dist/{chunk-757ec865.js → chunk-yaebdyfr.js} +2 -2
  123. package/dist/chunk-ycpq3gxc.js +2 -0
  124. package/dist/chunk-yd50awqp.js +3 -0
  125. package/dist/{chunk-csjw5esc.js → chunk-ydz7w2mt.js} +2 -2
  126. package/dist/chunk-yjgbxf26.js +2 -0
  127. package/dist/{chunk-jjnfj9nf.js → chunk-yqsza22w.js} +2 -2
  128. package/dist/{chunk-3xm6dyab.js → chunk-zbr333kf.js} +88 -27
  129. package/dist/chunk-zcyjdcpx.js +33 -0
  130. package/dist/{chunk-tqnysw0k.js → chunk-zfzcedw4.js} +4 -4
  131. package/dist/chunk-zm73n103.js +2 -0
  132. package/dist/cli.js +20 -20
  133. package/dist/component-renderer.js +54 -2
  134. package/dist/composables/use-outbox.d.ts +1 -0
  135. package/dist/composables/use-outbox.js +14 -4
  136. package/dist/craft-entry.js +2 -2
  137. package/dist/craft.js +2 -2
  138. package/dist/database.js +2 -2
  139. package/dist/native/bridge/protocol.d.ts +5 -0
  140. package/dist/native/bridge/protocol.js +3 -0
  141. package/dist/native/cli.js +12 -2
  142. package/dist/native/compiler/bundle.d.ts +4 -3
  143. package/dist/native/compiler/bundle.js +46 -51
  144. package/dist/native/compiler/component-mapping.d.ts +5 -0
  145. package/dist/native/compiler/component-mapping.js +90 -0
  146. package/dist/native/compiler/html-to-ir.js +42 -6
  147. package/dist/native/compiler/ir.d.ts +2 -0
  148. package/dist/native/compiler/render-screen.d.ts +4 -0
  149. package/dist/native/compiler/render-screen.js +10 -2
  150. package/dist/native/compiler/setup-script.d.ts +6 -0
  151. package/dist/native/compiler/setup-script.js +10 -0
  152. package/dist/native/components/primitives.d.ts +10 -0
  153. package/dist/native/index.d.ts +6 -24
  154. package/dist/native/index.js +1 -17
  155. package/dist/native/primitives/Button.stx +2 -1
  156. package/dist/native/primitives/Text.stx +2 -1
  157. package/dist/native/primitives/TextInput.stx +3 -1
  158. package/dist/native/prop-names.d.ts +2 -0
  159. package/dist/native/prop-names.js +71 -0
  160. package/dist/native/runtime/binding-tree.d.ts +31 -0
  161. package/dist/native/runtime/binding-tree.js +100 -0
  162. package/dist/native/runtime/craft-bridge.d.ts +9 -0
  163. package/dist/native/runtime/craft-bridge.js +231 -0
  164. package/dist/native/runtime/craft.d.ts +28 -3
  165. package/dist/native/runtime/jsc-globals.d.ts +16 -0
  166. package/dist/native/runtime/jsc-globals.js +64 -0
  167. package/dist/native/runtime/native-host.d.ts +3 -1
  168. package/dist/native/runtime/native-host.js +183 -33
  169. package/dist/native/runtime/shared-screen.d.ts +15 -0
  170. package/dist/native/runtime/shared-screen.js +41 -0
  171. package/dist/pwa.js +3 -3
  172. package/dist/signal-processing.d.ts +3 -1
  173. package/dist/signal-processing.js +4 -3
  174. package/dist/signals.js +77 -16
  175. package/dist/ssg.js +28 -28
  176. package/package.json +5 -5
  177. package/dist/chunk-10fh9qhe.js +0 -2
  178. package/dist/chunk-1569v24d.js +0 -2
  179. package/dist/chunk-18awnp9d.js +0 -2
  180. package/dist/chunk-1r0c5920.js +0 -30
  181. package/dist/chunk-2hswgxpb.js +0 -2
  182. package/dist/chunk-4363reg4.js +0 -2
  183. package/dist/chunk-48axv7bm.js +0 -2
  184. package/dist/chunk-50hgr79y.js +0 -2
  185. package/dist/chunk-54wczcee.js +0 -2
  186. package/dist/chunk-74gz26zs.js +0 -2
  187. package/dist/chunk-7906p8zs.js +0 -2
  188. package/dist/chunk-7dkfjmjw.js +0 -2
  189. package/dist/chunk-7vr5w75r.js +0 -4
  190. package/dist/chunk-7zn0yyqk.js +0 -2
  191. package/dist/chunk-8d2kamh2.js +0 -2
  192. package/dist/chunk-8ttvazck.js +0 -2
  193. package/dist/chunk-8y4bqsxz.js +0 -2
  194. package/dist/chunk-9bpnz431.js +0 -2
  195. package/dist/chunk-ac033b93.js +0 -2
  196. package/dist/chunk-aj43359g.js +0 -2
  197. package/dist/chunk-aj8yq228.js +0 -2
  198. package/dist/chunk-as72dvvm.js +0 -2
  199. package/dist/chunk-bfvaxrq0.js +0 -2
  200. package/dist/chunk-bkaw7sgz.js +0 -2
  201. package/dist/chunk-d0q2x8e3.js +0 -2
  202. package/dist/chunk-d2c5727w.js +0 -2
  203. package/dist/chunk-d5amzers.js +0 -2
  204. package/dist/chunk-dfchrqw5.js +0 -2
  205. package/dist/chunk-epv0ahg1.js +0 -2
  206. package/dist/chunk-f5489ese.js +0 -2
  207. package/dist/chunk-fqq1w9m1.js +0 -2
  208. package/dist/chunk-hcgsgnq8.js +0 -2
  209. package/dist/chunk-hgqcqg1h.js +0 -2
  210. package/dist/chunk-hjdwf9gp.js +0 -2
  211. package/dist/chunk-hp7ewdnp.js +0 -2
  212. package/dist/chunk-jjtzm6dn.js +0 -3
  213. package/dist/chunk-js79j12f.js +0 -18
  214. package/dist/chunk-kfsp322p.js +0 -2
  215. package/dist/chunk-kt557jaj.js +0 -2
  216. package/dist/chunk-n8kqvzba.js +0 -2
  217. package/dist/chunk-na70r4sp.js +0 -2
  218. package/dist/chunk-p083sckk.js +0 -2
  219. package/dist/chunk-pc178389.js +0 -2
  220. package/dist/chunk-psqk7932.js +0 -2
  221. package/dist/chunk-pv5nr9pd.js +0 -2
  222. package/dist/chunk-q1v0jwr4.js +0 -2
  223. package/dist/chunk-qeye0901.js +0 -2
  224. package/dist/chunk-qy59yp2v.js +0 -2
  225. package/dist/chunk-r5gjb55x.js +0 -2
  226. package/dist/chunk-tf44jyrh.js +0 -2
  227. package/dist/chunk-tfypkw4y.js +0 -3
  228. package/dist/chunk-vv4kkwhn.js +0 -2
  229. package/dist/chunk-vwhd3h8x.js +0 -2
  230. package/dist/chunk-vxj8kd2v.js +0 -2
  231. package/dist/chunk-vzzpvn21.js +0 -2
  232. package/dist/chunk-w1a2v264.js +0 -2
  233. package/dist/chunk-wcs7w8wv.js +0 -2
  234. package/dist/chunk-x6ndnpvr.js +0 -2
  235. package/dist/chunk-x8rckpyz.js +0 -2
  236. package/dist/chunk-ya0qecph.js +0 -27
  237. package/dist/chunk-ykwmqh8z.js +0 -2
  238. package/dist/chunk-ys71pmrb.js +0 -2
  239. package/dist/chunk-z5y4qyhg.js +0 -2
  240. package/dist/chunk-zpcz2kh6.js +0 -2
  241. package/dist/native/compiler/codegen.d.ts +0 -10
  242. package/dist/native/compiler/codegen.js +0 -145
  243. package/dist/native/compiler/parser.d.ts +0 -88
  244. package/dist/native/compiler/parser.js +0 -753
  245. package/dist/native/runtime/entry.d.ts +0 -1
  246. package/dist/native/runtime/entry.js +0 -3
  247. package/dist/native/runtime/index.d.ts +0 -45
  248. package/dist/native/runtime/index.js +0 -165
  249. package/dist/native/runtime/screen.d.ts +0 -43
  250. package/dist/native/runtime/screen.js +0 -808
@@ -1,808 +0,0 @@
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
- }