marko 6.0.0-next.3.26 → 6.0.0-next.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/types.d.ts +3 -3
- package/dist/debug/dom.js +276 -274
- package/dist/debug/dom.mjs +276 -274
- package/dist/dom/compat.d.ts +3 -3
- package/dist/dom/dom.d.ts +2 -1
- package/dist/dom/reconcile.d.ts +1 -1
- package/dist/dom/scope.d.ts +1 -1
- package/dist/dom/walker.d.ts +2 -2
- package/dist/dom.js +184 -184
- package/dist/dom.mjs +184 -184
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/common/types.d.ts
CHANGED
@@ -2,6 +2,8 @@ import type { Renderer as ClientRenderer } from "../dom/renderer";
|
|
2
2
|
export type Falsy = undefined | null | false | 0 | "";
|
3
3
|
export type CommentWalker = TreeWalker & Record<string, Comment>;
|
4
4
|
export interface BranchScope extends Scope {
|
5
|
+
___startNode: ChildNode;
|
6
|
+
___endNode: ChildNode;
|
5
7
|
___parentBranch: BranchScope | undefined;
|
6
8
|
___branchDepth: number;
|
7
9
|
___destroyed: 1 | undefined;
|
@@ -12,8 +14,6 @@ export interface Scope {
|
|
12
14
|
$global: Record<string, unknown>;
|
13
15
|
_: Scope | undefined;
|
14
16
|
___args: unknown;
|
15
|
-
___startNode: Node & ChildNode;
|
16
|
-
___endNode: Node & ChildNode;
|
17
17
|
___pending: 1 | 0 | undefined;
|
18
18
|
___renderer: ClientRenderer | undefined;
|
19
19
|
___abortControllers: Record<string | number, AbortController | void> | undefined;
|
@@ -86,7 +86,7 @@ export interface TemplateInput extends Input {
|
|
86
86
|
$global?: $Global;
|
87
87
|
}
|
88
88
|
export interface Template {
|
89
|
-
mount(input: Input, reference:
|
89
|
+
mount(input: Input, reference: Node, position?: InsertPosition): TemplateInstance;
|
90
90
|
render(input?: Input): RenderResult;
|
91
91
|
}
|
92
92
|
export interface TemplateInstance {
|
package/dist/debug/dom.js
CHANGED
@@ -174,64 +174,6 @@ function triggerMacroTask() {
|
|
174
174
|
port2.postMessage(0);
|
175
175
|
}
|
176
176
|
|
177
|
-
// src/dom/scope.ts
|
178
|
-
var pendingScopes = [];
|
179
|
-
var debugID = 0;
|
180
|
-
function createScope($global) {
|
181
|
-
const scope = {
|
182
|
-
___pending: 1,
|
183
|
-
$global
|
184
|
-
};
|
185
|
-
if (true) {
|
186
|
-
scope.___debugId = "client-" + debugID++;
|
187
|
-
}
|
188
|
-
pendingScopes.push(scope);
|
189
|
-
return scope;
|
190
|
-
}
|
191
|
-
function finishPendingScopes() {
|
192
|
-
for (const scope of pendingScopes) {
|
193
|
-
scope.___pending = 0;
|
194
|
-
}
|
195
|
-
pendingScopes = [];
|
196
|
-
}
|
197
|
-
var emptyBranch = createScope({});
|
198
|
-
function getEmptyBranch(marker) {
|
199
|
-
emptyBranch.___startNode = emptyBranch.___endNode = marker;
|
200
|
-
return emptyBranch;
|
201
|
-
}
|
202
|
-
function destroyBranch(branch) {
|
203
|
-
branch.___parentBranch?.___branchScopes?.delete(branch);
|
204
|
-
destroyNestedBranches(branch);
|
205
|
-
}
|
206
|
-
function destroyNestedBranches(branch) {
|
207
|
-
branch.___destroyed = 1;
|
208
|
-
branch.___branchScopes?.forEach(destroyNestedBranches);
|
209
|
-
branch.___abortScopes?.forEach((scope) => {
|
210
|
-
for (const id in scope.___abortControllers) {
|
211
|
-
scope.___abortControllers[id]?.abort();
|
212
|
-
}
|
213
|
-
});
|
214
|
-
}
|
215
|
-
function removeAndDestroyBranch(branch) {
|
216
|
-
destroyBranch(branch);
|
217
|
-
let current = branch.___startNode;
|
218
|
-
const stop = branch.___endNode.nextSibling;
|
219
|
-
while (current !== stop) {
|
220
|
-
const next = current.nextSibling;
|
221
|
-
current.remove();
|
222
|
-
current = next;
|
223
|
-
}
|
224
|
-
}
|
225
|
-
function insertBranchBefore(branch, parent, nextSibling) {
|
226
|
-
let current = branch.___startNode;
|
227
|
-
const stop = branch.___endNode.nextSibling;
|
228
|
-
while (current !== stop) {
|
229
|
-
const next = current.nextSibling;
|
230
|
-
parent.insertBefore(current, nextSibling);
|
231
|
-
current = next;
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
177
|
// src/common/helpers.ts
|
236
178
|
function classValue(value2) {
|
237
179
|
return toDelimitedString(value2, " ", stringifyClassObject);
|
@@ -287,173 +229,6 @@ function normalizeDynamicRenderer(value2) {
|
|
287
229
|
if (value2) return value2.content || value2.default || value2;
|
288
230
|
}
|
289
231
|
|
290
|
-
// src/dom/reconcile.ts
|
291
|
-
var WRONG_POS = 2147483647;
|
292
|
-
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
293
|
-
let oldStart = 0;
|
294
|
-
let newStart = 0;
|
295
|
-
let oldEnd = oldBranches.length - 1;
|
296
|
-
let newEnd = newBranches.length - 1;
|
297
|
-
let oldStartBranch = oldBranches[oldStart];
|
298
|
-
let newStartBranch = newBranches[newStart];
|
299
|
-
let oldEndBranch = oldBranches[oldEnd];
|
300
|
-
let newEndBranch = newBranches[newEnd];
|
301
|
-
let i;
|
302
|
-
let j;
|
303
|
-
let k;
|
304
|
-
let nextSibling;
|
305
|
-
let oldBranch;
|
306
|
-
let newBranch;
|
307
|
-
outer: {
|
308
|
-
while (oldStartBranch === newStartBranch) {
|
309
|
-
++oldStart;
|
310
|
-
++newStart;
|
311
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
312
|
-
break outer;
|
313
|
-
}
|
314
|
-
oldStartBranch = oldBranches[oldStart];
|
315
|
-
newStartBranch = newBranches[newStart];
|
316
|
-
}
|
317
|
-
while (oldEndBranch === newEndBranch) {
|
318
|
-
--oldEnd;
|
319
|
-
--newEnd;
|
320
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
321
|
-
break outer;
|
322
|
-
}
|
323
|
-
oldEndBranch = oldBranches[oldEnd];
|
324
|
-
newEndBranch = newBranches[newEnd];
|
325
|
-
}
|
326
|
-
}
|
327
|
-
if (oldStart > oldEnd) {
|
328
|
-
if (newStart <= newEnd) {
|
329
|
-
k = newEnd + 1;
|
330
|
-
nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
|
331
|
-
do {
|
332
|
-
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
333
|
-
} while (newStart <= newEnd);
|
334
|
-
}
|
335
|
-
} else if (newStart > newEnd) {
|
336
|
-
do {
|
337
|
-
removeAndDestroyBranch(oldBranches[oldStart++]);
|
338
|
-
} while (oldStart <= oldEnd);
|
339
|
-
} else {
|
340
|
-
const oldLength = oldEnd - oldStart + 1;
|
341
|
-
const newLength = newEnd - newStart + 1;
|
342
|
-
const aNullable = oldBranches;
|
343
|
-
const sources = new Array(newLength);
|
344
|
-
for (i = 0; i < newLength; ++i) {
|
345
|
-
sources[i] = -1;
|
346
|
-
}
|
347
|
-
let pos = 0;
|
348
|
-
let synced = 0;
|
349
|
-
const keyIndex = /* @__PURE__ */ new Map();
|
350
|
-
for (j = newStart; j <= newEnd; ++j) {
|
351
|
-
keyIndex.set(newBranches[j], j);
|
352
|
-
}
|
353
|
-
for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
|
354
|
-
oldBranch = oldBranches[i];
|
355
|
-
j = keyIndex.get(oldBranch);
|
356
|
-
if (j !== void 0) {
|
357
|
-
pos = pos > j ? WRONG_POS : j;
|
358
|
-
++synced;
|
359
|
-
newBranch = newBranches[j];
|
360
|
-
sources[j - newStart] = i;
|
361
|
-
aNullable[i] = null;
|
362
|
-
}
|
363
|
-
}
|
364
|
-
if (oldLength === oldBranches.length && synced === 0) {
|
365
|
-
for (; newStart < newLength; ++newStart) {
|
366
|
-
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
367
|
-
}
|
368
|
-
for (; oldStart < oldLength; ++oldStart) {
|
369
|
-
removeAndDestroyBranch(oldBranches[oldStart]);
|
370
|
-
}
|
371
|
-
} else {
|
372
|
-
i = oldLength - synced;
|
373
|
-
while (i > 0) {
|
374
|
-
oldBranch = aNullable[oldStart++];
|
375
|
-
if (oldBranch !== null) {
|
376
|
-
removeAndDestroyBranch(oldBranch);
|
377
|
-
i--;
|
378
|
-
}
|
379
|
-
}
|
380
|
-
if (pos === WRONG_POS) {
|
381
|
-
const seq = longestIncreasingSubsequence(sources);
|
382
|
-
j = seq.length - 1;
|
383
|
-
k = newBranches.length;
|
384
|
-
for (i = newLength - 1; i >= 0; --i) {
|
385
|
-
if (sources[i] === -1) {
|
386
|
-
pos = i + newStart;
|
387
|
-
newBranch = newBranches[pos++];
|
388
|
-
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
389
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
390
|
-
} else {
|
391
|
-
if (j < 0 || i !== seq[j]) {
|
392
|
-
pos = i + newStart;
|
393
|
-
newBranch = newBranches[pos++];
|
394
|
-
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
395
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
396
|
-
} else {
|
397
|
-
--j;
|
398
|
-
}
|
399
|
-
}
|
400
|
-
}
|
401
|
-
} else if (synced !== newLength) {
|
402
|
-
k = newBranches.length;
|
403
|
-
for (i = newLength - 1; i >= 0; --i) {
|
404
|
-
if (sources[i] === -1) {
|
405
|
-
pos = i + newStart;
|
406
|
-
newBranch = newBranches[pos++];
|
407
|
-
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
408
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
409
|
-
}
|
410
|
-
}
|
411
|
-
}
|
412
|
-
}
|
413
|
-
}
|
414
|
-
}
|
415
|
-
function longestIncreasingSubsequence(a) {
|
416
|
-
const p = a.slice();
|
417
|
-
const result = [];
|
418
|
-
result.push(0);
|
419
|
-
let u;
|
420
|
-
let v;
|
421
|
-
for (let i = 0, il = a.length; i < il; ++i) {
|
422
|
-
if (a[i] === -1) {
|
423
|
-
continue;
|
424
|
-
}
|
425
|
-
const j = result[result.length - 1];
|
426
|
-
if (a[j] < a[i]) {
|
427
|
-
p[i] = j;
|
428
|
-
result.push(i);
|
429
|
-
continue;
|
430
|
-
}
|
431
|
-
u = 0;
|
432
|
-
v = result.length - 1;
|
433
|
-
while (u < v) {
|
434
|
-
const c = (u + v) / 2 | 0;
|
435
|
-
if (a[result[c]] < a[i]) {
|
436
|
-
u = c + 1;
|
437
|
-
} else {
|
438
|
-
v = c;
|
439
|
-
}
|
440
|
-
}
|
441
|
-
if (a[i] < a[result[u]]) {
|
442
|
-
if (u > 0) {
|
443
|
-
p[i] = result[u - 1];
|
444
|
-
}
|
445
|
-
result[u] = i;
|
446
|
-
}
|
447
|
-
}
|
448
|
-
u = result.length;
|
449
|
-
v = result[u - 1];
|
450
|
-
while (u-- > 0) {
|
451
|
-
result[u] = v;
|
452
|
-
v = p[v];
|
453
|
-
}
|
454
|
-
return result;
|
455
|
-
}
|
456
|
-
|
457
232
|
// src/dom/event.ts
|
458
233
|
var elementHandlersByEvent = /* @__PURE__ */ new Map();
|
459
234
|
var defaultDelegator = createDelegator();
|
@@ -482,7 +257,7 @@ function createDelegator() {
|
|
482
257
|
};
|
483
258
|
}
|
484
259
|
function handleDelegated(ev) {
|
485
|
-
let target = ev.target;
|
260
|
+
let target = !rendering && ev.target;
|
486
261
|
if (target) {
|
487
262
|
const handlersByElement = elementHandlersByEvent.get(ev.type);
|
488
263
|
handlersByElement.get(target)?.(ev, target);
|
@@ -555,15 +330,20 @@ var Render = class {
|
|
555
330
|
const commentPrefix = data2.i;
|
556
331
|
const commentPrefixLen = commentPrefix.length;
|
557
332
|
const closestBranchMarkers = /* @__PURE__ */ new Map();
|
333
|
+
const visitNodes = new Set(visits);
|
334
|
+
let lastEndNode;
|
558
335
|
data2.v = [];
|
559
|
-
const branchEnd = (branchId, visit,
|
336
|
+
const branchEnd = (branchId, visit, reference) => {
|
560
337
|
const branch = scopeLookup[branchId] ||= {};
|
561
|
-
let endNode =
|
562
|
-
while ((endNode = endNode.previousSibling)
|
563
|
-
|
338
|
+
let endNode = reference;
|
339
|
+
while (visitNodes.has(endNode = endNode.previousSibling)) ;
|
340
|
+
if (endNode === lastEndNode) {
|
341
|
+
endNode = reference.parentNode.insertBefore(new Text(), reference);
|
342
|
+
}
|
343
|
+
branch.___endNode = lastEndNode = endNode;
|
564
344
|
branch.___startNode ||= endNode;
|
565
345
|
for (const [markerScopeId, markerNode] of closestBranchMarkers) {
|
566
|
-
if (branch.___startNode.compareDocumentPosition(markerNode) & 4 &&
|
346
|
+
if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
|
567
347
|
parentBranchIds.set(markerScopeId, branchId);
|
568
348
|
closestBranchMarkers.delete(markerScopeId);
|
569
349
|
}
|
@@ -1009,7 +789,6 @@ function toValueProp(it) {
|
|
1009
789
|
}
|
1010
790
|
|
1011
791
|
// src/dom/parse-html.ts
|
1012
|
-
var fallback = /* @__PURE__ */ new Text();
|
1013
792
|
var parser = /* @__PURE__ */ document.createElement("template");
|
1014
793
|
function parseHTML(html2) {
|
1015
794
|
parser.innerHTML = html2;
|
@@ -1028,7 +807,7 @@ function parseHTMLOrSingleNode(html2) {
|
|
1028
807
|
fragment.appendChild(content);
|
1029
808
|
return fragment;
|
1030
809
|
}
|
1031
|
-
return
|
810
|
+
return new Text();
|
1032
811
|
}
|
1033
812
|
|
1034
813
|
// src/dom/dom.ts
|
@@ -1202,21 +981,17 @@ function attrsEvents(scope, nodeAccessor) {
|
|
1202
981
|
on(el, name, events[name]);
|
1203
982
|
}
|
1204
983
|
}
|
1205
|
-
function html(scope, value2,
|
1206
|
-
const firstChild = scope[
|
1207
|
-
const lastChild = scope[
|
1208
|
-
const
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
scope[
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
const next = current.nextSibling;
|
1217
|
-
current.remove();
|
1218
|
-
current = next;
|
1219
|
-
}
|
984
|
+
function html(scope, value2, accessor) {
|
985
|
+
const firstChild = scope[accessor];
|
986
|
+
const lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild;
|
987
|
+
const newContent = parseHTML(
|
988
|
+
value2 || value2 === 0 ? value2 + "" : "<!>"
|
989
|
+
// TODO: is the comment needed
|
990
|
+
);
|
991
|
+
scope[accessor] = newContent.firstChild;
|
992
|
+
scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild;
|
993
|
+
firstChild.parentNode.insertBefore(newContent, firstChild);
|
994
|
+
removeChildNodes(firstChild, lastChild);
|
1220
995
|
}
|
1221
996
|
function props(scope, nodeIndex, index) {
|
1222
997
|
const nextProps = scope[index];
|
@@ -1256,6 +1031,234 @@ function lifecycle(scope, index, thisObj) {
|
|
1256
1031
|
).onabort = () => thisObj.onDestroy?.();
|
1257
1032
|
}
|
1258
1033
|
}
|
1034
|
+
function removeChildNodes(startNode, endNode) {
|
1035
|
+
const stop = endNode.nextSibling;
|
1036
|
+
let current = startNode;
|
1037
|
+
while (current !== stop) {
|
1038
|
+
const next = current.nextSibling;
|
1039
|
+
current.remove();
|
1040
|
+
current = next;
|
1041
|
+
}
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
// src/dom/scope.ts
|
1045
|
+
var pendingScopes = [];
|
1046
|
+
var debugID = 0;
|
1047
|
+
function createScope($global) {
|
1048
|
+
const scope = {
|
1049
|
+
___pending: 1,
|
1050
|
+
$global
|
1051
|
+
};
|
1052
|
+
if (true) {
|
1053
|
+
scope.___debugId = "client-" + debugID++;
|
1054
|
+
}
|
1055
|
+
pendingScopes.push(scope);
|
1056
|
+
return scope;
|
1057
|
+
}
|
1058
|
+
function finishPendingScopes() {
|
1059
|
+
for (const scope of pendingScopes) {
|
1060
|
+
scope.___pending = 0;
|
1061
|
+
}
|
1062
|
+
pendingScopes = [];
|
1063
|
+
}
|
1064
|
+
var emptyBranch = createScope({});
|
1065
|
+
function getEmptyBranch(marker) {
|
1066
|
+
emptyBranch.___startNode = emptyBranch.___endNode = marker;
|
1067
|
+
return emptyBranch;
|
1068
|
+
}
|
1069
|
+
function destroyBranch(branch) {
|
1070
|
+
branch.___parentBranch?.___branchScopes?.delete(branch);
|
1071
|
+
destroyNestedBranches(branch);
|
1072
|
+
}
|
1073
|
+
function destroyNestedBranches(branch) {
|
1074
|
+
branch.___destroyed = 1;
|
1075
|
+
branch.___branchScopes?.forEach(destroyNestedBranches);
|
1076
|
+
branch.___abortScopes?.forEach((scope) => {
|
1077
|
+
for (const id in scope.___abortControllers) {
|
1078
|
+
scope.___abortControllers[id]?.abort();
|
1079
|
+
}
|
1080
|
+
});
|
1081
|
+
}
|
1082
|
+
function removeAndDestroyBranch(branch) {
|
1083
|
+
destroyBranch(branch);
|
1084
|
+
removeChildNodes(branch.___startNode, branch.___endNode);
|
1085
|
+
}
|
1086
|
+
function insertBranchBefore(branch, parentNode, nextSibling) {
|
1087
|
+
let current = branch.___startNode;
|
1088
|
+
const stop = branch.___endNode.nextSibling;
|
1089
|
+
while (current !== stop) {
|
1090
|
+
const next = current.nextSibling;
|
1091
|
+
parentNode.insertBefore(current, nextSibling);
|
1092
|
+
current = next;
|
1093
|
+
}
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
// src/dom/reconcile.ts
|
1097
|
+
var WRONG_POS = 2147483647;
|
1098
|
+
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
1099
|
+
let oldStart = 0;
|
1100
|
+
let newStart = 0;
|
1101
|
+
let oldEnd = oldBranches.length - 1;
|
1102
|
+
let newEnd = newBranches.length - 1;
|
1103
|
+
let oldStartBranch = oldBranches[oldStart];
|
1104
|
+
let newStartBranch = newBranches[newStart];
|
1105
|
+
let oldEndBranch = oldBranches[oldEnd];
|
1106
|
+
let newEndBranch = newBranches[newEnd];
|
1107
|
+
let i;
|
1108
|
+
let j;
|
1109
|
+
let k;
|
1110
|
+
let nextSibling;
|
1111
|
+
let oldBranch;
|
1112
|
+
let newBranch;
|
1113
|
+
outer: {
|
1114
|
+
while (oldStartBranch === newStartBranch) {
|
1115
|
+
++oldStart;
|
1116
|
+
++newStart;
|
1117
|
+
if (oldStart > oldEnd || newStart > newEnd) {
|
1118
|
+
break outer;
|
1119
|
+
}
|
1120
|
+
oldStartBranch = oldBranches[oldStart];
|
1121
|
+
newStartBranch = newBranches[newStart];
|
1122
|
+
}
|
1123
|
+
while (oldEndBranch === newEndBranch) {
|
1124
|
+
--oldEnd;
|
1125
|
+
--newEnd;
|
1126
|
+
if (oldStart > oldEnd || newStart > newEnd) {
|
1127
|
+
break outer;
|
1128
|
+
}
|
1129
|
+
oldEndBranch = oldBranches[oldEnd];
|
1130
|
+
newEndBranch = newBranches[newEnd];
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
if (oldStart > oldEnd) {
|
1134
|
+
if (newStart <= newEnd) {
|
1135
|
+
k = newEnd + 1;
|
1136
|
+
nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
|
1137
|
+
do {
|
1138
|
+
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
1139
|
+
} while (newStart <= newEnd);
|
1140
|
+
}
|
1141
|
+
} else if (newStart > newEnd) {
|
1142
|
+
do {
|
1143
|
+
removeAndDestroyBranch(oldBranches[oldStart++]);
|
1144
|
+
} while (oldStart <= oldEnd);
|
1145
|
+
} else {
|
1146
|
+
const oldLength = oldEnd - oldStart + 1;
|
1147
|
+
const newLength = newEnd - newStart + 1;
|
1148
|
+
const aNullable = oldBranches;
|
1149
|
+
const sources = new Array(newLength);
|
1150
|
+
for (i = 0; i < newLength; ++i) {
|
1151
|
+
sources[i] = -1;
|
1152
|
+
}
|
1153
|
+
let pos = 0;
|
1154
|
+
let synced = 0;
|
1155
|
+
const keyIndex = /* @__PURE__ */ new Map();
|
1156
|
+
for (j = newStart; j <= newEnd; ++j) {
|
1157
|
+
keyIndex.set(newBranches[j], j);
|
1158
|
+
}
|
1159
|
+
for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
|
1160
|
+
oldBranch = oldBranches[i];
|
1161
|
+
j = keyIndex.get(oldBranch);
|
1162
|
+
if (j !== void 0) {
|
1163
|
+
pos = pos > j ? WRONG_POS : j;
|
1164
|
+
++synced;
|
1165
|
+
newBranch = newBranches[j];
|
1166
|
+
sources[j - newStart] = i;
|
1167
|
+
aNullable[i] = null;
|
1168
|
+
}
|
1169
|
+
}
|
1170
|
+
if (oldLength === oldBranches.length && synced === 0) {
|
1171
|
+
for (; newStart < newLength; ++newStart) {
|
1172
|
+
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
1173
|
+
}
|
1174
|
+
for (; oldStart < oldLength; ++oldStart) {
|
1175
|
+
removeAndDestroyBranch(oldBranches[oldStart]);
|
1176
|
+
}
|
1177
|
+
} else {
|
1178
|
+
i = oldLength - synced;
|
1179
|
+
while (i > 0) {
|
1180
|
+
oldBranch = aNullable[oldStart++];
|
1181
|
+
if (oldBranch !== null) {
|
1182
|
+
removeAndDestroyBranch(oldBranch);
|
1183
|
+
i--;
|
1184
|
+
}
|
1185
|
+
}
|
1186
|
+
if (pos === WRONG_POS) {
|
1187
|
+
const seq = longestIncreasingSubsequence(sources);
|
1188
|
+
j = seq.length - 1;
|
1189
|
+
k = newBranches.length;
|
1190
|
+
for (i = newLength - 1; i >= 0; --i) {
|
1191
|
+
if (sources[i] === -1) {
|
1192
|
+
pos = i + newStart;
|
1193
|
+
newBranch = newBranches[pos++];
|
1194
|
+
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
1195
|
+
insertBranchBefore(newBranch, parent, nextSibling);
|
1196
|
+
} else {
|
1197
|
+
if (j < 0 || i !== seq[j]) {
|
1198
|
+
pos = i + newStart;
|
1199
|
+
newBranch = newBranches[pos++];
|
1200
|
+
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
1201
|
+
insertBranchBefore(newBranch, parent, nextSibling);
|
1202
|
+
} else {
|
1203
|
+
--j;
|
1204
|
+
}
|
1205
|
+
}
|
1206
|
+
}
|
1207
|
+
} else if (synced !== newLength) {
|
1208
|
+
k = newBranches.length;
|
1209
|
+
for (i = newLength - 1; i >= 0; --i) {
|
1210
|
+
if (sources[i] === -1) {
|
1211
|
+
pos = i + newStart;
|
1212
|
+
newBranch = newBranches[pos++];
|
1213
|
+
nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
|
1214
|
+
insertBranchBefore(newBranch, parent, nextSibling);
|
1215
|
+
}
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
}
|
1219
|
+
}
|
1220
|
+
}
|
1221
|
+
function longestIncreasingSubsequence(a) {
|
1222
|
+
const p = a.slice();
|
1223
|
+
const result = [];
|
1224
|
+
result.push(0);
|
1225
|
+
let u;
|
1226
|
+
let v;
|
1227
|
+
for (let i = 0, il = a.length; i < il; ++i) {
|
1228
|
+
if (a[i] === -1) {
|
1229
|
+
continue;
|
1230
|
+
}
|
1231
|
+
const j = result[result.length - 1];
|
1232
|
+
if (a[j] < a[i]) {
|
1233
|
+
p[i] = j;
|
1234
|
+
result.push(i);
|
1235
|
+
continue;
|
1236
|
+
}
|
1237
|
+
u = 0;
|
1238
|
+
v = result.length - 1;
|
1239
|
+
while (u < v) {
|
1240
|
+
const c = (u + v) / 2 | 0;
|
1241
|
+
if (a[result[c]] < a[i]) {
|
1242
|
+
u = c + 1;
|
1243
|
+
} else {
|
1244
|
+
v = c;
|
1245
|
+
}
|
1246
|
+
}
|
1247
|
+
if (a[i] < a[result[u]]) {
|
1248
|
+
if (u > 0) {
|
1249
|
+
p[i] = result[u - 1];
|
1250
|
+
}
|
1251
|
+
result[u] = i;
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
u = result.length;
|
1255
|
+
v = result[u - 1];
|
1256
|
+
while (u-- > 0) {
|
1257
|
+
result[u] = v;
|
1258
|
+
v = p[v];
|
1259
|
+
}
|
1260
|
+
return result;
|
1261
|
+
}
|
1259
1262
|
|
1260
1263
|
// src/dom/walker.ts
|
1261
1264
|
var walker = /* @__PURE__ */ document.createTreeWalker(document);
|
@@ -1264,9 +1267,9 @@ function trimWalkString(walkString) {
|
|
1264
1267
|
while (walkString.charCodeAt(--end) > 47 /* BeginChild */) ;
|
1265
1268
|
return walkString.slice(0, end + 1);
|
1266
1269
|
}
|
1267
|
-
function walk(startNode, walkCodes,
|
1270
|
+
function walk(startNode, walkCodes, branch) {
|
1268
1271
|
walker.currentNode = startNode;
|
1269
|
-
walkInternal(walkCodes,
|
1272
|
+
walkInternal(walkCodes, branch, 0);
|
1270
1273
|
walker.currentNode = document;
|
1271
1274
|
}
|
1272
1275
|
function walkInternal(walkCodes, scope, currentWalkIndex) {
|
@@ -1297,7 +1300,6 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
|
|
1297
1300
|
}
|
1298
1301
|
} else if (value2 === 47 /* BeginChild */) {
|
1299
1302
|
const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
|
1300
|
-
childScope.___startNode = walker.currentNode;
|
1301
1303
|
childScope.___closestBranch = scope.___closestBranch;
|
1302
1304
|
currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
|
1303
1305
|
} else if (value2 === 38 /* EndChild */) {
|
@@ -1476,8 +1478,8 @@ function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
|
|
1476
1478
|
const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : getEmptyBranch(scope[nodeAccessor]);
|
1477
1479
|
insertBranchBefore(
|
1478
1480
|
newBranch,
|
1479
|
-
prevBranch.
|
1480
|
-
prevBranch.
|
1481
|
+
prevBranch.___endNode.parentNode,
|
1482
|
+
prevBranch.___endNode.nextSibling
|
1481
1483
|
);
|
1482
1484
|
removeAndDestroyBranch(prevBranch);
|
1483
1485
|
scope[nodeAccessor + "!" /* ConditionalScope */] = newRenderer && newBranch;
|
@@ -1943,13 +1945,13 @@ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
|
|
1943
1945
|
var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
|
1944
1946
|
|
1945
1947
|
// src/dom/compat.ts
|
1946
|
-
var
|
1948
|
+
var classIdToBranch = /* @__PURE__ */ new Map();
|
1947
1949
|
var compat = {
|
1948
1950
|
patchConditionals,
|
1949
1951
|
queueEffect,
|
1950
1952
|
init() {
|
1951
|
-
register(SET_SCOPE_REGISTER_ID, (
|
1952
|
-
|
1953
|
+
register(SET_SCOPE_REGISTER_ID, (branch) => {
|
1954
|
+
classIdToBranch.set(branch.m5c, branch);
|
1953
1955
|
});
|
1954
1956
|
},
|
1955
1957
|
registerRenderer(fn) {
|
@@ -1961,12 +1963,12 @@ var compat = {
|
|
1961
1963
|
isRenderer(renderer) {
|
1962
1964
|
return renderer.___clone !== void 0;
|
1963
1965
|
},
|
1964
|
-
getStartNode(
|
1965
|
-
return
|
1966
|
+
getStartNode(branch) {
|
1967
|
+
return branch.___startNode;
|
1966
1968
|
},
|
1967
|
-
setScopeNodes(
|
1968
|
-
|
1969
|
-
|
1969
|
+
setScopeNodes(branch, startNode, endNode) {
|
1970
|
+
branch.___startNode = startNode;
|
1971
|
+
branch.___endNode = endNode;
|
1970
1972
|
},
|
1971
1973
|
runComponentEffects() {
|
1972
1974
|
runEffects(this.effects);
|
@@ -1994,12 +1996,12 @@ var compat = {
|
|
1994
1996
|
return renderer;
|
1995
1997
|
},
|
1996
1998
|
render(out, component, renderer, args) {
|
1997
|
-
let
|
1998
|
-
if (!
|
1999
|
-
|
2000
|
-
if (
|
2001
|
-
component.scope =
|
2002
|
-
|
1999
|
+
let branch = component.scope;
|
2000
|
+
if (!branch) {
|
2001
|
+
branch = classIdToBranch.get(component.id);
|
2002
|
+
if (branch) {
|
2003
|
+
component.scope = branch;
|
2004
|
+
classIdToBranch.delete(component.id);
|
2003
2005
|
}
|
2004
2006
|
}
|
2005
2007
|
const applyArgs = renderer.___args || noop;
|
@@ -2012,18 +2014,18 @@ var compat = {
|
|
2012
2014
|
}
|
2013
2015
|
}
|
2014
2016
|
component.effects = prepareEffects(() => {
|
2015
|
-
if (!
|
2016
|
-
|
2017
|
-
|
2018
|
-
initBranch(renderer,
|
2017
|
+
if (!branch) {
|
2018
|
+
branch = component.scope = createScope(out.global);
|
2019
|
+
branch._ = renderer.___owner;
|
2020
|
+
initBranch(renderer, branch);
|
2019
2021
|
} else {
|
2020
|
-
applyArgs(
|
2022
|
+
applyArgs(branch, MARK);
|
2021
2023
|
existing = true;
|
2022
2024
|
}
|
2023
|
-
applyArgs(
|
2025
|
+
applyArgs(branch, args);
|
2024
2026
|
});
|
2025
2027
|
if (!existing) {
|
2026
|
-
return
|
2028
|
+
return branch.___startNode === branch.___endNode ? branch.___startNode : branch.___startNode.parentNode;
|
2027
2029
|
}
|
2028
2030
|
}
|
2029
2031
|
};
|