dash-button-web 0.0.1

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/dash-button.cjs.entry.js +2549 -0
  3. package/dist/cjs/dash-button.cjs.entry.js.map +1 -0
  4. package/dist/cjs/index-8282b36b.js +1733 -0
  5. package/dist/cjs/index-8282b36b.js.map +1 -0
  6. package/dist/cjs/index.cjs.js +4 -0
  7. package/dist/cjs/index.cjs.js.map +1 -0
  8. package/dist/cjs/loader.cjs.js +15 -0
  9. package/dist/cjs/loader.cjs.js.map +1 -0
  10. package/dist/cjs/web-compnont.cjs.js +25 -0
  11. package/dist/cjs/web-compnont.cjs.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +12 -0
  13. package/dist/collection/components/my-component/dash-button.css +169 -0
  14. package/dist/collection/components/my-component/dash-button.e2e.js +26 -0
  15. package/dist/collection/components/my-component/dash-button.e2e.js.map +1 -0
  16. package/dist/collection/components/my-component/dash-button.js +195 -0
  17. package/dist/collection/components/my-component/dash-button.js.map +1 -0
  18. package/dist/collection/components/my-component/dash-button.spec.js +35 -0
  19. package/dist/collection/components/my-component/dash-button.spec.js.map +1 -0
  20. package/dist/collection/index.js +2 -0
  21. package/dist/collection/index.js.map +1 -0
  22. package/dist/components/dash-button.d.ts +11 -0
  23. package/dist/components/dash-button.js +2574 -0
  24. package/dist/components/dash-button.js.map +1 -0
  25. package/dist/components/index.d.ts +33 -0
  26. package/dist/components/index.js +3 -0
  27. package/dist/components/index.js.map +1 -0
  28. package/dist/esm/dash-button.entry.js +2545 -0
  29. package/dist/esm/dash-button.entry.js.map +1 -0
  30. package/dist/esm/index-2b6c17bc.js +1706 -0
  31. package/dist/esm/index-2b6c17bc.js.map +1 -0
  32. package/dist/esm/index.js +3 -0
  33. package/dist/esm/index.js.map +1 -0
  34. package/dist/esm/loader.js +11 -0
  35. package/dist/esm/loader.js.map +1 -0
  36. package/dist/esm/polyfills/core-js.js +11 -0
  37. package/dist/esm/polyfills/dom.js +79 -0
  38. package/dist/esm/polyfills/es5-html-element.js +1 -0
  39. package/dist/esm/polyfills/index.js +34 -0
  40. package/dist/esm/polyfills/system.js +6 -0
  41. package/dist/esm/web-compnont.js +20 -0
  42. package/dist/esm/web-compnont.js.map +1 -0
  43. package/dist/index.cjs.js +1 -0
  44. package/dist/index.js +1 -0
  45. package/dist/types/components/my-component/dash-button.d.ts +19 -0
  46. package/dist/types/components.d.ts +49 -0
  47. package/dist/types/index.d.ts +1 -0
  48. package/dist/types/stencil-public-runtime.d.ts +1681 -0
  49. package/dist/web-compnont/index.esm.js +2 -0
  50. package/dist/web-compnont/index.esm.js.map +1 -0
  51. package/dist/web-compnont/p-35259f64.js +3 -0
  52. package/dist/web-compnont/p-35259f64.js.map +1 -0
  53. package/dist/web-compnont/p-97a6df2d.entry.js +10 -0
  54. package/dist/web-compnont/p-97a6df2d.entry.js.map +1 -0
  55. package/dist/web-compnont/web-compnont.esm.js +2 -0
  56. package/dist/web-compnont/web-compnont.esm.js.map +1 -0
  57. package/loader/cdn.js +3 -0
  58. package/loader/index.cjs.js +3 -0
  59. package/loader/index.d.ts +21 -0
  60. package/loader/index.es2017.js +3 -0
  61. package/loader/index.js +4 -0
  62. package/loader/package.json +11 -0
  63. package/package.json +41 -0
  64. package/readme.md +124 -0
