@barefootjs/client 0.33.1 → 0.33.2

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.
@@ -169873,6 +169873,10 @@ var EMPTY_BOUND = new Set;
169873
169873
  var constInitializerCache = new WeakMap;
169874
169874
  var functionInfoExprCache = new WeakMap;
169875
169875
 
169876
+ // ../jsx/src/ir-to-client-js/prop-handling.ts
169877
+ var _localConstantValuesCache = new WeakMap;
169878
+ var _restSpreadNamesCache = new WeakMap;
169879
+
169876
169880
  // ../jsx/src/ir-to-client-js/control-flow/stringify/template-parse.ts
169877
169881
  var SVG_ROOT_TAGS = new Set([
169878
169882
  "svg",
@@ -80,7 +80,33 @@ export interface CreateComponentSlotInfo {
80
80
  /** Slot id in the host (this child's `bf-m` value). */
81
81
  mount: string;
82
82
  }
83
- export declare function createComponent(nameOrDef: string | ComponentDef, props?: Record<string, unknown>, key?: string | number, slot?: CreateComponentSlotInfo, mountAt?: Element | null): HTMLElement;
83
+ /**
84
+ * The `HTMLElement | DocumentFragment` return covers exactly one shape: a
85
+ * BARE call (no `mountAt`, no ambient row-mount point) for a genuine
86
+ * fragment-root component (#2722). Every other combination — a normal
87
+ * component, or a fragment-root one with `mountAt`/row-mount already
88
+ * telling this function where to connect — still returns the real,
89
+ * single `HTMLElement`, unchanged (that element stays the caller-visible
90
+ * proxy even when the fragment root has further sibling roots of its own
91
+ * — #2735 — those travel alongside it, never in place of it). Only the
92
+ * no-known-destination case has no single element to hand back: the
93
+ * fragment root's own `<!--bf-scope:-->` boundary comments PLUS every
94
+ * top-level node the fragment's template rendered — elements, bare text
95
+ * and `<!--bf:sN-->` slot markers alike (`materializeComponent` step 7b)
96
+ * — must travel to wherever the caller inserts the result, and a
97
+ * `DocumentFragment` is the one `Node` a plain `container.appendChild(...)`
98
+ * / `el.replaceWith(...)` moves as a unit without the caller needing to
99
+ * know why.
100
+ *
101
+ * The first overload states that in the type system rather than only here:
102
+ * a call that passes a non-null `mountAt` is telling this function where to
103
+ * connect, so it can only get the real `HTMLElement` back. Callers on that
104
+ * overload need no cast, which is why `upsertChild` (registry.ts) and
105
+ * `upsertChildItem` (qsa-item.ts) assert nothing — the narrowing is the
106
+ * signature's job, not theirs.
107
+ */
108
+ export declare function createComponent(nameOrDef: string | ComponentDef, props: Record<string, unknown>, key: string | number | undefined, slot: CreateComponentSlotInfo | undefined, mountAt: Element): HTMLElement;
109
+ export declare function createComponent(nameOrDef: string | ComponentDef, props?: Record<string, unknown>, key?: string | number, slot?: CreateComponentSlotInfo, mountAt?: Element | null): HTMLElement | DocumentFragment;
84
110
  /**
85
111
  * Render a child component's template to an HTML string.
86
112
  * Used by compiler-generated template functions when a stateless component
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/runtime/component.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAS9C,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAExD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,CAAA;AAsB9F,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,aAAa,GAAG,IAAI,CAI9E;AAQD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAQjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAA;IACd,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAA;CACd;AAED,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;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAI9D;AAaD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,gBAAgB,CAejF"}
@@ -1330,8 +1330,7 @@ function hydrateCommentScope(comment) {
1330
1330
  if (hydratedScopes.has(proxyEl))
1331
1331
  return;
1332
1332
  commentScopeRegistry.set(proxyEl, { commentNode: comment, scopeId });
1333
- const parsed = parseProps(propsJson || null, `comment scope ${scopeId}`);
1334
- const props = parsed[name] ?? {};
1333
+ const props = parseProps(propsJson || null, `comment scope ${scopeId}`);
1335
1334
  runInit(proxyEl, def, props);
1336
1335
  }
1337
1336
  function nextElementSibling2(node) {
@@ -1412,8 +1411,9 @@ function materializeComponent(nameOrDef, props = {}, key, slot, mountAt) {
1412
1411
  });
1413
1412
  const def = getRegisteredDef(name);
1414
1413
  const isCommentWrapper = def?.comment === true;
1414
+ const isFragmentRoot = def?.fragmentRoot === true;
1415
1415
  const derivedScopeId = slot?.parent && slot.mount ? `${slot.parent}_${slot.mount}` : null;
1416
- const scopeId = isCommentWrapper ? null : derivedScopeId ?? `${def?.name ?? name}_${generateId()}`;
1416
+ const scopeId = isCommentWrapper && !isFragmentRoot ? null : derivedScopeId ?? `${def?.name ?? name}_${generateId()}`;
1417
1417
  const prevParentScopeId = _parentScopeId;
1418
1418
  if (scopeId) {
1419
1419
  _parentScopeId = scopeId;
@@ -1426,12 +1426,18 @@ function materializeComponent(nameOrDef, props = {}, key, slot, mountAt) {
1426
1426
  } finally {
1427
1427
  _parentScopeId = prevParentScopeId;
1428
1428
  }
1429
- const element = parseHTML(html.trim()).firstChild;
1429
+ const parsedFragment = parseHTML(html.trim());
1430
+ const roots = isFragmentRoot ? Array.from(parsedFragment.childNodes) : parsedFragment.firstChild ? [parsedFragment.firstChild] : [];
1431
+ const element = isFragmentRoot ? roots.find((node) => node.nodeType === Node.ELEMENT_NODE) : roots[0];
1432
+ if (isFragmentRoot && roots.length > 0 && !element) {
1433
+ console.warn(`[BarefootJS] Fragment-root component ${name} rendered no element root; ` + "a scope needs at least one element to attach to. Wrap the content in an element.");
1434
+ return createPlaceholder(name, key);
1435
+ }
1430
1436
  if (!element) {
1431
1437
  console.warn(`[BarefootJS] Template returned empty HTML for component: ${name}`);
1432
1438
  return createPlaceholder(name, key);
1433
1439
  }
1434
- if (scopeId) {
1440
+ if (scopeId && !isFragmentRoot) {
1435
1441
  element.setAttribute(BF_SCOPE, scopeId);
1436
1442
  }
1437
1443
  if (slot) {
@@ -1442,11 +1448,36 @@ function materializeComponent(nameOrDef, props = {}, key, slot, mountAt) {
1442
1448
  if (key !== undefined) {
1443
1449
  element.setAttribute(BF_KEY, String(key));
1444
1450
  }
1451
+ const fragmentComments = isFragmentRoot && scopeId ? {
1452
+ start: document.createComment(`${BF_SCOPE_COMMENT_PREFIX}${scopeId}`),
1453
+ end: document.createComment(`${BF_SCOPE_COMMENT_END_PREFIX}${scopeId}`)
1454
+ } : null;
1455
+ if (fragmentComments) {
1456
+ commentScopeRegistry.set(element, { commentNode: fragmentComments.start, scopeId });
1457
+ }
1445
1458
  const rootIsDeferredPlaceholder = element.hasAttribute(BF_PLACEHOLDER);
1459
+ let bareFragment = null;
1446
1460
  if (mountAt && !rootIsDeferredPlaceholder) {
1447
- mountAt.replaceWith(element);
1461
+ if (fragmentComments) {
1462
+ mountAt.replaceWith(fragmentComments.start, ...roots, fragmentComments.end);
1463
+ } else {
1464
+ mountAt.replaceWith(element);
1465
+ }
1448
1466
  } else if (rowMount && !rootIsDeferredPlaceholder) {
1449
- rowMount.container.insertBefore(element, rowMount.anchor);
1467
+ if (fragmentComments) {
1468
+ rowMount.container.insertBefore(fragmentComments.start, rowMount.anchor);
1469
+ rowMount.container.insertBefore(element, rowMount.anchor);
1470
+ rowMount.container.insertBefore(fragmentComments.end, rowMount.anchor);
1471
+ element.__bfScopeComments = fragmentComments;
1472
+ if (roots.length > 1) {
1473
+ console.warn(`[BarefootJS] Fragment-root component ${name} used as a loop row renders ` + `${roots.length} top-level nodes; only the first element is connected here. ` + "See https://github.com/piconic-ai/barefootjs/issues/2733");
1474
+ }
1475
+ } else {
1476
+ rowMount.container.insertBefore(element, rowMount.anchor);
1477
+ }
1478
+ } else if (fragmentComments && !rootIsDeferredPlaceholder) {
1479
+ bareFragment = document.createDocumentFragment();
1480
+ bareFragment.append(fragmentComments.start, ...roots, fragmentComments.end);
1450
1481
  }
1451
1482
  const prevScope = setCurrentScope(element);
1452
1483
  let placeholderWrapper = null;
@@ -1474,18 +1505,30 @@ function materializeComponent(nameOrDef, props = {}, key, slot, mountAt) {
1474
1505
  }
1475
1506
  setCurrentScope(prevScope);
1476
1507
  hydratedScopes.add(element);
1477
- return element;
1508
+ return bareFragment ?? element;
1509
+ }
1510
+ var FIRST_TAG_PATTERN = /<([a-zA-Z][^\s/>]*)/;
1511
+ var TAG_HEAD_PATTERN = /^(<[a-zA-Z][^\s/>]*)/;
1512
+ function spliceAttrsAfterFirstTag(html, attrs) {
1513
+ const firstElMatch = html.match(FIRST_TAG_PATTERN);
1514
+ if (!firstElMatch)
1515
+ return html;
1516
+ const insertPos = firstElMatch.index;
1517
+ return html.slice(0, insertPos) + html.slice(insertPos).replace(TAG_HEAD_PATTERN, `$1${attrs}`);
1478
1518
  }
1479
1519
  function renderChild(name, props, key, slotSuffix) {
1480
1520
  const templateFn = getTemplate(name);
1481
1521
  const suffix = slotSuffix ? `_${slotSuffix}` : "";
1482
- const displayName = getRegisteredDef(name)?.name ?? name;
1522
+ const def = getRegisteredDef(name);
1523
+ const displayName = def?.name ?? name;
1524
+ const isFragmentRoot = def?.fragmentRoot === true;
1483
1525
  const scopePrefix = _parentScopeId && slotSuffix ? _parentScopeId : `${displayName}_${generateId()}`;
1526
+ const scopeId = `${scopePrefix}${suffix}`;
1484
1527
  const keyAttr = key !== undefined ? ` ${BF_KEY}="${key}"` : "";
1485
1528
  const slotAttrs = _parentScopeId && slotSuffix ? ` ${BF_HOST}="${_parentScopeId}" ${BF_AT}="${slotSuffix}"` : "";
1486
- const bfsAttr = `${BF_SCOPE}="${scopePrefix}${suffix}"`;
1529
+ const bfsAttr = `${BF_SCOPE}="${scopeId}"`;
1487
1530
  if (!templateFn) {
1488
- return `<div ${bfsAttr}${slotAttrs}${keyAttr}></div>`;
1531
+ return isFragmentRoot ? `<!--${BF_SCOPE_COMMENT_PREFIX}${scopeId}--><div></div><!--${BF_SCOPE_COMMENT_END_PREFIX}${scopeId}-->` : `<div ${bfsAttr}${slotAttrs}${keyAttr}></div>`;
1489
1532
  }
1490
1533
  const prevParentScopeId = _parentScopeId;
1491
1534
  _parentScopeId = `${scopePrefix}${suffix}`;
@@ -1496,7 +1539,12 @@ function renderChild(name, props, key, slotSuffix) {
1496
1539
  _parentScopeId = prevParentScopeId;
1497
1540
  }
1498
1541
  let html = raw.trim().replace(PLACEHOLDER_ATTR_PATTERN, _parentScopeId ? ` bf-s="${_parentScopeId}"` : "");
1499
- const firstElMatch = html.match(/<(\w+)/);
1542
+ if (isFragmentRoot) {
1543
+ const hostSuffix = _parentScopeId && slotSuffix ? `|h=${_parentScopeId}|m=${slotSuffix}` : "";
1544
+ const keyedHtml = keyAttr ? spliceAttrsAfterFirstTag(html, keyAttr) : html;
1545
+ return `<!--${BF_SCOPE_COMMENT_PREFIX}${scopeId}${hostSuffix}-->${keyedHtml}<!--${BF_SCOPE_COMMENT_END_PREFIX}${scopeId}-->`;
1546
+ }
1547
+ const firstElMatch = html.match(FIRST_TAG_PATTERN);
1500
1548
  if (!firstElMatch)
1501
1549
  return html;
1502
1550
  const insertPos = firstElMatch.index;
@@ -1505,9 +1553,9 @@ function renderChild(name, props, key, slotSuffix) {
1505
1553
  if (ROOT_HAS_BFS_PATTERN.test(afterInsert)) {
1506
1554
  if (!extraAttrs)
1507
1555
  return html;
1508
- return html.slice(0, insertPos) + afterInsert.replace(/^(<\w+)/, `$1${extraAttrs}`);
1556
+ return html.slice(0, insertPos) + afterInsert.replace(TAG_HEAD_PATTERN, `$1${extraAttrs}`);
1509
1557
  }
1510
- return html.slice(0, insertPos) + afterInsert.replace(/^(<\w+)/, `$1 ${bfsAttr}${extraAttrs}`);
1558
+ return html.slice(0, insertPos) + afterInsert.replace(TAG_HEAD_PATTERN, `$1 ${bfsAttr}${extraAttrs}`);
1511
1559
  }
1512
1560
  var PLACEHOLDER_ATTR_PATTERN = new RegExp(`\\s+bf-s="${BF_PARENT_SCOPE_PLACEHOLDER}"`, "g");
1513
1561
  var ROOT_HAS_BFS_PATTERN = /^<\w+[^>]*\sbf-s="/;
@@ -1838,6 +1886,11 @@ function upsertChildItem(primaryEl, name, slotId, props, key, anchorScope) {
1838
1886
  }
1839
1887
  // src/runtime/map-array.ts
1840
1888
  import { createSignal, createEffect, createRoot as createRoot2 } from "@barefootjs/client/reactive";
1889
+ function scopeIdOf(start) {
1890
+ const rest = (start.nodeValue ?? "").slice(BF_SCOPE_COMMENT_PREFIX.length);
1891
+ const pipe = rest.indexOf("|");
1892
+ return pipe >= 0 ? rest.slice(0, pipe) : rest;
1893
+ }
1841
1894
  function findLoopMarkers2(container, markerId) {
1842
1895
  let start = null;
1843
1896
  let end = null;
@@ -1875,31 +1928,55 @@ function findItemRanges(start, end) {
1875
1928
  const ranges = [];
1876
1929
  let current = null;
1877
1930
  let sawItemMarker = false;
1931
+ let pendingScopeStart = null;
1932
+ let openScopeComments = null;
1878
1933
  let node = start.nextSibling;
1879
1934
  while (node && node !== end) {
1880
- if (node.nodeType === Node.COMMENT_NODE && node.nodeValue === BF_LOOP_ITEM) {
1881
- sawItemMarker = true;
1882
- current = { startMarker: node, primaryEl: null, extras: [] };
1883
- ranges.push(current);
1935
+ if (node.nodeType === Node.COMMENT_NODE) {
1936
+ const value = node.nodeValue ?? "";
1937
+ if (value === BF_LOOP_ITEM) {
1938
+ sawItemMarker = true;
1939
+ current = { startMarker: node, primaryEl: null, extras: [], scopeComments: null };
1940
+ ranges.push(current);
1941
+ } else if (value.startsWith(BF_SCOPE_COMMENT_PREFIX)) {
1942
+ pendingScopeStart = node;
1943
+ } else if (openScopeComments && value === BF_SCOPE_COMMENT_END_PREFIX + scopeIdOf(openScopeComments.start)) {
1944
+ openScopeComments.end = node;
1945
+ openScopeComments = null;
1946
+ }
1884
1947
  } else if (node.nodeType === Node.ELEMENT_NODE) {
1885
1948
  const el = node;
1949
+ let scopeComments = null;
1950
+ if (pendingScopeStart) {
1951
+ scopeComments = { start: pendingScopeStart, end: null };
1952
+ openScopeComments = scopeComments;
1953
+ pendingScopeStart = null;
1954
+ }
1886
1955
  if (sawItemMarker) {
1887
- if (!current.primaryEl)
1956
+ if (!current.primaryEl) {
1888
1957
  current.primaryEl = el;
1889
- else
1958
+ current.scopeComments = scopeComments;
1959
+ } else
1890
1960
  current.extras.push(el);
1891
1961
  } else {
1892
- ranges.push({ startMarker: null, primaryEl: el, extras: [] });
1962
+ ranges.push({ startMarker: null, primaryEl: el, extras: [], scopeComments });
1893
1963
  }
1894
1964
  }
1895
1965
  node = node.nextSibling;
1896
1966
  }
1897
- return ranges.filter((r) => r.primaryEl !== null);
1967
+ return ranges.filter((r) => r.primaryEl !== null).map((r) => ({
1968
+ ...r,
1969
+ scopeComments: r.scopeComments?.end ? r.scopeComments : null
1970
+ }));
1898
1971
  }
1899
1972
  function insertScope(scope, target, anchor) {
1900
1973
  if (scope.startMarker)
1901
1974
  target.insertBefore(scope.startMarker, anchor);
1975
+ if (scope.scopeComments)
1976
+ target.insertBefore(scope.scopeComments.start, anchor);
1902
1977
  target.insertBefore(scope.primaryEl, anchor);
1978
+ if (scope.scopeComments)
1979
+ target.insertBefore(scope.scopeComments.end, anchor);
1903
1980
  for (const ex of scope.extras)
1904
1981
  target.insertBefore(ex, anchor);
1905
1982
  }
@@ -1938,19 +2015,24 @@ function longestIncreasingSubsequenceIndices(arr) {
1938
2015
  function removeScope(scope) {
1939
2016
  if (scope.startMarker?.parentNode)
1940
2017
  scope.startMarker.remove();
2018
+ if (scope.scopeComments?.start.parentNode)
2019
+ scope.scopeComments.start.remove();
1941
2020
  if (scope.primaryEl.parentNode)
1942
2021
  scope.primaryEl.remove();
2022
+ if (scope.scopeComments?.end.parentNode)
2023
+ scope.scopeComments.end.remove();
1943
2024
  for (const ex of scope.extras) {
1944
2025
  if (ex.parentNode)
1945
2026
  ex.remove();
1946
2027
  }
1947
2028
  }
1948
- function createItemScope(item, index, renderItem, existingPrimary, existingExtras, existingStart, rowMount) {
2029
+ function createItemScope(item, index, renderItem, existingPrimary, existingExtras, existingStart, existingScopeComments, rowMount) {
1949
2030
  let primaryEl;
1950
2031
  let dispose;
1951
2032
  let setItem;
1952
2033
  let extras = [];
1953
2034
  let startMarker = null;
2035
+ let scopeComments = null;
1954
2036
  createRoot2((d) => {
1955
2037
  dispose = d;
1956
2038
  const [itemAccessor, itemSetter] = createSignal(item);
@@ -1973,6 +2055,7 @@ function createItemScope(item, index, renderItem, existingPrimary, existingExtra
1973
2055
  if (existingPrimary) {
1974
2056
  extras = existingExtras ?? [];
1975
2057
  startMarker = existingStart ?? null;
2058
+ scopeComments = existingScopeComments ?? null;
1976
2059
  } else {
1977
2060
  const stashed = primaryEl.__bfExtras;
1978
2061
  if (stashed && stashed.length > 0) {
@@ -1980,13 +2063,17 @@ function createItemScope(item, index, renderItem, existingPrimary, existingExtra
1980
2063
  startMarker = document.createComment(BF_LOOP_ITEM);
1981
2064
  }
1982
2065
  delete primaryEl.__bfExtras;
2066
+ const stashedScopeComments = primaryEl.__bfScopeComments;
2067
+ if (stashedScopeComments)
2068
+ scopeComments = stashedScopeComments;
2069
+ delete primaryEl.__bfScopeComments;
1983
2070
  }
1984
2071
  return;
1985
2072
  });
1986
2073
  if (rowMount && !existingPrimary && extras.length > 0 && primaryEl.parentNode) {
1987
2074
  primaryEl.remove();
1988
2075
  }
1989
- return { startMarker, primaryEl, extras, dispose, setItem };
2076
+ return { startMarker, primaryEl, extras, scopeComments, dispose, setItem };
1990
2077
  }
1991
2078
  function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
1992
2079
  if (!container)
@@ -2012,7 +2099,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2012
2099
  const anchor = endMarker ?? null;
2013
2100
  if (!hydrated) {
2014
2101
  hydrated = true;
2015
- const existingRanges = startMarker ? findItemRanges(startMarker, endMarker) : Array.from(container.children).map((el) => ({ startMarker: null, primaryEl: el, extras: [] }));
2102
+ const existingRanges = startMarker ? findItemRanges(startMarker, endMarker) : Array.from(container.children).map((el) => ({ startMarker: null, primaryEl: el, extras: [], scopeComments: null }));
2016
2103
  const needsHydration = existingRanges.length > 0 && (!existingRanges[0]?.primaryEl.hasAttribute("data-key") || scopes.size === 0);
2017
2104
  if (needsHydration) {
2018
2105
  for (let i2 = 0;i2 < existingRanges.length && i2 < items.length; i2++) {
@@ -2020,14 +2107,14 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2020
2107
  const item = items[i2];
2021
2108
  const key = getKey ? getKey(item, i2) : String(i2);
2022
2109
  range.primaryEl.setAttribute(BF_KEY, key);
2023
- const scope = createItemScope(item, i2, renderItem, range.primaryEl, range.extras, range.startMarker);
2110
+ const scope = createItemScope(item, i2, renderItem, range.primaryEl, range.extras, range.startMarker, range.scopeComments);
2024
2111
  scopes.set(key, scope);
2025
2112
  hydratedScopes.add(range.primaryEl);
2026
2113
  }
2027
2114
  for (let i2 = existingRanges.length;i2 < items.length; i2++) {
2028
2115
  const item = items[i2];
2029
2116
  const key = getKey ? getKey(item, i2) : String(i2);
2030
- const scope = createItemScope(item, i2, renderItem, undefined, undefined, undefined, { container, anchor });
2117
+ const scope = createItemScope(item, i2, renderItem, undefined, undefined, undefined, undefined, { container, anchor });
2031
2118
  if (!scope.primaryEl.dataset.key)
2032
2119
  scope.primaryEl.setAttribute(BF_KEY, key);
2033
2120
  scopes.set(key, scope);
@@ -2037,8 +2124,12 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2037
2124
  const range = existingRanges[i2];
2038
2125
  if (range.startMarker?.parentNode)
2039
2126
  range.startMarker.remove();
2127
+ if (range.scopeComments?.start.parentNode)
2128
+ range.scopeComments.start.remove();
2040
2129
  if (range.primaryEl.parentNode)
2041
2130
  range.primaryEl.remove();
2131
+ if (range.scopeComments?.end.parentNode)
2132
+ range.scopeComments.end.remove();
2042
2133
  for (const ex of range.extras) {
2043
2134
  if (ex.parentNode)
2044
2135
  ex.remove();
@@ -2048,7 +2139,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2048
2139
  }
2049
2140
  }
2050
2141
  if (scopes.size === 0) {
2051
- const loopRanges = startMarker ? findItemRanges(startMarker, endMarker) : Array.from(container.children).map((el) => ({ startMarker: null, primaryEl: el, extras: [] }));
2142
+ const loopRanges = startMarker ? findItemRanges(startMarker, endMarker) : Array.from(container.children).map((el) => ({ startMarker: null, primaryEl: el, extras: [], scopeComments: null }));
2052
2143
  for (const range of loopRanges) {
2053
2144
  const existingKey = range.primaryEl.dataset?.key;
2054
2145
  if (existingKey && !scopes.has(existingKey)) {
@@ -2056,6 +2147,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2056
2147
  startMarker: range.startMarker,
2057
2148
  primaryEl: range.primaryEl,
2058
2149
  extras: range.extras,
2150
+ scopeComments: range.scopeComments,
2059
2151
  dispose: () => {},
2060
2152
  setItem: () => {}
2061
2153
  });
@@ -2074,7 +2166,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2074
2166
  } else {
2075
2167
  let expectedNodeCount = 0;
2076
2168
  for (const scope of scopes.values()) {
2077
- expectedNodeCount += 1 + scope.extras.length + (scope.startMarker ? 1 : 0);
2169
+ expectedNodeCount += 1 + scope.extras.length + (scope.startMarker ? 1 : 0) + (scope.scopeComments ? 2 : 0);
2078
2170
  }
2079
2171
  let actualNodeCount = 0;
2080
2172
  for (let node = container.firstChild;node; node = node.nextSibling)
@@ -2106,7 +2198,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2106
2198
  existing.setItem(item);
2107
2199
  desiredOrder.push(existing);
2108
2200
  } else {
2109
- const scope = createItemScope(item, i2, renderItem, undefined, undefined, undefined, { container, anchor });
2201
+ const scope = createItemScope(item, i2, renderItem, undefined, undefined, undefined, undefined, { container, anchor });
2110
2202
  if (!scope.primaryEl.dataset.key)
2111
2203
  scope.primaryEl.setAttribute(BF_KEY, key);
2112
2204
  scopes.set(key, scope);
@@ -2145,7 +2237,7 @@ function mapArray(accessor, container, getKey, renderItem, markerId, bfId) {
2145
2237
  let j = i;
2146
2238
  while (j < desiredOrder.length && !stationary[j])
2147
2239
  j++;
2148
- const before = j < desiredOrder.length ? desiredOrder[j].startMarker ?? desiredOrder[j].primaryEl : anchor;
2240
+ const before = j < desiredOrder.length ? desiredOrder[j].startMarker ?? desiredOrder[j].scopeComments?.start ?? desiredOrder[j].primaryEl : anchor;
2149
2241
  if (j - i === 1) {
2150
2242
  insertScope(desiredOrder[i], container, before);
2151
2243
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"map-array.d.ts","sourceRoot":"","sources":["../../src/runtime/map-array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAqCH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,WAAW,EACtB,QAAQ,CAAC,EAAE,MAAM,GAChB;IAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,CA+BhD;AA8DD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA2B3E;AA2FD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,QAAQ,EAAE,MAAM,CAAC,EAAE,EACn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M,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EACrB,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,GAC3B,WAAW,GAAG,IAAI,CAuBpB"}
1
+ {"version":3,"file":"qsa-item.d.ts","sourceRoot":"","sources":["../../src/runtime/qsa-item.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AA4CH;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAQnF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EACrB,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,GAC3B,WAAW,GAAG,IAAI,CAyBpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/runtime/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAaxC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAclE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,OAAO,GAAG,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