UNPKG

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