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.
Files changed (139) hide show
  1. package/dist/src/aberdeen.d.ts +928 -944
  2. package/dist/src/aberdeen.js +1693 -1704
  3. package/dist/src/aberdeen.js.map +3 -3
  4. package/dist/src/index.d.ts +12 -0
  5. package/dist/src/index.js +11 -0
  6. package/dist/src/index.js.map +10 -0
  7. package/dist/src/prediction.d.ts +7 -4
  8. package/dist/src/prediction.js +18 -23
  9. package/dist/src/prediction.js.map +3 -3
  10. package/dist/src/route.d.ts +112 -99
  11. package/dist/src/route.js +254 -254
  12. package/dist/src/route.js.map +3 -3
  13. package/dist/src/server-dom.d.ts +158 -0
  14. package/dist/src/server-dom.js +458 -0
  15. package/dist/src/server-dom.js.map +10 -0
  16. package/dist/src/server.d.ts +55 -0
  17. package/dist/src/server.js +25 -0
  18. package/dist/src/server.js.map +10 -0
  19. package/dist/src/transitions.js +7 -4
  20. package/dist/src/transitions.js.map +3 -3
  21. package/dist/tests/environment.d.ts +24 -0
  22. package/dist/tests/{fakedom.js → environment.js} +239 -288
  23. package/dist/tests/environment.js.map +11 -0
  24. package/dist/tests/helpers.d.ts +15 -3
  25. package/dist/tests/helpers.js +277 -306
  26. package/dist/tests/helpers.js.map +6 -5
  27. package/dist-docs/Tutorial/index.html +30 -30
  28. package/dist-docs/aberdeen/Aberdeen/index.html +350 -0
  29. package/dist-docs/aberdeen/InitOptions/index.html +4 -0
  30. package/dist-docs/aberdeen/KeyToString/index.html +2 -0
  31. package/dist-docs/aberdeen/PromiseProxy/index.html +6 -6
  32. package/dist-docs/aberdeen/SortKeyType/index.html +2 -0
  33. package/dist-docs/aberdeen/TargetType/index.html +2 -0
  34. package/dist-docs/aberdeen/ValueRef/index.html +2 -0
  35. package/dist-docs/aberdeen/WindowLike/index.html +5 -0
  36. package/dist-docs/aberdeen/{clone → createA}/index.html +10 -5
  37. package/dist-docs/aberdeen/index.html +13 -54
  38. package/dist-docs/assets/aberdeen/aberdeen.d.ts +928 -944
  39. package/dist-docs/assets/aberdeen/aberdeen.js +1693 -1704
  40. package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
  41. package/dist-docs/assets/aberdeen/index.d.ts +12 -0
  42. package/dist-docs/assets/aberdeen/index.js +11 -0
  43. package/dist-docs/assets/aberdeen/index.js.map +10 -0
  44. package/dist-docs/assets/aberdeen/prediction.d.ts +7 -4
  45. package/dist-docs/assets/aberdeen/prediction.js +18 -23
  46. package/dist-docs/assets/aberdeen/prediction.js.map +3 -3
  47. package/dist-docs/assets/aberdeen/route.d.ts +112 -99
  48. package/dist-docs/assets/aberdeen/route.js +254 -254
  49. package/dist-docs/assets/aberdeen/route.js.map +3 -3
  50. package/dist-docs/assets/aberdeen/server-dom.d.ts +158 -0
  51. package/dist-docs/assets/aberdeen/server-dom.js +458 -0
  52. package/dist-docs/assets/aberdeen/server-dom.js.map +10 -0
  53. package/dist-docs/assets/aberdeen/server.d.ts +55 -0
  54. package/dist-docs/assets/aberdeen/server.js +25 -0
  55. package/dist-docs/assets/aberdeen/server.js.map +10 -0
  56. package/dist-docs/assets/aberdeen/transitions.js +7 -4
  57. package/dist-docs/assets/aberdeen/transitions.js.map +3 -3
  58. package/dist-docs/assets/navigation.js +1 -1
  59. package/dist-docs/assets/search.js +1 -1
  60. package/dist-docs/dispatcher/Dispatcher/index.html +5 -6
  61. package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
  62. package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
  63. package/dist-docs/dispatcher/index.html +2 -2
  64. package/dist-docs/hierarchy.html +1 -1
  65. package/dist-docs/index-1/index.html +2 -0
  66. package/dist-docs/index.html +2 -2
  67. package/dist-docs/media/CHANGELOG.md +14 -2
  68. package/dist-docs/modules.html +1 -1
  69. package/dist-docs/prediction/applyCanon/index.html +4 -3
  70. package/dist-docs/prediction/applyPrediction/index.html +4 -3
  71. package/dist-docs/prediction/index.html +2 -2
  72. package/dist-docs/route/Route/index.html +9 -9
  73. package/dist-docs/route/RouteApi/index.html +60 -0
  74. package/dist-docs/route/index.html +6 -15
  75. package/dist-docs/route/init/index.html +5 -0
  76. package/dist-docs/server/RenderToStringOptions/index.html +6 -0
  77. package/dist-docs/server/RenderToStringResult/index.html +6 -0
  78. package/dist-docs/server/index.html +4 -0
  79. package/dist-docs/server/renderToString/index.html +6 -0
  80. package/dist-docs/sitemap.xml +51 -155
  81. package/dist-docs/transitions/grow/index.html +2 -2
  82. package/dist-docs/transitions/index.html +2 -2
  83. package/dist-docs/transitions/shrink/index.html +2 -2
  84. package/package.json +17 -7
  85. package/skill/SKILL.md +28 -28
  86. package/skill/aberdeen.md +471 -3448
  87. package/skill/dispatcher.md +6 -16
  88. package/skill/prediction.md +17 -5
  89. package/skill/route.md +95 -77
  90. package/skill/transitions.md +3 -3
  91. package/src/aberdeen.ts +1226 -740
  92. package/src/index.ts +13 -0
  93. package/src/prediction.ts +25 -24
  94. package/src/route.ts +192 -142
  95. package/src/server-dom.ts +508 -0
  96. package/src/server.ts +74 -0
  97. package/src/transitions.ts +9 -3
  98. package/dist/tests/fakedom.d.ts +0 -9
  99. package/dist/tests/fakedom.js.map +0 -10
  100. package/dist-docs/aberdeen/A/index.html +0 -115
  101. package/dist-docs/aberdeen/CUSTOM_DUMP/index.html +0 -7
  102. package/dist-docs/aberdeen/NO_COPY/index.html +0 -2
  103. package/dist-docs/aberdeen/OPAQUE/index.html +0 -12
  104. package/dist-docs/aberdeen/clean/index.html +0 -11
  105. package/dist-docs/aberdeen/copy/index.html +0 -22
  106. package/dist-docs/aberdeen/count/index.html +0 -7
  107. package/dist-docs/aberdeen/cssVars/index.html +0 -11
  108. package/dist-docs/aberdeen/darkMode/index.html +0 -9
  109. package/dist-docs/aberdeen/default/index.html +0 -341
  110. package/dist-docs/aberdeen/derive/index.html +0 -18
  111. package/dist-docs/aberdeen/disableCreateDestroy/index.html +0 -6
  112. package/dist-docs/aberdeen/dump/index.html +0 -11
  113. package/dist-docs/aberdeen/insertCss/index.html +0 -30
  114. package/dist-docs/aberdeen/insertGlobalCss/index.html +0 -19
  115. package/dist-docs/aberdeen/invertString/index.html +0 -13
  116. package/dist-docs/aberdeen/isEmpty/index.html +0 -12
  117. package/dist-docs/aberdeen/map/index.html +0 -26
  118. package/dist-docs/aberdeen/merge/index.html +0 -11
  119. package/dist-docs/aberdeen/mount/index.html +0 -17
  120. package/dist-docs/aberdeen/multiMap/index.html +0 -28
  121. package/dist-docs/aberdeen/onEach/index.html +0 -19
  122. package/dist-docs/aberdeen/partition/index.html +0 -36
  123. package/dist-docs/aberdeen/peek/index.html +0 -40
  124. package/dist-docs/aberdeen/proxy/index.html +0 -35
  125. package/dist-docs/aberdeen/ref/index.html +0 -13
  126. package/dist-docs/aberdeen/runQueue/index.html +0 -13
  127. package/dist-docs/aberdeen/setErrorHandler/index.html +0 -16
  128. package/dist-docs/aberdeen/setSpacingCssVars/index.html +0 -8
  129. package/dist-docs/aberdeen/unmountAll/index.html +0 -5
  130. package/dist-docs/aberdeen/unproxy/index.html +0 -11
  131. package/dist-docs/route/back/index.html +0 -4
  132. package/dist-docs/route/current/index.html +0 -2
  133. package/dist-docs/route/go/index.html +0 -14
  134. package/dist-docs/route/interceptLinks/index.html +0 -8
  135. package/dist-docs/route/matchCurrent/index.html +0 -10
  136. package/dist-docs/route/persistScroll/index.html +0 -6
  137. package/dist-docs/route/push/index.html +0 -6
  138. package/dist-docs/route/setLog/index.html +0 -3
  139. 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
