aberdeen 1.17.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/aberdeen.d.ts +928 -944
- package/dist/src/aberdeen.js +1693 -1704
- package/dist/src/aberdeen.js.map +3 -3
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +10 -0
- package/dist/src/prediction.d.ts +7 -4
- package/dist/src/prediction.js +18 -23
- package/dist/src/prediction.js.map +3 -3
- package/dist/src/route.d.ts +112 -99
- package/dist/src/route.js +254 -254
- package/dist/src/route.js.map +3 -3
- package/dist/src/server-dom.d.ts +158 -0
- package/dist/src/server-dom.js +458 -0
- package/dist/src/server-dom.js.map +10 -0
- package/dist/src/server.d.ts +55 -0
- package/dist/src/server.js +25 -0
- package/dist/src/server.js.map +10 -0
- package/dist/src/transitions.js +7 -4
- package/dist/src/transitions.js.map +3 -3
- package/dist/tests/environment.d.ts +24 -0
- package/dist/tests/{fakedom.js → environment.js} +239 -288
- package/dist/tests/environment.js.map +11 -0
- package/dist/tests/helpers.d.ts +15 -3
- package/dist/tests/helpers.js +277 -306
- package/dist/tests/helpers.js.map +6 -5
- package/dist-docs/Tutorial/index.html +30 -30
- package/dist-docs/aberdeen/Aberdeen/index.html +350 -0
- package/dist-docs/aberdeen/InitOptions/index.html +4 -0
- package/dist-docs/aberdeen/KeyToString/index.html +2 -0
- package/dist-docs/aberdeen/PromiseProxy/index.html +6 -6
- package/dist-docs/aberdeen/SortKeyType/index.html +2 -0
- package/dist-docs/aberdeen/TargetType/index.html +2 -0
- package/dist-docs/aberdeen/ValueRef/index.html +2 -0
- package/dist-docs/aberdeen/WindowLike/index.html +5 -0
- package/dist-docs/aberdeen/{clone → createA}/index.html +10 -5
- package/dist-docs/aberdeen/index.html +13 -54
- package/dist-docs/assets/aberdeen/aberdeen.d.ts +928 -944
- package/dist-docs/assets/aberdeen/aberdeen.js +1693 -1704
- package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
- package/dist-docs/assets/aberdeen/index.d.ts +12 -0
- package/dist-docs/assets/aberdeen/index.js +11 -0
- package/dist-docs/assets/aberdeen/index.js.map +10 -0
- package/dist-docs/assets/aberdeen/prediction.d.ts +7 -4
- package/dist-docs/assets/aberdeen/prediction.js +18 -23
- package/dist-docs/assets/aberdeen/prediction.js.map +3 -3
- package/dist-docs/assets/aberdeen/route.d.ts +112 -99
- package/dist-docs/assets/aberdeen/route.js +254 -254
- package/dist-docs/assets/aberdeen/route.js.map +3 -3
- package/dist-docs/assets/aberdeen/server-dom.d.ts +158 -0
- package/dist-docs/assets/aberdeen/server-dom.js +458 -0
- package/dist-docs/assets/aberdeen/server-dom.js.map +10 -0
- package/dist-docs/assets/aberdeen/server.d.ts +55 -0
- package/dist-docs/assets/aberdeen/server.js +25 -0
- package/dist-docs/assets/aberdeen/server.js.map +10 -0
- package/dist-docs/assets/aberdeen/transitions.js +7 -4
- package/dist-docs/assets/aberdeen/transitions.js.map +3 -3
- package/dist-docs/assets/navigation.js +1 -1
- package/dist-docs/assets/search.js +1 -1
- package/dist-docs/dispatcher/Dispatcher/index.html +5 -6
- package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
- package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
- package/dist-docs/dispatcher/index.html +2 -2
- package/dist-docs/hierarchy.html +1 -1
- package/dist-docs/index-1/index.html +2 -0
- package/dist-docs/index.html +2 -2
- package/dist-docs/media/CHANGELOG.md +14 -2
- package/dist-docs/modules.html +1 -1
- package/dist-docs/prediction/applyCanon/index.html +4 -3
- package/dist-docs/prediction/applyPrediction/index.html +4 -3
- package/dist-docs/prediction/index.html +2 -2
- package/dist-docs/route/Route/index.html +9 -9
- package/dist-docs/route/RouteApi/index.html +60 -0
- package/dist-docs/route/index.html +6 -15
- package/dist-docs/route/init/index.html +5 -0
- package/dist-docs/server/RenderToStringOptions/index.html +6 -0
- package/dist-docs/server/RenderToStringResult/index.html +6 -0
- package/dist-docs/server/index.html +4 -0
- package/dist-docs/server/renderToString/index.html +6 -0
- package/dist-docs/sitemap.xml +51 -155
- package/dist-docs/transitions/grow/index.html +2 -2
- package/dist-docs/transitions/index.html +2 -2
- package/dist-docs/transitions/shrink/index.html +2 -2
- package/package.json +17 -7
- package/skill/SKILL.md +28 -28
- package/skill/aberdeen.md +471 -3448
- package/skill/dispatcher.md +6 -16
- package/skill/prediction.md +17 -5
- package/skill/route.md +95 -77
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +1226 -740
- package/src/index.ts +13 -0
- package/src/prediction.ts +25 -24
- package/src/route.ts +192 -142
- package/src/server-dom.ts +508 -0
- package/src/server.ts +74 -0
- package/src/transitions.ts +9 -3
- package/dist/tests/fakedom.d.ts +0 -9
- package/dist/tests/fakedom.js.map +0 -10
- package/dist-docs/aberdeen/A/index.html +0 -115
- package/dist-docs/aberdeen/CUSTOM_DUMP/index.html +0 -7
- package/dist-docs/aberdeen/NO_COPY/index.html +0 -2
- package/dist-docs/aberdeen/OPAQUE/index.html +0 -12
- package/dist-docs/aberdeen/clean/index.html +0 -11
- package/dist-docs/aberdeen/copy/index.html +0 -22
- package/dist-docs/aberdeen/count/index.html +0 -7
- package/dist-docs/aberdeen/cssVars/index.html +0 -11
- package/dist-docs/aberdeen/darkMode/index.html +0 -9
- package/dist-docs/aberdeen/default/index.html +0 -341
- package/dist-docs/aberdeen/derive/index.html +0 -18
- package/dist-docs/aberdeen/disableCreateDestroy/index.html +0 -6
- package/dist-docs/aberdeen/dump/index.html +0 -11
- package/dist-docs/aberdeen/insertCss/index.html +0 -30
- package/dist-docs/aberdeen/insertGlobalCss/index.html +0 -19
- package/dist-docs/aberdeen/invertString/index.html +0 -13
- package/dist-docs/aberdeen/isEmpty/index.html +0 -12
- package/dist-docs/aberdeen/map/index.html +0 -26
- package/dist-docs/aberdeen/merge/index.html +0 -11
- package/dist-docs/aberdeen/mount/index.html +0 -17
- package/dist-docs/aberdeen/multiMap/index.html +0 -28
- package/dist-docs/aberdeen/onEach/index.html +0 -19
- package/dist-docs/aberdeen/partition/index.html +0 -36
- package/dist-docs/aberdeen/peek/index.html +0 -40
- package/dist-docs/aberdeen/proxy/index.html +0 -35
- package/dist-docs/aberdeen/ref/index.html +0 -13
- package/dist-docs/aberdeen/runQueue/index.html +0 -13
- package/dist-docs/aberdeen/setErrorHandler/index.html +0 -16
- package/dist-docs/aberdeen/setSpacingCssVars/index.html +0 -8
- package/dist-docs/aberdeen/unmountAll/index.html +0 -5
- package/dist-docs/aberdeen/unproxy/index.html +0 -11
- package/dist-docs/route/back/index.html +0 -4
- package/dist-docs/route/current/index.html +0 -2
- package/dist-docs/route/go/index.html +0 -14
- package/dist-docs/route/interceptLinks/index.html +0 -8
- package/dist-docs/route/matchCurrent/index.html +0 -10
- package/dist-docs/route/persistScroll/index.html +0 -6
- package/dist-docs/route/push/index.html +0 -6
- package/dist-docs/route/setLog/index.html +0 -3
- package/dist-docs/route/up/index.html +0 -5
|
@@ -99,1880 +99,1869 @@ class ReverseSortedSet {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// src/aberdeen.ts
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
102
|
+
function createA(window, options = {}) {
|
|
103
|
+
const document = window ? window.document : undefined;
|
|
104
|
+
const Node = window ? window.Node : undefined;
|
|
105
|
+
const Element = window ? window.Element : undefined;
|
|
106
|
+
const setTimeout = window?.setTimeout ? window.setTimeout.bind(window) : globalThis.setTimeout;
|
|
107
|
+
const queueMicrotask = window?.queueMicrotask ? window.queueMicrotask.bind(window) : globalThis.queueMicrotask;
|
|
108
|
+
let sortedQueue;
|
|
109
|
+
let runQueueDepth = 0;
|
|
110
|
+
let topRedrawScope;
|
|
111
|
+
let survivingEl;
|
|
112
|
+
var SideEffect;
|
|
113
|
+
((SideEffect2) => {
|
|
114
|
+
SideEffect2[SideEffect2["Class"] = 0] = "Class";
|
|
115
|
+
SideEffect2[SideEffect2["Style"] = 1] = "Style";
|
|
116
|
+
SideEffect2[SideEffect2["Prop"] = 2] = "Prop";
|
|
117
|
+
SideEffect2[SideEffect2["Attr"] = 3] = "Attr";
|
|
118
|
+
SideEffect2[SideEffect2["Event"] = 4] = "Event";
|
|
119
|
+
})(SideEffect ||= {});
|
|
120
|
+
function recordSideEffect(scope, type, key, value) {
|
|
121
|
+
(scope.sideEffects ||= []).push(type, key, value);
|
|
122
|
+
}
|
|
123
|
+
function undoSideEffects(el, se) {
|
|
124
|
+
for (let i = se.length - 3;i >= 0; i -= 3) {
|
|
125
|
+
const key = se[i + 1];
|
|
126
|
+
const value = se[i + 2];
|
|
127
|
+
switch (se[i]) {
|
|
128
|
+
case 0 /* Class */:
|
|
129
|
+
value ? el.classList.add(key) : el.classList.remove(key);
|
|
130
|
+
break;
|
|
131
|
+
case 1 /* Style */:
|
|
132
|
+
el.style[key] = value == null ? "" : value;
|
|
133
|
+
break;
|
|
134
|
+
case 2 /* Prop */:
|
|
135
|
+
el[key] = value;
|
|
136
|
+
break;
|
|
137
|
+
case 3 /* Attr */:
|
|
138
|
+
value == null ? el.removeAttribute(key) : el.setAttribute(key, value);
|
|
139
|
+
break;
|
|
140
|
+
case 4 /* Event */:
|
|
141
|
+
el.removeEventListener(key, value);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
129
144
|
}
|
|
130
145
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
146
|
+
function queue(runner) {
|
|
147
|
+
if (!sortedQueue) {
|
|
148
|
+
sortedQueue = new ReverseSortedSet("prio");
|
|
149
|
+
queueMicrotask(runQueue);
|
|
150
|
+
} else if (!(runQueueDepth & 1)) {
|
|
151
|
+
runQueueDepth++;
|
|
152
|
+
if (runQueueDepth > 98) {
|
|
153
|
+
throw new Error("Too many recursive updates from observes");
|
|
154
|
+
}
|
|
140
155
|
}
|
|
156
|
+
sortedQueue.add(runner);
|
|
141
157
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
function runQueue() {
|
|
159
|
+
let time = Date.now();
|
|
160
|
+
while (sortedQueue) {
|
|
161
|
+
const runner = sortedQueue.fetchLast();
|
|
162
|
+
if (!runner)
|
|
163
|
+
break;
|
|
164
|
+
if (runQueueDepth & 1)
|
|
165
|
+
runQueueDepth++;
|
|
166
|
+
runner.queueRun();
|
|
167
|
+
}
|
|
168
|
+
sortedQueue = undefined;
|
|
169
|
+
runQueueDepth = 0;
|
|
170
|
+
time = Date.now() - time;
|
|
171
|
+
if (time > 9)
|
|
172
|
+
console.debug(`Aberdeen queue took ${time}ms`);
|
|
173
|
+
}
|
|
174
|
+
function arrayToStr(parts) {
|
|
175
|
+
let result = "";
|
|
176
|
+
for (const part of parts) {
|
|
177
|
+
if (typeof part === "string") {
|
|
178
|
+
result += `${part}\x01`;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (typeof part !== "number") {
|
|
182
|
+
throw new Error("onEach() sort key must be a string, number or an array of such");
|
|
183
|
+
}
|
|
184
|
+
let digits = "";
|
|
185
|
+
let num = Math.abs(Math.round(part));
|
|
186
|
+
const negative = part < 0;
|
|
187
|
+
while (num > 0) {
|
|
188
|
+
digits = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + digits;
|
|
189
|
+
num = Math.floor(num / 65533);
|
|
190
|
+
}
|
|
191
|
+
result += String.fromCharCode(128 + (negative ? -digits.length : digits.length)) + digits;
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
153
194
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function arrayToStr(parts) {
|
|
161
|
-
let result = "";
|
|
162
|
-
for (const part of parts) {
|
|
163
|
-
if (typeof part === "string") {
|
|
164
|
-
result += `${part}\x01`;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (typeof part !== "number") {
|
|
168
|
-
throw new Error("onEach() sort key must be a string, number or an array of such");
|
|
169
|
-
}
|
|
170
|
-
let digits = "";
|
|
171
|
-
let num = Math.abs(Math.round(part));
|
|
172
|
-
const negative = part < 0;
|
|
173
|
-
while (num > 0) {
|
|
174
|
-
digits = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + digits;
|
|
175
|
-
num = Math.floor(num / 65533);
|
|
176
|
-
}
|
|
177
|
-
result += String.fromCharCode(128 + (negative ? -digits.length : digits.length)) + digits;
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
function invertString(input) {
|
|
182
|
-
let result = "";
|
|
183
|
-
for (let i = 0;i < input.length; i++) {
|
|
184
|
-
result += String.fromCodePoint(65535 - input.charCodeAt(i));
|
|
195
|
+
function invertString(input) {
|
|
196
|
+
let result = "";
|
|
197
|
+
for (let i = 0;i < input.length; i++) {
|
|
198
|
+
result += String.fromCodePoint(65535 - input.charCodeAt(i));
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
185
201
|
}
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
var lastPrio = 0;
|
|
202
|
+
let lastPrio = 0;
|
|
189
203
|
|
|
190
|
-
class Scope {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
class Scope {
|
|
205
|
+
prio = --lastPrio;
|
|
206
|
+
remove() {
|
|
207
|
+
const lastNode = this.getLastNode();
|
|
208
|
+
if (lastNode)
|
|
209
|
+
removeNodes(lastNode, this.getPrecedingNode());
|
|
210
|
+
const savedSurvivingEl = survivingEl;
|
|
211
|
+
survivingEl = this.el;
|
|
212
|
+
this.delete();
|
|
213
|
+
survivingEl = savedSurvivingEl;
|
|
214
|
+
}
|
|
200
215
|
}
|
|
201
|
-
}
|
|
202
216
|
|
|
203
|
-
class DelayedOneTimeRunner {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
class DelayedOneTimeRunner {
|
|
218
|
+
queueRun;
|
|
219
|
+
prio = --lastPrio;
|
|
220
|
+
constructor(queueRun) {
|
|
221
|
+
this.queueRun = queueRun;
|
|
222
|
+
queue(this);
|
|
223
|
+
}
|
|
209
224
|
}
|
|
210
|
-
}
|
|
211
225
|
|
|
212
|
-
class ContentScope extends Scope {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
class ContentScope extends Scope {
|
|
227
|
+
cleaners;
|
|
228
|
+
sideEffects;
|
|
229
|
+
changes;
|
|
230
|
+
constructor(cleaners = []) {
|
|
231
|
+
super();
|
|
232
|
+
this.cleaners = cleaners;
|
|
233
|
+
}
|
|
234
|
+
lastChild;
|
|
235
|
+
redraw() {}
|
|
236
|
+
getLastNode() {
|
|
237
|
+
return findLastNodeInPrevSiblings(this.lastChild);
|
|
238
|
+
}
|
|
239
|
+
delete() {
|
|
240
|
+
const cleaners = this.cleaners;
|
|
241
|
+
for (let i = cleaners.length - 1;i >= 0; i--) {
|
|
242
|
+
const cleaner = cleaners[i];
|
|
243
|
+
if (typeof cleaner === "function")
|
|
244
|
+
cleaner();
|
|
245
|
+
else
|
|
246
|
+
cleaner.delete(this);
|
|
247
|
+
}
|
|
248
|
+
this.cleaners.length = 0;
|
|
249
|
+
const se = this.sideEffects;
|
|
250
|
+
if (se) {
|
|
251
|
+
if (this.el === survivingEl)
|
|
252
|
+
undoSideEffects(this.el, se);
|
|
253
|
+
this.sideEffects = undefined;
|
|
254
|
+
}
|
|
255
|
+
sortedQueue?.remove(this);
|
|
256
|
+
this.lastChild = undefined;
|
|
233
257
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
258
|
+
onChange(target, index, newData, oldData) {
|
|
259
|
+
if (!this.changes) {
|
|
260
|
+
this.changes = new Map;
|
|
261
|
+
queue(this);
|
|
262
|
+
}
|
|
263
|
+
let targetDelta = this.changes.get(target);
|
|
264
|
+
if (!targetDelta) {
|
|
265
|
+
targetDelta = new Map;
|
|
266
|
+
this.changes.set(target, targetDelta);
|
|
267
|
+
}
|
|
268
|
+
if (targetDelta.has(index)) {
|
|
269
|
+
if (targetDelta.get(index) === newData)
|
|
270
|
+
targetDelta.delete(index);
|
|
271
|
+
} else {
|
|
272
|
+
targetDelta.set(index, oldData);
|
|
273
|
+
}
|
|
240
274
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
275
|
+
fetchHasChanges() {
|
|
276
|
+
if (!this.changes)
|
|
277
|
+
return false;
|
|
278
|
+
for (const targetDelta of this.changes.values()) {
|
|
279
|
+
if (targetDelta.size > 0) {
|
|
280
|
+
delete this.changes;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
delete this.changes;
|
|
285
|
+
return false;
|
|
248
286
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.
|
|
287
|
+
queueRun() {
|
|
288
|
+
if (!this.fetchHasChanges())
|
|
289
|
+
return;
|
|
290
|
+
this.remove();
|
|
291
|
+
topRedrawScope = this;
|
|
292
|
+
this.redraw();
|
|
293
|
+
topRedrawScope = undefined;
|
|
253
294
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
targetDelta.delete(index);
|
|
257
|
-
} else {
|
|
258
|
-
targetDelta.set(index, oldData);
|
|
295
|
+
getInsertAfterNode() {
|
|
296
|
+
return this.getLastNode() || this.getPrecedingNode();
|
|
259
297
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (!this.changes)
|
|
263
|
-
return false;
|
|
264
|
-
for (const targetDelta of this.changes.values()) {
|
|
265
|
-
if (targetDelta.size > 0) {
|
|
266
|
-
delete this.changes;
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
298
|
+
getChildPrevSibling() {
|
|
299
|
+
return this.lastChild;
|
|
269
300
|
}
|
|
270
|
-
delete this.changes;
|
|
271
|
-
return false;
|
|
272
301
|
}
|
|
273
|
-
queueRun() {
|
|
274
|
-
if (!this.fetchHasChanges())
|
|
275
|
-
return;
|
|
276
|
-
this.remove();
|
|
277
|
-
topRedrawScope = this;
|
|
278
|
-
this.redraw();
|
|
279
|
-
topRedrawScope = undefined;
|
|
280
|
-
}
|
|
281
|
-
getInsertAfterNode() {
|
|
282
|
-
return this.getLastNode() || this.getPrecedingNode();
|
|
283
|
-
}
|
|
284
|
-
getChildPrevSibling() {
|
|
285
|
-
return this.lastChild;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
302
|
|
|
289
|
-
class ChainedScope extends ContentScope {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
303
|
+
class ChainedScope extends ContentScope {
|
|
304
|
+
el;
|
|
305
|
+
svg;
|
|
306
|
+
prevSibling;
|
|
307
|
+
constructor(el, svg, useParentCleaners = false) {
|
|
308
|
+
super(useParentCleaners ? currentScope.cleaners : []);
|
|
309
|
+
this.el = el;
|
|
310
|
+
this.svg = svg;
|
|
311
|
+
if (el === currentScope.el) {
|
|
312
|
+
this.prevSibling = currentScope.getChildPrevSibling();
|
|
313
|
+
currentScope.lastChild = this;
|
|
314
|
+
} else {
|
|
315
|
+
this.prevSibling = el.lastChild || undefined;
|
|
316
|
+
}
|
|
317
|
+
if (!useParentCleaners)
|
|
318
|
+
currentScope.cleaners.push(this);
|
|
319
|
+
}
|
|
320
|
+
getPrecedingNode() {
|
|
321
|
+
return findLastNodeInPrevSiblings(this.prevSibling);
|
|
322
|
+
}
|
|
323
|
+
getChildPrevSibling() {
|
|
324
|
+
return this.lastChild || this.prevSibling;
|
|
302
325
|
}
|
|
303
|
-
if (!useParentCleaners)
|
|
304
|
-
currentScope.cleaners.push(this);
|
|
305
|
-
}
|
|
306
|
-
getPrecedingNode() {
|
|
307
|
-
return findLastNodeInPrevSiblings(this.prevSibling);
|
|
308
|
-
}
|
|
309
|
-
getChildPrevSibling() {
|
|
310
|
-
return this.lastChild || this.prevSibling;
|
|
311
326
|
}
|
|
312
|
-
}
|
|
313
327
|
|
|
314
|
-
class RegularScope extends ChainedScope {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
class RegularScope extends ChainedScope {
|
|
329
|
+
renderer;
|
|
330
|
+
constructor(el, svg, renderer) {
|
|
331
|
+
super(el, svg);
|
|
332
|
+
this.renderer = renderer;
|
|
333
|
+
this.redraw();
|
|
334
|
+
}
|
|
335
|
+
redraw() {
|
|
336
|
+
const savedScope = currentScope;
|
|
337
|
+
currentScope = this;
|
|
338
|
+
try {
|
|
339
|
+
this.renderer();
|
|
340
|
+
} catch (e) {
|
|
341
|
+
handleError(e, true);
|
|
342
|
+
}
|
|
343
|
+
currentScope = savedScope;
|
|
328
344
|
}
|
|
329
|
-
currentScope = savedScope;
|
|
330
345
|
}
|
|
331
|
-
}
|
|
332
346
|
|
|
333
|
-
class RootScope extends ContentScope {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
347
|
+
class RootScope extends ContentScope {
|
|
348
|
+
el = document ? document.body : undefined;
|
|
349
|
+
svg = false;
|
|
350
|
+
getPrecedingNode() {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
338
353
|
}
|
|
339
|
-
}
|
|
340
354
|
|
|
341
|
-
class MountScope extends ContentScope {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
function removeNodes(node, preNode) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
355
|
+
class MountScope extends ContentScope {
|
|
356
|
+
el;
|
|
357
|
+
renderer;
|
|
358
|
+
svg;
|
|
359
|
+
constructor(el, renderer) {
|
|
360
|
+
super();
|
|
361
|
+
this.el = el;
|
|
362
|
+
this.renderer = renderer;
|
|
363
|
+
this.svg = el.namespaceURI === "http://www.w3.org/2000/svg";
|
|
364
|
+
const oldTopRedrawScope = topRedrawScope;
|
|
365
|
+
topRedrawScope = this;
|
|
366
|
+
this.redraw();
|
|
367
|
+
topRedrawScope = oldTopRedrawScope;
|
|
368
|
+
currentScope.cleaners.push(this);
|
|
369
|
+
}
|
|
370
|
+
redraw() {
|
|
371
|
+
RegularScope.prototype.redraw.call(this);
|
|
372
|
+
}
|
|
373
|
+
getPrecedingNode() {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
delete() {
|
|
377
|
+
removeNodes(this.getLastNode(), this.getPrecedingNode());
|
|
378
|
+
const savedSurvivingEl = survivingEl;
|
|
379
|
+
survivingEl = this.el;
|
|
380
|
+
super.delete();
|
|
381
|
+
survivingEl = savedSurvivingEl;
|
|
382
|
+
}
|
|
383
|
+
remove() {
|
|
384
|
+
this.delete();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function removeNodes(node, preNode) {
|
|
388
|
+
while (node && node !== preNode) {
|
|
389
|
+
const prevNode = node.previousSibling;
|
|
390
|
+
const onDestroy = onDestroyMap.get(node);
|
|
391
|
+
if (onDestroy && node instanceof Element) {
|
|
392
|
+
if (onDestroy !== true) {
|
|
393
|
+
if (typeof onDestroy === "function") {
|
|
394
|
+
onDestroy(node);
|
|
395
|
+
} else {
|
|
396
|
+
destroyWithClass(node, onDestroy);
|
|
397
|
+
}
|
|
398
|
+
onDestroyMap.set(node, true);
|
|
383
399
|
}
|
|
384
|
-
|
|
400
|
+
} else {
|
|
401
|
+
node.remove();
|
|
385
402
|
}
|
|
386
|
-
|
|
387
|
-
node.remove();
|
|
388
|
-
}
|
|
389
|
-
node = prevNode;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function findLastNodeInPrevSiblings(sibling) {
|
|
393
|
-
if (!sibling || sibling instanceof Node)
|
|
394
|
-
return sibling;
|
|
395
|
-
return sibling.getLastNode() || sibling.getPrecedingNode();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
class ResultScope extends ChainedScope {
|
|
399
|
-
renderer;
|
|
400
|
-
result = optProxy({ value: undefined });
|
|
401
|
-
constructor(renderer) {
|
|
402
|
-
super(currentScope.el, currentScope.svg);
|
|
403
|
-
this.renderer = renderer;
|
|
404
|
-
this.redraw();
|
|
405
|
-
}
|
|
406
|
-
redraw() {
|
|
407
|
-
const savedScope = currentScope;
|
|
408
|
-
currentScope = this;
|
|
409
|
-
try {
|
|
410
|
-
this.result.value = this.renderer();
|
|
411
|
-
} catch (e) {
|
|
412
|
-
handleError(e, true);
|
|
403
|
+
node = prevNode;
|
|
413
404
|
}
|
|
414
|
-
currentScope = savedScope;
|
|
415
405
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
target;
|
|
421
|
-
svg = false;
|
|
422
|
-
constructor(el, key, target) {
|
|
423
|
-
super(el, el.namespaceURI === "http://www.w3.org/2000/svg");
|
|
424
|
-
this.key = key;
|
|
425
|
-
this.target = target;
|
|
426
|
-
this.redraw();
|
|
427
|
-
}
|
|
428
|
-
redraw() {
|
|
429
|
-
const savedScope = currentScope;
|
|
430
|
-
currentScope = this;
|
|
431
|
-
applyArg(this.el, this.key, this.target.value);
|
|
432
|
-
currentScope = savedScope;
|
|
406
|
+
function findLastNodeInPrevSiblings(sibling) {
|
|
407
|
+
if (!sibling || !(sibling instanceof Scope))
|
|
408
|
+
return sibling;
|
|
409
|
+
return sibling.getLastNode() || sibling.getPrecedingNode();
|
|
433
410
|
}
|
|
434
|
-
}
|
|
435
411
|
|
|
436
|
-
class
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.prevSibling = currentScope.getChildPrevSibling();
|
|
452
|
-
currentScope.lastChild = this;
|
|
453
|
-
currentScope.cleaners.push(this);
|
|
454
|
-
if (target instanceof Array) {
|
|
455
|
-
for (let i = 0;i < target.length; i++) {
|
|
456
|
-
new OnEachItemScope(this, i, false);
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
for (const key of target instanceof Map ? target.keys() : target instanceof Set ? target.values() : Object.keys(target)) {
|
|
460
|
-
new OnEachItemScope(this, key, false);
|
|
412
|
+
class ResultScope extends ChainedScope {
|
|
413
|
+
renderer;
|
|
414
|
+
result = optProxy({ value: undefined });
|
|
415
|
+
constructor(renderer) {
|
|
416
|
+
super(currentScope.el, currentScope.svg);
|
|
417
|
+
this.renderer = renderer;
|
|
418
|
+
this.redraw();
|
|
419
|
+
}
|
|
420
|
+
redraw() {
|
|
421
|
+
const savedScope = currentScope;
|
|
422
|
+
currentScope = this;
|
|
423
|
+
try {
|
|
424
|
+
this.result.value = this.renderer();
|
|
425
|
+
} catch (e) {
|
|
426
|
+
handleError(e, true);
|
|
461
427
|
}
|
|
428
|
+
currentScope = savedScope;
|
|
462
429
|
}
|
|
463
430
|
}
|
|
464
|
-
|
|
465
|
-
|
|
431
|
+
|
|
432
|
+
class SetArgScope extends ChainedScope {
|
|
433
|
+
key;
|
|
434
|
+
target;
|
|
435
|
+
svg = false;
|
|
436
|
+
constructor(el, key, target) {
|
|
437
|
+
super(el, el.namespaceURI === "http://www.w3.org/2000/svg");
|
|
438
|
+
this.key = key;
|
|
439
|
+
this.target = target;
|
|
440
|
+
this.redraw();
|
|
441
|
+
}
|
|
442
|
+
redraw() {
|
|
443
|
+
const savedScope = currentScope;
|
|
444
|
+
currentScope = this;
|
|
445
|
+
applyArg(this.el, this.key, this.target.value);
|
|
446
|
+
currentScope = savedScope;
|
|
447
|
+
}
|
|
466
448
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
449
|
+
|
|
450
|
+
class OnEachScope extends Scope {
|
|
451
|
+
renderer;
|
|
452
|
+
makeSortKey;
|
|
453
|
+
parentElement = currentScope.el;
|
|
454
|
+
prevSibling;
|
|
455
|
+
target;
|
|
456
|
+
byIndex = new Map;
|
|
457
|
+
sortedSet = new ReverseSortedSet("sortKey");
|
|
458
|
+
changedIndexes = new Map;
|
|
459
|
+
constructor(proxy2, renderer, makeSortKey) {
|
|
460
|
+
super();
|
|
461
|
+
this.renderer = renderer;
|
|
462
|
+
this.makeSortKey = makeSortKey;
|
|
463
|
+
const target = this.target = proxy2[TARGET_SYMBOL] || proxy2;
|
|
464
|
+
subscribe(target, ANY_SYMBOL, this);
|
|
465
|
+
this.prevSibling = currentScope.getChildPrevSibling();
|
|
466
|
+
currentScope.lastChild = this;
|
|
467
|
+
currentScope.cleaners.push(this);
|
|
468
|
+
if (target instanceof Array) {
|
|
469
|
+
for (let i = 0;i < target.length; i++) {
|
|
470
|
+
new OnEachItemScope(this, i, false);
|
|
472
471
|
}
|
|
473
472
|
} else {
|
|
474
|
-
|
|
475
|
-
|
|
473
|
+
for (const key of target instanceof Map ? target.keys() : target instanceof Set ? target.values() : Object.keys(target)) {
|
|
474
|
+
new OnEachItemScope(this, key, false);
|
|
475
|
+
}
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
478
|
+
getPrecedingNode() {
|
|
479
|
+
return findLastNodeInPrevSiblings(this.prevSibling);
|
|
480
|
+
}
|
|
481
|
+
onChange(target, index, newData, oldData) {
|
|
482
|
+
if (!(target instanceof Array) || typeof index === "number") {
|
|
483
|
+
if (this.changedIndexes.has(index)) {
|
|
484
|
+
if (this.changedIndexes.get(index) === newData) {
|
|
485
|
+
this.changedIndexes.delete(index);
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
this.changedIndexes.set(index, oldData);
|
|
489
|
+
queue(this);
|
|
490
|
+
}
|
|
490
491
|
}
|
|
491
492
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
493
|
+
queueRun() {
|
|
494
|
+
const indexes = this.changedIndexes;
|
|
495
|
+
this.changedIndexes = new Map;
|
|
496
|
+
for (const index of indexes.keys()) {
|
|
497
|
+
const oldScope = this.byIndex.get(index);
|
|
498
|
+
if (oldScope)
|
|
499
|
+
oldScope.remove();
|
|
500
|
+
if (this.target instanceof Set || this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
|
|
501
|
+
new OnEachItemScope(this, index, true);
|
|
502
|
+
} else {
|
|
503
|
+
this.byIndex.delete(index);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
topRedrawScope = undefined;
|
|
497
507
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
508
|
+
delete() {
|
|
509
|
+
for (const scope of this.byIndex.values()) {
|
|
510
|
+
scope.delete();
|
|
511
|
+
}
|
|
512
|
+
sortedQueue?.remove(this);
|
|
513
|
+
this.byIndex.clear();
|
|
514
|
+
setTimeout(() => {
|
|
515
|
+
this.sortedSet.clear();
|
|
516
|
+
}, 1);
|
|
517
|
+
}
|
|
518
|
+
getLastNode() {
|
|
519
|
+
for (const scope of this.sortedSet) {
|
|
520
|
+
const node = scope.getActualLastNode();
|
|
521
|
+
if (node)
|
|
522
|
+
return node;
|
|
523
|
+
}
|
|
509
524
|
}
|
|
510
525
|
}
|
|
511
|
-
}
|
|
512
526
|
|
|
513
|
-
class OnEachItemScope extends ContentScope {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
queueRun() {
|
|
553
|
-
if (currentScope !== ROOT_SCOPE)
|
|
554
|
-
internalError(4);
|
|
555
|
-
if (!this.fetchHasChanges())
|
|
556
|
-
return;
|
|
557
|
-
if (this.sortKey !== undefined) {
|
|
558
|
-
const lastNode = this.getActualLastNode();
|
|
559
|
-
if (lastNode)
|
|
560
|
-
removeNodes(lastNode, this.getPrecedingNode());
|
|
561
|
-
}
|
|
562
|
-
const savedSurvivingEl = survivingEl;
|
|
563
|
-
survivingEl = this.el;
|
|
564
|
-
this.delete();
|
|
565
|
-
survivingEl = savedSurvivingEl;
|
|
566
|
-
this.lastChild = this;
|
|
567
|
-
topRedrawScope = this;
|
|
568
|
-
this.redraw();
|
|
569
|
-
topRedrawScope = undefined;
|
|
570
|
-
}
|
|
571
|
-
redraw() {
|
|
572
|
-
let value;
|
|
573
|
-
const target = this.parent.target;
|
|
574
|
-
let itemIndex = this.itemIndex;
|
|
575
|
-
if (target instanceof Set) {
|
|
576
|
-
value = itemIndex = optProxy(itemIndex);
|
|
577
|
-
} else if (target instanceof Map) {
|
|
578
|
-
value = optProxy(target.get(itemIndex));
|
|
579
|
-
itemIndex = optProxy(itemIndex);
|
|
580
|
-
} else {
|
|
581
|
-
value = optProxy(target[itemIndex]);
|
|
527
|
+
class OnEachItemScope extends ContentScope {
|
|
528
|
+
parent;
|
|
529
|
+
itemIndex;
|
|
530
|
+
sortKey;
|
|
531
|
+
el;
|
|
532
|
+
svg;
|
|
533
|
+
constructor(parent, itemIndex, topRedraw) {
|
|
534
|
+
super();
|
|
535
|
+
this.parent = parent;
|
|
536
|
+
this.itemIndex = itemIndex;
|
|
537
|
+
this.el = parent.parentElement;
|
|
538
|
+
this.svg = currentScope.svg;
|
|
539
|
+
this.parent.byIndex.set(this.itemIndex, this);
|
|
540
|
+
this.lastChild = this;
|
|
541
|
+
if (topRedraw)
|
|
542
|
+
topRedrawScope = this;
|
|
543
|
+
this.redraw();
|
|
544
|
+
}
|
|
545
|
+
getPrecedingNode() {
|
|
546
|
+
this.parent.sortedSet.add(this);
|
|
547
|
+
const preScope = this.parent.sortedSet.prev(this);
|
|
548
|
+
if (preScope)
|
|
549
|
+
return findLastNodeInPrevSiblings(preScope.lastChild);
|
|
550
|
+
return this.parent.getPrecedingNode();
|
|
551
|
+
}
|
|
552
|
+
getLastNode() {
|
|
553
|
+
return this.getPrecedingNode();
|
|
554
|
+
}
|
|
555
|
+
getActualLastNode() {
|
|
556
|
+
let child = this.lastChild;
|
|
557
|
+
while (child && child !== this) {
|
|
558
|
+
if (!(child instanceof Scope))
|
|
559
|
+
return child;
|
|
560
|
+
const node = child.getLastNode();
|
|
561
|
+
if (node)
|
|
562
|
+
return node;
|
|
563
|
+
child = child.getPrecedingNode();
|
|
564
|
+
}
|
|
582
565
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
566
|
+
queueRun() {
|
|
567
|
+
if (currentScope !== ROOT_SCOPE)
|
|
568
|
+
internalError(4);
|
|
569
|
+
if (!this.fetchHasChanges())
|
|
570
|
+
return;
|
|
571
|
+
if (this.sortKey !== undefined) {
|
|
572
|
+
const lastNode = this.getActualLastNode();
|
|
573
|
+
if (lastNode)
|
|
574
|
+
removeNodes(lastNode, this.getPrecedingNode());
|
|
575
|
+
}
|
|
576
|
+
const savedSurvivingEl = survivingEl;
|
|
577
|
+
survivingEl = this.el;
|
|
578
|
+
this.delete();
|
|
579
|
+
survivingEl = savedSurvivingEl;
|
|
580
|
+
this.lastChild = this;
|
|
581
|
+
topRedrawScope = this;
|
|
582
|
+
this.redraw();
|
|
583
|
+
topRedrawScope = undefined;
|
|
584
|
+
}
|
|
585
|
+
redraw() {
|
|
586
|
+
let value;
|
|
587
|
+
const target = this.parent.target;
|
|
588
|
+
let itemIndex = this.itemIndex;
|
|
589
|
+
if (target instanceof Set) {
|
|
590
|
+
value = itemIndex = optProxy(itemIndex);
|
|
591
|
+
} else if (target instanceof Map) {
|
|
592
|
+
value = optProxy(target.get(itemIndex));
|
|
593
|
+
itemIndex = optProxy(itemIndex);
|
|
589
594
|
} else {
|
|
590
|
-
|
|
595
|
+
value = optProxy(target[itemIndex]);
|
|
596
|
+
}
|
|
597
|
+
const savedScope = currentScope;
|
|
598
|
+
currentScope = this;
|
|
599
|
+
let sortKey;
|
|
600
|
+
try {
|
|
601
|
+
if (this.parent.makeSortKey) {
|
|
602
|
+
sortKey = this.parent.makeSortKey(value, itemIndex);
|
|
603
|
+
} else {
|
|
604
|
+
sortKey = itemIndex;
|
|
605
|
+
}
|
|
606
|
+
if (sortKey instanceof Array)
|
|
607
|
+
sortKey = arrayToStr(sortKey);
|
|
608
|
+
else if (typeof sortKey !== "string" && sortKey != null)
|
|
609
|
+
sortKey = arrayToStr([sortKey]);
|
|
610
|
+
if (this.sortKey !== sortKey) {
|
|
611
|
+
this.parent.sortedSet.remove(this);
|
|
612
|
+
this.sortKey = sortKey;
|
|
613
|
+
}
|
|
614
|
+
if (sortKey != null)
|
|
615
|
+
this.parent.renderer(value, itemIndex);
|
|
616
|
+
} catch (e) {
|
|
617
|
+
handleError(e, sortKey != null);
|
|
591
618
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
619
|
+
currentScope = savedScope;
|
|
620
|
+
}
|
|
621
|
+
getInsertAfterNode() {
|
|
622
|
+
if (this.sortKey == null)
|
|
623
|
+
internalError(1);
|
|
624
|
+
return findLastNodeInPrevSiblings(this.lastChild);
|
|
625
|
+
}
|
|
626
|
+
remove() {
|
|
627
|
+
if (this.sortKey !== undefined) {
|
|
628
|
+
const lastNode = this.getActualLastNode();
|
|
629
|
+
if (lastNode)
|
|
630
|
+
removeNodes(lastNode, this.getPrecedingNode());
|
|
597
631
|
this.parent.sortedSet.remove(this);
|
|
598
|
-
this.sortKey =
|
|
632
|
+
this.sortKey = undefined;
|
|
599
633
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
634
|
+
const savedSurvivingEl = survivingEl;
|
|
635
|
+
survivingEl = this.el;
|
|
636
|
+
this.delete();
|
|
637
|
+
survivingEl = savedSurvivingEl;
|
|
604
638
|
}
|
|
605
|
-
currentScope = savedScope;
|
|
606
639
|
}
|
|
607
|
-
|
|
608
|
-
if (
|
|
609
|
-
|
|
610
|
-
|
|
640
|
+
function addNode(el, node) {
|
|
641
|
+
if (el !== currentScope.el) {
|
|
642
|
+
el.appendChild(node);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const parentEl = currentScope.el;
|
|
646
|
+
const prevNode = currentScope.getInsertAfterNode();
|
|
647
|
+
parentEl.insertBefore(node, prevNode ? prevNode.nextSibling : parentEl.firstChild);
|
|
648
|
+
currentScope.lastChild = node;
|
|
611
649
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
650
|
+
const ROOT_SCOPE = new RootScope;
|
|
651
|
+
let currentScope = ROOT_SCOPE;
|
|
652
|
+
function leakScope(func) {
|
|
653
|
+
const savedScope = currentScope;
|
|
654
|
+
currentScope = new RootScope;
|
|
655
|
+
try {
|
|
656
|
+
return func();
|
|
657
|
+
} finally {
|
|
658
|
+
currentScope = savedScope;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const ANY_SYMBOL = Symbol("any");
|
|
662
|
+
const TARGET_SYMBOL = Symbol("target");
|
|
663
|
+
const MAP_SIZE_SYMBOL = Symbol("mapSize");
|
|
664
|
+
const subscribers = new WeakMap;
|
|
665
|
+
let peeking = 0;
|
|
666
|
+
function subscribe(target, index, observer = currentScope) {
|
|
667
|
+
if (observer === ROOT_SCOPE || peeking)
|
|
668
|
+
return;
|
|
669
|
+
let byTarget = subscribers.get(target);
|
|
670
|
+
if (!byTarget)
|
|
671
|
+
subscribers.set(target, byTarget = new Map);
|
|
672
|
+
if (index !== ANY_SYMBOL && byTarget.get(ANY_SYMBOL)?.has(observer))
|
|
673
|
+
return;
|
|
674
|
+
let byIndex = byTarget.get(index);
|
|
675
|
+
if (!byIndex)
|
|
676
|
+
byTarget.set(index, byIndex = new Set);
|
|
677
|
+
if (byIndex.has(observer))
|
|
678
|
+
return;
|
|
679
|
+
byIndex.add(observer);
|
|
680
|
+
if (observer === currentScope) {
|
|
681
|
+
currentScope.cleaners.push(byIndex);
|
|
682
|
+
} else {
|
|
683
|
+
currentScope.cleaners.push(() => {
|
|
684
|
+
byIndex.delete(observer);
|
|
685
|
+
});
|
|
619
686
|
}
|
|
620
|
-
const savedSurvivingEl = survivingEl;
|
|
621
|
-
survivingEl = this.el;
|
|
622
|
-
this.delete();
|
|
623
|
-
survivingEl = savedSurvivingEl;
|
|
624
687
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
const parentEl = currentScope.el;
|
|
632
|
-
const prevNode = currentScope.getInsertAfterNode();
|
|
633
|
-
parentEl.insertBefore(node, prevNode ? prevNode.nextSibling : parentEl.firstChild);
|
|
634
|
-
currentScope.lastChild = node;
|
|
635
|
-
}
|
|
636
|
-
var ROOT_SCOPE = new RootScope;
|
|
637
|
-
var currentScope = ROOT_SCOPE;
|
|
638
|
-
function leakScope(func) {
|
|
639
|
-
const savedScope = currentScope;
|
|
640
|
-
currentScope = new RootScope;
|
|
641
|
-
try {
|
|
642
|
-
return func();
|
|
643
|
-
} finally {
|
|
644
|
-
currentScope = savedScope;
|
|
688
|
+
function onEach(target, render, makeKey) {
|
|
689
|
+
if (!target || typeof target !== "object")
|
|
690
|
+
throw new Error("A.onEach requires an object");
|
|
691
|
+
target = target[TARGET_SYMBOL] || target;
|
|
692
|
+
new OnEachScope(target, render, makeKey);
|
|
645
693
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
var subscribers = new WeakMap;
|
|
651
|
-
var peeking = 0;
|
|
652
|
-
function subscribe(target, index, observer = currentScope) {
|
|
653
|
-
if (observer === ROOT_SCOPE || peeking)
|
|
654
|
-
return;
|
|
655
|
-
let byTarget = subscribers.get(target);
|
|
656
|
-
if (!byTarget)
|
|
657
|
-
subscribers.set(target, byTarget = new Map);
|
|
658
|
-
if (index !== ANY_SYMBOL && byTarget.get(ANY_SYMBOL)?.has(observer))
|
|
659
|
-
return;
|
|
660
|
-
let byIndex = byTarget.get(index);
|
|
661
|
-
if (!byIndex)
|
|
662
|
-
byTarget.set(index, byIndex = new Set);
|
|
663
|
-
if (byIndex.has(observer))
|
|
664
|
-
return;
|
|
665
|
-
byIndex.add(observer);
|
|
666
|
-
if (observer === currentScope) {
|
|
667
|
-
currentScope.cleaners.push(byIndex);
|
|
668
|
-
} else {
|
|
669
|
-
currentScope.cleaners.push(() => {
|
|
670
|
-
byIndex.delete(observer);
|
|
671
|
-
});
|
|
694
|
+
function isObjEmpty(obj) {
|
|
695
|
+
for (const k of Object.keys(obj))
|
|
696
|
+
return false;
|
|
697
|
+
return true;
|
|
672
698
|
}
|
|
673
|
-
|
|
674
|
-
function
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
699
|
+
const EMPTY = Symbol("empty");
|
|
700
|
+
function isEmpty(proxied) {
|
|
701
|
+
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
702
|
+
const scope = currentScope;
|
|
703
|
+
if (target instanceof Array) {
|
|
704
|
+
subscribe(target, "length", (index, newData, oldData) => {
|
|
705
|
+
if (!newData !== !oldData)
|
|
706
|
+
scope.onChange(target, EMPTY, !newData, !oldData);
|
|
707
|
+
});
|
|
708
|
+
return !target.length;
|
|
709
|
+
}
|
|
710
|
+
if (target instanceof Map || target instanceof Set) {
|
|
711
|
+
subscribe(target, MAP_SIZE_SYMBOL, (index, newData, oldData) => {
|
|
712
|
+
if (!newData !== !oldData)
|
|
713
|
+
scope.onChange(target, EMPTY, !newData, !oldData);
|
|
714
|
+
});
|
|
715
|
+
return !target.size;
|
|
716
|
+
}
|
|
717
|
+
let oldEmpty = isObjEmpty(target);
|
|
718
|
+
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
719
|
+
if (newData === EMPTY !== (oldData === EMPTY)) {
|
|
720
|
+
const newEmpty = isObjEmpty(target);
|
|
721
|
+
scope.onChange(target, EMPTY, newEmpty, oldEmpty);
|
|
722
|
+
oldEmpty = newEmpty;
|
|
723
|
+
}
|
|
693
724
|
});
|
|
694
|
-
return
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
725
|
+
return oldEmpty;
|
|
726
|
+
}
|
|
727
|
+
function count(proxied) {
|
|
728
|
+
if (proxied instanceof Array)
|
|
729
|
+
return ref(proxied, "length");
|
|
730
|
+
if (proxied instanceof Map || proxied instanceof Set)
|
|
731
|
+
return ref(proxied, "size");
|
|
732
|
+
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
733
|
+
let cnt = 0;
|
|
734
|
+
for (const k of Object.keys(target))
|
|
735
|
+
if (target[k] !== undefined)
|
|
736
|
+
cnt++;
|
|
737
|
+
const result = proxy(cnt);
|
|
738
|
+
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
739
|
+
if (oldData === newData) {} else if (oldData === EMPTY)
|
|
740
|
+
result.value = ++cnt;
|
|
741
|
+
else if (newData === EMPTY)
|
|
742
|
+
result.value = --cnt;
|
|
700
743
|
});
|
|
701
|
-
return
|
|
744
|
+
return result;
|
|
702
745
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
719
|
-
let cnt = 0;
|
|
720
|
-
for (const k of Object.keys(target))
|
|
721
|
-
if (target[k] !== undefined)
|
|
722
|
-
cnt++;
|
|
723
|
-
const result = proxy(cnt);
|
|
724
|
-
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
725
|
-
if (oldData === newData) {} else if (oldData === EMPTY)
|
|
726
|
-
result.value = ++cnt;
|
|
727
|
-
else if (newData === EMPTY)
|
|
728
|
-
result.value = --cnt;
|
|
729
|
-
});
|
|
730
|
-
return result;
|
|
731
|
-
}
|
|
732
|
-
function defaultEmitHandler(target, index, newData, oldData) {
|
|
733
|
-
if (newData === oldData && newData !== undefined)
|
|
734
|
-
return;
|
|
735
|
-
const byTarget = subscribers.get(target);
|
|
736
|
-
if (byTarget === undefined)
|
|
737
|
-
return;
|
|
738
|
-
for (const what of [index, ANY_SYMBOL]) {
|
|
739
|
-
const byIndex = byTarget.get(what);
|
|
740
|
-
if (byIndex) {
|
|
741
|
-
for (const observer of byIndex) {
|
|
742
|
-
if (typeof observer === "function")
|
|
743
|
-
observer(index, newData, oldData);
|
|
744
|
-
else
|
|
745
|
-
observer.onChange(target, index, newData, oldData);
|
|
746
|
+
function defaultEmitHandler(target, index, newData, oldData) {
|
|
747
|
+
if (newData === oldData && newData !== undefined)
|
|
748
|
+
return;
|
|
749
|
+
const byTarget = subscribers.get(target);
|
|
750
|
+
if (byTarget === undefined)
|
|
751
|
+
return;
|
|
752
|
+
for (const what of [index, ANY_SYMBOL]) {
|
|
753
|
+
const byIndex = byTarget.get(what);
|
|
754
|
+
if (byIndex) {
|
|
755
|
+
for (const observer of byIndex) {
|
|
756
|
+
if (typeof observer === "function")
|
|
757
|
+
observer(index, newData, oldData);
|
|
758
|
+
else
|
|
759
|
+
observer.onChange(target, index, newData, oldData);
|
|
760
|
+
}
|
|
746
761
|
}
|
|
747
762
|
}
|
|
748
763
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
764
|
+
let emit = defaultEmitHandler;
|
|
765
|
+
const objectHandler = {
|
|
766
|
+
get(target, prop) {
|
|
767
|
+
if (prop === TARGET_SYMBOL)
|
|
768
|
+
return target;
|
|
769
|
+
subscribe(target, prop);
|
|
770
|
+
return optProxy(target[prop]);
|
|
771
|
+
},
|
|
772
|
+
set(target, prop, newData) {
|
|
773
|
+
if (typeof newData === "object" && newData)
|
|
774
|
+
newData = newData[TARGET_SYMBOL] || newData;
|
|
775
|
+
const oldData = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
|
|
776
|
+
if (newData !== oldData) {
|
|
777
|
+
target[prop] = newData;
|
|
778
|
+
emit(target, prop, newData, oldData);
|
|
779
|
+
}
|
|
780
|
+
return true;
|
|
781
|
+
},
|
|
782
|
+
deleteProperty(target, prop) {
|
|
783
|
+
const old = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
|
|
784
|
+
delete target[prop];
|
|
785
|
+
emit(target, prop, EMPTY, old);
|
|
786
|
+
return true;
|
|
787
|
+
},
|
|
788
|
+
has(target, prop) {
|
|
789
|
+
subscribe(target, prop);
|
|
790
|
+
return target.hasOwnProperty(prop);
|
|
791
|
+
},
|
|
792
|
+
ownKeys(target) {
|
|
793
|
+
subscribe(target, ANY_SYMBOL);
|
|
794
|
+
return Reflect.ownKeys(target);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
function arraySet(target, prop, newData) {
|
|
798
|
+
if (typeof newData === "object" && newData) {
|
|
760
799
|
newData = newData[TARGET_SYMBOL] || newData;
|
|
761
|
-
|
|
800
|
+
}
|
|
801
|
+
let oldData = target[prop];
|
|
802
|
+
if (oldData === undefined && !target.hasOwnProperty(prop))
|
|
803
|
+
oldData = EMPTY;
|
|
762
804
|
if (newData !== oldData) {
|
|
763
|
-
|
|
764
|
-
|
|
805
|
+
const oldLength = target.length;
|
|
806
|
+
if (prop === "length") {
|
|
807
|
+
target.length = newData;
|
|
808
|
+
for (let i = newData;i < oldLength; i++) {
|
|
809
|
+
emit(target, i, EMPTY, target[i]);
|
|
810
|
+
}
|
|
811
|
+
} else {
|
|
812
|
+
if (typeof prop === "string") {
|
|
813
|
+
const n = 0 | prop;
|
|
814
|
+
if (String(n) === prop && n >= 0)
|
|
815
|
+
prop = n;
|
|
816
|
+
}
|
|
817
|
+
target[prop] = newData;
|
|
818
|
+
emit(target, prop, newData, oldData);
|
|
819
|
+
}
|
|
820
|
+
if (target.length !== oldLength) {
|
|
821
|
+
emit(target, "length", target.length, oldLength);
|
|
822
|
+
}
|
|
765
823
|
}
|
|
766
824
|
return true;
|
|
767
|
-
},
|
|
768
|
-
deleteProperty(target, prop) {
|
|
769
|
-
const old = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
|
|
770
|
-
delete target[prop];
|
|
771
|
-
emit(target, prop, EMPTY, old);
|
|
772
|
-
return true;
|
|
773
|
-
},
|
|
774
|
-
has(target, prop) {
|
|
775
|
-
subscribe(target, prop);
|
|
776
|
-
return target.hasOwnProperty(prop);
|
|
777
|
-
},
|
|
778
|
-
ownKeys(target) {
|
|
779
|
-
subscribe(target, ANY_SYMBOL);
|
|
780
|
-
return Reflect.ownKeys(target);
|
|
781
825
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
if (newData !== oldData) {
|
|
791
|
-
const oldLength = target.length;
|
|
792
|
-
if (prop === "length") {
|
|
793
|
-
target.length = newData;
|
|
794
|
-
for (let i = newData;i < oldLength; i++) {
|
|
795
|
-
emit(target, i, EMPTY, target[i]);
|
|
826
|
+
const arrayHandler = {
|
|
827
|
+
get(target, prop) {
|
|
828
|
+
if (prop === TARGET_SYMBOL)
|
|
829
|
+
return target;
|
|
830
|
+
if (typeof prop === "string") {
|
|
831
|
+
const n = 0 | prop;
|
|
832
|
+
if (String(n) === prop && n >= 0)
|
|
833
|
+
prop = n;
|
|
796
834
|
}
|
|
797
|
-
|
|
835
|
+
subscribe(target, prop);
|
|
836
|
+
return optProxy(target[prop]);
|
|
837
|
+
},
|
|
838
|
+
set: arraySet,
|
|
839
|
+
deleteProperty(target, prop) {
|
|
798
840
|
if (typeof prop === "string") {
|
|
799
841
|
const n = 0 | prop;
|
|
800
842
|
if (String(n) === prop && n >= 0)
|
|
801
843
|
prop = n;
|
|
802
844
|
}
|
|
803
|
-
target[prop]
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
emit(target,
|
|
845
|
+
let oldData = target[prop];
|
|
846
|
+
if (oldData === undefined && !target.hasOwnProperty(prop))
|
|
847
|
+
oldData = EMPTY;
|
|
848
|
+
delete target[prop];
|
|
849
|
+
emit(target, prop, EMPTY, oldData);
|
|
850
|
+
return true;
|
|
808
851
|
}
|
|
852
|
+
};
|
|
853
|
+
function wrapIteratorSingle(iterator) {
|
|
854
|
+
return {
|
|
855
|
+
[Symbol.iterator]() {
|
|
856
|
+
return this;
|
|
857
|
+
},
|
|
858
|
+
next() {
|
|
859
|
+
const result = iterator.next();
|
|
860
|
+
if (result.done)
|
|
861
|
+
return result;
|
|
862
|
+
return {
|
|
863
|
+
done: false,
|
|
864
|
+
value: optProxy(result.value)
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
};
|
|
809
868
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
deleteProperty(target, prop) {
|
|
826
|
-
if (typeof prop === "string") {
|
|
827
|
-
const n = 0 | prop;
|
|
828
|
-
if (String(n) === prop && n >= 0)
|
|
829
|
-
prop = n;
|
|
830
|
-
}
|
|
831
|
-
let oldData = target[prop];
|
|
832
|
-
if (oldData === undefined && !target.hasOwnProperty(prop))
|
|
833
|
-
oldData = EMPTY;
|
|
834
|
-
delete target[prop];
|
|
835
|
-
emit(target, prop, EMPTY, oldData);
|
|
836
|
-
return true;
|
|
869
|
+
function wrapIteratorPair(iterator) {
|
|
870
|
+
return {
|
|
871
|
+
[Symbol.iterator]() {
|
|
872
|
+
return this;
|
|
873
|
+
},
|
|
874
|
+
next() {
|
|
875
|
+
const result = iterator.next();
|
|
876
|
+
if (result.done)
|
|
877
|
+
return result;
|
|
878
|
+
return {
|
|
879
|
+
done: false,
|
|
880
|
+
value: [optProxy(result.value[0]), optProxy(result.value[1])]
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
};
|
|
837
884
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
885
|
+
function unproxyCollectionValue(value) {
|
|
886
|
+
return typeof value === "object" && value ? value[TARGET_SYMBOL] || value : value;
|
|
887
|
+
}
|
|
888
|
+
const mapMethodHandlers = {
|
|
889
|
+
get(key) {
|
|
890
|
+
const target = this[TARGET_SYMBOL];
|
|
891
|
+
key = unproxyCollectionValue(key);
|
|
892
|
+
subscribe(target, key);
|
|
893
|
+
return optProxy(target.get(key));
|
|
894
|
+
},
|
|
895
|
+
set(key, newData) {
|
|
896
|
+
const target = this[TARGET_SYMBOL];
|
|
897
|
+
key = unproxyCollectionValue(key);
|
|
898
|
+
newData = unproxyCollectionValue(newData);
|
|
899
|
+
let oldData = target.get(key);
|
|
900
|
+
if (oldData === undefined && !target.has(key))
|
|
901
|
+
oldData = EMPTY;
|
|
902
|
+
if (newData !== oldData) {
|
|
903
|
+
const oldSize = target.size;
|
|
904
|
+
target.set(key, newData);
|
|
905
|
+
emit(target, key, newData, oldData);
|
|
906
|
+
emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
|
|
907
|
+
}
|
|
842
908
|
return this;
|
|
843
909
|
},
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
910
|
+
delete(key) {
|
|
911
|
+
const target = this[TARGET_SYMBOL];
|
|
912
|
+
key = unproxyCollectionValue(key);
|
|
913
|
+
let oldData = target.get(key);
|
|
914
|
+
if (oldData === undefined && !target.has(key))
|
|
915
|
+
oldData = EMPTY;
|
|
916
|
+
const result = target.delete(key);
|
|
917
|
+
if (result) {
|
|
918
|
+
emit(target, key, EMPTY, oldData);
|
|
919
|
+
emit(target, MAP_SIZE_SYMBOL, target.size, target.size + 1);
|
|
920
|
+
}
|
|
921
|
+
return result;
|
|
922
|
+
},
|
|
923
|
+
clear() {
|
|
924
|
+
const target = this[TARGET_SYMBOL];
|
|
925
|
+
const oldSize = target.size;
|
|
926
|
+
for (const key of target.keys()) {
|
|
927
|
+
emit(target, key, undefined, target.get(key));
|
|
928
|
+
}
|
|
929
|
+
target.clear();
|
|
930
|
+
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
931
|
+
},
|
|
932
|
+
has(key) {
|
|
933
|
+
const target = this[TARGET_SYMBOL];
|
|
934
|
+
key = unproxyCollectionValue(key);
|
|
935
|
+
subscribe(target, key);
|
|
936
|
+
return target.has(key);
|
|
937
|
+
},
|
|
938
|
+
keys() {
|
|
939
|
+
const target = this[TARGET_SYMBOL];
|
|
940
|
+
subscribe(target, ANY_SYMBOL);
|
|
941
|
+
return wrapIteratorSingle(target.keys());
|
|
942
|
+
},
|
|
943
|
+
values() {
|
|
944
|
+
const target = this[TARGET_SYMBOL];
|
|
945
|
+
subscribe(target, ANY_SYMBOL);
|
|
946
|
+
return wrapIteratorSingle(target.values());
|
|
947
|
+
},
|
|
948
|
+
entries() {
|
|
949
|
+
const target = this[TARGET_SYMBOL];
|
|
950
|
+
subscribe(target, ANY_SYMBOL);
|
|
951
|
+
return wrapIteratorPair(target.entries());
|
|
952
|
+
},
|
|
953
|
+
[Symbol.iterator]() {
|
|
954
|
+
const target = this[TARGET_SYMBOL];
|
|
955
|
+
subscribe(target, ANY_SYMBOL);
|
|
956
|
+
return wrapIteratorPair(target[Symbol.iterator]());
|
|
852
957
|
}
|
|
853
958
|
};
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
959
|
+
const setMethodHandlers = {
|
|
960
|
+
add(value) {
|
|
961
|
+
const target = this[TARGET_SYMBOL];
|
|
962
|
+
value = unproxyCollectionValue(value);
|
|
963
|
+
if (!target.has(value)) {
|
|
964
|
+
const oldSize = target.size;
|
|
965
|
+
target.add(value);
|
|
966
|
+
emit(target, value, value, EMPTY);
|
|
967
|
+
emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
|
|
968
|
+
}
|
|
858
969
|
return this;
|
|
859
970
|
},
|
|
860
|
-
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
done: false,
|
|
866
|
-
value: [optProxy(result.value[0]), optProxy(result.value[1])]
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
function unproxyCollectionValue(value) {
|
|
872
|
-
return typeof value === "object" && value ? value[TARGET_SYMBOL] || value : value;
|
|
873
|
-
}
|
|
874
|
-
var mapMethodHandlers = {
|
|
875
|
-
get(key) {
|
|
876
|
-
const target = this[TARGET_SYMBOL];
|
|
877
|
-
key = unproxyCollectionValue(key);
|
|
878
|
-
subscribe(target, key);
|
|
879
|
-
return optProxy(target.get(key));
|
|
880
|
-
},
|
|
881
|
-
set(key, newData) {
|
|
882
|
-
const target = this[TARGET_SYMBOL];
|
|
883
|
-
key = unproxyCollectionValue(key);
|
|
884
|
-
newData = unproxyCollectionValue(newData);
|
|
885
|
-
let oldData = target.get(key);
|
|
886
|
-
if (oldData === undefined && !target.has(key))
|
|
887
|
-
oldData = EMPTY;
|
|
888
|
-
if (newData !== oldData) {
|
|
971
|
+
delete(value) {
|
|
972
|
+
const target = this[TARGET_SYMBOL];
|
|
973
|
+
value = unproxyCollectionValue(value);
|
|
974
|
+
if (!target.has(value))
|
|
975
|
+
return false;
|
|
889
976
|
const oldSize = target.size;
|
|
890
|
-
target.
|
|
891
|
-
emit(target,
|
|
892
|
-
emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
|
|
893
|
-
}
|
|
894
|
-
return this;
|
|
895
|
-
},
|
|
896
|
-
delete(key) {
|
|
897
|
-
const target = this[TARGET_SYMBOL];
|
|
898
|
-
key = unproxyCollectionValue(key);
|
|
899
|
-
let oldData = target.get(key);
|
|
900
|
-
if (oldData === undefined && !target.has(key))
|
|
901
|
-
oldData = EMPTY;
|
|
902
|
-
const result = target.delete(key);
|
|
903
|
-
if (result) {
|
|
904
|
-
emit(target, key, EMPTY, oldData);
|
|
905
|
-
emit(target, MAP_SIZE_SYMBOL, target.size, target.size + 1);
|
|
906
|
-
}
|
|
907
|
-
return result;
|
|
908
|
-
},
|
|
909
|
-
clear() {
|
|
910
|
-
const target = this[TARGET_SYMBOL];
|
|
911
|
-
const oldSize = target.size;
|
|
912
|
-
for (const key of target.keys()) {
|
|
913
|
-
emit(target, key, undefined, target.get(key));
|
|
914
|
-
}
|
|
915
|
-
target.clear();
|
|
916
|
-
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
917
|
-
},
|
|
918
|
-
has(key) {
|
|
919
|
-
const target = this[TARGET_SYMBOL];
|
|
920
|
-
key = unproxyCollectionValue(key);
|
|
921
|
-
subscribe(target, key);
|
|
922
|
-
return target.has(key);
|
|
923
|
-
},
|
|
924
|
-
keys() {
|
|
925
|
-
const target = this[TARGET_SYMBOL];
|
|
926
|
-
subscribe(target, ANY_SYMBOL);
|
|
927
|
-
return wrapIteratorSingle(target.keys());
|
|
928
|
-
},
|
|
929
|
-
values() {
|
|
930
|
-
const target = this[TARGET_SYMBOL];
|
|
931
|
-
subscribe(target, ANY_SYMBOL);
|
|
932
|
-
return wrapIteratorSingle(target.values());
|
|
933
|
-
},
|
|
934
|
-
entries() {
|
|
935
|
-
const target = this[TARGET_SYMBOL];
|
|
936
|
-
subscribe(target, ANY_SYMBOL);
|
|
937
|
-
return wrapIteratorPair(target.entries());
|
|
938
|
-
},
|
|
939
|
-
[Symbol.iterator]() {
|
|
940
|
-
const target = this[TARGET_SYMBOL];
|
|
941
|
-
subscribe(target, ANY_SYMBOL);
|
|
942
|
-
return wrapIteratorPair(target[Symbol.iterator]());
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
var setMethodHandlers = {
|
|
946
|
-
add(value) {
|
|
947
|
-
const target = this[TARGET_SYMBOL];
|
|
948
|
-
value = unproxyCollectionValue(value);
|
|
949
|
-
if (!target.has(value)) {
|
|
950
|
-
const oldSize = target.size;
|
|
951
|
-
target.add(value);
|
|
952
|
-
emit(target, value, value, EMPTY);
|
|
977
|
+
target.delete(value);
|
|
978
|
+
emit(target, value, EMPTY, value);
|
|
953
979
|
emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
|
|
980
|
+
return true;
|
|
981
|
+
},
|
|
982
|
+
clear() {
|
|
983
|
+
const target = this[TARGET_SYMBOL];
|
|
984
|
+
const oldSize = target.size;
|
|
985
|
+
if (!oldSize)
|
|
986
|
+
return;
|
|
987
|
+
for (const value of target.values())
|
|
988
|
+
emit(target, value, EMPTY, value);
|
|
989
|
+
target.clear();
|
|
990
|
+
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
991
|
+
},
|
|
992
|
+
has(value) {
|
|
993
|
+
const target = this[TARGET_SYMBOL];
|
|
994
|
+
value = unproxyCollectionValue(value);
|
|
995
|
+
subscribe(target, value);
|
|
996
|
+
return target.has(value);
|
|
997
|
+
},
|
|
998
|
+
keys() {
|
|
999
|
+
const target = this[TARGET_SYMBOL];
|
|
1000
|
+
subscribe(target, ANY_SYMBOL);
|
|
1001
|
+
return wrapIteratorSingle(target.keys());
|
|
1002
|
+
},
|
|
1003
|
+
values() {
|
|
1004
|
+
const target = this[TARGET_SYMBOL];
|
|
1005
|
+
subscribe(target, ANY_SYMBOL);
|
|
1006
|
+
return wrapIteratorSingle(target.values());
|
|
1007
|
+
},
|
|
1008
|
+
entries() {
|
|
1009
|
+
const target = this[TARGET_SYMBOL];
|
|
1010
|
+
subscribe(target, ANY_SYMBOL);
|
|
1011
|
+
return wrapIteratorPair(target.entries());
|
|
1012
|
+
},
|
|
1013
|
+
[Symbol.iterator]() {
|
|
1014
|
+
const target = this[TARGET_SYMBOL];
|
|
1015
|
+
subscribe(target, ANY_SYMBOL);
|
|
1016
|
+
return wrapIteratorSingle(target[Symbol.iterator]());
|
|
954
1017
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
clear() {
|
|
969
|
-
const target = this[TARGET_SYMBOL];
|
|
970
|
-
const oldSize = target.size;
|
|
971
|
-
if (!oldSize)
|
|
972
|
-
return;
|
|
973
|
-
for (const value of target.values())
|
|
974
|
-
emit(target, value, EMPTY, value);
|
|
975
|
-
target.clear();
|
|
976
|
-
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
977
|
-
},
|
|
978
|
-
has(value) {
|
|
979
|
-
const target = this[TARGET_SYMBOL];
|
|
980
|
-
value = unproxyCollectionValue(value);
|
|
981
|
-
subscribe(target, value);
|
|
982
|
-
return target.has(value);
|
|
983
|
-
},
|
|
984
|
-
keys() {
|
|
985
|
-
const target = this[TARGET_SYMBOL];
|
|
986
|
-
subscribe(target, ANY_SYMBOL);
|
|
987
|
-
return wrapIteratorSingle(target.keys());
|
|
988
|
-
},
|
|
989
|
-
values() {
|
|
990
|
-
const target = this[TARGET_SYMBOL];
|
|
991
|
-
subscribe(target, ANY_SYMBOL);
|
|
992
|
-
return wrapIteratorSingle(target.values());
|
|
993
|
-
},
|
|
994
|
-
entries() {
|
|
995
|
-
const target = this[TARGET_SYMBOL];
|
|
996
|
-
subscribe(target, ANY_SYMBOL);
|
|
997
|
-
return wrapIteratorPair(target.entries());
|
|
998
|
-
},
|
|
999
|
-
[Symbol.iterator]() {
|
|
1000
|
-
const target = this[TARGET_SYMBOL];
|
|
1001
|
-
subscribe(target, ANY_SYMBOL);
|
|
1002
|
-
return wrapIteratorSingle(target[Symbol.iterator]());
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
var mapHandler = {
|
|
1006
|
-
get(target, prop) {
|
|
1007
|
-
if (prop === TARGET_SYMBOL)
|
|
1008
|
-
return target;
|
|
1009
|
-
if (mapMethodHandlers.hasOwnProperty(prop)) {
|
|
1010
|
-
return mapMethodHandlers[prop];
|
|
1018
|
+
};
|
|
1019
|
+
const mapHandler = {
|
|
1020
|
+
get(target, prop) {
|
|
1021
|
+
if (prop === TARGET_SYMBOL)
|
|
1022
|
+
return target;
|
|
1023
|
+
if (mapMethodHandlers.hasOwnProperty(prop)) {
|
|
1024
|
+
return mapMethodHandlers[prop];
|
|
1025
|
+
}
|
|
1026
|
+
if (prop === "size") {
|
|
1027
|
+
subscribe(target, MAP_SIZE_SYMBOL);
|
|
1028
|
+
return target.size;
|
|
1029
|
+
}
|
|
1030
|
+
return target[prop];
|
|
1011
1031
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1032
|
+
};
|
|
1033
|
+
const setHandler = {
|
|
1034
|
+
get(target, prop) {
|
|
1035
|
+
if (prop === TARGET_SYMBOL)
|
|
1036
|
+
return target;
|
|
1037
|
+
if (setMethodHandlers.hasOwnProperty(prop)) {
|
|
1038
|
+
return setMethodHandlers[prop];
|
|
1039
|
+
}
|
|
1040
|
+
if (prop === "size") {
|
|
1041
|
+
subscribe(target, MAP_SIZE_SYMBOL);
|
|
1042
|
+
return target.size;
|
|
1043
|
+
}
|
|
1044
|
+
return target[prop];
|
|
1015
1045
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
1046
|
+
};
|
|
1047
|
+
const proxyMap = new WeakMap;
|
|
1048
|
+
function optProxy(value) {
|
|
1049
|
+
if (typeof value !== "object" || !value || value[TARGET_SYMBOL] !== undefined || value[OPAQUE] || value instanceof Date) {
|
|
1050
|
+
return value;
|
|
1051
|
+
}
|
|
1052
|
+
let proxied = proxyMap.get(value);
|
|
1053
|
+
if (proxied)
|
|
1054
|
+
return proxied;
|
|
1055
|
+
let handler;
|
|
1056
|
+
if (value instanceof Array) {
|
|
1057
|
+
handler = arrayHandler;
|
|
1058
|
+
} else if (value instanceof Map) {
|
|
1059
|
+
handler = mapHandler;
|
|
1060
|
+
} else if (value instanceof Set) {
|
|
1061
|
+
handler = setHandler;
|
|
1062
|
+
} else {
|
|
1063
|
+
handler = objectHandler;
|
|
1025
1064
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1065
|
+
proxied = new Proxy(value, handler);
|
|
1066
|
+
proxyMap.set(value, proxied);
|
|
1067
|
+
return proxied;
|
|
1068
|
+
}
|
|
1069
|
+
function proxy(target) {
|
|
1070
|
+
if (target instanceof Promise) {
|
|
1071
|
+
const result = optProxy({
|
|
1072
|
+
busy: true
|
|
1073
|
+
});
|
|
1074
|
+
target.then((value) => {
|
|
1075
|
+
result.value = value;
|
|
1076
|
+
result.busy = false;
|
|
1077
|
+
}).catch((err) => {
|
|
1078
|
+
result.error = err;
|
|
1079
|
+
result.busy = false;
|
|
1080
|
+
});
|
|
1081
|
+
return result;
|
|
1029
1082
|
}
|
|
1030
|
-
return target
|
|
1083
|
+
return optProxy(typeof target === "object" && target !== null ? target : { value: target });
|
|
1031
1084
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
function optProxy(value) {
|
|
1035
|
-
if (typeof value !== "object" || !value || value[TARGET_SYMBOL] !== undefined || value[OPAQUE] || value instanceof Date) {
|
|
1036
|
-
return value;
|
|
1085
|
+
function unproxy(target) {
|
|
1086
|
+
return target ? target[TARGET_SYMBOL] || target : target;
|
|
1037
1087
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
handler = arrayHandler;
|
|
1044
|
-
} else if (value instanceof Map) {
|
|
1045
|
-
handler = mapHandler;
|
|
1046
|
-
} else if (value instanceof Set) {
|
|
1047
|
-
handler = setHandler;
|
|
1048
|
-
} else {
|
|
1049
|
-
handler = objectHandler;
|
|
1050
|
-
}
|
|
1051
|
-
proxied = new Proxy(value, handler);
|
|
1052
|
-
proxyMap.set(value, proxied);
|
|
1053
|
-
return proxied;
|
|
1054
|
-
}
|
|
1055
|
-
function proxy(target) {
|
|
1056
|
-
if (target instanceof Promise) {
|
|
1057
|
-
const result = optProxy({
|
|
1058
|
-
busy: true
|
|
1059
|
-
});
|
|
1060
|
-
target.then((value) => {
|
|
1061
|
-
result.value = value;
|
|
1062
|
-
result.busy = false;
|
|
1063
|
-
}).catch((err) => {
|
|
1064
|
-
result.error = err;
|
|
1065
|
-
result.busy = false;
|
|
1066
|
-
});
|
|
1067
|
-
return result;
|
|
1088
|
+
const onDestroyMap = new WeakMap;
|
|
1089
|
+
function destroyWithClass(element, cls) {
|
|
1090
|
+
const classes = cls.split(".").filter((c) => c);
|
|
1091
|
+
element.classList.add(...classes);
|
|
1092
|
+
setTimeout(() => element.remove(), 2000);
|
|
1068
1093
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
dst
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
flags
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
delete dst[index];
|
|
1132
|
-
if (flags & COPY_EMIT)
|
|
1133
|
-
emit(dst, index, EMPTY, dstValue);
|
|
1134
|
-
changed = true;
|
|
1135
|
-
} else if (dstValue !== srcValue) {
|
|
1136
|
-
if (typeof srcValue === "object" && srcValue !== null) {
|
|
1137
|
-
if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
|
|
1138
|
-
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
1139
|
-
continue;
|
|
1094
|
+
function copy(a, b, c) {
|
|
1095
|
+
if (arguments.length > 2)
|
|
1096
|
+
return copySet(a, b, c, 0);
|
|
1097
|
+
return copyImpl(a, b, 0);
|
|
1098
|
+
}
|
|
1099
|
+
function copySet(dst, dstKey, src, flags) {
|
|
1100
|
+
let dstVal = peek(dst, dstKey);
|
|
1101
|
+
if (src === dstVal)
|
|
1102
|
+
return false;
|
|
1103
|
+
if (typeof dstVal === "object" && dstVal !== null && typeof src === "object" && src !== null && dstVal.constructor === src.constructor) {
|
|
1104
|
+
return copyImpl(dstVal, src, flags);
|
|
1105
|
+
}
|
|
1106
|
+
src = clone(src);
|
|
1107
|
+
if (dst instanceof Map)
|
|
1108
|
+
dst.set(dstKey, src);
|
|
1109
|
+
else
|
|
1110
|
+
dst[dstKey] = clone(src);
|
|
1111
|
+
return true;
|
|
1112
|
+
}
|
|
1113
|
+
function merge(a, b, c) {
|
|
1114
|
+
if (arguments.length > 2)
|
|
1115
|
+
return copySet(a, b, c, MERGE);
|
|
1116
|
+
return copyImpl(a, b, MERGE);
|
|
1117
|
+
}
|
|
1118
|
+
function copyImpl(dst, src, flags) {
|
|
1119
|
+
let unproxied = dst[TARGET_SYMBOL];
|
|
1120
|
+
if (unproxied) {
|
|
1121
|
+
dst = unproxied;
|
|
1122
|
+
flags |= COPY_EMIT;
|
|
1123
|
+
}
|
|
1124
|
+
unproxied = src[TARGET_SYMBOL];
|
|
1125
|
+
if (unproxied) {
|
|
1126
|
+
src = unproxied;
|
|
1127
|
+
if (currentScope !== ROOT_SCOPE && !peeking)
|
|
1128
|
+
flags |= COPY_SUBSCRIBE;
|
|
1129
|
+
}
|
|
1130
|
+
return copyRecursive(dst, src, flags);
|
|
1131
|
+
}
|
|
1132
|
+
function copyRecursive(dst, src, flags) {
|
|
1133
|
+
if (flags & COPY_SUBSCRIBE)
|
|
1134
|
+
subscribe(src, ANY_SYMBOL);
|
|
1135
|
+
let changed = false;
|
|
1136
|
+
if (src instanceof Array && dst instanceof Array) {
|
|
1137
|
+
const dstLen = dst.length;
|
|
1138
|
+
const srcLen = src.length;
|
|
1139
|
+
for (let index = 0;index < srcLen; index++) {
|
|
1140
|
+
let dstValue = dst[index];
|
|
1141
|
+
if (dstValue === undefined && !dst.hasOwnProperty(index))
|
|
1142
|
+
dstValue = EMPTY;
|
|
1143
|
+
let srcValue = src[index];
|
|
1144
|
+
if (srcValue === undefined && !src.hasOwnProperty(index)) {
|
|
1145
|
+
delete dst[index];
|
|
1146
|
+
if (flags & COPY_EMIT)
|
|
1147
|
+
emit(dst, index, EMPTY, dstValue);
|
|
1148
|
+
changed = true;
|
|
1149
|
+
} else if (dstValue !== srcValue) {
|
|
1150
|
+
if (typeof srcValue === "object" && srcValue !== null) {
|
|
1151
|
+
if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
|
|
1152
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
|
|
1140
1156
|
}
|
|
1141
|
-
|
|
1157
|
+
dst[index] = srcValue;
|
|
1158
|
+
if (flags & COPY_EMIT)
|
|
1159
|
+
emit(dst, index, srcValue, dstValue);
|
|
1160
|
+
changed = true;
|
|
1142
1161
|
}
|
|
1143
|
-
dst[index] = srcValue;
|
|
1144
|
-
if (flags & COPY_EMIT)
|
|
1145
|
-
emit(dst, index, srcValue, dstValue);
|
|
1146
|
-
changed = true;
|
|
1147
1162
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
emit(dst, i, EMPTY, old);
|
|
1155
|
-
}
|
|
1156
|
-
dst.length = srcLen;
|
|
1157
|
-
emit(dst, "length", srcLen, dstLen);
|
|
1158
|
-
} else {
|
|
1159
|
-
dst.length = srcLen;
|
|
1160
|
-
}
|
|
1161
|
-
changed = true;
|
|
1162
|
-
}
|
|
1163
|
-
} else if (src instanceof Map && dst instanceof Map) {
|
|
1164
|
-
for (const key of src.keys()) {
|
|
1165
|
-
let srcValue = src.get(key);
|
|
1166
|
-
let dstValue = dst.get(key);
|
|
1167
|
-
if (dstValue === undefined && !dst.has(key))
|
|
1168
|
-
dstValue = EMPTY;
|
|
1169
|
-
if (dstValue !== srcValue) {
|
|
1170
|
-
if (typeof srcValue === "object" && srcValue !== null) {
|
|
1171
|
-
if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
|
|
1172
|
-
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
1173
|
-
continue;
|
|
1163
|
+
if (srcLen !== dstLen) {
|
|
1164
|
+
if (flags & COPY_EMIT) {
|
|
1165
|
+
for (let i = srcLen;i < dstLen; i++) {
|
|
1166
|
+
const old = dst[i];
|
|
1167
|
+
delete dst[i];
|
|
1168
|
+
emit(dst, i, EMPTY, old);
|
|
1174
1169
|
}
|
|
1175
|
-
|
|
1170
|
+
dst.length = srcLen;
|
|
1171
|
+
emit(dst, "length", srcLen, dstLen);
|
|
1172
|
+
} else {
|
|
1173
|
+
dst.length = srcLen;
|
|
1176
1174
|
}
|
|
1177
|
-
dst.set(key, srcValue);
|
|
1178
|
-
if (flags & COPY_EMIT)
|
|
1179
|
-
emit(dst, key, srcValue, dstValue);
|
|
1180
1175
|
changed = true;
|
|
1181
1176
|
}
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1177
|
+
} else if (src instanceof Map && dst instanceof Map) {
|
|
1178
|
+
for (const key of src.keys()) {
|
|
1179
|
+
let srcValue = src.get(key);
|
|
1180
|
+
let dstValue = dst.get(key);
|
|
1181
|
+
if (dstValue === undefined && !dst.has(key))
|
|
1182
|
+
dstValue = EMPTY;
|
|
1183
|
+
if (dstValue !== srcValue) {
|
|
1184
|
+
if (typeof srcValue === "object" && srcValue !== null) {
|
|
1185
|
+
if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
|
|
1186
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
|
|
1190
1190
|
}
|
|
1191
|
+
dst.set(key, srcValue);
|
|
1192
|
+
if (flags & COPY_EMIT)
|
|
1193
|
+
emit(dst, key, srcValue, dstValue);
|
|
1191
1194
|
changed = true;
|
|
1192
1195
|
}
|
|
1193
1196
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
changed =
|
|
1203
|
-
continue;
|
|
1197
|
+
if (!(flags & MERGE)) {
|
|
1198
|
+
for (const k of dst.keys()) {
|
|
1199
|
+
if (!src.has(k)) {
|
|
1200
|
+
const old = dst.get(k);
|
|
1201
|
+
dst.delete(k);
|
|
1202
|
+
if (flags & COPY_EMIT) {
|
|
1203
|
+
emit(dst, k, EMPTY, old);
|
|
1204
|
+
}
|
|
1205
|
+
changed = true;
|
|
1204
1206
|
}
|
|
1205
|
-
srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
|
|
1206
1207
|
}
|
|
1207
|
-
dst[key] = srcValue;
|
|
1208
|
-
if (flags & COPY_EMIT)
|
|
1209
|
-
emit(dst, key, srcValue, dstValue);
|
|
1210
|
-
changed = true;
|
|
1211
1208
|
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1209
|
+
} else if (src.constructor === dst.constructor) {
|
|
1210
|
+
for (const key of Object.keys(src)) {
|
|
1211
|
+
let srcValue = src[key];
|
|
1212
|
+
const dstValue = dst.hasOwnProperty(key) ? dst[key] : EMPTY;
|
|
1213
|
+
if (dstValue !== srcValue) {
|
|
1214
|
+
if (typeof srcValue === "object" && srcValue !== null) {
|
|
1215
|
+
if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
|
|
1216
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
|
|
1220
1220
|
}
|
|
1221
|
+
dst[key] = srcValue;
|
|
1222
|
+
if (flags & COPY_EMIT)
|
|
1223
|
+
emit(dst, key, srcValue, dstValue);
|
|
1221
1224
|
changed = true;
|
|
1222
1225
|
}
|
|
1223
1226
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1227
|
+
if (!(flags & MERGE)) {
|
|
1228
|
+
for (const k of Object.keys(dst)) {
|
|
1229
|
+
if (!src.hasOwnProperty(k)) {
|
|
1230
|
+
const old = dst[k];
|
|
1231
|
+
delete dst[k];
|
|
1232
|
+
if (flags & COPY_EMIT && old !== undefined) {
|
|
1233
|
+
emit(dst, k, EMPTY, old);
|
|
1234
|
+
}
|
|
1235
|
+
changed = true;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
} else {
|
|
1240
|
+
throw new Error(`Incompatible or non-object types: ${src?.constructor?.name || typeof src} vs ${dst?.constructor?.name || typeof dst}`);
|
|
1241
|
+
}
|
|
1242
|
+
return changed;
|
|
1243
|
+
}
|
|
1244
|
+
const MERGE = 1;
|
|
1245
|
+
const COPY_SUBSCRIBE = 32;
|
|
1246
|
+
const COPY_EMIT = 64;
|
|
1247
|
+
const OPAQUE = Symbol("OPAQUE");
|
|
1248
|
+
const NO_COPY = OPAQUE;
|
|
1249
|
+
Promise.prototype[OPAQUE] = true;
|
|
1250
|
+
if (Node)
|
|
1251
|
+
Node.prototype[OPAQUE] = true;
|
|
1252
|
+
const cssVars = optProxy({});
|
|
1253
|
+
function setSpacingCssVars(base = 1, unit = "rem") {
|
|
1254
|
+
for (let i = 0;i <= 12; i++) {
|
|
1255
|
+
cssVars[i] = 2 ** (i - 3) * base + unit;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
const CSS_VAR_PATTERN = /(\burl\([^)]*\))|("[^"]*")|(^| )\$([\w-]+)/g;
|
|
1259
|
+
const DIGIT_FIRST = /^\d/;
|
|
1260
|
+
function cssVarRef(value) {
|
|
1261
|
+
if (value.indexOf("$") < 0)
|
|
1262
|
+
return value;
|
|
1263
|
+
return value.replace(CSS_VAR_PATTERN, (match, parens, quoted, prefix, name) => {
|
|
1264
|
+
if (parens || quoted)
|
|
1265
|
+
return match;
|
|
1266
|
+
const varName = DIGIT_FIRST.test(name) ? `m${name}` : name;
|
|
1267
|
+
return `${prefix}var(--${varName})`;
|
|
1268
|
+
});
|
|
1240
1269
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
if (
|
|
1270
|
+
let darkModeState;
|
|
1271
|
+
function darkMode() {
|
|
1272
|
+
if (!darkModeState) {
|
|
1273
|
+
if (!window || !window.matchMedia)
|
|
1274
|
+
return false;
|
|
1275
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1276
|
+
darkModeState = proxy({ value: mediaQuery.matches });
|
|
1277
|
+
mediaQuery.addEventListener("change", () => darkModeState.value = mediaQuery.matches);
|
|
1278
|
+
}
|
|
1279
|
+
return darkModeState.value;
|
|
1280
|
+
}
|
|
1281
|
+
function cloneRecursive(src, flags) {
|
|
1282
|
+
if (OPAQUE in src)
|
|
1283
|
+
return src;
|
|
1284
|
+
if (flags & COPY_SUBSCRIBE)
|
|
1285
|
+
subscribe(src, ANY_SYMBOL);
|
|
1286
|
+
if (src instanceof Array) {
|
|
1287
|
+
return src.map((v) => cloneValue(v, flags));
|
|
1288
|
+
}
|
|
1289
|
+
if (src instanceof Map) {
|
|
1290
|
+
const dst2 = new Map;
|
|
1291
|
+
for (const [k, v] of src)
|
|
1292
|
+
dst2.set(k, cloneValue(v, flags));
|
|
1293
|
+
return dst2;
|
|
1294
|
+
}
|
|
1295
|
+
const dst = Object.create(Object.getPrototypeOf(src));
|
|
1296
|
+
for (const k of Object.keys(src))
|
|
1297
|
+
dst[k] = cloneValue(src[k], flags);
|
|
1298
|
+
return dst;
|
|
1299
|
+
}
|
|
1300
|
+
function cloneValue(v, flags) {
|
|
1301
|
+
return typeof v === "object" && v !== null ? cloneRecursive(v, flags) : v;
|
|
1302
|
+
}
|
|
1303
|
+
function clone(src) {
|
|
1304
|
+
if (typeof src !== "object" || src === null)
|
|
1305
|
+
return src;
|
|
1306
|
+
let flags = 0;
|
|
1307
|
+
const unproxied = src[TARGET_SYMBOL];
|
|
1308
|
+
if (unproxied) {
|
|
1309
|
+
src = unproxied;
|
|
1310
|
+
if (currentScope !== ROOT_SCOPE && !peeking)
|
|
1311
|
+
flags = COPY_SUBSCRIBE;
|
|
1312
|
+
}
|
|
1313
|
+
return cloneRecursive(src, flags);
|
|
1314
|
+
}
|
|
1315
|
+
const refHandler = {
|
|
1316
|
+
get(target, prop) {
|
|
1317
|
+
if (prop === TARGET_SYMBOL) {
|
|
1318
|
+
return ref(unproxy(target.proxy), target.index);
|
|
1319
|
+
}
|
|
1320
|
+
if (prop === "value") {
|
|
1321
|
+
return target.proxy[target.index];
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
set(target, prop, value) {
|
|
1325
|
+
if (prop === "value") {
|
|
1326
|
+
target.proxy[target.index] = value;
|
|
1327
|
+
return true;
|
|
1328
|
+
}
|
|
1258
1329
|
return false;
|
|
1259
|
-
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1260
|
-
darkModeState = proxy({ value: mediaQuery.matches });
|
|
1261
|
-
mediaQuery.addEventListener("change", () => darkModeState.value = mediaQuery.matches);
|
|
1262
|
-
}
|
|
1263
|
-
return darkModeState.value;
|
|
1264
|
-
}
|
|
1265
|
-
function cloneRecursive(src, flags) {
|
|
1266
|
-
if (OPAQUE in src)
|
|
1267
|
-
return src;
|
|
1268
|
-
if (flags & COPY_SUBSCRIBE)
|
|
1269
|
-
subscribe(src, ANY_SYMBOL);
|
|
1270
|
-
if (src instanceof Array) {
|
|
1271
|
-
return src.map((v) => cloneValue(v, flags));
|
|
1272
|
-
}
|
|
1273
|
-
if (src instanceof Map) {
|
|
1274
|
-
const dst2 = new Map;
|
|
1275
|
-
for (const [k, v] of src)
|
|
1276
|
-
dst2.set(k, cloneValue(v, flags));
|
|
1277
|
-
return dst2;
|
|
1278
|
-
}
|
|
1279
|
-
const dst = Object.create(Object.getPrototypeOf(src));
|
|
1280
|
-
for (const k of Object.keys(src))
|
|
1281
|
-
dst[k] = cloneValue(src[k], flags);
|
|
1282
|
-
return dst;
|
|
1283
|
-
}
|
|
1284
|
-
function cloneValue(v, flags) {
|
|
1285
|
-
return typeof v === "object" && v !== null ? cloneRecursive(v, flags) : v;
|
|
1286
|
-
}
|
|
1287
|
-
function clone(src) {
|
|
1288
|
-
if (typeof src !== "object" || src === null)
|
|
1289
|
-
return src;
|
|
1290
|
-
let flags = 0;
|
|
1291
|
-
const unproxied = src[TARGET_SYMBOL];
|
|
1292
|
-
if (unproxied) {
|
|
1293
|
-
src = unproxied;
|
|
1294
|
-
if (currentScope !== ROOT_SCOPE && !peeking)
|
|
1295
|
-
flags = COPY_SUBSCRIBE;
|
|
1296
|
-
}
|
|
1297
|
-
return cloneRecursive(src, flags);
|
|
1298
|
-
}
|
|
1299
|
-
var refHandler = {
|
|
1300
|
-
get(target, prop) {
|
|
1301
|
-
if (prop === TARGET_SYMBOL) {
|
|
1302
|
-
return ref(unproxy(target.proxy), target.index);
|
|
1303
|
-
}
|
|
1304
|
-
if (prop === "value") {
|
|
1305
|
-
return target.proxy[target.index];
|
|
1306
|
-
}
|
|
1307
|
-
},
|
|
1308
|
-
set(target, prop, value) {
|
|
1309
|
-
if (prop === "value") {
|
|
1310
|
-
target.proxy[target.index] = value;
|
|
1311
|
-
return true;
|
|
1312
1330
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
};
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
} else if (type === "radio") {
|
|
1334
|
-
if (value === undefined && el.checked)
|
|
1335
|
-
target.value = el.value;
|
|
1336
|
-
onProxyChange = () => {
|
|
1337
|
-
el.checked = target.value === el.value;
|
|
1338
|
-
};
|
|
1339
|
-
onInputChange = () => {
|
|
1340
|
-
if (el.checked)
|
|
1331
|
+
};
|
|
1332
|
+
function ref(target, index) {
|
|
1333
|
+
return new Proxy({ proxy: target, index }, refHandler);
|
|
1334
|
+
}
|
|
1335
|
+
function applyBind(el, target) {
|
|
1336
|
+
let onProxyChange;
|
|
1337
|
+
let onInputChange;
|
|
1338
|
+
const type = el.getAttribute("type");
|
|
1339
|
+
const value = unproxy(target).value;
|
|
1340
|
+
if (type === "checkbox") {
|
|
1341
|
+
if (value === undefined)
|
|
1342
|
+
target.value = el.checked;
|
|
1343
|
+
onProxyChange = () => {
|
|
1344
|
+
el.checked = target.value;
|
|
1345
|
+
};
|
|
1346
|
+
onInputChange = () => {
|
|
1347
|
+
target.value = el.checked;
|
|
1348
|
+
};
|
|
1349
|
+
} else if (type === "radio") {
|
|
1350
|
+
if (value === undefined && el.checked)
|
|
1341
1351
|
target.value = el.value;
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
onProxyChange = () => {
|
|
1350
|
-
el.value = target.value;
|
|
1351
|
-
if (el.tagName === "SELECT" && el.value != target.value) {
|
|
1352
|
-
new DelayedOneTimeRunner(() => el.value = target.value);
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
derive(onProxyChange);
|
|
1357
|
-
el.addEventListener("input", onInputChange);
|
|
1358
|
-
clean(() => {
|
|
1359
|
-
el.removeEventListener("input", onInputChange);
|
|
1360
|
-
});
|
|
1361
|
-
}
|
|
1362
|
-
var RICH_PATTERN = /\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|\[(.+?)\]\((.+?)\)/g;
|
|
1363
|
-
var SPECIAL_PROPS = {
|
|
1364
|
-
create: (el, value) => {
|
|
1365
|
-
if (currentScope !== topRedrawScope)
|
|
1366
|
-
return;
|
|
1367
|
-
if (typeof value === "function") {
|
|
1368
|
-
value(el);
|
|
1369
|
-
} else {
|
|
1370
|
-
const classes = value.split(".").filter((c) => c);
|
|
1371
|
-
el.classList.add(...classes);
|
|
1372
|
-
(async () => {
|
|
1373
|
-
el.offsetHeight;
|
|
1374
|
-
el.classList.remove(...classes);
|
|
1375
|
-
})();
|
|
1376
|
-
}
|
|
1377
|
-
},
|
|
1378
|
-
destroy: (el, value) => {
|
|
1379
|
-
onDestroyMap.set(el, value);
|
|
1380
|
-
},
|
|
1381
|
-
html: (el, value) => {
|
|
1382
|
-
if (el === currentScope.el && !el.firstChild) {
|
|
1383
|
-
el.innerHTML = `${value}`;
|
|
1352
|
+
onProxyChange = () => {
|
|
1353
|
+
el.checked = target.value === el.value;
|
|
1354
|
+
};
|
|
1355
|
+
onInputChange = () => {
|
|
1356
|
+
if (el.checked)
|
|
1357
|
+
target.value = el.value;
|
|
1358
|
+
};
|
|
1384
1359
|
} else {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
let match;
|
|
1397
|
-
const str = String(value);
|
|
1398
|
-
RICH_PATTERN.lastIndex = 0;
|
|
1399
|
-
while ((match = RICH_PATTERN.exec(str)) !== null) {
|
|
1400
|
-
if (match.index > lastIndex) {
|
|
1401
|
-
addNode(el, document.createTextNode(str.slice(lastIndex, match.index)));
|
|
1402
|
-
}
|
|
1403
|
-
let node;
|
|
1404
|
-
if (match[1] !== undefined) {
|
|
1405
|
-
node = document.createElement("strong");
|
|
1406
|
-
node.textContent = match[1];
|
|
1407
|
-
} else if (match[2] !== undefined) {
|
|
1408
|
-
node = document.createElement("em");
|
|
1409
|
-
node.textContent = match[2];
|
|
1410
|
-
} else if (match[3] !== undefined) {
|
|
1411
|
-
node = document.createElement("code");
|
|
1412
|
-
node.textContent = match[3];
|
|
1413
|
-
} else {
|
|
1414
|
-
const a = document.createElement("a");
|
|
1415
|
-
a.textContent = match[4];
|
|
1416
|
-
a.href = match[5];
|
|
1417
|
-
node = a;
|
|
1418
|
-
}
|
|
1419
|
-
addNode(el, node);
|
|
1420
|
-
lastIndex = RICH_PATTERN.lastIndex;
|
|
1421
|
-
}
|
|
1422
|
-
if (lastIndex < str.length) {
|
|
1423
|
-
addNode(el, document.createTextNode(str.slice(lastIndex)));
|
|
1360
|
+
onInputChange = () => {
|
|
1361
|
+
target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
|
|
1362
|
+
};
|
|
1363
|
+
if (value === undefined)
|
|
1364
|
+
onInputChange();
|
|
1365
|
+
onProxyChange = () => {
|
|
1366
|
+
el.value = target.value;
|
|
1367
|
+
if (el.tagName === "SELECT" && el.value != target.value) {
|
|
1368
|
+
new DelayedOneTimeRunner(() => el.value = target.value);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1424
1371
|
}
|
|
1372
|
+
derive(onProxyChange);
|
|
1373
|
+
el.addEventListener("input", onInputChange);
|
|
1374
|
+
clean(() => {
|
|
1375
|
+
el.removeEventListener("input", onInputChange);
|
|
1376
|
+
});
|
|
1425
1377
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1378
|
+
const RICH_PATTERN = /\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|\[(.+?)\]\((.+?)\)/g;
|
|
1379
|
+
const SPECIAL_PROPS = {
|
|
1380
|
+
create: (el, value) => {
|
|
1381
|
+
if (currentScope !== topRedrawScope)
|
|
1382
|
+
return;
|
|
1383
|
+
if (typeof value === "function") {
|
|
1384
|
+
value(el);
|
|
1385
|
+
} else {
|
|
1386
|
+
const classes = value.split(".").filter((c) => c);
|
|
1387
|
+
el.classList.add(...classes);
|
|
1388
|
+
(async () => {
|
|
1389
|
+
el.offsetHeight;
|
|
1390
|
+
el.classList.remove(...classes);
|
|
1391
|
+
})();
|
|
1392
|
+
}
|
|
1393
|
+
},
|
|
1394
|
+
destroy: (el, value) => {
|
|
1395
|
+
onDestroyMap.set(el, value);
|
|
1396
|
+
},
|
|
1397
|
+
html: (el, value) => {
|
|
1398
|
+
if (el === currentScope.el && !el.firstChild) {
|
|
1399
|
+
el.innerHTML = `${value}`;
|
|
1400
|
+
} else {
|
|
1401
|
+
const tmpParent = document.createElement(currentScope.el.tagName);
|
|
1402
|
+
tmpParent.innerHTML = `${value}`;
|
|
1403
|
+
while (tmpParent.firstChild)
|
|
1404
|
+
addNode(el, tmpParent.firstChild);
|
|
1405
|
+
}
|
|
1406
|
+
},
|
|
1407
|
+
text: (el, value) => {
|
|
1408
|
+
addNode(el, document.createTextNode(value));
|
|
1409
|
+
},
|
|
1410
|
+
rich: (el, value) => {
|
|
1411
|
+
let lastIndex = 0;
|
|
1412
|
+
let match;
|
|
1413
|
+
const str = String(value);
|
|
1414
|
+
RICH_PATTERN.lastIndex = 0;
|
|
1415
|
+
while ((match = RICH_PATTERN.exec(str)) !== null) {
|
|
1416
|
+
if (match.index > lastIndex) {
|
|
1417
|
+
addNode(el, document.createTextNode(str.slice(lastIndex, match.index)));
|
|
1418
|
+
}
|
|
1419
|
+
let node;
|
|
1420
|
+
if (match[1] !== undefined) {
|
|
1421
|
+
node = document.createElement("strong");
|
|
1422
|
+
node.textContent = match[1];
|
|
1423
|
+
} else if (match[2] !== undefined) {
|
|
1424
|
+
node = document.createElement("em");
|
|
1425
|
+
node.textContent = match[2];
|
|
1426
|
+
} else if (match[3] !== undefined) {
|
|
1427
|
+
node = document.createElement("code");
|
|
1428
|
+
node.textContent = match[3];
|
|
1477
1429
|
} else {
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1430
|
+
const a = document.createElement("a");
|
|
1431
|
+
a.textContent = match[4];
|
|
1432
|
+
a.href = match[5];
|
|
1433
|
+
node = a;
|
|
1434
|
+
}
|
|
1435
|
+
addNode(el, node);
|
|
1436
|
+
lastIndex = RICH_PATTERN.lastIndex;
|
|
1437
|
+
}
|
|
1438
|
+
if (lastIndex < str.length) {
|
|
1439
|
+
addNode(el, document.createTextNode(str.slice(lastIndex)));
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
function A(...args) {
|
|
1444
|
+
let el = currentScope.el;
|
|
1445
|
+
let svg = currentScope.svg;
|
|
1446
|
+
const argCount = args.length;
|
|
1447
|
+
for (let argIndex = 0;argIndex < argCount; argIndex++) {
|
|
1448
|
+
const arg = args[argIndex];
|
|
1449
|
+
if (arg == null || arg === false) {} else if (typeof arg === "string") {
|
|
1450
|
+
let argLen = arg.length;
|
|
1451
|
+
let nextPos = 0;
|
|
1452
|
+
for (let pos = 0;pos < argLen; pos = nextPos + 1) {
|
|
1453
|
+
nextPos = findFirst(arg, " .=:#", pos);
|
|
1454
|
+
const next = arg[nextPos];
|
|
1455
|
+
if (next === ":") {
|
|
1456
|
+
const key = "$" + arg.substring(pos, nextPos);
|
|
1457
|
+
if (nextPos + 1 >= argLen) {
|
|
1458
|
+
applyArg(el, key, args[++argIndex]);
|
|
1459
|
+
break;
|
|
1460
|
+
}
|
|
1461
|
+
if (arg[nextPos + 1] === " ") {
|
|
1462
|
+
const endIndex = findFirst(arg, ";", nextPos + 2);
|
|
1463
|
+
const value = arg.substring(nextPos + 2, endIndex).trim();
|
|
1464
|
+
applyArg(el, key, value);
|
|
1465
|
+
nextPos = endIndex;
|
|
1495
1466
|
} else {
|
|
1496
|
-
|
|
1497
|
-
const
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1467
|
+
const endIndex = findFirst(arg, " ", nextPos + 1);
|
|
1468
|
+
const value = arg.substring(nextPos + 1, endIndex);
|
|
1469
|
+
applyArg(el, key, value);
|
|
1470
|
+
nextPos = endIndex;
|
|
1471
|
+
}
|
|
1472
|
+
} else if (next === "=") {
|
|
1473
|
+
const key = arg.substring(pos, nextPos);
|
|
1474
|
+
if (nextPos + 1 >= argLen) {
|
|
1475
|
+
applyArg(el, key, args[++argIndex]);
|
|
1476
|
+
break;
|
|
1477
|
+
}
|
|
1478
|
+
const afterEquals = arg[nextPos + 1];
|
|
1479
|
+
if (afterEquals === '"' || afterEquals === "'" || afterEquals === "`") {
|
|
1480
|
+
const endIndex = findFirst(arg, afterEquals, nextPos + 2);
|
|
1481
|
+
const value = arg.substring(nextPos + 2, endIndex);
|
|
1482
|
+
applyArg(el, key, value);
|
|
1483
|
+
nextPos = endIndex;
|
|
1484
|
+
} else {
|
|
1485
|
+
const endIndex = findFirst(arg, " ", nextPos + 1);
|
|
1486
|
+
const value = arg.substring(nextPos + 1, endIndex);
|
|
1487
|
+
applyArg(el, key, value);
|
|
1488
|
+
nextPos = endIndex;
|
|
1489
|
+
}
|
|
1490
|
+
} else {
|
|
1491
|
+
if (nextPos > pos) {
|
|
1492
|
+
const tag = arg.substring(pos, nextPos);
|
|
1493
|
+
svg ||= tag === "svg";
|
|
1494
|
+
let newEl = svg ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
|
|
1495
|
+
addNode(el, newEl);
|
|
1496
|
+
el = newEl;
|
|
1497
|
+
}
|
|
1498
|
+
if (next === "#") {
|
|
1499
|
+
const text = nextPos + 1 < argLen ? arg.substring(nextPos + 1) : args[++argIndex];
|
|
1500
|
+
applyArg(el, "text", text);
|
|
1501
|
+
break;
|
|
1502
|
+
}
|
|
1503
|
+
if (next === ".") {
|
|
1504
|
+
let classEnd = findFirst(arg, " #=.", nextPos + 1);
|
|
1505
|
+
if (arg[classEnd] === "=" && classEnd + 1 >= argLen) {
|
|
1506
|
+
applyArg(el, arg.substring(nextPos, classEnd), args[++argIndex]);
|
|
1507
|
+
nextPos = classEnd;
|
|
1508
|
+
} else {
|
|
1509
|
+
let className = arg.substring(nextPos + 1, classEnd);
|
|
1510
|
+
const cls = className || args[++argIndex];
|
|
1511
|
+
if (!el.classList.contains(cls)) {
|
|
1512
|
+
if (el === currentScope.el)
|
|
1513
|
+
recordSideEffect(currentScope, 0 /* Class */, cls, false);
|
|
1514
|
+
el.classList.add(cls);
|
|
1515
|
+
}
|
|
1516
|
+
nextPos = classEnd - 1;
|
|
1502
1517
|
}
|
|
1503
|
-
nextPos = classEnd - 1;
|
|
1504
1518
|
}
|
|
1505
1519
|
}
|
|
1506
1520
|
}
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1521
|
+
} else if (typeof arg === "object") {
|
|
1522
|
+
if (arg.constructor !== Object) {
|
|
1523
|
+
if (arg instanceof Node) {
|
|
1524
|
+
addNode(el, arg);
|
|
1525
|
+
if (arg instanceof Element) {
|
|
1526
|
+
el = arg;
|
|
1527
|
+
svg = arg.namespaceURI === "http://www.w3.org/2000/svg";
|
|
1528
|
+
}
|
|
1529
|
+
} else {
|
|
1530
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
1515
1531
|
}
|
|
1516
1532
|
} else {
|
|
1517
|
-
|
|
1533
|
+
for (const key of Object.keys(arg)) {
|
|
1534
|
+
applyArg(el, key, arg[key]);
|
|
1535
|
+
}
|
|
1518
1536
|
}
|
|
1537
|
+
} else if (typeof arg === "function") {
|
|
1538
|
+
new RegularScope(el, svg, arg);
|
|
1519
1539
|
} else {
|
|
1520
|
-
|
|
1521
|
-
applyArg(el, key, arg[key]);
|
|
1522
|
-
}
|
|
1540
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
1523
1541
|
}
|
|
1524
|
-
} else if (typeof arg === "function") {
|
|
1525
|
-
new RegularScope(el, svg, arg);
|
|
1526
|
-
} else {
|
|
1527
|
-
throw new Error(`Unexpected argument: ${arg}`);
|
|
1528
1542
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1543
|
+
return el;
|
|
1544
|
+
}
|
|
1545
|
+
function findFirst(str, chars, startPos) {
|
|
1546
|
+
if (chars.length === 1) {
|
|
1547
|
+
const idx = str.indexOf(chars, startPos);
|
|
1548
|
+
return idx >= 0 ? idx : str.length;
|
|
1549
|
+
}
|
|
1550
|
+
const strLen = str.length;
|
|
1551
|
+
for (let i = startPos;i < strLen; i++) {
|
|
1552
|
+
if (chars.indexOf(str[i]) >= 0)
|
|
1553
|
+
return i;
|
|
1554
|
+
}
|
|
1555
|
+
return strLen;
|
|
1556
|
+
}
|
|
1557
|
+
let cssCount = 0;
|
|
1558
|
+
function insertCss(style) {
|
|
1559
|
+
const prefix = `.AbdStl${++cssCount}`;
|
|
1560
|
+
const css = typeof style === "string" ? styleStringToCss(style, prefix) : objectToCss(style, prefix);
|
|
1561
|
+
if (css) {
|
|
1562
|
+
let cnt = cssSnippetCount++;
|
|
1563
|
+
cssSnippets[cnt] = css;
|
|
1564
|
+
clean(() => delete cssSnippets[cnt]);
|
|
1565
|
+
}
|
|
1566
|
+
return prefix;
|
|
1567
|
+
}
|
|
1568
|
+
let cssSnippets = proxy({});
|
|
1569
|
+
let cssSnippetCount = 0;
|
|
1570
|
+
function combinePrefixSelector(prefix, key) {
|
|
1571
|
+
const sel = [];
|
|
1572
|
+
for (const p of prefix.split(",")) {
|
|
1573
|
+
for (const k of key.split(",")) {
|
|
1574
|
+
sel.push(k.includes("&") ? k.trim().replace(/&/g, p) : `${p} ${k.trim()}`.trim());
|
|
1575
|
+
}
|
|
1562
1576
|
}
|
|
1577
|
+
return sel.join(",");
|
|
1563
1578
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
if (key.startsWith("@")) {
|
|
1571
|
-
css += `${key}{
|
|
1579
|
+
function objectToCss(style, prefix) {
|
|
1580
|
+
let css = "";
|
|
1581
|
+
for (const [key, val] of Object.entries(style)) {
|
|
1582
|
+
if (val && typeof val === "object") {
|
|
1583
|
+
if (key.startsWith("@")) {
|
|
1584
|
+
css += `${key}{
|
|
1572
1585
|
${objectToCss(val, prefix)}}
|
|
1573
1586
|
`;
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1587
|
+
} else {
|
|
1588
|
+
css += objectToCss(val, combinePrefixSelector(prefix, key));
|
|
1589
|
+
}
|
|
1590
|
+
} else if (typeof val === "string") {
|
|
1591
|
+
if (key.startsWith("@")) {
|
|
1592
|
+
css += `${key}{
|
|
1580
1593
|
${styleStringToCss(val, prefix)}}
|
|
1581
1594
|
`;
|
|
1582
|
-
|
|
1583
|
-
|
|
1595
|
+
} else {
|
|
1596
|
+
css += styleStringToCss(val, combinePrefixSelector(prefix, key));
|
|
1597
|
+
}
|
|
1584
1598
|
}
|
|
1585
1599
|
}
|
|
1600
|
+
return css;
|
|
1586
1601
|
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
function toCamel(p) {
|
|
1591
|
-
return p.replace(KEBAB_SEGMENT, (_, l) => l.toUpperCase());
|
|
1592
|
-
}
|
|
1593
|
-
var VALID_CSS_KEY = /^[a-zA-Z-]+$/;
|
|
1594
|
-
function styleStringToCss(styleStr, selector) {
|
|
1595
|
-
let props = "";
|
|
1596
|
-
for (let pos = 0, len = styleStr.length;pos < len; ) {
|
|
1597
|
-
while (styleStr[pos] === " ")
|
|
1598
|
-
pos++;
|
|
1599
|
-
if (pos >= len)
|
|
1600
|
-
break;
|
|
1601
|
-
const colon = styleStr.indexOf(":", pos);
|
|
1602
|
-
if (colon === -1)
|
|
1603
|
-
throw new Error(`Trailing data in style string: "${styleStr.substring(pos)}"`);
|
|
1604
|
-
const key = styleStr.substring(pos, colon);
|
|
1605
|
-
if (!VALID_CSS_KEY.test(key))
|
|
1606
|
-
throw new Error(`Invalid CSS key: "${key}" in style string: "${styleStr}"`);
|
|
1607
|
-
pos = colon + 1;
|
|
1608
|
-
let val;
|
|
1609
|
-
if (styleStr[pos] === " ") {
|
|
1610
|
-
pos++;
|
|
1611
|
-
const semi = styleStr.indexOf(";", pos);
|
|
1612
|
-
val = styleStr.substring(pos, semi === -1 ? len : semi).trim();
|
|
1613
|
-
pos = semi === -1 ? len : semi + 1;
|
|
1614
|
-
} else {
|
|
1615
|
-
const space = styleStr.indexOf(" ", pos);
|
|
1616
|
-
val = styleStr.substring(pos, space === -1 ? len : space);
|
|
1617
|
-
pos = space === -1 ? len : space;
|
|
1618
|
-
}
|
|
1619
|
-
const v = cssVarRef(val);
|
|
1620
|
-
const exp = CSS_SHORT[key] || key;
|
|
1621
|
-
props += typeof exp === "string" ? `${exp}:${v};` : exp.map((p) => `${p}:${v};`).join("");
|
|
1602
|
+
const KEBAB_SEGMENT = /-([a-z])/g;
|
|
1603
|
+
function toCamel(p) {
|
|
1604
|
+
return p.replace(KEBAB_SEGMENT, (_, l) => l.toUpperCase());
|
|
1622
1605
|
}
|
|
1623
|
-
|
|
1606
|
+
const VALID_CSS_KEY = /^[a-zA-Z-]+$/;
|
|
1607
|
+
function styleStringToCss(styleStr, selector) {
|
|
1608
|
+
let props = "";
|
|
1609
|
+
for (let pos = 0, len = styleStr.length;pos < len; ) {
|
|
1610
|
+
while (styleStr[pos] === " ")
|
|
1611
|
+
pos++;
|
|
1612
|
+
if (pos >= len)
|
|
1613
|
+
break;
|
|
1614
|
+
const colon = styleStr.indexOf(":", pos);
|
|
1615
|
+
if (colon === -1)
|
|
1616
|
+
throw new Error(`Trailing data in style string: "${styleStr.substring(pos)}"`);
|
|
1617
|
+
const key = styleStr.substring(pos, colon);
|
|
1618
|
+
if (!VALID_CSS_KEY.test(key))
|
|
1619
|
+
throw new Error(`Invalid CSS key: "${key}" in style string: "${styleStr}"`);
|
|
1620
|
+
pos = colon + 1;
|
|
1621
|
+
let val;
|
|
1622
|
+
if (styleStr[pos] === " ") {
|
|
1623
|
+
pos++;
|
|
1624
|
+
const semi = styleStr.indexOf(";", pos);
|
|
1625
|
+
val = styleStr.substring(pos, semi === -1 ? len : semi).trim();
|
|
1626
|
+
pos = semi === -1 ? len : semi + 1;
|
|
1627
|
+
} else {
|
|
1628
|
+
const space = styleStr.indexOf(" ", pos);
|
|
1629
|
+
val = styleStr.substring(pos, space === -1 ? len : space);
|
|
1630
|
+
pos = space === -1 ? len : space;
|
|
1631
|
+
}
|
|
1632
|
+
const v = cssVarRef(val);
|
|
1633
|
+
const exp = CSS_SHORT[key] || key;
|
|
1634
|
+
props += typeof exp === "string" ? `${exp}:${v};` : exp.map((p) => `${p}:${v};`).join("");
|
|
1635
|
+
}
|
|
1636
|
+
return props ? `${selector}{${props}}
|
|
1624
1637
|
` : "";
|
|
1625
|
-
}
|
|
1626
|
-
function insertGlobalCss(style) {
|
|
1627
|
-
const css = objectToCss(style, "");
|
|
1628
|
-
if (css) {
|
|
1629
|
-
let cnt = cssSnippetCount++;
|
|
1630
|
-
cssSnippets[cnt] = css;
|
|
1631
|
-
clean(() => delete cssSnippets[cnt]);
|
|
1632
1638
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1639
|
+
function insertGlobalCss(style) {
|
|
1640
|
+
const css = objectToCss(style, "");
|
|
1641
|
+
if (css) {
|
|
1642
|
+
let cnt = cssSnippetCount++;
|
|
1643
|
+
cssSnippets[cnt] = css;
|
|
1644
|
+
clean(() => delete cssSnippets[cnt]);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
const CSS_SHORT = {
|
|
1648
|
+
m: "margin",
|
|
1649
|
+
mt: "margin-top",
|
|
1650
|
+
mb: "margin-bottom",
|
|
1651
|
+
ml: "margin-left",
|
|
1652
|
+
mr: "margin-right",
|
|
1653
|
+
mh: ["margin-left", "margin-right"],
|
|
1654
|
+
mv: ["margin-top", "margin-bottom"],
|
|
1655
|
+
p: "padding",
|
|
1656
|
+
pt: "padding-top",
|
|
1657
|
+
pb: "padding-bottom",
|
|
1658
|
+
pl: "padding-left",
|
|
1659
|
+
pr: "padding-right",
|
|
1660
|
+
ph: ["padding-left", "padding-right"],
|
|
1661
|
+
pv: ["padding-top", "padding-bottom"],
|
|
1662
|
+
w: "width",
|
|
1663
|
+
h: "height",
|
|
1664
|
+
bg: "background",
|
|
1665
|
+
fg: "color",
|
|
1666
|
+
r: "border-radius"
|
|
1667
|
+
};
|
|
1668
|
+
function applyArg(el, key, value) {
|
|
1669
|
+
if (typeof value === "object" && value !== null && value[TARGET_SYMBOL]) {
|
|
1670
|
+
if (key === "bind") {
|
|
1671
|
+
applyBind(el, value);
|
|
1672
|
+
} else {
|
|
1673
|
+
new SetArgScope(el, key, value);
|
|
1674
|
+
}
|
|
1675
|
+
} else if (key[0] === ".") {
|
|
1676
|
+
const classes = key.substring(1).split(".");
|
|
1677
|
+
const list = el.classList;
|
|
1678
|
+
const desired = !!value;
|
|
1679
|
+
if (el === currentScope.el) {
|
|
1680
|
+
for (const cls of classes) {
|
|
1681
|
+
const had = list.contains(cls);
|
|
1682
|
+
if (had !== desired)
|
|
1683
|
+
recordSideEffect(currentScope, 0 /* Class */, cls, had);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
if (desired)
|
|
1687
|
+
list.add(...classes);
|
|
1688
|
+
else
|
|
1689
|
+
list.remove(...classes);
|
|
1690
|
+
} else if (key[0] === "$") {
|
|
1691
|
+
key = key.substring(1);
|
|
1692
|
+
const val = value == null || value === false ? "" : typeof value === "string" ? cssVarRef(value) : String(value);
|
|
1693
|
+
const expanded = CSS_SHORT[key] || key;
|
|
1694
|
+
const style = el.style;
|
|
1695
|
+
const setOwn = el === currentScope.el;
|
|
1696
|
+
const props = typeof expanded === "string" ? [expanded] : expanded;
|
|
1697
|
+
for (const prop of props) {
|
|
1698
|
+
const cm = toCamel(prop);
|
|
1699
|
+
if (setOwn)
|
|
1700
|
+
recordSideEffect(currentScope, 1 /* Style */, cm, style[cm]);
|
|
1701
|
+
style[cm] = val;
|
|
1702
|
+
}
|
|
1703
|
+
} else if (value == null) {} else if (key in SPECIAL_PROPS) {
|
|
1704
|
+
SPECIAL_PROPS[key](el, value);
|
|
1705
|
+
} else if (typeof value === "function") {
|
|
1706
|
+
el.addEventListener(key, value);
|
|
1707
|
+
if (el === currentScope.el)
|
|
1708
|
+
recordSideEffect(currentScope, 4 /* Event */, key, value);
|
|
1709
|
+
} else if (value === true || value === false || key === "value" || key === "selectedIndex") {
|
|
1710
|
+
if (el === currentScope.el)
|
|
1711
|
+
recordSideEffect(currentScope, 2 /* Prop */, key, el[key]);
|
|
1712
|
+
el[key] = value;
|
|
1659
1713
|
} else {
|
|
1660
|
-
|
|
1714
|
+
if (el === currentScope.el)
|
|
1715
|
+
recordSideEffect(currentScope, 3 /* Attr */, key, el.getAttribute(key));
|
|
1716
|
+
el.setAttribute(key, value);
|
|
1661
1717
|
}
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1718
|
+
}
|
|
1719
|
+
function defaultOnError(error) {
|
|
1720
|
+
console.error("Error while in Aberdeen render:", error);
|
|
1721
|
+
return true;
|
|
1722
|
+
}
|
|
1723
|
+
let onError = defaultOnError;
|
|
1724
|
+
function setErrorHandler(handler) {
|
|
1725
|
+
onError = handler || defaultOnError;
|
|
1726
|
+
}
|
|
1727
|
+
function clean(cleaner) {
|
|
1728
|
+
currentScope.cleaners.push(cleaner);
|
|
1729
|
+
}
|
|
1730
|
+
function derive(func) {
|
|
1731
|
+
return new ResultScope(func).result;
|
|
1732
|
+
}
|
|
1733
|
+
function mount(parentElement, func) {
|
|
1734
|
+
new MountScope(parentElement, func);
|
|
1735
|
+
}
|
|
1736
|
+
function unmountAll() {
|
|
1737
|
+
ROOT_SCOPE.remove();
|
|
1738
|
+
cssCount = 0;
|
|
1739
|
+
}
|
|
1740
|
+
function peek(target, key) {
|
|
1741
|
+
peeking++;
|
|
1742
|
+
try {
|
|
1743
|
+
if (arguments.length === 1) {
|
|
1744
|
+
return target();
|
|
1745
|
+
} else {
|
|
1746
|
+
return target instanceof Map ? target.get(key) : target[key];
|
|
1671
1747
|
}
|
|
1748
|
+
} finally {
|
|
1749
|
+
peeking--;
|
|
1672
1750
|
}
|
|
1673
|
-
if (desired)
|
|
1674
|
-
list.add(...classes);
|
|
1675
|
-
else
|
|
1676
|
-
list.remove(...classes);
|
|
1677
|
-
} else if (key[0] === "$") {
|
|
1678
|
-
key = key.substring(1);
|
|
1679
|
-
const val = value == null || value === false ? "" : typeof value === "string" ? cssVarRef(value) : String(value);
|
|
1680
|
-
const expanded = CSS_SHORT[key] || key;
|
|
1681
|
-
const style = el.style;
|
|
1682
|
-
const setOwn = el === currentScope.el;
|
|
1683
|
-
const props = typeof expanded === "string" ? [expanded] : expanded;
|
|
1684
|
-
for (const prop of props) {
|
|
1685
|
-
const cm = toCamel(prop);
|
|
1686
|
-
if (setOwn)
|
|
1687
|
-
recordSideEffect(currentScope, 1 /* Style */, cm, style[cm]);
|
|
1688
|
-
style[cm] = val;
|
|
1689
|
-
}
|
|
1690
|
-
} else if (value == null) {} else if (key in SPECIAL_PROPS) {
|
|
1691
|
-
SPECIAL_PROPS[key](el, value);
|
|
1692
|
-
} else if (typeof value === "function") {
|
|
1693
|
-
el.addEventListener(key, value);
|
|
1694
|
-
if (el === currentScope.el)
|
|
1695
|
-
recordSideEffect(currentScope, 4 /* Event */, key, value);
|
|
1696
|
-
} else if (value === true || value === false || key === "value" || key === "selectedIndex") {
|
|
1697
|
-
if (el === currentScope.el)
|
|
1698
|
-
recordSideEffect(currentScope, 2 /* Prop */, key, el[key]);
|
|
1699
|
-
el[key] = value;
|
|
1700
|
-
} else {
|
|
1701
|
-
if (el === currentScope.el)
|
|
1702
|
-
recordSideEffect(currentScope, 3 /* Attr */, key, el.getAttribute(key));
|
|
1703
|
-
el.setAttribute(key, value);
|
|
1704
1751
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
function setErrorHandler(handler) {
|
|
1712
|
-
onError = handler || defaultOnError;
|
|
1713
|
-
}
|
|
1714
|
-
function clean(cleaner) {
|
|
1715
|
-
currentScope.cleaners.push(cleaner);
|
|
1716
|
-
}
|
|
1717
|
-
function derive(func) {
|
|
1718
|
-
return new ResultScope(func).result;
|
|
1719
|
-
}
|
|
1720
|
-
function mount(parentElement, func) {
|
|
1721
|
-
new MountScope(parentElement, func);
|
|
1722
|
-
}
|
|
1723
|
-
function unmountAll() {
|
|
1724
|
-
ROOT_SCOPE.remove();
|
|
1725
|
-
cssCount = 0;
|
|
1726
|
-
}
|
|
1727
|
-
function peek(target, key) {
|
|
1728
|
-
peeking++;
|
|
1729
|
-
try {
|
|
1730
|
-
if (arguments.length === 1) {
|
|
1731
|
-
return target();
|
|
1752
|
+
function map(source, func) {
|
|
1753
|
+
let out;
|
|
1754
|
+
if (source instanceof Array) {
|
|
1755
|
+
out = optProxy([]);
|
|
1756
|
+
} else if (source instanceof Map) {
|
|
1757
|
+
out = optProxy(new Map);
|
|
1732
1758
|
} else {
|
|
1733
|
-
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
|
|
1759
|
+
out = optProxy({});
|
|
1760
|
+
}
|
|
1761
|
+
onEach(source, (item, key) => {
|
|
1762
|
+
const value = func(item, key);
|
|
1763
|
+
if (value !== undefined) {
|
|
1764
|
+
if (out instanceof Map) {
|
|
1765
|
+
out.set(key, value);
|
|
1766
|
+
clean(() => {
|
|
1767
|
+
out.delete(key);
|
|
1768
|
+
});
|
|
1769
|
+
} else {
|
|
1770
|
+
out[key] = value;
|
|
1771
|
+
clean(() => {
|
|
1772
|
+
delete out[key];
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
return out;
|
|
1737
1778
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
} else {
|
|
1746
|
-
out = optProxy({});
|
|
1747
|
-
}
|
|
1748
|
-
onEach(source, (item, key) => {
|
|
1749
|
-
const value = func(item, key);
|
|
1750
|
-
if (value !== undefined) {
|
|
1751
|
-
if (out instanceof Map) {
|
|
1752
|
-
out.set(key, value);
|
|
1753
|
-
clean(() => {
|
|
1754
|
-
out.delete(key);
|
|
1755
|
-
});
|
|
1756
|
-
} else {
|
|
1757
|
-
out[key] = value;
|
|
1779
|
+
function multiMap(source, func) {
|
|
1780
|
+
const out = optProxy({});
|
|
1781
|
+
onEach(source, (item, key) => {
|
|
1782
|
+
const pairs = func(item, key);
|
|
1783
|
+
if (pairs) {
|
|
1784
|
+
for (const key2 of Object.keys(pairs))
|
|
1785
|
+
out[key2] = pairs[key2];
|
|
1758
1786
|
clean(() => {
|
|
1759
|
-
|
|
1787
|
+
for (const key2 of Object.keys(pairs))
|
|
1788
|
+
delete out[key2];
|
|
1760
1789
|
});
|
|
1761
1790
|
}
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
clean(() => {
|
|
1774
|
-
for (const key2 of Object.keys(pairs))
|
|
1775
|
-
delete out[key2];
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
});
|
|
1779
|
-
return out;
|
|
1780
|
-
}
|
|
1781
|
-
function partition(source, func) {
|
|
1782
|
-
const unproxiedOut = {};
|
|
1783
|
-
const out = optProxy(unproxiedOut);
|
|
1784
|
-
onEach(source, (item, key) => {
|
|
1785
|
-
const rsp = func(item, key);
|
|
1786
|
-
if (rsp != null) {
|
|
1787
|
-
const buckets = rsp instanceof Array ? rsp : [rsp];
|
|
1788
|
-
if (buckets.length) {
|
|
1789
|
-
for (const bucket of buckets) {
|
|
1790
|
-
if (unproxiedOut[bucket])
|
|
1791
|
-
out[bucket][key] = item;
|
|
1792
|
-
else
|
|
1793
|
-
out[bucket] = { [key]: item };
|
|
1794
|
-
}
|
|
1795
|
-
clean(() => {
|
|
1791
|
+
});
|
|
1792
|
+
return out;
|
|
1793
|
+
}
|
|
1794
|
+
function partition(source, func) {
|
|
1795
|
+
const unproxiedOut = {};
|
|
1796
|
+
const out = optProxy(unproxiedOut);
|
|
1797
|
+
onEach(source, (item, key) => {
|
|
1798
|
+
const rsp = func(item, key);
|
|
1799
|
+
if (rsp != null) {
|
|
1800
|
+
const buckets = rsp instanceof Array ? rsp : [rsp];
|
|
1801
|
+
if (buckets.length) {
|
|
1796
1802
|
for (const bucket of buckets) {
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1803
|
+
if (unproxiedOut[bucket])
|
|
1804
|
+
out[bucket][key] = item;
|
|
1805
|
+
else
|
|
1806
|
+
out[bucket] = { [key]: item };
|
|
1800
1807
|
}
|
|
1801
|
-
|
|
1808
|
+
clean(() => {
|
|
1809
|
+
for (const bucket of buckets) {
|
|
1810
|
+
delete out[bucket][key];
|
|
1811
|
+
if (isObjEmpty(unproxiedOut[bucket]))
|
|
1812
|
+
delete out[bucket];
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1802
1816
|
}
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1817
|
+
});
|
|
1818
|
+
return out;
|
|
1819
|
+
}
|
|
1820
|
+
function dump(data) {
|
|
1821
|
+
const org = dumpSeen;
|
|
1822
|
+
dumpSeen ||= new Set;
|
|
1823
|
+
try {
|
|
1824
|
+
rawDump(data, dumpSeen);
|
|
1825
|
+
} finally {
|
|
1826
|
+
dumpSeen = org;
|
|
1827
|
+
}
|
|
1828
|
+
return data;
|
|
1829
|
+
}
|
|
1830
|
+
let dumpSeen;
|
|
1831
|
+
function rawDump(data, seen) {
|
|
1832
|
+
if (data && typeof data === "object") {
|
|
1833
|
+
const name = data.constructor.name || "unknown object";
|
|
1834
|
+
if (seen.has(data)) {
|
|
1835
|
+
A(`#<${name}: circular reference>`);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
seen.add(data);
|
|
1839
|
+
clean(() => seen.delete(data));
|
|
1840
|
+
const customDump = data[CUSTOM_DUMP];
|
|
1841
|
+
if (customDump !== undefined) {
|
|
1842
|
+
if (typeof customDump === "function")
|
|
1843
|
+
customDump.call(data);
|
|
1844
|
+
else
|
|
1845
|
+
A(`#${customDump}`);
|
|
1846
|
+
} else {
|
|
1847
|
+
A(`#<${name}>`, "ul", () => {
|
|
1848
|
+
onEach(data, (value, key) => {
|
|
1849
|
+
A("li", () => {
|
|
1850
|
+
if (!(data instanceof Array))
|
|
1851
|
+
A(`#${JSON.stringify(key)}: `);
|
|
1852
|
+
rawDump(value, seen);
|
|
1853
|
+
});
|
|
1840
1854
|
});
|
|
1841
1855
|
});
|
|
1842
|
-
}
|
|
1856
|
+
}
|
|
1857
|
+
} else if (data === undefined) {
|
|
1858
|
+
A("#undefined");
|
|
1859
|
+
} else {
|
|
1860
|
+
A("#" + JSON.stringify(data));
|
|
1843
1861
|
}
|
|
1844
|
-
} else if (data === undefined) {
|
|
1845
|
-
A("#undefined");
|
|
1846
|
-
} else {
|
|
1847
|
-
A("#" + JSON.stringify(data));
|
|
1848
1862
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
Date
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
throw new Error(`Aberdeen internal error ${code}`);
|
|
1856
|
-
}
|
|
1857
|
-
function handleError(e, showMessage) {
|
|
1858
|
-
try {
|
|
1859
|
-
if (onError(e) === false)
|
|
1860
|
-
showMessage = false;
|
|
1861
|
-
} catch (e2) {
|
|
1862
|
-
console.error(e2);
|
|
1863
|
-
}
|
|
1864
|
-
try {
|
|
1865
|
-
if (showMessage)
|
|
1866
|
-
A("div.aberdeen-error#Error");
|
|
1867
|
-
} catch {}
|
|
1868
|
-
}
|
|
1869
|
-
function withEmitHandler(handler, func) {
|
|
1870
|
-
const oldEmitHandler = emit;
|
|
1871
|
-
emit = handler;
|
|
1872
|
-
try {
|
|
1873
|
-
func();
|
|
1874
|
-
} finally {
|
|
1875
|
-
emit = oldEmitHandler;
|
|
1863
|
+
const CUSTOM_DUMP = Symbol("CUSTOM_DUMP");
|
|
1864
|
+
Date.prototype[CUSTOM_DUMP] = function() {
|
|
1865
|
+
A("#<Date> " + this.toISOString());
|
|
1866
|
+
};
|
|
1867
|
+
function internalError(code) {
|
|
1868
|
+
throw new Error(`Aberdeen internal error ${code}`);
|
|
1876
1869
|
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1870
|
+
function handleError(e, showMessage) {
|
|
1871
|
+
try {
|
|
1872
|
+
if (onError(e) === false)
|
|
1873
|
+
showMessage = false;
|
|
1874
|
+
} catch (e2) {
|
|
1875
|
+
console.error(e2);
|
|
1876
|
+
}
|
|
1877
|
+
try {
|
|
1878
|
+
if (showMessage)
|
|
1879
|
+
A("div.aberdeen-error#Error");
|
|
1880
|
+
} catch {}
|
|
1881
|
+
}
|
|
1882
|
+
function withEmitHandler(handler, func) {
|
|
1883
|
+
const oldEmitHandler = emit;
|
|
1884
|
+
emit = handler;
|
|
1885
|
+
try {
|
|
1886
|
+
func();
|
|
1887
|
+
} finally {
|
|
1888
|
+
emit = oldEmitHandler;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
function buildCssVars() {
|
|
1892
|
+
if (isEmpty(cssVars))
|
|
1893
|
+
return "";
|
|
1894
|
+
let css = ":root{";
|
|
1895
|
+
for (const [key, value] of Object.entries(cssVars)) {
|
|
1896
|
+
const varName = DIGIT_FIRST.test(String(key)) ? `m${key}` : key;
|
|
1897
|
+
css += `--${varName}:${value};`;
|
|
1898
|
+
}
|
|
1899
|
+
return css + `}
|
|
1897
1900
|
`;
|
|
1898
|
-
|
|
1901
|
+
}
|
|
1902
|
+
if (document) {
|
|
1903
|
+
leakScope(() => {
|
|
1904
|
+
A(() => {
|
|
1905
|
+
if (isEmpty(cssSnippets) && isEmpty(cssVars))
|
|
1906
|
+
return;
|
|
1907
|
+
mount(document.head, () => {
|
|
1908
|
+
A("style.abd", () => {
|
|
1909
|
+
onEach(cssSnippets, (value) => {
|
|
1910
|
+
A("#", value);
|
|
1911
|
+
});
|
|
1912
|
+
A(() => {
|
|
1913
|
+
let css = buildCssVars();
|
|
1914
|
+
if (css)
|
|
1915
|
+
A("#", css);
|
|
1916
|
+
});
|
|
1899
1917
|
});
|
|
1900
1918
|
});
|
|
1901
1919
|
});
|
|
1902
1920
|
});
|
|
1921
|
+
}
|
|
1922
|
+
if (options.transitions === false)
|
|
1923
|
+
SPECIAL_PROPS.create = SPECIAL_PROPS.destroy = () => {};
|
|
1924
|
+
return Object.assign(A, {
|
|
1925
|
+
clean,
|
|
1926
|
+
clone,
|
|
1927
|
+
copy,
|
|
1928
|
+
count,
|
|
1929
|
+
cssVars,
|
|
1930
|
+
CUSTOM_DUMP,
|
|
1931
|
+
darkMode,
|
|
1932
|
+
defaultEmitHandler,
|
|
1933
|
+
derive,
|
|
1934
|
+
dump,
|
|
1935
|
+
EMPTY,
|
|
1936
|
+
insertCss,
|
|
1937
|
+
insertGlobalCss,
|
|
1938
|
+
invertString,
|
|
1939
|
+
isEmpty,
|
|
1940
|
+
leakScope,
|
|
1941
|
+
map,
|
|
1942
|
+
MAP_SIZE_SYMBOL,
|
|
1943
|
+
merge,
|
|
1944
|
+
mount,
|
|
1945
|
+
multiMap,
|
|
1946
|
+
OPAQUE,
|
|
1947
|
+
NO_COPY,
|
|
1948
|
+
onEach,
|
|
1949
|
+
partition,
|
|
1950
|
+
peek,
|
|
1951
|
+
proxy,
|
|
1952
|
+
ref,
|
|
1953
|
+
runQueue,
|
|
1954
|
+
setErrorHandler,
|
|
1955
|
+
setSpacingCssVars,
|
|
1956
|
+
unmountAll,
|
|
1957
|
+
unproxy,
|
|
1958
|
+
window,
|
|
1959
|
+
withEmitHandler
|
|
1903
1960
|
});
|
|
1904
1961
|
}
|
|
1905
|
-
var aberdeen_default = Object.assign(A, {
|
|
1906
|
-
clean,
|
|
1907
|
-
clone,
|
|
1908
|
-
copy,
|
|
1909
|
-
count,
|
|
1910
|
-
cssVars,
|
|
1911
|
-
CUSTOM_DUMP,
|
|
1912
|
-
darkMode,
|
|
1913
|
-
derive,
|
|
1914
|
-
disableCreateDestroy,
|
|
1915
|
-
dump,
|
|
1916
|
-
insertCss,
|
|
1917
|
-
insertGlobalCss,
|
|
1918
|
-
invertString,
|
|
1919
|
-
isEmpty,
|
|
1920
|
-
map,
|
|
1921
|
-
merge,
|
|
1922
|
-
mount,
|
|
1923
|
-
multiMap,
|
|
1924
|
-
OPAQUE,
|
|
1925
|
-
NO_COPY,
|
|
1926
|
-
onEach,
|
|
1927
|
-
partition,
|
|
1928
|
-
peek,
|
|
1929
|
-
proxy,
|
|
1930
|
-
ref,
|
|
1931
|
-
runQueue,
|
|
1932
|
-
setErrorHandler,
|
|
1933
|
-
setSpacingCssVars,
|
|
1934
|
-
unmountAll,
|
|
1935
|
-
unproxy
|
|
1936
|
-
});
|
|
1937
1962
|
export {
|
|
1938
|
-
|
|
1939
|
-
unproxy,
|
|
1940
|
-
unmountAll,
|
|
1941
|
-
setSpacingCssVars,
|
|
1942
|
-
setErrorHandler,
|
|
1943
|
-
runQueue,
|
|
1944
|
-
ref,
|
|
1945
|
-
proxy,
|
|
1946
|
-
peek,
|
|
1947
|
-
partition,
|
|
1948
|
-
onEach,
|
|
1949
|
-
multiMap,
|
|
1950
|
-
mount,
|
|
1951
|
-
merge,
|
|
1952
|
-
map,
|
|
1953
|
-
leakScope,
|
|
1954
|
-
isEmpty,
|
|
1955
|
-
invertString,
|
|
1956
|
-
insertGlobalCss,
|
|
1957
|
-
insertCss,
|
|
1958
|
-
dump,
|
|
1959
|
-
disableCreateDestroy,
|
|
1960
|
-
derive,
|
|
1961
|
-
defaultEmitHandler,
|
|
1962
|
-
aberdeen_default as default,
|
|
1963
|
-
darkMode,
|
|
1964
|
-
cssVars,
|
|
1965
|
-
count,
|
|
1966
|
-
copy,
|
|
1967
|
-
clone,
|
|
1968
|
-
clean,
|
|
1969
|
-
OPAQUE,
|
|
1970
|
-
NO_COPY,
|
|
1971
|
-
MAP_SIZE_SYMBOL,
|
|
1972
|
-
EMPTY,
|
|
1973
|
-
CUSTOM_DUMP,
|
|
1974
|
-
A
|
|
1963
|
+
createA
|
|
1975
1964
|
};
|
|
1976
1965
|
|
|
1977
|
-
//# debugId=
|
|
1966
|
+
//# debugId=D6FCE405EAFADFD364756E2164756E21
|
|
1978
1967
|
//# sourceMappingURL=aberdeen.js.map
|