UNPKG

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