orvyn-lang 0.2.0 → 0.4.0
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/GUIDE.md +198 -0
- package/LANGUAGE.md +818 -30
- package/README.md +211 -250
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +207 -16
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +152 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +615 -58
- package/src/lang/device.js +41 -0
- package/src/lang/doctor.js +60 -0
- package/src/lang/env.js +27 -0
- package/src/lang/errors.js +513 -0
- package/src/lang/form.js +69 -8
- package/src/lang/index.js +2 -1
- package/src/lang/lexer.js +2 -0
- package/src/lang/list.js +44 -0
- package/src/lang/native/android/MainActivity.kt +65 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +176 -7
- package/src/lang/native/android/OrvynRenderer.kt +970 -50
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/assets.js +39 -0
- package/src/lang/native/build.js +140 -63
- package/src/lang/native/compatibility.js +57 -0
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +291 -4
- package/src/lang/native/ios/OrvynViews.swift +769 -41
- package/src/lang/native/ios.js +81 -2
- package/src/lang/native-runtime.js +541 -55
- package/src/lang/native-size.js +53 -0
- package/src/lang/page-files.js +71 -0
- package/src/lang/page.js +63 -0
- package/src/lang/parser.js +278 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +12 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +796 -10
- package/src/lang/runtime.js +399 -51
- package/src/lang/select.js +13 -0
- package/src/lang/server-code.js +233 -0
- package/src/lang/server-export.js +78 -0
- package/src/lang/server-libs.js +53 -0
- package/src/lang/server.js +409 -0
- package/src/lang/style-check.js +60 -0
- package/src/lang/test-runner.js +134 -0
- package/src/lang/types.js +317 -0
- package/src/lang/vite-plugin.js +108 -6
- package/src/lang/web-overlay.js +578 -0
- package/src/lang/widgets.js +94 -0
- package/src/lang/words.js +38 -0
- package/src/runtime/animations.js +24 -0
- package/src/runtime/appear.js +73 -0
- package/src/runtime/marquee.js +57 -0
- package/src/runtime/mount.js +120 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +50 -9
- package/src/styling/fluid.js +129 -6
- package/src/styling/spec.js +319 -0
|
@@ -1,15 +1,64 @@
|
|
|
1
|
-
import { effect, signal } from "../core/signal.js";
|
|
1
|
+
import { effect, onCleanup, signal } from "../core/signal.js";
|
|
2
|
+
import { nativeSize, cssParts } from "./native-size.js";
|
|
3
|
+
import { customAnimation } from "../runtime/animations.js";
|
|
4
|
+
import { defineAnimation } from "../runtime/animations.js";
|
|
2
5
|
import { createVNode } from "../runtime/vnode.js";
|
|
6
|
+
import {
|
|
7
|
+
autoButtonColor,
|
|
8
|
+
resolveFontFamily,
|
|
9
|
+
resolveThemeToken,
|
|
10
|
+
STYLE_SPEC,
|
|
11
|
+
theme,
|
|
12
|
+
warnStyle
|
|
13
|
+
} from "../styling/spec.js";
|
|
3
14
|
import { signal as signal2 } from "../core/signal.js";
|
|
4
15
|
import { createVNode as createVNode2 } from "../runtime/vnode.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
16
|
+
import { theme as theme2, setStyleWarningHandler } from "../styling/spec.js";
|
|
17
|
+
import {
|
|
18
|
+
createCancelToken,
|
|
19
|
+
createComponentInstance,
|
|
20
|
+
createHttp,
|
|
21
|
+
createSavedSignal,
|
|
22
|
+
createSecureStorage,
|
|
23
|
+
createStorageManager,
|
|
24
|
+
allScreens,
|
|
25
|
+
currentCancelToken,
|
|
26
|
+
runAppWork,
|
|
27
|
+
runWithComponentInstance,
|
|
28
|
+
startAppWork
|
|
29
|
+
} from "./runtime-shared.js";
|
|
30
|
+
import { createRouter } from "./router.js";
|
|
31
|
+
import { createAuth } from "./auth.js";
|
|
32
|
+
import { createErrorCenter } from "./errors.js";
|
|
33
|
+
import { createList } from "./list.js";
|
|
34
|
+
import { createDevice } from "./device.js";
|
|
35
|
+
const nativeAppId = () => String(globalThis.__orvynAppId || "");
|
|
36
|
+
function checkHostError(result) {
|
|
37
|
+
if (typeof result === "string" && result.length > 0) {
|
|
38
|
+
throw new Error(result);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const { savedSignal, resetState, storage } = createStorageManager({
|
|
7
42
|
get: (key) => {
|
|
8
43
|
const value = globalThis.__orvynStorageGet?.(key);
|
|
9
44
|
return value === void 0 ? null : value;
|
|
10
45
|
},
|
|
11
|
-
set: (key, value) => globalThis.__orvynStorageSet?.(key, value)
|
|
12
|
-
|
|
46
|
+
set: (key, value) => checkHostError(globalThis.__orvynStorageSet?.(key, value)),
|
|
47
|
+
remove: (key) => checkHostError(globalThis.__orvynStorageRemove?.(key))
|
|
48
|
+
}, nativeAppId);
|
|
49
|
+
const secure = createSecureStorage({
|
|
50
|
+
get isSecure() {
|
|
51
|
+
const g = globalThis;
|
|
52
|
+
return typeof g.__orvynSecureGet === "function" && typeof g.__orvynSecureSet === "function";
|
|
53
|
+
},
|
|
54
|
+
get: (key) => {
|
|
55
|
+
const value = globalThis.__orvynSecureGet?.(key);
|
|
56
|
+
return value === void 0 ? null : value;
|
|
57
|
+
},
|
|
58
|
+
set: (key, value) => checkHostError(globalThis.__orvynSecureSet?.(key, value)),
|
|
59
|
+
remove: (key) => checkHostError(globalThis.__orvynSecureRemove?.(key)),
|
|
60
|
+
clear: () => checkHostError(globalThis.__orvynSecureClear?.())
|
|
61
|
+
}, nativeAppId);
|
|
13
62
|
import {
|
|
14
63
|
readImported,
|
|
15
64
|
bindInput,
|
|
@@ -25,21 +74,41 @@ import {
|
|
|
25
74
|
setField,
|
|
26
75
|
sleep,
|
|
27
76
|
random,
|
|
28
|
-
len
|
|
77
|
+
len,
|
|
78
|
+
track,
|
|
79
|
+
resume,
|
|
80
|
+
componentState,
|
|
81
|
+
errorText,
|
|
82
|
+
isEmptyValue,
|
|
83
|
+
env,
|
|
84
|
+
setEnv,
|
|
85
|
+
registerScreens,
|
|
86
|
+
registeredScreens,
|
|
87
|
+
bindCheck
|
|
29
88
|
} from "./runtime-shared.js";
|
|
30
89
|
import { validate } from "./validation.js";
|
|
90
|
+
import { keyed } from "./list.js";
|
|
91
|
+
import { createSelect } from "./select.js";
|
|
92
|
+
import { createModal, createTabs, createMap } from "./widgets.js";
|
|
93
|
+
import { words } from "./words.js";
|
|
94
|
+
const List = createList(false);
|
|
95
|
+
const setPage = (_page) => {
|
|
96
|
+
};
|
|
31
97
|
import { formCache, createForm } from "./form.js";
|
|
32
98
|
const host = globalThis;
|
|
99
|
+
const platform = host.__orvynPlatform === "android" ? "android" : "ios";
|
|
100
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
33
101
|
let nextFetchId = 0;
|
|
34
102
|
const pendingFetches = /* @__PURE__ */ new Map();
|
|
35
103
|
host.__orvynFetchDone = (id, status, text, contentType) => {
|
|
36
104
|
const pending = pendingFetches.get(id);
|
|
37
105
|
if (!pending) return;
|
|
38
106
|
pendingFetches.delete(id);
|
|
107
|
+
pending.cleanup();
|
|
39
108
|
if (status === 0) {
|
|
40
109
|
pending.reject(new Error(`[Orvyn] fetch("${pending.url}") failed: ${text}`));
|
|
41
110
|
} else if (status < 200 || status >= 300) {
|
|
42
|
-
pending.reject(new Error(`[Orvyn] fetch("${pending.url}") failed with status ${status}`));
|
|
111
|
+
pending.reject(Object.assign(new Error(`[Orvyn] fetch("${pending.url}") failed with status ${status}`), { status }));
|
|
43
112
|
} else if ((contentType || "").includes("json")) {
|
|
44
113
|
try {
|
|
45
114
|
pending.resolve(JSON.parse(text));
|
|
@@ -50,7 +119,7 @@ host.__orvynFetchDone = (id, status, text, contentType) => {
|
|
|
50
119
|
pending.resolve(text);
|
|
51
120
|
}
|
|
52
121
|
};
|
|
53
|
-
function
|
|
122
|
+
function rawFetchData(url, options = {}) {
|
|
54
123
|
const id = ++nextFetchId;
|
|
55
124
|
const headers = { ...options.headers || {} };
|
|
56
125
|
let body = options.body;
|
|
@@ -58,34 +127,92 @@ function fetchData(url, options = {}) {
|
|
|
58
127
|
body = JSON.stringify(body);
|
|
59
128
|
headers["Content-Type"] = headers["Content-Type"] || "application/json";
|
|
60
129
|
}
|
|
130
|
+
const active = currentCancelToken();
|
|
131
|
+
const token = createCancelToken(options.signal);
|
|
132
|
+
const unbindActive = active ? active.onAbort((reason) => token.abort(reason)) : () => {
|
|
133
|
+
};
|
|
134
|
+
const timeoutMs = options.timeout === false || options.timeout === 0 ? 0 : Number(options.timeout ?? DEFAULT_TIMEOUT_MS) || 0;
|
|
61
135
|
return new Promise((resolve, reject) => {
|
|
62
|
-
|
|
136
|
+
let timedOut = false;
|
|
137
|
+
let timer = null;
|
|
138
|
+
let unbindAbort = () => {
|
|
139
|
+
};
|
|
140
|
+
const cleanup = () => {
|
|
141
|
+
if (timer !== null) {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
timer = null;
|
|
144
|
+
}
|
|
145
|
+
unbindAbort();
|
|
146
|
+
unbindActive();
|
|
147
|
+
token.cleanup();
|
|
148
|
+
};
|
|
149
|
+
const abortRequest = (reason) => {
|
|
150
|
+
if (!pendingFetches.has(id)) return;
|
|
151
|
+
pendingFetches.delete(id);
|
|
152
|
+
cleanup();
|
|
153
|
+
try {
|
|
154
|
+
host.__orvynAbortFetch?.(id);
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
if (reason === "timeout") {
|
|
158
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") timed out after ${timeoutMs}ms`), { name: "TimeoutError" }));
|
|
159
|
+
} else {
|
|
160
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") was cancelled`), { name: "AbortError" }));
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
if (token.aborted) {
|
|
164
|
+
cleanup();
|
|
165
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") was cancelled`), { name: "AbortError" }));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
pendingFetches.set(id, { resolve, reject, url, cleanup });
|
|
169
|
+
unbindAbort = token.onAbort(() => abortRequest(timedOut ? "timeout" : "cancel"));
|
|
170
|
+
if (timeoutMs > 0) {
|
|
171
|
+
timer = setTimeout(() => {
|
|
172
|
+
timedOut = true;
|
|
173
|
+
token.abort(new Error(`Timed out after ${timeoutMs}ms`));
|
|
174
|
+
}, timeoutMs);
|
|
175
|
+
}
|
|
63
176
|
host.__orvynFetch(id, String(url), options.method || "GET", body ?? null, JSON.stringify(headers));
|
|
64
177
|
});
|
|
65
178
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
179
|
+
let nextDeviceId = 0;
|
|
180
|
+
const pendingDevice = /* @__PURE__ */ new Map();
|
|
181
|
+
globalThis.__orvynDeviceDone = (id, json, error) => {
|
|
182
|
+
const waiting = pendingDevice.get(id);
|
|
183
|
+
if (!waiting) return;
|
|
184
|
+
pendingDevice.delete(id);
|
|
185
|
+
if (error) waiting.reject(new Error(`[Orvyn] ${error}`));
|
|
186
|
+
else waiting.resolve(json ? JSON.parse(json) : null);
|
|
187
|
+
};
|
|
188
|
+
const { pickPhoto, takePhoto, pickFile, getLocation } = createDevice((kind) => new Promise((resolve, reject) => {
|
|
189
|
+
const ask = globalThis.__orvynDevice;
|
|
190
|
+
if (!ask) return reject(new Error("[Orvyn] This app can't use the device here"));
|
|
191
|
+
const id = ++nextDeviceId;
|
|
192
|
+
pendingDevice.set(id, { resolve, reject });
|
|
193
|
+
ask(id, kind);
|
|
194
|
+
}));
|
|
195
|
+
const errorCenter = createErrorCenter({
|
|
196
|
+
isDev: () => Boolean(globalThis.__orvynDev),
|
|
197
|
+
send: (url, body) => rawFetchData(url, { method: "POST", body, timeout: 1e4 })
|
|
198
|
+
});
|
|
199
|
+
const at = errorCenter.at;
|
|
200
|
+
const guard = errorCenter.guard;
|
|
201
|
+
const renderError = errorCenter.renderError;
|
|
202
|
+
const registerSource = errorCenter.registerSource;
|
|
203
|
+
const onError = errorCenter.onError;
|
|
204
|
+
const setErrorPage = errorCenter.setErrorPage;
|
|
205
|
+
const reportError = errorCenter.report;
|
|
206
|
+
const log = errorCenter.log;
|
|
207
|
+
const auth = createAuth(secure, { onLogoutReset: () => {
|
|
208
|
+
storage.resetAll();
|
|
209
|
+
storage.clear();
|
|
210
|
+
} });
|
|
211
|
+
const fetchData = auth.__wrapFetch(rawFetchData);
|
|
212
|
+
const { get, post, put, patch, load, task } = createHttp(fetchData);
|
|
213
|
+
const STYLE_KEYS = new Set(
|
|
214
|
+
Object.entries(STYLE_SPEC).filter(([, spec]) => spec.support === "all").map(([key]) => key)
|
|
215
|
+
);
|
|
89
216
|
let handlers = [];
|
|
90
217
|
host.__orvynEvent = (id, value) => {
|
|
91
218
|
const handler = handlers[id];
|
|
@@ -103,11 +230,64 @@ function isVNode(value) {
|
|
|
103
230
|
return value && typeof value === "object" && "tag" in value && "props" in value && "children" in value;
|
|
104
231
|
}
|
|
105
232
|
function resolveResponsive(value) {
|
|
106
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
233
|
+
if (value && typeof value === "object" && !Array.isArray(value) && ("mobile" in value || "tablet" in value || "desktop" in value)) {
|
|
107
234
|
return value.mobile ?? value.tablet ?? value.desktop ?? Object.values(value)[0];
|
|
108
235
|
}
|
|
109
236
|
return value;
|
|
110
237
|
}
|
|
238
|
+
function resolveNativeStyleValue(key, raw, currentTheme = theme()) {
|
|
239
|
+
const responsive = resolveResponsive(raw);
|
|
240
|
+
if (responsive === void 0 || responsive === null) return void 0;
|
|
241
|
+
if ((key === "pressed" || key === "active" || key === "focus") && typeof responsive === "object") {
|
|
242
|
+
const nested = {};
|
|
243
|
+
for (const subKey in responsive) {
|
|
244
|
+
if (STYLE_KEYS.has(subKey)) {
|
|
245
|
+
const subVal = resolveNativeStyleValue(subKey, responsive[subKey], currentTheme);
|
|
246
|
+
if (subVal !== void 0 && subVal !== null) nested[subKey] = subVal;
|
|
247
|
+
} else {
|
|
248
|
+
warnStyle(subKey, "native");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return Object.keys(nested).length ? nested : void 0;
|
|
252
|
+
}
|
|
253
|
+
const themed = resolveThemeToken(key, responsive, currentTheme);
|
|
254
|
+
if (key === "position") return themed === "absolute" || themed === "sticky" ? themed : void 0;
|
|
255
|
+
if (["top", "right", "bottom", "left"].includes(key) && typeof themed === "string") {
|
|
256
|
+
const trimmed = themed.trim();
|
|
257
|
+
if (/^-?\d+(\.\d+)?%$/.test(trimmed)) return trimmed;
|
|
258
|
+
return nativeSize(trimmed) ?? (Number.isFinite(Number(trimmed.replace(/px$/, ""))) ? Number(trimmed.replace(/px$/, "")) : void 0);
|
|
259
|
+
}
|
|
260
|
+
if (key === "bg" && typeof themed === "string") return nativeBackground(themed);
|
|
261
|
+
if (key === "font") return resolveFontFamily(themed, "native") ?? themed;
|
|
262
|
+
if (["width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "size"].includes(key) && typeof themed === "string") {
|
|
263
|
+
return nativeSize(themed) ?? themed;
|
|
264
|
+
}
|
|
265
|
+
return themed;
|
|
266
|
+
}
|
|
267
|
+
function percentWithCap(value) {
|
|
268
|
+
if (typeof value !== "string") return null;
|
|
269
|
+
const match = value.trim().match(/^min\(\s*([^,]+?)\s*,\s*([^,]+?)\s*\)$/);
|
|
270
|
+
if (!match) return null;
|
|
271
|
+
const [a, b] = [match[1], match[2]];
|
|
272
|
+
const percent = /^\d+(\.\d+)?%$/.test(a) ? a : /^\d+(\.\d+)?%$/.test(b) ? b : null;
|
|
273
|
+
if (!percent) return null;
|
|
274
|
+
const cap = nativeSize(percent === a ? b : a) ?? Number(String(percent === a ? b : a).replace(/px$/, ""));
|
|
275
|
+
return Number.isFinite(cap) ? { percent, cap } : null;
|
|
276
|
+
}
|
|
277
|
+
function nativeBackground(value) {
|
|
278
|
+
if (!/(gradient\(|url\()/i.test(value)) return value;
|
|
279
|
+
const colours = [];
|
|
280
|
+
const pattern = /#[0-9a-f]{6}\b|#[0-9a-f]{3}\b|rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/gi;
|
|
281
|
+
for (const match of value.matchAll(pattern)) {
|
|
282
|
+
if (match[0].startsWith("#")) {
|
|
283
|
+
colours.push(match[0]);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (match[4] !== void 0 && Number(match[4]) < 1) continue;
|
|
287
|
+
colours.push("#" + [match[1], match[2], match[3]].map((n) => Math.min(255, Number(n)).toString(16).padStart(2, "0")).join(""));
|
|
288
|
+
}
|
|
289
|
+
return colours.length ? colours[colours.length - 1] : "transparent";
|
|
290
|
+
}
|
|
111
291
|
function flatten(children, out = []) {
|
|
112
292
|
for (const child of children) {
|
|
113
293
|
if (Array.isArray(child)) flatten(child, out);
|
|
@@ -126,7 +306,10 @@ function nodeType(tag, props) {
|
|
|
126
306
|
case "button":
|
|
127
307
|
return "button";
|
|
128
308
|
case "input":
|
|
309
|
+
case "textarea":
|
|
129
310
|
return "input";
|
|
311
|
+
case "select":
|
|
312
|
+
return "select";
|
|
130
313
|
case "img":
|
|
131
314
|
return "image";
|
|
132
315
|
case "a":
|
|
@@ -139,92 +322,395 @@ function nodeType(tag, props) {
|
|
|
139
322
|
}
|
|
140
323
|
}
|
|
141
324
|
}
|
|
142
|
-
|
|
325
|
+
const nativeFnIds = /* @__PURE__ */ new WeakMap();
|
|
326
|
+
let nextNativeFnId = 0;
|
|
327
|
+
function getNativeFnId(fn) {
|
|
328
|
+
let id = nativeFnIds.get(fn);
|
|
329
|
+
if (!id) {
|
|
330
|
+
id = ++nextNativeFnId;
|
|
331
|
+
nativeFnIds.set(fn, id);
|
|
332
|
+
}
|
|
333
|
+
return id;
|
|
334
|
+
}
|
|
335
|
+
const nativeInstances = /* @__PURE__ */ new Map();
|
|
336
|
+
function disposeNativeInstances() {
|
|
337
|
+
for (const entry of nativeInstances.values()) {
|
|
338
|
+
entry.instance.dispose();
|
|
339
|
+
}
|
|
340
|
+
nativeInstances.clear();
|
|
341
|
+
}
|
|
342
|
+
const pendingNativeButtons = /* @__PURE__ */ new Set();
|
|
343
|
+
const pendingVersion = signal(0);
|
|
344
|
+
function wrapNativeButtonTap(nodeId, tap) {
|
|
345
|
+
return (...args) => {
|
|
346
|
+
if (pendingNativeButtons.has(nodeId)) return;
|
|
347
|
+
const outcome = tap(...args);
|
|
348
|
+
if (outcome && typeof outcome.then === "function") {
|
|
349
|
+
pendingNativeButtons.add(nodeId);
|
|
350
|
+
pendingVersion.set(pendingVersion.get() + 1);
|
|
351
|
+
return Promise.resolve(outcome).finally(() => {
|
|
352
|
+
if (pendingNativeButtons.delete(nodeId)) {
|
|
353
|
+
pendingVersion.set(pendingVersion.get() + 1);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return outcome;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function toNative(value, id, submit, scopePath = "") {
|
|
143
361
|
if (typeof value === "string" || typeof value === "number") {
|
|
144
362
|
return { id, t: "text", s: {}, x: String(value) };
|
|
145
363
|
}
|
|
146
364
|
if (!isVNode(value)) return null;
|
|
147
365
|
if (typeof value.tag === "function") {
|
|
148
|
-
const
|
|
366
|
+
const fnId = getNativeFnId(value.tag);
|
|
367
|
+
const explicitKey = value.props?.key;
|
|
368
|
+
const instanceKey = explicitKey !== void 0 && explicitKey !== null ? `${scopePath}|fn:${fnId}|k:${typeof explicitKey}:${String(explicitKey)}` : `${id}|fn:${fnId}`;
|
|
369
|
+
let entry = nativeInstances.get(instanceKey);
|
|
370
|
+
if (!entry) {
|
|
371
|
+
entry = { instance: createComponentInstance(), users: 0 };
|
|
372
|
+
nativeInstances.set(instanceKey, entry);
|
|
373
|
+
}
|
|
374
|
+
const current = entry;
|
|
375
|
+
current.users++;
|
|
376
|
+
onCleanup(() => {
|
|
377
|
+
current.users--;
|
|
378
|
+
queueMicrotask(() => {
|
|
379
|
+
if (current.users === 0 && nativeInstances.get(instanceKey) === current) {
|
|
380
|
+
nativeInstances.delete(instanceKey);
|
|
381
|
+
current.instance.dispose();
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
const rendered = runWithComponentInstance(
|
|
386
|
+
current.instance,
|
|
387
|
+
() => value.tag({ ...value.props, children: value.children })
|
|
388
|
+
);
|
|
149
389
|
const list = flatten(Array.isArray(rendered) ? rendered : [rendered]);
|
|
150
|
-
return {
|
|
390
|
+
return {
|
|
391
|
+
id: instanceKey,
|
|
392
|
+
t: "col",
|
|
393
|
+
s: {},
|
|
394
|
+
c: list.map((child, i) => toNative(child, `${instanceKey}.${i}`, submit, instanceKey)).filter(Boolean)
|
|
395
|
+
};
|
|
151
396
|
}
|
|
152
397
|
const props = value.props || {};
|
|
398
|
+
if (resolveResponsive(props.show) === false) return null;
|
|
399
|
+
if (props.nativeRole === "toggle") {
|
|
400
|
+
const [input, words2] = value.children;
|
|
401
|
+
const node2 = {
|
|
402
|
+
id: `${id}:toggle`,
|
|
403
|
+
t: "toggle",
|
|
404
|
+
s: {},
|
|
405
|
+
x: String(words2.children[0] ?? ""),
|
|
406
|
+
v: input.props.checked ? "true" : "false",
|
|
407
|
+
inputType: input.props.role === "switch" ? "switch" : "checkbox"
|
|
408
|
+
};
|
|
409
|
+
if (input.props.disabled) node2.s.disabled = true;
|
|
410
|
+
else node2.e = { change: handlers.push(input.props.onInput) - 1 };
|
|
411
|
+
if (props["aria-label"] !== void 0) node2.a = String(props["aria-label"]);
|
|
412
|
+
return node2;
|
|
413
|
+
}
|
|
153
414
|
if (value.tag === "form") submit = props.onSubmit;
|
|
154
|
-
const t = nodeType(value.tag, props);
|
|
155
|
-
const
|
|
156
|
-
|
|
415
|
+
const t = props.nativeRole === "map" ? "map" : props.nativeRole === "list" ? "list" : props.nativeRole === "modal" ? "modal" : nodeType(value.tag, props);
|
|
416
|
+
const elKey = props.key;
|
|
417
|
+
const childScope = elKey !== void 0 && elKey !== null ? `${scopePath}|ek:${typeof elKey}:${String(elKey)}:${t}` : scopePath;
|
|
418
|
+
const node = { id: elKey !== void 0 && elKey !== null ? childScope : `${id}:${t}`, t, s: {} };
|
|
419
|
+
if (props["aria-label"] !== void 0) node.a = String(props["aria-label"]);
|
|
420
|
+
if (t === "list") node.rh = Number(props.rowHeight);
|
|
421
|
+
if (t === "map") {
|
|
422
|
+
node.v = String(props["data-place"]);
|
|
423
|
+
node.src = String(props.src);
|
|
424
|
+
node.a = String(props.title);
|
|
425
|
+
}
|
|
426
|
+
const currentTheme = theme();
|
|
427
|
+
for (const key in t === "modal" ? {} : props) {
|
|
428
|
+
if (["aria-label", "alt", "loading", "decoding", "nativeRole", "rowHeight", "role", "rows", "title", "data-place"].includes(key) && !(key === "loading" && typeof props[key] === "boolean")) continue;
|
|
429
|
+
if (key.startsWith("data-")) continue;
|
|
157
430
|
if (STYLE_KEYS.has(key)) {
|
|
158
|
-
|
|
431
|
+
if (key === "padding" && typeof resolveResponsive(props.padding) === "string") {
|
|
432
|
+
const parts = cssParts(String(resolveResponsive(props.padding)));
|
|
433
|
+
const size = (part) => nativeSize(part) ?? (Number.isFinite(Number(part)) ? Number(part) : void 0);
|
|
434
|
+
if (parts.length > 1) {
|
|
435
|
+
const [top, right = top, bottom = top, left = right] = parts.map(size);
|
|
436
|
+
const sides = { paddingTop: top, paddingRight: right, paddingBottom: bottom, paddingLeft: left };
|
|
437
|
+
for (const side in sides) if (sides[side] !== void 0 && props[side] === void 0) node.s[side] = sides[side];
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const single = size(parts[0] ?? "");
|
|
441
|
+
if (single !== void 0) {
|
|
442
|
+
node.s.padding = single;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (key === "margin" && typeof resolveResponsive(props.margin) === "string") {
|
|
447
|
+
const parts = cssParts(String(resolveResponsive(props.margin)));
|
|
448
|
+
if (parts.length > 1) {
|
|
449
|
+
if ((parts[1] ?? parts[0]) === "auto") node.s.centerSelf = true;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (key === "radius" && typeof resolveResponsive(props.radius) === "string" && cssParts(String(resolveResponsive(props.radius))).length > 1) {
|
|
454
|
+
const first = cssParts(String(resolveResponsive(props.radius)))[0];
|
|
455
|
+
const value2 = nativeSize(first) ?? Number(first);
|
|
456
|
+
if (Number.isFinite(value2)) node.s.radius = value2;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
if (key === "bg") {
|
|
460
|
+
const bg = resolveResponsive(props.bg);
|
|
461
|
+
const photo = typeof bg === "string" ? bg.match(/url\(\s*["']?([^"')]+)["']?\s*\)/i) : null;
|
|
462
|
+
if (photo) {
|
|
463
|
+
const src = photo[1];
|
|
464
|
+
node.s.bgImage = globalThis.__orvynAssets?.includes(src) ? "asset:" + src : src;
|
|
465
|
+
if (/gradient\(/i.test(bg.slice(0, photo.index))) node.s.bgDim = 0.5;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (/^(padding|paddingX|paddingY|margin|gap)$/.test(key)) {
|
|
469
|
+
const raw = resolveResponsive(props[key]);
|
|
470
|
+
const em = typeof raw === "string" ? raw.trim().match(/^(-?\d*\.?\d+)em$/) : null;
|
|
471
|
+
if (em) {
|
|
472
|
+
const textSize = Number(resolveResponsive(props.size)) || 17;
|
|
473
|
+
node.s[key] = Number(em[1]) * textSize;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (key === "basis") {
|
|
478
|
+
if (props.width !== void 0) continue;
|
|
479
|
+
const basis = resolveResponsive(props.basis);
|
|
480
|
+
const capped2 = percentWithCap(basis);
|
|
481
|
+
const grows = Number(resolveResponsive(props.grow)) > 0;
|
|
482
|
+
if (capped2) {
|
|
483
|
+
node.s.width = capped2.percent;
|
|
484
|
+
if (props.maxWidth === void 0 && !grows) node.s.maxWidth = capped2.cap;
|
|
485
|
+
} else if (typeof basis === "string" && /^\d+(\.\d+)?%$/.test(basis.trim())) node.s.width = basis.trim();
|
|
486
|
+
else if (typeof basis === "number") node.s.width = basis;
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
const capped = key === "width" || key === "height" ? percentWithCap(resolveResponsive(props[key])) : null;
|
|
490
|
+
if (capped) {
|
|
491
|
+
node.s[key] = capped.percent;
|
|
492
|
+
const maxKey = key === "width" ? "maxWidth" : "maxHeight";
|
|
493
|
+
if (node.s[maxKey] === void 0 && props[maxKey] === void 0) node.s[maxKey] = capped.cap;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const resolved = resolveNativeStyleValue(key, props[key], currentTheme);
|
|
159
497
|
if (resolved !== void 0 && resolved !== null) node.s[key] = resolved;
|
|
498
|
+
} else {
|
|
499
|
+
warnStyle(key, "native");
|
|
160
500
|
}
|
|
161
501
|
}
|
|
162
|
-
|
|
502
|
+
if (typeof node.s.appear === "string") {
|
|
503
|
+
const from = customAnimation(node.s.appear.trim().split(/\s+/)[0]);
|
|
504
|
+
if (from) node.s.appearFrom = from;
|
|
505
|
+
}
|
|
506
|
+
if (t === "button" && props.bg && !props.color) {
|
|
507
|
+
const fg = autoButtonColor(props.bg, currentTheme);
|
|
508
|
+
if (fg) node.s.color = fg;
|
|
509
|
+
}
|
|
510
|
+
const autoLoading = t === "button" && props.type !== "submit" && pendingNativeButtons.has(node.id);
|
|
511
|
+
if (autoLoading && node.s.loading === void 0) {
|
|
512
|
+
node.s.loading = true;
|
|
513
|
+
}
|
|
514
|
+
const blocked = Boolean(props.disabled || props.loading || autoLoading);
|
|
515
|
+
const rawTap = !blocked ? props.onClick ?? (value.tag === "button" && props.type === "submit" ? submit : void 0) : void 0;
|
|
516
|
+
if (t === "modal" && props.onClick) {
|
|
517
|
+
const close = value.children[0]?.children.find((c) => c?.props?.nativeRole === "close")?.props.onClick;
|
|
518
|
+
if (close) node.e = { ...node.e, tap: handlers.push(close) - 1 };
|
|
519
|
+
}
|
|
520
|
+
const tap = t === "modal" ? void 0 : rawTap && t === "button" && props.type !== "submit" ? wrapNativeButtonTap(node.id, rawTap) : rawTap;
|
|
163
521
|
if (tap) {
|
|
164
522
|
node.e = { ...node.e, tap: handlers.push(tap) - 1 };
|
|
165
523
|
}
|
|
166
524
|
if (props.onInput) {
|
|
167
525
|
node.e = { ...node.e, change: handlers.push(props.onInput) - 1 };
|
|
168
526
|
}
|
|
527
|
+
if (props.onVisible) {
|
|
528
|
+
node.e = { ...node.e, visible: handlers.push(props.onVisible) - 1 };
|
|
529
|
+
}
|
|
169
530
|
if (props.placeholder !== void 0) node.ph = String(props.placeholder);
|
|
170
531
|
if (t === "input" && props.type !== void 0) node.inputType = String(props.type);
|
|
532
|
+
if (value.tag === "textarea") node.inputType = "multiline";
|
|
171
533
|
if (props.value !== void 0) node.v = props.value === null ? "" : String(props.value);
|
|
172
|
-
if (props.src !== void 0)
|
|
534
|
+
if (props.src !== void 0) {
|
|
535
|
+
const src = String(props.src);
|
|
536
|
+
node.src = globalThis.__orvynAssets?.includes(src) ? "asset:" + src : src;
|
|
537
|
+
}
|
|
173
538
|
if (props.href !== void 0) node.href = String(props.href);
|
|
174
539
|
const children = flatten(value.children || []);
|
|
540
|
+
if (t === "select") {
|
|
541
|
+
node.ph = String(children[0]?.children?.[0] ?? "");
|
|
542
|
+
node.o = children.slice(1).map((option) => String(option.props.value));
|
|
543
|
+
node.v = String(children.find((option) => option.props.selected)?.props.value ?? "");
|
|
544
|
+
return node;
|
|
545
|
+
}
|
|
175
546
|
const isLeaf = t === "text" || t === "heading" || t === "button" || t === "link";
|
|
176
547
|
if (isLeaf) {
|
|
177
548
|
node.x = children.map((child) => typeof child === "string" || typeof child === "number" ? String(child) : "").join("");
|
|
178
549
|
} else if (t !== "input" && t !== "image") {
|
|
179
|
-
node.c = children.map((child, i) => toNative(child, `${node.id}.${i}`, submit)).filter(Boolean);
|
|
550
|
+
node.c = children.map((child, i) => toNative(child, `${node.id}.${i}`, submit, childScope)).filter(Boolean);
|
|
180
551
|
}
|
|
181
552
|
return node;
|
|
182
553
|
}
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
554
|
+
const router = createRouter();
|
|
555
|
+
router.setGuard(auth.__guard);
|
|
556
|
+
auth.__attachRouter(router);
|
|
557
|
+
const go = router.go;
|
|
558
|
+
const back = router.back;
|
|
559
|
+
const canGoBack = router.canGoBack;
|
|
560
|
+
function scrollTo(label, _offset = 0) {
|
|
561
|
+
const scroll = host.__orvynScrollTo;
|
|
562
|
+
if (typeof scroll === "function") scroll(String(label));
|
|
563
|
+
}
|
|
564
|
+
function openUrl(url) {
|
|
565
|
+
if (/^(https?:|mailto:|tel:|sms:|whatsapp:)/i.test(url)) {
|
|
566
|
+
const external = host.__orvynOpenExternal;
|
|
567
|
+
if (typeof external === "function") {
|
|
568
|
+
external(url);
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
return false;
|
|
187
572
|
}
|
|
188
|
-
|
|
573
|
+
return router.openUrl(url);
|
|
189
574
|
}
|
|
190
|
-
|
|
575
|
+
host.__orvynBack = () => router.back();
|
|
576
|
+
host.__orvynDeepLink = (url) => router.openUrl(url);
|
|
577
|
+
function startApp(_target, entry, onStart, screens = {}, initialParams = {}) {
|
|
191
578
|
if (typeof entry !== "function") {
|
|
192
579
|
throw new Error("[Orvyn] No screen to show. Add: screen Home { ... }");
|
|
193
580
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
581
|
+
disposeNativeInstances();
|
|
582
|
+
const endWork = startAppWork();
|
|
583
|
+
screens = { ...allScreens, ...screens };
|
|
584
|
+
router.start(entry, screens, initialParams, {
|
|
585
|
+
getInitialUrl: () => host.__orvynInitialUrl ?? null
|
|
586
|
+
});
|
|
587
|
+
const stop = effect(() => {
|
|
588
|
+
pendingVersion.get();
|
|
589
|
+
const current = router.current();
|
|
590
|
+
if (!current) return;
|
|
591
|
+
const currentTheme = theme();
|
|
197
592
|
handlers = [];
|
|
198
|
-
|
|
593
|
+
let tree = toNative(
|
|
594
|
+
createVNode(current.screen, { ...current.params, key: current.key }, []),
|
|
595
|
+
current.screen.name || "screen"
|
|
596
|
+
);
|
|
597
|
+
const overlayNodes = errorCenter.renderDevOverlay();
|
|
598
|
+
if (overlayNodes.length) {
|
|
599
|
+
const open = errorCenter.overlay.isOpen;
|
|
600
|
+
const box = toNative(createVNode("div", {
|
|
601
|
+
flex: true,
|
|
602
|
+
direction: "column",
|
|
603
|
+
gap: 8,
|
|
604
|
+
...open ? { padding: 16, bg: "#0f172a", grow: 1 } : { padding: 8 }
|
|
605
|
+
}, overlayNodes), "__orvyn_dev_overlay");
|
|
606
|
+
if (box) {
|
|
607
|
+
tree = open || !tree ? box : { ...box, c: [...box.c ?? [], tree] };
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (tree) {
|
|
611
|
+
tree.canGoBack = router.canGoBack();
|
|
612
|
+
tree.theme = {
|
|
613
|
+
dark: currentTheme.dark,
|
|
614
|
+
bg: currentTheme.colors.bg,
|
|
615
|
+
surface: currentTheme.colors.surface,
|
|
616
|
+
card: currentTheme.colors.card,
|
|
617
|
+
text: currentTheme.colors.text,
|
|
618
|
+
muted: currentTheme.colors.muted,
|
|
619
|
+
primary: currentTheme.colors.primary,
|
|
620
|
+
border: currentTheme.colors.border,
|
|
621
|
+
danger: currentTheme.colors.danger
|
|
622
|
+
};
|
|
623
|
+
}
|
|
199
624
|
host.__orvynRender(JSON.stringify(tree));
|
|
200
625
|
});
|
|
201
626
|
if (onStart) {
|
|
202
|
-
Promise.resolve().then(onStart).catch((error) => console.error(String(error?.stack || error)));
|
|
627
|
+
Promise.resolve().then(() => runAppWork(onStart)).catch((error) => console.error(String(error?.stack || error)));
|
|
203
628
|
}
|
|
629
|
+
return () => {
|
|
630
|
+
endWork();
|
|
631
|
+
stop();
|
|
632
|
+
router.reset();
|
|
633
|
+
disposeNativeInstances();
|
|
634
|
+
for (const pending of pendingFetches.values()) pending.cleanup();
|
|
635
|
+
pendingFetches.clear();
|
|
636
|
+
pendingNativeButtons.clear();
|
|
637
|
+
handlers = [];
|
|
638
|
+
};
|
|
204
639
|
}
|
|
205
640
|
export {
|
|
641
|
+
List,
|
|
206
642
|
add,
|
|
643
|
+
at,
|
|
644
|
+
auth,
|
|
645
|
+
back,
|
|
646
|
+
bindCheck,
|
|
207
647
|
bindInput,
|
|
648
|
+
canGoBack,
|
|
208
649
|
clear,
|
|
650
|
+
componentState,
|
|
209
651
|
createForm,
|
|
652
|
+
createMap,
|
|
653
|
+
createModal,
|
|
654
|
+
createSavedSignal,
|
|
655
|
+
createSelect,
|
|
656
|
+
createTabs,
|
|
210
657
|
createVNode2 as createVNode,
|
|
658
|
+
defineAnimation,
|
|
659
|
+
env,
|
|
660
|
+
errorText,
|
|
211
661
|
fetchData,
|
|
212
662
|
formCache,
|
|
663
|
+
get,
|
|
664
|
+
getLocation,
|
|
213
665
|
go,
|
|
666
|
+
guard,
|
|
214
667
|
importedState,
|
|
668
|
+
isEmptyValue,
|
|
669
|
+
keyed,
|
|
215
670
|
len,
|
|
671
|
+
load,
|
|
672
|
+
log,
|
|
673
|
+
nativeBackground,
|
|
674
|
+
nativeSize,
|
|
675
|
+
onError,
|
|
676
|
+
openUrl,
|
|
677
|
+
patch,
|
|
678
|
+
pickFile,
|
|
679
|
+
pickPhoto,
|
|
680
|
+
platform,
|
|
681
|
+
post,
|
|
682
|
+
put,
|
|
216
683
|
random,
|
|
217
684
|
readImported,
|
|
685
|
+
registerScreens,
|
|
686
|
+
registerSource,
|
|
687
|
+
registeredScreens,
|
|
218
688
|
remove,
|
|
219
689
|
removeAt,
|
|
690
|
+
renderError,
|
|
691
|
+
reportError,
|
|
692
|
+
resetState,
|
|
693
|
+
resume,
|
|
220
694
|
savedSignal,
|
|
695
|
+
scrollTo,
|
|
696
|
+
secure,
|
|
221
697
|
setAt,
|
|
698
|
+
setEnv,
|
|
699
|
+
setErrorPage,
|
|
222
700
|
setField,
|
|
701
|
+
setPage,
|
|
702
|
+
setStyleWarningHandler,
|
|
223
703
|
signal2 as signal,
|
|
224
704
|
sleep,
|
|
225
705
|
startApp,
|
|
706
|
+
storage,
|
|
226
707
|
str,
|
|
227
708
|
submitHandler,
|
|
709
|
+
takePhoto,
|
|
710
|
+
task,
|
|
711
|
+
theme2 as theme,
|
|
712
|
+
track,
|
|
228
713
|
update,
|
|
229
|
-
validate
|
|
714
|
+
validate,
|
|
715
|
+
words
|
|
230
716
|
};
|