hyper-scope-rails 1.0.0.alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +104 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-drive.esm.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-drive.esm.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-drive.iife.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-drive.iife.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-frame.esm.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-frame.esm.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-frame.iife.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/turbo-frame.iife.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/extensions/validate.esm.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/validate.esm.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/extensions/validate.iife.js +4 -0
- data/app/assets/javascripts/hyper-scope/extensions/validate.iife.js.map +1 -0
- data/app/assets/javascripts/hyper-scope/global.esm.js +4 -0
- data/app/assets/javascripts/hyper-scope/global.esm.js.map +1 -0
- data/app/assets/javascripts/hyper-scope.esm.js +7 -0
- data/app/assets/javascripts/hyper-scope.esm.js.map +1 -0
- data/app/assets/javascripts/hyper-scope.iife.js +7 -0
- data/app/assets/javascripts/hyper-scope.iife.js.map +1 -0
- data/config/importmap.rb +16 -0
- data/jsbundle/extensions/turbo-drive.esm.js +25 -0
- data/jsbundle/extensions/turbo-frame.esm.js +43 -0
- data/jsbundle/extensions/validate.esm.js +182 -0
- data/jsbundle/hyper-scope.esm.js +4354 -0
- data/lib/hyper-scope-rails.rb +4 -0
- data/lib/hyper_scope/rails/engine.rb +59 -0
- data/lib/hyper_scope/rails/helper.rb +76 -0
- data/lib/hyper_scope/rails/version.rb +9 -0
- data/lib/hyper_scope/rails.rb +22 -0
- metadata +88 -0
|
@@ -0,0 +1,4354 @@
|
|
|
1
|
+
// src/env.ts
|
|
2
|
+
var DEV = process.env.NODE_ENV !== "production";
|
|
3
|
+
|
|
4
|
+
// node_modules/@vue/shared/dist/shared.esm-bundler.js
|
|
5
|
+
function makeMap(str) {
|
|
6
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
7
|
+
for (const key of str.split(","))
|
|
8
|
+
map[key] = 1;
|
|
9
|
+
return (val) => (val in map);
|
|
10
|
+
}
|
|
11
|
+
var EMPTY_OBJ = process.env.NODE_ENV !== "production" ? Object.freeze({}) : {};
|
|
12
|
+
var EMPTY_ARR = process.env.NODE_ENV !== "production" ? Object.freeze([]) : [];
|
|
13
|
+
var extend = Object.assign;
|
|
14
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
15
|
+
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
16
|
+
var isArray = Array.isArray;
|
|
17
|
+
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
18
|
+
var isSet = (val) => toTypeString(val) === "[object Set]";
|
|
19
|
+
var isDate = (val) => toTypeString(val) === "[object Date]";
|
|
20
|
+
var isFunction = (val) => typeof val === "function";
|
|
21
|
+
var isString = (val) => typeof val === "string";
|
|
22
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
23
|
+
var isObject = (val) => val !== null && typeof val === "object";
|
|
24
|
+
var objectToString = Object.prototype.toString;
|
|
25
|
+
var toTypeString = (value) => objectToString.call(value);
|
|
26
|
+
var toRawType = (value) => {
|
|
27
|
+
return toTypeString(value).slice(8, -1);
|
|
28
|
+
};
|
|
29
|
+
var isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
30
|
+
var cacheStringFunction = (fn) => {
|
|
31
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
32
|
+
return (str) => {
|
|
33
|
+
const hit = cache[str];
|
|
34
|
+
return hit || (cache[str] = fn(str));
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var camelizeRE = /-\w/g;
|
|
38
|
+
var camelize = /* @__PURE__ */ cacheStringFunction((str) => {
|
|
39
|
+
return str.replace(camelizeRE, (c) => c.slice(1).toUpperCase());
|
|
40
|
+
});
|
|
41
|
+
var hyphenateRE = /\B([A-Z])/g;
|
|
42
|
+
var hyphenate = /* @__PURE__ */ cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
43
|
+
var capitalize = /* @__PURE__ */ cacheStringFunction((str) => {
|
|
44
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
45
|
+
});
|
|
46
|
+
var hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
47
|
+
var def = (obj, key, value, writable = false) => {
|
|
48
|
+
Object.defineProperty(obj, key, {
|
|
49
|
+
configurable: true,
|
|
50
|
+
enumerable: false,
|
|
51
|
+
writable,
|
|
52
|
+
value
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var toNumber = (val) => {
|
|
56
|
+
const n = isString(val) ? Number(val) : NaN;
|
|
57
|
+
return isNaN(n) ? val : n;
|
|
58
|
+
};
|
|
59
|
+
function normalizeStyle(value) {
|
|
60
|
+
if (isArray(value)) {
|
|
61
|
+
const res = {};
|
|
62
|
+
for (let i = 0;i < value.length; i++) {
|
|
63
|
+
const item = value[i];
|
|
64
|
+
const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
|
|
65
|
+
if (normalized) {
|
|
66
|
+
for (const key in normalized) {
|
|
67
|
+
res[key] = normalized[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return res;
|
|
72
|
+
} else if (isString(value) || isObject(value)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var listDelimiterRE = /;(?![^(]*\))/g;
|
|
77
|
+
var propertyDelimiterRE = /:([^]+)/;
|
|
78
|
+
var styleCommentRE = /"(?:[^"\\]|\\[^])*"|'(?:[^'\\]|\\[^])*'|\\[^]|\/\*[^]*?\*\//g;
|
|
79
|
+
function parseStringStyle(cssText) {
|
|
80
|
+
const ret = {};
|
|
81
|
+
cssText.replace(styleCommentRE, (match) => match.startsWith("/*") ? "" : match).split(listDelimiterRE).forEach((item) => {
|
|
82
|
+
if (item) {
|
|
83
|
+
const tmp = item.split(propertyDelimiterRE);
|
|
84
|
+
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
89
|
+
function normalizeClass(value) {
|
|
90
|
+
let res = "";
|
|
91
|
+
if (isString(value)) {
|
|
92
|
+
res = value;
|
|
93
|
+
} else if (isArray(value)) {
|
|
94
|
+
for (let i = 0;i < value.length; i++) {
|
|
95
|
+
const normalized = normalizeClass(value[i]);
|
|
96
|
+
if (normalized) {
|
|
97
|
+
res += normalized + " ";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else if (isObject(value)) {
|
|
101
|
+
for (const name in value) {
|
|
102
|
+
if (value[name]) {
|
|
103
|
+
res += name + " ";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return res.trim();
|
|
108
|
+
}
|
|
109
|
+
var specialBooleanAttrs = `itemscope,allowfullscreen,disablepictureinpicture,disableremoteplayback,formnovalidate,ismap,nomodule,novalidate,playsinline,readonly`;
|
|
110
|
+
var isSpecialBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs);
|
|
111
|
+
var isBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
|
|
112
|
+
function includeBooleanAttr(value) {
|
|
113
|
+
return !!value || value === "";
|
|
114
|
+
}
|
|
115
|
+
function looseCompareArrays(a, b, seen) {
|
|
116
|
+
if (a.length !== b.length)
|
|
117
|
+
return false;
|
|
118
|
+
let equal = true;
|
|
119
|
+
for (let i = 0;equal && i < a.length; i++) {
|
|
120
|
+
equal = looseEqual(a[i], b[i], seen);
|
|
121
|
+
}
|
|
122
|
+
return equal;
|
|
123
|
+
}
|
|
124
|
+
function looseCompareCollections(a, b, seen) {
|
|
125
|
+
if (a.size !== b.size)
|
|
126
|
+
return false;
|
|
127
|
+
const candidates = Array.from(b);
|
|
128
|
+
const matched = new Uint8Array(candidates.length);
|
|
129
|
+
for (const item of a) {
|
|
130
|
+
let index = -1;
|
|
131
|
+
for (let i = 0;i < candidates.length; i++) {
|
|
132
|
+
if (!matched[i] && looseEqual(item, candidates[i], seen)) {
|
|
133
|
+
index = i;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (index < 0)
|
|
138
|
+
return false;
|
|
139
|
+
matched[index] = 1;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
function looseCompareObjects(a, b, seen) {
|
|
144
|
+
let aValidType = isMap(a);
|
|
145
|
+
let bValidType = isMap(b);
|
|
146
|
+
if (aValidType || bValidType) {
|
|
147
|
+
return aValidType && bValidType ? looseCompareCollections(a, b, seen) : false;
|
|
148
|
+
}
|
|
149
|
+
aValidType = isSet(a);
|
|
150
|
+
bValidType = isSet(b);
|
|
151
|
+
if (aValidType || bValidType) {
|
|
152
|
+
return aValidType && bValidType ? looseCompareCollections(a, b, seen) : false;
|
|
153
|
+
}
|
|
154
|
+
const aKeysCount = Object.keys(a).length;
|
|
155
|
+
const bKeysCount = Object.keys(b).length;
|
|
156
|
+
if (aKeysCount !== bKeysCount) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
for (const key in a) {
|
|
160
|
+
const aHasKey = a.hasOwnProperty(key);
|
|
161
|
+
const bHasKey = b.hasOwnProperty(key);
|
|
162
|
+
if (aHasKey && !bHasKey || !aHasKey && bHasKey || !looseEqual(a[key], b[key], seen)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return String(a) === String(b);
|
|
167
|
+
}
|
|
168
|
+
function looseCompareNested(a, b, seen, compare) {
|
|
169
|
+
if (!seen) {
|
|
170
|
+
seen = [/* @__PURE__ */ new Map, /* @__PURE__ */ new Map];
|
|
171
|
+
}
|
|
172
|
+
const [seenA, seenB] = seen;
|
|
173
|
+
if (seenA.has(a) || seenB.has(b)) {
|
|
174
|
+
return seenA.get(a) === b && seenB.get(b) === a;
|
|
175
|
+
}
|
|
176
|
+
seenA.set(a, b);
|
|
177
|
+
seenB.set(b, a);
|
|
178
|
+
const equal = compare(a, b, seen);
|
|
179
|
+
seenA.delete(a);
|
|
180
|
+
seenB.delete(b);
|
|
181
|
+
return equal;
|
|
182
|
+
}
|
|
183
|
+
function looseEqual(a, b, seen) {
|
|
184
|
+
if (a === b)
|
|
185
|
+
return true;
|
|
186
|
+
let aValidType = isDate(a);
|
|
187
|
+
let bValidType = isDate(b);
|
|
188
|
+
if (aValidType || bValidType) {
|
|
189
|
+
return aValidType && bValidType ? a.getTime() === b.getTime() : false;
|
|
190
|
+
}
|
|
191
|
+
aValidType = isSymbol(a);
|
|
192
|
+
bValidType = isSymbol(b);
|
|
193
|
+
if (aValidType || bValidType) {
|
|
194
|
+
return a === b;
|
|
195
|
+
}
|
|
196
|
+
aValidType = isArray(a);
|
|
197
|
+
bValidType = isArray(b);
|
|
198
|
+
if (aValidType || bValidType) {
|
|
199
|
+
return aValidType && bValidType ? looseCompareNested(a, b, seen, looseCompareArrays) : false;
|
|
200
|
+
}
|
|
201
|
+
aValidType = isObject(a);
|
|
202
|
+
bValidType = isObject(b);
|
|
203
|
+
if (aValidType || bValidType) {
|
|
204
|
+
if (!aValidType || !bValidType) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return looseCompareNested(a, b, seen, looseCompareObjects);
|
|
208
|
+
}
|
|
209
|
+
return String(a) === String(b);
|
|
210
|
+
}
|
|
211
|
+
function looseIndexOf(arr, val) {
|
|
212
|
+
return arr.findIndex((item) => looseEqual(item, val));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
|
216
|
+
function warn(msg, ...args) {
|
|
217
|
+
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
218
|
+
}
|
|
219
|
+
var activeEffectScope;
|
|
220
|
+
|
|
221
|
+
class EffectScope {
|
|
222
|
+
constructor(detached = false) {
|
|
223
|
+
this.detached = detached;
|
|
224
|
+
this._active = true;
|
|
225
|
+
this._on = 0;
|
|
226
|
+
this.effects = [];
|
|
227
|
+
this.cleanups = [];
|
|
228
|
+
this._isPaused = false;
|
|
229
|
+
this._warnOnRun = true;
|
|
230
|
+
this.__v_skip = true;
|
|
231
|
+
if (!detached && activeEffectScope) {
|
|
232
|
+
if (activeEffectScope.active) {
|
|
233
|
+
this.parent = activeEffectScope;
|
|
234
|
+
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
|
|
235
|
+
} else {
|
|
236
|
+
this._active = false;
|
|
237
|
+
this._warnOnRun = false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
get active() {
|
|
242
|
+
return this._active;
|
|
243
|
+
}
|
|
244
|
+
pause() {
|
|
245
|
+
if (this._active) {
|
|
246
|
+
this._isPaused = true;
|
|
247
|
+
let i, l;
|
|
248
|
+
if (this.scopes) {
|
|
249
|
+
const scopes = this.scopes.slice();
|
|
250
|
+
for (i = 0, l = scopes.length;i < l; i++) {
|
|
251
|
+
scopes[i].pause();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (i = 0, l = this.effects.length;i < l; i++) {
|
|
255
|
+
this.effects[i].pause();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
resume() {
|
|
260
|
+
if (this._active) {
|
|
261
|
+
if (this._isPaused) {
|
|
262
|
+
this._isPaused = false;
|
|
263
|
+
let i, l;
|
|
264
|
+
if (this.scopes) {
|
|
265
|
+
const scopes = this.scopes.slice();
|
|
266
|
+
for (i = 0, l = scopes.length;i < l; i++) {
|
|
267
|
+
scopes[i].resume();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const effects = this.effects.slice();
|
|
271
|
+
for (i = 0, l = effects.length;i < l; i++) {
|
|
272
|
+
effects[i].resume();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
run(fn) {
|
|
278
|
+
if (this._active) {
|
|
279
|
+
const currentEffectScope = activeEffectScope;
|
|
280
|
+
try {
|
|
281
|
+
activeEffectScope = this;
|
|
282
|
+
return fn();
|
|
283
|
+
} finally {
|
|
284
|
+
activeEffectScope = currentEffectScope;
|
|
285
|
+
}
|
|
286
|
+
} else if (!!(process.env.NODE_ENV !== "production") && this._warnOnRun) {
|
|
287
|
+
warn(`cannot run an inactive effect scope.`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
on() {
|
|
291
|
+
if (++this._on === 1) {
|
|
292
|
+
this.prevScope = activeEffectScope;
|
|
293
|
+
activeEffectScope = this;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
off() {
|
|
297
|
+
if (this._on > 0 && --this._on === 0) {
|
|
298
|
+
if (activeEffectScope === this) {
|
|
299
|
+
activeEffectScope = this.prevScope;
|
|
300
|
+
} else {
|
|
301
|
+
let current = activeEffectScope;
|
|
302
|
+
while (current) {
|
|
303
|
+
if (current.prevScope === this) {
|
|
304
|
+
current.prevScope = this.prevScope;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
current = current.prevScope;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
this.prevScope = undefined;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
stop(fromParent) {
|
|
314
|
+
if (this._active) {
|
|
315
|
+
this._active = false;
|
|
316
|
+
let i, l;
|
|
317
|
+
for (i = 0, l = this.effects.length;i < l; i++) {
|
|
318
|
+
this.effects[i].stop();
|
|
319
|
+
}
|
|
320
|
+
this.effects.length = 0;
|
|
321
|
+
for (i = 0, l = this.cleanups.length;i < l; i++) {
|
|
322
|
+
this.cleanups[i]();
|
|
323
|
+
}
|
|
324
|
+
this.cleanups.length = 0;
|
|
325
|
+
if (this.scopes) {
|
|
326
|
+
const scopes = this.scopes.slice();
|
|
327
|
+
for (i = 0, l = scopes.length;i < l; i++) {
|
|
328
|
+
scopes[i].stop(true);
|
|
329
|
+
}
|
|
330
|
+
this.scopes.length = 0;
|
|
331
|
+
}
|
|
332
|
+
if (!this.detached && this.parent && !fromParent) {
|
|
333
|
+
const last = this.parent.scopes.pop();
|
|
334
|
+
if (last && last !== this) {
|
|
335
|
+
this.parent.scopes[this.index] = last;
|
|
336
|
+
last.index = this.index;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this.parent = undefined;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function effectScope(detached) {
|
|
344
|
+
return new EffectScope(detached);
|
|
345
|
+
}
|
|
346
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
347
|
+
if (activeEffectScope) {
|
|
348
|
+
if (activeEffectScope.active) {
|
|
349
|
+
activeEffectScope.cleanups.push(fn);
|
|
350
|
+
} else {
|
|
351
|
+
fn();
|
|
352
|
+
}
|
|
353
|
+
} else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
|
|
354
|
+
warn(`onScopeDispose() is called when there is no active effect scope to be associated with.`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
var activeSub;
|
|
358
|
+
var pausedQueueEffects = /* @__PURE__ */ new WeakSet;
|
|
359
|
+
|
|
360
|
+
class ReactiveEffect {
|
|
361
|
+
constructor(fn) {
|
|
362
|
+
this.fn = fn;
|
|
363
|
+
this.deps = undefined;
|
|
364
|
+
this.depsTail = undefined;
|
|
365
|
+
this.flags = 1 | 4;
|
|
366
|
+
this.next = undefined;
|
|
367
|
+
this.cleanup = undefined;
|
|
368
|
+
this.scheduler = undefined;
|
|
369
|
+
if (activeEffectScope) {
|
|
370
|
+
if (activeEffectScope.active) {
|
|
371
|
+
activeEffectScope.effects.push(this);
|
|
372
|
+
} else {
|
|
373
|
+
this.flags &= -2;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
pause() {
|
|
378
|
+
this.flags |= 64;
|
|
379
|
+
}
|
|
380
|
+
resume() {
|
|
381
|
+
if (this.flags & 64) {
|
|
382
|
+
this.flags &= -65;
|
|
383
|
+
if (pausedQueueEffects.has(this)) {
|
|
384
|
+
pausedQueueEffects.delete(this);
|
|
385
|
+
this.trigger();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
notify() {
|
|
390
|
+
if (this.flags & 2 && !(this.flags & 32)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (!(this.flags & 8)) {
|
|
394
|
+
batch(this);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
run() {
|
|
398
|
+
if (!(this.flags & 1)) {
|
|
399
|
+
return this.fn();
|
|
400
|
+
}
|
|
401
|
+
this.flags |= 2;
|
|
402
|
+
cleanupEffect(this);
|
|
403
|
+
prepareDeps(this);
|
|
404
|
+
const prevEffect = activeSub;
|
|
405
|
+
const prevShouldTrack = shouldTrack;
|
|
406
|
+
activeSub = this;
|
|
407
|
+
shouldTrack = true;
|
|
408
|
+
try {
|
|
409
|
+
return this.fn();
|
|
410
|
+
} finally {
|
|
411
|
+
if (!!(process.env.NODE_ENV !== "production") && activeSub !== this) {
|
|
412
|
+
warn("Active effect was not restored correctly - this is likely a Vue internal bug.");
|
|
413
|
+
}
|
|
414
|
+
cleanupDeps(this);
|
|
415
|
+
activeSub = prevEffect;
|
|
416
|
+
shouldTrack = prevShouldTrack;
|
|
417
|
+
this.flags &= -3;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
stop() {
|
|
421
|
+
if (this.flags & 1) {
|
|
422
|
+
for (let link = this.deps;link; link = link.nextDep) {
|
|
423
|
+
removeSub(link);
|
|
424
|
+
}
|
|
425
|
+
this.deps = this.depsTail = undefined;
|
|
426
|
+
cleanupEffect(this);
|
|
427
|
+
this.onStop && this.onStop();
|
|
428
|
+
this.flags &= -2;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
trigger() {
|
|
432
|
+
if (this.flags & 64) {
|
|
433
|
+
pausedQueueEffects.add(this);
|
|
434
|
+
} else if (this.scheduler) {
|
|
435
|
+
this.scheduler();
|
|
436
|
+
} else {
|
|
437
|
+
this.runIfDirty();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
runIfDirty() {
|
|
441
|
+
if (isDirty(this)) {
|
|
442
|
+
this.run();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
get dirty() {
|
|
446
|
+
return isDirty(this);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
var batchDepth = 0;
|
|
450
|
+
var batchedSub;
|
|
451
|
+
var batchedComputed;
|
|
452
|
+
function batch(sub, isComputed = false) {
|
|
453
|
+
sub.flags |= 8;
|
|
454
|
+
if (isComputed) {
|
|
455
|
+
sub.next = batchedComputed;
|
|
456
|
+
batchedComputed = sub;
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
sub.next = batchedSub;
|
|
460
|
+
batchedSub = sub;
|
|
461
|
+
}
|
|
462
|
+
function startBatch() {
|
|
463
|
+
batchDepth++;
|
|
464
|
+
}
|
|
465
|
+
function endBatch() {
|
|
466
|
+
if (--batchDepth > 0) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (batchedComputed) {
|
|
470
|
+
let e = batchedComputed;
|
|
471
|
+
batchedComputed = undefined;
|
|
472
|
+
while (e) {
|
|
473
|
+
const next = e.next;
|
|
474
|
+
e.next = undefined;
|
|
475
|
+
e.flags &= -9;
|
|
476
|
+
e = next;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
let error;
|
|
480
|
+
while (batchedSub) {
|
|
481
|
+
let e = batchedSub;
|
|
482
|
+
batchedSub = undefined;
|
|
483
|
+
while (e) {
|
|
484
|
+
const next = e.next;
|
|
485
|
+
e.next = undefined;
|
|
486
|
+
e.flags &= -9;
|
|
487
|
+
if (e.flags & 1) {
|
|
488
|
+
try {
|
|
489
|
+
e.trigger();
|
|
490
|
+
} catch (err) {
|
|
491
|
+
if (!error)
|
|
492
|
+
error = err;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
e = next;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (error)
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
function prepareDeps(sub) {
|
|
502
|
+
for (let link = sub.deps;link; link = link.nextDep) {
|
|
503
|
+
link.version = -1;
|
|
504
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
505
|
+
link.dep.activeLink = link;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function cleanupDeps(sub) {
|
|
509
|
+
let head;
|
|
510
|
+
let tail = sub.depsTail;
|
|
511
|
+
let link = tail;
|
|
512
|
+
while (link) {
|
|
513
|
+
const prev = link.prevDep;
|
|
514
|
+
if (link.version === -1) {
|
|
515
|
+
if (link === tail)
|
|
516
|
+
tail = prev;
|
|
517
|
+
removeSub(link);
|
|
518
|
+
removeDep(link);
|
|
519
|
+
} else {
|
|
520
|
+
head = link;
|
|
521
|
+
}
|
|
522
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
523
|
+
link.prevActiveLink = undefined;
|
|
524
|
+
link = prev;
|
|
525
|
+
}
|
|
526
|
+
sub.deps = head;
|
|
527
|
+
sub.depsTail = tail;
|
|
528
|
+
}
|
|
529
|
+
function isDirty(sub) {
|
|
530
|
+
for (let link = sub.deps;link; link = link.nextDep) {
|
|
531
|
+
if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (sub._dirty) {
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
function refreshComputed(computed) {
|
|
541
|
+
if (computed.flags & 4 && !(computed.flags & 16)) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
computed.flags &= -17;
|
|
545
|
+
if (computed.globalVersion === globalVersion) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
computed.globalVersion = globalVersion;
|
|
549
|
+
if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
computed.flags |= 2;
|
|
553
|
+
const dep = computed.dep;
|
|
554
|
+
const prevSub = activeSub;
|
|
555
|
+
const prevShouldTrack = shouldTrack;
|
|
556
|
+
activeSub = computed;
|
|
557
|
+
shouldTrack = true;
|
|
558
|
+
try {
|
|
559
|
+
prepareDeps(computed);
|
|
560
|
+
const value = computed.fn(computed._value);
|
|
561
|
+
if (dep.version === 0 || hasChanged(value, computed._value)) {
|
|
562
|
+
computed.flags |= 128;
|
|
563
|
+
computed._value = value;
|
|
564
|
+
dep.version++;
|
|
565
|
+
}
|
|
566
|
+
} catch (err) {
|
|
567
|
+
dep.version++;
|
|
568
|
+
throw err;
|
|
569
|
+
} finally {
|
|
570
|
+
activeSub = prevSub;
|
|
571
|
+
shouldTrack = prevShouldTrack;
|
|
572
|
+
cleanupDeps(computed);
|
|
573
|
+
computed.flags &= -3;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function removeSub(link, soft = false) {
|
|
577
|
+
const { dep, prevSub, nextSub } = link;
|
|
578
|
+
if (prevSub) {
|
|
579
|
+
prevSub.nextSub = nextSub;
|
|
580
|
+
link.prevSub = undefined;
|
|
581
|
+
}
|
|
582
|
+
if (nextSub) {
|
|
583
|
+
nextSub.prevSub = prevSub;
|
|
584
|
+
link.nextSub = undefined;
|
|
585
|
+
}
|
|
586
|
+
if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) {
|
|
587
|
+
dep.subsHead = nextSub;
|
|
588
|
+
}
|
|
589
|
+
if (dep.subs === link) {
|
|
590
|
+
dep.subs = prevSub;
|
|
591
|
+
if (!prevSub && dep.computed) {
|
|
592
|
+
dep.computed.flags &= -5;
|
|
593
|
+
for (let l = dep.computed.deps;l; l = l.nextDep) {
|
|
594
|
+
removeSub(l, true);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (!soft && !--dep.sc && dep.map) {
|
|
599
|
+
dep.map.delete(dep.key);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function removeDep(link) {
|
|
603
|
+
const { prevDep, nextDep } = link;
|
|
604
|
+
if (prevDep) {
|
|
605
|
+
prevDep.nextDep = nextDep;
|
|
606
|
+
link.prevDep = undefined;
|
|
607
|
+
}
|
|
608
|
+
if (nextDep) {
|
|
609
|
+
nextDep.prevDep = prevDep;
|
|
610
|
+
link.nextDep = undefined;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function effect(fn, options) {
|
|
614
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
615
|
+
fn = fn.effect.fn;
|
|
616
|
+
}
|
|
617
|
+
const e = new ReactiveEffect(fn);
|
|
618
|
+
if (options) {
|
|
619
|
+
extend(e, options);
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
e.run();
|
|
623
|
+
} catch (err) {
|
|
624
|
+
e.stop();
|
|
625
|
+
throw err;
|
|
626
|
+
}
|
|
627
|
+
const runner = e.run.bind(e);
|
|
628
|
+
runner.effect = e;
|
|
629
|
+
return runner;
|
|
630
|
+
}
|
|
631
|
+
function stop(runner) {
|
|
632
|
+
runner.effect.stop();
|
|
633
|
+
}
|
|
634
|
+
var shouldTrack = true;
|
|
635
|
+
var trackStack = [];
|
|
636
|
+
function pauseTracking() {
|
|
637
|
+
trackStack.push(shouldTrack);
|
|
638
|
+
shouldTrack = false;
|
|
639
|
+
}
|
|
640
|
+
function resetTracking() {
|
|
641
|
+
const last = trackStack.pop();
|
|
642
|
+
shouldTrack = last === undefined ? true : last;
|
|
643
|
+
}
|
|
644
|
+
function cleanupEffect(e) {
|
|
645
|
+
const { cleanup } = e;
|
|
646
|
+
e.cleanup = undefined;
|
|
647
|
+
if (cleanup) {
|
|
648
|
+
const prevSub = activeSub;
|
|
649
|
+
activeSub = undefined;
|
|
650
|
+
try {
|
|
651
|
+
cleanup();
|
|
652
|
+
} finally {
|
|
653
|
+
activeSub = prevSub;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
var globalVersion = 0;
|
|
658
|
+
|
|
659
|
+
class Link {
|
|
660
|
+
constructor(sub, dep) {
|
|
661
|
+
this.sub = sub;
|
|
662
|
+
this.dep = dep;
|
|
663
|
+
this.version = dep.version;
|
|
664
|
+
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = undefined;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
class Dep {
|
|
669
|
+
constructor(computed) {
|
|
670
|
+
this.computed = computed;
|
|
671
|
+
this.version = 0;
|
|
672
|
+
this.activeLink = undefined;
|
|
673
|
+
this.subs = undefined;
|
|
674
|
+
this.map = undefined;
|
|
675
|
+
this.key = undefined;
|
|
676
|
+
this.sc = 0;
|
|
677
|
+
this.__v_skip = true;
|
|
678
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
679
|
+
this.subsHead = undefined;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
track(debugInfo) {
|
|
683
|
+
if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
let link = this.activeLink;
|
|
687
|
+
if (link === undefined || link.sub !== activeSub) {
|
|
688
|
+
link = this.activeLink = new Link(activeSub, this);
|
|
689
|
+
if (!activeSub.deps) {
|
|
690
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
691
|
+
} else {
|
|
692
|
+
link.prevDep = activeSub.depsTail;
|
|
693
|
+
activeSub.depsTail.nextDep = link;
|
|
694
|
+
activeSub.depsTail = link;
|
|
695
|
+
}
|
|
696
|
+
addSub(link);
|
|
697
|
+
} else if (link.version === -1) {
|
|
698
|
+
link.version = this.version;
|
|
699
|
+
if (link.nextDep) {
|
|
700
|
+
const next = link.nextDep;
|
|
701
|
+
next.prevDep = link.prevDep;
|
|
702
|
+
if (link.prevDep) {
|
|
703
|
+
link.prevDep.nextDep = next;
|
|
704
|
+
}
|
|
705
|
+
link.prevDep = activeSub.depsTail;
|
|
706
|
+
link.nextDep = undefined;
|
|
707
|
+
activeSub.depsTail.nextDep = link;
|
|
708
|
+
activeSub.depsTail = link;
|
|
709
|
+
if (activeSub.deps === link) {
|
|
710
|
+
activeSub.deps = next;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (!!(process.env.NODE_ENV !== "production") && activeSub.onTrack) {
|
|
715
|
+
activeSub.onTrack(extend({
|
|
716
|
+
effect: activeSub
|
|
717
|
+
}, debugInfo));
|
|
718
|
+
}
|
|
719
|
+
return link;
|
|
720
|
+
}
|
|
721
|
+
trigger(debugInfo) {
|
|
722
|
+
this.version++;
|
|
723
|
+
globalVersion++;
|
|
724
|
+
this.notify(debugInfo);
|
|
725
|
+
}
|
|
726
|
+
notify(debugInfo) {
|
|
727
|
+
startBatch();
|
|
728
|
+
try {
|
|
729
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
730
|
+
for (let head = this.subsHead;head; head = head.nextSub) {
|
|
731
|
+
if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
|
732
|
+
head.sub.onTrigger(extend({
|
|
733
|
+
effect: head.sub
|
|
734
|
+
}, debugInfo));
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
for (let link = this.subs;link; link = link.prevSub) {
|
|
739
|
+
if (link.sub.notify()) {
|
|
740
|
+
link.sub.dep.notify();
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
} finally {
|
|
744
|
+
endBatch();
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function addSub(link) {
|
|
749
|
+
link.dep.sc++;
|
|
750
|
+
if (link.sub.flags & 4) {
|
|
751
|
+
const computed = link.dep.computed;
|
|
752
|
+
if (computed && !link.dep.subs) {
|
|
753
|
+
computed.flags |= 4 | 16;
|
|
754
|
+
for (let l = computed.deps;l; l = l.nextDep) {
|
|
755
|
+
addSub(l);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const currentTail = link.dep.subs;
|
|
759
|
+
if (currentTail !== link) {
|
|
760
|
+
link.prevSub = currentTail;
|
|
761
|
+
if (currentTail)
|
|
762
|
+
currentTail.nextSub = link;
|
|
763
|
+
}
|
|
764
|
+
if (!!(process.env.NODE_ENV !== "production") && link.dep.subsHead === undefined) {
|
|
765
|
+
link.dep.subsHead = link;
|
|
766
|
+
}
|
|
767
|
+
link.dep.subs = link;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
var targetMap = /* @__PURE__ */ new WeakMap;
|
|
771
|
+
var ITERATE_KEY = /* @__PURE__ */ Symbol(process.env.NODE_ENV !== "production" ? "Object iterate" : "");
|
|
772
|
+
var MAP_KEY_ITERATE_KEY = /* @__PURE__ */ Symbol(process.env.NODE_ENV !== "production" ? "Map keys iterate" : "");
|
|
773
|
+
var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol(process.env.NODE_ENV !== "production" ? "Array iterate" : "");
|
|
774
|
+
function track(target, type, key) {
|
|
775
|
+
if (shouldTrack && activeSub) {
|
|
776
|
+
let depsMap = targetMap.get(target);
|
|
777
|
+
if (!depsMap) {
|
|
778
|
+
targetMap.set(target, depsMap = /* @__PURE__ */ new Map);
|
|
779
|
+
}
|
|
780
|
+
let dep = depsMap.get(key);
|
|
781
|
+
if (!dep) {
|
|
782
|
+
depsMap.set(key, dep = new Dep);
|
|
783
|
+
dep.map = depsMap;
|
|
784
|
+
dep.key = key;
|
|
785
|
+
}
|
|
786
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
787
|
+
dep.track({
|
|
788
|
+
target,
|
|
789
|
+
type,
|
|
790
|
+
key
|
|
791
|
+
});
|
|
792
|
+
} else {
|
|
793
|
+
dep.track();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
798
|
+
const depsMap = targetMap.get(target);
|
|
799
|
+
if (!depsMap) {
|
|
800
|
+
globalVersion++;
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const run = (dep) => {
|
|
804
|
+
if (dep) {
|
|
805
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
806
|
+
dep.trigger({
|
|
807
|
+
target,
|
|
808
|
+
type,
|
|
809
|
+
key,
|
|
810
|
+
newValue,
|
|
811
|
+
oldValue,
|
|
812
|
+
oldTarget
|
|
813
|
+
});
|
|
814
|
+
} else {
|
|
815
|
+
dep.trigger();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
startBatch();
|
|
820
|
+
if (type === "clear") {
|
|
821
|
+
depsMap.forEach(run);
|
|
822
|
+
} else {
|
|
823
|
+
const targetIsArray = isArray(target);
|
|
824
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
825
|
+
if (targetIsArray && key === "length") {
|
|
826
|
+
const newLength = Number(newValue);
|
|
827
|
+
depsMap.forEach((dep, key2) => {
|
|
828
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
|
|
829
|
+
run(dep);
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
} else {
|
|
833
|
+
if (key !== undefined || depsMap.has(undefined)) {
|
|
834
|
+
run(depsMap.get(key));
|
|
835
|
+
}
|
|
836
|
+
if (isArrayIndex) {
|
|
837
|
+
run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
838
|
+
}
|
|
839
|
+
switch (type) {
|
|
840
|
+
case "add":
|
|
841
|
+
if (!targetIsArray) {
|
|
842
|
+
run(depsMap.get(ITERATE_KEY));
|
|
843
|
+
if (isMap(target)) {
|
|
844
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
845
|
+
}
|
|
846
|
+
} else if (isArrayIndex) {
|
|
847
|
+
run(depsMap.get("length"));
|
|
848
|
+
}
|
|
849
|
+
break;
|
|
850
|
+
case "delete":
|
|
851
|
+
if (!targetIsArray) {
|
|
852
|
+
run(depsMap.get(ITERATE_KEY));
|
|
853
|
+
if (isMap(target)) {
|
|
854
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
break;
|
|
858
|
+
case "set":
|
|
859
|
+
if (isMap(target)) {
|
|
860
|
+
run(depsMap.get(ITERATE_KEY));
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
endBatch();
|
|
867
|
+
}
|
|
868
|
+
function reactiveReadArray(array) {
|
|
869
|
+
const raw = toRaw(array);
|
|
870
|
+
if (raw === array)
|
|
871
|
+
return raw;
|
|
872
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
873
|
+
if (isShallow(array))
|
|
874
|
+
return raw;
|
|
875
|
+
if (!isReadonly(array))
|
|
876
|
+
return raw.map(toReactive);
|
|
877
|
+
return isReactive(array) ? raw.map((item) => toReadonly(toReactive(item))) : raw.map(toReadonly);
|
|
878
|
+
}
|
|
879
|
+
function shallowReadArray(arr) {
|
|
880
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
881
|
+
return arr;
|
|
882
|
+
}
|
|
883
|
+
function toWrapped(target, item) {
|
|
884
|
+
if (isReadonly(target)) {
|
|
885
|
+
return isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
|
|
886
|
+
}
|
|
887
|
+
return toReactive(item);
|
|
888
|
+
}
|
|
889
|
+
var arrayInstrumentations = {
|
|
890
|
+
__proto__: null,
|
|
891
|
+
[Symbol.iterator]() {
|
|
892
|
+
return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
|
|
893
|
+
},
|
|
894
|
+
concat(...args) {
|
|
895
|
+
return reactiveReadArray(this).concat(...args.map((x) => isArray(x) ? reactiveReadArray(x) : x));
|
|
896
|
+
},
|
|
897
|
+
entries() {
|
|
898
|
+
return iterator(this, "entries", (value) => {
|
|
899
|
+
value[1] = toWrapped(this, value[1]);
|
|
900
|
+
return value;
|
|
901
|
+
});
|
|
902
|
+
},
|
|
903
|
+
every(fn, thisArg) {
|
|
904
|
+
return apply(this, "every", fn, thisArg, undefined, arguments);
|
|
905
|
+
},
|
|
906
|
+
filter(fn, thisArg) {
|
|
907
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
|
|
908
|
+
},
|
|
909
|
+
find(fn, thisArg) {
|
|
910
|
+
return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
911
|
+
},
|
|
912
|
+
findIndex(fn, thisArg) {
|
|
913
|
+
return apply(this, "findIndex", fn, thisArg, undefined, arguments);
|
|
914
|
+
},
|
|
915
|
+
findLast(fn, thisArg) {
|
|
916
|
+
return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
917
|
+
},
|
|
918
|
+
findLastIndex(fn, thisArg) {
|
|
919
|
+
return apply(this, "findLastIndex", fn, thisArg, undefined, arguments);
|
|
920
|
+
},
|
|
921
|
+
forEach(fn, thisArg) {
|
|
922
|
+
return apply(this, "forEach", fn, thisArg, undefined, arguments);
|
|
923
|
+
},
|
|
924
|
+
includes(...args) {
|
|
925
|
+
return searchProxy(this, "includes", args);
|
|
926
|
+
},
|
|
927
|
+
indexOf(...args) {
|
|
928
|
+
return searchProxy(this, "indexOf", args);
|
|
929
|
+
},
|
|
930
|
+
join(separator) {
|
|
931
|
+
return reactiveReadArray(this).join(separator);
|
|
932
|
+
},
|
|
933
|
+
lastIndexOf(...args) {
|
|
934
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
935
|
+
},
|
|
936
|
+
map(fn, thisArg) {
|
|
937
|
+
return apply(this, "map", fn, thisArg, undefined, arguments);
|
|
938
|
+
},
|
|
939
|
+
pop() {
|
|
940
|
+
return noTracking(this, "pop");
|
|
941
|
+
},
|
|
942
|
+
push(...args) {
|
|
943
|
+
return noTracking(this, "push", args);
|
|
944
|
+
},
|
|
945
|
+
reduce(fn, ...args) {
|
|
946
|
+
return reduce(this, "reduce", fn, args);
|
|
947
|
+
},
|
|
948
|
+
reduceRight(fn, ...args) {
|
|
949
|
+
return reduce(this, "reduceRight", fn, args);
|
|
950
|
+
},
|
|
951
|
+
shift() {
|
|
952
|
+
return noTracking(this, "shift");
|
|
953
|
+
},
|
|
954
|
+
some(fn, thisArg) {
|
|
955
|
+
return apply(this, "some", fn, thisArg, undefined, arguments);
|
|
956
|
+
},
|
|
957
|
+
splice(...args) {
|
|
958
|
+
return noTracking(this, "splice", args);
|
|
959
|
+
},
|
|
960
|
+
toReversed() {
|
|
961
|
+
return reactiveReadArray(this).toReversed();
|
|
962
|
+
},
|
|
963
|
+
toSorted(comparer) {
|
|
964
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
965
|
+
},
|
|
966
|
+
toSpliced(...args) {
|
|
967
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
968
|
+
},
|
|
969
|
+
unshift(...args) {
|
|
970
|
+
return noTracking(this, "unshift", args);
|
|
971
|
+
},
|
|
972
|
+
values() {
|
|
973
|
+
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
function iterator(self2, method, wrapValue) {
|
|
977
|
+
const arr = shallowReadArray(self2);
|
|
978
|
+
const methodFn = arr[method];
|
|
979
|
+
const iter = methodFn.call(arr);
|
|
980
|
+
if (arr !== self2 && !isShallow(self2)) {
|
|
981
|
+
if (iter[Symbol.toStringTag] === "Array Iterator") {
|
|
982
|
+
const wrapped = Object.create(Object.getPrototypeOf(iter));
|
|
983
|
+
wrapped.next = () => wrapResult(iter.next(), wrapValue);
|
|
984
|
+
if (methodFn !== arrayProto[method]) {
|
|
985
|
+
Object.defineProperties(wrapped, {
|
|
986
|
+
return: {
|
|
987
|
+
get() {
|
|
988
|
+
const fn = iter.return;
|
|
989
|
+
return typeof fn === "function" ? fn.bind(iter) : fn;
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
throw: {
|
|
993
|
+
get() {
|
|
994
|
+
const fn = iter.throw;
|
|
995
|
+
return typeof fn === "function" ? fn.bind(iter) : fn;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
return wrapped;
|
|
1001
|
+
}
|
|
1002
|
+
iter._next = iter.next;
|
|
1003
|
+
iter.next = () => wrapResult(iter._next(), wrapValue);
|
|
1004
|
+
}
|
|
1005
|
+
return iter;
|
|
1006
|
+
}
|
|
1007
|
+
function wrapResult(result, wrapValue) {
|
|
1008
|
+
if (!result.done) {
|
|
1009
|
+
result.value = wrapValue(result.value);
|
|
1010
|
+
}
|
|
1011
|
+
return result;
|
|
1012
|
+
}
|
|
1013
|
+
var arrayProto = Array.prototype;
|
|
1014
|
+
function apply(self2, method, fn, thisArg, wrappedRetFn, args) {
|
|
1015
|
+
const arr = shallowReadArray(self2);
|
|
1016
|
+
const needsWrap = arr !== self2 && !isShallow(self2);
|
|
1017
|
+
const methodFn = arr[method];
|
|
1018
|
+
if (methodFn !== arrayProto[method]) {
|
|
1019
|
+
const result2 = methodFn.apply(self2, args);
|
|
1020
|
+
return needsWrap ? toReactive(result2) : result2;
|
|
1021
|
+
}
|
|
1022
|
+
let wrappedFn = fn;
|
|
1023
|
+
if (arr !== self2) {
|
|
1024
|
+
if (needsWrap) {
|
|
1025
|
+
wrappedFn = function(item, index) {
|
|
1026
|
+
return fn.call(this, toWrapped(self2, item), index, self2);
|
|
1027
|
+
};
|
|
1028
|
+
} else if (fn.length > 2) {
|
|
1029
|
+
wrappedFn = function(item, index) {
|
|
1030
|
+
return fn.call(this, item, index, self2);
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
1035
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
1036
|
+
}
|
|
1037
|
+
function reduce(self2, method, fn, args) {
|
|
1038
|
+
const arr = shallowReadArray(self2);
|
|
1039
|
+
const needsWrap = arr !== self2 && !isShallow(self2);
|
|
1040
|
+
let wrappedFn = fn;
|
|
1041
|
+
let wrapInitialAccumulator = false;
|
|
1042
|
+
if (arr !== self2) {
|
|
1043
|
+
if (needsWrap) {
|
|
1044
|
+
wrapInitialAccumulator = args.length === 0;
|
|
1045
|
+
wrappedFn = function(acc, item, index) {
|
|
1046
|
+
if (wrapInitialAccumulator) {
|
|
1047
|
+
wrapInitialAccumulator = false;
|
|
1048
|
+
acc = toWrapped(self2, acc);
|
|
1049
|
+
}
|
|
1050
|
+
return fn.call(this, acc, toWrapped(self2, item), index, self2);
|
|
1051
|
+
};
|
|
1052
|
+
} else if (fn.length > 3) {
|
|
1053
|
+
wrappedFn = function(acc, item, index) {
|
|
1054
|
+
return fn.call(this, acc, item, index, self2);
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const result = arr[method](wrappedFn, ...args);
|
|
1059
|
+
return wrapInitialAccumulator ? toWrapped(self2, result) : result;
|
|
1060
|
+
}
|
|
1061
|
+
function searchProxy(self2, method, args) {
|
|
1062
|
+
const arr = toRaw(self2);
|
|
1063
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
1064
|
+
const res = arr[method](...args);
|
|
1065
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
1066
|
+
args[0] = toRaw(args[0]);
|
|
1067
|
+
return arr[method](...args);
|
|
1068
|
+
}
|
|
1069
|
+
return res;
|
|
1070
|
+
}
|
|
1071
|
+
function noTracking(self2, method, args = []) {
|
|
1072
|
+
pauseTracking();
|
|
1073
|
+
startBatch();
|
|
1074
|
+
const res = toRaw(self2)[method].apply(self2, args);
|
|
1075
|
+
endBatch();
|
|
1076
|
+
resetTracking();
|
|
1077
|
+
return res;
|
|
1078
|
+
}
|
|
1079
|
+
var isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
1080
|
+
var builtInSymbols = /* @__PURE__ */ new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
|
|
1081
|
+
function hasOwnProperty2(key) {
|
|
1082
|
+
if (!isSymbol(key))
|
|
1083
|
+
key = String(key);
|
|
1084
|
+
const obj = toRaw(this);
|
|
1085
|
+
track(obj, "has", key);
|
|
1086
|
+
return obj.hasOwnProperty(key);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
class BaseReactiveHandler {
|
|
1090
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
1091
|
+
this._isReadonly = _isReadonly;
|
|
1092
|
+
this._isShallow = _isShallow;
|
|
1093
|
+
}
|
|
1094
|
+
get(target, key, receiver) {
|
|
1095
|
+
if (key === "__v_skip")
|
|
1096
|
+
return target["__v_skip"];
|
|
1097
|
+
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
|
1098
|
+
if (key === "__v_isReactive") {
|
|
1099
|
+
return !isReadonly2;
|
|
1100
|
+
} else if (key === "__v_isReadonly") {
|
|
1101
|
+
return isReadonly2;
|
|
1102
|
+
} else if (key === "__v_isShallow") {
|
|
1103
|
+
return isShallow2;
|
|
1104
|
+
} else if (key === "__v_raw") {
|
|
1105
|
+
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
|
1106
|
+
return target;
|
|
1107
|
+
}
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
const targetIsArray = isArray(target);
|
|
1111
|
+
if (!isReadonly2) {
|
|
1112
|
+
let fn;
|
|
1113
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
1114
|
+
return fn;
|
|
1115
|
+
}
|
|
1116
|
+
if (key === "hasOwnProperty") {
|
|
1117
|
+
return hasOwnProperty2;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
const res = Reflect.get(target, key, isRef(target) ? target : receiver);
|
|
1121
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
1122
|
+
return res;
|
|
1123
|
+
}
|
|
1124
|
+
if (!isReadonly2) {
|
|
1125
|
+
track(target, "get", key);
|
|
1126
|
+
}
|
|
1127
|
+
if (isShallow2) {
|
|
1128
|
+
return res;
|
|
1129
|
+
}
|
|
1130
|
+
if (isRef(res)) {
|
|
1131
|
+
const value = targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
1132
|
+
return isReadonly2 && isObject(value) ? readonly(value) : value;
|
|
1133
|
+
}
|
|
1134
|
+
if (isObject(res)) {
|
|
1135
|
+
return isReadonly2 ? readonly(res) : reactive(res);
|
|
1136
|
+
}
|
|
1137
|
+
return res;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
class MutableReactiveHandler extends BaseReactiveHandler {
|
|
1142
|
+
constructor(isShallow2 = false) {
|
|
1143
|
+
super(false, isShallow2);
|
|
1144
|
+
}
|
|
1145
|
+
set(target, key, value, receiver) {
|
|
1146
|
+
let oldValue = target[key];
|
|
1147
|
+
const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key);
|
|
1148
|
+
if (!this._isShallow) {
|
|
1149
|
+
const isOldValueReadonly = isReadonly(oldValue);
|
|
1150
|
+
if (!isShallow(value) && !isReadonly(value)) {
|
|
1151
|
+
oldValue = toRaw(oldValue);
|
|
1152
|
+
value = toRaw(value);
|
|
1153
|
+
}
|
|
1154
|
+
if (!isArrayWithIntegerKey && isRef(oldValue) && !isRef(value)) {
|
|
1155
|
+
if (isOldValueReadonly) {
|
|
1156
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1157
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target[key]);
|
|
1158
|
+
}
|
|
1159
|
+
return true;
|
|
1160
|
+
} else {
|
|
1161
|
+
oldValue.value = value;
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
|
|
1167
|
+
const result = Reflect.set(target, key, value, isRef(target) ? target : receiver);
|
|
1168
|
+
if (target === toRaw(receiver) && result) {
|
|
1169
|
+
if (!hadKey) {
|
|
1170
|
+
trigger(target, "add", key, value);
|
|
1171
|
+
} else if (hasChanged(value, oldValue)) {
|
|
1172
|
+
trigger(target, "set", key, value, oldValue);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return result;
|
|
1176
|
+
}
|
|
1177
|
+
deleteProperty(target, key) {
|
|
1178
|
+
const hadKey = hasOwn(target, key);
|
|
1179
|
+
const oldValue = target[key];
|
|
1180
|
+
const result = Reflect.deleteProperty(target, key);
|
|
1181
|
+
if (result && hadKey) {
|
|
1182
|
+
trigger(target, "delete", key, undefined, oldValue);
|
|
1183
|
+
}
|
|
1184
|
+
return result;
|
|
1185
|
+
}
|
|
1186
|
+
has(target, key) {
|
|
1187
|
+
const result = Reflect.has(target, key);
|
|
1188
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
|
1189
|
+
track(target, "has", key);
|
|
1190
|
+
}
|
|
1191
|
+
return result;
|
|
1192
|
+
}
|
|
1193
|
+
ownKeys(target) {
|
|
1194
|
+
track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
|
|
1195
|
+
return Reflect.ownKeys(target);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
1200
|
+
constructor(isShallow2 = false) {
|
|
1201
|
+
super(true, isShallow2);
|
|
1202
|
+
}
|
|
1203
|
+
set(target, key) {
|
|
1204
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1205
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
1206
|
+
}
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
deleteProperty(target, key) {
|
|
1210
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1211
|
+
warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
1212
|
+
}
|
|
1213
|
+
return true;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
var mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler;
|
|
1217
|
+
var readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler;
|
|
1218
|
+
var toShallow = (value) => value;
|
|
1219
|
+
var getProto = (v) => Reflect.getPrototypeOf(v);
|
|
1220
|
+
function createIterableMethod(method, isReadonly2, isShallow2) {
|
|
1221
|
+
return function(...args) {
|
|
1222
|
+
const target = this["__v_raw"];
|
|
1223
|
+
const rawTarget = toRaw(target);
|
|
1224
|
+
const targetIsMap = isMap(rawTarget);
|
|
1225
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
1226
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
1227
|
+
const innerIterator = target[method](...args);
|
|
1228
|
+
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
|
1229
|
+
!isReadonly2 && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
|
|
1230
|
+
return extend(Object.create(innerIterator), {
|
|
1231
|
+
next() {
|
|
1232
|
+
const { value, done } = innerIterator.next();
|
|
1233
|
+
return done ? { value, done } : {
|
|
1234
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
1235
|
+
done
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
function createReadonlyMethod(type) {
|
|
1242
|
+
return function(...args) {
|
|
1243
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1244
|
+
const key = args[0] ? `on key "${args[0]}" ` : ``;
|
|
1245
|
+
warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
|
|
1246
|
+
}
|
|
1247
|
+
return type === "delete" ? false : type === "clear" ? undefined : this;
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
function createInstrumentations(readonly, shallow) {
|
|
1251
|
+
const instrumentations = {
|
|
1252
|
+
get(key) {
|
|
1253
|
+
const target = this["__v_raw"];
|
|
1254
|
+
const rawTarget = toRaw(target);
|
|
1255
|
+
const rawKey = toRaw(key);
|
|
1256
|
+
if (!readonly) {
|
|
1257
|
+
if (hasChanged(key, rawKey)) {
|
|
1258
|
+
track(rawTarget, "get", key);
|
|
1259
|
+
}
|
|
1260
|
+
track(rawTarget, "get", rawKey);
|
|
1261
|
+
}
|
|
1262
|
+
const { has } = getProto(rawTarget);
|
|
1263
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
1264
|
+
if (has.call(rawTarget, key)) {
|
|
1265
|
+
return wrap(target.get(key));
|
|
1266
|
+
} else if (has.call(rawTarget, rawKey)) {
|
|
1267
|
+
return wrap(target.get(rawKey));
|
|
1268
|
+
} else if (target !== rawTarget) {
|
|
1269
|
+
target.get(key);
|
|
1270
|
+
}
|
|
1271
|
+
},
|
|
1272
|
+
get size() {
|
|
1273
|
+
const target = this["__v_raw"];
|
|
1274
|
+
!readonly && track(toRaw(target), "iterate", ITERATE_KEY);
|
|
1275
|
+
return target.size;
|
|
1276
|
+
},
|
|
1277
|
+
has(key) {
|
|
1278
|
+
const target = this["__v_raw"];
|
|
1279
|
+
const rawTarget = toRaw(target);
|
|
1280
|
+
const rawKey = toRaw(key);
|
|
1281
|
+
if (!readonly) {
|
|
1282
|
+
if (hasChanged(key, rawKey)) {
|
|
1283
|
+
track(rawTarget, "has", key);
|
|
1284
|
+
}
|
|
1285
|
+
track(rawTarget, "has", rawKey);
|
|
1286
|
+
}
|
|
1287
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
1288
|
+
},
|
|
1289
|
+
forEach(callback, thisArg) {
|
|
1290
|
+
const observed = this;
|
|
1291
|
+
const target = observed["__v_raw"];
|
|
1292
|
+
const rawTarget = toRaw(target);
|
|
1293
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
1294
|
+
!readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
1295
|
+
return target.forEach((value, key) => {
|
|
1296
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
extend(instrumentations, readonly ? {
|
|
1301
|
+
add: createReadonlyMethod("add"),
|
|
1302
|
+
set: createReadonlyMethod("set"),
|
|
1303
|
+
delete: createReadonlyMethod("delete"),
|
|
1304
|
+
clear: createReadonlyMethod("clear")
|
|
1305
|
+
} : {
|
|
1306
|
+
add(value) {
|
|
1307
|
+
const target = toRaw(this);
|
|
1308
|
+
const proto = getProto(target);
|
|
1309
|
+
const rawValue = toRaw(value);
|
|
1310
|
+
const valueToAdd = !shallow && !isShallow(value) && !isReadonly(value) ? rawValue : value;
|
|
1311
|
+
const hadKey = proto.has.call(target, valueToAdd) || hasChanged(value, valueToAdd) && proto.has.call(target, value) || hasChanged(rawValue, valueToAdd) && proto.has.call(target, rawValue);
|
|
1312
|
+
if (!hadKey) {
|
|
1313
|
+
target.add(valueToAdd);
|
|
1314
|
+
trigger(target, "add", valueToAdd, valueToAdd);
|
|
1315
|
+
}
|
|
1316
|
+
return this;
|
|
1317
|
+
},
|
|
1318
|
+
set(key, value) {
|
|
1319
|
+
if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
|
1320
|
+
value = toRaw(value);
|
|
1321
|
+
}
|
|
1322
|
+
const target = toRaw(this);
|
|
1323
|
+
const { has, get } = getProto(target);
|
|
1324
|
+
let hadKey = has.call(target, key);
|
|
1325
|
+
if (!hadKey) {
|
|
1326
|
+
key = toRaw(key);
|
|
1327
|
+
hadKey = has.call(target, key);
|
|
1328
|
+
} else if (!!(process.env.NODE_ENV !== "production")) {
|
|
1329
|
+
checkIdentityKeys(target, has, key);
|
|
1330
|
+
}
|
|
1331
|
+
const oldValue = get.call(target, key);
|
|
1332
|
+
target.set(key, value);
|
|
1333
|
+
if (!hadKey) {
|
|
1334
|
+
trigger(target, "add", key, value);
|
|
1335
|
+
} else if (hasChanged(value, oldValue)) {
|
|
1336
|
+
trigger(target, "set", key, value, oldValue);
|
|
1337
|
+
}
|
|
1338
|
+
return this;
|
|
1339
|
+
},
|
|
1340
|
+
delete(key) {
|
|
1341
|
+
const target = toRaw(this);
|
|
1342
|
+
const { has, get } = getProto(target);
|
|
1343
|
+
let hadKey = has.call(target, key);
|
|
1344
|
+
if (!hadKey) {
|
|
1345
|
+
key = toRaw(key);
|
|
1346
|
+
hadKey = has.call(target, key);
|
|
1347
|
+
} else if (!!(process.env.NODE_ENV !== "production")) {
|
|
1348
|
+
checkIdentityKeys(target, has, key);
|
|
1349
|
+
}
|
|
1350
|
+
const oldValue = get ? get.call(target, key) : undefined;
|
|
1351
|
+
const result = target.delete(key);
|
|
1352
|
+
if (hadKey) {
|
|
1353
|
+
trigger(target, "delete", key, undefined, oldValue);
|
|
1354
|
+
}
|
|
1355
|
+
return result;
|
|
1356
|
+
},
|
|
1357
|
+
clear() {
|
|
1358
|
+
const target = toRaw(this);
|
|
1359
|
+
const hadItems = target.size !== 0;
|
|
1360
|
+
const oldTarget = process.env.NODE_ENV !== "production" ? isMap(target) ? new Map(target) : new Set(target) : undefined;
|
|
1361
|
+
const result = target.clear();
|
|
1362
|
+
if (hadItems) {
|
|
1363
|
+
trigger(target, "clear", undefined, undefined, oldTarget);
|
|
1364
|
+
}
|
|
1365
|
+
return result;
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
const iteratorMethods = [
|
|
1369
|
+
"keys",
|
|
1370
|
+
"values",
|
|
1371
|
+
"entries",
|
|
1372
|
+
Symbol.iterator
|
|
1373
|
+
];
|
|
1374
|
+
iteratorMethods.forEach((method) => {
|
|
1375
|
+
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
1376
|
+
});
|
|
1377
|
+
return instrumentations;
|
|
1378
|
+
}
|
|
1379
|
+
function createInstrumentationGetter(isReadonly2, shallow) {
|
|
1380
|
+
const instrumentations = createInstrumentations(isReadonly2, shallow);
|
|
1381
|
+
return (target, key, receiver) => {
|
|
1382
|
+
if (key === "__v_isReactive") {
|
|
1383
|
+
return !isReadonly2;
|
|
1384
|
+
} else if (key === "__v_isReadonly") {
|
|
1385
|
+
return isReadonly2;
|
|
1386
|
+
} else if (key === "__v_isShallow") {
|
|
1387
|
+
return shallow;
|
|
1388
|
+
} else if (key === "__v_raw") {
|
|
1389
|
+
return target;
|
|
1390
|
+
}
|
|
1391
|
+
return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
var mutableCollectionHandlers = {
|
|
1395
|
+
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
1396
|
+
};
|
|
1397
|
+
var readonlyCollectionHandlers = {
|
|
1398
|
+
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
1399
|
+
};
|
|
1400
|
+
function checkIdentityKeys(target, has, key) {
|
|
1401
|
+
const rawKey = toRaw(key);
|
|
1402
|
+
if (rawKey !== key && has.call(target, rawKey)) {
|
|
1403
|
+
const type = toRawType(target);
|
|
1404
|
+
warn(`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap;
|
|
1408
|
+
var shallowReactiveMap = /* @__PURE__ */ new WeakMap;
|
|
1409
|
+
var readonlyMap = /* @__PURE__ */ new WeakMap;
|
|
1410
|
+
var shallowReadonlyMap = /* @__PURE__ */ new WeakMap;
|
|
1411
|
+
function targetTypeMap(rawType) {
|
|
1412
|
+
switch (rawType) {
|
|
1413
|
+
case "Object":
|
|
1414
|
+
case "Array":
|
|
1415
|
+
return 1;
|
|
1416
|
+
case "Map":
|
|
1417
|
+
case "Set":
|
|
1418
|
+
case "WeakMap":
|
|
1419
|
+
case "WeakSet":
|
|
1420
|
+
return 2;
|
|
1421
|
+
default:
|
|
1422
|
+
return 0;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
function reactive(target) {
|
|
1426
|
+
if (/* @__PURE__ */ isReadonly(target)) {
|
|
1427
|
+
return target;
|
|
1428
|
+
}
|
|
1429
|
+
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
|
|
1430
|
+
}
|
|
1431
|
+
function readonly(target) {
|
|
1432
|
+
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
|
|
1433
|
+
}
|
|
1434
|
+
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
|
1435
|
+
if (!isObject(target)) {
|
|
1436
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1437
|
+
warn(`value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(target)}`);
|
|
1438
|
+
}
|
|
1439
|
+
return target;
|
|
1440
|
+
}
|
|
1441
|
+
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
|
1442
|
+
return target;
|
|
1443
|
+
}
|
|
1444
|
+
if (target["__v_skip"] || !Object.isExtensible(target)) {
|
|
1445
|
+
return target;
|
|
1446
|
+
}
|
|
1447
|
+
const existingProxy = proxyMap.get(target);
|
|
1448
|
+
if (existingProxy) {
|
|
1449
|
+
return existingProxy;
|
|
1450
|
+
}
|
|
1451
|
+
const targetType = targetTypeMap(toRawType(target));
|
|
1452
|
+
if (targetType === 0) {
|
|
1453
|
+
return target;
|
|
1454
|
+
}
|
|
1455
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
1456
|
+
proxyMap.set(target, proxy);
|
|
1457
|
+
return proxy;
|
|
1458
|
+
}
|
|
1459
|
+
function isReactive(value) {
|
|
1460
|
+
if (/* @__PURE__ */ isReadonly(value)) {
|
|
1461
|
+
return /* @__PURE__ */ isReactive(value["__v_raw"]);
|
|
1462
|
+
}
|
|
1463
|
+
return !!(value && value["__v_isReactive"]);
|
|
1464
|
+
}
|
|
1465
|
+
function isReadonly(value) {
|
|
1466
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1467
|
+
}
|
|
1468
|
+
function isShallow(value) {
|
|
1469
|
+
return !!(value && value["__v_isShallow"]);
|
|
1470
|
+
}
|
|
1471
|
+
function isProxy(value) {
|
|
1472
|
+
return value ? !!value["__v_raw"] : false;
|
|
1473
|
+
}
|
|
1474
|
+
function toRaw(observed) {
|
|
1475
|
+
const raw = observed && observed["__v_raw"];
|
|
1476
|
+
return raw ? /* @__PURE__ */ toRaw(raw) : observed;
|
|
1477
|
+
}
|
|
1478
|
+
function markRaw(value) {
|
|
1479
|
+
if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
|
|
1480
|
+
def(value, "__v_skip", true);
|
|
1481
|
+
}
|
|
1482
|
+
return value;
|
|
1483
|
+
}
|
|
1484
|
+
var toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value) : value;
|
|
1485
|
+
var toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
1486
|
+
function isRef(r) {
|
|
1487
|
+
return r ? r["__v_isRef"] === true : false;
|
|
1488
|
+
}
|
|
1489
|
+
function ref(value) {
|
|
1490
|
+
return createRef(value, false);
|
|
1491
|
+
}
|
|
1492
|
+
function createRef(rawValue, shallow) {
|
|
1493
|
+
if (/* @__PURE__ */ isRef(rawValue)) {
|
|
1494
|
+
return rawValue;
|
|
1495
|
+
}
|
|
1496
|
+
return new RefImpl(rawValue, shallow);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
class RefImpl {
|
|
1500
|
+
constructor(value, isShallow2) {
|
|
1501
|
+
this.dep = new Dep;
|
|
1502
|
+
this["__v_isRef"] = true;
|
|
1503
|
+
this["__v_isShallow"] = false;
|
|
1504
|
+
this._rawValue = isShallow2 ? value : toRaw(value);
|
|
1505
|
+
this._value = isShallow2 ? value : toReactive(value);
|
|
1506
|
+
this["__v_isShallow"] = isShallow2;
|
|
1507
|
+
}
|
|
1508
|
+
get value() {
|
|
1509
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1510
|
+
this.dep.track({
|
|
1511
|
+
target: this,
|
|
1512
|
+
type: "get",
|
|
1513
|
+
key: "value"
|
|
1514
|
+
});
|
|
1515
|
+
} else {
|
|
1516
|
+
this.dep.track();
|
|
1517
|
+
}
|
|
1518
|
+
return this._value;
|
|
1519
|
+
}
|
|
1520
|
+
set value(newValue) {
|
|
1521
|
+
const oldValue = this._rawValue;
|
|
1522
|
+
const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
|
1523
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1524
|
+
if (hasChanged(newValue, oldValue)) {
|
|
1525
|
+
this._rawValue = newValue;
|
|
1526
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
1527
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
1528
|
+
this.dep.trigger({
|
|
1529
|
+
target: this,
|
|
1530
|
+
type: "set",
|
|
1531
|
+
key: "value",
|
|
1532
|
+
newValue,
|
|
1533
|
+
oldValue
|
|
1534
|
+
});
|
|
1535
|
+
} else {
|
|
1536
|
+
this.dep.trigger();
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
class ComputedRefImpl {
|
|
1542
|
+
constructor(fn, setter, isSSR) {
|
|
1543
|
+
this.fn = fn;
|
|
1544
|
+
this.setter = setter;
|
|
1545
|
+
this._value = undefined;
|
|
1546
|
+
this.dep = new Dep(this);
|
|
1547
|
+
this.__v_isRef = true;
|
|
1548
|
+
this.deps = undefined;
|
|
1549
|
+
this.depsTail = undefined;
|
|
1550
|
+
this.flags = 16;
|
|
1551
|
+
this.globalVersion = globalVersion - 1;
|
|
1552
|
+
this.next = undefined;
|
|
1553
|
+
this.effect = this;
|
|
1554
|
+
this["__v_isReadonly"] = !setter;
|
|
1555
|
+
this.isSSR = isSSR;
|
|
1556
|
+
}
|
|
1557
|
+
notify() {
|
|
1558
|
+
this.flags |= 16;
|
|
1559
|
+
if (!(this.flags & 8) && activeSub !== this) {
|
|
1560
|
+
batch(this, true);
|
|
1561
|
+
return true;
|
|
1562
|
+
} else if (!!(process.env.NODE_ENV !== "production"))
|
|
1563
|
+
;
|
|
1564
|
+
}
|
|
1565
|
+
get value() {
|
|
1566
|
+
const link = process.env.NODE_ENV !== "production" ? this.dep.track({
|
|
1567
|
+
target: this,
|
|
1568
|
+
type: "get",
|
|
1569
|
+
key: "value"
|
|
1570
|
+
}) : this.dep.track();
|
|
1571
|
+
refreshComputed(this);
|
|
1572
|
+
if (link) {
|
|
1573
|
+
link.version = this.dep.version;
|
|
1574
|
+
}
|
|
1575
|
+
return this._value;
|
|
1576
|
+
}
|
|
1577
|
+
set value(newValue) {
|
|
1578
|
+
if (this.setter) {
|
|
1579
|
+
this.setter(newValue);
|
|
1580
|
+
} else if (!!(process.env.NODE_ENV !== "production")) {
|
|
1581
|
+
warn("Write operation failed: computed value is readonly");
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1586
|
+
let getter;
|
|
1587
|
+
let setter;
|
|
1588
|
+
if (isFunction(getterOrOptions)) {
|
|
1589
|
+
getter = getterOrOptions;
|
|
1590
|
+
} else {
|
|
1591
|
+
getter = getterOrOptions.get;
|
|
1592
|
+
setter = getterOrOptions.set;
|
|
1593
|
+
}
|
|
1594
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
1595
|
+
if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
|
|
1596
|
+
cRef.onTrack = debugOptions.onTrack;
|
|
1597
|
+
cRef.onTrigger = debugOptions.onTrigger;
|
|
1598
|
+
}
|
|
1599
|
+
return cRef;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// src/scheduler.ts
|
|
1603
|
+
var queued = false;
|
|
1604
|
+
var flushIndex = -1;
|
|
1605
|
+
var queue = [];
|
|
1606
|
+
var p = Promise.resolve();
|
|
1607
|
+
var jobId = 0;
|
|
1608
|
+
var nextJobId = () => ++jobId;
|
|
1609
|
+
var nextTick = (fn) => p.then(fn);
|
|
1610
|
+
var idOf = (job) => job.id ?? Infinity;
|
|
1611
|
+
var queueJob = (job) => {
|
|
1612
|
+
if (!queue.includes(job)) {
|
|
1613
|
+
const id = idOf(job);
|
|
1614
|
+
let i = queue.length;
|
|
1615
|
+
while (i > flushIndex + 1 && idOf(queue[i - 1]) > id)
|
|
1616
|
+
i--;
|
|
1617
|
+
queue.splice(i, 0, job);
|
|
1618
|
+
}
|
|
1619
|
+
if (!queued) {
|
|
1620
|
+
queued = true;
|
|
1621
|
+
nextTick(flushJobs);
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
var flushJobs = () => {
|
|
1625
|
+
try {
|
|
1626
|
+
for (flushIndex = 0;flushIndex < queue.length; flushIndex++) {
|
|
1627
|
+
queue[flushIndex]();
|
|
1628
|
+
}
|
|
1629
|
+
} finally {
|
|
1630
|
+
flushIndex = -1;
|
|
1631
|
+
queue.length = 0;
|
|
1632
|
+
queued = false;
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
// src/context.ts
|
|
1637
|
+
var sealing = 0;
|
|
1638
|
+
var isSealing = () => sealing > 0;
|
|
1639
|
+
var sealContext = (ctx, teardown) => {
|
|
1640
|
+
const collect = (c) => [
|
|
1641
|
+
...c.sealers,
|
|
1642
|
+
...c.blocks.flatMap((b) => b.ctx && b.ctx !== c ? collect(b.ctx) : [])
|
|
1643
|
+
];
|
|
1644
|
+
sealing++;
|
|
1645
|
+
try {
|
|
1646
|
+
for (const fn of collect(ctx)) {
|
|
1647
|
+
try {
|
|
1648
|
+
fn();
|
|
1649
|
+
} catch (e) {
|
|
1650
|
+
console.error(e);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
flushJobs();
|
|
1654
|
+
teardown();
|
|
1655
|
+
} finally {
|
|
1656
|
+
sealing--;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
var createContext = (parent) => {
|
|
1660
|
+
const ctx = {
|
|
1661
|
+
delimiters: ["{{", "}}"],
|
|
1662
|
+
delimitersRE: /\{\{([^]+?)\}\}/g,
|
|
1663
|
+
provides: Object.create(null),
|
|
1664
|
+
...parent,
|
|
1665
|
+
scope: parent ? parent.scope : reactive({}),
|
|
1666
|
+
dirs: parent ? parent.dirs : {},
|
|
1667
|
+
effects: [],
|
|
1668
|
+
blocks: [],
|
|
1669
|
+
cleanups: [],
|
|
1670
|
+
sealers: [],
|
|
1671
|
+
effect: (fn) => {
|
|
1672
|
+
let stopped = false;
|
|
1673
|
+
const job = () => {
|
|
1674
|
+
if (!stopped)
|
|
1675
|
+
e();
|
|
1676
|
+
};
|
|
1677
|
+
job.id = nextJobId();
|
|
1678
|
+
const e = effect(fn, {
|
|
1679
|
+
scheduler: () => queueJob(job),
|
|
1680
|
+
onStop: () => stopped = true
|
|
1681
|
+
});
|
|
1682
|
+
ctx.effects.push(e);
|
|
1683
|
+
return e;
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
return ctx;
|
|
1687
|
+
};
|
|
1688
|
+
var paramNames = new Set(["$data", "$el"]);
|
|
1689
|
+
var claimedGlobals = new Set([
|
|
1690
|
+
"name",
|
|
1691
|
+
"open",
|
|
1692
|
+
"close",
|
|
1693
|
+
"closed",
|
|
1694
|
+
"status",
|
|
1695
|
+
"length",
|
|
1696
|
+
"top",
|
|
1697
|
+
"parent",
|
|
1698
|
+
"opener",
|
|
1699
|
+
"origin",
|
|
1700
|
+
"event",
|
|
1701
|
+
"frames",
|
|
1702
|
+
"screen",
|
|
1703
|
+
"content"
|
|
1704
|
+
]);
|
|
1705
|
+
var identRE = /^[A-Za-z_$][\w$]*$/;
|
|
1706
|
+
var lexicalProbes = Object.create(null);
|
|
1707
|
+
var isGlobalName = (key) => {
|
|
1708
|
+
if (claimedGlobals.has(key))
|
|
1709
|
+
return false;
|
|
1710
|
+
if (hasOwn(globalThis, key))
|
|
1711
|
+
return true;
|
|
1712
|
+
if (!identRE.test(key))
|
|
1713
|
+
return false;
|
|
1714
|
+
if (isElementName(key))
|
|
1715
|
+
return false;
|
|
1716
|
+
try {
|
|
1717
|
+
(lexicalProbes[key] ||= new Function(key))();
|
|
1718
|
+
return true;
|
|
1719
|
+
} catch {
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
var valueProbes = Object.create(null);
|
|
1724
|
+
var isElementName = (key) => {
|
|
1725
|
+
if (typeof Element === "undefined" || hasOwn(globalThis, key) || !(key in globalThis))
|
|
1726
|
+
return false;
|
|
1727
|
+
let value;
|
|
1728
|
+
try {
|
|
1729
|
+
value = globalThis[key];
|
|
1730
|
+
if (!(value instanceof Element || typeof HTMLCollection !== "undefined" && value instanceof HTMLCollection)) {
|
|
1731
|
+
return false;
|
|
1732
|
+
}
|
|
1733
|
+
return (valueProbes[key] ||= new Function(`return ${key}`))() === value;
|
|
1734
|
+
} catch {
|
|
1735
|
+
return false;
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
var strictHas = false;
|
|
1739
|
+
var isDeclared = (scope, key) => {
|
|
1740
|
+
const prev = strictHas;
|
|
1741
|
+
strictHas = true;
|
|
1742
|
+
try {
|
|
1743
|
+
return key in scope;
|
|
1744
|
+
} finally {
|
|
1745
|
+
strictHas = prev;
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
var rawScopes = new WeakMap;
|
|
1749
|
+
var claimElementName = (scope, key) => {
|
|
1750
|
+
if (identRE.test(key) && !paramNames.has(key) && !isDeclared(scope, key) && isElementName(key)) {
|
|
1751
|
+
scope[key] = undefined;
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
var createScopedContext = (ctx, data = {}, isScope = false) => {
|
|
1755
|
+
const parentScope = ctx.scope;
|
|
1756
|
+
const mergedScope = Object.create(parentScope);
|
|
1757
|
+
Object.defineProperties(mergedScope, Object.getOwnPropertyDescriptors(data));
|
|
1758
|
+
mergedScope.$refs = Object.create(parentScope.$refs);
|
|
1759
|
+
const reactiveProxy = reactive(new Proxy(mergedScope, {
|
|
1760
|
+
set(target, key, val, receiver) {
|
|
1761
|
+
if (receiver === reactiveProxy && !hasOwn(target, key)) {
|
|
1762
|
+
if (!isScope || isDeclared(parentScope, key)) {
|
|
1763
|
+
return Reflect.set(parentScope, key, val);
|
|
1764
|
+
}
|
|
1765
|
+
Object.defineProperty(target, key, {
|
|
1766
|
+
value: val,
|
|
1767
|
+
writable: true,
|
|
1768
|
+
enumerable: true,
|
|
1769
|
+
configurable: true
|
|
1770
|
+
});
|
|
1771
|
+
return true;
|
|
1772
|
+
}
|
|
1773
|
+
return Reflect.set(target, key, val, receiver);
|
|
1774
|
+
},
|
|
1775
|
+
get(target, key, receiver) {
|
|
1776
|
+
const value = Reflect.get(target, key, receiver);
|
|
1777
|
+
if (value === undefined && typeof key === "string" && !Reflect.has(target, key) && identRE.test(key) && isElementName(key)) {
|
|
1778
|
+
return globalThis[key];
|
|
1779
|
+
}
|
|
1780
|
+
return value;
|
|
1781
|
+
},
|
|
1782
|
+
has(target, key) {
|
|
1783
|
+
if (Reflect.has(target, key))
|
|
1784
|
+
return true;
|
|
1785
|
+
if (strictHas || typeof key !== "string" || paramNames.has(key)) {
|
|
1786
|
+
return false;
|
|
1787
|
+
}
|
|
1788
|
+
return !isGlobalName(key);
|
|
1789
|
+
}
|
|
1790
|
+
}));
|
|
1791
|
+
rawScopes.set(reactiveProxy, mergedScope);
|
|
1792
|
+
bindContextMethods(reactiveProxy);
|
|
1793
|
+
return {
|
|
1794
|
+
...ctx,
|
|
1795
|
+
scope: reactiveProxy,
|
|
1796
|
+
provides: isScope ? Object.create(ctx.provides) : ctx.provides
|
|
1797
|
+
};
|
|
1798
|
+
};
|
|
1799
|
+
var declareInScope = (scope, data) => {
|
|
1800
|
+
const raw = rawScopes.get(scope);
|
|
1801
|
+
if (!raw)
|
|
1802
|
+
return;
|
|
1803
|
+
const descriptors = Object.getOwnPropertyDescriptors(data);
|
|
1804
|
+
for (const key of Object.keys(descriptors)) {
|
|
1805
|
+
const d = descriptors[key];
|
|
1806
|
+
if (typeof d.value === "function")
|
|
1807
|
+
d.value = d.value.bind(scope);
|
|
1808
|
+
d.configurable = true;
|
|
1809
|
+
}
|
|
1810
|
+
Object.defineProperties(raw, descriptors);
|
|
1811
|
+
};
|
|
1812
|
+
var defineScopeHelpers = (scope, helpers) => {
|
|
1813
|
+
const raw = rawScopes.get(scope);
|
|
1814
|
+
if (!raw)
|
|
1815
|
+
return;
|
|
1816
|
+
for (const key of Object.keys(helpers)) {
|
|
1817
|
+
helpers[key] = { enumerable: false, configurable: true, ...helpers[key] };
|
|
1818
|
+
}
|
|
1819
|
+
Object.defineProperties(raw, helpers);
|
|
1820
|
+
};
|
|
1821
|
+
var bindContextMethods = (scope) => {
|
|
1822
|
+
for (const key of Object.keys(scope)) {
|
|
1823
|
+
if (typeof scope[key] === "function") {
|
|
1824
|
+
scope[key] = scope[key].bind(scope);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
var ctxOf = new WeakMap;
|
|
1829
|
+
var recordContext = (node, ctx) => {
|
|
1830
|
+
ctxOf.set(node, ctx);
|
|
1831
|
+
};
|
|
1832
|
+
var contextAt = (node) => ctxOf.get(node);
|
|
1833
|
+
var findContext = (node) => {
|
|
1834
|
+
let cur = node.parentNode;
|
|
1835
|
+
while (cur) {
|
|
1836
|
+
const ctx = ctxOf.get(cur);
|
|
1837
|
+
if (ctx)
|
|
1838
|
+
return ctx;
|
|
1839
|
+
cur = cur.parentNode;
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
var rootScopeOf = (scope) => {
|
|
1843
|
+
let cur = scope;
|
|
1844
|
+
let raw;
|
|
1845
|
+
while (raw = rawScopes.get(cur))
|
|
1846
|
+
cur = Object.getPrototypeOf(raw);
|
|
1847
|
+
return cur;
|
|
1848
|
+
};
|
|
1849
|
+
var slotCtxOf = new WeakMap;
|
|
1850
|
+
var slotMarks = 0;
|
|
1851
|
+
var recordSlotContext = (node, ctx) => {
|
|
1852
|
+
slotMarks++;
|
|
1853
|
+
slotCtxOf.set(node, ctx);
|
|
1854
|
+
};
|
|
1855
|
+
var slotContextOf = (node) => slotCtxOf.get(node);
|
|
1856
|
+
var copySlotContexts = (from, to, self2 = false) => {
|
|
1857
|
+
if (!slotMarks)
|
|
1858
|
+
return;
|
|
1859
|
+
const ctx = self2 && slotCtxOf.get(from);
|
|
1860
|
+
if (ctx) {
|
|
1861
|
+
slotCtxOf.set(to, ctx);
|
|
1862
|
+
const recorded = ctxOf.get(from);
|
|
1863
|
+
if (recorded)
|
|
1864
|
+
ctxOf.set(to, recorded);
|
|
1865
|
+
}
|
|
1866
|
+
let a = from.firstChild;
|
|
1867
|
+
let b = to.firstChild;
|
|
1868
|
+
while (a && b) {
|
|
1869
|
+
copySlotContexts(a, b, true);
|
|
1870
|
+
a = a.nextSibling;
|
|
1871
|
+
b = b.nextSibling;
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
|
|
1875
|
+
// src/directives/bind.ts
|
|
1876
|
+
var forceAttrRE = /^(spellcheck|draggable|form|list|type)$/;
|
|
1877
|
+
var bind = ({
|
|
1878
|
+
el,
|
|
1879
|
+
get,
|
|
1880
|
+
effect: effect2,
|
|
1881
|
+
arg,
|
|
1882
|
+
modifiers
|
|
1883
|
+
}) => {
|
|
1884
|
+
let prevValue;
|
|
1885
|
+
if (arg === "class") {
|
|
1886
|
+
el._class = el.className;
|
|
1887
|
+
}
|
|
1888
|
+
effect2(() => {
|
|
1889
|
+
let value = get();
|
|
1890
|
+
if (arg) {
|
|
1891
|
+
if (modifiers?.camel) {
|
|
1892
|
+
arg = camelize(arg);
|
|
1893
|
+
}
|
|
1894
|
+
setProp(el, arg, value, prevValue);
|
|
1895
|
+
} else {
|
|
1896
|
+
for (const key in value) {
|
|
1897
|
+
setProp(el, key, value[key], prevValue && prevValue[key]);
|
|
1898
|
+
}
|
|
1899
|
+
for (const key in prevValue) {
|
|
1900
|
+
if (!value || !(key in value)) {
|
|
1901
|
+
setProp(el, key, null);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
prevValue = value;
|
|
1906
|
+
});
|
|
1907
|
+
};
|
|
1908
|
+
var setProp = (el, key, value, prevValue) => {
|
|
1909
|
+
if (key === "class") {
|
|
1910
|
+
el.setAttribute("class", normalizeClass(el._class ? [el._class, value] : value) || "");
|
|
1911
|
+
} else if (key === "style") {
|
|
1912
|
+
value = normalizeStyle(value);
|
|
1913
|
+
const { style } = el;
|
|
1914
|
+
if (!value) {
|
|
1915
|
+
el.removeAttribute("style");
|
|
1916
|
+
} else if (isString(value)) {
|
|
1917
|
+
if (value !== prevValue)
|
|
1918
|
+
style.cssText = value;
|
|
1919
|
+
} else {
|
|
1920
|
+
for (const key2 in value) {
|
|
1921
|
+
setStyle(style, key2, value[key2]);
|
|
1922
|
+
}
|
|
1923
|
+
if (prevValue && !isString(prevValue)) {
|
|
1924
|
+
for (const key2 in prevValue) {
|
|
1925
|
+
if (value[key2] == null) {
|
|
1926
|
+
setStyle(style, key2, "");
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
} else if (!(el instanceof SVGElement) && key in el && !forceAttrRE.test(key)) {
|
|
1932
|
+
el[key] = value;
|
|
1933
|
+
if (key === "value") {
|
|
1934
|
+
el._value = value;
|
|
1935
|
+
}
|
|
1936
|
+
} else {
|
|
1937
|
+
if (key === "true-value") {
|
|
1938
|
+
el._trueValue = value;
|
|
1939
|
+
} else if (key === "false-value") {
|
|
1940
|
+
el._falseValue = value;
|
|
1941
|
+
} else if (isSpecialBooleanAttr(key)) {
|
|
1942
|
+
if (includeBooleanAttr(value))
|
|
1943
|
+
el.setAttribute(key, "");
|
|
1944
|
+
else
|
|
1945
|
+
el.removeAttribute(key);
|
|
1946
|
+
} else if (value != null) {
|
|
1947
|
+
el.setAttribute(key, value);
|
|
1948
|
+
} else {
|
|
1949
|
+
el.removeAttribute(key);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
var importantRE = /\s*!important$/;
|
|
1954
|
+
var setStyle = (style, name, val) => {
|
|
1955
|
+
if (isArray(val)) {
|
|
1956
|
+
val.forEach((v) => setStyle(style, name, v));
|
|
1957
|
+
} else {
|
|
1958
|
+
if (name.startsWith("--")) {
|
|
1959
|
+
style.setProperty(name, val);
|
|
1960
|
+
} else {
|
|
1961
|
+
if (importantRE.test(val)) {
|
|
1962
|
+
style.setProperty(hyphenate(name), val.replace(importantRE, ""), "important");
|
|
1963
|
+
} else {
|
|
1964
|
+
style[name] = val;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
// src/utils.ts
|
|
1971
|
+
var checkAttr = (el, name) => {
|
|
1972
|
+
const val = el.getAttribute(name);
|
|
1973
|
+
if (val != null)
|
|
1974
|
+
el.removeAttribute(name);
|
|
1975
|
+
return val;
|
|
1976
|
+
};
|
|
1977
|
+
var listen = (el, event, handler, options) => {
|
|
1978
|
+
el.addEventListener(event, handler, options);
|
|
1979
|
+
sink && sink.push(() => el.removeEventListener(event, handler, options));
|
|
1980
|
+
};
|
|
1981
|
+
var sink = null;
|
|
1982
|
+
var collectListeners = (to, fn) => {
|
|
1983
|
+
const outer = sink;
|
|
1984
|
+
sink = to;
|
|
1985
|
+
try {
|
|
1986
|
+
return fn();
|
|
1987
|
+
} finally {
|
|
1988
|
+
sink = outer;
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1991
|
+
|
|
1992
|
+
// src/directives/on.ts
|
|
1993
|
+
var fnExpRE = /^\s*(?:async\s+)?(?:\([^)]*?\)|[\w$]+)\s*=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
1994
|
+
var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;
|
|
1995
|
+
var systemModifiers = ["ctrl", "shift", "alt", "meta"];
|
|
1996
|
+
var modifierGuards = {
|
|
1997
|
+
stop: (e) => e.stopPropagation(),
|
|
1998
|
+
prevent: (e) => e.preventDefault(),
|
|
1999
|
+
self: (e) => e.target !== e.currentTarget,
|
|
2000
|
+
ctrl: (e) => !e.ctrlKey,
|
|
2001
|
+
shift: (e) => !e.shiftKey,
|
|
2002
|
+
alt: (e) => !e.altKey,
|
|
2003
|
+
meta: (e) => !e.metaKey,
|
|
2004
|
+
left: (e) => ("button" in e) && e.button !== 0,
|
|
2005
|
+
middle: (e) => ("button" in e) && e.button !== 1,
|
|
2006
|
+
right: (e) => ("button" in e) && e.button !== 2,
|
|
2007
|
+
exact: (e, modifiers) => systemModifiers.some((m) => e[`${m}Key`] && !modifiers[m])
|
|
2008
|
+
};
|
|
2009
|
+
var on = ({ el, get, exp, arg, modifiers, ctx }) => {
|
|
2010
|
+
if (!arg) {
|
|
2011
|
+
if (DEV) {
|
|
2012
|
+
console.error(`h-on="obj" syntax is not supported.`);
|
|
2013
|
+
}
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
let handler = simplePathRE.test(exp) ? get(`(e => ${exp}(e))`) : fnExpRE.test(exp) ? get(`(e => (${exp})(e))`) : get(`($event => { ${exp} })`);
|
|
2017
|
+
if (arg === "scope:mounted") {
|
|
2018
|
+
nextTick(handler);
|
|
2019
|
+
return;
|
|
2020
|
+
} else if (arg === "scope:unmounted") {
|
|
2021
|
+
return () => {
|
|
2022
|
+
isSealing() || handler();
|
|
2023
|
+
};
|
|
2024
|
+
} else if (arg === "scope:sealed") {
|
|
2025
|
+
ctx.sealers.push(() => handler());
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
if (modifiers) {
|
|
2029
|
+
if (arg === "click") {
|
|
2030
|
+
if (modifiers.right)
|
|
2031
|
+
arg = "contextmenu";
|
|
2032
|
+
if (modifiers.middle)
|
|
2033
|
+
arg = "mouseup";
|
|
2034
|
+
}
|
|
2035
|
+
const raw = handler;
|
|
2036
|
+
handler = (e) => {
|
|
2037
|
+
if ("key" in e && !(hyphenate(e.key) in modifiers)) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
for (const key in modifiers) {
|
|
2041
|
+
const guard = modifierGuards[key];
|
|
2042
|
+
if (guard && guard(e, modifiers)) {
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
return raw(e);
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
listen(el, arg, handler, modifiers);
|
|
2050
|
+
};
|
|
2051
|
+
|
|
2052
|
+
// src/directives/show.ts
|
|
2053
|
+
var show = ({ el, get, effect: effect2 }) => {
|
|
2054
|
+
const initialDisplay = el.style.display;
|
|
2055
|
+
effect2(() => {
|
|
2056
|
+
el.style.display = get() ? initialDisplay : "none";
|
|
2057
|
+
});
|
|
2058
|
+
};
|
|
2059
|
+
|
|
2060
|
+
// src/directives/text.ts
|
|
2061
|
+
var text = ({ el, get, effect: effect2 }) => {
|
|
2062
|
+
effect2(() => {
|
|
2063
|
+
el.textContent = toDisplayString(get());
|
|
2064
|
+
});
|
|
2065
|
+
};
|
|
2066
|
+
var toDisplayString = (value) => value == null ? "" : isObject(value) ? JSON.stringify(value, null, 2) : String(value);
|
|
2067
|
+
|
|
2068
|
+
// src/directives/html.ts
|
|
2069
|
+
var html = ({ el, get, effect: effect2 }) => {
|
|
2070
|
+
el.setAttribute("h-pre", "");
|
|
2071
|
+
effect2(() => {
|
|
2072
|
+
el.innerHTML = get();
|
|
2073
|
+
});
|
|
2074
|
+
};
|
|
2075
|
+
|
|
2076
|
+
// src/directives/model.ts
|
|
2077
|
+
var dotPathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
|
|
2078
|
+
var modelOf = (target) => {
|
|
2079
|
+
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
2080
|
+
return el && el._h_model || null;
|
|
2081
|
+
};
|
|
2082
|
+
var attachModel = (el, get, assign, render) => {
|
|
2083
|
+
const handle = {
|
|
2084
|
+
el,
|
|
2085
|
+
get,
|
|
2086
|
+
set(value) {
|
|
2087
|
+
pauseTracking();
|
|
2088
|
+
try {
|
|
2089
|
+
assign(value);
|
|
2090
|
+
render();
|
|
2091
|
+
} finally {
|
|
2092
|
+
resetTracking();
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
el._h_model = handle;
|
|
2097
|
+
};
|
|
2098
|
+
var model = ({ el, exp, get, effect: effect2, modifiers, ctx }) => {
|
|
2099
|
+
const type = el.type;
|
|
2100
|
+
const { trim, number = type === "number" } = modifiers || {};
|
|
2101
|
+
const rootName = exp.match(/^\s*([A-Za-z_$][\w$]*)/);
|
|
2102
|
+
if (rootName)
|
|
2103
|
+
claimElementName(ctx.scope, rootName[1]);
|
|
2104
|
+
let readExp = exp;
|
|
2105
|
+
let ensure = "";
|
|
2106
|
+
if (dotPathRE.test(exp)) {
|
|
2107
|
+
const parts = exp.split(".");
|
|
2108
|
+
readExp = parts.join("?.");
|
|
2109
|
+
for (let i = 1;i < parts.length; i++) {
|
|
2110
|
+
const p2 = parts.slice(0, i).join(".");
|
|
2111
|
+
ensure += `if (${p2} == null) ${p2} = {};`;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
const assign = get(`(val) => { ${ensure} ${exp} = val }`);
|
|
2115
|
+
const read = () => get(readExp);
|
|
2116
|
+
const seed = (val) => {
|
|
2117
|
+
pauseTracking();
|
|
2118
|
+
try {
|
|
2119
|
+
if (ensure)
|
|
2120
|
+
get(`(() => { ${ensure} })`)();
|
|
2121
|
+
if (read() === undefined) {
|
|
2122
|
+
const v = val();
|
|
2123
|
+
if (v !== undefined)
|
|
2124
|
+
assign(v);
|
|
2125
|
+
}
|
|
2126
|
+
} finally {
|
|
2127
|
+
resetTracking();
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
let render;
|
|
2131
|
+
if (el.tagName === "SELECT") {
|
|
2132
|
+
const sel = el;
|
|
2133
|
+
const picked = () => Array.prototype.filter.call(sel.options, (o) => o.selected).map((o) => getValue(o));
|
|
2134
|
+
const toModel = (vals) => {
|
|
2135
|
+
const out = number ? vals.map((v) => toNumber(v)) : vals;
|
|
2136
|
+
return sel.multiple ? out : out[0];
|
|
2137
|
+
};
|
|
2138
|
+
seed(() => toModel(picked()));
|
|
2139
|
+
let synced = picked();
|
|
2140
|
+
listen(el, "change", () => {
|
|
2141
|
+
const now = picked();
|
|
2142
|
+
if (looseEqual(now, synced))
|
|
2143
|
+
return;
|
|
2144
|
+
synced = now;
|
|
2145
|
+
assign(toModel(now));
|
|
2146
|
+
});
|
|
2147
|
+
const paint = (value) => {
|
|
2148
|
+
const isMultiple = sel.multiple;
|
|
2149
|
+
for (let i = 0, l = sel.options.length;i < l; i++) {
|
|
2150
|
+
const option = sel.options[i];
|
|
2151
|
+
const optionValue = getValue(option);
|
|
2152
|
+
if (isMultiple) {
|
|
2153
|
+
if (isArray(value)) {
|
|
2154
|
+
option.selected = looseIndexOf(value, optionValue) > -1;
|
|
2155
|
+
} else {
|
|
2156
|
+
option.selected = !!value?.has?.(optionValue);
|
|
2157
|
+
}
|
|
2158
|
+
} else {
|
|
2159
|
+
if (looseEqual(getValue(option), value)) {
|
|
2160
|
+
if (sel.selectedIndex !== i)
|
|
2161
|
+
sel.selectedIndex = i;
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
if (!isMultiple && sel.selectedIndex !== -1) {
|
|
2167
|
+
sel.selectedIndex = -1;
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
render = () => {
|
|
2171
|
+
paint(read());
|
|
2172
|
+
synced = picked();
|
|
2173
|
+
};
|
|
2174
|
+
} else if (type === "checkbox") {
|
|
2175
|
+
const box = el;
|
|
2176
|
+
seed(() => getCheckboxValue(box, box.checked));
|
|
2177
|
+
let synced = box.checked;
|
|
2178
|
+
listen(el, "change", () => {
|
|
2179
|
+
const checked = box.checked;
|
|
2180
|
+
if (checked === synced)
|
|
2181
|
+
return;
|
|
2182
|
+
synced = checked;
|
|
2183
|
+
const modelValue = read();
|
|
2184
|
+
if (isArray(modelValue)) {
|
|
2185
|
+
const elementValue = getValue(el);
|
|
2186
|
+
const index = looseIndexOf(modelValue, elementValue);
|
|
2187
|
+
const found = index !== -1;
|
|
2188
|
+
if (checked && !found) {
|
|
2189
|
+
assign(modelValue.concat(elementValue));
|
|
2190
|
+
} else if (!checked && found) {
|
|
2191
|
+
const filtered = [...modelValue];
|
|
2192
|
+
filtered.splice(index, 1);
|
|
2193
|
+
assign(filtered);
|
|
2194
|
+
}
|
|
2195
|
+
} else {
|
|
2196
|
+
assign(getCheckboxValue(box, checked));
|
|
2197
|
+
}
|
|
2198
|
+
});
|
|
2199
|
+
let oldValue;
|
|
2200
|
+
render = () => {
|
|
2201
|
+
const value = read();
|
|
2202
|
+
if (isArray(value)) {
|
|
2203
|
+
box.checked = looseIndexOf(value, getValue(el)) > -1;
|
|
2204
|
+
} else if (value !== oldValue) {
|
|
2205
|
+
box.checked = looseEqual(value, getCheckboxValue(box, true));
|
|
2206
|
+
}
|
|
2207
|
+
oldValue = value;
|
|
2208
|
+
synced = box.checked;
|
|
2209
|
+
};
|
|
2210
|
+
} else if (type === "radio") {
|
|
2211
|
+
const radio = el;
|
|
2212
|
+
seed(() => radio.checked ? getValue(el) : undefined);
|
|
2213
|
+
let synced = radio.checked;
|
|
2214
|
+
listen(el, "change", () => {
|
|
2215
|
+
const checked = radio.checked;
|
|
2216
|
+
if (checked === synced)
|
|
2217
|
+
return;
|
|
2218
|
+
synced = checked;
|
|
2219
|
+
if (checked)
|
|
2220
|
+
assign(getValue(el));
|
|
2221
|
+
});
|
|
2222
|
+
render = () => {
|
|
2223
|
+
radio.checked = looseEqual(read(), getValue(el));
|
|
2224
|
+
synced = radio.checked;
|
|
2225
|
+
};
|
|
2226
|
+
} else {
|
|
2227
|
+
const resolveValue = (val) => {
|
|
2228
|
+
if (trim)
|
|
2229
|
+
return val.trim();
|
|
2230
|
+
if (number)
|
|
2231
|
+
return toNumber(val);
|
|
2232
|
+
return val;
|
|
2233
|
+
};
|
|
2234
|
+
seed(() => resolveValue(el.value));
|
|
2235
|
+
let synced = el.value;
|
|
2236
|
+
let held = false;
|
|
2237
|
+
listen(el, "compositionstart", onCompositionStart);
|
|
2238
|
+
listen(el, "compositionend", onCompositionEnd);
|
|
2239
|
+
listen(el, modifiers?.lazy ? "change" : "input", () => {
|
|
2240
|
+
if (el.composing)
|
|
2241
|
+
return;
|
|
2242
|
+
if (el.value === synced) {
|
|
2243
|
+
if (held)
|
|
2244
|
+
render();
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
held = false;
|
|
2248
|
+
synced = el.value;
|
|
2249
|
+
assign(resolveValue(el.value));
|
|
2250
|
+
});
|
|
2251
|
+
if (trim) {
|
|
2252
|
+
listen(el, "change", () => {
|
|
2253
|
+
const dirty = el.value !== synced;
|
|
2254
|
+
el.value = el.value.trim();
|
|
2255
|
+
if (!dirty)
|
|
2256
|
+
synced = el.value;
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
render = () => {
|
|
2260
|
+
const newVal = read() ?? "";
|
|
2261
|
+
if (el.composing) {
|
|
2262
|
+
held = true;
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
held = false;
|
|
2266
|
+
const curVal = el.value;
|
|
2267
|
+
if (!(document.activeElement === el && resolveValue(curVal) === newVal) && curVal !== newVal) {
|
|
2268
|
+
el.value = newVal;
|
|
2269
|
+
}
|
|
2270
|
+
synced = el.value;
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
attachModel(el, read, assign, () => render());
|
|
2274
|
+
effect2(() => render());
|
|
2275
|
+
};
|
|
2276
|
+
var getValue = (el) => ("_value" in el) ? el._value : el.value;
|
|
2277
|
+
var getCheckboxValue = (el, checked) => {
|
|
2278
|
+
const key = checked ? "_trueValue" : "_falseValue";
|
|
2279
|
+
return key in el ? el[key] : checked;
|
|
2280
|
+
};
|
|
2281
|
+
var onCompositionStart = (e) => {
|
|
2282
|
+
e.target.composing = true;
|
|
2283
|
+
};
|
|
2284
|
+
var onCompositionEnd = (e) => {
|
|
2285
|
+
const target = e.target;
|
|
2286
|
+
if (target.composing) {
|
|
2287
|
+
target.composing = false;
|
|
2288
|
+
trigger2(target, "input");
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
var trigger2 = (el, type) => {
|
|
2292
|
+
const e = document.createEvent("HTMLEvents");
|
|
2293
|
+
e.initEvent(type, true, true);
|
|
2294
|
+
el.dispatchEvent(e);
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
// src/eval.ts
|
|
2298
|
+
var evalCache = Object.create(null);
|
|
2299
|
+
var evaluate = (scope, exp, el) => execute(scope, `return(${exp})`, el);
|
|
2300
|
+
var execute = (scope, exp, el) => {
|
|
2301
|
+
const fn = evalCache[exp] || (evalCache[exp] = toFunction(exp));
|
|
2302
|
+
try {
|
|
2303
|
+
return fn(scope, el);
|
|
2304
|
+
} catch (e) {
|
|
2305
|
+
if (DEV) {
|
|
2306
|
+
console.warn(`Error when evaluating expression "${exp}":`);
|
|
2307
|
+
}
|
|
2308
|
+
console.error(e);
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
var toFunction = (exp) => {
|
|
2312
|
+
try {
|
|
2313
|
+
return new Function(`$data`, `$el`, `with($data){${exp}}`);
|
|
2314
|
+
} catch (e) {
|
|
2315
|
+
console.error(`${e.message} in expression: ${exp}`);
|
|
2316
|
+
return () => {};
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
|
|
2320
|
+
// src/directives/effect.ts
|
|
2321
|
+
var effect2 = ({ el, ctx, exp, effect: effect3, modifiers }) => {
|
|
2322
|
+
const run = () => execute(ctx.scope, exp, el);
|
|
2323
|
+
if (modifiers && (modifiers.mounted || modifiers.unmounted || modifiers.sealed)) {
|
|
2324
|
+
let gone = false;
|
|
2325
|
+
if (modifiers.mounted)
|
|
2326
|
+
nextTick(() => gone || run());
|
|
2327
|
+
if (modifiers.sealed)
|
|
2328
|
+
ctx.sealers.push(run);
|
|
2329
|
+
return () => {
|
|
2330
|
+
gone = true;
|
|
2331
|
+
if (modifiers.unmounted && !isSealing())
|
|
2332
|
+
run();
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
nextTick(() => effect3(run));
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2338
|
+
// src/directives/index.ts
|
|
2339
|
+
var builtInDirectives = {
|
|
2340
|
+
bind,
|
|
2341
|
+
on,
|
|
2342
|
+
show,
|
|
2343
|
+
text,
|
|
2344
|
+
html,
|
|
2345
|
+
model,
|
|
2346
|
+
effect: effect2
|
|
2347
|
+
};
|
|
2348
|
+
|
|
2349
|
+
// src/directives/if.ts
|
|
2350
|
+
var _if = (el, exp, ctx) => {
|
|
2351
|
+
if (DEV && !exp.trim()) {
|
|
2352
|
+
console.warn(`h-if expression cannot be empty.`);
|
|
2353
|
+
}
|
|
2354
|
+
const parent = el.parentNode;
|
|
2355
|
+
const anchor = new Comment("h-if");
|
|
2356
|
+
parent.insertBefore(anchor, el);
|
|
2357
|
+
const branches = [
|
|
2358
|
+
{
|
|
2359
|
+
exp,
|
|
2360
|
+
el
|
|
2361
|
+
}
|
|
2362
|
+
];
|
|
2363
|
+
let elseEl;
|
|
2364
|
+
let elseExp;
|
|
2365
|
+
while (elseEl = el.nextElementSibling) {
|
|
2366
|
+
elseExp = null;
|
|
2367
|
+
if (checkAttr(elseEl, "h-else") === "" || (elseExp = checkAttr(elseEl, "h-else-if"))) {
|
|
2368
|
+
parent.removeChild(elseEl);
|
|
2369
|
+
branches.push({ exp: elseExp, el: elseEl });
|
|
2370
|
+
} else {
|
|
2371
|
+
break;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
const nextNode = el.nextSibling;
|
|
2375
|
+
parent.removeChild(el);
|
|
2376
|
+
let block;
|
|
2377
|
+
let activeBranchIndex = -1;
|
|
2378
|
+
const removeActiveBlock = () => {
|
|
2379
|
+
if (block) {
|
|
2380
|
+
block.el.parentNode.insertBefore(anchor, block.el);
|
|
2381
|
+
block.remove();
|
|
2382
|
+
block = undefined;
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
ctx.effect(() => {
|
|
2386
|
+
for (let i = 0;i < branches.length; i++) {
|
|
2387
|
+
const { exp: exp2, el: el2 } = branches[i];
|
|
2388
|
+
if (!exp2 || evaluate(ctx.scope, exp2)) {
|
|
2389
|
+
if (i !== activeBranchIndex) {
|
|
2390
|
+
removeActiveBlock();
|
|
2391
|
+
block = new Block(el2, ctx);
|
|
2392
|
+
const host = anchor.parentNode;
|
|
2393
|
+
block.insert(host, anchor);
|
|
2394
|
+
host.removeChild(anchor);
|
|
2395
|
+
activeBranchIndex = i;
|
|
2396
|
+
}
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
activeBranchIndex = -1;
|
|
2401
|
+
removeActiveBlock();
|
|
2402
|
+
});
|
|
2403
|
+
return nextNode;
|
|
2404
|
+
};
|
|
2405
|
+
|
|
2406
|
+
// src/directives/for.ts
|
|
2407
|
+
var forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
2408
|
+
var forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
2409
|
+
var stripParensRE = /^\(|\)$/g;
|
|
2410
|
+
var destructureRE = /^[{[]\s*((?:[\w_$]+\s*,?\s*)+)[\]}]$/;
|
|
2411
|
+
var _for = (el, exp, ctx) => {
|
|
2412
|
+
const inMatch = exp.match(forAliasRE);
|
|
2413
|
+
if (!inMatch) {
|
|
2414
|
+
DEV && console.warn(`invalid h-for expression: ${exp}`);
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
const nextNode = el.nextSibling;
|
|
2418
|
+
const parent = el.parentNode;
|
|
2419
|
+
const anchor = new Text("");
|
|
2420
|
+
parent.insertBefore(anchor, el);
|
|
2421
|
+
parent.removeChild(el);
|
|
2422
|
+
const sourceExp = inMatch[2].trim();
|
|
2423
|
+
let valueExp = inMatch[1].trim().replace(stripParensRE, "").trim();
|
|
2424
|
+
let destructureBindings;
|
|
2425
|
+
let isArrayDestructure = false;
|
|
2426
|
+
let indexExp;
|
|
2427
|
+
let objIndexExp;
|
|
2428
|
+
let keyAttr = "key";
|
|
2429
|
+
let keyExp = el.getAttribute(keyAttr) || el.getAttribute(keyAttr = ":key") || el.getAttribute(keyAttr = "h-bind:key");
|
|
2430
|
+
if (keyExp) {
|
|
2431
|
+
el.removeAttribute(keyAttr);
|
|
2432
|
+
if (keyAttr === "key")
|
|
2433
|
+
keyExp = JSON.stringify(keyExp);
|
|
2434
|
+
}
|
|
2435
|
+
let match;
|
|
2436
|
+
if (match = valueExp.match(forIteratorRE)) {
|
|
2437
|
+
valueExp = valueExp.replace(forIteratorRE, "").trim();
|
|
2438
|
+
indexExp = match[1].trim();
|
|
2439
|
+
if (match[2]) {
|
|
2440
|
+
objIndexExp = match[2].trim();
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
if (match = valueExp.match(destructureRE)) {
|
|
2444
|
+
destructureBindings = match[1].split(",").map((s) => s.trim());
|
|
2445
|
+
isArrayDestructure = valueExp[0] === "[";
|
|
2446
|
+
}
|
|
2447
|
+
let mounted = false;
|
|
2448
|
+
let blocks;
|
|
2449
|
+
let childCtxs;
|
|
2450
|
+
let keyToIndexMap;
|
|
2451
|
+
const createChildContexts = (source) => {
|
|
2452
|
+
const map = new Map;
|
|
2453
|
+
const ctxs = [];
|
|
2454
|
+
if (isArray(source)) {
|
|
2455
|
+
for (let i = 0;i < source.length; i++) {
|
|
2456
|
+
ctxs.push(createChildContext(map, source[i], i));
|
|
2457
|
+
}
|
|
2458
|
+
} else if (typeof source === "number") {
|
|
2459
|
+
for (let i = 0;i < source; i++) {
|
|
2460
|
+
ctxs.push(createChildContext(map, i + 1, i));
|
|
2461
|
+
}
|
|
2462
|
+
} else if (isObject(source)) {
|
|
2463
|
+
let i = 0;
|
|
2464
|
+
for (const key in source) {
|
|
2465
|
+
ctxs.push(createChildContext(map, source[key], i++, key));
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
return [ctxs, map];
|
|
2469
|
+
};
|
|
2470
|
+
const createChildContext = (map, value, index, objKey) => {
|
|
2471
|
+
const data = {};
|
|
2472
|
+
if (destructureBindings) {
|
|
2473
|
+
destructureBindings.forEach((b, i) => data[b] = value[isArrayDestructure ? i : b]);
|
|
2474
|
+
} else {
|
|
2475
|
+
data[valueExp] = value;
|
|
2476
|
+
}
|
|
2477
|
+
if (objKey) {
|
|
2478
|
+
indexExp && (data[indexExp] = objKey);
|
|
2479
|
+
objIndexExp && (data[objIndexExp] = index);
|
|
2480
|
+
} else {
|
|
2481
|
+
indexExp && (data[indexExp] = index);
|
|
2482
|
+
}
|
|
2483
|
+
const childCtx = createScopedContext(ctx, data);
|
|
2484
|
+
const key = keyExp ? evaluate(childCtx.scope, keyExp) : index;
|
|
2485
|
+
map.set(key, index);
|
|
2486
|
+
childCtx.key = key;
|
|
2487
|
+
return childCtx;
|
|
2488
|
+
};
|
|
2489
|
+
const mountBlock = (ctx2, ref2) => {
|
|
2490
|
+
const block = new Block(el, ctx2);
|
|
2491
|
+
block.key = ctx2.key;
|
|
2492
|
+
block.insert(anchor.parentNode, ref2);
|
|
2493
|
+
return block;
|
|
2494
|
+
};
|
|
2495
|
+
ctx.effect(() => {
|
|
2496
|
+
const source = evaluate(ctx.scope, sourceExp);
|
|
2497
|
+
const prevKeyToIndexMap = keyToIndexMap;
|
|
2498
|
+
[childCtxs, keyToIndexMap] = createChildContexts(source);
|
|
2499
|
+
if (!mounted) {
|
|
2500
|
+
blocks = childCtxs.map((s) => mountBlock(s, anchor));
|
|
2501
|
+
mounted = true;
|
|
2502
|
+
} else {
|
|
2503
|
+
for (let i2 = 0;i2 < blocks.length; i2++) {
|
|
2504
|
+
if (!keyToIndexMap.has(blocks[i2].key)) {
|
|
2505
|
+
blocks[i2].remove();
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
const nextBlocks = [];
|
|
2509
|
+
let i = childCtxs.length;
|
|
2510
|
+
let nextBlock;
|
|
2511
|
+
let prevMovedBlock;
|
|
2512
|
+
while (i--) {
|
|
2513
|
+
const childCtx = childCtxs[i];
|
|
2514
|
+
const oldIndex = prevKeyToIndexMap.get(childCtx.key);
|
|
2515
|
+
let block;
|
|
2516
|
+
if (oldIndex == null) {
|
|
2517
|
+
block = mountBlock(childCtx, nextBlock ? nextBlock.el : anchor);
|
|
2518
|
+
} else {
|
|
2519
|
+
block = blocks[oldIndex];
|
|
2520
|
+
Object.assign(block.ctx.scope, childCtx.scope);
|
|
2521
|
+
if (oldIndex !== i) {
|
|
2522
|
+
if (blocks[oldIndex + 1] !== nextBlock || prevMovedBlock === nextBlock) {
|
|
2523
|
+
prevMovedBlock = block;
|
|
2524
|
+
block.insert(anchor.parentNode, nextBlock ? nextBlock.el : anchor);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
nextBlocks.unshift(nextBlock = block);
|
|
2529
|
+
}
|
|
2530
|
+
blocks = nextBlocks;
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
return nextNode;
|
|
2534
|
+
};
|
|
2535
|
+
|
|
2536
|
+
// src/directives/ref.ts
|
|
2537
|
+
var ref2 = ({
|
|
2538
|
+
el,
|
|
2539
|
+
ctx: {
|
|
2540
|
+
scope: { $refs }
|
|
2541
|
+
},
|
|
2542
|
+
get,
|
|
2543
|
+
effect: effect3
|
|
2544
|
+
}) => {
|
|
2545
|
+
let prevRef;
|
|
2546
|
+
effect3(() => {
|
|
2547
|
+
const ref3 = get();
|
|
2548
|
+
$refs[ref3] = el;
|
|
2549
|
+
if (prevRef && ref3 !== prevRef) {
|
|
2550
|
+
delete $refs[prevRef];
|
|
2551
|
+
}
|
|
2552
|
+
prevRef = ref3;
|
|
2553
|
+
});
|
|
2554
|
+
return () => {
|
|
2555
|
+
prevRef && delete $refs[prevRef];
|
|
2556
|
+
};
|
|
2557
|
+
};
|
|
2558
|
+
|
|
2559
|
+
// src/async.ts
|
|
2560
|
+
var asyncStatuses = ["idle", "pending", "fulfilled", "rejected"];
|
|
2561
|
+
var createAsyncState = (status = "idle") => reactive({ status, value: undefined, promise: undefined });
|
|
2562
|
+
var createAsyncRegistry = (parent) => ({
|
|
2563
|
+
map: reactive(Object.create(null)),
|
|
2564
|
+
parent
|
|
2565
|
+
});
|
|
2566
|
+
var controllers = new WeakMap;
|
|
2567
|
+
var find = (reg, name) => {
|
|
2568
|
+
for (let cur = reg;cur; cur = cur.parent) {
|
|
2569
|
+
if (name in cur.map)
|
|
2570
|
+
return cur.map[name];
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
var validName = (name) => {
|
|
2574
|
+
if (typeof name === "string" && name && name[0] !== "$" && !/[\s:]/.test(name))
|
|
2575
|
+
return true;
|
|
2576
|
+
console.error(`hyper-scope: $async 의 이름으로 쓸 수 없습니다: ${String(name)} ` + `($ 로 시작하지 않고, 빈칸 · 콜론이 없는 글자여야 합니다)`);
|
|
2577
|
+
return false;
|
|
2578
|
+
};
|
|
2579
|
+
var readAsync = (reg, name) => find(reg, name) || createAsyncState();
|
|
2580
|
+
var settle = (state, mine, status, value) => {
|
|
2581
|
+
if (controllers.get(toRaw(state)) !== mine)
|
|
2582
|
+
return;
|
|
2583
|
+
controllers.delete(toRaw(state));
|
|
2584
|
+
state.status = status;
|
|
2585
|
+
state.value = value;
|
|
2586
|
+
};
|
|
2587
|
+
var runAsync = (reg, self2, name, fn, options) => {
|
|
2588
|
+
pauseTracking();
|
|
2589
|
+
try {
|
|
2590
|
+
const state = find(reg, name) || (reg.map[name] = createAsyncState());
|
|
2591
|
+
if (state.status === "pending" && !(options && options.force)) {
|
|
2592
|
+
console.error(`hyper-scope: $async("${name}") 이 아직 끝나지 않았습니다. ` + `겹쳐 돌지 않습니다 — 앞의 것을 취소하려면 { force: true } 를 줍니다.`);
|
|
2593
|
+
return state;
|
|
2594
|
+
}
|
|
2595
|
+
const raw = toRaw(state);
|
|
2596
|
+
controllers.get(raw)?.abort();
|
|
2597
|
+
controllers.delete(raw);
|
|
2598
|
+
if (fn == null) {
|
|
2599
|
+
state.status = "idle";
|
|
2600
|
+
state.value = undefined;
|
|
2601
|
+
return state;
|
|
2602
|
+
}
|
|
2603
|
+
if (typeof fn !== "function") {
|
|
2604
|
+
console.error(`hyper-scope: $async("${name}", …) 의 둘째 인자는 함수이거나 null 입니다.`);
|
|
2605
|
+
return state;
|
|
2606
|
+
}
|
|
2607
|
+
const controller = new AbortController;
|
|
2608
|
+
controllers.set(raw, controller);
|
|
2609
|
+
state.status = "pending";
|
|
2610
|
+
state.value = undefined;
|
|
2611
|
+
state.promise = new Promise((resolve) => resolve(fn.call(self2, { signal: controller.signal }))).then((value) => {
|
|
2612
|
+
settle(state, controller, "fulfilled", value);
|
|
2613
|
+
return state;
|
|
2614
|
+
}, (error) => {
|
|
2615
|
+
if (controllers.get(raw) === controller) {
|
|
2616
|
+
console.error(`hyper-scope: $async("${name}") 실행 중 오류`);
|
|
2617
|
+
console.error(error);
|
|
2618
|
+
}
|
|
2619
|
+
settle(state, controller, "rejected", error);
|
|
2620
|
+
return state;
|
|
2621
|
+
});
|
|
2622
|
+
return state;
|
|
2623
|
+
} finally {
|
|
2624
|
+
resetTracking();
|
|
2625
|
+
}
|
|
2626
|
+
};
|
|
2627
|
+
var abortAsyncs = (reg) => {
|
|
2628
|
+
const map = toRaw(reg.map);
|
|
2629
|
+
for (const name of Object.keys(map)) {
|
|
2630
|
+
const raw = toRaw(map[name]);
|
|
2631
|
+
controllers.get(raw)?.abort();
|
|
2632
|
+
controllers.delete(raw);
|
|
2633
|
+
}
|
|
2634
|
+
};
|
|
2635
|
+
var asyncHelpers = (reg, self2) => ({
|
|
2636
|
+
$async: (name, ...rest) => {
|
|
2637
|
+
if (!validName(name))
|
|
2638
|
+
return createAsyncState();
|
|
2639
|
+
return rest.length ? runAsync(reg, self2(), name, rest[0], rest[1]) : readAsync(reg, name);
|
|
2640
|
+
},
|
|
2641
|
+
$await: (name, cb) => {
|
|
2642
|
+
if (typeof cb !== "function") {
|
|
2643
|
+
console.error(`hyper-scope: $await("${String(name)}", 콜백) — 콜백이 필요합니다. 상태 객체는 $async("${String(name)}") 로 읽습니다.`);
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
if (!validName(name))
|
|
2647
|
+
return;
|
|
2648
|
+
return cb(readAsync(reg, name));
|
|
2649
|
+
}
|
|
2650
|
+
});
|
|
2651
|
+
|
|
2652
|
+
// src/scope.ts
|
|
2653
|
+
var readProps = (el) => {
|
|
2654
|
+
const raw = el.getAttribute("h-props");
|
|
2655
|
+
if (raw == null)
|
|
2656
|
+
return {};
|
|
2657
|
+
el.removeAttribute("h-props");
|
|
2658
|
+
try {
|
|
2659
|
+
return raw.trim() ? JSON.parse(raw) : {};
|
|
2660
|
+
} catch (e) {
|
|
2661
|
+
console.error(`hyper-scope: h-props 가 JSON 이 아닙니다: ${raw}`);
|
|
2662
|
+
console.error(e);
|
|
2663
|
+
return {};
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
var names = (tokens) => tokens.trim().split(/\s+/).filter(Boolean);
|
|
2667
|
+
var readonly2 = (what, key) => () => console.error(`hyper-scope: ${what} "${key}" 에는 값을 넣을 수 없습니다(읽기 전용).`);
|
|
2668
|
+
var views = new WeakMap;
|
|
2669
|
+
var readonlyView = (target, what, deep = true) => {
|
|
2670
|
+
let view = deep ? views.get(target) : undefined;
|
|
2671
|
+
if (view)
|
|
2672
|
+
return view;
|
|
2673
|
+
const refuse = (key) => {
|
|
2674
|
+
console.error(`hyper-scope: ${what} "${String(key)}" 에는 값을 넣을 수 없습니다(읽기 전용).`);
|
|
2675
|
+
return true;
|
|
2676
|
+
};
|
|
2677
|
+
view = new Proxy(target, {
|
|
2678
|
+
get(t, key) {
|
|
2679
|
+
if (key === "__v_skip")
|
|
2680
|
+
return true;
|
|
2681
|
+
const value = Reflect.get(t, key, t);
|
|
2682
|
+
return deep && value !== null && typeof value === "object" && typeof key !== "symbol" ? readonlyView(value, what) : value;
|
|
2683
|
+
},
|
|
2684
|
+
set: (_t, key) => refuse(key),
|
|
2685
|
+
deleteProperty: (_t, key) => refuse(key),
|
|
2686
|
+
defineProperty: (_t, key) => refuse(key)
|
|
2687
|
+
});
|
|
2688
|
+
if (deep)
|
|
2689
|
+
views.set(target, view);
|
|
2690
|
+
return view;
|
|
2691
|
+
};
|
|
2692
|
+
var injectInto = (scope, tokens, provides) => {
|
|
2693
|
+
const linked = {};
|
|
2694
|
+
for (const key of names(tokens)) {
|
|
2695
|
+
linked[key] = { get: () => provides[key], set: readonly2("h-inject 로 받은", key) };
|
|
2696
|
+
}
|
|
2697
|
+
defineScopeHelpers(scope, linked);
|
|
2698
|
+
};
|
|
2699
|
+
var provideRE = /^h-provide:(.+)$/;
|
|
2700
|
+
var computedRE = /^h-computed:(.+)$/;
|
|
2701
|
+
var applyProvides = (el, ctx, keep = false) => {
|
|
2702
|
+
let out;
|
|
2703
|
+
for (const { name, value } of [...el.attributes]) {
|
|
2704
|
+
if (name === "h-provide") {
|
|
2705
|
+
console.error(`hyper-scope: h-provide 는 이름이 필요합니다 — h-provide:이름="식"`);
|
|
2706
|
+
keep || el.removeAttribute(name);
|
|
2707
|
+
continue;
|
|
2708
|
+
}
|
|
2709
|
+
const m = name.match(provideRE);
|
|
2710
|
+
if (!m)
|
|
2711
|
+
continue;
|
|
2712
|
+
keep || el.removeAttribute(name);
|
|
2713
|
+
out ||= { ...ctx, provides: Object.create(ctx.provides) };
|
|
2714
|
+
const scope = ctx.scope;
|
|
2715
|
+
const value$ = computed(() => evaluate(scope, value, el));
|
|
2716
|
+
Object.defineProperty(out.provides, camelize(m[1]), {
|
|
2717
|
+
get: () => value$.value,
|
|
2718
|
+
enumerable: true,
|
|
2719
|
+
configurable: true
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
return out || ctx;
|
|
2723
|
+
};
|
|
2724
|
+
var defineComputeds = (el, scope) => {
|
|
2725
|
+
const defs = {};
|
|
2726
|
+
for (const { name, value } of [...el.attributes]) {
|
|
2727
|
+
if (name === "h-computed") {
|
|
2728
|
+
console.error(`hyper-scope: h-computed 는 이름이 필요합니다 — h-computed:이름="식". 값 없이 일을 하려면 h-effect 를 씁니다.`);
|
|
2729
|
+
el.removeAttribute(name);
|
|
2730
|
+
continue;
|
|
2731
|
+
}
|
|
2732
|
+
const m = name.match(computedRE);
|
|
2733
|
+
if (!m)
|
|
2734
|
+
continue;
|
|
2735
|
+
el.removeAttribute(name);
|
|
2736
|
+
const key = camelize(m[1]);
|
|
2737
|
+
const value$ = computed(() => evaluate(scope, value, el));
|
|
2738
|
+
defs[key] = { get: () => value$.value, set: readonly2("h-computed 의", key) };
|
|
2739
|
+
}
|
|
2740
|
+
const any = Object.keys(defs).length > 0;
|
|
2741
|
+
if (any)
|
|
2742
|
+
defineScopeHelpers(scope, defs);
|
|
2743
|
+
return any;
|
|
2744
|
+
};
|
|
2745
|
+
var hasComputeds = (el) => {
|
|
2746
|
+
for (const { name } of el.attributes)
|
|
2747
|
+
if (name.startsWith("h-computed"))
|
|
2748
|
+
return true;
|
|
2749
|
+
return false;
|
|
2750
|
+
};
|
|
2751
|
+
var openScope = (el, parent, inherit, inject) => {
|
|
2752
|
+
const parentScope = parent.scope;
|
|
2753
|
+
const own = createContext(parent);
|
|
2754
|
+
const ctx = createScopedContext({ ...own, scope: rootScopeOf(parentScope) }, {}, true);
|
|
2755
|
+
let dead = false;
|
|
2756
|
+
let sealed = false;
|
|
2757
|
+
const life = {
|
|
2758
|
+
ctx,
|
|
2759
|
+
teardown() {
|
|
2760
|
+
if (dead)
|
|
2761
|
+
return;
|
|
2762
|
+
dead = true;
|
|
2763
|
+
const siblings = parent.blocks;
|
|
2764
|
+
const i = siblings.indexOf(life);
|
|
2765
|
+
if (i > -1)
|
|
2766
|
+
siblings.splice(i, 1);
|
|
2767
|
+
[...ctx.blocks].forEach((child) => child.teardown());
|
|
2768
|
+
ctx.effects.forEach(stop);
|
|
2769
|
+
ctx.cleanups.forEach((fn) => fn());
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
parent.blocks.push(life);
|
|
2773
|
+
const scope = ctx.scope;
|
|
2774
|
+
const injectFrom = parent.provides;
|
|
2775
|
+
const provides = ctx.provides;
|
|
2776
|
+
const asyncs = ctx.asyncs = createAsyncRegistry();
|
|
2777
|
+
ctx.scopeState = createAsyncState("fulfilled");
|
|
2778
|
+
ctx.cleanups.push(() => abortAsyncs(asyncs));
|
|
2779
|
+
const helpers = asyncHelpers(asyncs, () => scope);
|
|
2780
|
+
if (inherit) {
|
|
2781
|
+
const linked = {};
|
|
2782
|
+
for (const key of names(inherit)) {
|
|
2783
|
+
linked[key] = {
|
|
2784
|
+
get: () => parentScope[key],
|
|
2785
|
+
set: (v) => parentScope[key] = v,
|
|
2786
|
+
enumerable: true
|
|
2787
|
+
};
|
|
2788
|
+
}
|
|
2789
|
+
defineScopeHelpers(scope, linked);
|
|
2790
|
+
}
|
|
2791
|
+
if (inject)
|
|
2792
|
+
injectInto(scope, inject, injectFrom);
|
|
2793
|
+
const parentHost = parentScope.$host;
|
|
2794
|
+
const placed = parentHost ? markRaw({
|
|
2795
|
+
el: parentHost.el,
|
|
2796
|
+
get scope() {
|
|
2797
|
+
return parentScope;
|
|
2798
|
+
},
|
|
2799
|
+
get parent() {
|
|
2800
|
+
return parentHost.parent;
|
|
2801
|
+
},
|
|
2802
|
+
get sealed() {
|
|
2803
|
+
return parentHost.sealed;
|
|
2804
|
+
},
|
|
2805
|
+
seal: () => parentHost.seal()
|
|
2806
|
+
}) : null;
|
|
2807
|
+
const host = markRaw({
|
|
2808
|
+
el,
|
|
2809
|
+
get scope() {
|
|
2810
|
+
return scope;
|
|
2811
|
+
},
|
|
2812
|
+
get parent() {
|
|
2813
|
+
return placed;
|
|
2814
|
+
},
|
|
2815
|
+
get sealed() {
|
|
2816
|
+
return sealed;
|
|
2817
|
+
},
|
|
2818
|
+
seal() {
|
|
2819
|
+
if (sealed || dead)
|
|
2820
|
+
return;
|
|
2821
|
+
sealed = true;
|
|
2822
|
+
sealContext(ctx, () => life.teardown());
|
|
2823
|
+
ctx.hooks?.sealed(el);
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2826
|
+
defineScopeHelpers(scope, {
|
|
2827
|
+
$scope: { value: scope },
|
|
2828
|
+
$host: { value: host },
|
|
2829
|
+
$root: {
|
|
2830
|
+
get: () => {
|
|
2831
|
+
console.error(`hyper-scope: $root 는 없어졌습니다 — 스코프 요소는 $host.el 입니다.`);
|
|
2832
|
+
return el;
|
|
2833
|
+
}
|
|
2834
|
+
},
|
|
2835
|
+
$props: { value: readonlyView(readProps(el), "$props 의") },
|
|
2836
|
+
$emit: {
|
|
2837
|
+
value: (name, detail, bubbles = true) => el.dispatchEvent(new CustomEvent(name, { detail, bubbles, cancelable: true }))
|
|
2838
|
+
},
|
|
2839
|
+
$dispatch: {
|
|
2840
|
+
value: (target, name, detail = null, bubbles = true) => dispatchTo(target, name, detail, bubbles)
|
|
2841
|
+
},
|
|
2842
|
+
$handle: {
|
|
2843
|
+
value: (target, name, detail = null) => dispatchTo(target, name, detail, false)
|
|
2844
|
+
},
|
|
2845
|
+
$provide: {
|
|
2846
|
+
value: (key, value) => {
|
|
2847
|
+
provides[key] = value;
|
|
2848
|
+
return value;
|
|
2849
|
+
}
|
|
2850
|
+
},
|
|
2851
|
+
$inject: {
|
|
2852
|
+
value: (key, fallback) => (key in injectFrom) ? injectFrom[key] : fallback
|
|
2853
|
+
},
|
|
2854
|
+
$async: { value: helpers.$async },
|
|
2855
|
+
$await: { value: helpers.$await }
|
|
2856
|
+
});
|
|
2857
|
+
const scoped = parent.scoped;
|
|
2858
|
+
if (scoped) {
|
|
2859
|
+
const defs = {};
|
|
2860
|
+
for (const name of Object.keys(scoped))
|
|
2861
|
+
defs[name] = { get: () => scoped[name](host) };
|
|
2862
|
+
defineScopeHelpers(scope, defs);
|
|
2863
|
+
}
|
|
2864
|
+
return ctx;
|
|
2865
|
+
};
|
|
2866
|
+
var scopeValue = (el, exp, ctx) => {
|
|
2867
|
+
const scope = ctx.scope;
|
|
2868
|
+
const value = exp ? evaluate(scope, exp, el) : undefined;
|
|
2869
|
+
if (typeof value !== "function")
|
|
2870
|
+
return value;
|
|
2871
|
+
const es = effectScope();
|
|
2872
|
+
ctx.cleanups.push(() => es.stop());
|
|
2873
|
+
const tools = {
|
|
2874
|
+
ref,
|
|
2875
|
+
computed,
|
|
2876
|
+
reactive,
|
|
2877
|
+
effect: ctx.effect,
|
|
2878
|
+
nextTick,
|
|
2879
|
+
props: scope.$props,
|
|
2880
|
+
emit: scope.$emit,
|
|
2881
|
+
provide: scope.$provide,
|
|
2882
|
+
inject: scope.$inject,
|
|
2883
|
+
host: scope.$host,
|
|
2884
|
+
scope,
|
|
2885
|
+
$async: scope.$async,
|
|
2886
|
+
$await: scope.$await
|
|
2887
|
+
};
|
|
2888
|
+
return es.run(() => value.call(scope, tools));
|
|
2889
|
+
};
|
|
2890
|
+
var isThenable = (v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
|
|
2891
|
+
var held = new WeakSet;
|
|
2892
|
+
var holdScope = (el) => held.add(el);
|
|
2893
|
+
var releaseScope = (el) => held.delete(el);
|
|
2894
|
+
var isHeldScope = (el) => held.has(el);
|
|
2895
|
+
var dispatchTo = (target, name, detail, bubbles) => {
|
|
2896
|
+
const to = typeof target === "string" ? document.querySelector(target) : target;
|
|
2897
|
+
if (!to) {
|
|
2898
|
+
DEV && console.warn(`hyper-scope: 이벤트 ${name} 을 받을 요소가 없습니다: ${String(target)}`);
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
2901
|
+
to.dispatchEvent(new CustomEvent(name, { detail, bubbles, cancelable: true }));
|
|
2902
|
+
return to;
|
|
2903
|
+
};
|
|
2904
|
+
var scriptCache = Object.create(null);
|
|
2905
|
+
var compileScript = (src) => {
|
|
2906
|
+
try {
|
|
2907
|
+
return new Function("$data", "$el", `with($data){${src}
|
|
2908
|
+
}`);
|
|
2909
|
+
} catch (e) {
|
|
2910
|
+
console.error(`hyper-scope: <script type="scope"> 를 읽지 못했습니다.`);
|
|
2911
|
+
console.error(e);
|
|
2912
|
+
return () => {};
|
|
2913
|
+
}
|
|
2914
|
+
};
|
|
2915
|
+
var isScopeScript = (el) => el.tagName === "SCRIPT" && el.getAttribute("type") === "scope";
|
|
2916
|
+
var runScopeScripts = (el, ctx) => {
|
|
2917
|
+
let es;
|
|
2918
|
+
for (const child of [...el.children]) {
|
|
2919
|
+
if (!isScopeScript(child))
|
|
2920
|
+
continue;
|
|
2921
|
+
const src = child.textContent || "";
|
|
2922
|
+
const fn = scriptCache[src] || (scriptCache[src] = compileScript(src));
|
|
2923
|
+
let result;
|
|
2924
|
+
try {
|
|
2925
|
+
if (!es) {
|
|
2926
|
+
const made = es = effectScope();
|
|
2927
|
+
ctx.cleanups.push(() => made.stop());
|
|
2928
|
+
}
|
|
2929
|
+
result = es.run(() => fn.call(ctx.scope, ctx.scope, el));
|
|
2930
|
+
} catch (e) {
|
|
2931
|
+
console.error(`hyper-scope: <script type="scope"> 실행 중 오류`);
|
|
2932
|
+
console.error(e);
|
|
2933
|
+
continue;
|
|
2934
|
+
}
|
|
2935
|
+
if (result && typeof result === "object")
|
|
2936
|
+
declareInScope(ctx.scope, result);
|
|
2937
|
+
}
|
|
2938
|
+
};
|
|
2939
|
+
var openState = (el, exp, parent) => {
|
|
2940
|
+
const ctx = createScopedContext(parent, {}, true);
|
|
2941
|
+
const scope = ctx.scope;
|
|
2942
|
+
const asyncs = ctx.asyncs = createAsyncRegistry(parent.asyncs);
|
|
2943
|
+
ctx.cleanups.push(() => abortAsyncs(asyncs));
|
|
2944
|
+
const helpers = asyncHelpers(asyncs, () => scope);
|
|
2945
|
+
defineScopeHelpers(scope, {
|
|
2946
|
+
$async: { value: helpers.$async },
|
|
2947
|
+
$await: { value: helpers.$await }
|
|
2948
|
+
});
|
|
2949
|
+
const data = exp ? evaluate(scope, exp, el) : undefined;
|
|
2950
|
+
if (data && typeof data === "object")
|
|
2951
|
+
declareInScope(scope, data);
|
|
2952
|
+
else if (exp.trim() && data !== undefined) {
|
|
2953
|
+
console.error(`hyper-scope: h-state 는 객체를 받습니다: ${exp}`);
|
|
2954
|
+
}
|
|
2955
|
+
return ctx;
|
|
2956
|
+
};
|
|
2957
|
+
|
|
2958
|
+
// src/component.ts
|
|
2959
|
+
var registry = new Map;
|
|
2960
|
+
var mounted = new WeakSet;
|
|
2961
|
+
var typeOfValue = (v) => typeof v === "number" ? Number : typeof v === "boolean" ? Boolean : typeof v === "string" ? String : Array.isArray(v) ? Array : v && typeof v === "object" ? Object : undefined;
|
|
2962
|
+
var normalizeProps = (props) => {
|
|
2963
|
+
const out = {};
|
|
2964
|
+
if (Array.isArray(props)) {
|
|
2965
|
+
for (const name of props)
|
|
2966
|
+
out[camelize(name)] = { type: String };
|
|
2967
|
+
return out;
|
|
2968
|
+
}
|
|
2969
|
+
for (const [name, decl] of Object.entries(props || {})) {
|
|
2970
|
+
const full = decl && typeof decl === "object" && !Array.isArray(decl) && (("type" in decl) || ("default" in decl));
|
|
2971
|
+
out[camelize(name)] = full ? { type: decl.type || typeOfValue(decl.default), default: decl.default } : { type: typeOfValue(decl), default: decl };
|
|
2972
|
+
}
|
|
2973
|
+
return out;
|
|
2974
|
+
};
|
|
2975
|
+
var defaultOf = (p2) => {
|
|
2976
|
+
const d = p2.default;
|
|
2977
|
+
if (typeof d === "function" && p2.type !== Function)
|
|
2978
|
+
return d();
|
|
2979
|
+
if (d && typeof d === "object")
|
|
2980
|
+
return JSON.parse(JSON.stringify(d));
|
|
2981
|
+
return d;
|
|
2982
|
+
};
|
|
2983
|
+
var convert = (raw, type) => {
|
|
2984
|
+
if (type === Number) {
|
|
2985
|
+
const n = Number(raw);
|
|
2986
|
+
return raw.trim() === "" || Number.isNaN(n) ? raw : n;
|
|
2987
|
+
}
|
|
2988
|
+
if (type === Boolean)
|
|
2989
|
+
return raw !== "false";
|
|
2990
|
+
if (type === Array || type === Object) {
|
|
2991
|
+
try {
|
|
2992
|
+
return JSON.parse(raw);
|
|
2993
|
+
} catch {
|
|
2994
|
+
return raw;
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
return raw;
|
|
2998
|
+
};
|
|
2999
|
+
var toTemplate = (src) => {
|
|
3000
|
+
if (typeof src !== "string")
|
|
3001
|
+
return src;
|
|
3002
|
+
if (src[0] === "#") {
|
|
3003
|
+
const found = document.querySelector(src);
|
|
3004
|
+
if (!(found instanceof HTMLTemplateElement)) {
|
|
3005
|
+
DEV && console.error(`hyper-scope: 컴포넌트 템플릿 ${src} 에 맞는 <template> 이 없습니다.`);
|
|
3006
|
+
return;
|
|
3007
|
+
}
|
|
3008
|
+
return found;
|
|
3009
|
+
}
|
|
3010
|
+
const t = document.createElement("template");
|
|
3011
|
+
t.innerHTML = src;
|
|
3012
|
+
return t;
|
|
3013
|
+
};
|
|
3014
|
+
var defineComponent = (name, def2) => {
|
|
3015
|
+
const tag = name.toLowerCase();
|
|
3016
|
+
if (!tag.includes("-")) {
|
|
3017
|
+
DEV && console.error(`hyper-scope: 컴포넌트 이름에는 하이픈이 있어야 합니다: ${name}`);
|
|
3018
|
+
return;
|
|
3019
|
+
}
|
|
3020
|
+
dropStyles(registry.get(tag));
|
|
3021
|
+
registry.set(tag, { def: def2, props: normalizeProps(def2.props) });
|
|
3022
|
+
};
|
|
3023
|
+
var dropStyles = (reg) => {
|
|
3024
|
+
for (const el of reg?.styles || [])
|
|
3025
|
+
el.parentNode?.removeChild(el);
|
|
3026
|
+
};
|
|
3027
|
+
var clearComponents = () => {
|
|
3028
|
+
for (const reg of registry.values())
|
|
3029
|
+
dropStyles(reg);
|
|
3030
|
+
registry.clear();
|
|
3031
|
+
};
|
|
3032
|
+
var installStyles = (tag, reg) => {
|
|
3033
|
+
if (!reg.styles) {
|
|
3034
|
+
const styles = reg.styles = [];
|
|
3035
|
+
const canScope = typeof globalThis.CSSScopeRule !== "undefined";
|
|
3036
|
+
const add = (css, scoped) => {
|
|
3037
|
+
if (!css.trim())
|
|
3038
|
+
return;
|
|
3039
|
+
const el = document.createElement("style");
|
|
3040
|
+
el.setAttribute("data-h-component", tag);
|
|
3041
|
+
el.textContent = scoped && canScope ? `@scope (${tag}) {
|
|
3042
|
+
${css}
|
|
3043
|
+
}` : css;
|
|
3044
|
+
styles.push(el);
|
|
3045
|
+
};
|
|
3046
|
+
for (const style of reg.template?.content.querySelectorAll("style") || []) {
|
|
3047
|
+
reg.inlineStyles = true;
|
|
3048
|
+
add(style.textContent || "", style.hasAttribute("scoped"));
|
|
3049
|
+
}
|
|
3050
|
+
const own = reg.def.style;
|
|
3051
|
+
if (typeof own === "string")
|
|
3052
|
+
add(own, false);
|
|
3053
|
+
else if (own)
|
|
3054
|
+
add(own.css, !!own.scoped);
|
|
3055
|
+
}
|
|
3056
|
+
for (const el of reg.styles)
|
|
3057
|
+
el.isConnected || document.head.appendChild(el);
|
|
3058
|
+
};
|
|
3059
|
+
var registerTemplates = (root) => {
|
|
3060
|
+
const found = [];
|
|
3061
|
+
if (root instanceof HTMLTemplateElement && root.hasAttribute("h-component"))
|
|
3062
|
+
found.push(root);
|
|
3063
|
+
root.querySelectorAll?.("template[h-component]").forEach((t) => found.push(t));
|
|
3064
|
+
for (const t of found) {
|
|
3065
|
+
const name = t.getAttribute("h-component");
|
|
3066
|
+
let props = {};
|
|
3067
|
+
const raw = t.getAttribute("h-props");
|
|
3068
|
+
if (raw && raw.trim()) {
|
|
3069
|
+
try {
|
|
3070
|
+
props = JSON.parse(raw);
|
|
3071
|
+
} catch (e) {
|
|
3072
|
+
console.error(`hyper-scope: <template h-component="${name}"> 의 h-props 가 JSON 이 아닙니다.`);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
defineComponent(name, { props, template: t });
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
var isComponentHost = (el) => registry.has(el.localName);
|
|
3079
|
+
var isPendingUnit = (el) => el.hasAttribute("h-scope") || isComponentHost(el) && !mounted.has(el) || isHeldScope(el);
|
|
3080
|
+
var unitSelector = () => ["[h-scope]", ...registry.keys()].join(",");
|
|
3081
|
+
var takeSlots = (host) => {
|
|
3082
|
+
const slots = Object.create(null);
|
|
3083
|
+
const put = (name, nodes) => (slots[name] ||= []).push(...nodes);
|
|
3084
|
+
for (const node of [...host.childNodes]) {
|
|
3085
|
+
host.removeChild(node);
|
|
3086
|
+
if (node.nodeType === 1) {
|
|
3087
|
+
const el = node;
|
|
3088
|
+
const name = el.getAttribute("slot");
|
|
3089
|
+
if (name) {
|
|
3090
|
+
el.removeAttribute("slot");
|
|
3091
|
+
if (el instanceof HTMLTemplateElement)
|
|
3092
|
+
put(name, [...el.content.childNodes]);
|
|
3093
|
+
else
|
|
3094
|
+
put(name, [el]);
|
|
3095
|
+
continue;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
put("default", [node]);
|
|
3099
|
+
}
|
|
3100
|
+
if (slots.default && slots.default.every((n) => n.nodeType === 3 && !n.textContent.trim())) {
|
|
3101
|
+
delete slots.default;
|
|
3102
|
+
}
|
|
3103
|
+
return slots;
|
|
3104
|
+
};
|
|
3105
|
+
var findSlots = (root, out = []) => {
|
|
3106
|
+
for (const el of root.querySelectorAll("slot, template")) {
|
|
3107
|
+
if (el instanceof HTMLTemplateElement)
|
|
3108
|
+
findSlots(el.content, out);
|
|
3109
|
+
else
|
|
3110
|
+
out.push(el);
|
|
3111
|
+
}
|
|
3112
|
+
return out;
|
|
3113
|
+
};
|
|
3114
|
+
var fillSlots = (frag, slots, parentCtx, readText) => {
|
|
3115
|
+
const slotCtx = readText ? { ...parentCtx, mustache: true } : parentCtx;
|
|
3116
|
+
for (const slot of findSlots(frag)) {
|
|
3117
|
+
const name = slot.getAttribute("name") || "default";
|
|
3118
|
+
const given = slots[name];
|
|
3119
|
+
const parent = slot.parentNode;
|
|
3120
|
+
if (given) {
|
|
3121
|
+
for (const node of given) {
|
|
3122
|
+
recordSlotContext(node, slotCtx);
|
|
3123
|
+
if (node.nodeType === 1)
|
|
3124
|
+
recordContext(node, parentCtx);
|
|
3125
|
+
parent.insertBefore(node, slot);
|
|
3126
|
+
}
|
|
3127
|
+
delete slots[name];
|
|
3128
|
+
} else {
|
|
3129
|
+
while (slot.firstChild)
|
|
3130
|
+
parent.insertBefore(slot.firstChild, slot);
|
|
3131
|
+
}
|
|
3132
|
+
parent.removeChild(slot);
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
var attrFor = (key, host) => {
|
|
3136
|
+
const kebab = hyphenate(key);
|
|
3137
|
+
if (host.hasAttribute(kebab))
|
|
3138
|
+
return host.getAttribute(kebab);
|
|
3139
|
+
const lower = key.toLowerCase();
|
|
3140
|
+
if (host.hasAttribute(lower))
|
|
3141
|
+
return host.getAttribute(lower);
|
|
3142
|
+
return null;
|
|
3143
|
+
};
|
|
3144
|
+
var dirRE = /^(?:h-|:|@)/;
|
|
3145
|
+
var bindRE = /^(?::|h-bind:)([^.]+)/;
|
|
3146
|
+
var mountComponent = (host, parentCtx) => {
|
|
3147
|
+
const reg = registry.get(host.localName);
|
|
3148
|
+
if (!reg || mounted.has(host))
|
|
3149
|
+
return;
|
|
3150
|
+
mounted.add(host);
|
|
3151
|
+
const { def: def2 } = reg;
|
|
3152
|
+
if (!reg.template)
|
|
3153
|
+
reg.template = toTemplate(def2.template);
|
|
3154
|
+
installStyles(host.localName, reg);
|
|
3155
|
+
if (host.hasAttribute("h-scope")) {
|
|
3156
|
+
DEV && console.warn(`hyper-scope: 컴포넌트 태그 <${host.localName}> 에는 h-scope 를 쓰지 않습니다.`);
|
|
3157
|
+
host.removeAttribute("h-scope");
|
|
3158
|
+
}
|
|
3159
|
+
const declared = reg.props;
|
|
3160
|
+
const initial = {};
|
|
3161
|
+
for (const [key, p2] of Object.entries(declared))
|
|
3162
|
+
initial[key] = defaultOf(p2);
|
|
3163
|
+
const json = host.getAttribute("h-props");
|
|
3164
|
+
if (json != null) {
|
|
3165
|
+
host.removeAttribute("h-props");
|
|
3166
|
+
try {
|
|
3167
|
+
if (json.trim())
|
|
3168
|
+
Object.assign(initial, JSON.parse(json));
|
|
3169
|
+
} catch (e) {
|
|
3170
|
+
console.error(`hyper-scope: <${host.localName}> 의 h-props 가 JSON 이 아닙니다: ${json}`);
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
for (const [key, p2] of Object.entries(declared)) {
|
|
3174
|
+
const raw = attrFor(key, host);
|
|
3175
|
+
if (raw != null)
|
|
3176
|
+
initial[key] = convert(raw, p2.type);
|
|
3177
|
+
}
|
|
3178
|
+
const props = reactive(initial);
|
|
3179
|
+
const isProp = (key) => hasOwn(declared, key) || hasOwn(initial, key);
|
|
3180
|
+
const watched = new Map;
|
|
3181
|
+
for (const key of Object.keys(declared)) {
|
|
3182
|
+
watched.set(hyphenate(key), key);
|
|
3183
|
+
watched.set(key.toLowerCase(), key);
|
|
3184
|
+
}
|
|
3185
|
+
const attrObserver = new MutationObserver((records) => {
|
|
3186
|
+
for (const r of records) {
|
|
3187
|
+
const key = watched.get(r.attributeName);
|
|
3188
|
+
if (!key)
|
|
3189
|
+
continue;
|
|
3190
|
+
const raw = host.getAttribute(r.attributeName);
|
|
3191
|
+
props[key] = raw == null ? defaultOf(declared[key]) : convert(raw, declared[key].type);
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
attrObserver.observe(host, { attributes: true, attributeFilter: [...watched.keys()] });
|
|
3195
|
+
parentCtx.cleanups.push(() => attrObserver.disconnect());
|
|
3196
|
+
const bridged = [];
|
|
3197
|
+
for (const key of Object.keys(declared)) {
|
|
3198
|
+
if (key in host)
|
|
3199
|
+
continue;
|
|
3200
|
+
Object.defineProperty(host, key, {
|
|
3201
|
+
configurable: true,
|
|
3202
|
+
enumerable: true,
|
|
3203
|
+
get: () => props[key],
|
|
3204
|
+
set: (value) => {
|
|
3205
|
+
props[key] = value;
|
|
3206
|
+
}
|
|
3207
|
+
});
|
|
3208
|
+
bridged.push(key);
|
|
3209
|
+
}
|
|
3210
|
+
parentCtx.cleanups.push(() => {
|
|
3211
|
+
for (const key of bridged)
|
|
3212
|
+
delete host[key];
|
|
3213
|
+
});
|
|
3214
|
+
const deferred = [];
|
|
3215
|
+
for (const { name, value } of [...host.attributes]) {
|
|
3216
|
+
if (!dirRE.test(name) || name === "h-cloak" || name === "h-text-inline")
|
|
3217
|
+
continue;
|
|
3218
|
+
const bound = name.match(bindRE);
|
|
3219
|
+
if (bound && isProp(camelize(bound[1]))) {
|
|
3220
|
+
const key = camelize(bound[1]);
|
|
3221
|
+
host.removeAttribute(name);
|
|
3222
|
+
parentCtx.effect(() => {
|
|
3223
|
+
props[key] = evaluate(parentCtx.scope, value, host);
|
|
3224
|
+
});
|
|
3225
|
+
continue;
|
|
3226
|
+
}
|
|
3227
|
+
if (name === "h-model" || name.startsWith("h-model.")) {
|
|
3228
|
+
host.removeAttribute(name);
|
|
3229
|
+
const prop = def2.model?.prop || "value";
|
|
3230
|
+
const event = def2.model?.event || "input";
|
|
3231
|
+
const assign = evaluate(parentCtx.scope, `(val) => { ${value} = val }`, host);
|
|
3232
|
+
const readModel = () => evaluate(parentCtx.scope, value, host);
|
|
3233
|
+
const pass = () => {
|
|
3234
|
+
props[prop] = readModel();
|
|
3235
|
+
};
|
|
3236
|
+
parentCtx.effect(pass);
|
|
3237
|
+
attachModel(host, readModel, assign, pass);
|
|
3238
|
+
const onEmit = (e) => {
|
|
3239
|
+
if (e instanceof CustomEvent && e.target === host)
|
|
3240
|
+
assign(e.detail);
|
|
3241
|
+
};
|
|
3242
|
+
host.addEventListener(event, onEmit);
|
|
3243
|
+
parentCtx.cleanups.push(() => host.removeEventListener(event, onEmit));
|
|
3244
|
+
continue;
|
|
3245
|
+
}
|
|
3246
|
+
if (name === "ref" || name === "h-keep" || name === "h-inject")
|
|
3247
|
+
continue;
|
|
3248
|
+
if (name[0] === "@" || name.startsWith("h-on"))
|
|
3249
|
+
deferred.push([name, value]);
|
|
3250
|
+
else
|
|
3251
|
+
processDirective(host, name, value, parentCtx);
|
|
3252
|
+
}
|
|
3253
|
+
for (const [name, value] of deferred)
|
|
3254
|
+
processDirective(host, name, value, parentCtx);
|
|
3255
|
+
const refName = host.getAttribute("ref");
|
|
3256
|
+
if (refName) {
|
|
3257
|
+
host.removeAttribute("ref");
|
|
3258
|
+
processDirective(host, ":ref", JSON.stringify(refName), parentCtx);
|
|
3259
|
+
}
|
|
3260
|
+
const inject = host.getAttribute("h-inject");
|
|
3261
|
+
host.removeAttribute("h-inject");
|
|
3262
|
+
const ctx = openScope(host, {
|
|
3263
|
+
...parentCtx,
|
|
3264
|
+
scope: rootScopeOf(parentCtx.scope),
|
|
3265
|
+
asyncs: undefined
|
|
3266
|
+
}, null, inject);
|
|
3267
|
+
const scope = ctx.scope;
|
|
3268
|
+
const view = readonlyView(props, "props 로 받은", false);
|
|
3269
|
+
const propGetters = {};
|
|
3270
|
+
for (const key of Object.keys(initial)) {
|
|
3271
|
+
propGetters[key] = {
|
|
3272
|
+
get: () => view[key],
|
|
3273
|
+
set: () => console.error(`hyper-scope: props 로 받은 "${key}" 에는 값을 넣을 수 없습니다(읽기 전용) — $emit 으로 알립니다.`),
|
|
3274
|
+
enumerable: true
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
defineScopeHelpers(scope, { $props: { value: view }, ...propGetters });
|
|
3278
|
+
recordContext(host, ctx);
|
|
3279
|
+
const readsHostText = takeMustache(host);
|
|
3280
|
+
const slots = takeSlots(host);
|
|
3281
|
+
if (reg.template) {
|
|
3282
|
+
const frag = reg.template.content.cloneNode(true);
|
|
3283
|
+
if (reg.inlineStyles) {
|
|
3284
|
+
for (const s of [...frag.querySelectorAll("style")])
|
|
3285
|
+
s.parentNode.removeChild(s);
|
|
3286
|
+
}
|
|
3287
|
+
fillSlots(frag, slots, parentCtx, readsHostText);
|
|
3288
|
+
host.appendChild(frag);
|
|
3289
|
+
}
|
|
3290
|
+
const mountedHooks = [];
|
|
3291
|
+
const es = effectScope();
|
|
3292
|
+
parentCtx.cleanups.push(() => es.stop());
|
|
3293
|
+
if (def2.setup) {
|
|
3294
|
+
const setupCtx = {
|
|
3295
|
+
host: scope.$host,
|
|
3296
|
+
emit: scope.$emit,
|
|
3297
|
+
provide: scope.$provide,
|
|
3298
|
+
inject: scope.$inject,
|
|
3299
|
+
onMounted: (fn) => mountedHooks.push(fn),
|
|
3300
|
+
onUnmounted: (fn) => parentCtx.cleanups.push(() => isSealing() || fn()),
|
|
3301
|
+
onSealed: (fn) => ctx.sealers.push(fn),
|
|
3302
|
+
scope
|
|
3303
|
+
};
|
|
3304
|
+
let result;
|
|
3305
|
+
try {
|
|
3306
|
+
result = es.run(() => def2.setup.call(scope, view, setupCtx));
|
|
3307
|
+
} catch (e) {
|
|
3308
|
+
console.error(`hyper-scope: <${host.localName}> setup 중 오류`);
|
|
3309
|
+
console.error(e);
|
|
3310
|
+
}
|
|
3311
|
+
if (result && typeof result === "object")
|
|
3312
|
+
declareInScope(scope, result);
|
|
3313
|
+
}
|
|
3314
|
+
es.run(() => runScopeScripts(host, ctx));
|
|
3315
|
+
ctx.hooks?.scope(host, ctx);
|
|
3316
|
+
walkChildren(host, ctx);
|
|
3317
|
+
if (mountedHooks.length)
|
|
3318
|
+
nextTick(() => mountedHooks.forEach((fn) => fn()));
|
|
3319
|
+
};
|
|
3320
|
+
var hasPendingAncestor = (el) => {
|
|
3321
|
+
for (let cur = el.parentElement;cur; cur = cur.parentElement) {
|
|
3322
|
+
if (isPendingUnit(cur))
|
|
3323
|
+
return true;
|
|
3324
|
+
}
|
|
3325
|
+
return false;
|
|
3326
|
+
};
|
|
3327
|
+
|
|
3328
|
+
// src/directives/await.ts
|
|
3329
|
+
var SCOPE = "$scope";
|
|
3330
|
+
var parseAwait = (exp) => {
|
|
3331
|
+
const tokens = [];
|
|
3332
|
+
for (const part of exp.trim().split(/\s+/)) {
|
|
3333
|
+
if (!part)
|
|
3334
|
+
continue;
|
|
3335
|
+
const i = part.indexOf(":");
|
|
3336
|
+
const name = i < 0 ? part : part.slice(0, i);
|
|
3337
|
+
const status = i < 0 ? "pending" : part.slice(i + 1);
|
|
3338
|
+
if (!name || !asyncStatuses.includes(status)) {
|
|
3339
|
+
console.error(`hyper-scope: h-await 의 토큰을 읽지 못했습니다: ${part} ` + `(이름 또는 이름:상태 — 상태는 ${asyncStatuses.join(" · ")})`);
|
|
3340
|
+
continue;
|
|
3341
|
+
}
|
|
3342
|
+
tokens.push({ name, status });
|
|
3343
|
+
}
|
|
3344
|
+
return tokens.length || exp.trim() ? tokens : [{ name: SCOPE, status: "pending" }];
|
|
3345
|
+
};
|
|
3346
|
+
var awaitsScope = (exp) => exp != null && (!exp.trim() || exp.trim().split(/\s+/).some((t) => t === SCOPE || t.startsWith(SCOPE + ":")));
|
|
3347
|
+
var mounted2 = new WeakSet;
|
|
3348
|
+
var isAwaitMounted = (node) => mounted2.has(node);
|
|
3349
|
+
var _await = (el, exp, ctx, scopeState) => {
|
|
3350
|
+
const tokens = parseAwait(exp);
|
|
3351
|
+
const own = scopeState || ctx.scopeState;
|
|
3352
|
+
const usesScope = tokens.some((t) => t.name === SCOPE);
|
|
3353
|
+
const blockCtx = usesScope && own ? createScopedContext(ctx, {
|
|
3354
|
+
get $error() {
|
|
3355
|
+
return own.status === "rejected" ? own.value : undefined;
|
|
3356
|
+
}
|
|
3357
|
+
}) : ctx;
|
|
3358
|
+
const parent = el.parentNode;
|
|
3359
|
+
const anchor = new Comment("h-await");
|
|
3360
|
+
parent.insertBefore(anchor, el);
|
|
3361
|
+
const nextNode = el.nextSibling;
|
|
3362
|
+
parent.removeChild(el);
|
|
3363
|
+
let block;
|
|
3364
|
+
ctx.effect(() => {
|
|
3365
|
+
const show2 = tokens.some(({ name, status }) => name === SCOPE ? !!own && own.status === status : readAsync(ctx.asyncs, name).status === status);
|
|
3366
|
+
if (show2 && !block) {
|
|
3367
|
+
block = new Block(el, blockCtx);
|
|
3368
|
+
const nodes = block.isFragment ? [...block.template.childNodes] : [block.template];
|
|
3369
|
+
nodes.forEach((n) => mounted2.add(n));
|
|
3370
|
+
const host = anchor.parentNode;
|
|
3371
|
+
block.insert(host, anchor);
|
|
3372
|
+
if (block.start)
|
|
3373
|
+
mounted2.add(block.start), mounted2.add(block.end);
|
|
3374
|
+
host.removeChild(anchor);
|
|
3375
|
+
} else if (!show2 && block) {
|
|
3376
|
+
block.el.parentNode.insertBefore(anchor, block.el);
|
|
3377
|
+
block.remove();
|
|
3378
|
+
block = undefined;
|
|
3379
|
+
}
|
|
3380
|
+
});
|
|
3381
|
+
return nextNode;
|
|
3382
|
+
};
|
|
3383
|
+
|
|
3384
|
+
// src/walk.ts
|
|
3385
|
+
var dirRE2 = /^(?:h-|:|@)/;
|
|
3386
|
+
var modifierRE = /\.([\w-]+)/g;
|
|
3387
|
+
var splitSelectors = (list) => {
|
|
3388
|
+
const out = [];
|
|
3389
|
+
let depth = 0;
|
|
3390
|
+
let quote = "";
|
|
3391
|
+
let cur = "";
|
|
3392
|
+
for (const ch of list) {
|
|
3393
|
+
if (quote) {
|
|
3394
|
+
if (ch === quote)
|
|
3395
|
+
quote = "";
|
|
3396
|
+
} else if (ch === '"' || ch === "'")
|
|
3397
|
+
quote = ch;
|
|
3398
|
+
else if (ch === "(" || ch === "[")
|
|
3399
|
+
depth++;
|
|
3400
|
+
else if (ch === ")" || ch === "]")
|
|
3401
|
+
depth--;
|
|
3402
|
+
else if (ch === "," && depth === 0) {
|
|
3403
|
+
out.push(cur);
|
|
3404
|
+
cur = "";
|
|
3405
|
+
continue;
|
|
3406
|
+
}
|
|
3407
|
+
cur += ch;
|
|
3408
|
+
}
|
|
3409
|
+
out.push(cur);
|
|
3410
|
+
return out.map((s) => s.trim()).filter(Boolean);
|
|
3411
|
+
};
|
|
3412
|
+
var splitSteps = (raw) => {
|
|
3413
|
+
const steps = [];
|
|
3414
|
+
let depth = 0;
|
|
3415
|
+
let quote = "";
|
|
3416
|
+
let cur = "";
|
|
3417
|
+
let child = false;
|
|
3418
|
+
let gap = "";
|
|
3419
|
+
const flush = () => {
|
|
3420
|
+
if (!cur)
|
|
3421
|
+
return true;
|
|
3422
|
+
steps.push({ child, selector: cur });
|
|
3423
|
+
cur = "";
|
|
3424
|
+
return true;
|
|
3425
|
+
};
|
|
3426
|
+
for (let i = 0;i < raw.length; i++) {
|
|
3427
|
+
const ch = raw[i];
|
|
3428
|
+
if (quote) {
|
|
3429
|
+
if (ch === quote)
|
|
3430
|
+
quote = "";
|
|
3431
|
+
cur += ch;
|
|
3432
|
+
continue;
|
|
3433
|
+
}
|
|
3434
|
+
if (ch === '"' || ch === "'")
|
|
3435
|
+
quote = ch;
|
|
3436
|
+
else if (ch === "(" || ch === "[")
|
|
3437
|
+
depth++;
|
|
3438
|
+
else if (ch === ")" || ch === "]")
|
|
3439
|
+
depth--;
|
|
3440
|
+
if (depth === 0 && !quote && (ch === ">" || /\s/.test(ch))) {
|
|
3441
|
+
if (ch === ">") {
|
|
3442
|
+
if (gap === ">")
|
|
3443
|
+
return;
|
|
3444
|
+
gap = ">";
|
|
3445
|
+
} else if (!gap)
|
|
3446
|
+
gap = " ";
|
|
3447
|
+
continue;
|
|
3448
|
+
}
|
|
3449
|
+
if (gap) {
|
|
3450
|
+
const sibling = ch === "+" || ch === "~";
|
|
3451
|
+
const afterSibling = /[+~]$/.test(cur);
|
|
3452
|
+
if (gap === " " && (sibling || afterSibling)) {} else {
|
|
3453
|
+
if (gap === ">" && (sibling || afterSibling))
|
|
3454
|
+
return;
|
|
3455
|
+
flush();
|
|
3456
|
+
child = gap === ">";
|
|
3457
|
+
}
|
|
3458
|
+
gap = "";
|
|
3459
|
+
}
|
|
3460
|
+
cur += ch;
|
|
3461
|
+
}
|
|
3462
|
+
if (gap === ">")
|
|
3463
|
+
return;
|
|
3464
|
+
flush();
|
|
3465
|
+
return steps.length ? steps : undefined;
|
|
3466
|
+
};
|
|
3467
|
+
var canMatch = (selector) => {
|
|
3468
|
+
try {
|
|
3469
|
+
document.createElement("div").matches(selector);
|
|
3470
|
+
return true;
|
|
3471
|
+
} catch {
|
|
3472
|
+
return false;
|
|
3473
|
+
}
|
|
3474
|
+
};
|
|
3475
|
+
var parseMustache = (value) => {
|
|
3476
|
+
const parts = [];
|
|
3477
|
+
for (const raw of splitSelectors(value)) {
|
|
3478
|
+
let part;
|
|
3479
|
+
if (raw[0] === ">") {
|
|
3480
|
+
const steps = splitSteps(raw);
|
|
3481
|
+
if (steps && steps.every((s) => canMatch(s.selector)))
|
|
3482
|
+
part = { steps };
|
|
3483
|
+
} else if (canMatch(raw))
|
|
3484
|
+
part = { selector: raw };
|
|
3485
|
+
if (!part) {
|
|
3486
|
+
console.error(`hyper-scope: h-text-inline 의 선택자를 읽지 못했습니다: ${raw}`);
|
|
3487
|
+
return;
|
|
3488
|
+
}
|
|
3489
|
+
parts.push(part);
|
|
3490
|
+
}
|
|
3491
|
+
return parts;
|
|
3492
|
+
};
|
|
3493
|
+
var fillsText = (el) => el.hasAttribute("h-text") || el.hasAttribute("h-html");
|
|
3494
|
+
var isMustacheBoundary = (el) => fillsText(el) || el.hasAttribute("h-scope") || el.hasAttribute("h-pre") || isComponentHost(el) || isScopeScript(el) || el.localName === "template" && el.hasAttribute("h-component");
|
|
3495
|
+
var markMustache = (root, parts, active) => {
|
|
3496
|
+
for (const el of [...root.children]) {
|
|
3497
|
+
if (isMustacheBoundary(el))
|
|
3498
|
+
continue;
|
|
3499
|
+
if (el instanceof HTMLTemplateElement) {
|
|
3500
|
+
markMustache(el.content, parts, active);
|
|
3501
|
+
continue;
|
|
3502
|
+
}
|
|
3503
|
+
let hit = false;
|
|
3504
|
+
const next = parts.map((p2, pi) => {
|
|
3505
|
+
if (!p2.steps) {
|
|
3506
|
+
if (el.matches(p2.selector))
|
|
3507
|
+
hit = true;
|
|
3508
|
+
return [];
|
|
3509
|
+
}
|
|
3510
|
+
const out = [];
|
|
3511
|
+
for (const i of active[pi]) {
|
|
3512
|
+
const step = p2.steps[i];
|
|
3513
|
+
if (!step.child && !out.includes(i))
|
|
3514
|
+
out.push(i);
|
|
3515
|
+
if (el.matches(step.selector)) {
|
|
3516
|
+
if (i === p2.steps.length - 1)
|
|
3517
|
+
hit = true;
|
|
3518
|
+
else if (!out.includes(i + 1))
|
|
3519
|
+
out.push(i + 1);
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
return out;
|
|
3523
|
+
});
|
|
3524
|
+
if (hit && !el.hasAttribute("h-text-inline"))
|
|
3525
|
+
el.setAttribute("h-text-inline", "");
|
|
3526
|
+
markMustache(el, parts, next);
|
|
3527
|
+
}
|
|
3528
|
+
};
|
|
3529
|
+
var takeMustache = (el) => {
|
|
3530
|
+
const value = el.getAttribute("h-text-inline");
|
|
3531
|
+
if (value == null)
|
|
3532
|
+
return false;
|
|
3533
|
+
el.removeAttribute("h-text-inline");
|
|
3534
|
+
if (fillsText(el))
|
|
3535
|
+
return false;
|
|
3536
|
+
const v = value.trim();
|
|
3537
|
+
if (v === "false" || v === "0")
|
|
3538
|
+
return false;
|
|
3539
|
+
if (v && v !== "true") {
|
|
3540
|
+
const parts = parseMustache(v);
|
|
3541
|
+
if (parts)
|
|
3542
|
+
markMustache(el, parts, parts.map((p2) => p2.steps ? [0] : []));
|
|
3543
|
+
}
|
|
3544
|
+
return true;
|
|
3545
|
+
};
|
|
3546
|
+
var walk = (node, ctx, readText = false) => {
|
|
3547
|
+
const slotCtx = slotContextOf(node);
|
|
3548
|
+
if (slotCtx) {
|
|
3549
|
+
ctx = slotCtx;
|
|
3550
|
+
readText = !!slotCtx.mustache;
|
|
3551
|
+
}
|
|
3552
|
+
if (isAwaitMounted(node))
|
|
3553
|
+
return;
|
|
3554
|
+
const type = node.nodeType;
|
|
3555
|
+
if (type === 1) {
|
|
3556
|
+
const el = node;
|
|
3557
|
+
if (el.hasAttribute("h-pre")) {
|
|
3558
|
+
return;
|
|
3559
|
+
}
|
|
3560
|
+
if (isScopeScript(el)) {
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3563
|
+
if (el.localName === "template" && el.hasAttribute("h-component")) {
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
if (ctx.hooks && ctx.hooks.detached(el, ctx)) {
|
|
3567
|
+
return;
|
|
3568
|
+
}
|
|
3569
|
+
if (el.localName === "template" && el.hasAttribute("h-cloak")) {
|
|
3570
|
+
const next = el.nextSibling;
|
|
3571
|
+
const frag = el.content;
|
|
3572
|
+
const first = frag.firstChild;
|
|
3573
|
+
el.parentNode.replaceChild(frag, el);
|
|
3574
|
+
return first || next;
|
|
3575
|
+
}
|
|
3576
|
+
const isScope = el.hasAttribute("h-scope");
|
|
3577
|
+
if (!isScope)
|
|
3578
|
+
checkAttr(el, "h-cloak");
|
|
3579
|
+
let exp;
|
|
3580
|
+
if (exp = checkAttr(el, "h-if")) {
|
|
3581
|
+
return _if(el, exp, ctx);
|
|
3582
|
+
}
|
|
3583
|
+
if (exp = checkAttr(el, "h-for")) {
|
|
3584
|
+
return _for(el, exp, ctx);
|
|
3585
|
+
}
|
|
3586
|
+
if ((exp = checkAttr(el, "h-await")) != null) {
|
|
3587
|
+
return _await(el, exp, ctx);
|
|
3588
|
+
}
|
|
3589
|
+
const beforeProvide = ctx;
|
|
3590
|
+
ctx = applyProvides(el, ctx);
|
|
3591
|
+
const provided = ctx !== beforeProvide;
|
|
3592
|
+
if (isComponentHost(el)) {
|
|
3593
|
+
isScope && checkAttr(el, "h-cloak");
|
|
3594
|
+
return mountComponent(el, ctx);
|
|
3595
|
+
}
|
|
3596
|
+
if (isScope) {
|
|
3597
|
+
exp = checkAttr(el, "h-scope");
|
|
3598
|
+
const outer = ctx;
|
|
3599
|
+
const scopeCtx = ctx = openScope(el, ctx, checkAttr(el, "h-inherit"), checkAttr(el, "h-inject"));
|
|
3600
|
+
const state = scopeCtx.scopeState;
|
|
3601
|
+
const ready = (data) => {
|
|
3602
|
+
data = data && typeof data === "object" ? data : {};
|
|
3603
|
+
declareInScope(scopeCtx.scope, data);
|
|
3604
|
+
recordContext(el, scopeCtx);
|
|
3605
|
+
if (data.$template) {
|
|
3606
|
+
resolveTemplate(el, data.$template);
|
|
3607
|
+
}
|
|
3608
|
+
runScopeScripts(el, scopeCtx);
|
|
3609
|
+
scopeCtx.hooks?.scope(el, scopeCtx);
|
|
3610
|
+
finishElement(el, scopeCtx, true);
|
|
3611
|
+
};
|
|
3612
|
+
const fail = (e) => {
|
|
3613
|
+
console.error(`hyper-scope: h-scope 의 함수가 실패했습니다 — 이 스코프는 살아나지 않습니다.`);
|
|
3614
|
+
console.error(e);
|
|
3615
|
+
state.value = e;
|
|
3616
|
+
state.status = "rejected";
|
|
3617
|
+
holdScope(el);
|
|
3618
|
+
el.removeAttribute("h-cloak");
|
|
3619
|
+
};
|
|
3620
|
+
let value;
|
|
3621
|
+
let threw = false;
|
|
3622
|
+
try {
|
|
3623
|
+
value = scopeValue(el, exp, scopeCtx);
|
|
3624
|
+
} catch (e) {
|
|
3625
|
+
threw = true;
|
|
3626
|
+
fail(e);
|
|
3627
|
+
}
|
|
3628
|
+
const pending = !threw && isThenable(value);
|
|
3629
|
+
if (pending)
|
|
3630
|
+
state.status = "pending";
|
|
3631
|
+
mountScopeAwaits(el, outer, state);
|
|
3632
|
+
if (threw)
|
|
3633
|
+
return;
|
|
3634
|
+
if (!pending)
|
|
3635
|
+
return ready(value);
|
|
3636
|
+
holdScope(el);
|
|
3637
|
+
let disposed = false;
|
|
3638
|
+
scopeCtx.cleanups.push(() => disposed = true);
|
|
3639
|
+
value.then((data) => {
|
|
3640
|
+
if (disposed)
|
|
3641
|
+
return;
|
|
3642
|
+
state.status = "fulfilled";
|
|
3643
|
+
nextTick(() => {
|
|
3644
|
+
if (disposed)
|
|
3645
|
+
return;
|
|
3646
|
+
releaseScope(el);
|
|
3647
|
+
ready(data);
|
|
3648
|
+
});
|
|
3649
|
+
}, (e) => disposed || fail(e));
|
|
3650
|
+
return;
|
|
3651
|
+
}
|
|
3652
|
+
finishElement(el, ctx, false, provided);
|
|
3653
|
+
} else if (type === 3) {
|
|
3654
|
+
const data = node.data;
|
|
3655
|
+
if (readText && data.includes(ctx.delimiters[0])) {
|
|
3656
|
+
let segments = [];
|
|
3657
|
+
let lastIndex = 0;
|
|
3658
|
+
let match;
|
|
3659
|
+
while (match = ctx.delimitersRE.exec(data)) {
|
|
3660
|
+
const leading = data.slice(lastIndex, match.index);
|
|
3661
|
+
if (leading)
|
|
3662
|
+
segments.push(JSON.stringify(leading));
|
|
3663
|
+
segments.push(`$s(${match[1]})`);
|
|
3664
|
+
lastIndex = match.index + match[0].length;
|
|
3665
|
+
}
|
|
3666
|
+
if (lastIndex < data.length) {
|
|
3667
|
+
segments.push(JSON.stringify(data.slice(lastIndex)));
|
|
3668
|
+
}
|
|
3669
|
+
applyDirective(node, text, segments.join("+"), ctx);
|
|
3670
|
+
}
|
|
3671
|
+
} else if (type === 11) {
|
|
3672
|
+
walkChildren(node, ctx);
|
|
3673
|
+
}
|
|
3674
|
+
};
|
|
3675
|
+
var finishElement = (el, ctx, own = false, changed = false) => {
|
|
3676
|
+
el.removeAttribute("h-cloak");
|
|
3677
|
+
let exp;
|
|
3678
|
+
if ((exp = checkAttr(el, "h-state")) != null) {
|
|
3679
|
+
ctx = openState(el, exp, ctx);
|
|
3680
|
+
own = changed = true;
|
|
3681
|
+
}
|
|
3682
|
+
const inject = checkAttr(el, "h-inject");
|
|
3683
|
+
if (inject || hasComputeds(el)) {
|
|
3684
|
+
if (!own)
|
|
3685
|
+
ctx = createScopedContext(ctx);
|
|
3686
|
+
if (inject)
|
|
3687
|
+
injectInto(ctx.scope, inject, ctx.provides);
|
|
3688
|
+
defineComputeds(el, ctx.scope);
|
|
3689
|
+
changed = true;
|
|
3690
|
+
}
|
|
3691
|
+
if (changed)
|
|
3692
|
+
recordContext(el, ctx);
|
|
3693
|
+
const mustache = takeMustache(el);
|
|
3694
|
+
if (exp = checkAttr(el, "h-ref") || checkAttr(el, "ref")) {
|
|
3695
|
+
applyDirective(el, ref2, `"${exp}"`, ctx);
|
|
3696
|
+
}
|
|
3697
|
+
walkChildren(el, ctx, mustache);
|
|
3698
|
+
const deferred = [];
|
|
3699
|
+
for (const { name, value } of [...el.attributes]) {
|
|
3700
|
+
if (dirRE2.test(name) && name !== "h-cloak" && name !== "h-text-inline") {
|
|
3701
|
+
if (name === "h-model" || name.startsWith("h-model.")) {
|
|
3702
|
+
deferred.unshift([name, value]);
|
|
3703
|
+
} else if (name[0] === "@" || /^h-on\b/.test(name)) {
|
|
3704
|
+
deferred.push([name, value]);
|
|
3705
|
+
} else {
|
|
3706
|
+
processDirective(el, name, value, ctx);
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
for (const [name, value] of deferred) {
|
|
3711
|
+
processDirective(el, name, value, ctx);
|
|
3712
|
+
}
|
|
3713
|
+
};
|
|
3714
|
+
var mountScopeAwaits = (el, ctx, state) => {
|
|
3715
|
+
for (const t of [...el.querySelectorAll("[h-await]")]) {
|
|
3716
|
+
const exp = t.getAttribute("h-await");
|
|
3717
|
+
if (!awaitsScope(exp))
|
|
3718
|
+
continue;
|
|
3719
|
+
const inner = t.parentElement.closest("[h-scope],[h-pre]");
|
|
3720
|
+
if (inner && inner !== el && el.contains(inner))
|
|
3721
|
+
continue;
|
|
3722
|
+
t.removeAttribute("h-await");
|
|
3723
|
+
_await(t, exp, ctx, state);
|
|
3724
|
+
}
|
|
3725
|
+
};
|
|
3726
|
+
var walkChildren = (node, ctx, readText = false) => {
|
|
3727
|
+
let child = node.firstChild;
|
|
3728
|
+
while (child) {
|
|
3729
|
+
child = walk(child, ctx, readText) || child.nextSibling;
|
|
3730
|
+
}
|
|
3731
|
+
};
|
|
3732
|
+
var processDirective = (el, raw, exp, ctx) => {
|
|
3733
|
+
let dir;
|
|
3734
|
+
let arg;
|
|
3735
|
+
let modifiers;
|
|
3736
|
+
const attrName = raw;
|
|
3737
|
+
raw = raw.replace(modifierRE, (_, m) => {
|
|
3738
|
+
(modifiers || (modifiers = {}))[m] = true;
|
|
3739
|
+
return "";
|
|
3740
|
+
});
|
|
3741
|
+
if (raw[0] === ":") {
|
|
3742
|
+
dir = bind;
|
|
3743
|
+
arg = raw.slice(1);
|
|
3744
|
+
} else if (raw[0] === "@") {
|
|
3745
|
+
dir = on;
|
|
3746
|
+
arg = raw.slice(1);
|
|
3747
|
+
} else {
|
|
3748
|
+
const argIndex = raw.indexOf(":");
|
|
3749
|
+
const dirName = argIndex > 0 ? raw.slice(2, argIndex) : raw.slice(2);
|
|
3750
|
+
dir = builtInDirectives[dirName] || ctx.dirs[dirName];
|
|
3751
|
+
arg = argIndex > 0 ? raw.slice(argIndex + 1) : undefined;
|
|
3752
|
+
}
|
|
3753
|
+
if (dir) {
|
|
3754
|
+
if (dir === bind && arg === "ref")
|
|
3755
|
+
dir = ref2;
|
|
3756
|
+
applyDirective(el, dir, exp, ctx, arg, modifiers);
|
|
3757
|
+
el.removeAttribute(attrName);
|
|
3758
|
+
} else if (DEV) {
|
|
3759
|
+
console.error(`unknown custom directive ${raw}.`);
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
var applyDirective = (el, dir, exp, ctx, arg, modifiers) => {
|
|
3763
|
+
const get = (e = exp) => evaluate(ctx.scope, e, el);
|
|
3764
|
+
const cleanup = collectListeners(ctx.cleanups, () => dir({
|
|
3765
|
+
el,
|
|
3766
|
+
get,
|
|
3767
|
+
effect: ctx.effect,
|
|
3768
|
+
ctx,
|
|
3769
|
+
exp,
|
|
3770
|
+
arg,
|
|
3771
|
+
modifiers
|
|
3772
|
+
}));
|
|
3773
|
+
if (cleanup) {
|
|
3774
|
+
ctx.cleanups.push(cleanup);
|
|
3775
|
+
}
|
|
3776
|
+
};
|
|
3777
|
+
var resolveTemplate = (el, template) => {
|
|
3778
|
+
if (template[0] === "#") {
|
|
3779
|
+
const templateEl = document.querySelector(template);
|
|
3780
|
+
if (DEV && !templateEl) {
|
|
3781
|
+
console.error(`template selector ${template} has no matching <template> element.`);
|
|
3782
|
+
}
|
|
3783
|
+
el.appendChild(templateEl.content.cloneNode(true));
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
el.innerHTML = template;
|
|
3787
|
+
};
|
|
3788
|
+
|
|
3789
|
+
// src/block.ts
|
|
3790
|
+
class Block {
|
|
3791
|
+
template;
|
|
3792
|
+
ctx;
|
|
3793
|
+
key;
|
|
3794
|
+
parentCtx;
|
|
3795
|
+
isFragment;
|
|
3796
|
+
start;
|
|
3797
|
+
end;
|
|
3798
|
+
get el() {
|
|
3799
|
+
return this.start || this.template;
|
|
3800
|
+
}
|
|
3801
|
+
constructor(template, parentCtx, isRoot = false) {
|
|
3802
|
+
this.isFragment = template instanceof HTMLTemplateElement;
|
|
3803
|
+
if (isRoot) {
|
|
3804
|
+
this.template = template;
|
|
3805
|
+
} else if (this.isFragment) {
|
|
3806
|
+
const content = template.content;
|
|
3807
|
+
this.template = content.cloneNode(true);
|
|
3808
|
+
copySlotContexts(content, this.template);
|
|
3809
|
+
} else {
|
|
3810
|
+
this.template = template.cloneNode(true);
|
|
3811
|
+
copySlotContexts(template, this.template);
|
|
3812
|
+
}
|
|
3813
|
+
if (isRoot) {
|
|
3814
|
+
this.ctx = parentCtx;
|
|
3815
|
+
} else {
|
|
3816
|
+
this.parentCtx = parentCtx;
|
|
3817
|
+
parentCtx.blocks.push(this);
|
|
3818
|
+
this.ctx = createContext(parentCtx);
|
|
3819
|
+
}
|
|
3820
|
+
if (this.isFragment) {
|
|
3821
|
+
for (const child of this.template.children) {
|
|
3822
|
+
recordContext(child, this.ctx);
|
|
3823
|
+
}
|
|
3824
|
+
} else {
|
|
3825
|
+
recordContext(this.template, this.ctx);
|
|
3826
|
+
}
|
|
3827
|
+
walk(this.template, this.ctx);
|
|
3828
|
+
}
|
|
3829
|
+
insert(parent, anchor = null) {
|
|
3830
|
+
if (this.isFragment) {
|
|
3831
|
+
if (this.start) {
|
|
3832
|
+
let node = this.start;
|
|
3833
|
+
let next;
|
|
3834
|
+
while (node) {
|
|
3835
|
+
next = node.nextSibling;
|
|
3836
|
+
parent.insertBefore(node, anchor);
|
|
3837
|
+
if (node === this.end)
|
|
3838
|
+
break;
|
|
3839
|
+
node = next;
|
|
3840
|
+
}
|
|
3841
|
+
} else {
|
|
3842
|
+
this.start = new Text("");
|
|
3843
|
+
this.end = new Text("");
|
|
3844
|
+
parent.insertBefore(this.end, anchor);
|
|
3845
|
+
parent.insertBefore(this.start, this.end);
|
|
3846
|
+
parent.insertBefore(this.template, this.end);
|
|
3847
|
+
}
|
|
3848
|
+
} else {
|
|
3849
|
+
parent.insertBefore(this.template, anchor);
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
remove() {
|
|
3853
|
+
if (this.parentCtx) {
|
|
3854
|
+
const siblings = this.parentCtx.blocks;
|
|
3855
|
+
const i = siblings.indexOf(this);
|
|
3856
|
+
if (i > -1)
|
|
3857
|
+
siblings.splice(i, 1);
|
|
3858
|
+
}
|
|
3859
|
+
if (this.start) {
|
|
3860
|
+
const parent = this.start.parentNode;
|
|
3861
|
+
let node = this.start;
|
|
3862
|
+
let next;
|
|
3863
|
+
while (node) {
|
|
3864
|
+
next = node.nextSibling;
|
|
3865
|
+
parent.removeChild(node);
|
|
3866
|
+
if (node === this.end)
|
|
3867
|
+
break;
|
|
3868
|
+
node = next;
|
|
3869
|
+
}
|
|
3870
|
+
} else {
|
|
3871
|
+
this.template.parentNode.removeChild(this.template);
|
|
3872
|
+
}
|
|
3873
|
+
this.teardown();
|
|
3874
|
+
}
|
|
3875
|
+
teardown() {
|
|
3876
|
+
[...this.ctx.blocks].forEach((child) => {
|
|
3877
|
+
child.teardown();
|
|
3878
|
+
});
|
|
3879
|
+
this.ctx.effects.forEach(stop);
|
|
3880
|
+
this.ctx.cleanups.forEach((fn) => fn());
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
// src/app.ts
|
|
3885
|
+
var escapeRegex = (str) => str.replace(/[-.*+?^${}()|[\]\/\\]/g, "\\$&");
|
|
3886
|
+
var createRootContext = (initialData) => {
|
|
3887
|
+
const ctx = createContext();
|
|
3888
|
+
if (initialData) {
|
|
3889
|
+
ctx.scope = reactive(initialData);
|
|
3890
|
+
bindContextMethods(ctx.scope);
|
|
3891
|
+
if (initialData.$delimiters) {
|
|
3892
|
+
setDelimiters(ctx, initialData.$delimiters);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
ctx.scope.$s = toDisplayString;
|
|
3896
|
+
ctx.scope.$nextTick = nextTick;
|
|
3897
|
+
ctx.scope.$model = modelOf;
|
|
3898
|
+
ctx.scope.$refs = Object.create(null);
|
|
3899
|
+
ctx.asyncs = createAsyncRegistry();
|
|
3900
|
+
Object.assign(ctx.scope, asyncHelpers(ctx.asyncs, () => ctx.scope));
|
|
3901
|
+
return ctx;
|
|
3902
|
+
};
|
|
3903
|
+
var setDelimiters = (ctx, [open, close]) => {
|
|
3904
|
+
ctx.delimiters = [open, close];
|
|
3905
|
+
ctx.delimitersRE = new RegExp(escapeRegex(open) + "([^]+?)" + escapeRegex(close), "g");
|
|
3906
|
+
};
|
|
3907
|
+
var createApp = (initialData) => {
|
|
3908
|
+
const ctx = createRootContext(initialData);
|
|
3909
|
+
let rootBlocks;
|
|
3910
|
+
return {
|
|
3911
|
+
directive(name, def2) {
|
|
3912
|
+
if (def2) {
|
|
3913
|
+
ctx.dirs[name] = def2;
|
|
3914
|
+
return this;
|
|
3915
|
+
} else {
|
|
3916
|
+
return ctx.dirs[name];
|
|
3917
|
+
}
|
|
3918
|
+
},
|
|
3919
|
+
mount(el) {
|
|
3920
|
+
if (typeof el === "string") {
|
|
3921
|
+
el = document.querySelector(el);
|
|
3922
|
+
if (!el) {
|
|
3923
|
+
DEV && console.error(`selector ${el} has no matching element.`);
|
|
3924
|
+
return;
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
el = el || document.documentElement;
|
|
3928
|
+
let roots;
|
|
3929
|
+
if (el.hasAttribute("h-scope")) {
|
|
3930
|
+
roots = [el];
|
|
3931
|
+
} else {
|
|
3932
|
+
roots = [...el.querySelectorAll(`[h-scope]`)].filter((root) => !root.matches(`[h-scope] [h-scope]`));
|
|
3933
|
+
}
|
|
3934
|
+
if (!roots.length) {
|
|
3935
|
+
roots = [el];
|
|
3936
|
+
}
|
|
3937
|
+
if (DEV && roots.length === 1 && roots[0] === document.documentElement) {
|
|
3938
|
+
console.warn(`Mounting on documentElement - this is non-optimal as hyper-scope ` + `will be forced to crawl the entire page's DOM. ` + `Consider explicitly marking elements controlled by hyper-scope ` + `with \`h-scope\`.`);
|
|
3939
|
+
}
|
|
3940
|
+
rootBlocks = roots.map((el2) => new Block(el2, ctx, true));
|
|
3941
|
+
return this;
|
|
3942
|
+
},
|
|
3943
|
+
unmount() {
|
|
3944
|
+
rootBlocks.forEach((block) => block.teardown());
|
|
3945
|
+
}
|
|
3946
|
+
};
|
|
3947
|
+
};
|
|
3948
|
+
// src/keep.ts
|
|
3949
|
+
var entries = new Map;
|
|
3950
|
+
var ownState = (scope) => {
|
|
3951
|
+
const out = {};
|
|
3952
|
+
const descriptors = Object.getOwnPropertyDescriptors(toRaw(scope));
|
|
3953
|
+
for (const [key, d] of Object.entries(descriptors)) {
|
|
3954
|
+
if (key[0] === "$" || !("value" in d) || typeof d.value === "function")
|
|
3955
|
+
continue;
|
|
3956
|
+
out[key] = d.value;
|
|
3957
|
+
}
|
|
3958
|
+
return out;
|
|
3959
|
+
};
|
|
3960
|
+
var moveInto = (current, value) => {
|
|
3961
|
+
if (isRef(current)) {
|
|
3962
|
+
if (isReadonly(current))
|
|
3963
|
+
return true;
|
|
3964
|
+
current.value = isRef(value) ? value.value : value;
|
|
3965
|
+
return true;
|
|
3966
|
+
}
|
|
3967
|
+
if (isReactive(current) && value && typeof value === "object" && !isRef(value)) {
|
|
3968
|
+
const from = toRaw(value);
|
|
3969
|
+
if (Array.isArray(current) && Array.isArray(from))
|
|
3970
|
+
current.splice(0, current.length, ...from);
|
|
3971
|
+
else if (!Array.isArray(current) && !Array.isArray(from))
|
|
3972
|
+
Object.assign(current, from);
|
|
3973
|
+
else
|
|
3974
|
+
return false;
|
|
3975
|
+
return true;
|
|
3976
|
+
}
|
|
3977
|
+
return false;
|
|
3978
|
+
};
|
|
3979
|
+
var restore = (scope, state) => {
|
|
3980
|
+
const raw = toRaw(scope);
|
|
3981
|
+
for (const [key, value] of Object.entries(state)) {
|
|
3982
|
+
const d = Object.getOwnPropertyDescriptor(raw, key);
|
|
3983
|
+
if (d && (!("value" in d) || typeof d.value === "function"))
|
|
3984
|
+
continue;
|
|
3985
|
+
if (d && moveInto(d.value, value))
|
|
3986
|
+
continue;
|
|
3987
|
+
if (isRef(value) && isReadonly(value))
|
|
3988
|
+
continue;
|
|
3989
|
+
Object.defineProperty(raw, key, { value, writable: true, enumerable: true, configurable: true });
|
|
3990
|
+
}
|
|
3991
|
+
};
|
|
3992
|
+
var keepScope = (el, ctx) => {
|
|
3993
|
+
const key = checkAttr(el, "h-keep");
|
|
3994
|
+
if (key == null)
|
|
3995
|
+
return;
|
|
3996
|
+
if (!key.trim()) {
|
|
3997
|
+
DEV && console.warn(`hyper-scope: h-keep 에는 키가 필요합니다.`);
|
|
3998
|
+
return;
|
|
3999
|
+
}
|
|
4000
|
+
const scope = ctx.scope;
|
|
4001
|
+
const prev = entries.get(key);
|
|
4002
|
+
const state = prev && (prev.scope ? ownState(prev.scope) : prev.saved);
|
|
4003
|
+
if (state)
|
|
4004
|
+
restore(scope, state);
|
|
4005
|
+
const token = {};
|
|
4006
|
+
entries.set(key, { owner: token, scope });
|
|
4007
|
+
ctx.cleanups.push(() => {
|
|
4008
|
+
if (entries.get(key)?.owner === token) {
|
|
4009
|
+
entries.set(key, { owner: null, saved: ownState(scope) });
|
|
4010
|
+
}
|
|
4011
|
+
});
|
|
4012
|
+
};
|
|
4013
|
+
var keepWithoutScope = () => {
|
|
4014
|
+
DEV && console.warn(`hyper-scope: h-keep 은 h-scope 와 같은 요소에 붙입니다.`);
|
|
4015
|
+
};
|
|
4016
|
+
var clearKeeps = () => entries.clear();
|
|
4017
|
+
|
|
4018
|
+
// src/snapshot.ts
|
|
4019
|
+
var MARK = "h-snapshot";
|
|
4020
|
+
var revive = (node, isLive, hooks = []) => {
|
|
4021
|
+
const found = [...node.querySelectorAll(`[${MARK}]`)];
|
|
4022
|
+
if (node.hasAttribute(MARK))
|
|
4023
|
+
found.unshift(node);
|
|
4024
|
+
let result = node;
|
|
4025
|
+
for (const dead of found) {
|
|
4026
|
+
if (!dead.isConnected || !dead.hasAttribute(MARK))
|
|
4027
|
+
continue;
|
|
4028
|
+
const html2 = dead.getAttribute(MARK);
|
|
4029
|
+
dead.removeAttribute(MARK);
|
|
4030
|
+
if (isLive(dead))
|
|
4031
|
+
continue;
|
|
4032
|
+
const t = document.createElement("template");
|
|
4033
|
+
t.innerHTML = html2;
|
|
4034
|
+
const fresh = t.content.firstElementChild;
|
|
4035
|
+
if (!fresh)
|
|
4036
|
+
continue;
|
|
4037
|
+
for (const hook of hooks)
|
|
4038
|
+
hook(dead, fresh);
|
|
4039
|
+
dead.replaceWith(fresh);
|
|
4040
|
+
if (dead === node)
|
|
4041
|
+
result = fresh;
|
|
4042
|
+
}
|
|
4043
|
+
return result;
|
|
4044
|
+
};
|
|
4045
|
+
|
|
4046
|
+
// src/runtime.ts
|
|
4047
|
+
var detachedSelector = "";
|
|
4048
|
+
var isDetached = (el) => !!detachedSelector && el.matches(detachedSelector);
|
|
4049
|
+
|
|
4050
|
+
class Unit {
|
|
4051
|
+
el;
|
|
4052
|
+
parentCtx;
|
|
4053
|
+
ctx;
|
|
4054
|
+
probe;
|
|
4055
|
+
dead = false;
|
|
4056
|
+
pristine;
|
|
4057
|
+
grace;
|
|
4058
|
+
constructor(el, parentCtx, detached = false) {
|
|
4059
|
+
this.el = el;
|
|
4060
|
+
this.parentCtx = parentCtx;
|
|
4061
|
+
this.pristine = el.outerHTML;
|
|
4062
|
+
this.grace = !!detachedSelector && !!el.closest(detachedSelector);
|
|
4063
|
+
this.ctx = createContext(parentCtx);
|
|
4064
|
+
if (!detached)
|
|
4065
|
+
parentCtx.blocks.push(this);
|
|
4066
|
+
recordContext(el, this.ctx);
|
|
4067
|
+
units.add(this);
|
|
4068
|
+
live.set(el, this);
|
|
4069
|
+
const parent = el.parentNode;
|
|
4070
|
+
const outer = mounting;
|
|
4071
|
+
mounting = el;
|
|
4072
|
+
try {
|
|
4073
|
+
walk(el, this.ctx);
|
|
4074
|
+
} finally {
|
|
4075
|
+
mounting = outer;
|
|
4076
|
+
}
|
|
4077
|
+
this.probe = el.isConnected ? el : parent;
|
|
4078
|
+
}
|
|
4079
|
+
teardown() {
|
|
4080
|
+
if (this.dead)
|
|
4081
|
+
return;
|
|
4082
|
+
this.dead = true;
|
|
4083
|
+
units.delete(this);
|
|
4084
|
+
const siblings = this.parentCtx.blocks;
|
|
4085
|
+
const i = siblings.indexOf(this);
|
|
4086
|
+
if (i > -1)
|
|
4087
|
+
siblings.splice(i, 1);
|
|
4088
|
+
[...this.ctx.blocks].forEach((child) => child.teardown());
|
|
4089
|
+
this.ctx.effects.forEach(stop);
|
|
4090
|
+
this.ctx.cleanups.forEach((fn) => fn());
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
var providedAbove = new WeakMap;
|
|
4094
|
+
var withProvidesAbove = (el, parentCtx) => {
|
|
4095
|
+
const chain = [];
|
|
4096
|
+
for (let cur = el.parentElement;cur && !contextAt(cur); cur = cur.parentElement)
|
|
4097
|
+
chain.unshift(cur);
|
|
4098
|
+
let ctx = parentCtx;
|
|
4099
|
+
for (const a of chain) {
|
|
4100
|
+
const cached = providedAbove.get(a);
|
|
4101
|
+
if (cached) {
|
|
4102
|
+
ctx = cached;
|
|
4103
|
+
continue;
|
|
4104
|
+
}
|
|
4105
|
+
const next = applyProvides(a, ctx, true);
|
|
4106
|
+
if (next !== ctx)
|
|
4107
|
+
providedAbove.set(a, ctx = next);
|
|
4108
|
+
}
|
|
4109
|
+
return ctx;
|
|
4110
|
+
};
|
|
4111
|
+
var units = new Set;
|
|
4112
|
+
var live = new WeakMap;
|
|
4113
|
+
var mounting;
|
|
4114
|
+
var root;
|
|
4115
|
+
var started = false;
|
|
4116
|
+
var observer;
|
|
4117
|
+
var waiting;
|
|
4118
|
+
var graceTimer;
|
|
4119
|
+
var snapshot = () => {
|
|
4120
|
+
for (const unit of units) {
|
|
4121
|
+
if (!unit.dead && unit.el.isConnected)
|
|
4122
|
+
unit.el.setAttribute(MARK, unit.pristine);
|
|
4123
|
+
}
|
|
4124
|
+
return () => {
|
|
4125
|
+
for (const unit of units) {
|
|
4126
|
+
if (unit.el.isConnected)
|
|
4127
|
+
unit.el.removeAttribute(MARK);
|
|
4128
|
+
}
|
|
4129
|
+
};
|
|
4130
|
+
};
|
|
4131
|
+
var reviveHooks = [];
|
|
4132
|
+
var stopHooks = [];
|
|
4133
|
+
var pendingPlugins = [];
|
|
4134
|
+
var OWNER = Symbol.for("hyper-scope.runtime");
|
|
4135
|
+
var reserved = new Set([
|
|
4136
|
+
"$scope",
|
|
4137
|
+
"$host",
|
|
4138
|
+
"$root",
|
|
4139
|
+
"$props",
|
|
4140
|
+
"$emit",
|
|
4141
|
+
"$dispatch",
|
|
4142
|
+
"$handle",
|
|
4143
|
+
"$provide",
|
|
4144
|
+
"$inject",
|
|
4145
|
+
"$async",
|
|
4146
|
+
"$await",
|
|
4147
|
+
"$refs",
|
|
4148
|
+
"$nextTick",
|
|
4149
|
+
"$model",
|
|
4150
|
+
"$s",
|
|
4151
|
+
"$el",
|
|
4152
|
+
"$data",
|
|
4153
|
+
"$error"
|
|
4154
|
+
]);
|
|
4155
|
+
var api = {
|
|
4156
|
+
define(name, value) {
|
|
4157
|
+
if (typeof name !== "string" || !name || reserved.has(name)) {
|
|
4158
|
+
console.error(`hyper-scope: define 으로 올릴 수 없는 이름입니다: ${String(name)}`);
|
|
4159
|
+
return;
|
|
4160
|
+
}
|
|
4161
|
+
root.scope[name] = isObject(value) && Object.isExtensible(value) && !isReactive(value) ? markRaw(value) : value;
|
|
4162
|
+
},
|
|
4163
|
+
defineScoped(name, factory) {
|
|
4164
|
+
if (typeof name !== "string" || !name || reserved.has(name) || typeof factory !== "function") {
|
|
4165
|
+
console.error(`hyper-scope: defineScoped 로 올릴 수 없습니다: ${String(name)}`);
|
|
4166
|
+
return;
|
|
4167
|
+
}
|
|
4168
|
+
(root.scoped ||= {})[name] = factory;
|
|
4169
|
+
},
|
|
4170
|
+
detach(selector) {
|
|
4171
|
+
detachedSelector = detachedSelector ? `${detachedSelector},${selector}` : selector;
|
|
4172
|
+
},
|
|
4173
|
+
snapshot,
|
|
4174
|
+
onRevive(hook) {
|
|
4175
|
+
reviveHooks.push(hook);
|
|
4176
|
+
},
|
|
4177
|
+
onStop(fn) {
|
|
4178
|
+
stopHooks.push(fn);
|
|
4179
|
+
},
|
|
4180
|
+
directive(name, def2) {
|
|
4181
|
+
root.dirs[name] = def2;
|
|
4182
|
+
},
|
|
4183
|
+
component(name, def2) {
|
|
4184
|
+
defineComponent(name, def2);
|
|
4185
|
+
if (started)
|
|
4186
|
+
mountWithin(document.documentElement);
|
|
4187
|
+
},
|
|
4188
|
+
provide(key, value) {
|
|
4189
|
+
const provides = root.provides;
|
|
4190
|
+
if (!(key in provides))
|
|
4191
|
+
provides[key] = value;
|
|
4192
|
+
return provides[key];
|
|
4193
|
+
},
|
|
4194
|
+
reactive,
|
|
4195
|
+
computed
|
|
4196
|
+
};
|
|
4197
|
+
var runPlugin = (fn) => {
|
|
4198
|
+
try {
|
|
4199
|
+
fn(api);
|
|
4200
|
+
} catch (e) {
|
|
4201
|
+
console.error(`hyper-scope: 플러그인 실행 중 오류`);
|
|
4202
|
+
console.error(e);
|
|
4203
|
+
}
|
|
4204
|
+
};
|
|
4205
|
+
var plugin = (fn) => {
|
|
4206
|
+
if (typeof fn !== "function") {
|
|
4207
|
+
console.error(`hyper-scope: plugin 은 함수를 받습니다 — plugin(({ define }) => { … })`);
|
|
4208
|
+
return;
|
|
4209
|
+
}
|
|
4210
|
+
if (root)
|
|
4211
|
+
runPlugin(fn);
|
|
4212
|
+
else
|
|
4213
|
+
pendingPlugins.push(fn);
|
|
4214
|
+
};
|
|
4215
|
+
var hooks = {
|
|
4216
|
+
detached: (el, ctx) => {
|
|
4217
|
+
if (el === mounting || !isDetached(el))
|
|
4218
|
+
return false;
|
|
4219
|
+
new Unit(el, ctx, true);
|
|
4220
|
+
return true;
|
|
4221
|
+
},
|
|
4222
|
+
scope: keepScope,
|
|
4223
|
+
sealed: (el) => live.get(el)?.teardown()
|
|
4224
|
+
};
|
|
4225
|
+
var detachedFromParent = (target) => {
|
|
4226
|
+
for (let cur = target;cur; cur = cur.parentNode) {
|
|
4227
|
+
if (cur !== target && contextAt(cur))
|
|
4228
|
+
return false;
|
|
4229
|
+
if (cur.nodeType === 1 && isDetached(cur))
|
|
4230
|
+
return true;
|
|
4231
|
+
}
|
|
4232
|
+
return false;
|
|
4233
|
+
};
|
|
4234
|
+
var isLive = (el) => {
|
|
4235
|
+
const unit = live.get(el);
|
|
4236
|
+
return !!unit && !unit.dead;
|
|
4237
|
+
};
|
|
4238
|
+
var mountWithin = (node) => {
|
|
4239
|
+
if (node.nodeType !== 1 || !node.isConnected)
|
|
4240
|
+
return;
|
|
4241
|
+
const el = revive(node, isLive, reviveHooks);
|
|
4242
|
+
registerTemplates(el);
|
|
4243
|
+
const selector = unitSelector();
|
|
4244
|
+
const found = el.matches(selector) ? [el] : [...el.querySelectorAll(selector)];
|
|
4245
|
+
for (const target of found) {
|
|
4246
|
+
if (!isPendingUnit(target) || !target.isConnected)
|
|
4247
|
+
continue;
|
|
4248
|
+
if (hasPendingAncestor(target))
|
|
4249
|
+
continue;
|
|
4250
|
+
if (target.closest("[h-pre]"))
|
|
4251
|
+
continue;
|
|
4252
|
+
new Unit(target, withProvidesAbove(target, findContext(target) || root), detachedFromParent(target));
|
|
4253
|
+
}
|
|
4254
|
+
};
|
|
4255
|
+
var sweep = () => {
|
|
4256
|
+
let waitMore = false;
|
|
4257
|
+
for (const unit of [...units]) {
|
|
4258
|
+
if (unit.dead || unit.probe.isConnected)
|
|
4259
|
+
continue;
|
|
4260
|
+
if (unit.grace)
|
|
4261
|
+
waitMore = true;
|
|
4262
|
+
else
|
|
4263
|
+
unit.teardown();
|
|
4264
|
+
}
|
|
4265
|
+
if (waitMore && !graceTimer) {
|
|
4266
|
+
graceTimer = setTimeout(() => {
|
|
4267
|
+
graceTimer = undefined;
|
|
4268
|
+
for (const unit of [...units]) {
|
|
4269
|
+
if (unit.grace && !unit.dead && !unit.probe.isConnected)
|
|
4270
|
+
unit.teardown();
|
|
4271
|
+
}
|
|
4272
|
+
});
|
|
4273
|
+
}
|
|
4274
|
+
};
|
|
4275
|
+
var onMutations = (records) => {
|
|
4276
|
+
let removed = false;
|
|
4277
|
+
for (const record of records) {
|
|
4278
|
+
if (record.removedNodes.length)
|
|
4279
|
+
removed = true;
|
|
4280
|
+
record.addedNodes.forEach(mountWithin);
|
|
4281
|
+
}
|
|
4282
|
+
if (removed)
|
|
4283
|
+
sweep();
|
|
4284
|
+
};
|
|
4285
|
+
var begin = (options) => {
|
|
4286
|
+
waiting = undefined;
|
|
4287
|
+
root = createRootContext();
|
|
4288
|
+
if (options.delimiters)
|
|
4289
|
+
setDelimiters(root, options.delimiters);
|
|
4290
|
+
root.hooks = hooks;
|
|
4291
|
+
root.dirs.keep = keepWithoutScope;
|
|
4292
|
+
document.dispatchEvent(new CustomEvent("hyper-scope:init", { detail: api }));
|
|
4293
|
+
for (const fn of [...pendingPlugins.splice(0), ...options.plugins || []])
|
|
4294
|
+
runPlugin(fn);
|
|
4295
|
+
mountWithin(document.documentElement);
|
|
4296
|
+
started = true;
|
|
4297
|
+
observer = new MutationObserver(onMutations);
|
|
4298
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
4299
|
+
};
|
|
4300
|
+
var start = (options = {}) => {
|
|
4301
|
+
if (root || waiting) {
|
|
4302
|
+
DEV && console.warn(`hyper-scope: start() 는 이미 불렸습니다. 두 번째 호출은 무시합니다.`);
|
|
4303
|
+
return;
|
|
4304
|
+
}
|
|
4305
|
+
const doc = document;
|
|
4306
|
+
if (doc[OWNER] && doc[OWNER] !== api) {
|
|
4307
|
+
console.error(`hyper-scope: another hyper-scope runtime is already running in this document — this start() is refused. ` + `Load one runtime per document; code bundled separately can reach the running one through "hyper-scope/global".`);
|
|
4308
|
+
return;
|
|
4309
|
+
}
|
|
4310
|
+
doc[OWNER] = api;
|
|
4311
|
+
if (document.readyState === "loading") {
|
|
4312
|
+
waiting = () => begin(options);
|
|
4313
|
+
document.addEventListener("DOMContentLoaded", waiting, { once: true });
|
|
4314
|
+
} else {
|
|
4315
|
+
begin(options);
|
|
4316
|
+
}
|
|
4317
|
+
};
|
|
4318
|
+
var stop2 = () => {
|
|
4319
|
+
if (document[OWNER] === api)
|
|
4320
|
+
delete document[OWNER];
|
|
4321
|
+
if (waiting) {
|
|
4322
|
+
document.removeEventListener("DOMContentLoaded", waiting);
|
|
4323
|
+
waiting = undefined;
|
|
4324
|
+
}
|
|
4325
|
+
observer?.disconnect();
|
|
4326
|
+
observer = undefined;
|
|
4327
|
+
for (const fn of stopHooks.splice(0))
|
|
4328
|
+
fn();
|
|
4329
|
+
reviveHooks.length = 0;
|
|
4330
|
+
detachedSelector = "";
|
|
4331
|
+
clearTimeout(graceTimer);
|
|
4332
|
+
graceTimer = undefined;
|
|
4333
|
+
for (const unit of [...units])
|
|
4334
|
+
unit.teardown();
|
|
4335
|
+
root = undefined;
|
|
4336
|
+
started = false;
|
|
4337
|
+
clearKeeps();
|
|
4338
|
+
pendingPlugins.length = 0;
|
|
4339
|
+
clearComponents();
|
|
4340
|
+
};
|
|
4341
|
+
export {
|
|
4342
|
+
stop2 as stop,
|
|
4343
|
+
start,
|
|
4344
|
+
ref,
|
|
4345
|
+
reactive,
|
|
4346
|
+
plugin,
|
|
4347
|
+
onScopeDispose,
|
|
4348
|
+
nextTick,
|
|
4349
|
+
modelOf,
|
|
4350
|
+
effectScope,
|
|
4351
|
+
effect,
|
|
4352
|
+
createApp,
|
|
4353
|
+
computed
|
|
4354
|
+
};
|