@sankhyalabs/sankhyablocks 1.3.31-beta.13 → 1.3.31-beta.16

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 (62) hide show
  1. package/dist/cjs/{SnkMessageBuilder-bb55d4c4.js → SnkMessageBuilder-79cf15c5.js} +1 -0
  2. package/dist/cjs/{index-c6671817.js → index-5575fe3d.js} +434 -231
  3. package/dist/cjs/loader.cjs.js +3 -3
  4. package/dist/cjs/sankhyablocks.cjs.js +3 -3
  5. package/dist/cjs/snk-application.cjs.entry.js +60 -2
  6. package/dist/cjs/snk-crud.cjs.entry.js +1 -1
  7. package/dist/cjs/snk-data-unit.cjs.entry.js +3 -3
  8. package/dist/cjs/snk-form_2.cjs.entry.js +2 -2
  9. package/dist/cjs/snk-pesquisa.cjs.entry.js +1 -1
  10. package/dist/cjs/snk-taskbar.cjs.entry.js +2 -2
  11. package/dist/cjs/{taskbar-elements-2888ceb6.js → taskbar-elements-2ae0d005.js} +1 -1
  12. package/dist/cjs/teste-pesquisa.cjs.entry.js +1 -1
  13. package/dist/collection/collection-manifest.json +2 -2
  14. package/dist/collection/components/snk-application/snk-application.js +703 -647
  15. package/dist/collection/components/snk-crud/snk-crud.js +75 -73
  16. package/dist/collection/components/snk-data-unit/snk-data-unit.js +262 -250
  17. package/dist/collection/components/snk-form/snk-form.js +111 -111
  18. package/dist/collection/components/snk-grid/snk-grid.js +93 -92
  19. package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +80 -79
  20. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +1 -2
  21. package/dist/collection/components/snk-taskbar/snk-taskbar.js +128 -116
  22. package/dist/collection/components/teste-pesquisa/teste-pesquisa.js +12 -9
  23. package/dist/collection/lib/http/data-fetcher/fetchers/totals-fetcher.js +47 -0
  24. package/dist/collection/lib/message/resources/snk-data-unit.msg.js +1 -0
  25. package/dist/components/SnkMessageBuilder.js +1 -0
  26. package/dist/components/index.d.ts +8 -5
  27. package/dist/components/index.js +8 -0
  28. package/dist/components/snk-application2.js +59 -0
  29. package/dist/components/snk-data-unit.js +1 -1
  30. package/dist/esm/{SnkMessageBuilder-17d91b88.js → SnkMessageBuilder-3cdde541.js} +1 -0
  31. package/dist/esm/{index-6a83ac96.js → index-cf91f542.js} +434 -231
  32. package/dist/esm/loader.js +3 -3
  33. package/dist/esm/polyfills/css-shim.js +1 -1
  34. package/dist/esm/sankhyablocks.js +3 -3
  35. package/dist/esm/snk-application.entry.js +60 -2
  36. package/dist/esm/snk-crud.entry.js +1 -1
  37. package/dist/esm/snk-data-unit.entry.js +3 -3
  38. package/dist/esm/snk-form_2.entry.js +2 -2
  39. package/dist/esm/snk-pesquisa.entry.js +1 -1
  40. package/dist/esm/snk-taskbar.entry.js +2 -2
  41. package/dist/esm/{taskbar-elements-5ea74223.js → taskbar-elements-bcccc0ff.js} +1 -1
  42. package/dist/esm/teste-pesquisa.entry.js +1 -1
  43. package/dist/sankhyablocks/{p-b7e029cd.entry.js → p-1ba29824.entry.js} +8 -3
  44. package/dist/sankhyablocks/{p-4c7b32d6.entry.js → p-2266555e.entry.js} +1 -1
  45. package/dist/sankhyablocks/p-23c4c94f.js +2 -0
  46. package/dist/sankhyablocks/{p-b559117b.js → p-2454be94.js} +1 -1
  47. package/dist/sankhyablocks/p-49743bc5.js +1 -0
  48. package/dist/sankhyablocks/{p-ce2d1214.entry.js → p-4fa389bd.entry.js} +1 -1
  49. package/dist/sankhyablocks/{p-56a32417.entry.js → p-5327ba05.entry.js} +1 -1
  50. package/dist/sankhyablocks/{p-d25803a1.entry.js → p-7a922fb4.entry.js} +1 -1
  51. package/dist/sankhyablocks/p-92d6f826.entry.js +1 -0
  52. package/dist/sankhyablocks/{p-d25637c9.entry.js → p-bdeef7f2.entry.js} +1 -1
  53. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  54. package/dist/types/components/snk-application/snk-application.d.ts +8 -0
  55. package/dist/types/components.d.ts +5 -1
  56. package/dist/types/lib/http/data-fetcher/fetchers/totals-fetcher.d.ts +8 -0
  57. package/dist/types/stencil-public-runtime.d.ts +15 -4
  58. package/loader/package.json +1 -0
  59. package/package.json +5 -5
  60. package/dist/sankhyablocks/p-ab694dbc.js +0 -1
  61. package/dist/sankhyablocks/p-cd1dc099.js +0 -2
  62. package/dist/sankhyablocks/p-edf81d2c.entry.js +0 -1
