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.
Files changed (63) hide show
  1. package/GUIDE.md +198 -0
  2. package/LANGUAGE.md +818 -30
  3. package/README.md +211 -250
  4. package/brand/orvyn-sunset-animated.svg +15 -0
  5. package/package.json +3 -1
  6. package/src/cli/orvyn.js +207 -16
  7. package/src/core/signal.js +104 -6
  8. package/src/devtools/runtime.js +25 -1
  9. package/src/lang/a11y.js +152 -0
  10. package/src/lang/auth.js +239 -0
  11. package/src/lang/bundle-native.js +10 -6
  12. package/src/lang/codegen.js +615 -58
  13. package/src/lang/device.js +41 -0
  14. package/src/lang/doctor.js +60 -0
  15. package/src/lang/env.js +27 -0
  16. package/src/lang/errors.js +513 -0
  17. package/src/lang/form.js +69 -8
  18. package/src/lang/index.js +2 -1
  19. package/src/lang/lexer.js +2 -0
  20. package/src/lang/list.js +44 -0
  21. package/src/lang/native/android/MainActivity.kt +65 -4
  22. package/src/lang/native/android/OrvynDevice.kt +163 -0
  23. package/src/lang/native/android/OrvynEngine.kt +176 -7
  24. package/src/lang/native/android/OrvynRenderer.kt +970 -50
  25. package/src/lang/native/android.js +74 -11
  26. package/src/lang/native/assets.js +39 -0
  27. package/src/lang/native/build.js +140 -63
  28. package/src/lang/native/compatibility.js +57 -0
  29. package/src/lang/native/config.js +108 -0
  30. package/src/lang/native/ios/OrvynApp.swift +6 -0
  31. package/src/lang/native/ios/OrvynEngine.swift +291 -4
  32. package/src/lang/native/ios/OrvynViews.swift +769 -41
  33. package/src/lang/native/ios.js +81 -2
  34. package/src/lang/native-runtime.js +541 -55
  35. package/src/lang/native-size.js +53 -0
  36. package/src/lang/page-files.js +71 -0
  37. package/src/lang/page.js +63 -0
  38. package/src/lang/parser.js +278 -15
  39. package/src/lang/prerender.js +300 -0
  40. package/src/lang/read-import.js +12 -0
  41. package/src/lang/router.js +266 -0
  42. package/src/lang/runtime-shared.js +796 -10
  43. package/src/lang/runtime.js +399 -51
  44. package/src/lang/select.js +13 -0
  45. package/src/lang/server-code.js +233 -0
  46. package/src/lang/server-export.js +78 -0
  47. package/src/lang/server-libs.js +53 -0
  48. package/src/lang/server.js +409 -0
  49. package/src/lang/style-check.js +60 -0
  50. package/src/lang/test-runner.js +134 -0
  51. package/src/lang/types.js +317 -0
  52. package/src/lang/vite-plugin.js +108 -6
  53. package/src/lang/web-overlay.js +578 -0
  54. package/src/lang/widgets.js +94 -0
  55. package/src/lang/words.js +38 -0
  56. package/src/runtime/animations.js +24 -0
  57. package/src/runtime/appear.js +73 -0
  58. package/src/runtime/marquee.js +57 -0
  59. package/src/runtime/mount.js +120 -27
  60. package/src/runtime/patch.js +90 -11
  61. package/src/runtime/style.js +50 -9
  62. package/src/styling/fluid.js +129 -6
  63. package/src/styling/spec.js +319 -0
