UNPKG

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