@stencil/core 5.0.0-alpha.1 → 5.0.0-alpha.11

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 (50) hide show
  1. package/dist/app-data/index.d.ts +2 -0
  2. package/dist/{runtime/app-data → app-data}/index.js +17 -12
  3. package/dist/{client-B1nuvCd2.mjs → client-aTQ7xHxx.mjs} +2432 -2278
  4. package/dist/compiler/index.d.mts +6 -6
  5. package/dist/compiler/index.mjs +2 -2
  6. package/dist/compiler/utils/index.d.mts +2 -2
  7. package/dist/compiler/utils/index.mjs +3 -3
  8. package/dist/{compiler-LX4_RKKd.mjs → compiler-DCN7Np2A.mjs} +14854 -13500
  9. package/dist/declarations/stencil-public-compiler.d.ts +4374 -2
  10. package/dist/declarations/stencil-public-compiler.js +2 -4
  11. package/dist/declarations/stencil-public-docs.d.ts +504 -1
  12. package/dist/declarations/stencil-public-runtime.d.ts +1982 -2
  13. package/dist/{index-fIuYTL9f.d.mts → index-BvkyxSY6.d.mts} +29 -2
  14. package/dist/{index-D-LlB2nw.d.mts → index-vY35H18z.d.mts} +795 -1188
  15. package/dist/{index-BONzXKJt.d.ts → index-xAkMgLX_.d.ts} +88 -39
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +2 -2
  18. package/dist/jsx-runtime.d.mts +18 -0
  19. package/dist/jsx-runtime.mjs +2 -0
  20. package/dist/{node-SxQIOCZE.mjs → node--akYC-sG.mjs} +20 -30
  21. package/dist/regular-expression-CFVJOTUh.mjs +508 -0
  22. package/dist/{runtime-CF9DJtSu.js → runtime/client/lazy.js} +2675 -2493
  23. package/dist/runtime/client/{index.d.ts → runtime.d.ts} +106 -78
  24. package/dist/runtime/client/{index.js → runtime.js} +2545 -2487
  25. package/dist/runtime/index.d.ts +58 -29
  26. package/dist/runtime/index.js +4795 -2
  27. package/dist/runtime/server/index.d.mts +103 -70
  28. package/dist/runtime/server/index.mjs +2545 -2350
  29. package/dist/runtime/server/runner.d.mts +44 -48
  30. package/dist/runtime/server/runner.mjs +347 -751
  31. package/dist/signals/index.d.ts +47 -0
  32. package/dist/signals/index.js +199 -0
  33. package/dist/sys/node/index.d.mts +1 -1
  34. package/dist/sys/node/index.mjs +1 -1
  35. package/dist/sys/node/worker.mjs +2 -2
  36. package/dist/testing/index.d.mts +97 -3
  37. package/dist/testing/index.mjs +367 -59
  38. package/dist/{validation-CaCgjw-f.mjs → validation-ByxKj8bC.mjs} +116 -99
  39. package/package.json +47 -38
  40. package/dist/index-CHjZtib0.d.ts +0 -30
  41. package/dist/jsx-runtime-DBzBJLKk.d.ts +0 -28
  42. package/dist/jsx-runtime.d.ts +0 -2
  43. package/dist/jsx-runtime.js +0 -2
  44. package/dist/runtime/app-data/index.d.ts +0 -2
  45. package/dist/serialize-BkYHk7Mi.mjs +0 -766
  46. package/dist/stencil-public-compiler-C_X1iolo.d.ts +0 -4455
  47. package/dist/stencil-public-runtime-DlV8o7-z.d.ts +0 -1845
  48. /package/dist/{runtime/app-globals → app-globals}/index.d.ts +0 -0
  49. /package/dist/{runtime/app-globals → app-globals}/index.js +0 -0
  50. /package/dist/{chunk-CjcI7cDX.mjs → chunk-z9aeyW2b.mjs} +0 -0
