@jumpgroup/jump-design-system 0.0.1

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