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