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