@oila/0account 3.4.7 → 3.4.8

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 (81) hide show
  1. package/dist/zero-account/app-globals-0f993ce5.js +5 -0
  2. package/dist/zero-account/app-globals-0f993ce5.js.map +1 -0
  3. package/dist/{collection/components/zero-account/enums.js → zero-account/enums-816340c2.js} +7 -4
  4. package/dist/zero-account/enums-816340c2.js.map +1 -0
  5. package/dist/zero-account/enums-e7827156.js +21 -0
  6. package/dist/zero-account/enums-e7827156.js.map +1 -0
  7. package/dist/zero-account/index-57856b47.js +3380 -0
  8. package/dist/zero-account/index-57856b47.js.map +1 -0
  9. package/dist/zero-account/index.esm.js +1 -0
  10. package/dist/zero-account/index.esm.js.map +1 -1
  11. package/dist/{collection/utils/qrcode/qrcode.js → zero-account/qr-code.entry.js} +35 -3
  12. package/dist/zero-account/qr-code.entry.js.map +1 -0
  13. package/dist/zero-account/shadow-css-8a6ccf47.js +389 -0
  14. package/dist/zero-account/shadow-css-8a6ccf47.js.map +1 -0
  15. package/dist/{components/zero-account.js → zero-account/zero-account.entry.js} +597 -58
  16. package/dist/zero-account/zero-account.entry.js.map +1 -0
  17. package/dist/zero-account/zero-account.esm.js +64 -1
  18. package/dist/zero-account/zero-account.esm.js.map +1 -1
  19. package/package.json +1 -1
  20. package/dist/cjs/index-1e526aba.js +0 -1645
  21. package/dist/cjs/index-1e526aba.js.map +0 -1
  22. package/dist/cjs/index.cjs.js +0 -4
  23. package/dist/cjs/index.cjs.js.map +0 -1
  24. package/dist/cjs/loader.cjs.js +0 -15
  25. package/dist/cjs/loader.cjs.js.map +0 -1
  26. package/dist/cjs/qr-code_2.cjs.entry.js +0 -2470
  27. package/dist/cjs/qr-code_2.cjs.entry.js.map +0 -1
  28. package/dist/cjs/zero-account.cjs.js +0 -25
  29. package/dist/cjs/zero-account.cjs.js.map +0 -1
  30. package/dist/collection/collection-manifest.json +0 -13
  31. package/dist/collection/components/zero-account/enums.js.map +0 -1
  32. package/dist/collection/components/zero-account/logo.js +0 -6
  33. package/dist/collection/components/zero-account/logo.js.map +0 -1
  34. package/dist/collection/components/zero-account/qrcode.js +0 -111
  35. package/dist/collection/components/zero-account/qrcode.js.map +0 -1
  36. package/dist/collection/components/zero-account/websocket.js +0 -175
  37. package/dist/collection/components/zero-account/websocket.js.map +0 -1
  38. package/dist/collection/components/zero-account/zero-account.css +0 -287
  39. package/dist/collection/components/zero-account/zero-account.e2e.js +0 -26
  40. package/dist/collection/components/zero-account/zero-account.e2e.js.map +0 -1
  41. package/dist/collection/components/zero-account/zero-account.js +0 -401
  42. package/dist/collection/components/zero-account/zero-account.js.map +0 -1
  43. package/dist/collection/components/zero-account/zero-account.spec.js +0 -35
  44. package/dist/collection/components/zero-account/zero-account.spec.js.map +0 -1
  45. package/dist/collection/index.js +0 -2
  46. package/dist/collection/index.js.map +0 -1
  47. package/dist/collection/utils/request.js +0 -38
  48. package/dist/collection/utils/request.js.map +0 -1
  49. package/dist/collection/utils/url.js +0 -43
  50. package/dist/collection/utils/utils.js +0 -16
  51. package/dist/collection/utils/utils.js.map +0 -1
  52. package/dist/collection/utils/utils.spec.js +0 -10
  53. package/dist/collection/utils/utils.spec.js.map +0 -1
  54. package/dist/components/index.js +0 -3
  55. package/dist/components/index.js.map +0 -1
  56. package/dist/components/qr-code.js +0 -8
  57. package/dist/components/qr-code.js.map +0 -1
  58. package/dist/components/qrcode.js +0 -1073
  59. package/dist/components/qrcode.js.map +0 -1
  60. package/dist/components/zero-account.js.map +0 -1
  61. package/dist/esm/index-09024c20.js +0 -1616
  62. package/dist/esm/index-09024c20.js.map +0 -1
  63. package/dist/esm/index.js +0 -3
  64. package/dist/esm/index.js.map +0 -1
  65. package/dist/esm/loader.js +0 -11
  66. package/dist/esm/loader.js.map +0 -1
  67. package/dist/esm/polyfills/core-js.js +0 -11
  68. package/dist/esm/polyfills/dom.js +0 -79
  69. package/dist/esm/polyfills/es5-html-element.js +0 -1
  70. package/dist/esm/polyfills/index.js +0 -34
  71. package/dist/esm/polyfills/system.js +0 -6
  72. package/dist/esm/qr-code_2.entry.js +0 -2465
  73. package/dist/esm/qr-code_2.entry.js.map +0 -1
  74. package/dist/esm/zero-account.js +0 -20
  75. package/dist/esm/zero-account.js.map +0 -1
  76. package/dist/index.cjs.js +0 -1
  77. package/dist/index.js +0 -1
  78. package/dist/zero-account/p-21f4994d.js +0 -3
  79. package/dist/zero-account/p-21f4994d.js.map +0 -1
  80. package/dist/zero-account/p-a29dc444.entry.js +0 -2
  81. package/dist/zero-account/p-a29dc444.entry.js.map +0 -1
