UNPKG

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