UNPKG

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