@teamvelix/velix 5.0.3 → 5.0.4
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/dist/build/index.js +4 -587
- package/dist/build/index.js.map +1 -1
- package/dist/chunk-7SGDYOVZ.js +136 -0
- package/dist/chunk-7SGDYOVZ.js.map +1 -0
- package/dist/chunk-F24Q2MX3.js +126 -0
- package/dist/chunk-F24Q2MX3.js.map +1 -0
- package/dist/chunk-INOZP2VD.js +165 -0
- package/dist/chunk-INOZP2VD.js.map +1 -0
- package/dist/chunk-NVTZ6HRX.js +2089 -0
- package/dist/chunk-NVTZ6HRX.js.map +1 -0
- package/dist/chunk-OIZNYND3.js +176 -0
- package/dist/chunk-OIZNYND3.js.map +1 -0
- package/dist/chunk-SPIGTNT7.js +406 -0
- package/dist/chunk-SPIGTNT7.js.map +1 -0
- package/dist/client/index.js +2 -147
- package/dist/client/index.js.map +1 -1
- package/dist/config.js +2 -128
- package/dist/config.js.map +1 -1
- package/dist/image-optimizer-I6TWWH6W.js +66 -0
- package/dist/image-optimizer-I6TWWH6W.js.map +1 -0
- package/dist/{index-l0dwPa62.d.ts → index-DYgxL3mE.d.ts} +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -3318
- package/dist/index.js.map +1 -1
- package/dist/islands/index.js +2 -181
- package/dist/islands/index.js.map +1 -1
- package/dist/runtime/start-dev.js +12 -2395
- package/dist/runtime/start-dev.js.map +1 -1
- package/dist/runtime/start-prod.js +5 -2387
- package/dist/runtime/start-prod.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +5 -2491
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/islands/index.js
CHANGED
|
@@ -1,182 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import crypto from "crypto";
|
|
4
|
-
var islandRegistry = /* @__PURE__ */ new Map();
|
|
5
|
-
function generateIslandId(componentName) {
|
|
6
|
-
const hash = crypto.randomBytes(4).toString("hex");
|
|
7
|
-
return `island-${componentName}-${hash}`;
|
|
8
|
-
}
|
|
9
|
-
function Island({ component: Component, props = {}, name, clientPath }) {
|
|
10
|
-
const islandId = generateIslandId(name);
|
|
11
|
-
islandRegistry.set(islandId, { id: islandId, name, clientPath, props });
|
|
12
|
-
return React.createElement("div", {
|
|
13
|
-
"data-island": islandId,
|
|
14
|
-
"data-island-name": name,
|
|
15
|
-
"data-island-props": JSON.stringify(props)
|
|
16
|
-
}, React.createElement(Component, props));
|
|
17
|
-
}
|
|
18
|
-
function getRegisteredIslands() {
|
|
19
|
-
const islands = Array.from(islandRegistry.values());
|
|
20
|
-
islandRegistry.clear();
|
|
21
|
-
return islands;
|
|
22
|
-
}
|
|
23
|
-
function createIsland(Component, options = {}) {
|
|
24
|
-
const { name = Component.name || "Island", clientPath } = options;
|
|
25
|
-
function IslandWrapper(props) {
|
|
26
|
-
return Island({
|
|
27
|
-
component: Component,
|
|
28
|
-
props,
|
|
29
|
-
name,
|
|
30
|
-
clientPath: clientPath || `/__velix/islands/${name}.js`
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
IslandWrapper.displayName = `Island(${name})`;
|
|
34
|
-
IslandWrapper.isIsland = true;
|
|
35
|
-
IslandWrapper.originalComponent = Component;
|
|
36
|
-
return IslandWrapper;
|
|
37
|
-
}
|
|
38
|
-
var LoadStrategy = {
|
|
39
|
-
IMMEDIATE: "immediate",
|
|
40
|
-
VISIBLE: "visible",
|
|
41
|
-
IDLE: "idle",
|
|
42
|
-
MEDIA: "media"
|
|
43
|
-
};
|
|
44
|
-
function createLazyIsland(Component, options = {}) {
|
|
45
|
-
const {
|
|
46
|
-
name = Component.name || "LazyIsland",
|
|
47
|
-
clientPath,
|
|
48
|
-
strategy = LoadStrategy.VISIBLE,
|
|
49
|
-
media = null
|
|
50
|
-
} = options;
|
|
51
|
-
function LazyIslandWrapper(props) {
|
|
52
|
-
const islandId = generateIslandId(name);
|
|
53
|
-
islandRegistry.set(islandId, {
|
|
54
|
-
id: islandId,
|
|
55
|
-
name,
|
|
56
|
-
clientPath: clientPath || `/__velix/islands/${name}.js`,
|
|
57
|
-
props,
|
|
58
|
-
strategy,
|
|
59
|
-
media
|
|
60
|
-
});
|
|
61
|
-
return React.createElement("div", {
|
|
62
|
-
"data-island": islandId,
|
|
63
|
-
"data-island-name": name,
|
|
64
|
-
"data-island-strategy": strategy,
|
|
65
|
-
"data-island-media": media,
|
|
66
|
-
"data-island-props": JSON.stringify(props)
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
LazyIslandWrapper.displayName = `LazyIsland(${name})`;
|
|
70
|
-
LazyIslandWrapper.isIsland = true;
|
|
71
|
-
LazyIslandWrapper.isLazy = true;
|
|
72
|
-
return LazyIslandWrapper;
|
|
73
|
-
}
|
|
74
|
-
function generateHydrationScript(islands) {
|
|
75
|
-
if (!islands.length) return "";
|
|
76
|
-
const islandData = islands.map((island) => ({
|
|
77
|
-
id: island.id,
|
|
78
|
-
name: island.name,
|
|
79
|
-
path: island.clientPath,
|
|
80
|
-
props: island.props
|
|
81
|
-
}));
|
|
82
|
-
return `
|
|
83
|
-
<script type="module">
|
|
84
|
-
const islands = ${JSON.stringify(islandData)};
|
|
85
|
-
|
|
86
|
-
async function hydrateIslands() {
|
|
87
|
-
const { hydrateRoot } = await import('/__velix/react-dom-client.js');
|
|
88
|
-
const React = await import('/__velix/react.js');
|
|
89
|
-
|
|
90
|
-
for (const island of islands) {
|
|
91
|
-
try {
|
|
92
|
-
const el = document.querySelector(\`[data-island="\${island.id}"]\`);
|
|
93
|
-
if (!el) continue;
|
|
94
|
-
const mod = await import(island.path);
|
|
95
|
-
hydrateRoot(el, React.createElement(mod.default, island.props));
|
|
96
|
-
el.setAttribute('data-hydrated', 'true');
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error(\`Failed to hydrate island \${island.name}:\`, error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (document.readyState === 'loading') {
|
|
104
|
-
document.addEventListener('DOMContentLoaded', hydrateIslands);
|
|
105
|
-
} else {
|
|
106
|
-
hydrateIslands();
|
|
107
|
-
}
|
|
108
|
-
</script>`;
|
|
109
|
-
}
|
|
110
|
-
function generateAdvancedHydrationScript(islands) {
|
|
111
|
-
if (!islands.length) return "";
|
|
112
|
-
const islandData = islands.map((island) => ({
|
|
113
|
-
id: island.id,
|
|
114
|
-
name: island.name,
|
|
115
|
-
path: island.clientPath,
|
|
116
|
-
props: island.props,
|
|
117
|
-
strategy: island.strategy || LoadStrategy.IMMEDIATE,
|
|
118
|
-
media: island.media
|
|
119
|
-
}));
|
|
120
|
-
return `
|
|
121
|
-
<script type="module">
|
|
122
|
-
const islands = ${JSON.stringify(islandData)};
|
|
123
|
-
|
|
124
|
-
async function hydrateIsland(island) {
|
|
125
|
-
const el = document.querySelector(\`[data-island="\${island.id}"]\`);
|
|
126
|
-
if (!el || el.hasAttribute('data-hydrated')) return;
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const { hydrateRoot } = await import('/__velix/react-dom-client.js');
|
|
130
|
-
const React = await import('/__velix/react.js');
|
|
131
|
-
const mod = await import(island.path);
|
|
132
|
-
hydrateRoot(el, React.createElement(mod.default, island.props));
|
|
133
|
-
el.setAttribute('data-hydrated', 'true');
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.error(\`Failed to hydrate island \${island.name}:\`, error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const visibleObserver = new IntersectionObserver((entries) => {
|
|
140
|
-
entries.forEach(entry => {
|
|
141
|
-
if (entry.isIntersecting) {
|
|
142
|
-
const id = entry.target.getAttribute('data-island');
|
|
143
|
-
const island = islands.find(i => i.id === id);
|
|
144
|
-
if (island) { hydrateIsland(island); visibleObserver.unobserve(entry.target); }
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}, { rootMargin: '50px' });
|
|
148
|
-
|
|
149
|
-
function processIslands() {
|
|
150
|
-
for (const island of islands) {
|
|
151
|
-
const el = document.querySelector(\`[data-island="\${island.id}"]\`);
|
|
152
|
-
if (!el) continue;
|
|
153
|
-
switch (island.strategy) {
|
|
154
|
-
case 'immediate': hydrateIsland(island); break;
|
|
155
|
-
case 'visible': visibleObserver.observe(el); break;
|
|
156
|
-
case 'idle': requestIdleCallback(() => hydrateIsland(island)); break;
|
|
157
|
-
case 'media':
|
|
158
|
-
if (island.media && window.matchMedia(island.media).matches) hydrateIsland(island);
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (document.readyState === 'loading') {
|
|
165
|
-
document.addEventListener('DOMContentLoaded', processIslands);
|
|
166
|
-
} else {
|
|
167
|
-
processIslands();
|
|
168
|
-
}
|
|
169
|
-
</script>`;
|
|
170
|
-
}
|
|
171
|
-
var islands_default = { Island, createIsland, createLazyIsland, getRegisteredIslands, generateHydrationScript, generateAdvancedHydrationScript, LoadStrategy };
|
|
172
|
-
export {
|
|
173
|
-
Island,
|
|
174
|
-
LoadStrategy,
|
|
175
|
-
createIsland,
|
|
176
|
-
createLazyIsland,
|
|
177
|
-
islands_default as default,
|
|
178
|
-
generateAdvancedHydrationScript,
|
|
179
|
-
generateHydrationScript,
|
|
180
|
-
getRegisteredIslands
|
|
181
|
-
};
|
|
1
|
+
export { Island, LoadStrategy, createIsland, createLazyIsland, islands_default as default, generateAdvancedHydrationScript, generateHydrationScript, getRegisteredIslands } from '../chunk-OIZNYND3.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
182
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|