marko 6.0.0-next.3.66 → 6.0.0-next.3.68

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 CHANGED
@@ -277,6 +277,8 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
277
277
  const branchIds = /* @__PURE__ */ new Set();
278
278
  const parentBranchIds = /* @__PURE__ */ new Map();
279
279
  let currentBranchId;
280
+ let $global;
281
+ let lastScopeId = 0;
280
282
  render.w = () => {
281
283
  walk2.call(render);
282
284
  const visits = render.v;
@@ -303,12 +305,12 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
303
305
  for (const visit of visitNodes) {
304
306
  const commentText = visit.data;
305
307
  const dataIndex = commentText.indexOf(" ") + 1;
306
- const scopeId = commentText.slice(
308
+ const scopeId = +commentText.slice(
307
309
  commentPrefixLen + 1,
308
310
  dataIndex ? dataIndex - 1 : commentText.length
309
311
  );
310
312
  const scope = scopeLookup[scopeId] ||= {
311
- ___id: +scopeId
313
+ ___id: scopeId
312
314
  };
313
315
  const data2 = dataIndex ? commentText.slice(dataIndex) : "";
314
316
  const token = commentText[commentPrefixLen];
@@ -344,7 +346,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
344
346
  while (~next) {
345
347
  const start = next + 1;
346
348
  next = data2.indexOf(" ", start);
347
- const childScopeId = data2.slice(
349
+ const childScopeId = +data2.slice(
348
350
  start,
349
351
  ~next ? next : data2.length
350
352
  );
@@ -361,20 +363,19 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
361
363
  for (let i = 0; i < resumes.length; i++) {
362
364
  const serialized = resumes[i];
363
365
  if (typeof serialized === "function") {
364
- const scopes = serialized(serializeContext);
365
- let { $global } = scopeLookup;
366
- if (!$global) {
367
- scopeLookup.$global = $global = scopes.$ || {};
368
- $global.runtimeId = runtimeId;
369
- $global.renderId = renderId;
370
- $global.___nextScopeId = 1e6;
371
- }
372
- for (const scopeId in scopes) {
373
- if (scopeId !== "$") {
374
- const scope = scopes[scopeId];
366
+ for (const scope of serialized(serializeContext)) {
367
+ if (!$global) {
368
+ $global = scope || {};
369
+ $global.runtimeId = runtimeId;
370
+ $global.renderId = renderId;
371
+ $global.___nextScopeId = 1e6;
372
+ } else if (typeof scope === "number") {
373
+ lastScopeId += scope;
374
+ } else {
375
+ const scopeId = ++lastScopeId;
375
376
  const prevScope = scopeLookup[scopeId];
376
377
  scope.$global = $global;
377
- scope.___id = +scopeId;
378
+ scope.___id = scopeId;
378
379
  if (prevScope !== scope) {
379
380
  scopeLookup[scopeId] = Object.assign(
380
381
  scope,
@@ -383,7 +384,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
383
384
  }
384
385
  const parentBranchId = scope["#ClosestBranchId" /* ClosestBranchId */] || parentBranchIds.get(scopeId);
385
386
  if (parentBranchId) {
386
- scope.___closestBranch = scopes[parentBranchId];
387
+ scope.___closestBranch = scopeLookup[parentBranchId];
387
388
  }
388
389
  if (branchIds.has(scopeId)) {
389
390
  const branch = scope;
@@ -1653,7 +1654,6 @@ function awaitTag(nodeAccessor, renderer) {
1653
1654
  })
1654
1655
  );
1655
1656
  if (tryWithPlaceholder) {
1656
- tryWithPlaceholder;
1657
1657
  if (!--tryWithPlaceholder.___pendingAsyncCount) {
1658
1658
  const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1659
1659
  tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
@@ -1664,12 +1664,6 @@ function awaitTag(nodeAccessor, renderer) {
1664
1664
  placeholderBranch.___startNode
1665
1665
  );
1666
1666
  removeAndDestroyBranch(placeholderBranch);
1667
- } else {
1668
- insertBranchBefore(
1669
- tryWithPlaceholder,
1670
- referenceNode.parentNode,
1671
- referenceNode
1672
- );
1673
1667
  }
1674
1668
  if (tryWithPlaceholder.___effects) {
1675
1669
  runEffects(tryWithPlaceholder.___effects, true);
@@ -189,6 +189,8 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
189
189
  const branchIds = /* @__PURE__ */ new Set();
190
190
  const parentBranchIds = /* @__PURE__ */ new Map();
191
191
  let currentBranchId;
192
+ let $global;
193
+ let lastScopeId = 0;
192
194
  render.w = () => {
193
195
  walk2.call(render);
194
196
  const visits = render.v;
@@ -215,12 +217,12 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
215
217
  for (const visit of visitNodes) {
216
218
  const commentText = visit.data;
217
219
  const dataIndex = commentText.indexOf(" ") + 1;
218
- const scopeId = commentText.slice(
220
+ const scopeId = +commentText.slice(
219
221
  commentPrefixLen + 1,
220
222
  dataIndex ? dataIndex - 1 : commentText.length
221
223
  );
222
224
  const scope = scopeLookup[scopeId] ||= {
223
- ___id: +scopeId
225
+ ___id: scopeId
224
226
  };
225
227
  const data2 = dataIndex ? commentText.slice(dataIndex) : "";
226
228
  const token = commentText[commentPrefixLen];
@@ -256,7 +258,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
256
258
  while (~next) {
257
259
  const start = next + 1;
258
260
  next = data2.indexOf(" ", start);
259
- const childScopeId = data2.slice(
261
+ const childScopeId = +data2.slice(
260
262
  start,
261
263
  ~next ? next : data2.length
262
264
  );
@@ -273,20 +275,19 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
273
275
  for (let i = 0; i < resumes.length; i++) {
274
276
  const serialized = resumes[i];
275
277
  if (typeof serialized === "function") {
276
- const scopes = serialized(serializeContext);
277
- let { $global } = scopeLookup;
278
- if (!$global) {
279
- scopeLookup.$global = $global = scopes.$ || {};
280
- $global.runtimeId = runtimeId;
281
- $global.renderId = renderId;
282
- $global.___nextScopeId = 1e6;
283
- }
284
- for (const scopeId in scopes) {
285
- if (scopeId !== "$") {
286
- const scope = scopes[scopeId];
278
+ for (const scope of serialized(serializeContext)) {
279
+ if (!$global) {
280
+ $global = scope || {};
281
+ $global.runtimeId = runtimeId;
282
+ $global.renderId = renderId;
283
+ $global.___nextScopeId = 1e6;
284
+ } else if (typeof scope === "number") {
285
+ lastScopeId += scope;
286
+ } else {
287
+ const scopeId = ++lastScopeId;
287
288
  const prevScope = scopeLookup[scopeId];
288
289
  scope.$global = $global;
289
- scope.___id = +scopeId;
290
+ scope.___id = scopeId;
290
291
  if (prevScope !== scope) {
291
292
  scopeLookup[scopeId] = Object.assign(
292
293
  scope,
@@ -295,7 +296,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
295
296
  }
296
297
  const parentBranchId = scope["#ClosestBranchId" /* ClosestBranchId */] || parentBranchIds.get(scopeId);
297
298
  if (parentBranchId) {
298
- scope.___closestBranch = scopes[parentBranchId];
299
+ scope.___closestBranch = scopeLookup[parentBranchId];
299
300
  }
300
301
  if (branchIds.has(scopeId)) {
301
302
  const branch = scope;
@@ -1565,7 +1566,6 @@ function awaitTag(nodeAccessor, renderer) {
1565
1566
  })
1566
1567
  );
1567
1568
  if (tryWithPlaceholder) {
1568
- tryWithPlaceholder;
1569
1569
  if (!--tryWithPlaceholder.___pendingAsyncCount) {
1570
1570
  const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1571
1571
  tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
@@ -1576,12 +1576,6 @@ function awaitTag(nodeAccessor, renderer) {
1576
1576
  placeholderBranch.___startNode
1577
1577
  );
1578
1578
  removeAndDestroyBranch(placeholderBranch);
1579
- } else {
1580
- insertBranchBefore(
1581
- tryWithPlaceholder,
1582
- referenceNode.parentNode,
1583
- referenceNode
1584
- );
1585
1579
  }
1586
1580
  if (tryWithPlaceholder.___effects) {
1587
1581
  runEffects(tryWithPlaceholder.___effects, true);
@@ -279,16 +279,12 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
279
279
  placeholders[id] = {
280
280
  i: 1,
281
281
  c(end = runtime.l[id] || node) {
282
- while (end.parentNode !== start.parentNode) {
283
- end = end.parentNode;
284
- }
285
-
286
282
  for (
287
283
  ;
288
- end != nextSibling;
289
- (nextSibling = start.nextSibling).remove()
284
+ (nextSibling = end.previousSibling || start).remove(),
285
+ start != nextSibling;
290
286
  );
291
- replace(start, node);
287
+ replace(end, node);
292
288
  },
293
289
  };
294
290
  }
@@ -310,7 +306,7 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
310
306
  }
311
307
  };
312
308
  })`
313
- ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e.r)))}})`;
309
+ ) : `(e=>{let i,l,t,r={},c=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,o,n,a,g)=>{"#"==d?(r[o]=l).i++:n==t&&i(),"T"==n.tagName&&(o=n.getAttribute(e.i))&&((a=e.l["^"+o])&&(r[o]={i:1,c(i=e.l[o]||n){for(;(t=i.previousSibling||a).remove(),a!=t;);c(i,n)}}),t=n.nextSibling,l=r[o],i=()=>{a||c(e.l[o],n),--l.i||l.c()},(d=e.j[o])&&(g=l.c,l.c=()=>g()+d(e.r)))}})`;
314
310
 
315
311
  // src/html/serializer.ts
316
312
  var { hasOwnProperty } = {};
@@ -1891,14 +1887,8 @@ var writeScope = (scopeId, partialScope) => {
1891
1887
  }
1892
1888
  if (state.writeScopes) {
1893
1889
  state.writeScopes[scopeId] = scope;
1894
- } else if (state.hasGlobals) {
1895
- state.writeScopes = { [scopeId]: scope };
1896
1890
  } else {
1897
- state.hasGlobals = true;
1898
- state.writeScopes = {
1899
- $: getFilteredGlobals(state.$global),
1900
- [scopeId]: scope
1901
- };
1891
+ state.writeScopes = { [scopeId]: scope };
1902
1892
  }
1903
1893
  return scope;
1904
1894
  };
@@ -2099,6 +2089,7 @@ var State2 = class {
2099
2089
  tagId = 1;
2100
2090
  scopeId = 1;
2101
2091
  reorderId = 1;
2092
+ lastSerializedScopeId = this.scopeId;
2102
2093
  hasGlobals = false;
2103
2094
  needsMainRuntime = false;
2104
2095
  hasMainRuntime = false;
@@ -2292,8 +2283,23 @@ function prepareChunk(chunk) {
2292
2283
  }
2293
2284
  let resumes = "";
2294
2285
  if (state.writeScopes || serializer.flushed) {
2295
- resumes = state.serializer.stringify(state.writeScopes || {}, boundary);
2286
+ let { lastSerializedScopeId } = state;
2287
+ const serializeData = [];
2288
+ if (!state.hasGlobals) {
2289
+ state.hasGlobals = true;
2290
+ serializeData.push(getFilteredGlobals(state.$global));
2291
+ }
2292
+ for (const key in state.writeScopes) {
2293
+ const scope = state.writeScopes[key];
2294
+ const scopeId = getScopeId(scope);
2295
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2296
+ lastSerializedScopeId = scopeId + 1;
2297
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2298
+ serializeData.push(scope);
2299
+ }
2300
+ resumes = state.serializer.stringify(serializeData, boundary);
2296
2301
  state.writeScopes = null;
2302
+ state.lastSerializedScopeId = lastSerializedScopeId;
2297
2303
  }
2298
2304
  if (effects) {
2299
2305
  hasWalk = true;
@@ -2331,8 +2337,8 @@ function prepareChunk(chunk) {
2331
2337
  let cur = reorderedChunk;
2332
2338
  reorderedChunk.reorderId = null;
2333
2339
  for (; ; ) {
2334
- const { next } = cur;
2335
2340
  cur.flushPlaceholder();
2341
+ const { next } = cur;
2336
2342
  cur.consumed = true;
2337
2343
  reorderHTML += cur.html;
2338
2344
  reorderEffects = concatEffects(reorderEffects, cur.effects);
@@ -2432,10 +2438,10 @@ function isPromise(value) {
2432
2438
  return value != null && typeof value.then === "function";
2433
2439
  }
2434
2440
  function getFilteredGlobals($global2) {
2435
- if (!$global2) return void 0;
2441
+ if (!$global2) return 0;
2436
2442
  const serializedGlobals = $global2.serializedGlobals;
2437
- if (!serializedGlobals) return void 0;
2438
- let filtered;
2443
+ if (!serializedGlobals) return 0;
2444
+ let filtered = 0;
2439
2445
  if (Array.isArray(serializedGlobals)) {
2440
2446
  for (const key of serializedGlobals) {
2441
2447
  const value = $global2[key];
@@ -195,16 +195,12 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
195
195
  placeholders[id] = {
196
196
  i: 1,
197
197
  c(end = runtime.l[id] || node) {
198
- while (end.parentNode !== start.parentNode) {
199
- end = end.parentNode;
200
- }
201
-
202
198
  for (
203
199
  ;
204
- end != nextSibling;
205
- (nextSibling = start.nextSibling).remove()
200
+ (nextSibling = end.previousSibling || start).remove(),
201
+ start != nextSibling;
206
202
  );
207
- replace(start, node);
203
+ replace(end, node);
208
204
  },
209
205
  };
210
206
  }
@@ -226,7 +222,7 @@ runtime.x = (op, id, node, start, placeholderCallback) => {
226
222
  }
227
223
  };
228
224
  })`
229
- ) : `(e=>{let i,t,r,l={},o=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,n,a,c,p)=>{"#"==d?(l[n]=t).i++:a==r&&i(),"T"==a.tagName&&(n=a.getAttribute(e.i))&&((c=e.l["^"+n])&&(l[n]={i:1,c(i=e.l[n]||a){for(;i.parentNode!==c.parentNode;)i=i.parentNode;for(;i!=r;(r=c.nextSibling).remove());o(c,a)}}),r=a.nextSibling,t=l[n],i=()=>{c||o(e.l[n],a),--t.i||t.c()},(d=e.j[n])&&(p=t.c,t.c=()=>p()+d(e.r)))}})`;
225
+ ) : `(e=>{let i,l,t,r={},c=(e,i)=>{e.replaceWith(...i.childNodes),i.remove()};e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(d,o,n,a,g)=>{"#"==d?(r[o]=l).i++:n==t&&i(),"T"==n.tagName&&(o=n.getAttribute(e.i))&&((a=e.l["^"+o])&&(r[o]={i:1,c(i=e.l[o]||n){for(;(t=i.previousSibling||a).remove(),a!=t;);c(i,n)}}),t=n.nextSibling,l=r[o],i=()=>{a||c(e.l[o],n),--l.i||l.c()},(d=e.j[o])&&(g=l.c,l.c=()=>g()+d(e.r)))}})`;
230
226
 
231
227
  // src/html/serializer.ts
232
228
  var { hasOwnProperty } = {};
@@ -1807,14 +1803,8 @@ var writeScope = (scopeId, partialScope) => {
1807
1803
  }
1808
1804
  if (state.writeScopes) {
1809
1805
  state.writeScopes[scopeId] = scope;
1810
- } else if (state.hasGlobals) {
1811
- state.writeScopes = { [scopeId]: scope };
1812
1806
  } else {
1813
- state.hasGlobals = true;
1814
- state.writeScopes = {
1815
- $: getFilteredGlobals(state.$global),
1816
- [scopeId]: scope
1817
- };
1807
+ state.writeScopes = { [scopeId]: scope };
1818
1808
  }
1819
1809
  return scope;
1820
1810
  };
@@ -2015,6 +2005,7 @@ var State2 = class {
2015
2005
  tagId = 1;
2016
2006
  scopeId = 1;
2017
2007
  reorderId = 1;
2008
+ lastSerializedScopeId = this.scopeId;
2018
2009
  hasGlobals = false;
2019
2010
  needsMainRuntime = false;
2020
2011
  hasMainRuntime = false;
@@ -2208,8 +2199,23 @@ function prepareChunk(chunk) {
2208
2199
  }
2209
2200
  let resumes = "";
2210
2201
  if (state.writeScopes || serializer.flushed) {
2211
- resumes = state.serializer.stringify(state.writeScopes || {}, boundary);
2202
+ let { lastSerializedScopeId } = state;
2203
+ const serializeData = [];
2204
+ if (!state.hasGlobals) {
2205
+ state.hasGlobals = true;
2206
+ serializeData.push(getFilteredGlobals(state.$global));
2207
+ }
2208
+ for (const key in state.writeScopes) {
2209
+ const scope = state.writeScopes[key];
2210
+ const scopeId = getScopeId(scope);
2211
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2212
+ lastSerializedScopeId = scopeId + 1;
2213
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2214
+ serializeData.push(scope);
2215
+ }
2216
+ resumes = state.serializer.stringify(serializeData, boundary);
2212
2217
  state.writeScopes = null;
2218
+ state.lastSerializedScopeId = lastSerializedScopeId;
2213
2219
  }
2214
2220
  if (effects) {
2215
2221
  hasWalk = true;
@@ -2247,8 +2253,8 @@ function prepareChunk(chunk) {
2247
2253
  let cur = reorderedChunk;
2248
2254
  reorderedChunk.reorderId = null;
2249
2255
  for (; ; ) {
2250
- const { next } = cur;
2251
2256
  cur.flushPlaceholder();
2257
+ const { next } = cur;
2252
2258
  cur.consumed = true;
2253
2259
  reorderHTML += cur.html;
2254
2260
  reorderEffects = concatEffects(reorderEffects, cur.effects);
@@ -2348,10 +2354,10 @@ function isPromise(value) {
2348
2354
  return value != null && typeof value.then === "function";
2349
2355
  }
2350
2356
  function getFilteredGlobals($global2) {
2351
- if (!$global2) return void 0;
2357
+ if (!$global2) return 0;
2352
2358
  const serializedGlobals = $global2.serializedGlobals;
2353
- if (!serializedGlobals) return void 0;
2354
- let filtered;
2359
+ if (!serializedGlobals) return 0;
2360
+ let filtered = 0;
2355
2361
  if (Array.isArray(serializedGlobals)) {
2356
2362
  for (const key of serializedGlobals) {
2357
2363
  const value = $global2[key];
package/dist/dom.js CHANGED
@@ -213,7 +213,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
213
213
  value: resumeRender = (renderId) => {
214
214
  let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, commentPrefixLen = render.i.length, branchStack = [], scopeLookup = render.s = {}, serializeContext = {
215
215
  _: registeredValues
216
- }, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map(), currentBranchId;
216
+ }, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map(), currentBranchId, $global, lastScopeId = 0;
217
217
  return render.w = () => {
218
218
  walk2.call(render);
219
219
  let visits = render.v, resumes = render.r;
@@ -229,11 +229,11 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
229
229
  )), branch.j = lastEndNode = endNode, branch.h ||= endNode, branchIds.add(branchId), branch;
230
230
  };
231
231
  for (let visit of visitNodes) {
232
- let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = commentText.slice(
232
+ let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = +commentText.slice(
233
233
  commentPrefixLen + 1,
234
234
  dataIndex ? dataIndex - 1 : commentText.length
235
235
  ), scope = scopeLookup[scopeId] ||= {
236
- m: +scopeId
236
+ m: scopeId
237
237
  }, data2 = dataIndex ? commentText.slice(dataIndex) : "", token = commentText[commentPrefixLen];
238
238
  if (token === "*" /* Node */) {
239
239
  let node = scope[data2] = visit.previousSibling;
@@ -252,7 +252,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
252
252
  for (scope[~next ? data2.slice(0, next) : data2] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit; ~next; ) {
253
253
  let start = next + 1;
254
254
  next = data2.indexOf(" ", start);
255
- let childScopeId = data2.slice(
255
+ let childScopeId = +data2.slice(
256
256
  start,
257
257
  ~next ? next : data2.length
258
258
  );
@@ -266,25 +266,27 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
266
266
  render.r = [], isResuming = !0;
267
267
  for (let i = 0; i < resumes.length; i++) {
268
268
  let serialized = resumes[i];
269
- if (typeof serialized == "function") {
270
- let scopes = serialized(serializeContext), { $global } = scopeLookup;
271
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.n = 1e6);
272
- for (let scopeId in scopes)
273
- if (scopeId !== "$") {
274
- let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
275
- scope.$global = $global, scope.m = +scopeId, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
269
+ if (typeof serialized == "function")
270
+ for (let scope of serialized(serializeContext))
271
+ if (!$global)
272
+ $global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.n = 1e6;
273
+ else if (typeof scope == "number")
274
+ lastScopeId += scope;
275
+ else {
276
+ let scopeId = ++lastScopeId, prevScope = scopeLookup[scopeId];
277
+ scope.$global = $global, scope.m = scopeId, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
276
278
  scope,
277
279
  prevScope
278
280
  ));
279
281
  let parentBranchId = scope.g || parentBranchIds.get(scopeId);
280
- if (parentBranchId && (scope.k = scopes[parentBranchId]), branchIds.has(scopeId)) {
282
+ if (parentBranchId && (scope.k = scopeLookup[parentBranchId]), branchIds.has(scopeId)) {
281
283
  let branch = scope, parentBranch = branch.k;
282
284
  scope.k = branch, parentBranch && (branch.u = parentBranch, (parentBranch.A ||= /* @__PURE__ */ new Set()).add(
283
285
  branch
284
286
  ));
285
287
  }
286
288
  }
287
- } else
289
+ else
288
290
  registeredValues[resumes[++i]](
289
291
  scopeLookup[serialized],
290
292
  scopeLookup[serialized]
@@ -1110,15 +1112,11 @@ function awaitTag(nodeAccessor, renderer) {
1110
1112
  })
1111
1113
  ), tryWithPlaceholder && !--tryWithPlaceholder.q)) {
1112
1114
  let placeholderBranch = tryWithPlaceholder.c;
1113
- tryWithPlaceholder.c = void 0, placeholderBranch ? (insertBranchBefore(
1115
+ tryWithPlaceholder.c = void 0, placeholderBranch && (insertBranchBefore(
1114
1116
  tryWithPlaceholder,
1115
1117
  placeholderBranch.h.parentNode,
1116
1118
  placeholderBranch.h
1117
- ), removeAndDestroyBranch(placeholderBranch)) : insertBranchBefore(
1118
- tryWithPlaceholder,
1119
- referenceNode.parentNode,
1120
- referenceNode
1121
- ), tryWithPlaceholder.H && runEffects(tryWithPlaceholder.H, !0);
1119
+ ), removeAndDestroyBranch(placeholderBranch)), tryWithPlaceholder.H && runEffects(tryWithPlaceholder.H, !0);
1122
1120
  }
1123
1121
  }).catch((error) => {
1124
1122
  renderCatch(scope, error, !0);
package/dist/dom.mjs CHANGED
@@ -128,7 +128,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
128
128
  value: resumeRender = (renderId) => {
129
129
  let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, commentPrefixLen = render.i.length, branchStack = [], scopeLookup = render.s = {}, serializeContext = {
130
130
  _: registeredValues
131
- }, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map(), currentBranchId;
131
+ }, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map(), currentBranchId, $global, lastScopeId = 0;
132
132
  return render.w = () => {
133
133
  walk2.call(render);
134
134
  let visits = render.v, resumes = render.r;
@@ -144,11 +144,11 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
144
144
  )), branch.j = lastEndNode = endNode, branch.h ||= endNode, branchIds.add(branchId), branch;
145
145
  };
146
146
  for (let visit of visitNodes) {
147
- let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = commentText.slice(
147
+ let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = +commentText.slice(
148
148
  commentPrefixLen + 1,
149
149
  dataIndex ? dataIndex - 1 : commentText.length
150
150
  ), scope = scopeLookup[scopeId] ||= {
151
- m: +scopeId
151
+ m: scopeId
152
152
  }, data2 = dataIndex ? commentText.slice(dataIndex) : "", token = commentText[commentPrefixLen];
153
153
  if (token === "*" /* Node */) {
154
154
  let node = scope[data2] = visit.previousSibling;
@@ -167,7 +167,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
167
167
  for (scope[~next ? data2.slice(0, next) : data2] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit; ~next; ) {
168
168
  let start = next + 1;
169
169
  next = data2.indexOf(" ", start);
170
- let childScopeId = data2.slice(
170
+ let childScopeId = +data2.slice(
171
171
  start,
172
172
  ~next ? next : data2.length
173
173
  );
@@ -181,25 +181,27 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
181
181
  render.r = [], isResuming = !0;
182
182
  for (let i = 0; i < resumes.length; i++) {
183
183
  let serialized = resumes[i];
184
- if (typeof serialized == "function") {
185
- let scopes = serialized(serializeContext), { $global } = scopeLookup;
186
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.n = 1e6);
187
- for (let scopeId in scopes)
188
- if (scopeId !== "$") {
189
- let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
190
- scope.$global = $global, scope.m = +scopeId, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
184
+ if (typeof serialized == "function")
185
+ for (let scope of serialized(serializeContext))
186
+ if (!$global)
187
+ $global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.n = 1e6;
188
+ else if (typeof scope == "number")
189
+ lastScopeId += scope;
190
+ else {
191
+ let scopeId = ++lastScopeId, prevScope = scopeLookup[scopeId];
192
+ scope.$global = $global, scope.m = scopeId, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
191
193
  scope,
192
194
  prevScope
193
195
  ));
194
196
  let parentBranchId = scope.g || parentBranchIds.get(scopeId);
195
- if (parentBranchId && (scope.k = scopes[parentBranchId]), branchIds.has(scopeId)) {
197
+ if (parentBranchId && (scope.k = scopeLookup[parentBranchId]), branchIds.has(scopeId)) {
196
198
  let branch = scope, parentBranch = branch.k;
197
199
  scope.k = branch, parentBranch && (branch.u = parentBranch, (parentBranch.A ||= /* @__PURE__ */ new Set()).add(
198
200
  branch
199
201
  ));
200
202
  }
201
203
  }
202
- } else
204
+ else
203
205
  registeredValues[resumes[++i]](
204
206
  scopeLookup[serialized],
205
207
  scopeLookup[serialized]
@@ -1025,15 +1027,11 @@ function awaitTag(nodeAccessor, renderer) {
1025
1027
  })
1026
1028
  ), tryWithPlaceholder && !--tryWithPlaceholder.q)) {
1027
1029
  let placeholderBranch = tryWithPlaceholder.c;
1028
- tryWithPlaceholder.c = void 0, placeholderBranch ? (insertBranchBefore(
1030
+ tryWithPlaceholder.c = void 0, placeholderBranch && (insertBranchBefore(
1029
1031
  tryWithPlaceholder,
1030
1032
  placeholderBranch.h.parentNode,
1031
1033
  placeholderBranch.h
1032
- ), removeAndDestroyBranch(placeholderBranch)) : insertBranchBefore(
1033
- tryWithPlaceholder,
1034
- referenceNode.parentNode,
1035
- referenceNode
1036
- ), tryWithPlaceholder.H && runEffects(tryWithPlaceholder.H, !0);
1034
+ ), removeAndDestroyBranch(placeholderBranch)), tryWithPlaceholder.H && runEffects(tryWithPlaceholder.H, !0);
1037
1035
  }
1038
1036
  }).catch((error) => {
1039
1037
  renderCatch(scope, error, !0);
@@ -63,6 +63,7 @@ export declare class State {
63
63
  tagId: number;
64
64
  scopeId: number;
65
65
  reorderId: number;
66
+ lastSerializedScopeId: number;
66
67
  hasGlobals: boolean;
67
68
  needsMainRuntime: boolean;
68
69
  hasMainRuntime: boolean;
@@ -73,9 +74,7 @@ export declare class State {
73
74
  serializer: Serializer;
74
75
  writeReorders: Chunk[] | null;
75
76
  scopes: Map<number, PartialScope>;
76
- writeScopes: null | (Record<number, PartialScope> & {
77
- $?: unknown;
78
- });
77
+ writeScopes: null | Record<number, PartialScope>;
79
78
  constructor($global: $Global & {
80
79
  renderId: string;
81
80
  runtimeId: string;