@stencil/core 5.0.0-alpha.31 → 5.0.0-alpha.33

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 (34) hide show
  1. package/dist/app-data/index.d.ts +1 -1
  2. package/dist/app-data/index.js +2 -0
  3. package/dist/client-Bqq2Agpl.mjs +2367 -0
  4. package/dist/compiler/index.d.mts +1 -1
  5. package/dist/compiler/index.mjs +2 -3
  6. package/dist/compiler/utils/index.d.mts +1 -1
  7. package/dist/compiler/utils/index.mjs +3 -3
  8. package/dist/{compiler-Cddp97Pg.mjs → compiler-DjwEWyq2.mjs} +478 -17
  9. package/dist/declarations/stencil-public-compiler.d.ts +20 -3
  10. package/dist/declarations/stencil-public-runtime.d.ts +10 -0
  11. package/dist/{regular-expression-XqU5zmPp.mjs → helpers-Cpp3qc3u.mjs} +12 -13
  12. package/dist/{index-BHj3EBl2.d.mts → index-BCm37iOm.d.mts} +40 -3
  13. package/dist/{index-D2PAsXxx.d.ts → index-BTVuF9UD.d.ts} +2 -0
  14. package/dist/{index-VK8okIiF.d.mts → index-C-fMSffa.d.mts} +2 -10
  15. package/dist/index.mjs +1 -1
  16. package/dist/jsx-runtime.mjs +1 -1
  17. package/dist/{node-BQR4L-TG.mjs → node-DugJ2Vs2.mjs} +3 -3
  18. package/dist/runtime/client/lazy.js +27 -3
  19. package/dist/runtime/client/runtime.js +27 -3
  20. package/dist/runtime/index.d.ts +1 -1
  21. package/dist/runtime/index.js +27 -3
  22. package/dist/runtime/server/index.mjs +27 -3
  23. package/dist/runtime/server/runner.mjs +21 -3
  24. package/dist/signals/index.js +2 -0
  25. package/dist/sys/node/index.d.mts +1 -1
  26. package/dist/sys/node/index.mjs +1 -1
  27. package/dist/sys/node/worker.mjs +2 -2
  28. package/dist/testing/index.d.mts +4677 -100
  29. package/dist/testing/index.mjs +7553 -780
  30. package/dist/{util-BIa-iHnt.mjs → util-IKfWWLJo.mjs} +1 -1
  31. package/dist/{validation-Dd3g77T5.mjs → validation-DAdGTrys.mjs} +16 -3
  32. package/package.json +4 -4
  33. package/dist/client-D1MsT-Rp.mjs +0 -4838
  34. package/dist/reactive-controller-BdCpSAQP.d.mts +0 -13
