UNPKG

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