UNPKG

8.75 kBJavaScriptView Raw
1/**
2 * Copyright (C) 2018 salesforce.com, inc.
3 */
4'use strict';
5
6Object.defineProperty(exports, '__esModule', { value: true });
7
8/**
9 * Copyright (C) 2018 salesforce.com, inc.
10 */
11
12/*
13 * Copyright (c) 2018, salesforce.com, inc.
14 * All rights reserved.
15 * SPDX-License-Identifier: MIT
16 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
17 */
18const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
19const { 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;
20const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
21function isUndefined(obj) {
22 return obj === undefined;
23}
24function isTrue$1(obj) {
25 return obj === true;
26}
27function isFalse$1(obj) {
28 return obj === false;
29}
30
31/*
32 * Copyright (c) 2018, salesforce.com, inc.
33 * All rights reserved.
34 * SPDX-License-Identifier: MIT
35 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
36 */
37/**
38 * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and
39 * ariaGrabbed) are deprecated:
40 * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes
41 *
42 * The above list of 46 aria attributes is consistent with the following resources:
43 * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060
44 * https://wicg.github.io/aom/spec/aria-reflection.html
45 */
46const AriaPropertyNames = [
47 'ariaActiveDescendant',
48 'ariaAtomic',
49 'ariaAutoComplete',
50 'ariaBusy',
51 'ariaChecked',
52 'ariaColCount',
53 'ariaColIndex',
54 'ariaColSpan',
55 'ariaControls',
56 'ariaCurrent',
57 'ariaDescribedBy',
58 'ariaDetails',
59 'ariaDisabled',
60 'ariaErrorMessage',
61 'ariaExpanded',
62 'ariaFlowTo',
63 'ariaHasPopup',
64 'ariaHidden',
65 'ariaInvalid',
66 'ariaKeyShortcuts',
67 'ariaLabel',
68 'ariaLabelledBy',
69 'ariaLevel',
70 'ariaLive',
71 'ariaModal',
72 'ariaMultiLine',
73 'ariaMultiSelectable',
74 'ariaOrientation',
75 'ariaOwns',
76 'ariaPlaceholder',
77 'ariaPosInSet',
78 'ariaPressed',
79 'ariaReadOnly',
80 'ariaRelevant',
81 'ariaRequired',
82 'ariaRoleDescription',
83 'ariaRowCount',
84 'ariaRowIndex',
85 'ariaRowSpan',
86 'ariaSelected',
87 'ariaSetSize',
88 'ariaSort',
89 'ariaValueMax',
90 'ariaValueMin',
91 'ariaValueNow',
92 'ariaValueText',
93 'role',
94];
95const AttrNameToPropNameMap = create(null);
96const PropNameToAttrNameMap = create(null);
97// Synthetic creation of all AOM property descriptors for Custom Elements
98forEach.call(AriaPropertyNames, (propName) => {
99 // Typescript infers the wrong function type for this particular overloaded method:
100 // https://github.com/Microsoft/TypeScript/issues/27972
101 // @ts-ignore type-mismatch
102 const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, 'aria-'));
103 AttrNameToPropNameMap[attrName] = propName;
104 PropNameToAttrNameMap[propName] = attrName;
105});
106
107/*
108 * Copyright (c) 2018, salesforce.com, inc.
109 * All rights reserved.
110 * SPDX-License-Identifier: MIT
111 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
112 */
113// Inspired from: https://mathiasbynens.be/notes/globalthis
114const _globalThis = (function () {
115 // On recent browsers, `globalThis` is already defined. In this case return it directly.
116 if (typeof globalThis === 'object') {
117 return globalThis;
118 }
119 let _globalThis;
120 try {
121 // eslint-disable-next-line no-extend-native
122 Object.defineProperty(Object.prototype, '__magic__', {
123 get: function () {
124 return this;
125 },
126 configurable: true,
127 });
128 // __magic__ is undefined in Safari 10 and IE10 and older.
129 // @ts-ignore
130 // eslint-disable-next-line no-undef
131 _globalThis = __magic__;
132 // @ts-ignore
133 delete Object.prototype.__magic__;
134 }
135 catch (ex) {
136 // In IE8, Object.defineProperty only works on DOM objects.
137 }
138 finally {
139 // If the magic above fails for some reason we assume that we are in a legacy browser.
140 // Assume `window` exists in this case.
141 if (typeof _globalThis === 'undefined') {
142 // @ts-ignore
143 _globalThis = window;
144 }
145 }
146 return _globalThis;
147})();
148
149/*
150 * Copyright (c) 2018, salesforce.com, inc.
151 * All rights reserved.
152 * SPDX-License-Identifier: MIT
153 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
154 */
155/*
156 * In IE11, symbols are expensive.
157 * Due to the nature of the symbol polyfill. This method abstract the
158 * creation of symbols, so we can fallback to string when native symbols
159 * are not supported. Note that we can't use typeof since it will fail when transpiling.
160 */
161const hasNativeSymbolsSupport = Symbol('x').toString() === 'Symbol(x)';
162const HTML_ATTRIBUTES_TO_PROPERTY = {
163 accesskey: 'accessKey',
164 readonly: 'readOnly',
165 tabindex: 'tabIndex',
166 bgcolor: 'bgColor',
167 colspan: 'colSpan',
168 rowspan: 'rowSpan',
169 contenteditable: 'contentEditable',
170 crossorigin: 'crossOrigin',
171 datetime: 'dateTime',
172 formaction: 'formAction',
173 ismap: 'isMap',
174 maxlength: 'maxLength',
175 minlength: 'minLength',
176 novalidate: 'noValidate',
177 usemap: 'useMap',
178 for: 'htmlFor',
179};
180keys(HTML_ATTRIBUTES_TO_PROPERTY).forEach((attrName) => {
181});
182/** version: 1.8.1 */
183
184/*
185 * Copyright (c) 2018, salesforce.com, inc.
186 * All rights reserved.
187 * SPDX-License-Identifier: MIT
188 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
189 */
190if (!_globalThis.lwcRuntimeFlags) {
191 Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
192}
193const runtimeFlags = _globalThis.lwcRuntimeFlags;
194// This function is not supported for use within components and is meant for
195// configuring runtime feature flags during app initialization.
196function setFeatureFlag(name, value) {
197 const isBoolean = isTrue$1(value) || isFalse$1(value);
198 if (!isBoolean) {
199 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.`;
200 if (process.env.NODE_ENV !== 'production') {
201 throw new TypeError(message);
202 }
203 else {
204 // eslint-disable-next-line no-console
205 console.error(message);
206 return;
207 }
208 }
209 if (isUndefined(featureFlagLookup[name])) {
210 // eslint-disable-next-line no-console
211 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.`);
212 return;
213 }
214 if (process.env.NODE_ENV !== 'production') {
215 // Allow the same flag to be set more than once outside of production to enable testing
216 runtimeFlags[name] = value;
217 }
218 else {
219 // Disallow the same flag to be set more than once in production
220 const runtimeValue = runtimeFlags[name];
221 if (!isUndefined(runtimeValue)) {
222 // eslint-disable-next-line no-console
223 console.error(`Failed to set the value "${value}" for the runtime feature flag "${name}". "${name}" has already been set with the value "${runtimeValue}".`);
224 return;
225 }
226 Object.defineProperty(runtimeFlags, name, { value });
227 }
228}
229// This function is exposed to components to facilitate testing so we add a
230// check to make sure it is not invoked in production.
231function setFeatureFlagForTest(name, value) {
232 if (process.env.NODE_ENV !== 'production') {
233 return setFeatureFlag(name, value);
234 }
235}
236
237const featureFlagLookup = {
238 ENABLE_REACTIVE_SETTER: null,
239 // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
240 ENABLE_ELEMENT_PATCH: null,
241 ENABLE_NODE_LIST_PATCH: null,
242 ENABLE_HTML_COLLECTIONS_PATCH: null,
243 ENABLE_NODE_PATCH: null,
244};
245
246exports.default = featureFlagLookup;
247exports.runtimeFlags = runtimeFlags;
248exports.setFeatureFlag = setFeatureFlag;
249exports.setFeatureFlagForTest = setFeatureFlagForTest;
250/** version: 1.8.1 */