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.
- package/GUIDE.md +49 -0
- package/LANGUAGE.md +81 -10
- package/package.json +1 -1
- package/src/cli/orvyn.js +25 -10
- package/src/lang/a11y.js +63 -13
- package/src/lang/codegen.js +192 -6
- package/src/lang/native/android/MainActivity.kt +22 -0
- package/src/lang/native/android/OrvynEngine.kt +22 -0
- package/src/lang/native/android/OrvynRenderer.kt +496 -50
- package/src/lang/native/assets.js +39 -0
- package/src/lang/native/build.js +12 -5
- package/src/lang/native/compatibility.js +57 -0
- package/src/lang/native/ios/OrvynEngine.swift +25 -0
- package/src/lang/native/ios/OrvynViews.swift +368 -35
- package/src/lang/native/ios.js +6 -0
- package/src/lang/native-runtime.js +138 -2
- package/src/lang/native-size.js +53 -0
- package/src/lang/page-files.js +71 -0
- package/src/lang/page.js +11 -0
- package/src/lang/parser.js +37 -2
- package/src/lang/prerender.js +1 -1
- package/src/lang/read-import.js +2 -1
- package/src/lang/runtime-shared.js +4 -0
- package/src/lang/runtime.js +48 -10
- package/src/lang/style-check.js +60 -0
- package/src/lang/types.js +6 -1
- package/src/lang/vite-plugin.js +27 -4
- package/src/lang/words.js +1 -1
- package/src/runtime/animations.js +24 -0
- package/src/runtime/appear.js +73 -0
- package/src/runtime/marquee.js +57 -0
- package/src/runtime/mount.js +4 -0
- package/src/runtime/style.js +43 -12
- package/src/styling/fluid.js +41 -5
- package/src/styling/spec.js +23 -10
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { APPEAR_PRESET_NAMES } from "./parser.js";
|
|
2
|
+
import { closestStyleProp, NON_STYLE_PROPS, STYLE_SPEC } from "../styling/spec.js";
|
|
3
|
+
const ELEMENTS = /* @__PURE__ */ new Set(["Column", "Row", "Box", "Text", "Heading", "Button", "Form", "SubmitButton", "Image", "DatePicker", "TextArea", "Input", "Link", "Question", "List", "Map", "Select", "Tabs", "Modal", "Checkbox", "Switch"]);
|
|
4
|
+
const EXTRA = /* @__PURE__ */ new Set(["options", "rowHeight", "title", "place", "question", "layout", "latitude", "longitude", "zoom", "open", "onClose", "onTap", "onClick", "onChange", "onSubmit", "onError", "onHover", "onLeave", "onVisible"]);
|
|
5
|
+
const APPEAR = APPEAR_PRESET_NAMES;
|
|
6
|
+
const TIME = /^\d+(\.\d+)?s$/;
|
|
7
|
+
function checkMotion(key, value, custom = /* @__PURE__ */ new Set()) {
|
|
8
|
+
const [first, ...rest] = value.trim().split(/\s+/);
|
|
9
|
+
if (key === "appear" && (!(APPEAR.includes(first) || custom.has(first)) || rest.length > 2 || !rest.every((t) => TIME.test(t)))) {
|
|
10
|
+
const own = custom.size ? `, your own (${[...custom].join(", ")})` : "";
|
|
11
|
+
return `appear: "${value}" isn't understood. Use one of ${APPEAR.join(", ")}${own}, then an optional time and delay, like "fade-up 0.6s 0.2s". To make a new one: animation ${first || "pop"} { opacity: 0, y: 30 }`;
|
|
12
|
+
}
|
|
13
|
+
if (key === "animate" && (!["ease", "linear", "spring"].includes(first) || rest.length > 1 || !rest.every((t) => TIME.test(t)))) {
|
|
14
|
+
return `animate: "${value}" isn't understood. Use ease, linear or spring with an optional time, like "ease 0.4s"`;
|
|
15
|
+
}
|
|
16
|
+
if (key === "marquee" && !rest.concat(first).every((t) => t === "left" || t === "right" || TIME.test(t))) {
|
|
17
|
+
return `marquee: "${value}" isn't understood. Use left or right with an optional time for one loop, like "left 30s"`;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function checkStyleProps(program) {
|
|
22
|
+
const warnings = [];
|
|
23
|
+
const custom = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const decl of program.body) {
|
|
25
|
+
if (decl.kind === "Use") decl.names.forEach((name) => custom.add(name));
|
|
26
|
+
if (decl.kind === "Const" && decl.init.kind === "Call" && decl.init.callee.kind === "Ident" && decl.init.callee.name === "defineAnimation") custom.add(decl.name);
|
|
27
|
+
}
|
|
28
|
+
const visit = (node) => {
|
|
29
|
+
if (node.kind === "ViewIf") {
|
|
30
|
+
node.then.forEach(visit);
|
|
31
|
+
node.else?.forEach(visit);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (node.kind === "ViewFor") {
|
|
35
|
+
node.body.forEach(visit);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (ELEMENTS.has(node.name)) for (const prop of node.props) {
|
|
39
|
+
const key = prop.key;
|
|
40
|
+
if ((key === "appear" || key === "animate" || key === "marquee") && prop.value.kind === "Expr" && prop.value.expr.kind === "String" && prop.value.expr.parts.length === 1 && typeof prop.value.expr.parts[0] === "string") {
|
|
41
|
+
const problem = checkMotion(key, prop.value.expr.parts[0], custom);
|
|
42
|
+
if (problem) warnings.push({ line: prop.line, col: prop.col, message: problem });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (STYLE_SPEC[key] || NON_STYLE_PROPS.has(key) || EXTRA.has(key) || key.startsWith("aria-") || key.startsWith("data-")) continue;
|
|
46
|
+
const suggestion = closestStyleProp(key);
|
|
47
|
+
warnings.push({
|
|
48
|
+
line: prop.line,
|
|
49
|
+
col: prop.col,
|
|
50
|
+
message: suggestion ? `Unknown prop "${key}" on ${node.name}. Did you mean "${suggestion}"?` : `Unknown prop "${key}" on ${node.name}. Check the spelling or use a supported style prop.`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
node.children.forEach(visit);
|
|
54
|
+
};
|
|
55
|
+
for (const decl of program.body) if (decl.kind === "Screen") decl.body.forEach(visit);
|
|
56
|
+
return warnings;
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
checkStyleProps
|
|
60
|
+
};
|
package/src/lang/types.js
CHANGED
|
@@ -143,7 +143,7 @@ function checkTypes(program, resolve) {
|
|
|
143
143
|
const wanted = expr.args[0];
|
|
144
144
|
if (item.k === "record" && wanted?.kind === "Object") {
|
|
145
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));
|
|
146
|
+
} else expr.args.forEach((a) => infer(a, item));
|
|
147
147
|
return word === "count" ? { k: "number" } : word === "first" ? item : target;
|
|
148
148
|
}
|
|
149
149
|
if (word === "sortBy") {
|
|
@@ -183,6 +183,7 @@ function checkTypes(program, resolve) {
|
|
|
183
183
|
for (const part of expr.parts) if (typeof part !== "string") infer(part);
|
|
184
184
|
return { k: "text" };
|
|
185
185
|
case "Ident":
|
|
186
|
+
if (expr.name === "platform" && scopes.every((s) => !s.has("platform"))) return { k: "text" };
|
|
186
187
|
return lookup(expr.name);
|
|
187
188
|
case "List": {
|
|
188
189
|
const all = expr.items.map((i) => infer(i));
|
|
@@ -203,6 +204,10 @@ function checkTypes(program, resolve) {
|
|
|
203
204
|
}
|
|
204
205
|
case "Call":
|
|
205
206
|
return call(expr);
|
|
207
|
+
case "New":
|
|
208
|
+
infer(expr.callee);
|
|
209
|
+
expr.args.forEach((arg) => infer(arg));
|
|
210
|
+
return ANY;
|
|
206
211
|
case "Unary":
|
|
207
212
|
infer(expr.operand);
|
|
208
213
|
return expr.op === "!" ? { k: "yesno" } : { k: "number" };
|
package/src/lang/vite-plugin.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { compile, OrvynSyntaxError } from "./index.js";
|
|
4
5
|
import { loadEnv } from "./env.js";
|
|
5
6
|
import { readImportFrom } from "./read-import.js";
|
|
7
|
+
import { projectScreens, withPageFiles } from "./page-files.js";
|
|
6
8
|
const orvynRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
7
9
|
const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
8
10
|
const webRuntime = fileURLToPath(new URL(`./runtime${ext}`, import.meta.url));
|
|
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
|
+
}
|
|
9
18
|
function moduleNamespace(id, rootDir) {
|
|
10
19
|
const cleanId = id.split("?")[0];
|
|
11
20
|
const rel = relative(rootDir, cleanId).replace(/\\/g, "/");
|
|
@@ -78,18 +87,31 @@ function orvynLang(options = {}) {
|
|
|
78
87
|
if (allow) return { server: { fs: { allow: [...allow, orvynRoot] } } };
|
|
79
88
|
return { server: { fs: { allow: [process.cwd(), orvynRoot] } } };
|
|
80
89
|
},
|
|
90
|
+
transformIndexHtml() {
|
|
91
|
+
return orvynMarkers();
|
|
92
|
+
},
|
|
81
93
|
// compiled .orv code imports "orvyn/lang/runtime"; point it at this
|
|
82
94
|
// copy of Orvyn whatever the package is called (orvyn, orvyn-lang, ...)
|
|
83
|
-
resolveId(id) {
|
|
84
|
-
|
|
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;
|
|
85
105
|
},
|
|
86
106
|
transform(source, id) {
|
|
87
107
|
if (!id.endsWith(".orv")) return null;
|
|
88
108
|
try {
|
|
109
|
+
source = withPageFiles(source, id.split("?")[0]);
|
|
89
110
|
let code = compile(source, {
|
|
90
111
|
moduleId: moduleNamespace(id, rootDir),
|
|
91
112
|
env,
|
|
92
113
|
resolveImport: readImportFrom(id.split("?")[0]),
|
|
114
|
+
projectScreens: projectScreens(id.split("?")[0]),
|
|
93
115
|
tests: options.tests,
|
|
94
116
|
...isDev ? { sourceText: source } : {}
|
|
95
117
|
});
|
|
@@ -114,5 +136,6 @@ function orvynLang(options = {}) {
|
|
|
114
136
|
};
|
|
115
137
|
}
|
|
116
138
|
export {
|
|
117
|
-
orvynLang
|
|
139
|
+
orvynLang,
|
|
140
|
+
orvynMarkers
|
|
118
141
|
};
|
package/src/lang/words.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const matches = (item, wanted) => !wanted || Object.entries(wanted).every(([key, value]) => item?.[key] === value);
|
|
1
|
+
const matches = (item, wanted) => typeof wanted === "function" ? wanted(item) : !wanted || Object.entries(wanted).every(([key, value]) => item?.[key] === value);
|
|
2
2
|
const text = (value) => String(value ?? "").toLowerCase();
|
|
3
3
|
const WORDS = {
|
|
4
4
|
where: (list, wanted) => list.filter((item) => matches(item, wanted)),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const KEYS = ["opacity", "x", "y", "scale", "rotate"];
|
|
2
|
+
const custom = /* @__PURE__ */ new Map();
|
|
3
|
+
function defineAnimation(name, from) {
|
|
4
|
+
const clean = {};
|
|
5
|
+
for (const key of Object.keys(from ?? {})) {
|
|
6
|
+
const value = from[key];
|
|
7
|
+
if (!KEYS.includes(key)) {
|
|
8
|
+
console.warn(`[Orvyn] animation ${name}: "${key}" isn't supported. Use ${KEYS.join(", ")}.`);
|
|
9
|
+
} else if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
10
|
+
console.warn(`[Orvyn] animation ${name}: ${key} should be a number, like ${key}: ${key === "opacity" || key === "scale" ? "0.5" : "20"}`);
|
|
11
|
+
} else {
|
|
12
|
+
clean[key] = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
custom.set(name, clean);
|
|
16
|
+
return name;
|
|
17
|
+
}
|
|
18
|
+
function customAnimation(name) {
|
|
19
|
+
return custom.get(name);
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
customAnimation,
|
|
23
|
+
defineAnimation
|
|
24
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { customAnimation } from "./animations.js";
|
|
2
|
+
const FROM = {
|
|
3
|
+
fade: { opacity: 0 },
|
|
4
|
+
"fade-up": { opacity: 0, transform: "translateY(24px)" },
|
|
5
|
+
"fade-down": { opacity: 0, transform: "translateY(-24px)" },
|
|
6
|
+
"slide-left": { opacity: 0, transform: "translateX(24px)" },
|
|
7
|
+
"slide-right": { opacity: 0, transform: "translateX(-24px)" },
|
|
8
|
+
scale: { opacity: 0, transform: "scale(0.9)" }
|
|
9
|
+
};
|
|
10
|
+
const APPEAR_PRESETS = Object.keys(FROM);
|
|
11
|
+
function customFrom(name) {
|
|
12
|
+
const from = customAnimation(name);
|
|
13
|
+
if (!from) return void 0;
|
|
14
|
+
const moves = [
|
|
15
|
+
from.x !== void 0 || from.y !== void 0 ? `translate(${from.x ?? 0}px, ${from.y ?? 0}px)` : "",
|
|
16
|
+
from.scale !== void 0 ? `scale(${from.scale})` : "",
|
|
17
|
+
from.rotate !== void 0 ? `rotate(${from.rotate}deg)` : ""
|
|
18
|
+
].filter(Boolean);
|
|
19
|
+
return {
|
|
20
|
+
...from.opacity !== void 0 ? { opacity: from.opacity } : {},
|
|
21
|
+
...moves.length ? { transform: moves.join(" ") } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const seconds = (text, fallback) => text ? Number(text.replace(/s$/, "")) * 1e3 || fallback : fallback;
|
|
25
|
+
let observer = null;
|
|
26
|
+
const pending = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function watch(el, run) {
|
|
28
|
+
const g = globalThis;
|
|
29
|
+
if (typeof g.IntersectionObserver !== "function") {
|
|
30
|
+
queueMicrotask(run);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
observer ??= new g.IntersectionObserver((entries) => {
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
if (!entry.isIntersecting) continue;
|
|
36
|
+
observer.unobserve(entry.target);
|
|
37
|
+
pending.get(entry.target)?.();
|
|
38
|
+
pending.delete(entry.target);
|
|
39
|
+
}
|
|
40
|
+
}, { threshold: 0.15 });
|
|
41
|
+
pending.set(el, run);
|
|
42
|
+
observer.observe(el);
|
|
43
|
+
}
|
|
44
|
+
function setupAppear(el, props) {
|
|
45
|
+
const spec = typeof props.appear === "string" ? props.appear.trim() : "";
|
|
46
|
+
const wantsEvent = typeof props.onVisible === "function";
|
|
47
|
+
if (!spec && !wantsEvent) return;
|
|
48
|
+
const [preset, duration, delay] = spec.split(/\s+/);
|
|
49
|
+
const from = FROM[preset] ?? customFrom(preset);
|
|
50
|
+
const g = globalThis;
|
|
51
|
+
const reduceMotion = typeof g.matchMedia === "function" && g.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
52
|
+
const animates = Boolean(from) && !reduceMotion && typeof el.animate === "function";
|
|
53
|
+
const ownOpacity = el.style.opacity ?? "";
|
|
54
|
+
if (animates) el.style.opacity = "0";
|
|
55
|
+
watch(el, () => {
|
|
56
|
+
if (animates) {
|
|
57
|
+
el.style.opacity = ownOpacity;
|
|
58
|
+
el.animate([from, { opacity: ownOpacity || "1", transform: "none" }], {
|
|
59
|
+
duration: seconds(duration, 500),
|
|
60
|
+
delay: seconds(delay, 0),
|
|
61
|
+
easing: "cubic-bezier(.2,.8,.2,1)",
|
|
62
|
+
fill: "backwards"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (wantsEvent && typeof el.dispatchEvent === "function") {
|
|
66
|
+
el.dispatchEvent(typeof g.Event === "function" ? new g.Event("visible") : { type: "visible" });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
APPEAR_PRESETS,
|
|
72
|
+
setupAppear
|
|
73
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function parseMarquee(value) {
|
|
2
|
+
if (value === true) return { direction: "left", seconds: 30 };
|
|
3
|
+
if (typeof value !== "string" || !value.trim()) return null;
|
|
4
|
+
let direction = "left";
|
|
5
|
+
let seconds = 30;
|
|
6
|
+
for (const part of value.trim().split(/\s+/)) {
|
|
7
|
+
if (part === "left" || part === "right") direction = part;
|
|
8
|
+
else if (/^\d+(\.\d+)?s$/.test(part)) seconds = Number(part.slice(0, -1));
|
|
9
|
+
else return null;
|
|
10
|
+
}
|
|
11
|
+
return { direction, seconds };
|
|
12
|
+
}
|
|
13
|
+
function setupMarquee(el, props) {
|
|
14
|
+
const spec = parseMarquee(props.marquee);
|
|
15
|
+
if (!spec) return;
|
|
16
|
+
const g = globalThis;
|
|
17
|
+
const reduceMotion = typeof g.matchMedia === "function" && g.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
18
|
+
el.style.flexWrap = "nowrap";
|
|
19
|
+
el.style.flexShrink = "0";
|
|
20
|
+
el.style.width = "max-content";
|
|
21
|
+
queueMicrotask(() => {
|
|
22
|
+
const parent = el.parentElement;
|
|
23
|
+
if (!parent || typeof el.cloneNode !== "function") return;
|
|
24
|
+
parent.style.overflow = "hidden";
|
|
25
|
+
parent.style.display = "flex";
|
|
26
|
+
parent.style.flexWrap = "nowrap";
|
|
27
|
+
const copy = el.cloneNode(true);
|
|
28
|
+
copy.setAttribute?.("aria-hidden", "true");
|
|
29
|
+
copy.removeAttribute?.("aria-label");
|
|
30
|
+
el.after(copy);
|
|
31
|
+
if (typeof g.MutationObserver === "function") {
|
|
32
|
+
new g.MutationObserver(() => {
|
|
33
|
+
const fresh = el.cloneNode(true);
|
|
34
|
+
fresh.setAttribute?.("aria-hidden", "true");
|
|
35
|
+
fresh.removeAttribute?.("aria-label");
|
|
36
|
+
const old = el.nextSibling;
|
|
37
|
+
if (old && old.getAttribute?.("aria-hidden") === "true") old.replaceWith(fresh);
|
|
38
|
+
if (!reduceMotion) slide(fresh);
|
|
39
|
+
}).observe(el, { childList: true, subtree: true, characterData: true });
|
|
40
|
+
}
|
|
41
|
+
if (reduceMotion || typeof el.animate !== "function") return;
|
|
42
|
+
const slide = (node) => {
|
|
43
|
+
const frames = [{ transform: "translateX(0)" }, { transform: "translateX(-100%)" }];
|
|
44
|
+
node.animate(spec.direction === "left" ? frames : [...frames].reverse(), {
|
|
45
|
+
duration: spec.seconds * 1e3,
|
|
46
|
+
iterations: Infinity,
|
|
47
|
+
easing: "linear"
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
slide(el);
|
|
51
|
+
slide(copy);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
parseMarquee,
|
|
56
|
+
setupMarquee
|
|
57
|
+
};
|
package/src/runtime/mount.js
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
runWithComponentInstance
|
|
17
17
|
} from "../lang/runtime-shared.js";
|
|
18
18
|
import { isStyleProp } from "../styling/fluid.js";
|
|
19
|
+
import { setupAppear } from "./appear.js";
|
|
20
|
+
import { setupMarquee } from "./marquee.js";
|
|
19
21
|
import { applyStyles } from "./style.js";
|
|
20
22
|
import { attachDomEvent, patchChildren, setDomProp, syncElementState } from "./patch.js";
|
|
21
23
|
const nodeCleanups = /* @__PURE__ */ new WeakMap();
|
|
@@ -182,6 +184,8 @@ function mount(vnode) {
|
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
syncElementState(el, props);
|
|
187
|
+
setupAppear(el, props);
|
|
188
|
+
setupMarquee(el, props);
|
|
185
189
|
for (const child of vnode.children) {
|
|
186
190
|
if (isEmpty(child)) continue;
|
|
187
191
|
el.appendChild(
|
package/src/runtime/style.js
CHANGED
|
@@ -4,12 +4,20 @@ import {
|
|
|
4
4
|
getResolvedClassName,
|
|
5
5
|
getStyleDeclarations,
|
|
6
6
|
getStylePropTargets,
|
|
7
|
+
isBreakpointValue,
|
|
7
8
|
isStyleProp
|
|
8
9
|
} from "../styling/fluid.js";
|
|
9
|
-
import { autoButtonColor, warnStyle } from "../styling/spec.js";
|
|
10
|
+
import { autoButtonColor, STYLE_SPEC, warnStyle } from "../styling/spec.js";
|
|
10
11
|
function isSignal(value) {
|
|
11
12
|
return value && typeof value.get === "function" && typeof value.subscribe === "function";
|
|
12
13
|
}
|
|
14
|
+
function readStyleValue(value) {
|
|
15
|
+
const raw = isSignal(value) ? value.get() : value;
|
|
16
|
+
if (globalThis.__orvynNativePreview && isBreakpointValue(raw)) {
|
|
17
|
+
return raw.mobile ?? raw.tablet ?? raw.desktop;
|
|
18
|
+
}
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
13
21
|
function clearStyle(el, property) {
|
|
14
22
|
if (property.startsWith("--")) {
|
|
15
23
|
el.style.removeProperty(property);
|
|
@@ -27,25 +35,45 @@ function setStyle(el, property, value) {
|
|
|
27
35
|
el.style[property] = value;
|
|
28
36
|
}
|
|
29
37
|
function applyStyles(el, props = {}) {
|
|
30
|
-
|
|
38
|
+
const nativePreview = globalThis.__orvynNativePreview === true;
|
|
39
|
+
const activeProps = nativePreview ? Object.fromEntries(
|
|
40
|
+
Object.entries(props).filter(([k]) => STYLE_SPEC[k]?.support !== "web").map(([k, v]) => [k, isBreakpointValue(v) ? v.mobile ?? v.tablet ?? v.desktop : v])
|
|
41
|
+
) : props;
|
|
42
|
+
ensureResponsiveStyles(activeProps);
|
|
31
43
|
ensureFluidUtilityStyles(
|
|
32
|
-
|
|
44
|
+
activeProps.className || activeProps.class
|
|
33
45
|
);
|
|
34
|
-
const className = getResolvedClassName(
|
|
46
|
+
const className = getResolvedClassName(activeProps);
|
|
35
47
|
if (className) {
|
|
36
48
|
el.setAttribute("class", className);
|
|
37
49
|
} else {
|
|
38
50
|
el.removeAttribute("class");
|
|
39
51
|
}
|
|
40
|
-
for (const key in
|
|
52
|
+
for (const key in activeProps) {
|
|
41
53
|
if (key === "class" || key === "className") {
|
|
42
54
|
continue;
|
|
43
55
|
}
|
|
44
56
|
if (!isStyleProp(key)) {
|
|
45
|
-
warnStyle(key, "web");
|
|
57
|
+
warnStyle(key, nativePreview ? "native" : "web");
|
|
46
58
|
continue;
|
|
47
59
|
}
|
|
48
60
|
const applyValue = (value2) => {
|
|
61
|
+
if (key === "show") {
|
|
62
|
+
if (value2 === false) setStyle(el, "display", "none");
|
|
63
|
+
else if (value2 === true) {
|
|
64
|
+
let display;
|
|
65
|
+
for (const other in activeProps) {
|
|
66
|
+
if (other === "show" || other === "class" || other === "className" || !isStyleProp(other)) continue;
|
|
67
|
+
const found = getStyleDeclarations(other, readStyleValue(activeProps[other]), "dom").find((d) => d.property === "display");
|
|
68
|
+
if (found) display = found.value;
|
|
69
|
+
}
|
|
70
|
+
if (!display && activeProps.flex) display = "flex";
|
|
71
|
+
else if (!display && activeProps.grid) display = "grid";
|
|
72
|
+
if (display) setStyle(el, "display", display);
|
|
73
|
+
else clearStyle(el, "display");
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
49
77
|
const declarations = getStyleDeclarations(
|
|
50
78
|
key,
|
|
51
79
|
value2,
|
|
@@ -65,18 +93,21 @@ function applyStyles(el, props = {}) {
|
|
|
65
93
|
);
|
|
66
94
|
});
|
|
67
95
|
};
|
|
68
|
-
const value =
|
|
96
|
+
const value = activeProps[key];
|
|
69
97
|
if (isSignal(value)) {
|
|
70
|
-
applyValue(value
|
|
98
|
+
applyValue(readStyleValue(value));
|
|
71
99
|
value.subscribe(() => {
|
|
72
|
-
applyValue(value
|
|
100
|
+
applyValue(readStyleValue(value));
|
|
73
101
|
});
|
|
74
102
|
} else {
|
|
75
|
-
applyValue(value);
|
|
103
|
+
applyValue(readStyleValue(value));
|
|
76
104
|
}
|
|
77
105
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
106
|
+
if (readStyleValue(activeProps.show) === false) {
|
|
107
|
+
setStyle(el, "display", "none");
|
|
108
|
+
}
|
|
109
|
+
if (el.nodeName?.toUpperCase() === "BUTTON" && activeProps.bg && !("color" in activeProps)) {
|
|
110
|
+
const fg = autoButtonColor(readStyleValue(activeProps.bg));
|
|
80
111
|
if (fg) setStyle(el, "color", fg);
|
|
81
112
|
}
|
|
82
113
|
}
|
package/src/styling/fluid.js
CHANGED
|
@@ -358,10 +358,10 @@ const WEB_THEME_VARS = {
|
|
|
358
358
|
card: "var(--orvyn-card, #f1f5f9)",
|
|
359
359
|
text: "var(--orvyn-text, #0f172a)",
|
|
360
360
|
muted: "var(--orvyn-muted, #64748b)",
|
|
361
|
-
primary: "var(--orvyn-primary, #
|
|
361
|
+
primary: "var(--orvyn-primary, #0066cc)",
|
|
362
362
|
onPrimary: "var(--orvyn-on-primary, #ffffff)",
|
|
363
363
|
border: "var(--orvyn-border, #cbd5e1)",
|
|
364
|
-
danger: "var(--orvyn-danger, #
|
|
364
|
+
danger: "var(--orvyn-danger, #b91c1c)",
|
|
365
365
|
success: "var(--orvyn-success, #16a34a)",
|
|
366
366
|
warning: "var(--orvyn-warning, #f59e0b)"
|
|
367
367
|
};
|
|
@@ -512,9 +512,12 @@ function isFluidProp(prop) {
|
|
|
512
512
|
return fluidProps.has(prop);
|
|
513
513
|
}
|
|
514
514
|
function isStyleProp(prop) {
|
|
515
|
-
return prop in domStyleProps || stateStyleProps.has(prop) || prop === "center" || prop === "scroll";
|
|
515
|
+
return prop in domStyleProps || stateStyleProps.has(prop) || prop === "center" || prop === "animate" || prop === "appear" || prop === "marquee" || prop === "scroll" || prop === "show";
|
|
516
516
|
}
|
|
517
517
|
function getStylePropTargets(prop, target) {
|
|
518
|
+
if (prop === "show") {
|
|
519
|
+
return ["display"];
|
|
520
|
+
}
|
|
518
521
|
if (prop === "center") {
|
|
519
522
|
return target === "dom" ? ["display", "alignItems", "justifyContent", "textAlign"] : ["display", "align-items", "justify-content", "text-align"];
|
|
520
523
|
}
|
|
@@ -535,6 +538,17 @@ function getStyleDeclarationsForValue(prop, value, target, options) {
|
|
|
535
538
|
if (isBreakpointValue(value)) {
|
|
536
539
|
return [];
|
|
537
540
|
}
|
|
541
|
+
if (prop === "show") {
|
|
542
|
+
return value === false ? [{ property: "display", value: "none" }] : [];
|
|
543
|
+
}
|
|
544
|
+
if (prop === "appear") return [];
|
|
545
|
+
if (prop === "marquee") return [];
|
|
546
|
+
if (prop === "animate") {
|
|
547
|
+
const match = String(value).trim().match(/^(ease|linear|spring)(?:\s+(\d+(?:\.\d+)?)s)?$/);
|
|
548
|
+
if (!match) return [];
|
|
549
|
+
const easing = match[1] === "spring" ? "cubic-bezier(.2,.8,.2,1)" : match[1];
|
|
550
|
+
return [{ property: "transition", value: `all ${match[2] ?? "0.3"}s ${easing}` }];
|
|
551
|
+
}
|
|
538
552
|
if (prop === "center") {
|
|
539
553
|
if (value !== true) return [];
|
|
540
554
|
const align = target === "dom" ? "alignItems" : "align-items";
|
|
@@ -613,7 +627,7 @@ function getResponsiveDeclarationGroups(props = {}, target) {
|
|
|
613
627
|
desktop: []
|
|
614
628
|
};
|
|
615
629
|
for (const key in props) {
|
|
616
|
-
if (key === "children" || key === "key" || key === "class" || key === "className" || key === "hydrate" || key === "resume" || key.startsWith("on") || !isStyleProp(key)) {
|
|
630
|
+
if (key === "children" || key === "key" || key === "class" || key === "className" || key === "hydrate" || key === "resume" || key === "show" || key.startsWith("on") || !isStyleProp(key)) {
|
|
617
631
|
continue;
|
|
618
632
|
}
|
|
619
633
|
const value = readValue(props[key]);
|
|
@@ -634,17 +648,34 @@ function getResponsiveDeclarationGroups(props = {}, target) {
|
|
|
634
648
|
}
|
|
635
649
|
return groups;
|
|
636
650
|
}
|
|
651
|
+
function showBreakpointMedia(value) {
|
|
652
|
+
if (!isBreakpointValue(value)) return [];
|
|
653
|
+
const mobileShown = (value.mobile ?? value.tablet ?? value.desktop) !== false;
|
|
654
|
+
const tabletShown = (value.tablet ?? value.mobile ?? value.desktop) !== false;
|
|
655
|
+
const desktopShown = (value.desktop ?? value.tablet ?? value.mobile) !== false;
|
|
656
|
+
const rules = [];
|
|
657
|
+
if (!mobileShown && !tabletShown && !desktopShown) return [{ query: null }];
|
|
658
|
+
if (!mobileShown && !tabletShown) rules.push({ query: `(max-width: ${breakpoints.desktop - 1}px)` });
|
|
659
|
+
else {
|
|
660
|
+
if (!mobileShown) rules.push({ query: `(max-width: ${breakpoints.tablet - 1}px)` });
|
|
661
|
+
if (!tabletShown) rules.push({ query: `(min-width: ${breakpoints.tablet}px) and (max-width: ${breakpoints.desktop - 1}px)` });
|
|
662
|
+
}
|
|
663
|
+
if (!desktopShown) rules.push({ query: `(min-width: ${breakpoints.desktop}px)` });
|
|
664
|
+
return rules;
|
|
665
|
+
}
|
|
637
666
|
function getResponsiveSignature(props = {}) {
|
|
638
667
|
const groups = getResponsiveDeclarationGroups(
|
|
639
668
|
props,
|
|
640
669
|
"css"
|
|
641
670
|
);
|
|
642
671
|
const states = getStateDeclarationGroups(props);
|
|
672
|
+
const showVal = readValue(props.show);
|
|
673
|
+
const showSig = isBreakpointValue(showVal) ? `show{${showBreakpointMedia(showVal).map((r) => r.query ?? "all").join(",")}}` : "";
|
|
643
674
|
return ["base", "tablet", "desktop"].map(
|
|
644
675
|
(breakpoint) => `${breakpoint}{${formatDeclarationBody(groups[breakpoint])}}`
|
|
645
676
|
).join("") + Object.entries(states).map(
|
|
646
677
|
([state, declarations]) => `${state}{${formatDeclarationBody(declarations)}}`
|
|
647
|
-
).join("");
|
|
678
|
+
).join("") + showSig;
|
|
648
679
|
}
|
|
649
680
|
function getStateDeclarationGroups(props = {}) {
|
|
650
681
|
const groups = {
|
|
@@ -726,6 +757,11 @@ function getResponsiveStyleRules(props = {}) {
|
|
|
726
757
|
`${selector}:${state} { ${formatDeclarationBody(declarations)} }`
|
|
727
758
|
);
|
|
728
759
|
});
|
|
760
|
+
for (const media of showBreakpointMedia(readValue(props.show))) {
|
|
761
|
+
rules.push(
|
|
762
|
+
media.query ? `@media ${media.query} { ${selector} { display: none !important } }` : `${selector} { display: none !important }`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
729
765
|
return rules.join("\n");
|
|
730
766
|
}
|
|
731
767
|
function ensureResponsiveStyles(props = {}) {
|
package/src/styling/spec.js
CHANGED
|
@@ -20,6 +20,7 @@ const STYLE_SPEC = {
|
|
|
20
20
|
grow: { support: "all" },
|
|
21
21
|
flex: { support: "all" },
|
|
22
22
|
direction: { support: "all" },
|
|
23
|
+
show: { support: "all" },
|
|
23
24
|
// Visual appearance (all platforms)
|
|
24
25
|
bg: { support: "all" },
|
|
25
26
|
color: { support: "all" },
|
|
@@ -27,6 +28,9 @@ const STYLE_SPEC = {
|
|
|
27
28
|
border: { support: "all" },
|
|
28
29
|
shadow: { support: "all" },
|
|
29
30
|
opacity: { support: "all" },
|
|
31
|
+
animate: { support: "all" },
|
|
32
|
+
appear: { support: "all" },
|
|
33
|
+
marquee: { support: "all" },
|
|
30
34
|
// Typography & direction (all platforms)
|
|
31
35
|
size: { support: "all" },
|
|
32
36
|
weight: { support: "all" },
|
|
@@ -48,20 +52,20 @@ const STYLE_SPEC = {
|
|
|
48
52
|
columns: { support: "web", note: "CSS Grid columns are web-only; use Row with wrap: true on phones" },
|
|
49
53
|
rows: { support: "web", note: "CSS Grid rows are web-only" },
|
|
50
54
|
minItemWidth: { support: "web", note: "CSS Grid auto-fit width is web-only" },
|
|
51
|
-
basis: { support: "
|
|
55
|
+
basis: { support: "all", note: "On phones, basis acts as the width when no width is set" },
|
|
52
56
|
shrink: { support: "web", note: "flex-shrink is web-only" },
|
|
53
57
|
display: { support: "web" },
|
|
54
|
-
overflow: { support: "
|
|
58
|
+
overflow: { support: "all", note: 'On phones only "hidden" is used; use scroll: true to scroll' },
|
|
55
59
|
overflowX: { support: "web", note: 'Use scroll: "horizontal" for cross-platform scrolling' },
|
|
56
60
|
overflowY: { support: "web", note: "Use scroll: true for cross-platform scrolling" },
|
|
57
61
|
objectFit: { support: "web" },
|
|
58
62
|
objectPosition: { support: "web" },
|
|
59
|
-
position: { support: "
|
|
63
|
+
position: { support: "all", note: 'On phones only "absolute" is used (iPhone so far); sticky and fixed act like normal' },
|
|
60
64
|
inset: { support: "web" },
|
|
61
|
-
top: { support: "
|
|
62
|
-
right: { support: "
|
|
63
|
-
bottom: { support: "
|
|
64
|
-
left: { support: "
|
|
65
|
+
top: { support: "all" },
|
|
66
|
+
right: { support: "all" },
|
|
67
|
+
bottom: { support: "all" },
|
|
68
|
+
left: { support: "all" },
|
|
65
69
|
zIndex: { support: "web" },
|
|
66
70
|
boxShadow: { support: "web", note: "Use shadow: 1..3 for cross-platform elevation" },
|
|
67
71
|
cursor: { support: "web" },
|
|
@@ -70,7 +74,7 @@ const STYLE_SPEC = {
|
|
|
70
74
|
transform: { support: "web" },
|
|
71
75
|
transition: { support: "web" },
|
|
72
76
|
whiteSpace: { support: "web" },
|
|
73
|
-
letterSpacing: { support: "
|
|
77
|
+
letterSpacing: { support: "all" },
|
|
74
78
|
textDecoration: { support: "web" }
|
|
75
79
|
};
|
|
76
80
|
const NON_STYLE_PROPS = /* @__PURE__ */ new Set([
|
|
@@ -107,7 +111,7 @@ const LIGHT_COLORS = {
|
|
|
107
111
|
card: "#f1f5f9",
|
|
108
112
|
text: "#0f172a",
|
|
109
113
|
muted: "#64748b",
|
|
110
|
-
primary: "#
|
|
114
|
+
primary: "#0066cc",
|
|
111
115
|
onPrimary: "#ffffff",
|
|
112
116
|
border: "#cbd5e1",
|
|
113
117
|
danger: "#b91c1c",
|
|
@@ -266,7 +270,15 @@ function closestStyleProp(name) {
|
|
|
266
270
|
maxheight: "maxHeight",
|
|
267
271
|
minheight: "minHeight",
|
|
268
272
|
paddingx: "paddingX",
|
|
269
|
-
paddingy: "paddingY"
|
|
273
|
+
paddingy: "paddingY",
|
|
274
|
+
paddingtop: "paddingY",
|
|
275
|
+
paddingbottom: "paddingY",
|
|
276
|
+
paddingleft: "paddingX",
|
|
277
|
+
paddingright: "paddingX",
|
|
278
|
+
margintop: "margin",
|
|
279
|
+
marginbottom: "margin",
|
|
280
|
+
marginleft: "margin",
|
|
281
|
+
marginright: "margin"
|
|
270
282
|
};
|
|
271
283
|
if (aliases[lower]) return aliases[lower];
|
|
272
284
|
for (const candidate of Object.keys(STYLE_SPEC)) {
|
|
@@ -296,6 +308,7 @@ export {
|
|
|
296
308
|
STYLE_SPEC,
|
|
297
309
|
autoButtonColor,
|
|
298
310
|
clearStyleWarnings,
|
|
311
|
+
closestStyleProp,
|
|
299
312
|
resetTheme,
|
|
300
313
|
resolveFontFamily,
|
|
301
314
|
resolveThemeToken,
|