reneco-hierarchized-picker 0.2.2-beta.7 → 0.2.2-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/index-55df525c.js +1465 -0
  2. package/dist/cjs/loader.cjs.js +1 -17
  3. package/dist/cjs/reneco-hierarchized-picker.cjs.entry.js +8 -58
  4. package/dist/cjs/reneco-hierarchized-picker.cjs.js +3 -133
  5. package/dist/collection/components/hierarchized-picker/hierarchized-picker.js +1 -1
  6. package/dist/custom-elements/index.js +7 -60
  7. package/dist/esm/index-ef964604.js +1437 -0
  8. package/dist/esm/loader.js +2 -18
  9. package/dist/esm/reneco-hierarchized-picker.entry.js +8 -58
  10. package/dist/esm/reneco-hierarchized-picker.js +4 -134
  11. package/dist/esm-es5/index-ef964604.js +2 -0
  12. package/dist/esm-es5/loader.js +1 -1
  13. package/dist/esm-es5/reneco-hierarchized-picker.entry.js +2 -2
  14. package/dist/esm-es5/reneco-hierarchized-picker.js +1 -1
  15. package/dist/reneco-hierarchized-picker/index.esm.js +0 -1
  16. package/dist/reneco-hierarchized-picker/p-20c44afe.system.entry.js +3 -0
  17. package/dist/reneco-hierarchized-picker/p-73168a50.system.js +1 -0
  18. package/dist/reneco-hierarchized-picker/p-9bcf4c87.js +2 -0
  19. package/dist/reneco-hierarchized-picker/p-ab414a6f.entry.js +1 -0
  20. package/dist/reneco-hierarchized-picker/p-ffa47dcf.system.js +2 -0
  21. package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.esm.js +1 -148
  22. package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.js +1 -1
  23. package/package.json +1 -1
  24. package/dist/cjs/app-globals-3a1e7e63.js +0 -5
  25. package/dist/cjs/css-shim-e843497f.js +0 -6
  26. package/dist/cjs/dom-ff96a4bc.js +0 -75
  27. package/dist/cjs/index-1f976b9a.js +0 -3407
  28. package/dist/cjs/shadow-css-7e3e0ab1.js +0 -389
  29. package/dist/esm/app-globals-0f993ce5.js +0 -3
  30. package/dist/esm/css-shim-b7d3d95f.js +0 -4
  31. package/dist/esm/dom-64053c71.js +0 -73
  32. package/dist/esm/index-f1624dc8.js +0 -3371
  33. package/dist/esm/shadow-css-98135883.js +0 -387
  34. package/dist/esm-es5/app-globals-0f993ce5.js +0 -1
  35. package/dist/esm-es5/css-shim-b7d3d95f.js +0 -1
  36. package/dist/esm-es5/dom-64053c71.js +0 -21
  37. package/dist/esm-es5/index-f1624dc8.js +0 -2
  38. package/dist/esm-es5/shadow-css-98135883.js +0 -12
  39. package/dist/reneco-hierarchized-picker/app-globals-0f993ce5.js +0 -3
  40. package/dist/reneco-hierarchized-picker/app-globals-497eb362.system.js +0 -1
  41. package/dist/reneco-hierarchized-picker/css-shim-1d8fad00.system.js +0 -1
  42. package/dist/reneco-hierarchized-picker/css-shim-b7d3d95f.js +0 -4
  43. package/dist/reneco-hierarchized-picker/dom-64053c71.js +0 -73
  44. package/dist/reneco-hierarchized-picker/dom-fbbb646f.system.js +0 -21
  45. package/dist/reneco-hierarchized-picker/index-d0e35b44.system.js +0 -2
  46. package/dist/reneco-hierarchized-picker/index-f1624dc8.js +0 -3371
  47. package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.entry.js +0 -19582
  48. package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.system.entry.js +0 -3
  49. package/dist/reneco-hierarchized-picker/reneco-hierarchized-picker.system.js +0 -1
  50. package/dist/reneco-hierarchized-picker/shadow-css-98135883.js +0 -387
  51. package/dist/reneco-hierarchized-picker/shadow-css-e5e084d1.system.js +0 -13
  52. /package/dist/reneco-hierarchized-picker/{index.system.js → p-50ea2036.system.js} +0 -0