@@ -0,0 +1,1733 @@
1
+ 'use strict';
2
+
3
+ function _interopNamespace(e) {
4
+ if (e && e.__esModule) return e;
5
+ var n = Object.create(null);
6
+ if (e) {
7
+ Object.keys(e).forEach(function (k) {
8
+ if (k !== 'default') {
9
+ var d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: function () {
13
+ return e[k];
14
+ }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n['default'] = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ const NAMESPACE = 'web-compnont';
24
+
25
+ /**
26
+ * Virtual DOM patching algorithm based on Snabbdom by
27
+ * Simon Friis Vindum (@paldepind)
28
+ * Licensed under the MIT License
29
+ * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
30
+ *
31
+ * Modified for Stencil's renderer and slot projection
32
+ */
33
+ let scopeId;
34
+ let hostTagName;
35
+ let isSvgMode = false;
36
+ let queuePending = false;
37
+ const createTime = (fnName, tagName = '') => {
38
+ {
39
+ return () => {
40
+ return;
41
+ };
42
+ }
43
+ };
44
+ const uniqueTime = (key, measureText) => {
45
+ {
46
+ return () => {
47
+ return;
48
+ };
49
+ }
50
+ };
51
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
52
+ /**
53
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
54
+ *
55
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
56
+ * support as of Stencil v4.
57
+ */
58
+ const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
59
+ /**
60
+ * Default style mode id
61
+ */
62
+ /**
63
+ * Reusable empty obj/array
64
+ * Don't add values to these!!
65
+ */
66
+ const EMPTY_OBJ = {};
67
+ const isDef = (v) => v != null;
68
+ /**
69
+ * Check whether a value is a 'complex type', defined here as an object or a
70
+ * function.
71
+ *
72
+ * @param o the value to check
73
+ * @returns whether it's a complex type or not
74
+ */
75
+ const isComplexType = (o) => {
76
+ // https://jsperf.com/typeof-fn-object/5
77
+ o = typeof o;
78
+ return o === 'object' || o === 'function';
79
+ };
80
+ /**
81
+ * Helper method for querying a `meta` tag that contains a nonce value
82
+ * out of a DOM's head.
83
+ *
84
+ * @param doc The DOM containing the `head` to query against
85
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
86
+ * exists or the tag has no content.
87
+ */
88
+ function queryNonceMetaTagContent(doc) {
89
+ var _a, _b, _c;
90
+ 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;
91
+ }
92
+ /**
93
+ * Production h() function based on Preact by
94
+ * Jason Miller (@developit)
95
+ * Licensed under the MIT License
96
+ * https://github.com/developit/preact/blob/master/LICENSE
97
+ *
98
+ * Modified for Stencil's compiler and vdom
99
+ */
100
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
101
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
102
+ const h = (nodeName, vnodeData, ...children) => {
103
+ let child = null;
104
+ let key = null;
105
+ let simple = false;
106
+ let lastSimple = false;
107
+ const vNodeChildren = [];
108
+ const walk = (c) => {
109
+ for (let i = 0; i < c.length; i++) {
110
+ child = c[i];
111
+ if (Array.isArray(child)) {
112
+ walk(child);
113
+ }
114
+ else if (child != null && typeof child !== 'boolean') {
115
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
116
+ child = String(child);
117
+ }
118
+ if (simple && lastSimple) {
119
+ // If the previous child was simple (string), we merge both
120
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
121
+ }
122
+ else {
123
+ // Append a new vNode, if it's text, we create a text vNode
124
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
125
+ }
126
+ lastSimple = simple;
127
+ }
128
+ }
129
+ };
130
+ walk(children);
131
+ if (vnodeData) {
132
+ if (vnodeData.key) {
133
+ key = vnodeData.key;
134
+ }
135
+ // normalize class / className attributes
136
+ {
137
+ const classData = vnodeData.className || vnodeData.class;
138
+ if (classData) {
139
+ vnodeData.class =
140
+ typeof classData !== 'object'
141
+ ? classData
142
+ : Object.keys(classData)
143
+ .filter((k) => classData[k])
144
+ .join(' ');
145
+ }
146
+ }
147
+ }
148
+ const vnode = newVNode(nodeName, null);
149
+ vnode.$attrs$ = vnodeData;
150
+ if (vNodeChildren.length > 0) {
151
+ vnode.$children$ = vNodeChildren;
152
+ }
153
+ {
154
+ vnode.$key$ = key;
155
+ }
156
+ return vnode;
157
+ };
158
+ /**
159
+ * A utility function for creating a virtual DOM node from a tag and some
160
+ * possible text content.
161
+ *
162
+ * @param tag the tag for this element
163
+ * @param text possible text content for the node
164
+ * @returns a newly-minted virtual DOM node
165
+ */
166
+ const newVNode = (tag, text) => {
167
+ const vnode = {
168
+ $flags$: 0,
169
+ $tag$: tag,
170
+ $text$: text,
171
+ $elm$: null,
172
+ $children$: null,
173
+ };
174
+ {
175
+ vnode.$attrs$ = null;
176
+ }
177
+ {
178
+ vnode.$key$ = null;
179
+ }
180
+ return vnode;
181
+ };
182
+ const Host = {};
183
+ /**
184
+ * Check whether a given node is a Host node or not
185
+ *
186
+ * @param node the virtual DOM node to check
187
+ * @returns whether it's a Host node or not
188
+ */
189
+ const isHost = (node) => node && node.$tag$ === Host;
190
+ /**
191
+ * Parse a new property value for a given property type.
192
+ *
193
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
194
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
195
+ * 1. `any`, the type given to `propValue` in the function signature
196
+ * 2. the type stored from `propType`.
197
+ *
198
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
199
+ *
200
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
201
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
202
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
203
+ * ```tsx
204
+ * <my-cmp prop-val={0}></my-cmp>
205
+ * ```
206
+ *
207
+ * HTML prop values on the other hand, will always a string
208
+ *
209
+ * @param propValue the new value to coerce to some type
210
+ * @param propType the type of the prop, expressed as a binary number
211
+ * @returns the parsed/coerced value
212
+ */
213
+ const parsePropertyValue = (propValue, propType) => {
214
+ // ensure this value is of the correct prop type
215
+ if (propValue != null && !isComplexType(propValue)) {
216
+ if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
217
+ // per the HTML spec, any string value means it is a boolean true value
218
+ // but we'll cheat here and say that the string "false" is the boolean false
219
+ return propValue === 'false' ? false : propValue === '' || !!propValue;
220
+ }
221
+ if (propType & 1 /* MEMBER_FLAGS.String */) {
222
+ // could have been passed as a number or boolean
223
+ // but we still want it as a string
224
+ return String(propValue);
225
+ }
226
+ // redundant return here for better minification
227
+ return propValue;
228
+ }
229
+ // not sure exactly what type we want
230
+ // so no need to change to a different type
231
+ return propValue;
232
+ };
233
+ const getElement = (ref) => (getHostRef(ref).$hostElement$ );
234
+ /**
235
+ * Helper function to create & dispatch a custom Event on a provided target
236
+ * @param elm the target of the Event
237
+ * @param name the name to give the custom Event
238
+ * @param opts options for configuring a custom Event
239
+ * @returns the custom Event
240
+ */
241
+ const emitEvent = (elm, name, opts) => {
242
+ const ev = plt.ce(name, opts);
243
+ elm.dispatchEvent(ev);
244
+ return ev;
245
+ };
246
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
247
+ const registerStyle = (scopeId, cssText, allowCS) => {
248
+ let style = styles.get(scopeId);
249
+ if (supportsConstructableStylesheets && allowCS) {
250
+ style = (style || new CSSStyleSheet());
251
+ if (typeof style === 'string') {
252
+ style = cssText;
253
+ }
254
+ else {
255
+ style.replaceSync(cssText);
256
+ }
257
+ }
258
+ else {
259
+ style = cssText;
260
+ }
261
+ styles.set(scopeId, style);
262
+ };
263
+ const addStyle = (styleContainerNode, cmpMeta, mode) => {
264
+ var _a;
265
+ const scopeId = getScopeId(cmpMeta);
266
+ const style = styles.get(scopeId);
267
+ // if an element is NOT connected then getRootNode() will return the wrong root node
268
+ // so the fallback is to always use the document for the root node in those cases
269
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
270
+ if (style) {
271
+ if (typeof style === 'string') {
272
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
273
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
274
+ let styleElm;
275
+ if (!appliedStyles) {
276
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
277
+ }
278
+ if (!appliedStyles.has(scopeId)) {
279
+ {
280
+ styleElm = doc.createElement('style');
281
+ styleElm.innerHTML = style;
282
+ // Apply CSP nonce to the style tag if it exists
283
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
284
+ if (nonce != null) {
285
+ styleElm.setAttribute('nonce', nonce);
286
+ }
287
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
288
+ }
289
+ // Add styles for `slot-fb` elements if we're using slots outside the Shadow DOM
290
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
291
+ styleElm.innerHTML += SLOT_FB_CSS;
292
+ }
293
+ if (appliedStyles) {
294
+ appliedStyles.add(scopeId);
295
+ }
296
+ }
297
+ }
298
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
299
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
300
+ }
301
+ }
302
+ return scopeId;
303
+ };
304
+ const attachStyles = (hostRef) => {
305
+ const cmpMeta = hostRef.$cmpMeta$;
306
+ const elm = hostRef.$hostElement$;
307
+ const flags = cmpMeta.$flags$;
308
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
309
+ const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
310
+ if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
311
+ // only required when we're NOT using native shadow dom (slot)
312
+ // or this browser doesn't support native shadow dom
313
+ // and this host element was NOT created with SSR
314
+ // let's pick out the inner content for slot projection
315
+ // create a node to represent where the original
316
+ // content was first placed, which is useful later on
317
+ // DOM WRITE!!
318
+ elm['s-sc'] = scopeId;
319
+ elm.classList.add(scopeId + '-h');
320
+ }
321
+ endAttachStyles();
322
+ };
323
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
324
+ /**
325
+ * Production setAccessor() function based on Preact by
326
+ * Jason Miller (@developit)
327
+ * Licensed under the MIT License
328
+ * https://github.com/developit/preact/blob/master/LICENSE
329
+ *
330
+ * Modified for Stencil's compiler and vdom
331
+ */
332
+ /**
333
+ * When running a VDom render set properties present on a VDom node onto the
334
+ * corresponding HTML element.
335
+ *
336
+ * Note that this function has special functionality for the `class`,
337
+ * `style`, `key`, and `ref` attributes, as well as event handlers (like
338
+ * `onClick`, etc). All others are just passed through as-is.
339
+ *
340
+ * @param elm the HTMLElement onto which attributes should be set
341
+ * @param memberName the name of the attribute to set
342
+ * @param oldValue the old value for the attribute
343
+ * @param newValue the new value for the attribute
344
+ * @param isSvg whether we're in an svg context or not
345
+ * @param flags bitflags for Vdom variables
346
+ */
347
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
348
+ if (oldValue !== newValue) {
349
+ let isProp = isMemberInElement(elm, memberName);
350
+ let ln = memberName.toLowerCase();
351
+ if (memberName === 'class') {
352
+ const classList = elm.classList;
353
+ const oldClasses = parseClassList(oldValue);
354
+ const newClasses = parseClassList(newValue);
355
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
356
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
357
+ }
358
+ else if (memberName === 'key')
359
+ ;
360
+ else if ((!isProp ) &&
361
+ memberName[0] === 'o' &&
362
+ memberName[1] === 'n') {
363
+ // Event Handlers
364
+ // so if the member name starts with "on" and the 3rd characters is
365
+ // a capital letter, and it's not already a member on the element,
366
+ // then we're assuming it's an event listener
367
+ if (memberName[2] === '-') {
368
+ // on- prefixed events
369
+ // allows to be explicit about the dom event to listen without any magic
370
+ // under the hood:
371
+ // <my-cmp on-click> // listens for "click"
372
+ // <my-cmp on-Click> // listens for "Click"
373
+ // <my-cmp on-ionChange> // listens for "ionChange"
374
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
375
+ memberName = memberName.slice(3);
376
+ }
377
+ else if (isMemberInElement(win, ln)) {
378
+ // standard event
379
+ // the JSX attribute could have been "onMouseOver" and the
380
+ // member name "onmouseover" is on the window's prototype
381
+ // so let's add the listener "mouseover", which is all lowercased
382
+ memberName = ln.slice(2);
383
+ }
384
+ else {
385
+ // custom event
386
+ // the JSX attribute could have been "onMyCustomEvent"
387
+ // so let's trim off the "on" prefix and lowercase the first character
388
+ // and add the listener "myCustomEvent"
389
+ // except for the first character, we keep the event name case
390
+ memberName = ln[2] + memberName.slice(3);
391
+ }
392
+ if (oldValue || newValue) {
393
+ // Need to account for "capture" events.
394
+ // If the event name ends with "Capture", we'll update the name to remove
395
+ // the "Capture" suffix and make sure the event listener is setup to handle the capture event.
396
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
397
+ // Make sure we only replace the last instance of "Capture"
398
+ memberName = memberName.replace(CAPTURE_EVENT_REGEX, '');
399
+ if (oldValue) {
400
+ plt.rel(elm, memberName, oldValue, capture);
401
+ }
402
+ if (newValue) {
403
+ plt.ael(elm, memberName, newValue, capture);
404
+ }
405
+ }
406
+ }
407
+ else {
408
+ // Set property if it exists and it's not a SVG
409
+ const isComplex = isComplexType(newValue);
410
+ if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
411
+ try {
412
+ if (!elm.tagName.includes('-')) {
413
+ const n = newValue == null ? '' : newValue;
414
+ // Workaround for Safari, moving the <input> caret when re-assigning the same valued
415
+ if (memberName === 'list') {
416
+ isProp = false;
417
+ }
418
+ else if (oldValue == null || elm[memberName] != n) {
419
+ elm[memberName] = n;
420
+ }
421
+ }
422
+ else {
423
+ elm[memberName] = newValue;
424
+ }
425
+ }
426
+ catch (e) {
427
+ /**
428
+ * in case someone tries to set a read-only property, e.g. "namespaceURI", we just ignore it
429
+ */
430
+ }
431
+ }
432
+ if (newValue == null || newValue === false) {
433
+ if (newValue !== false || elm.getAttribute(memberName) === '') {
434
+ {
435
+ elm.removeAttribute(memberName);
436
+ }
437
+ }
438
+ }
439
+ else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
440
+ newValue = newValue === true ? '' : newValue;
441
+ {
442
+ elm.setAttribute(memberName, newValue);
443
+ }
444
+ }
445
+ }
446
+ }
447
+ };
448
+ const parseClassListRegex = /\s/;
449
+ /**
450
+ * Parsed a string of classnames into an array
451
+ * @param value className string, e.g. "foo bar baz"
452
+ * @returns list of classes, e.g. ["foo", "bar", "baz"]
453
+ */
454
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
455
+ const CAPTURE_EVENT_SUFFIX = 'Capture';
456
+ const CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + '$');
457
+ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
458
+ // if the element passed in is a shadow root, which is a document fragment
459
+ // then we want to be adding attrs/props to the shadow root's "host" element
460
+ // if it's not a shadow root, then we add attrs/props to the same element
461
+ const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
462
+ ? newVnode.$elm$.host
463
+ : newVnode.$elm$;
464
+ const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
465
+ const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
466
+ {
467
+ // remove attributes no longer present on the vnode by setting them to undefined
468
+ for (memberName in oldVnodeAttrs) {
469
+ if (!(memberName in newVnodeAttrs)) {
470
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
471
+ }
472
+ }
473
+ }
474
+ // add new & update changed attributes
475
+ for (memberName in newVnodeAttrs) {
476
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
477
+ }
478
+ };
479
+ /**
480
+ * Create a DOM Node corresponding to one of the children of a given VNode.
481
+ *
482
+ * @param oldParentVNode the parent VNode from the previous render
483
+ * @param newParentVNode the parent VNode from the current render
484
+ * @param childIndex the index of the VNode, in the _new_ parent node's
485
+ * children, for which we will create a new DOM node
486
+ * @param parentElm the parent DOM node which our new node will be a child of
487
+ * @returns the newly created node
488
+ */
489
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
490
+ // tslint:disable-next-line: prefer-const
491
+ const newVNode = newParentVNode.$children$[childIndex];
492
+ let i = 0;
493
+ let elm;
494
+ let childNode;
495
+ if (newVNode.$text$ !== null) {
496
+ // create text node
497
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
498
+ }
499
+ else {
500
+ // create element
501
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
502
+ // add css classes, attrs, props, listeners, etc.
503
+ {
504
+ updateElement(null, newVNode, isSvgMode);
505
+ }
506
+ if (isDef(scopeId) && elm['s-si'] !== scopeId) {
507
+ // if there is a scopeId and this is the initial render
508
+ // then let's add the scopeId as a css class
509
+ elm.classList.add((elm['s-si'] = scopeId));
510
+ }
511
+ if (newVNode.$children$) {
512
+ for (i = 0; i < newVNode.$children$.length; ++i) {
513
+ // create the node
514
+ childNode = createElm(oldParentVNode, newVNode, i);
515
+ // return node could have been null
516
+ if (childNode) {
517
+ // append our new node
518
+ elm.appendChild(childNode);
519
+ }
520
+ }
521
+ }
522
+ }
523
+ // This needs to always happen so we can hide nodes that are projected
524
+ // to another component but don't end up in a slot
525
+ elm['s-hn'] = hostTagName;
526
+ return elm;
527
+ };
528
+ /**
529
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
530
+ * add them to the DOM in the appropriate place.
531
+ *
532
+ * @param parentElm the DOM node which should be used as a parent for the new
533
+ * DOM nodes
534
+ * @param before a child of the `parentElm` which the new children should be
535
+ * inserted before (optional)
536
+ * @param parentVNode the parent virtual DOM node
537
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
538
+ * @param startIdx the index in the child virtual DOM nodes at which to start
539
+ * creating DOM nodes (inclusive)
540
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
541
+ * creating DOM nodes (inclusive)
542
+ */
543
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
544
+ let containerElm = (parentElm);
545
+ let childNode;
546
+ if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
547
+ containerElm = containerElm.shadowRoot;
548
+ }
549
+ for (; startIdx <= endIdx; ++startIdx) {
550
+ if (vnodes[startIdx]) {
551
+ childNode = createElm(null, parentVNode, startIdx);
552
+ if (childNode) {
553
+ vnodes[startIdx].$elm$ = childNode;
554
+ containerElm.insertBefore(childNode, before);
555
+ }
556
+ }
557
+ }
558
+ };
559
+ /**
560
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
561
+ * This can be used to, for instance, clean up after a list of children which
562
+ * should no longer be shown.
563
+ *
564
+ * This function also handles some of Stencil's slot relocation logic.
565
+ *
566
+ * @param vnodes a list of virtual DOM nodes to remove
567
+ * @param startIdx the index at which to start removing nodes (inclusive)
568
+ * @param endIdx the index at which to stop removing nodes (inclusive)
569
+ */
570
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
571
+ for (let index = startIdx; index <= endIdx; ++index) {
572
+ const vnode = vnodes[index];
573
+ if (vnode) {
574
+ const elm = vnode.$elm$;
575
+ if (elm) {
576
+ // remove the vnode's element from the dom
577
+ elm.remove();
578
+ }
579
+ }
580
+ }
581
+ };
582
+ /**
583
+ * Reconcile the children of a new VNode with the children of an old VNode by
584
+ * traversing the two collections of children, identifying nodes that are
585
+ * conserved or changed, calling out to `patch` to make any necessary
586
+ * updates to the DOM, and rearranging DOM nodes as needed.
587
+ *
588
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
589
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
590
+ * 'windows' by storing start and end indices and references to the
591
+ * corresponding array entries. Initially the two 'windows' are basically equal
592
+ * to the entire array, but we progressively narrow the windows until there are
593
+ * no children left to update by doing the following:
594
+ *
595
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
596
+ * that if we have an initial array like the following we'll end up dealing
597
+ * only with a window bounded by the highlighted elements:
598
+ *
599
+ * [null, null, VNode1 , ... , VNode2, null, null]
600
+ * ^^^^^^ ^^^^^^
601
+ *
602
+ * 2. Check to see if the elements at the head and tail positions are equal
603
+ * across the windows. This will basically detect elements which haven't
604
+ * been added, removed, or changed position, i.e. if you had the following
605
+ * VNode elements (represented as HTML):
606
+ *
607
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
608
+ * newVNode: `<div><p><span>THERE</span></p></div>`
609
+ *
610
+ * Then when comparing the children of the `<div>` tag we check the equality
611
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
612
+ * same tag in the same position, we'd be able to avoid completely
613
+ * re-rendering the subtree under them with a new DOM element and would just
614
+ * call out to `patch` to handle reconciling their children and so on.
615
+ *
616
+ * 3. Check, for both windows, to see if the element at the beginning of the
617
+ * window corresponds to the element at the end of the other window. This is
618
+ * a heuristic which will let us identify _some_ situations in which
619
+ * elements have changed position, for instance it _should_ detect that the
620
+ * children nodes themselves have not changed but merely moved in the
621
+ * following example:
622
+ *
623
+ * oldVNode: `<div><element-one /><element-two /></div>`
624
+ * newVNode: `<div><element-two /><element-one /></div>`
625
+ *
626
+ * If we find cases like this then we also need to move the concrete DOM
627
+ * elements corresponding to the moved children to write the re-order to the
628
+ * DOM.
629
+ *
630
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
631
+ * nodes in the old children which have the same key as the first element in
632
+ * our window on the new children. If we find such a node we handle calling
633
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
634
+ * what we find.
635
+ *
636
+ * Finally, once we've narrowed our 'windows' to the point that either of them
637
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
638
+ * insertion or deletion that needs to happen to get a DOM state that correctly
639
+ * reflects the new child VNodes. If, for instance, after our window on the old
640
+ * children has collapsed we still have more nodes on the new children that
641
+ * we haven't dealt with yet then we need to add them, or if the new children
642
+ * collapse but we still have unhandled _old_ children then we need to make
643
+ * sure the corresponding DOM nodes are removed.
644
+ *
645
+ * @param parentElm the node into which the parent VNode is rendered
646
+ * @param oldCh the old children of the parent node
647
+ * @param newVNode the new VNode which will replace the parent
648
+ * @param newCh the new children of the parent node
649
+ * @param isInitialRender whether or not this is the first render of the vdom
650
+ */
651
+ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
652
+ let oldStartIdx = 0;
653
+ let newStartIdx = 0;
654
+ let idxInOld = 0;
655
+ let i = 0;
656
+ let oldEndIdx = oldCh.length - 1;
657
+ let oldStartVnode = oldCh[0];
658
+ let oldEndVnode = oldCh[oldEndIdx];
659
+ let newEndIdx = newCh.length - 1;
660
+ let newStartVnode = newCh[0];
661
+ let newEndVnode = newCh[newEndIdx];
662
+ let node;
663
+ let elmToMove;
664
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
665
+ if (oldStartVnode == null) {
666
+ // VNode might have been moved left
667
+ oldStartVnode = oldCh[++oldStartIdx];
668
+ }
669
+ else if (oldEndVnode == null) {
670
+ oldEndVnode = oldCh[--oldEndIdx];
671
+ }
672
+ else if (newStartVnode == null) {
673
+ newStartVnode = newCh[++newStartIdx];
674
+ }
675
+ else if (newEndVnode == null) {
676
+ newEndVnode = newCh[--newEndIdx];
677
+ }
678
+ else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
679
+ // if the start nodes are the same then we should patch the new VNode
680
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
681
+ // indices to reflect that. We don't need to move any DOM Nodes around
682
+ // since things are matched up in order.
683
+ patch(oldStartVnode, newStartVnode, isInitialRender);
684
+ oldStartVnode = oldCh[++oldStartIdx];
685
+ newStartVnode = newCh[++newStartIdx];
686
+ }
687
+ else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
688
+ // likewise, if the end nodes are the same we patch new onto old and
689
+ // decrement our end indices, and also likewise in this case we don't
690
+ // need to move any DOM Nodes.
691
+ patch(oldEndVnode, newEndVnode, isInitialRender);
692
+ oldEndVnode = oldCh[--oldEndIdx];
693
+ newEndVnode = newCh[--newEndIdx];
694
+ }
695
+ else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
696
+ patch(oldStartVnode, newEndVnode, isInitialRender);
697
+ // We need to move the element for `oldStartVnode` into a position which
698
+ // will be appropriate for `newEndVnode`. For this we can use
699
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
700
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
701
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
702
+ //
703
+ // <old-start-node />
704
+ // <some-intervening-node />
705
+ // <old-end-node />
706
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
707
+ // <next-sibling />
708
+ //
709
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
710
+ // the node for `oldStartVnode` at the end of the children of
711
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
712
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
713
+ // append it to the children of the parent element.
714
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
715
+ oldStartVnode = oldCh[++oldStartIdx];
716
+ newEndVnode = newCh[--newEndIdx];
717
+ }
718
+ else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
719
+ patch(oldEndVnode, newStartVnode, isInitialRender);
720
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
721
+ // the same node, so since we're here we know that they are not. Thus we
722
+ // can move the element for `oldEndVnode` _before_ the element for
723
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
724
+ // future.
725
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
726
+ oldEndVnode = oldCh[--oldEndIdx];
727
+ newStartVnode = newCh[++newStartIdx];
728
+ }
729
+ else {
730
+ // Here we do some checks to match up old and new nodes based on the
731
+ // `$key$` attribute, which is set by putting a `key="my-key"` attribute
732
+ // in the JSX for a DOM element in the implementation of a Stencil
733
+ // component.
734
+ //
735
+ // First we check to see if there are any nodes in the array of old
736
+ // children which have the same key as the first node in the new
737
+ // children.
738
+ idxInOld = -1;
739
+ {
740
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) {
741
+ if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
742
+ idxInOld = i;
743
+ break;
744
+ }
745
+ }
746
+ }
747
+ if (idxInOld >= 0) {
748
+ // We found a node in the old children which matches up with the first
749
+ // node in the new children! So let's deal with that
750
+ elmToMove = oldCh[idxInOld];
751
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) {
752
+ // the tag doesn't match so we'll need a new DOM element
753
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
754
+ }
755
+ else {
756
+ patch(elmToMove, newStartVnode, isInitialRender);
757
+ // invalidate the matching old node so that we won't try to update it
758
+ // again later on
759
+ oldCh[idxInOld] = undefined;
760
+ node = elmToMove.$elm$;
761
+ }
762
+ newStartVnode = newCh[++newStartIdx];
763
+ }
764
+ else {
765
+ // We either didn't find an element in the old children that matches
766
+ // the key of the first new child OR the build is not using `key`
767
+ // attributes at all. In either case we need to create a new element
768
+ // for the new node.
769
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
770
+ newStartVnode = newCh[++newStartIdx];
771
+ }
772
+ if (node) {
773
+ // if we created a new node then handle inserting it to the DOM
774
+ {
775
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
776
+ }
777
+ }
778
+ }
779
+ }
780
+ if (oldStartIdx > oldEndIdx) {
781
+ // we have some more new nodes to add which don't match up with old nodes
782
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
783
+ }
784
+ else if (newStartIdx > newEndIdx) {
785
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
786
+ // in the new array, so lets remove them (which entails cleaning up the
787
+ // relevant DOM nodes)
788
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
789
+ }
790
+ };
791
+ /**
792
+ * Compare two VNodes to determine if they are the same
793
+ *
794
+ * **NB**: This function is an equality _heuristic_ based on the available
795
+ * information set on the two VNodes and can be misleading under certain
796
+ * circumstances. In particular, if the two nodes do not have `key` attrs
797
+ * (available under `$key$` on VNodes) then the function falls back on merely
798
+ * checking that they have the same tag.
799
+ *
800
+ * So, in other words, if `key` attrs are not set on VNodes which may be
801
+ * changing order within a `children` array or something along those lines then
802
+ * we could obtain a false negative and then have to do needless re-rendering
803
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
804
+ *
805
+ * @param leftVNode the first VNode to check
806
+ * @param rightVNode the second VNode to check
807
+ * @param isInitialRender whether or not this is the first render of the vdom
808
+ * @returns whether they're equal or not
809
+ */
810
+ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
811
+ // compare if two vnode to see if they're "technically" the same
812
+ // need to have the same element tag, and same key to be the same
813
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
814
+ // this will be set if JSX tags in the build have `key` attrs set on them
815
+ // we only want to check this if we're not on the first render since on
816
+ // first render `leftVNode.$key$` will always be `null`, so we can be led
817
+ // astray and, for instance, accidentally delete a DOM node that we want to
818
+ // keep around.
819
+ if (!isInitialRender) {
820
+ return leftVNode.$key$ === rightVNode.$key$;
821
+ }
822
+ return true;
823
+ }
824
+ return false;
825
+ };
826
+ /**
827
+ * Handle reconciling an outdated VNode with a new one which corresponds to
828
+ * it. This function handles flushing updates to the DOM and reconciling the
829
+ * children of the two nodes (if any).
830
+ *
831
+ * @param oldVNode an old VNode whose DOM element and children we want to update
832
+ * @param newVNode a new VNode representing an updated version of the old one
833
+ * @param isInitialRender whether or not this is the first render of the vdom
834
+ */
835
+ const patch = (oldVNode, newVNode, isInitialRender = false) => {
836
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
837
+ const oldChildren = oldVNode.$children$;
838
+ const newChildren = newVNode.$children$;
839
+ const text = newVNode.$text$;
840
+ if (text === null) {
841
+ {
842
+ {
843
+ // either this is the first render of an element OR it's an update
844
+ // AND we already know it's possible it could have changed
845
+ // this updates the element's css classes, attrs, props, listeners, etc.
846
+ updateElement(oldVNode, newVNode, isSvgMode);
847
+ }
848
+ }
849
+ if (oldChildren !== null && newChildren !== null) {
850
+ // looks like there's child vnodes for both the old and new vnodes
851
+ // so we need to call `updateChildren` to reconcile them
852
+ updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
853
+ }
854
+ else if (newChildren !== null) {
855
+ // no old child vnodes, but there are new child vnodes to add
856
+ if (oldVNode.$text$ !== null) {
857
+ // the old vnode was text, so be sure to clear it out
858
+ elm.textContent = '';
859
+ }
860
+ // add the new vnode children
861
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
862
+ }
863
+ else if (oldChildren !== null) {
864
+ // no new child vnodes, but there are old child vnodes to remove
865
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
866
+ }
867
+ }
868
+ else if (oldVNode.$text$ !== text) {
869
+ // update the text content for the text only vnode
870
+ // and also only if the text is different than before
871
+ elm.data = text;
872
+ }
873
+ };
874
+ /**
875
+ * The main entry point for Stencil's virtual DOM-based rendering engine
876
+ *
877
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
878
+ * function will handle creating a virtual DOM tree with a single root, patching
879
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
880
+ * relocation, and reflecting attributes.
881
+ *
882
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
883
+ * the DOM node into which it should be rendered.
884
+ * @param renderFnResults the virtual DOM nodes to be rendered
885
+ * @param isInitialLoad whether or not this is the first call after page load
886
+ */
887
+ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
888
+ const hostElm = hostRef.$hostElement$;
889
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
890
+ // if `renderFnResults` is a Host node then we can use it directly. If not,
891
+ // we need to call `h` again to wrap the children of our component in a
892
+ // 'dummy' Host node (well, an empty vnode) since `renderVdom` assumes
893
+ // implicitly that the top-level vdom node is 1) an only child and 2)
894
+ // contains attrs that need to be set on the host element.
895
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
896
+ hostTagName = hostElm.tagName;
897
+ // On the first render and *only* on the first render we want to check for
898
+ // any attributes set on the host element which are also set on the vdom
899
+ // node. If we find them, we override the value on the VDom node attrs with
900
+ // the value from the host element, which allows developers building apps
901
+ // with Stencil components to override e.g. the `role` attribute on a
902
+ // component even if it's already set on the `Host`.
903
+ if (isInitialLoad && rootVnode.$attrs$) {
904
+ for (const key of Object.keys(rootVnode.$attrs$)) {
905
+ // We have a special implementation in `setAccessor` for `style` and
906
+ // `class` which reconciles values coming from the VDom with values
907
+ // already present on the DOM element, so we don't want to override those
908
+ // attributes on the VDom tree with values from the host element if they
909
+ // are present.
910
+ //
911
+ // Likewise, `ref` and `key` are special internal values for the Stencil
912
+ // runtime and we don't want to override those either.
913
+ if (hostElm.hasAttribute(key) && !['key', 'ref', 'style', 'class'].includes(key)) {
914
+ rootVnode.$attrs$[key] = hostElm[key];
915
+ }
916
+ }
917
+ }
918
+ rootVnode.$tag$ = null;
919
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
920
+ hostRef.$vnode$ = rootVnode;
921
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
922
+ {
923
+ scopeId = hostElm['s-sc'];
924
+ }
925
+ // synchronous patch
926
+ patch(oldVNode, rootVnode, isInitialLoad);
927
+ };
928
+ const attachToAncestor = (hostRef, ancestorComponent) => {
929
+ if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
930
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
931
+ }
932
+ };
933
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
934
+ {
935
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
936
+ }
937
+ if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
938
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
939
+ return;
940
+ }
941
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
942
+ // there is no ancestor component or the ancestor component
943
+ // has already fired off its lifecycle update then
944
+ // fire off the initial update
945
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
946
+ return writeTask(dispatch) ;
947
+ };
948
+ /**
949
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
950
+ * component lifecycle methods like `componentWillLoad` as well as
951
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
952
+ *
953
+ * @param hostRef a reference to a host DOM node
954
+ * @param isInitialLoad whether we're on the initial load or not
955
+ * @returns an empty Promise which is used to enqueue a series of operations for
956
+ * the component
957
+ */
958
+ const dispatchHooks = (hostRef, isInitialLoad) => {
959
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
960
+ const instance = hostRef.$lazyInstance$ ;
961
+ // We're going to use this variable together with `enqueue` to implement a
962
+ // little promise-based queue. We start out with it `undefined`. When we add
963
+ // the first function to the queue we'll set this variable to be that
964
+ // function's return value. When we attempt to add subsequent values to the
965
+ // queue we'll check that value and, if it was a `Promise`, we'll then chain
966
+ // the new function off of that `Promise` using `.then()`. This will give our
967
+ // queue two nice properties:
968
+ //
969
+ // 1. If all functions added to the queue are synchronous they'll be called
970
+ // synchronously right away.
971
+ // 2. If all functions added to the queue are asynchronous they'll all be
972
+ // called in order after `dispatchHooks` exits.
973
+ let maybePromise;
974
+ endSchedule();
975
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
976
+ };
977
+ /**
978
+ * This function uses a Promise to implement a simple first-in, first-out queue
979
+ * of functions to be called.
980
+ *
981
+ * The queue is ordered on the basis of the first argument. If it's
982
+ * `undefined`, then nothing is on the queue yet, so the provided function can
983
+ * be called synchronously (although note that this function may return a
984
+ * `Promise`). The idea is that then the return value of that enqueueing
985
+ * operation is kept around, so that if it was a `Promise` then subsequent
986
+ * functions can be enqueued by calling this function again with that `Promise`
987
+ * as the first argument.
988
+ *
989
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
990
+ * @param fn a function to enqueue
991
+ * @returns either a `Promise` or the return value of the provided function
992
+ */
993
+ const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
994
+ /**
995
+ * Check that a value is a `Promise`. To check, we first see if the value is an
996
+ * instance of the `Promise` global. In a few circumstances, in particular if
997
+ * the global has been overwritten, this is could be misleading, so we also do
998
+ * a little 'duck typing' check to see if the `.then` property of the value is
999
+ * defined and a function.
1000
+ *
1001
+ * @param maybePromise it might be a promise!
1002
+ * @returns whether it is or not
1003
+ */
1004
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
1005
+ (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
1006
+ /**
1007
+ * Update a component given reference to its host elements and so on.
1008
+ *
1009
+ * @param hostRef an object containing references to the element's host node,
1010
+ * VDom nodes, and other metadata
1011
+ * @param instance a reference to the underlying host element where it will be
1012
+ * rendered
1013
+ * @param isInitialLoad whether or not this function is being called as part of
1014
+ * the first render cycle
1015
+ */
1016
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1017
+ var _a;
1018
+ const elm = hostRef.$hostElement$;
1019
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1020
+ const rc = elm['s-rc'];
1021
+ if (isInitialLoad) {
1022
+ // DOM WRITE!
1023
+ attachStyles(hostRef);
1024
+ }
1025
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1026
+ {
1027
+ callRender(hostRef, instance, elm, isInitialLoad);
1028
+ }
1029
+ if (rc) {
1030
+ // ok, so turns out there are some child host elements
1031
+ // waiting on this parent element to load
1032
+ // let's fire off all update callbacks waiting
1033
+ rc.map((cb) => cb());
1034
+ elm['s-rc'] = undefined;
1035
+ }
1036
+ endRender();
1037
+ endUpdate();
1038
+ {
1039
+ const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
1040
+ const postUpdate = () => postUpdateComponent(hostRef);
1041
+ if (childrenPromises.length === 0) {
1042
+ postUpdate();
1043
+ }
1044
+ else {
1045
+ Promise.all(childrenPromises).then(postUpdate);
1046
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1047
+ childrenPromises.length = 0;
1048
+ }
1049
+ }
1050
+ };
1051
+ /**
1052
+ * Handle making the call to the VDom renderer with the proper context given
1053
+ * various build variables
1054
+ *
1055
+ * @param hostRef an object containing references to the element's host node,
1056
+ * VDom nodes, and other metadata
1057
+ * @param instance a reference to the underlying host element where it will be
1058
+ * rendered
1059
+ * @param elm the Host element for the component
1060
+ * @param isInitialLoad whether or not this function is being called as part of
1061
+ * @returns an empty promise
1062
+ */
1063
+ const callRender = (hostRef, instance, elm, isInitialLoad) => {
1064
+ try {
1065
+ /**
1066
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
1067
+ * method, so we can call the method immediately. If not, check before calling it.
1068
+ */
1069
+ instance = instance.render() ;
1070
+ {
1071
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1072
+ }
1073
+ {
1074
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1075
+ }
1076
+ {
1077
+ {
1078
+ // looks like we've got child nodes to render into this host element
1079
+ // or we need to update the css class/attrs on the host element
1080
+ // DOM WRITE!
1081
+ {
1082
+ renderVdom(hostRef, instance, isInitialLoad);
1083
+ }
1084
+ }
1085
+ }
1086
+ }
1087
+ catch (e) {
1088
+ consoleError(e, hostRef.$hostElement$);
1089
+ }
1090
+ return null;
1091
+ };
1092
+ const postUpdateComponent = (hostRef) => {
1093
+ const tagName = hostRef.$cmpMeta$.$tagName$;
1094
+ const elm = hostRef.$hostElement$;
1095
+ const endPostUpdate = createTime('postUpdate', tagName);
1096
+ const ancestorComponent = hostRef.$ancestorComponent$;
1097
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1098
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1099
+ {
1100
+ // DOM WRITE!
1101
+ addHydratedFlag(elm);
1102
+ }
1103
+ endPostUpdate();
1104
+ {
1105
+ hostRef.$onReadyResolve$(elm);
1106
+ if (!ancestorComponent) {
1107
+ appDidLoad();
1108
+ }
1109
+ }
1110
+ }
1111
+ else {
1112
+ endPostUpdate();
1113
+ }
1114
+ // load events fire from bottom to top
1115
+ // the deepest elements load first then bubbles up
1116
+ {
1117
+ if (hostRef.$onRenderResolve$) {
1118
+ hostRef.$onRenderResolve$();
1119
+ hostRef.$onRenderResolve$ = undefined;
1120
+ }
1121
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1122
+ nextTick(() => scheduleUpdate(hostRef, false));
1123
+ }
1124
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1125
+ }
1126
+ // ( •_•)
1127
+ // ( •_•)>⌐■-■
1128
+ // (⌐■_■)
1129
+ };
1130
+ const appDidLoad = (who) => {
1131
+ // on appload
1132
+ // we have finish the first big initial render
1133
+ {
1134
+ addHydratedFlag(doc.documentElement);
1135
+ }
1136
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1137
+ };
1138
+ /**
1139
+ * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
1140
+ * e.g. custom element node. If a build figures out that e.g. no component
1141
+ * has a `componentDidLoad` method, the instance method gets removed from the
1142
+ * output bundle and this function returns `undefined`.
1143
+ * @param instance any object that may or may not contain methods
1144
+ * @param method method name
1145
+ * @param arg single arbitrary argument
1146
+ * @returns result of method call if it exists, otherwise `undefined`
1147
+ */
1148
+ const safeCall = (instance, method, arg) => {
1149
+ if (instance && instance[method]) {
1150
+ try {
1151
+ return instance[method](arg);
1152
+ }
1153
+ catch (e) {
1154
+ consoleError(e);
1155
+ }
1156
+ }
1157
+ return undefined;
1158
+ };
1159
+ const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1160
+ ;
1161
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1162
+ const setValue = (ref, propName, newVal, cmpMeta) => {
1163
+ // check our new property value against our internal value
1164
+ const hostRef = getHostRef(ref);
1165
+ const oldVal = hostRef.$instanceValues$.get(propName);
1166
+ const flags = hostRef.$flags$;
1167
+ const instance = hostRef.$lazyInstance$ ;
1168
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1169
+ // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1170
+ const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1171
+ const didValueChange = newVal !== oldVal && !areBothNaN;
1172
+ if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1173
+ // gadzooks! the property's value has changed!!
1174
+ // set our new value!
1175
+ hostRef.$instanceValues$.set(propName, newVal);
1176
+ if (instance) {
1177
+ if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1178
+ // looks like this value actually changed, so we've got work to do!
1179
+ // but only if we've already rendered, otherwise just chill out
1180
+ // queue that we need to do an update, but don't worry about queuing
1181
+ // up millions cuz this function ensures it only runs once
1182
+ scheduleUpdate(hostRef, false);
1183
+ }
1184
+ }
1185
+ }
1186
+ };
1187
+ /**
1188
+ * Attach a series of runtime constructs to a compiled Stencil component
1189
+ * constructor, including getters and setters for the `@Prop` and `@State`
1190
+ * decorators, callbacks for when attributes change, and so on.
1191
+ *
1192
+ * @param Cstr the constructor for a component that we need to process
1193
+ * @param cmpMeta metadata collected previously about the component
1194
+ * @param flags a number used to store a series of bit flags
1195
+ * @returns a reference to the same constructor passed in (but now mutated)
1196
+ */
1197
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
1198
+ var _a;
1199
+ const prototype = Cstr.prototype;
1200
+ if (cmpMeta.$members$) {
1201
+ // It's better to have a const than two Object.entries()
1202
+ const members = Object.entries(cmpMeta.$members$);
1203
+ members.map(([memberName, [memberFlags]]) => {
1204
+ if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1205
+ ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1206
+ // proxyComponent - prop
1207
+ Object.defineProperty(prototype, memberName, {
1208
+ get() {
1209
+ // proxyComponent, get value
1210
+ return getValue(this, memberName);
1211
+ },
1212
+ set(newValue) {
1213
+ // proxyComponent, set value
1214
+ setValue(this, memberName, newValue, cmpMeta);
1215
+ },
1216
+ configurable: true,
1217
+ enumerable: true,
1218
+ });
1219
+ }
1220
+ });
1221
+ if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1222
+ const attrNameToPropName = new Map();
1223
+ prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
1224
+ plt.jmp(() => {
1225
+ var _a;
1226
+ const propName = attrNameToPropName.get(attrName);
1227
+ // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1228
+ // in the case where an attribute was set inline.
1229
+ // ```html
1230
+ // <my-component some-attribute="some-value"></my-component>
1231
+ // ```
1232
+ //
1233
+ // There is an edge case where a developer sets the attribute inline on a custom element and then
1234
+ // programmatically changes it before it has been upgraded as shown below:
1235
+ //
1236
+ // ```html
1237
+ // <!-- this component has _not_ been upgraded yet -->
1238
+ // <my-component id="test" some-attribute="some-value"></my-component>
1239
+ // <script>
1240
+ // // grab non-upgraded component
1241
+ // el = document.querySelector("#test");
1242
+ // el.someAttribute = "another-value";
1243
+ // // upgrade component
1244
+ // customElements.define('my-component', MyComponent);
1245
+ // </script>
1246
+ // ```
1247
+ // In this case if we do not un-shadow here and use the value of the shadowing property, attributeChangedCallback
1248
+ // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1249
+ // to the value that was set inline i.e. "some-value" from above example. When
1250
+ // the connectedCallback attempts to un-shadow it will use "some-value" as the initial value rather than "another-value"
1251
+ //
1252
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/un-shadowed
1253
+ // by connectedCallback as this attributeChangedCallback will not fire.
1254
+ //
1255
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1256
+ //
1257
+ // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1258
+ // properties here given that this goes against best practices outlined here
1259
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1260
+ if (this.hasOwnProperty(propName)) {
1261
+ newValue = this[propName];
1262
+ delete this[propName];
1263
+ }
1264
+ else if (prototype.hasOwnProperty(propName) &&
1265
+ typeof this[propName] === 'number' &&
1266
+ this[propName] == newValue) {
1267
+ // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1268
+ // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1269
+ // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1270
+ return;
1271
+ }
1272
+ else if (propName == null) {
1273
+ // At this point we should know this is not a "member", so we can treat it like watching an attribute
1274
+ // on a vanilla web component
1275
+ const hostRef = getHostRef(this);
1276
+ const flags = hostRef === null || hostRef === void 0 ? void 0 : hostRef.$flags$;
1277
+ // We only want to trigger the callback(s) if:
1278
+ // 1. The instance is ready
1279
+ // 2. The watchers are ready
1280
+ // 3. The value has changed
1281
+ if (flags &&
1282
+ !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) &&
1283
+ flags & 128 /* HOST_FLAGS.isWatchReady */ &&
1284
+ newValue !== oldValue) {
1285
+ const instance = hostRef.$lazyInstance$ ;
1286
+ const entry = (_a = cmpMeta.$watchers$) === null || _a === void 0 ? void 0 : _a[attrName];
1287
+ entry === null || entry === void 0 ? void 0 : entry.forEach((callbackName) => {
1288
+ if (instance[callbackName] != null) {
1289
+ instance[callbackName].call(instance, newValue, oldValue, attrName);
1290
+ }
1291
+ });
1292
+ }
1293
+ return;
1294
+ }
1295
+ this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1296
+ });
1297
+ };
1298
+ // Create an array of attributes to observe
1299
+ // This list in comprised of all strings used within a `@Watch()` decorator
1300
+ // on a component as well as any Stencil-specific "members" (`@Prop()`s and `@State()`s).
1301
+ // As such, there is no way to guarantee type-safety here that a user hasn't entered
1302
+ // an invalid attribute.
1303
+ Cstr.observedAttributes = Array.from(new Set([
1304
+ ...Object.keys((_a = cmpMeta.$watchers$) !== null && _a !== void 0 ? _a : {}),
1305
+ ...members
1306
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */)
1307
+ .map(([propName, m]) => {
1308
+ const attrName = m[1] || propName;
1309
+ attrNameToPropName.set(attrName, propName);
1310
+ return attrName;
1311
+ }),
1312
+ ]));
1313
+ }
1314
+ }
1315
+ return Cstr;
1316
+ };
1317
+ /**
1318
+ * Initialize a Stencil component given a reference to its host element, its
1319
+ * runtime bookkeeping data structure, runtime metadata about the component,
1320
+ * and (optionally) an HMR version ID.
1321
+ *
1322
+ * @param elm a host element
1323
+ * @param hostRef the element's runtime bookkeeping object
1324
+ * @param cmpMeta runtime metadata for the Stencil component
1325
+ * @param hmrVersionId an (optional) HMR version ID
1326
+ */
1327
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
1328
+ let Cstr;
1329
+ // initializeComponent
1330
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1331
+ // Let the runtime know that the component has been initialized
1332
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1333
+ {
1334
+ // lazy loaded components
1335
+ // request the component's implementation to be
1336
+ // wired up with the host element
1337
+ Cstr = loadModule(cmpMeta);
1338
+ if (Cstr.then) {
1339
+ // Await creates a micro-task avoid if possible
1340
+ const endLoad = uniqueTime();
1341
+ Cstr = await Cstr;
1342
+ endLoad();
1343
+ }
1344
+ if (!Cstr.isProxied) {
1345
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1346
+ Cstr.isProxied = true;
1347
+ }
1348
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1349
+ // ok, time to construct the instance
1350
+ // but let's keep track of when we start and stop
1351
+ // so that the getters/setters don't incorrectly step on data
1352
+ {
1353
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1354
+ }
1355
+ // construct the lazy-loaded component implementation
1356
+ // passing the hostRef is very important during
1357
+ // construction in order to directly wire together the
1358
+ // host element and the lazy-loaded instance
1359
+ try {
1360
+ new Cstr(hostRef);
1361
+ }
1362
+ catch (e) {
1363
+ consoleError(e);
1364
+ }
1365
+ {
1366
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1367
+ }
1368
+ endNewInstance();
1369
+ fireConnectedCallback(hostRef.$lazyInstance$);
1370
+ }
1371
+ if (Cstr.style) {
1372
+ // this component has styles but we haven't registered them yet
1373
+ let style = Cstr.style;
1374
+ const scopeId = getScopeId(cmpMeta);
1375
+ if (!styles.has(scopeId)) {
1376
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1377
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1378
+ endRegisterStyles();
1379
+ }
1380
+ }
1381
+ }
1382
+ // we've successfully created a lazy instance
1383
+ const ancestorComponent = hostRef.$ancestorComponent$;
1384
+ const schedule = () => scheduleUpdate(hostRef, true);
1385
+ if (ancestorComponent && ancestorComponent['s-rc']) {
1386
+ // this is the initial load and this component it has an ancestor component
1387
+ // but the ancestor component has NOT fired its will update lifecycle yet
1388
+ // so let's just cool our jets and wait for the ancestor to continue first
1389
+ // this will get fired off when the ancestor component
1390
+ // finally gets around to rendering its lazy self
1391
+ // fire off the initial update
1392
+ ancestorComponent['s-rc'].push(schedule);
1393
+ }
1394
+ else {
1395
+ schedule();
1396
+ }
1397
+ };
1398
+ const fireConnectedCallback = (instance) => {
1399
+ {
1400
+ safeCall(instance, 'connectedCallback');
1401
+ }
1402
+ };
1403
+ const connectedCallback = (elm) => {
1404
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1405
+ const hostRef = getHostRef(elm);
1406
+ const cmpMeta = hostRef.$cmpMeta$;
1407
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1408
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1409
+ // first time this component has connected
1410
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1411
+ {
1412
+ // find the first ancestor component (if there is one) and register
1413
+ // this component as one of the actively loading child components for its ancestor
1414
+ let ancestorComponent = elm;
1415
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1416
+ // climb up the ancestors looking for the first
1417
+ // component that hasn't finished its lifecycle update yet
1418
+ if (ancestorComponent['s-p']) {
1419
+ // we found this components first ancestor component
1420
+ // keep a reference to this component's ancestor component
1421
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1422
+ break;
1423
+ }
1424
+ }
1425
+ }
1426
+ // Lazy properties
1427
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1428
+ if (cmpMeta.$members$) {
1429
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1430
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1431
+ const value = elm[memberName];
1432
+ delete elm[memberName];
1433
+ elm[memberName] = value;
1434
+ }
1435
+ });
1436
+ }
1437
+ {
1438
+ initializeComponent(elm, hostRef, cmpMeta);
1439
+ }
1440
+ }
1441
+ else {
1442
+ // fire off connectedCallback() on component instance
1443
+ if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
1444
+ fireConnectedCallback(hostRef.$lazyInstance$);
1445
+ }
1446
+ else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1447
+ hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$));
1448
+ }
1449
+ }
1450
+ endConnected();
1451
+ }
1452
+ };
1453
+ const disconnectInstance = (instance) => {
1454
+ };
1455
+ const disconnectedCallback = async (elm) => {
1456
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1457
+ const hostRef = getHostRef(elm);
1458
+ if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) ;
1459
+ else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1460
+ hostRef.$onReadyPromise$.then(() => disconnectInstance());
1461
+ }
1462
+ }
1463
+ };
1464
+ const bootstrapLazy = (lazyBundles, options = {}) => {
1465
+ var _a;
1466
+ const endBootstrap = createTime();
1467
+ const cmpTags = [];
1468
+ const exclude = options.exclude || [];
1469
+ const customElements = win.customElements;
1470
+ const head = doc.head;
1471
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1472
+ const dataStyles = /*@__PURE__*/ doc.createElement('style');
1473
+ const deferredConnectedCallbacks = [];
1474
+ let appLoadFallback;
1475
+ let isBootstrapping = true;
1476
+ Object.assign(plt, options);
1477
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1478
+ let hasSlotRelocation = false;
1479
+ lazyBundles.map((lazyBundle) => {
1480
+ lazyBundle[1].map((compactMeta) => {
1481
+ const cmpMeta = {
1482
+ $flags$: compactMeta[0],
1483
+ $tagName$: compactMeta[1],
1484
+ $members$: compactMeta[2],
1485
+ $listeners$: compactMeta[3],
1486
+ };
1487
+ // Check if we are using slots outside the shadow DOM in this component.
1488
+ // We'll use this information later to add styles for `slot-fb` elements
1489
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
1490
+ hasSlotRelocation = true;
1491
+ }
1492
+ {
1493
+ cmpMeta.$members$ = compactMeta[2];
1494
+ }
1495
+ const tagName = cmpMeta.$tagName$;
1496
+ const HostElement = class extends HTMLElement {
1497
+ // StencilLazyHost
1498
+ constructor(self) {
1499
+ // @ts-ignore
1500
+ super(self);
1501
+ self = this;
1502
+ registerHost(self, cmpMeta);
1503
+ if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1504
+ // this component is using shadow dom
1505
+ // and this browser supports shadow dom
1506
+ // add the read-only property "shadowRoot" to the host element
1507
+ // adding the shadow root build conditionals to minimize runtime
1508
+ {
1509
+ {
1510
+ self.attachShadow({ mode: 'open' });
1511
+ }
1512
+ }
1513
+ }
1514
+ }
1515
+ connectedCallback() {
1516
+ if (appLoadFallback) {
1517
+ clearTimeout(appLoadFallback);
1518
+ appLoadFallback = null;
1519
+ }
1520
+ if (isBootstrapping) {
1521
+ // connectedCallback will be processed once all components have been registered
1522
+ deferredConnectedCallbacks.push(this);
1523
+ }
1524
+ else {
1525
+ plt.jmp(() => connectedCallback(this));
1526
+ }
1527
+ }
1528
+ disconnectedCallback() {
1529
+ plt.jmp(() => disconnectedCallback(this));
1530
+ }
1531
+ componentOnReady() {
1532
+ return getHostRef(this).$onReadyPromise$;
1533
+ }
1534
+ };
1535
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
1536
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1537
+ cmpTags.push(tagName);
1538
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1539
+ }
1540
+ });
1541
+ });
1542
+ // Add styles for `slot-fb` elements if any of our components are using slots outside the Shadow DOM
1543
+ if (hasSlotRelocation) {
1544
+ dataStyles.innerHTML += SLOT_FB_CSS;
1545
+ }
1546
+ // Add hydration styles
1547
+ {
1548
+ dataStyles.innerHTML += cmpTags + HYDRATED_CSS;
1549
+ }
1550
+ // If we have styles, add them to the DOM
1551
+ if (dataStyles.innerHTML.length) {
1552
+ dataStyles.setAttribute('data-styles', '');
1553
+ // Apply CSP nonce to the style tag if it exists
1554
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1555
+ if (nonce != null) {
1556
+ dataStyles.setAttribute('nonce', nonce);
1557
+ }
1558
+ // Insert the styles into the document head
1559
+ // NOTE: this _needs_ to happen last so we can ensure the nonce (and other attributes) are applied
1560
+ head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
1561
+ }
1562
+ // Process deferred connectedCallbacks now all components have been registered
1563
+ isBootstrapping = false;
1564
+ if (deferredConnectedCallbacks.length) {
1565
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
1566
+ }
1567
+ else {
1568
+ {
1569
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1570
+ }
1571
+ }
1572
+ // Fallback appLoad event
1573
+ endBootstrap();
1574
+ };
1575
+ /**
1576
+ * Assigns the given value to the nonce property on the runtime platform object.
1577
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1578
+ * @param nonce The value to be assigned to the platform nonce property.
1579
+ * @returns void
1580
+ */
1581
+ const setNonce = (nonce) => (plt.$nonce$ = nonce);
1582
+ /**
1583
+ * A WeakMap mapping runtime component references to their corresponding host reference
1584
+ * instances.
1585
+ *
1586
+ * **Note**: If we're in an HMR context we need to store a reference to this
1587
+ * value on `window` in order to maintain the mapping of {@link d.RuntimeRef}
1588
+ * to {@link d.HostRef} across HMR updates.
1589
+ *
1590
+ * This is necessary because when HMR updates for a component are processed by
1591
+ * the browser-side dev server client the JS bundle for that component is
1592
+ * re-fetched. Since the module containing {@link hostRefs} is included in
1593
+ * that bundle, if we do not store a reference to it the new iteration of the
1594
+ * component will not have access to the previous hostRef map, leading to a
1595
+ * bug where the new version of the component cannot properly initialize.
1596
+ */
1597
+ const hostRefs = new WeakMap();
1598
+ /**
1599
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
1600
+ *
1601
+ * @param ref the runtime ref of interest
1602
+ * @returns the Host reference (if found) or undefined
1603
+ */
1604
+ const getHostRef = (ref) => hostRefs.get(ref);
1605
+ /**
1606
+ * Register a lazy instance with the {@link hostRefs} object so it's
1607
+ * corresponding {@link d.HostRef} can be retrieved later.
1608
+ *
1609
+ * @param lazyInstance the lazy instance of interest
1610
+ * @param hostRef that instances `HostRef` object
1611
+ * @returns a reference to the host ref WeakMap
1612
+ */
1613
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1614
+ /**
1615
+ * Register a host element for a Stencil component, setting up various metadata
1616
+ * and callbacks based on {@link BUILD} flags as well as the component's runtime
1617
+ * metadata.
1618
+ *
1619
+ * @param hostElement the host element to register
1620
+ * @param cmpMeta runtime metadata for that component
1621
+ * @returns a reference to the host ref WeakMap
1622
+ */
1623
+ const registerHost = (hostElement, cmpMeta) => {
1624
+ const hostRef = {
1625
+ $flags$: 0,
1626
+ $hostElement$: hostElement,
1627
+ $cmpMeta$: cmpMeta,
1628
+ $instanceValues$: new Map(),
1629
+ };
1630
+ {
1631
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1632
+ hostElement['s-p'] = [];
1633
+ hostElement['s-rc'] = [];
1634
+ }
1635
+ return hostRefs.set(hostElement, hostRef);
1636
+ };
1637
+ const isMemberInElement = (elm, memberName) => memberName in elm;
1638
+ const consoleError = (e, el) => (0, console.error)(e, el);
1639
+ const cmpModules = /*@__PURE__*/ new Map();
1640
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1641
+ // loadModuleImport
1642
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1643
+ const bundleId = cmpMeta.$lazyBundleId$;
1644
+ const module = cmpModules.get(bundleId) ;
1645
+ if (module) {
1646
+ return module[exportName];
1647
+ }
1648
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1649
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
1650
+ /* @vite-ignore */
1651
+ /* webpackInclude: /\.entry\.js$/ */
1652
+ /* webpackExclude: /\.system\.entry\.js$/ */
1653
+ /* webpackMode: "lazy" */
1654
+ `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
1655
+ {
1656
+ cmpModules.set(bundleId, importedModule);
1657
+ }
1658
+ return importedModule[exportName];
1659
+ }, consoleError);
1660
+ };
1661
+ const styles = /*@__PURE__*/ new Map();
1662
+ const win = typeof window !== 'undefined' ? window : {};
1663
+ const doc = win.document || { head: {} };
1664
+ const plt = {
1665
+ $flags$: 0,
1666
+ $resourcesUrl$: '',
1667
+ jmp: (h) => h(),
1668
+ raf: (h) => requestAnimationFrame(h),
1669
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1670
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1671
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
1672
+ };
1673
+ const promiseResolve = (v) => Promise.resolve(v);
1674
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1675
+ try {
1676
+ new CSSStyleSheet();
1677
+ return typeof new CSSStyleSheet().replaceSync === 'function';
1678
+ }
1679
+ catch (e) { }
1680
+ return false;
1681
+ })()
1682
+ ;
1683
+ const queueDomReads = [];
1684
+ const queueDomWrites = [];
1685
+ const queueTask = (queue, write) => (cb) => {
1686
+ queue.push(cb);
1687
+ if (!queuePending) {
1688
+ queuePending = true;
1689
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1690
+ nextTick(flush);
1691
+ }
1692
+ else {
1693
+ plt.raf(flush);
1694
+ }
1695
+ }
1696
+ };
1697
+ const consume = (queue) => {
1698
+ for (let i = 0; i < queue.length; i++) {
1699
+ try {
1700
+ queue[i](performance.now());
1701
+ }
1702
+ catch (e) {
1703
+ consoleError(e);
1704
+ }
1705
+ }
1706
+ queue.length = 0;
1707
+ };
1708
+ const flush = () => {
1709
+ // always force a bunch of medium callbacks to run, but still have
1710
+ // a throttle on how many can run in a certain time
1711
+ // DOM READS!!!
1712
+ consume(queueDomReads);
1713
+ // DOM WRITES!!!
1714
+ {
1715
+ consume(queueDomWrites);
1716
+ if ((queuePending = queueDomReads.length > 0)) {
1717
+ // still more to do yet, but we've run out of time
1718
+ // let's let this thing cool off and try again in the next tick
1719
+ plt.raf(flush);
1720
+ }
1721
+ }
1722
+ };
1723
+ const nextTick = (cb) => promiseResolve().then(cb);
1724
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1725
+
1726
+ exports.bootstrapLazy = bootstrapLazy;
1727
+ exports.getElement = getElement;
1728
+ exports.h = h;
1729
+ exports.promiseResolve = promiseResolve;
1730
+ exports.registerInstance = registerInstance;
1731
+ exports.setNonce = setNonce;
1732
+
1733
+ //# sourceMappingURL=index-8282b36b.js.map