UNPKG

31.6 kBJavaScriptView Raw
1const NAMESPACE = 'jb-deckdeckgo';
2
3let scopeId;
4let hostTagName;
5let isSvgMode = false;
6let queuePending = false;
7const win = typeof window !== 'undefined' ? window : {};
8const doc = win.document || { head: {} };
9const plt = {
10 $flags$: 0,
11 $resourcesUrl$: '',
12 jmp: h => h(),
13 raf: h => requestAnimationFrame(h),
14 ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
15 rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
16 ce: (eventName, opts) => new CustomEvent(eventName, opts),
17};
18const promiseResolve = (v) => Promise.resolve(v);
19const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
20 try {
21 new CSSStyleSheet();
22 return typeof (new CSSStyleSheet()).replace === 'function';
23 }
24 catch (e) { }
25 return false;
26 })()
27 ;
28const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
29const createTime = (fnName, tagName = '') => {
30 {
31 return () => {
32 return;
33 };
34 }
35};
36const uniqueTime = (key, measureText) => {
37 {
38 return () => {
39 return;
40 };
41 }
42};
43const rootAppliedStyles = new WeakMap();
44const registerStyle = (scopeId, cssText, allowCS) => {
45 let style = styles.get(scopeId);
46 if (supportsConstructibleStylesheets && allowCS) {
47 style = (style || new CSSStyleSheet());
48 style.replace(cssText);
49 }
50 else {
51 style = cssText;
52 }
53 styles.set(scopeId, style);
54};
55const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
56 let scopeId = getScopeId(cmpMeta);
57 let style = styles.get(scopeId);
58 // if an element is NOT connected then getRootNode() will return the wrong root node
59 // so the fallback is to always use the document for the root node in those cases
60 styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
61 if (style) {
62 if (typeof style === 'string') {
63 styleContainerNode = styleContainerNode.head || styleContainerNode;
64 let appliedStyles = rootAppliedStyles.get(styleContainerNode);
65 let styleElm;
66 if (!appliedStyles) {
67 rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
68 }
69 if (!appliedStyles.has(scopeId)) {
70 {
71 {
72 styleElm = doc.createElement('style');
73 styleElm.innerHTML = style;
74 }
75 styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
76 }
77 if (appliedStyles) {
78 appliedStyles.add(scopeId);
79 }
80 }
81 }
82 else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
83 styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
84 }
85 }
86 return scopeId;
87};
88const attachStyles = (hostRef) => {
89 const cmpMeta = hostRef.$cmpMeta$;
90 const elm = hostRef.$hostElement$;
91 const flags = cmpMeta.$flags$;
92 const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
93 const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
94 if (flags & 10 /* needsScopedEncapsulation */) {
95 // only required when we're NOT using native shadow dom (slot)
96 // or this browser doesn't support native shadow dom
97 // and this host element was NOT created with SSR
98 // let's pick out the inner content for slot projection
99 // create a node to represent where the original
100 // content was first placed, which is useful later on
101 // DOM WRITE!!
102 elm['s-sc'] = scopeId;
103 elm.classList.add(scopeId + '-h');
104 }
105 endAttachStyles();
106};
107const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
108/**
109 * Default style mode id
110 */
111/**
112 * Reusable empty obj/array
113 * Don't add values to these!!
114 */
115const EMPTY_OBJ = {};
116const isDef = (v) => v != null;
117const isComplexType = (o) => {
118 // https://jsperf.com/typeof-fn-object/5
119 o = typeof o;
120 return o === 'object' || o === 'function';
121};
122/**
123 * Production h() function based on Preact by
124 * Jason Miller (@developit)
125 * Licensed under the MIT License
126 * https://github.com/developit/preact/blob/master/LICENSE
127 *
128 * Modified for Stencil's compiler and vdom
129 */
130// const stack: any[] = [];
131// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
132// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
133const h = (nodeName, vnodeData, ...children) => {
134 let child = null;
135 let simple = false;
136 let lastSimple = false;
137 let vNodeChildren = [];
138 const walk = (c) => {
139 for (let i = 0; i < c.length; i++) {
140 child = c[i];
141 if (Array.isArray(child)) {
142 walk(child);
143 }
144 else if (child != null && typeof child !== 'boolean') {
145 if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
146 child = String(child);
147 }
148 if (simple && lastSimple) {
149 // If the previous child was simple (string), we merge both
150 vNodeChildren[vNodeChildren.length - 1].$text$ += child;
151 }
152 else {
153 // Append a new vNode, if it's text, we create a text vNode
154 vNodeChildren.push(simple ? newVNode(null, child) : child);
155 }
156 lastSimple = simple;
157 }
158 }
159 };
160 walk(children);
161 if (vnodeData) {
162 {
163 const classData = vnodeData.className || vnodeData.class;
164 if (classData) {
165 vnodeData.class =
166 typeof classData !== 'object'
167 ? classData
168 : Object.keys(classData)
169 .filter(k => classData[k])
170 .join(' ');
171 }
172 }
173 }
174 if (typeof nodeName === 'function') {
175 // nodeName is a functional component
176 return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
177 }
178 const vnode = newVNode(nodeName, null);
179 vnode.$attrs$ = vnodeData;
180 if (vNodeChildren.length > 0) {
181 vnode.$children$ = vNodeChildren;
182 }
183 return vnode;
184};
185const newVNode = (tag, text) => {
186 const vnode = {
187 $flags$: 0,
188 $tag$: tag,
189 $text$: text,
190 $elm$: null,
191 $children$: null,
192 };
193 {
194 vnode.$attrs$ = null;
195 }
196 return vnode;
197};
198const Host = {};
199const isHost = (node) => node && node.$tag$ === Host;
200const vdomFnUtils = {
201 forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
202 map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
203};
204const convertToPublic = (node) => ({
205 vattrs: node.$attrs$,
206 vchildren: node.$children$,
207 vkey: node.$key$,
208 vname: node.$name$,
209 vtag: node.$tag$,
210 vtext: node.$text$,
211});
212const convertToPrivate = (node) => {
213 if (typeof node.vtag === 'function') {
214 const vnodeData = Object.assign({}, node.vattrs);
215 if (node.vkey) {
216 vnodeData.key = node.vkey;
217 }
218 if (node.vname) {
219 vnodeData.name = node.vname;
220 }
221 return h(node.vtag, vnodeData, ...(node.vchildren || []));
222 }
223 const vnode = newVNode(node.vtag, node.vtext);
224 vnode.$attrs$ = node.vattrs;
225 vnode.$children$ = node.vchildren;
226 vnode.$key$ = node.vkey;
227 vnode.$name$ = node.vname;
228 return vnode;
229};
230/**
231 * Production setAccessor() function based on Preact by
232 * Jason Miller (@developit)
233 * Licensed under the MIT License
234 * https://github.com/developit/preact/blob/master/LICENSE
235 *
236 * Modified for Stencil's compiler and vdom
237 */
238const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
239 if (oldValue !== newValue) {
240 let isProp = isMemberInElement(elm, memberName);
241 memberName.toLowerCase();
242 if (memberName === 'class') {
243 const classList = elm.classList;
244 const oldClasses = parseClassList(oldValue);
245 const newClasses = parseClassList(newValue);
246 classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
247 classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
248 }
249 else {
250 // Set property if it exists and it's not a SVG
251 const isComplex = isComplexType(newValue);
252 if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
253 try {
254 if (!elm.tagName.includes('-')) {
255 let n = newValue == null ? '' : newValue;
256 // Workaround for Safari, moving the <input> caret when re-assigning the same valued
257 if (memberName === 'list') {
258 isProp = false;
259 // tslint:disable-next-line: triple-equals
260 }
261 else if (oldValue == null || elm[memberName] != n) {
262 elm[memberName] = n;
263 }
264 }
265 else {
266 elm[memberName] = newValue;
267 }
268 }
269 catch (e) { }
270 }
271 if (newValue == null || newValue === false) {
272 if (newValue !== false || elm.getAttribute(memberName) === '') {
273 {
274 elm.removeAttribute(memberName);
275 }
276 }
277 }
278 else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
279 newValue = newValue === true ? '' : newValue;
280 {
281 elm.setAttribute(memberName, newValue);
282 }
283 }
284 }
285 }
286};
287const parseClassListRegex = /\s/;
288const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
289const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
290 // if the element passed in is a shadow root, which is a document fragment
291 // then we want to be adding attrs/props to the shadow root's "host" element
292 // if it's not a shadow root, then we add attrs/props to the same element
293 const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
294 const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
295 const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
296 // add new & update changed attributes
297 for (memberName in newVnodeAttrs) {
298 setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
299 }
300};
301const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
302 // tslint:disable-next-line: prefer-const
303 let newVNode = newParentVNode.$children$[childIndex];
304 let i = 0;
305 let elm;
306 let childNode;
307 if (newVNode.$text$ !== null) {
308 // create text node
309 elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
310 }
311 else {
312 // create element
313 elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
314 // add css classes, attrs, props, listeners, etc.
315 {
316 updateElement(null, newVNode, isSvgMode);
317 }
318 if (isDef(scopeId) && elm['s-si'] !== scopeId) {
319 // if there is a scopeId and this is the initial render
320 // then let's add the scopeId as a css class
321 elm.classList.add((elm['s-si'] = scopeId));
322 }
323 if (newVNode.$children$) {
324 for (i = 0; i < newVNode.$children$.length; ++i) {
325 // create the node
326 childNode = createElm(oldParentVNode, newVNode, i);
327 // return node could have been null
328 if (childNode) {
329 // append our new node
330 elm.appendChild(childNode);
331 }
332 }
333 }
334 }
335 return elm;
336};
337const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
338 let containerElm = (parentElm);
339 let childNode;
340 if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
341 containerElm = containerElm.shadowRoot;
342 }
343 for (; startIdx <= endIdx; ++startIdx) {
344 if (vnodes[startIdx]) {
345 childNode = createElm(null, parentVNode, startIdx);
346 if (childNode) {
347 vnodes[startIdx].$elm$ = childNode;
348 containerElm.insertBefore(childNode, before);
349 }
350 }
351 }
352};
353const patch = (oldVNode, newVNode) => {
354 const elm = (newVNode.$elm$ = oldVNode.$elm$);
355 const newChildren = newVNode.$children$;
356 const tag = newVNode.$tag$;
357 const text = newVNode.$text$;
358 if (text === null) {
359 // element node
360 {
361 if (tag === 'slot')
362 ;
363 else {
364 // either this is the first render of an element OR it's an update
365 // AND we already know it's possible it could have changed
366 // this updates the element's css classes, attrs, props, listeners, etc.
367 updateElement(oldVNode, newVNode, isSvgMode);
368 }
369 }
370 if (newChildren !== null) {
371 // add the new vnode children
372 addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
373 }
374 else ;
375 }
376 else if (oldVNode.$text$ !== text) {
377 // update the text content for the text only vnode
378 // and also only if the text is different than before
379 elm.data = text;
380 }
381};
382const renderVdom = (hostRef, renderFnResults) => {
383 const hostElm = hostRef.$hostElement$;
384 const oldVNode = hostRef.$vnode$ || newVNode(null, null);
385 const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
386 hostTagName = hostElm.tagName;
387 rootVnode.$tag$ = null;
388 rootVnode.$flags$ |= 4 /* isHost */;
389 hostRef.$vnode$ = rootVnode;
390 rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
391 {
392 scopeId = hostElm['s-sc'];
393 }
394 // synchronous patch
395 patch(oldVNode, rootVnode);
396};
397const getElement = (ref) => (getHostRef(ref).$hostElement$ );
398const createEvent = (ref, name, flags) => {
399 const elm = getElement(ref);
400 return {
401 emit: (detail) => {
402 return emitEvent(elm, name, {
403 bubbles: !!(flags & 4 /* Bubbles */),
404 composed: !!(flags & 2 /* Composed */),
405 cancelable: !!(flags & 1 /* Cancellable */),
406 detail,
407 });
408 },
409 };
410};
411const emitEvent = (elm, name, opts) => {
412 const ev = plt.ce(name, opts);
413 elm.dispatchEvent(ev);
414 return ev;
415};
416const attachToAncestor = (hostRef, ancestorComponent) => {
417 if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
418 ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
419 }
420};
421const scheduleUpdate = (hostRef, isInitialLoad) => {
422 if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
423 hostRef.$flags$ |= 512 /* needsRerender */;
424 return;
425 }
426 attachToAncestor(hostRef, hostRef.$ancestorComponent$);
427 // there is no ancestor component or the ancestor component
428 // has already fired off its lifecycle update then
429 // fire off the initial update
430 const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
431 return writeTask(dispatch) ;
432};
433const dispatchHooks = (hostRef, isInitialLoad) => {
434 const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
435 const instance = hostRef.$lazyInstance$ ;
436 let promise;
437 endSchedule();
438 return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
439};
440const updateComponent = async (hostRef, instance, isInitialLoad) => {
441 // updateComponent
442 const elm = hostRef.$hostElement$;
443 const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
444 const rc = elm['s-rc'];
445 if (isInitialLoad) {
446 // DOM WRITE!
447 attachStyles(hostRef);
448 }
449 const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
450 {
451 callRender(hostRef, instance);
452 }
453 if (rc) {
454 // ok, so turns out there are some child host elements
455 // waiting on this parent element to load
456 // let's fire off all update callbacks waiting
457 rc.map(cb => cb());
458 elm['s-rc'] = undefined;
459 }
460 endRender();
461 endUpdate();
462 {
463 const childrenPromises = elm['s-p'];
464 const postUpdate = () => postUpdateComponent(hostRef);
465 if (childrenPromises.length === 0) {
466 postUpdate();
467 }
468 else {
469 Promise.all(childrenPromises).then(postUpdate);
470 hostRef.$flags$ |= 4 /* isWaitingForChildren */;
471 childrenPromises.length = 0;
472 }
473 }
474};
475const callRender = (hostRef, instance, elm) => {
476 try {
477 instance = instance.render() ;
478 {
479 hostRef.$flags$ |= 2 /* hasRendered */;
480 }
481 {
482 {
483 // looks like we've got child nodes to render into this host element
484 // or we need to update the css class/attrs on the host element
485 // DOM WRITE!
486 {
487 renderVdom(hostRef, instance);
488 }
489 }
490 }
491 }
492 catch (e) {
493 consoleError(e, hostRef.$hostElement$);
494 }
495 return null;
496};
497const postUpdateComponent = (hostRef) => {
498 const tagName = hostRef.$cmpMeta$.$tagName$;
499 const elm = hostRef.$hostElement$;
500 const endPostUpdate = createTime('postUpdate', tagName);
501 const instance = hostRef.$lazyInstance$ ;
502 const ancestorComponent = hostRef.$ancestorComponent$;
503 if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
504 hostRef.$flags$ |= 64 /* hasLoadedComponent */;
505 {
506 // DOM WRITE!
507 addHydratedFlag(elm);
508 }
509 {
510 safeCall(instance, 'componentDidLoad');
511 }
512 endPostUpdate();
513 {
514 hostRef.$onReadyResolve$(elm);
515 if (!ancestorComponent) {
516 appDidLoad();
517 }
518 }
519 }
520 else {
521 endPostUpdate();
522 }
523 {
524 hostRef.$onInstanceResolve$(elm);
525 }
526 // load events fire from bottom to top
527 // the deepest elements load first then bubbles up
528 {
529 if (hostRef.$onRenderResolve$) {
530 hostRef.$onRenderResolve$();
531 hostRef.$onRenderResolve$ = undefined;
532 }
533 if (hostRef.$flags$ & 512 /* needsRerender */) {
534 nextTick(() => scheduleUpdate(hostRef, false));
535 }
536 hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
537 }
538 // ( •_•)
539 // ( •_•)>⌐■-■
540 // (⌐■_■)
541};
542const appDidLoad = (who) => {
543 // on appload
544 // we have finish the first big initial render
545 {
546 addHydratedFlag(doc.documentElement);
547 }
548 nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
549};
550const safeCall = (instance, method, arg) => {
551 if (instance && instance[method]) {
552 try {
553 return instance[method](arg);
554 }
555 catch (e) {
556 consoleError(e);
557 }
558 }
559 return undefined;
560};
561const then = (promise, thenFn) => {
562 return promise && promise.then ? promise.then(thenFn) : thenFn();
563};
564const addHydratedFlag = (elm) => (elm.classList.add('hydrated') );
565const proxyComponent = (Cstr, cmpMeta, flags) => {
566 if (cmpMeta.$members$) {
567 // It's better to have a const than two Object.entries()
568 const members = Object.entries(cmpMeta.$members$);
569 const prototype = Cstr.prototype;
570 members.map(([memberName, [memberFlags]]) => {
571 if (flags & 1 /* isElementConstructor */ && memberFlags & 64 /* Method */) {
572 // proxyComponent - method
573 Object.defineProperty(prototype, memberName, {
574 value(...args) {
575 const ref = getHostRef(this);
576 return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
577 },
578 });
579 }
580 });
581 }
582 return Cstr;
583};
584const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
585 // initializeComponent
586 if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
587 {
588 // we haven't initialized this element yet
589 hostRef.$flags$ |= 32 /* hasInitializedComponent */;
590 // lazy loaded components
591 // request the component's implementation to be
592 // wired up with the host element
593 Cstr = loadModule(cmpMeta);
594 if (Cstr.then) {
595 // Await creates a micro-task avoid if possible
596 const endLoad = uniqueTime();
597 Cstr = await Cstr;
598 endLoad();
599 }
600 if (!Cstr.isProxied) {
601 proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
602 Cstr.isProxied = true;
603 }
604 const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
605 // ok, time to construct the instance
606 // but let's keep track of when we start and stop
607 // so that the getters/setters don't incorrectly step on data
608 {
609 hostRef.$flags$ |= 8 /* isConstructingInstance */;
610 }
611 // construct the lazy-loaded component implementation
612 // passing the hostRef is very important during
613 // construction in order to directly wire together the
614 // host element and the lazy-loaded instance
615 try {
616 new Cstr(hostRef);
617 }
618 catch (e) {
619 consoleError(e);
620 }
621 {
622 hostRef.$flags$ &= ~8 /* isConstructingInstance */;
623 }
624 endNewInstance();
625 }
626 if (Cstr.style) {
627 // this component has styles but we haven't registered them yet
628 let style = Cstr.style;
629 const scopeId = getScopeId(cmpMeta);
630 if (!styles.has(scopeId)) {
631 const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
632 registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
633 endRegisterStyles();
634 }
635 }
636 }
637 // we've successfully created a lazy instance
638 const ancestorComponent = hostRef.$ancestorComponent$;
639 const schedule = () => scheduleUpdate(hostRef, true);
640 if (ancestorComponent && ancestorComponent['s-rc']) {
641 // this is the intial load and this component it has an ancestor component
642 // but the ancestor component has NOT fired its will update lifecycle yet
643 // so let's just cool our jets and wait for the ancestor to continue first
644 // this will get fired off when the ancestor component
645 // finally gets around to rendering its lazy self
646 // fire off the initial update
647 ancestorComponent['s-rc'].push(schedule);
648 }
649 else {
650 schedule();
651 }
652};
653const connectedCallback = (elm) => {
654 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
655 const hostRef = getHostRef(elm);
656 const cmpMeta = hostRef.$cmpMeta$;
657 const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
658 if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
659 // first time this component has connected
660 hostRef.$flags$ |= 1 /* hasConnected */;
661 {
662 // find the first ancestor component (if there is one) and register
663 // this component as one of the actively loading child components for its ancestor
664 let ancestorComponent = elm;
665 while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
666 // climb up the ancestors looking for the first
667 // component that hasn't finished its lifecycle update yet
668 if (ancestorComponent['s-p']) {
669 // we found this components first ancestor component
670 // keep a reference to this component's ancestor component
671 attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
672 break;
673 }
674 }
675 }
676 {
677 initializeComponent(elm, hostRef, cmpMeta);
678 }
679 }
680 endConnected();
681 }
682};
683const disconnectedCallback = (elm) => {
684 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
685 getHostRef(elm);
686 }
687};
688const bootstrapLazy = (lazyBundles, options = {}) => {
689 const endBootstrap = createTime();
690 const cmpTags = [];
691 const exclude = options.exclude || [];
692 const customElements = win.customElements;
693 const head = doc.head;
694 const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
695 const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
696 const deferredConnectedCallbacks = [];
697 let appLoadFallback;
698 let isBootstrapping = true;
699 Object.assign(plt, options);
700 plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
701 lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
702 const cmpMeta = {
703 $flags$: compactMeta[0],
704 $tagName$: compactMeta[1],
705 $members$: compactMeta[2],
706 $listeners$: compactMeta[3],
707 };
708 {
709 cmpMeta.$members$ = compactMeta[2];
710 }
711 const tagName = cmpMeta.$tagName$;
712 const HostElement = class extends HTMLElement {
713 // StencilLazyHost
714 constructor(self) {
715 // @ts-ignore
716 super(self);
717 self = this;
718 registerHost(self, cmpMeta);
719 if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
720 // this component is using shadow dom
721 // and this browser supports shadow dom
722 // add the read-only property "shadowRoot" to the host element
723 // adding the shadow root build conditionals to minimize runtime
724 {
725 {
726 self.attachShadow({ mode: 'open' });
727 }
728 }
729 }
730 }
731 connectedCallback() {
732 if (appLoadFallback) {
733 clearTimeout(appLoadFallback);
734 appLoadFallback = null;
735 }
736 if (isBootstrapping) {
737 // connectedCallback will be processed once all components have been registered
738 deferredConnectedCallbacks.push(this);
739 }
740 else {
741 plt.jmp(() => connectedCallback(this));
742 }
743 }
744 disconnectedCallback() {
745 plt.jmp(() => disconnectedCallback(this));
746 }
747 componentOnReady() {
748 return getHostRef(this).$onReadyPromise$;
749 }
750 };
751 cmpMeta.$lazyBundleId$ = lazyBundle[0];
752 if (!exclude.includes(tagName) && !customElements.get(tagName)) {
753 cmpTags.push(tagName);
754 customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
755 }
756 }));
757 {
758 visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
759 visibilityStyle.setAttribute('data-styles', '');
760 head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
761 }
762 // Process deferred connectedCallbacks now all components have been registered
763 isBootstrapping = false;
764 if (deferredConnectedCallbacks.length) {
765 deferredConnectedCallbacks.map(host => host.connectedCallback());
766 }
767 else {
768 {
769 plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
770 }
771 }
772 // Fallback appLoad event
773 endBootstrap();
774};
775const Fragment = (_, children) => children;
776const hostRefs = new WeakMap();
777const getHostRef = (ref) => hostRefs.get(ref);
778const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
779const registerHost = (elm, cmpMeta) => {
780 const hostRef = {
781 $flags$: 0,
782 $hostElement$: elm,
783 $cmpMeta$: cmpMeta,
784 $instanceValues$: new Map(),
785 };
786 {
787 hostRef.$onInstancePromise$ = new Promise(r => (hostRef.$onInstanceResolve$ = r));
788 }
789 {
790 hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
791 elm['s-p'] = [];
792 elm['s-rc'] = [];
793 }
794 return hostRefs.set(elm, hostRef);
795};
796const isMemberInElement = (elm, memberName) => memberName in elm;
797const consoleError = (e, el) => (0, console.error)(e, el);
798const cmpModules = /*@__PURE__*/ new Map();
799const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
800 // loadModuleImport
801 const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
802 const bundleId = cmpMeta.$lazyBundleId$;
803 const module = cmpModules.get(bundleId) ;
804 if (module) {
805 return module[exportName];
806 }
807 return import(
808 /* webpackInclude: /\.entry\.js$/ */
809 /* webpackExclude: /\.system\.entry\.js$/ */
810 /* webpackMode: "lazy" */
811 `./${bundleId}.entry.js${''}`).then(importedModule => {
812 {
813 cmpModules.set(bundleId, importedModule);
814 }
815 return importedModule[exportName];
816 }, consoleError);
817};
818const styles = new Map();
819const queueDomReads = [];
820const queueDomWrites = [];
821const queueTask = (queue, write) => (cb) => {
822 queue.push(cb);
823 if (!queuePending) {
824 queuePending = true;
825 if (write && plt.$flags$ & 4 /* queueSync */) {
826 nextTick(flush);
827 }
828 else {
829 plt.raf(flush);
830 }
831 }
832};
833const consume = (queue) => {
834 for (let i = 0; i < queue.length; i++) {
835 try {
836 queue[i](performance.now());
837 }
838 catch (e) {
839 consoleError(e);
840 }
841 }
842 queue.length = 0;
843};
844const flush = () => {
845 // always force a bunch of medium callbacks to run, but still have
846 // a throttle on how many can run in a certain time
847 // DOM READS!!!
848 consume(queueDomReads);
849 // DOM WRITES!!!
850 {
851 consume(queueDomWrites);
852 if ((queuePending = queueDomReads.length > 0)) {
853 // still more to do yet, but we've run out of time
854 // let's let this thing cool off and try again in the next tick
855 plt.raf(flush);
856 }
857 }
858};
859const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
860const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
861
862export { Fragment as F, Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };