orvyn-lang 0.3.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.
@@ -1,4 +1,7 @@
1
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";
3
6
  import {
4
7
  autoButtonColor,
@@ -80,6 +83,7 @@ import {
80
83
  env,
81
84
  setEnv,
82
85
  registerScreens,
86
+ registeredScreens,
83
87
  bindCheck
84
88
  } from "./runtime-shared.js";
85
89
  import { validate } from "./validation.js";
@@ -92,6 +96,7 @@ const setPage = (_page) => {
92
96
  };
93
97
  import { formCache, createForm } from "./form.js";
94
98
  const host = globalThis;
99
+ const platform = host.__orvynPlatform === "android" ? "android" : "ios";
95
100
  const DEFAULT_TIMEOUT_MS = 15e3;
96
101
  let nextFetchId = 0;
97
102
  const pendingFetches = /* @__PURE__ */ new Map();
@@ -246,9 +251,43 @@ function resolveNativeStyleValue(key, raw, currentTheme = theme()) {
246
251
  return Object.keys(nested).length ? nested : void 0;
247
252
  }
248
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);
249
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
+ }
250
265
  return themed;
251
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
+ }
252
291
  function flatten(children, out = []) {
253
292
  for (const child of children) {
254
293
  if (Array.isArray(child)) flatten(child, out);
@@ -356,6 +395,7 @@ function toNative(value, id, submit, scopePath = "") {
356
395
  };
357
396
  }
358
397
  const props = value.props || {};
398
+ if (resolveResponsive(props.show) === false) return null;
359
399
  if (props.nativeRole === "toggle") {
360
400
  const [input, words2] = value.children;
361
401
  const node2 = {
@@ -386,13 +426,83 @@ function toNative(value, id, submit, scopePath = "") {
386
426
  const currentTheme = theme();
387
427
  for (const key in t === "modal" ? {} : props) {
388
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;
389
430
  if (STYLE_KEYS.has(key)) {
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
+ }
390
496
  const resolved = resolveNativeStyleValue(key, props[key], currentTheme);
391
497
  if (resolved !== void 0 && resolved !== null) node.s[key] = resolved;
392
498
  } else {
393
499
  warnStyle(key, "native");
394
500
  }
395
501
  }
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
+ }
396
506
  if (t === "button" && props.bg && !props.color) {
397
507
  const fg = autoButtonColor(props.bg, currentTheme);
398
508
  if (fg) node.s.color = fg;
@@ -414,11 +524,17 @@ function toNative(value, id, submit, scopePath = "") {
414
524
  if (props.onInput) {
415
525
  node.e = { ...node.e, change: handlers.push(props.onInput) - 1 };
416
526
  }
527
+ if (props.onVisible) {
528
+ node.e = { ...node.e, visible: handlers.push(props.onVisible) - 1 };
529
+ }
417
530
  if (props.placeholder !== void 0) node.ph = String(props.placeholder);
418
531
  if (t === "input" && props.type !== void 0) node.inputType = String(props.type);
419
532
  if (value.tag === "textarea") node.inputType = "multiline";
420
533
  if (props.value !== void 0) node.v = props.value === null ? "" : String(props.value);
421
- if (props.src !== void 0) node.src = String(props.src);
534
+ if (props.src !== void 0) {
535
+ const src = String(props.src);
536
+ node.src = globalThis.__orvynAssets?.includes(src) ? "asset:" + src : src;
537
+ }
422
538
  if (props.href !== void 0) node.href = String(props.href);
423
539
  const children = flatten(value.children || []);
424
540
  if (t === "select") {
@@ -441,7 +557,21 @@ auth.__attachRouter(router);
441
557
  const go = router.go;
442
558
  const back = router.back;
443
559
  const canGoBack = router.canGoBack;
444
- const openUrl = router.openUrl;
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;
572
+ }
573
+ return router.openUrl(url);
574
+ }
445
575
  host.__orvynBack = () => router.back();
446
576
  host.__orvynDeepLink = (url) => router.openUrl(url);
447
577
  function startApp(_target, entry, onStart, screens = {}, initialParams = {}) {
@@ -525,6 +655,7 @@ export {
525
655
  createSelect,
526
656
  createTabs,
527
657
  createVNode2 as createVNode,
658
+ defineAnimation,
528
659
  env,
529
660
  errorText,
530
661
  fetchData,
@@ -539,17 +670,21 @@ export {
539
670
  len,
540
671
  load,
541
672
  log,
673
+ nativeBackground,
674
+ nativeSize,
542
675
  onError,
543
676
  openUrl,
544
677
  patch,
545
678
  pickFile,
546
679
  pickPhoto,
680
+ platform,
547
681
  post,
548
682
  put,
549
683
  random,
550
684
  readImported,
551
685
  registerScreens,
552
686
  registerSource,
687
+ registeredScreens,
553
688
  remove,
554
689
  removeAt,
555
690
  renderError,
@@ -557,6 +692,7 @@ export {
557
692
  resetState,
558
693
  resume,
559
694
  savedSignal,
695
+ scrollTo,
560
696
  secure,
561
697
  setAt,
562
698
  setEnv,
@@ -0,0 +1,53 @@
1
+ function nativeSize(value, viewport = globalThis.__orvynViewport) {
2
+ const width = Number(viewport?.width);
3
+ const height = Number(viewport?.height);
4
+ const atom = (part) => {
5
+ const match = part.trim().match(/^(-?\d+(?:\.\d+)?)(px|vw|vh|%)?$/);
6
+ if (!match) return void 0;
7
+ const amount = Number(match[1]);
8
+ switch (match[2]) {
9
+ case "vw":
10
+ case "%":
11
+ return width > 0 ? width * amount / 100 : void 0;
12
+ case "vh":
13
+ return height > 0 ? height * amount / 100 : void 0;
14
+ default:
15
+ return amount;
16
+ }
17
+ };
18
+ const pair = value.match(/^(min|max)\(\s*([^,]+)\s*,\s*([^,]+)\s*\)$/);
19
+ if (pair) {
20
+ const a = atom(pair[2]), b = atom(pair[3]);
21
+ return a === void 0 || b === void 0 ? void 0 : pair[1] === "min" ? Math.min(a, b) : Math.max(a, b);
22
+ }
23
+ const clamp = value.match(/^clamp\(\s*([^,]+)\s*,\s*([^,]+)\s*,\s*([^,]+)\s*\)$/);
24
+ if (clamp) {
25
+ const lo = atom(clamp[1]), mid = atom(clamp[2]), hi = atom(clamp[3]);
26
+ return lo === void 0 || mid === void 0 || hi === void 0 ? void 0 : Math.max(lo, Math.min(mid, hi));
27
+ }
28
+ const calc = value.match(/^calc\(\s*([^+\-]+)\s*([+\-])\s*([^+\-]+)\s*\)$/);
29
+ if (calc) {
30
+ const a = atom(calc[1]), b = atom(calc[3]);
31
+ return a === void 0 || b === void 0 ? void 0 : calc[2] === "+" ? a + b : a - b;
32
+ }
33
+ if (/(?:vw|vh)$/.test(value.trim())) return atom(value);
34
+ return /^-?\d+(?:\.\d+)?px$/.test(value.trim()) ? atom(value) : void 0;
35
+ }
36
+ function cssParts(value) {
37
+ const parts = [];
38
+ let depth = 0, current = "";
39
+ for (const ch of value.trim()) {
40
+ if (ch === "(") depth++;
41
+ if (ch === ")") depth--;
42
+ if (/\s/.test(ch) && depth === 0) {
43
+ if (current) parts.push(current);
44
+ current = "";
45
+ } else current += ch;
46
+ }
47
+ if (current) parts.push(current);
48
+ return parts;
49
+ }
50
+ export {
51
+ cssParts,
52
+ nativeSize
53
+ };
@@ -0,0 +1,71 @@
1
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
2
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
3
+ import { parse } from "./parser.js";
4
+ function withPageFiles(source, entry) {
5
+ if (basename(entry) !== "app.orv") return source;
6
+ const root = join(dirname(entry), "pages");
7
+ if (!existsSync(root)) return source;
8
+ const declared = new Set(parse(source).body.flatMap((d) => d.kind === "Use" ? d.names : d.kind === "Screen" ? [d.name] : []));
9
+ const imports = [];
10
+ const visit = (dir) => {
11
+ for (const name of readdirSync(dir).sort()) {
12
+ const full = join(dir, name);
13
+ if (statSync(full).isDirectory()) {
14
+ visit(full);
15
+ continue;
16
+ }
17
+ if (name !== "index.orv") continue;
18
+ const route = basename(dirname(full)).replace(/[-_]/g, "").toLowerCase();
19
+ const screens = parse(readFileSync(full, "utf-8")).body.filter((d) => d.kind === "Screen" && d.type === "screen");
20
+ for (const screen of screens) {
21
+ if (screen.kind !== "Screen" || screen.type !== "screen") continue;
22
+ if (screen.name.toLowerCase() !== route) continue;
23
+ if (declared.has(screen.name)) continue;
24
+ const path = "./" + relative(dirname(entry), full).split(sep).join("/").replace(/\.orv$/, "");
25
+ imports.push(`use ${screen.name} from ${JSON.stringify(path)}`);
26
+ declared.add(screen.name);
27
+ }
28
+ }
29
+ };
30
+ visit(root);
31
+ return imports.length ? `${source}
32
+ ${imports.join("\n")}
33
+ ` : source;
34
+ }
35
+ function collectProjectPrograms(entry) {
36
+ const seen = /* @__PURE__ */ new Set();
37
+ const items = [];
38
+ const visit = (file) => {
39
+ file = resolve(file);
40
+ if (seen.has(file) || !existsSync(file)) return;
41
+ seen.add(file);
42
+ const program = parse(withPageFiles(readFileSync(file, "utf-8"), file));
43
+ items.push({ file, program });
44
+ for (const decl of program.body) {
45
+ if (decl.kind !== "Use" || !decl.path.startsWith(".") || /\.(m?js|ts)$/.test(decl.path)) continue;
46
+ const base = resolve(dirname(file), decl.path.endsWith(".orv") ? decl.path : `${decl.path}.orv`);
47
+ const next = existsSync(base) ? base : resolve(dirname(file), decl.path, "index.orv");
48
+ if (existsSync(next)) visit(next);
49
+ }
50
+ };
51
+ visit(entry);
52
+ return items;
53
+ }
54
+ function projectScreens(file) {
55
+ let dir = dirname(resolve(file));
56
+ while (!existsSync(join(dir, "app.orv"))) {
57
+ const up = dirname(dir);
58
+ if (up === dir) return [];
59
+ dir = up;
60
+ }
61
+ try {
62
+ return collectProjectPrograms(join(dir, "app.orv")).flatMap(({ program }) => program.body.flatMap((d) => d.kind === "Screen" && d.type === "screen" ? [d.name] : []));
63
+ } catch {
64
+ return [];
65
+ }
66
+ }
67
+ export {
68
+ collectProjectPrograms,
69
+ projectScreens,
70
+ withPageFiles
71
+ };
package/src/lang/page.js CHANGED
@@ -1,6 +1,17 @@
1
1
  function structuredData(page, url) {
2
2
  const article = page.type === "article";
3
3
  const text = (value) => value ? String(value) : void 0;
4
+ const identity = {
5
+ "@type": "Person",
6
+ name: text(page.name ?? page.title),
7
+ description: text(page.description),
8
+ image: text(page.image),
9
+ jobTitle: text(page.jobTitle),
10
+ sameAs: Array.isArray(page.sameAs) ? page.sameAs.map(String) : void 0,
11
+ url: url || void 0
12
+ };
13
+ if (page.type === "person") return { "@context": "https://schema.org", ...identity };
14
+ if (page.type === "profile") return { "@context": "https://schema.org", "@type": "ProfilePage", name: text(page.title), description: text(page.description), mainEntity: identity, url: url || void 0 };
4
15
  return {
5
16
  "@context": "https://schema.org",
6
17
  "@type": article ? "Article" : "WebPage",
@@ -1,4 +1,5 @@
1
1
  import { OrvynSyntaxError, tokenize } from "./lexer.js";
2
+ const APPEAR_PRESET_NAMES = ["fade", "fade-up", "fade-down", "slide-left", "slide-right", "scale"];
2
3
  const BINARY_PRECEDENCE = {
3
4
  "??": 1,
4
5
  "||": 1,
@@ -221,6 +222,22 @@ class Parser {
221
222
  const body = this.parseBlock();
222
223
  return { kind: "Start", body, line: token.line, col: token.col };
223
224
  }
225
+ if (token.type === "ident" && token.value === "animation" && this.peek(1).type === "ident" && this.is("{", 2)) {
226
+ this.next();
227
+ const name = this.expectIdent('after "animation"');
228
+ if (APPEAR_PRESET_NAMES.includes(name.value)) {
229
+ this.fail(`"${name.value}" is already a built-in animation. Pick another name, like "my${capitalize(name.value)}"`, name);
230
+ }
231
+ const from = this.parseExpr();
232
+ const pos = { line: token.line, col: token.col };
233
+ const init = {
234
+ kind: "Call",
235
+ callee: { kind: "Ident", name: "defineAnimation", ...pos },
236
+ args: [{ kind: "String", parts: [name.value], ...pos }, from],
237
+ ...pos
238
+ };
239
+ return { kind: "Const", name: name.value, init, ...pos };
240
+ }
224
241
  if (this.eat("fn")) {
225
242
  const name = this.expectIdent('after "fn"');
226
243
  this.paramTypes = {};
@@ -387,8 +404,8 @@ class Parser {
387
404
  do {
388
405
  this.skipNewlines();
389
406
  const key = this.expectIdent("in page");
390
- if (!["title", "description", "image", "type", "author", "date", "noindex"].includes(key.value)) {
391
- this.fail(`page has no "${key.value}". Use: title, description, image, type, author, date, noindex`, key);
407
+ if (!["title", "description", "image", "type", "author", "date", "noindex", "name", "jobTitle", "sameAs"].includes(key.value)) {
408
+ this.fail(`page has no "${key.value}". Use: title, description, image, type, author, date, noindex, name, jobTitle, sameAs`, key);
392
409
  }
393
410
  this.expect(":", `after "${key.value}"`);
394
411
  page.push({ key: key.value, value: { kind: "Expr", expr: this.parseExpr() }, line: key.line, col: key.col });
@@ -471,6 +488,10 @@ class Parser {
471
488
  const body = this.parseViewBlock();
472
489
  return { kind: "ViewFor", name: name.value, iter, ...key ? { key } : {}, body, line: token.line, col: token.col };
473
490
  }
491
+ if (token.value === "slot" && token.type === "ident") {
492
+ this.next();
493
+ return { kind: "Element", name: "Slot", arg: null, props: [], children: [], line: token.line, col: token.col };
494
+ }
474
495
  if (token.type !== "ident" || !/^[A-Z]/.test(token.value)) {
475
496
  this.fail(
476
497
  `Expected an element like Text, Button or Column, but found ${describe(token)}`,
@@ -478,6 +499,9 @@ class Parser {
478
499
  );
479
500
  }
480
501
  this.next();
502
+ if (this.is("(") && this.is(")", 1)) {
503
+ this.fail(`Use ${token.value} without () inside a view`, this.peek());
504
+ }
481
505
  let arg = null;
482
506
  const props = [];
483
507
  const atArgsEnd = () => this.peek().type === "newline" || this.peek().type === "eof" || this.is("{") || this.is("}");
@@ -505,6 +529,10 @@ class Parser {
505
529
  }
506
530
  parsePropValue(key) {
507
531
  const isEvent = /^on[A-Z]/.test(key);
532
+ if (["align", "justify", "textAlign"].includes(key) && this.is("start")) {
533
+ const token = this.next();
534
+ return { kind: "Expr", expr: { kind: "Ident", name: "start", line: token.line, col: token.col } };
535
+ }
508
536
  if (isEvent && this.is("{")) {
509
537
  return { kind: "Handler", body: this.parseBlock() };
510
538
  }
@@ -539,6 +567,12 @@ class Parser {
539
567
  }
540
568
  parseUnary() {
541
569
  const token = this.peek();
570
+ if (token.type === "ident" && token.value === "new" && this.peek(1).type === "ident") {
571
+ this.next();
572
+ const call = this.parsePostfix(this.parsePrimary());
573
+ if (call.kind !== "Call") this.fail("new needs a class call, like new Lenis()", token);
574
+ return { kind: "New", callee: call.callee, args: call.args, line: token.line, col: token.col };
575
+ }
542
576
  if (this.eat("wait")) {
543
577
  return { kind: "Wait", expr: this.parseUnary(), line: token.line, col: token.col };
544
578
  }
@@ -744,5 +778,6 @@ function parse(source) {
744
778
  return new Parser(tokenize(source)).parseProgram();
745
779
  }
746
780
  export {
781
+ APPEAR_PRESET_NAMES,
747
782
  parse
748
783
  };
@@ -208,7 +208,7 @@ async function renderPages(entry, options = {}) {
208
208
  const site = (options.site ?? "").replace(/\/$/, "");
209
209
  const first = draw(code, "/", site);
210
210
  const screens = first.context.__app.screens;
211
- const home = screens.App ?? Object.entries(screens).find(([name]) => !["NotFound", "ErrorPage"].includes(name))?.[1];
211
+ const home = screens.App ?? screens.Home ?? Object.entries(screens).find(([name]) => !["NotFound", "ErrorPage"].includes(name))?.[1];
212
212
  const paths = [];
213
213
  try {
214
214
  for (const [name, screen] of Object.entries(screens)) {
@@ -2,7 +2,8 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
3
  function readImportFrom(file) {
4
4
  return (path) => {
5
- const full = resolve(dirname(file), path.endsWith(".orv") ? path : `${path}.orv`);
5
+ const base = resolve(dirname(file), path.endsWith(".orv") ? path : `${path}.orv`);
6
+ const full = existsSync(base) ? base : resolve(dirname(file), path, "index.orv");
6
7
  return existsSync(full) ? { source: readFileSync(full, "utf-8"), resolve: readImportFrom(full) } : null;
7
8
  };
8
9
  }
@@ -834,6 +834,9 @@ const allScreens = {};
834
834
  function registerScreens(screens) {
835
835
  Object.assign(allScreens, screens);
836
836
  }
837
+ function registeredScreens() {
838
+ return { ...allScreens };
839
+ }
837
840
  function bindCheck(state, key, indexed = false) {
838
841
  const handler = bindInput(state, key, indexed);
839
842
  return Object.assign((event) => {
@@ -866,6 +869,7 @@ export {
866
869
  random,
867
870
  readImported,
868
871
  registerScreens,
872
+ registeredScreens,
869
873
  remove,
870
874
  removeAt,
871
875
  resume,
@@ -2,6 +2,7 @@ import { createOwner, disposeOwner, effect, runWithOwner } from "../core/signal.
2
2
  import { createVNode } from "../runtime/vnode.js";
3
3
  import { disposeDomTree, mount } from "../runtime/mount.js";
4
4
  import { theme } from "../styling/spec.js";
5
+ import { defineAnimation } from "../runtime/animations.js";
5
6
  import { createRouter, parseRouteUrl } from "./router.js";
6
7
  import { createAuth } from "./auth.js";
7
8
  import { createErrorCenter } from "./errors.js";
@@ -77,6 +78,7 @@ import {
77
78
  env,
78
79
  setEnv,
79
80
  registerScreens,
81
+ registeredScreens,
80
82
  snapshotLocals,
81
83
  carryLocals,
82
84
  bindCheck
@@ -158,10 +160,32 @@ auth.__attachRouter(router);
158
160
  const go = router.go;
159
161
  const back = router.back;
160
162
  const canGoBack = router.canGoBack;
161
- const openUrl = router.openUrl;
163
+ const platform = "web";
164
+ function scrollTo(label, offset = 0) {
165
+ const doc = globalThis.document;
166
+ const win = globalThis.window;
167
+ if (!doc || !win) return;
168
+ const top = label === "top" ? 0 : (() => {
169
+ const el = [...doc.querySelectorAll("[aria-label]")].find((node) => node.getAttribute("aria-label") === label);
170
+ return el ? el.getBoundingClientRect().top + win.scrollY - offset : null;
171
+ })();
172
+ if (top === null) return;
173
+ if (win.__lenis?.scrollTo) win.__lenis.scrollTo(top, { duration: 1.2 });
174
+ else win.scrollTo({ top, behavior: "smooth" });
175
+ }
176
+ function openUrl(url) {
177
+ if (/^(https?:|mailto:|tel:|sms:|whatsapp:)/i.test(url)) {
178
+ const win = globalThis.window;
179
+ const origin = win?.location?.origin;
180
+ if (origin && origin !== "null" && /^https?:/i.test(url) && (url === origin || url.toLowerCase().startsWith(origin.toLowerCase() + "/") || url.toLowerCase().startsWith(origin.toLowerCase() + "?")) && router.openUrl(url)) return true;
181
+ if (/^https?:/i.test(url) && typeof win?.open === "function") win.open(url, "_blank", "noopener,noreferrer");
182
+ else if (win?.location) win.location.href = url;
183
+ return true;
184
+ }
185
+ return router.openUrl(url);
186
+ }
162
187
  const BASE_CSS = `
163
188
  :where(.orvyn-app) {
164
- max-width: 760px;
165
189
  margin: 0 auto;
166
190
  min-height: 100vh;
167
191
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
@@ -173,6 +197,11 @@ const BASE_CSS = `
173
197
  overflow-wrap: anywhere;
174
198
  -webkit-font-smoothing: antialiased;
175
199
  }
200
+ :where(.orvyn-app[data-orvyn-native-preview]) {
201
+ max-width: 390px;
202
+ border-left: 1px solid var(--orvyn-border, #cbd5e1);
203
+ border-right: 1px solid var(--orvyn-border, #cbd5e1);
204
+ }
176
205
  :where(.orvyn-app *) { box-sizing: border-box; overflow-wrap: anywhere; }
177
206
  :where(.orvyn-app button) {
178
207
  display: inline-flex;
@@ -185,14 +214,14 @@ const BASE_CSS = `
185
214
  margin: 0;
186
215
  font: inherit;
187
216
  font-weight: 600;
188
- color: var(--orvyn-primary, #007aff);
217
+ color: var(--orvyn-primary, #0066cc);
189
218
  text-align: left;
190
219
  cursor: pointer;
191
220
  transition: opacity 0.15s, transform 0.1s;
192
221
  }
193
222
  :where(.orvyn-app button:hover:not(:disabled)) { opacity: 0.85; }
194
223
  :where(.orvyn-app button:active:not(:disabled)) { opacity: 0.65; transform: scale(0.98); }
195
- :where(.orvyn-app button:focus-visible) { outline: 2px solid var(--orvyn-primary, #007aff); outline-offset: 2px; }
224
+ :where(.orvyn-app button:focus-visible) { outline: 2px solid var(--orvyn-primary, #0066cc); outline-offset: 2px; }
196
225
  :where(.orvyn-app button:disabled) { opacity: 0.5; cursor: not-allowed; }
197
226
  :where(.orvyn-app button[data-orvyn-loading="true"]) { opacity: 0.75; cursor: progress; }
198
227
  :where(.orvyn-app button[data-orvyn-loading="true"])::before {
@@ -208,7 +237,6 @@ const BASE_CSS = `
208
237
  @media (prefers-reduced-motion: reduce) {
209
238
  .orvyn-app, .orvyn-app *, .orvyn-app *::before { transition: none !important; animation: none !important; scroll-behavior: auto !important; transform: none !important; }
210
239
  }
211
- :where(.orvyn-app img) { background: var(--orvyn-surface, #f8fafc); }
212
240
  :where(.orvyn-app input) {
213
241
  font: inherit;
214
242
  color: inherit;
@@ -220,23 +248,23 @@ const BASE_CSS = `
220
248
  outline: none;
221
249
  background: var(--orvyn-bg, #fff);
222
250
  }
223
- :where(.orvyn-app input:focus) { border-color: var(--orvyn-primary, #007aff); box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15); }
251
+ :where(.orvyn-app input:focus) { border-color: var(--orvyn-primary, #0066cc); box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15); }
224
252
  :where(.orvyn-app textarea, .orvyn-app select) {
225
253
  font: inherit; color: inherit; width: 100%; padding: 10px;
226
254
  border: 1px solid var(--orvyn-border, #cbd5e1); border-radius: 8px; background: var(--orvyn-bg, #fff);
227
255
  }
228
- :where(.orvyn-app input[type="checkbox"]) { width: 1.15em; height: 1.15em; padding: 0; flex-shrink: 0; accent-color: var(--orvyn-primary, #007aff); }
256
+ :where(.orvyn-app input[type="checkbox"]) { width: 1.15em; height: 1.15em; padding: 0; flex-shrink: 0; accent-color: var(--orvyn-primary, #0066cc); }
229
257
  :where(.orvyn-app input[role="switch"]) {
230
258
  appearance: none; width: 2.6em; height: 1.5em; border-radius: 999px; border: none; cursor: pointer;
231
259
  background: var(--orvyn-border, #cbd5e1) radial-gradient(circle, #fff 0.6em, transparent 0.62em) left / 1.5em 100% no-repeat;
232
260
  }
233
- :where(.orvyn-app input[role="switch"]:checked) { background-color: var(--orvyn-primary, #007aff); background-position: right; }
261
+ :where(.orvyn-app input[role="switch"]:checked) { background-color: var(--orvyn-primary, #0066cc); background-position: right; }
234
262
  :where(.orvyn-app input:disabled) { opacity: 0.5; cursor: not-allowed; background: var(--orvyn-surface, #f8fafc); }
235
- :where(.orvyn-app input[data-orvyn-error="true"]), :where(.orvyn-app input[aria-invalid="true"]) { border-color: var(--orvyn-danger, #ef4444); }
263
+ :where(.orvyn-app input[data-orvyn-error="true"]), :where(.orvyn-app input[aria-invalid="true"]) { border-color: var(--orvyn-danger, #b91c1c); }
236
264
  :where(.orvyn-app input[data-orvyn-error="true"]:focus), :where(.orvyn-app input[aria-invalid="true"]:focus) { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18); }
237
265
  :where(.orvyn-app img) { display: block; object-fit: contain; flex-shrink: 0; max-width: 100%; }
238
266
  :where(.orvyn-app h1, .orvyn-app h2, .orvyn-app h3) { margin: 0; line-height: 1.15; }
239
- :where(.orvyn-app a) { color: var(--orvyn-primary, #007aff); text-decoration: none; font-weight: 600; }
267
+ :where(.orvyn-app a) { color: var(--orvyn-primary, #0066cc); text-decoration: none; font-weight: 600; }
240
268
  `;
241
269
  function injectBaseStyles() {
242
270
  if (typeof document === "undefined" || document.getElementById("orvyn-base")) return;
@@ -324,6 +352,11 @@ function startApp(target, entry, onStart, screens = {}, initialParams = {}) {
324
352
  win?.addEventListener?.("keydown", onKey);
325
353
  injectBaseStyles();
326
354
  target.classList.add("orvyn-app");
355
+ if (typeof win?.location?.search === "string" && /[?&]native(?:=1|=true)?(?:&|$)/.test(win.location.search)) {
356
+ ;
357
+ globalThis.__orvynNativePreview = true;
358
+ target.setAttribute?.("data-orvyn-native-preview", "true");
359
+ }
327
360
  if (target.getAttribute?.("data-orvyn-static") !== null && target.getAttribute?.("data-orvyn-static") !== void 0) {
328
361
  target.textContent = "";
329
362
  target.removeAttribute("data-orvyn-static");
@@ -382,6 +415,7 @@ function startApp(target, entry, onStart, screens = {}, initialParams = {}) {
382
415
  disposeDomTree(view);
383
416
  disposeOwner(root);
384
417
  router.reset();
418
+ delete globalThis.__orvynNativePreview;
385
419
  view.remove();
386
420
  };
387
421
  }
@@ -406,6 +440,7 @@ export {
406
440
  createSelect,
407
441
  createTabs,
408
442
  createVNode2 as createVNode,
443
+ defineAnimation,
409
444
  env,
410
445
  errorText,
411
446
  fetchData,
@@ -425,12 +460,14 @@ export {
425
460
  patch,
426
461
  pickFile,
427
462
  pickPhoto,
463
+ platform,
428
464
  post,
429
465
  put,
430
466
  random,
431
467
  readImported,
432
468
  registerScreens,
433
469
  registerSource,
470
+ registeredScreens,
434
471
  remove,
435
472
  removeAt,
436
473
  renderError,
@@ -438,6 +475,7 @@ export {
438
475
  resetState,
439
476
  resume,
440
477
  savedSignal,
478
+ scrollTo,
441
479
  secure,
442
480
  setAt,
443
481
  setEnv,