UNPKG

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