@@ -1,2 +1,4795 @@
1
- import { A as Host, C as postUpdateComponent, D as parsePropertyValue, E as getElement, M as getAssetPath, N as setAssetPath, O as getMode, P as HYDRATED_STYLE_ID, S as getRenderingRef, T as createEvent, _ as connectedCallback, a as transformTag, b as setValue, c as setNonce, d as Fragment, f as bootstrapLazy, g as disconnectedCallback, h as proxyCustomElement, i as setTagTransformer, j as h, k as setMode, l as Mixin, m as forceModeUpdate, n as jsx, o as render, p as defineCustomElement, r as jsxs, s as setPlatformOptions, t as insertVdomAnnotations, u as addHostEventListeners, v as proxyComponent, w as renderVdom, x as forceUpdate, y as getValue } from "../runtime-CF9DJtSu.js";
2
- export { Fragment, HYDRATED_STYLE_ID, Host, Mixin, addHostEventListeners, bootstrapLazy, connectedCallback, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getMode, getRenderingRef, getValue, h, insertVdomAnnotations, jsx, jsxs, parsePropertyValue, postUpdateComponent, proxyComponent, proxyCustomElement, render, renderVdom, setAssetPath, setMode, setNonce, setPlatformOptions, setTagTransformer, setValue, transformTag };
1
+ import { BUILD } from "../app-data/index.js";
2
+ import "../app-globals/index.js";
3
+ import { effect, effect as effect$1, signal } from "@preact/signals-core";
4
+ //#region src/client/client-build.ts
5
+ const Build = {
6
+ isDev: BUILD.isDev,
7
+ isBrowser: true,
8
+ isServer: false,
9
+ isTesting: BUILD.isTesting
10
+ };
11
+ const MEMBER_FLAGS = {
12
+ String: 1,
13
+ Number: 2,
14
+ Boolean: 4,
15
+ Any: 8,
16
+ Unknown: 16,
17
+ State: 32,
18
+ Method: 64,
19
+ Event: 128,
20
+ Element: 256,
21
+ ReflectAttr: 512,
22
+ Mutable: 1024,
23
+ Getter: 2048,
24
+ Setter: 4096,
25
+ Prop: 31,
26
+ HasAttribute: 31,
27
+ PropLike: 63
28
+ };
29
+ const WATCH_FLAGS = { Immediate: 1 };
30
+ const EVENT_FLAGS = {
31
+ Cancellable: 1,
32
+ Composed: 2,
33
+ Bubbles: 4
34
+ };
35
+ const LISTENER_FLAGS = {
36
+ Passive: 1,
37
+ Capture: 2,
38
+ TargetDocument: 4,
39
+ TargetWindow: 8,
40
+ TargetBody: 16
41
+ };
42
+ const HOST_FLAGS = {
43
+ hasConnected: 1,
44
+ hasRendered: 2,
45
+ isWaitingForChildren: 4,
46
+ isConstructingInstance: 8,
47
+ isQueuedForUpdate: 16,
48
+ hasInitializedComponent: 32,
49
+ hasLoadedComponent: 64,
50
+ isWatchReady: 128,
51
+ isListenReady: 256,
52
+ needsRerender: 512,
53
+ devOnRender: 1024,
54
+ devOnDidLoad: 2048
55
+ };
56
+ const CF_scopedCssEncapsulation = 2;
57
+ /**
58
+ * A set of flags used for bitwise calculations against {@link ComponentRuntimeMeta#$flags$}.
59
+ *
60
+ * These flags should only be used in conjunction with {@link ComponentRuntimeMeta#$flags$}.
61
+ * They should _not_ be used for calculations against other fields/numbers
62
+ */
63
+ const CMP_FLAGS = {
64
+ /**
65
+ * Used to determine if a component is using the shadow DOM.
66
+ * e.g. `shadow: true | {}` is set on the `@Component()` decorator
67
+ */
68
+ shadowDomEncapsulation: 1,
69
+ /**
70
+ * Used to determine if a component is using scoped stylesheets
71
+ * e.g. `scoped: true` is set on the `@Component()` decorator
72
+ */
73
+ scopedCssEncapsulation: CF_scopedCssEncapsulation,
74
+ /**
75
+ * Used to determine if a component does not use the shadow DOM _and_ has `<slot/>` tags in its markup.
76
+ */
77
+ hasSlotRelocation: 4,
78
+ /**
79
+ * Determines if `delegatesFocus` is enabled for a component that uses the shadow DOM.
80
+ * e.g. `shadow: { delegatesFocus: true }` is set on the `@Component()` decorator
81
+ */
82
+ shadowDelegatesFocus: 16,
83
+ /**
84
+ * Determines if `mode` is set on the `@Component()` decorator
85
+ */
86
+ hasMode: 32,
87
+ /**
88
+ * Determines if styles must be scoped - i.e. the component uses scoped stylesheets.
89
+ */
90
+ needsScopedEncapsulation: CF_scopedCssEncapsulation,
91
+ /**
92
+ * Determines if a component is form-associated or not. This is set based on
93
+ * options passed to the `@Component` decorator.
94
+ */
95
+ formAssociated: 64,
96
+ /**
97
+ * Determines if a `shadow: true` component needs
98
+ * to have its styles scoped during SSR as opposed to using DSD.
99
+ */
100
+ shadowNeedsScopedCss: 128,
101
+ /**
102
+ * Determines if a component has a `<slot>` in its template.
103
+ */
104
+ hasSlot: 256,
105
+ /**
106
+ * Determines if a component uses modern class property declarations.
107
+ */
108
+ hasModernPropertyDecls: 512,
109
+ /**
110
+ * Determines if `slotAssignment` is set to `'manual'` for a component that uses the shadow DOM.
111
+ * e.g. `shadow: { slotAssignment: 'manual' }` is set on the `@Component()` decorator
112
+ */
113
+ shadowSlotAssignmentManual: 1024,
114
+ /**
115
+ * Determines if the shadow DOM mode is 'closed'.
116
+ * e.g. `encapsulation: { type: 'shadow', mode: 'closed' }` is set on the `@Component()` decorator
117
+ */
118
+ shadowModeClosed: 2048,
119
+ /**
120
+ * Determines if the component should patch child node accessors for slot handling.
121
+ * e.g. `encapsulation: { type: 'none', patches: ['children'] }`
122
+ */
123
+ patchChildren: 4096,
124
+ /**
125
+ * Determines if the component should patch cloneNode() for slot handling.
126
+ * e.g. `encapsulation: { type: 'none', patches: ['clone'] }`
127
+ */
128
+ patchClone: 8192,
129
+ /**
130
+ * Determines if the component should patch appendChild/insertBefore for slot handling.
131
+ * e.g. `encapsulation: { type: 'none', patches: ['insert'] }`
132
+ */
133
+ patchInsert: 16384,
134
+ /**
135
+ * Determines if the component should apply all slot patches.
136
+ * e.g. `encapsulation: { type: 'none', patches: ['all'] }`
137
+ * Equivalent to the global `experimentalSlotFixes` config option.
138
+ */
139
+ patchAll: 32768
140
+ };
141
+ /**
142
+ * Namespaces
143
+ */
144
+ const SVG_NS = "http://www.w3.org/2000/svg";
145
+ /**
146
+ * DOM Node types
147
+ *
148
+ * See https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
149
+ *
150
+ * Note: this is a duplicate of the `NODE_TYPES` enum in mock-doc, it's
151
+ * copied over here so that we do not need to introduce a dependency on the
152
+ * mock-doc bundle in the runtime. See
153
+ * https://github.com/stenciljs/core/pull/5705 for more details.
154
+ */
155
+ const NODE_TYPES = {
156
+ ELEMENT_NODE: 1,
157
+ ATTRIBUTE_NODE: 2,
158
+ TEXT_NODE: 3,
159
+ CDATA_SECTION_NODE: 4,
160
+ ENTITY_REFERENCE_NODE: 5,
161
+ ENTITY_NODE: 6,
162
+ PROCESSING_INSTRUCTION_NODE: 7,
163
+ COMMENT_NODE: 8,
164
+ DOCUMENT_NODE: 9,
165
+ DOCUMENT_TYPE_NODE: 10,
166
+ DOCUMENT_FRAGMENT_NODE: 11,
167
+ NOTATION_NODE: 12
168
+ };
169
+ //#endregion
170
+ //#region src/utils/get-prop-descriptor.ts
171
+ /**
172
+ * Walks up a prototype chain to find a property descriptor.
173
+ * Stops before reaching native DOM prototypes (HTMLElement, etc.) to avoid
174
+ * treating native properties like `hidden` as component-defined getters.
175
+ * @param obj - The object to search on.
176
+ * @param memberName - The name of the member to find.
177
+ * @param getOnly - If true, only returns descriptors with a getter (i.e. ignores properties that are only fields or have setters without getters).
178
+ * @returns The property descriptor if found, otherwise undefined.
179
+ */
180
+ function getPropertyDescriptor(obj, memberName, getOnly) {
181
+ const stopAt = typeof HTMLElement !== "undefined" ? HTMLElement.prototype : null;
182
+ while (obj && obj !== stopAt) {
183
+ const desc = Object.getOwnPropertyDescriptor(obj, memberName);
184
+ if (desc && (!getOnly || desc.get)) return desc;
185
+ obj = Object.getPrototypeOf(obj);
186
+ }
187
+ }
188
+ //#endregion
189
+ //#region src/utils/es2022-rewire-class-members.ts
190
+ /**
191
+ * - Re-wires component prototype `get` / `set` with instance `@State` / `@Prop` decorated fields.
192
+ * - Makes sure the initial value from the `Element` is synced to the instance `@Prop` decorated fields.
193
+ *
194
+ * Background:
195
+ * During component init, Stencil loops through any `@Prop()` or `@State()` decorated properties
196
+ * and sets up getters and setters for each (within `src/runtime/proxy-component.ts`) on a component prototype.
197
+ *
198
+ * These accessors sync-up class instances with their `Element` and controls re-renders.
199
+ * With modern JS, compiled classes (e.g. `target: 'es2022'`) compiled Stencil components went from:
200
+ *
201
+ * ```ts
202
+ * class MyComponent {
203
+ * constructor() {
204
+ * this.prop1 = 'value1';
205
+ * }
206
+ * }
207
+ * ```
208
+ * To:
209
+ * ```ts
210
+ * class MyComponent {
211
+ * prop1 = 'value2';
212
+ * // ^^ These override the accessors originally set on the prototype
213
+ * }
214
+ * ```
215
+ *
216
+ * @param instance - class instance to re-wire
217
+ * @param hostRef - component reference meta
218
+ */
219
+ const reWireGetterSetter = (instance, hostRef) => {
220
+ const cmpMeta = hostRef.$cmpMeta$;
221
+ Object.entries(cmpMeta.$members$ ?? {}).map(([memberName, [memberFlags]]) => {
222
+ if ((BUILD.state || BUILD.prop) && (memberFlags & MEMBER_FLAGS.Prop || memberFlags & MEMBER_FLAGS.State)) {
223
+ const ogValue = instance[memberName];
224
+ const ogDescriptor = getPropertyDescriptor(Object.getPrototypeOf(instance), memberName, true) || Object.getOwnPropertyDescriptor(instance, memberName);
225
+ if (ogDescriptor) Object.defineProperty(instance, memberName, {
226
+ get() {
227
+ return ogDescriptor.get.call(this);
228
+ },
229
+ set(newValue) {
230
+ ogDescriptor.set.call(this, newValue);
231
+ },
232
+ configurable: true,
233
+ enumerable: true
234
+ });
235
+ if (hostRef.$instanceValues$.has(memberName)) instance[memberName] = hostRef.$instanceValues$.get(memberName);
236
+ else if (ogValue !== void 0 && instance[memberName] !== ogValue) instance[memberName] = ogValue;
237
+ }
238
+ });
239
+ };
240
+ //#endregion
241
+ //#region src/client/client-host-ref.ts
242
+ /**
243
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
244
+ *
245
+ * @param ref the runtime ref of interest
246
+ * @returns the Host reference (if found) or undefined
247
+ */
248
+ const getHostRef = (ref) => {
249
+ if (ref.__s_ghr) return ref.__s_ghr();
250
+ };
251
+ /**
252
+ * Register a host element for a Stencil component, setting up various metadata
253
+ * and callbacks based on {@link BUILD} flags as well as the component's runtime
254
+ * metadata.
255
+ *
256
+ * @param hostElement the host element to register
257
+ * @param cmpMeta runtime metadata for that component
258
+ * @returns a reference to the host ref WeakMap
259
+ */
260
+ const registerHost = (hostElement, cmpMeta) => {
261
+ const hostRef = {
262
+ $flags$: 0,
263
+ $hostElement$: hostElement,
264
+ $cmpMeta$: cmpMeta,
265
+ $instanceValues$: /* @__PURE__ */ new Map(),
266
+ $serializerValues$: /* @__PURE__ */ new Map()
267
+ };
268
+ if (BUILD.isDev) hostRef.$renderCount$ = 0;
269
+ if (BUILD.method && BUILD.lazyLoad) hostRef.$onInstancePromise$ = new Promise((r) => hostRef.$onInstanceResolve$ = r);
270
+ if (BUILD.asyncLoading) {
271
+ hostRef.$onReadyPromise$ = new Promise((r) => hostRef.$onReadyResolve$ = r);
272
+ hostElement["s-rp"] = hostRef.$onReadyPromise$;
273
+ if (!hostElement["s-p"]) hostElement["s-p"] = [];
274
+ if (!hostElement["s-rc"]) hostElement["s-rc"] = [];
275
+ }
276
+ if (BUILD.lazyLoad) hostRef.$fetchedCbList$ = [];
277
+ const ref = hostRef;
278
+ hostElement.__s_ghr = () => ref;
279
+ if (!BUILD.lazyLoad && cmpMeta.$flags$ & CMP_FLAGS.hasModernPropertyDecls && (BUILD.state || BUILD.prop)) reWireGetterSetter(hostElement, hostRef);
280
+ return ref;
281
+ };
282
+ const isMemberInElement = (elm, memberName) => memberName in elm;
283
+ const consoleError = (e, el) => (0, console.error)(e, el);
284
+ const STENCIL_DEV_MODE = BUILD.isTesting ? ["STENCIL:"] : ["%cstencil", "color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px"];
285
+ const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
286
+ const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
287
+ //#endregion
288
+ //#region src/client/client-load-module.ts
289
+ const cmpModules = /* @__PURE__ */ new Map();
290
+ /**
291
+ * We need to separate out this prefix so that Esbuild doesn't try to resolve
292
+ * the below, but instead retains a dynamic `import()` statement in the
293
+ * emitted code.
294
+ *
295
+ * See here for details https://esbuild.github.io/api/#non-analyzable-imports
296
+ *
297
+ * We need to do this in order to prevent Esbuild from analyzing / transforming
298
+ * the input. However some _other_ bundlers will _not_ work with such an import
299
+ * if it _lacks_ a leading `"./"`, so we thus we have to do a little dance
300
+ * where here in the source code it must be like this, so that an undesirable
301
+ * transformation that Esbuild would otherwise carry out doesn't occur, but we
302
+ * actually need to then manually edit the bundled Esbuild code later on to fix
303
+ * that. We do this with plugins in the Esbuild and Rolldown bundles which
304
+ * include this file.
305
+ */
306
+ const MODULE_IMPORT_PREFIX = "./";
307
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
308
+ const exportName = cmpMeta.$tagName$.replace(/-/g, "_");
309
+ const bundleId = cmpMeta.$lazyBundleId$;
310
+ if (BUILD.isDev && typeof bundleId !== "string") {
311
+ consoleDevError(`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`);
312
+ return;
313
+ } else if (!bundleId) return;
314
+ const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
315
+ if (module) return module[exportName];
316
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
317
+ const entryFile = `${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? "?s-hmr=" + hmrVersionId : ""}`;
318
+ const onLoad = (importedModule) => {
319
+ if (!BUILD.hotModuleReplacement) cmpModules.set(bundleId, importedModule);
320
+ return importedModule[exportName];
321
+ };
322
+ const onError = (e) => consoleError(e, hostRef.$hostElement$);
323
+ return import(
324
+ /* @vite-ignore */
325
+ /* webpackInclude: /\.entry\.js$/ */
326
+ /* webpackExclude: /\.system\.entry\.js$/ */
327
+ /* webpackMode: "lazy" */
328
+ `${MODULE_IMPORT_PREFIX}${entryFile}`
329
+ ).then(onLoad, onError);
330
+ };
331
+ //#endregion
332
+ //#region src/client/client-style.ts
333
+ const styles = /* @__PURE__ */ new Map();
334
+ const modeResolutionChain = [];
335
+ const needsScopedSSR = () => false;
336
+ //#endregion
337
+ //#region src/runtime/runtime-constants.ts
338
+ /**
339
+ * Bit flags for recording various properties of VDom nodes
340
+ */
341
+ const VNODE_FLAGS = {
342
+ /**
343
+ * Whether or not a vdom node is a slot reference
344
+ */
345
+ isSlotReference: 1,
346
+ /**
347
+ * Whether or not a slot element has fallback content
348
+ */
349
+ isSlotFallback: 2,
350
+ /**
351
+ * Whether or not an element is a host element
352
+ */
353
+ isHost: 4
354
+ };
355
+ const PROXY_FLAGS = {
356
+ isElementConstructor: 1,
357
+ proxyState: 2
358
+ };
359
+ const PLATFORM_FLAGS = {
360
+ /**
361
+ * designates a node in the DOM as being actively moved by the runtime
362
+ */
363
+ isTmpDisconnected: 1,
364
+ appLoaded: 2,
365
+ queueSync: 4,
366
+ queueMask: 6
367
+ };
368
+ /**
369
+ * A (subset) of node types which are relevant for the Stencil runtime. These
370
+ * values are based on the values which can possibly be returned by the
371
+ * `.nodeType` property of a DOM node. See here for details:
372
+ *
373
+ * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
374
+ */
375
+ const NODE_TYPE = {
376
+ ElementNode: 1,
377
+ TextNode: 3,
378
+ CommentNode: 8,
379
+ DocumentNode: 9,
380
+ DocumentTypeNode: 10,
381
+ DocumentFragment: 11
382
+ };
383
+ const HYDRATE_ID = "s-id";
384
+ const HYDRATED_STYLE_ID = "sty-id";
385
+ const HYDRATE_CHILD_ID = "c-id";
386
+ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
387
+ /**
388
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
389
+ *
390
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
391
+ * support as of Stencil v4.
392
+ */
393
+ const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
394
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
395
+ const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
396
+ "formAssociatedCallback",
397
+ "formResetCallback",
398
+ "formDisabledCallback",
399
+ "formStateRestoreCallback"
400
+ ];
401
+ //#endregion
402
+ //#region src/client/client-window.ts
403
+ const win = typeof window !== "undefined" ? window : {};
404
+ win.HTMLElement;
405
+ const plt = {
406
+ $flags$: 0,
407
+ $resourcesUrl$: "",
408
+ jmp: (h) => h(),
409
+ raf: (h) => requestAnimationFrame(h),
410
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
411
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
412
+ ce: (eventName, opts) => new CustomEvent(eventName, opts)
413
+ };
414
+ const supportsListenerOptions = /* @__PURE__ */ (() => {
415
+ let supported = false;
416
+ try {
417
+ win.document?.addEventListener("e", null, Object.defineProperty({}, "passive", { get() {
418
+ supported = true;
419
+ } }));
420
+ } catch {}
421
+ return supported;
422
+ })();
423
+ const promiseResolve = (v) => Promise.resolve(v);
424
+ const supportsConstructableStylesheets = BUILD.constructableCSS ? /* @__PURE__ */ (() => {
425
+ try {
426
+ if (!win.document.adoptedStyleSheets) return false;
427
+ return typeof new CSSStyleSheet().replaceSync === "function";
428
+ } catch {}
429
+ return false;
430
+ })() : false;
431
+ const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /* @__PURE__ */ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
432
+ //#endregion
433
+ //#region src/client/client-task-queue.ts
434
+ let queueCongestion = 0;
435
+ let queuePending = false;
436
+ const queueDomReads = [];
437
+ const queueDomWrites = [];
438
+ const queueDomWritesLow = [];
439
+ const queueTask = (queue, write) => (cb) => {
440
+ queue.push(cb);
441
+ if (!queuePending) {
442
+ queuePending = true;
443
+ if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
444
+ else plt.raf(flush);
445
+ }
446
+ };
447
+ const consume = (queue) => {
448
+ for (let i = 0; i < queue.length; i++) try {
449
+ queue[i](performance.now());
450
+ } catch (e) {
451
+ consoleError(e);
452
+ }
453
+ queue.length = 0;
454
+ };
455
+ const consumeTimeout = (queue, timeout) => {
456
+ let i = 0;
457
+ let ts = 0;
458
+ while (i < queue.length && (ts = performance.now()) < timeout) try {
459
+ queue[i++](ts);
460
+ } catch (e) {
461
+ consoleError(e);
462
+ }
463
+ if (i === queue.length) queue.length = 0;
464
+ else if (i !== 0) queue.splice(0, i);
465
+ };
466
+ const flush = () => {
467
+ if (BUILD.asyncQueue) queueCongestion++;
468
+ consume(queueDomReads);
469
+ if (BUILD.asyncQueue) {
470
+ const timeout = (plt.$flags$ & PLATFORM_FLAGS.queueMask) === PLATFORM_FLAGS.appLoaded ? performance.now() + 14 * Math.ceil(queueCongestion * (1 / 10)) : Infinity;
471
+ consumeTimeout(queueDomWrites, timeout);
472
+ consumeTimeout(queueDomWritesLow, timeout);
473
+ if (queueDomWrites.length > 0) {
474
+ queueDomWritesLow.push(...queueDomWrites);
475
+ queueDomWrites.length = 0;
476
+ }
477
+ if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) plt.raf(flush);
478
+ else queueCongestion = 0;
479
+ } else {
480
+ consume(queueDomWrites);
481
+ if (queuePending = queueDomReads.length > 0) plt.raf(flush);
482
+ }
483
+ };
484
+ const nextTick = (cb) => promiseResolve().then(cb);
485
+ const writeTask = /* @__PURE__ */ queueTask(queueDomWrites, true);
486
+ //#endregion
487
+ //#region src/runtime/asset-path.ts
488
+ const getAssetPath = (path) => {
489
+ const base = plt.$resourcesUrl$ || new URL(".", import.meta.url).href;
490
+ const assetUrl = new URL(path, base);
491
+ return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
492
+ };
493
+ const setAssetPath = (path) => plt.$resourcesUrl$ = path;
494
+ //#endregion
495
+ //#region src/utils/style.ts
496
+ /**
497
+ * If (1) styles is not empty string, and (2) constructable stylesheets are supported,
498
+ * then make a stylesheet.
499
+ *
500
+ * @param styles - The styles to add to the stylesheet. If empty string, then no stylesheet is returned.
501
+ * @returns A stylesheet if it can be created, otherwise undefined.
502
+ */
503
+ function createStyleSheetIfNeededAndSupported(styles) {
504
+ if (!styles || !supportsConstructableStylesheets) return void 0;
505
+ const sheet = new CSSStyleSheet();
506
+ sheet.replaceSync(styles);
507
+ return sheet;
508
+ }
509
+ //#endregion
510
+ //#region src/utils/shadow-root.ts
511
+ let globalStyleSheet;
512
+ function createShadowRoot(cmpMeta) {
513
+ const isClosed = BUILD.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
514
+ const opts = { mode: isClosed ? "closed" : "open" };
515
+ const reg = this.constructor._registry;
516
+ if (reg) opts.customElementRegistry = reg;
517
+ if (BUILD.shadowDelegatesFocus) opts.delegatesFocus = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDelegatesFocus);
518
+ if (BUILD.shadowSlotAssignmentManual) {
519
+ if (!!(cmpMeta.$flags$ & CMP_FLAGS.shadowSlotAssignmentManual)) opts.slotAssignment = "manual";
520
+ }
521
+ const shadowRoot = this.attachShadow(opts);
522
+ if (BUILD.shadowModeClosed && isClosed) this.__shadowRoot = shadowRoot;
523
+ if (globalStyleSheet === void 0) globalStyleSheet = createStyleSheetIfNeededAndSupported("") ?? null;
524
+ if (globalStyleSheet) if (supportsMutableAdoptedStyleSheets) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);
525
+ else shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, globalStyleSheet];
526
+ }
527
+ //#endregion
528
+ //#region src/runtime/slot-polyfill-utils.ts
529
+ /**
530
+ * Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
531
+ * are slot fallback nodes - `<slot-fb>...</slot-fb>`
532
+ *
533
+ * A slot fallback node should be visible by default. Then, it should be
534
+ * conditionally hidden if:
535
+ *
536
+ * - it has a sibling with a `slot` property set to its slot name or if
537
+ * - it is a default fallback slot node, in which case we hide if it has any
538
+ * content
539
+ *
540
+ * @param elm the element of interest
541
+ */
542
+ const updateFallbackSlotVisibility = (elm) => {
543
+ const childNodes = internalCall(elm, "childNodes");
544
+ if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
545
+ if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
546
+ else slotNode.hidden = false;
547
+ });
548
+ let i = 0;
549
+ for (i = 0; i < childNodes.length; i++) {
550
+ const childNode = childNodes[i];
551
+ if (childNode.nodeType === NODE_TYPE.ElementNode && internalCall(childNode, "childNodes").length) updateFallbackSlotVisibility(childNode);
552
+ }
553
+ };
554
+ /**
555
+ * Get's the child nodes of a component that are actually slotted.
556
+ * It does this by using root nodes of a component; for each slotted node there is a
557
+ * corresponding slot location node which points to the slotted node (via `['s-nr']`).
558
+ *
559
+ * This is only required until all patches are unified / switched on all the time (then we can rely on `childNodes`)
560
+ * either under 'lightDomPatches' or on by default
561
+ * @param childNodes all 'internal' child nodes of the component
562
+ * @returns An array of slotted reference nodes.
563
+ */
564
+ const getSlottedChildNodes = (childNodes) => {
565
+ const result = [];
566
+ for (let i = 0; i < childNodes.length; i++) {
567
+ const slottedNode = childNodes[i]["s-nr"] || void 0;
568
+ if (slottedNode && slottedNode.isConnected) result.push(slottedNode);
569
+ }
570
+ return result;
571
+ };
572
+ /**
573
+ * Recursively searches a series of child nodes for slot node/s, optionally with a provided slot name.
574
+ * @param childNodes the nodes to search for a slot with a specific name. Should be an element's root nodes.
575
+ * @param hostName the host name of the slot to match on.
576
+ * @param slotName the name of the slot to match on.
577
+ * @returns a reference to the slot node that matches the provided name, `null` otherwise
578
+ */
579
+ function getHostSlotNodes(childNodes, hostName, slotName) {
580
+ let i = 0;
581
+ let slottedNodes = [];
582
+ let childNode;
583
+ for (; i < childNodes.length; i++) {
584
+ childNode = childNodes[i];
585
+ if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
586
+ slottedNodes.push(childNode);
587
+ if (typeof slotName !== "undefined") return slottedNodes;
588
+ }
589
+ slottedNodes = [...slottedNodes, ...getHostSlotNodes(childNode.childNodes, hostName, slotName)];
590
+ }
591
+ return slottedNodes;
592
+ }
593
+ /**
594
+ * Get all 'child' sibling nodes of a slot node
595
+ * @param slot - the slot node to get the child nodes from
596
+ * @param slotName - the name of the slot to match on
597
+ * @param includeSlot - whether to include the slot node in the result
598
+ * @returns child nodes of the slot node
599
+ */
600
+ const getSlotChildSiblings = (slot, slotName, includeSlot = true) => {
601
+ const childNodes = [];
602
+ if (includeSlot && slot["s-sr"] || !slot["s-sr"]) childNodes.push(slot);
603
+ let node = slot;
604
+ while (node = node.nextSibling) if (getSlotName(node) === slotName && (includeSlot || !node["s-sr"])) childNodes.push(node);
605
+ return childNodes;
606
+ };
607
+ /**
608
+ * Check whether a node is located in a given named slot.
609
+ *
610
+ * @param nodeToRelocate the node of interest
611
+ * @param slotName the slot name to check
612
+ * @returns whether the node is located in the slot or not
613
+ */
614
+ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
615
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) {
616
+ if (nodeToRelocate.getAttribute("slot") === null && slotName === "") return true;
617
+ if (nodeToRelocate.getAttribute("slot") === slotName) return true;
618
+ return false;
619
+ }
620
+ if (nodeToRelocate["s-sn"] === slotName) return true;
621
+ return slotName === "";
622
+ };
623
+ /**
624
+ * Creates an empty text node to act as a forwarding address to a slotted node:
625
+ * 1) When non-shadow components re-render, they need a place to temporarily put 'lightDOM' elements.
626
+ * 2) Patched dom methods and accessors use this node to calculate what 'lightDOM' nodes are in the host.
627
+ *
628
+ * @param newChild a node that's going to be added to the component
629
+ * @param slotNode the slot node that the node will be added to
630
+ * @param prepend move the slotted location node to the beginning of the host
631
+ * @param position an ordered position to add the ref node which mirrors the lightDom nodes' order. Used during SSR hydration
632
+ * (the order of the slot location nodes determines the order of the slotted nodes in our patched accessors)
633
+ */
634
+ const addSlotRelocateNode = (newChild, slotNode, prepend, position) => {
635
+ if (newChild["s-ol"] && newChild["s-ol"].isConnected) return;
636
+ const slottedNodeLocation = document.createTextNode("");
637
+ slottedNodeLocation["s-nr"] = newChild;
638
+ if (!slotNode["s-cr"] || !slotNode["s-cr"].parentNode) return;
639
+ const parent = slotNode["s-cr"].parentNode;
640
+ const appendMethod = prepend ? internalCall(parent, "prepend") : internalCall(parent, "appendChild");
641
+ if (BUILD.hydrateClientSide && typeof position !== "undefined") {
642
+ slottedNodeLocation["s-oo"] = position;
643
+ const childNodes = internalCall(parent, "childNodes");
644
+ const slotRelocateNodes = [slottedNodeLocation];
645
+ childNodes.forEach((n) => {
646
+ if (n["s-nr"]) slotRelocateNodes.push(n);
647
+ });
648
+ slotRelocateNodes.sort((a, b) => {
649
+ if (!a["s-oo"] || a["s-oo"] < (b["s-oo"] || 0)) return -1;
650
+ else if (!b["s-oo"] || b["s-oo"] < a["s-oo"]) return 1;
651
+ return 0;
652
+ });
653
+ slotRelocateNodes.forEach((n) => appendMethod.call(parent, n));
654
+ } else appendMethod.call(parent, slottedNodeLocation);
655
+ newChild["s-ol"] = slottedNodeLocation;
656
+ newChild["s-sh"] = slotNode["s-hn"];
657
+ };
658
+ const getSlotName = (node) => typeof node["s-sn"] === "string" ? node["s-sn"] : node.nodeType === 1 && node.getAttribute("slot") || void 0;
659
+ /**
660
+ * Add `assignedElements` and `assignedNodes` methods on a fake slot node
661
+ *
662
+ * @param node - slot node to patch
663
+ */
664
+ function patchSlotNode(node) {
665
+ if (node.assignedElements || node.assignedNodes || !node["s-sr"]) return;
666
+ const assignedFactory = (elementsOnly) => function(opts) {
667
+ const toReturn = [];
668
+ const slotName = this["s-sn"];
669
+ if (opts?.flatten) if (BUILD.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
670
+ else console.error("Flattening not supported for Stencil non-shadow slots");
671
+ const parent = this["s-cr"].parentElement;
672
+ (parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes)).forEach((n) => {
673
+ if (slotName === getSlotName(n)) toReturn.push(n);
674
+ });
675
+ if (elementsOnly) return toReturn.filter((n) => n.nodeType === NODE_TYPE.ElementNode);
676
+ return toReturn;
677
+ }.bind(node);
678
+ node.assignedElements = assignedFactory(true);
679
+ node.assignedNodes = assignedFactory(false);
680
+ }
681
+ /**
682
+ * Dispatches a `slotchange` event on a fake `<slot />` node.
683
+ *
684
+ * @param elm the slot node to dispatch the event from
685
+ */
686
+ function dispatchSlotChangeEvent(elm) {
687
+ elm.name = elm["s-sn"] || "";
688
+ elm.dispatchEvent(new CustomEvent("slotchange", {
689
+ bubbles: false,
690
+ cancelable: false,
691
+ composed: false
692
+ }));
693
+ }
694
+ /**
695
+ * Find the slot node that a slotted node belongs to
696
+ *
697
+ * @param slottedNode - the slotted node to find the slot for
698
+ * @param parentHost - the parent host element of the slotted node
699
+ * @returns the slot node and slot name
700
+ */
701
+ function findSlotFromSlottedNode(slottedNode, parentHost) {
702
+ parentHost = parentHost || slottedNode["s-ol"]?.parentElement;
703
+ if (!parentHost) return {
704
+ slotNode: null,
705
+ slotName: ""
706
+ };
707
+ const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
708
+ return {
709
+ slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
710
+ slotName
711
+ };
712
+ }
713
+ //#endregion
714
+ //#region src/runtime/dom-extras.ts
715
+ const applyLightDomPatches = (hostElementPrototype) => {
716
+ patchSlotAppendChild(hostElementPrototype);
717
+ patchSlotAppend(hostElementPrototype);
718
+ patchSlotPrepend(hostElementPrototype);
719
+ patchSlotInsertAdjacentHTML(hostElementPrototype);
720
+ patchInsertBefore(hostElementPrototype);
721
+ patchTextContent(hostElementPrototype);
722
+ patchChildSlotNodes(hostElementPrototype);
723
+ patchSlotRemoveChild(hostElementPrototype);
724
+ };
725
+ /**
726
+ * Patches the `cloneNode` method on a `scoped` Stencil component.
727
+ *
728
+ * @param HostElementPrototype The Stencil component to be patched
729
+ */
730
+ const patchCloneNode = (HostElementPrototype) => {
731
+ if (HostElementPrototype.__cloneNode) return;
732
+ const orgCloneNode = HostElementPrototype.__cloneNode = HostElementPrototype.cloneNode;
733
+ HostElementPrototype.cloneNode = function(deep) {
734
+ const srcNode = this;
735
+ const isShadowDom = BUILD.shadowDom ? !!srcNode.shadowRoot : false;
736
+ const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
737
+ if (BUILD.slot && !isShadowDom && deep) {
738
+ let i = 0;
739
+ let slotted, nonStencilNode;
740
+ const stencilPrivates = [
741
+ "s-id",
742
+ "s-cr",
743
+ "s-lr",
744
+ "s-rc",
745
+ "s-sc",
746
+ "s-p",
747
+ "s-cn",
748
+ "s-sr",
749
+ "s-sn",
750
+ "s-hn",
751
+ "s-ol",
752
+ "s-nr",
753
+ "s-si",
754
+ "s-rf",
755
+ "s-scs"
756
+ ];
757
+ const childNodes = this.__childNodes || this.childNodes;
758
+ for (; i < childNodes.length; i++) {
759
+ slotted = childNodes[i]["s-nr"];
760
+ nonStencilNode = stencilPrivates.every((privateField) => !childNodes[i][privateField]);
761
+ if (slotted) if (clonedNode.__appendChild) clonedNode.__appendChild(slotted.cloneNode(true));
762
+ else clonedNode.appendChild(slotted.cloneNode(true));
763
+ if (nonStencilNode) clonedNode.appendChild(childNodes[i].cloneNode(true));
764
+ }
765
+ }
766
+ return clonedNode;
767
+ };
768
+ };
769
+ /**
770
+ * Patches the `appendChild` method on a `scoped` Stencil component.
771
+ * The patch will attempt to find a slot with the same name as the node being appended
772
+ * and insert it into the slot reference if found. Otherwise, it falls-back to the original
773
+ * `appendChild` method.
774
+ *
775
+ * @param HostElementPrototype The Stencil component to be patched
776
+ */
777
+ const patchSlotAppendChild = (HostElementPrototype) => {
778
+ if (HostElementPrototype.__appendChild) return;
779
+ HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
780
+ HostElementPrototype.appendChild = function(newChild) {
781
+ const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
782
+ if (slotNode) {
783
+ addSlotRelocateNode(newChild, slotNode);
784
+ const slotChildNodes = getSlotChildSiblings(slotNode, slotName);
785
+ const appendAfter = slotChildNodes[slotChildNodes.length - 1];
786
+ const insertedNode = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, appendAfter.nextSibling);
787
+ dispatchSlotChangeEvent(slotNode);
788
+ updateFallbackSlotVisibility(this);
789
+ return insertedNode;
790
+ }
791
+ return this.__appendChild(newChild);
792
+ };
793
+ };
794
+ /**
795
+ * Patches the `removeChild` method on a `scoped` Stencil component.
796
+ * This patch attempts to remove the specified node from a slot reference
797
+ * if the slot exists. Otherwise, it falls-back to the original `removeChild` method.
798
+ *
799
+ * @param ElementPrototype The Stencil component to be patched
800
+ */
801
+ const patchSlotRemoveChild = (ElementPrototype) => {
802
+ if (ElementPrototype.__removeChild) return;
803
+ ElementPrototype.__removeChild = ElementPrototype.removeChild;
804
+ ElementPrototype.removeChild = function(toRemove) {
805
+ if (toRemove && typeof toRemove["s-sn"] !== "undefined") {
806
+ if (getHostSlotNodes(this.__childNodes || this.childNodes, this.tagName, toRemove["s-sn"]) && toRemove.isConnected) {
807
+ toRemove.remove();
808
+ updateFallbackSlotVisibility(this);
809
+ return;
810
+ }
811
+ }
812
+ return this.__removeChild(toRemove);
813
+ };
814
+ };
815
+ /**
816
+ * Patches the `prepend` method for a slotted node inside a scoped component.
817
+ *
818
+ * @param HostElementPrototype the `Element` to be patched
819
+ */
820
+ const patchSlotPrepend = (HostElementPrototype) => {
821
+ if (HostElementPrototype.__prepend) return;
822
+ HostElementPrototype.__prepend = HostElementPrototype.prepend;
823
+ HostElementPrototype.prepend = function(...newChildren) {
824
+ newChildren.forEach((newChild) => {
825
+ if (typeof newChild === "string") newChild = this.ownerDocument.createTextNode(newChild);
826
+ const slotName = (newChild["s-sn"] = getSlotName(newChild)) || "";
827
+ const slotNode = getHostSlotNodes(internalCall(this, "childNodes"), this.tagName, slotName)[0];
828
+ if (slotNode) {
829
+ addSlotRelocateNode(newChild, slotNode, true);
830
+ const appendAfter = getSlotChildSiblings(slotNode, slotName)[0];
831
+ const toReturn = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, internalCall(appendAfter, "nextSibling"));
832
+ dispatchSlotChangeEvent(slotNode);
833
+ return toReturn;
834
+ }
835
+ if (newChild.nodeType === 1 && !!newChild.getAttribute("slot")) newChild.hidden = true;
836
+ return HostElementPrototype.__prepend(newChild);
837
+ });
838
+ };
839
+ };
840
+ /**
841
+ * Patches the `append` method for a slotted node inside a scoped component. The patched method uses
842
+ * `appendChild` under-the-hood while creating text nodes for any new children that passed as bare strings.
843
+ *
844
+ * @param HostElementPrototype the `Element` to be patched
845
+ */
846
+ const patchSlotAppend = (HostElementPrototype) => {
847
+ if (HostElementPrototype.__append) return;
848
+ HostElementPrototype.__append = HostElementPrototype.append;
849
+ HostElementPrototype.append = function(...newChildren) {
850
+ newChildren.forEach((newChild) => {
851
+ if (typeof newChild === "string") newChild = this.ownerDocument.createTextNode(newChild);
852
+ this.appendChild(newChild);
853
+ });
854
+ };
855
+ };
856
+ /**
857
+ * Patches the `insertAdjacentHTML` method for a slotted node inside a scoped component. Specifically,
858
+ * we only need to patch the behavior for the specific `beforeend` and `afterbegin` positions so the element
859
+ * gets inserted into the DOM in the correct location.
860
+ *
861
+ * @param HostElementPrototype the `Element` to be patched
862
+ */
863
+ const patchSlotInsertAdjacentHTML = (HostElementPrototype) => {
864
+ if (HostElementPrototype.__insertAdjacentHTML) return;
865
+ const originalInsertAdjacentHtml = HostElementPrototype.insertAdjacentHTML;
866
+ HostElementPrototype.insertAdjacentHTML = function(position, text) {
867
+ if (position !== "afterbegin" && position !== "beforeend") return originalInsertAdjacentHtml.call(this, position, text);
868
+ const container = this.ownerDocument.createElement("_");
869
+ let node;
870
+ container.innerHTML = text;
871
+ if (position === "afterbegin") while (node = container.firstChild) this.prepend(node);
872
+ else if (position === "beforeend") while (node = container.firstChild) this.append(node);
873
+ };
874
+ };
875
+ /**
876
+ * Patches the `insertBefore` of a non-shadow component.
877
+ *
878
+ * The *current* node to insert before may not be in the root of our component
879
+ * (e.g. if it's 'slotted' it appears in the root, but isn't really)
880
+ *
881
+ * This tries to find where the *current* node lives within the component and insert the new node before it
882
+ * *If* the new node is in the same slot as the *current* node. Otherwise the new node is appended to it's 'slot'
883
+ *
884
+ * @param HostElementPrototype the custom element prototype to patch
885
+ */
886
+ const patchInsertBefore = (HostElementPrototype) => {
887
+ if (HostElementPrototype.__insertBefore) return;
888
+ const eleProto = HostElementPrototype;
889
+ if (eleProto.__insertBefore) return;
890
+ eleProto.__insertBefore = HostElementPrototype.insertBefore;
891
+ HostElementPrototype.insertBefore = function(newChild, currentChild) {
892
+ const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
893
+ const slottedNodes = this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes);
894
+ if (slotNode) {
895
+ let found = false;
896
+ slottedNodes.forEach((childNode) => {
897
+ if (childNode === currentChild || currentChild === null) {
898
+ found = true;
899
+ if (currentChild === null || slotName !== currentChild["s-sn"]) {
900
+ this.appendChild(newChild);
901
+ return;
902
+ }
903
+ if (slotName === currentChild["s-sn"]) {
904
+ addSlotRelocateNode(newChild, slotNode);
905
+ internalCall(internalCall(currentChild, "parentNode"), "insertBefore")(newChild, currentChild);
906
+ dispatchSlotChangeEvent(slotNode);
907
+ }
908
+ return;
909
+ }
910
+ });
911
+ if (found) return newChild;
912
+ }
913
+ /**
914
+ * Fixes an issue where slotted elements are dynamically relocated in React, such as after data fetch.
915
+ *
916
+ * When a slotted element is passed to another scoped component (e.g., <A><C slot="header"/></A>),
917
+ * the child’s __parentNode (original parent node property) does not match this.
918
+ *
919
+ * To prevent errors, this checks if the current child's parent node differs from this.
920
+ * If so, appendChild(newChild) is called to ensure the child is correctly inserted,
921
+ * allowing Stencil to properly manage the slot placement.
922
+ */
923
+ const parentNode = currentChild?.__parentNode;
924
+ if (parentNode && !this.isSameNode(parentNode)) return this.appendChild(newChild);
925
+ return this.__insertBefore(newChild, currentChild);
926
+ };
927
+ };
928
+ /**
929
+ * Patches the `textContent` of an unnamed slotted node inside a scoped component
930
+ *
931
+ * @param hostElementPrototype the `Element` to be patched
932
+ */
933
+ const patchTextContent = (hostElementPrototype) => {
934
+ patchHostOriginalAccessor("textContent", hostElementPrototype);
935
+ Object.defineProperty(hostElementPrototype, "textContent", {
936
+ get: function() {
937
+ let text = "";
938
+ (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => text += node.textContent || "");
939
+ return text;
940
+ },
941
+ set: function(value) {
942
+ (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => {
943
+ if (node["s-ol"]) node["s-ol"].remove();
944
+ node.remove();
945
+ });
946
+ this.insertAdjacentHTML("beforeend", value);
947
+ }
948
+ });
949
+ };
950
+ const patchChildSlotNodes = (elm) => {
951
+ class FakeNodeList extends Array {
952
+ item(n) {
953
+ return this[n];
954
+ }
955
+ }
956
+ patchHostOriginalAccessor("children", elm);
957
+ Object.defineProperty(elm, "children", { get() {
958
+ return this.childNodes.filter((n) => n.nodeType === 1);
959
+ } });
960
+ Object.defineProperty(elm, "childElementCount", { get() {
961
+ return this.children.length;
962
+ } });
963
+ patchHostOriginalAccessor("firstChild", elm);
964
+ Object.defineProperty(elm, "firstChild", { get() {
965
+ return this.childNodes[0];
966
+ } });
967
+ patchHostOriginalAccessor("lastChild", elm);
968
+ Object.defineProperty(elm, "lastChild", { get() {
969
+ return this.childNodes[this.childNodes.length - 1];
970
+ } });
971
+ patchHostOriginalAccessor("childNodes", elm);
972
+ Object.defineProperty(elm, "childNodes", { get() {
973
+ const result = new FakeNodeList();
974
+ if (!this["s-cr"]) {
975
+ result.push(...Array.from(this.__childNodes));
976
+ return result;
977
+ }
978
+ result.push(...getSlottedChildNodes(this.__childNodes));
979
+ return result;
980
+ } });
981
+ };
982
+ /**
983
+ * Patches sibling accessors of a 'slotted' node within a non-shadow component.
984
+ * Meaning whilst stepping through a non-shadow element's nodes, only the mock 'lightDOM' nodes are returned.
985
+ * Especially relevant when rendering components via SSR... Frameworks will often try to reconcile their
986
+ * VDOM with the real DOM by stepping through nodes with 'nextSibling' et al.
987
+ * - `nextSibling`
988
+ * - `nextElementSibling`
989
+ * - `previousSibling`
990
+ * - `previousElementSibling`
991
+ *
992
+ * @param node the slotted node to be patched
993
+ */
994
+ const patchSlottedNode = (node) => {
995
+ if (!node || node.__nextSibling !== void 0 || !globalThis.Node) return;
996
+ patchNextSibling(node);
997
+ patchPreviousSibling(node);
998
+ patchParentNode(node);
999
+ if (node.nodeType === Node.ELEMENT_NODE) {
1000
+ patchNextElementSibling(node);
1001
+ patchPreviousElementSibling(node);
1002
+ }
1003
+ };
1004
+ /**
1005
+ * Patches the `nextSibling` accessor of a non-shadow slotted node
1006
+ *
1007
+ * @param node the slotted node to be patched
1008
+ */
1009
+ const patchNextSibling = (node) => {
1010
+ if (!node || node.__nextSibling) return;
1011
+ patchHostOriginalAccessor("nextSibling", node);
1012
+ Object.defineProperty(node, "nextSibling", { get: function() {
1013
+ const parentNodes = this["s-ol"]?.parentNode.childNodes;
1014
+ const index = parentNodes?.indexOf(this);
1015
+ if (parentNodes && index > -1) return parentNodes[index + 1];
1016
+ return this.__nextSibling;
1017
+ } });
1018
+ };
1019
+ /**
1020
+ * Patches the `nextElementSibling` accessor of a non-shadow slotted node
1021
+ *
1022
+ * @param element the slotted element node to be patched
1023
+ */
1024
+ const patchNextElementSibling = (element) => {
1025
+ if (!element || element.__nextElementSibling) return;
1026
+ patchHostOriginalAccessor("nextElementSibling", element);
1027
+ Object.defineProperty(element, "nextElementSibling", { get: function() {
1028
+ const parentEles = this["s-ol"]?.parentNode.children;
1029
+ const index = parentEles?.indexOf(this);
1030
+ if (parentEles && index > -1) return parentEles[index + 1];
1031
+ return this.__nextElementSibling;
1032
+ } });
1033
+ };
1034
+ /**
1035
+ * Patches the `previousSibling` accessor of a non-shadow slotted node
1036
+ *
1037
+ * @param node the slotted node to be patched
1038
+ */
1039
+ const patchPreviousSibling = (node) => {
1040
+ if (!node || node.__previousSibling) return;
1041
+ patchHostOriginalAccessor("previousSibling", node);
1042
+ Object.defineProperty(node, "previousSibling", { get: function() {
1043
+ const parentNodes = this["s-ol"]?.parentNode.childNodes;
1044
+ const index = parentNodes?.indexOf(this);
1045
+ if (parentNodes && index > -1) return parentNodes[index - 1];
1046
+ return this.__previousSibling;
1047
+ } });
1048
+ };
1049
+ /**
1050
+ * Patches the `previousElementSibling` accessor of a non-shadow slotted node
1051
+ *
1052
+ * @param element the slotted element node to be patched
1053
+ */
1054
+ const patchPreviousElementSibling = (element) => {
1055
+ if (!element || element.__previousElementSibling) return;
1056
+ patchHostOriginalAccessor("previousElementSibling", element);
1057
+ Object.defineProperty(element, "previousElementSibling", { get: function() {
1058
+ const parentNodes = this["s-ol"]?.parentNode.children;
1059
+ const index = parentNodes?.indexOf(this);
1060
+ if (parentNodes && index > -1) return parentNodes[index - 1];
1061
+ return this.__previousElementSibling;
1062
+ } });
1063
+ };
1064
+ /**
1065
+ * Patches the `parentNode` accessor of a non-shadow slotted node
1066
+ *
1067
+ * @param node the slotted node to be patched
1068
+ */
1069
+ const patchParentNode = (node) => {
1070
+ if (!node || node.__parentNode) return;
1071
+ patchHostOriginalAccessor("parentNode", node);
1072
+ Object.defineProperty(node, "parentNode", {
1073
+ get: function() {
1074
+ return this["s-ol"]?.parentNode || this.__parentNode;
1075
+ },
1076
+ set: function(value) {
1077
+ this.__parentNode = value;
1078
+ }
1079
+ });
1080
+ };
1081
+ const validElementPatches = [
1082
+ "children",
1083
+ "nextElementSibling",
1084
+ "previousElementSibling"
1085
+ ];
1086
+ const validNodesPatches = [
1087
+ "childNodes",
1088
+ "firstChild",
1089
+ "lastChild",
1090
+ "nextSibling",
1091
+ "previousSibling",
1092
+ "textContent",
1093
+ "parentNode"
1094
+ ];
1095
+ /**
1096
+ * Patches a node or element; making it's original accessor method available under a new name.
1097
+ * e.g. `nextSibling` -> `__nextSibling`
1098
+ *
1099
+ * @param accessorName - the name of the accessor to patch
1100
+ * @param node - the node to patch
1101
+ */
1102
+ function patchHostOriginalAccessor(accessorName, node) {
1103
+ /**
1104
+ * skip this method if a component was imported from a non-browser environment
1105
+ */
1106
+ if (!globalThis.Node || !globalThis.Element) return;
1107
+ let accessor;
1108
+ if (validElementPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Element.prototype, accessorName);
1109
+ else if (validNodesPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Node.prototype, accessorName);
1110
+ if (!accessor) accessor = Object.getOwnPropertyDescriptor(node, accessorName);
1111
+ if (accessor) Object.defineProperty(node, "__" + accessorName, accessor);
1112
+ }
1113
+ /**
1114
+ * Get the original / internal accessor or method of a node or element.
1115
+ *
1116
+ * @param node - the node to get the accessor from
1117
+ * @param method - the name of the accessor to get
1118
+ *
1119
+ * @returns the original accessor or method of the node
1120
+ */
1121
+ function internalCall(node, method) {
1122
+ if ("__" + method in node) {
1123
+ const toReturn = node["__" + method];
1124
+ if (typeof toReturn !== "function") return toReturn;
1125
+ return toReturn.bind(node);
1126
+ } else {
1127
+ if (typeof node[method] !== "function") return node[method];
1128
+ return node[method].bind(node);
1129
+ }
1130
+ }
1131
+ //#endregion
1132
+ //#region src/runtime/element.ts
1133
+ const getElement = (ref) => BUILD.lazyLoad ? getHostRef(ref)?.$hostElement$ : ref;
1134
+ /**
1135
+ * Get the shadow root for a Stencil component's host element.
1136
+ * This works for both open and closed shadow DOM modes.
1137
+ *
1138
+ * For closed shadow DOM, `element.shadowRoot` returns `null` by design,
1139
+ * but Stencil stores the reference internally so components can still
1140
+ * access their own shadow root.
1141
+ *
1142
+ * @param element The host element (from @Element() decorator)
1143
+ * @returns The shadow root, or null if no shadow root exists
1144
+ */
1145
+ const getShadowRoot = (element) => {
1146
+ if (BUILD.shadowModeClosed && element.__shadowRoot) return element.__shadowRoot;
1147
+ return element.shadowRoot;
1148
+ };
1149
+ //#endregion
1150
+ //#region src/runtime/profile.ts
1151
+ let i = 0;
1152
+ const createTime = (fnName, tagName = "") => {
1153
+ if (BUILD.profile && performance.mark) {
1154
+ const key = `st:${fnName}:${tagName}:${i++}`;
1155
+ performance.mark(key);
1156
+ return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
1157
+ } else return () => {};
1158
+ };
1159
+ const uniqueTime = (key, measureText) => {
1160
+ if (BUILD.profile && performance.mark) {
1161
+ if (performance.getEntriesByName(key, "mark").length === 0) performance.mark(key);
1162
+ return () => {
1163
+ if (performance.getEntriesByName(measureText, "measure").length === 0) performance.measure(measureText, key);
1164
+ };
1165
+ } else return () => {};
1166
+ };
1167
+ const inspect = (ref) => {
1168
+ const hostRef = getHostRef(ref);
1169
+ if (!hostRef) return;
1170
+ const flags = hostRef.$flags$;
1171
+ const hostElement = hostRef.$hostElement$;
1172
+ return {
1173
+ renderCount: hostRef.$renderCount$,
1174
+ flags: {
1175
+ hasRendered: !!(flags & HOST_FLAGS.hasRendered),
1176
+ hasConnected: !!(flags & HOST_FLAGS.hasConnected),
1177
+ isWaitingForChildren: !!(flags & HOST_FLAGS.isWaitingForChildren),
1178
+ isConstructingInstance: !!(flags & HOST_FLAGS.isConstructingInstance),
1179
+ isQueuedForUpdate: !!(flags & HOST_FLAGS.isQueuedForUpdate),
1180
+ hasInitializedComponent: !!(flags & HOST_FLAGS.hasInitializedComponent),
1181
+ hasLoadedComponent: !!(flags & HOST_FLAGS.hasLoadedComponent),
1182
+ isWatchReady: !!(flags & HOST_FLAGS.isWatchReady),
1183
+ isListenReady: !!(flags & HOST_FLAGS.isListenReady),
1184
+ needsRerender: !!(flags & HOST_FLAGS.needsRerender)
1185
+ },
1186
+ instanceValues: hostRef.$instanceValues$,
1187
+ serializerValues: hostRef.$serializerValues$,
1188
+ ancestorComponent: hostRef.$ancestorComponent$,
1189
+ hostElement,
1190
+ lazyInstance: hostRef.$lazyInstance$,
1191
+ vnode: hostRef.$vnode$,
1192
+ modeName: hostRef.$modeName$,
1193
+ fetchedCbList: hostRef.$fetchedCbList$,
1194
+ onReadyPromise: hostRef.$onReadyPromise$,
1195
+ onReadyResolve: hostRef.$onReadyResolve$,
1196
+ onInstancePromise: hostRef.$onInstancePromise$,
1197
+ onInstanceResolve: hostRef.$onInstanceResolve$,
1198
+ onRenderResolve: hostRef.$onRenderResolve$,
1199
+ queuedListeners: hostRef.$queuedListeners$,
1200
+ rmListeners: hostRef.$rmListeners$,
1201
+ ["s-id"]: hostElement["s-id"],
1202
+ ["s-cr"]: hostElement["s-cr"],
1203
+ ["s-lr"]: hostElement["s-lr"],
1204
+ ["s-p"]: hostElement["s-p"],
1205
+ ["s-rc"]: hostElement["s-rc"],
1206
+ ["s-sc"]: hostElement["s-sc"]
1207
+ };
1208
+ };
1209
+ const installDevTools = () => {
1210
+ if (BUILD.devTools) {
1211
+ const stencil = win.stencil = win.stencil || {};
1212
+ const originalInspect = stencil.inspect;
1213
+ stencil.inspect = (ref) => {
1214
+ let result = inspect(ref);
1215
+ if (!result && typeof originalInspect === "function") result = originalInspect(ref);
1216
+ return result;
1217
+ };
1218
+ }
1219
+ };
1220
+ //#endregion
1221
+ //#region src/utils/query-nonce-meta-tag-content.ts
1222
+ /**
1223
+ * Helper method for querying a `meta` tag that contains a nonce value
1224
+ * out of a DOM's head.
1225
+ *
1226
+ * @param doc The DOM containing the `head` to query against
1227
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
1228
+ * exists or the tag has no content.
1229
+ */
1230
+ function queryNonceMetaTagContent(doc) {
1231
+ return doc.head?.querySelector("meta[name=\"csp-nonce\"]")?.getAttribute("content") ?? void 0;
1232
+ }
1233
+ //#endregion
1234
+ //#region src/runtime/styles.ts
1235
+ const rootAppliedStyles = /* @__PURE__ */ new WeakMap();
1236
+ /**
1237
+ * Get or initialize the set of applied style scope IDs for a container element.
1238
+ *
1239
+ * @param container the container element to track styles for
1240
+ * @returns the set of applied scope IDs
1241
+ */
1242
+ const getAppliedStyles = (container) => {
1243
+ let applied = rootAppliedStyles.get(container);
1244
+ if (!applied) {
1245
+ applied = /* @__PURE__ */ new Set();
1246
+ rootAppliedStyles.set(container, applied);
1247
+ }
1248
+ return applied;
1249
+ };
1250
+ /**
1251
+ * Safely adopt a stylesheet into a container's adoptedStyleSheets.
1252
+ * Handles both mutable and immutable adoptedStyleSheets arrays.
1253
+ *
1254
+ * @param container the shadow root or document to adopt styles into
1255
+ * @param sheet the CSSStyleSheet to adopt
1256
+ * @param prepend if true, add to beginning; if false, add to end
1257
+ */
1258
+ const adoptStylesheet = (container, sheet, prepend = false) => {
1259
+ if (supportsMutableAdoptedStyleSheets) if (prepend) container.adoptedStyleSheets.unshift(sheet);
1260
+ else container.adoptedStyleSheets.push(sheet);
1261
+ else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
1262
+ else container.adoptedStyleSheets = [...container.adoptedStyleSheets, sheet];
1263
+ };
1264
+ /**
1265
+ * Create a CSSStyleSheet for the correct window context.
1266
+ * Constructable stylesheets can't be shared between windows,
1267
+ * so we need to create one for the current window.
1268
+ *
1269
+ * @param container the container node (used to determine the window context)
1270
+ * @param cssText the CSS text to populate the stylesheet with
1271
+ * @returns a new CSSStyleSheet for the correct window
1272
+ */
1273
+ const createStylesheetForWindow = (container, cssText) => {
1274
+ const sheet = new (container.defaultView ?? container.ownerDocument?.defaultView ?? win).CSSStyleSheet();
1275
+ sheet.replaceSync(cssText);
1276
+ return sheet;
1277
+ };
1278
+ /**
1279
+ * Get the style for a component, appending slot fallback CSS if needed.
1280
+ * Returns a new value without mutating the cached style.
1281
+ *
1282
+ * @param style - the style string or CSSStyleSheet to process
1283
+ * @returns the style (string or CSSStyleSheet) with slot CSS appended if needed, or undefined
1284
+ */
1285
+ const getStyleWithSlotCss = (style) => {
1286
+ if (!style) return SLOT_FB_CSS;
1287
+ if (typeof style === "string") return style + SLOT_FB_CSS;
1288
+ return style;
1289
+ };
1290
+ /**
1291
+ * Register the styles for a component by creating a stylesheet and then
1292
+ * registering it under the component's scope ID in a `WeakMap` for later use.
1293
+ *
1294
+ * If constructable stylesheet are not supported or `allowCS` is set to
1295
+ * `false` then the styles will be registered as a string instead.
1296
+ *
1297
+ * @param scopeId the scope ID for the component of interest
1298
+ * @param cssText styles for the component of interest
1299
+ * @param allowCS whether or not to use a constructable stylesheet
1300
+ */
1301
+ const registerStyle = (scopeId, cssText, allowCS) => {
1302
+ if (supportsConstructableStylesheets && allowCS) {
1303
+ const sheet = styles.get(scopeId) ?? new CSSStyleSheet();
1304
+ sheet.replaceSync(cssText);
1305
+ styles.set(scopeId, sheet);
1306
+ } else styles.set(scopeId, cssText);
1307
+ };
1308
+ /**
1309
+ * Attach the styles for a given component to the DOM
1310
+ *
1311
+ * If the element uses shadow or is already attached to the DOM then we can
1312
+ * create a stylesheet inside of its associated document fragment, otherwise
1313
+ * we'll stick the stylesheet into the document head.
1314
+ *
1315
+ * @param styleContainerNode the node within which a style element for the
1316
+ * component of interest should be added
1317
+ * @param cmpMeta runtime metadata for the component of interest
1318
+ * @param mode an optional current mode
1319
+ * @returns the scope ID for the component of interest
1320
+ */
1321
+ const addStyle = (styleContainerNode, cmpMeta, mode) => {
1322
+ const scopeId = getScopeId(cmpMeta, mode);
1323
+ if (!win.document) return scopeId;
1324
+ let style = styles.get(scopeId);
1325
+ if (cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) style = getStyleWithSlotCss(style);
1326
+ const isClosedShadowSSR = BUILD.hydrateServerSide && BUILD.shadowModeClosed && cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss && cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed;
1327
+ if (styleContainerNode.nodeType !== NODE_TYPE.DocumentFragment && !isClosedShadowSSR) styleContainerNode = win.document;
1328
+ if (style) {
1329
+ if (typeof style === "string") {
1330
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
1331
+ const appliedStyles = getAppliedStyles(styleContainerNode);
1332
+ let styleElm;
1333
+ const existingStyleElm = (BUILD.hydrateClientSide || BUILD.hotModuleReplacement) && styleContainerNode.querySelector(`[sty-id="${scopeId}"]`);
1334
+ if (existingStyleElm) existingStyleElm.textContent = style;
1335
+ else if (!appliedStyles.has(scopeId)) {
1336
+ styleElm = win.document.createElement("style");
1337
+ styleElm.textContent = style;
1338
+ const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
1339
+ if (nonce != null) styleElm.setAttribute("nonce", nonce);
1340
+ 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);
1341
+ if (BUILD.hotModuleReplacement && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) styleElm.setAttribute("data-slot-fb", "");
1342
+ /**
1343
+ * attach styles at the end of the head tag if we render scoped components
1344
+ */
1345
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) if (styleContainerNode.nodeName === "HEAD") {
1346
+ /**
1347
+ * if the page contains preconnect links, we want to insert the styles
1348
+ * after the last preconnect link to ensure the styles are preloaded
1349
+ */
1350
+ const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
1351
+ const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
1352
+ styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
1353
+ } else if ("host" in styleContainerNode) if (supportsConstructableStylesheets) {
1354
+ const stylesheet = createStylesheetForWindow(styleContainerNode, style);
1355
+ adoptStylesheet(styleContainerNode, stylesheet, true);
1356
+ } else {
1357
+ /**
1358
+ * If a scoped component is used within a shadow root and constructable stylesheets are
1359
+ * not supported, we want to insert the styles at the beginning of the shadow root node.
1360
+ *
1361
+ * However, if there is already a style node in the shadow root, we just append
1362
+ * the styles to the existing node.
1363
+ *
1364
+ * Note: order of how styles are applied is important. The new style node
1365
+ * should be inserted before the existing style node.
1366
+ *
1367
+ * During HMR, create separate style elements for scoped components so they can be
1368
+ * updated independently without affecting other components' styles.
1369
+ */
1370
+ const existingStyleContainer = styleContainerNode.querySelector("style");
1371
+ if (existingStyleContainer && !BUILD.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
1372
+ else styleContainerNode.prepend(styleElm);
1373
+ }
1374
+ else styleContainerNode.append(styleElm);
1375
+ /**
1376
+ * attach styles at the beginning of a shadow root node if we render shadow components
1377
+ */
1378
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
1379
+ else styleContainerNode.insertBefore(styleElm, null);
1380
+ if (appliedStyles) appliedStyles.add(scopeId);
1381
+ }
1382
+ } else if (BUILD.constructableCSS) {
1383
+ const appliedStyles = getAppliedStyles(styleContainerNode);
1384
+ if (!appliedStyles.has(scopeId)) {
1385
+ const currentWindow = styleContainerNode.defaultView ?? styleContainerNode.ownerDocument.defaultView;
1386
+ let stylesheet;
1387
+ if (style.constructor === currentWindow.CSSStyleSheet) stylesheet = style;
1388
+ else {
1389
+ stylesheet = new currentWindow.CSSStyleSheet();
1390
+ for (let i = 0; i < style.cssRules.length; i++) stylesheet.insertRule(style.cssRules[i].cssText, i);
1391
+ }
1392
+ adoptStylesheet(styleContainerNode, stylesheet);
1393
+ appliedStyles.add(scopeId);
1394
+ if (BUILD.hydrateClientSide && "host" in styleContainerNode) {
1395
+ const ssrStyleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`);
1396
+ if (ssrStyleElm) writeTask(() => ssrStyleElm.remove());
1397
+ }
1398
+ }
1399
+ }
1400
+ }
1401
+ return scopeId;
1402
+ };
1403
+ /**
1404
+ * Add styles for a given component to the DOM, optionally handling 'scoped'
1405
+ * encapsulation by adding an appropriate class name to the host element.
1406
+ *
1407
+ * @param hostRef the host reference for the component of interest
1408
+ */
1409
+ const attachStyles = (hostRef) => {
1410
+ const cmpMeta = hostRef.$cmpMeta$;
1411
+ const elm = hostRef.$hostElement$;
1412
+ const flags = cmpMeta.$flags$;
1413
+ const endAttachStyles = createTime("attachStyles", cmpMeta.$tagName$);
1414
+ let styleContainerNode;
1415
+ const shadowRoot = BUILD.shadowDom ? getShadowRoot(elm) : null;
1416
+ if (shadowRoot) styleContainerNode = shadowRoot;
1417
+ else if (BUILD.hydrateServerSide && BUILD.shadowModeClosed && flags & CMP_FLAGS.shadowNeedsScopedCss && flags & CMP_FLAGS.shadowModeClosed) styleContainerNode = elm;
1418
+ else styleContainerNode = elm.getRootNode();
1419
+ const scopeId = addStyle(styleContainerNode, cmpMeta, hostRef.$modeName$);
1420
+ if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & CMP_FLAGS.needsScopedEncapsulation) {
1421
+ elm["s-sc"] = scopeId;
1422
+ elm.classList.add(scopeId + "-h");
1423
+ }
1424
+ endAttachStyles();
1425
+ };
1426
+ /**
1427
+ * Get the scope ID for a given component
1428
+ *
1429
+ * @param cmp runtime metadata for the component of interest
1430
+ * @param mode the current mode (optional)
1431
+ * @returns a scope ID for the component of interest
1432
+ */
1433
+ const getScopeId = (cmp, mode) => "sc-" + (BUILD.mode && mode && cmp.$flags$ & CMP_FLAGS.hasMode ? cmp.$tagName$ + "-" + mode : cmp.$tagName$);
1434
+ /**
1435
+ * Convert a 'scoped' CSS string to one appropriate for use in the shadow DOM.
1436
+ *
1437
+ * Given a 'scoped' CSS string that looks like this:
1438
+ *
1439
+ * ```
1440
+ * /*!@div*\/div.class-name { display: flex };
1441
+ * ```
1442
+ *
1443
+ * Convert it to a 'shadow' appropriate string, like so:
1444
+ *
1445
+ * ```
1446
+ * /*!@div*\/div.class-name { display: flex }
1447
+ * ─┬─ ────────┬────────
1448
+ * │ │
1449
+ * │ ┌─────────────────┘
1450
+ * ▼ ▼
1451
+ * div{ display: flex }
1452
+ * ```
1453
+ *
1454
+ * Note that forward-slashes in the above are escaped so they don't end the
1455
+ * comment.
1456
+ *
1457
+ * @param css a CSS string to convert
1458
+ * @returns the converted string
1459
+ */
1460
+ const convertScopedToShadow = (css) => css.replace(/\/\*!@([^/]+)\*\/[^{]+\{/g, "$1{");
1461
+ /**
1462
+ * Hydrate styles after SSR for components *not* using DSD. Convert 'scoped' styles to 'shadow'
1463
+ * and add them to a constructable stylesheet.
1464
+ *
1465
+ * @returns void
1466
+ */
1467
+ const hydrateScopedToShadow = () => {
1468
+ if (!win.document) return;
1469
+ const styleElements = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1470
+ let i = 0;
1471
+ for (; i < styleElements.length; i++) registerStyle(styleElements[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styleElements[i].innerHTML), true);
1472
+ };
1473
+ //#endregion
1474
+ //#region src/utils/helpers.ts
1475
+ /**
1476
+ * Check if a value is defined (not null and not undefined).
1477
+ *
1478
+ * @param v - the value to check
1479
+ * @returns true if the value is defined
1480
+ */
1481
+ const isDef = (v) => v != null && v !== void 0;
1482
+ /**
1483
+ * Check whether a value is a 'complex type', defined here as an object or a
1484
+ * function.
1485
+ *
1486
+ * @param o the value to check
1487
+ * @returns whether it's a complex type or not
1488
+ */
1489
+ const isComplexType = (o) => {
1490
+ o = typeof o;
1491
+ return o === "object" || o === "function";
1492
+ };
1493
+ //#endregion
1494
+ //#region src/runtime/event-emitter.ts
1495
+ const createEvent = (ref, name, flags) => {
1496
+ const elm = getElement(ref);
1497
+ return { emit: (detail) => {
1498
+ if (BUILD.isDev && !elm.isConnected) consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
1499
+ return emitEvent(elm, name, {
1500
+ bubbles: !!(flags & EVENT_FLAGS.Bubbles),
1501
+ composed: !!(flags & EVENT_FLAGS.Composed),
1502
+ cancelable: !!(flags & EVENT_FLAGS.Cancellable),
1503
+ detail
1504
+ });
1505
+ } };
1506
+ };
1507
+ /**
1508
+ * Helper function to create & dispatch a custom Event on a provided target
1509
+ * @param elm the target of the Event
1510
+ * @param name the name to give the custom Event
1511
+ * @param opts options for configuring a custom Event
1512
+ * @returns the custom Event
1513
+ */
1514
+ const emitEvent = (elm, name, opts) => {
1515
+ const ev = plt.ce(name, opts);
1516
+ elm.dispatchEvent(ev);
1517
+ return ev;
1518
+ };
1519
+ //#endregion
1520
+ //#region src/runtime/registry.ts
1521
+ let _registry;
1522
+ const setRegistry = (registry) => {
1523
+ _registry = registry;
1524
+ };
1525
+ const getRegistry = () => _registry ?? customElements;
1526
+ //#endregion
1527
+ //#region src/runtime/vdom/set-accessor.ts
1528
+ /**
1529
+ * Production setAccessor() function based on Preact by
1530
+ * Jason Miller (@developit)
1531
+ * Licensed under the MIT License
1532
+ * https://github.com/developit/preact/blob/master/LICENSE
1533
+ *
1534
+ * Modified for Stencil's compiler and vdom
1535
+ */
1536
+ /** Per-element, per-attribute signal subscription disposers. */
1537
+ const signalAttrDisposers = /* @__PURE__ */ new WeakMap();
1538
+ const disposeAllSignalAttrs = (elm) => {
1539
+ if (!BUILD.vdomSignals) return;
1540
+ const map = signalAttrDisposers.get(elm);
1541
+ if (map) {
1542
+ map.forEach((d) => d());
1543
+ signalAttrDisposers.delete(elm);
1544
+ }
1545
+ };
1546
+ /**
1547
+ * When running a VDom render set properties present on a VDom node onto the
1548
+ * corresponding HTML element.
1549
+ *
1550
+ * Note that this function has special functionality for the `class`,
1551
+ * `style`, `key`, and `ref` attributes, as well as event handlers (like
1552
+ * `onClick`, etc). All others are just passed through as-is.
1553
+ *
1554
+ * @param elm the HTMLElement onto which attributes should be set
1555
+ * @param memberName the name of the attribute to set
1556
+ * @param oldValue the old value for the attribute
1557
+ * @param newValue the new value for the attribute
1558
+ * @param isSvg whether we're in an svg context or not
1559
+ * @param flags bitflags for Vdom variables
1560
+ * @param initialRender whether this is the first render of the VDom
1561
+ */
1562
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRender) => {
1563
+ if (oldValue === newValue) return;
1564
+ if (BUILD.vdomSignals && isSignalLike(newValue)) {
1565
+ const attrMap = signalAttrDisposers.get(elm) ?? /* @__PURE__ */ new Map();
1566
+ attrMap.get(memberName)?.();
1567
+ if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
1568
+ let prevVal = oldValue;
1569
+ attrMap.set(memberName, effect$1(() => {
1570
+ const curVal = newValue.value;
1571
+ setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
1572
+ prevVal = curVal;
1573
+ }));
1574
+ return;
1575
+ }
1576
+ if (BUILD.vdomSignals && isSignalLike(oldValue)) {
1577
+ const attrMap = signalAttrDisposers.get(elm);
1578
+ if (attrMap) {
1579
+ attrMap.get(memberName)?.();
1580
+ attrMap.delete(memberName);
1581
+ }
1582
+ }
1583
+ let isProp = isMemberInElement(elm, memberName);
1584
+ let ln = memberName.toLowerCase();
1585
+ if (BUILD.vdomClass && memberName === "class") {
1586
+ const classList = elm.classList;
1587
+ const oldClasses = parseClassList(oldValue);
1588
+ let newClasses = parseClassList(newValue);
1589
+ if (BUILD.hydrateClientSide && (elm["s-si"] || elm["s-sc"]) && initialRender) {
1590
+ const scopeId = elm["s-sc"] || elm["s-si"];
1591
+ newClasses.push(scopeId);
1592
+ oldClasses.forEach((c) => {
1593
+ if (c.startsWith(scopeId)) newClasses.push(c);
1594
+ });
1595
+ newClasses = [...new Set(newClasses)].filter((c) => c);
1596
+ classList.add(...newClasses);
1597
+ } else {
1598
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
1599
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
1600
+ }
1601
+ } else if (BUILD.vdomStyle && memberName === "style") {
1602
+ if (BUILD.updatable) {
1603
+ for (const prop in oldValue) if (!newValue || newValue[prop] == null) if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
1604
+ else elm.style[prop] = "";
1605
+ }
1606
+ for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
1607
+ else elm.style[prop] = newValue[prop];
1608
+ } else if (BUILD.vdomKey && memberName === "key") {} else if (BUILD.vdomRef && memberName === "ref") {
1609
+ if (newValue) queueRefAttachment(newValue, elm);
1610
+ } else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
1611
+ if (memberName[2] === "-") memberName = memberName.slice(3);
1612
+ else if (isMemberInElement(win, ln)) memberName = ln.slice(2);
1613
+ else memberName = ln[2] + memberName.slice(3);
1614
+ if (oldValue || newValue) {
1615
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
1616
+ memberName = memberName.replace(/* @__PURE__ */ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
1617
+ if (oldValue) plt.rel(elm, memberName, oldValue, capture);
1618
+ if (newValue) plt.ael(elm, memberName, newValue, capture);
1619
+ }
1620
+ } else if (BUILD.vdomPropOrAttr && memberName[0] === "a" && memberName.startsWith("attr:")) {
1621
+ const propName = memberName.slice(5);
1622
+ let attrName;
1623
+ if (BUILD.member) {
1624
+ const hostRef = getHostRef(elm);
1625
+ if (hostRef && hostRef.$cmpMeta$ && hostRef.$cmpMeta$.$members$) {
1626
+ const memberMeta = hostRef.$cmpMeta$.$members$[propName];
1627
+ if (memberMeta && memberMeta[1]) attrName = memberMeta[1];
1628
+ }
1629
+ }
1630
+ if (!attrName) attrName = propName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
1631
+ if (newValue == null || newValue === false) {
1632
+ if (newValue !== false || elm.getAttribute(attrName) === "") elm.removeAttribute(attrName);
1633
+ } else elm.setAttribute(attrName, newValue === true ? "" : newValue);
1634
+ return;
1635
+ } else if (BUILD.vdomPropOrAttr && memberName[0] === "p" && memberName.startsWith("prop:")) {
1636
+ const propName = memberName.slice(5);
1637
+ try {
1638
+ elm[propName] = newValue;
1639
+ } catch {}
1640
+ return;
1641
+ } else if (BUILD.vdomPropOrAttr) {
1642
+ const isComplex = isComplexType(newValue);
1643
+ if (!BUILD.lazyLoad) {
1644
+ const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
1645
+ if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
1646
+ if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
1647
+ elm["s-pp"].set(memberName, newValue);
1648
+ return;
1649
+ }
1650
+ }
1651
+ if ((isProp || isComplex && newValue !== null) && !isSvg) try {
1652
+ if (!elm.tagName.includes("-")) {
1653
+ const n = newValue == null ? "" : newValue;
1654
+ if (memberName === "list") isProp = false;
1655
+ else if (oldValue == null || elm[memberName] !== n) if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
1656
+ else elm.setAttribute(memberName, n);
1657
+ } else if (elm[memberName] !== newValue) elm[memberName] = newValue;
1658
+ } catch {}
1659
+ /**
1660
+ * Need to manually update attribute if:
1661
+ * - memberName is not an attribute
1662
+ * - if we are rendering the host element in order to reflect attribute
1663
+ * - if it's a SVG, since properties might not work in <svg>
1664
+ * - if the newValue is null/undefined or 'false'.
1665
+ */
1666
+ let xlink = false;
1667
+ if (BUILD.vdomXlink) {
1668
+ if (ln !== (ln = ln.replace(/^xlink:?/, ""))) {
1669
+ memberName = ln;
1670
+ xlink = true;
1671
+ }
1672
+ }
1673
+ if (newValue == null || newValue === false) {
1674
+ if (newValue !== false || elm.getAttribute(memberName) === "") if (BUILD.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1675
+ else elm.removeAttribute(memberName);
1676
+ } else if ((!isProp || flags & VNODE_FLAGS.isHost || isSvg) && !isComplex && elm.nodeType === NODE_TYPE.ElementNode) {
1677
+ newValue = newValue === true ? "" : newValue;
1678
+ if (BUILD.vdomXlink && xlink) elm.setAttributeNS(XLINK_NS, memberName, newValue);
1679
+ else elm.setAttribute(memberName, newValue);
1680
+ }
1681
+ }
1682
+ };
1683
+ const parseClassListRegex = /\s/;
1684
+ /**
1685
+ * Parsed a string of classnames into an array
1686
+ * @param value className string, e.g. "foo bar baz"
1687
+ * @returns list of classes, e.g. ["foo", "bar", "baz"]
1688
+ */
1689
+ const parseClassList = (value) => {
1690
+ if (typeof value === "object" && value && "baseVal" in value) value = value.baseVal;
1691
+ if (!value || typeof value !== "string") return [];
1692
+ return value.split(parseClassListRegex);
1693
+ };
1694
+ const CAPTURE_EVENT_SUFFIX = "Capture";
1695
+ //#endregion
1696
+ //#region src/runtime/vdom/update-element.ts
1697
+ /**
1698
+ * Handle updating attributes on the component element based on the current
1699
+ * values present in the virtual DOM.
1700
+ *
1701
+ * If the component of interest uses shadow DOM these are added to the shadow
1702
+ * root's host element.
1703
+ *
1704
+ * @param oldVnode an old virtual DOM node or null
1705
+ * @param newVnode a new virtual DOM node
1706
+ * @param isSvgMode whether or not we're in an SVG context
1707
+ * @param isInitialRender whether this is the first render of the VDOM
1708
+ */
1709
+ const updateElement = (oldVnode, newVnode, isSvgMode, isInitialRender) => {
1710
+ const oldVnodeAttrs = oldVnode && oldVnode.$attrs$ || {};
1711
+ const newVnodeAttrs = newVnode.$attrs$ || {};
1712
+ const oldKeys = Object.keys(oldVnodeAttrs);
1713
+ const newKeys = Object.keys(newVnodeAttrs);
1714
+ if (!BUILD.updatable && newKeys.length === 0) return;
1715
+ if (BUILD.updatable && oldKeys.length === 0 && newKeys.length === 0) return;
1716
+ const elm = newVnode.$elm$.nodeType === NODE_TYPE.DocumentFragment && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
1717
+ if (BUILD.updatable) {
1718
+ for (const memberName of sortedAttrNames(oldKeys)) if (!(memberName in newVnodeAttrs)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], void 0, isSvgMode, newVnode.$flags$, isInitialRender);
1719
+ }
1720
+ for (const memberName of sortedAttrNames(newKeys)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$, isInitialRender);
1721
+ };
1722
+ /**
1723
+ * Sort a list of attribute names to ensure that all the attribute names which
1724
+ * are _not_ `"ref"` come before `"ref"`. Preserve the order of the non-ref
1725
+ * attributes.
1726
+ *
1727
+ * **Note**: if the supplied attributes do not include `'ref'` then the same
1728
+ * (by reference) array will be returned without modification.
1729
+ *
1730
+ * @param attrNames attribute names to sort
1731
+ * @returns a list of attribute names, sorted if they include `"ref"`
1732
+ */
1733
+ function sortedAttrNames(attrNames) {
1734
+ if (!BUILD.vdomRef) return attrNames;
1735
+ return attrNames.includes("ref") ? [...attrNames.filter((attr) => attr !== "ref"), "ref"] : attrNames;
1736
+ }
1737
+ //#endregion
1738
+ //#region src/runtime/vdom/vdom-render.ts
1739
+ /**
1740
+ * Virtual DOM patching algorithm based on Snabbdom by
1741
+ * Simon Friis Vindum (@paldepind)
1742
+ * Licensed under the MIT License
1743
+ * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
1744
+ *
1745
+ * Modified for Stencil's renderer and slot projection
1746
+ */
1747
+ let scopeId;
1748
+ let contentRef;
1749
+ let hostTagName;
1750
+ let useNativeShadowDom = false;
1751
+ let checkSlotFallbackVisibility = false;
1752
+ let checkSlotRelocate = false;
1753
+ let isSvgMode = false;
1754
+ /**
1755
+ * Queues for ref callbacks that need to be called during rendering.
1756
+ * These ensure that ref callbacks are called in the correct order:
1757
+ * first all removal callbacks (with null), then all attachment callbacks (with elements).
1758
+ */
1759
+ const refCallbacksToRemove = [];
1760
+ const refCallbacksToAttach = [];
1761
+ /** Disposers for signal subscriptions on individual DOM nodes (text nodes, <s-show> wrappers). */
1762
+ const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
1763
+ const disposeSignalVNode = (vnode) => {
1764
+ const elm = vnode.$elm$;
1765
+ if (elm) {
1766
+ const dispose = signalNodeDisposers.get(elm);
1767
+ if (dispose) {
1768
+ dispose();
1769
+ signalNodeDisposers.delete(elm);
1770
+ }
1771
+ disposeAllSignalAttrs(elm);
1772
+ }
1773
+ vnode.$children$?.forEach(disposeSignalVNode);
1774
+ };
1775
+ /**
1776
+ * Create a DOM Node corresponding to one of the children of a given VNode.
1777
+ *
1778
+ * @param oldParentVNode the parent VNode from the previous render
1779
+ * @param newParentVNode the parent VNode from the current render
1780
+ * @param childIndex the index of the VNode, in the _new_ parent node's
1781
+ * children, for which we will create a new DOM node
1782
+ * @returns the newly created node
1783
+ */
1784
+ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1785
+ const newVNode = newParentVNode.$children$[childIndex];
1786
+ let i = 0;
1787
+ let elm;
1788
+ let childNode;
1789
+ let oldVNode;
1790
+ if (BUILD.slotRelocation && !useNativeShadowDom) {
1791
+ checkSlotRelocate = true;
1792
+ if (newVNode.$tag$ === "slot") newVNode.$flags$ |= newVNode.$children$ ? VNODE_FLAGS.isSlotFallback : VNODE_FLAGS.isSlotReference;
1793
+ }
1794
+ 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`);
1795
+ if (BUILD.vdomText && newVNode.$text$ != null) {
1796
+ elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
1797
+ if (BUILD.vdomSignals && newVNode.$signal$) {
1798
+ const textSig = newVNode.$signal$;
1799
+ const textNode = elm;
1800
+ signalNodeDisposers.set(textNode, effect$1(() => {
1801
+ textNode.data = String(textSig.value);
1802
+ }));
1803
+ }
1804
+ } else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1805
+ elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1806
+ if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1807
+ } else {
1808
+ if (BUILD.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
1809
+ if (!win.document) throw new Error("No DOM environment available for rendering.");
1810
+ const tag = !useNativeShadowDom && BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
1811
+ const _reg = getRegistry();
1812
+ const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
1813
+ elm = newVNode.$elm$ = BUILD.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
1814
+ if (BUILD.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
1815
+ if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1816
+ if ((BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) && isDef(scopeId) && elm["s-si"] !== scopeId) elm.classList.add(elm["s-si"] = scopeId);
1817
+ if (newVNode.$children$) {
1818
+ const appendTarget = newVNode.$tag$ === "template" ? elm.content : elm;
1819
+ for (i = 0; i < newVNode.$children$.length; ++i) {
1820
+ childNode = createElm(oldParentVNode, newVNode, i);
1821
+ if (childNode) appendTarget.appendChild(childNode);
1822
+ }
1823
+ }
1824
+ if (BUILD.svg) {
1825
+ if (newVNode.$tag$ === "svg") isSvgMode = false;
1826
+ else if (elm.tagName === "foreignObject") isSvgMode = true;
1827
+ }
1828
+ }
1829
+ elm["s-hn"] = hostTagName;
1830
+ if (BUILD.slotRelocation) {
1831
+ if (newVNode.$flags$ & (VNODE_FLAGS.isSlotFallback | VNODE_FLAGS.isSlotReference)) {
1832
+ elm["s-sr"] = true;
1833
+ elm["s-cr"] = contentRef;
1834
+ elm["s-sn"] = newVNode.$name$ || "";
1835
+ elm["s-rf"] = newVNode.$attrs$?.ref;
1836
+ patchSlotNode(elm);
1837
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
1838
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) relocateToHostRoot(oldParentVNode.$elm$);
1839
+ if (BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) addRemoveSlotScopedClass(contentRef, elm, newParentVNode.$elm$, oldParentVNode?.$elm$);
1840
+ }
1841
+ }
1842
+ return elm;
1843
+ };
1844
+ /**
1845
+ * Relocates all child nodes of an element that were a part of a previous slot relocation
1846
+ * to the root of the Stencil component currently being rendered. This happens when a parent
1847
+ * element of a slot reference node dynamically changes and triggers a re-render. We cannot use
1848
+ * `putBackInOriginalLocation()` because that may relocate nodes to elements that will not be re-rendered
1849
+ * and so they will not be relocated again.
1850
+ *
1851
+ * @param parentElm The element potentially containing relocated nodes.
1852
+ */
1853
+ const relocateToHostRoot = (parentElm) => {
1854
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
1855
+ const host = parentElm.closest(hostTagName.toLowerCase());
1856
+ if (host != null) {
1857
+ const contentRefNode = Array.from(host.__childNodes || host.childNodes).find((ref) => ref["s-cr"]);
1858
+ const childNodeArray = Array.from(parentElm.__childNodes || parentElm.childNodes);
1859
+ for (const childNode of contentRefNode ? childNodeArray.reverse() : childNodeArray) if (childNode["s-sh"] != null) {
1860
+ insertBefore(host, childNode, contentRefNode ?? null);
1861
+ childNode["s-sh"] = void 0;
1862
+ checkSlotRelocate = true;
1863
+ }
1864
+ }
1865
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
1866
+ };
1867
+ /**
1868
+ * Puts `<slot>` nodes and any slotted nodes back to their original location (wherever they were before being slotted).
1869
+ *
1870
+ * @param parentElm - The parent element of the nodes to relocate.
1871
+ * @param recursive - Whether or not to relocate nodes in child nodes as well.
1872
+ */
1873
+ const putBackInOriginalLocation = (parentElm, recursive) => {
1874
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
1875
+ const oldSlotChildNodes = Array.from(parentElm.__childNodes || parentElm.childNodes);
1876
+ if (parentElm["s-sr"]) {
1877
+ let node = parentElm;
1878
+ while (node = node.nextSibling) if (node && node["s-sn"] === parentElm["s-sn"] && node["s-sh"] === hostTagName) oldSlotChildNodes.push(node);
1879
+ }
1880
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
1881
+ const childNode = oldSlotChildNodes[i];
1882
+ if (childNode["s-hn"] !== hostTagName && childNode["s-ol"]) {
1883
+ insertBefore(referenceNode(childNode).parentNode, childNode, referenceNode(childNode));
1884
+ childNode["s-ol"].remove();
1885
+ childNode["s-ol"] = void 0;
1886
+ childNode["s-sh"] = void 0;
1887
+ checkSlotRelocate = true;
1888
+ }
1889
+ if (recursive) putBackInOriginalLocation(childNode, recursive);
1890
+ }
1891
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
1892
+ };
1893
+ /**
1894
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
1895
+ * add them to the DOM in the appropriate place.
1896
+ *
1897
+ * @param parentElm the DOM node which should be used as a parent for the new
1898
+ * DOM nodes
1899
+ * @param before a child of the `parentElm` which the new children should be
1900
+ * inserted before (optional)
1901
+ * @param parentVNode the parent virtual DOM node
1902
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
1903
+ * @param startIdx the index in the child virtual DOM nodes at which to start
1904
+ * creating DOM nodes (inclusive)
1905
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
1906
+ * creating DOM nodes (inclusive)
1907
+ */
1908
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
1909
+ let containerElm = BUILD.slotRelocation && parentElm["s-cr"] && parentElm["s-cr"].parentNode || parentElm;
1910
+ let childNode;
1911
+ if (BUILD.shadowDom && containerElm.tagName === hostTagName) {
1912
+ const shadow = getShadowRoot(containerElm);
1913
+ if (shadow) containerElm = shadow;
1914
+ }
1915
+ if (parentVNode.$tag$ === "template") containerElm = containerElm.content;
1916
+ for (; startIdx <= endIdx; ++startIdx) if (vnodes[startIdx]) {
1917
+ childNode = createElm(null, parentVNode, startIdx);
1918
+ if (childNode) {
1919
+ vnodes[startIdx].$elm$ = childNode;
1920
+ insertBefore(containerElm, childNode, BUILD.slotRelocation ? referenceNode(before) : before);
1921
+ }
1922
+ }
1923
+ };
1924
+ /**
1925
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
1926
+ * This can be used to, for instance, clean up after a list of children which
1927
+ * should no longer be shown.
1928
+ *
1929
+ * This function also handles some of Stencil's slot relocation logic.
1930
+ *
1931
+ * @param vnodes a list of virtual DOM nodes to remove
1932
+ * @param startIdx the index at which to start removing nodes (inclusive)
1933
+ * @param endIdx the index at which to stop removing nodes (inclusive)
1934
+ */
1935
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
1936
+ for (let index = startIdx; index <= endIdx; ++index) {
1937
+ const vnode = vnodes[index];
1938
+ if (vnode) {
1939
+ const elm = vnode.$elm$;
1940
+ nullifyVNodeRefs(vnode);
1941
+ if (BUILD.vdomSignals) disposeSignalVNode(vnode);
1942
+ if (elm) {
1943
+ if (BUILD.slotRelocation) {
1944
+ checkSlotFallbackVisibility = true;
1945
+ if (elm["s-ol"]) elm["s-ol"].remove();
1946
+ else putBackInOriginalLocation(elm, true);
1947
+ }
1948
+ elm.remove();
1949
+ }
1950
+ }
1951
+ }
1952
+ };
1953
+ /**
1954
+ * Reconcile the children of a new VNode with the children of an old VNode by
1955
+ * traversing the two collections of children, identifying nodes that are
1956
+ * conserved or changed, calling out to `patch` to make any necessary
1957
+ * updates to the DOM, and rearranging DOM nodes as needed.
1958
+ *
1959
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
1960
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
1961
+ * 'windows' by storing start and end indices and references to the
1962
+ * corresponding array entries. Initially the two 'windows' are basically equal
1963
+ * to the entire array, but we progressively narrow the windows until there are
1964
+ * no children left to update by doing the following:
1965
+ *
1966
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
1967
+ * that if we have an initial array like the following we'll end up dealing
1968
+ * only with a window bounded by the highlighted elements:
1969
+ *
1970
+ * [null, null, VNode1 , ... , VNode2, null, null]
1971
+ * ^^^^^^ ^^^^^^
1972
+ *
1973
+ * 2. Check to see if the elements at the head and tail positions are equal
1974
+ * across the windows. This will basically detect elements which haven't
1975
+ * been added, removed, or changed position, i.e. if you had the following
1976
+ * VNode elements (represented as HTML):
1977
+ *
1978
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
1979
+ * newVNode: `<div><p><span>THERE</span></p></div>`
1980
+ *
1981
+ * Then when comparing the children of the `<div>` tag we check the equality
1982
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
1983
+ * same tag in the same position, we'd be able to avoid completely
1984
+ * re-rendering the subtree under them with a new DOM element and would just
1985
+ * call out to `patch` to handle reconciling their children and so on.
1986
+ *
1987
+ * 3. Check, for both windows, to see if the element at the beginning of the
1988
+ * window corresponds to the element at the end of the other window. This is
1989
+ * a heuristic which will let us identify _some_ situations in which
1990
+ * elements have changed position, for instance it _should_ detect that the
1991
+ * children nodes themselves have not changed but merely moved in the
1992
+ * following example:
1993
+ *
1994
+ * oldVNode: `<div><element-one /><element-two /></div>`
1995
+ * newVNode: `<div><element-two /><element-one /></div>`
1996
+ *
1997
+ * If we find cases like this then we also need to move the concrete DOM
1998
+ * elements corresponding to the moved children to write the re-order to the
1999
+ * DOM.
2000
+ *
2001
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
2002
+ * nodes in the old children which have the same key as the first element in
2003
+ * our window on the new children. If we find such a node we handle calling
2004
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
2005
+ * what we find.
2006
+ *
2007
+ * Finally, once we've narrowed our 'windows' to the point that either of them
2008
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
2009
+ * insertion or deletion that needs to happen to get a DOM state that correctly
2010
+ * reflects the new child VNodes. If, for instance, after our window on the old
2011
+ * children has collapsed we still have more nodes on the new children that
2012
+ * we haven't dealt with yet then we need to add them, or if the new children
2013
+ * collapse but we still have unhandled _old_ children then we need to make
2014
+ * sure the corresponding DOM nodes are removed.
2015
+ *
2016
+ * @param parentElm the node into which the parent VNode is rendered
2017
+ * @param oldCh the old children of the parent node
2018
+ * @param newVNode the new VNode which will replace the parent
2019
+ * @param newCh the new children of the parent node
2020
+ * @param isInitialRender whether or not this is the first render of the vdom
2021
+ */
2022
+ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
2023
+ let oldStartIdx = 0;
2024
+ let newStartIdx = 0;
2025
+ let idxInOld = 0;
2026
+ let i = 0;
2027
+ let oldEndIdx = oldCh.length - 1;
2028
+ let oldStartVnode = oldCh[0];
2029
+ let oldEndVnode = oldCh[oldEndIdx];
2030
+ let newEndIdx = newCh.length - 1;
2031
+ let newStartVnode = newCh[0];
2032
+ let newEndVnode = newCh[newEndIdx];
2033
+ let node;
2034
+ let elmToMove;
2035
+ const containerElm = newVNode.$tag$ === "template" ? parentElm.content : parentElm;
2036
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) if (oldStartVnode == null) oldStartVnode = oldCh[++oldStartIdx];
2037
+ else if (oldEndVnode == null) oldEndVnode = oldCh[--oldEndIdx];
2038
+ else if (newStartVnode == null) newStartVnode = newCh[++newStartIdx];
2039
+ else if (newEndVnode == null) newEndVnode = newCh[--newEndIdx];
2040
+ else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
2041
+ patch(oldStartVnode, newStartVnode, isInitialRender);
2042
+ oldStartVnode = oldCh[++oldStartIdx];
2043
+ newStartVnode = newCh[++newStartIdx];
2044
+ } else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
2045
+ patch(oldEndVnode, newEndVnode, isInitialRender);
2046
+ oldEndVnode = oldCh[--oldEndIdx];
2047
+ newEndVnode = newCh[--newEndIdx];
2048
+ } else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
2049
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
2050
+ patch(oldStartVnode, newEndVnode, isInitialRender);
2051
+ insertBefore(containerElm, oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
2052
+ oldStartVnode = oldCh[++oldStartIdx];
2053
+ newEndVnode = newCh[--newEndIdx];
2054
+ } else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
2055
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
2056
+ patch(oldEndVnode, newStartVnode, isInitialRender);
2057
+ insertBefore(containerElm, oldEndVnode.$elm$, oldStartVnode.$elm$);
2058
+ oldEndVnode = oldCh[--oldEndIdx];
2059
+ newStartVnode = newCh[++newStartIdx];
2060
+ } else {
2061
+ idxInOld = -1;
2062
+ if (BUILD.vdomKey) {
2063
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
2064
+ idxInOld = i;
2065
+ break;
2066
+ }
2067
+ }
2068
+ if (BUILD.vdomKey && idxInOld >= 0) {
2069
+ elmToMove = oldCh[idxInOld];
2070
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
2071
+ else {
2072
+ patch(elmToMove, newStartVnode, isInitialRender);
2073
+ oldCh[idxInOld] = void 0;
2074
+ node = elmToMove.$elm$;
2075
+ }
2076
+ newStartVnode = newCh[++newStartIdx];
2077
+ } else {
2078
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
2079
+ newStartVnode = newCh[++newStartIdx];
2080
+ }
2081
+ if (node) if (BUILD.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
2082
+ else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
2083
+ }
2084
+ if (oldStartIdx > oldEndIdx) addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
2085
+ else if (BUILD.updatable && newStartIdx > newEndIdx) removeVnodes(oldCh, oldStartIdx, oldEndIdx);
2086
+ };
2087
+ /**
2088
+ * Compare two VNodes to determine if they are the same
2089
+ *
2090
+ * **NB**: This function is an equality _heuristic_ based on the available
2091
+ * information set on the two VNodes and can be misleading under certain
2092
+ * circumstances. In particular, if the two nodes do not have `key` attrs
2093
+ * (available under `$key$` on VNodes) then the function falls back on merely
2094
+ * checking that they have the same tag.
2095
+ *
2096
+ * So, in other words, if `key` attrs are not set on VNodes which may be
2097
+ * changing order within a `children` array or something along those lines then
2098
+ * we could obtain a false negative and then have to do needless re-rendering
2099
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
2100
+ *
2101
+ * @param leftVNode the first VNode to check
2102
+ * @param rightVNode the second VNode to check
2103
+ * @param isInitialRender whether or not this is the first render of the vdom
2104
+ * @returns whether they're equal or not
2105
+ */
2106
+ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
2107
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
2108
+ if (BUILD.slotRelocation && leftVNode.$tag$ === "slot") return leftVNode.$name$ === rightVNode.$name$;
2109
+ if (BUILD.vdomKey && !isInitialRender) return leftVNode.$key$ === rightVNode.$key$;
2110
+ if (isInitialRender && !leftVNode.$key$ && rightVNode.$key$) leftVNode.$key$ = rightVNode.$key$;
2111
+ return true;
2112
+ }
2113
+ return false;
2114
+ };
2115
+ /**
2116
+ * Returns the reference node (a comment which represents the
2117
+ * original location of a node in the vdom - before it was moved to its slot)
2118
+ * of a given node.
2119
+ *
2120
+ * (slot nodes can be relocated to a new location in the dom because of
2121
+ * some other component's slot)
2122
+ * @param node the node to find the original location reference node for
2123
+ * @returns reference node
2124
+ */
2125
+ const referenceNode = (node) => node && node["s-ol"] || node;
2126
+ /**
2127
+ * Handle reconciling an outdated VNode with a new one which corresponds to
2128
+ * it. This function handles flushing updates to the DOM and reconciling the
2129
+ * children of the two nodes (if any).
2130
+ *
2131
+ * @param oldVNode an old VNode whose DOM element and children we want to update
2132
+ * @param newVNode a new VNode representing an updated version of the old one
2133
+ * @param isInitialRender whether or not this is the first render of the vdom
2134
+ */
2135
+ const patch = (oldVNode, newVNode, isInitialRender = false) => {
2136
+ const elm = newVNode.$elm$ = oldVNode.$elm$;
2137
+ const oldChildren = oldVNode.$children$;
2138
+ const newChildren = newVNode.$children$;
2139
+ const tag = newVNode.$tag$;
2140
+ const text = newVNode.$text$;
2141
+ let defaultHolder;
2142
+ if (!BUILD.vdomText || text == null) {
2143
+ if (BUILD.svg) isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
2144
+ if (BUILD.vdomAttribute || BUILD.reflect) {
2145
+ if (BUILD.slot && tag === "slot" && !useNativeShadowDom) {
2146
+ if (oldVNode.$name$ !== newVNode.$name$) {
2147
+ newVNode.$elm$["s-sn"] = newVNode.$name$ || "";
2148
+ relocateToHostRoot(newVNode.$elm$.parentElement);
2149
+ }
2150
+ }
2151
+ updateElement(oldVNode, newVNode, isSvgMode, isInitialRender);
2152
+ }
2153
+ if (BUILD.updatable && oldChildren !== null && newChildren !== null) updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
2154
+ else if (newChildren !== null) {
2155
+ if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) elm.textContent = "";
2156
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
2157
+ } else if (!isInitialRender && BUILD.updatable && oldChildren !== null) removeVnodes(oldChildren, 0, oldChildren.length - 1);
2158
+ else if (BUILD.hydrateClientSide && isInitialRender && BUILD.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
2159
+ if (BUILD.svg && isSvgMode && tag === "svg") isSvgMode = false;
2160
+ } else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
2161
+ else if (BUILD.vdomText && oldVNode.$text$ !== text) elm.data = text;
2162
+ };
2163
+ /**
2164
+ * Component-global information about nodes which are either currently being
2165
+ * relocated or will be shortly.
2166
+ */
2167
+ const relocateNodes = [];
2168
+ /**
2169
+ * Mark the contents of a slot for relocation via adding references to them to
2170
+ * the {@link relocateNodes} data structure. The actual work of relocating them
2171
+ * will then be handled in {@link renderVdom}.
2172
+ *
2173
+ * @param elm a render node whose child nodes need to be relocated
2174
+ */
2175
+ const markSlotContentForRelocation = (elm) => {
2176
+ let node;
2177
+ let hostContentNodes;
2178
+ let j;
2179
+ const children = elm.__childNodes || elm.childNodes;
2180
+ for (const childNode of children) {
2181
+ if (childNode["s-sr"] && (node = childNode["s-cr"]) && node.parentNode) {
2182
+ hostContentNodes = node.parentNode.__childNodes || node.parentNode.childNodes;
2183
+ const slotName = childNode["s-sn"];
2184
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
2185
+ node = hostContentNodes[j];
2186
+ if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== childNode["s-hn"] && (!node["s-sh"] || node["s-sh"] !== childNode["s-hn"])) {
2187
+ if (isNodeLocatedInSlot(node, slotName)) {
2188
+ let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
2189
+ checkSlotFallbackVisibility = true;
2190
+ node["s-sn"] = node["s-sn"] || slotName;
2191
+ if (relocateNodeData) {
2192
+ relocateNodeData.$nodeToRelocate$["s-sh"] = childNode["s-hn"];
2193
+ relocateNodeData.$slotRefNode$ = childNode;
2194
+ } else {
2195
+ node["s-sh"] = childNode["s-hn"];
2196
+ relocateNodes.push({
2197
+ $slotRefNode$: childNode,
2198
+ $nodeToRelocate$: node
2199
+ });
2200
+ }
2201
+ if (node["s-sr"]) relocateNodes.map((relocateNode) => {
2202
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node["s-sn"])) {
2203
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
2204
+ if (relocateNodeData && !relocateNode.$slotRefNode$) relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
2205
+ }
2206
+ });
2207
+ } else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) relocateNodes.push({ $nodeToRelocate$: node });
2208
+ }
2209
+ }
2210
+ }
2211
+ if (childNode.nodeType === NODE_TYPE.ElementNode) markSlotContentForRelocation(childNode);
2212
+ }
2213
+ };
2214
+ /**
2215
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
2216
+ * them with `null`. This signals that the DOM element corresponding to the VDom
2217
+ * node has been removed from the DOM.
2218
+ *
2219
+ * @param vNode a virtual DOM node
2220
+ */
2221
+ const nullifyVNodeRefs = (vNode) => {
2222
+ if (BUILD.vdomRef) {
2223
+ if (vNode.$attrs$ && vNode.$attrs$.ref) refCallbacksToRemove.push(() => vNode.$attrs$.ref(null));
2224
+ if (vNode.$children$) vNode.$children$.map(nullifyVNodeRefs);
2225
+ }
2226
+ };
2227
+ /**
2228
+ * Queue a ref callback to be called with an element during rendering.
2229
+ * This ensures ref callbacks are called in the correct order.
2230
+ *
2231
+ * @param refCallback the ref callback function to queue
2232
+ * @param elm the element to pass to the callback
2233
+ */
2234
+ const queueRefAttachment = (refCallback, elm) => {
2235
+ if (BUILD.vdomRef) refCallbacksToAttach.push(() => refCallback(elm));
2236
+ };
2237
+ /**
2238
+ * Flush all queued ref callbacks in the correct order:
2239
+ * first all removal callbacks (with null), then all attachment callbacks (with elements).
2240
+ * This ensures that when elements are replaced/reordered, the ref is always left
2241
+ * pointing to the current element, not null.
2242
+ */
2243
+ const flushQueuedRefCallbacks = () => {
2244
+ if (BUILD.vdomRef) {
2245
+ refCallbacksToRemove.forEach((cb) => cb());
2246
+ refCallbacksToRemove.length = 0;
2247
+ refCallbacksToAttach.forEach((cb) => cb());
2248
+ refCallbacksToAttach.length = 0;
2249
+ }
2250
+ };
2251
+ /**
2252
+ * Inserts a node before a reference node as a child of a specified parent node.
2253
+ * Additionally, adds parent elements' scope ids as class names to the new node.
2254
+ *
2255
+ * @param parent parent node
2256
+ * @param newNode element to be inserted
2257
+ * @param reference anchor element
2258
+ * @param isInitialLoad whether or not this is the first render
2259
+ * @returns inserted node
2260
+ */
2261
+ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2262
+ if (BUILD.slotRelocation) {
2263
+ if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2264
+ else if (typeof newNode["s-sn"] === "string") {
2265
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2266
+ 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);
2267
+ parent.insertBefore(newNode, reference);
2268
+ const { slotNode } = findSlotFromSlottedNode(newNode);
2269
+ if (slotNode && !isInitialLoad) dispatchSlotChangeEvent(slotNode);
2270
+ return newNode;
2271
+ }
2272
+ }
2273
+ if (parent.__insertBefore) return parent.__insertBefore(newNode, reference);
2274
+ else return parent?.insertBefore(newNode, reference);
2275
+ };
2276
+ /**
2277
+ * Adds or removes a scoped class to the parent element of a slotted node.
2278
+ * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
2279
+ * in `scoped: true` components.
2280
+ *
2281
+ * @param reference - Content Reference Node. Used to get the scope id of the parent component.
2282
+ * @param slotNode - the `<slot>` node to apply the class for
2283
+ * @param newParent - the slots' new parent element that requires the scoped class
2284
+ * @param oldParent - optionally, an old parent element that may no longer require the scoped class
2285
+ */
2286
+ function addRemoveSlotScopedClass(reference, slotNode, newParent, oldParent) {
2287
+ let slotScopeId;
2288
+ if (reference && typeof slotNode["s-sn"] === "string" && !!slotNode["s-sr"] && reference.parentNode && reference.parentNode["s-sc"] && (slotScopeId = slotNode["s-si"] || reference.parentNode["s-sc"])) {
2289
+ const scopeName = slotNode["s-sn"];
2290
+ const hostName = slotNode["s-hn"];
2291
+ newParent.classList?.add(slotScopeId + "-s");
2292
+ if (oldParent && oldParent.classList?.contains(slotScopeId + "-s")) {
2293
+ let child = (oldParent.__childNodes || oldParent.childNodes)[0];
2294
+ let found = false;
2295
+ while (child) {
2296
+ if (child["s-sn"] !== scopeName && child["s-hn"] === hostName && !!child["s-sr"]) {
2297
+ found = true;
2298
+ break;
2299
+ }
2300
+ child = child.nextSibling;
2301
+ }
2302
+ if (!found) oldParent.classList.remove(slotScopeId + "-s");
2303
+ }
2304
+ }
2305
+ }
2306
+ /**
2307
+ * The main entry point for Stencil's virtual DOM-based rendering engine
2308
+ *
2309
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
2310
+ * function will handle creating a virtual DOM tree with a single root, patching
2311
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
2312
+ * relocation, and reflecting attributes.
2313
+ *
2314
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
2315
+ * the DOM node into which it should be rendered.
2316
+ * @param renderFnResults the virtual DOM nodes to be rendered
2317
+ * @param isInitialLoad whether or not this is the first call after page load
2318
+ */
2319
+ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
2320
+ const hostElm = hostRef.$hostElement$;
2321
+ const cmpMeta = hostRef.$cmpMeta$;
2322
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
2323
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
2324
+ hostTagName = hostElm.tagName;
2325
+ if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
2326
+ Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
2327
+
2328
+ The render() function should look like this instead:
2329
+
2330
+ render() {
2331
+ // Do not return an array
2332
+ return (
2333
+ <Host>{content}</Host>
2334
+ );
2335
+ }
2336
+ `);
2337
+ if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
2338
+ rootVnode.$attrs$ = rootVnode.$attrs$ || {};
2339
+ cmpMeta.$attrsToReflect$.forEach(([propName, attribute]) => {
2340
+ if (BUILD.serializer && hostRef.$serializerValues$.has(propName)) rootVnode.$attrs$[attribute] = hostRef.$serializerValues$.get(propName);
2341
+ else rootVnode.$attrs$[attribute] = hostElm[propName];
2342
+ });
2343
+ }
2344
+ if (isInitialLoad && rootVnode.$attrs$) {
2345
+ for (const key of Object.keys(rootVnode.$attrs$)) if (hostElm.hasAttribute(key) && ![
2346
+ "key",
2347
+ "ref",
2348
+ "style",
2349
+ "class"
2350
+ ].includes(key)) rootVnode.$attrs$[key] = hostElm[key];
2351
+ }
2352
+ rootVnode.$tag$ = null;
2353
+ rootVnode.$flags$ |= VNODE_FLAGS.isHost;
2354
+ hostRef.$vnode$ = rootVnode;
2355
+ rootVnode.$elm$ = oldVNode.$elm$ = BUILD.shadowDom ? getShadowRoot(hostElm) || hostElm : hostElm;
2356
+ if (BUILD.scoped || BUILD.shadowDom) scopeId = hostElm["s-sc"];
2357
+ useNativeShadowDom = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss);
2358
+ if (BUILD.slotRelocation) {
2359
+ contentRef = hostElm["s-cr"];
2360
+ checkSlotFallbackVisibility = false;
2361
+ }
2362
+ patch(oldVNode, rootVnode, isInitialLoad);
2363
+ if (BUILD.slotRelocation) {
2364
+ plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
2365
+ if (checkSlotRelocate) {
2366
+ markSlotContentForRelocation(rootVnode.$elm$);
2367
+ for (const relocateData of relocateNodes) {
2368
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
2369
+ if (!nodeToRelocate["s-ol"] && win.document) {
2370
+ const orgLocationNode = BUILD.isDebug || BUILD.hydrateServerSide ? originalLocationDebugNode(nodeToRelocate) : win.document.createTextNode("");
2371
+ orgLocationNode["s-nr"] = nodeToRelocate;
2372
+ insertBefore(nodeToRelocate.parentNode, nodeToRelocate["s-ol"] = orgLocationNode, nodeToRelocate, isInitialLoad);
2373
+ }
2374
+ }
2375
+ for (const relocateData of relocateNodes) {
2376
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
2377
+ const slotRefNode = relocateData.$slotRefNode$;
2378
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && isInitialLoad) nodeToRelocate["s-ih"] = !!nodeToRelocate.hidden;
2379
+ if (slotRefNode) {
2380
+ const parentNodeRef = slotRefNode.parentNode;
2381
+ let insertBeforeNode = slotRefNode.nextSibling;
2382
+ if (!BUILD.hydrateServerSide && insertBeforeNode && insertBeforeNode.nodeType === NODE_TYPE.ElementNode) {
2383
+ let orgLocationNode = nodeToRelocate["s-ol"]?.previousSibling;
2384
+ while (orgLocationNode) {
2385
+ let refNode = orgLocationNode["s-nr"] ?? null;
2386
+ if (refNode && refNode["s-sn"] === nodeToRelocate["s-sn"] && parentNodeRef === (refNode.__parentNode || refNode.parentNode)) {
2387
+ refNode = refNode.nextSibling;
2388
+ while (refNode === nodeToRelocate || refNode?.["s-sr"]) refNode = refNode?.nextSibling;
2389
+ if (!refNode || !refNode["s-nr"]) {
2390
+ insertBeforeNode = refNode;
2391
+ break;
2392
+ }
2393
+ }
2394
+ orgLocationNode = orgLocationNode.previousSibling;
2395
+ }
2396
+ }
2397
+ const parent = nodeToRelocate.__parentNode || nodeToRelocate.parentNode;
2398
+ const nextSibling = nodeToRelocate.__nextSibling || nodeToRelocate.nextSibling;
2399
+ if (!insertBeforeNode && parentNodeRef !== parent || nextSibling !== insertBeforeNode) {
2400
+ if (nodeToRelocate !== insertBeforeNode) {
2401
+ insertBefore(parentNodeRef, nodeToRelocate, insertBeforeNode, isInitialLoad);
2402
+ if (nodeToRelocate.nodeType === NODE_TYPE.CommentNode && nodeToRelocate.nodeValue.startsWith("s-nt-")) {
2403
+ const textNode = win.document.createTextNode(nodeToRelocate.nodeValue.replace(/^s-nt-/, ""));
2404
+ textNode["s-hn"] = nodeToRelocate["s-hn"];
2405
+ textNode["s-sn"] = nodeToRelocate["s-sn"];
2406
+ textNode["s-sh"] = nodeToRelocate["s-sh"];
2407
+ textNode["s-sr"] = nodeToRelocate["s-sr"];
2408
+ textNode["s-ol"] = nodeToRelocate["s-ol"];
2409
+ textNode["s-ol"]["s-nr"] = textNode;
2410
+ insertBefore(nodeToRelocate.parentNode, textNode, nodeToRelocate, isInitialLoad);
2411
+ nodeToRelocate.parentNode.removeChild(nodeToRelocate);
2412
+ }
2413
+ if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && nodeToRelocate.tagName !== "SLOT-FB") nodeToRelocate.hidden = nodeToRelocate["s-ih"] ?? false;
2414
+ }
2415
+ }
2416
+ if (nodeToRelocate && typeof slotRefNode["s-rf"] === "function") slotRefNode["s-rf"](slotRefNode);
2417
+ } else if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) nodeToRelocate.hidden = true;
2418
+ }
2419
+ }
2420
+ if (checkSlotFallbackVisibility) updateFallbackSlotVisibility(rootVnode.$elm$);
2421
+ plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
2422
+ relocateNodes.length = 0;
2423
+ }
2424
+ if (BUILD.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2425
+ const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
2426
+ for (const childNode of children) if (childNode["s-hn"] !== hostTagName && !childNode["s-sh"]) {
2427
+ if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
2428
+ if (childNode.nodeType === NODE_TYPE.ElementNode) childNode.hidden = true;
2429
+ else if (childNode.nodeType === NODE_TYPE.TextNode && !!childNode.nodeValue.trim()) {
2430
+ const textCommentNode = win.document.createComment("s-nt-" + childNode.nodeValue);
2431
+ textCommentNode["s-sn"] = childNode["s-sn"];
2432
+ insertBefore(childNode.parentNode, textCommentNode, childNode, isInitialLoad);
2433
+ childNode.parentNode.removeChild(childNode);
2434
+ }
2435
+ }
2436
+ }
2437
+ contentRef = void 0;
2438
+ flushQueuedRefCallbacks();
2439
+ };
2440
+ const slotReferenceDebugNode = (slotVNode) => win.document?.createComment(`<slot${slotVNode.$name$ ? " name=\"" + slotVNode.$name$ + "\"" : ""}> (host=${hostTagName.toLowerCase()})`);
2441
+ const originalLocationDebugNode = (nodeToRelocate) => win.document?.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate["s-hn"]})` : `[${nodeToRelocate.textContent}]`));
2442
+ //#endregion
2443
+ //#region src/runtime/update-component.ts
2444
+ const attachToAncestor = (hostRef, ancestorComponent) => {
2445
+ if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
2446
+ const index = ancestorComponent["s-p"].push(new Promise((r) => hostRef.$onRenderResolve$ = () => {
2447
+ ancestorComponent["s-p"].splice(index - 1, 1);
2448
+ r();
2449
+ }));
2450
+ }
2451
+ };
2452
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
2453
+ if (BUILD.taskQueue && BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2454
+ if (BUILD.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
2455
+ hostRef.$flags$ |= HOST_FLAGS.needsRerender;
2456
+ return;
2457
+ }
2458
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
2459
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
2460
+ if (isInitialLoad) {
2461
+ queueMicrotask(() => {
2462
+ dispatch();
2463
+ });
2464
+ return;
2465
+ }
2466
+ return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
2467
+ };
2468
+ /**
2469
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
2470
+ * component lifecycle methods like `componentWillLoad` as well as
2471
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
2472
+ *
2473
+ * @param hostRef a reference to a host DOM node
2474
+ * @param isInitialLoad whether we're on the initial load or not
2475
+ * @returns an empty Promise which is used to enqueue a series of operations for
2476
+ * the component
2477
+ */
2478
+ const dispatchHooks = (hostRef, isInitialLoad) => {
2479
+ const elm = hostRef.$hostElement$;
2480
+ const endSchedule = createTime("scheduleUpdate", hostRef.$cmpMeta$.$tagName$);
2481
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2482
+ /**
2483
+ * Given a user imports a component compiled with a `dist-custom-element`
2484
+ * output target into a Stencil project compiled with a `dist` output target,
2485
+ * then `instance` will be `undefined` as `hostRef` won't have a `lazyInstance`
2486
+ * property. In this case, the component will fail to render in one of the
2487
+ * subsequent functions.
2488
+ *
2489
+ * For this scenario to work the user needs to set the `externalRuntime` flag
2490
+ * for the `dist-custom-element` component that is being imported into the `dist`
2491
+ * Stencil project.
2492
+ */
2493
+ if (!instance) {
2494
+ if (BUILD.isDev) throw new Error(`Can't render <${elm.tagName.toLowerCase()} /> - compiled without externalRuntime: true. See https://stenciljs.com/docs/custom-elements#externalruntime`);
2495
+ return;
2496
+ }
2497
+ let maybePromise;
2498
+ if (isInitialLoad) {
2499
+ if (BUILD.lazyLoad) {
2500
+ if (BUILD.slotRelocation && hostRef.$deferredConnectedCallback$) {
2501
+ hostRef.$deferredConnectedCallback$ = false;
2502
+ safeCall(instance, "connectedCallback", void 0, elm);
2503
+ }
2504
+ if (BUILD.hostListener) {
2505
+ hostRef.$flags$ |= HOST_FLAGS.isListenReady;
2506
+ if (hostRef.$queuedListeners$) {
2507
+ hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event, elm));
2508
+ hostRef.$queuedListeners$ = void 0;
2509
+ }
2510
+ }
2511
+ if (hostRef.$fetchedCbList$.length) hostRef.$fetchedCbList$.forEach((cb) => cb(elm));
2512
+ }
2513
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillLoad");
2514
+ maybePromise = safeCall(instance, "componentWillLoad", void 0, elm);
2515
+ } else {
2516
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillUpdate");
2517
+ maybePromise = safeCall(instance, "componentWillUpdate", void 0, elm);
2518
+ }
2519
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillRender");
2520
+ maybePromise = enqueue(maybePromise, () => safeCall(instance, "componentWillRender", void 0, elm));
2521
+ endSchedule();
2522
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
2523
+ };
2524
+ /**
2525
+ * This function uses a Promise to implement a simple first-in, first-out queue
2526
+ * of functions to be called.
2527
+ *
2528
+ * The queue is ordered on the basis of the first argument. If it's
2529
+ * `undefined`, then nothing is on the queue yet, so the provided function can
2530
+ * be called synchronously (although note that this function may return a
2531
+ * `Promise`). The idea is that then the return value of that enqueueing
2532
+ * operation is kept around, so that if it was a `Promise` then subsequent
2533
+ * functions can be enqueued by calling this function again with that `Promise`
2534
+ * as the first argument.
2535
+ *
2536
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
2537
+ * @param fn a function to enqueue
2538
+ * @returns either a `Promise` or the return value of the provided function
2539
+ */
2540
+ const enqueue = (maybePromise, fn) => {
2541
+ if (isPromisey(maybePromise)) return maybePromise.then(fn).catch((err) => {
2542
+ console.error(err);
2543
+ fn();
2544
+ });
2545
+ const result = fn();
2546
+ return isPromisey(result) ? result : void 0;
2547
+ };
2548
+ /**
2549
+ * Check that a value is a `Promise`. To check, we first see if the value is an
2550
+ * instance of the `Promise` global. In a few circumstances, in particular if
2551
+ * the global has been overwritten, this is could be misleading, so we also do
2552
+ * a little 'duck typing' check to see if the `.then` property of the value is
2553
+ * defined and a function.
2554
+ *
2555
+ * @param maybePromise it might be a promise!
2556
+ * @returns whether it is or not
2557
+ */
2558
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise || maybePromise && maybePromise.then && typeof maybePromise.then === "function";
2559
+ /**
2560
+ * Update a component given reference to its host elements and so on.
2561
+ *
2562
+ * @param hostRef an object containing references to the element's host node,
2563
+ * VDom nodes, and other metadata
2564
+ * @param instance a reference to the underlying host element where it will be
2565
+ * rendered
2566
+ * @param isInitialLoad whether or not this function is being called as part of
2567
+ * the first render cycle
2568
+ * @returns a `Promise` if the update is asynchronous, otherwise `void`
2569
+ */
2570
+ const updateComponent = (hostRef, instance, isInitialLoad) => {
2571
+ const elm = hostRef.$hostElement$;
2572
+ const endUpdate = createTime("update", hostRef.$cmpMeta$.$tagName$);
2573
+ const rc = elm["s-rc"];
2574
+ if (BUILD.style && isInitialLoad) attachStyles(hostRef);
2575
+ const endRender = createTime("render", hostRef.$cmpMeta$.$tagName$);
2576
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
2577
+ if (BUILD.hydrateServerSide) return callRender(hostRef, instance, elm, isInitialLoad).then(() => {
2578
+ afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
2579
+ });
2580
+ callRender(hostRef, instance, elm, isInitialLoad);
2581
+ afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
2582
+ };
2583
+ const afterRender = (hostRef, elm, rc, isInitialLoad, endRender, endUpdate) => {
2584
+ if (BUILD.isDev) {
2585
+ hostRef.$renderCount$ = hostRef.$renderCount$ === void 0 ? 1 : hostRef.$renderCount$ + 1;
2586
+ hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
2587
+ }
2588
+ if (BUILD.hydrateServerSide) try {
2589
+ serverSideConnected(elm);
2590
+ if (isInitialLoad) {
2591
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) elm["s-en"] = "";
2592
+ else if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.scopedCssEncapsulation) elm["s-en"] = "c";
2593
+ }
2594
+ } catch (e) {
2595
+ consoleError(e, elm);
2596
+ }
2597
+ if (BUILD.asyncLoading && rc) {
2598
+ rc.map((cb) => cb());
2599
+ elm["s-rc"] = void 0;
2600
+ }
2601
+ endRender();
2602
+ endUpdate();
2603
+ if (BUILD.asyncLoading) {
2604
+ const childrenPromises = elm["s-p"] ?? [];
2605
+ const postUpdate = () => postUpdateComponent(hostRef);
2606
+ if (childrenPromises.length === 0) postUpdate();
2607
+ else {
2608
+ Promise.all(childrenPromises).then(postUpdate).catch(postUpdate);
2609
+ hostRef.$flags$ |= HOST_FLAGS.isWaitingForChildren;
2610
+ childrenPromises.length = 0;
2611
+ }
2612
+ } else postUpdateComponent(hostRef);
2613
+ };
2614
+ let renderingRef = null;
2615
+ /**
2616
+ * Handle making the call to the VDom renderer with the proper context given
2617
+ * various build variables
2618
+ *
2619
+ * @param hostRef an object containing references to the element's host node,
2620
+ * VDom nodes, and other metadata
2621
+ * @param instance a reference to the underlying host element where it will be
2622
+ * rendered
2623
+ * @param elm the Host element for the component
2624
+ * @param isInitialLoad whether or not this function is being called as part of
2625
+ * @returns an empty promise
2626
+ */
2627
+ const callRender = (hostRef, instance, elm, isInitialLoad) => {
2628
+ const allRenderFn = !!BUILD.allRenderFn;
2629
+ const lazyLoad = !!BUILD.lazyLoad;
2630
+ const taskQueue = !!BUILD.taskQueue;
2631
+ const updatable = !!BUILD.updatable;
2632
+ try {
2633
+ renderingRef = instance;
2634
+ /**
2635
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
2636
+ * method, so we can call the method immediately. If not, check before calling it.
2637
+ */
2638
+ instance = allRenderFn ? instance.render() : instance.render && instance.render();
2639
+ if (updatable && taskQueue) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2640
+ if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
2641
+ if (BUILD.hasRenderFn || BUILD.reflect) if (BUILD.vdomRender || BUILD.reflect) if (BUILD.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
2642
+ else renderVdom(hostRef, instance, isInitialLoad);
2643
+ else {
2644
+ const shadowRoot = elm.shadowRoot;
2645
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
2646
+ else elm.textContent = instance;
2647
+ }
2648
+ } catch (e) {
2649
+ consoleError(e, hostRef.$hostElement$);
2650
+ }
2651
+ renderingRef = null;
2652
+ return null;
2653
+ };
2654
+ const getRenderingRef = () => renderingRef;
2655
+ const postUpdateComponent = (hostRef) => {
2656
+ const tagName = hostRef.$cmpMeta$.$tagName$;
2657
+ const elm = hostRef.$hostElement$;
2658
+ const endPostUpdate = createTime("postUpdate", tagName);
2659
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2660
+ const ancestorComponent = hostRef.$ancestorComponent$;
2661
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
2662
+ safeCall(instance, "componentDidRender", void 0, elm);
2663
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
2664
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidRender");
2665
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasLoadedComponent)) {
2666
+ hostRef.$flags$ |= HOST_FLAGS.hasLoadedComponent;
2667
+ if (BUILD.asyncLoading && BUILD.cssAnnotations) addHydratedFlag(elm);
2668
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnDidLoad;
2669
+ safeCall(instance, "componentDidLoad", void 0, elm);
2670
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnDidLoad;
2671
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidLoad");
2672
+ if (BUILD.propChangeCallback) hostRef.$flags$ |= HOST_FLAGS.isWatchReady;
2673
+ endPostUpdate();
2674
+ if (BUILD.asyncLoading) {
2675
+ hostRef.$onReadyResolve$(elm);
2676
+ if (!ancestorComponent) appDidLoad(tagName);
2677
+ }
2678
+ } else {
2679
+ if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
2680
+ safeCall(instance, "componentDidUpdate", void 0, elm);
2681
+ if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
2682
+ if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidUpdate");
2683
+ endPostUpdate();
2684
+ }
2685
+ if (BUILD.method && BUILD.lazyLoad) hostRef.$onInstanceResolve$(elm);
2686
+ if (BUILD.asyncLoading) {
2687
+ if (hostRef.$onRenderResolve$) {
2688
+ hostRef.$onRenderResolve$();
2689
+ hostRef.$onRenderResolve$ = void 0;
2690
+ }
2691
+ if (hostRef.$flags$ & HOST_FLAGS.needsRerender) nextTick(() => scheduleUpdate(hostRef, false));
2692
+ hostRef.$flags$ &= ~(HOST_FLAGS.isWaitingForChildren | HOST_FLAGS.needsRerender);
2693
+ }
2694
+ };
2695
+ const forceUpdate = (ref) => {
2696
+ if (BUILD.updatable && (Build.isBrowser || Build.isTesting)) {
2697
+ const hostRef = getHostRef(ref);
2698
+ const isConnected = hostRef?.$hostElement$?.isConnected;
2699
+ if (isConnected && (hostRef.$flags$ & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered) scheduleUpdate(hostRef, false);
2700
+ return isConnected;
2701
+ }
2702
+ return false;
2703
+ };
2704
+ const appDidLoad = (who) => {
2705
+ if (BUILD.asyncQueue) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
2706
+ nextTick(() => emitEvent(win, "appload", { detail: { namespace: "app" } }));
2707
+ if (BUILD.hydrateClientSide) {
2708
+ if (plt.$orgLocNodes$?.size) plt.$orgLocNodes$.clear();
2709
+ }
2710
+ if (BUILD.profile && performance.measure) performance.measure(`[Stencil] app initial load (by ${who})`, "st:app:start");
2711
+ };
2712
+ /**
2713
+ * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
2714
+ * e.g. custom element node. If a build figures out that e.g. no component
2715
+ * has a `componentDidLoad` method, the instance method gets removed from the
2716
+ * output bundle and this function returns `undefined`.
2717
+ * @param instance any object that may or may not contain methods
2718
+ * @param method method name
2719
+ * @param arg single arbitrary argument
2720
+ * @param elm the element which made the call
2721
+ * @returns result of method call if it exists, otherwise `undefined`
2722
+ */
2723
+ const safeCall = (instance, method, arg, elm) => {
2724
+ if (instance && instance[method]) try {
2725
+ return instance[method](arg);
2726
+ } catch (e) {
2727
+ consoleError(e, elm);
2728
+ }
2729
+ };
2730
+ /**
2731
+ * For debugging purposes as `BUILD.lifecycleDOMEvents` is `false` by default and will
2732
+ * get removed by the compiler. Used for timing events to see how long they take.
2733
+ * @param elm the target of the Event
2734
+ * @param lifecycleName name of the event
2735
+ */
2736
+ const emitLifecycleEvent = (elm, lifecycleName) => {
2737
+ if (BUILD.lifecycleDOMEvents) emitEvent(elm, "stencil_" + lifecycleName, {
2738
+ bubbles: true,
2739
+ composed: true,
2740
+ detail: { namespace: "app" }
2741
+ });
2742
+ };
2743
+ /**
2744
+ * Set the hydrated flag on a DOM element
2745
+ *
2746
+ * @param elm a reference to a DOM element
2747
+ * @returns undefined
2748
+ */
2749
+ const addHydratedFlag = (elm) => BUILD.hydratedClass ? elm.classList.add(BUILD.hydratedSelectorName ?? "hydrated") : BUILD.hydratedAttribute ? elm.setAttribute(BUILD.hydratedSelectorName ?? "hydrated", "") : void 0;
2750
+ const serverSideConnected = (elm) => {
2751
+ const children = elm.children;
2752
+ if (children != null) for (let i = 0, ii = children.length; i < ii; i++) {
2753
+ const childElm = children[i];
2754
+ if (typeof childElm.connectedCallback === "function") childElm.connectedCallback();
2755
+ serverSideConnected(childElm);
2756
+ }
2757
+ };
2758
+ //#endregion
2759
+ //#region src/runtime/signals.ts
2760
+ const STENCIL_SIGNALS_SYMBOL = Symbol.for("stencil.signals");
2761
+ /**
2762
+ * Duck-type check for Signal objects. Cross-bundle-safe (no instanceof).
2763
+ * @param v value to test
2764
+ * @returns whether `v` implements the SignalLike interface
2765
+ */
2766
+ const isSignalLike = (v) => v !== null && typeof v === "object" && typeof v.peek === "function" && typeof v.subscribe === "function";
2767
+ /**
2768
+ * Create Signal.State instances for every @Prop/@State member, copy initial
2769
+ * values from $instanceValues$, and wire up:
2770
+ * - a per-prop scheduling effect → calls scheduleUpdate when value changes
2771
+ * - per-prop watcher effects → call @Watch callbacks with old/new value
2772
+ *
2773
+ * All dispose functions are collected into hostRef.$signalCleanup$() for
2774
+ * teardown on disconnect.
2775
+ * @param elm the host element
2776
+ * @param hostRef the component's host reference
2777
+ * @param cmpMeta the component's runtime metadata
2778
+ */
2779
+ const initializeSignals = (elm, hostRef, cmpMeta) => {
2780
+ if (hostRef.$signalValues$) return;
2781
+ hostRef.$signalValues$ = /* @__PURE__ */ new Map();
2782
+ const disposers = [];
2783
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2784
+ for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
2785
+ if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
2786
+ const sig = signal(hostRef.$instanceValues$.get(memberName));
2787
+ hostRef.$signalValues$.set(memberName, sig);
2788
+ let prevScheduleVal = sig.peek();
2789
+ disposers.push(effect(() => {
2790
+ const newVal = sig.value;
2791
+ if (hostRef.$flags$ & HOST_FLAGS.hasRendered) {
2792
+ if (instance?.componentShouldUpdate) {
2793
+ if (instance.componentShouldUpdate(newVal, prevScheduleVal, memberName) === false && !(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) {
2794
+ prevScheduleVal = newVal;
2795
+ return;
2796
+ }
2797
+ }
2798
+ if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
2799
+ }
2800
+ prevScheduleVal = newVal;
2801
+ }));
2802
+ if (BUILD.propChangeCallback && cmpMeta.$watchers$?.[memberName]) {
2803
+ const watchMethods = cmpMeta.$watchers$[memberName];
2804
+ let prevWatchVal = sig.peek();
2805
+ disposers.push(effect(() => {
2806
+ const newVal = sig.value;
2807
+ const flags = hostRef.$flags$;
2808
+ watchMethods.forEach((watcher) => {
2809
+ try {
2810
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
2811
+ if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
2812
+ const inst = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2813
+ if (inst) inst[watchMethodName](newVal, prevWatchVal, memberName);
2814
+ }
2815
+ } catch (e) {
2816
+ consoleError(e, elm);
2817
+ }
2818
+ });
2819
+ prevWatchVal = newVal;
2820
+ }));
2821
+ }
2822
+ }
2823
+ const effectMethods = instance?.["__stencilEffects"] ?? [];
2824
+ for (const methodName of effectMethods) disposers.push(effect(() => {
2825
+ try {
2826
+ instance[methodName]();
2827
+ } catch (e) {
2828
+ consoleError(e, elm);
2829
+ }
2830
+ }));
2831
+ elm[STENCIL_SIGNALS_SYMBOL] = new Map([...hostRef.$signalValues$].filter(([k]) => (cmpMeta.$members$?.[k]?.[0] ?? 0) & MEMBER_FLAGS.Prop));
2832
+ hostRef.$signalCleanup$ = () => {
2833
+ disposers.forEach((d) => d());
2834
+ elm[STENCIL_SIGNALS_SYMBOL] = void 0;
2835
+ };
2836
+ };
2837
+ /**
2838
+ * Sets up `@Effect()` method subscriptions without full signal-backing.
2839
+ * Called when `vdomSignals` is active but `signalBacking` is not - allows
2840
+ * reactive effects that track external signals with no @Prop/@State overhead.
2841
+ * @param elm the host element
2842
+ * @param hostRef the component's host reference
2843
+ */
2844
+ const initializeEffects = (elm, hostRef) => {
2845
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2846
+ const effectMethods = instance?.["__stencilEffects"] ?? [];
2847
+ if (!effectMethods.length) return;
2848
+ const disposers = [];
2849
+ for (const methodName of effectMethods) disposers.push(effect(() => {
2850
+ try {
2851
+ instance[methodName]();
2852
+ } catch (e) {
2853
+ consoleError(e, elm);
2854
+ }
2855
+ }));
2856
+ hostRef.$signalCleanup$ = () => disposers.forEach((d) => d());
2857
+ };
2858
+ //#endregion
2859
+ //#region src/runtime/vdom/h.ts
2860
+ /**
2861
+ * Production h() function based on Preact by
2862
+ * Jason Miller (@developit)
2863
+ * Licensed under the MIT License
2864
+ * https://github.com/developit/preact/blob/master/LICENSE
2865
+ *
2866
+ * Modified for Stencil's compiler and vdom
2867
+ */
2868
+ const h = (nodeName, vnodeData, ...children) => {
2869
+ if (typeof nodeName === "string") nodeName = transformTag(nodeName);
2870
+ let child = null;
2871
+ let key = null;
2872
+ let slotName = null;
2873
+ let simple = false;
2874
+ let lastSimple = false;
2875
+ const vNodeChildren = [];
2876
+ const walk = (c) => {
2877
+ for (let i = 0; i < c.length; i++) {
2878
+ child = c[i];
2879
+ if (Array.isArray(child)) walk(child);
2880
+ else if (child != null && typeof child !== "boolean") if (BUILD.vdomSignals && isSignalLike(child)) {
2881
+ const sigVNode = newVNode(null, String(child.peek()));
2882
+ sigVNode.$signal$ = child;
2883
+ vNodeChildren.push(sigVNode);
2884
+ lastSimple = false;
2885
+ } else {
2886
+ if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
2887
+ else if (BUILD.isDev && typeof nodeName !== "function" && child.$flags$ === void 0) consoleDevError(`vNode passed as children has unexpected type.
2888
+ Make sure it's using the correct h() function.
2889
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
2890
+ if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
2891
+ else vNodeChildren.push(simple ? newVNode(null, child) : child);
2892
+ lastSimple = simple;
2893
+ }
2894
+ }
2895
+ };
2896
+ walk(children);
2897
+ if (vnodeData) {
2898
+ if (BUILD.isDev && nodeName === "input") validateInputProperties(vnodeData);
2899
+ if (BUILD.vdomKey && vnodeData.key) key = vnodeData.key;
2900
+ if (BUILD.slotRelocation && vnodeData.name) slotName = vnodeData.name;
2901
+ if (BUILD.vdomClass) {
2902
+ const classData = vnodeData.class;
2903
+ if (classData && !(BUILD.vdomSignals && isSignalLike(classData))) vnodeData.class = typeof classData !== "object" ? classData : Object.keys(classData).filter((k) => classData[k]).join(" ");
2904
+ }
2905
+ }
2906
+ if (BUILD.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be the single root component. Make sure:
2907
+ - You are NOT using hostData() and <Host> in the same component.
2908
+ - <Host> is used once, and it's the single root component of the render() function.`);
2909
+ if (BUILD.vdomFunctional && typeof nodeName === "function") return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
2910
+ const vnode = newVNode(nodeName, null);
2911
+ vnode.$attrs$ = vnodeData;
2912
+ if (vNodeChildren.length > 0) vnode.$children$ = vNodeChildren;
2913
+ if (BUILD.vdomKey) vnode.$key$ = key;
2914
+ if (BUILD.slotRelocation) vnode.$name$ = slotName;
2915
+ return vnode;
2916
+ };
2917
+ /**
2918
+ * A utility function for creating a virtual DOM node from a tag and some
2919
+ * possible text content.
2920
+ *
2921
+ * @param tag the tag for this element
2922
+ * @param text possible text content for the node
2923
+ * @returns a newly-minted virtual DOM node
2924
+ */
2925
+ const newVNode = (tag, text) => {
2926
+ const vnode = {
2927
+ $flags$: 0,
2928
+ $tag$: tag,
2929
+ $text$: text ?? null,
2930
+ $elm$: null,
2931
+ $children$: null
2932
+ };
2933
+ if (BUILD.vdomAttribute) vnode.$attrs$ = null;
2934
+ if (BUILD.vdomKey) vnode.$key$ = null;
2935
+ if (BUILD.slotRelocation) vnode.$name$ = null;
2936
+ return vnode;
2937
+ };
2938
+ const Host = {};
2939
+ /**
2940
+ * Check whether a given node is a Host node or not
2941
+ *
2942
+ * @param node the virtual DOM node to check
2943
+ * @returns whether it's a Host node or not
2944
+ */
2945
+ const isHost = (node) => node && node.$tag$ === Host;
2946
+ /**
2947
+ * Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
2948
+ *
2949
+ * Note that these functions convert from {@link d.VNode} to
2950
+ * {@link d.ChildNode} to give functional component developers a friendly
2951
+ * interface.
2952
+ */
2953
+ const vdomFnUtils = {
2954
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
2955
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate)
2956
+ };
2957
+ /**
2958
+ * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
2959
+ * friendlier public interface (hence, 'convertToPublic').
2960
+ *
2961
+ * @param node the virtual DOM node to convert
2962
+ * @returns a converted child node
2963
+ */
2964
+ const convertToPublic = (node) => ({
2965
+ vattrs: node.$attrs$,
2966
+ vchildren: node.$children$,
2967
+ vkey: node.$key$,
2968
+ vname: node.$name$,
2969
+ vtag: node.$tag$,
2970
+ vtext: node.$text$
2971
+ });
2972
+ /**
2973
+ * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
2974
+ * order to use the resulting object in the virtual DOM. The initial object was
2975
+ * likely created as part of presenting a public API, so converting it back
2976
+ * involved making it 'private' again (hence, `convertToPrivate`).
2977
+ *
2978
+ * @param node the child node to convert
2979
+ * @returns a converted virtual DOM node
2980
+ */
2981
+ const convertToPrivate = (node) => {
2982
+ if (typeof node.vtag === "function") {
2983
+ const vnodeData = { ...node.vattrs };
2984
+ if (node.vkey) vnodeData.key = node.vkey;
2985
+ if (node.vname) vnodeData.name = node.vname;
2986
+ return h(node.vtag, vnodeData, ...node.vchildren || []);
2987
+ }
2988
+ const vnode = newVNode(node.vtag, node.vtext);
2989
+ vnode.$attrs$ = node.vattrs;
2990
+ vnode.$children$ = node.vchildren;
2991
+ vnode.$key$ = node.vkey;
2992
+ vnode.$name$ = node.vname;
2993
+ return vnode;
2994
+ };
2995
+ /**
2996
+ * Validates the ordering of attributes on an input element
2997
+ *
2998
+ * @param inputElm the element to validate
2999
+ */
3000
+ const validateInputProperties = (inputElm) => {
3001
+ const props = Object.keys(inputElm);
3002
+ const value = props.indexOf("value");
3003
+ if (value === -1) return;
3004
+ const typeIndex = props.indexOf("type");
3005
+ const minIndex = props.indexOf("min");
3006
+ const maxIndex = props.indexOf("max");
3007
+ const stepIndex = props.indexOf("step");
3008
+ if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
3009
+ };
3010
+ //#endregion
3011
+ //#region src/runtime/client-hydrate.ts
3012
+ /**
3013
+ * Takes an SSR rendered document, as annotated by 'vdom-annotations.ts' and:
3014
+ *
3015
+ * 1) Recreate an accurate VDOM which is fed to 'vdom-render.ts'. A failure to do so can cause hydration errors; extra renders, duplicated nodes
3016
+ * 2) Add shadowDOM trees to their respective #document-fragment
3017
+ * 3) Move forwarded, slotted nodes out of shadowDOMs
3018
+ * 4) Add meta nodes to non-shadow DOMs and their 'slotted' nodes
3019
+ *
3020
+ * @param hostElm The element to hydrate.
3021
+ * @param tagName The element's tag name.
3022
+ * @param hostId The host ID assigned to the element by the server. e.g. `s-id="1"`
3023
+ * @param hostRef The host reference for the element.
3024
+ */
3025
+ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3026
+ const endHydrate = createTime("hydrateClient", tagName);
3027
+ const shadowRoot = getShadowRoot(hostElm);
3028
+ const childRenderNodes = [];
3029
+ const slotNodes = [];
3030
+ const slottedNodes = [];
3031
+ const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
3032
+ const vnode = newVNode(tagName, null);
3033
+ vnode.$elm$ = hostElm;
3034
+ let scopeId;
3035
+ if (BUILD.scoped) {
3036
+ const cmpMeta = hostRef.$cmpMeta$;
3037
+ if (cmpMeta && cmpMeta.$flags$ & CMP_FLAGS.needsScopedEncapsulation && hostElm["s-sc"]) {
3038
+ scopeId = hostElm["s-sc"];
3039
+ hostElm.classList.add(scopeId + "-h");
3040
+ } else if (hostElm["s-sc"]) delete hostElm["s-sc"];
3041
+ }
3042
+ if (win.document && (!plt.$orgLocNodes$ || !plt.$orgLocNodes$.size)) initializeDocumentHydrate(win.document.body, plt.$orgLocNodes$ = /* @__PURE__ */ new Map());
3043
+ hostElm[HYDRATE_ID] = hostId;
3044
+ hostElm.removeAttribute(HYDRATE_ID);
3045
+ hostRef.$vnode$ = clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId, slottedNodes);
3046
+ let crIndex = 0;
3047
+ const crLength = childRenderNodes.length;
3048
+ let childRenderNode;
3049
+ for (; crIndex < crLength; crIndex++) {
3050
+ childRenderNode = childRenderNodes[crIndex];
3051
+ const orgLocationId = childRenderNode.$hostId$ + "." + childRenderNode.$nodeId$;
3052
+ const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
3053
+ const node = childRenderNode.$elm$;
3054
+ if (!shadowRoot) {
3055
+ node["s-hn"] = transformTag(tagName).toUpperCase();
3056
+ if (childRenderNode.$tag$ === "slot") node["s-cr"] = hostElm["s-cr"];
3057
+ } else if (childRenderNode.$tag$?.toString().includes("-") && childRenderNode.$tag$ !== "slot-fb" && !childRenderNode.$elm$.shadowRoot) {
3058
+ const cmpMeta = getHostRef(childRenderNode.$elm$);
3059
+ if (cmpMeta) {
3060
+ const childScopeId = getScopeId(cmpMeta.$cmpMeta$, BUILD.mode ? childRenderNode.$elm$.getAttribute("s-mode") : void 0);
3061
+ const styleSheet = win.document.querySelector(`style[sty-id="${childScopeId}"]`);
3062
+ if (styleSheet) shadowRootNodes.unshift(styleSheet.cloneNode(true));
3063
+ }
3064
+ }
3065
+ if (childRenderNode.$tag$ === "slot") {
3066
+ childRenderNode.$name$ = childRenderNode.$elm$["s-sn"] || childRenderNode.$elm$["name"] || null;
3067
+ if (childRenderNode.$children$) {
3068
+ childRenderNode.$flags$ |= VNODE_FLAGS.isSlotFallback;
3069
+ if (!childRenderNode.$elm$.childNodes.length) childRenderNode.$children$.forEach((c) => {
3070
+ childRenderNode.$elm$.appendChild(c.$elm$);
3071
+ });
3072
+ } else childRenderNode.$flags$ |= VNODE_FLAGS.isSlotReference;
3073
+ }
3074
+ if (orgLocationNode && orgLocationNode.isConnected) {
3075
+ const orgParentNode = orgLocationNode.parentNode;
3076
+ if (orgLocationNode.parentElement.shadowRoot && orgLocationNode["s-en"] === "") orgParentNode.insertBefore(node, orgLocationNode.nextSibling);
3077
+ orgParentNode.removeChild(orgLocationNode);
3078
+ if (!shadowRoot) node["s-oo"] = parseInt(childRenderNode.$nodeId$);
3079
+ }
3080
+ if (orgLocationNode && !orgLocationNode["s-id"]) plt.$orgLocNodes$.delete(orgLocationId);
3081
+ }
3082
+ const hosts = [];
3083
+ const snLen = slottedNodes.length;
3084
+ let snIndex = 0;
3085
+ let slotGroup;
3086
+ let snGroupIdx;
3087
+ let snGroupLen;
3088
+ let slottedItem;
3089
+ let currentPos = 0;
3090
+ for (; snIndex < snLen; snIndex++) {
3091
+ slotGroup = slottedNodes[snIndex];
3092
+ if (!slotGroup || !slotGroup.length) continue;
3093
+ snGroupLen = slotGroup.length;
3094
+ snGroupIdx = 0;
3095
+ for (; snGroupIdx < snGroupLen; snGroupIdx++) {
3096
+ slottedItem = slotGroup[snGroupIdx];
3097
+ const hid = slottedItem.hostId;
3098
+ if (!hosts[hid]) hosts[hid] = plt.$orgLocNodes$.get(slottedItem.hostId);
3099
+ if (!hosts[hid]) continue;
3100
+ const hostEle = hosts[hid];
3101
+ const siNode = slottedItem.node;
3102
+ const siSlot = slottedItem.slot;
3103
+ if (hostEle.shadowRoot && siNode.parentElement !== hostEle) hostEle.insertBefore(siNode, slotGroup[snGroupIdx - 1]?.node?.nextSibling);
3104
+ if (!hostEle.shadowRoot || !shadowRoot) {
3105
+ if (!siSlot["s-cr"]) {
3106
+ siSlot["s-cr"] = hostEle["s-cr"];
3107
+ if (!siSlot["s-cr"] && hostEle.shadowRoot) siSlot["s-cr"] = hostEle;
3108
+ else siSlot["s-cr"] = (hostEle.__childNodes || hostEle.childNodes)[0];
3109
+ }
3110
+ addSlotRelocateNode(siNode, siSlot, false, siNode["s-oo"] || currentPos);
3111
+ if (siNode.parentElement?.shadowRoot && siNode["getAttribute"] && siNode.getAttribute("slot")) siNode.removeAttribute("slot");
3112
+ if (BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll) patchSlottedNode(siNode);
3113
+ }
3114
+ currentPos = (siNode["s-oo"] || currentPos) + 1;
3115
+ }
3116
+ }
3117
+ if (BUILD.scoped && scopeId && slotNodes.length) slotNodes.forEach((slot) => {
3118
+ slot.$elm$.parentElement.classList.add(scopeId + "-s");
3119
+ });
3120
+ if (BUILD.shadowDom && shadowRoot && !shadowRoot.childNodes.length) {
3121
+ let rnIdex = 0;
3122
+ const rnLen = shadowRootNodes.length;
3123
+ if (rnLen) {
3124
+ for (; rnIdex < rnLen; rnIdex++) {
3125
+ const node = shadowRootNodes[rnIdex];
3126
+ /**
3127
+ * in apps with a lot of components the `shadowRootNodes` array can be modified while iterating over it
3128
+ * so we need to check if the node is still in the array before appending it to avoid any errors like:
3129
+ *
3130
+ * TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
3131
+ */
3132
+ if (node) shadowRoot.appendChild(node);
3133
+ }
3134
+ Array.from(hostElm.childNodes).forEach((node) => {
3135
+ if (typeof node["s-en"] !== "string" && typeof node["s-sn"] !== "string") {
3136
+ if (node.nodeType === NODE_TYPE.ElementNode && node.slot && node.hidden) node.removeAttribute("hidden");
3137
+ else if (node.nodeType === NODE_TYPE.CommentNode && !node.nodeValue) node.parentNode.removeChild(node);
3138
+ }
3139
+ });
3140
+ }
3141
+ }
3142
+ hostRef.$hostElement$ = hostElm;
3143
+ endHydrate();
3144
+ };
3145
+ /**
3146
+ * Recursively constructs the virtual node tree for a host element and its children.
3147
+ * The tree is constructed by parsing the annotations set on the nodes by the server (`vdom-annotations.ts`).
3148
+ *
3149
+ * In addition to constructing the VNode tree, we also track information about the node's descendants:
3150
+ * - which are slots
3151
+ * - which should exist in the shadow root
3152
+ * - which are nodes that should be rendered as children of the parent node
3153
+ *
3154
+ * @param parentVNode The vNode representing the parent node.
3155
+ * @param childRenderNodes An array of all child nodes in the parent's node tree.
3156
+ * @param slotNodes An array of all slot nodes in the parent's node tree.
3157
+ * @param shadowRootNodes An array of nodes that should be rendered in the shadowDOM of the parent.
3158
+ * @param hostElm The parent element.
3159
+ * @param node The node to construct the vNode tree for.
3160
+ * @param hostId The host ID assigned to the element by the server.
3161
+ * @param slottedNodes - nodes that have been slotted
3162
+ * @returns - the constructed VNode
3163
+ */
3164
+ const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId, slottedNodes = []) => {
3165
+ let childNodeType;
3166
+ let childIdSplt;
3167
+ let childVNode;
3168
+ let i;
3169
+ const scopeId = hostElm["s-sc"];
3170
+ if (node.nodeType === NODE_TYPE.ElementNode) {
3171
+ childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
3172
+ if (childNodeType) {
3173
+ childIdSplt = childNodeType.split(".");
3174
+ if (childIdSplt[0] === hostId || childIdSplt[0] === "0") {
3175
+ childVNode = createSimpleVNode({
3176
+ $hostId$: childIdSplt[0],
3177
+ $nodeId$: childIdSplt[1],
3178
+ $depth$: childIdSplt[2],
3179
+ $index$: childIdSplt[3],
3180
+ $tag$: node.tagName.toLowerCase(),
3181
+ $elm$: node,
3182
+ $attrs$: { class: node.className || "" }
3183
+ });
3184
+ childRenderNodes.push(childVNode);
3185
+ node.removeAttribute(HYDRATE_CHILD_ID);
3186
+ if (!parentVNode.$children$) parentVNode.$children$ = [];
3187
+ if (BUILD.scoped && scopeId && childIdSplt[0] === hostId) {
3188
+ node["s-si"] = scopeId;
3189
+ childVNode.$attrs$.class += " " + scopeId;
3190
+ }
3191
+ const slotName = childVNode.$elm$.getAttribute("s-sn");
3192
+ if (typeof slotName === "string") {
3193
+ if (childVNode.$tag$ === "slot-fb") {
3194
+ addSlot(slotName, childIdSplt[2], childVNode, node, parentVNode, childRenderNodes, slotNodes, shadowRootNodes, slottedNodes);
3195
+ if (BUILD.scoped && scopeId) node.classList.add(scopeId);
3196
+ }
3197
+ childVNode.$elm$["s-sn"] = slotName;
3198
+ childVNode.$elm$.removeAttribute("s-sn");
3199
+ }
3200
+ if (childVNode.$index$ !== void 0) parentVNode.$children$[childVNode.$index$] = childVNode;
3201
+ parentVNode = childVNode;
3202
+ if (shadowRootNodes && childVNode.$depth$ === "0") shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
3203
+ }
3204
+ }
3205
+ if (node.shadowRoot) for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId, slottedNodes);
3206
+ const nonShadowNodes = node.__childNodes || node.childNodes;
3207
+ for (i = nonShadowNodes.length - 1; i >= 0; i--) clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, nonShadowNodes[i], hostId, slottedNodes);
3208
+ } else if (node.nodeType === NODE_TYPE.CommentNode) {
3209
+ childIdSplt = node.nodeValue.split(".");
3210
+ if (childIdSplt[1] === hostId || childIdSplt[1] === "0") {
3211
+ childNodeType = childIdSplt[0];
3212
+ childVNode = createSimpleVNode({
3213
+ $hostId$: childIdSplt[1],
3214
+ $nodeId$: childIdSplt[2],
3215
+ $depth$: childIdSplt[3],
3216
+ $index$: childIdSplt[4] || "0",
3217
+ $elm$: node
3218
+ });
3219
+ if (childNodeType === "t") {
3220
+ childVNode.$elm$ = findCorrespondingNode(node, NODE_TYPE.TextNode);
3221
+ if (childVNode.$elm$ && childVNode.$elm$.nodeType === NODE_TYPE.TextNode) {
3222
+ childVNode.$text$ = childVNode.$elm$.textContent;
3223
+ childRenderNodes.push(childVNode);
3224
+ node.remove();
3225
+ if (hostId === childVNode.$hostId$) {
3226
+ if (!parentVNode.$children$) parentVNode.$children$ = [];
3227
+ parentVNode.$children$[childVNode.$index$] = childVNode;
3228
+ }
3229
+ if (shadowRootNodes && childVNode.$depth$ === "0") shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
3230
+ }
3231
+ } else if (childNodeType === "c") {
3232
+ childVNode.$elm$ = findCorrespondingNode(node, NODE_TYPE.CommentNode);
3233
+ if (childVNode.$elm$ && childVNode.$elm$.nodeType === NODE_TYPE.CommentNode) {
3234
+ childRenderNodes.push(childVNode);
3235
+ node.remove();
3236
+ }
3237
+ } else if (childVNode.$hostId$ === hostId) {
3238
+ if (childNodeType === "s") addSlot(node["s-sn"] = childIdSplt[5] || "", childIdSplt[2], childVNode, node, parentVNode, childRenderNodes, slotNodes, shadowRootNodes, slottedNodes);
3239
+ else if (childNodeType === "r") {
3240
+ if (BUILD.shadowDom && shadowRootNodes) node.remove();
3241
+ else if (BUILD.slotRelocation) {
3242
+ hostElm["s-cr"] = node;
3243
+ node["s-cn"] = true;
3244
+ }
3245
+ }
3246
+ }
3247
+ }
3248
+ } else if (parentVNode && parentVNode.$tag$ === "style") {
3249
+ const vnode = newVNode(null, node.textContent);
3250
+ vnode.$elm$ = node;
3251
+ vnode.$index$ = "0";
3252
+ parentVNode.$children$ = [vnode];
3253
+ }
3254
+ return parentVNode;
3255
+ };
3256
+ /**
3257
+ * Recursively locate any comments representing an 'original location' for a node; in a node's children or shadowRoot children.
3258
+ * Creates a map of component IDs and 'original location' ID's which are derived from comment nodes placed by 'vdom-annotations.ts'.
3259
+ * Each 'original location' relates to a lightDOM node that was moved deeper into the SSR markup. e.g. `<!--o.1-->` maps to `<div c-id="0.1">`
3260
+ *
3261
+ * @param node The node to search.
3262
+ * @param orgLocNodes A map of the original location annotations and the current node being searched.
3263
+ */
3264
+ const initializeDocumentHydrate = (node, orgLocNodes) => {
3265
+ if (node.nodeType === NODE_TYPE.ElementNode) {
3266
+ const componentId = node["s-id"] || node.getAttribute("s-id");
3267
+ if (componentId) orgLocNodes.set(componentId, node);
3268
+ let i = 0;
3269
+ if (node.shadowRoot) for (; i < node.shadowRoot.childNodes.length; i++) initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
3270
+ const nonShadowNodes = node.__childNodes || node.childNodes;
3271
+ for (i = 0; i < nonShadowNodes.length; i++) initializeDocumentHydrate(nonShadowNodes[i], orgLocNodes);
3272
+ } else if (node.nodeType === NODE_TYPE.CommentNode) {
3273
+ const childIdSplt = node.nodeValue.split(".");
3274
+ if (childIdSplt[0] === "o") {
3275
+ orgLocNodes.set(childIdSplt[1] + "." + childIdSplt[2], node);
3276
+ node.nodeValue = "";
3277
+ node["s-en"] = childIdSplt[3];
3278
+ }
3279
+ }
3280
+ };
3281
+ /**
3282
+ * Creates a VNode to add to a hydrated component VDOM
3283
+ *
3284
+ * @param vnode - a vnode partial which will be augmented
3285
+ * @returns an complete vnode
3286
+ */
3287
+ const createSimpleVNode = (vnode) => ({
3288
+ $flags$: 0,
3289
+ $index$: "0",
3290
+ ...vnode
3291
+ });
3292
+ function addSlot(slotName, slotId, childVNode, node, parentVNode, childRenderNodes, slotNodes, shadowRootNodes, slottedNodes) {
3293
+ node["s-sr"] = true;
3294
+ childVNode.$name$ = slotName || null;
3295
+ childVNode.$tag$ = "slot";
3296
+ const parentNodeId = parentVNode?.$elm$ ? parentVNode.$elm$["s-id"] || parentVNode.$elm$.getAttribute("s-id") : "";
3297
+ if (BUILD.shadowDom && shadowRootNodes && win.document) {
3298
+ const slot = childVNode.$elm$ = win.document.createElement(childVNode.$tag$);
3299
+ if (childVNode.$name$) childVNode.$elm$.setAttribute("name", slotName);
3300
+ if (parentVNode.$elm$.shadowRoot && parentNodeId && parentNodeId !== childVNode.$hostId$) internalCall(parentVNode.$elm$, "insertBefore")(slot, internalCall(parentVNode.$elm$, "children")[0]);
3301
+ else internalCall(internalCall(node, "parentNode"), "insertBefore")(slot, node);
3302
+ addSlottedNodes(slottedNodes, slotId, slotName, node, childVNode.$hostId$);
3303
+ node.remove();
3304
+ if (childVNode.$depth$ === "0") shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
3305
+ } else {
3306
+ const slot = childVNode.$elm$;
3307
+ const shouldMove = parentNodeId && parentNodeId !== childVNode.$hostId$ && parentVNode.$elm$.shadowRoot;
3308
+ addSlottedNodes(slottedNodes, slotId, slotName, node, shouldMove ? parentNodeId : childVNode.$hostId$);
3309
+ patchSlotNode(node);
3310
+ if (shouldMove) parentVNode.$elm$.insertBefore(slot, parentVNode.$elm$.children[0]);
3311
+ }
3312
+ childRenderNodes.push(childVNode);
3313
+ slotNodes.push(childVNode);
3314
+ if (!parentVNode.$children$) parentVNode.$children$ = [];
3315
+ parentVNode.$children$[childVNode.$index$] = childVNode;
3316
+ }
3317
+ /**
3318
+ * Adds groups of slotted nodes (grouped by slot ID) to this host element's 'master' array.
3319
+ * We'll use this after the host element's VDOM is completely constructed to finally position and add meta required by non-shadow slotted nodes
3320
+ *
3321
+ * @param slottedNodes - the main host element 'master' array to add to
3322
+ * @param slotNodeId - the slot node unique ID
3323
+ * @param slotName - the slot node name (can be '')
3324
+ * @param slotNode - the slot node
3325
+ * @param hostId - the host element id where this node should be slotted
3326
+ */
3327
+ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) => {
3328
+ let slottedNode = slotNode.nextSibling;
3329
+ const group = slottedNodes[slotNodeId] ||= [];
3330
+ if (!slottedNode || slottedNode.nodeValue?.startsWith("s.")) return;
3331
+ do {
3332
+ const sa = slottedNode["getAttribute"] && slottedNode.getAttribute("slot");
3333
+ if ((sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3334
+ slottedNode["s-sn"] = slotName;
3335
+ group.push({
3336
+ slot: slotNode,
3337
+ node: slottedNode,
3338
+ hostId
3339
+ });
3340
+ }
3341
+ slottedNode = slottedNode.nextSibling;
3342
+ } while (slottedNode && !slottedNode.nodeValue?.startsWith("s."));
3343
+ };
3344
+ /**
3345
+ * Steps through the node's siblings to find the next node of a specific type, with a value.
3346
+ * e.g. when we find a position comment `<!--t.1-->`, we need to find the next text node with a value.
3347
+ * (it's a guard against whitespace which is never accounted for in the SSR output)
3348
+ * @param node - the starting node
3349
+ * @param type - the type of node to find
3350
+ * @returns the first corresponding node of the type
3351
+ */
3352
+ const findCorrespondingNode = (node, type) => {
3353
+ let sibling = node;
3354
+ do
3355
+ sibling = sibling.nextSibling;
3356
+ while (sibling && (sibling.nodeType !== type || !sibling.nodeValue));
3357
+ return sibling;
3358
+ };
3359
+ //#endregion
3360
+ //#region src/utils/regular-expression.ts
3361
+ /**
3362
+ * Utility function that will escape all regular expression special characters in a string.
3363
+ *
3364
+ * @param text The string potentially containing special characters.
3365
+ * @returns The string with all special characters escaped.
3366
+ */
3367
+ const escapeRegExpSpecialCharacters = (text) => {
3368
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3369
+ };
3370
+ //#endregion
3371
+ //#region src/utils/shadow-css.ts
3372
+ /**
3373
+ * @license
3374
+ * Copyright Google Inc. All Rights Reserved.
3375
+ *
3376
+ * Use of this source code is governed by an MIT-style license that can be
3377
+ * found in the LICENSE file at https://angular.io/license
3378
+ *
3379
+ * This file is a port of shadowCSS from `webcomponents.js` to TypeScript.
3380
+ * https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js
3381
+ * https://github.com/angular/angular/blob/master/packages/compiler/src/shadow_css.ts
3382
+ */
3383
+ const safeSelector = (selector) => {
3384
+ const placeholders = [];
3385
+ let index = 0;
3386
+ selector = selector.replace(/(\[\s*part~=\s*("[^"]*"|'[^']*')\s*\])/g, (_, keep) => {
3387
+ const replaceBy = `__part-${index}__`;
3388
+ placeholders.push(keep);
3389
+ index++;
3390
+ return replaceBy;
3391
+ });
3392
+ selector = selector.replace(/(\[[^\]]*\])/g, (_, keep) => {
3393
+ const replaceBy = `__ph-${index}__`;
3394
+ placeholders.push(keep);
3395
+ index++;
3396
+ return replaceBy;
3397
+ });
3398
+ return {
3399
+ content: selector.replace(/(:nth-[-\w]+)(\([^)]+\))/g, (_, pseudo, exp) => {
3400
+ const replaceBy = `__ph-${index}__`;
3401
+ placeholders.push(exp);
3402
+ index++;
3403
+ return pseudo + replaceBy;
3404
+ }),
3405
+ placeholders
3406
+ };
3407
+ };
3408
+ const restoreSafeSelector = (placeholders, content) => {
3409
+ content = content.replace(/__part-(\d+)__/g, (_, index) => placeholders[+index]);
3410
+ return content.replace(/__ph-(\d+)__/g, (_, index) => placeholders[+index]);
3411
+ };
3412
+ const _polyfillHost = "-shadowcsshost";
3413
+ const _polyfillSlotted = "-shadowcssslotted";
3414
+ const _polyfillHostContext = "-shadowcsscontext";
3415
+ let _cssColonHostRe;
3416
+ let _cssColonHostContextRe;
3417
+ let _cssColonSlottedRe;
3418
+ const getCssColonHostRe = () => _cssColonHostRe ??= /* @__PURE__ */ new RegExp("(-shadowcsshost)(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)", "gim");
3419
+ const getCssColonHostContextRe = () => _cssColonHostContextRe ??= /* @__PURE__ */ new RegExp("(-shadowcsscontext)(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)", "gim");
3420
+ const getCssColonSlottedRe = () => _cssColonSlottedRe ??= /* @__PURE__ */ new RegExp("(-shadowcssslotted)(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)", "gim");
3421
+ const _polyfillHostNoCombinator = "-shadowcsshost-no-combinator";
3422
+ const _polyfillHostNoCombinatorRe = /-shadowcsshost-no-combinator([^\s]*)/;
3423
+ const _shadowDOMSelectorsRe = [/::shadow/g, /::content/g];
3424
+ const _safePartRe = /__part-(\d+)__/g;
3425
+ const _polyfillHostRe = /-shadowcsshost/gim;
3426
+ /**
3427
+ * Little helper for generating a regex that will match a specified
3428
+ * CSS selector when that selector is _not_ a part of a `@supports` rule.
3429
+ *
3430
+ * The pattern will match the provided `selector` (i.e. ':host', ':host-context', etc.)
3431
+ * when that selector is not a part of a `@supports` selector rule _or_ if the selector
3432
+ * is a part of the rule's declaration.
3433
+ *
3434
+ * For instance, if we create the regex with the selector ':host-context':
3435
+ * - '@supports selector(:host-context())' will return no matches (starts with '@supports')
3436
+ * - '@supports selector(:host-context()) { :host-context() { ... }}' will match the second ':host-context' (part of declaration)
3437
+ * - ':host-context() { ... }' will match ':host-context' (selector is not a '@supports' rule)
3438
+ * - ':host() { ... }' will return no matches (selector doesn't match selector used to create regex)
3439
+ *
3440
+ * @param selector The CSS selector we want to match for replacement
3441
+ * @returns A look-behind regex containing the selector
3442
+ */
3443
+ const createSupportsRuleRe = (selector) => {
3444
+ const escapedSelector = escapeRegExpSpecialCharacters(selector);
3445
+ return new RegExp(`(^|[^@]|@(?!supports\\s+selector\\s*\\([^{]*?${escapedSelector}))(${escapedSelector}\\b)`, "g");
3446
+ };
3447
+ const _commentRe = /\/\*\s*[\s\S]*?\*\//g;
3448
+ const stripComments = (input) => {
3449
+ return input.replace(_commentRe, "");
3450
+ };
3451
+ const _commentWithHashRe = /\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g;
3452
+ const extractCommentsWithHash = (input) => {
3453
+ return input.match(_commentWithHashRe) || [];
3454
+ };
3455
+ const _ruleRe = /(\s*)([^;{}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g;
3456
+ const _curlyRe = /([{}])/g;
3457
+ const _selectorPartsRe = /(^.*?[^\\])??((:+)(.*)|$)/;
3458
+ const OPEN_CURLY = "{";
3459
+ const CLOSE_CURLY = "}";
3460
+ const BLOCK_PLACEHOLDER = "%BLOCK%";
3461
+ const processRules = (input, ruleCallback) => {
3462
+ const inputWithEscapedBlocks = escapeBlocks(input);
3463
+ let nextBlockIndex = 0;
3464
+ return inputWithEscapedBlocks.escapedString.replace(_ruleRe, (...m) => {
3465
+ const selector = m[2];
3466
+ let content = "";
3467
+ let suffix = m[4];
3468
+ let contentPrefix = "";
3469
+ if (suffix && suffix.startsWith("{%BLOCK%")) {
3470
+ content = inputWithEscapedBlocks.blocks[nextBlockIndex++];
3471
+ suffix = suffix.substring(8);
3472
+ contentPrefix = "{";
3473
+ }
3474
+ const rule = ruleCallback({
3475
+ selector,
3476
+ content
3477
+ });
3478
+ return `${m[1]}${rule.selector}${m[3]}${contentPrefix}${rule.content}${suffix}`;
3479
+ });
3480
+ };
3481
+ const escapeBlocks = (input) => {
3482
+ const inputParts = input.split(_curlyRe);
3483
+ const resultParts = [];
3484
+ const escapedBlocks = [];
3485
+ let bracketCount = 0;
3486
+ let currentBlockParts = [];
3487
+ for (let partIndex = 0; partIndex < inputParts.length; partIndex++) {
3488
+ const part = inputParts[partIndex];
3489
+ if (part === CLOSE_CURLY) bracketCount--;
3490
+ if (bracketCount > 0) currentBlockParts.push(part);
3491
+ else {
3492
+ if (currentBlockParts.length > 0) {
3493
+ escapedBlocks.push(currentBlockParts.join(""));
3494
+ resultParts.push(BLOCK_PLACEHOLDER);
3495
+ currentBlockParts = [];
3496
+ }
3497
+ resultParts.push(part);
3498
+ }
3499
+ if (part === OPEN_CURLY) bracketCount++;
3500
+ }
3501
+ if (currentBlockParts.length > 0) {
3502
+ escapedBlocks.push(currentBlockParts.join(""));
3503
+ resultParts.push(BLOCK_PLACEHOLDER);
3504
+ }
3505
+ return {
3506
+ escapedString: resultParts.join(""),
3507
+ blocks: escapedBlocks
3508
+ };
3509
+ };
3510
+ /**
3511
+ * Replaces certain strings within the CSS with placeholders
3512
+ * that will later be replaced with class selectors appropriate
3513
+ * for the level of encapsulation (shadow or scoped).
3514
+ *
3515
+ * When performing these replacements, we want to ignore selectors that are a
3516
+ * part of an `@supports` rule. Replacing these selectors will result in invalid
3517
+ * CSS that gets passed to autoprefixer/postcss once the placeholders are replaced.
3518
+ * For example, a rule like:
3519
+ *
3520
+ * ```css
3521
+ * @supports selector(:host()) {
3522
+ * :host {
3523
+ * color: red;
3524
+ * }
3525
+ * }
3526
+ * ```
3527
+ *
3528
+ * Should be converted to:
3529
+ *
3530
+ * ```css
3531
+ * @supports selector(:host()) {
3532
+ * -shadowcsshost {
3533
+ * color: red;
3534
+ * }
3535
+ * }
3536
+ * ```
3537
+ *
3538
+ * The order the regex replacements happen in matters since we match
3539
+ * against a whole selector word so we need to match all of `:host-context`
3540
+ * before we try to replace `:host`. Otherwise the pattern for `:host` would match
3541
+ * `:host-context` resulting in something like `:-shadowcsshost-context`.
3542
+ *
3543
+ * @param cssText A CSS string for a component
3544
+ * @returns The modified CSS string
3545
+ */
3546
+ const insertPolyfillHostInCssText = (cssText) => {
3547
+ const supportsBlocks = [];
3548
+ cssText = cssText.replace(/@supports\s+selector\s*\(\s*([^)]*)\s*\)/g, (_, selectorContent) => {
3549
+ const placeholder = `__supports_${supportsBlocks.length}__`;
3550
+ supportsBlocks.push(selectorContent);
3551
+ return `@supports selector(${placeholder})`;
3552
+ });
3553
+ const _colonSlottedRe = createSupportsRuleRe("::slotted");
3554
+ const _colonHostRe = createSupportsRuleRe(":host");
3555
+ const _colonHostContextRe = createSupportsRuleRe(":host-context");
3556
+ cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
3557
+ supportsBlocks.forEach((originalSelector, index) => {
3558
+ cssText = cssText.replace(`__supports_${index}__`, originalSelector);
3559
+ });
3560
+ return cssText;
3561
+ };
3562
+ const convertColonRule = (cssText, regExp, partReplacer) => {
3563
+ return cssText.replace(regExp, (...m) => {
3564
+ if (m[2]) {
3565
+ const parts = m[2].split(",");
3566
+ const r = [];
3567
+ for (let i = 0; i < parts.length; i++) {
3568
+ const p = parts[i].trim();
3569
+ if (!p) break;
3570
+ r.push(partReplacer(_polyfillHostNoCombinator, p, m[3]));
3571
+ }
3572
+ return r.join(",");
3573
+ } else return _polyfillHostNoCombinator + m[3];
3574
+ });
3575
+ };
3576
+ const colonHostPartReplacer = (host, part, suffix) => {
3577
+ return host + part.replace(_polyfillHost, "") + suffix;
3578
+ };
3579
+ const convertColonHost = (cssText) => {
3580
+ return convertColonRule(cssText, getCssColonHostRe(), colonHostPartReplacer);
3581
+ };
3582
+ const colonHostContextPartReplacer = (host, part, suffix) => {
3583
+ if (part.indexOf(_polyfillHost) > -1) return colonHostPartReplacer(host, part, suffix);
3584
+ else return host + part + suffix + ", " + part + " " + host + suffix;
3585
+ };
3586
+ const convertColonSlotted = (cssText, slotScopeId) => {
3587
+ const slotClass = "." + slotScopeId + " > ";
3588
+ const selectors = [];
3589
+ cssText = cssText.replace(getCssColonSlottedRe(), (...m) => {
3590
+ if (m[2]) {
3591
+ const compound = m[2].trim();
3592
+ const suffix = m[3];
3593
+ const slottedSelector = slotClass + compound + suffix;
3594
+ let prefixSelector = "";
3595
+ for (let i = m[4] - 1; i >= 0; i--) {
3596
+ const char = m[5][i];
3597
+ if (char === "}" || char === ",") break;
3598
+ prefixSelector = char + prefixSelector;
3599
+ }
3600
+ const orgSelector = (prefixSelector + slottedSelector).trim();
3601
+ const addedSelector = `${prefixSelector.trimEnd()}${slottedSelector.trim()}`.trim();
3602
+ if (orgSelector !== addedSelector) {
3603
+ const updatedSelector = `${addedSelector}, ${orgSelector}`;
3604
+ selectors.push({
3605
+ orgSelector,
3606
+ updatedSelector
3607
+ });
3608
+ }
3609
+ return slottedSelector;
3610
+ } else return _polyfillHostNoCombinator + m[3];
3611
+ });
3612
+ return {
3613
+ selectors,
3614
+ cssText
3615
+ };
3616
+ };
3617
+ const convertColonHostContext = (cssText) => {
3618
+ return convertColonRule(cssText, getCssColonHostContextRe(), colonHostContextPartReplacer);
3619
+ };
3620
+ const convertShadowDOMSelectors = (cssText) => {
3621
+ return _shadowDOMSelectorsRe.reduce((result, pattern) => result.replace(pattern, " "), cssText);
3622
+ };
3623
+ const makeScopeMatcher = (scopeSelector) => {
3624
+ scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
3625
+ return new RegExp("^(" + scopeSelector + ")([>\\s~+[.,{:][\\s\\S]*)?$", "m");
3626
+ };
3627
+ const selectorNeedsScoping = (selector, scopeSelector) => {
3628
+ return !makeScopeMatcher(scopeSelector).test(selector);
3629
+ };
3630
+ const injectScopingSelector = (selector, scopingSelector) => {
3631
+ return selector.replace(_selectorPartsRe, (_, before = "", _colonGroup, colon = "", after = "") => {
3632
+ return before + scopingSelector + colon + after;
3633
+ });
3634
+ };
3635
+ const applySimpleSelectorScope = (selector, scopeSelector, hostSelector) => {
3636
+ _polyfillHostRe.lastIndex = 0;
3637
+ if (_polyfillHostRe.test(selector)) {
3638
+ const replaceBy = `.${hostSelector}`;
3639
+ return selector.replace(_polyfillHostNoCombinatorRe, (_, sel) => injectScopingSelector(sel, replaceBy)).replace(_polyfillHostRe, replaceBy + " ");
3640
+ }
3641
+ return scopeSelector + " " + selector;
3642
+ };
3643
+ const applyStrictSelectorScope = (selector, scopeSelector, hostSelector) => {
3644
+ scopeSelector = scopeSelector.replace(/\[is=([^\]]*)\]/g, (_, ...parts) => parts[0]);
3645
+ const className = "." + scopeSelector;
3646
+ const _scopeSelectorPart = (p) => {
3647
+ let scopedP = p.trim();
3648
+ if (!scopedP) return "";
3649
+ if (p.indexOf(_polyfillHostNoCombinator) > -1) scopedP = applySimpleSelectorScope(p, scopeSelector, hostSelector);
3650
+ else {
3651
+ const t = p.replace(_polyfillHostRe, "");
3652
+ if (t.length > 0) scopedP = injectScopingSelector(t, className);
3653
+ }
3654
+ return scopedP;
3655
+ };
3656
+ const safeContent = safeSelector(selector);
3657
+ selector = safeContent.content;
3658
+ let scopedSelector = "";
3659
+ let startIndex = 0;
3660
+ let res;
3661
+ const sep = /( |>|\+|~(?!=))(?=(?:[^()]*\([^()]*\))*[^()]*$)\s*/g;
3662
+ let shouldScope = !(selector.indexOf(_polyfillHostNoCombinator) > -1);
3663
+ while ((res = sep.exec(selector)) !== null) {
3664
+ const separator = res[1];
3665
+ const part = selector.slice(startIndex, res.index).trim();
3666
+ shouldScope = shouldScope || part.indexOf(_polyfillHostNoCombinator) > -1;
3667
+ const scopedPart = shouldScope ? _scopeSelectorPart(part) : part;
3668
+ scopedSelector += `${scopedPart} ${separator} `;
3669
+ startIndex = sep.lastIndex;
3670
+ }
3671
+ const part = selector.substring(startIndex);
3672
+ shouldScope = !part.match(_safePartRe) && (shouldScope || part.indexOf(_polyfillHostNoCombinator) > -1);
3673
+ scopedSelector += shouldScope ? _scopeSelectorPart(part) : part;
3674
+ return restoreSafeSelector(safeContent.placeholders, scopedSelector);
3675
+ };
3676
+ const scopeSelector = (selector, scopeSelectorText, hostSelector, slotSelector) => {
3677
+ return selector.split(",").map((shallowPart) => {
3678
+ if (slotSelector && shallowPart.indexOf("." + slotSelector) > -1) return shallowPart.trim();
3679
+ if (selectorNeedsScoping(shallowPart, scopeSelectorText)) return applyStrictSelectorScope(shallowPart, scopeSelectorText, hostSelector).trim();
3680
+ else return shallowPart.trim();
3681
+ }).join(", ");
3682
+ };
3683
+ const scopeSelectors = (cssText, scopeSelectorText, hostSelector, slotSelector, commentOriginalSelector) => {
3684
+ return processRules(cssText, (rule) => {
3685
+ let selector = rule.selector;
3686
+ let content = rule.content;
3687
+ if (rule.selector[0] !== "@") selector = scopeSelector(rule.selector, scopeSelectorText, hostSelector, slotSelector);
3688
+ else if (rule.selector.startsWith("@media") || rule.selector.startsWith("@supports") || rule.selector.startsWith("@page") || rule.selector.startsWith("@document")) content = scopeSelectors(rule.content, scopeSelectorText, hostSelector, slotSelector, commentOriginalSelector);
3689
+ return {
3690
+ selector: selector.replace(/\s{2,}/g, " ").trim(),
3691
+ content
3692
+ };
3693
+ });
3694
+ };
3695
+ const scopeCssText = (cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector) => {
3696
+ cssText = insertPolyfillHostInCssText(cssText);
3697
+ cssText = convertColonHost(cssText);
3698
+ cssText = convertColonHostContext(cssText);
3699
+ const slotted = convertColonSlotted(cssText, slotScopeId);
3700
+ cssText = slotted.cssText;
3701
+ cssText = convertShadowDOMSelectors(cssText);
3702
+ if (scopeId) cssText = scopeSelectors(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
3703
+ cssText = replaceShadowCssHost(cssText, hostScopeId);
3704
+ cssText = cssText.replace(/>\s*\*\s+([^{, ]+)/gm, " $1 ");
3705
+ return {
3706
+ cssText: cssText.trim(),
3707
+ slottedSelectors: slotted.selectors.map((ref) => ({
3708
+ orgSelector: replaceShadowCssHost(ref.orgSelector, hostScopeId),
3709
+ updatedSelector: replaceShadowCssHost(ref.updatedSelector, hostScopeId)
3710
+ }))
3711
+ };
3712
+ };
3713
+ /**
3714
+ * Helper function that replaces the interim string representing a `:host` selector with
3715
+ * the host scope selector class for the element.
3716
+ *
3717
+ * @param cssText The CSS string to make the replacement in
3718
+ * @param hostScopeId The scope ID that will be used as the class representing the host element
3719
+ * @returns CSS with the selector replaced
3720
+ */
3721
+ const replaceShadowCssHost = (cssText, hostScopeId) => {
3722
+ return cssText.replace(/-shadowcsshost-no-combinator/g, `.${hostScopeId}`);
3723
+ };
3724
+ /**
3725
+ * Expands selectors with ::part(...) to also include [part~="..."] selectors.
3726
+ * For example:
3727
+ * ```css
3728
+ * selectors-like-this::part(demo) { ... }
3729
+ * .something .selectors::part(demo demo2):hover { ... }
3730
+ * ```
3731
+ * Becomes:
3732
+ * ```
3733
+ * selectors-like-this::part(demo), selectors-like-this [part~="demo"] { ... }
3734
+ * .something .selectors::part(demo demo2):hover, .something .selectors [part~="demo"][part~="demo2"]:hover { ... }
3735
+ * ```
3736
+ *
3737
+ * @param cssText The CSS text to process
3738
+ * @returns The CSS text with expanded ::part(...) selectors
3739
+ */
3740
+ const expandPartSelectors = (cssText) => {
3741
+ const partSelectorRe = /([^\s,{][^,{]*?)::part\(\s*([^)]+?)\s*\)((?:[:.][^,{]*)*)/g;
3742
+ return processRules(cssText, (rule) => {
3743
+ if (rule.selector[0] === "@") return rule;
3744
+ rule.selector = rule.selector.split(",").map((sel) => {
3745
+ const out = [sel.trim()];
3746
+ let m;
3747
+ while ((m = partSelectorRe.exec(sel)) !== null) {
3748
+ const before = m[1].trimEnd();
3749
+ const partNames = m[2].trim().split(/\s+/);
3750
+ const after = m[3] || "";
3751
+ const partAttr = partNames.flatMap((p) => {
3752
+ if (!rule.selector.includes(`[part~="${p}"]`)) return [`[part~="${p}"]`];
3753
+ return [];
3754
+ }).join("");
3755
+ const expanded = `${before} ${partAttr}${after}`;
3756
+ if (!!partAttr && expanded !== sel.trim()) out.push(expanded);
3757
+ }
3758
+ return out.join(", ");
3759
+ }).join(", ");
3760
+ return rule;
3761
+ });
3762
+ };
3763
+ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
3764
+ const hostScopeId = scopeId + "-h";
3765
+ const slotScopeId = scopeId + "-s";
3766
+ const commentsWithHash = extractCommentsWithHash(cssText);
3767
+ cssText = stripComments(cssText);
3768
+ const orgSelectors = [];
3769
+ if (commentOriginalSelector) {
3770
+ const processCommentedSelector = (rule) => {
3771
+ const placeholder = `/*!@___${orgSelectors.length}___*/`;
3772
+ const comment = `/*!@${rule.selector}*/`;
3773
+ orgSelectors.push({
3774
+ placeholder,
3775
+ comment
3776
+ });
3777
+ rule.selector = placeholder + rule.selector;
3778
+ return rule;
3779
+ };
3780
+ cssText = processRules(cssText, (rule) => {
3781
+ if (rule.selector[0] !== "@") return processCommentedSelector(rule);
3782
+ else if (rule.selector.startsWith("@media") || rule.selector.startsWith("@supports") || rule.selector.startsWith("@page") || rule.selector.startsWith("@document")) {
3783
+ rule.content = processRules(rule.content, processCommentedSelector);
3784
+ return rule;
3785
+ }
3786
+ return rule;
3787
+ });
3788
+ }
3789
+ const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
3790
+ cssText = [scoped.cssText, ...commentsWithHash].join("\n");
3791
+ if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
3792
+ cssText = cssText.replace(placeholder, comment);
3793
+ });
3794
+ scoped.slottedSelectors.forEach((slottedSelector) => {
3795
+ const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
3796
+ cssText = cssText.replace(regex, slottedSelector.updatedSelector);
3797
+ });
3798
+ cssText = expandPartSelectors(cssText);
3799
+ return cssText;
3800
+ };
3801
+ //#endregion
3802
+ //#region src/runtime/mode.ts
3803
+ const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
3804
+ const setMode = (handler) => modeResolutionChain.push(handler);
3805
+ const getMode = (ref) => getHostRef(ref)?.$modeName$;
3806
+ //#endregion
3807
+ //#region src/runtime/normalize-watchers.ts
3808
+ /**
3809
+ * Normalizes watcher metadata to the current `{ [methodName]: flags }[]` format.
3810
+ *
3811
+ * Prior to Stencil 4.39.x (PR #6484), the `@Watch()` compiler emitted watcher
3812
+ * handlers as a plain string array: `{ "min": ["minChanged"] }`. The new format
3813
+ * wraps each entry in an object that carries option flags (e.g. `immediate`):
3814
+ * `{ "min": [{ "minChanged": 0 }] }`.
3815
+ *
3816
+ * When a library (e.g. Ionic Framework) was compiled with an older Stencil compiler
3817
+ * but consumed by an app using a newer Stencil runtime, the runtime's
3818
+ * `Object.entries(watcher)` call receives a string and misinterprets its character
3819
+ * indices as method names, causing:
3820
+ * `TypeError: instance[watchMethodName] is not a function`
3821
+ *
3822
+ * This helper should be used at `$watchers$` assignment sites that need to
3823
+ * accept both legacy and current compiler metadata so downstream code on those
3824
+ * paths can safely assume the new object format.
3825
+ *
3826
+ * @param raw The raw watcher map from compiled metadata (new or legacy format).
3827
+ * @returns A normalized watcher map in the `{ [methodName]: flags }[]` format, or `undefined` if `raw` is `undefined` or empty.
3828
+ */
3829
+ const normalizeWatchers = (raw) => {
3830
+ if (!raw) return void 0;
3831
+ const keys = Object.keys(raw);
3832
+ if (keys.length === 0) return void 0;
3833
+ let hasLegacy = false;
3834
+ for (const propName of keys) {
3835
+ if (hasLegacy) break;
3836
+ for (const h of raw[propName]) if (typeof h === "string") {
3837
+ hasLegacy = true;
3838
+ break;
3839
+ }
3840
+ }
3841
+ if (!hasLegacy) return raw;
3842
+ const out = {};
3843
+ for (const propName of keys) out[propName] = raw[propName].map((h) => typeof h === "string" ? { [h]: 0 } : h);
3844
+ return out;
3845
+ };
3846
+ //#endregion
3847
+ //#region src/runtime/parse-property-value.ts
3848
+ /**
3849
+ * Parse a new property value for a given property type.
3850
+ *
3851
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
3852
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
3853
+ * 1. `any`, the type given to `propValue` in the function signature
3854
+ * 2. the type stored from `propType`.
3855
+ *
3856
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
3857
+ *
3858
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
3859
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
3860
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
3861
+ * ```tsx
3862
+ * <my-cmp prop-val={0}></my-cmp>
3863
+ * ```
3864
+ *
3865
+ * HTML prop values on the other hand, will always a string
3866
+ *
3867
+ * @param propValue the new value to coerce to some type
3868
+ * @param propType the type of the prop, expressed as a binary number
3869
+ * @param isFormAssociated whether the component is form-associated (optional)
3870
+ * @returns the parsed/coerced value
3871
+ */
3872
+ const parsePropertyValue = (propValue, propType, isFormAssociated) => {
3873
+ if (propValue != null && !isComplexType(propValue)) {
3874
+ /**
3875
+ * ensure this value is of the correct prop type
3876
+ */
3877
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean)
3878
+ /**
3879
+ * For form-associated components, according to HTML spec, the presence of any boolean attribute
3880
+ * (regardless of its value, even "false") should make the property true.
3881
+ * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
3882
+ */
3883
+ if (BUILD.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
3884
+ else return propValue === "false" ? false : propValue === "" || !!propValue;
3885
+ /**
3886
+ * force it to be a number
3887
+ */
3888
+ if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
3889
+ /**
3890
+ * could have been passed as a number or boolean but we still want it as a string
3891
+ */
3892
+ if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
3893
+ return propValue;
3894
+ }
3895
+ /**
3896
+ * not sure exactly what type we want so no need to change to a different type
3897
+ */
3898
+ return propValue;
3899
+ };
3900
+ //#endregion
3901
+ //#region src/runtime/set-value.ts
3902
+ const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
3903
+ const run = (inst) => {
3904
+ let attrVal = val;
3905
+ for (const serializer of cmpMeta.$serializers$[propName]) {
3906
+ const [[methodName]] = Object.entries(serializer);
3907
+ attrVal = inst[methodName](attrVal, propName);
3908
+ }
3909
+ hostRef.$serializerValues$.set(propName, attrVal);
3910
+ };
3911
+ if (instance) run(instance);
3912
+ else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
3913
+ };
3914
+ const getValue = (ref, propName) => {
3915
+ if (BUILD.signalBacking) {
3916
+ const sig = getHostRef(ref)?.$signalValues$?.get(propName);
3917
+ if (sig !== void 0) return sig.value;
3918
+ }
3919
+ return getHostRef(ref).$instanceValues$.get(propName);
3920
+ };
3921
+ const setValue = (ref, propName, newVal, cmpMeta) => {
3922
+ const hostRef = getHostRef(ref);
3923
+ if (BUILD.signalBacking) {
3924
+ const sig = hostRef?.$signalValues$?.get(propName);
3925
+ if (sig !== void 0) {
3926
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
3927
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
3928
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3929
+ applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
3930
+ }
3931
+ if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
3932
+ return;
3933
+ }
3934
+ }
3935
+ if (!hostRef) {
3936
+ if (BUILD.lazyLoad) throw new Error(BUILD.isDev ? `Couldn't find host element for "${cmpMeta.$tagName$}". This usually happens when integrating a 3rd party Stencil component with another Stencil runtime. See https://github.com/stenciljs/core/issues/5457` : `Host element not found for "${cmpMeta.$tagName$}"`);
3937
+ return;
3938
+ }
3939
+ if (BUILD.serializer && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
3940
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3941
+ const oldVal = hostRef.$instanceValues$.get(propName);
3942
+ const flags = hostRef.$flags$;
3943
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
3944
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
3945
+ const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
3946
+ if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
3947
+ hostRef.$instanceValues$.set(propName, newVal);
3948
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
3949
+ if (BUILD.isDev) {
3950
+ if (hostRef.$flags$ & HOST_FLAGS.devOnRender) consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3951
+ else if (hostRef.$flags$ & HOST_FLAGS.devOnDidLoad) consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3952
+ }
3953
+ if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
3954
+ const watchMethods = cmpMeta.$watchers$[propName];
3955
+ if (watchMethods) watchMethods.map((watcher) => {
3956
+ try {
3957
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
3958
+ if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
3959
+ if (BUILD.signalBacking && !hostRef.$signalValues$) return;
3960
+ if (!instance) hostRef.$fetchedCbList$.push(() => {
3961
+ hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
3962
+ });
3963
+ else instance[watchMethodName](newVal, oldVal, propName);
3964
+ }
3965
+ } catch (e) {
3966
+ consoleError(e, elm);
3967
+ }
3968
+ });
3969
+ }
3970
+ if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
3971
+ if (instance.componentShouldUpdate) {
3972
+ if (instance.componentShouldUpdate(newVal, oldVal, propName) === false && !(flags & HOST_FLAGS.isQueuedForUpdate)) return;
3973
+ }
3974
+ if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3975
+ }
3976
+ }
3977
+ };
3978
+ //#endregion
3979
+ //#region src/runtime/proxy-component.ts
3980
+ /**
3981
+ * Attach a series of runtime constructs to a compiled Stencil component
3982
+ * constructor, including getters and setters for the `@Prop` and `@State`
3983
+ * decorators, callbacks for when attributes change, and so on.
3984
+ *
3985
+ * On a lazy loaded component, this is wired up to both the class instance
3986
+ * and the element separately. A `hostRef` keeps the 2 in sync.
3987
+ *
3988
+ * On a traditional component, this is wired up to the element only.
3989
+ *
3990
+ * @param Cstr - the constructor for a component that we need to process
3991
+ * @param cmpMeta - metadata collected previously about the component
3992
+ * @param flags - a number used to store a series of bit flags
3993
+ * @returns a reference to the same constructor passed in (but now mutated)
3994
+ */
3995
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
3996
+ const prototype = Cstr.prototype;
3997
+ if (BUILD.isTesting) {
3998
+ if (prototype.__stencilAugmented) return;
3999
+ prototype.__stencilAugmented = true;
4000
+ }
4001
+ /**
4002
+ * proxy form associated custom element lifecycle callbacks
4003
+ * @see https://web.dev/articles/more-capable-form-controls#lifecycle_callbacks
4004
+ */
4005
+ if (BUILD.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated && flags & PROXY_FLAGS.isElementConstructor) FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS.forEach((cbName) => {
4006
+ const originalFormAssociatedCallback = prototype[cbName];
4007
+ Object.defineProperty(prototype, cbName, { value(...args) {
4008
+ const hostRef = getHostRef(this);
4009
+ const instance = BUILD.lazyLoad ? hostRef?.$lazyInstance$ : this;
4010
+ if (!instance) hostRef?.$onReadyPromise$?.then((asyncInstance) => {
4011
+ const cb = asyncInstance[cbName];
4012
+ if (typeof cb === "function") cb.call(asyncInstance, ...args);
4013
+ });
4014
+ else {
4015
+ const cb = BUILD.lazyLoad ? instance[cbName] : originalFormAssociatedCallback;
4016
+ if (typeof cb === "function") cb.call(instance, ...args);
4017
+ }
4018
+ } });
4019
+ });
4020
+ if (BUILD.member && cmpMeta.$members$ || BUILD.propChangeCallback) {
4021
+ if (BUILD.propChangeCallback) {
4022
+ if (Cstr.watchers && !cmpMeta.$watchers$) cmpMeta.$watchers$ = normalizeWatchers(Cstr.watchers);
4023
+ if (Cstr.deserializers && !cmpMeta.$deserializers$) cmpMeta.$deserializers$ = Cstr.deserializers;
4024
+ if (Cstr.serializers && !cmpMeta.$serializers$) cmpMeta.$serializers$ = Cstr.serializers;
4025
+ }
4026
+ const members = Object.entries(cmpMeta.$members$ ?? {});
4027
+ members.map(([memberName, [memberFlags]]) => {
4028
+ if ((BUILD.prop || BUILD.state) && (memberFlags & MEMBER_FLAGS.Prop || (!BUILD.lazyLoad || flags & PROXY_FLAGS.proxyState) && memberFlags & MEMBER_FLAGS.State)) {
4029
+ const { get: origGetter, set: origSetter } = getPropertyDescriptor(prototype, memberName) || {};
4030
+ if (origGetter) cmpMeta.$members$[memberName][0] |= MEMBER_FLAGS.Getter;
4031
+ if (origSetter) cmpMeta.$members$[memberName][0] |= MEMBER_FLAGS.Setter;
4032
+ if (flags & PROXY_FLAGS.isElementConstructor || !origGetter) Object.defineProperty(prototype, memberName, {
4033
+ get() {
4034
+ if (BUILD.lazyLoad) {
4035
+ if ((cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Getter) === 0) return getValue(this, memberName);
4036
+ const ref = getHostRef(this);
4037
+ const instance = ref ? ref.$lazyInstance$ : prototype;
4038
+ if (!instance) return;
4039
+ return instance[memberName];
4040
+ }
4041
+ if (!BUILD.lazyLoad) return origGetter ? origGetter.apply(this) : getValue(this, memberName);
4042
+ },
4043
+ configurable: true,
4044
+ enumerable: true
4045
+ });
4046
+ Object.defineProperty(prototype, memberName, { set(newValue) {
4047
+ const ref = getHostRef(this);
4048
+ if (!ref) return;
4049
+ if (BUILD.isDev) {
4050
+ if ((flags & PROXY_FLAGS.isElementConstructor) === 0 && (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter) === 0 && (ref && ref.$flags$ & HOST_FLAGS.isConstructingInstance) === 0 && (memberFlags & MEMBER_FLAGS.Prop) !== 0 && (memberFlags & MEMBER_FLAGS.Mutable) === 0) consoleDevWarn(`@Prop() "${memberName}" on <${cmpMeta.$tagName$}> is immutable but was modified from within the component.\nMore information: https://stenciljs.com/docs/properties#prop-mutability`);
4051
+ }
4052
+ if (origSetter) {
4053
+ if (typeof (memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName]) === "undefined" && ref.$instanceValues$.get(memberName)) newValue = ref.$instanceValues$.get(memberName);
4054
+ origSetter.apply(this, [parsePropertyValue(newValue, memberFlags, BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated))]);
4055
+ newValue = memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName];
4056
+ setValue(this, memberName, newValue, cmpMeta);
4057
+ return;
4058
+ }
4059
+ if (!BUILD.lazyLoad) {
4060
+ setValue(this, memberName, newValue, cmpMeta);
4061
+ return;
4062
+ }
4063
+ if (BUILD.lazyLoad) {
4064
+ if ((flags & PROXY_FLAGS.isElementConstructor) === 0 || (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter) === 0) {
4065
+ setValue(this, memberName, newValue, cmpMeta);
4066
+ if (flags & PROXY_FLAGS.isElementConstructor && !ref.$lazyInstance$) ref.$fetchedCbList$.push(() => {
4067
+ if (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter && ref.$lazyInstance$[memberName] !== ref.$instanceValues$.get(memberName)) ref.$lazyInstance$[memberName] = newValue;
4068
+ });
4069
+ return;
4070
+ }
4071
+ const setterSetVal = () => {
4072
+ const currentValue = ref.$lazyInstance$[memberName];
4073
+ if (!ref.$instanceValues$.get(memberName) && currentValue) ref.$instanceValues$.set(memberName, currentValue);
4074
+ ref.$lazyInstance$[memberName] = parsePropertyValue(newValue, memberFlags, BUILD.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4075
+ setValue(this, memberName, ref.$lazyInstance$[memberName], cmpMeta);
4076
+ };
4077
+ if (ref.$lazyInstance$) setterSetVal();
4078
+ else ref.$fetchedCbList$.push(() => {
4079
+ setterSetVal();
4080
+ });
4081
+ }
4082
+ } });
4083
+ } else if (BUILD.lazyLoad && BUILD.method && flags & PROXY_FLAGS.isElementConstructor && memberFlags & MEMBER_FLAGS.Method) Object.defineProperty(prototype, memberName, { value(...args) {
4084
+ const ref = getHostRef(this);
4085
+ return ref?.$onInstancePromise$?.then(() => ref.$lazyInstance$?.[memberName](...args));
4086
+ } });
4087
+ });
4088
+ if (BUILD.observeAttribute && (!BUILD.lazyLoad || flags & PROXY_FLAGS.isElementConstructor)) {
4089
+ const attrNameToPropName = /* @__PURE__ */ new Map();
4090
+ prototype.attributeChangedCallback = function(attrName, oldValue, newValue) {
4091
+ plt.jmp(() => {
4092
+ const propName = attrNameToPropName.get(attrName);
4093
+ const hostRef = getHostRef(this);
4094
+ if (BUILD.serializer && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newValue) return;
4095
+ if (this.hasOwnProperty(propName) && BUILD.lazyLoad) {
4096
+ newValue = this[propName];
4097
+ delete this[propName];
4098
+ }
4099
+ if (BUILD.deserializer && cmpMeta.$deserializers$ && cmpMeta.$deserializers$[propName]) {
4100
+ const setVal = (methodName, instance) => {
4101
+ const deserializeVal = instance?.[methodName](newValue, propName);
4102
+ if (deserializeVal !== this[propName]) this[propName] = deserializeVal;
4103
+ };
4104
+ for (const deserializer of cmpMeta.$deserializers$[propName]) {
4105
+ const [[methodName]] = Object.entries(deserializer);
4106
+ if (BUILD.lazyLoad) if (hostRef.$lazyInstance$) setVal(methodName, hostRef.$lazyInstance$);
4107
+ else hostRef.$fetchedCbList$.push(() => {
4108
+ setVal(methodName, hostRef.$lazyInstance$);
4109
+ });
4110
+ else setVal(methodName, this);
4111
+ }
4112
+ return;
4113
+ } else if (prototype.hasOwnProperty(propName) && typeof this[propName] === "number" && this[propName] == newValue) return;
4114
+ else if (propName == null) {
4115
+ const hostFlags = hostRef?.$flags$;
4116
+ if (hostRef && hostFlags && !(hostFlags & HOST_FLAGS.isConstructingInstance) && newValue !== oldValue) {
4117
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : this;
4118
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
4119
+ (cmpMeta.$watchers$?.[attrName])?.forEach((watcher) => {
4120
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4121
+ if (instance[watchMethodName] != null && (hostFlags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate)) instance[watchMethodName](newValue, oldValue, attrName);
4122
+ });
4123
+ }
4124
+ return;
4125
+ }
4126
+ const propFlags = members.find(([m]) => m === propName);
4127
+ const isBooleanTarget = propFlags && propFlags[1][0] & MEMBER_FLAGS.Boolean;
4128
+ const isSpuriousBooleanRemoval = isBooleanTarget && newValue === null && this[propName] === void 0;
4129
+ if (isBooleanTarget) newValue = !(newValue === null || newValue === "false");
4130
+ const propDesc = Object.getOwnPropertyDescriptor(prototype, propName);
4131
+ if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4132
+ });
4133
+ };
4134
+ Cstr.observedAttributes = Array.from(new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
4135
+ const attrName = m[1] || propName;
4136
+ attrNameToPropName.set(attrName, propName);
4137
+ if (BUILD.reflect && m[0] & MEMBER_FLAGS.ReflectAttr) cmpMeta.$attrsToReflect$?.push([propName, attrName]);
4138
+ return attrName;
4139
+ })]));
4140
+ }
4141
+ }
4142
+ return Cstr;
4143
+ };
4144
+ //#endregion
4145
+ //#region src/runtime/initialize-component.ts
4146
+ /**
4147
+ * Initialize a Stencil component given a reference to its host element, its
4148
+ * runtime bookkeeping data structure, runtime metadata about the component,
4149
+ * and (optionally) an HMR version ID.
4150
+ *
4151
+ * @param elm a host element
4152
+ * @param hostRef the element's runtime bookkeeping object
4153
+ * @param cmpMeta runtime metadata for the Stencil component
4154
+ * @param hmrVersionId an (optional) HMR version ID
4155
+ */
4156
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4157
+ let Cstr;
4158
+ try {
4159
+ if ((hostRef.$flags$ & HOST_FLAGS.hasInitializedComponent) === 0) {
4160
+ hostRef.$flags$ |= HOST_FLAGS.hasInitializedComponent;
4161
+ const bundleId = cmpMeta.$lazyBundleId$;
4162
+ if (BUILD.lazyLoad && bundleId) {
4163
+ const CstrImport = loadModule(cmpMeta, hostRef, hmrVersionId);
4164
+ if (CstrImport && "then" in CstrImport) {
4165
+ const endLoad = uniqueTime(`st:load:${cmpMeta.$tagName$}:${hostRef.$modeName$}`, `[Stencil] Load module for <${cmpMeta.$tagName$}>`);
4166
+ Cstr = await CstrImport;
4167
+ endLoad();
4168
+ } else Cstr = CstrImport;
4169
+ if (!Cstr) throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
4170
+ if (BUILD.member && !Cstr.isProxied) {
4171
+ if (BUILD.propChangeCallback) {
4172
+ cmpMeta.$watchers$ = normalizeWatchers(Cstr.watchers);
4173
+ cmpMeta.$serializers$ = Cstr.serializers;
4174
+ cmpMeta.$deserializers$ = Cstr.deserializers;
4175
+ }
4176
+ proxyComponent(Cstr, cmpMeta, PROXY_FLAGS.proxyState);
4177
+ Cstr.isProxied = true;
4178
+ }
4179
+ const endNewInstance = createTime("createInstance", cmpMeta.$tagName$);
4180
+ if (BUILD.member) hostRef.$flags$ |= HOST_FLAGS.isConstructingInstance;
4181
+ try {
4182
+ new Cstr(hostRef);
4183
+ } catch (e) {
4184
+ consoleError(e, elm);
4185
+ }
4186
+ if (BUILD.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4187
+ endNewInstance();
4188
+ if (!(BUILD.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4189
+ else hostRef.$deferredConnectedCallback$ = true;
4190
+ } else Cstr = elm.constructor;
4191
+ if (BUILD.style && Cstr && Cstr.style) {
4192
+ /**
4193
+ * this component has styles but we haven't registered them yet
4194
+ */
4195
+ let style;
4196
+ if (typeof Cstr.style === "string")
4197
+ /**
4198
+ * in case the component has a `styleUrl` defined, e.g.
4199
+ * ```ts
4200
+ * @Component({
4201
+ * tag: 'my-component',
4202
+ * styleUrl: 'my-component.css'
4203
+ * })
4204
+ * ```
4205
+ */
4206
+ style = Cstr.style;
4207
+ else if (BUILD.mode && typeof Cstr.style !== "string") {
4208
+ /**
4209
+ * in case the component has a `styleUrl` object defined, e.g.
4210
+ * ```ts
4211
+ * @Component({
4212
+ * tag: 'my-component',
4213
+ * styleUrl: {
4214
+ * ios: 'my-component.ios.css',
4215
+ * md: 'my-component.md.css'
4216
+ * }
4217
+ * })
4218
+ * ```
4219
+ */
4220
+ hostRef.$modeName$ = computeMode(elm);
4221
+ if (hostRef.$modeName$) style = Cstr.style[hostRef.$modeName$];
4222
+ if (BUILD.hydrateServerSide && hostRef.$modeName$) elm.setAttribute("s-mode", hostRef.$modeName$);
4223
+ }
4224
+ const scopeId = getScopeId(cmpMeta, hostRef.$modeName$);
4225
+ if (!styles.has(scopeId) || BUILD.hotModuleReplacement && hmrVersionId) {
4226
+ const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4227
+ if (BUILD.hydrateServerSide && BUILD.shadowDom) {
4228
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4229
+ else if (needsScopedSSR()) style = expandPartSelectors(style);
4230
+ }
4231
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4232
+ endRegisterStyles();
4233
+ }
4234
+ }
4235
+ }
4236
+ if (BUILD.signalBacking && cmpMeta.$members$) initializeSignals(elm, hostRef, cmpMeta);
4237
+ else if (BUILD.vdomSignals) initializeEffects(elm, hostRef);
4238
+ const ancestorComponent = hostRef.$ancestorComponent$;
4239
+ const schedule = () => scheduleUpdate(hostRef, true);
4240
+ if (BUILD.asyncLoading && ancestorComponent && ancestorComponent["s-rc"]) ancestorComponent["s-rc"].push(schedule);
4241
+ else schedule();
4242
+ } catch (e) {
4243
+ consoleError(e, elm);
4244
+ if (BUILD.asyncLoading && hostRef.$onRenderResolve$) {
4245
+ hostRef.$onRenderResolve$();
4246
+ hostRef.$onRenderResolve$ = void 0;
4247
+ }
4248
+ if (BUILD.asyncLoading && hostRef.$onReadyResolve$) hostRef.$onReadyResolve$(elm);
4249
+ }
4250
+ };
4251
+ const fireConnectedCallback = (instance, elm) => {
4252
+ if (BUILD.lazyLoad) safeCall(instance, "connectedCallback", void 0, elm);
4253
+ };
4254
+ //#endregion
4255
+ //#region src/runtime/connected-callback.ts
4256
+ const connectedCallback = (elm) => {
4257
+ if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
4258
+ const hostRef = getHostRef(elm);
4259
+ if (!hostRef) return;
4260
+ const cmpMeta = hostRef.$cmpMeta$;
4261
+ const endConnected = createTime("connectedCallback", cmpMeta.$tagName$);
4262
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasConnected)) {
4263
+ hostRef.$flags$ |= HOST_FLAGS.hasConnected;
4264
+ let hostId;
4265
+ if (BUILD.hydrateClientSide) {
4266
+ hostId = elm.getAttribute(HYDRATE_ID);
4267
+ if (hostId) {
4268
+ if (BUILD.shadowDom && cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) {
4269
+ const shadowRoot = getShadowRoot(elm);
4270
+ const scopeId = BUILD.mode ? addStyle(shadowRoot, cmpMeta, elm.getAttribute("s-mode")) : addStyle(shadowRoot, cmpMeta);
4271
+ elm.classList.remove(scopeId + "-h", scopeId + "-s");
4272
+ } else if (BUILD.scoped && cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation) elm["s-sc"] = getScopeId(cmpMeta, BUILD.mode ? elm.getAttribute("s-mode") : void 0);
4273
+ initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
4274
+ }
4275
+ }
4276
+ if (BUILD.slotRelocation && !hostId) {
4277
+ if (BUILD.hydrateServerSide || (BUILD.slot || BUILD.shadowDom) && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) setContentReference(elm);
4278
+ }
4279
+ if (BUILD.asyncLoading) {
4280
+ let ancestorComponent = elm;
4281
+ while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) if (BUILD.hydrateClientSide && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id") && ancestorComponent["s-p"] || ancestorComponent["s-p"]) {
4282
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4283
+ break;
4284
+ }
4285
+ }
4286
+ if (BUILD.prop && !BUILD.hydrateServerSide && cmpMeta.$members$) Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
4287
+ if (memberFlags & MEMBER_FLAGS.Prop && Object.prototype.hasOwnProperty.call(elm, memberName)) {
4288
+ if (cmpMeta.$flags$ & CMP_FLAGS.hasModernPropertyDecls) {
4289
+ const desc = Object.getOwnPropertyDescriptor(elm, memberName);
4290
+ if (desc && (desc.get || desc.set)) return;
4291
+ }
4292
+ const value = elm[memberName];
4293
+ delete elm[memberName];
4294
+ elm[memberName] = value;
4295
+ }
4296
+ });
4297
+ if (!BUILD.lazyLoad && BUILD.prop && !BUILD.hydrateServerSide) {
4298
+ const pendingProps = elm["s-pp"];
4299
+ if (pendingProps) {
4300
+ delete elm["s-pp"];
4301
+ pendingProps.forEach((value, propName) => {
4302
+ elm[propName] = value;
4303
+ });
4304
+ }
4305
+ }
4306
+ if (BUILD.initializeNextTick) nextTick(() => initializeComponent(elm, hostRef, cmpMeta));
4307
+ else initializeComponent(elm, hostRef, cmpMeta);
4308
+ } else {
4309
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
4310
+ if (hostRef?.$lazyInstance$) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4311
+ else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$, elm));
4312
+ }
4313
+ endConnected();
4314
+ }
4315
+ };
4316
+ const setContentReference = (elm) => {
4317
+ if (!win.document) return;
4318
+ const contentRefElm = elm["s-cr"] = win.document.createComment(BUILD.isDebug ? `content-ref (host=${elm.localName})` : "");
4319
+ contentRefElm["s-cn"] = true;
4320
+ insertBefore(elm, contentRefElm, elm.firstChild);
4321
+ };
4322
+ //#endregion
4323
+ //#region src/runtime/disconnected-callback.ts
4324
+ const disconnectInstance = (instance, elm) => {
4325
+ if (BUILD.lazyLoad) safeCall(instance, "disconnectedCallback", void 0, elm || instance);
4326
+ };
4327
+ const disconnectedCallback = async (elm) => {
4328
+ if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
4329
+ const hostRef = getHostRef(elm);
4330
+ if (BUILD.hostListener) {
4331
+ if (hostRef?.$rmListeners$) {
4332
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4333
+ hostRef.$rmListeners$ = void 0;
4334
+ }
4335
+ }
4336
+ if (BUILD.vdomSignals && hostRef?.$signalCleanup$) {
4337
+ hostRef.$signalCleanup$();
4338
+ hostRef.$signalCleanup$ = void 0;
4339
+ }
4340
+ if (!BUILD.lazyLoad) disconnectInstance(elm);
4341
+ else if (hostRef?.$lazyInstance$) disconnectInstance(hostRef.$lazyInstance$, elm);
4342
+ else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$, elm));
4343
+ }
4344
+ /**
4345
+ * Remove the element from the `rootAppliedStyles` WeakMap
4346
+ */
4347
+ if (rootAppliedStyles.has(elm)) rootAppliedStyles.delete(elm);
4348
+ /**
4349
+ * Remove the shadow root from the `rootAppliedStyles` WeakMap
4350
+ */
4351
+ if (elm.shadowRoot && rootAppliedStyles.has(elm.shadowRoot)) rootAppliedStyles.delete(elm.shadowRoot);
4352
+ };
4353
+ //#endregion
4354
+ //#region src/runtime/hmr-component.ts
4355
+ /**
4356
+ * Kick off hot-module-replacement for a component. In order to replace the
4357
+ * component in-place we:
4358
+ *
4359
+ * 1. get a reference to the {@link d.HostRef} for the element
4360
+ * 2. reset the element's runtime flags
4361
+ * 3. re-run the initialization logic for the element (via
4362
+ * {@link initializeComponent})
4363
+ *
4364
+ * For standalone (non-lazy) builds, we instead re-import the component module
4365
+ * and patch the prototype of the registered constructor in-place, then
4366
+ * force a re-render of all existing instances in the DOM.
4367
+ *
4368
+ * @param hostElement the host element for the component which we want to start
4369
+ * doing HMR
4370
+ * @param cmpMeta runtime metadata for the component
4371
+ * @param hmrVersionId the current HMR version ID
4372
+ */
4373
+ const hmrStart = (hostElement, cmpMeta, hmrVersionId) => {
4374
+ if (BUILD.lazyLoad) {
4375
+ const hostRef = getHostRef(hostElement);
4376
+ if (!hostRef) return;
4377
+ hostRef.$flags$ = HOST_FLAGS.hasConnected;
4378
+ if (BUILD.hostListener && hostRef.$rmListeners$) {
4379
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4380
+ hostRef.$rmListeners$ = void 0;
4381
+ }
4382
+ initializeComponent(hostElement, hostRef, cmpMeta, hmrVersionId);
4383
+ } else hmrStandalone(hostElement, cmpMeta, hmrVersionId);
4384
+ };
4385
+ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4386
+ const modulePath = hostElement.constructor.__stencil_module__;
4387
+ console.log(`[Stencil HMR] hmrStandalone <${cmpMeta.$tagName$}> modulePath:`, modulePath);
4388
+ if (!modulePath) {
4389
+ console.warn(`[Stencil HMR] No __stencil_module__ on <${cmpMeta.$tagName$}> constructor - was this built with devMode?`);
4390
+ return;
4391
+ }
4392
+ try {
4393
+ const newModule = await import(
4394
+ /* @vite-ignore */
4395
+ `${modulePath}?s-hmr=${hmrVersionId}`
4396
+ );
4397
+ const NewClass = Object.values(newModule).find((v) => typeof v === "function" && v.is === cmpMeta.$tagName$) ?? newModule.default;
4398
+ if (!NewClass) return;
4399
+ const ctor = customElements.get(cmpMeta.$tagName$);
4400
+ if (ctor) for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4401
+ if (key === "constructor") continue;
4402
+ Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4403
+ }
4404
+ document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4405
+ if (BUILD.hostListener) {
4406
+ const hostRef = getHostRef(el);
4407
+ if (hostRef?.$rmListeners$) {
4408
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4409
+ hostRef.$rmListeners$ = void 0;
4410
+ addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4411
+ }
4412
+ }
4413
+ forceUpdate(el);
4414
+ });
4415
+ } catch (e) {
4416
+ console.error(`[Stencil HMR] Failed to reload <${cmpMeta.$tagName$}>`, e);
4417
+ }
4418
+ };
4419
+ //#endregion
4420
+ //#region src/runtime/bootstrap-standalone.ts
4421
+ const defineCustomElement = (Cstr, compactMeta) => {
4422
+ customElements.define(transformTag(compactMeta[1]), proxyCustomElement(Cstr, compactMeta));
4423
+ };
4424
+ const proxyCustomElement = (Cstr, compactMeta) => {
4425
+ if (BUILD.profile && performance.mark && performance.getEntriesByName("st:app:start", "mark").length === 0) performance.mark("st:app:start");
4426
+ const cmpMeta = {
4427
+ $flags$: compactMeta[0],
4428
+ $tagName$: compactMeta[1]
4429
+ };
4430
+ try {
4431
+ if (BUILD.member) cmpMeta.$members$ = compactMeta[2];
4432
+ if (BUILD.hostListener) cmpMeta.$listeners$ = compactMeta[3];
4433
+ if (BUILD.propChangeCallback) {
4434
+ cmpMeta.$watchers$ = normalizeWatchers(Cstr.$watchers$);
4435
+ cmpMeta.$deserializers$ = Cstr.$deserializers$;
4436
+ cmpMeta.$serializers$ = Cstr.$serializers$;
4437
+ }
4438
+ if (BUILD.reflect) cmpMeta.$attrsToReflect$ = [];
4439
+ if (BUILD.hotModuleReplacement) Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4440
+ hmrStart(this, cmpMeta, hmrVersionId);
4441
+ };
4442
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD.slotCloneNode || BUILD.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4443
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
4444
+ else {
4445
+ if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(Cstr.prototype);
4446
+ if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4447
+ patchSlotAppendChild(Cstr.prototype);
4448
+ patchSlotAppend(Cstr.prototype);
4449
+ patchSlotPrepend(Cstr.prototype);
4450
+ patchSlotInsertAdjacentHTML(Cstr.prototype);
4451
+ patchInsertBefore(Cstr.prototype);
4452
+ patchSlotRemoveChild(Cstr.prototype);
4453
+ }
4454
+ if (BUILD.slotTextContent) patchTextContent(Cstr.prototype);
4455
+ }
4456
+ if (BUILD.hydrateClientSide && BUILD.shadowDom) hydrateScopedToShadow();
4457
+ const originalConnectedCallback = Cstr.prototype.connectedCallback;
4458
+ const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
4459
+ Object.assign(Cstr.prototype, {
4460
+ __hasHostListenerAttached: false,
4461
+ __registerHost() {
4462
+ registerHost(this, cmpMeta);
4463
+ },
4464
+ componentOnReady() {
4465
+ return getHostRef(this)?.$onReadyPromise$;
4466
+ },
4467
+ connectedCallback() {
4468
+ if (!this.__hasHostListenerAttached) {
4469
+ const hostRef = getHostRef(this);
4470
+ if (!hostRef) return;
4471
+ addHostEventListeners(this, hostRef, cmpMeta.$listeners$);
4472
+ this.__hasHostListenerAttached = true;
4473
+ }
4474
+ connectedCallback(this);
4475
+ if (originalConnectedCallback) originalConnectedCallback.call(this);
4476
+ },
4477
+ disconnectedCallback() {
4478
+ disconnectedCallback(this);
4479
+ if (originalDisconnectedCallback) originalDisconnectedCallback.call(this);
4480
+ },
4481
+ __attachShadow() {
4482
+ const isClosed = BUILD.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
4483
+ let existingRoot = this.shadowRoot;
4484
+ if (BUILD.shadowModeClosed && isClosed) existingRoot = this.__shadowRoot ?? null;
4485
+ if (!existingRoot) createShadowRoot.call(this, cmpMeta);
4486
+ else if (BUILD.isDev && BUILD.shadowModeClosed && isClosed && existingRoot.mode !== "closed") throw new Error(`Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${existingRoot.mode} but expected closed.`);
4487
+ }
4488
+ });
4489
+ Object.defineProperty(Cstr, "is", {
4490
+ value: cmpMeta.$tagName$,
4491
+ configurable: true
4492
+ });
4493
+ return proxyComponent(Cstr, cmpMeta, PROXY_FLAGS.isElementConstructor | PROXY_FLAGS.proxyState);
4494
+ } catch (e) {
4495
+ consoleError(e);
4496
+ return Cstr;
4497
+ }
4498
+ };
4499
+ const forceModeUpdate = (elm) => {
4500
+ if (BUILD.style && BUILD.mode && !BUILD.lazyLoad) {
4501
+ const mode = computeMode(elm);
4502
+ const hostRef = getHostRef(elm);
4503
+ if (hostRef && hostRef.$modeName$ !== mode) {
4504
+ const cmpMeta = hostRef.$cmpMeta$;
4505
+ const oldScopeId = elm["s-sc"];
4506
+ const scopeId = getScopeId(cmpMeta, mode);
4507
+ const style = elm.constructor.style[mode];
4508
+ const flags = cmpMeta.$flags$;
4509
+ if (style) {
4510
+ if (!styles.has(scopeId)) registerStyle(scopeId, style, !!(flags & CMP_FLAGS.shadowDomEncapsulation));
4511
+ hostRef.$modeName$ = mode;
4512
+ elm.classList.remove(oldScopeId + "-h", oldScopeId + "-s");
4513
+ attachStyles(hostRef);
4514
+ forceUpdate(elm);
4515
+ }
4516
+ }
4517
+ }
4518
+ };
4519
+ //#endregion
4520
+ //#region src/runtime/bootstrap-loader.ts
4521
+ const bootstrapLazy = (lazyBundles, options = {}) => {
4522
+ if (BUILD.profile && performance.mark) performance.mark("st:app:start");
4523
+ installDevTools();
4524
+ if (!win.document) {
4525
+ console.warn("Stencil: No document found. Skipping");
4526
+ return;
4527
+ }
4528
+ const endBootstrap = createTime("bootstrapLazy");
4529
+ const cmpTags = [];
4530
+ const exclude = options.exclude || [];
4531
+ const _reg = options.registry ?? getRegistry();
4532
+ const head = win.document.head;
4533
+ const metaCharset = /* @__PURE__ */ head.querySelector("meta[charset]");
4534
+ const dataStyles = /* @__PURE__ */ win.document.createElement("style");
4535
+ const deferredConnectedCallbacks = [];
4536
+ let appLoadFallback;
4537
+ let isBootstrapping = true;
4538
+ Object.assign(plt, options);
4539
+ if (BUILD.asyncQueue && options.syncQueue) plt.$flags$ |= PLATFORM_FLAGS.queueSync;
4540
+ if (BUILD.hydrateClientSide) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
4541
+ if (BUILD.hydrateClientSide && BUILD.shadowDom) hydrateScopedToShadow();
4542
+ lazyBundles.map((lazyBundle) => {
4543
+ lazyBundle[1].map((compactMeta) => {
4544
+ const cmpMeta = {
4545
+ $flags$: compactMeta[0],
4546
+ $tagName$: compactMeta[1],
4547
+ $members$: compactMeta[2],
4548
+ $listeners$: compactMeta[3]
4549
+ };
4550
+ if (BUILD.member) cmpMeta.$members$ = compactMeta[2];
4551
+ if (BUILD.hostListener) cmpMeta.$listeners$ = compactMeta[3];
4552
+ if (BUILD.reflect) cmpMeta.$attrsToReflect$ = [];
4553
+ if (BUILD.propChangeCallback) {
4554
+ cmpMeta.$watchers$ = normalizeWatchers(compactMeta[4]);
4555
+ cmpMeta.$serializers$ = compactMeta[5] ?? {};
4556
+ cmpMeta.$deserializers$ = compactMeta[6] ?? {};
4557
+ }
4558
+ const tagName = transformTag(cmpMeta.$tagName$);
4559
+ const HostElement = class extends HTMLElement {
4560
+ ["s-p"];
4561
+ ["s-rc"];
4562
+ hreListeners = false;
4563
+ constructor(self) {
4564
+ super(self);
4565
+ self = this;
4566
+ registerHost(self, cmpMeta);
4567
+ if (BUILD.shadowDom && cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss)) {
4568
+ if (!self.shadowRoot) createShadowRoot.call(self, cmpMeta);
4569
+ else if (BUILD.isDev && self.shadowRoot.mode !== "open") throw new Error(`Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${self.shadowRoot.mode} but DSD shadow roots must use open mode.`);
4570
+ }
4571
+ }
4572
+ connectedCallback() {
4573
+ const hostRef = getHostRef(this);
4574
+ if (!hostRef) return;
4575
+ /**
4576
+ * The `connectedCallback` lifecycle event can potentially be fired multiple times
4577
+ * if the element is removed from the DOM and re-inserted. This is not a common use case,
4578
+ * but it can happen in some scenarios. To prevent registering the same event listeners
4579
+ * multiple times, we will only register them once.
4580
+ */
4581
+ if (!this.hreListeners) {
4582
+ this.hreListeners = true;
4583
+ addHostEventListeners(this, hostRef, cmpMeta.$listeners$);
4584
+ }
4585
+ if (appLoadFallback) {
4586
+ clearTimeout(appLoadFallback);
4587
+ appLoadFallback = null;
4588
+ }
4589
+ if (isBootstrapping) deferredConnectedCallbacks.push(this);
4590
+ else plt.jmp(() => connectedCallback(this));
4591
+ }
4592
+ disconnectedCallback() {
4593
+ plt.jmp(() => disconnectedCallback(this));
4594
+ /**
4595
+ * Clear up references within the `$vnode$` object to the DOM
4596
+ * node that was removed. This is necessary to ensure that these
4597
+ * references used as keys in the `hostRef` object can be properly
4598
+ * garbage collected.
4599
+ *
4600
+ * Also remove the reference from `deferredConnectedCallbacks` array
4601
+ * otherwise removed instances won't get garbage collected.
4602
+ */
4603
+ plt.raf(() => {
4604
+ const hostRef = getHostRef(this);
4605
+ if (!hostRef) return;
4606
+ const i = deferredConnectedCallbacks.findIndex((host) => host === this);
4607
+ if (i > -1) deferredConnectedCallbacks.splice(i, 1);
4608
+ if (hostRef?.$vnode$?.$elm$ instanceof Node && !hostRef.$vnode$.$elm$.isConnected) delete hostRef.$vnode$.$elm$;
4609
+ });
4610
+ }
4611
+ componentOnReady() {
4612
+ return getHostRef(this)?.$onReadyPromise$;
4613
+ }
4614
+ };
4615
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD.slotCloneNode || BUILD.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(HostElement.prototype);
4616
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(HostElement.prototype);
4617
+ else {
4618
+ if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(HostElement.prototype);
4619
+ if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4620
+ patchSlotAppendChild(HostElement.prototype);
4621
+ patchSlotAppend(HostElement.prototype);
4622
+ patchSlotPrepend(HostElement.prototype);
4623
+ patchSlotInsertAdjacentHTML(HostElement.prototype);
4624
+ patchInsertBefore(HostElement.prototype);
4625
+ patchSlotRemoveChild(HostElement.prototype);
4626
+ }
4627
+ if (BUILD.slotTextContent) patchTextContent(HostElement.prototype);
4628
+ }
4629
+ if (BUILD.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated) HostElement.formAssociated = true;
4630
+ if (BUILD.hotModuleReplacement) HostElement.prototype["s-hmr"] = function(hmrVersionId) {
4631
+ hmrStart(this, cmpMeta, hmrVersionId);
4632
+ };
4633
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
4634
+ if (!exclude.includes(tagName) && !_reg.get(tagName)) {
4635
+ cmpTags.push(tagName);
4636
+ const proxied = proxyComponent(HostElement, cmpMeta, PROXY_FLAGS.isElementConstructor);
4637
+ proxied._registry = _reg;
4638
+ _reg.define(tagName, proxied);
4639
+ }
4640
+ });
4641
+ });
4642
+ if (cmpTags.length > 0) {
4643
+ if (BUILD.invisiblePrehydration && !BUILD.staticHydrationStyles && (BUILD.hydratedClass || BUILD.hydratedAttribute)) dataStyles.textContent += cmpTags.sort() + HYDRATED_CSS;
4644
+ if (dataStyles.innerHTML.length) {
4645
+ dataStyles.setAttribute("data-styles", "");
4646
+ const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
4647
+ if (nonce != null) dataStyles.setAttribute("nonce", nonce);
4648
+ head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
4649
+ }
4650
+ }
4651
+ isBootstrapping = false;
4652
+ if (deferredConnectedCallbacks.length) deferredConnectedCallbacks.map((host) => host.connectedCallback());
4653
+ else if (BUILD.profile) plt.jmp(() => appLoadFallback = setTimeout(appDidLoad, 30, "timeout"));
4654
+ else plt.jmp(() => appLoadFallback = setTimeout(appDidLoad, 30));
4655
+ endBootstrap();
4656
+ };
4657
+ //#endregion
4658
+ //#region src/runtime/fragment.ts
4659
+ const Fragment = (_, children) => children;
4660
+ //#endregion
4661
+ //#region src/runtime/host-listener.ts
4662
+ const addHostEventListeners = (elm, hostRef, listeners) => {
4663
+ if (BUILD.hostListener && listeners && win.document) listeners.map(([flags, name, method]) => {
4664
+ const target = BUILD.hostListenerTarget ? getHostListenerTarget(win.document, elm, flags) : elm;
4665
+ const handler = hostListenerProxy(hostRef, method);
4666
+ const opts = hostListenerOpts(flags);
4667
+ plt.ael(target, name, handler, opts);
4668
+ (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
4669
+ });
4670
+ };
4671
+ const hostListenerProxy = (hostRef, methodName) => (ev) => {
4672
+ try {
4673
+ if (BUILD.lazyLoad) if (hostRef.$flags$ & HOST_FLAGS.isListenReady) hostRef.$lazyInstance$?.[methodName](ev);
4674
+ else (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
4675
+ else hostRef.$hostElement$[methodName](ev);
4676
+ } catch (e) {
4677
+ consoleError(e, hostRef.$hostElement$);
4678
+ }
4679
+ };
4680
+ const getHostListenerTarget = (doc, elm, flags) => {
4681
+ if (BUILD.hostListenerTargetDocument && flags & LISTENER_FLAGS.TargetDocument) return doc;
4682
+ if (BUILD.hostListenerTargetWindow && flags & LISTENER_FLAGS.TargetWindow) return win;
4683
+ if (BUILD.hostListenerTargetBody && flags & LISTENER_FLAGS.TargetBody) return doc.body;
4684
+ return elm;
4685
+ };
4686
+ const hostListenerOpts = (flags) => supportsListenerOptions ? {
4687
+ passive: (flags & LISTENER_FLAGS.Passive) !== 0,
4688
+ capture: (flags & LISTENER_FLAGS.Capture) !== 0
4689
+ } : (flags & LISTENER_FLAGS.Capture) !== 0;
4690
+ //#endregion
4691
+ //#region src/runtime/mixin.ts
4692
+ const baseClass = BUILD.lazyLoad ? class {} : globalThis.HTMLElement || class {};
4693
+ function Mixin(...mixins) {
4694
+ return mixins.reduceRight((acc, mixin) => mixin(acc), baseClass);
4695
+ }
4696
+ //#endregion
4697
+ //#region src/runtime/nonce.ts
4698
+ /**
4699
+ * Assigns the given value to the nonce property on the runtime platform object.
4700
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
4701
+ * @param nonce The value to be assigned to the platform nonce property.
4702
+ * @returns void
4703
+ */
4704
+ const setNonce = (nonce) => plt.$nonce$ = nonce;
4705
+ //#endregion
4706
+ //#region src/runtime/platform-options.ts
4707
+ const setPlatformOptions = (opts) => Object.assign(plt, opts);
4708
+ //#endregion
4709
+ //#region src/runtime/render.ts
4710
+ /**
4711
+ * A WeakMap to persist HostRef objects across multiple render() calls to the
4712
+ * same container. This enables VNode diffing on re-renders - without it, each
4713
+ * call creates a fresh HostRef with no previous VNode, causing renderVdom to
4714
+ * replace the entire DOM subtree instead of patching only what changed.
4715
+ */
4716
+ const hostRefCache = /* @__PURE__ */ new WeakMap();
4717
+ /**
4718
+ * Method to render a virtual DOM tree to a container element.
4719
+ *
4720
+ * Supports efficient re-renders: calling `render()` again on the same container
4721
+ * will diff the new VNode tree against the previous one and only update what changed,
4722
+ * preserving existing DOM elements and their state.
4723
+ *
4724
+ * @example
4725
+ * ```tsx
4726
+ * import { render } from '@stencil/core';
4727
+ *
4728
+ * const vnode = (
4729
+ * <div>
4730
+ * <h1>Hello, world!</h1>
4731
+ * </div>
4732
+ * );
4733
+ * render(vnode, document.body);
4734
+ * ```
4735
+ *
4736
+ * @param vnode - The virtual DOM tree to render
4737
+ * @param container - The container element to render the virtual DOM tree to
4738
+ */
4739
+ function render(vnode, container) {
4740
+ let ref = hostRefCache.get(container);
4741
+ if (!ref) {
4742
+ ref = {
4743
+ $flags$: 0,
4744
+ $cmpMeta$: {
4745
+ $flags$: 0,
4746
+ $tagName$: container.tagName
4747
+ },
4748
+ $hostElement$: container
4749
+ };
4750
+ hostRefCache.set(container, ref);
4751
+ }
4752
+ renderVdom(ref, vnode);
4753
+ }
4754
+ //#endregion
4755
+ //#region src/runtime/tag-transform.ts
4756
+ let tagTransformer = void 0;
4757
+ /**
4758
+ * Transforms a tag name using the current tag transformer
4759
+ * @param tag - the tag to transform e.g. `my-tag`
4760
+ * @returns the transformed tag e.g. `new-my-tag`
4761
+ */
4762
+ function transformTag(tag) {
4763
+ if (!tagTransformer) return tag;
4764
+ return tagTransformer(tag);
4765
+ }
4766
+ /**
4767
+ * Sets the tag transformer to be used when rendering custom elements
4768
+ * @param transformer the transformer function to use. Must return a string
4769
+ */
4770
+ function setTagTransformer(transformer) {
4771
+ tagTransformer = transformer;
4772
+ }
4773
+ //#endregion
4774
+ //#region src/runtime/vdom/jsx-runtime.ts
4775
+ function jsx(type, props, key) {
4776
+ const { children, ...rest } = props ?? {};
4777
+ if (key !== void 0 && !("key" in rest)) rest.key = key;
4778
+ const attrs = hasKeys(rest) ? rest : null;
4779
+ if (children !== void 0) return Array.isArray(children) ? h(type, attrs, ...children) : h(type, attrs, children);
4780
+ return h(type, attrs);
4781
+ }
4782
+ /**
4783
+ * @alias
4784
+ */
4785
+ const jsxs = jsx;
4786
+ /**
4787
+ * @alias
4788
+ */
4789
+ const jsxDEV = jsx;
4790
+ function hasKeys(obj) {
4791
+ for (const _ in obj) return true;
4792
+ return false;
4793
+ }
4794
+ //#endregion
4795
+ export { Fragment, HYDRATED_STYLE_ID, Host, Mixin, addHostEventListeners, bootstrapLazy, connectedCallback, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, jsx, jsxDEV, jsxs, normalizeWatchers, parsePropertyValue, postUpdateComponent, proxyComponent, proxyCustomElement, render, setAssetPath, setMode, setNonce, setPlatformOptions, setRegistry, setTagTransformer, setValue, transformTag };