@@ -22,6 +22,14 @@ function _interopNamespace(e) {
22
22
 
23
23
  const NAMESPACE = 'sankhyablocks';
24
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
+ */
25
33
  let scopeId;
26
34
  let contentRef;
27
35
  let hostTagName;
@@ -30,28 +38,6 @@ let checkSlotFallbackVisibility = false;
30
38
  let checkSlotRelocate = false;
31
39
  let isSvgMode = false;
32
40
  let queuePending = false;
33
- const win = typeof window !== 'undefined' ? window : {};
34
- const doc = win.document || { head: {} };
35
- const plt = {
36
- $flags$: 0,
37
- $resourcesUrl$: '',
38
- jmp: (h) => h(),
39
- raf: (h) => requestAnimationFrame(h),
40
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
41
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
42
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
43
- };
44
- const promiseResolve = (v) => Promise.resolve(v);
45
- const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
46
- try {
47
- new CSSStyleSheet();
48
- return typeof new CSSStyleSheet().replace === 'function';
49
- }
50
- catch (e) { }
51
- return false;
52
- })()
53
- ;
54
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
55
41
  const createTime = (fnName, tagName = '') => {
56
42
  {
57
43
  return () => {
@@ -66,74 +52,7 @@ const uniqueTime = (key, measureText) => {
66
52
  };
67
53
  }
68
54
  };
69
- const rootAppliedStyles = new WeakMap();
70
- const registerStyle = (scopeId, cssText, allowCS) => {
71
- let style = styles.get(scopeId);
72
- if (supportsConstructibleStylesheets && allowCS) {
73
- style = (style || new CSSStyleSheet());
74
- style.replace(cssText);
75
- }
76
- else {
77
- style = cssText;
78
- }
79
- styles.set(scopeId, style);
80
- };
81
- const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
82
- let scopeId = getScopeId(cmpMeta);
83
- const style = styles.get(scopeId);
84
- // if an element is NOT connected then getRootNode() will return the wrong root node
85
- // so the fallback is to always use the document for the root node in those cases
86
- styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
87
- if (style) {
88
- if (typeof style === 'string') {
89
- styleContainerNode = styleContainerNode.head || styleContainerNode;
90
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
91
- let styleElm;
92
- if (!appliedStyles) {
93
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
94
- }
95
- if (!appliedStyles.has(scopeId)) {
96
- {
97
- {
98
- styleElm = doc.createElement('style');
99
- styleElm.innerHTML = style;
100
- }
101
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
102
- }
103
- if (appliedStyles) {
104
- appliedStyles.add(scopeId);
105
- }
106
- }
107
- }
108
- else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
109
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
110
- }
111
- }
112
- return scopeId;
113
- };
114
- const attachStyles = (hostRef) => {
115
- const cmpMeta = hostRef.$cmpMeta$;
116
- const elm = hostRef.$hostElement$;
117
- const flags = cmpMeta.$flags$;
118
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
119
- const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
120
- if (flags & 10 /* needsScopedEncapsulation */) {
121
- // only required when we're NOT using native shadow dom (slot)
122
- // or this browser doesn't support native shadow dom
123
- // and this host element was NOT created with SSR
124
- // let's pick out the inner content for slot projection
125
- // create a node to represent where the original
126
- // content was first placed, which is useful later on
127
- // DOM WRITE!!
128
- elm['s-sc'] = scopeId;
129
- elm.classList.add(scopeId + '-h');
130
- if (flags & 2 /* scopedCssEncapsulation */) {
131
- elm.classList.add(scopeId + '-s');
132
- }
133
- }
134
- endAttachStyles();
135
- };
136
- const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
55
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
137
56
  /**
138
57
  * Default style mode id
139
58
  */
@@ -243,6 +162,152 @@ const newVNode = (tag, text) => {
243
162
  };
244
163
  const Host = {};
245
164
  const isHost = (node) => node && node.$tag$ === Host;
165
+ /**
166
+ * Parse a new property value for a given property type.
167
+ *
168
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
169
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
170
+ * 1. `any`, the type given to `propValue` in the function signature
171
+ * 2. the type stored from `propType`.
172
+ *
173
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
174
+ *
175
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
176
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
177
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
178
+ * ```tsx
179
+ * <my-cmp prop-val={0}></my-cmp>
180
+ * ```
181
+ *
182
+ * HTML prop values on the other hand, will always a string
183
+ *
184
+ * @param propValue the new value to coerce to some type
185
+ * @param propType the type of the prop, expressed as a binary number
186
+ * @returns the parsed/coerced value
187
+ */
188
+ const parsePropertyValue = (propValue, propType) => {
189
+ // ensure this value is of the correct prop type
190
+ if (propValue != null && !isComplexType(propValue)) {
191
+ if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
192
+ // per the HTML spec, any string value means it is a boolean true value
193
+ // but we'll cheat here and say that the string "false" is the boolean false
194
+ return propValue === 'false' ? false : propValue === '' || !!propValue;
195
+ }
196
+ if (propType & 2 /* MEMBER_FLAGS.Number */) {
197
+ // force it to be a number
198
+ return parseFloat(propValue);
199
+ }
200
+ if (propType & 1 /* MEMBER_FLAGS.String */) {
201
+ // could have been passed as a number or boolean
202
+ // but we still want it as a string
203
+ return String(propValue);
204
+ }
205
+ // redundant return here for better minification
206
+ return propValue;
207
+ }
208
+ // not sure exactly what type we want
209
+ // so no need to change to a different type
210
+ return propValue;
211
+ };
212
+ const getElement = (ref) => (getHostRef(ref).$hostElement$ );
213
+ const createEvent = (ref, name, flags) => {
214
+ const elm = getElement(ref);
215
+ return {
216
+ emit: (detail) => {
217
+ return emitEvent(elm, name, {
218
+ bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
219
+ composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
220
+ cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
221
+ detail,
222
+ });
223
+ },
224
+ };
225
+ };
226
+ /**
227
+ * Helper function to create & dispatch a custom Event on a provided target
228
+ * @param elm the target of the Event
229
+ * @param name the name to give the custom Event
230
+ * @param opts options for configuring a custom Event
231
+ * @returns the custom Event
232
+ */
233
+ const emitEvent = (elm, name, opts) => {
234
+ const ev = plt.ce(name, opts);
235
+ elm.dispatchEvent(ev);
236
+ return ev;
237
+ };
238
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
239
+ const registerStyle = (scopeId, cssText, allowCS) => {
240
+ let style = styles.get(scopeId);
241
+ if (supportsConstructableStylesheets && allowCS) {
242
+ style = (style || new CSSStyleSheet());
243
+ if (typeof style === 'string') {
244
+ style = cssText;
245
+ }
246
+ else {
247
+ style.replaceSync(cssText);
248
+ }
249
+ }
250
+ else {
251
+ style = cssText;
252
+ }
253
+ styles.set(scopeId, style);
254
+ };
255
+ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
256
+ let scopeId = getScopeId(cmpMeta);
257
+ const style = styles.get(scopeId);
258
+ // if an element is NOT connected then getRootNode() will return the wrong root node
259
+ // so the fallback is to always use the document for the root node in those cases
260
+ styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
261
+ if (style) {
262
+ if (typeof style === 'string') {
263
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
264
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
265
+ let styleElm;
266
+ if (!appliedStyles) {
267
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
268
+ }
269
+ if (!appliedStyles.has(scopeId)) {
270
+ {
271
+ {
272
+ styleElm = doc.createElement('style');
273
+ styleElm.innerHTML = style;
274
+ }
275
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
276
+ }
277
+ if (appliedStyles) {
278
+ appliedStyles.add(scopeId);
279
+ }
280
+ }
281
+ }
282
+ else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
283
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
284
+ }
285
+ }
286
+ return scopeId;
287
+ };
288
+ const attachStyles = (hostRef) => {
289
+ const cmpMeta = hostRef.$cmpMeta$;
290
+ const elm = hostRef.$hostElement$;
291
+ const flags = cmpMeta.$flags$;
292
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
293
+ const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
294
+ if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
295
+ // only required when we're NOT using native shadow dom (slot)
296
+ // or this browser doesn't support native shadow dom
297
+ // and this host element was NOT created with SSR
298
+ // let's pick out the inner content for slot projection
299
+ // create a node to represent where the original
300
+ // content was first placed, which is useful later on
301
+ // DOM WRITE!!
302
+ elm['s-sc'] = scopeId;
303
+ elm.classList.add(scopeId + '-h');
304
+ if (flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
305
+ elm.classList.add(scopeId + '-s');
306
+ }
307
+ }
308
+ endAttachStyles();
309
+ };
310
+ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
246
311
  /**
247
312
  * Production setAccessor() function based on Preact by
248
313
  * Jason Miller (@developit)
@@ -337,7 +402,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
337
402
  }
338
403
  }
339
404
  }
340
- else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
405
+ else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
341
406
  newValue = newValue === true ? '' : newValue;
342
407
  {
343
408
  elm.setAttribute(memberName, newValue);
@@ -352,7 +417,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
352
417
  // if the element passed in is a shadow root, which is a document fragment
353
418
  // then we want to be adding attrs/props to the shadow root's "host" element
354
419
  // if it's not a shadow root, then we add attrs/props to the same element
355
- const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
420
+ const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
356
421
  ? newVnode.$elm$.host
357
422
  : newVnode.$elm$;
358
423
  const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
@@ -370,6 +435,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
370
435
  setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
371
436
  }
372
437
  };
438
+ /**
439
+ * Create a DOM Node corresponding to one of the children of a given VNode.
440
+ *
441
+ * @param oldParentVNode the parent VNode from the previous render
442
+ * @param newParentVNode the parent VNode from the current render
443
+ * @param childIndex the index of the VNode, in the _new_ parent node's
444
+ * children, for which we will create a new DOM node
445
+ * @param parentElm the parent DOM node which our new node will be a child of
446
+ * @returns the newly created node
447
+ */
373
448
  const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
