UNPKG

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