@stacksjs/stx 0.2.534 → 0.2.536

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 (85) hide show
  1. package/dist/{chunk-843y0pfg.js → chunk-0yveptr0.js} +2 -2
  2. package/dist/{chunk-01343ehq.js → chunk-1es2y1jz.js} +1 -1
  3. package/dist/{chunk-13zbt9py.js → chunk-22ztsen0.js} +1 -1
  4. package/dist/{chunk-7zgtdap7.js → chunk-2kf4z3e6.js} +1 -1
  5. package/dist/{chunk-9p6bt089.js → chunk-33vbh6g3.js} +1 -1
  6. package/dist/{chunk-qqr4rn9p.js → chunk-5zp9wt6m.js} +2 -2
  7. package/dist/{chunk-pz1mjgsp.js → chunk-672nmsmm.js} +1 -1
  8. package/dist/{chunk-nmy4x6dx.js → chunk-7g90r41h.js} +1 -1
  9. package/dist/{chunk-f3q84h7b.js → chunk-8bt1mxny.js} +1 -1
  10. package/dist/{chunk-d1jxmhph.js → chunk-9e1hftmd.js} +1 -1
  11. package/dist/{chunk-7v2j9bmc.js → chunk-bgvqcjrg.js} +1 -1
  12. package/dist/{chunk-8chxczpj.js → chunk-bk5g7qez.js} +1 -1
  13. package/dist/{chunk-wxy9re1a.js → chunk-c0prbbpe.js} +1 -1
  14. package/dist/{chunk-kcs7hyep.js → chunk-dr0394tm.js} +1 -1
  15. package/dist/{chunk-tgc645pa.js → chunk-e6mmvwy9.js} +5 -5
  16. package/dist/{chunk-bxsehntq.js → chunk-f1cc1z85.js} +1 -1
  17. package/dist/{chunk-9674w2gm.js → chunk-g9byv420.js} +1 -1
  18. package/dist/{chunk-4a7v51vh.js → chunk-gx3cs15y.js} +1 -1
  19. package/dist/{chunk-sqb6gkzf.js → chunk-h51g1ydb.js} +1 -1
  20. package/dist/{chunk-gsc5t942.js → chunk-hen8zqnp.js} +1 -1
  21. package/dist/{chunk-tr9bjtqx.js → chunk-hpkrscgk.js} +1 -1
  22. package/dist/{chunk-z9r3tqyr.js → chunk-jn9e5a4t.js} +1 -1
  23. package/dist/{chunk-90kzf313.js → chunk-jq3j35a6.js} +1 -1
  24. package/dist/{chunk-xwrbrg1q.js → chunk-jsa2apk6.js} +1 -1
  25. package/dist/{chunk-94rg5s6c.js → chunk-jskc4rr7.js} +1 -1
  26. package/dist/{chunk-jv3jj612.js → chunk-knxqe213.js} +1 -1
  27. package/dist/chunk-kvn3xsfq.js +2 -0
  28. package/dist/{chunk-k3v13vfr.js → chunk-mx3rh8zj.js} +1 -1
  29. package/dist/chunk-n9k24wmf.js +57 -0
  30. package/dist/{chunk-d871008z.js → chunk-nn66ek7z.js} +1 -1
  31. package/dist/{chunk-ngma9vzc.js → chunk-pd460250.js} +1 -1
  32. package/dist/{chunk-v4r8nzf3.js → chunk-pekfkzh7.js} +1 -1
  33. package/dist/{chunk-gnx0fzne.js → chunk-pwdvc964.js} +19 -19
  34. package/dist/{chunk-3zs8yxy0.js → chunk-qmd2kvb2.js} +1 -1
  35. package/dist/{chunk-kvp0at16.js → chunk-s9htq6ef.js} +1 -1
  36. package/dist/{chunk-2n4je46m.js → chunk-sh8ec2e0.js} +1 -1
  37. package/dist/chunk-sve2646p.js +2 -0
  38. package/dist/{chunk-5g498pdp.js → chunk-sye2bjyq.js} +1 -1
  39. package/dist/{chunk-6rcxtdh3.js → chunk-tr49ckr5.js} +1 -1
  40. package/dist/{chunk-qk3ptn6h.js → chunk-va61kyky.js} +1 -1
  41. package/dist/{chunk-93n6yv5x.js → chunk-ve6tn04z.js} +1 -1
  42. package/dist/{chunk-0e5nasyf.js → chunk-vmq2dd3k.js} +1 -1
  43. package/dist/{chunk-fqfqyn48.js → chunk-xq7f1yc2.js} +1 -1
  44. package/dist/chunk-xvjtj1kt.js +2 -0
  45. package/dist/{chunk-vfnerp7h.js → chunk-xy5sx2z1.js} +1 -1
  46. package/dist/{chunk-2h4f37kx.js → chunk-xz7dk3yc.js} +1 -1
  47. package/dist/{chunk-zeve89kw.js → chunk-y5acfh13.js} +1 -1
  48. package/dist/{chunk-4pxc3r1p.js → chunk-z0h3we7z.js} +2 -2
  49. package/dist/{chunk-jvqas8y2.js → chunk-zaj09h72.js} +1 -1
  50. package/dist/{chunk-wjt46tdp.js → chunk-zs5p8jcn.js} +1 -1
  51. package/dist/cli.js +8 -8
  52. package/dist/client/signals-loop-conditional-runtime.d.ts +1 -1
  53. package/dist/client/signals-loop-conditional-runtime.js +1 -1
  54. package/dist/craft-entry.js +1 -1
  55. package/dist/craft.js +1 -1
  56. package/dist/native/bridge/protocol.d.ts +3 -1
  57. package/dist/native/compiler/browser.d.ts +10 -0
  58. package/dist/native/compiler/browser.js +31 -0
  59. package/dist/native/compiler/bundle.d.ts +3 -0
  60. package/dist/native/compiler/bundle.js +27 -10
  61. package/dist/native/compiler/html-to-ir.d.ts +2 -0
  62. package/dist/native/compiler/html-to-ir.js +8 -3
  63. package/dist/native/compiler/icons.d.ts +2 -0
  64. package/dist/native/compiler/icons.js +2 -0
  65. package/dist/native/compiler/render-screen.d.ts +1 -0
  66. package/dist/native/compiler/render-screen.js +2 -2
  67. package/dist/native/index.d.ts +1 -0
  68. package/dist/native/index.js +1 -0
  69. package/dist/native/runtime/browser-renderer.d.ts +16 -0
  70. package/dist/native/runtime/browser-renderer.js +537 -0
  71. package/dist/native/runtime/browser-screen.d.ts +26 -0
  72. package/dist/native/runtime/browser-screen.js +254 -0
  73. package/dist/native/runtime/craft-bridge.js +10 -6
  74. package/dist/native/runtime/craft.d.ts +1 -0
  75. package/dist/native/runtime/jsc-globals.js +1 -1
  76. package/dist/native/runtime/native-host.js +9 -4
  77. package/dist/pwa.js +1 -1
  78. package/dist/signals-loop-conditional-runtime.d.ts +1 -1
  79. package/dist/ssg.js +2 -2
  80. package/dist/variable-extractor.js +5 -1
  81. package/package.json +5 -5
  82. package/dist/chunk-40hbpz2b.js +0 -45
  83. package/dist/chunk-5wx323bm.js +0 -2
  84. package/dist/chunk-epa1c4q4.js +0 -2
  85. package/dist/chunk-ydtnskdv.js +0 -2
