@gataca/qr 2.0.1 → 2.0.2

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