@stencil/core 5.0.0-beta.2 → 5.0.0-beta.20

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.
Files changed (35) hide show
  1. package/dist/app-data/index.d.ts +1 -1
  2. package/dist/{client-BRu0GtRn.mjs → client-CVXS3JZ-.mjs} +105 -60
  3. package/dist/compiler/browser.d.ts +110 -79
  4. package/dist/compiler/browser.js +542 -241
  5. package/dist/compiler/index.d.mts +110 -2
  6. package/dist/compiler/index.mjs +3 -3
  7. package/dist/compiler/utils/index.d.mts +1 -1
  8. package/dist/{compiler-C8yf59oh.mjs → compiler-CUsOl_Kw.mjs} +4428 -2709
  9. package/dist/declarations/stencil-public-compiler.d.ts +144 -120
  10. package/dist/declarations/stencil-public-docs.d.ts +23 -0
  11. package/dist/declarations/stencil-public-runtime.d.ts +60 -58
  12. package/dist/{index-BopBfjPu.d.mts → index-B9-Byy8z.d.mts} +142 -118
  13. package/dist/{index-BXAcVN2j.d.ts → index-BHciXst1.d.ts} +57 -55
  14. package/dist/{index-DmHmu3y0.d.mts → index-Dz1G9pWZ.d.mts} +2 -2
  15. package/dist/index.d.mts +3 -0
  16. package/dist/index.mjs +1 -1
  17. package/dist/jsx-runtime.mjs +1 -1
  18. package/dist/{node-75gQKkFz.mjs → node-Bz2SOK7_.mjs} +6 -35
  19. package/dist/runtime/client/lazy.js +228 -180
  20. package/dist/runtime/client/runtime.d.ts +67 -66
  21. package/dist/runtime/client/runtime.js +228 -180
  22. package/dist/runtime/index.d.ts +4 -5
  23. package/dist/runtime/index.js +226 -178
  24. package/dist/runtime/server/index.d.mts +11 -11
  25. package/dist/runtime/server/index.mjs +287 -220
  26. package/dist/runtime/server/runner.d.mts +4 -4
  27. package/dist/runtime/server/runner.mjs +82 -54
  28. package/dist/signals/index.d.ts +11 -2
  29. package/dist/signals/index.js +11 -1
  30. package/dist/sys/node/index.d.mts +1 -1
  31. package/dist/sys/node/index.mjs +1 -1
  32. package/dist/sys/node/worker.mjs +2 -2
  33. package/dist/testing/index.d.mts +129 -112
  34. package/dist/testing/index.mjs +244 -193
  35. package/package.json +8 -4
@@ -1,11 +1,80 @@
1
1
  import { BUILD } from "../app-data/index.js";
2
2
  import "../app-globals/index.js";
3
- import { effect, effect as effect$1, signal } from "@preact/signals-core";
3
+ import * as SignalsCore from "@preact/signals-core";
4
+ //#region src/runtime/runtime-constants.ts
5
+ /**
6
+ * Bit flags for recording various properties of VDom nodes
7
+ */
8
+ const VNODE_FLAGS = {
9
+ /**
10
+ * Whether or not a vdom node is a slot reference
11
+ */
12
+ isSlotReference: 1,
13
+ /**
14
+ * Whether or not a slot element has fallback content
15
+ */
16
+ isSlotFallback: 2,
17
+ /**
18
+ * Whether or not an element is a host element
19
+ */
20
+ isHost: 4
21
+ };
22
+ const PROXY_FLAGS = {
23
+ isElementConstructor: 1,
24
+ proxyState: 2
25
+ };
26
+ const PLATFORM_FLAGS = {
27
+ /**
28
+ * designates a node in the DOM as being actively moved by the runtime
29
+ */
30
+ isTmpDisconnected: 1,
31
+ appLoaded: 2,
32
+ queueSync: 4,
33
+ queueMask: 6
34
+ };
35
+ /**
36
+ * A (subset) of node types which are relevant for the Stencil runtime. These
37
+ * values are based on the values which can possibly be returned by the
38
+ * `.nodeType` property of a DOM node. See here for details:
39
+ *
40
+ * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
41
+ */
42
+ const NODE_TYPE = {
43
+ ElementNode: 1,
44
+ TextNode: 3,
45
+ CommentNode: 8,
46
+ DocumentNode: 9,
47
+ DocumentTypeNode: 10,
48
+ DocumentFragment: 11
49
+ };
50
+ const HYDRATE_ID = "s-id";
51
+ const HYDRATED_STYLE_ID = "sty-id";
52
+ const HYDRATE_CHILD_ID = "c-id";
53
+ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
54
+ /**
55
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
56
+ *
57
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
58
+ * support as of Stencil v4.
59
+ */
60
+ const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
61
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
62
+ /**
63
+ * Minimum delay, in milliseconds, before retrying a failed lazy component load.
64
+ */
65
+ const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
66
+ const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
67
+ "formAssociatedCallback",
68
+ "formResetCallback",
69
+ "formDisabledCallback",
70
+ "formStateRestoreCallback"
71
+ ];
72
+ //#endregion
4
73
  //#region src/client/client-build.ts
