data-navigator 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -25
- package/README.md +18 -9
- package/dist/index.js +26 -7
- package/dist/index.mjs +23 -7
- package/dist/rendering.js +1 -1
- package/dist/rendering.mjs +1 -1
- package/dist/structure.mjs +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
4
|
-
All rights reserved.
|
|
3
|
+
Copyright (c) 2023 Carnegie Mellon University
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
# Data
|
|
1
|
+
# Data Navigator
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
5
|
Data Navigator is a JavaScript library that allows for navigation of data structures. Data Navigator makes png, svg, canvas, and even webgl graphics accessible to a wide array of assistive technologies and input modalities.
|
|
6
6
|
|
|
7
|
+
Check out [our online, interactive demo](http://dig.cmu.edu/data-navigator/) for a video introduction and to try out Data Navigator hands-on.
|
|
8
|
+
|
|
9
|
+
## Data Navigator's approach
|
|
10
|
+
|
|
7
11
|
Data Navigator has abstracted navigation into commands, which enables it to easily receive input from screen readers and keyboards to more interesting modalities like touch and mouse swiping, spoken commands, hand gestures, and even fabricated or totally novel interfaces, like bananas.
|
|
8
12
|
|
|
9
13
|

|
|
@@ -22,25 +26,30 @@ Visit [our landing page](http://dig.cmu.edu/data-navigator/) to try our demo, wh
|
|
|
22
26
|
|
|
23
27
|
We also have [a vega-lite demo online](https://dig.cmu.edu/data-navigator/vega-lite.html), which (under the hood) shows how someone could write one schema that serves any chart in an ecosystem.
|
|
24
28
|
|
|
25
|
-
##
|
|
26
|
-
|
|
29
|
+
## System design
|
|
30
|
+
|
|
31
|
+
Data Navigator is organized into 3 separately composable modules: the first is a graph-based _structure_ of nodes and edges, the second handles _input_ and navigation logic, and the third _renders_ the structure. These may be leveraged together or independently. Read our paper to learn more!
|
|
27
32
|
|
|
28
33
|
## Getting started
|
|
34
|
+
|
|
29
35
|
You can install or use both esm and cjs modules in a variety of ways, in addition to importing all of data-navigator or just one part.
|
|
36
|
+
|
|
30
37
|
```
|
|
31
38
|
# to install into a project
|
|
32
39
|
npm install data-navigator
|
|
33
40
|
```
|
|
41
|
+
|
|
34
42
|
```js
|
|
35
43
|
// to use it in a .js or .ts file
|
|
36
|
-
import { default as dataNavigator } from 'data-navigator'
|
|
37
|
-
console.log(dataNavigator)
|
|
44
|
+
import { default as dataNavigator } from 'data-navigator';
|
|
45
|
+
console.log(dataNavigator);
|
|
38
46
|
```
|
|
47
|
+
|
|
39
48
|
```html
|
|
40
49
|
<!-- and even as a script tag module loaded from a cdn -->
|
|
41
50
|
<script type="module">
|
|
42
|
-
import dataNavigator from
|
|
43
|
-
console.log(dataNavigator)
|
|
51
|
+
import dataNavigator from 'https://cdn.jsdelivr.net/npm/data-navigator@1.0.0/dist/index.mjs';
|
|
52
|
+
console.log(dataNavigator);
|
|
44
53
|
</script>
|
|
45
54
|
```
|
|
46
55
|
|
|
@@ -48,7 +57,7 @@ console.log(dataNavigator)
|
|
|
48
57
|
|
|
49
58
|
Data-Navigator was developed at CMU's [Data Interaction Group](https://dig.cmu.edu/) (CMU DIG), primarily by [Frank Elavsky](https://frank.computer).
|
|
50
59
|
|
|
51
|
-
## Citing Data
|
|
60
|
+
## Citing Data Navigator
|
|
52
61
|
|
|
53
62
|
```bib
|
|
54
63
|
@article{2023-data-navigator,
|
|
@@ -57,4 +66,4 @@ Data-Navigator was developed at CMU's [Data Interaction Group](https://dig.cmu.e
|
|
|
57
66
|
title = {{Data Navigator:} An Accessibility-Centered Data Navigation Toolkit},
|
|
58
67
|
journal = {{IEEE} {VIS}}
|
|
59
68
|
}
|
|
60
|
-
```
|
|
69
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -523,6 +523,12 @@ var input_default = function(options) {
|
|
|
523
523
|
};
|
|
524
524
|
// src/rendering.ts
|
|
525
525
|
var rendering_default = function(options) {
|
|
526
|
+
var setActiveDescendant = function(e) {
|
|
527
|
+
renderer.wrapper.setAttribute("aria-activedescendant", e.srcElement.id);
|
|
528
|
+
};
|
|
529
|
+
var removeActiveDescendant = function() {
|
|
530
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
531
|
+
};
|
|
526
532
|
var renderer = {};
|
|
527
533
|
var initialized = false;
|
|
528
534
|
var defaults = {
|
|
@@ -540,6 +546,7 @@ var rendering_default = function(options) {
|
|
|
540
546
|
defaults.existingElement = options.defaults.existingElement ? _object_spread({}, defaults.existingElement, options.defaults.existingElement) : defaults.existingElement;
|
|
541
547
|
}
|
|
542
548
|
renderer.initialize = function() {
|
|
549
|
+
var _options_exitElement;
|
|
543
550
|
if (initialized) {
|
|
544
551
|
console.error("The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ".concat(options.suffixId, ". No further action was taken."));
|
|
545
552
|
return;
|
|
@@ -558,6 +565,9 @@ var rendering_default = function(options) {
|
|
|
558
565
|
}
|
|
559
566
|
renderer.wrapper = document.createElement("div");
|
|
560
567
|
renderer.wrapper.id = "dn-wrapper-" + options.suffixId;
|
|
568
|
+
renderer.wrapper.setAttribute("role", "application");
|
|
569
|
+
renderer.wrapper.setAttribute("aria-label", options.root.description || "Data navigation structure");
|
|
570
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
561
571
|
renderer.wrapper.classList.add("dn-wrapper");
|
|
562
572
|
renderer.wrapper.style.width = options.root && options.root.width ? options.root.width : "100%";
|
|
563
573
|
if (options.root && options.root.height) {
|
|
@@ -577,7 +587,7 @@ var rendering_default = function(options) {
|
|
|
577
587
|
renderer.wrapper.appendChild(renderer.entryButton);
|
|
578
588
|
}
|
|
579
589
|
renderer.root.appendChild(renderer.wrapper);
|
|
580
|
-
if (options.exitElement
|
|
590
|
+
if ((_options_exitElement = options.exitElement) === null || _options_exitElement === void 0 ? void 0 : _options_exitElement.include) {
|
|
581
591
|
renderer.exitElement = document.createElement("div");
|
|
582
592
|
renderer.exitElement.id = "dn-exit-" + options.suffixId;
|
|
583
593
|
renderer.exitElement.classList.add("dn-exit-position");
|
|
@@ -587,15 +597,17 @@ var rendering_default = function(options) {
|
|
|
587
597
|
renderer.exitElement.setAttribute("tabindex", "-1");
|
|
588
598
|
renderer.exitElement.style.display = "none";
|
|
589
599
|
renderer.exitElement.addEventListener("focus", function(e) {
|
|
600
|
+
var _options_exitElement_callbacks, _options_exitElement;
|
|
590
601
|
renderer.exitElement.style.display = "block";
|
|
591
602
|
renderer.clearStructure();
|
|
592
|
-
if (options.exitElement.callbacks
|
|
603
|
+
if ((_options_exitElement = options.exitElement) === null || _options_exitElement === void 0 ? void 0 : (_options_exitElement_callbacks = _options_exitElement.callbacks) === null || _options_exitElement_callbacks === void 0 ? void 0 : _options_exitElement_callbacks.focus) {
|
|
593
604
|
options.exitElement.callbacks.focus(e);
|
|
594
605
|
}
|
|
595
606
|
});
|
|
596
607
|
renderer.exitElement.addEventListener("blur", function(e) {
|
|
608
|
+
var _options_exitElement_callbacks, _options_exitElement;
|
|
597
609
|
renderer.exitElement.style.display = "none";
|
|
598
|
-
if (options.exitElement.callbacks
|
|
610
|
+
if ((_options_exitElement = options.exitElement) === null || _options_exitElement === void 0 ? void 0 : (_options_exitElement_callbacks = _options_exitElement.callbacks) === null || _options_exitElement_callbacks === void 0 ? void 0 : _options_exitElement_callbacks.blur) {
|
|
599
611
|
options.exitElement.callbacks.blur(e);
|
|
600
612
|
}
|
|
601
613
|
});
|
|
@@ -605,7 +617,7 @@ var rendering_default = function(options) {
|
|
|
605
617
|
return renderer.root;
|
|
606
618
|
};
|
|
607
619
|
renderer.render = function(nodeData) {
|
|
608
|
-
var id = nodeData.renderId;
|
|
620
|
+
var id = nodeData.renderId + "";
|
|
609
621
|
var d = options.elementData[id];
|
|
610
622
|
if (!d) {
|
|
611
623
|
console.warn("Render data not found with renderId: ".concat(id, ". Failed to render."));
|
|
@@ -644,7 +656,9 @@ var rendering_default = function(options) {
|
|
|
644
656
|
node.style.height = height + "px";
|
|
645
657
|
node.style.left = x + "px";
|
|
646
658
|
node.style.top = y + "px";
|
|
647
|
-
node.setAttribute("tabindex", "
|
|
659
|
+
node.setAttribute("tabindex", "0");
|
|
660
|
+
node.addEventListener("focus", setActiveDescendant);
|
|
661
|
+
node.addEventListener("blur", removeActiveDescendant);
|
|
648
662
|
var nodeText = document.createElement(resolveProp("semantics", "elementType"));
|
|
649
663
|
var attributes = resolveProp("semantics", "attributes");
|
|
650
664
|
if (typeof attributes === "object") {
|
|
@@ -671,8 +685,8 @@ var rendering_default = function(options) {
|
|
|
671
685
|
svg.setAttribute("width", totalWidth + "");
|
|
672
686
|
svg.setAttribute("height", totalHeight + "");
|
|
673
687
|
svg.setAttribute("viewBox", "0 0 ".concat(totalWidth, " ").concat(totalHeight));
|
|
674
|
-
svg.style.left = -x + "";
|
|
675
|
-
svg.style.top = -y + "";
|
|
688
|
+
svg.style.left = -x + "px";
|
|
689
|
+
svg.style.top = -y + "px";
|
|
676
690
|
svg.classList.add("dn-node-svg");
|
|
677
691
|
svg.setAttribute("role", "presentation");
|
|
678
692
|
svg.setAttribute("focusable", "false");
|
|
@@ -687,7 +701,12 @@ var rendering_default = function(options) {
|
|
|
687
701
|
};
|
|
688
702
|
renderer.remove = function(renderId) {
|
|
689
703
|
var node = document.getElementById(renderId);
|
|
704
|
+
if (renderer.wrapper.getAttribute("aria-activedescendant") === renderId) {
|
|
705
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
706
|
+
}
|
|
690
707
|
if (node) {
|
|
708
|
+
node.removeEventListener("focus", setActiveDescendant);
|
|
709
|
+
node.removeEventListener("blur", removeActiveDescendant);
|
|
691
710
|
node.remove();
|
|
692
711
|
}
|
|
693
712
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -393,6 +393,12 @@ var input_default = (options) => {
|
|
|
393
393
|
|
|
394
394
|
// src/rendering.ts
|
|
395
395
|
var rendering_default = (options) => {
|
|
396
|
+
const setActiveDescendant = (e) => {
|
|
397
|
+
renderer.wrapper.setAttribute("aria-activedescendant", e.srcElement.id);
|
|
398
|
+
};
|
|
399
|
+
const removeActiveDescendant = () => {
|
|
400
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
401
|
+
};
|
|
396
402
|
let renderer = {};
|
|
397
403
|
let initialized = false;
|
|
398
404
|
let defaults = {
|
|
@@ -432,6 +438,9 @@ var rendering_default = (options) => {
|
|
|
432
438
|
}
|
|
433
439
|
renderer.wrapper = document.createElement("div");
|
|
434
440
|
renderer.wrapper.id = "dn-wrapper-" + options.suffixId;
|
|
441
|
+
renderer.wrapper.setAttribute("role", "application");
|
|
442
|
+
renderer.wrapper.setAttribute("aria-label", options.root.description || "Data navigation structure");
|
|
443
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
435
444
|
renderer.wrapper.classList.add("dn-wrapper");
|
|
436
445
|
renderer.wrapper.style.width = options.root && options.root.width ? options.root.width : "100%";
|
|
437
446
|
if (options.root && options.root.height) {
|
|
@@ -451,7 +460,7 @@ var rendering_default = (options) => {
|
|
|
451
460
|
renderer.wrapper.appendChild(renderer.entryButton);
|
|
452
461
|
}
|
|
453
462
|
renderer.root.appendChild(renderer.wrapper);
|
|
454
|
-
if (options.exitElement
|
|
463
|
+
if (options.exitElement?.include) {
|
|
455
464
|
renderer.exitElement = document.createElement("div");
|
|
456
465
|
renderer.exitElement.id = "dn-exit-" + options.suffixId;
|
|
457
466
|
renderer.exitElement.classList.add("dn-exit-position");
|
|
@@ -463,13 +472,13 @@ var rendering_default = (options) => {
|
|
|
463
472
|
renderer.exitElement.addEventListener("focus", (e) => {
|
|
464
473
|
renderer.exitElement.style.display = "block";
|
|
465
474
|
renderer.clearStructure();
|
|
466
|
-
if (options.exitElement
|
|
475
|
+
if (options.exitElement?.callbacks?.focus) {
|
|
467
476
|
options.exitElement.callbacks.focus(e);
|
|
468
477
|
}
|
|
469
478
|
});
|
|
470
479
|
renderer.exitElement.addEventListener("blur", (e) => {
|
|
471
480
|
renderer.exitElement.style.display = "none";
|
|
472
|
-
if (options.exitElement
|
|
481
|
+
if (options.exitElement?.callbacks?.blur) {
|
|
473
482
|
options.exitElement.callbacks.blur(e);
|
|
474
483
|
}
|
|
475
484
|
});
|
|
@@ -479,7 +488,7 @@ var rendering_default = (options) => {
|
|
|
479
488
|
return renderer.root;
|
|
480
489
|
};
|
|
481
490
|
renderer.render = (nodeData) => {
|
|
482
|
-
const id = nodeData.renderId;
|
|
491
|
+
const id = nodeData.renderId + "";
|
|
483
492
|
let d = options.elementData[id];
|
|
484
493
|
if (!d) {
|
|
485
494
|
console.warn(`Render data not found with renderId: ${id}. Failed to render.`);
|
|
@@ -518,7 +527,9 @@ var rendering_default = (options) => {
|
|
|
518
527
|
node.style.height = height + "px";
|
|
519
528
|
node.style.left = x + "px";
|
|
520
529
|
node.style.top = y + "px";
|
|
521
|
-
node.setAttribute("tabindex", "
|
|
530
|
+
node.setAttribute("tabindex", "0");
|
|
531
|
+
node.addEventListener("focus", setActiveDescendant);
|
|
532
|
+
node.addEventListener("blur", removeActiveDescendant);
|
|
522
533
|
const nodeText = document.createElement(resolveProp("semantics", "elementType"));
|
|
523
534
|
const attributes = resolveProp("semantics", "attributes");
|
|
524
535
|
if (typeof attributes === "object") {
|
|
@@ -547,8 +558,8 @@ var rendering_default = (options) => {
|
|
|
547
558
|
svg.setAttribute("width", totalWidth + "");
|
|
548
559
|
svg.setAttribute("height", totalHeight + "");
|
|
549
560
|
svg.setAttribute("viewBox", `0 0 ${totalWidth} ${totalHeight}`);
|
|
550
|
-
svg.style.left = -x + "";
|
|
551
|
-
svg.style.top = -y + "";
|
|
561
|
+
svg.style.left = -x + "px";
|
|
562
|
+
svg.style.top = -y + "px";
|
|
552
563
|
svg.classList.add("dn-node-svg");
|
|
553
564
|
svg.setAttribute("role", "presentation");
|
|
554
565
|
svg.setAttribute("focusable", "false");
|
|
@@ -563,7 +574,12 @@ var rendering_default = (options) => {
|
|
|
563
574
|
};
|
|
564
575
|
renderer.remove = (renderId) => {
|
|
565
576
|
const node = document.getElementById(renderId);
|
|
577
|
+
if (renderer.wrapper.getAttribute("aria-activedescendant") === renderId) {
|
|
578
|
+
renderer.wrapper.setAttribute("aria-activedescendant", "");
|
|
579
|
+
}
|
|
566
580
|
if (node) {
|
|
581
|
+
node.removeEventListener("focus", setActiveDescendant);
|
|
582
|
+
node.removeEventListener("blur", removeActiveDescendant);
|
|
567
583
|
node.remove();
|
|
568
584
|
}
|
|
569
585
|
};
|
package/dist/rendering.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t){if(t==null||t>e.length)t=e.length;for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function t(t){if(Array.isArray(t))return e(t)}function n(e,t,n){if(t in e){Object.defineProperty(e,t,{value:n,enumerable:true,configurable:true,writable:true})}else{e[t]=n}return e}function r(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function
|
|
1
|
+
function e(e,t){if(t==null||t>e.length)t=e.length;for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function t(t){if(Array.isArray(t))return e(t)}function n(e,t,n){if(t in e){Object.defineProperty(e,t,{value:n,enumerable:true,configurable:true,writable:true})}else{e[t]=n}return e}function r(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};var i=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){i=i.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}i.forEach(function(t){n(e,t,r[t])})}return e}function s(e){return t(e)||r(e)||o(e)||i()}function o(t,n){if(!t)return;if(typeof t==="string")return e(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);if(r==="Object"&&t.constructor)r=t.constructor.name;if(r==="Map"||r==="Set")return Array.from(r);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return e(t,n)}var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var f=function(e,t){for(var n in t)l(e,n,{get:t[n],enumerable:!0})},m=function(e,t,n,r){var i=true,a=false,s=undefined;if(t&&typeof t=="object"||typeof t=="function")try{var o=function(){var i=m.value;!d.call(e,i)&&i!==n&&l(e,i,{get:function(){return t[i]},enumerable:!(r=u(t,i))||r.enumerable})};for(var f=c(t)[Symbol.iterator](),m;!(i=(m=f.next()).done);i=true)o()}catch(e){a=true;s=e}finally{try{if(!i&&f.return!=null){f.return()}}finally{if(a){throw s}}}return e};var p=function(e){return m(l({},"__esModule",{value:!0}),e)};var b={};f(b,{default:function(){return v}});module.exports=p(b);var y={cssClass:"",dimensions:{x:0,y:0,width:0,height:0,path:""},semantics:{label:"",elementType:"div",role:"image",attributes:void 0},parentSemantics:{label:"",elementType:"figure",role:"figure",attributes:void 0},existingElement:{useForDimensions:!1,dimensions:void 0}};var v=function(e){var t=function(e){r.wrapper.setAttribute("aria-activedescendant",e.srcElement.id)},n=function(){r.wrapper.setAttribute("aria-activedescendant","")},r={},i=!1,o={cssClass:y.cssClass,dimensions:a({},y.dimensions),semantics:a({},y.semantics),parentSemantics:a({},y.parentSemantics),existingElement:a({},y.existingElement)};return e.defaults&&(o.cssClass=e.defaults.cssClass||o.cssClass,o.dimensions=e.defaults.dimensions?a({},o.dimensions,e.defaults.dimensions):o.dimensions,o.semantics=e.defaults.semantics?a({},o.semantics,e.defaults.semantics):o.semantics,o.parentSemantics=e.defaults.parentSemantics?a({},o.parentSemantics,e.defaults.parentSemantics):o.parentSemantics,o.existingElement=e.defaults.existingElement?a({},o.existingElement,e.defaults.existingElement):o.existingElement),r.initialize=function(){var t;if(i){console.error("The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ".concat(e.suffixId,". No further action was taken."));return}if(e.root&&document.getElementById(e.root.id))r.root=document.getElementById(e.root.id);else{console.error("No root element found, cannot build: RenderingOptions.root.id must reference an existing DOM element in order to render children.");return}if(r.root.style.position="relative",r.root.classList.add("dn-root"),!e.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return r.wrapper=document.createElement("div"),r.wrapper.id="dn-wrapper-"+e.suffixId,r.wrapper.setAttribute("role","application"),r.wrapper.setAttribute("aria-label",e.root.description||"Data navigation structure"),r.wrapper.setAttribute("aria-activedescendant",""),r.wrapper.classList.add("dn-wrapper"),r.wrapper.style.width=e.root&&e.root.width?e.root.width:"100%",e.root&&e.root.height&&(r.wrapper.style.height=e.root.height),e.entryButton&&e.entryButton.include&&(r.entryButton=document.createElement("button"),r.entryButton.id="dn-entry-button-"+e.suffixId,r.entryButton.classList.add("dn-entry-button"),r.entryButton.innerText="Enter navigation area",e.entryButton.callbacks&&e.entryButton.callbacks.click&&r.entryButton.addEventListener("click",e.entryButton.callbacks.click),e.entryButton.callbacks&&e.entryButton.callbacks.focus&&r.entryButton.addEventListener("focus",e.entryButton.callbacks.focus),r.wrapper.appendChild(r.entryButton)),r.root.appendChild(r.wrapper),((t=e.exitElement)===null||t===void 0?void 0:t.include)&&(r.exitElement=document.createElement("div"),r.exitElement.id="dn-exit-"+e.suffixId,r.exitElement.classList.add("dn-exit-position"),r.exitElement.innerText="End of data structure.",r.exitElement.setAttribute("aria-label","End of data structure."),r.exitElement.setAttribute("role","note"),r.exitElement.setAttribute("tabindex","-1"),r.exitElement.style.display="none",r.exitElement.addEventListener("focus",function(t){var n,i;r.exitElement.style.display="block",r.clearStructure(),((i=e.exitElement)===null||i===void 0?void 0:(n=i.callbacks)===null||n===void 0?void 0:n.focus)&&e.exitElement.callbacks.focus(t)}),r.exitElement.addEventListener("blur",function(t){var n,i;r.exitElement.style.display="none",((i=e.exitElement)===null||i===void 0?void 0:(n=i.callbacks)===null||n===void 0?void 0:n.blur)&&e.exitElement.callbacks.blur(t)}),r.root.appendChild(r.exitElement)),i=!0,r.root},r.render=function(a){var s=a.renderId+"",l=e.elementData[s];if(!l){console.warn("Render data not found with renderId: ".concat(s,". Failed to render."));return}if(!i){console.error("render() was called before initialize(), renderer must be initialized first.");return}var u=!1,c={},d=function(e,t,n){var r=l[e]||o[e],i=n&&u?c[t]:r[t],s=o[e][t];return typeof r=="function"?r(l,a.datum):typeof i=="function"?i(l,a.datum):i||s||(t?void 0:r)};u=d("existingElement","useForDimensions"),c=d("existingElement","dimensions");var f=parseFloat(d("dimensions","width",!0)||0),m=parseFloat(d("dimensions","height",!0)||0),p=parseFloat(d("dimensions","x",!0)||0),b=parseFloat(d("dimensions","y",!0)||0),y=document.createElement(d("parentSemantics","elementType")),v=d("parentSemantics","attributes");typeof v=="object"&&Object.keys(v).forEach(function(e){y.setAttribute(e,v[e])}),y.setAttribute("role",d("parentSemantics","role")),y.id=s,y.classList.add("dn-node"),y.classList.add(d("cssClass")),y.style.width=f+"px",y.style.height=m+"px",y.style.left=p+"px",y.style.top=b+"px",y.setAttribute("tabindex","0"),y.addEventListener("focus",t),y.addEventListener("blur",n);var x=document.createElement(d("semantics","elementType")),E=d("semantics","attributes");typeof E=="object"&&Object.keys(E).forEach(function(e){y.setAttribute(e,E[e])}),x.setAttribute("role",d("semantics","role")),x.classList.add("dn-node-text"),l.showText&&(x.innerText=l.semantics.label);var h=d("semantics","label");h||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),x.setAttribute("aria-label",h),y.appendChild(x);var w=d("dimensions","path");if(w){var g=f+p+10,A=m+b+10,S=document.createElementNS("http://www.w3.org/2000/svg","svg");S.setAttribute("width",g+""),S.setAttribute("height",A+""),S.setAttribute("viewBox","0 0 ".concat(g," ").concat(A)),S.style.left=-p+"px",S.style.top=-b+"px",S.classList.add("dn-node-svg"),S.setAttribute("role","presentation"),S.setAttribute("focusable","false");var O=document.createElementNS("http://www.w3.org/2000/svg","path");O.setAttribute("d",w),O.classList.add("dn-node-path"),S.appendChild(O),y.appendChild(S)}return r.wrapper.appendChild(y),y},r.remove=function(e){var i=document.getElementById(e);r.wrapper.getAttribute("aria-activedescendant")===e&&r.wrapper.setAttribute("aria-activedescendant",""),i&&(i.removeEventListener("focus",t),i.removeEventListener("blur",n),i.remove())},r.clearStructure=function(){s(r.wrapper.children).forEach(function(e){r.entryButton&&r.entryButton===e||r.remove(e.id)})},r};
|
package/dist/rendering.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as m}from"./chunk-GP5LYFFJ.mjs";var
|
|
1
|
+
import{d as m}from"./chunk-GP5LYFFJ.mjs";var T=t=>{let w=r=>{e.wrapper.setAttribute("aria-activedescendant",r.srcElement.id)},g=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},b=!1,s={cssClass:m.cssClass,dimensions:{...m.dimensions},semantics:{...m.semantics},parentSemantics:{...m.parentSemantics},existingElement:{...m.existingElement}};return t.defaults&&(s.cssClass=t.defaults.cssClass||s.cssClass,s.dimensions=t.defaults.dimensions?{...s.dimensions,...t.defaults.dimensions}:s.dimensions,s.semantics=t.defaults.semantics?{...s.semantics,...t.defaults.semantics}:s.semantics,s.parentSemantics=t.defaults.parentSemantics?{...s.parentSemantics,...t.defaults.parentSemantics}:s.parentSemantics,s.existingElement=t.defaults.existingElement?{...s.existingElement,...t.defaults.existingElement}:s.existingElement),e.initialize=()=>{if(b){console.error(`The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ${t.suffixId}. No further action was taken.`);return}if(t.root&&document.getElementById(t.root.id))e.root=document.getElementById(t.root.id);else{console.error("No root element found, cannot build: RenderingOptions.root.id must reference an existing DOM element in order to render children.");return}if(e.root.style.position="relative",e.root.classList.add("dn-root"),!t.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return e.wrapper=document.createElement("div"),e.wrapper.id="dn-wrapper-"+t.suffixId,e.wrapper.setAttribute("role","application"),e.wrapper.setAttribute("aria-label",t.root.description||"Data navigation structure"),e.wrapper.setAttribute("aria-activedescendant",""),e.wrapper.classList.add("dn-wrapper"),e.wrapper.style.width=t.root&&t.root.width?t.root.width:"100%",t.root&&t.root.height&&(e.wrapper.style.height=t.root.height),t.entryButton&&t.entryButton.include&&(e.entryButton=document.createElement("button"),e.entryButton.id="dn-entry-button-"+t.suffixId,e.entryButton.classList.add("dn-entry-button"),e.entryButton.innerText="Enter navigation area",t.entryButton.callbacks&&t.entryButton.callbacks.click&&e.entryButton.addEventListener("click",t.entryButton.callbacks.click),t.entryButton.callbacks&&t.entryButton.callbacks.focus&&e.entryButton.addEventListener("focus",t.entryButton.callbacks.focus),e.wrapper.appendChild(e.entryButton)),e.root.appendChild(e.wrapper),t.exitElement?.include&&(e.exitElement=document.createElement("div"),e.exitElement.id="dn-exit-"+t.suffixId,e.exitElement.classList.add("dn-exit-position"),e.exitElement.innerText="End of data structure.",e.exitElement.setAttribute("aria-label","End of data structure."),e.exitElement.setAttribute("role","note"),e.exitElement.setAttribute("tabindex","-1"),e.exitElement.style.display="none",e.exitElement.addEventListener("focus",r=>{e.exitElement.style.display="block",e.clearStructure(),t.exitElement?.callbacks?.focus&&t.exitElement.callbacks.focus(r)}),e.exitElement.addEventListener("blur",r=>{e.exitElement.style.display="none",t.exitElement?.callbacks?.blur&&t.exitElement.callbacks.blur(r)}),e.root.appendChild(e.exitElement)),b=!0,e.root},e.render=r=>{let d=r.renderId+"",u=t.elementData[d];if(!u){console.warn(`Render data not found with renderId: ${d}. Failed to render.`);return}if(!b){console.error("render() was called before initialize(), renderer must be initialized first.");return}let v=!1,A={},i=(a,o,l)=>{let c=u[a]||s[a],h=l&&v?A[o]:c[o],C=s[a][o];return typeof c=="function"?c(u,r.datum):typeof h=="function"?h(u,r.datum):h||C||(o?void 0:c)};v=i("existingElement","useForDimensions"),A=i("existingElement","dimensions");let B=parseFloat(i("dimensions","width",!0)||0),k=parseFloat(i("dimensions","height",!0)||0),p=parseFloat(i("dimensions","x",!0)||0),x=parseFloat(i("dimensions","y",!0)||0),n=document.createElement(i("parentSemantics","elementType")),E=i("parentSemantics","attributes");typeof E=="object"&&Object.keys(E).forEach(a=>{n.setAttribute(a,E[a])}),n.setAttribute("role",i("parentSemantics","role")),n.id=d,n.classList.add("dn-node"),n.classList.add(i("cssClass")),n.style.width=B+"px",n.style.height=k+"px",n.style.left=p+"px",n.style.top=x+"px",n.setAttribute("tabindex","0"),n.addEventListener("focus",w),n.addEventListener("blur",g);let f=document.createElement(i("semantics","elementType")),y=i("semantics","attributes");typeof y=="object"&&Object.keys(y).forEach(a=>{n.setAttribute(a,y[a])}),f.setAttribute("role",i("semantics","role")),f.classList.add("dn-node-text"),u.showText&&(f.innerText=u.semantics.label);let L=i("semantics","label");L||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),f.setAttribute("aria-label",L),n.appendChild(f);let S=i("dimensions","path");if(S){let a=B+p+10,o=k+x+10,l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("width",a+""),l.setAttribute("height",o+""),l.setAttribute("viewBox",`0 0 ${a} ${o}`),l.style.left=-p+"px",l.style.top=-x+"px",l.classList.add("dn-node-svg"),l.setAttribute("role","presentation"),l.setAttribute("focusable","false");let c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",S),c.classList.add("dn-node-path"),l.appendChild(c),n.appendChild(l)}return e.wrapper.appendChild(n),n},e.remove=r=>{let d=document.getElementById(r);e.wrapper.getAttribute("aria-activedescendant")===r&&e.wrapper.setAttribute("aria-activedescendant",""),d&&(d.removeEventListener("focus",w),d.removeEventListener("blur",g),d.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(r=>{e.entryButton&&e.entryButton===r||e.remove(r.id)})},e};export{T as default};
|
package/dist/structure.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as L}from"./chunk-KNRZ7RNY.mjs";import{c as C}from"./chunk-GP5LYFFJ.mjs";var j=t=>{if(t.dataType==="vega-lite"||t.dataType==="vl"||t.dataType==="Vega-Lite")return w(t);console.warn("Apologies, we currently only have structure scaffolding for Vega-Lite, generic scaffolding coming soon!")},w=t=>{let R=C,r={},u={},o={},y=0,$=t.groupInclusionCriteria?t.groupInclusionCriteria:()=>!0,E=t.itemInclusionCriteria?t.itemInclusionCriteria:()=>!0,S=t.datumInclusionCriteria?t.datumInclusionCriteria:()=>!0,b=t.vegaLiteView._renderer._origin,I=t.vegaLiteView._scenegraph.root.items[0].mark.items[0],m=(e,i)=>{if(e["data-navigator-id"])return e["data-navigator-id"];let c=`dn-node-${i}-${y}`;return y++,e["data-navigator-id"]=c,c},k=e=>{let i=r[e],c=i.index,g=i.level,l=i.parent,n=[],d=l.items[c-1];if(d){let s=m(d,g);if(r[s]){let a=`${s}-${i.id}`;n.push(a),u[a]||(u[a]={source:s,target:i.id,navigationRules:["left","right"]})}}let f=l.items[c+1];if(f){let s=m(f,g);if(r[s]){let a=`${i.id}-${s}`;n.push(a),u[a]||(u[a]={source:i.id,target:s,navigationRules:["left","right"]})}}if(g==="group"&&l.items[c].items){let a=(l.items[c].items[0].mark.items[0].items||l.items[c].items)[0],v=m(a,"item");if(r[v]){let x=`${i.id}-${v}`;n.push(x),u[x]||(u[x]={source:i.id,target:v,navigationRules:["parent","child"]})}}else if(g==="item"){let s=m(l,"group");if(r[s]){let a=`${s}-${i.id}`;n.push(a),u[a]||(u[a]={source:s,target:i.id,navigationRules:["parent","child"]})}}return t.exitFunction&&(n.push("any-exit"),u["any-exit"]||(u["any-exit"]={source:t.getCurrent,target:t.exitFunction,navigationRules:["exit"]})),n.push("any-undo"),u["any-undo"]||(u["any-undo"]={source:t.getCurrent,target:t.getPrevious,navigationRules:["undo"]}),n},p=(e,i,c,g,l)=>{let n=m(e,i),d="render-"+n,f=c||[0,0];r[n]={},r[n].d={},r[n].id=n,r[n].renderId=d,r[n].index=g,r[n].level=i,r[n].parent=l,o[d]={},o[d].renderId=d,o[d].dimensions={},o[d].dimensions.x=e.bounds.x1+f[0],o[d].dimensions.y=e.bounds.y1+f[1],o[d].dimensions.width=e.bounds.x2-e.bounds.x1,o[d].dimensions.height=e.bounds.y2-e.bounds.y1,o[d].cssClass="dn-vega-lite-node",e.datum&&Object.keys(e.datum).forEach(s=>{let a=e.datum[s];S(s,a,e.datum,i,t.vegaLiteSpec)&&(r[n].d[t.keyRenamingHash&&t.keyRenamingHash[s]?t.keyRenamingHash[s]:s]=a)}),o[d].semantics={},o[d].semantics.label=t.nodeDescriber?t.nodeDescriber(r[n].d,e,i):L(r[n].d)},h=0;return I.items.forEach(e=>{if($(e,h,t.vegaLiteSpec)){p(e,"group",b,h,I);let i=0,c=e.items[0].mark.items[0].items?e.items[0].mark.items[0]:e;c.items.forEach(g=>{E(g,i,e,t.vegaLiteSpec)&&p(g,"item",b,i,c),i++})}h++}),Object.keys(r).forEach(e=>{r[e].edges=k(e)}),{nodes:r,edges:u,elementData:o,navigationRules:R}},B=t=>({});export{B as buildNodeStructure,w as buildNodeStructureFromVegaLite,j as default};
|