374
449
  // tslint:disable-next-line: prefer-const
375
450
  const newVNode = newParentVNode.$children$[childIndex];
@@ -387,23 +462,23 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
387
462
  }
388
463
  newVNode.$flags$ |= newVNode.$children$
389
464
  ? // slot element has fallback content
390
- 2 /* isSlotFallback */
465
+ 2 /* VNODE_FLAGS.isSlotFallback */
391
466
  : // slot element does not have fallback content
392
- 1 /* isSlotReference */;
467
+ 1 /* VNODE_FLAGS.isSlotReference */;
393
468
  }
394
469
  }
395
470
  if (newVNode.$text$ !== null) {
396
471
  // create text node
397
472
  elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
398
473
  }
399
- else if (newVNode.$flags$ & 1 /* isSlotReference */) {
474
+ else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
400
475
  // create a slot reference node
401
476
  elm = newVNode.$elm$ =
402
477
  doc.createTextNode('');
403
478
  }
404
479
  else {
405
480
  // create element
406
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* isSlotFallback */
481
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
407
482
  ? 'slot-fb'
408
483
  : newVNode.$tag$));
409
484
  // add css classes, attrs, props, listeners, etc.
@@ -429,7 +504,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
429
504
  }
430
505
  {
431
506
  elm['s-hn'] = hostTagName;
432
- if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
507
+ if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
433
508
  // remember the content reference comment
434
509
  elm['s-sr'] = true;
435
510
  // remember the content reference comment
@@ -448,7 +523,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
448
523
  return elm;
449
524
  };
450
525
  const putBackInOriginalLocation = (parentElm, recursive) => {
451
- plt.$flags$ |= 1 /* isTmpDisconnected */;
526
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
452
527
  const oldSlotChildNodes = parentElm.childNodes;
453
528
  for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
454
529
  const childNode = oldSlotChildNodes[i];
@@ -469,7 +544,7 @@ const putBackInOriginalLocation = (parentElm, recursive) => {
469
544
  putBackInOriginalLocation(childNode, recursive);
470
545
  }
471
546
  }
472
- plt.$flags$ &= ~1 /* isTmpDisconnected */;
547
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
473
548
  };
474
549
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
475
550
  let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
@@ -511,6 +586,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
511
586
  }
512
587
  }
513
588
  };
