UNPKG

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