orvyn-lang 0.1.1 → 0.2.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/LANGUAGE.md +139 -3
- package/README.md +136 -1
- package/package.json +1 -1
- package/src/cli/orvyn.js +31 -480
- package/src/lang/codegen.js +90 -27
- package/src/lang/form.js +99 -0
- package/src/lang/native/android/OrvynRenderer.kt +5 -0
- package/src/lang/native/ios/OrvynEngine.swift +2 -0
- package/src/lang/native/ios/OrvynViews.swift +3 -0
- package/src/lang/native-runtime.js +22 -6
- package/src/lang/runtime-shared.js +28 -0
- package/src/lang/runtime.js +14 -1
- package/src/lang/validation.js +55 -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
|
@@ -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
|
-
};
|
|
@@ -1,121 +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
|
-
if (value === true) {
|
|
47
|
-
attrs.push(`data-orvyn-hydrate="idle"`);
|
|
48
|
-
} else {
|
|
49
|
-
attrs.push(
|
|
50
|
-
`data-orvyn-hydrate="${escapeHtml(value)}"`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (key === "resume") {
|
|
56
|
-
if (value === true) {
|
|
57
|
-
attrs.push(`data-orvyn-resume="true"`);
|
|
58
|
-
} else {
|
|
59
|
-
attrs.push(
|
|
60
|
-
`data-orvyn-resume="${escapeHtml(value)}"`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (isStyleProp(key)) {
|
|
66
|
-
getStyleDeclarations(key, value, "css").forEach((declaration) => {
|
|
67
|
-
styles.push(
|
|
68
|
-
`${declaration.property}: ${escapeHtml(
|
|
69
|
-
declaration.value
|
|
70
|
-
)}`
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (value === true) {
|
|
76
|
-
attrs.push(escapeHtml(key));
|
|
77
|
-
} else {
|
|
78
|
-
attrs.push(
|
|
79
|
-
`${escapeHtml(key)}="${escapeHtml(value)}"`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (styles.length > 0) {
|
|
84
|
-
attrs.push(
|
|
85
|
-
`style="${styles.join("; ")}"`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
89
|
-
}
|
|
90
|
-
function renderToString(vnode) {
|
|
91
|
-
if (vnode === null || vnode === void 0 || vnode === false) {
|
|
92
|
-
return "";
|
|
93
|
-
}
|
|
94
|
-
if (Array.isArray(vnode)) {
|
|
95
|
-
return vnode.map(renderToString).join("");
|
|
96
|
-
}
|
|
97
|
-
if (typeof vnode === "string" || typeof vnode === "number") {
|
|
98
|
-
return escapeHtml(vnode);
|
|
99
|
-
}
|
|
100
|
-
if (isSignal(vnode)) {
|
|
101
|
-
return escapeHtml(
|
|
102
|
-
vnode.get()
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
if (typeof vnode.tag === "function") {
|
|
106
|
-
return renderToString(
|
|
107
|
-
vnode.tag({
|
|
108
|
-
...vnode.props,
|
|
109
|
-
children: vnode.children
|
|
110
|
-
})
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
const children = vnode.children.map(renderToString).join("");
|
|
114
|
-
const attrs = renderAttributes(vnode.props);
|
|
115
|
-
const responsiveStyles = getResponsiveStyleRules(vnode.props);
|
|
116
|
-
const responsiveStyleTag = responsiveStyles ? `<style data-orvyn-responsive>${escapeStyleText(responsiveStyles)}</style>` : "";
|
|
117
|
-
return `${responsiveStyleTag}<${vnode.tag}${attrs}>${children}</${vnode.tag}>`;
|
|
118
|
-
}
|
|
119
|
-
export {
|
|
120
|
-
renderToString
|
|
121
|
-
};
|
package/src/runtime/resume.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
restoreSignalState,
|
|
3
|
-
serializeReactiveGraph,
|
|
4
|
-
serializeSignalState
|
|
5
|
-
} from "../core/signal.js";
|
|
6
|
-
import {
|
|
7
|
-
partialHydrate
|
|
8
|
-
} from "./partialHydration.js";
|
|
9
|
-
import { renderToString } from "./renderToString.js";
|
|
10
|
-
const snapshotId = "orvyn-resume-state";
|
|
11
|
-
function escapeJson(value) {
|
|
12
|
-
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
13
|
-
}
|
|
14
|
-
function createResumeSnapshot() {
|
|
15
|
-
return {
|
|
16
|
-
version: 1,
|
|
17
|
-
signals: serializeSignalState(),
|
|
18
|
-
graph: serializeReactiveGraph()
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function renderResumeState(snapshot = createResumeSnapshot()) {
|
|
22
|
-
return `<script type="application/json" id="${snapshotId}">${escapeJson(snapshot)}<\/script>`;
|
|
23
|
-
}
|
|
24
|
-
function renderResumable(vnode) {
|
|
25
|
-
return [
|
|
26
|
-
renderToString(vnode),
|
|
27
|
-
renderResumeState()
|
|
28
|
-
].join("");
|
|
29
|
-
}
|
|
30
|
-
function readResumeSnapshot(root = document) {
|
|
31
|
-
const el = root.querySelector?.(`#${snapshotId}`);
|
|
32
|
-
if (!el || !el.textContent) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return JSON.parse(
|
|
36
|
-
el.textContent
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
function restoreResumeState(snapshot) {
|
|
40
|
-
if (!snapshot) return;
|
|
41
|
-
restoreSignalState(
|
|
42
|
-
snapshot.signals
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
function resume(vnode, el, options = {}) {
|
|
46
|
-
const snapshot = readResumeSnapshot();
|
|
47
|
-
restoreResumeState(snapshot);
|
|
48
|
-
partialHydrate(
|
|
49
|
-
vnode,
|
|
50
|
-
el,
|
|
51
|
-
options
|
|
52
|
-
);
|
|
53
|
-
return snapshot;
|
|
54
|
-
}
|
|
55
|
-
export {
|
|
56
|
-
createResumeSnapshot,
|
|
57
|
-
readResumeSnapshot,
|
|
58
|
-
renderResumable,
|
|
59
|
-
renderResumeState,
|
|
60
|
-
restoreResumeState,
|
|
61
|
-
resume
|
|
62
|
-
};
|