589
+ /**
590
+ * Reconcile the children of a new VNode with the children of an old VNode by
591
+ * traversing the two collections of children, identifying nodes that are
592
+ * conserved or changed, calling out to `patch` to make any necessary
593
+ * updates to the DOM, and rearranging DOM nodes as needed.
594
+ *
595
+ * The algorithm for reconciling children works by analyzing two 'windows' onto
596
+ * the two arrays of children (`oldCh` and `newCh`). We keep track of the
597
+ * 'windows' by storing start and end indices and references to the
598
+ * corresponding array entries. Initially the two 'windows' are basically equal
599
+ * to the entire array, but we progressively narrow the windows until there are
600
+ * no children left to update by doing the following:
601
+ *
602
+ * 1. Skip any `null` entries at the beginning or end of the two arrays, so
603
+ * that if we have an initial array like the following we'll end up dealing
604
+ * only with a window bounded by the highlighted elements:
605
+ *
606
+ * [null, null, VNode1 , ... , VNode2, null, null]
607
+ * ^^^^^^ ^^^^^^
608
+ *
609
+ * 2. Check to see if the elements at the head and tail positions are equal
610
+ * across the windows. This will basically detect elements which haven't
611
+ * been added, removed, or changed position, i.e. if you had the following
612
+ * VNode elements (represented as HTML):
613
+ *
614
+ * oldVNode: `<div><p><span>HEY</span></p></div>`
615
+ * newVNode: `<div><p><span>THERE</span></p></div>`
616
+ *
617
+ * Then when comparing the children of the `<div>` tag we check the equality
618
+ * of the VNodes corresponding to the `<p>` tags and, since they are the
619
+ * same tag in the same position, we'd be able to avoid completely
620
+ * re-rendering the subtree under them with a new DOM element and would just
621
+ * call out to `patch` to handle reconciling their children and so on.
622
+ *
623
+ * 3. Check, for both windows, to see if the element at the beginning of the
624
+ * window corresponds to the element at the end of the other window. This is
625
+ * a heuristic which will let us identify _some_ situations in which
626
+ * elements have changed position, for instance it _should_ detect that the
627
+ * children nodes themselves have not changed but merely moved in the
628
+ * following example:
629
+ *
630
+ * oldVNode: `<div><element-one /><element-two /></div>`
631
+ * newVNode: `<div><element-two /><element-one /></div>`
632
+ *
633
+ * If we find cases like this then we also need to move the concrete DOM
634
+ * elements corresponding to the moved children to write the re-order to the
635
+ * DOM.
636
+ *
637
+ * 4. Finally, if VNodes have the `key` attribute set on them we check for any
638
+ * nodes in the old children which have the same key as the first element in
639
+ * our window on the new children. If we find such a node we handle calling
640
+ * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
641
+ * what we find.
642
+ *
643
+ * Finally, once we've narrowed our 'windows' to the point that either of them
644
+ * collapse (i.e. they have length 0) we then handle any remaining VNode
645
+ * insertion or deletion that needs to happen to get a DOM state that correctly
646
+ * reflects the new child VNodes. If, for instance, after our window on the old
647
+ * children has collapsed we still have more nodes on the new children that
648
+ * we haven't dealt with yet then we need to add them, or if the new children
649
+ * collapse but we still have unhandled _old_ children then we need to make
650
+ * sure the corresponding DOM nodes are removed.
651
+ *
652
+ * @param parentElm the node into which the parent VNode is rendered
653
+ * @param oldCh the old children of the parent node
654
+ * @param newVNode the new VNode which will replace the parent
655
+ * @param newCh the new children of the parent node
656
+ */
514
657
  const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
515
658
  let oldStartIdx = 0;
516
659
  let newStartIdx = 0;
@@ -526,7 +669,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
526
669
  let elmToMove;
527
670
  while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
528
671
  if (oldStartVnode == null) {
529
- // Vnode might have been moved left
672
+ // VNode might have been moved left
530
673
  oldStartVnode = oldCh[++oldStartIdx];
531
674
  }
532
675
  else if (oldEndVnode == null) {
@@ -539,37 +682,100 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
539
682
  newEndVnode = newCh[--newEndIdx];
540
683
  }
541
684
  else if (isSameVnode(oldStartVnode, newStartVnode)) {
685
+ // if the start nodes are the same then we should patch the new VNode
686
+ // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
687
+ // indices to reflect that. We don't need to move any DOM Nodes around
688
+ // since things are matched up in order.
542
689
  patch(oldStartVnode, newStartVnode);
543
690
  oldStartVnode = oldCh[++oldStartIdx];
544
691
  newStartVnode = newCh[++newStartIdx];
545
692
  }
546
693
  else if (isSameVnode(oldEndVnode, newEndVnode)) {
694
+ // likewise, if the end nodes are the same we patch new onto old and
695
+ // decrement our end indices, and also likewise in this case we don't
696
+ // need to move any DOM Nodes.
547
697
  patch(oldEndVnode, newEndVnode);
548
698
  oldEndVnode = oldCh[--oldEndIdx];
549
699
  newEndVnode = newCh[--newEndIdx];
550
700
  }
551
701
  else if (isSameVnode(oldStartVnode, newEndVnode)) {
552
- // Vnode moved right
702
+ // case: "Vnode moved right"
703
+ //
704
+ // We've found that the last node in our window on the new children is
705
+ // the same VNode as the _first_ node in our window on the old children
706
+ // we're dealing with now. Visually, this is the layout of these two
707
+ // nodes:
708
+ //
709
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
710
+ // ^^^^^^^^^^^
711
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
712
+ // ^^^^^^^^^^^^^
713
+ //
714
+ // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
715
+ // and move the DOM element for `oldStartVnode`.
553
716
  if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
554
717
  putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
555
718
  }
556
719
  patch(oldStartVnode, newEndVnode);
720
+ // We need to move the element for `oldStartVnode` into a position which
721
+ // will be appropriate for `newEndVnode`. For this we can use
722
+ // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
723
+ // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
724
+ // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
725
+ //
726
+ // <old-start-node />
727
+ // <some-intervening-node />
728
+ // <old-end-node />
729
+ // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
730
+ // <next-sibling />
731
+ //
732
+ // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
733
+ // the node for `oldStartVnode` at the end of the children of
734
+ // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
735
+ // aren't any siblings, and passing `null` to `Node.insertBefore` will
736
+ // append it to the children of the parent element.
557
737
  parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
558
738
  oldStartVnode = oldCh[++oldStartIdx];
559
739
  newEndVnode = newCh[--newEndIdx];
560
740
  }
561
741
  else if (isSameVnode(oldEndVnode, newStartVnode)) {
562
- // Vnode moved left
742
+ // case: "Vnode moved left"
743
+ //
744
+ // We've found that the first node in our window on the new children is
745
+ // the same VNode as the _last_ node in our window on the old children.
746
+ // Visually, this is the layout of these two nodes:
747
+ //
748
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
749
+ // ^^^^^^^^^^^^^
750
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
751
+ // ^^^^^^^^^^^
752
+ //
753
+ // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
754
+ // (which will handle updating any changed attributes, reconciling their
755
+ // children etc) but we also need to move the DOM node to which
756
+ // `oldEndVnode` corresponds.
563
757
  if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
564
758
  putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
565
759
  }
