@runopencode/rx-stencil 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +42 -0
  3. package/dist/cjs/index-825eaf13.js +1207 -0
  4. package/dist/cjs/index-825eaf13.js.map +1 -0
  5. package/dist/cjs/index.cjs.js +672 -0
  6. package/dist/cjs/index.cjs.js.map +1 -0
  7. package/dist/cjs/loader.cjs.js +24 -0
  8. package/dist/cjs/loader.cjs.js.map +1 -0
  9. package/dist/cjs/rx-async.cjs.entry.js +71 -0
  10. package/dist/cjs/rx-async.cjs.entry.js.map +1 -0
  11. package/dist/cjs/rx-stencil.cjs.js +28 -0
  12. package/dist/cjs/rx-stencil.cjs.js.map +1 -0
  13. package/dist/cjs/set-property-e9b49bec.js +1171 -0
  14. package/dist/cjs/set-property-e9b49bec.js.map +1 -0
  15. package/dist/collection/collection-manifest.json +12 -0
  16. package/dist/collection/components/async/async.js +66 -0
  17. package/dist/collection/components/async/async.js.map +1 -0
  18. package/dist/collection/components/async/async.scss +3 -0
  19. package/dist/collection/index.js +3 -0
  20. package/dist/collection/index.js.map +1 -0
  21. package/dist/collection/rx/decorator/index.js +3 -0
  22. package/dist/collection/rx/decorator/index.js.map +1 -0
  23. package/dist/collection/rx/decorator/query-selector-all.js +41 -0
  24. package/dist/collection/rx/decorator/query-selector-all.js.map +1 -0
  25. package/dist/collection/rx/decorator/query-selector.js +54 -0
  26. package/dist/collection/rx/decorator/query-selector.js.map +1 -0
  27. package/dist/collection/rx/index.js +5 -0
  28. package/dist/collection/rx/index.js.map +1 -0
  29. package/dist/collection/rx/observable/index.js +5 -0
  30. package/dist/collection/rx/observable/index.js.map +1 -0
  31. package/dist/collection/rx/observable/mutation-observable.js +13 -0
  32. package/dist/collection/rx/observable/mutation-observable.js.map +1 -0
  33. package/dist/collection/rx/observable/properties-observable.js +14 -0
  34. package/dist/collection/rx/observable/properties-observable.js.map +1 -0
  35. package/dist/collection/rx/observable/property-observable.js +28 -0
  36. package/dist/collection/rx/observable/property-observable.js.map +1 -0
  37. package/dist/collection/rx/observable/render-observable.js +24 -0
  38. package/dist/collection/rx/observable/render-observable.js.map +1 -0
  39. package/dist/collection/rx/operator/index.js +4 -0
  40. package/dist/collection/rx/operator/index.js.map +1 -0
  41. package/dist/collection/rx/operator/schedule-render.js +23 -0
  42. package/dist/collection/rx/operator/schedule-render.js.map +1 -0
  43. package/dist/collection/rx/operator/to-property.js +19 -0
  44. package/dist/collection/rx/operator/to-property.js.map +1 -0
  45. package/dist/collection/rx/operator/until-disconnected.js +105 -0
  46. package/dist/collection/rx/operator/until-disconnected.js.map +1 -0
  47. package/dist/collection/rx/subscriber/index.js +2 -0
  48. package/dist/collection/rx/subscriber/index.js.map +1 -0
  49. package/dist/collection/rx/subscriber/set-property.js +16 -0
  50. package/dist/collection/rx/subscriber/set-property.js.map +1 -0
  51. package/dist/collection/utils/get-property-descriptor.js +18 -0
  52. package/dist/collection/utils/get-property-descriptor.js.map +1 -0
  53. package/dist/collection/utils/index.js +2 -0
  54. package/dist/collection/utils/index.js.map +1 -0
  55. package/dist/components/index.d.ts +27 -0
  56. package/dist/components/index.js +661 -0
  57. package/dist/components/index.js.map +1 -0
  58. package/dist/components/rx-async.d.ts +11 -0
  59. package/dist/components/rx-async.js +86 -0
  60. package/dist/components/rx-async.js.map +1 -0
  61. package/dist/components/set-property.js +1153 -0
  62. package/dist/components/set-property.js.map +1 -0
  63. package/dist/esm/index-9f5c1c1c.js +1178 -0
  64. package/dist/esm/index-9f5c1c1c.js.map +1 -0
  65. package/dist/esm/index.js +660 -0
  66. package/dist/esm/index.js.map +1 -0
  67. package/dist/esm/loader.js +20 -0
  68. package/dist/esm/loader.js.map +1 -0
  69. package/dist/esm/polyfills/core-js.js +11 -0
  70. package/dist/esm/polyfills/css-shim.js +1 -0
  71. package/dist/esm/polyfills/dom.js +79 -0
  72. package/dist/esm/polyfills/es5-html-element.js +1 -0
  73. package/dist/esm/polyfills/index.js +34 -0
  74. package/dist/esm/polyfills/system.js +6 -0
  75. package/dist/esm/rx-async.entry.js +67 -0
  76. package/dist/esm/rx-async.entry.js.map +1 -0
  77. package/dist/esm/rx-stencil.js +23 -0
  78. package/dist/esm/rx-stencil.js.map +1 -0
  79. package/dist/esm/set-property-adc341f7.js +1153 -0
  80. package/dist/esm/set-property-adc341f7.js.map +1 -0
  81. package/dist/index.cjs.js +1 -0
  82. package/dist/index.js +1 -0
  83. package/dist/rx-stencil/index.esm.js +2 -0
  84. package/dist/rx-stencil/index.esm.js.map +1 -0
  85. package/dist/rx-stencil/p-3ccfcb54.js +3 -0
  86. package/dist/rx-stencil/p-3ccfcb54.js.map +1 -0
  87. package/dist/rx-stencil/p-55056215.js +2 -0
  88. package/dist/rx-stencil/p-55056215.js.map +1 -0
  89. package/dist/rx-stencil/p-b1ed83f6.entry.js +2 -0
  90. package/dist/rx-stencil/p-b1ed83f6.entry.js.map +1 -0
  91. package/dist/rx-stencil/rx-stencil.esm.js +2 -0
  92. package/dist/rx-stencil/rx-stencil.esm.js.map +1 -0
  93. package/dist/types/components/async/async.d.ts +10 -0
  94. package/dist/types/components.d.ts +41 -0
  95. package/dist/types/index.d.ts +2 -0
  96. package/dist/types/rx/decorator/index.d.ts +2 -0
  97. package/dist/types/rx/decorator/query-selector-all.d.ts +22 -0
  98. package/dist/types/rx/decorator/query-selector.d.ts +30 -0
  99. package/dist/types/rx/index.d.ts +4 -0
  100. package/dist/types/rx/observable/index.d.ts +4 -0
  101. package/dist/types/rx/observable/mutation-observable.d.ts +2 -0
  102. package/dist/types/rx/observable/properties-observable.d.ts +6 -0
  103. package/dist/types/rx/observable/property-observable.d.ts +6 -0
  104. package/dist/types/rx/observable/render-observable.d.ts +8 -0
  105. package/dist/types/rx/operator/index.d.ts +3 -0
  106. package/dist/types/rx/operator/schedule-render.d.ts +12 -0
  107. package/dist/types/rx/operator/to-property.d.ts +9 -0
  108. package/dist/types/rx/operator/until-disconnected.d.ts +7 -0
  109. package/dist/types/rx/subscriber/index.d.ts +1 -0
  110. package/dist/types/rx/subscriber/set-property.d.ts +16 -0
  111. package/dist/types/stencil-public-runtime.d.ts +1640 -0
  112. package/dist/types/utils/get-property-descriptor.d.ts +7 -0
  113. package/dist/types/utils/index.d.ts +1 -0
  114. package/docs/components.md +69 -0
  115. package/docs/creation-operators.md +138 -0
  116. package/docs/pipeable-operators.md +36 -0
  117. package/docs/query-selector-all-decorator.md +154 -0
  118. package/docs/query-selector-decorator.md +116 -0
  119. package/docs/subscribers.md +49 -0
  120. package/loader/cdn.js +3 -0
  121. package/loader/index.cjs.js +3 -0
  122. package/loader/index.d.ts +21 -0
  123. package/loader/index.es2017.js +3 -0
  124. package/loader/index.js +4 -0
  125. package/loader/package.json +11 -0
  126. package/package.json +48 -0