@@ -0,0 +1,2367 @@
1
+ import { B as HOST_FLAGS, C as CMP_FLAGS, G as NODE_TYPES, Z as SVG_NS, o as isComplexType, s as isDef, x as queryNonceMetaTagContent } from "./helpers-Cpp3qc3u.mjs";
2
+ import { effect } from "@preact/signals-core";
3
+ //#region src/app-data/index.ts
4
+ /**
5
+ * A collection of default build flags for a Stencil project.
6
+ *
7
+ * This collection can be found throughout the Stencil codebase, often imported from the `virtual:app-data` module like so:
8
+ * ```ts
9
+ * import { BUILD } from 'virtual:app-data';
10
+ * ```
11
+ * and is used to determine if a portion of the output of a Stencil _project_'s compilation step can be eliminated.
12
+ *
13
+ * e.g. When `BUILD.allRenderFn` evaluates to `false`, the compiler will eliminate conditional statements like:
14
+ * ```ts
15
+ * if (BUILD.allRenderFn) {
16
+ * // some code that will be eliminated if BUILD.allRenderFn is false
17
+ * }
18
+ * ```
19
+ *
20
+ * `virtual:app-data`, the module that `BUILD` is imported from, is an alias for `@stencil/core/app-data`, and is
21
+ * partially referenced by {@link STENCIL_APP_DATA_ID}. The `src/compiler/bundle/app-data-plugin.ts` references
22
+ * `STENCIL_APP_DATA_ID` uses it to replace these defaults with {@link BuildConditionals} that are derived from a
23
+ * Stencil project's contents (i.e. metadata from the components). This replacement happens at a Stencil project's
24
+ * compile time. Such code can be found at `src/compiler/app-core/app-data.ts`.
25
+ */
26
+ const BUILD = {
27
+ allRenderFn: false,
28
+ element: true,
29
+ event: true,
30
+ hasRenderFn: true,
31
+ hostListener: true,
32
+ hostListenerTargetWindow: true,
33
+ hostListenerTargetDocument: true,
34
+ hostListenerTargetBody: true,
35
+ hostListenerTarget: true,
36
+ member: true,
37
+ method: true,
38
+ mode: true,
39
+ observeAttribute: true,
40
+ prop: true,
41
+ propMutable: true,
42
+ reflect: true,
43
+ scoped: true,
44
+ shadowDom: true,
45
+ shadowModeClosed: false,
46
+ slot: true,
47
+ cssAnnotations: true,
48
+ state: true,
49
+ style: true,
50
+ formAssociated: true,
51
+ svg: true,
52
+ updatable: true,
53
+ vdomAttribute: true,
54
+ vdomXlink: true,
55
+ vdomClass: true,
56
+ vdomFunctional: true,
57
+ vdomKey: true,
58
+ vdomListener: true,
59
+ vdomRef: true,
60
+ vdomPropOrAttr: true,
61
+ vdomRender: true,
62
+ vdomStyle: true,
63
+ vdomText: true,
64
+ propChangeCallback: true,
65
+ taskQueue: true,
66
+ lifecycle: true,
67
+ serializer: true,
68
+ deserializer: true,
69
+ patchAll: true,
70
+ patchChildren: true,
71
+ patchClone: true,
72
+ patchInsert: true,
73
+ hotModuleReplacement: false,
74
+ isDebug: false,
75
+ isDev: false,
76
+ isTesting: false,
77
+ hydrateServerSide: false,
78
+ hydrateClientSide: true,
79
+ lifecycleDOMEvents: false,
80
+ lazyLoad: false,
81
+ profile: false,
82
+ slotRelocation: true,
83
+ lightDomPatches: true,
84
+ slotChildNodes: true,
85
+ slotCloneNode: true,
86
+ slotDomMutations: true,
87
+ slotTextContent: true,
88
+ hydratedAttribute: false,
89
+ hydratedClass: true,
90
+ invisiblePrehydration: true,
91
+ staticHydrationStyles: false,
92
+ propBoolean: true,
93
+ propNumber: true,
94
+ propString: true,
95
+ constructableCSS: true,
96
+ devTools: false,
97
+ shadowDelegatesFocus: true,
98
+ shadowSlotAssignmentManual: false,
99
+ shadowClonable: true,
100
+ shadowSerializable: true,
101
+ initializeNextTick: false,
102
+ asyncLoading: true,
103
+ asyncQueue: false
104
+ };
105
+ //#endregion
106
+ //#region src/client/client-build.ts
107
+ const Build = {
108
+ isDev: BUILD.isDev,
109
+ isBrowser: true,
110
+ isServer: false,
111
+ isTesting: BUILD.isTesting
112
+ };
113
+ //#endregion
114
+ //#region src/client/client-host-ref.ts
115
+ /**
116
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
117
+ *
118
+ * @param ref the runtime ref of interest
119
+ * @returns the Host reference (if found) or undefined
120
+ */
121
+ const getHostRef = (ref) => {
122
+ if (ref.__s_ghr) return ref.__s_ghr();
123
+ };
124
+ const isMemberInElement = (elm, memberName) => memberName in elm;
125
+ //#endregion
126
+ //#region src/client/client-log.ts
127
+ let customError;
128
+ const consoleError = (e, el) => (customError || console.error)(e, el);
129
+ const STENCIL_DEV_MODE = BUILD.isTesting ? ["STENCIL:"] : ["%cstencil", "color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px"];
130
+ const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
131
+ const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
132
+ const setErrorHandler = (handler) => customError = handler;
133
+ //#endregion
134
+ //#region src/client/client-load-module.ts
135
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
136
+ //#endregion
137
+ //#region src/client/client-style.ts
138
+ const styles = /*@__PURE__*/ new Map();
139
+ const modeResolutionChain = [];
140
+ //#endregion
141
+ //#region src/runtime/runtime-constants.ts
142
+ /**
143
+ * Bit flags for recording various properties of VDom nodes
144
+ */
145
+ const VNODE_FLAGS = {
146
+ /**
147
+ * Whether or not a vdom node is a slot reference
148
+ */
149
+ isSlotReference: 1,
150
+ /**
151
+ * Whether or not a slot element has fallback content
152
+ */
153
+ isSlotFallback: 2,
154
+ /**
155
+ * Whether or not an element is a host element
156
+ */
157
+ isHost: 4
158
+ };
159
+ const PLATFORM_FLAGS = {
160
+ /**
161
+ * designates a node in the DOM as being actively moved by the runtime
162
+ */
163
+ isTmpDisconnected: 1,
164
+ appLoaded: 2,
165
+ queueSync: 4,
166
+ queueMask: 6
167
+ };
168
+ /**
169
+ * A (subset) of node types which are relevant for the Stencil runtime. These
170
+ * values are based on the values which can possibly be returned by the
171
+ * `.nodeType` property of a DOM node. See here for details:
172
+ *
173
+ * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
174
+ */
175
+ const NODE_TYPE = {
176
+ ElementNode: 1,
177
+ TextNode: 3,
178
+ CommentNode: 8,
179
+ DocumentNode: 9,
180
+ DocumentTypeNode: 10,
181
+ DocumentFragment: 11
182
+ };
183
+ const HYDRATED_STYLE_ID = "sty-id";
184
+ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
185
+ /**
186
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
187
+ *
188
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
189
+ * support as of Stencil v4.
190
+ */
191
+ const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
192
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
193
+ //#endregion
194
+ //#region src/client/client-window.ts
195
+ const win = typeof window !== "undefined" ? window : {};
196
+ win.HTMLElement;
197
+ const plt = {
198
+ $flags$: 0,
199
+ $resourcesUrl$: "",
200
+ jmp: (h) => h(),
201
+ raf: (h) => requestAnimationFrame(h),
202
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
203
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
204
+ ce: (eventName, opts) => new CustomEvent(eventName, opts)
205
+ };
206
+ const setPlatformHelpers = (helpers) => {
207
+ Object.assign(plt, helpers);
208
+ };
209
+ const promiseResolve = (v) => Promise.resolve(v);
210
+ const supportsConstructableStylesheets = BUILD.constructableCSS ? /*@__PURE__*/ (() => {
211
+ try {
212
+ if (!win.document.adoptedStyleSheets) return false;
213
+ return typeof new CSSStyleSheet().replaceSync === "function";
214
+ } catch {}
215
+ return false;
216
+ })() : false;
217
+ const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /*@__PURE__*/ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
218
+ //#endregion
219
+ //#region src/client/client-task-queue.ts
220
+ let queueCongestion = 0;
221
+ let queuePending = false;
222
+ const queueDomReads = [];
223
+ const queueDomWrites = [];
224
+ const queueDomWritesLow = [];
225
+ const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
226
+ const queueTask = (queue, write) => (cb) => {
227
+ queue.push(cb);
228
+ if (!queuePending) {
229
+ queuePending = true;
230
+ if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
231
+ else scheduleFlush();
232
+ }
233
+ };
234
+ const consume = (queue) => {
235
+ for (let i = 0; i < queue.length; i++) try {
236
+ queue[i](performance.now());
237
+ } catch (e) {
238
+ consoleError(e);
239
+ }
240
+ queue.length = 0;
241
+ };
242
+ const consumeTimeout = (queue, timeout) => {
243
+ let i = 0;
244
+ let ts = 0;
245
+ while (i < queue.length && (ts = performance.now()) < timeout) try {
246
+ queue[i++](ts);
247
+ } catch (e) {
248
+ consoleError(e);
249
+ }
250
+ if (i === queue.length) queue.length = 0;
251
+ else if (i !== 0) queue.splice(0, i);
252
+ };
253
+ const flush = () => {
254
+ if (BUILD.asyncQueue) queueCongestion++;
255
+ consume(queueDomReads);
256
+ if (BUILD.asyncQueue) {
257
+ const timeout = (plt.$flags$ & PLATFORM_FLAGS.queueMask) === PLATFORM_FLAGS.appLoaded ? performance.now() + 14 * Math.ceil(queueCongestion * (1 / 10)) : Infinity;
258
+ consumeTimeout(queueDomWrites, timeout);
259
+ consumeTimeout(queueDomWritesLow, timeout);
260
+ if (queueDomWrites.length > 0) {
261
+ queueDomWritesLow.push(...queueDomWrites);
262
+ queueDomWrites.length = 0;
263
+ }
264
+ if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) scheduleFlush();
265
+ else queueCongestion = 0;
266
+ } else {
267
+ consume(queueDomWrites);
268
+ if (queuePending = queueDomReads.length > 0) scheduleFlush();
269
+ }
270
+ };
271
+ const nextTick = (cb) => promiseResolve().then(cb);
272
+ const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
273
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
274
+ //#endregion
275
+ //#region src/runtime/asset-path.ts
276
+ const getAssetPath = (path) => {
277
+ const base = plt.$resourcesUrl$ || new URL(".", import.meta.url).href;
278
+ const assetUrl = new URL(path, base);
279
+ return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
280
+ };
281
+ const setAssetPath = (path) => plt.$resourcesUrl$ = path;
282
+ //#endregion
283
+ //#region src/runtime/slot-polyfill-utils.ts
284
+ /**
285
+ * Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
286
+ * are slot fallback nodes - `<slot-fb>...</slot-fb>`
287
+ *
288
+ * A slot fallback node should be visible by default. Then, it should be
289
+ * conditionally hidden if:
290
+ *
291
+ * - it has a sibling with a `slot` property set to its slot name or if
292
+ * - it is a default fallback slot node, in which case we hide if it has any
293
+ * content
294
+ *
295
+ * @param elm the element of interest
296
+ */
297
+ const updateFallbackSlotVisibility = (elm) => {
298
+ const childNodes = internalCall(elm, "childNodes");
299
+ if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
300
+ if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") {
301
+ if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
302
+ else slotNode.hidden = false;
303
+ }
304
+ });
305
+ let i = 0;
306
+ for (i = 0; i < childNodes.length; i++) {
307
+ const childNode = childNodes[i];
308
+ if (childNode.nodeType === NODE_TYPE.ElementNode && internalCall(childNode, "childNodes").length) updateFallbackSlotVisibility(childNode);
309
+ }
310
+ };
311
+ /**
312
+ * Get's the child nodes of a component that are actually slotted.
313
+ * It does this by using root nodes of a component; for each slotted node there is a
314
+ * corresponding slot location node which points to the slotted node (via `['s-nr']`).
315
+ *
316
+ * This is only required until all patches are unified / switched on all the time (then we can rely on `childNodes`)
317
+ * either under 'lightDomPatches' or on by default
318
+ * @param childNodes all 'internal' child nodes of the component
319
+ * @returns An array of slotted reference nodes.
320
+ */
321
+ const getSlottedChildNodes = (childNodes) => {
322
+ const result = [];
323
+ for (let i = 0; i < childNodes.length; i++) {
324
+ const slottedNode = childNodes[i]["s-nr"] || void 0;
325
+ if (slottedNode && slottedNode.isConnected) result.push(slottedNode);
326
+ }
327
+ return result;
328
+ };
329
+ /**
330
+ * Recursively searches a series of child nodes for slot node/s, optionally with a provided slot name.
331
+ * @param childNodes the nodes to search for a slot with a specific name. Should be an element's root nodes.
332
+ * @param hostName the host name of the slot to match on.
333
+ * @param slotName the name of the slot to match on.
334
+ * @returns a reference to the slot node that matches the provided name, `null` otherwise
335
+ */
336
+ function getHostSlotNodes(childNodes, hostName, slotName) {
337
+ let i = 0;
338
+ let slottedNodes = [];
339
+ let childNode;
340
+ for (; i < childNodes.length; i++) {
341
+ childNode = childNodes[i];
342
+ if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
343
+ slottedNodes.push(childNode);
344
+ if (typeof slotName !== "undefined") return slottedNodes;
345
+ }
346
+ slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
347
+ }
348
+ return slottedNodes;
349
+ }
350
+ /**
351
+ * Get all 'child' sibling nodes of a slot node
352
+ * @param slot - the slot node to get the child nodes from
353
+ * @param slotName - the name of the slot to match on
354
+ * @param includeSlot - whether to include the slot node in the result
355
+ * @returns child nodes of the slot node
356
+ */
357
+ const getSlotChildSiblings = (slot, slotName, includeSlot = true) => {
358
+ const childNodes = [];
359
+ if (includeSlot && slot["s-sr"] || !slot["s-sr"]) childNodes.push(slot);
360
+ let node = slot;
361
+ while (node = node.nextSibling) if (getSlotName(node) === slotName && (includeSlot || !node["s-sr"])) childNodes.push(node);
362
+ return childNodes;
363
+ };
364
+ /**
365
+ * Check whether a node is located in a given named slot.
366
+ *
367
+ * @param nodeToRelocate the node of interest
368
+ * @param slotName the slot name to check
369
+ * @returns whether the node is located in the slot or not
370
+ */
371
+ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
372
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) {
373
+ if (nodeToRelocate.getAttribute("slot") === null && slotName === "") return true;
374
+ if (nodeToRelocate.getAttribute("slot") === slotName) return true;
375
+ return false;
376
+ }
377
+ if (typeof nodeToRelocate["s-sa"] === "string") return nodeToRelocate["s-sa"] === slotName;
378
+ return slotName === "";
379
+ };
380
+ const getSlotName = (node) => typeof node["s-sn"] === "string" ? node["s-sn"] : node.nodeType === 1 && node.getAttribute("slot") || void 0;
381
+ /**
382
+ * Add `assignedElements` and `assignedNodes` methods on a fake slot node
383
+ *
384
+ * @param node - slot node to patch
385
+ */
386
+ function patchSlotNode(node) {
387
+ if (node.assignedElements || node.assignedNodes || !node["s-sr"]) return;
388
+ const assignedFactory = (elementsOnly) => function(opts) {
389
+ const toReturn = [];
390
+ const slotName = this["s-sn"];
391
+ if (opts?.flatten) {
392
+ if (BUILD.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
393
+ else console.error("Flattening not supported for Stencil non-shadow slots");
394
+ }
395
+ const parent = this["s-cr"].parentElement;
396
+ (parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes)).forEach((n) => {
397
+ if (slotName === getSlotName(n)) toReturn.push(n);
398
+ });
399
+ if (elementsOnly) return toReturn.filter((n) => n.nodeType === NODE_TYPE.ElementNode);
400
+ return toReturn;
401
+ }.bind(node);
402
+ node.assignedElements = assignedFactory(true);
403
+ node.assignedNodes = assignedFactory(false);
404
+ }
405
+ /**
406
+ * Dispatches a `slotchange` event on a fake `<slot />` node.
407
+ *
408
+ * @param elm the slot node to dispatch the event from
409
+ */
410
+ function dispatchSlotChangeEvent(elm) {
411
+ elm.name = elm["s-sn"] || "";
412
+ elm.dispatchEvent(new CustomEvent("slotchange", {
413
+ bubbles: false,
414
+ cancelable: false,
415
+ composed: false
416
+ }));
417
+ }
418
+ /**
419
+ * Find the slot node that a slotted node belongs to
420
+ *
421
+ * @param slottedNode - the slotted node to find the slot for
422
+ * @param parentHost - the parent host element of the slotted node
423
+ * @returns the slot node and slot name
424
+ */
425
+ function findSlotFromSlottedNode(slottedNode, parentHost) {
426
+ parentHost = parentHost || slottedNode["s-ol"]?.parentElement;
427
+ if (!parentHost) return {
428
+ slotNode: null,
429
+ slotName: ""
430
+ };
431
+ const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
432
+ return {
433
+ slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
434
+ slotName
435
+ };
436
+ }
437
+ //#endregion
438
+ //#region src/runtime/dom-extras.ts
439
+ /**
440
+ * Patches the `parentNode` accessor of a non-shadow slotted node
441
+ *
442
+ * @param node the slotted node to be patched
443
+ */
444
+ const patchParentNode = (node) => {
445
+ if (!node || node.__parentNode) return;
446
+ patchHostOriginalAccessor("parentNode", node);
447
+ Object.defineProperty(node, "parentNode", {
448
+ get: function() {
449
+ return this["s-ol"]?.parentNode || this.__parentNode;
450
+ },
451
+ set: function(value) {
452
+ this.__parentNode = value;
453
+ }
454
+ });
455
+ };
456
+ const validElementPatches = [
457
+ "children",
458
+ "nextElementSibling",
459
+ "previousElementSibling"
460
+ ];
461
+ const validNodesPatches = [
462
+ "childNodes",
463
+ "firstChild",
464
+ "lastChild",
465
+ "nextSibling",
466
+ "previousSibling",
467
+ "textContent",
468
+ "parentNode"
469
+ ];
470
+ /**
471
+ * Patches a node or element; making it's original accessor method available under a new name.
472
+ * e.g. `nextSibling` -> `__nextSibling`
473
+ *
474
+ * @param accessorName - the name of the accessor to patch
475
+ * @param node - the node to patch
476
+ */
477
+ function patchHostOriginalAccessor(accessorName, node) {
478
+ /**
479
+ * skip this method if a component was imported from a non-browser environment
480
+ */
481
+ if (!globalThis.Node || !globalThis.Element) return;
482
+ let accessor;
483
+ if (validElementPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Element.prototype, accessorName);
484
+ else if (validNodesPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Node.prototype, accessorName);
485
+ if (!accessor) accessor = Object.getOwnPropertyDescriptor(node, accessorName);
486
+ if (accessor) Object.defineProperty(node, "__" + accessorName, accessor);
487
+ }
488
+ /**
489
+ * Get the original / internal accessor or method of a node or element.
490
+ *
491
+ * @param node - the node to get the accessor from
492
+ * @param method - the name of the accessor to get
493
+ *
494
+ * @returns the original accessor or method of the node
495
+ */
496
+ function internalCall(node, method) {
497
+ if ("__" + method in node) {
498
+ const toReturn = node["__" + method];
499
+ if (typeof toReturn !== "function") return toReturn;
500
+ return toReturn.bind(node);
501
+ } else {
502
+ if (typeof node[method] !== "function") return node[method];
503
+ return node[method].bind(node);
504
+ }
505
+ }
506
+ //#endregion
507
+ //#region src/runtime/element.ts
508
+ const getElement = (ref) => BUILD.lazyLoad ? getHostRef(ref)?.$hostElement$ : ref;
509
+ /**
510
+ * Get the shadow root for a Stencil component's host element.
511
+ * This works for both open and closed shadow DOM modes.
512
+ *
513
+ * For closed shadow DOM, `element.shadowRoot` returns `null` by design,
514
+ * but Stencil stores the reference internally so components can still
515
+ * access their own shadow root.
516
+ *
517
+ * @param element The host element (from @Element() decorator)
518
+ * @returns The shadow root, or null if no shadow root exists
519
+ */
520
+ const getShadowRoot = (element) => {
521
+ if (BUILD.shadowModeClosed && element.__shadowRoot) return element.__shadowRoot;
522
+ return element.shadowRoot;
523
+ };
524
+ //#endregion
525
+ //#region src/runtime/profile.ts
526
+ let i = 0;
527
+ const createTime = (fnName, tagName = "") => {
528
+ if (BUILD.profile && performance.mark) {
529
+ const key = `st:${fnName}:${tagName}:${i++}`;
530
+ performance.mark(key);
531
+ return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
532
+ } else return () => {};
533
+ };
534
+ //#endregion
535
+ //#region src/runtime/styles.ts
536
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
537
+ /**
538
+ * Get or initialize the set of applied style scope IDs for a container element.
539
+ *
540
+ * @param container the container element to track styles for
541
+ * @returns the set of applied scope IDs
542
+ */
543
+ const getAppliedStyles = (container) => {
544
+ let applied = rootAppliedStyles.get(container);
545
+ if (!applied) {
546
+ applied = /* @__PURE__ */ new Set();
547
+ rootAppliedStyles.set(container, applied);
548
+ }
549
+ return applied;
550
+ };
551
+ /**
552
+ * Safely adopt a stylesheet into a container's adoptedStyleSheets.
553
+ * Handles both mutable and immutable adoptedStyleSheets arrays.
554
+ *
555
+ * @param container the shadow root or document to adopt styles into
556
+ * @param sheet the CSSStyleSheet to adopt
557
+ * @param prepend if true, add to beginning; if false, add to end
558
+ */
559
+ const adoptStylesheet = (container, sheet, prepend = false) => {
560
+ if (supportsMutableAdoptedStyleSheets) {
561
+ if (prepend) container.adoptedStyleSheets.unshift(sheet);
562
+ else container.adoptedStyleSheets.push(sheet);
563
+ } else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
564
+ else container.adoptedStyleSheets = [...container.adoptedStyleSheets, sheet];
565
+ };
566
+ /**
567
+ * Create a CSSStyleSheet for the correct window context.
568
+ * Constructable stylesheets can't be shared between windows,
569
+ * so we need to create one for the current window.
570
+ *
571
+ * @param container the container node (used to determine the window context)
572
+ * @param cssText the CSS text to populate the stylesheet with
573
+ * @returns a new CSSStyleSheet for the correct window
574
+ */
575
+ const createStylesheetForWindow = (container, cssText) => {
576
+ const sheet = new (container.defaultView ?? (container.ownerDocument?.defaultView) ?? win).CSSStyleSheet();
577
+ sheet.replaceSync(cssText);
578
+ return sheet;
579
+ };
580
+ /**
581
+ * Get the style for a component, appending slot fallback CSS if needed.
582
+ * Returns a new value without mutating the cached style.
583
+ *
584
+ * @param style - the style string or CSSStyleSheet to process
585
+ * @returns the style (string or CSSStyleSheet) with slot CSS appended if needed, or undefined
586
+ */
587
+ const getStyleWithSlotCss = (style) => {
588
+ if (!style) return SLOT_FB_CSS;
589
+ if (typeof style === "string") return style + SLOT_FB_CSS;
590
+ return style;
591
+ };
592
+ /**
593
+ * Attach the styles for a given component to the DOM
594
+ *
595
+ * If the element uses shadow or is already attached to the DOM then we can
596
+ * create a stylesheet inside of its associated document fragment, otherwise
597
+ * we'll stick the stylesheet into the document head.
598
+ *
599
+ * @param styleContainerNode the node within which a style element for the
600
+ * component of interest should be added
601
+ * @param cmpMeta runtime metadata for the component of interest
602
+ * @param mode an optional current mode
603
+ * @returns the scope ID for the component of interest
604
+ */
605
+ const addStyle = (styleContainerNode, cmpMeta, mode) => {
606
+ const scopeId = getScopeId(cmpMeta, mode);
607
+ if (!win.document) return scopeId;
608
+ let style = styles.get(scopeId);
609
+ if (cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) style = getStyleWithSlotCss(style);
610
+ const isClosedShadowSSR = BUILD.hydrateServerSide && BUILD.shadowModeClosed && cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss && cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed;
611
+ if (styleContainerNode.nodeType !== NODE_TYPE.DocumentFragment && !isClosedShadowSSR) styleContainerNode = win.document;
612
+ if (style) {
613
+ if (typeof style === "string") {
614
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
615
+ const appliedStyles = getAppliedStyles(styleContainerNode);
616
+ let styleElm;
617
+ const existingStyleElm = (BUILD.hydrateClientSide || BUILD.hotModuleReplacement) && styleContainerNode.querySelector(`[sty-id="${scopeId}"]`);
618
+ if (existingStyleElm) existingStyleElm.textContent = style;
619
+ else if (!appliedStyles.has(scopeId)) {
620
+ styleElm = win.document.createElement("style");
621
+ styleElm.textContent = style;
622
+ const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
623
+ if (nonce != null) styleElm.setAttribute("nonce", nonce);
624
+ if (BUILD.hydrateServerSide && (cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation || cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss || cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) || BUILD.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
625
+ if (BUILD.hotModuleReplacement && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) styleElm.setAttribute("data-slot-fb", "");
626
+ /**
627
+ * attach styles at the end of the head tag if we render scoped components
628
+ */
629
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
630
+ if (styleContainerNode.nodeName === "HEAD") {
631
+ /**
632
+ * if the page contains preconnect links, we want to insert the styles
633
+ * after the last preconnect link to ensure the styles are preloaded
634
+ */
635
+ const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
636
+ const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
637
+ styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
638
+ } else if ("host" in styleContainerNode) {
639
+ if (supportsConstructableStylesheets) {
640
+ const stylesheet = createStylesheetForWindow(styleContainerNode, style);
641
+ adoptStylesheet(styleContainerNode, stylesheet, true);
642
+ } else {
643
+ /**
644
+ * If a scoped component is used within a shadow root and constructable stylesheets are
645
+ * not supported, we want to insert the styles at the beginning of the shadow root node.
646
+ *
647
+ * However, if there is already a style node in the shadow root, we just append
648
+ * the styles to the existing node.
649
+ *
650
+ * Note: order of how styles are applied is important. The new style node
651
+ * should be inserted before the existing style node.
652
+ *
653
+ * During HMR, create separate style elements for scoped components so they can be
654
+ * updated independently without affecting other components' styles.
655
+ */
656
+ const existingStyleContainer = styleContainerNode.querySelector("style");
657
+ if (existingStyleContainer && !BUILD.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
658
+ else styleContainerNode.prepend(styleElm);
659
+ }
660
+ } else styleContainerNode.append(styleElm);
661
+ }
662
+ /**
663
+ * attach styles at the beginning of a shadow root node if we render shadow components
664
+ */
665
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) {
666
+ if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
667
+ else styleContainerNode.insertBefore(styleElm, null);
668
+ }
669
+ if (appliedStyles) appliedStyles.add(scopeId);
670
+ }
671
+ } else if (BUILD.constructableCSS) {
672
+ const appliedStyles = getAppliedStyles(styleContainerNode);
673
+ if (!appliedStyles.has(scopeId)) {
674
+ const currentWindow = styleContainerNode.defaultView ?? styleContainerNode.ownerDocument.defaultView;
675
+ let stylesheet;
676
+ if (style.constructor === currentWindow.CSSStyleSheet) stylesheet = style;
677
+ else {
678
+ stylesheet = new currentWindow.CSSStyleSheet();
679
+ for (let i = 0; i < style.cssRules.length; i++) stylesheet.insertRule(style.cssRules[i].cssText, i);
680
+ }
681
+ adoptStylesheet(styleContainerNode, stylesheet);
682
+ appliedStyles.add(scopeId);
683
+ if (BUILD.hydrateClientSide && "host" in styleContainerNode) {
684
+ const ssrStyleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`);
685
+ if (ssrStyleElm) writeTask(() => ssrStyleElm.remove());
686
+ }
687
+ }
688
+ }
689
+ }
690
+ return scopeId;
691
+ };
692
+ /**
693
+ * Add styles for a given component to the DOM, optionally handling 'scoped'
694
+ * encapsulation by adding an appropriate class name to the host element.
695
+ *
696
+ * @param hostRef the host reference for the component of interest
697
+ */
698
+ const attachStyles = (hostRef) => {
699
+ const cmpMeta = hostRef.$cmpMeta$;
700
+ const elm = hostRef.$hostElement$;
701
+ const flags = cmpMeta.$flags$;
702
+ const endAttachStyles = createTime("attachStyles", cmpMeta.$tagName$);
703
+ let styleContainerNode;
704
+ const shadowRoot = BUILD.shadowDom ? getShadowRoot(elm) : null;
705
+ if (shadowRoot) styleContainerNode = shadowRoot;
706
+ else if (BUILD.hydrateServerSide && BUILD.shadowModeClosed && flags & CMP_FLAGS.shadowNeedsScopedCss && flags & CMP_FLAGS.shadowModeClosed) styleContainerNode = elm;
707
+ else styleContainerNode = elm.getRootNode();
708
+ const scopeId = addStyle(styleContainerNode, cmpMeta, hostRef.$modeName$);
709
+ if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & CMP_FLAGS.needsScopedEncapsulation) {
710
+ elm["s-sc"] = scopeId;
711
+ elm.classList.add(scopeId + "-h");
712
+ }
713
+ endAttachStyles();
714
+ };
715
+ /**
716
+ * Get the scope ID for a given component
717
+ *
718
+ * @param cmp runtime metadata for the component of interest
719
+ * @param mode the current mode (optional)
720
+ * @returns a scope ID for the component of interest
721
+ */
722
+ const getScopeId = (cmp, mode) => "sc-" + (BUILD.mode && mode && cmp.$flags$ & CMP_FLAGS.hasMode ? cmp.$tagName$ + "-" + mode : cmp.$tagName$);
723
+ //#endregion
724
+ //#region src/runtime/event-emitter.ts
725
+ /**
726
+ * Helper function to create & dispatch a custom Event on a provided target
727
+ * @param elm the target of the Event
728
+ * @param name the name to give the custom Event
729
+ * @param opts options for configuring a custom Event
730
+ * @returns the custom Event
731
+ */
732
+ const emitEvent = (elm, name, opts) => {
733
+ const ev = plt.ce(name, opts);
734
+ elm.dispatchEvent(ev);
735
+ return ev;
736
+ };
737
+ const getRegistry = () => customElements;
738
+ //#endregion
739
+ //#region src/runtime/vdom/set-accessor.ts
740
+ /**
741
+ * Production setAccessor() function based on Preact by
742
+ * Jason Miller (@developit)
743
+ * Licensed under the MIT License
744
+ * https://github.com/developit/preact/blob/master/LICENSE
745
+ *
746
+ * Modified for Stencil's compiler and vdom
747
+ */
748
+ /** Per-element, per-attribute signal subscription disposers. */
749
+ const signalAttrDisposers = /* @__PURE__ */ new WeakMap();
750
+ const disposeAllSignalAttrs = (elm) => {
751
+ if (!BUILD.vdomSignals) return;
752
+ const map = signalAttrDisposers.get(elm);
753
+ if (map) {
754
+ map.forEach((d) => d());
755
+ signalAttrDisposers.delete(elm);
756
+ }
757
+ };
758
+ /**
759
+ * When running a VDom render set properties present on a VDom node onto the
760
+ * corresponding HTML element.
761
+ *
762
+ * Note that this function has special functionality for the `class`,
763
+ * `style`, `key`, and `ref` attributes, as well as event handlers (like
764
+ * `onClick`, etc). All others are just passed through as-is.
765
+ *
766
+ * @param elm the HTMLElement onto which attributes should be set
767
+ * @param memberName the name of the attribute to set
768
+ * @param oldValue the old value for the attribute
769
+ * @param newValue the new value for the attribute
770
+ * @param isSvg whether we're in an svg context or not
771
+ * @param flags bitflags for Vdom variables
772
+ * @param initialRender whether this is the first render of the VDom
773
+ */
774
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRender) => {
775
+ if (oldValue === newValue) return;
776
+ if (BUILD.vdomSignals && isSignalLike(newValue)) {
777
+ const attrMap = signalAttrDisposers.get(elm) ?? /* @__PURE__ */ new Map();
778
+ attrMap.get(memberName)?.();
779
+ if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
780
+ let prevVal = oldValue;
781
+ attrMap.set(memberName, effect(() => {
782
+ const curVal = newValue.value;
783
+ setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
784
+ prevVal = curVal;
785
+ }));
786
+ return;
787
+ }
788
+ if (BUILD.vdomSignals && isSignalLike(oldValue)) {
789
+ const attrMap = signalAttrDisposers.get(elm);
790
+ if (attrMap) {
791
+ attrMap.get(memberName)?.();
792
+ attrMap.delete(memberName);
793
+ }
794
+ }
795
+ let isProp = isMemberInElement(elm, memberName);
796
+ let ln = memberName.toLowerCase();
797
+ if (BUILD.vdomClass && memberName === "class") {
798
+ const classList = elm.classList;
799
+ const oldClasses = parseClassList(oldValue);
800
+ let newClasses = parseClassList(newValue);
801
+ if (BUILD.hydrateClientSide && (elm["s-si"] || elm["s-sc"]) && initialRender) {
802
+ const scopeId = elm["s-sc"] || elm["s-si"];
803
+ newClasses.push(scopeId);
804
+ oldClasses.forEach((c) => {
805
+ if (c.startsWith(scopeId)) newClasses.push(c);
806
+ });
807
+ newClasses = [...new Set(newClasses)].filter((c) => c);
808
+ classList.add(...newClasses);
809
+ } else {
810
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
811
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
812
+ }
813
+ } else if (BUILD.vdomStyle && memberName === "style") {
814
+ if (BUILD.updatable) {
815
+ for (const prop in oldValue) if (!newValue || newValue[prop] == null) {
816
+ if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
817
+ else elm.style[prop] = "";
818
+ }
819
+ }
820
+ for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) {
821
+ if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
822
+ else elm.style[prop] = newValue[prop];
823
+ }
824
+ } else if (BUILD.vdomKey && memberName === "key") {} else if (BUILD.vdomRef && memberName === "ref") {
825
+ if (newValue) queueRefAttachment(newValue, elm);
826
+ } else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
827
+ if (memberName[2] === "-") memberName = memberName.slice(3);
828
+ else if (isMemberInElement(win, ln)) memberName = ln.slice(2);
829
+ else memberName = ln[2] + memberName.slice(3);
830
+ if (oldValue || newValue) {
831
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
832
+ memberName = memberName.replace(/*@__PURE__*/ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
833
+ if (oldValue) plt.rel(elm, memberName, oldValue, capture);
834
+ if (newValue) plt.ael(elm, memberName, newValue, capture);
835
+ }
836
+ } else if (BUILD.vdomPropOrAttr && memberName[0] === "a" && memberName.startsWith("attr:")) {
837
+ const propName = memberName.slice(5);
838
+ let attrName;
839
+ if (BUILD.member) {
840
+ const hostRef = getHostRef(elm);
841
+ if (hostRef && hostRef.$cmpMeta$ && hostRef.$cmpMeta$.$members$) {
842
+ const memberMeta = hostRef.$cmpMeta$.$members$[propName];
843
+ if (memberMeta && memberMeta[1]) attrName = memberMeta[1];
844
+ }
845
+ }
846
+ if (!attrName) attrName = propName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
847
+ if (newValue == null || newValue === false) {
848
+ if (newValue !== false || elm.getAttribute(attrName) === "") elm.removeAttribute(attrName);
849
+ } else elm.setAttribute(attrName, newValue === true ? "" : newValue);
850
+ return;
851
+ } else if (BUILD.vdomPropOrAttr && memberName[0] === "p" && memberName.startsWith("prop:")) {
852
+ const propName = memberName.slice(5);
853
+ try {
854
+ elm[propName] = newValue;
855
+ } catch {}
856
+ return;
857
+ } else if (BUILD.vdomPropOrAttr) {
858
+ const isComplex = isComplexType(newValue);
859
+ if (!BUILD.lazyLoad) {
860
+ const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
861
+ if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
862
+ if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
863
+ elm["s-pp"].set(memberName, newValue);
864
+ return;
865
+ }
866
+ }
867
+ if ((isProp || isComplex && newValue !== null) && !isSvg) try {
868
+ if (!elm.tagName.includes("-")) {
869
+ const n = newValue == null ? "" : newValue;
870
+ if (memberName === "list") isProp = false;
871
+ else if (oldValue == null || elm[memberName] !== n) {
872
+ if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
873
+ else elm.setAttribute(memberName, n);
874
+ }
875
+ } else if (elm[memberName] !== newValue) elm[memberName] = newValue;
876
+ } catch {}
877
+ /**
878
+ * Need to manually update attribute if:
879
+ * - memberName is not an attribute
880
+ * - if we are rendering the host element in order to reflect attribute
881
+ * - if it's a SVG, since properties might not work in <svg>
882
+ * - if the newValue is null/undefined or 'false'.
883
+ */
884
+ let xlink = false;
885
+ if (BUILD.vdomXlink) {
886
+ if (ln !== (ln = ln.replace(/^xlink:?/, ""))) {
887
+ memberName = ln;
888
+ xlink = true;
889
+ }
890
+ }
891
+ if (newValue == null || newValue === false) {
892
+ if (newValue !== false || elm.getAttribute(memberName) === "" || flags & VNODE_FLAGS.isHost && !isEnumeratedAttribute(memberName)) {
893
+ if (BUILD.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
894
+ else elm.removeAttribute(memberName);
895
+ }
896
+ } else if ((!isProp || flags & VNODE_FLAGS.isHost || isSvg) && !isComplex && elm.nodeType === NODE_TYPE.ElementNode) {
897
+ newValue = newValue === true ? "" : newValue;
898
+ if (BUILD.vdomXlink && xlink) elm.setAttributeNS(XLINK_NS, memberName, newValue);
899
+ else elm.setAttribute(memberName, newValue);
900
+ }
901
+ }
902
+ };
903
+ /**
904
+ * Attribute names that are enumerated (tri-state true/false/unset) rather than
905
+ * plain boolean-presence attributes. An explicit `"false"` string on one of
906
+ * these is semantically different from the attribute being absent, so a
907
+ * reflected `false` value must not clear a pre-existing literal value.
908
+ */
909
+ const ENUMERATED_ATTRIBUTES = /*@__PURE__*/ new Set([
910
+ "draggable",
911
+ "contenteditable",
912
+ "spellcheck"
913
+ ]);
914
+ const isEnumeratedAttribute = (attrName) => ENUMERATED_ATTRIBUTES.has(attrName) || attrName.startsWith("aria-");
915
+ const parseClassListRegex = /\s/;
916
+ /**
917
+ * Parsed a string of classnames into an array
918
+ * @param value className string, e.g. "foo bar baz"
919
+ * @returns list of classes, e.g. ["foo", "bar", "baz"]
920
+ */
921
+ const parseClassList = (value) => {
922
+ if (typeof value === "object" && value && "baseVal" in value) value = value.baseVal;
923
+ if (!value || typeof value !== "string") return [];
924
+ return value.split(parseClassListRegex);
925
+ };
926
+ const CAPTURE_EVENT_SUFFIX = "Capture";
927
+ //#endregion
928
+ //#region src/runtime/vdom/update-element.ts
929
+ /**
930
+ * Handle updating attributes on the component element based on the current
931
+ * values present in the virtual DOM.
932
+ *
933
+ * If the component of interest uses shadow DOM these are added to the shadow
934
+ * root's host element.
935
+ *
936
+ * @param oldVnode an old virtual DOM node or null
937
+ * @param newVnode a new virtual DOM node
938
+ * @param isSvgMode whether or not we're in an SVG context
939
+ * @param isInitialRender whether this is the first render of the VDOM
940
+ */
941
+ const updateElement = (oldVnode, newVnode, isSvgMode, isInitialRender) => {
942
+ const oldVnodeAttrs = oldVnode && oldVnode.$attrs$ || {};
943
+ const newVnodeAttrs = newVnode.$attrs$ || {};
944
+ const oldKeys = Object.keys(oldVnodeAttrs);
945
+ const newKeys = Object.keys(newVnodeAttrs);
946
+ if (!BUILD.updatable && newKeys.length === 0) return;
947
+ if (BUILD.updatable && oldKeys.length === 0 && newKeys.length === 0) return;
948
+ const elm = newVnode.$elm$.nodeType === NODE_TYPE.DocumentFragment && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
949
+ if (BUILD.updatable) {
950
+ for (const memberName of sortedAttrNames(oldKeys)) if (!(memberName in newVnodeAttrs)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], void 0, isSvgMode, newVnode.$flags$, isInitialRender);
951
+ }
952
+ for (const memberName of sortedAttrNames(newKeys)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$, isInitialRender);
953
+ };
954
+ /**
955
+ * Sort a list of attribute names to ensure that all the attribute names which
956
+ * are _not_ `"ref"` come before `"ref"`. Preserve the order of the non-ref
957
+ * attributes.
958
+ *
959
+ * **Note**: if the supplied attributes do not include `'ref'` then the same
960
+ * (by reference) array will be returned without modification.
961
+ *
962
+ * @param attrNames attribute names to sort
963
+ * @returns a list of attribute names, sorted if they include `"ref"`
964
+ */
965
+ function sortedAttrNames(attrNames) {
966
+ if (!BUILD.vdomRef) return attrNames;
967
+ return attrNames.includes("ref") ? [...attrNames.filter((attr) => attr !== "ref"), "ref"] : attrNames;
968
+ }
969
+ //#endregion
970
+ //#region src/runtime/vdom/vdom-render.ts
971
+ /**
972
+ * Virtual DOM patching algorithm based on Snabbdom by
973
+ * Simon Friis Vindum (@paldepind)
974
+ * Licensed under the MIT License
975
+ * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
976
+ *
977
+ * Modified for Stencil's renderer and slot projection
978
+ */
979
+ let scopeId;
980
+ let contentRef;
981
+ let hostTagName;
982
+ let useNativeShadowDom = false;
983
+ let checkSlotFallbackVisibility = false;
984
+ let checkSlotRelocate = false;
985
+ let isSvgMode = false;
986
+ /**
987
+ * Queues for ref callbacks that need to be called during rendering.
988
+ * These ensure that ref callbacks are called in the correct order:
989
+ * first all removal callbacks (with null), then all attachment callbacks (with elements).
990
+ */
991
+ const refCallbacksToRemove = [];
992
+ const refCallbacksToAttach = [];
993
+ /** Disposers for signal subscriptions on individual DOM nodes (text nodes, <s-show> wrappers). */
994
+ const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
995
+ const disposeSignalVNode = (vnode) => {
996
+ const elm = vnode.$elm$;
997
+ if (elm) {
998
+ const dispose = signalNodeDisposers.get(elm);
999
+ if (dispose) {
1000
+ dispose();
1001
+ signalNodeDisposers.delete(elm);
1002
+ }
1003
+ disposeAllSignalAttrs(elm);
1004
+ }
1005
+ vnode.$children$?.forEach(disposeSignalVNode);
1006
+ };
1007
+ /**
1008
+ * Create a DOM Node corresponding to one of the children of a given VNode.
1009
+ *
1010
+ * @param oldParentVNode the parent VNode from the previous render
1011
+ * @param newParentVNode the parent VNode from the current render
1012
+ * @param childIndex the index of the VNode, in the _new_ parent node's
1013
+ * children, for which we will create a new DOM node
1014
+ * @returns the newly created node
1015
+ */
1016
+ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1017
+ const newVNode = newParentVNode.$children$[childIndex];
1018
+ let i = 0;
1019
+ let elm;
1020
+ let childNode;
1021
+ let oldVNode;
1022
+ if (BUILD.slotRelocation && !useNativeShadowDom) {
1023
+ checkSlotRelocate = true;
1024
+ if (newVNode.$tag$ === "slot") newVNode.$flags$ |= newVNode.$children$ ? VNODE_FLAGS.isSlotFallback : VNODE_FLAGS.isSlotReference;
1025
+ }
1026
+ 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`);
1027
+ if (BUILD.vdomText && newVNode.$text$ != null) {
1028
+ elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
1029
+ if (BUILD.vdomSignals && newVNode.$signal$) {
1030
+ const textSig = newVNode.$signal$;
1031
+ const textNode = elm;
1032
+ signalNodeDisposers.set(textNode, effect(() => {
1033
+ textNode.data = String(textSig.value);
1034
+ }));
1035
+ }
1036
+ } else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1037
+ elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1038
+ if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
1039
+ if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1040
+ } else {
1041
+ if (BUILD.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
1042
+ if (!win.document) throw new Error("No DOM environment available for rendering.");
1043
+ const tag = !useNativeShadowDom && BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
1044
+ const _reg = getRegistry();
1045
+ const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
1046
+ elm = newVNode.$elm$ = BUILD.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
1047
+ if (BUILD.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
1048
+ if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1049
+ if ((BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) && isDef(scopeId) && elm["s-si"] !== scopeId) elm.classList.add(elm["s-si"] = scopeId);
1050
+ if (newVNode.$children$) {
1051
+ const appendTarget = newVNode.$tag$ === "template" ? elm.content : elm;
1052
+ for (i = 0; i < newVNode.$children$.length; ++i) {
1053
+ childNode = createElm(oldParentVNode, newVNode, i);
1054
+ if (childNode) appendTarget.appendChild(childNode);
1055
+ }
1056
+ }
1057
+ if (BUILD.svg) {
1058
+ if (newVNode.$tag$ === "svg") isSvgMode = false;
1059
+ else if (elm.tagName === "foreignObject") isSvgMode = true;
1060
+ }
1061
+ }
1062
+ elm["s-hn"] = hostTagName;
1063
+ if (BUILD.slotRelocation) {
1064
+ if (newVNode.$flags$ & (VNODE_FLAGS.isSlotFallback | VNODE_FLAGS.isSlotReference)) {
1065
+ elm["s-sr"] = true;
1066
+ elm["s-cr"] = contentRef;
1067
+ elm["s-sn"] = newVNode.$name$ || "";
1068
+ elm["s-rf"] = newVNode.$attrs$?.ref;
1069
+ patchSlotNode(elm);
1070
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
1071
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) relocateToHostRoot(oldParentVNode.$elm$);
1072
+ if (BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) addRemoveSlotScopedClass(contentRef, elm, newParentVNode.$elm$, oldParentVNode?.$elm$);
1073
+ }
1074
+ }
1075
+ return elm;
1076
+ };
1077
+ /**
1078
+ * Relocates all child nodes of an element that were a part of a previous slot relocation
1079
+ * to the root of the Stencil component currently being rendered. This happens when a parent
1080
+ * element of a slot reference node dynamically changes and triggers a re-render. We cannot use
1081
+ * `putBackInOriginalLocation()` because that may relocate nodes to elements that will not be re-rendered
1082
+ * and so they will not be relocated again.
1083
+ *
1084
+ * @param parentElm The element potentially containing relocated nodes.
1085
+ */
1086
+ const relocateToHostRoot = (parentElm) => {
1087
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
1088
+ const host = parentElm.closest(hostTagName.toLowerCase());
1089
+ if (host != null) {
1090
+ const contentRefNode = Array.from(host.__childNodes || host.childNodes).find((ref) => ref["s-cr"]);
1091
+ const childNodeArray = Array.from(parentElm.__childNodes || parentElm.childNodes);
1092
+ for (const childNode of contentRefNode ? childNodeArray.reverse() : childNodeArray) if (childNode["s-sh"] != null) {
1093
+ insertBefore(host, childNode, contentRefNode ?? null);
1094
+ childNode["s-sh"] = void 0;
1095
+ checkSlotRelocate = true;
1096
+ }
1097
+ }
1098
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
1099
+ };
1100
+ /**
1101
+ * Puts `<slot>` nodes and any slotted nodes back to their original location (wherever they were before being slotted).
1102
+ *
1103
+ * @param parentElm - The parent element of the nodes to relocate.
1104
+ * @param recursive - Whether or not to relocate nodes in child nodes as well.
1105
+ */
1106
+ const putBackInOriginalLocation = (parentElm, recursive) => {
1107
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
1108
+ const oldSlotChildNodes = Array.from(parentElm.__childNodes || parentElm.childNodes);
1109
+ if (parentElm["s-sr"]) {
1110
+ let node = parentElm;
1111
+ while (node = node.nextSibling) if (node && node["s-sn"] === parentElm["s-sn"] && node["s-sh"] === hostTagName) oldSlotChildNodes.push(node);
1112
+ }
1113
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
1114
+ const childNode = oldSlotChildNodes[i];
1115
+ if (childNode["s-hn"] !== hostTagName && childNode["s-ol"]) {
1116
+ insertBefore(referenceNode(childNode).parentNode, childNode, referenceNode(childNode));
1117
+ childNode["s-ol"].remove();
1118
+ childNode["s-ol"] = void 0;
1119
+ childNode["s-sh"] = void 0;
1120
+ checkSlotRelocate = true;
1121
+ }
1122
+ if (recursive) putBackInOriginalLocation(childNode, recursive);
1123
+ }
1124
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
1125
+ };
1126
+ /**
1127
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
1128
+ * add them to the DOM in the appropriate place.
1129
+ *
1130
+ * @param parentElm the DOM node which should be used as a parent for the new
1131
+ * DOM nodes
1132
+ * @param before a child of the `parentElm` which the new children should be
1133
+ * inserted before (optional)
1134
+ * @param parentVNode the parent virtual DOM node
1135
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
1136
+ * @param startIdx the index in the child virtual DOM nodes at which to start
1137
+ * creating DOM nodes (inclusive)
1138
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
1139
+ * creating DOM nodes (inclusive)
1140
+ */
1141
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
1142
+ let containerElm = BUILD.slotRelocation && parentElm["s-cr"] && parentElm["s-cr"].parentNode || parentElm;
1143
+ let childNode;
1144
+ if (BUILD.shadowDom && containerElm.tagName === hostTagName) {
1145
+ const shadow = getShadowRoot(containerElm);
1146
+ if (shadow) containerElm = shadow;
1147
+ }
1148
+ if (parentVNode.$tag$ === "template") containerElm = containerElm.content;
1149
+ for (; startIdx <= endIdx; ++startIdx) if (vnodes[startIdx]) {
1150
+ childNode = createElm(null, parentVNode, startIdx);
1151
+ if (childNode) {
1152
+ vnodes[startIdx].$elm$ = childNode;
1153
+ insertBefore(containerElm, childNode, BUILD.slotRelocation ? referenceNode(before) : before);
1154
+ }
1155
+ }
1156
+ };
1157
+ /**
1158
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
1159
+ * This can be used to, for instance, clean up after a list of children which
1160
+ * should no longer be shown.
1161
+ *
1162
+ * This function also handles some of Stencil's slot relocation logic.
1163
+ *
1164
+ * @param vnodes a list of virtual DOM nodes to remove
1165
+ * @param startIdx the index at which to start removing nodes (inclusive)
1166
+ * @param endIdx the index at which to stop removing nodes (inclusive)
1167
+ */
1168
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
1169
+ for (let index = startIdx; index <= endIdx; ++index) {
1170
+ const vnode = vnodes[index];
1171
+ if (vnode) {
1172
+ const elm = vnode.$elm$;
1173
+ nullifyVNodeRefs(vnode);
1174
+ if (BUILD.vdomSignals) disposeSignalVNode(vnode);
1175
+ if (elm) {
1176
+ if (BUILD.slotRelocation) {
1177
+ checkSlotFallbackVisibility = true;
1178
+ if (elm["s-ol"]) elm["s-ol"].remove();
1179
+ else putBackInOriginalLocation(elm, true);
1180
+ }
1181
+ elm.remove();
1182
+ }
1183
+ }
1184
+ }
1185
+ };
1186
+ /**
1187
+ * Reconcile the children of a new VNode with the children of an old VNode by
1188
+ * traversing the two collections of children, identifying nodes that are
1189
+ * conserved or changed, calling out to `patch` to make any necessary
1190
+ * updates to the DOM, and rearranging DOM nodes as needed.
1191
+ *
1192
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
1193
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
1194
+ * 'windows' by storing start and end indices and references to the
1195
+ * corresponding array entries. Initially the two 'windows' are basically equal
1196
+ * to the entire array, but we progressively narrow the windows until there are
1197
+ * no children left to update by doing the following:
1198
+ *
1199
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
1200
+ * that if we have an initial array like the following we'll end up dealing
1201
+ * only with a window bounded by the highlighted elements:
1202
+ *
1203
+ * [null, null, VNode1 , ... , VNode2, null, null]
1204
+ * ^^^^^^ ^^^^^^
1205
+ *
1206
+ * 2. Check to see if the elements at the head and tail positions are equal
1207
+ * across the windows. This will basically detect elements which haven't
1208
+ * been added, removed, or changed position, i.e. if you had the following
1209
+ * VNode elements (represented as HTML):
1210
+ *
1211
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
1212
+ * newVNode: `<div><p><span>THERE</span></p></div>`
1213
+ *
1214
+ * Then when comparing the children of the `<div>` tag we check the equality
1215
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
1216
+ * same tag in the same position, we'd be able to avoid completely
1217
+ * re-rendering the subtree under them with a new DOM element and would just
1218
+ * call out to `patch` to handle reconciling their children and so on.
1219
+ *
1220
+ * 3. Check, for both windows, to see if the element at the beginning of the
1221
+ * window corresponds to the element at the end of the other window. This is
1222
+ * a heuristic which will let us identify _some_ situations in which
1223
+ * elements have changed position, for instance it _should_ detect that the
1224
+ * children nodes themselves have not changed but merely moved in the
1225
+ * following example:
1226
+ *
1227
+ * oldVNode: `<div><element-one /><element-two /></div>`
1228
+ * newVNode: `<div><element-two /><element-one /></div>`
1229
+ *
1230
+ * If we find cases like this then we also need to move the concrete DOM
1231
+ * elements corresponding to the moved children to write the re-order to the
1232
+ * DOM.
1233
+ *
1234
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
1235
+ * nodes in the old children which have the same key as the first element in
1236
+ * our window on the new children. If we find such a node we handle calling
1237
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
1238
+ * what we find.
1239
+ *
1240
+ * Finally, once we've narrowed our 'windows' to the point that either of them
1241
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
1242
+ * insertion or deletion that needs to happen to get a DOM state that correctly
1243
+ * reflects the new child VNodes. If, for instance, after our window on the old
1244
+ * children has collapsed we still have more nodes on the new children that
1245
+ * we haven't dealt with yet then we need to add them, or if the new children
1246
+ * collapse but we still have unhandled _old_ children then we need to make
1247
+ * sure the corresponding DOM nodes are removed.
1248
+ *
1249
+ * @param parentElm the node into which the parent VNode is rendered
1250
+ * @param oldCh the old children of the parent node
1251
+ * @param newVNode the new VNode which will replace the parent
1252
+ * @param newCh the new children of the parent node
1253
+ * @param isInitialRender whether or not this is the first render of the vdom
1254
+ */
1255
+ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
1256
+ let oldStartIdx = 0;
1257
+ let newStartIdx = 0;
1258
+ let idxInOld = 0;
1259
+ let i = 0;
1260
+ let oldEndIdx = oldCh.length - 1;
1261
+ let oldStartVnode = oldCh[0];
1262
+ let oldEndVnode = oldCh[oldEndIdx];
1263
+ let newEndIdx = newCh.length - 1;
1264
+ let newStartVnode = newCh[0];
1265
+ let newEndVnode = newCh[newEndIdx];
1266
+ let node;
1267
+ let elmToMove;
1268
+ const containerElm = newVNode.$tag$ === "template" ? parentElm.content : parentElm;
1269
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) if (oldStartVnode == null) oldStartVnode = oldCh[++oldStartIdx];
1270
+ else if (oldEndVnode == null) oldEndVnode = oldCh[--oldEndIdx];
1271
+ else if (newStartVnode == null) newStartVnode = newCh[++newStartIdx];
1272
+ else if (newEndVnode == null) newEndVnode = newCh[--newEndIdx];
1273
+ else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
1274
+ patch(oldStartVnode, newStartVnode, isInitialRender);
1275
+ oldStartVnode = oldCh[++oldStartIdx];
1276
+ newStartVnode = newCh[++newStartIdx];
1277
+ } else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
1278
+ patch(oldEndVnode, newEndVnode, isInitialRender);
1279
+ oldEndVnode = oldCh[--oldEndIdx];
1280
+ newEndVnode = newCh[--newEndIdx];
1281
+ } else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
1282
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
1283
+ patch(oldStartVnode, newEndVnode, isInitialRender);
1284
+ insertBefore(containerElm, oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
1285
+ oldStartVnode = oldCh[++oldStartIdx];
1286
+ newEndVnode = newCh[--newEndIdx];
1287
+ } else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
1288
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
1289
+ patch(oldEndVnode, newStartVnode, isInitialRender);
1290
+ insertBefore(containerElm, oldEndVnode.$elm$, oldStartVnode.$elm$);
1291
+ oldEndVnode = oldCh[--oldEndIdx];
1292
+ newStartVnode = newCh[++newStartIdx];
1293
+ } else {
1294
+ idxInOld = -1;
1295
+ if (BUILD.vdomKey) {
1296
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
1297
+ idxInOld = i;
1298
+ break;
1299
+ }
1300
+ }
1301
+ if (BUILD.vdomKey && idxInOld >= 0) {
1302
+ elmToMove = oldCh[idxInOld];
1303
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
1304
+ else {
1305
+ patch(elmToMove, newStartVnode, isInitialRender);
1306
+ oldCh[idxInOld] = void 0;
1307
+ node = elmToMove.$elm$;
1308
+ }
1309
+ newStartVnode = newCh[++newStartIdx];
1310
+ } else {
1311
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
1312
+ newStartVnode = newCh[++newStartIdx];
1313
+ }
1314
+ if (node) {
1315
+ if (BUILD.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
1316
+ else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
1317
+ }
1318
+ }
1319
+ if (oldStartIdx > oldEndIdx) addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
1320
+ else if (BUILD.updatable && newStartIdx > newEndIdx) removeVnodes(oldCh, oldStartIdx, oldEndIdx);
1321
+ };
1322
+ /**
1323
+ * Compare two VNodes to determine if they are the same
1324
+ *
1325
+ * **NB**: This function is an equality _heuristic_ based on the available
1326
+ * information set on the two VNodes and can be misleading under certain
1327
+ * circumstances. In particular, if the two nodes do not have `key` attrs
1328
+ * (available under `$key$` on VNodes) then the function falls back on merely
1329
+ * checking that they have the same tag.
1330
+ *
1331
+ * So, in other words, if `key` attrs are not set on VNodes which may be
1332
+ * changing order within a `children` array or something along those lines then
1333
+ * we could obtain a false negative and then have to do needless re-rendering
1334
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
1335
+ *
1336
+ * @param leftVNode the first VNode to check
1337
+ * @param rightVNode the second VNode to check
1338
+ * @param isInitialRender whether or not this is the first render of the vdom
1339
+ * @returns whether they're equal or not
1340
+ */
1341
+ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
1342
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
1343
+ if (BUILD.slotRelocation && leftVNode.$tag$ === "slot") return leftVNode.$name$ === rightVNode.$name$;
1344
+ if (BUILD.vdomKey && !isInitialRender) return leftVNode.$key$ === rightVNode.$key$;
1345
+ if (isInitialRender && !leftVNode.$key$ && rightVNode.$key$) leftVNode.$key$ = rightVNode.$key$;
1346
+ return true;
1347
+ }
1348
+ return false;
1349
+ };
1350
+ /**
1351
+ * Returns the reference node (a comment which represents the
1352
+ * original location of a node in the vdom - before it was moved to its slot)
1353
+ * of a given node.
1354
+ *
1355
+ * (slot nodes can be relocated to a new location in the dom because of
1356
+ * some other component's slot)
1357
+ * @param node the node to find the original location reference node for
1358
+ * @returns reference node
1359
+ */
1360
+ const referenceNode = (node) => node && node["s-ol"] || node;
1361
+ /**
1362
+ * Handle reconciling an outdated VNode with a new one which corresponds to
1363
+ * it. This function handles flushing updates to the DOM and reconciling the
1364
+ * children of the two nodes (if any).
1365
+ *
1366
+ * @param oldVNode an old VNode whose DOM element and children we want to update
1367
+ * @param newVNode a new VNode representing an updated version of the old one
1368
+ * @param isInitialRender whether or not this is the first render of the vdom
1369
+ */
1370
+ const patch = (oldVNode, newVNode, isInitialRender = false) => {
1371
+ const elm = newVNode.$elm$ = oldVNode.$elm$;
1372
+ const oldChildren = oldVNode.$children$;
1373
+ const newChildren = newVNode.$children$;
1374
+ const tag = newVNode.$tag$;
1375
+ const text = newVNode.$text$;
1376
+ let defaultHolder;
1377
+ if (!BUILD.vdomText || text == null) {
1378
+ if (BUILD.svg) isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
1379
+ if (BUILD.vdomAttribute || BUILD.reflect) {
1380
+ if (BUILD.slot && tag === "slot" && !useNativeShadowDom) {
1381
+ if (oldVNode.$name$ !== newVNode.$name$) {
1382
+ newVNode.$elm$["s-sn"] = newVNode.$name$ || "";
1383
+ relocateToHostRoot(newVNode.$elm$.parentElement);
1384
+ }
1385
+ }
1386
+ updateElement(oldVNode, newVNode, isSvgMode, isInitialRender);
1387
+ }
1388
+ if (BUILD.updatable && oldChildren !== null && newChildren !== null) updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
1389
+ else if (newChildren !== null) {
1390
+ if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) elm.textContent = "";
1391
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
1392
+ } else if (!isInitialRender && BUILD.updatable && oldChildren !== null) removeVnodes(oldChildren, 0, oldChildren.length - 1);
1393
+ else if (BUILD.hydrateClientSide && isInitialRender && BUILD.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
1394
+ if (BUILD.svg && isSvgMode && tag === "svg") isSvgMode = false;
1395
+ } else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
1396
+ else if (BUILD.vdomText && oldVNode.$text$ !== text) elm.data = text;
1397
+ };
1398
+ /**
1399
+ * Component-global information about nodes which are either currently being
1400
+ * relocated or will be shortly.
1401
+ */
1402
+ const relocateNodes = [];
1403
+ /**
1404
+ * When a forwarded `<slot>` gets relocated, drag along any content already forwarded through it,
1405
+ * to wherever it just landed (or nowhere, to be hidden, if it didn't match anything).
1406
+ *
1407
+ * Runs as its own pass after {@link markSlotContentForRelocation} rather than inside it, so that
1408
+ * function's matching order - which hydration's node/comment ordering depends on - is untouched.
1409
+ */
1410
+ const carryContentWithRelocatedSlotRefs = () => {
1411
+ for (const relocateData of relocateNodes.slice()) {
1412
+ const marker = relocateData.$nodeToRelocate$;
1413
+ if (!marker["s-sr"]) continue;
1414
+ const carriedSiblings = getSlotChildSiblings(marker, marker["s-sn"] || "", false);
1415
+ for (const carriedSibling of carriedSiblings) {
1416
+ if (!carriedSibling["s-ol"]) continue;
1417
+ let siblingRelocateData = relocateNodes.find((r) => r.$nodeToRelocate$ === carriedSibling);
1418
+ if (!siblingRelocateData) {
1419
+ siblingRelocateData = { $nodeToRelocate$: carriedSibling };
1420
+ relocateNodes.push(siblingRelocateData);
1421
+ }
1422
+ siblingRelocateData.$slotRefNode$ = relocateData.$slotRefNode$;
1423
+ if (relocateData.$slotRefNode$) carriedSibling["s-sh"] = relocateData.$slotRefNode$["s-hn"];
1424
+ }
1425
+ }
1426
+ };
1427
+ /**
1428
+ * Mark the contents of a slot for relocation via adding references to them to
1429
+ * the {@link relocateNodes} data structure. The actual work of relocating them
1430
+ * will then be handled in {@link renderVdom}.
1431
+ *
1432
+ * @param elm a render node whose child nodes need to be relocated
1433
+ */
1434
+ const markSlotContentForRelocation = (elm) => {
1435
+ let node;
1436
+ let hostContentNodes;
1437
+ let j;
1438
+ const children = elm.__childNodes || elm.childNodes;
1439
+ for (const childNode of children) {
1440
+ if (childNode["s-sr"] && (node = childNode["s-cr"]) && node.parentNode) {
1441
+ hostContentNodes = node.parentNode.__childNodes || node.parentNode.childNodes;
1442
+ const slotName = childNode["s-sn"];
1443
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
1444
+ node = hostContentNodes[j];
1445
+ if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== childNode["s-hn"] && (!node["s-sh"] || node["s-sh"] !== childNode["s-hn"])) {
1446
+ if (isNodeLocatedInSlot(node, slotName)) {
1447
+ let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1448
+ checkSlotFallbackVisibility = true;
1449
+ node["s-sn"] = node["s-sn"] || slotName;
1450
+ if (relocateNodeData) {
1451
+ relocateNodeData.$nodeToRelocate$["s-sh"] = childNode["s-hn"];
1452
+ relocateNodeData.$slotRefNode$ = childNode;
1453
+ } else {
1454
+ node["s-sh"] = childNode["s-hn"];
1455
+ relocateNodes.push({
1456
+ $slotRefNode$: childNode,
1457
+ $nodeToRelocate$: node
1458
+ });
1459
+ }
1460
+ if (node["s-sr"]) relocateNodes.map((relocateNode) => {
1461
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node["s-sn"])) {
1462
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1463
+ if (relocateNodeData && !relocateNode.$slotRefNode$) relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1464
+ }
1465
+ });
1466
+ } else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) relocateNodes.push({ $nodeToRelocate$: node });
1467
+ }
1468
+ }
1469
+ }
1470
+ if (childNode.nodeType === NODE_TYPE.ElementNode) markSlotContentForRelocation(childNode);
1471
+ }
1472
+ };
1473
+ /**
1474
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
1475
+ * them with `null`. This signals that the DOM element corresponding to the VDom
1476
+ * node has been removed from the DOM.
1477
+ *
1478
+ * @param vNode a virtual DOM node
1479
+ */
1480
+ const nullifyVNodeRefs = (vNode) => {
1481
+ if (BUILD.vdomRef) {
1482
+ if (vNode.$attrs$ && vNode.$attrs$.ref) refCallbacksToRemove.push(() => vNode.$attrs$.ref(null));
1483
+ if (vNode.$children$) vNode.$children$.map(nullifyVNodeRefs);
1484
+ }
1485
+ };
1486
+ /**
1487
+ * Queue a ref callback to be called with an element during rendering.
1488
+ * This ensures ref callbacks are called in the correct order.
1489
+ *
1490
+ * @param refCallback the ref callback function to queue
1491
+ * @param elm the element to pass to the callback
1492
+ */
1493
+ const queueRefAttachment = (refCallback, elm) => {
1494
+ if (BUILD.vdomRef) refCallbacksToAttach.push(() => refCallback(elm));
1495
+ };
1496
+ /**
1497
+ * Flush all queued ref callbacks in the correct order:
1498
+ * first all removal callbacks (with null), then all attachment callbacks (with elements).
1499
+ * This ensures that when elements are replaced/reordered, the ref is always left
1500
+ * pointing to the current element, not null.
1501
+ */
1502
+ const flushQueuedRefCallbacks = () => {
1503
+ if (BUILD.vdomRef) {
1504
+ refCallbacksToRemove.forEach((cb) => cb());
1505
+ refCallbacksToRemove.length = 0;
1506
+ refCallbacksToAttach.forEach((cb) => cb());
1507
+ refCallbacksToAttach.length = 0;
1508
+ }
1509
+ };
1510
+ /**
1511
+ * Inserts a node before a reference node as a child of a specified parent node.
1512
+ * Additionally, adds parent elements' scope ids as class names to the new node.
1513
+ *
1514
+ * @param parent parent node
1515
+ * @param newNode element to be inserted
1516
+ * @param reference anchor element
1517
+ * @param isInitialLoad whether or not this is the first render
1518
+ * @returns inserted node
1519
+ */
1520
+ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
1521
+ if (BUILD.slotRelocation) {
1522
+ if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
1523
+ else if (typeof newNode["s-sn"] === "string") {
1524
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
1525
+ if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchParentNode(newNode);
1526
+ parent.insertBefore(newNode, reference);
1527
+ const { slotNode } = findSlotFromSlottedNode(newNode);
1528
+ if (slotNode && !isInitialLoad) dispatchSlotChangeEvent(slotNode);
1529
+ return newNode;
1530
+ }
1531
+ }
1532
+ if (BUILD.slotRelocation && parent?.__insertBefore) return parent.__insertBefore(newNode, reference);
1533
+ else return parent?.insertBefore(newNode, reference);
1534
+ };
1535
+ /**
1536
+ * Adds or removes a scoped class to the parent element of a slotted node.
1537
+ * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
1538
+ * in `scoped: true` components.
1539
+ *
1540
+ * @param reference - Content Reference Node. Used to get the scope id of the parent component.
1541
+ * @param slotNode - the `<slot>` node to apply the class for
1542
+ * @param newParent - the slots' new parent element that requires the scoped class
1543
+ * @param oldParent - optionally, an old parent element that may no longer require the scoped class
1544
+ */
1545
+ function addRemoveSlotScopedClass(reference, slotNode, newParent, oldParent) {
1546
+ let slotScopeId;
1547
+ if (reference && typeof slotNode["s-sn"] === "string" && !!slotNode["s-sr"] && reference.parentNode && reference.parentNode["s-sc"] && (slotScopeId = slotNode["s-si"] || reference.parentNode["s-sc"])) {
1548
+ const scopeName = slotNode["s-sn"];
1549
+ const hostName = slotNode["s-hn"];
1550
+ newParent.classList?.add(slotScopeId + "-s");
1551
+ if (oldParent && oldParent.classList?.contains(slotScopeId + "-s")) {
1552
+ let child = (oldParent.__childNodes || oldParent.childNodes)[0];
1553
+ let found = false;
1554
+ while (child) {
1555
+ if (child["s-sn"] !== scopeName && child["s-hn"] === hostName && !!child["s-sr"]) {
1556
+ found = true;
1557
+ break;
1558
+ }
1559
+ child = child.nextSibling;
1560
+ }
1561
+ if (!found) oldParent.classList.remove(slotScopeId + "-s");
1562
+ }
1563
+ }
1564
+ }
1565
+ /**
1566
+ * The main entry point for Stencil's virtual DOM-based rendering engine
1567
+ *
1568
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
1569
+ * function will handle creating a virtual DOM tree with a single root, patching
1570
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
1571
+ * relocation, and reflecting attributes.
1572
+ *
1573
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
1574
+ * the DOM node into which it should be rendered.
1575
+ * @param renderFnResults the virtual DOM nodes to be rendered
1576
+ * @param isInitialLoad whether or not this is the first call after page load
1577
+ */
1578
+ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1579
+ const hostElm = hostRef.$hostElement$;
1580
+ const cmpMeta = hostRef.$cmpMeta$;
1581
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1582
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1583
+ hostTagName = hostElm.tagName;
1584
+ if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
1585
+ Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
1586
+
1587
+ The render() function should look like this instead:
1588
+
1589
+ render() {
1590
+ // Do not return an array
1591
+ return (
1592
+ <Host>{content}</Host>
1593
+ );
1594
+ }
1595
+ `);
1596
+ if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
1597
+ rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1598
+ cmpMeta.$attrsToReflect$.forEach(([propName, attribute]) => {
1599
+ if (BUILD.serializer && hostRef.$serializerValues$.has(propName)) rootVnode.$attrs$[attribute] = hostRef.$serializerValues$.get(propName);
1600
+ else rootVnode.$attrs$[attribute] = hostElm[propName];
1601
+ });
1602
+ }
1603
+ if (isInitialLoad && rootVnode.$attrs$) {
1604
+ for (const key of Object.keys(rootVnode.$attrs$)) if (hostElm.hasAttribute(key) && ![
1605
+ "key",
1606
+ "ref",
1607
+ "style",
1608
+ "class"
1609
+ ].includes(key)) rootVnode.$attrs$[key] = hostElm[key];
1610
+ }
1611
+ rootVnode.$tag$ = null;
1612
+ rootVnode.$flags$ |= VNODE_FLAGS.isHost;
1613
+ hostRef.$vnode$ = rootVnode;
1614
+ rootVnode.$elm$ = oldVNode.$elm$ = BUILD.shadowDom ? getShadowRoot(hostElm) || hostElm : hostElm;
1615
+ if (BUILD.scoped || BUILD.shadowDom) scopeId = hostElm["s-sc"];
1616
+ useNativeShadowDom = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss);
1617
+ if (BUILD.slotRelocation) {
1618
+ contentRef = hostElm["s-cr"];
1619
+ checkSlotFallbackVisibility = false;
1620
+ }
1621
+ patch(oldVNode, rootVnode, isInitialLoad);
1622
+ if (BUILD.slotRelocation) {
1623
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
1624
+ if (checkSlotRelocate) {
1625
+ markSlotContentForRelocation(rootVnode.$elm$);
1626
+ carryContentWithRelocatedSlotRefs();
1627
+ for (const relocateData of relocateNodes) {
1628
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1629
+ if (!nodeToRelocate["s-ol"] && win.document) {
1630
+ const orgLocationNode = BUILD.isDebug || BUILD.hydrateServerSide ? originalLocationDebugNode(nodeToRelocate) : win.document.createTextNode("");
1631
+ orgLocationNode["s-nr"] = nodeToRelocate;
1632
+ insertBefore(nodeToRelocate.parentNode, nodeToRelocate["s-ol"] = orgLocationNode, nodeToRelocate, isInitialLoad);
1633
+ }
1634
+ }
1635
+ for (const relocateData of relocateNodes) {
1636
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
1637
+ const slotRefNode = relocateData.$slotRefNode$;
1638
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && isInitialLoad) nodeToRelocate["s-ih"] = !!nodeToRelocate.hidden;
1639
+ if (slotRefNode) {
1640
+ const parentNodeRef = slotRefNode.parentNode;
1641
+ let insertBeforeNode = slotRefNode.nextSibling;
1642
+ if (!BUILD.hydrateServerSide && insertBeforeNode && insertBeforeNode.nodeType === NODE_TYPE.ElementNode) {
1643
+ let orgLocationNode = nodeToRelocate["s-ol"]?.previousSibling;
1644
+ while (orgLocationNode) {
1645
+ let refNode = orgLocationNode["s-nr"] ?? null;
1646
+ if (refNode && refNode["s-sn"] === nodeToRelocate["s-sn"] && parentNodeRef === (refNode.__parentNode || refNode.parentNode)) {
1647
+ refNode = refNode.nextSibling;
1648
+ while (refNode === nodeToRelocate || refNode?.["s-sr"]) refNode = refNode?.nextSibling;
1649
+ if (!refNode || !refNode["s-nr"]) {
1650
+ insertBeforeNode = refNode;
1651
+ break;
1652
+ }
1653
+ }
1654
+ orgLocationNode = orgLocationNode.previousSibling;
1655
+ }
1656
+ }
1657
+ const parent = nodeToRelocate.__parentNode || nodeToRelocate.parentNode;
1658
+ const nextSibling = nodeToRelocate.__nextSibling || nodeToRelocate.nextSibling;
1659
+ if (!insertBeforeNode && parentNodeRef !== parent || nextSibling !== insertBeforeNode) {
1660
+ if (nodeToRelocate !== insertBeforeNode) {
1661
+ insertBefore(parentNodeRef, nodeToRelocate, insertBeforeNode, isInitialLoad);
1662
+ if (nodeToRelocate.nodeType === NODE_TYPE.CommentNode && nodeToRelocate.nodeValue.startsWith("s-nt-")) {
1663
+ const textNode = win.document.createTextNode(nodeToRelocate.nodeValue.replace(/^s-nt-/, ""));
1664
+ textNode["s-hn"] = nodeToRelocate["s-hn"];
1665
+ textNode["s-sn"] = nodeToRelocate["s-sn"];
1666
+ textNode["s-sh"] = nodeToRelocate["s-sh"];
1667
+ textNode["s-sr"] = nodeToRelocate["s-sr"];
1668
+ textNode["s-ol"] = nodeToRelocate["s-ol"];
1669
+ textNode["s-ol"]["s-nr"] = textNode;
1670
+ insertBefore(nodeToRelocate.parentNode, textNode, nodeToRelocate, isInitialLoad);
1671
+ nodeToRelocate.parentNode.removeChild(nodeToRelocate);
1672
+ }
1673
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && nodeToRelocate.tagName !== "SLOT-FB") nodeToRelocate.hidden = nodeToRelocate["s-ih"] ?? false;
1674
+ }
1675
+ }
1676
+ if (nodeToRelocate && typeof slotRefNode["s-rf"] === "function") slotRefNode["s-rf"](slotRefNode);
1677
+ } else if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) nodeToRelocate.hidden = true;
1678
+ }
1679
+ }
1680
+ if (checkSlotFallbackVisibility) updateFallbackSlotVisibility(rootVnode.$elm$);
1681
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
1682
+ relocateNodes.length = 0;
1683
+ }
1684
+ if (BUILD.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
1685
+ const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
1686
+ for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
1687
+ if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
1688
+ if (childNode.nodeType === NODE_TYPE.ElementNode) childNode.hidden = true;
1689
+ else if (childNode.nodeType === NODE_TYPE.TextNode && !!childNode.nodeValue.trim()) {
1690
+ const textCommentNode = win.document.createComment("s-nt-" + childNode.nodeValue);
1691
+ textCommentNode["s-sn"] = childNode["s-sn"];
1692
+ insertBefore(childNode.parentNode, textCommentNode, childNode, isInitialLoad);
1693
+ childNode.parentNode.removeChild(childNode);
1694
+ }
1695
+ }
1696
+ }
1697
+ contentRef = void 0;
1698
+ flushQueuedRefCallbacks();
1699
+ };
1700
+ const slotReferenceDebugNode = (slotVNode) => win.document?.createComment(`<slot${slotVNode.$name$ ? " name=\"" + slotVNode.$name$ + "\"" : ""}> (host=${hostTagName.toLowerCase()})`);
1701
+ const originalLocationDebugNode = (nodeToRelocate) => win.document?.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate["s-hn"]})` : `[${nodeToRelocate.textContent}]`));
1702
+ //#endregion
1703
+ //#region src/runtime/update-component.ts
1704
+ /**
1705
+ * Get a promise that resolves once `hostRef`'s real `connectedCallback` has fired for the first time.
1706
+ *
1707
+ * @param hostRef the component's host reference
1708
+ * @returns a promise that resolves once the component's real `connectedCallback` has fired
1709
+ */
1710
+ const ensureFirstConnectPromise = (hostRef) => {
1711
+ if (!hostRef.$onFirstConnectPromise$) hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
1712
+ return hostRef.$onFirstConnectPromise$;
1713
+ };
1714
+ const attachToAncestor = (hostRef, ancestorComponent) => {
1715
+ if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
1716
+ const index = ancestorComponent["s-p"].push(new Promise((r) => hostRef.$onRenderResolve$ = () => {
1717
+ ancestorComponent["s-p"].splice(index - 1, 1);
1718
+ r();
1719
+ }));
1720
+ if (ancestorComponent["s-pc"]) ancestorComponent["s-pc"].push(ensureFirstConnectPromise(hostRef));
1721
+ }
1722
+ };
1723
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
1724
+ if (BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
1725
+ if (BUILD.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
1726
+ hostRef.$flags$ |= HOST_FLAGS.needsRerender;
1727
+ return;
1728
+ }
1729
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1730
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1731
+ if (isInitialLoad) {
1732
+ const pendingConnects = BUILD.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
1733
+ if (pendingConnects && pendingConnects.length > 0) return Promise.all(pendingConnects).then(dispatch).catch(dispatch);
1734
+ queueMicrotask(() => {
1735
+ dispatch();
1736
+ });
1737
+ return;
1738
+ }
1739
+ return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
1740
+ };
1741
+ /**
1742
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
1743
+ * component lifecycle methods like `componentWillLoad` as well as
1744
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
1745
+ *
1746
+ * @param hostRef a reference to a host DOM node
1747
+ * @param isInitialLoad whether we're on the initial load or not
1748
+ * @returns an empty Promise which is used to enqueue a series of operations for
1749
+ * the component
1750
+ */
1751
+ const dispatchHooks = (hostRef, isInitialLoad) => {
1752
+ const elm = hostRef.$hostElement$;
1753
+ const endSchedule = createTime("scheduleUpdate", hostRef.$cmpMeta$.$tagName$);
1754
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1755
+ /**
1756
+ * Given a user imports a component compiled with a `dist-custom-element`
1757
+ * output target into a Stencil project compiled with a `dist` output target,
1758
+ * then `instance` will be `undefined` as `hostRef` won't have a `lazyInstance`
1759
+ * property. In this case, the component will fail to render in one of the
1760
+ * subsequent functions.
1761
+ *
1762
+ * For this scenario to work the user needs to set the `externalRuntime` flag
1763
+ * for the `dist-custom-element` component that is being imported into the `dist`
1764
+ * Stencil project.
1765
+ */
1766
+ if (!instance) {
1767
+ if (BUILD.isDev) throw new Error(`Can't render <${elm.tagName.toLowerCase()} /> - compiled without externalRuntime: true. See https://stenciljs.com/docs/custom-elements#externalruntime`);
1768
+ return;
1769
+ }
1770
+ let maybePromise;
1771
+ if (isInitialLoad) {
1772
+ if (BUILD.lazyLoad) {
1773
+ if (BUILD.hostListener) {
1774
+ hostRef.$flags$ |= HOST_FLAGS.isListenReady;
1775
+ if (hostRef.$queuedListeners$) {
1776
+ hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event, elm));
1777
+ hostRef.$queuedListeners$ = void 0;
1778
+ }
1779
+ }
1780
+ if (hostRef.$fetchedCbList$.length) hostRef.$fetchedCbList$.forEach((cb) => cb(elm));
1781
+ }
1782
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillLoad");
1783
+ maybePromise = safeCall(instance, "componentWillLoad", void 0, elm);
1784
+ } else {
1785
+ if (BUILD.updatable && hostRef.$queuedPropChanges$) {
1786
+ const changes = hostRef.$queuedPropChanges$;
1787
+ hostRef.$queuedPropChanges$ = void 0;
1788
+ if (safeCall(instance, "componentShouldUpdate", changes, elm) === false) {
1789
+ hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
1790
+ return;
1791
+ }
1792
+ }
1793
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillUpdate");
1794
+ maybePromise = safeCall(instance, "componentWillUpdate", void 0, elm);
1795
+ }
1796
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillRender");
1797
+ maybePromise = enqueue(maybePromise, () => safeCall(instance, "componentWillRender", void 0, elm));
1798
+ endSchedule();
1799
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
1800
+ };
1801
+ /**
1802
+ * This function uses a Promise to implement a simple first-in, first-out queue
1803
+ * of functions to be called.
1804
+ *
1805
+ * The queue is ordered on the basis of the first argument. If it's
1806
+ * `undefined`, then nothing is on the queue yet, so the provided function can
1807
+ * be called synchronously (although note that this function may return a
1808
+ * `Promise`). The idea is that then the return value of that enqueueing
1809
+ * operation is kept around, so that if it was a `Promise` then subsequent
1810
+ * functions can be enqueued by calling this function again with that `Promise`
1811
+ * as the first argument.
1812
+ *
1813
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
1814
+ * @param fn a function to enqueue
1815
+ * @returns either a `Promise` or the return value of the provided function
1816
+ */
1817
+ const enqueue = (maybePromise, fn) => {
1818
+ if (isPromisey(maybePromise)) return maybePromise.then(fn).catch((err) => {
1819
+ console.error(err);
1820
+ fn();
1821
+ });
1822
+ const result = fn();
1823
+ return isPromisey(result) ? result : void 0;
1824
+ };
1825
+ /**
1826
+ * Check that a value is a `Promise`. To check, we first see if the value is an
1827
+ * instance of the `Promise` global. In a few circumstances, in particular if
1828
+ * the global has been overwritten, this is could be misleading, so we also do
1829
+ * a little 'duck typing' check to see if the `.then` property of the value is
1830
+ * defined and a function.
1831
+ *
1832
+ * @param maybePromise it might be a promise!
1833
+ * @returns whether it is or not
1834
+ */
1835
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise || maybePromise && maybePromise.then && typeof maybePromise.then === "function";
1836
+ /**
1837
+ * Update a component given reference to its host elements and so on.
1838
+ *
1839
+ * @param hostRef an object containing references to the element's host node,
1840
+ * VDom nodes, and other metadata
1841
+ * @param instance a reference to the underlying host element where it will be
1842
+ * rendered
1843
+ * @param isInitialLoad whether or not this function is being called as part of
1844
+ * the first render cycle
1845
+ * @returns a `Promise` if the update is asynchronous, otherwise `void`
1846
+ */
1847
+ const updateComponent = (hostRef, instance, isInitialLoad) => {
1848
+ const elm = hostRef.$hostElement$;
1849
+ const endUpdate = createTime("update", hostRef.$cmpMeta$.$tagName$);
1850
+ const rc = elm["s-rc"];
1851
+ if (BUILD.style && isInitialLoad) attachStyles(hostRef);
1852
+ const endRender = createTime("render", hostRef.$cmpMeta$.$tagName$);
1853
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
1854
+ if (BUILD.hydrateServerSide) return callRender(hostRef, instance, elm, isInitialLoad).then(() => {
1855
+ afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
1856
+ });
1857
+ callRender(hostRef, instance, elm, isInitialLoad);
1858
+ afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
1859
+ };
1860
+ const afterRender = (hostRef, elm, rc, isInitialLoad, endRender, endUpdate) => {
1861
+ if (BUILD.isDev) {
1862
+ hostRef.$renderCount$ = hostRef.$renderCount$ === void 0 ? 1 : hostRef.$renderCount$ + 1;
1863
+ hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
1864
+ }
1865
+ if (BUILD.hydrateServerSide) try {
1866
+ serverSideConnected(elm);
1867
+ if (isInitialLoad) {
1868
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) elm["s-en"] = "";
1869
+ else if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.scopedCssEncapsulation) elm["s-en"] = "c";
1870
+ }
1871
+ } catch (e) {
1872
+ consoleError(e, elm);
1873
+ }
1874
+ if (BUILD.asyncLoading && rc) {
1875
+ rc.map((cb) => cb());
1876
+ elm["s-rc"] = void 0;
1877
+ }
1878
+ endRender();
1879
+ endUpdate();
1880
+ if (BUILD.asyncLoading) {
1881
+ const childrenPromises = elm["s-p"] ?? [];
1882
+ const postUpdate = () => postUpdateComponent(hostRef);
1883
+ if (childrenPromises.length === 0) postUpdate();
1884
+ else {
1885
+ Promise.all(childrenPromises).then(postUpdate).catch(postUpdate);
1886
+ hostRef.$flags$ |= HOST_FLAGS.isWaitingForChildren;
1887
+ childrenPromises.length = 0;
1888
+ }
1889
+ } else postUpdateComponent(hostRef);
1890
+ };
1891
+ let renderingRef = null;
1892
+ /**
1893
+ * Handle making the call to the VDom renderer with the proper context given
1894
+ * various build variables
1895
+ *
1896
+ * @param hostRef an object containing references to the element's host node,
1897
+ * VDom nodes, and other metadata
1898
+ * @param instance a reference to the underlying host element where it will be
1899
+ * rendered
1900
+ * @param elm the Host element for the component
1901
+ * @param isInitialLoad whether or not this function is being called as part of
1902
+ * @returns an empty promise
1903
+ */
1904
+ const callRender = (hostRef, instance, elm, isInitialLoad) => {
1905
+ const allRenderFn = !!BUILD.allRenderFn;
1906
+ const lazyLoad = !!BUILD.lazyLoad;
1907
+ const updatable = !!BUILD.updatable;
1908
+ try {
1909
+ renderingRef = instance;
1910
+ /**
1911
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
1912
+ * method, so we can call the method immediately. If not, check before calling it.
1913
+ */
1914
+ instance = allRenderFn ? instance.render() : instance.render && instance.render();
1915
+ if (updatable) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
1916
+ if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
1917
+ if (BUILD.hasRenderFn || BUILD.reflect) {
1918
+ if (BUILD.vdomRender || BUILD.reflect) {
1919
+ if (BUILD.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
1920
+ else renderVdom(hostRef, instance, isInitialLoad);
1921
+ } else {
1922
+ const shadowRoot = elm.shadowRoot;
1923
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
1924
+ else elm.textContent = instance;
1925
+ }
1926
+ }
1927
+ } catch (e) {
1928
+ consoleError(e, hostRef.$hostElement$);
1929
+ }
1930
+ renderingRef = null;
1931
+ return null;
1932
+ };
1933
+ const getRenderingRef = () => renderingRef;
1934
+ const postUpdateComponent = (hostRef) => {
1935
+ const tagName = hostRef.$cmpMeta$.$tagName$;
1936
+ const elm = hostRef.$hostElement$;
1937
+ const endPostUpdate = createTime("postUpdate", tagName);
1938
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1939
+ const ancestorComponent = hostRef.$ancestorComponent$;
1940
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
1941
+ safeCall(instance, "componentDidRender", void 0, elm);
1942
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
1943
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidRender");
1944
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasLoadedComponent)) {
1945
+ hostRef.$flags$ |= HOST_FLAGS.hasLoadedComponent;
1946
+ if (BUILD.asyncLoading && BUILD.cssAnnotations) addHydratedFlag(elm);
1947
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnDidLoad;
1948
+ safeCall(instance, "componentDidLoad", void 0, elm);
1949
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnDidLoad;
1950
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidLoad");
1951
+ if (BUILD.propChangeCallback) hostRef.$flags$ |= HOST_FLAGS.isWatchReady;
1952
+ endPostUpdate();
1953
+ if (BUILD.asyncLoading) {
1954
+ hostRef.$onReadyResolve$(elm);
1955
+ if (!ancestorComponent) appDidLoad(tagName);
1956
+ }
1957
+ } else {
1958
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
1959
+ safeCall(instance, "componentDidUpdate", void 0, elm);
1960
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
1961
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidUpdate");
1962
+ endPostUpdate();
1963
+ }
1964
+ if (BUILD.method && BUILD.lazyLoad) hostRef.$onInstanceResolve$(elm);
1965
+ if (BUILD.asyncLoading) {
1966
+ if (hostRef.$onRenderResolve$) {
1967
+ hostRef.$onRenderResolve$();
1968
+ hostRef.$onRenderResolve$ = void 0;
1969
+ }
1970
+ if (hostRef.$flags$ & HOST_FLAGS.needsRerender) nextTick(() => scheduleUpdate(hostRef, false));
1971
+ hostRef.$flags$ &= ~(HOST_FLAGS.isWaitingForChildren | HOST_FLAGS.needsRerender);
1972
+ }
1973
+ };
1974
+ const forceUpdate = (ref) => {
1975
+ if (BUILD.updatable && (Build.isBrowser || Build.isTesting)) {
1976
+ const hostRef = getHostRef(ref);
1977
+ const isConnected = hostRef?.$hostElement$?.isConnected;
1978
+ if (isConnected && (hostRef.$flags$ & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered) scheduleUpdate(hostRef, false);
1979
+ return isConnected;
1980
+ }
1981
+ return false;
1982
+ };
1983
+ const appDidLoad = (who) => {
1984
+ if (BUILD.asyncQueue) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
1985
+ nextTick(() => emitEvent(win, "appload", { detail: { namespace: "app" } }));
1986
+ if (BUILD.hydrateClientSide) {
1987
+ if (plt.$orgLocNodes$?.size) plt.$orgLocNodes$.clear();
1988
+ }
1989
+ if (BUILD.profile && performance.measure) performance.measure(`[Stencil] app initial load (by ${who})`, "st:app:start");
1990
+ };
1991
+ /**
1992
+ * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
1993
+ * e.g. custom element node. If a build figures out that e.g. no component
1994
+ * has a `componentDidLoad` method, the instance method gets removed from the
1995
+ * output bundle and this function returns `undefined`.
1996
+ * @param instance any object that may or may not contain methods
1997
+ * @param method method name
1998
+ * @param arg single arbitrary argument
1999
+ * @param elm the element which made the call
2000
+ * @returns result of method call if it exists, otherwise `undefined`
2001
+ */
2002
+ const safeCall = (instance, method, arg, elm) => {
2003
+ if (instance && instance[method]) try {
2004
+ return instance[method](arg);
2005
+ } catch (e) {
2006
+ consoleError(e, elm);
2007
+ }
2008
+ };
2009
+ /**
2010
+ * For debugging purposes as `BUILD.lifecycleDOMEvents` is `false` by default and will
2011
+ * get removed by the compiler. Used for timing events to see how long they take.
2012
+ * @param elm the target of the Event
2013
+ * @param lifecycleName name of the event
2014
+ */
2015
+ const emitLifecycleEvent = (elm, lifecycleName) => {
2016
+ if (BUILD.lifecycleDOMEvents) emitEvent(elm, "stencil_" + lifecycleName, {
2017
+ bubbles: true,
2018
+ composed: true,
2019
+ detail: { namespace: "app" }
2020
+ });
2021
+ };
2022
+ /**
2023
+ * Set the hydrated flag on a DOM element
2024
+ *
2025
+ * @param elm a reference to a DOM element
2026
+ * @returns undefined
2027
+ */
2028
+ const addHydratedFlag = (elm) => BUILD.hydratedClass ? elm.classList.add(BUILD.hydratedSelectorName ?? "hydrated") : BUILD.hydratedAttribute ? elm.setAttribute(BUILD.hydratedSelectorName ?? "hydrated", "") : void 0;
2029
+ const serverSideConnected = (elm) => {
2030
+ const children = elm.children;
2031
+ if (children != null) for (let i = 0, ii = children.length; i < ii; i++) {
2032
+ const childElm = children[i];
2033
+ if (typeof childElm.connectedCallback === "function") childElm.connectedCallback();
2034
+ serverSideConnected(childElm);
2035
+ }
2036
+ };
2037
+ //#endregion
2038
+ //#region src/runtime/signals.ts
2039
+ /**
2040
+ * Duck-type check for Signal objects. Cross-bundle-safe (no instanceof).
2041
+ * @param v value to test
2042
+ * @returns whether `v` implements the SignalLike interface
2043
+ */
2044
+ const isSignalLike = (v) => v !== null && typeof v === "object" && typeof v.peek === "function" && typeof v.subscribe === "function";
2045
+ //#endregion
2046
+ //#region src/runtime/vdom/h.ts
2047
+ /**
2048
+ * Production h() function based on Preact by
2049
+ * Jason Miller (@developit)
2050
+ * Licensed under the MIT License
2051
+ * https://github.com/developit/preact/blob/master/LICENSE
2052
+ *
2053
+ * Modified for Stencil's compiler and vdom
2054
+ */
2055
+ const h = (nodeName, vnodeData, ...children) => {
2056
+ if (typeof nodeName === "string") nodeName = transformTag(nodeName);
2057
+ let child = null;
2058
+ let key = null;
2059
+ let slotName = null;
2060
+ let simple = false;
2061
+ let lastSimple = false;
2062
+ const vNodeChildren = [];
2063
+ const walk = (c) => {
2064
+ for (let i = 0; i < c.length; i++) {
2065
+ child = c[i];
2066
+ if (Array.isArray(child)) walk(child);
2067
+ else if (child != null && typeof child !== "boolean") {
2068
+ if (BUILD.vdomSignals && isSignalLike(child)) {
2069
+ const sigVNode = newVNode(null, String(child.peek()));
2070
+ sigVNode.$signal$ = child;
2071
+ vNodeChildren.push(sigVNode);
2072
+ lastSimple = false;
2073
+ } else {
2074
+ if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
2075
+ else if (typeof nodeName !== "function" && child.$flags$ === void 0) {
2076
+ if (BUILD.isDev) consoleDevError(`vNode passed as children has unexpected type.
2077
+ Make sure it's using the correct h() function.
2078
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
2079
+ else consoleError("Invalid vNode child");
2080
+ continue;
2081
+ }
2082
+ if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
2083
+ else vNodeChildren.push(simple ? newVNode(null, child) : child);
2084
+ lastSimple = simple;
2085
+ }
2086
+ }
2087
+ }
2088
+ };
2089
+ walk(children);
2090
+ if (vnodeData) {
2091
+ if (BUILD.isDev && nodeName === "input") validateInputProperties(vnodeData);
2092
+ if (BUILD.vdomKey && vnodeData.key) key = vnodeData.key;
2093
+ if (BUILD.slotRelocation && vnodeData.name) slotName = vnodeData.name;
2094
+ if (BUILD.vdomClass) {
2095
+ const classData = vnodeData.class;
2096
+ if (classData && !(BUILD.vdomSignals && isSignalLike(classData))) vnodeData.class = typeof classData !== "object" ? classData : Object.keys(classData).filter((k) => classData[k]).join(" ");
2097
+ }
2098
+ }
2099
+ if (BUILD.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be the single root component. Make sure:
2100
+ - You are NOT using hostData() and <Host> in the same component.
2101
+ - <Host> is used once, and it's the single root component of the render() function.`);
2102
+ if (BUILD.vdomFunctional && typeof nodeName === "function") return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
2103
+ const vnode = newVNode(nodeName, null);
2104
+ vnode.$attrs$ = vnodeData;
2105
+ if (vNodeChildren.length > 0) vnode.$children$ = vNodeChildren;
2106
+ if (BUILD.vdomKey) vnode.$key$ = key;
2107
+ if (BUILD.slotRelocation) vnode.$name$ = slotName;
2108
+ return vnode;
2109
+ };
2110
+ /**
2111
+ * A utility function for creating a virtual DOM node from a tag and some
2112
+ * possible text content.
2113
+ *
2114
+ * @param tag the tag for this element
2115
+ * @param text possible text content for the node
2116
+ * @returns a newly-minted virtual DOM node
2117
+ */
2118
+ const newVNode = (tag, text) => {
2119
+ const vnode = {
2120
+ $flags$: 0,
2121
+ $tag$: tag,
2122
+ $text$: text ?? null,
2123
+ $elm$: null,
2124
+ $children$: null
2125
+ };
2126
+ if (BUILD.vdomAttribute) vnode.$attrs$ = null;
2127
+ if (BUILD.vdomKey) vnode.$key$ = null;
2128
+ if (BUILD.slotRelocation) vnode.$name$ = null;
2129
+ return vnode;
2130
+ };
2131
+ const Host = {};
2132
+ /**
2133
+ * Check whether a given node is a Host node or not
2134
+ *
2135
+ * @param node the virtual DOM node to check
2136
+ * @returns whether it's a Host node or not
2137
+ */
2138
+ const isHost = (node) => node && node.$tag$ === Host;
2139
+ /**
2140
+ * Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
2141
+ *
2142
+ * Note that these functions convert from {@link d.VNode} to
2143
+ * {@link d.ChildNode} to give functional component developers a friendly
2144
+ * interface.
2145
+ */
2146
+ const vdomFnUtils = {
2147
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
2148
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate)
2149
+ };
2150
+ /**
2151
+ * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
2152
+ * friendlier public interface (hence, 'convertToPublic').
2153
+ *
2154
+ * @param node the virtual DOM node to convert
2155
+ * @returns a converted child node
2156
+ */
2157
+ const convertToPublic = (node) => ({
2158
+ vattrs: node.$attrs$,
2159
+ vchildren: node.$children$,
2160
+ vkey: node.$key$,
2161
+ vname: node.$name$,
2162
+ vtag: node.$tag$,
2163
+ vtext: node.$text$
2164
+ });
2165
+ /**
2166
+ * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
2167
+ * order to use the resulting object in the virtual DOM. The initial object was
2168
+ * likely created as part of presenting a public API, so converting it back
2169
+ * involved making it 'private' again (hence, `convertToPrivate`).
2170
+ *
2171
+ * @param node the child node to convert
2172
+ * @returns a converted virtual DOM node
2173
+ */
2174
+ const convertToPrivate = (node) => {
2175
+ if (typeof node.vtag === "function") {
2176
+ const vnodeData = { ...node.vattrs };
2177
+ if (node.vkey) vnodeData.key = node.vkey;
2178
+ if (node.vname) vnodeData.name = node.vname;
2179
+ return h(node.vtag, vnodeData, ...node.vchildren || []);
2180
+ }
2181
+ const vnode = newVNode(node.vtag, node.vtext);
2182
+ vnode.$attrs$ = node.vattrs;
2183
+ vnode.$children$ = node.vchildren;
2184
+ vnode.$key$ = node.vkey;
2185
+ vnode.$name$ = node.vname;
2186
+ return vnode;
2187
+ };
2188
+ /**
2189
+ * Validates the ordering of attributes on an input element
2190
+ *
2191
+ * @param inputElm the element to validate
2192
+ */
2193
+ const validateInputProperties = (inputElm) => {
2194
+ const props = Object.keys(inputElm);
2195
+ const value = props.indexOf("value");
2196
+ if (value === -1) return;
2197
+ const typeIndex = props.indexOf("type");
2198
+ const minIndex = props.indexOf("min");
2199
+ const maxIndex = props.indexOf("max");
2200
+ const stepIndex = props.indexOf("step");
2201
+ if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
2202
+ };
2203
+ //#endregion
2204
+ //#region src/runtime/mode.ts
2205
+ const setMode = (handler) => modeResolutionChain.push(handler);
2206
+ const getMode = (ref) => getHostRef(ref)?.$modeName$;
2207
+ //#endregion
2208
+ //#region src/runtime/mixin.ts
2209
+ const baseClass = BUILD.lazyLoad ? class {} : globalThis.HTMLElement || class {};
2210
+ function Mixin(...mixins) {
2211
+ return mixins.reduceRight((acc, mixin) => mixin(acc), baseClass);
2212
+ }
2213
+ //#endregion
2214
+ //#region src/runtime/reactive-controller.ts
2215
+ const ReactiveControllerHost = (Base) => class ReactiveControllerHostMixin extends Base {
2216
+ controllers = /* @__PURE__ */ new Set();
2217
+ #connected = false;
2218
+ #updateCompleteResolvers = [];
2219
+ addController(controller) {
2220
+ this.controllers.add(controller);
2221
+ if (this.#connected) controller.hostConnected?.();
2222
+ }
2223
+ removeController(controller) {
2224
+ this.controllers.delete(controller);
2225
+ }
2226
+ requestUpdate() {
2227
+ forceUpdate(this);
2228
+ }
2229
+ get updateComplete() {
2230
+ return new Promise((resolve) => this.#updateCompleteResolvers.push(resolve));
2231
+ }
2232
+ connectedCallback() {
2233
+ super.connectedCallback?.();
2234
+ this.#connected = true;
2235
+ const el = getElement(this);
2236
+ if (el && el !== this) {
2237
+ el.addController = (controller) => this.addController(controller);
2238
+ el.removeController = (controller) => this.removeController(controller);
2239
+ el.requestUpdate = () => this.requestUpdate();
2240
+ Object.defineProperty(el, "updateComplete", {
2241
+ configurable: true,
2242
+ get: () => this.updateComplete
2243
+ });
2244
+ }
2245
+ this.controllers.forEach((c) => c.hostConnected?.());
2246
+ }
2247
+ disconnectedCallback() {
2248
+ super.disconnectedCallback?.();
2249
+ this.#connected = false;
2250
+ this.controllers.forEach((c) => c.hostDisconnected?.());
2251
+ }
2252
+ async componentWillLoad() {
2253
+ await super.componentWillLoad?.();
2254
+ await Promise.all([...this.controllers].map((c) => c.hostWillLoad?.()));
2255
+ }
2256
+ componentDidLoad() {
2257
+ super.componentDidLoad?.();
2258
+ this.controllers.forEach((c) => c.hostDidLoad?.());
2259
+ }
2260
+ async componentWillRender() {
2261
+ await super.componentWillRender?.();
2262
+ await Promise.all([...this.controllers].map((c) => c.hostWillRender?.()));
2263
+ }
2264
+ componentDidRender() {
2265
+ super.componentDidRender?.();
2266
+ this.controllers.forEach((c) => c.hostDidRender?.());
2267
+ const resolvers = this.#updateCompleteResolvers;
2268
+ this.#updateCompleteResolvers = [];
2269
+ resolvers.forEach((resolve) => resolve(true));
2270
+ }
2271
+ async componentWillUpdate() {
2272
+ await super.componentWillUpdate?.();
2273
+ await Promise.all([...this.controllers].map((c) => c.hostWillUpdate?.()));
2274
+ }
2275
+ componentDidUpdate() {
2276
+ super.componentDidUpdate?.();
2277
+ this.controllers.forEach((c) => c.hostDidUpdate?.());
2278
+ }
2279
+ };
2280
+ //#endregion
2281
+ //#region src/runtime/render.ts
2282
+ /**
2283
+ * A WeakMap to persist HostRef objects across multiple render() calls to the
2284
+ * same container. This enables VNode diffing on re-renders - without it, each
2285
+ * call creates a fresh HostRef with no previous VNode, causing renderVdom to
2286
+ * replace the entire DOM subtree instead of patching only what changed.
2287
+ */
2288
+ const hostRefCache = /* @__PURE__ */ new WeakMap();
2289
+ /**
2290
+ * Method to render a virtual DOM tree to a container element.
2291
+ *
2292
+ * Supports efficient re-renders: calling `render()` again on the same container
2293
+ * will diff the new VNode tree against the previous one and only update what changed,
2294
+ * preserving existing DOM elements and their state.
2295
+ *
2296
+ * @example
2297
+ * ```tsx
2298
+ * import { render } from '@stencil/core';
2299
+ *
2300
+ * const vnode = (
2301
+ * <div>
2302
+ * <h1>Hello, world!</h1>
2303
+ * </div>
2304
+ * );
2305
+ * render(vnode, document.body);
2306
+ * ```
2307
+ *
2308
+ * @param vnode - The virtual DOM tree to render
2309
+ * @param container - The container element to render the virtual DOM tree to
2310
+ */
2311
+ function render(vnode, container) {
2312
+ let ref = hostRefCache.get(container);
2313
+ if (!ref) {
2314
+ ref = {
2315
+ $flags$: 0,
2316
+ $cmpMeta$: {
2317
+ $flags$: 0,
2318
+ $tagName$: container.tagName
2319
+ },
2320
+ $hostElement$: container
2321
+ };
2322
+ hostRefCache.set(container, ref);
2323
+ }
2324
+ renderVdom(ref, vnode);
2325
+ }
2326
+ //#endregion
2327
+ //#region src/runtime/tag-transform.ts
2328
+ let tagTransformer = void 0;
2329
+ /**
2330
+ * Transforms a tag name using the current tag transformer
2331
+ * @param tag - the tag to transform e.g. `my-tag`
2332
+ * @returns the transformed tag e.g. `new-my-tag`
2333
+ */
2334
+ function transformTag(tag) {
2335
+ if (!tagTransformer) return tag;
2336
+ return tagTransformer(tag);
2337
+ }
2338
+ /**
2339
+ * Sets the tag transformer to be used when rendering custom elements
2340
+ * @param transformer the transformer function to use. Must return a string
2341
+ */
2342
+ function setTagTransformer(transformer) {
2343
+ tagTransformer = transformer;
2344
+ }
2345
+ //#endregion
2346
+ //#region src/runtime/vdom/jsx-runtime.ts
2347
+ function jsx(type, props, key) {
2348
+ const { children, ...rest } = props ?? {};
2349
+ if (key !== void 0 && !("key" in rest)) rest.key = key;
2350
+ const attrs = hasKeys(rest) ? rest : null;
2351
+ if (children !== void 0) return Array.isArray(children) ? h(type, attrs, ...children) : h(type, attrs, children);
2352
+ return h(type, attrs);
2353
+ }
2354
+ /**
2355
+ * @alias
2356
+ */
2357
+ const jsxs = jsx;
2358
+ /**
2359
+ * @alias
2360
+ */
2361
+ const jsxDEV = jsx;
2362
+ function hasKeys(obj) {
2363
+ for (const _ in obj) return true;
2364
+ return false;
2365
+ }
2366
+ //#endregion
2367
+ export { setErrorHandler as C, HYDRATED_CSS as S, getAssetPath as _, transformTag as a, writeTask as b, Mixin as c, Host as d, h as f, getShadowRoot as g, getElement as h, setTagTransformer as i, getMode as l, getRenderingRef as m, jsxDEV as n, render as o, forceUpdate as p, jsxs as r, ReactiveControllerHost as s, jsx as t, setMode as u, setAssetPath as v, Build as w, setPlatformHelpers as x, readTask as y };