UNPKG

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