@everymatrix/general-styling-wrapper 1.31.2 → 1.32.4

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