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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function createDevice(ask) {
|
|
2
|
+
return {
|
|
3
|
+
pickPhoto: () => ask("photo"),
|
|
4
|
+
takePhoto: () => ask("camera"),
|
|
5
|
+
pickFile: () => ask("file"),
|
|
6
|
+
getLocation: () => ask("location")
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function askBrowser(kind) {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
if (kind === "location") {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
if (!g.navigator?.geolocation) return reject(new Error("[Orvyn] This browser has no location"));
|
|
14
|
+
g.navigator.geolocation.getCurrentPosition(
|
|
15
|
+
(p) => resolve({ latitude: p.coords.latitude, longitude: p.coords.longitude, accuracy: p.coords.accuracy }),
|
|
16
|
+
(e) => reject(new Error(e.code === 1 ? "[Orvyn] Location was not allowed" : "[Orvyn] Could not get the location")),
|
|
17
|
+
{ timeout: 15e3 }
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const input = g.document.createElement("input");
|
|
23
|
+
input.type = "file";
|
|
24
|
+
if (kind !== "file") input.accept = "image/*";
|
|
25
|
+
if (kind === "camera") input.capture = "environment";
|
|
26
|
+
input.addEventListener("cancel", () => resolve(null));
|
|
27
|
+
input.addEventListener("change", () => {
|
|
28
|
+
const file = input.files?.[0];
|
|
29
|
+
if (!file) return resolve(null);
|
|
30
|
+
const reader = new g.FileReader();
|
|
31
|
+
reader.onload = () => resolve({ name: file.name, type: file.type, size: file.size, dataUrl: reader.result });
|
|
32
|
+
reader.onerror = () => reject(new Error("[Orvyn] Could not read the file"));
|
|
33
|
+
reader.readAsDataURL(file);
|
|
34
|
+
});
|
|
35
|
+
input.click();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
askBrowser,
|
|
40
|
+
createDevice
|
|
41
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { configFile, loadNativeConfig, releaseProblems } from "./native/config.js";
|
|
5
|
+
const systemProbe = {
|
|
6
|
+
platform: process.platform,
|
|
7
|
+
env: process.env,
|
|
8
|
+
run(command, args) {
|
|
9
|
+
const result = spawnSync(command, args, { encoding: "utf-8" });
|
|
10
|
+
return result.error || result.status !== 0 ? null : `${result.stdout}${result.stderr}`;
|
|
11
|
+
},
|
|
12
|
+
exists: existsSync
|
|
13
|
+
};
|
|
14
|
+
async function doctor(cwd, probe = systemProbe) {
|
|
15
|
+
const checks = [];
|
|
16
|
+
const add = (group, ok, label, fix) => checks.push({ group, ok, label, ...ok ? {} : { fix } });
|
|
17
|
+
add("Web", Number(process.versions.node.split(".")[0]) >= 24, `Node ${process.versions.node}`, "Install Node 24 or newer");
|
|
18
|
+
if (probe.platform === "darwin") {
|
|
19
|
+
add("iPhone", probe.run("xcodebuild", ["-version"]) !== null, "Xcode", "Install Xcode from the App Store and open it once");
|
|
20
|
+
add("iPhone", /iPhone/.test(probe.run("xcrun", ["simctl", "list", "devices", "available"]) ?? ""), "iPhone simulator", "Xcode \u2192 Settings \u2192 Components: add an iOS simulator");
|
|
21
|
+
add("iPhone", /"Apple (Development|Distribution)/.test(probe.run("security", ["find-identity", "-v", "-p", "codesigning"]) ?? ""), "Signing certificate", "Xcode \u2192 Settings \u2192 Accounts: sign in, then Manage Certificates");
|
|
22
|
+
} else {
|
|
23
|
+
add("iPhone", false, "macOS", "iPhone apps can only be built on a Mac");
|
|
24
|
+
}
|
|
25
|
+
const sdk = probe.env.ANDROID_HOME || probe.env.ANDROID_SDK_ROOT || join(probe.env.HOME || "", "Library/Android/sdk");
|
|
26
|
+
add("Android", /version "(1[7-9]|2\d)/.test(probe.run("java", ["-version"]) ?? ""), "Java 17 or newer", "Install a JDK, for example: brew install --cask temurin@17");
|
|
27
|
+
add("Android", probe.exists(sdk), "Android SDK", "Install Android Studio, or set ANDROID_HOME");
|
|
28
|
+
add("Android", probe.run("gradle", ["--version"]) !== null, "Gradle", "brew install gradle");
|
|
29
|
+
add("Android", probe.run("adb", ["version"]) !== null, "adb", `Add ${join(sdk, "platform-tools")} to your PATH`);
|
|
30
|
+
if (configFile(cwd)) {
|
|
31
|
+
for (const target of ["ios", "android"]) {
|
|
32
|
+
const group = target === "ios" ? "iPhone release" : "Android release";
|
|
33
|
+
try {
|
|
34
|
+
const problems = releaseProblems(target, await loadNativeConfig(cwd, "app.orv"), probe.env);
|
|
35
|
+
if (!problems.length) add(group, true, "Release settings", "");
|
|
36
|
+
for (const problem of problems) add(group, false, problem, "");
|
|
37
|
+
} catch (error) {
|
|
38
|
+
add(group, false, error.message, "");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return checks;
|
|
43
|
+
}
|
|
44
|
+
function formatChecks(checks) {
|
|
45
|
+
const lines = [];
|
|
46
|
+
let group = "";
|
|
47
|
+
for (const check of checks) {
|
|
48
|
+
if (check.group !== group) lines.push("", group = check.group);
|
|
49
|
+
lines.push(` ${check.ok ? "\u2713" : "\u2717"} ${check.label}`);
|
|
50
|
+
if (check.fix) lines.push(` ${check.fix}`);
|
|
51
|
+
}
|
|
52
|
+
const missing = checks.filter((check) => !check.ok).length;
|
|
53
|
+
lines.push("", missing ? `${missing} thing(s) to fix.` : "Everything is ready.");
|
|
54
|
+
return lines.join("\n").trim();
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
doctor,
|
|
58
|
+
formatChecks,
|
|
59
|
+
systemProbe
|
|
60
|
+
};
|
package/src/lang/env.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
async function loadEnv(dir, fallback, requested = process.env.ORVYN_ENV) {
|
|
5
|
+
const name = requested || fallback;
|
|
6
|
+
const path = ["orvyn.config.js", "orvyn.config.mjs", "orvyn.config.ts"].map((file) => join(dir, file)).find((file) => existsSync(file));
|
|
7
|
+
let all;
|
|
8
|
+
if (path) {
|
|
9
|
+
try {
|
|
10
|
+
all = (await import(pathToFileURL(path).href)).default?.env;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
throw new Error(`[Orvyn] Could not read ${basename(path)}: ${error.message}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const known = all ? Object.keys(all) : [];
|
|
16
|
+
if (all?.[name]) return { ...all[name], name };
|
|
17
|
+
if (requested) {
|
|
18
|
+
throw new Error(known.length ? `[Orvyn] There is no environment "${name}". Your config has: ${known.join(", ")}` : `[Orvyn] --env ${name} needs an env section in orvyn.config.js, like env: { ${name}: { API_URL: "..." } }`);
|
|
19
|
+
}
|
|
20
|
+
if (known.length) {
|
|
21
|
+
throw new Error(`[Orvyn] orvyn.config.js has no "${name}" environment. Add env.${name}, or pick one with --env (${known.join(", ")})`);
|
|
22
|
+
}
|
|
23
|
+
return { name };
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
loadEnv
|
|
27
|
+
};
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { signal } from "../core/signal.js";
|
|
2
|
+
import { createVNode } from "../runtime/vnode.js";
|
|
3
|
+
const LOC = /* @__PURE__ */ Symbol.for("orvyn.loc");
|
|
4
|
+
function createErrorCenter(options) {
|
|
5
|
+
let file = "";
|
|
6
|
+
let line = 0;
|
|
7
|
+
let col = 0;
|
|
8
|
+
const sources = /* @__PURE__ */ new Map();
|
|
9
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
10
|
+
const retryTick = signal(0, "__orvyn_error_retry");
|
|
11
|
+
const overlayState = signal(null);
|
|
12
|
+
const MAX_ISSUES = 20;
|
|
13
|
+
let overlayValue = null;
|
|
14
|
+
const setOverlay = (next) => {
|
|
15
|
+
overlayValue = next;
|
|
16
|
+
overlayState.set(next);
|
|
17
|
+
};
|
|
18
|
+
let sendUrl = "";
|
|
19
|
+
let errorPage = null;
|
|
20
|
+
let inHandler = false;
|
|
21
|
+
const recent = [];
|
|
22
|
+
function registerSource(fileId, content) {
|
|
23
|
+
if (!fileId || typeof content !== "string") return;
|
|
24
|
+
const normalized = fileId.replace(/\.orv$/, "");
|
|
25
|
+
sources.set(normalized, content.split(/\r?\n/));
|
|
26
|
+
}
|
|
27
|
+
function getSnippet(fileName, lineNo, radius = 2) {
|
|
28
|
+
if (!fileName || !lineNo) return [];
|
|
29
|
+
const normalized = fileName.replace(/\.orv$/, "");
|
|
30
|
+
const lines = sources.get(normalized) ?? sources.get(fileName);
|
|
31
|
+
if (!lines || lineNo < 1 || lineNo > lines.length) return [];
|
|
32
|
+
const start = Math.max(1, lineNo - radius);
|
|
33
|
+
const end = Math.min(lines.length, lineNo + radius);
|
|
34
|
+
const result = [];
|
|
35
|
+
for (let i = start; i <= end; i++) {
|
|
36
|
+
result.push({ lineNo: i, text: lines[i - 1] ?? "", active: i === lineNo });
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function at(f, l, c = 0) {
|
|
41
|
+
file = f;
|
|
42
|
+
line = l;
|
|
43
|
+
col = c;
|
|
44
|
+
}
|
|
45
|
+
function locate(error) {
|
|
46
|
+
if (error && typeof error === "object") {
|
|
47
|
+
if (!error[LOC]) {
|
|
48
|
+
try {
|
|
49
|
+
Object.defineProperty(error, LOC, { value: { file, line, col }, enumerable: false });
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return error[LOC] ?? { file, line, col };
|
|
54
|
+
}
|
|
55
|
+
return { file, line, col };
|
|
56
|
+
}
|
|
57
|
+
function rawMessage(error) {
|
|
58
|
+
const raw = error instanceof Error ? error.message : typeof error === "string" ? error : "";
|
|
59
|
+
return String(raw || "").replace(/^\[Orvyn\]\s*/, "");
|
|
60
|
+
}
|
|
61
|
+
function cleanMessage(error) {
|
|
62
|
+
const raw = error instanceof Error ? error.message : typeof error === "string" ? error : (() => {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.stringify(error);
|
|
65
|
+
} catch {
|
|
66
|
+
return String(error);
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
return friendly(String(raw ?? "Unknown error").replace(/^\[Orvyn\]\s*/, ""));
|
|
70
|
+
}
|
|
71
|
+
function report(error, where = "", kind = "event") {
|
|
72
|
+
const loc = locate(error);
|
|
73
|
+
const message = cleanMessage(error);
|
|
74
|
+
const original = rawMessage(error);
|
|
75
|
+
const err = {
|
|
76
|
+
message,
|
|
77
|
+
...original && original !== message ? { detail: original } : {},
|
|
78
|
+
file: loc.file ? `${loc.file}.orv`.replace(/\.orv\.orv$/, ".orv") : "",
|
|
79
|
+
line: loc.line || 0,
|
|
80
|
+
...loc.col ? { col: loc.col } : {},
|
|
81
|
+
where,
|
|
82
|
+
kind,
|
|
83
|
+
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
84
|
+
};
|
|
85
|
+
const place = err.file ? `${err.file}:${err.line}` : "unknown place";
|
|
86
|
+
console.error(`[Orvyn] ${err.message}
|
|
87
|
+
at ${place}${where ? ` (in ${where})` : ""}`);
|
|
88
|
+
recent.push(err);
|
|
89
|
+
if (recent.length > 20) recent.shift();
|
|
90
|
+
let handledByUser = false;
|
|
91
|
+
if (!inHandler) {
|
|
92
|
+
inHandler = true;
|
|
93
|
+
try {
|
|
94
|
+
for (const h of handlers) {
|
|
95
|
+
handledByUser = true;
|
|
96
|
+
try {
|
|
97
|
+
h(err);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
console.error("[Orvyn] onError itself failed:", e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
inHandler = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (options.isDev()) addIssue(err, handledByUser);
|
|
107
|
+
if (sendUrl && options.send) {
|
|
108
|
+
try {
|
|
109
|
+
Promise.resolve(options.send(sendUrl, { level: "error", ...err })).catch(() => {
|
|
110
|
+
});
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return err;
|
|
115
|
+
}
|
|
116
|
+
function addIssue(err, handledByUser) {
|
|
117
|
+
const prev = overlayValue;
|
|
118
|
+
const issues = prev ? [...prev.issues] : [];
|
|
119
|
+
const same = issues.findIndex((i) => i.message === err.message && i.file === err.file && i.line === err.line && i.where === err.where);
|
|
120
|
+
if (same >= 0) {
|
|
121
|
+
issues[same] = { ...issues[same], repeats: issues[same].repeats + 1 };
|
|
122
|
+
setOverlay({ issues, index: prev.index, minimized: prev.minimized });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
issues.push({ ...err, repeats: 1 });
|
|
126
|
+
while (issues.length > MAX_ISSUES) issues.shift();
|
|
127
|
+
setOverlay({
|
|
128
|
+
issues,
|
|
129
|
+
// jump to the newest error, like Next.js
|
|
130
|
+
index: issues.length - 1,
|
|
131
|
+
// errors your onError already handled start minimized
|
|
132
|
+
// a broken screen always opens the box; event errors your onError already
|
|
133
|
+
// handled start minimized
|
|
134
|
+
minimized: err.kind === "render" ? false : handledByUser ? prev ? prev.minimized : true : false
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const overlay = {
|
|
138
|
+
next() {
|
|
139
|
+
const cur = overlayState.get();
|
|
140
|
+
if (cur && cur.issues.length) setOverlay({ ...cur, index: (cur.index + 1) % cur.issues.length });
|
|
141
|
+
},
|
|
142
|
+
prev() {
|
|
143
|
+
const cur = overlayState.get();
|
|
144
|
+
if (cur && cur.issues.length) setOverlay({ ...cur, index: (cur.index - 1 + cur.issues.length) % cur.issues.length });
|
|
145
|
+
},
|
|
146
|
+
minimize() {
|
|
147
|
+
const cur = overlayState.get();
|
|
148
|
+
if (cur) setOverlay({ ...cur, minimized: true });
|
|
149
|
+
},
|
|
150
|
+
open() {
|
|
151
|
+
const cur = overlayState.get();
|
|
152
|
+
if (cur) setOverlay({ ...cur, minimized: false });
|
|
153
|
+
},
|
|
154
|
+
close() {
|
|
155
|
+
setOverlay(null);
|
|
156
|
+
},
|
|
157
|
+
retry() {
|
|
158
|
+
setOverlay(null);
|
|
159
|
+
retryTick.set(retryTick.get() + 1);
|
|
160
|
+
},
|
|
161
|
+
get state() {
|
|
162
|
+
return overlayState.get();
|
|
163
|
+
},
|
|
164
|
+
snippet: (f, l, radius = 3) => getSnippet(f, l, radius),
|
|
165
|
+
tip: (message) => explain(message),
|
|
166
|
+
get isOpen() {
|
|
167
|
+
const cur = overlayState.get();
|
|
168
|
+
return Boolean(cur && !cur.minimized);
|
|
169
|
+
},
|
|
170
|
+
get issues() {
|
|
171
|
+
return overlayState.get()?.issues ?? [];
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
function guard(fn, where, f, l, kind = "event") {
|
|
175
|
+
if (typeof fn !== "function") return fn;
|
|
176
|
+
const wrapped = function(...args) {
|
|
177
|
+
if (f) at(f, l ?? 0);
|
|
178
|
+
try {
|
|
179
|
+
const out = fn.apply(this, args);
|
|
180
|
+
if (out && typeof out.then === "function") {
|
|
181
|
+
return out.then(void 0, (error) => {
|
|
182
|
+
if (isCancel(error)) return void 0;
|
|
183
|
+
report(error, where, "async");
|
|
184
|
+
return void 0;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
report(error, where, kind);
|
|
190
|
+
return void 0;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
return wrapped;
|
|
194
|
+
}
|
|
195
|
+
function codeFrame(err, where) {
|
|
196
|
+
const h = createVNode;
|
|
197
|
+
const snippet = getSnippet(err.file, err.line);
|
|
198
|
+
const loc = `${err.file || "app.orv"}:${err.line || 1}${where ? ` \xB7 in ${where}` : ""}`;
|
|
199
|
+
const rows = [
|
|
200
|
+
h("span", { color: "#94a3b8", font: "mono", size: 12 }, [loc])
|
|
201
|
+
];
|
|
202
|
+
const width = snippet.length ? String(snippet[snippet.length - 1].lineNo).length : 2;
|
|
203
|
+
for (const entry of snippet) {
|
|
204
|
+
const num = String(entry.lineNo).padStart(width, " ");
|
|
205
|
+
const marker = entry.active ? ">" : " ";
|
|
206
|
+
rows.push(h("div", {
|
|
207
|
+
flex: true,
|
|
208
|
+
direction: "row",
|
|
209
|
+
gap: 8,
|
|
210
|
+
paddingX: 8,
|
|
211
|
+
paddingY: 3,
|
|
212
|
+
radius: 6,
|
|
213
|
+
bg: entry.active ? "#451a03" : "transparent"
|
|
214
|
+
}, [
|
|
215
|
+
h("span", { color: entry.active ? "#fbbf24" : "#64748b", font: "mono", size: 13 }, [`${marker} ${num} |`]),
|
|
216
|
+
h("span", { color: entry.active ? "#fef3c7" : "#cbd5e1", font: "mono", size: 13 }, [entry.text || " "])
|
|
217
|
+
]));
|
|
218
|
+
}
|
|
219
|
+
return h("div", {
|
|
220
|
+
flex: true,
|
|
221
|
+
direction: "column",
|
|
222
|
+
gap: 4,
|
|
223
|
+
padding: 12,
|
|
224
|
+
radius: 10,
|
|
225
|
+
bg: "#0f172a",
|
|
226
|
+
border: "1px solid #1e293b"
|
|
227
|
+
}, rows);
|
|
228
|
+
}
|
|
229
|
+
function tipBox(message) {
|
|
230
|
+
const tip = explain(message);
|
|
231
|
+
if (!tip) return null;
|
|
232
|
+
const h = createVNode;
|
|
233
|
+
return h("div", {
|
|
234
|
+
padding: 10,
|
|
235
|
+
radius: 8,
|
|
236
|
+
bg: "#f8fafc",
|
|
237
|
+
border: "1px solid #cbd5e1"
|
|
238
|
+
}, [
|
|
239
|
+
h("span", { color: "#334155", size: 13 }, [`Tip: ${tip}`])
|
|
240
|
+
]);
|
|
241
|
+
}
|
|
242
|
+
function setErrorPage(page) {
|
|
243
|
+
errorPage = typeof page === "function" ? page : null;
|
|
244
|
+
}
|
|
245
|
+
function renderError(error, where, isScreen = false) {
|
|
246
|
+
retryTick.get();
|
|
247
|
+
const err = report(error, where, "render");
|
|
248
|
+
const dev = options.isDev();
|
|
249
|
+
const h = createVNode;
|
|
250
|
+
const text = (value, extra = {}) => h("span", { ...extra }, [value]);
|
|
251
|
+
if (isScreen && errorPage) {
|
|
252
|
+
return [h(errorPage, {
|
|
253
|
+
// like the built-in card, released apps don't get the technical message
|
|
254
|
+
message: dev ? err.message : "",
|
|
255
|
+
retry: () => retryTick.set(retryTick.get() + 1)
|
|
256
|
+
}, [])];
|
|
257
|
+
}
|
|
258
|
+
if (!dev) {
|
|
259
|
+
return [h("div", {
|
|
260
|
+
flex: true,
|
|
261
|
+
direction: "column",
|
|
262
|
+
gap: 12,
|
|
263
|
+
padding: 24,
|
|
264
|
+
margin: 16,
|
|
265
|
+
maxWidth: 520,
|
|
266
|
+
width: "100%",
|
|
267
|
+
bg: "#ffffff",
|
|
268
|
+
border: "1px solid #e2e8f0",
|
|
269
|
+
radius: 16,
|
|
270
|
+
role: "alert",
|
|
271
|
+
"data-orvyn-error-view": "true"
|
|
272
|
+
}, [
|
|
273
|
+
h("h2", { color: "#0f172a", size: 22 }, ["Something went wrong"]),
|
|
274
|
+
text("Please try again. If it keeps happening, restart the app.", { color: "#475569", size: 15 }),
|
|
275
|
+
h("button", {
|
|
276
|
+
type: "button",
|
|
277
|
+
bg: "#2563eb",
|
|
278
|
+
color: "#ffffff",
|
|
279
|
+
paddingX: 16,
|
|
280
|
+
paddingY: 10,
|
|
281
|
+
radius: 10,
|
|
282
|
+
onClick: () => retryTick.set(retryTick.get() + 1)
|
|
283
|
+
}, ["Try again"])
|
|
284
|
+
])];
|
|
285
|
+
}
|
|
286
|
+
return [h("div", {
|
|
287
|
+
flex: true,
|
|
288
|
+
direction: "column",
|
|
289
|
+
gap: 6,
|
|
290
|
+
padding: 16,
|
|
291
|
+
margin: 12,
|
|
292
|
+
border: "1px dashed #f87171",
|
|
293
|
+
radius: 10,
|
|
294
|
+
role: "alert",
|
|
295
|
+
"data-orvyn-error-view": "true"
|
|
296
|
+
}, [
|
|
297
|
+
text(`Something broke in ${where}`, { color: "#dc2626", weight: "bold", size: 14 }),
|
|
298
|
+
text(err.message, { color: "#64748b", size: 13 }),
|
|
299
|
+
err.file ? text(`${err.file}:${err.line}`, { color: "#94a3b8", font: "mono", size: 12 }) : null
|
|
300
|
+
].filter(Boolean))];
|
|
301
|
+
}
|
|
302
|
+
function renderDevOverlay() {
|
|
303
|
+
if (!options.isDev()) return [];
|
|
304
|
+
const current = overlayState.get();
|
|
305
|
+
if (!current || !current.issues.length) return [];
|
|
306
|
+
const h = createVNode;
|
|
307
|
+
const { issues, index, minimized } = current;
|
|
308
|
+
const err = issues[Math.min(index, issues.length - 1)];
|
|
309
|
+
const total = issues.length;
|
|
310
|
+
if (minimized) {
|
|
311
|
+
return [h("button", {
|
|
312
|
+
type: "button",
|
|
313
|
+
"data-orvyn-pill": "true",
|
|
314
|
+
bg: "#0f172a",
|
|
315
|
+
color: "#fbbf24",
|
|
316
|
+
border: "1px solid #334155",
|
|
317
|
+
paddingX: 14,
|
|
318
|
+
paddingY: 8,
|
|
319
|
+
radius: 999,
|
|
320
|
+
size: 13,
|
|
321
|
+
onClick: overlay.open
|
|
322
|
+
}, [`Orvyn \xB7 ${total} ${total === 1 ? "error" : "errors"}`])];
|
|
323
|
+
}
|
|
324
|
+
const smallButton = (label, onClick, extra = {}) => h("button", {
|
|
325
|
+
type: "button",
|
|
326
|
+
bg: "#f1f5f9",
|
|
327
|
+
color: "#475569",
|
|
328
|
+
paddingX: 10,
|
|
329
|
+
paddingY: 4,
|
|
330
|
+
radius: 8,
|
|
331
|
+
size: 13,
|
|
332
|
+
onClick,
|
|
333
|
+
...extra
|
|
334
|
+
}, [label]);
|
|
335
|
+
const kindLabel = {
|
|
336
|
+
render: "while drawing the screen",
|
|
337
|
+
event: "in a button or event",
|
|
338
|
+
async: "while waiting for something",
|
|
339
|
+
start: "in start { }",
|
|
340
|
+
uncaught: "outside Orvyn code"
|
|
341
|
+
};
|
|
342
|
+
const header = h("div", { flex: true, direction: "row", align: "center", justify: "between", gap: 8 }, [
|
|
343
|
+
h("div", { flex: true, direction: "row", align: "center", gap: 6 }, [
|
|
344
|
+
total > 1 ? smallButton("\u2039", overlay.prev, { "aria-label": "Previous error" }) : null,
|
|
345
|
+
h("span", {
|
|
346
|
+
bg: "#fee2e2",
|
|
347
|
+
color: "#991b1b",
|
|
348
|
+
paddingX: 10,
|
|
349
|
+
paddingY: 4,
|
|
350
|
+
radius: 999,
|
|
351
|
+
size: 12,
|
|
352
|
+
weight: "bold"
|
|
353
|
+
}, [total > 1 ? `Error ${index + 1} of ${total}` : "Error"]),
|
|
354
|
+
total > 1 ? smallButton("\u203A", overlay.next, { "aria-label": "Next error" }) : null
|
|
355
|
+
].filter(Boolean)),
|
|
356
|
+
h("div", { flex: true, direction: "row", gap: 6 }, [
|
|
357
|
+
smallButton("Minimize", overlay.minimize),
|
|
358
|
+
smallButton("\u2715", overlay.close, { "aria-label": "Close" })
|
|
359
|
+
])
|
|
360
|
+
]);
|
|
361
|
+
const body = [
|
|
362
|
+
header,
|
|
363
|
+
h("h2", { color: "#b91c1c", size: 20 }, [err.message]),
|
|
364
|
+
h("span", { color: "#64748b", size: 13 }, [
|
|
365
|
+
`Happened ${kindLabel[err.kind] ?? err.kind}${err.repeats > 1 ? ` \xB7 ${err.repeats} times` : ""}`
|
|
366
|
+
])
|
|
367
|
+
];
|
|
368
|
+
if (err.file || err.line) body.push(codeFrame(err, err.where));
|
|
369
|
+
const tip = tipBox(err.message);
|
|
370
|
+
if (tip) body.push(tip);
|
|
371
|
+
body.push(h("div", { flex: true, direction: "row", justify: "between", align: "center", gap: 8 }, [
|
|
372
|
+
h("span", { color: "#94a3b8", size: 12 }, ["Fix the code and save. This box only shows while developing."]),
|
|
373
|
+
h("button", {
|
|
374
|
+
type: "button",
|
|
375
|
+
bg: "#2563eb",
|
|
376
|
+
color: "#ffffff",
|
|
377
|
+
paddingX: 14,
|
|
378
|
+
paddingY: 9,
|
|
379
|
+
radius: 10,
|
|
380
|
+
onClick: () => {
|
|
381
|
+
setOverlay(null);
|
|
382
|
+
retryTick.set(retryTick.get() + 1);
|
|
383
|
+
}
|
|
384
|
+
}, ["Try again"])
|
|
385
|
+
]));
|
|
386
|
+
return [h("div", { "data-orvyn-overlay": "true", role: "dialog", "aria-modal": "true" }, [
|
|
387
|
+
h("div", {
|
|
388
|
+
flex: true,
|
|
389
|
+
direction: "column",
|
|
390
|
+
gap: 12,
|
|
391
|
+
padding: 24,
|
|
392
|
+
maxWidth: 640,
|
|
393
|
+
width: "100%",
|
|
394
|
+
bg: "#ffffff",
|
|
395
|
+
border: "1px solid #e2e8f0",
|
|
396
|
+
radius: 16,
|
|
397
|
+
role: "alert",
|
|
398
|
+
"data-orvyn-overlay-card": "true"
|
|
399
|
+
}, body)
|
|
400
|
+
])];
|
|
401
|
+
}
|
|
402
|
+
function onError(fn) {
|
|
403
|
+
if (typeof fn === "function") handlers.add(fn);
|
|
404
|
+
return () => handlers.delete(fn);
|
|
405
|
+
}
|
|
406
|
+
const write = (level) => (...parts) => {
|
|
407
|
+
const message = parts.map((p) => typeof p === "string" ? p : (() => {
|
|
408
|
+
try {
|
|
409
|
+
return JSON.stringify(p);
|
|
410
|
+
} catch {
|
|
411
|
+
return String(p);
|
|
412
|
+
}
|
|
413
|
+
})()).join(" ");
|
|
414
|
+
const place = file ? `${file}.orv:${line}`.replace(/\.orv\.orv/, ".orv") : "";
|
|
415
|
+
const fn = level === "info" ? console.log : level === "warn" ? console.warn : console.error;
|
|
416
|
+
fn(`[${level}] ${message}${place ? ` (${place})` : ""}`);
|
|
417
|
+
if (sendUrl && options.send) {
|
|
418
|
+
try {
|
|
419
|
+
Promise.resolve(options.send(sendUrl, { level, message, file: place, time: (/* @__PURE__ */ new Date()).toISOString() })).catch(() => {
|
|
420
|
+
});
|
|
421
|
+
} catch {
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const log = {
|
|
426
|
+
info: write("info"),
|
|
427
|
+
warn: write("warn"),
|
|
428
|
+
error: write("error"),
|
|
429
|
+
// send logs and crash reports to your server (POST JSON)
|
|
430
|
+
sendTo(url) {
|
|
431
|
+
sendUrl = typeof url === "string" ? url : "";
|
|
432
|
+
},
|
|
433
|
+
get recent() {
|
|
434
|
+
return [...recent];
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
function reset() {
|
|
438
|
+
handlers.clear();
|
|
439
|
+
errorPage = null;
|
|
440
|
+
recent.length = 0;
|
|
441
|
+
setOverlay(null);
|
|
442
|
+
sendUrl = "";
|
|
443
|
+
file = "";
|
|
444
|
+
line = 0;
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
at,
|
|
448
|
+
report,
|
|
449
|
+
guard,
|
|
450
|
+
renderError,
|
|
451
|
+
renderDevOverlay,
|
|
452
|
+
registerSource,
|
|
453
|
+
overlay,
|
|
454
|
+
onError,
|
|
455
|
+
setErrorPage,
|
|
456
|
+
log,
|
|
457
|
+
reset,
|
|
458
|
+
get location() {
|
|
459
|
+
return { file, line };
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function isCancel(error) {
|
|
464
|
+
return error?.name === "AbortError";
|
|
465
|
+
}
|
|
466
|
+
function friendly(message) {
|
|
467
|
+
let m;
|
|
468
|
+
if (m = message.match(/Cannot read propert(?:y|ies) of (undefined|null)(?: \(reading '([^']+)'\))?/)) {
|
|
469
|
+
return m[2] ? `Tried to read "${m[2]}" from something that is ${m[1] === "null" ? "empty (null)" : "missing (undefined)"}` : `Tried to read from something that is ${m[1]}`;
|
|
470
|
+
}
|
|
471
|
+
if (m = message.match(/^(?:undefined is not an object|null is not an object) \(evaluating '([^']+)'\)/)) {
|
|
472
|
+
return `Tried to read "${m[1]}" from something that is missing`;
|
|
473
|
+
}
|
|
474
|
+
if (m = message.match(/^([\w$.?]+) is not a function/)) {
|
|
475
|
+
return `"${m[1].replace(/\?/g, "")}" is not a function, so it can't be called with ()`;
|
|
476
|
+
}
|
|
477
|
+
if (m = message.match(/^(\w+) is not defined$/)) {
|
|
478
|
+
return `"${m[1]}" doesn't exist here`;
|
|
479
|
+
}
|
|
480
|
+
if (/Maximum call stack size exceeded/.test(message)) {
|
|
481
|
+
return "A function keeps calling itself forever (too much recursion)";
|
|
482
|
+
}
|
|
483
|
+
if (/JSON\.parse|Unexpected token .* in JSON|is not valid JSON/.test(message)) {
|
|
484
|
+
return "The data is not valid JSON";
|
|
485
|
+
}
|
|
486
|
+
return message;
|
|
487
|
+
}
|
|
488
|
+
function explain(message) {
|
|
489
|
+
if (/not valid JSON/i.test(message)) {
|
|
490
|
+
return "Make sure the text or server reply is valid JSON before parsing, or handle bad data with `try { ... } catch err { ... }`.";
|
|
491
|
+
}
|
|
492
|
+
if (/something that is (?:empty|missing)/i.test(message)) {
|
|
493
|
+
return "This value is empty right now (for example, still loading). Check with `if value { ... }` before reading its fields.";
|
|
494
|
+
}
|
|
495
|
+
if (/is not a function/i.test(message)) {
|
|
496
|
+
return "You called something with () that holds a plain value instead of a function. Check its name or remove ().";
|
|
497
|
+
}
|
|
498
|
+
if (/doesn't exist here/i.test(message)) {
|
|
499
|
+
return "Declare this name above with `state`, `let`, or `fn`, or check for a typo.";
|
|
500
|
+
}
|
|
501
|
+
if (/too much recursion/i.test(message)) {
|
|
502
|
+
return "Add a stopping `if` condition so the function stops calling itself.";
|
|
503
|
+
}
|
|
504
|
+
if (/timed out|failed with status|failed:/i.test(message)) {
|
|
505
|
+
return "Check the URL or server response, and handle failures with `.error` / `.retry()` or `try { ... } catch err { ... }`.";
|
|
506
|
+
}
|
|
507
|
+
return "";
|
|
508
|
+
}
|
|
509
|
+
export {
|
|
510
|
+
createErrorCenter,
|
|
511
|
+
explain,
|
|
512
|
+
friendly
|
|
513
|
+
};
|