@justifi/webcomponents 0.0.6

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