@aiconomy/aico-components 0.0.13 → 0.0.14

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