orvyn-lang 0.2.0 → 0.3.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 +149 -0
- package/LANGUAGE.md +744 -27
- package/README.md +211 -250
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +186 -10
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +102 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +428 -57
- 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 +43 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +154 -7
- package/src/lang/native/android/OrvynRenderer.kt +518 -44
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/build.js +130 -60
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +266 -4
- package/src/lang/native/ios/OrvynViews.swift +429 -34
- package/src/lang/native/ios.js +75 -2
- package/src/lang/native-runtime.js +406 -56
- package/src/lang/page.js +52 -0
- package/src/lang/parser.js +243 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +11 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +792 -10
- package/src/lang/runtime.js +362 -52
- 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/test-runner.js +134 -0
- package/src/lang/types.js +312 -0
- package/src/lang/vite-plugin.js +82 -3
- 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/mount.js +116 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +11 -1
- package/src/styling/fluid.js +91 -4
- package/src/styling/spec.js +306 -0
|
@@ -1,15 +1,61 @@
|
|
|
1
|
-
import { effect, signal } from "../core/signal.js";
|
|
1
|
+
import { effect, onCleanup, signal } from "../core/signal.js";
|
|
2
2
|
import { createVNode } from "../runtime/vnode.js";
|
|
3
|
+
import {
|
|
4
|
+
autoButtonColor,
|
|
5
|
+
resolveFontFamily,
|
|
6
|
+
resolveThemeToken,
|
|
7
|
+
STYLE_SPEC,
|
|
8
|
+
theme,
|
|
9
|
+
warnStyle
|
|
10
|
+
} from "../styling/spec.js";
|
|
3
11
|
import { signal as signal2 } from "../core/signal.js";
|
|
4
12
|
import { createVNode as createVNode2 } from "../runtime/vnode.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
13
|
+
import { theme as theme2, setStyleWarningHandler } from "../styling/spec.js";
|
|
14
|
+
import {
|
|
15
|
+
createCancelToken,
|
|
16
|
+
createComponentInstance,
|
|
17
|
+
createHttp,
|
|
18
|
+
createSavedSignal,
|
|
19
|
+
createSecureStorage,
|
|
20
|
+
createStorageManager,
|
|
21
|
+
allScreens,
|
|
22
|
+
currentCancelToken,
|
|
23
|
+
runAppWork,
|
|
24
|
+
runWithComponentInstance,
|
|
25
|
+
startAppWork
|
|
26
|
+
} from "./runtime-shared.js";
|
|
27
|
+
import { createRouter } from "./router.js";
|
|
28
|
+
import { createAuth } from "./auth.js";
|
|
29
|
+
import { createErrorCenter } from "./errors.js";
|
|
30
|
+
import { createList } from "./list.js";
|
|
31
|
+
import { createDevice } from "./device.js";
|
|
32
|
+
const nativeAppId = () => String(globalThis.__orvynAppId || "");
|
|
33
|
+
function checkHostError(result) {
|
|
34
|
+
if (typeof result === "string" && result.length > 0) {
|
|
35
|
+
throw new Error(result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const { savedSignal, resetState, storage } = createStorageManager({
|
|
7
39
|
get: (key) => {
|
|
8
40
|
const value = globalThis.__orvynStorageGet?.(key);
|
|
9
41
|
return value === void 0 ? null : value;
|
|
10
42
|
},
|
|
11
|
-
set: (key, value) => globalThis.__orvynStorageSet?.(key, value)
|
|
12
|
-
|
|
43
|
+
set: (key, value) => checkHostError(globalThis.__orvynStorageSet?.(key, value)),
|
|
44
|
+
remove: (key) => checkHostError(globalThis.__orvynStorageRemove?.(key))
|
|
45
|
+
}, nativeAppId);
|
|
46
|
+
const secure = createSecureStorage({
|
|
47
|
+
get isSecure() {
|
|
48
|
+
const g = globalThis;
|
|
49
|
+
return typeof g.__orvynSecureGet === "function" && typeof g.__orvynSecureSet === "function";
|
|
50
|
+
},
|
|
51
|
+
get: (key) => {
|
|
52
|
+
const value = globalThis.__orvynSecureGet?.(key);
|
|
53
|
+
return value === void 0 ? null : value;
|
|
54
|
+
},
|
|
55
|
+
set: (key, value) => checkHostError(globalThis.__orvynSecureSet?.(key, value)),
|
|
56
|
+
remove: (key) => checkHostError(globalThis.__orvynSecureRemove?.(key)),
|
|
57
|
+
clear: () => checkHostError(globalThis.__orvynSecureClear?.())
|
|
58
|
+
}, nativeAppId);
|
|
13
59
|
import {
|
|
14
60
|
readImported,
|
|
15
61
|
bindInput,
|
|
@@ -25,21 +71,39 @@ import {
|
|
|
25
71
|
setField,
|
|
26
72
|
sleep,
|
|
27
73
|
random,
|
|
28
|
-
len
|
|
74
|
+
len,
|
|
75
|
+
track,
|
|
76
|
+
resume,
|
|
77
|
+
componentState,
|
|
78
|
+
errorText,
|
|
79
|
+
isEmptyValue,
|
|
80
|
+
env,
|
|
81
|
+
setEnv,
|
|
82
|
+
registerScreens,
|
|
83
|
+
bindCheck
|
|
29
84
|
} from "./runtime-shared.js";
|
|
30
85
|
import { validate } from "./validation.js";
|
|
86
|
+
import { keyed } from "./list.js";
|
|
87
|
+
import { createSelect } from "./select.js";
|
|
88
|
+
import { createModal, createTabs, createMap } from "./widgets.js";
|
|
89
|
+
import { words } from "./words.js";
|
|
90
|
+
const List = createList(false);
|
|
91
|
+
const setPage = (_page) => {
|
|
92
|
+
};
|
|
31
93
|
import { formCache, createForm } from "./form.js";
|
|
32
94
|
const host = globalThis;
|
|
95
|
+
const DEFAULT_TIMEOUT_MS = 15e3;
|
|
33
96
|
let nextFetchId = 0;
|
|
34
97
|
const pendingFetches = /* @__PURE__ */ new Map();
|
|
35
98
|
host.__orvynFetchDone = (id, status, text, contentType) => {
|
|
36
99
|
const pending = pendingFetches.get(id);
|
|
37
100
|
if (!pending) return;
|
|
38
101
|
pendingFetches.delete(id);
|
|
102
|
+
pending.cleanup();
|
|
39
103
|
if (status === 0) {
|
|
40
104
|
pending.reject(new Error(`[Orvyn] fetch("${pending.url}") failed: ${text}`));
|
|
41
105
|
} else if (status < 200 || status >= 300) {
|
|
42
|
-
pending.reject(new Error(`[Orvyn] fetch("${pending.url}") failed with status ${status}`));
|
|
106
|
+
pending.reject(Object.assign(new Error(`[Orvyn] fetch("${pending.url}") failed with status ${status}`), { status }));
|
|
43
107
|
} else if ((contentType || "").includes("json")) {
|
|
44
108
|
try {
|
|
45
109
|
pending.resolve(JSON.parse(text));
|
|
@@ -50,7 +114,7 @@ host.__orvynFetchDone = (id, status, text, contentType) => {
|
|
|
50
114
|
pending.resolve(text);
|
|
51
115
|
}
|
|
52
116
|
};
|
|
53
|
-
function
|
|
117
|
+
function rawFetchData(url, options = {}) {
|
|
54
118
|
const id = ++nextFetchId;
|
|
55
119
|
const headers = { ...options.headers || {} };
|
|
56
120
|
let body = options.body;
|
|
@@ -58,34 +122,92 @@ function fetchData(url, options = {}) {
|
|
|
58
122
|
body = JSON.stringify(body);
|
|
59
123
|
headers["Content-Type"] = headers["Content-Type"] || "application/json";
|
|
60
124
|
}
|
|
125
|
+
const active = currentCancelToken();
|
|
126
|
+
const token = createCancelToken(options.signal);
|
|
127
|
+
const unbindActive = active ? active.onAbort((reason) => token.abort(reason)) : () => {
|
|
128
|
+
};
|
|
129
|
+
const timeoutMs = options.timeout === false || options.timeout === 0 ? 0 : Number(options.timeout ?? DEFAULT_TIMEOUT_MS) || 0;
|
|
61
130
|
return new Promise((resolve, reject) => {
|
|
62
|
-
|
|
131
|
+
let timedOut = false;
|
|
132
|
+
let timer = null;
|
|
133
|
+
let unbindAbort = () => {
|
|
134
|
+
};
|
|
135
|
+
const cleanup = () => {
|
|
136
|
+
if (timer !== null) {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
timer = null;
|
|
139
|
+
}
|
|
140
|
+
unbindAbort();
|
|
141
|
+
unbindActive();
|
|
142
|
+
token.cleanup();
|
|
143
|
+
};
|
|
144
|
+
const abortRequest = (reason) => {
|
|
145
|
+
if (!pendingFetches.has(id)) return;
|
|
146
|
+
pendingFetches.delete(id);
|
|
147
|
+
cleanup();
|
|
148
|
+
try {
|
|
149
|
+
host.__orvynAbortFetch?.(id);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
if (reason === "timeout") {
|
|
153
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") timed out after ${timeoutMs}ms`), { name: "TimeoutError" }));
|
|
154
|
+
} else {
|
|
155
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") was cancelled`), { name: "AbortError" }));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if (token.aborted) {
|
|
159
|
+
cleanup();
|
|
160
|
+
reject(Object.assign(new Error(`[Orvyn] fetch("${url}") was cancelled`), { name: "AbortError" }));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
pendingFetches.set(id, { resolve, reject, url, cleanup });
|
|
164
|
+
unbindAbort = token.onAbort(() => abortRequest(timedOut ? "timeout" : "cancel"));
|
|
165
|
+
if (timeoutMs > 0) {
|
|
166
|
+
timer = setTimeout(() => {
|
|
167
|
+
timedOut = true;
|
|
168
|
+
token.abort(new Error(`Timed out after ${timeoutMs}ms`));
|
|
169
|
+
}, timeoutMs);
|
|
170
|
+
}
|
|
63
171
|
host.__orvynFetch(id, String(url), options.method || "GET", body ?? null, JSON.stringify(headers));
|
|
64
172
|
});
|
|
65
173
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
174
|
+
let nextDeviceId = 0;
|
|
175
|
+
const pendingDevice = /* @__PURE__ */ new Map();
|
|
176
|
+
globalThis.__orvynDeviceDone = (id, json, error) => {
|
|
177
|
+
const waiting = pendingDevice.get(id);
|
|
178
|
+
if (!waiting) return;
|
|
179
|
+
pendingDevice.delete(id);
|
|
180
|
+
if (error) waiting.reject(new Error(`[Orvyn] ${error}`));
|
|
181
|
+
else waiting.resolve(json ? JSON.parse(json) : null);
|
|
182
|
+
};
|
|
183
|
+
const { pickPhoto, takePhoto, pickFile, getLocation } = createDevice((kind) => new Promise((resolve, reject) => {
|
|
184
|
+
const ask = globalThis.__orvynDevice;
|
|
185
|
+
if (!ask) return reject(new Error("[Orvyn] This app can't use the device here"));
|
|
186
|
+
const id = ++nextDeviceId;
|
|
187
|
+
pendingDevice.set(id, { resolve, reject });
|
|
188
|
+
ask(id, kind);
|
|
189
|
+
}));
|
|
190
|
+
const errorCenter = createErrorCenter({
|
|
191
|
+
isDev: () => Boolean(globalThis.__orvynDev),
|
|
192
|
+
send: (url, body) => rawFetchData(url, { method: "POST", body, timeout: 1e4 })
|
|
193
|
+
});
|
|
194
|
+
const at = errorCenter.at;
|
|
195
|
+
const guard = errorCenter.guard;
|
|
196
|
+
const renderError = errorCenter.renderError;
|
|
197
|
+
const registerSource = errorCenter.registerSource;
|
|
198
|
+
const onError = errorCenter.onError;
|
|
199
|
+
const setErrorPage = errorCenter.setErrorPage;
|
|
200
|
+
const reportError = errorCenter.report;
|
|
201
|
+
const log = errorCenter.log;
|
|
202
|
+
const auth = createAuth(secure, { onLogoutReset: () => {
|
|
203
|
+
storage.resetAll();
|
|
204
|
+
storage.clear();
|
|
205
|
+
} });
|
|
206
|
+
const fetchData = auth.__wrapFetch(rawFetchData);
|
|
207
|
+
const { get, post, put, patch, load, task } = createHttp(fetchData);
|
|
208
|
+
const STYLE_KEYS = new Set(
|
|
209
|
+
Object.entries(STYLE_SPEC).filter(([, spec]) => spec.support === "all").map(([key]) => key)
|
|
210
|
+
);
|
|
89
211
|
let handlers = [];
|
|
90
212
|
host.__orvynEvent = (id, value) => {
|
|
91
213
|
const handler = handlers[id];
|
|
@@ -103,11 +225,30 @@ function isVNode(value) {
|
|
|
103
225
|
return value && typeof value === "object" && "tag" in value && "props" in value && "children" in value;
|
|
104
226
|
}
|
|
105
227
|
function resolveResponsive(value) {
|
|
106
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
228
|
+
if (value && typeof value === "object" && !Array.isArray(value) && ("mobile" in value || "tablet" in value || "desktop" in value)) {
|
|
107
229
|
return value.mobile ?? value.tablet ?? value.desktop ?? Object.values(value)[0];
|
|
108
230
|
}
|
|
109
231
|
return value;
|
|
110
232
|
}
|
|
233
|
+
function resolveNativeStyleValue(key, raw, currentTheme = theme()) {
|
|
234
|
+
const responsive = resolveResponsive(raw);
|
|
235
|
+
if (responsive === void 0 || responsive === null) return void 0;
|
|
236
|
+
if ((key === "pressed" || key === "active" || key === "focus") && typeof responsive === "object") {
|
|
237
|
+
const nested = {};
|
|
238
|
+
for (const subKey in responsive) {
|
|
239
|
+
if (STYLE_KEYS.has(subKey)) {
|
|
240
|
+
const subVal = resolveNativeStyleValue(subKey, responsive[subKey], currentTheme);
|
|
241
|
+
if (subVal !== void 0 && subVal !== null) nested[subKey] = subVal;
|
|
242
|
+
} else {
|
|
243
|
+
warnStyle(subKey, "native");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return Object.keys(nested).length ? nested : void 0;
|
|
247
|
+
}
|
|
248
|
+
const themed = resolveThemeToken(key, responsive, currentTheme);
|
|
249
|
+
if (key === "font") return resolveFontFamily(themed, "native") ?? themed;
|
|
250
|
+
return themed;
|
|
251
|
+
}
|
|
111
252
|
function flatten(children, out = []) {
|
|
112
253
|
for (const child of children) {
|
|
113
254
|
if (Array.isArray(child)) flatten(child, out);
|
|
@@ -126,7 +267,10 @@ function nodeType(tag, props) {
|
|
|
126
267
|
case "button":
|
|
127
268
|
return "button";
|
|
128
269
|
case "input":
|
|
270
|
+
case "textarea":
|
|
129
271
|
return "input";
|
|
272
|
+
case "select":
|
|
273
|
+
return "select";
|
|
130
274
|
case "img":
|
|
131
275
|
return "image";
|
|
132
276
|
case "a":
|
|
@@ -139,27 +283,131 @@ function nodeType(tag, props) {
|
|
|
139
283
|
}
|
|
140
284
|
}
|
|
141
285
|
}
|
|
142
|
-
|
|
286
|
+
const nativeFnIds = /* @__PURE__ */ new WeakMap();
|
|
287
|
+
let nextNativeFnId = 0;
|
|
288
|
+
function getNativeFnId(fn) {
|
|
289
|
+
let id = nativeFnIds.get(fn);
|
|
290
|
+
if (!id) {
|
|
291
|
+
id = ++nextNativeFnId;
|
|
292
|
+
nativeFnIds.set(fn, id);
|
|
293
|
+
}
|
|
294
|
+
return id;
|
|
295
|
+
}
|
|
296
|
+
const nativeInstances = /* @__PURE__ */ new Map();
|
|
297
|
+
function disposeNativeInstances() {
|
|
298
|
+
for (const entry of nativeInstances.values()) {
|
|
299
|
+
entry.instance.dispose();
|
|
300
|
+
}
|
|
301
|
+
nativeInstances.clear();
|
|
302
|
+
}
|
|
303
|
+
const pendingNativeButtons = /* @__PURE__ */ new Set();
|
|
304
|
+
const pendingVersion = signal(0);
|
|
305
|
+
function wrapNativeButtonTap(nodeId, tap) {
|
|
306
|
+
return (...args) => {
|
|
307
|
+
if (pendingNativeButtons.has(nodeId)) return;
|
|
308
|
+
const outcome = tap(...args);
|
|
309
|
+
if (outcome && typeof outcome.then === "function") {
|
|
310
|
+
pendingNativeButtons.add(nodeId);
|
|
311
|
+
pendingVersion.set(pendingVersion.get() + 1);
|
|
312
|
+
return Promise.resolve(outcome).finally(() => {
|
|
313
|
+
if (pendingNativeButtons.delete(nodeId)) {
|
|
314
|
+
pendingVersion.set(pendingVersion.get() + 1);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return outcome;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function toNative(value, id, submit, scopePath = "") {
|
|
143
322
|
if (typeof value === "string" || typeof value === "number") {
|
|
144
323
|
return { id, t: "text", s: {}, x: String(value) };
|
|
145
324
|
}
|
|
146
325
|
if (!isVNode(value)) return null;
|
|
147
326
|
if (typeof value.tag === "function") {
|
|
148
|
-
const
|
|
327
|
+
const fnId = getNativeFnId(value.tag);
|
|
328
|
+
const explicitKey = value.props?.key;
|
|
329
|
+
const instanceKey = explicitKey !== void 0 && explicitKey !== null ? `${scopePath}|fn:${fnId}|k:${typeof explicitKey}:${String(explicitKey)}` : `${id}|fn:${fnId}`;
|
|
330
|
+
let entry = nativeInstances.get(instanceKey);
|
|
331
|
+
if (!entry) {
|
|
332
|
+
entry = { instance: createComponentInstance(), users: 0 };
|
|
333
|
+
nativeInstances.set(instanceKey, entry);
|
|
334
|
+
}
|
|
335
|
+
const current = entry;
|
|
336
|
+
current.users++;
|
|
337
|
+
onCleanup(() => {
|
|
338
|
+
current.users--;
|
|
339
|
+
queueMicrotask(() => {
|
|
340
|
+
if (current.users === 0 && nativeInstances.get(instanceKey) === current) {
|
|
341
|
+
nativeInstances.delete(instanceKey);
|
|
342
|
+
current.instance.dispose();
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
const rendered = runWithComponentInstance(
|
|
347
|
+
current.instance,
|
|
348
|
+
() => value.tag({ ...value.props, children: value.children })
|
|
349
|
+
);
|
|
149
350
|
const list = flatten(Array.isArray(rendered) ? rendered : [rendered]);
|
|
150
|
-
return {
|
|
351
|
+
return {
|
|
352
|
+
id: instanceKey,
|
|
353
|
+
t: "col",
|
|
354
|
+
s: {},
|
|
355
|
+
c: list.map((child, i) => toNative(child, `${instanceKey}.${i}`, submit, instanceKey)).filter(Boolean)
|
|
356
|
+
};
|
|
151
357
|
}
|
|
152
358
|
const props = value.props || {};
|
|
359
|
+
if (props.nativeRole === "toggle") {
|
|
360
|
+
const [input, words2] = value.children;
|
|
361
|
+
const node2 = {
|
|
362
|
+
id: `${id}:toggle`,
|
|
363
|
+
t: "toggle",
|
|
364
|
+
s: {},
|
|
365
|
+
x: String(words2.children[0] ?? ""),
|
|
366
|
+
v: input.props.checked ? "true" : "false",
|
|
367
|
+
inputType: input.props.role === "switch" ? "switch" : "checkbox"
|
|
368
|
+
};
|
|
369
|
+
if (input.props.disabled) node2.s.disabled = true;
|
|
370
|
+
else node2.e = { change: handlers.push(input.props.onInput) - 1 };
|
|
371
|
+
if (props["aria-label"] !== void 0) node2.a = String(props["aria-label"]);
|
|
372
|
+
return node2;
|
|
373
|
+
}
|
|
153
374
|
if (value.tag === "form") submit = props.onSubmit;
|
|
154
|
-
const t = nodeType(value.tag, props);
|
|
155
|
-
const
|
|
156
|
-
|
|
375
|
+
const t = props.nativeRole === "map" ? "map" : props.nativeRole === "list" ? "list" : props.nativeRole === "modal" ? "modal" : nodeType(value.tag, props);
|
|
376
|
+
const elKey = props.key;
|
|
377
|
+
const childScope = elKey !== void 0 && elKey !== null ? `${scopePath}|ek:${typeof elKey}:${String(elKey)}:${t}` : scopePath;
|
|
378
|
+
const node = { id: elKey !== void 0 && elKey !== null ? childScope : `${id}:${t}`, t, s: {} };
|
|
379
|
+
if (props["aria-label"] !== void 0) node.a = String(props["aria-label"]);
|
|
380
|
+
if (t === "list") node.rh = Number(props.rowHeight);
|
|
381
|
+
if (t === "map") {
|
|
382
|
+
node.v = String(props["data-place"]);
|
|
383
|
+
node.src = String(props.src);
|
|
384
|
+
node.a = String(props.title);
|
|
385
|
+
}
|
|
386
|
+
const currentTheme = theme();
|
|
387
|
+
for (const key in t === "modal" ? {} : props) {
|
|
388
|
+
if (["aria-label", "alt", "loading", "decoding", "nativeRole", "rowHeight", "role", "rows", "title", "data-place"].includes(key) && !(key === "loading" && typeof props[key] === "boolean")) continue;
|
|
157
389
|
if (STYLE_KEYS.has(key)) {
|
|
158
|
-
const resolved =
|
|
390
|
+
const resolved = resolveNativeStyleValue(key, props[key], currentTheme);
|
|
159
391
|
if (resolved !== void 0 && resolved !== null) node.s[key] = resolved;
|
|
392
|
+
} else {
|
|
393
|
+
warnStyle(key, "native");
|
|
160
394
|
}
|
|
161
395
|
}
|
|
162
|
-
|
|
396
|
+
if (t === "button" && props.bg && !props.color) {
|
|
397
|
+
const fg = autoButtonColor(props.bg, currentTheme);
|
|
398
|
+
if (fg) node.s.color = fg;
|
|
399
|
+
}
|
|
400
|
+
const autoLoading = t === "button" && props.type !== "submit" && pendingNativeButtons.has(node.id);
|
|
401
|
+
if (autoLoading && node.s.loading === void 0) {
|
|
402
|
+
node.s.loading = true;
|
|
403
|
+
}
|
|
404
|
+
const blocked = Boolean(props.disabled || props.loading || autoLoading);
|
|
405
|
+
const rawTap = !blocked ? props.onClick ?? (value.tag === "button" && props.type === "submit" ? submit : void 0) : void 0;
|
|
406
|
+
if (t === "modal" && props.onClick) {
|
|
407
|
+
const close = value.children[0]?.children.find((c) => c?.props?.nativeRole === "close")?.props.onClick;
|
|
408
|
+
if (close) node.e = { ...node.e, tap: handlers.push(close) - 1 };
|
|
409
|
+
}
|
|
410
|
+
const tap = t === "modal" ? void 0 : rawTap && t === "button" && props.type !== "submit" ? wrapNativeButtonTap(node.id, rawTap) : rawTap;
|
|
163
411
|
if (tap) {
|
|
164
412
|
node.e = { ...node.e, tap: handlers.push(tap) - 1 };
|
|
165
413
|
}
|
|
@@ -168,63 +416,165 @@ function toNative(value, id, submit) {
|
|
|
168
416
|
}
|
|
169
417
|
if (props.placeholder !== void 0) node.ph = String(props.placeholder);
|
|
170
418
|
if (t === "input" && props.type !== void 0) node.inputType = String(props.type);
|
|
419
|
+
if (value.tag === "textarea") node.inputType = "multiline";
|
|
171
420
|
if (props.value !== void 0) node.v = props.value === null ? "" : String(props.value);
|
|
172
421
|
if (props.src !== void 0) node.src = String(props.src);
|
|
173
422
|
if (props.href !== void 0) node.href = String(props.href);
|
|
174
423
|
const children = flatten(value.children || []);
|
|
424
|
+
if (t === "select") {
|
|
425
|
+
node.ph = String(children[0]?.children?.[0] ?? "");
|
|
426
|
+
node.o = children.slice(1).map((option) => String(option.props.value));
|
|
427
|
+
node.v = String(children.find((option) => option.props.selected)?.props.value ?? "");
|
|
428
|
+
return node;
|
|
429
|
+
}
|
|
175
430
|
const isLeaf = t === "text" || t === "heading" || t === "button" || t === "link";
|
|
176
431
|
if (isLeaf) {
|
|
177
432
|
node.x = children.map((child) => typeof child === "string" || typeof child === "number" ? String(child) : "").join("");
|
|
178
433
|
} else if (t !== "input" && t !== "image") {
|
|
179
|
-
node.c = children.map((child, i) => toNative(child, `${node.id}.${i}`, submit)).filter(Boolean);
|
|
434
|
+
node.c = children.map((child, i) => toNative(child, `${node.id}.${i}`, submit, childScope)).filter(Boolean);
|
|
180
435
|
}
|
|
181
436
|
return node;
|
|
182
437
|
}
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
438
|
+
const router = createRouter();
|
|
439
|
+
router.setGuard(auth.__guard);
|
|
440
|
+
auth.__attachRouter(router);
|
|
441
|
+
const go = router.go;
|
|
442
|
+
const back = router.back;
|
|
443
|
+
const canGoBack = router.canGoBack;
|
|
444
|
+
const openUrl = router.openUrl;
|
|
445
|
+
host.__orvynBack = () => router.back();
|
|
446
|
+
host.__orvynDeepLink = (url) => router.openUrl(url);
|
|
447
|
+
function startApp(_target, entry, onStart, screens = {}, initialParams = {}) {
|
|
191
448
|
if (typeof entry !== "function") {
|
|
192
449
|
throw new Error("[Orvyn] No screen to show. Add: screen Home { ... }");
|
|
193
450
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
451
|
+
disposeNativeInstances();
|
|
452
|
+
const endWork = startAppWork();
|
|
453
|
+
screens = { ...allScreens, ...screens };
|
|
454
|
+
router.start(entry, screens, initialParams, {
|
|
455
|
+
getInitialUrl: () => host.__orvynInitialUrl ?? null
|
|
456
|
+
});
|
|
457
|
+
const stop = effect(() => {
|
|
458
|
+
pendingVersion.get();
|
|
459
|
+
const current = router.current();
|
|
460
|
+
if (!current) return;
|
|
461
|
+
const currentTheme = theme();
|
|
197
462
|
handlers = [];
|
|
198
|
-
|
|
463
|
+
let tree = toNative(
|
|
464
|
+
createVNode(current.screen, { ...current.params, key: current.key }, []),
|
|
465
|
+
current.screen.name || "screen"
|
|
466
|
+
);
|
|
467
|
+
const overlayNodes = errorCenter.renderDevOverlay();
|
|
468
|
+
if (overlayNodes.length) {
|
|
469
|
+
const open = errorCenter.overlay.isOpen;
|
|
470
|
+
const box = toNative(createVNode("div", {
|
|
471
|
+
flex: true,
|
|
472
|
+
direction: "column",
|
|
473
|
+
gap: 8,
|
|
474
|
+
...open ? { padding: 16, bg: "#0f172a", grow: 1 } : { padding: 8 }
|
|
475
|
+
}, overlayNodes), "__orvyn_dev_overlay");
|
|
476
|
+
if (box) {
|
|
477
|
+
tree = open || !tree ? box : { ...box, c: [...box.c ?? [], tree] };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (tree) {
|
|
481
|
+
tree.canGoBack = router.canGoBack();
|
|
482
|
+
tree.theme = {
|
|
483
|
+
dark: currentTheme.dark,
|
|
484
|
+
bg: currentTheme.colors.bg,
|
|
485
|
+
surface: currentTheme.colors.surface,
|
|
486
|
+
card: currentTheme.colors.card,
|
|
487
|
+
text: currentTheme.colors.text,
|
|
488
|
+
muted: currentTheme.colors.muted,
|
|
489
|
+
primary: currentTheme.colors.primary,
|
|
490
|
+
border: currentTheme.colors.border,
|
|
491
|
+
danger: currentTheme.colors.danger
|
|
492
|
+
};
|
|
493
|
+
}
|
|
199
494
|
host.__orvynRender(JSON.stringify(tree));
|
|
200
495
|
});
|
|
201
496
|
if (onStart) {
|
|
202
|
-
Promise.resolve().then(onStart).catch((error) => console.error(String(error?.stack || error)));
|
|
497
|
+
Promise.resolve().then(() => runAppWork(onStart)).catch((error) => console.error(String(error?.stack || error)));
|
|
203
498
|
}
|
|
499
|
+
return () => {
|
|
500
|
+
endWork();
|
|
501
|
+
stop();
|
|
502
|
+
router.reset();
|
|
503
|
+
disposeNativeInstances();
|
|
504
|
+
for (const pending of pendingFetches.values()) pending.cleanup();
|
|
505
|
+
pendingFetches.clear();
|
|
506
|
+
pendingNativeButtons.clear();
|
|
507
|
+
handlers = [];
|
|
508
|
+
};
|
|
204
509
|
}
|
|
205
510
|
export {
|
|
511
|
+
List,
|
|
206
512
|
add,
|
|
513
|
+
at,
|
|
514
|
+
auth,
|
|
515
|
+
back,
|
|
516
|
+
bindCheck,
|
|
207
517
|
bindInput,
|
|
518
|
+
canGoBack,
|
|
208
519
|
clear,
|
|
520
|
+
componentState,
|
|
209
521
|
createForm,
|
|
522
|
+
createMap,
|
|
523
|
+
createModal,
|
|
524
|
+
createSavedSignal,
|
|
525
|
+
createSelect,
|
|
526
|
+
createTabs,
|
|
210
527
|
createVNode2 as createVNode,
|
|
528
|
+
env,
|
|
529
|
+
errorText,
|
|
211
530
|
fetchData,
|
|
212
531
|
formCache,
|
|
532
|
+
get,
|
|
533
|
+
getLocation,
|
|
213
534
|
go,
|
|
535
|
+
guard,
|
|
214
536
|
importedState,
|
|
537
|
+
isEmptyValue,
|
|
538
|
+
keyed,
|
|
215
539
|
len,
|
|
540
|
+
load,
|
|
541
|
+
log,
|
|
542
|
+
onError,
|
|
543
|
+
openUrl,
|
|
544
|
+
patch,
|
|
545
|
+
pickFile,
|
|
546
|
+
pickPhoto,
|
|
547
|
+
post,
|
|
548
|
+
put,
|
|
216
549
|
random,
|
|
217
550
|
readImported,
|
|
551
|
+
registerScreens,
|
|
552
|
+
registerSource,
|
|
218
553
|
remove,
|
|
219
554
|
removeAt,
|
|
555
|
+
renderError,
|
|
556
|
+
reportError,
|
|
557
|
+
resetState,
|
|
558
|
+
resume,
|
|
220
559
|
savedSignal,
|
|
560
|
+
secure,
|
|
221
561
|
setAt,
|
|
562
|
+
setEnv,
|
|
563
|
+
setErrorPage,
|
|
222
564
|
setField,
|
|
565
|
+
setPage,
|
|
566
|
+
setStyleWarningHandler,
|
|
223
567
|
signal2 as signal,
|
|
224
568
|
sleep,
|
|
225
569
|
startApp,
|
|
570
|
+
storage,
|
|
226
571
|
str,
|
|
227
572
|
submitHandler,
|
|
573
|
+
takePhoto,
|
|
574
|
+
task,
|
|
575
|
+
theme2 as theme,
|
|
576
|
+
track,
|
|
228
577
|
update,
|
|
229
|
-
validate
|
|
578
|
+
validate,
|
|
579
|
+
words
|
|
230
580
|
};
|
package/src/lang/page.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function structuredData(page, url) {
|
|
2
|
+
const article = page.type === "article";
|
|
3
|
+
const text = (value) => value ? String(value) : void 0;
|
|
4
|
+
return {
|
|
5
|
+
"@context": "https://schema.org",
|
|
6
|
+
"@type": article ? "Article" : "WebPage",
|
|
7
|
+
[article ? "headline" : "name"]: text(page.title),
|
|
8
|
+
description: text(page.description),
|
|
9
|
+
image: text(page.image),
|
|
10
|
+
author: page.author ? { "@type": "Person", name: String(page.author) } : void 0,
|
|
11
|
+
datePublished: text(page.date),
|
|
12
|
+
url: url || void 0
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function applyPage(page) {
|
|
16
|
+
const doc = globalThis.document;
|
|
17
|
+
if (!doc?.head?.querySelector) return;
|
|
18
|
+
const head = (selector, tag, attributes, content, key = "content") => {
|
|
19
|
+
let el = doc.head.querySelector(selector);
|
|
20
|
+
if (!content) return el?.remove();
|
|
21
|
+
if (!el) {
|
|
22
|
+
el = doc.createElement(tag);
|
|
23
|
+
for (const [name, value] of Object.entries(attributes)) el.setAttribute(name, value);
|
|
24
|
+
doc.head.appendChild(el);
|
|
25
|
+
}
|
|
26
|
+
el.setAttribute(key, String(content));
|
|
27
|
+
};
|
|
28
|
+
const meta = (kind, name, content) => head(`meta[${kind}="${name}"]`, "meta", { [kind]: name }, content);
|
|
29
|
+
if (page.title) doc.title = String(page.title);
|
|
30
|
+
const location = globalThis.location;
|
|
31
|
+
const url = location?.origin ? `${location.origin}${location.pathname}` : "";
|
|
32
|
+
meta("name", "description", page.description);
|
|
33
|
+
meta("property", "og:title", page.title);
|
|
34
|
+
meta("property", "og:description", page.description);
|
|
35
|
+
meta("property", "og:image", page.image);
|
|
36
|
+
meta("property", "og:url", url);
|
|
37
|
+
meta("name", "twitter:card", page.image ? "summary_large_image" : "summary");
|
|
38
|
+
meta("name", "robots", page.noindex ? "noindex" : "");
|
|
39
|
+
head('link[rel="canonical"]', "link", { rel: "canonical" }, url, "href");
|
|
40
|
+
let data = doc.head.querySelector("script[data-orvyn-page]");
|
|
41
|
+
if (!data) {
|
|
42
|
+
data = doc.createElement("script");
|
|
43
|
+
data.setAttribute("type", "application/ld+json");
|
|
44
|
+
data.setAttribute("data-orvyn-page", "");
|
|
45
|
+
doc.head.appendChild(data);
|
|
46
|
+
}
|
|
47
|
+
data.textContent = JSON.stringify(structuredData(page, url));
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
applyPage,
|
|
51
|
+
structuredData
|
|
52
|
+
};
|