UNPKG

121 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';
23const BUILD = /* bulmil */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: true, attachStyles: true, cloneNodeFix: false, cmpDidLoad: false, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: false, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, cssVarShim: true, devTools: false, disconnectedCallback: false, dynamicImportShim: true, element: false, event: false, hasRenderFn: true, hostListener: false, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: false, hydrateClientSide: true, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: true, isDebug: false, isDev: true, isTesting: true, lazyLoad: true, lifecycle: false, lifecycleDOMEvents: true, member: true, method: false, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, safari10: true, scoped: false, scriptDataOpts: true, shadowDelegatesFocus: false, shadowDom: false, shadowDomShim: true, slot: true, slotChildNodesFix: false, slotRelocation: true, state: false, style: true, svg: false, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: false, vdomListener: true, vdomPropOrAttr: true, vdomRef: false, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: false };
24
25let scopeId;
26let contentRef;
27let hostTagName;
28let i = 0;
29let useNativeShadowDom = false;
30let checkSlotFallbackVisibility = false;
31let checkSlotRelocate = false;
32let isSvgMode = false;
33let renderingRef = null;
34let queueCongestion = 0;
35let queuePending = false;
36const win = typeof window !== 'undefined' ? window : {};
37const CSS = BUILD.cssVarShim ? win.CSS : null;
38const doc = win.document || { head: {} };
39const H = (win.HTMLElement || class {
40});
41const plt = {
42 $flags$: 0,
43 $resourcesUrl$: '',
44 jmp: h => h(),
45 raf: h => requestAnimationFrame(h),
46 ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
47 rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
48};
49const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)() : true;
50const supportsListenerOptions = /*@__PURE__*/ (() => {
51 let supportsListenerOptions = false;
52 try {
53 doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
54 get() {
55 supportsListenerOptions = true;
56 },
57 }));
58 }
59 catch (e) { }
60 return supportsListenerOptions;
61})();
62const promiseResolve = (v) => Promise.resolve(v);
63const supportsConstructibleStylesheets = BUILD.constructableCSS
64 ? /*@__PURE__*/ (() => {
65 try {
66 new CSSStyleSheet();
67 return true;
68 }
69 catch (e) { }
70 return false;
71 })()
72 : false;
73const Context = {};
74const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
75 if (BUILD.hostListener && listeners) {
76 // this is called immediately within the element's constructor
77 // initialize our event listeners on the host element
78 // we do this now so that we can listen to events that may
79 // have fired even before the instance is ready
80 if (BUILD.hostListenerTargetParent) {
81 // this component may have event listeners that should be attached to the parent
82 if (attachParentListeners) {
83 // this is being ran from within the connectedCallback
84 // which is important so that we know the host element actually has a parent element
85 // filter out the listeners to only have the ones that ARE being attached to the parent
86 listeners = listeners.filter(([flags]) => flags & 16 /* TargetParent */);
87 }
88 else {
89 // this is being ran from within the component constructor
90 // everything BUT the parent element listeners should be attached at this time
91 // filter out the listeners that are NOT being attached to the parent
92 listeners = listeners.filter(([flags]) => !(flags & 16 /* TargetParent */));
93 }
94 }
95 listeners.map(([flags, name, method]) => {
96 const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
97 const handler = hostListenerProxy(hostRef, method);
98 const opts = hostListenerOpts(flags);
99 plt.ael(target, name, handler, opts);
100 (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
101 });
102 }
103};
104const hostListenerProxy = (hostRef, methodName) => (ev) => {
105 if (BUILD.lazyLoad) {
106 if (hostRef.$flags$ & 256 /* isListenReady */) {
107 // instance is ready, let's call it's member method for this event
108 hostRef.$lazyInstance$[methodName](ev);
109 }
110 else {
111 (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
112 }
113 }
114 else {
115 hostRef.$hostElement$[methodName](ev);
116 }
117};
118const getHostListenerTarget = (elm, flags) => {
119 if (BUILD.hostListenerTargetDocument && flags & 4 /* TargetDocument */)
120 return doc;
121 if (BUILD.hostListenerTargetWindow && flags & 8 /* TargetWindow */)
122 return win;
123 if (BUILD.hostListenerTargetBody && flags & 32 /* TargetBody */)
124 return doc.body;
125 if (BUILD.hostListenerTargetParent && flags & 16 /* TargetParent */)
126 return elm.parentElement;
127 return elm;
128};
129// prettier-ignore
130const hostListenerOpts = (flags) => supportsListenerOptions
131 ? ({
132 passive: (flags & 1 /* Passive */) !== 0,
133 capture: (flags & 2 /* Capture */) !== 0,
134 })
135 : (flags & 2 /* Capture */) !== 0;
136const CONTENT_REF_ID = 'r';
137const ORG_LOCATION_ID = 'o';
138const SLOT_NODE_ID = 's';
139const TEXT_NODE_ID = 't';
140const HYDRATE_ID = 's-id';
141const HYDRATED_STYLE_ID = 'sty-id';
142const HYDRATE_CHILD_ID = 'c-id';
143const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
144const XLINK_NS = 'http://www.w3.org/1999/xlink';
145const createTime = (fnName, tagName = '') => {
146 if (BUILD.profile && performance.mark) {
147 const key = `st:${fnName}:${tagName}:${i++}`;
148 // Start
149 performance.mark(key);
150 // End
151 return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
152 }
153 else {
154 return () => {
155 return;
156 };
157 }
158};
159const uniqueTime = (key, measureText) => {
160 if (BUILD.profile && performance.mark) {
161 if (performance.getEntriesByName(key).length === 0) {
162 performance.mark(key);
163 }
164 return () => {
165 if (performance.getEntriesByName(measureText).length === 0) {
166 performance.measure(measureText, key);
167 }
168 };
169 }
170 else {
171 return () => {
172 return;
173 };
174 }
175};
176const inspect = (ref) => {
177 const hostRef = getHostRef(ref);
178 if (!hostRef) {
179 return undefined;
180 }
181 const flags = hostRef.$flags$;
182 const hostElement = hostRef.$hostElement$;
183 return {
184 renderCount: hostRef.$renderCount$,
185 flags: {
186 hasRendered: !!(flags & 2 /* hasRendered */),
187 hasConnected: !!(flags & 1 /* hasConnected */),
188 isWaitingForChildren: !!(flags & 4 /* isWaitingForChildren */),
189 isConstructingInstance: !!(flags & 8 /* isConstructingInstance */),
190 isQueuedForUpdate: !!(flags & 16 /* isQueuedForUpdate */),
191 hasInitializedComponent: !!(flags & 32 /* hasInitializedComponent */),
192 hasLoadedComponent: !!(flags & 64 /* hasLoadedComponent */),
193 isWatchReady: !!(flags & 128 /* isWatchReady */),
194 isListenReady: !!(flags & 256 /* isListenReady */),
195 needsRerender: !!(flags & 512 /* needsRerender */),
196 },
197 instanceValues: hostRef.$instanceValues$,
198 ancestorComponent: hostRef.$ancestorComponent$,
199 hostElement,
200 lazyInstance: hostRef.$lazyInstance$,
201 vnode: hostRef.$vnode$,
202 modeName: hostRef.$modeName$,
203 onReadyPromise: hostRef.$onReadyPromise$,
204 onReadyResolve: hostRef.$onReadyResolve$,
205 onInstancePromise: hostRef.$onInstancePromise$,
206 onInstanceResolve: hostRef.$onInstanceResolve$,
207 onRenderResolve: hostRef.$onRenderResolve$,
208 queuedListeners: hostRef.$queuedListeners$,
209 rmListeners: hostRef.$rmListeners$,
210 ['s-id']: hostElement['s-id'],
211 ['s-cr']: hostElement['s-cr'],
212 ['s-lr']: hostElement['s-lr'],
213 ['s-p']: hostElement['s-p'],
214 ['s-rc']: hostElement['s-rc'],
215 ['s-sc']: hostElement['s-sc'],
216 };
217};
218const installDevTools = () => {
219 if (BUILD.devTools) {
220 const stencil = (win.stencil = win.stencil || {});
221 const originalInspect = stencil.inspect;
222 stencil.inspect = (ref) => {
223 let result = inspect(ref);
224 if (!result && typeof originalInspect === 'function') {
225 result = originalInspect(ref);
226 }
227 return result;
228 };
229 }
230};
231const rootAppliedStyles = new WeakMap();
232const registerStyle = (scopeId, cssText, allowCS) => {
233 let style = styles.get(scopeId);
234 if (supportsConstructibleStylesheets && allowCS) {
235 style = (style || new CSSStyleSheet());
236 style.replace(cssText);
237 }
238 else {
239 style = cssText;
240 }
241 styles.set(scopeId, style);
242};
243const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
244 let scopeId = getScopeId(cmpMeta, mode);
245 let style = styles.get(scopeId);
246 if (!BUILD.attachStyles) {
247 return scopeId;
248 }
249 // if an element is NOT connected then getRootNode() will return the wrong root node
250 // so the fallback is to always use the document for the root node in those cases
251 styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
252 if (style) {
253 if (typeof style === 'string') {
254 styleContainerNode = styleContainerNode.head || styleContainerNode;
255 let appliedStyles = rootAppliedStyles.get(styleContainerNode);
256 let styleElm;
257 if (!appliedStyles) {
258 rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
259 }
260 if (!appliedStyles.has(scopeId)) {
261 if (BUILD.hydrateClientSide && styleContainerNode.host && (styleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`))) {
262 // This is only happening on native shadow-dom, do not needs CSS var shim
263 styleElm.innerHTML = style;
264 }
265 else {
266 if (BUILD.cssVarShim && plt.$cssShim$) {
267 styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
268 const newScopeId = styleElm['s-sc'];
269 if (newScopeId) {
270 scopeId = newScopeId;
271 // we don't want to add this styleID to the appliedStyles Set
272 // since the cssVarShim might need to apply several different
273 // stylesheets for the same component
274 appliedStyles = null;
275 }
276 }
277 else {
278 styleElm = doc.createElement('style');
279 styleElm.innerHTML = style;
280 }
281 if (BUILD.hydrateServerSide || BUILD.hotModuleReplacement) {
282 styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
283 }
284 styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
285 }
286 if (appliedStyles) {
287 appliedStyles.add(scopeId);
288 }
289 }
290 }
291 else if (BUILD.constructableCSS && !styleContainerNode.adoptedStyleSheets.includes(style)) {
292 styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
293 }
294 }
295 return scopeId;
296};
297const attachStyles = (hostRef) => {
298 const cmpMeta = hostRef.$cmpMeta$;
299 const elm = hostRef.$hostElement$;
300 const flags = cmpMeta.$flags$;
301 const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
302 const scopeId = addStyle(BUILD.shadowDom && supportsShadow && elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
303 if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & 10 /* needsScopedEncapsulation */) {
304 // only required when we're NOT using native shadow dom (slot)
305 // or this browser doesn't support native shadow dom
306 // and this host element was NOT created with SSR
307 // let's pick out the inner content for slot projection
308 // create a node to represent where the original
309 // content was first placed, which is useful later on
310 // DOM WRITE!!
311 elm['s-sc'] = scopeId;
312 elm.classList.add(scopeId + '-h');
313 if (BUILD.scoped && flags & 2 /* scopedCssEncapsulation */) {
314 elm.classList.add(scopeId + '-s');
315 }
316 }
317 endAttachStyles();
318};
319const getScopeId = (cmp, mode) => 'sc-' + (BUILD.mode && mode && cmp.$flags$ & 32 /* hasMode */ ? cmp.$tagName$ + '-' + mode : cmp.$tagName$);
320const convertScopedToShadow = (css) => css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{');
321// Private
322const computeMode = (elm) => modeResolutionChain.map(h => h(elm)).find(m => !!m);
323// Public
324const setMode = (handler) => modeResolutionChain.push(handler);
325const getMode = (ref) => getHostRef(ref).$modeName$;
326/**
327 * Default style mode id
328 */
329/**
330 * Reusable empty obj/array
331 * Don't add values to these!!
332 */
333const EMPTY_OBJ = {};
334/**
335 * Namespaces
336 */
337const SVG_NS = 'http://www.w3.org/2000/svg';
338const HTML_NS = 'http://www.w3.org/1999/xhtml';
339const isDef = (v) => v != null;
340const isComplexType = (o) => {
341 // https://jsperf.com/typeof-fn-object/5
342 o = typeof o;
343 return o === 'object' || o === 'function';
344};
345/**
346 * Production h() function based on Preact by
347 * Jason Miller (@developit)
348 * Licensed under the MIT License
349 * https://github.com/developit/preact/blob/master/LICENSE
350 *
351 * Modified for Stencil's compiler and vdom
352 */
353// const stack: any[] = [];
354// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
355// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
356const h = (nodeName, vnodeData, ...children) => {
357 let child = null;
358 let key = null;
359 let slotName = null;
360 let simple = false;
361 let lastSimple = false;
362 let vNodeChildren = [];
363 const walk = (c) => {
364 for (let i = 0; i < c.length; i++) {
365 child = c[i];
366 if (Array.isArray(child)) {
367 walk(child);
368 }
369 else if (child != null && typeof child !== 'boolean') {
370 if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
371 child = String(child);
372 }
373 else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
374 consoleDevError(`vNode passed as children has unexpected type.
375Make sure it's using the correct h() function.
376Empty objects can also be the cause, look for JSX comments that became objects.`);
377 }
378 if (simple && lastSimple) {
379 // If the previous child was simple (string), we merge both
380 vNodeChildren[vNodeChildren.length - 1].$text$ += child;
381 }
382 else {
383 // Append a new vNode, if it's text, we create a text vNode
384 vNodeChildren.push(simple ? newVNode(null, child) : child);
385 }
386 lastSimple = simple;
387 }
388 }
389 };
390 walk(children);
391 if (vnodeData) {
392 if (BUILD.isDev && nodeName === 'input') {
393 validateInputProperties(vnodeData);
394 }
395 // normalize class / classname attributes
396 if (BUILD.vdomKey && vnodeData.key) {
397 key = vnodeData.key;
398 }
399 if (BUILD.slotRelocation && vnodeData.name) {
400 slotName = vnodeData.name;
401 }
402 if (BUILD.vdomClass) {
403 const classData = vnodeData.className || vnodeData.class;
404 if (classData) {
405 vnodeData.class =
406 typeof classData !== 'object'
407 ? classData
408 : Object.keys(classData)
409 .filter(k => classData[k])
410 .join(' ');
411 }
412 }
413 }
414 if (BUILD.isDev && vNodeChildren.some(isHost)) {
415 consoleDevError(`The <Host> must be the single root component. Make sure:
416- You are NOT using hostData() and <Host> in the same component.
417- <Host> is used once, and it's the single root component of the render() function.`);
418 }
419 if (BUILD.vdomFunctional && typeof nodeName === 'function') {
420 // nodeName is a functional component
421 return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
422 }
423 const vnode = newVNode(nodeName, null);
424 vnode.$attrs$ = vnodeData;
425 if (vNodeChildren.length > 0) {
426 vnode.$children$ = vNodeChildren;
427 }
428 if (BUILD.vdomKey) {
429 vnode.$key$ = key;
430 }
431 if (BUILD.slotRelocation) {
432 vnode.$name$ = slotName;
433 }
434 return vnode;
435};
436const newVNode = (tag, text) => {
437 const vnode = {
438 $flags$: 0,
439 $tag$: tag,
440 $text$: text,
441 $elm$: null,
442 $children$: null,
443 };
444 if (BUILD.vdomAttribute) {
445 vnode.$attrs$ = null;
446 }
447 if (BUILD.vdomKey) {
448 vnode.$key$ = null;
449 }
450 if (BUILD.slotRelocation) {
451 vnode.$name$ = null;
452 }
453 return vnode;
454};
455const Host = {};
456const isHost = (node) => node && node.$tag$ === Host;
457const vdomFnUtils = {
458 forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
459 map: (children, cb) => children
460 .map(convertToPublic)
461 .map(cb)
462 .map(convertToPrivate),
463};
464const convertToPublic = (node) => ({
465 vattrs: node.$attrs$,
466 vchildren: node.$children$,
467 vkey: node.$key$,
468 vname: node.$name$,
469 vtag: node.$tag$,
470 vtext: node.$text$,
471});
472const convertToPrivate = (node) => {
473 const vnode = newVNode(node.vtag, node.vtext);
474 vnode.$attrs$ = node.vattrs;
475 vnode.$children$ = node.vchildren;
476 vnode.$key$ = node.vkey;
477 vnode.$name$ = node.vname;
478 return vnode;
479};
480const validateInputProperties = (vnodeData) => {
481 const props = Object.keys(vnodeData);
482 const typeIndex = props.indexOf('type');
483 const minIndex = props.indexOf('min');
484 const maxIndex = props.indexOf('max');
485 const stepIndex = props.indexOf('min');
486 const value = props.indexOf('value');
487 if (value === -1) {
488 return;
489 }
490 if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
491 consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
492 }
493};
494/**
495 * Production setAccessor() function based on Preact by
496 * Jason Miller (@developit)
497 * Licensed under the MIT License
498 * https://github.com/developit/preact/blob/master/LICENSE
499 *
500 * Modified for Stencil's compiler and vdom
501 */
502const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
503 if (oldValue !== newValue) {
504 let isProp = isMemberInElement(elm, memberName);
505 let ln = memberName.toLowerCase();
506 if (BUILD.vdomClass && memberName === 'class') {
507 const classList = elm.classList;
508 const oldClasses = parseClassList(oldValue);
509 const newClasses = parseClassList(newValue);
510 classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
511 classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
512 }
513 else if (BUILD.vdomStyle && memberName === 'style') {
514 // update style attribute, css properties and values
515 if (BUILD.updatable) {
516 for (const prop in oldValue) {
517 if (!newValue || newValue[prop] == null) {
518 if (!BUILD.hydrateServerSide && prop.includes('-')) {
519 elm.style.removeProperty(prop);
520 }
521 else {
522 elm.style[prop] = '';
523 }
524 }
525 }
526 }
527 for (const prop in newValue) {
528 if (!oldValue || newValue[prop] !== oldValue[prop]) {
529 if (!BUILD.hydrateServerSide && prop.includes('-')) {
530 elm.style.setProperty(prop, newValue[prop]);
531 }
532 else {
533 elm.style[prop] = newValue[prop];
534 }
535 }
536 }
537 }
538 else if (BUILD.vdomKey && memberName === 'key')
539 ;
540 else if (BUILD.vdomRef && memberName === 'ref') {
541 // minifier will clean this up
542 if (newValue) {
543 newValue(elm);
544 }
545 }
546 else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === 'o' && memberName[1] === 'n') {
547 // Event Handlers
548 // so if the member name starts with "on" and the 3rd characters is
549 // a capital letter, and it's not already a member on the element,
550 // then we're assuming it's an event listener
551 if (memberName[2] === '-') {
552 // on- prefixed events
553 // allows to be explicit about the dom event to listen without any magic
554 // under the hood:
555 // <my-cmp on-click> // listens for "click"
556 // <my-cmp on-Click> // listens for "Click"
557 // <my-cmp on-ionChange> // listens for "ionChange"
558 // <my-cmp on-EVENTS> // listens for "EVENTS"
559 memberName = memberName.slice(3);
560 }
561 else if (isMemberInElement(win, ln)) {
562 // standard event
563 // the JSX attribute could have been "onMouseOver" and the
564 // member name "onmouseover" is on the window's prototype
565 // so let's add the listener "mouseover", which is all lowercased
566 memberName = ln.slice(2);
567 }
568 else {
569 // custom event
570 // the JSX attribute could have been "onMyCustomEvent"
571 // so let's trim off the "on" prefix and lowercase the first character
572 // and add the listener "myCustomEvent"
573 // except for the first character, we keep the event name case
574 memberName = ln[2] + memberName.slice(3);
575 }
576 if (oldValue) {
577 plt.rel(elm, memberName, oldValue, false);
578 }
579 if (newValue) {
580 plt.ael(elm, memberName, newValue, false);
581 }
582 }
583 else if (BUILD.vdomPropOrAttr) {
584 // Set property if it exists and it's not a SVG
585 const isComplex = isComplexType(newValue);
586 if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
587 try {
588 if (!elm.tagName.includes('-')) {
589 let n = newValue == null ? '' : newValue;
590 // Workaround for Safari, moving the <input> caret when re-assigning the same valued
591 if (memberName === 'list') {
592 isProp = false;
593 // tslint:disable-next-line: triple-equals
594 }
595 else if (oldValue == null || elm[memberName] != n) {
596 elm[memberName] = n;
597 }
598 }
599 else {
600 elm[memberName] = newValue;
601 }
602 }
603 catch (e) { }
604 }
605 /**
606 * Need to manually update attribute if:
607 * - memberName is not an attribute
608 * - if we are rendering the host element in order to reflect attribute
609 * - if it's a SVG, since properties might not work in <svg>
610 * - if the newValue is null/undefined or 'false'.
611 */
612 let xlink = false;
613 if (BUILD.vdomXlink) {
614 if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
615 memberName = ln;
616 xlink = true;
617 }
618 }
619 if (newValue == null || newValue === false) {
620 if (newValue !== false || elm.getAttribute(memberName) === '') {
621 if (BUILD.vdomXlink && xlink) {
622 elm.removeAttributeNS(XLINK_NS, memberName);
623 }
624 else {
625 elm.removeAttribute(memberName);
626 }
627 }
628 }
629 else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
630 newValue = newValue === true ? '' : newValue;
631 if (BUILD.vdomXlink && xlink) {
632 elm.setAttributeNS(XLINK_NS, memberName, newValue);
633 }
634 else {
635 elm.setAttribute(memberName, newValue);
636 }
637 }
638 }
639 }
640};
641const parseClassListRegex = /\s/;
642const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
643const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
644 // if the element passed in is a shadow root, which is a document fragment
645 // then we want to be adding attrs/props to the shadow root's "host" element
646 // if it's not a shadow root, then we add attrs/props to the same element
647 const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
648 const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
649 const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
650 if (BUILD.updatable) {
651 // remove attributes no longer present on the vnode by setting them to undefined
652 for (memberName in oldVnodeAttrs) {
653 if (!(memberName in newVnodeAttrs)) {
654 setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
655 }
656 }
657 }
658 // add new & update changed attributes
659 for (memberName in newVnodeAttrs) {
660 setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
661 }
662};
663const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
664 // tslint:disable-next-line: prefer-const
665 let newVNode = newParentVNode.$children$[childIndex];
666 let i = 0;
667 let elm;
668 let childNode;
669 let oldVNode;
670 if (BUILD.slotRelocation && !useNativeShadowDom) {
671 // remember for later we need to check to relocate nodes
672 checkSlotRelocate = true;
673 if (newVNode.$tag$ === 'slot') {
674 if (scopeId) {
675 // scoped css needs to add its scoped id to the parent element
676 parentElm.classList.add(scopeId + '-s');
677 }
678 newVNode.$flags$ |= newVNode.$children$
679 ? // slot element has fallback content
680 2 /* isSlotFallback */
681 : // slot element does not have fallback content
682 1 /* isSlotReference */;
683 }
684 }
685 if (BUILD.isDev && newVNode.$elm$) {
686 consoleError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${newVNode.$tag$}" element`} node should not be shared within the same renderer. The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be reused. For more information please see https://stenciljs.com/docs/templating-jsx#avoid-shared-jsx-nodes`);
687 }
688 if (BUILD.vdomText && newVNode.$text$ !== null) {
689 // create text node
690 elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
691 }
692 else if (BUILD.slotRelocation && newVNode.$flags$ & 1 /* isSlotReference */) {
693 // create a slot reference node
694 elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : doc.createTextNode('');
695 }
696 else {
697 if (BUILD.svg && !isSvgMode) {
698 isSvgMode = newVNode.$tag$ === 'svg';
699 }
700 // create element
701 elm = newVNode.$elm$ = (BUILD.svg
702 ? doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, BUILD.slotRelocation && newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$)
703 : doc.createElement(BUILD.slotRelocation && newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$));
704 if (BUILD.svg && isSvgMode && newVNode.$tag$ === 'foreignObject') {
705 isSvgMode = false;
706 }
707 // add css classes, attrs, props, listeners, etc.
708 if (BUILD.vdomAttribute) {
709 updateElement(null, newVNode, isSvgMode);
710 }
711 if ((BUILD.shadowDom || BUILD.scoped) && isDef(scopeId) && elm['s-si'] !== scopeId) {
712 // if there is a scopeId and this is the initial render
713 // then let's add the scopeId as a css class
714 elm.classList.add((elm['s-si'] = scopeId));
715 }
716 if (newVNode.$children$) {
717 for (i = 0; i < newVNode.$children$.length; ++i) {
718 // create the node
719 childNode = createElm(oldParentVNode, newVNode, i, elm);
720 // return node could have been null
721 if (childNode) {
722 // append our new node
723 elm.appendChild(childNode);
724 }
725 }
726 }
727 if (BUILD.svg) {
728 if (newVNode.$tag$ === 'svg') {
729 // Only reset the SVG context when we're exiting <svg> element
730 isSvgMode = false;
731 }
732 else if (elm.tagName === 'foreignObject') {
733 // Reenter SVG context when we're exiting <foreignObject> element
734 isSvgMode = true;
735 }
736 }
737 }
738 if (BUILD.slotRelocation) {
739 elm['s-hn'] = hostTagName;
740 if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
741 // remember the content reference comment
742 elm['s-sr'] = true;
743 // remember the content reference comment
744 elm['s-cr'] = contentRef;
745 // remember the slot name, or empty string for default slot
746 elm['s-sn'] = newVNode.$name$ || '';
747 // check if we've got an old vnode for this slot
748 oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
749 if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
750 // we've got an old slot vnode and the wrapper is being replaced
751 // so let's move the old slot content back to it's original location
752 putBackInOriginalLocation(oldParentVNode.$elm$, false);
753 }
754 }
755 }
756 return elm;
757};
758const putBackInOriginalLocation = (parentElm, recursive) => {
759 plt.$flags$ |= 1 /* isTmpDisconnected */;
760 const oldSlotChildNodes = parentElm.childNodes;
761 for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
762 const childNode = oldSlotChildNodes[i];
763 if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
764 // // this child node in the old element is from another component
765 // // remove this node from the old slot's parent
766 // childNode.remove();
767 // and relocate it back to it's original location
768 parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
769 // remove the old original location comment entirely
770 // later on the patch function will know what to do
771 // and move this to the correct spot in need be
772 childNode['s-ol'].remove();
773 childNode['s-ol'] = undefined;
774 checkSlotRelocate = true;
775 }
776 if (recursive) {
777 putBackInOriginalLocation(childNode, recursive);
778 }
779 }
780 plt.$flags$ &= ~1 /* isTmpDisconnected */;
781};
782const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
783 let containerElm = ((BUILD.slotRelocation && parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
784 let childNode;
785 if (BUILD.shadowDom && containerElm.shadowRoot && containerElm.tagName === hostTagName) {
786 containerElm = containerElm.shadowRoot;
787 }
788 for (; startIdx <= endIdx; ++startIdx) {
789 if (vnodes[startIdx]) {
790 childNode = createElm(null, parentVNode, startIdx, parentElm);
791 if (childNode) {
792 vnodes[startIdx].$elm$ = childNode;
793 containerElm.insertBefore(childNode, BUILD.slotRelocation ? referenceNode(before) : before);
794 }
795 }
796 }
797};
798const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
799 for (; startIdx <= endIdx; ++startIdx) {
800 if ((vnode = vnodes[startIdx])) {
801 elm = vnode.$elm$;
802 callNodeRefs(vnode);
803 if (BUILD.slotRelocation) {
804 // we're removing this element
805 // so it's possible we need to show slot fallback content now
806 checkSlotFallbackVisibility = true;
807 if (elm['s-ol']) {
808 // remove the original location comment
809 elm['s-ol'].remove();
810 }
811 else {
812 // it's possible that child nodes of the node
813 // that's being removed are slot nodes
814 putBackInOriginalLocation(elm, true);
815 }
816 }
817 // remove the vnode's element from the dom
818 elm.remove();
819 }
820 }
821};
822const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
823 let oldStartIdx = 0;
824 let newStartIdx = 0;
825 let idxInOld = 0;
826 let i = 0;
827 let oldEndIdx = oldCh.length - 1;
828 let oldStartVnode = oldCh[0];
829 let oldEndVnode = oldCh[oldEndIdx];
830 let newEndIdx = newCh.length - 1;
831 let newStartVnode = newCh[0];
832 let newEndVnode = newCh[newEndIdx];
833 let node;
834 let elmToMove;
835 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
836 if (oldStartVnode == null) {
837 // Vnode might have been moved left
838 oldStartVnode = oldCh[++oldStartIdx];
839 }
840 else if (oldEndVnode == null) {
841 oldEndVnode = oldCh[--oldEndIdx];
842 }
843 else if (newStartVnode == null) {
844 newStartVnode = newCh[++newStartIdx];
845 }
846 else if (newEndVnode == null) {
847 newEndVnode = newCh[--newEndIdx];
848 }
849 else if (isSameVnode(oldStartVnode, newStartVnode)) {
850 patch(oldStartVnode, newStartVnode);
851 oldStartVnode = oldCh[++oldStartIdx];
852 newStartVnode = newCh[++newStartIdx];
853 }
854 else if (isSameVnode(oldEndVnode, newEndVnode)) {
855 patch(oldEndVnode, newEndVnode);
856 oldEndVnode = oldCh[--oldEndIdx];
857 newEndVnode = newCh[--newEndIdx];
858 }
859 else if (isSameVnode(oldStartVnode, newEndVnode)) {
860 // Vnode moved right
861 if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
862 putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
863 }
864 patch(oldStartVnode, newEndVnode);
865 parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
866 oldStartVnode = oldCh[++oldStartIdx];
867 newEndVnode = newCh[--newEndIdx];
868 }
869 else if (isSameVnode(oldEndVnode, newStartVnode)) {
870 // Vnode moved left
871 if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
872 putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
873 }
874 patch(oldEndVnode, newStartVnode);
875 parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
876 oldEndVnode = oldCh[--oldEndIdx];
877 newStartVnode = newCh[++newStartIdx];
878 }
879 else {
880 // createKeyToOldIdx
881 idxInOld = -1;
882 if (BUILD.vdomKey) {
883 for (i = oldStartIdx; i <= oldEndIdx; ++i) {
884 if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
885 idxInOld = i;
886 break;
887 }
888 }
889 }
890 if (BUILD.vdomKey && idxInOld >= 0) {
891 elmToMove = oldCh[idxInOld];
892 if (elmToMove.$tag$ !== newStartVnode.$tag$) {
893 node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
894 }
895 else {
896 patch(elmToMove, newStartVnode);
897 oldCh[idxInOld] = undefined;
898 node = elmToMove.$elm$;
899 }
900 newStartVnode = newCh[++newStartIdx];
901 }
902 else {
903 // new element
904 node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
905 newStartVnode = newCh[++newStartIdx];
906 }
907 if (node) {
908 if (BUILD.slotRelocation) {
909 parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
910 }
911 else {
912 oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
913 }
914 }
915 }
916 }
917 if (oldStartIdx > oldEndIdx) {
918 addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
919 }
920 else if (BUILD.updatable && newStartIdx > newEndIdx) {
921 removeVnodes(oldCh, oldStartIdx, oldEndIdx);
922 }
923};
924const isSameVnode = (vnode1, vnode2) => {
925 // compare if two vnode to see if they're "technically" the same
926 // need to have the same element tag, and same key to be the same
927 if (vnode1.$tag$ === vnode2.$tag$) {
928 if (BUILD.slotRelocation && vnode1.$tag$ === 'slot') {
929 return vnode1.$name$ === vnode2.$name$;
930 }
931 if (BUILD.vdomKey) {
932 return vnode1.$key$ === vnode2.$key$;
933 }
934 return true;
935 }
936 return false;
937};
938const referenceNode = (node) => {
939 // this node was relocated to a new location in the dom
940 // because of some other component's slot
941 // but we still have an html comment in place of where
942 // it's original location was according to it's original vdom
943 return (node && node['s-ol']) || node;
944};
945const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
946const patch = (oldVNode, newVNode) => {
947 const elm = (newVNode.$elm$ = oldVNode.$elm$);
948 const oldChildren = oldVNode.$children$;
949 const newChildren = newVNode.$children$;
950 const tag = newVNode.$tag$;
951 const text = newVNode.$text$;
952 let defaultHolder;
953 if (!BUILD.vdomText || text === null) {
954 if (BUILD.svg) {
955 // test if we're rendering an svg element, or still rendering nodes inside of one
956 // only add this to the when the compiler sees we're using an svg somewhere
957 isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
958 }
959 // element node
960 if (BUILD.vdomAttribute || BUILD.reflect) {
961 if (BUILD.slot && tag === 'slot')
962 ;
963 else {
964 // either this is the first render of an element OR it's an update
965 // AND we already know it's possible it could have changed
966 // this updates the element's css classes, attrs, props, listeners, etc.
967 updateElement(oldVNode, newVNode, isSvgMode);
968 }
969 }
970 if (BUILD.updatable && oldChildren !== null && newChildren !== null) {
971 // looks like there's child vnodes for both the old and new vnodes
972 updateChildren(elm, oldChildren, newVNode, newChildren);
973 }
974 else if (newChildren !== null) {
975 // no old child vnodes, but there are new child vnodes to add
976 if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) {
977 // the old vnode was text, so be sure to clear it out
978 elm.textContent = '';
979 }
980 // add the new vnode children
981 addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
982 }
983 else if (BUILD.updatable && oldChildren !== null) {
984 // no new child vnodes, but there are old child vnodes to remove
985 removeVnodes(oldChildren, 0, oldChildren.length - 1);
986 }
987 if (BUILD.svg && isSvgMode && tag === 'svg') {
988 isSvgMode = false;
989 }
990 }
991 else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm['s-cr'])) {
992 // this element has slotted content
993 defaultHolder.parentNode.textContent = text;
994 }
995 else if (BUILD.vdomText && oldVNode.$text$ !== text) {
996 // update the text content for the text only vnode
997 // and also only if the text is different than before
998 elm.data = text;
999 }
1000};
1001const updateFallbackSlotVisibility = (elm) => {
1002 // tslint:disable-next-line: prefer-const
1003 let childNodes = elm.childNodes;
1004 let childNode;
1005 let i;
1006 let ilen;
1007 let j;
1008 let slotNameAttr;
1009 let nodeType;
1010 for (i = 0, ilen = childNodes.length; i < ilen; i++) {
1011 childNode = childNodes[i];
1012 if (childNode.nodeType === 1 /* ElementNode */) {
1013 if (childNode['s-sr']) {
1014 // this is a slot fallback node
1015 // get the slot name for this slot reference node
1016 slotNameAttr = childNode['s-sn'];
1017 // by default always show a fallback slot node
1018 // then hide it if there are other slots in the light dom
1019 childNode.hidden = false;
1020 for (j = 0; j < ilen; j++) {
1021 if (childNodes[j]['s-hn'] !== childNode['s-hn']) {
1022 // this sibling node is from a different component
1023 nodeType = childNodes[j].nodeType;
1024 if (slotNameAttr !== '') {
1025 // this is a named fallback slot node
1026 if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
1027 childNode.hidden = true;
1028 break;
1029 }
1030 }
1031 else {
1032 // this is a default fallback slot node
1033 // any element or text node (with content)
1034 // should hide the default fallback slot node
1035 if (nodeType === 1 /* ElementNode */ || (nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
1036 childNode.hidden = true;
1037 break;
1038 }
1039 }
1040 }
1041 }
1042 }
1043 // keep drilling down
1044 updateFallbackSlotVisibility(childNode);
1045 }
1046 }
1047};
1048const relocateNodes = [];
1049const relocateSlotContent = (elm) => {
1050 // tslint:disable-next-line: prefer-const
1051 let childNode;
1052 let node;
1053 let hostContentNodes;
1054 let slotNameAttr;
1055 let relocateNodeData;
1056 let j;
1057 let i = 0;
1058 let childNodes = elm.childNodes;
1059 let ilen = childNodes.length;
1060 for (; i < ilen; i++) {
1061 childNode = childNodes[i];
1062 if (childNode['s-sr'] && (node = childNode['s-cr'])) {
1063 // first got the content reference comment node
1064 // then we got it's parent, which is where all the host content is in now
1065 hostContentNodes = node.parentNode.childNodes;
1066 slotNameAttr = childNode['s-sn'];
1067 for (j = hostContentNodes.length - 1; j >= 0; j--) {
1068 node = hostContentNodes[j];
1069 if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
1070 // let's do some relocating to its new home
1071 // but never relocate a content reference node
1072 // that is suppose to always represent the original content location
1073 if (isNodeLocatedInSlot(node, slotNameAttr)) {
1074 // it's possible we've already decided to relocate this node
1075 relocateNodeData = relocateNodes.find(r => r.$nodeToRelocate$ === node);
1076 // made some changes to slots
1077 // let's make sure we also double check
1078 // fallbacks are correctly hidden or shown
1079 checkSlotFallbackVisibility = true;
1080 node['s-sn'] = node['s-sn'] || slotNameAttr;
1081 if (relocateNodeData) {
1082 // previously we never found a slot home for this node
1083 // but turns out we did, so let's remember it now
1084 relocateNodeData.$slotRefNode$ = childNode;
1085 }
1086 else {
1087 // add to our list of nodes to relocate
1088 relocateNodes.push({
1089 $slotRefNode$: childNode,
1090 $nodeToRelocate$: node,
1091 });
1092 }
1093 if (node['s-sr']) {
1094 relocateNodes.map(relocateNode => {
1095 if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1096 relocateNodeData = relocateNodes.find(r => r.$nodeToRelocate$ === node);
1097 if (relocateNodeData && !relocateNode.$slotRefNode$) {
1098 relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1099 }
1100 }
1101 });
1102 }
1103 }
1104 else if (!relocateNodes.some(r => r.$nodeToRelocate$ === node)) {
1105 // so far this element does not have a slot home, not setting slotRefNode on purpose
1106 // if we never find a home for this element then we'll need to hide it
1107 relocateNodes.push({
1108 $nodeToRelocate$: node,
1109 });
1110 }
1111 }
1112 }
1113 }
1114 if (childNode.nodeType === 1 /* ElementNode */) {
1115 relocateSlotContent(childNode);
1116 }
1117 }
1118};
1119const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1120 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1121 if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1122 return true;
1123 }
1124 if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1125 return true;
1126 }
1127 return false;
1128 }
1129 if (nodeToRelocate['s-sn'] === slotNameAttr) {
1130 return true;
1131 }
1132 return slotNameAttr === '';
1133};
1134const callNodeRefs = (vNode) => {
1135 if (BUILD.vdomRef) {
1136 vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1137 vNode.$children$ && vNode.$children$.map(callNodeRefs);
1138 }
1139};
1140const renderVdom = (hostRef, renderFnResults) => {
1141 const hostElm = hostRef.$hostElement$;
1142 const cmpMeta = hostRef.$cmpMeta$;
1143 const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1144 const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1145 hostTagName = hostElm.tagName;
1146 // <Host> runtime check
1147 if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) {
1148 throw new Error(`The <Host> must be the single root component.
1149Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
1150
1151The render() function should look like this instead:
1152
1153render() {
1154 // Do not return an array
1155 return (
1156 <Host>{content}</Host>
1157 );
1158}
1159 `);
1160 }
1161 if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
1162 rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1163 cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
1164 }
1165 rootVnode.$tag$ = null;
1166 rootVnode.$flags$ |= 4 /* isHost */;
1167 hostRef.$vnode$ = rootVnode;
1168 rootVnode.$elm$ = oldVNode.$elm$ = (BUILD.shadowDom ? hostElm.shadowRoot || hostElm : hostElm);
1169 if (BUILD.scoped || BUILD.shadowDom) {
1170 scopeId = hostElm['s-sc'];
1171 }
1172 if (BUILD.slotRelocation) {
1173 contentRef = hostElm['s-cr'];
1174 useNativeShadowDom = supportsShadow && (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
1175 // always reset
1176 checkSlotFallbackVisibility = false;
1177 }
1178 // synchronous patch
1179 patch(oldVNode, rootVnode);
1180 if (BUILD.slotRelocation) {
1181 // while we're moving nodes around existing nodes, temporarily disable
1182 // the disconnectCallback from working
1183 plt.$flags$ |= 1 /* isTmpDisconnected */;
1184 if (checkSlotRelocate) {
1185 relocateSlotContent(rootVnode.$elm$);
1186 let relocateData;
1187 let nodeToRelocate;
1188 let orgLocationNode;
1189 let parentNodeRef;
1190 let insertBeforeNode;
1191 let refNode;
1192 let i = 0;
1193 for (; i < relocateNodes.length; i++) {
1194 relocateData = relocateNodes[i];
1195 nodeToRelocate = relocateData.$nodeToRelocate$;
1196 if (!nodeToRelocate['s-ol']) {
1197 // add a reference node marking this node's original location
1198 // keep a reference to this node for later lookups
1199 orgLocationNode = BUILD.isDebug || BUILD.hydrateServerSide ? originalLocationDebugNode(nodeToRelocate) : doc.createTextNode('');
1200 orgLocationNode['s-nr'] = nodeToRelocate;
1201 nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1202 }
1203 }
1204 for (i = 0; i < relocateNodes.length; i++) {
1205 relocateData = relocateNodes[i];
1206 nodeToRelocate = relocateData.$nodeToRelocate$;
1207 if (relocateData.$slotRefNode$) {
1208 // by default we're just going to insert it directly
1209 // after the slot reference node
1210 parentNodeRef = relocateData.$slotRefNode$.parentNode;
1211 insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1212 orgLocationNode = nodeToRelocate['s-ol'];
1213 while ((orgLocationNode = orgLocationNode.previousSibling)) {
1214 refNode = orgLocationNode['s-nr'];
1215 if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1216 refNode = refNode.nextSibling;
1217 if (!refNode || !refNode['s-nr']) {
1218 insertBeforeNode = refNode;
1219 break;
1220 }
1221 }
1222 }
1223 if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) || nodeToRelocate.nextSibling !== insertBeforeNode) {
1224 // we've checked that it's worth while to relocate
1225 // since that the node to relocate
1226 // has a different next sibling or parent relocated
1227 if (nodeToRelocate !== insertBeforeNode) {
1228 if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1229 // probably a component in the index.html that doesn't have it's hostname set
1230 nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1231 }
1232 // add it back to the dom but in its new home
1233 parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1234 }
1235 }
1236 }
1237 else {
1238 // this node doesn't have a slot home to go to, so let's hide it
1239 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1240 nodeToRelocate.hidden = true;
1241 }
1242 }
1243 }
1244 }
1245 if (checkSlotFallbackVisibility) {
1246 updateFallbackSlotVisibility(rootVnode.$elm$);
1247 }
1248 // done moving nodes around
1249 // allow the disconnect callback to work again
1250 plt.$flags$ &= ~1 /* isTmpDisconnected */;
1251 // always reset
1252 relocateNodes.length = 0;
1253 }
1254};
1255// slot comment debug nodes only created with the `--debug` flag
1256// otherwise these nodes are text nodes w/out content
1257const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
1258const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})` : `[${nodeToRelocate.textContent}]`));
1259const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
1260const createEvent = (ref, name, flags) => {
1261 const elm = getElement(ref);
1262 return {
1263 emit: (detail) => {
1264 if (BUILD.isDev && !elm.isConnected) {
1265 consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
1266 }
1267 return emitEvent(elm, name, {
1268 bubbles: !!(flags & 4 /* Bubbles */),
1269 composed: !!(flags & 2 /* Composed */),
1270 cancelable: !!(flags & 1 /* Cancellable */),
1271 detail,
1272 });
1273 },
1274 };
1275};
1276const emitEvent = (elm, name, opts) => {
1277 const ev = new (BUILD.hydrateServerSide ? win.CustomEvent : CustomEvent)(name, opts);
1278 elm.dispatchEvent(ev);
1279 return ev;
1280};
1281const attachToAncestor = (hostRef, ancestorComponent) => {
1282 if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1283 ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
1284 }
1285};
1286const scheduleUpdate = (hostRef, isInitialLoad) => {
1287 if (BUILD.taskQueue && BUILD.updatable) {
1288 hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
1289 }
1290 if (BUILD.asyncLoading && hostRef.$flags$ & 4 /* isWaitingForChildren */) {
1291 hostRef.$flags$ |= 512 /* needsRerender */;
1292 return;
1293 }
1294 attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1295 // there is no ancestorc omponent or the ancestor component
1296 // has already fired off its lifecycle update then
1297 // fire off the initial update
1298 const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1299 return BUILD.taskQueue ? writeTask(dispatch) : dispatch;
1300};
1301const dispatchHooks = (hostRef, isInitialLoad) => {
1302 const elm = hostRef.$hostElement$;
1303 const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1304 const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1305 let promise;
1306 if (isInitialLoad) {
1307 if (BUILD.lazyLoad && BUILD.hostListener) {
1308 hostRef.$flags$ |= 256 /* isListenReady */;
1309 if (hostRef.$queuedListeners$) {
1310 hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1311 hostRef.$queuedListeners$ = null;
1312 }
1313 }
1314 emitLifecycleEvent(elm, 'componentWillLoad');
1315 if (BUILD.cmpWillLoad) {
1316 promise = safeCall(instance, 'componentWillLoad');
1317 }
1318 }
1319 else {
1320 emitLifecycleEvent(elm, 'componentWillUpdate');
1321 if (BUILD.cmpWillUpdate) {
1322 promise = safeCall(instance, 'componentWillUpdate');
1323 }
1324 }
1325 emitLifecycleEvent(elm, 'componentWillRender');
1326 if (BUILD.cmpWillRender) {
1327 promise = then(promise, () => safeCall(instance, 'componentWillRender'));
1328 }
1329 endSchedule();
1330 return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
1331};
1332const updateComponent = (hostRef, instance, isInitialLoad) => {
1333 // updateComponent
1334 const elm = hostRef.$hostElement$;
1335 const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1336 const rc = elm['s-rc'];
1337 if (BUILD.style && isInitialLoad) {
1338 // DOM WRITE!
1339 attachStyles(hostRef);
1340 }
1341 const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1342 if (BUILD.isDev) {
1343 hostRef.$flags$ |= 1024 /* devOnRender */;
1344 }
1345 if (BUILD.hasRenderFn || BUILD.reflect) {
1346 if (BUILD.vdomRender || BUILD.reflect) {
1347 // looks like we've got child nodes to render into this host element
1348 // or we need to update the css class/attrs on the host element
1349 // DOM WRITE!
1350 renderVdom(hostRef, callRender(hostRef, instance));
1351 }
1352 else {
1353 elm.textContent = callRender(hostRef, instance);
1354 }
1355 }
1356 if (BUILD.cssVarShim && plt.$cssShim$) {
1357 plt.$cssShim$.updateHost(elm);
1358 }
1359 if (BUILD.isDev) {
1360 hostRef.$renderCount$++;
1361 hostRef.$flags$ &= ~1024 /* devOnRender */;
1362 }
1363 if (BUILD.hydrateServerSide) {
1364 try {
1365 // manually connected child components during server-side hydrate
1366 serverSideConnected(elm);
1367 if (isInitialLoad) {
1368 // using only during server-side hydrate
1369 if (hostRef.$cmpMeta$.$flags$ & 1 /* shadowDomEncapsulation */) {
1370 elm['s-en'] = '';
1371 }
1372 else if (hostRef.$cmpMeta$.$flags$ & 2 /* scopedCssEncapsulation */) {
1373 elm['s-en'] = 'c';
1374 }
1375 }
1376 }
1377 catch (e) {
1378 consoleError(e);
1379 }
1380 }
1381 if (BUILD.asyncLoading && rc) {
1382 // ok, so turns out there are some child host elements
1383 // waiting on this parent element to load
1384 // let's fire off all update callbacks waiting
1385 rc.map(cb => cb());
1386 elm['s-rc'] = undefined;
1387 }
1388 endRender();
1389 endUpdate();
1390 if (BUILD.asyncLoading) {
1391 const childrenPromises = elm['s-p'];
1392 const postUpdate = () => postUpdateComponent(hostRef);
1393 if (childrenPromises.length === 0) {
1394 postUpdate();
1395 }
1396 else {
1397 Promise.all(childrenPromises).then(postUpdate);
1398 hostRef.$flags$ |= 4 /* isWaitingForChildren */;
1399 childrenPromises.length = 0;
1400 }
1401 }
1402 else {
1403 postUpdateComponent(hostRef);
1404 }
1405};
1406const callRender = (hostRef, instance) => {
1407 try {
1408 renderingRef = instance;
1409 instance = BUILD.allRenderFn ? instance.render() : instance.render && instance.render();
1410 if (BUILD.updatable && BUILD.taskQueue) {
1411 hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
1412 }
1413 if (BUILD.updatable || BUILD.lazyLoad) {
1414 hostRef.$flags$ |= 2 /* hasRendered */;
1415 }
1416 }
1417 catch (e) {
1418 consoleError(e);
1419 }
1420 renderingRef = null;
1421 return instance;
1422};
1423const getRenderingRef = () => renderingRef;
1424const postUpdateComponent = (hostRef) => {
1425 const tagName = hostRef.$cmpMeta$.$tagName$;
1426 const elm = hostRef.$hostElement$;
1427 const endPostUpdate = createTime('postUpdate', tagName);
1428 const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1429 const ancestorComponent = hostRef.$ancestorComponent$;
1430 if (BUILD.cmpDidRender) {
1431 if (BUILD.isDev) {
1432 hostRef.$flags$ |= 1024 /* devOnRender */;
1433 }
1434 safeCall(instance, 'componentDidRender');
1435 if (BUILD.isDev) {
1436 hostRef.$flags$ &= ~1024 /* devOnRender */;
1437 }
1438 }
1439 emitLifecycleEvent(elm, 'componentDidRender');
1440 if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
1441 hostRef.$flags$ |= 64 /* hasLoadedComponent */;
1442 if (BUILD.asyncLoading && BUILD.cssAnnotations) {
1443 // DOM WRITE!
1444 addHydratedFlag(elm);
1445 }
1446 if (BUILD.cmpDidLoad) {
1447 if (BUILD.isDev) {
1448 hostRef.$flags$ |= 2048 /* devOnDidLoad */;
1449 }
1450 safeCall(instance, 'componentDidLoad');
1451 if (BUILD.isDev) {
1452 hostRef.$flags$ &= ~2048 /* devOnDidLoad */;
1453 }
1454 }
1455 emitLifecycleEvent(elm, 'componentDidLoad');
1456 endPostUpdate();
1457 if (BUILD.asyncLoading) {
1458 hostRef.$onReadyResolve$(elm);
1459 if (!ancestorComponent) {
1460 appDidLoad(tagName);
1461 }
1462 }
1463 }
1464 else {
1465 if (BUILD.cmpDidUpdate) {
1466 // we've already loaded this component
1467 // fire off the user's componentDidUpdate method (if one was provided)
1468 // componentDidUpdate runs AFTER render() has been called
1469 // and all child components have finished updating
1470 if (BUILD.isDev) {
1471 hostRef.$flags$ |= 1024 /* devOnRender */;
1472 }
1473 safeCall(instance, 'componentDidUpdate');
1474 if (BUILD.isDev) {
1475 hostRef.$flags$ &= ~1024 /* devOnRender */;
1476 }
1477 }
1478 emitLifecycleEvent(elm, 'componentDidUpdate');
1479 endPostUpdate();
1480 }
1481 if (BUILD.hotModuleReplacement) {
1482 elm['s-hmr-load'] && elm['s-hmr-load']();
1483 }
1484 if (BUILD.method && BUILD.lazyLoad) {
1485 hostRef.$onInstanceResolve$(elm);
1486 }
1487 // load events fire from bottom to top
1488 // the deepest elements load first then bubbles up
1489 if (BUILD.asyncLoading) {
1490 if (hostRef.$onRenderResolve$) {
1491 hostRef.$onRenderResolve$();
1492 hostRef.$onRenderResolve$ = undefined;
1493 }
1494 if (hostRef.$flags$ & 512 /* needsRerender */) {
1495 nextTick(() => scheduleUpdate(hostRef, false));
1496 }
1497 hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
1498 }
1499 // ( •_•)
1500 // ( •_•)>⌐■-■
1501 // (⌐■_■)
1502};
1503const forceUpdate = (ref) => {
1504 if (BUILD.updatable) {
1505 const hostRef = getHostRef(ref);
1506 const isConnected = hostRef.$hostElement$.isConnected;
1507 if (isConnected && (hostRef.$flags$ & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1508 scheduleUpdate(hostRef, false);
1509 }
1510 // Returns "true" when the forced update was successfully scheduled
1511 return isConnected;
1512 }
1513 return false;
1514};
1515const appDidLoad = (who) => {
1516 // on appload
1517 // we have finish the first big initial render
1518 if (BUILD.cssAnnotations) {
1519 addHydratedFlag(doc.documentElement);
1520 }
1521 if (BUILD.asyncQueue) {
1522 plt.$flags$ |= 2 /* appLoaded */;
1523 }
1524 nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1525 if (BUILD.profile && performance.measure) {
1526 performance.measure(`[Stencil] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
1527 }
1528};
1529const safeCall = (instance, method, arg) => {
1530 if (instance && instance[method]) {
1531 try {
1532 return instance[method](arg);
1533 }
1534 catch (e) {
1535 consoleError(e);
1536 }
1537 }
1538 return undefined;
1539};
1540const then = (promise, thenFn) => {
1541 return promise && promise.then ? promise.then(thenFn) : thenFn();
1542};
1543const emitLifecycleEvent = (elm, lifecycleName) => {
1544 if (BUILD.lifecycleDOMEvents) {
1545 emitEvent(elm, 'stencil_' + lifecycleName, {
1546 bubbles: true,
1547 composed: true,
1548 detail: {
1549 namespace: NAMESPACE,
1550 },
1551 });
1552 }
1553};
1554const addHydratedFlag = (elm) => (BUILD.hydratedClass ? elm.classList.add('hydrated') : BUILD.hydratedAttribute ? elm.setAttribute('hydrated', '') : undefined);
1555const serverSideConnected = (elm) => {
1556 const children = elm.children;
1557 if (children != null) {
1558 for (let i = 0, ii = children.length; i < ii; i++) {
1559 const childElm = children[i];
1560 if (typeof childElm.connectedCallback === 'function') {
1561 childElm.connectedCallback();
1562 }
1563 serverSideConnected(childElm);
1564 }
1565 }
1566};
1567const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
1568 const endHydrate = createTime('hydrateClient', tagName);
1569 const shadowRoot = hostElm.shadowRoot;
1570 const childRenderNodes = [];
1571 const slotNodes = [];
1572 const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
1573 const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
1574 if (!plt.$orgLocNodes$) {
1575 initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
1576 }
1577 hostElm[HYDRATE_ID] = hostId;
1578 hostElm.removeAttribute(HYDRATE_ID);
1579 clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
1580 childRenderNodes.map(c => {
1581 const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
1582 const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
1583 const node = c.$elm$;
1584 if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
1585 orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
1586 }
1587 if (!shadowRoot) {
1588 node['s-hn'] = tagName;
1589 if (orgLocationNode) {
1590 node['s-ol'] = orgLocationNode;
1591 node['s-ol']['s-nr'] = node;
1592 }
1593 }
1594 plt.$orgLocNodes$.delete(orgLocationId);
1595 });
1596 if (BUILD.shadowDom && shadowRoot) {
1597 shadowRootNodes.map(shadowRootNode => {
1598 if (shadowRootNode) {
1599 shadowRoot.appendChild(shadowRootNode);
1600 }
1601 });
1602 }
1603 endHydrate();
1604};
1605const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
1606 let childNodeType;
1607 let childIdSplt;
1608 let childVNode;
1609 let i;
1610 if (node.nodeType === 1 /* ElementNode */) {
1611 childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
1612 if (childNodeType) {
1613 // got the node data from the element's attribute
1614 // `${hostId}.${nodeId}.${depth}.${index}`
1615 childIdSplt = childNodeType.split('.');
1616 if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
1617 childVNode = {
1618 $flags$: 0,
1619 $hostId$: childIdSplt[0],
1620 $nodeId$: childIdSplt[1],
1621 $depth$: childIdSplt[2],
1622 $index$: childIdSplt[3],
1623 $tag$: node.tagName.toLowerCase(),
1624 $elm$: node,
1625 $attrs$: null,
1626 $children$: null,
1627 $key$: null,
1628 $name$: null,
1629 $text$: null,
1630 };
1631 childRenderNodes.push(childVNode);
1632 node.removeAttribute(HYDRATE_CHILD_ID);
1633 // this is a new child vnode
1634 // so ensure its parent vnode has the vchildren array
1635 if (!parentVNode.$children$) {
1636 parentVNode.$children$ = [];
1637 }
1638 // add our child vnode to a specific index of the vnode's children
1639 parentVNode.$children$[childVNode.$index$] = childVNode;
1640 // this is now the new parent vnode for all the next child checks
1641 parentVNode = childVNode;
1642 if (shadowRootNodes && childVNode.$depth$ === '0') {
1643 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1644 }
1645 }
1646 }
1647 // recursively drill down, end to start so we can remove nodes
1648 for (i = node.childNodes.length - 1; i >= 0; i--) {
1649 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
1650 }
1651 if (node.shadowRoot) {
1652 // keep drilling down through the shadow root nodes
1653 for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
1654 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
1655 }
1656 }
1657 }
1658 else if (node.nodeType === 8 /* CommentNode */) {
1659 // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
1660 childIdSplt = node.nodeValue.split('.');
1661 if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
1662 // comment node for either the host id or a 0 host id
1663 childNodeType = childIdSplt[0];
1664 childVNode = {
1665 $flags$: 0,
1666 $hostId$: childIdSplt[1],
1667 $nodeId$: childIdSplt[2],
1668 $depth$: childIdSplt[3],
1669 $index$: childIdSplt[4],
1670 $elm$: node,
1671 $attrs$: null,
1672 $children$: null,
1673 $key$: null,
1674 $name$: null,
1675 $tag$: null,
1676 $text$: null,
1677 };
1678 if (childNodeType === TEXT_NODE_ID) {
1679 childVNode.$elm$ = node.nextSibling;
1680 if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* TextNode */) {
1681 childVNode.$text$ = childVNode.$elm$.textContent;
1682 childRenderNodes.push(childVNode);
1683 // remove the text comment since it's no longer needed
1684 node.remove();
1685 if (!parentVNode.$children$) {
1686 parentVNode.$children$ = [];
1687 }
1688 parentVNode.$children$[childVNode.$index$] = childVNode;
1689 if (shadowRootNodes && childVNode.$depth$ === '0') {
1690 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1691 }
1692 }
1693 }
1694 else if (childVNode.$hostId$ === hostId) {
1695 // this comment node is specifcally for this host id
1696 if (childNodeType === SLOT_NODE_ID) {
1697 // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
1698 childVNode.$tag$ = 'slot';
1699 if (childIdSplt[5]) {
1700 node['s-sn'] = childVNode.$name$ = childIdSplt[5];
1701 }
1702 else {
1703 node['s-sn'] = '';
1704 }
1705 node['s-sr'] = true;
1706 if (BUILD.shadowDom && shadowRootNodes) {
1707 // browser support shadowRoot and this is a shadow dom component
1708 // create an actual slot element
1709 childVNode.$elm$ = doc.createElement(childVNode.$tag$);
1710 if (childVNode.$name$) {
1711 // add the slot name attribute
1712 childVNode.$elm$.setAttribute('name', childVNode.$name$);
1713 }
1714 // insert the new slot element before the slot comment
1715 node.parentNode.insertBefore(childVNode.$elm$, node);
1716 // remove the slot comment since it's not needed for shadow
1717 node.remove();
1718 if (childVNode.$depth$ === '0') {
1719 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1720 }
1721 }
1722 slotNodes.push(childVNode);
1723 if (!parentVNode.$children$) {
1724 parentVNode.$children$ = [];
1725 }
1726 parentVNode.$children$[childVNode.$index$] = childVNode;
1727 }
1728 else if (childNodeType === CONTENT_REF_ID) {
1729 // `${CONTENT_REF_ID}.${hostId}`;
1730 if (BUILD.shadowDom && shadowRootNodes) {
1731 // remove the content ref comment since it's not needed for shadow
1732 node.remove();
1733 }
1734 else if (BUILD.slotRelocation) {
1735 hostElm['s-cr'] = node;
1736 node['s-cn'] = true;
1737 }
1738 }
1739 }
1740 }
1741 }
1742 else if (parentVNode && parentVNode.$tag$ === 'style') {
1743 const vnode = newVNode(null, node.textContent);
1744 vnode.$elm$ = node;
1745 vnode.$index$ = '0';
1746 parentVNode.$children$ = [vnode];
1747 }
1748};
1749const initializeDocumentHydrate = (node, orgLocNodes) => {
1750 if (node.nodeType === 1 /* ElementNode */) {
1751 let i = 0;
1752 for (; i < node.childNodes.length; i++) {
1753 initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
1754 }
1755 if (node.shadowRoot) {
1756 for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
1757 initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
1758 }
1759 }
1760 }
1761 else if (node.nodeType === 8 /* CommentNode */) {
1762 const childIdSplt = node.nodeValue.split('.');
1763 if (childIdSplt[0] === ORG_LOCATION_ID) {
1764 orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
1765 node.nodeValue = '';
1766 // useful to know if the original location is
1767 // the root light-dom of a shadow dom component
1768 node['s-en'] = childIdSplt[3];
1769 }
1770 }
1771};
1772const parsePropertyValue = (propValue, propType) => {
1773 // ensure this value is of the correct prop type
1774 if (propValue != null && !isComplexType(propValue)) {
1775 if (BUILD.propBoolean && propType & 4 /* Boolean */) {
1776 // per the HTML spec, any string value means it is a boolean true value
1777 // but we'll cheat here and say that the string "false" is the boolean false
1778 return propValue === 'false' ? false : propValue === '' || !!propValue;
1779 }
1780 if (BUILD.propNumber && propType & 2 /* Number */) {
1781 // force it to be a number
1782 return parseFloat(propValue);
1783 }
1784 if (BUILD.propString && propType & 1 /* String */) {
1785 // could have been passed as a number or boolean
1786 // but we still want it as a string
1787 return String(propValue);
1788 }
1789 // redundant return here for better minification
1790 return propValue;
1791 }
1792 // not sure exactly what type we want
1793 // so no need to change to a different type
1794 return propValue;
1795};
1796const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1797const setValue = (ref, propName, newVal, cmpMeta) => {
1798 // check our new property value against our internal value
1799 const hostRef = getHostRef(ref);
1800 const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
1801 const oldVal = hostRef.$instanceValues$.get(propName);
1802 const flags = hostRef.$flags$;
1803 const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1804 newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1805 if ((!BUILD.lazyLoad || !(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
1806 // gadzooks! the property's value has changed!!
1807 // set our new value!
1808 hostRef.$instanceValues$.set(propName, newVal);
1809 if (BUILD.isDev) {
1810 if (hostRef.$flags$ & 1024 /* devOnRender */) {
1811 consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1812 }
1813 else if (hostRef.$flags$ & 2048 /* devOnDidLoad */) {
1814 consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1815 }
1816 }
1817 if (!BUILD.lazyLoad || instance) {
1818 // get an array of method names of watch functions to call
1819 if (BUILD.watchCallback && cmpMeta.$watchers$) {
1820 if (!BUILD.lazyLoad || flags & 128 /* isWatchReady */) {
1821 const watchMethods = cmpMeta.$watchers$[propName];
1822 if (watchMethods) {
1823 // this instance is watching for when this property changed
1824 watchMethods.map(watchMethodName => {
1825 try {
1826 // fire off each of the watch methods that are watching this property
1827 instance[watchMethodName](newVal, oldVal, propName);
1828 }
1829 catch (e) {
1830 consoleError(e);
1831 }
1832 });
1833 }
1834 }
1835 }
1836 if (BUILD.updatable && (flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1837 if (BUILD.cmpShouldUpdate && instance.componentShouldUpdate) {
1838 if (instance.componentShouldUpdate(newVal, oldVal, propName) === false) {
1839 return;
1840 }
1841 }
1842 // looks like this value actually changed, so we've got work to do!
1843 // but only if we've already rendered, otherwise just chill out
1844 // queue that we need to do an update, but don't worry about queuing
1845 // up millions cuz this function ensures it only runs once
1846 scheduleUpdate(hostRef, false);
1847 }
1848 }
1849 }
1850};
1851const proxyComponent = (Cstr, cmpMeta, flags) => {
1852 if (BUILD.member && cmpMeta.$members$) {
1853 if (BUILD.watchCallback && Cstr.watchers) {
1854 cmpMeta.$watchers$ = Cstr.watchers;
1855 }
1856 // It's better to have a const than two Object.entries()
1857 const members = Object.entries(cmpMeta.$members$);
1858 const prototype = Cstr.prototype;
1859 members.map(([memberName, [memberFlags]]) => {
1860 if ((BUILD.prop || BUILD.state) && (memberFlags & 31 /* Prop */ || ((!BUILD.lazyLoad || flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
1861 // proxyComponent - prop
1862 Object.defineProperty(prototype, memberName, {
1863 get() {
1864 // proxyComponent, get value
1865 return getValue(this, memberName);
1866 },
1867 set(newValue) {
1868 if (
1869 // only during dev time
1870 BUILD.isDev &&
1871 // we are proxing the instance (not element)
1872 (flags & 1 /* isElementConstructor */) === 0 &&
1873 // the member is a non-mutable prop
1874 (memberFlags & (31 /* Prop */ | 1024 /* Mutable */)) === 31 /* Prop */) {
1875 consoleDevWarn(`@Prop() "${memberName}" on "${cmpMeta.$tagName$}" cannot be modified.\nFurther information: https://stenciljs.com/docs/properties#prop-mutability`);
1876 }
1877 // proxyComponent, set value
1878 setValue(this, memberName, newValue, cmpMeta);
1879 },
1880 configurable: true,
1881 enumerable: true,
1882 });
1883 }
1884 else if (BUILD.lazyLoad && BUILD.method && flags & 1 /* isElementConstructor */ && memberFlags & 64 /* Method */) {
1885 // proxyComponent - method
1886 Object.defineProperty(prototype, memberName, {
1887 value(...args) {
1888 const ref = getHostRef(this);
1889 return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
1890 },
1891 });
1892 }
1893 });
1894 if (BUILD.observeAttribute && (!BUILD.lazyLoad || flags & 1 /* isElementConstructor */)) {
1895 const attrNameToPropName = new Map();
1896 prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1897 plt.jmp(() => {
1898 const propName = attrNameToPropName.get(attrName);
1899 this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1900 });
1901 };
1902 // create an array of attributes to observe
1903 // and also create a map of html attribute name to js property name
1904 Cstr.observedAttributes = members
1905 .filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
1906 .map(([propName, m]) => {
1907 const attrName = m[1] || propName;
1908 attrNameToPropName.set(attrName, propName);
1909 if (BUILD.reflect && m[0] & 512 /* ReflectAttr */) {
1910 cmpMeta.$attrsToReflect$.push([propName, attrName]);
1911 }
1912 return attrName;
1913 });
1914 }
1915 }
1916 return Cstr;
1917};
1918const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1919 // initializeComponent
1920 if ((BUILD.lazyLoad || BUILD.hydrateServerSide || BUILD.style) && (hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
1921 // we haven't initialized this element yet
1922 hostRef.$flags$ |= 32 /* hasInitializedComponent */;
1923 if (BUILD.lazyLoad || BUILD.hydrateClientSide) {
1924 // lazy loaded components
1925 // request the component's implementation to be
1926 // wired up with the host element
1927 Cstr = loadModule(cmpMeta, hostRef, hmrVersionId);
1928 if (Cstr.then) {
1929 // Await creates a micro-task avoid if possible
1930 const endLoad = uniqueTime(`st:load:${cmpMeta.$tagName$}:${hostRef.$modeName$}`, `[Stencil] Load module for <${cmpMeta.$tagName$}>`);
1931 Cstr = await Cstr;
1932 endLoad();
1933 }
1934 if ((BUILD.isDev || BUILD.isDebug) && !Cstr) {
1935 throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
1936 }
1937 if (BUILD.member && !Cstr.isProxied) {
1938 // we'eve never proxied this Constructor before
1939 // let's add the getters/setters to its prototype before
1940 // the first time we create an instance of the implementation
1941 if (BUILD.watchCallback) {
1942 cmpMeta.$watchers$ = Cstr.watchers;
1943 }
1944 proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
1945 Cstr.isProxied = true;
1946 }
1947 const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1948 // ok, time to construct the instance
1949 // but let's keep track of when we start and stop
1950 // so that the getters/setters don't incorrectly step on data
1951 if (BUILD.member) {
1952 hostRef.$flags$ |= 8 /* isConstructingInstance */;
1953 }
1954 // construct the lazy-loaded component implementation
1955 // passing the hostRef is very important during
1956 // construction in order to directly wire together the
1957 // host element and the lazy-loaded instance
1958 try {
1959 new Cstr(hostRef);
1960 }
1961 catch (e) {
1962 consoleError(e);
1963 }
1964 if (BUILD.member) {
1965 hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1966 }
1967 if (BUILD.watchCallback) {
1968 hostRef.$flags$ |= 128 /* isWatchReady */;
1969 }
1970 endNewInstance();
1971 fireConnectedCallback(hostRef.$lazyInstance$);
1972 }
1973 else {
1974 Cstr = elm.constructor;
1975 }
1976 if (BUILD.style && Cstr.style) {
1977 // this component has styles but we haven't registered them yet
1978 let style = Cstr.style;
1979 if (BUILD.mode && typeof style !== 'string') {
1980 style = style[(hostRef.$modeName$ = computeMode(elm))];
1981 if (BUILD.hydrateServerSide && hostRef.$modeName$) {
1982 elm.setAttribute('s-mode', hostRef.$modeName$);
1983 }
1984 }
1985 const scopeId = getScopeId(cmpMeta, hostRef.$modeName$);
1986 if (!styles.has(scopeId)) {
1987 const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1988 if (!BUILD.hydrateServerSide && BUILD.shadowDom && BUILD.shadowDomShim && cmpMeta.$flags$ & 8 /* needsShadowDomShim */) {
1989 style = await Promise.resolve().then(function () { return require('./shadow-css-d4b529be.js'); }).then(m => m.scopeCss(style, scopeId, false));
1990 }
1991 registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1992 endRegisterStyles();
1993 }
1994 }
1995 }
1996 // we've successfully created a lazy instance
1997 const ancestorComponent = hostRef.$ancestorComponent$;
1998 const schedule = () => scheduleUpdate(hostRef, true);
1999 if (BUILD.asyncLoading && ancestorComponent && ancestorComponent['s-rc']) {
2000 // this is the intial load and this component it has an ancestor component
2001 // but the ancestor component has NOT fired its will update lifecycle yet
2002 // so let's just cool our jets and wait for the ancestor to continue first
2003 // this will get fired off when the ancestor component
2004 // finally gets around to rendering its lazy self
2005 // fire off the initial update
2006 ancestorComponent['s-rc'].push(schedule);
2007 }
2008 else {
2009 schedule();
2010 }
2011};
2012const fireConnectedCallback = (instance) => {
2013 if (BUILD.lazyLoad && BUILD.connectedCallback) {
2014 safeCall(instance, 'connectedCallback');
2015 }
2016};
2017const connectedCallback = (elm) => {
2018 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
2019 const hostRef = getHostRef(elm);
2020 const cmpMeta = hostRef.$cmpMeta$;
2021 const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
2022 if (BUILD.hostListenerTargetParent) {
2023 // only run if we have listeners being attached to a parent
2024 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, true);
2025 }
2026 if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
2027 // first time this component has connected
2028 hostRef.$flags$ |= 1 /* hasConnected */;
2029 let hostId;
2030 if (BUILD.hydrateClientSide) {
2031 hostId = elm.getAttribute(HYDRATE_ID);
2032 if (hostId) {
2033 if (BUILD.shadowDom && supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2034 const scopeId = BUILD.mode ? addStyle(elm.shadowRoot, cmpMeta, elm.getAttribute('s-mode')) : addStyle(elm.shadowRoot, cmpMeta);
2035 elm.classList.remove(scopeId + '-h', scopeId + '-s');
2036 }
2037 initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
2038 }
2039 }
2040 if (BUILD.slotRelocation && !hostId) {
2041 // initUpdate
2042 // if the slot polyfill is required we'll need to put some nodes
2043 // in here to act as original content anchors as we move nodes around
2044 // host element has been connected to the DOM
2045 if (BUILD.hydrateServerSide || ((BUILD.slot || BUILD.shadowDom) && cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
2046 setContentReference(elm);
2047 }
2048 }
2049 if (BUILD.asyncLoading) {
2050 // find the first ancestor component (if there is one) and register
2051 // this component as one of the actively loading child components for its ancestor
2052 let ancestorComponent = elm;
2053 while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
2054 // climb up the ancestors looking for the first
2055 // component that hasn't finished its lifecycle update yet
2056 if ((BUILD.hydrateClientSide && ancestorComponent.nodeType === 1 /* ElementNode */ && ancestorComponent.hasAttribute('s-id') && ancestorComponent['s-p']) ||
2057 ancestorComponent['s-p']) {
2058 // we found this components first ancestor component
2059 // keep a reference to this component's ancestor component
2060 attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
2061 break;
2062 }
2063 }
2064 }
2065 // Lazy properties
2066 // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2067 if (BUILD.prop && BUILD.lazyLoad && !BUILD.hydrateServerSide && cmpMeta.$members$) {
2068 Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
2069 if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
2070 const value = elm[memberName];
2071 delete elm[memberName];
2072 elm[memberName] = value;
2073 }
2074 });
2075 }
2076 if (BUILD.initializeNextTick) {
2077 // connectedCallback, taskQueue, initialLoad
2078 // angular sets attribute AFTER connectCallback
2079 // https://github.com/angular/angular/issues/18909
2080 // https://github.com/angular/angular/issues/19940
2081 nextTick(() => initializeComponent(elm, hostRef, cmpMeta));
2082 }
2083 else {
2084 initializeComponent(elm, hostRef, cmpMeta);
2085 }
2086 }
2087 else {
2088 // not the first time this has connected
2089 // reattach any event listeners to the host
2090 // since they would have been removed when disconnected
2091 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2092 // fire off connectedCallback() on component instance
2093 fireConnectedCallback(hostRef.$lazyInstance$);
2094 }
2095 endConnected();
2096 }
2097};
2098const setContentReference = (elm) => {
2099 // only required when we're NOT using native shadow dom (slot)
2100 // or this browser doesn't support native shadow dom
2101 // and this host element was NOT created with SSR
2102 // let's pick out the inner content for slot projection
2103 // create a node to represent where the original
2104 // content was first placed, which is useful later on
2105 const contentRefElm = (elm['s-cr'] = doc.createComment(BUILD.isDebug ? `content-ref (host=${elm.localName})` : ''));
2106 contentRefElm['s-cn'] = true;
2107 elm.insertBefore(contentRefElm, elm.firstChild);
2108};
2109const disconnectedCallback = (elm) => {
2110 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
2111 const hostRef = getHostRef(elm);
2112 const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2113 if (BUILD.hostListener) {
2114 if (hostRef.$rmListeners$) {
2115 hostRef.$rmListeners$.map(rmListener => rmListener());
2116 hostRef.$rmListeners$ = undefined;
2117 }
2118 }
2119 // clear CSS var-shim tracking
2120 if (BUILD.cssVarShim && plt.$cssShim$) {
2121 plt.$cssShim$.removeHost(elm);
2122 }
2123 if (BUILD.lazyLoad && BUILD.disconnectedCallback) {
2124 safeCall(instance, 'disconnectedCallback');
2125 }
2126 if (BUILD.cmpDidUnload) {
2127 safeCall(instance, 'componentDidUnload');
2128 }
2129 }
2130};
2131const defineCustomElement = (Cstr, compactMeta) => {
2132 customElements.define(compactMeta[1], proxyCustomElement(Cstr, compactMeta));
2133};
2134const proxyCustomElement = (Cstr, compactMeta) => {
2135 const cmpMeta = {
2136 $flags$: compactMeta[0],
2137 $tagName$: compactMeta[1],
2138 };
2139 if (BUILD.member) {
2140 cmpMeta.$members$ = compactMeta[2];
2141 }
2142 if (BUILD.hostListener) {
2143 cmpMeta.$listeners$ = compactMeta[3];
2144 }
2145 if (BUILD.watchCallback) {
2146 cmpMeta.$watchers$ = Cstr.$watchers$;
2147 }
2148 if (BUILD.reflect) {
2149 cmpMeta.$attrsToReflect$ = [];
2150 }
2151 if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2152 cmpMeta.$flags$ |= 8 /* needsShadowDomShim */;
2153 }
2154 const originalConnectedCallback = Cstr.prototype.connectedCallback;
2155 const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
2156 Object.assign(Cstr.prototype, {
2157 __registerHost() {
2158 registerHost(this, cmpMeta);
2159 },
2160 connectedCallback() {
2161 connectedCallback(this);
2162 if (BUILD.connectedCallback && originalConnectedCallback) {
2163 originalConnectedCallback.call(this);
2164 }
2165 },
2166 disconnectedCallback() {
2167 disconnectedCallback(this);
2168 if (BUILD.disconnectedCallback && originalDisconnectedCallback) {
2169 originalDisconnectedCallback.call(this);
2170 }
2171 },
2172 });
2173 Cstr.is = cmpMeta.$tagName$;
2174 return proxyComponent(Cstr, cmpMeta, 1 /* isElementConstructor */ | 2 /* proxyState */);
2175};
2176const forceModeUpdate = (elm) => {
2177 if (BUILD.style && BUILD.mode && !BUILD.lazyLoad) {
2178 const mode = computeMode(elm);
2179 const hostRef = getHostRef(elm);
2180 if (hostRef.$modeName$ !== mode) {
2181 const cmpMeta = hostRef.$cmpMeta$;
2182 const oldScopeId = elm['s-sc'];
2183 const scopeId = getScopeId(cmpMeta, mode);
2184 const style = elm.constructor.style[mode];
2185 const flags = cmpMeta.$flags$;
2186 if (style) {
2187 if (!styles.has(scopeId)) {
2188 registerStyle(scopeId, style, !!(flags & 1 /* shadowDomEncapsulation */));
2189 }
2190 hostRef.$modeName$ = mode;
2191 elm.classList.remove(oldScopeId + '-h', oldScopeId + '-s');
2192 attachStyles(hostRef);
2193 forceUpdate(elm);
2194 }
2195 }
2196 }
2197};
2198const attachShadow = (el) => {
2199 if (supportsShadow) {
2200 el.attachShadow({ mode: 'open' });
2201 }
2202 else {
2203 el.shadowRoot = el;
2204 }
2205};
2206const hmrStart = (elm, cmpMeta, hmrVersionId) => {
2207 // ¯\_(ツ)_/¯
2208 const hostRef = getHostRef(elm);
2209 // reset state flags to only have been connected
2210 hostRef.$flags$ = 1 /* hasConnected */;
2211 // TODO
2212 // detatch any event listeners that may have been added
2213 // because we're not passing an exact event name it'll
2214 // remove all of this element's event, which is good
2215 // create a callback for when this component finishes hmr
2216 elm['s-hmr-load'] = () => {
2217 // finished hmr for this element
2218 delete elm['s-hmr-load'];
2219 };
2220 // re-initialize the component
2221 initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
2222};
2223const patchCloneNode = (HostElementPrototype) => {
2224 const orgCloneNode = HostElementPrototype.cloneNode;
2225 HostElementPrototype.cloneNode = function (deep) {
2226 const srcNode = this;
2227 const isShadowDom = BUILD.shadowDom ? srcNode.shadowRoot && supportsShadow : false;
2228 const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
2229 if (BUILD.slot && !isShadowDom && deep) {
2230 let i = 0;
2231 let slotted;
2232 for (; i < srcNode.childNodes.length; i++) {
2233 slotted = srcNode.childNodes[i]['s-nr'];
2234 if (slotted) {
2235 if (BUILD.appendChildSlotFix && clonedNode.__appendChild) {
2236 clonedNode.__appendChild(slotted.cloneNode(true));
2237 }
2238 else {
2239 clonedNode.appendChild(slotted.cloneNode(true));
2240 }
2241 }
2242 }
2243 }
2244 return clonedNode;
2245 };
2246};
2247const patchSlotAppendChild = (HostElementPrototype) => {
2248 HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
2249 HostElementPrototype.appendChild = function (newChild) {
2250 const slotName = (newChild['s-sn'] = getSlotName(newChild));
2251 const slotNode = getHostSlotNode(this.childNodes, slotName);
2252 if (slotNode) {
2253 const slotChildNodes = getHostSlotChildNodes(slotNode, slotName);
2254 const appendAfter = slotChildNodes[slotChildNodes.length - 1];
2255 return appendAfter.parentNode.insertBefore(newChild, appendAfter.nextSibling);
2256 }
2257 return this.__appendChild(newChild);
2258 };
2259};
2260const patchChildSlotNodes = (elm, cmpMeta) => {
2261 class FakeNodeList extends Array {
2262 item(n) {
2263 return this[n];
2264 }
2265 }
2266 if (cmpMeta.$flags$ & 8 /* needsShadowDomShim */) {
2267 const childNodesFn = elm.__lookupGetter__('childNodes');
2268 Object.defineProperty(elm, 'children', {
2269 get() {
2270 return this.childNodes.map((n) => n.nodeType === 1);
2271 },
2272 });
2273 Object.defineProperty(elm, 'childElementCount', {
2274 get() {
2275 return elm.children.length;
2276 },
2277 });
2278 Object.defineProperty(elm, 'childNodes', {
2279 get() {
2280 const childNodes = childNodesFn.call(this);
2281 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0 && getHostRef(this).$flags$ & 2 /* hasRendered */) {
2282 const result = new FakeNodeList();
2283 for (let i = 0; i < childNodes.length; i++) {
2284 const slot = childNodes[i]['s-nr'];
2285 if (slot) {
2286 result.push(slot);
2287 }
2288 }
2289 return result;
2290 }
2291 return FakeNodeList.from(childNodes);
2292 },
2293 });
2294 }
2295};
2296const getSlotName = (node) => node['s-sn'] || (node.nodeType === 1 && node.getAttribute('slot')) || '';
2297const getHostSlotNode = (childNodes, slotName) => {
2298 let i = 0;
2299 let childNode;
2300 for (; i < childNodes.length; i++) {
2301 childNode = childNodes[i];
2302 if (childNode['s-sr'] && childNode['s-sn'] === slotName) {
2303 return childNode;
2304 }
2305 childNode = getHostSlotNode(childNode.childNodes, slotName);
2306 if (childNode) {
2307 return childNode;
2308 }
2309 }
2310 return null;
2311};
2312const getHostSlotChildNodes = (n, slotName) => {
2313 const childNodes = [n];
2314 while ((n = n.nextSibling) && n['s-sn'] === slotName) {
2315 childNodes.push(n);
2316 }
2317 return childNodes;
2318};
2319const bootstrapLazy = (lazyBundles, options = {}) => {
2320 if (BUILD.profile && performance.mark) {
2321 performance.mark('st:app:start');
2322 }
2323 installDevTools();
2324 const endBootstrap = createTime('bootstrapLazy');
2325 const cmpTags = [];
2326 const exclude = options.exclude || [];
2327 const customElements = win.customElements;
2328 const head = doc.head;
2329 const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
2330 const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
2331 const deferredConnectedCallbacks = [];
2332 const styles = /*@__PURE__*/ doc.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
2333 let appLoadFallback;
2334 let isBootstrapping = true;
2335 let i = 0;
2336 Object.assign(plt, options);
2337 plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
2338 if (BUILD.asyncQueue) {
2339 if (options.syncQueue) {
2340 plt.$flags$ |= 4 /* queueSync */;
2341 }
2342 }
2343 if (BUILD.hydrateClientSide) {
2344 // If the app is already hydrated there is not point to disable the
2345 // async queue. This will improve the first input delay
2346 plt.$flags$ |= 2 /* appLoaded */;
2347 }
2348 if (BUILD.hydrateClientSide && BUILD.shadowDom) {
2349 for (; i < styles.length; i++) {
2350 registerStyle(styles[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styles[i].innerHTML), true);
2351 }
2352 }
2353 lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
2354 const cmpMeta = {
2355 $flags$: compactMeta[0],
2356 $tagName$: compactMeta[1],
2357 $members$: compactMeta[2],
2358 $listeners$: compactMeta[3],
2359 };
2360 if (BUILD.member) {
2361 cmpMeta.$members$ = compactMeta[2];
2362 }
2363 if (BUILD.hostListener) {
2364 cmpMeta.$listeners$ = compactMeta[3];
2365 }
2366 if (BUILD.reflect) {
2367 cmpMeta.$attrsToReflect$ = [];
2368 }
2369 if (BUILD.watchCallback) {
2370 cmpMeta.$watchers$ = {};
2371 }
2372 if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2373 cmpMeta.$flags$ |= 8 /* needsShadowDomShim */;
2374 }
2375 const tagName = BUILD.transformTagName && options.transformTagName ? options.transformTagName(cmpMeta.$tagName$) : cmpMeta.$tagName$;
2376 const HostElement = class extends HTMLElement {
2377 // StencilLazyHost
2378 constructor(self) {
2379 // @ts-ignore
2380 super(self);
2381 self = this;
2382 registerHost(self, cmpMeta);
2383 if (BUILD.shadowDom && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2384 // this component is using shadow dom
2385 // and this browser supports shadow dom
2386 // add the read-only property "shadowRoot" to the host element
2387 // adding the shadow root build conditionals to minimize runtime
2388 if (supportsShadow) {
2389 if (BUILD.shadowDelegatesFocus) {
2390 self.attachShadow({
2391 mode: 'open',
2392 delegatesFocus: !!(cmpMeta.$flags$ & 16 /* shadowDelegatesFocus */),
2393 });
2394 }
2395 else {
2396 self.attachShadow({ mode: 'open' });
2397 }
2398 }
2399 else if (!BUILD.hydrateServerSide && !('shadowRoot' in self)) {
2400 self.shadowRoot = self;
2401 }
2402 }
2403 if (BUILD.slotChildNodesFix) {
2404 patchChildSlotNodes(self, cmpMeta);
2405 }
2406 }
2407 connectedCallback() {
2408 if (appLoadFallback) {
2409 clearTimeout(appLoadFallback);
2410 appLoadFallback = null;
2411 }
2412 if (isBootstrapping) {
2413 // connectedCallback will be processed once all components have been registered
2414 deferredConnectedCallbacks.push(this);
2415 }
2416 else {
2417 plt.jmp(() => connectedCallback(this));
2418 }
2419 }
2420 disconnectedCallback() {
2421 plt.jmp(() => disconnectedCallback(this));
2422 }
2423 forceUpdate() {
2424 if (BUILD.isDev) {
2425 consoleDevWarn(`element.forceUpdate() is deprecated, use the "forceUpdate" function from "@stencil/core" instead:
2426
2427 import { forceUpdate } from ‘@stencil/core’;
2428
2429 forceUpdate(this);
2430 forceUpdate(element);`);
2431 }
2432 forceUpdate(this);
2433 }
2434 componentOnReady() {
2435 return getHostRef(this).$onReadyPromise$;
2436 }
2437 };
2438 if (BUILD.cloneNodeFix) {
2439 patchCloneNode(HostElement.prototype);
2440 }
2441 if (BUILD.appendChildSlotFix) {
2442 patchSlotAppendChild(HostElement.prototype);
2443 }
2444 if (BUILD.hotModuleReplacement) {
2445 HostElement.prototype['s-hmr'] = function (hmrVersionId) {
2446 hmrStart(this, cmpMeta, hmrVersionId);
2447 };
2448 }
2449 cmpMeta.$lazyBundleId$ = lazyBundle[0];
2450 if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2451 cmpTags.push(tagName);
2452 customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
2453 }
2454 }));
2455 if (BUILD.hydratedClass || BUILD.hydratedAttribute) {
2456 visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
2457 visibilityStyle.setAttribute('data-styles', '');
2458 head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
2459 }
2460 // Process deferred connectedCallbacks now all components have been registered
2461 isBootstrapping = false;
2462 if (deferredConnectedCallbacks.length) {
2463 deferredConnectedCallbacks.map(host => host.connectedCallback());
2464 }
2465 else {
2466 if (BUILD.profile) {
2467 plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30, 'timeout')));
2468 }
2469 else {
2470 plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
2471 }
2472 }
2473 // Fallback appLoad event
2474 endBootstrap();
2475};
2476const getAssetPath = (path) => {
2477 const assetUrl = new URL(path, plt.$resourcesUrl$);
2478 return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
2479};
2480const getConnect = (_ref, tagName) => {
2481 const componentOnReady = () => {
2482 let elm = doc.querySelector(tagName);
2483 if (!elm) {
2484 elm = doc.createElement(tagName);
2485 doc.body.appendChild(elm);
2486 }
2487 return typeof elm.componentOnReady === 'function' ? elm.componentOnReady() : Promise.resolve(elm);
2488 };
2489 const create = (...args) => {
2490 return componentOnReady().then(el => el.create(...args));
2491 };
2492 return {
2493 create,
2494 componentOnReady,
2495 };
2496};
2497const getContext = (_elm, context) => {
2498 if (context in Context) {
2499 return Context[context];
2500 }
2501 else if (context === 'window') {
2502 return win;
2503 }
2504 else if (context === 'document') {
2505 return doc;
2506 }
2507 else if (context === 'isServer' || context === 'isPrerender') {
2508 return BUILD.hydrateServerSide ? true : false;
2509 }
2510 else if (context === 'isClient') {
2511 return BUILD.hydrateServerSide ? false : true;
2512 }
2513 else if (context === 'resourcesUrl' || context === 'publicPath') {
2514 return getAssetPath('.');
2515 }
2516 else if (context === 'queue') {
2517 return {
2518 write: writeTask,
2519 read: readTask,
2520 tick: {
2521 then(cb) {
2522 return nextTick(cb);
2523 },
2524 },
2525 };
2526 }
2527 return undefined;
2528};
2529const insertVdomAnnotations = (doc, staticComponents) => {
2530 if (doc != null) {
2531 const docData = {
2532 hostIds: 0,
2533 rootLevelIds: 0,
2534 staticComponents: new Set(staticComponents),
2535 };
2536 const orgLocationNodes = [];
2537 parseVNodeAnnotations(doc, doc.body, docData, orgLocationNodes);
2538 orgLocationNodes.forEach(orgLocationNode => {
2539 if (orgLocationNode != null) {
2540 const nodeRef = orgLocationNode['s-nr'];
2541 let hostId = nodeRef['s-host-id'];
2542 let nodeId = nodeRef['s-node-id'];
2543 let childId = `${hostId}.${nodeId}`;
2544 if (hostId == null) {
2545 hostId = 0;
2546 docData.rootLevelIds++;
2547 nodeId = docData.rootLevelIds;
2548 childId = `${hostId}.${nodeId}`;
2549 if (nodeRef.nodeType === 1 /* ElementNode */) {
2550 nodeRef.setAttribute(HYDRATE_CHILD_ID, childId);
2551 }
2552 else if (nodeRef.nodeType === 3 /* TextNode */) {
2553 if (hostId === 0) {
2554 const textContent = nodeRef.nodeValue.trim();
2555 if (textContent === '') {
2556 // useless whitespace node at the document root
2557 orgLocationNode.remove();
2558 return;
2559 }
2560 }
2561 const commentBeforeTextNode = doc.createComment(childId);
2562 commentBeforeTextNode.nodeValue = `${TEXT_NODE_ID}.${childId}`;
2563 nodeRef.parentNode.insertBefore(commentBeforeTextNode, nodeRef);
2564 }
2565 }
2566 let orgLocationNodeId = `${ORG_LOCATION_ID}.${childId}`;
2567 const orgLocationParentNode = orgLocationNode.parentElement;
2568 if (orgLocationParentNode) {
2569 if (orgLocationParentNode['s-en'] === '') {
2570 // ending with a "." means that the parent element
2571 // of this node's original location is a SHADOW dom element
2572 // and this node is apart of the root level light dom
2573 orgLocationNodeId += `.`;
2574 }
2575 else if (orgLocationParentNode['s-en'] === 'c') {
2576 // ending with a ".c" means that the parent element
2577 // of this node's original location is a SCOPED element
2578 // and this node is apart of the root level light dom
2579 orgLocationNodeId += `.c`;
2580 }
2581 }
2582 orgLocationNode.nodeValue = orgLocationNodeId;
2583 }
2584 });
2585 }
2586};
2587const parseVNodeAnnotations = (doc, node, docData, orgLocationNodes) => {
2588 if (node == null) {
2589 return;
2590 }
2591 if (node['s-nr'] != null) {
2592 orgLocationNodes.push(node);
2593 }
2594 if (node.nodeType === 1 /* ElementNode */) {
2595 node.childNodes.forEach(childNode => {
2596 const hostRef = getHostRef(childNode);
2597 if (hostRef != null && !docData.staticComponents.has(childNode.nodeName.toLowerCase())) {
2598 const cmpData = {
2599 nodeIds: 0,
2600 };
2601 insertVNodeAnnotations(doc, childNode, hostRef.$vnode$, docData, cmpData);
2602 }
2603 parseVNodeAnnotations(doc, childNode, docData, orgLocationNodes);
2604 });
2605 }
2606};
2607const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
2608 if (vnode != null) {
2609 const hostId = ++docData.hostIds;
2610 hostElm.setAttribute(HYDRATE_ID, hostId);
2611 if (hostElm['s-cr'] != null) {
2612 hostElm['s-cr'].nodeValue = `${CONTENT_REF_ID}.${hostId}`;
2613 }
2614 if (vnode.$children$ != null) {
2615 const depth = 0;
2616 vnode.$children$.forEach((vnodeChild, index) => {
2617 insertChildVNodeAnnotations(doc, vnodeChild, cmpData, hostId, depth, index);
2618 });
2619 }
2620 if (hostElm && vnode && vnode.$elm$ && !hostElm.hasAttribute('c-id')) {
2621 const parent = hostElm.parentElement;
2622 if (parent && parent.childNodes) {
2623 const parentChildNodes = Array.from(parent.childNodes);
2624 const comment = parentChildNodes.find(node => node.nodeType === 8 /* CommentNode */ && node['s-sr']);
2625 if (comment) {
2626 const index = parentChildNodes.indexOf(hostElm) - 1;
2627 vnode.$elm$.setAttribute(HYDRATE_CHILD_ID, `${comment['s-host-id']}.${comment['s-node-id']}.0.${index}`);
2628 }
2629 }
2630 }
2631 }
2632};
2633const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, index) => {
2634 const childElm = vnodeChild.$elm$;
2635 if (childElm == null) {
2636 return;
2637 }
2638 const nodeId = cmpData.nodeIds++;
2639 const childId = `${hostId}.${nodeId}.${depth}.${index}`;
2640 childElm['s-host-id'] = hostId;
2641 childElm['s-node-id'] = nodeId;
2642 if (childElm.nodeType === 1 /* ElementNode */) {
2643 childElm.setAttribute(HYDRATE_CHILD_ID, childId);
2644 }
2645 else if (childElm.nodeType === 3 /* TextNode */) {
2646 const parentNode = childElm.parentNode;
2647 if (parentNode.nodeName !== 'STYLE') {
2648 const textNodeId = `${TEXT_NODE_ID}.${childId}`;
2649 const commentBeforeTextNode = doc.createComment(textNodeId);
2650 parentNode.insertBefore(commentBeforeTextNode, childElm);
2651 }
2652 }
2653 else if (childElm.nodeType === 8 /* CommentNode */) {
2654 if (childElm['s-sr']) {
2655 const slotName = childElm['s-sn'] || '';
2656 const slotNodeId = `${SLOT_NODE_ID}.${childId}.${slotName}`;
2657 childElm.nodeValue = slotNodeId;
2658 }
2659 }
2660 if (vnodeChild.$children$ != null) {
2661 const childDepth = depth + 1;
2662 vnodeChild.$children$.forEach((vnode, index) => {
2663 insertChildVNodeAnnotations(doc, vnode, cmpData, hostId, childDepth, index);
2664 });
2665 }
2666};
2667const hostRefs = new WeakMap();
2668const getHostRef = (ref) => hostRefs.get(ref);
2669const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
2670const registerHost = (elm, cmpMeta) => {
2671 const hostRef = {
2672 $flags$: 0,
2673 $hostElement$: elm,
2674 $cmpMeta$: cmpMeta,
2675 $instanceValues$: new Map(),
2676 };
2677 if (BUILD.isDev) {
2678 hostRef.$renderCount$ = 0;
2679 }
2680 if (BUILD.method && BUILD.lazyLoad) {
2681 hostRef.$onInstancePromise$ = new Promise(r => (hostRef.$onInstanceResolve$ = r));
2682 }
2683 if (BUILD.asyncLoading) {
2684 hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
2685 elm['s-p'] = [];
2686 elm['s-rc'] = [];
2687 }
2688 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2689 return hostRefs.set(elm, hostRef);
2690};
2691const isMemberInElement = (elm, memberName) => memberName in elm;
2692const STENCIL_DEV_MODE = BUILD.isTesting
2693 ? ['STENCIL:'] // E2E testing
2694 : ['%cstencil', 'color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px'];
2695const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
2696const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
2697const consoleDevInfo = (...m) => console.info(...STENCIL_DEV_MODE, ...m);
2698const consoleError = (e) => console.error(e);
2699const cmpModules = /*@__PURE__*/ new Map();
2700const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
2701 // loadModuleImport
2702 const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
2703 const bundleId = cmpMeta.$lazyBundleId$;
2704 if (BUILD.isDev && typeof bundleId !== 'string') {
2705 consoleDevError(`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`);
2706 return undefined;
2707 }
2708 const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
2709 if (module) {
2710 return module[exportName];
2711 }
2712 return Promise.resolve().then(function () { return _interopNamespace(require(
2713 /* webpackInclude: /\.entry\.js$/ */
2714 /* webpackExclude: /\.system\.entry\.js$/ */
2715 /* webpackMode: "lazy" */
2716 `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`)); }).then(importedModule => {
2717 if (!BUILD.hotModuleReplacement) {
2718 cmpModules.set(bundleId, importedModule);
2719 }
2720 return importedModule[exportName];
2721 }, consoleError);
2722};
2723const styles = new Map();
2724const modeResolutionChain = [];
2725const queueDomReads = [];
2726const queueDomWrites = [];
2727const queueDomWritesLow = [];
2728const queueTask = (queue, write) => (cb) => {
2729 queue.push(cb);
2730 if (!queuePending) {
2731 queuePending = true;
2732 if (write && plt.$flags$ & 4 /* queueSync */) {
2733 nextTick(flush);
2734 }
2735 else {
2736 plt.raf(flush);
2737 }
2738 }
2739};
2740const consume = (queue) => {
2741 for (let i = 0; i < queue.length; i++) {
2742 try {
2743 queue[i](performance.now());
2744 }
2745 catch (e) {
2746 consoleError(e);
2747 }
2748 }
2749 queue.length = 0;
2750};
2751const consumeTimeout = (queue, timeout) => {
2752 let i = 0;
2753 let ts = 0;
2754 while (i < queue.length && (ts = performance.now()) < timeout) {
2755 try {
2756 queue[i++](ts);
2757 }
2758 catch (e) {
2759 consoleError(e);
2760 }
2761 }
2762 if (i === queue.length) {
2763 queue.length = 0;
2764 }
2765 else if (i !== 0) {
2766 queue.splice(0, i);
2767 }
2768};
2769const flush = () => {
2770 if (BUILD.asyncQueue) {
2771 queueCongestion++;
2772 }
2773 // always force a bunch of medium callbacks to run, but still have
2774 // a throttle on how many can run in a certain time
2775 // DOM READS!!!
2776 consume(queueDomReads);
2777 // DOM WRITES!!!
2778 if (BUILD.asyncQueue) {
2779 const timeout = (plt.$flags$ & 6 /* queueMask */) === 2 /* appLoaded */ ? performance.now() + 14 * Math.ceil(queueCongestion * (1.0 / 10.0)) : Infinity;
2780 consumeTimeout(queueDomWrites, timeout);
2781 consumeTimeout(queueDomWritesLow, timeout);
2782 if (queueDomWrites.length > 0) {
2783 queueDomWritesLow.push(...queueDomWrites);
2784 queueDomWrites.length = 0;
2785 }
2786 if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
2787 // still more to do yet, but we've run out of time
2788 // let's let this thing cool off and try again in the next tick
2789 plt.raf(flush);
2790 }
2791 else {
2792 queueCongestion = 0;
2793 }
2794 }
2795 else {
2796 consume(queueDomWrites);
2797 if ((queuePending = queueDomReads.length > 0)) {
2798 // still more to do yet, but we've run out of time
2799 // let's let this thing cool off and try again in the next tick
2800 plt.raf(flush);
2801 }
2802 }
2803};
2804const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
2805const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
2806const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
2807const Build = {
2808 isDev: BUILD.isDev ? true : false,
2809 isBrowser: true,
2810 isServer: false,
2811 isTesting: BUILD.isTesting ? true : false,
2812};
2813
2814exports.BUILD = BUILD;
2815exports.CSS = CSS;
2816exports.H = H;
2817exports.Host = Host;
2818exports.NAMESPACE = NAMESPACE;
2819exports.bootstrapLazy = bootstrapLazy;
2820exports.consoleDevInfo = consoleDevInfo;
2821exports.doc = doc;
2822exports.h = h;
2823exports.plt = plt;
2824exports.promiseResolve = promiseResolve;
2825exports.registerInstance = registerInstance;
2826exports.win = win;