pushfeedback 0.0.1

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