UNPKG

215 kBJavaScriptView Raw
1/* proxy-compat-disable */
2/**
3 * Copyright (C) 2018 salesforce.com, inc.
4 */
5
6/*
7 * Copyright (c) 2018, salesforce.com, inc.
8 * All rights reserved.
9 * SPDX-License-Identifier: MIT
10 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
11 */
12const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
13const { filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, slice: ArraySlice, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
14const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
15function isUndefined(obj) {
16 return obj === undefined;
17}
18function isNull(obj) {
19 return obj === null;
20}
21function isFunction(obj) {
22 return typeof obj === 'function';
23}
24function isObject(obj) {
25 return typeof obj === 'object';
26}
27function isString(obj) {
28 return typeof obj === 'string';
29}
30
31/*
32 * Copyright (c) 2018, salesforce.com, inc.
33 * All rights reserved.
34 * SPDX-License-Identifier: MIT
35 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
36 */
37/**
38 * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and
39 * ariaGrabbed) are deprecated:
40 * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes
41 *
42 * The above list of 46 aria attributes is consistent with the following resources:
43 * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
44 * https://wicg.github.io/aom/spec/aria-reflection.html
45 */
46const AriaPropertyNames = [
47 'ariaActiveDescendant',
48 'ariaAtomic',
49 'ariaAutoComplete',
50 'ariaBusy',
51 'ariaChecked',
52 'ariaColCount',
53 'ariaColIndex',
54 'ariaColSpan',
55 'ariaControls',
56 'ariaCurrent',
57 'ariaDescribedBy',
58 'ariaDetails',
59 'ariaDisabled',
60 'ariaErrorMessage',
61 'ariaExpanded',
62 'ariaFlowTo',
63 'ariaHasPopup',
64 'ariaHidden',
65 'ariaInvalid',
66 'ariaKeyShortcuts',
67 'ariaLabel',
68 'ariaLabelledBy',
69 'ariaLevel',
70 'ariaLive',
71 'ariaModal',
72 'ariaMultiLine',
73 'ariaMultiSelectable',
74 'ariaOrientation',
75 'ariaOwns',
76 'ariaPlaceholder',
77 'ariaPosInSet',
78 'ariaPressed',
79 'ariaReadOnly',
80 'ariaRelevant',
81 'ariaRequired',
82 'ariaRoleDescription',
83 'ariaRowCount',
84 'ariaRowIndex',
85 'ariaRowSpan',
86 'ariaSelected',
87 'ariaSetSize',
88 'ariaSort',
89 'ariaValueMax',
90 'ariaValueMin',
91 'ariaValueNow',
92 'ariaValueText',
93 'role',
94];
95const AttrNameToPropNameMap = create(null);
96const PropNameToAttrNameMap = create(null);
97// Synthetic creation of all AOM property descriptors for Custom Elements
98forEach.call(AriaPropertyNames, (propName) => {
99 // Typescript infers the wrong function type for this particular overloaded method:
100 // https://github.com/Microsoft/TypeScript/issues/27972
101 // @ts-ignore type-mismatch
102 const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, 'aria-'));
103 AttrNameToPropNameMap[attrName] = propName;
104 PropNameToAttrNameMap[propName] = attrName;
105});
106function isAriaAttribute(attrName) {
107 return attrName in AttrNameToPropNameMap;
108}
109
110/*
111 * Copyright (c) 2018, salesforce.com, inc.
112 * All rights reserved.
113 * SPDX-License-Identifier: MIT
114 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
115 */
116// Inspired from: https://mathiasbynens.be/notes/globalthis
117const _globalThis = (function () {
118 // On recent browsers, `globalThis` is already defined. In this case return it directly.
119 if (typeof globalThis === 'object') {
120 return globalThis;
121 }
122 let _globalThis;
123 try {
124 // eslint-disable-next-line no-extend-native
125 Object.defineProperty(Object.prototype, '__magic__', {
126 get: function () {
127 return this;
128 },
129 configurable: true,
130 });
131 // __magic__ is undefined in Safari 10 and IE10 and older.
132 // @ts-ignore
133 // eslint-disable-next-line no-undef
134 _globalThis = __magic__;
135 // @ts-ignore
136 delete Object.prototype.__magic__;
137 }
138 catch (ex) {
139 // In IE8, Object.defineProperty only works on DOM objects.
140 }
141 finally {
142 // If the magic above fails for some reason we assume that we are in a legacy browser.
143 // Assume `window` exists in this case.
144 if (typeof _globalThis === 'undefined') {
145 // @ts-ignore
146 _globalThis = window;
147 }
148 }
149 return _globalThis;
150})();
151
152/*
153 * Copyright (c) 2018, salesforce.com, inc.
154 * All rights reserved.
155 * SPDX-License-Identifier: MIT
156 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
157 */
158/*
159 * In IE11, symbols are expensive.
160 * Due to the nature of the symbol polyfill. This method abstract the
161 * creation of symbols, so we can fallback to string when native symbols
162 * are not supported. Note that we can't use typeof since it will fail when transpiling.
163 */
164const hasNativeSymbolsSupport = Symbol('x').toString() === 'Symbol(x)';
165
166/*
167 * Copyright (c) 2020, salesforce.com, inc.
168 * All rights reserved.
169 * SPDX-License-Identifier: MIT
170 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
171 */
172// The following list contains a mix of both void elements from the HTML and the XML namespace
173// without distinction.
174const VOID_ELEMENTS = [
175 'area',
176 'base',
177 'br',
178 'circle',
179 'col',
180 'ellipse',
181 'feBlend',
182 'feColorMatrix',
183 'feFuncR',
184 'feFuncG',
185 'feFuncB',
186 'feFuncA',
187 'feImage',
188 'feComposite',
189 'feConvolveMatrix',
190 'feDiffuseLighting',
191 'feDisplacementMap',
192 'feDropShadow',
193 'feFlood',
194 'feGaussianBlur',
195 'feMerge',
196 'feMergeNode',
197 'feMorphology',
198 'feOffset',
199 'feSpecularLighting',
200 'feTile',
201 'feTurbulence',
202 'fePointLight',
203 'embed',
204 'hr',
205 'img',
206 'input',
207 'keygen',
208 'line',
209 'link',
210 'menuitem',
211 'meta',
212 'param',
213 'rect',
214 'source',
215 'track',
216 'wbr',
217];
218const VOID_ELEMENTS_SET = new Set(VOID_ELEMENTS);
219function isVoidElement(name) {
220 return VOID_ELEMENTS_SET.has(name);
221}
222
223/*
224 * Copyright (c) 2020, salesforce.com, inc.
225 * All rights reserved.
226 * SPDX-License-Identifier: MIT
227 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
228 */
229/**
230 * Maps boolean attribute name to supported tags: 'boolean attr name' => Set of allowed tag names that supports them.
231 */
232const BOOLEAN_ATTRIBUTES = new Map([
233 ['autofocus', new Set(['button', 'input', 'keygen', 'select', 'textarea'])],
234 ['autoplay', new Set(['audio', 'video'])],
235 ['checked', new Set(['command', 'input'])],
236 [
237 'disabled',
238 new Set([
239 'button',
240 'command',
241 'fieldset',
242 'input',
243 'keygen',
244 'optgroup',
245 'select',
246 'textarea',
247 ]),
248 ],
249 ['formnovalidate', new Set(['button'])],
250 ['hidden', new Set()],
251 ['loop', new Set(['audio', 'bgsound', 'marquee', 'video'])],
252 ['multiple', new Set(['input', 'select'])],
253 ['muted', new Set(['audio', 'video'])],
254 ['novalidate', new Set(['form'])],
255 ['open', new Set(['details'])],
256 ['readonly', new Set(['input', 'textarea'])],
257 ['required', new Set(['input', 'select', 'textarea'])],
258 ['reversed', new Set(['ol'])],
259 ['selected', new Set(['option'])],
260]);
261function isBooleanAttribute(attrName, tagName) {
262 const allowedTagNames = BOOLEAN_ATTRIBUTES.get(attrName);
263 return (allowedTagNames !== undefined &&
264 (allowedTagNames.size === 0 || allowedTagNames.has(tagName)));
265}
266const GLOBAL_ATTRIBUTE = new Set([
267 'role',
268 'accesskey',
269 'class',
270 'contenteditable',
271 'contextmenu',
272 'dir',
273 'draggable',
274 'dropzone',
275 'hidden',
276 'id',
277 'itemprop',
278 'lang',
279 'slot',
280 'spellcheck',
281 'style',
282 'tabindex',
283 'title',
284]);
285function isGlobalHtmlAttribute(attrName) {
286 return GLOBAL_ATTRIBUTE.has(attrName);
287}
288const HTML_ATTRIBUTES_TO_PROPERTY = {
289 accesskey: 'accessKey',
290 readonly: 'readOnly',
291 tabindex: 'tabIndex',
292 bgcolor: 'bgColor',
293 colspan: 'colSpan',
294 rowspan: 'rowSpan',
295 contenteditable: 'contentEditable',
296 crossorigin: 'crossOrigin',
297 datetime: 'dateTime',
298 formaction: 'formAction',
299 ismap: 'isMap',
300 maxlength: 'maxLength',
301 minlength: 'minLength',
302 novalidate: 'noValidate',
303 usemap: 'useMap',
304 for: 'htmlFor',
305};
306keys(HTML_ATTRIBUTES_TO_PROPERTY).forEach((attrName) => {
307});
308/** version: 1.7.12 */
309
310/*
311 * Copyright (c) 2020, salesforce.com, inc.
312 * All rights reserved.
313 * SPDX-License-Identifier: MIT
314 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
315 */
316/**
317 * The following constructor might be used in either the constructor or the connectedCallback. In
318 * order to ensure that the component evaluates, we attach those mock constructors to the global
319 * object.
320 */
321if (typeof Event !== 'function' && typeof CustomEvent !== 'function') {
322 class Event {
323 }
324 class CustomEvent extends Event {
325 }
326 defineProperties(_globalThis, {
327 Event: {
328 value: Event,
329 configurable: true,
330 writable: true,
331 },
332 CustomEvent: {
333 value: CustomEvent,
334 configurable: true,
335 writable: true,
336 },
337 });
338}
339
340/* proxy-compat-disable */
341/**
342 * Copyright (C) 2018 salesforce.com, inc.
343 */
344
345/*
346 * Copyright (c) 2018, salesforce.com, inc.
347 * All rights reserved.
348 * SPDX-License-Identifier: MIT
349 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
350 */
351function invariant(value, msg) {
352 if (!value) {
353 throw new Error(`Invariant Violation: ${msg}`);
354 }
355}
356
357function isTrue(value, msg) {
358 if (!value) {
359 throw new Error(`Assert Violation: ${msg}`);
360 }
361}
362
363function isFalse(value, msg) {
364 if (value) {
365 throw new Error(`Assert Violation: ${msg}`);
366 }
367}
368
369function fail(msg) {
370 throw new Error(msg);
371}
372
373var assert = /*#__PURE__*/Object.freeze({
374 __proto__: null,
375 invariant: invariant,
376 isTrue: isTrue,
377 isFalse: isFalse,
378 fail: fail
379});
380/*
381 * Copyright (c) 2018, salesforce.com, inc.
382 * All rights reserved.
383 * SPDX-License-Identifier: MIT
384 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
385 */
386
387const {
388 assign: assign$1,
389 create: create$1,
390 defineProperties: defineProperties$1,
391 defineProperty: defineProperty$1,
392 freeze: freeze$1,
393 getOwnPropertyDescriptor: getOwnPropertyDescriptor$1,
394 getOwnPropertyNames: getOwnPropertyNames$1,
395 getPrototypeOf: getPrototypeOf$1,
396 hasOwnProperty: hasOwnProperty$1,
397 isFrozen: isFrozen$1,
398 keys: keys$1,
399 seal: seal$1,
400 setPrototypeOf: setPrototypeOf$1
401} = Object;
402const {
403 isArray
404} = Array;
405const {
406 filter: ArrayFilter$1,
407 find: ArrayFind$1,
408 indexOf: ArrayIndexOf$1,
409 join: ArrayJoin$1,
410 map: ArrayMap$1,
411 push: ArrayPush$1,
412 reduce: ArrayReduce$1,
413 reverse: ArrayReverse$1,
414 slice: ArraySlice$1,
415 splice: ArraySplice$1,
416 unshift: ArrayUnshift$1,
417 forEach: forEach$1
418} = Array.prototype;
419const {
420 charCodeAt: StringCharCodeAt$1,
421 replace: StringReplace$1,
422 slice: StringSlice$1,
423 toLowerCase: StringToLowerCase$1
424} = String.prototype;
425
426function isUndefined$1(obj) {
427 return obj === undefined;
428}
429
430function isNull$1(obj) {
431 return obj === null;
432}
433
434function isTrue$1(obj) {
435 return obj === true;
436}
437
438function isFalse$1(obj) {
439 return obj === false;
440}
441
442function isFunction$1(obj) {
443 return typeof obj === 'function';
444}
445
446function isObject$1(obj) {
447 return typeof obj === 'object';
448}
449
450function isString$1(obj) {
451 return typeof obj === 'string';
452}
453
454function isNumber(obj) {
455 return typeof obj === 'number';
456}
457
458const OtS = {}.toString;
459
460function toString(obj) {
461 if (obj && obj.toString) {
462 // Arrays might hold objects with "null" prototype So using
463 // Array.prototype.toString directly will cause an error Iterate through
464 // all the items and handle individually.
465 if (isArray(obj)) {
466 return ArrayJoin$1.call(ArrayMap$1.call(obj, toString), ',');
467 }
468
469 return obj.toString();
470 } else if (typeof obj === 'object') {
471 return OtS.call(obj);
472 } else {
473 return obj + emptyString;
474 }
475}
476
477function getPropertyDescriptor(o, p) {
478 do {
479 const d = getOwnPropertyDescriptor$1(o, p);
480
481 if (!isUndefined$1(d)) {
482 return d;
483 }
484
485 o = getPrototypeOf$1(o);
486 } while (o !== null);
487}
488
489const emptyString = '';
490/*
491 * Copyright (c) 2018, salesforce.com, inc.
492 * All rights reserved.
493 * SPDX-License-Identifier: MIT
494 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
495 */
496
497/**
498 * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and
499 * ariaGrabbed) are deprecated:
500 * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes
501 *
502 * The above list of 46 aria attributes is consistent with the following resources:
503 * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
504 * https://wicg.github.io/aom/spec/aria-reflection.html
505 */
506
507const AriaPropertyNames$1 = ['ariaActiveDescendant', 'ariaAtomic', 'ariaAutoComplete', 'ariaBusy', 'ariaChecked', 'ariaColCount', 'ariaColIndex', 'ariaColSpan', 'ariaControls', 'ariaCurrent', 'ariaDescribedBy', 'ariaDetails', 'ariaDisabled', 'ariaErrorMessage', 'ariaExpanded', 'ariaFlowTo', 'ariaHasPopup', 'ariaHidden', 'ariaInvalid', 'ariaKeyShortcuts', 'ariaLabel', 'ariaLabelledBy', 'ariaLevel', 'ariaLive', 'ariaModal', 'ariaMultiLine', 'ariaMultiSelectable', 'ariaOrientation', 'ariaOwns', 'ariaPlaceholder', 'ariaPosInSet', 'ariaPressed', 'ariaReadOnly', 'ariaRelevant', 'ariaRequired', 'ariaRoleDescription', 'ariaRowCount', 'ariaRowIndex', 'ariaRowSpan', 'ariaSelected', 'ariaSetSize', 'ariaSort', 'ariaValueMax', 'ariaValueMin', 'ariaValueNow', 'ariaValueText', 'role'];
508const AttrNameToPropNameMap$1 = create$1(null);
509const PropNameToAttrNameMap$1 = create$1(null); // Synthetic creation of all AOM property descriptors for Custom Elements
510
511forEach$1.call(AriaPropertyNames$1, propName => {
512 // Typescript infers the wrong function type for this particular overloaded method:
513 // https://github.com/Microsoft/TypeScript/issues/27972
514 // @ts-ignore type-mismatch
515 const attrName = StringToLowerCase$1.call(StringReplace$1.call(propName, /^aria/, 'aria-'));
516 AttrNameToPropNameMap$1[attrName] = propName;
517 PropNameToAttrNameMap$1[propName] = attrName;
518});
519/*
520 * Copyright (c) 2018, salesforce.com, inc.
521 * All rights reserved.
522 * SPDX-License-Identifier: MIT
523 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
524 */
525// Inspired from: https://mathiasbynens.be/notes/globalthis
526
527
528const _globalThis$1 = function () {
529 // On recent browsers, `globalThis` is already defined. In this case return it directly.
530 if (typeof globalThis === 'object') {
531 return globalThis;
532 }
533
534 let _globalThis;
535
536 try {
537 // eslint-disable-next-line no-extend-native
538 Object.defineProperty(Object.prototype, '__magic__', {
539 get: function () {
540 return this;
541 },
542 configurable: true
543 }); // __magic__ is undefined in Safari 10 and IE10 and older.
544 // @ts-ignore
545 // eslint-disable-next-line no-undef
546
547 _globalThis = __magic__; // @ts-ignore
548
549 delete Object.prototype.__magic__;
550 } catch (ex) {// In IE8, Object.defineProperty only works on DOM objects.
551 } finally {
552 // If the magic above fails for some reason we assume that we are in a legacy browser.
553 // Assume `window` exists in this case.
554 if (typeof _globalThis === 'undefined') {
555 // @ts-ignore
556 _globalThis = window;
557 }
558 }
559
560 return _globalThis;
561}();
562/*
563 * Copyright (c) 2018, salesforce.com, inc.
564 * All rights reserved.
565 * SPDX-License-Identifier: MIT
566 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
567 */
568
569/*
570 * In IE11, symbols are expensive.
571 * Due to the nature of the symbol polyfill. This method abstract the
572 * creation of symbols, so we can fallback to string when native symbols
573 * are not supported. Note that we can't use typeof since it will fail when transpiling.
574 */
575
576
577const hasNativeSymbolsSupport$1 = Symbol('x').toString() === 'Symbol(x)';
578
579function createHiddenField(key, namespace) {
580 return hasNativeSymbolsSupport$1 ? Symbol(key) : `$$lwc-${namespace}-${key}$$`;
581}
582
583const hiddenFieldsMap = new WeakMap();
584
585function setHiddenField(o, field, value) {
586 let valuesByField = hiddenFieldsMap.get(o);
587
588 if (isUndefined$1(valuesByField)) {
589 valuesByField = create$1(null);
590 hiddenFieldsMap.set(o, valuesByField);
591 }
592
593 valuesByField[field] = value;
594}
595
596function getHiddenField(o, field) {
597 const valuesByField = hiddenFieldsMap.get(o);
598
599 if (!isUndefined$1(valuesByField)) {
600 return valuesByField[field];
601 }
602}
603
604const HTML_ATTRIBUTES_TO_PROPERTY$1 = {
605 accesskey: 'accessKey',
606 readonly: 'readOnly',
607 tabindex: 'tabIndex',
608 bgcolor: 'bgColor',
609 colspan: 'colSpan',
610 rowspan: 'rowSpan',
611 contenteditable: 'contentEditable',
612 crossorigin: 'crossOrigin',
613 datetime: 'dateTime',
614 formaction: 'formAction',
615 ismap: 'isMap',
616 maxlength: 'maxLength',
617 minlength: 'minLength',
618 novalidate: 'noValidate',
619 usemap: 'useMap',
620 for: 'htmlFor'
621};
622keys$1(HTML_ATTRIBUTES_TO_PROPERTY$1).forEach(attrName => {
623});
624/** version: 1.7.12 */
625
626/*
627 * Copyright (c) 2018, salesforce.com, inc.
628 * All rights reserved.
629 * SPDX-License-Identifier: MIT
630 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
631 */
632let nextTickCallbackQueue = [];
633const SPACE_CHAR = 32;
634const EmptyObject = seal$1(create$1(null));
635const EmptyArray = seal$1([]);
636
637function flushCallbackQueue() {
638 if (process.env.NODE_ENV !== 'production') {
639 if (nextTickCallbackQueue.length === 0) {
640 throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
641 }
642 }
643
644 const callbacks = nextTickCallbackQueue;
645 nextTickCallbackQueue = []; // reset to a new queue
646
647 for (let i = 0, len = callbacks.length; i < len; i += 1) {
648 callbacks[i]();
649 }
650}
651
652function addCallbackToNextTick(callback) {
653 if (process.env.NODE_ENV !== 'production') {
654 if (!isFunction$1(callback)) {
655 throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
656 }
657 }
658
659 if (nextTickCallbackQueue.length === 0) {
660 Promise.resolve().then(flushCallbackQueue);
661 }
662
663 ArrayPush$1.call(nextTickCallbackQueue, callback);
664}
665function guid() {
666 function s4() {
667 return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
668 }
669
670 return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
671}
672
673/*
674 * Copyright (c) 2019, salesforce.com, inc.
675 * All rights reserved.
676 * SPDX-License-Identifier: MIT
677 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
678 */
679const {
680 create: create$1$1
681} = Object;
682const {
683 splice: ArraySplice$1$1,
684 indexOf: ArrayIndexOf$1$1,
685 push: ArrayPush$1$1
686} = Array.prototype;
687const TargetToReactiveRecordMap = new WeakMap();
688
689function isUndefined$1$1(obj) {
690 return obj === undefined;
691}
692
693function getReactiveRecord(target) {
694 let reactiveRecord = TargetToReactiveRecordMap.get(target);
695
696 if (isUndefined$1$1(reactiveRecord)) {
697 const newRecord = create$1$1(null);
698 reactiveRecord = newRecord;
699 TargetToReactiveRecordMap.set(target, newRecord);
700 }
701
702 return reactiveRecord;
703}
704
705let currentReactiveObserver = null;
706function valueMutated(target, key) {
707 const reactiveRecord = TargetToReactiveRecordMap.get(target);
708
709 if (!isUndefined$1$1(reactiveRecord)) {
710 const reactiveObservers = reactiveRecord[key];
711
712 if (!isUndefined$1$1(reactiveObservers)) {
713 for (let i = 0, len = reactiveObservers.length; i < len; i += 1) {
714 const ro = reactiveObservers[i];
715 ro.notify();
716 }
717 }
718 }
719}
720function valueObserved(target, key) {
721 // We should determine if an active Observing Record is present to track mutations.
722 if (currentReactiveObserver === null) {
723 return;
724 }
725
726 const ro = currentReactiveObserver;
727 const reactiveRecord = getReactiveRecord(target);
728 let reactiveObservers = reactiveRecord[key];
729
730 if (isUndefined$1$1(reactiveObservers)) {
731 reactiveObservers = [];
732 reactiveRecord[key] = reactiveObservers;
733 } else if (reactiveObservers[0] === ro) {
734 return; // perf optimization considering that most subscriptions will come from the same record
735 }
736
737 if (ArrayIndexOf$1$1.call(reactiveObservers, ro) === -1) {
738 ro.link(reactiveObservers);
739 }
740}
741class ReactiveObserver {
742 constructor(callback) {
743 this.listeners = [];
744 this.callback = callback;
745 }
746
747 observe(job) {
748 const inceptionReactiveRecord = currentReactiveObserver;
749 currentReactiveObserver = this;
750 let error;
751
752 try {
753 job();
754 } catch (e) {
755 error = Object(e);
756 } finally {
757 currentReactiveObserver = inceptionReactiveRecord;
758
759 if (error !== undefined) {
760 throw error; // eslint-disable-line no-unsafe-finally
761 }
762 }
763 }
764 /**
765 * This method is responsible for disconnecting the Reactive Observer
766 * from any Reactive Record that has a reference to it, to prevent future
767 * notifications about previously recorded access.
768 */
769
770
771 reset() {
772 const {
773 listeners
774 } = this;
775 const len = listeners.length;
776
777 if (len > 0) {
778 for (let i = 0; i < len; i += 1) {
779 const set = listeners[i];
780 const pos = ArrayIndexOf$1$1.call(listeners[i], this);
781 ArraySplice$1$1.call(set, pos, 1);
782 }
783
784 listeners.length = 0;
785 }
786 } // friend methods
787
788
789 notify() {
790 this.callback.call(undefined, this);
791 }
792
793 link(reactiveObservers) {
794 ArrayPush$1$1.call(reactiveObservers, this); // we keep track of observing records where the observing record was added to so we can do some clean up later on
795
796 ArrayPush$1$1.call(this.listeners, reactiveObservers);
797 }
798
799}
800
801/*
802 * Copyright (c) 2018, salesforce.com, inc.
803 * All rights reserved.
804 * SPDX-License-Identifier: MIT
805 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
806 */
807function componentValueMutated(vm, key) {
808 valueMutated(vm.component, key);
809}
810function componentValueObserved(vm, key) {
811 valueObserved(vm.component, key);
812}
813
814/*
815 * Copyright (c) 2018, salesforce.com, inc.
816 * All rights reserved.
817 * SPDX-License-Identifier: MIT
818 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
819 */
820function getComponentTag(vm) {
821 return `<${StringToLowerCase$1.call(vm.tagName)}>`;
822} // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
823
824function getComponentStack(vm) {
825 const stack = [];
826 let prefix = '';
827
828 while (!isNull$1(vm.owner)) {
829 ArrayPush$1.call(stack, prefix + getComponentTag(vm));
830 vm = vm.owner;
831 prefix += '\t';
832 }
833
834 return ArrayJoin$1.call(stack, '\n');
835}
836function getErrorComponentStack(vm) {
837 const wcStack = [];
838 let currentVm = vm;
839
840 while (!isNull$1(currentVm)) {
841 ArrayPush$1.call(wcStack, getComponentTag(currentVm));
842 currentVm = currentVm.owner;
843 }
844
845 return wcStack.reverse().join('\n\t');
846}
847
848/*
849 * Copyright (c) 2018, salesforce.com, inc.
850 * All rights reserved.
851 * SPDX-License-Identifier: MIT
852 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
853 */
854function logError(message, vm) {
855 let msg = `[LWC error]: ${message}`;
856
857 if (!isUndefined$1(vm)) {
858 msg = `${msg}\n${getComponentStack(vm)}`;
859 }
860
861 if (process.env.NODE_ENV === 'test') {
862 /* eslint-disable-next-line no-console */
863 console.error(msg);
864 return;
865 }
866
867 try {
868 throw new Error(msg);
869 } catch (e) {
870 /* eslint-disable-next-line no-console */
871 console.error(e);
872 }
873}
874
875/*
876 * Copyright (c) 2018, salesforce.com, inc.
877 * All rights reserved.
878 * SPDX-License-Identifier: MIT
879 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
880 */
881
882function handleEvent(event, vnode) {
883 const {
884 type
885 } = event;
886 const {
887 data: {
888 on
889 }
890 } = vnode;
891 const handler = on && on[type]; // call event handler if exists
892
893 if (handler) {
894 handler.call(undefined, event);
895 }
896}
897
898function createListener() {
899 return function handler(event) {
900 handleEvent(event, handler.vnode);
901 };
902}
903
904function updateAllEventListeners(oldVnode, vnode) {
905 if (isUndefined$1(oldVnode.listener)) {
906 createAllEventListeners(vnode);
907 } else {
908 vnode.listener = oldVnode.listener;
909 vnode.listener.vnode = vnode;
910 }
911}
912
913function createAllEventListeners(vnode) {
914 const {
915 elm,
916 data: {
917 on
918 },
919 owner: {
920 renderer
921 }
922 } = vnode;
923
924 if (isUndefined$1(on)) {
925 return;
926 }
927
928 const listener = vnode.listener = createListener();
929 listener.vnode = vnode;
930 let name;
931
932 for (name in on) {
933 renderer.addEventListener(elm, name, listener);
934 }
935}
936
937var modEvents = {
938 update: updateAllEventListeners,
939 create: createAllEventListeners
940};
941
942/*
943 * Copyright (c) 2018, salesforce.com, inc.
944 * All rights reserved.
945 * SPDX-License-Identifier: MIT
946 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
947 */
948
949const defaultDefHTMLPropertyNames = ['accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title']; // Few more exceptions that are using the attribute name to match the property in lowercase.
950// this list was compiled from https://msdn.microsoft.com/en-us/library/ms533062(v=vs.85).aspx
951// and https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
952// Note: this list most be in sync with the compiler as well.
953
954const HTMLPropertyNamesWithLowercasedReflectiveAttributes = ['accessKey', 'readOnly', 'tabIndex', 'bgColor', 'colSpan', 'rowSpan', 'contentEditable', 'dateTime', 'formAction', 'isMap', 'maxLength', 'useMap'];
955
956function offsetPropertyErrorMessage(name) {
957 return `Using the \`${name}\` property is an anti-pattern because it rounds the value to an integer. Instead, use the \`getBoundingClientRect\` method to obtain fractional values for the size of an element and its position relative to the viewport.`;
958} // Global HTML Attributes & Properties
959// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
960// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
961
962
963const globalHTMLProperties = assign$1(create$1(null), {
964 accessKey: {
965 attribute: 'accesskey'
966 },
967 accessKeyLabel: {
968 readOnly: true
969 },
970 className: {
971 attribute: 'class',
972 error: 'Using the `className` property is an anti-pattern because of slow runtime behavior and potential conflicts with classes provided by the owner element. Use the `classList` API instead.'
973 },
974 contentEditable: {
975 attribute: 'contenteditable'
976 },
977 dataset: {
978 readOnly: true,
979 error: "Using the `dataset` property is an anti-pattern because it can't be statically analyzed. Expose each property individually using the `@api` decorator instead."
980 },
981 dir: {
982 attribute: 'dir'
983 },
984 draggable: {
985 attribute: 'draggable'
986 },
987 dropzone: {
988 attribute: 'dropzone',
989 readOnly: true
990 },
991 hidden: {
992 attribute: 'hidden'
993 },
994 id: {
995 attribute: 'id'
996 },
997 inputMode: {
998 attribute: 'inputmode'
999 },
1000 lang: {
1001 attribute: 'lang'
1002 },
1003 slot: {
1004 attribute: 'slot',
1005 error: 'Using the `slot` property is an anti-pattern.'
1006 },
1007 spellcheck: {
1008 attribute: 'spellcheck'
1009 },
1010 style: {
1011 attribute: 'style'
1012 },
1013 tabIndex: {
1014 attribute: 'tabindex'
1015 },
1016 title: {
1017 attribute: 'title'
1018 },
1019 translate: {
1020 attribute: 'translate'
1021 },
1022 // additional "global attributes" that are not present in the link above.
1023 isContentEditable: {
1024 readOnly: true
1025 },
1026 offsetHeight: {
1027 readOnly: true,
1028 error: offsetPropertyErrorMessage('offsetHeight')
1029 },
1030 offsetLeft: {
1031 readOnly: true,
1032 error: offsetPropertyErrorMessage('offsetLeft')
1033 },
1034 offsetParent: {
1035 readOnly: true
1036 },
1037 offsetTop: {
1038 readOnly: true,
1039 error: offsetPropertyErrorMessage('offsetTop')
1040 },
1041 offsetWidth: {
1042 readOnly: true,
1043 error: offsetPropertyErrorMessage('offsetWidth')
1044 },
1045 role: {
1046 attribute: 'role'
1047 }
1048});
1049const AttrNameToPropNameMap$1$1 = assign$1(create$1(null), AttrNameToPropNameMap$1);
1050const PropNameToAttrNameMap$1$1 = assign$1(create$1(null), PropNameToAttrNameMap$1);
1051forEach$1.call(defaultDefHTMLPropertyNames, propName => {
1052 const attrName = StringToLowerCase$1.call(propName);
1053 AttrNameToPropNameMap$1$1[attrName] = propName;
1054 PropNameToAttrNameMap$1$1[propName] = attrName;
1055});
1056forEach$1.call(HTMLPropertyNamesWithLowercasedReflectiveAttributes, propName => {
1057 const attrName = StringToLowerCase$1.call(propName);
1058 AttrNameToPropNameMap$1$1[attrName] = propName;
1059 PropNameToAttrNameMap$1$1[propName] = attrName;
1060});
1061const CAPS_REGEX = /[A-Z]/g;
1062/**
1063 * This method maps between property names
1064 * and the corresponding attribute name.
1065 */
1066
1067function getAttrNameFromPropName(propName) {
1068 if (isUndefined$1(PropNameToAttrNameMap$1$1[propName])) {
1069 PropNameToAttrNameMap$1$1[propName] = StringReplace$1.call(propName, CAPS_REGEX, match => '-' + match.toLowerCase());
1070 }
1071
1072 return PropNameToAttrNameMap$1$1[propName];
1073}
1074
1075/*
1076 * Copyright (c) 2018, salesforce.com, inc.
1077 * All rights reserved.
1078 * SPDX-License-Identifier: MIT
1079 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1080 */
1081const xlinkNS = 'http://www.w3.org/1999/xlink';
1082const xmlNS = 'http://www.w3.org/XML/1998/namespace';
1083const ColonCharCode = 58;
1084
1085function updateAttrs(oldVnode, vnode) {
1086 const {
1087 data: {
1088 attrs
1089 },
1090 owner: {
1091 renderer
1092 }
1093 } = vnode;
1094
1095 if (isUndefined$1(attrs)) {
1096 return;
1097 }
1098
1099 let {
1100 data: {
1101 attrs: oldAttrs
1102 }
1103 } = oldVnode;
1104
1105 if (oldAttrs === attrs) {
1106 return;
1107 }
1108
1109 if (process.env.NODE_ENV !== 'production') {
1110 assert.invariant(isUndefined$1(oldAttrs) || keys$1(oldAttrs).join(',') === keys$1(attrs).join(','), `vnode.data.attrs cannot change shape.`);
1111 }
1112
1113 const elm = vnode.elm;
1114 const {
1115 setAttribute,
1116 removeAttribute
1117 } = renderer;
1118 let key;
1119 oldAttrs = isUndefined$1(oldAttrs) ? EmptyObject : oldAttrs; // update modified attributes, add new attributes
1120 // this routine is only useful for data-* attributes in all kind of elements
1121 // and aria-* in standard elements (custom elements will use props for these)
1122
1123 for (key in attrs) {
1124 const cur = attrs[key];
1125 const old = oldAttrs[key];
1126
1127 if (old !== cur) {
1128
1129 if (StringCharCodeAt$1.call(key, 3) === ColonCharCode) {
1130 // Assume xml namespace
1131 setAttribute(elm, key, cur, xmlNS);
1132 } else if (StringCharCodeAt$1.call(key, 5) === ColonCharCode) {
1133 // Assume xlink namespace
1134 setAttribute(elm, key, cur, xlinkNS);
1135 } else if (isNull$1(cur)) {
1136 removeAttribute(elm, key);
1137 } else {
1138 setAttribute(elm, key, cur);
1139 }
1140 }
1141 }
1142}
1143
1144const emptyVNode = {
1145 data: {}
1146};
1147var modAttrs = {
1148 create: vnode => updateAttrs(emptyVNode, vnode),
1149 update: updateAttrs
1150};
1151
1152/*
1153 * Copyright (c) 2018, salesforce.com, inc.
1154 * All rights reserved.
1155 * SPDX-License-Identifier: MIT
1156 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1157 */
1158
1159function isLiveBindingProp(sel, key) {
1160 // For properties with live bindings, we read values from the DOM element
1161 // instead of relying on internally tracked values.
1162 return sel === 'input' && (key === 'value' || key === 'checked');
1163}
1164
1165function update(oldVnode, vnode) {
1166 const props = vnode.data.props;
1167
1168 if (isUndefined$1(props)) {
1169 return;
1170 }
1171
1172 const oldProps = oldVnode.data.props;
1173
1174 if (oldProps === props) {
1175 return;
1176 }
1177
1178 if (process.env.NODE_ENV !== 'production') {
1179 assert.invariant(isUndefined$1(oldProps) || keys$1(oldProps).join(',') === keys$1(props).join(','), 'vnode.data.props cannot change shape.');
1180 }
1181
1182 const isFirstPatch = isUndefined$1(oldProps);
1183 const {
1184 elm,
1185 sel,
1186 owner: {
1187 renderer
1188 }
1189 } = vnode;
1190
1191 for (const key in props) {
1192 const cur = props[key]; // if it is the first time this element is patched, or the current value is different to the previous value...
1193
1194 if (isFirstPatch || cur !== (isLiveBindingProp(sel, key) ? renderer.getProperty(elm, key) : oldProps[key])) {
1195 renderer.setProperty(elm, key, cur);
1196 }
1197 }
1198}
1199
1200const emptyVNode$1 = {
1201 data: {}
1202};
1203var modProps = {
1204 create: vnode => update(emptyVNode$1, vnode),
1205 update
1206};
1207
1208/*
1209 * Copyright (c) 2018, salesforce.com, inc.
1210 * All rights reserved.
1211 * SPDX-License-Identifier: MIT
1212 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1213 */
1214const classNameToClassMap = create$1(null);
1215
1216function getMapFromClassName(className) {
1217 // Intentionally using == to match undefined and null values from computed style attribute
1218 if (className == null) {
1219 return EmptyObject;
1220 } // computed class names must be string
1221
1222
1223 className = isString$1(className) ? className : className + '';
1224 let map = classNameToClassMap[className];
1225
1226 if (map) {
1227 return map;
1228 }
1229
1230 map = create$1(null);
1231 let start = 0;
1232 let o;
1233 const len = className.length;
1234
1235 for (o = 0; o < len; o++) {
1236 if (StringCharCodeAt$1.call(className, o) === SPACE_CHAR) {
1237 if (o > start) {
1238 map[StringSlice$1.call(className, start, o)] = true;
1239 }
1240
1241 start = o + 1;
1242 }
1243 }
1244
1245 if (o > start) {
1246 map[StringSlice$1.call(className, start, o)] = true;
1247 }
1248
1249 classNameToClassMap[className] = map;
1250
1251 if (process.env.NODE_ENV !== 'production') {
1252 // just to make sure that this object never changes as part of the diffing algo
1253 freeze$1(map);
1254 }
1255
1256 return map;
1257}
1258
1259function updateClassAttribute(oldVnode, vnode) {
1260 const {
1261 elm,
1262 data: {
1263 className: newClass
1264 },
1265 owner: {
1266 renderer
1267 }
1268 } = vnode;
1269 const {
1270 data: {
1271 className: oldClass
1272 }
1273 } = oldVnode;
1274
1275 if (oldClass === newClass) {
1276 return;
1277 }
1278
1279 const classList = renderer.getClassList(elm);
1280 const newClassMap = getMapFromClassName(newClass);
1281 const oldClassMap = getMapFromClassName(oldClass);
1282 let name;
1283
1284 for (name in oldClassMap) {
1285 // remove only if it is not in the new class collection and it is not set from within the instance
1286 if (isUndefined$1(newClassMap[name])) {
1287 classList.remove(name);
1288 }
1289 }
1290
1291 for (name in newClassMap) {
1292 if (isUndefined$1(oldClassMap[name])) {
1293 classList.add(name);
1294 }
1295 }
1296}
1297
1298const emptyVNode$2 = {
1299 data: {}
1300};
1301var modComputedClassName = {
1302 create: vnode => updateClassAttribute(emptyVNode$2, vnode),
1303 update: updateClassAttribute
1304};
1305
1306/*
1307 * Copyright (c) 2018, salesforce.com, inc.
1308 * All rights reserved.
1309 * SPDX-License-Identifier: MIT
1310 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1311 */
1312
1313function updateStyleAttribute(oldVnode, vnode) {
1314 const {
1315 elm,
1316 data: {
1317 style: newStyle
1318 },
1319 owner: {
1320 renderer
1321 }
1322 } = vnode;
1323 const {
1324 getStyleDeclaration,
1325 removeAttribute
1326 } = renderer;
1327
1328 if (oldVnode.data.style === newStyle) {
1329 return;
1330 }
1331
1332 const style = getStyleDeclaration(elm);
1333
1334 if (!isString$1(newStyle) || newStyle === '') {
1335 removeAttribute(elm, 'style');
1336 } else {
1337 style.cssText = newStyle;
1338 }
1339}
1340
1341const emptyVNode$3 = {
1342 data: {}
1343};
1344var modComputedStyle = {
1345 create: vnode => updateStyleAttribute(emptyVNode$3, vnode),
1346 update: updateStyleAttribute
1347};
1348
1349/*
1350 * Copyright (c) 2018, salesforce.com, inc.
1351 * All rights reserved.
1352 * SPDX-License-Identifier: MIT
1353 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1354 */
1355// The compiler takes care of transforming the inline classnames into an object. It's faster to set the
1356// different classnames properties individually instead of via a string.
1357
1358function createClassAttribute(vnode) {
1359 const {
1360 elm,
1361 data: {
1362 classMap
1363 },
1364 owner: {
1365 renderer
1366 }
1367 } = vnode;
1368
1369 if (isUndefined$1(classMap)) {
1370 return;
1371 }
1372
1373 const classList = renderer.getClassList(elm);
1374
1375 for (const name in classMap) {
1376 classList.add(name);
1377 }
1378}
1379
1380var modStaticClassName = {
1381 create: createClassAttribute
1382};
1383
1384/*
1385 * Copyright (c) 2018, salesforce.com, inc.
1386 * All rights reserved.
1387 * SPDX-License-Identifier: MIT
1388 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1389 */
1390// The compiler takes care of transforming the inline style into an object. It's faster to set the
1391// different style properties individually instead of via a string.
1392
1393function createStyleAttribute(vnode) {
1394 const {
1395 elm,
1396 data: {
1397 styleMap
1398 },
1399 owner: {
1400 renderer
1401 }
1402 } = vnode;
1403
1404 if (isUndefined$1(styleMap)) {
1405 return;
1406 }
1407
1408 const style = renderer.getStyleDeclaration(elm);
1409
1410 for (const name in styleMap) {
1411 style[name] = styleMap[name];
1412 }
1413}
1414
1415var modStaticStyle = {
1416 create: createStyleAttribute
1417};
1418
1419/*
1420 * Copyright (c) 2018, salesforce.com, inc.
1421 * All rights reserved.
1422 * SPDX-License-Identifier: MIT
1423 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1424 */
1425
1426/**
1427@license
1428Copyright (c) 2015 Simon Friis Vindum.
1429This code may only be used under the MIT License found at
1430https://github.com/snabbdom/snabbdom/blob/master/LICENSE
1431Code distributed by Snabbdom as part of the Snabbdom project at
1432https://github.com/snabbdom/snabbdom/
1433*/
1434function isUndef(s) {
1435 return s === undefined;
1436}
1437
1438function sameVnode(vnode1, vnode2) {
1439 return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
1440}
1441
1442function isVNode(vnode) {
1443 return vnode != null;
1444}
1445
1446function createKeyToOldIdx(children, beginIdx, endIdx) {
1447 const map = {};
1448 let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
1449
1450 for (j = beginIdx; j <= endIdx; ++j) {
1451 ch = children[j];
1452
1453 if (isVNode(ch)) {
1454 key = ch.key;
1455
1456 if (key !== undefined) {
1457 map[key] = j;
1458 }
1459 }
1460 }
1461
1462 return map;
1463}
1464
1465function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
1466 for (; startIdx <= endIdx; ++startIdx) {
1467 const ch = vnodes[startIdx];
1468
1469 if (isVNode(ch)) {
1470 ch.hook.create(ch);
1471 ch.hook.insert(ch, parentElm, before);
1472 }
1473 }
1474}
1475
1476function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
1477 for (; startIdx <= endIdx; ++startIdx) {
1478 const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
1479
1480 if (isVNode(ch)) {
1481 ch.hook.remove(ch, parentElm);
1482 }
1483 }
1484}
1485
1486function updateDynamicChildren(parentElm, oldCh, newCh) {
1487 let oldStartIdx = 0;
1488 let newStartIdx = 0;
1489 let oldEndIdx = oldCh.length - 1;
1490 let oldStartVnode = oldCh[0];
1491 let oldEndVnode = oldCh[oldEndIdx];
1492 let newEndIdx = newCh.length - 1;
1493 let newStartVnode = newCh[0];
1494 let newEndVnode = newCh[newEndIdx];
1495 let oldKeyToIdx;
1496 let idxInOld;
1497 let elmToMove;
1498 let before;
1499
1500 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1501 if (!isVNode(oldStartVnode)) {
1502 oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
1503 } else if (!isVNode(oldEndVnode)) {
1504 oldEndVnode = oldCh[--oldEndIdx];
1505 } else if (!isVNode(newStartVnode)) {
1506 newStartVnode = newCh[++newStartIdx];
1507 } else if (!isVNode(newEndVnode)) {
1508 newEndVnode = newCh[--newEndIdx];
1509 } else if (sameVnode(oldStartVnode, newStartVnode)) {
1510 patchVnode(oldStartVnode, newStartVnode);
1511 oldStartVnode = oldCh[++oldStartIdx];
1512 newStartVnode = newCh[++newStartIdx];
1513 } else if (sameVnode(oldEndVnode, newEndVnode)) {
1514 patchVnode(oldEndVnode, newEndVnode);
1515 oldEndVnode = oldCh[--oldEndIdx];
1516 newEndVnode = newCh[--newEndIdx];
1517 } else if (sameVnode(oldStartVnode, newEndVnode)) {
1518 // Vnode moved right
1519 patchVnode(oldStartVnode, newEndVnode);
1520 newEndVnode.hook.move(oldStartVnode, parentElm, oldEndVnode.owner.renderer.nextSibling(oldEndVnode.elm));
1521 oldStartVnode = oldCh[++oldStartIdx];
1522 newEndVnode = newCh[--newEndIdx];
1523 } else if (sameVnode(oldEndVnode, newStartVnode)) {
1524 // Vnode moved left
1525 patchVnode(oldEndVnode, newStartVnode);
1526 newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
1527 oldEndVnode = oldCh[--oldEndIdx];
1528 newStartVnode = newCh[++newStartIdx];
1529 } else {
1530 if (oldKeyToIdx === undefined) {
1531 oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
1532 }
1533
1534 idxInOld = oldKeyToIdx[newStartVnode.key];
1535
1536 if (isUndef(idxInOld)) {
1537 // New element
1538 newStartVnode.hook.create(newStartVnode);
1539 newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1540 newStartVnode = newCh[++newStartIdx];
1541 } else {
1542 elmToMove = oldCh[idxInOld];
1543
1544 if (isVNode(elmToMove)) {
1545 if (elmToMove.sel !== newStartVnode.sel) {
1546 // New element
1547 newStartVnode.hook.create(newStartVnode);
1548 newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1549 } else {
1550 patchVnode(elmToMove, newStartVnode);
1551 oldCh[idxInOld] = undefined;
1552 newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
1553 }
1554 }
1555
1556 newStartVnode = newCh[++newStartIdx];
1557 }
1558 }
1559 }
1560
1561 if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
1562 if (oldStartIdx > oldEndIdx) {
1563 const n = newCh[newEndIdx + 1];
1564 before = isVNode(n) ? n.elm : null;
1565 addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
1566 } else {
1567 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
1568 }
1569 }
1570}
1571function updateStaticChildren(parentElm, oldCh, newCh) {
1572 const {
1573 length
1574 } = newCh;
1575
1576 if (oldCh.length === 0) {
1577 // the old list is empty, we can directly insert anything new
1578 addVnodes(parentElm, null, newCh, 0, length);
1579 return;
1580 } // if the old list is not empty, the new list MUST have the same
1581 // amount of nodes, that's why we call this static children
1582
1583
1584 let referenceElm = null;
1585
1586 for (let i = length - 1; i >= 0; i -= 1) {
1587 const vnode = newCh[i];
1588 const oldVNode = oldCh[i];
1589
1590 if (vnode !== oldVNode) {
1591 if (isVNode(oldVNode)) {
1592 if (isVNode(vnode)) {
1593 // both vnodes must be equivalent, and se just need to patch them
1594 patchVnode(oldVNode, vnode);
1595 referenceElm = vnode.elm;
1596 } else {
1597 // removing the old vnode since the new one is null
1598 oldVNode.hook.remove(oldVNode, parentElm);
1599 }
1600 } else if (isVNode(vnode)) {
1601 // this condition is unnecessary
1602 vnode.hook.create(vnode); // insert the new node one since the old one is null
1603
1604 vnode.hook.insert(vnode, parentElm, referenceElm);
1605 referenceElm = vnode.elm;
1606 }
1607 }
1608 }
1609}
1610
1611function patchVnode(oldVnode, vnode) {
1612 if (oldVnode !== vnode) {
1613 vnode.elm = oldVnode.elm;
1614 vnode.hook.update(oldVnode, vnode);
1615 }
1616}
1617
1618/*
1619 * Copyright (c) 2018, salesforce.com, inc.
1620 * All rights reserved.
1621 * SPDX-License-Identifier: MIT
1622 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1623 */
1624
1625function generateDataDescriptor(options) {
1626 return assign$1({
1627 configurable: true,
1628 enumerable: true,
1629 writable: true
1630 }, options);
1631}
1632
1633function generateAccessorDescriptor(options) {
1634 return assign$1({
1635 configurable: true,
1636 enumerable: true
1637 }, options);
1638}
1639
1640let isDomMutationAllowed = false;
1641function unlockDomMutation() {
1642 if (process.env.NODE_ENV === 'production') {
1643 // this method should never leak to prod
1644 throw new ReferenceError();
1645 }
1646
1647 isDomMutationAllowed = true;
1648}
1649function lockDomMutation() {
1650 if (process.env.NODE_ENV === 'production') {
1651 // this method should never leak to prod
1652 throw new ReferenceError();
1653 }
1654
1655 isDomMutationAllowed = false;
1656}
1657
1658function logMissingPortalError(name, type) {
1659 return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
1660}
1661
1662function patchElementWithRestrictions(elm, options) {
1663 if (process.env.NODE_ENV === 'production') {
1664 // this method should never leak to prod
1665 throw new ReferenceError();
1666 }
1667
1668 const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1669 const descriptors = {
1670 outerHTML: generateAccessorDescriptor({
1671 get() {
1672 return originalOuterHTMLDescriptor.get.call(this);
1673 },
1674
1675 set(_value) {
1676 throw new TypeError(`Invalid attempt to set outerHTML on Element.`);
1677 }
1678
1679 })
1680 }; // Apply extra restriction related to DOM manipulation if the element is not a portal.
1681
1682 if (isFalse$1(options.isPortal)) {
1683 const {
1684 appendChild,
1685 insertBefore,
1686 removeChild,
1687 replaceChild
1688 } = elm;
1689 const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue');
1690 const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1691 const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1692 assign$1(descriptors, {
1693 appendChild: generateDataDescriptor({
1694 value(aChild) {
1695 logMissingPortalError('appendChild', 'method');
1696 return appendChild.call(this, aChild);
1697 }
1698
1699 }),
1700 insertBefore: generateDataDescriptor({
1701 value(newNode, referenceNode) {
1702 if (!isDomMutationAllowed) {
1703 logMissingPortalError('insertBefore', 'method');
1704 }
1705
1706 return insertBefore.call(this, newNode, referenceNode);
1707 }
1708
1709 }),
1710 removeChild: generateDataDescriptor({
1711 value(aChild) {
1712 if (!isDomMutationAllowed) {
1713 logMissingPortalError('removeChild', 'method');
1714 }
1715
1716 return removeChild.call(this, aChild);
1717 }
1718
1719 }),
1720 replaceChild: generateDataDescriptor({
1721 value(newChild, oldChild) {
1722 logMissingPortalError('replaceChild', 'method');
1723 return replaceChild.call(this, newChild, oldChild);
1724 }
1725
1726 }),
1727 nodeValue: generateAccessorDescriptor({
1728 get() {
1729 return originalNodeValueDescriptor.get.call(this);
1730 },
1731
1732 set(value) {
1733 if (!isDomMutationAllowed) {
1734 logMissingPortalError('nodeValue', 'property');
1735 }
1736
1737 originalNodeValueDescriptor.set.call(this, value);
1738 }
1739
1740 }),
1741 textContent: generateAccessorDescriptor({
1742 get() {
1743 return originalTextContentDescriptor.get.call(this);
1744 },
1745
1746 set(value) {
1747 logMissingPortalError('textContent', 'property');
1748 originalTextContentDescriptor.set.call(this, value);
1749 }
1750
1751 }),
1752 innerHTML: generateAccessorDescriptor({
1753 get() {
1754 return originalInnerHTMLDescriptor.get.call(this);
1755 },
1756
1757 set(value) {
1758 logMissingPortalError('innerHTML', 'property');
1759 return originalInnerHTMLDescriptor.set.call(this, value);
1760 }
1761
1762 })
1763 });
1764 }
1765
1766 defineProperties$1(elm, descriptors);
1767}
1768const BLOCKED_SHADOW_ROOT_METHODS = ['cloneNode', 'getElementById', 'getSelection', 'elementsFromPoint', 'dispatchEvent'];
1769
1770function getShadowRootRestrictionsDescriptors(sr) {
1771 if (process.env.NODE_ENV === 'production') {
1772 // this method should never leak to prod
1773 throw new ReferenceError();
1774 } // Disallowing properties in dev mode only to avoid people doing the wrong
1775 // thing when using the real shadow root, because if that's the case,
1776 // the component will not work when running with synthetic shadow.
1777
1778
1779 const originalAddEventListener = sr.addEventListener;
1780 const originalInnerHTMLDescriptor = getPropertyDescriptor(sr, 'innerHTML');
1781 const originalTextContentDescriptor = getPropertyDescriptor(sr, 'textContent');
1782 const descriptors = {
1783 innerHTML: generateAccessorDescriptor({
1784 get() {
1785 return originalInnerHTMLDescriptor.get.call(this);
1786 },
1787
1788 set(_value) {
1789 throw new TypeError(`Invalid attempt to set innerHTML on ShadowRoot.`);
1790 }
1791
1792 }),
1793 textContent: generateAccessorDescriptor({
1794 get() {
1795 return originalTextContentDescriptor.get.call(this);
1796 },
1797
1798 set(_value) {
1799 throw new TypeError(`Invalid attempt to set textContent on ShadowRoot.`);
1800 }
1801
1802 }),
1803 addEventListener: generateDataDescriptor({
1804 value(type, listener, options) {
1805 // TODO [#420]: this is triggered when the component author attempts to add a listener
1806 // programmatically into its Component's shadow root
1807 if (!isUndefined$1(options)) {
1808 logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
1809 } // Typescript does not like it when you treat the `arguments` object as an array
1810 // @ts-ignore type-mismatch
1811
1812
1813 return originalAddEventListener.apply(this, arguments);
1814 }
1815
1816 })
1817 };
1818 forEach$1.call(BLOCKED_SHADOW_ROOT_METHODS, methodName => {
1819 descriptors[methodName] = generateAccessorDescriptor({
1820 get() {
1821 throw new Error(`Disallowed method "${methodName}" in ShadowRoot.`);
1822 }
1823
1824 });
1825 });
1826 return descriptors;
1827} // Custom Elements Restrictions:
1828// -----------------------------
1829
1830
1831function getCustomElementRestrictionsDescriptors(elm) {
1832 if (process.env.NODE_ENV === 'production') {
1833 // this method should never leak to prod
1834 throw new ReferenceError();
1835 }
1836
1837 const originalAddEventListener = elm.addEventListener;
1838 const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1839 const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1840 const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1841 return {
1842 innerHTML: generateAccessorDescriptor({
1843 get() {
1844 return originalInnerHTMLDescriptor.get.call(this);
1845 },
1846
1847 set(_value) {
1848 throw new TypeError(`Invalid attempt to set innerHTML on HTMLElement.`);
1849 }
1850
1851 }),
1852 outerHTML: generateAccessorDescriptor({
1853 get() {
1854 return originalOuterHTMLDescriptor.get.call(this);
1855 },
1856
1857 set(_value) {
1858 throw new TypeError(`Invalid attempt to set outerHTML on HTMLElement.`);
1859 }
1860
1861 }),
1862 textContent: generateAccessorDescriptor({
1863 get() {
1864 return originalTextContentDescriptor.get.call(this);
1865 },
1866
1867 set(_value) {
1868 throw new TypeError(`Invalid attempt to set textContent on HTMLElement.`);
1869 }
1870
1871 }),
1872 addEventListener: generateDataDescriptor({
1873 value(type, listener, options) {
1874 // TODO [#420]: this is triggered when the component author attempts to add a listener
1875 // programmatically into a lighting element node
1876 if (!isUndefined$1(options)) {
1877 logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
1878 } // Typescript does not like it when you treat the `arguments` object as an array
1879 // @ts-ignore type-mismatch
1880
1881
1882 return originalAddEventListener.apply(this, arguments);
1883 }
1884
1885 })
1886 };
1887}
1888
1889function getComponentRestrictionsDescriptors() {
1890 if (process.env.NODE_ENV === 'production') {
1891 // this method should never leak to prod
1892 throw new ReferenceError();
1893 }
1894
1895 return {
1896 tagName: generateAccessorDescriptor({
1897 get() {
1898 throw new Error(`Usage of property \`tagName\` is disallowed because the component itself does` + ` not know which tagName will be used to create the element, therefore writing` + ` code that check for that value is error prone.`);
1899 },
1900
1901 configurable: true,
1902 enumerable: false
1903 })
1904 };
1905}
1906
1907function getLightningElementPrototypeRestrictionsDescriptors(proto) {
1908 if (process.env.NODE_ENV === 'production') {
1909 // this method should never leak to prod
1910 throw new ReferenceError();
1911 }
1912
1913 const originalDispatchEvent = proto.dispatchEvent;
1914 const descriptors = {
1915 dispatchEvent: generateDataDescriptor({
1916 value(event) {
1917 const vm = getAssociatedVM(this);
1918
1919 if (!isNull$1(event) && isObject$1(event)) {
1920 const {
1921 type
1922 } = event;
1923
1924 if (!/^[a-z][a-z0-9_]*$/.test(type)) {
1925 logError(`Invalid event type "${type}" dispatched in element ${getComponentTag(vm)}.` + ` Event name must start with a lowercase letter and followed only lowercase` + ` letters, numbers, and underscores`, vm);
1926 }
1927 } // Typescript does not like it when you treat the `arguments` object as an array
1928 // @ts-ignore type-mismatch
1929
1930
1931 return originalDispatchEvent.apply(this, arguments);
1932 }
1933
1934 })
1935 };
1936 forEach$1.call(getOwnPropertyNames$1(globalHTMLProperties), propName => {
1937 if (propName in proto) {
1938 return; // no need to redefine something that we are already exposing
1939 }
1940
1941 descriptors[propName] = generateAccessorDescriptor({
1942 get() {
1943 const {
1944 error,
1945 attribute
1946 } = globalHTMLProperties[propName];
1947 const msg = [];
1948 msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
1949
1950 if (error) {
1951 msg.push(error);
1952 } else if (attribute) {
1953 msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
1954 }
1955
1956 logError(msg.join('\n'), getAssociatedVM(this));
1957 },
1958
1959 set() {
1960 const {
1961 readOnly
1962 } = globalHTMLProperties[propName];
1963
1964 if (readOnly) {
1965 logError(`The global HTML property \`${propName}\` is read-only.`, getAssociatedVM(this));
1966 }
1967 }
1968
1969 });
1970 });
1971 return descriptors;
1972} // This routine will prevent access to certain properties on a shadow root instance to guarantee
1973// that all components will work fine in IE11 and other browsers without shadow dom support.
1974
1975
1976function patchShadowRootWithRestrictions(sr) {
1977 defineProperties$1(sr, getShadowRootRestrictionsDescriptors(sr));
1978}
1979function patchCustomElementWithRestrictions(elm) {
1980 const restrictionsDescriptors = getCustomElementRestrictionsDescriptors(elm);
1981 const elmProto = getPrototypeOf$1(elm);
1982 setPrototypeOf$1(elm, create$1(elmProto, restrictionsDescriptors));
1983}
1984function patchComponentWithRestrictions(cmp) {
1985 defineProperties$1(cmp, getComponentRestrictionsDescriptors());
1986}
1987function patchLightningElementPrototypeWithRestrictions(proto) {
1988 defineProperties$1(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
1989}
1990
1991/*
1992 * Copyright (c) 2020, salesforce.com, inc.
1993 * All rights reserved.
1994 * SPDX-License-Identifier: MIT
1995 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1996 */
1997// This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
1998// to inject at runtime.
1999const HTMLElementConstructor = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
2000const HTMLElementPrototype = HTMLElementConstructor.prototype;
2001
2002/*
2003 * Copyright (c) 2018, salesforce.com, inc.
2004 * All rights reserved.
2005 * SPDX-License-Identifier: MIT
2006 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2007 */
2008/**
2009 * This is a descriptor map that contains
2010 * all standard properties that a Custom Element can support (including AOM properties), which
2011 * determines what kind of capabilities the Base HTML Element and
2012 * Base Lightning Element should support.
2013 */
2014
2015const HTMLElementOriginalDescriptors = create$1(null);
2016forEach$1.call(keys$1(PropNameToAttrNameMap$1), propName => {
2017 // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
2018 // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
2019 const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
2020
2021 if (!isUndefined$1(descriptor)) {
2022 HTMLElementOriginalDescriptors[propName] = descriptor;
2023 }
2024});
2025forEach$1.call(defaultDefHTMLPropertyNames, propName => {
2026 // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
2027 // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
2028 // this category, so, better to be sure.
2029 const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
2030
2031 if (!isUndefined$1(descriptor)) {
2032 HTMLElementOriginalDescriptors[propName] = descriptor;
2033 }
2034});
2035
2036/**
2037 * Copyright (C) 2017 salesforce.com, inc.
2038 */
2039const {
2040 isArray: isArray$1
2041} = Array;
2042const {
2043 getPrototypeOf: getPrototypeOf$1$1,
2044 create: ObjectCreate,
2045 defineProperty: ObjectDefineProperty,
2046 defineProperties: ObjectDefineProperties,
2047 isExtensible,
2048 getOwnPropertyDescriptor: getOwnPropertyDescriptor$1$1,
2049 getOwnPropertyNames: getOwnPropertyNames$1$1,
2050 getOwnPropertySymbols,
2051 preventExtensions,
2052 hasOwnProperty: hasOwnProperty$1$1
2053} = Object;
2054const {
2055 push: ArrayPush$2,
2056 concat: ArrayConcat,
2057 map: ArrayMap$1$1
2058} = Array.prototype;
2059const OtS$1 = {}.toString;
2060
2061function toString$1(obj) {
2062 if (obj && obj.toString) {
2063 return obj.toString();
2064 } else if (typeof obj === 'object') {
2065 return OtS$1.call(obj);
2066 } else {
2067 return obj + '';
2068 }
2069}
2070
2071function isUndefined$2(obj) {
2072 return obj === undefined;
2073}
2074
2075function isFunction$1$1(obj) {
2076 return typeof obj === 'function';
2077}
2078
2079const proxyToValueMap = new WeakMap();
2080
2081function registerProxy(proxy, value) {
2082 proxyToValueMap.set(proxy, value);
2083}
2084
2085const unwrap = replicaOrAny => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
2086
2087class BaseProxyHandler {
2088 constructor(membrane, value) {
2089 this.originalTarget = value;
2090 this.membrane = membrane;
2091 } // Shared utility methods
2092
2093
2094 wrapDescriptor(descriptor) {
2095 if (hasOwnProperty$1$1.call(descriptor, 'value')) {
2096 descriptor.value = this.wrapValue(descriptor.value);
2097 } else {
2098 const {
2099 set: originalSet,
2100 get: originalGet
2101 } = descriptor;
2102
2103 if (!isUndefined$2(originalGet)) {
2104 descriptor.get = this.wrapGetter(originalGet);
2105 }
2106
2107 if (!isUndefined$2(originalSet)) {
2108 descriptor.set = this.wrapSetter(originalSet);
2109 }
2110 }
2111
2112 return descriptor;
2113 }
2114
2115 copyDescriptorIntoShadowTarget(shadowTarget, key) {
2116 const {
2117 originalTarget
2118 } = this; // Note: a property might get defined multiple times in the shadowTarget
2119 // but it will always be compatible with the previous descriptor
2120 // to preserve the object invariants, which makes these lines safe.
2121
2122 const originalDescriptor = getOwnPropertyDescriptor$1$1(originalTarget, key);
2123
2124 if (!isUndefined$2(originalDescriptor)) {
2125 const wrappedDesc = this.wrapDescriptor(originalDescriptor);
2126 ObjectDefineProperty(shadowTarget, key, wrappedDesc);
2127 }
2128 }
2129
2130 lockShadowTarget(shadowTarget) {
2131 const {
2132 originalTarget
2133 } = this;
2134 const targetKeys = ArrayConcat.call(getOwnPropertyNames$1$1(originalTarget), getOwnPropertySymbols(originalTarget));
2135 targetKeys.forEach(key => {
2136 this.copyDescriptorIntoShadowTarget(shadowTarget, key);
2137 });
2138 const {
2139 membrane: {
2140 tagPropertyKey
2141 }
2142 } = this;
2143
2144 if (!isUndefined$2(tagPropertyKey) && !hasOwnProperty$1$1.call(shadowTarget, tagPropertyKey)) {
2145 ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
2146 }
2147
2148 preventExtensions(shadowTarget);
2149 } // Shared Traps
2150
2151
2152 apply(shadowTarget, thisArg, argArray) {
2153 /* No op */
2154 }
2155
2156 construct(shadowTarget, argArray, newTarget) {
2157 /* No op */
2158 }
2159
2160 get(shadowTarget, key) {
2161 const {
2162 originalTarget,
2163 membrane: {
2164 valueObserved
2165 }
2166 } = this;
2167 const value = originalTarget[key];
2168 valueObserved(originalTarget, key);
2169 return this.wrapValue(value);
2170 }
2171
2172 has(shadowTarget, key) {
2173 const {
2174 originalTarget,
2175 membrane: {
2176 tagPropertyKey,
2177 valueObserved
2178 }
2179 } = this;
2180 valueObserved(originalTarget, key); // since key is never going to be undefined, and tagPropertyKey might be undefined
2181 // we can simply compare them as the second part of the condition.
2182
2183 return key in originalTarget || key === tagPropertyKey;
2184 }
2185
2186 ownKeys(shadowTarget) {
2187 const {
2188 originalTarget,
2189 membrane: {
2190 tagPropertyKey
2191 }
2192 } = this; // if the membrane tag key exists and it is not in the original target, we add it to the keys.
2193
2194 const keys = isUndefined$2(tagPropertyKey) || hasOwnProperty$1$1.call(originalTarget, tagPropertyKey) ? [] : [tagPropertyKey]; // small perf optimization using push instead of concat to avoid creating an extra array
2195
2196 ArrayPush$2.apply(keys, getOwnPropertyNames$1$1(originalTarget));
2197 ArrayPush$2.apply(keys, getOwnPropertySymbols(originalTarget));
2198 return keys;
2199 }
2200
2201 isExtensible(shadowTarget) {
2202 const {
2203 originalTarget
2204 } = this; // optimization to avoid attempting to lock down the shadowTarget multiple times
2205
2206 if (!isExtensible(shadowTarget)) {
2207 return false; // was already locked down
2208 }
2209
2210 if (!isExtensible(originalTarget)) {
2211 this.lockShadowTarget(shadowTarget);
2212 return false;
2213 }
2214
2215 return true;
2216 }
2217
2218 getPrototypeOf(shadowTarget) {
2219 const {
2220 originalTarget
2221 } = this;
2222 return getPrototypeOf$1$1(originalTarget);
2223 }
2224
2225 getOwnPropertyDescriptor(shadowTarget, key) {
2226 const {
2227 originalTarget,
2228 membrane: {
2229 valueObserved,
2230 tagPropertyKey
2231 }
2232 } = this; // keys looked up via getOwnPropertyDescriptor need to be reactive
2233
2234 valueObserved(originalTarget, key);
2235 let desc = getOwnPropertyDescriptor$1$1(originalTarget, key);
2236
2237 if (isUndefined$2(desc)) {
2238 if (key !== tagPropertyKey) {
2239 return undefined;
2240 } // if the key is the membrane tag key, and is not in the original target,
2241 // we produce a synthetic descriptor and install it on the shadow target
2242
2243
2244 desc = {
2245 value: undefined,
2246 writable: false,
2247 configurable: false,
2248 enumerable: false
2249 };
2250 ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
2251 return desc;
2252 }
2253
2254 if (desc.configurable === false) {
2255 // updating the descriptor to non-configurable on the shadow
2256 this.copyDescriptorIntoShadowTarget(shadowTarget, key);
2257 } // Note: by accessing the descriptor, the key is marked as observed
2258 // but access to the value, setter or getter (if available) cannot observe
2259 // mutations, just like regular methods, in which case we just do nothing.
2260
2261
2262 return this.wrapDescriptor(desc);
2263 }
2264
2265}
2266
2267const getterMap = new WeakMap();
2268const setterMap = new WeakMap();
2269const reverseGetterMap = new WeakMap();
2270const reverseSetterMap = new WeakMap();
2271
2272class ReactiveProxyHandler extends BaseProxyHandler {
2273 wrapValue(value) {
2274 return this.membrane.getProxy(value);
2275 }
2276
2277 wrapGetter(originalGet) {
2278 const wrappedGetter = getterMap.get(originalGet);
2279
2280 if (!isUndefined$2(wrappedGetter)) {
2281 return wrappedGetter;
2282 }
2283
2284 const handler = this;
2285
2286 const get = function () {
2287 // invoking the original getter with the original target
2288 return handler.wrapValue(originalGet.call(unwrap(this)));
2289 };
2290
2291 getterMap.set(originalGet, get);
2292 reverseGetterMap.set(get, originalGet);
2293 return get;
2294 }
2295
2296 wrapSetter(originalSet) {
2297 const wrappedSetter = setterMap.get(originalSet);
2298
2299 if (!isUndefined$2(wrappedSetter)) {
2300 return wrappedSetter;
2301 }
2302
2303 const set = function (v) {
2304 // invoking the original setter with the original target
2305 originalSet.call(unwrap(this), unwrap(v));
2306 };
2307
2308 setterMap.set(originalSet, set);
2309 reverseSetterMap.set(set, originalSet);
2310 return set;
2311 }
2312
2313 unwrapDescriptor(descriptor) {
2314 if (hasOwnProperty$1$1.call(descriptor, 'value')) {
2315 // dealing with a data descriptor
2316 descriptor.value = unwrap(descriptor.value);
2317 } else {
2318 const {
2319 set,
2320 get
2321 } = descriptor;
2322
2323 if (!isUndefined$2(get)) {
2324 descriptor.get = this.unwrapGetter(get);
2325 }
2326
2327 if (!isUndefined$2(set)) {
2328 descriptor.set = this.unwrapSetter(set);
2329 }
2330 }
2331
2332 return descriptor;
2333 }
2334
2335 unwrapGetter(redGet) {
2336 const reverseGetter = reverseGetterMap.get(redGet);
2337
2338 if (!isUndefined$2(reverseGetter)) {
2339 return reverseGetter;
2340 }
2341
2342 const handler = this;
2343
2344 const get = function () {
2345 // invoking the red getter with the proxy of this
2346 return unwrap(redGet.call(handler.wrapValue(this)));
2347 };
2348
2349 getterMap.set(get, redGet);
2350 reverseGetterMap.set(redGet, get);
2351 return get;
2352 }
2353
2354 unwrapSetter(redSet) {
2355 const reverseSetter = reverseSetterMap.get(redSet);
2356
2357 if (!isUndefined$2(reverseSetter)) {
2358 return reverseSetter;
2359 }
2360
2361 const handler = this;
2362
2363 const set = function (v) {
2364 // invoking the red setter with the proxy of this
2365 redSet.call(handler.wrapValue(this), handler.wrapValue(v));
2366 };
2367
2368 setterMap.set(set, redSet);
2369 reverseSetterMap.set(redSet, set);
2370 return set;
2371 }
2372
2373 set(shadowTarget, key, value) {
2374 const {
2375 originalTarget,
2376 membrane: {
2377 valueMutated
2378 }
2379 } = this;
2380 const oldValue = originalTarget[key];
2381
2382 if (oldValue !== value) {
2383 originalTarget[key] = value;
2384 valueMutated(originalTarget, key);
2385 } else if (key === 'length' && isArray$1(originalTarget)) {
2386 // fix for issue #236: push will add the new index, and by the time length
2387 // is updated, the internal length is already equal to the new length value
2388 // therefore, the oldValue is equal to the value. This is the forking logic
2389 // to support this use case.
2390 valueMutated(originalTarget, key);
2391 }
2392
2393 return true;
2394 }
2395
2396 deleteProperty(shadowTarget, key) {
2397 const {
2398 originalTarget,
2399 membrane: {
2400 valueMutated
2401 }
2402 } = this;
2403 delete originalTarget[key];
2404 valueMutated(originalTarget, key);
2405 return true;
2406 }
2407
2408 setPrototypeOf(shadowTarget, prototype) {
2409 if (process.env.NODE_ENV !== 'production') {
2410 throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString$1(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
2411 }
2412 }
2413
2414 preventExtensions(shadowTarget) {
2415 if (isExtensible(shadowTarget)) {
2416 const {
2417 originalTarget
2418 } = this;
2419 preventExtensions(originalTarget); // if the originalTarget is a proxy itself, it might reject
2420 // the preventExtension call, in which case we should not attempt to lock down
2421 // the shadow target.
2422
2423 if (isExtensible(originalTarget)) {
2424 return false;
2425 }
2426
2427 this.lockShadowTarget(shadowTarget);
2428 }
2429
2430 return true;
2431 }
2432
2433 defineProperty(shadowTarget, key, descriptor) {
2434 const {
2435 originalTarget,
2436 membrane: {
2437 valueMutated,
2438 tagPropertyKey
2439 }
2440 } = this;
2441
2442 if (key === tagPropertyKey && !hasOwnProperty$1$1.call(originalTarget, key)) {
2443 // To avoid leaking the membrane tag property into the original target, we must
2444 // be sure that the original target doesn't have yet.
2445 // NOTE: we do not return false here because Object.freeze and equivalent operations
2446 // will attempt to set the descriptor to the same value, and expect no to throw. This
2447 // is an small compromise for the sake of not having to diff the descriptors.
2448 return true;
2449 }
2450
2451 ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor)); // intentionally testing if false since it could be undefined as well
2452
2453 if (descriptor.configurable === false) {
2454 this.copyDescriptorIntoShadowTarget(shadowTarget, key);
2455 }
2456
2457 valueMutated(originalTarget, key);
2458 return true;
2459 }
2460
2461}
2462
2463const getterMap$1 = new WeakMap();
2464const setterMap$1 = new WeakMap();
2465
2466class ReadOnlyHandler extends BaseProxyHandler {
2467 wrapValue(value) {
2468 return this.membrane.getReadOnlyProxy(value);
2469 }
2470
2471 wrapGetter(originalGet) {
2472 const wrappedGetter = getterMap$1.get(originalGet);
2473
2474 if (!isUndefined$2(wrappedGetter)) {
2475 return wrappedGetter;
2476 }
2477
2478 const handler = this;
2479
2480 const get = function () {
2481 // invoking the original getter with the original target
2482 return handler.wrapValue(originalGet.call(unwrap(this)));
2483 };
2484
2485 getterMap$1.set(originalGet, get);
2486 return get;
2487 }
2488
2489 wrapSetter(originalSet) {
2490 const wrappedSetter = setterMap$1.get(originalSet);
2491
2492 if (!isUndefined$2(wrappedSetter)) {
2493 return wrappedSetter;
2494 }
2495
2496 const handler = this;
2497
2498 const set = function (v) {
2499 if (process.env.NODE_ENV !== 'production') {
2500 const {
2501 originalTarget
2502 } = handler;
2503 throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
2504 }
2505 };
2506
2507 setterMap$1.set(originalSet, set);
2508 return set;
2509 }
2510
2511 set(shadowTarget, key, value) {
2512 if (process.env.NODE_ENV !== 'production') {
2513 const {
2514 originalTarget
2515 } = this;
2516 throw new Error(`Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2517 }
2518
2519 return false;
2520 }
2521
2522 deleteProperty(shadowTarget, key) {
2523 if (process.env.NODE_ENV !== 'production') {
2524 const {
2525 originalTarget
2526 } = this;
2527 throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2528 }
2529
2530 return false;
2531 }
2532
2533 setPrototypeOf(shadowTarget, prototype) {
2534 if (process.env.NODE_ENV !== 'production') {
2535 const {
2536 originalTarget
2537 } = this;
2538 throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
2539 }
2540 }
2541
2542 preventExtensions(shadowTarget) {
2543 if (process.env.NODE_ENV !== 'production') {
2544 const {
2545 originalTarget
2546 } = this;
2547 throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
2548 }
2549
2550 return false;
2551 }
2552
2553 defineProperty(shadowTarget, key, descriptor) {
2554 if (process.env.NODE_ENV !== 'production') {
2555 const {
2556 originalTarget
2557 } = this;
2558 throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
2559 }
2560
2561 return false;
2562 }
2563
2564}
2565
2566function extract(objectOrArray) {
2567 if (isArray$1(objectOrArray)) {
2568 return objectOrArray.map(item => {
2569 const original = unwrap(item);
2570
2571 if (original !== item) {
2572 return extract(original);
2573 }
2574
2575 return item;
2576 });
2577 }
2578
2579 const obj = ObjectCreate(getPrototypeOf$1$1(objectOrArray));
2580 const names = getOwnPropertyNames$1$1(objectOrArray);
2581 return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
2582 const item = objectOrArray[key];
2583 const original = unwrap(item);
2584
2585 if (original !== item) {
2586 seed[key] = extract(original);
2587 } else {
2588 seed[key] = item;
2589 }
2590
2591 return seed;
2592 }, obj);
2593}
2594
2595const formatter = {
2596 header: plainOrProxy => {
2597 const originalTarget = unwrap(plainOrProxy); // if originalTarget is falsy or not unwrappable, exit
2598
2599 if (!originalTarget || originalTarget === plainOrProxy) {
2600 return null;
2601 }
2602
2603 const obj = extract(plainOrProxy);
2604 return ['object', {
2605 object: obj
2606 }];
2607 },
2608 hasBody: () => {
2609 return false;
2610 },
2611 body: () => {
2612 return null;
2613 }
2614}; // Inspired from paulmillr/es6-shim
2615// https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
2616
2617function getGlobal() {
2618 // the only reliable means to get the global object is `Function('return this')()`
2619 // However, this causes CSP violations in Chrome apps.
2620 if (typeof globalThis !== 'undefined') {
2621 return globalThis;
2622 }
2623
2624 if (typeof self !== 'undefined') {
2625 return self;
2626 }
2627
2628 if (typeof window !== 'undefined') {
2629 return window;
2630 }
2631
2632 if (typeof global !== 'undefined') {
2633 return global;
2634 } // Gracefully degrade if not able to locate the global object
2635
2636
2637 return {};
2638}
2639
2640function init() {
2641 if (process.env.NODE_ENV === 'production') {
2642 // this method should never leak to prod
2643 throw new ReferenceError();
2644 }
2645
2646 const global = getGlobal(); // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
2647 // - Go to Settings,
2648 // - Under console, select "Enable custom formatters"
2649 // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
2650
2651 const devtoolsFormatters = global.devtoolsFormatters || [];
2652 ArrayPush$2.call(devtoolsFormatters, formatter);
2653 global.devtoolsFormatters = devtoolsFormatters;
2654}
2655
2656if (process.env.NODE_ENV !== 'production') {
2657 init();
2658}
2659
2660const ObjectDotPrototype = Object.prototype;
2661
2662function defaultValueIsObservable(value) {
2663 // intentionally checking for null
2664 if (value === null) {
2665 return false;
2666 } // treat all non-object types, including undefined, as non-observable values
2667
2668
2669 if (typeof value !== 'object') {
2670 return false;
2671 }
2672
2673 if (isArray$1(value)) {
2674 return true;
2675 }
2676
2677 const proto = getPrototypeOf$1$1(value);
2678 return proto === ObjectDotPrototype || proto === null || getPrototypeOf$1$1(proto) === null;
2679}
2680
2681const defaultValueObserved = (obj, key) => {
2682 /* do nothing */
2683};
2684
2685const defaultValueMutated = (obj, key) => {
2686 /* do nothing */
2687};
2688
2689const defaultValueDistortion = value => value;
2690
2691function createShadowTarget(value) {
2692 return isArray$1(value) ? [] : {};
2693}
2694
2695class ReactiveMembrane {
2696 constructor(options) {
2697 this.valueDistortion = defaultValueDistortion;
2698 this.valueMutated = defaultValueMutated;
2699 this.valueObserved = defaultValueObserved;
2700 this.valueIsObservable = defaultValueIsObservable;
2701 this.objectGraph = new WeakMap();
2702
2703 if (!isUndefined$2(options)) {
2704 const {
2705 valueDistortion,
2706 valueMutated,
2707 valueObserved,
2708 valueIsObservable,
2709 tagPropertyKey
2710 } = options;
2711 this.valueDistortion = isFunction$1$1(valueDistortion) ? valueDistortion : defaultValueDistortion;
2712 this.valueMutated = isFunction$1$1(valueMutated) ? valueMutated : defaultValueMutated;
2713 this.valueObserved = isFunction$1$1(valueObserved) ? valueObserved : defaultValueObserved;
2714 this.valueIsObservable = isFunction$1$1(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
2715 this.tagPropertyKey = tagPropertyKey;
2716 }
2717 }
2718
2719 getProxy(value) {
2720 const unwrappedValue = unwrap(value);
2721 const distorted = this.valueDistortion(unwrappedValue);
2722
2723 if (this.valueIsObservable(distorted)) {
2724 const o = this.getReactiveState(unwrappedValue, distorted); // when trying to extract the writable version of a readonly
2725 // we return the readonly.
2726
2727 return o.readOnly === value ? value : o.reactive;
2728 }
2729
2730 return distorted;
2731 }
2732
2733 getReadOnlyProxy(value) {
2734 value = unwrap(value);
2735 const distorted = this.valueDistortion(value);
2736
2737 if (this.valueIsObservable(distorted)) {
2738 return this.getReactiveState(value, distorted).readOnly;
2739 }
2740
2741 return distorted;
2742 }
2743
2744 unwrapProxy(p) {
2745 return unwrap(p);
2746 }
2747
2748 getReactiveState(value, distortedValue) {
2749 const {
2750 objectGraph
2751 } = this;
2752 let reactiveState = objectGraph.get(distortedValue);
2753
2754 if (reactiveState) {
2755 return reactiveState;
2756 }
2757
2758 const membrane = this;
2759 reactiveState = {
2760 get reactive() {
2761 const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue); // caching the reactive proxy after the first time it is accessed
2762
2763 const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
2764 registerProxy(proxy, value);
2765 ObjectDefineProperty(this, 'reactive', {
2766 value: proxy
2767 });
2768 return proxy;
2769 },
2770
2771 get readOnly() {
2772 const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue); // caching the readOnly proxy after the first time it is accessed
2773
2774 const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
2775 registerProxy(proxy, value);
2776 ObjectDefineProperty(this, 'readOnly', {
2777 value: proxy
2778 });
2779 return proxy;
2780 }
2781
2782 };
2783 objectGraph.set(distortedValue, reactiveState);
2784 return reactiveState;
2785 }
2786
2787}
2788/** version: 1.0.0 */
2789
2790/*
2791 * Copyright (c) 2018, salesforce.com, inc.
2792 * All rights reserved.
2793 * SPDX-License-Identifier: MIT
2794 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2795 */
2796const lockerLivePropertyKey = Symbol.for('@@lockerLiveValue');
2797
2798function valueDistortion(value) {
2799 return value;
2800}
2801
2802const reactiveMembrane = new ReactiveMembrane({
2803 valueObserved,
2804 valueMutated,
2805 valueDistortion,
2806 tagPropertyKey: lockerLivePropertyKey
2807});
2808/**
2809 * EXPERIMENTAL: This function implements an unwrap mechanism that
2810 * works for observable membrane objects. This API is subject to
2811 * change or being removed.
2812 */
2813
2814const unwrap$1 = function (value) {
2815 const unwrapped = reactiveMembrane.unwrapProxy(value);
2816
2817 if (unwrapped !== value) {
2818 // if value is a proxy, unwrap to access original value and apply distortion
2819 return valueDistortion(unwrapped);
2820 }
2821
2822 return value;
2823};
2824
2825/*
2826 * Copyright (c) 2018, salesforce.com, inc.
2827 * All rights reserved.
2828 * SPDX-License-Identifier: MIT
2829 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2830 */
2831/**
2832 * This operation is called with a descriptor of an standard html property
2833 * that a Custom Element can support (including AOM properties), which
2834 * determines what kind of capabilities the Base Lightning Element should support. When producing the new descriptors
2835 * for the Base Lightning Element, it also include the reactivity bit, so the standard property is reactive.
2836 */
2837
2838function createBridgeToElementDescriptor(propName, descriptor) {
2839 const {
2840 get,
2841 set,
2842 enumerable,
2843 configurable
2844 } = descriptor;
2845
2846 if (!isFunction$1(get)) {
2847 if (process.env.NODE_ENV !== 'production') {
2848 assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard getter.`);
2849 }
2850
2851 throw new TypeError();
2852 }
2853
2854 if (!isFunction$1(set)) {
2855 if (process.env.NODE_ENV !== 'production') {
2856 assert.fail(`Detected invalid public property descriptor for HTMLElement.prototype.${propName} definition. Missing the standard setter.`);
2857 }
2858
2859 throw new TypeError();
2860 }
2861
2862 return {
2863 enumerable,
2864 configurable,
2865
2866 get() {
2867 const vm = getAssociatedVM(this);
2868
2869 if (isBeingConstructed(vm)) {
2870 if (process.env.NODE_ENV !== 'production') {
2871 logError(`The value of property \`${propName}\` can't be read from the constructor because the owner component hasn't set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
2872 }
2873
2874 return;
2875 }
2876
2877 componentValueObserved(vm, propName);
2878 return get.call(vm.elm);
2879 },
2880
2881 set(newValue) {
2882 const vm = getAssociatedVM(this);
2883
2884 if (process.env.NODE_ENV !== 'production') {
2885 const vmBeingRendered = getVMBeingRendered();
2886 assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${propName}`);
2887 assert.invariant(!isUpdatingTemplate, `When updating the template of ${vmBeingRendered}, one of the accessors used by the template has side effects on the state of ${vm}.${propName}`);
2888 assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
2889 assert.invariant(!isObject$1(newValue) || isNull$1(newValue), `Invalid value "${newValue}" for "${propName}" of ${vm}. Value cannot be an object, must be a primitive value.`);
2890 }
2891
2892 if (newValue !== vm.cmpProps[propName]) {
2893 vm.cmpProps[propName] = newValue;
2894 componentValueMutated(vm, propName);
2895 }
2896
2897 return set.call(vm.elm, newValue);
2898 }
2899
2900 };
2901}
2902/**
2903 * This class is the base class for any LWC element.
2904 * Some elements directly extends this class, others implement it via inheritance.
2905 **/
2906
2907
2908function BaseLightningElementConstructor() {
2909 var _a; // This should be as performant as possible, while any initialization should be done lazily
2910
2911
2912 if (isNull$1(vmBeingConstructed)) {
2913 throw new ReferenceError('Illegal constructor');
2914 }
2915
2916 const vm = vmBeingConstructed;
2917 const {
2918 elm,
2919 mode,
2920 renderer,
2921 def: {
2922 ctor
2923 }
2924 } = vm;
2925
2926 if (process.env.NODE_ENV !== 'production') {
2927 (_a = renderer.assertInstanceOfHTMLElement) === null || _a === void 0 ? void 0 : _a.call(renderer, vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
2928 }
2929
2930 const component = this;
2931 const cmpRoot = renderer.attachShadow(elm, {
2932 mode,
2933 delegatesFocus: !!ctor.delegatesFocus,
2934 '$$lwc-synthetic-mode$$': true
2935 });
2936 vm.component = this;
2937 vm.cmpRoot = cmpRoot; // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
2938 // component creation and passes hooks to instrument all the component interactions with the
2939 // engine. We are intentionally hiding this argument from the formal API of LightningElement
2940 // because we don't want folks to know about it just yet.
2941
2942 if (arguments.length === 1) {
2943 const {
2944 callHook,
2945 setHook,
2946 getHook
2947 } = arguments[0];
2948 vm.callHook = callHook;
2949 vm.setHook = setHook;
2950 vm.getHook = getHook;
2951 } // Making the component instance a live value when using Locker to support expandos.
2952
2953
2954 defineProperty$1(component, lockerLivePropertyKey, EmptyObject); // Linking elm, shadow root and component with the VM.
2955
2956 associateVM(component, vm);
2957 associateVM(cmpRoot, vm);
2958 associateVM(elm, vm); // Adding extra guard rails in DEV mode.
2959
2960 if (process.env.NODE_ENV !== 'production') {
2961 patchCustomElementWithRestrictions(elm);
2962 patchComponentWithRestrictions(component);
2963 patchShadowRootWithRestrictions(cmpRoot);
2964 }
2965
2966 return this;
2967}
2968
2969BaseLightningElementConstructor.prototype = {
2970 constructor: BaseLightningElementConstructor,
2971
2972 dispatchEvent(event) {
2973 const {
2974 elm,
2975 renderer: {
2976 dispatchEvent
2977 }
2978 } = getAssociatedVM(this);
2979 return dispatchEvent(elm, event);
2980 },
2981
2982 addEventListener(type, listener, options) {
2983 const vm = getAssociatedVM(this);
2984 const {
2985 elm,
2986 renderer: {
2987 addEventListener
2988 }
2989 } = vm;
2990
2991 if (process.env.NODE_ENV !== 'production') {
2992 const vmBeingRendered = getVMBeingRendered();
2993 assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2994 assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm} by adding an event listener for "${type}".`);
2995 assert.invariant(isFunction$1(listener), `Invalid second argument for this.addEventListener() in ${vm} for event "${type}". Expected an EventListener but received ${listener}.`);
2996 }
2997
2998 const wrappedListener = getWrappedComponentsListener(vm, listener);
2999 addEventListener(elm, type, wrappedListener, options);
3000 },
3001
3002 removeEventListener(type, listener, options) {
3003 const vm = getAssociatedVM(this);
3004 const {
3005 elm,
3006 renderer: {
3007 removeEventListener
3008 }
3009 } = vm;
3010 const wrappedListener = getWrappedComponentsListener(vm, listener);
3011 removeEventListener(elm, type, wrappedListener, options);
3012 },
3013
3014 hasAttribute(name) {
3015 const {
3016 elm,
3017 renderer: {
3018 getAttribute
3019 }
3020 } = getAssociatedVM(this);
3021 return !isNull$1(getAttribute(elm, name));
3022 },
3023
3024 hasAttributeNS(namespace, name) {
3025 const {
3026 elm,
3027 renderer: {
3028 getAttribute
3029 }
3030 } = getAssociatedVM(this);
3031 return !isNull$1(getAttribute(elm, name, namespace));
3032 },
3033
3034 removeAttribute(name) {
3035 const {
3036 elm,
3037 renderer: {
3038 removeAttribute
3039 }
3040 } = getAssociatedVM(this);
3041 removeAttribute(elm, name);
3042 },
3043
3044 removeAttributeNS(namespace, name) {
3045 const {
3046 elm,
3047 renderer: {
3048 removeAttribute
3049 }
3050 } = getAssociatedVM(this);
3051 removeAttribute(elm, name, namespace);
3052 },
3053
3054 getAttribute(name) {
3055 const {
3056 elm,
3057 renderer: {
3058 getAttribute
3059 }
3060 } = getAssociatedVM(this);
3061 return getAttribute(elm, name);
3062 },
3063
3064 getAttributeNS(namespace, name) {
3065 const {
3066 elm,
3067 renderer: {
3068 getAttribute
3069 }
3070 } = getAssociatedVM(this);
3071 return getAttribute(elm, name, namespace);
3072 },
3073
3074 setAttribute(name, value) {
3075 const vm = getAssociatedVM(this);
3076 const {
3077 elm,
3078 renderer: {
3079 setAttribute
3080 }
3081 } = vm;
3082
3083 if (process.env.NODE_ENV !== 'production') {
3084 assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
3085 }
3086 setAttribute(elm, name, value);
3087 },
3088
3089 setAttributeNS(namespace, name, value) {
3090 const vm = getAssociatedVM(this);
3091 const {
3092 elm,
3093 renderer: {
3094 setAttribute
3095 }
3096 } = vm;
3097
3098 if (process.env.NODE_ENV !== 'production') {
3099 assert.isFalse(isBeingConstructed(vm), `Failed to construct '${getComponentTag(vm)}': The result must not have attributes.`);
3100 }
3101 setAttribute(elm, name, value, namespace);
3102 },
3103
3104 getBoundingClientRect() {
3105 const vm = getAssociatedVM(this);
3106 const {
3107 elm,
3108 renderer: {
3109 getBoundingClientRect
3110 }
3111 } = vm;
3112
3113 if (process.env.NODE_ENV !== 'production') {
3114 assert.isFalse(isBeingConstructed(vm), `this.getBoundingClientRect() should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM, instead, you can use it in one of the available life-cycle hooks.`);
3115 }
3116
3117 return getBoundingClientRect(elm);
3118 },
3119
3120 querySelector(selectors) {
3121 const vm = getAssociatedVM(this);
3122 const {
3123 elm,
3124 renderer: {
3125 querySelector
3126 }
3127 } = vm;
3128
3129 if (process.env.NODE_ENV !== 'production') {
3130 assert.isFalse(isBeingConstructed(vm), `this.querySelector() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3131 }
3132
3133 return querySelector(elm, selectors);
3134 },
3135
3136 querySelectorAll(selectors) {
3137 const vm = getAssociatedVM(this);
3138 const {
3139 elm,
3140 renderer: {
3141 querySelectorAll
3142 }
3143 } = vm;
3144
3145 if (process.env.NODE_ENV !== 'production') {
3146 assert.isFalse(isBeingConstructed(vm), `this.querySelectorAll() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3147 }
3148
3149 return querySelectorAll(elm, selectors);
3150 },
3151
3152 getElementsByTagName(tagNameOrWildCard) {
3153 const vm = getAssociatedVM(this);
3154 const {
3155 elm,
3156 renderer: {
3157 getElementsByTagName
3158 }
3159 } = vm;
3160
3161 if (process.env.NODE_ENV !== 'production') {
3162 assert.isFalse(isBeingConstructed(vm), `this.getElementsByTagName() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3163 }
3164
3165 return getElementsByTagName(elm, tagNameOrWildCard);
3166 },
3167
3168 getElementsByClassName(names) {
3169 const vm = getAssociatedVM(this);
3170 const {
3171 elm,
3172 renderer: {
3173 getElementsByClassName
3174 }
3175 } = vm;
3176
3177 if (process.env.NODE_ENV !== 'production') {
3178 assert.isFalse(isBeingConstructed(vm), `this.getElementsByClassName() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3179 }
3180
3181 return getElementsByClassName(elm, names);
3182 },
3183
3184 get isConnected() {
3185 const {
3186 elm,
3187 renderer: {
3188 isConnected
3189 }
3190 } = getAssociatedVM(this);
3191 return isConnected(elm);
3192 },
3193
3194 get classList() {
3195 const vm = getAssociatedVM(this);
3196 const {
3197 elm,
3198 renderer: {
3199 getClassList
3200 }
3201 } = vm;
3202
3203 if (process.env.NODE_ENV !== 'production') {
3204 // TODO [#1290]: this still fails in dev but works in production, eventually, we should
3205 // just throw in all modes
3206 assert.isFalse(isBeingConstructed(vm), `Failed to construct ${vm}: The result must not have attributes. Adding or tampering with classname in constructor is not allowed in a web component, use connectedCallback() instead.`);
3207 }
3208
3209 return getClassList(elm);
3210 },
3211
3212 get template() {
3213 const vm = getAssociatedVM(this);
3214 return vm.cmpRoot;
3215 },
3216
3217 get shadowRoot() {
3218 // From within the component instance, the shadowRoot is always reported as "closed".
3219 // Authors should rely on this.template instead.
3220 return null;
3221 },
3222
3223 render() {
3224 const vm = getAssociatedVM(this);
3225 return vm.def.template;
3226 },
3227
3228 toString() {
3229 const vm = getAssociatedVM(this);
3230 return `[object ${vm.def.name}]`;
3231 }
3232
3233};
3234const lightningBasedDescriptors = create$1(null);
3235
3236for (const propName in HTMLElementOriginalDescriptors) {
3237 lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
3238}
3239
3240defineProperties$1(BaseLightningElementConstructor.prototype, lightningBasedDescriptors);
3241defineProperty$1(BaseLightningElementConstructor, 'CustomElementConstructor', {
3242 get() {
3243 // If required, a runtime-specific implementation must be defined.
3244 throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
3245 },
3246
3247 configurable: true
3248});
3249
3250if (process.env.NODE_ENV !== 'production') {
3251 patchLightningElementPrototypeWithRestrictions(BaseLightningElementConstructor.prototype);
3252} // @ts-ignore
3253
3254
3255const BaseLightningElement = BaseLightningElementConstructor;
3256
3257/*
3258 * Copyright (c) 2018, salesforce.com, inc.
3259 * All rights reserved.
3260 * SPDX-License-Identifier: MIT
3261 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3262 */
3263/**
3264 * @wire decorator to wire fields and methods to a wire adapter in
3265 * LWC Components. This function implements the internals of this
3266 * decorator.
3267 */
3268
3269function wire(_adapter, _config) {
3270 if (process.env.NODE_ENV !== 'production') {
3271 assert.fail('@wire(adapter, config?) may only be used as a decorator.');
3272 }
3273
3274 throw new Error();
3275}
3276function internalWireFieldDecorator(key) {
3277 return {
3278 get() {
3279 const vm = getAssociatedVM(this);
3280 componentValueObserved(vm, key);
3281 return vm.cmpFields[key];
3282 },
3283
3284 set(value) {
3285 const vm = getAssociatedVM(this);
3286 /**
3287 * Reactivity for wired fields is provided in wiring.
3288 * We intentionally add reactivity here since this is just
3289 * letting the author to do the wrong thing, but it will keep our
3290 * system to be backward compatible.
3291 */
3292
3293 if (value !== vm.cmpFields[key]) {
3294 vm.cmpFields[key] = value;
3295 componentValueMutated(vm, key);
3296 }
3297 },
3298
3299 enumerable: true,
3300 configurable: true
3301 };
3302}
3303
3304/*
3305 * Copyright (c) 2018, salesforce.com, inc.
3306 * All rights reserved.
3307 * SPDX-License-Identifier: MIT
3308 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3309 */
3310function track(target) {
3311 if (arguments.length === 1) {
3312 return reactiveMembrane.getProxy(target);
3313 }
3314
3315 if (process.env.NODE_ENV !== 'production') {
3316 assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
3317 }
3318
3319 throw new Error();
3320}
3321function internalTrackDecorator(key) {
3322 return {
3323 get() {
3324 const vm = getAssociatedVM(this);
3325 componentValueObserved(vm, key);
3326 return vm.cmpFields[key];
3327 },
3328
3329 set(newValue) {
3330 const vm = getAssociatedVM(this);
3331
3332 if (process.env.NODE_ENV !== 'production') {
3333 const vmBeingRendered = getVMBeingRendered();
3334 assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString(key)}`);
3335 assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString(key)}`);
3336 }
3337
3338 const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
3339
3340 if (reactiveOrAnyValue !== vm.cmpFields[key]) {
3341 vm.cmpFields[key] = reactiveOrAnyValue;
3342 componentValueMutated(vm, key);
3343 }
3344 },
3345
3346 enumerable: true,
3347 configurable: true
3348 };
3349}
3350
3351/**
3352 * Copyright (C) 2018 salesforce.com, inc.
3353 */
3354
3355/**
3356 * Copyright (C) 2018 salesforce.com, inc.
3357 */
3358
3359/*
3360 * Copyright (c) 2018, salesforce.com, inc.
3361 * All rights reserved.
3362 * SPDX-License-Identifier: MIT
3363 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3364 */
3365const {
3366 assign: assign$1$1,
3367 create: create$2,
3368 defineProperties: defineProperties$1$1,
3369 defineProperty: defineProperty$1$1,
3370 freeze: freeze$1$1,
3371 getOwnPropertyDescriptor: getOwnPropertyDescriptor$2,
3372 getOwnPropertyNames: getOwnPropertyNames$2,
3373 getPrototypeOf: getPrototypeOf$2,
3374 hasOwnProperty: hasOwnProperty$2,
3375 isFrozen: isFrozen$1$1,
3376 keys: keys$1$1,
3377 seal: seal$1$1,
3378 setPrototypeOf: setPrototypeOf$1$1
3379} = Object;
3380const {
3381 filter: ArrayFilter$1$1,
3382 find: ArrayFind$1$1,
3383 indexOf: ArrayIndexOf$2,
3384 join: ArrayJoin$1$1,
3385 map: ArrayMap$2,
3386 push: ArrayPush$3,
3387 reduce: ArrayReduce$1$1,
3388 reverse: ArrayReverse$1$1,
3389 slice: ArraySlice$1$1,
3390 splice: ArraySplice$2,
3391 unshift: ArrayUnshift$1$1,
3392 forEach: forEach$1$1
3393} = Array.prototype;
3394const {
3395 charCodeAt: StringCharCodeAt$1$1,
3396 replace: StringReplace$1$1,
3397 slice: StringSlice$1$1,
3398 toLowerCase: StringToLowerCase$1$1
3399} = String.prototype;
3400
3401function isUndefined$3(obj) {
3402 return obj === undefined;
3403}
3404
3405function isTrue$1$1(obj) {
3406 return obj === true;
3407}
3408
3409function isFalse$1$1(obj) {
3410 return obj === false;
3411}
3412/*
3413 * Copyright (c) 2018, salesforce.com, inc.
3414 * All rights reserved.
3415 * SPDX-License-Identifier: MIT
3416 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3417 */
3418
3419/**
3420 * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and
3421 * ariaGrabbed) are deprecated:
3422 * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes
3423 *
3424 * The above list of 46 aria attributes is consistent with the following resources:
3425 * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
3426 * https://wicg.github.io/aom/spec/aria-reflection.html
3427 */
3428
3429
3430const AriaPropertyNames$1$1 = ['ariaActiveDescendant', 'ariaAtomic', 'ariaAutoComplete', 'ariaBusy', 'ariaChecked', 'ariaColCount', 'ariaColIndex', 'ariaColSpan', 'ariaControls', 'ariaCurrent', 'ariaDescribedBy', 'ariaDetails', 'ariaDisabled', 'ariaErrorMessage', 'ariaExpanded', 'ariaFlowTo', 'ariaHasPopup', 'ariaHidden', 'ariaInvalid', 'ariaKeyShortcuts', 'ariaLabel', 'ariaLabelledBy', 'ariaLevel', 'ariaLive', 'ariaModal', 'ariaMultiLine', 'ariaMultiSelectable', 'ariaOrientation', 'ariaOwns', 'ariaPlaceholder', 'ariaPosInSet', 'ariaPressed', 'ariaReadOnly', 'ariaRelevant', 'ariaRequired', 'ariaRoleDescription', 'ariaRowCount', 'ariaRowIndex', 'ariaRowSpan', 'ariaSelected', 'ariaSetSize', 'ariaSort', 'ariaValueMax', 'ariaValueMin', 'ariaValueNow', 'ariaValueText', 'role'];
3431const AttrNameToPropNameMap$2 = create$2(null);
3432const PropNameToAttrNameMap$2 = create$2(null); // Synthetic creation of all AOM property descriptors for Custom Elements
3433
3434forEach$1$1.call(AriaPropertyNames$1$1, propName => {
3435 // Typescript infers the wrong function type for this particular overloaded method:
3436 // https://github.com/Microsoft/TypeScript/issues/27972
3437 // @ts-ignore type-mismatch
3438 const attrName = StringToLowerCase$1$1.call(StringReplace$1$1.call(propName, /^aria/, 'aria-'));
3439 AttrNameToPropNameMap$2[attrName] = propName;
3440 PropNameToAttrNameMap$2[propName] = attrName;
3441});
3442/*
3443 * Copyright (c) 2018, salesforce.com, inc.
3444 * All rights reserved.
3445 * SPDX-License-Identifier: MIT
3446 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3447 */
3448// Inspired from: https://mathiasbynens.be/notes/globalthis
3449
3450const _globalThis$1$1 = function () {
3451 // On recent browsers, `globalThis` is already defined. In this case return it directly.
3452 if (typeof globalThis === 'object') {
3453 return globalThis;
3454 }
3455
3456 let _globalThis;
3457
3458 try {
3459 // eslint-disable-next-line no-extend-native
3460 Object.defineProperty(Object.prototype, '__magic__', {
3461 get: function () {
3462 return this;
3463 },
3464 configurable: true
3465 }); // __magic__ is undefined in Safari 10 and IE10 and older.
3466 // @ts-ignore
3467 // eslint-disable-next-line no-undef
3468
3469 _globalThis = __magic__; // @ts-ignore
3470
3471 delete Object.prototype.__magic__;
3472 } catch (ex) {// In IE8, Object.defineProperty only works on DOM objects.
3473 } finally {
3474 // If the magic above fails for some reason we assume that we are in a legacy browser.
3475 // Assume `window` exists in this case.
3476 if (typeof _globalThis === 'undefined') {
3477 // @ts-ignore
3478 _globalThis = window;
3479 }
3480 }
3481
3482 return _globalThis;
3483}();
3484/*
3485 * Copyright (c) 2018, salesforce.com, inc.
3486 * All rights reserved.
3487 * SPDX-License-Identifier: MIT
3488 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3489 */
3490
3491/*
3492 * In IE11, symbols are expensive.
3493 * Due to the nature of the symbol polyfill. This method abstract the
3494 * creation of symbols, so we can fallback to string when native symbols
3495 * are not supported. Note that we can't use typeof since it will fail when transpiling.
3496 */
3497
3498
3499const hasNativeSymbolsSupport$1$1 = Symbol('x').toString() === 'Symbol(x)';
3500const HTML_ATTRIBUTES_TO_PROPERTY$1$1 = {
3501 accesskey: 'accessKey',
3502 readonly: 'readOnly',
3503 tabindex: 'tabIndex',
3504 bgcolor: 'bgColor',
3505 colspan: 'colSpan',
3506 rowspan: 'rowSpan',
3507 contenteditable: 'contentEditable',
3508 crossorigin: 'crossOrigin',
3509 datetime: 'dateTime',
3510 formaction: 'formAction',
3511 ismap: 'isMap',
3512 maxlength: 'maxLength',
3513 minlength: 'minLength',
3514 novalidate: 'noValidate',
3515 usemap: 'useMap',
3516 for: 'htmlFor'
3517};
3518keys$1$1(HTML_ATTRIBUTES_TO_PROPERTY$1$1).forEach(attrName => {});
3519/** version: 1.7.12 */
3520
3521/*
3522 * Copyright (c) 2018, salesforce.com, inc.
3523 * All rights reserved.
3524 * SPDX-License-Identifier: MIT
3525 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3526 */
3527
3528if (!_globalThis$1$1.lwcRuntimeFlags) {
3529 Object.defineProperty(_globalThis$1$1, 'lwcRuntimeFlags', {
3530 value: create$2(null)
3531 });
3532}
3533
3534const runtimeFlags = _globalThis$1$1.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
3535// configuring runtime feature flags during app initialization.
3536
3537function setFeatureFlag(name, value) {
3538 const isBoolean = isTrue$1$1(value) || isFalse$1$1(value);
3539
3540 if (!isBoolean) {
3541 const message = `Failed to set the value "${value}" for the runtime feature flag "${name}". Runtime feature flags can only be set to a boolean value.`;
3542
3543 if (process.env.NODE_ENV !== 'production') {
3544 throw new TypeError(message);
3545 } else {
3546 // eslint-disable-next-line no-console
3547 console.error(message);
3548 return;
3549 }
3550 }
3551
3552 if (isUndefined$3(featureFlagLookup[name])) {
3553 // eslint-disable-next-line no-console
3554 console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Possible reasons are that 1) it was misspelled or 2) it was removed from the @lwc/features package.`);
3555 return;
3556 }
3557
3558 if (process.env.NODE_ENV !== 'production') {
3559 // Allow the same flag to be set more than once outside of production to enable testing
3560 runtimeFlags[name] = value;
3561 } else {
3562 // Disallow the same flag to be set more than once in production
3563 const runtimeValue = runtimeFlags[name];
3564
3565 if (!isUndefined$3(runtimeValue)) {
3566 // eslint-disable-next-line no-console
3567 console.error(`Failed to set the value "${value}" for the runtime feature flag "${name}". "${name}" has already been set with the value "${runtimeValue}".`);
3568 return;
3569 }
3570
3571 Object.defineProperty(runtimeFlags, name, {
3572 value
3573 });
3574 }
3575} // This function is exposed to components to facilitate testing so we add a
3576// check to make sure it is not invoked in production.
3577
3578
3579function setFeatureFlagForTest(name, value) {
3580 if (process.env.NODE_ENV !== 'production') {
3581 return setFeatureFlag(name, value);
3582 }
3583}
3584
3585const featureFlagLookup = {
3586 ENABLE_REACTIVE_SETTER: null,
3587 // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
3588 ENABLE_ELEMENT_PATCH: null,
3589 ENABLE_NODE_LIST_PATCH: null,
3590 ENABLE_HTML_COLLECTIONS_PATCH: null,
3591 ENABLE_NODE_PATCH: null
3592};
3593/** version: 1.7.12 */
3594
3595/*
3596 * Copyright (c) 2018, salesforce.com, inc.
3597 * All rights reserved.
3598 * SPDX-License-Identifier: MIT
3599 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3600 */
3601function api() {
3602 if (process.env.NODE_ENV !== 'production') {
3603 assert.fail(`@api decorator can only be used as a decorator function.`);
3604 }
3605
3606 throw new Error();
3607}
3608function createPublicPropertyDescriptor(key) {
3609 return {
3610 get() {
3611 const vm = getAssociatedVM(this);
3612
3613 if (isBeingConstructed(vm)) {
3614 if (process.env.NODE_ENV !== 'production') {
3615 logError(`Can’t read the value of property \`${toString(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
3616 }
3617
3618 return;
3619 }
3620
3621 componentValueObserved(vm, key);
3622 return vm.cmpProps[key];
3623 },
3624
3625 set(newValue) {
3626 const vm = getAssociatedVM(this);
3627
3628 if (process.env.NODE_ENV !== 'production') {
3629 const vmBeingRendered = getVMBeingRendered();
3630 assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString(key)}`);
3631 assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString(key)}`);
3632 }
3633
3634 vm.cmpProps[key] = newValue;
3635 componentValueMutated(vm, key);
3636 },
3637
3638 enumerable: true,
3639 configurable: true
3640 };
3641}
3642class AccessorReactiveObserver extends ReactiveObserver {
3643 constructor(vm, set) {
3644 super(() => {
3645 if (isFalse$1(this.debouncing)) {
3646 this.debouncing = true;
3647 addCallbackToNextTick(() => {
3648 if (isTrue$1(this.debouncing)) {
3649 const {
3650 value
3651 } = this;
3652 const {
3653 isDirty: dirtyStateBeforeSetterCall,
3654 component,
3655 idx
3656 } = vm;
3657 set.call(component, value); // de-bouncing after the call to the original setter to prevent
3658 // infinity loop if the setter itself is mutating things that
3659 // were accessed during the previous invocation.
3660
3661 this.debouncing = false;
3662
3663 if (isTrue$1(vm.isDirty) && isFalse$1(dirtyStateBeforeSetterCall) && idx > 0) {
3664 // immediate rehydration due to a setter driven mutation, otherwise
3665 // the component will get rendered on the second tick, which it is not
3666 // desirable.
3667 rerenderVM(vm);
3668 }
3669 }
3670 });
3671 }
3672 });
3673 this.debouncing = false;
3674 }
3675
3676 reset(value) {
3677 super.reset();
3678 this.debouncing = false;
3679
3680 if (arguments.length > 0) {
3681 this.value = value;
3682 }
3683 }
3684
3685}
3686function createPublicAccessorDescriptor(key, descriptor) {
3687 const {
3688 get,
3689 set,
3690 enumerable,
3691 configurable
3692 } = descriptor;
3693
3694 if (!isFunction$1(get)) {
3695 if (process.env.NODE_ENV !== 'production') {
3696 assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString(key)} decorated with @api`);
3697 }
3698
3699 throw new Error();
3700 }
3701
3702 return {
3703 get() {
3704 if (process.env.NODE_ENV !== 'production') {
3705 // Assert that the this value is an actual Component with an associated VM.
3706 getAssociatedVM(this);
3707 }
3708
3709 return get.call(this);
3710 },
3711
3712 set(newValue) {
3713 const vm = getAssociatedVM(this);
3714
3715 if (process.env.NODE_ENV !== 'production') {
3716 const vmBeingRendered = getVMBeingRendered();
3717 assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString(key)}`);
3718 assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString(key)}`);
3719 }
3720
3721 if (set) {
3722 if (runtimeFlags.ENABLE_REACTIVE_SETTER) {
3723 let ro = vm.oar[key];
3724
3725 if (isUndefined$1(ro)) {
3726 ro = vm.oar[key] = new AccessorReactiveObserver(vm, set);
3727 } // every time we invoke this setter from outside (through this wrapper setter)
3728 // we should reset the value and then debounce just in case there is a pending
3729 // invocation the next tick that is not longer relevant since the value is changing
3730 // from outside.
3731
3732
3733 ro.reset(newValue);
3734 ro.observe(() => {
3735 set.call(this, newValue);
3736 });
3737 } else {
3738 set.call(this, newValue);
3739 }
3740 } else if (process.env.NODE_ENV !== 'production') {
3741 assert.fail(`Invalid attempt to set a new value for property ${toString(key)} of ${vm} that does not has a setter decorated with @api.`);
3742 }
3743 },
3744
3745 enumerable,
3746 configurable
3747 };
3748}
3749
3750function createObservedFieldPropertyDescriptor(key) {
3751 return {
3752 get() {
3753 const vm = getAssociatedVM(this);
3754 componentValueObserved(vm, key);
3755 return vm.cmpFields[key];
3756 },
3757
3758 set(newValue) {
3759 const vm = getAssociatedVM(this);
3760
3761 if (newValue !== vm.cmpFields[key]) {
3762 vm.cmpFields[key] = newValue;
3763 componentValueMutated(vm, key);
3764 }
3765 },
3766
3767 enumerable: true,
3768 configurable: true
3769 };
3770}
3771
3772/*
3773 * Copyright (c) 2018, salesforce.com, inc.
3774 * All rights reserved.
3775 * SPDX-License-Identifier: MIT
3776 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3777 */
3778var PropType;
3779
3780(function (PropType) {
3781 PropType[PropType["Field"] = 0] = "Field";
3782 PropType[PropType["Set"] = 1] = "Set";
3783 PropType[PropType["Get"] = 2] = "Get";
3784 PropType[PropType["GetSet"] = 3] = "GetSet";
3785})(PropType || (PropType = {}));
3786
3787function validateObservedField(Ctor, fieldName, descriptor) {
3788 if (process.env.NODE_ENV !== 'production') {
3789 if (!isUndefined$1(descriptor)) {
3790 assert.fail(`Compiler Error: Invalid field ${fieldName} declaration.`);
3791 }
3792 }
3793}
3794
3795function validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor) {
3796 if (process.env.NODE_ENV !== 'production') {
3797 if (!isUndefined$1(descriptor)) {
3798 assert.fail(`Compiler Error: Invalid @track ${fieldName} declaration.`);
3799 }
3800 }
3801}
3802
3803function validateFieldDecoratedWithWire(Ctor, fieldName, descriptor) {
3804 if (process.env.NODE_ENV !== 'production') {
3805 if (!isUndefined$1(descriptor)) {
3806 assert.fail(`Compiler Error: Invalid @wire(...) ${fieldName} field declaration.`);
3807 }
3808 }
3809}
3810
3811function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
3812 if (process.env.NODE_ENV !== 'production') {
3813 if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse$1(descriptor.writable)) {
3814 assert.fail(`Compiler Error: Invalid @wire(...) ${methodName} method declaration.`);
3815 }
3816 }
3817}
3818
3819function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
3820 if (process.env.NODE_ENV !== 'production') {
3821 if (!isUndefined$1(descriptor)) {
3822 assert.fail(`Compiler Error: Invalid @api ${fieldName} field declaration.`);
3823 }
3824 }
3825}
3826
3827function validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor) {
3828 if (process.env.NODE_ENV !== 'production') {
3829 if (isUndefined$1(descriptor)) {
3830 assert.fail(`Compiler Error: Invalid @api get ${fieldName} accessor declaration.`);
3831 } else if (isFunction$1(descriptor.set)) {
3832 assert.isTrue(isFunction$1(descriptor.get), `Compiler Error: Missing getter for property ${toString(fieldName)} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
3833 } else if (!isFunction$1(descriptor.get)) {
3834 assert.fail(`Compiler Error: Missing @api get ${fieldName} accessor declaration.`);
3835 }
3836 }
3837}
3838
3839function validateMethodDecoratedWithApi(Ctor, methodName, descriptor) {
3840 if (process.env.NODE_ENV !== 'production') {
3841 if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse$1(descriptor.writable)) {
3842 assert.fail(`Compiler Error: Invalid @api ${methodName} method declaration.`);
3843 }
3844 }
3845}
3846/**
3847 * INTERNAL: This function can only be invoked by compiled code. The compiler
3848 * will prevent this function from being imported by user-land code.
3849 */
3850
3851
3852function registerDecorators(Ctor, meta) {
3853 const proto = Ctor.prototype;
3854 const {
3855 publicProps,
3856 publicMethods,
3857 wire,
3858 track,
3859 fields
3860 } = meta;
3861 const apiMethods = create$1(null);
3862 const apiFields = create$1(null);
3863 const wiredMethods = create$1(null);
3864 const wiredFields = create$1(null);
3865 const observedFields = create$1(null);
3866 const apiFieldsConfig = create$1(null);
3867 let descriptor;
3868
3869 if (!isUndefined$1(publicProps)) {
3870 for (const fieldName in publicProps) {
3871 const propConfig = publicProps[fieldName];
3872 apiFieldsConfig[fieldName] = propConfig.config;
3873 descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3874
3875 if (propConfig.config > 0) {
3876 // accessor declaration
3877 if (process.env.NODE_ENV !== 'production') {
3878 validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor);
3879 }
3880
3881 if (isUndefined$1(descriptor)) {
3882 throw new Error();
3883 }
3884
3885 descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3886 } else {
3887 // field declaration
3888 if (process.env.NODE_ENV !== 'production') {
3889 validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
3890 }
3891
3892 descriptor = createPublicPropertyDescriptor(fieldName);
3893 }
3894
3895 apiFields[fieldName] = descriptor;
3896 defineProperty$1(proto, fieldName, descriptor);
3897 }
3898 }
3899
3900 if (!isUndefined$1(publicMethods)) {
3901 forEach$1.call(publicMethods, methodName => {
3902 descriptor = getOwnPropertyDescriptor$1(proto, methodName);
3903
3904 if (process.env.NODE_ENV !== 'production') {
3905 validateMethodDecoratedWithApi(Ctor, methodName, descriptor);
3906 }
3907
3908 if (isUndefined$1(descriptor)) {
3909 throw new Error();
3910 }
3911
3912 apiMethods[methodName] = descriptor;
3913 });
3914 }
3915
3916 if (!isUndefined$1(wire)) {
3917 for (const fieldOrMethodName in wire) {
3918 const {
3919 adapter,
3920 method,
3921 config: configCallback,
3922 dynamic = []
3923 } = wire[fieldOrMethodName];
3924 descriptor = getOwnPropertyDescriptor$1(proto, fieldOrMethodName);
3925
3926 if (method === 1) {
3927 if (process.env.NODE_ENV !== 'production') {
3928 assert.isTrue(adapter, `@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
3929 validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3930 }
3931
3932 if (isUndefined$1(descriptor)) {
3933 throw new Error();
3934 }
3935
3936 wiredMethods[fieldOrMethodName] = descriptor;
3937 storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic);
3938 } else {
3939 if (process.env.NODE_ENV !== 'production') {
3940 assert.isTrue(adapter, `@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
3941 validateFieldDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3942 }
3943
3944 descriptor = internalWireFieldDecorator(fieldOrMethodName);
3945 wiredFields[fieldOrMethodName] = descriptor;
3946 storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic);
3947 defineProperty$1(proto, fieldOrMethodName, descriptor);
3948 }
3949 }
3950 }
3951
3952 if (!isUndefined$1(track)) {
3953 for (const fieldName in track) {
3954 descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3955
3956 if (process.env.NODE_ENV !== 'production') {
3957 validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor);
3958 }
3959
3960 descriptor = internalTrackDecorator(fieldName);
3961 defineProperty$1(proto, fieldName, descriptor);
3962 }
3963 }
3964
3965 if (!isUndefined$1(fields)) {
3966 for (let i = 0, n = fields.length; i < n; i++) {
3967 const fieldName = fields[i];
3968 descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3969
3970 if (process.env.NODE_ENV !== 'production') {
3971 validateObservedField(Ctor, fieldName, descriptor);
3972 }
3973
3974 observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3975 }
3976 }
3977
3978 setDecoratorsMeta(Ctor, {
3979 apiMethods,
3980 apiFields,
3981 apiFieldsConfig,
3982 wiredMethods,
3983 wiredFields,
3984 observedFields
3985 });
3986 return Ctor;
3987}
3988const signedDecoratorToMetaMap = new Map();
3989
3990function setDecoratorsMeta(Ctor, meta) {
3991 signedDecoratorToMetaMap.set(Ctor, meta);
3992}
3993
3994const defaultMeta = {
3995 apiMethods: EmptyObject,
3996 apiFields: EmptyObject,
3997 apiFieldsConfig: EmptyObject,
3998 wiredMethods: EmptyObject,
3999 wiredFields: EmptyObject,
4000 observedFields: EmptyObject
4001};
4002function getDecoratorsMeta(Ctor) {
4003 const meta = signedDecoratorToMetaMap.get(Ctor);
4004 return isUndefined$1(meta) ? defaultMeta : meta;
4005}
4006
4007const signedTemplateSet = new Set();
4008function defaultEmptyTemplate() {
4009 return [];
4010}
4011signedTemplateSet.add(defaultEmptyTemplate);
4012function isTemplateRegistered(tpl) {
4013 return signedTemplateSet.has(tpl);
4014}
4015/**
4016 * INTERNAL: This function can only be invoked by compiled code. The compiler
4017 * will prevent this function from being imported by userland code.
4018 */
4019
4020function registerTemplate(tpl) {
4021 signedTemplateSet.add(tpl); // chaining this method as a way to wrap existing
4022 // assignment of templates easily, without too much transformation
4023
4024 return tpl;
4025}
4026/**
4027 * EXPERIMENTAL: This function acts like a hook for Lightning Locker
4028 * Service and other similar libraries to sanitize vulnerable attributes.
4029 * This API is subject to change or being removed.
4030 */
4031
4032function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
4033 // locker-service patches this function during runtime to sanitize vulnerable attributes.
4034 // when ran off-core this function becomes a noop and returns the user authored value.
4035 return attrValue;
4036}
4037
4038/*
4039 * Copyright (c) 2018, salesforce.com, inc.
4040 * All rights reserved.
4041 * SPDX-License-Identifier: MIT
4042 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4043 */
4044// from the element instance, and get the value or set a new value on the component.
4045// This means that across different elements, similar names can get the exact same
4046// descriptor, so we can cache them:
4047
4048const cachedGetterByKey = create$1(null);
4049const cachedSetterByKey = create$1(null);
4050
4051function createGetter(key) {
4052 let fn = cachedGetterByKey[key];
4053
4054 if (isUndefined$1(fn)) {
4055 fn = cachedGetterByKey[key] = function () {
4056 const vm = getAssociatedVM(this);
4057 const {
4058 getHook
4059 } = vm;
4060 return getHook(vm.component, key);
4061 };
4062 }
4063
4064 return fn;
4065}
4066
4067function createSetter(key) {
4068 let fn = cachedSetterByKey[key];
4069
4070 if (isUndefined$1(fn)) {
4071 fn = cachedSetterByKey[key] = function (newValue) {
4072 const vm = getAssociatedVM(this);
4073 const {
4074 setHook
4075 } = vm;
4076 newValue = reactiveMembrane.getReadOnlyProxy(newValue);
4077 setHook(vm.component, key, newValue);
4078 };
4079 }
4080
4081 return fn;
4082}
4083
4084function createMethodCaller(methodName) {
4085 return function () {
4086 const vm = getAssociatedVM(this);
4087 const {
4088 callHook,
4089 component
4090 } = vm;
4091 const fn = component[methodName];
4092 return callHook(vm.component, fn, ArraySlice$1.call(arguments));
4093 };
4094}
4095
4096function HTMLBridgeElementFactory(SuperClass, props, methods) {
4097 let HTMLBridgeElement;
4098 /**
4099 * Modern browsers will have all Native Constructors as regular Classes
4100 * and must be instantiated with the new keyword. In older browsers,
4101 * specifically IE11, those are objects with a prototype property defined,
4102 * since they are not supposed to be extended or instantiated with the
4103 * new keyword. This forking logic supports both cases, specifically because
4104 * wc.ts relies on the construction path of the bridges to create new
4105 * fully qualifying web components.
4106 */
4107
4108 if (isFunction$1(SuperClass)) {
4109 HTMLBridgeElement = class extends SuperClass {};
4110 } else {
4111 HTMLBridgeElement = function () {
4112 // Bridge classes are not supposed to be instantiated directly in
4113 // browsers that do not support web components.
4114 throw new TypeError('Illegal constructor');
4115 }; // prototype inheritance dance
4116
4117
4118 setPrototypeOf$1(HTMLBridgeElement, SuperClass);
4119 setPrototypeOf$1(HTMLBridgeElement.prototype, SuperClass.prototype);
4120 defineProperty$1(HTMLBridgeElement.prototype, 'constructor', {
4121 writable: true,
4122 configurable: true,
4123 value: HTMLBridgeElement
4124 });
4125 }
4126
4127 const descriptors = create$1(null); // expose getters and setters for each public props on the new Element Bridge
4128
4129 for (let i = 0, len = props.length; i < len; i += 1) {
4130 const propName = props[i];
4131 descriptors[propName] = {
4132 get: createGetter(propName),
4133 set: createSetter(propName),
4134 enumerable: true,
4135 configurable: true
4136 };
4137 } // expose public methods as props on the new Element Bridge
4138
4139
4140 for (let i = 0, len = methods.length; i < len; i += 1) {
4141 const methodName = methods[i];
4142 descriptors[methodName] = {
4143 value: createMethodCaller(methodName),
4144 writable: true,
4145 configurable: true
4146 };
4147 }
4148
4149 defineProperties$1(HTMLBridgeElement.prototype, descriptors);
4150 return HTMLBridgeElement;
4151}
4152const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
4153freeze$1(BaseBridgeElement);
4154seal$1(BaseBridgeElement.prototype);
4155
4156/*
4157 * Copyright (c) 2020, salesforce.com, inc.
4158 * All rights reserved.
4159 * SPDX-License-Identifier: MIT
4160 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4161 */
4162function resolveCircularModuleDependency(fn) {
4163 return fn();
4164}
4165function isCircularModuleDependency(obj) {
4166 return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
4167}
4168
4169/*
4170 * Copyright (c) 2018, salesforce.com, inc.
4171 * All rights reserved.
4172 * SPDX-License-Identifier: MIT
4173 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4174 */
4175const CtorToDefMap = new WeakMap();
4176
4177function getCtorProto(Ctor) {
4178 let proto = getPrototypeOf$1(Ctor);
4179
4180 if (isNull$1(proto)) {
4181 throw new ReferenceError(`Invalid prototype chain for ${Ctor.name}, you must extend LightningElement.`);
4182 } // covering the cases where the ref is circular in AMD
4183
4184
4185 if (isCircularModuleDependency(proto)) {
4186 const p = resolveCircularModuleDependency(proto);
4187
4188 if (process.env.NODE_ENV !== 'production') {
4189 if (isNull$1(p)) {
4190 throw new ReferenceError(`Circular module dependency for ${Ctor.name}, must resolve to a constructor that extends LightningElement.`);
4191 }
4192 } // escape hatch for Locker and other abstractions to provide their own base class instead
4193 // of our Base class without having to leak it to user-land. If the circular function returns
4194 // itself, that's the signal that we have hit the end of the proto chain, which must always
4195 // be base.
4196
4197
4198 proto = p === proto ? BaseLightningElement : p;
4199 }
4200
4201 return proto;
4202}
4203
4204function createComponentDef(Ctor) {
4205 if (process.env.NODE_ENV !== 'production') {
4206 const ctorName = Ctor.name; // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
4207 // assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
4208
4209 assert.isTrue(Ctor.constructor, `Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
4210 }
4211
4212 const decoratorsMeta = getDecoratorsMeta(Ctor);
4213 const {
4214 apiFields,
4215 apiFieldsConfig,
4216 apiMethods,
4217 wiredFields,
4218 wiredMethods,
4219 observedFields
4220 } = decoratorsMeta;
4221 const proto = Ctor.prototype;
4222 let {
4223 connectedCallback,
4224 disconnectedCallback,
4225 renderedCallback,
4226 errorCallback,
4227 render
4228 } = proto;
4229 const superProto = getCtorProto(Ctor);
4230 const superDef = superProto !== BaseLightningElement ? getComponentInternalDef(superProto) : lightingElementDef;
4231 const bridge = HTMLBridgeElementFactory(superDef.bridge, keys$1(apiFields), keys$1(apiMethods));
4232 const props = assign$1(create$1(null), superDef.props, apiFields);
4233 const propsConfig = assign$1(create$1(null), superDef.propsConfig, apiFieldsConfig);
4234 const methods = assign$1(create$1(null), superDef.methods, apiMethods);
4235 const wire = assign$1(create$1(null), superDef.wire, wiredFields, wiredMethods);
4236 connectedCallback = connectedCallback || superDef.connectedCallback;
4237 disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
4238 renderedCallback = renderedCallback || superDef.renderedCallback;
4239 errorCallback = errorCallback || superDef.errorCallback;
4240 render = render || superDef.render;
4241 const template = getComponentRegisteredTemplate(Ctor) || superDef.template;
4242 const name = Ctor.name || superDef.name; // installing observed fields into the prototype.
4243
4244 defineProperties$1(proto, observedFields);
4245 const def = {
4246 ctor: Ctor,
4247 name,
4248 wire,
4249 props,
4250 propsConfig,
4251 methods,
4252 bridge,
4253 template,
4254 connectedCallback,
4255 disconnectedCallback,
4256 renderedCallback,
4257 errorCallback,
4258 render
4259 };
4260
4261 if (process.env.NODE_ENV !== 'production') {
4262 freeze$1(Ctor.prototype);
4263 }
4264
4265 return def;
4266}
4267/**
4268 * EXPERIMENTAL: This function allows for the identification of LWC constructors. This API is
4269 * subject to change or being removed.
4270 */
4271
4272
4273function isComponentConstructor(ctor) {
4274 if (!isFunction$1(ctor)) {
4275 return false;
4276 } // Fast path: LightningElement is part of the prototype chain of the constructor.
4277
4278
4279 if (ctor.prototype instanceof BaseLightningElement) {
4280 return true;
4281 } // Slow path: LightningElement is not part of the prototype chain of the constructor, we need
4282 // climb up the constructor prototype chain to check in case there are circular dependencies
4283 // to resolve.
4284
4285
4286 let current = ctor;
4287
4288 do {
4289 if (isCircularModuleDependency(current)) {
4290 const circularResolved = resolveCircularModuleDependency(current); // If the circular function returns itself, that's the signal that we have hit the end
4291 // of the proto chain, which must always be a valid base constructor.
4292
4293 if (circularResolved === current) {
4294 return true;
4295 }
4296
4297 current = circularResolved;
4298 }
4299
4300 if (current === BaseLightningElement) {
4301 return true;
4302 }
4303 } while (!isNull$1(current) && (current = getPrototypeOf$1(current))); // Finally return false if the LightningElement is not part of the prototype chain.
4304
4305
4306 return false;
4307}
4308function getComponentInternalDef(Ctor) {
4309 let def = CtorToDefMap.get(Ctor);
4310
4311 if (isUndefined$1(def)) {
4312 if (isCircularModuleDependency(Ctor)) {
4313 const resolvedCtor = resolveCircularModuleDependency(Ctor);
4314 def = getComponentInternalDef(resolvedCtor); // Cache the unresolved component ctor too. The next time if the same unresolved ctor is used,
4315 // look up the definition in cache instead of re-resolving and recreating the def.
4316
4317 CtorToDefMap.set(Ctor, def);
4318 return def;
4319 }
4320
4321 if (!isComponentConstructor(Ctor)) {
4322 throw new TypeError(`${Ctor} is not a valid component, or does not extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration.`);
4323 }
4324
4325 def = createComponentDef(Ctor);
4326 CtorToDefMap.set(Ctor, def);
4327 }
4328
4329 return def;
4330}
4331/** Set prototype for public methods and properties on the element. No DOM Patching occurs here. */
4332
4333function setElementProto(elm, def) {
4334 setPrototypeOf$1(elm, def.bridge.prototype);
4335}
4336const lightingElementDef = {
4337 ctor: BaseLightningElement,
4338 name: BaseLightningElement.name,
4339 props: lightningBasedDescriptors,
4340 propsConfig: EmptyObject,
4341 methods: EmptyObject,
4342 wire: EmptyObject,
4343 bridge: BaseBridgeElement,
4344 template: defaultEmptyTemplate,
4345 render: BaseLightningElement.prototype.render
4346};
4347var PropDefType;
4348
4349(function (PropDefType) {
4350 PropDefType["any"] = "any";
4351})(PropDefType || (PropDefType = {}));
4352/**
4353 * EXPERIMENTAL: This function allows for the collection of internal component metadata. This API is
4354 * subject to change or being removed.
4355 */
4356
4357
4358function getComponentDef(Ctor) {
4359 const def = getComponentInternalDef(Ctor); // From the internal def object, we need to extract the info that is useful
4360 // for some external services, e.g.: Locker Service, usually, all they care
4361 // is about the shape of the constructor, the internals of it are not relevant
4362 // because they don't have a way to mess with that.
4363
4364 const {
4365 ctor,
4366 name,
4367 props,
4368 propsConfig,
4369 methods
4370 } = def;
4371 const publicProps = {};
4372
4373 for (const key in props) {
4374 // avoid leaking the reference to the public props descriptors
4375 publicProps[key] = {
4376 config: propsConfig[key] || 0,
4377 type: PropDefType.any,
4378 attr: getAttrNameFromPropName(key)
4379 };
4380 }
4381
4382 const publicMethods = {};
4383
4384 for (const key in methods) {
4385 // avoid leaking the reference to the public method descriptors
4386 publicMethods[key] = methods[key].value;
4387 }
4388
4389 return {
4390 ctor,
4391 name,
4392 props: publicProps,
4393 methods: publicMethods
4394 };
4395}
4396
4397/*
4398 * Copyright (c) 2018, salesforce.com, inc.
4399 * All rights reserved.
4400 * SPDX-License-Identifier: MIT
4401 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4402 */
4403
4404const noop = () => void 0;
4405
4406function observeElementChildNodes(elm) {
4407 elm.$domManual$ = true;
4408}
4409
4410function setElementShadowToken(elm, token) {
4411 elm.$shadowToken$ = token;
4412}
4413
4414function updateNodeHook(oldVnode, vnode) {
4415 const {
4416 elm,
4417 text,
4418 owner: {
4419 renderer
4420 }
4421 } = vnode;
4422
4423 if (oldVnode.text !== text) {
4424 if (process.env.NODE_ENV !== 'production') {
4425 unlockDomMutation();
4426 }
4427
4428 renderer.setText(elm, text);
4429
4430 if (process.env.NODE_ENV !== 'production') {
4431 lockDomMutation();
4432 }
4433 }
4434}
4435function insertNodeHook(vnode, parentNode, referenceNode) {
4436 const {
4437 renderer
4438 } = vnode.owner;
4439
4440 if (process.env.NODE_ENV !== 'production') {
4441 unlockDomMutation();
4442 }
4443
4444 renderer.insert(vnode.elm, parentNode, referenceNode);
4445
4446 if (process.env.NODE_ENV !== 'production') {
4447 lockDomMutation();
4448 }
4449}
4450function removeNodeHook(vnode, parentNode) {
4451 const {
4452 renderer
4453 } = vnode.owner;
4454
4455 if (process.env.NODE_ENV !== 'production') {
4456 unlockDomMutation();
4457 }
4458
4459 renderer.remove(vnode.elm, parentNode);
4460
4461 if (process.env.NODE_ENV !== 'production') {
4462 lockDomMutation();
4463 }
4464}
4465function createElmHook(vnode) {
4466 modEvents.create(vnode); // Attrs need to be applied to element before props
4467 // IE11 will wipe out value on radio inputs if value
4468 // is set before type=radio.
4469
4470 modAttrs.create(vnode);
4471 modProps.create(vnode);
4472 modStaticClassName.create(vnode);
4473 modStaticStyle.create(vnode);
4474 modComputedClassName.create(vnode);
4475 modComputedStyle.create(vnode);
4476}
4477var LWCDOMMode;
4478
4479(function (LWCDOMMode) {
4480 LWCDOMMode["manual"] = "manual";
4481})(LWCDOMMode || (LWCDOMMode = {}));
4482
4483function fallbackElmHook(elm, vnode) {
4484 const {
4485 owner
4486 } = vnode;
4487
4488 if (isTrue$1(owner.renderer.syntheticShadow)) {
4489 const {
4490 data: {
4491 context
4492 }
4493 } = vnode;
4494 const {
4495 shadowAttribute
4496 } = owner.context;
4497
4498 if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === LWCDOMMode.manual) {
4499 // this element will now accept any manual content inserted into it
4500 observeElementChildNodes(elm);
4501 } // when running in synthetic shadow mode, we need to set the shadowToken value
4502 // into each element from the template, so they can be styled accordingly.
4503
4504
4505 setElementShadowToken(elm, shadowAttribute);
4506 }
4507
4508 if (process.env.NODE_ENV !== 'production') {
4509 const {
4510 data: {
4511 context
4512 }
4513 } = vnode;
4514 const isPortal = !isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === LWCDOMMode.manual;
4515 patchElementWithRestrictions(elm, {
4516 isPortal
4517 });
4518 }
4519}
4520function updateElmHook(oldVnode, vnode) {
4521 // Attrs need to be applied to element before props
4522 // IE11 will wipe out value on radio inputs if value
4523 // is set before type=radio.
4524 modAttrs.update(oldVnode, vnode);
4525 modProps.update(oldVnode, vnode);
4526 modComputedClassName.update(oldVnode, vnode);
4527 modComputedStyle.update(oldVnode, vnode);
4528}
4529function insertCustomElmHook(vnode) {
4530 const vm = getAssociatedVM(vnode.elm);
4531 appendVM(vm);
4532}
4533function updateChildrenHook(oldVnode, vnode) {
4534 const {
4535 children,
4536 owner
4537 } = vnode;
4538 const fn = hasDynamicChildren(children) ? updateDynamicChildren : updateStaticChildren;
4539 runWithBoundaryProtection(owner, owner.owner, noop, () => {
4540 fn(vnode.elm, oldVnode.children, children);
4541 }, noop);
4542}
4543function allocateChildrenHook(vnode) {
4544 const vm = getAssociatedVM(vnode.elm); // A component with slots will re-render because:
4545 // 1- There is a change of the internal state.
4546 // 2- There is a change on the external api (ex: slots)
4547 //
4548 // In case #1, the vnodes in the cmpSlots will be reused since they didn't changed. This routine emptied the
4549 // slotted children when those VCustomElement were rendered and therefore in subsequent calls to allocate children
4550 // in a reused VCustomElement, there won't be any slotted children.
4551 // For those cases, we will use the reference for allocated children stored when rendering the fresh VCustomElement.
4552 //
4553 // In case #2, we will always get a fresh VCustomElement.
4554
4555 const children = vnode.aChildren || vnode.children;
4556 vm.aChildren = children;
4557
4558 if (isTrue$1(vm.renderer.syntheticShadow)) {
4559 // slow path
4560 allocateInSlot(vm, children); // save the allocated children in case this vnode is reused.
4561
4562 vnode.aChildren = children; // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4563
4564 vnode.children = EmptyArray;
4565 }
4566}
4567function createViewModelHook(elm, vnode) {
4568 if (!isUndefined$1(getAssociatedVMIfPresent(elm))) {
4569 // There is a possibility that a custom element is registered under tagName,
4570 // in which case, the initialization is already carry on, and there is nothing else
4571 // to do here since this hook is called right after invoking `document.createElement`.
4572 return;
4573 }
4574
4575 const {
4576 sel,
4577 mode,
4578 ctor,
4579 owner
4580 } = vnode;
4581 const def = getComponentInternalDef(ctor);
4582 setElementProto(elm, def);
4583
4584 if (isTrue$1(owner.renderer.syntheticShadow)) {
4585 const {
4586 shadowAttribute
4587 } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4588 // into each element from the template, so they can be styled accordingly.
4589
4590 setElementShadowToken(elm, shadowAttribute);
4591 }
4592
4593 createVM(elm, def, {
4594 mode,
4595 owner,
4596 tagName: sel,
4597 renderer: owner.renderer
4598 });
4599
4600 if (process.env.NODE_ENV !== 'production') {
4601 assert.isTrue(isArray(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4602 }
4603}
4604function createCustomElmHook(vnode) {
4605 modEvents.create(vnode); // Attrs need to be applied to element before props
4606 // IE11 will wipe out value on radio inputs if value
4607 // is set before type=radio.
4608
4609 modAttrs.create(vnode);
4610 modProps.create(vnode);
4611 modStaticClassName.create(vnode);
4612 modStaticStyle.create(vnode);
4613 modComputedClassName.create(vnode);
4614 modComputedStyle.create(vnode);
4615}
4616function createChildrenHook(vnode) {
4617 const {
4618 elm,
4619 children
4620 } = vnode;
4621
4622 for (let j = 0; j < children.length; ++j) {
4623 const ch = children[j];
4624
4625 if (ch != null) {
4626 ch.hook.create(ch);
4627 ch.hook.insert(ch, elm, null);
4628 }
4629 }
4630}
4631function rerenderCustomElmHook(vnode) {
4632 const vm = getAssociatedVM(vnode.elm);
4633
4634 if (process.env.NODE_ENV !== 'production') {
4635 assert.isTrue(isArray(vnode.children), `Invalid vnode for a custom element, it must have children defined.`);
4636 }
4637
4638 rerenderVM(vm);
4639}
4640function updateCustomElmHook(oldVnode, vnode) {
4641 // Attrs need to be applied to element before props
4642 // IE11 will wipe out value on radio inputs if value
4643 // is set before type=radio.
4644 modAttrs.update(oldVnode, vnode);
4645 modProps.update(oldVnode, vnode);
4646 modComputedClassName.update(oldVnode, vnode);
4647 modComputedStyle.update(oldVnode, vnode);
4648}
4649function removeElmHook(vnode) {
4650 // this method only needs to search on child vnodes from template
4651 // to trigger the remove hook just in case some of those children
4652 // are custom elements.
4653 const {
4654 children,
4655 elm
4656 } = vnode;
4657
4658 for (let j = 0, len = children.length; j < len; ++j) {
4659 const ch = children[j];
4660
4661 if (!isNull$1(ch)) {
4662 ch.hook.remove(ch, elm);
4663 }
4664 }
4665}
4666function removeCustomElmHook(vnode) {
4667 // for custom elements we don't have to go recursively because the removeVM routine
4668 // will take care of disconnecting any child VM attached to its shadow as well.
4669 removeVM(getAssociatedVM(vnode.elm));
4670} // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4671
4672const FromIteration = new WeakMap(); // dynamic children means it was generated by an iteration
4673// in a template, and will require a more complex diffing algo.
4674
4675function markAsDynamicChildren(children) {
4676 FromIteration.set(children, 1);
4677}
4678function hasDynamicChildren(children) {
4679 return FromIteration.has(children);
4680}
4681
4682/*
4683 * Copyright (c) 2018, salesforce.com, inc.
4684 * All rights reserved.
4685 * SPDX-License-Identifier: MIT
4686 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4687 */
4688const CHAR_S = 115;
4689const CHAR_V = 118;
4690const CHAR_G = 103;
4691const NamespaceAttributeForSVG = 'http://www.w3.org/2000/svg';
4692const SymbolIterator = Symbol.iterator;
4693const TextHook = {
4694 create: vnode => {
4695 const {
4696 renderer
4697 } = vnode.owner;
4698 const elm = renderer.createText(vnode.text);
4699 linkNodeToShadow(elm, vnode);
4700 vnode.elm = elm;
4701 },
4702 update: updateNodeHook,
4703 insert: insertNodeHook,
4704 move: insertNodeHook,
4705 remove: removeNodeHook
4706}; // insert is called after update, which is used somewhere else (via a module)
4707// to mark the vm as inserted, that means we cannot use update as the main channel
4708// to rehydrate when dirty, because sometimes the element is not inserted just yet,
4709// which breaks some invariants. For that reason, we have the following for any
4710// Custom Element that is inserted via a template.
4711
4712const ElementHook = {
4713 create: vnode => {
4714 const {
4715 sel,
4716 data: {
4717 ns
4718 },
4719 owner: {
4720 renderer
4721 }
4722 } = vnode;
4723 const elm = renderer.createElement(sel, ns);
4724 linkNodeToShadow(elm, vnode);
4725 fallbackElmHook(elm, vnode);
4726 vnode.elm = elm;
4727 createElmHook(vnode);
4728 },
4729 update: (oldVnode, vnode) => {
4730 updateElmHook(oldVnode, vnode);
4731 updateChildrenHook(oldVnode, vnode);
4732 },
4733 insert: (vnode, parentNode, referenceNode) => {
4734 insertNodeHook(vnode, parentNode, referenceNode);
4735 createChildrenHook(vnode);
4736 },
4737 move: (vnode, parentNode, referenceNode) => {
4738 insertNodeHook(vnode, parentNode, referenceNode);
4739 },
4740 remove: (vnode, parentNode) => {
4741 removeNodeHook(vnode, parentNode);
4742 removeElmHook(vnode);
4743 }
4744};
4745const CustomElementHook = {
4746 create: vnode => {
4747 const {
4748 sel,
4749 owner: {
4750 renderer
4751 }
4752 } = vnode;
4753 const elm = renderer.createElement(sel);
4754 linkNodeToShadow(elm, vnode);
4755 createViewModelHook(elm, vnode);
4756 vnode.elm = elm;
4757 allocateChildrenHook(vnode);
4758 createCustomElmHook(vnode);
4759 },
4760 update: (oldVnode, vnode) => {
4761 updateCustomElmHook(oldVnode, vnode); // in fallback mode, the allocation will always set children to
4762 // empty and delegate the real allocation to the slot elements
4763
4764 allocateChildrenHook(vnode); // in fallback mode, the children will be always empty, so, nothing
4765 // will happen, but in native, it does allocate the light dom
4766
4767 updateChildrenHook(oldVnode, vnode); // this will update the shadowRoot
4768
4769 rerenderCustomElmHook(vnode);
4770 },
4771 insert: (vnode, parentNode, referenceNode) => {
4772 insertNodeHook(vnode, parentNode, referenceNode);
4773 const vm = getAssociatedVM(vnode.elm);
4774
4775 if (process.env.NODE_ENV !== 'production') {
4776 assert.isTrue(vm.state === VMState.created, `${vm} cannot be recycled.`);
4777 }
4778
4779 runConnectedCallback(vm);
4780 createChildrenHook(vnode);
4781 insertCustomElmHook(vnode);
4782 },
4783 move: (vnode, parentNode, referenceNode) => {
4784 insertNodeHook(vnode, parentNode, referenceNode);
4785 },
4786 remove: (vnode, parentNode) => {
4787 removeNodeHook(vnode, parentNode);
4788 removeCustomElmHook(vnode);
4789 }
4790};
4791
4792function linkNodeToShadow(elm, vnode) {
4793 // TODO [#1164]: this should eventually be done by the polyfill directly
4794 elm.$shadowResolver$ = vnode.owner.cmpRoot.$shadowResolver$;
4795} // TODO [#1136]: this should be done by the compiler, adding ns to every sub-element
4796
4797
4798function addNS(vnode) {
4799 const {
4800 data,
4801 children,
4802 sel
4803 } = vnode;
4804 data.ns = NamespaceAttributeForSVG; // TODO [#1275]: review why `sel` equal `foreignObject` should get this `ns`
4805
4806 if (isArray(children) && sel !== 'foreignObject') {
4807 for (let j = 0, n = children.length; j < n; ++j) {
4808 const childNode = children[j];
4809
4810 if (childNode != null && childNode.hook === ElementHook) {
4811 addNS(childNode);
4812 }
4813 }
4814 }
4815}
4816
4817function addVNodeToChildLWC(vnode) {
4818 ArrayPush$1.call(getVMBeingRendered().velements, vnode);
4819} // [h]tml node
4820
4821
4822function h(sel, data, children) {
4823 const vmBeingRendered = getVMBeingRendered();
4824
4825 if (process.env.NODE_ENV !== 'production') {
4826 assert.isTrue(isString$1(sel), `h() 1st argument sel must be a string.`);
4827 assert.isTrue(isObject$1(data), `h() 2nd argument data must be an object.`);
4828 assert.isTrue(isArray(children), `h() 3rd argument children must be an array.`);
4829 assert.isTrue('key' in data, ` <${sel}> "key" attribute is invalid or missing for ${vmBeingRendered}. Key inside iterator is either undefined or null.`); // checking reserved internal data properties
4830
4831 assert.isFalse(data.className && data.classMap, `vnode.data.className and vnode.data.classMap ambiguous declaration.`);
4832 assert.isFalse(data.styleMap && data.style, `vnode.data.styleMap and vnode.data.style ambiguous declaration.`);
4833
4834 if (data.style && !isString$1(data.style)) {
4835 logError(`Invalid 'style' attribute passed to <${sel}> is ignored. This attribute must be a string value.`, vmBeingRendered);
4836 }
4837
4838 forEach$1.call(children, childVnode => {
4839 if (childVnode != null) {
4840 assert.isTrue(childVnode && 'sel' in childVnode && 'data' in childVnode && 'children' in childVnode && 'text' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
4841 }
4842 });
4843 }
4844
4845 const {
4846 key
4847 } = data;
4848 let text, elm;
4849 const vnode = {
4850 sel,
4851 data,
4852 children,
4853 text,
4854 elm,
4855 key,
4856 hook: ElementHook,
4857 owner: vmBeingRendered
4858 };
4859
4860 if (sel.length === 3 && StringCharCodeAt$1.call(sel, 0) === CHAR_S && StringCharCodeAt$1.call(sel, 1) === CHAR_V && StringCharCodeAt$1.call(sel, 2) === CHAR_G) {
4861 addNS(vnode);
4862 }
4863
4864 return vnode;
4865} // [t]ab[i]ndex function
4866
4867function ti(value) {
4868 // if value is greater than 0, we normalize to 0
4869 // If value is an invalid tabIndex value (null, undefined, string, etc), we let that value pass through
4870 // If value is less than -1, we don't care
4871 const shouldNormalize = value > 0 && !(isTrue$1(value) || isFalse$1(value));
4872
4873 if (process.env.NODE_ENV !== 'production') {
4874 const vmBeingRendered = getVMBeingRendered();
4875
4876 if (shouldNormalize) {
4877 logError(`Invalid tabindex value \`${toString(value)}\` in template for ${vmBeingRendered}. This attribute must be set to 0 or -1.`, vmBeingRendered);
4878 }
4879 }
4880
4881 return shouldNormalize ? 0 : value;
4882} // [s]lot element node
4883
4884function s(slotName, data, children, slotset) {
4885 if (process.env.NODE_ENV !== 'production') {
4886 assert.isTrue(isString$1(slotName), `s() 1st argument slotName must be a string.`);
4887 assert.isTrue(isObject$1(data), `s() 2nd argument data must be an object.`);
4888 assert.isTrue(isArray(children), `h() 3rd argument children must be an array.`);
4889 }
4890
4891 if (!isUndefined$1(slotset) && !isUndefined$1(slotset[slotName]) && slotset[slotName].length !== 0) {
4892 children = slotset[slotName];
4893 }
4894
4895 const vnode = h('slot', data, children);
4896
4897 if (vnode.owner.renderer.syntheticShadow) {
4898 // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
4899 sc(children);
4900 }
4901
4902 return vnode;
4903} // [c]ustom element node
4904
4905function c(sel, Ctor, data, children = EmptyArray) {
4906 const vmBeingRendered = getVMBeingRendered();
4907
4908 if (process.env.NODE_ENV !== 'production') {
4909 assert.isTrue(isString$1(sel), `c() 1st argument sel must be a string.`);
4910 assert.isTrue(isFunction$1(Ctor), `c() 2nd argument Ctor must be a function.`);
4911 assert.isTrue(isObject$1(data), `c() 3nd argument data must be an object.`);
4912 assert.isTrue(arguments.length === 3 || isArray(children), `c() 4nd argument data must be an array.`); // checking reserved internal data properties
4913
4914 assert.isFalse(data.className && data.classMap, `vnode.data.className and vnode.data.classMap ambiguous declaration.`);
4915 assert.isFalse(data.styleMap && data.style, `vnode.data.styleMap and vnode.data.style ambiguous declaration.`);
4916
4917 if (data.style && !isString$1(data.style)) {
4918 logError(`Invalid 'style' attribute passed to <${sel}> is ignored. This attribute must be a string value.`, vmBeingRendered);
4919 }
4920
4921 if (arguments.length === 4) {
4922 forEach$1.call(children, childVnode => {
4923 if (childVnode != null) {
4924 assert.isTrue(childVnode && 'sel' in childVnode && 'data' in childVnode && 'children' in childVnode && 'text' in childVnode && 'elm' in childVnode && 'key' in childVnode, `${childVnode} is not a vnode.`);
4925 }
4926 });
4927 }
4928 }
4929
4930 const {
4931 key
4932 } = data;
4933 let text, elm;
4934 const vnode = {
4935 sel,
4936 data,
4937 children,
4938 text,
4939 elm,
4940 key,
4941 hook: CustomElementHook,
4942 ctor: Ctor,
4943 owner: vmBeingRendered,
4944 mode: 'open'
4945 };
4946 addVNodeToChildLWC(vnode);
4947 return vnode;
4948} // [i]terable node
4949
4950function i(iterable, factory) {
4951 const list = []; // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
4952
4953 sc(list);
4954 const vmBeingRendered = getVMBeingRendered();
4955
4956 if (isUndefined$1(iterable) || iterable === null) {
4957 if (process.env.NODE_ENV !== 'production') {
4958 logError(`Invalid template iteration for value "${toString(iterable)}" in ${vmBeingRendered}. It must be an Array or an iterable Object.`, vmBeingRendered);
4959 }
4960
4961 return list;
4962 }
4963
4964 if (process.env.NODE_ENV !== 'production') {
4965 assert.isFalse(isUndefined$1(iterable[SymbolIterator]), `Invalid template iteration for value \`${toString(iterable)}\` in ${vmBeingRendered}. It must be an array-like object and not \`null\` nor \`undefined\`.`);
4966 }
4967
4968 const iterator = iterable[SymbolIterator]();
4969
4970 if (process.env.NODE_ENV !== 'production') {
4971 assert.isTrue(iterator && isFunction$1(iterator.next), `Invalid iterator function for "${toString(iterable)}" in ${vmBeingRendered}.`);
4972 }
4973
4974 let next = iterator.next();
4975 let j = 0;
4976 let {
4977 value,
4978 done: last
4979 } = next;
4980 let keyMap;
4981 let iterationError;
4982
4983 if (process.env.NODE_ENV !== 'production') {
4984 keyMap = create$1(null);
4985 }
4986
4987 while (last === false) {
4988 // implementing a look-back-approach because we need to know if the element is the last
4989 next = iterator.next();
4990 last = next.done; // template factory logic based on the previous collected value
4991
4992 const vnode = factory(value, j, j === 0, last);
4993
4994 if (isArray(vnode)) {
4995 ArrayPush$1.apply(list, vnode);
4996 } else {
4997 ArrayPush$1.call(list, vnode);
4998 }
4999
5000 if (process.env.NODE_ENV !== 'production') {
5001 const vnodes = isArray(vnode) ? vnode : [vnode];
5002 forEach$1.call(vnodes, childVnode => {
5003 if (!isNull$1(childVnode) && isObject$1(childVnode) && !isUndefined$1(childVnode.sel)) {
5004 const {
5005 key
5006 } = childVnode;
5007
5008 if (isString$1(key) || isNumber(key)) {
5009 if (keyMap[key] === 1 && isUndefined$1(iterationError)) {
5010 iterationError = `Duplicated "key" attribute value for "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. A key with value "${childVnode.key}" appears more than once in the iteration. Key values must be unique numbers or strings.`;
5011 }
5012
5013 keyMap[key] = 1;
5014 } else if (isUndefined$1(iterationError)) {
5015 iterationError = `Invalid "key" attribute value in "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. Set a unique "key" value on all iterated child elements.`;
5016 }
5017 }
5018 });
5019 } // preparing next value
5020
5021
5022 j += 1;
5023 value = next.value;
5024 }
5025
5026 if (process.env.NODE_ENV !== 'production') {
5027 if (!isUndefined$1(iterationError)) {
5028 logError(iterationError, vmBeingRendered);
5029 }
5030 }
5031
5032 return list;
5033}
5034/**
5035 * [f]lattening
5036 */
5037
5038function f(items) {
5039 if (process.env.NODE_ENV !== 'production') {
5040 assert.isTrue(isArray(items), 'flattening api can only work with arrays.');
5041 }
5042
5043 const len = items.length;
5044 const flattened = []; // TODO [#1276]: compiler should give us some sort of indicator when a vnodes collection is dynamic
5045
5046 sc(flattened);
5047
5048 for (let j = 0; j < len; j += 1) {
5049 const item = items[j];
5050
5051 if (isArray(item)) {
5052 ArrayPush$1.apply(flattened, item);
5053 } else {
5054 ArrayPush$1.call(flattened, item);
5055 }
5056 }
5057
5058 return flattened;
5059} // [t]ext node
5060
5061function t(text) {
5062 const data = EmptyObject;
5063 let sel, children, key, elm;
5064 return {
5065 sel,
5066 data,
5067 children,
5068 text,
5069 elm,
5070 key,
5071 hook: TextHook,
5072 owner: getVMBeingRendered()
5073 };
5074} // [d]ynamic value to produce a text vnode
5075
5076function d(value) {
5077 if (value == null) {
5078 return null;
5079 }
5080
5081 return t(value);
5082} // [b]ind function
5083
5084function b(fn) {
5085 const vmBeingRendered = getVMBeingRendered();
5086
5087 if (isNull$1(vmBeingRendered)) {
5088 throw new Error();
5089 }
5090
5091 const vm = vmBeingRendered;
5092 return function (event) {
5093 invokeEventListener(vm, fn, vm.component, event);
5094 };
5095} // [k]ey function
5096
5097function k(compilerKey, obj) {
5098 switch (typeof obj) {
5099 case 'number':
5100 case 'string':
5101 return compilerKey + ':' + obj;
5102
5103 case 'object':
5104 if (process.env.NODE_ENV !== 'production') {
5105 assert.fail(`Invalid key value "${obj}" in ${getVMBeingRendered()}. Key must be a string or number.`);
5106 }
5107
5108 }
5109} // [g]lobal [id] function
5110
5111function gid(id) {
5112 const vmBeingRendered = getVMBeingRendered();
5113
5114 if (isUndefined$1(id) || id === '') {
5115 if (process.env.NODE_ENV !== 'production') {
5116 logError(`Invalid id value "${id}". The id attribute must contain a non-empty string.`, vmBeingRendered);
5117 }
5118
5119 return id;
5120 } // We remove attributes when they are assigned a value of null
5121
5122
5123 if (isNull$1(id)) {
5124 return null;
5125 }
5126
5127 return `${id}-${vmBeingRendered.idx}`;
5128} // [f]ragment [id] function
5129
5130function fid(url) {
5131 const vmBeingRendered = getVMBeingRendered();
5132
5133 if (isUndefined$1(url) || url === '') {
5134 if (process.env.NODE_ENV !== 'production') {
5135 if (isUndefined$1(url)) {
5136 logError(`Undefined url value for "href" or "xlink:href" attribute. Expected a non-empty string.`, vmBeingRendered);
5137 }
5138 }
5139
5140 return url;
5141 } // We remove attributes when they are assigned a value of null
5142
5143
5144 if (isNull$1(url)) {
5145 return null;
5146 } // Apply transformation only for fragment-only-urls
5147
5148
5149 if (/^#/.test(url)) {
5150 return `${url}-${vmBeingRendered.idx}`;
5151 }
5152
5153 return url;
5154}
5155/**
5156 * Map to store an index value assigned to any dynamic component reference ingested
5157 * by dc() api. This allows us to generate a unique unique per template per dynamic
5158 * component reference to avoid diffing algo mismatches.
5159 */
5160
5161const DynamicImportedComponentMap = new Map();
5162let dynamicImportedComponentCounter = 0;
5163/**
5164 * create a dynamic component via `<x-foo lwc:dynamic={Ctor}>`
5165 */
5166
5167function dc(sel, Ctor, data, children) {
5168 if (process.env.NODE_ENV !== 'production') {
5169 assert.isTrue(isString$1(sel), `dc() 1st argument sel must be a string.`);
5170 assert.isTrue(isObject$1(data), `dc() 3nd argument data must be an object.`);
5171 assert.isTrue(arguments.length === 3 || isArray(children), `dc() 4nd argument data must be an array.`);
5172 } // null or undefined values should produce a null value in the VNodes
5173
5174
5175 if (Ctor == null) {
5176 return null;
5177 }
5178
5179 if (!isComponentConstructor(Ctor)) {
5180 throw new Error(`Invalid LWC Constructor ${toString(Ctor)} for custom element <${sel}>.`);
5181 }
5182
5183 let idx = DynamicImportedComponentMap.get(Ctor);
5184
5185 if (isUndefined$1(idx)) {
5186 idx = dynamicImportedComponentCounter++;
5187 DynamicImportedComponentMap.set(Ctor, idx);
5188 } // the new vnode key is a mix of idx and compiler key, this is required by the diffing algo
5189 // to identify different constructors as vnodes with different keys to avoid reusing the
5190 // element used for previous constructors.
5191
5192
5193 data.key = `dc:${idx}:${data.key}`;
5194 return c(sel, Ctor, data, children);
5195}
5196/**
5197 * slow children collection marking mechanism. this API allows the compiler to signal
5198 * to the engine that a particular collection of children must be diffed using the slow
5199 * algo based on keys due to the nature of the list. E.g.:
5200 *
5201 * - slot element's children: the content of the slot has to be dynamic when in synthetic
5202 * shadow mode because the `vnode.children` might be the slotted
5203 * content vs default content, in which case the size and the
5204 * keys are not matching.
5205 * - children that contain dynamic components
5206 * - children that are produced by iteration
5207 *
5208 */
5209
5210function sc(vnodes) {
5211 if (process.env.NODE_ENV !== 'production') {
5212 assert.isTrue(isArray(vnodes), 'sc() api can only work with arrays.');
5213 } // We have to mark the vnodes collection as dynamic so we can later on
5214 // choose to use the snabbdom virtual dom diffing algo instead of our
5215 // static dummy algo.
5216
5217
5218 markAsDynamicChildren(vnodes);
5219 return vnodes;
5220}
5221
5222var api$1 = /*#__PURE__*/Object.freeze({
5223 __proto__: null,
5224 h: h,
5225 ti: ti,
5226 s: s,
5227 c: c,
5228 i: i,
5229 f: f,
5230 t: t,
5231 d: d,
5232 b: b,
5233 k: k,
5234 gid: gid,
5235 fid: fid,
5236 dc: dc,
5237 sc: sc
5238});
5239
5240/*
5241 * Copyright (c) 2018, salesforce.com, inc.
5242 * All rights reserved.
5243 * SPDX-License-Identifier: MIT
5244 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5245 */
5246
5247function createShadowStyleVNode(content) {
5248 return h('style', {
5249 key: 'style',
5250 attrs: {
5251 type: 'text/css'
5252 }
5253 }, [t(content)]);
5254}
5255
5256function updateSyntheticShadowAttributes(vm, template) {
5257 const {
5258 elm,
5259 context,
5260 renderer
5261 } = vm;
5262 const {
5263 stylesheets: newStylesheets,
5264 stylesheetTokens: newStylesheetTokens
5265 } = template;
5266 let newHostAttribute;
5267 let newShadowAttribute; // Reset the styling token applied to the host element.
5268
5269 const oldHostAttribute = context.hostAttribute;
5270
5271 if (!isUndefined$1(oldHostAttribute)) {
5272 renderer.removeAttribute(elm, oldHostAttribute);
5273 } // Apply the new template styling token to the host element, if the new template has any
5274 // associated stylesheets.
5275
5276
5277 if (!isUndefined$1(newStylesheetTokens) && !isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5278 newHostAttribute = newStylesheetTokens.hostAttribute;
5279 newShadowAttribute = newStylesheetTokens.shadowAttribute;
5280 renderer.setAttribute(elm, newHostAttribute, '');
5281 } // Update the styling tokens present on the context object.
5282
5283
5284 context.hostAttribute = newHostAttribute;
5285 context.shadowAttribute = newShadowAttribute;
5286}
5287
5288function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5289 const content = [];
5290
5291 for (let i = 0; i < stylesheets.length; i++) {
5292 const stylesheet = stylesheets[i];
5293
5294 if (isArray(stylesheet)) {
5295 ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5296 } else {
5297 ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5298 }
5299 }
5300
5301 return content;
5302}
5303
5304function getStylesheetsContent(vm, template) {
5305 const {
5306 stylesheets,
5307 stylesheetTokens: tokens
5308 } = template;
5309 const {
5310 syntheticShadow
5311 } = vm.renderer;
5312 let content = [];
5313
5314 if (!isUndefined$1(stylesheets) && !isUndefined$1(tokens)) {
5315 const hostSelector = syntheticShadow ? `[${tokens.hostAttribute}]` : '';
5316 const shadowSelector = syntheticShadow ? `[${tokens.shadowAttribute}]` : '';
5317 content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, !syntheticShadow);
5318 }
5319
5320 return content;
5321}
5322function createStylesheet(vm, stylesheets) {
5323 const {
5324 renderer
5325 } = vm;
5326
5327 if (renderer.syntheticShadow) {
5328 for (let i = 0; i < stylesheets.length; i++) {
5329 renderer.insertGlobalStylesheet(stylesheets[i]);
5330 }
5331
5332 return null;
5333 } else {
5334 const shadowStyleSheetContent = ArrayJoin$1.call(stylesheets, '\n');
5335 return createShadowStyleVNode(shadowStyleSheetContent);
5336 }
5337}
5338
5339/*
5340 * Copyright (c) 2018, salesforce.com, inc.
5341 * All rights reserved.
5342 * SPDX-License-Identifier: MIT
5343 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5344 */
5345var GlobalMeasurementPhase;
5346
5347(function (GlobalMeasurementPhase) {
5348 GlobalMeasurementPhase["REHYDRATE"] = "lwc-rehydrate";
5349 GlobalMeasurementPhase["HYDRATE"] = "lwc-hydrate";
5350})(GlobalMeasurementPhase || (GlobalMeasurementPhase = {})); // Even if all the browser the engine supports implements the UserTiming API, we need to guard the measure APIs.
5351// JSDom (used in Jest) for example doesn't implement the UserTiming APIs.
5352
5353
5354const isUserTimingSupported = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
5355
5356function getMarkName(phase, vm) {
5357 // Adding the VM idx to the mark name creates a unique mark name component instance. This is necessary to produce
5358 // the right measures for components that are recursive.
5359 return `${getComponentTag(vm)} - ${phase} - ${vm.idx}`;
5360}
5361
5362function getMeasureName(phase, vm) {
5363 return `${getComponentTag(vm)} - ${phase}`;
5364}
5365
5366function start(markName) {
5367 performance.mark(markName);
5368}
5369
5370function end(measureName, markName) {
5371 performance.measure(measureName, markName); // Clear the created marks and measure to avoid filling the performance entries buffer.
5372 // Note: Even if the entries get deleted, existing PerformanceObservers preserve a copy of those entries.
5373
5374 performance.clearMarks(markName);
5375 performance.clearMarks(measureName);
5376}
5377
5378function noop$1() {
5379 /* do nothing */
5380}
5381
5382const startMeasure = !isUserTimingSupported ? noop$1 : function (phase, vm) {
5383 const markName = getMarkName(phase, vm);
5384 start(markName);
5385};
5386const endMeasure = !isUserTimingSupported ? noop$1 : function (phase, vm) {
5387 const markName = getMarkName(phase, vm);
5388 const measureName = getMeasureName(phase, vm);
5389 end(measureName, markName);
5390};
5391const startGlobalMeasure = !isUserTimingSupported ? noop$1 : function (phase, vm) {
5392 const markName = isUndefined$1(vm) ? phase : getMarkName(phase, vm);
5393 start(markName);
5394};
5395const endGlobalMeasure = !isUserTimingSupported ? noop$1 : function (phase, vm) {
5396 const markName = isUndefined$1(vm) ? phase : getMarkName(phase, vm);
5397 end(phase, markName);
5398};
5399
5400/*
5401 * Copyright (c) 2018, salesforce.com, inc.
5402 * All rights reserved.
5403 * SPDX-License-Identifier: MIT
5404 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5405 */
5406
5407function noop$2(_opId, _phase, _cmpName, _vm_idx) {}
5408
5409let logOperation = noop$2;
5410var OperationId;
5411
5412(function (OperationId) {
5413 OperationId[OperationId["constructor"] = 0] = "constructor";
5414 OperationId[OperationId["render"] = 1] = "render";
5415 OperationId[OperationId["patch"] = 2] = "patch";
5416 OperationId[OperationId["connectedCallback"] = 3] = "connectedCallback";
5417 OperationId[OperationId["renderedCallback"] = 4] = "renderedCallback";
5418 OperationId[OperationId["disconnectedCallback"] = 5] = "disconnectedCallback";
5419 OperationId[OperationId["errorCallback"] = 6] = "errorCallback";
5420})(OperationId || (OperationId = {}));
5421
5422var Phase;
5423
5424(function (Phase) {
5425 Phase[Phase["Start"] = 0] = "Start";
5426 Phase[Phase["Stop"] = 1] = "Stop";
5427})(Phase || (Phase = {}));
5428
5429const opIdToMeasurementPhaseMappingArray = ['constructor', 'render', 'patch', 'connectedCallback', 'renderedCallback', 'disconnectedCallback', 'errorCallback'];
5430let profilerEnabled = false;
5431let logMarks = false;
5432let bufferLogging = false;
5433
5434if (process.env.NODE_ENV !== 'production') {
5435 profilerEnabled = true;
5436 logMarks = true;
5437 bufferLogging = false;
5438}
5439
5440function trackProfilerState(callback) {
5441 callback(profilerEnabled);
5442}
5443
5444function logOperationStart(opId, vm) {
5445 if (logMarks) {
5446 startMeasure(opIdToMeasurementPhaseMappingArray[opId], vm);
5447 }
5448
5449 if (bufferLogging) {
5450 logOperation(opId, Phase.Start, vm.tagName, vm.idx);
5451 }
5452}
5453
5454function logOperationEnd(opId, vm) {
5455 if (logMarks) {
5456 endMeasure(opIdToMeasurementPhaseMappingArray[opId], vm);
5457 }
5458
5459 if (bufferLogging) {
5460 logOperation(opId, Phase.Stop, vm.tagName, vm.idx);
5461 }
5462}
5463
5464/*
5465 * Copyright (c) 2018, salesforce.com, inc.
5466 * All rights reserved.
5467 * SPDX-License-Identifier: MIT
5468 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5469 */
5470let isUpdatingTemplate = false;
5471let vmBeingRendered = null;
5472function getVMBeingRendered() {
5473 return vmBeingRendered;
5474}
5475function setVMBeingRendered(vm) {
5476 vmBeingRendered = vm;
5477}
5478let profilerEnabled$1 = false;
5479trackProfilerState(t => profilerEnabled$1 = t);
5480
5481function validateSlots(vm, html) {
5482 if (process.env.NODE_ENV === 'production') {
5483 // this method should never leak to prod
5484 throw new ReferenceError();
5485 }
5486
5487 const {
5488 cmpSlots
5489 } = vm;
5490 const {
5491 slots = EmptyArray
5492 } = html;
5493
5494 for (const slotName in cmpSlots) {
5495 // eslint-disable-next-line lwc-internal/no-production-assert
5496 assert.isTrue(isArray(cmpSlots[slotName]), `Slots can only be set to an array, instead received ${toString(cmpSlots[slotName])} for slot "${slotName}" in ${vm}.`);
5497
5498 if (slotName !== '' && ArrayIndexOf$1.call(slots, slotName) === -1) {
5499 // TODO [#1297]: this should never really happen because the compiler should always validate
5500 // eslint-disable-next-line lwc-internal/no-production-assert
5501 logError(`Ignoring unknown provided slot name "${slotName}" in ${vm}. Check for a typo on the slot attribute.`, vm);
5502 }
5503 }
5504}
5505
5506function evaluateTemplate(vm, html) {
5507 if (process.env.NODE_ENV !== 'production') {
5508 assert.isTrue(isFunction$1(html), `evaluateTemplate() second argument must be an imported template instead of ${toString(html)}`);
5509 }
5510
5511 const isUpdatingTemplateInception = isUpdatingTemplate;
5512 const vmOfTemplateBeingUpdatedInception = vmBeingRendered;
5513 let vnodes = [];
5514 runWithBoundaryProtection(vm, vm.owner, () => {
5515 // pre
5516 vmBeingRendered = vm;
5517
5518 if (profilerEnabled$1) {
5519 logOperationStart(OperationId.render, vm);
5520 }
5521 }, () => {
5522 // job
5523 const {
5524 component,
5525 context,
5526 cmpSlots,
5527 cmpTemplate,
5528 tro,
5529 renderer
5530 } = vm;
5531 tro.observe(() => {
5532 // Reset the cache memoizer for template when needed.
5533 if (html !== cmpTemplate) {
5534 // Perf opt: do not reset the shadow root during the first rendering (there is
5535 // nothing to reset).
5536 if (!isNull$1(cmpTemplate)) {
5537 // It is important to reset the content to avoid reusing similar elements
5538 // generated from a different template, because they could have similar IDs,
5539 // and snabbdom just rely on the IDs.
5540 resetShadowRoot(vm);
5541 } // Check that the template was built by the compiler.
5542
5543
5544 if (!isTemplateRegistered(html)) {
5545 throw new TypeError(`Invalid template returned by the render() method on ${vm}. It must return an imported template (e.g.: \`import html from "./${vm.def.name}.html"\`), instead, it has returned: ${toString(html)}.`);
5546 }
5547
5548 vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5549
5550 context.tplCache = create$1(null); // Update the synthetic shadow attributes on the host element if necessary.
5551
5552 if (renderer.syntheticShadow) {
5553 updateSyntheticShadowAttributes(vm, html);
5554 } // Evaluate, create stylesheet and cache the produced VNode for future
5555 // re-rendering.
5556
5557
5558 const stylesheetsContent = getStylesheetsContent(vm, html);
5559 context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
5560 }
5561
5562 if (process.env.NODE_ENV !== 'production') {
5563 // validating slots in every rendering since the allocated content might change over time
5564 validateSlots(vm, html);
5565 } // right before producing the vnodes, we clear up all internal references
5566 // to custom elements from the template.
5567
5568
5569 vm.velements = []; // Set the global flag that template is being updated
5570
5571 isUpdatingTemplate = true;
5572 vnodes = html.call(undefined, api$1, component, cmpSlots, context.tplCache);
5573 const {
5574 styleVNode
5575 } = context;
5576
5577 if (!isNull$1(styleVNode)) {
5578 ArrayUnshift$1.call(vnodes, styleVNode);
5579 }
5580 });
5581 }, () => {
5582 // post
5583 isUpdatingTemplate = isUpdatingTemplateInception;
5584 vmBeingRendered = vmOfTemplateBeingUpdatedInception;
5585
5586 if (profilerEnabled$1) {
5587 logOperationEnd(OperationId.render, vm);
5588 }
5589 });
5590
5591 if (process.env.NODE_ENV !== 'production') {
5592 assert.invariant(isArray(vnodes), `Compiler should produce html functions that always return an array.`);
5593 }
5594
5595 return vnodes;
5596}
5597
5598/*
5599 * Copyright (c) 2018, salesforce.com, inc.
5600 * All rights reserved.
5601 * SPDX-License-Identifier: MIT
5602 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5603 */
5604function addErrorComponentStack(vm, error) {
5605 if (!isFrozen$1(error) && isUndefined$1(error.wcStack)) {
5606 const wcStack = getErrorComponentStack(vm);
5607 defineProperty$1(error, 'wcStack', {
5608 get() {
5609 return wcStack;
5610 }
5611
5612 });
5613 }
5614}
5615
5616/*
5617 * Copyright (c) 2018, salesforce.com, inc.
5618 * All rights reserved.
5619 * SPDX-License-Identifier: MIT
5620 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5621 */
5622let isInvokingRender = false;
5623let vmBeingConstructed = null;
5624function isBeingConstructed(vm) {
5625 return vmBeingConstructed === vm;
5626}
5627let profilerEnabled$2 = false;
5628trackProfilerState(t => profilerEnabled$2 = t);
5629
5630const noop$3 = () => void 0;
5631
5632function invokeComponentCallback(vm, fn, args) {
5633 const {
5634 component,
5635 callHook,
5636 owner
5637 } = vm;
5638 let result;
5639 runWithBoundaryProtection(vm, owner, noop$3, () => {
5640 // job
5641 result = callHook(component, fn, args);
5642 }, noop$3);
5643 return result;
5644}
5645function invokeComponentConstructor(vm, Ctor) {
5646 const vmBeingConstructedInception = vmBeingConstructed;
5647 let error;
5648
5649 if (profilerEnabled$2) {
5650 logOperationStart(OperationId.constructor, vm);
5651 }
5652
5653 vmBeingConstructed = vm;
5654 /**
5655 * Constructors don't need to be wrapped with a boundary because for root elements
5656 * it should throw, while elements from template are already wrapped by a boundary
5657 * associated to the diffing algo.
5658 */
5659
5660 try {
5661 // job
5662 const result = new Ctor(); // Check indirectly if the constructor result is an instance of LightningElement. Using
5663 // the "instanceof" operator would not work here since Locker Service provides its own
5664 // implementation of LightningElement, so we indirectly check if the base constructor is
5665 // invoked by accessing the component on the vm.
5666
5667 if (vmBeingConstructed.component !== result) {
5668 throw new TypeError('Invalid component constructor, the class should extend LightningElement.');
5669 }
5670 } catch (e) {
5671 error = Object(e);
5672 } finally {
5673 if (profilerEnabled$2) {
5674 logOperationEnd(OperationId.constructor, vm);
5675 }
5676
5677 vmBeingConstructed = vmBeingConstructedInception;
5678
5679 if (!isUndefined$1(error)) {
5680 addErrorComponentStack(vm, error); // re-throwing the original error annotated after restoring the context
5681
5682 throw error; // eslint-disable-line no-unsafe-finally
5683 }
5684 }
5685}
5686function invokeComponentRenderMethod(vm) {
5687 const {
5688 def: {
5689 render
5690 },
5691 callHook,
5692 component,
5693 owner
5694 } = vm;
5695 const isRenderBeingInvokedInception = isInvokingRender;
5696 const vmBeingRenderedInception = getVMBeingRendered();
5697 let html;
5698 let renderInvocationSuccessful = false;
5699 runWithBoundaryProtection(vm, owner, () => {
5700 // pre
5701 isInvokingRender = true;
5702 setVMBeingRendered(vm);
5703 }, () => {
5704 // job
5705 vm.tro.observe(() => {
5706 html = callHook(component, render);
5707 renderInvocationSuccessful = true;
5708 });
5709 }, () => {
5710 // post
5711 isInvokingRender = isRenderBeingInvokedInception;
5712 setVMBeingRendered(vmBeingRenderedInception);
5713 }); // If render() invocation failed, process errorCallback in boundary and return an empty template
5714
5715 return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
5716}
5717function invokeComponentRenderedCallback(vm) {
5718 const {
5719 def: {
5720 renderedCallback
5721 },
5722 component,
5723 callHook,
5724 owner
5725 } = vm;
5726
5727 if (!isUndefined$1(renderedCallback)) {
5728 runWithBoundaryProtection(vm, owner, () => {
5729
5730 if (profilerEnabled$2) {
5731 logOperationStart(OperationId.renderedCallback, vm);
5732 }
5733 }, () => {
5734 // job
5735 callHook(component, renderedCallback);
5736 }, () => {
5737 // post
5738 if (profilerEnabled$2) {
5739 logOperationEnd(OperationId.renderedCallback, vm);
5740 }
5741 });
5742 }
5743}
5744function invokeEventListener(vm, fn, thisValue, event) {
5745 const {
5746 callHook,
5747 owner
5748 } = vm;
5749 runWithBoundaryProtection(vm, owner, noop$3, () => {
5750 // job
5751 if (process.env.NODE_ENV !== 'production') {
5752 assert.isTrue(isFunction$1(fn), `Invalid event handler for event '${event.type}' on ${vm}.`);
5753 }
5754
5755 callHook(thisValue, fn, [event]);
5756 }, noop$3);
5757}
5758
5759/*
5760 * Copyright (c) 2018, salesforce.com, inc.
5761 * All rights reserved.
5762 * SPDX-License-Identifier: MIT
5763 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5764 */
5765const signedTemplateMap = new Map();
5766/**
5767 * INTERNAL: This function can only be invoked by compiled code. The compiler
5768 * will prevent this function from being imported by userland code.
5769 */
5770
5771function registerComponent(Ctor, {
5772 tmpl
5773}) {
5774 signedTemplateMap.set(Ctor, tmpl); // chaining this method as a way to wrap existing assignment of component constructor easily,
5775 // without too much transformation
5776
5777 return Ctor;
5778}
5779function getComponentRegisteredTemplate(Ctor) {
5780 return signedTemplateMap.get(Ctor);
5781}
5782function createComponent(vm, Ctor) {
5783 // create the component instance
5784 invokeComponentConstructor(vm, Ctor);
5785
5786 if (isUndefined$1(vm.component)) {
5787 throw new ReferenceError(`Invalid construction for ${Ctor}, you must extend LightningElement.`);
5788 }
5789}
5790function getTemplateReactiveObserver(vm) {
5791 return new ReactiveObserver(() => {
5792 const {
5793 isDirty
5794 } = vm;
5795
5796 if (isFalse$1(isDirty)) {
5797 markComponentAsDirty(vm);
5798 scheduleRehydration(vm);
5799 }
5800 });
5801}
5802function renderComponent(vm) {
5803 if (process.env.NODE_ENV !== 'production') {
5804 assert.invariant(vm.isDirty, `${vm} is not dirty.`);
5805 }
5806
5807 vm.tro.reset();
5808 const vnodes = invokeComponentRenderMethod(vm);
5809 vm.isDirty = false;
5810 vm.isScheduled = false;
5811
5812 if (process.env.NODE_ENV !== 'production') {
5813 assert.invariant(isArray(vnodes), `${vm}.render() should always return an array of vnodes instead of ${vnodes}`);
5814 }
5815
5816 return vnodes;
5817}
5818function markComponentAsDirty(vm) {
5819 if (process.env.NODE_ENV !== 'production') {
5820 const vmBeingRendered = getVMBeingRendered();
5821 assert.isFalse(vm.isDirty, `markComponentAsDirty() for ${vm} should not be called when the component is already dirty.`);
5822 assert.isFalse(isInvokingRender, `markComponentAsDirty() for ${vm} cannot be called during rendering of ${vmBeingRendered}.`);
5823 assert.isFalse(isUpdatingTemplate, `markComponentAsDirty() for ${vm} cannot be called while updating template of ${vmBeingRendered}.`);
5824 }
5825
5826 vm.isDirty = true;
5827}
5828const cmpEventListenerMap = new WeakMap();
5829function getWrappedComponentsListener(vm, listener) {
5830 if (!isFunction$1(listener)) {
5831 throw new TypeError(); // avoiding problems with non-valid listeners
5832 }
5833
5834 let wrappedListener = cmpEventListenerMap.get(listener);
5835
5836 if (isUndefined$1(wrappedListener)) {
5837 wrappedListener = function (event) {
5838 invokeEventListener(vm, listener, undefined, event);
5839 };
5840
5841 cmpEventListenerMap.set(listener, wrappedListener);
5842 }
5843
5844 return wrappedListener;
5845}
5846
5847/*
5848 * Copyright (c) 2018, salesforce.com, inc.
5849 * All rights reserved.
5850 * SPDX-License-Identifier: MIT
5851 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5852 */
5853const Services = create$1(null);
5854const hooks = ['rendered', 'connected', 'disconnected'];
5855/**
5856 * EXPERIMENTAL: This function allows for the registration of "services"
5857 * in LWC by exposing hooks into the component life-cycle. This API is
5858 * subject to change or being removed.
5859 */
5860
5861function register(service) {
5862 if (process.env.NODE_ENV !== 'production') {
5863 assert.isTrue(isObject$1(service), `Invalid service declaration, ${service}: service must be an object`);
5864 }
5865
5866 for (let i = 0; i < hooks.length; ++i) {
5867 const hookName = hooks[i];
5868
5869 if (hookName in service) {
5870 let l = Services[hookName];
5871
5872 if (isUndefined$1(l)) {
5873 Services[hookName] = l = [];
5874 }
5875
5876 ArrayPush$1.call(l, service[hookName]);
5877 }
5878 }
5879}
5880function invokeServiceHook(vm, cbs) {
5881 if (process.env.NODE_ENV !== 'production') {
5882 assert.isTrue(isArray(cbs) && cbs.length > 0, `Optimize invokeServiceHook() to be invoked only when needed`);
5883 }
5884
5885 const {
5886 component,
5887 def,
5888 context
5889 } = vm;
5890
5891 for (let i = 0, len = cbs.length; i < len; ++i) {
5892 cbs[i].call(undefined, component, {}, def, context);
5893 }
5894}
5895
5896/*
5897 * Copyright (c) 2018, salesforce.com, inc.
5898 * All rights reserved.
5899 * SPDX-License-Identifier: MIT
5900 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5901 */
5902var VMState;
5903
5904(function (VMState) {
5905 VMState[VMState["created"] = 0] = "created";
5906 VMState[VMState["connected"] = 1] = "connected";
5907 VMState[VMState["disconnected"] = 2] = "disconnected";
5908})(VMState || (VMState = {}));
5909
5910let profilerEnabled$3 = false;
5911trackProfilerState(t => profilerEnabled$3 = t);
5912let idx = 0;
5913/** The internal slot used to associate different objects the engine manipulates with the VM */
5914
5915const ViewModelReflection = createHiddenField('ViewModel', 'engine');
5916
5917function callHook(cmp, fn, args = []) {
5918 return fn.apply(cmp, args);
5919}
5920
5921function setHook(cmp, prop, newValue) {
5922 cmp[prop] = newValue;
5923}
5924
5925function getHook(cmp, prop) {
5926 return cmp[prop];
5927}
5928
5929function rerenderVM(vm) {
5930 rehydrate(vm);
5931}
5932function connectRootElement(elm) {
5933 const vm = getAssociatedVM(elm);
5934 startGlobalMeasure(GlobalMeasurementPhase.HYDRATE, vm); // Usually means moving the element from one place to another, which is observable via
5935 // life-cycle hooks.
5936
5937 if (vm.state === VMState.connected) {
5938 disconnectRootElement(elm);
5939 }
5940
5941 runConnectedCallback(vm);
5942 rehydrate(vm);
5943 endGlobalMeasure(GlobalMeasurementPhase.HYDRATE, vm);
5944}
5945function disconnectRootElement(elm) {
5946 const vm = getAssociatedVM(elm);
5947 resetComponentStateWhenRemoved(vm);
5948}
5949function appendVM(vm) {
5950 rehydrate(vm);
5951} // just in case the component comes back, with this we guarantee re-rendering it
5952// while preventing any attempt to rehydration until after reinsertion.
5953
5954function resetComponentStateWhenRemoved(vm) {
5955 const {
5956 state
5957 } = vm;
5958
5959 if (state !== VMState.disconnected) {
5960 const {
5961 oar,
5962 tro
5963 } = vm; // Making sure that any observing record will not trigger the rehydrated on this vm
5964
5965 tro.reset(); // Making sure that any observing accessor record will not trigger the setter to be reinvoked
5966
5967 for (const key in oar) {
5968 oar[key].reset();
5969 }
5970
5971 runDisconnectedCallback(vm); // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5972
5973 runShadowChildNodesDisconnectedCallback(vm);
5974 runLightChildNodesDisconnectedCallback(vm);
5975 }
5976} // this method is triggered by the diffing algo only when a vnode from the
5977// old vnode.children is removed from the DOM.
5978
5979
5980function removeVM(vm) {
5981 if (process.env.NODE_ENV !== 'production') {
5982 assert.isTrue(vm.state === VMState.connected || vm.state === VMState.disconnected, `${vm} must have been connected.`);
5983 }
5984
5985 resetComponentStateWhenRemoved(vm);
5986}
5987function createVM(elm, def, options) {
5988 const {
5989 mode,
5990 owner,
5991 renderer,
5992 tagName
5993 } = options;
5994 const vm = {
5995 elm,
5996 def,
5997 idx: idx++,
5998 state: VMState.created,
5999 isScheduled: false,
6000 isDirty: true,
6001 tagName,
6002 mode,
6003 owner,
6004 renderer,
6005 children: EmptyArray,
6006 aChildren: EmptyArray,
6007 velements: EmptyArray,
6008 cmpProps: create$1(null),
6009 cmpFields: create$1(null),
6010 cmpSlots: create$1(null),
6011 oar: create$1(null),
6012 cmpTemplate: null,
6013 context: {
6014 hostAttribute: undefined,
6015 shadowAttribute: undefined,
6016 styleVNode: null,
6017 tplCache: EmptyObject,
6018 wiredConnecting: EmptyArray,
6019 wiredDisconnecting: EmptyArray
6020 },
6021 tro: null,
6022 component: null,
6023 cmpRoot: null,
6024 callHook,
6025 setHook,
6026 getHook
6027 };
6028 vm.tro = getTemplateReactiveObserver(vm);
6029
6030 if (process.env.NODE_ENV !== 'production') {
6031 vm.toString = () => {
6032 return `[object:vm ${def.name} (${vm.idx})]`;
6033 };
6034 } // Create component instance associated to the vm and the element.
6035
6036
6037 createComponent(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6038
6039 if (isFalse$1(renderer.ssr) && hasWireAdapters(vm)) {
6040 installWireAdapters(vm);
6041 }
6042
6043 return vm;
6044}
6045
6046function assertIsVM(obj) {
6047 if (isNull$1(obj) || !isObject$1(obj) || !('cmpRoot' in obj)) {
6048 throw new TypeError(`${obj} is not a VM.`);
6049 }
6050}
6051
6052function associateVM(obj, vm) {
6053 setHiddenField(obj, ViewModelReflection, vm);
6054}
6055function getAssociatedVM(obj) {
6056 const vm = getHiddenField(obj, ViewModelReflection);
6057
6058 if (process.env.NODE_ENV !== 'production') {
6059 assertIsVM(vm);
6060 }
6061
6062 return vm;
6063}
6064function getAssociatedVMIfPresent(obj) {
6065 const maybeVm = getHiddenField(obj, ViewModelReflection);
6066
6067 if (process.env.NODE_ENV !== 'production') {
6068 if (!isUndefined$1(maybeVm)) {
6069 assertIsVM(maybeVm);
6070 }
6071 }
6072
6073 return maybeVm;
6074}
6075
6076function rehydrate(vm) {
6077 if (isTrue$1(vm.isDirty)) {
6078 const children = renderComponent(vm);
6079 patchShadowRoot(vm, children);
6080 }
6081}
6082
6083function patchShadowRoot(vm, newCh) {
6084 const {
6085 cmpRoot,
6086 children: oldCh
6087 } = vm; // caching the new children collection
6088
6089 vm.children = newCh;
6090
6091 if (newCh.length > 0 || oldCh.length > 0) {
6092 // patch function mutates vnodes by adding the element reference,
6093 // however, if patching fails it contains partial changes.
6094 if (oldCh !== newCh) {
6095 const fn = hasDynamicChildren(newCh) ? updateDynamicChildren : updateStaticChildren;
6096 runWithBoundaryProtection(vm, vm, () => {
6097 // pre
6098 if (profilerEnabled$3) {
6099 logOperationStart(OperationId.patch, vm);
6100 }
6101 }, () => {
6102 // job
6103 fn(cmpRoot, oldCh, newCh);
6104 }, () => {
6105 // post
6106 if (profilerEnabled$3) {
6107 logOperationEnd(OperationId.patch, vm);
6108 }
6109 });
6110 }
6111 }
6112
6113 if (vm.state === VMState.connected) {
6114 // If the element is connected, that means connectedCallback was already issued, and
6115 // any successive rendering should finish with the call to renderedCallback, otherwise
6116 // the connectedCallback will take care of calling it in the right order at the end of
6117 // the current rehydration process.
6118 runRenderedCallback(vm);
6119 }
6120}
6121
6122function runRenderedCallback(vm) {
6123 if (isTrue$1(vm.renderer.ssr)) {
6124 return;
6125 }
6126
6127 const {
6128 rendered
6129 } = Services;
6130
6131 if (rendered) {
6132 invokeServiceHook(vm, rendered);
6133 }
6134
6135 invokeComponentRenderedCallback(vm);
6136}
6137
6138let rehydrateQueue = [];
6139
6140function flushRehydrationQueue() {
6141 startGlobalMeasure(GlobalMeasurementPhase.REHYDRATE);
6142
6143 if (process.env.NODE_ENV !== 'production') {
6144 assert.invariant(rehydrateQueue.length, `If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ${rehydrateQueue}.`);
6145 }
6146
6147 const vms = rehydrateQueue.sort((a, b) => a.idx - b.idx);
6148 rehydrateQueue = []; // reset to a new queue
6149
6150 for (let i = 0, len = vms.length; i < len; i += 1) {
6151 const vm = vms[i];
6152
6153 try {
6154 rehydrate(vm);
6155 } catch (error) {
6156 if (i + 1 < len) {
6157 // pieces of the queue are still pending to be rehydrated, those should have priority
6158 if (rehydrateQueue.length === 0) {
6159 addCallbackToNextTick(flushRehydrationQueue);
6160 }
6161
6162 ArrayUnshift$1.apply(rehydrateQueue, ArraySlice$1.call(vms, i + 1));
6163 } // we need to end the measure before throwing.
6164
6165
6166 endGlobalMeasure(GlobalMeasurementPhase.REHYDRATE); // re-throwing the original error will break the current tick, but since the next tick is
6167 // already scheduled, it should continue patching the rest.
6168
6169 throw error; // eslint-disable-line no-unsafe-finally
6170 }
6171 }
6172
6173 endGlobalMeasure(GlobalMeasurementPhase.REHYDRATE);
6174}
6175
6176function runConnectedCallback(vm) {
6177 const {
6178 state
6179 } = vm;
6180
6181 if (state === VMState.connected) {
6182 return; // nothing to do since it was already connected
6183 }
6184
6185 vm.state = VMState.connected; // reporting connection
6186
6187 const {
6188 connected
6189 } = Services;
6190
6191 if (connected) {
6192 invokeServiceHook(vm, connected);
6193 }
6194
6195 if (hasWireAdapters(vm)) {
6196 connectWireAdapters(vm);
6197 }
6198
6199 const {
6200 connectedCallback
6201 } = vm.def;
6202
6203 if (!isUndefined$1(connectedCallback)) {
6204 if (profilerEnabled$3) {
6205 logOperationStart(OperationId.connectedCallback, vm);
6206 }
6207
6208 invokeComponentCallback(vm, connectedCallback);
6209
6210 if (profilerEnabled$3) {
6211 logOperationEnd(OperationId.connectedCallback, vm);
6212 }
6213 }
6214}
6215
6216function hasWireAdapters(vm) {
6217 return getOwnPropertyNames$1(vm.def.wire).length > 0;
6218}
6219
6220function runDisconnectedCallback(vm) {
6221 if (process.env.NODE_ENV !== 'production') {
6222 assert.isTrue(vm.state !== VMState.disconnected, `${vm} must be inserted.`);
6223 }
6224
6225 if (isFalse$1(vm.isDirty)) {
6226 // this guarantees that if the component is reused/reinserted,
6227 // it will be re-rendered because we are disconnecting the reactivity
6228 // linking, so mutations are not automatically reflected on the state
6229 // of disconnected components.
6230 vm.isDirty = true;
6231 }
6232
6233 vm.state = VMState.disconnected; // reporting disconnection
6234
6235 const {
6236 disconnected
6237 } = Services;
6238
6239 if (disconnected) {
6240 invokeServiceHook(vm, disconnected);
6241 }
6242
6243 if (hasWireAdapters(vm)) {
6244 disconnectWireAdapters(vm);
6245 }
6246
6247 const {
6248 disconnectedCallback
6249 } = vm.def;
6250
6251 if (!isUndefined$1(disconnectedCallback)) {
6252 if (profilerEnabled$3) {
6253 logOperationStart(OperationId.disconnectedCallback, vm);
6254 }
6255
6256 invokeComponentCallback(vm, disconnectedCallback);
6257
6258 if (profilerEnabled$3) {
6259 logOperationEnd(OperationId.disconnectedCallback, vm);
6260 }
6261 }
6262}
6263
6264function runShadowChildNodesDisconnectedCallback(vm) {
6265 const {
6266 velements: vCustomElementCollection
6267 } = vm; // Reporting disconnection for every child in inverse order since they are
6268 // inserted in reserved order.
6269
6270 for (let i = vCustomElementCollection.length - 1; i >= 0; i -= 1) {
6271 const {
6272 elm
6273 } = vCustomElementCollection[i]; // There are two cases where the element could be undefined:
6274 // * when there is an error during the construction phase, and an error
6275 // boundary picks it, there is a possibility that the VCustomElement
6276 // is not properly initialized, and therefore is should be ignored.
6277 // * when slotted custom element is not used by the element where it is
6278 // slotted into it, as a result, the custom element was never
6279 // initialized.
6280
6281 if (!isUndefined$1(elm)) {
6282 const childVM = getAssociatedVMIfPresent(elm); // The VM associated with the element might be associated undefined
6283 // in the case where the VM failed in the middle of its creation,
6284 // eg: constructor throwing before invoking super().
6285
6286 if (!isUndefined$1(childVM)) {
6287 resetComponentStateWhenRemoved(childVM);
6288 }
6289 }
6290 }
6291}
6292
6293function runLightChildNodesDisconnectedCallback(vm) {
6294 const {
6295 aChildren: adoptedChildren
6296 } = vm;
6297 recursivelyDisconnectChildren(adoptedChildren);
6298}
6299/**
6300 * The recursion doesn't need to be a complete traversal of the vnode graph,
6301 * instead it can be partial, when a custom element vnode is found, we don't
6302 * need to continue into its children because by attempting to disconnect the
6303 * custom element itself will trigger the removal of anything slotted or anything
6304 * defined on its shadow.
6305 */
6306
6307
6308function recursivelyDisconnectChildren(vnodes) {
6309 for (let i = 0, len = vnodes.length; i < len; i += 1) {
6310 const vnode = vnodes[i];
6311
6312 if (!isNull$1(vnode) && isArray(vnode.children) && !isUndefined$1(vnode.elm)) {
6313 // vnode is a VElement with children
6314 if (isUndefined$1(vnode.ctor)) {
6315 // it is a VElement, just keep looking (recursively)
6316 recursivelyDisconnectChildren(vnode.children);
6317 } else {
6318 // it is a VCustomElement, disconnect it and ignore its children
6319 resetComponentStateWhenRemoved(getAssociatedVM(vnode.elm));
6320 }
6321 }
6322 }
6323} // This is a super optimized mechanism to remove the content of the shadowRoot without having to go
6324// into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
6325// children VNodes might not be representing the current state of the DOM.
6326
6327
6328function resetShadowRoot(vm) {
6329 const {
6330 children,
6331 cmpRoot,
6332 renderer
6333 } = vm;
6334
6335 for (let i = 0, len = children.length; i < len; i++) {
6336 const child = children[i];
6337
6338 if (!isNull$1(child) && !isUndefined$1(child.elm)) {
6339 renderer.remove(child.elm, cmpRoot);
6340 }
6341 }
6342
6343 vm.children = EmptyArray;
6344 runShadowChildNodesDisconnectedCallback(vm);
6345 vm.velements = EmptyArray;
6346}
6347function scheduleRehydration(vm) {
6348 if (isTrue$1(vm.renderer.ssr) || isTrue$1(vm.isScheduled)) {
6349 return;
6350 }
6351
6352 vm.isScheduled = true;
6353
6354 if (rehydrateQueue.length === 0) {
6355 addCallbackToNextTick(flushRehydrationQueue);
6356 }
6357
6358 ArrayPush$1.call(rehydrateQueue, vm);
6359}
6360
6361function getErrorBoundaryVM(vm) {
6362 let currentVm = vm;
6363
6364 while (!isNull$1(currentVm)) {
6365 if (!isUndefined$1(currentVm.def.errorCallback)) {
6366 return currentVm;
6367 }
6368
6369 currentVm = currentVm.owner;
6370 }
6371} // slow path routine
6372// NOTE: we should probably more this routine to the synthetic shadow folder
6373// and get the allocation to be cached by in the elm instead of in the VM
6374
6375
6376function allocateInSlot(vm, children) {
6377 if (process.env.NODE_ENV !== 'production') {
6378 assert.invariant(isObject$1(vm.cmpSlots), `When doing manual allocation, there must be a cmpSlots object available.`);
6379 }
6380
6381 const {
6382 cmpSlots: oldSlots
6383 } = vm;
6384 const cmpSlots = vm.cmpSlots = create$1(null);
6385
6386 for (let i = 0, len = children.length; i < len; i += 1) {
6387 const vnode = children[i];
6388
6389 if (isNull$1(vnode)) {
6390 continue;
6391 }
6392
6393 const {
6394 data
6395 } = vnode;
6396 const slotName = data.attrs && data.attrs.slot || '';
6397 const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
6398 // which might have similar keys. Each vnode will always have a key that
6399 // starts with a numeric character from compiler. In this case, we add a unique
6400 // notation for slotted vnodes keys, e.g.: `@foo:1:1`
6401
6402 if (!isUndefined$1(vnode.key)) {
6403 vnode.key = `@${slotName}:${vnode.key}`;
6404 }
6405
6406 ArrayPush$1.call(vnodes, vnode);
6407 }
6408
6409 if (isFalse$1(vm.isDirty)) {
6410 // We need to determine if the old allocation is really different from the new one
6411 // and mark the vm as dirty
6412 const oldKeys = keys$1(oldSlots);
6413
6414 if (oldKeys.length !== keys$1(cmpSlots).length) {
6415 markComponentAsDirty(vm);
6416 return;
6417 }
6418
6419 for (let i = 0, len = oldKeys.length; i < len; i += 1) {
6420 const key = oldKeys[i];
6421
6422 if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
6423 markComponentAsDirty(vm);
6424 return;
6425 }
6426
6427 const oldVNodes = oldSlots[key];
6428 const vnodes = cmpSlots[key];
6429
6430 for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
6431 if (oldVNodes[j] !== vnodes[j]) {
6432 markComponentAsDirty(vm);
6433 return;
6434 }
6435 }
6436 }
6437 }
6438}
6439function runWithBoundaryProtection(vm, owner, pre, job, post) {
6440 let error;
6441 pre();
6442
6443 try {
6444 job();
6445 } catch (e) {
6446 error = Object(e);
6447 } finally {
6448 post();
6449
6450 if (!isUndefined$1(error)) {
6451 addErrorComponentStack(vm, error);
6452 const errorBoundaryVm = isNull$1(owner) ? undefined : getErrorBoundaryVM(owner);
6453
6454 if (isUndefined$1(errorBoundaryVm)) {
6455 throw error; // eslint-disable-line no-unsafe-finally
6456 }
6457
6458 resetShadowRoot(vm); // remove offenders
6459
6460 if (profilerEnabled$3) {
6461 logOperationStart(OperationId.errorCallback, vm);
6462 } // error boundaries must have an ErrorCallback
6463
6464
6465 const errorCallback = errorBoundaryVm.def.errorCallback;
6466 invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
6467
6468 if (profilerEnabled$3) {
6469 logOperationEnd(OperationId.errorCallback, vm);
6470 }
6471 }
6472 }
6473}
6474
6475/*
6476 * Copyright (c) 2018, salesforce.com, inc.
6477 * All rights reserved.
6478 * SPDX-License-Identifier: MIT
6479 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6480 */
6481const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
6482const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
6483const WireMetaMap = new Map();
6484
6485function noop$4() {}
6486
6487class WireContextRegistrationEvent extends CustomEvent {
6488 constructor(adapterToken, {
6489 setNewContext,
6490 setDisconnectedCallback
6491 }) {
6492 super(adapterToken, {
6493 bubbles: true,
6494 composed: true
6495 });
6496 defineProperties$1(this, {
6497 setNewContext: {
6498 value: setNewContext
6499 },
6500 setDisconnectedCallback: {
6501 value: setDisconnectedCallback
6502 }
6503 });
6504 }
6505
6506}
6507
6508function createFieldDataCallback(vm, name) {
6509 const {
6510 cmpFields
6511 } = vm;
6512 return value => {
6513 if (value !== vm.cmpFields[name]) {
6514 // storing the value in the underlying storage
6515 cmpFields[name] = value;
6516 componentValueMutated(vm, name);
6517 }
6518 };
6519}
6520
6521function createMethodDataCallback(vm, method) {
6522 return value => {
6523 // dispatching new value into the wired method
6524 runWithBoundaryProtection(vm, vm.owner, noop$4, () => {
6525 // job
6526 method.call(vm.component, value);
6527 }, noop$4);
6528 };
6529}
6530
6531function createConfigWatcher(vm, wireDef, callbackWhenConfigIsReady) {
6532 const {
6533 component
6534 } = vm;
6535 const {
6536 configCallback
6537 } = wireDef;
6538 let hasPendingConfig = false; // creating the reactive observer for reactive params when needed
6539
6540 const ro = new ReactiveObserver(() => {
6541 if (hasPendingConfig === false) {
6542 hasPendingConfig = true; // collect new config in the micro-task
6543
6544 Promise.resolve().then(() => {
6545 hasPendingConfig = false; // resetting current reactive params
6546
6547 ro.reset(); // dispatching a new config due to a change in the configuration
6548
6549 callback();
6550 });
6551 }
6552 });
6553
6554 const callback = () => {
6555 let config;
6556 ro.observe(() => config = configCallback(component)); // eslint-disable-next-line lwc-internal/no-invalid-todo
6557 // TODO: dev-mode validation of config based on the adapter.configSchema
6558 // @ts-ignore it is assigned in the observe() callback
6559
6560 callbackWhenConfigIsReady(config);
6561 };
6562
6563 return callback;
6564}
6565
6566function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
6567 const {
6568 adapter
6569 } = wireDef;
6570 const adapterContextToken = getAdapterToken(adapter);
6571
6572 if (isUndefined$1(adapterContextToken)) {
6573 return; // no provider found, nothing to be done
6574 }
6575
6576 const {
6577 elm,
6578 renderer,
6579 context: {
6580 wiredConnecting,
6581 wiredDisconnecting
6582 }
6583 } = vm; // waiting for the component to be connected to formally request the context via the token
6584
6585 ArrayPush$1.call(wiredConnecting, () => {
6586 // This event is responsible for connecting the host element with another
6587 // element in the composed path that is providing contextual data. The provider
6588 // must be listening for a special dom event with the name corresponding to the value of
6589 // `adapterContextToken`, which will remain secret and internal to this file only to
6590 // guarantee that the linkage can be forged.
6591 const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
6592 setNewContext(newContext) {
6593 // eslint-disable-next-line lwc-internal/no-invalid-todo
6594 // TODO: dev-mode validation of config based on the adapter.contextSchema
6595 callbackWhenContextIsReady(newContext);
6596 },
6597
6598 setDisconnectedCallback(disconnectCallback) {
6599 // adds this callback into the disconnect bucket so it gets disconnected from parent
6600 // the the element hosting the wire is disconnected
6601 ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
6602 }
6603
6604 });
6605 renderer.dispatchEvent(elm, contextRegistrationEvent);
6606 });
6607}
6608
6609function createConnector(vm, name, wireDef) {
6610 const {
6611 method,
6612 adapter,
6613 configCallback,
6614 dynamic
6615 } = wireDef;
6616 const hasDynamicParams = dynamic.length > 0;
6617 const {
6618 component
6619 } = vm;
6620 const dataCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
6621 let context;
6622 let connector; // Workaround to pass the component element associated to this wire adapter instance.
6623
6624 defineProperty$1(dataCallback, DeprecatedWiredElementHost, {
6625 value: vm.elm
6626 });
6627 defineProperty$1(dataCallback, DeprecatedWiredParamsMeta, {
6628 value: dynamic
6629 });
6630 runWithBoundaryProtection(vm, vm, noop$4, () => {
6631 // job
6632 connector = new adapter(dataCallback);
6633 }, noop$4);
6634
6635 const updateConnectorConfig = config => {
6636 // every time the config is recomputed due to tracking,
6637 // this callback will be invoked with the new computed config
6638 runWithBoundaryProtection(vm, vm, noop$4, () => {
6639 // job
6640 connector.update(config, context);
6641 }, noop$4);
6642 }; // Computes the current wire config and calls the update method on the wire adapter.
6643 // This initial implementation may change depending on the specific wire instance, if it has params, we will need
6644 // to observe changes in the next tick.
6645
6646
6647 let computeConfigAndUpdate = () => {
6648 updateConnectorConfig(configCallback(component));
6649 };
6650
6651 if (hasDynamicParams) {
6652 // This wire has dynamic parameters: we wait for the component instance is created and its values set
6653 // in order to call the update(config) method.
6654 Promise.resolve().then(() => {
6655 computeConfigAndUpdate = createConfigWatcher(vm, wireDef, updateConnectorConfig);
6656 computeConfigAndUpdate();
6657 });
6658 } else {
6659 computeConfigAndUpdate();
6660 } // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
6661
6662
6663 if (!isUndefined$1(adapter.contextSchema)) {
6664 createContextWatcher(vm, wireDef, newContext => {
6665 // every time the context is pushed into this component,
6666 // this callback will be invoked with the new computed context
6667 if (context !== newContext) {
6668 context = newContext; // Note: when new context arrives, the config will be recomputed and pushed along side the new
6669 // context, this is to preserve the identity characteristics, config should not have identity
6670 // (ever), while context can have identity
6671
6672 computeConfigAndUpdate();
6673 }
6674 });
6675 } // @ts-ignore the boundary protection executes sync, connector is always defined
6676
6677
6678 return connector;
6679}
6680
6681const AdapterToTokenMap = new Map();
6682function getAdapterToken(adapter) {
6683 return AdapterToTokenMap.get(adapter);
6684}
6685function setAdapterToken(adapter, token) {
6686 AdapterToTokenMap.set(adapter, token);
6687}
6688function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
6689 // support for callable adapters
6690 if (adapter.adapter) {
6691 adapter = adapter.adapter;
6692 }
6693
6694 const method = descriptor.value;
6695 const def = {
6696 adapter,
6697 method,
6698 configCallback,
6699 dynamic
6700 };
6701 WireMetaMap.set(descriptor, def);
6702}
6703function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
6704 // support for callable adapters
6705 if (adapter.adapter) {
6706 adapter = adapter.adapter;
6707 }
6708
6709 const def = {
6710 adapter,
6711 configCallback,
6712 dynamic
6713 };
6714 WireMetaMap.set(descriptor, def);
6715}
6716function installWireAdapters(vm) {
6717 const {
6718 context,
6719 def: {
6720 wire
6721 }
6722 } = vm;
6723 const wiredConnecting = context.wiredConnecting = [];
6724 const wiredDisconnecting = context.wiredDisconnecting = [];
6725
6726 for (const fieldNameOrMethod in wire) {
6727 const descriptor = wire[fieldNameOrMethod];
6728 const wireDef = WireMetaMap.get(descriptor);
6729
6730 if (process.env.NODE_ENV !== 'production') {
6731 assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
6732 }
6733
6734 if (!isUndefined$1(wireDef)) {
6735 const adapterInstance = createConnector(vm, fieldNameOrMethod, wireDef);
6736 ArrayPush$1.call(wiredConnecting, () => adapterInstance.connect());
6737 ArrayPush$1.call(wiredDisconnecting, () => adapterInstance.disconnect());
6738 }
6739 }
6740}
6741function connectWireAdapters(vm) {
6742 const {
6743 wiredConnecting
6744 } = vm.context;
6745
6746 for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
6747 wiredConnecting[i]();
6748 }
6749}
6750function disconnectWireAdapters(vm) {
6751 const {
6752 wiredDisconnecting
6753 } = vm.context;
6754 runWithBoundaryProtection(vm, vm, noop$4, () => {
6755 // job
6756 for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
6757 wiredDisconnecting[i]();
6758 }
6759 }, noop$4);
6760}
6761
6762/*
6763 * Copyright (c) 2018, salesforce.com, inc.
6764 * All rights reserved.
6765 * SPDX-License-Identifier: MIT
6766 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6767 */
6768
6769function createContextProvider(adapter) {
6770 let adapterContextToken = getAdapterToken(adapter);
6771
6772 if (!isUndefined$1(adapterContextToken)) {
6773 throw new Error(`Adapter already has a context provider.`);
6774 }
6775
6776 adapterContextToken = guid();
6777 setAdapterToken(adapter, adapterContextToken);
6778 const providers = new WeakSet();
6779 return (elm, options) => {
6780 if (providers.has(elm)) {
6781 throw new Error(`Adapter was already installed on ${elm}.`);
6782 }
6783
6784 providers.add(elm);
6785 const {
6786 consumerConnectedCallback,
6787 consumerDisconnectedCallback
6788 } = options;
6789 elm.addEventListener(adapterContextToken, evt => {
6790 const {
6791 setNewContext,
6792 setDisconnectedCallback
6793 } = evt;
6794 const consumer = {
6795 provide(newContext) {
6796 setNewContext(newContext);
6797 }
6798
6799 };
6800
6801 const disconnectCallback = () => {
6802 if (!isUndefined$1(consumerDisconnectedCallback)) {
6803 consumerDisconnectedCallback(consumer);
6804 }
6805 };
6806
6807 setDisconnectedCallback(disconnectCallback);
6808 consumerConnectedCallback(consumer);
6809 evt.stopImmediatePropagation();
6810 });
6811 };
6812}
6813
6814/*
6815 * Copyright (c) 2018, salesforce.com, inc.
6816 * All rights reserved.
6817 * SPDX-License-Identifier: MIT
6818 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6819 */
6820/**
6821 * EXPERIMENTAL: This function allows you to create a reactive readonly
6822 * membrane around any object value. This API is subject to change or
6823 * being removed.
6824 */
6825
6826function readonly(obj) {
6827 if (process.env.NODE_ENV !== 'production') {
6828 // TODO [#1292]: Remove the readonly decorator
6829 if (arguments.length !== 1) {
6830 assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6831 }
6832 }
6833
6834 return reactiveMembrane.getReadOnlyProxy(obj);
6835}
6836/* version: 1.7.12 */
6837
6838/*
6839 * Copyright (c) 2020, salesforce.com, inc.
6840 * All rights reserved.
6841 * SPDX-License-Identifier: MIT
6842 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6843 */
6844var HostNodeType;
6845(function (HostNodeType) {
6846 HostNodeType["Text"] = "text";
6847 HostNodeType["Element"] = "element";
6848 HostNodeType["ShadowRoot"] = "shadow-root";
6849})(HostNodeType || (HostNodeType = {}));
6850
6851/*
6852 * Copyright (c) 2020, salesforce.com, inc.
6853 * All rights reserved.
6854 * SPDX-License-Identifier: MIT
6855 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6856 */
6857const CLASSNAMES_SEPARATOR = /\s+/g;
6858function classNameToTokenList(value) {
6859 return new Set(value.trim().split(CLASSNAMES_SEPARATOR));
6860}
6861function tokenListToClassName(values) {
6862 return Array.from(values).join(' ');
6863}
6864
6865/*
6866 * Copyright (c) 2020, salesforce.com, inc.
6867 * All rights reserved.
6868 * SPDX-License-Identifier: MIT
6869 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6870 */
6871const DASH_CHAR_CODE = 45; // "-"
6872const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
6873const PROPERTY_DELIMITER = /:(.+)/;
6874// Implementation of the CSS property to IDL attribute algorithm.
6875// https://drafts.csswg.org/cssom/#idl-attribute-to-css-property
6876function cssPropertyToIdlAttribute(property) {
6877 let output = '';
6878 let uppercaseNext = false;
6879 for (let i = 0; i < property.length; i++) {
6880 if (property.charCodeAt(i) === DASH_CHAR_CODE) {
6881 uppercaseNext = true;
6882 }
6883 else if (uppercaseNext) {
6884 uppercaseNext = false;
6885 output += property[i].toUpperCase();
6886 }
6887 else {
6888 output += property[i];
6889 }
6890 }
6891 return output;
6892}
6893function idlAttributeToCssProperty(attribute) {
6894 let output = '';
6895 for (let i = 0; i < attribute.length; i++) {
6896 const char = attribute.charAt(i);
6897 const lowerCasedChar = char.toLowerCase();
6898 if (char !== lowerCasedChar) {
6899 output += `-${lowerCasedChar}`;
6900 }
6901 else {
6902 output += `${char}`;
6903 }
6904 }
6905 return output;
6906}
6907// Borrowed from Vue template compiler.
6908// https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
6909function styleTextToCssDeclaration(cssText) {
6910 const styleDeclaration = {};
6911 const declarations = cssText.split(DECLARATION_DELIMITER);
6912 for (const declaration of declarations) {
6913 if (declaration) {
6914 const [prop, value] = declaration.split(PROPERTY_DELIMITER);
6915 if (prop !== undefined && value !== undefined) {
6916 const camelCasedAttribute = cssPropertyToIdlAttribute(prop.trim());
6917 styleDeclaration[camelCasedAttribute] = value.trim();
6918 }
6919 }
6920 }
6921 return styleDeclaration;
6922}
6923function cssDeclarationToStyleText(styleDeclaration) {
6924 return Object.entries(styleDeclaration)
6925 .map(([prop, value]) => {
6926 return `${idlAttributeToCssProperty(prop)}: ${value};`;
6927 })
6928 .join(' ');
6929}
6930
6931/*
6932 * Copyright (c) 2020, salesforce.com, inc.
6933 * All rights reserved.
6934 * SPDX-License-Identifier: MIT
6935 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6936 */
6937function unsupportedMethod(name) {
6938 return function () {
6939 throw new TypeError(`"${name}" is not supported in this environment`);
6940 };
6941}
6942function createElement(name, namespace) {
6943 return {
6944 type: HostNodeType.Element,
6945 name,
6946 namespace,
6947 parent: null,
6948 shadowRoot: null,
6949 children: [],
6950 attributes: [],
6951 eventListeners: {},
6952 };
6953}
6954const renderer = {
6955 ssr: true,
6956 syntheticShadow: false,
6957 insert(node, parent, anchor) {
6958 if (node.parent !== null && node.parent !== parent) {
6959 const nodeIndex = node.parent.children.indexOf(node);
6960 node.parent.children.splice(nodeIndex, 1);
6961 }
6962 node.parent = parent;
6963 const anchorIndex = isNull(anchor) ? -1 : parent.children.indexOf(anchor);
6964 if (anchorIndex === -1) {
6965 parent.children.push(node);
6966 }
6967 else {
6968 parent.children.splice(anchorIndex, 0, node);
6969 }
6970 },
6971 remove(node, parent) {
6972 const nodeIndex = parent.children.indexOf(node);
6973 parent.children.splice(nodeIndex, 1);
6974 },
6975 createElement,
6976 createText(content) {
6977 return {
6978 type: HostNodeType.Text,
6979 value: String(content),
6980 parent: null,
6981 };
6982 },
6983 nextSibling(node) {
6984 const { parent } = node;
6985 if (isNull(parent)) {
6986 return null;
6987 }
6988 const nodeIndex = parent.children.indexOf(node);
6989 return parent.children[nodeIndex + 1] || null;
6990 },
6991 attachShadow(element, config) {
6992 element.shadowRoot = {
6993 type: HostNodeType.ShadowRoot,
6994 children: [],
6995 mode: config.mode,
6996 delegatesFocus: !!config.delegatesFocus,
6997 };
6998 return element.shadowRoot;
6999 },
7000 getProperty(node, key) {
7001 var _a, _b;
7002 if (key in node) {
7003 return node[key];
7004 }
7005 if (node.type === HostNodeType.Element) {
7006 const attrName = getAttrNameFromPropName(key);
7007 // Handle all the boolean properties.
7008 if (isBooleanAttribute(attrName, node.name)) {
7009 return (_a = this.getAttribute(node, attrName)) !== null && _a !== void 0 ? _a : false;
7010 }
7011 // Handle global html attributes and AOM.
7012 if (isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) {
7013 return this.getAttribute(node, attrName);
7014 }
7015 // Handle special elements live bindings. The checked property is already handled above
7016 // in the boolean case.
7017 if (node.name === 'input' && key === 'value') {
7018 return (_b = this.getAttribute(node, 'value')) !== null && _b !== void 0 ? _b : '';
7019 }
7020 }
7021 if (process.env.NODE_ENV !== 'production') {
7022 // eslint-disable-next-line no-console
7023 console.error(`Unexpected "${key}" property access from the renderer`);
7024 }
7025 },
7026 setProperty(node, key, value) {
7027 if (key in node) {
7028 return (node[key] = value);
7029 }
7030 if (node.type === HostNodeType.Element) {
7031 const attrName = getAttrNameFromPropName(key);
7032 // Handle all the boolean properties.
7033 if (isBooleanAttribute(attrName, node.name)) {
7034 return value === true
7035 ? this.setAttribute(node, attrName, '')
7036 : this.removeAttribute(node, attrName);
7037 }
7038 // Handle global html attributes and AOM.
7039 if (isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) {
7040 return this.setAttribute(node, attrName, value);
7041 }
7042 // Handle special elements live bindings. The checked property is already handled above
7043 // in the boolean case.
7044 if (node.name === 'input' && attrName === 'value') {
7045 return isNull(value) || isUndefined(value)
7046 ? this.removeAttribute(node, 'value')
7047 : this.setAttribute(node, 'value', value);
7048 }
7049 }
7050 if (process.env.NODE_ENV !== 'production') {
7051 // eslint-disable-next-line no-console
7052 console.error(`Unexpected attempt to set "${key}=${value}" property from the renderer`);
7053 }
7054 },
7055 setText(node, content) {
7056 if (node.type === HostNodeType.Text) {
7057 node.value = content;
7058 }
7059 else if (node.type === HostNodeType.Element) {
7060 node.children = [
7061 {
7062 type: HostNodeType.Text,
7063 parent: node,
7064 value: content,
7065 },
7066 ];
7067 }
7068 },
7069 getAttribute(element, name, namespace = null) {
7070 const attribute = element.attributes.find((attr) => attr.name === name && attr.namespace === namespace);
7071 return attribute ? attribute.value : null;
7072 },
7073 setAttribute(element, name, value, namespace = null) {
7074 const attribute = element.attributes.find((attr) => attr.name === name && attr.namespace === namespace);
7075 if (isUndefined(attribute)) {
7076 element.attributes.push({
7077 name,
7078 namespace,
7079 value: String(value),
7080 });
7081 }
7082 else {
7083 attribute.value = value;
7084 }
7085 },
7086 removeAttribute(element, name, namespace) {
7087 element.attributes = element.attributes.filter((attr) => attr.name !== name && attr.namespace !== namespace);
7088 },
7089 getClassList(element) {
7090 function getClassAttribute() {
7091 let classAttribute = element.attributes.find((attr) => attr.name === 'class' && isNull(attr.namespace));
7092 if (isUndefined(classAttribute)) {
7093 classAttribute = {
7094 name: 'class',
7095 namespace: null,
7096 value: '',
7097 };
7098 element.attributes.push(classAttribute);
7099 }
7100 return classAttribute;
7101 }
7102 return {
7103 add(...names) {
7104 const classAttribute = getClassAttribute();
7105 const tokenList = classNameToTokenList(classAttribute.value);
7106 names.forEach((name) => tokenList.add(name));
7107 classAttribute.value = tokenListToClassName(tokenList);
7108 },
7109 remove(...names) {
7110 const classAttribute = getClassAttribute();
7111 const tokenList = classNameToTokenList(classAttribute.value);
7112 names.forEach((name) => tokenList.delete(name));
7113 classAttribute.value = tokenListToClassName(tokenList);
7114 },
7115 };
7116 },
7117 getStyleDeclaration(element) {
7118 function getStyleAttribute() {
7119 return element.attributes.find((attr) => attr.name === 'style' && isNull(attr.namespace));
7120 }
7121 return new Proxy({}, {
7122 get(target, property) {
7123 let value;
7124 const styleAttribute = getStyleAttribute();
7125 if (isUndefined(styleAttribute)) {
7126 return '';
7127 }
7128 if (property === 'cssText') {
7129 value = styleAttribute.value;
7130 }
7131 else {
7132 const cssDeclaration = styleTextToCssDeclaration(styleAttribute.value);
7133 value = cssDeclaration[property] || '';
7134 }
7135 return value;
7136 },
7137 set(target, property, value) {
7138 let styleAttribute = getStyleAttribute();
7139 if (isUndefined(styleAttribute)) {
7140 styleAttribute = {
7141 name: 'style',
7142 namespace: null,
7143 value: '',
7144 };
7145 element.attributes.push(styleAttribute);
7146 }
7147 if (property === 'cssText') {
7148 styleAttribute.value = value;
7149 }
7150 else {
7151 const cssDeclaration = styleTextToCssDeclaration(styleAttribute.value);
7152 cssDeclaration[property] = value;
7153 styleAttribute.value = cssDeclarationToStyleText(cssDeclaration);
7154 }
7155 return value;
7156 },
7157 });
7158 },
7159 isConnected(node) {
7160 return !isNull(node.parent);
7161 },
7162 insertGlobalStylesheet() {
7163 // Noop on SSR (for now). This need to be reevaluated whenever we will implement support for
7164 // synthetic shadow.
7165 },
7166 addEventListener() {
7167 // Noop on SSR.
7168 },
7169 removeEventListener() {
7170 // Noop on SSR.
7171 },
7172 dispatchEvent: unsupportedMethod('dispatchEvent'),
7173 getBoundingClientRect: unsupportedMethod('getBoundingClientRect'),
7174 querySelector: unsupportedMethod('querySelector'),
7175 querySelectorAll: unsupportedMethod('querySelectorAll'),
7176 getElementsByTagName: unsupportedMethod('getElementsByTagName'),
7177 getElementsByClassName: unsupportedMethod('getElementsByClassName'),
7178};
7179
7180/*
7181 * Copyright (c) 2020, salesforce.com, inc.
7182 * All rights reserved.
7183 * SPDX-License-Identifier: MIT
7184 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7185 */
7186const ESCAPED_CHARS = {
7187 '"': '&quot;',
7188 "'": '&#x27;',
7189 '<': '&lt;',
7190 '>': '&gt;',
7191 '&': '&amp;',
7192};
7193function htmlEscape(str) {
7194 return str.replace(/["'<>&]/g, (char) => ESCAPED_CHARS[char]);
7195}
7196
7197/*
7198 * Copyright (c) 2020, salesforce.com, inc.
7199 * All rights reserved.
7200 * SPDX-License-Identifier: MIT
7201 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7202 */
7203function serializeAttributes(attributes) {
7204 return attributes
7205 .map((attr) => attr.value.length ? `${attr.name}=${JSON.stringify(htmlEscape(attr.value))}` : attr.name)
7206 .join(' ');
7207}
7208function serializeChildNodes(children) {
7209 return children
7210 .map((child) => {
7211 switch (child.type) {
7212 case HostNodeType.Text:
7213 return htmlEscape(child.value);
7214 case HostNodeType.Element:
7215 return serializeElement(child);
7216 }
7217 })
7218 .join('');
7219}
7220function serializeShadowRoot(shadowRoot) {
7221 const attrs = [`shadowroot="${shadowRoot.mode}"`];
7222 if (shadowRoot.delegatesFocus) {
7223 attrs.push('shadowrootdelegatesfocus');
7224 }
7225 return `<template ${attrs.join(' ')}>${serializeChildNodes(shadowRoot.children)}</template>`;
7226}
7227function serializeElement(element) {
7228 let output = '';
7229 const { name } = element;
7230 const attrs = element.attributes.length ? ` ${serializeAttributes(element.attributes)}` : '';
7231 const children = serializeChildNodes(element.children);
7232 output += `<${name}${attrs}>`;
7233 if (element.shadowRoot) {
7234 output += serializeShadowRoot(element.shadowRoot);
7235 }
7236 output += children;
7237 if (!isVoidElement(name)) {
7238 output += `</${name}>`;
7239 }
7240 return output;
7241}
7242
7243/*
7244 * Copyright (c) 2018, salesforce.com, inc.
7245 * All rights reserved.
7246 * SPDX-License-Identifier: MIT
7247 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7248 */
7249const FakeRootElement = {
7250 type: HostNodeType.Element,
7251 name: 'fake-root-element',
7252 namespace: 'ssr',
7253 parent: null,
7254 shadowRoot: null,
7255 children: [],
7256 attributes: [],
7257 eventListeners: {},
7258};
7259function renderComponent$1(tagName, Ctor, props = {}) {
7260 if (!isString(tagName)) {
7261 throw new TypeError(`"renderComponent" expects a string as the first parameter but instead received ${tagName}.`);
7262 }
7263 if (!isFunction(Ctor)) {
7264 throw new TypeError(`"renderComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
7265 }
7266 if (!isObject(props) || isNull(props)) {
7267 throw new TypeError(`"renderComponent" expects an object as the third parameter but instead received ${props}.`);
7268 }
7269 const element = renderer.createElement(tagName);
7270 const def = getComponentInternalDef(Ctor);
7271 setElementProto(element, def);
7272 createVM(element, def, {
7273 mode: 'open',
7274 owner: null,
7275 renderer,
7276 tagName,
7277 });
7278 for (const [key, value] of Object.entries(props)) {
7279 element[key] = value;
7280 }
7281 element.parent = FakeRootElement;
7282 connectRootElement(element);
7283 return serializeElement(element);
7284}
7285
7286/*
7287 * Copyright (c) 2018, salesforce.com, inc.
7288 * All rights reserved.
7289 * SPDX-License-Identifier: MIT
7290 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7291 */
7292freeze(BaseLightningElement);
7293seal(BaseLightningElement.prototype);
7294
7295export { BaseLightningElement as LightningElement, api, createContextProvider, getComponentDef, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent$1 as renderComponent, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, track, unwrap$1 as unwrap, wire };
7296/* version: 1.7.12 */