UNPKG

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