@usecapsule/core-components 3.1.0 → 3.1.1

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