bromcom-ui 2.3.60 → 2.3.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2818 @@
1
+ const NAMESPACE = 'bromcom-ui';
2
+ const BUILD = /* bromcom-ui */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: true, cmpShouldUpdate: true, cmpWillLoad: true, cmpWillRender: true, cmpWillUpdate: true, connectedCallback: true, constructableCSS: false, cssAnnotations: true, cssVarShim: false, devTools: true, disconnectedCallback: true, dynamicImportShim: false, element: false, event: true, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: false, hostListenerTargetDocument: true, hostListenerTargetParent: false, hostListenerTargetWindow: true, hotModuleReplacement: true, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: false, isDebug: false, isDev: true, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: true, mode: false, observeAttribute: true, profile: true, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, safari10: false, scoped: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, shadowDomShim: false, slot: true, slotChildNodesFix: false, slotRelocation: true, state: true, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: true, watchCallback: true };
3
+ const Env = /* bromcom-ui */ {};
4
+
5
+ let scopeId;
6
+ let contentRef;
7
+ let hostTagName;
8
+ let customError;
9
+ let i = 0;
10
+ let useNativeShadowDom = false;
11
+ let checkSlotFallbackVisibility = false;
12
+ let checkSlotRelocate = false;
13
+ let isSvgMode = false;
14
+ let renderingRef = null;
15
+ let queueCongestion = 0;
16
+ let queuePending = false;
17
+ const win = typeof window !== 'undefined' ? window : {};
18
+ const CSS = BUILD.cssVarShim ? win.CSS : null;
19
+ const doc = win.document || { head: {} };
20
+ const H = (win.HTMLElement || class {
21
+ });
22
+ const plt = {
23
+ $flags$: 0,
24
+ $resourcesUrl$: '',
25
+ jmp: h => h(),
26
+ raf: h => requestAnimationFrame(h),
27
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
28
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
29
+ ce: (eventName, opts) => new CustomEvent(eventName, opts),
30
+ };
31
+ const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)() : true;
32
+ const supportsListenerOptions = /*@__PURE__*/ (() => {
33
+ let supportsListenerOptions = false;
34
+ try {
35
+ doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
36
+ get() {
37
+ supportsListenerOptions = true;
38
+ },
39
+ }));
40
+ }
41
+ catch (e) { }
42
+ return supportsListenerOptions;
43
+ })();
44
+ const promiseResolve = (v) => Promise.resolve(v);
45
+ const supportsConstructibleStylesheets = BUILD.constructableCSS
46
+ ? /*@__PURE__*/ (() => {
47
+ try {
48
+ new CSSStyleSheet();
49
+ return true;
50
+ }
51
+ catch (e) { }
52
+ return false;
53
+ })()
54
+ : false;
55
+ const Context = {};
56
+ const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
57
+ if (BUILD.hostListener && listeners) {
58
+ // this is called immediately within the element's constructor
59
+ // initialize our event listeners on the host element
60
+ // we do this now so that we can listen to events that may
61
+ // have fired even before the instance is ready
62
+ if (BUILD.hostListenerTargetParent) {
63
+ // this component may have event listeners that should be attached to the parent
64
+ if (attachParentListeners) {
65
+ // this is being ran from within the connectedCallback
66
+ // which is important so that we know the host element actually has a parent element
67
+ // filter out the listeners to only have the ones that ARE being attached to the parent
68
+ listeners = listeners.filter(([flags]) => flags & 32 /* TargetParent */);
69
+ }
70
+ else {
71
+ // this is being ran from within the component constructor
72
+ // everything BUT the parent element listeners should be attached at this time
73
+ // filter out the listeners that are NOT being attached to the parent
74
+ listeners = listeners.filter(([flags]) => !(flags & 32 /* TargetParent */));
75
+ }
76
+ }
77
+ listeners.map(([flags, name, method]) => {
78
+ const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
79
+ const handler = hostListenerProxy(hostRef, method);
80
+ const opts = hostListenerOpts(flags);
81
+ plt.ael(target, name, handler, opts);
82
+ (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
83
+ });
84
+ }
85
+ };
86
+ const hostListenerProxy = (hostRef, methodName) => (ev) => {
87
+ try {
88
+ if (BUILD.lazyLoad) {
89
+ if (hostRef.$flags$ & 256 /* isListenReady */) {
90
+ // instance is ready, let's call it's member method for this event
91
+ hostRef.$lazyInstance$[methodName](ev);
92
+ }
93
+ else {
94
+ (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
95
+ }
96
+ }
97
+ else {
98
+ hostRef.$hostElement$[methodName](ev);
99
+ }
100
+ }
101
+ catch (e) {
102
+ consoleError(e);
103
+ }
104
+ };
105
+ const getHostListenerTarget = (elm, flags) => {
106
+ if (BUILD.hostListenerTargetDocument && flags & 4 /* TargetDocument */)
107
+ return doc;
108
+ if (BUILD.hostListenerTargetWindow && flags & 8 /* TargetWindow */)
109
+ return win;
110
+ if (BUILD.hostListenerTargetBody && flags & 16 /* TargetBody */)
111
+ return doc.body;
112
+ if (BUILD.hostListenerTargetParent && flags & 32 /* TargetParent */)
113
+ return elm.parentElement;
114
+ return elm;
115
+ };
116
+ // prettier-ignore
117
+ const hostListenerOpts = (flags) => supportsListenerOptions
118
+ ? ({
119
+ passive: (flags & 1 /* Passive */) !== 0,
120
+ capture: (flags & 2 /* Capture */) !== 0,
121
+ })
122
+ : (flags & 2 /* Capture */) !== 0;
123
+ const CONTENT_REF_ID = 'r';
124
+ const ORG_LOCATION_ID = 'o';
125
+ const SLOT_NODE_ID = 's';
126
+ const TEXT_NODE_ID = 't';
127
+ const HYDRATE_ID = 's-id';
128
+ const HYDRATED_STYLE_ID = 'sty-id';
129
+ const HYDRATE_CHILD_ID = 'c-id';
130
+ const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
131
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
132
+ const createTime = (fnName, tagName = '') => {
133
+ if (BUILD.profile && performance.mark) {
134
+ const key = `st:${fnName}:${tagName}:${i++}`;
135
+ // Start
136
+ performance.mark(key);
137
+ // End
138
+ return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
139
+ }
140
+ else {
141
+ return () => {
142
+ return;
143
+ };
144
+ }
145
+ };
146
+ const uniqueTime = (key, measureText) => {
147
+ if (BUILD.profile && performance.mark) {
148
+ if (performance.getEntriesByName(key).length === 0) {
149
+ performance.mark(key);
150
+ }
151
+ return () => {
152
+ if (performance.getEntriesByName(measureText).length === 0) {
153
+ performance.measure(measureText, key);
154
+ }
155
+ };
156
+ }
157
+ else {
158
+ return () => {
159
+ return;
160
+ };
161
+ }
162
+ };
163
+ const inspect = (ref) => {
164
+ const hostRef = getHostRef(ref);
165
+ if (!hostRef) {
166
+ return undefined;
167
+ }
168
+ const flags = hostRef.$flags$;
169
+ const hostElement = hostRef.$hostElement$;
170
+ return {
171
+ renderCount: hostRef.$renderCount$,
172
+ flags: {
173
+ hasRendered: !!(flags & 2 /* hasRendered */),
174
+ hasConnected: !!(flags & 1 /* hasConnected */),
175
+ isWaitingForChildren: !!(flags & 4 /* isWaitingForChildren */),
176
+ isConstructingInstance: !!(flags & 8 /* isConstructingInstance */),
177
+ isQueuedForUpdate: !!(flags & 16 /* isQueuedForUpdate */),
178
+ hasInitializedComponent: !!(flags & 32 /* hasInitializedComponent */),
179
+ hasLoadedComponent: !!(flags & 64 /* hasLoadedComponent */),
180
+ isWatchReady: !!(flags & 128 /* isWatchReady */),
181
+ isListenReady: !!(flags & 256 /* isListenReady */),
182
+ needsRerender: !!(flags & 512 /* needsRerender */),
183
+ },
184
+ instanceValues: hostRef.$instanceValues$,
185
+ ancestorComponent: hostRef.$ancestorComponent$,
186
+ hostElement,
187
+ lazyInstance: hostRef.$lazyInstance$,
188
+ vnode: hostRef.$vnode$,
189
+ modeName: hostRef.$modeName$,
190
+ onReadyPromise: hostRef.$onReadyPromise$,
191
+ onReadyResolve: hostRef.$onReadyResolve$,
192
+ onInstancePromise: hostRef.$onInstancePromise$,
193
+ onInstanceResolve: hostRef.$onInstanceResolve$,
194
+ onRenderResolve: hostRef.$onRenderResolve$,
195
+ queuedListeners: hostRef.$queuedListeners$,
196
+ rmListeners: hostRef.$rmListeners$,
197
+ ['s-id']: hostElement['s-id'],
198
+ ['s-cr']: hostElement['s-cr'],
199
+ ['s-lr']: hostElement['s-lr'],
200
+ ['s-p']: hostElement['s-p'],
201
+ ['s-rc']: hostElement['s-rc'],
202
+ ['s-sc']: hostElement['s-sc'],
203
+ };
204
+ };
205
+ const installDevTools = () => {
206
+ if (BUILD.devTools) {
207
+ const stencil = (win.stencil = win.stencil || {});
208
+ const originalInspect = stencil.inspect;
209
+ stencil.inspect = (ref) => {
210
+ let result = inspect(ref);
211
+ if (!result && typeof originalInspect === 'function') {
212
+ result = originalInspect(ref);
213
+ }
214
+ return result;
215
+ };
216
+ }
217
+ };
218
+ const rootAppliedStyles = new WeakMap();
219
+ const registerStyle = (scopeId, cssText, allowCS) => {
220
+ let style = styles.get(scopeId);
221
+ if (supportsConstructibleStylesheets && allowCS) {
222
+ style = (style || new CSSStyleSheet());
223
+ style.replace(cssText);
224
+ }
225
+ else {
226
+ style = cssText;
227
+ }
228
+ styles.set(scopeId, style);
229
+ };
230
+ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
231
+ let scopeId = getScopeId(cmpMeta, mode);
232
+ let style = styles.get(scopeId);
233
+ if (!BUILD.attachStyles) {
234
+ return scopeId;
235
+ }
236
+ // if an element is NOT connected then getRootNode() will return the wrong root node
237
+ // so the fallback is to always use the document for the root node in those cases
238
+ styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
239
+ if (style) {
240
+ if (typeof style === 'string') {
241
+ styleContainerNode = styleContainerNode.head || styleContainerNode;
242
+ let appliedStyles = rootAppliedStyles.get(styleContainerNode);
243
+ let styleElm;
244
+ if (!appliedStyles) {
245
+ rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
246
+ }
247
+ if (!appliedStyles.has(scopeId)) {
248
+ if (BUILD.hydrateClientSide && styleContainerNode.host && (styleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`))) {
249
+ // This is only happening on native shadow-dom, do not needs CSS var shim
250
+ styleElm.innerHTML = style;
251
+ }
252
+ else {
253
+ if (BUILD.cssVarShim && plt.$cssShim$) {
254
+ styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
255
+ const newScopeId = styleElm['s-sc'];
256
+ if (newScopeId) {
257
+ scopeId = newScopeId;
258
+ // we don't want to add this styleID to the appliedStyles Set
259
+ // since the cssVarShim might need to apply several different
260
+ // stylesheets for the same component
261
+ appliedStyles = null;
262
+ }
263
+ }
264
+ else {
265
+ styleElm = doc.createElement('style');
266
+ styleElm.innerHTML = style;
267
+ }
268
+ if (BUILD.hydrateServerSide || BUILD.hotModuleReplacement) {
269
+ styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
270
+ }
271
+ styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
272
+ }
273
+ if (appliedStyles) {
274
+ appliedStyles.add(scopeId);
275
+ }
276
+ }
277
+ }
278
+ else if (BUILD.constructableCSS && !styleContainerNode.adoptedStyleSheets.includes(style)) {
279
+ styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
280
+ }
281
+ }
282
+ return scopeId;
283
+ };
284
+ const attachStyles = (hostRef) => {
285
+ const cmpMeta = hostRef.$cmpMeta$;
286
+ const elm = hostRef.$hostElement$;
287
+ const flags = cmpMeta.$flags$;
288
+ const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
289
+ const scopeId = addStyle(BUILD.shadowDom && supportsShadow && elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
290
+ if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & 10 /* needsScopedEncapsulation */) {
291
+ // only required when we're NOT using native shadow dom (slot)
292
+ // or this browser doesn't support native shadow dom
293
+ // and this host element was NOT created with SSR
294
+ // let's pick out the inner content for slot projection
295
+ // create a node to represent where the original
296
+ // content was first placed, which is useful later on
297
+ // DOM WRITE!!
298
+ elm['s-sc'] = scopeId;
299
+ elm.classList.add(scopeId + '-h');
300
+ if (BUILD.scoped && flags & 2 /* scopedCssEncapsulation */) {
301
+ elm.classList.add(scopeId + '-s');
302
+ }
303
+ }
304
+ endAttachStyles();
305
+ };
306
+ const getScopeId = (cmp, mode) => 'sc-' + (BUILD.mode && mode && cmp.$flags$ & 32 /* hasMode */ ? cmp.$tagName$ + '-' + mode : cmp.$tagName$);
307
+ const convertScopedToShadow = (css) => css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{');
308
+ // Private
309
+ const computeMode = (elm) => modeResolutionChain.map(h => h(elm)).find(m => !!m);
310
+ // Public
311
+ const setMode = (handler) => modeResolutionChain.push(handler);
312
+ const getMode = (ref) => getHostRef(ref).$modeName$;
313
+ /**
314
+ * Default style mode id
315
+ */
316
+ /**
317
+ * Reusable empty obj/array
318
+ * Don't add values to these!!
319
+ */
320
+ const EMPTY_OBJ = {};
321
+ /**
322
+ * Namespaces
323
+ */
324
+ const SVG_NS = 'http://www.w3.org/2000/svg';
325
+ const HTML_NS = 'http://www.w3.org/1999/xhtml';
326
+ const isDef = (v) => v != null;
327
+ const isComplexType = (o) => {
328
+ // https://jsperf.com/typeof-fn-object/5
329
+ o = typeof o;
330
+ return o === 'object' || o === 'function';
331
+ };
332
+ /**
333
+ * Production h() function based on Preact by
334
+ * Jason Miller (@developit)
335
+ * Licensed under the MIT License
336
+ * https://github.com/developit/preact/blob/master/LICENSE
337
+ *
338
+ * Modified for Stencil's compiler and vdom
339
+ */
340
+ // const stack: any[] = [];
341
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
342
+ // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
343
+ const h = (nodeName, vnodeData, ...children) => {
344
+ let child = null;
345
+ let key = null;
346
+ let slotName = null;
347
+ let simple = false;
348
+ let lastSimple = false;
349
+ let vNodeChildren = [];
350
+ const walk = (c) => {
351
+ for (let i = 0; i < c.length; i++) {
352
+ child = c[i];
353
+ if (Array.isArray(child)) {
354
+ walk(child);
355
+ }
356
+ else if (child != null && typeof child !== 'boolean') {
357
+ if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
358
+ child = String(child);
359
+ }
360
+ else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
361
+ consoleDevError(`vNode passed as children has unexpected type.
362
+ Make sure it's using the correct h() function.
363
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
364
+ }
365
+ if (simple && lastSimple) {
366
+ // If the previous child was simple (string), we merge both
367
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
368
+ }
369
+ else {
370
+ // Append a new vNode, if it's text, we create a text vNode
371
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
372
+ }
373
+ lastSimple = simple;
374
+ }
375
+ }
376
+ };
377
+ walk(children);
378
+ if (vnodeData) {
379
+ if (BUILD.isDev && nodeName === 'input') {
380
+ validateInputProperties(vnodeData);
381
+ }
382
+ // normalize class / classname attributes
383
+ if (BUILD.vdomKey && vnodeData.key) {
384
+ key = vnodeData.key;
385
+ }
386
+ if (BUILD.slotRelocation && vnodeData.name) {
387
+ slotName = vnodeData.name;
388
+ }
389
+ if (BUILD.vdomClass) {
390
+ const classData = vnodeData.className || vnodeData.class;
391
+ if (classData) {
392
+ vnodeData.class =
393
+ typeof classData !== 'object'
394
+ ? classData
395
+ : Object.keys(classData)
396
+ .filter(k => classData[k])
397
+ .join(' ');
398
+ }
399
+ }
400
+ }
401
+ if (BUILD.isDev && vNodeChildren.some(isHost)) {
402
+ consoleDevError(`The <Host> must be the single root component. Make sure:
403
+ - You are NOT using hostData() and <Host> in the same component.
404
+ - <Host> is used once, and it's the single root component of the render() function.`);
405
+ }
406
+ if (BUILD.vdomFunctional && typeof nodeName === 'function') {
407
+ // nodeName is a functional component
408
+ return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
409
+ }
410
+ const vnode = newVNode(nodeName, null);
411
+ vnode.$attrs$ = vnodeData;
412
+ if (vNodeChildren.length > 0) {
413
+ vnode.$children$ = vNodeChildren;
414
+ }
415
+ if (BUILD.vdomKey) {
416
+ vnode.$key$ = key;
417
+ }
418
+ if (BUILD.slotRelocation) {
419
+ vnode.$name$ = slotName;
420
+ }
421
+ return vnode;
422
+ };
423
+ const newVNode = (tag, text) => {
424
+ const vnode = {
425
+ $flags$: 0,
426
+ $tag$: tag,
427
+ $text$: text,
428
+ $elm$: null,
429
+ $children$: null,
430
+ };
431
+ if (BUILD.vdomAttribute) {
432
+ vnode.$attrs$ = null;
433
+ }
434
+ if (BUILD.vdomKey) {
435
+ vnode.$key$ = null;
436
+ }
437
+ if (BUILD.slotRelocation) {
438
+ vnode.$name$ = null;
439
+ }
440
+ return vnode;
441
+ };
442
+ const Host = {};
443
+ const isHost = (node) => node && node.$tag$ === Host;
444
+ const vdomFnUtils = {
445
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
446
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
447
+ };
448
+ const convertToPublic = (node) => ({
449
+ vattrs: node.$attrs$,
450
+ vchildren: node.$children$,
451
+ vkey: node.$key$,
452
+ vname: node.$name$,
453
+ vtag: node.$tag$,
454
+ vtext: node.$text$,
455
+ });
456
+ const convertToPrivate = (node) => {
457
+ if (typeof node.vtag === 'function') {
458
+ const vnodeData = Object.assign({}, node.vattrs);
459
+ if (node.vkey) {
460
+ vnodeData.key = node.vkey;
461
+ }
462
+ if (node.vname) {
463
+ vnodeData.name = node.vname;
464
+ }
465
+ return h(node.vtag, vnodeData, ...(node.vchildren || []));
466
+ }
467
+ const vnode = newVNode(node.vtag, node.vtext);
468
+ vnode.$attrs$ = node.vattrs;
469
+ vnode.$children$ = node.vchildren;
470
+ vnode.$key$ = node.vkey;
471
+ vnode.$name$ = node.vname;
472
+ return vnode;
473
+ };
474
+ const validateInputProperties = (vnodeData) => {
475
+ const props = Object.keys(vnodeData);
476
+ const typeIndex = props.indexOf('type');
477
+ const minIndex = props.indexOf('min');
478
+ const maxIndex = props.indexOf('max');
479
+ const stepIndex = props.indexOf('min');
480
+ const value = props.indexOf('value');
481
+ if (value === -1) {
482
+ return;
483
+ }
484
+ if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
485
+ consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
486
+ }
487
+ };
488
+ /**
489
+ * Production setAccessor() function based on Preact by
490
+ * Jason Miller (@developit)
491
+ * Licensed under the MIT License
492
+ * https://github.com/developit/preact/blob/master/LICENSE
493
+ *
494
+ * Modified for Stencil's compiler and vdom
495
+ */
496
+ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
497
+ if (oldValue !== newValue) {
498
+ let isProp = isMemberInElement(elm, memberName);
499
+ let ln = memberName.toLowerCase();
500
+ if (BUILD.vdomClass && memberName === 'class') {
501
+ const classList = elm.classList;
502
+ const oldClasses = parseClassList(oldValue);
503
+ const newClasses = parseClassList(newValue);
504
+ classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
505
+ classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
506
+ }
507
+ else if (BUILD.vdomStyle && memberName === 'style') {
508
+ // update style attribute, css properties and values
509
+ if (BUILD.updatable) {
510
+ for (const prop in oldValue) {
511
+ if (!newValue || newValue[prop] == null) {
512
+ if (!BUILD.hydrateServerSide && prop.includes('-')) {
513
+ elm.style.removeProperty(prop);
514
+ }
515
+ else {
516
+ elm.style[prop] = '';
517
+ }
518
+ }
519
+ }
520
+ }
521
+ for (const prop in newValue) {
522
+ if (!oldValue || newValue[prop] !== oldValue[prop]) {
523
+ if (!BUILD.hydrateServerSide && prop.includes('-')) {
524
+ elm.style.setProperty(prop, newValue[prop]);
525
+ }
526
+ else {
527
+ elm.style[prop] = newValue[prop];
528
+ }
529
+ }
530
+ }
531
+ }
532
+ else if (BUILD.vdomKey && memberName === 'key')
533
+ ;
534
+ else if (BUILD.vdomRef && memberName === 'ref') {
535
+ // minifier will clean this up
536
+ if (newValue) {
537
+ newValue(elm);
538
+ }
539
+ }
540
+ else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === 'o' && memberName[1] === 'n') {
541
+ // Event Handlers
542
+ // so if the member name starts with "on" and the 3rd characters is
543
+ // a capital letter, and it's not already a member on the element,
544
+ // then we're assuming it's an event listener
545
+ if (memberName[2] === '-') {
546
+ // on- prefixed events
547
+ // allows to be explicit about the dom event to listen without any magic
548
+ // under the hood:
549
+ // <my-cmp on-click> // listens for "click"
550
+ // <my-cmp on-Click> // listens for "Click"
551
+ // <my-cmp on-ionChange> // listens for "ionChange"
552
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
553
+ memberName = memberName.slice(3);
554
+ }
555
+ else if (isMemberInElement(win, ln)) {
556
+ // standard event
557
+ // the JSX attribute could have been "onMouseOver" and the
558
+ // member name "onmouseover" is on the window's prototype
559
+ // so let's add the listener "mouseover", which is all lowercased
560
+ memberName = ln.slice(2);
561
+ }
562
+ else {
563
+ // custom event
564
+ // the JSX attribute could have been "onMyCustomEvent"
565
+ // so let's trim off the "on" prefix and lowercase the first character
566
+ // and add the listener "myCustomEvent"
567
+ // except for the first character, we keep the event name case
568
+ memberName = ln[2] + memberName.slice(3);
569
+ }
570
+ if (oldValue) {
571
+ plt.rel(elm, memberName, oldValue, false);
572
+ }
573
+ if (newValue) {
574
+ plt.ael(elm, memberName, newValue, false);
575
+ }
576
+ }
577
+ else if (BUILD.vdomPropOrAttr) {
578
+ // Set property if it exists and it's not a SVG
579
+ const isComplex = isComplexType(newValue);
580
+ if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
581
+ try {
582
+ if (!elm.tagName.includes('-')) {
583
+ let n = newValue == null ? '' : newValue;
584
+ // Workaround for Safari, moving the <input> caret when re-assigning the same valued
585
+ if (memberName === 'list') {
586
+ isProp = false;
587
+ // tslint:disable-next-line: triple-equals
588
+ }
589
+ else if (oldValue == null || elm[memberName] != n) {
590
+ elm[memberName] = n;
591
+ }
592
+ }
593
+ else {
594
+ elm[memberName] = newValue;
595
+ }
596
+ }
597
+ catch (e) { }
598
+ }
599
+ /**
600
+ * Need to manually update attribute if:
601
+ * - memberName is not an attribute
602
+ * - if we are rendering the host element in order to reflect attribute
603
+ * - if it's a SVG, since properties might not work in <svg>
604
+ * - if the newValue is null/undefined or 'false'.
605
+ */
606
+ let xlink = false;
607
+ if (BUILD.vdomXlink) {
608
+ if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
609
+ memberName = ln;
610
+ xlink = true;
611
+ }
612
+ }
613
+ if (newValue == null || newValue === false) {
614
+ if (newValue !== false || elm.getAttribute(memberName) === '') {
615
+ if (BUILD.vdomXlink && xlink) {
616
+ elm.removeAttributeNS(XLINK_NS, memberName);
617
+ }
618
+ else {
619
+ elm.removeAttribute(memberName);
620
+ }
621
+ }
622
+ }
623
+ else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
624
+ newValue = newValue === true ? '' : newValue;
625
+ if (BUILD.vdomXlink && xlink) {
626
+ elm.setAttributeNS(XLINK_NS, memberName, newValue);
627
+ }
628
+ else {
629
+ elm.setAttribute(memberName, newValue);
630
+ }
631
+ }
632
+ }
633
+ }
634
+ };
635
+ const parseClassListRegex = /\s/;
636
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
637
+ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
638
+ // if the element passed in is a shadow root, which is a document fragment
639
+ // then we want to be adding attrs/props to the shadow root's "host" element
640
+ // if it's not a shadow root, then we add attrs/props to the same element
641
+ const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
642
+ const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
643
+ const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
644
+ if (BUILD.updatable) {
645
+ // remove attributes no longer present on the vnode by setting them to undefined
646
+ for (memberName in oldVnodeAttrs) {
647
+ if (!(memberName in newVnodeAttrs)) {
648
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
649
+ }
650
+ }
651
+ }
652
+ // add new & update changed attributes
653
+ for (memberName in newVnodeAttrs) {
654
+ setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
655
+ }
656
+ };
657
+ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
658
+ // tslint:disable-next-line: prefer-const
659
+ let newVNode = newParentVNode.$children$[childIndex];
660
+ let i = 0;
661
+ let elm;
662
+ let childNode;
663
+ let oldVNode;
664
+ if (BUILD.slotRelocation && !useNativeShadowDom) {
665
+ // remember for later we need to check to relocate nodes
666
+ checkSlotRelocate = true;
667
+ if (newVNode.$tag$ === 'slot') {
668
+ if (scopeId) {
669
+ // scoped css needs to add its scoped id to the parent element
670
+ parentElm.classList.add(scopeId + '-s');
671
+ }
672
+ newVNode.$flags$ |= newVNode.$children$
673
+ ? // slot element has fallback content
674
+ 2 /* isSlotFallback */
675
+ : // slot element does not have fallback content
676
+ 1 /* isSlotReference */;
677
+ }
678
+ }
679
+ if (BUILD.isDev && newVNode.$elm$) {
680
+ consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${newVNode.$tag$}" element`} node should not be shared within the same renderer. The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be reused. For more information please see https://stenciljs.com/docs/templating-jsx#avoid-shared-jsx-nodes`);
681
+ }
682
+ if (BUILD.vdomText && newVNode.$text$ !== null) {
683
+ // create text node
684
+ elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
685
+ }
686
+ else if (BUILD.slotRelocation && newVNode.$flags$ & 1 /* isSlotReference */) {
687
+ // create a slot reference node
688
+ elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : doc.createTextNode('');
689
+ }
690
+ else {
691
+ if (BUILD.svg && !isSvgMode) {
692
+ isSvgMode = newVNode.$tag$ === 'svg';
693
+ }
694
+ // create element
695
+ elm = newVNode.$elm$ = (BUILD.svg
696
+ ? doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, BUILD.slotRelocation && newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$)
697
+ : doc.createElement(BUILD.slotRelocation && newVNode.$flags$ & 2 /* isSlotFallback */ ? 'slot-fb' : newVNode.$tag$));
698
+ if (BUILD.svg && isSvgMode && newVNode.$tag$ === 'foreignObject') {
699
+ isSvgMode = false;
700
+ }
701
+ // add css classes, attrs, props, listeners, etc.
702
+ if (BUILD.vdomAttribute) {
703
+ updateElement(null, newVNode, isSvgMode);
704
+ }
705
+ if ((BUILD.shadowDom || BUILD.scoped) && isDef(scopeId) && elm['s-si'] !== scopeId) {
706
+ // if there is a scopeId and this is the initial render
707
+ // then let's add the scopeId as a css class
708
+ elm.classList.add((elm['s-si'] = scopeId));
709
+ }
710
+ if (newVNode.$children$) {
711
+ for (i = 0; i < newVNode.$children$.length; ++i) {
712
+ // create the node
713
+ childNode = createElm(oldParentVNode, newVNode, i, elm);
714
+ // return node could have been null
715
+ if (childNode) {
716
+ // append our new node
717
+ elm.appendChild(childNode);
718
+ }
719
+ }
720
+ }
721
+ if (BUILD.svg) {
722
+ if (newVNode.$tag$ === 'svg') {
723
+ // Only reset the SVG context when we're exiting <svg> element
724
+ isSvgMode = false;
725
+ }
726
+ else if (elm.tagName === 'foreignObject') {
727
+ // Reenter SVG context when we're exiting <foreignObject> element
728
+ isSvgMode = true;
729
+ }
730
+ }
731
+ }
732
+ if (BUILD.slotRelocation) {
733
+ elm['s-hn'] = hostTagName;
734
+ if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
735
+ // remember the content reference comment
736
+ elm['s-sr'] = true;
737
+ // remember the content reference comment
738
+ elm['s-cr'] = contentRef;
739
+ // remember the slot name, or empty string for default slot
740
+ elm['s-sn'] = newVNode.$name$ || '';
741
+ // check if we've got an old vnode for this slot
742
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
743
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
744
+ // we've got an old slot vnode and the wrapper is being replaced
745
+ // so let's move the old slot content back to it's original location
746
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
747
+ }
748
+ }
749
+ }
750
+ return elm;
751
+ };
752
+ const putBackInOriginalLocation = (parentElm, recursive) => {
753
+ plt.$flags$ |= 1 /* isTmpDisconnected */;
754
+ const oldSlotChildNodes = parentElm.childNodes;
755
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
756
+ const childNode = oldSlotChildNodes[i];
757
+ if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
758
+ // // this child node in the old element is from another component
759
+ // // remove this node from the old slot's parent
760
+ // childNode.remove();
761
+ // and relocate it back to it's original location
762
+ parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
763
+ // remove the old original location comment entirely
764
+ // later on the patch function will know what to do
765
+ // and move this to the correct spot in need be
766
+ childNode['s-ol'].remove();
767
+ childNode['s-ol'] = undefined;
768
+ checkSlotRelocate = true;
769
+ }
770
+ if (recursive) {
771
+ putBackInOriginalLocation(childNode, recursive);
772
+ }
773
+ }
774
+ plt.$flags$ &= ~1 /* isTmpDisconnected */;
775
+ };
776
+ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
777
+ let containerElm = ((BUILD.slotRelocation && parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
778
+ let childNode;
779
+ if (BUILD.shadowDom && containerElm.shadowRoot && containerElm.tagName === hostTagName) {
780
+ containerElm = containerElm.shadowRoot;
781
+ }
782
+ for (; startIdx <= endIdx; ++startIdx) {
783
+ if (vnodes[startIdx]) {
784
+ childNode = createElm(null, parentVNode, startIdx, parentElm);
785
+ if (childNode) {
786
+ vnodes[startIdx].$elm$ = childNode;
787
+ containerElm.insertBefore(childNode, BUILD.slotRelocation ? referenceNode(before) : before);
788
+ }
789
+ }
790
+ }
791
+ };
792
+ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
793
+ for (; startIdx <= endIdx; ++startIdx) {
794
+ if ((vnode = vnodes[startIdx])) {
795
+ elm = vnode.$elm$;
796
+ callNodeRefs(vnode);
797
+ if (BUILD.slotRelocation) {
798
+ // we're removing this element
799
+ // so it's possible we need to show slot fallback content now
800
+ checkSlotFallbackVisibility = true;
801
+ if (elm['s-ol']) {
802
+ // remove the original location comment
803
+ elm['s-ol'].remove();
804
+ }
805
+ else {
806
+ // it's possible that child nodes of the node
807
+ // that's being removed are slot nodes
808
+ putBackInOriginalLocation(elm, true);
809
+ }
810
+ }
811
+ // remove the vnode's element from the dom
812
+ elm.remove();
813
+ }
814
+ }
815
+ };
816
+ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
817
+ let oldStartIdx = 0;
818
+ let newStartIdx = 0;
819
+ let idxInOld = 0;
820
+ let i = 0;
821
+ let oldEndIdx = oldCh.length - 1;
822
+ let oldStartVnode = oldCh[0];
823
+ let oldEndVnode = oldCh[oldEndIdx];
824
+ let newEndIdx = newCh.length - 1;
825
+ let newStartVnode = newCh[0];
826
+ let newEndVnode = newCh[newEndIdx];
827
+ let node;
828
+ let elmToMove;
829
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
830
+ if (oldStartVnode == null) {
831
+ // Vnode might have been moved left
832
+ oldStartVnode = oldCh[++oldStartIdx];
833
+ }
834
+ else if (oldEndVnode == null) {
835
+ oldEndVnode = oldCh[--oldEndIdx];
836
+ }
837
+ else if (newStartVnode == null) {
838
+ newStartVnode = newCh[++newStartIdx];
839
+ }
840
+ else if (newEndVnode == null) {
841
+ newEndVnode = newCh[--newEndIdx];
842
+ }
843
+ else if (isSameVnode(oldStartVnode, newStartVnode)) {
844
+ patch(oldStartVnode, newStartVnode);
845
+ oldStartVnode = oldCh[++oldStartIdx];
846
+ newStartVnode = newCh[++newStartIdx];
847
+ }
848
+ else if (isSameVnode(oldEndVnode, newEndVnode)) {
849
+ patch(oldEndVnode, newEndVnode);
850
+ oldEndVnode = oldCh[--oldEndIdx];
851
+ newEndVnode = newCh[--newEndIdx];
852
+ }
853
+ else if (isSameVnode(oldStartVnode, newEndVnode)) {
854
+ // Vnode moved right
855
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
856
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
857
+ }
858
+ patch(oldStartVnode, newEndVnode);
859
+ parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
860
+ oldStartVnode = oldCh[++oldStartIdx];
861
+ newEndVnode = newCh[--newEndIdx];
862
+ }
863
+ else if (isSameVnode(oldEndVnode, newStartVnode)) {
864
+ // Vnode moved left
865
+ if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
866
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
867
+ }
868
+ patch(oldEndVnode, newStartVnode);
869
+ parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
870
+ oldEndVnode = oldCh[--oldEndIdx];
871
+ newStartVnode = newCh[++newStartIdx];
872
+ }
873
+ else {
874
+ // createKeyToOldIdx
875
+ idxInOld = -1;
876
+ if (BUILD.vdomKey) {
877
+ for (i = oldStartIdx; i <= oldEndIdx; ++i) {
878
+ if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
879
+ idxInOld = i;
880
+ break;
881
+ }
882
+ }
883
+ }
884
+ if (BUILD.vdomKey && idxInOld >= 0) {
885
+ elmToMove = oldCh[idxInOld];
886
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) {
887
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
888
+ }
889
+ else {
890
+ patch(elmToMove, newStartVnode);
891
+ oldCh[idxInOld] = undefined;
892
+ node = elmToMove.$elm$;
893
+ }
894
+ newStartVnode = newCh[++newStartIdx];
895
+ }
896
+ else {
897
+ // new element
898
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
899
+ newStartVnode = newCh[++newStartIdx];
900
+ }
901
+ if (node) {
902
+ if (BUILD.slotRelocation) {
903
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
904
+ }
905
+ else {
906
+ oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
907
+ }
908
+ }
909
+ }
910
+ }
911
+ if (oldStartIdx > oldEndIdx) {
912
+ addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
913
+ }
914
+ else if (BUILD.updatable && newStartIdx > newEndIdx) {
915
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
916
+ }
917
+ };
918
+ const isSameVnode = (vnode1, vnode2) => {
919
+ // compare if two vnode to see if they're "technically" the same
920
+ // need to have the same element tag, and same key to be the same
921
+ if (vnode1.$tag$ === vnode2.$tag$) {
922
+ if (BUILD.slotRelocation && vnode1.$tag$ === 'slot') {
923
+ return vnode1.$name$ === vnode2.$name$;
924
+ }
925
+ if (BUILD.vdomKey) {
926
+ return vnode1.$key$ === vnode2.$key$;
927
+ }
928
+ return true;
929
+ }
930
+ return false;
931
+ };
932
+ const referenceNode = (node) => {
933
+ // this node was relocated to a new location in the dom
934
+ // because of some other component's slot
935
+ // but we still have an html comment in place of where
936
+ // it's original location was according to it's original vdom
937
+ return (node && node['s-ol']) || node;
938
+ };
939
+ const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
940
+ const patch = (oldVNode, newVNode) => {
941
+ const elm = (newVNode.$elm$ = oldVNode.$elm$);
942
+ const oldChildren = oldVNode.$children$;
943
+ const newChildren = newVNode.$children$;
944
+ const tag = newVNode.$tag$;
945
+ const text = newVNode.$text$;
946
+ let defaultHolder;
947
+ if (!BUILD.vdomText || text === null) {
948
+ if (BUILD.svg) {
949
+ // test if we're rendering an svg element, or still rendering nodes inside of one
950
+ // only add this to the when the compiler sees we're using an svg somewhere
951
+ isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
952
+ }
953
+ // element node
954
+ if (BUILD.vdomAttribute || BUILD.reflect) {
955
+ if (BUILD.slot && tag === 'slot')
956
+ ;
957
+ else {
958
+ // either this is the first render of an element OR it's an update
959
+ // AND we already know it's possible it could have changed
960
+ // this updates the element's css classes, attrs, props, listeners, etc.
961
+ updateElement(oldVNode, newVNode, isSvgMode);
962
+ }
963
+ }
964
+ if (BUILD.updatable && oldChildren !== null && newChildren !== null) {
965
+ // looks like there's child vnodes for both the old and new vnodes
966
+ updateChildren(elm, oldChildren, newVNode, newChildren);
967
+ }
968
+ else if (newChildren !== null) {
969
+ // no old child vnodes, but there are new child vnodes to add
970
+ if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) {
971
+ // the old vnode was text, so be sure to clear it out
972
+ elm.textContent = '';
973
+ }
974
+ // add the new vnode children
975
+ addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
976
+ }
977
+ else if (BUILD.updatable && oldChildren !== null) {
978
+ // no new child vnodes, but there are old child vnodes to remove
979
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
980
+ }
981
+ if (BUILD.svg && isSvgMode && tag === 'svg') {
982
+ isSvgMode = false;
983
+ }
984
+ }
985
+ else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm['s-cr'])) {
986
+ // this element has slotted content
987
+ defaultHolder.parentNode.textContent = text;
988
+ }
989
+ else if (BUILD.vdomText && oldVNode.$text$ !== text) {
990
+ // update the text content for the text only vnode
991
+ // and also only if the text is different than before
992
+ elm.data = text;
993
+ }
994
+ };
995
+ const updateFallbackSlotVisibility = (elm) => {
996
+ // tslint:disable-next-line: prefer-const
997
+ let childNodes = elm.childNodes;
998
+ let childNode;
999
+ let i;
1000
+ let ilen;
1001
+ let j;
1002
+ let slotNameAttr;
1003
+ let nodeType;
1004
+ for (i = 0, ilen = childNodes.length; i < ilen; i++) {
1005
+ childNode = childNodes[i];
1006
+ if (childNode.nodeType === 1 /* ElementNode */) {
1007
+ if (childNode['s-sr']) {
1008
+ // this is a slot fallback node
1009
+ // get the slot name for this slot reference node
1010
+ slotNameAttr = childNode['s-sn'];
1011
+ // by default always show a fallback slot node
1012
+ // then hide it if there are other slots in the light dom
1013
+ childNode.hidden = false;
1014
+ for (j = 0; j < ilen; j++) {
1015
+ if (childNodes[j]['s-hn'] !== childNode['s-hn']) {
1016
+ // this sibling node is from a different component
1017
+ nodeType = childNodes[j].nodeType;
1018
+ if (slotNameAttr !== '') {
1019
+ // this is a named fallback slot node
1020
+ if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
1021
+ childNode.hidden = true;
1022
+ break;
1023
+ }
1024
+ }
1025
+ else {
1026
+ // this is a default fallback slot node
1027
+ // any element or text node (with content)
1028
+ // should hide the default fallback slot node
1029
+ if (nodeType === 1 /* ElementNode */ || (nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
1030
+ childNode.hidden = true;
1031
+ break;
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ // keep drilling down
1038
+ updateFallbackSlotVisibility(childNode);
1039
+ }
1040
+ }
1041
+ };
1042
+ const relocateNodes = [];
1043
+ const relocateSlotContent = (elm) => {
1044
+ // tslint:disable-next-line: prefer-const
1045
+ let childNode;
1046
+ let node;
1047
+ let hostContentNodes;
1048
+ let slotNameAttr;
1049
+ let relocateNodeData;
1050
+ let j;
1051
+ let i = 0;
1052
+ let childNodes = elm.childNodes;
1053
+ let ilen = childNodes.length;
1054
+ for (; i < ilen; i++) {
1055
+ childNode = childNodes[i];
1056
+ if (childNode['s-sr'] && (node = childNode['s-cr'])) {
1057
+ // first got the content reference comment node
1058
+ // then we got it's parent, which is where all the host content is in now
1059
+ hostContentNodes = node.parentNode.childNodes;
1060
+ slotNameAttr = childNode['s-sn'];
1061
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
1062
+ node = hostContentNodes[j];
1063
+ if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
1064
+ // let's do some relocating to its new home
1065
+ // but never relocate a content reference node
1066
+ // that is suppose to always represent the original content location
1067
+ if (isNodeLocatedInSlot(node, slotNameAttr)) {
1068
+ // it's possible we've already decided to relocate this node
1069
+ relocateNodeData = relocateNodes.find(r => r.$nodeToRelocate$ === node);
1070
+ // made some changes to slots
1071
+ // let's make sure we also double check
1072
+ // fallbacks are correctly hidden or shown
1073
+ checkSlotFallbackVisibility = true;
1074
+ node['s-sn'] = node['s-sn'] || slotNameAttr;
1075
+ if (relocateNodeData) {
1076
+ // previously we never found a slot home for this node
1077
+ // but turns out we did, so let's remember it now
1078
+ relocateNodeData.$slotRefNode$ = childNode;
1079
+ }
1080
+ else {
1081
+ // add to our list of nodes to relocate
1082
+ relocateNodes.push({
1083
+ $slotRefNode$: childNode,
1084
+ $nodeToRelocate$: node,
1085
+ });
1086
+ }
1087
+ if (node['s-sr']) {
1088
+ relocateNodes.map(relocateNode => {
1089
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1090
+ relocateNodeData = relocateNodes.find(r => r.$nodeToRelocate$ === node);
1091
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
1092
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1093
+ }
1094
+ }
1095
+ });
1096
+ }
1097
+ }
1098
+ else if (!relocateNodes.some(r => r.$nodeToRelocate$ === node)) {
1099
+ // so far this element does not have a slot home, not setting slotRefNode on purpose
1100
+ // if we never find a home for this element then we'll need to hide it
1101
+ relocateNodes.push({
1102
+ $nodeToRelocate$: node,
1103
+ });
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+ if (childNode.nodeType === 1 /* ElementNode */) {
1109
+ relocateSlotContent(childNode);
1110
+ }
1111
+ }
1112
+ };
1113
+ const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1114
+ if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1115
+ if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1116
+ return true;
1117
+ }
1118
+ if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1119
+ return true;
1120
+ }
1121
+ return false;
1122
+ }
1123
+ if (nodeToRelocate['s-sn'] === slotNameAttr) {
1124
+ return true;
1125
+ }
1126
+ return slotNameAttr === '';
1127
+ };
1128
+ const callNodeRefs = (vNode) => {
1129
+ if (BUILD.vdomRef) {
1130
+ vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1131
+ vNode.$children$ && vNode.$children$.map(callNodeRefs);
1132
+ }
1133
+ };
1134
+ const renderVdom = (hostRef, renderFnResults) => {
1135
+ const hostElm = hostRef.$hostElement$;
1136
+ const cmpMeta = hostRef.$cmpMeta$;
1137
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1138
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1139
+ hostTagName = hostElm.tagName;
1140
+ // <Host> runtime check
1141
+ if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) {
1142
+ throw new Error(`The <Host> must be the single root component.
1143
+ Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
1144
+
1145
+ The render() function should look like this instead:
1146
+
1147
+ render() {
1148
+ // Do not return an array
1149
+ return (
1150
+ <Host>{content}</Host>
1151
+ );
1152
+ }
1153
+ `);
1154
+ }
1155
+ if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
1156
+ rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1157
+ cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
1158
+ }
1159
+ rootVnode.$tag$ = null;
1160
+ rootVnode.$flags$ |= 4 /* isHost */;
1161
+ hostRef.$vnode$ = rootVnode;
1162
+ rootVnode.$elm$ = oldVNode.$elm$ = (BUILD.shadowDom ? hostElm.shadowRoot || hostElm : hostElm);
1163
+ if (BUILD.scoped || BUILD.shadowDom) {
1164
+ scopeId = hostElm['s-sc'];
1165
+ }
1166
+ if (BUILD.slotRelocation) {
1167
+ contentRef = hostElm['s-cr'];
1168
+ useNativeShadowDom = supportsShadow && (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
1169
+ // always reset
1170
+ checkSlotFallbackVisibility = false;
1171
+ }
1172
+ // synchronous patch
1173
+ patch(oldVNode, rootVnode);
1174
+ if (BUILD.slotRelocation) {
1175
+ // while we're moving nodes around existing nodes, temporarily disable
1176
+ // the disconnectCallback from working
1177
+ plt.$flags$ |= 1 /* isTmpDisconnected */;
1178
+ if (checkSlotRelocate) {
1179
+ relocateSlotContent(rootVnode.$elm$);
1180
+ let relocateData;
1181
+ let nodeToRelocate;
1182
+ let orgLocationNode;
1183
+ let parentNodeRef;
1184
+ let insertBeforeNode;
1185
+ let refNode;
1186
+ let i = 0;
1187
+ for (; i < relocateNodes.length; i++) {
1188
+ relocateData = relocateNodes[i];
1189
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1190
+ if (!nodeToRelocate['s-ol']) {
1191
+ // add a reference node marking this node's original location
1192
+ // keep a reference to this node for later lookups
1193
+ orgLocationNode = BUILD.isDebug || BUILD.hydrateServerSide ? originalLocationDebugNode(nodeToRelocate) : doc.createTextNode('');
1194
+ orgLocationNode['s-nr'] = nodeToRelocate;
1195
+ nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1196
+ }
1197
+ }
1198
+ for (i = 0; i < relocateNodes.length; i++) {
1199
+ relocateData = relocateNodes[i];
1200
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1201
+ if (relocateData.$slotRefNode$) {
1202
+ // by default we're just going to insert it directly
1203
+ // after the slot reference node
1204
+ parentNodeRef = relocateData.$slotRefNode$.parentNode;
1205
+ insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1206
+ orgLocationNode = nodeToRelocate['s-ol'];
1207
+ while ((orgLocationNode = orgLocationNode.previousSibling)) {
1208
+ refNode = orgLocationNode['s-nr'];
1209
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1210
+ refNode = refNode.nextSibling;
1211
+ if (!refNode || !refNode['s-nr']) {
1212
+ insertBeforeNode = refNode;
1213
+ break;
1214
+ }
1215
+ }
1216
+ }
1217
+ if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) || nodeToRelocate.nextSibling !== insertBeforeNode) {
1218
+ // we've checked that it's worth while to relocate
1219
+ // since that the node to relocate
1220
+ // has a different next sibling or parent relocated
1221
+ if (nodeToRelocate !== insertBeforeNode) {
1222
+ if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1223
+ // probably a component in the index.html that doesn't have it's hostname set
1224
+ nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1225
+ }
1226
+ // add it back to the dom but in its new home
1227
+ parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1228
+ }
1229
+ }
1230
+ }
1231
+ else {
1232
+ // this node doesn't have a slot home to go to, so let's hide it
1233
+ if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
1234
+ nodeToRelocate.hidden = true;
1235
+ }
1236
+ }
1237
+ }
1238
+ }
1239
+ if (checkSlotFallbackVisibility) {
1240
+ updateFallbackSlotVisibility(rootVnode.$elm$);
1241
+ }
1242
+ // done moving nodes around
1243
+ // allow the disconnect callback to work again
1244
+ plt.$flags$ &= ~1 /* isTmpDisconnected */;
1245
+ // always reset
1246
+ relocateNodes.length = 0;
1247
+ }
1248
+ };
1249
+ // slot comment debug nodes only created with the `--debug` flag
1250
+ // otherwise these nodes are text nodes w/out content
1251
+ const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
1252
+ const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})` : `[${nodeToRelocate.textContent}]`));
1253
+ const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
1254
+ const createEvent = (ref, name, flags) => {
1255
+ const elm = getElement(ref);
1256
+ return {
1257
+ emit: (detail) => {
1258
+ if (BUILD.isDev && !elm.isConnected) {
1259
+ consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
1260
+ }
1261
+ return emitEvent(elm, name, {
1262
+ bubbles: !!(flags & 4 /* Bubbles */),
1263
+ composed: !!(flags & 2 /* Composed */),
1264
+ cancelable: !!(flags & 1 /* Cancellable */),
1265
+ detail,
1266
+ });
1267
+ },
1268
+ };
1269
+ };
1270
+ const emitEvent = (elm, name, opts) => {
1271
+ const ev = plt.ce(name, opts);
1272
+ elm.dispatchEvent(ev);
1273
+ return ev;
1274
+ };
1275
+ const attachToAncestor = (hostRef, ancestorComponent) => {
1276
+ if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1277
+ ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
1278
+ }
1279
+ };
1280
+ const scheduleUpdate = (hostRef, isInitialLoad) => {
1281
+ if (BUILD.taskQueue && BUILD.updatable) {
1282
+ hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
1283
+ }
1284
+ if (BUILD.asyncLoading && hostRef.$flags$ & 4 /* isWaitingForChildren */) {
1285
+ hostRef.$flags$ |= 512 /* needsRerender */;
1286
+ return;
1287
+ }
1288
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1289
+ // there is no ancestor component or the ancestor component
1290
+ // has already fired off its lifecycle update then
1291
+ // fire off the initial update
1292
+ const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1293
+ return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
1294
+ };
1295
+ const dispatchHooks = (hostRef, isInitialLoad) => {
1296
+ const elm = hostRef.$hostElement$;
1297
+ const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1298
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1299
+ let promise;
1300
+ if (isInitialLoad) {
1301
+ if (BUILD.lazyLoad && BUILD.hostListener) {
1302
+ hostRef.$flags$ |= 256 /* isListenReady */;
1303
+ if (hostRef.$queuedListeners$) {
1304
+ hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1305
+ hostRef.$queuedListeners$ = null;
1306
+ }
1307
+ }
1308
+ emitLifecycleEvent(elm, 'componentWillLoad');
1309
+ if (BUILD.cmpWillLoad) {
1310
+ promise = safeCall(instance, 'componentWillLoad');
1311
+ }
1312
+ }
1313
+ else {
1314
+ emitLifecycleEvent(elm, 'componentWillUpdate');
1315
+ if (BUILD.cmpWillUpdate) {
1316
+ promise = safeCall(instance, 'componentWillUpdate');
1317
+ }
1318
+ }
1319
+ emitLifecycleEvent(elm, 'componentWillRender');
1320
+ if (BUILD.cmpWillRender) {
1321
+ promise = then(promise, () => safeCall(instance, 'componentWillRender'));
1322
+ }
1323
+ endSchedule();
1324
+ return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
1325
+ };
1326
+ const updateComponent = async (hostRef, instance, isInitialLoad) => {
1327
+ // updateComponent
1328
+ const elm = hostRef.$hostElement$;
1329
+ const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1330
+ const rc = elm['s-rc'];
1331
+ if (BUILD.style && isInitialLoad) {
1332
+ // DOM WRITE!
1333
+ attachStyles(hostRef);
1334
+ }
1335
+ const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1336
+ if (BUILD.isDev) {
1337
+ hostRef.$flags$ |= 1024 /* devOnRender */;
1338
+ }
1339
+ if (BUILD.hasRenderFn || BUILD.reflect) {
1340
+ if (BUILD.vdomRender || BUILD.reflect) {
1341
+ // looks like we've got child nodes to render into this host element
1342
+ // or we need to update the css class/attrs on the host element
1343
+ // DOM WRITE!
1344
+ if (BUILD.hydrateServerSide) {
1345
+ renderVdom(hostRef, await callRender(hostRef, instance));
1346
+ }
1347
+ else {
1348
+ renderVdom(hostRef, callRender(hostRef, instance));
1349
+ }
1350
+ }
1351
+ else {
1352
+ elm.textContent = callRender(hostRef, instance);
1353
+ }
1354
+ }
1355
+ if (BUILD.cssVarShim && plt.$cssShim$) {
1356
+ plt.$cssShim$.updateHost(elm);
1357
+ }
1358
+ if (BUILD.isDev) {
1359
+ hostRef.$renderCount$++;
1360
+ hostRef.$flags$ &= ~1024 /* devOnRender */;
1361
+ }
1362
+ if (BUILD.hydrateServerSide) {
1363
+ try {
1364
+ // manually connected child components during server-side hydrate
1365
+ serverSideConnected(elm);
1366
+ if (isInitialLoad) {
1367
+ // using only during server-side hydrate
1368
+ if (hostRef.$cmpMeta$.$flags$ & 1 /* shadowDomEncapsulation */) {
1369
+ elm['s-en'] = '';
1370
+ }
1371
+ else if (hostRef.$cmpMeta$.$flags$ & 2 /* scopedCssEncapsulation */) {
1372
+ elm['s-en'] = 'c';
1373
+ }
1374
+ }
1375
+ }
1376
+ catch (e) {
1377
+ consoleError(e, elm);
1378
+ }
1379
+ }
1380
+ if (BUILD.asyncLoading && rc) {
1381
+ // ok, so turns out there are some child host elements
1382
+ // waiting on this parent element to load
1383
+ // let's fire off all update callbacks waiting
1384
+ rc.map(cb => cb());
1385
+ elm['s-rc'] = undefined;
1386
+ }
1387
+ endRender();
1388
+ endUpdate();
1389
+ if (BUILD.asyncLoading) {
1390
+ const childrenPromises = elm['s-p'];
1391
+ const postUpdate = () => postUpdateComponent(hostRef);
1392
+ if (childrenPromises.length === 0) {
1393
+ postUpdate();
1394
+ }
1395
+ else {
1396
+ Promise.all(childrenPromises).then(postUpdate);
1397
+ hostRef.$flags$ |= 4 /* isWaitingForChildren */;
1398
+ childrenPromises.length = 0;
1399
+ }
1400
+ }
1401
+ else {
1402
+ postUpdateComponent(hostRef);
1403
+ }
1404
+ };
1405
+ const callRender = (hostRef, instance) => {
1406
+ // in order for bundlers to correctly treeshake the BUILD object
1407
+ // we need to ensure BUILD is not deoptimized within a try/catch
1408
+ // https://rollupjs.org/guide/en/#treeshake tryCatchDeoptimization
1409
+ const allRenderFn = BUILD.allRenderFn ? true : false;
1410
+ const lazyLoad = BUILD.lazyLoad ? true : false;
1411
+ const taskQueue = BUILD.taskQueue ? true : false;
1412
+ const updatable = BUILD.updatable ? true : false;
1413
+ try {
1414
+ renderingRef = instance;
1415
+ instance = allRenderFn ? instance.render() : instance.render && instance.render();
1416
+ if (updatable && taskQueue) {
1417
+ hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
1418
+ }
1419
+ if (updatable || lazyLoad) {
1420
+ hostRef.$flags$ |= 2 /* hasRendered */;
1421
+ }
1422
+ }
1423
+ catch (e) {
1424
+ consoleError(e, hostRef.$hostElement$);
1425
+ }
1426
+ renderingRef = null;
1427
+ return instance;
1428
+ };
1429
+ const getRenderingRef = () => renderingRef;
1430
+ const postUpdateComponent = (hostRef) => {
1431
+ const tagName = hostRef.$cmpMeta$.$tagName$;
1432
+ const elm = hostRef.$hostElement$;
1433
+ const endPostUpdate = createTime('postUpdate', tagName);
1434
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1435
+ const ancestorComponent = hostRef.$ancestorComponent$;
1436
+ if (BUILD.cmpDidRender) {
1437
+ if (BUILD.isDev) {
1438
+ hostRef.$flags$ |= 1024 /* devOnRender */;
1439
+ }
1440
+ safeCall(instance, 'componentDidRender');
1441
+ if (BUILD.isDev) {
1442
+ hostRef.$flags$ &= ~1024 /* devOnRender */;
1443
+ }
1444
+ }
1445
+ emitLifecycleEvent(elm, 'componentDidRender');
1446
+ if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
1447
+ hostRef.$flags$ |= 64 /* hasLoadedComponent */;
1448
+ if (BUILD.asyncLoading && BUILD.cssAnnotations) {
1449
+ // DOM WRITE!
1450
+ addHydratedFlag(elm);
1451
+ }
1452
+ if (BUILD.cmpDidLoad) {
1453
+ if (BUILD.isDev) {
1454
+ hostRef.$flags$ |= 2048 /* devOnDidLoad */;
1455
+ }
1456
+ safeCall(instance, 'componentDidLoad');
1457
+ if (BUILD.isDev) {
1458
+ hostRef.$flags$ &= ~2048 /* devOnDidLoad */;
1459
+ }
1460
+ }
1461
+ emitLifecycleEvent(elm, 'componentDidLoad');
1462
+ endPostUpdate();
1463
+ if (BUILD.asyncLoading) {
1464
+ hostRef.$onReadyResolve$(elm);
1465
+ if (!ancestorComponent) {
1466
+ appDidLoad(tagName);
1467
+ }
1468
+ }
1469
+ }
1470
+ else {
1471
+ if (BUILD.cmpDidUpdate) {
1472
+ // we've already loaded this component
1473
+ // fire off the user's componentDidUpdate method (if one was provided)
1474
+ // componentDidUpdate runs AFTER render() has been called
1475
+ // and all child components have finished updating
1476
+ if (BUILD.isDev) {
1477
+ hostRef.$flags$ |= 1024 /* devOnRender */;
1478
+ }
1479
+ safeCall(instance, 'componentDidUpdate');
1480
+ if (BUILD.isDev) {
1481
+ hostRef.$flags$ &= ~1024 /* devOnRender */;
1482
+ }
1483
+ }
1484
+ emitLifecycleEvent(elm, 'componentDidUpdate');
1485
+ endPostUpdate();
1486
+ }
1487
+ if (BUILD.hotModuleReplacement) {
1488
+ elm['s-hmr-load'] && elm['s-hmr-load']();
1489
+ }
1490
+ if (BUILD.method && BUILD.lazyLoad) {
1491
+ hostRef.$onInstanceResolve$(elm);
1492
+ }
1493
+ // load events fire from bottom to top
1494
+ // the deepest elements load first then bubbles up
1495
+ if (BUILD.asyncLoading) {
1496
+ if (hostRef.$onRenderResolve$) {
1497
+ hostRef.$onRenderResolve$();
1498
+ hostRef.$onRenderResolve$ = undefined;
1499
+ }
1500
+ if (hostRef.$flags$ & 512 /* needsRerender */) {
1501
+ nextTick(() => scheduleUpdate(hostRef, false));
1502
+ }
1503
+ hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
1504
+ }
1505
+ // ( •_•)
1506
+ // ( •_•)>⌐■-■
1507
+ // (⌐■_■)
1508
+ };
1509
+ const forceUpdate = (ref) => {
1510
+ if (BUILD.updatable) {
1511
+ const hostRef = getHostRef(ref);
1512
+ const isConnected = hostRef.$hostElement$.isConnected;
1513
+ if (isConnected && (hostRef.$flags$ & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1514
+ scheduleUpdate(hostRef, false);
1515
+ }
1516
+ // Returns "true" when the forced update was successfully scheduled
1517
+ return isConnected;
1518
+ }
1519
+ return false;
1520
+ };
1521
+ const appDidLoad = (who) => {
1522
+ // on appload
1523
+ // we have finish the first big initial render
1524
+ if (BUILD.cssAnnotations) {
1525
+ addHydratedFlag(doc.documentElement);
1526
+ }
1527
+ if (BUILD.asyncQueue) {
1528
+ plt.$flags$ |= 2 /* appLoaded */;
1529
+ }
1530
+ nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1531
+ if (BUILD.profile && performance.measure) {
1532
+ performance.measure(`[Stencil] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
1533
+ }
1534
+ };
1535
+ const safeCall = (instance, method, arg) => {
1536
+ if (instance && instance[method]) {
1537
+ try {
1538
+ return instance[method](arg);
1539
+ }
1540
+ catch (e) {
1541
+ consoleError(e);
1542
+ }
1543
+ }
1544
+ return undefined;
1545
+ };
1546
+ const then = (promise, thenFn) => {
1547
+ return promise && promise.then ? promise.then(thenFn) : thenFn();
1548
+ };
1549
+ const emitLifecycleEvent = (elm, lifecycleName) => {
1550
+ if (BUILD.lifecycleDOMEvents) {
1551
+ emitEvent(elm, 'stencil_' + lifecycleName, {
1552
+ bubbles: true,
1553
+ composed: true,
1554
+ detail: {
1555
+ namespace: NAMESPACE,
1556
+ },
1557
+ });
1558
+ }
1559
+ };
1560
+ const addHydratedFlag = (elm) => (BUILD.hydratedClass ? elm.classList.add('hydrated') : BUILD.hydratedAttribute ? elm.setAttribute('hydrated', '') : undefined);
1561
+ const serverSideConnected = (elm) => {
1562
+ const children = elm.children;
1563
+ if (children != null) {
1564
+ for (let i = 0, ii = children.length; i < ii; i++) {
1565
+ const childElm = children[i];
1566
+ if (typeof childElm.connectedCallback === 'function') {
1567
+ childElm.connectedCallback();
1568
+ }
1569
+ serverSideConnected(childElm);
1570
+ }
1571
+ }
1572
+ };
1573
+ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
1574
+ const endHydrate = createTime('hydrateClient', tagName);
1575
+ const shadowRoot = hostElm.shadowRoot;
1576
+ const childRenderNodes = [];
1577
+ const slotNodes = [];
1578
+ const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
1579
+ const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
1580
+ if (!plt.$orgLocNodes$) {
1581
+ initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
1582
+ }
1583
+ hostElm[HYDRATE_ID] = hostId;
1584
+ hostElm.removeAttribute(HYDRATE_ID);
1585
+ clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
1586
+ childRenderNodes.map(c => {
1587
+ const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
1588
+ const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
1589
+ const node = c.$elm$;
1590
+ if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
1591
+ orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
1592
+ }
1593
+ if (!shadowRoot) {
1594
+ node['s-hn'] = tagName;
1595
+ if (orgLocationNode) {
1596
+ node['s-ol'] = orgLocationNode;
1597
+ node['s-ol']['s-nr'] = node;
1598
+ }
1599
+ }
1600
+ plt.$orgLocNodes$.delete(orgLocationId);
1601
+ });
1602
+ if (BUILD.shadowDom && shadowRoot) {
1603
+ shadowRootNodes.map(shadowRootNode => {
1604
+ if (shadowRootNode) {
1605
+ shadowRoot.appendChild(shadowRootNode);
1606
+ }
1607
+ });
1608
+ }
1609
+ endHydrate();
1610
+ };
1611
+ const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
1612
+ let childNodeType;
1613
+ let childIdSplt;
1614
+ let childVNode;
1615
+ let i;
1616
+ if (node.nodeType === 1 /* ElementNode */) {
1617
+ childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
1618
+ if (childNodeType) {
1619
+ // got the node data from the element's attribute
1620
+ // `${hostId}.${nodeId}.${depth}.${index}`
1621
+ childIdSplt = childNodeType.split('.');
1622
+ if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
1623
+ childVNode = {
1624
+ $flags$: 0,
1625
+ $hostId$: childIdSplt[0],
1626
+ $nodeId$: childIdSplt[1],
1627
+ $depth$: childIdSplt[2],
1628
+ $index$: childIdSplt[3],
1629
+ $tag$: node.tagName.toLowerCase(),
1630
+ $elm$: node,
1631
+ $attrs$: null,
1632
+ $children$: null,
1633
+ $key$: null,
1634
+ $name$: null,
1635
+ $text$: null,
1636
+ };
1637
+ childRenderNodes.push(childVNode);
1638
+ node.removeAttribute(HYDRATE_CHILD_ID);
1639
+ // this is a new child vnode
1640
+ // so ensure its parent vnode has the vchildren array
1641
+ if (!parentVNode.$children$) {
1642
+ parentVNode.$children$ = [];
1643
+ }
1644
+ // add our child vnode to a specific index of the vnode's children
1645
+ parentVNode.$children$[childVNode.$index$] = childVNode;
1646
+ // this is now the new parent vnode for all the next child checks
1647
+ parentVNode = childVNode;
1648
+ if (shadowRootNodes && childVNode.$depth$ === '0') {
1649
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1650
+ }
1651
+ }
1652
+ }
1653
+ // recursively drill down, end to start so we can remove nodes
1654
+ for (i = node.childNodes.length - 1; i >= 0; i--) {
1655
+ clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
1656
+ }
1657
+ if (node.shadowRoot) {
1658
+ // keep drilling down through the shadow root nodes
1659
+ for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
1660
+ clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
1661
+ }
1662
+ }
1663
+ }
1664
+ else if (node.nodeType === 8 /* CommentNode */) {
1665
+ // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
1666
+ childIdSplt = node.nodeValue.split('.');
1667
+ if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
1668
+ // comment node for either the host id or a 0 host id
1669
+ childNodeType = childIdSplt[0];
1670
+ childVNode = {
1671
+ $flags$: 0,
1672
+ $hostId$: childIdSplt[1],
1673
+ $nodeId$: childIdSplt[2],
1674
+ $depth$: childIdSplt[3],
1675
+ $index$: childIdSplt[4],
1676
+ $elm$: node,
1677
+ $attrs$: null,
1678
+ $children$: null,
1679
+ $key$: null,
1680
+ $name$: null,
1681
+ $tag$: null,
1682
+ $text$: null,
1683
+ };
1684
+ if (childNodeType === TEXT_NODE_ID) {
1685
+ childVNode.$elm$ = node.nextSibling;
1686
+ if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* TextNode */) {
1687
+ childVNode.$text$ = childVNode.$elm$.textContent;
1688
+ childRenderNodes.push(childVNode);
1689
+ // remove the text comment since it's no longer needed
1690
+ node.remove();
1691
+ if (!parentVNode.$children$) {
1692
+ parentVNode.$children$ = [];
1693
+ }
1694
+ parentVNode.$children$[childVNode.$index$] = childVNode;
1695
+ if (shadowRootNodes && childVNode.$depth$ === '0') {
1696
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1697
+ }
1698
+ }
1699
+ }
1700
+ else if (childVNode.$hostId$ === hostId) {
1701
+ // this comment node is specifcally for this host id
1702
+ if (childNodeType === SLOT_NODE_ID) {
1703
+ // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
1704
+ childVNode.$tag$ = 'slot';
1705
+ if (childIdSplt[5]) {
1706
+ node['s-sn'] = childVNode.$name$ = childIdSplt[5];
1707
+ }
1708
+ else {
1709
+ node['s-sn'] = '';
1710
+ }
1711
+ node['s-sr'] = true;
1712
+ if (BUILD.shadowDom && shadowRootNodes) {
1713
+ // browser support shadowRoot and this is a shadow dom component
1714
+ // create an actual slot element
1715
+ childVNode.$elm$ = doc.createElement(childVNode.$tag$);
1716
+ if (childVNode.$name$) {
1717
+ // add the slot name attribute
1718
+ childVNode.$elm$.setAttribute('name', childVNode.$name$);
1719
+ }
1720
+ // insert the new slot element before the slot comment
1721
+ node.parentNode.insertBefore(childVNode.$elm$, node);
1722
+ // remove the slot comment since it's not needed for shadow
1723
+ node.remove();
1724
+ if (childVNode.$depth$ === '0') {
1725
+ shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
1726
+ }
1727
+ }
1728
+ slotNodes.push(childVNode);
1729
+ if (!parentVNode.$children$) {
1730
+ parentVNode.$children$ = [];
1731
+ }
1732
+ parentVNode.$children$[childVNode.$index$] = childVNode;
1733
+ }
1734
+ else if (childNodeType === CONTENT_REF_ID) {
1735
+ // `${CONTENT_REF_ID}.${hostId}`;
1736
+ if (BUILD.shadowDom && shadowRootNodes) {
1737
+ // remove the content ref comment since it's not needed for shadow
1738
+ node.remove();
1739
+ }
1740
+ else if (BUILD.slotRelocation) {
1741
+ hostElm['s-cr'] = node;
1742
+ node['s-cn'] = true;
1743
+ }
1744
+ }
1745
+ }
1746
+ }
1747
+ }
1748
+ else if (parentVNode && parentVNode.$tag$ === 'style') {
1749
+ const vnode = newVNode(null, node.textContent);
1750
+ vnode.$elm$ = node;
1751
+ vnode.$index$ = '0';
1752
+ parentVNode.$children$ = [vnode];
1753
+ }
1754
+ };
1755
+ const initializeDocumentHydrate = (node, orgLocNodes) => {
1756
+ if (node.nodeType === 1 /* ElementNode */) {
1757
+ let i = 0;
1758
+ for (; i < node.childNodes.length; i++) {
1759
+ initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
1760
+ }
1761
+ if (node.shadowRoot) {
1762
+ for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
1763
+ initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
1764
+ }
1765
+ }
1766
+ }
1767
+ else if (node.nodeType === 8 /* CommentNode */) {
1768
+ const childIdSplt = node.nodeValue.split('.');
1769
+ if (childIdSplt[0] === ORG_LOCATION_ID) {
1770
+ orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
1771
+ node.nodeValue = '';
1772
+ // useful to know if the original location is
1773
+ // the root light-dom of a shadow dom component
1774
+ node['s-en'] = childIdSplt[3];
1775
+ }
1776
+ }
1777
+ };
1778
+ const parsePropertyValue = (propValue, propType) => {
1779
+ // ensure this value is of the correct prop type
1780
+ if (propValue != null && !isComplexType(propValue)) {
1781
+ if (BUILD.propBoolean && propType & 4 /* Boolean */) {
1782
+ // per the HTML spec, any string value means it is a boolean true value
1783
+ // but we'll cheat here and say that the string "false" is the boolean false
1784
+ return propValue === 'false' ? false : propValue === '' || !!propValue;
1785
+ }
1786
+ if (BUILD.propNumber && propType & 2 /* Number */) {
1787
+ // force it to be a number
1788
+ return parseFloat(propValue);
1789
+ }
1790
+ if (BUILD.propString && propType & 1 /* String */) {
1791
+ // could have been passed as a number or boolean
1792
+ // but we still want it as a string
1793
+ return String(propValue);
1794
+ }
1795
+ // redundant return here for better minification
1796
+ return propValue;
1797
+ }
1798
+ // not sure exactly what type we want
1799
+ // so no need to change to a different type
1800
+ return propValue;
1801
+ };
1802
+ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1803
+ const setValue = (ref, propName, newVal, cmpMeta) => {
1804
+ // check our new property value against our internal value
1805
+ const hostRef = getHostRef(ref);
1806
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
1807
+ const oldVal = hostRef.$instanceValues$.get(propName);
1808
+ const flags = hostRef.$flags$;
1809
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1810
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1811
+ if ((!BUILD.lazyLoad || !(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
1812
+ // gadzooks! the property's value has changed!!
1813
+ // set our new value!
1814
+ hostRef.$instanceValues$.set(propName, newVal);
1815
+ if (BUILD.isDev) {
1816
+ if (hostRef.$flags$ & 1024 /* devOnRender */) {
1817
+ consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1818
+ }
1819
+ else if (hostRef.$flags$ & 2048 /* devOnDidLoad */) {
1820
+ consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1821
+ }
1822
+ }
1823
+ if (!BUILD.lazyLoad || instance) {
1824
+ // get an array of method names of watch functions to call
1825
+ if (BUILD.watchCallback && cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
1826
+ const watchMethods = cmpMeta.$watchers$[propName];
1827
+ if (watchMethods) {
1828
+ // this instance is watching for when this property changed
1829
+ watchMethods.map(watchMethodName => {
1830
+ try {
1831
+ // fire off each of the watch methods that are watching this property
1832
+ instance[watchMethodName](newVal, oldVal, propName);
1833
+ }
1834
+ catch (e) {
1835
+ consoleError(e, elm);
1836
+ }
1837
+ });
1838
+ }
1839
+ }
1840
+ if (BUILD.updatable && (flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
1841
+ if (BUILD.cmpShouldUpdate && instance.componentShouldUpdate) {
1842
+ if (instance.componentShouldUpdate(newVal, oldVal, propName) === false) {
1843
+ return;
1844
+ }
1845
+ }
1846
+ // looks like this value actually changed, so we've got work to do!
1847
+ // but only if we've already rendered, otherwise just chill out
1848
+ // queue that we need to do an update, but don't worry about queuing
1849
+ // up millions cuz this function ensures it only runs once
1850
+ scheduleUpdate(hostRef, false);
1851
+ }
1852
+ }
1853
+ }
1854
+ };
1855
+ const proxyComponent = (Cstr, cmpMeta, flags) => {
1856
+ if (BUILD.member && cmpMeta.$members$) {
1857
+ if (BUILD.watchCallback && Cstr.watchers) {
1858
+ cmpMeta.$watchers$ = Cstr.watchers;
1859
+ }
1860
+ // It's better to have a const than two Object.entries()
1861
+ const members = Object.entries(cmpMeta.$members$);
1862
+ const prototype = Cstr.prototype;
1863
+ members.map(([memberName, [memberFlags]]) => {
1864
+ if ((BUILD.prop || BUILD.state) && (memberFlags & 31 /* Prop */ || ((!BUILD.lazyLoad || flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
1865
+ // proxyComponent - prop
1866
+ Object.defineProperty(prototype, memberName, {
1867
+ get() {
1868
+ // proxyComponent, get value
1869
+ return getValue(this, memberName);
1870
+ },
1871
+ set(newValue) {
1872
+ if (
1873
+ // only during dev time
1874
+ BUILD.isDev &&
1875
+ // we are proxing the instance (not element)
1876
+ (flags & 1 /* isElementConstructor */) === 0 &&
1877
+ // the member is a non-mutable prop
1878
+ (memberFlags & (31 /* Prop */ | 1024 /* Mutable */)) === 31 /* Prop */) {
1879
+ consoleDevWarn(`@Prop() "${memberName}" on "${cmpMeta.$tagName$}" cannot be modified.\nFurther information: https://stenciljs.com/docs/properties#prop-mutability`);
1880
+ }
1881
+ // proxyComponent, set value
1882
+ setValue(this, memberName, newValue, cmpMeta);
1883
+ },
1884
+ configurable: true,
1885
+ enumerable: true,
1886
+ });
1887
+ }
1888
+ else if (BUILD.lazyLoad && BUILD.method && flags & 1 /* isElementConstructor */ && memberFlags & 64 /* Method */) {
1889
+ // proxyComponent - method
1890
+ Object.defineProperty(prototype, memberName, {
1891
+ value(...args) {
1892
+ const ref = getHostRef(this);
1893
+ return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
1894
+ },
1895
+ });
1896
+ }
1897
+ });
1898
+ if (BUILD.observeAttribute && (!BUILD.lazyLoad || flags & 1 /* isElementConstructor */)) {
1899
+ const attrNameToPropName = new Map();
1900
+ prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1901
+ plt.jmp(() => {
1902
+ const propName = attrNameToPropName.get(attrName);
1903
+ this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1904
+ });
1905
+ };
1906
+ // create an array of attributes to observe
1907
+ // and also create a map of html attribute name to js property name
1908
+ Cstr.observedAttributes = members
1909
+ .filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
1910
+ .map(([propName, m]) => {
1911
+ const attrName = m[1] || propName;
1912
+ attrNameToPropName.set(attrName, propName);
1913
+ if (BUILD.reflect && m[0] & 512 /* ReflectAttr */) {
1914
+ cmpMeta.$attrsToReflect$.push([propName, attrName]);
1915
+ }
1916
+ return attrName;
1917
+ });
1918
+ }
1919
+ }
1920
+ return Cstr;
1921
+ };
1922
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1923
+ // initializeComponent
1924
+ if ((BUILD.lazyLoad || BUILD.hydrateServerSide || BUILD.style) && (hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
1925
+ if (BUILD.lazyLoad || BUILD.hydrateClientSide) {
1926
+ // we haven't initialized this element yet
1927
+ hostRef.$flags$ |= 32 /* hasInitializedComponent */;
1928
+ // lazy loaded components
1929
+ // request the component's implementation to be
1930
+ // wired up with the host element
1931
+ Cstr = loadModule(cmpMeta, hostRef, hmrVersionId);
1932
+ if (Cstr.then) {
1933
+ // Await creates a micro-task avoid if possible
1934
+ const endLoad = uniqueTime(`st:load:${cmpMeta.$tagName$}:${hostRef.$modeName$}`, `[Stencil] Load module for <${cmpMeta.$tagName$}>`);
1935
+ Cstr = await Cstr;
1936
+ endLoad();
1937
+ }
1938
+ if ((BUILD.isDev || BUILD.isDebug) && !Cstr) {
1939
+ throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
1940
+ }
1941
+ if (BUILD.member && !Cstr.isProxied) {
1942
+ // we'eve never proxied this Constructor before
1943
+ // let's add the getters/setters to its prototype before
1944
+ // the first time we create an instance of the implementation
1945
+ if (BUILD.watchCallback) {
1946
+ cmpMeta.$watchers$ = Cstr.watchers;
1947
+ }
1948
+ proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
1949
+ Cstr.isProxied = true;
1950
+ }
1951
+ const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1952
+ // ok, time to construct the instance
1953
+ // but let's keep track of when we start and stop
1954
+ // so that the getters/setters don't incorrectly step on data
1955
+ if (BUILD.member) {
1956
+ hostRef.$flags$ |= 8 /* isConstructingInstance */;
1957
+ }
1958
+ // construct the lazy-loaded component implementation
1959
+ // passing the hostRef is very important during
1960
+ // construction in order to directly wire together the
1961
+ // host element and the lazy-loaded instance
1962
+ try {
1963
+ new Cstr(hostRef);
1964
+ }
1965
+ catch (e) {
1966
+ consoleError(e);
1967
+ }
1968
+ if (BUILD.member) {
1969
+ hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1970
+ }
1971
+ if (BUILD.watchCallback) {
1972
+ hostRef.$flags$ |= 128 /* isWatchReady */;
1973
+ }
1974
+ endNewInstance();
1975
+ fireConnectedCallback(hostRef.$lazyInstance$);
1976
+ }
1977
+ else {
1978
+ // sync constructor component
1979
+ Cstr = elm.constructor;
1980
+ hostRef.$flags$ |= 128 /* isWatchReady */ | 32 /* hasInitializedComponent */;
1981
+ }
1982
+ if (BUILD.style && Cstr.style) {
1983
+ // this component has styles but we haven't registered them yet
1984
+ let style = Cstr.style;
1985
+ if (BUILD.mode && typeof style !== 'string') {
1986
+ style = style[(hostRef.$modeName$ = computeMode(elm))];
1987
+ if (BUILD.hydrateServerSide && hostRef.$modeName$) {
1988
+ elm.setAttribute('s-mode', hostRef.$modeName$);
1989
+ }
1990
+ }
1991
+ const scopeId = getScopeId(cmpMeta, hostRef.$modeName$);
1992
+ if (!styles.has(scopeId)) {
1993
+ const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1994
+ if (!BUILD.hydrateServerSide && BUILD.shadowDom && BUILD.shadowDomShim && cmpMeta.$flags$ & 8 /* needsShadowDomShim */) {
1995
+ style = await import('./shadow-css-3ef739e8.js').then(m => m.scopeCss(style, scopeId, false));
1996
+ }
1997
+ registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1998
+ endRegisterStyles();
1999
+ }
2000
+ }
2001
+ }
2002
+ // we've successfully created a lazy instance
2003
+ const ancestorComponent = hostRef.$ancestorComponent$;
2004
+ const schedule = () => scheduleUpdate(hostRef, true);
2005
+ if (BUILD.asyncLoading && ancestorComponent && ancestorComponent['s-rc']) {
2006
+ // this is the intial load and this component it has an ancestor component
2007
+ // but the ancestor component has NOT fired its will update lifecycle yet
2008
+ // so let's just cool our jets and wait for the ancestor to continue first
2009
+ // this will get fired off when the ancestor component
2010
+ // finally gets around to rendering its lazy self
2011
+ // fire off the initial update
2012
+ ancestorComponent['s-rc'].push(schedule);
2013
+ }
2014
+ else {
2015
+ schedule();
2016
+ }
2017
+ };
2018
+ const fireConnectedCallback = (instance) => {
2019
+ if (BUILD.lazyLoad && BUILD.connectedCallback) {
2020
+ safeCall(instance, 'connectedCallback');
2021
+ }
2022
+ };
2023
+ const connectedCallback = (elm) => {
2024
+ if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
2025
+ const hostRef = getHostRef(elm);
2026
+ const cmpMeta = hostRef.$cmpMeta$;
2027
+ const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
2028
+ if (BUILD.hostListenerTargetParent) {
2029
+ // only run if we have listeners being attached to a parent
2030
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, true);
2031
+ }
2032
+ if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
2033
+ // first time this component has connected
2034
+ hostRef.$flags$ |= 1 /* hasConnected */;
2035
+ let hostId;
2036
+ if (BUILD.hydrateClientSide) {
2037
+ hostId = elm.getAttribute(HYDRATE_ID);
2038
+ if (hostId) {
2039
+ if (BUILD.shadowDom && supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2040
+ const scopeId = BUILD.mode ? addStyle(elm.shadowRoot, cmpMeta, elm.getAttribute('s-mode')) : addStyle(elm.shadowRoot, cmpMeta);
2041
+ elm.classList.remove(scopeId + '-h', scopeId + '-s');
2042
+ }
2043
+ initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
2044
+ }
2045
+ }
2046
+ if (BUILD.slotRelocation && !hostId) {
2047
+ // initUpdate
2048
+ // if the slot polyfill is required we'll need to put some nodes
2049
+ // in here to act as original content anchors as we move nodes around
2050
+ // host element has been connected to the DOM
2051
+ if (BUILD.hydrateServerSide || ((BUILD.slot || BUILD.shadowDom) && cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
2052
+ setContentReference(elm);
2053
+ }
2054
+ }
2055
+ if (BUILD.asyncLoading) {
2056
+ // find the first ancestor component (if there is one) and register
2057
+ // this component as one of the actively loading child components for its ancestor
2058
+ let ancestorComponent = elm;
2059
+ while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
2060
+ // climb up the ancestors looking for the first
2061
+ // component that hasn't finished its lifecycle update yet
2062
+ if ((BUILD.hydrateClientSide && ancestorComponent.nodeType === 1 /* ElementNode */ && ancestorComponent.hasAttribute('s-id') && ancestorComponent['s-p']) ||
2063
+ ancestorComponent['s-p']) {
2064
+ // we found this components first ancestor component
2065
+ // keep a reference to this component's ancestor component
2066
+ attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
2067
+ break;
2068
+ }
2069
+ }
2070
+ }
2071
+ // Lazy properties
2072
+ // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2073
+ if (BUILD.prop && BUILD.lazyLoad && !BUILD.hydrateServerSide && cmpMeta.$members$) {
2074
+ Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
2075
+ if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
2076
+ const value = elm[memberName];
2077
+ delete elm[memberName];
2078
+ elm[memberName] = value;
2079
+ }
2080
+ });
2081
+ }
2082
+ if (BUILD.initializeNextTick) {
2083
+ // connectedCallback, taskQueue, initialLoad
2084
+ // angular sets attribute AFTER connectCallback
2085
+ // https://github.com/angular/angular/issues/18909
2086
+ // https://github.com/angular/angular/issues/19940
2087
+ nextTick(() => initializeComponent(elm, hostRef, cmpMeta));
2088
+ }
2089
+ else {
2090
+ initializeComponent(elm, hostRef, cmpMeta);
2091
+ }
2092
+ }
2093
+ else {
2094
+ // not the first time this has connected
2095
+ // reattach any event listeners to the host
2096
+ // since they would have been removed when disconnected
2097
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2098
+ // fire off connectedCallback() on component instance
2099
+ fireConnectedCallback(hostRef.$lazyInstance$);
2100
+ }
2101
+ endConnected();
2102
+ }
2103
+ };
2104
+ const setContentReference = (elm) => {
2105
+ // only required when we're NOT using native shadow dom (slot)
2106
+ // or this browser doesn't support native shadow dom
2107
+ // and this host element was NOT created with SSR
2108
+ // let's pick out the inner content for slot projection
2109
+ // create a node to represent where the original
2110
+ // content was first placed, which is useful later on
2111
+ const contentRefElm = (elm['s-cr'] = doc.createComment(BUILD.isDebug ? `content-ref (host=${elm.localName})` : ''));
2112
+ contentRefElm['s-cn'] = true;
2113
+ elm.insertBefore(contentRefElm, elm.firstChild);
2114
+ };
2115
+ const disconnectedCallback = (elm) => {
2116
+ if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
2117
+ const hostRef = getHostRef(elm);
2118
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2119
+ if (BUILD.hostListener) {
2120
+ if (hostRef.$rmListeners$) {
2121
+ hostRef.$rmListeners$.map(rmListener => rmListener());
2122
+ hostRef.$rmListeners$ = undefined;
2123
+ }
2124
+ }
2125
+ // clear CSS var-shim tracking
2126
+ if (BUILD.cssVarShim && plt.$cssShim$) {
2127
+ plt.$cssShim$.removeHost(elm);
2128
+ }
2129
+ if (BUILD.lazyLoad && BUILD.disconnectedCallback) {
2130
+ safeCall(instance, 'disconnectedCallback');
2131
+ }
2132
+ if (BUILD.cmpDidUnload) {
2133
+ safeCall(instance, 'componentDidUnload');
2134
+ }
2135
+ }
2136
+ };
2137
+ const defineCustomElement = (Cstr, compactMeta) => {
2138
+ customElements.define(compactMeta[1], proxyCustomElement(Cstr, compactMeta));
2139
+ };
2140
+ const proxyCustomElement = (Cstr, compactMeta) => {
2141
+ const cmpMeta = {
2142
+ $flags$: compactMeta[0],
2143
+ $tagName$: compactMeta[1],
2144
+ };
2145
+ if (BUILD.member) {
2146
+ cmpMeta.$members$ = compactMeta[2];
2147
+ }
2148
+ if (BUILD.hostListener) {
2149
+ cmpMeta.$listeners$ = compactMeta[3];
2150
+ }
2151
+ if (BUILD.watchCallback) {
2152
+ cmpMeta.$watchers$ = Cstr.$watchers$;
2153
+ }
2154
+ if (BUILD.reflect) {
2155
+ cmpMeta.$attrsToReflect$ = [];
2156
+ }
2157
+ if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2158
+ cmpMeta.$flags$ |= 8 /* needsShadowDomShim */;
2159
+ }
2160
+ const originalConnectedCallback = Cstr.prototype.connectedCallback;
2161
+ const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
2162
+ Object.assign(Cstr.prototype, {
2163
+ __registerHost() {
2164
+ registerHost(this, cmpMeta);
2165
+ },
2166
+ connectedCallback() {
2167
+ connectedCallback(this);
2168
+ if (BUILD.connectedCallback && originalConnectedCallback) {
2169
+ originalConnectedCallback.call(this);
2170
+ }
2171
+ },
2172
+ disconnectedCallback() {
2173
+ disconnectedCallback(this);
2174
+ if (BUILD.disconnectedCallback && originalDisconnectedCallback) {
2175
+ originalDisconnectedCallback.call(this);
2176
+ }
2177
+ },
2178
+ });
2179
+ Cstr.is = cmpMeta.$tagName$;
2180
+ return proxyComponent(Cstr, cmpMeta, 1 /* isElementConstructor */ | 2 /* proxyState */);
2181
+ };
2182
+ const forceModeUpdate = (elm) => {
2183
+ if (BUILD.style && BUILD.mode && !BUILD.lazyLoad) {
2184
+ const mode = computeMode(elm);
2185
+ const hostRef = getHostRef(elm);
2186
+ if (hostRef.$modeName$ !== mode) {
2187
+ const cmpMeta = hostRef.$cmpMeta$;
2188
+ const oldScopeId = elm['s-sc'];
2189
+ const scopeId = getScopeId(cmpMeta, mode);
2190
+ const style = elm.constructor.style[mode];
2191
+ const flags = cmpMeta.$flags$;
2192
+ if (style) {
2193
+ if (!styles.has(scopeId)) {
2194
+ registerStyle(scopeId, style, !!(flags & 1 /* shadowDomEncapsulation */));
2195
+ }
2196
+ hostRef.$modeName$ = mode;
2197
+ elm.classList.remove(oldScopeId + '-h', oldScopeId + '-s');
2198
+ attachStyles(hostRef);
2199
+ forceUpdate(elm);
2200
+ }
2201
+ }
2202
+ }
2203
+ };
2204
+ const attachShadow = (el) => {
2205
+ if (supportsShadow) {
2206
+ el.attachShadow({ mode: 'open' });
2207
+ }
2208
+ else {
2209
+ el.shadowRoot = el;
2210
+ }
2211
+ };
2212
+ const hmrStart = (elm, cmpMeta, hmrVersionId) => {
2213
+ // ¯\_(ツ)_/¯
2214
+ const hostRef = getHostRef(elm);
2215
+ // reset state flags to only have been connected
2216
+ hostRef.$flags$ = 1 /* hasConnected */;
2217
+ // TODO
2218
+ // detatch any event listeners that may have been added
2219
+ // because we're not passing an exact event name it'll
2220
+ // remove all of this element's event, which is good
2221
+ // create a callback for when this component finishes hmr
2222
+ elm['s-hmr-load'] = () => {
2223
+ // finished hmr for this element
2224
+ delete elm['s-hmr-load'];
2225
+ };
2226
+ // re-initialize the component
2227
+ initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
2228
+ };
2229
+ const patchCloneNode = (HostElementPrototype) => {
2230
+ const orgCloneNode = HostElementPrototype.cloneNode;
2231
+ HostElementPrototype.cloneNode = function (deep) {
2232
+ const srcNode = this;
2233
+ const isShadowDom = BUILD.shadowDom ? srcNode.shadowRoot && supportsShadow : false;
2234
+ const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
2235
+ if (BUILD.slot && !isShadowDom && deep) {
2236
+ let i = 0;
2237
+ let slotted, nonStencilNode;
2238
+ let stencilPrivates = ['s-id', 's-cr', 's-lr', 's-rc', 's-sc', 's-p', 's-cn', 's-sr', 's-sn', 's-hn', 's-ol', 's-nr', 's-si'];
2239
+ for (; i < srcNode.childNodes.length; i++) {
2240
+ slotted = srcNode.childNodes[i]['s-nr'];
2241
+ nonStencilNode = stencilPrivates.every((privateField) => !srcNode.childNodes[i][privateField]);
2242
+ if (slotted) {
2243
+ if (BUILD.appendChildSlotFix && clonedNode.__appendChild) {
2244
+ clonedNode.__appendChild(slotted.cloneNode(true));
2245
+ }
2246
+ else {
2247
+ clonedNode.appendChild(slotted.cloneNode(true));
2248
+ }
2249
+ }
2250
+ if (nonStencilNode) {
2251
+ clonedNode.appendChild(srcNode.childNodes[i].cloneNode(true));
2252
+ }
2253
+ }
2254
+ }
2255
+ return clonedNode;
2256
+ };
2257
+ };
2258
+ const patchSlotAppendChild = (HostElementPrototype) => {
2259
+ HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
2260
+ HostElementPrototype.appendChild = function (newChild) {
2261
+ const slotName = (newChild['s-sn'] = getSlotName(newChild));
2262
+ const slotNode = getHostSlotNode(this.childNodes, slotName);
2263
+ if (slotNode) {
2264
+ const slotChildNodes = getHostSlotChildNodes(slotNode, slotName);
2265
+ const appendAfter = slotChildNodes[slotChildNodes.length - 1];
2266
+ return appendAfter.parentNode.insertBefore(newChild, appendAfter.nextSibling);
2267
+ }
2268
+ return this.__appendChild(newChild);
2269
+ };
2270
+ };
2271
+ const patchChildSlotNodes = (elm, cmpMeta) => {
2272
+ class FakeNodeList extends Array {
2273
+ item(n) {
2274
+ return this[n];
2275
+ }
2276
+ }
2277
+ if (cmpMeta.$flags$ & 8 /* needsShadowDomShim */) {
2278
+ const childNodesFn = elm.__lookupGetter__('childNodes');
2279
+ Object.defineProperty(elm, 'children', {
2280
+ get() {
2281
+ return this.childNodes.map((n) => n.nodeType === 1);
2282
+ },
2283
+ });
2284
+ Object.defineProperty(elm, 'childElementCount', {
2285
+ get() {
2286
+ return elm.children.length;
2287
+ },
2288
+ });
2289
+ Object.defineProperty(elm, 'childNodes', {
2290
+ get() {
2291
+ const childNodes = childNodesFn.call(this);
2292
+ if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0 && getHostRef(this).$flags$ & 2 /* hasRendered */) {
2293
+ const result = new FakeNodeList();
2294
+ for (let i = 0; i < childNodes.length; i++) {
2295
+ const slot = childNodes[i]['s-nr'];
2296
+ if (slot) {
2297
+ result.push(slot);
2298
+ }
2299
+ }
2300
+ return result;
2301
+ }
2302
+ return FakeNodeList.from(childNodes);
2303
+ },
2304
+ });
2305
+ }
2306
+ };
2307
+ const getSlotName = (node) => node['s-sn'] || (node.nodeType === 1 && node.getAttribute('slot')) || '';
2308
+ const getHostSlotNode = (childNodes, slotName) => {
2309
+ let i = 0;
2310
+ let childNode;
2311
+ for (; i < childNodes.length; i++) {
2312
+ childNode = childNodes[i];
2313
+ if (childNode['s-sr'] && childNode['s-sn'] === slotName) {
2314
+ return childNode;
2315
+ }
2316
+ childNode = getHostSlotNode(childNode.childNodes, slotName);
2317
+ if (childNode) {
2318
+ return childNode;
2319
+ }
2320
+ }
2321
+ return null;
2322
+ };
2323
+ const getHostSlotChildNodes = (n, slotName) => {
2324
+ const childNodes = [n];
2325
+ while ((n = n.nextSibling) && n['s-sn'] === slotName) {
2326
+ childNodes.push(n);
2327
+ }
2328
+ return childNodes;
2329
+ };
2330
+ const bootstrapLazy = (lazyBundles, options = {}) => {
2331
+ if (BUILD.profile && performance.mark) {
2332
+ performance.mark('st:app:start');
2333
+ }
2334
+ installDevTools();
2335
+ const endBootstrap = createTime('bootstrapLazy');
2336
+ const cmpTags = [];
2337
+ const exclude = options.exclude || [];
2338
+ const customElements = win.customElements;
2339
+ const head = doc.head;
2340
+ const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
2341
+ const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
2342
+ const deferredConnectedCallbacks = [];
2343
+ const styles = /*@__PURE__*/ doc.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
2344
+ let appLoadFallback;
2345
+ let isBootstrapping = true;
2346
+ let i = 0;
2347
+ Object.assign(plt, options);
2348
+ plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
2349
+ if (BUILD.asyncQueue) {
2350
+ if (options.syncQueue) {
2351
+ plt.$flags$ |= 4 /* queueSync */;
2352
+ }
2353
+ }
2354
+ if (BUILD.hydrateClientSide) {
2355
+ // If the app is already hydrated there is not point to disable the
2356
+ // async queue. This will improve the first input delay
2357
+ plt.$flags$ |= 2 /* appLoaded */;
2358
+ }
2359
+ if (BUILD.hydrateClientSide && BUILD.shadowDom) {
2360
+ for (; i < styles.length; i++) {
2361
+ registerStyle(styles[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styles[i].innerHTML), true);
2362
+ }
2363
+ }
2364
+ lazyBundles.map(lazyBundle => lazyBundle[1].map(compactMeta => {
2365
+ const cmpMeta = {
2366
+ $flags$: compactMeta[0],
2367
+ $tagName$: compactMeta[1],
2368
+ $members$: compactMeta[2],
2369
+ $listeners$: compactMeta[3],
2370
+ };
2371
+ if (BUILD.member) {
2372
+ cmpMeta.$members$ = compactMeta[2];
2373
+ }
2374
+ if (BUILD.hostListener) {
2375
+ cmpMeta.$listeners$ = compactMeta[3];
2376
+ }
2377
+ if (BUILD.reflect) {
2378
+ cmpMeta.$attrsToReflect$ = [];
2379
+ }
2380
+ if (BUILD.watchCallback) {
2381
+ cmpMeta.$watchers$ = {};
2382
+ }
2383
+ if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2384
+ cmpMeta.$flags$ |= 8 /* needsShadowDomShim */;
2385
+ }
2386
+ const tagName = BUILD.transformTagName && options.transformTagName ? options.transformTagName(cmpMeta.$tagName$) : cmpMeta.$tagName$;
2387
+ const HostElement = class extends HTMLElement {
2388
+ // StencilLazyHost
2389
+ constructor(self) {
2390
+ // @ts-ignore
2391
+ super(self);
2392
+ self = this;
2393
+ registerHost(self, cmpMeta);
2394
+ if (BUILD.shadowDom && cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
2395
+ // this component is using shadow dom
2396
+ // and this browser supports shadow dom
2397
+ // add the read-only property "shadowRoot" to the host element
2398
+ // adding the shadow root build conditionals to minimize runtime
2399
+ if (supportsShadow) {
2400
+ if (BUILD.shadowDelegatesFocus) {
2401
+ self.attachShadow({
2402
+ mode: 'open',
2403
+ delegatesFocus: !!(cmpMeta.$flags$ & 16 /* shadowDelegatesFocus */),
2404
+ });
2405
+ }
2406
+ else {
2407
+ self.attachShadow({ mode: 'open' });
2408
+ }
2409
+ }
2410
+ else if (!BUILD.hydrateServerSide && !('shadowRoot' in self)) {
2411
+ self.shadowRoot = self;
2412
+ }
2413
+ }
2414
+ if (BUILD.slotChildNodesFix) {
2415
+ patchChildSlotNodes(self, cmpMeta);
2416
+ }
2417
+ }
2418
+ connectedCallback() {
2419
+ if (appLoadFallback) {
2420
+ clearTimeout(appLoadFallback);
2421
+ appLoadFallback = null;
2422
+ }
2423
+ if (isBootstrapping) {
2424
+ // connectedCallback will be processed once all components have been registered
2425
+ deferredConnectedCallbacks.push(this);
2426
+ }
2427
+ else {
2428
+ plt.jmp(() => connectedCallback(this));
2429
+ }
2430
+ }
2431
+ disconnectedCallback() {
2432
+ plt.jmp(() => disconnectedCallback(this));
2433
+ }
2434
+ componentOnReady() {
2435
+ return getHostRef(this).$onReadyPromise$;
2436
+ }
2437
+ };
2438
+ if (BUILD.cloneNodeFix) {
2439
+ patchCloneNode(HostElement.prototype);
2440
+ }
2441
+ if (BUILD.appendChildSlotFix) {
2442
+ patchSlotAppendChild(HostElement.prototype);
2443
+ }
2444
+ if (BUILD.hotModuleReplacement) {
2445
+ HostElement.prototype['s-hmr'] = function (hmrVersionId) {
2446
+ hmrStart(this, cmpMeta, hmrVersionId);
2447
+ };
2448
+ }
2449
+ cmpMeta.$lazyBundleId$ = lazyBundle[0];
2450
+ if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2451
+ cmpTags.push(tagName);
2452
+ customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
2453
+ }
2454
+ }));
2455
+ if (BUILD.hydratedClass || BUILD.hydratedAttribute) {
2456
+ visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
2457
+ visibilityStyle.setAttribute('data-styles', '');
2458
+ head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
2459
+ }
2460
+ // Process deferred connectedCallbacks now all components have been registered
2461
+ isBootstrapping = false;
2462
+ if (deferredConnectedCallbacks.length) {
2463
+ deferredConnectedCallbacks.map(host => host.connectedCallback());
2464
+ }
2465
+ else {
2466
+ if (BUILD.profile) {
2467
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30, 'timeout')));
2468
+ }
2469
+ else {
2470
+ plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
2471
+ }
2472
+ }
2473
+ // Fallback appLoad event
2474
+ endBootstrap();
2475
+ };
2476
+ const getAssetPath = (path) => {
2477
+ const assetUrl = new URL(path, plt.$resourcesUrl$);
2478
+ return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
2479
+ };
2480
+ const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
2481
+ const getConnect = (_ref, tagName) => {
2482
+ const componentOnReady = () => {
2483
+ let elm = doc.querySelector(tagName);
2484
+ if (!elm) {
2485
+ elm = doc.createElement(tagName);
2486
+ doc.body.appendChild(elm);
2487
+ }
2488
+ return typeof elm.componentOnReady === 'function' ? elm.componentOnReady() : Promise.resolve(elm);
2489
+ };
2490
+ const create = (...args) => {
2491
+ return componentOnReady().then(el => el.create(...args));
2492
+ };
2493
+ return {
2494
+ create,
2495
+ componentOnReady,
2496
+ };
2497
+ };
2498
+ const getContext = (_elm, context) => {
2499
+ if (context in Context) {
2500
+ return Context[context];
2501
+ }
2502
+ else if (context === 'window') {
2503
+ return win;
2504
+ }
2505
+ else if (context === 'document') {
2506
+ return doc;
2507
+ }
2508
+ else if (context === 'isServer' || context === 'isPrerender') {
2509
+ return BUILD.hydrateServerSide ? true : false;
2510
+ }
2511
+ else if (context === 'isClient') {
2512
+ return BUILD.hydrateServerSide ? false : true;
2513
+ }
2514
+ else if (context === 'resourcesUrl' || context === 'publicPath') {
2515
+ return getAssetPath('.');
2516
+ }
2517
+ else if (context === 'queue') {
2518
+ return {
2519
+ write: writeTask,
2520
+ read: readTask,
2521
+ tick: {
2522
+ then(cb) {
2523
+ return nextTick(cb);
2524
+ },
2525
+ },
2526
+ };
2527
+ }
2528
+ return undefined;
2529
+ };
2530
+ const insertVdomAnnotations = (doc, staticComponents) => {
2531
+ if (doc != null) {
2532
+ const docData = {
2533
+ hostIds: 0,
2534
+ rootLevelIds: 0,
2535
+ staticComponents: new Set(staticComponents),
2536
+ };
2537
+ const orgLocationNodes = [];
2538
+ parseVNodeAnnotations(doc, doc.body, docData, orgLocationNodes);
2539
+ orgLocationNodes.forEach(orgLocationNode => {
2540
+ if (orgLocationNode != null) {
2541
+ const nodeRef = orgLocationNode['s-nr'];
2542
+ let hostId = nodeRef['s-host-id'];
2543
+ let nodeId = nodeRef['s-node-id'];
2544
+ let childId = `${hostId}.${nodeId}`;
2545
+ if (hostId == null) {
2546
+ hostId = 0;
2547
+ docData.rootLevelIds++;
2548
+ nodeId = docData.rootLevelIds;
2549
+ childId = `${hostId}.${nodeId}`;
2550
+ if (nodeRef.nodeType === 1 /* ElementNode */) {
2551
+ nodeRef.setAttribute(HYDRATE_CHILD_ID, childId);
2552
+ }
2553
+ else if (nodeRef.nodeType === 3 /* TextNode */) {
2554
+ if (hostId === 0) {
2555
+ const textContent = nodeRef.nodeValue.trim();
2556
+ if (textContent === '') {
2557
+ // useless whitespace node at the document root
2558
+ orgLocationNode.remove();
2559
+ return;
2560
+ }
2561
+ }
2562
+ const commentBeforeTextNode = doc.createComment(childId);
2563
+ commentBeforeTextNode.nodeValue = `${TEXT_NODE_ID}.${childId}`;
2564
+ nodeRef.parentNode.insertBefore(commentBeforeTextNode, nodeRef);
2565
+ }
2566
+ }
2567
+ let orgLocationNodeId = `${ORG_LOCATION_ID}.${childId}`;
2568
+ const orgLocationParentNode = orgLocationNode.parentElement;
2569
+ if (orgLocationParentNode) {
2570
+ if (orgLocationParentNode['s-en'] === '') {
2571
+ // ending with a "." means that the parent element
2572
+ // of this node's original location is a SHADOW dom element
2573
+ // and this node is apart of the root level light dom
2574
+ orgLocationNodeId += `.`;
2575
+ }
2576
+ else if (orgLocationParentNode['s-en'] === 'c') {
2577
+ // ending with a ".c" means that the parent element
2578
+ // of this node's original location is a SCOPED element
2579
+ // and this node is apart of the root level light dom
2580
+ orgLocationNodeId += `.c`;
2581
+ }
2582
+ }
2583
+ orgLocationNode.nodeValue = orgLocationNodeId;
2584
+ }
2585
+ });
2586
+ }
2587
+ };
2588
+ const parseVNodeAnnotations = (doc, node, docData, orgLocationNodes) => {
2589
+ if (node == null) {
2590
+ return;
2591
+ }
2592
+ if (node['s-nr'] != null) {
2593
+ orgLocationNodes.push(node);
2594
+ }
2595
+ if (node.nodeType === 1 /* ElementNode */) {
2596
+ node.childNodes.forEach(childNode => {
2597
+ const hostRef = getHostRef(childNode);
2598
+ if (hostRef != null && !docData.staticComponents.has(childNode.nodeName.toLowerCase())) {
2599
+ const cmpData = {
2600
+ nodeIds: 0,
2601
+ };
2602
+ insertVNodeAnnotations(doc, childNode, hostRef.$vnode$, docData, cmpData);
2603
+ }
2604
+ parseVNodeAnnotations(doc, childNode, docData, orgLocationNodes);
2605
+ });
2606
+ }
2607
+ };
2608
+ const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
2609
+ if (vnode != null) {
2610
+ const hostId = ++docData.hostIds;
2611
+ hostElm.setAttribute(HYDRATE_ID, hostId);
2612
+ if (hostElm['s-cr'] != null) {
2613
+ hostElm['s-cr'].nodeValue = `${CONTENT_REF_ID}.${hostId}`;
2614
+ }
2615
+ if (vnode.$children$ != null) {
2616
+ const depth = 0;
2617
+ vnode.$children$.forEach((vnodeChild, index) => {
2618
+ insertChildVNodeAnnotations(doc, vnodeChild, cmpData, hostId, depth, index);
2619
+ });
2620
+ }
2621
+ if (hostElm && vnode && vnode.$elm$ && !hostElm.hasAttribute('c-id')) {
2622
+ const parent = hostElm.parentElement;
2623
+ if (parent && parent.childNodes) {
2624
+ const parentChildNodes = Array.from(parent.childNodes);
2625
+ const comment = parentChildNodes.find(node => node.nodeType === 8 /* CommentNode */ && node['s-sr']);
2626
+ if (comment) {
2627
+ const index = parentChildNodes.indexOf(hostElm) - 1;
2628
+ vnode.$elm$.setAttribute(HYDRATE_CHILD_ID, `${comment['s-host-id']}.${comment['s-node-id']}.0.${index}`);
2629
+ }
2630
+ }
2631
+ }
2632
+ }
2633
+ };
2634
+ const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, index) => {
2635
+ const childElm = vnodeChild.$elm$;
2636
+ if (childElm == null) {
2637
+ return;
2638
+ }
2639
+ const nodeId = cmpData.nodeIds++;
2640
+ const childId = `${hostId}.${nodeId}.${depth}.${index}`;
2641
+ childElm['s-host-id'] = hostId;
2642
+ childElm['s-node-id'] = nodeId;
2643
+ if (childElm.nodeType === 1 /* ElementNode */) {
2644
+ childElm.setAttribute(HYDRATE_CHILD_ID, childId);
2645
+ }
2646
+ else if (childElm.nodeType === 3 /* TextNode */) {
2647
+ const parentNode = childElm.parentNode;
2648
+ const nodeName = parentNode.nodeName;
2649
+ if (nodeName !== 'STYLE' && nodeName !== 'SCRIPT') {
2650
+ const textNodeId = `${TEXT_NODE_ID}.${childId}`;
2651
+ const commentBeforeTextNode = doc.createComment(textNodeId);
2652
+ parentNode.insertBefore(commentBeforeTextNode, childElm);
2653
+ }
2654
+ }
2655
+ else if (childElm.nodeType === 8 /* CommentNode */) {
2656
+ if (childElm['s-sr']) {
2657
+ const slotName = childElm['s-sn'] || '';
2658
+ const slotNodeId = `${SLOT_NODE_ID}.${childId}.${slotName}`;
2659
+ childElm.nodeValue = slotNodeId;
2660
+ }
2661
+ }
2662
+ if (vnodeChild.$children$ != null) {
2663
+ const childDepth = depth + 1;
2664
+ vnodeChild.$children$.forEach((vnode, index) => {
2665
+ insertChildVNodeAnnotations(doc, vnode, cmpData, hostId, childDepth, index);
2666
+ });
2667
+ }
2668
+ };
2669
+ const Fragment = (_, children) => children;
2670
+ const hostRefs = new WeakMap();
2671
+ const getHostRef = (ref) => hostRefs.get(ref);
2672
+ const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
2673
+ const registerHost = (elm, cmpMeta) => {
2674
+ const hostRef = {
2675
+ $flags$: 0,
2676
+ $hostElement$: elm,
2677
+ $cmpMeta$: cmpMeta,
2678
+ $instanceValues$: new Map(),
2679
+ };
2680
+ if (BUILD.isDev) {
2681
+ hostRef.$renderCount$ = 0;
2682
+ }
2683
+ if (BUILD.method && BUILD.lazyLoad) {
2684
+ hostRef.$onInstancePromise$ = new Promise(r => (hostRef.$onInstanceResolve$ = r));
2685
+ }
2686
+ if (BUILD.asyncLoading) {
2687
+ hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
2688
+ elm['s-p'] = [];
2689
+ elm['s-rc'] = [];
2690
+ }
2691
+ addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2692
+ return hostRefs.set(elm, hostRef);
2693
+ };
2694
+ const isMemberInElement = (elm, memberName) => memberName in elm;
2695
+ const consoleError = (e, el) => (customError || console.error)(e, el);
2696
+ const STENCIL_DEV_MODE = BUILD.isTesting
2697
+ ? ['STENCIL:'] // E2E testing
2698
+ : ['%cstencil', 'color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px'];
2699
+ const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
2700
+ const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
2701
+ const consoleDevInfo = (...m) => console.info(...STENCIL_DEV_MODE, ...m);
2702
+ const setErrorHandler = (handler) => customError = handler;
2703
+ const cmpModules = /*@__PURE__*/ new Map();
2704
+ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
2705
+ // loadModuleImport
2706
+ const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
2707
+ const bundleId = cmpMeta.$lazyBundleId$;
2708
+ if (BUILD.isDev && typeof bundleId !== 'string') {
2709
+ consoleDevError(`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`);
2710
+ return undefined;
2711
+ }
2712
+ const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
2713
+ if (module) {
2714
+ return module[exportName];
2715
+ }
2716
+ return import(
2717
+ /* webpackInclude: /\.entry\.js$/ */
2718
+ /* webpackExclude: /\.system\.entry\.js$/ */
2719
+ /* webpackMode: "lazy" */
2720
+ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`).then(importedModule => {
2721
+ if (!BUILD.hotModuleReplacement) {
2722
+ cmpModules.set(bundleId, importedModule);
2723
+ }
2724
+ return importedModule[exportName];
2725
+ }, consoleError);
2726
+ };
2727
+ const styles = new Map();
2728
+ const modeResolutionChain = [];
2729
+ const queueDomReads = [];
2730
+ const queueDomWrites = [];
2731
+ const queueDomWritesLow = [];
2732
+ const queueTask = (queue, write) => (cb) => {
2733
+ queue.push(cb);
2734
+ if (!queuePending) {
2735
+ queuePending = true;
2736
+ if (write && plt.$flags$ & 4 /* queueSync */) {
2737
+ nextTick(flush);
2738
+ }
2739
+ else {
2740
+ plt.raf(flush);
2741
+ }
2742
+ }
2743
+ };
2744
+ const consume = (queue) => {
2745
+ for (let i = 0; i < queue.length; i++) {
2746
+ try {
2747
+ queue[i](performance.now());
2748
+ }
2749
+ catch (e) {
2750
+ consoleError(e);
2751
+ }
2752
+ }
2753
+ queue.length = 0;
2754
+ };
2755
+ const consumeTimeout = (queue, timeout) => {
2756
+ let i = 0;
2757
+ let ts = 0;
2758
+ while (i < queue.length && (ts = performance.now()) < timeout) {
2759
+ try {
2760
+ queue[i++](ts);
2761
+ }
2762
+ catch (e) {
2763
+ consoleError(e);
2764
+ }
2765
+ }
2766
+ if (i === queue.length) {
2767
+ queue.length = 0;
2768
+ }
2769
+ else if (i !== 0) {
2770
+ queue.splice(0, i);
2771
+ }
2772
+ };
2773
+ const flush = () => {
2774
+ if (BUILD.asyncQueue) {
2775
+ queueCongestion++;
2776
+ }
2777
+ // always force a bunch of medium callbacks to run, but still have
2778
+ // a throttle on how many can run in a certain time
2779
+ // DOM READS!!!
2780
+ consume(queueDomReads);
2781
+ // DOM WRITES!!!
2782
+ if (BUILD.asyncQueue) {
2783
+ const timeout = (plt.$flags$ & 6 /* queueMask */) === 2 /* appLoaded */ ? performance.now() + 14 * Math.ceil(queueCongestion * (1.0 / 10.0)) : Infinity;
2784
+ consumeTimeout(queueDomWrites, timeout);
2785
+ consumeTimeout(queueDomWritesLow, timeout);
2786
+ if (queueDomWrites.length > 0) {
2787
+ queueDomWritesLow.push(...queueDomWrites);
2788
+ queueDomWrites.length = 0;
2789
+ }
2790
+ if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
2791
+ // still more to do yet, but we've run out of time
2792
+ // let's let this thing cool off and try again in the next tick
2793
+ plt.raf(flush);
2794
+ }
2795
+ else {
2796
+ queueCongestion = 0;
2797
+ }
2798
+ }
2799
+ else {
2800
+ consume(queueDomWrites);
2801
+ if ((queuePending = queueDomReads.length > 0)) {
2802
+ // still more to do yet, but we've run out of time
2803
+ // let's let this thing cool off and try again in the next tick
2804
+ plt.raf(flush);
2805
+ }
2806
+ }
2807
+ };
2808
+ const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
2809
+ const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
2810
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
2811
+ const Build = {
2812
+ isDev: BUILD.isDev ? true : false,
2813
+ isBrowser: true,
2814
+ isServer: false,
2815
+ isTesting: BUILD.isTesting ? true : false,
2816
+ };
2817
+
2818
+ export { BUILD as B, CSS as C, H, NAMESPACE as N, promiseResolve as a, bootstrapLazy as b, consoleDevInfo as c, doc as d, createEvent as e, Host as f, getElement as g, h, getAssetPath as i, forceUpdate as j, plt as p, registerInstance as r, win as w };