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