@@ -0,0 +1,1178 @@
1
+ const NAMESPACE = 'rx-stencil';
2
+
3
+ /**
4
+ * Virtual DOM patching algorithm based on Snabbdom by
5
+ * Simon Friis Vindum (@paldepind)
6
+ * Licensed under the MIT License
7
+ * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
8
+ *
9
+ * Modified for Stencil's renderer and slot projection
10
+ */
11
+ let queuePending = false;
12
+ const createTime = (fnName, tagName = '') => {
13
+ {
14
+ return () => {
15
+ return;
16
+ };
17
+ }
18
+ };
19
+ const uniqueTime = (key, measureText) => {
20
+ {
21
+ return () => {
22
+ return;
23
+ };
24
+ }
25
+ };
26
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
27
+ /**
28
+ * Check whether a value is a 'complex type', defined here as an object or a
29
+ * function.
30
+ *
31
+ * @param o the value to check
32
+ * @returns whether it's a complex type or not
33
+ */
34
+ const isComplexType = (o) => {
35
+ // https://jsperf.com/typeof-fn-object/5
36
+ o = typeof o;
37
+ return o === 'object' || o === 'function';
38
+ };
39
+ /**
40
+ * Helper method for querying a `meta` tag that contains a nonce value
41
+ * out of a DOM's head.
42
+ *
43
+ * @param doc The DOM containing the `head` to query against
44
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
45
+ * exists or the tag has no content.
46
+ */
47
+ function queryNonceMetaTagContent(doc) {
48
+ var _a, _b, _c;
49
+ 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;
50
+ }
51
+ /**
52
+ * Production h() function based on Preact by
53
+ * Jason Miller (@developit)
54
+ * Licensed under the MIT License
55
+ * https://github.com/developit/preact/blob/master/LICENSE
56
+ *
57
+ * Modified for Stencil's compiler and vdom
58
+ */
59
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
60
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
61
+ const h = (nodeName, vnodeData, ...children) => {
62
+ let child = null;
63
+ let simple = false;
64
+ let lastSimple = false;
65
+ const vNodeChildren = [];
66
+ const walk = (c) => {
67
+ for (let i = 0; i < c.length; i++) {
68
+ child = c[i];
69
+ if (Array.isArray(child)) {
70
+ walk(child);
71
+ }
72
+ else if (child != null && typeof child !== 'boolean') {
73
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
74
+ child = String(child);
75
+ }
76
+ if (simple && lastSimple) {
77
+ // If the previous child was simple (string), we merge both
78
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
79
+ }
80
+ else {
81
+ // Append a new vNode, if it's text, we create a text vNode
82
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
83
+ }
84
+ lastSimple = simple;
85
+ }
86
+ }
87
+ };
88
+ walk(children);
89
+ const vnode = newVNode(nodeName, null);
90
+ vnode.$attrs$ = vnodeData;
91
+ if (vNodeChildren.length > 0) {
92
+ vnode.$children$ = vNodeChildren;
93
+ }
94
+ return vnode;
95
+ };
96
+ /**
97
+ * A utility function for creating a virtual DOM node from a tag and some
98
+ * possible text content.
99
+ *
100
+ * @param tag the tag for this element
101
+ * @param text possible text content for the node
102
+ * @returns a newly-minted virtual DOM node
103
+ */
104
+ const newVNode = (tag, text) => {
105
+ const vnode = {
106
+ $flags$: 0,
107
+ $tag$: tag,
108
+ $text$: text,
109
+ $elm$: null,
110
+ $children$: null,
111
+ };
112
+ return vnode;
113
+ };
114
+ const Host = {};
115
+ /**
116
+ * Check whether a given node is a Host node or not
117
+ *
118
+ * @param node the virtual DOM node to check
119
+ * @returns whether it's a Host node or not
120
+ */
121
+ const isHost = (node) => node && node.$tag$ === Host;
122
+ /**
123
+ * Parse a new property value for a given property type.
124
+ *
125
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
126
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
127
+ * 1. `any`, the type given to `propValue` in the function signature
128
+ * 2. the type stored from `propType`.
129
+ *
130
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
131
+ *
132
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
133
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
134
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
135
+ * ```tsx
136
+ * <my-cmp prop-val={0}></my-cmp>
137
+ * ```
138
+ *
139
+ * HTML prop values on the other hand, will always a string
140
+ *
141
+ * @param propValue the new value to coerce to some type
142
+ * @param propType the type of the prop, expressed as a binary number
143
+ * @returns the parsed/coerced value
144
+ */
145
+ const parsePropertyValue = (propValue, propType) => {
146
+ // ensure this value is of the correct prop type
147
+ if (propValue != null && !isComplexType(propValue)) {
148
+ // redundant return here for better minification
149
+ return propValue;
150
+ }
151
+ // not sure exactly what type we want
152
+ // so no need to change to a different type
153
+ return propValue;
154
+ };
155
+ const getElement = (ref) => (getHostRef(ref).$hostElement$ );
156
+ /**
157
+ * Helper function to create & dispatch a custom Event on a provided target
158
+ * @param elm the target of the Event
159
+ * @param name the name to give the custom Event
160
+ * @param opts options for configuring a custom Event
161
+ * @returns the custom Event
162
+ */
163
+ const emitEvent = (elm, name, opts) => {
164
+ const ev = plt.ce(name, opts);
165
+ elm.dispatchEvent(ev);
166
+ return ev;
167
+ };
168
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
169
+ const registerStyle = (scopeId, cssText, allowCS) => {
170
+ let style = styles.get(scopeId);
171
+ if (supportsConstructableStylesheets && allowCS) {
172
+ style = (style || new CSSStyleSheet());
173
+ if (typeof style === 'string') {
174
+ style = cssText;
175
+ }
176
+ else {
177
+ style.replaceSync(cssText);
178
+ }
179
+ }
180
+ else {
181
+ style = cssText;
182
+ }
183
+ styles.set(scopeId, style);
184
+ };
185
+ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
186
+ var _a;
187
+ let scopeId = getScopeId(cmpMeta);
188
+ const style = styles.get(scopeId);
189
+ // if an element is NOT connected then getRootNode() will return the wrong root node
190
+ // so the fallback is to always use the document for the root node in those cases
191
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
192
+ if (style) {
193
+ if (typeof style === 'string') {
194
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
195
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
196
+ let styleElm;
197
+ if (!appliedStyles) {
198
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
199
+ }
200
+ if (!appliedStyles.has(scopeId)) {
201
+ {
202
+ // TODO(STENCIL-659): Remove code implementing the CSS variable shim
203
+ {
204
+ styleElm = doc.createElement('style');
205
+ styleElm.innerHTML = style;
206
+ }
207
+ // Apply CSP nonce to the style tag if it exists
208
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
209
+ if (nonce != null) {
210
+ styleElm.setAttribute('nonce', nonce);
211
+ }
212
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
213
+ }
214
+ if (appliedStyles) {
215
+ appliedStyles.add(scopeId);
216
+ }
217
+ }
218
+ }
219
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
220
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
221
+ }
222
+ }
223
+ return scopeId;
224
+ };
225
+ const attachStyles = (hostRef) => {
226
+ const cmpMeta = hostRef.$cmpMeta$;
227
+ const elm = hostRef.$hostElement$;
228
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
229
+ addStyle(elm.getRootNode(), cmpMeta);
230
+ endAttachStyles();
231
+ };
232
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
233
+ /**
234
+ * Create a DOM Node corresponding to one of the children of a given VNode.
235
+ *
236
+ * @param oldParentVNode the parent VNode from the previous render
237
+ * @param newParentVNode the parent VNode from the current render
238
+ * @param childIndex the index of the VNode, in the _new_ parent node's
239
+ * children, for which we will create a new DOM node
240
+ * @param parentElm the parent DOM node which our new node will be a child of
241
+ * @returns the newly created node
242
+ */
243
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
244
+ // tslint:disable-next-line: prefer-const
245
+ const newVNode = newParentVNode.$children$[childIndex];
246
+ let i = 0;
247
+ let elm;
248
+ let childNode;
249
+ if (newVNode.$text$ !== null) {
250
+ // create text node
251
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
252
+ }
253
+ else {
254
+ // create element
255
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
256
+ if (newVNode.$children$) {
257
+ for (i = 0; i < newVNode.$children$.length; ++i) {
258
+ // create the node
259
+ childNode = createElm(oldParentVNode, newVNode, i);
260
+ // return node could have been null
261
+ if (childNode) {
262
+ // append our new node
263
+ elm.appendChild(childNode);
264
+ }
265
+ }
266
+ }
267
+ }
268
+ return elm;
269
+ };
270
+ /**
271
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
272
+ * add them to the DOM in the appropriate place.
273
+ *
274
+ * @param parentElm the DOM node which should be used as a parent for the new
275
+ * DOM nodes
276
+ * @param before a child of the `parentElm` which the new children should be
277
+ * inserted before (optional)
278
+ * @param parentVNode the parent virtual DOM node
279
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
280
+ * @param startIdx the index in the child virtual DOM nodes at which to start
281
+ * creating DOM nodes (inclusive)
282
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
283
+ * creating DOM nodes (inclusive)
284
+ */
285
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
286
+ let containerElm = (parentElm);
287
+ let childNode;
288
+ for (; startIdx <= endIdx; ++startIdx) {
289
+ if (vnodes[startIdx]) {
290
+ childNode = createElm(null, parentVNode, startIdx);
291
+ if (childNode) {
292
+ vnodes[startIdx].$elm$ = childNode;
293
+ containerElm.insertBefore(childNode, before);
294
+ }
295
+ }
296
+ }
297
+ };
298
+ /**
299
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
300
+ * This can be used to, for instance, clean up after a list of children which
301
+ * should no longer be shown.
302
+ *
303
+ * This function also handles some of Stencil's slot relocation logic.
304
+ *
305
+ * @param vnodes a list of virtual DOM nodes to remove
306
+ * @param startIdx the index at which to start removing nodes (inclusive)
307
+ * @param endIdx the index at which to stop removing nodes (inclusive)
308
+ */
309
+ const removeVnodes = (vnodes, startIdx, endIdx) => {
310
+ for (let index = startIdx; index <= endIdx; ++index) {
311
+ const vnode = vnodes[index];
312
+ if (vnode) {
313
+ const elm = vnode.$elm$;
314
+ if (elm) {
315
+ // remove the vnode's element from the dom
316
+ elm.remove();
317
+ }
318
+ }
319
+ }
320
+ };
321
+ /**
322
+ * Reconcile the children of a new VNode with the children of an old VNode by
323
+ * traversing the two collections of children, identifying nodes that are
324
+ * conserved or changed, calling out to `patch` to make any necessary
325
+ * updates to the DOM, and rearranging DOM nodes as needed.
326
+ *
327
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
328
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
329
+ * 'windows' by storing start and end indices and references to the
330
+ * corresponding array entries. Initially the two 'windows' are basically equal
331
+ * to the entire array, but we progressively narrow the windows until there are
332
+ * no children left to update by doing the following:
333
+ *
334
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
335
+ * that if we have an initial array like the following we'll end up dealing
336
+ * only with a window bounded by the highlighted elements:
337
+ *
338
+ * [null, null, VNode1 , ... , VNode2, null, null]
339
+ * ^^^^^^ ^^^^^^
340
+ *
341
+ * 2. Check to see if the elements at the head and tail positions are equal
342
+ * across the windows. This will basically detect elements which haven't
343
+ * been added, removed, or changed position, i.e. if you had the following
344
+ * VNode elements (represented as HTML):
345
+ *
346
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
347
+ * newVNode: `<div><p><span>THERE</span></p></div>`
348
+ *
349
+ * Then when comparing the children of the `<div>` tag we check the equality
350
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
351
+ * same tag in the same position, we'd be able to avoid completely
352
+ * re-rendering the subtree under them with a new DOM element and would just
353
+ * call out to `patch` to handle reconciling their children and so on.
354
+ *
355
+ * 3. Check, for both windows, to see if the element at the beginning of the
356
+ * window corresponds to the element at the end of the other window. This is
357
+ * a heuristic which will let us identify _some_ situations in which
358
+ * elements have changed position, for instance it _should_ detect that the
359
+ * children nodes themselves have not changed but merely moved in the
360
+ * following example:
361
+ *
362
+ * oldVNode: `<div><element-one /><element-two /></div>`
363
+ * newVNode: `<div><element-two /><element-one /></div>`
364
+ *
365
+ * If we find cases like this then we also need to move the concrete DOM
366
+ * elements corresponding to the moved children to write the re-order to the
367
+ * DOM.
368
+ *
369
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
370
+ * nodes in the old children which have the same key as the first element in
371
+ * our window on the new children. If we find such a node we handle calling
372
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
373
+ * what we find.
374
+ *
375
+ * Finally, once we've narrowed our 'windows' to the point that either of them
376
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
377
+ * insertion or deletion that needs to happen to get a DOM state that correctly
378
+ * reflects the new child VNodes. If, for instance, after our window on the old
379
+ * children has collapsed we still have more nodes on the new children that
380
+ * we haven't dealt with yet then we need to add them, or if the new children
381
+ * collapse but we still have unhandled _old_ children then we need to make
382
+ * sure the corresponding DOM nodes are removed.
383
+ *
384
+ * @param parentElm the node into which the parent VNode is rendered
385
+ * @param oldCh the old children of the parent node
386
+ * @param newVNode the new VNode which will replace the parent
387
+ * @param newCh the new children of the parent node
388
+ */
389
+ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
390
+ let oldStartIdx = 0;
391
+ let newStartIdx = 0;
392
+ let oldEndIdx = oldCh.length - 1;
393
+ let oldStartVnode = oldCh[0];
394
+ let oldEndVnode = oldCh[oldEndIdx];
395
+ let newEndIdx = newCh.length - 1;
396
+ let newStartVnode = newCh[0];
397
+ let newEndVnode = newCh[newEndIdx];
398
+ let node;
399
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
400
+ if (oldStartVnode == null) {
401
+ // VNode might have been moved left
402
+ oldStartVnode = oldCh[++oldStartIdx];
403
+ }
404
+ else if (oldEndVnode == null) {
405
+ oldEndVnode = oldCh[--oldEndIdx];
406
+ }
407
+ else if (newStartVnode == null) {
408
+ newStartVnode = newCh[++newStartIdx];
409
+ }
410
+ else if (newEndVnode == null) {
411
+ newEndVnode = newCh[--newEndIdx];
412
+ }
413
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
414
+ // if the start nodes are the same then we should patch the new VNode
415
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
416
+ // indices to reflect that. We don't need to move any DOM Nodes around
417
+ // since things are matched up in order.
418
+ patch(oldStartVnode, newStartVnode);
419
+ oldStartVnode = oldCh[++oldStartIdx];
420
+ newStartVnode = newCh[++newStartIdx];
421
+ }
422
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
423
+ // likewise, if the end nodes are the same we patch new onto old and
424
+ // decrement our end indices, and also likewise in this case we don't
425
+ // need to move any DOM Nodes.
426
+ patch(oldEndVnode, newEndVnode);
427
+ oldEndVnode = oldCh[--oldEndIdx];
428
+ newEndVnode = newCh[--newEndIdx];
429
+ }
430
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
431
+ patch(oldStartVnode, newEndVnode);
432
+ // We need to move the element for `oldStartVnode` into a position which
433
+ // will be appropriate for `newEndVnode`. For this we can use
434
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
435
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
436
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
437
+ //
438
+ // <old-start-node />
439
+ // <some-intervening-node />
440
+ // <old-end-node />
441
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
442
+ // <next-sibling />
443
+ //
444
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
445
+ // the node for `oldStartVnode` at the end of the children of
446
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
447
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
448
+ // append it to the children of the parent element.
449
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
450
+ oldStartVnode = oldCh[++oldStartIdx];
451
+ newEndVnode = newCh[--newEndIdx];
452
+ }
453
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
454
+ patch(oldEndVnode, newStartVnode);
455
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
456
+ // the same node, so since we're here we know that they are not. Thus we
457
+ // can move the element for `oldEndVnode` _before_ the element for
458
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
459
+ // future.
460
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
461
+ oldEndVnode = oldCh[--oldEndIdx];
462
+ newStartVnode = newCh[++newStartIdx];
463
+ }
464
+ else {
465
+ {
466
+ // We either didn't find an element in the old children that matches
467
+ // the key of the first new child OR the build is not using `key`
468
+ // attributes at all. In either case we need to create a new element
469
+ // for the new node.
470
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
471
+ newStartVnode = newCh[++newStartIdx];
472
+ }
473
+ if (node) {
474
+ // if we created a new node then handle inserting it to the DOM
475
+ {
476
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
477
+ }
478
+ }
479
+ }
480
+ }
481
+ if (oldStartIdx > oldEndIdx) {
482
+ // we have some more new nodes to add which don't match up with old nodes
483
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
484
+ }
485
+ else if (newStartIdx > newEndIdx) {
486
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
487
+ // in the new array, so lets remove them (which entails cleaning up the
488
+ // relevant DOM nodes)
489
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
490
+ }
491
+ };
492
+ /**
493
+ * Compare two VNodes to determine if they are the same
494
+ *
495
+ * **NB**: This function is an equality _heuristic_ based on the available
496
+ * information set on the two VNodes and can be misleading under certain
497
+ * circumstances. In particular, if the two nodes do not have `key` attrs
498
+ * (available under `$key$` on VNodes) then the function falls back on merely
499
+ * checking that they have the same tag.
500
+ *
501
+ * So, in other words, if `key` attrs are not set on VNodes which may be
502
+ * changing order within a `children` array or something along those lines then
503
+ * we could obtain a false negative and then have to do needless re-rendering
504
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
505
+ *
506
+ * @param leftVNode the first VNode to check
507
+ * @param rightVNode the second VNode to check
508
+ * @returns whether they're equal or not
509
+ */
510
+ const isSameVnode = (leftVNode, rightVNode) => {
511
+ // compare if two vnode to see if they're "technically" the same
512
+ // need to have the same element tag, and same key to be the same
513
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
514
+ return true;
515
+ }
516
+ return false;
517
+ };
518
+ /**
519
+ * Handle reconciling an outdated VNode with a new one which corresponds to
520
+ * it. This function handles flushing updates to the DOM and reconciling the
521
+ * children of the two nodes (if any).
522
+ *
523
+ * @param oldVNode an old VNode whose DOM element and children we want to update
524
+ * @param newVNode a new VNode representing an updated version of the old one
525
+ */
526
+ const patch = (oldVNode, newVNode) => {
527
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
528
+ const oldChildren = oldVNode.$children$;
529
+ const newChildren = newVNode.$children$;
530
+ const text = newVNode.$text$;
531
+ if (text === null) {
532
+ if (oldChildren !== null && newChildren !== null) {
533
+ // looks like there's child vnodes for both the old and new vnodes
534
+ // so we need to call `updateChildren` to reconcile them
535
+ updateChildren(elm, oldChildren, newVNode, newChildren);
536
+ }
537
+ else if (newChildren !== null) {
538
+ // no old child vnodes, but there are new child vnodes to add
539
+ if (oldVNode.$text$ !== null) {
540
+ // the old vnode was text, so be sure to clear it out
541
+ elm.textContent = '';
542
+ }
543
+ // add the new vnode children
544
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
545
+ }
546
+ else if (oldChildren !== null) {
547
+ // no new child vnodes, but there are old child vnodes to remove
548
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
549
+ }
550
+ }
551
+ else if (oldVNode.$text$ !== text) {
552
+ // update the text content for the text only vnode
553
+ // and also only if the text is different than before
554
+ elm.data = text;
555
+ }
556
+ };
557
+ /**
558
+ * The main entry point for Stencil's virtual DOM-based rendering engine
559
+ *
560
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
561
+ * function will handle creating a virtual DOM tree with a single root, patching
562
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
563
+ * relocation, and reflecting attributes.
564
+ *
565
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
566
+ * the DOM node into which it should be rendered.
567
+ * @param renderFnResults the virtual DOM nodes to be rendered
568
+ */
569
+ const renderVdom = (hostRef, renderFnResults) => {
570
+ const hostElm = hostRef.$hostElement$;
571
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
572
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
573
+ rootVnode.$tag$ = null;
574
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
575
+ hostRef.$vnode$ = rootVnode;
576
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
577
+ // synchronous patch
578
+ patch(oldVNode, rootVnode);
579
+ };
580
+ const attachToAncestor = (hostRef, ancestorComponent) => {
581
+ if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
582
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
583
+ }
584
+ };
585
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
586
+ {
587
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
588
+ }
589
+ if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
590
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
591
+ return;
592
+ }
593
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
594
+ // there is no ancestor component or the ancestor component
595
+ // has already fired off its lifecycle update then
596
+ // fire off the initial update
597
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
598
+ return writeTask(dispatch) ;
599
+ };
600
+ /**
601
+ * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
602
+ * component lifecycle methods like `componentWillLoad` as well as
603
+ * {@link updateComponent}, which will kick off the virtual DOM re-render.
604
+ *
605
+ * @param hostRef a reference to a host DOM node
606
+ * @param isInitialLoad whether we're on the initial load or not
607
+ * @returns an empty Promise which is used to enqueue a series of operations for
608
+ * the component
609
+ */
610
+ const dispatchHooks = (hostRef, isInitialLoad) => {
611
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
612
+ const instance = hostRef.$lazyInstance$ ;
613
+ // We're going to use this variable together with `enqueue` to implement a
614
+ // little promise-based queue. We start out with it `undefined`. When we add
615
+ // the first function to the queue we'll set this variable to be that
616
+ // function's return value. When we attempt to add subsequent values to the
617
+ // queue we'll check that value and, if it was a `Promise`, we'll then chain
618
+ // the new function off of that `Promise` using `.then()`. This will give our
619
+ // queue two nice properties:
620
+ //
621
+ // 1. If all functions added to the queue are synchronous they'll be called
622
+ // synchronously right away.
623
+ // 2. If all functions added to the queue are asynchronous they'll all be
624
+ // called in order after `dispatchHooks` exits.
625
+ let maybePromise;
626
+ endSchedule();
627
+ return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
628
+ };
629
+ /**
630
+ * This function uses a Promise to implement a simple first-in, first-out queue
631
+ * of functions to be called.
632
+ *
633
+ * The queue is ordered on the basis of the first argument. If it's
634
+ * `undefined`, then nothing is on the queue yet, so the provided function can
635
+ * be called synchronously (although note that this function may return a
636
+ * `Promise`). The idea is that then the return value of that enqueueing
637
+ * operation is kept around, so that if it was a `Promise` then subsequent
638
+ * functions can be enqueued by calling this function again with that `Promise`
639
+ * as the first argument.
640
+ *
641
+ * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
642
+ * @param fn a function to enqueue
643
+ * @returns either a `Promise` or the return value of the provided function
644
+ */
645
+ const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
646
+ /**
647
+ * Check that a value is a `Promise`. To check, we first see if the value is an
648
+ * instance of the `Promise` global. In a few circumstances, in particular if
649
+ * the global has been overwritten, this is could be misleading, so we also do
650
+ * a little 'duck typing' check to see if the `.then` property of the value is
651
+ * defined and a function.
652
+ *
653
+ * @param maybePromise it might be a promise!
654
+ * @returns whether it is or not
655
+ */
656
+ const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
657
+ (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
658
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
659
+ var _a;
660
+ const elm = hostRef.$hostElement$;
661
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
662
+ const rc = elm['s-rc'];
663
+ if (isInitialLoad) {
664
+ // DOM WRITE!
665
+ attachStyles(hostRef);
666
+ }
667
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
668
+ {
669
+ callRender(hostRef, instance);
670
+ }
671
+ if (rc) {
672
+ // ok, so turns out there are some child host elements
673
+ // waiting on this parent element to load
674
+ // let's fire off all update callbacks waiting
675
+ rc.map((cb) => cb());
676
+ elm['s-rc'] = undefined;
677
+ }
678
+ endRender();
679
+ endUpdate();
680
+ {
681
+ const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
682
+ const postUpdate = () => postUpdateComponent(hostRef);
683
+ if (childrenPromises.length === 0) {
684
+ postUpdate();
685
+ }
686
+ else {
687
+ Promise.all(childrenPromises).then(postUpdate);
688
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
689
+ childrenPromises.length = 0;
690
+ }
691
+ }
692
+ };
693
+ const callRender = (hostRef, instance, elm) => {
694
+ try {
695
+ instance = instance.render() ;
696
+ {
697
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
698
+ }
699
+ {
700
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
701
+ }
702
+ {
703
+ {
704
+ // looks like we've got child nodes to render into this host element
705
+ // or we need to update the css class/attrs on the host element
706
+ // DOM WRITE!
707
+ {
708
+ renderVdom(hostRef, instance);
709
+ }
710
+ }
711
+ }
712
+ }
713
+ catch (e) {
714
+ consoleError(e, hostRef.$hostElement$);
715
+ }
716
+ return null;
717
+ };
718
+ const postUpdateComponent = (hostRef) => {
719
+ const tagName = hostRef.$cmpMeta$.$tagName$;
720
+ const elm = hostRef.$hostElement$;
721
+ const endPostUpdate = createTime('postUpdate', tagName);
722
+ const ancestorComponent = hostRef.$ancestorComponent$;
723
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
724
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
725
+ {
726
+ // DOM WRITE!
727
+ addHydratedFlag(elm);
728
+ }
729
+ endPostUpdate();
730
+ {
731
+ hostRef.$onReadyResolve$(elm);
732
+ if (!ancestorComponent) {
733
+ appDidLoad();
734
+ }
735
+ }
736
+ }
737
+ else {
738
+ endPostUpdate();
739
+ }
740
+ // load events fire from bottom to top
741
+ // the deepest elements load first then bubbles up
742
+ {
743
+ if (hostRef.$onRenderResolve$) {
744
+ hostRef.$onRenderResolve$();
745
+ hostRef.$onRenderResolve$ = undefined;
746
+ }
747
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
748
+ nextTick(() => scheduleUpdate(hostRef, false));
749
+ }
750
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
751
+ }
752
+ // ( •_•)
753
+ // ( •_•)>⌐■-■
754
+ // (⌐■_■)
755
+ };
756
+ const forceUpdate = (ref) => {
757
+ {
758
+ const hostRef = getHostRef(ref);
759
+ const isConnected = hostRef.$hostElement$.isConnected;
760
+ if (isConnected &&
761
+ (hostRef.$flags$ & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
762
+ scheduleUpdate(hostRef, false);
763
+ }
764
+ // Returns "true" when the forced update was successfully scheduled
765
+ return isConnected;
766
+ }
767
+ };
768
+ const appDidLoad = (who) => {
769
+ // on appload
770
+ // we have finish the first big initial render
771
+ {
772
+ addHydratedFlag(doc.documentElement);
773
+ }
774
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
775
+ };
776
+ const safeCall = (instance, method, arg) => {
777
+ if (instance && instance[method]) {
778
+ try {
779
+ return instance[method](arg);
780
+ }
781
+ catch (e) {
782
+ consoleError(e);
783
+ }
784
+ }
785
+ return undefined;
786
+ };
787
+ const addHydratedFlag = (elm) => elm.classList.add('hydrated')
788
+ ;
789
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
790
+ const setValue = (ref, propName, newVal, cmpMeta) => {
791
+ // check our new property value against our internal value
792
+ const hostRef = getHostRef(ref);
793
+ const oldVal = hostRef.$instanceValues$.get(propName);
794
+ const flags = hostRef.$flags$;
795
+ const instance = hostRef.$lazyInstance$ ;
796
+ newVal = parsePropertyValue(newVal);
797
+ // explicitly check for NaN on both sides, as `NaN === NaN` is always false
798
+ const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
799
+ const didValueChange = newVal !== oldVal && !areBothNaN;
800
+ if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
801
+ // gadzooks! the property's value has changed!!
802
+ // set our new value!
803
+ hostRef.$instanceValues$.set(propName, newVal);
804
+ if (instance) {
805
+ if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
806
+ // looks like this value actually changed, so we've got work to do!
807
+ // but only if we've already rendered, otherwise just chill out
808
+ // queue that we need to do an update, but don't worry about queuing
809
+ // up millions cuz this function ensures it only runs once
810
+ scheduleUpdate(hostRef, false);
811
+ }
812
+ }
813
+ }
814
+ };
815
+ /**
816
+ * Attach a series of runtime constructs to a compiled Stencil component
817
+ * constructor, including getters and setters for the `@Prop` and `@State`
818
+ * decorators, callbacks for when attributes change, and so on.
819
+ *
820
+ * @param Cstr the constructor for a component that we need to process
821
+ * @param cmpMeta metadata collected previously about the component
822
+ * @param flags a number used to store a series of bit flags
823
+ * @returns a reference to the same constructor passed in (but now mutated)
824
+ */
825
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
826
+ if (cmpMeta.$members$) {
827
+ // It's better to have a const than two Object.entries()
828
+ const members = Object.entries(cmpMeta.$members$);
829
+ const prototype = Cstr.prototype;
830
+ members.map(([memberName, [memberFlags]]) => {
831
+ if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
832
+ ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
833
+ // proxyComponent - prop
834
+ Object.defineProperty(prototype, memberName, {
835
+ get() {
836
+ // proxyComponent, get value
837
+ return getValue(this, memberName);
838
+ },
839
+ set(newValue) {
840
+ // proxyComponent, set value
841
+ setValue(this, memberName, newValue);
842
+ },
843
+ configurable: true,
844
+ enumerable: true,
845
+ });
846
+ }
847
+ });
848
+ }
849
+ return Cstr;
850
+ };
851
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
852
+ // initializeComponent
853
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
854
+ // Let the runtime know that the component has been initialized
855
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
856
+ {
857
+ // lazy loaded components
858
+ // request the component's implementation to be
859
+ // wired up with the host element
860
+ Cstr = loadModule(cmpMeta);
861
+ if (Cstr.then) {
862
+ // Await creates a micro-task avoid if possible
863
+ const endLoad = uniqueTime();
864
+ Cstr = await Cstr;
865
+ endLoad();
866
+ }
867
+ if (!Cstr.isProxied) {
868
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
869
+ Cstr.isProxied = true;
870
+ }
871
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
872
+ // ok, time to construct the instance
873
+ // but let's keep track of when we start and stop
874
+ // so that the getters/setters don't incorrectly step on data
875
+ {
876
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
877
+ }
878
+ // construct the lazy-loaded component implementation
879
+ // passing the hostRef is very important during
880
+ // construction in order to directly wire together the
881
+ // host element and the lazy-loaded instance
882
+ try {
883
+ new Cstr(hostRef);
884
+ }
885
+ catch (e) {
886
+ consoleError(e);
887
+ }
888
+ {
889
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
890
+ }
891
+ endNewInstance();
892
+ fireConnectedCallback(hostRef.$lazyInstance$);
893
+ }
894
+ if (Cstr.style) {
895
+ // this component has styles but we haven't registered them yet
896
+ let style = Cstr.style;
897
+ const scopeId = getScopeId(cmpMeta);
898
+ if (!styles.has(scopeId)) {
899
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
900
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
901
+ endRegisterStyles();
902
+ }
903
+ }
904
+ }
905
+ // we've successfully created a lazy instance
906
+ const ancestorComponent = hostRef.$ancestorComponent$;
907
+ const schedule = () => scheduleUpdate(hostRef, true);
908
+ if (ancestorComponent && ancestorComponent['s-rc']) {
909
+ // this is the initial load and this component it has an ancestor component
910
+ // but the ancestor component has NOT fired its will update lifecycle yet
911
+ // so let's just cool our jets and wait for the ancestor to continue first
912
+ // this will get fired off when the ancestor component
913
+ // finally gets around to rendering its lazy self
914
+ // fire off the initial update
915
+ ancestorComponent['s-rc'].push(schedule);
916
+ }
917
+ else {
918
+ schedule();
919
+ }
920
+ };
921
+ const fireConnectedCallback = (instance) => {
922
+ {
923
+ safeCall(instance, 'connectedCallback');
924
+ }
925
+ };
926
+ const connectedCallback = (elm) => {
927
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
928
+ const hostRef = getHostRef(elm);
929
+ const cmpMeta = hostRef.$cmpMeta$;
930
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
931
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
932
+ // first time this component has connected
933
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
934
+ {
935
+ // find the first ancestor component (if there is one) and register
936
+ // this component as one of the actively loading child components for its ancestor
937
+ let ancestorComponent = elm;
938
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
939
+ // climb up the ancestors looking for the first
940
+ // component that hasn't finished its lifecycle update yet
941
+ if (ancestorComponent['s-p']) {
942
+ // we found this components first ancestor component
943
+ // keep a reference to this component's ancestor component
944
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
945
+ break;
946
+ }
947
+ }
948
+ }
949
+ // Lazy properties
950
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
951
+ if (cmpMeta.$members$) {
952
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
953
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
954
+ const value = elm[memberName];
955
+ delete elm[memberName];
956
+ elm[memberName] = value;
957
+ }
958
+ });
959
+ }
960
+ {
961
+ initializeComponent(elm, hostRef, cmpMeta);
962
+ }
963
+ }
964
+ else {
965
+ // fire off connectedCallback() on component instance
966
+ fireConnectedCallback(hostRef.$lazyInstance$);
967
+ }
968
+ endConnected();
969
+ }
970
+ };
971
+ const disconnectedCallback = (elm) => {
972
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
973
+ const hostRef = getHostRef(elm);
974
+ const instance = hostRef.$lazyInstance$ ;
975
+ {
976
+ safeCall(instance, 'disconnectedCallback');
977
+ }
978
+ }
979
+ };
980
+ const bootstrapLazy = (lazyBundles, options = {}) => {
981
+ var _a;
982
+ const endBootstrap = createTime();
983
+ const cmpTags = [];
984
+ const exclude = options.exclude || [];
985
+ const customElements = win.customElements;
986
+ const head = doc.head;
987
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
988
+ const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
989
+ const deferredConnectedCallbacks = [];
990
+ let appLoadFallback;
991
+ let isBootstrapping = true;
992
+ Object.assign(plt, options);
993
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
994
+ lazyBundles.map((lazyBundle) => {
995
+ lazyBundle[1].map((compactMeta) => {
996
+ const cmpMeta = {
997
+ $flags$: compactMeta[0],
998
+ $tagName$: compactMeta[1],
999
+ $members$: compactMeta[2],
1000
+ $listeners$: compactMeta[3],
1001
+ };
1002
+ {
1003
+ cmpMeta.$members$ = compactMeta[2];
1004
+ }
1005
+ const tagName = cmpMeta.$tagName$;
1006
+ const HostElement = class extends HTMLElement {
1007
+ // StencilLazyHost
1008
+ constructor(self) {
1009
+ // @ts-ignore
1010
+ super(self);
1011
+ self = this;
1012
+ registerHost(self, cmpMeta);
1013
+ }
1014
+ connectedCallback() {
1015
+ if (appLoadFallback) {
1016
+ clearTimeout(appLoadFallback);
1017
+ appLoadFallback = null;
1018
+ }
1019
+ if (isBootstrapping) {
1020
+ // connectedCallback will be processed once all components have been registered
1021
+ deferredConnectedCallbacks.push(this);
1022
+ }
1023
+ else {
1024
+ plt.jmp(() => connectedCallback(this));
1025
+ }
1026
+ }
1027
+ disconnectedCallback() {
1028
+ plt.jmp(() => disconnectedCallback(this));
1029
+ }
1030
+ componentOnReady() {
1031
+ return getHostRef(this).$onReadyPromise$;
1032
+ }
1033
+ };
1034
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
1035
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1036
+ cmpTags.push(tagName);
1037
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1038
+ }
1039
+ });
1040
+ });
1041
+ {
1042
+ visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1043
+ visibilityStyle.setAttribute('data-styles', '');
1044
+ // Apply CSP nonce to the style tag if it exists
1045
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1046
+ if (nonce != null) {
1047
+ visibilityStyle.setAttribute('nonce', nonce);
1048
+ }
1049
+ head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1050
+ }
1051
+ // Process deferred connectedCallbacks now all components have been registered
1052
+ isBootstrapping = false;
1053
+ if (deferredConnectedCallbacks.length) {
1054
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
1055
+ }
1056
+ else {
1057
+ {
1058
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1059
+ }
1060
+ }
1061
+ // Fallback appLoad event
1062
+ endBootstrap();
1063
+ };
1064
+ /**
1065
+ * Assigns the given value to the nonce property on the runtime platform object.
1066
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1067
+ * @param nonce The value to be assigned to the platform nonce property.
1068
+ * @returns void
1069
+ */
1070
+ const setNonce = (nonce) => (plt.$nonce$ = nonce);
1071
+ const hostRefs = /*@__PURE__*/ new WeakMap();
1072
+ const getHostRef = (ref) => hostRefs.get(ref);
1073
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1074
+ const registerHost = (elm, cmpMeta) => {
1075
+ const hostRef = {
1076
+ $flags$: 0,
1077
+ $hostElement$: elm,
1078
+ $cmpMeta$: cmpMeta,
1079
+ $instanceValues$: new Map(),
1080
+ };
1081
+ {
1082
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1083
+ elm['s-p'] = [];
1084
+ elm['s-rc'] = [];
1085
+ }
1086
+ return hostRefs.set(elm, hostRef);
1087
+ };
1088
+ const consoleError = (e, el) => (0, console.error)(e, el);
1089
+ const cmpModules = /*@__PURE__*/ new Map();
1090
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1091
+ // loadModuleImport
1092
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1093
+ const bundleId = cmpMeta.$lazyBundleId$;
1094
+ const module = cmpModules.get(bundleId) ;
1095
+ if (module) {
1096
+ return module[exportName];
1097
+ }
1098
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1099
+ return import(
1100
+ /* @vite-ignore */
1101
+ /* webpackInclude: /\.entry\.js$/ */
1102
+ /* webpackExclude: /\.system\.entry\.js$/ */
1103
+ /* webpackMode: "lazy" */
1104
+ `./${bundleId}.entry.js${''}`).then((importedModule) => {
1105
+ {
1106
+ cmpModules.set(bundleId, importedModule);
1107
+ }
1108
+ return importedModule[exportName];
1109
+ }, consoleError);
1110
+ };
1111
+ const styles = /*@__PURE__*/ new Map();
1112
+ const win = typeof window !== 'undefined' ? window : {};
1113
+ const doc = win.document || { head: {} };
1114
+ const plt = {
1115
+ $flags$: 0,
1116
+ $resourcesUrl$: '',
1117
+ jmp: (h) => h(),
1118
+ raf: (h) => requestAnimationFrame(h),
1119
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1120
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1121
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
1122
+ };
1123
+ const promiseResolve = (v) => Promise.resolve(v);
1124
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1125
+ try {
1126
+ new CSSStyleSheet();
1127
+ return typeof new CSSStyleSheet().replaceSync === 'function';
1128
+ }
1129
+ catch (e) { }
1130
+ return false;
1131
+ })()
1132
+ ;
1133
+ const queueDomReads = [];
1134
+ const queueDomWrites = [];
1135
+ const queueTask = (queue, write) => (cb) => {
1136
+ queue.push(cb);
1137
+ if (!queuePending) {
1138
+ queuePending = true;
1139
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1140
+ nextTick(flush);
1141
+ }
1142
+ else {
1143
+ plt.raf(flush);
1144
+ }
1145
+ }
1146
+ };
1147
+ const consume = (queue) => {
1148
+ for (let i = 0; i < queue.length; i++) {
1149
+ try {
1150
+ queue[i](performance.now());
1151
+ }
1152
+ catch (e) {
1153
+ consoleError(e);
1154
+ }
1155
+ }
1156
+ queue.length = 0;
1157
+ };
1158
+ const flush = () => {
1159
+ // always force a bunch of medium callbacks to run, but still have
1160
+ // a throttle on how many can run in a certain time
1161
+ // DOM READS!!!
1162
+ consume(queueDomReads);
1163
+ // DOM WRITES!!!
1164
+ {
1165
+ consume(queueDomWrites);
1166
+ if ((queuePending = queueDomReads.length > 0)) {
1167
+ // still more to do yet, but we've run out of time
1168
+ // let's let this thing cool off and try again in the next tick
1169
+ plt.raf(flush);
1170
+ }
1171
+ }
1172
+ };
1173
+ const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1174
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1175
+
1176
+ export { Host as H, bootstrapLazy as b, forceUpdate as f, getElement as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
1177
+
1178
+ //# sourceMappingURL=index-9f5c1c1c.js.map