UNPKG

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