@estjs/template 0.0.14 → 0.0.15-beta.1
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/README.md +14 -0
- package/dist/template.cjs.js +4 -3
- package/dist/template.cjs.js.map +1 -1
- package/dist/template.d.cts +601 -310
- package/dist/template.d.ts +601 -310
- package/dist/template.dev.cjs.js +1671 -779
- package/dist/template.dev.esm.js +1641 -777
- package/dist/template.esm.js +4 -3
- package/dist/template.esm.js.map +1 -1
- package/package.json +5 -5
- package/types/component.d.ts +2 -2
- package/types/jsx.d.ts +149 -122
- package/types/node.d.ts +3 -3
package/dist/template.dev.cjs.js
CHANGED
|
@@ -1,946 +1,1838 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var shared = require('@estjs/shared');
|
|
4
|
-
var
|
|
4
|
+
var signals = require('@estjs/signals');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @estjs/template v0.0.
|
|
7
|
+
* @estjs/template v0.0.15-beta.1
|
|
8
8
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
9
9
|
* @license MIT
|
|
10
10
|
**/
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
var __async = (__this, __arguments, generator) => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
var fulfilled = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.next(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var rejected = (value) => {
|
|
37
|
+
try {
|
|
38
|
+
step(generator.throw(value));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
reject(e);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
44
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
var activeContext = null;
|
|
48
|
+
var contextStack = [];
|
|
49
|
+
var contextId = 0;
|
|
50
|
+
function createContext(parent = null) {
|
|
51
|
+
const context = {
|
|
52
|
+
id: ++contextId,
|
|
53
|
+
parent,
|
|
54
|
+
provides: /* @__PURE__ */ new Map(),
|
|
55
|
+
cleanup: /* @__PURE__ */ new Set(),
|
|
56
|
+
mount: /* @__PURE__ */ new Set(),
|
|
57
|
+
update: /* @__PURE__ */ new Set(),
|
|
58
|
+
destroy: /* @__PURE__ */ new Set(),
|
|
59
|
+
isMount: false,
|
|
60
|
+
isDestroy: false,
|
|
61
|
+
children: /* @__PURE__ */ new Set()
|
|
62
|
+
};
|
|
63
|
+
if (parent) {
|
|
64
|
+
parent.children.add(context);
|
|
65
|
+
}
|
|
66
|
+
return context;
|
|
67
|
+
}
|
|
68
|
+
function getActiveContext() {
|
|
69
|
+
return activeContext;
|
|
70
|
+
}
|
|
71
|
+
function pushContextStack(context) {
|
|
72
|
+
if (activeContext) {
|
|
73
|
+
contextStack.push(activeContext);
|
|
74
|
+
}
|
|
75
|
+
activeContext = context;
|
|
76
|
+
}
|
|
77
|
+
function popContextStack() {
|
|
78
|
+
activeContext = contextStack.pop() || null;
|
|
79
|
+
}
|
|
80
|
+
function destroyContext(context) {
|
|
81
|
+
if (!context || context.isDestroy) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const childrenToDestroy = Array.from(context.children);
|
|
85
|
+
childrenToDestroy.forEach(destroyContext);
|
|
86
|
+
cleanupContext(context);
|
|
87
|
+
}
|
|
88
|
+
function cleanupContext(context) {
|
|
89
|
+
if (!context || context.isDestroy) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (context.parent) {
|
|
93
|
+
context.parent.children.delete(context);
|
|
94
|
+
context.parent = null;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
context.cleanup.forEach((fn) => fn());
|
|
98
|
+
context.cleanup.clear();
|
|
99
|
+
context.mount.clear();
|
|
100
|
+
context.update.clear();
|
|
101
|
+
context.destroy.clear();
|
|
102
|
+
context.provides.clear();
|
|
103
|
+
context.children.clear();
|
|
104
|
+
} catch (error_) {
|
|
105
|
+
shared.error("Error during context cleanup:", error_);
|
|
106
|
+
}
|
|
107
|
+
context.isDestroy = true;
|
|
108
|
+
}
|
|
109
|
+
var LIFECYCLE = {
|
|
110
|
+
mount: "mount",
|
|
111
|
+
destroy: "destroy",
|
|
112
|
+
update: "update"
|
|
113
|
+
};
|
|
114
|
+
function registerLifecycleHook(type, hook) {
|
|
115
|
+
const context = getActiveContext();
|
|
116
|
+
if (!context) {
|
|
117
|
+
shared.error(`Cannot register ${type} hook outside component context`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!LIFECYCLE[type]) {
|
|
121
|
+
shared.error(`Invalid lifecycle type: ${type}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (type === LIFECYCLE.mount && context.isMount) {
|
|
125
|
+
try {
|
|
126
|
+
hook();
|
|
127
|
+
} catch (error_) {
|
|
128
|
+
shared.error(`Error in ${type} hook:`, error_);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
context[type].add(hook);
|
|
133
|
+
}
|
|
134
|
+
function triggerLifecycleHook(type) {
|
|
135
|
+
const context = getActiveContext();
|
|
136
|
+
if (!context) {
|
|
137
|
+
shared.error(`Cannot trigger ${type} hook outside component context`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const hooks = context[type];
|
|
141
|
+
if (!(hooks == null ? void 0 : hooks.size)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
hooks.forEach((hook) => {
|
|
145
|
+
try {
|
|
146
|
+
hook();
|
|
147
|
+
} catch (error_) {
|
|
148
|
+
{
|
|
149
|
+
shared.error(`Error in ${type} lifecycle hook:`, error_);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function onMount(hook) {
|
|
155
|
+
registerLifecycleHook(LIFECYCLE.mount, hook);
|
|
156
|
+
}
|
|
157
|
+
function onDestroy(hook) {
|
|
158
|
+
registerLifecycleHook(LIFECYCLE.destroy, hook);
|
|
159
|
+
}
|
|
160
|
+
function onUpdate(hook) {
|
|
161
|
+
registerLifecycleHook(LIFECYCLE.update, hook);
|
|
162
|
+
}
|
|
11
163
|
|
|
12
|
-
|
|
13
|
-
// src/sharedConfig.ts
|
|
164
|
+
// src/constants.ts
|
|
14
165
|
var EVENT_PREFIX = "on";
|
|
15
|
-
var UPDATE_PREFIX = "update";
|
|
16
|
-
var CHILDREN_PROP = "children";
|
|
17
|
-
var EMPTY_TEMPLATE = "";
|
|
18
|
-
var FRAGMENT_PROP_KEY = "0";
|
|
19
|
-
var SINGLE_PROP_KEY = "1";
|
|
20
166
|
var REF_KEY = "ref";
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
167
|
+
var KEY_PROP = "key";
|
|
168
|
+
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
169
|
+
var XLINK_NAMESPACE = "http://www.w3.org/2000/xlink";
|
|
170
|
+
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
171
|
+
var DATA_IDX_REGEX = /^\d+-\d+$/;
|
|
172
|
+
var MAX_KEY_LENGTH = 1e3;
|
|
173
|
+
var componentKeyPrefixCache = /* @__PURE__ */ new WeakMap();
|
|
174
|
+
function getComponentKey(type) {
|
|
175
|
+
let prefix = componentKeyPrefixCache.get(type);
|
|
176
|
+
if (!prefix) {
|
|
177
|
+
const name = type.name || "anonymous";
|
|
178
|
+
const hash = simpleHash(type.toString()).toString(36);
|
|
179
|
+
prefix = `${name}_${hash}`;
|
|
180
|
+
componentKeyPrefixCache.set(type, prefix);
|
|
181
|
+
}
|
|
182
|
+
return prefix;
|
|
183
|
+
}
|
|
184
|
+
function simpleHash(str) {
|
|
185
|
+
let hash = 0;
|
|
186
|
+
const len = str.length < 100 ? str.length : 100;
|
|
187
|
+
for (let i = 0; i < len; i++) {
|
|
188
|
+
hash = Math.trunc((hash << 5) - hash + str.charCodeAt(i));
|
|
28
189
|
}
|
|
29
|
-
|
|
30
|
-
|
|
190
|
+
return hash < 0 ? -hash : hash;
|
|
191
|
+
}
|
|
192
|
+
var symbolIdCounter = 0;
|
|
193
|
+
function normalizeKey(key) {
|
|
194
|
+
if (shared.isFalsy(key)) {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
if (shared.isString(key)) {
|
|
198
|
+
if (key.length <= MAX_KEY_LENGTH) {
|
|
199
|
+
return key;
|
|
200
|
+
}
|
|
201
|
+
{
|
|
202
|
+
shared.warn(
|
|
203
|
+
`[Key System] Key length exceeds ${MAX_KEY_LENGTH} characters. Consider using a shorter identifier.`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return `${key.slice(0, MAX_KEY_LENGTH - 10)}_${simpleHash(key).toString(36)}`;
|
|
31
207
|
}
|
|
32
|
-
|
|
33
|
-
|
|
208
|
+
if (shared.isNumber(key)) {
|
|
209
|
+
{
|
|
210
|
+
if (key !== key) {
|
|
211
|
+
shared.warn("[Key System] NaN cannot be used as a key");
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
if (!Number.isFinite(key)) {
|
|
215
|
+
shared.warn("[Key System] Infinity cannot be used as a key");
|
|
216
|
+
return void 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return String(key);
|
|
34
220
|
}
|
|
35
|
-
|
|
36
|
-
|
|
221
|
+
if (shared.isSymbol(key)) {
|
|
222
|
+
const globalKey = Symbol.keyFor(key);
|
|
223
|
+
if (globalKey) {
|
|
224
|
+
return `_s.${globalKey}`;
|
|
225
|
+
}
|
|
226
|
+
const desc = key.description;
|
|
227
|
+
return desc ? `_s.${desc}` : `${symbolIdCounter++}`;
|
|
37
228
|
}
|
|
38
|
-
|
|
39
|
-
|
|
229
|
+
return String(key);
|
|
230
|
+
}
|
|
231
|
+
var NODE_KEY_SYMBOL = Symbol("essor.key");
|
|
232
|
+
function setNodeKey(node, key) {
|
|
233
|
+
if (isComponent(node)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (!node || node.nodeType === Node.DOCUMENT_NODE) {
|
|
237
|
+
{
|
|
238
|
+
shared.warn("[Key System] Cannot set key on invalid node");
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
40
241
|
}
|
|
41
|
-
|
|
42
|
-
|
|
242
|
+
const normalizedKey = normalizeKey(key);
|
|
243
|
+
if (shared.isFalsy(normalizedKey)) {
|
|
244
|
+
delete node[NODE_KEY_SYMBOL];
|
|
245
|
+
} else {
|
|
246
|
+
node[NODE_KEY_SYMBOL] = normalizedKey;
|
|
43
247
|
}
|
|
44
|
-
};
|
|
45
|
-
var renderContext = new RenderContext();
|
|
46
|
-
var componentMap = /* @__PURE__ */ new Map();
|
|
47
|
-
function enterComponent(temp, index) {
|
|
48
|
-
componentMap.set(temp, {
|
|
49
|
-
index
|
|
50
|
-
});
|
|
51
248
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
return (
|
|
249
|
+
function getNodeKey(node) {
|
|
250
|
+
if (!node) return void 0;
|
|
251
|
+
return isComponent(node) ? node.key : node[NODE_KEY_SYMBOL];
|
|
55
252
|
}
|
|
56
253
|
|
|
57
|
-
// src/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
254
|
+
// src/utils.ts
|
|
255
|
+
function removeNode(node) {
|
|
256
|
+
if (!node) return;
|
|
257
|
+
try {
|
|
258
|
+
if (isComponent(node)) {
|
|
259
|
+
node.destroy();
|
|
260
|
+
} else {
|
|
261
|
+
const element = node;
|
|
262
|
+
if (element.parentElement) {
|
|
263
|
+
element.remove();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
} catch (_error) {
|
|
267
|
+
shared.error("Failed to remove node:", _error);
|
|
65
268
|
}
|
|
66
|
-
|
|
269
|
+
}
|
|
270
|
+
function insertNode(parent, child, before = null) {
|
|
271
|
+
if (!parent || !child) return;
|
|
272
|
+
try {
|
|
273
|
+
const beforeNode = isComponent(before) ? before.firstChild : before;
|
|
274
|
+
if (isComponent(child)) {
|
|
275
|
+
child.mount(parent, beforeNode);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (beforeNode) {
|
|
279
|
+
parent.insertBefore(child, beforeNode);
|
|
280
|
+
} else {
|
|
281
|
+
if (true) {
|
|
282
|
+
if (!child) {
|
|
283
|
+
shared.error("insertNode: child is not a Node", child);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
parent.appendChild(child);
|
|
287
|
+
}
|
|
288
|
+
} catch (_error) {
|
|
289
|
+
shared.error("Failed to insert node:", _error);
|
|
67
290
|
}
|
|
68
|
-
|
|
291
|
+
}
|
|
292
|
+
function replaceNode(parent, newNode, oldNode) {
|
|
293
|
+
if (!parent || !newNode || !oldNode || newNode === oldNode) return;
|
|
294
|
+
try {
|
|
295
|
+
insertNode(parent, newNode, oldNode);
|
|
296
|
+
removeNode(oldNode);
|
|
297
|
+
} catch (_error) {
|
|
298
|
+
shared.error("Failed to replace node:", _error);
|
|
69
299
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
300
|
+
}
|
|
301
|
+
function getFirstDOMNode(node) {
|
|
302
|
+
if (!node) {
|
|
303
|
+
return null;
|
|
74
304
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return _LifecycleContext.context[context];
|
|
305
|
+
if (isComponent(node)) {
|
|
306
|
+
return node.firstChild;
|
|
78
307
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
308
|
+
return node;
|
|
309
|
+
}
|
|
310
|
+
function isSameNode(a, b) {
|
|
311
|
+
const keyA = getNodeKey(a);
|
|
312
|
+
const keyB = getNodeKey(b);
|
|
313
|
+
if (keyA !== keyB) {
|
|
314
|
+
return false;
|
|
82
315
|
}
|
|
83
|
-
|
|
84
|
-
|
|
316
|
+
const aIsComponent = isComponent(a);
|
|
317
|
+
const bIsComponent = isComponent(b);
|
|
318
|
+
if (aIsComponent && bIsComponent) {
|
|
319
|
+
return a.component === b.component;
|
|
85
320
|
}
|
|
86
|
-
|
|
87
|
-
|
|
321
|
+
if (aIsComponent !== bIsComponent) {
|
|
322
|
+
return false;
|
|
88
323
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
324
|
+
const aNode = a;
|
|
325
|
+
const bNode = b;
|
|
326
|
+
if (aNode.nodeType !== bNode.nodeType) {
|
|
327
|
+
return false;
|
|
92
328
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_LifecycleContext.context = {};
|
|
96
|
-
var LifecycleContext = _LifecycleContext;
|
|
97
|
-
|
|
98
|
-
// src/ssgNode.ts
|
|
99
|
-
function isSSGNode(node) {
|
|
100
|
-
return node instanceof SSGNode;
|
|
101
|
-
}
|
|
102
|
-
var componentIndex = 1;
|
|
103
|
-
var SSGNode = class extends LifecycleContext {
|
|
104
|
-
constructor(template, props = {}, key) {
|
|
105
|
-
super();
|
|
106
|
-
this.template = template;
|
|
107
|
-
this.props = props;
|
|
108
|
-
this.key = key;
|
|
109
|
-
enterComponent(template, componentIndex);
|
|
110
|
-
this.templates = this.processTemplate();
|
|
329
|
+
if (aNode.nodeType === Node.ELEMENT_NODE) {
|
|
330
|
+
return aNode.tagName === bNode.tagName;
|
|
111
331
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return [];
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
function normalizeNode(node) {
|
|
335
|
+
if (shared.isHTMLElement(node)) {
|
|
336
|
+
return node;
|
|
119
337
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (p1.includes("data-ci")) return match;
|
|
124
|
-
return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_, tagName, attrs) => {
|
|
125
|
-
return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
|
|
126
|
-
});
|
|
127
|
-
} else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
|
|
128
|
-
return `<!--${0 /* TEXT */}-${componentIndex}-->${p2}<!$>`;
|
|
129
|
-
}
|
|
130
|
-
return match;
|
|
131
|
-
});
|
|
338
|
+
if (shared.isPrimitive(node)) {
|
|
339
|
+
const textContent = shared.isFalsy(node) ? "" : String(node);
|
|
340
|
+
return document.createTextNode(textContent);
|
|
132
341
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
342
|
+
return node;
|
|
343
|
+
}
|
|
344
|
+
function isHtmlInputElement(val) {
|
|
345
|
+
return val instanceof HTMLInputElement;
|
|
346
|
+
}
|
|
347
|
+
function isHtmlSelectElement(val) {
|
|
348
|
+
return val instanceof HTMLSelectElement;
|
|
349
|
+
}
|
|
350
|
+
function isHtmlTextAreaElement(val) {
|
|
351
|
+
return val instanceof HTMLTextAreaElement;
|
|
352
|
+
}
|
|
353
|
+
function isHtmLTextElement(val) {
|
|
354
|
+
return val instanceof Text;
|
|
355
|
+
}
|
|
356
|
+
function shallowCompare(a, b) {
|
|
357
|
+
if (a === b) return true;
|
|
358
|
+
if (!a || !b) return false;
|
|
359
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
360
|
+
for (const key in a) {
|
|
361
|
+
if (a[key] !== b[key]) return false;
|
|
362
|
+
}
|
|
363
|
+
for (const key in b) {
|
|
364
|
+
if (!(key in a)) return false;
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
function transferKey(oldNode, newNode) {
|
|
369
|
+
if (isComponent(oldNode) || isComponent(newNode)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const oldKey = getNodeKey(oldNode);
|
|
373
|
+
if (oldKey && !getNodeKey(newNode)) {
|
|
374
|
+
setNodeKey(newNode, oldKey);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function patch(parent, oldNode, newNode) {
|
|
378
|
+
if (newNode === oldNode) {
|
|
379
|
+
return oldNode;
|
|
380
|
+
}
|
|
381
|
+
const oldIsElement = shared.isHTMLElement(oldNode);
|
|
382
|
+
const newIsElement = shared.isHTMLElement(newNode);
|
|
383
|
+
if (newIsElement && oldIsElement) {
|
|
384
|
+
if (newNode.isEqualNode(oldNode)) {
|
|
385
|
+
return oldNode;
|
|
386
|
+
}
|
|
387
|
+
if (oldNode.tagName === newNode.tagName) {
|
|
388
|
+
const oldAttrs = oldNode.attributes;
|
|
389
|
+
const newAttrs = newNode.attributes;
|
|
390
|
+
for (let i = oldAttrs.length - 1; i >= 0; i--) {
|
|
391
|
+
const attrName = oldAttrs[i].name;
|
|
392
|
+
if (!newNode.hasAttribute(attrName)) {
|
|
393
|
+
oldNode.removeAttribute(attrName);
|
|
394
|
+
}
|
|
146
395
|
}
|
|
396
|
+
for (let i = 0, len = newAttrs.length; i < len; i++) {
|
|
397
|
+
const attr = newAttrs[i];
|
|
398
|
+
if (oldNode.getAttribute(attr.name) !== attr.value) {
|
|
399
|
+
oldNode.setAttribute(attr.name, attr.value);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
transferKey(oldNode, newNode);
|
|
403
|
+
return oldNode;
|
|
147
404
|
}
|
|
148
|
-
return this.renderTemplate();
|
|
149
405
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
return this.templates.join("");
|
|
406
|
+
if (isHtmLTextElement(oldNode) && isHtmLTextElement(newNode)) {
|
|
407
|
+
if (oldNode.textContent !== newNode.textContent) {
|
|
408
|
+
oldNode.textContent = newNode.textContent;
|
|
409
|
+
}
|
|
410
|
+
transferKey(oldNode, newNode);
|
|
411
|
+
return oldNode;
|
|
412
|
+
}
|
|
413
|
+
const oldIsComponent = isComponent(oldNode);
|
|
414
|
+
const newIsComponent = isComponent(newNode);
|
|
415
|
+
if (oldIsComponent && newIsComponent) {
|
|
416
|
+
if (oldNode.component === newNode.component) {
|
|
417
|
+
return newNode.update(oldNode);
|
|
418
|
+
}
|
|
164
419
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
});
|
|
420
|
+
replaceNode(parent, newNode, oldNode);
|
|
421
|
+
return newNode;
|
|
422
|
+
}
|
|
423
|
+
function patchChildren(parent, oldChildren, newChildren, anchor) {
|
|
424
|
+
const oldLength = oldChildren.length;
|
|
425
|
+
const newLength = newChildren.length;
|
|
426
|
+
if (oldLength === 0 && newLength === 0) {
|
|
427
|
+
return [];
|
|
175
428
|
}
|
|
176
|
-
|
|
177
|
-
|
|
429
|
+
if (oldLength === 0) {
|
|
430
|
+
const fragment = document.createDocumentFragment();
|
|
431
|
+
for (let i = 0; i < newLength; i++) {
|
|
432
|
+
insertNode(fragment, newChildren[i]);
|
|
433
|
+
}
|
|
434
|
+
insertNode(parent, fragment, anchor);
|
|
435
|
+
return newChildren;
|
|
178
436
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
437
|
+
if (newLength === 0) {
|
|
438
|
+
for (let i = 0; i < oldLength; i++) {
|
|
439
|
+
removeNode(oldChildren[i]);
|
|
440
|
+
}
|
|
441
|
+
return [];
|
|
185
442
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const childResult = child.mount();
|
|
193
|
-
return shared.isFunction(childResult) ? childResult(this.props) : extractSignal(childResult);
|
|
443
|
+
if (oldLength === 1 && newLength === 1) {
|
|
444
|
+
const oldNode = oldChildren[0];
|
|
445
|
+
const newNode = newChildren[0];
|
|
446
|
+
if (isSameNode(oldNode, newNode)) {
|
|
447
|
+
patch(parent, oldNode, newNode);
|
|
448
|
+
newChildren[0] = oldNode;
|
|
194
449
|
} else {
|
|
195
|
-
|
|
450
|
+
replaceNode(parent, newNode, oldNode);
|
|
196
451
|
}
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
child.unmount();
|
|
223
|
-
} else {
|
|
224
|
-
const parent = child.parentNode;
|
|
225
|
-
if (parent) {
|
|
226
|
-
child.remove();
|
|
452
|
+
return newChildren;
|
|
453
|
+
}
|
|
454
|
+
if (oldLength === 2 && newLength === 2) {
|
|
455
|
+
const o0 = oldChildren[0];
|
|
456
|
+
const o1 = oldChildren[1];
|
|
457
|
+
const n0 = newChildren[0];
|
|
458
|
+
const n1 = newChildren[1];
|
|
459
|
+
if (isSameNode(o0, n0) && isSameNode(o1, n1)) {
|
|
460
|
+
patch(parent, o0, n0);
|
|
461
|
+
patch(parent, o1, n1);
|
|
462
|
+
newChildren[0] = o0;
|
|
463
|
+
newChildren[1] = o1;
|
|
464
|
+
return newChildren;
|
|
465
|
+
}
|
|
466
|
+
if (isSameNode(o0, n1) && isSameNode(o1, n0)) {
|
|
467
|
+
patch(parent, o0, n1);
|
|
468
|
+
patch(parent, o1, n0);
|
|
469
|
+
const dom1 = getFirstDOMNode(o1);
|
|
470
|
+
const dom0 = getFirstDOMNode(o0);
|
|
471
|
+
if (dom1 && dom0 && dom1.parentNode === parent) {
|
|
472
|
+
parent.insertBefore(dom1, dom0);
|
|
473
|
+
}
|
|
474
|
+
newChildren[0] = o1;
|
|
475
|
+
newChildren[1] = o0;
|
|
476
|
+
return newChildren;
|
|
227
477
|
}
|
|
228
478
|
}
|
|
479
|
+
return patchKeyedChildren(parent, oldChildren, newChildren, anchor);
|
|
229
480
|
}
|
|
230
|
-
function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
481
|
+
function patchKeyedChildren(parent, oldChildren, newChildren, anchor) {
|
|
482
|
+
let oldStartIdx = 0;
|
|
483
|
+
let newStartIdx = 0;
|
|
484
|
+
let oldEndIdx = oldChildren.length - 1;
|
|
485
|
+
let newEndIdx = newChildren.length - 1;
|
|
486
|
+
let oldStartNode = oldChildren[0];
|
|
487
|
+
let oldEndNode = oldChildren[oldEndIdx];
|
|
488
|
+
let newStartNode = newChildren[0];
|
|
489
|
+
let newEndNode = newChildren[newEndIdx];
|
|
490
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
491
|
+
if (!oldStartNode) {
|
|
492
|
+
oldStartNode = oldChildren[++oldStartIdx];
|
|
493
|
+
} else if (!oldEndNode) {
|
|
494
|
+
oldEndNode = oldChildren[--oldEndIdx];
|
|
495
|
+
} else if (isSameNode(oldStartNode, newStartNode)) {
|
|
496
|
+
patch(parent, oldStartNode, newStartNode);
|
|
497
|
+
newChildren[newStartIdx] = oldStartNode;
|
|
498
|
+
oldStartNode = oldChildren[++oldStartIdx];
|
|
499
|
+
newStartNode = newChildren[++newStartIdx];
|
|
500
|
+
} else {
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
505
|
+
if (!oldStartNode) {
|
|
506
|
+
oldStartNode = oldChildren[++oldStartIdx];
|
|
507
|
+
} else if (!oldEndNode) {
|
|
508
|
+
oldEndNode = oldChildren[--oldEndIdx];
|
|
509
|
+
} else if (isSameNode(oldEndNode, newEndNode)) {
|
|
510
|
+
patch(parent, oldEndNode, newEndNode);
|
|
511
|
+
newChildren[newEndIdx] = oldEndNode;
|
|
512
|
+
oldEndNode = oldChildren[--oldEndIdx];
|
|
513
|
+
newEndNode = newChildren[--newEndIdx];
|
|
514
|
+
} else {
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (oldStartIdx > oldEndIdx) {
|
|
519
|
+
if (newStartIdx <= newEndIdx) {
|
|
520
|
+
const anchorNode = newEndIdx + 1 < newChildren.length ? getFirstDOMNode(newChildren[newEndIdx + 1]) : anchor;
|
|
521
|
+
for (let i = newStartIdx; i <= newEndIdx; i++) {
|
|
522
|
+
insertNode(parent, newChildren[i], anchorNode);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
} else if (newStartIdx > newEndIdx) {
|
|
526
|
+
for (let i = oldStartIdx; i <= oldEndIdx; i++) {
|
|
527
|
+
const node = oldChildren[i];
|
|
528
|
+
if (node) {
|
|
529
|
+
removeNode(node);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
239
532
|
} else {
|
|
240
|
-
|
|
533
|
+
patchUnknownSequence(
|
|
534
|
+
parent,
|
|
535
|
+
oldChildren,
|
|
536
|
+
newChildren,
|
|
537
|
+
oldStartIdx,
|
|
538
|
+
oldEndIdx,
|
|
539
|
+
newStartIdx,
|
|
540
|
+
newEndIdx,
|
|
541
|
+
anchor
|
|
542
|
+
);
|
|
241
543
|
}
|
|
544
|
+
return newChildren;
|
|
242
545
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
546
|
+
function patchUnknownSequence(parent, oldChildren, newChildren, oldStartIdx, oldEndIdx, newStartIdx, newEndIdx, anchor) {
|
|
547
|
+
const newLength = newEndIdx - newStartIdx + 1;
|
|
548
|
+
const newChildrenLen = newChildren.length;
|
|
549
|
+
let keyToNewIndexMap;
|
|
550
|
+
for (let i = newStartIdx; i <= newEndIdx; i++) {
|
|
551
|
+
const key = getNodeKey(newChildren[i]);
|
|
552
|
+
if (key !== void 0) {
|
|
553
|
+
if (!keyToNewIndexMap) {
|
|
554
|
+
keyToNewIndexMap = /* @__PURE__ */ Object.create(null);
|
|
555
|
+
}
|
|
556
|
+
keyToNewIndexMap[key] = i;
|
|
557
|
+
}
|
|
250
558
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
559
|
+
const newIndexToOldIndexMap = new Int32Array(newLength);
|
|
560
|
+
let moved = false;
|
|
561
|
+
let maxNewIndexSoFar = 0;
|
|
562
|
+
let patched = 0;
|
|
563
|
+
for (let i = oldStartIdx; i <= oldEndIdx; i++) {
|
|
564
|
+
const oldNode = oldChildren[i];
|
|
565
|
+
if (!oldNode) continue;
|
|
566
|
+
if (patched >= newLength) {
|
|
567
|
+
removeNode(oldNode);
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
let newIndex;
|
|
571
|
+
const oldKey = getNodeKey(oldNode);
|
|
572
|
+
if (oldKey !== void 0 && keyToNewIndexMap && oldKey in keyToNewIndexMap) {
|
|
573
|
+
newIndex = keyToNewIndexMap[oldKey];
|
|
574
|
+
} else {
|
|
575
|
+
for (let j2 = newStartIdx; j2 <= newEndIdx; j2++) {
|
|
576
|
+
if (newIndexToOldIndexMap[j2 - newStartIdx] === 0 && oldKey === void 0 && getNodeKey(newChildren[j2]) === void 0 && isSameNode(oldNode, newChildren[j2])) {
|
|
577
|
+
newIndex = j2;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (newIndex === void 0) {
|
|
583
|
+
removeNode(oldNode);
|
|
584
|
+
} else {
|
|
585
|
+
newIndexToOldIndexMap[newIndex - newStartIdx] = i + 1;
|
|
586
|
+
if (newIndex >= maxNewIndexSoFar) {
|
|
587
|
+
maxNewIndexSoFar = newIndex;
|
|
588
|
+
} else {
|
|
589
|
+
moved = true;
|
|
590
|
+
}
|
|
591
|
+
patch(parent, oldNode, newChildren[newIndex]);
|
|
592
|
+
newChildren[newIndex] = oldNode;
|
|
593
|
+
patched++;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
|
|
597
|
+
let j = increasingNewIndexSequence.length - 1;
|
|
598
|
+
for (let i = newLength - 1; i >= 0; i--) {
|
|
599
|
+
const nextIndex = newStartIdx + i;
|
|
600
|
+
const nextNode = newChildren[nextIndex];
|
|
601
|
+
const nextAnchor = nextIndex + 1 < newChildrenLen ? getFirstDOMNode(newChildren[nextIndex + 1]) : anchor;
|
|
602
|
+
if (newIndexToOldIndexMap[i] === 0) {
|
|
603
|
+
insertNode(parent, nextNode, nextAnchor);
|
|
604
|
+
} else if (moved) {
|
|
605
|
+
if (j < 0 || i !== increasingNewIndexSequence[j]) {
|
|
606
|
+
const domNode = getFirstDOMNode(nextNode);
|
|
607
|
+
if (domNode && domNode.parentNode === parent) {
|
|
608
|
+
insertNode(parent, domNode, nextAnchor);
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
j--;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
260
614
|
}
|
|
261
615
|
}
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
616
|
+
function getSequence(arr) {
|
|
617
|
+
const len = arr.length;
|
|
618
|
+
if (len === 0) return [];
|
|
619
|
+
if (len === 1) return arr[0] !== 0 ? [0] : [];
|
|
620
|
+
const result = [];
|
|
621
|
+
const p = new Int32Array(len);
|
|
622
|
+
let i;
|
|
623
|
+
let j;
|
|
624
|
+
let u;
|
|
625
|
+
let v;
|
|
626
|
+
let c;
|
|
627
|
+
for (i = 0; i < len; i++) {
|
|
628
|
+
const arrI = arr[i];
|
|
629
|
+
if (arrI !== 0) {
|
|
630
|
+
j = result[result.length - 1];
|
|
631
|
+
if (result.length === 0 || arr[j] < arrI) {
|
|
632
|
+
p[i] = j;
|
|
633
|
+
result.push(i);
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
u = 0;
|
|
637
|
+
v = result.length - 1;
|
|
638
|
+
while (u < v) {
|
|
639
|
+
c = u + v >> 1;
|
|
640
|
+
if (arr[result[c]] < arrI) {
|
|
641
|
+
u = c + 1;
|
|
642
|
+
} else {
|
|
643
|
+
v = c;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (arrI < arr[result[u]]) {
|
|
647
|
+
if (u > 0) {
|
|
648
|
+
p[i] = result[u - 1];
|
|
649
|
+
}
|
|
650
|
+
result[u] = i;
|
|
651
|
+
}
|
|
272
652
|
}
|
|
273
653
|
}
|
|
654
|
+
u = result.length;
|
|
655
|
+
v = result[u - 1];
|
|
656
|
+
while (u-- > 0) {
|
|
657
|
+
result[u] = v;
|
|
658
|
+
v = p[v];
|
|
659
|
+
}
|
|
660
|
+
return result;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/binding.ts
|
|
664
|
+
function addEventListener(element, event, handler, options) {
|
|
665
|
+
element.addEventListener(event, handler, options);
|
|
666
|
+
const context = getActiveContext();
|
|
667
|
+
if (context) {
|
|
668
|
+
context.cleanup.add(() => {
|
|
669
|
+
element.removeEventListener(event, handler, options);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
274
672
|
}
|
|
275
|
-
function
|
|
276
|
-
if (node
|
|
673
|
+
function bindElement(node, key, defaultValue, setter) {
|
|
674
|
+
if (isHtmlInputElement(node)) {
|
|
277
675
|
switch (node.type) {
|
|
278
676
|
case "checkbox":
|
|
279
|
-
|
|
677
|
+
addEventListener(node, "change", () => {
|
|
280
678
|
setter(Boolean(node.checked));
|
|
281
679
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
680
|
+
break;
|
|
681
|
+
case "radio":
|
|
682
|
+
addEventListener(node, "change", () => {
|
|
683
|
+
setter(node.checked ? node.value : "");
|
|
285
684
|
});
|
|
685
|
+
break;
|
|
286
686
|
case "file":
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
setter(node.files);
|
|
290
|
-
}
|
|
687
|
+
addEventListener(node, "change", () => {
|
|
688
|
+
setter(node.files);
|
|
291
689
|
});
|
|
690
|
+
break;
|
|
292
691
|
case "number":
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
setter(
|
|
692
|
+
case "range":
|
|
693
|
+
addEventListener(node, "input", () => {
|
|
694
|
+
setter(node.value || "");
|
|
296
695
|
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
696
|
+
break;
|
|
697
|
+
case "date":
|
|
698
|
+
case "datetime-local":
|
|
699
|
+
case "month":
|
|
700
|
+
case "time":
|
|
701
|
+
case "week":
|
|
702
|
+
addEventListener(node, "change", () => {
|
|
703
|
+
setter(node.value || "");
|
|
300
704
|
});
|
|
301
|
-
|
|
302
|
-
|
|
705
|
+
break;
|
|
706
|
+
default:
|
|
707
|
+
addEventListener(node, "input", () => {
|
|
303
708
|
setter(node.value);
|
|
304
709
|
});
|
|
710
|
+
break;
|
|
305
711
|
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
712
|
+
} else if (isHtmlSelectElement(node)) {
|
|
713
|
+
addEventListener(node, "change", () => {
|
|
714
|
+
if (node.multiple) {
|
|
715
|
+
const values = Array.from(node.options).filter((option) => option.selected).map((option) => option.value);
|
|
716
|
+
setter(values);
|
|
717
|
+
} else {
|
|
718
|
+
setter(node.value);
|
|
719
|
+
}
|
|
310
720
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return addEventListener(node, "input", () => {
|
|
721
|
+
} else if (isHtmlTextAreaElement(node)) {
|
|
722
|
+
addEventListener(node, "input", () => {
|
|
314
723
|
setter(node.value);
|
|
315
724
|
});
|
|
316
725
|
}
|
|
317
726
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
727
|
+
function insert(parent, nodeFactory, before, options) {
|
|
728
|
+
if (!parent) return;
|
|
729
|
+
const context = getActiveContext();
|
|
730
|
+
if (!context) return;
|
|
731
|
+
let renderedNodes = [];
|
|
732
|
+
const cleanup = signals.effect(() => {
|
|
733
|
+
const rawNodes = shared.isFunction(nodeFactory) ? nodeFactory() : nodeFactory;
|
|
734
|
+
const nodes = shared.coerceArray(rawNodes).map(normalizeNode);
|
|
735
|
+
renderedNodes = patchChildren(parent, renderedNodes, nodes, before);
|
|
736
|
+
});
|
|
737
|
+
context.cleanup.add(() => {
|
|
738
|
+
cleanup();
|
|
739
|
+
if (!(options == null ? void 0 : options.preserveOnCleanup)) {
|
|
740
|
+
renderedNodes.forEach((node) => removeNode(node));
|
|
741
|
+
}
|
|
742
|
+
renderedNodes.length = 0;
|
|
743
|
+
});
|
|
324
744
|
}
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
745
|
+
function mapNodes(template2, indexes) {
|
|
746
|
+
const len = indexes.length;
|
|
747
|
+
const tree = new Array(len);
|
|
748
|
+
const indexSet = new Set(indexes);
|
|
749
|
+
let index = 1;
|
|
750
|
+
let found = 0;
|
|
751
|
+
const walk = (node) => {
|
|
752
|
+
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
753
|
+
if (indexSet.has(index)) {
|
|
754
|
+
tree[found++] = node;
|
|
755
|
+
if (found === len) return true;
|
|
756
|
+
}
|
|
757
|
+
index++;
|
|
758
|
+
}
|
|
759
|
+
let child = node.firstChild;
|
|
760
|
+
while (child) {
|
|
761
|
+
if (walk(child)) return true;
|
|
762
|
+
child = child.nextSibling;
|
|
763
|
+
}
|
|
764
|
+
return false;
|
|
765
|
+
};
|
|
766
|
+
walk(template2);
|
|
767
|
+
return tree;
|
|
331
768
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
769
|
+
|
|
770
|
+
// src/component.ts
|
|
771
|
+
var _a;
|
|
772
|
+
_a = "normal" /* NORMAL */;
|
|
773
|
+
var Component = class {
|
|
774
|
+
constructor(component, props) {
|
|
775
|
+
this.component = component;
|
|
336
776
|
this.props = props;
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
|
|
340
|
-
this.
|
|
341
|
-
|
|
342
|
-
this.
|
|
343
|
-
|
|
344
|
-
this.
|
|
345
|
-
|
|
777
|
+
// component rendered node
|
|
778
|
+
this.renderedNode = null;
|
|
779
|
+
// component context
|
|
780
|
+
this.componentContext = null;
|
|
781
|
+
// component parent node
|
|
782
|
+
this.parentNode = null;
|
|
783
|
+
// component before node
|
|
784
|
+
this.beforeNode = null;
|
|
785
|
+
// component props
|
|
786
|
+
this.reactiveProps = {};
|
|
787
|
+
this._propSnapshots = {};
|
|
788
|
+
// component state
|
|
789
|
+
this.state = 0 /* INITIAL */;
|
|
790
|
+
// component context
|
|
791
|
+
this.context = null;
|
|
792
|
+
// component parent context
|
|
793
|
+
this.parentContext = null;
|
|
794
|
+
// component type
|
|
795
|
+
// @ts-ignore
|
|
796
|
+
this[_a] = true;
|
|
797
|
+
this.key = (props == null ? void 0 : props.key) ? normalizeKey(props.key) : getComponentKey(component);
|
|
798
|
+
this.reactiveProps = signals.shallowReactive(__spreadValues({}, this.props || {}));
|
|
799
|
+
this.parentContext = getActiveContext();
|
|
800
|
+
if (this.props) {
|
|
801
|
+
for (const key in this.props) {
|
|
802
|
+
const val = this.props[key];
|
|
803
|
+
if (shared.isObject(val) && val !== null) {
|
|
804
|
+
this._propSnapshots[key] = Array.isArray(val) ? [...val] : __spreadValues({}, val);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
get isConnected() {
|
|
810
|
+
return this.state === 2 /* MOUNTED */;
|
|
346
811
|
}
|
|
347
812
|
get firstChild() {
|
|
348
|
-
var
|
|
349
|
-
return (
|
|
813
|
+
var _a2;
|
|
814
|
+
return (_a2 = this.renderedNode) != null ? _a2 : null;
|
|
815
|
+
}
|
|
816
|
+
mount(parentNode, beforeNode) {
|
|
817
|
+
this.parentNode = parentNode;
|
|
818
|
+
this.beforeNode = beforeNode || null;
|
|
819
|
+
this.state = 1 /* MOUNTING */;
|
|
820
|
+
if (this.renderedNode) {
|
|
821
|
+
insertNode(parentNode, this.renderedNode, beforeNode);
|
|
822
|
+
return this.renderedNode;
|
|
823
|
+
}
|
|
824
|
+
this.componentContext = createContext(this.parentContext);
|
|
825
|
+
pushContextStack(this.componentContext);
|
|
826
|
+
let result = this.component(this.reactiveProps);
|
|
827
|
+
if (shared.isFunction(result)) {
|
|
828
|
+
result = result(this.reactiveProps);
|
|
829
|
+
}
|
|
830
|
+
if (signals.isSignal(result) || signals.isComputed(result)) {
|
|
831
|
+
result = result.value;
|
|
832
|
+
}
|
|
833
|
+
this.renderedNode = result;
|
|
834
|
+
insertNode(parentNode, this.renderedNode, beforeNode);
|
|
835
|
+
this.applyProps(this.props || {});
|
|
836
|
+
this.state = 2 /* MOUNTED */;
|
|
837
|
+
if (this.componentContext) {
|
|
838
|
+
this.componentContext.isMount = true;
|
|
839
|
+
}
|
|
840
|
+
triggerLifecycleHook(LIFECYCLE.mount);
|
|
841
|
+
return this.renderedNode;
|
|
350
842
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
mount(parent, before) {
|
|
356
|
-
var _a, _b, _c, _d;
|
|
357
|
-
this.parent = parent;
|
|
358
|
-
if (!shared.isFunction(this.template)) {
|
|
359
|
-
throw new Error("Template must be a function");
|
|
360
|
-
}
|
|
361
|
-
if (this.isConnected) {
|
|
362
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
363
|
-
}
|
|
364
|
-
this.initRef();
|
|
365
|
-
this.rootNode = this.template(signal.useReactive(this.proxyProps, [CHILDREN_PROP]));
|
|
366
|
-
this.nodes = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
367
|
-
this.callMountHooks();
|
|
368
|
-
this.patchProps(this.props);
|
|
369
|
-
this.removeRef();
|
|
370
|
-
return this.nodes;
|
|
371
|
-
}
|
|
372
|
-
unmount() {
|
|
373
|
-
var _a;
|
|
374
|
-
this.callLifecycleHooks("destroy");
|
|
375
|
-
this.cleanup();
|
|
376
|
-
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
377
|
-
this.resetState();
|
|
378
|
-
if (this.key) {
|
|
379
|
-
componentCache.delete(this.key);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
resetState() {
|
|
383
|
-
this.rootNode = null;
|
|
384
|
-
this.proxyProps = {};
|
|
385
|
-
this.nodes = [];
|
|
386
|
-
this.parent = null;
|
|
387
|
-
}
|
|
388
|
-
callLifecycleHooks(type) {
|
|
389
|
-
this.hooks[type].forEach((handler) => handler());
|
|
390
|
-
}
|
|
391
|
-
callMountHooks() {
|
|
392
|
-
this.hooks.mounted.forEach((handler) => handler());
|
|
393
|
-
}
|
|
394
|
-
callDestroyHooks() {
|
|
395
|
-
this.hooks.destroy.forEach((handler) => handler());
|
|
396
|
-
}
|
|
397
|
-
clearEmitter() {
|
|
398
|
-
for (const cleanup of this.emitter) {
|
|
399
|
-
cleanup();
|
|
400
|
-
}
|
|
401
|
-
this.emitter.clear();
|
|
402
|
-
}
|
|
403
|
-
inheritNode(node) {
|
|
404
|
-
Object.assign(this.proxyProps, node.proxyProps);
|
|
405
|
-
this.rootNode = node.rootNode;
|
|
406
|
-
this.trackMap = node.trackMap;
|
|
407
|
-
this.hooks = node.hooks;
|
|
408
|
-
if (shared.hasChanged(node.props, this.props)) {
|
|
409
|
-
const props = this.props;
|
|
410
|
-
this.props = node.props;
|
|
411
|
-
this.patchProps(props);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
getNodeTrack(trackKey) {
|
|
415
|
-
let track = this.trackMap.get(trackKey);
|
|
416
|
-
if (!track) {
|
|
417
|
-
track = { cleanup: () => {
|
|
418
|
-
} };
|
|
419
|
-
this.trackMap.set(trackKey, track);
|
|
420
|
-
}
|
|
421
|
-
track.cleanup();
|
|
422
|
-
return track;
|
|
423
|
-
}
|
|
424
|
-
patchProps(props) {
|
|
425
|
-
var _a;
|
|
426
|
-
if (!props) {
|
|
427
|
-
return;
|
|
843
|
+
update(prevNode) {
|
|
844
|
+
if (this.key !== prevNode.key) {
|
|
845
|
+
this.mount(prevNode.parentNode, prevNode.beforeNode);
|
|
846
|
+
return this;
|
|
428
847
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
848
|
+
this.parentNode = prevNode.parentNode;
|
|
849
|
+
this.beforeNode = prevNode.beforeNode;
|
|
850
|
+
this.componentContext = prevNode.componentContext;
|
|
851
|
+
this.renderedNode = prevNode.renderedNode;
|
|
852
|
+
this.state = prevNode.state;
|
|
853
|
+
this.reactiveProps = prevNode.reactiveProps;
|
|
854
|
+
this._propSnapshots = prevNode._propSnapshots;
|
|
855
|
+
if (this.props) {
|
|
856
|
+
for (const key in this.props) {
|
|
857
|
+
if (key === "key") continue;
|
|
858
|
+
const newValue = this.props[key];
|
|
859
|
+
const oldValue = this.reactiveProps[key];
|
|
860
|
+
if (shared.isObject(newValue) && newValue !== null) {
|
|
861
|
+
const snapshot = this._propSnapshots[key];
|
|
862
|
+
if (!snapshot || !shallowCompare(newValue, snapshot)) {
|
|
863
|
+
const newSnapshot = Array.isArray(newValue) ? newValue.slice() : Object.assign({}, newValue);
|
|
864
|
+
this.reactiveProps[key] = newSnapshot;
|
|
865
|
+
this._propSnapshots[key] = newSnapshot;
|
|
866
|
+
}
|
|
867
|
+
} else {
|
|
868
|
+
if (shared.hasChanged(newValue, oldValue)) {
|
|
869
|
+
this.reactiveProps[key] = newValue;
|
|
870
|
+
if (this._propSnapshots[key]) {
|
|
871
|
+
delete this._propSnapshots[key];
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
438
875
|
}
|
|
439
876
|
}
|
|
440
|
-
this.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
patchUpdateHandler(key, prop) {
|
|
452
|
-
this.proxyProps[key] = extractSignal(prop);
|
|
877
|
+
if (!this.isConnected && this.parentNode) {
|
|
878
|
+
this.mount(this.parentNode, this.beforeNode);
|
|
879
|
+
}
|
|
880
|
+
if (this.componentContext) {
|
|
881
|
+
pushContextStack(this.componentContext);
|
|
882
|
+
this.applyProps(this.props || {});
|
|
883
|
+
triggerLifecycleHook(LIFECYCLE.update);
|
|
884
|
+
popContextStack();
|
|
885
|
+
}
|
|
886
|
+
return this;
|
|
453
887
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
888
|
+
forceUpdate() {
|
|
889
|
+
return __async(this, null, function* () {
|
|
890
|
+
if (this.state === 5 /* DESTROYED */ || !this.parentNode || !this.componentContext) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const prevNode = this.renderedNode;
|
|
894
|
+
let newNode;
|
|
895
|
+
try {
|
|
896
|
+
if (this.componentContext) {
|
|
897
|
+
pushContextStack(this.componentContext);
|
|
898
|
+
}
|
|
899
|
+
newNode = this.component(this.reactiveProps);
|
|
900
|
+
if (shared.isFunction(newNode)) {
|
|
901
|
+
newNode = newNode(this.reactiveProps);
|
|
902
|
+
}
|
|
903
|
+
if (signals.isSignal(newNode) || signals.isComputed(newNode)) {
|
|
904
|
+
newNode = newNode.value;
|
|
905
|
+
}
|
|
906
|
+
if (prevNode && newNode && prevNode !== newNode) {
|
|
907
|
+
if (this.parentNode) {
|
|
908
|
+
replaceNode(this.parentNode, newNode, prevNode);
|
|
909
|
+
this.renderedNode = newNode;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
yield triggerLifecycleHook(LIFECYCLE.update);
|
|
913
|
+
} catch (_error) {
|
|
914
|
+
shared.error("Force update failed:", _error);
|
|
915
|
+
throw _error;
|
|
916
|
+
} finally {
|
|
917
|
+
if (this.componentContext) {
|
|
918
|
+
popContextStack();
|
|
919
|
+
}
|
|
920
|
+
}
|
|
458
921
|
});
|
|
459
922
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
this.
|
|
923
|
+
/**
|
|
924
|
+
* Destroy component
|
|
925
|
+
*/
|
|
926
|
+
destroy() {
|
|
927
|
+
if (this.state === 4 /* DESTROYING */ || this.state === 5 /* DESTROYED */) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
this.state = 4 /* DESTROYING */;
|
|
931
|
+
const context = this.componentContext;
|
|
932
|
+
if (context) {
|
|
933
|
+
pushContextStack(context);
|
|
934
|
+
triggerLifecycleHook(LIFECYCLE.destroy);
|
|
935
|
+
destroyContext(context);
|
|
936
|
+
this.componentContext = null;
|
|
937
|
+
popContextStack();
|
|
938
|
+
}
|
|
939
|
+
const rendered = this.renderedNode;
|
|
940
|
+
if (rendered) {
|
|
941
|
+
removeNode(rendered);
|
|
942
|
+
}
|
|
943
|
+
this.renderedNode = null;
|
|
944
|
+
this.parentNode = null;
|
|
945
|
+
this.beforeNode = null;
|
|
946
|
+
this.reactiveProps = {};
|
|
947
|
+
this.props = void 0;
|
|
948
|
+
this.state = 5 /* DESTROYED */;
|
|
949
|
+
}
|
|
950
|
+
applyProps(props) {
|
|
951
|
+
if (!props) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
for (const [propName, propValue] of Object.entries(props)) {
|
|
955
|
+
if (shared.startsWith(propName, EVENT_PREFIX) && this.renderedNode) {
|
|
956
|
+
const eventName = propName.slice(2).toLowerCase();
|
|
957
|
+
if (shared.isHTMLElement(this.renderedNode)) {
|
|
958
|
+
addEventListener(this.renderedNode, eventName, propValue);
|
|
959
|
+
}
|
|
960
|
+
} else if (propName === REF_KEY && signals.isSignal(propValue)) {
|
|
961
|
+
propValue.value = this.renderedNode;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
this.props = props;
|
|
468
965
|
}
|
|
469
966
|
};
|
|
967
|
+
function isComponent(node) {
|
|
968
|
+
return !!node && !!node["normal" /* NORMAL */];
|
|
969
|
+
}
|
|
970
|
+
function createComponent(componentFn, props) {
|
|
971
|
+
if (isComponent(componentFn)) {
|
|
972
|
+
return componentFn;
|
|
973
|
+
}
|
|
974
|
+
return new Component(componentFn, props);
|
|
975
|
+
}
|
|
470
976
|
|
|
471
|
-
// src/
|
|
472
|
-
function
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
977
|
+
// src/renderer.ts
|
|
978
|
+
function template(html) {
|
|
979
|
+
let node;
|
|
980
|
+
const create = () => {
|
|
981
|
+
const template2 = document.createElement("template");
|
|
982
|
+
template2.innerHTML = html;
|
|
983
|
+
const firstChild = template2.content.firstChild;
|
|
984
|
+
if (!firstChild) {
|
|
985
|
+
throw new Error("Invalid template: empty content");
|
|
986
|
+
}
|
|
987
|
+
return firstChild;
|
|
988
|
+
};
|
|
989
|
+
return () => (node || (node = create())).cloneNode(true);
|
|
990
|
+
}
|
|
991
|
+
function createApp(component, target) {
|
|
992
|
+
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
993
|
+
if (!container) {
|
|
994
|
+
shared.error(`Target element not found: ${target}`);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const existingContext = container.innerHTML;
|
|
998
|
+
if (existingContext) {
|
|
999
|
+
shared.error(`Target element is not empty, it will be delete: ${target}`);
|
|
1000
|
+
container.innerHTML = "";
|
|
1001
|
+
}
|
|
1002
|
+
const rootComponent = createComponent(component);
|
|
1003
|
+
rootComponent.mount(container);
|
|
1004
|
+
return rootComponent;
|
|
1005
|
+
}
|
|
1006
|
+
function provide(key, value) {
|
|
1007
|
+
const context = getActiveContext();
|
|
1008
|
+
if (!context) {
|
|
1009
|
+
shared.error("provide must be called within a template");
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
context.provides.set(key, value);
|
|
1013
|
+
}
|
|
1014
|
+
function inject(key, defaultValue) {
|
|
1015
|
+
const context = getActiveContext();
|
|
1016
|
+
if (!context) {
|
|
1017
|
+
shared.error("inject must be called within a template");
|
|
1018
|
+
return defaultValue;
|
|
1019
|
+
}
|
|
1020
|
+
let currentContext = context;
|
|
1021
|
+
while (currentContext) {
|
|
1022
|
+
const value = currentContext.provides.get(key);
|
|
1023
|
+
if (!shared.isNil(value)) {
|
|
1024
|
+
return value;
|
|
506
1025
|
}
|
|
507
|
-
|
|
1026
|
+
currentContext = currentContext.parent;
|
|
508
1027
|
}
|
|
509
|
-
|
|
510
|
-
|
|
1028
|
+
return defaultValue;
|
|
1029
|
+
}
|
|
1030
|
+
function eventHandler(e) {
|
|
1031
|
+
let node = e.target;
|
|
1032
|
+
const key = `${e.type}`;
|
|
1033
|
+
const oriTarget = e.target;
|
|
1034
|
+
const oriCurrentTarget = e.currentTarget;
|
|
1035
|
+
const reTarget = (value) => Object.defineProperty(e, "target", {
|
|
1036
|
+
configurable: true,
|
|
1037
|
+
value
|
|
511
1038
|
});
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1039
|
+
const handleNode = () => {
|
|
1040
|
+
const handler = node[`_$${key}`];
|
|
1041
|
+
if (handler && shared.isFunction(handler) && !node.disabled) {
|
|
1042
|
+
const data = node[`${key}Data`];
|
|
1043
|
+
data ? handler.call(node, data, e) : handler.call(node, e);
|
|
1044
|
+
if (e.cancelBubble) return false;
|
|
1045
|
+
}
|
|
1046
|
+
if (node.host && !shared.isString(node.host) && !node.host._$host && shared.isFunction(node.contains) && node.contains(e.target)) {
|
|
1047
|
+
reTarget(node.host);
|
|
1048
|
+
}
|
|
1049
|
+
return true;
|
|
1050
|
+
};
|
|
1051
|
+
const walkUpTree = () => {
|
|
1052
|
+
while (handleNode() && (node = node._$host || node.parentNode || node.host)) ;
|
|
1053
|
+
};
|
|
1054
|
+
Object.defineProperty(e, "currentTarget", {
|
|
1055
|
+
configurable: true,
|
|
1056
|
+
get() {
|
|
1057
|
+
return node || document;
|
|
515
1058
|
}
|
|
516
1059
|
});
|
|
517
|
-
|
|
1060
|
+
if (e.composedPath) {
|
|
1061
|
+
const path = e.composedPath();
|
|
1062
|
+
reTarget(path[0]);
|
|
1063
|
+
for (let i = 0; i < path.length - 2; i++) {
|
|
1064
|
+
node = path[i];
|
|
1065
|
+
if (!handleNode()) break;
|
|
1066
|
+
if (node._$host) {
|
|
1067
|
+
node = node._$host;
|
|
1068
|
+
walkUpTree();
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
if (node.parentNode === oriCurrentTarget) {
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
} else walkUpTree();
|
|
1076
|
+
reTarget(oriTarget);
|
|
518
1077
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
1078
|
+
var $EVENTS = Symbol("_$EVENTS");
|
|
1079
|
+
function delegateEvents(eventNames, document2 = window.document) {
|
|
1080
|
+
const docWithEvents = document2;
|
|
1081
|
+
const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
|
|
1082
|
+
for (const name of eventNames) {
|
|
1083
|
+
if (!eventSet.has(name)) {
|
|
1084
|
+
eventSet.add(name);
|
|
1085
|
+
document2.addEventListener(name, eventHandler);
|
|
524
1086
|
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
function patchClass(el, prev, next, isSVG = false) {
|
|
1090
|
+
if (prev === next) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
const normalizedNext = normalizeClass(next);
|
|
1094
|
+
const normalizedPrev = normalizeClass(prev);
|
|
1095
|
+
if (normalizedNext && normalizedPrev === normalizedNext) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (!normalizedNext) {
|
|
1099
|
+
el.removeAttribute("class");
|
|
1100
|
+
} else if (isSVG) {
|
|
1101
|
+
el.setAttribute("class", normalizedNext);
|
|
525
1102
|
} else {
|
|
526
|
-
|
|
527
|
-
const child = children[0];
|
|
528
|
-
const start = isJsxElement(child) ? child.firstChild : child;
|
|
529
|
-
range.setStartBefore(start);
|
|
530
|
-
if (before) {
|
|
531
|
-
range.setEndBefore(before);
|
|
532
|
-
} else {
|
|
533
|
-
range.setEndAfter(parent);
|
|
534
|
-
}
|
|
535
|
-
range.deleteContents();
|
|
1103
|
+
el.className = normalizedNext;
|
|
536
1104
|
}
|
|
537
|
-
children.forEach((node) => {
|
|
538
|
-
if (isJsxElement(node)) {
|
|
539
|
-
node.unmount();
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
1105
|
}
|
|
543
|
-
function
|
|
544
|
-
if (
|
|
545
|
-
return
|
|
1106
|
+
function normalizeClass(value) {
|
|
1107
|
+
if (value == null) {
|
|
1108
|
+
return "";
|
|
546
1109
|
}
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
|
|
1110
|
+
if (typeof value === "string") {
|
|
1111
|
+
return value.trim();
|
|
1112
|
+
}
|
|
1113
|
+
if (shared.isArray(value)) {
|
|
1114
|
+
return value.map(normalizeClass).filter(Boolean).join(" ");
|
|
550
1115
|
}
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
1116
|
+
if (shared.isObject(value)) {
|
|
1117
|
+
const result = [];
|
|
1118
|
+
for (const key in value) {
|
|
1119
|
+
if (value[key]) {
|
|
1120
|
+
result.push(key);
|
|
1121
|
+
}
|
|
554
1122
|
}
|
|
555
|
-
return
|
|
1123
|
+
return result.join(" ");
|
|
556
1124
|
}
|
|
557
|
-
|
|
558
|
-
return next;
|
|
1125
|
+
return String(value).trim();
|
|
559
1126
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
1127
|
+
var importantRE = /\s*!important$/;
|
|
1128
|
+
var prefixes = ["Webkit", "Moz", "ms"];
|
|
1129
|
+
var prefixCache = {};
|
|
1130
|
+
function patchStyle(el, prev, next) {
|
|
1131
|
+
const style = el.style;
|
|
1132
|
+
const isCssString = shared.isString(next);
|
|
1133
|
+
if (next && isCssString) {
|
|
1134
|
+
if (prev !== next) {
|
|
1135
|
+
style.cssText = next;
|
|
1136
|
+
}
|
|
1137
|
+
return;
|
|
565
1138
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
if (isJsxElement(node)) {
|
|
570
|
-
const jsxKey = node.key;
|
|
571
|
-
if (jsxKey !== void 0 && jsxKey !== null) {
|
|
572
|
-
return String(jsxKey);
|
|
1139
|
+
if (!next) {
|
|
1140
|
+
if (prev) {
|
|
1141
|
+
el.removeAttribute("style");
|
|
573
1142
|
}
|
|
1143
|
+
return;
|
|
574
1144
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
this.componentIndex = getComponentIndex(this.template);
|
|
1145
|
+
if (prev && !shared.isString(prev)) {
|
|
1146
|
+
for (const key in prev) {
|
|
1147
|
+
if (!next || next[key] == null) {
|
|
1148
|
+
setStyle(style, key, "");
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
} else if (prev && shared.isString(prev)) {
|
|
1152
|
+
const prevStyles = prev.split(";");
|
|
1153
|
+
for (const stylePart of prevStyles) {
|
|
1154
|
+
const colonIndex = stylePart.indexOf(":");
|
|
1155
|
+
if (colonIndex > 0) {
|
|
1156
|
+
const key = stylePart.slice(0, colonIndex).trim();
|
|
1157
|
+
if (next && shared.isObject(next) && next[key] == null) {
|
|
1158
|
+
setStyle(style, key, "");
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
592
1161
|
}
|
|
593
1162
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1163
|
+
if (next && !shared.isString(next)) {
|
|
1164
|
+
for (const key in next) {
|
|
1165
|
+
const value = next[key];
|
|
1166
|
+
if ((!prev || shared.isString(prev) || prev[key] !== value) && value != null) {
|
|
1167
|
+
setStyle(style, key, value);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
597
1170
|
}
|
|
598
|
-
|
|
599
|
-
|
|
1171
|
+
}
|
|
1172
|
+
function setStyle(style, name, val) {
|
|
1173
|
+
if (shared.isArray(val)) {
|
|
1174
|
+
for (const element of val) {
|
|
1175
|
+
setStyle(style, name, element);
|
|
1176
|
+
}
|
|
1177
|
+
return;
|
|
600
1178
|
}
|
|
601
|
-
|
|
1179
|
+
if (val == null || val === "") {
|
|
1180
|
+
val = "";
|
|
602
1181
|
}
|
|
603
|
-
|
|
1182
|
+
if (name.startsWith("--")) {
|
|
1183
|
+
style.setProperty(name, val);
|
|
1184
|
+
return;
|
|
604
1185
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1186
|
+
const prefixed = autoPrefix(style, name);
|
|
1187
|
+
if (typeof val === "string" && importantRE.test(val)) {
|
|
1188
|
+
style.setProperty(shared.camelCase(prefixed), val.replace(importantRE, ""), "important");
|
|
1189
|
+
} else {
|
|
1190
|
+
style[prefixed] = val;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
function autoPrefix(style, rawName) {
|
|
1194
|
+
const cached = prefixCache[rawName];
|
|
1195
|
+
if (cached) {
|
|
1196
|
+
return cached;
|
|
1197
|
+
}
|
|
1198
|
+
let name = shared.camelCase(rawName);
|
|
1199
|
+
if (name !== "filter" && name in style) {
|
|
1200
|
+
return prefixCache[rawName] = name;
|
|
1201
|
+
}
|
|
1202
|
+
name = shared.capitalize(name);
|
|
1203
|
+
for (const prefix of prefixes) {
|
|
1204
|
+
const prefixed = prefix + name;
|
|
1205
|
+
if (prefixed in style) {
|
|
1206
|
+
return prefixCache[rawName] = prefixed;
|
|
614
1207
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
1208
|
+
}
|
|
1209
|
+
return rawName;
|
|
1210
|
+
}
|
|
1211
|
+
function patchAttr(el, key, prev, next) {
|
|
1212
|
+
if (key === REF_KEY) {
|
|
1213
|
+
prev.value = el;
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
if (key === KEY_PROP) {
|
|
1217
|
+
if (next == null) {
|
|
1218
|
+
setNodeKey(el, void 0);
|
|
1219
|
+
} else {
|
|
1220
|
+
setNodeKey(el, String(next));
|
|
622
1221
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
|
|
1225
|
+
const isXlink = elementIsSVG && key.startsWith("xlink:");
|
|
1226
|
+
const isXmlns = elementIsSVG && key.startsWith("xmlns:");
|
|
1227
|
+
const isBoolean = shared.isSpecialBooleanAttr(key) || shared.isBooleanAttr(key);
|
|
1228
|
+
if (prev === next) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const lowerKey = key.toLowerCase();
|
|
1232
|
+
if (/^on[a-z]+/.test(lowerKey)) {
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
if (lowerKey === "innerhtml") {
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (next == null) {
|
|
1239
|
+
if (isXlink) {
|
|
1240
|
+
el.removeAttributeNS(XLINK_NAMESPACE, key.slice(6));
|
|
1241
|
+
} else if (isXmlns) {
|
|
1242
|
+
const localName = key.slice(6);
|
|
1243
|
+
el.removeAttributeNS(XMLNS_NAMESPACE, localName);
|
|
626
1244
|
} else {
|
|
627
|
-
|
|
1245
|
+
el.removeAttribute(key);
|
|
628
1246
|
}
|
|
629
|
-
|
|
630
|
-
this.patchProps(this.props);
|
|
631
|
-
this.mounted = true;
|
|
632
|
-
return this.nodes;
|
|
1247
|
+
return;
|
|
633
1248
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
});
|
|
638
|
-
this.trackMap.clear();
|
|
639
|
-
this.treeMap.clear();
|
|
640
|
-
this.nodes.forEach((node) => removeChild(node));
|
|
641
|
-
this.nodes = [];
|
|
642
|
-
this.mounted = false;
|
|
643
|
-
if (this.key) {
|
|
644
|
-
componentCache.delete(this.key);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
inheritNode(node) {
|
|
648
|
-
this.mounted = node.mounted;
|
|
649
|
-
this.nodes = node.nodes;
|
|
650
|
-
this.trackMap = node.trackMap;
|
|
651
|
-
this.treeMap = node.treeMap;
|
|
652
|
-
const props = this.props;
|
|
653
|
-
this.props = node.props;
|
|
654
|
-
this.patchProps(props);
|
|
655
|
-
}
|
|
656
|
-
mapSSGNodeTree(parent) {
|
|
657
|
-
this.treeMap.set(0, parent);
|
|
658
|
-
this.walkNodeTree(parent, this.handleSSGNode.bind(this));
|
|
659
|
-
}
|
|
660
|
-
// protected method to map node tree
|
|
661
|
-
mapNodeTree(parent, tree) {
|
|
662
|
-
let index = 1;
|
|
663
|
-
this.treeMap.set(0, parent);
|
|
664
|
-
const handleNode = (node) => {
|
|
665
|
-
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
666
|
-
this.treeMap.set(index++, node);
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
this.walkNodeTree(tree, handleNode);
|
|
1249
|
+
if (isXlink) {
|
|
1250
|
+
el.setAttributeNS(XLINK_NAMESPACE, key, String(next));
|
|
1251
|
+
return;
|
|
670
1252
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
1253
|
+
if (isXmlns) {
|
|
1254
|
+
el.setAttributeNS(XMLNS_NAMESPACE, key, String(next));
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
if (isBoolean) {
|
|
1258
|
+
if (shared.includeBooleanAttr(next)) {
|
|
1259
|
+
el.setAttribute(key, "");
|
|
1260
|
+
} else {
|
|
1261
|
+
el.removeAttribute(key);
|
|
674
1262
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const attrValue = shared.isSymbol(next) ? String(next) : next;
|
|
1266
|
+
const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href";
|
|
1267
|
+
if (isUrlAttr && typeof attrValue === "string") {
|
|
1268
|
+
const v = attrValue.trim().toLowerCase();
|
|
1269
|
+
if (v.startsWith("javascript:") || v.startsWith("data:")) {
|
|
1270
|
+
return;
|
|
679
1271
|
}
|
|
680
1272
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
} else if (node.nodeType !== Node.TEXT_NODE) {
|
|
690
|
-
const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
|
|
691
|
-
if (hk && +ci === this.componentIndex) {
|
|
692
|
-
this.treeMap.set(+hk, node);
|
|
1273
|
+
if (elementIsSVG) {
|
|
1274
|
+
el.setAttribute(key, String(attrValue));
|
|
1275
|
+
} else {
|
|
1276
|
+
if (key in el) {
|
|
1277
|
+
try {
|
|
1278
|
+
el[key] = attrValue;
|
|
1279
|
+
} catch (e) {
|
|
1280
|
+
el.setAttribute(key, String(attrValue));
|
|
693
1281
|
}
|
|
1282
|
+
} else {
|
|
1283
|
+
el.setAttribute(key, String(attrValue));
|
|
694
1284
|
}
|
|
695
1285
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// src/operations/event.ts
|
|
1289
|
+
function addEvent(el, event, handler, options) {
|
|
1290
|
+
if (!(options == null ? void 0 : options.delegate)) {
|
|
1291
|
+
el.addEventListener(event, handler, options);
|
|
1292
|
+
return () => el.removeEventListener(event, handler, options);
|
|
1293
|
+
}
|
|
1294
|
+
const selector = options.delegate;
|
|
1295
|
+
const wrappedHandler = (e) => {
|
|
1296
|
+
const target = e.target;
|
|
1297
|
+
if (target.matches(selector) || target.closest(selector)) {
|
|
1298
|
+
handler.call(el, e);
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
const cleanOptions = __spreadValues({}, options);
|
|
1302
|
+
cleanOptions.delegate = void 0;
|
|
1303
|
+
el.addEventListener(event, wrappedHandler, cleanOptions);
|
|
1304
|
+
return () => {
|
|
1305
|
+
el.removeEventListener(event, wrappedHandler, cleanOptions);
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// src/components/Fragment.ts
|
|
1310
|
+
function Fragment(props) {
|
|
1311
|
+
if (typeof document === "undefined") {
|
|
1312
|
+
const children2 = props.children;
|
|
1313
|
+
if (!children2) return "";
|
|
1314
|
+
const childArray = Array.isArray(children2) ? children2 : [children2];
|
|
1315
|
+
return childArray.map((child) => String(child || "")).join("");
|
|
1316
|
+
}
|
|
1317
|
+
const fragment = document.createDocumentFragment();
|
|
1318
|
+
const children = props.children;
|
|
1319
|
+
if (children) {
|
|
1320
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
1321
|
+
childArray.forEach((child) => {
|
|
1322
|
+
if (child != null) {
|
|
1323
|
+
const normalized = normalizeNode(child);
|
|
1324
|
+
if (normalized) {
|
|
1325
|
+
insertNode(fragment, normalized);
|
|
1326
|
+
}
|
|
703
1327
|
}
|
|
704
1328
|
});
|
|
705
|
-
this.props = props;
|
|
706
1329
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1330
|
+
return fragment;
|
|
1331
|
+
}
|
|
1332
|
+
Fragment["fragment" /* FRAGMENT */] = true;
|
|
1333
|
+
function isFragment(node) {
|
|
1334
|
+
return !!node && !!node["fragment" /* FRAGMENT */];
|
|
1335
|
+
}
|
|
1336
|
+
function Portal(props) {
|
|
1337
|
+
if (typeof document === "undefined") {
|
|
1338
|
+
const children = props.children;
|
|
1339
|
+
if (!children) return "";
|
|
1340
|
+
const childArray = shared.isArray(children) ? children : [children];
|
|
1341
|
+
return childArray.map((child) => String(child || "")).join("");
|
|
1342
|
+
}
|
|
1343
|
+
const placeholder = document.createComment("portal");
|
|
1344
|
+
placeholder["portal" /* PORTAL */] = true;
|
|
1345
|
+
onMount(() => {
|
|
1346
|
+
const targetElement = shared.isString(props.target) ? document.querySelector(props.target) : props.target;
|
|
1347
|
+
if (!targetElement) {
|
|
1348
|
+
{
|
|
1349
|
+
shared.warn(`[Portal] Target element not found: ${props.target}`);
|
|
720
1350
|
}
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
getBindUpdateValue(props, key, attr) {
|
|
724
|
-
const updateKey = `${UPDATE_PREFIX}${shared.capitalize(attr)}`;
|
|
725
|
-
if (updateKey && props[updateKey] && shared.isFunction(props[updateKey])) {
|
|
726
|
-
this.bindValueKeys.push(updateKey);
|
|
727
|
-
return props[updateKey];
|
|
1351
|
+
return;
|
|
728
1352
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
const before = shared.isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
740
|
-
const trackKey = `${key}:${CHILDREN_PROP}:${index}`;
|
|
741
|
-
const track = this.getNodeTrack(trackKey, true, isRoot);
|
|
742
|
-
this.patchChild(track, node, child, before);
|
|
1353
|
+
const children = props.children;
|
|
1354
|
+
if (children) {
|
|
1355
|
+
const childArray = shared.isArray(children) ? children : [children];
|
|
1356
|
+
childArray.forEach((child) => {
|
|
1357
|
+
if (child != null) {
|
|
1358
|
+
const normalized = normalizeNode(child);
|
|
1359
|
+
if (normalized) {
|
|
1360
|
+
insertNode(targetElement, normalized);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
743
1363
|
});
|
|
744
1364
|
}
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
let cleanupBind;
|
|
759
|
-
if (updateFn && shared.isHTMLElement(element)) {
|
|
760
|
-
cleanupBind = bindNode(element, (value2) => {
|
|
761
|
-
updateFn(value2);
|
|
762
|
-
});
|
|
1365
|
+
});
|
|
1366
|
+
return placeholder;
|
|
1367
|
+
}
|
|
1368
|
+
Portal["portal" /* PORTAL */] = true;
|
|
1369
|
+
function isPortal(node) {
|
|
1370
|
+
return !!node && !!node["portal" /* PORTAL */];
|
|
1371
|
+
}
|
|
1372
|
+
var SuspenseContext = Symbol("SuspenseContext");
|
|
1373
|
+
function Suspense(props) {
|
|
1374
|
+
if (shared.isUndefined(document)) {
|
|
1375
|
+
const fallback = props.fallback;
|
|
1376
|
+
if (fallback) {
|
|
1377
|
+
return String(fallback || "");
|
|
763
1378
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1379
|
+
return "";
|
|
1380
|
+
}
|
|
1381
|
+
const container = document.createElement("div");
|
|
1382
|
+
container.style.display = "contents";
|
|
1383
|
+
let isMounted = true;
|
|
1384
|
+
let pendingCount = 0;
|
|
1385
|
+
let isShowingFallback = false;
|
|
1386
|
+
let resolvedChildren = null;
|
|
1387
|
+
const showFallback = () => {
|
|
1388
|
+
if (isShowingFallback) return;
|
|
1389
|
+
isShowingFallback = true;
|
|
1390
|
+
while (container.firstChild) {
|
|
1391
|
+
container.removeChild(container.firstChild);
|
|
1392
|
+
}
|
|
1393
|
+
if (props.fallback != null) {
|
|
1394
|
+
const normalized = normalizeNode(props.fallback);
|
|
1395
|
+
if (normalized) {
|
|
1396
|
+
insertNode(container, normalized);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
const showChildren = () => {
|
|
1401
|
+
if (!isShowingFallback) return;
|
|
1402
|
+
const hasContent = resolvedChildren || props.children != null && !shared.isPromise(props.children);
|
|
1403
|
+
if (!hasContent) {
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
isShowingFallback = false;
|
|
1407
|
+
while (container.firstChild) {
|
|
1408
|
+
container.removeChild(container.firstChild);
|
|
1409
|
+
}
|
|
1410
|
+
if (resolvedChildren) {
|
|
1411
|
+
renderChildren(resolvedChildren);
|
|
1412
|
+
} else if (props.children != null && !shared.isPromise(props.children)) {
|
|
1413
|
+
renderChildren(props.children);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
const renderChildren = (children2) => {
|
|
1417
|
+
while (container.firstChild) {
|
|
1418
|
+
container.removeChild(container.firstChild);
|
|
1419
|
+
}
|
|
1420
|
+
if (children2 == null) return;
|
|
1421
|
+
const currentContext = getActiveContext();
|
|
1422
|
+
const childArray = shared.isArray(children2) ? children2 : [children2];
|
|
1423
|
+
childArray.forEach((child) => {
|
|
1424
|
+
if (child != null) {
|
|
1425
|
+
if (isComponent(child)) {
|
|
1426
|
+
child.parentContext = currentContext;
|
|
1427
|
+
}
|
|
1428
|
+
const normalized = normalizeNode(child);
|
|
1429
|
+
if (normalized) {
|
|
1430
|
+
insertNode(container, normalized);
|
|
1431
|
+
}
|
|
776
1432
|
}
|
|
777
|
-
|
|
778
|
-
|
|
1433
|
+
});
|
|
1434
|
+
if (isShowingFallback) {
|
|
1435
|
+
while (container.firstChild) {
|
|
1436
|
+
container.removeChild(container.firstChild);
|
|
1437
|
+
}
|
|
1438
|
+
if (props.fallback != null) {
|
|
1439
|
+
const normalized = normalizeNode(props.fallback);
|
|
1440
|
+
if (normalized) {
|
|
1441
|
+
insertNode(container, normalized);
|
|
1442
|
+
}
|
|
779
1443
|
}
|
|
780
|
-
this.trackMap.set(trackKey, track);
|
|
781
1444
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
track.lastNodes = patchChildren(parent, track.lastNodes, nextNodes, before);
|
|
1445
|
+
};
|
|
1446
|
+
const suspenseContext = {
|
|
1447
|
+
register: (promise) => {
|
|
1448
|
+
pendingCount++;
|
|
1449
|
+
showFallback();
|
|
1450
|
+
promise.then(() => {
|
|
1451
|
+
if (!isMounted) return;
|
|
1452
|
+
pendingCount--;
|
|
1453
|
+
if (pendingCount === 0) {
|
|
1454
|
+
showChildren();
|
|
793
1455
|
}
|
|
794
|
-
})
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
track.lastNodes.set(key, newNode);
|
|
803
|
-
insertChild(parent, newNode, before);
|
|
1456
|
+
}).catch((error10) => {
|
|
1457
|
+
{
|
|
1458
|
+
shared.warn("[Suspense] Resource failed:", error10);
|
|
1459
|
+
}
|
|
1460
|
+
if (!isMounted) return;
|
|
1461
|
+
pendingCount--;
|
|
1462
|
+
if (pendingCount === 0) {
|
|
1463
|
+
showChildren();
|
|
804
1464
|
}
|
|
805
1465
|
});
|
|
1466
|
+
},
|
|
1467
|
+
increment: () => {
|
|
1468
|
+
pendingCount++;
|
|
1469
|
+
showFallback();
|
|
1470
|
+
},
|
|
1471
|
+
decrement: () => {
|
|
1472
|
+
pendingCount--;
|
|
1473
|
+
if (pendingCount === 0) {
|
|
1474
|
+
showChildren();
|
|
1475
|
+
}
|
|
806
1476
|
}
|
|
1477
|
+
};
|
|
1478
|
+
provide(SuspenseContext, suspenseContext);
|
|
1479
|
+
const children = props.children;
|
|
1480
|
+
if (shared.isPromise(children)) {
|
|
1481
|
+
children.then((resolved) => {
|
|
1482
|
+
resolvedChildren = resolved;
|
|
1483
|
+
}).catch(() => {
|
|
1484
|
+
});
|
|
1485
|
+
suspenseContext.register(children);
|
|
1486
|
+
} else if (children != null) {
|
|
1487
|
+
renderChildren(children);
|
|
1488
|
+
} else {
|
|
1489
|
+
showFallback();
|
|
807
1490
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
(
|
|
812
|
-
|
|
813
|
-
|
|
1491
|
+
onDestroy(() => {
|
|
1492
|
+
isMounted = false;
|
|
1493
|
+
while (container.firstChild) {
|
|
1494
|
+
container.removeChild(container.firstChild);
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
return container;
|
|
1498
|
+
}
|
|
1499
|
+
Suspense["suspense" /* SUSPENSE */] = true;
|
|
1500
|
+
function isSuspense(node) {
|
|
1501
|
+
return !!node && !!node["suspense" /* SUSPENSE */];
|
|
1502
|
+
}
|
|
1503
|
+
function createResource(fetcher, options) {
|
|
1504
|
+
const value = signals.signal(options == null ? void 0 : options.initialValue);
|
|
1505
|
+
const loading = signals.signal(true);
|
|
1506
|
+
const error10 = signals.signal(null);
|
|
1507
|
+
const state = signals.signal("pending");
|
|
1508
|
+
let fetchId = 0;
|
|
1509
|
+
let currentPromise = null;
|
|
1510
|
+
const fetch = () => __async(null, null, function* () {
|
|
1511
|
+
const currentFetchId = ++fetchId;
|
|
1512
|
+
loading.value = true;
|
|
1513
|
+
state.value = "pending";
|
|
1514
|
+
error10.value = null;
|
|
1515
|
+
const promise = fetcher();
|
|
1516
|
+
currentPromise = promise.then(() => {
|
|
1517
|
+
});
|
|
1518
|
+
try {
|
|
1519
|
+
const result = yield promise;
|
|
1520
|
+
if (currentFetchId === fetchId) {
|
|
1521
|
+
value.value = result;
|
|
1522
|
+
state.value = "ready";
|
|
1523
|
+
loading.value = false;
|
|
814
1524
|
}
|
|
815
|
-
)
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
1525
|
+
} catch (error_) {
|
|
1526
|
+
if (currentFetchId === fetchId) {
|
|
1527
|
+
error10.value = error_ instanceof Error ? error_ : new Error(String(error_));
|
|
1528
|
+
state.value = "errored";
|
|
1529
|
+
loading.value = false;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
fetch();
|
|
1534
|
+
const resource = (() => {
|
|
1535
|
+
if (loading.value && currentPromise) {
|
|
1536
|
+
const suspenseContext = inject(SuspenseContext, null);
|
|
1537
|
+
if (suspenseContext) {
|
|
1538
|
+
suspenseContext.register(currentPromise);
|
|
826
1539
|
}
|
|
827
|
-
result.set(key, node);
|
|
828
|
-
});
|
|
829
|
-
return result;
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
// src/jsxRenderer.ts
|
|
834
|
-
var componentCache = /* @__PURE__ */ new Map();
|
|
835
|
-
function createNodeCache(NodeConstructor, template, props = {}, key) {
|
|
836
|
-
if (key) {
|
|
837
|
-
const cached = componentCache.get(key);
|
|
838
|
-
if (cached) {
|
|
839
|
-
return cached;
|
|
840
1540
|
}
|
|
1541
|
+
return value.value;
|
|
1542
|
+
});
|
|
1543
|
+
resource.loading = loading;
|
|
1544
|
+
resource.error = error10;
|
|
1545
|
+
resource.state = state;
|
|
1546
|
+
const actions = {
|
|
1547
|
+
mutate: (newValue) => {
|
|
1548
|
+
value.value = newValue;
|
|
1549
|
+
state.value = "ready";
|
|
1550
|
+
loading.value = false;
|
|
1551
|
+
error10.value = null;
|
|
1552
|
+
},
|
|
1553
|
+
refetch: () => __async(null, null, function* () {
|
|
1554
|
+
yield fetch();
|
|
1555
|
+
})
|
|
1556
|
+
};
|
|
1557
|
+
return [resource, actions];
|
|
1558
|
+
}
|
|
1559
|
+
var hydrationCounter = 0;
|
|
1560
|
+
function getHydrationKey() {
|
|
1561
|
+
return `${hydrationCounter++}`;
|
|
1562
|
+
}
|
|
1563
|
+
function resetHydrationKey() {
|
|
1564
|
+
hydrationCounter = 0;
|
|
1565
|
+
}
|
|
1566
|
+
function endHydration() {
|
|
1567
|
+
}
|
|
1568
|
+
function convertToString(content, isSvg = false) {
|
|
1569
|
+
if (shared.isNil(content)) {
|
|
1570
|
+
return "";
|
|
841
1571
|
}
|
|
842
|
-
if (
|
|
843
|
-
|
|
1572
|
+
if (shared.isString(content)) {
|
|
1573
|
+
return content;
|
|
844
1574
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
componentCache.set(key, newNode);
|
|
1575
|
+
if (shared.isArray(content)) {
|
|
1576
|
+
return content.map((item) => convertToString(item, isSvg)).join("");
|
|
848
1577
|
}
|
|
849
|
-
|
|
1578
|
+
if (shared.isFunction(content)) {
|
|
1579
|
+
return convertToString(content(), isSvg);
|
|
1580
|
+
}
|
|
1581
|
+
return String(content);
|
|
1582
|
+
}
|
|
1583
|
+
function addAttributes(htmlContent, hydrationId) {
|
|
1584
|
+
const rootElementRegex = /^<([a-z]+)(\s*)([^>]*)>/i;
|
|
1585
|
+
const indexAttributeRegex = /data-idx="(\d+)"/g;
|
|
1586
|
+
const commentRegex = /<!--(.*?)-->/g;
|
|
1587
|
+
const enhancedHtml = htmlContent.replace(rootElementRegex, `<$1$2$3 data-hk="${hydrationId}">`).replaceAll(indexAttributeRegex, `data-idx="${hydrationId}-$1"`).replaceAll(commentRegex, `<!--${hydrationId}-$1-->`);
|
|
1588
|
+
return enhancedHtml;
|
|
850
1589
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1590
|
+
|
|
1591
|
+
// src/server/render.ts
|
|
1592
|
+
function renderToString(component, props) {
|
|
1593
|
+
if (!shared.isFunction(component)) {
|
|
1594
|
+
shared.error("Component must be a function");
|
|
1595
|
+
return "";
|
|
854
1596
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1597
|
+
resetHydrationKey();
|
|
1598
|
+
const result = component(props);
|
|
1599
|
+
return convertToString(result);
|
|
1600
|
+
}
|
|
1601
|
+
function render(templates, hydrationKey, ...components) {
|
|
1602
|
+
let content = "";
|
|
1603
|
+
let index = 0;
|
|
1604
|
+
for (const template2 of templates) {
|
|
1605
|
+
content += template2;
|
|
1606
|
+
if (index < components.length) {
|
|
1607
|
+
const component = components[index++];
|
|
1608
|
+
if (component) {
|
|
1609
|
+
content += convertToString(component);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
859
1612
|
}
|
|
860
|
-
|
|
861
|
-
|
|
1613
|
+
const result = addAttributes(content, hydrationKey);
|
|
1614
|
+
return result;
|
|
1615
|
+
}
|
|
1616
|
+
function createSSGComponent(component, props = {}) {
|
|
1617
|
+
if (!shared.isFunction(component)) {
|
|
1618
|
+
shared.error("create ssg component: Component is not a function");
|
|
1619
|
+
return "";
|
|
862
1620
|
}
|
|
863
|
-
|
|
1621
|
+
const result = component(props);
|
|
1622
|
+
return convertToString(result);
|
|
864
1623
|
}
|
|
865
|
-
function
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}
|
|
881
|
-
} : props;
|
|
882
|
-
const templateElement = template === EMPTY_TEMPLATE ? createTemplate(EMPTY_TEMPLATE) : template;
|
|
883
|
-
return createNodeCache(TemplateNode, templateElement, processedProps);
|
|
884
|
-
}
|
|
885
|
-
function onMount(cb) {
|
|
886
|
-
assertInsideComponent("onMounted");
|
|
887
|
-
LifecycleContext.ref && LifecycleContext.ref.addHook("mounted", cb);
|
|
888
|
-
}
|
|
889
|
-
function onDestroy(cb) {
|
|
890
|
-
assertInsideComponent("onDestroy");
|
|
891
|
-
LifecycleContext.ref && LifecycleContext.ref.addHook("destroy", cb);
|
|
892
|
-
}
|
|
893
|
-
function assertInsideComponent(hookName, key) {
|
|
894
|
-
if (!LifecycleContext.ref && true) {
|
|
895
|
-
console.error(
|
|
896
|
-
`"${hookName}"(key: ${shared.isSymbol(key) ? key.toString() : key}) can only be called within the component function body
|
|
897
|
-
and cannot be used in asynchronous or deferred calls.`
|
|
898
|
-
);
|
|
1624
|
+
function normalizeStyle(styleValue) {
|
|
1625
|
+
if (shared.isArray(styleValue)) {
|
|
1626
|
+
const normalizedStyleObject = {};
|
|
1627
|
+
for (const styleItem of styleValue) {
|
|
1628
|
+
const normalizedItem = shared.isString(styleItem) ? parseStyleString(styleItem) : normalizeStyle(styleItem);
|
|
1629
|
+
if (normalizedItem) {
|
|
1630
|
+
for (const key in normalizedItem) {
|
|
1631
|
+
normalizedStyleObject[key] = normalizedItem[key];
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return normalizedStyleObject;
|
|
1636
|
+
}
|
|
1637
|
+
if (shared.isString(styleValue) || shared.isObject(styleValue)) {
|
|
1638
|
+
return styleValue;
|
|
899
1639
|
}
|
|
1640
|
+
return void 0;
|
|
900
1641
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
1642
|
+
var styleSeparatorRegex = /;(?![^(]*\))/g;
|
|
1643
|
+
var propertyValueSeparatorRegex = /:([\s\S]+)/;
|
|
1644
|
+
var styleCommentRegex = /\/\*[\s\S]*?\*\//g;
|
|
1645
|
+
function parseStyleString(cssText) {
|
|
1646
|
+
const styleObject = {};
|
|
1647
|
+
cssText.replaceAll(styleCommentRegex, "").split(styleSeparatorRegex).forEach((styleItem) => {
|
|
1648
|
+
if (styleItem) {
|
|
1649
|
+
const parts = styleItem.split(propertyValueSeparatorRegex);
|
|
1650
|
+
if (parts.length > 1) {
|
|
1651
|
+
styleObject[parts[0].trim()] = parts[1].trim();
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
return styleObject;
|
|
904
1656
|
}
|
|
905
|
-
function
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1657
|
+
function styleObjectToString(styleValue) {
|
|
1658
|
+
if (!styleValue) {
|
|
1659
|
+
return "";
|
|
1660
|
+
}
|
|
1661
|
+
if (shared.isString(styleValue)) {
|
|
1662
|
+
return styleValue;
|
|
1663
|
+
}
|
|
1664
|
+
let cssText = "";
|
|
1665
|
+
for (const propName in styleValue) {
|
|
1666
|
+
const propValue = styleValue[propName];
|
|
1667
|
+
if (shared.isString(propValue) || shared.isNumber(propValue)) {
|
|
1668
|
+
const normalizedPropName = propName.startsWith("--") ? propName : shared.kebabCase(propName);
|
|
1669
|
+
cssText += `${normalizedPropName}:${propValue};`;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
return cssText;
|
|
909
1673
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1674
|
+
function normalizeClassName(classValue) {
|
|
1675
|
+
let resultClassName = "";
|
|
1676
|
+
if (shared.isString(classValue)) {
|
|
1677
|
+
resultClassName = classValue;
|
|
1678
|
+
} else if (shared.isArray(classValue)) {
|
|
1679
|
+
for (const item of classValue) {
|
|
1680
|
+
const normalizedItem = normalizeClassName(item);
|
|
1681
|
+
if (normalizedItem) {
|
|
1682
|
+
resultClassName += `${normalizedItem} `;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
} else if (shared.isObject(classValue)) {
|
|
1686
|
+
for (const className in classValue) {
|
|
1687
|
+
if (classValue[className]) {
|
|
1688
|
+
resultClassName += `${className} `;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return resultClassName.trim();
|
|
918
1693
|
}
|
|
919
|
-
function
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1694
|
+
function setSSGAttr(attrName, attrValue, hydrationId) {
|
|
1695
|
+
if (signals.isSignal(attrValue) || signals.isComputed(attrValue)) {
|
|
1696
|
+
return setSSGAttr(attrName, attrValue.value);
|
|
1697
|
+
}
|
|
1698
|
+
if (!attrValue && attrValue !== 0) {
|
|
1699
|
+
return "";
|
|
923
1700
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1701
|
+
if (attrName === "style") {
|
|
1702
|
+
const normalizedStyle = normalizeStyle(attrValue);
|
|
1703
|
+
if (!normalizedStyle) {
|
|
1704
|
+
return "";
|
|
1705
|
+
}
|
|
1706
|
+
if (shared.isString(normalizedStyle)) {
|
|
1707
|
+
return ` style="${normalizedStyle}"`;
|
|
1708
|
+
}
|
|
1709
|
+
return ` style="${styleObjectToString(normalizedStyle)}"`;
|
|
1710
|
+
}
|
|
1711
|
+
if (attrName === "class") {
|
|
1712
|
+
const normalizedClassName = normalizeClassName(attrValue);
|
|
1713
|
+
return normalizedClassName ? ` class="${normalizedClassName}"` : "";
|
|
1714
|
+
}
|
|
1715
|
+
if (attrName.startsWith("on")) {
|
|
1716
|
+
return "";
|
|
1717
|
+
}
|
|
1718
|
+
if (attrValue === true) {
|
|
1719
|
+
return ` ${attrName}`;
|
|
1720
|
+
}
|
|
1721
|
+
return ` ${attrName}="${attrValue}"`;
|
|
1722
|
+
}
|
|
1723
|
+
function getRenderedElement(temp) {
|
|
1724
|
+
return () => {
|
|
1725
|
+
const key = getHydrationKey();
|
|
1726
|
+
const node = document.querySelector(`[data-hk="${key}"]`);
|
|
1727
|
+
return node || template(temp)();
|
|
1728
|
+
};
|
|
927
1729
|
}
|
|
928
|
-
function
|
|
929
|
-
|
|
930
|
-
|
|
1730
|
+
function mapSSRNodes(template2, idx) {
|
|
1731
|
+
const hk = template2.dataset.hk;
|
|
1732
|
+
if (!hk) {
|
|
1733
|
+
return mapNodes(template2, idx);
|
|
1734
|
+
}
|
|
1735
|
+
const nodesList = [];
|
|
1736
|
+
const elements = template2.querySelectorAll(`[data-idx^="${hk}"]`);
|
|
1737
|
+
if (elements.length > 0) {
|
|
1738
|
+
nodesList.push(
|
|
1739
|
+
...Array.from(elements).filter((item) => {
|
|
1740
|
+
const idxAttr = item.dataset.idx;
|
|
1741
|
+
return idxAttr !== null && DATA_IDX_REGEX.test(idxAttr);
|
|
1742
|
+
}).map((item) => {
|
|
1743
|
+
const idxAttr = item.dataset.idx || "";
|
|
1744
|
+
const [hkPart, idxPart] = idxAttr.split("-");
|
|
1745
|
+
return {
|
|
1746
|
+
hk: hkPart,
|
|
1747
|
+
idx: idxPart,
|
|
1748
|
+
node: item
|
|
1749
|
+
};
|
|
1750
|
+
})
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
const commentNodes = [];
|
|
1754
|
+
const walkNodes = (node) => {
|
|
1755
|
+
if (node.nodeType === Node.COMMENT_NODE && node.textContent && DATA_IDX_REGEX.test(node.textContent)) {
|
|
1756
|
+
const [hkPart, idxPart] = node.textContent.split("-");
|
|
1757
|
+
commentNodes.push({
|
|
1758
|
+
hk: hkPart,
|
|
1759
|
+
idx: idxPart,
|
|
1760
|
+
node
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
let child = node.firstChild;
|
|
1764
|
+
while (child) {
|
|
1765
|
+
walkNodes(child);
|
|
1766
|
+
child = child.nextSibling;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
walkNodes(template2);
|
|
1770
|
+
nodesList.push(...commentNodes);
|
|
1771
|
+
const nodes = [template2];
|
|
1772
|
+
idx.forEach((indexValue) => {
|
|
1773
|
+
const node = nodesList.find((item) => item.idx === String(indexValue));
|
|
1774
|
+
if (node) {
|
|
1775
|
+
nodes.push(node.node);
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
return nodes;
|
|
1779
|
+
}
|
|
1780
|
+
function hydrate(component, container, props = {}) {
|
|
1781
|
+
resetHydrationKey();
|
|
1782
|
+
try {
|
|
1783
|
+
const rootElement = shared.isString(container) ? document.querySelector(container) : container;
|
|
1784
|
+
if (!rootElement) {
|
|
1785
|
+
shared.error("Hydration error: Root element not found");
|
|
1786
|
+
return void 0;
|
|
1787
|
+
}
|
|
1788
|
+
const rootComponent = createComponent(component, props);
|
|
1789
|
+
rootComponent.mount(rootElement);
|
|
1790
|
+
endHydration();
|
|
1791
|
+
return rootComponent;
|
|
1792
|
+
} catch (error_) {
|
|
1793
|
+
shared.error("Hydration error:", error_);
|
|
1794
|
+
return void 0;
|
|
931
1795
|
}
|
|
932
|
-
return h(component, props);
|
|
933
1796
|
}
|
|
934
1797
|
|
|
1798
|
+
Object.defineProperty(exports, "escapeHTML", {
|
|
1799
|
+
enumerable: true,
|
|
1800
|
+
get: function () { return shared.escapeHTML; }
|
|
1801
|
+
});
|
|
1802
|
+
exports.Component = Component;
|
|
935
1803
|
exports.Fragment = Fragment;
|
|
936
|
-
exports.
|
|
1804
|
+
exports.Portal = Portal;
|
|
1805
|
+
exports.Suspense = Suspense;
|
|
1806
|
+
exports.SuspenseContext = SuspenseContext;
|
|
1807
|
+
exports.addEvent = addEvent;
|
|
1808
|
+
exports.addEventListener = addEventListener;
|
|
1809
|
+
exports.bindElement = bindElement;
|
|
1810
|
+
exports.createApp = createApp;
|
|
1811
|
+
exports.createComponent = createComponent;
|
|
1812
|
+
exports.createResource = createResource;
|
|
1813
|
+
exports.createSSGComponent = createSSGComponent;
|
|
1814
|
+
exports.delegateEvents = delegateEvents;
|
|
1815
|
+
exports.getHydrationKey = getHydrationKey;
|
|
1816
|
+
exports.getRenderedElement = getRenderedElement;
|
|
937
1817
|
exports.hydrate = hydrate;
|
|
938
1818
|
exports.inject = inject;
|
|
1819
|
+
exports.insert = insert;
|
|
939
1820
|
exports.isComponent = isComponent;
|
|
940
|
-
exports.
|
|
1821
|
+
exports.isFragment = isFragment;
|
|
1822
|
+
exports.isPortal = isPortal;
|
|
1823
|
+
exports.isSuspense = isSuspense;
|
|
1824
|
+
exports.mapNodes = mapNodes;
|
|
1825
|
+
exports.mapSSRNodes = mapSSRNodes;
|
|
1826
|
+
exports.normalizeClass = normalizeClass;
|
|
941
1827
|
exports.onDestroy = onDestroy;
|
|
942
1828
|
exports.onMount = onMount;
|
|
1829
|
+
exports.onUpdate = onUpdate;
|
|
1830
|
+
exports.patchAttr = patchAttr;
|
|
1831
|
+
exports.patchClass = patchClass;
|
|
1832
|
+
exports.patchStyle = patchStyle;
|
|
943
1833
|
exports.provide = provide;
|
|
1834
|
+
exports.render = render;
|
|
944
1835
|
exports.renderToString = renderToString;
|
|
945
|
-
exports.
|
|
946
|
-
exports.
|
|
1836
|
+
exports.setSSGAttr = setSSGAttr;
|
|
1837
|
+
exports.setStyle = setStyle;
|
|
1838
|
+
exports.template = template;
|