@salla.sa/twilight 2.0.20 → 2.0.22

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