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