marko 6.0.151 → 6.0.153
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/debug/dom.js +126 -192
- package/dist/debug/dom.mjs +126 -192
- package/dist/dom.js +55 -89
- package/dist/dom.mjs +55 -89
- package/package.json +2 -2
- package/dist/dom/reconcile.d.ts +0 -2
package/dist/debug/dom.js
CHANGED
|
@@ -417,11 +417,12 @@ function destroyBranch(branch) {
|
|
|
417
417
|
function destroyNestedBranches(branch) {
|
|
418
418
|
branch["#Destroyed" /* Destroyed */] = 1;
|
|
419
419
|
branch["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedBranches);
|
|
420
|
-
branch["#AbortScopes" /* AbortScopes */]?.forEach(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
420
|
+
branch["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
|
|
421
|
+
}
|
|
422
|
+
function resetControllers(scope) {
|
|
423
|
+
for (const id in scope["#AbortControllers" /* AbortControllers */]) {
|
|
424
|
+
$signalReset(scope, id);
|
|
425
|
+
}
|
|
425
426
|
}
|
|
426
427
|
function removeAndDestroyBranch(branch) {
|
|
427
428
|
destroyBranch(branch);
|
|
@@ -1707,172 +1708,6 @@ function toInsertNode(startNode, endNode) {
|
|
|
1707
1708
|
return parent;
|
|
1708
1709
|
}
|
|
1709
1710
|
|
|
1710
|
-
// src/dom/reconcile.ts
|
|
1711
|
-
var WRONG_POS = 2147483647;
|
|
1712
|
-
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
|
1713
|
-
let oldStart = 0;
|
|
1714
|
-
let newStart = 0;
|
|
1715
|
-
let oldEnd = oldBranches.length - 1;
|
|
1716
|
-
let newEnd = newBranches.length - 1;
|
|
1717
|
-
let oldStartBranch = oldBranches[oldStart];
|
|
1718
|
-
let newStartBranch = newBranches[newStart];
|
|
1719
|
-
let oldEndBranch = oldBranches[oldEnd];
|
|
1720
|
-
let newEndBranch = newBranches[newEnd];
|
|
1721
|
-
let i;
|
|
1722
|
-
let j;
|
|
1723
|
-
let k;
|
|
1724
|
-
let nextSibling;
|
|
1725
|
-
let oldBranch;
|
|
1726
|
-
let newBranch;
|
|
1727
|
-
outer: {
|
|
1728
|
-
while (oldStartBranch === newStartBranch) {
|
|
1729
|
-
++oldStart;
|
|
1730
|
-
++newStart;
|
|
1731
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
|
1732
|
-
break outer;
|
|
1733
|
-
}
|
|
1734
|
-
oldStartBranch = oldBranches[oldStart];
|
|
1735
|
-
newStartBranch = newBranches[newStart];
|
|
1736
|
-
}
|
|
1737
|
-
while (oldEndBranch === newEndBranch) {
|
|
1738
|
-
--oldEnd;
|
|
1739
|
-
--newEnd;
|
|
1740
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
|
1741
|
-
break outer;
|
|
1742
|
-
}
|
|
1743
|
-
oldEndBranch = oldBranches[oldEnd];
|
|
1744
|
-
newEndBranch = newBranches[newEnd];
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
if (oldStart > oldEnd) {
|
|
1748
|
-
if (newStart <= newEnd) {
|
|
1749
|
-
k = newEnd + 1;
|
|
1750
|
-
nextSibling = k < newBranches.length ? newBranches[k]["#StartNode" /* StartNode */] : afterReference;
|
|
1751
|
-
do {
|
|
1752
|
-
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
|
1753
|
-
} while (newStart <= newEnd);
|
|
1754
|
-
}
|
|
1755
|
-
} else if (newStart > newEnd) {
|
|
1756
|
-
do {
|
|
1757
|
-
removeAndDestroyBranch(oldBranches[oldStart++]);
|
|
1758
|
-
} while (oldStart <= oldEnd);
|
|
1759
|
-
} else {
|
|
1760
|
-
const oldLength = oldEnd - oldStart + 1;
|
|
1761
|
-
const newLength = newEnd - newStart + 1;
|
|
1762
|
-
const aNullable = oldBranches;
|
|
1763
|
-
const sources = new Array(newLength);
|
|
1764
|
-
for (i = 0; i < newLength; ++i) {
|
|
1765
|
-
sources[i] = -1;
|
|
1766
|
-
}
|
|
1767
|
-
let pos = 0;
|
|
1768
|
-
let synced = 0;
|
|
1769
|
-
const keyIndex = /* @__PURE__ */ new Map();
|
|
1770
|
-
for (j = newStart; j <= newEnd; ++j) {
|
|
1771
|
-
keyIndex.set(newBranches[j], j);
|
|
1772
|
-
}
|
|
1773
|
-
for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
|
|
1774
|
-
oldBranch = oldBranches[i];
|
|
1775
|
-
j = keyIndex.get(oldBranch);
|
|
1776
|
-
if (j !== void 0) {
|
|
1777
|
-
pos = pos > j ? WRONG_POS : j;
|
|
1778
|
-
++synced;
|
|
1779
|
-
newBranch = newBranches[j];
|
|
1780
|
-
sources[j - newStart] = i;
|
|
1781
|
-
aNullable[i] = null;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
if (oldLength === oldBranches.length && synced === 0) {
|
|
1785
|
-
for (; newStart < newLength; ++newStart) {
|
|
1786
|
-
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
|
1787
|
-
}
|
|
1788
|
-
for (; oldStart < oldLength; ++oldStart) {
|
|
1789
|
-
removeAndDestroyBranch(oldBranches[oldStart]);
|
|
1790
|
-
}
|
|
1791
|
-
} else {
|
|
1792
|
-
i = oldLength - synced;
|
|
1793
|
-
while (i > 0) {
|
|
1794
|
-
oldBranch = aNullable[oldStart++];
|
|
1795
|
-
if (oldBranch !== null) {
|
|
1796
|
-
removeAndDestroyBranch(oldBranch);
|
|
1797
|
-
i--;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
if (pos === WRONG_POS) {
|
|
1801
|
-
const seq = longestIncreasingSubsequence(sources);
|
|
1802
|
-
j = seq.length - 1;
|
|
1803
|
-
k = newBranches.length;
|
|
1804
|
-
for (i = newLength - 1; i >= 0; --i) {
|
|
1805
|
-
if (sources[i] === -1) {
|
|
1806
|
-
pos = i + newStart;
|
|
1807
|
-
newBranch = newBranches[pos++];
|
|
1808
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1809
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1810
|
-
} else {
|
|
1811
|
-
if (j < 0 || i !== seq[j]) {
|
|
1812
|
-
pos = i + newStart;
|
|
1813
|
-
newBranch = newBranches[pos++];
|
|
1814
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1815
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1816
|
-
} else {
|
|
1817
|
-
--j;
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
} else if (synced !== newLength) {
|
|
1822
|
-
k = newBranches.length;
|
|
1823
|
-
for (i = newLength - 1; i >= 0; --i) {
|
|
1824
|
-
if (sources[i] === -1) {
|
|
1825
|
-
pos = i + newStart;
|
|
1826
|
-
newBranch = newBranches[pos++];
|
|
1827
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1828
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
function longestIncreasingSubsequence(a) {
|
|
1836
|
-
const p = a.slice();
|
|
1837
|
-
const result = [0];
|
|
1838
|
-
let u;
|
|
1839
|
-
let v;
|
|
1840
|
-
for (let i = 0, il = a.length; i < il; ++i) {
|
|
1841
|
-
if (a[i] === -1) {
|
|
1842
|
-
continue;
|
|
1843
|
-
}
|
|
1844
|
-
const j = result[result.length - 1];
|
|
1845
|
-
if (a[j] < a[i]) {
|
|
1846
|
-
p[i] = j;
|
|
1847
|
-
result.push(i);
|
|
1848
|
-
continue;
|
|
1849
|
-
}
|
|
1850
|
-
u = 0;
|
|
1851
|
-
v = result.length - 1;
|
|
1852
|
-
while (u < v) {
|
|
1853
|
-
const c = (u + v) / 2 | 0;
|
|
1854
|
-
if (a[result[c]] < a[i]) {
|
|
1855
|
-
u = c + 1;
|
|
1856
|
-
} else {
|
|
1857
|
-
v = c;
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
if (a[i] < a[result[u]]) {
|
|
1861
|
-
if (u > 0) {
|
|
1862
|
-
p[i] = result[u - 1];
|
|
1863
|
-
}
|
|
1864
|
-
result[u] = i;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
u = result.length;
|
|
1868
|
-
v = result[u - 1];
|
|
1869
|
-
while (u-- > 0) {
|
|
1870
|
-
result[u] = v;
|
|
1871
|
-
v = p[v];
|
|
1872
|
-
}
|
|
1873
|
-
return result;
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
1711
|
// src/dom/control-flow.ts
|
|
1877
1712
|
function _await_promise(nodeAccessor, params) {
|
|
1878
1713
|
if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
|
|
@@ -2253,52 +2088,151 @@ function loop(forEach) {
|
|
|
2253
2088
|
return (nodeAccessor, template, walks, setup, params) => {
|
|
2254
2089
|
if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
|
|
2255
2090
|
const scopesAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
|
|
2256
|
-
const scopesByKeyAccessor = "BranchScopes:" /* BranchScopes */ + scopesAccessor;
|
|
2257
2091
|
const renderer = _content("", template, walks, setup)();
|
|
2258
2092
|
enableBranches();
|
|
2259
2093
|
return (scope, value) => {
|
|
2260
2094
|
const referenceNode = scope[nodeAccessor];
|
|
2261
2095
|
const oldScopes = toArray(scope[scopesAccessor]);
|
|
2262
|
-
const oldScopesByKey = scope[scopesByKeyAccessor] || oldScopes.reduce(
|
|
2263
|
-
(map, scope2, i) => map.set(scope2["#LoopKey" /* LoopKey */] ?? i, scope2),
|
|
2264
|
-
/* @__PURE__ */ new Map()
|
|
2265
|
-
);
|
|
2266
2096
|
const newScopes = scope[scopesAccessor] = [];
|
|
2267
|
-
const
|
|
2097
|
+
const oldLen = oldScopes.length;
|
|
2268
2098
|
const parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.["#StartNode" /* StartNode */].parentNode : referenceNode;
|
|
2099
|
+
let oldScopesByKey;
|
|
2100
|
+
let hasPotentialMoves;
|
|
2101
|
+
if (true) {
|
|
2102
|
+
var seenKeys = /* @__PURE__ */ new Set();
|
|
2103
|
+
}
|
|
2269
2104
|
forEach(value, (key, args) => {
|
|
2270
2105
|
if (true) {
|
|
2271
|
-
if (
|
|
2106
|
+
if (seenKeys.has(key)) {
|
|
2272
2107
|
console.error(
|
|
2273
2108
|
`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`,
|
|
2274
2109
|
key
|
|
2275
2110
|
);
|
|
2111
|
+
} else {
|
|
2112
|
+
seenKeys.add(key);
|
|
2276
2113
|
}
|
|
2277
2114
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2115
|
+
let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce(
|
|
2116
|
+
(map, scope2, i) => map.set(scope2["#LoopKey" /* LoopKey */] ?? i, scope2),
|
|
2117
|
+
/* @__PURE__ */ new Map()
|
|
2118
|
+
)).get(key);
|
|
2119
|
+
if (branch) {
|
|
2120
|
+
hasPotentialMoves = oldScopesByKey.delete(key);
|
|
2121
|
+
} else {
|
|
2122
|
+
branch = createAndSetupBranch(
|
|
2123
|
+
scope["$global" /* Global */],
|
|
2124
|
+
renderer,
|
|
2125
|
+
scope,
|
|
2126
|
+
parentNode
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2284
2129
|
branch["#LoopKey" /* LoopKey */] = key;
|
|
2285
|
-
params?.(branch, args);
|
|
2286
|
-
newScopesByKey.set(key, branch);
|
|
2287
2130
|
newScopes.push(branch);
|
|
2131
|
+
params?.(branch, args);
|
|
2288
2132
|
});
|
|
2133
|
+
const newLen = newScopes.length;
|
|
2134
|
+
const hasSiblings = referenceNode !== parentNode;
|
|
2289
2135
|
let afterReference = null;
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2136
|
+
let oldEnd = oldLen - 1;
|
|
2137
|
+
let newEnd = newLen - 1;
|
|
2138
|
+
let start = 0;
|
|
2139
|
+
if (hasSiblings) {
|
|
2140
|
+
if (oldLen) {
|
|
2141
|
+
afterReference = oldScopes[oldEnd]["#EndNode" /* EndNode */].nextSibling;
|
|
2142
|
+
if (!newLen) {
|
|
2294
2143
|
parentNode.insertBefore(referenceNode, afterReference);
|
|
2295
2144
|
}
|
|
2296
|
-
} else if (
|
|
2145
|
+
} else if (newLen) {
|
|
2297
2146
|
afterReference = referenceNode.nextSibling;
|
|
2298
2147
|
referenceNode.remove();
|
|
2299
2148
|
}
|
|
2300
2149
|
}
|
|
2301
|
-
|
|
2150
|
+
if (!hasPotentialMoves) {
|
|
2151
|
+
if (oldLen) {
|
|
2152
|
+
oldScopes.forEach(
|
|
2153
|
+
hasSiblings ? removeAndDestroyBranch : destroyBranch
|
|
2154
|
+
);
|
|
2155
|
+
if (!hasSiblings) {
|
|
2156
|
+
parentNode.textContent = "";
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
for (const newScope of newScopes) {
|
|
2160
|
+
insertBranchBefore(newScope, parentNode, afterReference);
|
|
2161
|
+
}
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
for (const branch of oldScopesByKey.values()) {
|
|
2165
|
+
removeAndDestroyBranch(branch);
|
|
2166
|
+
}
|
|
2167
|
+
while (start < oldLen && start < newLen && oldScopes[start] === newScopes[start]) {
|
|
2168
|
+
start++;
|
|
2169
|
+
}
|
|
2170
|
+
while (oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]) {
|
|
2171
|
+
oldEnd--;
|
|
2172
|
+
newEnd--;
|
|
2173
|
+
}
|
|
2174
|
+
if (oldEnd + 1 < oldLen) {
|
|
2175
|
+
afterReference = oldScopes[oldEnd + 1]["#StartNode" /* StartNode */];
|
|
2176
|
+
}
|
|
2177
|
+
if (start > oldEnd) {
|
|
2178
|
+
if (start <= newEnd) {
|
|
2179
|
+
for (let i = start; i <= newEnd; i++) {
|
|
2180
|
+
insertBranchBefore(newScopes[i], parentNode, afterReference);
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
return;
|
|
2184
|
+
} else if (start > newEnd) {
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
const diffLen = newEnd - start + 1;
|
|
2188
|
+
const oldPos = /* @__PURE__ */ new Map();
|
|
2189
|
+
const sources = new Array(diffLen);
|
|
2190
|
+
const pred = new Array(diffLen);
|
|
2191
|
+
const tails = [];
|
|
2192
|
+
let tail = -1;
|
|
2193
|
+
let lo;
|
|
2194
|
+
let hi;
|
|
2195
|
+
let mid;
|
|
2196
|
+
for (let i = start; i <= oldEnd; i++) {
|
|
2197
|
+
oldPos.set(oldScopes[i], i);
|
|
2198
|
+
}
|
|
2199
|
+
for (let i = diffLen; i--; ) {
|
|
2200
|
+
sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
|
|
2201
|
+
}
|
|
2202
|
+
for (let i = 0; i < diffLen; i++) {
|
|
2203
|
+
if (~sources[i]) {
|
|
2204
|
+
if (tail < 0 || sources[tails[tail]] < sources[i]) {
|
|
2205
|
+
if (~tail) pred[i] = tails[tail];
|
|
2206
|
+
tails[++tail] = i;
|
|
2207
|
+
} else {
|
|
2208
|
+
lo = 0;
|
|
2209
|
+
hi = tail;
|
|
2210
|
+
while (lo < hi) {
|
|
2211
|
+
mid = (lo + hi) / 2 | 0;
|
|
2212
|
+
if (sources[tails[mid]] < sources[i]) lo = mid + 1;
|
|
2213
|
+
else hi = mid;
|
|
2214
|
+
}
|
|
2215
|
+
if (sources[i] < sources[tails[lo]]) {
|
|
2216
|
+
if (lo > 0) pred[i] = tails[lo - 1];
|
|
2217
|
+
tails[lo] = i;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
hi = tails[tail];
|
|
2223
|
+
lo = tail + 1;
|
|
2224
|
+
while (lo-- > 0) {
|
|
2225
|
+
tails[lo] = hi;
|
|
2226
|
+
hi = pred[hi];
|
|
2227
|
+
}
|
|
2228
|
+
for (let i = diffLen; i--; ) {
|
|
2229
|
+
if (~tail && i === tails[tail]) {
|
|
2230
|
+
tail--;
|
|
2231
|
+
} else {
|
|
2232
|
+
insertBranchBefore(newScopes[start + i], parentNode, afterReference);
|
|
2233
|
+
}
|
|
2234
|
+
afterReference = newScopes[start + i]["#StartNode" /* StartNode */];
|
|
2235
|
+
}
|
|
2302
2236
|
};
|
|
2303
2237
|
};
|
|
2304
2238
|
}
|
package/dist/debug/dom.mjs
CHANGED
|
@@ -303,11 +303,12 @@ function destroyBranch(branch) {
|
|
|
303
303
|
function destroyNestedBranches(branch) {
|
|
304
304
|
branch["#Destroyed" /* Destroyed */] = 1;
|
|
305
305
|
branch["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedBranches);
|
|
306
|
-
branch["#AbortScopes" /* AbortScopes */]?.forEach(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
branch["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
|
|
307
|
+
}
|
|
308
|
+
function resetControllers(scope) {
|
|
309
|
+
for (const id in scope["#AbortControllers" /* AbortControllers */]) {
|
|
310
|
+
$signalReset(scope, id);
|
|
311
|
+
}
|
|
311
312
|
}
|
|
312
313
|
function removeAndDestroyBranch(branch) {
|
|
313
314
|
destroyBranch(branch);
|
|
@@ -1593,172 +1594,6 @@ function toInsertNode(startNode, endNode) {
|
|
|
1593
1594
|
return parent;
|
|
1594
1595
|
}
|
|
1595
1596
|
|
|
1596
|
-
// src/dom/reconcile.ts
|
|
1597
|
-
var WRONG_POS = 2147483647;
|
|
1598
|
-
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
|
1599
|
-
let oldStart = 0;
|
|
1600
|
-
let newStart = 0;
|
|
1601
|
-
let oldEnd = oldBranches.length - 1;
|
|
1602
|
-
let newEnd = newBranches.length - 1;
|
|
1603
|
-
let oldStartBranch = oldBranches[oldStart];
|
|
1604
|
-
let newStartBranch = newBranches[newStart];
|
|
1605
|
-
let oldEndBranch = oldBranches[oldEnd];
|
|
1606
|
-
let newEndBranch = newBranches[newEnd];
|
|
1607
|
-
let i;
|
|
1608
|
-
let j;
|
|
1609
|
-
let k;
|
|
1610
|
-
let nextSibling;
|
|
1611
|
-
let oldBranch;
|
|
1612
|
-
let newBranch;
|
|
1613
|
-
outer: {
|
|
1614
|
-
while (oldStartBranch === newStartBranch) {
|
|
1615
|
-
++oldStart;
|
|
1616
|
-
++newStart;
|
|
1617
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
|
1618
|
-
break outer;
|
|
1619
|
-
}
|
|
1620
|
-
oldStartBranch = oldBranches[oldStart];
|
|
1621
|
-
newStartBranch = newBranches[newStart];
|
|
1622
|
-
}
|
|
1623
|
-
while (oldEndBranch === newEndBranch) {
|
|
1624
|
-
--oldEnd;
|
|
1625
|
-
--newEnd;
|
|
1626
|
-
if (oldStart > oldEnd || newStart > newEnd) {
|
|
1627
|
-
break outer;
|
|
1628
|
-
}
|
|
1629
|
-
oldEndBranch = oldBranches[oldEnd];
|
|
1630
|
-
newEndBranch = newBranches[newEnd];
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
if (oldStart > oldEnd) {
|
|
1634
|
-
if (newStart <= newEnd) {
|
|
1635
|
-
k = newEnd + 1;
|
|
1636
|
-
nextSibling = k < newBranches.length ? newBranches[k]["#StartNode" /* StartNode */] : afterReference;
|
|
1637
|
-
do {
|
|
1638
|
-
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
|
1639
|
-
} while (newStart <= newEnd);
|
|
1640
|
-
}
|
|
1641
|
-
} else if (newStart > newEnd) {
|
|
1642
|
-
do {
|
|
1643
|
-
removeAndDestroyBranch(oldBranches[oldStart++]);
|
|
1644
|
-
} while (oldStart <= oldEnd);
|
|
1645
|
-
} else {
|
|
1646
|
-
const oldLength = oldEnd - oldStart + 1;
|
|
1647
|
-
const newLength = newEnd - newStart + 1;
|
|
1648
|
-
const aNullable = oldBranches;
|
|
1649
|
-
const sources = new Array(newLength);
|
|
1650
|
-
for (i = 0; i < newLength; ++i) {
|
|
1651
|
-
sources[i] = -1;
|
|
1652
|
-
}
|
|
1653
|
-
let pos = 0;
|
|
1654
|
-
let synced = 0;
|
|
1655
|
-
const keyIndex = /* @__PURE__ */ new Map();
|
|
1656
|
-
for (j = newStart; j <= newEnd; ++j) {
|
|
1657
|
-
keyIndex.set(newBranches[j], j);
|
|
1658
|
-
}
|
|
1659
|
-
for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
|
|
1660
|
-
oldBranch = oldBranches[i];
|
|
1661
|
-
j = keyIndex.get(oldBranch);
|
|
1662
|
-
if (j !== void 0) {
|
|
1663
|
-
pos = pos > j ? WRONG_POS : j;
|
|
1664
|
-
++synced;
|
|
1665
|
-
newBranch = newBranches[j];
|
|
1666
|
-
sources[j - newStart] = i;
|
|
1667
|
-
aNullable[i] = null;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
if (oldLength === oldBranches.length && synced === 0) {
|
|
1671
|
-
for (; newStart < newLength; ++newStart) {
|
|
1672
|
-
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
|
1673
|
-
}
|
|
1674
|
-
for (; oldStart < oldLength; ++oldStart) {
|
|
1675
|
-
removeAndDestroyBranch(oldBranches[oldStart]);
|
|
1676
|
-
}
|
|
1677
|
-
} else {
|
|
1678
|
-
i = oldLength - synced;
|
|
1679
|
-
while (i > 0) {
|
|
1680
|
-
oldBranch = aNullable[oldStart++];
|
|
1681
|
-
if (oldBranch !== null) {
|
|
1682
|
-
removeAndDestroyBranch(oldBranch);
|
|
1683
|
-
i--;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
if (pos === WRONG_POS) {
|
|
1687
|
-
const seq = longestIncreasingSubsequence(sources);
|
|
1688
|
-
j = seq.length - 1;
|
|
1689
|
-
k = newBranches.length;
|
|
1690
|
-
for (i = newLength - 1; i >= 0; --i) {
|
|
1691
|
-
if (sources[i] === -1) {
|
|
1692
|
-
pos = i + newStart;
|
|
1693
|
-
newBranch = newBranches[pos++];
|
|
1694
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1695
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1696
|
-
} else {
|
|
1697
|
-
if (j < 0 || i !== seq[j]) {
|
|
1698
|
-
pos = i + newStart;
|
|
1699
|
-
newBranch = newBranches[pos++];
|
|
1700
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1701
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1702
|
-
} else {
|
|
1703
|
-
--j;
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
} else if (synced !== newLength) {
|
|
1708
|
-
k = newBranches.length;
|
|
1709
|
-
for (i = newLength - 1; i >= 0; --i) {
|
|
1710
|
-
if (sources[i] === -1) {
|
|
1711
|
-
pos = i + newStart;
|
|
1712
|
-
newBranch = newBranches[pos++];
|
|
1713
|
-
nextSibling = pos < k ? newBranches[pos]["#StartNode" /* StartNode */] : afterReference;
|
|
1714
|
-
insertBranchBefore(newBranch, parent, nextSibling);
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
function longestIncreasingSubsequence(a) {
|
|
1722
|
-
const p = a.slice();
|
|
1723
|
-
const result = [0];
|
|
1724
|
-
let u;
|
|
1725
|
-
let v;
|
|
1726
|
-
for (let i = 0, il = a.length; i < il; ++i) {
|
|
1727
|
-
if (a[i] === -1) {
|
|
1728
|
-
continue;
|
|
1729
|
-
}
|
|
1730
|
-
const j = result[result.length - 1];
|
|
1731
|
-
if (a[j] < a[i]) {
|
|
1732
|
-
p[i] = j;
|
|
1733
|
-
result.push(i);
|
|
1734
|
-
continue;
|
|
1735
|
-
}
|
|
1736
|
-
u = 0;
|
|
1737
|
-
v = result.length - 1;
|
|
1738
|
-
while (u < v) {
|
|
1739
|
-
const c = (u + v) / 2 | 0;
|
|
1740
|
-
if (a[result[c]] < a[i]) {
|
|
1741
|
-
u = c + 1;
|
|
1742
|
-
} else {
|
|
1743
|
-
v = c;
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
if (a[i] < a[result[u]]) {
|
|
1747
|
-
if (u > 0) {
|
|
1748
|
-
p[i] = result[u - 1];
|
|
1749
|
-
}
|
|
1750
|
-
result[u] = i;
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
u = result.length;
|
|
1754
|
-
v = result[u - 1];
|
|
1755
|
-
while (u-- > 0) {
|
|
1756
|
-
result[u] = v;
|
|
1757
|
-
v = p[v];
|
|
1758
|
-
}
|
|
1759
|
-
return result;
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
1597
|
// src/dom/control-flow.ts
|
|
1763
1598
|
function _await_promise(nodeAccessor, params) {
|
|
1764
1599
|
if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
|
|
@@ -2139,52 +1974,151 @@ function loop(forEach) {
|
|
|
2139
1974
|
return (nodeAccessor, template, walks, setup, params) => {
|
|
2140
1975
|
if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
|
|
2141
1976
|
const scopesAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
|
|
2142
|
-
const scopesByKeyAccessor = "BranchScopes:" /* BranchScopes */ + scopesAccessor;
|
|
2143
1977
|
const renderer = _content("", template, walks, setup)();
|
|
2144
1978
|
enableBranches();
|
|
2145
1979
|
return (scope, value) => {
|
|
2146
1980
|
const referenceNode = scope[nodeAccessor];
|
|
2147
1981
|
const oldScopes = toArray(scope[scopesAccessor]);
|
|
2148
|
-
const oldScopesByKey = scope[scopesByKeyAccessor] || oldScopes.reduce(
|
|
2149
|
-
(map, scope2, i) => map.set(scope2["#LoopKey" /* LoopKey */] ?? i, scope2),
|
|
2150
|
-
/* @__PURE__ */ new Map()
|
|
2151
|
-
);
|
|
2152
1982
|
const newScopes = scope[scopesAccessor] = [];
|
|
2153
|
-
const
|
|
1983
|
+
const oldLen = oldScopes.length;
|
|
2154
1984
|
const parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.["#StartNode" /* StartNode */].parentNode : referenceNode;
|
|
1985
|
+
let oldScopesByKey;
|
|
1986
|
+
let hasPotentialMoves;
|
|
1987
|
+
if (true) {
|
|
1988
|
+
var seenKeys = /* @__PURE__ */ new Set();
|
|
1989
|
+
}
|
|
2155
1990
|
forEach(value, (key, args) => {
|
|
2156
1991
|
if (true) {
|
|
2157
|
-
if (
|
|
1992
|
+
if (seenKeys.has(key)) {
|
|
2158
1993
|
console.error(
|
|
2159
1994
|
`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`,
|
|
2160
1995
|
key
|
|
2161
1996
|
);
|
|
1997
|
+
} else {
|
|
1998
|
+
seenKeys.add(key);
|
|
2162
1999
|
}
|
|
2163
2000
|
}
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2001
|
+
let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce(
|
|
2002
|
+
(map, scope2, i) => map.set(scope2["#LoopKey" /* LoopKey */] ?? i, scope2),
|
|
2003
|
+
/* @__PURE__ */ new Map()
|
|
2004
|
+
)).get(key);
|
|
2005
|
+
if (branch) {
|
|
2006
|
+
hasPotentialMoves = oldScopesByKey.delete(key);
|
|
2007
|
+
} else {
|
|
2008
|
+
branch = createAndSetupBranch(
|
|
2009
|
+
scope["$global" /* Global */],
|
|
2010
|
+
renderer,
|
|
2011
|
+
scope,
|
|
2012
|
+
parentNode
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2170
2015
|
branch["#LoopKey" /* LoopKey */] = key;
|
|
2171
|
-
params?.(branch, args);
|
|
2172
|
-
newScopesByKey.set(key, branch);
|
|
2173
2016
|
newScopes.push(branch);
|
|
2017
|
+
params?.(branch, args);
|
|
2174
2018
|
});
|
|
2019
|
+
const newLen = newScopes.length;
|
|
2020
|
+
const hasSiblings = referenceNode !== parentNode;
|
|
2175
2021
|
let afterReference = null;
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2022
|
+
let oldEnd = oldLen - 1;
|
|
2023
|
+
let newEnd = newLen - 1;
|
|
2024
|
+
let start = 0;
|
|
2025
|
+
if (hasSiblings) {
|
|
2026
|
+
if (oldLen) {
|
|
2027
|
+
afterReference = oldScopes[oldEnd]["#EndNode" /* EndNode */].nextSibling;
|
|
2028
|
+
if (!newLen) {
|
|
2180
2029
|
parentNode.insertBefore(referenceNode, afterReference);
|
|
2181
2030
|
}
|
|
2182
|
-
} else if (
|
|
2031
|
+
} else if (newLen) {
|
|
2183
2032
|
afterReference = referenceNode.nextSibling;
|
|
2184
2033
|
referenceNode.remove();
|
|
2185
2034
|
}
|
|
2186
2035
|
}
|
|
2187
|
-
|
|
2036
|
+
if (!hasPotentialMoves) {
|
|
2037
|
+
if (oldLen) {
|
|
2038
|
+
oldScopes.forEach(
|
|
2039
|
+
hasSiblings ? removeAndDestroyBranch : destroyBranch
|
|
2040
|
+
);
|
|
2041
|
+
if (!hasSiblings) {
|
|
2042
|
+
parentNode.textContent = "";
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
for (const newScope of newScopes) {
|
|
2046
|
+
insertBranchBefore(newScope, parentNode, afterReference);
|
|
2047
|
+
}
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
for (const branch of oldScopesByKey.values()) {
|
|
2051
|
+
removeAndDestroyBranch(branch);
|
|
2052
|
+
}
|
|
2053
|
+
while (start < oldLen && start < newLen && oldScopes[start] === newScopes[start]) {
|
|
2054
|
+
start++;
|
|
2055
|
+
}
|
|
2056
|
+
while (oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]) {
|
|
2057
|
+
oldEnd--;
|
|
2058
|
+
newEnd--;
|
|
2059
|
+
}
|
|
2060
|
+
if (oldEnd + 1 < oldLen) {
|
|
2061
|
+
afterReference = oldScopes[oldEnd + 1]["#StartNode" /* StartNode */];
|
|
2062
|
+
}
|
|
2063
|
+
if (start > oldEnd) {
|
|
2064
|
+
if (start <= newEnd) {
|
|
2065
|
+
for (let i = start; i <= newEnd; i++) {
|
|
2066
|
+
insertBranchBefore(newScopes[i], parentNode, afterReference);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
return;
|
|
2070
|
+
} else if (start > newEnd) {
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
const diffLen = newEnd - start + 1;
|
|
2074
|
+
const oldPos = /* @__PURE__ */ new Map();
|
|
2075
|
+
const sources = new Array(diffLen);
|
|
2076
|
+
const pred = new Array(diffLen);
|
|
2077
|
+
const tails = [];
|
|
2078
|
+
let tail = -1;
|
|
2079
|
+
let lo;
|
|
2080
|
+
let hi;
|
|
2081
|
+
let mid;
|
|
2082
|
+
for (let i = start; i <= oldEnd; i++) {
|
|
2083
|
+
oldPos.set(oldScopes[i], i);
|
|
2084
|
+
}
|
|
2085
|
+
for (let i = diffLen; i--; ) {
|
|
2086
|
+
sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
|
|
2087
|
+
}
|
|
2088
|
+
for (let i = 0; i < diffLen; i++) {
|
|
2089
|
+
if (~sources[i]) {
|
|
2090
|
+
if (tail < 0 || sources[tails[tail]] < sources[i]) {
|
|
2091
|
+
if (~tail) pred[i] = tails[tail];
|
|
2092
|
+
tails[++tail] = i;
|
|
2093
|
+
} else {
|
|
2094
|
+
lo = 0;
|
|
2095
|
+
hi = tail;
|
|
2096
|
+
while (lo < hi) {
|
|
2097
|
+
mid = (lo + hi) / 2 | 0;
|
|
2098
|
+
if (sources[tails[mid]] < sources[i]) lo = mid + 1;
|
|
2099
|
+
else hi = mid;
|
|
2100
|
+
}
|
|
2101
|
+
if (sources[i] < sources[tails[lo]]) {
|
|
2102
|
+
if (lo > 0) pred[i] = tails[lo - 1];
|
|
2103
|
+
tails[lo] = i;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
hi = tails[tail];
|
|
2109
|
+
lo = tail + 1;
|
|
2110
|
+
while (lo-- > 0) {
|
|
2111
|
+
tails[lo] = hi;
|
|
2112
|
+
hi = pred[hi];
|
|
2113
|
+
}
|
|
2114
|
+
for (let i = diffLen; i--; ) {
|
|
2115
|
+
if (~tail && i === tails[tail]) {
|
|
2116
|
+
tail--;
|
|
2117
|
+
} else {
|
|
2118
|
+
insertBranchBefore(newScopes[start + i], parentNode, afterReference);
|
|
2119
|
+
}
|
|
2120
|
+
afterReference = newScopes[start + i]["#StartNode" /* StartNode */];
|
|
2121
|
+
}
|
|
2188
2122
|
};
|
|
2189
2123
|
};
|
|
2190
2124
|
}
|
package/dist/dom.js
CHANGED
|
@@ -278,10 +278,11 @@ function destroyBranch(branch) {
|
|
|
278
278
|
), destroyNestedBranches(branch);
|
|
279
279
|
}
|
|
280
280
|
function destroyNestedBranches(branch) {
|
|
281
|
-
branch.I = 1, branch.D?.forEach(destroyNestedBranches), branch.B?.forEach(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
branch.I = 1, branch.D?.forEach(destroyNestedBranches), branch.B?.forEach(resetControllers);
|
|
282
|
+
}
|
|
283
|
+
function resetControllers(scope) {
|
|
284
|
+
for (let id in scope.A)
|
|
285
|
+
$signalReset(scope, id);
|
|
285
286
|
}
|
|
286
287
|
function removeAndDestroyBranch(branch) {
|
|
287
288
|
destroyBranch(branch), removeChildNodes(
|
|
@@ -1071,81 +1072,6 @@ function toInsertNode(startNode, endNode) {
|
|
|
1071
1072
|
return parent;
|
|
1072
1073
|
}
|
|
1073
1074
|
|
|
1074
|
-
// src/dom/reconcile.ts
|
|
1075
|
-
var WRONG_POS = 2147483647;
|
|
1076
|
-
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
|
1077
|
-
let oldStart = 0, newStart = 0, oldEnd = oldBranches.length - 1, newEnd = newBranches.length - 1, oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart], oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd], i, j, k, nextSibling, oldBranch, newBranch;
|
|
1078
|
-
outer: {
|
|
1079
|
-
for (; oldStartBranch === newStartBranch; ) {
|
|
1080
|
-
if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd)
|
|
1081
|
-
break outer;
|
|
1082
|
-
oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart];
|
|
1083
|
-
}
|
|
1084
|
-
for (; oldEndBranch === newEndBranch; ) {
|
|
1085
|
-
if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd)
|
|
1086
|
-
break outer;
|
|
1087
|
-
oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd];
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
if (oldStart > oldEnd) {
|
|
1091
|
-
if (newStart <= newEnd) {
|
|
1092
|
-
k = newEnd + 1, nextSibling = k < newBranches.length ? newBranches[k].S : afterReference;
|
|
1093
|
-
do
|
|
1094
|
-
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
|
1095
|
-
while (newStart <= newEnd);
|
|
1096
|
-
}
|
|
1097
|
-
} else if (newStart > newEnd)
|
|
1098
|
-
do
|
|
1099
|
-
removeAndDestroyBranch(oldBranches[oldStart++]);
|
|
1100
|
-
while (oldStart <= oldEnd);
|
|
1101
|
-
else {
|
|
1102
|
-
let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldBranches, sources = new Array(newLength);
|
|
1103
|
-
for (i = 0; i < newLength; ++i)
|
|
1104
|
-
sources[i] = -1;
|
|
1105
|
-
let pos = 0, synced = 0, keyIndex = /* @__PURE__ */ new Map();
|
|
1106
|
-
for (j = newStart; j <= newEnd; ++j)
|
|
1107
|
-
keyIndex.set(newBranches[j], j);
|
|
1108
|
-
for (i = oldStart; i <= oldEnd && synced < newLength; ++i)
|
|
1109
|
-
oldBranch = oldBranches[i], j = keyIndex.get(oldBranch), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newBranch = newBranches[j], sources[j - newStart] = i, aNullable[i] = null);
|
|
1110
|
-
if (oldLength === oldBranches.length && synced === 0) {
|
|
1111
|
-
for (; newStart < newLength; ++newStart)
|
|
1112
|
-
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
|
1113
|
-
for (; oldStart < oldLength; ++oldStart)
|
|
1114
|
-
removeAndDestroyBranch(oldBranches[oldStart]);
|
|
1115
|
-
} else {
|
|
1116
|
-
for (i = oldLength - synced; i > 0; )
|
|
1117
|
-
oldBranch = aNullable[oldStart++], oldBranch !== null && (removeAndDestroyBranch(oldBranch), i--);
|
|
1118
|
-
if (pos === WRONG_POS) {
|
|
1119
|
-
let seq = longestIncreasingSubsequence(sources);
|
|
1120
|
-
for (j = seq.length - 1, k = newBranches.length, i = newLength - 1; i >= 0; --i)
|
|
1121
|
-
sources[i] === -1 ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling)) : --j;
|
|
1122
|
-
} else if (synced !== newLength)
|
|
1123
|
-
for (k = newBranches.length, i = newLength - 1; i >= 0; --i)
|
|
1124
|
-
sources[i] === -1 && (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling));
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
function longestIncreasingSubsequence(a) {
|
|
1129
|
-
let p = a.slice(), result = [0], u, v;
|
|
1130
|
-
for (let i = 0, il = a.length; i < il; ++i) {
|
|
1131
|
-
if (a[i] === -1)
|
|
1132
|
-
continue;
|
|
1133
|
-
let j = result[result.length - 1];
|
|
1134
|
-
if (a[j] < a[i]) {
|
|
1135
|
-
p[i] = j, result.push(i);
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
for (u = 0, v = result.length - 1; u < v; ) {
|
|
1139
|
-
let c = (u + v) / 2 | 0;
|
|
1140
|
-
a[result[c]] < a[i] ? u = c + 1 : v = c;
|
|
1141
|
-
}
|
|
1142
|
-
a[i] < a[result[u]] && (u > 0 && (p[i] = result[u - 1]), result[u] = i);
|
|
1143
|
-
}
|
|
1144
|
-
for (u = result.length, v = result[u - 1]; u-- > 0; )
|
|
1145
|
-
result[u] = v, v = p[v];
|
|
1146
|
-
return result;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
1075
|
// src/dom/control-flow.ts
|
|
1150
1076
|
function _await_promise(nodeAccessor, params) {
|
|
1151
1077
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
@@ -1399,23 +1325,63 @@ var _for_of = loop(([all, by = bySecondArg], cb) => {
|
|
|
1399
1325
|
function loop(forEach) {
|
|
1400
1326
|
return (nodeAccessor, template, walks, setup, params) => {
|
|
1401
1327
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
1402
|
-
let scopesAccessor = "A" /* BranchScopes */ + nodeAccessor,
|
|
1328
|
+
let scopesAccessor = "A" /* BranchScopes */ + nodeAccessor, renderer = _content("", template, walks, setup)();
|
|
1403
1329
|
return enableBranches(), (scope, value) => {
|
|
1404
|
-
let referenceNode = scope[nodeAccessor], oldScopes = toArray(scope[scopesAccessor]),
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
), newScopes = scope[scopesAccessor] = [], newScopesByKey = scope[scopesByKeyAccessor] = /* @__PURE__ */ new Map(), parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.S.parentNode : referenceNode;
|
|
1330
|
+
let referenceNode = scope[nodeAccessor], oldScopes = toArray(scope[scopesAccessor]), newScopes = scope[scopesAccessor] = [], oldLen = oldScopes.length, parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.S.parentNode : referenceNode, oldScopesByKey, hasPotentialMoves;
|
|
1331
|
+
if (0)
|
|
1332
|
+
var seenKeys;
|
|
1408
1333
|
forEach(value, (key, args) => {
|
|
1409
|
-
let branch = oldScopesByKey
|
|
1334
|
+
let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce(
|
|
1335
|
+
(map, scope2, i) => map.set(scope2.M ?? i, scope2),
|
|
1336
|
+
/* @__PURE__ */ new Map()
|
|
1337
|
+
)).get(key);
|
|
1338
|
+
branch ? hasPotentialMoves = oldScopesByKey.delete(key) : branch = createAndSetupBranch(
|
|
1410
1339
|
scope.$,
|
|
1411
1340
|
renderer,
|
|
1412
1341
|
scope,
|
|
1413
1342
|
parentNode
|
|
1414
|
-
);
|
|
1415
|
-
branch.M = key, params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
|
|
1343
|
+
), branch.M = key, newScopes.push(branch), params?.(branch, args);
|
|
1416
1344
|
});
|
|
1417
|
-
let afterReference = null;
|
|
1418
|
-
|
|
1345
|
+
let newLen = newScopes.length, hasSiblings = referenceNode !== parentNode, afterReference = null, oldEnd = oldLen - 1, newEnd = newLen - 1, start = 0;
|
|
1346
|
+
if (hasSiblings && (oldLen ? (afterReference = oldScopes[oldEnd].K.nextSibling, newLen || parentNode.insertBefore(referenceNode, afterReference)) : newLen && (afterReference = referenceNode.nextSibling, referenceNode.remove())), !hasPotentialMoves) {
|
|
1347
|
+
oldLen && (oldScopes.forEach(
|
|
1348
|
+
hasSiblings ? removeAndDestroyBranch : destroyBranch
|
|
1349
|
+
), hasSiblings || (parentNode.textContent = ""));
|
|
1350
|
+
for (let newScope of newScopes)
|
|
1351
|
+
insertBranchBefore(newScope, parentNode, afterReference);
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
for (let branch of oldScopesByKey.values())
|
|
1355
|
+
removeAndDestroyBranch(branch);
|
|
1356
|
+
for (; start < oldLen && start < newLen && oldScopes[start] === newScopes[start]; )
|
|
1357
|
+
start++;
|
|
1358
|
+
for (; oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]; )
|
|
1359
|
+
oldEnd--, newEnd--;
|
|
1360
|
+
if (oldEnd + 1 < oldLen && (afterReference = oldScopes[oldEnd + 1].S), start > oldEnd) {
|
|
1361
|
+
if (start <= newEnd)
|
|
1362
|
+
for (let i = start; i <= newEnd; i++)
|
|
1363
|
+
insertBranchBefore(newScopes[i], parentNode, afterReference);
|
|
1364
|
+
return;
|
|
1365
|
+
} else if (start > newEnd)
|
|
1366
|
+
return;
|
|
1367
|
+
let diffLen = newEnd - start + 1, oldPos = /* @__PURE__ */ new Map(), sources = new Array(diffLen), pred = new Array(diffLen), tails = [], tail = -1, lo, hi, mid;
|
|
1368
|
+
for (let i = start; i <= oldEnd; i++)
|
|
1369
|
+
oldPos.set(oldScopes[i], i);
|
|
1370
|
+
for (let i = diffLen; i--; )
|
|
1371
|
+
sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
|
|
1372
|
+
for (let i = 0; i < diffLen; i++)
|
|
1373
|
+
if (~sources[i])
|
|
1374
|
+
if (tail < 0 || sources[tails[tail]] < sources[i])
|
|
1375
|
+
~tail && (pred[i] = tails[tail]), tails[++tail] = i;
|
|
1376
|
+
else {
|
|
1377
|
+
for (lo = 0, hi = tail; lo < hi; )
|
|
1378
|
+
mid = (lo + hi) / 2 | 0, sources[tails[mid]] < sources[i] ? lo = mid + 1 : hi = mid;
|
|
1379
|
+
sources[i] < sources[tails[lo]] && (lo > 0 && (pred[i] = tails[lo - 1]), tails[lo] = i);
|
|
1380
|
+
}
|
|
1381
|
+
for (hi = tails[tail], lo = tail + 1; lo-- > 0; )
|
|
1382
|
+
tails[lo] = hi, hi = pred[hi];
|
|
1383
|
+
for (let i = diffLen; i--; )
|
|
1384
|
+
~tail && i === tails[tail] ? tail-- : insertBranchBefore(newScopes[start + i], parentNode, afterReference), afterReference = newScopes[start + i].S;
|
|
1419
1385
|
};
|
|
1420
1386
|
};
|
|
1421
1387
|
}
|
package/dist/dom.mjs
CHANGED
|
@@ -167,10 +167,11 @@ function destroyBranch(branch) {
|
|
|
167
167
|
), destroyNestedBranches(branch);
|
|
168
168
|
}
|
|
169
169
|
function destroyNestedBranches(branch) {
|
|
170
|
-
branch.I = 1, branch.D?.forEach(destroyNestedBranches), branch.B?.forEach(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
branch.I = 1, branch.D?.forEach(destroyNestedBranches), branch.B?.forEach(resetControllers);
|
|
171
|
+
}
|
|
172
|
+
function resetControllers(scope) {
|
|
173
|
+
for (let id in scope.A)
|
|
174
|
+
$signalReset(scope, id);
|
|
174
175
|
}
|
|
175
176
|
function removeAndDestroyBranch(branch) {
|
|
176
177
|
destroyBranch(branch), removeChildNodes(
|
|
@@ -960,81 +961,6 @@ function toInsertNode(startNode, endNode) {
|
|
|
960
961
|
return parent;
|
|
961
962
|
}
|
|
962
963
|
|
|
963
|
-
// src/dom/reconcile.ts
|
|
964
|
-
var WRONG_POS = 2147483647;
|
|
965
|
-
function reconcile(parent, oldBranches, newBranches, afterReference) {
|
|
966
|
-
let oldStart = 0, newStart = 0, oldEnd = oldBranches.length - 1, newEnd = newBranches.length - 1, oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart], oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd], i, j, k, nextSibling, oldBranch, newBranch;
|
|
967
|
-
outer: {
|
|
968
|
-
for (; oldStartBranch === newStartBranch; ) {
|
|
969
|
-
if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd)
|
|
970
|
-
break outer;
|
|
971
|
-
oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart];
|
|
972
|
-
}
|
|
973
|
-
for (; oldEndBranch === newEndBranch; ) {
|
|
974
|
-
if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd)
|
|
975
|
-
break outer;
|
|
976
|
-
oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd];
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
if (oldStart > oldEnd) {
|
|
980
|
-
if (newStart <= newEnd) {
|
|
981
|
-
k = newEnd + 1, nextSibling = k < newBranches.length ? newBranches[k].S : afterReference;
|
|
982
|
-
do
|
|
983
|
-
insertBranchBefore(newBranches[newStart++], parent, nextSibling);
|
|
984
|
-
while (newStart <= newEnd);
|
|
985
|
-
}
|
|
986
|
-
} else if (newStart > newEnd)
|
|
987
|
-
do
|
|
988
|
-
removeAndDestroyBranch(oldBranches[oldStart++]);
|
|
989
|
-
while (oldStart <= oldEnd);
|
|
990
|
-
else {
|
|
991
|
-
let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldBranches, sources = new Array(newLength);
|
|
992
|
-
for (i = 0; i < newLength; ++i)
|
|
993
|
-
sources[i] = -1;
|
|
994
|
-
let pos = 0, synced = 0, keyIndex = /* @__PURE__ */ new Map();
|
|
995
|
-
for (j = newStart; j <= newEnd; ++j)
|
|
996
|
-
keyIndex.set(newBranches[j], j);
|
|
997
|
-
for (i = oldStart; i <= oldEnd && synced < newLength; ++i)
|
|
998
|
-
oldBranch = oldBranches[i], j = keyIndex.get(oldBranch), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newBranch = newBranches[j], sources[j - newStart] = i, aNullable[i] = null);
|
|
999
|
-
if (oldLength === oldBranches.length && synced === 0) {
|
|
1000
|
-
for (; newStart < newLength; ++newStart)
|
|
1001
|
-
insertBranchBefore(newBranches[newStart], parent, afterReference);
|
|
1002
|
-
for (; oldStart < oldLength; ++oldStart)
|
|
1003
|
-
removeAndDestroyBranch(oldBranches[oldStart]);
|
|
1004
|
-
} else {
|
|
1005
|
-
for (i = oldLength - synced; i > 0; )
|
|
1006
|
-
oldBranch = aNullable[oldStart++], oldBranch !== null && (removeAndDestroyBranch(oldBranch), i--);
|
|
1007
|
-
if (pos === WRONG_POS) {
|
|
1008
|
-
let seq = longestIncreasingSubsequence(sources);
|
|
1009
|
-
for (j = seq.length - 1, k = newBranches.length, i = newLength - 1; i >= 0; --i)
|
|
1010
|
-
sources[i] === -1 ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling)) : --j;
|
|
1011
|
-
} else if (synced !== newLength)
|
|
1012
|
-
for (k = newBranches.length, i = newLength - 1; i >= 0; --i)
|
|
1013
|
-
sources[i] === -1 && (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].S : afterReference, insertBranchBefore(newBranch, parent, nextSibling));
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
function longestIncreasingSubsequence(a) {
|
|
1018
|
-
let p = a.slice(), result = [0], u, v;
|
|
1019
|
-
for (let i = 0, il = a.length; i < il; ++i) {
|
|
1020
|
-
if (a[i] === -1)
|
|
1021
|
-
continue;
|
|
1022
|
-
let j = result[result.length - 1];
|
|
1023
|
-
if (a[j] < a[i]) {
|
|
1024
|
-
p[i] = j, result.push(i);
|
|
1025
|
-
continue;
|
|
1026
|
-
}
|
|
1027
|
-
for (u = 0, v = result.length - 1; u < v; ) {
|
|
1028
|
-
let c = (u + v) / 2 | 0;
|
|
1029
|
-
a[result[c]] < a[i] ? u = c + 1 : v = c;
|
|
1030
|
-
}
|
|
1031
|
-
a[i] < a[result[u]] && (u > 0 && (p[i] = result[u - 1]), result[u] = i);
|
|
1032
|
-
}
|
|
1033
|
-
for (u = result.length, v = result[u - 1]; u-- > 0; )
|
|
1034
|
-
result[u] = v, v = p[v];
|
|
1035
|
-
return result;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
964
|
// src/dom/control-flow.ts
|
|
1039
965
|
function _await_promise(nodeAccessor, params) {
|
|
1040
966
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
@@ -1288,23 +1214,63 @@ var _for_of = loop(([all, by = bySecondArg], cb) => {
|
|
|
1288
1214
|
function loop(forEach) {
|
|
1289
1215
|
return (nodeAccessor, template, walks, setup, params) => {
|
|
1290
1216
|
nodeAccessor = decodeAccessor(nodeAccessor);
|
|
1291
|
-
let scopesAccessor = "A" /* BranchScopes */ + nodeAccessor,
|
|
1217
|
+
let scopesAccessor = "A" /* BranchScopes */ + nodeAccessor, renderer = _content("", template, walks, setup)();
|
|
1292
1218
|
return enableBranches(), (scope, value) => {
|
|
1293
|
-
let referenceNode = scope[nodeAccessor], oldScopes = toArray(scope[scopesAccessor]),
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
), newScopes = scope[scopesAccessor] = [], newScopesByKey = scope[scopesByKeyAccessor] = /* @__PURE__ */ new Map(), parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.S.parentNode : referenceNode;
|
|
1219
|
+
let referenceNode = scope[nodeAccessor], oldScopes = toArray(scope[scopesAccessor]), newScopes = scope[scopesAccessor] = [], oldLen = oldScopes.length, parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.S.parentNode : referenceNode, oldScopesByKey, hasPotentialMoves;
|
|
1220
|
+
if (0)
|
|
1221
|
+
var seenKeys;
|
|
1297
1222
|
forEach(value, (key, args) => {
|
|
1298
|
-
let branch = oldScopesByKey
|
|
1223
|
+
let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce(
|
|
1224
|
+
(map, scope2, i) => map.set(scope2.M ?? i, scope2),
|
|
1225
|
+
/* @__PURE__ */ new Map()
|
|
1226
|
+
)).get(key);
|
|
1227
|
+
branch ? hasPotentialMoves = oldScopesByKey.delete(key) : branch = createAndSetupBranch(
|
|
1299
1228
|
scope.$,
|
|
1300
1229
|
renderer,
|
|
1301
1230
|
scope,
|
|
1302
1231
|
parentNode
|
|
1303
|
-
);
|
|
1304
|
-
branch.M = key, params?.(branch, args), newScopesByKey.set(key, branch), newScopes.push(branch);
|
|
1232
|
+
), branch.M = key, newScopes.push(branch), params?.(branch, args);
|
|
1305
1233
|
});
|
|
1306
|
-
let afterReference = null;
|
|
1307
|
-
|
|
1234
|
+
let newLen = newScopes.length, hasSiblings = referenceNode !== parentNode, afterReference = null, oldEnd = oldLen - 1, newEnd = newLen - 1, start = 0;
|
|
1235
|
+
if (hasSiblings && (oldLen ? (afterReference = oldScopes[oldEnd].K.nextSibling, newLen || parentNode.insertBefore(referenceNode, afterReference)) : newLen && (afterReference = referenceNode.nextSibling, referenceNode.remove())), !hasPotentialMoves) {
|
|
1236
|
+
oldLen && (oldScopes.forEach(
|
|
1237
|
+
hasSiblings ? removeAndDestroyBranch : destroyBranch
|
|
1238
|
+
), hasSiblings || (parentNode.textContent = ""));
|
|
1239
|
+
for (let newScope of newScopes)
|
|
1240
|
+
insertBranchBefore(newScope, parentNode, afterReference);
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
for (let branch of oldScopesByKey.values())
|
|
1244
|
+
removeAndDestroyBranch(branch);
|
|
1245
|
+
for (; start < oldLen && start < newLen && oldScopes[start] === newScopes[start]; )
|
|
1246
|
+
start++;
|
|
1247
|
+
for (; oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]; )
|
|
1248
|
+
oldEnd--, newEnd--;
|
|
1249
|
+
if (oldEnd + 1 < oldLen && (afterReference = oldScopes[oldEnd + 1].S), start > oldEnd) {
|
|
1250
|
+
if (start <= newEnd)
|
|
1251
|
+
for (let i = start; i <= newEnd; i++)
|
|
1252
|
+
insertBranchBefore(newScopes[i], parentNode, afterReference);
|
|
1253
|
+
return;
|
|
1254
|
+
} else if (start > newEnd)
|
|
1255
|
+
return;
|
|
1256
|
+
let diffLen = newEnd - start + 1, oldPos = /* @__PURE__ */ new Map(), sources = new Array(diffLen), pred = new Array(diffLen), tails = [], tail = -1, lo, hi, mid;
|
|
1257
|
+
for (let i = start; i <= oldEnd; i++)
|
|
1258
|
+
oldPos.set(oldScopes[i], i);
|
|
1259
|
+
for (let i = diffLen; i--; )
|
|
1260
|
+
sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
|
|
1261
|
+
for (let i = 0; i < diffLen; i++)
|
|
1262
|
+
if (~sources[i])
|
|
1263
|
+
if (tail < 0 || sources[tails[tail]] < sources[i])
|
|
1264
|
+
~tail && (pred[i] = tails[tail]), tails[++tail] = i;
|
|
1265
|
+
else {
|
|
1266
|
+
for (lo = 0, hi = tail; lo < hi; )
|
|
1267
|
+
mid = (lo + hi) / 2 | 0, sources[tails[mid]] < sources[i] ? lo = mid + 1 : hi = mid;
|
|
1268
|
+
sources[i] < sources[tails[lo]] && (lo > 0 && (pred[i] = tails[lo - 1]), tails[lo] = i);
|
|
1269
|
+
}
|
|
1270
|
+
for (hi = tails[tail], lo = tail + 1; lo-- > 0; )
|
|
1271
|
+
tails[lo] = hi, hi = pred[hi];
|
|
1272
|
+
for (let i = diffLen; i--; )
|
|
1273
|
+
~tail && i === tails[tail] ? tail-- : insertBranchBefore(newScopes[start + i], parentNode, afterReference), afterReference = newScopes[start + i].S;
|
|
1308
1274
|
};
|
|
1309
1275
|
};
|
|
1310
1276
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marko",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.153",
|
|
4
4
|
"description": "Optimized runtime for Marko templates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"build": "node -r ~ts ./scripts/bundle.ts"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@marko/compiler": "^5.39.
|
|
51
|
+
"@marko/compiler": "^5.39.58",
|
|
52
52
|
"csstype": "^3.2.3",
|
|
53
53
|
"magic-string": "^0.30.21"
|
|
54
54
|
},
|
package/dist/dom/reconcile.d.ts
DELETED