Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lwc/aria-reflection

Package Overview
Dependencies
Maintainers
14
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lwc/aria-reflection - npm Package Compare versions

Comparing version 4.0.0-alpha.0 to 4.0.0

135

dist/index.cjs.js

@@ -6,8 +6,4 @@ /**

Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@lwc/shared');
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.

@@ -17,57 +13,80 @@ * SPDX-License-Identifier: MIT

*/
function detect(propName, prototype) {
return shared.isUndefined(shared.getOwnPropertyDescriptor(prototype, propName));
}
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
function createAriaPropertyPropertyDescriptor(attrName) {
// Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
// from Element.prototype, because these methods are overridden in LightningElement.
return {
get() {
// reflect what's in the attribute
return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
},
set(newValue) {
// reflect into the corresponding attribute
if (shared.isNull(newValue)) {
this.removeAttribute(attrName);
}
else {
this.setAttribute(attrName, newValue);
}
},
configurable: true,
enumerable: true,
};
}
function patch(propName, prototype) {
const attrName = shared.AriaPropNameToAttrNameMap[propName];
const descriptor = createAriaPropertyPropertyDescriptor(attrName);
shared.defineProperty(prototype, propName, descriptor);
}
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
function applyAriaReflection(prototype = Element.prototype) {
const ElementPrototypeAriaPropertyNames = shared.keys(shared.AriaPropNameToAttrNameMap);
for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
const propName = ElementPrototypeAriaPropertyNames[i];
if (detect(propName, prototype)) {
patch(propName, prototype);
}
// Minimal polyfill of ARIA string reflection, plus some non-standard ARIA props
// Taken from https://github.com/salesforce/lwc/blob/44a01ef/packages/%40lwc/shared/src/aria.ts#L22-L70
// This is designed for maximum backwards compatibility on LEX - it should never change.
// We deliberately don't import from @lwc/shared because that would make this code less portable.
const ARIA_PROPERTIES = [
'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',
];
for (const prop of ARIA_PROPERTIES) {
const attribute = prop.replace(/^aria/, 'aria-').toLowerCase(); // e.g. ariaPosInSet => aria-posinset
if (!Object.getOwnPropertyDescriptor(Element.prototype, prop)) {
Object.defineProperty(Element.prototype, prop, {
get() {
return this.getAttribute(attribute);
},
set(value) {
// Per the spec, only null is treated as removing the attribute. However, Chromium/WebKit currently
// differ from the spec and allow undefined as well. Here, we follow the spec, as well as
// our historical behavior. See: https://github.com/w3c/aria/issues/1858
if (value === null) {
this.removeAttribute(attribute);
}
else {
this.setAttribute(attribute, value);
}
},
// configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
configurable: true,
enumerable: true,
});
}
}
exports.applyAriaReflection = applyAriaReflection;
/** version: 4.0.0-alpha.0 */
/** version: 4.0.0 */
//# sourceMappingURL=index.cjs.js.map

@@ -1,1 +0,1 @@

export declare function applyAriaReflection(prototype?: any): void;
declare const ARIA_PROPERTIES: string[];
/**
* Copyright (C) 2023 salesforce.com, inc.
*/
import { isUndefined, getOwnPropertyDescriptor, AriaPropNameToAttrNameMap, defineProperty, isNull, keys } from '@lwc/shared';
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.

@@ -12,57 +10,80 @@ * SPDX-License-Identifier: MIT

*/
function detect(propName, prototype) {
return isUndefined(getOwnPropertyDescriptor(prototype, propName));
}
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
function createAriaPropertyPropertyDescriptor(attrName) {
// Note that we need to call this.{get,set,has,remove}Attribute rather than dereferencing
// from Element.prototype, because these methods are overridden in LightningElement.
return {
get() {
// reflect what's in the attribute
return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null;
},
set(newValue) {
// reflect into the corresponding attribute
if (isNull(newValue)) {
this.removeAttribute(attrName);
}
else {
this.setAttribute(attrName, newValue);
}
},
configurable: true,
enumerable: true,
};
}
function patch(propName, prototype) {
const attrName = AriaPropNameToAttrNameMap[propName];
const descriptor = createAriaPropertyPropertyDescriptor(attrName);
defineProperty(prototype, propName, descriptor);
}
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
function applyAriaReflection(prototype = Element.prototype) {
const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap);
for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) {
const propName = ElementPrototypeAriaPropertyNames[i];
if (detect(propName, prototype)) {
patch(propName, prototype);
}
// Minimal polyfill of ARIA string reflection, plus some non-standard ARIA props
// Taken from https://github.com/salesforce/lwc/blob/44a01ef/packages/%40lwc/shared/src/aria.ts#L22-L70
// This is designed for maximum backwards compatibility on LEX - it should never change.
// We deliberately don't import from @lwc/shared because that would make this code less portable.
const ARIA_PROPERTIES = [
'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',
];
for (const prop of ARIA_PROPERTIES) {
const attribute = prop.replace(/^aria/, 'aria-').toLowerCase(); // e.g. ariaPosInSet => aria-posinset
if (!Object.getOwnPropertyDescriptor(Element.prototype, prop)) {
Object.defineProperty(Element.prototype, prop, {
get() {
return this.getAttribute(attribute);
},
set(value) {
// Per the spec, only null is treated as removing the attribute. However, Chromium/WebKit currently
// differ from the spec and allow undefined as well. Here, we follow the spec, as well as
// our historical behavior. See: https://github.com/w3c/aria/issues/1858
if (value === null) {
this.removeAttribute(attribute);
}
else {
this.setAttribute(attribute, value);
}
},
// configurable and enumerable to allow it to be overridden – this mimics Safari's/Chrome's behavior
configurable: true,
enumerable: true,
});
}
}
export { applyAriaReflection };
/** version: 4.0.0-alpha.0 */
/** version: 4.0.0 */
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ {

"name": "@lwc/aria-reflection",
"version": "4.0.0-alpha.0",
"version": "4.0.0",
"description": "ARIA element reflection polyfill for strings",

@@ -44,3 +44,3 @@ "keywords": [

"outputs": [
"./dist"
"{projectRoot}/dist"
]

@@ -50,5 +50,3 @@ }

},
"dependencies": {
"@lwc/shared": "4.0.0-alpha.0"
}
}
"dependencies": {}
}
# @lwc/aria-reflection
> **Note:** use this code at your own risk. It is optimized for backwards-compatibility, not
> as a forward-looking polyfill that keeps up to date with web standards.
Polyfill for [ARIA string reflection](https://wicg.github.io/aom/spec/aria-reflection.html) on Elements.

@@ -24,17 +27,7 @@ This is part of the [Accessibility Object Model](https://wicg.github.io/aom/explainer.html) (AOM).

```js
import { applyAriaReflection } from '@lwc/aria-reflection';
applyAriaReflection();
import '@lwc/aria-reflection';
```
The polyfill is applied as soon as the function is executed.
The polyfill is applied globally to `Element.prototype` as soon as the module is imported.
Optionally, you can pass in a custom prototype:
```js
applyAriaReflection(MyCustomElement.prototype);
```
By default, the polyfill is applied to the global `Element.prototype`.
## Implementation

@@ -41,0 +34,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc