1 | const NAMESPACE = 'ionicons';
|
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 | const vnode = newVNode(nodeName, null);
|
175 | vnode.$attrs$ = vnodeData;
|
176 | if (vNodeChildren.length > 0) {
|
177 | vnode.$children$ = vNodeChildren;
|
178 | }
|
179 | return vnode;
|
180 | };
|
181 | const newVNode = (tag, text) => {
|
182 | const vnode = {
|
183 | $flags$: 0,
|
184 | $tag$: tag,
|
185 | $text$: text,
|
186 | $elm$: null,
|
187 | $children$: null,
|
188 | };
|
189 | {
|
190 | vnode.$attrs$ = null;
|
191 | }
|
192 | return vnode;
|
193 | };
|
194 | const Host = {};
|
195 | const isHost = (node) => node && node.$tag$ === Host;
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
205 | if (oldValue !== newValue) {
|
206 | let isProp = isMemberInElement(elm, memberName);
|
207 | memberName.toLowerCase();
|
208 | if (memberName === 'class') {
|
209 | const classList = elm.classList;
|
210 | const oldClasses = parseClassList(oldValue);
|
211 | const newClasses = parseClassList(newValue);
|
212 | classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
|
213 | classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
|
214 | }
|
215 | else {
|
216 |
|
217 | const isComplex = isComplexType(newValue);
|
218 | if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
|
219 | try {
|
220 | if (!elm.tagName.includes('-')) {
|
221 | let n = newValue == null ? '' : newValue;
|
222 |
|
223 | if (memberName === 'list') {
|
224 | isProp = false;
|
225 |
|
226 | }
|
227 | else if (oldValue == null || elm[memberName] != n) {
|
228 | elm[memberName] = n;
|
229 | }
|
230 | }
|
231 | else {
|
232 | elm[memberName] = newValue;
|
233 | }
|
234 | }
|
235 | catch (e) { }
|
236 | }
|
237 | if (newValue == null || newValue === false) {
|
238 | if (newValue !== false || elm.getAttribute(memberName) === '') {
|
239 | {
|
240 | elm.removeAttribute(memberName);
|
241 | }
|
242 | }
|
243 | }
|
244 | else if ((!isProp || flags & 4 || isSvg) && !isComplex) {
|
245 | newValue = newValue === true ? '' : newValue;
|
246 | {
|
247 | elm.setAttribute(memberName, newValue);
|
248 | }
|
249 | }
|
250 | }
|
251 | }
|
252 | };
|
253 | const parseClassListRegex = /\s/;
|
254 | const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
|
255 | const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
256 |
|
257 |
|
258 |
|
259 | const elm = newVnode.$elm$.nodeType === 11 && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
|
260 | const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
261 | const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
|
262 | {
|
263 |
|
264 | for (memberName in oldVnodeAttrs) {
|
265 | if (!(memberName in newVnodeAttrs)) {
|
266 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
|
267 | }
|
268 | }
|
269 | }
|
270 |
|
271 | for (memberName in newVnodeAttrs) {
|
272 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
273 | }
|
274 | };
|
275 | const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
276 |
|
277 | let newVNode = newParentVNode.$children$[childIndex];
|
278 | let i = 0;
|
279 | let elm;
|
280 | let childNode;
|
281 | if (newVNode.$text$ !== null) {
|
282 |
|
283 | elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
|
284 | }
|
285 | else {
|
286 |
|
287 | elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
|
288 |
|
289 | {
|
290 | updateElement(null, newVNode, isSvgMode);
|
291 | }
|
292 | if (isDef(scopeId) && elm['s-si'] !== scopeId) {
|
293 |
|
294 |
|
295 | elm.classList.add((elm['s-si'] = scopeId));
|
296 | }
|
297 | if (newVNode.$children$) {
|
298 | for (i = 0; i < newVNode.$children$.length; ++i) {
|
299 |
|
300 | childNode = createElm(oldParentVNode, newVNode, i);
|
301 |
|
302 | if (childNode) {
|
303 |
|
304 | elm.appendChild(childNode);
|
305 | }
|
306 | }
|
307 | }
|
308 | }
|
309 | return elm;
|
310 | };
|
311 | const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
312 | let containerElm = (parentElm);
|
313 | let childNode;
|
314 | if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
|
315 | containerElm = containerElm.shadowRoot;
|
316 | }
|
317 | for (; startIdx <= endIdx; ++startIdx) {
|
318 | if (vnodes[startIdx]) {
|
319 | childNode = createElm(null, parentVNode, startIdx);
|
320 | if (childNode) {
|
321 | vnodes[startIdx].$elm$ = childNode;
|
322 | containerElm.insertBefore(childNode, before);
|
323 | }
|
324 | }
|
325 | }
|
326 | };
|
327 | const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
328 | for (; startIdx <= endIdx; ++startIdx) {
|
329 | if ((vnode = vnodes[startIdx])) {
|
330 | elm = vnode.$elm$;
|
331 |
|
332 | elm.remove();
|
333 | }
|
334 | }
|
335 | };
|
336 | const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
337 | let oldStartIdx = 0;
|
338 | let newStartIdx = 0;
|
339 | let oldEndIdx = oldCh.length - 1;
|
340 | let oldStartVnode = oldCh[0];
|
341 | let oldEndVnode = oldCh[oldEndIdx];
|
342 | let newEndIdx = newCh.length - 1;
|
343 | let newStartVnode = newCh[0];
|
344 | let newEndVnode = newCh[newEndIdx];
|
345 | let node;
|
346 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
347 | if (oldStartVnode == null) {
|
348 |
|
349 | oldStartVnode = oldCh[++oldStartIdx];
|
350 | }
|
351 | else if (oldEndVnode == null) {
|
352 | oldEndVnode = oldCh[--oldEndIdx];
|
353 | }
|
354 | else if (newStartVnode == null) {
|
355 | newStartVnode = newCh[++newStartIdx];
|
356 | }
|
357 | else if (newEndVnode == null) {
|
358 | newEndVnode = newCh[--newEndIdx];
|
359 | }
|
360 | else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
361 | patch(oldStartVnode, newStartVnode);
|
362 | oldStartVnode = oldCh[++oldStartIdx];
|
363 | newStartVnode = newCh[++newStartIdx];
|
364 | }
|
365 | else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
366 | patch(oldEndVnode, newEndVnode);
|
367 | oldEndVnode = oldCh[--oldEndIdx];
|
368 | newEndVnode = newCh[--newEndIdx];
|
369 | }
|
370 | else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
371 | patch(oldStartVnode, newEndVnode);
|
372 | parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
373 | oldStartVnode = oldCh[++oldStartIdx];
|
374 | newEndVnode = newCh[--newEndIdx];
|
375 | }
|
376 | else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
377 | patch(oldEndVnode, newStartVnode);
|
378 | parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
379 | oldEndVnode = oldCh[--oldEndIdx];
|
380 | newStartVnode = newCh[++newStartIdx];
|
381 | }
|
382 | else {
|
383 | {
|
384 |
|
385 | node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
386 | newStartVnode = newCh[++newStartIdx];
|
387 | }
|
388 | if (node) {
|
389 | {
|
390 | oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
|
391 | }
|
392 | }
|
393 | }
|
394 | }
|
395 | if (oldStartIdx > oldEndIdx) {
|
396 | addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
397 | }
|
398 | else if (newStartIdx > newEndIdx) {
|
399 | removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
400 | }
|
401 | };
|
402 | const isSameVnode = (vnode1, vnode2) => {
|
403 |
|
404 |
|
405 | if (vnode1.$tag$ === vnode2.$tag$) {
|
406 | return true;
|
407 | }
|
408 | return false;
|
409 | };
|
410 | const patch = (oldVNode, newVNode) => {
|
411 | const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
412 | const oldChildren = oldVNode.$children$;
|
413 | const newChildren = newVNode.$children$;
|
414 | const text = newVNode.$text$;
|
415 | if (text === null) {
|
416 |
|
417 | {
|
418 | {
|
419 |
|
420 |
|
421 |
|
422 | updateElement(oldVNode, newVNode, isSvgMode);
|
423 | }
|
424 | }
|
425 | if (oldChildren !== null && newChildren !== null) {
|
426 |
|
427 | updateChildren(elm, oldChildren, newVNode, newChildren);
|
428 | }
|
429 | else if (newChildren !== null) {
|
430 |
|
431 | if (oldVNode.$text$ !== null) {
|
432 |
|
433 | elm.textContent = '';
|
434 | }
|
435 |
|
436 | addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
437 | }
|
438 | else if (oldChildren !== null) {
|
439 |
|
440 | removeVnodes(oldChildren, 0, oldChildren.length - 1);
|
441 | }
|
442 | }
|
443 | else if (oldVNode.$text$ !== text) {
|
444 |
|
445 |
|
446 | elm.data = text;
|
447 | }
|
448 | };
|
449 | const renderVdom = (hostRef, renderFnResults) => {
|
450 | const hostElm = hostRef.$hostElement$;
|
451 | const cmpMeta = hostRef.$cmpMeta$;
|
452 | const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
453 | const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
|
454 | hostTagName = hostElm.tagName;
|
455 | if (cmpMeta.$attrsToReflect$) {
|
456 | rootVnode.$attrs$ = rootVnode.$attrs$ || {};
|
457 | cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
458 | }
|
459 | rootVnode.$tag$ = null;
|
460 | rootVnode.$flags$ |= 4 ;
|
461 | hostRef.$vnode$ = rootVnode;
|
462 | rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
463 | {
|
464 | scopeId = hostElm['s-sc'];
|
465 | }
|
466 |
|
467 | patch(oldVNode, rootVnode);
|
468 | };
|
469 | const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
470 | const emitEvent = (elm, name, opts) => {
|
471 | const ev = plt.ce(name, opts);
|
472 | elm.dispatchEvent(ev);
|
473 | return ev;
|
474 | };
|
475 | const attachToAncestor = (hostRef, ancestorComponent) => {
|
476 | if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
477 | ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
|
478 | }
|
479 | };
|
480 | const scheduleUpdate = (hostRef, isInitialLoad) => {
|
481 | {
|
482 | hostRef.$flags$ |= 16 ;
|
483 | }
|
484 | if (hostRef.$flags$ & 4 ) {
|
485 | hostRef.$flags$ |= 512 ;
|
486 | return;
|
487 | }
|
488 | attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
489 |
|
490 |
|
491 |
|
492 | const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
493 | return writeTask(dispatch) ;
|
494 | };
|
495 | const dispatchHooks = (hostRef, isInitialLoad) => {
|
496 | const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
497 | const instance = hostRef.$lazyInstance$ ;
|
498 | let promise;
|
499 | endSchedule();
|
500 | return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
|
501 | };
|
502 | const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
503 |
|
504 | const elm = hostRef.$hostElement$;
|
505 | const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
506 | const rc = elm['s-rc'];
|
507 | if (isInitialLoad) {
|
508 |
|
509 | attachStyles(hostRef);
|
510 | }
|
511 | const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
|
512 | {
|
513 | callRender(hostRef, instance);
|
514 | }
|
515 | if (rc) {
|
516 |
|
517 |
|
518 |
|
519 | rc.map(cb => cb());
|
520 | elm['s-rc'] = undefined;
|
521 | }
|
522 | endRender();
|
523 | endUpdate();
|
524 | {
|
525 | const childrenPromises = elm['s-p'];
|
526 | const postUpdate = () => postUpdateComponent(hostRef);
|
527 | if (childrenPromises.length === 0) {
|
528 | postUpdate();
|
529 | }
|
530 | else {
|
531 | Promise.all(childrenPromises).then(postUpdate);
|
532 | hostRef.$flags$ |= 4 ;
|
533 | childrenPromises.length = 0;
|
534 | }
|
535 | }
|
536 | };
|
537 | const callRender = (hostRef, instance, elm) => {
|
538 | try {
|
539 | instance = instance.render() ;
|
540 | {
|
541 | hostRef.$flags$ &= ~16 ;
|
542 | }
|
543 | {
|
544 | hostRef.$flags$ |= 2 ;
|
545 | }
|
546 | {
|
547 | {
|
548 |
|
549 |
|
550 |
|
551 | {
|
552 | renderVdom(hostRef, instance);
|
553 | }
|
554 | }
|
555 | }
|
556 | }
|
557 | catch (e) {
|
558 | consoleError(e, hostRef.$hostElement$);
|
559 | }
|
560 | return null;
|
561 | };
|
562 | const postUpdateComponent = (hostRef) => {
|
563 | const tagName = hostRef.$cmpMeta$.$tagName$;
|
564 | const elm = hostRef.$hostElement$;
|
565 | const endPostUpdate = createTime('postUpdate', tagName);
|
566 | const ancestorComponent = hostRef.$ancestorComponent$;
|
567 | if (!(hostRef.$flags$ & 64 )) {
|
568 | hostRef.$flags$ |= 64 ;
|
569 | {
|
570 |
|
571 | addHydratedFlag(elm);
|
572 | }
|
573 | endPostUpdate();
|
574 | {
|
575 | hostRef.$onReadyResolve$(elm);
|
576 | if (!ancestorComponent) {
|
577 | appDidLoad();
|
578 | }
|
579 | }
|
580 | }
|
581 | else {
|
582 | endPostUpdate();
|
583 | }
|
584 |
|
585 |
|
586 | {
|
587 | if (hostRef.$onRenderResolve$) {
|
588 | hostRef.$onRenderResolve$();
|
589 | hostRef.$onRenderResolve$ = undefined;
|
590 | }
|
591 | if (hostRef.$flags$ & 512 ) {
|
592 | nextTick(() => scheduleUpdate(hostRef, false));
|
593 | }
|
594 | hostRef.$flags$ &= ~(4 | 512 );
|
595 | }
|
596 |
|
597 |
|
598 |
|
599 | };
|
600 | const appDidLoad = (who) => {
|
601 |
|
602 |
|
603 | {
|
604 | addHydratedFlag(doc.documentElement);
|
605 | }
|
606 | nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
607 | };
|
608 | const safeCall = (instance, method, arg) => {
|
609 | if (instance && instance[method]) {
|
610 | try {
|
611 | return instance[method](arg);
|
612 | }
|
613 | catch (e) {
|
614 | consoleError(e);
|
615 | }
|
616 | }
|
617 | return undefined;
|
618 | };
|
619 | const then = (promise, thenFn) => {
|
620 | return promise && promise.then ? promise.then(thenFn) : thenFn();
|
621 | };
|
622 | const addHydratedFlag = (elm) => (elm.classList.add('hydrated') );
|
623 | const parsePropertyValue = (propValue, propType) => {
|
624 |
|
625 | if (propValue != null && !isComplexType(propValue)) {
|
626 | if (propType & 4 ) {
|
627 |
|
628 |
|
629 | return propValue === 'false' ? false : propValue === '' || !!propValue;
|
630 | }
|
631 | if (propType & 1 ) {
|
632 |
|
633 |
|
634 | return String(propValue);
|
635 | }
|
636 |
|
637 | return propValue;
|
638 | }
|
639 |
|
640 |
|
641 | return propValue;
|
642 | };
|
643 | const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
644 | const setValue = (ref, propName, newVal, cmpMeta) => {
|
645 |
|
646 | const hostRef = getHostRef(ref);
|
647 | const elm = hostRef.$hostElement$ ;
|
648 | const oldVal = hostRef.$instanceValues$.get(propName);
|
649 | const flags = hostRef.$flags$;
|
650 | const instance = hostRef.$lazyInstance$ ;
|
651 | newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
|
652 | if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
|
653 |
|
654 |
|
655 | hostRef.$instanceValues$.set(propName, newVal);
|
656 | if (instance) {
|
657 |
|
658 | if (cmpMeta.$watchers$ && flags & 128 ) {
|
659 | const watchMethods = cmpMeta.$watchers$[propName];
|
660 | if (watchMethods) {
|
661 |
|
662 | watchMethods.map(watchMethodName => {
|
663 | try {
|
664 |
|
665 | instance[watchMethodName](newVal, oldVal, propName);
|
666 | }
|
667 | catch (e) {
|
668 | consoleError(e, elm);
|
669 | }
|
670 | });
|
671 | }
|
672 | }
|
673 | if ((flags & (2 | 16 )) === 2 ) {
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | scheduleUpdate(hostRef, false);
|
679 | }
|
680 | }
|
681 | }
|
682 | };
|
683 | const proxyComponent = (Cstr, cmpMeta, flags) => {
|
684 | if (cmpMeta.$members$) {
|
685 | if (Cstr.watchers) {
|
686 | cmpMeta.$watchers$ = Cstr.watchers;
|
687 | }
|
688 |
|
689 | const members = Object.entries(cmpMeta.$members$);
|
690 | const prototype = Cstr.prototype;
|
691 | members.map(([memberName, [memberFlags]]) => {
|
692 | if ((memberFlags & 31 || ((flags & 2 ) && memberFlags & 32 ))) {
|
693 |
|
694 | Object.defineProperty(prototype, memberName, {
|
695 | get() {
|
696 |
|
697 | return getValue(this, memberName);
|
698 | },
|
699 | set(newValue) {
|
700 |
|
701 | setValue(this, memberName, newValue, cmpMeta);
|
702 | },
|
703 | configurable: true,
|
704 | enumerable: true,
|
705 | });
|
706 | }
|
707 | });
|
708 | if ((flags & 1 )) {
|
709 | const attrNameToPropName = new Map();
|
710 | prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
711 | plt.jmp(() => {
|
712 | const propName = attrNameToPropName.get(attrName);
|
713 | this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
|
714 | });
|
715 | };
|
716 |
|
717 |
|
718 | Cstr.observedAttributes = members
|
719 | .filter(([_, m]) => m[0] & 15 )
|
720 | .map(([propName, m]) => {
|
721 | const attrName = m[1] || propName;
|
722 | attrNameToPropName.set(attrName, propName);
|
723 | if (m[0] & 512 ) {
|
724 | cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
725 | }
|
726 | return attrName;
|
727 | });
|
728 | }
|
729 | }
|
730 | return Cstr;
|
731 | };
|
732 | const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
733 |
|
734 | if ((hostRef.$flags$ & 32 ) === 0) {
|
735 | {
|
736 |
|
737 | hostRef.$flags$ |= 32 ;
|
738 |
|
739 |
|
740 |
|
741 | Cstr = loadModule(cmpMeta);
|
742 | if (Cstr.then) {
|
743 |
|
744 | const endLoad = uniqueTime();
|
745 | Cstr = await Cstr;
|
746 | endLoad();
|
747 | }
|
748 | if (!Cstr.isProxied) {
|
749 |
|
750 |
|
751 |
|
752 | {
|
753 | cmpMeta.$watchers$ = Cstr.watchers;
|
754 | }
|
755 | proxyComponent(Cstr, cmpMeta, 2 );
|
756 | Cstr.isProxied = true;
|
757 | }
|
758 | const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
759 |
|
760 |
|
761 |
|
762 | {
|
763 | hostRef.$flags$ |= 8 ;
|
764 | }
|
765 |
|
766 |
|
767 |
|
768 |
|
769 | try {
|
770 | new Cstr(hostRef);
|
771 | }
|
772 | catch (e) {
|
773 | consoleError(e);
|
774 | }
|
775 | {
|
776 | hostRef.$flags$ &= ~8 ;
|
777 | }
|
778 | {
|
779 | hostRef.$flags$ |= 128 ;
|
780 | }
|
781 | endNewInstance();
|
782 | fireConnectedCallback(hostRef.$lazyInstance$);
|
783 | }
|
784 | if (Cstr.style) {
|
785 |
|
786 | let style = Cstr.style;
|
787 | const scopeId = getScopeId(cmpMeta);
|
788 | if (!styles.has(scopeId)) {
|
789 | const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
790 | registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 ));
|
791 | endRegisterStyles();
|
792 | }
|
793 | }
|
794 | }
|
795 |
|
796 | const ancestorComponent = hostRef.$ancestorComponent$;
|
797 | const schedule = () => scheduleUpdate(hostRef, true);
|
798 | if (ancestorComponent && ancestorComponent['s-rc']) {
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | ancestorComponent['s-rc'].push(schedule);
|
806 | }
|
807 | else {
|
808 | schedule();
|
809 | }
|
810 | };
|
811 | const fireConnectedCallback = (instance) => {
|
812 | {
|
813 | safeCall(instance, 'connectedCallback');
|
814 | }
|
815 | };
|
816 | const connectedCallback = (elm) => {
|
817 | if ((plt.$flags$ & 1 ) === 0) {
|
818 | const hostRef = getHostRef(elm);
|
819 | const cmpMeta = hostRef.$cmpMeta$;
|
820 | const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
821 | if (!(hostRef.$flags$ & 1 )) {
|
822 |
|
823 | hostRef.$flags$ |= 1 ;
|
824 | {
|
825 |
|
826 |
|
827 | let ancestorComponent = elm;
|
828 | while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
|
829 |
|
830 |
|
831 | if (ancestorComponent['s-p']) {
|
832 |
|
833 |
|
834 | attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
|
835 | break;
|
836 | }
|
837 | }
|
838 | }
|
839 |
|
840 |
|
841 | if (cmpMeta.$members$) {
|
842 | Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
843 | if (memberFlags & 31 && elm.hasOwnProperty(memberName)) {
|
844 | const value = elm[memberName];
|
845 | delete elm[memberName];
|
846 | elm[memberName] = value;
|
847 | }
|
848 | });
|
849 | }
|
850 | {
|
851 | initializeComponent(elm, hostRef, cmpMeta);
|
852 | }
|
853 | }
|
854 | else {
|
855 |
|
856 | fireConnectedCallback(hostRef.$lazyInstance$);
|
857 | }
|
858 | endConnected();
|
859 | }
|
860 | };
|
861 | const disconnectedCallback = (elm) => {
|
862 | if ((plt.$flags$ & 1 ) === 0) {
|
863 | const hostRef = getHostRef(elm);
|
864 | const instance = hostRef.$lazyInstance$ ;
|
865 | {
|
866 | safeCall(instance, 'disconnectedCallback');
|
867 | }
|
868 | }
|
869 | };
|
870 | const bootstrapLazy = (lazyBundles, options = {}) => {
|
871 | const endBootstrap = createTime();
|
872 | const cmpTags = [];
|
873 | const exclude = options.exclude || [];
|
874 | const customElements = win.customElements;
|
875 | const head = doc.head;
|
876 | const metaCharset = head.querySelector('meta[charset]');
|
877 | const visibilityStyle = doc.createElement('style');
|
878 | const deferredConnectedCallbacks = [];
|
879 | let appLoadFallback;
|
880 | let isBootstrapping = true;
|
881 | Object.assign(plt, options);
|
882 | plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
|
883 | lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
|
884 | const cmpMeta = {
|
885 | $flags$: compactMeta[0],
|
886 | $tagName$: compactMeta[1],
|
887 | $members$: compactMeta[2],
|
888 | $listeners$: compactMeta[3],
|
889 | };
|
890 | {
|
891 | cmpMeta.$members$ = compactMeta[2];
|
892 | }
|
893 | {
|
894 | cmpMeta.$attrsToReflect$ = [];
|
895 | }
|
896 | {
|
897 | cmpMeta.$watchers$ = {};
|
898 | }
|
899 | const tagName = cmpMeta.$tagName$;
|
900 | const HostElement = class extends HTMLElement {
|
901 |
|
902 | constructor(self) {
|
903 |
|
904 | super(self);
|
905 | self = this;
|
906 | registerHost(self, cmpMeta);
|
907 | if (cmpMeta.$flags$ & 1 ) {
|
908 |
|
909 |
|
910 |
|
911 |
|
912 | {
|
913 | {
|
914 | self.attachShadow({ mode: 'open' });
|
915 | }
|
916 | }
|
917 | }
|
918 | }
|
919 | connectedCallback() {
|
920 | if (appLoadFallback) {
|
921 | clearTimeout(appLoadFallback);
|
922 | appLoadFallback = null;
|
923 | }
|
924 | if (isBootstrapping) {
|
925 |
|
926 | deferredConnectedCallbacks.push(this);
|
927 | }
|
928 | else {
|
929 | plt.jmp(() => connectedCallback(this));
|
930 | }
|
931 | }
|
932 | disconnectedCallback() {
|
933 | plt.jmp(() => disconnectedCallback(this));
|
934 | }
|
935 | componentOnReady() {
|
936 | return getHostRef(this).$onReadyPromise$;
|
937 | }
|
938 | };
|
939 | cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
940 | if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
941 | cmpTags.push(tagName);
|
942 | customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 ));
|
943 | }
|
944 | }));
|
945 | {
|
946 | visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
|
947 | visibilityStyle.setAttribute('data-styles', '');
|
948 | head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
|
949 | }
|
950 |
|
951 | isBootstrapping = false;
|
952 | if (deferredConnectedCallbacks.length) {
|
953 | deferredConnectedCallbacks.map(host => host.connectedCallback());
|
954 | }
|
955 | else {
|
956 | {
|
957 | plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
|
958 | }
|
959 | }
|
960 |
|
961 | endBootstrap();
|
962 | };
|
963 | const getAssetPath = (path) => {
|
964 | const assetUrl = new URL(path, plt.$resourcesUrl$);
|
965 | return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
|
966 | };
|
967 | const hostRefs = new WeakMap();
|
968 | const getHostRef = (ref) => hostRefs.get(ref);
|
969 | const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
970 | const registerHost = (elm, cmpMeta) => {
|
971 | const hostRef = {
|
972 | $flags$: 0,
|
973 | $hostElement$: elm,
|
974 | $cmpMeta$: cmpMeta,
|
975 | $instanceValues$: new Map(),
|
976 | };
|
977 | {
|
978 | hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
|
979 | elm['s-p'] = [];
|
980 | elm['s-rc'] = [];
|
981 | }
|
982 | return hostRefs.set(elm, hostRef);
|
983 | };
|
984 | const isMemberInElement = (elm, memberName) => memberName in elm;
|
985 | const consoleError = (e, el) => (0, console.error)(e, el);
|
986 | const cmpModules = new Map();
|
987 | const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
988 |
|
989 | const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
|
990 | const bundleId = cmpMeta.$lazyBundleId$;
|
991 | const module = cmpModules.get(bundleId) ;
|
992 | if (module) {
|
993 | return module[exportName];
|
994 | }
|
995 | return import(
|
996 |
|
997 |
|
998 |
|
999 | `./${bundleId}.entry.js${''}`).then(importedModule => {
|
1000 | {
|
1001 | cmpModules.set(bundleId, importedModule);
|
1002 | }
|
1003 | return importedModule[exportName];
|
1004 | }, consoleError);
|
1005 | };
|
1006 | const styles = new Map();
|
1007 | const queueDomReads = [];
|
1008 | const queueDomWrites = [];
|
1009 | const queueTask = (queue, write) => (cb) => {
|
1010 | queue.push(cb);
|
1011 | if (!queuePending) {
|
1012 | queuePending = true;
|
1013 | if (write && plt.$flags$ & 4 ) {
|
1014 | nextTick(flush);
|
1015 | }
|
1016 | else {
|
1017 | plt.raf(flush);
|
1018 | }
|
1019 | }
|
1020 | };
|
1021 | const consume = (queue) => {
|
1022 | for (let i = 0; i < queue.length; i++) {
|
1023 | try {
|
1024 | queue[i](performance.now());
|
1025 | }
|
1026 | catch (e) {
|
1027 | consoleError(e);
|
1028 | }
|
1029 | }
|
1030 | queue.length = 0;
|
1031 | };
|
1032 | const flush = () => {
|
1033 |
|
1034 |
|
1035 |
|
1036 | consume(queueDomReads);
|
1037 |
|
1038 | {
|
1039 | consume(queueDomWrites);
|
1040 | if ((queuePending = queueDomReads.length > 0)) {
|
1041 |
|
1042 |
|
1043 | plt.raf(flush);
|
1044 | }
|
1045 | }
|
1046 | };
|
1047 | const nextTick = (cb) => promiseResolve().then(cb);
|
1048 | const writeTask = queueTask(queueDomWrites, true);
|
1049 |
|
1050 | export { Host as H, getElement as a, bootstrapLazy as b, getAssetPath as g, h, promiseResolve as p, registerInstance as r };
|