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