5
74
  const Build = {
6
- isDev: BUILD.isDev,
7
75
  isBrowser: true,
8
76
  isServer: false,
77
+ isDev: BUILD.isDev,
9
78
  isTesting: BUILD.isTesting
10
79
  };
11
80
  const MEMBER_FLAGS = {
@@ -371,78 +440,9 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
371
440
  //#endregion
372
441
  //#region src/client/client-style.ts
373
442
  const styles = /*@__PURE__*/ new Map();
374
- const modeResolutionChain = [];
443
+ const modeResolver = [];
375
444
  const needsScopedSSR = () => false;
376
445
  //#endregion
377
- //#region src/runtime/runtime-constants.ts
378
- /**
379
- * Bit flags for recording various properties of VDom nodes
380
- */
381
- const VNODE_FLAGS = {
382
- /**
383
- * Whether or not a vdom node is a slot reference
384
- */
385
- isSlotReference: 1,
386
- /**
387
- * Whether or not a slot element has fallback content
388
- */
389
- isSlotFallback: 2,
390
- /**
391
- * Whether or not an element is a host element
392
- */
393
- isHost: 4
394
- };
395
- const PROXY_FLAGS = {
396
- isElementConstructor: 1,
397
- proxyState: 2
398
- };
399
- const PLATFORM_FLAGS = {
400
- /**
401
- * designates a node in the DOM as being actively moved by the runtime
402
- */
403
- isTmpDisconnected: 1,
404
- appLoaded: 2,
405
- queueSync: 4,
406
- queueMask: 6
407
- };
408
- /**
409
- * A (subset) of node types which are relevant for the Stencil runtime. These
410
- * values are based on the values which can possibly be returned by the
411
- * `.nodeType` property of a DOM node. See here for details:
412
- *
413
- * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
414
- */
415
- const NODE_TYPE = {
416
- ElementNode: 1,
417
- TextNode: 3,
418
- CommentNode: 8,
419
- DocumentNode: 9,
420
- DocumentTypeNode: 10,
421
- DocumentFragment: 11
422
- };
423
- const HYDRATE_ID = "s-id";
424
- const HYDRATED_STYLE_ID = "sty-id";
425
- const HYDRATE_CHILD_ID = "c-id";
426
- const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
427
- /**
428
- * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
429
- *
430
- * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
431
- * support as of Stencil v4.
432
- */
433
- const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
434
- const XLINK_NS = "http://www.w3.org/1999/xlink";
435
- /**
436
- * Minimum delay, in milliseconds, before retrying a failed lazy component load.
437
- */
438
- const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
439
- const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
440
- "formAssociatedCallback",
441
- "formResetCallback",
442
- "formDisabledCallback",
443
- "formStateRestoreCallback"
444
- ];
445
- //#endregion
446
446
  //#region src/client/client-window.ts
447
447
  const win = typeof window !== "undefined" ? window : {};
448
448
  win.HTMLElement;
@@ -480,7 +480,7 @@ let queuePending = false;
480
480
  const queueDomReads = [];
481
481
  const queueDomWrites = [];
482
482
  const queueDomWritesLow = [];
