UNPKG

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