1 | const NAMESPACE = 'taro-components';
|
2 |
|
3 | let contentRef;
|
4 | let hostTagName;
|
5 | let useNativeShadowDom = false;
|
6 | let checkSlotFallbackVisibility = false;
|
7 | let checkSlotRelocate = false;
|
8 | let isSvgMode = false;
|
9 | let queuePending = false;
|
10 | const win = typeof window !== 'undefined' ? window : {};
|
11 | const doc = win.document || { head: {} };
|
12 | const plt = {
|
13 | $flags$: 0,
|
14 | $resourcesUrl$: '',
|
15 | jmp: (h) => h(),
|
16 | raf: (h) => requestAnimationFrame(h),
|
17 | ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
18 | rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
19 | ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
20 | };
|
21 | const promiseResolve = (v) => Promise.resolve(v);
|
22 | const supportsConstructibleStylesheets = (() => {
|
23 | try {
|
24 | new CSSStyleSheet();
|
25 | return typeof new CSSStyleSheet().replace === 'function';
|
26 | }
|
27 | catch (e) { }
|
28 | return false;
|
29 | })()
|
30 | ;
|
31 | const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
32 | if (listeners) {
|
33 | listeners.map(([flags, name, method]) => {
|
34 | const target = getHostListenerTarget(elm, flags) ;
|
35 | const handler = hostListenerProxy(hostRef, method);
|
36 | const opts = hostListenerOpts(flags);
|
37 | plt.ael(target, name, handler, opts);
|
38 | (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
39 | });
|
40 | }
|
41 | };
|
42 | const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
43 | try {
|
44 | {
|
45 | if (hostRef.$flags$ & 256 ) {
|
46 |
|
47 | hostRef.$lazyInstance$[methodName](ev);
|
48 | }
|
49 | else {
|
50 | (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
51 | }
|
52 | }
|
53 | }
|
54 | catch (e) {
|
55 | consoleError(e);
|
56 | }
|
57 | };
|
58 | const getHostListenerTarget = (elm, flags) => {
|
59 | if (flags & 4 )
|
60 | return doc;
|
61 | return elm;
|
62 | };
|
63 |
|
64 | const hostListenerOpts = (flags) => (flags & 2 ) !== 0;
|
65 | const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
66 | const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
67 | const createTime = (fnName, tagName = '') => {
|
68 | {
|
69 | return () => {
|
70 | return;
|
71 | };
|
72 | }
|
73 | };
|
74 | const uniqueTime = (key, measureText) => {
|
75 | {
|
76 | return () => {
|
77 | return;
|
78 | };
|
79 | }
|
80 | };
|
81 | const rootAppliedStyles = new WeakMap();
|
82 | const registerStyle = (scopeId, cssText, allowCS) => {
|
83 | let style = styles.get(scopeId);
|
84 | if (supportsConstructibleStylesheets && allowCS) {
|
85 | style = (style || new CSSStyleSheet());
|
86 | style.replace(cssText);
|
87 | }
|
88 | else {
|
89 | style = cssText;
|
90 | }
|
91 | styles.set(scopeId, style);
|
92 | };
|
93 | const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
94 | let scopeId = getScopeId(cmpMeta);
|
95 | let style = styles.get(scopeId);
|
96 |
|
97 |
|
98 | styleContainerNode = styleContainerNode.nodeType === 11 ? styleContainerNode : doc;
|
99 | if (style) {
|
100 | if (typeof style === 'string') {
|
101 | styleContainerNode = styleContainerNode.head || styleContainerNode;
|
102 | let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
103 | let styleElm;
|
104 | if (!appliedStyles) {
|
105 | rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
106 | }
|
107 | if (!appliedStyles.has(scopeId)) {
|
108 | {
|
109 | {
|
110 | styleElm = doc.createElement('style');
|
111 | styleElm.innerHTML = style;
|
112 | }
|
113 | styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
114 | }
|
115 | if (appliedStyles) {
|
116 | appliedStyles.add(scopeId);
|
117 | }
|
118 | }
|
119 | }
|
120 | else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
121 | styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
122 | }
|
123 | }
|
124 | return scopeId;
|
125 | };
|
126 | const attachStyles = (hostRef) => {
|
127 | const cmpMeta = hostRef.$cmpMeta$;
|
128 | const elm = hostRef.$hostElement$;
|
129 | const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
130 | addStyle(elm.getRootNode(), cmpMeta);
|
131 | endAttachStyles();
|
132 | };
|
133 | const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | const EMPTY_OBJ = {};
|
142 | const isComplexType = (o) => {
|
143 |
|
144 | o = typeof o;
|
145 | return o === 'object' || o === 'function';
|
146 | };
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | const h = (nodeName, vnodeData, ...children) => {
|
159 | let child = null;
|
160 | let key = null;
|
161 | let slotName = null;
|
162 | let simple = false;
|
163 | let lastSimple = false;
|
164 | let vNodeChildren = [];
|
165 | const walk = (c) => {
|
166 | for (let i = 0; i < c.length; i++) {
|
167 | child = c[i];
|
168 | if (Array.isArray(child)) {
|
169 | walk(child);
|
170 | }
|
171 | else if (child != null && typeof child !== 'boolean') {
|
172 | if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
|
173 | child = String(child);
|
174 | }
|
175 | if (simple && lastSimple) {
|
176 |
|
177 | vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
178 | }
|
179 | else {
|
180 |
|
181 | vNodeChildren.push(simple ? newVNode(null, child) : child);
|
182 | }
|
183 | lastSimple = simple;
|
184 | }
|
185 | }
|
186 | };
|
187 | walk(children);
|
188 | if (vnodeData) {
|
189 |
|
190 | if (vnodeData.key) {
|
191 | key = vnodeData.key;
|
192 | }
|
193 | if (vnodeData.name) {
|
194 | slotName = vnodeData.name;
|
195 | }
|
196 | {
|
197 | const classData = vnodeData.className || vnodeData.class;
|
198 | if (classData) {
|
199 | vnodeData.class =
|
200 | typeof classData !== 'object'
|
201 | ? classData
|
202 | : Object.keys(classData)
|
203 | .filter((k) => classData[k])
|
204 | .join(' ');
|
205 | }
|
206 | }
|
207 | }
|
208 | if (typeof nodeName === 'function') {
|
209 |
|
210 | return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
|
211 | }
|
212 | const vnode = newVNode(nodeName, null);
|
213 | vnode.$attrs$ = vnodeData;
|
214 | if (vNodeChildren.length > 0) {
|
215 | vnode.$children$ = vNodeChildren;
|
216 | }
|
217 | {
|
218 | vnode.$key$ = key;
|
219 | }
|
220 | {
|
221 | vnode.$name$ = slotName;
|
222 | }
|
223 | return vnode;
|
224 | };
|
225 | const newVNode = (tag, text) => {
|
226 | const vnode = {
|
227 | $flags$: 0,
|
228 | $tag$: tag,
|
229 | $text$: text,
|
230 | $elm$: null,
|
231 | $children$: null,
|
232 | };
|
233 | {
|
234 | vnode.$attrs$ = null;
|
235 | }
|
236 | {
|
237 | vnode.$key$ = null;
|
238 | }
|
239 | {
|
240 | vnode.$name$ = null;
|
241 | }
|
242 | return vnode;
|
243 | };
|
244 | const Host = {};
|
245 | const isHost = (node) => node && node.$tag$ === Host;
|
246 | const vdomFnUtils = {
|
247 | forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
248 | map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
|
249 | };
|
250 | const convertToPublic = (node) => ({
|
251 | vattrs: node.$attrs$,
|
252 | vchildren: node.$children$,
|
253 | vkey: node.$key$,
|
254 | vname: node.$name$,
|
255 | vtag: node.$tag$,
|
256 | vtext: node.$text$,
|
257 | });
|
258 | const convertToPrivate = (node) => {
|
259 | if (typeof node.vtag === 'function') {
|
260 | const vnodeData = Object.assign({}, node.vattrs);
|
261 | if (node.vkey) {
|
262 | vnodeData.key = node.vkey;
|
263 | }
|
264 | if (node.vname) {
|
265 | vnodeData.name = node.vname;
|
266 | }
|
267 | return h(node.vtag, vnodeData, ...(node.vchildren || []));
|
268 | }
|
269 | const vnode = newVNode(node.vtag, node.vtext);
|
270 | vnode.$attrs$ = node.vattrs;
|
271 | vnode.$children$ = node.vchildren;
|
272 | vnode.$key$ = node.vkey;
|
273 | vnode.$name$ = node.vname;
|
274 | return vnode;
|
275 | };
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
285 | if (oldValue !== newValue) {
|
286 | let isProp = isMemberInElement(elm, memberName);
|
287 | let ln = memberName.toLowerCase();
|
288 | if (memberName === 'class') {
|
289 | const classList = elm.classList;
|
290 | const oldClasses = parseClassList(oldValue);
|
291 | const newClasses = parseClassList(newValue);
|
292 | classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
|
293 | classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
|
294 | }
|
295 | else if (memberName === 'style') {
|
296 |
|
297 | {
|
298 | for (const prop in oldValue) {
|
299 | if (!newValue || newValue[prop] == null) {
|
300 | if (prop.includes('-')) {
|
301 | elm.style.removeProperty(prop);
|
302 | }
|
303 | else {
|
304 | elm.style[prop] = '';
|
305 | }
|
306 | }
|
307 | }
|
308 | }
|
309 | for (const prop in newValue) {
|
310 | if (!oldValue || newValue[prop] !== oldValue[prop]) {
|
311 | if (prop.includes('-')) {
|
312 | elm.style.setProperty(prop, newValue[prop]);
|
313 | }
|
314 | else {
|
315 | elm.style[prop] = newValue[prop];
|
316 | }
|
317 | }
|
318 | }
|
319 | }
|
320 | else if (memberName === 'key')
|
321 | ;
|
322 | else if (memberName === 'ref') {
|
323 |
|
324 | if (newValue) {
|
325 | newValue(elm);
|
326 | }
|
327 | }
|
328 | else if ((!isProp ) &&
|
329 | memberName[0] === 'o' &&
|
330 | memberName[1] === 'n') {
|
331 |
|
332 |
|
333 |
|
334 |
|
335 | if (memberName[2] === '-') {
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | memberName = memberName.slice(3);
|
344 | }
|
345 | else if (isMemberInElement(win, ln)) {
|
346 |
|
347 |
|
348 |
|
349 |
|
350 | memberName = ln.slice(2);
|
351 | }
|
352 | else {
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 | memberName = ln[2] + memberName.slice(3);
|
359 | }
|
360 | if (oldValue) {
|
361 | plt.rel(elm, memberName, oldValue, false);
|
362 | }
|
363 | if (newValue) {
|
364 | plt.ael(elm, memberName, newValue, false);
|
365 | }
|
366 | }
|
367 | else {
|
368 |
|
369 | const isComplex = isComplexType(newValue);
|
370 | if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
|
371 | try {
|
372 | if (!elm.tagName.includes('-')) {
|
373 | let n = newValue == null ? '' : newValue;
|
374 |
|
375 | if (memberName === 'list') {
|
376 | isProp = false;
|
377 | }
|
378 | else if (oldValue == null || elm[memberName] != n) {
|
379 | elm[memberName] = n;
|
380 | }
|
381 | }
|
382 | else {
|
383 | elm[memberName] = newValue;
|
384 | }
|
385 | }
|
386 | catch (e) { }
|
387 | }
|
388 | |
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 | let xlink = false;
|
396 | {
|
397 | if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
|
398 | memberName = ln;
|
399 | xlink = true;
|
400 | }
|
401 | }
|
402 | if (newValue == null || newValue === false) {
|
403 | if (newValue !== false || elm.getAttribute(memberName) === '') {
|
404 | if (xlink) {
|
405 | elm.removeAttributeNS(XLINK_NS, memberName);
|
406 | }
|
407 | else {
|
408 | elm.removeAttribute(memberName);
|
409 | }
|
410 | }
|
411 | }
|
412 | else if ((!isProp || flags & 4 || isSvg) && !isComplex) {
|
413 | newValue = newValue === true ? '' : newValue;
|
414 | if (xlink) {
|
415 | elm.setAttributeNS(XLINK_NS, memberName, newValue);
|
416 | }
|
417 | else {
|
418 | elm.setAttribute(memberName, newValue);
|
419 | }
|
420 | }
|
421 | }
|
422 | }
|
423 | };
|
424 | const parseClassListRegex = /\s/;
|
425 | const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
|
426 | const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
427 |
|
428 |
|
429 |
|
430 | const elm = newVnode.$elm$.nodeType === 11 && newVnode.$elm$.host
|
431 | ? newVnode.$elm$.host
|
432 | : newVnode.$elm$;
|
433 | const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
434 | const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
|
435 | {
|
436 |
|
437 | for (memberName in oldVnodeAttrs) {
|
438 | if (!(memberName in newVnodeAttrs)) {
|
439 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
|
440 | }
|
441 | }
|
442 | }
|
443 |
|
444 | for (memberName in newVnodeAttrs) {
|
445 | setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
446 | }
|
447 | };
|
448 | const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
449 |
|
450 | let newVNode = newParentVNode.$children$[childIndex];
|
451 | let i = 0;
|
452 | let elm;
|
453 | let childNode;
|
454 | let oldVNode;
|
455 | if (!useNativeShadowDom) {
|
456 |
|
457 | checkSlotRelocate = true;
|
458 | if (newVNode.$tag$ === 'slot') {
|
459 | newVNode.$flags$ |= newVNode.$children$
|
460 | ?
|
461 | 2
|
462 | :
|
463 | 1 ;
|
464 | }
|
465 | }
|
466 | if (newVNode.$text$ !== null) {
|
467 |
|
468 | elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
|
469 | }
|
470 | else if (newVNode.$flags$ & 1 ) {
|
471 |
|
472 | elm = newVNode.$elm$ =
|
473 | doc.createTextNode('');
|
474 | }
|
475 | else {
|
476 |
|
477 | elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2
|
478 | ? 'slot-fb'
|
479 | : newVNode.$tag$));
|
480 |
|
481 | {
|
482 | updateElement(null, newVNode, isSvgMode);
|
483 | }
|
484 | if (newVNode.$children$) {
|
485 | for (i = 0; i < newVNode.$children$.length; ++i) {
|
486 |
|
487 | childNode = createElm(oldParentVNode, newVNode, i);
|
488 |
|
489 | if (childNode) {
|
490 |
|
491 | elm.appendChild(childNode);
|
492 | }
|
493 | }
|
494 | }
|
495 | }
|
496 | {
|
497 | elm['s-hn'] = hostTagName;
|
498 | if (newVNode.$flags$ & (2 | 1 )) {
|
499 |
|
500 | elm['s-sr'] = true;
|
501 |
|
502 | elm['s-cr'] = contentRef;
|
503 |
|
504 | elm['s-sn'] = newVNode.$name$ || '';
|
505 |
|
506 | oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
|
507 | if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
|
508 |
|
509 |
|
510 | putBackInOriginalLocation(oldParentVNode.$elm$, false);
|
511 | }
|
512 | }
|
513 | }
|
514 | return elm;
|
515 | };
|
516 | const putBackInOriginalLocation = (parentElm, recursive) => {
|
517 | plt.$flags$ |= 1 ;
|
518 | const oldSlotChildNodes = parentElm.childNodes;
|
519 | for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
|
520 | const childNode = oldSlotChildNodes[i];
|
521 | if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
|
522 |
|
523 |
|
524 |
|
525 |
|
526 | parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
|
527 |
|
528 |
|
529 |
|
530 | childNode['s-ol'].remove();
|
531 | childNode['s-ol'] = undefined;
|
532 | checkSlotRelocate = true;
|
533 | }
|
534 | if (recursive) {
|
535 | putBackInOriginalLocation(childNode, recursive);
|
536 | }
|
537 | }
|
538 | plt.$flags$ &= ~1 ;
|
539 | };
|
540 | const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
541 | let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
|
542 | let childNode;
|
543 | for (; startIdx <= endIdx; ++startIdx) {
|
544 | if (vnodes[startIdx]) {
|
545 | childNode = createElm(null, parentVNode, startIdx);
|
546 | if (childNode) {
|
547 | vnodes[startIdx].$elm$ = childNode;
|
548 | containerElm.insertBefore(childNode, referenceNode(before) );
|
549 | }
|
550 | }
|
551 | }
|
552 | };
|
553 | const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
554 | for (; startIdx <= endIdx; ++startIdx) {
|
555 | if ((vnode = vnodes[startIdx])) {
|
556 | elm = vnode.$elm$;
|
557 | callNodeRefs(vnode);
|
558 | {
|
559 |
|
560 |
|
561 | checkSlotFallbackVisibility = true;
|
562 | if (elm['s-ol']) {
|
563 |
|
564 | elm['s-ol'].remove();
|
565 | }
|
566 | else {
|
567 |
|
568 |
|
569 | putBackInOriginalLocation(elm, true);
|
570 | }
|
571 | }
|
572 |
|
573 | elm.remove();
|
574 | }
|
575 | }
|
576 | };
|
577 | const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
578 | let oldStartIdx = 0;
|
579 | let newStartIdx = 0;
|
580 | let idxInOld = 0;
|
581 | let i = 0;
|
582 | let oldEndIdx = oldCh.length - 1;
|
583 | let oldStartVnode = oldCh[0];
|
584 | let oldEndVnode = oldCh[oldEndIdx];
|
585 | let newEndIdx = newCh.length - 1;
|
586 | let newStartVnode = newCh[0];
|
587 | let newEndVnode = newCh[newEndIdx];
|
588 | let node;
|
589 | let elmToMove;
|
590 | while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
591 | if (oldStartVnode == null) {
|
592 |
|
593 | oldStartVnode = oldCh[++oldStartIdx];
|
594 | }
|
595 | else if (oldEndVnode == null) {
|
596 | oldEndVnode = oldCh[--oldEndIdx];
|
597 | }
|
598 | else if (newStartVnode == null) {
|
599 | newStartVnode = newCh[++newStartIdx];
|
600 | }
|
601 | else if (newEndVnode == null) {
|
602 | newEndVnode = newCh[--newEndIdx];
|
603 | }
|
604 | else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
605 | patch(oldStartVnode, newStartVnode);
|
606 | oldStartVnode = oldCh[++oldStartIdx];
|
607 | newStartVnode = newCh[++newStartIdx];
|
608 | }
|
609 | else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
610 | patch(oldEndVnode, newEndVnode);
|
611 | oldEndVnode = oldCh[--oldEndIdx];
|
612 | newEndVnode = newCh[--newEndIdx];
|
613 | }
|
614 | else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
615 |
|
616 | if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
617 | putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
|
618 | }
|
619 | patch(oldStartVnode, newEndVnode);
|
620 | parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
621 | oldStartVnode = oldCh[++oldStartIdx];
|
622 | newEndVnode = newCh[--newEndIdx];
|
623 | }
|
624 | else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
625 |
|
626 | if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
627 | putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
|
628 | }
|
629 | patch(oldEndVnode, newStartVnode);
|
630 | parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
631 | oldEndVnode = oldCh[--oldEndIdx];
|
632 | newStartVnode = newCh[++newStartIdx];
|
633 | }
|
634 | else {
|
635 |
|
636 | idxInOld = -1;
|
637 | {
|
638 | for (i = oldStartIdx; i <= oldEndIdx; ++i) {
|
639 | if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
|
640 | idxInOld = i;
|
641 | break;
|
642 | }
|
643 | }
|
644 | }
|
645 | if (idxInOld >= 0) {
|
646 | elmToMove = oldCh[idxInOld];
|
647 | if (elmToMove.$tag$ !== newStartVnode.$tag$) {
|
648 | node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
|
649 | }
|
650 | else {
|
651 | patch(elmToMove, newStartVnode);
|
652 | oldCh[idxInOld] = undefined;
|
653 | node = elmToMove.$elm$;
|
654 | }
|
655 | newStartVnode = newCh[++newStartIdx];
|
656 | }
|
657 | else {
|
658 |
|
659 | node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
660 | newStartVnode = newCh[++newStartIdx];
|
661 | }
|
662 | if (node) {
|
663 | {
|
664 | parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
|
665 | }
|
666 | }
|
667 | }
|
668 | }
|
669 | if (oldStartIdx > oldEndIdx) {
|
670 | addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
671 | }
|
672 | else if (newStartIdx > newEndIdx) {
|
673 | removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
674 | }
|
675 | };
|
676 | const isSameVnode = (vnode1, vnode2) => {
|
677 |
|
678 |
|
679 | if (vnode1.$tag$ === vnode2.$tag$) {
|
680 | if (vnode1.$tag$ === 'slot') {
|
681 | return vnode1.$name$ === vnode2.$name$;
|
682 | }
|
683 | {
|
684 | return vnode1.$key$ === vnode2.$key$;
|
685 | }
|
686 | }
|
687 | return false;
|
688 | };
|
689 | const referenceNode = (node) => {
|
690 |
|
691 |
|
692 |
|
693 |
|
694 | return (node && node['s-ol']) || node;
|
695 | };
|
696 | const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
|
697 | const patch = (oldVNode, newVNode) => {
|
698 | const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
699 | const oldChildren = oldVNode.$children$;
|
700 | const newChildren = newVNode.$children$;
|
701 | const tag = newVNode.$tag$;
|
702 | const text = newVNode.$text$;
|
703 | let defaultHolder;
|
704 | if (text === null) {
|
705 |
|
706 | {
|
707 | if (tag === 'slot')
|
708 | ;
|
709 | else {
|
710 |
|
711 |
|
712 |
|
713 | updateElement(oldVNode, newVNode, isSvgMode);
|
714 | }
|
715 | }
|
716 | if (oldChildren !== null && newChildren !== null) {
|
717 |
|
718 | updateChildren(elm, oldChildren, newVNode, newChildren);
|
719 | }
|
720 | else if (newChildren !== null) {
|
721 |
|
722 | if (oldVNode.$text$ !== null) {
|
723 |
|
724 | elm.textContent = '';
|
725 | }
|
726 |
|
727 | addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
728 | }
|
729 | else if (oldChildren !== null) {
|
730 |
|
731 | removeVnodes(oldChildren, 0, oldChildren.length - 1);
|
732 | }
|
733 | }
|
734 | else if ((defaultHolder = elm['s-cr'])) {
|
735 |
|
736 | defaultHolder.parentNode.textContent = text;
|
737 | }
|
738 | else if (oldVNode.$text$ !== text) {
|
739 |
|
740 |
|
741 | elm.data = text;
|
742 | }
|
743 | };
|
744 | const updateFallbackSlotVisibility = (elm) => {
|
745 |
|
746 | let childNodes = elm.childNodes;
|
747 | let childNode;
|
748 | let i;
|
749 | let ilen;
|
750 | let j;
|
751 | let slotNameAttr;
|
752 | let nodeType;
|
753 | for (i = 0, ilen = childNodes.length; i < ilen; i++) {
|
754 | childNode = childNodes[i];
|
755 | if (childNode.nodeType === 1 ) {
|
756 | if (childNode['s-sr']) {
|
757 |
|
758 |
|
759 | slotNameAttr = childNode['s-sn'];
|
760 |
|
761 |
|
762 | childNode.hidden = false;
|
763 | for (j = 0; j < ilen; j++) {
|
764 | nodeType = childNodes[j].nodeType;
|
765 | if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
|
766 |
|
767 | if (nodeType === 1 && slotNameAttr === childNodes[j].getAttribute('slot')) {
|
768 | childNode.hidden = true;
|
769 | break;
|
770 | }
|
771 | }
|
772 | else {
|
773 |
|
774 |
|
775 |
|
776 | if (nodeType === 1 ||
|
777 | (nodeType === 3 && childNodes[j].textContent.trim() !== '')) {
|
778 | childNode.hidden = true;
|
779 | break;
|
780 | }
|
781 | }
|
782 | }
|
783 | }
|
784 |
|
785 | updateFallbackSlotVisibility(childNode);
|
786 | }
|
787 | }
|
788 | };
|
789 | const relocateNodes = [];
|
790 | const relocateSlotContent = (elm) => {
|
791 |
|
792 | let childNode;
|
793 | let node;
|
794 | let hostContentNodes;
|
795 | let slotNameAttr;
|
796 | let relocateNodeData;
|
797 | let j;
|
798 | let i = 0;
|
799 | let childNodes = elm.childNodes;
|
800 | let ilen = childNodes.length;
|
801 | for (; i < ilen; i++) {
|
802 | childNode = childNodes[i];
|
803 | if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
|
804 |
|
805 |
|
806 | hostContentNodes = node.parentNode.childNodes;
|
807 | slotNameAttr = childNode['s-sn'];
|
808 | for (j = hostContentNodes.length - 1; j >= 0; j--) {
|
809 | node = hostContentNodes[j];
|
810 | if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
|
811 |
|
812 |
|
813 |
|
814 | if (isNodeLocatedInSlot(node, slotNameAttr)) {
|
815 |
|
816 | relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
|
817 |
|
818 |
|
819 |
|
820 | checkSlotFallbackVisibility = true;
|
821 | node['s-sn'] = node['s-sn'] || slotNameAttr;
|
822 | if (relocateNodeData) {
|
823 |
|
824 |
|
825 | relocateNodeData.$slotRefNode$ = childNode;
|
826 | }
|
827 | else {
|
828 |
|
829 | relocateNodes.push({
|
830 | $slotRefNode$: childNode,
|
831 | $nodeToRelocate$: node,
|
832 | });
|
833 | }
|
834 | if (node['s-sr']) {
|
835 | relocateNodes.map((relocateNode) => {
|
836 | if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
|
837 | relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
|
838 | if (relocateNodeData && !relocateNode.$slotRefNode$) {
|
839 | relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
|
840 | }
|
841 | }
|
842 | });
|
843 | }
|
844 | }
|
845 | else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
|
846 |
|
847 |
|
848 | relocateNodes.push({
|
849 | $nodeToRelocate$: node,
|
850 | });
|
851 | }
|
852 | }
|
853 | }
|
854 | }
|
855 | if (childNode.nodeType === 1 ) {
|
856 | relocateSlotContent(childNode);
|
857 | }
|
858 | }
|
859 | };
|
860 | const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
|
861 | if (nodeToRelocate.nodeType === 1 ) {
|
862 | if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
|
863 | return true;
|
864 | }
|
865 | if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
|
866 | return true;
|
867 | }
|
868 | return false;
|
869 | }
|
870 | if (nodeToRelocate['s-sn'] === slotNameAttr) {
|
871 | return true;
|
872 | }
|
873 | return slotNameAttr === '';
|
874 | };
|
875 | const callNodeRefs = (vNode) => {
|
876 | {
|
877 | vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
|
878 | vNode.$children$ && vNode.$children$.map(callNodeRefs);
|
879 | }
|
880 | };
|
881 | const renderVdom = (hostRef, renderFnResults) => {
|
882 | const hostElm = hostRef.$hostElement$;
|
883 | const cmpMeta = hostRef.$cmpMeta$;
|
884 | const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
885 | const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
|
886 | hostTagName = hostElm.tagName;
|
887 | rootVnode.$tag$ = null;
|
888 | rootVnode.$flags$ |= 4 ;
|
889 | hostRef.$vnode$ = rootVnode;
|
890 | rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
|
891 | {
|
892 | contentRef = hostElm['s-cr'];
|
893 | useNativeShadowDom = (cmpMeta.$flags$ & 1 ) !== 0;
|
894 |
|
895 | checkSlotFallbackVisibility = false;
|
896 | }
|
897 |
|
898 | patch(oldVNode, rootVnode);
|
899 | {
|
900 |
|
901 |
|
902 | plt.$flags$ |= 1 ;
|
903 | if (checkSlotRelocate) {
|
904 | relocateSlotContent(rootVnode.$elm$);
|
905 | let relocateData;
|
906 | let nodeToRelocate;
|
907 | let orgLocationNode;
|
908 | let parentNodeRef;
|
909 | let insertBeforeNode;
|
910 | let refNode;
|
911 | let i = 0;
|
912 | for (; i < relocateNodes.length; i++) {
|
913 | relocateData = relocateNodes[i];
|
914 | nodeToRelocate = relocateData.$nodeToRelocate$;
|
915 | if (!nodeToRelocate['s-ol']) {
|
916 |
|
917 |
|
918 | orgLocationNode =
|
919 | doc.createTextNode('');
|
920 | orgLocationNode['s-nr'] = nodeToRelocate;
|
921 | nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
|
922 | }
|
923 | }
|
924 | for (i = 0; i < relocateNodes.length; i++) {
|
925 | relocateData = relocateNodes[i];
|
926 | nodeToRelocate = relocateData.$nodeToRelocate$;
|
927 | if (relocateData.$slotRefNode$) {
|
928 |
|
929 |
|
930 | parentNodeRef = relocateData.$slotRefNode$.parentNode;
|
931 | insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
|
932 | orgLocationNode = nodeToRelocate['s-ol'];
|
933 | while ((orgLocationNode = orgLocationNode.previousSibling)) {
|
934 | refNode = orgLocationNode['s-nr'];
|
935 | if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
|
936 | refNode = refNode.nextSibling;
|
937 | if (!refNode || !refNode['s-nr']) {
|
938 | insertBeforeNode = refNode;
|
939 | break;
|
940 | }
|
941 | }
|
942 | }
|
943 | if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
|
944 | nodeToRelocate.nextSibling !== insertBeforeNode) {
|
945 |
|
946 |
|
947 |
|
948 | if (nodeToRelocate !== insertBeforeNode) {
|
949 | if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
|
950 |
|
951 | nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
|
952 | }
|
953 |
|
954 | parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
|
955 | }
|
956 | }
|
957 | }
|
958 | else {
|
959 |
|
960 | if (nodeToRelocate.nodeType === 1 ) {
|
961 | nodeToRelocate.hidden = true;
|
962 | }
|
963 | }
|
964 | }
|
965 | }
|
966 | if (checkSlotFallbackVisibility) {
|
967 | updateFallbackSlotVisibility(rootVnode.$elm$);
|
968 | }
|
969 |
|
970 |
|
971 | plt.$flags$ &= ~1 ;
|
972 |
|
973 | relocateNodes.length = 0;
|
974 | }
|
975 | };
|
976 | const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
977 | const createEvent = (ref, name, flags) => {
|
978 | const elm = getElement(ref);
|
979 | return {
|
980 | emit: (detail) => {
|
981 | return emitEvent(elm, name, {
|
982 | bubbles: !!(flags & 4 ),
|
983 | composed: !!(flags & 2 ),
|
984 | cancelable: !!(flags & 1 ),
|
985 | detail,
|
986 | });
|
987 | },
|
988 | };
|
989 | };
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 | const emitEvent = (elm, name, opts) => {
|
998 | const ev = plt.ce(name, opts);
|
999 | elm.dispatchEvent(ev);
|
1000 | return ev;
|
1001 | };
|
1002 | const attachToAncestor = (hostRef, ancestorComponent) => {
|
1003 | if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
1004 | ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
1005 | }
|
1006 | };
|
1007 | const scheduleUpdate = (hostRef, isInitialLoad) => {
|
1008 | {
|
1009 | hostRef.$flags$ |= 16 ;
|
1010 | }
|
1011 | if (hostRef.$flags$ & 4 ) {
|
1012 | hostRef.$flags$ |= 512 ;
|
1013 | return;
|
1014 | }
|
1015 | attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
1016 |
|
1017 |
|
1018 |
|
1019 | const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
1020 | return writeTask(dispatch) ;
|
1021 | };
|
1022 | const dispatchHooks = (hostRef, isInitialLoad) => {
|
1023 | const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
1024 | const instance = hostRef.$lazyInstance$ ;
|
1025 | let promise;
|
1026 | if (isInitialLoad) {
|
1027 | {
|
1028 | hostRef.$flags$ |= 256 ;
|
1029 | if (hostRef.$queuedListeners$) {
|
1030 | hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
|
1031 | hostRef.$queuedListeners$ = null;
|
1032 | }
|
1033 | }
|
1034 | {
|
1035 | promise = safeCall(instance, 'componentWillLoad');
|
1036 | }
|
1037 | }
|
1038 | else {
|
1039 | {
|
1040 | promise = safeCall(instance, 'componentWillUpdate');
|
1041 | }
|
1042 | }
|
1043 | endSchedule();
|
1044 | return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
|
1045 | };
|
1046 | const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
1047 |
|
1048 | const elm = hostRef.$hostElement$;
|
1049 | const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
1050 | const rc = elm['s-rc'];
|
1051 | if (isInitialLoad) {
|
1052 |
|
1053 | attachStyles(hostRef);
|
1054 | }
|
1055 | const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
|
1056 | {
|
1057 | callRender(hostRef, instance);
|
1058 | }
|
1059 | if (rc) {
|
1060 |
|
1061 |
|
1062 |
|
1063 | rc.map((cb) => cb());
|
1064 | elm['s-rc'] = undefined;
|
1065 | }
|
1066 | endRender();
|
1067 | endUpdate();
|
1068 | {
|
1069 | const childrenPromises = elm['s-p'];
|
1070 | const postUpdate = () => postUpdateComponent(hostRef);
|
1071 | if (childrenPromises.length === 0) {
|
1072 | postUpdate();
|
1073 | }
|
1074 | else {
|
1075 | Promise.all(childrenPromises).then(postUpdate);
|
1076 | hostRef.$flags$ |= 4 ;
|
1077 | childrenPromises.length = 0;
|
1078 | }
|
1079 | }
|
1080 | };
|
1081 | const callRender = (hostRef, instance, elm) => {
|
1082 | try {
|
1083 | instance = instance.render() ;
|
1084 | {
|
1085 | hostRef.$flags$ &= ~16 ;
|
1086 | }
|
1087 | {
|
1088 | hostRef.$flags$ |= 2 ;
|
1089 | }
|
1090 | {
|
1091 | {
|
1092 |
|
1093 |
|
1094 |
|
1095 | {
|
1096 | renderVdom(hostRef, instance);
|
1097 | }
|
1098 | }
|
1099 | }
|
1100 | }
|
1101 | catch (e) {
|
1102 | consoleError(e, hostRef.$hostElement$);
|
1103 | }
|
1104 | return null;
|
1105 | };
|
1106 | const postUpdateComponent = (hostRef) => {
|
1107 | const tagName = hostRef.$cmpMeta$.$tagName$;
|
1108 | const elm = hostRef.$hostElement$;
|
1109 | const endPostUpdate = createTime('postUpdate', tagName);
|
1110 | const instance = hostRef.$lazyInstance$ ;
|
1111 | const ancestorComponent = hostRef.$ancestorComponent$;
|
1112 | {
|
1113 | safeCall(instance, 'componentDidRender');
|
1114 | }
|
1115 | if (!(hostRef.$flags$ & 64 )) {
|
1116 | hostRef.$flags$ |= 64 ;
|
1117 | {
|
1118 |
|
1119 | addHydratedFlag(elm);
|
1120 | }
|
1121 | {
|
1122 | safeCall(instance, 'componentDidLoad');
|
1123 | }
|
1124 | endPostUpdate();
|
1125 | {
|
1126 | hostRef.$onReadyResolve$(elm);
|
1127 | if (!ancestorComponent) {
|
1128 | appDidLoad();
|
1129 | }
|
1130 | }
|
1131 | }
|
1132 | else {
|
1133 | {
|
1134 | safeCall(instance, 'componentDidUpdate');
|
1135 | }
|
1136 | endPostUpdate();
|
1137 | }
|
1138 | {
|
1139 | hostRef.$onInstanceResolve$(elm);
|
1140 | }
|
1141 |
|
1142 |
|
1143 | {
|
1144 | if (hostRef.$onRenderResolve$) {
|
1145 | hostRef.$onRenderResolve$();
|
1146 | hostRef.$onRenderResolve$ = undefined;
|
1147 | }
|
1148 | if (hostRef.$flags$ & 512 ) {
|
1149 | nextTick(() => scheduleUpdate(hostRef, false));
|
1150 | }
|
1151 | hostRef.$flags$ &= ~(4 | 512 );
|
1152 | }
|
1153 |
|
1154 |
|
1155 |
|
1156 | };
|
1157 | const appDidLoad = (who) => {
|
1158 |
|
1159 |
|
1160 | {
|
1161 | addHydratedFlag(doc.documentElement);
|
1162 | }
|
1163 | nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
1164 | };
|
1165 | const safeCall = (instance, method, arg) => {
|
1166 | if (instance && instance[method]) {
|
1167 | try {
|
1168 | return instance[method](arg);
|
1169 | }
|
1170 | catch (e) {
|
1171 | consoleError(e);
|
1172 | }
|
1173 | }
|
1174 | return undefined;
|
1175 | };
|
1176 | const then = (promise, thenFn) => {
|
1177 | return promise && promise.then ? promise.then(thenFn) : thenFn();
|
1178 | };
|
1179 | const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
1180 | ;
|
1181 | const parsePropertyValue = (propValue, propType) => {
|
1182 |
|
1183 | if (propValue != null && !isComplexType(propValue)) {
|
1184 | if (propType & 4 ) {
|
1185 |
|
1186 |
|
1187 | return propValue === 'false' ? false : propValue === '' || !!propValue;
|
1188 | }
|
1189 | if (propType & 2 ) {
|
1190 |
|
1191 | return parseFloat(propValue);
|
1192 | }
|
1193 | if (propType & 1 ) {
|
1194 |
|
1195 |
|
1196 | return String(propValue);
|
1197 | }
|
1198 |
|
1199 | return propValue;
|
1200 | }
|
1201 |
|
1202 |
|
1203 | return propValue;
|
1204 | };
|
1205 | const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
1206 | const setValue = (ref, propName, newVal, cmpMeta) => {
|
1207 |
|
1208 | const hostRef = getHostRef(ref);
|
1209 | const elm = hostRef.$hostElement$ ;
|
1210 | const oldVal = hostRef.$instanceValues$.get(propName);
|
1211 | const flags = hostRef.$flags$;
|
1212 | const instance = hostRef.$lazyInstance$ ;
|
1213 | newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
|
1214 | if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
|
1215 |
|
1216 |
|
1217 | hostRef.$instanceValues$.set(propName, newVal);
|
1218 | if (instance) {
|
1219 |
|
1220 | if (cmpMeta.$watchers$ && flags & 128 ) {
|
1221 | const watchMethods = cmpMeta.$watchers$[propName];
|
1222 | if (watchMethods) {
|
1223 |
|
1224 | watchMethods.map((watchMethodName) => {
|
1225 | try {
|
1226 |
|
1227 | instance[watchMethodName](newVal, oldVal, propName);
|
1228 | }
|
1229 | catch (e) {
|
1230 | consoleError(e, elm);
|
1231 | }
|
1232 | });
|
1233 | }
|
1234 | }
|
1235 | if ((flags & (2 | 16 )) === 2 ) {
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 | scheduleUpdate(hostRef, false);
|
1241 | }
|
1242 | }
|
1243 | }
|
1244 | };
|
1245 | const proxyComponent = (Cstr, cmpMeta, flags) => {
|
1246 | if (cmpMeta.$members$) {
|
1247 | if (Cstr.watchers) {
|
1248 | cmpMeta.$watchers$ = Cstr.watchers;
|
1249 | }
|
1250 |
|
1251 | const members = Object.entries(cmpMeta.$members$);
|
1252 | const prototype = Cstr.prototype;
|
1253 | members.map(([memberName, [memberFlags]]) => {
|
1254 | if ((memberFlags & 31 ||
|
1255 | ((flags & 2 ) && memberFlags & 32 ))) {
|
1256 |
|
1257 | Object.defineProperty(prototype, memberName, {
|
1258 | get() {
|
1259 |
|
1260 | return getValue(this, memberName);
|
1261 | },
|
1262 | set(newValue) {
|
1263 |
|
1264 | setValue(this, memberName, newValue, cmpMeta);
|
1265 | },
|
1266 | configurable: true,
|
1267 | enumerable: true,
|
1268 | });
|
1269 | }
|
1270 | else if (flags & 1 &&
|
1271 | memberFlags & 64 ) {
|
1272 |
|
1273 | Object.defineProperty(prototype, memberName, {
|
1274 | value(...args) {
|
1275 | const ref = getHostRef(this);
|
1276 | return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
|
1277 | },
|
1278 | });
|
1279 | }
|
1280 | });
|
1281 | if ((flags & 1 )) {
|
1282 | const attrNameToPropName = new Map();
|
1283 | prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
1284 | plt.jmp(() => {
|
1285 | const propName = attrNameToPropName.get(attrName);
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 | if (this.hasOwnProperty(propName)) {
|
1320 | newValue = this[propName];
|
1321 | delete this[propName];
|
1322 | }
|
1323 | else if (prototype.hasOwnProperty(propName) &&
|
1324 | typeof this[propName] === 'number' &&
|
1325 | this[propName] == newValue) {
|
1326 |
|
1327 |
|
1328 |
|
1329 | return;
|
1330 | }
|
1331 | this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
|
1332 | });
|
1333 | };
|
1334 |
|
1335 |
|
1336 | Cstr.observedAttributes = members
|
1337 | .filter(([_, m]) => m[0] & 15 )
|
1338 | .map(([propName, m]) => {
|
1339 | const attrName = m[1] || propName;
|
1340 | attrNameToPropName.set(attrName, propName);
|
1341 | return attrName;
|
1342 | });
|
1343 | }
|
1344 | }
|
1345 | return Cstr;
|
1346 | };
|
1347 | const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
1348 |
|
1349 | if ((hostRef.$flags$ & 32 ) === 0) {
|
1350 | {
|
1351 |
|
1352 | hostRef.$flags$ |= 32 ;
|
1353 |
|
1354 |
|
1355 |
|
1356 | Cstr = loadModule(cmpMeta);
|
1357 | if (Cstr.then) {
|
1358 |
|
1359 | const endLoad = uniqueTime();
|
1360 | Cstr = await Cstr;
|
1361 | endLoad();
|
1362 | }
|
1363 | if (!Cstr.isProxied) {
|
1364 |
|
1365 |
|
1366 |
|
1367 | {
|
1368 | cmpMeta.$watchers$ = Cstr.watchers;
|
1369 | }
|
1370 | proxyComponent(Cstr, cmpMeta, 2 );
|
1371 | Cstr.isProxied = true;
|
1372 | }
|
1373 | const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
1374 |
|
1375 |
|
1376 |
|
1377 | {
|
1378 | hostRef.$flags$ |= 8 ;
|
1379 | }
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 | try {
|
1385 | new Cstr(hostRef);
|
1386 | }
|
1387 | catch (e) {
|
1388 | consoleError(e);
|
1389 | }
|
1390 | {
|
1391 | hostRef.$flags$ &= ~8 ;
|
1392 | }
|
1393 | {
|
1394 | hostRef.$flags$ |= 128 ;
|
1395 | }
|
1396 | endNewInstance();
|
1397 | fireConnectedCallback(hostRef.$lazyInstance$);
|
1398 | }
|
1399 | if (Cstr.style) {
|
1400 |
|
1401 | let style = Cstr.style;
|
1402 | const scopeId = getScopeId(cmpMeta);
|
1403 | if (!styles.has(scopeId)) {
|
1404 | const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
1405 | registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 ));
|
1406 | endRegisterStyles();
|
1407 | }
|
1408 | }
|
1409 | }
|
1410 |
|
1411 | const ancestorComponent = hostRef.$ancestorComponent$;
|
1412 | const schedule = () => scheduleUpdate(hostRef, true);
|
1413 | if (ancestorComponent && ancestorComponent['s-rc']) {
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 | ancestorComponent['s-rc'].push(schedule);
|
1421 | }
|
1422 | else {
|
1423 | schedule();
|
1424 | }
|
1425 | };
|
1426 | const fireConnectedCallback = (instance) => {
|
1427 | {
|
1428 | safeCall(instance, 'connectedCallback');
|
1429 | }
|
1430 | };
|
1431 | const connectedCallback = (elm) => {
|
1432 | if ((plt.$flags$ & 1 ) === 0) {
|
1433 | const hostRef = getHostRef(elm);
|
1434 | const cmpMeta = hostRef.$cmpMeta$;
|
1435 | const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
1436 | if (!(hostRef.$flags$ & 1 )) {
|
1437 |
|
1438 | hostRef.$flags$ |= 1 ;
|
1439 | {
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 | if ((cmpMeta.$flags$ & (4 | 8 ))) {
|
1445 | setContentReference(elm);
|
1446 | }
|
1447 | }
|
1448 | {
|
1449 |
|
1450 |
|
1451 | let ancestorComponent = elm;
|
1452 | while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
|
1453 |
|
1454 |
|
1455 | if (ancestorComponent['s-p']) {
|
1456 |
|
1457 |
|
1458 | attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
|
1459 | break;
|
1460 | }
|
1461 | }
|
1462 | }
|
1463 |
|
1464 |
|
1465 | if (cmpMeta.$members$) {
|
1466 | Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
1467 | if (memberFlags & 31 && elm.hasOwnProperty(memberName)) {
|
1468 | const value = elm[memberName];
|
1469 | delete elm[memberName];
|
1470 | elm[memberName] = value;
|
1471 | }
|
1472 | });
|
1473 | }
|
1474 | {
|
1475 | initializeComponent(elm, hostRef, cmpMeta);
|
1476 | }
|
1477 | }
|
1478 | else {
|
1479 |
|
1480 |
|
1481 |
|
1482 | addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
|
1483 |
|
1484 | fireConnectedCallback(hostRef.$lazyInstance$);
|
1485 | }
|
1486 | endConnected();
|
1487 | }
|
1488 | };
|
1489 | const setContentReference = (elm) => {
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 | const contentRefElm = (elm['s-cr'] = doc.createComment(''));
|
1497 | contentRefElm['s-cn'] = true;
|
1498 | elm.insertBefore(contentRefElm, elm.firstChild);
|
1499 | };
|
1500 | const disconnectedCallback = (elm) => {
|
1501 | if ((plt.$flags$ & 1 ) === 0) {
|
1502 | const hostRef = getHostRef(elm);
|
1503 | const instance = hostRef.$lazyInstance$ ;
|
1504 | {
|
1505 | if (hostRef.$rmListeners$) {
|
1506 | hostRef.$rmListeners$.map((rmListener) => rmListener());
|
1507 | hostRef.$rmListeners$ = undefined;
|
1508 | }
|
1509 | }
|
1510 | {
|
1511 | safeCall(instance, 'disconnectedCallback');
|
1512 | }
|
1513 | }
|
1514 | };
|
1515 | const bootstrapLazy = (lazyBundles, options = {}) => {
|
1516 | const endBootstrap = createTime();
|
1517 | const cmpTags = [];
|
1518 | const exclude = options.exclude || [];
|
1519 | const customElements = win.customElements;
|
1520 | const head = doc.head;
|
1521 | const metaCharset = head.querySelector('meta[charset]');
|
1522 | const visibilityStyle = doc.createElement('style');
|
1523 | const deferredConnectedCallbacks = [];
|
1524 | let appLoadFallback;
|
1525 | let isBootstrapping = true;
|
1526 | Object.assign(plt, options);
|
1527 | plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
|
1528 | lazyBundles.map((lazyBundle) => {
|
1529 | lazyBundle[1].map((compactMeta) => {
|
1530 | const cmpMeta = {
|
1531 | $flags$: compactMeta[0],
|
1532 | $tagName$: compactMeta[1],
|
1533 | $members$: compactMeta[2],
|
1534 | $listeners$: compactMeta[3],
|
1535 | };
|
1536 | {
|
1537 | cmpMeta.$members$ = compactMeta[2];
|
1538 | }
|
1539 | {
|
1540 | cmpMeta.$listeners$ = compactMeta[3];
|
1541 | }
|
1542 | {
|
1543 | cmpMeta.$watchers$ = {};
|
1544 | }
|
1545 | const tagName = cmpMeta.$tagName$;
|
1546 | const HostElement = class extends HTMLElement {
|
1547 |
|
1548 | constructor(self) {
|
1549 |
|
1550 | super(self);
|
1551 | self = this;
|
1552 | registerHost(self, cmpMeta);
|
1553 | }
|
1554 | connectedCallback() {
|
1555 | if (appLoadFallback) {
|
1556 | clearTimeout(appLoadFallback);
|
1557 | appLoadFallback = null;
|
1558 | }
|
1559 | if (isBootstrapping) {
|
1560 |
|
1561 | deferredConnectedCallbacks.push(this);
|
1562 | }
|
1563 | else {
|
1564 | plt.jmp(() => connectedCallback(this));
|
1565 | }
|
1566 | }
|
1567 | disconnectedCallback() {
|
1568 | plt.jmp(() => disconnectedCallback(this));
|
1569 | }
|
1570 | componentOnReady() {
|
1571 | return getHostRef(this).$onReadyPromise$;
|
1572 | }
|
1573 | };
|
1574 | cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
1575 | if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
1576 | cmpTags.push(tagName);
|
1577 | customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 ));
|
1578 | }
|
1579 | });
|
1580 | });
|
1581 | {
|
1582 | visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
|
1583 | visibilityStyle.setAttribute('data-styles', '');
|
1584 | head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
|
1585 | }
|
1586 |
|
1587 | isBootstrapping = false;
|
1588 | if (deferredConnectedCallbacks.length) {
|
1589 | deferredConnectedCallbacks.map((host) => host.connectedCallback());
|
1590 | }
|
1591 | else {
|
1592 | {
|
1593 | plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
|
1594 | }
|
1595 | }
|
1596 |
|
1597 | endBootstrap();
|
1598 | };
|
1599 | const hostRefs = new WeakMap();
|
1600 | const getHostRef = (ref) => hostRefs.get(ref);
|
1601 | const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
1602 | const registerHost = (elm, cmpMeta) => {
|
1603 | const hostRef = {
|
1604 | $flags$: 0,
|
1605 | $hostElement$: elm,
|
1606 | $cmpMeta$: cmpMeta,
|
1607 | $instanceValues$: new Map(),
|
1608 | };
|
1609 | {
|
1610 | hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
|
1611 | }
|
1612 | {
|
1613 | hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
|
1614 | elm['s-p'] = [];
|
1615 | elm['s-rc'] = [];
|
1616 | }
|
1617 | addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
|
1618 | return hostRefs.set(elm, hostRef);
|
1619 | };
|
1620 | const isMemberInElement = (elm, memberName) => memberName in elm;
|
1621 | const consoleError = (e, el) => (0, console.error)(e, el);
|
1622 | const cmpModules = new Map();
|
1623 | const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
1624 |
|
1625 | const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
|
1626 | const bundleId = cmpMeta.$lazyBundleId$;
|
1627 | const module = cmpModules.get(bundleId) ;
|
1628 | if (module) {
|
1629 | return module[exportName];
|
1630 | }
|
1631 | return import(
|
1632 |
|
1633 |
|
1634 |
|
1635 | `./${bundleId}.entry.js${''}`).then((importedModule) => {
|
1636 | {
|
1637 | cmpModules.set(bundleId, importedModule);
|
1638 | }
|
1639 | return importedModule[exportName];
|
1640 | }, consoleError);
|
1641 | };
|
1642 | const styles = new Map();
|
1643 | const queueDomReads = [];
|
1644 | const queueDomWrites = [];
|
1645 | const queueTask = (queue, write) => (cb) => {
|
1646 | queue.push(cb);
|
1647 | if (!queuePending) {
|
1648 | queuePending = true;
|
1649 | if (write && plt.$flags$ & 4 ) {
|
1650 | nextTick(flush);
|
1651 | }
|
1652 | else {
|
1653 | plt.raf(flush);
|
1654 | }
|
1655 | }
|
1656 | };
|
1657 | const consume = (queue) => {
|
1658 | for (let i = 0; i < queue.length; i++) {
|
1659 | try {
|
1660 | queue[i](performance.now());
|
1661 | }
|
1662 | catch (e) {
|
1663 | consoleError(e);
|
1664 | }
|
1665 | }
|
1666 | queue.length = 0;
|
1667 | };
|
1668 | const flush = () => {
|
1669 |
|
1670 |
|
1671 |
|
1672 | consume(queueDomReads);
|
1673 |
|
1674 | {
|
1675 | consume(queueDomWrites);
|
1676 | if ((queuePending = queueDomReads.length > 0)) {
|
1677 |
|
1678 |
|
1679 | plt.raf(flush);
|
1680 | }
|
1681 | }
|
1682 | };
|
1683 | const nextTick = (cb) => promiseResolve().then(cb);
|
1684 | const writeTask = queueTask(queueDomWrites, true);
|
1685 |
|
1686 | export { Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };
|