@salla.sa/twilight-components 1.0.5 → 1.0.6

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