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