marko 6.1.2 → 6.1.3

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.
@@ -175,7 +175,7 @@ function forStepBy(by, index) {
175
175
  }
176
176
  //#endregion
177
177
  //#region src/html/inlined-runtimes.debug.ts
178
- const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] || (self[runtimeId] = (
178
+ const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] ||= (
179
179
  renderId,
180
180
  prefix = runtimeId + renderId,
181
181
  prefixLen = prefix.length,
@@ -210,7 +210,7 @@ const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] || (self[runtimeId
210
210
  }
211
211
  },
212
212
  })
213
- ), self[runtimeId]))`;
213
+ , self[runtimeId]))`;
214
214
  const REORDER_RUNTIME_CODE = `((runtime) => {
215
215
  if (runtime.j) return;
216
216
  let onNextSibling,
@@ -761,15 +761,16 @@ function writeRegistered(state, val, parent, accessor, registered) {
761
761
  } else state.buf.push(registered.access);
762
762
  return true;
763
763
  }
764
+ const STRING_DEDUP_LENGTH = 12;
764
765
  function writeString(state, val, parent, accessor) {
765
- if (val.length > 30) {
766
+ if (val.length > STRING_DEDUP_LENGTH) {
766
767
  const ref = state.strs.get(val);
767
- if (ref) state.buf.push(ensureId(state, ref));
768
- else {
769
- state.strs.set(val, new Reference(parent, accessor, state.flush, state.buf.length));
770
- state.buf.push(quote(val, 0));
771
- }
772
- } else state.buf.push(quote(val, 0));
768
+ if (ref) {
769
+ state.buf.push(ensureId(state, ref));
770
+ return true;
771
+ } else state.strs.set(val, new Reference(parent, accessor, state.flush, state.buf.length));
772
+ }
773
+ state.buf.push(quote(val, 0));
773
774
  return true;
774
775
  }
775
776
  function writeNumber(state, val) {
@@ -891,7 +892,7 @@ function writeArray(state, val, ref) {
891
892
  return true;
892
893
  }
893
894
  function writeDate(state, val) {
894
- state.buf.push("new Date(\"" + val.toISOString() + "\")");
895
+ state.buf.push("new Date(" + +val + ")");
895
896
  return true;
896
897
  }
897
898
  function writeRegExp(state, val) {
@@ -913,9 +914,9 @@ function writeMap(state, val, ref) {
913
914
  state.buf.push("new Map");
914
915
  return true;
915
916
  }
916
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
917
917
  const items = [];
918
918
  let assigns;
919
+ let needsId;
919
920
  let i = 0;
920
921
  if (val.size < 25) {
921
922
  for (let [itemKey, itemValue] of val) {
@@ -927,12 +928,10 @@ function writeMap(state, val, ref) {
927
928
  itemValue = void 0;
928
929
  (assigns ||= []).push("a[" + i + "][1]");
929
930
  }
931
+ needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
930
932
  i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
931
933
  }
932
- if (assigns) state.buf.push("((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map," + arrayRef.id + "=");
933
- else state.buf.push("new Map(" + arrayRef.id + "=");
934
- writeArray(state, items, arrayRef);
935
- state.buf.push(")");
934
+ writeArrayArg(state, ref, items, assigns && "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
936
935
  } else {
937
936
  for (let [itemKey, itemValue] of val) {
938
937
  if (itemKey === val) {
@@ -943,12 +942,10 @@ function writeMap(state, val, ref) {
943
942
  itemValue = 0;
944
943
  (assigns ||= []).push("a[" + (i + 1) + "]");
945
944
  }
945
+ needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
946
946
  i = items.push(itemKey, itemValue);
947
947
  }
948
- if (assigns) state.buf.push("(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(" + arrayRef.id + "=");
949
- else state.buf.push("(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(" + arrayRef.id + "=");
950
- writeArray(state, items, arrayRef);
951
- state.buf.push(")");
948
+ writeArrayArg(state, ref, items, assigns && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
952
949
  }
953
950
  return true;
954
951
  }
@@ -959,20 +956,38 @@ function writeSet(state, val, ref) {
959
956
  }
960
957
  const items = [];
961
958
  let assigns;
959
+ let needsId;
962
960
  let i = 0;
963
961
  for (let item of val) {
964
962
  if (item === val) {
965
963
  item = 0;
966
964
  (assigns ||= []).push("i[" + i + "]");
967
- }
965
+ } else needsId ||= isDedupedMember(item);
968
966
  i = items.push(item);
969
967
  }
970
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
971
- state.buf.push((assigns ? "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set," : "new Set(") + arrayRef.id + "=");
972
- writeArray(state, items, arrayRef);
973
- state.buf.push(")");
968
+ writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
974
969
  return true;
975
970
  }
971
+ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
972
+ if (assignsPrefix || needsId) {
973
+ const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
974
+ state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "=");
975
+ writeArray(state, items, arrayRef);
976
+ } else {
977
+ state.buf.push(plainPrefix);
978
+ writeArray(state, items, new Reference(ref, null, state.flush, state.buf.length));
979
+ }
980
+ state.buf.push(")");
981
+ }
982
+ function isDedupedMember(val) {
983
+ switch (typeof val) {
984
+ case "object": return val !== null;
985
+ case "function":
986
+ case "symbol": return true;
987
+ case "string": return val.length > STRING_DEDUP_LENGTH;
988
+ default: return false;
989
+ }
990
+ }
976
991
  function writeArrayBuffer(state, val) {
977
992
  let result;
978
993
  if (val.byteLength) {
@@ -1205,22 +1220,16 @@ function writeObjectProps(state, val, ref) {
1205
1220
  else state.buf.pop();
1206
1221
  }
1207
1222
  if (hasSymbolIterator(val)) {
1208
- const iterArr = [...val];
1209
- switch (iterArr.length) {
1210
- case 0:
1211
- state.buf.push(sep + "*[Symbol.iterator](){}");
1212
- break;
1213
- case 1:
1214
- state.buf.push(sep + "*[Symbol.iterator](){yield " + (iterArr[0] === val ? "this" : ensureId(state, ref)) + "}");
1215
- break;
1216
- default: {
1217
- const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1218
- state.buf.push(sep + "*[(" + iterRef.id + "=");
1219
- writeArray(state, iterArr, iterRef);
1220
- state.buf.push(",Symbol.iterator)](){yield*" + iterRef.id + "}");
1221
- break;
1222
- }
1223
- }
1223
+ let yieldSelf = "";
1224
+ const iterArr = [];
1225
+ for (const item of val) if (item === val && !(yieldSelf || iterArr.length)) yieldSelf = "yield this;";
1226
+ else iterArr.push(item);
1227
+ if (iterArr.length) {
1228
+ const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1229
+ state.buf.push(sep + "*[(" + iterRef.id + "=");
1230
+ writeArray(state, iterArr, iterRef);
1231
+ state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
1232
+ } else state.buf.push(sep + "*[Symbol.iterator](){" + yieldSelf.slice(0, -1) + "}");
1224
1233
  sep = ",";
1225
1234
  }
1226
1235
  return sep;
@@ -1514,7 +1523,7 @@ function _serialize_if(condition, key) {
1514
1523
  return condition && (condition === 1 || condition[key]) ? 1 : void 0;
1515
1524
  }
1516
1525
  function _serialize_guard(condition, key) {
1517
- return condition && (condition === 1 || condition[key]) ? 1 : 0;
1526
+ return _serialize_if(condition, key) || 0;
1518
1527
  }
1519
1528
  function _el_resume(scopeId, accessor, shouldResume) {
1520
1529
  if (shouldResume === 0) return "";
@@ -1549,127 +1558,58 @@ function withIsAsync(cb, value) {
1549
1558
  return withContext(kIsAsync, true, cb, value);
1550
1559
  }
1551
1560
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1552
- const { state } = $chunk.boundary;
1553
- const resumeKeys = serializeMarker !== 0;
1554
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1555
- let flushBranchIds = "";
1556
- if (serializeBranch !== 0) {
1557
- let loopScopes;
1558
- var seenKeys = /* @__PURE__ */ new Set();
1559
- forOf(list, (item, index) => {
1560
- const branchId = _peek_scope_id();
1561
- const itemKey = forOfBy(by, item, index);
1562
- if (by) {
1563
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1564
- seenKeys.add(itemKey);
1565
- }
1566
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1567
- else {
1568
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1569
- flushBranchIds = branchId + "";
1570
- }
1571
- withBranchId(branchId, () => {
1572
- cb(item, index);
1573
- const branchScope = writeScope(branchId, {});
1574
- if (resumeKeys && itemKey !== index) branchScope["#LoopKey"] = itemKey;
1575
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1576
- });
1577
- });
1578
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1579
- } else forOf(list, cb);
1580
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1561
+ forBranches(by, (each) => each ? forOf(list, (item, index) => {
1562
+ const itemKey = forOfBy(by, item, index);
1563
+ each(itemKey, itemKey === index, () => cb(item, index));
1564
+ }) : forOf(list, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1581
1565
  }
1582
1566
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1583
- const { state } = $chunk.boundary;
1584
- const resumeKeys = serializeMarker !== 0;
1585
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1586
- let flushBranchIds = "";
1587
- if (serializeBranch !== 0) {
1588
- let loopScopes;
1589
- var seenKeys = /* @__PURE__ */ new Set();
1590
- forIn(obj, (key, value) => {
1591
- const branchId = _peek_scope_id();
1592
- const itemKey = forInBy(by, key, value);
1593
- if (by) {
1594
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1595
- seenKeys.add(itemKey);
1596
- }
1597
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1598
- else {
1599
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1600
- flushBranchIds = branchId + "";
1601
- }
1602
- withBranchId(branchId, () => {
1603
- cb(key, value);
1604
- const branchScope = writeScope(branchId, {});
1605
- if (resumeKeys) branchScope["#LoopKey"] = itemKey;
1606
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1607
- });
1608
- });
1609
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1610
- } else forIn(obj, cb);
1611
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1567
+ forBranches(by, (each) => each ? forIn(obj, (key, value) => {
1568
+ each(forInBy(by, key, value), false, () => cb(key, value));
1569
+ }) : forIn(obj, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1612
1570
  }
1613
1571
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1614
- const { state } = $chunk.boundary;
1615
- const resumeKeys = serializeMarker !== 0;
1616
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1617
- let flushBranchIds = "";
1618
- if (serializeBranch !== 0) {
1619
- let loopScopes;
1620
- var seenKeys = /* @__PURE__ */ new Set();
1621
- forTo(to, from, step, (i) => {
1622
- const branchId = _peek_scope_id();
1623
- const itemKey = forStepBy(by, i);
1624
- if (by) {
1625
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1626
- seenKeys.add(itemKey);
1627
- }
1628
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1629
- else {
1630
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1631
- flushBranchIds = branchId + "";
1632
- }
1633
- withBranchId(branchId, () => {
1634
- cb(i);
1635
- const branchScope = writeScope(branchId, {});
1636
- if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
1637
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1638
- });
1639
- });
1640
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1641
- } else forTo(to, from, step, cb);
1642
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1572
+ forBranches(by, (each) => each ? forTo(to, from, step, (i) => {
1573
+ const itemKey = forStepBy(by, i);
1574
+ each(itemKey, itemKey === i, () => cb(i));
1575
+ }) : forTo(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1643
1576
  }
1644
1577
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1578
+ forBranches(by, (each) => each ? forUntil(to, from, step, (i) => {
1579
+ const itemKey = forStepBy(by, i);
1580
+ each(itemKey, itemKey === i, () => cb(i));
1581
+ }) : forUntil(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1582
+ }
1583
+ function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1584
+ if (serializeBranch === 0) {
1585
+ iterate(0);
1586
+ writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, "");
1587
+ return;
1588
+ }
1645
1589
  const { state } = $chunk.boundary;
1646
1590
  const resumeKeys = serializeMarker !== 0;
1647
1591
  const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1648
1592
  let flushBranchIds = "";
1649
- if (serializeBranch !== 0) {
1650
- let loopScopes;
1651
- var seenKeys = /* @__PURE__ */ new Set();
1652
- forUntil(to, from, step, (i) => {
1653
- const branchId = _peek_scope_id();
1654
- const itemKey = forStepBy(by, i);
1655
- if (by) {
1656
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1657
- seenKeys.add(itemKey);
1658
- }
1659
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1660
- else {
1661
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1662
- flushBranchIds = branchId + "";
1663
- }
1664
- withBranchId(branchId, () => {
1665
- cb(i);
1666
- const branchScope = writeScope(branchId, {});
1667
- if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
1668
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1669
- });
1593
+ let loopScopes;
1594
+ var seenKeys = /* @__PURE__ */ new Set();
1595
+ iterate((itemKey, sameAsIndex, render) => {
1596
+ const branchId = _peek_scope_id();
1597
+ if (by) {
1598
+ if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1599
+ seenKeys.add(itemKey);
1600
+ }
1601
+ if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1602
+ else {
1603
+ $chunk.writeHTML(state.mark("[", flushBranchIds));
1604
+ flushBranchIds = branchId + "";
1605
+ }
1606
+ withBranchId(branchId, () => {
1607
+ render();
1608
+ const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { ["#LoopKey"]: itemKey } : {});
1609
+ if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1670
1610
  });
1671
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1672
- } else forUntil(to, from, step, cb);
1611
+ });
1612
+ if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1673
1613
  writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1674
1614
  }
1675
1615
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
@@ -18,5 +18,6 @@ export declare function queueEffect<S extends Scope, T extends ExecFn<S>>(scope:
18
18
  export declare function run(): void;
19
19
  export declare function prepareEffects(fn: () => void): unknown[];
20
20
  export declare let runEffects: (effects: unknown[], checkPending?: boolean | 1) => void;
21
+ export declare function skipDestroyedRenders(): void;
21
22
  export declare function _enable_catch(): void;
22
23
  export {};
@@ -1,7 +1,8 @@
1
1
  import { type Accessor, AccessorProp, type EncodedAccessor, type Scope } from "../common/types";
2
2
  export type SignalFn = (scope: Scope) => void;
3
- export type Signal<T> = (scope: Scope, value: T) => void;
4
- export declare function _let<T>(id: EncodedAccessor, fn?: SignalFn): (scope: Scope, value: T, valueChange?: (v: T) => void) => T;
3
+ export type Signal<T = unknown, U extends Scope = Scope> = (scope: U, value: T) => void;
4
+ export declare function _let<T>(id: EncodedAccessor, fn?: SignalFn): (scope: Scope, value: T) => T;
5
+ export declare function _let_change<T>(id: EncodedAccessor, fn?: SignalFn): (scope: Scope, value: T, valueChange?: (v: T) => void) => T;
5
6
  export declare function _const<T>(valueAccessor: EncodedAccessor, fn?: SignalFn): Signal<T>;
6
7
  export declare function _or(id: number, fn: SignalFn, defaultPending?: number, scopeIdAccessor?: EncodedAccessor): Signal<never>;
7
8
  export declare function _for_closure(ownerLoopNodeAccessor: EncodedAccessor, fn: SignalFn): SignalFn;
@@ -15,7 +16,7 @@ export declare function _closure_get(valueAccessor: EncodedAccessor, fn: SignalF
15
16
  };
16
17
  export declare function _child_setup(setup: Signal<never> & {
17
18
  _: Signal<Scope>;
18
- }): Signal<never> & {
19
+ }): Signal<never, Scope> & {
19
20
  _: Signal<Scope>;
20
21
  };
21
22
  export declare function _var(scope: Scope, childAccessor: EncodedAccessor, signal: Signal<unknown>): void;
package/dist/dom.d.ts CHANGED
@@ -11,5 +11,5 @@ export { _on } from "./dom/event";
11
11
  export { _enable_catch, run } from "./dom/queue";
12
12
  export { _content, _content_closures, _content_resume } from "./dom/renderer";
13
13
  export { _el, _resume, _var_resume, init, initEmbedded } from "./dom/resume";
14
- export { _child_setup, _closure, _closure_get, _const, _el_read, _for_closure, _hoist, _hoist_resume, _id, _if_closure, _let, _or, _return, _return_change, _script, _var, _var_change, } from "./dom/signals";
14
+ export { _child_setup, _closure, _closure_get, _const, _el_read, _for_closure, _hoist, _hoist_resume, _id, _if_closure, _let, _let_change, _or, _return, _return_change, _script, _var, _var_change, } from "./dom/signals";
15
15
  export { _template } from "./dom/template";
package/dist/dom.js CHANGED
@@ -249,7 +249,7 @@ function schedule() {
249
249
  isScheduled || (isScheduled = 1, queueMicrotask(flushAndWaitFrame));
250
250
  }
251
251
  function flushAndWaitFrame() {
252
- run(), requestAnimationFrame(triggerMacroTask);
252
+ requestAnimationFrame(triggerMacroTask), run();
253
253
  }
254
254
  function triggerMacroTask() {
255
255
  channel || (channel = new MessageChannel(), channel.port1.onmessage = () => {
@@ -259,13 +259,17 @@ function triggerMacroTask() {
259
259
  //#endregion
260
260
  //#region src/dom/signals.ts
261
261
  function _let(id, fn) {
262
- let valueAccessor = decodeAccessor(id), valueChangeAccessor = "M" + valueAccessor;
263
- return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.H) && (scope[valueAccessor] = value, fn?.(scope)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : scope[valueAccessor] !== (scope[valueAccessor] = value) && fn && (schedule(), queueRender(scope, fn, id)), value);
262
+ let valueAccessor = decodeAccessor(id);
263
+ return (scope, value) => (rendering ? scope.H && (scope[valueAccessor] = value, fn?.(scope)) : (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn) && (schedule(), queueRender(scope, fn, id)), value);
264
+ }
265
+ function _let_change(id, fn) {
266
+ let valueAccessor = decodeAccessor(id), valueChangeAccessor = "M" + valueAccessor, base = _let(id, fn);
267
+ return (scope, value, valueChange) => (rendering ? (scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope)) ? (scope[valueAccessor] = value, fn?.(scope)) : base(scope, value) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : base(scope, value), value);
264
268
  }
265
269
  function _const(valueAccessor, fn) {
266
- return valueAccessor = decodeAccessor(valueAccessor), (scope, value) => {
267
- (scope.H || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn?.(scope));
268
- };
270
+ return valueAccessor = decodeAccessor(valueAccessor), ((scope, value) => {
271
+ (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn?.(scope));
272
+ });
269
273
  }
270
274
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "L") {
271
275
  return scopeIdAccessor !== "L" && (scopeIdAccessor = decodeAccessor(scopeIdAccessor)), (scope) => {
@@ -406,7 +410,7 @@ function createCloneableHTML(html, ns) {
406
410
  //#endregion
407
411
  //#region src/dom/resume.ts
408
412
  function enableBranches() {
409
- branchesEnabled = 1;
413
+ branchesEnabled || (branchesEnabled = 1, skipDestroyedRenders());
410
414
  }
411
415
  function initEmbedded(readyId, runtimeId) {
412
416
  embedEnabled = 1, ready(readyId), init(runtimeId), new MutationObserver(() => {
@@ -1014,11 +1018,16 @@ function runRenders() {
1014
1018
  }
1015
1019
  pendingRenders[i] = item;
1016
1020
  }
1017
- render.b.F?.I || runRender(render);
1021
+ runRender(render);
1018
1022
  }
1019
1023
  for (let scope of pendingScopes) scope.H = 0;
1020
1024
  pendingScopes = [];
1021
1025
  }
1026
+ function skipDestroyedRenders() {
1027
+ runRender = ((runRender) => (render) => {
1028
+ render.b.F?.I || runRender(render);
1029
+ })(runRender);
1030
+ }
1022
1031
  function _enable_catch() {
1023
1032
  if (!catchEnabled) {
1024
1033
  catchEnabled = 1, enableBranches();
@@ -1112,4 +1121,4 @@ exports.$signal = $signal, exports.$signalReset = $signalReset, exports._assert_
1112
1121
  get: function() {
1113
1122
  return _dynamic_tag;
1114
1123
  }
1115
- }), exports._el = _el, exports._el_read = _el_read, exports._enable_catch = _enable_catch, exports._for_closure = _for_closure, exports._for_in = _for_in, exports._for_of = _for_of, exports._for_to = _for_to, exports._for_until = _for_until, exports._hoist = _hoist, exports._hoist_resume = _hoist_resume, exports._html = _html, exports._id = _id, exports._if = _if, exports._if_closure = _if_closure, exports._let = _let, exports._lifecycle = _lifecycle, exports._on = _on, exports._or = _or, exports._resume = _resume, exports._resume_dynamic_tag = _resume_dynamic_tag, exports._return = _return, exports._return_change = _return_change, exports._script = _script, exports._template = _template, exports._text = _text, exports._text_content = _text_content, exports._to_text = _to_text, exports._try = _try, exports._var = _var, exports._var_change = _var_change, exports._var_resume = _var_resume, exports.attrTag = attrTag, exports.attrTags = attrTags, exports.compat = compat, exports.forIn = forIn, exports.forOf = forOf, exports.forTo = forTo, exports.forUntil = forUntil, exports.init = init, exports.initEmbedded = initEmbedded, exports.run = run;
1124
+ }), exports._el = _el, exports._el_read = _el_read, exports._enable_catch = _enable_catch, exports._for_closure = _for_closure, exports._for_in = _for_in, exports._for_of = _for_of, exports._for_to = _for_to, exports._for_until = _for_until, exports._hoist = _hoist, exports._hoist_resume = _hoist_resume, exports._html = _html, exports._id = _id, exports._if = _if, exports._if_closure = _if_closure, exports._let = _let, exports._let_change = _let_change, exports._lifecycle = _lifecycle, exports._on = _on, exports._or = _or, exports._resume = _resume, exports._resume_dynamic_tag = _resume_dynamic_tag, exports._return = _return, exports._return_change = _return_change, exports._script = _script, exports._template = _template, exports._text = _text, exports._text_content = _text_content, exports._to_text = _to_text, exports._try = _try, exports._var = _var, exports._var_change = _var_change, exports._var_resume = _var_resume, exports.attrTag = attrTag, exports.attrTags = attrTags, exports.compat = compat, exports.forIn = forIn, exports.forOf = forOf, exports.forTo = forTo, exports.forUntil = forUntil, exports.init = init, exports.initEmbedded = initEmbedded, exports.run = run;
package/dist/dom.mjs CHANGED
@@ -248,7 +248,7 @@ function schedule() {
248
248
  isScheduled || (isScheduled = 1, queueMicrotask(flushAndWaitFrame));
249
249
  }
250
250
  function flushAndWaitFrame() {
251
- run(), requestAnimationFrame(triggerMacroTask);
251
+ requestAnimationFrame(triggerMacroTask), run();
252
252
  }
253
253
  function triggerMacroTask() {
254
254
  channel || (channel = new MessageChannel(), channel.port1.onmessage = () => {
@@ -258,13 +258,17 @@ function triggerMacroTask() {
258
258
  //#endregion
259
259
  //#region src/dom/signals.ts
260
260
  function _let(id, fn) {
261
- let valueAccessor = decodeAccessor(id), valueChangeAccessor = "M" + valueAccessor;
262
- return (scope, value, valueChange) => (rendering ? ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope.H) && (scope[valueAccessor] = value, fn?.(scope)) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : scope[valueAccessor] !== (scope[valueAccessor] = value) && fn && (schedule(), queueRender(scope, fn, id)), value);
261
+ let valueAccessor = decodeAccessor(id);
262
+ return (scope, value) => (rendering ? scope.H && (scope[valueAccessor] = value, fn?.(scope)) : (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn) && (schedule(), queueRender(scope, fn, id)), value);
263
+ }
264
+ function _let_change(id, fn) {
265
+ let valueAccessor = decodeAccessor(id), valueChangeAccessor = "M" + valueAccessor, base = _let(id, fn);
266
+ return (scope, value, valueChange) => (rendering ? (scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope)) ? (scope[valueAccessor] = value, fn?.(scope)) : base(scope, value) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](value) : base(scope, value), value);
263
267
  }
264
268
  function _const(valueAccessor, fn) {
265
- return valueAccessor = decodeAccessor(valueAccessor), (scope, value) => {
266
- (scope.H || scope[valueAccessor] !== value) && (scope[valueAccessor] = value, fn?.(scope));
267
- };
269
+ return valueAccessor = decodeAccessor(valueAccessor), ((scope, value) => {
270
+ (scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn?.(scope));
271
+ });
268
272
  }
269
273
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "L") {
270
274
  return scopeIdAccessor !== "L" && (scopeIdAccessor = decodeAccessor(scopeIdAccessor)), (scope) => {
@@ -405,7 +409,7 @@ function createCloneableHTML(html, ns) {
405
409
  //#endregion
406
410
  //#region src/dom/resume.ts
407
411
  function enableBranches() {
408
- branchesEnabled = 1;
412
+ branchesEnabled || (branchesEnabled = 1, skipDestroyedRenders());
409
413
  }
410
414
  function initEmbedded(readyId, runtimeId) {
411
415
  embedEnabled = 1, ready(readyId), init(runtimeId), new MutationObserver(() => {
@@ -1013,11 +1017,16 @@ function runRenders() {
1013
1017
  }
1014
1018
  pendingRenders[i] = item;
1015
1019
  }
1016
- render.b.F?.I || runRender(render);
1020
+ runRender(render);
1017
1021
  }
1018
1022
  for (let scope of pendingScopes) scope.H = 0;
1019
1023
  pendingScopes = [];
1020
1024
  }
1025
+ function skipDestroyedRenders() {
1026
+ runRender = ((runRender) => (render) => {
1027
+ render.b.F?.I || runRender(render);
1028
+ })(runRender);
1029
+ }
1021
1030
  function _enable_catch() {
1022
1031
  if (!catchEnabled) {
1023
1032
  catchEnabled = 1, enableBranches();
@@ -1107,4 +1116,4 @@ function mount(input = {}, reference, position) {
1107
1116
  };
1108
1117
  }
1109
1118
  //#endregion
1110
- export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };
1119
+ export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _let_change, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };
@@ -1,2 +1,2 @@
1
- export declare const WALKER_RUNTIME_CODE = "(e=>(self[e]||(self[e]=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}}),self[e]))";
1
+ export declare const WALKER_RUNTIME_CODE = "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))";
2
2
  export declare const REORDER_RUNTIME_CODE = "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector(\"style[\"+e.i+\"]\")||\"\"),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l[\"^\"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})";
@@ -1,2 +1,2 @@
1
- export declare const WALKER_RUNTIME_CODE = "((runtimeId) => (self[runtimeId] || (self[runtimeId] = (\n renderId,\n prefix = runtimeId + renderId,\n prefixLen = prefix.length,\n lookup = {},\n visits = [],\n doc = document,\n walker = doc.createTreeWalker(\n doc,\n 129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,\n ),\n) =>\n doc = (self[runtimeId][renderId] = {\n i: prefix,\n d: doc,\n l: lookup,\n v: visits,\n x() {},\n w(node, op, id) {\n while ((node = walker.nextNode())) {\n doc.x(\n (op =\n (op = node.data) &&\n !op.indexOf(prefix) &&\n ((lookup[(id = op.slice(prefixLen + 1))] = node), op[prefixLen])),\n id,\n node,\n );\n\n if (op > \"#\") {\n visits.push(node);\n }\n }\n },\n })\n), self[runtimeId]))";
1
+ export declare const WALKER_RUNTIME_CODE = "((runtimeId) => (self[runtimeId] ||= (\n renderId,\n prefix = runtimeId + renderId,\n prefixLen = prefix.length,\n lookup = {},\n visits = [],\n doc = document,\n walker = doc.createTreeWalker(\n doc,\n 129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,\n ),\n) =>\n doc = (self[runtimeId][renderId] = {\n i: prefix,\n d: doc,\n l: lookup,\n v: visits,\n x() {},\n w(node, op, id) {\n while ((node = walker.nextNode())) {\n doc.x(\n (op =\n (op = node.data) &&\n !op.indexOf(prefix) &&\n ((lookup[(id = op.slice(prefixLen + 1))] = node), op[prefixLen])),\n id,\n node,\n );\n\n if (op > \"#\") {\n visits.push(node);\n }\n }\n },\n })\n, self[runtimeId]))";
2
2
  export declare const REORDER_RUNTIME_CODE = "((runtime) => {\n if (runtime.j) return;\n let onNextSibling,\n placeholder,\n nextSibling,\n placeholders = runtime.p = {},\n replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);\n runtime.d.head.append(\n runtime.d.querySelector(\"style[\" + runtime.i + \"]\") || \"\"\n );\n runtime.j = {};\n runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {\n if (node == nextSibling) {\n onNextSibling();\n }\n\n if (op == \"#\") {\n (placeholders[id] = placeholder).i++;\n } else if (op == \"!\") {\n if (runtime.l[id] && placeholders[id]) {\n nextSibling = node.nextSibling;\n onNextSibling = () => placeholders[id].c();\n }\n } else if (node.tagName == \"T\" && (id = node.getAttribute(runtime.i))) {\n nextSibling = node.nextSibling;\n onNextSibling = () => {\n node.remove();\n placeholderRoot || replace(id, node);\n placeholder.c();\n };\n placeholder =\n placeholders[id] ||\n (placeholderRoot = placeholders[id] =\n {\n i: runtime.l[id] ? 1 : 2,\n c(start = runtime.l[\"^\" + id]) {\n if (--placeholderRoot.i) return 1;\n for (\n ;\n (nextSibling =\n runtime.l[id].previousSibling || start).remove(),\n start != nextSibling;\n\n );\n replace(id, node);\n },\n });\n // repurpose \"op\" for callbacks ...carefully\n if ((op = runtime.j[id])) {\n placeholderCb = placeholder.c;\n placeholder.c = () => placeholderCb() || op(runtime.r);\n }\n }\n };\n})";