@@ -0,0 +1,537 @@
1
+ import { LUCIDE_TO_SF } from "../compiler/icons.js";
2
+ const SYMBOL_TO_ICON = Object.fromEntries(Object.entries(LUCIDE_TO_SF).map(([name, symbol]) => [symbol, name])), SVG_NS = "http://www.w3.org/2000/svg", SVG = { Svg: "svg", G: "g", Path: "path", Line: "line", Rect: "rect", Circle: "circle", Ellipse: "ellipse", Polyline: "polyline", Polygon: "polygon", SvgText: "text" }, TAGS = { View: "div", SafeAreaView: "div", ScrollView: "div", KeyboardAvoidingView: "div", Text: "span", TextInput: "input", Button: "button", TouchableOpacity: "button", TouchableHighlight: "button", Pressable: "button", Icon: "span", Image: "img", ImageBackground: "div", Video: "video", FlatList: "div", SectionList: "div", Switch: "input", Checkbox: "input", Slider: "input", Picker: "select", DatePicker: "input", Modal: "dialog", ActivityIndicator: "progress", StatusBar: "div", RefreshControl: "progress", Sidebar: "aside", SplitView: "div" }, CONTAINERS = new Set(["View", "SafeAreaView", "ScrollView", "KeyboardAvoidingView", "FlatList", "SectionList", "Sidebar", "SplitView", "ImageBackground"]), UNITLESS = new Set(["opacity", "flex", "flexGrow", "flexShrink", "fontWeight", "zIndex", "aspectRatio", "order"]), SVG_PROPS = { viewBox: "viewBox", fillRule: "fill-rule", clipRule: "clip-rule", strokeWidth: "stroke-width", strokeLinecap: "stroke-linecap", strokeLinejoin: "stroke-linejoin", strokeDasharray: "stroke-dasharray", strokeDashoffset: "stroke-dashoffset", fillOpacity: "fill-opacity", strokeOpacity: "stroke-opacity", textAnchor: "text-anchor" };
3
+
4
+ export class BrowserScreenRenderer {
5
+ container;
6
+ options;
7
+ nodes = new Map;
8
+ revision = 0;
9
+ root = null;
10
+ constructor(container, options) {
11
+ this.container = container;
12
+ this.options = options;
13
+ }
14
+ render(tree) {
15
+ const ids = new Set, validate = (node) => {
16
+ if (!node.id || ids.has(node.id))
17
+ throw Error("Screen node ids must be unique and non-empty");
18
+ ids.add(node.id);
19
+ this.tag(node.type);
20
+ if (node.type === "Icon")
21
+ this.icon(node.props);
22
+ for (const child of node.children)
23
+ if (typeof child !== "string")
24
+ validate(child);
25
+ };
26
+ validate(tree);
27
+ this.dispose();
28
+ const create = (node, parent) => {
29
+ if (!node.id)
30
+ throw Error("A portable screen node needs an id");
31
+ const record = this.create(node.id, node.type, node.props, { ...node.style }, node.events);
32
+ record.parent = parent;
33
+ for (const child of node.children)
34
+ if (typeof child === "string")
35
+ record.element.append(this.container.ownerDocument.createTextNode(child));
36
+ else {
37
+ record.element.append(create(child, node.id));
38
+ record.children.push(child.id);
39
+ }
40
+ return record.element;
41
+ };
42
+ this.container.replaceChildren(create(tree, null));
43
+ this.root = tree.id;
44
+ this.revision = 0;
45
+ }
46
+ mutate(batch) {
47
+ if (batch.version !== 1 || batch.baseRevision !== this.revision || batch.revision !== this.revision + 1)
48
+ throw Error("REVISION_MISMATCH");
49
+ this.validate(batch.operations);
50
+ for (const operation of batch.operations)
51
+ if (operation.op === "createNode") {
52
+ const record = this.create(operation.id, operation.node.type, operation.node.props ?? {}, operation.node.style ?? {}, operation.node.events ?? {});
53
+ if (operation.node.children)
54
+ record.element.textContent = operation.node.children.join("");
55
+ } else if (operation.op === "updateNode") {
56
+ const record = this.nodes.get(operation.id);
57
+ Object.assign(record.props, operation.patch.props);
58
+ Object.assign(record.style, operation.patch.style);
59
+ Object.assign(record.events, operation.patch.events);
60
+ if (operation.patch.children)
61
+ record.element.textContent = operation.patch.children.join("");
62
+ this.update(record);
63
+ } else if (operation.op === "removeNode")
64
+ this.remove(operation.id);
65
+ else {
66
+ const parent = this.nodes.get(operation.parentId), child = this.nodes.get(operation.childId);
67
+ if (child.parent) {
68
+ const old = this.nodes.get(child.parent);
69
+ old.children = old.children.filter((id) => id !== operation.childId);
70
+ }
71
+ parent.children.splice(operation.index, 0, operation.childId);
72
+ child.parent = operation.parentId;
73
+ const before = parent.children[operation.index + 1];
74
+ parent.element.insertBefore(child.element, before ? this.nodes.get(before).element : null);
75
+ }
76
+ this.revision = batch.revision;
77
+ }
78
+ validate(operations) {
79
+ const parents = new Map([...this.nodes].map(([id, node]) => [id, node.parent])), children = new Map([...this.nodes].map(([id, node]) => [id, [...node.children]])), descriptors = new Map([...this.nodes].map(([id, node]) => [id, { type: node.type, props: { ...node.props } }])), remove = (id) => {
80
+ for (const child of children.get(id) ?? [])
81
+ remove(child);
82
+ parents.delete(id);
83
+ children.delete(id);
84
+ };
85
+ for (const operation of operations)
86
+ if (operation.op === "createNode") {
87
+ if (parents.has(operation.id) || !this.tag(operation.node.type))
88
+ throw Error(`Invalid create: ${operation.id}`);
89
+ const props = operation.node.props ?? {};
90
+ if (operation.node.type === "Icon")
91
+ this.icon(props);
92
+ descriptors.set(operation.id, { type: operation.node.type, props: { ...props } });
93
+ parents.set(operation.id, null);
94
+ children.set(operation.id, []);
95
+ } else if (operation.op === "insertChild" || operation.op === "moveChild") {
96
+ if (!parents.has(operation.parentId) || !parents.has(operation.childId))
97
+ throw Error("Missing mutation node");
98
+ let ancestor = operation.parentId;
99
+ while (ancestor) {
100
+ if (ancestor === operation.childId)
101
+ throw Error("A screen tree cannot contain a cycle");
102
+ ancestor = parents.get(ancestor) ?? null;
103
+ }
104
+ const old = parents.get(operation.childId);
105
+ if (old)
106
+ children.set(old, children.get(old).filter((id) => id !== operation.childId));
107
+ const list = children.get(operation.parentId);
108
+ if (!Number.isInteger(operation.index) || operation.index < 0 || operation.index > list.length)
109
+ throw Error("Invalid child index");
110
+ list.splice(operation.index, 0, operation.childId);
111
+ parents.set(operation.childId, operation.parentId);
112
+ } else {
113
+ if (!parents.has(operation.id))
114
+ throw Error(`Unknown mutation node: ${operation.id}`);
115
+ if (operation.op === "removeNode") {
116
+ if (operation.id === this.root)
117
+ throw Error("Cannot remove the screen root");
118
+ const parent = parents.get(operation.id);
119
+ if (parent)
120
+ children.set(parent, children.get(parent).filter((id) => id !== operation.id));
121
+ remove(operation.id);
122
+ } else {
123
+ if (operation.patch.children && children.get(operation.id).length)
124
+ throw Error("Cannot replace structural children with text");
125
+ const descriptor = descriptors.get(operation.id);
126
+ Object.assign(descriptor.props, operation.patch.props);
127
+ if (descriptor.type === "Icon")
128
+ this.icon(descriptor.props);
129
+ }
130
+ }
131
+ }
132
+ tag(type) {
133
+ const tag = SVG[type] ?? TAGS[type];
134
+ if (!tag)
135
+ throw Error(`Unsupported browser primitive: ${type}`);
136
+ return tag;
137
+ }
138
+ create(id, type, props, style, events) {
139
+ const doc = this.container.ownerDocument, tag = type === "TextInput" && props.multiline ? "textarea" : this.tag(type), element = SVG[type] ? doc.createElementNS(SVG_NS, tag) : doc.createElement(tag), record = { element, type, props: { ...props }, style: { ...style }, events: { ...events }, parent: null, children: [], dispose: [] };
140
+ this.nodes.set(id, record);
141
+ element.setAttribute("data-stx-node", id);
142
+ element.setAttribute("data-stx-primitive", type);
143
+ this.events(record);
144
+ this.update(record);
145
+ return record;
146
+ }
147
+ fire(record, name, payload = {}) {
148
+ if (record.props.disabled && ["onPress", "onLongPress", "onPressIn", "onPressOut"].includes(name))
149
+ return;
150
+ const handler = record.events[name];
151
+ if (handler)
152
+ this.options.event(handler, payload);
153
+ }
154
+ events(record) {
155
+ const element = record.element, listen = (name, listener) => {
156
+ element.addEventListener(name, listener);
157
+ record.dispose.push(() => element.removeEventListener(name, listener));
158
+ };
159
+ listen("click", (event) => {
160
+ if (record.props.disabled || record.props.editable === !1)
161
+ return;
162
+ if (event.target?.closest("[data-stx-pressable]") !== element && element.hasAttribute("data-stx-pressable"))
163
+ return;
164
+ this.fire(record, "onPress");
165
+ });
166
+ listen("input", () => {
167
+ const input = element;
168
+ if (record.type === "Slider")
169
+ this.fire(record, "onValueChange", { value: Number(input.value) });
170
+ else
171
+ this.fire(record, "onChangeText", { text: input.value, value: input.value });
172
+ });
173
+ listen("change", () => {
174
+ const input = element, value = record.type === "Switch" || record.type === "Checkbox" ? input.checked : record.type === "Slider" ? Number(input.value) : input.value;
175
+ this.fire(record, "onValueChange", { value, text: input.value });
176
+ if (record.type === "Slider")
177
+ this.fire(record, "onSlidingComplete", { value });
178
+ });
179
+ listen("focus", () => this.fire(record, "onFocus"));
180
+ listen("blur", () => {
181
+ this.fire(record, "onBlur");
182
+ this.fire(record, "onEndEditing", { text: element.value });
183
+ });
184
+ listen("keydown", (event) => {
185
+ if (event.key === "Enter" && !record.props.multiline)
186
+ this.fire(record, "onSubmitEditing", { text: element.value });
187
+ });
188
+ listen("contextmenu", (event) => {
189
+ if (record.events.onLongPress) {
190
+ event.preventDefault();
191
+ this.fire(record, "onLongPress");
192
+ }
193
+ });
194
+ listen("pointerdown", () => this.fire(record, "onPressIn"));
195
+ listen("pointerup", () => this.fire(record, "onPressOut"));
196
+ listen("cancel", (event) => {
197
+ if (record.events.onRequestClose) {
198
+ event.preventDefault();
199
+ this.fire(record, "onRequestClose");
200
+ }
201
+ });
202
+ listen("close", () => this.fire(record, "onDismiss"));
203
+ listen("scroll", () => this.fire(record, "onScroll", { contentOffset: { x: element.scrollLeft, y: element.scrollTop }, layoutMeasurement: { width: element.clientWidth, height: element.clientHeight }, contentSize: { width: element.scrollWidth, height: element.scrollHeight } }));
204
+ const videoEvents = { play: "onPlay", pause: "onPause", ended: "onEnd", timeupdate: "onProgress", loadedmetadata: "onLoad", loadstart: "onLoadStart", loadeddata: "onLoadEnd", error: "onError", enterpictureinpicture: "onPictureInPictureStart", leavepictureinpicture: "onPictureInPictureStop" };
205
+ if (record.type === "Video")
206
+ for (const [name, native] of Object.entries(videoEvents))
207
+ listen(name, () => {
208
+ const video = element;
209
+ this.fire(record, native, { currentTime: video.currentTime, duration: Number.isFinite(video.duration) ? video.duration : 0, position: video.currentTime, error: video.error?.message });
210
+ });
211
+ if (record.type === "ScrollView") {
212
+ let start = null;
213
+ listen("touchstart", (event) => {
214
+ start = element.scrollTop <= 0 ? event.touches[0]?.clientY ?? null : null;
215
+ });
216
+ listen("touchend", (event) => {
217
+ const end = event.changedTouches[0]?.clientY;
218
+ if (start !== null && end !== void 0 && end - start > 80 && !record.props.refreshing)
219
+ this.fire(record, "onRefresh");
220
+ start = null;
221
+ });
222
+ }
223
+ }
224
+ update(record) {
225
+ const { element, props, type, style } = record, css = element.style;
226
+ css.cssText = "";
227
+ css.boxSizing = "border-box";
228
+ css.borderStyle = "solid";
229
+ css.borderWidth = "0";
230
+ if (CONTAINERS.has(type)) {
231
+ css.display = "flex";
232
+ css.flexDirection = "column";
233
+ css.minWidth = "0";
234
+ css.flexShrink = "0";
235
+ }
236
+ if (type === "Text") {
237
+ css.display = "block";
238
+ css.whiteSpace = "pre-wrap";
239
+ css.flexShrink = "1";
240
+ css.minWidth = "0";
241
+ css.overflowWrap = "anywhere";
242
+ }
243
+ if (["Button", "TouchableOpacity", "TouchableHighlight", "Pressable"].includes(type)) {
244
+ css.display = "flex";
245
+ css.flexDirection = "column";
246
+ css.alignItems = "stretch";
247
+ css.font = "inherit";
248
+ css.color = "inherit";
249
+ css.background = "transparent";
250
+ css.border = "0";
251
+ css.padding = "0";
252
+ css.textAlign = "inherit";
253
+ css.cursor = "pointer";
254
+ }
255
+ if (type === "ScrollView") {
256
+ css.overflowY = "auto";
257
+ css.overscrollBehaviorY = "contain";
258
+ css.flex = "1";
259
+ css.minHeight = "0";
260
+ css.flexDirection = props.horizontal ? "row" : "column";
261
+ if (props.horizontal)
262
+ css.overflowX = "auto";
263
+ }
264
+ if (type === "Image") {
265
+ css.objectFit = String(props.resizeMode ?? "cover");
266
+ css.display = "block";
267
+ }
268
+ if (type === "TextInput") {
269
+ css.font = "inherit";
270
+ css.color = "inherit";
271
+ css.background = "transparent";
272
+ css.border = "0";
273
+ css.minWidth = "0";
274
+ css.minHeight = "32px";
275
+ css.outlineOffset = "2px";
276
+ }
277
+ if (type === "Icon") {
278
+ css.display = "inline-block";
279
+ css.width = "20px";
280
+ css.height = "20px";
281
+ css.flexShrink = "0";
282
+ }
283
+ this.style(css, style);
284
+ if (props.contentContainerStyle && typeof props.contentContainerStyle === "object")
285
+ this.style(css, props.contentContainerStyle);
286
+ if (props.testID != null)
287
+ element.setAttribute("data-testid", String(props.testID));
288
+ if (props.accessibilityLabel != null || type === "TextInput" && props.placeholder)
289
+ element.setAttribute("aria-label", String(props.accessibilityLabel ?? props.placeholder));
290
+ else
291
+ element.removeAttribute("aria-label");
292
+ if (props.accessibilityHint != null)
293
+ element.setAttribute("aria-description", String(props.accessibilityHint));
294
+ const role = props.accessibilityRole;
295
+ if (role && role !== "none")
296
+ element.setAttribute("role", String(role === "header" ? "heading" : role));
297
+ else
298
+ element.removeAttribute("role");
299
+ if (record.events.onPress || ["Button", "TouchableOpacity", "TouchableHighlight", "Pressable"].includes(type)) {
300
+ element.setAttribute("data-stx-pressable", "");
301
+ if (!["input", "button", "select", "textarea", "a"].includes(element.tagName.toLowerCase())) {
302
+ element.setAttribute("role", String(role || "button"));
303
+ element.setAttribute("tabindex", props.disabled ? "-1" : "0");
304
+ element.onkeydown = (event) => {
305
+ if (event.key === " " || event.key === "Enter") {
306
+ event.preventDefault();
307
+ this.fire(record, "onPress");
308
+ }
309
+ };
310
+ }
311
+ }
312
+ if (["Switch", "Checkbox", "Slider", "TextInput", "DatePicker", "Button", "Picker"].includes(type))
313
+ element.disabled = Boolean(props.disabled);
314
+ if (type === "Switch" || type === "Checkbox") {
315
+ const input = element;
316
+ input.type = "checkbox";
317
+ input.checked = Boolean(props.value ?? props.checked);
318
+ input.setAttribute("role", type === "Switch" ? "switch" : "checkbox");
319
+ }
320
+ if (type === "Slider") {
321
+ const input = element;
322
+ input.type = "range";
323
+ input.min = String(props.minimumValue ?? 0);
324
+ input.max = String(props.maximumValue ?? 1);
325
+ input.step = String(props.step ?? "any");
326
+ input.value = String(props.value ?? 0);
327
+ }
328
+ if (type === "TextInput" || type === "DatePicker") {
329
+ const input = element;
330
+ if (type === "DatePicker") {
331
+ input.type = props.mode === "time" ? "time" : props.mode === "datetime" ? "datetime-local" : "date";
332
+ input.min = String(props.minimumDate ?? props.min ?? "");
333
+ input.max = String(props.maximumDate ?? props.max ?? "");
334
+ if (props.mode === "time")
335
+ input.step = String(Number(props.minuteInterval ?? 1) * 60);
336
+ } else if (!props.multiline)
337
+ input.type = props.secureTextEntry ? "password" : props.keyboardType === "email-address" ? "email" : "text";
338
+ const inputMode = props.keyboardType === "decimal-pad" ? "decimal" : props.keyboardType === "number-pad" || props.keyboardType === "numeric" ? "numeric" : props.keyboardType === "phone-pad" ? "tel" : "";
339
+ if (inputMode)
340
+ input.inputMode = inputMode;
341
+ const value = props.value == null ? "" : String(props.value);
342
+ if (input.value !== value)
343
+ input.value = value;
344
+ input.placeholder = String(props.placeholder ?? "");
345
+ input.readOnly = props.editable === !1;
346
+ if (props.maxLength != null)
347
+ input.maxLength = Number(props.maxLength);
348
+ if (props.autoComplete)
349
+ input.autocomplete = String(props.autoComplete);
350
+ }
351
+ if (type === "Picker") {
352
+ const select = element, options = Array.isArray(props.options) ? props.options : [], signature = JSON.stringify(options);
353
+ if (select.dataset.options !== signature) {
354
+ select.replaceChildren(...options.map((option) => {
355
+ const node = element.ownerDocument.createElement("option");
356
+ node.value = String(option.value);
357
+ node.textContent = String(option.label ?? option.value);
358
+ return node;
359
+ }));
360
+ select.dataset.options = signature;
361
+ }
362
+ select.value = String(props.value ?? "");
363
+ }
364
+ if (type === "Image" || type === "Video" || type === "ImageBackground") {
365
+ const source = props.source ?? props.src, url = typeof source === "string" ? source : source && typeof source === "object" ? String(source.uri ?? "") : "";
366
+ if (type === "ImageBackground")
367
+ css.backgroundImage = `url(${JSON.stringify(url)})`;
368
+ if (url !== element.getAttribute("data-source")) {
369
+ element.setAttribute("data-source", url);
370
+ const apply = (resolved) => {
371
+ if (!this.nodes.has(element.getAttribute("data-stx-node") ?? "") || element.getAttribute("data-source") !== url)
372
+ return;
373
+ if (type === "ImageBackground")
374
+ css.backgroundImage = `url(${JSON.stringify(resolved)})`;
375
+ else
376
+ element.src = resolved;
377
+ };
378
+ apply(url);
379
+ if (url && this.options.resolveMedia)
380
+ this.options.resolveMedia(url).then(apply).catch(() => {});
381
+ }
382
+ }
383
+ if (type === "Image")
384
+ element.alt = String(props.accessibilityLabel ?? "");
385
+ if (type === "Video") {
386
+ const video = element;
387
+ video.controls = props.controls !== !1;
388
+ video.autoplay = Boolean(props.autoplay ?? props.autoPlay);
389
+ video.poster = String(props.poster ?? "");
390
+ video.disablePictureInPicture = props.pictureInPicture === !1;
391
+ css.objectFit = props.resizeMode === "contain" ? "contain" : "cover";
392
+ video.loop = Boolean(props.repeat ?? props.loop);
393
+ video.muted = Boolean(props.muted);
394
+ video.playsInline = !0;
395
+ if (typeof props.currentTime === "number" && Math.abs(video.currentTime - props.currentTime) > 0.5)
396
+ video.currentTime = props.currentTime;
397
+ if (props.paused === !0 && !video.paused)
398
+ video.pause();
399
+ if ((props.paused === !1 || props.paused === void 0 && video.autoplay) && video.paused && video.src)
400
+ video.play().catch(() => {});
401
+ }
402
+ if (type === "Modal") {
403
+ const dialog = element;
404
+ css.position = "fixed";
405
+ css.inset = "0";
406
+ css.maxWidth = "100%";
407
+ css.maxHeight = "100%";
408
+ css.width = "100%";
409
+ css.height = "100%";
410
+ css.padding = "0";
411
+ css.margin = "0";
412
+ css.border = "0";
413
+ if (!Boolean(props.visible)) {
414
+ if (dialog.open)
415
+ dialog.close();
416
+ css.display = "none";
417
+ } else
418
+ queueMicrotask(() => {
419
+ if (!dialog.isConnected || !record.props.visible)
420
+ return;
421
+ css.display = "flex";
422
+ css.flexDirection = "column";
423
+ if (!dialog.open) {
424
+ dialog.showModal();
425
+ this.fire(record, "onShow");
426
+ }
427
+ });
428
+ }
429
+ if (type === "ActivityIndicator" || type === "RefreshControl") {
430
+ element.setAttribute("aria-label", String(props.accessibilityLabel ?? "Loading"));
431
+ css.width = "24px";
432
+ css.height = "24px";
433
+ }
434
+ if (type === "StatusBar")
435
+ css.display = "none";
436
+ if (type === "Icon") {
437
+ const icon = this.icon(props);
438
+ css.backgroundColor = "currentColor";
439
+ const data = `<svg xmlns="${SVG_NS}" viewBox="0 0 ${icon.width ?? 24} ${icon.height ?? 24}">${icon.body}</svg>`;
440
+ css.mask = `url("data:image/svg+xml,${encodeURIComponent(data)}") center / contain no-repeat`;
441
+ css.webkitMask = css.mask;
442
+ element.setAttribute("aria-hidden", props.accessibilityLabel ? "false" : "true");
443
+ }
444
+ if (type === "Text" && props.numberOfLines) {
445
+ css.overflow = "hidden";
446
+ css.display = "-webkit-box";
447
+ css.webkitBoxOrient = "vertical";
448
+ css.webkitLineClamp = String(props.numberOfLines);
449
+ }
450
+ if (SVG[type])
451
+ for (const [key, value] of Object.entries(props)) {
452
+ if (["geometry", "testID", "accessibilityLabel"].includes(key))
453
+ continue;
454
+ const name = SVG_PROPS[key] ?? key;
455
+ if (value == null)
456
+ element.removeAttribute(name);
457
+ else
458
+ element.setAttribute(name, Array.isArray(value) ? value.join(" ") : String(value));
459
+ }
460
+ if (props.scrollTarget && typeof props.scrollTarget === "object") {
461
+ const target = props.scrollTarget, signature = JSON.stringify(target);
462
+ if (element.getAttribute("data-scroll-target") !== signature) {
463
+ element.setAttribute("data-scroll-target", signature);
464
+ queueMicrotask(() => {
465
+ for (const candidate of this.nodes.values())
466
+ if (candidate.props.testID === target.id)
467
+ candidate.element.scrollIntoView?.({ behavior: target.animated === !1 ? "instant" : "smooth", block: "start" });
468
+ });
469
+ }
470
+ }
471
+ }
472
+ icon(props) {
473
+ const name = String(props.iconify ?? props.name ?? props.symbol ?? ""), icon = this.options.icons?.[SYMBOL_TO_ICON[name]] ?? this.options.icons?.[name] ?? this.options.icons?.[name.replace(/^i-lucide-/, "")] ?? this.options.icons?.[String(props.symbol)];
474
+ if (!icon)
475
+ throw Error(`No browser icon registered for ${name}`);
476
+ return icon;
477
+ }
478
+ style(css, values) {
479
+ const set = (key, value) => {
480
+ const property = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
481
+ if (value == null)
482
+ css.removeProperty(property);
483
+ else
484
+ css.setProperty(property, typeof value === "number" && !UNITLESS.has(key) ? `${value}px` : String(value));
485
+ };
486
+ for (const [key, value] of Object.entries(values))
487
+ if (key.endsWith("Horizontal")) {
488
+ const base = key.slice(0, -10);
489
+ set(`${base}Left`, value);
490
+ set(`${base}Right`, value);
491
+ } else if (key.endsWith("Vertical")) {
492
+ const base = key.slice(0, -8);
493
+ set(`${base}Top`, value);
494
+ set(`${base}Bottom`, value);
495
+ } else if (key === "gridColumns")
496
+ css.gridTemplateColumns = value ? `repeat(${value}, minmax(0, 1fr))` : "";
497
+ else if (key === "transform" && Array.isArray(value))
498
+ css.transform = value.flatMap((step) => Object.entries(step).map(([name, amount]) => `${name}(${amount}${typeof amount === "number" && (name.startsWith("translate") || name === "perspective") ? "px" : ""})`)).join(" ");
499
+ else if (key.startsWith("shadow") || key === "elevation" || key.startsWith("gradient") || key === "resizeMode" || key === "tintColor")
500
+ continue;
501
+ else
502
+ set(key, value);
503
+ if (values.gradientFrom && values.gradientTo)
504
+ css.backgroundImage = `linear-gradient(${String(values.gradientDirection || "to-b").replace(/^to-/, "to ").replace("br", "bottom right").replace("bl", "bottom left").replace(/^to b$/, "to bottom").replace(/^to r$/, "to right").replace(/^to l$/, "to left").replace(/^to t$/, "to top")}, ${[values.gradientFrom, values.gradientVia, values.gradientTo].filter(Boolean).join(", ")})`;
505
+ if (values.shadowColor || values.shadowRadius) {
506
+ const offset = values.shadowOffset;
507
+ css.boxShadow = `${offset?.width ?? 0}px ${offset?.height ?? 0}px ${values.shadowRadius ?? 0}px ${values.shadowColor ?? "transparent"}`;
508
+ }
509
+ }
510
+ remove(id) {
511
+ const record = this.nodes.get(id);
512
+ if (!record)
513
+ return;
514
+ for (const child of [...record.children])
515
+ this.remove(child);
516
+ for (const dispose of record.dispose)
517
+ dispose();
518
+ if (record.type === "Video") {
519
+ record.element.pause();
520
+ record.element.removeAttribute("src");
521
+ }
522
+ record.element.remove();
523
+ if (record.parent) {
524
+ const parent = this.nodes.get(record.parent);
525
+ if (parent)
526
+ parent.children = parent.children.filter((child) => child !== id);
527
+ }
528
+ this.nodes.delete(id);
529
+ }
530
+ dispose() {
531
+ for (const id of [...this.nodes.keys()])
532
+ this.remove(id);
533
+ this.container.replaceChildren();
534
+ this.root = null;
535
+ this.revision = 0;
536
+ }
537
+ }
@@ -0,0 +1,26 @@
1
+ import { type BrowserRendererOptions } from './browser-renderer';
2
+ import type { NativeBridgeInterface } from '../bridge/protocol';
3
+ /** The browser renderer is a peer host of UIKit and Android, on the same protocol. */
4
+ export declare function createBrowserScreenBridge(platform: BrowserPlatform, options: BrowserScreenOptions): NativeBridgeInterface & { dispose: () => void };
5
+ /** Fixed route segments win over parameters, consistently with the Craft hosts. */
6
+ export declare function matchBrowserRoute(path: string, routes: Record<string, string>): { screen: string, params: Record<string, string> } | null;
7
+ export declare interface BrowserPlatform {
8
+ craft: Record<string, unknown>
9
+ capabilities: string[]
10
+ call: (module: string, method: string, args: unknown[], signal: AbortSignal) => Promise<unknown>
11
+ navigate: (path: string, replace?: boolean) => void
12
+ emit?: (listener: (type: string, payload: unknown) => void) => () => void
13
+ resolveMedia?: (url: string) => Promise<string>
14
+ resolveFile?: (value: unknown) => unknown
15
+ dispose: () => void
16
+ }
17
+ export declare interface BrowserScreenOptions {
18
+ container: string
19
+ routes: Record<string, string>
20
+ screen: string
21
+ params?: Record<string, unknown>
22
+ appURL: string
23
+ title?: string
24
+ tabs?: Array<{ id: string, title: string, symbol?: string }>
25
+ icons?: BrowserRendererOptions['icons']
26
+ }