@oila/0account 3.4.8 → 3.4.9

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 (95) hide show
  1. package/dist/cjs/index-ef57218a.js +1948 -0
  2. package/dist/cjs/index-ef57218a.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +4 -0
  4. package/dist/cjs/index.cjs.js.map +1 -0
  5. package/dist/cjs/loader.cjs.js +15 -0
  6. package/dist/cjs/loader.cjs.js.map +1 -0
  7. package/dist/cjs/qr-code_2.cjs.entry.js +1550 -0
  8. package/dist/cjs/qr-code_2.cjs.entry.js.map +1 -0
  9. package/dist/cjs/zero-account.cjs.js +25 -0
  10. package/dist/cjs/zero-account.cjs.js.map +1 -0
  11. package/dist/collection/collection-manifest.json +13 -0
  12. package/dist/collection/components/zero-account/enums.js +18 -0
  13. package/dist/collection/components/zero-account/enums.js.map +1 -0
  14. package/dist/collection/components/zero-account/logo.js +6 -0
  15. package/dist/collection/components/zero-account/logo.js.map +1 -0
  16. package/dist/collection/components/zero-account/qrcode.js +111 -0
  17. package/dist/collection/components/zero-account/qrcode.js.map +1 -0
  18. package/dist/collection/components/zero-account/websocket.js +176 -0
  19. package/dist/collection/components/zero-account/websocket.js.map +1 -0
  20. package/dist/collection/components/zero-account/zero-account.css +294 -0
  21. package/dist/collection/components/zero-account/zero-account.e2e.js +26 -0
  22. package/dist/collection/components/zero-account/zero-account.e2e.js.map +1 -0
  23. package/dist/collection/components/zero-account/zero-account.js +402 -0
  24. package/dist/collection/components/zero-account/zero-account.js.map +1 -0
  25. package/dist/collection/components/zero-account/zero-account.spec.js +35 -0
  26. package/dist/collection/components/zero-account/zero-account.spec.js.map +1 -0
  27. package/dist/collection/index.js +2 -0
  28. package/dist/collection/index.js.map +1 -0
  29. package/dist/{zero-account/qr-code.entry.js → collection/utils/qrcode/qrcode.js} +3 -35
  30. package/dist/collection/utils/request.js +45 -0
  31. package/dist/collection/utils/request.js.map +1 -0
  32. package/dist/collection/utils/url.js +43 -0
  33. package/dist/collection/utils/utils.js +16 -0
  34. package/dist/collection/utils/utils.js.map +1 -0
  35. package/dist/collection/utils/utils.spec.js +10 -0
  36. package/dist/collection/utils/utils.spec.js.map +1 -0
  37. package/dist/components/index.d.ts +6 -0
  38. package/dist/components/index.js +3 -0
  39. package/dist/components/index.js.map +1 -0
  40. package/dist/components/qr-code.d.ts +2 -2
  41. package/dist/components/qr-code.js +8 -0
  42. package/dist/components/qr-code.js.map +1 -0
  43. package/dist/components/qrcode.js +1073 -0
  44. package/dist/components/qrcode.js.map +1 -0
  45. package/dist/components/zero-account.d.ts +2 -2
  46. package/dist/components/zero-account.js +535 -0
  47. package/dist/components/zero-account.js.map +1 -0
  48. package/dist/esm/index-798be1d4.js +1919 -0
  49. package/dist/esm/index-798be1d4.js.map +1 -0
  50. package/dist/esm/index.js +3 -0
  51. package/dist/esm/index.js.map +1 -0
  52. package/dist/esm/loader.js +11 -0
  53. package/dist/esm/loader.js.map +1 -0
  54. package/dist/esm/polyfills/core-js.js +11 -0
  55. package/dist/esm/polyfills/dom.js +79 -0
  56. package/dist/esm/polyfills/es5-html-element.js +1 -0
  57. package/dist/esm/polyfills/index.js +34 -0
  58. package/dist/esm/polyfills/system.js +6 -0
  59. package/dist/esm/qr-code_2.entry.js +1545 -0
  60. package/dist/esm/qr-code_2.entry.js.map +1 -0
  61. package/dist/esm/zero-account.js +20 -0
  62. package/dist/esm/zero-account.js.map +1 -0
  63. package/dist/index.cjs.js +1 -0
  64. package/dist/index.js +1 -0
  65. package/dist/types/components/zero-account/enums.d.ts +8 -8
  66. package/dist/types/components/zero-account/logo.d.ts +2 -2
  67. package/dist/types/components/zero-account/qrcode.d.ts +5 -5
  68. package/dist/types/components/zero-account/websocket.d.ts +27 -25
  69. package/dist/types/components/zero-account/zero-account.d.ts +39 -39
  70. package/dist/types/stencil-public-runtime.d.ts +46 -5
  71. package/dist/types/utils/request.d.ts +5 -5
  72. package/dist/types/utils/utils.d.ts +3 -3
  73. package/dist/zero-account/index.esm.js +0 -1
  74. package/dist/zero-account/index.esm.js.map +1 -1
  75. package/dist/zero-account/p-3b6bbcf5.js +3 -0
  76. package/dist/zero-account/p-3b6bbcf5.js.map +1 -0
  77. package/dist/zero-account/p-b6f591cf.entry.js +2 -0
  78. package/dist/zero-account/p-b6f591cf.entry.js.map +1 -0
  79. package/dist/zero-account/zero-account.esm.js +1 -64
  80. package/dist/zero-account/zero-account.esm.js.map +1 -1
  81. package/loader/index.d.ts +1 -1
  82. package/package.json +10 -10
  83. package/dist/zero-account/app-globals-0f993ce5.js +0 -5
  84. package/dist/zero-account/app-globals-0f993ce5.js.map +0 -1
  85. package/dist/zero-account/enums-816340c2.js +0 -21
  86. package/dist/zero-account/enums-816340c2.js.map +0 -1
  87. package/dist/zero-account/enums-e7827156.js +0 -21
  88. package/dist/zero-account/enums-e7827156.js.map +0 -1
  89. package/dist/zero-account/index-57856b47.js +0 -3380
  90. package/dist/zero-account/index-57856b47.js.map +0 -1
  91. package/dist/zero-account/qr-code.entry.js.map +0 -1
  92. package/dist/zero-account/shadow-css-8a6ccf47.js +0 -389
  93. package/dist/zero-account/shadow-css-8a6ccf47.js.map +0 -1
  94. package/dist/zero-account/zero-account.entry.js +0 -1994
  95. package/dist/zero-account/zero-account.entry.js.map +0 -1