@@ -0,0 +1,3380 @@
1
+ const NAMESPACE = 'zero-account';
2
+ const BUILD = /* zero-account */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: false, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: true, constructableCSS: false, cssAnnotations: true, devTools: true, disconnectedCallback: true, element: false, event: false, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: false, hostListenerTargetDocument: true, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: true, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: true, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: false, mode: false, observeAttribute: true, profile: true, prop: true, propBoolean: true, propMutable: false, propNumber: true, propString: true, reflect: false, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, slot: true, slotChildNodesFix: false, slotRelocation: false, state: true, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: false, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: false };
3
+ const Env = /* zero-account */ {};
4
+
5
+ /**
6
+ * Virtual DOM patching algorithm based on Snabbdom by
7
+ * Simon Friis Vindum (@paldepind)
8
+ * Licensed under the MIT License
9
+ * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
10
+ *
11
+ * Modified for Stencil's renderer and slot projection
12
+ */
13
+ let scopeId;
14
+ let contentRef;
15
+ let hostTagName;
16
+ let customError;
17
+ let i = 0;
18
+ let useNativeShadowDom = false;
19
+ let checkSlotFallbackVisibility = false;
20
+ let checkSlotRelocate = false;
21
+ let isSvgMode = false;
22
+ let renderingRef = null;
23
+ let queueCongestion = 0;
24
+ let queuePending = false;
25
+ const Build = {
26
+ isDev: BUILD.isDev ? true : false,
27
+ isBrowser: true,
28
+ isServer: false,
29
+ isTesting: BUILD.isTesting ? true : false,
30
+ };
31
+ const getAssetPath = (path) => {
32
+ const assetUrl = new URL(path, plt.$resourcesUrl$);
33
+ return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
34
+ };
35
+ const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
36
+ const createTime = (fnName, tagName = '') => {
37
+ if (BUILD.profile && performance.mark) {
38
+ const key = `st:${fnName}:${tagName}:${i++}`;
39
+ // Start
40
+ performance.mark(key);
41
+ // End
42
+ return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
43
+ }
44
+ else {
45
+ return () => {
46
+ return;
47
+ };
48
+ }
49
+ };
50
+ const uniqueTime = (key, measureText) => {
51
+ if (BUILD.profile && performance.mark) {
52
+ if (performance.getEntriesByName(key, 'mark').length === 0) {
53
+ performance.mark(key);
54
+ }
55
+ return () => {
56
+ if (performance.getEntriesByName(measureText, 'measure').length === 0) {
57
+ performance.measure(measureText, key);
58
+ }
59
+ };
60
+ }
61
+ else {
62
+ return () => {
63
+ return;
64
+ };
65
+ }
66
+ };
67
+ const inspect = (ref) => {
68
+ const hostRef = getHostRef(ref);
69
+ if (!hostRef) {
70
+ return undefined;
71
+ }
72
+ const flags = hostRef.$flags$;
73
+ const hostElement = hostRef.$hostElement$;
74
+ return {
75
+ renderCount: hostRef.$renderCount$,
76
+ flags: {
77
+ hasRendered: !!(flags & 2 /* HOST_FLAGS.hasRendered */),
78
+ hasConnected: !!(flags & 1 /* HOST_FLAGS.hasConnected */),
79
+ isWaitingForChildren: !!(flags & 4 /* HOST_FLAGS.isWaitingForChildren */),
80
+ isConstructingInstance: !!(flags & 8 /* HOST_FLAGS.isConstructingInstance */),
81
+ isQueuedForUpdate: !!(flags & 16 /* HOST_FLAGS.isQueuedForUpdate */),
82
+ hasInitializedComponent: !!(flags & 32 /* HOST_FLAGS.hasInitializedComponent */),
83
+ hasLoadedComponent: !!(flags & 64 /* HOST_FLAGS.hasLoadedComponent */),
84
+ isWatchReady: !!(flags & 128 /* HOST_FLAGS.isWatchReady */),
85
+ isListenReady: !!(flags & 256 /* HOST_FLAGS.isListenReady */),
86
+ needsRerender: !!(flags & 512 /* HOST_FLAGS.needsRerender */),
87
+ },
88
+ instanceValues: hostRef.$instanceValues$,
89
+ ancestorComponent: hostRef.$ancestorComponent$,
90
+ hostElement,
91
+ lazyInstance: hostRef.$lazyInstance$,
92
+ vnode: hostRef.$vnode$,
93
+ modeName: hostRef.$modeName$,
94
+ onReadyPromise: hostRef.$onReadyPromise$,
95
+ onReadyResolve: hostRef.$onReadyResolve$,
96
+ onInstancePromise: hostRef.$onInstancePromise$,
97
+ onInstanceResolve: hostRef.$onInstanceResolve$,
98
+ onRenderResolve: hostRef.$onRenderResolve$,
99
+ queuedListeners: hostRef.$queuedListeners$,
100
+ rmListeners: hostRef.$rmListeners$,
101
+ ['s-id']: hostElement['s-id'],
102
+ ['s-cr']: hostElement['s-cr'],
103
+ ['s-lr']: hostElement['s-lr'],
104
+ ['s-p']: hostElement['s-p'],
105
+ ['s-rc']: hostElement['s-rc'],
106
+ ['s-sc']: hostElement['s-sc'],
107
+ };
108
+ };
109
+ const installDevTools = () => {
110
+ if (BUILD.devTools) {
111
+ const stencil = (win.stencil = win.stencil || {});
112
+ const originalInspect = stencil.inspect;
113
+ stencil.inspect = (ref) => {
114
+ let result = inspect(ref);
115
+ if (!result && typeof originalInspect === 'function') {
116
+ result = originalInspect(ref);
117
+ }
118
+ return result;
119
+ };
120
+ }
121
+ };
122
+ const CONTENT_REF_ID = 'r';
123
+ const ORG_LOCATION_ID = 'o';
124
+ const SLOT_NODE_ID = 's';
125
+ const TEXT_NODE_ID = 't';
126
+ const HYDRATE_ID = 's-id';
127
+ const HYDRATED_STYLE_ID = 'sty-id';
128
+ const HYDRATE_CHILD_ID = 'c-id';
129
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
130
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
131
+ /**
132
+ * Default style mode id
133
+ */
134
+ /**
135
+ * Reusable empty obj/array
136
+ * Don't add values to these!!
137
+ */
138
+ const EMPTY_OBJ = {};
139
+ /**
140
+ * Namespaces
141
+ */
142
+ const SVG_NS = 'http://www.w3.org/2000/svg';
143
+ const HTML_NS = 'http://www.w3.org/1999/xhtml';
144
+ const isDef = (v) => v != null;
145
+ /**
146
+ * Check whether a value is a 'complex type', defined here as an object or a
147
+ * function.
148
+ *
149
+ * @param o the value to check
150
+ * @returns whether it's a complex type or not
151
+ */
152
+ const isComplexType = (o) => {
153
+ // https://jsperf.com/typeof-fn-object/5
154
+ o = typeof o;
155
+ return o === 'object' || o === 'function';
156
+ };
157
+ /**
158
+ * Helper method for querying a `meta` tag that contains a nonce value
159
+ * out of a DOM's head.
160
+ *
161
+ * @param doc The DOM containing the `head` to query against
162
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
163
+ * exists or the tag has no content.
164
+ */
165
+ function queryNonceMetaTagContent(doc) {
166
+ var _a, _b, _c;
167
+ return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
168
+ }
169
+ /**
170
+ * Production h() function based on Preact by
171
+ * Jason Miller (@developit)
172
+ * Licensed under the MIT License
173
+ * https://github.com/developit/preact/blob/master/LICENSE
174
+ *
175
+ * Modified for Stencil's compiler and vdom
176
+ */
177
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
178
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
179
+ const h = (nodeName, vnodeData, ...children) => {
180
+ let child = null;
181
+ let key = null;
182
+ let slotName = null;
183
+ let simple = false;
184
+ let lastSimple = false;
185
+ const vNodeChildren = [];
186
+ const walk = (c) => {
187
+ for (let i = 0; i < c.length; i++) {
188
+ child = c[i];
189
+ if (Array.isArray(child)) {
190
+ walk(child);
191
+ }
192
+ else if (child != null && typeof child !== 'boolean') {
193
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
194
+ child = String(child);
195
+ }
196
+ else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
197
+ consoleDevError(`vNode passed as children has unexpected type.
198
+ Make sure it's using the correct h() function.
199
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
200
+ }
201
+ if (simple && lastSimple) {
202
+ // If the previous child was simple (string), we merge both
203
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
204
+ }
205
+ else {
206
+ // Append a new vNode, if it's text, we create a text vNode
207
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
208
+ }
209
+ lastSimple = simple;
210
+ }
211
+ }
212
+ };
213
+ walk(children);
214
+ if (vnodeData) {
215
+ if (BUILD.isDev && nodeName === 'input') {
216
+ validateInputProperties(vnodeData);
217
+ }
218
+ // normalize class / classname attributes
219
+ if (BUILD.vdomKey && vnodeData.key) {
220
+ key = vnodeData.key;
221
+ }
222
+ if (BUILD.slotRelocation && vnodeData.name) {
223
+ slotName = vnodeData.name;
224
+ }
225
+ if (BUILD.vdomClass) {
226
+ const classData = vnodeData.className || vnodeData.class;
227
+ if (classData) {
228
+ vnodeData.class =
229
+ typeof classData !== 'object'
230
+ ? classData
231
+ : Object.keys(classData)
232
+ .filter((k) => classData[k])
233
+ .join(' ');
234
+ }
235
+ }
236
+ }
237
+ if (BUILD.isDev && vNodeChildren.some(isHost)) {
238
+ consoleDevError(`The <Host> must be the single root component. Make sure:
239
+ - You are NOT using hostData() and <Host> in the same component.
240
+ - <Host> is used once, and it's the single root component of the render() function.`);
241
+ }
242
+ if (BUILD.vdomFunctional && typeof nodeName === 'function') {
243
+ // nodeName is a functional component
244
+ return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
245
+ }
246
+ const vnode = newVNode(nodeName, null);
247
+ vnode.$attrs$ = vnodeData;
248
+ if (vNodeChildren.length > 0) {
249
+ vnode.$children$ = vNodeChildren;
250
+ }
251
+ if (BUILD.vdomKey) {
252
+ vnode.$key$ = key;
253
+ }
254
+ if (BUILD.slotRelocation) {
255
+ vnode.$name$ = slotName;
256
+ }
257
+ return vnode;
258
+ };
259
+ /**
260
+ * A utility function for creating a virtual DOM node from a tag and some
261
+ * possible text content.
262
+ *
263
+ * @param tag the tag for this element
264
+ * @param text possible text content for the node
265
+ * @returns a newly-minted virtual DOM node
266
+ */
267
+ const newVNode = (tag, text) => {
268
+ const vnode = {
269
+ $flags$: 0,
270
+ $tag$: tag,
271
+ $text$: text,
272
+ $elm$: null,
273
+ $children$: null,
274
+ };
275
+ if (BUILD.vdomAttribute) {
276
+ vnode.$attrs$ = null;
277
+ }
278
+ if (BUILD.vdomKey) {
279
+ vnode.$key$ = null;
280
+ }
281
+ if (BUILD.slotRelocation) {
282
+ vnode.$name$ = null;
283
+ }
284
+ return vnode;
285
+ };
286
+ const Host = {};
287
+ /**
288
+ * Check whether a given node is a Host node or not
289
+ *
290
+ * @param node the virtual DOM node to check
291
+ * @returns whether it's a Host node or not
292
+ */
293
+ const isHost = (node) => node && node.$tag$ === Host;
294
+ /**
295
+ * Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
296
+ *
297
+ * Note that these functions convert from {@link d.VNode} to
298
+ * {@link d.ChildNode} to give functional component developers a friendly
299
+ * interface.
300
+ */
301
+ const vdomFnUtils = {
302
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
303
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
304
+ };
305
+ /**
306
+ * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
307
+ * friendlier public interface (hence, 'convertToPublic').
308
+ *
309
+ * @param node the virtual DOM node to convert
310
+ * @returns a converted child node
311
+ */
312
+ const convertToPublic = (node) => ({
313
+ vattrs: node.$attrs$,
314
+ vchildren: node.$children$,
315
+ vkey: node.$key$,
316
+ vname: node.$name$,
317
+ vtag: node.$tag$,
318
+ vtext: node.$text$,
319
+ });
320
+ /**
321
+ * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
322
+ * order to use the resulting object in the virtual DOM. The initial object was
323
+ * likely created as part of presenting a public API, so converting it back
324
+ * involved making it 'private' again (hence, `convertToPrivate`).
325
+ *
326
+ * @param node the child node to convert
327
+ * @returns a converted virtual DOM node
328
+ */
329
+ const convertToPrivate = (node) => {
330
+ if (typeof node.vtag === 'function') {
331
+ const vnodeData = Object.assign({}, node.vattrs);
332
+ if (node.vkey) {
333
+ vnodeData.key = node.vkey;
334
+ }
335
+ if (node.vname) {
336
+ vnodeData.name = node.vname;
337
+ }
338
+ return h(node.vtag, vnodeData, ...(node.vchildren || []));
339
+ }
340
+ const vnode = newVNode(node.vtag, node.vtext);
341
+ vnode.$attrs$ = node.vattrs;
342
+ vnode.$children$ = node.vchildren;
343
+ vnode.$key$ = node.vkey;
344
+ vnode.$name$ = node.vname;
345
+ return vnode;
346
+ };
347
+ /**
348
+ * Validates the ordering of attributes on an input element
349
+ *
350
+ * @param inputElm the element to validate
351
+ */
352
+ const validateInputProperties = (inputElm) => {
353
+ const props = Object.keys(inputElm);
354
+ const value = props.indexOf('value');
355
+ if (value === -1) {
356
+ return;
357
+ }
358
+ const typeIndex = props.indexOf('type');
359
+ const minIndex = props.indexOf('min');
360
+ const maxIndex = props.indexOf('max');
361
+ const stepIndex = props.indexOf('step');
362
+ if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
363
+ consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
364
+ }
365
+ };
366
+ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
367
+ const endHydrate = createTime('hydrateClient', tagName);
368
+ const shadowRoot = hostElm.shadowRoot;
369
+ const childRenderNodes = [];
370
+ const slotNodes = [];
371
+ const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
372
+ const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
373
+ if (!plt.$orgLocNodes$) {
374
+ initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
375
+ }
376
+ hostElm[HYDRATE_ID] = hostId;
377
+ hostElm.removeAttribute(HYDRATE_ID);
378
+ clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
379
+ childRenderNodes.map((c) => {
380
+ const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
381
+ const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
382
+ const node = c.$elm$;
383
+ if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
384
+ orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
385
+ }
386
+ if (!shadowRoot) {
387
+ node['s-hn'] = tagName;
388
+ if (orgLocationNode) {
389
+ node['s-ol'] = orgLocationNode;
390
+ node['s-ol']['s-nr'] = node;
391
+ }
392
+ }
393
+ plt.$orgLocNodes$.delete(orgLocationId);
394
+ });
395
+ if (BUILD.shadowDom && shadowRoot) {
396
+ shadowRootNodes.map((shadowRootNode) => {
397
+ if (shadowRootNode) {
398
+ shadowRoot.appendChild(shadowRootNode);
399
+ }
400
+ });
401
+ }
402
+ endHydrate();
403
+ };
404
+ const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
405
+ let childNodeType;
406
+ let childIdSplt;
407
+ let childVNode;
408
+ let i;
409
+ if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
410
+ childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
411
+ if (childNodeType) {
412
+ // got the node data from the element's attribute
413
+ // `${hostId}.${nodeId}.${depth}.${index}`
414
+ childIdSplt = childNodeType.split('.');
415
+ if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
416
+ childVNode = {
417
+ $flags$: 0,
418
+ $hostId$: childIdSplt[0],
419
+ $nodeId$: childIdSplt[1],
420
+ $depth$: childIdSplt[2],
421
+ $index$: childIdSplt[3],
422
+ $tag$: node.tagName.toLowerCase(),
423
+ $elm$: node,
424
+ $attrs$: null,
425
+ $children$: null,
426
+ $key$: null,
427
+ $name$: null,
428
+ $text$: null,
429
+ };
430
+ childRenderNodes.push(childVNode);
431
+ node.removeAttribute(HYDRATE_CHILD_ID);
432
+ // this is a new child vnode
433
+ // so ensure its parent vnode has the vchildren array
434
+ if (!parentVNode.$children$) {
435
+ parentVNode.$children$ = [];
436
+ }
437
+ // add our child vnode to a specific index of the vnode's children
438
+ parentVNode.$children$[childVNode.$index$] = childVNode;
439
+ // this is now the new parent vnode for all the next child checks
440
+ parentVNode = childVNode;
441
+ if (shadowRootNodes && childVNode.$depth$ === '0') {
442
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
443
+ }
444
+ }
445
+ }
446
+ // recursively drill down, end to start so we can remove nodes
447
+ for (i = node.childNodes.length - 1; i >= 0; i--) {
448
+ clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
449
+ }
450
+ if (node.shadowRoot) {
451
+ // keep drilling down through the shadow root nodes
452
+ for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
453
+ clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
454
+ }
455
+ }
456
+ }
457
+ else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
458
+ // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
459
+ childIdSplt = node.nodeValue.split('.');
460
+ if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
461
+ // comment node for either the host id or a 0 host id
462
+ childNodeType = childIdSplt[0];
463
+ childVNode = {
464
+ $flags$: 0,
465
+ $hostId$: childIdSplt[1],
466
+ $nodeId$: childIdSplt[2],
467
+ $depth$: childIdSplt[3],
468
+ $index$: childIdSplt[4],
469
+ $elm$: node,
470
+ $attrs$: null,
471
+ $children$: null,
472
+ $key$: null,
473
+ $name$: null,
474
+ $tag$: null,
475
+ $text$: null,
476
+ };
477
+ if (childNodeType === TEXT_NODE_ID) {
478
+ childVNode.$elm$ = node.nextSibling;
479
+ if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* NODE_TYPE.TextNode */) {
480
+ childVNode.$text$ = childVNode.$elm$.textContent;
481
+ childRenderNodes.push(childVNode);
482
+ // remove the text comment since it's no longer needed
483
+ node.remove();
484
+ if (!parentVNode.$children$) {
485
+ parentVNode.$children$ = [];
486
+ }
487
+ parentVNode.$children$[childVNode.$index$] = childVNode;
488
+ if (shadowRootNodes && childVNode.$depth$ === '0') {
489
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
490
+ }
491
+ }
492
+ }
493
+ else if (childVNode.$hostId$ === hostId) {
494
+ // this comment node is specifcally for this host id
495
+ if (childNodeType === SLOT_NODE_ID) {
496
+ // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
497
+ childVNode.$tag$ = 'slot';
498
+ if (childIdSplt[5]) {
499
+ node['s-sn'] = childVNode.$name$ = childIdSplt[5];
500
+ }
501
+ else {
502
+ node['s-sn'] = '';
503
+ }
504
+ node['s-sr'] = true;
505
+ if (BUILD.shadowDom && shadowRootNodes) {
506
+ // browser support shadowRoot and this is a shadow dom component
507
+ // create an actual slot element
508
+ childVNode.$elm$ = doc.createElement(childVNode.$tag$);
509
+ if (childVNode.$name$) {
510
+ // add the slot name attribute
511
+ childVNode.$elm$.setAttribute('name', childVNode.$name$);
512
+ }
513
+ // insert the new slot element before the slot comment
514
+ node.parentNode.insertBefore(childVNode.$elm$, node);
515
+ // remove the slot comment since it's not needed for shadow
516
+ node.remove();
517
+ if (childVNode.$depth$ === '0') {
518
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
519
+ }
520
+ }
521
+ slotNodes.push(childVNode);
522
+ if (!parentVNode.$children$) {
523
+ parentVNode.$children$ = [];
524
+ }
525
+ parentVNode.$children$[childVNode.$index$] = childVNode;
526
+ }
527
+ else if (childNodeType === CONTENT_REF_ID) {
528
+ // `${CONTENT_REF_ID}.${hostId}`;
529
+ if (BUILD.shadowDom && shadowRootNodes) {
530
+ // remove the content ref comment since it's not needed for shadow
531
+ node.remove();
532
+ }
533
+ else if (BUILD.slotRelocation) {
534
+ hostElm['s-cr'] = node;
535
+ node['s-cn'] = true;
536
+ }
537
+ }
538
+ }
539
+ }
540
+ }
541
+ else if (parentVNode && parentVNode.$tag$ === 'style') {
542
+ const vnode = newVNode(null, node.textContent);
543
+ vnode.$elm$ = node;
544
+ vnode.$index$ = '0';
545
+ parentVNode.$children$ = [vnode];
546
+ }
547
+ };
548
+ const initializeDocumentHydrate = (node, orgLocNodes) => {
549
+ if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
550
+ let i = 0;
551
+ for (; i < node.childNodes.length; i++) {
552
+ initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
553
+ }
554
+ if (node.shadowRoot) {
555
+ for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
556
+ initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
557
+ }
558
+ }
559
+ }
560
+ else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
561
+ const childIdSplt = node.nodeValue.split('.');
562
+ if (childIdSplt[0] === ORG_LOCATION_ID) {
563
+ orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
564
+ node.nodeValue = '';
565
+ // useful to know if the original location is
566
+ // the root light-dom of a shadow dom component
567
+ node['s-en'] = childIdSplt[3];
568
+ }
569
+ }
570
+ };
571
+ // Private
572
+ const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
573
+ // Public
574
+ const setMode = (handler) => modeResolutionChain.push(handler);
575
+ const getMode = (ref) => getHostRef(ref).$modeName$;
576
+ /**
577
+ * Parse a new property value for a given property type.
578
+ *
579
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
580
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
581
+ * 1. `any`, the type given to `propValue` in the function signature
582
+ * 2. the type stored from `propType`.
583
+ *
584
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
585
+ *
586
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
587
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
588
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
589
+ * ```tsx
590
+ * <my-cmp prop-val={0}></my-cmp>
591
+ * ```
592
+ *
593
+ * HTML prop values on the other hand, will always a string
594
+ *
595
+ * @param propValue the new value to coerce to some type
596
+ * @param propType the type of the prop, expressed as a binary number
597
+ * @returns the parsed/coerced value
598
+ */
599
+ const parsePropertyValue = (propValue, propType) => {
600
+ // ensure this value is of the correct prop type
601
+ if (propValue != null && !isComplexType(propValue)) {
602
+ if (BUILD.propBoolean && propType & 4 /* MEMBER_FLAGS.Boolean */) {
603
+ // per the HTML spec, any string value means it is a boolean true value
604
+ // but we'll cheat here and say that the string "false" is the boolean false
605
+ return propValue === 'false' ? false : propValue === '' || !!propValue;
606
+ }
607
+ if (BUILD.propNumber && propType & 2 /* MEMBER_FLAGS.Number */) {
608
+ // force it to be a number
609
+ return parseFloat(propValue);
610
+ }
611
+ if (BUILD.propString && propType & 1 /* MEMBER_FLAGS.String */) {
612
+ // could have been passed as a number or boolean
613
+ // but we still want it as a string
614
+ return String(propValue);
615
+ }
616
+ // redundant return here for better minification
617
+ return propValue;
618
+ }
619
+ // not sure exactly what type we want
620
+ // so no need to change to a different type
621
+ return propValue;
622
+ };
623
+ const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
624
+ const createEvent = (ref, name, flags) => {
625
+ const elm = getElement(ref);
626
+ return {
627
+ emit: (detail) => {
628
+ if (BUILD.isDev && !elm.isConnected) {
629
+ consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
630
+ }
631
+ return emitEvent(elm, name, {
632
+ bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
633
+ composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
634
+ cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
635
+ detail,
636
+ });
637
+ },
638
+ };
639
+ };
640
+ /**
641
+ * Helper function to create & dispatch a custom Event on a provided target
642
+ * @param elm the target of the Event
643
+ * @param name the name to give the custom Event
644
+ * @param opts options for configuring a custom Event
645
+ * @returns the custom Event
646
+ */
647
+ const emitEvent = (elm, name, opts) => {
648
+ const ev = plt.ce(name, opts);
649
+ elm.dispatchEvent(ev);
650
+ return ev;
651
+ };
652
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
653
+ const registerStyle = (scopeId, cssText, allowCS) => {
654
+ let style = styles.get(scopeId);
655
+ if (supportsConstructableStylesheets && allowCS) {
656
+ style = (style || new CSSStyleSheet());
657
+ if (typeof style === 'string') {
658
+ style = cssText;
659
+ }
660
+ else {
661
+ style.replaceSync(cssText);
662
+ }
663
+ }
664
+ else {
665
+ style = cssText;
666
+ }
667
+ styles.set(scopeId, style);
668
+ };
669
+ const addStyle = (styleContainerNode, cmpMeta, mode) => {
670
+ var _a;
671
+ const scopeId = getScopeId(cmpMeta, mode);
672
+ const style = styles.get(scopeId);
673
+ if (!BUILD.attachStyles) {
674
+ return scopeId;
675
+ }
676
+ // if an element is NOT connected then getRootNode() will return the wrong root node
677
+ // so the fallback is to always use the document for the root node in those cases
678
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
679
+ if (style) {
680
+ if (typeof style === 'string') {
681
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
682
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
683
+ let styleElm;
684
+ if (!appliedStyles) {
685
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
686
+ }
687
+ if (!appliedStyles.has(scopeId)) {
688
+ if (BUILD.hydrateClientSide &&
689
+ styleContainerNode.host &&
690
+ (styleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`))) {
691
+ // This is only happening on native shadow-dom, do not needs CSS var shim
692
+ styleElm.innerHTML = style;
693
+ }
694
+ else {
695
+ styleElm = doc.createElement('style');
696
+ styleElm.innerHTML = style;
697
+ // Apply CSP nonce to the style tag if it exists
698
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
699
+ if (nonce != null) {
700
+ styleElm.setAttribute('nonce', nonce);
701
+ }
702
+ if (BUILD.hydrateServerSide || BUILD.hotModuleReplacement) {
703
+ styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
704
+ }
705
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
706
+ }
707
+ if (appliedStyles) {
708
+ appliedStyles.add(scopeId);
709
+ }
710
+ }
711
+ }
712
+ else if (BUILD.constructableCSS && !styleContainerNode.adoptedStyleSheets.includes(style)) {
713
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
714
+ }
715
+ }
716
+ return scopeId;
717
+ };
718
+ const attachStyles = (hostRef) => {
719
+ const cmpMeta = hostRef.$cmpMeta$;
720
+ const elm = hostRef.$hostElement$;
721
+ const flags = cmpMeta.$flags$;
722
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
723
+ const scopeId = addStyle(BUILD.shadowDom && supportsShadow && elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$);
724
+ if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
725
+ // only required when we're NOT using native shadow dom (slot)
726
+ // or this browser doesn't support native shadow dom
727
+ // and this host element was NOT created with SSR
728
+ // let's pick out the inner content for slot projection
729
+ // create a node to represent where the original
730
+ // content was first placed, which is useful later on
731
+ // DOM WRITE!!
732
+ elm['s-sc'] = scopeId;
733
+ elm.classList.add(scopeId + '-h');
734
+ if (BUILD.scoped && flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
735
+ elm.classList.add(scopeId + '-s');
736
+ }
737
+ }
738
+ endAttachStyles();
739
+ };
740
+ const getScopeId = (cmp, mode) => 'sc-' + (BUILD.mode && mode && cmp.$flags$ & 32 /* CMP_FLAGS.hasMode */ ? cmp.$tagName$ + '-' + mode : cmp.$tagName$);
741
+ const convertScopedToShadow = (css) => css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{');
742
+ /**
743
+ * Production setAccessor() function based on Preact by
744
+ * Jason Miller (@developit)
745
+ * Licensed under the MIT License
746
+ * https://github.com/developit/preact/blob/master/LICENSE
747
+ *
748
+ * Modified for Stencil's compiler and vdom
749
+ */
750
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
751
+ if (oldValue !== newValue) {
752
+ let isProp = isMemberInElement(elm, memberName);
753
+ let ln = memberName.toLowerCase();
754
+ if (BUILD.vdomClass && memberName === 'class') {
755
+ const classList = elm.classList;
756
+ const oldClasses = parseClassList(oldValue);
757
+ const newClasses = parseClassList(newValue);
758
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
759
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
760
+ }
761
+ else if (BUILD.vdomStyle && memberName === 'style') {
762
+ // update style attribute, css properties and values
763
+ if (BUILD.updatable) {
764
+ for (const prop in oldValue) {
765
+ if (!newValue || newValue[prop] == null) {
766
+ if (!BUILD.hydrateServerSide && prop.includes('-')) {
767
+ elm.style.removeProperty(prop);
768
+ }
769
+ else {
770
+ elm.style[prop] = '';
771
+ }
772
+ }
773
+ }
774
+ }
775
+ for (const prop in newValue) {
776
+ if (!oldValue || newValue[prop] !== oldValue[prop]) {
777
+ if (!BUILD.hydrateServerSide && prop.includes('-')) {
778
+ elm.style.setProperty(prop, newValue[prop]);
779
+ }
780
+ else {
781
+ elm.style[prop] = newValue[prop];
782
+ }
783
+ }
784
+ }
785
+ }
786
+ else if (BUILD.vdomKey && memberName === 'key')
787
+ ;
788
+ else if (BUILD.vdomRef && memberName === 'ref') {
789
+ // minifier will clean this up
790
+ if (newValue) {
791
+ newValue(elm);
792
+ }
793
+ }
794
+ else if (BUILD.vdomListener &&
795
+ (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) &&
796
+ memberName[0] === 'o' &&
797
+ memberName[1] === 'n') {
798
+ // Event Handlers
799
+ // so if the member name starts with "on" and the 3rd characters is
800
+ // a capital letter, and it's not already a member on the element,
801
+ // then we're assuming it's an event listener
802
+ if (memberName[2] === '-') {
803
+ // on- prefixed events
804
+ // allows to be explicit about the dom event to listen without any magic
805
+ // under the hood:
806
+ // <my-cmp on-click> // listens for "click"
807
+ // <my-cmp on-Click> // listens for "Click"
808
+ // <my-cmp on-ionChange> // listens for "ionChange"
809
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
810
+ memberName = memberName.slice(3);
811
+ }
812
+ else if (isMemberInElement(win, ln)) {
813
+ // standard event
814
+ // the JSX attribute could have been "onMouseOver" and the
815
+ // member name "onmouseover" is on the window's prototype
816
+ // so let's add the listener "mouseover", which is all lowercased
817
+ memberName = ln.slice(2);
818
+ }
819
+ else {
820
+ // custom event
821
+ // the JSX attribute could have been "onMyCustomEvent"
822
+ // so let's trim off the "on" prefix and lowercase the first character
823
+ // and add the listener "myCustomEvent"
824
+ // except for the first character, we keep the event name case
825
+ memberName = ln[2] + memberName.slice(3);
826
+ }
827
+ if (oldValue) {
828
+ plt.rel(elm, memberName, oldValue, false);
829
+ }
830
+ if (newValue) {
831
+ plt.ael(elm, memberName, newValue, false);
832
+ }
833
+ }
834
+ else if (BUILD.vdomPropOrAttr) {
835
+ // Set property if it exists and it's not a SVG
836
+ const isComplex = isComplexType(newValue);
837
+ if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
838
+ try {
839
+ if (!elm.tagName.includes('-')) {
840
+ const n = newValue == null ? '' : newValue;
841
+ // Workaround for Safari, moving the <input> caret when re-assigning the same valued
842
+ if (memberName === 'list') {
843
+ isProp = false;
844
+ }
845
+ else if (oldValue == null || elm[memberName] != n) {
846
+ elm[memberName] = n;
847
+ }
848
+ }
849
+ else {
850
+ elm[memberName] = newValue;
851
+ }
852
+ }
853
+ catch (e) { }
854
+ }
855
+ /**
856
+ * Need to manually update attribute if:
857
+ * - memberName is not an attribute
858
+ * - if we are rendering the host element in order to reflect attribute
859
+ * - if it's a SVG, since properties might not work in <svg>
860
+ * - if the newValue is null/undefined or 'false'.
861
+ */
862
+ let xlink = false;
863
+ if (BUILD.vdomXlink) {
864
+ if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
865
+ memberName = ln;
866
+ xlink = true;
867
+ }
868
+ }
869
+ if (newValue == null || newValue === false) {
870
+ if (newValue !== false || elm.getAttribute(memberName) === '') {
871
+ if (BUILD.vdomXlink && xlink) {
872
+ elm.removeAttributeNS(XLINK_NS, memberName);
873
+ }
874
+ else {
875
+ elm.removeAttribute(memberName);
876
+ }
877
+ }
878
+ }
879
+ else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
880
+ newValue = newValue === true ? '' : newValue;
881
+ if (BUILD.vdomXlink && xlink) {
882
+ elm.setAttributeNS(XLINK_NS, memberName, newValue);
883
+ }
884
+ else {
885
+ elm.setAttribute(memberName, newValue);
886
+ }
887
+ }
888
+ }
889
+ }
890
+ };
891
+ const parseClassListRegex = /\s/;
892
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
893
+ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
894
+ // if the element passed in is a shadow root, which is a document fragment
895
+ // then we want to be adding attrs/props to the shadow root's "host" element
896
+ // if it's not a shadow root, then we add attrs/props to the same element
897
+ const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
898
+ ? newVnode.$elm$.host
899
+ : newVnode.$elm$;
900
+ const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
901
+ const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
902
+ if (BUILD.updatable) {
903
+ // remove attributes no longer present on the vnode by setting them to undefined
904
+ for (memberName in oldVnodeAttrs) {
905
+ if (!(memberName in newVnodeAttrs)) {
906
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
907
+ }
908
+ }
909
+ }
910
+ // add new & update changed attributes
911
+ for (memberName in newVnodeAttrs) {
912
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
913
+ }
914
+ };
915
+ /**
916
+ * Create a DOM Node corresponding to one of the children of a given VNode.
917
+ *
918
+ * @param oldParentVNode the parent VNode from the previous render
919
+ * @param newParentVNode the parent VNode from the current render
920
+ * @param childIndex the index of the VNode, in the _new_ parent node's
921
+ * children, for which we will create a new DOM node
922
+ * @param parentElm the parent DOM node which our new node will be a child of
923
+ * @returns the newly created node
924
+ */
925
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
926
+ // tslint:disable-next-line: prefer-const
927
+ const newVNode = newParentVNode.$children$[childIndex];
928
+ let i = 0;
929
+ let elm;
930
+ let childNode;
931
+ let oldVNode;
932
+ if (BUILD.slotRelocation && !useNativeShadowDom) {
933
+ // remember for later we need to check to relocate nodes
934
+ checkSlotRelocate = true;
935
+ if (newVNode.$tag$ === 'slot') {
936
+ if (scopeId) {
937
+ // scoped css needs to add its scoped id to the parent element
938
+ parentElm.classList.add(scopeId + '-s');
939
+ }
940
+ newVNode.$flags$ |= newVNode.$children$
941
+ ? // slot element has fallback content
942
+ 2 /* VNODE_FLAGS.isSlotFallback */
943
+ : // slot element does not have fallback content
944
+ 1 /* VNODE_FLAGS.isSlotReference */;
945
+ }
946
+ }
947
+ if (BUILD.isDev && newVNode.$elm$) {
948
+ consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${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`);
949
+ }
950
+ if (BUILD.vdomText && newVNode.$text$ !== null) {
951
+ // create text node
952
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
953
+ }
954
+ else if (BUILD.slotRelocation && newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
955
+ // create a slot reference node
956
+ elm = newVNode.$elm$ =
957
+ BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : doc.createTextNode('');
958
+ }
959
+ else {
960
+ if (BUILD.svg && !isSvgMode) {
961
+ isSvgMode = newVNode.$tag$ === 'svg';
962
+ }
963
+ // create element
964
+ elm = newVNode.$elm$ = (BUILD.svg
965
+ ? doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, BUILD.slotRelocation && newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
966
+ ? 'slot-fb'
967
+ : newVNode.$tag$)
968
+ : doc.createElement(BUILD.slotRelocation && newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
969
+ ? 'slot-fb'
970
+ : newVNode.$tag$));
971
+ if (BUILD.svg && isSvgMode && newVNode.$tag$ === 'foreignObject') {
972
+ isSvgMode = false;
973
+ }
974
+ // add css classes, attrs, props, listeners, etc.
975
+ if (BUILD.vdomAttribute) {
976
+ updateElement(null, newVNode, isSvgMode);
977
+ }
978
+ if ((BUILD.shadowDom || BUILD.scoped) && isDef(scopeId) && elm['s-si'] !== scopeId) {
979
+ // if there is a scopeId and this is the initial render
980
+ // then let's add the scopeId as a css class
981
+ elm.classList.add((elm['s-si'] = scopeId));
982
+ }
983
+ if (newVNode.$children$) {
984
+ for (i = 0; i < newVNode.$children$.length; ++i) {
985
+ // create the node
986
+ childNode = createElm(oldParentVNode, newVNode, i, elm);
987
+ // return node could have been null
988
+ if (childNode) {
989
+ // append our new node
990
+ elm.appendChild(childNode);
991
+ }
992
+ }
993
+ }
994
+ if (BUILD.svg) {
995
+ if (newVNode.$tag$ === 'svg') {
996
+ // Only reset the SVG context when we're exiting <svg> element
997
+ isSvgMode = false;
998
+ }
999
+ else if (elm.tagName === 'foreignObject') {
1000
+ // Reenter SVG context when we're exiting <foreignObject> element
1001
+ isSvgMode = true;
1002
+ }
1003
+ }
1004
+ }
1005
+ if (BUILD.slotRelocation) {
1006
+ elm['s-hn'] = hostTagName;
1007
+ if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
1008
+ // remember the content reference comment
1009
+ elm['s-sr'] = true;
1010
+ // remember the content reference comment
1011
+ elm['s-cr'] = contentRef;
1012
+ // remember the slot name, or empty string for default slot
1013
+ elm['s-sn'] = newVNode.$name$ || '';
1014
+ // check if we've got an old vnode for this slot
1015
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
1016
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
1017
+ // we've got an old slot vnode and the wrapper is being replaced
1018
+ // so let's move the old slot content back to it's original location
1019
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
1020
+ }
1021
+ }
1022
+ }
1023
+ return elm;
1024
+ };
1025
+ const putBackInOriginalLocation = (parentElm, recursive) => {
1026
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1027
+ const oldSlotChildNodes = parentElm.childNodes;
1028
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
1029
+ const childNode = oldSlotChildNodes[i];
1030
+ if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
1031
+ // // this child node in the old element is from another component
1032
+ // // remove this node from the old slot's parent
1033
+ // childNode.remove();
1034
+ // and relocate it back to it's original location
1035
+ parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
1036
+ // remove the old original location comment entirely
1037
+ // later on the patch function will know what to do
1038
+ // and move this to the correct spot in need be
1039
+ childNode['s-ol'].remove();
1040
+ childNode['s-ol'] = undefined;
1041
+ checkSlotRelocate = true;
1042
+ }
1043
+ if (recursive) {
1044
+ putBackInOriginalLocation(childNode, recursive);
1045
+ }
1046
+ }
1047
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1048
+ };
1049
+ /**
1050
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
1051
+ * add them to the DOM in the appropriate place.
1052
+ *
1053
+ * @param parentElm the DOM node which should be used as a parent for the new
1054
+ * DOM nodes
1055
+ * @param before a child of the `parentElm` which the new children should be
1056
+ * inserted before (optional)
1057
+ * @param parentVNode the parent virtual DOM node
1058
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
1059
+ * @param startIdx the index in the child virtual DOM nodes at which to start
1060
+ * creating DOM nodes (inclusive)
1061
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
1062
+ * creating DOM nodes (inclusive)
1063
+ */
1064
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
1065
+ let containerElm = ((BUILD.slotRelocation && parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
1066
+ let childNode;
1067
+ if (BUILD.shadowDom && containerElm.shadowRoot && containerElm.tagName === hostTagName) {
1068
+ containerElm = containerElm.shadowRoot;
1069
+ }
1070
+ for (; startIdx <= endIdx; ++startIdx) {
1071
+ if (vnodes[startIdx]) {
1072
+ childNode = createElm(null, parentVNode, startIdx, parentElm);
1073
+ if (childNode) {
1074
+ vnodes[startIdx].$elm$ = childNode;
1075
+ containerElm.insertBefore(childNode, BUILD.slotRelocation ? referenceNode(before) : before);
1076
+ }
1077
+ }
1078
+ }
1079
+ };
1080
+ /**
1081
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
1082
+ * This can be used to, for instance, clean up after a list of children which
1083
+ * should no longer be shown.
1084
+ *
1085
+ * This function also handles some of Stencil's slot relocation logic.
1086
+ *
1087
+ * @param vnodes a list of virtual DOM nodes to remove
1088
+ * @param startIdx the index at which to start removing nodes (inclusive)
1089
+ * @param endIdx the index at which to stop removing nodes (inclusive)
1090
+ */
1091
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
1092
+ for (let index = startIdx; index <= endIdx; ++index) {
1093
+ const vnode = vnodes[index];
1094
+ if (vnode) {
1095
+ const elm = vnode.$elm$;
1096
+ nullifyVNodeRefs(vnode);
1097
+ if (elm) {
1098
+ if (BUILD.slotRelocation) {
1099
+ // we're removing this element
1100
+ // so it's possible we need to show slot fallback content now
1101
+ checkSlotFallbackVisibility = true;
1102
+ if (elm['s-ol']) {
1103
+ // remove the original location comment
1104
+ elm['s-ol'].remove();
1105
+ }
1106
+ else {
1107
+ // it's possible that child nodes of the node
1108
+ // that's being removed are slot nodes
1109
+ putBackInOriginalLocation(elm, true);
1110
+ }
1111
+ }
1112
+ // remove the vnode's element from the dom
1113
+ elm.remove();
1114
+ }
1115
+ }
1116
+ }
1117
+ };
1118
+ /**
1119
+ * Reconcile the children of a new VNode with the children of an old VNode by
1120
+ * traversing the two collections of children, identifying nodes that are
1121
+ * conserved or changed, calling out to `patch` to make any necessary
1122
+ * updates to the DOM, and rearranging DOM nodes as needed.
1123
+ *
1124
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
1125
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
1126
+ * 'windows' by storing start and end indices and references to the
1127
+ * corresponding array entries. Initially the two 'windows' are basically equal
1128
+ * to the entire array, but we progressively narrow the windows until there are
1129
+ * no children left to update by doing the following:
1130
+ *
1131
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
1132
+ * that if we have an initial array like the following we'll end up dealing
1133
+ * only with a window bounded by the highlighted elements:
1134
+ *
1135
+ * [null, null, VNode1 , ... , VNode2, null, null]
1136
+ * ^^^^^^ ^^^^^^
1137
+ *
1138
+ * 2. Check to see if the elements at the head and tail positions are equal
1139
+ * across the windows. This will basically detect elements which haven't
1140
+ * been added, removed, or changed position, i.e. if you had the following
1141
+ * VNode elements (represented as HTML):
1142
+ *
1143
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
1144
+ * newVNode: `<div><p><span>THERE</span></p></div>`
1145
+ *
1146
+ * Then when comparing the children of the `<div>` tag we check the equality
1147
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
1148
+ * same tag in the same position, we'd be able to avoid completely
1149
+ * re-rendering the subtree under them with a new DOM element and would just
1150
+ * call out to `patch` to handle reconciling their children and so on.
1151
+ *
1152
+ * 3. Check, for both windows, to see if the element at the beginning of the
1153
+ * window corresponds to the element at the end of the other window. This is
1154
+ * a heuristic which will let us identify _some_ situations in which
1155
+ * elements have changed position, for instance it _should_ detect that the
1156
+ * children nodes themselves have not changed but merely moved in the
1157
+ * following example:
1158
+ *
1159
+ * oldVNode: `<div><element-one /><element-two /></div>`
1160
+ * newVNode: `<div><element-two /><element-one /></div>`
1161
+ *
1162
+ * If we find cases like this then we also need to move the concrete DOM
1163
+ * elements corresponding to the moved children to write the re-order to the
1164
+ * DOM.
1165
+ *
1166
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
1167
+ * nodes in the old children which have the same key as the first element in
1168
+ * our window on the new children. If we find such a node we handle calling
1169
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
1170
+ * what we find.
1171
+ *
1172
+ * Finally, once we've narrowed our 'windows' to the point that either of them
1173
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
1174
+ * insertion or deletion that needs to happen to get a DOM state that correctly
1175
+ * reflects the new child VNodes. If, for instance, after our window on the old
1176
+ * children has collapsed we still have more nodes on the new children that
1177
+ * we haven't dealt with yet then we need to add them, or if the new children
1178
+ * collapse but we still have unhandled _old_ children then we need to make
1179
+ * sure the corresponding DOM nodes are removed.
1180
+ *
1181
+ * @param parentElm the node into which the parent VNode is rendered
1182
+ * @param oldCh the old children of the parent node
1183
+ * @param newVNode the new VNode which will replace the parent
1184
+ * @param newCh the new children of the parent node
1185
+ */
1186
+ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
1187
+ let oldStartIdx = 0;
1188
+ let newStartIdx = 0;
1189
+ let idxInOld = 0;
1190
+ let i = 0;
1191
+ let oldEndIdx = oldCh.length - 1;
1192
+ let oldStartVnode = oldCh[0];
1193
+ let oldEndVnode = oldCh[oldEndIdx];
1194
+ let newEndIdx = newCh.length - 1;
1195
+ let newStartVnode = newCh[0];
1196
+ let newEndVnode = newCh[newEndIdx];
1197
+ let node;
1198
+ let elmToMove;
1199
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1200
+ if (oldStartVnode == null) {
1201
+ // VNode might have been moved left
1202
+ oldStartVnode = oldCh[++oldStartIdx];
1203
+ }
1204
+ else if (oldEndVnode == null) {
1205
+ oldEndVnode = oldCh[--oldEndIdx];
1206
+ }
1207
+ else if (newStartVnode == null) {
1208
+ newStartVnode = newCh[++newStartIdx];
1209
+ }
1210
+ else if (newEndVnode == null) {
1211
+ newEndVnode = newCh[--newEndIdx];
1212
+ }
1213
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
1214
+ // if the start nodes are the same then we should patch the new VNode
1215
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
1216
+ // indices to reflect that. We don't need to move any DOM Nodes around
1217
+ // since things are matched up in order.
1218
+ patch(oldStartVnode, newStartVnode);
1219
+ oldStartVnode = oldCh[++oldStartIdx];
1220
+ newStartVnode = newCh[++newStartIdx];
1221
+ }
1222
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
1223
+ // likewise, if the end nodes are the same we patch new onto old and
1224
+ // decrement our end indices, and also likewise in this case we don't
1225
+ // need to move any DOM Nodes.
1226
+ patch(oldEndVnode, newEndVnode);
1227
+ oldEndVnode = oldCh[--oldEndIdx];
1228
+ newEndVnode = newCh[--newEndIdx];
1229
+ }
1230
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
1231
+ // case: "Vnode moved right"
1232
+ //
1233
+ // We've found that the last node in our window on the new children is
1234
+ // the same VNode as the _first_ node in our window on the old children
1235
+ // we're dealing with now. Visually, this is the layout of these two
1236
+ // nodes:
1237
+ //
1238
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
1239
+ // ^^^^^^^^^^^
1240
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
1241
+ // ^^^^^^^^^^^^^
1242
+ //
1243
+ // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
1244
+ // and move the DOM element for `oldStartVnode`.
1245
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
1246
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
1247
+ }
1248
+ patch(oldStartVnode, newEndVnode);
1249
+ // We need to move the element for `oldStartVnode` into a position which
1250
+ // will be appropriate for `newEndVnode`. For this we can use
1251
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
1252
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
1253
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
1254
+ //
1255
+ // <old-start-node />
1256
+ // <some-intervening-node />
1257
+ // <old-end-node />
1258
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
1259
+ // <next-sibling />
1260
+ //
1261
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
1262
+ // the node for `oldStartVnode` at the end of the children of
1263
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
1264
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
1265
+ // append it to the children of the parent element.
1266
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
1267
+ oldStartVnode = oldCh[++oldStartIdx];
1268
+ newEndVnode = newCh[--newEndIdx];
1269
+ }
1270
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
1271
+ // case: "Vnode moved left"
1272
+ //
1273
+ // We've found that the first node in our window on the new children is
1274
+ // the same VNode as the _last_ node in our window on the old children.
1275
+ // Visually, this is the layout of these two nodes:
1276
+ //
1277
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
1278
+ // ^^^^^^^^^^^^^
1279
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
1280
+ // ^^^^^^^^^^^
1281
+ //
1282
+ // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
1283
+ // (which will handle updating any changed attributes, reconciling their
1284
+ // children etc) but we also need to move the DOM node to which
1285
+ // `oldEndVnode` corresponds.
1286
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
1287
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
1288
+ }
1289
+ patch(oldEndVnode, newStartVnode);
1290
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
1291
+ // the same node, so since we're here we know that they are not. Thus we
1292
+ // can move the element for `oldEndVnode` _before_ the element for
1293
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
1294
+ // future.
1295
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
1296
+ oldEndVnode = oldCh[--oldEndIdx];
1297
+ newStartVnode = newCh[++newStartIdx];
1298
+ }
1299
+ else {
1300
+ // Here we do some checks to match up old and new nodes based on the
1301
+ // `$key$` attribute, which is set by putting a `key="my-key"` attribute
1302
+ // in the JSX for a DOM element in the implementation of a Stencil
1303
+ // component.
1304
+ //
1305
+ // First we check to see if there are any nodes in the array of old
1306
+ // children which have the same key as the first node in the new
1307
+ // children.
1308
+ idxInOld = -1;
1309
+ if (BUILD.vdomKey) {
1310
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) {
1311
+ if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
1312
+ idxInOld = i;
1313
+ break;
1314
+ }
1315
+ }
1316
+ }
1317
+ if (BUILD.vdomKey && idxInOld >= 0) {
1318
+ // We found a node in the old children which matches up with the first
1319
+ // node in the new children! So let's deal with that
1320
+ elmToMove = oldCh[idxInOld];
1321
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) {
1322
+ // the tag doesn't match so we'll need a new DOM element
1323
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
1324
+ }
1325
+ else {
1326
+ patch(elmToMove, newStartVnode);
1327
+ // invalidate the matching old node so that we won't try to update it
1328
+ // again later on
1329
+ oldCh[idxInOld] = undefined;
1330
+ node = elmToMove.$elm$;
1331
+ }
1332
+ newStartVnode = newCh[++newStartIdx];
1333
+ }
1334
+ else {
1335
+ // We either didn't find an element in the old children that matches
1336
+ // the key of the first new child OR the build is not using `key`
1337
+ // attributes at all. In either case we need to create a new element
1338
+ // for the new node.
1339
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
1340
+ newStartVnode = newCh[++newStartIdx];
1341
+ }
1342
+ if (node) {
1343
+ // if we created a new node then handle inserting it to the DOM
1344
+ if (BUILD.slotRelocation) {
1345
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
1346
+ }
1347
+ else {
1348
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ if (oldStartIdx > oldEndIdx) {
1354
+ // we have some more new nodes to add which don't match up with old nodes
1355
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
1356
+ }
1357
+ else if (BUILD.updatable && newStartIdx > newEndIdx) {
1358
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
1359
+ // in the new array, so lets remove them (which entails cleaning up the
1360
+ // relevant DOM nodes)
1361
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
1362
+ }
1363
+ };
1364
+ /**
1365
+ * Compare two VNodes to determine if they are the same
1366
+ *
1367
+ * **NB**: This function is an equality _heuristic_ based on the available
1368
+ * information set on the two VNodes and can be misleading under certain
1369
+ * circumstances. In particular, if the two nodes do not have `key` attrs
1370
+ * (available under `$key$` on VNodes) then the function falls back on merely
1371
+ * checking that they have the same tag.
1372
+ *
1373
+ * So, in other words, if `key` attrs are not set on VNodes which may be
1374
+ * changing order within a `children` array or something along those lines then
1375
+ * we could obtain a false negative and then have to do needless re-rendering
1376
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
1377
+ *
1378
+ * @param leftVNode the first VNode to check
1379
+ * @param rightVNode the second VNode to check
1380
+ * @returns whether they're equal or not
1381
+ */
1382
+ const isSameVnode = (leftVNode, rightVNode) => {
1383
+ // compare if two vnode to see if they're "technically" the same
1384
+ // need to have the same element tag, and same key to be the same
1385
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
1386
+ if (BUILD.slotRelocation && leftVNode.$tag$ === 'slot') {
1387
+ return leftVNode.$name$ === rightVNode.$name$;
1388
+ }
1389
+ // this will be set if components in the build have `key` attrs set on them
1390
+ if (BUILD.vdomKey) {
1391
+ return leftVNode.$key$ === rightVNode.$key$;
1392
+ }
1393
+ return true;
1394
+ }
1395
+ return false;
1396
+ };
1397
+ const referenceNode = (node) => {
1398
+ // this node was relocated to a new location in the dom
1399
+ // because of some other component's slot
1400
+ // but we still have an html comment in place of where
1401
+ // it's original location was according to it's original vdom
1402
+ return (node && node['s-ol']) || node;
1403
+ };
1404
+ const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
1405
+ /**
1406
+ * Handle reconciling an outdated VNode with a new one which corresponds to
1407
+ * it. This function handles flushing updates to the DOM and reconciling the
1408
+ * children of the two nodes (if any).
1409
+ *
1410
+ * @param oldVNode an old VNode whose DOM element and children we want to update
1411
+ * @param newVNode a new VNode representing an updated version of the old one
1412
+ */
1413
+ const patch = (oldVNode, newVNode) => {
1414
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
1415
+ const oldChildren = oldVNode.$children$;
1416
+ const newChildren = newVNode.$children$;
1417
+ const tag = newVNode.$tag$;
1418
+ const text = newVNode.$text$;
1419
+ let defaultHolder;
1420
+ if (!BUILD.vdomText || text === null) {
1421
+ if (BUILD.svg) {
1422
+ // test if we're rendering an svg element, or still rendering nodes inside of one
1423
+ // only add this to the when the compiler sees we're using an svg somewhere
1424
+ isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
1425
+ }
1426
+ if (BUILD.vdomAttribute || BUILD.reflect) {
1427
+ if (BUILD.slot && tag === 'slot')
1428
+ ;
1429
+ else {
1430
+ // either this is the first render of an element OR it's an update
1431
+ // AND we already know it's possible it could have changed
1432
+ // this updates the element's css classes, attrs, props, listeners, etc.
1433
+ updateElement(oldVNode, newVNode, isSvgMode);
1434
+ }
1435
+ }
1436
+ if (BUILD.updatable && oldChildren !== null && newChildren !== null) {
1437
+ // looks like there's child vnodes for both the old and new vnodes
1438
+ // so we need to call `updateChildren` to reconcile them
1439
+ updateChildren(elm, oldChildren, newVNode, newChildren);
1440
+ }
1441
+ else if (newChildren !== null) {
1442
+ // no old child vnodes, but there are new child vnodes to add
1443
+ if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) {
1444
+ // the old vnode was text, so be sure to clear it out
1445
+ elm.textContent = '';
1446
+ }
1447
+ // add the new vnode children
1448
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
1449
+ }
1450
+ else if (BUILD.updatable && oldChildren !== null) {
1451
+ // no new child vnodes, but there are old child vnodes to remove
1452
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
1453
+ }
1454
+ if (BUILD.svg && isSvgMode && tag === 'svg') {
1455
+ isSvgMode = false;
1456
+ }
1457
+ }
1458
+ else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm['s-cr'])) {
1459
+ // this element has slotted content
1460
+ defaultHolder.parentNode.textContent = text;
1461
+ }
1462
+ else if (BUILD.vdomText && oldVNode.$text$ !== text) {
1463
+ // update the text content for the text only vnode
1464
+ // and also only if the text is different than before
1465
+ elm.data = text;
1466
+ }
1467
+ };
1468
+ const updateFallbackSlotVisibility = (elm) => {
1469
+ // tslint:disable-next-line: prefer-const
1470
+ const childNodes = elm.childNodes;
1471
+ let childNode;
1472
+ let i;
1473
+ let ilen;
1474
+ let j;
1475
+ let slotNameAttr;
1476
+ let nodeType;
1477
+ for (i = 0, ilen = childNodes.length; i < ilen; i++) {
1478
+ childNode = childNodes[i];
1479
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1480
+ if (childNode['s-sr']) {
1481
+ // this is a slot fallback node
1482
+ // get the slot name for this slot reference node
1483
+ slotNameAttr = childNode['s-sn'];
1484
+ // by default always show a fallback slot node
1485
+ // then hide it if there are other slots in the light dom
1486
+ childNode.hidden = false;
1487
+ for (j = 0; j < ilen; j++) {
1488
+ nodeType = childNodes[j].nodeType;
1489
+ if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
1490
+ // this sibling node is from a different component OR is a named fallback slot node
1491
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
1492
+ childNode.hidden = true;
1493
+ break;
1494
+ }
1495
+ }
1496
+ else {
1497
+ // this is a default fallback slot node
1498
+ // any element or text node (with content)
1499
+ // should hide the default fallback slot node
1500
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
1501
+ (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
1502
+ childNode.hidden = true;
1503
+ break;
1504
+ }
1505
+ }
1506
+ }
1507
+ }
1508
+ // keep drilling down
1509
+ updateFallbackSlotVisibility(childNode);
1510
+ }
1511
+ }
1512
+ };
1513
+ const relocateNodes = [];
1514
+ const relocateSlotContent = (elm) => {
1515
+ // tslint:disable-next-line: prefer-const
1516
+ let childNode;
1517
+ let node;
1518
+ let hostContentNodes;
1519
+ let slotNameAttr;
1520
+ let relocateNodeData;
1521
+ let j;
1522
+ let i = 0;
1523
+ const childNodes = elm.childNodes;
1524
+ const ilen = childNodes.length;
1525
+ for (; i < ilen; i++) {
1526
+ childNode = childNodes[i];
1527
+ if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
1528
+ // first got the content reference comment node
1529
+ // then we got it's parent, which is where all the host content is in now
1530
+ hostContentNodes = node.parentNode.childNodes;
1531
+ slotNameAttr = childNode['s-sn'];
1532
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
1533
+ node = hostContentNodes[j];
1534
+ if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
1535
+ // let's do some relocating to its new home
1536
+ // but never relocate a content reference node
1537
+ // that is suppose to always represent the original content location
1538
+ if (isNodeLocatedInSlot(node, slotNameAttr)) {
1539
+ // it's possible we've already decided to relocate this node
1540
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1541
+ // made some changes to slots
1542
+ // let's make sure we also double check
1543
+ // fallbacks are correctly hidden or shown
1544
+ checkSlotFallbackVisibility = true;
1545
+ node['s-sn'] = node['s-sn'] || slotNameAttr;
1546
+ if (relocateNodeData) {
1547
+ // previously we never found a slot home for this node
1548
+ // but turns out we did, so let's remember it now
1549
+ relocateNodeData.$slotRefNode$ = childNode;
1550
+ }
1551
+ else {
1552
+ // add to our list of nodes to relocate
1553
+ relocateNodes.push({
1554
+ $slotRefNode$: childNode,
1555
+ $nodeToRelocate$: node,
1556
+ });
1557
+ }
1558
+ if (node['s-sr']) {
1559
+ relocateNodes.map((relocateNode) => {
1560
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1561
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1562
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
1563
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1564
+ }
1565
+ }
1566
+ });
1567
+ }
1568
+ }
1569
+ else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1570
+ // so far this element does not have a slot home, not setting slotRefNode on purpose
1571
+ // if we never find a home for this element then we'll need to hide it
1572
+ relocateNodes.push({
1573
+ $nodeToRelocate$: node,
1574
+ });
1575
+ }
1576
+ }
1577
+ }
1578
+ }
1579
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1580
+ relocateSlotContent(childNode);
1581
+ }
1582
+ }
1583
+ };
1584
+ const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1585
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1586
+ if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1587
+ return true;
1588
+ }
1589
+ if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1590
+ return true;
1591
+ }
1592
+ return false;
1593
+ }
1594
+ if (nodeToRelocate['s-sn'] === slotNameAttr) {
1595
+ return true;
1596
+ }
1597
+ return slotNameAttr === '';
1598
+ };
1599
+ /**
1600
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by
1601
+ * calling them with `null`. This signals that the DOM element corresponding to
1602
+ * the VDom node has been removed from the DOM.
1603
+ *
1604
+ * @param vNode a virtual DOM node
1605
+ */
1606
+ const nullifyVNodeRefs = (vNode) => {
1607
+ if (BUILD.vdomRef) {
1608
+ vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1609
+ vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
1610
+ }
1611
+ };
1612
+ /**
1613
+ * The main entry point for Stencil's virtual DOM-based rendering engine
1614
+ *
1615
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
1616
+ * function will handle creating a virtual DOM tree with a single root, patching
1617
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
1618
+ * relocation, and reflecting attributes.
1619
+ *
1620
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
1621
+ * the DOM node into which it should be rendered.
1622
+ * @param renderFnResults the virtual DOM nodes to be rendered
1623
+ */
1624
+ const renderVdom = (hostRef, renderFnResults) => {
1625
+ const hostElm = hostRef.$hostElement$;
1626
+ const cmpMeta = hostRef.$cmpMeta$;
1627
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1628
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1629
+ hostTagName = hostElm.tagName;
1630
+ // <Host> runtime check
1631
+ if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) {
1632
+ throw new Error(`The <Host> must be the single root component.
1633
+ Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
1634
+
1635
+ The render() function should look like this instead:
1636
+
1637
+ render() {
1638
+ // Do not return an array
1639
+ return (
1640
+ <Host>{content}</Host>
1641
+ );
1642
+ }
1643
+ `);
1644
+ }
1645
+ if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
1646
+ rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1647
+ cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
1648
+ }
1649
+ rootVnode.$tag$ = null;
1650
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
1651
+ hostRef.$vnode$ = rootVnode;
1652
+ rootVnode.$elm$ = oldVNode.$elm$ = (BUILD.shadowDom ? hostElm.shadowRoot || hostElm : hostElm);
1653
+ if (BUILD.scoped || BUILD.shadowDom) {
1654
+ scopeId = hostElm['s-sc'];
1655
+ }
1656
+ if (BUILD.slotRelocation) {
1657
+ contentRef = hostElm['s-cr'];
1658
+ useNativeShadowDom = supportsShadow && (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1659
+ // always reset
1660
+ checkSlotFallbackVisibility = false;
1661
+ }
1662
+ // synchronous patch
1663
+ patch(oldVNode, rootVnode);
1664
+ if (BUILD.slotRelocation) {
1665
+ // while we're moving nodes around existing nodes, temporarily disable
1666
+ // the disconnectCallback from working
1667
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1668
+ if (checkSlotRelocate) {
1669
+ relocateSlotContent(rootVnode.$elm$);
1670
+ let relocateData;
1671
+ let nodeToRelocate;
1672
+ let orgLocationNode;
1673
+ let parentNodeRef;
1674
+ let insertBeforeNode;
1675
+ let refNode;
1676
+ let i = 0;
1677
+ for (; i < relocateNodes.length; i++) {
1678
+ relocateData = relocateNodes[i];
1679
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1680
+ if (!nodeToRelocate['s-ol']) {
1681
+ // add a reference node marking this node's original location
1682
+ // keep a reference to this node for later lookups
1683
+ orgLocationNode =
1684
+ BUILD.isDebug || BUILD.hydrateServerSide
1685
+ ? originalLocationDebugNode(nodeToRelocate)
1686
+ : doc.createTextNode('');
1687
+ orgLocationNode['s-nr'] = nodeToRelocate;
1688
+ nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1689
+ }
1690
+ }
1691
+ for (i = 0; i < relocateNodes.length; i++) {
1692
+ relocateData = relocateNodes[i];
1693
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1694
+ if (relocateData.$slotRefNode$) {
1695
+ // by default we're just going to insert it directly
1696
+ // after the slot reference node
1697
+ parentNodeRef = relocateData.$slotRefNode$.parentNode;
1698
+ insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1699
+ orgLocationNode = nodeToRelocate['s-ol'];
1700
+ while ((orgLocationNode = orgLocationNode.previousSibling)) {
1701
+ refNode = orgLocationNode['s-nr'];
1702
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1703
+ refNode = refNode.nextSibling;
1704
+ if (!refNode || !refNode['s-nr']) {
1705
+ insertBeforeNode = refNode;
1706
+ break;
1707
+ }
1708
+ }
1709
+ }
1710
+ if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1711
+ nodeToRelocate.nextSibling !== insertBeforeNode) {
1712
+ // we've checked that it's worth while to relocate
1713
+ // since that the node to relocate
1714
+ // has a different next sibling or parent relocated
1715
+ if (nodeToRelocate !== insertBeforeNode) {
1716
+ if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1717
+ // probably a component in the index.html that doesn't have it's hostname set
1718
+ nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1719
+ }
1720
+ // add it back to the dom but in its new home
1721
+ parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1722
+ }
1723
+ }
1724
+ }
1725
+ else {
1726
+ // this node doesn't have a slot home to go to, so let's hide it
1727
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1728
+ nodeToRelocate.hidden = true;
1729
+ }
1730
+ }
1731
+ }
1732
+ }
1733
+ if (checkSlotFallbackVisibility) {
1734
+ updateFallbackSlotVisibility(rootVnode.$elm$);
1735
+ }
1736
+ // done moving nodes around
1737
+ // allow the disconnect callback to work again
1738
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1739
+ // always reset
1740
+ relocateNodes.length = 0;
1741
+ }
1742
+ };
1743
+ // slot comment debug nodes only created with the `--debug` flag
1744
+ // otherwise these nodes are text nodes w/out content
1745
+ const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
1746
+ const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` +
1747
+ (nodeToRelocate.localName
1748
+ ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})`
1749
+ : `[${nodeToRelocate.textContent}]`));
1750
+ const attachToAncestor = (hostRef, ancestorComponent) => {
1751
+ if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1752
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
1753
+ }
1754
+ };
1755
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
1756
+ if (BUILD.taskQueue && BUILD.updatable) {
1757
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
1758
+ }
1759
+ if (BUILD.asyncLoading && hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1760
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
1761
+ return;
1762
+ }
1763
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1764
+ // there is no ancestor component or the ancestor component
1765
+ // has already fired off its lifecycle update then
1766
+ // fire off the initial update
1767
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1768
+ return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
1769
+ };
1770
+ /**
1771
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
1772
+ * component lifecycle methods like `componentWillLoad` as well as
1773
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
1774
+ *
1775
+ * @param hostRef a reference to a host DOM node
1776
+ * @param isInitialLoad whether we're on the initial load or not
1777
+ * @returns an empty Promise which is used to enqueue a series of operations for
1778
+ * the component
1779
+ */
1780
+ const dispatchHooks = (hostRef, isInitialLoad) => {
1781
+ const elm = hostRef.$hostElement$;
1782
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1783
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1784
+ // We're going to use this variable together with `enqueue` to implement a
1785
+ // little promise-based queue. We start out with it `undefined`. When we add
1786
+ // the first function to the queue we'll set this variable to be that
1787
+ // function's return value. When we attempt to add subsequent values to the
1788
+ // queue we'll check that value and, if it was a `Promise`, we'll then chain
1789
+ // the new function off of that `Promise` using `.then()`. This will give our
1790
+ // queue two nice properties:
1791
+ //
1792
+ // 1. If all functions added to the queue are synchronous they'll be called
1793
+ // synchronously right away.
1794
+ // 2. If all functions added to the queue are asynchronous they'll all be
1795
+ // called in order after `dispatchHooks` exits.
1796
+ let maybePromise;
1797
+ if (isInitialLoad) {
1798
+ if (BUILD.lazyLoad && BUILD.hostListener) {
1799
+ hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
1800
+ if (hostRef.$queuedListeners$) {
1801
+ hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1802
+ hostRef.$queuedListeners$ = undefined;
1803
+ }
1804
+ }
1805
+ emitLifecycleEvent(elm, 'componentWillLoad');
1806
+ if (BUILD.cmpWillLoad) {
1807
+ // If `componentWillLoad` returns a `Promise` then we want to wait on
1808
+ // whatever's going on in that `Promise` before we launch into
1809
+ // rendering the component, doing other lifecycle stuff, etc. So
1810
+ // in that case we assign the returned promise to the variable we
1811
+ // declared above to hold a possible 'queueing' Promise
1812
+ maybePromise = safeCall(instance, 'componentWillLoad');
1813
+ }
1814
+ }
1815
+ else {
1816
+ emitLifecycleEvent(elm, 'componentWillUpdate');
1817
+ if (BUILD.cmpWillUpdate) {
1818
+ // Like `componentWillLoad` above, we allow Stencil component
1819
+ // authors to return a `Promise` from this lifecycle callback, and
1820
+ // we specify that our runtime will wait for that `Promise` to
1821
+ // resolve before the component re-renders. So if the method
1822
+ // returns a `Promise` we need to keep it around!
1823
+ maybePromise = safeCall(instance, 'componentWillUpdate');
1824
+ }
1825
+ }
1826
+ emitLifecycleEvent(elm, 'componentWillRender');
1827
+ if (BUILD.cmpWillRender) {
1828
+ maybePromise = enqueue(maybePromise, () => safeCall(instance, 'componentWillRender'));
1829
+ }
1830
+ endSchedule();
1831
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
1832
+ };
1833
+ /**
1834
+ * This function uses a Promise to implement a simple first-in, first-out queue
1835
+ * of functions to be called.
1836
+ *
1837
+ * The queue is ordered on the basis of the first argument. If it's
1838
+ * `undefined`, then nothing is on the queue yet, so the provided function can
1839
+ * be called synchronously (although note that this function may return a
1840
+ * `Promise`). The idea is that then the return value of that enqueueing
1841
+ * operation is kept around, so that if it was a `Promise` then subsequent
1842
+ * functions can be enqueued by calling this function again with that `Promise`
1843
+ * as the first argument.
1844
+ *
1845
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
1846
+ * @param fn a function to enqueue
1847
+ * @returns either a `Promise` or the return value of the provided function
1848
+ */
1849
+ const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
1850
+ /**
1851
+ * Check that a value is a `Promise`. To check, we first see if the value is an
1852
+ * instance of the `Promise` global. In a few circumstances, in particular if
1853
+ * the global has been overwritten, this is could be misleading, so we also do
1854
+ * a little 'duck typing' check to see if the `.then` property of the value is
1855
+ * defined and a function.
1856
+ *
1857
+ * @param maybePromise it might be a promise!
1858
+ * @returns whether it is or not
1859
+ */
1860
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
1861
+ (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
1862
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1863
+ var _a;
1864
+ const elm = hostRef.$hostElement$;
1865
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1866
+ const rc = elm['s-rc'];
1867
+ if (BUILD.style && isInitialLoad) {
1868
+ // DOM WRITE!
1869
+ attachStyles(hostRef);
1870
+ }
1871
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1872
+ if (BUILD.isDev) {
1873
+ hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
1874
+ }
1875
+ if (BUILD.hydrateServerSide) {
1876
+ await callRender(hostRef, instance, elm);
1877
+ }
1878
+ else {
1879
+ callRender(hostRef, instance, elm);
1880
+ }
1881
+ if (BUILD.isDev) {
1882
+ hostRef.$renderCount$ = hostRef.$renderCount$ === undefined ? 1 : hostRef.$renderCount$ + 1;
1883
+ hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
1884
+ }
1885
+ if (BUILD.hydrateServerSide) {
1886
+ try {
1887
+ // manually connected child components during server-side hydrate
1888
+ serverSideConnected(elm);
1889
+ if (isInitialLoad) {
1890
+ // using only during server-side hydrate
1891
+ if (hostRef.$cmpMeta$.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1892
+ elm['s-en'] = '';
1893
+ }
1894
+ else if (hostRef.$cmpMeta$.$flags$ & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
1895
+ elm['s-en'] = 'c';
1896
+ }
1897
+ }
1898
+ }
1899
+ catch (e) {
1900
+ consoleError(e, elm);
1901
+ }
1902
+ }
1903
+ if (BUILD.asyncLoading && rc) {
1904
+ // ok, so turns out there are some child host elements
1905
+ // waiting on this parent element to load
1906
+ // let's fire off all update callbacks waiting
1907
+ rc.map((cb) => cb());
1908
+ elm['s-rc'] = undefined;
1909
+ }
1910
+ endRender();
1911
+ endUpdate();
1912
+ if (BUILD.asyncLoading) {
1913
+ const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
1914
+ const postUpdate = () => postUpdateComponent(hostRef);
1915
+ if (childrenPromises.length === 0) {
1916
+ postUpdate();
1917
+ }
1918
+ else {
1919
+ Promise.all(childrenPromises).then(postUpdate);
1920
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1921
+ childrenPromises.length = 0;
1922
+ }
1923
+ }
1924
+ else {
1925
+ postUpdateComponent(hostRef);
1926
+ }
1927
+ };
1928
+ const callRender = (hostRef, instance, elm) => {
1929
+ // in order for bundlers to correctly treeshake the BUILD object
1930
+ // we need to ensure BUILD is not deoptimized within a try/catch
1931
+ // https://rollupjs.org/guide/en/#treeshake tryCatchDeoptimization
1932
+ const allRenderFn = BUILD.allRenderFn ? true : false;
1933
+ const lazyLoad = BUILD.lazyLoad ? true : false;
1934
+ const taskQueue = BUILD.taskQueue ? true : false;
1935
+ const updatable = BUILD.updatable ? true : false;
1936
+ try {
1937
+ renderingRef = instance;
1938
+ instance = allRenderFn ? instance.render() : instance.render && instance.render();
1939
+ if (updatable && taskQueue) {
1940
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1941
+ }
1942
+ if (updatable || lazyLoad) {
1943
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1944
+ }
1945
+ if (BUILD.hasRenderFn || BUILD.reflect) {
1946
+ if (BUILD.vdomRender || BUILD.reflect) {
1947
+ // looks like we've got child nodes to render into this host element
1948
+ // or we need to update the css class/attrs on the host element
1949
+ // DOM WRITE!
1950
+ if (BUILD.hydrateServerSide) {
1951
+ return Promise.resolve(instance).then((value) => renderVdom(hostRef, value));
1952
+ }
1953
+ else {
1954
+ renderVdom(hostRef, instance);
1955
+ }
1956
+ }
1957
+ else {
1958
+ elm.textContent = instance;
1959
+ }
1960
+ }
1961
+ }
1962
+ catch (e) {
1963
+ consoleError(e, hostRef.$hostElement$);
1964
+ }
1965
+ renderingRef = null;
1966
+ return null;
1967
+ };
1968
+ const getRenderingRef = () => renderingRef;
1969
+ const postUpdateComponent = (hostRef) => {
1970
+ const tagName = hostRef.$cmpMeta$.$tagName$;
1971
+ const elm = hostRef.$hostElement$;
1972
+ const endPostUpdate = createTime('postUpdate', tagName);
1973
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1974
+ const ancestorComponent = hostRef.$ancestorComponent$;
1975
+ if (BUILD.cmpDidRender) {
1976
+ if (BUILD.isDev) {
1977
+ hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
1978
+ }
1979
+ safeCall(instance, 'componentDidRender');
1980
+ if (BUILD.isDev) {
1981
+ hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
1982
+ }
1983
+ }
1984
+ emitLifecycleEvent(elm, 'componentDidRender');
1985
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1986
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1987
+ if (BUILD.asyncLoading && BUILD.cssAnnotations) {
1988
+ // DOM WRITE!
1989
+ addHydratedFlag(elm);
1990
+ }
1991
+ if (BUILD.cmpDidLoad) {
1992
+ if (BUILD.isDev) {
1993
+ hostRef.$flags$ |= 2048 /* HOST_FLAGS.devOnDidLoad */;
1994
+ }
1995
+ safeCall(instance, 'componentDidLoad');
1996
+ if (BUILD.isDev) {
1997
+ hostRef.$flags$ &= ~2048 /* HOST_FLAGS.devOnDidLoad */;
1998
+ }
1999
+ }
2000
+ emitLifecycleEvent(elm, 'componentDidLoad');
2001
+ endPostUpdate();
2002
+ if (BUILD.asyncLoading) {
2003
+ hostRef.$onReadyResolve$(elm);
2004
+ if (!ancestorComponent) {
2005
+ appDidLoad(tagName);
2006
+ }
2007
+ }
2008
+ }
2009
+ else {
2010
+ if (BUILD.cmpDidUpdate) {
2011
+ // we've already loaded this component
2012
+ // fire off the user's componentDidUpdate method (if one was provided)
2013
+ // componentDidUpdate runs AFTER render() has been called
2014
+ // and all child components have finished updating
2015
+ if (BUILD.isDev) {
2016
+ hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
2017
+ }
2018
+ safeCall(instance, 'componentDidUpdate');
2019
+ if (BUILD.isDev) {
2020
+ hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
2021
+ }
2022
+ }
2023
+ emitLifecycleEvent(elm, 'componentDidUpdate');
2024
+ endPostUpdate();
2025
+ }
2026
+ if (BUILD.hotModuleReplacement) {
2027
+ elm['s-hmr-load'] && elm['s-hmr-load']();
2028
+ }
2029
+ if (BUILD.method && BUILD.lazyLoad) {
2030
+ hostRef.$onInstanceResolve$(elm);
2031
+ }
2032
+ // load events fire from bottom to top
2033
+ // the deepest elements load first then bubbles up
2034
+ if (BUILD.asyncLoading) {
2035
+ if (hostRef.$onRenderResolve$) {
2036
+ hostRef.$onRenderResolve$();
2037
+ hostRef.$onRenderResolve$ = undefined;
2038
+ }
2039
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
2040
+ nextTick(() => scheduleUpdate(hostRef, false));
2041
+ }
2042
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
2043
+ }
2044
+ // ( •_•)
2045
+ // ( •_•)>⌐■-■
2046
+ // (⌐■_■)
2047
+ };
2048
+ const forceUpdate = (ref) => {
2049
+ if (BUILD.updatable) {
2050
+ const hostRef = getHostRef(ref);
2051
+ const isConnected = hostRef.$hostElement$.isConnected;
2052
+ if (isConnected &&
2053
+ (hostRef.$flags$ & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
2054
+ scheduleUpdate(hostRef, false);
2055
+ }
2056
+ // Returns "true" when the forced update was successfully scheduled
2057
+ return isConnected;
2058
+ }
2059
+ return false;
2060
+ };
2061
+ const appDidLoad = (who) => {
2062
+ // on appload
2063
+ // we have finish the first big initial render
2064
+ if (BUILD.cssAnnotations) {
2065
+ addHydratedFlag(doc.documentElement);
2066
+ }
2067
+ if (BUILD.asyncQueue) {
2068
+ plt.$flags$ |= 2 /* PLATFORM_FLAGS.appLoaded */;
2069
+ }
2070
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
2071
+ if (BUILD.profile && performance.measure) {
2072
+ performance.measure(`[Stencil] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
2073
+ }
2074
+ };
2075
+ const safeCall = (instance, method, arg) => {
2076
+ if (instance && instance[method]) {
2077
+ try {
2078
+ return instance[method](arg);
2079
+ }
2080
+ catch (e) {
2081
+ consoleError(e);
2082
+ }
2083
+ }
2084
+ return undefined;
2085
+ };
2086
+ const emitLifecycleEvent = (elm, lifecycleName) => {
2087
+ if (BUILD.lifecycleDOMEvents) {
2088
+ emitEvent(elm, 'stencil_' + lifecycleName, {
2089
+ bubbles: true,
2090
+ composed: true,
2091
+ detail: {
2092
+ namespace: NAMESPACE,
2093
+ },
2094
+ });
2095
+ }
2096
+ };
2097
+ const addHydratedFlag = (elm) => BUILD.hydratedClass
2098
+ ? elm.classList.add('hydrated')
2099
+ : BUILD.hydratedAttribute
2100
+ ? elm.setAttribute('hydrated', '')
2101
+ : undefined;
2102
+ const serverSideConnected = (elm) => {
2103
+ const children = elm.children;
2104
+ if (children != null) {
2105
+ for (let i = 0, ii = children.length; i < ii; i++) {
2106
+ const childElm = children[i];
2107
+ if (typeof childElm.connectedCallback === 'function') {
2108
+ childElm.connectedCallback();
2109
+ }
2110
+ serverSideConnected(childElm);
2111
+ }
2112
+ }
2113
+ };
2114
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
2115
+ const setValue = (ref, propName, newVal, cmpMeta) => {
2116
+ // check our new property value against our internal value
2117
+ const hostRef = getHostRef(ref);
2118
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
2119
+ const oldVal = hostRef.$instanceValues$.get(propName);
2120
+ const flags = hostRef.$flags$;
2121
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2122
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
2123
+ // explicitly check for NaN on both sides, as `NaN === NaN` is always false
2124
+ const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
2125
+ const didValueChange = newVal !== oldVal && !areBothNaN;
2126
+ if ((!BUILD.lazyLoad || !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
2127
+ // gadzooks! the property's value has changed!!
2128
+ // set our new value!
2129
+ hostRef.$instanceValues$.set(propName, newVal);
2130
+ if (BUILD.isDev) {
2131
+ if (hostRef.$flags$ & 1024 /* HOST_FLAGS.devOnRender */) {
2132
+ 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);
2133
+ }
2134
+ else if (hostRef.$flags$ & 2048 /* HOST_FLAGS.devOnDidLoad */) {
2135
+ 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);
2136
+ }
2137
+ }
2138
+ if (!BUILD.lazyLoad || instance) {
2139
+ // get an array of method names of watch functions to call
2140
+ if (BUILD.watchCallback && cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
2141
+ const watchMethods = cmpMeta.$watchers$[propName];
2142
+ if (watchMethods) {
2143
+ // this instance is watching for when this property changed
2144
+ watchMethods.map((watchMethodName) => {
2145
+ try {
2146
+ // fire off each of the watch methods that are watching this property
2147
+ instance[watchMethodName](newVal, oldVal, propName);
2148
+ }
2149
+ catch (e) {
2150
+ consoleError(e, elm);
2151
+ }
2152
+ });
2153
+ }
2154
+ }
2155
+ if (BUILD.updatable &&
2156
+ (flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
2157
+ if (BUILD.cmpShouldUpdate && instance.componentShouldUpdate) {
2158
+ if (instance.componentShouldUpdate(newVal, oldVal, propName) === false) {
2159
+ return;
2160
+ }
2161
+ }
2162
+ // looks like this value actually changed, so we've got work to do!
2163
+ // but only if we've already rendered, otherwise just chill out
2164
+ // queue that we need to do an update, but don't worry about queuing
2165
+ // up millions cuz this function ensures it only runs once
2166
+ scheduleUpdate(hostRef, false);
2167
+ }
2168
+ }
2169
+ }
2170
+ };
2171
+ /**
2172
+ * Attach a series of runtime constructs to a compiled Stencil component
2173
+ * constructor, including getters and setters for the `@Prop` and `@State`
2174
+ * decorators, callbacks for when attributes change, and so on.
2175
+ *
2176
+ * @param Cstr the constructor for a component that we need to process
2177
+ * @param cmpMeta metadata collected previously about the component
2178
+ * @param flags a number used to store a series of bit flags
2179
+ * @returns a reference to the same constructor passed in (but now mutated)
2180
+ */
2181
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
2182
+ if (BUILD.member && cmpMeta.$members$) {
2183
+ if (BUILD.watchCallback && Cstr.watchers) {
2184
+ cmpMeta.$watchers$ = Cstr.watchers;
2185
+ }
2186
+ // It's better to have a const than two Object.entries()
2187
+ const members = Object.entries(cmpMeta.$members$);
2188
+ const prototype = Cstr.prototype;
2189
+ members.map(([memberName, [memberFlags]]) => {
2190
+ if ((BUILD.prop || BUILD.state) &&
2191
+ (memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
2192
+ ((!BUILD.lazyLoad || flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
2193
+ // proxyComponent - prop
2194
+ Object.defineProperty(prototype, memberName, {
2195
+ get() {
2196
+ // proxyComponent, get value
2197
+ return getValue(this, memberName);
2198
+ },
2199
+ set(newValue) {
2200
+ // only during dev time
2201
+ if (BUILD.isDev) {
2202
+ const ref = getHostRef(this);
2203
+ if (
2204
+ // we are proxying the instance (not element)
2205
+ (flags & 1 /* PROXY_FLAGS.isElementConstructor */) === 0 &&
2206
+ // the element is not constructing
2207
+ (ref.$flags$ & 8 /* HOST_FLAGS.isConstructingInstance */) === 0 &&
2208
+ // the member is a prop
2209
+ (memberFlags & 31 /* MEMBER_FLAGS.Prop */) !== 0 &&
2210
+ // the member is not mutable
2211
+ (memberFlags & 1024 /* MEMBER_FLAGS.Mutable */) === 0) {
2212
+ consoleDevWarn(`@Prop() "${memberName}" on <${cmpMeta.$tagName$}> is immutable but was modified from within the component.\nMore information: https://stenciljs.com/docs/properties#prop-mutability`);
2213
+ }
2214
+ }
2215
+ // proxyComponent, set value
2216
+ setValue(this, memberName, newValue, cmpMeta);
2217
+ },
2218
+ configurable: true,
2219
+ enumerable: true,
2220
+ });
2221
+ }
2222
+ else if (BUILD.lazyLoad &&
2223
+ BUILD.method &&
2224
+ flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
2225
+ memberFlags & 64 /* MEMBER_FLAGS.Method */) {
2226
+ // proxyComponent - method
2227
+ Object.defineProperty(prototype, memberName, {
2228
+ value(...args) {
2229
+ const ref = getHostRef(this);
2230
+ return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
2231
+ },
2232
+ });
2233
+ }
2234
+ });
2235
+ if (BUILD.observeAttribute && (!BUILD.lazyLoad || flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
2236
+ const attrNameToPropName = new Map();
2237
+ prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
2238
+ plt.jmp(() => {
2239
+ const propName = attrNameToPropName.get(attrName);
2240
+ // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
2241
+ // in the case where an attribute was set inline.
2242
+ // ```html
2243
+ // <my-component some-attribute="some-value"></my-component>
2244
+ // ```
2245
+ //
2246
+ // There is an edge case where a developer sets the attribute inline on a custom element and then
2247
+ // programmatically changes it before it has been upgraded as shown below:
2248
+ //
2249
+ // ```html
2250
+ // <!-- this component has _not_ been upgraded yet -->
2251
+ // <my-component id="test" some-attribute="some-value"></my-component>
2252
+ // <script>
2253
+ // // grab non-upgraded component
2254
+ // el = document.querySelector("#test");
2255
+ // el.someAttribute = "another-value";
2256
+ // // upgrade component
2257
+ // customElements.define('my-component', MyComponent);
2258
+ // </script>
2259
+ // ```
2260
+ // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
2261
+ // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
2262
+ // to the value that was set inline i.e. "some-value" from above example. When
2263
+ // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
2264
+ //
2265
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
2266
+ // by connectedCallback as this attributeChangedCallback will not fire.
2267
+ //
2268
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2269
+ //
2270
+ // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
2271
+ // properties here given that this goes against best practices outlined here
2272
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
2273
+ if (this.hasOwnProperty(propName)) {
2274
+ newValue = this[propName];
2275
+ delete this[propName];
2276
+ }
2277
+ else if (prototype.hasOwnProperty(propName) &&
2278
+ typeof this[propName] === 'number' &&
2279
+ this[propName] == newValue) {
2280
+ // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
2281
+ // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
2282
+ // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
2283
+ return;
2284
+ }
2285
+ this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
2286
+ });
2287
+ };
2288
+ // create an array of attributes to observe
2289
+ // and also create a map of html attribute name to js property name
2290
+ Cstr.observedAttributes = members
2291
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
2292
+ .map(([propName, m]) => {
2293
+ const attrName = m[1] || propName;
2294
+ attrNameToPropName.set(attrName, propName);
2295
+ if (BUILD.reflect && m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
2296
+ cmpMeta.$attrsToReflect$.push([propName, attrName]);
2297
+ }
2298
+ return attrName;
2299
+ });
2300
+ }
2301
+ }
2302
+ return Cstr;
2303
+ };
2304
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
2305
+ // initializeComponent
2306
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
2307
+ // Let the runtime know that the component has been initialized
2308
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
2309
+ if (BUILD.lazyLoad || BUILD.hydrateClientSide) {
2310
+ // lazy loaded components
2311
+ // request the component's implementation to be
2312
+ // wired up with the host element
2313
+ Cstr = loadModule(cmpMeta, hostRef, hmrVersionId);
2314
+ if (Cstr.then) {
2315
+ // Await creates a micro-task avoid if possible
2316
+ const endLoad = uniqueTime(`st:load:${cmpMeta.$tagName$}:${hostRef.$modeName$}`, `[Stencil] Load module for <${cmpMeta.$tagName$}>`);
2317
+ Cstr = await Cstr;
2318
+ endLoad();
2319
+ }
2320
+ if ((BUILD.isDev || BUILD.isDebug) && !Cstr) {
2321
+ throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
2322
+ }
2323
+ if (BUILD.member && !Cstr.isProxied) {
2324
+ // we've never proxied this Constructor before
2325
+ // let's add the getters/setters to its prototype before
2326
+ // the first time we create an instance of the implementation
2327
+ if (BUILD.watchCallback) {
2328
+ cmpMeta.$watchers$ = Cstr.watchers;
2329
+ }
2330
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
2331
+ Cstr.isProxied = true;
2332
+ }
2333
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
2334
+ // ok, time to construct the instance
2335
+ // but let's keep track of when we start and stop
2336
+ // so that the getters/setters don't incorrectly step on data
2337
+ if (BUILD.member) {
2338
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
2339
+ }
2340
+ // construct the lazy-loaded component implementation
2341
+ // passing the hostRef is very important during
2342
+ // construction in order to directly wire together the
2343
+ // host element and the lazy-loaded instance
2344
+ try {
2345
+ new Cstr(hostRef);
2346
+ }
2347
+ catch (e) {
2348
+ consoleError(e);
2349
+ }
2350
+ if (BUILD.member) {
2351
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
2352
+ }
2353
+ if (BUILD.watchCallback) {
2354
+ hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
2355
+ }
2356
+ endNewInstance();
2357
+ fireConnectedCallback(hostRef.$lazyInstance$);
2358
+ }
2359
+ else {
2360
+ // sync constructor component
2361
+ Cstr = elm.constructor;
2362
+ // wait for the CustomElementRegistry to mark the component as ready before setting `isWatchReady`. Otherwise,
2363
+ // watchers may fire prematurely if `customElements.get()`/`customElements.whenDefined()` resolves _before_
2364
+ // Stencil has completed instantiating the component.
2365
+ customElements.whenDefined(cmpMeta.$tagName$).then(() => (hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */));
2366
+ }
2367
+ if (BUILD.style && Cstr.style) {
2368
+ // this component has styles but we haven't registered them yet
2369
+ let style = Cstr.style;
2370
+ if (BUILD.mode && typeof style !== 'string') {
2371
+ style = style[(hostRef.$modeName$ = computeMode(elm))];
2372
+ if (BUILD.hydrateServerSide && hostRef.$modeName$) {
2373
+ elm.setAttribute('s-mode', hostRef.$modeName$);
2374
+ }
2375
+ }
2376
+ const scopeId = getScopeId(cmpMeta, hostRef.$modeName$);
2377
+ if (!styles.has(scopeId)) {
2378
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
2379
+ if (!BUILD.hydrateServerSide &&
2380
+ BUILD.shadowDom &&
2381
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2382
+ BUILD.shadowDomShim &&
2383
+ cmpMeta.$flags$ & 8 /* CMP_FLAGS.needsShadowDomShim */) {
2384
+ style = await import('./shadow-css-8a6ccf47.js').then((m) => m.scopeCss(style, scopeId, false));
2385
+ }
2386
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
2387
+ endRegisterStyles();
2388
+ }
2389
+ }
2390
+ }
2391
+ // we've successfully created a lazy instance
2392
+ const ancestorComponent = hostRef.$ancestorComponent$;
2393
+ const schedule = () => scheduleUpdate(hostRef, true);
2394
+ if (BUILD.asyncLoading && ancestorComponent && ancestorComponent['s-rc']) {
2395
+ // this is the initial load and this component it has an ancestor component
2396
+ // but the ancestor component has NOT fired its will update lifecycle yet
2397
+ // so let's just cool our jets and wait for the ancestor to continue first
2398
+ // this will get fired off when the ancestor component
2399
+ // finally gets around to rendering its lazy self
2400
+ // fire off the initial update
2401
+ ancestorComponent['s-rc'].push(schedule);
2402
+ }
2403
+ else {
2404
+ schedule();
2405
+ }
2406
+ };
2407
+ const fireConnectedCallback = (instance) => {
2408
+ if (BUILD.lazyLoad && BUILD.connectedCallback) {
2409
+ safeCall(instance, 'connectedCallback');
2410
+ }
2411
+ };
2412
+ const connectedCallback = (elm) => {
2413
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2414
+ const hostRef = getHostRef(elm);
2415
+ const cmpMeta = hostRef.$cmpMeta$;
2416
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
2417
+ if (BUILD.hostListenerTargetParent) {
2418
+ // only run if we have listeners being attached to a parent
2419
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, true);
2420
+ }
2421
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
2422
+ // first time this component has connected
2423
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
2424
+ let hostId;
2425
+ if (BUILD.hydrateClientSide) {
2426
+ hostId = elm.getAttribute(HYDRATE_ID);
2427
+ if (hostId) {
2428
+ if (BUILD.shadowDom && supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2429
+ const scopeId = BUILD.mode
2430
+ ? addStyle(elm.shadowRoot, cmpMeta, elm.getAttribute('s-mode'))
2431
+ : addStyle(elm.shadowRoot, cmpMeta);
2432
+ elm.classList.remove(scopeId + '-h', scopeId + '-s');
2433
+ }
2434
+ initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
2435
+ }
2436
+ }
2437
+ if (BUILD.slotRelocation && !hostId) {
2438
+ // initUpdate
2439
+ // if the slot polyfill is required we'll need to put some nodes
2440
+ // in here to act as original content anchors as we move nodes around
2441
+ // host element has been connected to the DOM
2442
+ if (BUILD.hydrateServerSide ||
2443
+ ((BUILD.slot || BUILD.shadowDom) &&
2444
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2445
+ cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
2446
+ setContentReference(elm);
2447
+ }
2448
+ }
2449
+ if (BUILD.asyncLoading) {
2450
+ // find the first ancestor component (if there is one) and register
2451
+ // this component as one of the actively loading child components for its ancestor
2452
+ let ancestorComponent = elm;
2453
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
2454
+ // climb up the ancestors looking for the first
2455
+ // component that hasn't finished its lifecycle update yet
2456
+ if ((BUILD.hydrateClientSide &&
2457
+ ancestorComponent.nodeType === 1 /* NODE_TYPE.ElementNode */ &&
2458
+ ancestorComponent.hasAttribute('s-id') &&
2459
+ ancestorComponent['s-p']) ||
2460
+ ancestorComponent['s-p']) {
2461
+ // we found this components first ancestor component
2462
+ // keep a reference to this component's ancestor component
2463
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
2464
+ break;
2465
+ }
2466
+ }
2467
+ }
2468
+ // Lazy properties
2469
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2470
+ if (BUILD.prop && !BUILD.hydrateServerSide && cmpMeta.$members$) {
2471
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
2472
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
2473
+ const value = elm[memberName];
2474
+ delete elm[memberName];
2475
+ elm[memberName] = value;
2476
+ }
2477
+ });
2478
+ }
2479
+ if (BUILD.initializeNextTick) {
2480
+ // connectedCallback, taskQueue, initialLoad
2481
+ // angular sets attribute AFTER connectCallback
2482
+ // https://github.com/angular/angular/issues/18909
2483
+ // https://github.com/angular/angular/issues/19940
2484
+ nextTick(() => initializeComponent(elm, hostRef, cmpMeta));
2485
+ }
2486
+ else {
2487
+ initializeComponent(elm, hostRef, cmpMeta);
2488
+ }
2489
+ }
2490
+ else {
2491
+ // not the first time this has connected
2492
+ // reattach any event listeners to the host
2493
+ // since they would have been removed when disconnected
2494
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2495
+ // fire off connectedCallback() on component instance
2496
+ fireConnectedCallback(hostRef.$lazyInstance$);
2497
+ }
2498
+ endConnected();
2499
+ }
2500
+ };
2501
+ const setContentReference = (elm) => {
2502
+ // only required when we're NOT using native shadow dom (slot)
2503
+ // or this browser doesn't support native shadow dom
2504
+ // and this host element was NOT created with SSR
2505
+ // let's pick out the inner content for slot projection
2506
+ // create a node to represent where the original
2507
+ // content was first placed, which is useful later on
2508
+ const contentRefElm = (elm['s-cr'] = doc.createComment(BUILD.isDebug ? `content-ref (host=${elm.localName})` : ''));
2509
+ contentRefElm['s-cn'] = true;
2510
+ elm.insertBefore(contentRefElm, elm.firstChild);
2511
+ };
2512
+ const disconnectedCallback = (elm) => {
2513
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2514
+ const hostRef = getHostRef(elm);
2515
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2516
+ if (BUILD.hostListener) {
2517
+ if (hostRef.$rmListeners$) {
2518
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
2519
+ hostRef.$rmListeners$ = undefined;
2520
+ }
2521
+ }
2522
+ if (BUILD.lazyLoad && BUILD.disconnectedCallback) {
2523
+ safeCall(instance, 'disconnectedCallback');
2524
+ }
2525
+ if (BUILD.cmpDidUnload) {
2526
+ safeCall(instance, 'componentDidUnload');
2527
+ }
2528
+ }
2529
+ };
2530
+ const defineCustomElement = (Cstr, compactMeta) => {
2531
+ customElements.define(compactMeta[1], proxyCustomElement(Cstr, compactMeta));
2532
+ };
2533
+ const proxyCustomElement = (Cstr, compactMeta) => {
2534
+ const cmpMeta = {
2535
+ $flags$: compactMeta[0],
2536
+ $tagName$: compactMeta[1],
2537
+ };
2538
+ if (BUILD.member) {
2539
+ cmpMeta.$members$ = compactMeta[2];
2540
+ }
2541
+ if (BUILD.hostListener) {
2542
+ cmpMeta.$listeners$ = compactMeta[3];
2543
+ }
2544
+ if (BUILD.watchCallback) {
2545
+ cmpMeta.$watchers$ = Cstr.$watchers$;
2546
+ }
2547
+ if (BUILD.reflect) {
2548
+ cmpMeta.$attrsToReflect$ = [];
2549
+ }
2550
+ if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2551
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2552
+ cmpMeta.$flags$ |= 8 /* CMP_FLAGS.needsShadowDomShim */;
2553
+ }
2554
+ const originalConnectedCallback = Cstr.prototype.connectedCallback;
2555
+ const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
2556
+ Object.assign(Cstr.prototype, {
2557
+ __registerHost() {
2558
+ registerHost(this, cmpMeta);
2559
+ },
2560
+ connectedCallback() {
2561
+ connectedCallback(this);
2562
+ if (BUILD.connectedCallback && originalConnectedCallback) {
2563
+ originalConnectedCallback.call(this);
2564
+ }
2565
+ },
2566
+ disconnectedCallback() {
2567
+ disconnectedCallback(this);
2568
+ if (BUILD.disconnectedCallback && originalDisconnectedCallback) {
2569
+ originalDisconnectedCallback.call(this);
2570
+ }
2571
+ },
2572
+ __attachShadow() {
2573
+ if (supportsShadow) {
2574
+ if (BUILD.shadowDelegatesFocus) {
2575
+ this.attachShadow({
2576
+ mode: 'open',
2577
+ delegatesFocus: !!(cmpMeta.$flags$ & 16 /* CMP_FLAGS.shadowDelegatesFocus */),
2578
+ });
2579
+ }
2580
+ else {
2581
+ this.attachShadow({ mode: 'open' });
2582
+ }
2583
+ }
2584
+ else {
2585
+ this.shadowRoot = this;
2586
+ }
2587
+ },
2588
+ });
2589
+ Cstr.is = cmpMeta.$tagName$;
2590
+ return proxyComponent(Cstr, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */ | 2 /* PROXY_FLAGS.proxyState */);
2591
+ };
2592
+ const forceModeUpdate = (elm) => {
2593
+ if (BUILD.style && BUILD.mode && !BUILD.lazyLoad) {
2594
+ const mode = computeMode(elm);
2595
+ const hostRef = getHostRef(elm);
2596
+ if (hostRef.$modeName$ !== mode) {
2597
+ const cmpMeta = hostRef.$cmpMeta$;
2598
+ const oldScopeId = elm['s-sc'];
2599
+ const scopeId = getScopeId(cmpMeta, mode);
2600
+ const style = elm.constructor.style[mode];
2601
+ const flags = cmpMeta.$flags$;
2602
+ if (style) {
2603
+ if (!styles.has(scopeId)) {
2604
+ registerStyle(scopeId, style, !!(flags & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
2605
+ }
2606
+ hostRef.$modeName$ = mode;
2607
+ elm.classList.remove(oldScopeId + '-h', oldScopeId + '-s');
2608
+ attachStyles(hostRef);
2609
+ forceUpdate(elm);
2610
+ }
2611
+ }
2612
+ }
2613
+ };
2614
+ const patchCloneNode = (HostElementPrototype) => {
2615
+ const orgCloneNode = HostElementPrototype.cloneNode;
2616
+ HostElementPrototype.cloneNode = function (deep) {
2617
+ const srcNode = this;
2618
+ const isShadowDom = BUILD.shadowDom ? srcNode.shadowRoot && supportsShadow : false;
2619
+ const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
2620
+ if (BUILD.slot && !isShadowDom && deep) {
2621
+ let i = 0;
2622
+ let slotted, nonStencilNode;
2623
+ const stencilPrivates = [
2624
+ 's-id',
2625
+ 's-cr',
2626
+ 's-lr',
2627
+ 's-rc',
2628
+ 's-sc',
2629
+ 's-p',
2630
+ 's-cn',
2631
+ 's-sr',
2632
+ 's-sn',
2633
+ 's-hn',
2634
+ 's-ol',
2635
+ 's-nr',
2636
+ 's-si',
2637
+ ];
2638
+ for (; i < srcNode.childNodes.length; i++) {
2639
+ slotted = srcNode.childNodes[i]['s-nr'];
2640
+ nonStencilNode = stencilPrivates.every((privateField) => !srcNode.childNodes[i][privateField]);
2641
+ if (slotted) {
2642
+ if (BUILD.appendChildSlotFix && clonedNode.__appendChild) {
2643
+ clonedNode.__appendChild(slotted.cloneNode(true));
2644
+ }
2645
+ else {
2646
+ clonedNode.appendChild(slotted.cloneNode(true));
2647
+ }
2648
+ }
2649
+ if (nonStencilNode) {
2650
+ clonedNode.appendChild(srcNode.childNodes[i].cloneNode(true));
2651
+ }
2652
+ }
2653
+ }
2654
+ return clonedNode;
2655
+ };
2656
+ };
2657
+ const patchSlotAppendChild = (HostElementPrototype) => {
2658
+ HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
2659
+ HostElementPrototype.appendChild = function (newChild) {
2660
+ const slotName = (newChild['s-sn'] = getSlotName(newChild));
2661
+ const slotNode = getHostSlotNode(this.childNodes, slotName);
2662
+ if (slotNode) {
2663
+ const slotChildNodes = getHostSlotChildNodes(slotNode, slotName);
2664
+ const appendAfter = slotChildNodes[slotChildNodes.length - 1];
2665
+ return appendAfter.parentNode.insertBefore(newChild, appendAfter.nextSibling);
2666
+ }
2667
+ return this.__appendChild(newChild);
2668
+ };
2669
+ };
2670
+ /**
2671
+ * Patches the text content of an unnamed slotted node inside a scoped component
2672
+ * @param hostElementPrototype the `Element` to be patched
2673
+ * @param cmpMeta component runtime metadata used to determine if the component should be patched or not
2674
+ */
2675
+ const patchTextContent = (hostElementPrototype, cmpMeta) => {
2676
+ if (BUILD.scoped && cmpMeta.$flags$ & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
2677
+ const descriptor = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
2678
+ Object.defineProperty(hostElementPrototype, '__textContent', descriptor);
2679
+ Object.defineProperty(hostElementPrototype, 'textContent', {
2680
+ get() {
2681
+ var _a;
2682
+ // get the 'default slot', which would be the first slot in a shadow tree (if we were using one), whose name is
2683
+ // the empty string
2684
+ const slotNode = getHostSlotNode(this.childNodes, '');
2685
+ // when a slot node is found, the textContent _may_ be found in the next sibling (text) node, depending on how
2686
+ // nodes were reordered during the vdom render. first try to get the text content from the sibling.
2687
+ if (((_a = slotNode === null || slotNode === void 0 ? void 0 : slotNode.nextSibling) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* NODE_TYPES.TEXT_NODE */) {
2688
+ return slotNode.nextSibling.textContent;
2689
+ }
2690
+ else if (slotNode) {
2691
+ return slotNode.textContent;
2692
+ }
2693
+ else {
2694
+ // fallback to the original implementation
2695
+ return this.__textContent;
2696
+ }
2697
+ },
2698
+ set(value) {
2699
+ var _a;
2700
+ // get the 'default slot', which would be the first slot in a shadow tree (if we were using one), whose name is
2701
+ // the empty string
2702
+ const slotNode = getHostSlotNode(this.childNodes, '');
2703
+ // when a slot node is found, the textContent _may_ need to be placed in the next sibling (text) node,
2704
+ // depending on how nodes were reordered during the vdom render. first try to set the text content on the
2705
+ // sibling.
2706
+ if (((_a = slotNode === null || slotNode === void 0 ? void 0 : slotNode.nextSibling) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* NODE_TYPES.TEXT_NODE */) {
2707
+ slotNode.nextSibling.textContent = value;
2708
+ }
2709
+ else if (slotNode) {
2710
+ slotNode.textContent = value;
2711
+ }
2712
+ else {
2713
+ // we couldn't find a slot, but that doesn't mean that there isn't one. if this check ran before the DOM
2714
+ // loaded, we could have missed it. check for a content reference element on the scoped component and insert
2715
+ // it there
2716
+ this.__textContent = value;
2717
+ const contentRefElm = this['s-cr'];
2718
+ if (contentRefElm) {
2719
+ this.insertBefore(contentRefElm, this.firstChild);
2720
+ }
2721
+ }
2722
+ },
2723
+ });
2724
+ }
2725
+ };
2726
+ const patchChildSlotNodes = (elm, cmpMeta) => {
2727
+ class FakeNodeList extends Array {
2728
+ item(n) {
2729
+ return this[n];
2730
+ }
2731
+ }
2732
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2733
+ if (cmpMeta.$flags$ & 8 /* CMP_FLAGS.needsShadowDomShim */) {
2734
+ const childNodesFn = elm.__lookupGetter__('childNodes');
2735
+ Object.defineProperty(elm, 'children', {
2736
+ get() {
2737
+ return this.childNodes.map((n) => n.nodeType === 1);
2738
+ },
2739
+ });
2740
+ Object.defineProperty(elm, 'childElementCount', {
2741
+ get() {
2742
+ return elm.children.length;
2743
+ },
2744
+ });
2745
+ Object.defineProperty(elm, 'childNodes', {
2746
+ get() {
2747
+ const childNodes = childNodesFn.call(this);
2748
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0 &&
2749
+ getHostRef(this).$flags$ & 2 /* HOST_FLAGS.hasRendered */) {
2750
+ const result = new FakeNodeList();
2751
+ for (let i = 0; i < childNodes.length; i++) {
2752
+ const slot = childNodes[i]['s-nr'];
2753
+ if (slot) {
2754
+ result.push(slot);
2755
+ }
2756
+ }
2757
+ return result;
2758
+ }
2759
+ return FakeNodeList.from(childNodes);
2760
+ },
2761
+ });
2762
+ }
2763
+ };
2764
+ const getSlotName = (node) => node['s-sn'] || (node.nodeType === 1 && node.getAttribute('slot')) || '';
2765
+ /**
2766
+ * Recursively searches a series of child nodes for a slot with the provided name.
2767
+ * @param childNodes the nodes to search for a slot with a specific name.
2768
+ * @param slotName the name of the slot to match on.
2769
+ * @returns a reference to the slot node that matches the provided name, `null` otherwise
2770
+ */
2771
+ const getHostSlotNode = (childNodes, slotName) => {
2772
+ let i = 0;
2773
+ let childNode;
2774
+ for (; i < childNodes.length; i++) {
2775
+ childNode = childNodes[i];
2776
+ if (childNode['s-sr'] && childNode['s-sn'] === slotName) {
2777
+ return childNode;
2778
+ }
2779
+ childNode = getHostSlotNode(childNode.childNodes, slotName);
2780
+ if (childNode) {
2781
+ return childNode;
2782
+ }
2783
+ }
2784
+ return null;
2785
+ };
2786
+ const getHostSlotChildNodes = (n, slotName) => {
2787
+ const childNodes = [n];
2788
+ while ((n = n.nextSibling) && n['s-sn'] === slotName) {
2789
+ childNodes.push(n);
2790
+ }
2791
+ return childNodes;
2792
+ };
2793
+ const hmrStart = (elm, cmpMeta, hmrVersionId) => {
2794
+ // ¯\_(ツ)_/¯
2795
+ const hostRef = getHostRef(elm);
2796
+ // reset state flags to only have been connected
2797
+ hostRef.$flags$ = 1 /* HOST_FLAGS.hasConnected */;
2798
+ // TODO
2799
+ // detatch any event listeners that may have been added
2800
+ // because we're not passing an exact event name it'll
2801
+ // remove all of this element's event, which is good
2802
+ // create a callback for when this component finishes hmr
2803
+ elm['s-hmr-load'] = () => {
2804
+ // finished hmr for this element
2805
+ delete elm['s-hmr-load'];
2806
+ };
2807
+ // re-initialize the component
2808
+ initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
2809
+ };
2810
+ const bootstrapLazy = (lazyBundles, options = {}) => {
2811
+ var _a;
2812
+ if (BUILD.profile && performance.mark) {
2813
+ performance.mark('st:app:start');
2814
+ }
2815
+ installDevTools();
2816
+ const endBootstrap = createTime('bootstrapLazy');
2817
+ const cmpTags = [];
2818
+ const exclude = options.exclude || [];
2819
+ const customElements = win.customElements;
2820
+ const head = doc.head;
2821
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
2822
+ const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
2823
+ const deferredConnectedCallbacks = [];
2824
+ const styles = /*@__PURE__*/ doc.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
2825
+ let appLoadFallback;
2826
+ let isBootstrapping = true;
2827
+ let i = 0;
2828
+ Object.assign(plt, options);
2829
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
2830
+ if (BUILD.asyncQueue) {
2831
+ if (options.syncQueue) {
2832
+ plt.$flags$ |= 4 /* PLATFORM_FLAGS.queueSync */;
2833
+ }
2834
+ }
2835
+ if (BUILD.hydrateClientSide) {
2836
+ // If the app is already hydrated there is not point to disable the
2837
+ // async queue. This will improve the first input delay
2838
+ plt.$flags$ |= 2 /* PLATFORM_FLAGS.appLoaded */;
2839
+ }
2840
+ if (BUILD.hydrateClientSide && BUILD.shadowDom) {
2841
+ for (; i < styles.length; i++) {
2842
+ registerStyle(styles[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styles[i].innerHTML), true);
2843
+ }
2844
+ }
2845
+ lazyBundles.map((lazyBundle) => {
2846
+ lazyBundle[1].map((compactMeta) => {
2847
+ const cmpMeta = {
2848
+ $flags$: compactMeta[0],
2849
+ $tagName$: compactMeta[1],
2850
+ $members$: compactMeta[2],
2851
+ $listeners$: compactMeta[3],
2852
+ };
2853
+ if (BUILD.member) {
2854
+ cmpMeta.$members$ = compactMeta[2];
2855
+ }
2856
+ if (BUILD.hostListener) {
2857
+ cmpMeta.$listeners$ = compactMeta[3];
2858
+ }
2859
+ if (BUILD.reflect) {
2860
+ cmpMeta.$attrsToReflect$ = [];
2861
+ }
2862
+ if (BUILD.watchCallback) {
2863
+ cmpMeta.$watchers$ = {};
2864
+ }
2865
+ if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2866
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2867
+ cmpMeta.$flags$ |= 8 /* CMP_FLAGS.needsShadowDomShim */;
2868
+ }
2869
+ const tagName = BUILD.transformTagName && options.transformTagName
2870
+ ? options.transformTagName(cmpMeta.$tagName$)
2871
+ : cmpMeta.$tagName$;
2872
+ const HostElement = class extends HTMLElement {
2873
+ // StencilLazyHost
2874
+ constructor(self) {
2875
+ // @ts-ignore
2876
+ super(self);
2877
+ self = this;
2878
+ registerHost(self, cmpMeta);
2879
+ if (BUILD.shadowDom && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2880
+ // this component is using shadow dom
2881
+ // and this browser supports shadow dom
2882
+ // add the read-only property "shadowRoot" to the host element
2883
+ // adding the shadow root build conditionals to minimize runtime
2884
+ if (supportsShadow) {
2885
+ if (BUILD.shadowDelegatesFocus) {
2886
+ self.attachShadow({
2887
+ mode: 'open',
2888
+ delegatesFocus: !!(cmpMeta.$flags$ & 16 /* CMP_FLAGS.shadowDelegatesFocus */),
2889
+ });
2890
+ }
2891
+ else {
2892
+ self.attachShadow({ mode: 'open' });
2893
+ }
2894
+ }
2895
+ else if (!BUILD.hydrateServerSide && !('shadowRoot' in self)) {
2896
+ self.shadowRoot = self;
2897
+ }
2898
+ }
2899
+ if (BUILD.slotChildNodesFix) {
2900
+ patchChildSlotNodes(self, cmpMeta);
2901
+ }
2902
+ }
2903
+ connectedCallback() {
2904
+ if (appLoadFallback) {
2905
+ clearTimeout(appLoadFallback);
2906
+ appLoadFallback = null;
2907
+ }
2908
+ if (isBootstrapping) {
2909
+ // connectedCallback will be processed once all components have been registered
2910
+ deferredConnectedCallbacks.push(this);
2911
+ }
2912
+ else {
2913
+ plt.jmp(() => connectedCallback(this));
2914
+ }
2915
+ }
2916
+ disconnectedCallback() {
2917
+ plt.jmp(() => disconnectedCallback(this));
2918
+ }
2919
+ componentOnReady() {
2920
+ return getHostRef(this).$onReadyPromise$;
2921
+ }
2922
+ };
2923
+ if (BUILD.cloneNodeFix) {
2924
+ patchCloneNode(HostElement.prototype);
2925
+ }
2926
+ if (BUILD.appendChildSlotFix) {
2927
+ patchSlotAppendChild(HostElement.prototype);
2928
+ }
2929
+ if (BUILD.hotModuleReplacement) {
2930
+ HostElement.prototype['s-hmr'] = function (hmrVersionId) {
2931
+ hmrStart(this, cmpMeta, hmrVersionId);
2932
+ };
2933
+ }
2934
+ if (BUILD.scopedSlotTextContentFix) {
2935
+ patchTextContent(HostElement.prototype, cmpMeta);
2936
+ }
2937
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
2938
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2939
+ cmpTags.push(tagName);
2940
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
2941
+ }
2942
+ });
2943
+ });
2944
+ if (BUILD.invisiblePrehydration && (BUILD.hydratedClass || BUILD.hydratedAttribute)) {
2945
+ visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
2946
+ visibilityStyle.setAttribute('data-styles', '');
2947
+ // Apply CSP nonce to the style tag if it exists
2948
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
2949
+ if (nonce != null) {
2950
+ visibilityStyle.setAttribute('nonce', nonce);
2951
+ }
2952
+ head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
2953
+ }
2954
+ // Process deferred connectedCallbacks now all components have been registered
2955
+ isBootstrapping = false;
2956
+ if (deferredConnectedCallbacks.length) {
2957
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
2958
+ }
2959
+ else {
2960
+ if (BUILD.profile) {
2961
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30, 'timeout')));
2962
+ }
2963
+ else {
2964
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
2965
+ }
2966
+ }
2967
+ // Fallback appLoad event
2968
+ endBootstrap();
2969
+ };
2970
+ const Fragment = (_, children) => children;
2971
+ const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
2972
+ if (BUILD.hostListener && listeners) {
2973
+ // this is called immediately within the element's constructor
2974
+ // initialize our event listeners on the host element
2975
+ // we do this now so that we can listen to events that may
2976
+ // have fired even before the instance is ready
2977
+ if (BUILD.hostListenerTargetParent) {
2978
+ // this component may have event listeners that should be attached to the parent
2979
+ if (attachParentListeners) {
2980
+ // this is being ran from within the connectedCallback
2981
+ // which is important so that we know the host element actually has a parent element
2982
+ // filter out the listeners to only have the ones that ARE being attached to the parent
2983
+ listeners = listeners.filter(([flags]) => flags & 32 /* LISTENER_FLAGS.TargetParent */);
2984
+ }
2985
+ else {
2986
+ // this is being ran from within the component constructor
2987
+ // everything BUT the parent element listeners should be attached at this time
2988
+ // filter out the listeners that are NOT being attached to the parent
2989
+ listeners = listeners.filter(([flags]) => !(flags & 32 /* LISTENER_FLAGS.TargetParent */));
2990
+ }
2991
+ }
2992
+ listeners.map(([flags, name, method]) => {
2993
+ const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
2994
+ const handler = hostListenerProxy(hostRef, method);
2995
+ const opts = hostListenerOpts(flags);
2996
+ plt.ael(target, name, handler, opts);
2997
+ (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
2998
+ });
2999
+ }
3000
+ };
3001
+ const hostListenerProxy = (hostRef, methodName) => (ev) => {
3002
+ try {
3003
+ if (BUILD.lazyLoad) {
3004
+ if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
3005
+ // instance is ready, let's call it's member method for this event
3006
+ hostRef.$lazyInstance$[methodName](ev);
3007
+ }
3008
+ else {
3009
+ (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
3010
+ }
3011
+ }
3012
+ else {
3013
+ hostRef.$hostElement$[methodName](ev);
3014
+ }
3015
+ }
3016
+ catch (e) {
3017
+ consoleError(e);
3018
+ }
3019
+ };
3020
+ const getHostListenerTarget = (elm, flags) => {
3021
+ if (BUILD.hostListenerTargetDocument && flags & 4 /* LISTENER_FLAGS.TargetDocument */)
3022
+ return doc;
3023
+ if (BUILD.hostListenerTargetWindow && flags & 8 /* LISTENER_FLAGS.TargetWindow */)
3024
+ return win;
3025
+ if (BUILD.hostListenerTargetBody && flags & 16 /* LISTENER_FLAGS.TargetBody */)
3026
+ return doc.body;
3027
+ if (BUILD.hostListenerTargetParent && flags & 32 /* LISTENER_FLAGS.TargetParent */)
3028
+ return elm.parentElement;
3029
+ return elm;
3030
+ };
3031
+ // prettier-ignore
3032
+ const hostListenerOpts = (flags) => supportsListenerOptions
3033
+ ? ({
3034
+ passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
3035
+ capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
3036
+ })
3037
+ : (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
3038
+ /**
3039
+ * Assigns the given value to the nonce property on the runtime platform object.
3040
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
3041
+ * @param nonce The value to be assigned to the platform nonce property.
3042
+ * @returns void
3043
+ */
3044
+ const setNonce = (nonce) => (plt.$nonce$ = nonce);
3045
+ const setPlatformOptions = (opts) => Object.assign(plt, opts);
3046
+ const insertVdomAnnotations = (doc, staticComponents) => {
3047
+ if (doc != null) {
3048
+ const docData = {
3049
+ hostIds: 0,
3050
+ rootLevelIds: 0,
3051
+ staticComponents: new Set(staticComponents),
3052
+ };
3053
+ const orgLocationNodes = [];
3054
+ parseVNodeAnnotations(doc, doc.body, docData, orgLocationNodes);
3055
+ orgLocationNodes.forEach((orgLocationNode) => {
3056
+ if (orgLocationNode != null) {
3057
+ const nodeRef = orgLocationNode['s-nr'];
3058
+ let hostId = nodeRef['s-host-id'];
3059
+ let nodeId = nodeRef['s-node-id'];
3060
+ let childId = `${hostId}.${nodeId}`;
3061
+ if (hostId == null) {
3062
+ hostId = 0;
3063
+ docData.rootLevelIds++;
3064
+ nodeId = docData.rootLevelIds;
3065
+ childId = `${hostId}.${nodeId}`;
3066
+ if (nodeRef.nodeType === 1 /* NODE_TYPE.ElementNode */) {
3067
+ nodeRef.setAttribute(HYDRATE_CHILD_ID, childId);
3068
+ }
3069
+ else if (nodeRef.nodeType === 3 /* NODE_TYPE.TextNode */) {
3070
+ if (hostId === 0) {
3071
+ const textContent = nodeRef.nodeValue.trim();
3072
+ if (textContent === '') {
3073
+ // useless whitespace node at the document root
3074
+ orgLocationNode.remove();
3075
+ return;
3076
+ }
3077
+ }
3078
+ const commentBeforeTextNode = doc.createComment(childId);
3079
+ commentBeforeTextNode.nodeValue = `${TEXT_NODE_ID}.${childId}`;
3080
+ nodeRef.parentNode.insertBefore(commentBeforeTextNode, nodeRef);
3081
+ }
3082
+ }
3083
+ let orgLocationNodeId = `${ORG_LOCATION_ID}.${childId}`;
3084
+ const orgLocationParentNode = orgLocationNode.parentElement;
3085
+ if (orgLocationParentNode) {
3086
+ if (orgLocationParentNode['s-en'] === '') {
3087
+ // ending with a "." means that the parent element
3088
+ // of this node's original location is a SHADOW dom element
3089
+ // and this node is apart of the root level light dom
3090
+ orgLocationNodeId += `.`;
3091
+ }
3092
+ else if (orgLocationParentNode['s-en'] === 'c') {
3093
+ // ending with a ".c" means that the parent element
3094
+ // of this node's original location is a SCOPED element
3095
+ // and this node is apart of the root level light dom
3096
+ orgLocationNodeId += `.c`;
3097
+ }
3098
+ }
3099
+ orgLocationNode.nodeValue = orgLocationNodeId;
3100
+ }
3101
+ });
3102
+ }
3103
+ };
3104
+ const parseVNodeAnnotations = (doc, node, docData, orgLocationNodes) => {
3105
+ if (node == null) {
3106
+ return;
3107
+ }
3108
+ if (node['s-nr'] != null) {
3109
+ orgLocationNodes.push(node);
3110
+ }
3111
+ if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
3112
+ node.childNodes.forEach((childNode) => {
3113
+ const hostRef = getHostRef(childNode);
3114
+ if (hostRef != null && !docData.staticComponents.has(childNode.nodeName.toLowerCase())) {
3115
+ const cmpData = {
3116
+ nodeIds: 0,
3117
+ };
3118
+ insertVNodeAnnotations(doc, childNode, hostRef.$vnode$, docData, cmpData);
3119
+ }
3120
+ parseVNodeAnnotations(doc, childNode, docData, orgLocationNodes);
3121
+ });
3122
+ }
3123
+ };
3124
+ const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
3125
+ if (vnode != null) {
3126
+ const hostId = ++docData.hostIds;
3127
+ hostElm.setAttribute(HYDRATE_ID, hostId);
3128
+ if (hostElm['s-cr'] != null) {
3129
+ hostElm['s-cr'].nodeValue = `${CONTENT_REF_ID}.${hostId}`;
3130
+ }
3131
+ if (vnode.$children$ != null) {
3132
+ const depth = 0;
3133
+ vnode.$children$.forEach((vnodeChild, index) => {
3134
+ insertChildVNodeAnnotations(doc, vnodeChild, cmpData, hostId, depth, index);
3135
+ });
3136
+ }
3137
+ if (hostElm && vnode && vnode.$elm$ && !hostElm.hasAttribute('c-id')) {
3138
+ const parent = hostElm.parentElement;
3139
+ if (parent && parent.childNodes) {
3140
+ const parentChildNodes = Array.from(parent.childNodes);
3141
+ const comment = parentChildNodes.find((node) => node.nodeType === 8 /* NODE_TYPE.CommentNode */ && node['s-sr']);
3142
+ if (comment) {
3143
+ const index = parentChildNodes.indexOf(hostElm) - 1;
3144
+ vnode.$elm$.setAttribute(HYDRATE_CHILD_ID, `${comment['s-host-id']}.${comment['s-node-id']}.0.${index}`);
3145
+ }
3146
+ }
3147
+ }
3148
+ }
3149
+ };
3150
+ const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, index) => {
3151
+ const childElm = vnodeChild.$elm$;
3152
+ if (childElm == null) {
3153
+ return;
3154
+ }
3155
+ const nodeId = cmpData.nodeIds++;
3156
+ const childId = `${hostId}.${nodeId}.${depth}.${index}`;
3157
+ childElm['s-host-id'] = hostId;
3158
+ childElm['s-node-id'] = nodeId;
3159
+ if (childElm.nodeType === 1 /* NODE_TYPE.ElementNode */) {
3160
+ childElm.setAttribute(HYDRATE_CHILD_ID, childId);
3161
+ }
3162
+ else if (childElm.nodeType === 3 /* NODE_TYPE.TextNode */) {
3163
+ const parentNode = childElm.parentNode;
3164
+ const nodeName = parentNode.nodeName;
3165
+ if (nodeName !== 'STYLE' && nodeName !== 'SCRIPT') {
3166
+ const textNodeId = `${TEXT_NODE_ID}.${childId}`;
3167
+ const commentBeforeTextNode = doc.createComment(textNodeId);
3168
+ parentNode.insertBefore(commentBeforeTextNode, childElm);
3169
+ }
3170
+ }
3171
+ else if (childElm.nodeType === 8 /* NODE_TYPE.CommentNode */) {
3172
+ if (childElm['s-sr']) {
3173
+ const slotName = childElm['s-sn'] || '';
3174
+ const slotNodeId = `${SLOT_NODE_ID}.${childId}.${slotName}`;
3175
+ childElm.nodeValue = slotNodeId;
3176
+ }
3177
+ }
3178
+ if (vnodeChild.$children$ != null) {
3179
+ const childDepth = depth + 1;
3180
+ vnodeChild.$children$.forEach((vnode, index) => {
3181
+ insertChildVNodeAnnotations(doc, vnode, cmpData, hostId, childDepth, index);
3182
+ });
3183
+ }
3184
+ };
3185
+ const hostRefs = /*@__PURE__*/ new WeakMap();
3186
+ const getHostRef = (ref) => hostRefs.get(ref);
3187
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
3188
+ const registerHost = (elm, cmpMeta) => {
3189
+ const hostRef = {
3190
+ $flags$: 0,
3191
+ $hostElement$: elm,
3192
+ $cmpMeta$: cmpMeta,
3193
+ $instanceValues$: new Map(),
3194
+ };
3195
+ if (BUILD.isDev) {
3196
+ hostRef.$renderCount$ = 0;
3197
+ }
3198
+ if (BUILD.method && BUILD.lazyLoad) {
3199
+ hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
3200
+ }
3201
+ if (BUILD.asyncLoading) {
3202
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
3203
+ elm['s-p'] = [];
3204
+ elm['s-rc'] = [];
3205
+ }
3206
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
3207
+ return hostRefs.set(elm, hostRef);
3208
+ };
3209
+ const isMemberInElement = (elm, memberName) => memberName in elm;
3210
+ const consoleError = (e, el) => (customError || console.error)(e, el);
3211
+ const STENCIL_DEV_MODE = BUILD.isTesting
3212
+ ? ['STENCIL:'] // E2E testing
3213
+ : [
3214
+ '%cstencil',
3215
+ 'color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px',
3216
+ ];
3217
+ const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
3218
+ const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
3219
+ const consoleDevInfo = (...m) => console.info(...STENCIL_DEV_MODE, ...m);
3220
+ const setErrorHandler = (handler) => (customError = handler);
3221
+ const cmpModules = /*@__PURE__*/ new Map();
3222
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
3223
+ // loadModuleImport
3224
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
3225
+ const bundleId = cmpMeta.$lazyBundleId$;
3226
+ if (BUILD.isDev && typeof bundleId !== 'string') {
3227
+ consoleDevError(`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`);
3228
+ return undefined;
3229
+ }
3230
+ const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
3231
+ if (module) {
3232
+ return module[exportName];
3233
+ }
3234
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
3235
+ return import(
3236
+ /* @vite-ignore */
3237
+ /* webpackInclude: /\.entry\.js$/ */
3238
+ /* webpackExclude: /\.system\.entry\.js$/ */
3239
+ /* webpackMode: "lazy" */
3240
+ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`).then((importedModule) => {
3241
+ if (!BUILD.hotModuleReplacement) {
3242
+ cmpModules.set(bundleId, importedModule);
3243
+ }
3244
+ return importedModule[exportName];
3245
+ }, consoleError);
3246
+ };
3247
+ const styles = /*@__PURE__*/ new Map();
3248
+ const modeResolutionChain = [];
3249
+ const win = typeof window !== 'undefined' ? window : {};
3250
+ const doc = win.document || { head: {} };
3251
+ const H = (win.HTMLElement || class {
3252
+ });
3253
+ const plt = {
3254
+ $flags$: 0,
3255
+ $resourcesUrl$: '',
3256
+ jmp: (h) => h(),
3257
+ raf: (h) => requestAnimationFrame(h),
3258
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
3259
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
3260
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
3261
+ };
3262
+ const setPlatformHelpers = (helpers) => {
3263
+ Object.assign(plt, helpers);
3264
+ };
3265
+ const supportsShadow =
3266
+ // TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
3267
+ BUILD.shadowDomShim && BUILD.shadowDom
3268
+ ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)()
3269
+ : true;
3270
+ const supportsListenerOptions = /*@__PURE__*/ (() => {
3271
+ let supportsListenerOptions = false;
3272
+ try {
3273
+ doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
3274
+ get() {
3275
+ supportsListenerOptions = true;
3276
+ },
3277
+ }));
3278
+ }
3279
+ catch (e) { }
3280
+ return supportsListenerOptions;
3281
+ })();
3282
+ const promiseResolve = (v) => Promise.resolve(v);
3283
+ const supportsConstructableStylesheets = BUILD.constructableCSS
3284
+ ? /*@__PURE__*/ (() => {
3285
+ try {
3286
+ new CSSStyleSheet();
3287
+ return typeof new CSSStyleSheet().replaceSync === 'function';
3288
+ }
3289
+ catch (e) { }
3290
+ return false;
3291
+ })()
3292
+ : false;
3293
+ const queueDomReads = [];
3294
+ const queueDomWrites = [];
3295
+ const queueDomWritesLow = [];
3296
+ const queueTask = (queue, write) => (cb) => {
3297
+ queue.push(cb);
3298
+ if (!queuePending) {
3299
+ queuePending = true;
3300
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
3301
+ nextTick(flush);
3302
+ }
3303
+ else {
3304
+ plt.raf(flush);
3305
+ }
3306
+ }
3307
+ };
3308
+ const consume = (queue) => {
3309
+ for (let i = 0; i < queue.length; i++) {
3310
+ try {
3311
+ queue[i](performance.now());
3312
+ }
3313
+ catch (e) {
3314
+ consoleError(e);
3315
+ }
3316
+ }
3317
+ queue.length = 0;
3318
+ };
3319
+ const consumeTimeout = (queue, timeout) => {
3320
+ let i = 0;
3321
+ let ts = 0;
3322
+ while (i < queue.length && (ts = performance.now()) < timeout) {
3323
+ try {
3324
+ queue[i++](ts);
3325
+ }
3326
+ catch (e) {
3327
+ consoleError(e);
3328
+ }
3329
+ }
3330
+ if (i === queue.length) {
3331
+ queue.length = 0;
3332
+ }
3333
+ else if (i !== 0) {
3334
+ queue.splice(0, i);
3335
+ }
3336
+ };
3337
+ const flush = () => {
3338
+ if (BUILD.asyncQueue) {
3339
+ queueCongestion++;
3340
+ }
3341
+ // always force a bunch of medium callbacks to run, but still have
3342
+ // a throttle on how many can run in a certain time
3343
+ // DOM READS!!!
3344
+ consume(queueDomReads);
3345
+ // DOM WRITES!!!
3346
+ if (BUILD.asyncQueue) {
3347
+ const timeout = (plt.$flags$ & 6 /* PLATFORM_FLAGS.queueMask */) === 2 /* PLATFORM_FLAGS.appLoaded */
3348
+ ? performance.now() + 14 * Math.ceil(queueCongestion * (1.0 / 10.0))
3349
+ : Infinity;
3350
+ consumeTimeout(queueDomWrites, timeout);
3351
+ consumeTimeout(queueDomWritesLow, timeout);
3352
+ if (queueDomWrites.length > 0) {
3353
+ queueDomWritesLow.push(...queueDomWrites);
3354
+ queueDomWrites.length = 0;
3355
+ }
3356
+ if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
3357
+ // still more to do yet, but we've run out of time
3358
+ // let's let this thing cool off and try again in the next tick
3359
+ plt.raf(flush);
3360
+ }
3361
+ else {
3362
+ queueCongestion = 0;
3363
+ }
3364
+ }
3365
+ else {
3366
+ consume(queueDomWrites);
3367
+ if ((queuePending = queueDomReads.length > 0)) {
3368
+ // still more to do yet, but we've run out of time
3369
+ // let's let this thing cool off and try again in the next tick
3370
+ plt.raf(flush);
3371
+ }
3372
+ }
3373
+ };
3374
+ const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
3375
+ const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
3376
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
3377
+
3378
+ export { BUILD as B, H, NAMESPACE as N, Build as a, bootstrapLazy as b, consoleDevInfo as c, doc as d, Host as e, getElement as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
3379
+
3380
+ //# sourceMappingURL=index-57856b47.js.map