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