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