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