essor 0.0.12 → 0.0.13-beta.2
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/essor.cjs.js +32 -40
- package/dist/essor.cjs.js.map +1 -1
- package/dist/essor.d.cts +1 -1
- package/dist/essor.d.ts +1 -1
- package/dist/essor.dev.cjs.js +863 -1169
- package/dist/essor.dev.esm.js +846 -1149
- package/dist/essor.esm.js +6 -11
- package/dist/essor.esm.js.map +1 -1
- package/package.json +4 -4
package/dist/essor.dev.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* essor v0.0.
|
|
2
|
+
* essor v0.0.13-beta.2
|
|
3
3
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
|
-
var essor_version = "0.0.
|
|
8
|
+
var essor_version = "0.0.13-beta.2";
|
|
9
9
|
|
|
10
10
|
// ../shared/dist/shared.js
|
|
11
11
|
var isObject = (val) => val !== null && typeof val === "object";
|
|
@@ -16,16 +16,40 @@ function isString(val) {
|
|
|
16
16
|
function isSymbol(val) {
|
|
17
17
|
return typeof val === "symbol";
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function isSet(val) {
|
|
20
|
+
return _toString.call(val) === "[object Set]";
|
|
21
|
+
}
|
|
22
|
+
function isWeakMap(val) {
|
|
23
|
+
return _toString.call(val) === "[object WeakMap]";
|
|
24
|
+
}
|
|
25
|
+
function isWeakSet(val) {
|
|
26
|
+
return _toString.call(val) === "[object WeakSet]";
|
|
27
|
+
}
|
|
28
|
+
function isMap(val) {
|
|
29
|
+
return _toString.call(val) === "[object Map]";
|
|
30
|
+
}
|
|
31
|
+
function isNil(x2) {
|
|
32
|
+
return x2 === null || x2 === void 0;
|
|
21
33
|
}
|
|
22
34
|
var isFunction = (val) => typeof val === "function";
|
|
23
|
-
function isFalsy(
|
|
24
|
-
return
|
|
35
|
+
function isFalsy(x2) {
|
|
36
|
+
return x2 === false || x2 === null || x2 === void 0;
|
|
37
|
+
}
|
|
38
|
+
var isPlainObject = (val) => _toString.call(val) === "[object Object]";
|
|
39
|
+
function isStringNumber(val) {
|
|
40
|
+
if (!isString(val)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return !Number.isNaN(Number(val));
|
|
25
44
|
}
|
|
45
|
+
var _toString = Object.prototype.toString;
|
|
46
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
47
|
+
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
26
48
|
function coerceArray(data) {
|
|
27
|
-
return
|
|
49
|
+
return isArray(data) ? data.flat() : [data];
|
|
28
50
|
}
|
|
51
|
+
var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
|
|
52
|
+
var noop = Function.prototype;
|
|
29
53
|
function startsWith(str, searchString) {
|
|
30
54
|
if (!isString(str)) {
|
|
31
55
|
return false;
|
|
@@ -50,6 +74,9 @@ function escape(str) {
|
|
|
50
74
|
}
|
|
51
75
|
});
|
|
52
76
|
}
|
|
77
|
+
function isExclude(key, exclude) {
|
|
78
|
+
return isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
|
|
79
|
+
}
|
|
53
80
|
var kebabCase = (string) => {
|
|
54
81
|
return string.replaceAll(/[A-Z]+/g, (match, offset) => {
|
|
55
82
|
return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
|
|
@@ -58,827 +85,404 @@ var kebabCase = (string) => {
|
|
|
58
85
|
var capitalizeFirstLetter = (inputString) => {
|
|
59
86
|
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
|
|
60
87
|
};
|
|
88
|
+
function warn(msg, ...args) {
|
|
89
|
+
console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
|
|
90
|
+
}
|
|
61
91
|
|
|
62
|
-
// ../signal/dist/signal.
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
for (var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (__getOwnPropSymbols)
|
|
73
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
74
|
-
if (__propIsEnum.call(b, prop))
|
|
75
|
-
__defNormalProp(a, prop, b[prop]);
|
|
76
|
-
}
|
|
77
|
-
return a;
|
|
92
|
+
// ../signal/dist/signal.esm.js
|
|
93
|
+
var ye = Object.defineProperty;
|
|
94
|
+
var U = Object.getOwnPropertySymbols;
|
|
95
|
+
var Se = Object.prototype.hasOwnProperty;
|
|
96
|
+
var me = Object.prototype.propertyIsEnumerable;
|
|
97
|
+
var Q = (e, t, n) => t in e ? ye(e, t, { enumerable: true, configurable: true, writable: true, value: n }) : e[t] = n;
|
|
98
|
+
var y = (e, t) => {
|
|
99
|
+
for (var n in t || (t = {})) Se.call(t, n) && Q(e, n, t[n]);
|
|
100
|
+
if (U) for (var n of U(t)) me.call(t, n) && Q(e, n, t[n]);
|
|
101
|
+
return e;
|
|
78
102
|
};
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return _toString.call(val) === "[object Set]";
|
|
86
|
-
}
|
|
87
|
-
function isWeakMap(val) {
|
|
88
|
-
return _toString.call(val) === "[object WeakMap]";
|
|
103
|
+
var M = [];
|
|
104
|
+
var F = [];
|
|
105
|
+
var X = Promise.resolve();
|
|
106
|
+
var K = false;
|
|
107
|
+
function C(e) {
|
|
108
|
+
return e ? X.then(e) : X;
|
|
89
109
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
function isMap(val) {
|
|
94
|
-
return _toString.call(val) === "[object Map]";
|
|
110
|
+
function ge(e) {
|
|
111
|
+
M.includes(e) || (M.push(e), Y());
|
|
95
112
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function isStringNumber(val) {
|
|
99
|
-
if (!isString2(val)) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
return !Number.isNaN(Number(val));
|
|
113
|
+
function Y() {
|
|
114
|
+
K || (K = true, C(ve));
|
|
103
115
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
107
|
-
var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
|
|
108
|
-
var noop2 = Function.prototype;
|
|
109
|
-
function isExclude(key, exclude) {
|
|
110
|
-
return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
|
|
116
|
+
function _e(e) {
|
|
117
|
+
xe(e, F);
|
|
111
118
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
119
|
+
function xe(e, t) {
|
|
120
|
+
t.includes(e) || (t.push(e), Y());
|
|
114
121
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function nextTick(fn) {
|
|
120
|
-
return fn ? p.then(fn) : p;
|
|
122
|
+
function ve() {
|
|
123
|
+
K = false, we();
|
|
124
|
+
let e;
|
|
125
|
+
for (; e = M.shift(); ) e && e();
|
|
121
126
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
function we() {
|
|
128
|
+
for (; F.length > 0; ) {
|
|
129
|
+
let e = F.shift();
|
|
130
|
+
e && e();
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
isFlushPending = true;
|
|
133
|
-
nextTick(flushJobs);
|
|
134
|
-
}
|
|
135
|
-
function queuePreFlushCb(cb) {
|
|
136
|
-
queueCb(cb, activePreFlushCbs);
|
|
137
|
-
}
|
|
138
|
-
function queueCb(cb, activeQueue) {
|
|
139
|
-
if (!activeQueue.includes(cb)) {
|
|
140
|
-
activeQueue.push(cb);
|
|
141
|
-
queueFlush();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function flushJobs() {
|
|
145
|
-
isFlushPending = false;
|
|
146
|
-
flushPreFlushCbs();
|
|
147
|
-
let job;
|
|
148
|
-
while (job = queue.shift()) {
|
|
149
|
-
if (job) {
|
|
150
|
-
job();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
133
|
+
function Z(e, t) {
|
|
134
|
+
return t === "sync" ? () => e() : t === "pre" ? () => _e(e) : () => {
|
|
135
|
+
C(() => ge(e));
|
|
136
|
+
};
|
|
153
137
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
138
|
+
var T = null;
|
|
139
|
+
var G = /* @__PURE__ */ new WeakMap();
|
|
140
|
+
var H = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
var _ = Symbol("");
|
|
142
|
+
var x = Symbol("");
|
|
143
|
+
var te = Symbol("");
|
|
144
|
+
var ne = Symbol("");
|
|
145
|
+
var $ = Symbol("");
|
|
146
|
+
var f = Symbol("");
|
|
147
|
+
var S = Symbol("");
|
|
148
|
+
var D = false;
|
|
149
|
+
var E = /* @__PURE__ */ new Set();
|
|
150
|
+
function u(e, t) {
|
|
151
|
+
if (!T) return;
|
|
152
|
+
let n = G.get(e);
|
|
153
|
+
n || (n = /* @__PURE__ */ new Map(), G.set(e, n));
|
|
154
|
+
let o = n.get(t);
|
|
155
|
+
o || (o = /* @__PURE__ */ new Set(), n.set(t, o)), T && o.add(T);
|
|
156
|
+
}
|
|
157
|
+
function p(e, t) {
|
|
158
|
+
let n = G.get(e);
|
|
159
|
+
if (!n) return;
|
|
160
|
+
let o = n.get(t);
|
|
161
|
+
o && o.forEach((r) => {
|
|
162
|
+
if (hasOwn(r, "active") && !r.active) {
|
|
163
|
+
o.delete(r);
|
|
164
|
+
return;
|
|
159
165
|
}
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
var activeEffect = null;
|
|
163
|
-
var activeComputed = null;
|
|
164
|
-
var triggerMap = /* @__PURE__ */ new WeakMap();
|
|
165
|
-
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
166
|
-
var ReactiveSymbol = Symbol("ReactiveSymbol");
|
|
167
|
-
var ReactivePeekSymbol = Symbol("__raw");
|
|
168
|
-
var SignalValueKey = Symbol("SignalValueKey");
|
|
169
|
-
var ComputedValueKey = Symbol("ComputedValueKey");
|
|
170
|
-
var reactiveArrayKey = Symbol("ReactiveArrayKey");
|
|
171
|
-
var ReactiveCollectionKey = Symbol("ReactiveCollectionKey");
|
|
172
|
-
var ReactiveWeakCollectionKey = Symbol("ReactiveWeakCollectionKey");
|
|
173
|
-
var inBatch = false;
|
|
174
|
-
var batchQueue = /* @__PURE__ */ new Set();
|
|
175
|
-
function track(target, key) {
|
|
176
|
-
if (!activeEffect && !activeComputed) return;
|
|
177
|
-
let depsMap = triggerMap.get(target);
|
|
178
|
-
if (!depsMap) {
|
|
179
|
-
depsMap = /* @__PURE__ */ new Map();
|
|
180
|
-
triggerMap.set(target, depsMap);
|
|
181
|
-
}
|
|
182
|
-
let dep = depsMap.get(key);
|
|
183
|
-
if (!dep) {
|
|
184
|
-
dep = /* @__PURE__ */ new Set();
|
|
185
|
-
depsMap.set(key, dep);
|
|
186
|
-
}
|
|
187
|
-
if (activeEffect) dep.add(activeEffect);
|
|
188
|
-
}
|
|
189
|
-
function trigger(target, key) {
|
|
190
|
-
const depsMap = triggerMap.get(target);
|
|
191
|
-
if (!depsMap) return;
|
|
192
|
-
const dep = depsMap.get(key);
|
|
193
|
-
if (dep) {
|
|
194
|
-
dep.forEach((effect) => {
|
|
195
|
-
if (hasOwn(effect, "active") && !effect.active) {
|
|
196
|
-
dep.delete(effect);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (inBatch) {
|
|
200
|
-
batchQueue.add(effect);
|
|
201
|
-
} else {
|
|
202
|
-
effect();
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
166
|
+
D ? E.add(r) : r();
|
|
167
|
+
});
|
|
206
168
|
}
|
|
207
|
-
var
|
|
208
|
-
|
|
209
|
-
* Creates a new Signal instance.
|
|
210
|
-
* @param {T} value - The initial value of the Signal.
|
|
211
|
-
* @param {boolean} [shallow] - Whether to create a shallow Signal.
|
|
212
|
-
*/
|
|
213
|
-
constructor(value, shallow = false) {
|
|
169
|
+
var j = class {
|
|
170
|
+
constructor(t, n = false) {
|
|
214
171
|
this.__signal = true;
|
|
215
|
-
this.
|
|
216
|
-
this._value = value;
|
|
172
|
+
this.__shallow = n, this.__value = t;
|
|
217
173
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Gets the current value of the Signal.
|
|
220
|
-
* @returns {T} The current value.
|
|
221
|
-
*/
|
|
222
174
|
get value() {
|
|
223
|
-
|
|
224
|
-
if (isObject2(this._value) && !this._shallow) {
|
|
225
|
-
return useReactive(this._value);
|
|
226
|
-
}
|
|
227
|
-
return this._value;
|
|
175
|
+
return u(this, te), isObject(this.__value) && !this.__shallow ? v(this.__value) : this.__value;
|
|
228
176
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
* @param {T} newValue - The new value to set.
|
|
232
|
-
*/
|
|
233
|
-
set value(newValue) {
|
|
234
|
-
if (isSignal(newValue)) {
|
|
235
|
-
newValue = newValue.peek();
|
|
236
|
-
}
|
|
237
|
-
if (hasChanged(newValue, this._value)) {
|
|
238
|
-
this._value = newValue;
|
|
239
|
-
trigger(this, SignalValueKey);
|
|
240
|
-
}
|
|
177
|
+
set value(t) {
|
|
178
|
+
h(t) && (t = t.peek()), hasChanged(t, this.__value) && (this.__value = t, p(this, te));
|
|
241
179
|
}
|
|
242
|
-
/**
|
|
243
|
-
* Returns the current value without triggering reactivity.
|
|
244
|
-
* @returns {T} The current value.
|
|
245
|
-
*/
|
|
246
180
|
peek() {
|
|
247
|
-
return this.
|
|
181
|
+
return this.__value;
|
|
248
182
|
}
|
|
249
183
|
};
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
return value;
|
|
253
|
-
}
|
|
254
|
-
return new Signal(value);
|
|
184
|
+
function le(e) {
|
|
185
|
+
return h(e) ? e : new j(e);
|
|
255
186
|
}
|
|
256
|
-
function
|
|
257
|
-
return new
|
|
187
|
+
function Re(e) {
|
|
188
|
+
return new j(e, true);
|
|
258
189
|
}
|
|
259
|
-
function
|
|
260
|
-
return !!(
|
|
190
|
+
function h(e) {
|
|
191
|
+
return !!(e && (e != null && e.__signal));
|
|
261
192
|
}
|
|
262
|
-
var
|
|
263
|
-
constructor(
|
|
264
|
-
this.fn =
|
|
193
|
+
var V = class {
|
|
194
|
+
constructor(t) {
|
|
195
|
+
this.fn = t;
|
|
265
196
|
this.__computed = true;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this._value = this.fn();
|
|
269
|
-
activeEffect = prev;
|
|
197
|
+
let n = T;
|
|
198
|
+
T = this.run.bind(this), this.__value = this.fn(), T = n;
|
|
270
199
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Get the current computed value without tracking it.
|
|
273
|
-
*/
|
|
274
200
|
peek() {
|
|
275
|
-
return this.
|
|
201
|
+
return this.__value;
|
|
276
202
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Run the computed function and update the value if it has changed.
|
|
279
|
-
*/
|
|
280
203
|
run() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
this._value = newValue;
|
|
284
|
-
trigger(this, ComputedValueKey);
|
|
285
|
-
}
|
|
204
|
+
let t = this.fn();
|
|
205
|
+
hasChanged(t, this.__value) && (this.__value = t, p(this, ne));
|
|
286
206
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Get the current computed value and track its usage.
|
|
289
|
-
*/
|
|
290
207
|
get value() {
|
|
291
|
-
|
|
292
|
-
return this._value;
|
|
208
|
+
return u(this, ne), this.__value;
|
|
293
209
|
}
|
|
294
210
|
};
|
|
295
|
-
function
|
|
296
|
-
return new
|
|
211
|
+
function z(e) {
|
|
212
|
+
return new V(e);
|
|
297
213
|
}
|
|
298
|
-
function
|
|
299
|
-
return !!(
|
|
214
|
+
function I(e) {
|
|
215
|
+
return !!(e && e.__computed);
|
|
300
216
|
}
|
|
301
|
-
function
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} else {
|
|
307
|
-
return () => {
|
|
308
|
-
nextTick(() => queueJob(effect));
|
|
309
|
-
};
|
|
217
|
+
function B(e, t = {}) {
|
|
218
|
+
let { flush: n = "pre", onTrack: o, onTrigger: r } = t;
|
|
219
|
+
function s() {
|
|
220
|
+
let d = T;
|
|
221
|
+
T = s.init ? s : s.scheduler, e(), r && r(), T = d;
|
|
310
222
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
function effectFn() {
|
|
315
|
-
const prev = activeEffect;
|
|
316
|
-
activeEffect = effectFn.init ? effectFn : effectFn.scheduler;
|
|
317
|
-
fn();
|
|
318
|
-
onTrigger && onTrigger();
|
|
319
|
-
activeEffect = prev;
|
|
320
|
-
}
|
|
321
|
-
const scheduler = createScheduler(effectFn, flush);
|
|
322
|
-
effectFn.scheduler = scheduler;
|
|
323
|
-
effectFn.init = true;
|
|
324
|
-
effectFn.active = true;
|
|
325
|
-
onTrack && onTrack();
|
|
326
|
-
effectFn();
|
|
327
|
-
return () => {
|
|
328
|
-
effectFn.active = false;
|
|
329
|
-
activeEffect = null;
|
|
223
|
+
let i = Z(s, n);
|
|
224
|
+
return s.scheduler = i, s.init = true, s.active = true, o && o(), s(), () => {
|
|
225
|
+
s.active = false, T = null;
|
|
330
226
|
};
|
|
331
227
|
}
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
function shallowReactive(initialValue, exclude) {
|
|
372
|
-
return reactive(initialValue, true, exclude);
|
|
373
|
-
}
|
|
374
|
-
function unReactive(target) {
|
|
375
|
-
if (!isObject2(target)) {
|
|
376
|
-
return target;
|
|
377
|
-
}
|
|
378
|
-
if (!isReactive(target)) {
|
|
379
|
-
return target;
|
|
380
|
-
}
|
|
381
|
-
return target[ReactivePeekSymbol];
|
|
382
|
-
}
|
|
383
|
-
var basicHandler = (shallow, exclude) => {
|
|
384
|
-
return {
|
|
385
|
-
get(target, key, receiver) {
|
|
386
|
-
if (key === ReactiveSymbol) return true;
|
|
387
|
-
if (key === ReactivePeekSymbol) return target;
|
|
388
|
-
const getValue = Reflect.get(target, key, receiver);
|
|
389
|
-
const value = isSignal(getValue) ? getValue.value : getValue;
|
|
390
|
-
if (isExclude(key, exclude)) {
|
|
391
|
-
return value;
|
|
392
|
-
}
|
|
393
|
-
track(target, key);
|
|
394
|
-
if (isObject2(value) && !shallow) {
|
|
395
|
-
return useReactive(value);
|
|
396
|
-
}
|
|
397
|
-
return value;
|
|
398
|
-
},
|
|
399
|
-
set(target, key, value, receiver) {
|
|
400
|
-
if (isExclude(key, exclude)) {
|
|
401
|
-
Reflect.set(target, key, value, receiver);
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
let oldValue = Reflect.get(target, key, receiver);
|
|
405
|
-
if (isSignal(oldValue)) {
|
|
406
|
-
oldValue = oldValue.value;
|
|
407
|
-
}
|
|
408
|
-
if (isSignal(value)) {
|
|
409
|
-
value = value.value;
|
|
410
|
-
}
|
|
411
|
-
const obj = Reflect.set(target, key, value, receiver);
|
|
412
|
-
if (hasChanged(value, oldValue)) {
|
|
413
|
-
trigger(target, key);
|
|
414
|
-
}
|
|
415
|
-
return obj;
|
|
416
|
-
},
|
|
417
|
-
// handle delete
|
|
418
|
-
deleteProperty(target, key) {
|
|
419
|
-
const oldValue = Reflect.get(target, key);
|
|
420
|
-
const result = Reflect.deleteProperty(target, key);
|
|
421
|
-
if (oldValue !== void 0) {
|
|
422
|
-
trigger(target, key);
|
|
423
|
-
}
|
|
424
|
-
return result;
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
var arrayInstrumentations = createArrayInstrumentations();
|
|
429
|
-
function createArrayInstrumentations() {
|
|
430
|
-
const instrumentations2 = {};
|
|
431
|
-
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
432
|
-
instrumentations2[key] = function(...args) {
|
|
433
|
-
const arr = this;
|
|
434
|
-
for (let i = 0, l = this.length; i < l; i++) {
|
|
435
|
-
track(arr, `${i}`);
|
|
436
|
-
}
|
|
437
|
-
const res = arr[key](...args);
|
|
438
|
-
if (res === -1 || res === false) {
|
|
439
|
-
return arr[key](...args);
|
|
440
|
-
}
|
|
441
|
-
return res;
|
|
228
|
+
function We(e, t) {
|
|
229
|
+
return !e || !isObject(e) ? e : Object.entries(e).reduce((o, [r, s]) => (o[r] = isExclude(r, t) || h(s) ? s : le(s), o), {});
|
|
230
|
+
}
|
|
231
|
+
function c(e) {
|
|
232
|
+
return e && (b(e) ? e[x] : h(e) ? e.peek() : isArray(e) ? e.map((t) => c(t)) : isPlainObject(e) ? Object.fromEntries(Object.entries(e).map(([t, n]) => [t, c(n)])) : e);
|
|
233
|
+
}
|
|
234
|
+
function b(e) {
|
|
235
|
+
return !!(e && typeof e == "object" && e[_]);
|
|
236
|
+
}
|
|
237
|
+
function L(e, t) {
|
|
238
|
+
return v(e, false, t);
|
|
239
|
+
}
|
|
240
|
+
function Ce(e, t) {
|
|
241
|
+
return v(e, true, t);
|
|
242
|
+
}
|
|
243
|
+
var Ee = (e, t) => ({ get(n, o, r) {
|
|
244
|
+
if (o === _) return true;
|
|
245
|
+
if (o === x) return n;
|
|
246
|
+
let s = Reflect.get(n, o, r), i = h(s) ? s.value : s;
|
|
247
|
+
return isExclude(o, t) ? i : (u(n, o), isObject(i) && !e ? v(i) : i);
|
|
248
|
+
}, set(n, o, r, s) {
|
|
249
|
+
if (isExclude(o, t)) return Reflect.set(n, o, r, s), true;
|
|
250
|
+
let i = Reflect.get(n, o, s);
|
|
251
|
+
h(i) && (i = i.value), h(r) && (r = r.value);
|
|
252
|
+
let d = Reflect.set(n, o, r, s);
|
|
253
|
+
return hasChanged(r, i) && p(n, o), d;
|
|
254
|
+
}, deleteProperty(n, o) {
|
|
255
|
+
let r = Reflect.get(n, o), s = Reflect.deleteProperty(n, o);
|
|
256
|
+
return r !== void 0 && p(n, o), s;
|
|
257
|
+
} });
|
|
258
|
+
var oe = Pe();
|
|
259
|
+
function Pe() {
|
|
260
|
+
let e = {};
|
|
261
|
+
return ["includes", "indexOf", "lastIndexOf"].forEach((t) => {
|
|
262
|
+
e[t] = function(...n) {
|
|
263
|
+
let o = c(this);
|
|
264
|
+
for (let s = 0, i = this.length; s < i; s++) u(o, `${s}`);
|
|
265
|
+
let r = o[t](...n);
|
|
266
|
+
return r === -1 || r === false ? o[t](...n) : r;
|
|
442
267
|
};
|
|
443
|
-
})
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
[
|
|
455
|
-
"forEach",
|
|
456
|
-
"map",
|
|
457
|
-
"filter",
|
|
458
|
-
"reduce",
|
|
459
|
-
"reduceRight",
|
|
460
|
-
"some",
|
|
461
|
-
"every",
|
|
462
|
-
"find",
|
|
463
|
-
"findIndex",
|
|
464
|
-
"findLast",
|
|
465
|
-
"findLastIndex",
|
|
466
|
-
"entries",
|
|
467
|
-
"keys",
|
|
468
|
-
"values"
|
|
469
|
-
].forEach((key) => {
|
|
470
|
-
instrumentations2[key] = function(...args) {
|
|
471
|
-
const arr = unReactive(this);
|
|
472
|
-
track(arr, reactiveArrayKey);
|
|
473
|
-
return arr[key].apply(this, args);
|
|
268
|
+
}), ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((t) => {
|
|
269
|
+
e[t] = function(...n) {
|
|
270
|
+
let o = c(this), r = o[t].apply(this, n);
|
|
271
|
+
return p(o, $), r;
|
|
272
|
+
};
|
|
273
|
+
}), ["forEach", "map", "filter", "reduce", "reduceRight", "some", "every", "find", "findIndex", "findLast", "findLastIndex", "entries", "keys", "values"].forEach((t) => {
|
|
274
|
+
e[t] = function(...n) {
|
|
275
|
+
let o = c(this);
|
|
276
|
+
return u(o, $), o[t].apply(this, n);
|
|
474
277
|
};
|
|
278
|
+
}), e;
|
|
279
|
+
}
|
|
280
|
+
var je = (e, t) => ({ get(n, o, r) {
|
|
281
|
+
if (o === _) return true;
|
|
282
|
+
if (o === x) return n;
|
|
283
|
+
if (oe.hasOwnProperty(o)) return Reflect.get(oe, o, r);
|
|
284
|
+
let s = Reflect.get(n, o, r);
|
|
285
|
+
return isExclude(o, t) ? s : (isStringNumber(o) && u(n, o), u(n, "length"), isObject(s) && !e ? v(s) : s);
|
|
286
|
+
}, set(n, o, r, s) {
|
|
287
|
+
let i = Reflect.get(n, o, s), d = Reflect.set(n, o, r, s);
|
|
288
|
+
return hasChanged(r, i) && (isStringNumber(o) && p(n, o), (o === "length" || !i) && p(n, "length")), d;
|
|
289
|
+
} });
|
|
290
|
+
var Ae = { get(e, t) {
|
|
291
|
+
return t === _ ? true : t === x ? e : ((t === Symbol.iterator || t === "size") && u(e, f), Reflect.get(hasOwn(re, t) && t in e ? re : e, t, e));
|
|
292
|
+
} };
|
|
293
|
+
var Ie = { get(e, t) {
|
|
294
|
+
return t === _ ? true : t === x ? e : Reflect.get(hasOwn(se, t) && t in e ? se : e, t, e);
|
|
295
|
+
} };
|
|
296
|
+
var re = { get(e) {
|
|
297
|
+
let t = c(this);
|
|
298
|
+
return u(t, f), t.get(e);
|
|
299
|
+
}, set(e, t) {
|
|
300
|
+
let n = c(this), o = n.set(e, t);
|
|
301
|
+
return p(n, f), o;
|
|
302
|
+
}, add(e) {
|
|
303
|
+
let t = c(this), n = t.add(e);
|
|
304
|
+
return p(t, f), n;
|
|
305
|
+
}, has(e) {
|
|
306
|
+
let t = c(this);
|
|
307
|
+
return u(t, f), t.has(e);
|
|
308
|
+
}, delete(e) {
|
|
309
|
+
let t = c(this), n = t.has(e), o = t.delete(e);
|
|
310
|
+
return n && p(t, f), o;
|
|
311
|
+
}, clear() {
|
|
312
|
+
let e = c(this), t = e.size > 0, n = e.clear();
|
|
313
|
+
return t && p(e, f), n;
|
|
314
|
+
}, forEach(e, t) {
|
|
315
|
+
let n = c(this);
|
|
316
|
+
u(n, f), n.forEach((o, r) => {
|
|
317
|
+
e.call(t, o, r, n);
|
|
475
318
|
});
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
319
|
+
}, get size() {
|
|
320
|
+
let e = c(this);
|
|
321
|
+
return u(e, f), e.size;
|
|
322
|
+
}, keys() {
|
|
323
|
+
let e = c(this);
|
|
324
|
+
return u(e, f), e.keys();
|
|
325
|
+
}, values() {
|
|
326
|
+
let e = c(this);
|
|
327
|
+
return u(e, f), e.values();
|
|
328
|
+
}, entries() {
|
|
329
|
+
let e = c(this);
|
|
330
|
+
return u(e, f), e.entries();
|
|
331
|
+
}, [Symbol.iterator]() {
|
|
332
|
+
let e = c(this);
|
|
333
|
+
return u(e, f), e[Symbol.iterator]();
|
|
334
|
+
} };
|
|
335
|
+
var se = { get(e) {
|
|
336
|
+
let t = c(this);
|
|
337
|
+
return u(t, S), t.get(e);
|
|
338
|
+
}, set(e, t) {
|
|
339
|
+
let n = c(this), o = n.set(e, t);
|
|
340
|
+
return p(n, S), o;
|
|
341
|
+
}, add(e) {
|
|
342
|
+
let t = c(this), n = t.add(e);
|
|
343
|
+
return p(t, S), n;
|
|
344
|
+
}, has(e) {
|
|
345
|
+
let t = c(this);
|
|
346
|
+
return u(t, S), t.has(e);
|
|
347
|
+
}, delete(e) {
|
|
348
|
+
let t = c(this), n = t.delete(e);
|
|
349
|
+
return p(t, S), n;
|
|
350
|
+
} };
|
|
351
|
+
function v(e, t = false, n) {
|
|
352
|
+
if (!isObject(e) || b(e)) return e;
|
|
353
|
+
if (H.has(e)) return H.get(e);
|
|
354
|
+
let o;
|
|
355
|
+
isArray(e) ? (u(e, $), o = je(t, n)) : isSet(e) || isMap(e) ? (u(e, f), o = Ae) : isWeakSet(e) || isWeakMap(e) ? (u(e, S), o = Ie) : o = Ee(t, n);
|
|
356
|
+
let r = new Proxy(e, o);
|
|
357
|
+
return H.set(e, r), r;
|
|
358
|
+
}
|
|
359
|
+
function Oe(e) {
|
|
360
|
+
b(e) && (isWeakMap(e) || isWeakSet(e) || fe(() => {
|
|
361
|
+
isArray(e) ? e.length = 0 : isSet(e) || isMap(e) ? e.clear() : isObject(e) && Object.keys(e).forEach((t) => {
|
|
362
|
+
delete e[t];
|
|
363
|
+
});
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
function fe(e) {
|
|
367
|
+
try {
|
|
368
|
+
D = true, e();
|
|
369
|
+
} finally {
|
|
370
|
+
D = false, Me();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function Me() {
|
|
374
|
+
E.size > 0 && (E.forEach((e) => e()), E.clear());
|
|
375
|
+
}
|
|
376
|
+
function De(e, t, n) {
|
|
377
|
+
return Je(e, t, n);
|
|
378
|
+
}
|
|
379
|
+
var pe = void 0;
|
|
380
|
+
var w;
|
|
381
|
+
var N = false;
|
|
382
|
+
function Ve(e) {
|
|
383
|
+
w = e, N || (N = true, C(qe));
|
|
384
|
+
}
|
|
385
|
+
function qe() {
|
|
386
|
+
w == null || w(), w = null, N = false;
|
|
387
|
+
}
|
|
388
|
+
function Je(e, t, { deep: n, immediate: o } = {}) {
|
|
389
|
+
let r, s = isArray(e);
|
|
390
|
+
if (h(e) || I(e)) r = () => e.value;
|
|
391
|
+
else if (b(e)) r = () => y({}, e);
|
|
392
|
+
else if (s) r = () => e.map((a) => ze(a));
|
|
393
|
+
else if (isFunction(e)) r = e;
|
|
394
|
+
else return warn("Invalid source type", e), noop;
|
|
395
|
+
if (t && n) {
|
|
396
|
+
let a = r, l = n === true ? 1 / 0 : n;
|
|
397
|
+
r = () => k(a(), l);
|
|
398
|
+
}
|
|
399
|
+
let i = s ? Array.from({ length: e.length }).fill(pe) : pe, d = false, O = () => {
|
|
400
|
+
let a = r();
|
|
401
|
+
hasChanged(a, i) && (o && t && (t(a, i), i = a), d && t && Ve(() => {
|
|
402
|
+
t(a, i), i = a;
|
|
403
|
+
}), !d && (i = a));
|
|
404
|
+
}, g = B(O, { flush: "sync" });
|
|
405
|
+
return d = true, o && O(), g;
|
|
406
|
+
}
|
|
407
|
+
function ze(e) {
|
|
408
|
+
return h(e) || I(e) ? e.value : b(e) ? y({}, e) : isFunction(e) ? e() : (warn("Invalid source", e), noop);
|
|
409
|
+
}
|
|
410
|
+
function k(e, t = 1 / 0, n) {
|
|
411
|
+
if (t <= 0 || !isObject(e) || (n = n || /* @__PURE__ */ new Set(), n.has(e))) return e;
|
|
412
|
+
if (n.add(e), t--, h(e)) k(e.value, t, n);
|
|
413
|
+
else if (isArray(e)) for (let o of e) k(o, t, n);
|
|
414
|
+
else if (isSet(e) || isMap(e)) e.forEach((o) => {
|
|
415
|
+
k(o, t, n);
|
|
416
|
+
});
|
|
417
|
+
else if (isPlainObject(e)) for (let o in e) k(e[o], t, n);
|
|
418
|
+
return e;
|
|
419
|
+
}
|
|
420
|
+
function Be(e) {
|
|
421
|
+
let { state: t, getters: n, actions: o } = e, r = y({}, t != null ? t : {}), s = L(t != null ? t : {}), i = [], d = [], g = y({ state: s }, { patch$(a) {
|
|
422
|
+
Object.assign(s, a), i.forEach((l) => l(s)), d.forEach((l) => l(s));
|
|
423
|
+
}, subscribe$(a) {
|
|
424
|
+
i.push(a);
|
|
425
|
+
}, unsubscribe$(a) {
|
|
426
|
+
let l = i.indexOf(a);
|
|
427
|
+
l !== -1 && i.splice(l, 1);
|
|
428
|
+
}, onAction$(a) {
|
|
429
|
+
d.push(a);
|
|
430
|
+
}, reset$() {
|
|
431
|
+
Object.assign(s, r);
|
|
432
|
+
} });
|
|
433
|
+
for (let a in n) {
|
|
434
|
+
let l = n[a];
|
|
435
|
+
l && Object.defineProperty(g, a, { get() {
|
|
436
|
+
return z(l.bind(s, s)).value;
|
|
437
|
+
}, enumerable: true, configurable: true });
|
|
438
|
+
}
|
|
439
|
+
for (let a in o) {
|
|
440
|
+
let l = o[a];
|
|
441
|
+
l && (g[a] = l.bind(s));
|
|
442
|
+
}
|
|
443
|
+
return g;
|
|
444
|
+
}
|
|
445
|
+
function Le(e) {
|
|
446
|
+
return function() {
|
|
447
|
+
return Be(e);
|
|
512
448
|
};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
return Reflect.get(
|
|
522
|
-
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
523
|
-
key,
|
|
524
|
-
target
|
|
525
|
-
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// ../template/dist/template.dev.esm.js
|
|
452
|
+
var componentMap = /* @__PURE__ */ new Map();
|
|
453
|
+
var RenderContext = class {
|
|
454
|
+
constructor() {
|
|
455
|
+
this.renderMode = 0;
|
|
526
456
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
get(target, key) {
|
|
530
|
-
if (key === ReactiveSymbol) return true;
|
|
531
|
-
if (key === ReactivePeekSymbol) return target;
|
|
532
|
-
return Reflect.get(
|
|
533
|
-
hasOwn(weakInstrumentations, key) && key in target ? weakInstrumentations : target,
|
|
534
|
-
key,
|
|
535
|
-
target
|
|
536
|
-
);
|
|
457
|
+
get isSSG() {
|
|
458
|
+
return this.renderMode === 1;
|
|
537
459
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
get(key) {
|
|
541
|
-
const target = unReactive(this);
|
|
542
|
-
track(target, ReactiveCollectionKey);
|
|
543
|
-
return target.get(key);
|
|
544
|
-
},
|
|
545
|
-
set(key, value) {
|
|
546
|
-
const target = unReactive(this);
|
|
547
|
-
const result = target.set(key, value);
|
|
548
|
-
trigger(target, ReactiveCollectionKey);
|
|
549
|
-
return result;
|
|
550
|
-
},
|
|
551
|
-
add(value) {
|
|
552
|
-
const target = unReactive(this);
|
|
553
|
-
const result = target.add(value);
|
|
554
|
-
trigger(target, ReactiveCollectionKey);
|
|
555
|
-
return result;
|
|
556
|
-
},
|
|
557
|
-
has(key) {
|
|
558
|
-
const target = unReactive(this);
|
|
559
|
-
track(target, ReactiveCollectionKey);
|
|
560
|
-
return target.has(key);
|
|
561
|
-
},
|
|
562
|
-
delete(key) {
|
|
563
|
-
const target = unReactive(this);
|
|
564
|
-
const hadKey = target.has(key);
|
|
565
|
-
const result = target.delete(key);
|
|
566
|
-
if (hadKey) {
|
|
567
|
-
trigger(target, ReactiveCollectionKey);
|
|
568
|
-
}
|
|
569
|
-
return result;
|
|
570
|
-
},
|
|
571
|
-
clear() {
|
|
572
|
-
const target = unReactive(this);
|
|
573
|
-
const hadItems = target.size > 0;
|
|
574
|
-
const result = target.clear();
|
|
575
|
-
if (hadItems) {
|
|
576
|
-
trigger(target, ReactiveCollectionKey);
|
|
577
|
-
}
|
|
578
|
-
return result;
|
|
579
|
-
},
|
|
580
|
-
forEach(callback, thisArg) {
|
|
581
|
-
const target = unReactive(this);
|
|
582
|
-
track(target, ReactiveCollectionKey);
|
|
583
|
-
target.forEach((value, key) => {
|
|
584
|
-
callback.call(thisArg, value, key, target);
|
|
585
|
-
});
|
|
586
|
-
},
|
|
587
|
-
get size() {
|
|
588
|
-
const target = unReactive(this);
|
|
589
|
-
track(target, ReactiveCollectionKey);
|
|
590
|
-
return target.size;
|
|
591
|
-
},
|
|
592
|
-
keys() {
|
|
593
|
-
const target = unReactive(this);
|
|
594
|
-
track(target, ReactiveCollectionKey);
|
|
595
|
-
return target.keys();
|
|
596
|
-
},
|
|
597
|
-
values() {
|
|
598
|
-
const target = unReactive(this);
|
|
599
|
-
track(target, ReactiveCollectionKey);
|
|
600
|
-
return target.values();
|
|
601
|
-
},
|
|
602
|
-
entries() {
|
|
603
|
-
const target = unReactive(this);
|
|
604
|
-
track(target, ReactiveCollectionKey);
|
|
605
|
-
return target.entries();
|
|
606
|
-
},
|
|
607
|
-
[Symbol.iterator]() {
|
|
608
|
-
const target = unReactive(this);
|
|
609
|
-
track(target, ReactiveCollectionKey);
|
|
610
|
-
return target[Symbol.iterator]();
|
|
460
|
+
get isSSR() {
|
|
461
|
+
return this.renderMode === 2;
|
|
611
462
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
get(key) {
|
|
615
|
-
const target = unReactive(this);
|
|
616
|
-
track(target, ReactiveWeakCollectionKey);
|
|
617
|
-
return target.get(key);
|
|
618
|
-
},
|
|
619
|
-
set(key, value) {
|
|
620
|
-
const target = unReactive(this);
|
|
621
|
-
const result = target.set(key, value);
|
|
622
|
-
trigger(target, ReactiveWeakCollectionKey);
|
|
623
|
-
return result;
|
|
624
|
-
},
|
|
625
|
-
add(value) {
|
|
626
|
-
const target = unReactive(this);
|
|
627
|
-
const result = target.add(value);
|
|
628
|
-
trigger(target, ReactiveWeakCollectionKey);
|
|
629
|
-
return result;
|
|
630
|
-
},
|
|
631
|
-
has(key) {
|
|
632
|
-
const target = unReactive(this);
|
|
633
|
-
track(target, ReactiveWeakCollectionKey);
|
|
634
|
-
return target.has(key);
|
|
635
|
-
},
|
|
636
|
-
delete(key) {
|
|
637
|
-
const target = unReactive(this);
|
|
638
|
-
const result = target.delete(key);
|
|
639
|
-
trigger(target, ReactiveWeakCollectionKey);
|
|
640
|
-
return result;
|
|
463
|
+
get isClient() {
|
|
464
|
+
return this.renderMode === 0;
|
|
641
465
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
if (!isObject2(initialValue)) {
|
|
645
|
-
return initialValue;
|
|
646
|
-
}
|
|
647
|
-
if (isReactive(initialValue)) {
|
|
648
|
-
return initialValue;
|
|
649
|
-
}
|
|
650
|
-
if (reactiveMap.has(initialValue)) {
|
|
651
|
-
return reactiveMap.get(initialValue);
|
|
652
|
-
}
|
|
653
|
-
let handler;
|
|
654
|
-
if (isArray2(initialValue)) {
|
|
655
|
-
track(initialValue, reactiveArrayKey);
|
|
656
|
-
handler = ArrayHandler(shallow, exclude);
|
|
657
|
-
} else if (isSet(initialValue) || isMap(initialValue)) {
|
|
658
|
-
track(initialValue, ReactiveCollectionKey);
|
|
659
|
-
handler = collectionHandlers;
|
|
660
|
-
} else if (isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
661
|
-
track(initialValue, ReactiveWeakCollectionKey);
|
|
662
|
-
handler = weakCollectionHandlers;
|
|
663
|
-
} else {
|
|
664
|
-
handler = basicHandler(shallow, exclude);
|
|
466
|
+
setSSR() {
|
|
467
|
+
this.renderMode = 2;
|
|
665
468
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
return proxy;
|
|
669
|
-
}
|
|
670
|
-
function clearReactive(reactiveObj) {
|
|
671
|
-
if (!isReactive(reactiveObj)) {
|
|
672
|
-
{
|
|
673
|
-
warn("clearReactive: argument must be a reactive object");
|
|
674
|
-
}
|
|
675
|
-
return;
|
|
469
|
+
setSSG() {
|
|
470
|
+
this.renderMode = 1;
|
|
676
471
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
warn("clearReactive: WeakMap and WeakSet are not clearable");
|
|
680
|
-
}
|
|
681
|
-
return;
|
|
472
|
+
setClient() {
|
|
473
|
+
this.renderMode = 0;
|
|
682
474
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
} else if (isObject2(reactiveObj)) {
|
|
689
|
-
Object.keys(reactiveObj).forEach((key) => {
|
|
690
|
-
delete reactiveObj[key];
|
|
691
|
-
});
|
|
692
|
-
}
|
|
475
|
+
};
|
|
476
|
+
var renderContext = new RenderContext();
|
|
477
|
+
function enterComponent(temp, index) {
|
|
478
|
+
componentMap.set(temp, {
|
|
479
|
+
index
|
|
693
480
|
});
|
|
694
481
|
}
|
|
695
|
-
function
|
|
696
|
-
|
|
697
|
-
inBatch = true;
|
|
698
|
-
fn();
|
|
699
|
-
} finally {
|
|
700
|
-
inBatch = false;
|
|
701
|
-
runBatch();
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function runBatch() {
|
|
705
|
-
if (batchQueue.size > 0) {
|
|
706
|
-
batchQueue.forEach((effect) => effect());
|
|
707
|
-
batchQueue.clear();
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
function useWatch(source, cb, options) {
|
|
711
|
-
return doWatch(source, cb, options);
|
|
712
|
-
}
|
|
713
|
-
var INITIAL_WATCHER_VALUE = void 0;
|
|
714
|
-
var watcher;
|
|
715
|
-
var flushing = false;
|
|
716
|
-
function queueWatcher(fn) {
|
|
717
|
-
watcher = fn;
|
|
718
|
-
if (!flushing) {
|
|
719
|
-
flushing = true;
|
|
720
|
-
nextTick(flushWatchers);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function flushWatchers() {
|
|
724
|
-
watcher == null ? void 0 : watcher();
|
|
725
|
-
watcher = null;
|
|
726
|
-
flushing = false;
|
|
727
|
-
}
|
|
728
|
-
function doWatch(source, cb, { deep, immediate } = {}) {
|
|
729
|
-
let getter;
|
|
730
|
-
const isMultiSource = isArray2(source);
|
|
731
|
-
if (isSignal(source) || isComputed(source)) {
|
|
732
|
-
getter = () => source.value;
|
|
733
|
-
} else if (isReactive(source)) {
|
|
734
|
-
getter = () => __spreadValues({}, source);
|
|
735
|
-
} else if (isMultiSource) {
|
|
736
|
-
getter = () => source.map((s) => resolveSource(s));
|
|
737
|
-
} else if (isFunction2(source)) {
|
|
738
|
-
getter = source;
|
|
739
|
-
} else {
|
|
740
|
-
warn("Invalid source type", source);
|
|
741
|
-
return noop2;
|
|
742
|
-
}
|
|
743
|
-
if (cb && deep) {
|
|
744
|
-
const baseGetter = getter;
|
|
745
|
-
const depth = deep === true ? Infinity : deep;
|
|
746
|
-
getter = () => traverse(baseGetter(), depth);
|
|
747
|
-
}
|
|
748
|
-
let oldValue = isMultiSource ? Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
|
|
749
|
-
let runCb = false;
|
|
750
|
-
const effectFn = () => {
|
|
751
|
-
const newValue = getter();
|
|
752
|
-
if (hasChanged(newValue, oldValue)) {
|
|
753
|
-
if (immediate && cb) {
|
|
754
|
-
cb(newValue, oldValue);
|
|
755
|
-
oldValue = newValue;
|
|
756
|
-
}
|
|
757
|
-
if (runCb && cb) {
|
|
758
|
-
queueWatcher(() => {
|
|
759
|
-
cb(newValue, oldValue);
|
|
760
|
-
oldValue = newValue;
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
!runCb && (oldValue = newValue);
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
const stop = useEffect(effectFn, { flush: "sync" });
|
|
767
|
-
runCb = true;
|
|
768
|
-
if (immediate) {
|
|
769
|
-
effectFn();
|
|
770
|
-
}
|
|
771
|
-
return stop;
|
|
772
|
-
}
|
|
773
|
-
function resolveSource(s) {
|
|
774
|
-
if (isSignal(s) || isComputed(s)) return s.value;
|
|
775
|
-
if (isReactive(s)) return __spreadValues({}, s);
|
|
776
|
-
if (isFunction2(s)) return s();
|
|
777
|
-
warn("Invalid source", s);
|
|
778
|
-
return noop2;
|
|
779
|
-
}
|
|
780
|
-
function traverse(value, depth = Infinity, seen) {
|
|
781
|
-
if (depth <= 0 || !isObject2(value)) {
|
|
782
|
-
return value;
|
|
783
|
-
}
|
|
784
|
-
seen = seen || /* @__PURE__ */ new Set();
|
|
785
|
-
if (seen.has(value)) {
|
|
786
|
-
return value;
|
|
787
|
-
}
|
|
788
|
-
seen.add(value);
|
|
789
|
-
depth--;
|
|
790
|
-
if (isSignal(value)) {
|
|
791
|
-
traverse(value.value, depth, seen);
|
|
792
|
-
} else if (isArray2(value)) {
|
|
793
|
-
for (const element of value) {
|
|
794
|
-
traverse(element, depth, seen);
|
|
795
|
-
}
|
|
796
|
-
} else if (isSet(value) || isMap(value)) {
|
|
797
|
-
value.forEach((v) => {
|
|
798
|
-
traverse(v, depth, seen);
|
|
799
|
-
});
|
|
800
|
-
} else if (isPlainObject(value)) {
|
|
801
|
-
for (const key in value) {
|
|
802
|
-
traverse(value[key], depth, seen);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
return value;
|
|
806
|
-
}
|
|
807
|
-
function createOptionsStore(options) {
|
|
808
|
-
const { state, getters, actions } = options;
|
|
809
|
-
const initState = __spreadValues({}, state != null ? state : {});
|
|
810
|
-
const reactiveState = useReactive(state != null ? state : {});
|
|
811
|
-
const subscriptions = [];
|
|
812
|
-
const actionCallbacks = [];
|
|
813
|
-
const default_actions = {
|
|
814
|
-
patch$(payload) {
|
|
815
|
-
Object.assign(reactiveState, payload);
|
|
816
|
-
subscriptions.forEach((callback) => callback(reactiveState));
|
|
817
|
-
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
818
|
-
},
|
|
819
|
-
subscribe$(callback) {
|
|
820
|
-
subscriptions.push(callback);
|
|
821
|
-
},
|
|
822
|
-
unsubscribe$(callback) {
|
|
823
|
-
const index = subscriptions.indexOf(callback);
|
|
824
|
-
if (index !== -1) {
|
|
825
|
-
subscriptions.splice(index, 1);
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
onAction$(callback) {
|
|
829
|
-
actionCallbacks.push(callback);
|
|
830
|
-
},
|
|
831
|
-
reset$() {
|
|
832
|
-
Object.assign(reactiveState, initState);
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
const store = __spreadValues({
|
|
836
|
-
state: reactiveState
|
|
837
|
-
}, default_actions);
|
|
838
|
-
for (const key in getters) {
|
|
839
|
-
const getter = getters[key];
|
|
840
|
-
if (getter) {
|
|
841
|
-
Object.defineProperty(store, key, {
|
|
842
|
-
get() {
|
|
843
|
-
return useComputed(getter.bind(reactiveState, reactiveState)).value;
|
|
844
|
-
},
|
|
845
|
-
enumerable: true,
|
|
846
|
-
configurable: true
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
for (const key in actions) {
|
|
851
|
-
const action = actions[key];
|
|
852
|
-
if (action) {
|
|
853
|
-
store[key] = action.bind(reactiveState);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return store;
|
|
482
|
+
function getComponentIndex(temp) {
|
|
483
|
+
return componentMap.get(temp).index;
|
|
857
484
|
}
|
|
858
|
-
|
|
859
|
-
return function() {
|
|
860
|
-
return createOptionsStore(options);
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
// ../template/dist/template.dev.esm.js
|
|
865
|
-
var __defProp2 = Object.defineProperty;
|
|
866
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
867
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
868
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
869
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
870
|
-
var __spreadValues2 = (a, b) => {
|
|
871
|
-
for (var prop in b || (b = {}))
|
|
872
|
-
if (__hasOwnProp2.call(b, prop))
|
|
873
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
874
|
-
if (__getOwnPropSymbols2)
|
|
875
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
876
|
-
if (__propIsEnum2.call(b, prop))
|
|
877
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
878
|
-
}
|
|
879
|
-
return a;
|
|
880
|
-
};
|
|
881
|
-
var _Hooks = class _Hooks2 {
|
|
485
|
+
var _LifecycleContext = class _LifecycleContext2 {
|
|
882
486
|
constructor() {
|
|
883
487
|
this.hooks = {
|
|
884
488
|
mounted: /* @__PURE__ */ new Set(),
|
|
@@ -894,154 +498,120 @@ var _Hooks = class _Hooks2 {
|
|
|
894
498
|
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
895
499
|
}
|
|
896
500
|
getContext(context) {
|
|
897
|
-
return
|
|
501
|
+
return _LifecycleContext2.context[context];
|
|
898
502
|
}
|
|
899
503
|
setContext(context, value) {
|
|
900
|
-
|
|
504
|
+
_LifecycleContext2.context[context] = value;
|
|
901
505
|
}
|
|
902
506
|
initRef() {
|
|
903
|
-
|
|
507
|
+
_LifecycleContext2.ref = this;
|
|
904
508
|
}
|
|
905
509
|
removeRef() {
|
|
906
|
-
|
|
510
|
+
_LifecycleContext2.ref = null;
|
|
511
|
+
}
|
|
512
|
+
clearHooks() {
|
|
513
|
+
Object.values(this.hooks).forEach((set) => set.clear());
|
|
907
514
|
}
|
|
908
515
|
};
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
var
|
|
912
|
-
|
|
913
|
-
|
|
516
|
+
_LifecycleContext.ref = null;
|
|
517
|
+
_LifecycleContext.context = {};
|
|
518
|
+
var LifecycleContext = _LifecycleContext;
|
|
519
|
+
function isSSGNode(node) {
|
|
520
|
+
return node instanceof SSGNode;
|
|
521
|
+
}
|
|
522
|
+
var componentIndex = 1;
|
|
523
|
+
var SSGNode = class extends LifecycleContext {
|
|
524
|
+
constructor(template, props = {}, key) {
|
|
914
525
|
super();
|
|
915
|
-
this.template =
|
|
526
|
+
this.template = template;
|
|
916
527
|
this.props = props;
|
|
917
528
|
this.key = key;
|
|
918
|
-
|
|
919
|
-
this.
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
get isConnected() {
|
|
935
|
-
var _a, _b;
|
|
936
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
937
|
-
}
|
|
938
|
-
inheritNode(node) {
|
|
939
|
-
this.context = node.context;
|
|
940
|
-
this.hooks = node.hooks;
|
|
941
|
-
Object.assign(this.proxyProps, node.proxyProps);
|
|
942
|
-
this.rootNode = node.rootNode;
|
|
943
|
-
this.trackMap = node.trackMap;
|
|
944
|
-
const props = this.props;
|
|
945
|
-
this.props = node.props;
|
|
946
|
-
this.patchProps(props);
|
|
947
|
-
}
|
|
948
|
-
mount(parent, before) {
|
|
949
|
-
var _a, _b, _c, _d;
|
|
950
|
-
if (!isFunction(this.template)) {
|
|
951
|
-
throw new Error("Template must be a function");
|
|
952
|
-
}
|
|
953
|
-
if (this.isConnected) {
|
|
954
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
529
|
+
enterComponent(template, componentIndex);
|
|
530
|
+
if (isArray(this.template)) {
|
|
531
|
+
const PLACEHOLDER = " __PLACEHOLDER__ ";
|
|
532
|
+
const htmlString = this.template.join(PLACEHOLDER);
|
|
533
|
+
const processedString = htmlString.replaceAll(/(<[^>]+>)|([^<]+)/g, (match, p1, p2) => {
|
|
534
|
+
if (p1) {
|
|
535
|
+
if (p1.includes("data-ci")) return match;
|
|
536
|
+
return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_2, tagName, attrs) => {
|
|
537
|
+
return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
|
|
538
|
+
});
|
|
539
|
+
} else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
|
|
540
|
+
return `<!--${0}-${componentIndex}-->${p2}<!$>`;
|
|
541
|
+
}
|
|
542
|
+
return match;
|
|
543
|
+
});
|
|
544
|
+
this.template = processedString.split(PLACEHOLDER);
|
|
955
545
|
}
|
|
546
|
+
}
|
|
547
|
+
mount() {
|
|
956
548
|
this.initRef();
|
|
957
|
-
|
|
549
|
+
const output = this.render();
|
|
958
550
|
this.removeRef();
|
|
959
|
-
|
|
960
|
-
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
961
|
-
this.hooks.mounted.forEach((handler) => handler());
|
|
962
|
-
this.patchProps(this.props);
|
|
963
|
-
return mountedNode;
|
|
964
|
-
}
|
|
965
|
-
unmount() {
|
|
966
|
-
var _a;
|
|
967
|
-
this.hooks.destroy.forEach((handler) => handler());
|
|
968
|
-
Object.values(this.hooks).forEach((set) => set.clear());
|
|
969
|
-
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
970
|
-
this.rootNode = null;
|
|
971
|
-
this.proxyProps = {};
|
|
972
|
-
this.mounted = false;
|
|
973
|
-
this.emitter.forEach((emitter) => emitter());
|
|
551
|
+
return output;
|
|
974
552
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
track2.cleanup();
|
|
553
|
+
render() {
|
|
554
|
+
if (isFunction(this.template)) {
|
|
555
|
+
const root = this.template(this.props);
|
|
556
|
+
if (isSSGNode(root)) {
|
|
557
|
+
return root.mount();
|
|
558
|
+
} else {
|
|
559
|
+
return String(root);
|
|
560
|
+
}
|
|
984
561
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
997
|
-
} else if (startsWith(key, "update")) {
|
|
998
|
-
props[key] = isSignal(prop) ? prop.value : prop;
|
|
999
|
-
} else if (key !== "children") {
|
|
1000
|
-
const newValue = (_d = (_c = this.proxyProps)[key]) != null ? _d : _c[key] = useSignal(prop);
|
|
1001
|
-
const track2 = this.getNodeTrack(key);
|
|
1002
|
-
track2.cleanup = useEffect(() => {
|
|
1003
|
-
newValue.value = isFunction(prop) ? prop() : prop;
|
|
562
|
+
const template = this.template;
|
|
563
|
+
Object.keys(this.props).forEach((key) => {
|
|
564
|
+
const cur = this.props[key];
|
|
565
|
+
const childrens = cur.children;
|
|
566
|
+
normalizeProp(cur);
|
|
567
|
+
const findIndex = template.findIndex((t) => t.includes(`data-hk="${key}"`));
|
|
568
|
+
if (childrens) {
|
|
569
|
+
childrens.forEach(([child]) => {
|
|
570
|
+
componentIndex++;
|
|
571
|
+
const children = renderChildren(child, cur);
|
|
572
|
+
this.template[findIndex] += children;
|
|
1004
573
|
});
|
|
1005
574
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
575
|
+
this.template[findIndex].replaceAll(
|
|
576
|
+
`data-hk="${key}"`,
|
|
577
|
+
`data-hk="${key}" ${generateAttributes(cur)}`
|
|
578
|
+
);
|
|
579
|
+
});
|
|
580
|
+
return template.join("");
|
|
1008
581
|
}
|
|
1009
582
|
};
|
|
1010
|
-
function
|
|
1011
|
-
|
|
1012
|
-
if (
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
if (_template === "") {
|
|
1019
|
-
props = {
|
|
1020
|
-
0: props
|
|
1021
|
-
};
|
|
583
|
+
function normalizeProp(props) {
|
|
584
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
585
|
+
if (key === "children") {
|
|
586
|
+
delete props[key];
|
|
587
|
+
} else if (isFunction(value)) {
|
|
588
|
+
delete props[key];
|
|
589
|
+
} else if (h(value)) {
|
|
590
|
+
props[key] = value.value;
|
|
1022
591
|
}
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
return isFunction(_template) ? new ComponentNode(_template, props, key) : new TemplateNode(_template, props, key);
|
|
1026
|
-
}
|
|
1027
|
-
function isComponent(node) {
|
|
1028
|
-
return node instanceof ComponentNode;
|
|
1029
|
-
}
|
|
1030
|
-
function isJsxElement(node) {
|
|
1031
|
-
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
1032
|
-
}
|
|
1033
|
-
function template(html) {
|
|
1034
|
-
const template2 = document.createElement("template");
|
|
1035
|
-
template2.innerHTML = closeHtmlTags(html);
|
|
1036
|
-
return template2;
|
|
1037
|
-
}
|
|
1038
|
-
function Fragment(props) {
|
|
1039
|
-
return props.children;
|
|
592
|
+
});
|
|
1040
593
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
594
|
+
function generateAttributes(props) {
|
|
595
|
+
return Object.entries(props).filter(([key, value]) => key !== "children" && !isFunction(value)).map(([key, value]) => `${key}="${escape(String(value))}"`).join(" ");
|
|
596
|
+
}
|
|
597
|
+
function renderChildren(children, prop) {
|
|
598
|
+
if (isFunction(children)) {
|
|
599
|
+
return renderChildren(children(prop), prop);
|
|
600
|
+
} else if (h(children)) {
|
|
601
|
+
return `<!--${1}-${componentIndex}-->${children.value}<!$>`;
|
|
602
|
+
} else if (isSSGNode(children)) {
|
|
603
|
+
const childResult = children.mount();
|
|
604
|
+
return isFunction(childResult) ? childResult(prop) : extractSignal(childResult);
|
|
605
|
+
} else {
|
|
606
|
+
return `<!--${1}-${componentIndex}-->${children}<!$>`;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");
|
|
610
|
+
var htmlTags = "a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp".split(
|
|
611
|
+
","
|
|
612
|
+
);
|
|
1043
613
|
function coerceNode(data) {
|
|
1044
|
-
if (isJsxElement(data) || data instanceof Node) {
|
|
614
|
+
if (isJsxElement(data) || data instanceof Node || isSSGNode(data)) {
|
|
1045
615
|
return data;
|
|
1046
616
|
}
|
|
1047
617
|
const text = isFalsy(data) ? "" : String(data);
|
|
@@ -1049,11 +619,12 @@ function coerceNode(data) {
|
|
|
1049
619
|
}
|
|
1050
620
|
function insertChild(parent, child, before = null) {
|
|
1051
621
|
const beforeNode = isJsxElement(before) ? before.firstChild : before;
|
|
622
|
+
const ssr = renderContext.isSSR;
|
|
1052
623
|
if (isJsxElement(child)) {
|
|
1053
624
|
child.mount(parent, beforeNode);
|
|
1054
|
-
} else if (beforeNode) {
|
|
625
|
+
} else if (beforeNode && !ssr) {
|
|
1055
626
|
beforeNode.before(child);
|
|
1056
|
-
} else {
|
|
627
|
+
} else if (!ssr) {
|
|
1057
628
|
parent.append(child);
|
|
1058
629
|
}
|
|
1059
630
|
}
|
|
@@ -1075,7 +646,7 @@ function setAttribute(element, attr, value) {
|
|
|
1075
646
|
if (attr === "class") {
|
|
1076
647
|
if (typeof value === "string") {
|
|
1077
648
|
element.className = value;
|
|
1078
|
-
} else if (
|
|
649
|
+
} else if (isArray(value)) {
|
|
1079
650
|
element.className = value.join(" ");
|
|
1080
651
|
} else if (value && typeof value === "object") {
|
|
1081
652
|
element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
|
|
@@ -1098,14 +669,14 @@ function setAttribute(element, attr, value) {
|
|
|
1098
669
|
} else if (value === true) {
|
|
1099
670
|
element.setAttribute(attr, "");
|
|
1100
671
|
} else {
|
|
1101
|
-
if (element instanceof HTMLInputElement) {
|
|
672
|
+
if (element instanceof HTMLInputElement && attr === "value") {
|
|
1102
673
|
element.value = String(value);
|
|
1103
674
|
} else {
|
|
1104
675
|
element.setAttribute(attr, String(value));
|
|
1105
676
|
}
|
|
1106
677
|
}
|
|
1107
678
|
}
|
|
1108
|
-
function
|
|
679
|
+
function bindNode(node, setter) {
|
|
1109
680
|
if (node instanceof HTMLInputElement) {
|
|
1110
681
|
switch (node.type) {
|
|
1111
682
|
case "checkbox":
|
|
@@ -1148,16 +719,12 @@ function binNode(node, setter) {
|
|
|
1148
719
|
});
|
|
1149
720
|
}
|
|
1150
721
|
}
|
|
1151
|
-
|
|
1152
|
-
function nextTick2(fn) {
|
|
1153
|
-
return fn ? p2.then(fn) : p2;
|
|
1154
|
-
}
|
|
722
|
+
Promise.resolve();
|
|
1155
723
|
function addEventListener(node, eventName, handler) {
|
|
1156
724
|
node.addEventListener(eventName, handler);
|
|
1157
725
|
return () => node.removeEventListener(eventName, handler);
|
|
1158
726
|
}
|
|
1159
727
|
function closeHtmlTags(input) {
|
|
1160
|
-
const selfClosingTagList = selfClosingTags.split(",");
|
|
1161
728
|
const tagStack = [];
|
|
1162
729
|
const output = [];
|
|
1163
730
|
const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
|
|
@@ -1179,7 +746,7 @@ function closeHtmlTags(input) {
|
|
|
1179
746
|
if (tagStack.length > 0) {
|
|
1180
747
|
tagStack.pop();
|
|
1181
748
|
}
|
|
1182
|
-
} else if (!
|
|
749
|
+
} else if (!selfClosingTags.includes(tagName)) {
|
|
1183
750
|
tagStack.push(tagName);
|
|
1184
751
|
}
|
|
1185
752
|
output.push(fullMatch);
|
|
@@ -1194,44 +761,145 @@ function closeHtmlTags(input) {
|
|
|
1194
761
|
return output.join("");
|
|
1195
762
|
}
|
|
1196
763
|
function isHtmlTagName(tagName) {
|
|
1197
|
-
|
|
1198
|
-
return htmlTagsList.includes(tagName);
|
|
764
|
+
return htmlTags.includes(tagName);
|
|
1199
765
|
}
|
|
1200
766
|
function convertToHtmlTag(tagName) {
|
|
1201
|
-
|
|
1202
|
-
if (selfClosingTagList.includes(tagName)) {
|
|
767
|
+
if (selfClosingTags.includes(tagName)) {
|
|
1203
768
|
return `<${tagName}/>`;
|
|
1204
769
|
} else {
|
|
1205
770
|
return `<${tagName}></${tagName}>`;
|
|
1206
771
|
}
|
|
1207
772
|
}
|
|
773
|
+
function extractSignal(signal) {
|
|
774
|
+
if (h(signal)) {
|
|
775
|
+
return signal.value;
|
|
776
|
+
} else {
|
|
777
|
+
return signal;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
var ComponentNode = class extends LifecycleContext {
|
|
781
|
+
constructor(template, props, key) {
|
|
782
|
+
super();
|
|
783
|
+
this.template = template;
|
|
784
|
+
this.props = props;
|
|
785
|
+
this.key = key;
|
|
786
|
+
this.emitter = /* @__PURE__ */ new Set();
|
|
787
|
+
this.rootNode = null;
|
|
788
|
+
this.trackMap = /* @__PURE__ */ new Map();
|
|
789
|
+
this.proxyProps = props ? L(
|
|
790
|
+
props,
|
|
791
|
+
(key2) => startsWith(key2, "on") || startsWith(key2, "update") || key2 === "children"
|
|
792
|
+
) : {};
|
|
793
|
+
}
|
|
794
|
+
get firstChild() {
|
|
795
|
+
var _a, _b;
|
|
796
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
797
|
+
}
|
|
798
|
+
get isConnected() {
|
|
799
|
+
var _a, _b;
|
|
800
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
801
|
+
}
|
|
802
|
+
mount(parent, before) {
|
|
803
|
+
var _a, _b, _c, _d;
|
|
804
|
+
if (!isFunction(this.template)) {
|
|
805
|
+
throw new Error("Template must be a function");
|
|
806
|
+
}
|
|
807
|
+
if (this.isConnected) {
|
|
808
|
+
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
809
|
+
}
|
|
810
|
+
this.initRef();
|
|
811
|
+
this.rootNode = this.template(this.proxyProps);
|
|
812
|
+
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
813
|
+
this.hooks.mounted.forEach((handler) => handler());
|
|
814
|
+
this.patchProps(this.props);
|
|
815
|
+
this.removeRef();
|
|
816
|
+
return mountedNode;
|
|
817
|
+
}
|
|
818
|
+
unmount() {
|
|
819
|
+
var _a;
|
|
820
|
+
this.hooks.destroy.forEach((handler) => handler());
|
|
821
|
+
this.clearHooks();
|
|
822
|
+
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
823
|
+
this.rootNode = null;
|
|
824
|
+
this.proxyProps = {};
|
|
825
|
+
for (const cleanup of this.emitter) {
|
|
826
|
+
cleanup();
|
|
827
|
+
}
|
|
828
|
+
this.emitter.clear();
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Inherit props and state from another ComponentNode.
|
|
832
|
+
* It will:
|
|
833
|
+
* 1. Copy props from the node to this proxyProps.
|
|
834
|
+
* 2. Copy the rootNode, trackMap and hooks from the node.
|
|
835
|
+
* 3. Copy the props from the node to this.
|
|
836
|
+
* 4. Patch props from the props passed in the constructor.
|
|
837
|
+
* @param node The node to inherit from.
|
|
838
|
+
*/
|
|
839
|
+
inheritNode(node) {
|
|
840
|
+
Object.assign(this.proxyProps, node.proxyProps);
|
|
841
|
+
this.rootNode = node.rootNode;
|
|
842
|
+
this.trackMap = node.trackMap;
|
|
843
|
+
this.hooks = node.hooks;
|
|
844
|
+
const props = this.props;
|
|
845
|
+
this.props = node.props;
|
|
846
|
+
this.patchProps(props);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
|
|
850
|
+
* Then, call the cleanup function to remove any previously registered hooks.
|
|
851
|
+
* @param trackKey the key of the node track to get.
|
|
852
|
+
* @returns the NodeTrack, cleaned up and ready to use.
|
|
853
|
+
*/
|
|
854
|
+
getNodeTrack(trackKey) {
|
|
855
|
+
let track = this.trackMap.get(trackKey);
|
|
856
|
+
if (!track) {
|
|
857
|
+
track = { cleanup: () => {
|
|
858
|
+
} };
|
|
859
|
+
this.trackMap.set(trackKey, track);
|
|
860
|
+
}
|
|
861
|
+
track.cleanup();
|
|
862
|
+
return track;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Patch the props of this node.
|
|
866
|
+
* It will:
|
|
867
|
+
* 1. Iterate the props and patch it.
|
|
868
|
+
* 2. If the prop is a event handler, add a event listener to the first child of the node.
|
|
869
|
+
* 3. If the prop is a ref, set the first child of the node to the ref.
|
|
870
|
+
* 4. If the prop is a update handler, update the prop in the node's props.
|
|
871
|
+
* 5. If the prop is a normal prop, create a signal for it and then patch it.
|
|
872
|
+
* @param props The props to patch.
|
|
873
|
+
*/
|
|
874
|
+
patchProps(props) {
|
|
875
|
+
var _a, _b;
|
|
876
|
+
if (!props) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
880
|
+
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.firstChild)) {
|
|
881
|
+
const event = key.slice(2).toLowerCase();
|
|
882
|
+
const cleanup = addEventListener(this.rootNode.nodes[0], event, prop);
|
|
883
|
+
this.emitter.add(cleanup);
|
|
884
|
+
} else if (key === "ref") {
|
|
885
|
+
prop.value = (_b = this.rootNode) == null ? void 0 : _b.firstChild;
|
|
886
|
+
} else if (startsWith(key, "update")) {
|
|
887
|
+
this.props[key] = extractSignal(prop);
|
|
888
|
+
} else if (key !== "children") {
|
|
889
|
+
const track = this.getNodeTrack(key);
|
|
890
|
+
track.cleanup = B(() => {
|
|
891
|
+
this.proxyProps[key] = isFunction(prop) ? prop() : prop;
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
this.props = props;
|
|
896
|
+
}
|
|
897
|
+
};
|
|
1208
898
|
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
1209
899
|
const result = /* @__PURE__ */ new Map();
|
|
1210
900
|
const children = Array.from(childrenMap.values());
|
|
1211
|
-
const childrenLength = children.length;
|
|
1212
901
|
if (childrenMap.size > 0 && nextChildren.length === 0) {
|
|
1213
|
-
|
|
1214
|
-
parent.innerHTML = "";
|
|
1215
|
-
if (before) {
|
|
1216
|
-
insertChild(parent, before);
|
|
1217
|
-
}
|
|
1218
|
-
} else {
|
|
1219
|
-
const range = document.createRange();
|
|
1220
|
-
const child = children[0];
|
|
1221
|
-
const start = isJsxElement(child) ? child.firstChild : child;
|
|
1222
|
-
range.setStartBefore(start);
|
|
1223
|
-
if (before) {
|
|
1224
|
-
range.setEndBefore(before);
|
|
1225
|
-
} else {
|
|
1226
|
-
range.setEndAfter(parent);
|
|
1227
|
-
}
|
|
1228
|
-
range.deleteContents();
|
|
1229
|
-
}
|
|
1230
|
-
children.forEach((node) => {
|
|
1231
|
-
if (isJsxElement(node)) {
|
|
1232
|
-
node.unmount();
|
|
1233
|
-
}
|
|
1234
|
-
});
|
|
902
|
+
clearChildren(parent, children, before);
|
|
1235
903
|
return result;
|
|
1236
904
|
}
|
|
1237
905
|
const replaces = [];
|
|
@@ -1272,6 +940,30 @@ function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
|
1272
940
|
});
|
|
1273
941
|
return result;
|
|
1274
942
|
}
|
|
943
|
+
function clearChildren(parent, children, before) {
|
|
944
|
+
if (parent.childNodes.length === children.length + (before ? 1 : 0)) {
|
|
945
|
+
parent.innerHTML = "";
|
|
946
|
+
if (before) {
|
|
947
|
+
insertChild(parent, before);
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
const range = document.createRange();
|
|
951
|
+
const child = children[0];
|
|
952
|
+
const start = isJsxElement(child) ? child.firstChild : child;
|
|
953
|
+
range.setStartBefore(start);
|
|
954
|
+
if (before) {
|
|
955
|
+
range.setEndBefore(before);
|
|
956
|
+
} else {
|
|
957
|
+
range.setEndAfter(parent);
|
|
958
|
+
}
|
|
959
|
+
range.deleteContents();
|
|
960
|
+
}
|
|
961
|
+
children.forEach((node) => {
|
|
962
|
+
if (isJsxElement(node)) {
|
|
963
|
+
node.unmount();
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
}
|
|
1275
967
|
function patch(parent, node, next) {
|
|
1276
968
|
if (node === next) {
|
|
1277
969
|
return node;
|
|
@@ -1306,30 +998,34 @@ function getKey(node, index) {
|
|
|
1306
998
|
}
|
|
1307
999
|
return `_$${index}$`;
|
|
1308
1000
|
}
|
|
1309
|
-
var TemplateNode = class
|
|
1310
|
-
constructor(
|
|
1311
|
-
this.template =
|
|
1001
|
+
var TemplateNode = class {
|
|
1002
|
+
constructor(template, props, key) {
|
|
1003
|
+
this.template = template;
|
|
1312
1004
|
this.props = props;
|
|
1313
1005
|
this.key = key;
|
|
1314
1006
|
this.treeMap = /* @__PURE__ */ new Map();
|
|
1315
1007
|
this.mounted = false;
|
|
1316
1008
|
this.nodes = [];
|
|
1317
|
-
this.provides = {};
|
|
1318
1009
|
this.trackMap = /* @__PURE__ */ new Map();
|
|
1010
|
+
this.bindValueKeys = [];
|
|
1319
1011
|
this.parent = null;
|
|
1320
|
-
this.key
|
|
1012
|
+
this.key || (this.key = props == null ? void 0 : props.key);
|
|
1013
|
+
if (renderContext.isSSR) {
|
|
1014
|
+
this.componentIndex = getComponentIndex(this.template);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
addEventListener() {
|
|
1018
|
+
}
|
|
1019
|
+
removeEventListener() {
|
|
1321
1020
|
}
|
|
1322
1021
|
get firstChild() {
|
|
1323
1022
|
var _a;
|
|
1324
1023
|
return (_a = this.nodes[0]) != null ? _a : null;
|
|
1325
1024
|
}
|
|
1025
|
+
// is mounted
|
|
1326
1026
|
get isConnected() {
|
|
1327
1027
|
return this.mounted;
|
|
1328
1028
|
}
|
|
1329
|
-
addEventListener() {
|
|
1330
|
-
}
|
|
1331
|
-
removeEventListener() {
|
|
1332
|
-
}
|
|
1333
1029
|
mount(parent, before) {
|
|
1334
1030
|
var _a;
|
|
1335
1031
|
this.parent = parent;
|
|
@@ -1337,6 +1033,9 @@ var TemplateNode = class _TemplateNode {
|
|
|
1337
1033
|
this.nodes.forEach((node) => insertChild(parent, node, before));
|
|
1338
1034
|
return this.nodes;
|
|
1339
1035
|
}
|
|
1036
|
+
if (isArray(this.template)) {
|
|
1037
|
+
this.template = createTemplate(this.template.join(""));
|
|
1038
|
+
}
|
|
1340
1039
|
const cloneNode = this.template.content.cloneNode(true);
|
|
1341
1040
|
const firstChild = cloneNode.firstChild;
|
|
1342
1041
|
if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
|
|
@@ -1346,23 +1045,20 @@ var TemplateNode = class _TemplateNode {
|
|
|
1346
1045
|
});
|
|
1347
1046
|
}
|
|
1348
1047
|
this.nodes = Array.from(cloneNode.childNodes);
|
|
1349
|
-
|
|
1048
|
+
if (renderContext.isSSR) {
|
|
1049
|
+
this.mapSSGNodeTree(parent);
|
|
1050
|
+
} else {
|
|
1051
|
+
this.mapNodeTree(parent, cloneNode);
|
|
1052
|
+
}
|
|
1350
1053
|
insertChild(parent, cloneNode, before);
|
|
1351
|
-
this.
|
|
1054
|
+
this.patchProps(this.props);
|
|
1352
1055
|
this.mounted = true;
|
|
1353
1056
|
return this.nodes;
|
|
1354
1057
|
}
|
|
1355
1058
|
unmount() {
|
|
1356
|
-
this.trackMap.forEach((
|
|
1357
|
-
var _a
|
|
1358
|
-
(_a =
|
|
1359
|
-
(_b = track2.lastNodes) == null ? void 0 : _b.forEach((node) => {
|
|
1360
|
-
if (track2.isRoot) {
|
|
1361
|
-
removeChild(node);
|
|
1362
|
-
} else if (node instanceof _TemplateNode) {
|
|
1363
|
-
node.unmount();
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1059
|
+
this.trackMap.forEach((track) => {
|
|
1060
|
+
var _a;
|
|
1061
|
+
(_a = track.cleanup) == null ? void 0 : _a.call(track);
|
|
1366
1062
|
});
|
|
1367
1063
|
this.trackMap.clear();
|
|
1368
1064
|
this.treeMap.clear();
|
|
@@ -1370,6 +1066,52 @@ var TemplateNode = class _TemplateNode {
|
|
|
1370
1066
|
this.nodes = [];
|
|
1371
1067
|
this.mounted = false;
|
|
1372
1068
|
}
|
|
1069
|
+
patchProps(props) {
|
|
1070
|
+
if (!props) return;
|
|
1071
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
1072
|
+
const index = Number(key);
|
|
1073
|
+
const node = this.treeMap.get(index);
|
|
1074
|
+
if (node) {
|
|
1075
|
+
this.patchProp(key, node, value, index === 0);
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
this.props = props;
|
|
1079
|
+
}
|
|
1080
|
+
inheritNode(node) {
|
|
1081
|
+
this.mounted = node.mounted;
|
|
1082
|
+
this.nodes = node.nodes;
|
|
1083
|
+
this.trackMap = node.trackMap;
|
|
1084
|
+
this.treeMap = node.treeMap;
|
|
1085
|
+
const props = this.props;
|
|
1086
|
+
this.props = node.props;
|
|
1087
|
+
this.patchProps(props);
|
|
1088
|
+
}
|
|
1089
|
+
mapSSGNodeTree(parent) {
|
|
1090
|
+
this.treeMap.set(0, parent);
|
|
1091
|
+
const walk = (node) => {
|
|
1092
|
+
var _a;
|
|
1093
|
+
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
1094
|
+
if (node.nodeType === Node.COMMENT_NODE) {
|
|
1095
|
+
const [type, index] = ((_a = node.textContent) == null ? void 0 : _a.split("-")) || "";
|
|
1096
|
+
if (0 === +type && +index === this.componentIndex) {
|
|
1097
|
+
const textNode = node.nextSibling;
|
|
1098
|
+
this.treeMap.set(+index, textNode);
|
|
1099
|
+
}
|
|
1100
|
+
} else if (node.nodeType !== Node.TEXT_NODE) {
|
|
1101
|
+
const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
|
|
1102
|
+
if (hk && +ci === this.componentIndex) {
|
|
1103
|
+
this.treeMap.set(+hk, node);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
let child = node.firstChild;
|
|
1108
|
+
while (child) {
|
|
1109
|
+
walk(child);
|
|
1110
|
+
child = child.nextSibling;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
walk(parent);
|
|
1114
|
+
}
|
|
1373
1115
|
mapNodeTree(parent, tree) {
|
|
1374
1116
|
let index = 1;
|
|
1375
1117
|
this.treeMap.set(0, parent);
|
|
@@ -1385,84 +1127,78 @@ var TemplateNode = class _TemplateNode {
|
|
|
1385
1127
|
};
|
|
1386
1128
|
walk(tree);
|
|
1387
1129
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
}
|
|
1397
|
-
this.props = props;
|
|
1398
|
-
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
|
|
1132
|
+
* Then, call the cleanup function to remove any previously registered hooks.
|
|
1133
|
+
* @param trackKey the key of the node track to get.
|
|
1134
|
+
* @param trackLastNodes if true, the track will record the last nodes it has rendered.
|
|
1135
|
+
* @param isRoot if true, the track will be treated as a root track.
|
|
1136
|
+
* @returns the NodeTrack, cleaned up and ready to use.
|
|
1137
|
+
*/
|
|
1399
1138
|
getNodeTrack(trackKey, trackLastNodes, isRoot) {
|
|
1400
1139
|
var _a;
|
|
1401
|
-
let
|
|
1402
|
-
if (!
|
|
1403
|
-
|
|
1140
|
+
let track = this.trackMap.get(trackKey);
|
|
1141
|
+
if (!track) {
|
|
1142
|
+
track = { cleanup: () => {
|
|
1404
1143
|
} };
|
|
1405
1144
|
if (trackLastNodes) {
|
|
1406
|
-
|
|
1145
|
+
track.lastNodes = /* @__PURE__ */ new Map();
|
|
1407
1146
|
}
|
|
1408
1147
|
if (isRoot) {
|
|
1409
|
-
|
|
1148
|
+
track.isRoot = true;
|
|
1410
1149
|
}
|
|
1411
|
-
this.trackMap.set(trackKey,
|
|
1150
|
+
this.trackMap.set(trackKey, track);
|
|
1412
1151
|
}
|
|
1413
|
-
(_a =
|
|
1414
|
-
return
|
|
1415
|
-
}
|
|
1416
|
-
inheritNode(node) {
|
|
1417
|
-
this.mounted = node.mounted;
|
|
1418
|
-
this.nodes = node.nodes;
|
|
1419
|
-
this.trackMap = node.trackMap;
|
|
1420
|
-
this.treeMap = node.treeMap;
|
|
1421
|
-
const props = this.props;
|
|
1422
|
-
this.props = node.props;
|
|
1423
|
-
this.patchNodes(props);
|
|
1152
|
+
(_a = track.cleanup) == null ? void 0 : _a.call(track);
|
|
1153
|
+
return track;
|
|
1424
1154
|
}
|
|
1425
|
-
|
|
1155
|
+
patchProp(key, node, props, isRoot) {
|
|
1426
1156
|
for (const attr in props) {
|
|
1427
1157
|
if (attr === "children" && props.children) {
|
|
1428
1158
|
if (!isArray(props.children)) {
|
|
1429
1159
|
const trackKey = `${key}:${attr}:${0}`;
|
|
1430
|
-
const
|
|
1431
|
-
patchChild(
|
|
1160
|
+
const track = this.getNodeTrack(trackKey, true, isRoot);
|
|
1161
|
+
patchChild(track, node, props.children, null);
|
|
1432
1162
|
} else {
|
|
1433
1163
|
props.children.filter(Boolean).forEach((item, index) => {
|
|
1434
1164
|
var _a;
|
|
1435
1165
|
const [child, path] = isArray(item) ? item : [item, null];
|
|
1436
1166
|
const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
1437
1167
|
const trackKey = `${key}:${attr}:${index}`;
|
|
1438
|
-
const
|
|
1439
|
-
patchChild(
|
|
1168
|
+
const track = this.getNodeTrack(trackKey, true, isRoot);
|
|
1169
|
+
patchChild(track, node, child, before);
|
|
1440
1170
|
});
|
|
1441
1171
|
}
|
|
1442
1172
|
} else if (attr === "ref") {
|
|
1443
1173
|
props[attr].value = node;
|
|
1444
1174
|
} else if (startsWith(attr, "on")) {
|
|
1445
1175
|
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
1446
|
-
const
|
|
1176
|
+
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
1447
1177
|
const listener = props[attr];
|
|
1448
|
-
|
|
1449
|
-
} else
|
|
1450
|
-
const
|
|
1178
|
+
track.cleanup = addEventListener(node, eventName, listener);
|
|
1179
|
+
} else {
|
|
1180
|
+
const updateKey = `update${capitalizeFirstLetter(attr)}`;
|
|
1181
|
+
if (this.bindValueKeys.includes(attr)) {
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
if (props[updateKey]) {
|
|
1185
|
+
this.bindValueKeys.push(updateKey);
|
|
1186
|
+
}
|
|
1187
|
+
const track = this.getNodeTrack(`${key}:${attr}`);
|
|
1451
1188
|
const val = props[attr];
|
|
1452
|
-
const triggerValue =
|
|
1453
|
-
patchAttribute(
|
|
1454
|
-
const cleanup =
|
|
1455
|
-
triggerValue.value =
|
|
1456
|
-
patchAttribute(
|
|
1189
|
+
const triggerValue = h(val) ? val : le(val);
|
|
1190
|
+
patchAttribute(track, node, attr, triggerValue.value);
|
|
1191
|
+
const cleanup = B(() => {
|
|
1192
|
+
triggerValue.value = h(val) ? val.value : val;
|
|
1193
|
+
patchAttribute(track, node, attr, triggerValue.value);
|
|
1457
1194
|
});
|
|
1458
1195
|
let cleanupBind;
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
cleanupBind = binNode(node, (value) => {
|
|
1196
|
+
if (props[updateKey] && !isComponent(attr)) {
|
|
1197
|
+
cleanupBind = bindNode(node, (value) => {
|
|
1462
1198
|
props[updateKey](value);
|
|
1463
1199
|
});
|
|
1464
1200
|
}
|
|
1465
|
-
|
|
1201
|
+
track.cleanup = () => {
|
|
1466
1202
|
cleanup && cleanup();
|
|
1467
1203
|
cleanupBind && cleanupBind();
|
|
1468
1204
|
};
|
|
@@ -1470,178 +1206,144 @@ var TemplateNode = class _TemplateNode {
|
|
|
1470
1206
|
}
|
|
1471
1207
|
}
|
|
1472
1208
|
};
|
|
1473
|
-
function
|
|
1209
|
+
function patchChild(track, parent, child, before) {
|
|
1210
|
+
if (isFunction(child)) {
|
|
1211
|
+
track.cleanup = B(() => {
|
|
1212
|
+
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
1213
|
+
if (renderContext.isSSR) {
|
|
1214
|
+
track.lastNodes = reconcileChildren(parent, nextNodes, before);
|
|
1215
|
+
} else {
|
|
1216
|
+
track.lastNodes = patchChildren(parent, track.lastNodes, nextNodes, before);
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
} else {
|
|
1220
|
+
coerceArray(child).forEach((node, index) => {
|
|
1221
|
+
const newNode = coerceNode(node);
|
|
1222
|
+
const key = getKey(newNode, index);
|
|
1223
|
+
if (renderContext.isSSR) {
|
|
1224
|
+
track.lastNodes = reconcileChildren(parent, [newNode], before);
|
|
1225
|
+
} else {
|
|
1226
|
+
track.lastNodes.set(key, newNode);
|
|
1227
|
+
insertChild(parent, newNode, before);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function reconcileChildren(parent, nextNodes, before) {
|
|
1233
|
+
const result = /* @__PURE__ */ new Map();
|
|
1234
|
+
const textNodes = Array.from(parent.childNodes).filter(
|
|
1235
|
+
(node) => {
|
|
1236
|
+
var _a, _b;
|
|
1237
|
+
return node.nodeType === Node.TEXT_NODE && ((_a = node.previousSibling) == null ? void 0 : _a.nodeType) === Node.COMMENT_NODE && ((_b = node.nextSibling) == null ? void 0 : _b.nodeType) === Node.COMMENT_NODE;
|
|
1238
|
+
}
|
|
1239
|
+
);
|
|
1240
|
+
nextNodes.forEach((node, index) => {
|
|
1241
|
+
const key = getKey(node, index);
|
|
1242
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1243
|
+
textNodes.forEach((ne2) => {
|
|
1244
|
+
if (node.textContent === ne2.textContent) {
|
|
1245
|
+
parent.replaceChild(node, ne2);
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
} else {
|
|
1249
|
+
insertChild(parent, node, before);
|
|
1250
|
+
}
|
|
1251
|
+
result.set(key, node);
|
|
1252
|
+
});
|
|
1253
|
+
return result;
|
|
1254
|
+
}
|
|
1255
|
+
function patchAttribute(track, node, attr, data) {
|
|
1474
1256
|
const element = node;
|
|
1475
1257
|
if (!element.setAttribute) {
|
|
1476
1258
|
return;
|
|
1477
1259
|
}
|
|
1478
1260
|
if (isFunction(data)) {
|
|
1479
|
-
|
|
1261
|
+
track.cleanup = B(() => {
|
|
1480
1262
|
setAttribute(element, attr, data());
|
|
1481
1263
|
});
|
|
1482
1264
|
} else {
|
|
1483
1265
|
setAttribute(element, attr, data);
|
|
1484
1266
|
}
|
|
1485
1267
|
}
|
|
1486
|
-
function
|
|
1487
|
-
if (
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
})
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
track2.lastNodes.set(String(i), newNode);
|
|
1496
|
-
insertChild(parent, newNode, before);
|
|
1497
|
-
});
|
|
1268
|
+
function h2(template, props, key) {
|
|
1269
|
+
if (isString(template)) {
|
|
1270
|
+
if (isHtmlTagName(template)) {
|
|
1271
|
+
template = convertToHtmlTag(template);
|
|
1272
|
+
props = { "1": props };
|
|
1273
|
+
} else if (template === "") {
|
|
1274
|
+
props = { "0": props };
|
|
1275
|
+
}
|
|
1276
|
+
template = createTemplate(template);
|
|
1498
1277
|
}
|
|
1278
|
+
return isFunction(template) ? new ComponentNode(template, props, key) : new TemplateNode(template, props, key);
|
|
1279
|
+
}
|
|
1280
|
+
function isComponent(node) {
|
|
1281
|
+
return node instanceof ComponentNode;
|
|
1282
|
+
}
|
|
1283
|
+
function isJsxElement(node) {
|
|
1284
|
+
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
1285
|
+
}
|
|
1286
|
+
function createTemplate(html) {
|
|
1287
|
+
const template = document.createElement("template");
|
|
1288
|
+
template.innerHTML = closeHtmlTags(html);
|
|
1289
|
+
return template;
|
|
1290
|
+
}
|
|
1291
|
+
function Fragment(props) {
|
|
1292
|
+
return props.children;
|
|
1499
1293
|
}
|
|
1500
1294
|
function onMount(cb) {
|
|
1501
1295
|
var _a;
|
|
1502
|
-
|
|
1503
|
-
(_a =
|
|
1296
|
+
assertInsideComponent("onMounted");
|
|
1297
|
+
(_a = LifecycleContext.ref) == null ? void 0 : _a.addHook("mounted", cb);
|
|
1504
1298
|
}
|
|
1505
1299
|
function onDestroy(cb) {
|
|
1506
1300
|
var _a;
|
|
1507
|
-
|
|
1508
|
-
(_a =
|
|
1301
|
+
assertInsideComponent("onDestroy");
|
|
1302
|
+
(_a = LifecycleContext.ref) == null ? void 0 : _a.addHook("destroy", cb);
|
|
1509
1303
|
}
|
|
1510
|
-
function
|
|
1511
|
-
if (!
|
|
1304
|
+
function assertInsideComponent(hookName, key) {
|
|
1305
|
+
if (!LifecycleContext.ref && true) {
|
|
1512
1306
|
console.error(
|
|
1513
|
-
`"${
|
|
1307
|
+
`"${hookName}"(key: ${isSymbol(key) ? key.toString() : key}) can only be called within the component function body
|
|
1514
1308
|
and cannot be used in asynchronous or deferred calls.`
|
|
1515
1309
|
);
|
|
1516
1310
|
}
|
|
1517
1311
|
}
|
|
1518
1312
|
function useProvide(key, value) {
|
|
1519
1313
|
var _a;
|
|
1520
|
-
|
|
1521
|
-
(_a =
|
|
1314
|
+
assertInsideComponent("useProvide", key);
|
|
1315
|
+
(_a = LifecycleContext.ref) == null ? void 0 : _a.setContext(key, value);
|
|
1522
1316
|
}
|
|
1523
1317
|
function useInject(key, defaultValue) {
|
|
1524
1318
|
var _a;
|
|
1525
|
-
|
|
1526
|
-
return ((_a =
|
|
1319
|
+
assertInsideComponent("useInject", key);
|
|
1320
|
+
return ((_a = LifecycleContext.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
|
|
1527
1321
|
}
|
|
1528
1322
|
function useRef() {
|
|
1529
|
-
const ref =
|
|
1323
|
+
const ref = Re(null);
|
|
1530
1324
|
return ref;
|
|
1531
1325
|
}
|
|
1532
|
-
function
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
function normalizeProps(props) {
|
|
1539
|
-
Object.keys(props).forEach((propKey) => {
|
|
1540
|
-
if (isFunction(props[propKey])) {
|
|
1541
|
-
delete props[propKey];
|
|
1542
|
-
}
|
|
1543
|
-
if (isSignal(props[propKey])) {
|
|
1544
|
-
props[propKey] = props[propKey].value;
|
|
1545
|
-
}
|
|
1546
|
-
});
|
|
1326
|
+
function renderToString(component, props) {
|
|
1327
|
+
renderContext.setSSG();
|
|
1328
|
+
const ssrNode = new SSGNode(component, props || {});
|
|
1329
|
+
const html = ssrNode.mount();
|
|
1330
|
+
renderContext.setClient();
|
|
1331
|
+
return html;
|
|
1547
1332
|
}
|
|
1548
|
-
function
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
const mapKey = path ? String(path) : `${key}`;
|
|
1553
|
-
if (!childNodesMap[mapKey]) childNodesMap[mapKey] = [];
|
|
1554
|
-
const childResult = result.mount();
|
|
1555
|
-
childNodesMap[mapKey].push(
|
|
1556
|
-
isFunction(childResult) ? childResult(prop) : isSignal(childResult) ? childResult.value : childResult
|
|
1557
|
-
);
|
|
1558
|
-
} else {
|
|
1559
|
-
tmpl.template += isFunction(result) ? result(prop) : String(result);
|
|
1333
|
+
function hydrate(component, container) {
|
|
1334
|
+
const rootElement = typeof container === "string" ? document.querySelector(container) : container;
|
|
1335
|
+
if (!rootElement) {
|
|
1336
|
+
throw new Error(`Could not find container: ${container}`);
|
|
1560
1337
|
}
|
|
1338
|
+
renderContext.setSSR();
|
|
1339
|
+
h2(component).mount(rootElement);
|
|
1340
|
+
renderContext.setClient();
|
|
1561
1341
|
}
|
|
1562
|
-
var ServerNode = class _ServerNode extends Hooks {
|
|
1563
|
-
constructor(template2, props = {}, key) {
|
|
1564
|
-
super();
|
|
1565
|
-
this.template = template2;
|
|
1566
|
-
this.props = props;
|
|
1567
|
-
this.key = key;
|
|
1568
|
-
this.childNodesMap = {};
|
|
1569
|
-
this.processedTemplates = {};
|
|
1570
|
-
}
|
|
1571
|
-
/**
|
|
1572
|
-
* Mount and render the component
|
|
1573
|
-
*/
|
|
1574
|
-
mount() {
|
|
1575
|
-
this.initRef();
|
|
1576
|
-
const output = this.render();
|
|
1577
|
-
this.removeRef();
|
|
1578
|
-
return output;
|
|
1579
|
-
}
|
|
1580
|
-
/**
|
|
1581
|
-
* Initialize template entries and props
|
|
1582
|
-
*/
|
|
1583
|
-
initTemplates() {
|
|
1584
|
-
const templateCollection = Array.isArray(this.template) ? this.template.reduce((acc, tmpl, index) => {
|
|
1585
|
-
acc[index + 1] = { template: tmpl };
|
|
1586
|
-
return acc;
|
|
1587
|
-
}, {}) : this.template;
|
|
1588
|
-
if (isObject(templateCollection)) {
|
|
1589
|
-
Object.entries(templateCollection).forEach(([key, tmpl]) => {
|
|
1590
|
-
const prop = __spreadValues2({}, this.props[key]);
|
|
1591
|
-
normalizeProps(prop);
|
|
1592
|
-
if (prop.children) {
|
|
1593
|
-
prop.children.forEach((item) => {
|
|
1594
|
-
const [child, path] = isArray(item) ? item : [item, null];
|
|
1595
|
-
if (isFunction(child)) {
|
|
1596
|
-
const result = child(prop);
|
|
1597
|
-
handleChildResult(result, prop, key, tmpl, this.childNodesMap, path);
|
|
1598
|
-
} else {
|
|
1599
|
-
tmpl.template += isSignal(child) ? child.value : String(child);
|
|
1600
|
-
}
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
this.processedTemplates[key] = {
|
|
1604
|
-
template: tmpl.template,
|
|
1605
|
-
props: prop
|
|
1606
|
-
};
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
* Render component and its children into a string
|
|
1612
|
-
*/
|
|
1613
|
-
render() {
|
|
1614
|
-
if (isFunction(this.template)) {
|
|
1615
|
-
const root = this.template(this.props);
|
|
1616
|
-
return root instanceof _ServerNode ? root.mount() : String(root);
|
|
1617
|
-
}
|
|
1618
|
-
if (this.template instanceof _ServerNode) {
|
|
1619
|
-
return this.template.mount();
|
|
1620
|
-
}
|
|
1621
|
-
this.initTemplates();
|
|
1622
|
-
return Object.entries(this.processedTemplates).map(([key, { template: template2, props }]) => {
|
|
1623
|
-
let content = template2;
|
|
1624
|
-
if (props && Object.keys(props).length > 0) {
|
|
1625
|
-
content += ` ${generateAttributes(props)}`;
|
|
1626
|
-
}
|
|
1627
|
-
if (this.childNodesMap[key]) {
|
|
1628
|
-
content = content.replace("<!>", this.renderChildren(this.childNodesMap[key]));
|
|
1629
|
-
}
|
|
1630
|
-
return content;
|
|
1631
|
-
}).join("");
|
|
1632
|
-
}
|
|
1633
|
-
/**
|
|
1634
|
-
* Render child nodes into a string
|
|
1635
|
-
*/
|
|
1636
|
-
renderChildren(children) {
|
|
1637
|
-
return coerceArray(children).map(String).join("");
|
|
1638
|
-
}
|
|
1639
|
-
};
|
|
1640
1342
|
function ssg(component, props) {
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
return
|
|
1343
|
+
if (renderContext.isSSG) {
|
|
1344
|
+
return new SSGNode(component, props);
|
|
1345
|
+
}
|
|
1346
|
+
return h2(component, props);
|
|
1645
1347
|
}
|
|
1646
1348
|
|
|
1647
1349
|
// src/index.ts
|
|
@@ -1649,19 +1351,14 @@ if (globalThis) {
|
|
|
1649
1351
|
globalThis.__essor_version__ = essor_version;
|
|
1650
1352
|
}
|
|
1651
1353
|
/**
|
|
1652
|
-
* @estjs/
|
|
1653
|
-
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1654
|
-
* @license MIT
|
|
1655
|
-
**/
|
|
1656
|
-
/**
|
|
1657
|
-
* @estjs/signal v0.0.12
|
|
1354
|
+
* @estjs/signal v0.0.13-beta.2
|
|
1658
1355
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1659
1356
|
* @license MIT
|
|
1660
1357
|
**/
|
|
1661
1358
|
/**
|
|
1662
|
-
* @estjs/template v0.0.
|
|
1359
|
+
* @estjs/template v0.0.13-beta.2
|
|
1663
1360
|
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1664
1361
|
* @license MIT
|
|
1665
1362
|
**/
|
|
1666
1363
|
|
|
1667
|
-
export {
|
|
1364
|
+
export { Fragment, Oe as clearReactive, Le as createStore, essor_version, h2 as h, hydrate, isComponent, I as isComputed, isJsxElement, b as isReactive, h as isSignal, onDestroy, onMount, renderToString, Ce as shallowReactive, Re as shallowSignal, We as signalObject, ssg, createTemplate as template, c as toRaw, fe as useBatch, z as useComputed, B as useEffect, useInject, useProvide, L as useReactive, useRef, le as useSignal, De as useWatch };
|