566
760
  patch(oldEndVnode, newStartVnode);
761
+ // We've already checked above if `oldStartVnode` and `newStartVnode` are
762
+ // the same node, so since we're here we know that they are not. Thus we
763
+ // can move the element for `oldEndVnode` _before_ the element for
764
+ // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
765
+ // future.
567
766
  parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
568
767
  oldEndVnode = oldCh[--oldEndIdx];
569
768
  newStartVnode = newCh[++newStartIdx];
570
769
  }
571
770
  else {
572
- // createKeyToOldIdx
771
+ // Here we do some checks to match up old and new nodes based on the
772
+ // `$key$` attribute, which is set by putting a `key="my-key"` attribute
773
+ // in the JSX for a DOM element in the implementation of a Stencil
774
+ // component.
775
+ //
776
+ // First we check to see if there are any nodes in the array of old
777
+ // children which have the same key as the first node in the new
778
+ // children.
573
779
  idxInOld = -1;
574
780
  {
575
781
  for (i = oldStartIdx; i <= oldEndIdx; ++i) {
@@ -580,23 +786,32 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
580
786
  }
581
787
  }
582
788
  if (idxInOld >= 0) {
789
+ // We found a node in the old children which matches up with the first
790
+ // node in the new children! So let's deal with that
583
791
  elmToMove = oldCh[idxInOld];
584
792
  if (elmToMove.$tag$ !== newStartVnode.$tag$) {
793
+ // the tag doesn't match so we'll need a new DOM element
585
794
  node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
586
795
  }
587
796
  else {
588
797
  patch(elmToMove, newStartVnode);
798
+ // invalidate the matching old node so that we won't try to update it
799
+ // again later on
589
800
  oldCh[idxInOld] = undefined;
590
801
  node = elmToMove.$elm$;
591
802
  }
592
803
  newStartVnode = newCh[++newStartIdx];
593
804
  }
594
805
  else {
595
- // new element
806
+ // We either didn't find an element in the old children that matches
807
+ // the key of the first new child OR the build is not using `key`
808
+ // attributes at all. In either case we need to create a new element
809
+ // for the new node.
596
810
  node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
597
811
  newStartVnode = newCh[++newStartIdx];
598
812
  }
599
813
  if (node) {
814
+ // if we created a new node then handle inserting it to the DOM
600
815
  {
601
816
  parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
602
817
  }
@@ -604,21 +819,43 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
604
819
  }
605
820
  }
606
821
  if (oldStartIdx > oldEndIdx) {
822
+ // we have some more new nodes to add which don't match up with old nodes
607
823
  addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
608
824
  }
609
825
  else if (newStartIdx > newEndIdx) {
826
+ // there are nodes in the `oldCh` array which no longer correspond to nodes
827
+ // in the new array, so lets remove them (which entails cleaning up the
828
+ // relevant DOM nodes)
610
829
  removeVnodes(oldCh, oldStartIdx, oldEndIdx);
611
830
  }
612
831
  };
