essor 0.0.10-beta.21 → 0.0.10-beta.22
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/LICENSE +20 -20
- package/package.json +4 -4
- package/dist/essor.cjs.js +0 -55
- package/dist/essor.cjs.js.map +0 -1
- package/dist/essor.d.cts +0 -6
- package/dist/essor.d.ts +0 -6
- package/dist/essor.dev.cjs.js +0 -1211
- package/dist/essor.dev.esm.js +0 -1181
- package/dist/essor.esm.js +0 -25
- package/dist/essor.esm.js.map +0 -1
package/dist/essor.dev.esm.js
DELETED
|
@@ -1,1181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* essor v0.0.10-beta.20
|
|
3
|
-
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
4
|
-
* @license MIT
|
|
5
|
-
**/
|
|
6
|
-
|
|
7
|
-
// src/version.ts
|
|
8
|
-
var essor_version = "0.0.10-beta.20";
|
|
9
|
-
|
|
10
|
-
// ../shared/dist/essor-shared.js
|
|
11
|
-
var isObject = (val) => val !== null && typeof val === "object";
|
|
12
|
-
var isArray = Array.isArray;
|
|
13
|
-
function isString(val) {
|
|
14
|
-
return typeof val === "string";
|
|
15
|
-
}
|
|
16
|
-
function isNil(x) {
|
|
17
|
-
return x === null || x === void 0;
|
|
18
|
-
}
|
|
19
|
-
var isFunction = (val) => typeof val === "function";
|
|
20
|
-
function isFalsy(x) {
|
|
21
|
-
return x === false || x === null || x === void 0;
|
|
22
|
-
}
|
|
23
|
-
function coerceArray(data) {
|
|
24
|
-
return Array.isArray(data) ? data.flat() : [data];
|
|
25
|
-
}
|
|
26
|
-
function startsWith(str, searchString) {
|
|
27
|
-
if (!isString(str)) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
return str.indexOf(searchString) === 0;
|
|
31
|
-
}
|
|
32
|
-
var kebabCase = (string) => {
|
|
33
|
-
return string.replaceAll(/[A-Z]+/g, (match, offset) => {
|
|
34
|
-
return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var capitalizeFirstLetter = (inputString) => {
|
|
38
|
-
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// ../signal/dist/signal.dev.esm.js
|
|
42
|
-
var __defProp = Object.defineProperty;
|
|
43
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
44
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
45
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
46
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
47
|
-
var __spreadValues = (a, b) => {
|
|
48
|
-
for (var prop in b || (b = {}))
|
|
49
|
-
if (__hasOwnProp.call(b, prop))
|
|
50
|
-
__defNormalProp(a, prop, b[prop]);
|
|
51
|
-
if (__getOwnPropSymbols)
|
|
52
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
53
|
-
if (__propIsEnum.call(b, prop))
|
|
54
|
-
__defNormalProp(a, prop, b[prop]);
|
|
55
|
-
}
|
|
56
|
-
return a;
|
|
57
|
-
};
|
|
58
|
-
var isObject2 = (val) => val !== null && typeof val === "object";
|
|
59
|
-
var isArray2 = Array.isArray;
|
|
60
|
-
function isString2(val) {
|
|
61
|
-
return typeof val === "string";
|
|
62
|
-
}
|
|
63
|
-
function isNull(val) {
|
|
64
|
-
return val === null;
|
|
65
|
-
}
|
|
66
|
-
function isSet(val) {
|
|
67
|
-
return _toString.call(val) === "[object Set]";
|
|
68
|
-
}
|
|
69
|
-
function isWeakMap(val) {
|
|
70
|
-
return _toString.call(val) === "[object WeakMap]";
|
|
71
|
-
}
|
|
72
|
-
function isWeakSet(val) {
|
|
73
|
-
return _toString.call(val) === "[object WeakSet]";
|
|
74
|
-
}
|
|
75
|
-
function isMap(val) {
|
|
76
|
-
return _toString.call(val) === "[object Map]";
|
|
77
|
-
}
|
|
78
|
-
var isFunction2 = (val) => typeof val === "function";
|
|
79
|
-
var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
|
|
80
|
-
function isHTMLElement(obj) {
|
|
81
|
-
if (!obj) return false;
|
|
82
|
-
return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
83
|
-
}
|
|
84
|
-
var _toString = Object.prototype.toString;
|
|
85
|
-
var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
|
|
86
|
-
var noop2 = Function.prototype;
|
|
87
|
-
function startsWith2(str, searchString) {
|
|
88
|
-
if (!isString2(str)) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
return str.indexOf(searchString) === 0;
|
|
92
|
-
}
|
|
93
|
-
function isExclude(key, exclude) {
|
|
94
|
-
return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
|
|
95
|
-
}
|
|
96
|
-
function warn(msg, ...args) {
|
|
97
|
-
console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
|
|
98
|
-
}
|
|
99
|
-
var activeEffect = null;
|
|
100
|
-
var activeComputed = null;
|
|
101
|
-
var computedMap = /* @__PURE__ */ new WeakMap();
|
|
102
|
-
var signalMap = /* @__PURE__ */ new WeakMap();
|
|
103
|
-
var effectDeps = /* @__PURE__ */ new Set();
|
|
104
|
-
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
105
|
-
var arrayMethods = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"];
|
|
106
|
-
function track(target, key) {
|
|
107
|
-
if (!activeEffect && !activeComputed) return;
|
|
108
|
-
let depsMap = signalMap.get(target);
|
|
109
|
-
if (!depsMap) {
|
|
110
|
-
depsMap = /* @__PURE__ */ new Map();
|
|
111
|
-
signalMap.set(target, depsMap);
|
|
112
|
-
}
|
|
113
|
-
let dep = depsMap.get(key);
|
|
114
|
-
if (!dep) {
|
|
115
|
-
dep = /* @__PURE__ */ new Set();
|
|
116
|
-
depsMap.set(key, dep);
|
|
117
|
-
}
|
|
118
|
-
if (activeEffect) dep.add(activeEffect);
|
|
119
|
-
let computedDepsMap = computedMap.get(target);
|
|
120
|
-
if (!computedDepsMap) {
|
|
121
|
-
computedDepsMap = /* @__PURE__ */ new Map();
|
|
122
|
-
computedMap.set(target, computedDepsMap);
|
|
123
|
-
}
|
|
124
|
-
let computedDeps = computedDepsMap.get(key);
|
|
125
|
-
if (!computedDeps) {
|
|
126
|
-
computedDeps = /* @__PURE__ */ new Set();
|
|
127
|
-
computedDepsMap.set(key, computedDeps);
|
|
128
|
-
}
|
|
129
|
-
if (activeComputed) {
|
|
130
|
-
computedDeps.add(activeComputed);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function trigger(target, key) {
|
|
134
|
-
const depsMap = signalMap.get(target);
|
|
135
|
-
if (!depsMap) return;
|
|
136
|
-
const dep = depsMap.get(key);
|
|
137
|
-
if (dep) {
|
|
138
|
-
dep.forEach((effect) => effectDeps.has(effect) && effect());
|
|
139
|
-
}
|
|
140
|
-
const computedDepsMap = computedMap.get(target);
|
|
141
|
-
if (computedDepsMap) {
|
|
142
|
-
const computeds = computedDepsMap.get(key);
|
|
143
|
-
if (computeds) {
|
|
144
|
-
computeds.forEach((computed) => computed.run());
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
var Signal = class {
|
|
149
|
-
constructor(value, shallow = false) {
|
|
150
|
-
this._value = value;
|
|
151
|
-
this._shallow = shallow;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Get the current value of the Signal and track its usage.
|
|
155
|
-
*/
|
|
156
|
-
get value() {
|
|
157
|
-
track(this, "_sv");
|
|
158
|
-
this.__triggerObject();
|
|
159
|
-
return this._value;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Trigger reactivity for non-primitive and non-HTMLElement values.
|
|
163
|
-
* Recursively applies reactivity to nested objects.
|
|
164
|
-
*/
|
|
165
|
-
__triggerObject() {
|
|
166
|
-
if (!isPrimitive(this._value) && !isHTMLElement(this._value) && !this._shallow) {
|
|
167
|
-
useReactive(this._value);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Set a new value to the Signal and trigger updates if the value has changed.
|
|
172
|
-
*/
|
|
173
|
-
set value(newValue) {
|
|
174
|
-
if (isSignal(newValue)) {
|
|
175
|
-
console.warn("Signal cannot be set to another signal, use .peek() instead");
|
|
176
|
-
newValue = newValue.peek();
|
|
177
|
-
}
|
|
178
|
-
if (hasChanged(newValue, this._value)) {
|
|
179
|
-
this._value = newValue;
|
|
180
|
-
if (!isPrimitive(this._value) && !isHTMLElement(this._value)) {
|
|
181
|
-
this.__triggerObject();
|
|
182
|
-
}
|
|
183
|
-
trigger(this, "_sv");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Peek at the current value of the Signal without tracking it.
|
|
188
|
-
*/
|
|
189
|
-
peek() {
|
|
190
|
-
return this._value;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
function useSignal(value) {
|
|
194
|
-
if (isSignal(value)) {
|
|
195
|
-
return value;
|
|
196
|
-
}
|
|
197
|
-
return new Signal(value);
|
|
198
|
-
}
|
|
199
|
-
function shallowSignal(value) {
|
|
200
|
-
return new Signal(value, true);
|
|
201
|
-
}
|
|
202
|
-
function isSignal(value) {
|
|
203
|
-
return value instanceof Signal;
|
|
204
|
-
}
|
|
205
|
-
var Computed = class {
|
|
206
|
-
constructor(fn) {
|
|
207
|
-
this.fn = fn;
|
|
208
|
-
const prev = activeComputed;
|
|
209
|
-
activeComputed = this;
|
|
210
|
-
this._value = this.fn();
|
|
211
|
-
activeComputed = prev;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Get the current computed value without tracking it.
|
|
215
|
-
*/
|
|
216
|
-
peek() {
|
|
217
|
-
return this._value;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Run the computed function and update the value if it has changed.
|
|
221
|
-
*/
|
|
222
|
-
run() {
|
|
223
|
-
const newValue = this.fn();
|
|
224
|
-
if (hasChanged(newValue, this._value)) {
|
|
225
|
-
this._value = newValue;
|
|
226
|
-
trigger(this, "_cv");
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Get the current computed value and track its usage.
|
|
231
|
-
*/
|
|
232
|
-
get value() {
|
|
233
|
-
track(this, "_cv");
|
|
234
|
-
return this._value;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
function useComputed(fn) {
|
|
238
|
-
return new Computed(fn);
|
|
239
|
-
}
|
|
240
|
-
function isComputed(value) {
|
|
241
|
-
return value instanceof Computed;
|
|
242
|
-
}
|
|
243
|
-
function useEffect(fn) {
|
|
244
|
-
function effectFn() {
|
|
245
|
-
const prev = activeEffect;
|
|
246
|
-
activeEffect = effectFn;
|
|
247
|
-
fn();
|
|
248
|
-
activeEffect = prev;
|
|
249
|
-
}
|
|
250
|
-
effectDeps.add(effectFn);
|
|
251
|
-
effectFn();
|
|
252
|
-
return () => {
|
|
253
|
-
effectDeps.delete(effectFn);
|
|
254
|
-
activeEffect = null;
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function signalObject(initialValues, exclude) {
|
|
258
|
-
const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
|
|
259
|
-
acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
|
|
260
|
-
return acc;
|
|
261
|
-
}, {});
|
|
262
|
-
return signals;
|
|
263
|
-
}
|
|
264
|
-
function unSignal(signal, exclude) {
|
|
265
|
-
if (!signal) return {};
|
|
266
|
-
if (isSignal(signal)) {
|
|
267
|
-
return signal.peek();
|
|
268
|
-
}
|
|
269
|
-
if (isArray2(signal)) {
|
|
270
|
-
return signal.map((value) => unSignal(value, exclude));
|
|
271
|
-
}
|
|
272
|
-
if (isObject2(signal)) {
|
|
273
|
-
return Object.entries(signal).reduce((acc, [key, value]) => {
|
|
274
|
-
if (isExclude(key, exclude)) {
|
|
275
|
-
acc[key] = value;
|
|
276
|
-
} else {
|
|
277
|
-
acc[key] = isSignal(value) ? value.peek() : isReactive(value) ? unReactive(value) : value;
|
|
278
|
-
}
|
|
279
|
-
return acc;
|
|
280
|
-
}, {});
|
|
281
|
-
}
|
|
282
|
-
return signal;
|
|
283
|
-
}
|
|
284
|
-
var REACTIVE_MARKER = Symbol("useReactive");
|
|
285
|
-
function isReactive(obj) {
|
|
286
|
-
return obj && obj[REACTIVE_MARKER] === true;
|
|
287
|
-
}
|
|
288
|
-
function unReactive(obj) {
|
|
289
|
-
if (!isReactive(obj)) {
|
|
290
|
-
return obj;
|
|
291
|
-
}
|
|
292
|
-
return __spreadValues({}, obj);
|
|
293
|
-
}
|
|
294
|
-
function createArrayProxy(initialValue) {
|
|
295
|
-
arrayMethods.forEach((method) => {
|
|
296
|
-
const originalMethod = Array.prototype[method];
|
|
297
|
-
track(initialValue, "length");
|
|
298
|
-
Object.defineProperty(initialValue, method, {
|
|
299
|
-
value(...args) {
|
|
300
|
-
const result = originalMethod.apply(this, args);
|
|
301
|
-
if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].includes(method)) {
|
|
302
|
-
trigger(initialValue, "length");
|
|
303
|
-
}
|
|
304
|
-
return result;
|
|
305
|
-
},
|
|
306
|
-
enumerable: false,
|
|
307
|
-
writable: true,
|
|
308
|
-
configurable: true
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function useReactive(initialValue, exclude) {
|
|
313
|
-
return reactive(initialValue, exclude, false);
|
|
314
|
-
}
|
|
315
|
-
function shallowReactive(initialValue, exclude) {
|
|
316
|
-
return reactive(initialValue, exclude, true);
|
|
317
|
-
}
|
|
318
|
-
function reactive(initialValue, exclude, shallow = false) {
|
|
319
|
-
if (!isObject2(initialValue)) {
|
|
320
|
-
return initialValue;
|
|
321
|
-
}
|
|
322
|
-
if (isReactive(initialValue)) {
|
|
323
|
-
return initialValue;
|
|
324
|
-
}
|
|
325
|
-
if (reactiveMap.has(initialValue)) {
|
|
326
|
-
return reactiveMap.get(initialValue);
|
|
327
|
-
}
|
|
328
|
-
if (Array.isArray(initialValue)) {
|
|
329
|
-
createArrayProxy(initialValue);
|
|
330
|
-
}
|
|
331
|
-
if (isSet(initialValue) || isMap(initialValue) || isWeakSet(initialValue) || isWeakMap(initialValue)) {
|
|
332
|
-
return initialValue;
|
|
333
|
-
}
|
|
334
|
-
const handler = {
|
|
335
|
-
get(target, key, receiver) {
|
|
336
|
-
if (key === REACTIVE_MARKER || startsWith2(key, "_")) return true;
|
|
337
|
-
const getValue = Reflect.get(target, key, receiver);
|
|
338
|
-
const value = isSignal(getValue) ? getValue.value : getValue;
|
|
339
|
-
if (isExclude(key, exclude)) {
|
|
340
|
-
return value;
|
|
341
|
-
}
|
|
342
|
-
track(target, key);
|
|
343
|
-
if (isObject2(value) && !shallow) {
|
|
344
|
-
return useReactive(value);
|
|
345
|
-
}
|
|
346
|
-
return value;
|
|
347
|
-
},
|
|
348
|
-
set(target, key, value, receiver) {
|
|
349
|
-
if (isExclude(key, exclude)) {
|
|
350
|
-
Reflect.set(target, key, value, receiver);
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
let oldValue = Reflect.get(target, key, receiver);
|
|
354
|
-
if (isSignal(oldValue)) {
|
|
355
|
-
oldValue = oldValue.value;
|
|
356
|
-
}
|
|
357
|
-
if (isSignal(value)) {
|
|
358
|
-
value = value.value;
|
|
359
|
-
}
|
|
360
|
-
const obj = Reflect.set(target, key, value, receiver);
|
|
361
|
-
if (hasChanged(value, oldValue)) {
|
|
362
|
-
trigger(target, key);
|
|
363
|
-
}
|
|
364
|
-
return obj;
|
|
365
|
-
},
|
|
366
|
-
deleteProperty(target, key) {
|
|
367
|
-
const oldValue = Reflect.get(target, key);
|
|
368
|
-
const result = Reflect.deleteProperty(target, key);
|
|
369
|
-
if (oldValue !== void 0) {
|
|
370
|
-
trigger(target, key);
|
|
371
|
-
}
|
|
372
|
-
return result;
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
const proxy = new Proxy(initialValue, handler);
|
|
376
|
-
reactiveMap.set(initialValue, proxy);
|
|
377
|
-
return proxy;
|
|
378
|
-
}
|
|
379
|
-
function useWatch(source, cb, options) {
|
|
380
|
-
return doWatch(source, cb, options);
|
|
381
|
-
}
|
|
382
|
-
function doWatch(source, cb, options) {
|
|
383
|
-
let getter;
|
|
384
|
-
if (isSignal(source) || isComputed(source)) {
|
|
385
|
-
getter = () => source.value;
|
|
386
|
-
} else if (isReactive(source)) {
|
|
387
|
-
getter = () => __spreadValues({}, source);
|
|
388
|
-
} else if (isArray2(source)) {
|
|
389
|
-
getter = () => source.map((s) => {
|
|
390
|
-
if (isSignal(s) || isComputed(s)) return s.value;
|
|
391
|
-
if (isReactive(s)) return __spreadValues({}, s);
|
|
392
|
-
if (isFunction2(s)) return s();
|
|
393
|
-
return warn("Invalid source", s);
|
|
394
|
-
});
|
|
395
|
-
} else if (isFunction2(source)) {
|
|
396
|
-
getter = source;
|
|
397
|
-
} else {
|
|
398
|
-
warn("Invalid source type", source);
|
|
399
|
-
getter = noop2;
|
|
400
|
-
}
|
|
401
|
-
let oldValue;
|
|
402
|
-
const effectFn = () => {
|
|
403
|
-
const newValue = getter();
|
|
404
|
-
if ((options == null ? void 0 : options.deep) || hasChanged(newValue, oldValue)) {
|
|
405
|
-
cb && cb(newValue, oldValue);
|
|
406
|
-
oldValue = newValue;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
const stop = useEffect(effectFn);
|
|
410
|
-
if (options == null ? void 0 : options.immediate) {
|
|
411
|
-
effectFn();
|
|
412
|
-
}
|
|
413
|
-
return stop;
|
|
414
|
-
}
|
|
415
|
-
var _id = 0;
|
|
416
|
-
var StoreMap = /* @__PURE__ */ new Map();
|
|
417
|
-
function createOptionsStore(options) {
|
|
418
|
-
const { state, getters, actions } = options;
|
|
419
|
-
const initState = __spreadValues({}, state != null ? state : {});
|
|
420
|
-
const reactiveState = useReactive(state != null ? state : {});
|
|
421
|
-
const subscriptions = [];
|
|
422
|
-
const actionCallbacks = [];
|
|
423
|
-
const default_actions = {
|
|
424
|
-
patch$(payload) {
|
|
425
|
-
Object.assign(reactiveState, payload);
|
|
426
|
-
subscriptions.forEach((callback) => callback(reactiveState));
|
|
427
|
-
actionCallbacks.forEach((callback) => callback(reactiveState));
|
|
428
|
-
},
|
|
429
|
-
subscribe$(callback) {
|
|
430
|
-
subscriptions.push(callback);
|
|
431
|
-
},
|
|
432
|
-
unsubscribe$(callback) {
|
|
433
|
-
const index = subscriptions.indexOf(callback);
|
|
434
|
-
if (index !== -1) {
|
|
435
|
-
subscriptions.splice(index, 1);
|
|
436
|
-
}
|
|
437
|
-
},
|
|
438
|
-
onAction$(callback) {
|
|
439
|
-
actionCallbacks.push(callback);
|
|
440
|
-
},
|
|
441
|
-
reset$() {
|
|
442
|
-
Object.assign(reactiveState, initState);
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
const store = __spreadValues({
|
|
446
|
-
state: reactiveState
|
|
447
|
-
}, default_actions);
|
|
448
|
-
for (const key in getters) {
|
|
449
|
-
const getter = getters[key];
|
|
450
|
-
if (getter) {
|
|
451
|
-
useWatch(useComputed(getter.bind(reactiveState, reactiveState)), (value) => {
|
|
452
|
-
store[key] = value;
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
for (const key in actions) {
|
|
457
|
-
const action = actions[key];
|
|
458
|
-
if (action) {
|
|
459
|
-
store[key] = action.bind(reactiveState);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
StoreMap.set(_id, store);
|
|
463
|
-
++_id;
|
|
464
|
-
return store;
|
|
465
|
-
}
|
|
466
|
-
function createStore(options) {
|
|
467
|
-
return function() {
|
|
468
|
-
if (StoreMap.has(_id)) {
|
|
469
|
-
return StoreMap.get(_id);
|
|
470
|
-
}
|
|
471
|
-
return createOptionsStore(options);
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// ../template/dist/template.dev.esm.js
|
|
476
|
-
var _ComponentNode = class _ComponentNode2 {
|
|
477
|
-
constructor(template2, props) {
|
|
478
|
-
this.template = template2;
|
|
479
|
-
this.props = props;
|
|
480
|
-
this.proxyProps = {};
|
|
481
|
-
this.context = {};
|
|
482
|
-
this.emitter = /* @__PURE__ */ new Set();
|
|
483
|
-
this.mounted = false;
|
|
484
|
-
this.rootNode = null;
|
|
485
|
-
this.hooks = {
|
|
486
|
-
mounted: /* @__PURE__ */ new Set(),
|
|
487
|
-
destroy: /* @__PURE__ */ new Set()
|
|
488
|
-
};
|
|
489
|
-
this.trackMap = /* @__PURE__ */ new Map();
|
|
490
|
-
this.proxyProps = signalObject(
|
|
491
|
-
props,
|
|
492
|
-
(key) => startsWith(key, "on") || startsWith(key, "update")
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
addEventListener() {
|
|
496
|
-
}
|
|
497
|
-
removeEventListener() {
|
|
498
|
-
}
|
|
499
|
-
get firstChild() {
|
|
500
|
-
var _a, _b;
|
|
501
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
|
|
502
|
-
}
|
|
503
|
-
get isConnected() {
|
|
504
|
-
var _a, _b;
|
|
505
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
|
|
506
|
-
}
|
|
507
|
-
addHook(hook, cb) {
|
|
508
|
-
var _a;
|
|
509
|
-
(_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
|
|
510
|
-
}
|
|
511
|
-
getContext(context) {
|
|
512
|
-
return _ComponentNode2.context[context];
|
|
513
|
-
}
|
|
514
|
-
setContext(context, value) {
|
|
515
|
-
_ComponentNode2.context[context] = value;
|
|
516
|
-
}
|
|
517
|
-
inheritNode(node) {
|
|
518
|
-
this.context = node.context;
|
|
519
|
-
this.hooks = node.hooks;
|
|
520
|
-
Object.assign(this.proxyProps, node.proxyProps);
|
|
521
|
-
this.rootNode = node.rootNode;
|
|
522
|
-
this.trackMap = node.trackMap;
|
|
523
|
-
const props = this.props;
|
|
524
|
-
this.props = node.props;
|
|
525
|
-
this.patchProps(props);
|
|
526
|
-
}
|
|
527
|
-
mount(parent, before) {
|
|
528
|
-
var _a, _b, _c, _d;
|
|
529
|
-
if (!isFunction(this.template)) {
|
|
530
|
-
throw new Error("Template must be a function");
|
|
531
|
-
}
|
|
532
|
-
if (this.isConnected) {
|
|
533
|
-
return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
|
|
534
|
-
}
|
|
535
|
-
_ComponentNode2.ref = this;
|
|
536
|
-
this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
|
|
537
|
-
_ComponentNode2.ref = null;
|
|
538
|
-
this.mounted = true;
|
|
539
|
-
const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
|
|
540
|
-
this.hooks.mounted.forEach((handler) => handler());
|
|
541
|
-
this.patchProps(this.props);
|
|
542
|
-
return mountedNode;
|
|
543
|
-
}
|
|
544
|
-
unmount() {
|
|
545
|
-
var _a;
|
|
546
|
-
this.hooks.destroy.forEach((handler) => handler());
|
|
547
|
-
Object.values(this.hooks).forEach((set) => set.clear());
|
|
548
|
-
(_a = this.rootNode) == null ? void 0 : _a.unmount();
|
|
549
|
-
this.rootNode = null;
|
|
550
|
-
this.proxyProps = {};
|
|
551
|
-
this.mounted = false;
|
|
552
|
-
this.emitter.forEach((emitter) => emitter());
|
|
553
|
-
}
|
|
554
|
-
getNodeTrack(trackKey, suppressCleanupCall) {
|
|
555
|
-
let track2 = this.trackMap.get(trackKey);
|
|
556
|
-
if (!track2) {
|
|
557
|
-
track2 = { cleanup: () => {
|
|
558
|
-
} };
|
|
559
|
-
this.trackMap.set(trackKey, track2);
|
|
560
|
-
}
|
|
561
|
-
if (!suppressCleanupCall) {
|
|
562
|
-
track2.cleanup();
|
|
563
|
-
}
|
|
564
|
-
return track2;
|
|
565
|
-
}
|
|
566
|
-
patchProps(props) {
|
|
567
|
-
var _a, _b, _c, _d, _e;
|
|
568
|
-
for (const [key, prop] of Object.entries(props)) {
|
|
569
|
-
if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
|
|
570
|
-
const event = key.slice(2).toLowerCase();
|
|
571
|
-
const listener = prop;
|
|
572
|
-
const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
|
|
573
|
-
this.emitter.add(cleanup);
|
|
574
|
-
} else if (key === "ref") {
|
|
575
|
-
if (isSignal(prop)) {
|
|
576
|
-
props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
|
|
577
|
-
} else if (isFunction(prop)) {
|
|
578
|
-
props[key]((_c = this.rootNode) == null ? void 0 : _c.nodes[0]);
|
|
579
|
-
}
|
|
580
|
-
} else if (startsWith(key, "update")) {
|
|
581
|
-
props[key] = isSignal(prop) ? prop.value : prop;
|
|
582
|
-
} else if (key !== "children") {
|
|
583
|
-
const newValue = (_e = (_d = this.proxyProps)[key]) != null ? _e : _d[key] = useSignal(prop);
|
|
584
|
-
const track2 = this.getNodeTrack(key);
|
|
585
|
-
track2.cleanup = useEffect(() => {
|
|
586
|
-
newValue.value = isFunction(prop) ? prop() : prop;
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
this.props = props;
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
_ComponentNode.ref = null;
|
|
594
|
-
_ComponentNode.context = {};
|
|
595
|
-
var ComponentNode = _ComponentNode;
|
|
596
|
-
function h(_template, props) {
|
|
597
|
-
if (isString(_template)) {
|
|
598
|
-
if (isHtmlTagName(_template)) {
|
|
599
|
-
_template = convertToHtmlTag(_template);
|
|
600
|
-
props = {
|
|
601
|
-
1: props
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
if (_template === "") {
|
|
605
|
-
props = {
|
|
606
|
-
0: props
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
_template = template(_template);
|
|
610
|
-
}
|
|
611
|
-
return isFunction(_template) ? new ComponentNode(_template, props) : new TemplateNode(_template, props);
|
|
612
|
-
}
|
|
613
|
-
function isJsxElement(node) {
|
|
614
|
-
return node instanceof ComponentNode || node instanceof TemplateNode;
|
|
615
|
-
}
|
|
616
|
-
function template(html) {
|
|
617
|
-
html = closeHtmlTags(html);
|
|
618
|
-
const template2 = document.createElement("template");
|
|
619
|
-
template2.innerHTML = html;
|
|
620
|
-
return template2;
|
|
621
|
-
}
|
|
622
|
-
function Fragment(props) {
|
|
623
|
-
return props.children;
|
|
624
|
-
}
|
|
625
|
-
var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
626
|
-
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";
|
|
627
|
-
function coerceNode(data) {
|
|
628
|
-
if (isJsxElement(data) || data instanceof Node) {
|
|
629
|
-
return data;
|
|
630
|
-
}
|
|
631
|
-
const text = isFalsy(data) ? "" : String(data);
|
|
632
|
-
return document.createTextNode(text);
|
|
633
|
-
}
|
|
634
|
-
function insertChild(parent, child, before = null) {
|
|
635
|
-
const beforeNode = isJsxElement(before) ? before.firstChild : before;
|
|
636
|
-
if (isJsxElement(child)) {
|
|
637
|
-
child.mount(parent, beforeNode);
|
|
638
|
-
} else if (beforeNode) {
|
|
639
|
-
beforeNode.before(child);
|
|
640
|
-
} else {
|
|
641
|
-
parent.append(child);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function removeChild(child) {
|
|
645
|
-
if (isJsxElement(child)) {
|
|
646
|
-
child.unmount();
|
|
647
|
-
} else {
|
|
648
|
-
const parent = child.parentNode;
|
|
649
|
-
if (parent) {
|
|
650
|
-
child.remove();
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
function replaceChild(parent, node, child) {
|
|
655
|
-
insertChild(parent, node, child);
|
|
656
|
-
removeChild(child);
|
|
657
|
-
}
|
|
658
|
-
function setAttribute(element, attr, value) {
|
|
659
|
-
if (attr === "class") {
|
|
660
|
-
if (typeof value === "string") {
|
|
661
|
-
element.className = value;
|
|
662
|
-
} else if (Array.isArray(value)) {
|
|
663
|
-
element.className = value.join(" ");
|
|
664
|
-
} else if (value && typeof value === "object") {
|
|
665
|
-
element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
|
|
666
|
-
}
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
if (attr === "style") {
|
|
670
|
-
if (typeof value === "string") {
|
|
671
|
-
element.style.cssText = value;
|
|
672
|
-
} else if (value && typeof value === "object") {
|
|
673
|
-
const obj = value;
|
|
674
|
-
Object.keys(obj).forEach((key) => {
|
|
675
|
-
element.style.setProperty(kebabCase(key), String(obj[key]));
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
if (isFalsy(value)) {
|
|
681
|
-
element.removeAttribute(attr);
|
|
682
|
-
} else if (value === true) {
|
|
683
|
-
element.setAttribute(attr, "");
|
|
684
|
-
} else {
|
|
685
|
-
if (element instanceof HTMLInputElement) {
|
|
686
|
-
element.value = String(value);
|
|
687
|
-
} else {
|
|
688
|
-
element.setAttribute(attr, String(value));
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
function binNode(node, setter) {
|
|
693
|
-
if (node instanceof HTMLInputElement) {
|
|
694
|
-
switch (node.type) {
|
|
695
|
-
case "checkbox":
|
|
696
|
-
return addEventListener(node, "change", () => {
|
|
697
|
-
setter(Boolean(node.checked));
|
|
698
|
-
});
|
|
699
|
-
case "date":
|
|
700
|
-
return addEventListener(node, "change", () => {
|
|
701
|
-
setter(node.value ? node.value : "");
|
|
702
|
-
});
|
|
703
|
-
case "file":
|
|
704
|
-
return addEventListener(node, "change", () => {
|
|
705
|
-
if (node.files) {
|
|
706
|
-
setter(node.files);
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
case "number":
|
|
710
|
-
return addEventListener(node, "input", () => {
|
|
711
|
-
const value = Number.parseFloat(node.value);
|
|
712
|
-
setter(Number.isNaN(value) ? "" : String(value));
|
|
713
|
-
});
|
|
714
|
-
case "radio":
|
|
715
|
-
return addEventListener(node, "change", () => {
|
|
716
|
-
setter(node.checked ? node.value : "");
|
|
717
|
-
});
|
|
718
|
-
case "text":
|
|
719
|
-
return addEventListener(node, "input", () => {
|
|
720
|
-
setter(node.value);
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
if (node instanceof HTMLSelectElement) {
|
|
725
|
-
return addEventListener(node, "change", () => {
|
|
726
|
-
setter(node.value);
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
if (node instanceof HTMLTextAreaElement) {
|
|
730
|
-
return addEventListener(node, "input", () => {
|
|
731
|
-
setter(node.value);
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
var p = Promise.resolve();
|
|
736
|
-
function nextTick(fn) {
|
|
737
|
-
return fn ? p.then(fn) : p;
|
|
738
|
-
}
|
|
739
|
-
function addEventListener(node, eventName, handler) {
|
|
740
|
-
node.addEventListener(eventName, handler);
|
|
741
|
-
return () => node.removeEventListener(eventName, handler);
|
|
742
|
-
}
|
|
743
|
-
function closeHtmlTags(input) {
|
|
744
|
-
const selfClosingTagList = selfClosingTags.split(",");
|
|
745
|
-
const tagStack = [];
|
|
746
|
-
const output = [];
|
|
747
|
-
const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
|
|
748
|
-
let lastIndex = 0;
|
|
749
|
-
while (true) {
|
|
750
|
-
const match = tagPattern.exec(input);
|
|
751
|
-
if (!match) break;
|
|
752
|
-
const [fullMatch, tagName] = match;
|
|
753
|
-
const isEndTag = fullMatch[1] === "/";
|
|
754
|
-
output.push(input.slice(lastIndex, match.index));
|
|
755
|
-
lastIndex = match.index + fullMatch.length;
|
|
756
|
-
if (isEndTag) {
|
|
757
|
-
while (tagStack.length > 0 && tagStack[tagStack.length - 1] !== tagName) {
|
|
758
|
-
const unclosedTag = tagStack.pop();
|
|
759
|
-
if (unclosedTag) {
|
|
760
|
-
output.push(`</${unclosedTag}>`);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
if (tagStack.length > 0) {
|
|
764
|
-
tagStack.pop();
|
|
765
|
-
}
|
|
766
|
-
} else if (!selfClosingTagList.includes(tagName)) {
|
|
767
|
-
tagStack.push(tagName);
|
|
768
|
-
}
|
|
769
|
-
output.push(fullMatch);
|
|
770
|
-
}
|
|
771
|
-
output.push(input.slice(lastIndex));
|
|
772
|
-
while (tagStack.length > 0) {
|
|
773
|
-
const unclosedTag = tagStack.pop();
|
|
774
|
-
if (unclosedTag) {
|
|
775
|
-
output.push(`</${unclosedTag}>`);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
return output.join("");
|
|
779
|
-
}
|
|
780
|
-
function isHtmlTagName(tagName) {
|
|
781
|
-
const htmlTagsList = htmlTags.split(",");
|
|
782
|
-
return htmlTagsList.includes(tagName);
|
|
783
|
-
}
|
|
784
|
-
function convertToHtmlTag(tagName) {
|
|
785
|
-
const selfClosingTagList = selfClosingTags.split(",");
|
|
786
|
-
if (selfClosingTagList.includes(tagName)) {
|
|
787
|
-
return `<${tagName}/>`;
|
|
788
|
-
} else {
|
|
789
|
-
return `<${tagName}></${tagName}>`;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function patchChildren(parent, childrenMap, nextChildren, before) {
|
|
793
|
-
const result = /* @__PURE__ */ new Map();
|
|
794
|
-
const children = Array.from(childrenMap.values());
|
|
795
|
-
const childrenLength = children.length;
|
|
796
|
-
if (childrenMap.size > 0 && nextChildren.length === 0) {
|
|
797
|
-
if (parent.childNodes.length === childrenLength + (before ? 1 : 0)) {
|
|
798
|
-
parent.innerHTML = "";
|
|
799
|
-
if (before) {
|
|
800
|
-
insertChild(parent, before);
|
|
801
|
-
}
|
|
802
|
-
} else {
|
|
803
|
-
const range = document.createRange();
|
|
804
|
-
const child = children[0];
|
|
805
|
-
const start = isJsxElement(child) ? child.firstChild : child;
|
|
806
|
-
range.setStartBefore(start);
|
|
807
|
-
if (before) {
|
|
808
|
-
range.setEndBefore(before);
|
|
809
|
-
} else {
|
|
810
|
-
range.setEndAfter(parent);
|
|
811
|
-
}
|
|
812
|
-
range.deleteContents();
|
|
813
|
-
}
|
|
814
|
-
children.forEach((node) => {
|
|
815
|
-
if (isJsxElement(node)) {
|
|
816
|
-
node.unmount();
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
return result;
|
|
820
|
-
}
|
|
821
|
-
const replaces = [];
|
|
822
|
-
const nextChildrenMap = mapKeys(nextChildren);
|
|
823
|
-
let childIndex = 0;
|
|
824
|
-
for (let [i, child] of nextChildren.entries()) {
|
|
825
|
-
let currChild = children[childIndex];
|
|
826
|
-
let currKey = getKey(currChild, i);
|
|
827
|
-
while (currChild && !nextChildrenMap.has(currKey)) {
|
|
828
|
-
removeChild(currChild);
|
|
829
|
-
childrenMap.delete(currKey);
|
|
830
|
-
currChild = children[++childIndex];
|
|
831
|
-
currKey = getKey(currChild, i);
|
|
832
|
-
}
|
|
833
|
-
const key = getKey(child, i);
|
|
834
|
-
const origChild = childrenMap.get(key);
|
|
835
|
-
if (origChild) {
|
|
836
|
-
child = patch(parent, origChild, child);
|
|
837
|
-
}
|
|
838
|
-
if (currChild) {
|
|
839
|
-
if (currChild === origChild) {
|
|
840
|
-
childIndex++;
|
|
841
|
-
} else {
|
|
842
|
-
const placeholder = document.createComment("");
|
|
843
|
-
insertChild(parent, placeholder, currChild);
|
|
844
|
-
replaces.push([placeholder, child]);
|
|
845
|
-
}
|
|
846
|
-
} else {
|
|
847
|
-
insertChild(parent, child, before);
|
|
848
|
-
}
|
|
849
|
-
result.set(key, child);
|
|
850
|
-
}
|
|
851
|
-
replaces.forEach(([placeholder, child]) => replaceChild(parent, child, placeholder));
|
|
852
|
-
childrenMap.forEach((child, key) => {
|
|
853
|
-
if (child.isConnected && !result.has(key)) {
|
|
854
|
-
removeChild(child);
|
|
855
|
-
}
|
|
856
|
-
});
|
|
857
|
-
return result;
|
|
858
|
-
}
|
|
859
|
-
function patch(parent, node, next) {
|
|
860
|
-
if (node === next) {
|
|
861
|
-
return node;
|
|
862
|
-
}
|
|
863
|
-
if (isJsxElement(node) && isJsxElement(next) && node.template === next.template) {
|
|
864
|
-
next.inheritNode(node);
|
|
865
|
-
return next;
|
|
866
|
-
}
|
|
867
|
-
if (node instanceof Text && next instanceof Text) {
|
|
868
|
-
if (node.textContent !== next.textContent) {
|
|
869
|
-
node.textContent = next.textContent;
|
|
870
|
-
}
|
|
871
|
-
return node;
|
|
872
|
-
}
|
|
873
|
-
replaceChild(parent, next, node);
|
|
874
|
-
return next;
|
|
875
|
-
}
|
|
876
|
-
function mapKeys(children) {
|
|
877
|
-
const result = /* @__PURE__ */ new Map();
|
|
878
|
-
for (const [i, child] of children.entries()) {
|
|
879
|
-
const key = getKey(child, i);
|
|
880
|
-
result.set(key, child);
|
|
881
|
-
}
|
|
882
|
-
return result;
|
|
883
|
-
}
|
|
884
|
-
function getKey(node, index) {
|
|
885
|
-
const id = node instanceof Element ? node.id : void 0;
|
|
886
|
-
const result = id === "" ? void 0 : id;
|
|
887
|
-
return result != null ? result : `_$${index}$`;
|
|
888
|
-
}
|
|
889
|
-
var TemplateNode = class _TemplateNode {
|
|
890
|
-
constructor(template2, props) {
|
|
891
|
-
this.template = template2;
|
|
892
|
-
this.props = props;
|
|
893
|
-
this.treeMap = /* @__PURE__ */ new Map();
|
|
894
|
-
this.mounted = false;
|
|
895
|
-
this.nodes = [];
|
|
896
|
-
this.provides = {};
|
|
897
|
-
this.trackMap = /* @__PURE__ */ new Map();
|
|
898
|
-
this.parent = null;
|
|
899
|
-
}
|
|
900
|
-
get firstChild() {
|
|
901
|
-
var _a;
|
|
902
|
-
return (_a = this.nodes[0]) != null ? _a : null;
|
|
903
|
-
}
|
|
904
|
-
get isConnected() {
|
|
905
|
-
return this.mounted;
|
|
906
|
-
}
|
|
907
|
-
addEventListener() {
|
|
908
|
-
}
|
|
909
|
-
removeEventListener() {
|
|
910
|
-
}
|
|
911
|
-
unmount() {
|
|
912
|
-
this.trackMap.forEach((track2) => {
|
|
913
|
-
var _a, _b;
|
|
914
|
-
(_a = track2.cleanup) == null ? void 0 : _a.call(track2);
|
|
915
|
-
(_b = track2.lastNodes) == null ? void 0 : _b.forEach((node) => {
|
|
916
|
-
if (track2.isRoot) {
|
|
917
|
-
removeChild(node);
|
|
918
|
-
} else if (node instanceof _TemplateNode) {
|
|
919
|
-
node.unmount();
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
this.trackMap.clear();
|
|
924
|
-
this.treeMap.clear();
|
|
925
|
-
this.nodes.forEach((node) => removeChild(node));
|
|
926
|
-
this.nodes = [];
|
|
927
|
-
this.mounted = false;
|
|
928
|
-
}
|
|
929
|
-
mount(parent, before) {
|
|
930
|
-
var _a;
|
|
931
|
-
this.parent = parent;
|
|
932
|
-
if (this.isConnected) {
|
|
933
|
-
this.nodes.forEach((node) => insertChild(parent, node, before));
|
|
934
|
-
return this.nodes;
|
|
935
|
-
}
|
|
936
|
-
const cloneNode = this.template.content.cloneNode(true);
|
|
937
|
-
const firstChild = cloneNode.firstChild;
|
|
938
|
-
if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
|
|
939
|
-
firstChild.remove();
|
|
940
|
-
firstChild == null ? void 0 : firstChild.childNodes.forEach((node) => {
|
|
941
|
-
cloneNode.append(node);
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
this.nodes = Array.from(cloneNode.childNodes);
|
|
945
|
-
this.mapNodeTree(parent, cloneNode);
|
|
946
|
-
insertChild(parent, cloneNode, before);
|
|
947
|
-
this.patchNodes(this.props);
|
|
948
|
-
this.mounted = true;
|
|
949
|
-
return this.nodes;
|
|
950
|
-
}
|
|
951
|
-
mapNodeTree(parent, tree) {
|
|
952
|
-
let index = 1;
|
|
953
|
-
this.treeMap.set(0, parent);
|
|
954
|
-
const walk = (node) => {
|
|
955
|
-
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
|
956
|
-
this.treeMap.set(index++, node);
|
|
957
|
-
}
|
|
958
|
-
let child = node.firstChild;
|
|
959
|
-
while (child) {
|
|
960
|
-
walk(child);
|
|
961
|
-
child = child.nextSibling;
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
walk(tree);
|
|
965
|
-
}
|
|
966
|
-
patchNodes(props) {
|
|
967
|
-
for (const key in props) {
|
|
968
|
-
const index = Number(key);
|
|
969
|
-
const node = this.treeMap.get(index);
|
|
970
|
-
if (node) {
|
|
971
|
-
const value = this.props[key];
|
|
972
|
-
this.patchNode(key, node, value, index === 0);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
this.props = props;
|
|
976
|
-
}
|
|
977
|
-
getNodeTrack(trackKey, trackLastNodes, isRoot) {
|
|
978
|
-
var _a;
|
|
979
|
-
let track2 = this.trackMap.get(trackKey);
|
|
980
|
-
if (!track2) {
|
|
981
|
-
track2 = { cleanup: () => {
|
|
982
|
-
} };
|
|
983
|
-
if (trackLastNodes) {
|
|
984
|
-
track2.lastNodes = /* @__PURE__ */ new Map();
|
|
985
|
-
}
|
|
986
|
-
if (isRoot) {
|
|
987
|
-
track2.isRoot = true;
|
|
988
|
-
}
|
|
989
|
-
this.trackMap.set(trackKey, track2);
|
|
990
|
-
}
|
|
991
|
-
(_a = track2.cleanup) == null ? void 0 : _a.call(track2);
|
|
992
|
-
return track2;
|
|
993
|
-
}
|
|
994
|
-
inheritNode(node) {
|
|
995
|
-
this.mounted = node.mounted;
|
|
996
|
-
this.nodes = node.nodes;
|
|
997
|
-
this.trackMap = node.trackMap;
|
|
998
|
-
this.treeMap = node.treeMap;
|
|
999
|
-
const props = this.props;
|
|
1000
|
-
this.props = node.props;
|
|
1001
|
-
this.patchNodes(props);
|
|
1002
|
-
}
|
|
1003
|
-
patchNode(key, node, props, isRoot) {
|
|
1004
|
-
for (const attr in props) {
|
|
1005
|
-
if (attr === "children" && props.children) {
|
|
1006
|
-
if (!isArray(props.children)) {
|
|
1007
|
-
const trackKey = `${key}:${attr}:${0}`;
|
|
1008
|
-
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1009
|
-
patchChild(track2, node, props.children, null);
|
|
1010
|
-
} else {
|
|
1011
|
-
props.children.filter(Boolean).forEach((item, index) => {
|
|
1012
|
-
var _a;
|
|
1013
|
-
const [child, path] = isArray(item) ? item : [item, null];
|
|
1014
|
-
const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
|
|
1015
|
-
const trackKey = `${key}:${attr}:${index}`;
|
|
1016
|
-
const track2 = this.getNodeTrack(trackKey, true, isRoot);
|
|
1017
|
-
patchChild(track2, node, child, before);
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
} else if (attr === "ref") {
|
|
1021
|
-
if (isSignal(props[attr])) {
|
|
1022
|
-
props[attr].value = node;
|
|
1023
|
-
} else if (isFunction(props[attr])) {
|
|
1024
|
-
props[attr](node);
|
|
1025
|
-
}
|
|
1026
|
-
} else if (startsWith(attr, "on")) {
|
|
1027
|
-
const eventName = attr.slice(2).toLocaleLowerCase();
|
|
1028
|
-
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1029
|
-
const listener = props[attr];
|
|
1030
|
-
track2.cleanup = addEventListener(node, eventName, listener);
|
|
1031
|
-
} else if (!startsWith(attr, "update")) {
|
|
1032
|
-
const track2 = this.getNodeTrack(`${key}:${attr}`);
|
|
1033
|
-
const val = props[attr];
|
|
1034
|
-
const triggerValue = isSignal(val) ? val : useSignal(val);
|
|
1035
|
-
patchAttribute(track2, node, attr, triggerValue.value);
|
|
1036
|
-
const cleanup = useEffect(() => {
|
|
1037
|
-
triggerValue.value = isSignal(val) ? val.value : val;
|
|
1038
|
-
patchAttribute(track2, node, attr, triggerValue.value);
|
|
1039
|
-
});
|
|
1040
|
-
let cleanupBind;
|
|
1041
|
-
const updateKey = `update${capitalizeFirstLetter(attr)}`;
|
|
1042
|
-
if (props[updateKey]) {
|
|
1043
|
-
cleanupBind = binNode(node, (value) => {
|
|
1044
|
-
props[updateKey](value);
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
track2.cleanup = () => {
|
|
1048
|
-
cleanup && cleanup();
|
|
1049
|
-
cleanupBind && cleanupBind();
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
function patchAttribute(track2, node, attr, data) {
|
|
1056
|
-
const element = node;
|
|
1057
|
-
if (!element.setAttribute) {
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
if (isFunction(data)) {
|
|
1061
|
-
track2.cleanup = useEffect(() => {
|
|
1062
|
-
setAttribute(element, attr, data());
|
|
1063
|
-
});
|
|
1064
|
-
} else {
|
|
1065
|
-
setAttribute(element, attr, data);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
function patchChild(track2, parent, child, before) {
|
|
1069
|
-
if (isFunction(child)) {
|
|
1070
|
-
track2.cleanup = useEffect(() => {
|
|
1071
|
-
const nextNodes = coerceArray(child()).map(coerceNode);
|
|
1072
|
-
track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
|
|
1073
|
-
});
|
|
1074
|
-
} else {
|
|
1075
|
-
coerceArray(child).forEach((node, i) => {
|
|
1076
|
-
const newNode = coerceNode(node);
|
|
1077
|
-
track2.lastNodes.set(String(i), newNode);
|
|
1078
|
-
insertChild(parent, newNode, before);
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
function onMount(cb) {
|
|
1083
|
-
var _a;
|
|
1084
|
-
throwIfOutsideComponent("onMounted");
|
|
1085
|
-
(_a = ComponentNode.ref) == null ? void 0 : _a.addHook("mounted", cb);
|
|
1086
|
-
}
|
|
1087
|
-
function onDestroy(cb) {
|
|
1088
|
-
var _a;
|
|
1089
|
-
throwIfOutsideComponent("onDestroy");
|
|
1090
|
-
(_a = ComponentNode.ref) == null ? void 0 : _a.addHook("destroy", cb);
|
|
1091
|
-
}
|
|
1092
|
-
function throwIfOutsideComponent(hook) {
|
|
1093
|
-
if (!ComponentNode.ref) {
|
|
1094
|
-
console.error(
|
|
1095
|
-
`"${hook}" can only be called within the component function body
|
|
1096
|
-
and cannot be used in asynchronous or deferred calls.`
|
|
1097
|
-
);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
function useProvide(key, value) {
|
|
1101
|
-
var _a;
|
|
1102
|
-
throwIfOutsideComponent("useProvide");
|
|
1103
|
-
(_a = ComponentNode.ref) == null ? void 0 : _a.setContext(key, value);
|
|
1104
|
-
}
|
|
1105
|
-
function useInject(key, defaultValue) {
|
|
1106
|
-
var _a;
|
|
1107
|
-
throwIfOutsideComponent("useInject");
|
|
1108
|
-
return ((_a = ComponentNode.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
|
|
1109
|
-
}
|
|
1110
|
-
function convertJsonToAttributes(json) {
|
|
1111
|
-
return Object.entries(json).map(([key, value]) => `${key}=${JSON.stringify(escape(String(value)))}`).join(" ");
|
|
1112
|
-
}
|
|
1113
|
-
function renderTemplate(template2, props) {
|
|
1114
|
-
if (isFunction(template2)) {
|
|
1115
|
-
return template2(props);
|
|
1116
|
-
}
|
|
1117
|
-
const templateCollection = Array.isArray(template2) ? template2.reduce((acc, tmpl, index) => {
|
|
1118
|
-
acc[index + 1] = { template: tmpl };
|
|
1119
|
-
return acc;
|
|
1120
|
-
}, {}) : template2;
|
|
1121
|
-
const childNodesMap = {};
|
|
1122
|
-
const processedTemplates = {};
|
|
1123
|
-
if (isObject(templateCollection)) {
|
|
1124
|
-
for (const [key, tmpl] of Object.entries(templateCollection)) {
|
|
1125
|
-
const prop = props[key];
|
|
1126
|
-
if (prop) {
|
|
1127
|
-
for (const propKey in prop) {
|
|
1128
|
-
if (startsWith(propKey, "on") && isFunction(prop[propKey])) {
|
|
1129
|
-
delete prop[propKey];
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
if (prop.children) {
|
|
1133
|
-
for (const [child, idx] of prop.children) {
|
|
1134
|
-
if (!childNodesMap[idx]) childNodesMap[idx] = [];
|
|
1135
|
-
childNodesMap[idx].push(child);
|
|
1136
|
-
}
|
|
1137
|
-
delete prop.children;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
processedTemplates[key] = { template: tmpl.template, props: prop };
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
return Object.entries(processedTemplates).map(([key, { template: tmpl, props: prop }]) => {
|
|
1144
|
-
let renderedString = tmpl;
|
|
1145
|
-
if (prop) {
|
|
1146
|
-
renderedString += ` ${convertJsonToAttributes(prop)}`;
|
|
1147
|
-
}
|
|
1148
|
-
if (childNodesMap[key]) {
|
|
1149
|
-
renderedString += childNodesMap[key].map((child) => renderTemplate(child, prop)).join("");
|
|
1150
|
-
}
|
|
1151
|
-
return renderedString;
|
|
1152
|
-
}).join("");
|
|
1153
|
-
}
|
|
1154
|
-
function renderToString(component, props) {
|
|
1155
|
-
return renderTemplate(component, props);
|
|
1156
|
-
}
|
|
1157
|
-
function renderSSG(component, root, props = {}) {
|
|
1158
|
-
root.innerHTML = renderTemplate(component, props);
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
// src/index.ts
|
|
1162
|
-
if (globalThis) {
|
|
1163
|
-
globalThis.__essor_version__ = essor_version;
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* @estjs/shared v0.0.10-beta.20
|
|
1167
|
-
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1168
|
-
* @license MIT
|
|
1169
|
-
**/
|
|
1170
|
-
/**
|
|
1171
|
-
* @estjs/signal v0.0.10-beta.20
|
|
1172
|
-
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1173
|
-
* @license MIT
|
|
1174
|
-
**/
|
|
1175
|
-
/**
|
|
1176
|
-
* @estjs/template v0.0.10-beta.20
|
|
1177
|
-
* (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
|
|
1178
|
-
* @license MIT
|
|
1179
|
-
**/
|
|
1180
|
-
|
|
1181
|
-
export { ComponentNode, Fragment, TemplateNode, createStore, essor_version, h, isComputed, isJsxElement, isReactive, isSignal, nextTick, onDestroy, onMount, renderSSG, renderTemplate, renderToString, shallowReactive, shallowSignal, signalObject, template, unReactive, unSignal, useComputed, useEffect, useInject, useProvide, useReactive, useSignal, useWatch };
|