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