613
- const isSameVnode = (vnode1, vnode2) => {
832
+ /**
833
+ * Compare two VNodes to determine if they are the same
834
+ *
835
+ * **NB**: This function is an equality _heuristic_ based on the available
836
+ * information set on the two VNodes and can be misleading under certain
837
+ * circumstances. In particular, if the two nodes do not have `key` attrs
838
+ * (available under `$key$` on VNodes) then the function falls back on merely
839
+ * checking that they have the same tag.
840
+ *
841
+ * So, in other words, if `key` attrs are not set on VNodes which may be
842
+ * changing order within a `children` array or something along those lines then
843
+ * we could obtain a false positive and then have to do needless re-rendering.
844
+ *
845
+ * @param leftVNode the first VNode to check
846
+ * @param rightVNode the second VNode to check
847
+ * @returns whether they're equal or not
848
+ */
849
+ const isSameVnode = (leftVNode, rightVNode) => {
614
850
  // compare if two vnode to see if they're "technically" the same
615
851
  // need to have the same element tag, and same key to be the same
616
- if (vnode1.$tag$ === vnode2.$tag$) {
617
- if (vnode1.$tag$ === 'slot') {
618
- return vnode1.$name$ === vnode2.$name$;
852
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
853
+ if (leftVNode.$tag$ === 'slot') {
854
+ return leftVNode.$name$ === rightVNode.$name$;
619
855
  }
856
+ // this will be set if components in the build have `key` attrs set on them
620
857
  {
621
- return vnode1.$key$ === vnode2.$key$;
858
+ return leftVNode.$key$ === rightVNode.$key$;
622
859
  }
623
860
  }
624
861
  return false;
@@ -631,6 +868,14 @@ const referenceNode = (node) => {
631
868
  return (node && node['s-ol']) || node;
632
869
  };
633
870
  const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
871
+ /**
872
+ * Handle reconciling an outdated VNode with a new one which corresponds to
873
+ * it. This function handles flushing updates to the DOM and reconciling the
874
+ * children of the two nodes (if any).
875
+ *
876
+ * @param oldVNode an old VNode whose DOM element and children we want to update
877
+ * @param newVNode a new VNode representing an updated version of the old one
878
+ */
634
879
  const patch = (oldVNode, newVNode) => {
635
880
  const elm = (newVNode.$elm$ = oldVNode.$elm$);
636
881
  const oldChildren = oldVNode.$children$;
@@ -639,7 +884,6 @@ const patch = (oldVNode, newVNode) => {
639
884
  const text = newVNode.$text$;
640
885
  let defaultHolder;
641
886
  if (text === null) {
642
- // element node
643
887
  {
644
888
  if (tag === 'slot')
645
889
  ;
@@ -652,6 +896,7 @@ const patch = (oldVNode, newVNode) => {
652
896
  }
653
897
  if (oldChildren !== null && newChildren !== null) {
654
898
  // looks like there's child vnodes for both the old and new vnodes
899
+ // so we need to call `updateChildren` to reconcile them
655
900
  updateChildren(elm, oldChildren, newVNode, newChildren);
656
901
  }
657
902
  else if (newChildren !== null) {
@@ -689,7 +934,7 @@ const updateFallbackSlotVisibility = (elm) => {
689
934
  let nodeType;
690
935
  for (i = 0, ilen = childNodes.length; i < ilen; i++) {
691
936
  childNode = childNodes[i];
692
- if (childNode.nodeType === 1 /* ElementNode */) {
937
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
693
938
  if (childNode['s-sr']) {
694
939
  // this is a slot fallback node
695
940
  // get the slot name for this slot reference node
@@ -701,7 +946,7 @@ const updateFallbackSlotVisibility = (elm) => {
701
946
  nodeType = childNodes[j].nodeType;
702
947
  if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
703
948
  // this sibling node is from a different component OR is a named fallback slot node
704
- if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
949
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
705
950
  childNode.hidden = true;
706
951
  break;
707
952
  }
@@ -710,8 +955,8 @@ const updateFallbackSlotVisibility = (elm) => {
710
955
  // this is a default fallback slot node
711
956
  // any element or text node (with content)
712
957
  // should hide the default fallback slot node
713
- if (nodeType === 1 /* ElementNode */ ||
714
- (nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
958
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
959
+ (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
715
960
  childNode.hidden = true;
716
961
  break;
717
962
  }
@@ -789,13 +1034,13 @@ const relocateSlotContent = (elm) => {
789
1034
  }
790
1035
  }
791
1036
  }
792
- if (childNode.nodeType === 1 /* ElementNode */) {
1037
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
793
1038
  relocateSlotContent(childNode);
794
1039
  }
795
1040
  }
796
1041
  };
797
1042
  const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
798
- if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1043
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
799
1044
  if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
800
1045
  return true;
801
1046
  }
@@ -822,7 +1067,7 @@ const renderVdom = (hostRef, renderFnResults) => {
822
1067
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
823
1068
  hostTagName = hostElm.tagName;
824
1069
  rootVnode.$tag$ = null;
825
- rootVnode.$flags$ |= 4 /* isHost */;
1070
+ rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
826
1071
  hostRef.$vnode$ = rootVnode;
827
1072
  rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
828
1073
  {
@@ -830,7 +1075,7 @@ const renderVdom = (hostRef, renderFnResults) => {
830
1075
  }
831
1076
  {
832
1077
  contentRef = hostElm['s-cr'];
833
- useNativeShadowDom = (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
1078
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
834
1079
  // always reset
835
1080
  checkSlotFallbackVisibility = false;
836
1081
  }
@@ -839,7 +1084,7 @@ const renderVdom = (hostRef, renderFnResults) => {
839
1084
  {
840
1085
  // while we're moving nodes around existing nodes, temporarily disable
841
1086
  // the disconnectCallback from working
842
- plt.$flags$ |= 1 /* isTmpDisconnected */;
1087
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
843
1088
  if (checkSlotRelocate) {
844
1089
  relocateSlotContent(rootVnode.$elm$);
845
1090
  let relocateData;
@@ -897,7 +1142,7 @@ const renderVdom = (hostRef, renderFnResults) => {
897
1142
  }
898
1143
  else {
899
1144
  // this node doesn't have a slot home to go to, so let's hide it
900
- if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1145
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
901
1146
  nodeToRelocate.hidden = true;
902
1147
  }
903
1148
  }
@@ -908,37 +1153,11 @@ const renderVdom = (hostRef, renderFnResults) => {
908
1153
  }
909
1154
  // done moving nodes around
910
1155
  // allow the disconnect callback to work again
911
- plt.$flags$ &= ~1 /* isTmpDisconnected */;
1156
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
912
1157
  // always reset
913
1158
  relocateNodes.length = 0;
914
1159
  }
915
1160
  };
916
- const getElement = (ref) => (getHostRef(ref).$hostElement$ );
917
- const createEvent = (ref, name, flags) => {
918
- const elm = getElement(ref);
919
- return {
920
- emit: (detail) => {
921
- return emitEvent(elm, name, {
922
- bubbles: !!(flags & 4 /* Bubbles */),
923
- composed: !!(flags & 2 /* Composed */),
924
- cancelable: !!(flags & 1 /* Cancellable */),
925
- detail,
926
- });
927
- },
928
- };
929
- };
930
- /**
931
- * Helper function to create & dispatch a custom Event on a provided target
932
- * @param elm the target of the Event
933
- * @param name the name to give the custom Event
934
- * @param opts options for configuring a custom Event
935
- * @returns the custom Event
936
- */
937
- const emitEvent = (elm, name, opts) => {
938
- const ev = plt.ce(name, opts);
939
- elm.dispatchEvent(ev);
940
- return ev;
941
- };
942
1161
  const attachToAncestor = (hostRef, ancestorComponent) => {
943
1162
  if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
944
1163
  ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
@@ -946,10 +1165,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
946
1165
  };
947
1166
  const scheduleUpdate = (hostRef, isInitialLoad) => {
948
1167
  {
949
- hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
1168
+ hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
950
1169
  }
951
- if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
952
- hostRef.$flags$ |= 512 /* needsRerender */;
1170
+ if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1171
+ hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
953
1172
  return;
954
1173
  }
955
1174
  attachToAncestor(hostRef, hostRef.$ancestorComponent$);
@@ -1004,7 +1223,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1004
1223
  }
1005
1224
  else {
1006
1225
  Promise.all(childrenPromises).then(postUpdate);
1007
- hostRef.$flags$ |= 4 /* isWaitingForChildren */;
1226
+ hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1008
1227
  childrenPromises.length = 0;
1009
1228
  }
1010
1229
  }
@@ -1013,10 +1232,10 @@ const callRender = (hostRef, instance, elm) => {
1013
1232
  try {
1014
1233
  instance = instance.render() ;
1015
1234
  {
1016
- hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
1235
+ hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1017
1236
  }
1018
1237
  {
1019
- hostRef.$flags$ |= 2 /* hasRendered */;
1238
+ hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1020
1239
  }
1021
1240
  {
1022
1241
  {
@@ -1040,8 +1259,8 @@ const postUpdateComponent = (hostRef) => {
1040
1259
  const endPostUpdate = createTime('postUpdate', tagName);
1041
1260
  const instance = hostRef.$lazyInstance$ ;
1042
1261
  const ancestorComponent = hostRef.$ancestorComponent$;
1043
- if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
1044
- hostRef.$flags$ |= 64 /* hasLoadedComponent */;
1262
+ if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1263
+ hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1045
1264
  {
1046
1265
  // DOM WRITE!
1047
1266
  addHydratedFlag(elm);
@@ -1070,10 +1289,10 @@ const postUpdateComponent = (hostRef) => {
1070
1289
  hostRef.$onRenderResolve$();
1071
1290
  hostRef.$onRenderResolve$ = undefined;
1072
1291
  }
1073
- if (hostRef.$flags$ & 512 /* needsRerender */) {
1292
+ if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1074
1293
  nextTick(() => scheduleUpdate(hostRef, false));
1075
1294
  }
1076
- hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
1295
+ hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1077
1296
  }
1078
1297
  // ( •_•)
1079
1298
  // ( •_•)>⌐■-■
@@ -1103,53 +1322,6 @@ const then = (promise, thenFn) => {
1103
1322
  };
1104
1323
  const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1105
1324
  ;
1106
- /**
1107
- * Parse a new property value for a given property type.
1108
- *
1109
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
1110
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
1111
- * 1. `any`, the type given to `propValue` in the function signature
1112
- * 2. the type stored from `propType`.
1113
- *
1114
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
1115
- *
1116
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
1117
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
1118
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
1119
- * ```tsx
1120
- * <my-cmp prop-val={0}></my-cmp>
1121
- * ```
1122
- *
1123
- * HTML prop values on the other hand, will always a string
1124
- *
1125
- * @param propValue the new value to coerce to some type
1126
- * @param propType the type of the prop, expressed as a binary number
1127
- * @returns the parsed/coerced value
1128
- */
1129
- const parsePropertyValue = (propValue, propType) => {
1130
- // ensure this value is of the correct prop type
1131
- if (propValue != null && !isComplexType(propValue)) {
1132
- if (propType & 4 /* Boolean */) {
1133
- // per the HTML spec, any string value means it is a boolean true value
1134
- // but we'll cheat here and say that the string "false" is the boolean false
1135
- return propValue === 'false' ? false : propValue === '' || !!propValue;
1136
- }
1137
- if (propType & 2 /* Number */) {
1138
- // force it to be a number
1139
- return parseFloat(propValue);
1140
- }
1141
- if (propType & 1 /* String */) {
1142
- // could have been passed as a number or boolean
1143
- // but we still want it as a string
1144
- return String(propValue);
1145
- }
1146
- // redundant return here for better minification
1147
- return propValue;
1148
- }
1149
- // not sure exactly what type we want
1150
- // so no need to change to a different type
1151
- return propValue;
1152
- };
1153
1325
  const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1154
1326
  const setValue = (ref, propName, newVal, cmpMeta) => {
1155
1327
  // check our new property value against our internal value
@@ -1162,13 +1334,13 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
1162
1334
  // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1163
1335
  const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1164
1336
  const didValueChange = newVal !== oldVal && !areBothNaN;
1165
- if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1337
+ if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1166
1338
  // gadzooks! the property's value has changed!!
1167
1339
  // set our new value!
1168
1340
  hostRef.$instanceValues$.set(propName, newVal);
1169
1341
  if (instance) {
1170
1342
  // get an array of method names of watch functions to call
1171
- if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
1343
+ if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
1172
1344
  const watchMethods = cmpMeta.$watchers$[propName];
1173
1345
  if (watchMethods) {
1174
1346
  // this instance is watching for when this property changed
@@ -1183,7 +1355,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
1183
1355
  });
1184
1356
  }
1185
1357
  }
1186
- if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1358
+ if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1187
1359
  // looks like this value actually changed, so we've got work to do!
1188
1360
  // but only if we've already rendered, otherwise just chill out
1189
1361
  // queue that we need to do an update, but don't worry about queuing
@@ -1193,6 +1365,16 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
1193
1365
  }
1194
1366
  }
1195
1367
  };
1368
+ /**
1369
+ * Attach a series of runtime constructs to a compiled Stencil component
1370
+ * constructor, including getters and setters for the `@Prop` and `@State`
1371
+ * decorators, callbacks for when attributes change, and so on.
1372
+ *
1373
+ * @param Cstr the constructor for a component that we need to process
1374
+ * @param cmpMeta metadata collected previously about the component
1375
+ * @param flags a number used to store a series of bit flags
1376
+ * @returns a reference to the same constructor passed in (but now mutated)
1377
+ */
1196
1378
  const proxyComponent = (Cstr, cmpMeta, flags) => {
1197
1379
  if (cmpMeta.$members$) {
1198
1380
  if (Cstr.watchers) {
@@ -1202,8 +1384,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1202
1384
  const members = Object.entries(cmpMeta.$members$);
1203
1385
  const prototype = Cstr.prototype;
1204
1386
  members.map(([memberName, [memberFlags]]) => {
1205
- if ((memberFlags & 31 /* Prop */ ||
1206
- ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
1387
+ if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1388
+ ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1207
1389
  // proxyComponent - prop
1208
1390
  Object.defineProperty(prototype, memberName, {
1209
1391
  get() {
@@ -1218,8 +1400,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1218
1400
  enumerable: true,
1219
1401
  });
1220
1402
  }
1221
- else if (flags & 1 /* isElementConstructor */ &&
1222
- memberFlags & 64 /* Method */) {
1403
+ else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
1404
+ memberFlags & 64 /* MEMBER_FLAGS.Method */) {
1223
1405
  // proxyComponent - method
1224
1406
  Object.defineProperty(prototype, memberName, {
1225
1407
  value(...args) {
@@ -1229,7 +1411,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1229
1411
  });
1230
1412
  }
1231
1413
  });
1232
- if ((flags & 1 /* isElementConstructor */)) {
1414
+ if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1233
1415
  const attrNameToPropName = new Map();
1234
1416
  prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1235
1417
  plt.jmp(() => {
@@ -1285,7 +1467,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1285
1467
  // create an array of attributes to observe
1286
1468
  // and also create a map of html attribute name to js property name
1287
1469
  Cstr.observedAttributes = members
1288
- .filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
1470
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
1289
1471
  .map(([propName, m]) => {
1290
1472
  const attrName = m[1] || propName;
1291
1473
  attrNameToPropName.set(attrName, propName);
@@ -1297,10 +1479,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1297
1479
  };
1298
1480
  const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1299
1481
  // initializeComponent
1300
- if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
1482
+ if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1301
1483
  {
1302
1484
  // we haven't initialized this element yet
1303
- hostRef.$flags$ |= 32 /* hasInitializedComponent */;
1485
+ hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1304
1486
  // lazy loaded components
1305
1487
  // request the component's implementation to be
1306
1488
  // wired up with the host element
@@ -1318,7 +1500,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
1318
1500
  {
1319
1501
  cmpMeta.$watchers$ = Cstr.watchers;
1320
1502
  }
1321
- proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
1503
+ proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1322
1504
  Cstr.isProxied = true;
1323
1505
  }
1324
1506
  const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
@@ -1326,7 +1508,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
1326
1508
  // but let's keep track of when we start and stop
1327
1509
  // so that the getters/setters don't incorrectly step on data
1328
1510
  {
1329
- hostRef.$flags$ |= 8 /* isConstructingInstance */;
1511
+ hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1330
1512
  }
1331
1513
  // construct the lazy-loaded component implementation
1332
1514
  // passing the hostRef is very important during
@@ -1339,10 +1521,10 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
1339
1521
  consoleError(e);
1340
1522
  }
1341
1523
  {
1342
- hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1524
+ hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1343
1525
  }
1344
1526
  {
1345
- hostRef.$flags$ |= 128 /* isWatchReady */;
1527
+ hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
1346
1528
  }
1347
1529
  endNewInstance();
1348
1530
  fireConnectedCallback(hostRef.$lazyInstance$);
@@ -1353,7 +1535,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
1353
1535
  const scopeId = getScopeId(cmpMeta);
1354
1536
  if (!styles.has(scopeId)) {
1355
1537
  const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1356
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1538
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1357
1539
  endRegisterStyles();
1358
1540
  }
1359
1541
  }
@@ -1380,19 +1562,19 @@ const fireConnectedCallback = (instance) => {
1380
1562
  }
1381
1563
  };
1382
1564
  const connectedCallback = (elm) => {
1383
- if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1565
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1384
1566
  const hostRef = getHostRef(elm);
1385
1567
  const cmpMeta = hostRef.$cmpMeta$;
1386
1568
  const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1387
- if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
1569
+ if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1388
1570
  // first time this component has connected
1389
- hostRef.$flags$ |= 1 /* hasConnected */;
1571
+ hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1390
1572
  {
1391
1573
  // initUpdate
1392
1574
  // if the slot polyfill is required we'll need to put some nodes
1393
1575
  // in here to act as original content anchors as we move nodes around
1394
1576
  // host element has been connected to the DOM
1395
- if ((cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
1577
+ if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
1396
1578
  setContentReference(elm);
1397
1579
  }
1398
1580
  }
@@ -1415,7 +1597,7 @@ const connectedCallback = (elm) => {
1415
1597
  // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1416
1598
  if (cmpMeta.$members$) {
1417
1599
  Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1418
- if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
1600
+ if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1419
1601
  const value = elm[memberName];
1420
1602
  delete elm[memberName];
1421
1603
  elm[memberName] = value;
@@ -1445,7 +1627,7 @@ const setContentReference = (elm) => {
1445
1627
  elm.insertBefore(contentRefElm, elm.firstChild);
1446
1628
  };
1447
1629
  const disconnectedCallback = (elm) => {
1448
- if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1630
+ if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1449
1631
  const hostRef = getHostRef(elm);
1450
1632
  const instance = hostRef.$lazyInstance$ ;
1451
1633
  {
@@ -1488,7 +1670,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1488
1670
  super(self);
1489
1671
  self = this;
1490
1672
  registerHost(self, cmpMeta);
1491
- if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
1673
+ if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1492
1674
  // this component is using shadow dom
1493
1675
  // and this browser supports shadow dom
1494
1676
  // add the read-only property "shadowRoot" to the host element
@@ -1523,7 +1705,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1523
1705
  cmpMeta.$lazyBundleId$ = lazyBundle[0];
1524
1706
  if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1525
1707
  cmpTags.push(tagName);
1526
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
1708
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1527
1709
  }
1528
1710
  });
1529
1711
  });
@@ -1545,7 +1727,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1545
1727
  // Fallback appLoad event
1546
1728
  endBootstrap();
1547
1729
  };
1548
- const hostRefs = new WeakMap();
1730
+ const hostRefs = /*@__PURE__*/ new WeakMap();
1549
1731
  const getHostRef = (ref) => hostRefs.get(ref);
1550
1732
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1551
1733
  const registerHost = (elm, cmpMeta) => {
@@ -1589,14 +1771,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1589
1771
  return importedModule[exportName];
1590
1772
  }, consoleError);
1591
1773
  };
1592
- const styles = new Map();
1774
+ const styles = /*@__PURE__*/ new Map();
1775
+ const win = typeof window !== 'undefined' ? window : {};
1776
+ const doc = win.document || { head: {} };
1777
+ const plt = {
1778
+ $flags$: 0,
1779
+ $resourcesUrl$: '',
1780
+ jmp: (h) => h(),
1781
+ raf: (h) => requestAnimationFrame(h),
1782
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1783
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1784
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
1785
+ };
1786
+ const promiseResolve = (v) => Promise.resolve(v);
1787
+ const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1788
+ try {
1789
+ new CSSStyleSheet();
1790
+ return typeof new CSSStyleSheet().replaceSync === 'function';
1791
+ }
1792
+ catch (e) { }
1793
+ return false;
1794
+ })()
1795
+ ;
1593
1796
  const queueDomReads = [];
1594
1797
  const queueDomWrites = [];
1595
1798
  const queueTask = (queue, write) => (cb) => {
1596
1799
  queue.push(cb);
1597
1800
  if (!queuePending) {
1598
1801
  queuePending = true;
1599
- if (write && plt.$flags$ & 4 /* queueSync */) {
1802
+ if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1600
1803
  nextTick(flush);
1601
1804
  }
1602
1805
  else {