@@ -0,0 +1,1465 @@
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 = 'reneco-hierarchized-picker';
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 isSvgMode = false;
34
+ let queuePending = false;
35
+ const createTime = (fnName, tagName = '') => {
36
+ {
37
+ return () => {
38
+ return;
39
+ };
40
+ }
41
+ };
42
+ const uniqueTime = (key, measureText) => {
43
+ {
44
+ return () => {
45
+ return;
46
+ };
47
+ }
48
+ };
49
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
50
+ /**
51
+ * Default style mode id
52
+ */
53
+ /**
54
+ * Reusable empty obj/array
55
+ * Don't add values to these!!
56
+ */
57
+ const EMPTY_OBJ = {};
58
+ const isComplexType = (o) => {
59
+ // https://jsperf.com/typeof-fn-object/5
60
+ o = typeof o;
61
+ return o === 'object' || o === 'function';
62
+ };
63
+ /**
64
+ * Helper method for querying a `meta` tag that contains a nonce value
65
+ * out of a DOM's head.
66
+ *
67
+ * @param doc The DOM containing the `head` to query against
68
+ * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
69
+ * exists or the tag has no content.
70
+ */
71
+ function queryNonceMetaTagContent(doc) {
72
+ var _a, _b, _c;
73
+ return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
74
+ }
75
+ /**
76
+ * Production h() function based on Preact by
77
+ * Jason Miller (@developit)
78
+ * Licensed under the MIT License
79
+ * https://github.com/developit/preact/blob/master/LICENSE
80
+ *
81
+ * Modified for Stencil's compiler and vdom
82
+ */
83
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
84
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
85
+ const h = (nodeName, vnodeData, ...children) => {
86
+ let child = null;
87
+ let simple = false;
88
+ let lastSimple = false;
89
+ const vNodeChildren = [];
90
+ const walk = (c) => {
91
+ for (let i = 0; i < c.length; i++) {
92
+ child = c[i];
93
+ if (Array.isArray(child)) {
94
+ walk(child);
95
+ }
96
+ else if (child != null && typeof child !== 'boolean') {
97
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
98
+ child = String(child);
99
+ }
100
+ if (simple && lastSimple) {
101
+ // If the previous child was simple (string), we merge both
102
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
103
+ }
104
+ else {
105
+ // Append a new vNode, if it's text, we create a text vNode
106
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
107
+ }
108
+ lastSimple = simple;
109
+ }
110
+ }
111
+ };
112
+ walk(children);
113
+ if (vnodeData) {
114
+ {
115
+ const classData = vnodeData.className || vnodeData.class;
116
+ if (classData) {
117
+ vnodeData.class =
118
+ typeof classData !== 'object'
119
+ ? classData
120
+ : Object.keys(classData)
121
+ .filter((k) => classData[k])
122
+ .join(' ');
123
+ }
124
+ }
125
+ }
126
+ const vnode = newVNode(nodeName, null);
127
+ vnode.$attrs$ = vnodeData;
128
+ if (vNodeChildren.length > 0) {
129
+ vnode.$children$ = vNodeChildren;
130
+ }
131
+ return vnode;
132
+ };
133
+ /**
134
+ * A utility function for creating a virtual DOM node from a tag and some
135
+ * possible text content.
136
+ *
137
+ * @param tag the tag for this element
138
+ * @param text possible text content for the node
139
+ * @returns a newly-minted virtual DOM node
140
+ */
141
+ const newVNode = (tag, text) => {
142
+ const vnode = {
143
+ $flags$: 0,
144
+ $tag$: tag,
145
+ $text$: text,
146
+ $elm$: null,
147
+ $children$: null,
148
+ };
149
+ {
150
+ vnode.$attrs$ = 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
+ const getElement = (ref) => (getHostRef(ref).$hostElement$ );
206
+ const createEvent = (ref, name, flags) => {
207
+ const elm = getElement(ref);
208
+ return {
209
+ emit: (detail) => {
210
+ return emitEvent(elm, name, {
211
+ bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
212
+ composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
213
+ cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
214
+ detail,
215
+ });
216
+ },
217
+ };
218
+ };
219
+ /**
220
+ * Helper function to create & dispatch a custom Event on a provided target
221
+ * @param elm the target of the Event
222
+ * @param name the name to give the custom Event
223
+ * @param opts options for configuring a custom Event
224
+ * @returns the custom Event
225
+ */
226
+ const emitEvent = (elm, name, opts) => {
227
+ const ev = plt.ce(name, opts);
228
+ elm.dispatchEvent(ev);
229
+ return ev;
230
+ };
231
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
232
+ const registerStyle = (scopeId, cssText, allowCS) => {
233
+ let style = styles.get(scopeId);
234
+ if (supportsConstructableStylesheets && allowCS) {
235
+ style = (style || new CSSStyleSheet());
236
+ if (typeof style === 'string') {
237
+ style = cssText;
238
+ }
239
+ else {
240
+ style.replaceSync(cssText);
241
+ }
242
+ }
243
+ else {
244
+ style = cssText;
245
+ }
246
+ styles.set(scopeId, style);
247
+ };
248
+ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
249
+ var _a;
250
+ let scopeId = getScopeId(cmpMeta);
251
+ const style = styles.get(scopeId);
252
+ // if an element is NOT connected then getRootNode() will return the wrong root node
253
+ // so the fallback is to always use the document for the root node in those cases
254
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
255
+ if (style) {
256
+ if (typeof style === 'string') {
257
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
258
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
259
+ let styleElm;
260
+ if (!appliedStyles) {
261
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
262
+ }
263
+ if (!appliedStyles.has(scopeId)) {
264
+ {
265
+ {
266
+ styleElm = doc.createElement('style');
267
+ styleElm.innerHTML = style;
268
+ }
269
+ // Apply CSP nonce to the style tag if it exists
270
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
271
+ if (nonce != null) {
272
+ styleElm.setAttribute('nonce', nonce);
273
+ }
274
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
275
+ }
276
+ if (appliedStyles) {
277
+ appliedStyles.add(scopeId);
278
+ }
279
+ }
280
+ }
281
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
282
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
283
+ }
284
+ }
285
+ return scopeId;
286
+ };
287
+ const attachStyles = (hostRef) => {
288
+ const cmpMeta = hostRef.$cmpMeta$;
289
+ const elm = hostRef.$hostElement$;
290
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
291
+ addStyle(elm.getRootNode(), cmpMeta);
292
+ endAttachStyles();
293
+ };
294
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
295
+ /**
296
+ * Production setAccessor() function based on Preact by
297
+ * Jason Miller (@developit)
298
+ * Licensed under the MIT License
299
+ * https://github.com/developit/preact/blob/master/LICENSE
300
+ *
301
+ * Modified for Stencil's compiler and vdom
302
+ */
303
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
304
+ if (oldValue !== newValue) {
305
+ let isProp = isMemberInElement(elm, memberName);
306
+ let ln = memberName.toLowerCase();
307
+ if (memberName === 'class') {
308
+ const classList = elm.classList;
309
+ const oldClasses = parseClassList(oldValue);
310
+ const newClasses = parseClassList(newValue);
311
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
312
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
313
+ }
314
+ else if (memberName === 'style') {
315
+ // update style attribute, css properties and values
316
+ {
317
+ for (const prop in oldValue) {
318
+ if (!newValue || newValue[prop] == null) {
319
+ if (prop.includes('-')) {
320
+ elm.style.removeProperty(prop);
321
+ }
322
+ else {
323
+ elm.style[prop] = '';
324
+ }
325
+ }
326
+ }
327
+ }
328
+ for (const prop in newValue) {
329
+ if (!oldValue || newValue[prop] !== oldValue[prop]) {
330
+ if (prop.includes('-')) {
331
+ elm.style.setProperty(prop, newValue[prop]);
332
+ }
333
+ else {
334
+ elm.style[prop] = newValue[prop];
335
+ }
336
+ }
337
+ }
338
+ }
339
+ else if (memberName === 'ref') {
340
+ // minifier will clean this up
341
+ if (newValue) {
342
+ newValue(elm);
343
+ }
344
+ }
345
+ else if ((!isProp ) &&
346
+ memberName[0] === 'o' &&
347
+ memberName[1] === 'n') {
348
+ // Event Handlers
349
+ // so if the member name starts with "on" and the 3rd characters is
350
+ // a capital letter, and it's not already a member on the element,
351
+ // then we're assuming it's an event listener
352
+ if (memberName[2] === '-') {
353
+ // on- prefixed events
354
+ // allows to be explicit about the dom event to listen without any magic
355
+ // under the hood:
356
+ // <my-cmp on-click> // listens for "click"
357
+ // <my-cmp on-Click> // listens for "Click"
358
+ // <my-cmp on-ionChange> // listens for "ionChange"
359
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
360
+ memberName = memberName.slice(3);
361
+ }
362
+ else if (isMemberInElement(win, ln)) {
363
+ // standard event
364
+ // the JSX attribute could have been "onMouseOver" and the
365
+ // member name "onmouseover" is on the window's prototype
366
+ // so let's add the listener "mouseover", which is all lowercased
367
+ memberName = ln.slice(2);
368
+ }
369
+ else {
370
+ // custom event
371
+ // the JSX attribute could have been "onMyCustomEvent"
372
+ // so let's trim off the "on" prefix and lowercase the first character
373
+ // and add the listener "myCustomEvent"
374
+ // except for the first character, we keep the event name case
375
+ memberName = ln[2] + memberName.slice(3);
376
+ }
377
+ if (oldValue) {
378
+ plt.rel(elm, memberName, oldValue, false);
379
+ }
380
+ if (newValue) {
381
+ plt.ael(elm, memberName, newValue, false);
382
+ }
383
+ }
384
+ else {
385
+ // Set property if it exists and it's not a SVG
386
+ const isComplex = isComplexType(newValue);
387
+ if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
388
+ try {
389
+ if (!elm.tagName.includes('-')) {
390
+ const n = newValue == null ? '' : newValue;
391
+ // Workaround for Safari, moving the <input> caret when re-assigning the same valued
392
+ if (memberName === 'list') {
393
+ isProp = false;
394
+ }
395
+ else if (oldValue == null || elm[memberName] != n) {
396
+ elm[memberName] = n;
397
+ }
398
+ }
399
+ else {
400
+ elm[memberName] = newValue;
401
+ }
402
+ }
403
+ catch (e) { }
404
+ }
405
+ if (newValue == null || newValue === false) {
406
+ if (newValue !== false || elm.getAttribute(memberName) === '') {
407
+ {
408
+ elm.removeAttribute(memberName);
409
+ }
410
+ }
411
+ }
412
+ else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
413
+ newValue = newValue === true ? '' : newValue;
414
+ {
415
+ elm.setAttribute(memberName, newValue);
416
+ }
417
+ }
418
+ }
419
+ }
420
+ };
421
+ const parseClassListRegex = /\s/;
422
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
423
+ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
424
+ // if the element passed in is a shadow root, which is a document fragment
425
+ // then we want to be adding attrs/props to the shadow root's "host" element
426
+ // if it's not a shadow root, then we add attrs/props to the same element
427
+ const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
428
+ ? newVnode.$elm$.host
429
+ : newVnode.$elm$;
430
+ const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
431
+ const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
432
+ {
433
+ // remove attributes no longer present on the vnode by setting them to undefined
434
+ for (memberName in oldVnodeAttrs) {
435
+ if (!(memberName in newVnodeAttrs)) {
436
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
437
+ }
438
+ }
439
+ }
440
+ // add new & update changed attributes
441
+ for (memberName in newVnodeAttrs) {
442
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
443
+ }
444
+ };
445
+ /**
446
+ * Create a DOM Node corresponding to one of the children of a given VNode.
447
+ *
448
+ * @param oldParentVNode the parent VNode from the previous render
449
+ * @param newParentVNode the parent VNode from the current render
450
+ * @param childIndex the index of the VNode, in the _new_ parent node's
451
+ * children, for which we will create a new DOM node
452
+ * @param parentElm the parent DOM node which our new node will be a child of
453
+ * @returns the newly created node
454
+ */
455
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
456
+ // tslint:disable-next-line: prefer-const
457
+ const newVNode = newParentVNode.$children$[childIndex];
458
+ let i = 0;
459
+ let elm;
460
+ let childNode;
461
+ if (newVNode.$text$ !== null) {
462
+ // create text node
463
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
464
+ }
465
+ else {
466
+ // create element
467
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
468
+ // add css classes, attrs, props, listeners, etc.
469
+ {
470
+ updateElement(null, newVNode, isSvgMode);
471
+ }
472
+ if (newVNode.$children$) {
473
+ for (i = 0; i < newVNode.$children$.length; ++i) {
474
+ // create the node
475
+ childNode = createElm(oldParentVNode, newVNode, i);
476
+ // return node could have been null
477
+ if (childNode) {
478
+ // append our new node
479
+ elm.appendChild(childNode);
480
+ }
481
+ }
482
+ }
483
+ }
484
+ return elm;
485
+ };
486
+ /**
487
+ * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
488
+ * add them to the DOM in the appropriate place.
489
+ *
490
+ * @param parentElm the DOM node which should be used as a parent for the new
491
+ * DOM nodes
492
+ * @param before a child of the `parentElm` which the new children should be
493
+ * inserted before (optional)
494
+ * @param parentVNode the parent virtual DOM node
495
+ * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
496
+ * @param startIdx the index in the child virtual DOM nodes at which to start
497
+ * creating DOM nodes (inclusive)
498
+ * @param endIdx the index in the child virtual DOM nodes at which to stop
499
+ * creating DOM nodes (inclusive)
500
+ */
501
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
502
+ let containerElm = (parentElm);
503
+ let childNode;
504
+ for (; startIdx <= endIdx; ++startIdx) {
505
+ if (vnodes[startIdx]) {
506
+ childNode = createElm(null, parentVNode, startIdx);
507
+ if (childNode) {
508
+ vnodes[startIdx].$elm$ = childNode;
509
+ containerElm.insertBefore(childNode, before);
510
+ }
511
+ }
512
+ }
513
+ };
514
+ /**
515
+ * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
516
+ * This can be used to, for instance, clean up after a list of children which
517
+ * should no longer be shown.
518
+ *
519
+ * This function also handles some of Stencil's slot relocation logic.
520
+ *
521
+ * @param vnodes a list of virtual DOM nodes to remove
522
+ * @param startIdx the index at which to start removing nodes (inclusive)
523
+ * @param endIdx the index at which to stop removing nodes (inclusive)
524
+ * @param vnode a VNode
525
+ * @param elm an element
526
+ */
527
+ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
528
+ for (; startIdx <= endIdx; ++startIdx) {
529
+ if ((vnode = vnodes[startIdx])) {
530
+ elm = vnode.$elm$;
531
+ callNodeRefs(vnode);
532
+ // remove the vnode's element from the dom
533
+ elm.remove();
534
+ }
535
+ }
536
+ };
537
+ /**
538
+ * Reconcile the children of a new VNode with the children of an old VNode by
539
+ * traversing the two collections of children, identifying nodes that are
540
+ * conserved or changed, calling out to `patch` to make any necessary
541
+ * updates to the DOM, and rearranging DOM nodes as needed.
542
+ *
543
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
544
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
545
+ * 'windows' by storing start and end indices and references to the
546
+ * corresponding array entries. Initially the two 'windows' are basically equal
547
+ * to the entire array, but we progressively narrow the windows until there are
548
+ * no children left to update by doing the following:
549
+ *
550
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
551
+ * that if we have an initial array like the following we'll end up dealing
552
+ * only with a window bounded by the highlighted elements:
553
+ *
554
+ * [null, null, VNode1 , ... , VNode2, null, null]
555
+ * ^^^^^^ ^^^^^^
556
+ *
557
+ * 2. Check to see if the elements at the head and tail positions are equal
558
+ * across the windows. This will basically detect elements which haven't
559
+ * been added, removed, or changed position, i.e. if you had the following
560
+ * VNode elements (represented as HTML):
561
+ *
562
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
563
+ * newVNode: `<div><p><span>THERE</span></p></div>`
564
+ *
565
+ * Then when comparing the children of the `<div>` tag we check the equality
566
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
567
+ * same tag in the same position, we'd be able to avoid completely
568
+ * re-rendering the subtree under them with a new DOM element and would just
569
+ * call out to `patch` to handle reconciling their children and so on.
570
+ *
571
+ * 3. Check, for both windows, to see if the element at the beginning of the
572
+ * window corresponds to the element at the end of the other window. This is
573
+ * a heuristic which will let us identify _some_ situations in which
574
+ * elements have changed position, for instance it _should_ detect that the
575
+ * children nodes themselves have not changed but merely moved in the
576
+ * following example:
577
+ *
578
+ * oldVNode: `<div><element-one /><element-two /></div>`
579
+ * newVNode: `<div><element-two /><element-one /></div>`
580
+ *
581
+ * If we find cases like this then we also need to move the concrete DOM
582
+ * elements corresponding to the moved children to write the re-order to the
583
+ * DOM.
584
+ *
585
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
586
+ * nodes in the old children which have the same key as the first element in
587
+ * our window on the new children. If we find such a node we handle calling
588
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
589
+ * what we find.
590
+ *
591
+ * Finally, once we've narrowed our 'windows' to the point that either of them
592
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
593
+ * insertion or deletion that needs to happen to get a DOM state that correctly
594
+ * reflects the new child VNodes. If, for instance, after our window on the old
595
+ * children has collapsed we still have more nodes on the new children that
596
+ * we haven't dealt with yet then we need to add them, or if the new children
597
+ * collapse but we still have unhandled _old_ children then we need to make
598
+ * sure the corresponding DOM nodes are removed.
599
+ *
600
+ * @param parentElm the node into which the parent VNode is rendered
601
+ * @param oldCh the old children of the parent node
602
+ * @param newVNode the new VNode which will replace the parent
603
+ * @param newCh the new children of the parent node
604
+ */
605
+ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
606
+ let oldStartIdx = 0;
607
+ let newStartIdx = 0;
608
+ let oldEndIdx = oldCh.length - 1;
609
+ let oldStartVnode = oldCh[0];
610
+ let oldEndVnode = oldCh[oldEndIdx];
611
+ let newEndIdx = newCh.length - 1;
612
+ let newStartVnode = newCh[0];
613
+ let newEndVnode = newCh[newEndIdx];
614
+ let node;
615
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
616
+ if (oldStartVnode == null) {
617
+ // VNode might have been moved left
618
+ oldStartVnode = oldCh[++oldStartIdx];
619
+ }
620
+ else if (oldEndVnode == null) {
621
+ oldEndVnode = oldCh[--oldEndIdx];
622
+ }
623
+ else if (newStartVnode == null) {
624
+ newStartVnode = newCh[++newStartIdx];
625
+ }
626
+ else if (newEndVnode == null) {
627
+ newEndVnode = newCh[--newEndIdx];
628
+ }
629
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
630
+ // if the start nodes are the same then we should patch the new VNode
631
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
632
+ // indices to reflect that. We don't need to move any DOM Nodes around
633
+ // since things are matched up in order.
634
+ patch(oldStartVnode, newStartVnode);
635
+ oldStartVnode = oldCh[++oldStartIdx];
636
+ newStartVnode = newCh[++newStartIdx];
637
+ }
638
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
639
+ // likewise, if the end nodes are the same we patch new onto old and
640
+ // decrement our end indices, and also likewise in this case we don't
641
+ // need to move any DOM Nodes.
642
+ patch(oldEndVnode, newEndVnode);
643
+ oldEndVnode = oldCh[--oldEndIdx];
644
+ newEndVnode = newCh[--newEndIdx];
645
+ }
646
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
647
+ patch(oldStartVnode, newEndVnode);
648
+ // We need to move the element for `oldStartVnode` into a position which
649
+ // will be appropriate for `newEndVnode`. For this we can use
650
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
651
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
652
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
653
+ //
654
+ // <old-start-node />
655
+ // <some-intervening-node />
656
+ // <old-end-node />
657
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
658
+ // <next-sibling />
659
+ //
660
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
661
+ // the node for `oldStartVnode` at the end of the children of
662
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
663
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
664
+ // append it to the children of the parent element.
665
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
666
+ oldStartVnode = oldCh[++oldStartIdx];
667
+ newEndVnode = newCh[--newEndIdx];
668
+ }
669
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
670
+ patch(oldEndVnode, newStartVnode);
671
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
672
+ // the same node, so since we're here we know that they are not. Thus we
673
+ // can move the element for `oldEndVnode` _before_ the element for
674
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
675
+ // future.
676
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
677
+ oldEndVnode = oldCh[--oldEndIdx];
678
+ newStartVnode = newCh[++newStartIdx];
679
+ }
680
+ else {
681
+ {
682
+ // We either didn't find an element in the old children that matches
683
+ // the key of the first new child OR the build is not using `key`
684
+ // attributes at all. In either case we need to create a new element
685
+ // for the new node.
686
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
687
+ newStartVnode = newCh[++newStartIdx];
688
+ }
689
+ if (node) {
690
+ // if we created a new node then handle inserting it to the DOM
691
+ {
692
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
693
+ }
694
+ }
695
+ }
696
+ }
697
+ if (oldStartIdx > oldEndIdx) {
698
+ // we have some more new nodes to add which don't match up with old nodes
699
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
700
+ }
701
+ else if (newStartIdx > newEndIdx) {
702
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
703
+ // in the new array, so lets remove them (which entails cleaning up the
704
+ // relevant DOM nodes)
705
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
706
+ }
707
+ };
708
+ /**
709
+ * Compare two VNodes to determine if they are the same
710
+ *
711
+ * **NB**: This function is an equality _heuristic_ based on the available
712
+ * information set on the two VNodes and can be misleading under certain
713
+ * circumstances. In particular, if the two nodes do not have `key` attrs
714
+ * (available under `$key$` on VNodes) then the function falls back on merely
715
+ * checking that they have the same tag.
716
+ *
717
+ * So, in other words, if `key` attrs are not set on VNodes which may be
718
+ * changing order within a `children` array or something along those lines then
719
+ * we could obtain a false negative and then have to do needless re-rendering
720
+ * (i.e. we'd say two VNodes aren't equal when in fact they should be).
721
+ *
722
+ * @param leftVNode the first VNode to check
723
+ * @param rightVNode the second VNode to check
724
+ * @returns whether they're equal or not
725
+ */
726
+ const isSameVnode = (leftVNode, rightVNode) => {
727
+ // compare if two vnode to see if they're "technically" the same
728
+ // need to have the same element tag, and same key to be the same
729
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
730
+ return true;
731
+ }
732
+ return false;
733
+ };
734
+ /**
735
+ * Handle reconciling an outdated VNode with a new one which corresponds to
736
+ * it. This function handles flushing updates to the DOM and reconciling the
737
+ * children of the two nodes (if any).
738
+ *
739
+ * @param oldVNode an old VNode whose DOM element and children we want to update
740
+ * @param newVNode a new VNode representing an updated version of the old one
741
+ */
742
+ const patch = (oldVNode, newVNode) => {
743
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
744
+ const oldChildren = oldVNode.$children$;
745
+ const newChildren = newVNode.$children$;
746
+ const text = newVNode.$text$;
747
+ if (text === null) {
748
+ {
749
+ {
750
+ // either this is the first render of an element OR it's an update
751
+ // AND we already know it's possible it could have changed
752
+ // this updates the element's css classes, attrs, props, listeners, etc.
753
+ updateElement(oldVNode, newVNode, isSvgMode);
754
+ }
755
+ }
756
+ if (oldChildren !== null && newChildren !== null) {
757
+ // looks like there's child vnodes for both the old and new vnodes
758
+ // so we need to call `updateChildren` to reconcile them
759
+ updateChildren(elm, oldChildren, newVNode, newChildren);
760
+ }
761
+ else if (newChildren !== null) {
762
+ // no old child vnodes, but there are new child vnodes to add
763
+ if (oldVNode.$text$ !== null) {
764
+ // the old vnode was text, so be sure to clear it out
765
+ elm.textContent = '';
766
+ }
767
+ // add the new vnode children
768
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
769
+ }
770
+ else if (oldChildren !== null) {
771
+ // no new child vnodes, but there are old child vnodes to remove
772
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
773
+ }
774
+ }
775
+ else if (oldVNode.$text$ !== text) {
776
+ // update the text content for the text only vnode
777
+ // and also only if the text is different than before
778
+ elm.data = text;
779
+ }
780
+ };
781
+ const callNodeRefs = (vNode) => {
782
+ {
783
+ vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
784
+ vNode.$children$ && vNode.$children$.map(callNodeRefs);
785
+ }
786
+ };
787
+ /**
788
+ * The main entry point for Stencil's virtual DOM-based rendering engine
789
+ *
790
+ * Given a {@link d.HostRef} container and some virtual DOM nodes, this
791
+ * function will handle creating a virtual DOM tree with a single root, patching
792
+ * the current virtual DOM tree onto an old one (if any), dealing with slot
793
+ * relocation, and reflecting attributes.
794
+ *
795
+ * @param hostRef data needed to root and render the virtual DOM tree, such as
796
+ * the DOM node into which it should be rendered.
797
+ * @param renderFnResults the virtual DOM nodes to be rendered
798
+ */
799
+ const renderVdom = (hostRef, renderFnResults) => {
800
+ const hostElm = hostRef.$hostElement$;
801
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
802
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
803
+ rootVnode.$tag$ = null;
804
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
805
+ hostRef.$vnode$ = rootVnode;
806
+ rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
807
+ // synchronous patch
808
+ patch(oldVNode, rootVnode);
809
+ };
810
+ const attachToAncestor = (hostRef, ancestorComponent) => {
811
+ if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
812
+ ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
813
+ }
814
+ };
815
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
816
+ {
817
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
818
+ }
819
+ if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
820
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
821
+ return;
822
+ }
823
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
824
+ // there is no ancestor component or the ancestor component
825
+ // has already fired off its lifecycle update then
826
+ // fire off the initial update
827
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
828
+ return writeTask(dispatch) ;
829
+ };
830
+ const dispatchHooks = (hostRef, isInitialLoad) => {
831
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
832
+ const instance = hostRef.$lazyInstance$ ;
833
+ let promise;
834
+ if (isInitialLoad) {
835
+ {
836
+ promise = safeCall(instance, 'componentWillLoad');
837
+ }
838
+ }
839
+ {
840
+ promise = then(promise, () => safeCall(instance, 'componentWillRender'));
841
+ }
842
+ endSchedule();
843
+ return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
844
+ };
845
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
846
+ // updateComponent
847
+ const elm = hostRef.$hostElement$;
848
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
849
+ const rc = elm['s-rc'];
850
+ if (isInitialLoad) {
851
+ // DOM WRITE!
852
+ attachStyles(hostRef);
853
+ }
854
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
855
+ {
856
+ callRender(hostRef, instance);
857
+ }
858
+ if (rc) {
859
+ // ok, so turns out there are some child host elements
860
+ // waiting on this parent element to load
861
+ // let's fire off all update callbacks waiting
862
+ rc.map((cb) => cb());
863
+ elm['s-rc'] = undefined;
864
+ }
865
+ endRender();
866
+ endUpdate();
867
+ {
868
+ const childrenPromises = elm['s-p'];
869
+ const postUpdate = () => postUpdateComponent(hostRef);
870
+ if (childrenPromises.length === 0) {
871
+ postUpdate();
872
+ }
873
+ else {
874
+ Promise.all(childrenPromises).then(postUpdate);
875
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
876
+ childrenPromises.length = 0;
877
+ }
878
+ }
879
+ };
880
+ const callRender = (hostRef, instance, elm) => {
881
+ try {
882
+ instance = instance.render() ;
883
+ {
884
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
885
+ }
886
+ {
887
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
888
+ }
889
+ {
890
+ {
891
+ // looks like we've got child nodes to render into this host element
892
+ // or we need to update the css class/attrs on the host element
893
+ // DOM WRITE!
894
+ {
895
+ renderVdom(hostRef, instance);
896
+ }
897
+ }
898
+ }
899
+ }
900
+ catch (e) {
901
+ consoleError(e, hostRef.$hostElement$);
902
+ }
903
+ return null;
904
+ };
905
+ const postUpdateComponent = (hostRef) => {
906
+ const tagName = hostRef.$cmpMeta$.$tagName$;
907
+ const elm = hostRef.$hostElement$;
908
+ const endPostUpdate = createTime('postUpdate', tagName);
909
+ const instance = hostRef.$lazyInstance$ ;
910
+ const ancestorComponent = hostRef.$ancestorComponent$;
911
+ {
912
+ safeCall(instance, 'componentDidRender');
913
+ }
914
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
915
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
916
+ {
917
+ // DOM WRITE!
918
+ addHydratedFlag(elm);
919
+ }
920
+ {
921
+ safeCall(instance, 'componentDidLoad');
922
+ }
923
+ endPostUpdate();
924
+ {
925
+ hostRef.$onReadyResolve$(elm);
926
+ if (!ancestorComponent) {
927
+ appDidLoad();
928
+ }
929
+ }
930
+ }
931
+ else {
932
+ endPostUpdate();
933
+ }
934
+ {
935
+ hostRef.$onInstanceResolve$(elm);
936
+ }
937
+ // load events fire from bottom to top
938
+ // the deepest elements load first then bubbles up
939
+ {
940
+ if (hostRef.$onRenderResolve$) {
941
+ hostRef.$onRenderResolve$();
942
+ hostRef.$onRenderResolve$ = undefined;
943
+ }
944
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
945
+ nextTick(() => scheduleUpdate(hostRef, false));
946
+ }
947
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
948
+ }
949
+ // ( •_•)
950
+ // ( •_•)>⌐■-■
951
+ // (⌐■_■)
952
+ };
953
+ const appDidLoad = (who) => {
954
+ // on appload
955
+ // we have finish the first big initial render
956
+ {
957
+ addHydratedFlag(doc.documentElement);
958
+ }
959
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
960
+ };
961
+ const safeCall = (instance, method, arg) => {
962
+ if (instance && instance[method]) {
963
+ try {
964
+ return instance[method](arg);
965
+ }
966
+ catch (e) {
967
+ consoleError(e);
968
+ }
969
+ }
970
+ return undefined;
971
+ };
972
+ const then = (promise, thenFn) => {
973
+ return promise && promise.then ? promise.then(thenFn) : thenFn();
974
+ };
975
+ const addHydratedFlag = (elm) => elm.classList.add('hydrated')
976
+ ;
977
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
978
+ const setValue = (ref, propName, newVal, cmpMeta) => {
979
+ // check our new property value against our internal value
980
+ const hostRef = getHostRef(ref);
981
+ const elm = hostRef.$hostElement$ ;
982
+ const oldVal = hostRef.$instanceValues$.get(propName);
983
+ const flags = hostRef.$flags$;
984
+ const instance = hostRef.$lazyInstance$ ;
985
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
986
+ // explicitly check for NaN on both sides, as `NaN === NaN` is always false
987
+ const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
988
+ const didValueChange = newVal !== oldVal && !areBothNaN;
989
+ if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
990
+ // gadzooks! the property's value has changed!!
991
+ // set our new value!
992
+ hostRef.$instanceValues$.set(propName, newVal);
993
+ if (instance) {
994
+ // get an array of method names of watch functions to call
995
+ if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
996
+ const watchMethods = cmpMeta.$watchers$[propName];
997
+ if (watchMethods) {
998
+ // this instance is watching for when this property changed
999
+ watchMethods.map((watchMethodName) => {
1000
+ try {
1001
+ // fire off each of the watch methods that are watching this property
1002
+ instance[watchMethodName](newVal, oldVal, propName);
1003
+ }
1004
+ catch (e) {
1005
+ consoleError(e, elm);
1006
+ }
1007
+ });
1008
+ }
1009
+ }
1010
+ if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1011
+ // looks like this value actually changed, so we've got work to do!
1012
+ // but only if we've already rendered, otherwise just chill out
1013
+ // queue that we need to do an update, but don't worry about queuing
1014
+ // up millions cuz this function ensures it only runs once
1015
+ scheduleUpdate(hostRef, false);
1016
+ }
1017
+ }
1018
+ }
1019
+ };
1020
+ /**
1021
+ * Attach a series of runtime constructs to a compiled Stencil component
1022
+ * constructor, including getters and setters for the `@Prop` and `@State`
1023
+ * decorators, callbacks for when attributes change, and so on.
1024
+ *
1025
+ * @param Cstr the constructor for a component that we need to process
1026
+ * @param cmpMeta metadata collected previously about the component
1027
+ * @param flags a number used to store a series of bit flags
1028
+ * @returns a reference to the same constructor passed in (but now mutated)
1029
+ */
1030
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
1031
+ if (cmpMeta.$members$) {
1032
+ if (Cstr.watchers) {
1033
+ cmpMeta.$watchers$ = Cstr.watchers;
1034
+ }
1035
+ // It's better to have a const than two Object.entries()
1036
+ const members = Object.entries(cmpMeta.$members$);
1037
+ const prototype = Cstr.prototype;
1038
+ members.map(([memberName, [memberFlags]]) => {
1039
+ if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1040
+ ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1041
+ // proxyComponent - prop
1042
+ Object.defineProperty(prototype, memberName, {
1043
+ get() {
1044
+ // proxyComponent, get value
1045
+ return getValue(this, memberName);
1046
+ },
1047
+ set(newValue) {
1048
+ // proxyComponent, set value
1049
+ setValue(this, memberName, newValue, cmpMeta);
1050
+ },
1051
+ configurable: true,
1052
+ enumerable: true,
1053
+ });
1054
+ }
1055
+ else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
1056
+ memberFlags & 64 /* MEMBER_FLAGS.Method */) {
1057
+ // proxyComponent - method
1058
+ Object.defineProperty(prototype, memberName, {
1059
+ value(...args) {
1060
+ const ref = getHostRef(this);
1061
+ return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
1062
+ },
1063
+ });
1064
+ }
1065
+ });
1066
+ if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1067
+ const attrNameToPropName = new Map();
1068
+ prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1069
+ plt.jmp(() => {
1070
+ const propName = attrNameToPropName.get(attrName);
1071
+ // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1072
+ // in the case where an attribute was set inline.
1073
+ // ```html
1074
+ // <my-component some-attribute="some-value"></my-component>
1075
+ // ```
1076
+ //
1077
+ // There is an edge case where a developer sets the attribute inline on a custom element and then
1078
+ // programmatically changes it before it has been upgraded as shown below:
1079
+ //
1080
+ // ```html
1081
+ // <!-- this component has _not_ been upgraded yet -->
1082
+ // <my-component id="test" some-attribute="some-value"></my-component>
1083
+ // <script>
1084
+ // // grab non-upgraded component
1085
+ // el = document.querySelector("#test");
1086
+ // el.someAttribute = "another-value";
1087
+ // // upgrade component
1088
+ // customElements.define('my-component', MyComponent);
1089
+ // </script>
1090
+ // ```
1091
+ // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
1092
+ // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1093
+ // to the value that was set inline i.e. "some-value" from above example. When
1094
+ // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
1095
+ //
1096
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
1097
+ // by connectedCallback as this attributeChangedCallback will not fire.
1098
+ //
1099
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1100
+ //
1101
+ // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1102
+ // properties here given that this goes against best practices outlined here
1103
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1104
+ if (this.hasOwnProperty(propName)) {
1105
+ newValue = this[propName];
1106
+ delete this[propName];
1107
+ }
1108
+ else if (prototype.hasOwnProperty(propName) &&
1109
+ typeof this[propName] === 'number' &&
1110
+ this[propName] == newValue) {
1111
+ // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1112
+ // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1113
+ // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1114
+ return;
1115
+ }
1116
+ this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1117
+ });
1118
+ };
1119
+ // create an array of attributes to observe
1120
+ // and also create a map of html attribute name to js property name
1121
+ Cstr.observedAttributes = members
1122
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
1123
+ .map(([propName, m]) => {
1124
+ const attrName = m[1] || propName;
1125
+ attrNameToPropName.set(attrName, propName);
1126
+ return attrName;
1127
+ });
1128
+ }
1129
+ }
1130
+ return Cstr;
1131
+ };
1132
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1133
+ // initializeComponent
1134
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1135
+ {
1136
+ // we haven't initialized this element yet
1137
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1138
+ // lazy loaded components
1139
+ // request the component's implementation to be
1140
+ // wired up with the host element
1141
+ Cstr = loadModule(cmpMeta);
1142
+ if (Cstr.then) {
1143
+ // Await creates a micro-task avoid if possible
1144
+ const endLoad = uniqueTime();
1145
+ Cstr = await Cstr;
1146
+ endLoad();
1147
+ }
1148
+ if (!Cstr.isProxied) {
1149
+ // we've never proxied this Constructor before
1150
+ // let's add the getters/setters to its prototype before
1151
+ // the first time we create an instance of the implementation
1152
+ {
1153
+ cmpMeta.$watchers$ = Cstr.watchers;
1154
+ }
1155
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1156
+ Cstr.isProxied = true;
1157
+ }
1158
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1159
+ // ok, time to construct the instance
1160
+ // but let's keep track of when we start and stop
1161
+ // so that the getters/setters don't incorrectly step on data
1162
+ {
1163
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1164
+ }
1165
+ // construct the lazy-loaded component implementation
1166
+ // passing the hostRef is very important during
1167
+ // construction in order to directly wire together the
1168
+ // host element and the lazy-loaded instance
1169
+ try {
1170
+ new Cstr(hostRef);
1171
+ }
1172
+ catch (e) {
1173
+ consoleError(e);
1174
+ }
1175
+ {
1176
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1177
+ }
1178
+ {
1179
+ hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
1180
+ }
1181
+ endNewInstance();
1182
+ }
1183
+ if (Cstr.style) {
1184
+ // this component has styles but we haven't registered them yet
1185
+ let style = Cstr.style;
1186
+ const scopeId = getScopeId(cmpMeta);
1187
+ if (!styles.has(scopeId)) {
1188
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1189
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1190
+ endRegisterStyles();
1191
+ }
1192
+ }
1193
+ }
1194
+ // we've successfully created a lazy instance
1195
+ const ancestorComponent = hostRef.$ancestorComponent$;
1196
+ const schedule = () => scheduleUpdate(hostRef, true);
1197
+ if (ancestorComponent && ancestorComponent['s-rc']) {
1198
+ // this is the initial load and this component it has an ancestor component
1199
+ // but the ancestor component has NOT fired its will update lifecycle yet
1200
+ // so let's just cool our jets and wait for the ancestor to continue first
1201
+ // this will get fired off when the ancestor component
1202
+ // finally gets around to rendering its lazy self
1203
+ // fire off the initial update
1204
+ ancestorComponent['s-rc'].push(schedule);
1205
+ }
1206
+ else {
1207
+ schedule();
1208
+ }
1209
+ };
1210
+ const connectedCallback = (elm) => {
1211
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1212
+ const hostRef = getHostRef(elm);
1213
+ const cmpMeta = hostRef.$cmpMeta$;
1214
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1215
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1216
+ // first time this component has connected
1217
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1218
+ {
1219
+ // find the first ancestor component (if there is one) and register
1220
+ // this component as one of the actively loading child components for its ancestor
1221
+ let ancestorComponent = elm;
1222
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1223
+ // climb up the ancestors looking for the first
1224
+ // component that hasn't finished its lifecycle update yet
1225
+ if (ancestorComponent['s-p']) {
1226
+ // we found this components first ancestor component
1227
+ // keep a reference to this component's ancestor component
1228
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1229
+ break;
1230
+ }
1231
+ }
1232
+ }
1233
+ // Lazy properties
1234
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1235
+ if (cmpMeta.$members$) {
1236
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1237
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1238
+ const value = elm[memberName];
1239
+ delete elm[memberName];
1240
+ elm[memberName] = value;
1241
+ }
1242
+ });
1243
+ }
1244
+ {
1245
+ initializeComponent(elm, hostRef, cmpMeta);
1246
+ }
1247
+ }
1248
+ endConnected();
1249
+ }
1250
+ };
1251
+ const disconnectedCallback = (elm) => {
1252
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1253
+ getHostRef(elm);
1254
+ }
1255
+ };
1256
+ const bootstrapLazy = (lazyBundles, options = {}) => {
1257
+ var _a;
1258
+ const endBootstrap = createTime();
1259
+ const cmpTags = [];
1260
+ const exclude = options.exclude || [];
1261
+ const customElements = win.customElements;
1262
+ const head = doc.head;
1263
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1264
+ const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1265
+ const deferredConnectedCallbacks = [];
1266
+ let appLoadFallback;
1267
+ let isBootstrapping = true;
1268
+ Object.assign(plt, options);
1269
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1270
+ lazyBundles.map((lazyBundle) => {
1271
+ lazyBundle[1].map((compactMeta) => {
1272
+ const cmpMeta = {
1273
+ $flags$: compactMeta[0],
1274
+ $tagName$: compactMeta[1],
1275
+ $members$: compactMeta[2],
1276
+ $listeners$: compactMeta[3],
1277
+ };
1278
+ {
1279
+ cmpMeta.$members$ = compactMeta[2];
1280
+ }
1281
+ {
1282
+ cmpMeta.$watchers$ = {};
1283
+ }
1284
+ const tagName = cmpMeta.$tagName$;
1285
+ const HostElement = class extends HTMLElement {
1286
+ // StencilLazyHost
1287
+ constructor(self) {
1288
+ // @ts-ignore
1289
+ super(self);
1290
+ self = this;
1291
+ registerHost(self, cmpMeta);
1292
+ }
1293
+ connectedCallback() {
1294
+ if (appLoadFallback) {
1295
+ clearTimeout(appLoadFallback);
1296
+ appLoadFallback = null;
1297
+ }
1298
+ if (isBootstrapping) {
1299
+ // connectedCallback will be processed once all components have been registered
1300
+ deferredConnectedCallbacks.push(this);
1301
+ }
1302
+ else {
1303
+ plt.jmp(() => connectedCallback(this));
1304
+ }
1305
+ }
1306
+ disconnectedCallback() {
1307
+ plt.jmp(() => disconnectedCallback(this));
1308
+ }
1309
+ componentOnReady() {
1310
+ return getHostRef(this).$onReadyPromise$;
1311
+ }
1312
+ };
1313
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
1314
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1315
+ cmpTags.push(tagName);
1316
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1317
+ }
1318
+ });
1319
+ });
1320
+ {
1321
+ visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1322
+ visibilityStyle.setAttribute('data-styles', '');
1323
+ // Apply CSP nonce to the style tag if it exists
1324
+ const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1325
+ if (nonce != null) {
1326
+ visibilityStyle.setAttribute('nonce', nonce);
1327
+ }
1328
+ head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1329
+ }
1330
+ // Process deferred connectedCallbacks now all components have been registered
1331
+ isBootstrapping = false;
1332
+ if (deferredConnectedCallbacks.length) {
1333
+ deferredConnectedCallbacks.map((host) => host.connectedCallback());
1334
+ }
1335
+ else {
1336
+ {
1337
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1338
+ }
1339
+ }
1340
+ // Fallback appLoad event
1341
+ endBootstrap();
1342
+ };
1343
+ /**
1344
+ * Assigns the given value to the nonce property on the runtime platform object.
1345
+ * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1346
+ * @param nonce The value to be assigned to the platform nonce property.
1347
+ * @returns void
1348
+ */
1349
+ const setNonce = (nonce) => (plt.$nonce$ = nonce);
1350
+ const hostRefs = /*@__PURE__*/ new WeakMap();
1351
+ const getHostRef = (ref) => hostRefs.get(ref);
1352
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1353
+ const registerHost = (elm, cmpMeta) => {
1354
+ const hostRef = {
1355
+ $flags$: 0,
1356
+ $hostElement$: elm,
1357
+ $cmpMeta$: cmpMeta,
1358
+ $instanceValues$: new Map(),
1359
+ };
1360
+ {
1361
+ hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
1362
+ }
1363
+ {
1364
+ hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1365
+ elm['s-p'] = [];
1366
+ elm['s-rc'] = [];
1367
+ }
1368
+ return hostRefs.set(elm, hostRef);
1369
+ };
1370
+ const isMemberInElement = (elm, memberName) => memberName in elm;
1371
+ const consoleError = (e, el) => (0, console.error)(e, el);
1372
+ const cmpModules = /*@__PURE__*/ new Map();
1373
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1374
+ // loadModuleImport
1375
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1376
+ const bundleId = cmpMeta.$lazyBundleId$;
1377
+ const module = cmpModules.get(bundleId) ;
1378
+ if (module) {
1379
+ return module[exportName];
1380
+ }
1381
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1382
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
1383
+ /* @vite-ignore */
1384
+ /* webpackInclude: /\.entry\.js$/ */
1385
+ /* webpackExclude: /\.system\.entry\.js$/ */
1386
+ /* webpackMode: "lazy" */
1387
+ `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
1388
+ {
1389
+ cmpModules.set(bundleId, importedModule);
1390
+ }
1391
+ return importedModule[exportName];
1392
+ }, consoleError);
1393
+ };
1394
+ const styles = /*@__PURE__*/ new Map();
1395
+ const win = typeof window !== 'undefined' ? window : {};
1396
+ const doc = win.document || { head: {} };
1397
+ const plt = {
1398
+ $flags$: 0,
1399
+ $resourcesUrl$: '',
1400
+ jmp: (h) => h(),
1401
+ raf: (h) => requestAnimationFrame(h),
1402
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1403
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1404
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
1405
+ };
1406
+ const promiseResolve = (v) => Promise.resolve(v);
1407
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1408
+ try {
1409
+ new CSSStyleSheet();
1410
+ return typeof new CSSStyleSheet().replaceSync === 'function';
1411
+ }
1412
+ catch (e) { }
1413
+ return false;
1414
+ })()
1415
+ ;
1416
+ const queueDomReads = [];
1417
+ const queueDomWrites = [];
1418
+ const queueTask = (queue, write) => (cb) => {
1419
+ queue.push(cb);
1420
+ if (!queuePending) {
1421
+ queuePending = true;
1422
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1423
+ nextTick(flush);
1424
+ }
1425
+ else {
1426
+ plt.raf(flush);
1427
+ }
1428
+ }
1429
+ };
1430
+ const consume = (queue) => {
1431
+ for (let i = 0; i < queue.length; i++) {
1432
+ try {
1433
+ queue[i](performance.now());
1434
+ }
1435
+ catch (e) {
1436
+ consoleError(e);
1437
+ }
1438
+ }
1439
+ queue.length = 0;
1440
+ };
1441
+ const flush = () => {
1442
+ // always force a bunch of medium callbacks to run, but still have
1443
+ // a throttle on how many can run in a certain time
1444
+ // DOM READS!!!
1445
+ consume(queueDomReads);
1446
+ // DOM WRITES!!!
1447
+ {
1448
+ consume(queueDomWrites);
1449
+ if ((queuePending = queueDomReads.length > 0)) {
1450
+ // still more to do yet, but we've run out of time
1451
+ // let's let this thing cool off and try again in the next tick
1452
+ plt.raf(flush);
1453
+ }
1454
+ }
1455
+ };
1456
+ const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1457
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1458
+
1459
+ exports.bootstrapLazy = bootstrapLazy;
1460
+ exports.createEvent = createEvent;
1461
+ exports.getElement = getElement;
1462
+ exports.h = h;
1463
+ exports.promiseResolve = promiseResolve;
1464
+ exports.registerInstance = registerInstance;
1465
+ exports.setNonce = setNonce;