orvyn-lang 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUIDE.md +149 -0
- package/LANGUAGE.md +744 -27
- package/README.md +211 -250
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +186 -10
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +102 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +428 -57
- package/src/lang/device.js +41 -0
- package/src/lang/doctor.js +60 -0
- package/src/lang/env.js +27 -0
- package/src/lang/errors.js +513 -0
- package/src/lang/form.js +69 -8
- package/src/lang/index.js +2 -1
- package/src/lang/lexer.js +2 -0
- package/src/lang/list.js +44 -0
- package/src/lang/native/android/MainActivity.kt +43 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +154 -7
- package/src/lang/native/android/OrvynRenderer.kt +518 -44
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/build.js +130 -60
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +266 -4
- package/src/lang/native/ios/OrvynViews.swift +429 -34
- package/src/lang/native/ios.js +75 -2
- package/src/lang/native-runtime.js +406 -56
- package/src/lang/page.js +52 -0
- package/src/lang/parser.js +243 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +11 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +792 -10
- package/src/lang/runtime.js +362 -52
- package/src/lang/select.js +13 -0
- package/src/lang/server-code.js +233 -0
- package/src/lang/server-export.js +78 -0
- package/src/lang/server-libs.js +53 -0
- package/src/lang/server.js +409 -0
- package/src/lang/test-runner.js +134 -0
- package/src/lang/types.js +312 -0
- package/src/lang/vite-plugin.js +82 -3
- package/src/lang/web-overlay.js +578 -0
- package/src/lang/widgets.js +94 -0
- package/src/lang/words.js +38 -0
- package/src/runtime/mount.js +116 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +11 -1
- package/src/styling/fluid.js +91 -4
- package/src/styling/spec.js +306 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { signal } from "../core/signal.js";
|
|
2
|
+
const STYLE_SPEC = {
|
|
3
|
+
// Layout & sizing (all platforms)
|
|
4
|
+
width: { support: "all" },
|
|
5
|
+
height: { support: "all" },
|
|
6
|
+
minWidth: { support: "all" },
|
|
7
|
+
maxWidth: { support: "all" },
|
|
8
|
+
minHeight: { support: "all" },
|
|
9
|
+
maxHeight: { support: "all" },
|
|
10
|
+
padding: { support: "all" },
|
|
11
|
+
paddingX: { support: "all" },
|
|
12
|
+
paddingY: { support: "all" },
|
|
13
|
+
margin: { support: "all" },
|
|
14
|
+
gap: { support: "all" },
|
|
15
|
+
align: { support: "all" },
|
|
16
|
+
justify: { support: "all" },
|
|
17
|
+
center: { support: "all" },
|
|
18
|
+
wrap: { support: "all" },
|
|
19
|
+
scroll: { support: "all" },
|
|
20
|
+
grow: { support: "all" },
|
|
21
|
+
flex: { support: "all" },
|
|
22
|
+
direction: { support: "all" },
|
|
23
|
+
// Visual appearance (all platforms)
|
|
24
|
+
bg: { support: "all" },
|
|
25
|
+
color: { support: "all" },
|
|
26
|
+
radius: { support: "all" },
|
|
27
|
+
border: { support: "all" },
|
|
28
|
+
shadow: { support: "all" },
|
|
29
|
+
opacity: { support: "all" },
|
|
30
|
+
// Typography & direction (all platforms)
|
|
31
|
+
size: { support: "all" },
|
|
32
|
+
weight: { support: "all" },
|
|
33
|
+
fontWeight: { support: "all" },
|
|
34
|
+
font: { support: "all" },
|
|
35
|
+
lineHeight: { support: "all" },
|
|
36
|
+
textAlign: { support: "all" },
|
|
37
|
+
rtl: { support: "all" },
|
|
38
|
+
// Interactive & validation states (all platforms)
|
|
39
|
+
disabled: { support: "all" },
|
|
40
|
+
loading: { support: "all" },
|
|
41
|
+
error: { support: "all" },
|
|
42
|
+
pressed: { support: "all" },
|
|
43
|
+
active: { support: "all" },
|
|
44
|
+
focus: { support: "all" },
|
|
45
|
+
// Web-specific extras (warn cleanly when used in native apps)
|
|
46
|
+
hover: { support: "web", note: "Touch devices have no pointer hover state" },
|
|
47
|
+
grid: { support: "web", note: "CSS Grid layout is web-only; use Row with wrap: true for cross-platform grids" },
|
|
48
|
+
columns: { support: "web", note: "CSS Grid columns are web-only; use Row with wrap: true on phones" },
|
|
49
|
+
rows: { support: "web", note: "CSS Grid rows are web-only" },
|
|
50
|
+
minItemWidth: { support: "web", note: "CSS Grid auto-fit width is web-only" },
|
|
51
|
+
basis: { support: "web", note: "flex-basis is web-only; use width on phones" },
|
|
52
|
+
shrink: { support: "web", note: "flex-shrink is web-only" },
|
|
53
|
+
display: { support: "web" },
|
|
54
|
+
overflow: { support: "web", note: "Use scroll: true for cross-platform scrolling" },
|
|
55
|
+
overflowX: { support: "web", note: 'Use scroll: "horizontal" for cross-platform scrolling' },
|
|
56
|
+
overflowY: { support: "web", note: "Use scroll: true for cross-platform scrolling" },
|
|
57
|
+
objectFit: { support: "web" },
|
|
58
|
+
objectPosition: { support: "web" },
|
|
59
|
+
position: { support: "web", note: "Absolute/fixed CSS positioning is web-only" },
|
|
60
|
+
inset: { support: "web" },
|
|
61
|
+
top: { support: "web" },
|
|
62
|
+
right: { support: "web" },
|
|
63
|
+
bottom: { support: "web" },
|
|
64
|
+
left: { support: "web" },
|
|
65
|
+
zIndex: { support: "web" },
|
|
66
|
+
boxShadow: { support: "web", note: "Use shadow: 1..3 for cross-platform elevation" },
|
|
67
|
+
cursor: { support: "web" },
|
|
68
|
+
userSelect: { support: "web" },
|
|
69
|
+
pointerEvents: { support: "web" },
|
|
70
|
+
transform: { support: "web" },
|
|
71
|
+
transition: { support: "web" },
|
|
72
|
+
whiteSpace: { support: "web" },
|
|
73
|
+
letterSpacing: { support: "web" },
|
|
74
|
+
textDecoration: { support: "web" }
|
|
75
|
+
};
|
|
76
|
+
const NON_STYLE_PROPS = /* @__PURE__ */ new Set([
|
|
77
|
+
"children",
|
|
78
|
+
"key",
|
|
79
|
+
"class",
|
|
80
|
+
"className",
|
|
81
|
+
"hydrate",
|
|
82
|
+
"resume",
|
|
83
|
+
"nativeRole",
|
|
84
|
+
"type",
|
|
85
|
+
"placeholder",
|
|
86
|
+
"value",
|
|
87
|
+
"checked",
|
|
88
|
+
"selected",
|
|
89
|
+
"src",
|
|
90
|
+
"href",
|
|
91
|
+
"alt",
|
|
92
|
+
"id",
|
|
93
|
+
"name",
|
|
94
|
+
"role",
|
|
95
|
+
"noValidate",
|
|
96
|
+
"required",
|
|
97
|
+
"minLength",
|
|
98
|
+
"maxLength",
|
|
99
|
+
"email",
|
|
100
|
+
"label",
|
|
101
|
+
"message",
|
|
102
|
+
"bind"
|
|
103
|
+
]);
|
|
104
|
+
const LIGHT_COLORS = {
|
|
105
|
+
bg: "#ffffff",
|
|
106
|
+
surface: "#f8fafc",
|
|
107
|
+
card: "#f1f5f9",
|
|
108
|
+
text: "#0f172a",
|
|
109
|
+
muted: "#64748b",
|
|
110
|
+
primary: "#007aff",
|
|
111
|
+
onPrimary: "#ffffff",
|
|
112
|
+
border: "#cbd5e1",
|
|
113
|
+
danger: "#b91c1c",
|
|
114
|
+
success: "#16a34a",
|
|
115
|
+
warning: "#f59e0b"
|
|
116
|
+
};
|
|
117
|
+
const DARK_COLORS = {
|
|
118
|
+
bg: "#0b0f19",
|
|
119
|
+
surface: "#111827",
|
|
120
|
+
card: "#1e293b",
|
|
121
|
+
text: "#f8fafc",
|
|
122
|
+
muted: "#94a3b8",
|
|
123
|
+
primary: "#3b82f6",
|
|
124
|
+
onPrimary: "#ffffff",
|
|
125
|
+
border: "#334155",
|
|
126
|
+
danger: "#f87171",
|
|
127
|
+
success: "#4ade80",
|
|
128
|
+
warning: "#fbbf24"
|
|
129
|
+
};
|
|
130
|
+
const DEFAULT_SPACING = {
|
|
131
|
+
xs: 4,
|
|
132
|
+
sm: 8,
|
|
133
|
+
md: 16,
|
|
134
|
+
lg: 24,
|
|
135
|
+
xl: 32
|
|
136
|
+
};
|
|
137
|
+
const DEFAULT_TEXT_SIZES = {
|
|
138
|
+
caption: 13,
|
|
139
|
+
body: 17,
|
|
140
|
+
subtitle: 20,
|
|
141
|
+
title: 28
|
|
142
|
+
};
|
|
143
|
+
function systemPrefersDark() {
|
|
144
|
+
try {
|
|
145
|
+
return typeof globalThis.matchMedia === "function" && globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function buildTheme(mode, overrides = {}) {
|
|
151
|
+
const dark = mode === "dark" || mode === "system" && systemPrefersDark();
|
|
152
|
+
const base = dark ? DARK_COLORS : LIGHT_COLORS;
|
|
153
|
+
return {
|
|
154
|
+
mode,
|
|
155
|
+
dark,
|
|
156
|
+
colors: { ...base, ...overrides },
|
|
157
|
+
spacing: { ...DEFAULT_SPACING },
|
|
158
|
+
textSizes: { ...DEFAULT_TEXT_SIZES }
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const themeState = signal(buildTheme("light"), "__orvyn_theme");
|
|
162
|
+
let themeOverrides = {};
|
|
163
|
+
function setOrReadTheme(input) {
|
|
164
|
+
if (input === void 0) return themeState.get();
|
|
165
|
+
if (typeof input === "string") {
|
|
166
|
+
if (input !== "light" && input !== "dark" && input !== "system") {
|
|
167
|
+
throw new Error(`[Orvyn] theme("${input}") is not valid. Use "light", "dark", or "system".`);
|
|
168
|
+
}
|
|
169
|
+
const next = buildTheme(input, themeOverrides);
|
|
170
|
+
themeState.set(next);
|
|
171
|
+
return next;
|
|
172
|
+
}
|
|
173
|
+
if (input && typeof input === "object") {
|
|
174
|
+
const { mode, dark, ...palette } = input;
|
|
175
|
+
const resolvedMode = mode ?? (dark === true ? "dark" : dark === false ? "light" : themeState.get().mode);
|
|
176
|
+
themeOverrides = { ...themeOverrides, ...palette };
|
|
177
|
+
const next = buildTheme(resolvedMode, themeOverrides);
|
|
178
|
+
themeState.set(next);
|
|
179
|
+
return next;
|
|
180
|
+
}
|
|
181
|
+
return themeState.get();
|
|
182
|
+
}
|
|
183
|
+
const theme = Object.defineProperties(setOrReadTheme, {
|
|
184
|
+
mode: { get: () => themeState.get().mode, enumerable: true },
|
|
185
|
+
dark: { get: () => themeState.get().dark, enumerable: true },
|
|
186
|
+
colors: { get: () => themeState.get().colors, enumerable: true },
|
|
187
|
+
spacing: { get: () => themeState.get().spacing, enumerable: true },
|
|
188
|
+
textSizes: { get: () => themeState.get().textSizes, enumerable: true },
|
|
189
|
+
toggle: {
|
|
190
|
+
value: () => setOrReadTheme(themeState.get().dark ? "light" : "dark"),
|
|
191
|
+
enumerable: true
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const LIGHT_BGS = /* @__PURE__ */ new Set(["white", "#fff", "#ffffff", "surface", "card", "yellow", "transparent", "clear"]);
|
|
195
|
+
function autoButtonColor(bg, currentTheme = themeState.get()) {
|
|
196
|
+
if (typeof bg !== "string") return null;
|
|
197
|
+
const key = bg.trim().toLowerCase();
|
|
198
|
+
if (!key || key === "none") return null;
|
|
199
|
+
if (LIGHT_BGS.has(key) || key === currentTheme.colors.bg.toLowerCase() && !currentTheme.dark) {
|
|
200
|
+
return "#0f172a";
|
|
201
|
+
}
|
|
202
|
+
return "#ffffff";
|
|
203
|
+
}
|
|
204
|
+
function resetTheme() {
|
|
205
|
+
themeOverrides = {};
|
|
206
|
+
themeState.set(buildTheme("light"));
|
|
207
|
+
}
|
|
208
|
+
function subscribeTheme(fn) {
|
|
209
|
+
return themeState.subscribe(fn);
|
|
210
|
+
}
|
|
211
|
+
const COLOR_PROPS = /* @__PURE__ */ new Set(["bg", "color"]);
|
|
212
|
+
const SPACE_PROPS = /* @__PURE__ */ new Set(["padding", "paddingX", "paddingY", "margin", "gap", "radius"]);
|
|
213
|
+
const FONT_ALIASES = {
|
|
214
|
+
sans: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif',
|
|
215
|
+
serif: 'Georgia, Cambria, "Times New Roman", Times, serif',
|
|
216
|
+
mono: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace"
|
|
217
|
+
};
|
|
218
|
+
function resolveThemeToken(prop, value, currentTheme = themeState.get()) {
|
|
219
|
+
if (typeof value !== "string") return value;
|
|
220
|
+
const key = value.trim();
|
|
221
|
+
if (COLOR_PROPS.has(prop) && Object.hasOwn(currentTheme.colors, key)) {
|
|
222
|
+
return currentTheme.colors[key];
|
|
223
|
+
}
|
|
224
|
+
if (prop === "border") {
|
|
225
|
+
return key.split(/\s+/).map(
|
|
226
|
+
(part) => Object.hasOwn(currentTheme.colors, part) ? currentTheme.colors[part] : part
|
|
227
|
+
).join(" ");
|
|
228
|
+
}
|
|
229
|
+
if (SPACE_PROPS.has(prop) && Object.hasOwn(currentTheme.spacing, key)) {
|
|
230
|
+
return currentTheme.spacing[key];
|
|
231
|
+
}
|
|
232
|
+
if (prop === "size" && Object.hasOwn(currentTheme.textSizes, key)) {
|
|
233
|
+
return currentTheme.textSizes[key];
|
|
234
|
+
}
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
function resolveFontFamily(value, target) {
|
|
238
|
+
if (typeof value !== "string" || !value.trim()) return null;
|
|
239
|
+
const trimmed = value.trim();
|
|
240
|
+
if (target === "web") return FONT_ALIASES[trimmed] ?? trimmed;
|
|
241
|
+
return trimmed;
|
|
242
|
+
}
|
|
243
|
+
const emittedWarnings = /* @__PURE__ */ new Set();
|
|
244
|
+
let warningHandler = null;
|
|
245
|
+
function setStyleWarningHandler(fn) {
|
|
246
|
+
warningHandler = fn;
|
|
247
|
+
emittedWarnings.clear();
|
|
248
|
+
}
|
|
249
|
+
function clearStyleWarnings() {
|
|
250
|
+
emittedWarnings.clear();
|
|
251
|
+
}
|
|
252
|
+
function closestStyleProp(name) {
|
|
253
|
+
const lower = name.toLowerCase();
|
|
254
|
+
const aliases = {
|
|
255
|
+
colour: "color",
|
|
256
|
+
background: "bg",
|
|
257
|
+
backgroundcolor: "bg",
|
|
258
|
+
fontsize: "size",
|
|
259
|
+
fontweight: "weight",
|
|
260
|
+
fontfamily: "font",
|
|
261
|
+
borderradius: "radius",
|
|
262
|
+
textalign: "textAlign",
|
|
263
|
+
lineheight: "lineHeight",
|
|
264
|
+
maxwidth: "maxWidth",
|
|
265
|
+
minwidth: "minWidth",
|
|
266
|
+
maxheight: "maxHeight",
|
|
267
|
+
minheight: "minHeight",
|
|
268
|
+
paddingx: "paddingX",
|
|
269
|
+
paddingy: "paddingY"
|
|
270
|
+
};
|
|
271
|
+
if (aliases[lower]) return aliases[lower];
|
|
272
|
+
for (const candidate of Object.keys(STYLE_SPEC)) {
|
|
273
|
+
if (candidate.toLowerCase() === lower) return candidate;
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
function warnStyle(key, platform) {
|
|
278
|
+
if (NON_STYLE_PROPS.has(key) || key.startsWith("on") || key.startsWith("aria-")) return;
|
|
279
|
+
const spec = STYLE_SPEC[key];
|
|
280
|
+
let message = null;
|
|
281
|
+
if (!spec) {
|
|
282
|
+
const suggestion = closestStyleProp(key);
|
|
283
|
+
message = suggestion ? `[Orvyn style] Unknown style "${key}". Did you mean "${suggestion}"?` : `[Orvyn style] Unknown style "${key}". Check LANGUAGE.md for supported style props.`;
|
|
284
|
+
} else if (platform === "native" && spec.support === "web") {
|
|
285
|
+
message = spec.note ? `[Orvyn style] "${key}" is web-only (${spec.note}).` : `[Orvyn style] "${key}" is currently web-only and is ignored on iOS/Android.`;
|
|
286
|
+
}
|
|
287
|
+
if (!message) return;
|
|
288
|
+
const dedupeKey = `${platform}:${key}:${message}`;
|
|
289
|
+
if (emittedWarnings.has(dedupeKey)) return;
|
|
290
|
+
emittedWarnings.add(dedupeKey);
|
|
291
|
+
if (warningHandler) warningHandler(message);
|
|
292
|
+
else console.warn(message);
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
NON_STYLE_PROPS,
|
|
296
|
+
STYLE_SPEC,
|
|
297
|
+
autoButtonColor,
|
|
298
|
+
clearStyleWarnings,
|
|
299
|
+
resetTheme,
|
|
300
|
+
resolveFontFamily,
|
|
301
|
+
resolveThemeToken,
|
|
302
|
+
setStyleWarningHandler,
|
|
303
|
+
subscribeTheme,
|
|
304
|
+
theme,
|
|
305
|
+
warnStyle
|
|
306
|
+
};
|