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

@krautzource/sre-to-tree

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@krautzource/sre-to-tree - npm Package Compare versions

Comparing version 1.3.5 to 1.4.0

8

CHANGELOG.md

@@ -5,2 +5,10 @@ # Changelog

## [1.4.0](https://github.com/krautzource/sre-to-tree/compare/v1.3.5...v1.4.0) (2021-03-13)
### Features
* "reinstate" anchors ([eca1914](https://github.com/krautzource/sre-to-tree/commit/eca19148b2f1bb059739414aa017bf78dd6fcba9)), closes [#19](https://github.com/krautzource/sre-to-tree/issues/19)
* improve anchors ([e2afba8](https://github.com/krautzource/sre-to-tree/commit/e2afba8ede649edf35080c0973ff42ba4133e229)), closes [#22](https://github.com/krautzource/sre-to-tree/issues/22)
### [1.3.5](https://github.com/krautzource/sre-to-tree/compare/v1.3.4...v1.3.5) (2021-02-27)

@@ -7,0 +15,0 @@

36

lib.js

@@ -95,3 +95,3 @@ const crypto = require('crypto');

if (ariaOwned.includes(' ')) {
console.warn('empty aria-own part; stopping recursion')
console.warn('empty aria-own part; stopping recursion');
return;

@@ -113,3 +113,9 @@ }

const moveAttribute = (oldnode, newnode, attribute) => {
if (!oldnode || !newnode || oldnode === newnode || !oldnode.hasAttribute(attribute)) return;
if (
!oldnode ||
!newnode ||
oldnode === newnode ||
!oldnode.hasAttribute(attribute)
)
return;
const value = oldnode.getAttribute(attribute);

@@ -135,2 +141,24 @@ newnode.setAttribute(attribute, value);

*
* @param {Node} child A DOM descendant to postprocess
*/
const postprocessingDescendant = (child) => {
if (child.getAttribute('role')) return;
if (child.tagName.toUpperCase() !== 'A' || !child.hasAttribute('href')) {
child.setAttribute('role', 'presentation');
return;
}
const firstSemanticChild = child.querySelector('[data-semantic-speech]');
if (!firstSemanticChild) {
console.warn('Link without semantic child');
return;
}
firstSemanticChild.setAttribute('data-href', child.getAttribute('href'));
firstSemanticChild.setAttribute(
'aria-label',
firstSemanticChild.getAttribute('aria-label') + ' link'
); // TODO R&D braille display affordances and how to fit them together with Nemeth
};
/**
*
* @param {Node} node A DOM node containing speech-rule-engine-style attributes (data-semantic-*)

@@ -150,5 +178,3 @@ */

rewriteNode(semanticIdTable, hash, level, skeletonNode);
descendantNodes.forEach((child) => {
if (!child.getAttribute('role')) child.setAttribute('role', 'presentation');
});
descendantNodes.forEach(postprocessingDescendant);
if (node !== skeletonNode) {

@@ -155,0 +181,0 @@ moveAttribute(skeletonNode, node, 'aria-owns');

2

package.json
{
"name": "@krautzource/sre-to-tree",
"version": "1.3.5",
"version": "1.4.0",
"description": "Rewritig speech-rule-engine enriched DOM nodes to a labeled WAI ARIA tree",

@@ -5,0 +5,0 @@ "main": "lib.js",

@@ -5,9 +5,11 @@ const test = require('tape');

test('rewriteNode warnings', (t) => {
t.plan(1);
const out = tex2svg('\\href{//google.com}{link}');
test('anchors', (t) => {
t.plan(4);
const out = tex2svg('a = \\href{//example.com}{link}');
const svg = out.firstElementChild;
sre2tree(svg);
// console.log(svg.outerHTML)
t.ok(true , 'FAKE TEST - check there were no console warnings!');
t.notOk(svg.querySelector('a').getAttribute('role') , 'anchors do not get role (presentation');
t.equal(svg.querySelector('a > [data-semantic-speech]'), svg.querySelector('a > [data-href]'), 'Link "pushed" to first semantic child');
t.equal(svg.querySelector('a').getAttribute('href'), svg.querySelector('a > [data-href]').getAttribute('data-href'), '"pushed" Link data-href value');
t.ok(svg.querySelector('a > [data-href]').getAttribute('aria-label').endsWith(' link'), '"pushed" fake-link aria-label affordance');
});
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