@estjs/template 0.0.15-beta.13 → 0.0.15-beta.17
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/chunk-3E4EK64L.dev.esm.js +152 -0
- package/dist/chunk-3E4EK64L.dev.esm.js.map +1 -0
- package/dist/chunk-IRDMO5MX.esm.js +2 -0
- package/dist/chunk-IRDMO5MX.esm.js.map +1 -0
- package/dist/internal-Bz6h0aPa.d.cts +84 -0
- package/dist/internal-Bz6h0aPa.d.ts +84 -0
- package/dist/internal.cjs.js +2 -0
- package/dist/internal.cjs.js.map +1 -0
- package/dist/internal.d.cts +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.dev.cjs.js +110 -0
- package/dist/internal.dev.cjs.js.map +1 -0
- package/dist/internal.dev.esm.js +3 -0
- package/dist/internal.dev.esm.js.map +1 -0
- package/dist/internal.esm.js +2 -0
- package/dist/internal.esm.js.map +1 -0
- package/dist/template.cjs.js +2 -2
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +423 -341
- package/dist/template.d.ts +423 -341
- package/dist/template.dev.cjs.js +1464 -1311
- package/dist/template.dev.cjs.js.map +1 -1
- package/dist/template.dev.esm.js +1393 -1381
- package/dist/template.dev.esm.js.map +1 -1
- package/dist/template.esm.js +2 -2
- package/dist/template.esm.js.map +1 -1
- package/package.json +13 -3
package/dist/template.dev.cjs.js
CHANGED
|
@@ -3,21 +3,20 @@
|
|
|
3
3
|
var shared = require('@estjs/shared');
|
|
4
4
|
var signals = require('@estjs/signals');
|
|
5
5
|
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
for (var prop in
|
|
13
|
-
if (__hasOwnProp.call(
|
|
14
|
-
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(
|
|
17
|
-
if (__propIsEnum.call(
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return
|
|
9
|
+
var __objRest = (source, exclude) => {
|
|
10
|
+
var target = {};
|
|
11
|
+
for (var prop in source)
|
|
12
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
13
|
+
target[prop] = source[prop];
|
|
14
|
+
if (source != null && __getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
16
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
17
|
+
target[prop] = source[prop];
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
21
20
|
};
|
|
22
21
|
var __async = (__this, __arguments, generator) => {
|
|
23
22
|
return new Promise((resolve, reject) => {
|
|
@@ -39,14 +38,23 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
38
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
39
|
});
|
|
41
40
|
};
|
|
41
|
+
|
|
42
|
+
// src/constants.ts
|
|
43
|
+
var SPREAD_NAME = "_$spread$";
|
|
44
|
+
var REF_KEY = "ref";
|
|
45
|
+
var KEY_PROP = "key";
|
|
46
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
47
|
+
var XLINK_NAMESPACE = "http://www.w3.org/2000/xlink";
|
|
48
|
+
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
49
|
+
var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
|
|
50
|
+
var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
|
|
51
|
+
var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
|
|
52
|
+
var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
|
|
42
53
|
var activeScope = null;
|
|
43
54
|
var scopeId = 0;
|
|
44
55
|
function getActiveScope() {
|
|
45
56
|
return activeScope;
|
|
46
57
|
}
|
|
47
|
-
function setActiveScope(scope) {
|
|
48
|
-
activeScope = scope;
|
|
49
|
-
}
|
|
50
58
|
function createScope(parent = activeScope) {
|
|
51
59
|
const scope = {
|
|
52
60
|
id: ++scopeId,
|
|
@@ -84,52 +92,61 @@ function runWithScope(scope, fn) {
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
function disposeScope(scope) {
|
|
87
|
-
var _a2
|
|
95
|
+
var _a2;
|
|
88
96
|
if (!scope || scope.isDestroyed) {
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
99
|
+
scope.isDestroyed = true;
|
|
100
|
+
if (scope.children && scope.children.size > 0) {
|
|
101
|
+
for (const child2 of scope.children) {
|
|
102
|
+
if (child2) {
|
|
103
|
+
child2.parent = null;
|
|
104
|
+
disposeScope(child2);
|
|
96
105
|
}
|
|
97
106
|
}
|
|
107
|
+
scope.children.clear();
|
|
98
108
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
{
|
|
105
|
-
|
|
109
|
+
const prevScope = activeScope;
|
|
110
|
+
activeScope = scope;
|
|
111
|
+
try {
|
|
112
|
+
if (scope.onDestroy) {
|
|
113
|
+
for (let i = 0; i < scope.onDestroy.length; i++) {
|
|
114
|
+
try {
|
|
115
|
+
scope.onDestroy[i]();
|
|
116
|
+
} catch (error_) {
|
|
117
|
+
if (true) {
|
|
118
|
+
shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
|
|
119
|
+
}
|
|
106
120
|
}
|
|
107
121
|
}
|
|
122
|
+
scope.onDestroy = null;
|
|
108
123
|
}
|
|
109
|
-
scope.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
|
|
124
|
+
if (scope.cleanup) {
|
|
125
|
+
for (let i = 0; i < scope.cleanup.length; i++) {
|
|
126
|
+
try {
|
|
127
|
+
scope.cleanup[i]();
|
|
128
|
+
} catch (error_) {
|
|
129
|
+
if (true) {
|
|
130
|
+
shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
|
|
131
|
+
}
|
|
118
132
|
}
|
|
119
133
|
}
|
|
134
|
+
scope.cleanup = null;
|
|
120
135
|
}
|
|
121
|
-
|
|
136
|
+
} finally {
|
|
137
|
+
activeScope = prevScope;
|
|
122
138
|
}
|
|
123
139
|
if ((_a2 = scope.parent) == null ? void 0 : _a2.children) {
|
|
124
140
|
scope.parent.children.delete(scope);
|
|
125
141
|
}
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
if (scope.provides) {
|
|
143
|
+
scope.provides.clear();
|
|
144
|
+
scope.provides = null;
|
|
145
|
+
}
|
|
146
|
+
scope.onMount = null;
|
|
147
|
+
scope.onUpdate = null;
|
|
148
|
+
scope.children = null;
|
|
131
149
|
scope.parent = null;
|
|
132
|
-
scope.isDestroyed = true;
|
|
133
150
|
}
|
|
134
151
|
function onCleanup(fn) {
|
|
135
152
|
const scope = activeScope;
|
|
@@ -140,460 +157,453 @@ function onCleanup(fn) {
|
|
|
140
157
|
return;
|
|
141
158
|
}
|
|
142
159
|
if (!scope.cleanup) {
|
|
143
|
-
scope.cleanup =
|
|
144
|
-
}
|
|
145
|
-
scope.cleanup.add(fn);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/constants.ts
|
|
149
|
-
var EVENT_PREFIX = "on";
|
|
150
|
-
var SPREAD_NAME = "_$spread$";
|
|
151
|
-
var REF_KEY = "ref";
|
|
152
|
-
var KEY_PROP = "key";
|
|
153
|
-
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
154
|
-
var XLINK_NAMESPACE = "http://www.w3.org/2000/xlink";
|
|
155
|
-
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
156
|
-
var NORMAL_COMPONENT = /* @__PURE__ */ Symbol("Normal Component" );
|
|
157
|
-
var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
|
|
158
|
-
var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
|
|
159
|
-
var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
|
|
160
|
-
var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
|
|
161
|
-
var MAX_KEY_LENGTH = 1e3;
|
|
162
|
-
var componentKeyPrefixCache = /* @__PURE__ */ new WeakMap();
|
|
163
|
-
function getComponentKey(type) {
|
|
164
|
-
let prefix = componentKeyPrefixCache.get(type);
|
|
165
|
-
if (!prefix) {
|
|
166
|
-
const name = type.name || "anonymous";
|
|
167
|
-
const hash = simpleHash(type.toString()).toString(36);
|
|
168
|
-
prefix = `${name}_${hash}`;
|
|
169
|
-
componentKeyPrefixCache.set(type, prefix);
|
|
170
|
-
}
|
|
171
|
-
return prefix;
|
|
172
|
-
}
|
|
173
|
-
function simpleHash(str) {
|
|
174
|
-
let hash = 0;
|
|
175
|
-
const len = str.length < 100 ? str.length : 100;
|
|
176
|
-
for (let i = 0; i < len; i++) {
|
|
177
|
-
hash = Math.trunc((hash << 5) - hash + str.charCodeAt(i));
|
|
160
|
+
scope.cleanup = [];
|
|
178
161
|
}
|
|
179
|
-
|
|
162
|
+
scope.cleanup.push(fn);
|
|
180
163
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (key.length <= MAX_KEY_LENGTH) {
|
|
188
|
-
return key;
|
|
189
|
-
}
|
|
190
|
-
{
|
|
191
|
-
shared.warn(
|
|
192
|
-
`[Key System] Key length exceeds ${MAX_KEY_LENGTH} characters. Consider using a shorter identifier.`
|
|
193
|
-
);
|
|
164
|
+
function patchAttr(el, key, prev, next2) {
|
|
165
|
+
if (key === KEY_PROP) {
|
|
166
|
+
if (next2 == null) {
|
|
167
|
+
el.removeAttribute(key);
|
|
168
|
+
} else {
|
|
169
|
+
el.setAttribute(key, String(next2));
|
|
194
170
|
}
|
|
195
|
-
return
|
|
171
|
+
return;
|
|
196
172
|
}
|
|
197
|
-
if (
|
|
173
|
+
if (key === SPREAD_NAME) {
|
|
174
|
+
const prevObj = shared.isObject(prev) ? prev : null;
|
|
175
|
+
const nextObj = shared.isObject(next2) ? next2 : null;
|
|
198
176
|
{
|
|
199
|
-
if (
|
|
200
|
-
shared.warn("
|
|
201
|
-
return void 0;
|
|
177
|
+
if (next2 != null && !nextObj) {
|
|
178
|
+
shared.warn("spread attribute must be an object");
|
|
202
179
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
180
|
+
}
|
|
181
|
+
if (prevObj) {
|
|
182
|
+
for (const attrKey in prevObj) {
|
|
183
|
+
if (attrKey === SPREAD_NAME) {
|
|
184
|
+
{
|
|
185
|
+
shared.warn("nested spread attributes are ignored");
|
|
186
|
+
}
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!nextObj || !(attrKey in nextObj)) {
|
|
190
|
+
patchAttr(el, attrKey, prevObj[attrKey], null);
|
|
191
|
+
}
|
|
206
192
|
}
|
|
207
193
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
194
|
+
if (nextObj) {
|
|
195
|
+
for (const attrKey in nextObj) {
|
|
196
|
+
if (attrKey === SPREAD_NAME) {
|
|
197
|
+
{
|
|
198
|
+
shared.warn("nested spread attributes are ignored");
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
patchAttr(el, attrKey, prevObj == null ? void 0 : prevObj[attrKey], nextObj[attrKey]);
|
|
203
|
+
}
|
|
214
204
|
}
|
|
215
|
-
|
|
216
|
-
return desc ? `_s.${desc}` : `${symbolIdCounter++}`;
|
|
205
|
+
return;
|
|
217
206
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (
|
|
207
|
+
const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
|
|
208
|
+
const isXlink = elementIsSVG && key.startsWith("xlink:");
|
|
209
|
+
const isXmlns = elementIsSVG && key.startsWith("xmlns:");
|
|
210
|
+
const isBoolean2 = shared.isSpecialBooleanAttr(key) || shared.isBooleanAttr(key);
|
|
211
|
+
if (prev === next2) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110) {
|
|
223
215
|
return;
|
|
224
216
|
}
|
|
225
|
-
|
|
217
|
+
const lowerKey = key.toLowerCase();
|
|
218
|
+
if (lowerKey === "innerhtml" || lowerKey === "srcdoc") {
|
|
226
219
|
{
|
|
227
|
-
shared.warn(
|
|
220
|
+
shared.warn(`${key} updates are ignored by patchAttr`);
|
|
228
221
|
}
|
|
229
222
|
return;
|
|
230
223
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/utils/node.ts
|
|
244
|
-
function normalizeNode(node) {
|
|
245
|
-
if (shared.isHTMLElement(node)) {
|
|
246
|
-
return node;
|
|
247
|
-
}
|
|
248
|
-
if (shared.isPrimitive(node)) {
|
|
249
|
-
const textContent = shared.isFalsy(node) ? "" : String(node);
|
|
250
|
-
return document.createTextNode(textContent);
|
|
251
|
-
}
|
|
252
|
-
return node;
|
|
253
|
-
}
|
|
254
|
-
function isSameNode(a, b) {
|
|
255
|
-
const keyA = getNodeKey(a);
|
|
256
|
-
const keyB = getNodeKey(b);
|
|
257
|
-
if (keyA !== keyB) {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
const aIsComponent = isComponent(a);
|
|
261
|
-
const bIsComponent = isComponent(b);
|
|
262
|
-
if (aIsComponent && bIsComponent) {
|
|
263
|
-
return a.component === b.component;
|
|
224
|
+
if (next2 == null) {
|
|
225
|
+
if (isXlink) {
|
|
226
|
+
el.removeAttributeNS(XLINK_NAMESPACE, key.slice(6));
|
|
227
|
+
} else if (isXmlns) {
|
|
228
|
+
const localName = key.slice(6);
|
|
229
|
+
el.removeAttributeNS(XMLNS_NAMESPACE, localName);
|
|
230
|
+
} else {
|
|
231
|
+
el.removeAttribute(key);
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
264
234
|
}
|
|
265
|
-
if (
|
|
266
|
-
|
|
235
|
+
if (isBoolean2) {
|
|
236
|
+
if (shared.includeBooleanAttr(next2)) {
|
|
237
|
+
el.setAttribute(key, "");
|
|
238
|
+
} else {
|
|
239
|
+
el.removeAttribute(key);
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
267
242
|
}
|
|
268
|
-
|
|
269
|
-
|
|
243
|
+
const attrValue = shared.isSymbol(next2) ? String(next2) : next2;
|
|
244
|
+
const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href" || lowerKey === "action" || lowerKey === "formaction" || lowerKey === "poster";
|
|
245
|
+
if (isUrlAttr && shared.isString(attrValue)) {
|
|
246
|
+
const v = attrValue.trim().toLowerCase();
|
|
247
|
+
if (v.startsWith("javascript:") || v.startsWith("data:")) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
270
250
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return false;
|
|
251
|
+
if (isXlink) {
|
|
252
|
+
el.setAttributeNS(XLINK_NAMESPACE, key, String(attrValue));
|
|
253
|
+
return;
|
|
275
254
|
}
|
|
276
|
-
if (
|
|
277
|
-
|
|
255
|
+
if (isXmlns) {
|
|
256
|
+
el.setAttributeNS(XMLNS_NAMESPACE, key, String(attrValue));
|
|
257
|
+
return;
|
|
278
258
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
291
|
-
for (const key of aKeys) {
|
|
292
|
-
if (!(key in bRecord) || aRecord[key] !== bRecord[key]) {
|
|
293
|
-
return false;
|
|
259
|
+
if (elementIsSVG) {
|
|
260
|
+
el.setAttribute(key, String(attrValue));
|
|
261
|
+
} else {
|
|
262
|
+
if (key in el) {
|
|
263
|
+
try {
|
|
264
|
+
el[key] = attrValue;
|
|
265
|
+
} catch (e) {
|
|
266
|
+
el.setAttribute(key, String(attrValue));
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
el.setAttribute(key, String(attrValue));
|
|
294
270
|
}
|
|
295
271
|
}
|
|
296
|
-
return true;
|
|
297
272
|
}
|
|
298
|
-
function
|
|
299
|
-
if (
|
|
300
|
-
if (isComponent(node)) {
|
|
301
|
-
node.destroy();
|
|
273
|
+
function patchClass(el, prev, next2, isSVG = false) {
|
|
274
|
+
if (prev === next2) {
|
|
302
275
|
return;
|
|
303
276
|
}
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
306
|
-
|
|
277
|
+
const normalizedNext = normalizeClass(next2);
|
|
278
|
+
if (!normalizedNext) {
|
|
279
|
+
el.removeAttribute("class");
|
|
280
|
+
return;
|
|
307
281
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (!parent || !child) return;
|
|
311
|
-
if (isComponent(child)) {
|
|
312
|
-
const beforeNode2 = isComponent(before) ? before.firstChild : before;
|
|
313
|
-
child.mount(parent, beforeNode2);
|
|
282
|
+
const normalizedPrev = shared.isString(prev) ? prev : normalizeClass(prev);
|
|
283
|
+
if (normalizedPrev === normalizedNext) {
|
|
314
284
|
return;
|
|
315
285
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
parent.insertBefore(child, beforeNode);
|
|
286
|
+
if (isSVG) {
|
|
287
|
+
el.setAttribute("class", normalizedNext);
|
|
319
288
|
} else {
|
|
320
|
-
|
|
289
|
+
el.className = normalizedNext;
|
|
321
290
|
}
|
|
322
291
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
292
|
+
var normalizeClass = shared.normalizeClassName;
|
|
293
|
+
var importantRE = /\s*!important$/;
|
|
294
|
+
var prefixes = ["Webkit", "Moz", "ms"];
|
|
295
|
+
var prefixCache = {};
|
|
296
|
+
function patchStyle(el, prev, next2) {
|
|
297
|
+
const style = el.style;
|
|
298
|
+
if (next2 && shared.isString(next2)) {
|
|
299
|
+
if (prev !== next2) {
|
|
300
|
+
style.cssText = next2;
|
|
301
|
+
}
|
|
331
302
|
return;
|
|
332
303
|
}
|
|
333
|
-
if (
|
|
334
|
-
|
|
304
|
+
if (!next2) {
|
|
305
|
+
if (prev) {
|
|
306
|
+
el.removeAttribute("style");
|
|
307
|
+
}
|
|
308
|
+
return;
|
|
335
309
|
}
|
|
336
|
-
if (shared.
|
|
337
|
-
|
|
310
|
+
if (prev && !shared.isString(prev)) {
|
|
311
|
+
const prevObj = prev;
|
|
312
|
+
for (const key in prevObj) {
|
|
313
|
+
if (!next2 || next2[key] == null) {
|
|
314
|
+
setStyle(style, key, "");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else if (prev && shared.isString(prev)) {
|
|
318
|
+
const declRE = /(?:^|;)\s*([a-z][a-z\d-]*)\s*:/gi;
|
|
319
|
+
let match;
|
|
320
|
+
while ((match = declRE.exec(prev)) !== null) {
|
|
321
|
+
const key = match[1].trim();
|
|
322
|
+
if (key && next2 && shared.isObject(next2) && next2[key] == null) {
|
|
323
|
+
setStyle(style, key, "");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (next2 && !shared.isString(next2)) {
|
|
328
|
+
const nextObj = next2;
|
|
329
|
+
for (const key in nextObj) {
|
|
330
|
+
const value = nextObj[key];
|
|
331
|
+
if ((!prev || shared.isString(prev) || prev[key] !== value) && value != null) {
|
|
332
|
+
setStyle(style, key, value);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
338
335
|
}
|
|
339
|
-
return node;
|
|
340
336
|
}
|
|
341
|
-
function
|
|
342
|
-
if (
|
|
337
|
+
function setStyle(style, name, val) {
|
|
338
|
+
if (shared.isArray(val)) {
|
|
339
|
+
for (const element of val) {
|
|
340
|
+
setStyle(style, name, element);
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (val == null || val === "") {
|
|
345
|
+
val = "";
|
|
346
|
+
}
|
|
347
|
+
if (name.startsWith("--")) {
|
|
348
|
+
style.setProperty(name, val);
|
|
343
349
|
return;
|
|
344
350
|
}
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
347
|
-
|
|
351
|
+
const prefixed = autoPrefix(style, name);
|
|
352
|
+
if (shared.isString(val) && importantRE.test(val)) {
|
|
353
|
+
style.setProperty(shared.camelCase(prefixed), val.replace(importantRE, ""), "important");
|
|
354
|
+
} else {
|
|
355
|
+
style[prefixed] = val;
|
|
348
356
|
}
|
|
349
357
|
}
|
|
350
|
-
function
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
function autoPrefix(style, rawName) {
|
|
359
|
+
const cached = prefixCache[rawName];
|
|
360
|
+
if (cached) {
|
|
361
|
+
return cached;
|
|
362
|
+
}
|
|
363
|
+
let name = shared.camelCase(rawName);
|
|
364
|
+
if (name !== "filter" && name in style) {
|
|
365
|
+
return prefixCache[rawName] = name;
|
|
353
366
|
}
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
if (
|
|
358
|
-
return
|
|
367
|
+
name = shared.capitalize(name);
|
|
368
|
+
for (const prefix of prefixes) {
|
|
369
|
+
const prefixed = prefix + name;
|
|
370
|
+
if (prefixed in style) {
|
|
371
|
+
return prefixCache[rawName] = prefixed;
|
|
359
372
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
373
|
+
}
|
|
374
|
+
return rawName;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/hydration.ts
|
|
378
|
+
var _hydrationKey = 0;
|
|
379
|
+
function getHydrationKey() {
|
|
380
|
+
return String(_hydrationKey++);
|
|
381
|
+
}
|
|
382
|
+
function resetHydrationKey() {
|
|
383
|
+
_hydrationKey = 0;
|
|
384
|
+
}
|
|
385
|
+
var _isHydrating = false;
|
|
386
|
+
function isHydrating() {
|
|
387
|
+
return _isHydrating;
|
|
388
|
+
}
|
|
389
|
+
var _registry = /* @__PURE__ */ new Map();
|
|
390
|
+
function gatherHydratable(root) {
|
|
391
|
+
const nodes = root.querySelectorAll("[data-hk]");
|
|
392
|
+
for (const node of nodes) {
|
|
393
|
+
const key = node.dataset.hk;
|
|
394
|
+
if (key != null && !_registry.has(key)) {
|
|
395
|
+
_registry.set(key, node);
|
|
377
396
|
}
|
|
378
397
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
398
|
+
}
|
|
399
|
+
var _teleportCallsiteAnchors = [];
|
|
400
|
+
var _teleportTargetStarts = /* @__PURE__ */ new Map();
|
|
401
|
+
function gatherTeleportAnchors() {
|
|
402
|
+
if (typeof document === "undefined") return;
|
|
403
|
+
const walker = document.createNodeIterator(document.body, NodeFilter.SHOW_COMMENT);
|
|
404
|
+
let node;
|
|
405
|
+
while (node = walker.nextNode()) {
|
|
406
|
+
const data = node.data;
|
|
407
|
+
if (data === "teleport-anchor") {
|
|
408
|
+
_teleportCallsiteAnchors.push(node);
|
|
409
|
+
} else if (data === "teleport-start") {
|
|
410
|
+
const parent = node.parentElement;
|
|
411
|
+
if (!parent) continue;
|
|
412
|
+
let bucket = _teleportTargetStarts.get(parent);
|
|
413
|
+
if (!bucket) {
|
|
414
|
+
bucket = [];
|
|
415
|
+
_teleportTargetStarts.set(parent, bucket);
|
|
416
|
+
}
|
|
417
|
+
bucket.push(node);
|
|
382
418
|
}
|
|
383
|
-
transferKey(oldNode, newNode);
|
|
384
|
-
return oldNode;
|
|
385
419
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
420
|
+
}
|
|
421
|
+
function consumeTeleportAnchor() {
|
|
422
|
+
var _a2;
|
|
423
|
+
return (_a2 = _teleportCallsiteAnchors.shift()) != null ? _a2 : null;
|
|
424
|
+
}
|
|
425
|
+
function consumeTeleportBlock(target) {
|
|
426
|
+
const bucket = _teleportTargetStarts.get(target);
|
|
427
|
+
const start = bucket == null ? void 0 : bucket.shift();
|
|
428
|
+
if (!start) return null;
|
|
429
|
+
const nodes = [];
|
|
430
|
+
let cursor = start.nextSibling;
|
|
431
|
+
while (cursor) {
|
|
432
|
+
if (cursor.nodeType === Node.COMMENT_NODE && cursor.data === "teleport-end") {
|
|
433
|
+
return { start, end: cursor, nodes };
|
|
391
434
|
}
|
|
435
|
+
nodes.push(cursor);
|
|
436
|
+
cursor = cursor.nextSibling;
|
|
437
|
+
}
|
|
438
|
+
{
|
|
439
|
+
shared.warn("[Portal] hydration: orphaned <!--teleport-start--> without matching <!--teleport-end-->");
|
|
392
440
|
}
|
|
393
|
-
|
|
394
|
-
return newNode;
|
|
441
|
+
return null;
|
|
395
442
|
}
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
443
|
+
function beginHydration(root) {
|
|
444
|
+
_isHydrating = true;
|
|
445
|
+
_hydrationKey = 0;
|
|
446
|
+
_registry.clear();
|
|
447
|
+
_teleportCallsiteAnchors.length = 0;
|
|
448
|
+
_teleportTargetStarts.clear();
|
|
449
|
+
gatherHydratable(root);
|
|
450
|
+
gatherTeleportAnchors();
|
|
451
|
+
}
|
|
452
|
+
function endHydration() {
|
|
453
|
+
_isHydrating = false;
|
|
454
|
+
_registry.clear();
|
|
455
|
+
_teleportCallsiteAnchors.length = 0;
|
|
456
|
+
_teleportTargetStarts.clear();
|
|
457
|
+
}
|
|
458
|
+
function getRenderedElement(html) {
|
|
459
|
+
if (!shared.isBrowser()) {
|
|
460
|
+
return () => {
|
|
461
|
+
throw new Error("[essor] getRenderedElement called in non-browser environment");
|
|
462
|
+
};
|
|
401
463
|
}
|
|
464
|
+
let _csrFactory = null;
|
|
465
|
+
return () => {
|
|
466
|
+
if (!_isHydrating) {
|
|
467
|
+
if (!_csrFactory) _csrFactory = template(html);
|
|
468
|
+
return _csrFactory();
|
|
469
|
+
}
|
|
470
|
+
const key = getHydrationKey();
|
|
471
|
+
const node = _registry.get(key);
|
|
472
|
+
if (node) {
|
|
473
|
+
_registry.delete(key);
|
|
474
|
+
return node;
|
|
475
|
+
}
|
|
476
|
+
shared.warn(`[essor] hydration mismatch: no SSR element for key "${key}"`);
|
|
477
|
+
if (!_csrFactory) _csrFactory = template(html);
|
|
478
|
+
return _csrFactory();
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function patchClassHydrate(el, prev, next2, isSVG) {
|
|
482
|
+
if (_isHydrating) return;
|
|
483
|
+
patchClass(el, prev, next2, isSVG);
|
|
484
|
+
}
|
|
485
|
+
function patchAttrHydrate(el, key, prev, next2) {
|
|
486
|
+
if (_isHydrating) return;
|
|
487
|
+
patchAttr(el, key, prev, next2);
|
|
488
|
+
}
|
|
489
|
+
function patchStyleHydrate(el, prev, next2) {
|
|
490
|
+
if (_isHydrating) return;
|
|
491
|
+
patchStyle(el, prev, next2);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/reconcile.ts
|
|
495
|
+
function resolveInsertAnchor(parent, candidate) {
|
|
496
|
+
return candidate && candidate.parentNode === parent ? candidate : null;
|
|
497
|
+
}
|
|
498
|
+
function reconcileArrays(parent, oldNodes, newNodes, anchor) {
|
|
499
|
+
const fallbackAnchor = resolveInsertAnchor(parent, anchor);
|
|
500
|
+
const oldLength = oldNodes.length;
|
|
501
|
+
const newLength = newNodes.length;
|
|
502
|
+
if (oldLength === 0 && newLength === 0) return newNodes;
|
|
402
503
|
if (oldLength === 0) {
|
|
403
504
|
for (let i = 0; i < newLength; i++) {
|
|
404
|
-
insertNode(parent,
|
|
505
|
+
insertNode(parent, newNodes[i], fallbackAnchor);
|
|
405
506
|
}
|
|
406
|
-
return
|
|
507
|
+
return newNodes;
|
|
407
508
|
}
|
|
408
509
|
if (newLength === 0) {
|
|
409
510
|
for (let i = 0; i < oldLength; i++) {
|
|
410
|
-
removeNode(
|
|
511
|
+
removeNode(oldNodes[i]);
|
|
411
512
|
}
|
|
412
513
|
return [];
|
|
413
514
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
} else {
|
|
421
|
-
replaceNode(parent, newNode, oldNode);
|
|
422
|
-
}
|
|
423
|
-
return newChildren;
|
|
424
|
-
}
|
|
425
|
-
if (oldLength === 2 && newLength === 2) {
|
|
426
|
-
const o0 = oldChildren[0];
|
|
427
|
-
const o1 = oldChildren[1];
|
|
428
|
-
const n0 = newChildren[0];
|
|
429
|
-
const n1 = newChildren[1];
|
|
430
|
-
if (isSameNode(o0, n0) && isSameNode(o1, n1)) {
|
|
431
|
-
patch(parent, o0, n0);
|
|
432
|
-
patch(parent, o1, n1);
|
|
433
|
-
newChildren[0] = o0;
|
|
434
|
-
newChildren[1] = o1;
|
|
435
|
-
return newChildren;
|
|
436
|
-
}
|
|
437
|
-
if (isSameNode(o0, n1) && isSameNode(o1, n0)) {
|
|
438
|
-
patch(parent, o0, n1);
|
|
439
|
-
patch(parent, o1, n0);
|
|
440
|
-
const dom1 = getFirstDOMNode(o1);
|
|
441
|
-
const dom0 = getFirstDOMNode(o0);
|
|
442
|
-
if (dom1 && dom0 && dom1.parentNode === parent) {
|
|
443
|
-
parent.insertBefore(dom1, dom0);
|
|
444
|
-
}
|
|
445
|
-
newChildren[0] = o1;
|
|
446
|
-
newChildren[1] = o0;
|
|
447
|
-
return newChildren;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return patchKeyedChildren(parent, oldChildren, newChildren, anchor);
|
|
451
|
-
}
|
|
452
|
-
function patchKeyedChildren(parent, oldChildren, newChildren, anchor) {
|
|
453
|
-
let oldStartIdx = 0;
|
|
454
|
-
let newStartIdx = 0;
|
|
455
|
-
let oldEndIdx = oldChildren.length - 1;
|
|
456
|
-
let newEndIdx = newChildren.length - 1;
|
|
457
|
-
let oldStartNode = oldChildren[0];
|
|
458
|
-
let oldEndNode = oldChildren[oldEndIdx];
|
|
459
|
-
let newStartNode = newChildren[0];
|
|
460
|
-
let newEndNode = newChildren[newEndIdx];
|
|
461
|
-
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
462
|
-
if (!oldStartNode) {
|
|
463
|
-
oldStartNode = oldChildren[++oldStartIdx];
|
|
464
|
-
} else if (!oldEndNode) {
|
|
465
|
-
oldEndNode = oldChildren[--oldEndIdx];
|
|
466
|
-
} else if (isSameNode(oldStartNode, newStartNode)) {
|
|
467
|
-
patch(parent, oldStartNode, newStartNode);
|
|
468
|
-
newChildren[newStartIdx] = oldStartNode;
|
|
469
|
-
oldStartNode = oldChildren[++oldStartIdx];
|
|
470
|
-
newStartNode = newChildren[++newStartIdx];
|
|
515
|
+
let start = 0;
|
|
516
|
+
let oldEnd = oldLength - 1;
|
|
517
|
+
let newEnd = newLength - 1;
|
|
518
|
+
while (start <= oldEnd && start <= newEnd) {
|
|
519
|
+
if (oldNodes[start] === newNodes[start]) {
|
|
520
|
+
start++;
|
|
471
521
|
} else {
|
|
472
522
|
break;
|
|
473
523
|
}
|
|
474
524
|
}
|
|
475
|
-
while (
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
oldEndNode = oldChildren[--oldEndIdx];
|
|
480
|
-
} else if (isSameNode(oldEndNode, newEndNode)) {
|
|
481
|
-
patch(parent, oldEndNode, newEndNode);
|
|
482
|
-
newChildren[newEndIdx] = oldEndNode;
|
|
483
|
-
oldEndNode = oldChildren[--oldEndIdx];
|
|
484
|
-
newEndNode = newChildren[--newEndIdx];
|
|
525
|
+
while (oldEnd >= start && newEnd >= start) {
|
|
526
|
+
if (oldNodes[oldEnd] === newNodes[newEnd]) {
|
|
527
|
+
oldEnd--;
|
|
528
|
+
newEnd--;
|
|
485
529
|
} else {
|
|
486
530
|
break;
|
|
487
531
|
}
|
|
488
532
|
}
|
|
489
|
-
if (
|
|
490
|
-
if (
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
533
|
+
if (start > oldEnd) {
|
|
534
|
+
if (start <= newEnd) {
|
|
535
|
+
const nextPos = newEnd + 1;
|
|
536
|
+
const nextNode = resolveInsertAnchor(
|
|
537
|
+
parent,
|
|
538
|
+
nextPos < newLength ? newNodes[nextPos] : fallbackAnchor
|
|
539
|
+
);
|
|
540
|
+
for (let i = start; i <= newEnd; i++) {
|
|
541
|
+
insertNode(parent, newNodes[i], nextNode);
|
|
494
542
|
}
|
|
495
543
|
}
|
|
496
|
-
} else if (
|
|
497
|
-
for (let i =
|
|
498
|
-
|
|
499
|
-
if (node) {
|
|
500
|
-
removeNode(node);
|
|
501
|
-
}
|
|
544
|
+
} else if (start > newEnd) {
|
|
545
|
+
for (let i = start; i <= oldEnd; i++) {
|
|
546
|
+
removeNode(oldNodes[i]);
|
|
502
547
|
}
|
|
503
548
|
} else {
|
|
504
|
-
|
|
505
|
-
parent,
|
|
506
|
-
oldChildren,
|
|
507
|
-
newChildren,
|
|
508
|
-
oldStartIdx,
|
|
509
|
-
oldEndIdx,
|
|
510
|
-
newStartIdx,
|
|
511
|
-
newEndIdx,
|
|
512
|
-
anchor
|
|
513
|
-
);
|
|
549
|
+
reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, newEnd, fallbackAnchor);
|
|
514
550
|
}
|
|
515
|
-
return
|
|
551
|
+
return newNodes;
|
|
516
552
|
}
|
|
517
|
-
function
|
|
518
|
-
const newLength =
|
|
519
|
-
|
|
520
|
-
for (let i =
|
|
521
|
-
|
|
522
|
-
if (key !== void 0) {
|
|
523
|
-
if (!keyToNewIndexMap) {
|
|
524
|
-
keyToNewIndexMap = /* @__PURE__ */ Object.create(null);
|
|
525
|
-
}
|
|
526
|
-
keyToNewIndexMap[key] = i;
|
|
527
|
-
}
|
|
553
|
+
function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, newEnd, anchor) {
|
|
554
|
+
const newLength = newEnd - start + 1;
|
|
555
|
+
const newIndexMap = /* @__PURE__ */ new Map();
|
|
556
|
+
for (let i = start; i <= newEnd; i++) {
|
|
557
|
+
newIndexMap.set(newNodes[i], i);
|
|
528
558
|
}
|
|
529
559
|
const newIndexToOldIndexMap = new Int32Array(newLength);
|
|
560
|
+
newIndexToOldIndexMap.fill(0);
|
|
561
|
+
let patched = 0;
|
|
530
562
|
let moved = false;
|
|
531
563
|
let maxNewIndexSoFar = 0;
|
|
532
|
-
let
|
|
533
|
-
|
|
534
|
-
const oldNode = oldChildren[i];
|
|
535
|
-
if (!oldNode) continue;
|
|
564
|
+
for (let i = start; i <= oldEnd; i++) {
|
|
565
|
+
const oldNode = oldNodes[i];
|
|
536
566
|
if (patched >= newLength) {
|
|
537
567
|
removeNode(oldNode);
|
|
538
568
|
continue;
|
|
539
569
|
}
|
|
540
|
-
|
|
541
|
-
const oldKey = getNodeKey(oldNode);
|
|
542
|
-
if (oldKey !== void 0 && keyToNewIndexMap && oldKey in keyToNewIndexMap) {
|
|
543
|
-
newIndex = keyToNewIndexMap[oldKey];
|
|
544
|
-
} else {
|
|
545
|
-
for (let j2 = newStartIdx; j2 <= newEndIdx; j2++) {
|
|
546
|
-
if (newIndexToOldIndexMap[j2 - newStartIdx] === 0 && oldKey === void 0 && getNodeKey(newChildren[j2]) === void 0 && isSameNode(oldNode, newChildren[j2])) {
|
|
547
|
-
newIndex = j2;
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
570
|
+
const newIndex = newIndexMap.get(oldNode);
|
|
552
571
|
if (newIndex === void 0) {
|
|
553
572
|
removeNode(oldNode);
|
|
554
573
|
} else {
|
|
555
|
-
newIndexToOldIndexMap[newIndex -
|
|
574
|
+
newIndexToOldIndexMap[newIndex - start] = i + 1;
|
|
556
575
|
if (newIndex >= maxNewIndexSoFar) {
|
|
557
576
|
maxNewIndexSoFar = newIndex;
|
|
558
577
|
} else {
|
|
559
578
|
moved = true;
|
|
560
579
|
}
|
|
561
|
-
patch(parent, oldNode, newChildren[newIndex]);
|
|
562
|
-
newChildren[newIndex] = oldNode;
|
|
563
580
|
patched++;
|
|
564
581
|
}
|
|
565
582
|
}
|
|
566
583
|
const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
|
|
567
584
|
let j = increasingNewIndexSequence.length - 1;
|
|
568
|
-
let cachedAnchor = anchor;
|
|
569
585
|
for (let i = newLength - 1; i >= 0; i--) {
|
|
570
|
-
const nextIndex =
|
|
571
|
-
const nextNode =
|
|
586
|
+
const nextIndex = start + i;
|
|
587
|
+
const nextNode = newNodes[nextIndex];
|
|
588
|
+
const anchorNode = resolveInsertAnchor(
|
|
589
|
+
parent,
|
|
590
|
+
nextIndex + 1 < newNodes.length ? newNodes[nextIndex + 1] : anchor
|
|
591
|
+
);
|
|
572
592
|
if (newIndexToOldIndexMap[i] === 0) {
|
|
573
|
-
insertNode(parent, nextNode,
|
|
574
|
-
cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
|
|
593
|
+
insertNode(parent, nextNode, anchorNode);
|
|
575
594
|
} else if (moved) {
|
|
576
595
|
if (j < 0 || i !== increasingNewIndexSequence[j]) {
|
|
577
|
-
|
|
578
|
-
if (domNode && domNode.parentNode === parent) {
|
|
579
|
-
insertNode(parent, domNode, cachedAnchor);
|
|
580
|
-
}
|
|
581
|
-
cachedAnchor = domNode || cachedAnchor;
|
|
596
|
+
insertNode(parent, nextNode, anchorNode);
|
|
582
597
|
} else {
|
|
583
|
-
cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
|
|
584
598
|
j--;
|
|
585
599
|
}
|
|
586
|
-
} else {
|
|
587
|
-
cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
|
|
588
600
|
}
|
|
589
601
|
}
|
|
590
602
|
}
|
|
591
603
|
function getSequence(arr) {
|
|
604
|
+
const p = new Int32Array(arr.length);
|
|
605
|
+
const result = [0];
|
|
592
606
|
const len = arr.length;
|
|
593
|
-
if (len === 0) return [];
|
|
594
|
-
if (len === 1) return arr[0] !== 0 ? [0] : [];
|
|
595
|
-
const result = [];
|
|
596
|
-
const p = new Int32Array(len);
|
|
597
607
|
let i;
|
|
598
608
|
let j;
|
|
599
609
|
let u;
|
|
@@ -603,7 +613,7 @@ function getSequence(arr) {
|
|
|
603
613
|
const arrI = arr[i];
|
|
604
614
|
if (arrI !== 0) {
|
|
605
615
|
j = result[result.length - 1];
|
|
606
|
-
if (
|
|
616
|
+
if (arr[j] < arrI) {
|
|
607
617
|
p[i] = j;
|
|
608
618
|
result.push(i);
|
|
609
619
|
continue;
|
|
@@ -635,260 +645,253 @@ function getSequence(arr) {
|
|
|
635
645
|
return result;
|
|
636
646
|
}
|
|
637
647
|
|
|
638
|
-
// src/
|
|
639
|
-
function
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
} else if (shared.isHtmlSelectElement(node)) {
|
|
649
|
-
bindSelectElement(node, setter);
|
|
650
|
-
} else if (shared.isHtmlTextAreaElement(node)) {
|
|
651
|
-
addEventListener(node, "input", () => {
|
|
652
|
-
setter(node.value);
|
|
653
|
-
});
|
|
648
|
+
// src/dom.ts
|
|
649
|
+
function removeNode(node) {
|
|
650
|
+
if (!node) return;
|
|
651
|
+
if (isComponent(node)) {
|
|
652
|
+
node.destroy();
|
|
653
|
+
} else {
|
|
654
|
+
const element = node;
|
|
655
|
+
if (element.parentNode) {
|
|
656
|
+
element.remove();
|
|
657
|
+
}
|
|
654
658
|
}
|
|
655
659
|
}
|
|
656
|
-
function
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
break;
|
|
663
|
-
case "radio":
|
|
664
|
-
addEventListener(node, "change", () => {
|
|
665
|
-
setter(node.checked ? node.value : "");
|
|
666
|
-
});
|
|
667
|
-
break;
|
|
668
|
-
case "file":
|
|
669
|
-
addEventListener(node, "change", () => {
|
|
670
|
-
setter(node.files);
|
|
671
|
-
});
|
|
672
|
-
break;
|
|
673
|
-
case "number":
|
|
674
|
-
case "range":
|
|
675
|
-
addEventListener(node, "input", () => {
|
|
676
|
-
setter(node.value || "");
|
|
677
|
-
});
|
|
678
|
-
break;
|
|
679
|
-
case "date":
|
|
680
|
-
case "datetime-local":
|
|
681
|
-
case "month":
|
|
682
|
-
case "time":
|
|
683
|
-
case "week":
|
|
684
|
-
addEventListener(node, "change", () => {
|
|
685
|
-
setter(node.value || "");
|
|
686
|
-
});
|
|
687
|
-
break;
|
|
688
|
-
default:
|
|
689
|
-
addEventListener(node, "input", () => {
|
|
690
|
-
setter(node.value);
|
|
691
|
-
});
|
|
692
|
-
break;
|
|
660
|
+
function insertNode(parent, child2, before) {
|
|
661
|
+
if (!parent || !child2) return;
|
|
662
|
+
const beforeNode = isComponent(before) ? before.firstChild : before;
|
|
663
|
+
if (isComponent(child2)) {
|
|
664
|
+
child2.mount(parent, beforeNode);
|
|
665
|
+
return;
|
|
693
666
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
setter(node.value);
|
|
667
|
+
if (beforeNode) {
|
|
668
|
+
parent.insertBefore(child2, beforeNode);
|
|
669
|
+
} else {
|
|
670
|
+
{
|
|
671
|
+
if (!child2) {
|
|
672
|
+
shared.error("insertNode: child is not a Node", child2);
|
|
673
|
+
}
|
|
702
674
|
}
|
|
703
|
-
|
|
675
|
+
parent.appendChild(child2);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function normalizeNode(node) {
|
|
679
|
+
if (shared.isHTMLElement(node)) {
|
|
680
|
+
return node;
|
|
681
|
+
}
|
|
682
|
+
if (shared.isPrimitive(node)) {
|
|
683
|
+
return document.createTextNode(shared.isFalsy(node) ? "" : String(node));
|
|
684
|
+
}
|
|
685
|
+
return node;
|
|
704
686
|
}
|
|
705
687
|
function insert(parent, nodeFactory, before) {
|
|
706
688
|
if (!parent) return;
|
|
689
|
+
const ownerScope = getActiveScope();
|
|
707
690
|
let renderedNodes = [];
|
|
708
|
-
|
|
709
|
-
const
|
|
710
|
-
|
|
691
|
+
let isFirstRun = true;
|
|
692
|
+
const resolveNodes = (raw) => {
|
|
693
|
+
if (raw instanceof Node) return [raw];
|
|
694
|
+
if (shared.isNull(raw) || shared.isUndefined(raw) || shared.isString(raw) || shared.isNumber(raw) || shared.isBoolean(raw)) {
|
|
695
|
+
return [normalizeNode(raw)];
|
|
696
|
+
}
|
|
697
|
+
return shared.coerceArray(raw).map((item) => shared.isFunction(item) ? item() : item).flatMap((i) => i).map(normalizeNode);
|
|
698
|
+
};
|
|
699
|
+
const effectRunner = signals.effect(() => {
|
|
700
|
+
const executeUpdate = () => {
|
|
711
701
|
const rawNodes = shared.isFunction(nodeFactory) ? nodeFactory() : nodeFactory;
|
|
712
|
-
const nodes =
|
|
713
|
-
|
|
702
|
+
const nodes = resolveNodes(rawNodes);
|
|
703
|
+
if (isFirstRun && isHydrating() && nodes.every((node) => node instanceof Node && node.parentNode === parent)) {
|
|
704
|
+
renderedNodes = nodes;
|
|
705
|
+
isFirstRun = false;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
|
|
709
|
+
isFirstRun = false;
|
|
714
710
|
};
|
|
715
|
-
if (
|
|
716
|
-
runWithScope(
|
|
711
|
+
if (ownerScope && !ownerScope.isDestroyed) {
|
|
712
|
+
runWithScope(ownerScope, executeUpdate);
|
|
717
713
|
} else {
|
|
718
|
-
|
|
714
|
+
executeUpdate();
|
|
719
715
|
}
|
|
720
716
|
});
|
|
721
717
|
onCleanup(() => {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
renderedNodes
|
|
718
|
+
effectRunner.stop();
|
|
719
|
+
for (const node of renderedNodes) removeNode(node);
|
|
720
|
+
renderedNodes = [];
|
|
725
721
|
});
|
|
726
722
|
return renderedNodes;
|
|
727
723
|
}
|
|
728
|
-
function
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
724
|
+
function child(node) {
|
|
725
|
+
return (node == null ? void 0 : node.firstChild) || null;
|
|
726
|
+
}
|
|
727
|
+
function next(node, step = 1) {
|
|
728
|
+
while (node && step > 0) {
|
|
729
|
+
node = node.nextSibling;
|
|
730
|
+
step--;
|
|
731
|
+
}
|
|
732
|
+
return node || null;
|
|
733
|
+
}
|
|
734
|
+
function nthChild(node, index) {
|
|
735
|
+
if (!node || index < 0) return null;
|
|
736
|
+
let current = node.firstChild;
|
|
737
|
+
while (current && index > 0) {
|
|
738
|
+
current = current.nextSibling;
|
|
739
|
+
index--;
|
|
740
|
+
}
|
|
741
|
+
return current || null;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// src/operations/event.ts
|
|
745
|
+
function addEvent(el, event, handler, options) {
|
|
746
|
+
if (!(options == null ? void 0 : options.delegate)) {
|
|
747
|
+
el.addEventListener(event, handler, options);
|
|
748
|
+
return () => el.removeEventListener(event, handler, options);
|
|
749
|
+
}
|
|
750
|
+
const selector = options.delegate;
|
|
751
|
+
const wrappedHandler = (e) => {
|
|
752
|
+
const target = e.target;
|
|
753
|
+
if (target.matches(selector) || target.closest(selector)) {
|
|
754
|
+
handler.call(el, e);
|
|
746
755
|
}
|
|
747
|
-
return false;
|
|
748
756
|
};
|
|
749
|
-
|
|
750
|
-
|
|
757
|
+
const _a2 = options, { delegate: _ } = _a2, nativeOptions = __objRest(_a2, ["delegate"]);
|
|
758
|
+
el.addEventListener(event, wrappedHandler, nativeOptions);
|
|
759
|
+
return () => {
|
|
760
|
+
el.removeEventListener(event, wrappedHandler, nativeOptions);
|
|
761
|
+
};
|
|
751
762
|
}
|
|
752
|
-
function
|
|
763
|
+
function registerScopedHook(scope, listKey, hook) {
|
|
764
|
+
let hookList = scope[listKey];
|
|
765
|
+
if (!hookList) {
|
|
766
|
+
hookList = [];
|
|
767
|
+
scope[listKey] = hookList;
|
|
768
|
+
}
|
|
769
|
+
hookList.push(hook);
|
|
770
|
+
}
|
|
771
|
+
function executeHooks(hooks, scopeId2, phase) {
|
|
772
|
+
const len = hooks.length;
|
|
773
|
+
if (len === 0) return;
|
|
774
|
+
let pending;
|
|
775
|
+
for (let i = 0; i < len; i++) {
|
|
776
|
+
try {
|
|
777
|
+
const result = hooks[i]();
|
|
778
|
+
if (shared.isPromise(result)) {
|
|
779
|
+
const safePromise = result.catch((error_) => {
|
|
780
|
+
if (true) {
|
|
781
|
+
shared.error(`Scope(${scopeId2}): Async ${phase} hook rejected:`, error_);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
(pending || (pending = [])).push(safePromise);
|
|
785
|
+
}
|
|
786
|
+
} catch (error_) {
|
|
787
|
+
{
|
|
788
|
+
shared.error(`Scope(${scopeId2}): Error in ${phase} hook:`, error_);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (!pending) return;
|
|
793
|
+
return Promise.all(pending).then(() => {
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
function onMount(hook) {
|
|
753
797
|
const scope = getActiveScope();
|
|
754
798
|
if (!scope) {
|
|
755
|
-
|
|
756
|
-
shared.error("onMount() must be called within a scope");
|
|
757
|
-
}
|
|
799
|
+
shared.error("onMount() must be called within a scope");
|
|
758
800
|
return;
|
|
759
801
|
}
|
|
760
802
|
if (scope.isMounted) {
|
|
761
803
|
try {
|
|
762
|
-
hook();
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
804
|
+
const result = hook();
|
|
805
|
+
if (shared.isPromise(result)) {
|
|
806
|
+
result.catch((error_) => {
|
|
807
|
+
if (true) shared.error(`Scope(${scope.id}): Async mount hook rejected:`, error_);
|
|
808
|
+
});
|
|
766
809
|
}
|
|
810
|
+
} catch (error_) {
|
|
811
|
+
shared.error(`Scope(${scope.id}): Error in mount hook:`, error_);
|
|
767
812
|
}
|
|
768
813
|
return;
|
|
769
814
|
}
|
|
770
|
-
|
|
771
|
-
scope.onMount = /* @__PURE__ */ new Set();
|
|
772
|
-
}
|
|
773
|
-
scope.onMount.add(hook);
|
|
815
|
+
registerScopedHook(scope, "onMount", hook);
|
|
774
816
|
}
|
|
775
|
-
function
|
|
817
|
+
function onUpdate(hook) {
|
|
776
818
|
const scope = getActiveScope();
|
|
777
819
|
if (!scope) {
|
|
778
|
-
|
|
779
|
-
shared.error("onUpdate() must be called within a scope");
|
|
780
|
-
}
|
|
820
|
+
shared.error("onUpdate() must be called within a scope");
|
|
781
821
|
return;
|
|
782
822
|
}
|
|
783
|
-
|
|
784
|
-
scope.onUpdate = /* @__PURE__ */ new Set();
|
|
785
|
-
}
|
|
786
|
-
scope.onUpdate.add(hook);
|
|
823
|
+
registerScopedHook(scope, "onUpdate", hook);
|
|
787
824
|
}
|
|
788
|
-
function
|
|
825
|
+
function onDestroy(hook) {
|
|
789
826
|
const scope = getActiveScope();
|
|
790
827
|
if (!scope) {
|
|
791
|
-
|
|
792
|
-
shared.error("onDestroy() must be called within a scope");
|
|
793
|
-
}
|
|
828
|
+
shared.error("onDestroy() must be called within a scope");
|
|
794
829
|
return;
|
|
795
830
|
}
|
|
796
|
-
|
|
797
|
-
scope.onDestroy = /* @__PURE__ */ new Set();
|
|
798
|
-
}
|
|
799
|
-
scope.onDestroy.add(hook);
|
|
831
|
+
registerScopedHook(scope, "onDestroy", hook);
|
|
800
832
|
}
|
|
801
833
|
function triggerMountHooks(scope) {
|
|
802
|
-
if (
|
|
834
|
+
if (scope.isDestroyed) {
|
|
803
835
|
return;
|
|
804
836
|
}
|
|
805
|
-
scope.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
for (const hook of scope.onMount) {
|
|
809
|
-
try {
|
|
810
|
-
hook();
|
|
811
|
-
} catch (error_) {
|
|
812
|
-
if (true) {
|
|
813
|
-
shared.error(`Scope(${scope.id}): Error in mount hook:`, error_);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
});
|
|
837
|
+
if (!scope.onMount || scope.onMount.length === 0) {
|
|
838
|
+
scope.isMounted = true;
|
|
839
|
+
return;
|
|
818
840
|
}
|
|
841
|
+
const mountHooks = scope.onMount;
|
|
842
|
+
const result = runWithScope(scope, () => executeHooks(mountHooks, scope.id, "mount"));
|
|
843
|
+
mountHooks.length = 0;
|
|
844
|
+
scope.isMounted = true;
|
|
845
|
+
return result;
|
|
819
846
|
}
|
|
820
847
|
function triggerUpdateHooks(scope) {
|
|
821
|
-
if (!scope || scope.
|
|
822
|
-
|
|
848
|
+
if (scope.isDestroyed || !scope.onUpdate || scope.onUpdate.length === 0) return;
|
|
849
|
+
return runWithScope(scope, () => executeHooks(scope.onUpdate, scope.id, "update"));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/component.ts
|
|
853
|
+
function syncDescriptors(target, source, pruneMissing = false) {
|
|
854
|
+
const seen = pruneMissing ? /* @__PURE__ */ new Set() : null;
|
|
855
|
+
for (const key of Object.getOwnPropertyNames(source)) {
|
|
856
|
+
seen == null ? void 0 : seen.add(key);
|
|
857
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
823
858
|
}
|
|
824
|
-
if (
|
|
825
|
-
for (const
|
|
826
|
-
|
|
827
|
-
hook();
|
|
828
|
-
} catch (error_) {
|
|
829
|
-
{
|
|
830
|
-
shared.error(`Scope(${scope.id}): Error in update hook:`, error_);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
859
|
+
if (seen) {
|
|
860
|
+
for (const key of Object.getOwnPropertyNames(target)) {
|
|
861
|
+
if (!seen.has(key)) delete target[key];
|
|
833
862
|
}
|
|
834
863
|
}
|
|
835
864
|
}
|
|
836
|
-
function
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
function onDestroy(hook) {
|
|
840
|
-
registerDestroyHook(hook);
|
|
865
|
+
function readProp(source, key) {
|
|
866
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
867
|
+
return descriptor.get ? descriptor.get.call(source) : descriptor.value;
|
|
841
868
|
}
|
|
842
|
-
function onUpdate(hook) {
|
|
843
|
-
registerUpdateHook(hook);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// src/component.ts
|
|
847
869
|
var _a;
|
|
848
|
-
_a =
|
|
870
|
+
_a = "normal" /* NORMAL */;
|
|
849
871
|
var Component = class {
|
|
850
872
|
constructor(component, props = {}) {
|
|
851
873
|
this.component = component;
|
|
852
874
|
this.props = props;
|
|
853
|
-
|
|
854
|
-
this.renderedNodes = [];
|
|
855
|
-
// Component scope (unified context management)
|
|
875
|
+
this[_a] = true;
|
|
856
876
|
this.scope = null;
|
|
857
|
-
// Component parent node
|
|
858
|
-
this.parentNode = void 0;
|
|
859
|
-
// Component before node
|
|
860
|
-
this.beforeNode = void 0;
|
|
861
|
-
// Component props (reactive and snapshot)
|
|
862
|
-
this.reactiveProps = {};
|
|
863
|
-
this._propSnapshots = {};
|
|
864
|
-
// Component lifecycle state
|
|
865
877
|
this.state = 0 /* INITIAL */;
|
|
866
|
-
|
|
867
|
-
this.
|
|
868
|
-
|
|
869
|
-
this
|
|
870
|
-
this.
|
|
871
|
-
this.reactiveProps = signals.shallowReactive(__spreadValues({}, props));
|
|
878
|
+
this.beforeNode = void 0;
|
|
879
|
+
this.renderedNodes = [];
|
|
880
|
+
this.firstChild = void 0;
|
|
881
|
+
this.parentNode = void 0;
|
|
882
|
+
this.rootEventCleanups = [];
|
|
872
883
|
this.parentScope = getActiveScope();
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
this._propSnapshots[key] = shared.isArray(val) ? [...val] : __spreadValues({}, val);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
get isConnected() {
|
|
881
|
-
return this.state === 2 /* MOUNTED */;
|
|
882
|
-
}
|
|
883
|
-
get firstChild() {
|
|
884
|
-
for (const node of this.renderedNodes) {
|
|
885
|
-
const dom = getFirstDOMNode(node);
|
|
886
|
-
if (dom) return dom;
|
|
887
|
-
}
|
|
888
|
-
return void 0;
|
|
884
|
+
const container = {};
|
|
885
|
+
syncDescriptors(container, props);
|
|
886
|
+
this.reactiveProps = signals.shallowReactive(container);
|
|
889
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Mount the component into `parentNode` (optionally before `beforeNode`).
|
|
890
|
+
* If already rendered, the existing DOM is re-inserted without re-running
|
|
891
|
+
* the component function.
|
|
892
|
+
*/
|
|
890
893
|
mount(parentNode, beforeNode) {
|
|
891
|
-
var _a2
|
|
894
|
+
var _a2;
|
|
892
895
|
this.parentNode = parentNode;
|
|
893
896
|
this.beforeNode = beforeNode;
|
|
894
897
|
this.state = 1 /* MOUNTING */;
|
|
@@ -899,177 +902,128 @@ var Component = class {
|
|
|
899
902
|
this.state = 2 /* MOUNTED */;
|
|
900
903
|
return this.renderedNodes;
|
|
901
904
|
}
|
|
902
|
-
const
|
|
903
|
-
this.scope =
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
result
|
|
911
|
-
|
|
912
|
-
|
|
905
|
+
const scope = createScope((_a2 = this.parentScope) != null ? _a2 : getActiveScope());
|
|
906
|
+
this.scope = scope;
|
|
907
|
+
const renderedNodes = runWithScope(scope, () => {
|
|
908
|
+
var _a3;
|
|
909
|
+
let result = this.component(this.reactiveProps);
|
|
910
|
+
if (shared.isFunction(result)) {
|
|
911
|
+
result = result(this.reactiveProps);
|
|
912
|
+
}
|
|
913
|
+
if (signals.isSignal(result) || signals.isComputed(result)) {
|
|
914
|
+
result = result.value;
|
|
915
|
+
}
|
|
916
|
+
return (_a3 = insert(parentNode, result, beforeNode)) != null ? _a3 : [];
|
|
917
|
+
});
|
|
913
918
|
this.renderedNodes = renderedNodes;
|
|
914
|
-
this.
|
|
919
|
+
this.firstChild = renderedNodes[0];
|
|
920
|
+
this.syncSpecialProps(this.props);
|
|
915
921
|
this.state = 2 /* MOUNTED */;
|
|
916
|
-
triggerMountHooks(
|
|
922
|
+
triggerMountHooks(scope);
|
|
917
923
|
return this.renderedNodes;
|
|
918
924
|
}
|
|
919
|
-
update(prevNode) {
|
|
920
|
-
if (this.key !== prevNode.key) {
|
|
921
|
-
this.mount(prevNode.parentNode, prevNode.beforeNode);
|
|
922
|
-
return this;
|
|
923
|
-
}
|
|
924
|
-
this.parentNode = prevNode.parentNode;
|
|
925
|
-
this.beforeNode = prevNode.beforeNode;
|
|
926
|
-
this.scope = prevNode.scope;
|
|
927
|
-
this.parentScope = prevNode.parentScope;
|
|
928
|
-
this.renderedNodes = prevNode.renderedNodes;
|
|
929
|
-
this.state = prevNode.state;
|
|
930
|
-
this.reactiveProps = prevNode.reactiveProps;
|
|
931
|
-
this._propSnapshots = prevNode._propSnapshots;
|
|
932
|
-
this._updateReactiveProps(this.props);
|
|
933
|
-
if (!this.isConnected && this.parentNode) {
|
|
934
|
-
this.mount(this.parentNode, this.beforeNode);
|
|
935
|
-
return this;
|
|
936
|
-
}
|
|
937
|
-
if (this.scope) {
|
|
938
|
-
setActiveScope(this.scope);
|
|
939
|
-
this.applyProps(this.props);
|
|
940
|
-
triggerUpdateHooks(this.scope);
|
|
941
|
-
}
|
|
942
|
-
return this;
|
|
943
|
-
}
|
|
944
925
|
/**
|
|
945
|
-
*
|
|
926
|
+
* Re-install props into the same `reactiveProps` container (preserving
|
|
927
|
+
* any closures already holding a reference to it) and re-apply
|
|
928
|
+
* refs/events against the current root element.
|
|
946
929
|
*/
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
this._propSnapshots[key] = newSnapshot;
|
|
960
|
-
} else {
|
|
961
|
-
if (shared.hasChanged(newValue, oldValue)) {
|
|
962
|
-
this.reactiveProps[key] = newValue;
|
|
963
|
-
if (this._propSnapshots[key]) {
|
|
964
|
-
delete this._propSnapshots[key];
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
unwrapRenderResult(result) {
|
|
971
|
-
if (shared.isFunction(result)) {
|
|
972
|
-
result = result(this.reactiveProps);
|
|
973
|
-
}
|
|
974
|
-
if (signals.isSignal(result) || signals.isComputed(result)) {
|
|
975
|
-
result = result.value;
|
|
976
|
-
}
|
|
977
|
-
if (isComponent(result)) {
|
|
978
|
-
result = result.mount(this.parentNode, this.beforeNode);
|
|
979
|
-
}
|
|
980
|
-
if (shared.isPromise(result)) {
|
|
981
|
-
result = result.then((r) => this.unwrapRenderResult(r));
|
|
982
|
-
}
|
|
983
|
-
return result;
|
|
984
|
-
}
|
|
985
|
-
forceUpdate() {
|
|
986
|
-
if (this.state === 5 /* DESTROYED */ || !this.parentNode || !this.scope) {
|
|
987
|
-
return;
|
|
988
|
-
}
|
|
989
|
-
const originalNodes = [...this.renderedNodes];
|
|
990
|
-
try {
|
|
991
|
-
runWithScope(this.scope, () => {
|
|
992
|
-
let result = this.component(this.reactiveProps);
|
|
993
|
-
if (shared.isFunction(result)) {
|
|
994
|
-
result = result(this.reactiveProps);
|
|
995
|
-
}
|
|
996
|
-
if (signals.isSignal(result) || signals.isComputed(result)) {
|
|
997
|
-
result = result.value;
|
|
998
|
-
}
|
|
999
|
-
const newNodes = shared.coerceArray(result);
|
|
1000
|
-
const anchor = this._getAnchorNode();
|
|
1001
|
-
if (!this.parentNode) return;
|
|
1002
|
-
for (const node of this.renderedNodes) {
|
|
1003
|
-
removeNode(node);
|
|
1004
|
-
}
|
|
1005
|
-
for (const node of newNodes) {
|
|
1006
|
-
insertNode(this.parentNode, node, anchor);
|
|
1007
|
-
}
|
|
1008
|
-
this.renderedNodes = newNodes;
|
|
1009
|
-
});
|
|
1010
|
-
if (this.scope) {
|
|
1011
|
-
triggerUpdateHooks(this.scope);
|
|
1012
|
-
}
|
|
1013
|
-
} catch (error8) {
|
|
1014
|
-
this.renderedNodes = originalNodes;
|
|
1015
|
-
throw error8;
|
|
1016
|
-
}
|
|
930
|
+
update(props) {
|
|
931
|
+
this.props = props;
|
|
932
|
+
const scope = this.scope;
|
|
933
|
+
if (!scope || scope.isDestroyed) return;
|
|
934
|
+
syncDescriptors(
|
|
935
|
+
this.reactiveProps,
|
|
936
|
+
props != null ? props : {},
|
|
937
|
+
/* pruneMissing */
|
|
938
|
+
true
|
|
939
|
+
);
|
|
940
|
+
this.syncSpecialProps(props);
|
|
941
|
+
triggerUpdateHooks(scope);
|
|
1017
942
|
}
|
|
1018
943
|
/**
|
|
1019
|
-
*
|
|
944
|
+
* Tear down and re-mount the component at its current insertion point.
|
|
945
|
+
* No-op if the component has never been mounted.
|
|
1020
946
|
*/
|
|
1021
|
-
|
|
1022
|
-
if (this.
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
return lastDom.nextSibling;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
return void 0;
|
|
947
|
+
forceUpdate() {
|
|
948
|
+
if (!this.parentNode) return;
|
|
949
|
+
const parent = this.parentNode;
|
|
950
|
+
const before = this.beforeNode;
|
|
951
|
+
this.destroy();
|
|
952
|
+
this.mount(parent, before);
|
|
1031
953
|
}
|
|
1032
954
|
/**
|
|
1033
|
-
*
|
|
955
|
+
* Dispose the scope, remove all rendered nodes, and clear bookkeeping.
|
|
956
|
+
* Idempotent: subsequent calls are no-ops.
|
|
1034
957
|
*/
|
|
1035
958
|
destroy() {
|
|
1036
|
-
if (this.state === 4 /* DESTROYING */ || this.state === 5 /* DESTROYED */) {
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
this.state = 4 /* DESTROYING */;
|
|
1040
|
-
for (const node of this.renderedNodes) {
|
|
1041
|
-
removeNode(node);
|
|
1042
|
-
}
|
|
1043
959
|
const scope = this.scope;
|
|
1044
|
-
if (scope)
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
960
|
+
if (!scope || scope.isDestroyed) return;
|
|
961
|
+
this.scope = null;
|
|
962
|
+
this.releaseSpecialProps();
|
|
963
|
+
disposeScope(scope);
|
|
964
|
+
for (const node of this.renderedNodes) removeNode(node);
|
|
1048
965
|
this.renderedNodes = [];
|
|
966
|
+
this.firstChild = void 0;
|
|
1049
967
|
this.parentNode = void 0;
|
|
1050
|
-
this.beforeNode = void 0;
|
|
1051
|
-
this.parentScope = null;
|
|
1052
|
-
this.reactiveProps = {};
|
|
1053
|
-
this.props = {};
|
|
1054
|
-
this.state = 5 /* DESTROYED */;
|
|
1055
968
|
}
|
|
1056
|
-
|
|
969
|
+
/**
|
|
970
|
+
* Apply props that bind to the root DOM element rather than flowing into
|
|
971
|
+
* the component body: `ref` (signal/function) and `onXxx` event handlers.
|
|
972
|
+
* The render-facing `reactiveProps` already has those keys; here we just
|
|
973
|
+
* wire them to the actual DOM node.
|
|
974
|
+
*/
|
|
975
|
+
syncSpecialProps(props) {
|
|
1057
976
|
if (!props) return;
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
977
|
+
const root = this.firstChild;
|
|
978
|
+
if (!root) return;
|
|
979
|
+
this.releaseSpecialProps();
|
|
980
|
+
for (const key of Object.getOwnPropertyNames(props)) {
|
|
981
|
+
const value = readProp(props, key);
|
|
982
|
+
if (key === REF_KEY) {
|
|
983
|
+
this.rootRefCleanup = this.bindRootRef(value, root);
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (shared.isOn(key) && shared.isFunction(value)) {
|
|
987
|
+
const eventName = key.slice(2).toLowerCase();
|
|
988
|
+
this.rootEventCleanups.push(addEvent(root, eventName, value));
|
|
1066
989
|
}
|
|
1067
990
|
}
|
|
1068
|
-
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Remove all listeners/ref bindings currently attached to the root element.
|
|
994
|
+
*/
|
|
995
|
+
releaseSpecialProps() {
|
|
996
|
+
for (const cleanup of this.rootEventCleanups) {
|
|
997
|
+
cleanup();
|
|
998
|
+
}
|
|
999
|
+
this.rootEventCleanups.length = 0;
|
|
1000
|
+
if (this.rootRefCleanup) {
|
|
1001
|
+
this.rootRefCleanup();
|
|
1002
|
+
this.rootRefCleanup = void 0;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Bind the root ref prop and return a cleanup that restores the previous ref state.
|
|
1007
|
+
*/
|
|
1008
|
+
bindRootRef(value, root) {
|
|
1009
|
+
if (shared.isFunction(value)) {
|
|
1010
|
+
value(root);
|
|
1011
|
+
return () => value(null);
|
|
1012
|
+
}
|
|
1013
|
+
if (signals.isSignal(value)) {
|
|
1014
|
+
const previousValue = value.value;
|
|
1015
|
+
value.value = root;
|
|
1016
|
+
return () => {
|
|
1017
|
+
if (value.value === root) {
|
|
1018
|
+
value.value = previousValue;
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
return void 0;
|
|
1069
1023
|
}
|
|
1070
1024
|
};
|
|
1071
1025
|
function isComponent(node) {
|
|
1072
|
-
return !!node && !!node[
|
|
1026
|
+
return !!node && !!node["normal" /* NORMAL */];
|
|
1073
1027
|
}
|
|
1074
1028
|
function createComponent(componentFn, props) {
|
|
1075
1029
|
if (isComponent(componentFn)) {
|
|
@@ -1095,17 +1049,72 @@ function template(html) {
|
|
|
1095
1049
|
function createApp(component, target) {
|
|
1096
1050
|
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
1097
1051
|
if (!container) {
|
|
1098
|
-
|
|
1052
|
+
{
|
|
1053
|
+
shared.warn(`Target element not found: ${target}`);
|
|
1054
|
+
}
|
|
1099
1055
|
return;
|
|
1100
1056
|
}
|
|
1101
|
-
const
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1057
|
+
const existingContent = container.innerHTML;
|
|
1058
|
+
if (existingContent) {
|
|
1059
|
+
{
|
|
1060
|
+
shared.warn(`Target element is not empty, it will be cleared: ${target}`);
|
|
1061
|
+
}
|
|
1104
1062
|
container.innerHTML = "";
|
|
1105
1063
|
}
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1064
|
+
const scope = createScope();
|
|
1065
|
+
let rootNode;
|
|
1066
|
+
try {
|
|
1067
|
+
runWithScope(scope, () => {
|
|
1068
|
+
const mountedRoot = createComponent(component);
|
|
1069
|
+
if (isComponent(mountedRoot)) {
|
|
1070
|
+
rootNode = mountedRoot;
|
|
1071
|
+
insertNode(container, mountedRoot);
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
} catch (error_) {
|
|
1075
|
+
disposeScope(scope);
|
|
1076
|
+
throw error_;
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
root: rootNode,
|
|
1080
|
+
unmount: () => {
|
|
1081
|
+
disposeScope(scope);
|
|
1082
|
+
rootNode == null ? void 0 : rootNode.destroy();
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
function hydrate(component, target) {
|
|
1087
|
+
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
1088
|
+
if (!container) {
|
|
1089
|
+
{
|
|
1090
|
+
shared.warn(`[essor] hydrate: target element not found: ${target}`);
|
|
1091
|
+
}
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
beginHydration(container);
|
|
1095
|
+
const scope = createScope();
|
|
1096
|
+
let rootNode;
|
|
1097
|
+
try {
|
|
1098
|
+
runWithScope(scope, () => {
|
|
1099
|
+
const mountedRoot = createComponent(component);
|
|
1100
|
+
if (isComponent(mountedRoot)) {
|
|
1101
|
+
rootNode = mountedRoot;
|
|
1102
|
+
insert(container, mountedRoot);
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
} catch (error_) {
|
|
1106
|
+
disposeScope(scope);
|
|
1107
|
+
throw error_;
|
|
1108
|
+
} finally {
|
|
1109
|
+
endHydration();
|
|
1110
|
+
}
|
|
1111
|
+
return {
|
|
1112
|
+
root: rootNode,
|
|
1113
|
+
unmount: () => {
|
|
1114
|
+
disposeScope(scope);
|
|
1115
|
+
rootNode == null ? void 0 : rootNode.destroy();
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1109
1118
|
}
|
|
1110
1119
|
function provide(key, value) {
|
|
1111
1120
|
const scope = getActiveScope();
|
|
@@ -1131,68 +1140,66 @@ function inject(key, defaultValue) {
|
|
|
1131
1140
|
let current = scope;
|
|
1132
1141
|
while (current) {
|
|
1133
1142
|
if (current.provides) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
return value;
|
|
1143
|
+
if (current.provides.has(key)) {
|
|
1144
|
+
return current.provides.get(key);
|
|
1137
1145
|
}
|
|
1138
1146
|
}
|
|
1139
1147
|
current = current.parent;
|
|
1140
1148
|
}
|
|
1141
1149
|
return defaultValue;
|
|
1142
1150
|
}
|
|
1143
|
-
function
|
|
1144
|
-
Object.defineProperty(
|
|
1151
|
+
function reTargetEvent(e, value) {
|
|
1152
|
+
Object.defineProperty(e, "target", {
|
|
1145
1153
|
configurable: true,
|
|
1146
1154
|
value
|
|
1147
1155
|
});
|
|
1148
1156
|
}
|
|
1149
|
-
function
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
const oriCurrentTarget = event.currentTarget;
|
|
1171
|
-
Object.defineProperty(event, "currentTarget", {
|
|
1157
|
+
function eventHandler(e) {
|
|
1158
|
+
let node = e.target;
|
|
1159
|
+
const key = e.type;
|
|
1160
|
+
const oriTarget = e.target;
|
|
1161
|
+
const oriCurrentTarget = e.currentTarget;
|
|
1162
|
+
const handleNode = () => {
|
|
1163
|
+
const handler = node[`_$${key}`];
|
|
1164
|
+
if (handler && shared.isFunction(handler) && !node.disabled) {
|
|
1165
|
+
const data = node[`${key}Data`];
|
|
1166
|
+
data ? handler.call(node, data, e) : handler.call(node, e);
|
|
1167
|
+
if (e.cancelBubble) return false;
|
|
1168
|
+
}
|
|
1169
|
+
if (node.host && !shared.isString(node.host) && !node.host._$host && shared.isFunction(node.contains) && node.contains(e.target)) {
|
|
1170
|
+
reTargetEvent(e, node.host);
|
|
1171
|
+
}
|
|
1172
|
+
return true;
|
|
1173
|
+
};
|
|
1174
|
+
const walkUpTree = () => {
|
|
1175
|
+
while (handleNode() && (node = node._$host || node.parentNode || node.host)) ;
|
|
1176
|
+
};
|
|
1177
|
+
Object.defineProperty(e, "currentTarget", {
|
|
1172
1178
|
configurable: true,
|
|
1179
|
+
/**
|
|
1180
|
+
* Returns the current delegated target for the event.
|
|
1181
|
+
*/
|
|
1173
1182
|
get() {
|
|
1174
1183
|
return node || document;
|
|
1175
1184
|
}
|
|
1176
1185
|
});
|
|
1177
|
-
if (
|
|
1178
|
-
const path =
|
|
1179
|
-
|
|
1186
|
+
if (e.composedPath) {
|
|
1187
|
+
const path = e.composedPath();
|
|
1188
|
+
reTargetEvent(e, path[0]);
|
|
1180
1189
|
for (let i = 0; i < path.length - 2; i++) {
|
|
1181
1190
|
node = path[i];
|
|
1182
|
-
if (!
|
|
1191
|
+
if (!handleNode()) break;
|
|
1183
1192
|
if (node._$host) {
|
|
1184
1193
|
node = node._$host;
|
|
1185
|
-
|
|
1194
|
+
walkUpTree();
|
|
1186
1195
|
break;
|
|
1187
1196
|
}
|
|
1188
1197
|
if (node.parentNode === oriCurrentTarget) {
|
|
1189
1198
|
break;
|
|
1190
1199
|
}
|
|
1191
1200
|
}
|
|
1192
|
-
} else
|
|
1193
|
-
|
|
1194
|
-
}
|
|
1195
|
-
reTarget(event, oriTarget);
|
|
1201
|
+
} else walkUpTree();
|
|
1202
|
+
reTargetEvent(e, oriTarget);
|
|
1196
1203
|
}
|
|
1197
1204
|
var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
|
|
1198
1205
|
function delegateEvents(eventNames, document2 = window.document) {
|
|
@@ -1205,424 +1212,354 @@ function delegateEvents(eventNames, document2 = window.document) {
|
|
|
1205
1212
|
}
|
|
1206
1213
|
}
|
|
1207
1214
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
get(obj, prop) {
|
|
1215
|
-
if (excludeSet.has(prop)) {
|
|
1216
|
-
return void 0;
|
|
1217
|
-
}
|
|
1218
|
-
return Reflect.get(obj, prop);
|
|
1219
|
-
},
|
|
1220
|
-
// Intercept property enumeration (for...in, Object.keys, etc.)
|
|
1221
|
-
ownKeys(obj) {
|
|
1222
|
-
return Reflect.ownKeys(obj).filter((key) => !excludeSet.has(key));
|
|
1223
|
-
},
|
|
1224
|
-
// Intercept property descriptor retrieval
|
|
1225
|
-
getOwnPropertyDescriptor(obj, prop) {
|
|
1226
|
-
if (excludeSet.has(prop)) {
|
|
1227
|
-
return void 0;
|
|
1228
|
-
}
|
|
1229
|
-
return Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
1230
|
-
},
|
|
1231
|
-
// Intercept the 'in' operator
|
|
1232
|
-
has(obj, prop) {
|
|
1233
|
-
if (excludeSet.has(prop)) {
|
|
1234
|
-
return false;
|
|
1235
|
-
}
|
|
1236
|
-
return Reflect.has(obj, prop);
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
// src/hydration/shared.ts
|
|
1242
|
-
var isHydrationActive = false;
|
|
1243
|
-
function startHydration() {
|
|
1244
|
-
isHydrationActive = true;
|
|
1245
|
-
}
|
|
1246
|
-
function endHydration() {
|
|
1247
|
-
isHydrationActive = false;
|
|
1248
|
-
}
|
|
1249
|
-
function isHydrating() {
|
|
1250
|
-
return isHydrationActive;
|
|
1251
|
-
}
|
|
1252
|
-
var hydrationCounter = 0;
|
|
1253
|
-
function getHydrationKey() {
|
|
1254
|
-
return `${hydrationCounter++}`;
|
|
1255
|
-
}
|
|
1256
|
-
function resetHydrationKey() {
|
|
1257
|
-
hydrationCounter = 0;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
// src/hydration/hydration.ts
|
|
1261
|
-
var DATA_IDX_REGEX = /^\d+-\d+$/;
|
|
1262
|
-
function getRenderedElement(temp) {
|
|
1263
|
-
return () => {
|
|
1264
|
-
if (!shared.isBrowser()) {
|
|
1265
|
-
return null;
|
|
1266
|
-
}
|
|
1267
|
-
const key = getHydrationKey();
|
|
1268
|
-
const node = document.querySelector(`[data-hk="${key}"]`);
|
|
1269
|
-
if (node) {
|
|
1270
|
-
return node;
|
|
1271
|
-
}
|
|
1272
|
-
return template(temp)();
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
function mapSSRNodes(templateEl, idx) {
|
|
1276
|
-
const hk = templateEl.dataset.hk;
|
|
1277
|
-
if (!hk) {
|
|
1278
|
-
return mapNodes(templateEl, idx);
|
|
1279
|
-
}
|
|
1280
|
-
const nodesList = [];
|
|
1281
|
-
const elements = templateEl.querySelectorAll(`[data-idx^="${hk}"]`);
|
|
1282
|
-
if (elements.length > 0) {
|
|
1283
|
-
nodesList.push(
|
|
1284
|
-
...Array.from(elements).filter((item) => {
|
|
1285
|
-
const idxAttr = item.dataset.idx;
|
|
1286
|
-
return idxAttr !== null && DATA_IDX_REGEX.test(idxAttr);
|
|
1287
|
-
}).map((item) => {
|
|
1288
|
-
const idxAttr = item.dataset.idx || "";
|
|
1289
|
-
const [hkPart, idxPart] = idxAttr.split("-");
|
|
1290
|
-
return {
|
|
1291
|
-
hk: hkPart,
|
|
1292
|
-
idx: idxPart,
|
|
1293
|
-
node: item
|
|
1294
|
-
};
|
|
1295
|
-
})
|
|
1296
|
-
);
|
|
1297
|
-
}
|
|
1298
|
-
const commentNodes = [];
|
|
1299
|
-
const walkNodes = (node) => {
|
|
1300
|
-
if (node.nodeType === Node.COMMENT_NODE && node.textContent && DATA_IDX_REGEX.test(node.textContent)) {
|
|
1301
|
-
const [hkPart, idxPart] = node.textContent.split("-");
|
|
1302
|
-
commentNodes.push({
|
|
1303
|
-
hk: hkPart,
|
|
1304
|
-
idx: idxPart,
|
|
1305
|
-
node
|
|
1306
|
-
});
|
|
1307
|
-
}
|
|
1308
|
-
let child = node.firstChild;
|
|
1309
|
-
while (child) {
|
|
1310
|
-
walkNodes(child);
|
|
1311
|
-
child = child.nextSibling;
|
|
1312
|
-
}
|
|
1313
|
-
};
|
|
1314
|
-
walkNodes(templateEl);
|
|
1315
|
-
nodesList.push(...commentNodes);
|
|
1316
|
-
const nodes = [templateEl];
|
|
1317
|
-
idx.forEach((indexValue) => {
|
|
1318
|
-
const node = nodesList.find((item) => item.idx === String(indexValue));
|
|
1319
|
-
if (node) {
|
|
1320
|
-
nodes.push(node.node);
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
return nodes;
|
|
1324
|
-
}
|
|
1325
|
-
function hydrate(component, container) {
|
|
1326
|
-
startHydration();
|
|
1327
|
-
resetHydrationKey();
|
|
1328
|
-
try {
|
|
1329
|
-
const rootElement = shared.isString(container) ? document.querySelector(container) : container;
|
|
1330
|
-
if (!rootElement) {
|
|
1331
|
-
shared.error("Hydration error: Root element not found");
|
|
1332
|
-
return void 0;
|
|
1333
|
-
}
|
|
1334
|
-
const rootComponent = createComponent(component);
|
|
1335
|
-
rootComponent.mount(rootElement);
|
|
1336
|
-
endHydration();
|
|
1337
|
-
return rootComponent;
|
|
1338
|
-
} catch (error_) {
|
|
1339
|
-
shared.error("Hydration error:", error_);
|
|
1340
|
-
endHydration();
|
|
1341
|
-
return void 0;
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
function patchClass(el, prev, next, isSVG = false) {
|
|
1345
|
-
if (prev === next) {
|
|
1346
|
-
return;
|
|
1347
|
-
}
|
|
1348
|
-
if (isHydrating()) {
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
const normalizedNext = normalizeClass(next);
|
|
1352
|
-
const normalizedPrev = normalizeClass(prev);
|
|
1353
|
-
if (normalizedNext && normalizedPrev === normalizedNext) {
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
if (!normalizedNext) {
|
|
1357
|
-
el.removeAttribute("class");
|
|
1358
|
-
} else if (isSVG) {
|
|
1359
|
-
el.setAttribute("class", normalizedNext);
|
|
1360
|
-
} else {
|
|
1361
|
-
el.className = normalizedNext;
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
function normalizeClass(value) {
|
|
1365
|
-
return shared.normalizeClassName(value);
|
|
1366
|
-
}
|
|
1367
|
-
var importantRE = /\s*!important$/;
|
|
1368
|
-
var prefixes = ["Webkit", "Moz", "ms"];
|
|
1369
|
-
var prefixCache = {};
|
|
1370
|
-
function patchStyle(el, prev, next) {
|
|
1371
|
-
const style = el.style;
|
|
1372
|
-
const isCssString = shared.isString(next);
|
|
1373
|
-
if (isHydrating()) {
|
|
1374
|
-
return;
|
|
1375
|
-
}
|
|
1376
|
-
if (next && isCssString) {
|
|
1377
|
-
if (prev !== next) {
|
|
1378
|
-
style.cssText = next;
|
|
1379
|
-
}
|
|
1380
|
-
return;
|
|
1381
|
-
}
|
|
1382
|
-
if (!next) {
|
|
1383
|
-
if (prev) {
|
|
1384
|
-
el.removeAttribute("style");
|
|
1385
|
-
}
|
|
1386
|
-
return;
|
|
1387
|
-
}
|
|
1388
|
-
if (prev && !shared.isString(prev)) {
|
|
1389
|
-
for (const key in prev) {
|
|
1390
|
-
if (!next || next[key] == null) {
|
|
1391
|
-
setStyle(style, key, "");
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
} else if (prev && shared.isString(prev)) {
|
|
1395
|
-
const prevStyles = prev.split(";");
|
|
1396
|
-
for (const stylePart of prevStyles) {
|
|
1397
|
-
const colonIndex = stylePart.indexOf(":");
|
|
1398
|
-
if (colonIndex > 0) {
|
|
1399
|
-
const key = stylePart.slice(0, colonIndex).trim();
|
|
1400
|
-
if (next && shared.isObject(next) && next[key] == null) {
|
|
1401
|
-
setStyle(style, key, "");
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
if (next && !shared.isString(next)) {
|
|
1407
|
-
for (const key in next) {
|
|
1408
|
-
const value = next[key];
|
|
1409
|
-
if ((!prev || shared.isString(prev) || prev[key] !== value) && value != null) {
|
|
1410
|
-
setStyle(style, key, value);
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
function setStyle(style, name, val) {
|
|
1416
|
-
if (shared.isArray(val)) {
|
|
1417
|
-
for (const element of val) {
|
|
1418
|
-
setStyle(style, name, element);
|
|
1215
|
+
function clearDelegatedEvents(document2 = window.document) {
|
|
1216
|
+
const docWithEvents = document2;
|
|
1217
|
+
const eventSet = docWithEvents[$EVENTS];
|
|
1218
|
+
if (eventSet) {
|
|
1219
|
+
for (const name of eventSet.keys()) {
|
|
1220
|
+
document2.removeEventListener(name, eventHandler);
|
|
1419
1221
|
}
|
|
1420
|
-
|
|
1421
|
-
}
|
|
1422
|
-
if (val == null || val === "") {
|
|
1423
|
-
val = "";
|
|
1424
|
-
}
|
|
1425
|
-
if (name.startsWith("--")) {
|
|
1426
|
-
style.setProperty(name, val);
|
|
1427
|
-
return;
|
|
1428
|
-
}
|
|
1429
|
-
const prefixed = autoPrefix(style, name);
|
|
1430
|
-
if (shared.isString(val) && importantRE.test(val)) {
|
|
1431
|
-
style.setProperty(shared.camelCase(prefixed), val.replace(importantRE, ""), "important");
|
|
1432
|
-
} else {
|
|
1433
|
-
style[prefixed] = val;
|
|
1222
|
+
delete docWithEvents[$EVENTS];
|
|
1434
1223
|
}
|
|
1435
1224
|
}
|
|
1436
|
-
function
|
|
1437
|
-
const
|
|
1438
|
-
if (
|
|
1439
|
-
|
|
1440
|
-
}
|
|
1441
|
-
let name = shared.camelCase(rawName);
|
|
1442
|
-
if (name !== "filter" && name in style) {
|
|
1443
|
-
return prefixCache[rawName] = name;
|
|
1444
|
-
}
|
|
1445
|
-
name = shared.capitalize(name);
|
|
1446
|
-
for (const prefix of prefixes) {
|
|
1447
|
-
const prefixed = prefix + name;
|
|
1448
|
-
if (prefixed in style) {
|
|
1449
|
-
return prefixCache[rawName] = prefixed;
|
|
1450
|
-
}
|
|
1225
|
+
function addEventListener(element, event, handler, options) {
|
|
1226
|
+
const cleanup = addEvent(element, event, handler, options);
|
|
1227
|
+
if (getActiveScope()) {
|
|
1228
|
+
onCleanup(cleanup);
|
|
1451
1229
|
}
|
|
1452
|
-
return rawName;
|
|
1453
1230
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
{
|
|
1465
|
-
if (!shared.isObject(next)) {
|
|
1466
|
-
shared.warn("spread attribute must be an object");
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
Object.keys(next).forEach((k) => {
|
|
1470
|
-
patchAttr(el, k, prev == null ? void 0 : prev[k], next == null ? void 0 : next[k]);
|
|
1471
|
-
});
|
|
1472
|
-
return;
|
|
1473
|
-
}
|
|
1474
|
-
if (isHydrating()) {
|
|
1475
|
-
return;
|
|
1476
|
-
}
|
|
1477
|
-
const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
|
|
1478
|
-
const isXlink = elementIsSVG && key.startsWith("xlink:");
|
|
1479
|
-
const isXmlns = elementIsSVG && key.startsWith("xmlns:");
|
|
1480
|
-
const isBoolean = shared.isSpecialBooleanAttr(key) || shared.isBooleanAttr(key);
|
|
1481
|
-
if (prev === next) {
|
|
1482
|
-
return;
|
|
1231
|
+
|
|
1232
|
+
// src/binding.ts
|
|
1233
|
+
var INPUT_CHECKBOX_CHECKED = {
|
|
1234
|
+
event: "change",
|
|
1235
|
+
forceChangeEvent: true,
|
|
1236
|
+
read: (n) => n.checked,
|
|
1237
|
+
write: (n, v) => {
|
|
1238
|
+
const el = n;
|
|
1239
|
+
const next2 = Boolean(v);
|
|
1240
|
+
if (el.checked !== next2) el.checked = next2;
|
|
1483
1241
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1242
|
+
};
|
|
1243
|
+
var INPUT_RADIO_CHECKED = {
|
|
1244
|
+
event: "change",
|
|
1245
|
+
forceChangeEvent: true,
|
|
1246
|
+
read: (n) => {
|
|
1247
|
+
const el = n;
|
|
1248
|
+
return el.checked ? el.value : "";
|
|
1249
|
+
},
|
|
1250
|
+
write: (n, v) => {
|
|
1251
|
+
const el = n;
|
|
1252
|
+
const next2 = String(v) === el.value;
|
|
1253
|
+
if (el.checked !== next2) el.checked = next2;
|
|
1487
1254
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1255
|
+
};
|
|
1256
|
+
var INPUT_FILE_FILES = {
|
|
1257
|
+
event: "change",
|
|
1258
|
+
forceChangeEvent: true,
|
|
1259
|
+
read: (n) => n.files,
|
|
1260
|
+
// Browsers do not allow programmatic writes to <input type="file">.
|
|
1261
|
+
write: () => {
|
|
1490
1262
|
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1263
|
+
};
|
|
1264
|
+
var INPUT_VALUE = {
|
|
1265
|
+
event: "input",
|
|
1266
|
+
needsComposition: true,
|
|
1267
|
+
read: (n) => n.value,
|
|
1268
|
+
write: (n, v) => {
|
|
1269
|
+
const el = n;
|
|
1270
|
+
const next2 = v == null ? "" : String(v);
|
|
1271
|
+
if (el.value !== next2) el.value = next2;
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
var SELECT_VALUE = {
|
|
1275
|
+
event: "change",
|
|
1276
|
+
forceChangeEvent: true,
|
|
1277
|
+
read: (n) => {
|
|
1278
|
+
const s = n;
|
|
1279
|
+
return s.multiple ? Array.from(s.selectedOptions, (o) => o.value) : s.value;
|
|
1280
|
+
},
|
|
1281
|
+
write: (n, v) => {
|
|
1282
|
+
const s = n;
|
|
1283
|
+
if (s.multiple) {
|
|
1284
|
+
const set = new Set((Array.isArray(v) ? v : []).map(String));
|
|
1285
|
+
for (const opt of Array.from(s.options)) opt.selected = set.has(opt.value);
|
|
1497
1286
|
} else {
|
|
1498
|
-
|
|
1287
|
+
const next2 = v == null ? "" : String(v);
|
|
1288
|
+
if (s.value !== next2) s.value = next2;
|
|
1499
1289
|
}
|
|
1500
|
-
return;
|
|
1501
|
-
}
|
|
1502
|
-
if (isXlink) {
|
|
1503
|
-
el.setAttributeNS(XLINK_NAMESPACE, key, String(next));
|
|
1504
|
-
return;
|
|
1505
1290
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1291
|
+
};
|
|
1292
|
+
var TEXTAREA_VALUE = {
|
|
1293
|
+
event: "input",
|
|
1294
|
+
needsComposition: true,
|
|
1295
|
+
read: (n) => n.value,
|
|
1296
|
+
write: (n, v) => {
|
|
1297
|
+
const el = n;
|
|
1298
|
+
const next2 = v == null ? "" : String(v);
|
|
1299
|
+
if (el.value !== next2) el.value = next2;
|
|
1509
1300
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1301
|
+
};
|
|
1302
|
+
function resolveStrategy(node, prop) {
|
|
1303
|
+
const tag = node.nodeName;
|
|
1304
|
+
if (tag === "INPUT") {
|
|
1305
|
+
const type = node.type;
|
|
1306
|
+
if (prop === "checked") {
|
|
1307
|
+
return type === "radio" ? INPUT_RADIO_CHECKED : INPUT_CHECKBOX_CHECKED;
|
|
1308
|
+
}
|
|
1309
|
+
if (prop === "files") return INPUT_FILE_FILES;
|
|
1310
|
+
return INPUT_VALUE;
|
|
1311
|
+
}
|
|
1312
|
+
if (tag === "SELECT") return SELECT_VALUE;
|
|
1313
|
+
if (tag === "TEXTAREA") return TEXTAREA_VALUE;
|
|
1314
|
+
return {
|
|
1315
|
+
event: "input",
|
|
1316
|
+
read: (n) => n[prop],
|
|
1317
|
+
write: (n, v) => {
|
|
1318
|
+
n[prop] = v;
|
|
1515
1319
|
}
|
|
1516
|
-
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
function castValue(val, trim, number) {
|
|
1323
|
+
if (!shared.isString(val)) return val;
|
|
1324
|
+
if (trim) val = val.trim();
|
|
1325
|
+
if (number && val !== "") {
|
|
1326
|
+
const parsed = Number(val);
|
|
1327
|
+
if (!Number.isNaN(parsed)) return parsed;
|
|
1517
1328
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1329
|
+
return val;
|
|
1330
|
+
}
|
|
1331
|
+
function isFocused(node) {
|
|
1332
|
+
const root = node.getRootNode();
|
|
1333
|
+
return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === node;
|
|
1334
|
+
}
|
|
1335
|
+
function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
1336
|
+
if (!node) return;
|
|
1337
|
+
const strategy = resolveStrategy(node, prop);
|
|
1338
|
+
const { trim, number, lazy } = modifiers;
|
|
1339
|
+
const isFiles = prop === "files";
|
|
1340
|
+
const readModel = () => shared.isFunction(getter) ? getter() : getter;
|
|
1341
|
+
const transform = (v) => isFiles ? v : castValue(v, trim, number);
|
|
1342
|
+
const eventName = lazy || strategy.forceChangeEvent ? "change" : strategy.event;
|
|
1343
|
+
let composing = false;
|
|
1344
|
+
const syncFromDom = () => {
|
|
1345
|
+
if (composing) return;
|
|
1346
|
+
const raw = strategy.read(node);
|
|
1347
|
+
if (raw === void 0) return;
|
|
1348
|
+
if (isFiles) {
|
|
1349
|
+
setter(raw);
|
|
1523
1350
|
return;
|
|
1524
1351
|
}
|
|
1352
|
+
const next2 = transform(raw);
|
|
1353
|
+
if (!Object.is(readModel(), next2)) {
|
|
1354
|
+
setter(next2);
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
addEventListener(node, eventName, syncFromDom);
|
|
1358
|
+
if (!lazy && !isFiles && (trim || number) && eventName !== "change") {
|
|
1359
|
+
addEventListener(node, "change", () => {
|
|
1360
|
+
strategy.write(node, transform(strategy.read(node)));
|
|
1361
|
+
});
|
|
1525
1362
|
}
|
|
1526
|
-
if (
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1363
|
+
if (strategy.needsComposition && !lazy) {
|
|
1364
|
+
addEventListener(node, "compositionstart", () => {
|
|
1365
|
+
composing = true;
|
|
1366
|
+
});
|
|
1367
|
+
addEventListener(node, "compositionend", () => {
|
|
1368
|
+
if (!composing) return;
|
|
1369
|
+
composing = false;
|
|
1370
|
+
syncFromDom();
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
const runner = signals.effect(() => {
|
|
1374
|
+
const value = readModel();
|
|
1375
|
+
if (strategy.needsComposition && !lazy && isFocused(node)) {
|
|
1376
|
+
if (composing) return;
|
|
1377
|
+
const current = transform(strategy.read(node));
|
|
1378
|
+
if (Object.is(current, value)) return;
|
|
1537
1379
|
}
|
|
1380
|
+
strategy.write(node, value);
|
|
1381
|
+
});
|
|
1382
|
+
if (getActiveScope()) {
|
|
1383
|
+
onCleanup(() => runner.stop());
|
|
1538
1384
|
}
|
|
1539
1385
|
}
|
|
1540
1386
|
|
|
1541
|
-
// src/
|
|
1542
|
-
function
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1387
|
+
// src/utils.ts
|
|
1388
|
+
function omitProps(target, keys) {
|
|
1389
|
+
const excludeSet = new Set(keys);
|
|
1390
|
+
return new Proxy(target, {
|
|
1391
|
+
/**
|
|
1392
|
+
* Returns a property unless it is excluded by the proxy.
|
|
1393
|
+
*/
|
|
1394
|
+
get(obj, prop) {
|
|
1395
|
+
if (excludeSet.has(prop)) {
|
|
1396
|
+
return void 0;
|
|
1397
|
+
}
|
|
1398
|
+
return Reflect.get(obj, prop);
|
|
1399
|
+
},
|
|
1400
|
+
/**
|
|
1401
|
+
* Returns the enumerable keys that are not excluded from the proxy.
|
|
1402
|
+
*/
|
|
1403
|
+
ownKeys(obj) {
|
|
1404
|
+
return Reflect.ownKeys(obj).filter((key) => !excludeSet.has(key));
|
|
1405
|
+
},
|
|
1406
|
+
/**
|
|
1407
|
+
* Returns the property descriptor unless the key is excluded.
|
|
1408
|
+
*/
|
|
1409
|
+
getOwnPropertyDescriptor(obj, prop) {
|
|
1410
|
+
if (excludeSet.has(prop)) {
|
|
1411
|
+
return void 0;
|
|
1412
|
+
}
|
|
1413
|
+
return Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
1414
|
+
},
|
|
1415
|
+
/**
|
|
1416
|
+
* Returns whether the requested value exists.
|
|
1417
|
+
*/
|
|
1418
|
+
has(obj, prop) {
|
|
1419
|
+
if (excludeSet.has(prop)) {
|
|
1420
|
+
return false;
|
|
1421
|
+
}
|
|
1422
|
+
return Reflect.has(obj, prop);
|
|
1552
1423
|
}
|
|
1553
|
-
};
|
|
1554
|
-
const cleanOptions = __spreadValues({}, options);
|
|
1555
|
-
cleanOptions.delegate = void 0;
|
|
1556
|
-
el.addEventListener(event, wrappedHandler, cleanOptions);
|
|
1557
|
-
return () => {
|
|
1558
|
-
el.removeEventListener(event, wrappedHandler, cleanOptions);
|
|
1559
|
-
};
|
|
1424
|
+
});
|
|
1560
1425
|
}
|
|
1426
|
+
|
|
1427
|
+
// src/components/Fragment.ts
|
|
1561
1428
|
function Fragment(props) {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
shared.error("Fragment component requires props");
|
|
1565
|
-
return null;
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
if (!(props == null ? void 0 : props.children)) {
|
|
1569
|
-
shared.error("Fragment component requires children");
|
|
1570
|
-
return null;
|
|
1571
|
-
}
|
|
1572
|
-
const { children } = props;
|
|
1573
|
-
return children;
|
|
1429
|
+
if (!props || props.children == null) return null;
|
|
1430
|
+
return props.children;
|
|
1574
1431
|
}
|
|
1575
1432
|
Fragment[FRAGMENT_COMPONENT] = true;
|
|
1576
1433
|
function isFragment(node) {
|
|
1577
1434
|
return !!node && !!node[FRAGMENT_COMPONENT];
|
|
1578
1435
|
}
|
|
1436
|
+
function resolveTarget(props) {
|
|
1437
|
+
const raw = shared.isFunction(props.target) ? props.target() : props.target;
|
|
1438
|
+
if (raw == null) return null;
|
|
1439
|
+
if (shared.isString(raw)) return document.querySelector(raw);
|
|
1440
|
+
return raw;
|
|
1441
|
+
}
|
|
1442
|
+
function evalDisabled(props) {
|
|
1443
|
+
return shared.isFunction(props.disabled) ? !!props.disabled() : !!props.disabled;
|
|
1444
|
+
}
|
|
1579
1445
|
function Portal(props) {
|
|
1446
|
+
if (isHydrating()) {
|
|
1447
|
+
const adopted = tryHydratePortal(props);
|
|
1448
|
+
if (adopted) return adopted;
|
|
1449
|
+
}
|
|
1580
1450
|
const placeholder = document.createComment("portal");
|
|
1581
1451
|
placeholder[PORTAL_COMPONENT] = true;
|
|
1582
|
-
const children = props
|
|
1583
|
-
if (children)
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1452
|
+
const { children } = props;
|
|
1453
|
+
if (children == null) return placeholder;
|
|
1454
|
+
const ownerScope = getActiveScope();
|
|
1455
|
+
let innerScope = null;
|
|
1456
|
+
const mountAt = (parent, before) => {
|
|
1457
|
+
innerScope = createScope(ownerScope);
|
|
1458
|
+
runWithScope(innerScope, () => {
|
|
1459
|
+
insert(parent, () => children, before);
|
|
1460
|
+
});
|
|
1461
|
+
};
|
|
1462
|
+
const teardown = () => {
|
|
1463
|
+
if (innerScope) {
|
|
1464
|
+
disposeScope(innerScope);
|
|
1465
|
+
innerScope = null;
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
const apply = (disabled, target) => {
|
|
1469
|
+
teardown();
|
|
1470
|
+
if (disabled) {
|
|
1471
|
+
const parent = placeholder.parentNode;
|
|
1472
|
+
if (!parent) return;
|
|
1473
|
+
mountAt(parent, placeholder);
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
if (!target) {
|
|
1477
|
+
{
|
|
1478
|
+
shared.warn(`[Portal] Target element not found: ${String(props.target)}`);
|
|
1593
1479
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
mountAt(target);
|
|
1483
|
+
};
|
|
1484
|
+
let mounted = false;
|
|
1485
|
+
const effectRunner = signals.effect(() => {
|
|
1486
|
+
const disabled = evalDisabled(props);
|
|
1487
|
+
const target = disabled ? null : resolveTarget(props);
|
|
1488
|
+
if (mounted) {
|
|
1489
|
+
apply(disabled, target);
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
onMount(() => {
|
|
1493
|
+
mounted = true;
|
|
1494
|
+
const disabled = evalDisabled(props);
|
|
1495
|
+
const target = disabled ? null : resolveTarget(props);
|
|
1496
|
+
if (disabled || target) {
|
|
1497
|
+
apply(disabled, target);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
queueMicrotask(() => {
|
|
1501
|
+
if (!placeholder.parentNode) return;
|
|
1502
|
+
apply(evalDisabled(props), resolveTarget(props));
|
|
1610
1503
|
});
|
|
1611
|
-
}
|
|
1504
|
+
});
|
|
1505
|
+
onCleanup(() => {
|
|
1506
|
+
effectRunner.stop();
|
|
1507
|
+
teardown();
|
|
1508
|
+
});
|
|
1612
1509
|
return placeholder;
|
|
1613
1510
|
}
|
|
1614
1511
|
Portal[PORTAL_COMPONENT] = true;
|
|
1512
|
+
function tryHydratePortal(props) {
|
|
1513
|
+
if (evalDisabled(props)) return null;
|
|
1514
|
+
const anchor = consumeTeleportAnchor();
|
|
1515
|
+
if (!anchor) {
|
|
1516
|
+
{
|
|
1517
|
+
shared.warn("[Portal] hydration mismatch: no <!--teleport-anchor--> at call site.");
|
|
1518
|
+
}
|
|
1519
|
+
return null;
|
|
1520
|
+
}
|
|
1521
|
+
const target = resolveTarget(props);
|
|
1522
|
+
if (!target) {
|
|
1523
|
+
{
|
|
1524
|
+
shared.warn(`[Portal] hydration mismatch: target not found: ${String(props.target)}`);
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
const block = consumeTeleportBlock(target);
|
|
1529
|
+
if (!block) {
|
|
1530
|
+
{
|
|
1531
|
+
shared.warn(
|
|
1532
|
+
`[Portal] hydration mismatch: no <!--teleport-start--> in target ${String(props.target)}`
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
anchor[PORTAL_COMPONENT] = true;
|
|
1538
|
+
return anchor;
|
|
1539
|
+
}
|
|
1615
1540
|
function isPortal(node) {
|
|
1616
1541
|
return !!node && !!node[PORTAL_COMPONENT];
|
|
1617
1542
|
}
|
|
1543
|
+
function clearContainer(el) {
|
|
1544
|
+
while (el.firstChild) {
|
|
1545
|
+
el.removeChild(el.firstChild);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
function resolveNodeValue(value) {
|
|
1549
|
+
let current = value;
|
|
1550
|
+
while (shared.isFunction(current)) {
|
|
1551
|
+
current = current();
|
|
1552
|
+
}
|
|
1553
|
+
if (signals.isSignal(current) || signals.isComputed(current)) {
|
|
1554
|
+
return resolveNodeValue(current.value);
|
|
1555
|
+
}
|
|
1556
|
+
return current;
|
|
1557
|
+
}
|
|
1618
1558
|
var SuspenseContext = /* @__PURE__ */ Symbol("SuspenseContext");
|
|
1619
1559
|
function Suspense(props) {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
return String(fallback || "");
|
|
1624
|
-
}
|
|
1625
|
-
return "";
|
|
1560
|
+
var _a2;
|
|
1561
|
+
if (!shared.isBrowser()) {
|
|
1562
|
+
return (_a2 = props.fallback) != null ? _a2 : "";
|
|
1626
1563
|
}
|
|
1627
1564
|
const container = document.createElement("div");
|
|
1628
1565
|
container.style.display = "contents";
|
|
@@ -1630,19 +1567,42 @@ function Suspense(props) {
|
|
|
1630
1567
|
let pendingCount = 0;
|
|
1631
1568
|
let isShowingFallback = false;
|
|
1632
1569
|
let resolvedChildren = null;
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1570
|
+
const materializeChild = (value) => {
|
|
1571
|
+
const current = resolveNodeValue(value);
|
|
1572
|
+
if (shared.isArray(current)) {
|
|
1573
|
+
const nodes = [];
|
|
1574
|
+
for (const item of current) {
|
|
1575
|
+
const materialized = materializeChild(item);
|
|
1576
|
+
if (shared.isArray(materialized)) {
|
|
1577
|
+
nodes.push(...materialized);
|
|
1578
|
+
} else {
|
|
1579
|
+
nodes.push(materialized);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
return nodes;
|
|
1638
1583
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1584
|
+
return normalizeNode(current);
|
|
1585
|
+
};
|
|
1586
|
+
const insertMaterializedChild = (value) => {
|
|
1587
|
+
const normalized = materializeChild(value);
|
|
1588
|
+
const nodes = shared.isArray(normalized) ? normalized : [normalized];
|
|
1589
|
+
for (const node of nodes) {
|
|
1590
|
+
if (node != null) {
|
|
1591
|
+
insertNode(container, node);
|
|
1643
1592
|
}
|
|
1644
1593
|
}
|
|
1645
1594
|
};
|
|
1595
|
+
const renderFallbackContent = () => {
|
|
1596
|
+
clearContainer(container);
|
|
1597
|
+
if (props.fallback != null) {
|
|
1598
|
+
insertMaterializedChild(props.fallback);
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
const showFallback = () => {
|
|
1602
|
+
if (isShowingFallback) return;
|
|
1603
|
+
isShowingFallback = true;
|
|
1604
|
+
renderFallbackContent();
|
|
1605
|
+
};
|
|
1646
1606
|
const showChildren = () => {
|
|
1647
1607
|
if (!isShowingFallback) return;
|
|
1648
1608
|
const hasContent = resolvedChildren || props.children != null && !shared.isPromise(props.children);
|
|
@@ -1650,9 +1610,7 @@ function Suspense(props) {
|
|
|
1650
1610
|
return;
|
|
1651
1611
|
}
|
|
1652
1612
|
isShowingFallback = false;
|
|
1653
|
-
|
|
1654
|
-
container.removeChild(container.firstChild);
|
|
1655
|
-
}
|
|
1613
|
+
clearContainer(container);
|
|
1656
1614
|
if (resolvedChildren) {
|
|
1657
1615
|
renderChildren(resolvedChildren);
|
|
1658
1616
|
} else if (props.children != null && !shared.isPromise(props.children)) {
|
|
@@ -1660,33 +1618,17 @@ function Suspense(props) {
|
|
|
1660
1618
|
}
|
|
1661
1619
|
};
|
|
1662
1620
|
const renderChildren = (children2) => {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
}
|
|
1621
|
+
if (isShowingFallback) return;
|
|
1622
|
+
clearContainer(container);
|
|
1666
1623
|
if (children2 == null) return;
|
|
1667
|
-
const currentScope = getActiveScope();
|
|
1668
1624
|
const childArray = shared.isArray(children2) ? children2 : [children2];
|
|
1669
|
-
childArray
|
|
1670
|
-
if (
|
|
1671
|
-
|
|
1672
|
-
child.parentContext = currentScope;
|
|
1673
|
-
}
|
|
1674
|
-
const normalized = normalizeNode(child);
|
|
1675
|
-
if (normalized) {
|
|
1676
|
-
insertNode(container, normalized);
|
|
1677
|
-
}
|
|
1625
|
+
for (const child2 of childArray) {
|
|
1626
|
+
if (child2 != null) {
|
|
1627
|
+
insertMaterializedChild(child2);
|
|
1678
1628
|
}
|
|
1679
|
-
}
|
|
1629
|
+
}
|
|
1680
1630
|
if (isShowingFallback) {
|
|
1681
|
-
|
|
1682
|
-
container.removeChild(container.firstChild);
|
|
1683
|
-
}
|
|
1684
|
-
if (props.fallback != null) {
|
|
1685
|
-
const normalized = normalizeNode(props.fallback);
|
|
1686
|
-
if (normalized) {
|
|
1687
|
-
insertNode(container, normalized);
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1631
|
+
renderFallbackContent();
|
|
1690
1632
|
}
|
|
1691
1633
|
};
|
|
1692
1634
|
const suspenseContext = {
|
|
@@ -1699,9 +1641,9 @@ function Suspense(props) {
|
|
|
1699
1641
|
if (pendingCount === 0) {
|
|
1700
1642
|
showChildren();
|
|
1701
1643
|
}
|
|
1702
|
-
}).catch((
|
|
1644
|
+
}).catch((error5) => {
|
|
1703
1645
|
{
|
|
1704
|
-
shared.warn("[Suspense] Resource failed:",
|
|
1646
|
+
shared.warn("[Suspense] Resource failed:", error5);
|
|
1705
1647
|
}
|
|
1706
1648
|
if (!isMounted) return;
|
|
1707
1649
|
pendingCount--;
|
|
@@ -1715,7 +1657,7 @@ function Suspense(props) {
|
|
|
1715
1657
|
showFallback();
|
|
1716
1658
|
},
|
|
1717
1659
|
decrement: () => {
|
|
1718
|
-
pendingCount
|
|
1660
|
+
pendingCount = Math.max(0, pendingCount - 1);
|
|
1719
1661
|
if (pendingCount === 0) {
|
|
1720
1662
|
showChildren();
|
|
1721
1663
|
}
|
|
@@ -1736,9 +1678,10 @@ function Suspense(props) {
|
|
|
1736
1678
|
}
|
|
1737
1679
|
onDestroy(() => {
|
|
1738
1680
|
isMounted = false;
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1681
|
+
pendingCount = 0;
|
|
1682
|
+
resolvedChildren = null;
|
|
1683
|
+
clearContainer(container);
|
|
1684
|
+
container.remove();
|
|
1742
1685
|
});
|
|
1743
1686
|
return container;
|
|
1744
1687
|
}
|
|
@@ -1749,19 +1692,25 @@ function isSuspense(node) {
|
|
|
1749
1692
|
function createResource(fetcher, options) {
|
|
1750
1693
|
const value = signals.signal(options == null ? void 0 : options.initialValue);
|
|
1751
1694
|
const loading = signals.signal(true);
|
|
1752
|
-
const
|
|
1695
|
+
const error5 = signals.signal(null);
|
|
1753
1696
|
const state = signals.signal("pending");
|
|
1754
1697
|
let fetchId = 0;
|
|
1755
1698
|
let currentPromise = null;
|
|
1699
|
+
let suspenseRegistered = false;
|
|
1700
|
+
const suspenseContext = inject(SuspenseContext, null);
|
|
1756
1701
|
const fetch = () => __async(null, null, function* () {
|
|
1757
1702
|
const currentFetchId = ++fetchId;
|
|
1758
1703
|
loading.value = true;
|
|
1759
1704
|
state.value = "pending";
|
|
1760
|
-
|
|
1705
|
+
error5.value = null;
|
|
1706
|
+
suspenseRegistered = false;
|
|
1707
|
+
if (suspenseContext) {
|
|
1708
|
+
suspenseContext.increment();
|
|
1709
|
+
}
|
|
1761
1710
|
try {
|
|
1762
1711
|
const promise = fetcher();
|
|
1763
|
-
currentPromise = promise
|
|
1764
|
-
|
|
1712
|
+
currentPromise = promise;
|
|
1713
|
+
promise.catch(() => {
|
|
1765
1714
|
});
|
|
1766
1715
|
const result = yield promise;
|
|
1767
1716
|
if (currentFetchId === fetchId) {
|
|
@@ -1771,31 +1720,33 @@ function createResource(fetcher, options) {
|
|
|
1771
1720
|
}
|
|
1772
1721
|
} catch (error_) {
|
|
1773
1722
|
if (currentFetchId === fetchId) {
|
|
1774
|
-
|
|
1723
|
+
error5.value = error_ instanceof Error ? error_ : new Error(String(error_));
|
|
1775
1724
|
state.value = "errored";
|
|
1776
1725
|
loading.value = false;
|
|
1777
1726
|
}
|
|
1727
|
+
} finally {
|
|
1728
|
+
if (suspenseContext) {
|
|
1729
|
+
suspenseContext.decrement();
|
|
1730
|
+
}
|
|
1778
1731
|
}
|
|
1779
1732
|
});
|
|
1780
1733
|
fetch();
|
|
1781
1734
|
const resource = (() => {
|
|
1782
|
-
if (loading.value && currentPromise) {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
suspenseContext.register(currentPromise);
|
|
1786
|
-
}
|
|
1735
|
+
if (!suspenseRegistered && loading.value && currentPromise && suspenseContext) {
|
|
1736
|
+
suspenseRegistered = true;
|
|
1737
|
+
suspenseContext.register(currentPromise);
|
|
1787
1738
|
}
|
|
1788
1739
|
return value.value;
|
|
1789
1740
|
});
|
|
1790
1741
|
resource.loading = loading;
|
|
1791
|
-
resource.error =
|
|
1742
|
+
resource.error = error5;
|
|
1792
1743
|
resource.state = state;
|
|
1793
1744
|
const actions = {
|
|
1794
1745
|
mutate: (newValue) => {
|
|
1795
1746
|
value.value = newValue;
|
|
1796
1747
|
state.value = "ready";
|
|
1797
1748
|
loading.value = false;
|
|
1798
|
-
|
|
1749
|
+
error5.value = null;
|
|
1799
1750
|
},
|
|
1800
1751
|
refetch: () => __async(null, null, function* () {
|
|
1801
1752
|
yield fetch();
|
|
@@ -1803,89 +1754,274 @@ function createResource(fetcher, options) {
|
|
|
1803
1754
|
};
|
|
1804
1755
|
return [resource, actions];
|
|
1805
1756
|
}
|
|
1757
|
+
function resolveModule(mod) {
|
|
1758
|
+
return shared.isFunction(mod) ? mod : mod.default;
|
|
1759
|
+
}
|
|
1760
|
+
function renderInto(el, fn, props) {
|
|
1761
|
+
const comp = new Component(fn, props);
|
|
1762
|
+
comp.mount(el);
|
|
1763
|
+
return comp;
|
|
1764
|
+
}
|
|
1765
|
+
function defineAsyncComponent(loader, options = {}) {
|
|
1766
|
+
const { delay = 200, timeout, ssr = "blocking", onError } = options;
|
|
1767
|
+
if (typeof window === "undefined") {
|
|
1768
|
+
if (ssr === "client-only") {
|
|
1769
|
+
const placeholder = () => "";
|
|
1770
|
+
placeholder.__asyncLoader = loader;
|
|
1771
|
+
placeholder.__asyncResolved = () => null;
|
|
1772
|
+
return placeholder;
|
|
1773
|
+
}
|
|
1774
|
+
let ssrResolved = null;
|
|
1775
|
+
let ssrPromise = null;
|
|
1776
|
+
const ssrLoad = () => {
|
|
1777
|
+
if (ssrPromise) return ssrPromise;
|
|
1778
|
+
ssrPromise = loader().then((mod) => {
|
|
1779
|
+
ssrResolved = resolveModule(mod);
|
|
1780
|
+
}).catch(() => {
|
|
1781
|
+
});
|
|
1782
|
+
return ssrPromise;
|
|
1783
|
+
};
|
|
1784
|
+
ssrLoad();
|
|
1785
|
+
const ssrWrapper = (props) => {
|
|
1786
|
+
if (ssrResolved) {
|
|
1787
|
+
return ssrResolved(props);
|
|
1788
|
+
}
|
|
1789
|
+
return "";
|
|
1790
|
+
};
|
|
1791
|
+
ssrWrapper.__asyncLoader = ssrLoad;
|
|
1792
|
+
ssrWrapper.__asyncResolved = () => ssrResolved;
|
|
1793
|
+
return ssrWrapper;
|
|
1794
|
+
}
|
|
1795
|
+
let cachedComponent = null;
|
|
1796
|
+
let cachedError = null;
|
|
1797
|
+
let cachedStatus = "pending";
|
|
1798
|
+
let loadPromise = null;
|
|
1799
|
+
function load() {
|
|
1800
|
+
if (loadPromise) return loadPromise;
|
|
1801
|
+
loadPromise = loader().then((mod) => {
|
|
1802
|
+
cachedComponent = resolveModule(mod);
|
|
1803
|
+
cachedStatus = "resolved";
|
|
1804
|
+
}).catch((error5) => {
|
|
1805
|
+
cachedError = error5 instanceof Error ? error5 : new Error(String(error5));
|
|
1806
|
+
cachedStatus = "errored";
|
|
1807
|
+
loadPromise = null;
|
|
1808
|
+
});
|
|
1809
|
+
return loadPromise;
|
|
1810
|
+
}
|
|
1811
|
+
load();
|
|
1812
|
+
function AsyncWrapper(props) {
|
|
1813
|
+
var _a2;
|
|
1814
|
+
if (cachedStatus === "resolved" && cachedComponent) {
|
|
1815
|
+
const el = document.createElement("div");
|
|
1816
|
+
el.style.display = "contents";
|
|
1817
|
+
const comp = renderInto(el, cachedComponent, props);
|
|
1818
|
+
onCleanup(() => comp.destroy());
|
|
1819
|
+
return el;
|
|
1820
|
+
}
|
|
1821
|
+
if (cachedStatus === "errored" && cachedError) {
|
|
1822
|
+
const el = document.createElement("div");
|
|
1823
|
+
el.style.display = "contents";
|
|
1824
|
+
if (options.error) {
|
|
1825
|
+
let alive2 = true;
|
|
1826
|
+
let currentComp2 = null;
|
|
1827
|
+
const swap2 = (fn, swapProps) => {
|
|
1828
|
+
if (!alive2) return;
|
|
1829
|
+
currentComp2 == null ? void 0 : currentComp2.destroy();
|
|
1830
|
+
currentComp2 = renderInto(el, fn, swapProps);
|
|
1831
|
+
};
|
|
1832
|
+
const retry = () => {
|
|
1833
|
+
loadPromise = null;
|
|
1834
|
+
cachedStatus = "pending";
|
|
1835
|
+
cachedError = null;
|
|
1836
|
+
if (options.loading) swap2(options.loading);
|
|
1837
|
+
load().then(() => {
|
|
1838
|
+
if (!alive2) return;
|
|
1839
|
+
if (cachedStatus === "resolved" && cachedComponent) {
|
|
1840
|
+
swap2(cachedComponent, props);
|
|
1841
|
+
} else if (cachedStatus === "errored" && cachedError) {
|
|
1842
|
+
if (options.error) swap2(options.error, { error: cachedError, retry });
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
};
|
|
1846
|
+
swap2(options.error, { error: cachedError, retry });
|
|
1847
|
+
onDestroy(() => {
|
|
1848
|
+
alive2 = false;
|
|
1849
|
+
currentComp2 == null ? void 0 : currentComp2.destroy();
|
|
1850
|
+
currentComp2 = null;
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
return el;
|
|
1854
|
+
}
|
|
1855
|
+
const container = document.createElement("div");
|
|
1856
|
+
container.style.display = "contents";
|
|
1857
|
+
let alive = true;
|
|
1858
|
+
let currentComp = null;
|
|
1859
|
+
let delayTimer = null;
|
|
1860
|
+
let timeoutTimer = null;
|
|
1861
|
+
const swap = (fn, swapProps) => {
|
|
1862
|
+
if (!alive) return;
|
|
1863
|
+
currentComp == null ? void 0 : currentComp.destroy();
|
|
1864
|
+
currentComp = renderInto(container, fn, swapProps);
|
|
1865
|
+
};
|
|
1866
|
+
const retryWith = (retryProps) => () => {
|
|
1867
|
+
loadPromise = null;
|
|
1868
|
+
cachedStatus = "pending";
|
|
1869
|
+
cachedError = null;
|
|
1870
|
+
if (options.loading) swap(options.loading);
|
|
1871
|
+
load().then(() => {
|
|
1872
|
+
if (cachedStatus === "resolved" && cachedComponent) {
|
|
1873
|
+
swap(cachedComponent, retryProps);
|
|
1874
|
+
} else if (cachedStatus === "errored" && cachedError) {
|
|
1875
|
+
if (options.error) {
|
|
1876
|
+
swap(options.error, {
|
|
1877
|
+
error: cachedError,
|
|
1878
|
+
retry: retryWith(retryProps)
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
};
|
|
1884
|
+
onDestroy(() => {
|
|
1885
|
+
alive = false;
|
|
1886
|
+
currentComp == null ? void 0 : currentComp.destroy();
|
|
1887
|
+
currentComp = null;
|
|
1888
|
+
if (delayTimer != null) clearTimeout(delayTimer);
|
|
1889
|
+
if (timeoutTimer != null) clearTimeout(timeoutTimer);
|
|
1890
|
+
});
|
|
1891
|
+
const suspenseCtx = (_a2 = inject(SuspenseContext)) != null ? _a2 : null;
|
|
1892
|
+
const showResolved = (compFn) => swap(compFn, props);
|
|
1893
|
+
const showError = (err) => {
|
|
1894
|
+
if (options.error) swap(options.error, { error: err, retry: retryWith(props) });
|
|
1895
|
+
};
|
|
1896
|
+
const showLoading = () => {
|
|
1897
|
+
if (options.loading) swap(options.loading);
|
|
1898
|
+
};
|
|
1899
|
+
const instancePromise = load().then(() => {
|
|
1900
|
+
if (!alive) return;
|
|
1901
|
+
if (cachedStatus === "resolved" && cachedComponent) {
|
|
1902
|
+
showResolved(cachedComponent);
|
|
1903
|
+
} else if (cachedStatus === "errored" && cachedError) {
|
|
1904
|
+
showError(cachedError);
|
|
1905
|
+
if (onError) onError(cachedError, retryWith(props));
|
|
1906
|
+
}
|
|
1907
|
+
if (delayTimer != null) clearTimeout(delayTimer);
|
|
1908
|
+
if (timeoutTimer != null) clearTimeout(timeoutTimer);
|
|
1909
|
+
});
|
|
1910
|
+
if (suspenseCtx) {
|
|
1911
|
+
suspenseCtx.register(instancePromise);
|
|
1912
|
+
}
|
|
1913
|
+
if (delay > 0) {
|
|
1914
|
+
delayTimer = setTimeout(() => {
|
|
1915
|
+
if (alive && cachedStatus === "pending") {
|
|
1916
|
+
showLoading();
|
|
1917
|
+
}
|
|
1918
|
+
}, delay);
|
|
1919
|
+
} else if (options.loading) {
|
|
1920
|
+
showLoading();
|
|
1921
|
+
}
|
|
1922
|
+
if (timeout != null) {
|
|
1923
|
+
timeoutTimer = setTimeout(() => {
|
|
1924
|
+
if (alive && cachedStatus === "pending") {
|
|
1925
|
+
const err = new Error(`[defineAsyncComponent] Timeout after ${timeout}ms`);
|
|
1926
|
+
cachedError = err;
|
|
1927
|
+
cachedStatus = "errored";
|
|
1928
|
+
showError(err);
|
|
1929
|
+
if (onError) onError(err, retryWith(props));
|
|
1930
|
+
}
|
|
1931
|
+
}, timeout);
|
|
1932
|
+
}
|
|
1933
|
+
return container;
|
|
1934
|
+
}
|
|
1935
|
+
AsyncWrapper.__asyncLoader = load;
|
|
1936
|
+
AsyncWrapper.__asyncResolved = () => cachedComponent;
|
|
1937
|
+
return AsyncWrapper;
|
|
1938
|
+
}
|
|
1806
1939
|
function For(props) {
|
|
1807
1940
|
const fragment = document.createDocumentFragment();
|
|
1808
1941
|
const marker = document.createComment("");
|
|
1809
1942
|
fragment.appendChild(marker);
|
|
1810
1943
|
let entries = [];
|
|
1811
|
-
let
|
|
1812
|
-
const keyFn = props.
|
|
1944
|
+
let fallbackNodes = [];
|
|
1945
|
+
const keyFn = props.key;
|
|
1813
1946
|
const renderFn = props.children;
|
|
1814
1947
|
const getList = () => {
|
|
1815
1948
|
var _a2, _b;
|
|
1816
1949
|
const input = props.each;
|
|
1817
1950
|
if (signals.isSignal(input)) return (_a2 = input.value) != null ? _a2 : [];
|
|
1818
|
-
if (
|
|
1951
|
+
if (shared.isFunction(input)) return (_b = input()) != null ? _b : [];
|
|
1819
1952
|
return input != null ? input : [];
|
|
1820
1953
|
};
|
|
1821
1954
|
const getKey = (item) => keyFn ? keyFn(item) : item;
|
|
1822
|
-
const
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1955
|
+
const normalizeNodes = (value) => {
|
|
1956
|
+
if (Array.isArray(value)) {
|
|
1957
|
+
const nodes = [];
|
|
1958
|
+
for (const item of value) {
|
|
1959
|
+
nodes.push(...normalizeNodes(item));
|
|
1960
|
+
}
|
|
1961
|
+
return nodes;
|
|
1962
|
+
}
|
|
1963
|
+
return [normalizeNode(value)];
|
|
1964
|
+
};
|
|
1965
|
+
const mountValue = (value, parent, before) => {
|
|
1966
|
+
const nodes = normalizeNodes(value);
|
|
1967
|
+
for (const node of nodes) {
|
|
1968
|
+
if (before) {
|
|
1969
|
+
parent.insertBefore(node, before);
|
|
1833
1970
|
} else {
|
|
1834
|
-
node
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1971
|
+
parent.appendChild(node);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
return nodes;
|
|
1975
|
+
};
|
|
1976
|
+
const mountFallback = (parent, before) => {
|
|
1977
|
+
if (!props.fallback) return;
|
|
1978
|
+
const nodes = mountValue(props.fallback(), parent, before);
|
|
1979
|
+
fallbackNodes = nodes;
|
|
1980
|
+
};
|
|
1981
|
+
const clearFallback = () => {
|
|
1982
|
+
for (const node of fallbackNodes) {
|
|
1983
|
+
if (node.parentNode) {
|
|
1984
|
+
node.parentNode.removeChild(node);
|
|
1842
1985
|
}
|
|
1843
|
-
} finally {
|
|
1844
|
-
setActiveScope(prevScope);
|
|
1845
1986
|
}
|
|
1846
|
-
|
|
1987
|
+
fallbackNodes = [];
|
|
1988
|
+
};
|
|
1989
|
+
const renderItem = (item, index, parent, before) => {
|
|
1990
|
+
const parentScope = getActiveScope();
|
|
1991
|
+
const scope = createScope(parentScope);
|
|
1992
|
+
let mountedNodes = [];
|
|
1993
|
+
runWithScope(scope, () => {
|
|
1994
|
+
mountedNodes = mountValue(renderFn(item, index), parent, before);
|
|
1995
|
+
});
|
|
1996
|
+
return { key: getKey(item), item, nodes: mountedNodes, scope };
|
|
1847
1997
|
};
|
|
1848
1998
|
const disposeItem = (entry) => {
|
|
1849
1999
|
disposeScope(entry.scope);
|
|
1850
|
-
|
|
1851
|
-
|
|
2000
|
+
for (const node of entry.nodes) {
|
|
2001
|
+
if (node.parentNode) {
|
|
2002
|
+
node.parentNode.removeChild(node);
|
|
2003
|
+
}
|
|
1852
2004
|
}
|
|
1853
2005
|
};
|
|
1854
|
-
signals.
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
if (
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if (newItems.length === 0) {
|
|
1862
|
-
if (props.fallback) {
|
|
1863
|
-
const fb = props.fallback();
|
|
1864
|
-
if (isComponent(fb)) {
|
|
1865
|
-
fb.mount(fragment, marker);
|
|
1866
|
-
fallbackNode = (_a2 = fb.firstChild) != null ? _a2 : document.createComment("empty");
|
|
1867
|
-
} else {
|
|
1868
|
-
fallbackNode = fb;
|
|
1869
|
-
fragment.insertBefore(fallbackNode, marker);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
return { prev: newItems };
|
|
1873
|
-
}
|
|
2006
|
+
const effectRunner = signals.effect(() => {
|
|
2007
|
+
const newItems = getList();
|
|
2008
|
+
const parent = marker.parentNode;
|
|
2009
|
+
if (!parent) {
|
|
2010
|
+
if (newItems.length === 0) {
|
|
2011
|
+
mountFallback(fragment, marker);
|
|
2012
|
+
} else {
|
|
1874
2013
|
entries = new Array(newItems.length);
|
|
1875
|
-
|
|
1876
|
-
|
|
2014
|
+
let idx = 0;
|
|
2015
|
+
for (const newItem of newItems) {
|
|
2016
|
+
entries[idx] = renderItem(newItem, idx, fragment, marker);
|
|
2017
|
+
idx++;
|
|
1877
2018
|
}
|
|
1878
|
-
return { prev: newItems };
|
|
1879
2019
|
}
|
|
1880
|
-
|
|
1881
|
-
return { prev: newItems };
|
|
1882
|
-
},
|
|
1883
|
-
{
|
|
1884
|
-
prev: []
|
|
2020
|
+
return;
|
|
1885
2021
|
}
|
|
1886
|
-
|
|
2022
|
+
reconcile(parent, newItems);
|
|
2023
|
+
});
|
|
1887
2024
|
function reconcile(parent, newItems) {
|
|
1888
|
-
var _a2;
|
|
1889
2025
|
const oldLen = entries.length;
|
|
1890
2026
|
const newLen = newItems.length;
|
|
1891
2027
|
if (newLen === 0) {
|
|
@@ -1893,22 +2029,14 @@ function For(props) {
|
|
|
1893
2029
|
disposeItem(entries[i]);
|
|
1894
2030
|
}
|
|
1895
2031
|
entries = [];
|
|
1896
|
-
if (props.fallback &&
|
|
1897
|
-
|
|
1898
|
-
if (isComponent(fb)) {
|
|
1899
|
-
fb.mount(parent, marker);
|
|
1900
|
-
fallbackNode = (_a2 = fb.firstChild) != null ? _a2 : document.createComment("empty");
|
|
1901
|
-
} else {
|
|
1902
|
-
fallbackNode = fb;
|
|
1903
|
-
parent.insertBefore(fallbackNode, marker);
|
|
1904
|
-
}
|
|
2032
|
+
if (props.fallback && fallbackNodes.length === 0) {
|
|
2033
|
+
mountFallback(parent, marker);
|
|
1905
2034
|
}
|
|
1906
2035
|
return;
|
|
1907
2036
|
}
|
|
1908
|
-
if (oldLen === 0 ||
|
|
1909
|
-
if (
|
|
1910
|
-
|
|
1911
|
-
fallbackNode = null;
|
|
2037
|
+
if (oldLen === 0 || fallbackNodes.length > 0) {
|
|
2038
|
+
if (fallbackNodes.length > 0) {
|
|
2039
|
+
clearFallback();
|
|
1912
2040
|
}
|
|
1913
2041
|
entries = new Array(newLen);
|
|
1914
2042
|
const batchFragment2 = document.createDocumentFragment();
|
|
@@ -1922,46 +2050,76 @@ function For(props) {
|
|
|
1922
2050
|
for (let i = 0; i < oldLen; i++) {
|
|
1923
2051
|
const entry = entries[i];
|
|
1924
2052
|
const list = oldKeyMap.get(entry.key);
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
oldKeyMap.set(entry.key, [entry]);
|
|
1929
|
-
}
|
|
2053
|
+
const pair = [entry, i];
|
|
2054
|
+
if (list) list.push(pair);
|
|
2055
|
+
else oldKeyMap.set(entry.key, [pair]);
|
|
1930
2056
|
}
|
|
1931
2057
|
const newEntries = new Array(newLen);
|
|
1932
2058
|
const toRemove = [];
|
|
1933
|
-
|
|
2059
|
+
let batchFragment = null;
|
|
2060
|
+
const newIndexToOldIndex = new Int32Array(newLen);
|
|
2061
|
+
let moved = false;
|
|
2062
|
+
let maxOldSeen = 0;
|
|
2063
|
+
const newKeys = new Array(newLen);
|
|
2064
|
+
for (let i = 0; i < newLen; i++) {
|
|
2065
|
+
newKeys[i] = getKey(newItems[i]);
|
|
2066
|
+
}
|
|
1934
2067
|
for (let i = 0; i < newLen; i++) {
|
|
1935
2068
|
const item = newItems[i];
|
|
1936
|
-
const key =
|
|
2069
|
+
const key = newKeys[i];
|
|
1937
2070
|
const oldList = oldKeyMap.get(key);
|
|
1938
2071
|
if (oldList && oldList.length > 0) {
|
|
1939
|
-
|
|
2072
|
+
const [reused, oldIndex] = oldList.shift();
|
|
2073
|
+
if (Object.is(reused.item, item)) {
|
|
2074
|
+
reused.item = item;
|
|
2075
|
+
newEntries[i] = reused;
|
|
2076
|
+
newIndexToOldIndex[i] = oldIndex + 1;
|
|
2077
|
+
if (oldIndex < maxOldSeen) moved = true;
|
|
2078
|
+
else maxOldSeen = oldIndex;
|
|
2079
|
+
} else {
|
|
2080
|
+
if (!batchFragment) batchFragment = document.createDocumentFragment();
|
|
2081
|
+
disposeItem(reused);
|
|
2082
|
+
newEntries[i] = renderItem(item, i, batchFragment, null);
|
|
2083
|
+
}
|
|
1940
2084
|
} else {
|
|
2085
|
+
if (!batchFragment) batchFragment = document.createDocumentFragment();
|
|
1941
2086
|
newEntries[i] = renderItem(item, i, batchFragment, null);
|
|
1942
2087
|
}
|
|
1943
2088
|
}
|
|
1944
2089
|
for (const list of oldKeyMap.values()) {
|
|
1945
|
-
for (const entry of list)
|
|
1946
|
-
|
|
2090
|
+
for (const [entry] of list) toRemove.push(entry);
|
|
2091
|
+
}
|
|
2092
|
+
for (const entry of toRemove) disposeItem(entry);
|
|
2093
|
+
const lis = moved ? getSequence(newIndexToOldIndex) : [];
|
|
2094
|
+
let lisCursor = lis.length - 1;
|
|
2095
|
+
let nextNode = marker;
|
|
2096
|
+
for (let i = newLen - 1; i >= 0; i--) {
|
|
2097
|
+
const entry = newEntries[i];
|
|
2098
|
+
const nodes = entry.nodes;
|
|
2099
|
+
const isFresh = newIndexToOldIndex[i] === 0;
|
|
2100
|
+
const inLis = !isFresh && moved && lisCursor >= 0 && i === lis[lisCursor];
|
|
2101
|
+
if (inLis) {
|
|
2102
|
+
lisCursor--;
|
|
2103
|
+
for (let j = nodes.length - 1; j >= 0; j--) nextNode = nodes[j];
|
|
2104
|
+
continue;
|
|
2105
|
+
}
|
|
2106
|
+
for (let j = nodes.length - 1; j >= 0; j--) {
|
|
2107
|
+
const node = nodes[j];
|
|
2108
|
+
if (node.nextSibling !== nextNode) {
|
|
2109
|
+
parent.insertBefore(node, nextNode);
|
|
2110
|
+
}
|
|
2111
|
+
nextNode = node;
|
|
1947
2112
|
}
|
|
1948
|
-
}
|
|
1949
|
-
for (const entry of toRemove) {
|
|
1950
|
-
disposeItem(entry);
|
|
1951
|
-
}
|
|
1952
|
-
for (let i = 0; i < newLen; i++) {
|
|
1953
|
-
const node = newEntries[i].node;
|
|
1954
|
-
parent.insertBefore(node, marker);
|
|
1955
2113
|
}
|
|
1956
2114
|
entries = newEntries;
|
|
1957
2115
|
}
|
|
1958
2116
|
onCleanup(() => {
|
|
2117
|
+
effectRunner.stop();
|
|
1959
2118
|
for (const entry of entries) {
|
|
1960
2119
|
disposeItem(entry);
|
|
1961
2120
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
}
|
|
2121
|
+
entries = [];
|
|
2122
|
+
clearFallback();
|
|
1965
2123
|
if (marker.parentNode) {
|
|
1966
2124
|
marker.parentNode.removeChild(marker);
|
|
1967
2125
|
}
|
|
@@ -1977,49 +2135,44 @@ exports.Portal = Portal;
|
|
|
1977
2135
|
exports.Suspense = Suspense;
|
|
1978
2136
|
exports.addEvent = addEvent;
|
|
1979
2137
|
exports.addEventListener = addEventListener;
|
|
2138
|
+
exports.beginHydration = beginHydration;
|
|
1980
2139
|
exports.bindElement = bindElement;
|
|
2140
|
+
exports.child = child;
|
|
2141
|
+
exports.clearDelegatedEvents = clearDelegatedEvents;
|
|
2142
|
+
exports.consumeTeleportAnchor = consumeTeleportAnchor;
|
|
2143
|
+
exports.consumeTeleportBlock = consumeTeleportBlock;
|
|
1981
2144
|
exports.createApp = createApp;
|
|
1982
2145
|
exports.createComponent = createComponent;
|
|
1983
2146
|
exports.createResource = createResource;
|
|
1984
|
-
exports.
|
|
2147
|
+
exports.defineAsyncComponent = defineAsyncComponent;
|
|
1985
2148
|
exports.delegateEvents = delegateEvents;
|
|
1986
|
-
exports.disposeScope = disposeScope;
|
|
1987
2149
|
exports.endHydration = endHydration;
|
|
1988
|
-
exports.getActiveScope = getActiveScope;
|
|
1989
|
-
exports.getFirstDOMNode = getFirstDOMNode;
|
|
1990
2150
|
exports.getHydrationKey = getHydrationKey;
|
|
1991
2151
|
exports.getRenderedElement = getRenderedElement;
|
|
1992
2152
|
exports.hydrate = hydrate;
|
|
1993
2153
|
exports.inject = inject;
|
|
1994
2154
|
exports.insert = insert;
|
|
1995
|
-
exports.insertNode = insertNode;
|
|
1996
2155
|
exports.isComponent = isComponent;
|
|
1997
2156
|
exports.isFragment = isFragment;
|
|
1998
2157
|
exports.isHydrating = isHydrating;
|
|
1999
2158
|
exports.isPortal = isPortal;
|
|
2000
|
-
exports.isSameNode = isSameNode;
|
|
2001
2159
|
exports.isSuspense = isSuspense;
|
|
2002
|
-
exports.
|
|
2003
|
-
exports.mapSSRNodes = mapSSRNodes;
|
|
2160
|
+
exports.next = next;
|
|
2004
2161
|
exports.normalizeClass = normalizeClass;
|
|
2005
|
-
exports.
|
|
2162
|
+
exports.nthChild = nthChild;
|
|
2006
2163
|
exports.omitProps = omitProps;
|
|
2007
|
-
exports.onCleanup = onCleanup;
|
|
2008
2164
|
exports.onDestroy = onDestroy;
|
|
2009
2165
|
exports.onMount = onMount;
|
|
2010
2166
|
exports.onUpdate = onUpdate;
|
|
2011
2167
|
exports.patchAttr = patchAttr;
|
|
2168
|
+
exports.patchAttrHydrate = patchAttrHydrate;
|
|
2012
2169
|
exports.patchClass = patchClass;
|
|
2170
|
+
exports.patchClassHydrate = patchClassHydrate;
|
|
2013
2171
|
exports.patchStyle = patchStyle;
|
|
2172
|
+
exports.patchStyleHydrate = patchStyleHydrate;
|
|
2014
2173
|
exports.provide = provide;
|
|
2015
|
-
exports.removeNode = removeNode;
|
|
2016
|
-
exports.replaceNode = replaceNode;
|
|
2017
2174
|
exports.resetHydrationKey = resetHydrationKey;
|
|
2018
|
-
exports.runWithScope = runWithScope;
|
|
2019
|
-
exports.setActiveScope = setActiveScope;
|
|
2020
2175
|
exports.setStyle = setStyle;
|
|
2021
|
-
exports.shallowCompare = shallowCompare;
|
|
2022
|
-
exports.startHydration = startHydration;
|
|
2023
2176
|
exports.template = template;
|
|
2024
2177
|
//# sourceMappingURL=template.dev.cjs.js.map
|
|
2025
2178
|
//# sourceMappingURL=template.dev.cjs.js.map
|