UNPKG

72.6 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 = 'bulmil';
58var contentRef;
59var hostTagName;
60var useNativeShadowDom = false;
61var checkSlotFallbackVisibility = false;
62var checkSlotRelocate = false;
63var isSvgMode = false;
64var queueCongestion = 0;
65var queuePending = false;
66var win = typeof window !== 'undefined' ? window : {};
67var CSS = win.CSS;
68var doc = win.document || { head: {} };
69var plt = {
70 $flags$: 0,
71 $resourcesUrl$: '',
72 jmp: function (h) { return h(); },
73 raf: function (h) { return requestAnimationFrame(h); },
74 ael: function (el, eventName, listener, opts) { return el.addEventListener(eventName, listener, opts); },
75 rel: function (el, eventName, listener, opts) { return el.removeEventListener(eventName, listener, opts); },
76};
77var supportsShadow = true;
78var promiseResolve = function (v) { return Promise.resolve(v); };
79var supportsConstructibleStylesheets = /*@__PURE__*/ (function () {
80 try {
81 new CSSStyleSheet();
82 return true;
83 }
84 catch (e) { }
85 return false;
86})();
87var CONTENT_REF_ID = 'r';
88var ORG_LOCATION_ID = 'o';
89var SLOT_NODE_ID = 's';
90var TEXT_NODE_ID = 't';
91var HYDRATE_ID = 's-id';
92var HYDRATED_STYLE_ID = 'sty-id';
93var HYDRATE_CHILD_ID = 'c-id';
94var HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
95var createTime = function (fnName, tagName) {
96 if (tagName === void 0) { tagName = ''; }
97 {
98 return function () {
99 return;
100 };
101 }
102};
103var uniqueTime = function (key, measureText) {
104 {
105 return function () {
106 return;
107 };
108 }
109};
110var rootAppliedStyles = new WeakMap();
111var registerStyle = function (scopeId, cssText, allowCS) {
112 var style = styles.get(scopeId);
113 if (supportsConstructibleStylesheets && allowCS) {
114 style = (style || new CSSStyleSheet());
115 style.replace(cssText);
116 }
117 else {
118 style = cssText;
119 }
120 styles.set(scopeId, style);
121};
122var addStyle = function (styleContainerNode, cmpMeta, mode, hostElm) {
123 var scopeId = getScopeId(cmpMeta);
124 var style = styles.get(scopeId);
125 // if an element is NOT connected then getRootNode() will return the wrong root node
126 // so the fallback is to always use the document for the root node in those cases
127 styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
128 if (style) {
129 if (typeof style === 'string') {
130 styleContainerNode = styleContainerNode.head || styleContainerNode;
131 var appliedStyles = rootAppliedStyles.get(styleContainerNode);
132 var styleElm = void 0;
133 if (!appliedStyles) {
134 rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
135 }
136 if (!appliedStyles.has(scopeId)) {
137 if (styleContainerNode.host && (styleElm = styleContainerNode.querySelector("[" + HYDRATED_STYLE_ID + "=\"" + scopeId + "\"]"))) {
138 // This is only happening on native shadow-dom, do not needs CSS var shim
139 styleElm.innerHTML = style;
140 }
141 else {
142 if (plt.$cssShim$) {
143 styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
144 var newScopeId = styleElm['s-sc'];
145 if (newScopeId) {
146 scopeId = newScopeId;
147 // we don't want to add this styleID to the appliedStyles Set
148 // since the cssVarShim might need to apply several different
149 // stylesheets for the same component
150 appliedStyles = null;
151 }
152 }
153 else {
154 styleElm = doc.createElement('style');
155 styleElm.innerHTML = style;
156 }
157 styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
158 }
159 if (appliedStyles) {
160 appliedStyles.add(scopeId);
161 }
162 }
163 }
164 else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
165 styleContainerNode.adoptedStyleSheets = __spreadArrays(styleContainerNode.adoptedStyleSheets, [style]);
166 }
167 }
168 return scopeId;
169};
170var attachStyles = function (hostRef) {
171 var cmpMeta = hostRef.$cmpMeta$;
172 var elm = hostRef.$hostElement$;
173 var endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
174 var scopeId = addStyle(elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
175 endAttachStyles();
176};
177var getScopeId = function (cmp, mode) { return 'sc-' + (cmp.$tagName$); };
178/**
179 * Default style mode id
180 */
181/**
182 * Reusable empty obj/array
183 * Don't add values to these!!
184 */
185var EMPTY_OBJ = {};
186var isComplexType = function (o) {
187 // https://jsperf.com/typeof-fn-object/5
188 o = typeof o;
189 return o === 'object' || o === 'function';
190};
191/**
192 * Production h() function based on Preact by
193 * Jason Miller (@developit)
194 * Licensed under the MIT License
195 * https://github.com/developit/preact/blob/master/LICENSE
196 *
197 * Modified for Stencil's compiler and vdom
198 */
199// const stack: any[] = [];
200// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
201// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
202var h = function (nodeName, vnodeData) {
203 var children = [];
204 for (var _i = 2; _i < arguments.length; _i++) {
205 children[_i - 2] = arguments[_i];
206 }
207 var child = null;
208 var slotName = null;
209 var simple = false;
210 var lastSimple = false;
211 var vNodeChildren = [];
212 var walk = function (c) {
213 for (var i = 0; i < c.length; i++) {
214 child = c[i];
215 if (Array.isArray(child)) {
216 walk(child);
217 }
218 else if (child != null && typeof child !== 'boolean') {
219 if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
220 child = String(child);
221 }
222 if (simple && lastSimple) {
223 // If the previous child was simple (string), we merge both
224 vNodeChildren[vNodeChildren.length - 1].$text$ += child;
225 }
226 else {
227 // Append a new vNode, if it's text, we create a text vNode
228 vNodeChildren.push(simple ? newVNode(null, child) : child);
229 }
230 lastSimple = simple;
231 }
232 }
233 };
234 walk(children);
235 if (vnodeData) {
236 if (vnodeData.name) {
237 slotName = vnodeData.name;
238 }
239 {
240 var classData_1 = vnodeData.className || vnodeData.class;
241 if (classData_1) {
242 vnodeData.class =
243 typeof classData_1 !== 'object'
244 ? classData_1
245 : Object.keys(classData_1)
246 .filter(function (k) { return classData_1[k]; })
247 .join(' ');
248 }
249 }
250 }
251 if (typeof nodeName === 'function') {
252 // nodeName is a functional component
253 return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
254 }
255 var vnode = newVNode(nodeName, null);
256 vnode.$attrs$ = vnodeData;
257 if (vNodeChildren.length > 0) {
258 vnode.$children$ = vNodeChildren;
259 }
260 {
261 vnode.$name$ = slotName;
262 }
263 return vnode;
264};
265var newVNode = function (tag, text) {
266 var vnode = {
267 $flags$: 0,
268 $tag$: tag,
269 $text$: text,
270 $elm$: null,
271 $children$: null,
272 };
273 {
274 vnode.$attrs$ = null;
275 }
276 {
277 vnode.$name$ = null;
278 }
279 return vnode;
280};
281var Host = {};
282var isHost = function (node) { return node && node.$tag$ === Host; };
283var vdomFnUtils = {
284 forEach: function (children, cb) { return children.map(convertToPublic).forEach(cb); },
285 map: function (children, cb) { return children
286 .map(convertToPublic)
287 .map(cb)
288 .map(convertToPrivate); },
289};
290var convertToPublic = function (node) { return ({
291 vattrs: node.$attrs$,
292 vchildren: node.$children$,
293 vkey: node.$key$,
294 vname: node.$name$,
295 vtag: node.$tag$,
296 vtext: node.$text$,
297}); };
298var convertToPrivate = function (node) {
299 var vnode = newVNode(node.vtag, node.vtext);
300 vnode.$attrs$ = node.vattrs;
301 vnode.$children$ = node.vchildren;
302 vnode.$key$ = node.vkey;
303 vnode.$name$ = node.vname;
304 return vnode;
305};
306/**
307 * Production setAccessor() function based on Preact by
308 * Jason Miller (@developit)
309 * Licensed under the MIT License
310 * https://github.com/developit/preact/blob/master/LICENSE
311 *
312 * Modified for Stencil's compiler and vdom
313 */
314var setAccessor = function (elm, memberName, oldValue, newValue, isSvg, flags) {
315 if (oldValue !== newValue) {
316 var isProp = isMemberInElement(elm, memberName);
317 var ln = memberName.toLowerCase();
318 if (memberName === 'class') {
319 var classList = elm.classList;
320 var oldClasses_1 = parseClassList(oldValue);
321 var newClasses_1 = parseClassList(newValue);
322 classList.remove.apply(classList, oldClasses_1.filter(function (c) { return c && !newClasses_1.includes(c); }));
323 classList.add.apply(classList, newClasses_1.filter(function (c) { return c && !oldClasses_1.includes(c); }));
324 }
325 else if ((!isProp) && memberName[0] === 'o' && memberName[1] === 'n') {
326 // Event Handlers
327 // so if the member name starts with "on" and the 3rd characters is
328 // a capital letter, and it's not already a member on the element,
329 // then we're assuming it's an event listener
330 if (memberName[2] === '-') {
331 // on- prefixed events
332 // allows to be explicit about the dom event to listen without any magic
333 // under the hood:
334 // <my-cmp on-click> // listens for "click"
335 // <my-cmp on-Click> // listens for "Click"
336 // <my-cmp on-ionChange> // listens for "ionChange"
337 // <my-cmp on-EVENTS> // listens for "EVENTS"
338 memberName = memberName.slice(3);
339 }
340 else if (isMemberInElement(win, ln)) {
341 // standard event
342 // the JSX attribute could have been "onMouseOver" and the
343 // member name "onmouseover" is on the window's prototype
344 // so let's add the listener "mouseover", which is all lowercased
345 memberName = ln.slice(2);
346 }
347 else {
348 // custom event
349 // the JSX attribute could have been "onMyCustomEvent"
350 // so let's trim off the "on" prefix and lowercase the first character
351 // and add the listener "myCustomEvent"
352 // except for the first character, we keep the event name case
353 memberName = ln[2] + memberName.slice(3);
354 }
355 if (oldValue) {
356 plt.rel(elm, memberName, oldValue, false);
357 }
358 if (newValue) {
359 plt.ael(elm, memberName, newValue, false);
360 }
361 }
362 else {
363 // Set property if it exists and it's not a SVG
364 var isComplex = isComplexType(newValue);
365 if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
366 try {
367 if (!elm.tagName.includes('-')) {
368 var n = newValue == null ? '' : newValue;
369 // Workaround for Safari, moving the <input> caret when re-assigning the same valued
370 if (memberName === 'list') {
371 isProp = false;
372 // tslint:disable-next-line: triple-equals
373 }
374 else if (oldValue == null || elm[memberName] != n) {
375 elm[memberName] = n;
376 }
377 }
378 else {
379 elm[memberName] = newValue;
380 }
381 }
382 catch (e) { }
383 }
384 if (newValue == null || newValue === false) {
385 if (newValue !== false || elm.getAttribute(memberName) === '') {
386 {
387 elm.removeAttribute(memberName);
388 }
389 }
390 }
391 else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
392 newValue = newValue === true ? '' : newValue;
393 {
394 elm.setAttribute(memberName, newValue);
395 }
396 }
397 }
398 }
399};
400var parseClassListRegex = /\s/;
401var parseClassList = function (value) { return (!value ? [] : value.split(parseClassListRegex)); };
402var updateElement = function (oldVnode, newVnode, isSvgMode, memberName) {
403 // if the element passed in is a shadow root, which is a document fragment
404 // then we want to be adding attrs/props to the shadow root's "host" element
405 // if it's not a shadow root, then we add attrs/props to the same element
406 var elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
407 var oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
408 var newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
409 {
410 // remove attributes no longer present on the vnode by setting them to undefined
411 for (memberName in oldVnodeAttrs) {
412 if (!(memberName in newVnodeAttrs)) {
413 setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
414 }
415 }
416 }
417 // add new & update changed attributes
418 for (memberName in newVnodeAttrs) {
419 setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
420 }
421};
422var createElm = function (oldParentVNode, newParentVNode, childIndex, parentElm) {
423 // tslint:disable-next-line: prefer-const
424 var newVNode = newParentVNode.$children$[childIndex];
425 var i = 0;
426 var elm;
427 var childNode;
428 var oldVNode;
429 if (!useNativeShadowDom) {
430 // remember for later we need to check to relocate nodes
431 checkSlotRelocate = true;
432 if (newVNode.$tag$ === 'slot') {
433 newVNode.$flags$ |= newVNode.$children$
434 ? // slot element has fallback content
435 2 /* isSlotFallback */
436 : // slot element does not have fallback content
437 1 /* isSlotReference */;
438 }
439 }
440 if (newVNode.$text$ !== null) {
441 // create text node
442 elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
443 }
444 else if (newVNode.$flags$ & 1 /* isSlotReference */) {
445 // create a slot reference node
446 elm = newVNode.$elm$ = doc.createTextNode('');
447 }
448 else {
449 // create element
450 elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$));
451 // add css classes, attrs, props, listeners, etc.
452 {
453 updateElement(null, newVNode, isSvgMode);
454 }
455 if (newVNode.$children$) {
456 for (i = 0; i < newVNode.$children$.length; ++i) {
457 // create the node
458 childNode = createElm(oldParentVNode, newVNode, i);
459 // return node could have been null
460 if (childNode) {
461 // append our new node
462 elm.appendChild(childNode);
463 }
464 }
465 }
466 }
467 {
468 elm['s-hn'] = hostTagName;
469 if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
470 // remember the content reference comment
471 elm['s-sr'] = true;
472 // remember the content reference comment
473 elm['s-cr'] = contentRef;
474 // remember the slot name, or empty string for default slot
475 elm['s-sn'] = newVNode.$name$ || '';
476 // check if we've got an old vnode for this slot
477 oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
478 if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
479 // we've got an old slot vnode and the wrapper is being replaced
480 // so let's move the old slot content back to it's original location
481 putBackInOriginalLocation(oldParentVNode.$elm$, false);
482 }
483 }
484 }
485 return elm;
486};
487var putBackInOriginalLocation = function (parentElm, recursive) {
488 plt.$flags$ |= 1 /* isTmpDisconnected */;
489 var oldSlotChildNodes = parentElm.childNodes;
490 for (var i = oldSlotChildNodes.length - 1; i >= 0; i--) {
491 var childNode = oldSlotChildNodes[i];
492 if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
493 // // this child node in the old element is from another component
494 // // remove this node from the old slot's parent
495 // childNode.remove();
496 // and relocate it back to it's original location
497 parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
498 // remove the old original location comment entirely
499 // later on the patch function will know what to do
500 // and move this to the correct spot in need be
501 childNode['s-ol'].remove();
502 childNode['s-ol'] = undefined;
503 checkSlotRelocate = true;
504 }
505 if (recursive) {
506 putBackInOriginalLocation(childNode, recursive);
507 }
508 }
509 plt.$flags$ &= ~1 /* isTmpDisconnected */;
510};
511var addVnodes = function (parentElm, before, parentVNode, vnodes, startIdx, endIdx) {
512 var containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
513 var childNode;
514 for (; startIdx <= endIdx; ++startIdx) {
515 if (vnodes[startIdx]) {
516 childNode = createElm(null, parentVNode, startIdx);
517 if (childNode) {
518 vnodes[startIdx].$elm$ = childNode;
519 containerElm.insertBefore(childNode, referenceNode(before));
520 }
521 }
522 }
523};
524var removeVnodes = function (vnodes, startIdx, endIdx, vnode, elm) {
525 for (; startIdx <= endIdx; ++startIdx) {
526 if ((vnode = vnodes[startIdx])) {
527 elm = vnode.$elm$;
528 {
529 // we're removing this element
530 // so it's possible we need to show slot fallback content now
531 checkSlotFallbackVisibility = true;
532 if (elm['s-ol']) {
533 // remove the original location comment
534 elm['s-ol'].remove();
535 }
536 else {
537 // it's possible that child nodes of the node
538 // that's being removed are slot nodes
539 putBackInOriginalLocation(elm, true);
540 }
541 }
542 // remove the vnode's element from the dom
543 elm.remove();
544 }
545 }
546};
547var updateChildren = function (parentElm, oldCh, newVNode, newCh) {
548 var oldStartIdx = 0;
549 var newStartIdx = 0;
550 var oldEndIdx = oldCh.length - 1;
551 var oldStartVnode = oldCh[0];
552 var oldEndVnode = oldCh[oldEndIdx];
553 var newEndIdx = newCh.length - 1;
554 var newStartVnode = newCh[0];
555 var newEndVnode = newCh[newEndIdx];
556 var node;
557 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
558 if (oldStartVnode == null) {
559 // Vnode might have been moved left
560 oldStartVnode = oldCh[++oldStartIdx];
561 }
562 else if (oldEndVnode == null) {
563 oldEndVnode = oldCh[--oldEndIdx];
564 }
565 else if (newStartVnode == null) {
566 newStartVnode = newCh[++newStartIdx];
567 }
568 else if (newEndVnode == null) {
569 newEndVnode = newCh[--newEndIdx];
570 }
571 else if (isSameVnode(oldStartVnode, newStartVnode)) {
572 patch(oldStartVnode, newStartVnode);
573 oldStartVnode = oldCh[++oldStartIdx];
574 newStartVnode = newCh[++newStartIdx];
575 }
576 else if (isSameVnode(oldEndVnode, newEndVnode)) {
577 patch(oldEndVnode, newEndVnode);
578 oldEndVnode = oldCh[--oldEndIdx];
579 newEndVnode = newCh[--newEndIdx];
580 }
581 else if (isSameVnode(oldStartVnode, newEndVnode)) {
582 // Vnode moved right
583 if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
584 putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
585 }
586 patch(oldStartVnode, newEndVnode);
587 parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
588 oldStartVnode = oldCh[++oldStartIdx];
589 newEndVnode = newCh[--newEndIdx];
590 }
591 else if (isSameVnode(oldEndVnode, newStartVnode)) {
592 // Vnode moved left
593 if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
594 putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
595 }
596 patch(oldEndVnode, newStartVnode);
597 parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
598 oldEndVnode = oldCh[--oldEndIdx];
599 newStartVnode = newCh[++newStartIdx];
600 }
601 else {
602 {
603 // new element
604 node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
605 newStartVnode = newCh[++newStartIdx];
606 }
607 if (node) {
608 {
609 parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
610 }
611 }
612 }
613 }
614 if (oldStartIdx > oldEndIdx) {
615 addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
616 }
617 else if (newStartIdx > newEndIdx) {
618 removeVnodes(oldCh, oldStartIdx, oldEndIdx);
619 }
620};
621var isSameVnode = function (vnode1, vnode2) {
622 // compare if two vnode to see if they're "technically" the same
623 // need to have the same element tag, and same key to be the same
624 if (vnode1.$tag$ === vnode2.$tag$) {
625 if (vnode1.$tag$ === 'slot') {
626 return vnode1.$name$ === vnode2.$name$;
627 }
628 return true;
629 }
630 return false;
631};
632var referenceNode = function (node) {
633 // this node was relocated to a new location in the dom
634 // because of some other component's slot
635 // but we still have an html comment in place of where
636 // it's original location was according to it's original vdom
637 return (node && node['s-ol']) || node;
638};
639var parentReferenceNode = function (node) { return (node['s-ol'] ? node['s-ol'] : node).parentNode; };
640var patch = function (oldVNode, newVNode) {
641 var elm = (newVNode.$elm$ = oldVNode.$elm$);
642 var oldChildren = oldVNode.$children$;
643 var newChildren = newVNode.$children$;
644 var tag = newVNode.$tag$;
645 var text = newVNode.$text$;
646 var defaultHolder;
647 if (text === null) {
648 // element node
649 {
650 if (tag === 'slot')
651 ;
652 else {
653 // either this is the first render of an element OR it's an update
654 // AND we already know it's possible it could have changed
655 // this updates the element's css classes, attrs, props, listeners, etc.
656 updateElement(oldVNode, newVNode, isSvgMode);
657 }
658 }
659 if (oldChildren !== null && newChildren !== null) {
660 // looks like there's child vnodes for both the old and new vnodes
661 updateChildren(elm, oldChildren, newVNode, newChildren);
662 }
663 else if (newChildren !== null) {
664 // no old child vnodes, but there are new child vnodes to add
665 if (oldVNode.$text$ !== null) {
666 // the old vnode was text, so be sure to clear it out
667 elm.textContent = '';
668 }
669 // add the new vnode children
670 addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
671 }
672 else if (oldChildren !== null) {
673 // no new child vnodes, but there are old child vnodes to remove
674 removeVnodes(oldChildren, 0, oldChildren.length - 1);
675 }
676 }
677 else if ((defaultHolder = elm['s-cr'])) {
678 // this element has slotted content
679 defaultHolder.parentNode.textContent = text;
680 }
681 else if (oldVNode.$text$ !== text) {
682 // update the text content for the text only vnode
683 // and also only if the text is different than before
684 elm.data = text;
685 }
686};
687var updateFallbackSlotVisibility = function (elm) {
688 // tslint:disable-next-line: prefer-const
689 var childNodes = elm.childNodes;
690 var childNode;
691 var i;
692 var ilen;
693 var j;
694 var slotNameAttr;
695 var nodeType;
696 for (i = 0, ilen = childNodes.length; i < ilen; i++) {
697 childNode = childNodes[i];
698 if (childNode.nodeType === 1 /* ElementNode */) {
699 if (childNode['s-sr']) {
700 // this is a slot fallback node
701 // get the slot name for this slot reference node
702 slotNameAttr = childNode['s-sn'];
703 // by default always show a fallback slot node
704 // then hide it if there are other slots in the light dom
705 childNode.hidden = false;
706 for (j = 0; j < ilen; j++) {
707 if (childNodes[j]['s-hn'] !== childNode['s-hn']) {
708 // this sibling node is from a different component
709 nodeType = childNodes[j].nodeType;
710 if (slotNameAttr !== '') {
711 // this is a named fallback slot node
712 if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
713 childNode.hidden = true;
714 break;
715 }
716 }
717 else {
718 // this is a default fallback slot node
719 // any element or text node (with content)
720 // should hide the default fallback slot node
721 if (nodeType === 1 /* ElementNode */ || (nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
722 childNode.hidden = true;
723 break;
724 }
725 }
726 }
727 }
728 }
729 // keep drilling down
730 updateFallbackSlotVisibility(childNode);
731 }
732 }
733};
734var relocateNodes = [];
735var relocateSlotContent = function (elm) {
736 // tslint:disable-next-line: prefer-const
737 var childNode;
738 var node;
739 var hostContentNodes;
740 var slotNameAttr;
741 var relocateNodeData;
742 var j;
743 var i = 0;
744 var childNodes = elm.childNodes;
745 var ilen = childNodes.length;
746 for (; i < ilen; i++) {
747 childNode = childNodes[i];
748 if (childNode['s-sr'] && (node = childNode['s-cr'])) {
749 // first got the content reference comment node
750 // then we got it's parent, which is where all the host content is in now
751 hostContentNodes = node.parentNode.childNodes;
752 slotNameAttr = childNode['s-sn'];
753 for (j = hostContentNodes.length - 1; j >= 0; j--) {
754 node = hostContentNodes[j];
755 if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
756 // let's do some relocating to its new home
757 // but never relocate a content reference node
758 // that is suppose to always represent the original content location
759 if (isNodeLocatedInSlot(node, slotNameAttr)) {
760 // it's possible we've already decided to relocate this node
761 relocateNodeData = relocateNodes.find(function (r) { return r.$nodeToRelocate$ === node; });
762 // made some changes to slots
763 // let's make sure we also double check
764 // fallbacks are correctly hidden or shown
765 checkSlotFallbackVisibility = true;
766 node['s-sn'] = node['s-sn'] || slotNameAttr;
767 if (relocateNodeData) {
768 // previously we never found a slot home for this node
769 // but turns out we did, so let's remember it now
770 relocateNodeData.$slotRefNode$ = childNode;
771 }
772 else {
773 // add to our list of nodes to relocate
774 relocateNodes.push({
775 $slotRefNode$: childNode,
776 $nodeToRelocate$: node,
777 });
778 }
779 if (node['s-sr']) {
780 relocateNodes.map(function (relocateNode) {
781 if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
782 relocateNodeData = relocateNodes.find(function (r) { return r.$nodeToRelocate$ === node; });
783 if (relocateNodeData && !relocateNode.$slotRefNode$) {
784 relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
785 }
786 }
787 });
788 }
789 }
790 else if (!relocateNodes.some(function (r) { return r.$nodeToRelocate$ === node; })) {
791 // so far this element does not have a slot home, not setting slotRefNode on purpose
792 // if we never find a home for this element then we'll need to hide it
793 relocateNodes.push({
794 $nodeToRelocate$: node,
795 });
796 }
797 }
798 }
799 }
800 if (childNode.nodeType === 1 /* ElementNode */) {
801 relocateSlotContent(childNode);
802 }
803 }
804};
805var isNodeLocatedInSlot = function (nodeToRelocate, slotNameAttr) {
806 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
807 if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
808 return true;
809 }
810 if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
811 return true;
812 }
813 return false;
814 }
815 if (nodeToRelocate['s-sn'] === slotNameAttr) {
816 return true;
817 }
818 return slotNameAttr === '';
819};
820var renderVdom = function (hostRef, renderFnResults) {
821 var hostElm = hostRef.$hostElement$;
822 var cmpMeta = hostRef.$cmpMeta$;
823 var oldVNode = hostRef.$vnode$ || newVNode(null, null);
824 var rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
825 hostTagName = hostElm.tagName;
826 if (cmpMeta.$attrsToReflect$) {
827 rootVnode.$attrs$ = rootVnode.$attrs$ || {};
828 cmpMeta.$attrsToReflect$.map(function (_a) {
829 var propName = _a[0], attribute = _a[1];
830 return (rootVnode.$attrs$[attribute] = hostElm[propName]);
831 });
832 }
833 rootVnode.$tag$ = null;
834 rootVnode.$flags$ |= 4 /* isHost */;
835 hostRef.$vnode$ = rootVnode;
836 rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
837 {
838 contentRef = hostElm['s-cr'];
839 useNativeShadowDom = (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
840 // always reset
841 checkSlotFallbackVisibility = false;
842 }
843 // synchronous patch
844 patch(oldVNode, rootVnode);
845 {
846 // while we're moving nodes around existing nodes, temporarily disable
847 // the disconnectCallback from working
848 plt.$flags$ |= 1 /* isTmpDisconnected */;
849 if (checkSlotRelocate) {
850 relocateSlotContent(rootVnode.$elm$);
851 var relocateData = void 0;
852 var nodeToRelocate = void 0;
853 var orgLocationNode = void 0;
854 var parentNodeRef = void 0;
855 var insertBeforeNode = void 0;
856 var refNode = void 0;
857 var i = 0;
858 for (; i < relocateNodes.length; i++) {
859 relocateData = relocateNodes[i];
860 nodeToRelocate = relocateData.$nodeToRelocate$;
861 if (!nodeToRelocate['s-ol']) {
862 // add a reference node marking this node's original location
863 // keep a reference to this node for later lookups
864 orgLocationNode = doc.createTextNode('');
865 orgLocationNode['s-nr'] = nodeToRelocate;
866 nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
867 }
868 }
869 for (i = 0; i < relocateNodes.length; i++) {
870 relocateData = relocateNodes[i];
871 nodeToRelocate = relocateData.$nodeToRelocate$;
872 if (relocateData.$slotRefNode$) {
873 // by default we're just going to insert it directly
874 // after the slot reference node
875 parentNodeRef = relocateData.$slotRefNode$.parentNode;
876 insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
877 orgLocationNode = nodeToRelocate['s-ol'];
878 while ((orgLocationNode = orgLocationNode.previousSibling)) {
879 refNode = orgLocationNode['s-nr'];
880 if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
881 refNode = refNode.nextSibling;
882 if (!refNode || !refNode['s-nr']) {
883 insertBeforeNode = refNode;
884 break;
885 }
886 }
887 }
888 if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) || nodeToRelocate.nextSibling !== insertBeforeNode) {
889 // we've checked that it's worth while to relocate
890 // since that the node to relocate
891 // has a different next sibling or parent relocated
892 if (nodeToRelocate !== insertBeforeNode) {
893 if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
894 // probably a component in the index.html that doesn't have it's hostname set
895 nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
896 }
897 // add it back to the dom but in its new home
898 parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
899 }
900 }
901 }
902 else {
903 // this node doesn't have a slot home to go to, so let's hide it
904 if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
905 nodeToRelocate.hidden = true;
906 }
907 }
908 }
909 }
910 if (checkSlotFallbackVisibility) {
911 updateFallbackSlotVisibility(rootVnode.$elm$);
912 }
913 // done moving nodes around
914 // allow the disconnect callback to work again
915 plt.$flags$ &= ~1 /* isTmpDisconnected */;
916 // always reset
917 relocateNodes.length = 0;
918 }
919};
920var emitEvent = function (elm, name, opts) {
921 var ev = new (CustomEvent)(name, opts);
922 elm.dispatchEvent(ev);
923 return ev;
924};
925var attachToAncestor = function (hostRef, ancestorComponent) {
926 if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
927 ancestorComponent['s-p'].push(new Promise(function (r) { return (hostRef.$onRenderResolve$ = r); }));
928 }
929};
930var scheduleUpdate = function (hostRef, isInitialLoad) {
931 {
932 hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
933 }
934 if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
935 hostRef.$flags$ |= 512 /* needsRerender */;
936 return;
937 }
938 attachToAncestor(hostRef, hostRef.$ancestorComponent$);
939 // there is no ancestorc omponent or the ancestor component
940 // has already fired off its lifecycle update then
941 // fire off the initial update
942 var dispatch = function () { return dispatchHooks(hostRef, isInitialLoad); };
943 return writeTask(dispatch);
944};
945var dispatchHooks = function (hostRef, isInitialLoad) {
946 var endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
947 var instance = hostRef.$lazyInstance$;
948 var promise;
949 endSchedule();
950 return then(promise, function () { return updateComponent(hostRef, instance, isInitialLoad); });
951};
952var updateComponent = function (hostRef, instance, isInitialLoad) {
953 // updateComponent
954 var elm = hostRef.$hostElement$;
955 var endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
956 var rc = elm['s-rc'];
957 if (isInitialLoad) {
958 // DOM WRITE!
959 attachStyles(hostRef);
960 }
961 var endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
962 {
963 {
964 // looks like we've got child nodes to render into this host element
965 // or we need to update the css class/attrs on the host element
966 // DOM WRITE!
967 renderVdom(hostRef, callRender(hostRef, instance));
968 }
969 }
970 if (plt.$cssShim$) {
971 plt.$cssShim$.updateHost(elm);
972 }
973 if (rc) {
974 // ok, so turns out there are some child host elements
975 // waiting on this parent element to load
976 // let's fire off all update callbacks waiting
977 rc.map(function (cb) { return cb(); });
978 elm['s-rc'] = undefined;
979 }
980 endRender();
981 endUpdate();
982 {
983 var childrenPromises = elm['s-p'];
984 var postUpdate = function () { return postUpdateComponent(hostRef); };
985 if (childrenPromises.length === 0) {
986 postUpdate();
987 }
988 else {
989 Promise.all(childrenPromises).then(postUpdate);
990 hostRef.$flags$ |= 4 /* isWaitingForChildren */;
991 childrenPromises.length = 0;
992 }
993 }
994};
995var callRender = function (hostRef, instance) {
996 try {
997 instance = instance.render();
998 {
999 hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
1000 }
1001 {
1002 hostRef.$flags$ |= 2 /* hasRendered */;
1003 }
1004 }
1005 catch (e) {
1006 consoleError(e);
1007 }
1008 return instance;
1009};
1010var postUpdateComponent = function (hostRef) {
1011 var tagName = hostRef.$cmpMeta$.$tagName$;
1012 var elm = hostRef.$hostElement$;
1013 var endPostUpdate = createTime('postUpdate', tagName);
1014 var ancestorComponent = hostRef.$ancestorComponent$;
1015 if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
1016 hostRef.$flags$ |= 64 /* hasLoadedComponent */;
1017 {
1018 // DOM WRITE!
1019 addHydratedFlag(elm);
1020 }
1021 endPostUpdate();
1022 {
1023 hostRef.$onReadyResolve$(elm);
1024 if (!ancestorComponent) {
1025 appDidLoad();
1026 }
1027 }
1028 }
1029 else {
1030 endPostUpdate();
1031 }
1032 // load events fire from bottom to top
1033 // the deepest elements load first then bubbles up
1034 {
1035 if (hostRef.$onRenderResolve$) {
1036 hostRef.$onRenderResolve$();
1037 hostRef.$onRenderResolve$ = undefined;
1038 }
1039 if (hostRef.$flags$ & 512 /* needsRerender */) {
1040 nextTick(function () { return scheduleUpdate(hostRef, false); });
1041 }
1042 hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
1043 }
1044 // ( •_•)
1045 // ( •_•)>⌐■-■
1046 // (⌐■_■)
1047};
1048var forceUpdate = function (ref) {
1049 {
1050 var hostRef = getHostRef(ref);
1051 var isConnected = hostRef.$hostElement$.isConnected;
1052 if (isConnected && (hostRef.$flags$ & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1053 scheduleUpdate(hostRef, false);
1054 }
1055 // Returns "true" when the forced update was successfully scheduled
1056 return isConnected;
1057 }
1058};
1059var appDidLoad = function (who) {
1060 // on appload
1061 // we have finish the first big initial render
1062 {
1063 addHydratedFlag(doc.documentElement);
1064 }
1065 {
1066 plt.$flags$ |= 2 /* appLoaded */;
1067 }
1068 nextTick(function () { return emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }); });
1069};
1070var then = function (promise, thenFn) {
1071 return promise && promise.then ? promise.then(thenFn) : thenFn();
1072};
1073var addHydratedFlag = function (elm) { return (elm.classList.add('hydrated')); };
1074var initializeClientHydrate = function (hostElm, tagName, hostId, hostRef) {
1075 var endHydrate = createTime('hydrateClient', tagName);
1076 var shadowRoot = hostElm.shadowRoot;
1077 var childRenderNodes = [];
1078 var slotNodes = [];
1079 var shadowRootNodes = null;
1080 var vnode = (hostRef.$vnode$ = newVNode(tagName, null));
1081 if (!plt.$orgLocNodes$) {
1082 initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
1083 }
1084 hostElm[HYDRATE_ID] = hostId;
1085 hostElm.removeAttribute(HYDRATE_ID);
1086 clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
1087 childRenderNodes.map(function (c) {
1088 var orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
1089 var orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
1090 var node = c.$elm$;
1091 if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
1092 orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
1093 }
1094 if (!shadowRoot) {
1095 node['s-hn'] = tagName;
1096 if (orgLocationNode) {
1097 node['s-ol'] = orgLocationNode;
1098 node['s-ol']['s-nr'] = node;
1099 }
1100 }
1101 plt.$orgLocNodes$.delete(orgLocationId);
1102 });
1103 endHydrate();
1104};
1105var clientHydrate = function (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) {
1106 var childNodeType;
1107 var childIdSplt;
1108 var childVNode;
1109 var i;
1110 if (node.nodeType === 1 /* ElementNode */) {
1111 childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
1112 if (childNodeType) {
1113 // got the node data from the element's attribute
1114 // `${hostId}.${nodeId}.${depth}.${index}`
1115 childIdSplt = childNodeType.split('.');
1116 if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
1117 childVNode = {
1118 $flags$: 0,
1119 $hostId$: childIdSplt[0],
1120 $nodeId$: childIdSplt[1],
1121 $depth$: childIdSplt[2],
1122 $index$: childIdSplt[3],
1123 $tag$: node.tagName.toLowerCase(),
1124 $elm$: node,
1125 $attrs$: null,
1126 $children$: null,
1127 $key$: null,
1128 $name$: null,
1129 $text$: null,
1130 };
1131 childRenderNodes.push(childVNode);
1132 node.removeAttribute(HYDRATE_CHILD_ID);
1133 // this is a new child vnode
1134 // so ensure its parent vnode has the vchildren array
1135 if (!parentVNode.$children$) {
1136 parentVNode.$children$ = [];
1137 }
1138 // add our child vnode to a specific index of the vnode's children
1139 parentVNode.$children$[childVNode.$index$] = childVNode;
1140 // this is now the new parent vnode for all the next child checks
1141 parentVNode = childVNode;
1142 if (shadowRootNodes && childVNode.$depth$ === '0') {
1143 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1144 }
1145 }
1146 }
1147 // recursively drill down, end to start so we can remove nodes
1148 for (i = node.childNodes.length - 1; i >= 0; i--) {
1149 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
1150 }
1151 if (node.shadowRoot) {
1152 // keep drilling down through the shadow root nodes
1153 for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
1154 clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
1155 }
1156 }
1157 }
1158 else if (node.nodeType === 8 /* CommentNode */) {
1159 // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
1160 childIdSplt = node.nodeValue.split('.');
1161 if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
1162 // comment node for either the host id or a 0 host id
1163 childNodeType = childIdSplt[0];
1164 childVNode = {
1165 $flags$: 0,
1166 $hostId$: childIdSplt[1],
1167 $nodeId$: childIdSplt[2],
1168 $depth$: childIdSplt[3],
1169 $index$: childIdSplt[4],
1170 $elm$: node,
1171 $attrs$: null,
1172 $children$: null,
1173 $key$: null,
1174 $name$: null,
1175 $tag$: null,
1176 $text$: null,
1177 };
1178 if (childNodeType === TEXT_NODE_ID) {
1179 childVNode.$elm$ = node.nextSibling;
1180 if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* TextNode */) {
1181 childVNode.$text$ = childVNode.$elm$.textContent;
1182 childRenderNodes.push(childVNode);
1183 // remove the text comment since it's no longer needed
1184 node.remove();
1185 if (!parentVNode.$children$) {
1186 parentVNode.$children$ = [];
1187 }
1188 parentVNode.$children$[childVNode.$index$] = childVNode;
1189 if (shadowRootNodes && childVNode.$depth$ === '0') {
1190 shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1191 }
1192 }
1193 }
1194 else if (childVNode.$hostId$ === hostId) {
1195 // this comment node is specifcally for this host id
1196 if (childNodeType === SLOT_NODE_ID) {
1197 // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
1198 childVNode.$tag$ = 'slot';
1199 if (childIdSplt[5]) {
1200 node['s-sn'] = childVNode.$name$ = childIdSplt[5];
1201 }
1202 else {
1203 node['s-sn'] = '';
1204 }
1205 node['s-sr'] = true;
1206 slotNodes.push(childVNode);
1207 if (!parentVNode.$children$) {
1208 parentVNode.$children$ = [];
1209 }
1210 parentVNode.$children$[childVNode.$index$] = childVNode;
1211 }
1212 else if (childNodeType === CONTENT_REF_ID) {
1213 // `${CONTENT_REF_ID}.${hostId}`;
1214 {
1215 hostElm['s-cr'] = node;
1216 node['s-cn'] = true;
1217 }
1218 }
1219 }
1220 }
1221 }
1222 else if (parentVNode && parentVNode.$tag$ === 'style') {
1223 var vnode = newVNode(null, node.textContent);
1224 vnode.$elm$ = node;
1225 vnode.$index$ = '0';
1226 parentVNode.$children$ = [vnode];
1227 }
1228};
1229var initializeDocumentHydrate = function (node, orgLocNodes) {
1230 if (node.nodeType === 1 /* ElementNode */) {
1231 var i = 0;
1232 for (; i < node.childNodes.length; i++) {
1233 initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
1234 }
1235 if (node.shadowRoot) {
1236 for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
1237 initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
1238 }
1239 }
1240 }
1241 else if (node.nodeType === 8 /* CommentNode */) {
1242 var childIdSplt = node.nodeValue.split('.');
1243 if (childIdSplt[0] === ORG_LOCATION_ID) {
1244 orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
1245 node.nodeValue = '';
1246 // useful to know if the original location is
1247 // the root light-dom of a shadow dom component
1248 node['s-en'] = childIdSplt[3];
1249 }
1250 }
1251};
1252var parsePropertyValue = function (propValue, propType) {
1253 // ensure this value is of the correct prop type
1254 if (propValue != null && !isComplexType(propValue)) {
1255 if (propType & 4 /* Boolean */) {
1256 // per the HTML spec, any string value means it is a boolean true value
1257 // but we'll cheat here and say that the string "false" is the boolean false
1258 return propValue === 'false' ? false : propValue === '' || !!propValue;
1259 }
1260 if (propType & 2 /* Number */) {
1261 // force it to be a number
1262 return parseFloat(propValue);
1263 }
1264 if (propType & 1 /* String */) {
1265 // could have been passed as a number or boolean
1266 // but we still want it as a string
1267 return String(propValue);
1268 }
1269 // redundant return here for better minification
1270 return propValue;
1271 }
1272 // not sure exactly what type we want
1273 // so no need to change to a different type
1274 return propValue;
1275};
1276var getValue = function (ref, propName) { return getHostRef(ref).$instanceValues$.get(propName); };
1277var setValue = function (ref, propName, newVal, cmpMeta) {
1278 // check our new property value against our internal value
1279 var hostRef = getHostRef(ref);
1280 var oldVal = hostRef.$instanceValues$.get(propName);
1281 var flags = hostRef.$flags$;
1282 var instance = hostRef.$lazyInstance$;
1283 newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1284 if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
1285 // gadzooks! the property's value has changed!!
1286 // set our new value!
1287 hostRef.$instanceValues$.set(propName, newVal);
1288 if (instance) {
1289 if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1290 // looks like this value actually changed, so we've got work to do!
1291 // but only if we've already rendered, otherwise just chill out
1292 // queue that we need to do an update, but don't worry about queuing
1293 // up millions cuz this function ensures it only runs once
1294 scheduleUpdate(hostRef, false);
1295 }
1296 }
1297 }
1298};
1299var proxyComponent = function (Cstr, cmpMeta, flags) {
1300 if (cmpMeta.$members$) {
1301 // It's better to have a const than two Object.entries()
1302 var members = Object.entries(cmpMeta.$members$);
1303 var prototype_1 = Cstr.prototype;
1304 members.map(function (_a) {
1305 var memberName = _a[0], memberFlags = _a[1][0];
1306 if ((memberFlags & 31 /* Prop */ || ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
1307 // proxyComponent - prop
1308 Object.defineProperty(prototype_1, memberName, {
1309 get: function () {
1310 // proxyComponent, get value
1311 return getValue(this, memberName);
1312 },
1313 set: function (newValue) {
1314 // proxyComponent, set value
1315 setValue(this, memberName, newValue, cmpMeta);
1316 },
1317 configurable: true,
1318 enumerable: true,
1319 });
1320 }
1321 });
1322 if ((flags & 1 /* isElementConstructor */)) {
1323 var attrNameToPropName_1 = new Map();
1324 prototype_1.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1325 var _this = this;
1326 plt.jmp(function () {
1327 var propName = attrNameToPropName_1.get(attrName);
1328 _this[propName] = newValue === null && typeof _this[propName] === 'boolean' ? false : newValue;
1329 });
1330 };
1331 // create an array of attributes to observe
1332 // and also create a map of html attribute name to js property name
1333 Cstr.observedAttributes = members
1334 .filter(function (_a) {
1335 var _ = _a[0], m = _a[1];
1336 return m[0] & 15;
1337 } /* HasAttribute */) // filter to only keep props that should match attributes
1338 .map(function (_a) {
1339 var propName = _a[0], m = _a[1];
1340 var attrName = m[1] || propName;
1341 attrNameToPropName_1.set(attrName, propName);
1342 if (m[0] & 512 /* ReflectAttr */) {
1343 cmpMeta.$attrsToReflect$.push([propName, attrName]);
1344 }
1345 return attrName;
1346 });
1347 }
1348 }
1349 return Cstr;
1350};
1351var initializeComponent = function (elm, hostRef, cmpMeta, hmrVersionId, Cstr) { return __awaiter(void 0, void 0, void 0, function () {
1352 var endLoad, endNewInstance, style, scopeId, endRegisterStyles, ancestorComponent, schedule;
1353 return __generator(this, function (_a) {
1354 switch (_a.label) {
1355 case 0:
1356 if (!((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0)) return [3 /*break*/, 3];
1357 // we haven't initialized this element yet
1358 hostRef.$flags$ |= 32 /* hasInitializedComponent */;
1359 // lazy loaded components
1360 // request the component's implementation to be
1361 // wired up with the host element
1362 Cstr = loadModule(cmpMeta);
1363 if (!Cstr.then) return [3 /*break*/, 2];
1364 endLoad = uniqueTime();
1365 return [4 /*yield*/, Cstr];
1366 case 1:
1367 Cstr = _a.sent();
1368 endLoad();
1369 _a.label = 2;
1370 case 2:
1371 if (!Cstr.isProxied) {
1372 proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
1373 Cstr.isProxied = true;
1374 }
1375 endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1376 // ok, time to construct the instance
1377 // but let's keep track of when we start and stop
1378 // so that the getters/setters don't incorrectly step on data
1379 {
1380 hostRef.$flags$ |= 8 /* isConstructingInstance */;
1381 }
1382 // construct the lazy-loaded component implementation
1383 // passing the hostRef is very important during
1384 // construction in order to directly wire together the
1385 // host element and the lazy-loaded instance
1386 try {
1387 new Cstr(hostRef);
1388 }
1389 catch (e) {
1390 consoleError(e);
1391 }
1392 {
1393 hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1394 }
1395 endNewInstance();
1396 if (Cstr.style) {
1397 style = Cstr.style;
1398 scopeId = getScopeId(cmpMeta);
1399 if (!styles.has(scopeId)) {
1400 endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1401 registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1402 endRegisterStyles();
1403 }
1404 }
1405 _a.label = 3;
1406 case 3:
1407 ancestorComponent = hostRef.$ancestorComponent$;
1408 schedule = function () { return scheduleUpdate(hostRef, true); };
1409 if (ancestorComponent && ancestorComponent['s-rc']) {
1410 // this is the intial load and this component it has an ancestor component
1411 // but the ancestor component has NOT fired its will update lifecycle yet
1412 // so let's just cool our jets and wait for the ancestor to continue first
1413 // this will get fired off when the ancestor component
1414 // finally gets around to rendering its lazy self
1415 // fire off the initial update
1416 ancestorComponent['s-rc'].push(schedule);
1417 }
1418 else {
1419 schedule();
1420 }
1421 return [2 /*return*/];
1422 }
1423 });
1424}); };
1425var connectedCallback = function (elm) {
1426 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1427 var hostRef_1 = getHostRef(elm);
1428 var cmpMeta_1 = hostRef_1.$cmpMeta$;
1429 var endConnected = createTime('connectedCallback', cmpMeta_1.$tagName$);
1430 if (!(hostRef_1.$flags$ & 1 /* hasConnected */)) {
1431 // first time this component has connected
1432 hostRef_1.$flags$ |= 1 /* hasConnected */;
1433 var hostId = void 0;
1434 {
1435 hostId = elm.getAttribute(HYDRATE_ID);
1436 if (hostId) {
1437 initializeClientHydrate(elm, cmpMeta_1.$tagName$, hostId, hostRef_1);
1438 }
1439 }
1440 if (!hostId) {
1441 // initUpdate
1442 // if the slot polyfill is required we'll need to put some nodes
1443 // in here to act as original content anchors as we move nodes around
1444 // host element has been connected to the DOM
1445 if ((cmpMeta_1.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
1446 setContentReference(elm);
1447 }
1448 }
1449 {
1450 // find the first ancestor component (if there is one) and register
1451 // this component as one of the actively loading child components for its ancestor
1452 var ancestorComponent = elm;
1453 while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1454 // climb up the ancestors looking for the first
1455 // component that hasn't finished its lifecycle update yet
1456 if ((ancestorComponent.nodeType === 1 /* ElementNode */ && ancestorComponent.hasAttribute('s-id') && ancestorComponent['s-p']) ||
1457 ancestorComponent['s-p']) {
1458 // we found this components first ancestor component
1459 // keep a reference to this component's ancestor component
1460 attachToAncestor(hostRef_1, (hostRef_1.$ancestorComponent$ = ancestorComponent));
1461 break;
1462 }
1463 }
1464 }
1465 // Lazy properties
1466 // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1467 if (cmpMeta_1.$members$) {
1468 Object.entries(cmpMeta_1.$members$).map(function (_a) {
1469 var memberName = _a[0], memberFlags = _a[1][0];
1470 if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
1471 var value = elm[memberName];
1472 delete elm[memberName];
1473 elm[memberName] = value;
1474 }
1475 });
1476 }
1477 {
1478 // connectedCallback, taskQueue, initialLoad
1479 // angular sets attribute AFTER connectCallback
1480 // https://github.com/angular/angular/issues/18909
1481 // https://github.com/angular/angular/issues/19940
1482 nextTick(function () { return initializeComponent(elm, hostRef_1, cmpMeta_1); });
1483 }
1484 }
1485 endConnected();
1486 }
1487};
1488var setContentReference = function (elm) {
1489 // only required when we're NOT using native shadow dom (slot)
1490 // or this browser doesn't support native shadow dom
1491 // and this host element was NOT created with SSR
1492 // let's pick out the inner content for slot projection
1493 // create a node to represent where the original
1494 // content was first placed, which is useful later on
1495 var contentRefElm = (elm['s-cr'] = doc.createComment(''));
1496 contentRefElm['s-cn'] = true;
1497 elm.insertBefore(contentRefElm, elm.firstChild);
1498};
1499var disconnectedCallback = function (elm) {
1500 if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1501 var hostRef = getHostRef(elm);
1502 // clear CSS var-shim tracking
1503 if (plt.$cssShim$) {
1504 plt.$cssShim$.removeHost(elm);
1505 }
1506 }
1507};
1508var bootstrapLazy = function (lazyBundles, options) {
1509 if (options === void 0) { options = {}; }
1510 var endBootstrap = createTime();
1511 var cmpTags = [];
1512 var exclude = options.exclude || [];
1513 var customElements = win.customElements;
1514 var head = doc.head;
1515 var metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1516 var visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1517 var deferredConnectedCallbacks = [];
1518 var appLoadFallback;
1519 var isBootstrapping = true;
1520 Object.assign(plt, options);
1521 plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1522 {
1523 if (options.syncQueue) {
1524 plt.$flags$ |= 4 /* queueSync */;
1525 }
1526 }
1527 {
1528 // If the app is already hydrated there is not point to disable the
1529 // async queue. This will improve the first input delay
1530 plt.$flags$ |= 2 /* appLoaded */;
1531 }
1532 lazyBundles.map(function (lazyBundle) { return lazyBundle[1].map(function (compactMeta) {
1533 var cmpMeta = {
1534 $flags$: compactMeta[0],
1535 $tagName$: compactMeta[1],
1536 $members$: compactMeta[2],
1537 $listeners$: compactMeta[3],
1538 };
1539 {
1540 cmpMeta.$members$ = compactMeta[2];
1541 }
1542 {
1543 cmpMeta.$attrsToReflect$ = [];
1544 }
1545 var tagName = cmpMeta.$tagName$;
1546 var HostElement = /** @class */ (function (_super) {
1547 __extends(HostElement, _super);
1548 // StencilLazyHost
1549 function HostElement(self) {
1550 var _this =
1551 // @ts-ignore
1552 _super.call(this, self) || this;
1553 self = _this;
1554 registerHost(self, cmpMeta);
1555 return _this;
1556 }
1557 HostElement.prototype.connectedCallback = function () {
1558 var _this = this;
1559 if (appLoadFallback) {
1560 clearTimeout(appLoadFallback);
1561 appLoadFallback = null;
1562 }
1563 if (isBootstrapping) {
1564 // connectedCallback will be processed once all components have been registered
1565 deferredConnectedCallbacks.push(this);
1566 }
1567 else {
1568 plt.jmp(function () { return connectedCallback(_this); });
1569 }
1570 };
1571 HostElement.prototype.disconnectedCallback = function () {
1572 var _this = this;
1573 plt.jmp(function () { return disconnectedCallback(_this); });
1574 };
1575 HostElement.prototype.forceUpdate = function () {
1576 forceUpdate(this);
1577 };
1578 HostElement.prototype.componentOnReady = function () {
1579 return getHostRef(this).$onReadyPromise$;
1580 };
1581 return HostElement;
1582 }(HTMLElement));
1583 cmpMeta.$lazyBundleId$ = lazyBundle[0];
1584 if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1585 cmpTags.push(tagName);
1586 customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
1587 }
1588 }); });
1589 {
1590 visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1591 visibilityStyle.setAttribute('data-styles', '');
1592 head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1593 }
1594 // Process deferred connectedCallbacks now all components have been registered
1595 isBootstrapping = false;
1596 if (deferredConnectedCallbacks.length) {
1597 deferredConnectedCallbacks.map(function (host) { return host.connectedCallback(); });
1598 }
1599 else {
1600 {
1601 plt.jmp(function () { return (appLoadFallback = setTimeout(appDidLoad, 30)); });
1602 }
1603 }
1604 // Fallback appLoad event
1605 endBootstrap();
1606};
1607var hostRefs = new WeakMap();
1608var getHostRef = function (ref) { return hostRefs.get(ref); };
1609var registerInstance = function (lazyInstance, hostRef) { return hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef); };
1610var registerHost = function (elm, cmpMeta) {
1611 var hostRef = {
1612 $flags$: 0,
1613 $hostElement$: elm,
1614 $cmpMeta$: cmpMeta,
1615 $instanceValues$: new Map(),
1616 };
1617 {
1618 hostRef.$onReadyPromise$ = new Promise(function (r) { return (hostRef.$onReadyResolve$ = r); });
1619 elm['s-p'] = [];
1620 elm['s-rc'] = [];
1621 }
1622 return hostRefs.set(elm, hostRef);
1623};
1624var isMemberInElement = function (elm, memberName) { return memberName in elm; };
1625var consoleError = function (e) { return console.error(e); };
1626var cmpModules = /*@__PURE__*/ new Map();
1627var loadModule = function (cmpMeta, hostRef, hmrVersionId) {
1628 // loadModuleImport
1629 var exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1630 var bundleId = cmpMeta.$lazyBundleId$;
1631 var module = cmpModules.get(bundleId);
1632 if (module) {
1633 return module[exportName];
1634 }
1635 return import(
1636 /* webpackInclude: /\.entry\.js$/ */
1637 /* webpackExclude: /\.system\.entry\.js$/ */
1638 /* webpackMode: "lazy" */
1639 "./" + bundleId + ".entry.js" + '').then(function (importedModule) {
1640 {
1641 cmpModules.set(bundleId, importedModule);
1642 }
1643 return importedModule[exportName];
1644 }, consoleError);
1645};
1646var styles = new Map();
1647var queueDomReads = [];
1648var queueDomWrites = [];
1649var queueDomWritesLow = [];
1650var queueTask = function (queue, write) { return function (cb) {
1651 queue.push(cb);
1652 if (!queuePending) {
1653 queuePending = true;
1654 if (write && plt.$flags$ & 4 /* queueSync */) {
1655 nextTick(flush);
1656 }
1657 else {
1658 plt.raf(flush);
1659 }
1660 }
1661}; };
1662var consume = function (queue) {
1663 for (var i = 0; i < queue.length; i++) {
1664 try {
1665 queue[i](performance.now());
1666 }
1667 catch (e) {
1668 consoleError(e);
1669 }
1670 }
1671 queue.length = 0;
1672};
1673var consumeTimeout = function (queue, timeout) {
1674 var i = 0;
1675 var ts = 0;
1676 while (i < queue.length && (ts = performance.now()) < timeout) {
1677 try {
1678 queue[i++](ts);
1679 }
1680 catch (e) {
1681 consoleError(e);
1682 }
1683 }
1684 if (i === queue.length) {
1685 queue.length = 0;
1686 }
1687 else if (i !== 0) {
1688 queue.splice(0, i);
1689 }
1690};
1691var flush = function () {
1692 {
1693 queueCongestion++;
1694 }
1695 // always force a bunch of medium callbacks to run, but still have
1696 // a throttle on how many can run in a certain time
1697 // DOM READS!!!
1698 consume(queueDomReads);
1699 // DOM WRITES!!!
1700 {
1701 var timeout = (plt.$flags$ & 6 /* queueMask */) === 2 /* appLoaded */ ? performance.now() + 14 * Math.ceil(queueCongestion * (1.0 / 10.0)) : Infinity;
1702 consumeTimeout(queueDomWrites, timeout);
1703 consumeTimeout(queueDomWritesLow, timeout);
1704 if (queueDomWrites.length > 0) {
1705 queueDomWritesLow.push.apply(queueDomWritesLow, queueDomWrites);
1706 queueDomWrites.length = 0;
1707 }
1708 if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
1709 // still more to do yet, but we've run out of time
1710 // let's let this thing cool off and try again in the next tick
1711 plt.raf(flush);
1712 }
1713 else {
1714 queueCongestion = 0;
1715 }
1716 }
1717};
1718var nextTick = /*@__PURE__*/ function (cb) { return promiseResolve().then(cb); };
1719var writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1720export { CSS as C, Host as H, NAMESPACE as N, promiseResolve as a, bootstrapLazy as b, doc as d, h, plt as p, registerInstance as r, win as w };