UNPKG

96.4 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 };
8 return function (d, b) {
9 extendStatics(d, b);
10 function __() { this.constructor = d; }
11 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12 };
13})();
14var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16 return new (P || (P = Promise))(function (resolve, reject) {
17 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20 step((generator = generator.apply(thisArg, _arguments || [])).next());
21 });
22};
23var __generator = (this && this.__generator) || function (thisArg, body) {
24 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26 function verb(n) { return function (v) { return step([n, v]); }; }
27 function step(op) {
28 if (f) throw new TypeError("Generator is already executing.");
29 while (_) try {
30 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31 if (y = 0, t) op = [op[0] & 2, t.value];
32 switch (op[0]) {
33 case 0: case 1: t = op; break;
34 case 4: _.label++; return { value: op[1], done: false };
35 case 5: _.label++; y = op[1]; op = [0]; continue;
36 case 7: op = _.ops.pop(); _.trys.pop(); continue;
37 default:
38 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42 if (t[2]) _.ops.pop();
43 _.trys.pop(); continue;
44 }
45 op = body.call(thisArg, _);
46 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48 }
49};
50var __spreadArrays = (this && this.__spreadArrays) || function () {
51 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
52 for (var r = Array(s), k = 0, i = 0; i < il; i++)
53 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
54 r[k] = a[j];
55 return r;
56};
57var NAMESPACE = 'calcite';
58var scopeId;
59var contentRef;
60var hostTagName;
61var useNativeShadowDom = false;
62var checkSlotFallbackVisibility = false;
63var checkSlotRelocate = false;
64var isSvgMode = false;
65var queueCongestion = 0;
66var queuePending = false;
67var win = typeof window !== 'undefined' ? window : {};
68var CSS = win.CSS;
69var doc = win.document || { head: {} };
70var plt = {
71 $flags$: 0,
72 $resourcesUrl$: '',
73 jmp: function (h) { return h(); },
74 raf: function (h) { return requestAnimationFrame(h); },
75 ael: function (el, eventName, listener, opts) { return el.addEventListener(eventName, listener, opts); },
76 rel: function (el, eventName, listener, opts) { return el.removeEventListener(eventName, listener, opts); },
77};
78var supportsShadow = /*@__PURE__*/ (function () { return (doc.head.attachShadow + '').indexOf('[native') > -1; })();
79var promiseResolve = function (v) { return Promise.resolve(v); };
80var supportsConstructibleStylesheets = /*@__PURE__*/ (function () {
81 try {
82 new CSSStyleSheet();
83 return true;
84 }
85 catch (e) { }
86 return false;
87})();
88var addHostEventListeners = function (elm, hostRef, listeners, attachParentListeners) {
89 if (listeners) {
90 // this is called immediately within the element's constructor
91 // initialize our event listeners on the host element
92 // we do this now so that we can listen to events that may
93 // have fired even before the instance is ready
94 {
95 // this component may have event listeners that should be attached to the parent
96 if (attachParentListeners) {
97 // this is being ran from within the connectedCallback
98 // which is important so that we know the host element actually has a parent element
99 // filter out the listeners to only have the ones that ARE being attached to the parent
100 listeners = listeners.filter(function (_a) {
101 var flags = _a[0];
102 return flags & 16;
103 } /* TargetParent */);
104 }
105 else {
106 // this is being ran from within the component constructor
107 // everything BUT the parent element listeners should be attached at this time
108 // filter out the listeners that are NOT being attached to the parent
109 listeners = listeners.filter(function (_a) {
110 var flags = _a[0];
111 return !(flags & 16 /* TargetParent */);
112 });
113 }
114 }
115 listeners.map(function (_a) {
116 var flags = _a[0], name = _a[1], method = _a[2];
117 var target = getHostListenerTarget(elm, flags);
118 var handler = hostListenerProxy(hostRef, method);
119 var opts = hostListenerOpts(flags);
120 plt.ael(target, name, handler, opts);
121 (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(function () { return plt.rel(target, name, handler, opts); });
122 });
123 }
124};
125var hostListenerProxy = function (hostRef, methodName) { return function (ev) {
126 {
127 if (hostRef.$flags$ & 256 /* isListenReady */) {
128 // instance is ready, let's call it's member method for this event
129 hostRef.$lazyInstance$[methodName](ev);
130 }
131 else {
132 (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
133 }
134 }
135}; };
136var getHostListenerTarget = function (elm, flags) {
137 if (flags & 8 /* TargetWindow */)
138 return win;
139 if (flags & 32 /* TargetBody */)
140 return doc.body;
141 if (flags & 16 /* TargetParent */)
142 return elm.parentElement;
143 return elm;
144};
145// prettier-ignore
146var hostListenerOpts = function (flags) { return (flags & 2 /* Capture */) !== 0; };
147var CONTENT_REF_ID = 'r';
148var ORG_LOCATION_ID = 'o';
149var SLOT_NODE_ID = 's';
150var TEXT_NODE_ID = 't';
151var HYDRATE_ID = 's-id';
152var HYDRATED_STYLE_ID = 'sty-id';
153var HYDRATE_CHILD_ID = 'c-id';
154var HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
155var XLINK_NS = 'http://www.w3.org/1999/xlink';
156var createTime = function (fnName, tagName) {
157 if (tagName === void 0) { tagName = ''; }
158 {
159 return function () {
160 return;
161 };
162 }
163};
164var uniqueTime = function (key, measureText) {
165 {
166 return function () {
167 return;
168 };
169 }
170};
171var rootAppliedStyles = new WeakMap();
172var registerStyle = function (scopeId, cssText, allowCS) {
173 var style = styles.get(scopeId);
174 if (supportsConstructibleStylesheets && allowCS) {
175 style = (style || new CSSStyleSheet());
176 style.replace(cssText);
177 }
178 else {
179 style = cssText;
180 }
181 styles.set(scopeId, style);
182};
183var addStyle = function (styleContainerNode, cmpMeta, mode, hostElm) {
184 var scopeId = getScopeId(cmpMeta.$tagName$);
185 var style = styles.get(scopeId);
186 // if an element is NOT connected then getRootNode() will return the wrong root node
187 // so the fallback is to always use the document for the root node in those cases
188 styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
189 if (style) {
190 if (typeof style === 'string') {
191 styleContainerNode = styleContainerNode.head || styleContainerNode;
192 var appliedStyles = rootAppliedStyles.get(styleContainerNode);
193 var styleElm = void 0;
194 if (!appliedStyles) {
195 rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
196 }
197 if (!appliedStyles.has(scopeId)) {
198 if (styleContainerNode.host && (styleElm = styleContainerNode.querySelector("[" + HYDRATED_STYLE_ID + "=\"" + scopeId + "\"]"))) {
199 // This is only happening on native shadow-dom, do not needs CSS var shim
200 styleElm.innerHTML = style;
201 }
202 else {
203 if (plt.$cssShim$) {
204 styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
205 var newScopeId = styleElm['s-sc'];
206 if (newScopeId) {
207 scopeId = newScopeId;
208 // we don't want to add this styleID to the appliedStyles Set
209 // since the cssVarShim might need to apply several different
210 // stylesheets for the same component
211 appliedStyles = null;
212 }
213 }
214 else {
215 styleElm = doc.createElement('style');
216 styleElm.innerHTML = style;
217 }
218 styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
219 }
220 if (appliedStyles) {
221 appliedStyles.add(scopeId);
222 }
223 }
224 }
225 else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
226 styleContainerNode.adoptedStyleSheets = __spreadArrays(styleContainerNode.adoptedStyleSheets, [style]);
227 }
228 }
229 return scopeId;
230};
231var attachStyles = function (hostRef) {
232 var cmpMeta = hostRef.$cmpMeta$;
233 var elm = hostRef.$hostElement$;
234 var flags = cmpMeta.$flags$;
235 var endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
236 var scopeId = addStyle(supportsShadow && elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
237 if (flags & 10 /* needsScopedEncapsulation */) {
238 // only required when we're NOT using native shadow dom (slot)
239 // or this browser doesn't support native shadow dom
240 // and this host element was NOT created with SSR
241 // let's pick out the inner content for slot projection
242 // create a node to represent where the original
243 // content was first placed, which is useful later on
244 // DOM WRITE!!
245 elm['s-sc'] = scopeId;
246 elm.classList.add(scopeId + '-h');
247 }
248 endAttachStyles();
249};
250var getScopeId = function (tagName, mode) { return 'sc-' + (tagName); };
251var convertScopedToShadow = function (css) { return css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{'); };
252/**
253 * Default style mode id
254 */
255/**
256 * Reusable empty obj/array
257 * Don't add values to these!!
258 */
259var EMPTY_OBJ = {};
260/**
261 * Namespaces
262 */
263var SVG_NS = 'http://www.w3.org/2000/svg';
264var HTML_NS = 'http://www.w3.org/1999/xhtml';
265var isDef = function (v) { return v != null; };
266var isComplexType = function (o) {
267 // https://jsperf.com/typeof-fn-object/5
268 o = typeof o;
269 return o === 'object' || o === 'function';
270};
271var getDynamicImportFunction = function (namespace) { return "__sc_import_" + namespace.replace(/\s|-/g, '_'); };
272/**
273 * Production h() function based on Preact by
274 * Jason Miller (@developit)
275 * Licensed under the MIT License
276 * https://github.com/developit/preact/blob/master/LICENSE
277 *
278 * Modified for Stencil's compiler and vdom
279 */
280// const stack: any[] = [];
281// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
282// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
283var h = function (nodeName, vnodeData) {
284 var children = [];
285 for (var _i = 2; _i < arguments.length; _i++) {
286 children[_i - 2] = arguments[_i];
287 }
288 var child = null;
289 var key = null;
290 var slotName = null;
291 var simple = false;
292 var lastSimple = false;
293 var vNodeChildren = [];
294 var walk = function (c) {
295 for (var i = 0; i < c.length; i++) {
296 child = c[i];
297 if (Array.isArray(child)) {
298 walk(child);
299 }
300 else if (child != null && typeof child !== 'boolean') {
301 if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
302 child = String(child);
303 }
304 if (simple && lastSimple) {
305 // If the previous child was simple (string), we merge both
306 vNodeChildren[vNodeChildren.length - 1].$text$ += child;
307 }
308 else {
309 // Append a new vNode, if it's text, we create a text vNode
310 vNodeChildren.push(simple ? newVNode(null, child) : child);
311 }
312 lastSimple = simple;
313 }
314 }
315 };
316 walk(children);
317 if (vnodeData) {
318 // normalize class / classname attributes
319 if (vnodeData.key) {
320 key = vnodeData.key;
321 }
322 if (vnodeData.name) {
323 slotName = vnodeData.name;
324 }
325 {
326 var classData_1 = vnodeData.className || vnodeData.class;
327 if (classData_1) {
328 vnodeData.class =
329 typeof classData_1 !== 'object'
330 ? classData_1
331 : Object.keys(classData_1)
332 .filter(function (k) { return classData_1[k]; })
333 .join(' ');
334 }
335 }
336 }
337 if (typeof nodeName === 'function') {
338 // nodeName is a functional component
339 return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
340 }
341 var vnode = newVNode(nodeName, null);
342 vnode.$attrs$ = vnodeData;
343 if (vNodeChildren.length > 0) {
344 vnode.$children$ = vNodeChildren;
345 }
346 {
347 vnode.$key$ = key;
348 }
349 {
350 vnode.$name$ = slotName;
351 }
352 return vnode;
353};
354var newVNode = function (tag, text) {
355 var vnode = {
356 $flags$: 0,
357 $tag$: tag,
358 $text$: text,
359 $elm$: null,
360 $children$: null,
361 };
362 {
363 vnode.$attrs$ = null;
364 }
365 {
366 vnode.$key$ = null;
367 }
368 {
369 vnode.$name$ = null;
370 }
371 return vnode;
372};
373var Host = {};
374var isHost = function (node) { return node && node.$tag$ === Host; };
375var vdomFnUtils = {
376 forEach: function (children, cb) { return children.map(convertToPublic).forEach(cb); },
377 map: function (children, cb) { return children
378 .map(convertToPublic)
379 .map(cb)
380 .map(convertToPrivate); },
381};
382var convertToPublic = function (node) { return ({
383 vattrs: node.$attrs$,
384 vchildren: node.$children$,
385 vkey: node.$key$,
386 vname: node.$name$,
387 vtag: node.$tag$,
388 vtext: node.$text$,
389}); };
390var convertToPrivate = function (node) {
391 var vnode = newVNode(node.vtag, node.vtext);
392 vnode.$attrs$ = node.vattrs;
393 vnode.$children$ = node.vchildren;
394 vnode.$key$ = node.vkey;
395 vnode.$name$ = node.vname;
396 return vnode;
397};
398/**
399 * Production setAccessor() function based on Preact by
400 * Jason Miller (@developit)
401 * Licensed under the MIT License
402 * https://github.com/developit/preact/blob/master/LICENSE
403 *
404 * Modified for Stencil's compiler and vdom
405 */
406var setAccessor = function (elm, memberName, oldValue, newValue, isSvg, flags) {
407 if (oldValue !== newValue) {
408 var isProp = isMemberInElement(elm, memberName);
409 var ln = memberName.toLowerCase();
410 if (memberName === 'class') {
411 var classList = elm.classList;
412 var oldClasses_1 = parseClassList(oldValue);
413 var newClasses_1 = parseClassList(newValue);
414 classList.remove.apply(classList, oldClasses_1.filter(function (c) { return c && !newClasses_1.includes(c); }));
415 classList.add.apply(classList, newClasses_1.filter(function (c) { return c && !oldClasses_1.includes(c); }));
416 }
417 else if (memberName === 'style') {
418 // update style attribute, css properties and values
419 {
420 for (var prop in oldValue) {
421 if (!newValue || newValue[prop] == null) {
422 if (prop.includes('-')) {
423 elm.style.removeProperty(prop);
424 }
425 else {
426 elm.style[prop] = '';
427 }
428 }
429 }
430 }
431 for (var prop in newValue) {
432 if (!oldValue || newValue[prop] !== oldValue[prop]) {
433 if (prop.includes('-')) {
434 elm.style.setProperty(prop, newValue[prop]);
435 }
436 else {
437 elm.style[prop] = newValue[prop];
438 }
439 }
440 }
441 }
442 else if (memberName === 'key')
443 ;
444 else if (memberName === 'ref') {
445 // minifier will clean this up
446 if (newValue) {
447 newValue(elm);
448 }
449 }
450 else if ((!isProp) && memberName[0] === 'o' && memberName[1] === 'n') {
451 // Event Handlers
452 // so if the member name starts with "on" and the 3rd characters is
453 // a capital letter, and it's not already a member on the element,
454 // then we're assuming it's an event listener
455 if (memberName[2] === '-') {
456 // on- prefixed events
457 // allows to be explicit about the dom event to listen without any magic
458 // under the hood:
459 // <my-cmp on-click> // listens for "click"
460 // <my-cmp on-Click> // listens for "Click"
461 // <my-cmp on-ionChange> // listens for "ionChange"
462 // <my-cmp on-EVENTS> // listens for "EVENTS"
463 memberName = memberName.slice(3);
464 }
465 else if (isMemberInElement(win, ln)) {
466 // standard event
467 // the JSX attribute could have been "onMouseOver" and the
468 // member name "onmouseover" is on the window's prototype
469 // so let's add the listener "mouseover", which is all lowercased
470 memberName = ln.slice(2);
471 }
472 else {
473 // custom event
474 // the JSX attribute could have been "onMyCustomEvent"
475 // so let's trim off the "on" prefix and lowercase the first character
476 // and add the listener "myCustomEvent"
477 // except for the first character, we keep the event name case
478 memberName = ln[2] + memberName.slice(3);
479 }
480 if (oldValue) {
481 plt.rel(elm, memberName, oldValue, false);
482 }
483 if (newValue) {
484 plt.ael(elm, memberName, newValue, false);
485 }
486 }
487 else {
488 // Set property if it exists and it's not a SVG
489 var isComplex = isComplexType(newValue);
490 if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
491 try {
492 if (!elm.tagName.includes('-')) {
493 var n = newValue == null ? '' : newValue;
494 // Workaround for Safari, moving the <input> caret when re-assigning the same valued
495 if (memberName === 'list') {
496 isProp = false;
497 // tslint:disable-next-line: triple-equals
498 }
499 else if (oldValue == null || elm[memberName] != n) {
500 elm[memberName] = n;
501 }
502 }
503 else {
504 elm[memberName] = newValue;
505 }
506 }
507 catch (e) { }
508 }
509 /**
510 * Need to manually update attribute if:
511 * - memberName is not an attribute
512 * - if we are rendering the host element in order to reflect attribute
513 * - if it's a SVG, since properties might not work in <svg>
514 * - if the newValue is null/undefined or 'false'.
515 */
516 var xlink = false;
517 {
518 if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
519 memberName = ln;
520 xlink = true;
521 }
522 }
523 if (newValue == null || newValue === false) {
524 if (xlink) {
525 elm.removeAttributeNS(XLINK_NS, memberName);
526 }
527 else {
528 elm.removeAttribute(memberName);
529 }
530 }
531 else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
532 newValue = newValue === true ? '' : newValue;
533 if (xlink) {
534 elm.setAttributeNS(XLINK_NS, memberName, newValue);
535 }
536 else {
537 elm.setAttribute(memberName, newValue);
538 }
539 }
540 }
541 }
542};
543var parseClassListRegex = /\s/;
544var parseClassList = function (value) { return (!value ? [] : value.split(parseClassListRegex)); };
545var updateElement = function (oldVnode, newVnode, isSvgMode, memberName) {
546 // if the element passed in is a shadow root, which is a document fragment
547 // then we want to be adding attrs/props to the shadow root's "host" element
548 // if it's not a shadow root, then we add attrs/props to the same element
549 var elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
550 var oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
551 var newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
552 {
553 // remove attributes no longer present on the vnode by setting them to undefined
554 for (memberName in oldVnodeAttrs) {
555 if (!(memberName in newVnodeAttrs)) {
556 setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
557 }
558 }
559 }
560 // add new & update changed attributes
561 for (memberName in newVnodeAttrs) {
562 setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
563 }
564};
565var createElm = function (oldParentVNode, newParentVNode, childIndex, parentElm) {
566 // tslint:disable-next-line: prefer-const
567 var newVNode = newParentVNode.$children$[childIndex];
568 var i = 0;
569 var elm;
570 var childNode;
571 var oldVNode;
572 if (!useNativeShadowDom) {
573 // remember for later we need to check to relocate nodes
574 checkSlotRelocate = true;
575 if (newVNode.$tag$ === 'slot') {
576 if (scopeId) {
577 // scoped css needs to add its scoped id to the parent element
578 parentElm.classList.add(scopeId + '-s');
579 }
580 newVNode.$flags$ |= newVNode.$children$
581 ? // slot element has fallback content
582 2 /* isSlotFallback */
583 : // slot element does not have fallback content
584 1 /* isSlotReference */;
585 }
586 }
587 if (newVNode.$text$ !== null) {
588 // create text node
589 elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
590 }
591 else if (newVNode.$flags$ & 1 /* isSlotReference */) {
592 // create a slot reference node
593 elm = newVNode.$elm$ = doc.createTextNode('');
594 }
595 else {
596 if (!isSvgMode) {
597 isSvgMode = newVNode.$tag$ === 'svg';
598 }
599 // create element
600 elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$));
601 if (isSvgMode && newVNode.$tag$ === 'foreignObject') {
602 isSvgMode = false;
603 }
604 // add css classes, attrs, props, listeners, etc.
605 {
606 updateElement(null, newVNode, isSvgMode);
607 }
608 if (isDef(scopeId) && elm['s-si'] !== scopeId) {
609 // if there is a scopeId and this is the initial render
610 // then let's add the scopeId as a css class
611 elm.classList.add((elm['s-si'] = scopeId));
612 }
613 if (newVNode.$children$) {
614 for (i = 0; i < newVNode.$children$.length; ++i) {
615 // create the node
616 childNode = createElm(oldParentVNode, newVNode, i, elm);
617 // return node could have been null
618 if (childNode) {
619 // append our new node
620 elm.appendChild(childNode);
621 }
622 }
623 }
624 {
625 if (newVNode.$tag$ === 'svg') {
626 // Only reset the SVG context when we're exiting <svg> element
627 isSvgMode = false;
628 }
629 else if (elm.tagName === 'foreignObject') {
630 // Reenter SVG context when we're exiting <foreignObject> element
631 isSvgMode = true;
632 }
633 }
634 }
635 {
636 elm['s-hn'] = hostTagName;
637 if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
638 // remember the content reference comment
639 elm['s-sr'] = true;
640 // remember the content reference comment
641 elm['s-cr'] = contentRef;
642 // remember the slot name, or empty string for default slot
643 elm['s-sn'] = newVNode.$name$ || '';
644 // check if we've got an old vnode for this slot
645 oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
646 if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
647 // we've got an old slot vnode and the wrapper is being replaced
648 // so let's move the old slot content back to it's original location
649 putBackInOriginalLocation(oldParentVNode.$elm$, false);
650 }
651 }
652 }
653 return elm;
654};
655var putBackInOriginalLocation = function (parentElm, recursive) {
656 plt.$flags$ |= 1 /* isTmpDisconnected */;
657 var oldSlotChildNodes = parentElm.childNodes;
658 for (var i = oldSlotChildNodes.length - 1; i >= 0; i--) {
659 var childNode = oldSlotChildNodes[i];
660 if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
661 // // this child node in the old element is from another component
662 // // remove this node from the old slot's parent
663 // childNode.remove();
664 // and relocate it back to it's original location
665 parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
666 // remove the old original location comment entirely
667 // later on the patch function will know what to do
668 // and move this to the correct spot in need be
669 childNode['s-ol'].remove();
670 childNode['s-ol'] = undefined;
671 checkSlotRelocate = true;
672 }
673 if (recursive) {
674 putBackInOriginalLocation(childNode, recursive);
675 }
676 }
677 plt.$flags$ &= ~1 /* isTmpDisconnected */;
678};
679var addVnodes = function (parentElm, before, parentVNode, vnodes, startIdx, endIdx) {
680 var containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
681 var childNode;
682 if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
683 containerElm = containerElm.shadowRoot;
684 }
685 for (; startIdx <= endIdx; ++startIdx) {
686 if (vnodes[startIdx]) {
687 childNode = createElm(null, parentVNode, startIdx, parentElm);
688 if (childNode) {
689 vnodes[startIdx].$elm$ = childNode;
690 containerElm.insertBefore(childNode, referenceNode(before));
691 }
692 }
693 }
694};
695var removeVnodes = function (vnodes, startIdx, endIdx, vnode, elm) {
696 for (; startIdx <= endIdx; ++startIdx) {
697 if ((vnode = vnodes[startIdx])) {
698 elm = vnode.$elm$;
699 callNodeRefs(vnode);
700 {
701 // we're removing this element
702 // so it's possible we need to show slot fallback content now
703 checkSlotFallbackVisibility = true;
704 if (elm['s-ol']) {
705 // remove the original location comment
706 elm['s-ol'].remove();
707 }
708 else {
709 // it's possible that child nodes of the node
710 // that's being removed are slot nodes
711 putBackInOriginalLocation(elm, true);
712 }
713 }
714 // remove the vnode's element from the dom
715 elm.remove();
716 }
717 }
718};
719var updateChildren = function (parentElm, oldCh, newVNode, newCh) {
720 var oldStartIdx = 0;
721 var newStartIdx = 0;
722 var idxInOld = 0;
723 var i = 0;
724 var oldEndIdx = oldCh.length - 1;
725 var oldStartVnode = oldCh[0];
726 var oldEndVnode = oldCh[oldEndIdx];
727 var newEndIdx = newCh.length - 1;
728 var newStartVnode = newCh[0];
729 var newEndVnode = newCh[newEndIdx];
730 var node;
731 var elmToMove;
732 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
733 if (oldStartVnode == null) {
734 // Vnode might have been moved left
735 oldStartVnode = oldCh[++oldStartIdx];
736 }
737 else if (oldEndVnode == null) {
738 oldEndVnode = oldCh[--oldEndIdx];
739 }
740 else if (newStartVnode == null) {
741 newStartVnode = newCh[++newStartIdx];
742 }
743 else if (newEndVnode == null) {
744 newEndVnode = newCh[--newEndIdx];
745 }
746 else if (isSameVnode(oldStartVnode, newStartVnode)) {
747 patch(oldStartVnode, newStartVnode);
748 oldStartVnode = oldCh[++oldStartIdx];
749 newStartVnode = newCh[++newStartIdx];
750 }
751 else if (isSameVnode(oldEndVnode, newEndVnode)) {
752 patch(oldEndVnode, newEndVnode);
753 oldEndVnode = oldCh[--oldEndIdx];
754 newEndVnode = newCh[--newEndIdx];
755 }
756 else if (isSameVnode(oldStartVnode, newEndVnode)) {
757 // Vnode moved right
758 if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
759 putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
760 }
761 patch(oldStartVnode, newEndVnode);
762 parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
763 oldStartVnode = oldCh[++oldStartIdx];
764 newEndVnode = newCh[--newEndIdx];
765 }
766 else if (isSameVnode(oldEndVnode, newStartVnode)) {
767 // Vnode moved left
768 if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
769 putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
770 }
771 patch(oldEndVnode, newStartVnode);
772 parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
773 oldEndVnode = oldCh[--oldEndIdx];
774 newStartVnode = newCh[++newStartIdx];
775 }
776 else {
777 // createKeyToOldIdx
778 idxInOld = -1;
779 {
780 for (i = oldStartIdx; i <= oldEndIdx; ++i) {
781 if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
782 idxInOld = i;
783 break;
784 }
785 }
786 }
787 if (idxInOld >= 0) {
788 elmToMove = oldCh[idxInOld];
789 if (elmToMove.$tag$ !== newStartVnode.$tag$) {
790 node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
791 }
792 else {
793 patch(elmToMove, newStartVnode);
794 oldCh[idxInOld] = undefined;
795 node = elmToMove.$elm$;
796 }
797 newStartVnode = newCh[++newStartIdx];
798 }
799 else {
800 // new element
801 node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
802 newStartVnode = newCh[++newStartIdx];
803 }
804 if (node) {
805 {
806 parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
807 }
808 }
809 }
810 }
811 if (oldStartIdx > oldEndIdx) {
812 addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
813 }
814 else if (newStartIdx > newEndIdx) {
815 removeVnodes(oldCh, oldStartIdx, oldEndIdx);
816 }
817};
818var isSameVnode = function (vnode1, vnode2) {
819 // compare if two vnode to see if they're "technically" the same
820 // need to have the same element tag, and same key to be the same
821 if (vnode1.$tag$ === vnode2.$tag$) {
822 if (vnode1.$tag$ === 'slot') {
823 return vnode1.$name$ === vnode2.$name$;
824 }
825 {
826 return vnode1.$key$ === vnode2.$key$;
827 }
828 }
829 return false;
830};
831var referenceNode = function (node) {
832 // this node was relocated to a new location in the dom
833 // because of some other component's slot
834 // but we still have an html comment in place of where
835 // it's original location was according to it's original vdom
836 return (node && node['s-ol']) || node;
837};
838var parentReferenceNode = function (node) { return (node['s-ol'] ? node['s-ol'] : node).parentNode; };
839var patch = function (oldVNode, newVNode) {
840 var elm = (newVNode.$elm$ = oldVNode.$elm$);
841 var oldChildren = oldVNode.$children$;
842 var newChildren = newVNode.$children$;
843 var tag = newVNode.$tag$;
844 var text = newVNode.$text$;
845 var defaultHolder;
846 if (text === null) {
847 {
848 // test if we're rendering an svg element, or still rendering nodes inside of one
849 // only add this to the when the compiler sees we're using an svg somewhere
850 isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
851 }
852 // element node
853 {
854 if (tag === 'slot')
855 ;
856 else {
857 // either this is the first render of an element OR it's an update
858 // AND we already know it's possible it could have changed
859 // this updates the element's css classes, attrs, props, listeners, etc.
860 updateElement(oldVNode, newVNode, isSvgMode);
861 }
862 }
863 if (oldChildren !== null && newChildren !== null) {
864 // looks like there's child vnodes for both the old and new vnodes
865 updateChildren(elm, oldChildren, newVNode, newChildren);
866 }
867 else if (newChildren !== null) {
868 // no old child vnodes, but there are new child vnodes to add
869 if (oldVNode.$text$ !== null) {
870 // the old vnode was text, so be sure to clear it out
871 elm.textContent = '';
872 }
873 // add the new vnode children
874 addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
875 }
876 else if (oldChildren !== null) {
877 // no new child vnodes, but there are old child vnodes to remove
878 removeVnodes(oldChildren, 0, oldChildren.length - 1);
879 }
880 if (isSvgMode && tag === 'svg') {
881 isSvgMode = false;
882 }
883 }
884 else if ((defaultHolder = elm['s-cr'])) {
885 // this element has slotted content
886 defaultHolder.parentNode.textContent = text;
887 }
888 else if (oldVNode.$text$ !== text) {
889 // update the text content for the text only vnode
890 // and also only if the text is different than before
891 elm.data = text;
892 }
893};
894var updateFallbackSlotVisibility = function (elm) {
895 // tslint:disable-next-line: prefer-const
896 var childNodes = elm.childNodes;
897 var childNode;
898 var i;
899 var ilen;
900 var j;
901 var slotNameAttr;
902 var nodeType;
903 for (i = 0, ilen = childNodes.length; i < ilen; i++) {
904 childNode = childNodes[i];
905 if (childNode.nodeType === 1 /* ElementNode */) {
906 if (childNode['s-sr']) {
907 // this is a slot fallback node
908 // get the slot name for this slot reference node
909 slotNameAttr = childNode['s-sn'];
910 // by default always show a fallback slot node
911 // then hide it if there are other slots in the light dom
912 childNode.hidden = false;
913 for (j = 0; j < ilen; j++) {
914 if (childNodes[j]['s-hn'] !== childNode['s-hn']) {
915 // this sibling node is from a different component
916 nodeType = childNodes[j].nodeType;
917 if (slotNameAttr !== '') {
918 // this is a named fallback slot node
919 if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
920 childNode.hidden = true;
921 break;
922 }
923 }
924 else {
925 // this is a default fallback slot node
926 // any element or text node (with content)
927 // should hide the default fallback slot node
928 if (nodeType === 1 /* ElementNode */ || (nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
929 childNode.hidden = true;
930 break;
931 }
932 }
933 }
934 }
935 }
936 // keep drilling down
937 updateFallbackSlotVisibility(childNode);
938 }
939 }
940};
941var relocateNodes = [];
942var relocateSlotContent = function (elm) {
943 // tslint:disable-next-line: prefer-const
944 var childNode;
945 var node;
946 var hostContentNodes;
947 var slotNameAttr;
948 var relocateNodeData;
949 var j;
950 var i = 0;
951 var childNodes = elm.childNodes;
952 var ilen = childNodes.length;
953 for (; i < ilen; i++) {
954 childNode = childNodes[i];
955 if (childNode['s-sr'] && (node = childNode['s-cr'])) {
956 // first got the content reference comment node
957 // then we got it's parent, which is where all the host content is in now
958 hostContentNodes = node.parentNode.childNodes;
959 slotNameAttr = childNode['s-sn'];
960 for (j = hostContentNodes.length - 1; j >= 0; j--) {
961 node = hostContentNodes[j];
962 if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
963 // let's do some relocating to its new home
964 // but never relocate a content reference node
965 // that is suppose to always represent the original content location
966 if (isNodeLocatedInSlot(node, slotNameAttr)) {
967 // it's possible we've already decided to relocate this node
968 relocateNodeData = relocateNodes.find(function (r) { return r.$nodeToRelocate$ === node; });
969 // made some changes to slots
970 // let's make sure we also double check
971 // fallbacks are correctly hidden or shown
972 checkSlotFallbackVisibility = true;
973 node['s-sn'] = node['s-sn'] || slotNameAttr;
974 if (relocateNodeData) {
975 // previously we never found a slot home for this node
976 // but turns out we did, so let's remember it now
977 relocateNodeData.$slotRefNode$ = childNode;
978 }
979 else {
980 // add to our list of nodes to relocate
981 relocateNodes.push({
982 $slotRefNode$: childNode,
983 $nodeToRelocate$: node,
984 });
985 }
986 if (node['s-sr']) {
987 relocateNodes.map(function (relocateNode) {
988 if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
989 relocateNodeData = relocateNodes.find(function (r) { return r.$nodeToRelocate$ === node; });
990 if (relocateNodeData && !relocateNode.$slotRefNode$) {
991 relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
992 }
993 }
994 });
995 }
996 }
997 else if (!relocateNodes.some(function (r) { return r.$nodeToRelocate$ === node; })) {
998 // so far this element does not have a slot home, not setting slotRefNode on purpose
999 // if we never find a home for this element then we'll need to hide it
1000 relocateNodes.push({
1001 $nodeToRelocate$: node,
1002 });
1003 }
1004 }
1005 }
1006 }
1007 if (childNode.nodeType === 1 /* ElementNode */) {
1008 relocateSlotContent(childNode);
1009 }
1010 }
1011};
1012var isNodeLocatedInSlot = function (nodeToRelocate, slotNameAttr) {
1013 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1014 if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1015 return true;
1016 }
1017 if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1018 return true;
1019 }
1020 return false;
1021 }
1022 if (nodeToRelocate['s-sn'] === slotNameAttr) {
1023 return true;
1024 }
1025 return slotNameAttr === '';
1026};
1027var callNodeRefs = function (vNode) {
1028 {
1029 vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1030 vNode.$children$ && vNode.$children$.map(callNodeRefs);
1031 }
1032};
1033var renderVdom = function (hostRef, renderFnResults) {
1034 var hostElm = hostRef.$hostElement$;
1035 var cmpMeta = hostRef.$cmpMeta$;
1036 var oldVNode = hostRef.$vnode$ || newVNode(null, null);
1037 var rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1038 hostTagName = hostElm.tagName;
1039 if (cmpMeta.$attrsToReflect$) {
1040 rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1041 cmpMeta.$attrsToReflect$.map(function (_a) {
1042 var propName = _a[0], attribute = _a[1];
1043 return (rootVnode.$attrs$[attribute] = hostElm[propName]);
1044 });
1045 }
1046 rootVnode.$tag$ = null;
1047 rootVnode.$flags$ |= 4 /* isHost */;
1048 hostRef.$vnode$ = rootVnode;
1049 rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm);
1050 {
1051 scopeId = hostElm['s-sc'];
1052 }
1053 {
1054 contentRef = hostElm['s-cr'];
1055 useNativeShadowDom = supportsShadow && (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
1056 // always reset
1057 checkSlotFallbackVisibility = false;
1058 }
1059 // synchronous patch
1060 patch(oldVNode, rootVnode);
1061 {
1062 // while we're moving nodes around existing nodes, temporarily disable
1063 // the disconnectCallback from working
1064 plt.$flags$ |= 1 /* isTmpDisconnected */;
1065 if (checkSlotRelocate) {
1066 relocateSlotContent(rootVnode.$elm$);
1067 var relocateData = void 0;
1068 var nodeToRelocate = void 0;
1069 var orgLocationNode = void 0;
1070 var parentNodeRef = void 0;
1071 var insertBeforeNode = void 0;
1072 var refNode = void 0;
1073 var i = 0;
1074 for (; i < relocateNodes.length; i++) {
1075 relocateData = relocateNodes[i];
1076 nodeToRelocate = relocateData.$nodeToRelocate$;
1077 if (!nodeToRelocate['s-ol']) {
1078 // add a reference node marking this node's original location
1079 // keep a reference to this node for later lookups
1080 orgLocationNode = doc.createTextNode('');
1081 orgLocationNode['s-nr'] = nodeToRelocate;
1082 nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1083 }
1084 }
1085 for (i = 0; i < relocateNodes.length; i++) {
1086 relocateData = relocateNodes[i];
1087 nodeToRelocate = relocateData.$nodeToRelocate$;
1088 if (relocateData.$slotRefNode$) {
1089 // by default we're just going to insert it directly
1090 // after the slot reference node
1091 parentNodeRef = relocateData.$slotRefNode$.parentNode;
1092 insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1093 orgLocationNode = nodeToRelocate['s-ol'];
1094 while ((orgLocationNode = orgLocationNode.previousSibling)) {
1095 refNode = orgLocationNode['s-nr'];
1096 if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1097 refNode = refNode.nextSibling;
1098 if (!refNode || !refNode['s-nr']) {
1099 insertBeforeNode = refNode;
1100 break;
1101 }
1102 }
1103 }
1104 if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) || nodeToRelocate.nextSibling !== insertBeforeNode) {
1105 // we've checked that it's worth while to relocate
1106 // since that the node to relocate
1107 // has a different next sibling or parent relocated
1108 if (nodeToRelocate !== insertBeforeNode) {
1109 if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1110 // probably a component in the index.html that doesn't have it's hostname set
1111 nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1112 }
1113 // add it back to the dom but in its new home
1114 parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1115 }
1116 }
1117 }
1118 else {
1119 // this node doesn't have a slot home to go to, so let's hide it
1120 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1121 nodeToRelocate.hidden = true;
1122 }
1123 }
1124 }
1125 }
1126 if (checkSlotFallbackVisibility) {
1127 updateFallbackSlotVisibility(rootVnode.$elm$);
1128 }
1129 // done moving nodes around
1130 // allow the disconnect callback to work again
1131 plt.$flags$ &= ~1 /* isTmpDisconnected */;
1132 // always reset
1133 relocateNodes.length = 0;
1134 }
1135};
1136var getElement = function (ref) { return (getHostRef(ref).$hostElement$); };
1137var createEvent = function (ref, name, flags) {
1138 var elm = getElement(ref);
1139 return {
1140 emit: function (detail) {
1141 return emitEvent(elm, name, {
1142 bubbles: !!(flags & 4 /* Bubbles */),
1143 composed: !!(flags & 2 /* Composed */),
1144 cancelable: !!(flags & 1 /* Cancellable */),
1145 detail: detail,
1146 });
1147 },
1148 };
1149};
1150var emitEvent = function (elm, name, opts) {
1151 var ev = new (CustomEvent)(name, opts);
1152 elm.dispatchEvent(ev);
1153 return ev;
1154};
1155var attachToAncestor = function (hostRef, ancestorComponent) {
1156 if (ancestorComponent && !hostRef.$onRenderResolve$) {
1157 ancestorComponent['s-p'].push(new Promise(function (r) { return (hostRef.$onRenderResolve$ = r); }));
1158 }
1159};
1160var scheduleUpdate = function (hostRef, isInitialLoad) {
1161 {
1162 hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
1163 }
1164 if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
1165 hostRef.$flags$ |= 512 /* needsRerender */;
1166 return;
1167 }
1168 var endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1169 var ancestorComponent = hostRef.$ancestorComponent$;
1170 var instance = hostRef.$lazyInstance$;
1171 var update = function () { return updateComponent(hostRef, instance, isInitialLoad); };
1172 attachToAncestor(hostRef, ancestorComponent);
1173 var promise;
1174 if (isInitialLoad) {
1175 {
1176 hostRef.$flags$ |= 256 /* isListenReady */;
1177 if (hostRef.$queuedListeners$) {
1178 hostRef.$queuedListeners$.map(function (_a) {
1179 var methodName = _a[0], event = _a[1];
1180 return safeCall(instance, methodName, event);
1181 });
1182 hostRef.$queuedListeners$ = null;
1183 }
1184 }
1185 {
1186 promise = safeCall(instance, 'componentWillLoad');
1187 }
1188 }
1189 else {
1190 {
1191 promise = safeCall(instance, 'componentWillUpdate');
1192 }
1193 }
1194 {
1195 promise = then(promise, function () { return safeCall(instance, 'componentWillRender'); });
1196 }
1197 endSchedule();
1198 // there is no ancestorc omponent or the ancestor component
1199 // has already fired off its lifecycle update then
1200 // fire off the initial update
1201 return then(promise, function () { return writeTask(update); });
1202};
1203var updateComponent = function (hostRef, instance, isInitialLoad) {
1204 // updateComponent
1205 var elm = hostRef.$hostElement$;
1206 var endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1207 var rc = elm['s-rc'];
1208 if (isInitialLoad) {
1209 // DOM WRITE!
1210 attachStyles(hostRef);
1211 }
1212 var endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1213 {
1214 {
1215 // looks like we've got child nodes to render into this host element
1216 // or we need to update the css class/attrs on the host element
1217 // DOM WRITE!
1218 renderVdom(hostRef, callRender(instance));
1219 }
1220 }
1221 if (plt.$cssShim$) {
1222 plt.$cssShim$.updateHost(elm);
1223 }
1224 {
1225 hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
1226 }
1227 {
1228 hostRef.$flags$ |= 2 /* hasRendered */;
1229 }
1230 if (rc) {
1231 // ok, so turns out there are some child host elements
1232 // waiting on this parent element to load
1233 // let's fire off all update callbacks waiting
1234 rc.map(function (cb) { return cb(); });
1235 elm['s-rc'] = undefined;
1236 }
1237 endRender();
1238 endUpdate();
1239 {
1240 var childrenPromises = elm['s-p'];
1241 var postUpdate = function () { return postUpdateComponent(hostRef); };
1242 if (childrenPromises.length === 0) {
1243 postUpdate();
1244 }
1245 else {
1246 Promise.all(childrenPromises).then(postUpdate);
1247 hostRef.$flags$ |= 4 /* isWaitingForChildren */;
1248 childrenPromises.length = 0;
1249 }
1250 }
1251};
1252var callRender = function (instance) {
1253 try {
1254 instance = instance.render();
1255 }
1256 catch (e) {
1257 consoleError(e);
1258 }
1259 return instance;
1260};
1261var postUpdateComponent = function (hostRef) {
1262 var tagName = hostRef.$cmpMeta$.$tagName$;
1263 var elm = hostRef.$hostElement$;
1264 var endPostUpdate = createTime('postUpdate', tagName);
1265 var instance = hostRef.$lazyInstance$;
1266 var ancestorComponent = hostRef.$ancestorComponent$;
1267 {
1268 safeCall(instance, 'componentDidRender');
1269 }
1270 if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
1271 hostRef.$flags$ |= 64 /* hasLoadedComponent */;
1272 {
1273 // DOM WRITE!
1274 addHydratedFlag(elm);
1275 }
1276 {
1277 safeCall(instance, 'componentDidLoad');
1278 }
1279 endPostUpdate();
1280 {
1281 hostRef.$onReadyResolve$(elm);
1282 if (!ancestorComponent) {
1283 appDidLoad();
1284 }
1285 }
1286 }
1287 else {
1288 {
1289 safeCall(instance, 'componentDidUpdate');
1290 }
1291 endPostUpdate();
1292 }
1293 {
1294 hostRef.$onInstanceResolve$(elm);
1295 }
1296 // load events fire from bottom to top
1297 // the deepest elements load first then bubbles up
1298 {
1299 if (hostRef.$onRenderResolve$) {
1300 hostRef.$onRenderResolve$();
1301 hostRef.$onRenderResolve$ = undefined;
1302 }
1303 if (hostRef.$flags$ & 512 /* needsRerender */) {
1304 nextTick(function () { return scheduleUpdate(hostRef, false); });
1305 }
1306 hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
1307 }
1308 // ( •_•)
1309 // ( •_•)>⌐■-■
1310 // (⌐■_■)
1311};
1312var forceUpdate = function (ref) {
1313 {
1314 var hostRef = getHostRef(ref);
1315 var isConnected = hostRef.$hostElement$.isConnected;
1316 if (isConnected && (hostRef.$flags$ & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1317 scheduleUpdate(hostRef, false);
1318 }
1319 // Returns "true" when the forced update was successfully scheduled
1320 return isConnected;
1321 }
1322};
1323var appDidLoad = function (who) {
1324 // on appload
1325 // we have finish the first big initial render
1326 {
1327 addHydratedFlag(doc.documentElement);
1328 }
1329 {
1330 plt.$flags$ |= 2 /* appLoaded */;
1331 }
1332 nextTick(function () { return emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }); });
1333};
1334var safeCall = function (instance, method, arg) {
1335 if (instance && instance[method]) {
1336 try {
1337 return instance[method](arg);
1338 }
1339 catch (e) {
1340 consoleError(e);
1341 }
1342 }
1343 return undefined;
1344};
1345var then = function (promise, thenFn) {
1346 return promise && promise.then ? promise.then(thenFn) : thenFn();
1347};
1348var addHydratedFlag = function (elm) { return (elm.classList.add('hydrated')); };
1349var initializeClientHydrate = function (hostElm, tagName, hostId, hostRef) {
1350 var endHydrate = createTime('hydrateClient', tagName);
1351 var shadowRoot = hostElm.shadowRoot;
1352 var childRenderNodes = [];
1353 var slotNodes = [];
1354 var shadowRootNodes = shadowRoot ? [] : null;
1355 var vnode = (hostRef.$vnode$ = newVNode(tagName, null));
1356 if (!plt.$orgLocNodes$) {
1357 initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
1358 }
1359 hostElm[HYDRATE_ID] = hostId;
1360 hostElm.removeAttribute(HYDRATE_ID);
1361 clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
1362 childRenderNodes.map(function (c) {
1363 var orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
1364 var orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
1365 var node = c.$elm$;
1366 if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
1367 orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
1368 }
1369 if (!shadowRoot) {
1370 node['s-hn'] = tagName;
1371 if (orgLocationNode) {
1372 node['s-ol'] = orgLocationNode;
1373 node['s-ol']['s-nr'] = node;
1374 }
1375 }
1376 plt.$orgLocNodes$.delete(orgLocationId);
1377 });
1378 if (shadowRoot) {
1379 shadowRootNodes.map(function (shadowRootNode) {
1380 if (shadowRootNode) {
1381 shadowRoot.appendChild(shadowRootNode);
1382 }
1383 });
1384 }
1385 endHydrate();
1386};
1387var clientHydrate = function (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) {
1388 var childNodeType;
1389 var childIdSplt;
1390 var childVNode;
1391 var i;
1392 if (node.nodeType === 1 /* ElementNode */) {
1393 childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
1394 if (childNodeType) {
1395 // got the node data from the element's attribute
1396 // `${hostId}.${nodeId}.${depth}.${index}`
1397 childIdSplt = childNodeType.split('.');
1398 if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
1399 childVNode = {
1400 $flags$: 0,
1401 $hostId$: childIdSplt[0],
1402 $nodeId$: childIdSplt[1],
1403 $depth$: childIdSplt[2],
1404 $index$: childIdSplt[3],
1405 $tag$: node.tagName.toLowerCase(),
1406 $elm$: node,
1407 $attrs$: null,
1408 $children$: null,
1409 $key$: null,
1410 $name$: null,
1411 $text$: null,
1412 };
1413 childRenderNodes.push(childVNode);
1414 node.removeAttribute(HYDRATE_CHILD_ID);
1415 // this is a new child vnode
1416 // so ensure its parent vnode has the vchildren array
1417 if (!parentVNode.$children$) {
1418 parentVNode.$children$ = [];
1419 }
1420 // add our child vnode to a specific index of the vnode's children
1421 parentVNode.$children$[childVNode.$index$] = childVNode;
1422 // this is now the new parent vnode for all the next child checks
1423 parentVNode = childVNode;
1424 if (shadowRootNodes && childVNode.$depth$ === '0') {
1425 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1426 }
1427 }
1428 }
1429 // recursively drill down, end to start so we can remove nodes
1430 for (i = node.childNodes.length - 1; i >= 0; i--) {
1431 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
1432 }
1433 if (node.shadowRoot) {
1434 // keep drilling down through the shadow root nodes
1435 for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
1436 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
1437 }
1438 }
1439 }
1440 else if (node.nodeType === 8 /* CommentNode */) {
1441 // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
1442 childIdSplt = node.nodeValue.split('.');
1443 if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
1444 // comment node for either the host id or a 0 host id
1445 childNodeType = childIdSplt[0];
1446 childVNode = {
1447 $flags$: 0,
1448 $hostId$: childIdSplt[1],
1449 $nodeId$: childIdSplt[2],
1450 $depth$: childIdSplt[3],
1451 $index$: childIdSplt[4],
1452 $elm$: node,
1453 $attrs$: null,
1454 $children$: null,
1455 $key$: null,
1456 $name$: null,
1457 $tag$: null,
1458 $text$: null,
1459 };
1460 if (childNodeType === TEXT_NODE_ID) {
1461 childVNode.$elm$ = node.nextSibling;
1462 if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* TextNode */) {
1463 childVNode.$text$ = childVNode.$elm$.textContent;
1464 childRenderNodes.push(childVNode);
1465 // remove the text comment since it's no longer needed
1466 node.remove();
1467 if (!parentVNode.$children$) {
1468 parentVNode.$children$ = [];
1469 }
1470 parentVNode.$children$[childVNode.$index$] = childVNode;
1471 if (shadowRootNodes && childVNode.$depth$ === '0') {
1472 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1473 }
1474 }
1475 }
1476 else if (childVNode.$hostId$ === hostId) {
1477 // this comment node is specifcally for this host id
1478 if (childNodeType === SLOT_NODE_ID) {
1479 // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
1480 childVNode.$tag$ = 'slot';
1481 if (childIdSplt[5]) {
1482 node['s-sn'] = childVNode.$name$ = childIdSplt[5];
1483 }
1484 else {
1485 node['s-sn'] = '';
1486 }
1487 node['s-sr'] = true;
1488 if (shadowRootNodes) {
1489 // browser support shadowRoot and this is a shadow dom component
1490 // create an actual slot element
1491 childVNode.$elm$ = doc.createElement(childVNode.$tag$);
1492 if (childVNode.$name$) {
1493 // add the slot name attribute
1494 childVNode.$elm$.setAttribute('name', childVNode.$name$);
1495 }
1496 // insert the new slot element before the slot comment
1497 node.parentNode.insertBefore(childVNode.$elm$, node);
1498 // remove the slot comment since it's not needed for shadow
1499 node.remove();
1500 if (childVNode.$depth$ === '0') {
1501 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1502 }
1503 }
1504 slotNodes.push(childVNode);
1505 if (!parentVNode.$children$) {
1506 parentVNode.$children$ = [];
1507 }
1508 parentVNode.$children$[childVNode.$index$] = childVNode;
1509 }
1510 else if (childNodeType === CONTENT_REF_ID) {
1511 // `${CONTENT_REF_ID}.${hostId}`;
1512 if (shadowRootNodes) {
1513 // remove the content ref comment since it's not needed for shadow
1514 node.remove();
1515 }
1516 else {
1517 hostElm['s-cr'] = node;
1518 node['s-cn'] = true;
1519 }
1520 }
1521 }
1522 }
1523 }
1524 else if (parentVNode && parentVNode.$tag$ === 'style') {
1525 var vnode = newVNode(null, node.textContent);
1526 vnode.$elm$ = node;
1527 vnode.$index$ = '0';
1528 parentVNode.$children$ = [vnode];
1529 }
1530};
1531var initializeDocumentHydrate = function (node, orgLocNodes) {
1532 if (node.nodeType === 1 /* ElementNode */) {
1533 var i = 0;
1534 for (; i < node.childNodes.length; i++) {
1535 initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
1536 }
1537 if (node.shadowRoot) {
1538 for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
1539 initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
1540 }
1541 }
1542 }
1543 else if (node.nodeType === 8 /* CommentNode */) {
1544 var childIdSplt = node.nodeValue.split('.');
1545 if (childIdSplt[0] === ORG_LOCATION_ID) {
1546 orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
1547 node.nodeValue = '';
1548 // useful to know if the original location is
1549 // the root light-dom of a shadow dom component
1550 node['s-en'] = childIdSplt[3];
1551 }
1552 }
1553};
1554var parsePropertyValue = function (propValue, propType) {
1555 // ensure this value is of the correct prop type
1556 if (propValue != null && !isComplexType(propValue)) {
1557 if (propType & 4 /* Boolean */) {
1558 // per the HTML spec, any string value means it is a boolean true value
1559 // but we'll cheat here and say that the string "false" is the boolean false
1560 return propValue === 'false' ? false : propValue === '' || !!propValue;
1561 }
1562 if (propType & 2 /* Number */) {
1563 // force it to be a number
1564 return parseFloat(propValue);
1565 }
1566 if (propType & 1 /* String */) {
1567 // could have been passed as a number or boolean
1568 // but we still want it as a string
1569 return String(propValue);
1570 }
1571 // redundant return here for better minification
1572 return propValue;
1573 }
1574 // not sure exactly what type we want
1575 // so no need to change to a different type
1576 return propValue;
1577};
1578var getValue = function (ref, propName) { return getHostRef(ref).$instanceValues$.get(propName); };
1579var setValue = function (ref, propName, newVal, cmpMeta) {
1580 // check our new property value against our internal value
1581 var hostRef = getHostRef(ref);
1582 var oldVal = hostRef.$instanceValues$.get(propName);
1583 var flags = hostRef.$flags$;
1584 var instance = hostRef.$lazyInstance$;
1585 newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1586 if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
1587 // gadzooks! the property's value has changed!!
1588 // set our new value!
1589 hostRef.$instanceValues$.set(propName, newVal);
1590 if (instance) {
1591 // get an array of method names of watch functions to call
1592 if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
1593 var watchMethods = cmpMeta.$watchers$[propName];
1594 if (watchMethods) {
1595 // this instance is watching for when this property changed
1596 watchMethods.map(function (watchMethodName) {
1597 try {
1598 // fire off each of the watch methods that are watching this property
1599 instance[watchMethodName](newVal, oldVal, propName);
1600 }
1601 catch (e) {
1602 consoleError(e);
1603 }
1604 });
1605 }
1606 }
1607 if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1608 // looks like this value actually changed, so we've got work to do!
1609 // but only if we've already rendered, otherwise just chill out
1610 // queue that we need to do an update, but don't worry about queuing
1611 // up millions cuz this function ensures it only runs once
1612 scheduleUpdate(hostRef, false);
1613 }
1614 }
1615 }
1616};
1617var proxyComponent = function (Cstr, cmpMeta, flags) {
1618 if (cmpMeta.$members$) {
1619 if (Cstr.watchers) {
1620 cmpMeta.$watchers$ = Cstr.watchers;
1621 }
1622 // It's better to have a const than two Object.entries()
1623 var members = Object.entries(cmpMeta.$members$);
1624 var prototype_1 = Cstr.prototype;
1625 members.map(function (_a) {
1626 var memberName = _a[0], memberFlags = _a[1][0];
1627 if ((memberFlags & 31 /* Prop */ || ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
1628 // proxyComponent - prop
1629 Object.defineProperty(prototype_1, memberName, {
1630 get: function () {
1631 // proxyComponent, get value
1632 return getValue(this, memberName);
1633 },
1634 set: function (newValue) {
1635 // proxyComponent, set value
1636 setValue(this, memberName, newValue, cmpMeta);
1637 },
1638 configurable: true,
1639 enumerable: true,
1640 });
1641 }
1642 else if (flags & 1 /* isElementConstructor */ && memberFlags & 64 /* Method */) {
1643 // proxyComponent - method
1644 Object.defineProperty(prototype_1, memberName, {
1645 value: function () {
1646 var args = [];
1647 for (var _i = 0; _i < arguments.length; _i++) {
1648 args[_i] = arguments[_i];
1649 }
1650 var ref = getHostRef(this);
1651 return ref.$onInstancePromise$.then(function () {
1652 var _a;
1653 return (_a = ref.$lazyInstance$)[memberName].apply(_a, args);
1654 });
1655 },
1656 });
1657 }
1658 });
1659 if ((flags & 1 /* isElementConstructor */)) {
1660 var attrNameToPropName_1 = new Map();
1661 prototype_1.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1662 var _this = this;
1663 plt.jmp(function () {
1664 var propName = attrNameToPropName_1.get(attrName);
1665 _this[propName] = newValue === null && typeof _this[propName] === 'boolean' ? false : newValue;
1666 });
1667 };
1668 // create an array of attributes to observe
1669 // and also create a map of html attribute name to js property name
1670 Cstr.observedAttributes = members
1671 .filter(function (_a) {
1672 var _ = _a[0], m = _a[1];
1673 return m[0] & 15;
1674 } /* HasAttribute */) // filter to only keep props that should match attributes
1675 .map(function (_a) {
1676 var propName = _a[0], m = _a[1];
1677 var attrName = m[1] || propName;
1678 attrNameToPropName_1.set(attrName, propName);
1679 if (m[0] & 512 /* ReflectAttr */) {
1680 cmpMeta.$attrsToReflect$.push([propName, attrName]);
1681 }
1682 return attrName;
1683 });
1684 }
1685 }
1686 return Cstr;
1687};
1688var initializeComponent = function (elm, hostRef, cmpMeta, hmrVersionId, Cstr) { return __awaiter(void 0, void 0, void 0, function () {
1689 var endLoad, endNewInstance, scopeId_1, endRegisterStyles, style_1, ancestorComponent, schedule;
1690 return __generator(this, function (_a) {
1691 switch (_a.label) {
1692 case 0:
1693 if (!((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0)) return [3 /*break*/, 5];
1694 // we haven't initialized this element yet
1695 hostRef.$flags$ |= 32 /* hasInitializedComponent */;
1696 // lazy loaded components
1697 // request the component's implementation to be
1698 // wired up with the host element
1699 Cstr = loadModule(cmpMeta);
1700 if (!Cstr.then) return [3 /*break*/, 2];
1701 endLoad = uniqueTime();
1702 return [4 /*yield*/, Cstr];
1703 case 1:
1704 Cstr = _a.sent();
1705 endLoad();
1706 _a.label = 2;
1707 case 2:
1708 if (!Cstr.isProxied) {
1709 // we'eve never proxied this Constructor before
1710 // let's add the getters/setters to its prototype before
1711 // the first time we create an instance of the implementation
1712 {
1713 cmpMeta.$watchers$ = Cstr.watchers;
1714 }
1715 proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
1716 Cstr.isProxied = true;
1717 }
1718 endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1719 // ok, time to construct the instance
1720 // but let's keep track of when we start and stop
1721 // so that the getters/setters don't incorrectly step on data
1722 {
1723 hostRef.$flags$ |= 8 /* isConstructingInstance */;
1724 }
1725 // construct the lazy-loaded component implementation
1726 // passing the hostRef is very important during
1727 // construction in order to directly wire together the
1728 // host element and the lazy-loaded instance
1729 try {
1730 new Cstr(hostRef);
1731 }
1732 catch (e) {
1733 consoleError(e);
1734 }
1735 {
1736 hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1737 }
1738 {
1739 hostRef.$flags$ |= 128 /* isWatchReady */;
1740 }
1741 endNewInstance();
1742 fireConnectedCallback(hostRef.$lazyInstance$);
1743 scopeId_1 = getScopeId(cmpMeta.$tagName$);
1744 if (!(!styles.has(scopeId_1) && Cstr.style)) return [3 /*break*/, 5];
1745 endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1746 style_1 = Cstr.style;
1747 if (!(cmpMeta.$flags$ & 8) /* needsShadowDomShim */) return [3 /*break*/, 4]; /* needsShadowDomShim */
1748 return [4 /*yield*/, import('./shadow-css-76400429.js').then(function (m) { return m.scopeCss(style_1, scopeId_1, false); })];
1749 case 3:
1750 style_1 = _a.sent();
1751 _a.label = 4;
1752 case 4:
1753 registerStyle(scopeId_1, style_1, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1754 endRegisterStyles();
1755 _a.label = 5;
1756 case 5:
1757 ancestorComponent = hostRef.$ancestorComponent$;
1758 schedule = function () { return scheduleUpdate(hostRef, true); };
1759 if (ancestorComponent && ancestorComponent['s-rc']) {
1760 // this is the intial load and this component it has an ancestor component
1761 // but the ancestor component has NOT fired its will update lifecycle yet
1762 // so let's just cool our jets and wait for the ancestor to continue first
1763 // this will get fired off when the ancestor component
1764 // finally gets around to rendering its lazy self
1765 // fire off the initial update
1766 ancestorComponent['s-rc'].push(schedule);
1767 }
1768 else {
1769 schedule();
1770 }
1771 return [2 /*return*/];
1772 }
1773 });
1774}); };
1775var fireConnectedCallback = function (instance) {
1776 {
1777 safeCall(instance, 'connectedCallback');
1778 }
1779};
1780var connectedCallback = function (elm) {
1781 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1782 var hostRef = getHostRef(elm);
1783 var cmpMeta = hostRef.$cmpMeta$;
1784 var endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1785 {
1786 // only run if we have listeners being attached to a parent
1787 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, true);
1788 }
1789 if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
1790 // first time this component has connected
1791 hostRef.$flags$ |= 1 /* hasConnected */;
1792 var hostId = void 0;
1793 {
1794 hostId = elm.getAttribute(HYDRATE_ID);
1795 if (hostId) {
1796 if (supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
1797 var scopeId_2 = addStyle(elm.shadowRoot, cmpMeta);
1798 elm.classList.remove(scopeId_2 + '-h', scopeId_2 + '-s');
1799 }
1800 initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
1801 }
1802 }
1803 if (!hostId) {
1804 // initUpdate
1805 // if the slot polyfill is required we'll need to put some nodes
1806 // in here to act as original content anchors as we move nodes around
1807 // host element has been connected to the DOM
1808 if ((cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
1809 setContentReference(elm);
1810 }
1811 }
1812 {
1813 // find the first ancestor component (if there is one) and register
1814 // this component as one of the actively loading child components for its ancestor
1815 var ancestorComponent = elm;
1816 while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1817 // climb up the ancestors looking for the first
1818 // component that hasn't finished its lifecycle update yet
1819 if ((ancestorComponent.nodeType === 1 /* ElementNode */ && ancestorComponent.hasAttribute('s-id')) || ancestorComponent['s-p']) {
1820 // we found this components first ancestor component
1821 // keep a reference to this component's ancestor component
1822 attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1823 break;
1824 }
1825 }
1826 }
1827 // Lazy properties
1828 // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1829 if (cmpMeta.$members$) {
1830 Object.entries(cmpMeta.$members$).map(function (_a) {
1831 var memberName = _a[0], memberFlags = _a[1][0];
1832 if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
1833 var value = elm[memberName];
1834 delete elm[memberName];
1835 elm[memberName] = value;
1836 }
1837 });
1838 }
1839 {
1840 initializeComponent(elm, hostRef, cmpMeta);
1841 }
1842 }
1843 else {
1844 // not the first time this has connected
1845 // reattach any event listeners to the host
1846 // since they would have been removed when disconnected
1847 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
1848 // fire off connectedCallback() on component instance
1849 fireConnectedCallback(hostRef.$lazyInstance$);
1850 }
1851 endConnected();
1852 }
1853};
1854var setContentReference = function (elm) {
1855 // only required when we're NOT using native shadow dom (slot)
1856 // or this browser doesn't support native shadow dom
1857 // and this host element was NOT created with SSR
1858 // let's pick out the inner content for slot projection
1859 // create a node to represent where the original
1860 // content was first placed, which is useful later on
1861 var contentRefElm = (elm['s-cr'] = doc.createComment(''));
1862 contentRefElm['s-cn'] = true;
1863 elm.insertBefore(contentRefElm, elm.firstChild);
1864};
1865var disconnectedCallback = function (elm) {
1866 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1867 var hostRef = getHostRef(elm);
1868 var instance = hostRef.$lazyInstance$;
1869 {
1870 if (hostRef.$rmListeners$) {
1871 hostRef.$rmListeners$.map(function (rmListener) { return rmListener(); });
1872 hostRef.$rmListeners$ = undefined;
1873 }
1874 }
1875 // clear CSS var-shim tracking
1876 if (plt.$cssShim$) {
1877 plt.$cssShim$.removeHost(elm);
1878 }
1879 {
1880 safeCall(instance, 'disconnectedCallback');
1881 }
1882 {
1883 safeCall(instance, 'componentDidUnload');
1884 }
1885 }
1886};
1887var patchSlotAppendChild = function (HostElementPrototype) {
1888 HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
1889 HostElementPrototype.appendChild = function (newChild) {
1890 var slotName = (newChild['s-sn'] = getSlotName(newChild));
1891 var slotNode = getHostSlotNode(this.childNodes, slotName);
1892 if (slotNode) {
1893 var slotChildNodes = getHostSlotChildNodes(slotNode, slotName);
1894 var appendAfter = slotChildNodes[slotChildNodes.length - 1];
1895 return appendAfter.parentNode.insertBefore(newChild, appendAfter.nextSibling);
1896 }
1897 return this.__appendChild(newChild);
1898 };
1899};
1900var patchChildSlotNodes = function (elm, cmpMeta) {
1901 if (cmpMeta.$flags$ & 8 /* needsShadowDomShim */) {
1902 var childrenFn_1 = elm.__lookupGetter__('children');
1903 var childNodesFn_1 = elm.__lookupGetter__('childNodes');
1904 Object.defineProperty(elm, 'children', {
1905 get: function () {
1906 var children = childrenFn_1.call(this);
1907 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1908 var slotNode = getHostSlotNode(children, '');
1909 if (slotNode && slotNode.parentNode) {
1910 return slotNode.parentNode.children;
1911 }
1912 }
1913 return children;
1914 },
1915 });
1916 Object.defineProperty(elm, 'childElementCount', {
1917 get: function () {
1918 return elm.children.length;
1919 },
1920 });
1921 Object.defineProperty(elm, 'childNodes', {
1922 get: function () {
1923 var childNodes = childNodesFn_1.call(this);
1924 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1925 var slotNode = getHostSlotNode(childNodes, '');
1926 if (slotNode && slotNode.parentNode) {
1927 return slotNode.parentNode.childNodes;
1928 }
1929 }
1930 return childNodes;
1931 },
1932 });
1933 }
1934};
1935var getSlotName = function (node) { return node['s-sn'] || (node.nodeType === 1 && node.getAttribute('slot')) || ''; };
1936var getHostSlotNode = function (childNodes, slotName) {
1937 var i = 0;
1938 var childNode;
1939 for (; i < childNodes.length; i++) {
1940 childNode = childNodes[i];
1941 if (childNode['s-sr'] && childNode['s-sn'] === slotName) {
1942 return childNode;
1943 }
1944 childNode = getHostSlotNode(childNode.childNodes, slotName);
1945 if (childNode) {
1946 return childNode;
1947 }
1948 }
1949 return null;
1950};
1951var getHostSlotChildNodes = function (n, slotName) {
1952 var childNodes = [n];
1953 while ((n = n.nextSibling) && n['s-sn'] === slotName) {
1954 childNodes.push(n);
1955 }
1956 return childNodes;
1957};
1958var bootstrapLazy = function (lazyBundles, options) {
1959 if (options === void 0) { options = {}; }
1960 var endBootstrap = createTime();
1961 var cmpTags = [];
1962 var exclude = options.exclude || [];
1963 var customElements = win.customElements;
1964 var head = doc.head;
1965 var metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1966 var visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1967 var deferredConnectedCallbacks = [];
1968 var styles = /*@__PURE__*/ doc.querySelectorAll("[" + HYDRATED_STYLE_ID + "]");
1969 var appLoadFallback;
1970 var isBootstrapping = true;
1971 var i = 0;
1972 Object.assign(plt, options);
1973 plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1974 if (options.syncQueue) {
1975 plt.$flags$ |= 4 /* queueSync */;
1976 }
1977 {
1978 // If the app is already hydrated there is not point to disable the
1979 // async queue. This will improve the first input delay
1980 plt.$flags$ |= 2 /* appLoaded */;
1981 }
1982 {
1983 for (; i < styles.length; i++) {
1984 registerStyle(styles[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styles[i].innerHTML), true);
1985 }
1986 }
1987 lazyBundles.map(function (lazyBundle) { return lazyBundle[1].map(function (compactMeta) {
1988 var cmpMeta = {
1989 $flags$: compactMeta[0],
1990 $tagName$: compactMeta[1],
1991 $members$: compactMeta[2],
1992 $listeners$: compactMeta[3],
1993 };
1994 {
1995 cmpMeta.$members$ = compactMeta[2];
1996 }
1997 {
1998 cmpMeta.$listeners$ = compactMeta[3];
1999 }
2000 {
2001 cmpMeta.$attrsToReflect$ = [];
2002 }
2003 {
2004 cmpMeta.$watchers$ = {};
2005 }
2006 if (!supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2007 cmpMeta.$flags$ |= 8 /* needsShadowDomShim */;
2008 }
2009 var tagName = cmpMeta.$tagName$;
2010 var HostElement = /** @class */ (function (_super) {
2011 __extends(HostElement, _super);
2012 // StencilLazyHost
2013 function HostElement(self) {
2014 var _this =
2015 // @ts-ignore
2016 _super.call(this, self) || this;
2017 self = _this;
2018 registerHost(self, cmpMeta);
2019 if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2020 // this component is using shadow dom
2021 // and this browser supports shadow dom
2022 // add the read-only property "shadowRoot" to the host element
2023 // adding the shadow root build conditionals to minimize runtime
2024 if (supportsShadow) {
2025 {
2026 self.attachShadow({ mode: 'open' });
2027 }
2028 }
2029 else if (!('shadowRoot' in self)) {
2030 self.shadowRoot = self;
2031 }
2032 }
2033 {
2034 patchChildSlotNodes(self, cmpMeta);
2035 }
2036 return _this;
2037 }
2038 HostElement.prototype.connectedCallback = function () {
2039 var _this = this;
2040 if (appLoadFallback) {
2041 clearTimeout(appLoadFallback);
2042 appLoadFallback = null;
2043 }
2044 if (isBootstrapping) {
2045 // connectedCallback will be processed once all components have been registered
2046 deferredConnectedCallbacks.push(this);
2047 }
2048 else {
2049 plt.jmp(function () { return connectedCallback(_this); });
2050 }
2051 };
2052 HostElement.prototype.disconnectedCallback = function () {
2053 var _this = this;
2054 plt.jmp(function () { return disconnectedCallback(_this); });
2055 };
2056 HostElement.prototype.forceUpdate = function () {
2057 forceUpdate(this);
2058 };
2059 HostElement.prototype.componentOnReady = function () {
2060 return getHostRef(this).$onReadyPromise$;
2061 };
2062 return HostElement;
2063 }(HTMLElement));
2064 {
2065 patchSlotAppendChild(HostElement.prototype);
2066 }
2067 cmpMeta.$lazyBundleIds$ = lazyBundle[0];
2068 if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2069 cmpTags.push(tagName);
2070 customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
2071 }
2072 }); });
2073 {
2074 visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
2075 visibilityStyle.setAttribute('data-styles', '');
2076 head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
2077 }
2078 // Process deferred connectedCallbacks now all components have been registered
2079 isBootstrapping = false;
2080 if (deferredConnectedCallbacks.length) {
2081 deferredConnectedCallbacks.map(function (host) { return host.connectedCallback(); });
2082 }
2083 else {
2084 {
2085 plt.jmp(function () { return (appLoadFallback = setTimeout(appDidLoad, 30)); });
2086 }
2087 }
2088 // Fallback appLoad event
2089 endBootstrap();
2090};
2091var getAssetPath = function (path) {
2092 var assetUrl = new URL(path, plt.$resourcesUrl$);
2093 return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
2094};
2095var hostRefs = new WeakMap();
2096var getHostRef = function (ref) { return hostRefs.get(ref); };
2097var registerInstance = function (lazyInstance, hostRef) { return hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef); };
2098var registerHost = function (elm, cmpMeta) {
2099 var hostRef = {
2100 $flags$: 0,
2101 $hostElement$: elm,
2102 $cmpMeta$: cmpMeta,
2103 $instanceValues$: new Map(),
2104 };
2105 {
2106 hostRef.$onInstancePromise$ = new Promise(function (r) { return (hostRef.$onInstanceResolve$ = r); });
2107 }
2108 {
2109 hostRef.$onReadyPromise$ = new Promise(function (r) { return (hostRef.$onReadyResolve$ = r); });
2110 elm['s-p'] = [];
2111 elm['s-rc'] = [];
2112 }
2113 addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2114 return hostRefs.set(elm, hostRef);
2115};
2116var isMemberInElement = function (elm, memberName) { return memberName in elm; };
2117var consoleError = function (e) { return console.error(e); };
2118var cmpModules = /*@__PURE__*/ new Map();
2119var loadModule = function (cmpMeta, hostRef, hmrVersionId) {
2120 // loadModuleImport
2121 var exportName = cmpMeta.$tagName$.replace(/-/g, '_');
2122 var bundleId = (cmpMeta.$lazyBundleIds$);
2123 var module = cmpModules.get(bundleId);
2124 if (module) {
2125 return module[exportName];
2126 }
2127 return import(
2128 /* webpackInclude: /\.entry\.js$/ */
2129 /* webpackExclude: /\.system\.entry\.js$/ */
2130 /* webpackMode: "lazy" */
2131 /* webpackChunkName: "stencil-[request]" */
2132 "./" + bundleId + ".entry.js" + '').then(function (importedModule) {
2133 {
2134 cmpModules.set(bundleId, importedModule);
2135 }
2136 return importedModule[exportName];
2137 }, consoleError);
2138};
2139var styles = new Map();
2140var queueDomReads = [];
2141var queueDomWrites = [];
2142var queueDomWritesLow = [];
2143var queueTask = function (queue, write) { return function (cb) {
2144 queue.push(cb);
2145 if (!queuePending) {
2146 queuePending = true;
2147 if (write && plt.$flags$ & 4 /* queueSync */) {
2148 nextTick(flush);
2149 }
2150 else {
2151 plt.raf(flush);
2152 }
2153 }
2154}; };
2155var consume = function (queue) {
2156 for (var i = 0; i < queue.length; i++) {
2157 try {
2158 queue[i](performance.now());
2159 }
2160 catch (e) {
2161 consoleError(e);
2162 }
2163 }
2164 queue.length = 0;
2165};
2166var consumeTimeout = function (queue, timeout) {
2167 var i = 0;
2168 var ts = 0;
2169 while (i < queue.length && (ts = performance.now()) < timeout) {
2170 try {
2171 queue[i++](ts);
2172 }
2173 catch (e) {
2174 consoleError(e);
2175 }
2176 }
2177 if (i === queue.length) {
2178 queue.length = 0;
2179 }
2180 else if (i !== 0) {
2181 queue.splice(0, i);
2182 }
2183};
2184var flush = function () {
2185 queueCongestion++;
2186 // always force a bunch of medium callbacks to run, but still have
2187 // a throttle on how many can run in a certain time
2188 // DOM READS!!!
2189 consume(queueDomReads);
2190 var timeout = (plt.$flags$ & 6 /* queueMask */) === 2 /* appLoaded */ ? performance.now() + 10 * Math.ceil(queueCongestion * (1.0 / 22.0)) : Infinity;
2191 // DOM WRITES!!!
2192 consumeTimeout(queueDomWrites, timeout);
2193 consumeTimeout(queueDomWritesLow, timeout);
2194 if (queueDomWrites.length > 0) {
2195 queueDomWritesLow.push.apply(queueDomWritesLow, queueDomWrites);
2196 queueDomWrites.length = 0;
2197 }
2198 if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
2199 // still more to do yet, but we've run out of time
2200 // let's let this thing cool off and try again in the next tick
2201 plt.raf(flush);
2202 }
2203 else {
2204 queueCongestion = 0;
2205 }
2206};
2207var nextTick = /*@__PURE__*/ function (cb) { return promiseResolve().then(cb); };
2208var writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
2209var patchEsm = function () {
2210 // @ts-ignore
2211 if (!(CSS && CSS.supports && CSS.supports('color', 'var(--c)'))) {
2212 // @ts-ignore
2213 return import(/* webpackChunkName: "stencil-polyfills-css-shim" */ './css-shim-f8adc4ba.js').then(function () {
2214 if ((plt.$cssShim$ = win.__cssshim)) {
2215 return plt.$cssShim$.i();
2216 }
2217 else {
2218 // for better minification
2219 return 0;
2220 }
2221 });
2222 }
2223 return promiseResolve();
2224};
2225var patchBrowser = function () {
2226 {
2227 // shim css vars
2228 plt.$cssShim$ = win.__cssshim;
2229 }
2230 // @ts-ignore
2231 var scriptElm = Array.from(doc.querySelectorAll('script')).find(function (s) { return new RegExp("/" + NAMESPACE + "(\\.esm)?\\.js($|\\?|#)").test(s.src) || s.getAttribute('data-stencil-namespace') === NAMESPACE; });
2232 var opts = scriptElm['data-opts'] || {};
2233 if ('onbeforeload' in scriptElm && !history.scrollRestoration /* IS_ESM_BUILD */) {
2234 // Safari < v11 support: This IF is true if it's Safari below v11.
2235 // This fn cannot use async/await since Safari didn't support it until v11,
2236 // however, Safari 10 did support modules. Safari 10 also didn't support "nomodule",
2237 // so both the ESM file and nomodule file would get downloaded. Only Safari
2238 // has 'onbeforeload' in the script, and "history.scrollRestoration" was added
2239 // to Safari in v11. Return a noop then() so the async/await ESM code doesn't continue.
2240 // IS_ESM_BUILD is replaced at build time so this check doesn't happen in systemjs builds.
2241 return {
2242 then: function () {
2243 /* promise noop */
2244 },
2245 };
2246 }
2247 {
2248 opts.resourcesUrl = new URL('.', new URL(scriptElm.getAttribute('data-resources-url') || scriptElm.src, win.location.href)).href;
2249 {
2250 patchDynamicImport(opts.resourcesUrl, scriptElm);
2251 }
2252 if (!win.customElements) {
2253 // module support, but no custom elements support (Old Edge)
2254 // @ts-ignore
2255 return import(/* webpackChunkName: "stencil-polyfills-dom" */ './dom-4001f04a.js').then(function () { return opts; });
2256 }
2257 }
2258 return promiseResolve(opts);
2259};
2260var patchDynamicImport = function (base, orgScriptElm) {
2261 var importFunctionName = getDynamicImportFunction(NAMESPACE);
2262 try {
2263 // test if this browser supports dynamic imports
2264 // There is a caching issue in V8, that breaks using import() in Function
2265 // By generating a random string, we can workaround it
2266 // Check https://bugs.chromium.org/p/chromium/issues/detail?id=990810 for more info
2267 win[importFunctionName] = new Function('w', "return import(w);//" + Math.random());
2268 }
2269 catch (e) {
2270 // this shim is specifically for browsers that do support "esm" imports
2271 // however, they do NOT support "dynamic" imports
2272 // basically this code is for old Edge, v18 and below
2273 var moduleMap_1 = new Map();
2274 win[importFunctionName] = function (src) {
2275 var url = new URL(src, base).href;
2276 var mod = moduleMap_1.get(url);
2277 if (!mod) {
2278 var script_1 = doc.createElement('script');
2279 script_1.type = 'module';
2280 script_1.crossOrigin = orgScriptElm.crossOrigin;
2281 script_1.src = URL.createObjectURL(new Blob(["import * as m from '" + url + "'; window." + importFunctionName + ".m = m;"], { type: 'application/javascript' }));
2282 mod = new Promise(function (resolve) {
2283 script_1.onload = function () {
2284 resolve(win[importFunctionName].m);
2285 script_1.remove();
2286 };
2287 });
2288 moduleMap_1.set(url, mod);
2289 doc.head.appendChild(script_1);
2290 }
2291 return mod;
2292 };
2293 }
2294};
2295export { Host as H, patchEsm as a, bootstrapLazy as b, createEvent as c, getAssetPath as d, getElement as g, h, patchBrowser as p, registerInstance as r };