@estjs/template 0.0.16-beta.7 → 0.0.16-beta.9
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-GXUTKBCN.js +1 -0
- package/dist/{chunk-OEKE4VTS.dev.esm.js → chunk-W5LMSADN.dev.js} +37 -27
- package/dist/chunk-W5LMSADN.dev.js.map +1 -0
- package/dist/internal.cjs +1 -0
- package/dist/{internal.dev.cjs.js → internal.dev.cjs} +23 -26
- package/dist/internal.dev.cjs.map +1 -0
- package/dist/internal.dev.js +3 -0
- package/dist/{internal.dev.esm.js.map → internal.dev.js.map} +1 -1
- package/dist/internal.js +1 -0
- package/dist/template.cjs +2 -0
- package/dist/template.d.cts +203 -64
- package/dist/template.d.ts +203 -64
- package/dist/{template.dev.cjs.js → template.dev.cjs} +1094 -201
- package/dist/template.dev.cjs.map +1 -0
- package/dist/{template.dev.esm.js → template.dev.js} +1050 -177
- package/dist/template.dev.js.map +1 -0
- package/dist/template.js +2 -0
- package/package.json +21 -22
- package/dist/chunk-IA4OZ7NW.esm.js +0 -1
- package/dist/chunk-OEKE4VTS.dev.esm.js.map +0 -1
- package/dist/internal.cjs.js +0 -1
- package/dist/internal.dev.cjs.js.map +0 -1
- package/dist/internal.dev.esm.js +0 -3
- package/dist/internal.esm.js +0 -1
- package/dist/template.cjs.js +0 -2
- package/dist/template.dev.cjs.js.map +0 -1
- package/dist/template.dev.esm.js.map +0 -1
- package/dist/template.esm.js +0 -2
|
@@ -3,9 +3,22 @@
|
|
|
3
3
|
var shared = require('@estjs/shared');
|
|
4
4
|
var signals = require('@estjs/signals');
|
|
5
5
|
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
6
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
9
22
|
var __objRest = (source, exclude) => {
|
|
10
23
|
var target = {};
|
|
11
24
|
for (var prop in source)
|
|
@@ -38,9 +51,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
51
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
52
|
});
|
|
40
53
|
};
|
|
41
|
-
|
|
42
|
-
// src/constants.ts
|
|
43
|
-
var SPREAD_NAME = "_$spread$";
|
|
44
54
|
var REF_KEY = "ref";
|
|
45
55
|
var KEY_PROP = "key";
|
|
46
56
|
var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
@@ -50,11 +60,17 @@ var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
|
|
|
50
60
|
var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
|
|
51
61
|
var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
|
|
52
62
|
var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
|
|
63
|
+
var TRANSITION_COMPONENT = /* @__PURE__ */ Symbol("Transition Component" );
|
|
64
|
+
var TRANSITION_GROUP_COMPONENT = /* @__PURE__ */ Symbol("TransitionGroup Component" );
|
|
53
65
|
var activeScope = null;
|
|
54
66
|
var scopeId = 0;
|
|
55
67
|
function getActiveScope() {
|
|
56
68
|
return activeScope;
|
|
57
69
|
}
|
|
70
|
+
function setActiveScope(scope) {
|
|
71
|
+
activeScope = scope;
|
|
72
|
+
signals.setCurrentScope(scope == null ? void 0 : scope.effectScope);
|
|
73
|
+
}
|
|
58
74
|
function createScope(parent = activeScope) {
|
|
59
75
|
const reactiveScope = parent ? parent.effectScope.run(() => signals.effectScope()) : signals.effectScope(true);
|
|
60
76
|
const scope = {
|
|
@@ -86,11 +102,11 @@ function createScope(parent = activeScope) {
|
|
|
86
102
|
}
|
|
87
103
|
function runWithScope(scope, fn) {
|
|
88
104
|
const prevScope = activeScope;
|
|
89
|
-
|
|
105
|
+
setActiveScope(scope);
|
|
90
106
|
try {
|
|
91
107
|
return scope.effectScope.run(fn);
|
|
92
108
|
} finally {
|
|
93
|
-
|
|
109
|
+
setActiveScope(prevScope);
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
function disposeScope(scope) {
|
|
@@ -108,32 +124,29 @@ function disposeScope(scope) {
|
|
|
108
124
|
}
|
|
109
125
|
scope.children.clear();
|
|
110
126
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
|
127
|
+
const prevScope = activeScope;
|
|
128
|
+
setActiveScope(scope);
|
|
129
|
+
if (scope.onDestroy) {
|
|
130
|
+
for (let i = 0; i < scope.onDestroy.length; i++) {
|
|
131
|
+
try {
|
|
132
|
+
scope.onDestroy[i]();
|
|
133
|
+
} catch (error_) {
|
|
134
|
+
shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
|
|
121
135
|
}
|
|
122
|
-
scope.onDestroy = null;
|
|
123
136
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
137
|
+
scope.onDestroy = null;
|
|
138
|
+
}
|
|
139
|
+
if (scope.cleanup) {
|
|
140
|
+
for (let i = 0; i < scope.cleanup.length; i++) {
|
|
141
|
+
try {
|
|
142
|
+
scope.cleanup[i]();
|
|
143
|
+
} catch (error_) {
|
|
144
|
+
shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
|
|
133
145
|
}
|
|
134
|
-
scope.cleanup = null;
|
|
135
146
|
}
|
|
136
|
-
|
|
147
|
+
scope.cleanup = null;
|
|
148
|
+
}
|
|
149
|
+
setActiveScope(prevScope);
|
|
137
150
|
scope.effectScope.stop();
|
|
138
151
|
if ((_a2 = scope.parent) == null ? void 0 : _a2.children) {
|
|
139
152
|
scope.parent.children.delete(scope);
|
|
@@ -169,7 +182,7 @@ function patchAttr(el, key, prev, next2) {
|
|
|
169
182
|
}
|
|
170
183
|
return;
|
|
171
184
|
}
|
|
172
|
-
if (key === SPREAD_NAME) {
|
|
185
|
+
if (key === shared.SPREAD_NAME) {
|
|
173
186
|
const prevObj = shared.isObject(prev) ? prev : null;
|
|
174
187
|
const nextObj = shared.isObject(next2) ? next2 : null;
|
|
175
188
|
{
|
|
@@ -179,7 +192,7 @@ function patchAttr(el, key, prev, next2) {
|
|
|
179
192
|
}
|
|
180
193
|
if (prevObj) {
|
|
181
194
|
for (const attrKey in prevObj) {
|
|
182
|
-
if (attrKey === SPREAD_NAME) {
|
|
195
|
+
if (attrKey === shared.SPREAD_NAME) {
|
|
183
196
|
{
|
|
184
197
|
shared.warn("nested spread attributes are ignored");
|
|
185
198
|
}
|
|
@@ -192,7 +205,7 @@ function patchAttr(el, key, prev, next2) {
|
|
|
192
205
|
}
|
|
193
206
|
if (nextObj) {
|
|
194
207
|
for (const attrKey in nextObj) {
|
|
195
|
-
if (attrKey === SPREAD_NAME) {
|
|
208
|
+
if (attrKey === shared.SPREAD_NAME) {
|
|
196
209
|
{
|
|
197
210
|
shared.warn("nested spread attributes are ignored");
|
|
198
211
|
}
|
|
@@ -204,8 +217,8 @@ function patchAttr(el, key, prev, next2) {
|
|
|
204
217
|
return;
|
|
205
218
|
}
|
|
206
219
|
const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
|
|
207
|
-
const isXlink = elementIsSVG &&
|
|
208
|
-
const isXmlns = elementIsSVG &&
|
|
220
|
+
const isXlink = elementIsSVG && shared.startsWith(key, "xlink:");
|
|
221
|
+
const isXmlns = elementIsSVG && shared.startsWith(key, "xmlns:");
|
|
209
222
|
const isBoolean = shared.isSpecialBooleanAttr(key) || shared.isBooleanAttr(key);
|
|
210
223
|
if (prev === next2) {
|
|
211
224
|
return;
|
|
@@ -243,7 +256,7 @@ function patchAttr(el, key, prev, next2) {
|
|
|
243
256
|
const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href" || lowerKey === "action" || lowerKey === "formaction" || lowerKey === "poster";
|
|
244
257
|
if (isUrlAttr && shared.isString(attrValue)) {
|
|
245
258
|
const v = attrValue.trim().toLowerCase();
|
|
246
|
-
if (
|
|
259
|
+
if (shared.startsWith(v, "javascript:") || shared.startsWith(v, "data:")) {
|
|
247
260
|
return;
|
|
248
261
|
}
|
|
249
262
|
}
|
|
@@ -347,7 +360,7 @@ function setStyle(style, name, val) {
|
|
|
347
360
|
if (priority) {
|
|
348
361
|
val = val.replace(importantRE, "");
|
|
349
362
|
}
|
|
350
|
-
if (
|
|
363
|
+
if (shared.startsWith(name, "--")) {
|
|
351
364
|
if (priority) {
|
|
352
365
|
style.setProperty(name, val, priority);
|
|
353
366
|
} else {
|
|
@@ -364,7 +377,7 @@ function setStyle(style, name, val) {
|
|
|
364
377
|
}
|
|
365
378
|
function toCssPropertyName(name) {
|
|
366
379
|
const hyphenated = shared.kebabCase(name);
|
|
367
|
-
return
|
|
380
|
+
return shared.startsWith(name, "Webkit") || shared.startsWith(name, "Moz") || shared.startsWith(name, "ms") ? `-${hyphenated}` : hyphenated;
|
|
368
381
|
}
|
|
369
382
|
function autoPrefix(style, rawName) {
|
|
370
383
|
const cached = prefixCache[rawName];
|
|
@@ -466,6 +479,77 @@ function endHydration() {
|
|
|
466
479
|
_teleportCallsiteAnchors.length = 0;
|
|
467
480
|
_teleportTargetStarts.clear();
|
|
468
481
|
}
|
|
482
|
+
function claimHydratedNodes(parent, expected, before) {
|
|
483
|
+
var _a2, _b;
|
|
484
|
+
if (!_isHydrating || before && before.parentNode !== parent) return null;
|
|
485
|
+
if (expected.length === 0) return [];
|
|
486
|
+
const claimed = new Array(expected.length);
|
|
487
|
+
let cursor = before ? before.previousSibling : parent.lastChild;
|
|
488
|
+
for (let i = expected.length - 1; i >= 0; i--) {
|
|
489
|
+
if (!cursor) return null;
|
|
490
|
+
const expectedNode = expected[i];
|
|
491
|
+
const expectedType = expectedNode.nodeType;
|
|
492
|
+
if (expectedType === Node.TEXT_NODE) {
|
|
493
|
+
const expectedText = (_a2 = expectedNode.textContent) != null ? _a2 : "";
|
|
494
|
+
if (!expectedText || cursor.nodeType !== Node.TEXT_NODE) return null;
|
|
495
|
+
const existingText = (_b = cursor.textContent) != null ? _b : "";
|
|
496
|
+
if (existingText === expectedText) {
|
|
497
|
+
claimed[i] = cursor;
|
|
498
|
+
cursor = cursor.previousSibling;
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (!existingText.endsWith(expectedText)) return null;
|
|
502
|
+
const prefix = existingText.slice(0, existingText.length - expectedText.length);
|
|
503
|
+
if (!prefix) return null;
|
|
504
|
+
const prefixNode = document.createTextNode(prefix);
|
|
505
|
+
parent.insertBefore(prefixNode, cursor);
|
|
506
|
+
cursor.textContent = expectedText;
|
|
507
|
+
claimed[i] = cursor;
|
|
508
|
+
cursor = prefixNode;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (cursor.nodeType !== expectedType) return null;
|
|
512
|
+
if (expectedType === Node.ELEMENT_NODE) {
|
|
513
|
+
if (cursor.tagName !== expectedNode.tagName) return null;
|
|
514
|
+
} else if (expectedType === Node.COMMENT_NODE && cursor.data !== expectedNode.data) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
claimed[i] = cursor;
|
|
518
|
+
cursor = cursor.previousSibling;
|
|
519
|
+
}
|
|
520
|
+
return claimed;
|
|
521
|
+
}
|
|
522
|
+
function resolveHydrationKey(parent) {
|
|
523
|
+
var _a2, _b, _c;
|
|
524
|
+
const el = parent;
|
|
525
|
+
return (_c = (_b = el.dataset.hk) != null ? _b : (_a2 = parent.closest("[data-hk]")) == null ? void 0 : _a2.dataset.hk) != null ? _c : null;
|
|
526
|
+
}
|
|
527
|
+
function hydrationMarker(parent, index) {
|
|
528
|
+
if (!_isHydrating || !parent || index < 0) return null;
|
|
529
|
+
const key = parent instanceof Element ? resolveHydrationKey(parent) : null;
|
|
530
|
+
const expected = key ? `${key}-${index}` : String(index);
|
|
531
|
+
let cursor = parent.firstChild;
|
|
532
|
+
while (cursor) {
|
|
533
|
+
if (cursor.nodeType === Node.COMMENT_NODE && cursor.data === expected) {
|
|
534
|
+
return cursor;
|
|
535
|
+
}
|
|
536
|
+
cursor = cursor.nextSibling;
|
|
537
|
+
}
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
function hydrationAnchor(parent, index) {
|
|
541
|
+
if (!_isHydrating || !(parent instanceof Element) || index < 0) return null;
|
|
542
|
+
const key = resolveHydrationKey(parent);
|
|
543
|
+
const expected = key ? `${key}-${index}` : String(index);
|
|
544
|
+
let cursor = parent.firstChild;
|
|
545
|
+
while (cursor) {
|
|
546
|
+
if (cursor instanceof Element && cursor.getAttribute(shared.HYDRATION_ANCHOR_ATTR) === expected) {
|
|
547
|
+
return cursor;
|
|
548
|
+
}
|
|
549
|
+
cursor = cursor.nextSibling;
|
|
550
|
+
}
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
469
553
|
function getRenderedElement(html) {
|
|
470
554
|
if (!shared.isBrowser()) {
|
|
471
555
|
return () => {
|
|
@@ -563,12 +647,17 @@ function reconcileArrays(parent, oldNodes, newNodes, anchor) {
|
|
|
563
647
|
}
|
|
564
648
|
function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, newEnd, anchor) {
|
|
565
649
|
const newLength = newEnd - start + 1;
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
650
|
+
const findNewIndex = newLength <= 4 ? (node) => {
|
|
651
|
+
for (let i = start; i <= newEnd; i++) {
|
|
652
|
+
if (newNodes[i] === node) return i;
|
|
653
|
+
}
|
|
654
|
+
return void 0;
|
|
655
|
+
} : (() => {
|
|
656
|
+
const map = /* @__PURE__ */ new Map();
|
|
657
|
+
for (let i = start; i <= newEnd; i++) map.set(newNodes[i], i);
|
|
658
|
+
return (node) => map.get(node);
|
|
659
|
+
})();
|
|
570
660
|
const newIndexToOldIndexMap = new Int32Array(newLength);
|
|
571
|
-
newIndexToOldIndexMap.fill(0);
|
|
572
661
|
let patched = 0;
|
|
573
662
|
let moved = false;
|
|
574
663
|
let maxNewIndexSoFar = 0;
|
|
@@ -578,7 +667,7 @@ function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, new
|
|
|
578
667
|
removeNode(oldNode);
|
|
579
668
|
continue;
|
|
580
669
|
}
|
|
581
|
-
const newIndex =
|
|
670
|
+
const newIndex = findNewIndex(oldNode);
|
|
582
671
|
if (newIndex === void 0) {
|
|
583
672
|
removeNode(oldNode);
|
|
584
673
|
} else {
|
|
@@ -724,6 +813,14 @@ function insert(parent, nodeFactory, before) {
|
|
|
724
813
|
isFirstRun = false;
|
|
725
814
|
return;
|
|
726
815
|
}
|
|
816
|
+
if (isFirstRun && isHydrating()) {
|
|
817
|
+
const hydratedNodes = claimHydratedNodes(parent, nodes, before);
|
|
818
|
+
if (hydratedNodes) {
|
|
819
|
+
renderedNodes = hydratedNodes;
|
|
820
|
+
isFirstRun = false;
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
727
824
|
renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
|
|
728
825
|
isFirstRun = false;
|
|
729
826
|
};
|
|
@@ -870,14 +967,13 @@ function triggerUpdateHooks(scope) {
|
|
|
870
967
|
|
|
871
968
|
// src/component.ts
|
|
872
969
|
function syncDescriptors(target, source, pruneMissing = false) {
|
|
873
|
-
const seen = pruneMissing ? /* @__PURE__ */ new Set() : null;
|
|
874
970
|
for (const key of Object.getOwnPropertyNames(source)) {
|
|
875
|
-
seen == null ? void 0 : seen.add(key);
|
|
876
971
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
877
972
|
}
|
|
878
|
-
if (
|
|
973
|
+
if (pruneMissing) {
|
|
974
|
+
const sourceKeys = Object.getOwnPropertyNames(source);
|
|
879
975
|
for (const key of Object.getOwnPropertyNames(target)) {
|
|
880
|
-
if (!
|
|
976
|
+
if (!sourceKeys.includes(key)) delete target[key];
|
|
881
977
|
}
|
|
882
978
|
}
|
|
883
979
|
}
|
|
@@ -986,6 +1082,9 @@ var Component = class {
|
|
|
986
1082
|
this.renderedNodes = [];
|
|
987
1083
|
this.firstChild = void 0;
|
|
988
1084
|
this.parentNode = void 0;
|
|
1085
|
+
for (const key of Object.getOwnPropertyNames(this.reactiveProps)) {
|
|
1086
|
+
delete this.reactiveProps[key];
|
|
1087
|
+
}
|
|
989
1088
|
}
|
|
990
1089
|
/**
|
|
991
1090
|
* Apply props that bind to the root DOM element rather than flowing into
|
|
@@ -996,7 +1095,7 @@ var Component = class {
|
|
|
996
1095
|
syncSpecialProps(props) {
|
|
997
1096
|
if (!props) return;
|
|
998
1097
|
const root = this.firstChild;
|
|
999
|
-
if (!root) return;
|
|
1098
|
+
if (!root || !(root instanceof Element)) return;
|
|
1000
1099
|
this.releaseSpecialProps();
|
|
1001
1100
|
for (const key of Object.getOwnPropertyNames(props)) {
|
|
1002
1101
|
if (key === REF_KEY) {
|
|
@@ -1008,7 +1107,22 @@ var Component = class {
|
|
|
1008
1107
|
const value = readProp(props, key);
|
|
1009
1108
|
if (!shared.isFunction(value)) continue;
|
|
1010
1109
|
const eventName = key.slice(2).toLowerCase();
|
|
1011
|
-
|
|
1110
|
+
const target = root;
|
|
1111
|
+
const slot = `_$${eventName}`;
|
|
1112
|
+
const prev = target[slot];
|
|
1113
|
+
if (shared.isFunction(prev)) {
|
|
1114
|
+
target[slot] = value;
|
|
1115
|
+
this.rootEventCleanups.push(() => {
|
|
1116
|
+
if (target[slot] === value) target[slot] = prev;
|
|
1117
|
+
});
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
const fn = value;
|
|
1121
|
+
const handler = (event) => {
|
|
1122
|
+
if (target.disabled) return;
|
|
1123
|
+
fn.call(target, event);
|
|
1124
|
+
};
|
|
1125
|
+
this.rootEventCleanups.push(addEvent(target, eventName, handler));
|
|
1012
1126
|
}
|
|
1013
1127
|
}
|
|
1014
1128
|
}
|
|
@@ -1055,91 +1169,6 @@ function createComponent(componentFn, props) {
|
|
|
1055
1169
|
}
|
|
1056
1170
|
return new Component(componentFn, props);
|
|
1057
1171
|
}
|
|
1058
|
-
|
|
1059
|
-
// src/renderer.ts
|
|
1060
|
-
function template(html) {
|
|
1061
|
-
let node;
|
|
1062
|
-
const create = () => {
|
|
1063
|
-
const template2 = document.createElement("template");
|
|
1064
|
-
template2.innerHTML = html;
|
|
1065
|
-
const firstChild = template2.content.firstChild;
|
|
1066
|
-
if (!firstChild) {
|
|
1067
|
-
throw new Error("Invalid template: empty content");
|
|
1068
|
-
}
|
|
1069
|
-
return firstChild;
|
|
1070
|
-
};
|
|
1071
|
-
return () => (node || (node = create())).cloneNode(true);
|
|
1072
|
-
}
|
|
1073
|
-
function createApp(component, target) {
|
|
1074
|
-
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
1075
|
-
if (!container) {
|
|
1076
|
-
{
|
|
1077
|
-
shared.warn(`Target element not found: ${target}`);
|
|
1078
|
-
}
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
const existingContent = container.innerHTML;
|
|
1082
|
-
if (existingContent) {
|
|
1083
|
-
{
|
|
1084
|
-
shared.warn(`Target element is not empty, it will be cleared: ${target}`);
|
|
1085
|
-
}
|
|
1086
|
-
container.innerHTML = "";
|
|
1087
|
-
}
|
|
1088
|
-
const scope = createScope();
|
|
1089
|
-
let rootNode;
|
|
1090
|
-
try {
|
|
1091
|
-
runWithScope(scope, () => {
|
|
1092
|
-
const mountedRoot = createComponent(component);
|
|
1093
|
-
if (isComponent(mountedRoot)) {
|
|
1094
|
-
rootNode = mountedRoot;
|
|
1095
|
-
insertNode(container, mountedRoot);
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
} catch (error_) {
|
|
1099
|
-
disposeScope(scope);
|
|
1100
|
-
throw error_;
|
|
1101
|
-
}
|
|
1102
|
-
return {
|
|
1103
|
-
root: rootNode,
|
|
1104
|
-
unmount: () => {
|
|
1105
|
-
disposeScope(scope);
|
|
1106
|
-
rootNode == null ? void 0 : rootNode.destroy();
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
function hydrate(component, target) {
|
|
1111
|
-
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
1112
|
-
if (!container) {
|
|
1113
|
-
{
|
|
1114
|
-
shared.warn(`[essor] hydrate: target element not found: ${target}`);
|
|
1115
|
-
}
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
beginHydration(container);
|
|
1119
|
-
const scope = createScope();
|
|
1120
|
-
let rootNode;
|
|
1121
|
-
try {
|
|
1122
|
-
runWithScope(scope, () => {
|
|
1123
|
-
const mountedRoot = createComponent(component);
|
|
1124
|
-
if (isComponent(mountedRoot)) {
|
|
1125
|
-
rootNode = mountedRoot;
|
|
1126
|
-
insert(container, mountedRoot);
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
} catch (error_) {
|
|
1130
|
-
disposeScope(scope);
|
|
1131
|
-
throw error_;
|
|
1132
|
-
} finally {
|
|
1133
|
-
endHydration();
|
|
1134
|
-
}
|
|
1135
|
-
return {
|
|
1136
|
-
root: rootNode,
|
|
1137
|
-
unmount: () => {
|
|
1138
|
-
disposeScope(scope);
|
|
1139
|
-
rootNode == null ? void 0 : rootNode.destroy();
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
1172
|
function provide(key, value) {
|
|
1144
1173
|
const scope = getActiveScope();
|
|
1145
1174
|
if (!scope) {
|
|
@@ -1172,6 +1201,186 @@ function inject(key, defaultValue) {
|
|
|
1172
1201
|
}
|
|
1173
1202
|
return defaultValue;
|
|
1174
1203
|
}
|
|
1204
|
+
|
|
1205
|
+
// src/renderer.ts
|
|
1206
|
+
var VERSION = typeof __VERSION__ === "string" ? __VERSION__ : "";
|
|
1207
|
+
var ENFORCE_ORDER = { pre: 0, default: 1, post: 2 };
|
|
1208
|
+
function template(html) {
|
|
1209
|
+
let node;
|
|
1210
|
+
const create = () => {
|
|
1211
|
+
const template2 = document.createElement("template");
|
|
1212
|
+
template2.innerHTML = html;
|
|
1213
|
+
const firstChild = template2.content.firstChild;
|
|
1214
|
+
if (!firstChild) {
|
|
1215
|
+
throw new Error("Invalid template: empty content");
|
|
1216
|
+
}
|
|
1217
|
+
return firstChild;
|
|
1218
|
+
};
|
|
1219
|
+
return () => (node || (node = create())).cloneNode(true);
|
|
1220
|
+
}
|
|
1221
|
+
function createApp(component, arg) {
|
|
1222
|
+
if (shared.isString(arg) || arg instanceof Element) {
|
|
1223
|
+
return buildApp(component).mount(arg);
|
|
1224
|
+
}
|
|
1225
|
+
return buildApp(component, arg);
|
|
1226
|
+
}
|
|
1227
|
+
function hydrate(component, target) {
|
|
1228
|
+
return buildApp(component).hydrate(target);
|
|
1229
|
+
}
|
|
1230
|
+
function definePlugin(plugin) {
|
|
1231
|
+
return plugin;
|
|
1232
|
+
}
|
|
1233
|
+
function buildApp(component, options) {
|
|
1234
|
+
var _a2, _b;
|
|
1235
|
+
const plugins = (_a2 = options == null ? void 0 : options.plugins) != null ? _a2 : [];
|
|
1236
|
+
const config = __spreadValues({}, (_b = options == null ? void 0 : options.config) != null ? _b : {});
|
|
1237
|
+
let mounted = false;
|
|
1238
|
+
function mount(target, isHydrate) {
|
|
1239
|
+
if (mounted) {
|
|
1240
|
+
shared.warn("App is already mounted");
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
mounted = true;
|
|
1244
|
+
const container = shared.isString(target) ? document.querySelector(target) : target;
|
|
1245
|
+
if (!container) {
|
|
1246
|
+
{
|
|
1247
|
+
shared.warn(`[essor] ${isHydrate ? "hydrate" : "createApp"}: target element not found: ${target}`);
|
|
1248
|
+
}
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
if (!isHydrate && container.innerHTML) {
|
|
1252
|
+
shared.warn(`Target element is not empty, it will be cleared: ${target}`);
|
|
1253
|
+
container.innerHTML = "";
|
|
1254
|
+
}
|
|
1255
|
+
const scope = createScope();
|
|
1256
|
+
const mountHooks = [];
|
|
1257
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1258
|
+
const seenRefs = /* @__PURE__ */ new Set();
|
|
1259
|
+
let activePluginName;
|
|
1260
|
+
let root;
|
|
1261
|
+
function reportError(error5, info) {
|
|
1262
|
+
if (config.errorHandler) config.errorHandler(info, error5);
|
|
1263
|
+
else throw error5;
|
|
1264
|
+
}
|
|
1265
|
+
const ordered = plugins.map((entry, index) => ({ entry, index })).sort((a, b) => {
|
|
1266
|
+
var _a3, _b2;
|
|
1267
|
+
const pa = ENFORCE_ORDER[(_a3 = normalizePlugin(a.entry).enforce) != null ? _a3 : "default"];
|
|
1268
|
+
const pb = ENFORCE_ORDER[(_b2 = normalizePlugin(b.entry).enforce) != null ? _b2 : "default"];
|
|
1269
|
+
return pa - pb || a.index - b.index;
|
|
1270
|
+
}).map((x) => x.entry);
|
|
1271
|
+
function runSetup(plugin, opts) {
|
|
1272
|
+
if (seenRefs.has(plugin) || seenNames.has(plugin.name)) {
|
|
1273
|
+
shared.warn(`Plugin "${plugin.name}" is already registered, skipping`);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
seenRefs.add(plugin);
|
|
1277
|
+
seenNames.add(plugin.name);
|
|
1278
|
+
activePluginName = plugin.name;
|
|
1279
|
+
try {
|
|
1280
|
+
const result = plugin.setup(ctx, opts);
|
|
1281
|
+
if (result instanceof Promise) {
|
|
1282
|
+
const pinned = plugin.name;
|
|
1283
|
+
return result.catch((error5) => reportError(error5, { phase: "install", plugin: pinned })).finally(() => {
|
|
1284
|
+
if (activePluginName === pinned) activePluginName = void 0;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
activePluginName = void 0;
|
|
1288
|
+
return result;
|
|
1289
|
+
} catch (error5) {
|
|
1290
|
+
activePluginName = void 0;
|
|
1291
|
+
reportError(error5, { phase: "install", plugin: plugin.name });
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
const ctx = {
|
|
1295
|
+
provide,
|
|
1296
|
+
inject,
|
|
1297
|
+
onMount: (fn) => void mountHooks.push(fn),
|
|
1298
|
+
onCleanup,
|
|
1299
|
+
warn(message) {
|
|
1300
|
+
const info = { plugin: activePluginName };
|
|
1301
|
+
if (config.warnHandler) config.warnHandler(info, message);
|
|
1302
|
+
else shared.warn(message);
|
|
1303
|
+
},
|
|
1304
|
+
error(message) {
|
|
1305
|
+
throw new Error(message);
|
|
1306
|
+
},
|
|
1307
|
+
config,
|
|
1308
|
+
version: VERSION
|
|
1309
|
+
};
|
|
1310
|
+
function finishMount() {
|
|
1311
|
+
if (isHydrate) beginHydration(container);
|
|
1312
|
+
try {
|
|
1313
|
+
const node = createComponent(component);
|
|
1314
|
+
if (isComponent(node)) {
|
|
1315
|
+
root = node;
|
|
1316
|
+
(isHydrate ? insert : insertNode)(container, node);
|
|
1317
|
+
}
|
|
1318
|
+
} finally {
|
|
1319
|
+
if (isHydrate) endHydration();
|
|
1320
|
+
}
|
|
1321
|
+
for (const fn of mountHooks) {
|
|
1322
|
+
try {
|
|
1323
|
+
fn();
|
|
1324
|
+
} catch (error5) {
|
|
1325
|
+
reportError(error5, { phase: "mount" });
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return {
|
|
1329
|
+
root,
|
|
1330
|
+
unmount() {
|
|
1331
|
+
disposeScope(scope);
|
|
1332
|
+
root == null ? void 0 : root.destroy();
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
let asyncTail;
|
|
1337
|
+
try {
|
|
1338
|
+
runWithScope(scope, () => {
|
|
1339
|
+
for (const entry of ordered) {
|
|
1340
|
+
const [plugin, opts] = unpack(entry);
|
|
1341
|
+
if (asyncTail) {
|
|
1342
|
+
asyncTail = asyncTail.then(
|
|
1343
|
+
() => runWithScope(scope, () => {
|
|
1344
|
+
const r = runSetup(plugin, opts);
|
|
1345
|
+
return r instanceof Promise ? r : void 0;
|
|
1346
|
+
})
|
|
1347
|
+
);
|
|
1348
|
+
continue;
|
|
1349
|
+
}
|
|
1350
|
+
const result = runSetup(plugin, opts);
|
|
1351
|
+
if (result instanceof Promise) asyncTail = result;
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
} catch (error5) {
|
|
1355
|
+
disposeScope(scope);
|
|
1356
|
+
throw error5;
|
|
1357
|
+
}
|
|
1358
|
+
if (asyncTail) {
|
|
1359
|
+
return asyncTail.then(() => runWithScope(scope, finishMount)).catch((error5) => {
|
|
1360
|
+
disposeScope(scope);
|
|
1361
|
+
throw error5;
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
try {
|
|
1365
|
+
return runWithScope(scope, finishMount);
|
|
1366
|
+
} catch (error5) {
|
|
1367
|
+
disposeScope(scope);
|
|
1368
|
+
throw error5;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
const app = {
|
|
1372
|
+
config,
|
|
1373
|
+
mount: (target) => mount(target, false),
|
|
1374
|
+
hydrate: (target) => mount(target, true)
|
|
1375
|
+
};
|
|
1376
|
+
return app;
|
|
1377
|
+
}
|
|
1378
|
+
function normalizePlugin(entry) {
|
|
1379
|
+
return Array.isArray(entry) ? entry[0] : entry;
|
|
1380
|
+
}
|
|
1381
|
+
function unpack(entry) {
|
|
1382
|
+
return Array.isArray(entry) ? [entry[0], entry[1]] : [entry, void 0];
|
|
1383
|
+
}
|
|
1175
1384
|
function reTargetEvent(e, value) {
|
|
1176
1385
|
Object.defineProperty(e, "target", {
|
|
1177
1386
|
configurable: true,
|
|
@@ -1226,7 +1435,7 @@ function eventHandler(e) {
|
|
|
1226
1435
|
reTargetEvent(e, oriTarget);
|
|
1227
1436
|
}
|
|
1228
1437
|
var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
|
|
1229
|
-
function delegateEvents(eventNames, document2 =
|
|
1438
|
+
function delegateEvents(eventNames, document2 = globalThis.document) {
|
|
1230
1439
|
const docWithEvents = document2;
|
|
1231
1440
|
const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
|
|
1232
1441
|
for (const name of eventNames) {
|
|
@@ -1236,7 +1445,7 @@ function delegateEvents(eventNames, document2 = window.document) {
|
|
|
1236
1445
|
}
|
|
1237
1446
|
}
|
|
1238
1447
|
}
|
|
1239
|
-
function clearDelegatedEvents(document2 =
|
|
1448
|
+
function clearDelegatedEvents(document2 = globalThis.document) {
|
|
1240
1449
|
const docWithEvents = document2;
|
|
1241
1450
|
const eventSet = docWithEvents[$EVENTS];
|
|
1242
1451
|
if (eventSet) {
|
|
@@ -1254,6 +1463,11 @@ function addEventListener(element, event, handler, options) {
|
|
|
1254
1463
|
}
|
|
1255
1464
|
|
|
1256
1465
|
// src/binding.ts
|
|
1466
|
+
var IDENTITY = (v) => v;
|
|
1467
|
+
var EMPTY_FILES = (() => {
|
|
1468
|
+
if (typeof DataTransfer !== "undefined") return new DataTransfer().files;
|
|
1469
|
+
return [];
|
|
1470
|
+
})();
|
|
1257
1471
|
function writeValue(el, v) {
|
|
1258
1472
|
const target = el;
|
|
1259
1473
|
const next2 = v == null ? "" : String(v);
|
|
@@ -1262,10 +1476,11 @@ function writeValue(el, v) {
|
|
|
1262
1476
|
var CHECKBOX = {
|
|
1263
1477
|
event: "change",
|
|
1264
1478
|
forceChange: true,
|
|
1479
|
+
checkboxArray: true,
|
|
1265
1480
|
read: (el) => el.checked,
|
|
1266
1481
|
write(el, v) {
|
|
1267
1482
|
const e = el;
|
|
1268
|
-
const next2 = Boolean(v);
|
|
1483
|
+
const next2 = shared.isArray(v) ? v.map(String).includes(e.value) : Boolean(v);
|
|
1269
1484
|
if (e.checked !== next2) e.checked = next2;
|
|
1270
1485
|
}
|
|
1271
1486
|
};
|
|
@@ -1286,17 +1501,15 @@ var FILE = {
|
|
|
1286
1501
|
event: "change",
|
|
1287
1502
|
forceChange: true,
|
|
1288
1503
|
read: (el) => el.files,
|
|
1289
|
-
write() {
|
|
1504
|
+
write(el, v) {
|
|
1505
|
+
if (v != null) return;
|
|
1506
|
+
try {
|
|
1507
|
+
el.files = EMPTY_FILES;
|
|
1508
|
+
} catch (e) {
|
|
1509
|
+
}
|
|
1290
1510
|
}
|
|
1291
|
-
// browsers forbid programmatic writes to file inputs
|
|
1292
|
-
};
|
|
1293
|
-
var TEXT = {
|
|
1294
|
-
event: "input",
|
|
1295
|
-
ime: true,
|
|
1296
|
-
read: (el) => el.value,
|
|
1297
|
-
write: writeValue
|
|
1298
1511
|
};
|
|
1299
|
-
var
|
|
1512
|
+
var TEXT_LIKE = {
|
|
1300
1513
|
event: "input",
|
|
1301
1514
|
ime: true,
|
|
1302
1515
|
read: (el) => el.value,
|
|
@@ -1311,41 +1524,44 @@ var SELECT = {
|
|
|
1311
1524
|
},
|
|
1312
1525
|
write(el, v) {
|
|
1313
1526
|
const s = el;
|
|
1314
|
-
if (s.multiple)
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
} else {
|
|
1318
|
-
writeValue(el, v);
|
|
1319
|
-
}
|
|
1527
|
+
if (!s.multiple) return writeValue(el, v);
|
|
1528
|
+
const selected = new Set((shared.isArray(v) ? v : []).map(String));
|
|
1529
|
+
for (const opt of Array.from(s.options)) opt.selected = selected.has(opt.value);
|
|
1320
1530
|
}
|
|
1321
1531
|
};
|
|
1532
|
+
function customStrategy(prop) {
|
|
1533
|
+
return {
|
|
1534
|
+
event: "input",
|
|
1535
|
+
read: (el) => el[prop],
|
|
1536
|
+
write(el, v) {
|
|
1537
|
+
el[prop] = v;
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1322
1541
|
function resolve(node, prop) {
|
|
1323
1542
|
switch (node.nodeName) {
|
|
1324
1543
|
case "INPUT":
|
|
1325
1544
|
if (prop === "checked") return node.type === "radio" ? RADIO : CHECKBOX;
|
|
1326
1545
|
if (prop === "files") return FILE;
|
|
1327
|
-
return
|
|
1546
|
+
if (prop === "value") return TEXT_LIKE;
|
|
1547
|
+
return customStrategy(prop);
|
|
1328
1548
|
case "SELECT":
|
|
1329
1549
|
return SELECT;
|
|
1330
1550
|
case "TEXTAREA":
|
|
1331
|
-
return
|
|
1551
|
+
return TEXT_LIKE;
|
|
1332
1552
|
default:
|
|
1333
|
-
return
|
|
1334
|
-
event: "input",
|
|
1335
|
-
read: (el) => el[prop],
|
|
1336
|
-
write(el, v) {
|
|
1337
|
-
el[prop] = v;
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1553
|
+
return customStrategy(prop);
|
|
1340
1554
|
}
|
|
1341
1555
|
}
|
|
1342
1556
|
function applyModifiers(v, trim, toNum) {
|
|
1343
1557
|
if (!shared.isString(v)) return v;
|
|
1344
|
-
|
|
1345
|
-
if (
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1558
|
+
const s = trim ? v.trim() : v;
|
|
1559
|
+
if (toNum) {
|
|
1560
|
+
const probe = trim ? s : s.trim();
|
|
1561
|
+
if (probe !== "") {
|
|
1562
|
+
const n = Number(probe);
|
|
1563
|
+
if (!Number.isNaN(n)) return n;
|
|
1564
|
+
}
|
|
1349
1565
|
}
|
|
1350
1566
|
return s;
|
|
1351
1567
|
}
|
|
@@ -1353,44 +1569,54 @@ function isFocused(el) {
|
|
|
1353
1569
|
const root = el.getRootNode();
|
|
1354
1570
|
return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === el;
|
|
1355
1571
|
}
|
|
1572
|
+
function shouldAutoCoerceNumber(node, prop) {
|
|
1573
|
+
if (prop !== "value" || node.nodeName !== "INPUT") return false;
|
|
1574
|
+
const t = node.type;
|
|
1575
|
+
return t === "number" || t === "range";
|
|
1576
|
+
}
|
|
1356
1577
|
function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
1357
1578
|
if (!node) return;
|
|
1358
|
-
const { event, read, write, forceChange, ime } = resolve(node, prop);
|
|
1579
|
+
const { event, read, write, forceChange, ime, checkboxArray } = resolve(node, prop);
|
|
1359
1580
|
const trim = modifiers.trim === true;
|
|
1360
|
-
const toNum = modifiers.number === true;
|
|
1581
|
+
const toNum = modifiers.number === true || shouldAutoCoerceNumber(node, prop);
|
|
1361
1582
|
const lazy = modifiers.lazy === true;
|
|
1362
1583
|
const shouldCast = (trim || toNum) && prop !== "files";
|
|
1363
1584
|
const getModel = shared.isFunction(getter) ? getter : () => getter;
|
|
1364
|
-
const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) :
|
|
1585
|
+
const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : IDENTITY;
|
|
1586
|
+
const computeNext = checkboxArray ? (raw) => {
|
|
1587
|
+
const current = getModel();
|
|
1588
|
+
if (!shared.isArray(current)) return cast(raw);
|
|
1589
|
+
const own = node.value;
|
|
1590
|
+
const next2 = current.filter((item) => String(item) !== own);
|
|
1591
|
+
if (raw) next2.push(own);
|
|
1592
|
+
return next2;
|
|
1593
|
+
} : cast;
|
|
1365
1594
|
let composing = false;
|
|
1366
1595
|
const eventName = lazy || forceChange ? "change" : event;
|
|
1367
1596
|
const syncToModel = () => {
|
|
1368
1597
|
if (composing) return;
|
|
1369
1598
|
const raw = read(node);
|
|
1370
1599
|
if (raw === void 0) return;
|
|
1371
|
-
const next2 =
|
|
1600
|
+
const next2 = computeNext(raw);
|
|
1372
1601
|
if (!Object.is(getModel(), next2)) setter(next2);
|
|
1373
1602
|
};
|
|
1374
1603
|
addEventListener(node, eventName, syncToModel);
|
|
1375
1604
|
if (!lazy && shouldCast && eventName !== "change") {
|
|
1376
1605
|
addEventListener(node, "change", () => write(node, cast(read(node))));
|
|
1377
1606
|
}
|
|
1378
|
-
if (ime
|
|
1607
|
+
if (ime) {
|
|
1379
1608
|
addEventListener(node, "compositionstart", () => {
|
|
1380
1609
|
composing = true;
|
|
1381
1610
|
});
|
|
1382
1611
|
addEventListener(node, "compositionend", () => {
|
|
1383
|
-
if (!composing) return;
|
|
1384
1612
|
composing = false;
|
|
1385
|
-
syncToModel();
|
|
1613
|
+
if (!lazy) syncToModel();
|
|
1386
1614
|
});
|
|
1387
1615
|
}
|
|
1388
1616
|
const runner = signals.effect(() => {
|
|
1389
1617
|
const value = getModel();
|
|
1390
|
-
if (ime &&
|
|
1391
|
-
|
|
1392
|
-
if (Object.is(cast(read(node)), value)) return;
|
|
1393
|
-
}
|
|
1618
|
+
if (ime && composing) return;
|
|
1619
|
+
if (ime && !lazy && isFocused(node) && Object.is(cast(read(node)), value)) return;
|
|
1394
1620
|
write(node, value);
|
|
1395
1621
|
});
|
|
1396
1622
|
if (getActiveScope()) {
|
|
@@ -1399,6 +1625,18 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
|
1399
1625
|
}
|
|
1400
1626
|
|
|
1401
1627
|
// src/utils.ts
|
|
1628
|
+
function unwrapSlotValue(raw) {
|
|
1629
|
+
let v = raw;
|
|
1630
|
+
if (Array.isArray(v) && v.length === 1) v = v[0];
|
|
1631
|
+
return typeof v === "function" ? v() : v;
|
|
1632
|
+
}
|
|
1633
|
+
function useChildren(props) {
|
|
1634
|
+
const desc = Object.getOwnPropertyDescriptor(props, "children");
|
|
1635
|
+
if (desc == null ? void 0 : desc.get) {
|
|
1636
|
+
return () => unwrapSlotValue(desc.get.call(props));
|
|
1637
|
+
}
|
|
1638
|
+
return () => unwrapSlotValue(props.children);
|
|
1639
|
+
}
|
|
1402
1640
|
function omitProps(target, keys) {
|
|
1403
1641
|
const excludeSet = new Set(keys);
|
|
1404
1642
|
return new Proxy(target, {
|
|
@@ -1437,9 +1675,11 @@ function omitProps(target, keys) {
|
|
|
1437
1675
|
}
|
|
1438
1676
|
});
|
|
1439
1677
|
}
|
|
1440
|
-
|
|
1441
|
-
// src/components/Fragment.ts
|
|
1442
1678
|
function Fragment(props) {
|
|
1679
|
+
var _a2;
|
|
1680
|
+
if (props && (((_a2 = Object.getOwnPropertyDescriptor(props, "children")) == null ? void 0 : _a2.get) || signals.isReactive(props))) {
|
|
1681
|
+
return [() => props.children];
|
|
1682
|
+
}
|
|
1443
1683
|
const children = props == null ? void 0 : props.children;
|
|
1444
1684
|
if (children == null) return null;
|
|
1445
1685
|
return children;
|
|
@@ -1958,7 +2198,11 @@ function For(props) {
|
|
|
1958
2198
|
let entries = [];
|
|
1959
2199
|
let fallbackNodes = [];
|
|
1960
2200
|
const keyFn = props.key;
|
|
1961
|
-
const
|
|
2201
|
+
const raw = props.children;
|
|
2202
|
+
const renderFn = Array.isArray(raw) && raw.length === 1 && shared.isFunction(raw[0]) ? raw[0] : props.children;
|
|
2203
|
+
if (!shared.isFunction(renderFn)) {
|
|
2204
|
+
throw new TypeError("<For> requires `children` to be a function (item, index) => Node");
|
|
2205
|
+
}
|
|
1962
2206
|
const getList = () => {
|
|
1963
2207
|
var _a2, _b;
|
|
1964
2208
|
const input = props.each;
|
|
@@ -1966,27 +2210,21 @@ function For(props) {
|
|
|
1966
2210
|
if (shared.isFunction(input)) return (_b = input()) != null ? _b : [];
|
|
1967
2211
|
return input != null ? input : [];
|
|
1968
2212
|
};
|
|
1969
|
-
const getKey = (item) => keyFn ? keyFn(item) : item;
|
|
1970
|
-
const
|
|
2213
|
+
const getKey = (item, index) => keyFn ? keyFn(item, index) : item;
|
|
2214
|
+
const mountValue = (value, parent, before) => {
|
|
2215
|
+
if (value == null || value === false) return [];
|
|
1971
2216
|
if (Array.isArray(value)) {
|
|
1972
2217
|
const nodes = [];
|
|
1973
|
-
for (const
|
|
1974
|
-
nodes.push(...normalizeNodes(item));
|
|
1975
|
-
}
|
|
2218
|
+
for (const child2 of value) nodes.push(...mountValue(child2, parent, before));
|
|
1976
2219
|
return nodes;
|
|
1977
2220
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
const nodes = normalizeNodes(value);
|
|
1982
|
-
for (const node of nodes) {
|
|
1983
|
-
if (before) {
|
|
1984
|
-
parent.insertBefore(node, before);
|
|
1985
|
-
} else {
|
|
1986
|
-
parent.appendChild(node);
|
|
1987
|
-
}
|
|
2221
|
+
if (isComponent(value)) {
|
|
2222
|
+
insertNode(parent, value, before != null ? before : void 0);
|
|
2223
|
+
return value.renderedNodes;
|
|
1988
2224
|
}
|
|
1989
|
-
|
|
2225
|
+
const node = normalizeNode(value);
|
|
2226
|
+
insertNode(parent, node, before != null ? before : void 0);
|
|
2227
|
+
return [node];
|
|
1990
2228
|
};
|
|
1991
2229
|
const mountFallback = (parent, before) => {
|
|
1992
2230
|
if (!props.fallback) return;
|
|
@@ -2001,14 +2239,14 @@ function For(props) {
|
|
|
2001
2239
|
}
|
|
2002
2240
|
fallbackNodes = [];
|
|
2003
2241
|
};
|
|
2004
|
-
const renderItem = (item, index, parent, before) => {
|
|
2242
|
+
const renderItem = (item, index, parent, before, key = getKey(item, index)) => {
|
|
2005
2243
|
const parentScope = getActiveScope();
|
|
2006
2244
|
const scope = createScope(parentScope);
|
|
2007
2245
|
let mountedNodes = [];
|
|
2008
2246
|
runWithScope(scope, () => {
|
|
2009
2247
|
mountedNodes = mountValue(renderFn(item, index), parent, before);
|
|
2010
2248
|
});
|
|
2011
|
-
return { key
|
|
2249
|
+
return { key, item, nodes: mountedNodes, scope };
|
|
2012
2250
|
};
|
|
2013
2251
|
const disposeItem = (entry) => {
|
|
2014
2252
|
disposeScope(entry.scope);
|
|
@@ -2077,7 +2315,7 @@ function For(props) {
|
|
|
2077
2315
|
let maxOldSeen = 0;
|
|
2078
2316
|
const newKeys = new Array(newLen);
|
|
2079
2317
|
for (let i = 0; i < newLen; i++) {
|
|
2080
|
-
newKeys[i] = getKey(newItems[i]);
|
|
2318
|
+
newKeys[i] = getKey(newItems[i], i);
|
|
2081
2319
|
}
|
|
2082
2320
|
for (let i = 0; i < newLen; i++) {
|
|
2083
2321
|
const item = newItems[i];
|
|
@@ -2094,11 +2332,11 @@ function For(props) {
|
|
|
2094
2332
|
} else {
|
|
2095
2333
|
if (!batchFragment) batchFragment = document.createDocumentFragment();
|
|
2096
2334
|
disposeItem(reused);
|
|
2097
|
-
newEntries[i] = renderItem(item, i, batchFragment, null);
|
|
2335
|
+
newEntries[i] = renderItem(item, i, batchFragment, null, key);
|
|
2098
2336
|
}
|
|
2099
2337
|
} else {
|
|
2100
2338
|
if (!batchFragment) batchFragment = document.createDocumentFragment();
|
|
2101
|
-
newEntries[i] = renderItem(item, i, batchFragment, null);
|
|
2339
|
+
newEntries[i] = renderItem(item, i, batchFragment, null, key);
|
|
2102
2340
|
}
|
|
2103
2341
|
}
|
|
2104
2342
|
for (const list of oldKeyMap.values()) {
|
|
@@ -2142,12 +2380,662 @@ function For(props) {
|
|
|
2142
2380
|
return fragment;
|
|
2143
2381
|
}
|
|
2144
2382
|
For[FOR_COMPONENT] = true;
|
|
2383
|
+
function resolveTransitionClasses(props) {
|
|
2384
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2385
|
+
const n = (_a2 = props.name) != null ? _a2 : "v";
|
|
2386
|
+
const enterFrom = (_b = props.enterFromClass) != null ? _b : `${n}-enter-from`;
|
|
2387
|
+
const enterActive = (_c = props.enterActiveClass) != null ? _c : `${n}-enter-active`;
|
|
2388
|
+
const enterTo = (_d = props.enterToClass) != null ? _d : `${n}-enter-to`;
|
|
2389
|
+
return {
|
|
2390
|
+
enterFrom,
|
|
2391
|
+
enterActive,
|
|
2392
|
+
enterTo,
|
|
2393
|
+
leaveFrom: (_e = props.leaveFromClass) != null ? _e : `${n}-leave-from`,
|
|
2394
|
+
leaveActive: (_f = props.leaveActiveClass) != null ? _f : `${n}-leave-active`,
|
|
2395
|
+
leaveTo: (_g = props.leaveToClass) != null ? _g : `${n}-leave-to`,
|
|
2396
|
+
appearFrom: (_h = props.appearFromClass) != null ? _h : enterFrom,
|
|
2397
|
+
appearActive: (_i = props.appearActiveClass) != null ? _i : enterActive,
|
|
2398
|
+
appearTo: (_j = props.appearToClass) != null ? _j : enterTo
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
var toMs = (s) => {
|
|
2402
|
+
if (!s) return 0;
|
|
2403
|
+
if (s.endsWith("ms")) return Number(s.slice(0, -2).replace(",", "."));
|
|
2404
|
+
return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
|
|
2405
|
+
};
|
|
2406
|
+
function sumMs(delays, durations) {
|
|
2407
|
+
const d = delays.split(", ");
|
|
2408
|
+
const u = durations.split(", ");
|
|
2409
|
+
let max = 0;
|
|
2410
|
+
for (const [i, dur] of u.entries()) {
|
|
2411
|
+
const total = toMs(dur) + toMs(d[i % d.length] || "0s");
|
|
2412
|
+
if (total > max) max = total;
|
|
2413
|
+
}
|
|
2414
|
+
return max;
|
|
2415
|
+
}
|
|
2416
|
+
function getTransitionInfo(el, type) {
|
|
2417
|
+
const s = getComputedStyle(el);
|
|
2418
|
+
const tt = type !== "animation" ? sumMs(s.transitionDelay, s.transitionDuration) : 0;
|
|
2419
|
+
const at = type !== "transition" ? sumMs(s.animationDelay, s.animationDuration) : 0;
|
|
2420
|
+
if (tt === 0 && at === 0) return null;
|
|
2421
|
+
return tt >= at ? { event: "transitionend", timeout: tt } : { event: "animationend", timeout: at };
|
|
2422
|
+
}
|
|
2423
|
+
function addClass(el, cls) {
|
|
2424
|
+
for (const c of cls.split(/\s+/)) if (c) el.classList.add(c);
|
|
2425
|
+
}
|
|
2426
|
+
function removeClass(el, cls) {
|
|
2427
|
+
for (const c of cls.split(/\s+/)) if (c) el.classList.remove(c);
|
|
2428
|
+
}
|
|
2429
|
+
function nextFrame(cb) {
|
|
2430
|
+
requestAnimationFrame(() => requestAnimationFrame(cb));
|
|
2431
|
+
}
|
|
2432
|
+
function forceReflow(el) {
|
|
2433
|
+
void el.offsetHeight;
|
|
2434
|
+
}
|
|
2435
|
+
function whenTransitionEnds(el, type, explicit, resolve2) {
|
|
2436
|
+
if (explicit != null) {
|
|
2437
|
+
setTimeout(resolve2, explicit);
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
const info = getTransitionInfo(el, type);
|
|
2441
|
+
if (!info) {
|
|
2442
|
+
resolve2();
|
|
2443
|
+
return;
|
|
2444
|
+
}
|
|
2445
|
+
let done = false;
|
|
2446
|
+
const finish = () => {
|
|
2447
|
+
if (done) return;
|
|
2448
|
+
done = true;
|
|
2449
|
+
el.removeEventListener(info.event, onEnd);
|
|
2450
|
+
resolve2();
|
|
2451
|
+
};
|
|
2452
|
+
const onEnd = () => finish();
|
|
2453
|
+
el.addEventListener(info.event, onEnd);
|
|
2454
|
+
setTimeout(finish, info.timeout + 1);
|
|
2455
|
+
}
|
|
2456
|
+
function resolveDuration(d, dir) {
|
|
2457
|
+
if (d == null) return null;
|
|
2458
|
+
if (typeof d === "number") return d;
|
|
2459
|
+
return d[dir];
|
|
2460
|
+
}
|
|
2461
|
+
function validateSlot(value) {
|
|
2462
|
+
if (value == null || value === false) return null;
|
|
2463
|
+
if (Array.isArray(value)) {
|
|
2464
|
+
{
|
|
2465
|
+
throw new Error(
|
|
2466
|
+
"[essor] <Transition> expects a single root child. Use <TransitionGroup> for multiple children."
|
|
2467
|
+
);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
if (value instanceof Element) return value;
|
|
2471
|
+
if (isComponent(value)) {
|
|
2472
|
+
const comp = value;
|
|
2473
|
+
if (comp.scope == null) {
|
|
2474
|
+
const fragment = document.createDocumentFragment();
|
|
2475
|
+
comp.mount(fragment);
|
|
2476
|
+
}
|
|
2477
|
+
if (comp.renderedNodes.length > 1) {
|
|
2478
|
+
shared.warn(
|
|
2479
|
+
"[Transition] child component rendered multiple root nodes; only the first is animated. Wrap the children in a single element or use <TransitionGroup>."
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
const first = comp.firstChild;
|
|
2483
|
+
if (first instanceof Element) return first;
|
|
2484
|
+
{
|
|
2485
|
+
shared.warn("[Transition] child component did not render an Element root.");
|
|
2486
|
+
}
|
|
2487
|
+
return null;
|
|
2488
|
+
}
|
|
2489
|
+
{
|
|
2490
|
+
shared.warn("[Transition] received a non-element child; animation will be skipped.");
|
|
2491
|
+
}
|
|
2492
|
+
return null;
|
|
2493
|
+
}
|
|
2494
|
+
var ENTER_CB = /* @__PURE__ */ Symbol("enter_cb");
|
|
2495
|
+
var LEAVE_CB = /* @__PURE__ */ Symbol("leave_cb");
|
|
2496
|
+
function Transition(props) {
|
|
2497
|
+
const anchor = document.createComment("");
|
|
2498
|
+
const classes = resolveTransitionClasses(props);
|
|
2499
|
+
const useCss = props.css !== false;
|
|
2500
|
+
const readSlot = useChildren(props);
|
|
2501
|
+
let state = "idle";
|
|
2502
|
+
let currentEl = null;
|
|
2503
|
+
let leavingEl = null;
|
|
2504
|
+
let mounted = false;
|
|
2505
|
+
let pendingRaw = void 0;
|
|
2506
|
+
let hasPending = false;
|
|
2507
|
+
let scheduled = false;
|
|
2508
|
+
let disposed = false;
|
|
2509
|
+
const enter = (el, phase) => {
|
|
2510
|
+
var _a2;
|
|
2511
|
+
const prevLeave = el[LEAVE_CB];
|
|
2512
|
+
if (prevLeave) prevLeave(true);
|
|
2513
|
+
state = "entering";
|
|
2514
|
+
const fromCls = phase === "appear" ? classes.appearFrom : classes.enterFrom;
|
|
2515
|
+
const activeCls = phase === "appear" ? classes.appearActive : classes.enterActive;
|
|
2516
|
+
const toCls = phase === "appear" ? classes.appearTo : classes.enterTo;
|
|
2517
|
+
(_a2 = props.onBeforeEnter) == null ? void 0 : _a2.call(props, el);
|
|
2518
|
+
if (useCss) {
|
|
2519
|
+
addClass(el, fromCls);
|
|
2520
|
+
addClass(el, activeCls);
|
|
2521
|
+
}
|
|
2522
|
+
let called = false;
|
|
2523
|
+
const done = (cancelled) => {
|
|
2524
|
+
var _a3, _b;
|
|
2525
|
+
if (called) return;
|
|
2526
|
+
called = true;
|
|
2527
|
+
el[ENTER_CB] = void 0;
|
|
2528
|
+
if (useCss) {
|
|
2529
|
+
removeClass(el, fromCls);
|
|
2530
|
+
removeClass(el, activeCls);
|
|
2531
|
+
removeClass(el, toCls);
|
|
2532
|
+
}
|
|
2533
|
+
if (cancelled) {
|
|
2534
|
+
(_a3 = props.onEnterCancelled) == null ? void 0 : _a3.call(props, el);
|
|
2535
|
+
} else {
|
|
2536
|
+
state = "entered";
|
|
2537
|
+
(_b = props.onAfterEnter) == null ? void 0 : _b.call(props, el);
|
|
2538
|
+
}
|
|
2539
|
+
};
|
|
2540
|
+
el[ENTER_CB] = done;
|
|
2541
|
+
nextFrame(() => {
|
|
2542
|
+
if (called) return;
|
|
2543
|
+
if (useCss) {
|
|
2544
|
+
removeClass(el, fromCls);
|
|
2545
|
+
addClass(el, toCls);
|
|
2546
|
+
}
|
|
2547
|
+
if (props.onEnter) {
|
|
2548
|
+
props.onEnter(el, () => done(false));
|
|
2549
|
+
} else if (useCss) {
|
|
2550
|
+
const explicit = resolveDuration(props.duration, "enter");
|
|
2551
|
+
whenTransitionEnds(el, props.type, explicit, () => done(false));
|
|
2552
|
+
} else {
|
|
2553
|
+
done(false);
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
};
|
|
2557
|
+
const leave = (el, after) => {
|
|
2558
|
+
var _a2;
|
|
2559
|
+
const prevEnter = el[ENTER_CB];
|
|
2560
|
+
if (prevEnter) {
|
|
2561
|
+
prevEnter(true);
|
|
2562
|
+
forceReflow(el);
|
|
2563
|
+
}
|
|
2564
|
+
state = "leaving";
|
|
2565
|
+
(_a2 = props.onBeforeLeave) == null ? void 0 : _a2.call(props, el);
|
|
2566
|
+
if (useCss) {
|
|
2567
|
+
addClass(el, classes.leaveFrom);
|
|
2568
|
+
addClass(el, classes.leaveActive);
|
|
2569
|
+
}
|
|
2570
|
+
let called = false;
|
|
2571
|
+
const done = (cancelled) => {
|
|
2572
|
+
var _a3, _b;
|
|
2573
|
+
if (called) return;
|
|
2574
|
+
called = true;
|
|
2575
|
+
el[LEAVE_CB] = void 0;
|
|
2576
|
+
if (useCss) {
|
|
2577
|
+
removeClass(el, classes.leaveFrom);
|
|
2578
|
+
removeClass(el, classes.leaveActive);
|
|
2579
|
+
removeClass(el, classes.leaveTo);
|
|
2580
|
+
}
|
|
2581
|
+
if (cancelled) {
|
|
2582
|
+
(_a3 = props.onLeaveCancelled) == null ? void 0 : _a3.call(props, el);
|
|
2583
|
+
} else {
|
|
2584
|
+
state = "idle";
|
|
2585
|
+
after();
|
|
2586
|
+
(_b = props.onAfterLeave) == null ? void 0 : _b.call(props, el);
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
el[LEAVE_CB] = done;
|
|
2590
|
+
const explicit = resolveDuration(props.duration, "leave");
|
|
2591
|
+
const hasCssInfo = useCss && !props.onLeave && explicit == null ? !!getTransitionInfo(el, props.type) : false;
|
|
2592
|
+
if (!props.onLeave && explicit == null && !hasCssInfo) {
|
|
2593
|
+
done(false);
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
nextFrame(() => {
|
|
2597
|
+
if (called) return;
|
|
2598
|
+
if (useCss) {
|
|
2599
|
+
removeClass(el, classes.leaveFrom);
|
|
2600
|
+
addClass(el, classes.leaveTo);
|
|
2601
|
+
}
|
|
2602
|
+
if (props.onLeave) {
|
|
2603
|
+
props.onLeave(el, () => done(false));
|
|
2604
|
+
} else if (useCss) {
|
|
2605
|
+
whenTransitionEnds(el, props.type, explicit, () => done(false));
|
|
2606
|
+
} else {
|
|
2607
|
+
done(false);
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
};
|
|
2611
|
+
const commit = (next2, isFirst) => {
|
|
2612
|
+
if (next2 && state === "leaving" && leavingEl) {
|
|
2613
|
+
const reviving = leavingEl;
|
|
2614
|
+
const leaveCb = reviving[LEAVE_CB];
|
|
2615
|
+
if (leaveCb) leaveCb(true);
|
|
2616
|
+
leavingEl = null;
|
|
2617
|
+
currentEl = reviving;
|
|
2618
|
+
enter(reviving, "enter");
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
if (next2 === currentEl) return;
|
|
2622
|
+
const outgoing = currentEl;
|
|
2623
|
+
currentEl = next2;
|
|
2624
|
+
if (outgoing) {
|
|
2625
|
+
leavingEl = outgoing;
|
|
2626
|
+
const captured = outgoing;
|
|
2627
|
+
leave(captured, () => {
|
|
2628
|
+
if (captured.parentNode) captured.parentNode.removeChild(captured);
|
|
2629
|
+
if (leavingEl === captured) leavingEl = null;
|
|
2630
|
+
});
|
|
2631
|
+
}
|
|
2632
|
+
if (next2 && anchor.parentNode) {
|
|
2633
|
+
anchor.parentNode.insertBefore(next2, anchor);
|
|
2634
|
+
if (isFirst && !props.appear) {
|
|
2635
|
+
state = "entered";
|
|
2636
|
+
} else {
|
|
2637
|
+
enter(next2, isFirst && props.appear ? "appear" : "enter");
|
|
2638
|
+
}
|
|
2639
|
+
} else if (!outgoing && !next2) {
|
|
2640
|
+
state = "idle";
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
const flush = () => {
|
|
2644
|
+
scheduled = false;
|
|
2645
|
+
if (disposed || !hasPending) return;
|
|
2646
|
+
const raw = pendingRaw;
|
|
2647
|
+
hasPending = false;
|
|
2648
|
+
pendingRaw = void 0;
|
|
2649
|
+
try {
|
|
2650
|
+
commit(validateSlot(raw), false);
|
|
2651
|
+
} catch (error5) {
|
|
2652
|
+
console.error("[essor] <Transition>", error5);
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
const scheduleCommit = (raw) => {
|
|
2656
|
+
pendingRaw = raw;
|
|
2657
|
+
hasPending = true;
|
|
2658
|
+
if (scheduled) return;
|
|
2659
|
+
scheduled = true;
|
|
2660
|
+
queueMicrotask(flush);
|
|
2661
|
+
};
|
|
2662
|
+
const effectRunner = signals.effect(() => {
|
|
2663
|
+
const raw = readSlot();
|
|
2664
|
+
if (mounted) {
|
|
2665
|
+
scheduleCommit(raw);
|
|
2666
|
+
} else {
|
|
2667
|
+
pendingRaw = raw;
|
|
2668
|
+
hasPending = true;
|
|
2669
|
+
}
|
|
2670
|
+
});
|
|
2671
|
+
onMount(() => {
|
|
2672
|
+
mounted = true;
|
|
2673
|
+
const initial = hasPending ? validateSlot(pendingRaw) : null;
|
|
2674
|
+
hasPending = false;
|
|
2675
|
+
pendingRaw = void 0;
|
|
2676
|
+
commit(initial, true);
|
|
2677
|
+
});
|
|
2678
|
+
onCleanup(() => {
|
|
2679
|
+
disposed = true;
|
|
2680
|
+
effectRunner.stop();
|
|
2681
|
+
for (const el of [currentEl, leavingEl]) {
|
|
2682
|
+
if (!el) continue;
|
|
2683
|
+
const ec = el[ENTER_CB];
|
|
2684
|
+
const lc = el[LEAVE_CB];
|
|
2685
|
+
ec == null ? void 0 : ec(true);
|
|
2686
|
+
lc == null ? void 0 : lc(true);
|
|
2687
|
+
if (el.parentNode) el.parentNode.removeChild(el);
|
|
2688
|
+
}
|
|
2689
|
+
currentEl = null;
|
|
2690
|
+
leavingEl = null;
|
|
2691
|
+
state = "idle";
|
|
2692
|
+
});
|
|
2693
|
+
return anchor;
|
|
2694
|
+
}
|
|
2695
|
+
Transition[TRANSITION_COMPONENT] = true;
|
|
2696
|
+
function isTransition(node) {
|
|
2697
|
+
return !!node && !!node[TRANSITION_COMPONENT];
|
|
2698
|
+
}
|
|
2699
|
+
function resolveItemElement(raw, parent) {
|
|
2700
|
+
if (raw == null || raw === false) return { el: null, comp: null };
|
|
2701
|
+
if (Array.isArray(raw) && raw.length === 1) {
|
|
2702
|
+
return resolveItemElement(raw[0], parent);
|
|
2703
|
+
}
|
|
2704
|
+
if (shared.isFunction(raw)) {
|
|
2705
|
+
return resolveItemElement(raw(), parent);
|
|
2706
|
+
}
|
|
2707
|
+
if (raw instanceof HTMLElement) {
|
|
2708
|
+
return { el: raw, comp: null };
|
|
2709
|
+
}
|
|
2710
|
+
if (isComponent(raw)) {
|
|
2711
|
+
const comp = raw;
|
|
2712
|
+
if (comp.scope == null) {
|
|
2713
|
+
comp.mount(parent);
|
|
2714
|
+
}
|
|
2715
|
+
if (comp.renderedNodes.length > 1) {
|
|
2716
|
+
shared.warn(
|
|
2717
|
+
"[TransitionGroup] child component rendered multiple root nodes; only the first participates in enter/leave/move animations."
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
const first = comp.firstChild;
|
|
2721
|
+
if (first instanceof HTMLElement) return { el: first, comp };
|
|
2722
|
+
return { el: null, comp };
|
|
2723
|
+
}
|
|
2724
|
+
{
|
|
2725
|
+
shared.warn(
|
|
2726
|
+
"[TransitionGroup] child render returned a non-element value; animations require Element or Component roots."
|
|
2727
|
+
);
|
|
2728
|
+
}
|
|
2729
|
+
return { el: null, comp: null };
|
|
2730
|
+
}
|
|
2731
|
+
function saveStyles(el) {
|
|
2732
|
+
return {
|
|
2733
|
+
position: el.style.position,
|
|
2734
|
+
top: el.style.top,
|
|
2735
|
+
left: el.style.left,
|
|
2736
|
+
width: el.style.width,
|
|
2737
|
+
height: el.style.height
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
function restoreStyles(el, s) {
|
|
2741
|
+
el.style.position = s.position;
|
|
2742
|
+
el.style.top = s.top;
|
|
2743
|
+
el.style.left = s.left;
|
|
2744
|
+
el.style.width = s.width;
|
|
2745
|
+
el.style.height = s.height;
|
|
2746
|
+
}
|
|
2747
|
+
function TransitionGroup(props) {
|
|
2748
|
+
var _a2, _b, _c;
|
|
2749
|
+
const tag = (_a2 = props.tag) != null ? _a2 : "div";
|
|
2750
|
+
const wrapper = document.createElement(tag);
|
|
2751
|
+
const classes = resolveTransitionClasses(props);
|
|
2752
|
+
const useCss = props.css !== false;
|
|
2753
|
+
const moveClass = (_c = props.moveClass) != null ? _c : `${(_b = props.name) != null ? _b : "v"}-move`;
|
|
2754
|
+
const keyFn = props.key;
|
|
2755
|
+
const rawChildren = props.children;
|
|
2756
|
+
const childrenFn = Array.isArray(rawChildren) && rawChildren.length === 1 && shared.isFunction(rawChildren[0]) ? rawChildren[0] : props.children;
|
|
2757
|
+
if (!shared.isFunction(childrenFn) || !shared.isFunction(keyFn)) {
|
|
2758
|
+
throw new TypeError(
|
|
2759
|
+
"<TransitionGroup> requires `children: (item, index) => Node` and `key: (item, index) => unknown`"
|
|
2760
|
+
);
|
|
2761
|
+
}
|
|
2762
|
+
const getList = () => {
|
|
2763
|
+
var _a3, _b2;
|
|
2764
|
+
const input = props.each;
|
|
2765
|
+
if (signals.isSignal(input)) return (_a3 = input.value) != null ? _a3 : [];
|
|
2766
|
+
if (shared.isFunction(input)) return (_b2 = input()) != null ? _b2 : [];
|
|
2767
|
+
return input != null ? input : [];
|
|
2768
|
+
};
|
|
2769
|
+
let entries = [];
|
|
2770
|
+
let mounted = false;
|
|
2771
|
+
const renderEntry = (item, index) => {
|
|
2772
|
+
const parentScope = getActiveScope();
|
|
2773
|
+
const scope = createScope(parentScope);
|
|
2774
|
+
let raw;
|
|
2775
|
+
runWithScope(scope, () => {
|
|
2776
|
+
raw = childrenFn(item, index);
|
|
2777
|
+
});
|
|
2778
|
+
const { el, comp } = resolveItemElement(raw, wrapper);
|
|
2779
|
+
if (!el) {
|
|
2780
|
+
disposeScope(scope);
|
|
2781
|
+
return null;
|
|
2782
|
+
}
|
|
2783
|
+
return {
|
|
2784
|
+
key: keyFn(item, index),
|
|
2785
|
+
item,
|
|
2786
|
+
el,
|
|
2787
|
+
comp,
|
|
2788
|
+
scope,
|
|
2789
|
+
state: "entering"
|
|
2790
|
+
};
|
|
2791
|
+
};
|
|
2792
|
+
const detachEntryDom = (entry) => {
|
|
2793
|
+
if (entry.comp) {
|
|
2794
|
+
for (const node of entry.comp.renderedNodes) {
|
|
2795
|
+
if (node.parentNode === wrapper) wrapper.removeChild(node);
|
|
2796
|
+
}
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2799
|
+
if (entry.el.parentNode === wrapper) wrapper.removeChild(entry.el);
|
|
2800
|
+
};
|
|
2801
|
+
const disposeEntry = (entry) => {
|
|
2802
|
+
var _a3, _b2;
|
|
2803
|
+
(_a3 = entry.cancelEnter) == null ? void 0 : _a3.call(entry, true);
|
|
2804
|
+
(_b2 = entry.cancelLeave) == null ? void 0 : _b2.call(entry, true);
|
|
2805
|
+
if (entry.comp) entry.comp.destroy();
|
|
2806
|
+
detachEntryDom(entry);
|
|
2807
|
+
disposeScope(entry.scope);
|
|
2808
|
+
};
|
|
2809
|
+
const runEnter = (entry) => {
|
|
2810
|
+
var _a3, _b2, _c2;
|
|
2811
|
+
const el = entry.el;
|
|
2812
|
+
(_a3 = entry.cancelLeave) == null ? void 0 : _a3.call(entry, true);
|
|
2813
|
+
if (!useCss) {
|
|
2814
|
+
entry.state = "present";
|
|
2815
|
+
(_b2 = props.onAfterEnter) == null ? void 0 : _b2.call(props, el);
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
(_c2 = props.onBeforeEnter) == null ? void 0 : _c2.call(props, el);
|
|
2819
|
+
addClass(el, classes.enterFrom);
|
|
2820
|
+
addClass(el, classes.enterActive);
|
|
2821
|
+
let called = false;
|
|
2822
|
+
const done = (cancelled) => {
|
|
2823
|
+
var _a4, _b3;
|
|
2824
|
+
if (called) return;
|
|
2825
|
+
called = true;
|
|
2826
|
+
entry.cancelEnter = void 0;
|
|
2827
|
+
removeClass(el, classes.enterFrom);
|
|
2828
|
+
removeClass(el, classes.enterActive);
|
|
2829
|
+
removeClass(el, classes.enterTo);
|
|
2830
|
+
if (cancelled) {
|
|
2831
|
+
(_a4 = props.onEnterCancelled) == null ? void 0 : _a4.call(props, el);
|
|
2832
|
+
} else {
|
|
2833
|
+
entry.state = "present";
|
|
2834
|
+
(_b3 = props.onAfterEnter) == null ? void 0 : _b3.call(props, el);
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
entry.cancelEnter = done;
|
|
2838
|
+
entry.state = "entering";
|
|
2839
|
+
nextFrame(() => {
|
|
2840
|
+
if (called) return;
|
|
2841
|
+
removeClass(el, classes.enterFrom);
|
|
2842
|
+
addClass(el, classes.enterTo);
|
|
2843
|
+
if (props.onEnter) {
|
|
2844
|
+
props.onEnter(el, () => done(false));
|
|
2845
|
+
} else {
|
|
2846
|
+
const explicit = resolveDuration(props.duration, "enter");
|
|
2847
|
+
whenTransitionEnds(el, props.type, explicit, () => done(false));
|
|
2848
|
+
}
|
|
2849
|
+
});
|
|
2850
|
+
};
|
|
2851
|
+
const runLeave = (entry, prevRect) => {
|
|
2852
|
+
var _a3, _b2;
|
|
2853
|
+
const el = entry.el;
|
|
2854
|
+
if (entry.cancelEnter) {
|
|
2855
|
+
entry.cancelEnter(true);
|
|
2856
|
+
forceReflow(el);
|
|
2857
|
+
}
|
|
2858
|
+
entry.state = "leaving";
|
|
2859
|
+
entry.savedStyles = saveStyles(el);
|
|
2860
|
+
const parentRect = wrapper.getBoundingClientRect();
|
|
2861
|
+
el.style.position = "absolute";
|
|
2862
|
+
el.style.top = `${prevRect.top - parentRect.top}px`;
|
|
2863
|
+
el.style.left = `${prevRect.left - parentRect.left}px`;
|
|
2864
|
+
el.style.width = `${prevRect.width}px`;
|
|
2865
|
+
el.style.height = `${prevRect.height}px`;
|
|
2866
|
+
if (!useCss) {
|
|
2867
|
+
if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
|
|
2868
|
+
detachEntryDom(entry);
|
|
2869
|
+
disposeScope(entry.scope);
|
|
2870
|
+
if (entry.comp) entry.comp.destroy();
|
|
2871
|
+
(_a3 = props.onAfterLeave) == null ? void 0 : _a3.call(props, el);
|
|
2872
|
+
return;
|
|
2873
|
+
}
|
|
2874
|
+
(_b2 = props.onBeforeLeave) == null ? void 0 : _b2.call(props, el);
|
|
2875
|
+
addClass(el, classes.leaveFrom);
|
|
2876
|
+
addClass(el, classes.leaveActive);
|
|
2877
|
+
let called = false;
|
|
2878
|
+
const done = (cancelled) => {
|
|
2879
|
+
var _a4, _b3;
|
|
2880
|
+
if (called) return;
|
|
2881
|
+
called = true;
|
|
2882
|
+
entry.cancelLeave = void 0;
|
|
2883
|
+
removeClass(el, classes.leaveFrom);
|
|
2884
|
+
removeClass(el, classes.leaveActive);
|
|
2885
|
+
removeClass(el, classes.leaveTo);
|
|
2886
|
+
if (cancelled) {
|
|
2887
|
+
if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
|
|
2888
|
+
entry.savedStyles = void 0;
|
|
2889
|
+
(_a4 = props.onLeaveCancelled) == null ? void 0 : _a4.call(props, el);
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
|
|
2893
|
+
entry.savedStyles = void 0;
|
|
2894
|
+
detachEntryDom(entry);
|
|
2895
|
+
disposeScope(entry.scope);
|
|
2896
|
+
if (entry.comp) entry.comp.destroy();
|
|
2897
|
+
(_b3 = props.onAfterLeave) == null ? void 0 : _b3.call(props, el);
|
|
2898
|
+
};
|
|
2899
|
+
entry.cancelLeave = done;
|
|
2900
|
+
nextFrame(() => {
|
|
2901
|
+
if (called) return;
|
|
2902
|
+
removeClass(el, classes.leaveFrom);
|
|
2903
|
+
addClass(el, classes.leaveTo);
|
|
2904
|
+
if (props.onLeave) {
|
|
2905
|
+
props.onLeave(el, () => done(false));
|
|
2906
|
+
} else {
|
|
2907
|
+
const explicit = resolveDuration(props.duration, "leave");
|
|
2908
|
+
whenTransitionEnds(el, props.type, explicit, () => done(false));
|
|
2909
|
+
}
|
|
2910
|
+
});
|
|
2911
|
+
};
|
|
2912
|
+
const runMove = (entry, prevRect) => {
|
|
2913
|
+
if (!useCss || entry.state !== "present") return;
|
|
2914
|
+
const el = entry.el;
|
|
2915
|
+
const newRect = el.getBoundingClientRect();
|
|
2916
|
+
const dx = prevRect.left - newRect.left;
|
|
2917
|
+
const dy = prevRect.top - newRect.top;
|
|
2918
|
+
if (!dx && !dy) return;
|
|
2919
|
+
const savedTransform = el.style.transform;
|
|
2920
|
+
const savedTransition = el.style.transitionDuration;
|
|
2921
|
+
el.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
2922
|
+
el.style.transitionDuration = "0s";
|
|
2923
|
+
addClass(el, moveClass);
|
|
2924
|
+
forceReflow(el);
|
|
2925
|
+
el.style.transform = savedTransform;
|
|
2926
|
+
el.style.transitionDuration = savedTransition;
|
|
2927
|
+
const explicit = resolveDuration(props.duration, "enter");
|
|
2928
|
+
whenTransitionEnds(el, props.type, explicit, () => {
|
|
2929
|
+
removeClass(el, moveClass);
|
|
2930
|
+
});
|
|
2931
|
+
};
|
|
2932
|
+
const snapshotPositions = () => {
|
|
2933
|
+
for (const entry of entries) {
|
|
2934
|
+
if (entry.state === "leaving") continue;
|
|
2935
|
+
entry.prevRect = entry.el.getBoundingClientRect();
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
const reconcile = (newItems) => {
|
|
2939
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
2940
|
+
for (const entry of entries) byKey.set(entry.key, entry);
|
|
2941
|
+
const next2 = [];
|
|
2942
|
+
for (const [i, item] of newItems.entries()) {
|
|
2943
|
+
const key = keyFn(item, i);
|
|
2944
|
+
const reused = byKey.get(key);
|
|
2945
|
+
if (reused) {
|
|
2946
|
+
byKey.delete(key);
|
|
2947
|
+
reused.item = item;
|
|
2948
|
+
next2.push(reused);
|
|
2949
|
+
} else {
|
|
2950
|
+
const fresh = renderEntry(item, i);
|
|
2951
|
+
if (fresh) next2.push(fresh);
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
const leaving = [];
|
|
2955
|
+
for (const entry of byKey.values()) {
|
|
2956
|
+
if (entry.state !== "leaving") leaving.push(entry);
|
|
2957
|
+
}
|
|
2958
|
+
let anchor = null;
|
|
2959
|
+
for (let i = next2.length - 1; i >= 0; i--) {
|
|
2960
|
+
const el = next2[i].el;
|
|
2961
|
+
if (el.parentNode !== wrapper || el.nextSibling !== anchor) {
|
|
2962
|
+
wrapper.insertBefore(el, anchor);
|
|
2963
|
+
}
|
|
2964
|
+
anchor = el;
|
|
2965
|
+
}
|
|
2966
|
+
return { next: next2, leaving };
|
|
2967
|
+
};
|
|
2968
|
+
const update = (newItems, isInitial) => {
|
|
2969
|
+
if (isInitial) {
|
|
2970
|
+
const initial = [];
|
|
2971
|
+
for (const [i, item] of newItems.entries()) {
|
|
2972
|
+
const entry = renderEntry(item, i);
|
|
2973
|
+
if (!entry) continue;
|
|
2974
|
+
if (entry.el.parentNode !== wrapper) wrapper.appendChild(entry.el);
|
|
2975
|
+
entry.state = "present";
|
|
2976
|
+
initial.push(entry);
|
|
2977
|
+
}
|
|
2978
|
+
entries = initial;
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
snapshotPositions();
|
|
2982
|
+
const { next: next2, leaving } = reconcile(newItems);
|
|
2983
|
+
for (const entry of next2) {
|
|
2984
|
+
if (entry.state !== "present") runEnter(entry);
|
|
2985
|
+
}
|
|
2986
|
+
for (const entry of leaving) {
|
|
2987
|
+
const rect = entry.prevRect;
|
|
2988
|
+
if (!rect) {
|
|
2989
|
+
{
|
|
2990
|
+
shared.warn("[TransitionGroup] leaving entry without prevRect \u2014 skipping leave animation");
|
|
2991
|
+
}
|
|
2992
|
+
continue;
|
|
2993
|
+
}
|
|
2994
|
+
runLeave(entry, rect);
|
|
2995
|
+
}
|
|
2996
|
+
for (const entry of next2) {
|
|
2997
|
+
if (entry.state !== "present" || !entry.prevRect) continue;
|
|
2998
|
+
runMove(entry, entry.prevRect);
|
|
2999
|
+
entry.prevRect = void 0;
|
|
3000
|
+
}
|
|
3001
|
+
entries = next2.concat(leaving);
|
|
3002
|
+
};
|
|
3003
|
+
let pendingItems = null;
|
|
3004
|
+
const effectRunner = signals.effect(() => {
|
|
3005
|
+
const list = getList();
|
|
3006
|
+
if (!mounted) {
|
|
3007
|
+
pendingItems = list;
|
|
3008
|
+
return;
|
|
3009
|
+
}
|
|
3010
|
+
update(list, false);
|
|
3011
|
+
});
|
|
3012
|
+
onMount(() => {
|
|
3013
|
+
mounted = true;
|
|
3014
|
+
if (pendingItems) {
|
|
3015
|
+
update(pendingItems, true);
|
|
3016
|
+
pendingItems = null;
|
|
3017
|
+
}
|
|
3018
|
+
});
|
|
3019
|
+
onCleanup(() => {
|
|
3020
|
+
effectRunner.stop();
|
|
3021
|
+
for (const entry of entries) disposeEntry(entry);
|
|
3022
|
+
entries = [];
|
|
3023
|
+
if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
|
|
3024
|
+
});
|
|
3025
|
+
return wrapper;
|
|
3026
|
+
}
|
|
3027
|
+
TransitionGroup[TRANSITION_GROUP_COMPONENT] = true;
|
|
3028
|
+
function isTransitionGroup(node) {
|
|
3029
|
+
return !!node && !!node[TRANSITION_GROUP_COMPONENT];
|
|
3030
|
+
}
|
|
2145
3031
|
|
|
2146
3032
|
exports.Component = Component;
|
|
2147
3033
|
exports.For = For;
|
|
2148
3034
|
exports.Fragment = Fragment;
|
|
2149
3035
|
exports.Portal = Portal;
|
|
2150
3036
|
exports.Suspense = Suspense;
|
|
3037
|
+
exports.Transition = Transition;
|
|
3038
|
+
exports.TransitionGroup = TransitionGroup;
|
|
2151
3039
|
exports.addEvent = addEvent;
|
|
2152
3040
|
exports.addEventListener = addEventListener;
|
|
2153
3041
|
exports.beginHydration = beginHydration;
|
|
@@ -2160,11 +3048,14 @@ exports.createApp = createApp;
|
|
|
2160
3048
|
exports.createComponent = createComponent;
|
|
2161
3049
|
exports.createResource = createResource;
|
|
2162
3050
|
exports.defineAsyncComponent = defineAsyncComponent;
|
|
3051
|
+
exports.definePlugin = definePlugin;
|
|
2163
3052
|
exports.delegateEvents = delegateEvents;
|
|
2164
3053
|
exports.endHydration = endHydration;
|
|
2165
3054
|
exports.getHydrationKey = getHydrationKey;
|
|
2166
3055
|
exports.getRenderedElement = getRenderedElement;
|
|
2167
3056
|
exports.hydrate = hydrate;
|
|
3057
|
+
exports.hydrationAnchor = hydrationAnchor;
|
|
3058
|
+
exports.hydrationMarker = hydrationMarker;
|
|
2168
3059
|
exports.inject = inject;
|
|
2169
3060
|
exports.insert = insert;
|
|
2170
3061
|
exports.isComponent = isComponent;
|
|
@@ -2172,6 +3063,8 @@ exports.isFragment = isFragment;
|
|
|
2172
3063
|
exports.isHydrating = isHydrating;
|
|
2173
3064
|
exports.isPortal = isPortal;
|
|
2174
3065
|
exports.isSuspense = isSuspense;
|
|
3066
|
+
exports.isTransition = isTransition;
|
|
3067
|
+
exports.isTransitionGroup = isTransitionGroup;
|
|
2175
3068
|
exports.next = next;
|
|
2176
3069
|
exports.normalizeClass = normalizeClass;
|
|
2177
3070
|
exports.nthChild = nthChild;
|
|
@@ -2189,5 +3082,5 @@ exports.provide = provide;
|
|
|
2189
3082
|
exports.resetHydrationKey = resetHydrationKey;
|
|
2190
3083
|
exports.setStyle = setStyle;
|
|
2191
3084
|
exports.template = template;
|
|
2192
|
-
//# sourceMappingURL=template.dev.cjs.
|
|
2193
|
-
//# sourceMappingURL=template.dev.cjs.
|
|
3085
|
+
//# sourceMappingURL=template.dev.cjs.map
|
|
3086
|
+
//# sourceMappingURL=template.dev.cjs.map
|