@gataca/qr 2.0.2 → 2.0.3

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