@salla.sa/twilight-components 1.0.3 → 1.0.5

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