483
- const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
483
+ const scheduleFlush = () => win.document?.hidden ? setTimeout(flush, 16) : plt.raf(flush);
484
484
  const queueTask = (queue, write) => (cb) => {
485
485
  queue.push(cb);
486
486
  if (!queuePending) {
@@ -1557,6 +1557,13 @@ const isComplexType = (o) => {
1557
1557
  return o === "object" || o === "function";
1558
1558
  };
1559
1559
  //#endregion
1560
+ //#region src/runtime/signals-core.ts
1561
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1562
+ const effect = (fn, options) => getCore().effect(fn, options);
1563
+ function signal(value, options) {
1564
+ return getCore().signal(value, options);
1565
+ }
1566
+ //#endregion
1560
1567
  //#region src/runtime/event-emitter.ts
1561
1568
  const createEvent = (ref, name, flags) => {
1562
1569
  const elm = getElement(ref);
@@ -1589,6 +1596,11 @@ const setRegistry = (registry) => {
1589
1596
  _registry = registry;
1590
1597
  };
1591
1598
  const getRegistry = () => _registry ?? customElements;
1599
+ /**
1600
+ * @param elm a defined component host
1601
+ * @returns the registry the host's class was defined in, else the active registry
1602
+ */
1603
+ const getHostRegistry = (elm) => elm.constructor._registry ?? getRegistry();
1592
1604
  //#endregion
1593
1605
  //#region src/runtime/vdom/set-accessor.ts
1594
1606
  /**
@@ -1632,7 +1644,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1632
1644
  attrMap.get(memberName)?.();
1633
1645
  if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
1634
1646
  let prevVal = oldValue;
1635
- attrMap.set(memberName, effect$1(() => {
1647
+ attrMap.set(memberName, effect(() => {
1636
1648
  const curVal = newValue.value;
1637
1649
  setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
1638
1650
  prevVal = curVal;
@@ -1712,10 +1724,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1712
1724
  const isComplex = isComplexType(newValue);
1713
1725
  if (!BUILD.lazyLoad) {
1714
1726
  const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
1715
- if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
1727
+ if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && !customElements.get(elm.tagName.toLowerCase())) {
1716
1728
  if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
1717
1729
  elm["s-pp"].set(memberName, newValue);
1718
- return;
1730
+ if (isComplex || /[A-Z]/.test(memberName)) return;
1719
1731
  }
1720
1732
  }
1721
1733
  if ((isProp || isComplex && newValue !== null) && !isSvg) try {
@@ -1833,6 +1845,7 @@ function sortedAttrNames(attrNames) {
1833
1845
  let scopeId;
1834
1846
  let contentRef;
1835
1847
  let hostTagName;
1848
+ let hostRegistry;
1836
1849
  let useNativeShadowDom = false;
1837
1850
  let checkSlotFallbackVisibility = false;
1838
1851
  let checkSlotRelocate = false;
@@ -1849,16 +1862,33 @@ const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
1849
1862
  const disposeSignalVNode = (vnode) => {
1850
1863
  const elm = vnode.$elm$;
1851
1864
  if (elm) {
1852
- const dispose = signalNodeDisposers.get(elm);
1853
- if (dispose) {
1854
- dispose();
1855
- signalNodeDisposers.delete(elm);
1856
- }
1865
+ disposeTextSignal(elm);
1857
1866
  disposeAllSignalAttrs(elm);
1858
1867
  }
1859
1868
  vnode.$children$?.forEach(disposeSignalVNode);
1860
1869
  };
1861
1870
  /**
1871
+ * Tear down a text node's signal subscription, if it has one.
1872
+ * @param textNode the text node to unsubscribe
1873
+ */
1874
+ const disposeTextSignal = (textNode) => {
1875
+ const dispose = signalNodeDisposers.get(textNode);
1876
+ if (dispose) {
1877
+ dispose();
1878
+ signalNodeDisposers.delete(textNode);
1879
+ }
1880
+ };
1881
+ /**
1882
+ * Subscribe a text node to a signal, keeping its `data` in sync on every change.
1883
+ * @param textNode the text node to keep in sync
1884
+ * @param textSig the signal to subscribe to
1885
+ */
1886
+ const wireTextSignal = (textNode, textSig) => {
1887
+ signalNodeDisposers.set(textNode, effect(() => {
1888
+ textNode.data = String(textSig.value);
1889
+ }));
1890
+ };
1891
+ /**
1862
1892
  * Create a DOM Node corresponding to one of the children of a given VNode.
1863
1893
  *
1864
1894
  * @param oldParentVNode the parent VNode from the previous render
@@ -1880,13 +1910,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1880
1910
  if (BUILD.isDev && newVNode.$elm$) consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${String(newVNode.$tag$)}" element`} node should not be shared within the same renderer. The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be reused. For more information please see https://stenciljs.com/docs/templating-jsx#avoid-shared-jsx-nodes`);
1881
1911
  if (BUILD.vdomText && newVNode.$text$ != null) {
1882
1912
  elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
1883
- if (BUILD.vdomSignals && newVNode.$signal$) {
1884
- const textSig = newVNode.$signal$;
1885
- const textNode = elm;
1886
- signalNodeDisposers.set(textNode, effect$1(() => {
1887
- textNode.data = String(textSig.value);
1888
- }));
1889
- }
1913
+ if (BUILD.vdomSignals && newVNode.$signal$) wireTextSignal(elm, newVNode.$signal$);
1890
1914
  } else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1891
1915
  elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1892
1916
  if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
@@ -1895,8 +1919,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1895
1919
  if (BUILD.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
1896
1920
  if (!win.document) throw new Error("No DOM environment available for rendering.");
1897
1921
  const tag = !useNativeShadowDom && BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
1898
- const _reg = getRegistry();
1899
- const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
1922
+ const registryOpts = hostRegistry !== win.customElements && tag.includes("-") ? { customElementRegistry: hostRegistry } : void 0;
1900
1923
  elm = newVNode.$elm$ = BUILD.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
1901
1924
  if (BUILD.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
1902
1925
  if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
@@ -2154,7 +2177,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
2154
2177
  }
2155
2178
  if (BUILD.vdomKey && idxInOld >= 0) {
2156
2179
  elmToMove = oldCh[idxInOld];
2157
- if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
2180
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
2158
2181
  else {
2159
2182
  patch(elmToMove, newStartVnode, isInitialRender);
2160
2183
  oldCh[idxInOld] = void 0;
@@ -2247,7 +2270,17 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
2247
2270
  else if (BUILD.hydrateClientSide && isInitialRender && BUILD.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
2248
2271
  if (BUILD.svg && isSvgMode && tag === "svg") isSvgMode = false;
2249
2272
  } else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
2250
- else if (BUILD.vdomText && oldVNode.$text$ !== text) elm.data = text;
2273
+ else if (BUILD.vdomText) {
2274
+ if (BUILD.vdomSignals && newVNode.$signal$) {
2275
+ if (newVNode.$signal$ !== oldVNode.$signal$) {
2276
+ disposeTextSignal(elm);
2277
+ wireTextSignal(elm, newVNode.$signal$);
2278
+ }
2279
+ } else {
2280
+ if (BUILD.vdomSignals && oldVNode.$signal$) disposeTextSignal(elm);
2281
+ if (oldVNode.$text$ !== text) elm.data = text;
2282
+ }
2283
+ }
2251
2284
  };
2252
2285
  /**
2253
2286
  * Component-global information about nodes which are either currently being
@@ -2435,6 +2468,7 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
2435
2468
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
2436
2469
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
2437
2470
  hostTagName = hostElm.tagName;
2471
+ hostRegistry = getHostRegistry(hostElm);
2438
2472
  if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
2439
2473
  Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
2440
2474
 
@@ -2587,11 +2621,12 @@ const markFirstConnected = (hostRef) => {
2587
2621
  * autoloader, where the ancestor tag may not be defined yet.
2588
2622
  *
2589
2623
  * @param ancestorElm the nearest Stencil ancestor element
2624
+ * @param registry the registry the waiting component is defined in
2590
2625
  */
2591
- const awaitAncestorConnected = async (ancestorElm) => {
2626
+ const awaitAncestorConnected = async (ancestorElm, registry) => {
2592
2627
  let ancestorHostRef = getHostRef(ancestorElm);
2593
2628
  if (!BUILD.lazyLoad && !ancestorHostRef) {
2594
- await getRegistry().whenDefined(ancestorElm.tagName.toLowerCase());
2629
+ await registry.whenDefined(ancestorElm.tagName.toLowerCase());
2595
2630
  ancestorHostRef = getHostRef(ancestorElm);
2596
2631
  }
2597
2632
  if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
@@ -2947,8 +2982,7 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2947
2982
  const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2948
2983
  for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
2949
2984
  if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
2950
- const initialVal = hostRef.$instanceValues$.get(memberName);
2951
- const sig = signal(initialVal);
2985
+ const sig = signal(hostRef.$instanceValues$.get(memberName));
2952
2986
  hostRef.$signalValues$.set(memberName, sig);
2953
2987
  let prevScheduleVal = sig.peek();
2954
2988
  disposers.push(effect(() => {
@@ -3076,9 +3110,7 @@ const h = (nodeName, vnodeData, ...children) => {
3076
3110
  if (classData && !(BUILD.vdomSignals && isSignalLike(classData))) vnodeData.class = typeof classData !== "object" ? classData : Object.keys(classData).filter((k) => classData[k]).join(" ");
3077
3111
  }
3078
3112
  }
3079
- if (BUILD.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be the single root component. Make sure:
3080
- - You are NOT using hostData() and <Host> in the same component.
3081
- - <Host> is used once, and it's the single root component of the render() function.`);
3113
+ if (BUILD.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be used once, and be the single root component of the render() function.`);
3082
3114
  if (BUILD.vdomFunctional && typeof nodeName === "function") return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
3083
3115
  const vnode = newVNode(nodeName, null);
3084
3116
  vnode.$attrs$ = vnodeData;
@@ -3854,7 +3886,7 @@ const scopeSelector = (selector, scopeSelectorText, hostSelector, slotSelector)
3854
3886
  else return shallowPart.trim();
3855
3887
  }).join(", ");
3856
3888
  };
3857
- const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer");
3889
+ const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer") || selector.startsWith("@container");
3858
3890
  const scopeSelectors = (cssText, scopeSelectorText, hostSelector, slotSelector, commentOriginalSelector) => {
3859
3891
  return processRules(cssText, (rule) => {
3860
3892
  let selector = rule.selector;
@@ -3973,8 +4005,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
3973
4005
  };
3974
4006
  //#endregion
3975
4007
  //#region src/runtime/mode.ts
3976
- const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
3977
- const setMode = (handler) => modeResolutionChain.push(handler);
4008
+ const computeMode = (elm) => modeResolver.map((h) => h(elm)).find((m) => !!m);
4009
+ const setMode = (handler) => {
4010
+ modeResolver.length = 0;
4011
+ modeResolver.push(handler);
4012
+ };
3978
4013
  const getMode = (ref) => getHostRef(ref)?.$modeName$;
3979
4014
  //#endregion
3980
4015
  //#region src/runtime/normalize-watchers.ts
@@ -4039,23 +4074,14 @@ const normalizeWatchers = (raw) => {
4039
4074
  *
4040
4075
  * @param propValue the new value to coerce to some type
4041
4076
  * @param propType the type of the prop, expressed as a binary number
4042
- * @param isFormAssociated whether the component is form-associated (optional)
4043
4077
  * @returns the parsed/coerced value
4044
4078
  */
4045
- const parsePropertyValue = (propValue, propType, isFormAssociated) => {
4079
+ const parsePropertyValue = (propValue, propType) => {
4046
4080
  if (propValue != null && !isComplexType(propValue)) {
4047
4081
  /**
4048
4082
  * ensure this value is of the correct prop type
4049
4083
  */
4050
- if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) {
4051
- /**
4052
- * For form-associated components, according to HTML spec, the presence of any boolean attribute
4053
- * (regardless of its value, even "false") should make the property true.
4054
- * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
4055
- */
4056
- if (BUILD.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
4057
- else return propValue === "false" ? false : propValue === "" || !!propValue;
4058
- }
4084
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
4059
4085
  /**
4060
4086
  * force it to be a number
4061
4087
  */
@@ -4097,7 +4123,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4097
4123
  if (BUILD.signalBacking) {
4098
4124
  const sig = hostRef?.$signalValues$?.get(propName);
4099
4125
  if (sig !== void 0) {
4100
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4126
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4101
4127
  if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
4102
4128
  const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4103
4129
  applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
@@ -4115,7 +4141,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4115
4141
  const oldVal = hostRef.$instanceValues$.get(propName);
4116
4142
  const flags = hostRef.$flags$;
4117
4143
  const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
4118
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4144
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4119
4145
  const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
4120
4146
  if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
4121
4147
  hostRef.$instanceValues$.set(propName, newVal);
@@ -4164,6 +4190,22 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4164
4190
  */
4165
4191
  const reflectedAttrValue = (propValue) => propValue == null || propValue === false ? null : propValue === true ? "" : String(propValue);
4166
4192
  /**
4193
+ * Hand values written to a lazy component's element before its instance existed to the
4194
+ * instance's own `@Prop` setters. Must run as soon as the instance is constructed, so that
4195
+ * whenever `$lazyInstance$` is set, reads through it agree with the element's last write.
4196
+ *
4197
+ * @param hostRef the runtime bookkeeping object of a freshly constructed lazy instance
4198
+ * @param cmpMeta runtime metadata for the component (with any run-time only setters flagged)
4199
+ */
4200
+ const replayPendingSetterValues = (hostRef, cmpMeta) => {
4201
+ const instance = hostRef.$lazyInstance$;
4202
+ if (!instance) return;
4203
+ for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) if (memberFlags & MEMBER_FLAGS.Setter && hostRef.$instanceValues$.has(memberName)) {
4204
+ const pendingValue = hostRef.$instanceValues$.get(memberName);
4205
+ if (instance[memberName] !== pendingValue) instance[memberName] = pendingValue;
4206
+ }
4207
+ };
4208
+ /**
4167
4209
  * Attach a series of runtime constructs to a compiled Stencil component
4168
4210
  * constructor, including getters and setters for the `@Prop` and `@State`
4169
4211
  * decorators, callbacks for when attributes change, and so on.
@@ -4220,9 +4262,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4220
4262
  if (BUILD.lazyLoad) {
4221
4263
  if ((cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Getter) === 0) return getValue(this, memberName);
4222
4264
  const ref = getHostRef(this);
4223
- const instance = ref ? ref.$lazyInstance$ : prototype;
4224
- if (!instance) return;
4225
- return instance[memberName];
4265
+ if (!ref) return prototype[memberName];
4266
+ return ref.$lazyInstance$ ? ref.$lazyInstance$[memberName] : getValue(this, memberName);
4226
4267
  }
4227
4268
  if (!BUILD.lazyLoad) return origGetter ? origGetter.apply(this) : getValue(this, memberName);
4228
4269
  },
@@ -4237,7 +4278,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4237
4278
  }
4238
4279
  if (origSetter) {
4239
4280
  if (typeof (memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName]) === "undefined" && ref.$instanceValues$.get(memberName)) newValue = ref.$instanceValues$.get(memberName);
4240
- origSetter.apply(this, [parsePropertyValue(newValue, memberFlags, BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated))]);
4281
+ origSetter.apply(this, [parsePropertyValue(newValue, memberFlags)]);
4241
4282
  newValue = memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName];
4242
4283
  setValue(this, memberName, newValue, cmpMeta);
4243
4284
  return;
@@ -4249,21 +4290,15 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4249
4290
  if (BUILD.lazyLoad) {
4250
4291
  if ((flags & PROXY_FLAGS.isElementConstructor) === 0 || (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter) === 0) {
4251
4292
  setValue(this, memberName, newValue, cmpMeta);
4252
- if (flags & PROXY_FLAGS.isElementConstructor && !ref.$lazyInstance$) ref.$fetchedCbList$.push(() => {
4253
- if (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter && ref.$lazyInstance$[memberName] !== ref.$instanceValues$.get(memberName)) ref.$lazyInstance$[memberName] = newValue;
4254
- });
4255
4293
  return;
4256
4294
  }
4257
- const setterSetVal = () => {
4295
+ const parsedValue = parsePropertyValue(newValue, memberFlags);
4296
+ if (ref.$lazyInstance$) {
4258
4297
  const currentValue = ref.$lazyInstance$[memberName];
4259
4298
  if (!ref.$instanceValues$.get(memberName) && currentValue) ref.$instanceValues$.set(memberName, currentValue);
4260
- ref.$lazyInstance$[memberName] = parsePropertyValue(newValue, memberFlags, BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4299
+ ref.$lazyInstance$[memberName] = parsedValue;
4261
4300
  setValue(this, memberName, ref.$lazyInstance$[memberName], cmpMeta);
4262
- };
4263
- if (ref.$lazyInstance$) setterSetVal();
4264
- else ref.$fetchedCbList$.push(() => {
4265
- setterSetVal();
4266
- });
4301
+ } else ref.$instanceValues$.set(memberName, parsedValue);
4267
4302
  }
4268
4303
  } });
4269
4304
  } else if (BUILD.lazyLoad && BUILD.method && flags & PROXY_FLAGS.isElementConstructor && memberFlags & MEMBER_FLAGS.Method) Object.defineProperty(prototype, memberName, { value(...args) {
@@ -4315,7 +4350,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4315
4350
  const isBooleanTarget = propMemberFlags & MEMBER_FLAGS.Boolean;
4316
4351
  if (BUILD.reflect && propMemberFlags & MEMBER_FLAGS.ReflectAttr && propMemberFlags & MEMBER_FLAGS.Any && !isComplexType(this[propName]) && reflectedAttrValue(this[propName]) === newValue) return;
4317
4352
  const isSpuriousBooleanRemoval = isBooleanTarget && newValue === null && this[propName] === void 0;
4318
- if (isBooleanTarget) newValue = !(newValue === null || newValue === "false");
4353
+ if (isBooleanTarget) {
4354
+ if (BUILD.isDev && newValue === "false") consoleDevWarn(`<${cmpMeta.$tagName$} ${attrName}="false">: boolean attributes are true when present, regardless of value. Remove the attribute or set the "${propName}" property to false instead.`);
4355
+ newValue = newValue !== null;
4356
+ }
4319
4357
  const propDesc = Object.getOwnPropertyDescriptor(prototype, propName);
4320
4358
  if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4321
4359
  });
@@ -4378,9 +4416,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4378
4416
  } catch (e) {
4379
4417
  consoleError(e, elm);
4380
4418
  }
4381
- if (BUILD.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4419
+ if (BUILD.member) {
4420
+ hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4421
+ replayPendingSetterValues(hostRef, cmpMeta);
4422
+ }
4382
4423
  endNewInstance();
4383
- if (BUILD.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$);
4424
+ if (BUILD.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(elm));
4384
4425
  if (!(BUILD.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4385
4426
  fireConnectedCallback(hostRef.$lazyInstance$, elm);
4386
4427
  if (BUILD.asyncLoading) markFirstConnected(hostRef);
@@ -4480,9 +4521,16 @@ const connectedCallback = (elm) => {
4480
4521
  }
4481
4522
  if (BUILD.asyncLoading) {
4482
4523
  let ancestorComponent = elm;
4483
- while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) if (BUILD.hydrateClientSide && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id") && ancestorComponent["s-p"] || ancestorComponent["s-p"]) {
4484
- attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4485
- break;
4524
+ while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) {
4525
+ if (BUILD.hydrateClientSide && !ancestorComponent["s-p"] && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id")) {
4526
+ ancestorComponent["s-p"] = [];
4527
+ ancestorComponent["s-rc"] = [];
4528
+ ancestorComponent["s-pc"] = [];
4529
+ }
4530
+ if (ancestorComponent["s-p"]) {
4531
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4532
+ break;
4533
+ }
4486
4534
  }
4487
4535
  }
4488
4536
  if (BUILD.prop && !BUILD.hydrateServerSide && cmpMeta.$members$) Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
@@ -4598,48 +4646,45 @@ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4598
4646
  `${modulePath}?s-hmr=${hmrVersionId}`
4599
4647
  );
4600
4648
  const NewClass = Object.values(newModule).find((v) => typeof v === "function" && v.is === cmpMeta.$tagName$) ?? newModule.default;
4601
- if (!NewClass) return;
4602
- const ctor = customElements.get(cmpMeta.$tagName$);
4603
- if (ctor) {
4604
- for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4605
- if (key === "constructor") continue;
4606
- Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4607
- }
4608
- const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4609
- if (styleDesc) {
4610
- Object.defineProperty(ctor, "style", styleDesc);
4611
- const newStyle = NewClass.style;
4612
- if (newStyle) {
4613
- const scopeId = getScopeId(cmpMeta);
4614
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4615
- console.log("[stencil-hmr] registerStyle", {
4616
- tag: cmpMeta.$tagName$,
4617
- scopeId,
4618
- isShadow,
4619
- cssLen: newStyle.length
4620
- });
4621
- registerStyle(scopeId, newStyle, isShadow);
4622
- }
4623
- }
4624
- }
4625
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4626
- document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4627
- const hostRef = getHostRef(el);
4628
- if (BUILD.hostListener && hostRef?.$rmListeners$) {
4629
- hostRef.$rmListeners$.map((rmListener) => rmListener());
4630
- hostRef.$rmListeners$ = void 0;
4631
- addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4632
- }
4633
- if (!isShadow && hostRef) {
4634
- console.log("[stencil-hmr] calling attachStyles for", cmpMeta.$tagName$);
4635
- attachStyles(hostRef);
4636
- }
4637
- forceUpdate(el);
4638
- });
4649
+ if (NewClass) hmrApplyClass(cmpMeta, NewClass);
4639
4650
  } catch (e) {
4640
4651
  console.error(`[Stencil HMR] Failed to reload <${cmpMeta.$tagName$}>`, e);
4641
4652
  }
4642
4653
  };
4654
+ /**
4655
+ * Patch a re-executed component class onto the registered one and re-render every live instance.
4656
+ * Shared by the standalone re-import above and bundlers that re-execute the module themselves
4657
+ * (webpack/rspack `module.hot`), which reach it via the constructor's `s-hmr-apply` hook.
4658
+ *
4659
+ * @param cmpMeta runtime metadata for the component
4660
+ * @param NewClass the component's newly executed class
4661
+ */
4662
+ const hmrApplyClass = (cmpMeta, NewClass) => {
4663
+ const ctor = customElements.get(cmpMeta.$tagName$);
4664
+ const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4665
+ if (ctor && ctor !== NewClass) {
4666
+ for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4667
+ if (key === "constructor") continue;
4668
+ Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4669
+ }
4670
+ const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4671
+ if (styleDesc) {
4672
+ Object.defineProperty(ctor, "style", styleDesc);
4673
+ const newStyle = NewClass.style;
4674
+ if (newStyle) registerStyle(getScopeId(cmpMeta), newStyle, isShadow);
4675
+ }
4676
+ }
4677
+ document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4678
+ const hostRef = getHostRef(el);
4679
+ if (BUILD.hostListener && hostRef?.$rmListeners$) {
4680
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4681
+ hostRef.$rmListeners$ = void 0;
4682
+ addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4683
+ }
4684
+ if (!isShadow && hostRef) attachStyles(hostRef);
4685
+ forceUpdate(el);
4686
+ });
4687
+ };
4643
4688
  //#endregion
4644
4689
  //#region src/runtime/bootstrap-standalone.ts
4645
4690
  const defineCustomElement = (Cstr, compactMeta) => {
@@ -4662,9 +4707,12 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4662
4707
  cmpMeta.$serializers$ = Cstr.$serializers$;
4663
4708
  }
4664
4709
  if (BUILD.reflect) cmpMeta.$attrsToReflect$ = [];
4665
- if (BUILD.hotModuleReplacement) Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4666
- hmrStart(this, cmpMeta, hmrVersionId);
4667
- };
4710
+ if (BUILD.hotModuleReplacement) {
4711
+ Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4712
+ hmrStart(this, cmpMeta, hmrVersionId);
4713
+ };
4714
+ Cstr["s-hmr-apply"] = (NewClass) => hmrApplyClass(cmpMeta, NewClass);
4715
+ }
4668
4716
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD.slotCloneNode || BUILD.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4669
4717
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4670
4718
  if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
@@ -4703,7 +4751,7 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4703
4751
  }
4704
4752
  connectedCallback(this);
4705
4753
  if (BUILD.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
4706
- await awaitAncestorConnected(hostRef.$ancestorComponent$);
4754
+ await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(this));
4707
4755
  if (!this.isConnected) return;
4708
4756
  }
4709
4757
  if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
@@ -5018,7 +5066,7 @@ function Mixin(...mixins) {
5018
5066
  //#region src/runtime/nonce.ts
5019
5067
  /**
5020
5068
  * Assigns the given value to the nonce property on the runtime platform object.
5021
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
5069
+ * During runtime, this value is used to set the nonce attribute on all dynamically created style tags.
5022
5070
  * @param nonce The value to be assigned to the platform nonce property.
5023
5071
  * @returns void
5024
5072
  */