ai12z 0.0.1-alpha.8

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