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