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