1 | const NAMESPACE = 'jb-deckdeckgo';
|
2 |
|
3 | let scopeId;
|
4 | let hostTagName;
|
5 | let isSvgMode = false;
|
6 | let queuePending = false;
|
7 | const win = typeof window !== 'undefined' ? window : {};
|
8 | const doc = win.document || { head: {} };
|
9 | const 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 | };
|
18 | const promiseResolve = (v) => Promise.resolve(v);
|
19 | const supportsConstructibleStylesheets = (() => {
|
20 | try {
|
21 | new CSSStyleSheet();
|
22 | return typeof (new CSSStyleSheet()).replace === 'function';
|
23 | }
|
24 | catch (e) { }
|
25 | return false;
|
26 | })()
|
27 | ;
|
28 | const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
29 | const createTime = (fnName, tagName = '') => {
|
30 | {
|
31 | return () => {
|
32 | return;
|
33 | };
|
34 | }
|
35 | };
|
36 | const uniqueTime = (key, measureText) => {
|
37 | {
|
38 | return () => {
|
39 | return;
|
40 | };
|
41 | }
|
42 | };
|
43 | const rootAppliedStyles = new WeakMap();
|
44 | const 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 | };
|
55 | const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
56 | let scopeId = getScopeId(cmpMeta);
|
57 | let style = styles.get(scopeId);
|
58 |
|
59 |
|
60 | styleContainerNode = styleContainerNode.nodeType === 11 ? 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 | };
|
88 | const 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 ) {
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | elm['s-sc'] = scopeId;
|
103 | elm.classList.add(scopeId + '-h');
|
104 | }
|
105 | endAttachStyles();
|
106 | };
|
107 | const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | const EMPTY_OBJ = {};
|
116 | const isDef = (v) => v != null;
|
117 | const isComplexType = (o) => {
|
118 |
|
119 | o = typeof o;
|
120 | return o === 'object' || o === 'function';
|
121 | };
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | const 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 |
|
150 | vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
151 | }
|
152 | else {
|
153 |
|
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 |
|
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 | };
|
185 | const 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 | };
|
198 | const Host = {};
|
199 | const isHost = (node) => node && node.$tag$ === Host;
|
200 | const vdomFnUtils = {
|
201 | forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
202 | map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
|
203 | };
|
204 | const 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 | });
|
212 | const 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 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | const 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 |
|
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 |
|
257 | if (memberName === 'list') {
|
258 | isProp = false;
|
259 |
|
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 || isSvg) && !isComplex) {
|
279 | newValue = newValue === true ? '' : newValue;
|
280 | {
|
281 | elm.setAttribute(memberName, newValue);
|
282 | }
|
283 | }
|
284 | }
|
285 | }
|
286 | };
|
287 | const parseClassListRegex = /\s/;
|
288 | const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
|
289 | const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
290 |
|
291 |
|
292 |
|
293 | const elm = newVnode.$elm$.nodeType === 11 && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
|
294 | const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
295 | const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
|
296 |
|
297 | for (memberName in newVnodeAttrs) {
|
298 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
299 | }
|
300 | };
|
301 | const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
302 |
|
303 | let newVNode = newParentVNode.$children$[childIndex];
|
304 | let i = 0;
|
305 | let elm;
|
306 | let childNode;
|
307 | if (newVNode.$text$ !== null) {
|
308 |
|
309 | elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
|
310 | }
|
311 | else {
|
312 |
|
313 | elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
|
314 |
|
315 | {
|
316 | updateElement(null, newVNode, isSvgMode);
|
317 | }
|
318 | if (isDef(scopeId) && elm['s-si'] !== scopeId) {
|
319 |
|
320 |
|
321 | elm.classList.add((elm['s-si'] = scopeId));
|
322 | }
|
323 | if (newVNode.$children$) {
|
324 | for (i = 0; i < newVNode.$children$.length; ++i) {
|
325 |
|
326 | childNode = createElm(oldParentVNode, newVNode, i);
|
327 |
|
328 | if (childNode) {
|
329 |
|
330 | elm.appendChild(childNode);
|
331 | }
|
332 | }
|
333 | }
|
334 | }
|
335 | return elm;
|
336 | };
|
337 | const 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 | };
|
353 | const 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 |
|
360 | {
|
361 | if (tag === 'slot')
|
362 | ;
|
363 | else {
|
364 |
|
365 |
|
366 |
|
367 | updateElement(oldVNode, newVNode, isSvgMode);
|
368 | }
|
369 | }
|
370 | if (newChildren !== null) {
|
371 |
|
372 | addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
373 | }
|
374 | else ;
|
375 | }
|
376 | else if (oldVNode.$text$ !== text) {
|
377 |
|
378 |
|
379 | elm.data = text;
|
380 | }
|
381 | };
|
382 | const 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 ;
|
389 | hostRef.$vnode$ = rootVnode;
|
390 | rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
391 | {
|
392 | scopeId = hostElm['s-sc'];
|
393 | }
|
394 |
|
395 | patch(oldVNode, rootVnode);
|
396 | };
|
397 | const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
398 | const createEvent = (ref, name, flags) => {
|
399 | const elm = getElement(ref);
|
400 | return {
|
401 | emit: (detail) => {
|
402 | return emitEvent(elm, name, {
|
403 | bubbles: !!(flags & 4 ),
|
404 | composed: !!(flags & 2 ),
|
405 | cancelable: !!(flags & 1 ),
|
406 | detail,
|
407 | });
|
408 | },
|
409 | };
|
410 | };
|
411 | const emitEvent = (elm, name, opts) => {
|
412 | const ev = plt.ce(name, opts);
|
413 | elm.dispatchEvent(ev);
|
414 | return ev;
|
415 | };
|
416 | const attachToAncestor = (hostRef, ancestorComponent) => {
|
417 | if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
418 | ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
|
419 | }
|
420 | };
|
421 | const scheduleUpdate = (hostRef, isInitialLoad) => {
|
422 | if (hostRef.$flags$ & 4 ) {
|
423 | hostRef.$flags$ |= 512 ;
|
424 | return;
|
425 | }
|
426 | attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
427 |
|
428 |
|
429 |
|
430 | const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
431 | return writeTask(dispatch) ;
|
432 | };
|
433 | const 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 | };
|
440 | const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
441 |
|
442 | const elm = hostRef.$hostElement$;
|
443 | const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
444 | const rc = elm['s-rc'];
|
445 | if (isInitialLoad) {
|
446 |
|
447 | attachStyles(hostRef);
|
448 | }
|
449 | const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
|
450 | {
|
451 | callRender(hostRef, instance);
|
452 | }
|
453 | if (rc) {
|
454 |
|
455 |
|
456 |
|
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 ;
|
471 | childrenPromises.length = 0;
|
472 | }
|
473 | }
|
474 | };
|
475 | const callRender = (hostRef, instance, elm) => {
|
476 | try {
|
477 | instance = instance.render() ;
|
478 | {
|
479 | hostRef.$flags$ |= 2 ;
|
480 | }
|
481 | {
|
482 | {
|
483 |
|
484 |
|
485 |
|
486 | {
|
487 | renderVdom(hostRef, instance);
|
488 | }
|
489 | }
|
490 | }
|
491 | }
|
492 | catch (e) {
|
493 | consoleError(e, hostRef.$hostElement$);
|
494 | }
|
495 | return null;
|
496 | };
|
497 | const 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 )) {
|
504 | hostRef.$flags$ |= 64 ;
|
505 | {
|
506 |
|
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 |
|
527 |
|
528 | {
|
529 | if (hostRef.$onRenderResolve$) {
|
530 | hostRef.$onRenderResolve$();
|
531 | hostRef.$onRenderResolve$ = undefined;
|
532 | }
|
533 | if (hostRef.$flags$ & 512 ) {
|
534 | nextTick(() => scheduleUpdate(hostRef, false));
|
535 | }
|
536 | hostRef.$flags$ &= ~(4 | 512 );
|
537 | }
|
538 |
|
539 |
|
540 |
|
541 | };
|
542 | const appDidLoad = (who) => {
|
543 |
|
544 |
|
545 | {
|
546 | addHydratedFlag(doc.documentElement);
|
547 | }
|
548 | nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
549 | };
|
550 | const 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 | };
|
561 | const then = (promise, thenFn) => {
|
562 | return promise && promise.then ? promise.then(thenFn) : thenFn();
|
563 | };
|
564 | const addHydratedFlag = (elm) => (elm.classList.add('hydrated') );
|
565 | const proxyComponent = (Cstr, cmpMeta, flags) => {
|
566 | if (cmpMeta.$members$) {
|
567 |
|
568 | const members = Object.entries(cmpMeta.$members$);
|
569 | const prototype = Cstr.prototype;
|
570 | members.map(([memberName, [memberFlags]]) => {
|
571 | if (flags & 1 && memberFlags & 64 ) {
|
572 |
|
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 | };
|
584 | const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
585 |
|
586 | if ((hostRef.$flags$ & 32 ) === 0) {
|
587 | {
|
588 |
|
589 | hostRef.$flags$ |= 32 ;
|
590 |
|
591 |
|
592 |
|
593 | Cstr = loadModule(cmpMeta);
|
594 | if (Cstr.then) {
|
595 |
|
596 | const endLoad = uniqueTime();
|
597 | Cstr = await Cstr;
|
598 | endLoad();
|
599 | }
|
600 | if (!Cstr.isProxied) {
|
601 | proxyComponent(Cstr, cmpMeta, 2 );
|
602 | Cstr.isProxied = true;
|
603 | }
|
604 | const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
605 |
|
606 |
|
607 |
|
608 | {
|
609 | hostRef.$flags$ |= 8 ;
|
610 | }
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | try {
|
616 | new Cstr(hostRef);
|
617 | }
|
618 | catch (e) {
|
619 | consoleError(e);
|
620 | }
|
621 | {
|
622 | hostRef.$flags$ &= ~8 ;
|
623 | }
|
624 | endNewInstance();
|
625 | }
|
626 | if (Cstr.style) {
|
627 |
|
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 ));
|
633 | endRegisterStyles();
|
634 | }
|
635 | }
|
636 | }
|
637 |
|
638 | const ancestorComponent = hostRef.$ancestorComponent$;
|
639 | const schedule = () => scheduleUpdate(hostRef, true);
|
640 | if (ancestorComponent && ancestorComponent['s-rc']) {
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 | ancestorComponent['s-rc'].push(schedule);
|
648 | }
|
649 | else {
|
650 | schedule();
|
651 | }
|
652 | };
|
653 | const connectedCallback = (elm) => {
|
654 | if ((plt.$flags$ & 1 ) === 0) {
|
655 | const hostRef = getHostRef(elm);
|
656 | const cmpMeta = hostRef.$cmpMeta$;
|
657 | const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
658 | if (!(hostRef.$flags$ & 1 )) {
|
659 |
|
660 | hostRef.$flags$ |= 1 ;
|
661 | {
|
662 |
|
663 |
|
664 | let ancestorComponent = elm;
|
665 | while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
|
666 |
|
667 |
|
668 | if (ancestorComponent['s-p']) {
|
669 |
|
670 |
|
671 | attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
|
672 | break;
|
673 | }
|
674 | }
|
675 | }
|
676 | {
|
677 | initializeComponent(elm, hostRef, cmpMeta);
|
678 | }
|
679 | }
|
680 | endConnected();
|
681 | }
|
682 | };
|
683 | const disconnectedCallback = (elm) => {
|
684 | if ((plt.$flags$ & 1 ) === 0) {
|
685 | getHostRef(elm);
|
686 | }
|
687 | };
|
688 | const 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 = head.querySelector('meta[charset]');
|
695 | const visibilityStyle = 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 |
|
714 | constructor(self) {
|
715 |
|
716 | super(self);
|
717 | self = this;
|
718 | registerHost(self, cmpMeta);
|
719 | if (cmpMeta.$flags$ & 1 ) {
|
720 |
|
721 |
|
722 |
|
723 |
|
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 |
|
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 ));
|
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 |
|
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 |
|
773 | endBootstrap();
|
774 | };
|
775 | const Fragment = (_, children) => children;
|
776 | const hostRefs = new WeakMap();
|
777 | const getHostRef = (ref) => hostRefs.get(ref);
|
778 | const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
779 | const 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 | };
|
796 | const isMemberInElement = (elm, memberName) => memberName in elm;
|
797 | const consoleError = (e, el) => (0, console.error)(e, el);
|
798 | const cmpModules = new Map();
|
799 | const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
800 |
|
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 |
|
809 |
|
810 |
|
811 | `./${bundleId}.entry.js${''}`).then(importedModule => {
|
812 | {
|
813 | cmpModules.set(bundleId, importedModule);
|
814 | }
|
815 | return importedModule[exportName];
|
816 | }, consoleError);
|
817 | };
|
818 | const styles = new Map();
|
819 | const queueDomReads = [];
|
820 | const queueDomWrites = [];
|
821 | const queueTask = (queue, write) => (cb) => {
|
822 | queue.push(cb);
|
823 | if (!queuePending) {
|
824 | queuePending = true;
|
825 | if (write && plt.$flags$ & 4 ) {
|
826 | nextTick(flush);
|
827 | }
|
828 | else {
|
829 | plt.raf(flush);
|
830 | }
|
831 | }
|
832 | };
|
833 | const 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 | };
|
844 | const flush = () => {
|
845 |
|
846 |
|
847 |
|
848 | consume(queueDomReads);
|
849 |
|
850 | {
|
851 | consume(queueDomWrites);
|
852 | if ((queuePending = queueDomReads.length > 0)) {
|
853 |
|
854 |
|
855 | plt.raf(flush);
|
856 | }
|
857 | }
|
858 | };
|
859 | const nextTick = (cb) => promiseResolve().then(cb);
|
860 | const writeTask = queueTask(queueDomWrites, true);
|
861 |
|
862 | export { Fragment as F, Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };
|