@@ -0,0 +1,317 @@
1
+ import { OrvynSyntaxError } from "./lexer.js";
2
+ import { parse } from "./parser.js";
3
+ const ANY = { k: "any" };
4
+ const BASIC = ["text", "number", "yesno"];
5
+ const describe = (t) => t.k === "list" ? `list of ${describe(t.of)}` : t.k === "record" ? t.decl.name : t.k === "null" ? "empty" : t.k;
6
+ function closest(name, names) {
7
+ const distance = (a, b) => {
8
+ const row = Array.from({ length: b.length + 1 }, (_, i) => i);
9
+ for (let i = 1; i <= a.length; i++) {
10
+ let previous = row[0];
11
+ row[0] = i;
12
+ for (let j = 1; j <= b.length; j++) {
13
+ const kept = row[j];
14
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
15
+ previous = kept;
16
+ }
17
+ }
18
+ return row[b.length];
19
+ };
20
+ const best = names.map((n) => [distance(name.toLowerCase(), n.toLowerCase()), n]).sort((a, b) => a[0] - b[0])[0];
21
+ return best && best[0] <= 2 ? ` Did you mean "${best[1]}"?` : ` It has: ${names.join(", ")}`;
22
+ }
23
+ function checkTypes(program, resolve) {
24
+ const types = /* @__PURE__ */ new Map();
25
+ const unknownImports = /* @__PURE__ */ new Set();
26
+ const typeImports = /* @__PURE__ */ new Set();
27
+ const globals = /* @__PURE__ */ new Map();
28
+ const signatures = /* @__PURE__ */ new Map();
29
+ const fail = (message, at) => {
30
+ throw new OrvynSyntaxError(message, at.line, at.col);
31
+ };
32
+ const toType = (ref, at) => {
33
+ if (!ref) return ANY;
34
+ if (ref.list) return { k: "list", of: toType(ref.list, at) };
35
+ const name = ref.name;
36
+ if (BASIC.includes(name)) return { k: name };
37
+ const found = types.get(name);
38
+ if (found) return { k: "record", decl: found };
39
+ if (unknownImports.has(name)) return ANY;
40
+ return fail(`There is no type "${name}".${closest(name, [...BASIC, ...types.keys()])}`, at);
41
+ };
42
+ const signature = (decl) => signatures.set(decl.name, { params: decl.params, types: decl.params.map((p) => decl.paramTypes?.[p] ? toType(decl.paramTypes[p], decl) : null) });
43
+ const read = (use, from) => {
44
+ if (!from || /\.(m?js|ts)$/.test(use.path) || !/^[./]/.test(use.path)) return null;
45
+ const found = from(use.path);
46
+ if (found === null) return null;
47
+ const { source, resolve: next } = typeof found === "string" ? { source: found, resolve: from } : found;
48
+ try {
49
+ return { program: parse(source), resolve: next };
50
+ } catch {
51
+ return null;
52
+ }
53
+ };
54
+ const seen = /* @__PURE__ */ new Set();
55
+ const gather = (other) => {
56
+ const key = JSON.stringify(other.program);
57
+ if (seen.has(key)) return;
58
+ seen.add(key);
59
+ for (const each of other.program.body) {
60
+ if (each.kind === "Type" && !types.has(each.name)) types.set(each.name, each);
61
+ if (each.kind === "Use") {
62
+ const deeper = read(each, other.resolve);
63
+ if (deeper) gather(deeper);
64
+ else for (const name of each.names) if (/^[A-Z]/.test(name)) unknownImports.add(name);
65
+ }
66
+ }
67
+ };
68
+ const imported = [];
69
+ for (const use of program.body) {
70
+ if (use.kind !== "Use") continue;
71
+ const other = read(use, resolve);
72
+ if (other) gather(other);
73
+ for (const name of use.names) {
74
+ const decl = other?.program.body.find((d) => "name" in d && d.name === name);
75
+ if (!decl) unknownImports.add(name);
76
+ else if (decl.kind === "Type") typeImports.add(name);
77
+ else if (decl.kind === "State" || decl.kind === "Const" || decl.kind === "Fn" || decl.kind === "Screen") imported.push(decl);
78
+ }
79
+ }
80
+ for (const decl of program.body) {
81
+ if (decl.kind !== "Type") continue;
82
+ if (BASIC.includes(decl.name)) fail(`"${decl.name}" is already a type`, decl);
83
+ if (types.has(decl.name) && program.body.filter((d) => d.kind === "Type" && d.name === decl.name).length > 1) fail(`Type "${decl.name}" is written twice`, decl);
84
+ types.set(decl.name, decl);
85
+ }
86
+ for (const decl of types.values()) for (const field of decl.fields) toType(field.type, field);
87
+ for (const decl of [...imported, ...program.body]) {
88
+ if (decl.kind === "State" || decl.kind === "Const") globals.set(decl.name, toType(decl.type, decl));
89
+ if (decl.kind === "Fn") signature(decl);
90
+ if (decl.kind === "Screen" && decl.type) signature(decl);
91
+ }
92
+ let scopes = [globals];
93
+ const lookup = (name) => {
94
+ for (let i = scopes.length - 1; i >= 0; i--) if (scopes[i].has(name)) return scopes[i].get(name);
95
+ return ANY;
96
+ };
97
+ const within = (names, work) => {
98
+ scopes.push(new Map(names));
99
+ try {
100
+ work();
101
+ } finally {
102
+ scopes.pop();
103
+ }
104
+ };
105
+ const fieldOf = (record, name, at) => {
106
+ const field = record.decl.fields.find((f) => f.name === name);
107
+ if (!field) fail(`${record.decl.name} has no "${name}".${closest(name, record.decl.fields.map((f) => f.name))}`, at);
108
+ return toType(field.type, field);
109
+ };
110
+ const fits = (wanted, value, what, nullable = true) => {
111
+ if (wanted.k === "any") return void infer(value);
112
+ if (value.kind === "Null") {
113
+ if (!nullable) fail(`${what} can't be empty`, value);
114
+ return;
115
+ }
116
+ if (wanted.k === "record" && value.kind === "Object") {
117
+ for (const entry of value.entries) fits(fieldOf(wanted, entry.key, value), entry.value, `"${entry.key}"`);
118
+ const missing = wanted.decl.fields.filter((f) => !f.optional && !value.entries.some((e) => e.key === f.name));
119
+ if (missing.length) fail(`This ${wanted.decl.name} is missing: ${missing.map((f) => f.name).join(", ")}`, value);
120
+ return;
121
+ }
122
+ if (wanted.k === "list" && value.kind === "List") return value.items.forEach((item) => fits(wanted.of, item, "Each item", false));
123
+ const got = infer(value);
124
+ const same = (a, b) => a.k === "any" || b.k === "any" || b.k === "null" || (a.k === "list" && b.k === "list" ? same(a.of, b.of) : a.k === "record" && b.k === "record" ? a.decl.name === b.decl.name : a.k === b.k);
125
+ if (!same(wanted, got)) fail(`${what} should be ${describe(wanted)}, but this is ${describe(got)}`, value);
126
+ };
127
+ const call = (expr) => {
128
+ const callee = expr.callee;
129
+ if (callee.kind === "Member") {
130
+ const target = infer(callee.object);
131
+ const word = callee.property;
132
+ if (target.k !== "list") {
133
+ expr.args.forEach((a) => infer(a));
134
+ return ANY;
135
+ }
136
+ const item = target.of;
137
+ const named = (arg) => {
138
+ if (item.k === "record" && arg?.kind === "String" && arg.parts.length === 1 && typeof arg.parts[0] === "string") return fieldOf(item, arg.parts[0], arg);
139
+ if (arg) infer(arg);
140
+ return ANY;
141
+ };
142
+ if (["where", "count", "first"].includes(word)) {
143
+ const wanted = expr.args[0];
144
+ if (item.k === "record" && wanted?.kind === "Object") {
145
+ for (const entry of wanted.entries) fits(fieldOf(item, entry.key, wanted), entry.value, `"${entry.key}"`);
146
+ } else expr.args.forEach((a) => infer(a, item));
147
+ return word === "count" ? { k: "number" } : word === "first" ? item : target;
148
+ }
149
+ if (word === "sortBy") {
150
+ named(expr.args[0]);
151
+ return target;
152
+ }
153
+ if (word === "search") {
154
+ if (expr.args[0]) infer(expr.args[0]);
155
+ named(expr.args[1]);
156
+ return target;
157
+ }
158
+ if (word === "pick") return { k: "list", of: named(expr.args[0]) };
159
+ if (word === "total") {
160
+ expr.args.forEach(named);
161
+ return { k: "number" };
162
+ }
163
+ if (word === "add") {
164
+ if (expr.args[0]) fits(item, expr.args[0], "A new item", false);
165
+ return ANY;
166
+ }
167
+ expr.args.forEach((a) => infer(a, item));
168
+ return word === "filter" ? target : word === "find" ? item : ANY;
169
+ }
170
+ const known = callee.kind === "Ident" ? signatures.get(callee.name) : void 0;
171
+ expr.args.forEach((arg, i) => known?.types[i] ? fits(known.types[i], arg, `"${known.params[i]}"`) : infer(arg));
172
+ return ANY;
173
+ };
174
+ const infer = (expr, item = ANY) => {
175
+ switch (expr.kind) {
176
+ case "Number":
177
+ return { k: "number" };
178
+ case "Bool":
179
+ return { k: "yesno" };
180
+ case "Null":
181
+ return { k: "null" };
182
+ case "String":
183
+ for (const part of expr.parts) if (typeof part !== "string") infer(part);
184
+ return { k: "text" };
185
+ case "Ident":
186
+ if (expr.name === "platform" && scopes.every((s) => !s.has("platform"))) return { k: "text" };
187
+ return lookup(expr.name);
188
+ case "List": {
189
+ const all = expr.items.map((i) => infer(i));
190
+ return { k: "list", of: all.length && all.every((t) => t.k === all[0].k) ? all[0] : ANY };
191
+ }
192
+ case "Object":
193
+ expr.entries.forEach((e) => infer(e.value));
194
+ return ANY;
195
+ case "Member": {
196
+ const object = infer(expr.object);
197
+ if (object.k === "record") return fieldOf(object, expr.property, expr);
198
+ return expr.property === "length" && (object.k === "list" || object.k === "text") ? { k: "number" } : ANY;
199
+ }
200
+ case "Index": {
201
+ const object = infer(expr.object);
202
+ infer(expr.index);
203
+ return object.k === "list" ? object.of : ANY;
204
+ }
205
+ case "Call":
206
+ return call(expr);
207
+ case "New":
208
+ infer(expr.callee);
209
+ expr.args.forEach((arg) => infer(arg));
210
+ return ANY;
211
+ case "Unary":
212
+ infer(expr.operand);
213
+ return expr.op === "!" ? { k: "yesno" } : { k: "number" };
214
+ case "Binary": {
215
+ const [left, right] = [infer(expr.left), infer(expr.right)];
216
+ if (["==", "!=", "<", ">", "<=", ">="].includes(expr.op)) return { k: "yesno" };
217
+ if (["-", "*", "/", "%"].includes(expr.op)) return { k: "number" };
218
+ if (expr.op === "+") return left.k === "text" || right.k === "text" ? { k: "text" } : left.k === "number" && right.k === "number" ? left : ANY;
219
+ return expr.op === "??" ? right : ANY;
220
+ }
221
+ case "Ternary":
222
+ infer(expr.cond);
223
+ infer(expr.else, item);
224
+ return infer(expr.then, item);
225
+ case "Wait":
226
+ return infer(expr.expr);
227
+ case "Lambda":
228
+ within(expr.params.map((p, i) => [p, i === 0 ? item : ANY]), () => infer(expr.body));
229
+ return ANY;
230
+ }
231
+ };
232
+ const statements = (body) => within([], () => {
233
+ for (const stmt of body) {
234
+ if (stmt.kind === "Let") {
235
+ const declared = toType(stmt.type, stmt);
236
+ let found = declared;
237
+ if (stmt.type) fits(declared, stmt.init, `"${stmt.name}"`);
238
+ else found = infer(stmt.init);
239
+ scopes.at(-1).set(stmt.name, found);
240
+ } else if (stmt.kind === "Assign") {
241
+ const wanted = infer(stmt.target);
242
+ if (stmt.op === "=") fits(wanted, stmt.value, stmt.target.kind === "Ident" ? `"${stmt.target.name}"` : "This field");
243
+ else infer(stmt.value);
244
+ } else if (stmt.kind === "ExprStmt") infer(stmt.expr);
245
+ else if (stmt.kind === "Return") {
246
+ if (stmt.value) infer(stmt.value);
247
+ } else if (stmt.kind === "If") {
248
+ infer(stmt.cond);
249
+ statements(stmt.then);
250
+ if (stmt.else) statements(stmt.else);
251
+ } else if (stmt.kind === "For") {
252
+ const list = infer(stmt.iter);
253
+ within([[stmt.name, list.k === "list" ? list.of : ANY]], () => statements(stmt.body));
254
+ } else if (stmt.kind === "Try") {
255
+ statements(stmt.body);
256
+ within(stmt.catchName ? [[stmt.catchName, { k: "text" }]] : [], () => statements(stmt.catchBody));
257
+ }
258
+ }
259
+ });
260
+ const view = (node) => {
261
+ if (node.kind === "ViewIf") {
262
+ infer(node.cond);
263
+ node.then.forEach(view);
264
+ node.else?.forEach(view);
265
+ return;
266
+ }
267
+ if (node.kind === "ViewFor") {
268
+ const list = infer(node.iter);
269
+ return within([[node.name, list.k === "list" ? list.of : ANY]], () => {
270
+ if (node.key) infer(node.key);
271
+ node.body.forEach(view);
272
+ });
273
+ }
274
+ if (node.arg) infer(node.arg);
275
+ const component = signatures.get(node.name);
276
+ for (const prop of node.props) {
277
+ if (prop.value.kind === "Handler") {
278
+ const body = prop.value.body;
279
+ within([["value", ANY]], () => statements(body));
280
+ continue;
281
+ }
282
+ const at = component?.params.indexOf(prop.key) ?? -1;
283
+ const wanted = at >= 0 ? component.types[at] : null;
284
+ if (wanted) fits(wanted, prop.value.expr, `"${prop.key}"`);
285
+ else infer(prop.value.expr);
286
+ }
287
+ node.children.forEach(view);
288
+ };
289
+ for (const decl of program.body) {
290
+ scopes = [globals];
291
+ if ((decl.kind === "State" || decl.kind === "Const") && decl.type) fits(globals.get(decl.name), decl.init, `"${decl.name}"`);
292
+ else if (decl.kind === "Start" || decl.kind === "Test") statements(decl.body);
293
+ else if (decl.kind === "Fn") within(decl.params.map((p) => [p, toType(decl.paramTypes?.[p], decl)]), () => statements(decl.body));
294
+ else if (decl.kind === "Screen") {
295
+ within(decl.params.map((p) => [p, toType(decl.paramTypes?.[p], decl)]), () => {
296
+ for (const local of decl.locals ?? []) {
297
+ const declared = toType(local.type, local);
298
+ if (local.type) fits(declared, local.init, `"${local.name}"`);
299
+ scopes.at(-1).set(local.name, local.type ? declared : infer(local.init));
300
+ }
301
+ decl.body.forEach(view);
302
+ });
303
+ }
304
+ }
305
+ return {
306
+ ...program,
307
+ body: program.body.flatMap((decl) => {
308
+ if (decl.kind === "Type") return [];
309
+ if (decl.kind !== "Use") return [decl];
310
+ const names = decl.names.filter((n) => !typeImports.has(n));
311
+ return names.length ? [{ ...decl, names }] : [];
312
+ })
313
+ };
314
+ }
315
+ export {
316
+ checkTypes
317
+ };
@@ -1,27 +1,128 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { basename, dirname, join, relative, resolve } from "node:path";
1
3
  import { fileURLToPath } from "node:url";
2
4
  import { compile, OrvynSyntaxError } from "./index.js";
5
+ import { loadEnv } from "./env.js";
6
+ import { readImportFrom } from "./read-import.js";
7
+ import { projectScreens, withPageFiles } from "./page-files.js";
3
8
  const orvynRoot = fileURLToPath(new URL("../../", import.meta.url));
4
9
  const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
5
10
  const webRuntime = fileURLToPath(new URL(`./runtime${ext}`, import.meta.url));
6
- function orvynLang() {
11
+ const orvynVersion = JSON.parse(readFileSync(join(orvynRoot, "package.json"), "utf8")).version;
12
+ function orvynMarkers(version = orvynVersion) {
13
+ return [
14
+ { tag: "meta", attrs: { name: "generator", content: `Orvyn ${version}` }, injectTo: "head-prepend" },
15
+ { tag: "script", children: `window.__ORVYN__={version:${JSON.stringify(version)}}`, injectTo: "head-prepend" }
16
+ ];
17
+ }
18
+ function moduleNamespace(id, rootDir) {
19
+ const cleanId = id.split("?")[0];
20
+ const rel = relative(rootDir, cleanId).replace(/\\/g, "/");
21
+ if (!rel || rel.startsWith("..")) {
22
+ return basename(cleanId, ".orv") || "app";
23
+ }
24
+ return rel.replace(/\.orv$/, "");
25
+ }
26
+ const HOT = `
27
+ let __live = null
28
+ const __mount = mountApp
29
+ mountApp = function (target, screen, params) {
30
+ const stop = __mount(target, screen, params)
31
+ __live = { target, stop }
32
+ return stop
33
+ }
34
+ const __initial = {}
35
+ const __plain = value => { try { return JSON.stringify(value, (k, v) => { if (typeof v === "function") throw 0; return v }) } catch { return undefined } }
36
+ const __states = {}
37
+ if (import.meta.hot) {
38
+ import.meta.hot.dispose(data => {
39
+ data.live = __live
40
+ data.locals = __o.snapshotLocals()
41
+ data.scroll = typeof scrollY === "number" ? [scrollX, scrollY] : null
42
+ data.states = Object.fromEntries(Object.entries(__states).map(([name, s]) => [name, { value: s.get(), initial: __initial[name] }]))
43
+ if (typeof onError === "function") __o.onError(onError)()
44
+ })
45
+ import.meta.hot.accept(next => {
46
+ const { live, states, locals, scroll } = import.meta.hot.data
47
+ // a file without the running app passes the change up to the file that has it
48
+ if (!live) return import.meta.hot.invalidate()
49
+ if (!next) return
50
+ live.stop()
51
+ next.__restore(states)
52
+ __o.carryLocals(locals)
53
+ next.mountApp(live.target)
54
+ __o.carryLocals([])
55
+ if (scroll) scrollTo(...scroll)
56
+ })
57
+ }
58
+ `;
59
+ const restore = (names) => `
60
+ for (const [__name, __state] of [${names.map((n) => `[${JSON.stringify(n)}, ${n}]`).join(", ")}]) {
61
+ __states[__name] = __state
62
+ __initial[__name] = __plain(__state.get())
63
+ }
64
+ export function __restore(old) {
65
+ for (const [name, kept] of Object.entries(old ?? {})) {
66
+ if (__states[name] && kept.initial !== undefined && kept.initial === __initial[name] && __plain(kept.value) !== undefined) {
67
+ __states[name].set(kept.value)
68
+ }
69
+ }
70
+ }
71
+ `;
72
+ function orvynLang(options = {}) {
73
+ let rootDir = options.root || process.cwd();
74
+ let isDev = Boolean(options.dev);
75
+ let env = options.env;
76
+ let hot = false;
7
77
  return {
8
78
  name: "orvyn-lang",
9
79
  // let Vite serve Orvyn's runtime files when Orvyn is installed
10
80
  // from another folder (npm install ../orvyn)
11
- config(config) {
81
+ async config(config, run) {
82
+ if (options.dev === void 0 && run?.command) isDev = run.command === "serve";
83
+ hot = run?.command === "serve";
84
+ env = options.env ?? await loadEnv(config.root || rootDir, isDev ? "dev" : "prod");
85
+ if (!options.root && config.root) rootDir = config.root;
12
86
  const allow = config.server?.fs?.allow;
13
87
  if (allow) return { server: { fs: { allow: [...allow, orvynRoot] } } };
14
88
  return { server: { fs: { allow: [process.cwd(), orvynRoot] } } };
15
89
  },
90
+ transformIndexHtml() {
91
+ return orvynMarkers();
92
+ },
16
93
  // compiled .orv code imports "orvyn/lang/runtime"; point it at this
17
94
  // copy of Orvyn whatever the package is called (orvyn, orvyn-lang, ...)
18
- resolveId(id) {
19
- return id === "orvyn/lang/runtime" ? webRuntime : null;
95
+ resolveId(id, importer) {
96
+ if (id === "orvyn/lang/runtime") return webRuntime;
97
+ if (importer && id.startsWith(".") && id.endsWith(".orv")) {
98
+ const file = resolve(dirname(importer), id);
99
+ if (!existsSync(file)) {
100
+ const index = join(file.slice(0, -4), "index.orv");
101
+ if (existsSync(index)) return index;
102
+ }
103
+ }
104
+ return null;
20
105
  },
21
106
  transform(source, id) {
22
107
  if (!id.endsWith(".orv")) return null;
23
108
  try {
24
- return { code: compile(source), map: null };
109
+ source = withPageFiles(source, id.split("?")[0]);
110
+ let code = compile(source, {
111
+ moduleId: moduleNamespace(id, rootDir),
112
+ env,
113
+ resolveImport: readImportFrom(id.split("?")[0]),
114
+ projectScreens: projectScreens(id.split("?")[0]),
115
+ tests: options.tests,
116
+ ...isDev ? { sourceText: source } : {}
117
+ });
118
+ if (hot) {
119
+ const states = [...code.matchAll(/^export const (\S+) = (?:__signal|__o\.savedSignal)\(/gm)].map((m) => m[1]);
120
+ code = code + HOT + restore(states);
121
+ }
122
+ return {
123
+ code,
124
+ map: null
125
+ };
25
126
  } catch (error) {
26
127
  if (error instanceof OrvynSyntaxError) {
27
128
  const err = new Error(error.message);
@@ -35,5 +136,6 @@ function orvynLang() {
35
136
  };
36
137
  }
37
138
  export {
38
- orvynLang
139
+ orvynLang,
140
+ orvynMarkers
39
141
  };