UNPKG

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