UNPKG

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