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.
- package/GUIDE.md +198 -0
- package/LANGUAGE.md +818 -30
- package/README.md +211 -250
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +207 -16
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +152 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +615 -58
- 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 +65 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +176 -7
- package/src/lang/native/android/OrvynRenderer.kt +970 -50
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/assets.js +39 -0
- package/src/lang/native/build.js +140 -63
- package/src/lang/native/compatibility.js +57 -0
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +291 -4
- package/src/lang/native/ios/OrvynViews.swift +769 -41
- package/src/lang/native/ios.js +81 -2
- package/src/lang/native-runtime.js +541 -55
- package/src/lang/native-size.js +53 -0
- package/src/lang/page-files.js +71 -0
- package/src/lang/page.js +63 -0
- package/src/lang/parser.js +278 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +12 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +796 -10
- package/src/lang/runtime.js +399 -51
- 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/style-check.js +60 -0
- package/src/lang/test-runner.js +134 -0
- package/src/lang/types.js +317 -0
- package/src/lang/vite-plugin.js +108 -6
- 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/animations.js +24 -0
- package/src/runtime/appear.js +73 -0
- package/src/runtime/marquee.js +57 -0
- package/src/runtime/mount.js +120 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +50 -9
- package/src/styling/fluid.js +129 -6
- package/src/styling/spec.js +319 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const matches = (item, wanted) => typeof wanted === "function" ? wanted(item) : !wanted || Object.entries(wanted).every(([key, value]) => item?.[key] === value);
|
|
2
|
+
const text = (value) => String(value ?? "").toLowerCase();
|
|
3
|
+
const WORDS = {
|
|
4
|
+
where: (list, wanted) => list.filter((item) => matches(item, wanted)),
|
|
5
|
+
count: (list, wanted) => list.filter((item) => matches(item, wanted)).length,
|
|
6
|
+
first: (list, wanted) => list.find((item) => matches(item, wanted)) ?? null,
|
|
7
|
+
// without a field name, every text in the item is searched
|
|
8
|
+
search: (list, query, field) => {
|
|
9
|
+
const needle = text(query).trim();
|
|
10
|
+
if (!needle) return [...list];
|
|
11
|
+
return list.filter((item) => {
|
|
12
|
+
const values = field ? [item?.[field]] : item && typeof item === "object" ? Object.values(item) : [item];
|
|
13
|
+
return values.some((v) => (typeof v === "string" || typeof v === "number") && text(v).includes(needle));
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
pick: (list, field) => list.map((item) => item?.[field]),
|
|
17
|
+
total: (list, field, times) => list.reduce((sum, item) => {
|
|
18
|
+
const value = Number(field ? item?.[field] : item) || 0;
|
|
19
|
+
return sum + value * (times ? Number(item?.[times]) || 0 : 1);
|
|
20
|
+
}, 0),
|
|
21
|
+
sortBy: (list, field, order) => {
|
|
22
|
+
const sorted = [...list].sort((a, b) => {
|
|
23
|
+
const [x, y] = [a?.[field], b?.[field]];
|
|
24
|
+
return typeof x === "number" && typeof y === "number" ? x - y : String(x ?? "").localeCompare(String(y ?? ""));
|
|
25
|
+
});
|
|
26
|
+
return order === "high" ? sorted.reverse() : sorted;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const LIST_WORDS = Object.keys(WORDS);
|
|
30
|
+
function words(target, name, args) {
|
|
31
|
+
if (target === null || target === void 0) return WORDS[name]([], ...args);
|
|
32
|
+
if (Array.isArray(target)) return WORDS[name](target, ...args);
|
|
33
|
+
return target[name](...args);
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
LIST_WORDS,
|
|
37
|
+
words
|
|
38
|
+
};
|
|
@@ -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
|
@@ -1,12 +1,76 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createOwner,
|
|
3
|
+
disposeOwner,
|
|
4
|
+
effect,
|
|
5
|
+
runWithOwner,
|
|
6
|
+
signal
|
|
7
|
+
} from "../core/signal.js";
|
|
2
8
|
import {
|
|
3
9
|
beginComponentRender,
|
|
4
10
|
endComponentRender,
|
|
5
|
-
registerComponent
|
|
11
|
+
registerComponent,
|
|
12
|
+
unregisterComponent
|
|
6
13
|
} from "../devtools/runtime.js";
|
|
14
|
+
import {
|
|
15
|
+
createComponentInstance,
|
|
16
|
+
runWithComponentInstance
|
|
17
|
+
} from "../lang/runtime-shared.js";
|
|
7
18
|
import { isStyleProp } from "../styling/fluid.js";
|
|
19
|
+
import { setupAppear } from "./appear.js";
|
|
20
|
+
import { setupMarquee } from "./marquee.js";
|
|
8
21
|
import { applyStyles } from "./style.js";
|
|
9
|
-
import { patchChildren, setDomProp } from "./patch.js";
|
|
22
|
+
import { attachDomEvent, patchChildren, setDomProp, syncElementState } from "./patch.js";
|
|
23
|
+
const nodeCleanups = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
const mountedComponents = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
function registerNodeCleanup(node, fn) {
|
|
26
|
+
let list = nodeCleanups.get(node);
|
|
27
|
+
if (!list) {
|
|
28
|
+
list = [];
|
|
29
|
+
nodeCleanups.set(node, list);
|
|
30
|
+
}
|
|
31
|
+
list.push(fn);
|
|
32
|
+
}
|
|
33
|
+
function disposeDomTree(node) {
|
|
34
|
+
if (!node || typeof node !== "object") return;
|
|
35
|
+
const list = nodeCleanups.get(node);
|
|
36
|
+
if (list) {
|
|
37
|
+
nodeCleanups.delete(node);
|
|
38
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
39
|
+
try {
|
|
40
|
+
list[i]();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("[Orvyn] cleanup failed", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const children = node.childNodes;
|
|
47
|
+
if (children && children.length) {
|
|
48
|
+
for (let i = 0; i < children.length; i++) {
|
|
49
|
+
disposeDomTree(children[i]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function updateMountedComponent(node, nextProps) {
|
|
54
|
+
const update = mountedComponents.get(node);
|
|
55
|
+
if (!update) return false;
|
|
56
|
+
update(nextProps);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
function shallowPropsEqual(prev, next) {
|
|
60
|
+
const keysA = Object.keys(prev);
|
|
61
|
+
const keysB = Object.keys(next);
|
|
62
|
+
if (keysA.length !== keysB.length) return false;
|
|
63
|
+
for (const key of keysA) {
|
|
64
|
+
if (!Object.prototype.hasOwnProperty.call(next, key)) return false;
|
|
65
|
+
if (key === "children") {
|
|
66
|
+
if (Array.isArray(prev.children) && Array.isArray(next.children) && prev.children.length === 0 && next.children.length === 0) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!Object.is(prev[key], next[key])) return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
10
74
|
function isSignal(value) {
|
|
11
75
|
return value && typeof value.get === "function";
|
|
12
76
|
}
|
|
@@ -50,33 +114,59 @@ function mount(vnode) {
|
|
|
50
114
|
}
|
|
51
115
|
if (typeof vnode.tag === "function") {
|
|
52
116
|
const container = document.createElement("div");
|
|
117
|
+
container.style.display = "contents";
|
|
53
118
|
const componentId = registerComponent(
|
|
54
119
|
vnode.tag.name || "Anonymous"
|
|
55
120
|
);
|
|
121
|
+
const componentOwner = createOwner();
|
|
122
|
+
let latestProps = {
|
|
123
|
+
...vnode.props,
|
|
124
|
+
children: vnode.children
|
|
125
|
+
};
|
|
126
|
+
const propsSignal = signal(latestProps);
|
|
127
|
+
const instance = createComponentInstance();
|
|
56
128
|
let previous;
|
|
57
129
|
let mounted = false;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
130
|
+
const stopComponent = runWithOwner(
|
|
131
|
+
componentOwner,
|
|
132
|
+
() => effect(() => {
|
|
133
|
+
const startedAt = beginComponentRender(componentId);
|
|
134
|
+
try {
|
|
135
|
+
const props2 = propsSignal.get();
|
|
136
|
+
const rendered = runWithComponentInstance(
|
|
137
|
+
instance,
|
|
138
|
+
() => vnode.tag(props2)
|
|
139
|
+
);
|
|
140
|
+
const list = Array.isArray(rendered) ? rendered : [rendered];
|
|
141
|
+
if (mounted) {
|
|
142
|
+
patchChildren(container, previous, list);
|
|
143
|
+
} else {
|
|
144
|
+
container.appendChild(mount(list));
|
|
145
|
+
mounted = true;
|
|
146
|
+
}
|
|
147
|
+
previous = list;
|
|
148
|
+
} finally {
|
|
149
|
+
endComponentRender(
|
|
150
|
+
componentId,
|
|
151
|
+
startedAt
|
|
152
|
+
);
|
|
71
153
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
mountedComponents.set(container, (nextProps) => {
|
|
157
|
+
if (!shallowPropsEqual(latestProps, nextProps)) {
|
|
158
|
+
latestProps = nextProps;
|
|
159
|
+
propsSignal.set(nextProps);
|
|
78
160
|
}
|
|
79
161
|
});
|
|
162
|
+
registerNodeCleanup(container, () => {
|
|
163
|
+
mountedComponents.delete(container);
|
|
164
|
+
stopComponent();
|
|
165
|
+
disposeOwner(componentOwner);
|
|
166
|
+
propsSignal.dispose();
|
|
167
|
+
instance.dispose();
|
|
168
|
+
unregisterComponent(componentId);
|
|
169
|
+
});
|
|
80
170
|
return container;
|
|
81
171
|
}
|
|
82
172
|
const el = document.createElement(vnode.tag);
|
|
@@ -88,14 +178,14 @@ function mount(vnode) {
|
|
|
88
178
|
continue;
|
|
89
179
|
}
|
|
90
180
|
if (key.startsWith("on")) {
|
|
91
|
-
el
|
|
92
|
-
key.slice(2).toLowerCase(),
|
|
93
|
-
value
|
|
94
|
-
);
|
|
181
|
+
attachDomEvent(el, key, value);
|
|
95
182
|
} else if (!isStyleProp(key)) {
|
|
96
183
|
setDomProp(el, key, value);
|
|
97
184
|
}
|
|
98
185
|
}
|
|
186
|
+
syncElementState(el, props);
|
|
187
|
+
setupAppear(el, props);
|
|
188
|
+
setupMarquee(el, props);
|
|
99
189
|
for (const child of vnode.children) {
|
|
100
190
|
if (isEmpty(child)) continue;
|
|
101
191
|
el.appendChild(
|
|
@@ -105,5 +195,8 @@ function mount(vnode) {
|
|
|
105
195
|
return el;
|
|
106
196
|
}
|
|
107
197
|
export {
|
|
108
|
-
|
|
198
|
+
disposeDomTree,
|
|
199
|
+
mount,
|
|
200
|
+
registerNodeCleanup,
|
|
201
|
+
updateMountedComponent
|
|
109
202
|
};
|
package/src/runtime/patch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyStyles } from "./style.js";
|
|
2
|
-
import { mount } from "./mount.js";
|
|
2
|
+
import { disposeDomTree, mount, updateMountedComponent } from "./mount.js";
|
|
3
3
|
import {
|
|
4
4
|
getStylePropTargets,
|
|
5
5
|
isStyleProp
|
|
@@ -13,7 +13,82 @@ function clearStyle(el, property) {
|
|
|
13
13
|
el.style[property] = "";
|
|
14
14
|
}
|
|
15
15
|
const LIVE_PROPS = /* @__PURE__ */ new Set(["value", "checked", "selected"]);
|
|
16
|
+
const pendingButtons = /* @__PURE__ */ new WeakSet();
|
|
17
|
+
const latestNodeProps = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
const nodeEventWrappers = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
function attachDomEvent(el, key, raw) {
|
|
20
|
+
if (typeof raw !== "function") return;
|
|
21
|
+
const eventName = key.slice(2).toLowerCase();
|
|
22
|
+
const isAsyncButtonClick = eventName === "click" && el.nodeName?.toUpperCase() === "BUTTON" && el.type !== "submit";
|
|
23
|
+
const wrapped = isAsyncButtonClick ? (event) => {
|
|
24
|
+
if (pendingButtons.has(el)) return;
|
|
25
|
+
const outcome = raw(event);
|
|
26
|
+
if (outcome && typeof outcome.then === "function") {
|
|
27
|
+
pendingButtons.add(el);
|
|
28
|
+
syncElementState(el, latestNodeProps.get(el) || {});
|
|
29
|
+
return Promise.resolve(outcome).finally(() => {
|
|
30
|
+
pendingButtons.delete(el);
|
|
31
|
+
syncElementState(el, latestNodeProps.get(el) || {});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return outcome;
|
|
35
|
+
} : raw;
|
|
36
|
+
let map = nodeEventWrappers.get(el);
|
|
37
|
+
if (!map) {
|
|
38
|
+
map = /* @__PURE__ */ new Map();
|
|
39
|
+
nodeEventWrappers.set(el, map);
|
|
40
|
+
}
|
|
41
|
+
const prev = map.get(eventName);
|
|
42
|
+
if (prev) el.removeEventListener(eventName, prev.wrapped);
|
|
43
|
+
map.set(eventName, { raw, wrapped });
|
|
44
|
+
el.addEventListener(eventName, wrapped);
|
|
45
|
+
}
|
|
46
|
+
function detachDomEvent(el, key, oldRaw) {
|
|
47
|
+
const eventName = key.slice(2).toLowerCase();
|
|
48
|
+
const map = nodeEventWrappers.get(el);
|
|
49
|
+
const entry = map?.get(eventName);
|
|
50
|
+
if (entry && entry.raw === oldRaw) {
|
|
51
|
+
el.removeEventListener(eventName, entry.wrapped);
|
|
52
|
+
map.delete(eventName);
|
|
53
|
+
} else {
|
|
54
|
+
el.removeEventListener(eventName, oldRaw);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function syncElementState(el, props = {}) {
|
|
58
|
+
latestNodeProps.set(el, props);
|
|
59
|
+
const autoLoading = pendingButtons.has(el);
|
|
60
|
+
const lazy = props.loading === "lazy" || props.loading === "eager";
|
|
61
|
+
if (lazy) el.setAttribute("loading", props.loading);
|
|
62
|
+
const isLoading = Boolean(props.loading && !lazy || autoLoading);
|
|
63
|
+
const isDisabled = Boolean(props.disabled || isLoading);
|
|
64
|
+
const tag = el.nodeName?.toUpperCase();
|
|
65
|
+
if (tag === "BUTTON" || tag === "INPUT" || "disabled" in el) {
|
|
66
|
+
el.disabled = isDisabled;
|
|
67
|
+
}
|
|
68
|
+
if (props.disabled) el.setAttribute("aria-disabled", "true");
|
|
69
|
+
else el.removeAttribute("aria-disabled");
|
|
70
|
+
if (isLoading) {
|
|
71
|
+
el.setAttribute("aria-busy", "true");
|
|
72
|
+
el.setAttribute("data-orvyn-loading", "true");
|
|
73
|
+
} else {
|
|
74
|
+
el.removeAttribute("aria-busy");
|
|
75
|
+
el.removeAttribute("data-orvyn-loading");
|
|
76
|
+
}
|
|
77
|
+
if (props.error) {
|
|
78
|
+
el.setAttribute("aria-invalid", "true");
|
|
79
|
+
el.setAttribute("data-orvyn-error", "true");
|
|
80
|
+
} else if (!("aria-invalid" in props)) {
|
|
81
|
+
el.removeAttribute("aria-invalid");
|
|
82
|
+
el.removeAttribute("data-orvyn-error");
|
|
83
|
+
}
|
|
84
|
+
if (props.rtl === true) el.setAttribute("dir", "rtl");
|
|
85
|
+
else if (props.rtl === false) el.setAttribute("dir", "ltr");
|
|
86
|
+
else if (!("dir" in props)) el.removeAttribute("dir");
|
|
87
|
+
}
|
|
16
88
|
function setDomProp(el, key, value) {
|
|
89
|
+
if (key === "disabled" || key === "loading" || key === "error" || key === "rtl") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
17
92
|
if (LIVE_PROPS.has(key)) {
|
|
18
93
|
const next = key === "value" ? value ?? "" : Boolean(value);
|
|
19
94
|
if (el[key] !== next) el[key] = next;
|
|
@@ -63,10 +138,7 @@ function patchProps(el, oldProps = {}, newProps = {}) {
|
|
|
63
138
|
const newValue = newProps[key];
|
|
64
139
|
if (oldValue === newValue) continue;
|
|
65
140
|
if (key.startsWith("on")) {
|
|
66
|
-
el
|
|
67
|
-
key.slice(2).toLowerCase(),
|
|
68
|
-
oldValue
|
|
69
|
-
);
|
|
141
|
+
detachDomEvent(el, key, oldValue);
|
|
70
142
|
} else if (isStyleProp(key) && !(key in newProps)) {
|
|
71
143
|
getStylePropTargets(key, "dom").forEach((target) => {
|
|
72
144
|
clearStyle(el, target);
|
|
@@ -86,14 +158,12 @@ function patchProps(el, oldProps = {}, newProps = {}) {
|
|
|
86
158
|
const newValue = newProps[key];
|
|
87
159
|
if (oldValue === newValue) continue;
|
|
88
160
|
if (key.startsWith("on")) {
|
|
89
|
-
el
|
|
90
|
-
key.slice(2).toLowerCase(),
|
|
91
|
-
newValue
|
|
92
|
-
);
|
|
161
|
+
attachDomEvent(el, key, newValue);
|
|
93
162
|
} else if (!isStyleProp(key)) {
|
|
94
163
|
setDomProp(el, key, newValue);
|
|
95
164
|
}
|
|
96
165
|
}
|
|
166
|
+
syncElementState(el, newProps);
|
|
97
167
|
}
|
|
98
168
|
function patchChildren(el, oldChildren = [], newChildren = []) {
|
|
99
169
|
const oldList = normalizeChildren(oldChildren);
|
|
@@ -150,12 +220,13 @@ function patchChildren(el, oldChildren = [], newChildren = []) {
|
|
|
150
220
|
});
|
|
151
221
|
oldRecords.forEach((record) => {
|
|
152
222
|
if (!used.has(record)) {
|
|
223
|
+
disposeDomTree(record.el);
|
|
153
224
|
record.el?.remove();
|
|
154
225
|
}
|
|
155
226
|
});
|
|
156
227
|
}
|
|
157
228
|
function patch(parent, el, oldVNode, newVNode) {
|
|
158
|
-
if (oldVNode === newVNode) {
|
|
229
|
+
if (oldVNode === newVNode && isTextVNode(newVNode)) {
|
|
159
230
|
return el;
|
|
160
231
|
}
|
|
161
232
|
if (isTextVNode(oldVNode) && isTextVNode(newVNode)) {
|
|
@@ -166,6 +237,7 @@ function patch(parent, el, oldVNode, newVNode) {
|
|
|
166
237
|
}
|
|
167
238
|
if (isTextVNode(oldVNode) || isTextVNode(newVNode) || !canPatch(oldVNode, newVNode)) {
|
|
168
239
|
const newEl = mount(newVNode);
|
|
240
|
+
disposeDomTree(el);
|
|
169
241
|
parent.replaceChild(
|
|
170
242
|
newEl,
|
|
171
243
|
el
|
|
@@ -173,7 +245,11 @@ function patch(parent, el, oldVNode, newVNode) {
|
|
|
173
245
|
return newEl;
|
|
174
246
|
}
|
|
175
247
|
if (typeof newVNode.tag === "function") {
|
|
248
|
+
if (updateMountedComponent(el, { ...newVNode.props, children: newVNode.children })) {
|
|
249
|
+
return el;
|
|
250
|
+
}
|
|
176
251
|
const newEl = mount(newVNode);
|
|
252
|
+
disposeDomTree(el);
|
|
177
253
|
parent.replaceChild(
|
|
178
254
|
newEl,
|
|
179
255
|
el
|
|
@@ -193,7 +269,10 @@ function patch(parent, el, oldVNode, newVNode) {
|
|
|
193
269
|
return el;
|
|
194
270
|
}
|
|
195
271
|
export {
|
|
272
|
+
attachDomEvent,
|
|
273
|
+
detachDomEvent,
|
|
196
274
|
patch,
|
|
197
275
|
patchChildren,
|
|
198
|
-
setDomProp
|
|
276
|
+
setDomProp,
|
|
277
|
+
syncElementState
|
|
199
278
|
};
|
package/src/runtime/style.js
CHANGED
|
@@ -3,11 +3,21 @@ import {
|
|
|
3
3
|
ensureFluidUtilityStyles,
|
|
4
4
|
getResolvedClassName,
|
|
5
5
|
getStyleDeclarations,
|
|
6
|
-
getStylePropTargets
|
|
6
|
+
getStylePropTargets,
|
|
7
|
+
isBreakpointValue,
|
|
8
|
+
isStyleProp
|
|
7
9
|
} from "../styling/fluid.js";
|
|
10
|
+
import { autoButtonColor, STYLE_SPEC, warnStyle } from "../styling/spec.js";
|
|
8
11
|
function isSignal(value) {
|
|
9
12
|
return value && typeof value.get === "function" && typeof value.subscribe === "function";
|
|
10
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
|
+
}
|
|
11
21
|
function clearStyle(el, property) {
|
|
12
22
|
if (property.startsWith("--")) {
|
|
13
23
|
el.style.removeProperty(property);
|
|
@@ -25,21 +35,45 @@ function setStyle(el, property, value) {
|
|
|
25
35
|
el.style[property] = value;
|
|
26
36
|
}
|
|
27
37
|
function applyStyles(el, props = {}) {
|
|
28
|
-
|
|
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);
|
|
29
43
|
ensureFluidUtilityStyles(
|
|
30
|
-
|
|
44
|
+
activeProps.className || activeProps.class
|
|
31
45
|
);
|
|
32
|
-
const className = getResolvedClassName(
|
|
46
|
+
const className = getResolvedClassName(activeProps);
|
|
33
47
|
if (className) {
|
|
34
48
|
el.setAttribute("class", className);
|
|
35
49
|
} else {
|
|
36
50
|
el.removeAttribute("class");
|
|
37
51
|
}
|
|
38
|
-
for (const key in
|
|
52
|
+
for (const key in activeProps) {
|
|
39
53
|
if (key === "class" || key === "className") {
|
|
40
54
|
continue;
|
|
41
55
|
}
|
|
56
|
+
if (!isStyleProp(key)) {
|
|
57
|
+
warnStyle(key, nativePreview ? "native" : "web");
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
42
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
|
+
}
|
|
43
77
|
const declarations = getStyleDeclarations(
|
|
44
78
|
key,
|
|
45
79
|
value2,
|
|
@@ -59,16 +93,23 @@ function applyStyles(el, props = {}) {
|
|
|
59
93
|
);
|
|
60
94
|
});
|
|
61
95
|
};
|
|
62
|
-
const value =
|
|
96
|
+
const value = activeProps[key];
|
|
63
97
|
if (isSignal(value)) {
|
|
64
|
-
applyValue(value
|
|
98
|
+
applyValue(readStyleValue(value));
|
|
65
99
|
value.subscribe(() => {
|
|
66
|
-
applyValue(value
|
|
100
|
+
applyValue(readStyleValue(value));
|
|
67
101
|
});
|
|
68
102
|
} else {
|
|
69
|
-
applyValue(value);
|
|
103
|
+
applyValue(readStyleValue(value));
|
|
70
104
|
}
|
|
71
105
|
}
|
|
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));
|
|
111
|
+
if (fg) setStyle(el, "color", fg);
|
|
112
|
+
}
|
|
72
113
|
}
|
|
73
114
|
export {
|
|
74
115
|
applyStyles
|