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,578 @@
1
+ import { effect, signal } from "../core/signal.js";
2
+ const VERSION = "0.2.0";
3
+ const MONO = `"Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace`;
4
+ const SANS = `"Geist", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;
5
+ const BG = "#0a0a0a";
6
+ const BORDER = "#2e2e2e";
7
+ const CSS = `
8
+ :host { all: initial; }
9
+ * { box-sizing: border-box; margin: 0; }
10
+ button { font: inherit; }
11
+ .backdrop {
12
+ position: fixed; inset: 0; z-index: 2147483647;
13
+ background: rgba(0, 0, 0, 0.5);
14
+ backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
15
+ display: flex; justify-content: center; align-items: center;
16
+ padding: 24px 16px 24vh; overflow-y: auto;
17
+ font-family: ${SANS}; color: #ededed; -webkit-font-smoothing: antialiased;
18
+ }
19
+ .shell { width: 100%; max-width: 960px; min-width: 0; margin: auto; filter: drop-shadow(0 24px 48px rgba(0,0,0,0.5)); }
20
+
21
+ /* ---- folder tabs with curved notch ---- */
22
+ .tabs { display: flex; align-items: flex-end; height: 48px; position: relative; }
23
+ .tab {
24
+ height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px;
25
+ background: ${BG}; border: 1px solid ${BORDER}; border-bottom: 0;
26
+ position: relative; z-index: 1;
27
+ }
28
+ .tab.left { border-radius: 16px 0 0 0; border-right: 0; }
29
+ .tab.right { border-radius: 0 16px 0 0; border-left: 0; }
30
+ .curve { width: 48px; height: 48px; flex-shrink: 0; position: relative; z-index: 1; display: block; }
31
+ .gap { flex: 1; height: 36px; align-self: flex-end; background: ${BG}; border-top: 1px solid ${BORDER}; position: relative; top: 0; }
32
+ .count { font-size: 14px; color: #ededed; font-variant-numeric: tabular-nums; min-width: 2.4em; text-align: center; }
33
+ .nb {
34
+ all: unset; cursor: pointer; width: 24px; height: 24px; border-radius: 50%;
35
+ display: inline-grid; place-items: center; color: #a1a1a1; background: #1a1a1a;
36
+ }
37
+ .nb:hover:not([disabled]) { color: #fff; background: #262626; }
38
+ .nb[disabled] { opacity: 0.35; cursor: default; }
39
+ .nb svg { width: 12px; height: 12px; }
40
+ .ver { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: #a1a1a1;
41
+ border: 1px solid ${BORDER}; border-radius: 999px; padding: 5px 12px 5px 10px; }
42
+ .ver .logo-s { width: 16px; height: 16px; display: inline-grid; }
43
+ .ver .logo-s svg { width: 16px; height: 16px; }
44
+
45
+ /* ---- body ---- */
46
+ .dialog {
47
+ background: ${BG}; border: 1px solid ${BORDER}; border-top: 0;
48
+ border-radius: 0 0 16px 16px; padding: 4px 16px 16px; position: relative;
49
+ }
50
+ /* Orvyn brand line along the bottom edge */
51
+ .dialog::after {
52
+ content: ""; position: absolute; left: 24px; right: 24px; bottom: -1px; height: 2px; border-radius: 2px;
53
+ background: linear-gradient(90deg, #fde68a, #fb923c, #e11d48);
54
+ }
55
+ .head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 0 12px; }
56
+ .label {
57
+ font-family: ${MONO}; font-size: 14px; font-weight: 600; color: #ff6166;
58
+ background: rgba(255, 77, 79, 0.15); border-radius: 6px; padding: 3px 8px;
59
+ }
60
+ .tools { display: flex; gap: 8px; }
61
+ .tb {
62
+ all: unset; cursor: pointer; width: 32px; height: 32px; border-radius: 50%;
63
+ display: inline-grid; place-items: center; color: #a1a1a1; border: 1px solid ${BORDER}; background: #111;
64
+ }
65
+ .tb:hover { color: #fff; background: #1f1f1f; border-color: #fb923c; }
66
+ .tb:focus-visible, .nb:focus-visible, .op:focus-visible, .badge-btn:focus-visible { outline: 2px solid #fdba74; outline-offset: 2px; }
67
+ .tb svg { width: 16px; height: 16px; }
68
+ .title { font-size: 18px; line-height: 1.5; font-weight: 500; color: #ff6166; padding: 4px 0 16px; word-break: break-word; }
69
+ .title .x { margin-right: 6px; }
70
+ .sub { margin: -10px 0 16px; font-size: 13px; color: #a1a1a1; font-family: ${MONO}; word-break: break-word; }
71
+
72
+ /* ---- code frame (React style) ---- */
73
+ .frame { border: 1px solid ${BORDER}; border-radius: 8px; background: #000; overflow: hidden; min-width: 0; }
74
+ .fh {
75
+ display: flex; align-items: center; gap: 10px; padding: 12px 16px;
76
+ border-bottom: 1px solid #1f1f1f; font-family: ${MONO}; font-size: 13px; color: #ededed;
77
+ }
78
+ .fh .ic { font: 700 8px/1 ${SANS}; color: #fff; background: linear-gradient(135deg, #fb923c, #e11d48); border-radius: 3px; padding: 4px 3px; }
79
+ .fh .p { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
80
+ .fh .p span { color: #a1a1a1; }
81
+ .op { all: unset; cursor: pointer; color: #a1a1a1; display: inline-grid; place-items: center; }
82
+ .op:hover { color: #fb923c; }
83
+ .op svg { width: 16px; height: 16px; }
84
+ pre {
85
+ padding: 16px; overflow-x: auto; white-space: pre;
86
+ font-family: ${MONO}; font-size: 13px; line-height: 1.6; color: #ededed;
87
+ }
88
+ .dim { color: #737373; }
89
+ .red { color: #ff6166; }
90
+
91
+ /* ---- hint (Orvyn extra, kept small) ---- */
92
+ .hint { margin-top: 12px; font-size: 13px; line-height: 1.6; color: #a1a1a1; }
93
+ .hint b { color: #fb923c; font-weight: 600; }
94
+ code { font-family: ${MONO}; font-size: 12px; color: #ededed; background: #1a1a1a; padding: 1px 5px; border-radius: 4px; }
95
+
96
+ /* ---- dev badge: always in the corner while developing (like Next.js "N") ---- */
97
+ .badge-btn {
98
+ all: unset; cursor: pointer; user-select: none; -webkit-user-select: none; position: fixed; left: 20px; bottom: 20px; z-index: 2147483647;
99
+ display: inline-flex; align-items: center; gap: 10px; border-radius: 999px;
100
+ font: 600 14px ${SANS}; color: #fff;
101
+ }
102
+ /* just the ring with a black center and white dot, no tile, no shadow */
103
+ .badge-btn .logo { width: 40px; height: 40px; display: grid; place-items: center; }
104
+ .badge-btn .logo svg { width: 40px; height: 40px; overflow: visible; }
105
+ /* with errors: red pill, logo in a lighter circle, white "1 Issue" (like Next.js) */
106
+ .badge-btn.issues { gap: 12px; padding: 4px 18px 4px 4px; background: rgba(0, 0, 0, 0.8);
107
+ border: 1.5px solid #ff0000; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
108
+ .badge-btn.issues:hover { background: rgba(0, 0, 0, 0.9); }
109
+ .badge-btn.issues .logo { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.16); }
110
+ .badge-btn.issues .logo svg { width: 26px; height: 26px; }
111
+ .pill-count.chip { font: 500 15px ${SANS}; color: #fff; }
112
+ /* page-load intro: the brand animation played once (arcs draw, ring turns, dot pops) */
113
+ .intro .logo { animation: o-tile 0.35s ease-out both; }
114
+ .intro.tap .logo { animation: none; }
115
+ .intro .s { stroke-dasharray: 29.3; stroke-dashoffset: 29.3; animation: o-draw 0.6s cubic-bezier(.65,0,.35,1) forwards; }
116
+ .intro .s2 { animation-delay: 0.12s; }
117
+ .intro .s3 { animation-delay: 0.24s; }
118
+ .intro .ring { transform-box: fill-box; transform-origin: center; animation: o-spin 0.8s 0.45s cubic-bezier(.65,0,.35,1) both; }
119
+ .intro .dot { transform-box: fill-box; transform-origin: center; transform: scale(0); animation: o-pop 0.45s 0.75s cubic-bezier(.34,1.56,.64,1) forwards; }
120
+ @keyframes o-tile { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
121
+ @keyframes o-draw { to { stroke-dashoffset: 0; } }
122
+ @keyframes o-spin { from { transform: rotate(-120deg); } to { transform: rotate(0deg); } }
123
+ @keyframes o-pop { 0% { transform: scale(0); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
124
+ @media (prefers-reduced-motion: reduce) {
125
+ .intro .logo, .intro .s, .intro .ring, .intro .dot { animation: none !important; stroke-dashoffset: 0 !important; transform: none !important; }
126
+ }
127
+ /* ---- dev tools menu (like the Next.js indicator menu) ---- */
128
+ .menu {
129
+ position: fixed; z-index: 2147483647; width: 300px;
130
+ background: #0a0a0a; color: #ededed; border: 1px solid #262626; border-radius: 16px; overflow: hidden;
131
+ box-shadow: 0 16px 40px rgba(0,0,0,0.3); font: 400 15px/1.4 ${SANS};
132
+ animation: m-in 0.14s ease-out;
133
+ }
134
+ @keyframes m-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
135
+ .menu .grp { padding: 6px 0; }
136
+ .mi {
137
+ all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
138
+ padding: 10px 20px; cursor: default; color: #ededed; font: inherit;
139
+ }
140
+ button.mi { cursor: pointer; }
141
+ button.mi:hover, button.mi:focus-visible { background: #1a1a1a; }
142
+ .mi .v { color: #a1a1a1; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
143
+ .mi .v.link { color: #52a8ff; text-decoration: underline; text-underline-offset: 3px; }
144
+ .mi .v.bad { color: #fff; background: #e5484d; border-radius: 999px; padding: 0 8px; font-size: 13px; font-weight: 600; }
145
+ .mi .v.good { color: #45a557; }
146
+ .mi svg { width: 18px; height: 18px; color: #8f8f8f; flex-shrink: 0; }
147
+ .menu .foot-grp { border-top: 1px solid #262626; background: #000; padding: 6px 0; }
148
+ .mh { display: flex; align-items: center; gap: 8px; padding: 12px 16px 6px; color: #a1a1a1; font-size: 13px; }
149
+ .mh button { all: unset; cursor: pointer; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; }
150
+ .mh button:hover { background: #1a1a1a; color: #ededed; }
151
+ .mh svg { width: 14px; height: 14px; }
152
+ .kv { padding: 6px 20px; font-size: 13px; }
153
+ .kv .k { color: #8f8f8f; margin-bottom: 2px; }
154
+ .kv .val { font-family: ${MONO}; color: #ededed; word-break: break-all; }
155
+ .seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px 20px 10px; }
156
+ .seg button { all: unset; cursor: pointer; text-align: center; padding: 7px 0; border-radius: 8px; border: 1px solid #262626; font-size: 13px; color: #a1a1a1; }
157
+ .seg button[aria-pressed="true"] { color: #fff; border-color: #fb923c; background: rgba(251,146,60,0.1); }
158
+ .seg button:hover { color: #ededed; }
159
+ .pill-logo, .pill-count { all: unset; cursor: pointer; display: inline-flex; align-items: center; }
160
+ .pill-logo:focus-visible, .pill-count:focus-visible { outline: 2px solid #fdba74; outline-offset: 2px; border-radius: 999px; }
161
+ .toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #ededed; color: #0a0a0a;
162
+ font: 500 13px ${SANS}; padding: 8px 14px; border-radius: 8px; z-index: 2147483647; }
163
+
164
+ @media (max-width: 640px) {
165
+ .backdrop { padding: 12px 8px; }
166
+ .ver { display: none; }
167
+ .title { font-size: 16px; }
168
+ pre { font-size: 12px; padding: 12px; }
169
+ }
170
+ `;
171
+ const LOGO = `<svg viewBox="11 11 42 42" aria-hidden="true"><g class="ring"><path class="s s1" d="M33.05 17.04 A15 15 0 0 1 45.48 38.58" fill="none" stroke="#fde68a" stroke-width="9" stroke-linecap="round"/><path class="s s2" d="M44.44 40.39 A15 15 0 0 1 19.56 40.39" fill="none" stroke="#fb923c" stroke-width="9" stroke-linecap="round"/><path class="s s3" d="M18.52 38.58 A15 15 0 0 1 30.95 17.04" fill="none" stroke="#e11d48" stroke-width="9" stroke-linecap="round"/></g><circle cx="32" cy="32" r="11" fill="#0a0a0a"/><circle class="dot" cx="32" cy="32" r="3.4" fill="#fff"/></svg>`;
172
+ const MENU_ICON = {
173
+ chevron: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 3.5 4.5 4.5L6 12.5"/></svg>`,
174
+ back: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3.5 5.5 8l4.5 4.5"/></svg>`,
175
+ gear: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>`
176
+ };
177
+ const ICON = {
178
+ prev: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3 5 8l5 5"/></svg>`,
179
+ next: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 3 5 5-5 5"/></svg>`,
180
+ copy: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 5.5V3.75A1.25 1.25 0 0 0 9.25 2.5h-5.5A1.25 1.25 0 0 0 2.5 3.75v5.5a1.25 1.25 0 0 0 1.25 1.25H5.5"/></svg>`,
181
+ retry: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3h-3"/></svg>`,
182
+ min: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M4 8h8"/></svg>`,
183
+ close: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M4.5 4.5l7 7M11.5 4.5l-7 7"/></svg>`,
184
+ open: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9.5 2.5h4v4M13.5 2.5 8 8M12 9.5V12a1.5 1.5 0 0 1-1.5 1.5h-6A1.5 1.5 0 0 1 3 12V6a1.5 1.5 0 0 1 1.5-1.5H7"/></svg>`
185
+ };
186
+ function curve(side) {
187
+ const flip = side === "right" ? ` transform="matrix(-1 0 0 1 48 0)"` : "";
188
+ return `<svg class="curve" viewBox="0 0 48 48" preserveAspectRatio="none" aria-hidden="true"><g${flip}>
189
+ <path d="M0 0.5 C 20 0.5, 22 12.5, 48 12.5 L 48 48 L 0 48 Z" fill="${BG}"/>
190
+ <path d="M0 0.5 C 20 0.5, 22 12.5, 48 12.5" fill="none" stroke="${BORDER}" stroke-width="1"/>
191
+ </g></svg>`;
192
+ }
193
+ const KIND = {
194
+ render: "Runtime Error",
195
+ event: "Runtime Error",
196
+ async: "Unhandled Runtime Error",
197
+ start: "Runtime Error",
198
+ uncaught: "Unhandled Runtime Error"
199
+ };
200
+ function el(tag, attrs = {}, ...kids) {
201
+ const node = document.createElement(tag);
202
+ for (const [k, v] of Object.entries(attrs)) {
203
+ if (v === void 0 || v === false) continue;
204
+ if (k === "on") for (const [ev, fn] of Object.entries(v)) node.addEventListener(ev, fn);
205
+ else if (k === "class") node.className = v;
206
+ else if (k === "html") node.innerHTML = v;
207
+ else node.setAttribute(k, v === true ? "" : String(v));
208
+ }
209
+ for (const kid of kids) if (kid !== null && kid !== false && kid !== void 0) node.append(kid);
210
+ return node;
211
+ }
212
+ const s = (cls, text) => el("span", { class: cls }, text);
213
+ function rich(text) {
214
+ const out = el("span");
215
+ text.split(/(`[^`]+`)/).forEach((part) => {
216
+ out.append(part.startsWith("`") && part.endsWith("`") ? el("code", {}, part.slice(1, -1)) : part);
217
+ });
218
+ return out;
219
+ }
220
+ function errorText(err, lines) {
221
+ const out = [`${KIND[err.kind] ?? "Runtime Error"}: ${err.message}`];
222
+ if (err.detail) out.push(err.detail);
223
+ if (err.file) out.push(`
224
+ ${err.file} (${err.line}:${err.col || 1})${err.where ? ` @ ${err.where}` : ""}`);
225
+ const w = Math.max(...lines.map((l) => String(l.lineNo).length), 1);
226
+ for (const l of lines) out.push(`${l.active ? ">" : " "} ${String(l.lineNo).padStart(w)} | ${l.text}`);
227
+ return out.join("\n");
228
+ }
229
+ function frame(err, all) {
230
+ const lines = [...all];
231
+ while (lines.length && !lines[0].active && !lines[0].text.trim()) lines.shift();
232
+ while (lines.length && !lines[lines.length - 1].active && !lines[lines.length - 1].text.trim()) lines.pop();
233
+ if (!lines.length) return null;
234
+ const w = Math.max(...lines.map((l) => String(l.lineNo).length));
235
+ const pre = el("pre");
236
+ lines.forEach((l, i) => {
237
+ if (i) pre.append("\n");
238
+ if (l.active) {
239
+ pre.append(s("red", ">"), s("dim", ` ${String(l.lineNo).padStart(w)} |`), ` ${l.text}`);
240
+ const code = l.text;
241
+ const indent = code.length - code.trimStart().length;
242
+ const col = err.col ? err.col - 1 : indent;
243
+ pre.append("\n", s("dim", ` ${" ".repeat(w)} |`), ` ${" ".repeat(Math.max(0, col))}`, s("red", "^"));
244
+ } else {
245
+ pre.append(s("dim", ` ${String(l.lineNo).padStart(w)} | ${l.text}`));
246
+ }
247
+ });
248
+ return pre;
249
+ }
250
+ const CORNERS = ["bottom-left", "bottom-right", "top-left", "top-right"];
251
+ const store = {
252
+ get(key, session = false) {
253
+ try {
254
+ return (session ? sessionStorage : localStorage).getItem(key);
255
+ } catch {
256
+ return null;
257
+ }
258
+ },
259
+ set(key, value, session = false) {
260
+ try {
261
+ const s2 = session ? sessionStorage : localStorage;
262
+ value === null ? s2.removeItem(key) : s2.setItem(key, value);
263
+ } catch {
264
+ }
265
+ }
266
+ };
267
+ function cornerStyle(corner, offset = 20) {
268
+ const [v, h] = corner.split("-");
269
+ return `${v}: ${offset}px; ${h}: 20px; ${v === "top" ? "bottom" : "top"}: auto; ${h === "left" ? "right" : "left"}: auto;`;
270
+ }
271
+ function mountWebOverlay(api, info) {
272
+ if (typeof document === "undefined" || !document.body) return () => {
273
+ };
274
+ const host = document.createElement("orvyn-error-overlay");
275
+ host.setAttribute("data-orvyn-dev-overlay", "true");
276
+ const root = host.attachShadow ? host.attachShadow({ mode: "open" }) : host;
277
+ root.append(el("style", {}, CSS));
278
+ const mountPoint = document.createElement("div");
279
+ root.append(mountPoint);
280
+ document.body.append(host);
281
+ const toast = (text) => {
282
+ const t = el("div", { class: "toast" }, text);
283
+ root.append(t);
284
+ setTimeout(() => t.remove(), 1400);
285
+ };
286
+ const menu = signal(null, "__orvyn_devtools_menu");
287
+ const corner = signal(CORNERS.includes(store.get("orvyn:devtools:corner") || "") ? store.get("orvyn:devtools:corner") : "bottom-left", "__orvyn_devtools_corner");
288
+ const hidden = signal(store.get("orvyn:devtools:hidden", true) === "1", "__orvyn_devtools_hidden");
289
+ const closeMenu = () => menu.set(null);
290
+ const onDocClick = (e) => {
291
+ if (menu.get() && !e.composedPath().includes(host)) closeMenu();
292
+ };
293
+ const onKey = (e) => {
294
+ if (e.key === "Escape" && menu.get()) closeMenu();
295
+ };
296
+ document.addEventListener("click", onDocClick, true);
297
+ document.addEventListener("keydown", onKey);
298
+ function renderMenu(state) {
299
+ const view = menu.get();
300
+ if (!view) return null;
301
+ const where = corner.get();
302
+ const box = el("div", { class: "menu", role: "menu", style: cornerStyle(where, 76) });
303
+ const current = info?.() ?? null;
304
+ const total = state?.issues.length ?? 0;
305
+ const row = (label, value, onClick, chevron = false) => {
306
+ const kids = [el("span", {}, label)];
307
+ if (value !== null) kids.push(typeof value === "string" ? el("span", { class: "v" }, value) : value);
308
+ if (chevron) kids.push(el("span", { html: MENU_ICON.chevron }));
309
+ return onClick ? el("button", { class: "mi", type: "button", role: "menuitem", on: { click: onClick } }, ...kids) : el("div", { class: "mi" }, ...kids);
310
+ };
311
+ const header = (title) => el(
312
+ "div",
313
+ { class: "mh" },
314
+ el("button", { type: "button", "aria-label": "Back", html: MENU_ICON.back, on: { click: () => menu.set("main") } }),
315
+ title
316
+ );
317
+ if (view === "main") {
318
+ box.append(el(
319
+ "div",
320
+ { class: "grp" },
321
+ row(
322
+ "Issues",
323
+ el("span", { class: total ? "v bad" : "v good" }, total ? String(total) : "None"),
324
+ total ? () => {
325
+ closeMenu();
326
+ api.open();
327
+ } : void 0
328
+ ),
329
+ row("Screen", current?.screen ?? "\u2014"),
330
+ row("Runtime", el("a", { class: "v link", href: "https://vite.dev", target: "_blank", rel: "noreferrer" }, "Web \xB7 Vite")),
331
+ row("Screen Info", null, () => menu.set("info"), true)
332
+ ), el(
333
+ "div",
334
+ { class: "foot-grp" },
335
+ el(
336
+ "button",
337
+ { class: "mi", type: "button", role: "menuitem", on: { click: () => menu.set("prefs") } },
338
+ el("span", {}, "Preferences"),
339
+ el("span", { html: MENU_ICON.gear })
340
+ )
341
+ ));
342
+ } else if (view === "info") {
343
+ const kv = (k, v) => el("div", { class: "kv" }, el("div", { class: "k" }, k), el("div", { class: "val" }, v));
344
+ box.append(header("Screen Info"), el(
345
+ "div",
346
+ { class: "grp" },
347
+ kv("Screen", current?.screen ?? "\u2014"),
348
+ kv("URL", current?.url ?? "/"),
349
+ kv("Params", current && Object.keys(current.params).length ? JSON.stringify(current.params) : "none"),
350
+ kv("All screens", current?.screens.join(", ") || "\u2014")
351
+ ));
352
+ } else {
353
+ const labels = { "bottom-left": "Bottom left", "bottom-right": "Bottom right", "top-left": "Top left", "top-right": "Top right" };
354
+ const seg = el("div", { class: "seg" }, ...CORNERS.map((c) => el("button", {
355
+ type: "button",
356
+ "aria-pressed": String(c === where),
357
+ on: { click: () => {
358
+ corner.set(c);
359
+ store.set("orvyn:devtools:corner", c);
360
+ } }
361
+ }, labels[c])));
362
+ box.append(
363
+ header("Preferences"),
364
+ el("div", { class: "kv" }, el("div", { class: "k" }, "Position")),
365
+ seg,
366
+ el(
367
+ "div",
368
+ { class: "foot-grp" },
369
+ row("Hide dev tools for this session", null, () => {
370
+ hidden.set(true);
371
+ store.set("orvyn:devtools:hidden", "1", true);
372
+ closeMenu();
373
+ toast("Hidden until you open a new tab");
374
+ })
375
+ )
376
+ );
377
+ }
378
+ return box;
379
+ }
380
+ let justDragged = false;
381
+ function makeDraggable(node) {
382
+ node.style.touchAction = "none";
383
+ node.addEventListener("pointerdown", (down) => {
384
+ if (down.button !== 0) return;
385
+ const startX = down.clientX;
386
+ const startY = down.clientY;
387
+ let dragging = false;
388
+ const move = (e) => {
389
+ if (e.pointerId !== down.pointerId) return;
390
+ const dx = e.clientX - startX;
391
+ const dy = e.clientY - startY;
392
+ if (!dragging && Math.hypot(dx, dy) < 6) return;
393
+ if (!dragging) {
394
+ dragging = true;
395
+ node.style.transition = "none";
396
+ node.style.cursor = "grabbing";
397
+ if (menu.get()) closeMenu();
398
+ }
399
+ e.preventDefault();
400
+ node.style.transform = `translate(${dx}px, ${dy}px)`;
401
+ };
402
+ const up = (e) => {
403
+ if (e.pointerId !== down.pointerId) return;
404
+ window.removeEventListener("pointermove", move, true);
405
+ window.removeEventListener("pointerup", up, true);
406
+ window.removeEventListener("pointercancel", up, true);
407
+ if (!dragging) return;
408
+ justDragged = true;
409
+ setTimeout(() => {
410
+ justDragged = false;
411
+ }, 0);
412
+ const rect = node.getBoundingClientRect();
413
+ const cx = rect.left + rect.width / 2;
414
+ const cy = rect.top + rect.height / 2;
415
+ const next = `${cy < window.innerHeight / 2 ? "top" : "bottom"}-${cx < window.innerWidth / 2 ? "left" : "right"}`;
416
+ const before = rect;
417
+ node.style.transform = "";
418
+ node.setAttribute("style", cornerStyle(next) + "touch-action: none;");
419
+ const after = node.getBoundingClientRect();
420
+ node.style.transform = `translate(${before.left - after.left}px, ${before.top - after.top}px)`;
421
+ void node.offsetWidth;
422
+ node.style.transition = "transform 0.25s cubic-bezier(.2,.8,.2,1)";
423
+ node.style.transform = "";
424
+ setTimeout(() => {
425
+ store.set("orvyn:devtools:corner", next);
426
+ corner.set(next);
427
+ }, 260);
428
+ };
429
+ window.addEventListener("pointermove", move, true);
430
+ window.addEventListener("pointerup", up, true);
431
+ window.addEventListener("pointercancel", up, true);
432
+ });
433
+ return node;
434
+ }
435
+ let animation = " intro";
436
+ const intro = () => {
437
+ const cls = animation;
438
+ animation = "";
439
+ return cls;
440
+ };
441
+ const stop = effect(() => {
442
+ const state = api.state;
443
+ mountPoint.replaceChildren();
444
+ const place = cornerStyle(corner.get());
445
+ const toggleMenu = (e) => {
446
+ e.stopPropagation();
447
+ if (justDragged) return;
448
+ animation = " intro tap";
449
+ menu.set(menu.get() ? null : "main");
450
+ };
451
+ const hasOpenError = Boolean(state && state.issues.length && !state.minimized);
452
+ if (hidden.get() && !hasOpenError) return;
453
+ if (!hasOpenError) {
454
+ const m = renderMenu(state);
455
+ if (m) mountPoint.append(m);
456
+ }
457
+ if (!state || !state.issues.length) {
458
+ mountPoint.append(
459
+ makeDraggable(el("button", {
460
+ class: `badge-btn${intro()}`,
461
+ type: "button",
462
+ "aria-label": "Open Orvyn dev tools",
463
+ "aria-haspopup": "menu",
464
+ "aria-expanded": String(Boolean(menu.get())),
465
+ style: place,
466
+ on: { click: toggleMenu }
467
+ }, el("span", { class: "logo", html: LOGO })))
468
+ );
469
+ return;
470
+ }
471
+ const { issues, index, minimized } = state;
472
+ const total = issues.length;
473
+ if (minimized) {
474
+ mountPoint.append(makeDraggable(el(
475
+ "div",
476
+ { class: `badge-btn issues${intro()}`, style: place },
477
+ el(
478
+ "button",
479
+ { class: "pill-logo", type: "button", "aria-label": "Open Orvyn dev tools", on: { click: toggleMenu } },
480
+ el("span", { class: "logo", html: LOGO })
481
+ ),
482
+ el(
483
+ "button",
484
+ { class: "pill-count chip", type: "button", "aria-label": "Show errors", on: { click: (e) => {
485
+ e.stopPropagation();
486
+ if (justDragged) return;
487
+ closeMenu();
488
+ api.open();
489
+ } } },
490
+ `${total} ${total === 1 ? "Issue" : "Issues"}`
491
+ )
492
+ )));
493
+ return;
494
+ }
495
+ const err = issues[Math.min(index, total - 1)];
496
+ const lines = api.snippet(err.file, err.line, 2);
497
+ const tip = api.tip(err.message);
498
+ const copy = () => {
499
+ try {
500
+ navigator.clipboard?.writeText(errorText(err, lines)).then(() => toast("Copied"), () => toast("Couldn't copy"));
501
+ } catch {
502
+ toast("Couldn't copy");
503
+ }
504
+ };
505
+ const openInEditor = () => {
506
+ fetch(`/__open-in-editor?file=${encodeURIComponent(`${err.file}:${err.line}:${err.col || 1}`)}`).catch(() => toast("Couldn't open the editor"));
507
+ };
508
+ const tabs = el(
509
+ "div",
510
+ { class: "tabs" },
511
+ el(
512
+ "div",
513
+ { class: "tab left" },
514
+ el("button", { class: "nb", type: "button", "aria-label": "Previous error", disabled: total < 2, html: ICON.prev, on: { click: api.prev } }),
515
+ el("span", { class: "count" }, `${index + 1}/${total}`),
516
+ el("button", { class: "nb", type: "button", "aria-label": "Next error", disabled: total < 2, html: ICON.next, on: { click: api.next } })
517
+ ),
518
+ el("span", { html: curve("left") }),
519
+ el("div", { class: "gap" }),
520
+ el("span", { html: curve("right") }),
521
+ el(
522
+ "div",
523
+ { class: "tab right" },
524
+ el("span", { class: "ver" }, el("span", { class: "logo-s", html: LOGO }), `Orvyn ${VERSION}`)
525
+ )
526
+ );
527
+ const head = el(
528
+ "div",
529
+ { class: "head" },
530
+ el("span", { class: "label" }, KIND[err.kind] ?? "Runtime Error"),
531
+ el(
532
+ "div",
533
+ { class: "tools" },
534
+ el("button", { class: "tb", type: "button", title: "Copy error", "aria-label": "Copy error", html: ICON.copy, on: { click: copy } }),
535
+ el("button", { class: "tb", type: "button", title: "Try again", "aria-label": "Try again", html: ICON.retry, on: { click: api.retry } }),
536
+ el("button", { class: "tb", type: "button", title: "Minimize", "aria-label": "Minimize", html: ICON.min, on: { click: api.minimize } }),
537
+ el("button", { class: "tb", type: "button", title: "Close (Esc)", "aria-label": "Close", html: ICON.close, on: { click: api.close } })
538
+ )
539
+ );
540
+ const code = frame(err, lines);
541
+ const body = el(
542
+ "div",
543
+ { class: "dialog" },
544
+ head,
545
+ el("h1", { class: "title" }, el("span", { class: "x" }, "\xD7"), err.message),
546
+ err.detail ? el("p", { class: "sub" }, err.detail) : null,
547
+ err.file ? el(
548
+ "div",
549
+ { class: "frame" },
550
+ el(
551
+ "div",
552
+ { class: "fh" },
553
+ el("span", { class: "ic" }, "ORV"),
554
+ el("span", { class: "p" }, `${err.file} `, el("span", {}, `(${err.line}:${err.col || 1})${err.where ? ` @ ${err.where}` : ""}`)),
555
+ el("button", { class: "op", type: "button", title: "Open in editor", "aria-label": "Open in editor", html: ICON.open, on: { click: openInEditor } })
556
+ ),
557
+ code
558
+ ) : null,
559
+ tip ? el("p", { class: "hint" }, el("b", {}, "Hint: "), rich(tip)) : null
560
+ );
561
+ mountPoint.append(el("div", {
562
+ class: "backdrop",
563
+ on: { click: (e) => {
564
+ if (e.target === e.currentTarget) api.minimize();
565
+ } }
566
+ }, el("div", { class: "shell", role: "dialog", "aria-modal": "true", "aria-label": err.message }, tabs, body)));
567
+ });
568
+ return () => {
569
+ stop();
570
+ document.removeEventListener("click", onDocClick, true);
571
+ document.removeEventListener("keydown", onKey);
572
+ host.remove();
573
+ };
574
+ }
575
+ export {
576
+ errorText,
577
+ mountWebOverlay
578
+ };
@@ -0,0 +1,94 @@
1
+ import { createVNode } from "../runtime/vnode.js";
2
+ function createModal(props, children) {
3
+ const { open, onClose, title, ...style } = props;
4
+ if (!open) return [];
5
+ return createVNode("div", {
6
+ key: "orvyn-modal",
7
+ nativeRole: "modal",
8
+ flex: true,
9
+ align: "center",
10
+ justify: "center",
11
+ padding: 16,
12
+ position: "fixed",
13
+ inset: "0",
14
+ zIndex: 1e3,
15
+ bg: "rgba(0,0,0,0.45)",
16
+ // a tap on the dark area closes; taps inside the card don't
17
+ onClick: (event) => {
18
+ if (event?.target === event?.currentTarget) onClose?.();
19
+ },
20
+ onKeydown: (event) => {
21
+ if (event?.key === "Escape") onClose?.();
22
+ }
23
+ }, [
24
+ createVNode("div", {
25
+ role: "dialog",
26
+ "aria-modal": "true",
27
+ "aria-label": String(title ?? "Dialog"),
28
+ tabindex: "-1",
29
+ flex: true,
30
+ direction: "column",
31
+ gap: 12,
32
+ padding: 20,
33
+ radius: 16,
34
+ width: "100%",
35
+ maxWidth: 420,
36
+ bg: "bg",
37
+ ...style
38
+ }, [
39
+ ...title ? [createVNode("h2", { size: 22 }, [String(title)])] : [],
40
+ ...children,
41
+ createVNode("button", { type: "button", nativeRole: "close", onClick: () => onClose?.() }, ["Close"])
42
+ ])
43
+ ]);
44
+ }
45
+ function createTabs(props, options) {
46
+ const { value, onInput, ...style } = props;
47
+ return createVNode(
48
+ "div",
49
+ { flex: true, direction: "row", gap: 4, role: "tablist", ...style },
50
+ Array.from(options ?? [], (option) => {
51
+ const name = String(option);
52
+ const on = name === String(value);
53
+ return createVNode("button", {
54
+ key: name,
55
+ type: "button",
56
+ role: "tab",
57
+ "aria-selected": on ? "true" : "false",
58
+ paddingX: 14,
59
+ paddingY: 10,
60
+ radius: 8,
61
+ grow: 1,
62
+ bg: on ? "primary" : "card",
63
+ color: on ? "onPrimary" : "text",
64
+ onClick: () => onInput({ target: { value: name } })
65
+ }, [name]);
66
+ })
67
+ );
68
+ }
69
+ function createMap(props) {
70
+ const { latitude, longitude, zoom = 14, height = 240, title, ...style } = props;
71
+ const lat = Number(latitude);
72
+ const lon = Number(longitude);
73
+ if (latitude === null || latitude === void 0 || longitude === null || longitude === void 0 || !(Math.abs(lat) <= 90) || !(Math.abs(lon) <= 180)) return [];
74
+ const level = Math.min(19, Math.max(1, Number(zoom) || 14));
75
+ const half = 180 / 2 ** level;
76
+ const box = [lon - half, lat - half / 2, lon + half, lat + half / 2].map((n) => n.toFixed(6)).join(",");
77
+ return createVNode("iframe", {
78
+ src: `https://www.openstreetmap.org/export/embed.html?bbox=${encodeURIComponent(box)}&layer=mapnik&marker=${lat}%2C${lon}`,
79
+ title: String(title ?? "Map"),
80
+ loading: "lazy",
81
+ nativeRole: "map",
82
+ "data-place": `${lat},${lon},${level}`,
83
+ width: "100%",
84
+ border: "1px solid border",
85
+ radius: 12,
86
+ height,
87
+ ...style
88
+ }, []);
89
+ }
90
+ export {
91
+ createMap,
92
+ createModal,
93
+ createTabs
94
+ };