orvyn-lang 0.1.1 → 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 +877 -24
- package/README.md +227 -131
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +216 -489
- 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 +498 -64
- 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 +160 -0
- 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 +519 -40
- 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 +268 -4
- package/src/lang/native/ios/OrvynViews.swift +429 -31
- package/src/lang/native/ios.js +75 -2
- package/src/lang/native-runtime.js +423 -57
- 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 +820 -10
- package/src/lang/runtime.js +375 -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/validation.js +55 -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
- package/src/core/context.js +0 -19
- package/src/core/lifecycle.js +0 -8
- package/src/core/resource.js +0 -27
- package/src/core/router.js +0 -20
- package/src/core/theme.js +0 -10
- package/src/devtools/devicePreview/PreviewFrame.js +0 -214
- package/src/devtools/devicePreview/index.js +0 -6
- package/src/devtools/overlay.js +0 -105
- package/src/runtime/createRenderer.js +0 -22
- package/src/runtime/h.js +0 -93
- package/src/runtime/hydrate.js +0 -59
- package/src/runtime/jsx-dev-runtime.js +0 -7
- package/src/runtime/jsx-runtime.js +0 -13
- package/src/runtime/partialHydration.js +0 -154
- package/src/runtime/platform.js +0 -135
- package/src/runtime/renderToStream.js +0 -127
- package/src/runtime/renderToString.js +0 -121
- package/src/runtime/resume.js +0 -62
package/src/devtools/overlay.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
exposeDevToolsGlobal,
|
|
3
|
-
getDevToolsSnapshot
|
|
4
|
-
} from "./runtime.js";
|
|
5
|
-
let panel = null;
|
|
6
|
-
let refreshTimer = null;
|
|
7
|
-
function section(title, value) {
|
|
8
|
-
return `
|
|
9
|
-
<div style="margin-bottom:12px">
|
|
10
|
-
<div style="font-weight:700;margin-bottom:4px">${title}</div>
|
|
11
|
-
<pre style="white-space:pre-wrap;margin:0;font:12px ui-monospace,monospace">${value}</pre>
|
|
12
|
-
</div>
|
|
13
|
-
`;
|
|
14
|
-
}
|
|
15
|
-
function renderPanel() {
|
|
16
|
-
if (!panel) return;
|
|
17
|
-
const snapshot = getDevToolsSnapshot();
|
|
18
|
-
panel.innerHTML = `
|
|
19
|
-
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px">
|
|
20
|
-
<strong>Orvyn DevTools</strong>
|
|
21
|
-
<button data-orvyn-close style="border:0;background:#333;color:white;border-radius:6px;padding:4px 8px">Close</button>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
${section(
|
|
25
|
-
"Signals",
|
|
26
|
-
JSON.stringify(snapshot.signals, null, 2)
|
|
27
|
-
)}
|
|
28
|
-
|
|
29
|
-
${section(
|
|
30
|
-
"Effects",
|
|
31
|
-
JSON.stringify(snapshot.effects, null, 2)
|
|
32
|
-
)}
|
|
33
|
-
|
|
34
|
-
${section(
|
|
35
|
-
"Components",
|
|
36
|
-
JSON.stringify(snapshot.components, null, 2)
|
|
37
|
-
)}
|
|
38
|
-
|
|
39
|
-
${section(
|
|
40
|
-
"Dependency Graph",
|
|
41
|
-
JSON.stringify(snapshot.dependencyGraph, null, 2)
|
|
42
|
-
)}
|
|
43
|
-
|
|
44
|
-
${section(
|
|
45
|
-
"Render Profiler",
|
|
46
|
-
JSON.stringify(snapshot.renders.slice(-10), null, 2)
|
|
47
|
-
)}
|
|
48
|
-
`;
|
|
49
|
-
panel.querySelector("[data-orvyn-close]")?.addEventListener("click", () => {
|
|
50
|
-
panel?.remove();
|
|
51
|
-
panel = null;
|
|
52
|
-
if (refreshTimer !== null) {
|
|
53
|
-
clearInterval(refreshTimer);
|
|
54
|
-
refreshTimer = null;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function installDevToolsOverlay() {
|
|
59
|
-
if (typeof document === "undefined") return;
|
|
60
|
-
exposeDevToolsGlobal();
|
|
61
|
-
const toggle = document.createElement("button");
|
|
62
|
-
toggle.textContent = "Orvyn";
|
|
63
|
-
toggle.style.position = "fixed";
|
|
64
|
-
toggle.style.right = "16px";
|
|
65
|
-
toggle.style.bottom = "16px";
|
|
66
|
-
toggle.style.zIndex = "99999";
|
|
67
|
-
toggle.style.border = "0";
|
|
68
|
-
toggle.style.borderRadius = "8px";
|
|
69
|
-
toggle.style.padding = "10px 12px";
|
|
70
|
-
toggle.style.background = "#111";
|
|
71
|
-
toggle.style.color = "white";
|
|
72
|
-
toggle.style.font = "13px system-ui";
|
|
73
|
-
toggle.style.cursor = "pointer";
|
|
74
|
-
toggle.addEventListener("click", () => {
|
|
75
|
-
if (panel) {
|
|
76
|
-
renderPanel();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
panel = document.createElement("aside");
|
|
80
|
-
panel.style.position = "fixed";
|
|
81
|
-
panel.style.right = "16px";
|
|
82
|
-
panel.style.bottom = "64px";
|
|
83
|
-
panel.style.width = "420px";
|
|
84
|
-
panel.style.maxHeight = "72vh";
|
|
85
|
-
panel.style.overflow = "auto";
|
|
86
|
-
panel.style.zIndex = "99999";
|
|
87
|
-
panel.style.background = "white";
|
|
88
|
-
panel.style.color = "#111";
|
|
89
|
-
panel.style.border = "1px solid #ddd";
|
|
90
|
-
panel.style.borderRadius = "8px";
|
|
91
|
-
panel.style.boxShadow = "0 12px 40px rgba(0,0,0,0.2)";
|
|
92
|
-
panel.style.padding = "14px";
|
|
93
|
-
panel.style.font = "13px system-ui";
|
|
94
|
-
document.body.appendChild(panel);
|
|
95
|
-
renderPanel();
|
|
96
|
-
refreshTimer = window.setInterval(
|
|
97
|
-
renderPanel,
|
|
98
|
-
500
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
document.body.appendChild(toggle);
|
|
102
|
-
}
|
|
103
|
-
export {
|
|
104
|
-
installDevToolsOverlay
|
|
105
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { androidRenderer } from "../platforms/android/index.js";
|
|
2
|
-
import { iosRenderer } from "../platforms/ios/index.js";
|
|
3
|
-
import { webRenderer } from "../platforms/web/index.js";
|
|
4
|
-
const renderers = {
|
|
5
|
-
web: webRenderer,
|
|
6
|
-
ios: iosRenderer,
|
|
7
|
-
android: androidRenderer
|
|
8
|
-
};
|
|
9
|
-
function createRenderer(target = "web") {
|
|
10
|
-
const renderer = renderers[target];
|
|
11
|
-
if (!renderer) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`[Orvyn Renderer] Unknown target: ${target}`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
console.log("[Orvyn Renderer]");
|
|
17
|
-
console.log(`Target: ${target}`);
|
|
18
|
-
return renderer;
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
createRenderer
|
|
22
|
-
};
|
package/src/runtime/h.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { applyStyles } from "./style.js";
|
|
2
|
-
import { isStyleProp } from "../styling/fluid.js";
|
|
3
|
-
const nativeAppendChild = typeof Node !== "undefined" ? Node.prototype.appendChild : null;
|
|
4
|
-
function isSignal(value) {
|
|
5
|
-
return value && typeof value.get === "function" && typeof value.subscribe === "function";
|
|
6
|
-
}
|
|
7
|
-
function isVNode(value) {
|
|
8
|
-
return value && value.__orvynVNode === true;
|
|
9
|
-
}
|
|
10
|
-
function appendRendered(parent, child) {
|
|
11
|
-
const rendered = renderNode(child);
|
|
12
|
-
if (rendered && nativeAppendChild) {
|
|
13
|
-
nativeAppendChild.call(parent, rendered);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function renderNode(value) {
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
const fragment = document.createDocumentFragment();
|
|
19
|
-
value.forEach((child) => {
|
|
20
|
-
appendRendered(fragment, child);
|
|
21
|
-
});
|
|
22
|
-
return fragment;
|
|
23
|
-
}
|
|
24
|
-
if (isVNode(value)) {
|
|
25
|
-
return renderNode(
|
|
26
|
-
value.tag({
|
|
27
|
-
...value.props,
|
|
28
|
-
children: value.children
|
|
29
|
-
})
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
if (isSignal(value)) {
|
|
33
|
-
const textNode = document.createTextNode(
|
|
34
|
-
String(value.get())
|
|
35
|
-
);
|
|
36
|
-
value.subscribe(() => {
|
|
37
|
-
textNode.textContent = String(value.get());
|
|
38
|
-
});
|
|
39
|
-
return textNode;
|
|
40
|
-
}
|
|
41
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
42
|
-
return document.createTextNode(String(value));
|
|
43
|
-
}
|
|
44
|
-
if (value instanceof Node) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
if (nativeAppendChild && !Node.prototype.__orvynAppendPatched) {
|
|
50
|
-
Node.prototype.appendChild = function(child) {
|
|
51
|
-
const rendered = renderNode(child);
|
|
52
|
-
if (!rendered) {
|
|
53
|
-
return child;
|
|
54
|
-
}
|
|
55
|
-
return nativeAppendChild.call(this, rendered);
|
|
56
|
-
};
|
|
57
|
-
Node.prototype.__orvynAppendPatched = true;
|
|
58
|
-
}
|
|
59
|
-
function h(tag, props = {}, children = []) {
|
|
60
|
-
if (typeof tag === "function") {
|
|
61
|
-
return {
|
|
62
|
-
__orvynVNode: true,
|
|
63
|
-
tag,
|
|
64
|
-
props,
|
|
65
|
-
children
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const el = document.createElement(tag);
|
|
69
|
-
applyStyles(el, props);
|
|
70
|
-
for (const key in props) {
|
|
71
|
-
if (key === "class" || key === "className" || key === "nativeRole") {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (key.startsWith("on")) {
|
|
75
|
-
el.addEventListener(
|
|
76
|
-
key.slice(2).toLowerCase(),
|
|
77
|
-
props[key]
|
|
78
|
-
);
|
|
79
|
-
} else if (!isStyleProp(key)) {
|
|
80
|
-
el.setAttribute(
|
|
81
|
-
key === "className" ? "class" : key,
|
|
82
|
-
props[key]
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
children.forEach((child) => {
|
|
87
|
-
appendRendered(el, child);
|
|
88
|
-
});
|
|
89
|
-
return el;
|
|
90
|
-
}
|
|
91
|
-
export {
|
|
92
|
-
h
|
|
93
|
-
};
|
package/src/runtime/hydrate.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
function isSignal(value) {
|
|
2
|
-
return value && typeof value.get === "function";
|
|
3
|
-
}
|
|
4
|
-
function normalizeChildren(children = []) {
|
|
5
|
-
return children.flatMap((child) => {
|
|
6
|
-
if (Array.isArray(child)) {
|
|
7
|
-
return normalizeChildren(child);
|
|
8
|
-
}
|
|
9
|
-
if (child === null || child === void 0 || child === false) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
return [child];
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
function hydrate(vnode, el) {
|
|
16
|
-
if (!vnode || !el) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (typeof vnode === "string" || typeof vnode === "number") {
|
|
20
|
-
el.textContent = String(vnode);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (isSignal(vnode)) {
|
|
24
|
-
el.textContent = String(vnode.get());
|
|
25
|
-
vnode.subscribe(() => {
|
|
26
|
-
el.textContent = String(vnode.get());
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof vnode.tag === "function") {
|
|
31
|
-
hydrate(
|
|
32
|
-
vnode.tag({
|
|
33
|
-
...vnode.props,
|
|
34
|
-
children: vnode.children
|
|
35
|
-
}),
|
|
36
|
-
el
|
|
37
|
-
);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
for (const key in vnode.props) {
|
|
41
|
-
if (key.startsWith("on")) {
|
|
42
|
-
el.addEventListener(
|
|
43
|
-
key.slice(2).toLowerCase(),
|
|
44
|
-
vnode.props[key]
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
normalizeChildren(vnode.children).forEach(
|
|
49
|
-
(child, index) => {
|
|
50
|
-
hydrate(
|
|
51
|
-
child,
|
|
52
|
-
el.childNodes[index]
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
58
|
-
hydrate
|
|
59
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createVNode } from "./vnode.js";
|
|
2
|
-
function jsx(tag, props) {
|
|
3
|
-
return createVNode(
|
|
4
|
-
tag,
|
|
5
|
-
props,
|
|
6
|
-
props?.children ? Array.isArray(props.children) ? props.children : [props.children] : []
|
|
7
|
-
);
|
|
8
|
-
}
|
|
9
|
-
const jsxs = jsx;
|
|
10
|
-
export {
|
|
11
|
-
jsx,
|
|
12
|
-
jsxs
|
|
13
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { hydrate } from "./hydrate.js";
|
|
2
|
-
function isVNode(value) {
|
|
3
|
-
return value && typeof value === "object" && "tag" in value && "props" in value && "children" in value;
|
|
4
|
-
}
|
|
5
|
-
function resolveComponent(vnode) {
|
|
6
|
-
if (isVNode(vnode) && typeof vnode.tag === "function") {
|
|
7
|
-
return resolveComponent(
|
|
8
|
-
vnode.tag({
|
|
9
|
-
...vnode.props,
|
|
10
|
-
children: vnode.children
|
|
11
|
-
})
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return vnode;
|
|
15
|
-
}
|
|
16
|
-
function getHydrationMode(vnode, fallback) {
|
|
17
|
-
const value = vnode?.props?.hydrate;
|
|
18
|
-
if (value === false) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (value === true) {
|
|
22
|
-
return fallback;
|
|
23
|
-
}
|
|
24
|
-
if (value === "load" || value === "idle" || value === "visible" || value === "interaction" || value === "manual") {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
function hydrateOnce(vnode, el) {
|
|
30
|
-
if (!el || el.__orvynHydrated) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
hydrate(vnode, el);
|
|
34
|
-
el.__orvynHydrated = true;
|
|
35
|
-
}
|
|
36
|
-
function hydrateWhenVisible(vnode, el) {
|
|
37
|
-
if (typeof IntersectionObserver === "undefined") {
|
|
38
|
-
hydrateOnce(vnode, el);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const observer = new IntersectionObserver((entries) => {
|
|
42
|
-
if (entries.some((entry) => entry.isIntersecting)) {
|
|
43
|
-
observer.disconnect();
|
|
44
|
-
hydrateOnce(vnode, el);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
observer.observe(el);
|
|
48
|
-
}
|
|
49
|
-
function hydrateOnInteraction(vnode, el) {
|
|
50
|
-
const events = [
|
|
51
|
-
"click",
|
|
52
|
-
"input",
|
|
53
|
-
"focus",
|
|
54
|
-
"pointerenter"
|
|
55
|
-
];
|
|
56
|
-
const run = () => {
|
|
57
|
-
events.forEach((event) => {
|
|
58
|
-
el.removeEventListener(
|
|
59
|
-
event,
|
|
60
|
-
run,
|
|
61
|
-
true
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
hydrateOnce(vnode, el);
|
|
65
|
-
};
|
|
66
|
-
events.forEach((event) => {
|
|
67
|
-
el.addEventListener(
|
|
68
|
-
event,
|
|
69
|
-
run,
|
|
70
|
-
true
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function scheduleHydration(vnode, el, mode) {
|
|
75
|
-
if (mode === "manual") {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (mode === "load") {
|
|
79
|
-
hydrateOnce(vnode, el);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (mode === "idle") {
|
|
83
|
-
const run = typeof requestIdleCallback === "function" ? requestIdleCallback : (callback) => {
|
|
84
|
-
return setTimeout(() => {
|
|
85
|
-
callback({
|
|
86
|
-
didTimeout: false,
|
|
87
|
-
timeRemaining: () => 0
|
|
88
|
-
});
|
|
89
|
-
}, 1);
|
|
90
|
-
};
|
|
91
|
-
run(() => {
|
|
92
|
-
hydrateOnce(vnode, el);
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (mode === "visible") {
|
|
97
|
-
hydrateWhenVisible(vnode, el);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
hydrateOnInteraction(vnode, el);
|
|
101
|
-
}
|
|
102
|
-
function partialHydrate(vnode, el, options = {}) {
|
|
103
|
-
if (!vnode || !el) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const defaultMode = options.defaultMode || "idle";
|
|
107
|
-
const resolved = resolveComponent(vnode);
|
|
108
|
-
if (!isVNode(resolved)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const mode = getHydrationMode(
|
|
112
|
-
resolved,
|
|
113
|
-
defaultMode
|
|
114
|
-
);
|
|
115
|
-
if (mode) {
|
|
116
|
-
scheduleHydration(
|
|
117
|
-
resolved,
|
|
118
|
-
el,
|
|
119
|
-
mode
|
|
120
|
-
);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (mode === false) {
|
|
124
|
-
resolved.children.forEach(
|
|
125
|
-
(child, index) => {
|
|
126
|
-
partialHydrate(
|
|
127
|
-
child,
|
|
128
|
-
el.childNodes[index],
|
|
129
|
-
options
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
resolved.children.forEach(
|
|
136
|
-
(child, index) => {
|
|
137
|
-
partialHydrate(
|
|
138
|
-
child,
|
|
139
|
-
el.childNodes[index],
|
|
140
|
-
options
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
function hydrateIsland(vnode, el) {
|
|
146
|
-
hydrateOnce(
|
|
147
|
-
resolveComponent(vnode),
|
|
148
|
-
el
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
export {
|
|
152
|
-
hydrateIsland,
|
|
153
|
-
partialHydrate
|
|
154
|
-
};
|
package/src/runtime/platform.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const profiles = {
|
|
2
|
-
desktop: {
|
|
3
|
-
platform: "desktop",
|
|
4
|
-
renderer: "web",
|
|
5
|
-
width: 1440,
|
|
6
|
-
height: 900,
|
|
7
|
-
density: 1,
|
|
8
|
-
safeArea: {
|
|
9
|
-
top: 0,
|
|
10
|
-
right: 0,
|
|
11
|
-
bottom: 0,
|
|
12
|
-
left: 0
|
|
13
|
-
},
|
|
14
|
-
touch: false
|
|
15
|
-
},
|
|
16
|
-
tablet: {
|
|
17
|
-
platform: "tablet",
|
|
18
|
-
renderer: "web",
|
|
19
|
-
width: 768,
|
|
20
|
-
height: 1024,
|
|
21
|
-
density: 1.5,
|
|
22
|
-
safeArea: {
|
|
23
|
-
top: 0,
|
|
24
|
-
right: 0,
|
|
25
|
-
bottom: 0,
|
|
26
|
-
left: 0
|
|
27
|
-
},
|
|
28
|
-
touch: true
|
|
29
|
-
},
|
|
30
|
-
iphone: {
|
|
31
|
-
platform: "iphone",
|
|
32
|
-
renderer: "ios",
|
|
33
|
-
width: 390,
|
|
34
|
-
height: 844,
|
|
35
|
-
density: 3,
|
|
36
|
-
safeArea: {
|
|
37
|
-
top: 44,
|
|
38
|
-
right: 0,
|
|
39
|
-
bottom: 34,
|
|
40
|
-
left: 0
|
|
41
|
-
},
|
|
42
|
-
touch: true
|
|
43
|
-
},
|
|
44
|
-
android: {
|
|
45
|
-
platform: "android",
|
|
46
|
-
renderer: "android",
|
|
47
|
-
width: 412,
|
|
48
|
-
height: 915,
|
|
49
|
-
density: 2.75,
|
|
50
|
-
safeArea: {
|
|
51
|
-
top: 24,
|
|
52
|
-
right: 0,
|
|
53
|
-
bottom: 16,
|
|
54
|
-
left: 0
|
|
55
|
-
},
|
|
56
|
-
touch: true
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
let currentPlatform = "desktop";
|
|
60
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
61
|
-
function applyPlatformToDocument(profile) {
|
|
62
|
-
if (typeof document === "undefined") {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const root = document.documentElement;
|
|
66
|
-
root.dataset.orvynPlatform = profile.platform;
|
|
67
|
-
root.dataset.orvynRenderer = profile.renderer;
|
|
68
|
-
root.style.setProperty(
|
|
69
|
-
"--orvyn-viewport-width",
|
|
70
|
-
`${profile.width}px`
|
|
71
|
-
);
|
|
72
|
-
root.style.setProperty(
|
|
73
|
-
"--orvyn-viewport-height",
|
|
74
|
-
`${profile.height}px`
|
|
75
|
-
);
|
|
76
|
-
root.style.setProperty(
|
|
77
|
-
"--orvyn-safe-area-top",
|
|
78
|
-
`${profile.safeArea.top}px`
|
|
79
|
-
);
|
|
80
|
-
root.style.setProperty(
|
|
81
|
-
"--orvyn-safe-area-right",
|
|
82
|
-
`${profile.safeArea.right}px`
|
|
83
|
-
);
|
|
84
|
-
root.style.setProperty(
|
|
85
|
-
"--orvyn-safe-area-bottom",
|
|
86
|
-
`${profile.safeArea.bottom}px`
|
|
87
|
-
);
|
|
88
|
-
root.style.setProperty(
|
|
89
|
-
"--orvyn-safe-area-left",
|
|
90
|
-
`${profile.safeArea.left}px`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
function getPlatform() {
|
|
94
|
-
return currentPlatform;
|
|
95
|
-
}
|
|
96
|
-
function getPlatformProfile(platform = currentPlatform) {
|
|
97
|
-
return profiles[platform];
|
|
98
|
-
}
|
|
99
|
-
function setPlatform(platform) {
|
|
100
|
-
if (!profiles[platform]) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
currentPlatform = platform;
|
|
104
|
-
const profile = getPlatformProfile(platform);
|
|
105
|
-
applyPlatformToDocument(profile);
|
|
106
|
-
subscribers.forEach((subscriber) => {
|
|
107
|
-
subscriber(profile);
|
|
108
|
-
});
|
|
109
|
-
if (typeof window !== "undefined") {
|
|
110
|
-
window.dispatchEvent(
|
|
111
|
-
new CustomEvent(
|
|
112
|
-
"orvyn:platform",
|
|
113
|
-
{ detail: profile }
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function subscribePlatform(subscriber) {
|
|
119
|
-
subscribers.add(subscriber);
|
|
120
|
-
subscriber(getPlatformProfile());
|
|
121
|
-
return () => {
|
|
122
|
-
subscribers.delete(subscriber);
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function getDeviceProfiles() {
|
|
126
|
-
return profiles;
|
|
127
|
-
}
|
|
128
|
-
setPlatform(currentPlatform);
|
|
129
|
-
export {
|
|
130
|
-
getDeviceProfiles,
|
|
131
|
-
getPlatform,
|
|
132
|
-
getPlatformProfile,
|
|
133
|
-
setPlatform,
|
|
134
|
-
subscribePlatform
|
|
135
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFluidUtilityDeclarations,
|
|
3
|
-
getResolvedClassName,
|
|
4
|
-
getResponsiveStyleRules,
|
|
5
|
-
getStyleDeclarations,
|
|
6
|
-
isStyleProp
|
|
7
|
-
} from "../styling/fluid.js";
|
|
8
|
-
function isSignal(value) {
|
|
9
|
-
return value && typeof value.get === "function";
|
|
10
|
-
}
|
|
11
|
-
function escapeHtml(value) {
|
|
12
|
-
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
13
|
-
}
|
|
14
|
-
function escapeStyleText(value) {
|
|
15
|
-
return String(value).replace(/<\/style/gi, "<\\/style");
|
|
16
|
-
}
|
|
17
|
-
function readValue(value) {
|
|
18
|
-
return isSignal(value) ? value.get() : value;
|
|
19
|
-
}
|
|
20
|
-
function renderAttributes(props = {}) {
|
|
21
|
-
const attrs = [];
|
|
22
|
-
const styles = [];
|
|
23
|
-
const className = getResolvedClassName(props);
|
|
24
|
-
if (className) {
|
|
25
|
-
attrs.push(
|
|
26
|
-
`class="${escapeHtml(className)}"`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
getFluidUtilityDeclarations(
|
|
30
|
-
readValue(props.className || props.class),
|
|
31
|
-
"css"
|
|
32
|
-
).forEach((declaration) => {
|
|
33
|
-
styles.push(
|
|
34
|
-
`${declaration.property}: ${escapeHtml(declaration.value)}`
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
for (const key in props) {
|
|
38
|
-
if (key === "children" || key === "key" || key === "class" || key === "className" || key === "nativeRole" || key.startsWith("on")) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const value = readValue(props[key]);
|
|
42
|
-
if (value === false || value === null || value === void 0) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (key === "hydrate") {
|
|
46
|
-
attrs.push(
|
|
47
|
-
`data-orvyn-hydrate="${escapeHtml(
|
|
48
|
-
value === true ? "idle" : value
|
|
49
|
-
)}"`
|
|
50
|
-
);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (key === "resume") {
|
|
54
|
-
attrs.push(
|
|
55
|
-
`data-orvyn-resume="${escapeHtml(
|
|
56
|
-
value === true ? "true" : value
|
|
57
|
-
)}"`
|
|
58
|
-
);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (isStyleProp(key)) {
|
|
62
|
-
getStyleDeclarations(key, value, "css").forEach((declaration) => {
|
|
63
|
-
styles.push(
|
|
64
|
-
`${declaration.property}: ${escapeHtml(
|
|
65
|
-
declaration.value
|
|
66
|
-
)}`
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (value === true) {
|
|
72
|
-
attrs.push(escapeHtml(key));
|
|
73
|
-
} else {
|
|
74
|
-
attrs.push(
|
|
75
|
-
`${escapeHtml(key)}="${escapeHtml(value)}"`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (styles.length > 0) {
|
|
80
|
-
attrs.push(
|
|
81
|
-
`style="${styles.join("; ")}"`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
85
|
-
}
|
|
86
|
-
async function* renderToStream(vnode) {
|
|
87
|
-
if (vnode === null || vnode === void 0 || vnode === false) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (Array.isArray(vnode)) {
|
|
91
|
-
for (const child of vnode) {
|
|
92
|
-
yield* renderToStream(child);
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (typeof vnode === "string" || typeof vnode === "number") {
|
|
97
|
-
yield escapeHtml(vnode);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (isSignal(vnode)) {
|
|
101
|
-
yield escapeHtml(
|
|
102
|
-
vnode.get()
|
|
103
|
-
);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (typeof vnode.tag === "function") {
|
|
107
|
-
yield* renderToStream(
|
|
108
|
-
vnode.tag({
|
|
109
|
-
...vnode.props,
|
|
110
|
-
children: vnode.children
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const responsiveStyles = getResponsiveStyleRules(vnode.props);
|
|
116
|
-
if (responsiveStyles) {
|
|
117
|
-
yield `<style data-orvyn-responsive>${escapeStyleText(responsiveStyles)}</style>`;
|
|
118
|
-
}
|
|
119
|
-
yield `<${vnode.tag}${renderAttributes(vnode.props)}>`;
|
|
120
|
-
for (const child of vnode.children) {
|
|
121
|
-
yield* renderToStream(child);
|
|
122
|
-
}
|
|
123
|
-
yield `</${vnode.tag}>`;
|
|
124
|
-
}
|
|
125
|
-
export {
|
|
126
|
-
renderToStream
|
|
127
|
-
};
|