@salla.sa/twilight-components 1.0.12 → 1.0.13

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