@haiilo/catalyst 0.0.11 → 0.2.0

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