@aevantec/litevue 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/dist/litevue-devtools.iife.js +1 -1
- package/dist/litevue-devtools.mjs +1 -1
- package/dist/litevue-devtools.umd.js +1 -1
- package/dist/litevue-plugins.dev.iife.js +898 -0
- package/dist/litevue-plugins.dev.mjs +880 -0
- package/dist/litevue-plugins.iife.js +1 -1
- package/dist/litevue-plugins.mjs +1 -1
- package/dist/litevue-plugins.umd.js +1 -1
- package/dist/litevue.dev.iife.js +2193 -0
- package/dist/litevue.dev.mjs +2182 -0
- package/dist/litevue.iife.js +1 -1
- package/dist/litevue.mjs +1 -1
- package/dist/litevue.umd.js +1 -1
- package/dist/plugins/collapse.iife.js +1 -1
- package/dist/plugins/collapse.mjs +1 -1
- package/dist/plugins/collapse.umd.js +1 -1
- package/dist/plugins/media.dev.iife.js +249 -0
- package/dist/plugins/media.dev.mjs +243 -0
- package/dist/plugins/morph.dev.iife.js +217 -0
- package/dist/plugins/morph.dev.mjs +212 -0
- package/dist/plugins/persist.dev.iife.js +126 -0
- package/dist/plugins/persist.dev.mjs +120 -0
- package/dist/types/app.d.mts +7 -0
- package/dist/types/app.d.ts +7 -0
- package/dist/types/directives/bind.d.mts +1 -1
- package/dist/types/directives/bind.d.ts +1 -1
- package/dist/types/errors.d.mts +36 -0
- package/dist/types/errors.d.ts +36 -0
- package/dist/types/eval.d.mts +8 -2
- package/dist/types/eval.d.ts +8 -2
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lazy.d.mts +15 -0
- package/dist/types/lazy.d.ts +15 -0
- package/dist/types/plugins/morph/index.d.mts +2 -1
- package/dist/types/plugins/morph/index.d.ts +2 -1
- package/package.json +10 -2
|
@@ -0,0 +1,2182 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/@vue+shared@3.4.38/node_modules/@vue/shared/dist/shared.esm-bundler.js
|
|
2
|
+
/**
|
|
3
|
+
* @vue/shared v3.4.38
|
|
4
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
5
|
+
* @license MIT
|
|
6
|
+
**/
|
|
7
|
+
/*! #__NO_SIDE_EFFECTS__ */
|
|
8
|
+
// @__NO_SIDE_EFFECTS__
|
|
9
|
+
function makeMap(str, expectsLowerCase) {
|
|
10
|
+
const set = new Set(str.split(","));
|
|
11
|
+
return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
|
|
12
|
+
}
|
|
13
|
+
Object.freeze({});
|
|
14
|
+
Object.freeze([]);
|
|
15
|
+
var NOOP = () => {};
|
|
16
|
+
var extend = Object.assign;
|
|
17
|
+
var remove = (arr, el) => {
|
|
18
|
+
const i = arr.indexOf(el);
|
|
19
|
+
if (i > -1) arr.splice(i, 1);
|
|
20
|
+
};
|
|
21
|
+
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
22
|
+
var hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
23
|
+
var isArray = Array.isArray;
|
|
24
|
+
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
25
|
+
var isDate = (val) => toTypeString(val) === "[object Date]";
|
|
26
|
+
var isFunction = (val) => typeof val === "function";
|
|
27
|
+
var isString = (val) => typeof val === "string";
|
|
28
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
29
|
+
var isObject = (val) => val !== null && typeof val === "object";
|
|
30
|
+
var objectToString = Object.prototype.toString;
|
|
31
|
+
var toTypeString = (value) => objectToString.call(value);
|
|
32
|
+
var toRawType = (value) => {
|
|
33
|
+
return toTypeString(value).slice(8, -1);
|
|
34
|
+
};
|
|
35
|
+
var isPlainObject = (val) => toTypeString(val) === "[object Object]";
|
|
36
|
+
var isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
37
|
+
var cacheStringFunction = (fn) => {
|
|
38
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
39
|
+
return (str) => {
|
|
40
|
+
return cache[str] || (cache[str] = fn(str));
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var camelizeRE = /-(\w)/g;
|
|
44
|
+
var camelize = cacheStringFunction((str) => {
|
|
45
|
+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
46
|
+
});
|
|
47
|
+
var hyphenateRE = /\B([A-Z])/g;
|
|
48
|
+
var hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
49
|
+
var hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
50
|
+
var toNumber = (val) => {
|
|
51
|
+
const n = isString(val) ? Number(val) : NaN;
|
|
52
|
+
return isNaN(n) ? val : n;
|
|
53
|
+
};
|
|
54
|
+
function normalizeStyle(value) {
|
|
55
|
+
if (isArray(value)) {
|
|
56
|
+
const res = {};
|
|
57
|
+
for (let i = 0; i < value.length; i++) {
|
|
58
|
+
const item = value[i];
|
|
59
|
+
const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
|
|
60
|
+
if (normalized) for (const key in normalized) res[key] = normalized[key];
|
|
61
|
+
}
|
|
62
|
+
return res;
|
|
63
|
+
} else if (isString(value) || isObject(value)) return value;
|
|
64
|
+
}
|
|
65
|
+
var listDelimiterRE = /;(?![^(]*\))/g;
|
|
66
|
+
var propertyDelimiterRE = /:([^]+)/;
|
|
67
|
+
var styleCommentRE = /\/\*[^]*?\*\//g;
|
|
68
|
+
function parseStringStyle(cssText) {
|
|
69
|
+
const ret = {};
|
|
70
|
+
cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
|
71
|
+
if (item) {
|
|
72
|
+
const tmp = item.split(propertyDelimiterRE);
|
|
73
|
+
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return ret;
|
|
77
|
+
}
|
|
78
|
+
function normalizeClass(value) {
|
|
79
|
+
let res = "";
|
|
80
|
+
if (isString(value)) res = value;
|
|
81
|
+
else if (isArray(value)) for (let i = 0; i < value.length; i++) {
|
|
82
|
+
const normalized = normalizeClass(value[i]);
|
|
83
|
+
if (normalized) res += normalized + " ";
|
|
84
|
+
}
|
|
85
|
+
else if (isObject(value)) {
|
|
86
|
+
for (const name in value) if (value[name]) res += name + " ";
|
|
87
|
+
}
|
|
88
|
+
return res.trim();
|
|
89
|
+
}
|
|
90
|
+
function looseCompareArrays(a, b) {
|
|
91
|
+
if (a.length !== b.length) return false;
|
|
92
|
+
let equal = true;
|
|
93
|
+
for (let i = 0; equal && i < a.length; i++) equal = looseEqual(a[i], b[i]);
|
|
94
|
+
return equal;
|
|
95
|
+
}
|
|
96
|
+
function looseEqual(a, b) {
|
|
97
|
+
if (a === b) return true;
|
|
98
|
+
let aValidType = isDate(a);
|
|
99
|
+
let bValidType = isDate(b);
|
|
100
|
+
if (aValidType || bValidType) return aValidType && bValidType ? a.getTime() === b.getTime() : false;
|
|
101
|
+
aValidType = isSymbol(a);
|
|
102
|
+
bValidType = isSymbol(b);
|
|
103
|
+
if (aValidType || bValidType) return a === b;
|
|
104
|
+
aValidType = isArray(a);
|
|
105
|
+
bValidType = isArray(b);
|
|
106
|
+
if (aValidType || bValidType) return aValidType && bValidType ? looseCompareArrays(a, b) : false;
|
|
107
|
+
aValidType = isObject(a);
|
|
108
|
+
bValidType = isObject(b);
|
|
109
|
+
if (aValidType || bValidType) {
|
|
110
|
+
if (!aValidType || !bValidType) return false;
|
|
111
|
+
if (Object.keys(a).length !== Object.keys(b).length) return false;
|
|
112
|
+
for (const key in a) {
|
|
113
|
+
const aHasKey = a.hasOwnProperty(key);
|
|
114
|
+
const bHasKey = b.hasOwnProperty(key);
|
|
115
|
+
if (aHasKey && !bHasKey || !aHasKey && bHasKey || !looseEqual(a[key], b[key])) return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return String(a) === String(b);
|
|
119
|
+
}
|
|
120
|
+
function looseIndexOf(arr, val) {
|
|
121
|
+
return arr.findIndex((item) => looseEqual(item, val));
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region node_modules/.pnpm/@vue+reactivity@3.4.38/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
|
125
|
+
/**
|
|
126
|
+
* @vue/reactivity v3.4.38
|
|
127
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
128
|
+
* @license MIT
|
|
129
|
+
**/
|
|
130
|
+
function warn$1(msg, ...args) {
|
|
131
|
+
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
132
|
+
}
|
|
133
|
+
var activeEffectScope;
|
|
134
|
+
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
135
|
+
if (scope && scope.active) scope.effects.push(effect);
|
|
136
|
+
}
|
|
137
|
+
var activeEffect;
|
|
138
|
+
var ReactiveEffect = class {
|
|
139
|
+
constructor(fn, trigger, scheduler, scope) {
|
|
140
|
+
this.fn = fn;
|
|
141
|
+
this.trigger = trigger;
|
|
142
|
+
this.scheduler = scheduler;
|
|
143
|
+
this.active = true;
|
|
144
|
+
this.deps = [];
|
|
145
|
+
/**
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
this._dirtyLevel = 4;
|
|
149
|
+
/**
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
this._trackId = 0;
|
|
153
|
+
/**
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
this._runnings = 0;
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
this._shouldSchedule = false;
|
|
161
|
+
/**
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
this._depsLength = 0;
|
|
165
|
+
recordEffectScope(this, scope);
|
|
166
|
+
}
|
|
167
|
+
get dirty() {
|
|
168
|
+
if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
|
|
169
|
+
this._dirtyLevel = 1;
|
|
170
|
+
pauseTracking();
|
|
171
|
+
for (let i = 0; i < this._depsLength; i++) {
|
|
172
|
+
const dep = this.deps[i];
|
|
173
|
+
if (dep.computed) {
|
|
174
|
+
triggerComputed(dep.computed);
|
|
175
|
+
if (this._dirtyLevel >= 4) break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (this._dirtyLevel === 1) this._dirtyLevel = 0;
|
|
179
|
+
resetTracking();
|
|
180
|
+
}
|
|
181
|
+
return this._dirtyLevel >= 4;
|
|
182
|
+
}
|
|
183
|
+
set dirty(v) {
|
|
184
|
+
this._dirtyLevel = v ? 4 : 0;
|
|
185
|
+
}
|
|
186
|
+
run() {
|
|
187
|
+
this._dirtyLevel = 0;
|
|
188
|
+
if (!this.active) return this.fn();
|
|
189
|
+
let lastShouldTrack = shouldTrack;
|
|
190
|
+
let lastEffect = activeEffect;
|
|
191
|
+
try {
|
|
192
|
+
shouldTrack = true;
|
|
193
|
+
activeEffect = this;
|
|
194
|
+
this._runnings++;
|
|
195
|
+
preCleanupEffect(this);
|
|
196
|
+
return this.fn();
|
|
197
|
+
} finally {
|
|
198
|
+
postCleanupEffect(this);
|
|
199
|
+
this._runnings--;
|
|
200
|
+
activeEffect = lastEffect;
|
|
201
|
+
shouldTrack = lastShouldTrack;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
stop() {
|
|
205
|
+
if (this.active) {
|
|
206
|
+
preCleanupEffect(this);
|
|
207
|
+
postCleanupEffect(this);
|
|
208
|
+
this.onStop && this.onStop();
|
|
209
|
+
this.active = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
function triggerComputed(computed) {
|
|
214
|
+
return computed.value;
|
|
215
|
+
}
|
|
216
|
+
function preCleanupEffect(effect2) {
|
|
217
|
+
effect2._trackId++;
|
|
218
|
+
effect2._depsLength = 0;
|
|
219
|
+
}
|
|
220
|
+
function postCleanupEffect(effect2) {
|
|
221
|
+
if (effect2.deps.length > effect2._depsLength) {
|
|
222
|
+
for (let i = effect2._depsLength; i < effect2.deps.length; i++) cleanupDepEffect(effect2.deps[i], effect2);
|
|
223
|
+
effect2.deps.length = effect2._depsLength;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function cleanupDepEffect(dep, effect2) {
|
|
227
|
+
const trackId = dep.get(effect2);
|
|
228
|
+
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
|
229
|
+
dep.delete(effect2);
|
|
230
|
+
if (dep.size === 0) dep.cleanup();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function effect$1(fn, options) {
|
|
234
|
+
if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
|
|
235
|
+
const _effect = new ReactiveEffect(fn, NOOP, () => {
|
|
236
|
+
if (_effect.dirty) _effect.run();
|
|
237
|
+
});
|
|
238
|
+
if (options) {
|
|
239
|
+
extend(_effect, options);
|
|
240
|
+
if (options.scope) recordEffectScope(_effect, options.scope);
|
|
241
|
+
}
|
|
242
|
+
if (!options || !options.lazy) _effect.run();
|
|
243
|
+
const runner = _effect.run.bind(_effect);
|
|
244
|
+
runner.effect = _effect;
|
|
245
|
+
return runner;
|
|
246
|
+
}
|
|
247
|
+
function stop(runner) {
|
|
248
|
+
runner.effect.stop();
|
|
249
|
+
}
|
|
250
|
+
var shouldTrack = true;
|
|
251
|
+
var pauseScheduleStack = 0;
|
|
252
|
+
var trackStack = [];
|
|
253
|
+
function pauseTracking() {
|
|
254
|
+
trackStack.push(shouldTrack);
|
|
255
|
+
shouldTrack = false;
|
|
256
|
+
}
|
|
257
|
+
function resetTracking() {
|
|
258
|
+
const last = trackStack.pop();
|
|
259
|
+
shouldTrack = last === void 0 ? true : last;
|
|
260
|
+
}
|
|
261
|
+
function pauseScheduling() {
|
|
262
|
+
pauseScheduleStack++;
|
|
263
|
+
}
|
|
264
|
+
function resetScheduling() {
|
|
265
|
+
pauseScheduleStack--;
|
|
266
|
+
while (!pauseScheduleStack && queueEffectSchedulers.length) queueEffectSchedulers.shift()();
|
|
267
|
+
}
|
|
268
|
+
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
|
269
|
+
var _a;
|
|
270
|
+
if (dep.get(effect2) !== effect2._trackId) {
|
|
271
|
+
dep.set(effect2, effect2._trackId);
|
|
272
|
+
const oldDep = effect2.deps[effect2._depsLength];
|
|
273
|
+
if (oldDep !== dep) {
|
|
274
|
+
if (oldDep) cleanupDepEffect(oldDep, effect2);
|
|
275
|
+
effect2.deps[effect2._depsLength++] = dep;
|
|
276
|
+
} else effect2._depsLength++;
|
|
277
|
+
(_a = effect2.onTrack) == null || _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
var queueEffectSchedulers = [];
|
|
281
|
+
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
|
282
|
+
var _a;
|
|
283
|
+
pauseScheduling();
|
|
284
|
+
for (const effect2 of dep.keys()) {
|
|
285
|
+
let tracking;
|
|
286
|
+
if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
|
287
|
+
effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
|
|
288
|
+
effect2._dirtyLevel = dirtyLevel;
|
|
289
|
+
}
|
|
290
|
+
if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
|
291
|
+
(_a = effect2.onTrigger) == null || _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
|
|
292
|
+
effect2.trigger();
|
|
293
|
+
if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
|
|
294
|
+
effect2._shouldSchedule = false;
|
|
295
|
+
if (effect2.scheduler) queueEffectSchedulers.push(effect2.scheduler);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
resetScheduling();
|
|
300
|
+
}
|
|
301
|
+
var createDep = (cleanup, computed) => {
|
|
302
|
+
const dep = /* @__PURE__ */ new Map();
|
|
303
|
+
dep.cleanup = cleanup;
|
|
304
|
+
dep.computed = computed;
|
|
305
|
+
return dep;
|
|
306
|
+
};
|
|
307
|
+
var targetMap = /* @__PURE__ */ new WeakMap();
|
|
308
|
+
var ITERATE_KEY = Symbol("iterate");
|
|
309
|
+
var MAP_KEY_ITERATE_KEY = Symbol("Map key iterate");
|
|
310
|
+
function track(target, type, key) {
|
|
311
|
+
if (shouldTrack && activeEffect) {
|
|
312
|
+
let depsMap = targetMap.get(target);
|
|
313
|
+
if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
314
|
+
let dep = depsMap.get(key);
|
|
315
|
+
if (!dep) depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
|
316
|
+
trackEffect(activeEffect, dep, {
|
|
317
|
+
target,
|
|
318
|
+
type,
|
|
319
|
+
key
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function trigger$1(target, type, key, newValue, oldValue, oldTarget) {
|
|
324
|
+
const depsMap = targetMap.get(target);
|
|
325
|
+
if (!depsMap) return;
|
|
326
|
+
let deps = [];
|
|
327
|
+
if (type === "clear") deps = [...depsMap.values()];
|
|
328
|
+
else if (key === "length" && isArray(target)) {
|
|
329
|
+
const newLength = Number(newValue);
|
|
330
|
+
depsMap.forEach((dep, key2) => {
|
|
331
|
+
if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) deps.push(dep);
|
|
332
|
+
});
|
|
333
|
+
} else {
|
|
334
|
+
if (key !== void 0) deps.push(depsMap.get(key));
|
|
335
|
+
switch (type) {
|
|
336
|
+
case "add":
|
|
337
|
+
if (!isArray(target)) {
|
|
338
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
339
|
+
if (isMap(target)) deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
340
|
+
} else if (isIntegerKey(key)) deps.push(depsMap.get("length"));
|
|
341
|
+
break;
|
|
342
|
+
case "delete":
|
|
343
|
+
if (!isArray(target)) {
|
|
344
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
345
|
+
if (isMap(target)) deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
case "set": if (isMap(target)) deps.push(depsMap.get(ITERATE_KEY));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
pauseScheduling();
|
|
352
|
+
for (const dep of deps) if (dep) triggerEffects(dep, 4, {
|
|
353
|
+
target,
|
|
354
|
+
type,
|
|
355
|
+
key,
|
|
356
|
+
newValue,
|
|
357
|
+
oldValue,
|
|
358
|
+
oldTarget
|
|
359
|
+
});
|
|
360
|
+
resetScheduling();
|
|
361
|
+
}
|
|
362
|
+
var isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
363
|
+
var builtInSymbols = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
|
|
364
|
+
var arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
365
|
+
function createArrayInstrumentations() {
|
|
366
|
+
const instrumentations = {};
|
|
367
|
+
[
|
|
368
|
+
"includes",
|
|
369
|
+
"indexOf",
|
|
370
|
+
"lastIndexOf"
|
|
371
|
+
].forEach((key) => {
|
|
372
|
+
instrumentations[key] = function(...args) {
|
|
373
|
+
const arr = toRaw(this);
|
|
374
|
+
for (let i = 0, l = this.length; i < l; i++) track(arr, "get", i + "");
|
|
375
|
+
const res = arr[key](...args);
|
|
376
|
+
if (res === -1 || res === false) return arr[key](...args.map(toRaw));
|
|
377
|
+
else return res;
|
|
378
|
+
};
|
|
379
|
+
});
|
|
380
|
+
[
|
|
381
|
+
"push",
|
|
382
|
+
"pop",
|
|
383
|
+
"shift",
|
|
384
|
+
"unshift",
|
|
385
|
+
"splice"
|
|
386
|
+
].forEach((key) => {
|
|
387
|
+
instrumentations[key] = function(...args) {
|
|
388
|
+
pauseTracking();
|
|
389
|
+
pauseScheduling();
|
|
390
|
+
const res = toRaw(this)[key].apply(this, args);
|
|
391
|
+
resetScheduling();
|
|
392
|
+
resetTracking();
|
|
393
|
+
return res;
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
return instrumentations;
|
|
397
|
+
}
|
|
398
|
+
function hasOwnProperty(key) {
|
|
399
|
+
if (!isSymbol(key)) key = String(key);
|
|
400
|
+
const obj = toRaw(this);
|
|
401
|
+
track(obj, "has", key);
|
|
402
|
+
return obj.hasOwnProperty(key);
|
|
403
|
+
}
|
|
404
|
+
var BaseReactiveHandler = class {
|
|
405
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
406
|
+
this._isReadonly = _isReadonly;
|
|
407
|
+
this._isShallow = _isShallow;
|
|
408
|
+
}
|
|
409
|
+
get(target, key, receiver) {
|
|
410
|
+
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
|
411
|
+
if (key === "__v_isReactive") return !isReadonly2;
|
|
412
|
+
else if (key === "__v_isReadonly") return isReadonly2;
|
|
413
|
+
else if (key === "__v_isShallow") return isShallow2;
|
|
414
|
+
else if (key === "__v_raw") {
|
|
415
|
+
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const targetIsArray = isArray(target);
|
|
419
|
+
if (!isReadonly2) {
|
|
420
|
+
if (targetIsArray && hasOwn(arrayInstrumentations, key)) return Reflect.get(arrayInstrumentations, key, receiver);
|
|
421
|
+
if (key === "hasOwnProperty") return hasOwnProperty;
|
|
422
|
+
}
|
|
423
|
+
const res = Reflect.get(target, key, receiver);
|
|
424
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
|
|
425
|
+
if (!isReadonly2) track(target, "get", key);
|
|
426
|
+
if (isShallow2) return res;
|
|
427
|
+
if (isRef(res)) return targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
428
|
+
if (isObject(res)) return isReadonly2 ? readonly(res) : reactive(res);
|
|
429
|
+
return res;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var MutableReactiveHandler = class extends BaseReactiveHandler {
|
|
433
|
+
constructor(isShallow2 = false) {
|
|
434
|
+
super(false, isShallow2);
|
|
435
|
+
}
|
|
436
|
+
set(target, key, value, receiver) {
|
|
437
|
+
let oldValue = target[key];
|
|
438
|
+
if (!this._isShallow) {
|
|
439
|
+
const isOldValueReadonly = isReadonly(oldValue);
|
|
440
|
+
if (!isShallow(value) && !isReadonly(value)) {
|
|
441
|
+
oldValue = toRaw(oldValue);
|
|
442
|
+
value = toRaw(value);
|
|
443
|
+
}
|
|
444
|
+
if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
|
|
445
|
+
if (isOldValueReadonly) return false;
|
|
446
|
+
else {
|
|
447
|
+
oldValue.value = value;
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
|
|
453
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
454
|
+
if (target === toRaw(receiver)) {
|
|
455
|
+
if (!hadKey) trigger$1(target, "add", key, value);
|
|
456
|
+
else if (hasChanged(value, oldValue)) trigger$1(target, "set", key, value, oldValue);
|
|
457
|
+
}
|
|
458
|
+
return result;
|
|
459
|
+
}
|
|
460
|
+
deleteProperty(target, key) {
|
|
461
|
+
const hadKey = hasOwn(target, key);
|
|
462
|
+
const oldValue = target[key];
|
|
463
|
+
const result = Reflect.deleteProperty(target, key);
|
|
464
|
+
if (result && hadKey) trigger$1(target, "delete", key, void 0, oldValue);
|
|
465
|
+
return result;
|
|
466
|
+
}
|
|
467
|
+
has(target, key) {
|
|
468
|
+
const result = Reflect.has(target, key);
|
|
469
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) track(target, "has", key);
|
|
470
|
+
return result;
|
|
471
|
+
}
|
|
472
|
+
ownKeys(target) {
|
|
473
|
+
track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
|
|
474
|
+
return Reflect.ownKeys(target);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
|
|
478
|
+
constructor(isShallow2 = false) {
|
|
479
|
+
super(true, isShallow2);
|
|
480
|
+
}
|
|
481
|
+
set(target, key) {
|
|
482
|
+
warn$1(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
deleteProperty(target, key) {
|
|
486
|
+
warn$1(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
var mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
491
|
+
var readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
492
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
493
|
+
var shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
494
|
+
var readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
495
|
+
var shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
496
|
+
function targetTypeMap(rawType) {
|
|
497
|
+
switch (rawType) {
|
|
498
|
+
case "Object":
|
|
499
|
+
case "Array": return 1;
|
|
500
|
+
default: return 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function getTargetType(value) {
|
|
504
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
|
505
|
+
}
|
|
506
|
+
function reactive(target) {
|
|
507
|
+
if (isReadonly(target)) return target;
|
|
508
|
+
return createReactiveObject(target, false, mutableHandlers, null, reactiveMap);
|
|
509
|
+
}
|
|
510
|
+
function readonly(target) {
|
|
511
|
+
return createReactiveObject(target, true, readonlyHandlers, null, readonlyMap);
|
|
512
|
+
}
|
|
513
|
+
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
|
514
|
+
if (!isObject(target)) {
|
|
515
|
+
warn$1(`value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(target)}`);
|
|
516
|
+
return target;
|
|
517
|
+
}
|
|
518
|
+
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) return target;
|
|
519
|
+
const existingProxy = proxyMap.get(target);
|
|
520
|
+
if (existingProxy) return existingProxy;
|
|
521
|
+
const targetType = getTargetType(target);
|
|
522
|
+
if (targetType === 0) return target;
|
|
523
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
524
|
+
proxyMap.set(target, proxy);
|
|
525
|
+
return proxy;
|
|
526
|
+
}
|
|
527
|
+
function isReadonly(value) {
|
|
528
|
+
return !!(value && value["__v_isReadonly"]);
|
|
529
|
+
}
|
|
530
|
+
function isShallow(value) {
|
|
531
|
+
return !!(value && value["__v_isShallow"]);
|
|
532
|
+
}
|
|
533
|
+
function toRaw(observed) {
|
|
534
|
+
const raw = observed && observed["__v_raw"];
|
|
535
|
+
return raw ? toRaw(raw) : observed;
|
|
536
|
+
}
|
|
537
|
+
var COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
|
|
538
|
+
var ComputedRefImpl = class {
|
|
539
|
+
constructor(getter, _setter, isReadonly, isSSR) {
|
|
540
|
+
this.getter = getter;
|
|
541
|
+
this._setter = _setter;
|
|
542
|
+
this.dep = void 0;
|
|
543
|
+
this.__v_isRef = true;
|
|
544
|
+
this["__v_isReadonly"] = false;
|
|
545
|
+
this.effect = new ReactiveEffect(() => getter(this._value), () => triggerRefValue(this, this.effect._dirtyLevel === 2 ? 2 : 3));
|
|
546
|
+
this.effect.computed = this;
|
|
547
|
+
this.effect.active = this._cacheable = !isSSR;
|
|
548
|
+
this["__v_isReadonly"] = isReadonly;
|
|
549
|
+
}
|
|
550
|
+
get value() {
|
|
551
|
+
const self = toRaw(this);
|
|
552
|
+
if ((!self._cacheable || self.effect.dirty) && hasChanged(self._value, self._value = self.effect.run())) triggerRefValue(self, 4);
|
|
553
|
+
trackRefValue(self);
|
|
554
|
+
if (self.effect._dirtyLevel >= 2) {
|
|
555
|
+
if (this._warnRecursive) warn$1(COMPUTED_SIDE_EFFECT_WARN, `
|
|
556
|
+
|
|
557
|
+
getter: `, this.getter);
|
|
558
|
+
triggerRefValue(self, 2);
|
|
559
|
+
}
|
|
560
|
+
return self._value;
|
|
561
|
+
}
|
|
562
|
+
set value(newValue) {
|
|
563
|
+
this._setter(newValue);
|
|
564
|
+
}
|
|
565
|
+
get _dirty() {
|
|
566
|
+
return this.effect.dirty;
|
|
567
|
+
}
|
|
568
|
+
set _dirty(v) {
|
|
569
|
+
this.effect.dirty = v;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
573
|
+
let getter;
|
|
574
|
+
let setter;
|
|
575
|
+
const onlyGetter = isFunction(getterOrOptions);
|
|
576
|
+
if (onlyGetter) {
|
|
577
|
+
getter = getterOrOptions;
|
|
578
|
+
setter = () => {
|
|
579
|
+
warn$1("Write operation failed: computed value is readonly");
|
|
580
|
+
};
|
|
581
|
+
} else {
|
|
582
|
+
getter = getterOrOptions.get;
|
|
583
|
+
setter = getterOrOptions.set;
|
|
584
|
+
}
|
|
585
|
+
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
586
|
+
if (debugOptions && !isSSR) {
|
|
587
|
+
cRef.effect.onTrack = debugOptions.onTrack;
|
|
588
|
+
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
589
|
+
}
|
|
590
|
+
return cRef;
|
|
591
|
+
}
|
|
592
|
+
function trackRefValue(ref2) {
|
|
593
|
+
var _a;
|
|
594
|
+
if (shouldTrack && activeEffect) {
|
|
595
|
+
ref2 = toRaw(ref2);
|
|
596
|
+
trackEffect(activeEffect, (_a = ref2.dep) != null ? _a : ref2.dep = createDep(() => ref2.dep = void 0, ref2 instanceof ComputedRefImpl ? ref2 : void 0), {
|
|
597
|
+
target: ref2,
|
|
598
|
+
type: "get",
|
|
599
|
+
key: "value"
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function triggerRefValue(ref2, dirtyLevel = 4, newVal, oldVal) {
|
|
604
|
+
ref2 = toRaw(ref2);
|
|
605
|
+
const dep = ref2.dep;
|
|
606
|
+
if (dep) triggerEffects(dep, dirtyLevel, {
|
|
607
|
+
target: ref2,
|
|
608
|
+
type: "set",
|
|
609
|
+
key: "value",
|
|
610
|
+
newValue: newVal,
|
|
611
|
+
oldValue: oldVal
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
function isRef(r) {
|
|
615
|
+
return !!(r && r.__v_isRef === true);
|
|
616
|
+
}
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/magics.ts
|
|
619
|
+
var uid = 0;
|
|
620
|
+
/**
|
|
621
|
+
* $id('name') — unique ids for accessibility attributes. Stable within a scope
|
|
622
|
+
* so label/input pairs match, unique across scopes.
|
|
623
|
+
*/
|
|
624
|
+
var createId = () => {
|
|
625
|
+
const memo = Object.create(null);
|
|
626
|
+
return (name = "id") => memo[name] || (memo[name] = `${name}-${++uid}`);
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* $watch(source, callback) — watches a dot-path string or getter and calls
|
|
630
|
+
* back with (value, oldValue). Tied to the owning scope's effects, so it stops
|
|
631
|
+
* when the scope unmounts.
|
|
632
|
+
*/
|
|
633
|
+
var createWatch = (ctx) => (source, cb) => {
|
|
634
|
+
const getter = typeof source === "function" ? source : () => source.split(".").reduce((o, k) => o == null ? o : o[k], ctx.scope);
|
|
635
|
+
let oldValue;
|
|
636
|
+
let init = false;
|
|
637
|
+
ctx.effect(() => {
|
|
638
|
+
const value = getter();
|
|
639
|
+
const previous = oldValue;
|
|
640
|
+
oldValue = value;
|
|
641
|
+
if (init && value !== previous) {
|
|
642
|
+
pauseTracking();
|
|
643
|
+
try {
|
|
644
|
+
cb(value, previous);
|
|
645
|
+
} finally {
|
|
646
|
+
resetTracking();
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
init = true;
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/devtools.ts
|
|
654
|
+
var scopes = /* @__PURE__ */ new Map();
|
|
655
|
+
var exps = /* @__PURE__ */ new Map();
|
|
656
|
+
var names = /* @__PURE__ */ new Map();
|
|
657
|
+
var storeMap = /* @__PURE__ */ new Map();
|
|
658
|
+
var componentNames = /* @__PURE__ */ new Set();
|
|
659
|
+
var disabled = false;
|
|
660
|
+
var isDisabled = () => disabled || typeof window !== "undefined" && window.__LITE_VUE_DEVTOOLS__ === false;
|
|
661
|
+
var listeners = {
|
|
662
|
+
"scope:mount": /* @__PURE__ */ new Set(),
|
|
663
|
+
"scope:unmount": /* @__PURE__ */ new Set(),
|
|
664
|
+
"store:register": /* @__PURE__ */ new Set(),
|
|
665
|
+
flush: /* @__PURE__ */ new Set()
|
|
666
|
+
};
|
|
667
|
+
var emit = (event, ...args) => {
|
|
668
|
+
listeners[event].forEach((fn) => fn(...args));
|
|
669
|
+
};
|
|
670
|
+
var noop = () => {};
|
|
671
|
+
var registerScope = (el, scope, exp, name) => {
|
|
672
|
+
if (isDisabled()) return noop;
|
|
673
|
+
scopes.set(el, scope);
|
|
674
|
+
if (exp) exps.set(el, exp);
|
|
675
|
+
if (name) names.set(el, name);
|
|
676
|
+
emit("scope:mount", el, scope);
|
|
677
|
+
return () => {
|
|
678
|
+
if (scopes.delete(el)) {
|
|
679
|
+
exps.delete(el);
|
|
680
|
+
names.delete(el);
|
|
681
|
+
emit("scope:unmount", el);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
var registerStore = (name, store) => {
|
|
686
|
+
if (isDisabled()) return;
|
|
687
|
+
storeMap.set(name, store);
|
|
688
|
+
emit("store:register", name, store);
|
|
689
|
+
};
|
|
690
|
+
var registerComponent = (name) => {
|
|
691
|
+
if (!isDisabled()) componentNames.add(name);
|
|
692
|
+
};
|
|
693
|
+
var emitFlush = () => {
|
|
694
|
+
if (listeners.flush.size && !isDisabled()) emit("flush");
|
|
695
|
+
};
|
|
696
|
+
var devtools = {
|
|
697
|
+
scopes,
|
|
698
|
+
exps,
|
|
699
|
+
names,
|
|
700
|
+
stores: storeMap,
|
|
701
|
+
components: componentNames,
|
|
702
|
+
getScopeByName(name) {
|
|
703
|
+
for (const [el, n] of names) if (n === name) return scopes.get(el);
|
|
704
|
+
},
|
|
705
|
+
getScope(node) {
|
|
706
|
+
let el = node.nodeType === 1 ? node : node.parentElement;
|
|
707
|
+
while (el) {
|
|
708
|
+
const scope = scopes.get(el);
|
|
709
|
+
if (scope) return scope;
|
|
710
|
+
el = el.parentElement;
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
on(event, fn) {
|
|
714
|
+
listeners[event].add(fn);
|
|
715
|
+
return () => listeners[event].delete(fn);
|
|
716
|
+
},
|
|
717
|
+
off(event, fn) {
|
|
718
|
+
listeners[event].delete(fn);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* Turn devtools off for production: stops scope registration, clears
|
|
723
|
+
* everything already registered, and removes window.__LITE_VUE__. For
|
|
724
|
+
* script-tag users, setting window.__LITE_VUE_DEVTOOLS__ = false before the
|
|
725
|
+
* library loads has the same effect.
|
|
726
|
+
*/
|
|
727
|
+
var disableDevtools = () => {
|
|
728
|
+
disabled = true;
|
|
729
|
+
scopes.clear();
|
|
730
|
+
exps.clear();
|
|
731
|
+
names.clear();
|
|
732
|
+
storeMap.clear();
|
|
733
|
+
componentNames.clear();
|
|
734
|
+
for (const event in listeners) listeners[event].clear();
|
|
735
|
+
if (typeof window !== "undefined" && window.__LITE_VUE__ === devtools) delete window.__LITE_VUE__;
|
|
736
|
+
};
|
|
737
|
+
if (typeof window !== "undefined" && !isDisabled()) window.__LITE_VUE__ = devtools;
|
|
738
|
+
//#endregion
|
|
739
|
+
//#region src/errors.ts
|
|
740
|
+
/** Levenshtein, bounded — only used to rank candidate names in DEV. */
|
|
741
|
+
var distance = (a, b) => {
|
|
742
|
+
const m = a.length;
|
|
743
|
+
const n = b.length;
|
|
744
|
+
if (!m || !n) return m || n;
|
|
745
|
+
let prev = Array.from({ length: n + 1 }, (_, i) => i);
|
|
746
|
+
const curr = [];
|
|
747
|
+
for (let i = 1; i <= m; i++) {
|
|
748
|
+
curr[0] = i;
|
|
749
|
+
for (let j = 1; j <= n; j++) curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
750
|
+
prev = curr.slice();
|
|
751
|
+
}
|
|
752
|
+
return prev[n];
|
|
753
|
+
};
|
|
754
|
+
/** Every name in scope, up the prototype chain that nested `v-scope`s inherit. */
|
|
755
|
+
var scopeNames = (scope) => {
|
|
756
|
+
const names = /* @__PURE__ */ new Set();
|
|
757
|
+
let cur = scope;
|
|
758
|
+
while (cur && cur !== Object.prototype) {
|
|
759
|
+
for (const key of Object.getOwnPropertyNames(cur)) if (key !== "__v_skip" && !key.startsWith("__v_")) names.add(key);
|
|
760
|
+
cur = Object.getPrototypeOf(cur);
|
|
761
|
+
}
|
|
762
|
+
return [...names];
|
|
763
|
+
};
|
|
764
|
+
/** `count is not defined` → the closest name actually in scope. */
|
|
765
|
+
var suggestName = (err, scope) => {
|
|
766
|
+
if (!scope || !(err instanceof ReferenceError)) return;
|
|
767
|
+
const missing = /^(\w+) is not defined$/.exec(err.message)?.[1];
|
|
768
|
+
if (!missing) return;
|
|
769
|
+
const candidates = scopeNames(scope).filter((n) => !n.startsWith("$"));
|
|
770
|
+
let best;
|
|
771
|
+
let bestScore = Infinity;
|
|
772
|
+
for (const name of candidates) {
|
|
773
|
+
const d = distance(missing.toLowerCase(), name.toLowerCase());
|
|
774
|
+
if (d < bestScore) {
|
|
775
|
+
bestScore = d;
|
|
776
|
+
best = name;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const limit = Math.max(1, Math.floor(missing.length / 3));
|
|
780
|
+
return best && bestScore <= limit ? {
|
|
781
|
+
missing,
|
|
782
|
+
suggestion: best
|
|
783
|
+
} : { missing };
|
|
784
|
+
};
|
|
785
|
+
/** A short, recognisable rendering of the element — not its whole subtree. */
|
|
786
|
+
var describeEl = (el) => {
|
|
787
|
+
if (!el) return;
|
|
788
|
+
if (!(el instanceof Element)) return el.nodeType === 3 ? `text node "${el.nodeValue?.trim().slice(0, 40)}"` : void 0;
|
|
789
|
+
return `<${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""}${el.classList.length ? `.${[...el.classList].join(".")}` : ""}>`;
|
|
790
|
+
};
|
|
791
|
+
var handlers = [];
|
|
792
|
+
/** Registered by `app.onError()`. Shared across apps, like the store registry. */
|
|
793
|
+
var addErrorHandler = (fn) => {
|
|
794
|
+
handlers.push(fn);
|
|
795
|
+
return () => {
|
|
796
|
+
const i = handlers.indexOf(fn);
|
|
797
|
+
if (i > -1) handlers.splice(i, 1);
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
var PHASES = {
|
|
801
|
+
expression: "evaluating",
|
|
802
|
+
handler: "handling an event in",
|
|
803
|
+
directive: "setting up",
|
|
804
|
+
compile: "compiling",
|
|
805
|
+
effect: "re-running an effect",
|
|
806
|
+
teardown: "tearing down"
|
|
807
|
+
};
|
|
808
|
+
var handleError = (err, info) => {
|
|
809
|
+
for (const fn of handlers) try {
|
|
810
|
+
fn(err, info);
|
|
811
|
+
} catch (inner) {
|
|
812
|
+
console.error("[litevue] an onError handler itself threw:", inner);
|
|
813
|
+
}
|
|
814
|
+
const where = info.source ? ` ${info.source}` : "";
|
|
815
|
+
const parts = [`[litevue] error ${PHASES[info.phase]}${where}`];
|
|
816
|
+
if (info.expression) parts.push(`\n expression: ${info.expression.trim()}`);
|
|
817
|
+
const el = describeEl(info.el);
|
|
818
|
+
if (el) parts.push(`\n element: ${el}`);
|
|
819
|
+
const named = suggestName(err, info.scope);
|
|
820
|
+
if (named?.suggestion) parts.push(`\n "${named.missing}" is not in scope — did you mean "${named.suggestion}"?`);
|
|
821
|
+
else if (named) {
|
|
822
|
+
const names = scopeNames(info.scope).filter((n) => !n.startsWith("$"));
|
|
823
|
+
parts.push(`\n "${named.missing}" is not in scope.` + (names.length ? ` Available: ${names.slice(0, 12).join(", ")}${names.length > 12 ? ", …" : ""}` : " This scope declares nothing — is the v-scope on the right element?"));
|
|
824
|
+
}
|
|
825
|
+
console.error(parts.join(""), "\n ", err);
|
|
826
|
+
if (info.el) console.error(info.el);
|
|
827
|
+
};
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/scheduler.ts
|
|
830
|
+
/**
|
|
831
|
+
* Effects this library has stopped.
|
|
832
|
+
*
|
|
833
|
+
* The scheduler must know whether a queued runner is still live, and
|
|
834
|
+
* @vue/reactivity offers no supported way to ask: 3.4's `ReactiveEffect.active`
|
|
835
|
+
* became an undeclared `flags` bitfield in 3.5. Since every stop here goes
|
|
836
|
+
* through `stopEffect`, tracking them ourselves is version-proof. Weak, so a
|
|
837
|
+
* stopped effect stays collectable.
|
|
838
|
+
*/
|
|
839
|
+
var stopped = /* @__PURE__ */ new WeakSet();
|
|
840
|
+
/** Stops an effect and remembers that it is stopped. Use instead of `stop`. */
|
|
841
|
+
var stopEffect = (runner) => {
|
|
842
|
+
stopped.add(runner);
|
|
843
|
+
stop(runner);
|
|
844
|
+
};
|
|
845
|
+
var queued = false;
|
|
846
|
+
var queue = [];
|
|
847
|
+
var p = Promise.resolve();
|
|
848
|
+
var flushIndex = -1;
|
|
849
|
+
var MAX_RUNS = 100;
|
|
850
|
+
var nextTick = (fn) => p.then(fn);
|
|
851
|
+
var queueJob = (job) => {
|
|
852
|
+
if (!queue.includes(job, flushIndex + 1)) queue.push(job);
|
|
853
|
+
if (!queued) {
|
|
854
|
+
queued = true;
|
|
855
|
+
nextTick(flushJobs);
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
var flushJobs = () => {
|
|
859
|
+
const runs = /* @__PURE__ */ new Map();
|
|
860
|
+
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
|
861
|
+
const job = queue[flushIndex];
|
|
862
|
+
if (stopped.has(job)) continue;
|
|
863
|
+
const n = (runs.get(job) || 0) + 1;
|
|
864
|
+
runs.set(job, n);
|
|
865
|
+
if (n > MAX_RUNS) {
|
|
866
|
+
handleError(Error(`an effect re-ran ${MAX_RUNS} times in one update and was stopped. Two effects are probably each writing state the other reads; derive one from the other with a getter or computed() instead.`), { phase: "effect" });
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
try {
|
|
870
|
+
job();
|
|
871
|
+
} catch (e) {
|
|
872
|
+
handleError(e, { phase: "effect" });
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
queue.length = 0;
|
|
876
|
+
flushIndex = -1;
|
|
877
|
+
queued = false;
|
|
878
|
+
emitFlush();
|
|
879
|
+
};
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/directives/bind.ts
|
|
882
|
+
var forceAttrRE = /^(spellcheck|draggable|form|list|type)$/;
|
|
883
|
+
var bind = ({ el, get, effect, arg, modifiers }) => {
|
|
884
|
+
let prevValue;
|
|
885
|
+
if (arg === "class") el._class = el.getAttribute("class");
|
|
886
|
+
effect(() => {
|
|
887
|
+
let value = get();
|
|
888
|
+
if (arg) {
|
|
889
|
+
if (modifiers?.camel) arg = camelize(arg);
|
|
890
|
+
setProp(el, arg, value, prevValue);
|
|
891
|
+
} else {
|
|
892
|
+
for (const key in value) setProp(el, key, value[key], prevValue && prevValue[key]);
|
|
893
|
+
for (const key in prevValue) if (!value || !(key in value)) setProp(el, key, null);
|
|
894
|
+
}
|
|
895
|
+
prevValue = isPlainObject(value) ? { ...value } : value;
|
|
896
|
+
});
|
|
897
|
+
};
|
|
898
|
+
var setProp = (el, key, value, prevValue) => {
|
|
899
|
+
if (key === "class") el.setAttribute("class", normalizeClass(el._class ? [el._class, value] : value) || "");
|
|
900
|
+
else if (key === "style") {
|
|
901
|
+
value = normalizeStyle(value);
|
|
902
|
+
const { style } = el;
|
|
903
|
+
if (!value) el.removeAttribute("style");
|
|
904
|
+
else if (isString(value)) {
|
|
905
|
+
if (value !== prevValue) style.cssText = value;
|
|
906
|
+
} else {
|
|
907
|
+
for (const key in value) setStyle(style, key, value[key]);
|
|
908
|
+
if (prevValue && !isString(prevValue)) {
|
|
909
|
+
for (const key in prevValue) if (value[key] == null) setStyle(style, key, "");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
} else if (!(el instanceof SVGElement) && key in el && !forceAttrRE.test(key)) {
|
|
913
|
+
el[key] = value == null && typeof el[key] == "string" ? "" : value;
|
|
914
|
+
if (value == null) el.removeAttribute(key);
|
|
915
|
+
if (key === "value") el._value = value;
|
|
916
|
+
} else if (key === "true-value") el._trueValue = value;
|
|
917
|
+
else if (key === "false-value") el._falseValue = value;
|
|
918
|
+
else if (value != null) el.setAttribute(key, value);
|
|
919
|
+
else el.removeAttribute(key);
|
|
920
|
+
};
|
|
921
|
+
var importantRE = /\s*!important$/;
|
|
922
|
+
var setStyle = (style, name, val) => {
|
|
923
|
+
if (isArray(val)) val.forEach((v) => setStyle(style, name, v));
|
|
924
|
+
else if (name.startsWith("--")) style.setProperty(name, val);
|
|
925
|
+
else if (importantRE.test(val)) style.setProperty(hyphenate(name), val.replace(importantRE, ""), "important");
|
|
926
|
+
else style[name] = val;
|
|
927
|
+
};
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/warn.ts
|
|
930
|
+
/**
|
|
931
|
+
* Development warnings.
|
|
932
|
+
*
|
|
933
|
+
* Every call site is guarded by `import.meta.env.DEV`; the production build
|
|
934
|
+
* replaces that constant and terser drops the branch, so neither these
|
|
935
|
+
* functions nor their strings ship. Messages are therefore free to be wordy —
|
|
936
|
+
* say what to do instead.
|
|
937
|
+
*/
|
|
938
|
+
var seen = /* @__PURE__ */ new Set();
|
|
939
|
+
var warn = (msg) => {
|
|
940
|
+
console.warn(`[litevue] ${msg}`);
|
|
941
|
+
};
|
|
942
|
+
/**
|
|
943
|
+
* Warns once per `key`. Most callers are effects, which re-run on every
|
|
944
|
+
* relevant change — one mistake would otherwise print on every keystroke.
|
|
945
|
+
*/
|
|
946
|
+
var warnOnce = (key, msg) => {
|
|
947
|
+
if (seen.has(key)) return;
|
|
948
|
+
seen.add(key);
|
|
949
|
+
warn(msg);
|
|
950
|
+
};
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/directives/on.ts
|
|
953
|
+
/**
|
|
954
|
+
* Can `exp` stand as a single expression, or is it a statement list?
|
|
955
|
+
* Memoised: it compiles a throwaway function, which a `v-for` pays per row.
|
|
956
|
+
*/
|
|
957
|
+
var expressionCache = Object.create(null);
|
|
958
|
+
var isExpression = (exp) => {
|
|
959
|
+
const hit = expressionCache[exp];
|
|
960
|
+
if (hit !== void 0) return hit;
|
|
961
|
+
try {
|
|
962
|
+
new Function(`return (${exp})`);
|
|
963
|
+
return expressionCache[exp] = true;
|
|
964
|
+
} catch {
|
|
965
|
+
return expressionCache[exp] = false;
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;
|
|
969
|
+
var systemModifiers = [
|
|
970
|
+
"ctrl",
|
|
971
|
+
"shift",
|
|
972
|
+
"alt",
|
|
973
|
+
"meta"
|
|
974
|
+
];
|
|
975
|
+
var modifierGuards = {
|
|
976
|
+
stop: (e) => e.stopPropagation(),
|
|
977
|
+
prevent: (e) => e.preventDefault(),
|
|
978
|
+
self: (e) => e.target !== e.currentTarget,
|
|
979
|
+
ctrl: (e) => !e.ctrlKey,
|
|
980
|
+
shift: (e) => !e.shiftKey,
|
|
981
|
+
alt: (e) => !e.altKey,
|
|
982
|
+
meta: (e) => !e.metaKey,
|
|
983
|
+
left: (e) => "button" in e && e.button !== 0,
|
|
984
|
+
middle: (e) => "button" in e && e.button !== 1,
|
|
985
|
+
right: (e) => "button" in e && e.button !== 2,
|
|
986
|
+
exact: (e, modifiers) => systemModifiers.some((m) => e[`${m}Key`] && !modifiers[m])
|
|
987
|
+
};
|
|
988
|
+
var keyAliases = {
|
|
989
|
+
esc: "escape",
|
|
990
|
+
space: " ",
|
|
991
|
+
up: "arrow-up",
|
|
992
|
+
down: "arrow-down",
|
|
993
|
+
left: "arrow-left",
|
|
994
|
+
right: "arrow-right",
|
|
995
|
+
delete: "backspace"
|
|
996
|
+
};
|
|
997
|
+
var nonKeyModifierRE = /^(stop|prevent|self|ctrl|shift|alt|meta|left|middle|right|exact|once|capture|passive|window|document|outside|debounce(-\d+)?|throttle(-\d+)?|prop-.+|name-.+)$/;
|
|
998
|
+
var on = ({ el, get, ctx, exp, arg, modifiers }) => {
|
|
999
|
+
if (!arg) {
|
|
1000
|
+
console.error(`v-on="obj" syntax is not supported in LiteVue.`);
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const raw = simplePathRE.test(exp) ? get(`(e => ${exp}(e))`) : isExpression(exp) ? get(`($event => (${exp}))`) : get(`($event => { ${exp} })`);
|
|
1004
|
+
let handler = (...args) => {
|
|
1005
|
+
try {
|
|
1006
|
+
const result = raw(...args);
|
|
1007
|
+
if (result instanceof Promise) result.catch(fail);
|
|
1008
|
+
return result;
|
|
1009
|
+
} catch (e) {
|
|
1010
|
+
fail(e);
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
function fail(e) {
|
|
1014
|
+
handleError(e, {
|
|
1015
|
+
phase: "handler",
|
|
1016
|
+
source: `@${arg}`,
|
|
1017
|
+
expression: exp,
|
|
1018
|
+
el,
|
|
1019
|
+
scope: ctx.scope
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
if (arg === "vue:mounted" || arg === "vue:unmounted") console.warn(`@${arg} is deprecated in LiteVue - use @${arg.slice(4)} instead.`);
|
|
1023
|
+
if (arg === "mounted" || arg === "vue:mounted") {
|
|
1024
|
+
let live = true;
|
|
1025
|
+
nextTick(() => {
|
|
1026
|
+
if (live) handler();
|
|
1027
|
+
});
|
|
1028
|
+
return () => {
|
|
1029
|
+
live = false;
|
|
1030
|
+
};
|
|
1031
|
+
} else if (arg === "unmounted" || arg === "vue:unmounted") return () => handler();
|
|
1032
|
+
let debounceTimer;
|
|
1033
|
+
if (modifiers) {
|
|
1034
|
+
if (arg === "click") {
|
|
1035
|
+
if (modifiers.right) arg = "contextmenu";
|
|
1036
|
+
if (modifiers.middle) arg = "mouseup";
|
|
1037
|
+
}
|
|
1038
|
+
let invoke = handler;
|
|
1039
|
+
for (const key in modifiers) {
|
|
1040
|
+
let m = /^debounce(?:-(\d+))?$/.exec(key);
|
|
1041
|
+
if (m) {
|
|
1042
|
+
const fn = invoke;
|
|
1043
|
+
const ms = m[1] ? +m[1] : 250;
|
|
1044
|
+
invoke = (e) => {
|
|
1045
|
+
clearTimeout(debounceTimer);
|
|
1046
|
+
debounceTimer = setTimeout(fn, ms, e);
|
|
1047
|
+
};
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
m = /^throttle(?:-(\d+))?$/.exec(key);
|
|
1051
|
+
if (m) {
|
|
1052
|
+
const fn = invoke;
|
|
1053
|
+
const ms = m[1] ? +m[1] : 250;
|
|
1054
|
+
let last = 0;
|
|
1055
|
+
invoke = (e) => {
|
|
1056
|
+
const now = Date.now();
|
|
1057
|
+
if (now - last >= ms) {
|
|
1058
|
+
last = now;
|
|
1059
|
+
fn(e);
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
const keyFilter = Object.keys(modifiers).filter((k) => !nonKeyModifierRE.test(k) || k in keyAliases);
|
|
1065
|
+
if (!arg.startsWith("key")) for (const k of keyFilter) {
|
|
1066
|
+
if (k in keyAliases) continue;
|
|
1067
|
+
const ms = /^(\d+)ms$/.exec(k);
|
|
1068
|
+
warnOnce(`modifier:${arg}.${k}`, `@${arg}.${k}: .${k} is not a modifier LiteVue knows, so it is ignored.` + (ms ? ` Timings are written with a dash — .debounce-${ms[1]} or .throttle-${ms[1]}.` : ` Key names only filter keyboard events.`));
|
|
1069
|
+
}
|
|
1070
|
+
handler = (e) => {
|
|
1071
|
+
if (modifiers.outside && el.contains(e.target)) return;
|
|
1072
|
+
if ("key" in e && keyFilter.length) {
|
|
1073
|
+
const key = hyphenate(e.key);
|
|
1074
|
+
if (!keyFilter.some((k) => k === key || keyAliases[k] === key)) return;
|
|
1075
|
+
}
|
|
1076
|
+
for (const key in modifiers) {
|
|
1077
|
+
const guard = modifierGuards[key];
|
|
1078
|
+
if (guard && guard(e, modifiers)) return;
|
|
1079
|
+
if (key.startsWith("prop-") && "propertyName" in e && e.propertyName !== key.slice(5)) return;
|
|
1080
|
+
if (key.startsWith("name-") && "animationName" in e && e.animationName !== key.slice(5)) return;
|
|
1081
|
+
}
|
|
1082
|
+
return invoke(e);
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
const target = modifiers?.window ? window : modifiers?.document || modifiers?.outside ? document : el;
|
|
1086
|
+
const event = arg;
|
|
1087
|
+
target.addEventListener(event, handler, modifiers);
|
|
1088
|
+
return () => {
|
|
1089
|
+
clearTimeout(debounceTimer);
|
|
1090
|
+
target.removeEventListener(event, handler, modifiers);
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region src/directives/show.ts
|
|
1095
|
+
var show = ({ el, get, effect }) => {
|
|
1096
|
+
const initialDisplay = el.style.display;
|
|
1097
|
+
effect(() => {
|
|
1098
|
+
el.style.display = get() ? initialDisplay : "none";
|
|
1099
|
+
});
|
|
1100
|
+
};
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/directives/text.ts
|
|
1103
|
+
var text = ({ el, get, effect }) => {
|
|
1104
|
+
effect(() => {
|
|
1105
|
+
el.textContent = toDisplayString(get());
|
|
1106
|
+
});
|
|
1107
|
+
};
|
|
1108
|
+
var toDisplayString = (value) => value == null ? "" : isObject(value) ? JSON.stringify(value, null, 2) : String(value);
|
|
1109
|
+
//#endregion
|
|
1110
|
+
//#region src/directives/html.ts
|
|
1111
|
+
var html = ({ el, get, effect }) => {
|
|
1112
|
+
effect(() => {
|
|
1113
|
+
el.innerHTML = get() ?? "";
|
|
1114
|
+
});
|
|
1115
|
+
};
|
|
1116
|
+
//#endregion
|
|
1117
|
+
//#region src/utils.ts
|
|
1118
|
+
var checkAttr = (el, name) => {
|
|
1119
|
+
const val = el.getAttribute(name);
|
|
1120
|
+
if (val != null) el.removeAttribute(name);
|
|
1121
|
+
return val;
|
|
1122
|
+
};
|
|
1123
|
+
/**
|
|
1124
|
+
* Adds a listener and returns a remover. Callers are expected to use it:
|
|
1125
|
+
* `app.unmount(el)` leaves elements in the document, so a listener left behind
|
|
1126
|
+
* would keep driving markup meant to be inert.
|
|
1127
|
+
*/
|
|
1128
|
+
var listen = (el, event, handler, options) => {
|
|
1129
|
+
el.addEventListener(event, handler, options);
|
|
1130
|
+
return () => el.removeEventListener(event, handler, options);
|
|
1131
|
+
};
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/directives/model.ts
|
|
1134
|
+
var model = ({ el, exp, get, effect, modifiers }) => {
|
|
1135
|
+
const type = el.type;
|
|
1136
|
+
const assign = get(`(val) => { ${exp} = val }`);
|
|
1137
|
+
const { trim, number = type === "number", lazy, fill } = modifiers || {};
|
|
1138
|
+
const off = [];
|
|
1139
|
+
const on = (event, handler) => off.push(listen(el, event, handler));
|
|
1140
|
+
if (el.tagName === "SELECT") {
|
|
1141
|
+
const sel = el;
|
|
1142
|
+
on("change", () => {
|
|
1143
|
+
const selectedVal = Array.prototype.filter.call(sel.options, (o) => o.selected).map((o) => number ? toNumber(getValue(o)) : getValue(o));
|
|
1144
|
+
assign(sel.multiple ? selectedVal : selectedVal[0]);
|
|
1145
|
+
});
|
|
1146
|
+
effect(() => {
|
|
1147
|
+
const value = get();
|
|
1148
|
+
const isMultiple = sel.multiple;
|
|
1149
|
+
if (isMultiple && !isArray(value)) warnOnce(`select-multiple:${exp}`, `<select multiple v-model="${exp}"> needs an array, but got ${value === null ? "null" : typeof value}, so no option is selected. Initialise it as [] — a change writes an array either way.`);
|
|
1150
|
+
for (let i = 0, l = sel.options.length; i < l; i++) {
|
|
1151
|
+
const option = sel.options[i];
|
|
1152
|
+
const optionValue = getValue(option);
|
|
1153
|
+
if (isMultiple) option.selected = isArray(value) && looseIndexOf(value, optionValue) > -1;
|
|
1154
|
+
else if (looseEqual(getValue(option), value)) {
|
|
1155
|
+
if (sel.selectedIndex !== i) sel.selectedIndex = i;
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
if (!isMultiple && sel.selectedIndex !== -1) sel.selectedIndex = -1;
|
|
1160
|
+
});
|
|
1161
|
+
} else if (type === "checkbox") {
|
|
1162
|
+
on("change", () => {
|
|
1163
|
+
const modelValue = get();
|
|
1164
|
+
const checked = el.checked;
|
|
1165
|
+
if (isArray(modelValue)) {
|
|
1166
|
+
const elementValue = getValue(el);
|
|
1167
|
+
const index = looseIndexOf(modelValue, elementValue);
|
|
1168
|
+
const found = index !== -1;
|
|
1169
|
+
if (checked && !found) assign(modelValue.concat(elementValue));
|
|
1170
|
+
else if (!checked && found) {
|
|
1171
|
+
const filtered = [...modelValue];
|
|
1172
|
+
filtered.splice(index, 1);
|
|
1173
|
+
assign(filtered);
|
|
1174
|
+
}
|
|
1175
|
+
} else assign(getCheckboxValue(el, checked));
|
|
1176
|
+
});
|
|
1177
|
+
effect(() => {
|
|
1178
|
+
const value = get();
|
|
1179
|
+
if (isArray(value)) el.checked = looseIndexOf(value, getValue(el)) > -1;
|
|
1180
|
+
else el.checked = looseEqual(value, getCheckboxValue(el, true));
|
|
1181
|
+
});
|
|
1182
|
+
} else if (type === "radio") {
|
|
1183
|
+
on("change", () => {
|
|
1184
|
+
assign(getValue(el));
|
|
1185
|
+
});
|
|
1186
|
+
effect(() => {
|
|
1187
|
+
el.checked = looseEqual(get(), getValue(el));
|
|
1188
|
+
});
|
|
1189
|
+
} else {
|
|
1190
|
+
const resolveValue = (val) => {
|
|
1191
|
+
if (trim) val = val.trim();
|
|
1192
|
+
return number ? toNumber(val) : val;
|
|
1193
|
+
};
|
|
1194
|
+
let write = assign;
|
|
1195
|
+
let debounceTimer;
|
|
1196
|
+
for (const key in modifiers || {}) {
|
|
1197
|
+
const m = /^debounce(?:-(\d+))?$/.exec(key);
|
|
1198
|
+
if (m) {
|
|
1199
|
+
const ms = m[1] ? +m[1] : 250;
|
|
1200
|
+
write = (val) => {
|
|
1201
|
+
clearTimeout(debounceTimer);
|
|
1202
|
+
debounceTimer = setTimeout(assign, ms, val);
|
|
1203
|
+
};
|
|
1204
|
+
off.push(() => clearTimeout(debounceTimer));
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
on("compositionstart", onCompositionStart);
|
|
1208
|
+
on("compositionend", onCompositionEnd);
|
|
1209
|
+
on(lazy ? "change" : "input", () => {
|
|
1210
|
+
if (el.composing) return;
|
|
1211
|
+
write(resolveValue(el.value));
|
|
1212
|
+
});
|
|
1213
|
+
if (trim) on("change", () => {
|
|
1214
|
+
el.value = el.value.trim();
|
|
1215
|
+
});
|
|
1216
|
+
if (fill) {
|
|
1217
|
+
const cur = get();
|
|
1218
|
+
if ((cur == null || cur === "") && el.value) assign(resolveValue(el.value));
|
|
1219
|
+
}
|
|
1220
|
+
effect(() => {
|
|
1221
|
+
if (el.composing) return;
|
|
1222
|
+
const curVal = el.value;
|
|
1223
|
+
const newVal = get();
|
|
1224
|
+
if (document.activeElement === el && resolveValue(curVal) === newVal) return;
|
|
1225
|
+
if (curVal !== newVal) el.value = newVal;
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
return () => off.forEach((remove) => remove());
|
|
1229
|
+
};
|
|
1230
|
+
var getValue = (el) => "_value" in el ? el._value : el.value;
|
|
1231
|
+
var getCheckboxValue = (el, checked) => {
|
|
1232
|
+
const key = checked ? "_trueValue" : "_falseValue";
|
|
1233
|
+
return key in el ? el[key] : checked;
|
|
1234
|
+
};
|
|
1235
|
+
var onCompositionStart = (e) => {
|
|
1236
|
+
e.target.composing = true;
|
|
1237
|
+
};
|
|
1238
|
+
var onCompositionEnd = (e) => {
|
|
1239
|
+
const target = e.target;
|
|
1240
|
+
if (target.composing) {
|
|
1241
|
+
target.composing = false;
|
|
1242
|
+
trigger(target, "input");
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
var trigger = (el, type) => {
|
|
1246
|
+
const e = document.createEvent("HTMLEvents");
|
|
1247
|
+
e.initEvent(type, true, true);
|
|
1248
|
+
el.dispatchEvent(e);
|
|
1249
|
+
};
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/eval.ts
|
|
1252
|
+
var evalCache = Object.create(null);
|
|
1253
|
+
var mkDispatch = (el) => (event, detail) => el.dispatchEvent(new CustomEvent(event, {
|
|
1254
|
+
detail,
|
|
1255
|
+
bubbles: true
|
|
1256
|
+
}));
|
|
1257
|
+
var unwrap = (exp) => exp.replace(/^return\(([^]*)\)$/, "$1");
|
|
1258
|
+
var evaluate = (scope, exp, el, meta) => execute(scope, `return(${exp})`, el, meta);
|
|
1259
|
+
var execute = (scope, exp, el, meta) => {
|
|
1260
|
+
const fn = evalCache[exp] || (evalCache[exp] = toFunction(exp, el, meta));
|
|
1261
|
+
try {
|
|
1262
|
+
return fn(scope, el, el && mkDispatch(el));
|
|
1263
|
+
} catch (e) {
|
|
1264
|
+
handleError(e, {
|
|
1265
|
+
phase: "expression",
|
|
1266
|
+
expression: meta?.expression ?? unwrap(exp),
|
|
1267
|
+
source: meta?.source,
|
|
1268
|
+
el: meta?.el ?? el,
|
|
1269
|
+
scope
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
var toFunction = (exp, el, meta) => {
|
|
1274
|
+
try {
|
|
1275
|
+
return new Function(`$data`, `$el`, `$dispatch`, `with($data){${exp}}`);
|
|
1276
|
+
} catch (e) {
|
|
1277
|
+
handleError(e, {
|
|
1278
|
+
phase: "compile",
|
|
1279
|
+
expression: meta?.expression ?? unwrap(exp),
|
|
1280
|
+
source: meta?.source,
|
|
1281
|
+
el: meta?.el ?? el
|
|
1282
|
+
});
|
|
1283
|
+
return () => {};
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
//#endregion
|
|
1287
|
+
//#region src/ownership.ts
|
|
1288
|
+
var owned = /* @__PURE__ */ new WeakMap();
|
|
1289
|
+
/**
|
|
1290
|
+
* The node currently being walked. A module-level cursor suffices because the
|
|
1291
|
+
* walk is synchronous and depth-first, and it keeps `owner` out of every
|
|
1292
|
+
* directive signature.
|
|
1293
|
+
*/
|
|
1294
|
+
var owner;
|
|
1295
|
+
var setOwner = (node) => {
|
|
1296
|
+
const previous = owner;
|
|
1297
|
+
owner = node;
|
|
1298
|
+
return previous;
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* Registers a disposer against `node`, defaulting to the node being walked.
|
|
1302
|
+
* Pass `node` explicitly for a directive that outlives its element: `v-if` and
|
|
1303
|
+
* `v-for` detach the template and render from an anchor, so they must own to
|
|
1304
|
+
* the anchor.
|
|
1305
|
+
*/
|
|
1306
|
+
var own = (dispose, node = owner) => {
|
|
1307
|
+
if (!node) return;
|
|
1308
|
+
const list = owned.get(node);
|
|
1309
|
+
if (list) list.push(dispose);
|
|
1310
|
+
else owned.set(node, [dispose]);
|
|
1311
|
+
};
|
|
1312
|
+
/**
|
|
1313
|
+
* Disposes `node` and its subtree. Safe on an unowned node, and idempotent —
|
|
1314
|
+
* the record is dropped as it runs.
|
|
1315
|
+
*/
|
|
1316
|
+
var disposeSubtree = (node) => {
|
|
1317
|
+
const list = owned.get(node);
|
|
1318
|
+
if (list) {
|
|
1319
|
+
owned.delete(node);
|
|
1320
|
+
for (const fn of list) fn();
|
|
1321
|
+
}
|
|
1322
|
+
let child = node.firstChild;
|
|
1323
|
+
while (child) {
|
|
1324
|
+
const next = child.nextSibling;
|
|
1325
|
+
disposeSubtree(child);
|
|
1326
|
+
child = next;
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
//#endregion
|
|
1330
|
+
//#region src/directives/effect.ts
|
|
1331
|
+
var effect = ({ el, ctx, exp, effect }) => {
|
|
1332
|
+
let live = true;
|
|
1333
|
+
nextTick(() => {
|
|
1334
|
+
if (!live) return;
|
|
1335
|
+
const previous = setOwner(el);
|
|
1336
|
+
try {
|
|
1337
|
+
effect(() => execute(ctx.scope, exp, el, {
|
|
1338
|
+
source: "v-effect",
|
|
1339
|
+
el
|
|
1340
|
+
}));
|
|
1341
|
+
} finally {
|
|
1342
|
+
setOwner(previous);
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
return () => {
|
|
1346
|
+
live = false;
|
|
1347
|
+
};
|
|
1348
|
+
};
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region src/directives/index.ts
|
|
1351
|
+
var builtInDirectives = {
|
|
1352
|
+
bind,
|
|
1353
|
+
on,
|
|
1354
|
+
show,
|
|
1355
|
+
text,
|
|
1356
|
+
html,
|
|
1357
|
+
model,
|
|
1358
|
+
effect
|
|
1359
|
+
};
|
|
1360
|
+
//#endregion
|
|
1361
|
+
//#region src/directives/if.ts
|
|
1362
|
+
var _if = (el, exp, ctx) => {
|
|
1363
|
+
if (!exp.trim()) console.warn(`v-if expression cannot be empty.`);
|
|
1364
|
+
const anchor = new Comment("v-if");
|
|
1365
|
+
el.before(anchor);
|
|
1366
|
+
const branches = [{
|
|
1367
|
+
exp,
|
|
1368
|
+
el
|
|
1369
|
+
}];
|
|
1370
|
+
let elseEl;
|
|
1371
|
+
let elseExp;
|
|
1372
|
+
while (elseEl = el.nextElementSibling) {
|
|
1373
|
+
elseExp = null;
|
|
1374
|
+
if (checkAttr(elseEl, "v-else") === "" || (elseExp = checkAttr(elseEl, "v-else-if"))) {
|
|
1375
|
+
elseEl.remove();
|
|
1376
|
+
branches.push({
|
|
1377
|
+
exp: elseExp,
|
|
1378
|
+
el: elseEl
|
|
1379
|
+
});
|
|
1380
|
+
} else break;
|
|
1381
|
+
}
|
|
1382
|
+
const nextNode = el.nextSibling;
|
|
1383
|
+
el.remove();
|
|
1384
|
+
setOwner(anchor);
|
|
1385
|
+
let block;
|
|
1386
|
+
let activeBranchIndex = -1;
|
|
1387
|
+
const removeActiveBlock = () => {
|
|
1388
|
+
if (block) {
|
|
1389
|
+
if (!anchor.parentNode) block.el.before(anchor);
|
|
1390
|
+
block.remove();
|
|
1391
|
+
block = void 0;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
let branchEffect;
|
|
1395
|
+
const stopBranches = () => stopEffect(branchEffect);
|
|
1396
|
+
branchEffect = ctx.effect(() => {
|
|
1397
|
+
for (let i = 0; i < branches.length; i++) {
|
|
1398
|
+
const { exp, el } = branches[i];
|
|
1399
|
+
if (!exp || evaluate(ctx.scope, exp, el, {
|
|
1400
|
+
source: "v-if",
|
|
1401
|
+
el
|
|
1402
|
+
})) {
|
|
1403
|
+
if (i !== activeBranchIndex) {
|
|
1404
|
+
removeActiveBlock();
|
|
1405
|
+
const parent = anchor.parentNode;
|
|
1406
|
+
block = new Block(el, ctx);
|
|
1407
|
+
block.insert(parent, anchor);
|
|
1408
|
+
own(stopBranches, block.el);
|
|
1409
|
+
if (block.el.parentNode === parent) anchor.remove();
|
|
1410
|
+
activeBranchIndex = i;
|
|
1411
|
+
}
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
activeBranchIndex = -1;
|
|
1416
|
+
removeActiveBlock();
|
|
1417
|
+
});
|
|
1418
|
+
own(stopBranches, anchor);
|
|
1419
|
+
return nextNode;
|
|
1420
|
+
};
|
|
1421
|
+
//#endregion
|
|
1422
|
+
//#region src/directives/for.ts
|
|
1423
|
+
var forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
1424
|
+
var forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/;
|
|
1425
|
+
var stripParensRE = /^\(|\)$/g;
|
|
1426
|
+
var destructureRE = /^[{[]\s*((?:[\w_$]+\s*,?\s*)+)[\]}]$/;
|
|
1427
|
+
var _for = (el, exp, ctx) => {
|
|
1428
|
+
const inMatch = exp.match(forAliasRE);
|
|
1429
|
+
if (!inMatch) {
|
|
1430
|
+
console.warn(`invalid v-for expression: ${exp}`);
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
const nextNode = el.nextSibling;
|
|
1434
|
+
const anchor = new Text("");
|
|
1435
|
+
el.replaceWith(anchor);
|
|
1436
|
+
const parent = () => anchor.parentNode;
|
|
1437
|
+
setOwner(anchor);
|
|
1438
|
+
const sourceExp = inMatch[2].trim();
|
|
1439
|
+
let valueExp = inMatch[1].trim().replace(stripParensRE, "").trim();
|
|
1440
|
+
let destructureBindings;
|
|
1441
|
+
let isArrayDestructure = false;
|
|
1442
|
+
let indexExp;
|
|
1443
|
+
let objIndexExp;
|
|
1444
|
+
let keyAttr = "key";
|
|
1445
|
+
let keyExp = el.getAttribute(keyAttr) || el.getAttribute(keyAttr = ":key") || el.getAttribute(keyAttr = "v-bind:key");
|
|
1446
|
+
if (keyExp) {
|
|
1447
|
+
el.removeAttribute(keyAttr);
|
|
1448
|
+
if (keyAttr === "key") keyExp = JSON.stringify(keyExp);
|
|
1449
|
+
}
|
|
1450
|
+
let match;
|
|
1451
|
+
if (match = valueExp.match(forIteratorRE)) {
|
|
1452
|
+
valueExp = valueExp.replace(forIteratorRE, "").trim();
|
|
1453
|
+
indexExp = match[1].trim();
|
|
1454
|
+
if (match[2]) objIndexExp = match[2].trim();
|
|
1455
|
+
}
|
|
1456
|
+
if (match = valueExp.match(destructureRE)) {
|
|
1457
|
+
destructureBindings = match[1].split(",").map((s) => s.trim());
|
|
1458
|
+
isArrayDestructure = valueExp[0] === "[";
|
|
1459
|
+
}
|
|
1460
|
+
let mounted = false;
|
|
1461
|
+
let blocks;
|
|
1462
|
+
let childCtxs;
|
|
1463
|
+
let keyToIndexMap;
|
|
1464
|
+
const createChildContexts = (source) => {
|
|
1465
|
+
const map = /* @__PURE__ */ new Map();
|
|
1466
|
+
const ctxs = [];
|
|
1467
|
+
if (isArray(source)) for (let i = 0; i < source.length; i++) ctxs.push(createChildContext(map, source[i], i));
|
|
1468
|
+
else if (typeof source === "number") for (let i = 0; i < source; i++) ctxs.push(createChildContext(map, i + 1, i));
|
|
1469
|
+
else if (isObject(source)) {
|
|
1470
|
+
let i = 0;
|
|
1471
|
+
for (const key in source) ctxs.push(createChildContext(map, source[key], i++, key));
|
|
1472
|
+
}
|
|
1473
|
+
return [ctxs, map];
|
|
1474
|
+
};
|
|
1475
|
+
const createChildContext = (map, value, index, objKey) => {
|
|
1476
|
+
const data = {};
|
|
1477
|
+
if (destructureBindings) destructureBindings.forEach((b, i) => data[b] = value[isArrayDestructure ? i : b]);
|
|
1478
|
+
else data[valueExp] = value;
|
|
1479
|
+
if (objKey) {
|
|
1480
|
+
indexExp && (data[indexExp] = objKey);
|
|
1481
|
+
objIndexExp && (data[objIndexExp] = index);
|
|
1482
|
+
} else indexExp && (data[indexExp] = index);
|
|
1483
|
+
const childCtx = createScopedContext(ctx, data);
|
|
1484
|
+
const key = keyExp ? evaluate(childCtx.scope, keyExp, el, {
|
|
1485
|
+
source: ":key",
|
|
1486
|
+
el
|
|
1487
|
+
}) : index;
|
|
1488
|
+
map.set(key, index);
|
|
1489
|
+
childCtx.key = key;
|
|
1490
|
+
return childCtx;
|
|
1491
|
+
};
|
|
1492
|
+
const mountBlock = (ctx, ref) => {
|
|
1493
|
+
const block = new Block(el, ctx);
|
|
1494
|
+
block.key = ctx.key;
|
|
1495
|
+
block.insert(parent(), ref);
|
|
1496
|
+
return block;
|
|
1497
|
+
};
|
|
1498
|
+
let prevItems;
|
|
1499
|
+
ctx.effect(() => {
|
|
1500
|
+
const source = evaluate(ctx.scope, sourceExp, el, {
|
|
1501
|
+
source: "v-for",
|
|
1502
|
+
el
|
|
1503
|
+
});
|
|
1504
|
+
const prevKeyToIndexMap = keyToIndexMap;
|
|
1505
|
+
[childCtxs, keyToIndexMap] = createChildContexts(source);
|
|
1506
|
+
if (keyToIndexMap.size !== childCtxs.length) {
|
|
1507
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1508
|
+
let dup;
|
|
1509
|
+
for (const child of childCtxs) {
|
|
1510
|
+
const n = (counts.get(child.key) || 0) + 1;
|
|
1511
|
+
counts.set(child.key, n);
|
|
1512
|
+
if (n > 1 && dup === void 0) dup = child.key;
|
|
1513
|
+
}
|
|
1514
|
+
warnOnce(`for-dup-key:${exp}`, `v-for="${exp}" produced a duplicate :key ${JSON.stringify(dup)}. Keys must be unique among siblings — with a repeat, one item's element and its scope state are silently dropped. Key by something stable and unique, such as a record id.`);
|
|
1515
|
+
}
|
|
1516
|
+
if (!keyExp && isArray(source)) {
|
|
1517
|
+
const items = [...source];
|
|
1518
|
+
if (prevItems) {
|
|
1519
|
+
if (items.some((item, i) => {
|
|
1520
|
+
const was = prevItems.indexOf(item);
|
|
1521
|
+
return was > -1 && was !== i;
|
|
1522
|
+
})) warnOnce(`for-no-key:${exp}`, `v-for="${exp}" has no :key and its items were reordered. Without a key the list reconciles by position, so elements are reused for different items — losing focus, cursor position, scroll offset and any state held on those nodes. Add :key with a value that identifies the item.`);
|
|
1523
|
+
}
|
|
1524
|
+
prevItems = items;
|
|
1525
|
+
}
|
|
1526
|
+
if (!mounted) {
|
|
1527
|
+
blocks = childCtxs.map((s) => mountBlock(s, anchor));
|
|
1528
|
+
mounted = true;
|
|
1529
|
+
} else {
|
|
1530
|
+
for (let i = 0; i < blocks.length; i++) if (!keyToIndexMap.has(blocks[i].key)) blocks[i].remove();
|
|
1531
|
+
const nextBlocks = [];
|
|
1532
|
+
let i = childCtxs.length;
|
|
1533
|
+
let nextBlock;
|
|
1534
|
+
let prevMovedBlock;
|
|
1535
|
+
while (i--) {
|
|
1536
|
+
const childCtx = childCtxs[i];
|
|
1537
|
+
const oldIndex = prevKeyToIndexMap.get(childCtx.key);
|
|
1538
|
+
let block;
|
|
1539
|
+
if (oldIndex == null) block = mountBlock(childCtx, nextBlock ? nextBlock.el : anchor);
|
|
1540
|
+
else {
|
|
1541
|
+
block = blocks[oldIndex];
|
|
1542
|
+
Object.assign(block.ctx.scope, childCtx.scope);
|
|
1543
|
+
if (oldIndex !== i) {
|
|
1544
|
+
if (blocks[oldIndex + 1] !== nextBlock || prevMovedBlock === nextBlock) {
|
|
1545
|
+
prevMovedBlock = block;
|
|
1546
|
+
block.insert(parent(), nextBlock ? nextBlock.el : anchor);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
nextBlocks.unshift(nextBlock = block);
|
|
1551
|
+
}
|
|
1552
|
+
blocks = nextBlocks;
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
return nextNode;
|
|
1556
|
+
};
|
|
1557
|
+
//#endregion
|
|
1558
|
+
//#region src/directives/ref.ts
|
|
1559
|
+
var ref = ({ el, ctx: { scope: { $refs } }, get, effect }) => {
|
|
1560
|
+
let prevRef;
|
|
1561
|
+
effect(() => {
|
|
1562
|
+
const ref = get();
|
|
1563
|
+
{
|
|
1564
|
+
const existing = $refs[ref];
|
|
1565
|
+
if (existing && existing !== el && existing.isConnected) warnOnce(`ref-dup:${ref}`, `two elements claim ref="${ref}" in the same scope; $refs.${ref} points at the last one mounted and the earlier element is no longer reachable. Give each element its own name, or key off the item inside v-for rather than using a ref.`);
|
|
1566
|
+
}
|
|
1567
|
+
$refs[ref] = el;
|
|
1568
|
+
if (prevRef && ref !== prevRef) delete $refs[prevRef];
|
|
1569
|
+
prevRef = ref;
|
|
1570
|
+
});
|
|
1571
|
+
return () => {
|
|
1572
|
+
prevRef && delete $refs[prevRef];
|
|
1573
|
+
};
|
|
1574
|
+
};
|
|
1575
|
+
//#endregion
|
|
1576
|
+
//#region src/lazy.ts
|
|
1577
|
+
var LAZY_MODES = [
|
|
1578
|
+
"visible",
|
|
1579
|
+
"idle",
|
|
1580
|
+
"interaction"
|
|
1581
|
+
];
|
|
1582
|
+
/** Selector matching every scope root, deferred or not. */
|
|
1583
|
+
var SCOPE_SELECTOR = ["[v-scope]", ...LAZY_MODES.map((m) => `[v-scope\\.${m}]`)].join(",");
|
|
1584
|
+
var INTERACTIONS = [
|
|
1585
|
+
"pointerdown",
|
|
1586
|
+
"keydown",
|
|
1587
|
+
"focusin"
|
|
1588
|
+
];
|
|
1589
|
+
/**
|
|
1590
|
+
* Arms `mode` and returns a disposer. Fires at most once; disposing first
|
|
1591
|
+
* cancels it, since a region can be unmounted while still waiting.
|
|
1592
|
+
*/
|
|
1593
|
+
var arm = (el, mode, fire) => {
|
|
1594
|
+
let done = false;
|
|
1595
|
+
const once = () => {
|
|
1596
|
+
if (done) return;
|
|
1597
|
+
done = true;
|
|
1598
|
+
stop();
|
|
1599
|
+
fire();
|
|
1600
|
+
};
|
|
1601
|
+
let stop = () => {};
|
|
1602
|
+
if (mode === "visible" && typeof IntersectionObserver == "function") {
|
|
1603
|
+
const io = new IntersectionObserver((entries) => {
|
|
1604
|
+
if (entries.some((e) => e.isIntersecting)) once();
|
|
1605
|
+
});
|
|
1606
|
+
io.observe(el);
|
|
1607
|
+
stop = () => io.disconnect();
|
|
1608
|
+
} else if (mode !== "interaction") {
|
|
1609
|
+
const ric = window.requestIdleCallback;
|
|
1610
|
+
const id = ric ? ric(once) : setTimeout(once);
|
|
1611
|
+
stop = () => ric ? window.cancelIdleCallback(id) : clearTimeout(id);
|
|
1612
|
+
} else {
|
|
1613
|
+
for (const type of INTERACTIONS) el.addEventListener(type, once);
|
|
1614
|
+
stop = () => {
|
|
1615
|
+
for (const type of INTERACTIONS) el.removeEventListener(type, once);
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
return () => {
|
|
1619
|
+
done = true;
|
|
1620
|
+
stop();
|
|
1621
|
+
};
|
|
1622
|
+
};
|
|
1623
|
+
/**
|
|
1624
|
+
* Returns true if `el` was deferred. The walk must not descend into it:
|
|
1625
|
+
* walking consumes directives, so it could not be walked again later.
|
|
1626
|
+
*/
|
|
1627
|
+
var deferScope = (el, ctx, walk, once) => {
|
|
1628
|
+
const mode = LAZY_MODES.find((m) => el.hasAttribute(`v-scope.${m}`));
|
|
1629
|
+
if (!mode) return false;
|
|
1630
|
+
const attr = `v-scope.${mode}`;
|
|
1631
|
+
const dispose = arm(el, mode, () => {
|
|
1632
|
+
if (!el.hasAttribute(attr)) return;
|
|
1633
|
+
el.setAttribute("v-scope", el.getAttribute(attr));
|
|
1634
|
+
el.removeAttribute(attr);
|
|
1635
|
+
walk(el, ctx, once);
|
|
1636
|
+
});
|
|
1637
|
+
ctx.cleanups.push(dispose);
|
|
1638
|
+
own(dispose);
|
|
1639
|
+
return true;
|
|
1640
|
+
};
|
|
1641
|
+
//#endregion
|
|
1642
|
+
//#region src/walk.ts
|
|
1643
|
+
var dirRE = /^(?:v-|:|@)/;
|
|
1644
|
+
var modifierRE = /\.([\w-]+)/g;
|
|
1645
|
+
var inOnce = false;
|
|
1646
|
+
/**
|
|
1647
|
+
* Registers a cleanup on both owners: the context, for whole-region teardown,
|
|
1648
|
+
* and the walked node, for a subtree detached on its own. Dropping the entry
|
|
1649
|
+
* when the node goes keeps a re-mounted region from accumulating spent ones.
|
|
1650
|
+
*
|
|
1651
|
+
* The `indexOf` guard also makes this run-once. A subtree can reach the same
|
|
1652
|
+
* cleanup twice — via the block root, whose teardown drains `ctx.cleanups`,
|
|
1653
|
+
* and via the node — and a second run would remove a listener the next mount
|
|
1654
|
+
* installed.
|
|
1655
|
+
*/
|
|
1656
|
+
var addCleanup = (ctx, cleanup) => {
|
|
1657
|
+
ctx.cleanups.push(cleanup);
|
|
1658
|
+
own(() => {
|
|
1659
|
+
const i = ctx.cleanups.indexOf(cleanup);
|
|
1660
|
+
if (i > -1) {
|
|
1661
|
+
ctx.cleanups.splice(i, 1);
|
|
1662
|
+
cleanup();
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
};
|
|
1666
|
+
var walkDeferred = (node, ctx, once) => {
|
|
1667
|
+
const previous = inOnce;
|
|
1668
|
+
inOnce = once;
|
|
1669
|
+
try {
|
|
1670
|
+
walk(node, ctx);
|
|
1671
|
+
} finally {
|
|
1672
|
+
inOnce = previous;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
var walk = (node, ctx) => {
|
|
1676
|
+
const previousOwner = setOwner(node);
|
|
1677
|
+
try {
|
|
1678
|
+
return walkNode(node, ctx);
|
|
1679
|
+
} finally {
|
|
1680
|
+
setOwner(previousOwner);
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
var walkNode = (node, ctx) => {
|
|
1684
|
+
const type = node.nodeType;
|
|
1685
|
+
if (type === 1) {
|
|
1686
|
+
const el = node;
|
|
1687
|
+
if (el.hasAttribute("v-pre")) return;
|
|
1688
|
+
if (deferScope(el, ctx, walkDeferred, inOnce)) return;
|
|
1689
|
+
checkAttr(el, "v-cloak");
|
|
1690
|
+
let exp;
|
|
1691
|
+
if (exp = checkAttr(el, "v-if")) return _if(el, exp, ctx);
|
|
1692
|
+
if (exp = checkAttr(el, "v-for")) return _for(el, exp, ctx);
|
|
1693
|
+
const name = checkAttr(el, "v-name");
|
|
1694
|
+
let teleportNext;
|
|
1695
|
+
if (exp = checkAttr(el, "v-teleport")) {
|
|
1696
|
+
const target = document.querySelector(exp);
|
|
1697
|
+
if (target) {
|
|
1698
|
+
teleportNext = el.nextSibling;
|
|
1699
|
+
el.__teleported = true;
|
|
1700
|
+
target.appendChild(el);
|
|
1701
|
+
ctx.cleanups.push(() => el.remove());
|
|
1702
|
+
} else console.error(`v-teleport target "${exp}" not found.`);
|
|
1703
|
+
}
|
|
1704
|
+
if ((exp = checkAttr(el, "v-scope")) || exp === "") {
|
|
1705
|
+
const scope = (exp ? evaluate(ctx.scope, exp, el, {
|
|
1706
|
+
source: "v-scope",
|
|
1707
|
+
el
|
|
1708
|
+
}) : {}) || {};
|
|
1709
|
+
ctx = createScopedContext(ctx, scope);
|
|
1710
|
+
el.__ctx = ctx;
|
|
1711
|
+
addCleanup(ctx, registerScope(el, ctx.scope, exp || void 0, name || void 0));
|
|
1712
|
+
if (scope.$template) resolveTemplate(el, scope.$template);
|
|
1713
|
+
}
|
|
1714
|
+
const hasVOnce = checkAttr(el, "v-once") != null;
|
|
1715
|
+
if (hasVOnce) inOnce = true;
|
|
1716
|
+
if (exp = checkAttr(el, "ref")) applyDirective(el, ref, `"${exp}"`, ctx);
|
|
1717
|
+
walkChildren(el, ctx);
|
|
1718
|
+
const deferred = [];
|
|
1719
|
+
for (const { name, value } of [...el.attributes]) if (dirRE.test(name) && name !== "v-cloak") {
|
|
1720
|
+
if (name === "v-model" || name.startsWith("v-model.")) deferred.unshift([name, value]);
|
|
1721
|
+
else if (name[0] === "@" || /^v-on\b/.test(name)) deferred.push([name, value]);
|
|
1722
|
+
else processDirective(el, name, value, ctx);
|
|
1723
|
+
}
|
|
1724
|
+
for (const [name, value] of deferred) processDirective(el, name, value, ctx);
|
|
1725
|
+
if (hasVOnce) inOnce = false;
|
|
1726
|
+
return teleportNext;
|
|
1727
|
+
} else if (type === 3) {
|
|
1728
|
+
const data = node.data;
|
|
1729
|
+
if (data.includes(ctx.delimiters[0])) {
|
|
1730
|
+
let segments = [];
|
|
1731
|
+
let lastIndex = 0;
|
|
1732
|
+
let match;
|
|
1733
|
+
while (match = ctx.delimitersRE.exec(data)) {
|
|
1734
|
+
const leading = data.slice(lastIndex, match.index);
|
|
1735
|
+
if (leading) segments.push(JSON.stringify(leading));
|
|
1736
|
+
segments.push(`$s(${match[1]})`);
|
|
1737
|
+
lastIndex = match.index + match[0].length;
|
|
1738
|
+
}
|
|
1739
|
+
if (lastIndex < data.length) segments.push(JSON.stringify(data.slice(lastIndex)));
|
|
1740
|
+
applyDirective(node, text, segments.join("+"), ctx, void 0, void 0, "{{ }}", data.trim());
|
|
1741
|
+
}
|
|
1742
|
+
} else if (type === 11) walkChildren(node, ctx);
|
|
1743
|
+
};
|
|
1744
|
+
var walkChildren = (node, ctx) => {
|
|
1745
|
+
let child = node.firstChild;
|
|
1746
|
+
while (child) child = walk(child, ctx) || child.nextSibling;
|
|
1747
|
+
};
|
|
1748
|
+
var processDirective = (el, raw, exp, ctx) => {
|
|
1749
|
+
let dir;
|
|
1750
|
+
let arg;
|
|
1751
|
+
let modifiers;
|
|
1752
|
+
const source = raw;
|
|
1753
|
+
raw = raw.replace(modifierRE, (_, m) => {
|
|
1754
|
+
(modifiers || (modifiers = {}))[m] = true;
|
|
1755
|
+
return "";
|
|
1756
|
+
});
|
|
1757
|
+
if (raw[0] === ":") {
|
|
1758
|
+
dir = bind;
|
|
1759
|
+
arg = raw.slice(1);
|
|
1760
|
+
} else if (raw[0] === "@") {
|
|
1761
|
+
dir = on;
|
|
1762
|
+
arg = raw.slice(1);
|
|
1763
|
+
} else {
|
|
1764
|
+
const argIndex = raw.indexOf(":");
|
|
1765
|
+
const dirName = argIndex > 0 ? raw.slice(2, argIndex) : raw.slice(2);
|
|
1766
|
+
dir = builtInDirectives[dirName] || ctx.dirs[dirName];
|
|
1767
|
+
arg = argIndex > 0 ? raw.slice(argIndex + 1) : void 0;
|
|
1768
|
+
}
|
|
1769
|
+
if (dir) {
|
|
1770
|
+
if (dir === bind && arg === "ref") dir = ref;
|
|
1771
|
+
applyDirective(el, dir, exp, ctx, arg, modifiers, source);
|
|
1772
|
+
el.removeAttribute(source);
|
|
1773
|
+
} else {
|
|
1774
|
+
const known = [
|
|
1775
|
+
"v-scope",
|
|
1776
|
+
"v-if",
|
|
1777
|
+
"v-for",
|
|
1778
|
+
"v-once",
|
|
1779
|
+
"v-pre",
|
|
1780
|
+
"v-cloak",
|
|
1781
|
+
"v-teleport",
|
|
1782
|
+
"v-name",
|
|
1783
|
+
"ref",
|
|
1784
|
+
...Object.keys(builtInDirectives).map((d) => "v-" + d),
|
|
1785
|
+
...Object.keys(ctx.dirs).map((d) => "v-" + d)
|
|
1786
|
+
].sort();
|
|
1787
|
+
console.error(`[litevue] unknown directive ${source} on ${describeEl(el)}.\n Known directives: ${known.join(", ")}.\n A directive from a plugin needs app.use(...) before mount().`);
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var applyDirective = (el, dir, exp, ctx, arg, modifiers, source, displayExp) => {
|
|
1791
|
+
const meta = {
|
|
1792
|
+
source,
|
|
1793
|
+
el,
|
|
1794
|
+
expression: displayExp
|
|
1795
|
+
};
|
|
1796
|
+
const get = (e = exp) => evaluate(ctx.scope, e, el, meta);
|
|
1797
|
+
let cleanup;
|
|
1798
|
+
try {
|
|
1799
|
+
cleanup = dir({
|
|
1800
|
+
el,
|
|
1801
|
+
get,
|
|
1802
|
+
effect: ctx.effect,
|
|
1803
|
+
ctx,
|
|
1804
|
+
exp,
|
|
1805
|
+
arg,
|
|
1806
|
+
modifiers
|
|
1807
|
+
});
|
|
1808
|
+
} catch (e) {
|
|
1809
|
+
handleError(e, {
|
|
1810
|
+
phase: "directive",
|
|
1811
|
+
source,
|
|
1812
|
+
el,
|
|
1813
|
+
expression: exp
|
|
1814
|
+
});
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
if (cleanup) addCleanup(ctx, cleanup);
|
|
1818
|
+
};
|
|
1819
|
+
var resolveTemplate = (el, template) => {
|
|
1820
|
+
if (template[0] === "#") {
|
|
1821
|
+
const templateEl = document.querySelector(template);
|
|
1822
|
+
if (!templateEl) {
|
|
1823
|
+
console.error(`template selector ${template} has no matching <template> element.`);
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
el.appendChild(templateEl.content.cloneNode(true));
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
el.innerHTML = template;
|
|
1830
|
+
};
|
|
1831
|
+
//#endregion
|
|
1832
|
+
//#region src/context.ts
|
|
1833
|
+
var createContext = (parent) => {
|
|
1834
|
+
const ctx = {
|
|
1835
|
+
delimiters: ["{{", "}}"],
|
|
1836
|
+
delimitersRE: /\{\{([^]+?)\}\}/g,
|
|
1837
|
+
...parent,
|
|
1838
|
+
scope: parent ? parent.scope : reactive({}),
|
|
1839
|
+
dirs: parent ? parent.dirs : {},
|
|
1840
|
+
effects: [],
|
|
1841
|
+
blocks: [],
|
|
1842
|
+
cleanups: [],
|
|
1843
|
+
effect: (fn) => {
|
|
1844
|
+
if (inOnce) {
|
|
1845
|
+
queueJob(fn);
|
|
1846
|
+
return fn;
|
|
1847
|
+
}
|
|
1848
|
+
const e = effect$1(fn, { scheduler: () => queueJob(e) });
|
|
1849
|
+
ctx.effects.push(e);
|
|
1850
|
+
own(() => {
|
|
1851
|
+
stopEffect(e);
|
|
1852
|
+
remove(ctx.effects, e);
|
|
1853
|
+
});
|
|
1854
|
+
return e;
|
|
1855
|
+
}
|
|
1856
|
+
};
|
|
1857
|
+
return ctx;
|
|
1858
|
+
};
|
|
1859
|
+
/**
|
|
1860
|
+
* Framework-provided, so non-enumerable: `Object.assign`-ing one scope onto
|
|
1861
|
+
* another must copy the user's data and leave these alone. v-for does exactly
|
|
1862
|
+
* that on every update, which reset each row's $id and wiped its $refs.
|
|
1863
|
+
*/
|
|
1864
|
+
var hide = (scope, key, value) => Object.defineProperty(scope, key, {
|
|
1865
|
+
value,
|
|
1866
|
+
writable: true,
|
|
1867
|
+
configurable: true
|
|
1868
|
+
});
|
|
1869
|
+
var createScopedContext = (ctx, data = {}) => {
|
|
1870
|
+
const parentScope = ctx.scope;
|
|
1871
|
+
const mergedScope = Object.create(parentScope);
|
|
1872
|
+
Object.defineProperties(mergedScope, Object.getOwnPropertyDescriptors(data));
|
|
1873
|
+
hide(mergedScope, "$refs", Object.create(parentScope.$refs));
|
|
1874
|
+
const reactiveProxy = reactive(new Proxy(mergedScope, { set(target, key, val, receiver) {
|
|
1875
|
+
if (receiver === reactiveProxy && !hasOwn(target, key)) return Reflect.set(parentScope, key, val);
|
|
1876
|
+
return Reflect.set(target, key, val, receiver);
|
|
1877
|
+
} }));
|
|
1878
|
+
const scopedCtx = {
|
|
1879
|
+
...ctx,
|
|
1880
|
+
scope: reactiveProxy
|
|
1881
|
+
};
|
|
1882
|
+
hide(mergedScope, "$watch", createWatch(scopedCtx));
|
|
1883
|
+
hide(mergedScope, "$id", createId());
|
|
1884
|
+
bindContextMethods(reactiveProxy);
|
|
1885
|
+
return scopedCtx;
|
|
1886
|
+
};
|
|
1887
|
+
var bindContextMethods = (scope) => {
|
|
1888
|
+
for (const key of Object.keys(scope)) {
|
|
1889
|
+
const fn = Object.getOwnPropertyDescriptor(scope, key).value;
|
|
1890
|
+
if (typeof fn === "function") scope[key] = fn.bind(scope);
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
//#endregion
|
|
1894
|
+
//#region src/block.ts
|
|
1895
|
+
var Block = class {
|
|
1896
|
+
template;
|
|
1897
|
+
ctx;
|
|
1898
|
+
key;
|
|
1899
|
+
parentCtx;
|
|
1900
|
+
isFragment;
|
|
1901
|
+
start;
|
|
1902
|
+
end;
|
|
1903
|
+
owned = false;
|
|
1904
|
+
get el() {
|
|
1905
|
+
return this.start || this.template;
|
|
1906
|
+
}
|
|
1907
|
+
constructor(template, parentCtx, isRoot = false) {
|
|
1908
|
+
this.isFragment = template instanceof HTMLTemplateElement;
|
|
1909
|
+
if (isRoot) this.template = template;
|
|
1910
|
+
else if (this.isFragment) this.template = template.content.cloneNode(true);
|
|
1911
|
+
else this.template = template.cloneNode(true);
|
|
1912
|
+
if (isRoot) this.ctx = createContext(parentCtx);
|
|
1913
|
+
else {
|
|
1914
|
+
this.parentCtx = parentCtx;
|
|
1915
|
+
parentCtx.blocks.push(this);
|
|
1916
|
+
this.ctx = createContext(parentCtx);
|
|
1917
|
+
}
|
|
1918
|
+
walk(this.template, this.ctx);
|
|
1919
|
+
}
|
|
1920
|
+
insert(parent, anchor = null) {
|
|
1921
|
+
if (this.isFragment) {
|
|
1922
|
+
if (this.start) {
|
|
1923
|
+
let node = this.start;
|
|
1924
|
+
let next;
|
|
1925
|
+
while (node) {
|
|
1926
|
+
next = node.nextSibling;
|
|
1927
|
+
parent.insertBefore(node, anchor);
|
|
1928
|
+
if (node === this.end) break;
|
|
1929
|
+
node = next;
|
|
1930
|
+
}
|
|
1931
|
+
} else {
|
|
1932
|
+
this.start = new Text("");
|
|
1933
|
+
this.end = new Text("");
|
|
1934
|
+
parent.insertBefore(this.end, anchor);
|
|
1935
|
+
parent.insertBefore(this.start, this.end);
|
|
1936
|
+
parent.insertBefore(this.template, this.end);
|
|
1937
|
+
}
|
|
1938
|
+
} else if (!this.template.__teleported) parent.insertBefore(this.template, anchor);
|
|
1939
|
+
if (!this.owned) {
|
|
1940
|
+
this.owned = true;
|
|
1941
|
+
own(() => this.discard(), this.el);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
remove() {
|
|
1945
|
+
if (this.parentCtx) remove(this.parentCtx.blocks, this);
|
|
1946
|
+
const removeNow = () => {
|
|
1947
|
+
const parent = this.start ? this.start.parentNode : this.template.parentNode;
|
|
1948
|
+
if (parent) {
|
|
1949
|
+
if (this.start) {
|
|
1950
|
+
let node = this.start;
|
|
1951
|
+
let next;
|
|
1952
|
+
while (node) {
|
|
1953
|
+
next = node.nextSibling;
|
|
1954
|
+
parent.removeChild(node);
|
|
1955
|
+
if (node === this.end) break;
|
|
1956
|
+
node = next;
|
|
1957
|
+
}
|
|
1958
|
+
} else parent.removeChild(this.template);
|
|
1959
|
+
}
|
|
1960
|
+
this.teardown();
|
|
1961
|
+
};
|
|
1962
|
+
const leave = this.isFragment ? void 0 : this.template.__leave;
|
|
1963
|
+
if (leave) leave().then(removeNow);
|
|
1964
|
+
else removeNow();
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* The bookkeeping half of `remove()`, for a block whose nodes are already
|
|
1968
|
+
* gone — `remove()`'s `removeChild` calls would throw on them.
|
|
1969
|
+
*/
|
|
1970
|
+
discard() {
|
|
1971
|
+
if (this.parentCtx) remove(this.parentCtx.blocks, this);
|
|
1972
|
+
this.teardown();
|
|
1973
|
+
}
|
|
1974
|
+
teardown() {
|
|
1975
|
+
this.ctx.blocks.splice(0).forEach((child) => {
|
|
1976
|
+
child.teardown();
|
|
1977
|
+
});
|
|
1978
|
+
this.ctx.effects.splice(0).forEach(stopEffect);
|
|
1979
|
+
this.ctx.cleanups.splice(0).forEach((fn) => fn());
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/store.ts
|
|
1984
|
+
/**
|
|
1985
|
+
* DEV: catch `$store.typo`, which otherwise reads as `undefined` and renders a
|
|
1986
|
+
* blank instead of raising.
|
|
1987
|
+
*
|
|
1988
|
+
* The trap sits *under* `reactive`, not over it: `reactive` probes its target
|
|
1989
|
+
* for `__v_raw`, and a wrapper that forwards that probe is bypassed entirely.
|
|
1990
|
+
* `__v_`-prefixed keys are ignored for the same reason — they are not reads a
|
|
1991
|
+
* user wrote.
|
|
1992
|
+
*
|
|
1993
|
+
* Deferred to the end of the task, because reading a store before it is
|
|
1994
|
+
* registered is legitimate — the registry is reactive so the expression
|
|
1995
|
+
* re-runs. A microtask would warn on a store registered after an `await`. One
|
|
1996
|
+
* registered later still warns; a check cannot wait forever.
|
|
1997
|
+
*/
|
|
1998
|
+
var registry = Object.create(null);
|
|
1999
|
+
var target = registry;
|
|
2000
|
+
target = new Proxy(registry, { get(obj, key, receiver) {
|
|
2001
|
+
if (typeof key === "string" && !key.startsWith("__") && !(key in obj)) setTimeout(() => {
|
|
2002
|
+
if (key in obj) return;
|
|
2003
|
+
warnOnce(`store-missing:${key}`, `$store.${key} is not registered, so it reads as undefined. Register it with store('${key}', { … }) before mounting, or check the spelling.`);
|
|
2004
|
+
});
|
|
2005
|
+
return Reflect.get(obj, key, receiver);
|
|
2006
|
+
} });
|
|
2007
|
+
var stores = reactive(target);
|
|
2008
|
+
/**
|
|
2009
|
+
* Register or retrieve a global store, shared across apps and exposed to every
|
|
2010
|
+
* expression as `$store.<name>`. Passing a value registers it and runs its
|
|
2011
|
+
* `init()` once, if present; omitting one retrieves.
|
|
2012
|
+
*/
|
|
2013
|
+
var store = (name, value) => {
|
|
2014
|
+
if (value !== void 0) {
|
|
2015
|
+
stores[name] = value;
|
|
2016
|
+
if (typeof stores[name].init === "function") stores[name].init();
|
|
2017
|
+
registerStore(name, stores[name]);
|
|
2018
|
+
}
|
|
2019
|
+
return stores[name];
|
|
2020
|
+
};
|
|
2021
|
+
//#endregion
|
|
2022
|
+
//#region src/app.ts
|
|
2023
|
+
var mountedRoots = /* @__PURE__ */ new WeakSet();
|
|
2024
|
+
var escapeRegex = (str) => str.replace(/[-.*+?^${}()|[\]/\\]/g, "\\$&");
|
|
2025
|
+
var createApp = (initialData) => {
|
|
2026
|
+
const ctx = createContext();
|
|
2027
|
+
if (typeof initialData === "function") {
|
|
2028
|
+
initialData = initialData();
|
|
2029
|
+
if (!initialData || typeof initialData !== "object") console.error(`createApp setup function must return an object.`);
|
|
2030
|
+
}
|
|
2031
|
+
if (initialData) {
|
|
2032
|
+
ctx.scope = reactive(initialData);
|
|
2033
|
+
bindContextMethods(ctx.scope);
|
|
2034
|
+
if (initialData.$delimiters) {
|
|
2035
|
+
const [open, close] = ctx.delimiters = initialData.$delimiters;
|
|
2036
|
+
ctx.delimitersRE = new RegExp(escapeRegex(open) + "([^]+?)" + escapeRegex(close), "g");
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
ctx.scope.$s = toDisplayString;
|
|
2040
|
+
ctx.scope.$nextTick = nextTick;
|
|
2041
|
+
ctx.scope.$refs = Object.create(null);
|
|
2042
|
+
ctx.scope.$store = stores;
|
|
2043
|
+
ctx.scope.$watch = createWatch(ctx);
|
|
2044
|
+
ctx.scope.$id = createId();
|
|
2045
|
+
Object.defineProperty(ctx.scope, "$root", {
|
|
2046
|
+
value: ctx.scope,
|
|
2047
|
+
enumerable: false
|
|
2048
|
+
});
|
|
2049
|
+
const components = Object.create(null);
|
|
2050
|
+
let rootBlocks = [];
|
|
2051
|
+
const installedPlugins = /* @__PURE__ */ new Set();
|
|
2052
|
+
const pluginTeardowns = [];
|
|
2053
|
+
const ownErrorHandlers = [];
|
|
2054
|
+
const app = {
|
|
2055
|
+
get scope() {
|
|
2056
|
+
return ctx.scope;
|
|
2057
|
+
},
|
|
2058
|
+
directive(name, def) {
|
|
2059
|
+
if (def) {
|
|
2060
|
+
ctx.dirs[name] = def;
|
|
2061
|
+
return this;
|
|
2062
|
+
} else return ctx.dirs[name];
|
|
2063
|
+
},
|
|
2064
|
+
component(name, factory) {
|
|
2065
|
+
if (!factory) return components[name];
|
|
2066
|
+
if (name in components) warn(`component "${name}" is already registered and has been replaced. Registering twice is usually two modules claiming the same name.`);
|
|
2067
|
+
else if (name in ctx.scope) warn(`component "${name}" was not registered: the root scope already has a "${name}", and overwriting it would replace your data with the component. Rename one of them.`);
|
|
2068
|
+
if (!(name in components) && name in ctx.scope) return this;
|
|
2069
|
+
components[name] = factory;
|
|
2070
|
+
registerComponent(name);
|
|
2071
|
+
ctx.scope[name] = factory;
|
|
2072
|
+
return this;
|
|
2073
|
+
},
|
|
2074
|
+
onError(handler) {
|
|
2075
|
+
const off = addErrorHandler(handler);
|
|
2076
|
+
ownErrorHandlers.push(off);
|
|
2077
|
+
return () => {
|
|
2078
|
+
const i = ownErrorHandlers.indexOf(off);
|
|
2079
|
+
if (i > -1) ownErrorHandlers.splice(i, 1);
|
|
2080
|
+
off();
|
|
2081
|
+
};
|
|
2082
|
+
},
|
|
2083
|
+
use(plugin, options) {
|
|
2084
|
+
if (!installedPlugins.has(plugin)) {
|
|
2085
|
+
installedPlugins.add(plugin);
|
|
2086
|
+
const teardown = (typeof plugin === "function" ? plugin : plugin.install)(app, options);
|
|
2087
|
+
if (typeof teardown === "function") pluginTeardowns.push(teardown);
|
|
2088
|
+
}
|
|
2089
|
+
return app;
|
|
2090
|
+
},
|
|
2091
|
+
mount(el) {
|
|
2092
|
+
if (typeof el === "string") {
|
|
2093
|
+
const target = document.querySelector(el);
|
|
2094
|
+
if (!target) {
|
|
2095
|
+
console.error(`mount: selector ${el} has no matching element.`);
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
el = target;
|
|
2099
|
+
}
|
|
2100
|
+
el = el || document.documentElement;
|
|
2101
|
+
let roots;
|
|
2102
|
+
if (el.matches(SCOPE_SELECTOR)) roots = [el];
|
|
2103
|
+
else roots = [...el.querySelectorAll(SCOPE_SELECTOR)].filter((root) => !root.matches(`:where(${SCOPE_SELECTOR}) *`));
|
|
2104
|
+
if (!roots.length) roots = [el];
|
|
2105
|
+
if (roots.length === 1 && roots[0] === document.documentElement) console.warn("Mounting on documentElement - this is non-optimal as LiteVue will be forced to crawl the entire page's DOM. Consider explicitly marking elements controlled by LiteVue with `v-scope`.");
|
|
2106
|
+
ctx.walk ??= walk;
|
|
2107
|
+
ctx.dispose ??= disposeSubtree;
|
|
2108
|
+
for (const el of roots) {
|
|
2109
|
+
if (mountedRoots.has(el)) warn("mount() was called again on an element that has already been mounted, so its directives were consumed by the first walk and nothing was bound this time. To re-activate a region, insert fresh markup and mount that instead.");
|
|
2110
|
+
mountedRoots.add(el);
|
|
2111
|
+
const name = el.getAttribute("v-name");
|
|
2112
|
+
const block = new Block(el, ctx, true);
|
|
2113
|
+
el.__ctx ??= block.ctx;
|
|
2114
|
+
if (!devtools.scopes.has(el) && !el.matches(SCOPE_SELECTOR)) block.ctx.cleanups.push(registerScope(el, block.ctx.scope, void 0, name || void 0));
|
|
2115
|
+
rootBlocks.push(block);
|
|
2116
|
+
}
|
|
2117
|
+
return this;
|
|
2118
|
+
},
|
|
2119
|
+
/**
|
|
2120
|
+
* Tear down mounted regions: every root, or only those at or inside `el`.
|
|
2121
|
+
* Effects stop, cleanups run and scopes deregister; the rest of the app
|
|
2122
|
+
* keeps running. Without it, replacing a region's markup leaves its
|
|
2123
|
+
* effects writing to detached nodes.
|
|
2124
|
+
*/
|
|
2125
|
+
unmount(el) {
|
|
2126
|
+
if (el == null) {
|
|
2127
|
+
rootBlocks.forEach((block) => block.teardown());
|
|
2128
|
+
rootBlocks = [];
|
|
2129
|
+
pluginTeardowns.splice(0).forEach((fn) => {
|
|
2130
|
+
try {
|
|
2131
|
+
fn();
|
|
2132
|
+
} catch (e) {
|
|
2133
|
+
handleError(e, {
|
|
2134
|
+
phase: "teardown",
|
|
2135
|
+
source: "plugin"
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
installedPlugins.clear();
|
|
2140
|
+
ownErrorHandlers.splice(0).forEach((off) => off());
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
const target = typeof el === "string" ? document.querySelector(el) : el;
|
|
2144
|
+
if (!target) {
|
|
2145
|
+
console.warn(`unmount: selector ${el} has no matching element.`);
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
const kept = [];
|
|
2149
|
+
for (const block of rootBlocks) {
|
|
2150
|
+
const root = block.template;
|
|
2151
|
+
if (target.contains(root)) block.teardown();
|
|
2152
|
+
else kept.push(block);
|
|
2153
|
+
}
|
|
2154
|
+
if (kept.length === rootBlocks.length) console.warn("unmount: no mounted region found at or inside the given element. Pass the same element that was mounted, or one containing it.");
|
|
2155
|
+
rootBlocks = kept;
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
return app;
|
|
2159
|
+
};
|
|
2160
|
+
//#endregion
|
|
2161
|
+
//#region src/effect.ts
|
|
2162
|
+
/**
|
|
2163
|
+
* Runs `fn` now, then again when the reactive state it read changes. The
|
|
2164
|
+
* JS-side counterpart to `v-effect`, for work not tied to an element.
|
|
2165
|
+
*
|
|
2166
|
+
* Re-runs are scheduled, so a burst of mutations in one tick triggers one run
|
|
2167
|
+
* with the DOM already updated — unlike raw `effect`, which fires
|
|
2168
|
+
* synchronously per mutation.
|
|
2169
|
+
*
|
|
2170
|
+
* Returns a stop function. Nothing stops it automatically.
|
|
2171
|
+
*/
|
|
2172
|
+
var watchEffect = (fn) => {
|
|
2173
|
+
let runner;
|
|
2174
|
+
runner = effect$1(fn, { scheduler: () => queueJob(runner) });
|
|
2175
|
+
return () => stopEffect(runner);
|
|
2176
|
+
};
|
|
2177
|
+
//#endregion
|
|
2178
|
+
//#region src/index.ts
|
|
2179
|
+
var s = document.currentScript;
|
|
2180
|
+
if (s && s.hasAttribute("init")) createApp().mount();
|
|
2181
|
+
//#endregion
|
|
2182
|
+
export { computed, createApp, devtools, disableDevtools, nextTick, reactive, store, watchEffect };
|