@ptcwebops/ptcw-design 0.0.1

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