@@ -0,0 +1,1948 @@
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 = 'zero-account';
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 useNativeShadowDom = false;
36
+ let isSvgMode = false;
37
+ let queuePending = false;
38
+ const Build = {
39
+ isDev: false,
40
+ isBrowser: true,
41
+ isServer: false,
42
+ isTesting: false,
43
+ };
44
+ const createTime = (fnName, tagName = '') => {
45
+ {
46
+ return () => {
47
+ return;
48
+ };
49
+ }
50
+ };
51
+ const uniqueTime = (key, measureText) => {
52
+ {
53
+ return () => {
54
+ return;
55
+ };
56
+ }
57
+ };
58
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
59
+ /**
60
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
61
+ *
62
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
63
+ * support as of Stencil v4.
64
+ */
65
+ const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
66
+ /**
67
+ * Default style mode id
68
+ */
69
+ /**
70
+ * Reusable empty obj/array
71
+ * Don't add values to these!!
72
+ */
73
+ const EMPTY_OBJ = {};
74
+ /**
75
+ * Namespaces
76
+ */
77
+ const SVG_NS = 'http://www.w3.org/2000/svg';
78
+ const HTML_NS = 'http://www.w3.org/1999/xhtml';
79
+ const isDef = (v) => v != null;
80
+ /**
81
+ * Check whether a value is a 'complex type', defined here as an object or a
82
+ * function.
83
+ *
84
+ * @param o the value to check
85
+ * @returns whether it's a complex type or not
86
+ */
87
+ const isComplexType = (o) => {
88
+ // https://jsperf.com/typeof-fn-object/5
89
+ o = typeof o;
90
+ return o === 'object' || o === 'function';
91
+ };
92
+ /**
93
+ * Helper method for querying a `meta` tag that contains a nonce value
94
+ * out of a DOM's head.
95
+ *
96
+ * @param doc The DOM containing the `head` to query against
97
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
98
+ * exists or the tag has no content.
99
+ */
100
+ function queryNonceMetaTagContent(doc) {
101
+ var _a, _b, _c;
102
+ return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
103
+ }
104
+ /**
105
+ * Production h() function based on Preact by
106
+ * Jason Miller (@developit)
107
+ * Licensed under the MIT License
108
+ * https://github.com/developit/preact/blob/master/LICENSE
109
+ *
110
+ * Modified for Stencil's compiler and vdom
111
+ */
112
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
113
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
114
+ const h = (nodeName, vnodeData, ...children) => {
115
+ let child = null;
116
+ let key = null;
117
+ let simple = false;
118
+ let lastSimple = false;
119
+ const vNodeChildren = [];
120
+ const walk = (c) => {
121
+ for (let i = 0; i < c.length; i++) {
122
+ child = c[i];
123
+ if (Array.isArray(child)) {
124
+ walk(child);
125
+ }
126
+ else if (child != null && typeof child !== 'boolean') {
127
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
128
+ child = String(child);
129
+ }
130
+ if (simple && lastSimple) {
131
+ // If the previous child was simple (string), we merge both
132
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
133
+ }
134
+ else {
135
+ // Append a new vNode, if it's text, we create a text vNode
136
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
137
+ }
138
+ lastSimple = simple;
139
+ }
140
+ }
141
+ };
142
+ walk(children);
143
+ if (vnodeData) {
144
+ if (vnodeData.key) {
145
+ key = vnodeData.key;
146
+ }
147
+ // normalize class / className attributes
148
+ {
149
+ const classData = vnodeData.className || vnodeData.class;
150
+ if (classData) {
151
+ vnodeData.class =
152
+ typeof classData !== 'object'
153
+ ? classData
154
+ : Object.keys(classData)
155
+ .filter((k) => classData[k])
156
+ .join(' ');
157
+ }
158
+ }
159
+ }
160
+ if (typeof nodeName === 'function') {
161
+ // nodeName is a functional component
162
+ return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
163
+ }
164
+ const vnode = newVNode(nodeName, null);
165
+ vnode.$attrs$ = vnodeData;
166
+ if (vNodeChildren.length > 0) {
167
+ vnode.$children$ = vNodeChildren;
168
+ }
169
+ {
170
+ vnode.$key$ = key;
171
+ }
172
+ return vnode;
173
+ };
174
+ /**
175
+ * A utility function for creating a virtual DOM node from a tag and some
176
+ * possible text content.
177
+ *
178
+ * @param tag the tag for this element
179
+ * @param text possible text content for the node
180
+ * @returns a newly-minted virtual DOM node
181
+ */
182
+ const newVNode = (tag, text) => {
183
+ const vnode = {
184
+ $flags$: 0,
185
+ $tag$: tag,
186
+ $text$: text,
187
+ $elm$: null,
188
+ $children$: null,
189
+ };
190
+ {
191
+ vnode.$attrs$ = null;
192
+ }
193
+ {
194
+ vnode.$key$ = null;
195
+ }
196
+ return vnode;
197
+ };
198
+ const Host = {};
199
+ /**
200
+ * Check whether a given node is a Host node or not
201
+ *
202
+ * @param node the virtual DOM node to check
203
+ * @returns whether it's a Host node or not
204
+ */
205
+ const isHost = (node) => node && node.$tag$ === Host;
206
+ /**
207
+ * Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
208
+ *
209
+ * Note that these functions convert from {@link d.VNode} to
210
+ * {@link d.ChildNode} to give functional component developers a friendly
211
+ * interface.
212
+ */
213
+ const vdomFnUtils = {
214
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
215
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
216
+ };
217
+ /**
218
+ * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
219
+ * friendlier public interface (hence, 'convertToPublic').
220
+ *
221
+ * @param node the virtual DOM node to convert
222
+ * @returns a converted child node
223
+ */
224
+ const convertToPublic = (node) => ({
225
+ vattrs: node.$attrs$,
226
+ vchildren: node.$children$,
227
+ vkey: node.$key$,
228
+ vname: node.$name$,
229
+ vtag: node.$tag$,
230
+ vtext: node.$text$,
231
+ });
232
+ /**
233
+ * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
234
+ * order to use the resulting object in the virtual DOM. The initial object was
235
+ * likely created as part of presenting a public API, so converting it back
236
+ * involved making it 'private' again (hence, `convertToPrivate`).
237
+ *
238
+ * @param node the child node to convert
239
+ * @returns a converted virtual DOM node
240
+ */
241
+ const convertToPrivate = (node) => {
242
+ if (typeof node.vtag === 'function') {
243
+ const vnodeData = Object.assign({}, node.vattrs);
244
+ if (node.vkey) {
245
+ vnodeData.key = node.vkey;
246
+ }
247
+ if (node.vname) {
248
+ vnodeData.name = node.vname;
249
+ }
250
+ return h(node.vtag, vnodeData, ...(node.vchildren || []));
251
+ }
252
+ const vnode = newVNode(node.vtag, node.vtext);
253
+ vnode.$attrs$ = node.vattrs;
254
+ vnode.$children$ = node.vchildren;
255
+ vnode.$key$ = node.vkey;
256
+ vnode.$name$ = node.vname;
257
+ return vnode;
258
+ };
259
+ /**
260
+ * Parse a new property value for a given property type.
261
+ *
262
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
263
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
264
+ * 1. `any`, the type given to `propValue` in the function signature
265
+ * 2. the type stored from `propType`.
266
+ *
267
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
268
+ *
269
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
270
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
271
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
272
+ * ```tsx
273
+ * <my-cmp prop-val={0}></my-cmp>
274
+ * ```
275
+ *
276
+ * HTML prop values on the other hand, will always a string
277
+ *
278
+ * @param propValue the new value to coerce to some type
279
+ * @param propType the type of the prop, expressed as a binary number
280
+ * @returns the parsed/coerced value
281
+ */
282
+ const parsePropertyValue = (propValue, propType) => {
283
+ // ensure this value is of the correct prop type
284
+ if (propValue != null && !isComplexType(propValue)) {
285
+ if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
286
+ // per the HTML spec, any string value means it is a boolean true value
287
+ // but we'll cheat here and say that the string "false" is the boolean false
288
+ return propValue === 'false' ? false : propValue === '' || !!propValue;
289
+ }
290
+ if (propType & 2 /* MEMBER_FLAGS.Number */) {
291
+ // force it to be a number
292
+ return parseFloat(propValue);
293
+ }
294
+ if (propType & 1 /* MEMBER_FLAGS.String */) {
295
+ // could have been passed as a number or boolean
296
+ // but we still want it as a string
297
+ return String(propValue);
298
+ }
299
+ // redundant return here for better minification
300
+ return propValue;
301
+ }
302
+ // not sure exactly what type we want
303
+ // so no need to change to a different type
304
+ return propValue;
305
+ };
306
+ const getElement = (ref) => (getHostRef(ref).$hostElement$ );
307
+ /**
308
+ * Helper function to create & dispatch a custom Event on a provided target
309
+ * @param elm the target of the Event
310
+ * @param name the name to give the custom Event
311
+ * @param opts options for configuring a custom Event
312
+ * @returns the custom Event
313
+ */
314
+ const emitEvent = (elm, name, opts) => {
315
+ const ev = plt.ce(name, opts);
316
+ elm.dispatchEvent(ev);
317
+ return ev;
318
+ };
319
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
320
+ const registerStyle = (scopeId, cssText, allowCS) => {
321
+ let style = styles.get(scopeId);
322
+ if (supportsConstructableStylesheets && allowCS) {
323
+ style = (style || new CSSStyleSheet());
324
+ if (typeof style === 'string') {
325
+ style = cssText;
326
+ }
327
+ else {
328
+ style.replaceSync(cssText);
329
+ }
330
+ }
331
+ else {
332
+ style = cssText;
333
+ }
334
+ styles.set(scopeId, style);
335
+ };
336
+ const addStyle = (styleContainerNode, cmpMeta, mode) => {
337
+ var _a;
338
+ const scopeId = getScopeId(cmpMeta);
339
+ const style = styles.get(scopeId);
340
+ // if an element is NOT connected then getRootNode() will return the wrong root node
341
+ // so the fallback is to always use the document for the root node in those cases
342
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
343
+ if (style) {
344
+ if (typeof style === 'string') {
345
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
346
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
347
+ let styleElm;
348
+ if (!appliedStyles) {
349
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
350
+ }
351
+ if (!appliedStyles.has(scopeId)) {
352
+ {
353
+ styleElm = doc.createElement('style');
354
+ styleElm.innerHTML = style;
355
+ // Apply CSP nonce to the style tag if it exists
356
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
357
+ if (nonce != null) {
358
+ styleElm.setAttribute('nonce', nonce);
359
+ }
360
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
361
+ }
362
+ // Add styles for `slot-fb` elements if we're using slots outside the Shadow DOM
363
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
364
+ styleElm.innerHTML += SLOT_FB_CSS;
365
+ }
366
+ if (appliedStyles) {
367
+ appliedStyles.add(scopeId);
368
+ }
369
+ }
370
+ }
371
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
372
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
373
+ }
374
+ }
375
+ return scopeId;
376
+ };
377
+ const attachStyles = (hostRef) => {
378
+ const cmpMeta = hostRef.$cmpMeta$;
379
+ const elm = hostRef.$hostElement$;
380
+ const flags = cmpMeta.$flags$;
381
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
382
+ const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
383
+ if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
384
+ // only required when we're NOT using native shadow dom (slot)
385
+ // or this browser doesn't support native shadow dom
386
+ // and this host element was NOT created with SSR
387
+ // let's pick out the inner content for slot projection
388
+ // create a node to represent where the original
389
+ // content was first placed, which is useful later on
390
+ // DOM WRITE!!
391
+ elm['s-sc'] = scopeId;
392
+ elm.classList.add(scopeId + '-h');
393
+ }
394
+ endAttachStyles();
395
+ };
396
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
397
+ /**
398
+ * Production setAccessor() function based on Preact by
399
+ * Jason Miller (@developit)
400
+ * Licensed under the MIT License
401
+ * https://github.com/developit/preact/blob/master/LICENSE
402
+ *
403
+ * Modified for Stencil's compiler and vdom
404
+ */
405
+ /**
406
+ * When running a VDom render set properties present on a VDom node onto the
407
+ * corresponding HTML element.
408
+ *
409
+ * Note that this function has special functionality for the `class`,
410
+ * `style`, `key`, and `ref` attributes, as well as event handlers (like
411
+ * `onClick`, etc). All others are just passed through as-is.
412
+ *
413
+ * @param elm the HTMLElement onto which attributes should be set
414
+ * @param memberName the name of the attribute to set
415
+ * @param oldValue the old value for the attribute
416
+ * @param newValue the new value for the attribute
417
+ * @param isSvg whether we're in an svg context or not
418
+ * @param flags bitflags for Vdom variables
419
+ */
420
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
421
+ if (oldValue !== newValue) {
422
+ let isProp = isMemberInElement(elm, memberName);
423
+ let ln = memberName.toLowerCase();
424
+ if (memberName === 'class') {
425
+ const classList = elm.classList;
426
+ const oldClasses = parseClassList(oldValue);
427
+ const newClasses = parseClassList(newValue);
428
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
429
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
430
+ }
431
+ else if (memberName === 'key')
432
+ ;
433
+ else if (memberName === 'ref') {
434
+ // minifier will clean this up
435
+ if (newValue) {
436
+ newValue(elm);
437
+ }
438
+ }
439
+ else if ((!isProp ) &&
440
+ memberName[0] === 'o' &&
441
+ memberName[1] === 'n') {
442
+ // Event Handlers
443
+ // so if the member name starts with "on" and the 3rd characters is
444
+ // a capital letter, and it's not already a member on the element,
445
+ // then we're assuming it's an event listener
446
+ if (memberName[2] === '-') {
447
+ // on- prefixed events
448
+ // allows to be explicit about the dom event to listen without any magic
449
+ // under the hood:
450
+ // <my-cmp on-click> // listens for "click"
451
+ // <my-cmp on-Click> // listens for "Click"
452
+ // <my-cmp on-ionChange> // listens for "ionChange"
453
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
454
+ memberName = memberName.slice(3);
455
+ }
456
+ else if (isMemberInElement(win, ln)) {
457
+ // standard event
458
+ // the JSX attribute could have been "onMouseOver" and the
459
+ // member name "onmouseover" is on the window's prototype
460
+ // so let's add the listener "mouseover", which is all lowercased
461
+ memberName = ln.slice(2);
462
+ }
463
+ else {
464
+ // custom event
465
+ // the JSX attribute could have been "onMyCustomEvent"
466
+ // so let's trim off the "on" prefix and lowercase the first character
467
+ // and add the listener "myCustomEvent"
468
+ // except for the first character, we keep the event name case
469
+ memberName = ln[2] + memberName.slice(3);
470
+ }
471
+ if (oldValue || newValue) {
472
+ // Need to account for "capture" events.
473
+ // If the event name ends with "Capture", we'll update the name to remove
474
+ // the "Capture" suffix and make sure the event listener is setup to handle the capture event.
475
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
476
+ // Make sure we only replace the last instance of "Capture"
477
+ memberName = memberName.replace(CAPTURE_EVENT_REGEX, '');
478
+ if (oldValue) {
479
+ plt.rel(elm, memberName, oldValue, capture);
480
+ }
481
+ if (newValue) {
482
+ plt.ael(elm, memberName, newValue, capture);
483
+ }
484
+ }
485
+ }
486
+ else {
487
+ // Set property if it exists and it's not a SVG
488
+ const isComplex = isComplexType(newValue);
489
+ if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
490
+ try {
491
+ if (!elm.tagName.includes('-')) {
492
+ const n = newValue == null ? '' : newValue;
493
+ // Workaround for Safari, moving the <input> caret when re-assigning the same valued
494
+ if (memberName === 'list') {
495
+ isProp = false;
496
+ }
497
+ else if (oldValue == null || elm[memberName] != n) {
498
+ elm[memberName] = n;
499
+ }
500
+ }
501
+ else {
502
+ elm[memberName] = newValue;
503
+ }
504
+ }
505
+ catch (e) {
506
+ /**
507
+ * in case someone tries to set a read-only property, e.g. "namespaceURI", we just ignore it
508
+ */
509
+ }
510
+ }
511
+ if (newValue == null || newValue === false) {
512
+ if (newValue !== false || elm.getAttribute(memberName) === '') {
513
+ {
514
+ elm.removeAttribute(memberName);
515
+ }
516
+ }
517
+ }
518
+ else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
519
+ newValue = newValue === true ? '' : newValue;
520
+ {
521
+ elm.setAttribute(memberName, newValue);
522
+ }
523
+ }
524
+ }
525
+ }
526
+ };
527
+ const parseClassListRegex = /\s/;
528
+ /**
529
+ * Parsed a string of classnames into an array
530
+ * @param value className string, e.g. "foo bar baz"
531
+ * @returns list of classes, e.g. ["foo", "bar", "baz"]
532
+ */
533
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
534
+ const CAPTURE_EVENT_SUFFIX = 'Capture';
535
+ const CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + '$');
536
+ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
537
+ // if the element passed in is a shadow root, which is a document fragment
538
+ // then we want to be adding attrs/props to the shadow root's "host" element
539
+ // if it's not a shadow root, then we add attrs/props to the same element
540
+ const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
541
+ ? newVnode.$elm$.host
542
+ : newVnode.$elm$;
543
+ const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
544
+ const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
545
+ {
546
+ // remove attributes no longer present on the vnode by setting them to undefined
547
+ for (memberName in oldVnodeAttrs) {
548
+ if (!(memberName in newVnodeAttrs)) {
549
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
550
+ }
551
+ }
552
+ }
553
+ // add new & update changed attributes
554
+ for (memberName in newVnodeAttrs) {
555
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
556
+ }
557
+ };
558
+ /**
559
+ * Create a DOM Node corresponding to one of the children of a given VNode.
560
+ *
561
+ * @param oldParentVNode the parent VNode from the previous render
562
+ * @param newParentVNode the parent VNode from the current render
563
+ * @param childIndex the index of the VNode, in the _new_ parent node's
564
+ * children, for which we will create a new DOM node
565
+ * @param parentElm the parent DOM node which our new node will be a child of
566
+ * @returns the newly created node
567
+ */
568
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
569
+ // tslint:disable-next-line: prefer-const
570
+ const newVNode = newParentVNode.$children$[childIndex];
571
+ let i = 0;
572
+ let elm;
573
+ let childNode;
574
+ if (newVNode.$text$ !== null) {
575
+ // create text node
576
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
577
+ }
578
+ else {
579
+ if (!isSvgMode) {
580
+ isSvgMode = newVNode.$tag$ === 'svg';
581
+ }
582
+ // create element
583
+ elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$tag$)
584
+ );
585
+ if (isSvgMode && newVNode.$tag$ === 'foreignObject') {
586
+ isSvgMode = false;
587
+ }
588
+ // add css classes, attrs, props, listeners, etc.
589
+ {
590
+ updateElement(null, newVNode, isSvgMode);
591
+ }
592
+ if (isDef(scopeId) && elm['s-si'] !== scopeId) {
593
+ // if there is a scopeId and this is the initial render
594
+ // then let's add the scopeId as a css class
595
+ elm.classList.add((elm['s-si'] = scopeId));
596
+ }
597
+ if (newVNode.$children$) {
598
+ for (i = 0; i < newVNode.$children$.length; ++i) {
599
+ // create the node
600
+ childNode = createElm(oldParentVNode, newVNode, i);
601
+ // return node could have been null
602
+ if (childNode) {
603
+ // append our new node
604
+ elm.appendChild(childNode);
605
+ }
606
+ }
607
+ }
608
+ {
609
+ if (newVNode.$tag$ === 'svg') {
610
+ // Only reset the SVG context when we're exiting <svg> element
611
+ isSvgMode = false;
612
+ }
613
+ else if (elm.tagName === 'foreignObject') {
614
+ // Reenter SVG context when we're exiting <foreignObject> element
615
+ isSvgMode = true;
616
+ }
617
+ }
618
+ }
619
+ // This needs to always happen so we can hide nodes that are projected
620
+ // to another component but don't end up in a slot
621
+ elm['s-hn'] = hostTagName;
622
+ return elm;
623
+ };
624
+ /**
625
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
626
+ * add them to the DOM in the appropriate place.
627
+ *
628
+ * @param parentElm the DOM node which should be used as a parent for the new
629
+ * DOM nodes
630
+ * @param before a child of the `parentElm` which the new children should be
631
+ * inserted before (optional)
632
+ * @param parentVNode the parent virtual DOM node
633
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
634
+ * @param startIdx the index in the child virtual DOM nodes at which to start
635
+ * creating DOM nodes (inclusive)
636
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
637
+ * creating DOM nodes (inclusive)
638
+ */
639
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
640
+ let containerElm = (parentElm);
641
+ let childNode;
642
+ if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
643
+ containerElm = containerElm.shadowRoot;
644
+ }
645
+ for (; startIdx <= endIdx; ++startIdx) {
646
+ if (vnodes[startIdx]) {
647
+ childNode = createElm(null, parentVNode, startIdx);
648
+ if (childNode) {
649
+ vnodes[startIdx].$elm$ = childNode;
650
+ containerElm.insertBefore(childNode, before);
651
+ }
652
+ }
653
+ }
654
+ };
655
+ /**
656
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
657
+ * This can be used to, for instance, clean up after a list of children which
658
+ * should no longer be shown.
659
+ *
660
+ * This function also handles some of Stencil's slot relocation logic.
661
+ *
662
+ * @param vnodes a list of virtual DOM nodes to remove
663
+ * @param startIdx the index at which to start removing nodes (inclusive)
664
+ * @param endIdx the index at which to stop removing nodes (inclusive)
665
+ */
666
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
667
+ for (let index = startIdx; index <= endIdx; ++index) {
668
+ const vnode = vnodes[index];
669
+ if (vnode) {
670
+ const elm = vnode.$elm$;
671
+ nullifyVNodeRefs(vnode);
672
+ if (elm) {
673
+ // remove the vnode's element from the dom
674
+ elm.remove();
675
+ }
676
+ }
677
+ }
678
+ };
679
+ /**
680
+ * Reconcile the children of a new VNode with the children of an old VNode by
681
+ * traversing the two collections of children, identifying nodes that are
682
+ * conserved or changed, calling out to `patch` to make any necessary
683
+ * updates to the DOM, and rearranging DOM nodes as needed.
684
+ *
685
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
686
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
687
+ * 'windows' by storing start and end indices and references to the
688
+ * corresponding array entries. Initially the two 'windows' are basically equal
689
+ * to the entire array, but we progressively narrow the windows until there are
690
+ * no children left to update by doing the following:
691
+ *
692
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
693
+ * that if we have an initial array like the following we'll end up dealing
694
+ * only with a window bounded by the highlighted elements:
695
+ *
696
+ * [null, null, VNode1 , ... , VNode2, null, null]
697
+ * ^^^^^^ ^^^^^^
698
+ *
699
+ * 2. Check to see if the elements at the head and tail positions are equal
700
+ * across the windows. This will basically detect elements which haven't
701
+ * been added, removed, or changed position, i.e. if you had the following
702
+ * VNode elements (represented as HTML):
703
+ *
704
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
705
+ * newVNode: `<div><p><span>THERE</span></p></div>`
706
+ *
707
+ * Then when comparing the children of the `<div>` tag we check the equality
708
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
709
+ * same tag in the same position, we'd be able to avoid completely
710
+ * re-rendering the subtree under them with a new DOM element and would just
711
+ * call out to `patch` to handle reconciling their children and so on.
712
+ *
713
+ * 3. Check, for both windows, to see if the element at the beginning of the
714
+ * window corresponds to the element at the end of the other window. This is
715
+ * a heuristic which will let us identify _some_ situations in which
716
+ * elements have changed position, for instance it _should_ detect that the
717
+ * children nodes themselves have not changed but merely moved in the
718
+ * following example:
719
+ *
720
+ * oldVNode: `<div><element-one /><element-two /></div>`
721
+ * newVNode: `<div><element-two /><element-one /></div>`
722
+ *
723
+ * If we find cases like this then we also need to move the concrete DOM
724
+ * elements corresponding to the moved children to write the re-order to the
725
+ * DOM.
726
+ *
727
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
728
+ * nodes in the old children which have the same key as the first element in
729
+ * our window on the new children. If we find such a node we handle calling
730
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
731
+ * what we find.
732
+ *
733
+ * Finally, once we've narrowed our 'windows' to the point that either of them
734
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
735
+ * insertion or deletion that needs to happen to get a DOM state that correctly
736
+ * reflects the new child VNodes. If, for instance, after our window on the old
737
+ * children has collapsed we still have more nodes on the new children that
738
+ * we haven't dealt with yet then we need to add them, or if the new children
739
+ * collapse but we still have unhandled _old_ children then we need to make
740
+ * sure the corresponding DOM nodes are removed.
741
+ *
742
+ * @param parentElm the node into which the parent VNode is rendered
743
+ * @param oldCh the old children of the parent node
744
+ * @param newVNode the new VNode which will replace the parent
745
+ * @param newCh the new children of the parent node
746
+ * @param isInitialRender whether or not this is the first render of the vdom
747
+ */
748
+ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
749
+ let oldStartIdx = 0;
750
+ let newStartIdx = 0;
751
+ let idxInOld = 0;
752
+ let i = 0;
753
+ let oldEndIdx = oldCh.length - 1;
754
+ let oldStartVnode = oldCh[0];
755
+ let oldEndVnode = oldCh[oldEndIdx];
756
+ let newEndIdx = newCh.length - 1;
757
+ let newStartVnode = newCh[0];
758
+ let newEndVnode = newCh[newEndIdx];
759
+ let node;
760
+ let elmToMove;
761
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
762
+ if (oldStartVnode == null) {
763
+ // VNode might have been moved left
764
+ oldStartVnode = oldCh[++oldStartIdx];
765
+ }
766
+ else if (oldEndVnode == null) {
767
+ oldEndVnode = oldCh[--oldEndIdx];
768
+ }
769
+ else if (newStartVnode == null) {
770
+ newStartVnode = newCh[++newStartIdx];
771
+ }
772
+ else if (newEndVnode == null) {
773
+ newEndVnode = newCh[--newEndIdx];
774
+ }
775
+ else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
776
+ // if the start nodes are the same then we should patch the new VNode
777
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
778
+ // indices to reflect that. We don't need to move any DOM Nodes around
779
+ // since things are matched up in order.
780
+ patch(oldStartVnode, newStartVnode, isInitialRender);
781
+ oldStartVnode = oldCh[++oldStartIdx];
782
+ newStartVnode = newCh[++newStartIdx];
783
+ }
784
+ else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
785
+ // likewise, if the end nodes are the same we patch new onto old and
786
+ // decrement our end indices, and also likewise in this case we don't
787
+ // need to move any DOM Nodes.
788
+ patch(oldEndVnode, newEndVnode, isInitialRender);
789
+ oldEndVnode = oldCh[--oldEndIdx];
790
+ newEndVnode = newCh[--newEndIdx];
791
+ }
792
+ else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
793
+ patch(oldStartVnode, newEndVnode, isInitialRender);
794
+ // We need to move the element for `oldStartVnode` into a position which
795
+ // will be appropriate for `newEndVnode`. For this we can use
796
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
797
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
798
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
799
+ //
800
+ // <old-start-node />
801
+ // <some-intervening-node />
802
+ // <old-end-node />
803
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
804
+ // <next-sibling />
805
+ //
806
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
807
+ // the node for `oldStartVnode` at the end of the children of
808
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
809
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
810
+ // append it to the children of the parent element.
811
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
812
+ oldStartVnode = oldCh[++oldStartIdx];
813
+ newEndVnode = newCh[--newEndIdx];
814
+ }
815
+ else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
816
+ patch(oldEndVnode, newStartVnode, isInitialRender);
817
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
818
+ // the same node, so since we're here we know that they are not. Thus we
819
+ // can move the element for `oldEndVnode` _before_ the element for
820
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
821
+ // future.
822
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
823
+ oldEndVnode = oldCh[--oldEndIdx];
824
+ newStartVnode = newCh[++newStartIdx];
825
+ }
826
+ else {
827
+ // Here we do some checks to match up old and new nodes based on the
828
+ // `$key$` attribute, which is set by putting a `key="my-key"` attribute
829
+ // in the JSX for a DOM element in the implementation of a Stencil
830
+ // component.
831
+ //
832
+ // First we check to see if there are any nodes in the array of old
833
+ // children which have the same key as the first node in the new
834
+ // children.
835
+ idxInOld = -1;
836
+ {
837
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) {
838
+ if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
839
+ idxInOld = i;
840
+ break;
841
+ }
842
+ }
843
+ }
844
+ if (idxInOld >= 0) {
845
+ // We found a node in the old children which matches up with the first
846
+ // node in the new children! So let's deal with that
847
+ elmToMove = oldCh[idxInOld];
848
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) {
849
+ // the tag doesn't match so we'll need a new DOM element
850
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
851
+ }
852
+ else {
853
+ patch(elmToMove, newStartVnode, isInitialRender);
854
+ // invalidate the matching old node so that we won't try to update it
855
+ // again later on
856
+ oldCh[idxInOld] = undefined;
857
+ node = elmToMove.$elm$;
858
+ }
859
+ newStartVnode = newCh[++newStartIdx];
860
+ }
861
+ else {
862
+ // We either didn't find an element in the old children that matches
863
+ // the key of the first new child OR the build is not using `key`
864
+ // attributes at all. In either case we need to create a new element
865
+ // for the new node.
866
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
867
+ newStartVnode = newCh[++newStartIdx];
868
+ }
869
+ if (node) {
870
+ // if we created a new node then handle inserting it to the DOM
871
+ {
872
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
873
+ }
874
+ }
875
+ }
876
+ }
877
+ if (oldStartIdx > oldEndIdx) {
878
+ // we have some more new nodes to add which don't match up with old nodes
879
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
880
+ }
881
+ else if (newStartIdx > newEndIdx) {
882
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
883
+ // in the new array, so lets remove them (which entails cleaning up the
884
+ // relevant DOM nodes)
885
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
886
+ }
887
+ };
888
+ /**
889
+ * Compare two VNodes to determine if they are the same
890
+ *
891
+ * **NB**: This function is an equality _heuristic_ based on the available
892
+ * information set on the two VNodes and can be misleading under certain
893
+ * circumstances. In particular, if the two nodes do not have `key` attrs
894
+ * (available under `$key$` on VNodes) then the function falls back on merely
895
+ * checking that they have the same tag.
896
+ *
897
+ * So, in other words, if `key` attrs are not set on VNodes which may be
898
+ * changing order within a `children` array or something along those lines then
899
+ * we could obtain a false negative and then have to do needless re-rendering
900
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
901
+ *
902
+ * @param leftVNode the first VNode to check
903
+ * @param rightVNode the second VNode to check
904
+ * @param isInitialRender whether or not this is the first render of the vdom
905
+ * @returns whether they're equal or not
906
+ */
907
+ const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
908
+ // compare if two vnode to see if they're "technically" the same
909
+ // need to have the same element tag, and same key to be the same
910
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
911
+ // this will be set if JSX tags in the build have `key` attrs set on them
912
+ // we only want to check this if we're not on the first render since on
913
+ // first render `leftVNode.$key$` will always be `null`, so we can be led
914
+ // astray and, for instance, accidentally delete a DOM node that we want to
915
+ // keep around.
916
+ if (!isInitialRender) {
917
+ return leftVNode.$key$ === rightVNode.$key$;
918
+ }
919
+ return true;
920
+ }
921
+ return false;
922
+ };
923
+ /**
924
+ * Handle reconciling an outdated VNode with a new one which corresponds to
925
+ * it. This function handles flushing updates to the DOM and reconciling the
926
+ * children of the two nodes (if any).
927
+ *
928
+ * @param oldVNode an old VNode whose DOM element and children we want to update
929
+ * @param newVNode a new VNode representing an updated version of the old one
930
+ * @param isInitialRender whether or not this is the first render of the vdom
931
+ */
932
+ const patch = (oldVNode, newVNode, isInitialRender = false) => {
933
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
934
+ const oldChildren = oldVNode.$children$;
935
+ const newChildren = newVNode.$children$;
936
+ const tag = newVNode.$tag$;
937
+ const text = newVNode.$text$;
938
+ if (text === null) {
939
+ {
940
+ // test if we're rendering an svg element, or still rendering nodes inside of one
941
+ // only add this to the when the compiler sees we're using an svg somewhere
942
+ isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
943
+ }
944
+ {
945
+ if (tag === 'slot' && !useNativeShadowDom) ;
946
+ else {
947
+ // either this is the first render of an element OR it's an update
948
+ // AND we already know it's possible it could have changed
949
+ // this updates the element's css classes, attrs, props, listeners, etc.
950
+ updateElement(oldVNode, newVNode, isSvgMode);
951
+ }
952
+ }
953
+ if (oldChildren !== null && newChildren !== null) {
954
+ // looks like there's child vnodes for both the old and new vnodes
955
+ // so we need to call `updateChildren` to reconcile them
956
+ updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
957
+ }
958
+ else if (newChildren !== null) {
959
+ // no old child vnodes, but there are new child vnodes to add
960
+ if (oldVNode.$text$ !== null) {
961
+ // the old vnode was text, so be sure to clear it out
962
+ elm.textContent = '';
963
+ }
964
+ // add the new vnode children
965
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
966
+ }
967
+ else if (oldChildren !== null) {
968
+ // no new child vnodes, but there are old child vnodes to remove
969
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
970
+ }
971
+ if (isSvgMode && tag === 'svg') {
972
+ isSvgMode = false;
973
+ }
974
+ }
975
+ else if (oldVNode.$text$ !== text) {
976
+ // update the text content for the text only vnode
977
+ // and also only if the text is different than before
978
+ elm.data = text;
979
+ }
980
+ };
981
+ /**
982
+ * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
983
+ * them with `null`. This signals that the DOM element corresponding to the VDom
984
+ * node has been removed from the DOM.
985
+ *
986
+ * @param vNode a virtual DOM node
987
+ */
988
+ const nullifyVNodeRefs = (vNode) => {
989
+ {
990
+ vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
991
+ vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
992
+ }
993
+ };
994
+ /**
995
+ * The main entry point for Stencil's virtual DOM-based rendering engine
996
+ *
997
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
998
+ * function will handle creating a virtual DOM tree with a single root, patching
999
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
1000
+ * relocation, and reflecting attributes.
1001
+ *
1002
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
1003
+ * the DOM node into which it should be rendered.
1004
+ * @param renderFnResults the virtual DOM nodes to be rendered
1005
+ * @param isInitialLoad whether or not this is the first call after page load
1006
+ */
1007
+ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1008
+ const hostElm = hostRef.$hostElement$;
1009
+ const cmpMeta = hostRef.$cmpMeta$;
1010
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1011
+ // if `renderFnResults` is a Host node then we can use it directly. If not,
1012
+ // we need to call `h` again to wrap the children of our component in a
1013
+ // 'dummy' Host node (well, an empty vnode) since `renderVdom` assumes
1014
+ // implicitly that the top-level vdom node is 1) an only child and 2)
1015
+ // contains attrs that need to be set on the host element.
1016
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1017
+ hostTagName = hostElm.tagName;
1018
+ // On the first render and *only* on the first render we want to check for
1019
+ // any attributes set on the host element which are also set on the vdom
1020
+ // node. If we find them, we override the value on the VDom node attrs with
1021
+ // the value from the host element, which allows developers building apps
1022
+ // with Stencil components to override e.g. the `role` attribute on a
1023
+ // component even if it's already set on the `Host`.
1024
+ if (isInitialLoad && rootVnode.$attrs$) {
1025
+ for (const key of Object.keys(rootVnode.$attrs$)) {
1026
+ // We have a special implementation in `setAccessor` for `style` and
1027
+ // `class` which reconciles values coming from the VDom with values
1028
+ // already present on the DOM element, so we don't want to override those
1029
+ // attributes on the VDom tree with values from the host element if they
1030
+ // are present.
1031
+ //
1032
+ // Likewise, `ref` and `key` are special internal values for the Stencil
1033
+ // runtime and we don't want to override those either.
1034
+ if (hostElm.hasAttribute(key) && !['key', 'ref', 'style', 'class'].includes(key)) {
1035
+ rootVnode.$attrs$[key] = hostElm[key];
1036
+ }
1037
+ }
1038
+ }
1039
+ rootVnode.$tag$ = null;
1040
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
1041
+ hostRef.$vnode$ = rootVnode;
1042
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
1043
+ {
1044
+ scopeId = hostElm['s-sc'];
1045
+ }
1046
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1047
+ // synchronous patch
1048
+ patch(oldVNode, rootVnode, isInitialLoad);
1049
+ };
1050
+ const attachToAncestor = (hostRef, ancestorComponent) => {
1051
+ if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1052
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
1053
+ }
1054
+ };
1055
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
1056
+ {
1057
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
1058
+ }
1059
+ if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1060
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
1061
+ return;
1062
+ }
1063
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1064
+ // there is no ancestor component or the ancestor component
1065
+ // has already fired off its lifecycle update then
1066
+ // fire off the initial update
1067
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1068
+ return writeTask(dispatch) ;
1069
+ };
1070
+ /**
1071
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
1072
+ * component lifecycle methods like `componentWillLoad` as well as
1073
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
1074
+ *
1075
+ * @param hostRef a reference to a host DOM node
1076
+ * @param isInitialLoad whether we're on the initial load or not
1077
+ * @returns an empty Promise which is used to enqueue a series of operations for
1078
+ * the component
1079
+ */
1080
+ const dispatchHooks = (hostRef, isInitialLoad) => {
1081
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1082
+ const instance = hostRef.$lazyInstance$ ;
1083
+ // We're going to use this variable together with `enqueue` to implement a
1084
+ // little promise-based queue. We start out with it `undefined`. When we add
1085
+ // the first function to the queue we'll set this variable to be that
1086
+ // function's return value. When we attempt to add subsequent values to the
1087
+ // queue we'll check that value and, if it was a `Promise`, we'll then chain
1088
+ // the new function off of that `Promise` using `.then()`. This will give our
1089
+ // queue two nice properties:
1090
+ //
1091
+ // 1. If all functions added to the queue are synchronous they'll be called
1092
+ // synchronously right away.
1093
+ // 2. If all functions added to the queue are asynchronous they'll all be
1094
+ // called in order after `dispatchHooks` exits.
1095
+ let maybePromise;
1096
+ if (isInitialLoad) {
1097
+ {
1098
+ hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
1099
+ if (hostRef.$queuedListeners$) {
1100
+ hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1101
+ hostRef.$queuedListeners$ = undefined;
1102
+ }
1103
+ }
1104
+ {
1105
+ // If `componentWillLoad` returns a `Promise` then we want to wait on
1106
+ // whatever's going on in that `Promise` before we launch into
1107
+ // rendering the component, doing other lifecycle stuff, etc. So
1108
+ // in that case we assign the returned promise to the variable we
1109
+ // declared above to hold a possible 'queueing' Promise
1110
+ maybePromise = safeCall(instance, 'componentWillLoad');
1111
+ }
1112
+ }
1113
+ endSchedule();
1114
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
1115
+ };
1116
+ /**
1117
+ * This function uses a Promise to implement a simple first-in, first-out queue
1118
+ * of functions to be called.
1119
+ *
1120
+ * The queue is ordered on the basis of the first argument. If it's
1121
+ * `undefined`, then nothing is on the queue yet, so the provided function can
1122
+ * be called synchronously (although note that this function may return a
1123
+ * `Promise`). The idea is that then the return value of that enqueueing
1124
+ * operation is kept around, so that if it was a `Promise` then subsequent
1125
+ * functions can be enqueued by calling this function again with that `Promise`
1126
+ * as the first argument.
1127
+ *
1128
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
1129
+ * @param fn a function to enqueue
1130
+ * @returns either a `Promise` or the return value of the provided function
1131
+ */
1132
+ const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
1133
+ /**
1134
+ * Check that a value is a `Promise`. To check, we first see if the value is an
1135
+ * instance of the `Promise` global. In a few circumstances, in particular if
1136
+ * the global has been overwritten, this is could be misleading, so we also do
1137
+ * a little 'duck typing' check to see if the `.then` property of the value is
1138
+ * defined and a function.
1139
+ *
1140
+ * @param maybePromise it might be a promise!
1141
+ * @returns whether it is or not
1142
+ */
1143
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
1144
+ (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
1145
+ /**
1146
+ * Update a component given reference to its host elements and so on.
1147
+ *
1148
+ * @param hostRef an object containing references to the element's host node,
1149
+ * VDom nodes, and other metadata
1150
+ * @param instance a reference to the underlying host element where it will be
1151
+ * rendered
1152
+ * @param isInitialLoad whether or not this function is being called as part of
1153
+ * the first render cycle
1154
+ */
1155
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1156
+ var _a;
1157
+ const elm = hostRef.$hostElement$;
1158
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1159
+ const rc = elm['s-rc'];
1160
+ if (isInitialLoad) {
1161
+ // DOM WRITE!
1162
+ attachStyles(hostRef);
1163
+ }
1164
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1165
+ {
1166
+ callRender(hostRef, instance, elm, isInitialLoad);
1167
+ }
1168
+ if (rc) {
1169
+ // ok, so turns out there are some child host elements
1170
+ // waiting on this parent element to load
1171
+ // let's fire off all update callbacks waiting
1172
+ rc.map((cb) => cb());
1173
+ elm['s-rc'] = undefined;
1174
+ }
1175
+ endRender();
1176
+ endUpdate();
1177
+ {
1178
+ const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
1179
+ const postUpdate = () => postUpdateComponent(hostRef);
1180
+ if (childrenPromises.length === 0) {
1181
+ postUpdate();
1182
+ }
1183
+ else {
1184
+ Promise.all(childrenPromises).then(postUpdate);
1185
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1186
+ childrenPromises.length = 0;
1187
+ }
1188
+ }
1189
+ };
1190
+ /**
1191
+ * Handle making the call to the VDom renderer with the proper context given
1192
+ * various build variables
1193
+ *
1194
+ * @param hostRef an object containing references to the element's host node,
1195
+ * VDom nodes, and other metadata
1196
+ * @param instance a reference to the underlying host element where it will be
1197
+ * rendered
1198
+ * @param elm the Host element for the component
1199
+ * @param isInitialLoad whether or not this function is being called as part of
1200
+ * @returns an empty promise
1201
+ */
1202
+ const callRender = (hostRef, instance, elm, isInitialLoad) => {
1203
+ try {
1204
+ /**
1205
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
1206
+ * method, so we can call the method immediately. If not, check before calling it.
1207
+ */
1208
+ instance = instance.render() ;
1209
+ {
1210
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1211
+ }
1212
+ {
1213
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1214
+ }
1215
+ {
1216
+ {
1217
+ // looks like we've got child nodes to render into this host element
1218
+ // or we need to update the css class/attrs on the host element
1219
+ // DOM WRITE!
1220
+ {
1221
+ renderVdom(hostRef, instance, isInitialLoad);
1222
+ }
1223
+ }
1224
+ }
1225
+ }
1226
+ catch (e) {
1227
+ consoleError(e, hostRef.$hostElement$);
1228
+ }
1229
+ return null;
1230
+ };
1231
+ const postUpdateComponent = (hostRef) => {
1232
+ const tagName = hostRef.$cmpMeta$.$tagName$;
1233
+ const elm = hostRef.$hostElement$;
1234
+ const endPostUpdate = createTime('postUpdate', tagName);
1235
+ const ancestorComponent = hostRef.$ancestorComponent$;
1236
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1237
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1238
+ {
1239
+ // DOM WRITE!
1240
+ addHydratedFlag(elm);
1241
+ }
1242
+ endPostUpdate();
1243
+ {
1244
+ hostRef.$onReadyResolve$(elm);
1245
+ if (!ancestorComponent) {
1246
+ appDidLoad();
1247
+ }
1248
+ }
1249
+ }
1250
+ else {
1251
+ endPostUpdate();
1252
+ }
1253
+ // load events fire from bottom to top
1254
+ // the deepest elements load first then bubbles up
1255
+ {
1256
+ if (hostRef.$onRenderResolve$) {
1257
+ hostRef.$onRenderResolve$();
1258
+ hostRef.$onRenderResolve$ = undefined;
1259
+ }
1260
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1261
+ nextTick(() => scheduleUpdate(hostRef, false));
1262
+ }
1263
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1264
+ }
1265
+ // ( •_•)
1266
+ // ( •_•)>⌐■-■
1267
+ // (⌐■_■)
1268
+ };
1269
+ const appDidLoad = (who) => {
1270
+ // on appload
1271
+ // we have finish the first big initial render
1272
+ {
1273
+ addHydratedFlag(doc.documentElement);
1274
+ }
1275
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1276
+ };
1277
+ /**
1278
+ * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
1279
+ * e.g. custom element node. If a build figures out that e.g. no component
1280
+ * has a `componentDidLoad` method, the instance method gets removed from the
1281
+ * output bundle and this function returns `undefined`.
1282
+ * @param instance any object that may or may not contain methods
1283
+ * @param method method name
1284
+ * @param arg single arbitrary argument
1285
+ * @returns result of method call if it exists, otherwise `undefined`
1286
+ */
1287
+ const safeCall = (instance, method, arg) => {
1288
+ if (instance && instance[method]) {
1289
+ try {
1290
+ return instance[method](arg);
1291
+ }
1292
+ catch (e) {
1293
+ consoleError(e);
1294
+ }
1295
+ }
1296
+ return undefined;
1297
+ };
1298
+ const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1299
+ ;
1300
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1301
+ const setValue = (ref, propName, newVal, cmpMeta) => {
1302
+ // check our new property value against our internal value
1303
+ const hostRef = getHostRef(ref);
1304
+ const oldVal = hostRef.$instanceValues$.get(propName);
1305
+ const flags = hostRef.$flags$;
1306
+ const instance = hostRef.$lazyInstance$ ;
1307
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1308
+ // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1309
+ const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1310
+ const didValueChange = newVal !== oldVal && !areBothNaN;
1311
+ if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1312
+ // gadzooks! the property's value has changed!!
1313
+ // set our new value!
1314
+ hostRef.$instanceValues$.set(propName, newVal);
1315
+ if (instance) {
1316
+ if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1317
+ // looks like this value actually changed, so we've got work to do!
1318
+ // but only if we've already rendered, otherwise just chill out
1319
+ // queue that we need to do an update, but don't worry about queuing
1320
+ // up millions cuz this function ensures it only runs once
1321
+ scheduleUpdate(hostRef, false);
1322
+ }
1323
+ }
1324
+ }
1325
+ };
1326
+ /**
1327
+ * Attach a series of runtime constructs to a compiled Stencil component
1328
+ * constructor, including getters and setters for the `@Prop` and `@State`
1329
+ * decorators, callbacks for when attributes change, and so on.
1330
+ *
1331
+ * @param Cstr the constructor for a component that we need to process
1332
+ * @param cmpMeta metadata collected previously about the component
1333
+ * @param flags a number used to store a series of bit flags
1334
+ * @returns a reference to the same constructor passed in (but now mutated)
1335
+ */
1336
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
1337
+ var _a;
1338
+ const prototype = Cstr.prototype;
1339
+ if (cmpMeta.$members$) {
1340
+ // It's better to have a const than two Object.entries()
1341
+ const members = Object.entries(cmpMeta.$members$);
1342
+ members.map(([memberName, [memberFlags]]) => {
1343
+ if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1344
+ ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1345
+ // proxyComponent - prop
1346
+ Object.defineProperty(prototype, memberName, {
1347
+ get() {
1348
+ // proxyComponent, get value
1349
+ return getValue(this, memberName);
1350
+ },
1351
+ set(newValue) {
1352
+ // proxyComponent, set value
1353
+ setValue(this, memberName, newValue, cmpMeta);
1354
+ },
1355
+ configurable: true,
1356
+ enumerable: true,
1357
+ });
1358
+ }
1359
+ });
1360
+ if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1361
+ const attrNameToPropName = new Map();
1362
+ prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
1363
+ plt.jmp(() => {
1364
+ var _a;
1365
+ const propName = attrNameToPropName.get(attrName);
1366
+ // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1367
+ // in the case where an attribute was set inline.
1368
+ // ```html
1369
+ // <my-component some-attribute="some-value"></my-component>
1370
+ // ```
1371
+ //
1372
+ // There is an edge case where a developer sets the attribute inline on a custom element and then
1373
+ // programmatically changes it before it has been upgraded as shown below:
1374
+ //
1375
+ // ```html
1376
+ // <!-- this component has _not_ been upgraded yet -->
1377
+ // <my-component id="test" some-attribute="some-value"></my-component>
1378
+ // <script>
1379
+ // // grab non-upgraded component
1380
+ // el = document.querySelector("#test");
1381
+ // el.someAttribute = "another-value";
1382
+ // // upgrade component
1383
+ // customElements.define('my-component', MyComponent);
1384
+ // </script>
1385
+ // ```
1386
+ // In this case if we do not un-shadow here and use the value of the shadowing property, attributeChangedCallback
1387
+ // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1388
+ // to the value that was set inline i.e. "some-value" from above example. When
1389
+ // the connectedCallback attempts to un-shadow it will use "some-value" as the initial value rather than "another-value"
1390
+ //
1391
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/un-shadowed
1392
+ // by connectedCallback as this attributeChangedCallback will not fire.
1393
+ //
1394
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1395
+ //
1396
+ // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1397
+ // properties here given that this goes against best practices outlined here
1398
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1399
+ if (this.hasOwnProperty(propName)) {
1400
+ newValue = this[propName];
1401
+ delete this[propName];
1402
+ }
1403
+ else if (prototype.hasOwnProperty(propName) &&
1404
+ typeof this[propName] === 'number' &&
1405
+ this[propName] == newValue) {
1406
+ // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1407
+ // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1408
+ // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1409
+ return;
1410
+ }
1411
+ else if (propName == null) {
1412
+ // At this point we should know this is not a "member", so we can treat it like watching an attribute
1413
+ // on a vanilla web component
1414
+ const hostRef = getHostRef(this);
1415
+ const flags = hostRef === null || hostRef === void 0 ? void 0 : hostRef.$flags$;
1416
+ // We only want to trigger the callback(s) if:
1417
+ // 1. The instance is ready
1418
+ // 2. The watchers are ready
1419
+ // 3. The value has changed
1420
+ if (flags &&
1421
+ !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) &&
1422
+ flags & 128 /* HOST_FLAGS.isWatchReady */ &&
1423
+ newValue !== oldValue) {
1424
+ const instance = hostRef.$lazyInstance$ ;
1425
+ const entry = (_a = cmpMeta.$watchers$) === null || _a === void 0 ? void 0 : _a[attrName];
1426
+ entry === null || entry === void 0 ? void 0 : entry.forEach((callbackName) => {
1427
+ if (instance[callbackName] != null) {
1428
+ instance[callbackName].call(instance, newValue, oldValue, attrName);
1429
+ }
1430
+ });
1431
+ }
1432
+ return;
1433
+ }
1434
+ this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1435
+ });
1436
+ };
1437
+ // Create an array of attributes to observe
1438
+ // This list in comprised of all strings used within a `@Watch()` decorator
1439
+ // on a component as well as any Stencil-specific "members" (`@Prop()`s and `@State()`s).
1440
+ // As such, there is no way to guarantee type-safety here that a user hasn't entered
1441
+ // an invalid attribute.
1442
+ Cstr.observedAttributes = Array.from(new Set([
1443
+ ...Object.keys((_a = cmpMeta.$watchers$) !== null && _a !== void 0 ? _a : {}),
1444
+ ...members
1445
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */)
1446
+ .map(([propName, m]) => {
1447
+ const attrName = m[1] || propName;
1448
+ attrNameToPropName.set(attrName, propName);
1449
+ return attrName;
1450
+ }),
1451
+ ]));
1452
+ }
1453
+ }
1454
+ return Cstr;
1455
+ };
1456
+ /**
1457
+ * Initialize a Stencil component given a reference to its host element, its
1458
+ * runtime bookkeeping data structure, runtime metadata about the component,
1459
+ * and (optionally) an HMR version ID.
1460
+ *
1461
+ * @param elm a host element
1462
+ * @param hostRef the element's runtime bookkeeping object
1463
+ * @param cmpMeta runtime metadata for the Stencil component
1464
+ * @param hmrVersionId an (optional) HMR version ID
1465
+ */
1466
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
1467
+ let Cstr;
1468
+ // initializeComponent
1469
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1470
+ // Let the runtime know that the component has been initialized
1471
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1472
+ {
1473
+ // lazy loaded components
1474
+ // request the component's implementation to be
1475
+ // wired up with the host element
1476
+ Cstr = loadModule(cmpMeta);
1477
+ if (Cstr.then) {
1478
+ // Await creates a micro-task avoid if possible
1479
+ const endLoad = uniqueTime();
1480
+ Cstr = await Cstr;
1481
+ endLoad();
1482
+ }
1483
+ if (!Cstr.isProxied) {
1484
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1485
+ Cstr.isProxied = true;
1486
+ }
1487
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1488
+ // ok, time to construct the instance
1489
+ // but let's keep track of when we start and stop
1490
+ // so that the getters/setters don't incorrectly step on data
1491
+ {
1492
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1493
+ }
1494
+ // construct the lazy-loaded component implementation
1495
+ // passing the hostRef is very important during
1496
+ // construction in order to directly wire together the
1497
+ // host element and the lazy-loaded instance
1498
+ try {
1499
+ new Cstr(hostRef);
1500
+ }
1501
+ catch (e) {
1502
+ consoleError(e);
1503
+ }
1504
+ {
1505
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1506
+ }
1507
+ endNewInstance();
1508
+ fireConnectedCallback(hostRef.$lazyInstance$);
1509
+ }
1510
+ if (Cstr.style) {
1511
+ // this component has styles but we haven't registered them yet
1512
+ let style = Cstr.style;
1513
+ const scopeId = getScopeId(cmpMeta);
1514
+ if (!styles.has(scopeId)) {
1515
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1516
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1517
+ endRegisterStyles();
1518
+ }
1519
+ }
1520
+ }
1521
+ // we've successfully created a lazy instance
1522
+ const ancestorComponent = hostRef.$ancestorComponent$;
1523
+ const schedule = () => scheduleUpdate(hostRef, true);
1524
+ if (ancestorComponent && ancestorComponent['s-rc']) {
1525
+ // this is the initial load and this component it has an ancestor component
1526
+ // but the ancestor component has NOT fired its will update lifecycle yet
1527
+ // so let's just cool our jets and wait for the ancestor to continue first
1528
+ // this will get fired off when the ancestor component
1529
+ // finally gets around to rendering its lazy self
1530
+ // fire off the initial update
1531
+ ancestorComponent['s-rc'].push(schedule);
1532
+ }
1533
+ else {
1534
+ schedule();
1535
+ }
1536
+ };
1537
+ const fireConnectedCallback = (instance) => {
1538
+ {
1539
+ safeCall(instance, 'connectedCallback');
1540
+ }
1541
+ };
1542
+ const connectedCallback = (elm) => {
1543
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1544
+ const hostRef = getHostRef(elm);
1545
+ const cmpMeta = hostRef.$cmpMeta$;
1546
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1547
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1548
+ // first time this component has connected
1549
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1550
+ {
1551
+ // find the first ancestor component (if there is one) and register
1552
+ // this component as one of the actively loading child components for its ancestor
1553
+ let ancestorComponent = elm;
1554
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1555
+ // climb up the ancestors looking for the first
1556
+ // component that hasn't finished its lifecycle update yet
1557
+ if (ancestorComponent['s-p']) {
1558
+ // we found this components first ancestor component
1559
+ // keep a reference to this component's ancestor component
1560
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1561
+ break;
1562
+ }
1563
+ }
1564
+ }
1565
+ // Lazy properties
1566
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1567
+ if (cmpMeta.$members$) {
1568
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1569
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1570
+ const value = elm[memberName];
1571
+ delete elm[memberName];
1572
+ elm[memberName] = value;
1573
+ }
1574
+ });
1575
+ }
1576
+ {
1577
+ initializeComponent(elm, hostRef, cmpMeta);
1578
+ }
1579
+ }
1580
+ else {
1581
+ // not the first time this has connected
1582
+ // reattach any event listeners to the host
1583
+ // since they would have been removed when disconnected
1584
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
1585
+ // fire off connectedCallback() on component instance
1586
+ if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
1587
+ fireConnectedCallback(hostRef.$lazyInstance$);
1588
+ }
1589
+ else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1590
+ hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$));
1591
+ }
1592
+ }
1593
+ endConnected();
1594
+ }
1595
+ };
1596
+ const disconnectInstance = (instance) => {
1597
+ {
1598
+ safeCall(instance, 'disconnectedCallback');
1599
+ }
1600
+ };
1601
+ const disconnectedCallback = async (elm) => {
1602
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1603
+ const hostRef = getHostRef(elm);
1604
+ {
1605
+ if (hostRef.$rmListeners$) {
1606
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
1607
+ hostRef.$rmListeners$ = undefined;
1608
+ }
1609
+ }
1610
+ if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
1611
+ disconnectInstance(hostRef.$lazyInstance$);
1612
+ }
1613
+ else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1614
+ hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$));
1615
+ }
1616
+ }
1617
+ };
1618
+ const bootstrapLazy = (lazyBundles, options = {}) => {
1619
+ var _a;
1620
+ const endBootstrap = createTime();
1621
+ const cmpTags = [];
1622
+ const exclude = options.exclude || [];
1623
+ const customElements = win.customElements;
1624
+ const head = doc.head;
1625
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1626
+ const dataStyles = /*@__PURE__*/ doc.createElement('style');
1627
+ const deferredConnectedCallbacks = [];
1628
+ let appLoadFallback;
1629
+ let isBootstrapping = true;
1630
+ Object.assign(plt, options);
1631
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1632
+ let hasSlotRelocation = false;
1633
+ lazyBundles.map((lazyBundle) => {
1634
+ lazyBundle[1].map((compactMeta) => {
1635
+ const cmpMeta = {
1636
+ $flags$: compactMeta[0],
1637
+ $tagName$: compactMeta[1],
1638
+ $members$: compactMeta[2],
1639
+ $listeners$: compactMeta[3],
1640
+ };
1641
+ // Check if we are using slots outside the shadow DOM in this component.
1642
+ // We'll use this information later to add styles for `slot-fb` elements
1643
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
1644
+ hasSlotRelocation = true;
1645
+ }
1646
+ {
1647
+ cmpMeta.$members$ = compactMeta[2];
1648
+ }
1649
+ {
1650
+ cmpMeta.$listeners$ = compactMeta[3];
1651
+ }
1652
+ const tagName = cmpMeta.$tagName$;
1653
+ const HostElement = class extends HTMLElement {
1654
+ // StencilLazyHost
1655
+ constructor(self) {
1656
+ // @ts-ignore
1657
+ super(self);
1658
+ self = this;
1659
+ registerHost(self, cmpMeta);
1660
+ if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1661
+ // this component is using shadow dom
1662
+ // and this browser supports shadow dom
1663
+ // add the read-only property "shadowRoot" to the host element
1664
+ // adding the shadow root build conditionals to minimize runtime
1665
+ {
1666
+ {
1667
+ self.attachShadow({ mode: 'open' });
1668
+ }
1669
+ }
1670
+ }
1671
+ }
1672
+ connectedCallback() {
1673
+ if (appLoadFallback) {
1674
+ clearTimeout(appLoadFallback);
1675
+ appLoadFallback = null;
1676
+ }
1677
+ if (isBootstrapping) {
1678
+ // connectedCallback will be processed once all components have been registered
1679
+ deferredConnectedCallbacks.push(this);
1680
+ }
1681
+ else {
1682
+ plt.jmp(() => connectedCallback(this));
1683
+ }
1684
+ }
1685
+ disconnectedCallback() {
1686
+ plt.jmp(() => disconnectedCallback(this));
1687
+ }
1688
+ componentOnReady() {
1689
+ return getHostRef(this).$onReadyPromise$;
1690
+ }
1691
+ };
1692
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
1693
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1694
+ cmpTags.push(tagName);
1695
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1696
+ }
1697
+ });
1698
+ });
1699
+ // Only bother generating CSS if we have components
1700
+ // TODO(STENCIL-1118): Add test cases for CSS content based on conditionals
1701
+ if (cmpTags.length > 0) {
1702
+ // Add styles for `slot-fb` elements if any of our components are using slots outside the Shadow DOM
1703
+ if (hasSlotRelocation) {
1704
+ dataStyles.innerHTML += SLOT_FB_CSS;
1705
+ }
1706
+ // Add hydration styles
1707
+ {
1708
+ dataStyles.innerHTML += cmpTags + HYDRATED_CSS;
1709
+ }
1710
+ // If we have styles, add them to the DOM
1711
+ if (dataStyles.innerHTML.length) {
1712
+ dataStyles.setAttribute('data-styles', '');
1713
+ // Apply CSP nonce to the style tag if it exists
1714
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1715
+ if (nonce != null) {
1716
+ dataStyles.setAttribute('nonce', nonce);
1717
+ }
1718
+ // Insert the styles into the document head
1719
+ // NOTE: this _needs_ to happen last so we can ensure the nonce (and other attributes) are applied
1720
+ head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
1721
+ }
1722
+ }
1723
+ // Process deferred connectedCallbacks now all components have been registered
1724
+ isBootstrapping = false;
1725
+ if (deferredConnectedCallbacks.length) {
1726
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
1727
+ }
1728
+ else {
1729
+ {
1730
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1731
+ }
1732
+ }
1733
+ // Fallback appLoad event
1734
+ endBootstrap();
1735
+ };
1736
+ const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
1737
+ if (listeners) {
1738
+ listeners.map(([flags, name, method]) => {
1739
+ const target = getHostListenerTarget(elm, flags) ;
1740
+ const handler = hostListenerProxy(hostRef, method);
1741
+ const opts = hostListenerOpts(flags);
1742
+ plt.ael(target, name, handler, opts);
1743
+ (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
1744
+ });
1745
+ }
1746
+ };
1747
+ const hostListenerProxy = (hostRef, methodName) => (ev) => {
1748
+ try {
1749
+ {
1750
+ if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
1751
+ // instance is ready, let's call it's member method for this event
1752
+ hostRef.$lazyInstance$[methodName](ev);
1753
+ }
1754
+ else {
1755
+ (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
1756
+ }
1757
+ }
1758
+ }
1759
+ catch (e) {
1760
+ consoleError(e);
1761
+ }
1762
+ };
1763
+ const getHostListenerTarget = (elm, flags) => {
1764
+ if (flags & 4 /* LISTENER_FLAGS.TargetDocument */)
1765
+ return doc;
1766
+ return elm;
1767
+ };
1768
+ // prettier-ignore
1769
+ const hostListenerOpts = (flags) => supportsListenerOptions
1770
+ ? ({
1771
+ passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
1772
+ capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
1773
+ })
1774
+ : (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
1775
+ /**
1776
+ * Assigns the given value to the nonce property on the runtime platform object.
1777
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1778
+ * @param nonce The value to be assigned to the platform nonce property.
1779
+ * @returns void
1780
+ */
1781
+ const setNonce = (nonce) => (plt.$nonce$ = nonce);
1782
+ /**
1783
+ * A WeakMap mapping runtime component references to their corresponding host reference
1784
+ * instances.
1785
+ *
1786
+ * **Note**: If we're in an HMR context we need to store a reference to this
1787
+ * value on `window` in order to maintain the mapping of {@link d.RuntimeRef}
1788
+ * to {@link d.HostRef} across HMR updates.
1789
+ *
1790
+ * This is necessary because when HMR updates for a component are processed by
1791
+ * the browser-side dev server client the JS bundle for that component is
1792
+ * re-fetched. Since the module containing {@link hostRefs} is included in
1793
+ * that bundle, if we do not store a reference to it the new iteration of the
1794
+ * component will not have access to the previous hostRef map, leading to a
1795
+ * bug where the new version of the component cannot properly initialize.
1796
+ */
1797
+ const hostRefs = new WeakMap();
1798
+ /**
1799
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
1800
+ *
1801
+ * @param ref the runtime ref of interest
1802
+ * @returns the Host reference (if found) or undefined
1803
+ */
1804
+ const getHostRef = (ref) => hostRefs.get(ref);
1805
+ /**
1806
+ * Register a lazy instance with the {@link hostRefs} object so it's
1807
+ * corresponding {@link d.HostRef} can be retrieved later.
1808
+ *
1809
+ * @param lazyInstance the lazy instance of interest
1810
+ * @param hostRef that instances `HostRef` object
1811
+ * @returns a reference to the host ref WeakMap
1812
+ */
1813
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1814
+ /**
1815
+ * Register a host element for a Stencil component, setting up various metadata
1816
+ * and callbacks based on {@link BUILD} flags as well as the component's runtime
1817
+ * metadata.
1818
+ *
1819
+ * @param hostElement the host element to register
1820
+ * @param cmpMeta runtime metadata for that component
1821
+ * @returns a reference to the host ref WeakMap
1822
+ */
1823
+ const registerHost = (hostElement, cmpMeta) => {
1824
+ const hostRef = {
1825
+ $flags$: 0,
1826
+ $hostElement$: hostElement,
1827
+ $cmpMeta$: cmpMeta,
1828
+ $instanceValues$: new Map(),
1829
+ };
1830
+ {
1831
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1832
+ hostElement['s-p'] = [];
1833
+ hostElement['s-rc'] = [];
1834
+ }
1835
+ addHostEventListeners(hostElement, hostRef, cmpMeta.$listeners$);
1836
+ return hostRefs.set(hostElement, hostRef);
1837
+ };
1838
+ const isMemberInElement = (elm, memberName) => memberName in elm;
1839
+ const consoleError = (e, el) => (0, console.error)(e, el);
1840
+ const cmpModules = /*@__PURE__*/ new Map();
1841
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1842
+ // loadModuleImport
1843
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1844
+ const bundleId = cmpMeta.$lazyBundleId$;
1845
+ const module = cmpModules.get(bundleId) ;
1846
+ if (module) {
1847
+ return module[exportName];
1848
+ }
1849
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1850
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
1851
+ /* @vite-ignore */
1852
+ /* webpackInclude: /\.entry\.js$/ */
1853
+ /* webpackExclude: /\.system\.entry\.js$/ */
1854
+ /* webpackMode: "lazy" */
1855
+ `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
1856
+ {
1857
+ cmpModules.set(bundleId, importedModule);
1858
+ }
1859
+ return importedModule[exportName];
1860
+ }, consoleError);
1861
+ };
1862
+ const styles = /*@__PURE__*/ new Map();
1863
+ const win = typeof window !== 'undefined' ? window : {};
1864
+ const doc = win.document || { head: {} };
1865
+ const plt = {
1866
+ $flags$: 0,
1867
+ $resourcesUrl$: '',
1868
+ jmp: (h) => h(),
1869
+ raf: (h) => requestAnimationFrame(h),
1870
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1871
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1872
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
1873
+ };
1874
+ const supportsListenerOptions = /*@__PURE__*/ (() => {
1875
+ let supportsListenerOptions = false;
1876
+ try {
1877
+ doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
1878
+ get() {
1879
+ supportsListenerOptions = true;
1880
+ },
1881
+ }));
1882
+ }
1883
+ catch (e) { }
1884
+ return supportsListenerOptions;
1885
+ })();
1886
+ const promiseResolve = (v) => Promise.resolve(v);
1887
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1888
+ try {
1889
+ new CSSStyleSheet();
1890
+ return typeof new CSSStyleSheet().replaceSync === 'function';
1891
+ }
1892
+ catch (e) { }
1893
+ return false;
1894
+ })()
1895
+ ;
1896
+ const queueDomReads = [];
1897
+ const queueDomWrites = [];
1898
+ const queueTask = (queue, write) => (cb) => {
1899
+ queue.push(cb);
1900
+ if (!queuePending) {
1901
+ queuePending = true;
1902
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1903
+ nextTick(flush);
1904
+ }
1905
+ else {
1906
+ plt.raf(flush);
1907
+ }
1908
+ }
1909
+ };
1910
+ const consume = (queue) => {
1911
+ for (let i = 0; i < queue.length; i++) {
1912
+ try {
1913
+ queue[i](performance.now());
1914
+ }
1915
+ catch (e) {
1916
+ consoleError(e);
1917
+ }
1918
+ }
1919
+ queue.length = 0;
1920
+ };
1921
+ const flush = () => {
1922
+ // always force a bunch of medium callbacks to run, but still have
1923
+ // a throttle on how many can run in a certain time
1924
+ // DOM READS!!!
1925
+ consume(queueDomReads);
1926
+ // DOM WRITES!!!
1927
+ {
1928
+ consume(queueDomWrites);
1929
+ if ((queuePending = queueDomReads.length > 0)) {
1930
+ // still more to do yet, but we've run out of time
1931
+ // let's let this thing cool off and try again in the next tick
1932
+ plt.raf(flush);
1933
+ }
1934
+ }
1935
+ };
1936
+ const nextTick = (cb) => promiseResolve().then(cb);
1937
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1938
+
1939
+ exports.Build = Build;
1940
+ exports.Host = Host;
1941
+ exports.bootstrapLazy = bootstrapLazy;
1942
+ exports.getElement = getElement;
1943
+ exports.h = h;
1944
+ exports.promiseResolve = promiseResolve;
1945
+ exports.registerInstance = registerInstance;
1946
+ exports.setNonce = setNonce;
1947
+
1948
+ //# sourceMappingURL=index-ef57218a.js.map