- var sortedQueue;
103
- var runQueueDepth = 0;
104
- var topRedrawScope;
105
- var survivingEl;
106
- function recordSideEffect(scope, type, key, value) {
107
- (scope.sideEffects ||= []).push(type, key, value);
108
- }
109
- function undoSideEffects(el, se) {
110
- for (let i = se.length - 3;i >= 0; i -= 3) {
111
- const key = se[i + 1];
112
- const value = se[i + 2];
113
- switch (se[i]) {
114
- case 0 /* Class */:
115
- value ? el.classList.add(key) : el.classList.remove(key);
116
- break;
117
- case 1 /* Style */:
118
- el.style[key] = value == null ? "" : value;
119
- break;
120
- case 2 /* Prop */:
121
- el[key] = value;
122
- break;
123
- case 3 /* Attr */:
124
- value == null ? el.removeAttribute(key) : el.setAttribute(key, value);
125
- break;
126
- case 4 /* Event */:
127
- el.removeEventListener(key, value);
128
- break;
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
- function queue(runner) {
133
- if (!sortedQueue) {
134
- sortedQueue = new ReverseSortedSet("prio");
135
- queueMicrotask(runQueue);
136
- } else if (!(runQueueDepth & 1)) {
137
- runQueueDepth++;
138
- if (runQueueDepth > 98) {
139
- throw new Error("Too many recursive updates from observes");
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
- sortedQueue.add(runner);
143
- }
144
- function runQueue() {
145
- let time = Date.now();
146
- while (sortedQueue) {
147
- const runner = sortedQueue.fetchLast();
148
- if (!runner)
149
- break;
150
- if (runQueueDepth & 1)
151
- runQueueDepth++;
152
- runner.queueRun();
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
- sortedQueue = undefined;
155
- runQueueDepth = 0;
156
- time = Date.now() - time;
157
- if (time > 9)
158
- console.debug(`Aberdeen queue took ${time}ms`);
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
- return result;
187
- }
188
- var lastPrio = 0;
202
+ let lastPrio = 0;
189
203
 
190
- class Scope {
191
- prio = --lastPrio;
192
- remove() {
193
- const lastNode = this.getLastNode();
194
- if (lastNode)
195
- removeNodes(lastNode, this.getPrecedingNode());
196
- const savedSurvivingEl = survivingEl;
197
- survivingEl = this.el;
198
- this.delete();
199
- survivingEl = savedSurvivingEl;
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
- queueRun;
205
- prio = --lastPrio;
206
- constructor(queueRun) {
207
- this.queueRun = queueRun;
208
- queue(this);
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
- cleaners;
214
- sideEffects;
215
- changes;
216
- constructor(cleaners = []) {
217
- super();
218
- this.cleaners = cleaners;
219
- }
220
- lastChild;
221
- redraw() {}
222
- getLastNode() {
223
- return findLastNodeInPrevSiblings(this.lastChild);
224
- }
225
- delete() {
226
- const cleaners = this.cleaners;
227
- for (let i = cleaners.length - 1;i >= 0; i--) {
228
- const cleaner = cleaners[i];
229
- if (typeof cleaner === "function")
230
- cleaner();
231
- else
232
- cleaner.delete(this);
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
- this.cleaners.length = 0;
235
- const se = this.sideEffects;
236
- if (se) {
237
- if (this.el === survivingEl)
238
- undoSideEffects(this.el, se);
239
- this.sideEffects = undefined;
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
- sortedQueue?.remove(this);
242
- this.lastChild = undefined;
243
- }
244
- onChange(target, index, newData, oldData) {
245
- if (!this.changes) {
246
- this.changes = new Map;
247
- queue(this);
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
- let targetDelta = this.changes.get(target);
250
- if (!targetDelta) {
251
- targetDelta = new Map;
252
- this.changes.set(target, targetDelta);
287
+ queueRun() {
288
+ if (!this.fetchHasChanges())
289
+ return;
290
+ this.remove();
291
+ topRedrawScope = this;
292
+ this.redraw();
293
+ topRedrawScope = undefined;
253
294
  }
254
- if (targetDelta.has(index)) {
255
- if (targetDelta.get(index) === newData)
256
- targetDelta.delete(index);
257
- } else {
258
- targetDelta.set(index, oldData);
295
+ getInsertAfterNode() {
296
+ return this.getLastNode() || this.getPrecedingNode();
259
297
  }
260
- }
261
- fetchHasChanges() {
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
- el;
291
- svg;
292
- prevSibling;
293
- constructor(el, svg, useParentCleaners = false) {
294
- super(useParentCleaners ? currentScope.cleaners : []);
295
- this.el = el;
296
- this.svg = svg;
297
- if (el === currentScope.el) {
298
- this.prevSibling = currentScope.getChildPrevSibling();
299
- currentScope.lastChild = this;
300
- } else {
301
- this.prevSibling = el.lastChild || undefined;
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
- renderer;
316
- constructor(el, svg, renderer) {
317
- super(el, svg);
318
- this.renderer = renderer;
319
- this.redraw();
320
- }
321
- redraw() {
322
- const savedScope = currentScope;
323
- currentScope = this;
324
- try {
325
- this.renderer();
326
- } catch (e) {
327
- handleError(e, true);
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
- el = document.body;
335
- svg = false;
336
- getPrecedingNode() {
337
- return;
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
- el;
343
- renderer;
344
- svg;
345
- constructor(el, renderer) {
346
- super();
347
- this.el = el;
348
- this.renderer = renderer;
349
- this.svg = el.namespaceURI === "http://www.w3.org/2000/svg";
350
- const oldTopRedrawScope = topRedrawScope;
351
- topRedrawScope = this;
352
- this.redraw();
353
- topRedrawScope = oldTopRedrawScope;
354
- currentScope.cleaners.push(this);
355
- }
356
- redraw() {
357
- RegularScope.prototype.redraw.call(this);
358
- }
359
- getPrecedingNode() {
360
- return;
361
- }
362
- delete() {
363
- removeNodes(this.getLastNode(), this.getPrecedingNode());
364
- const savedSurvivingEl = survivingEl;
365
- survivingEl = this.el;
366
- super.delete();
367
- survivingEl = savedSurvivingEl;
368
- }
369
- remove() {
370
- this.delete();
371
- }
372
- }
373
- function removeNodes(node, preNode) {
374
- while (node && node !== preNode) {
375
- const prevNode = node.previousSibling;
376
- const onDestroy = onDestroyMap.get(node);
377
- if (onDestroy && node instanceof Element) {
378
- if (onDestroy !== true) {
379
- if (typeof onDestroy === "function") {
380
- onDestroy(node);
381
- } else {
382
- destroyWithClass(node, onDestroy);
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
- onDestroyMap.set(node, true);
400
+ } else {
401
+ node.remove();
385
402
  }
386
- } else {
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
- class SetArgScope extends ChainedScope {
419
- key;
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 OnEachScope extends Scope {
437
- renderer;
438
- makeSortKey;
439
- parentElement = currentScope.el;
440
- prevSibling;
441
- target;
442
- byIndex = new Map;
443
- sortedSet = new ReverseSortedSet("sortKey");
444
- changedIndexes = new Map;
445
- constructor(proxy, renderer, makeSortKey) {
446
- super();
447
- this.renderer = renderer;
448
- this.makeSortKey = makeSortKey;
449
- const target = this.target = proxy[TARGET_SYMBOL] || proxy;
450
- subscribe(target, ANY_SYMBOL, this);
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
- getPrecedingNode() {
465
- return findLastNodeInPrevSiblings(this.prevSibling);
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
- onChange(target, index, newData, oldData) {
468
- if (!(target instanceof Array) || typeof index === "number") {
469
- if (this.changedIndexes.has(index)) {
470
- if (this.changedIndexes.get(index) === newData) {
471
- this.changedIndexes.delete(index);
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
- this.changedIndexes.set(index, oldData);
475
- queue(this);
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
- queueRun() {
480
- const indexes = this.changedIndexes;
481
- this.changedIndexes = new Map;
482
- for (const index of indexes.keys()) {
483
- const oldScope = this.byIndex.get(index);
484
- if (oldScope)
485
- oldScope.remove();
486
- if (this.target instanceof Set || this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
487
- new OnEachItemScope(this, index, true);
488
- } else {
489
- this.byIndex.delete(index);
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
- topRedrawScope = undefined;
493
- }
494
- delete() {
495
- for (const scope of this.byIndex.values()) {
496
- scope.delete();
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
- sortedQueue?.remove(this);
499
- this.byIndex.clear();
500
- setTimeout(() => {
501
- this.sortedSet.clear();
502
- }, 1);
503
- }
504
- getLastNode() {
505
- for (const scope of this.sortedSet) {
506
- const node = scope.getActualLastNode();
507
- if (node)
508
- return node;
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
- parent;
515
- itemIndex;
516
- sortKey;
517
- el;
518
- svg;
519
- constructor(parent, itemIndex, topRedraw) {
520
- super();
521
- this.parent = parent;
522
- this.itemIndex = itemIndex;
523
- this.el = parent.parentElement;
524
- this.svg = currentScope.svg;
525
- this.parent.byIndex.set(this.itemIndex, this);
526
- this.lastChild = this;
527
- if (topRedraw)
528
- topRedrawScope = this;
529
- this.redraw();
530
- }
531
- getPrecedingNode() {
532
- this.parent.sortedSet.add(this);
533
- const preScope = this.parent.sortedSet.prev(this);
534
- if (preScope)
535
- return findLastNodeInPrevSiblings(preScope.lastChild);
536
- return this.parent.getPrecedingNode();
537
- }
538
- getLastNode() {
539
- return this.getPrecedingNode();
540
- }
541
- getActualLastNode() {
542
- let child = this.lastChild;
543
- while (child && child !== this) {
544
- if (child instanceof Node)
545
- return child;
546
- const node = child.getLastNode();
547
- if (node)
548
- return node;
549
- child = child.getPrecedingNode();
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
- const savedScope = currentScope;
584
- currentScope = this;
585
- let sortKey;
586
- try {
587
- if (this.parent.makeSortKey) {
588
- sortKey = this.parent.makeSortKey(value, itemIndex);
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
- sortKey = itemIndex;
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
- if (sortKey instanceof Array)
593
- sortKey = arrayToStr(sortKey);
594
- else if (typeof sortKey !== "string" && sortKey != null)
595
- sortKey = arrayToStr([sortKey]);
596
- if (this.sortKey !== sortKey) {
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 = sortKey;
632
+ this.sortKey = undefined;
599
633
  }
600
- if (sortKey != null)
601
- this.parent.renderer(value, itemIndex);
602
- } catch (e) {
603
- handleError(e, sortKey != null);
634
+ const savedSurvivingEl = survivingEl;
635
+ survivingEl = this.el;
636
+ this.delete();
637
+ survivingEl = savedSurvivingEl;
604
638
  }
605
- currentScope = savedScope;
606
639
  }
607
- getInsertAfterNode() {
608
- if (this.sortKey == null)
609
- internalError(1);
610
- return findLastNodeInPrevSiblings(this.lastChild);
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
- remove() {
613
- if (this.sortKey !== undefined) {
614
- const lastNode = this.getActualLastNode();
615
- if (lastNode)
616
- removeNodes(lastNode, this.getPrecedingNode());
617
- this.parent.sortedSet.remove(this);
618
- this.sortKey = undefined;
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
- function addNode(el, node) {
627
- if (el !== currentScope.el) {
628
- el.appendChild(node);
629
- return;
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
- var ANY_SYMBOL = Symbol("any");
648
- var TARGET_SYMBOL = Symbol("target");
649
- var MAP_SIZE_SYMBOL = Symbol("mapSize");
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 onEach(target, render, makeKey) {
675
- if (!target || typeof target !== "object")
676
- throw new Error("A.onEach requires an object");
677
- target = target[TARGET_SYMBOL] || target;
678
- new OnEachScope(target, render, makeKey);
679
- }
680
- function isObjEmpty(obj) {
681
- for (const k of Object.keys(obj))
682
- return false;
683
- return true;
684
- }
685
- var EMPTY = Symbol("empty");
686
- function isEmpty(proxied) {
687
- const target = proxied[TARGET_SYMBOL] || proxied;
688
- const scope = currentScope;
689
- if (target instanceof Array) {
690
- subscribe(target, "length", (index, newData, oldData) => {
691
- if (!newData !== !oldData)
692
- scope.onChange(target, EMPTY, !newData, !oldData);
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 !target.length;
695
- }
696
- if (target instanceof Map || target instanceof Set) {
697
- subscribe(target, MAP_SIZE_SYMBOL, (index, newData, oldData) => {
698
- if (!newData !== !oldData)
699
- scope.onChange(target, EMPTY, !newData, !oldData);
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 !target.size;
744
+ return result;
702
745
  }
703
- let oldEmpty = isObjEmpty(target);
704
- subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
705
- if (newData === EMPTY !== (oldData === EMPTY)) {
706
- const newEmpty = isObjEmpty(target);
707
- scope.onChange(target, EMPTY, newEmpty, oldEmpty);
708
- oldEmpty = newEmpty;
709
- }
710
- });
711
- return oldEmpty;
712
- }
713
- function count(proxied) {
714
- if (proxied instanceof Array)
715
- return ref(proxied, "length");
716
- if (proxied instanceof Map || proxied instanceof Set)
717
- return ref(proxied, "size");
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
- var emit = defaultEmitHandler;
751
- var objectHandler = {
752
- get(target, prop) {
753
- if (prop === TARGET_SYMBOL)
754
- return target;
755
- subscribe(target, prop);
756
- return optProxy(target[prop]);
757
- },
758
- set(target, prop, newData) {
759
- if (typeof newData === "object" && newData)
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
- const oldData = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
800
+ }
801
+ let oldData = target[prop];
802
+ if (oldData === undefined && !target.hasOwnProperty(prop))
803
+ oldData = EMPTY;
762
804
  if (newData !== oldData) {
763
- target[prop] = newData;
764
- emit(target, prop, newData, oldData);
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
- function arraySet(target, prop, newData) {
784
- if (typeof newData === "object" && newData) {
785
- newData = newData[TARGET_SYMBOL] || newData;
786
- }
787
- let oldData = target[prop];
788
- if (oldData === undefined && !target.hasOwnProperty(prop))
789
- oldData = EMPTY;
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
- } else {
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] = newData;
804
- emit(target, prop, newData, oldData);
805
- }
806
- if (target.length !== oldLength) {
807
- emit(target, "length", target.length, oldLength);
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
- return true;
811
- }
812
- var arrayHandler = {
813
- get(target, prop) {
814
- if (prop === TARGET_SYMBOL)
815
- return target;
816
- if (typeof prop === "string") {
817
- const n = 0 | prop;
818
- if (String(n) === prop && n >= 0)
819
- prop = n;
820
- }
821
- subscribe(target, prop);
822
- return optProxy(target[prop]);
823
- },
824
- set: arraySet,
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
- function wrapIteratorSingle(iterator) {
840
- return {
841
- [Symbol.iterator]() {
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
- next() {
845
- const result = iterator.next();
846
- if (result.done)
847
- return result;
848
- return {
849
- done: false,
850
- value: optProxy(result.value)
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
- function wrapIteratorPair(iterator) {
856
- return {
857
- [Symbol.iterator]() {
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
- next() {
861
- const result = iterator.next();
862
- if (result.done)
863
- return result;
864
- return {
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.set(key, newData);
891
- emit(target, key, newData, oldData);
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
- return this;
956
- },
957
- delete(value) {
958
- const target = this[TARGET_SYMBOL];
959
- value = unproxyCollectionValue(value);
960
- if (!target.has(value))
961
- return false;
962
- const oldSize = target.size;
963
- target.delete(value);
964
- emit(target, value, EMPTY, value);
965
- emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
966
- return true;
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
- if (prop === "size") {
1013
- subscribe(target, MAP_SIZE_SYMBOL);
1014
- return target.size;
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
- return target[prop];
1017
- }
1018
- };
1019
- var setHandler = {
1020
- get(target, prop) {
1021
- if (prop === TARGET_SYMBOL)
1022
- return target;
1023
- if (setMethodHandlers.hasOwnProperty(prop)) {
1024
- return setMethodHandlers[prop];
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
- if (prop === "size") {
1027
- subscribe(target, MAP_SIZE_SYMBOL);
1028
- return target.size;
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[prop];
1083
+ return optProxy(typeof target === "object" && target !== null ? target : { value: target });
1031
1084
  }
1032
- };
1033
- var proxyMap = new WeakMap;
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
- let proxied = proxyMap.get(value);
1039
- if (proxied)
1040
- return proxied;
1041
- let handler;
1042
- if (value instanceof Array) {
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
- return optProxy(typeof target === "object" && target !== null ? target : { value: target });
1070
- }
1071
- function unproxy(target) {
1072
- return target ? target[TARGET_SYMBOL] || target : target;
1073
- }
1074
- var onDestroyMap = new WeakMap;
1075
- function destroyWithClass(element, cls) {
1076
- const classes = cls.split(".").filter((c) => c);
1077
- element.classList.add(...classes);
1078
- setTimeout(() => element.remove(), 2000);
1079
- }
1080
- function copy(a, b, c) {
1081
- if (arguments.length > 2)
1082
- return copySet(a, b, c, 0);
1083
- return copyImpl(a, b, 0);
1084
- }
1085
- function copySet(dst, dstKey, src, flags) {
1086
- let dstVal = peek(dst, dstKey);
1087
- if (src === dstVal)
1088
- return false;
1089
- if (typeof dstVal === "object" && dstVal !== null && typeof src === "object" && src !== null && dstVal.constructor === src.constructor) {
1090
- return copyImpl(dstVal, src, flags);
1091
- }
1092
- src = clone(src);
1093
- if (dst instanceof Map)
1094
- dst.set(dstKey, src);
1095
- else
1096
- dst[dstKey] = clone(src);
1097
- return true;
1098
- }
1099
- function merge(a, b, c) {
1100
- if (arguments.length > 2)
1101
- return copySet(a, b, c, MERGE);
1102
- return copyImpl(a, b, MERGE);
1103
- }
1104
- function copyImpl(dst, src, flags) {
1105
- let unproxied = dst[TARGET_SYMBOL];
1106
- if (unproxied) {
1107
- dst = unproxied;
1108
- flags |= COPY_EMIT;
1109
- }
1110
- unproxied = src[TARGET_SYMBOL];
1111
- if (unproxied) {
1112
- src = unproxied;
1113
- if (currentScope !== ROOT_SCOPE && !peeking)
1114
- flags |= COPY_SUBSCRIBE;
1115
- }
1116
- return copyRecursive(dst, src, flags);
1117
- }
1118
- function copyRecursive(dst, src, flags) {
1119
- if (flags & COPY_SUBSCRIBE)
1120
- subscribe(src, ANY_SYMBOL);
1121
- let changed = false;
1122
- if (src instanceof Array && dst instanceof Array) {
1123
- const dstLen = dst.length;
1124
- const srcLen = src.length;
1125
- for (let index = 0;index < srcLen; index++) {
1126
- let dstValue = dst[index];
1127
- if (dstValue === undefined && !dst.hasOwnProperty(index))
1128
- dstValue = EMPTY;
1129
- let srcValue = src[index];
1130
- if (srcValue === undefined && !src.hasOwnProperty(index)) {
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
- srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
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
- if (srcLen !== dstLen) {
1150
- if (flags & COPY_EMIT) {
1151
- for (let i = srcLen;i < dstLen; i++) {
1152
- const old = dst[i];
1153
- delete dst[i];
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
- srcValue = cloneRecursive(srcValue, flags & COPY_SUBSCRIBE);
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
- if (!(flags & MERGE)) {
1184
- for (const k of dst.keys()) {
1185
- if (!src.has(k)) {
1186
- const old = dst.get(k);
1187
- dst.delete(k);
1188
- if (flags & COPY_EMIT) {
1189
- emit(dst, k, EMPTY, old);
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
- } else if (src.constructor === dst.constructor) {
1196
- for (const key of Object.keys(src)) {
1197
- let srcValue = src[key];
1198
- const dstValue = dst.hasOwnProperty(key) ? dst[key] : EMPTY;
1199
- if (dstValue !== srcValue) {
1200
- if (typeof srcValue === "object" && srcValue !== null) {
1201
- if (typeof dstValue === "object" && dstValue !== null && srcValue.constructor === dstValue.constructor && !(OPAQUE in srcValue)) {
1202
- changed = copyRecursive(dstValue, srcValue, flags) || 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
- if (!(flags & MERGE)) {
1214
- for (const k of Object.keys(dst)) {
1215
- if (!src.hasOwnProperty(k)) {
1216
- const old = dst[k];
1217
- delete dst[k];
1218
- if (flags & COPY_EMIT && old !== undefined) {
1219
- emit(dst, k, EMPTY, old);
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
- } else {
1226
- throw new Error(`Incompatible or non-object types: ${src?.constructor?.name || typeof src} vs ${dst?.constructor?.name || typeof dst}`);
1227
- }
1228
- return changed;
1229
- }
1230
- var MERGE = 1;
1231
- var COPY_SUBSCRIBE = 32;
1232
- var COPY_EMIT = 64;
1233
- var OPAQUE = Symbol("OPAQUE");
1234
- var NO_COPY = OPAQUE;
1235
- Promise.prototype[OPAQUE] = true;
1236
- var cssVars = optProxy({});
1237
- function setSpacingCssVars(base = 1, unit = "rem") {
1238
- for (let i = 0;i <= 12; i++) {
1239
- cssVars[i] = 2 ** (i - 3) * base + unit;
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
- var CSS_VAR_PATTERN = /(\burl\([^)]*\))|("[^"]*")|(^| )\$([\w-]+)/g;
1243
- var DIGIT_FIRST = /^\d/;
1244
- function cssVarRef(value) {
1245
- if (value.indexOf("$") < 0)
1246
- return value;
1247
- return value.replace(CSS_VAR_PATTERN, (match, parens, quoted, prefix, name) => {
1248
- if (parens || quoted)
1249
- return match;
1250
- const varName = DIGIT_FIRST.test(name) ? `m${name}` : name;
1251
- return `${prefix}var(--${varName})`;
1252
- });
1253
- }
1254
- var darkModeState;
1255
- function darkMode() {
1256
- if (!darkModeState) {
1257
- if (typeof window === "undefined" || !window.matchMedia)
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
- return false;
1314
- }
1315
- };
1316
- function ref(target, index) {
1317
- return new Proxy({ proxy: target, index }, refHandler);
1318
- }
1319
- function applyBind(el, target) {
1320
- let onProxyChange;
1321
- let onInputChange;
1322
- const type = el.getAttribute("type");
1323
- const value = unproxy(target).value;
1324
- if (type === "checkbox") {
1325
- if (value === undefined)
1326
- target.value = el.checked;
1327
- onProxyChange = () => {
1328
- el.checked = target.value;
1329
- };
1330
- onInputChange = () => {
1331
- target.value = el.checked;
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
- } else {
1344
- onInputChange = () => {
1345
- target.value = type === "number" || type === "range" ? el.value === "" ? null : +el.value : el.value;
1346
- };
1347
- if (value === undefined)
1348
- onInputChange();
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
- const tmpParent = document.createElement(currentScope.el.tagName);
1386
- tmpParent.innerHTML = `${value}`;
1387
- while (tmpParent.firstChild)
1388
- addNode(el, tmpParent.firstChild);
1389
- }
1390
- },
1391
- text: (el, value) => {
1392
- addNode(el, document.createTextNode(value));
1393
- },
1394
- rich: (el, value) => {
1395
- let lastIndex = 0;
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
- function disableCreateDestroy() {
1428
- SPECIAL_PROPS.create = SPECIAL_PROPS.destroy = () => {};
1429
- }
1430
- function A(...args) {
1431
- let el = currentScope.el;
1432
- let svg = currentScope.svg;
1433
- const argCount = args.length;
1434
- for (let argIndex = 0;argIndex < argCount; argIndex++) {
1435
- const arg = args[argIndex];
1436
- if (arg == null || arg === false) {} else if (typeof arg === "string") {
1437
- let argLen = arg.length;
1438
- let nextPos = 0;
1439
- for (let pos = 0;pos < argLen; pos = nextPos + 1) {
1440
- nextPos = findFirst(arg, " .=:#", pos);
1441
- const next = arg[nextPos];
1442
- if (next === ":") {
1443
- const key = "$" + arg.substring(pos, nextPos);
1444
- if (nextPos + 1 >= argLen) {
1445
- applyArg(el, key, args[++argIndex]);
1446
- break;
1447
- }
1448
- if (arg[nextPos + 1] === " ") {
1449
- const endIndex = findFirst(arg, ";", nextPos + 2);
1450
- const value = arg.substring(nextPos + 2, endIndex).trim();
1451
- applyArg(el, key, value);
1452
- nextPos = endIndex;
1453
- } else {
1454
- const endIndex = findFirst(arg, " ", nextPos + 1);
1455
- const value = arg.substring(nextPos + 1, endIndex);
1456
- applyArg(el, key, value);
1457
- nextPos = endIndex;
1458
- }
1459
- } else if (next === "=") {
1460
- const key = arg.substring(pos, nextPos);
1461
- if (nextPos + 1 >= argLen) {
1462
- applyArg(el, key, args[++argIndex]);
1463
- break;
1464
- }
1465
- const afterEquals = arg[nextPos + 1];
1466
- if (afterEquals === '"' || afterEquals === "'" || afterEquals === "`") {
1467
- const endIndex = findFirst(arg, afterEquals, nextPos + 2);
1468
- const value = arg.substring(nextPos + 2, endIndex);
1469
- applyArg(el, key, value);
1470
- nextPos = endIndex;
1471
- } else {
1472
- const endIndex = findFirst(arg, " ", nextPos + 1);
1473
- const value = arg.substring(nextPos + 1, endIndex);
1474
- applyArg(el, key, value);
1475
- nextPos = endIndex;
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
- if (nextPos > pos) {
1479
- const tag = arg.substring(pos, nextPos);
1480
- svg ||= tag === "svg";
1481
- let newEl = svg ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
1482
- addNode(el, newEl);
1483
- el = newEl;
1484
- }
1485
- if (next === "#") {
1486
- const text = nextPos + 1 < argLen ? arg.substring(nextPos + 1) : args[++argIndex];
1487
- applyArg(el, "text", text);
1488
- break;
1489
- }
1490
- if (next === ".") {
1491
- let classEnd = findFirst(arg, " #=.", nextPos + 1);
1492
- if (arg[classEnd] === "=" && classEnd + 1 >= argLen) {
1493
- applyArg(el, arg.substring(nextPos, classEnd), args[++argIndex]);
1494
- nextPos = classEnd;
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
- let className = arg.substring(nextPos + 1, classEnd);
1497
- const cls = className || args[++argIndex];
1498
- if (!el.classList.contains(cls)) {
1499
- if (el === currentScope.el)
1500
- recordSideEffect(currentScope, 0 /* Class */, cls, false);
1501
- el.classList.add(cls);
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
- } else if (typeof arg === "object") {
1509
- if (arg.constructor !== Object) {
1510
- if (arg instanceof Node) {
1511
- addNode(el, arg);
1512
- if (arg instanceof Element) {
1513
- el = arg;
1514
- svg = arg.namespaceURI === "http://www.w3.org/2000/svg";
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
- throw new Error(`Unexpected argument: ${arg}`);
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
- for (const key of Object.keys(arg)) {
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
- return el;
1531
- }
1532
- function findFirst(str, chars, startPos) {
1533
- if (chars.length === 1) {
1534
- const idx = str.indexOf(chars, startPos);
1535
- return idx >= 0 ? idx : str.length;
1536
- }
1537
- const strLen = str.length;
1538
- for (let i = startPos;i < strLen; i++) {
1539
- if (chars.indexOf(str[i]) >= 0)
1540
- return i;
1541
- }
1542
- return strLen;
1543
- }
1544
- var cssCount = 0;
1545
- function insertCss(style) {
1546
- const prefix = `.AbdStl${++cssCount}`;
1547
- const css = typeof style === "string" ? styleStringToCss(style, prefix) : objectToCss(style, prefix);
1548
- if (css) {
1549
- let cnt = cssSnippetCount++;
1550
- cssSnippets[cnt] = css;
1551
- clean(() => delete cssSnippets[cnt]);
1552
- }
1553
- return prefix;
1554
- }
1555
- var cssSnippets = proxy({});
1556
- var cssSnippetCount = 0;
1557
- function combinePrefixSelector(prefix, key) {
1558
- const sel = [];
1559
- for (const p of prefix.split(",")) {
1560
- for (const k of key.split(",")) {
1561
- sel.push(k.includes("&") ? k.trim().replace(/&/g, p) : `${p} ${k.trim()}`.trim());
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
- return sel.join(",");
1565
- }
1566
- function objectToCss(style, prefix) {
1567
- let css = "";
1568
- for (const [key, val] of Object.entries(style)) {
1569
- if (val && typeof val === "object") {
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
- } else {
1575
- css += objectToCss(val, combinePrefixSelector(prefix, key));
1576
- }
1577
- } else if (typeof val === "string") {
1578
- if (key.startsWith("@")) {
1579
- css += `${key}{
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
- } else {
1583
- css += styleStringToCss(val, combinePrefixSelector(prefix, key));
1595
+ } else {
1596
+ css += styleStringToCss(val, combinePrefixSelector(prefix, key));
1597
+ }
1584
1598
  }
1585
1599
  }
1600
+ return css;
1586
1601
  }
1587
- return css;
1588
- }
1589
- var KEBAB_SEGMENT = /-([a-z])/g;
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
- return props ? `${selector}{${props}}
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
- var CSS_SHORT = {
1635
- m: "margin",
1636
- mt: "margin-top",
1637
- mb: "margin-bottom",
1638
- ml: "margin-left",
1639
- mr: "margin-right",
1640
- mh: ["margin-left", "margin-right"],
1641
- mv: ["margin-top", "margin-bottom"],
1642
- p: "padding",
1643
- pt: "padding-top",
1644
- pb: "padding-bottom",
1645
- pl: "padding-left",
1646
- pr: "padding-right",
1647
- ph: ["padding-left", "padding-right"],
1648
- pv: ["padding-top", "padding-bottom"],
1649
- w: "width",
1650
- h: "height",
1651
- bg: "background",
1652
- fg: "color",
1653
- r: "border-radius"
1654
- };
1655
- function applyArg(el, key, value) {
1656
- if (typeof value === "object" && value !== null && value[TARGET_SYMBOL]) {
1657
- if (key === "bind") {
1658
- applyBind(el, value);
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
- new SetArgScope(el, key, value);
1714
+ if (el === currentScope.el)
1715
+ recordSideEffect(currentScope, 3 /* Attr */, key, el.getAttribute(key));
1716
+ el.setAttribute(key, value);
1661
1717
  }
1662
- } else if (key[0] === ".") {
1663
- const classes = key.substring(1).split(".");
1664
- const list = el.classList;
1665
- const desired = !!value;
1666
- if (el === currentScope.el) {
1667
- for (const cls of classes) {
1668
- const had = list.contains(cls);
1669
- if (had !== desired)
1670
- recordSideEffect(currentScope, 0 /* Class */, cls, had);
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
- function defaultOnError(error) {
1707
- console.error("Error while in Aberdeen render:", error);
1708
- return true;
1709
- }
1710
- var onError = defaultOnError;
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
- return target instanceof Map ? target.get(key) : target[key];
1734
- }
1735
- } finally {
1736
- peeking--;
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
- function map(source, func) {
1740
- let out;
1741
- if (source instanceof Array) {
1742
- out = optProxy([]);
1743
- } else if (source instanceof Map) {
1744
- out = optProxy(new Map);
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
- delete out[key];
1787
+ for (const key2 of Object.keys(pairs))
1788
+ delete out[key2];
1760
1789
  });
1761
1790
  }
1762
- }
1763
- });
1764
- return out;
1765
- }
1766
- function multiMap(source, func) {
1767
- const out = optProxy({});
1768
- onEach(source, (item, key) => {
1769
- const pairs = func(item, key);
1770
- if (pairs) {
1771
- for (const key2 of Object.keys(pairs))
1772
- out[key2] = pairs[key2];
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
- delete out[bucket][key];
1798
- if (isObjEmpty(unproxiedOut[bucket]))
1799
- delete out[bucket];
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
- return out;
1806
- }
1807
- function dump(data) {
1808
- const org = dumpSeen;
1809
- dumpSeen ||= new Set;
1810
- try {
1811
- rawDump(data, dumpSeen);
1812
- } finally {
1813
- dumpSeen = org;
1814
- }
1815
- return data;
1816
- }
1817
- var dumpSeen;
1818
- function rawDump(data, seen) {
1819
- if (data && typeof data === "object") {
1820
- const name = data.constructor.name || "unknown object";
1821
- if (seen.has(data)) {
1822
- A(`#<${name}: circular reference>`);
1823
- return;
1824
- }
1825
- seen.add(data);
1826
- clean(() => seen.delete(data));
1827
- const customDump = data[CUSTOM_DUMP];
1828
- if (customDump !== undefined) {
1829
- if (typeof customDump === "function")
1830
- customDump.call(data);
1831
- else
1832
- A(`#${customDump}`);
1833
- } else {
1834
- A(`#<${name}>`, "ul", () => {
1835
- onEach(data, (value, key) => {
1836
- A("li", () => {
1837
- if (!(data instanceof Array))
1838
- A(`#${JSON.stringify(key)}: `);
1839
- rawDump(value, seen);
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
- var CUSTOM_DUMP = Symbol("CUSTOM_DUMP");
1851
- Date.prototype[CUSTOM_DUMP] = function() {
1852
- A("#<Date> " + this.toISOString());
1853
- };
1854
- function internalError(code) {
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
- if (typeof document !== "undefined") {
1879
- leakScope(() => {
1880
- A(() => {
1881
- if (isEmpty(cssSnippets) && isEmpty(cssVars))
1882
- return;
1883
- mount(document.head, () => {
1884
- A("style.abd", () => {
1885
- onEach(cssSnippets, (value) => {
1886
- A("#", value);
1887
- });
1888
- A(() => {
1889
- if (isEmpty(cssVars))
1890
- return;
1891
- let css = ":root{";
1892
- for (const [key, value] of Object.entries(cssVars)) {
1893
- const varName = DIGIT_FIRST.test(String(key)) ? `m${key}` : key;
1894
- css += `--${varName}:${value};`;
1895
- }
1896
- css += `}
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
- A("#", css);
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
- withEmitHandler,
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=28BFF8A898B656A464756E2164756E21
1966
+ //# debugId=D6FCE405EAFADFD364756E2164756E21
1978
1967
  //# sourceMappingURL=aberdeen.js.map