data-navigator 2.2.3 → 2.3.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/dist/input.cjs CHANGED
@@ -1 +1 @@
1
- function e(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}var r=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var i=function e(e,t){for(var n in t)r(e,n,{get:t[n],enumerable:!0})},u=function i(i,u,a,c){var f=true,d=false,s=undefined;if(u&&(typeof u==="undefined"?"undefined":e(u))=="object"||typeof u=="function")try{var y=function(){var e=v.value;!o.call(i,e)&&e!==a&&r(i,e,{get:function r(){return u[e]},enumerable:!(c=t(u,e))||c.enumerable})};for(var l=n(u)[Symbol.iterator](),v;!(f=(v=l.next()).done);f=true)y()}catch(e){d=true;s=e}finally{try{if(!f&&l.return!=null){l.return()}}finally{if(d){throw s}}}return i};var a=function e(e){return u(r({},"__esModule",{value:!0}),e)};var c={};i(c,{default:function e(){return s}});module.exports=a(c);var f={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var d={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var s=function e(e){var r={},t=f,n=d;return r.moveTo=function(r){var t=e.structure.nodes[r];if(t)return t},r.move=function(t,o){if(t){var i=e.structure.nodes[t];if(i.edges){var u=function(){var r=e.structure.edges[i.edges[c]];if(r.navigationRules.forEach(function(e){a||(a=d(e,r))}),a)return"break"};var a=null,c=0,f=n[o];if(!f)return;var d=function e(e,r){if(e!==o)return null;var n={target:typeof r.target=="string"?r.target:r.target(i,t),source:typeof r.source=="string"?r.source:r.source(i,t)};return n[f.direction]!==t?n[f.direction]:null};for(c=0;c<i.edges.length;c++){var s=u();if(s==="break")break}return a?r.moveTo(a):void 0}}},r.enter=function(){if(e.entryPoint)return r.moveTo(e.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},r.exit=function(){if(e.exitPoint)return e.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},r.keydownValidator=function(e){var r=t[e.code];if(r)return r},r.focus=function(e){var r=document.getElementById(e);r&&r.focus()},r.setNavigationKeyBindings=function(e){e?(t={},n=e,Object.keys(e).forEach(function(r){var n=e[r];t[n.key]=r})):(t=f,n=d)},r.setNavigationKeyBindings(e.navigationRules),r};
1
+ var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var v=(r,t)=>{for(var n in t)p(r,n,{get:t[n],enumerable:!0})},x=(r,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of h(t))!m.call(r,e)&&e!==n&&p(r,e,{get:()=>t[e],enumerable:!(s=k(t,e))||s.enumerable});return r};var R=r=>x(p({},"__esModule",{value:!0}),r);var A={};v(A,{default:()=>b});module.exports=R(A);var g={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var f={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var b=r=>{let t={},n=g,s=f;return t.moveTo=e=>{let i=r.structure.nodes[e];if(i)return i},t.move=(e,i)=>{if(e){let a=r.structure.nodes[e];if(a.edges){let c=null,d=0,l=s[i];if(!l)return;let w=(u,o)=>{if(u!==i)return null;let y={target:typeof o.target=="string"?o.target:o.target(a,e),source:typeof o.source=="string"?o.source:o.source(a,e)};return y[l.direction]!==e?y[l.direction]:null};for(d=0;d<a.edges.length;d++){let u=r.structure.edges[a.edges[d]];if(u.navigationRules.forEach(o=>{c||(c=w(o,u))}),c)break}return c?t.moveTo(c):void 0}}},t.enter=()=>{if(r.entryPoint)return t.moveTo(r.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},t.exit=()=>{if(r.exitPoint)return r.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},t.keydownValidator=e=>{let i=n[e.code];if(i)return i},t.focus=e=>{let i=document.getElementById(e);i&&i.focus()},t.setNavigationKeyBindings=e=>{e?(n={},s=e,Object.keys(e).forEach(i=>{let a=e[i];n[a.key]=i})):(n=g,s=f)},t.setNavigationKeyBindings(r.navigationRules),t};
package/dist/input.js CHANGED
@@ -1 +1 @@
1
- import{b as c,f as g}from"./chunk-MPFBSVCV.js";var v=r=>{let n={},u=c,l=g;return n.moveTo=e=>{let t=r.structure.nodes[e];if(t)return t},n.move=(e,t)=>{if(e){let o=r.structure.nodes[e];if(o.edges){let s=null,a=0,d=l[t];if(!d)return;let y=(f,i)=>{if(f!==t)return null;let p={target:typeof i.target=="string"?i.target:i.target(o,e),source:typeof i.source=="string"?i.source:i.source(o,e)};return p[d.direction]!==e?p[d.direction]:null};for(a=0;a<o.edges.length;a++){let f=r.structure.edges[o.edges[a]];if(f.navigationRules.forEach(i=>{s||(s=y(i,f))}),s)break}return s?n.moveTo(s):void 0}}},n.enter=()=>{if(r.entryPoint)return n.moveTo(r.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},n.exit=()=>{if(r.exitPoint)return r.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},n.keydownValidator=e=>{let t=u[e.code];if(t)return t},n.focus=e=>{let t=document.getElementById(e);t&&t.focus()},n.setNavigationKeyBindings=e=>{e?(u={},l=e,Object.keys(e).forEach(t=>{let o=e[t];u[o.key]=t})):(u=c,l=g)},n.setNavigationKeyBindings(r.navigationRules),n};export{v as default};
1
+ import{a}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import"./chunk-RGY6OTGO.js";export{a as default};
@@ -1 +1 @@
1
- function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(t){if(Array.isArray(t))return e(t)}function r(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}function n(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 n=arguments[t]!=null?arguments[t]:{};var i=Object.keys(n);if(typeof Object.getOwnPropertySymbols==="function"){i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))}i.forEach(function(t){r(e,t,n[t])})}return e}function o(e){return t(e)||n(e)||l(e)||i()}function s(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function l(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor)n=t.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=function e(e,t){for(var r in t)u(e,r,{get:t[r],enumerable:!0})},m=function e(e,t,r,n){var i=true,a=false,o=undefined;if(t&&(typeof t==="undefined"?"undefined":s(t))=="object"||typeof t=="function")try{var l=function(){var i=m.value;!p.call(e,i)&&i!==r&&u(e,i,{get:function e(){return t[i]},enumerable:!(n=c(t,i))||n.enumerable})};for(var f=d(t)[Symbol.iterator](),m;!(i=(m=f.next()).done);i=true)l()}catch(e){a=true;o=e}finally{try{if(!i&&f.return!=null){f.return()}}finally{if(a){throw o}}}return e};var b=function e(e){return m(u({},"__esModule",{value:!0}),e)};var y={};f(y,{default:function e(){return x}});module.exports=b(y);var v={cssClass:void 0,spatialProperties:{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:{useForSpatialProperties:!1,spatialProperties:void 0}};var x=function e(e){var t=function e(e){n.wrapper.setAttribute("aria-activedescendant",e.srcElement.id)},r=function e(){n.wrapper.setAttribute("aria-activedescendant","")},n={},i=!1,l={cssClass:v.cssClass,spatialProperties:a({},v.spatialProperties),semantics:a({},v.semantics),parentSemantics:a({},v.parentSemantics),existingElement:a({},v.existingElement)};return e.defaults&&(l.cssClass=e.defaults.cssClass||l.cssClass,l.spatialProperties=e.defaults.spatialProperties?a({},l.spatialProperties,e.defaults.spatialProperties):l.spatialProperties,l.semantics=e.defaults.semantics?a({},l.semantics,e.defaults.semantics):l.semantics,l.parentSemantics=e.defaults.parentSemantics?a({},l.parentSemantics,e.defaults.parentSemantics):l.parentSemantics,l.existingElement=e.defaults.existingElement?a({},l.existingElement,e.defaults.existingElement):l.existingElement),n.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))n.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(n.root.style.position="relative",n.root.classList.add("dn-root"),!e.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return n.wrapper=document.createElement("div"),n.wrapper.id="dn-wrapper-"+e.suffixId,n.wrapper.setAttribute("role","application"),n.wrapper.setAttribute("aria-label",e.root.description||"Data navigation structure"),n.wrapper.setAttribute("aria-activedescendant",""),n.wrapper.classList.add("dn-wrapper"),n.wrapper.style.width=e.root&&e.root.width?e.root.width:"100%",e.root&&e.root.height&&(n.wrapper.style.height=e.root.height),e.entryButton&&e.entryButton.include&&(n.entryButton=document.createElement("button"),n.entryButton.id="dn-entry-button-"+e.suffixId,n.entryButton.classList.add("dn-entry-button"),n.entryButton.innerText="Enter navigation area",e.entryButton.callbacks&&e.entryButton.callbacks.click&&n.entryButton.addEventListener("click",e.entryButton.callbacks.click),e.entryButton.callbacks&&e.entryButton.callbacks.focus&&n.entryButton.addEventListener("focus",e.entryButton.callbacks.focus),n.wrapper.appendChild(n.entryButton)),n.root.appendChild(n.wrapper),((t=e.exitElement)===null||t===void 0?void 0:t.include)&&(n.exitElement=document.createElement("div"),n.exitElement.id="dn-exit-"+e.suffixId,n.exitElement.classList.add("dn-exit-position"),n.exitElement.innerText="End of data structure.",n.exitElement.setAttribute("aria-label","End of data structure."),n.exitElement.setAttribute("role","note"),n.exitElement.setAttribute("tabindex","-1"),n.exitElement.style.display="none",n.exitElement.addEventListener("focus",function(t){var r,i;n.exitElement.style.display="block",n.clearStructure(),((i=e.exitElement)===null||i===void 0?void 0:(r=i.callbacks)===null||r===void 0?void 0:r.focus)&&e.exitElement.callbacks.focus(t)}),n.exitElement.addEventListener("blur",function(t){var r,i;n.exitElement.style.display="none",((i=e.exitElement)===null||i===void 0?void 0:(r=i.callbacks)===null||r===void 0?void 0:r.blur)&&e.exitElement.callbacks.blur(t)}),n.root.appendChild(n.exitElement)),i=!0,n.root},n.render=function(a){var o=a.renderId+"",u=e.elementData[o];if(!u){console.warn("Render data not found with renderId: ".concat(o,". Failed to render."));return}if(!i){console.error("render() was called before initialize(), renderer must be initialized first.");return}var c=!1,d={},p=function e(e,t,r){var n;var i=u[e]||l[e],o=r&&c?d[t]:i===null||i===void 0?void 0:i[t],s=(n=l[e])===null||n===void 0?void 0:n[t];return typeof i=="function"?i(u,a.datum):typeof o=="function"?o(u,a.datum):o||s||(t?void 0:i)};c=p("existingElement","useForSpatialProperties"),d=p("existingElement","spatialProperties");var f=parseFloat(p("spatialProperties","width",!0)||0),m=parseFloat(p("spatialProperties","height",!0)||0),b=parseFloat(p("spatialProperties","x",!0)||0),y=parseFloat(p("spatialProperties","y",!0)||0),v=document.createElement(p("parentSemantics","elementType")),x=p("parentSemantics","attributes");(typeof x==="undefined"?"undefined":s(x))=="object"&&Object.keys(x).forEach(function(e){v.setAttribute(e,x[e])}),v.setAttribute("role",p("parentSemantics","role")),v.id=o,v.classList.add("dn-node"),v.classList.add(p("cssClass")),v.style.width=f+"px",v.style.height=m+"px",v.style.left=b+"px",v.style.top=y+"px",v.setAttribute("tabindex","0"),v.addEventListener("focus",t),v.addEventListener("blur",r);var h=document.createElement(p("semantics","elementType")),E=p("semantics","attributes");(typeof E==="undefined"?"undefined":s(E))=="object"&&Object.keys(E).forEach(function(e){v.setAttribute(e,E[e])}),h.setAttribute("role",p("semantics","role")),h.classList.add("dn-node-text"),u.showText&&(h.innerText=u.semantics.label);var w=p("semantics","label");w||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),h.setAttribute("aria-label",w),v.appendChild(h);var g=p("spatialProperties","path");if(g){var A=f+b+10,S=m+y+10,P=document.createElementNS("http://www.w3.org/2000/svg","svg");P.setAttribute("width",A+""),P.setAttribute("height",S+""),P.setAttribute("viewBox","0 0 ".concat(A," ").concat(S)),P.style.left=-b+"px",P.style.top=-y+"px",P.classList.add("dn-node-svg"),P.setAttribute("role","presentation"),P.setAttribute("focusable","false");var O=document.createElementNS("http://www.w3.org/2000/svg","path");O.setAttribute("d",g),O.classList.add("dn-node-path"),P.appendChild(O),v.appendChild(P)}return n.wrapper.appendChild(v),v},n.remove=function(e){var i=document.getElementById(e);n.wrapper.getAttribute("aria-activedescendant")===e&&n.wrapper.setAttribute("aria-activedescendant",""),i&&(i.removeEventListener("focus",t),i.removeEventListener("blur",r),i.remove())},n.clearStructure=function(){o(n.wrapper.children).forEach(function(e){n.entryButton&&n.entryButton===e||n.remove(e.id)})},n};
1
+ var b=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var O=(e,r,i)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,o=(e,r)=>{for(var i in r||(r={}))T.call(r,i)&&O(e,i,r[i]);if(N)for(var i of N(r))j.call(r,i)&&O(e,i,r[i]);return e};var F=(e,r)=>{for(var i in r)b(e,i,{get:r[i],enumerable:!0})},U=(e,r,i,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of I(r))!T.call(e,m)&&m!==i&&b(e,m,{get:()=>r[m],enumerable:!(t=K(r,m))||t.enumerable});return e};var z=e=>U(b({},"__esModule",{value:!0}),e);var $={};F($,{default:()=>G});module.exports=z($);var w={cssClass:void 0,spatialProperties:{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:{useForSpatialProperties:!1,spatialProperties:void 0}};var G=e=>{let r=l=>{t.wrapper.setAttribute("aria-activedescendant",l.srcElement.id)},i=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},m=!1,n={cssClass:w.cssClass,spatialProperties:o({},w.spatialProperties),semantics:o({},w.semantics),parentSemantics:o({},w.parentSemantics),existingElement:o({},w.existingElement)};return e.defaults&&(n.cssClass=e.defaults.cssClass||n.cssClass,n.spatialProperties=e.defaults.spatialProperties?o(o({},n.spatialProperties),e.defaults.spatialProperties):n.spatialProperties,n.semantics=e.defaults.semantics?o(o({},n.semantics),e.defaults.semantics):n.semantics,n.parentSemantics=e.defaults.parentSemantics?o(o({},n.parentSemantics),e.defaults.parentSemantics):n.parentSemantics,n.existingElement=e.defaults.existingElement?o(o({},n.existingElement),e.defaults.existingElement):n.existingElement),t.initialize=()=>{var l;if(m){console.error(`The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ${e.suffixId}. No further action was taken.`);return}if(e.root&&document.getElementById(e.root.id))t.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(t.root.style.position="relative",t.root.classList.add("dn-root"),!e.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return t.wrapper=document.createElement("div"),t.wrapper.id="dn-wrapper-"+e.suffixId,t.wrapper.setAttribute("role","application"),t.wrapper.setAttribute("aria-label",e.root.description||"Data navigation structure"),t.wrapper.setAttribute("aria-activedescendant",""),t.wrapper.classList.add("dn-wrapper"),t.wrapper.style.width=e.root&&e.root.width?e.root.width:"100%",e.root&&e.root.height&&(t.wrapper.style.height=e.root.height),e.entryButton&&e.entryButton.include&&(t.entryButton=document.createElement("button"),t.entryButton.id="dn-entry-button-"+e.suffixId,t.entryButton.classList.add("dn-entry-button"),t.entryButton.innerText="Enter navigation area",e.entryButton.callbacks&&e.entryButton.callbacks.click&&t.entryButton.addEventListener("click",e.entryButton.callbacks.click),e.entryButton.callbacks&&e.entryButton.callbacks.focus&&t.entryButton.addEventListener("focus",e.entryButton.callbacks.focus),t.wrapper.appendChild(t.entryButton)),t.root.appendChild(t.wrapper),(l=e.exitElement)!=null&&l.include&&(t.exitElement=document.createElement("div"),t.exitElement.id="dn-exit-"+e.suffixId,t.exitElement.classList.add("dn-exit-position"),t.exitElement.innerText="End of data structure.",t.exitElement.setAttribute("aria-label","End of data structure."),t.exitElement.setAttribute("role","note"),t.exitElement.setAttribute("tabindex","-1"),t.exitElement.style.display="none",t.exitElement.addEventListener("focus",d=>{var c,y;t.exitElement.style.display="block",t.clearStructure(),(y=(c=e.exitElement)==null?void 0:c.callbacks)!=null&&y.focus&&e.exitElement.callbacks.focus(d)}),t.exitElement.addEventListener("blur",d=>{var c,y;t.exitElement.style.display="none",(y=(c=e.exitElement)==null?void 0:c.callbacks)!=null&&y.blur&&e.exitElement.callbacks.blur(d)}),t.root.appendChild(t.exitElement)),m=!0,t.root},t.render=l=>{let d=l.renderId+"",c=e.elementData[d];if(!c){console.warn(`Render data not found with renderId: ${d}. Failed to render.`);return}if(!m){console.error("render() was called before initialize(), renderer must be initialized first.");return}let y=!1,B={},s=(u,g,p)=>{var C;let f=c[u]||n[u],A=p&&y?B[g]:f==null?void 0:f[g],D=(C=n[u])==null?void 0:C[g];return typeof f=="function"?f(c,l.datum):typeof A=="function"?A(c,l.datum):A||D||(g?void 0:f)};y=s("existingElement","useForSpatialProperties"),B=s("existingElement","spatialProperties");let L=parseFloat(s("spatialProperties","width",!0)||0),P=parseFloat(s("spatialProperties","height",!0)||0),h=parseFloat(s("spatialProperties","x",!0)||0),E=parseFloat(s("spatialProperties","y",!0)||0),a=document.createElement(s("parentSemantics","elementType")),k=s("parentSemantics","attributes");typeof k=="object"&&Object.keys(k).forEach(u=>{a.setAttribute(u,k[u])}),a.setAttribute("role",s("parentSemantics","role")),a.id=d,a.classList.add("dn-node"),a.classList.add(s("cssClass")),a.style.width=L+"px",a.style.height=P+"px",a.style.left=h+"px",a.style.top=E+"px",a.setAttribute("tabindex","0"),a.addEventListener("focus",r),a.addEventListener("blur",i);let x=document.createElement(s("semantics","elementType")),v=s("semantics","attributes");typeof v=="object"&&Object.keys(v).forEach(u=>{a.setAttribute(u,v[u])}),x.setAttribute("role",s("semantics","role")),x.classList.add("dn-node-text"),c.showText&&(x.innerText=c.semantics.label);let S=s("semantics","label");S||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),x.setAttribute("aria-label",S),a.appendChild(x);let R=s("spatialProperties","path");if(R){let u=L+h+10,g=P+E+10,p=document.createElementNS("http://www.w3.org/2000/svg","svg");p.setAttribute("width",u+""),p.setAttribute("height",g+""),p.setAttribute("viewBox",`0 0 ${u} ${g}`),p.style.left=-h+"px",p.style.top=-E+"px",p.classList.add("dn-node-svg"),p.setAttribute("role","presentation"),p.setAttribute("focusable","false");let f=document.createElementNS("http://www.w3.org/2000/svg","path");f.setAttribute("d",R),f.classList.add("dn-node-path"),p.appendChild(f),a.appendChild(p)}return t.wrapper.appendChild(a),a},t.remove=l=>{let d=document.getElementById(l);t.wrapper.getAttribute("aria-activedescendant")===l&&t.wrapper.setAttribute("aria-activedescendant",""),d&&(d.removeEventListener("focus",r),d.removeEventListener("blur",i),d.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(l=>{t.entryButton&&t.entryButton===l||t.remove(l.id)})},t};
package/dist/rendering.js CHANGED
@@ -1 +1 @@
1
- import{j as m}from"./chunk-MPFBSVCV.js";var I=t=>{let w=a=>{e.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},g=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},f=!1,n={cssClass:m.cssClass,spatialProperties:{...m.spatialProperties},semantics:{...m.semantics},parentSemantics:{...m.parentSemantics},existingElement:{...m.existingElement}};return t.defaults&&(n.cssClass=t.defaults.cssClass||n.cssClass,n.spatialProperties=t.defaults.spatialProperties?{...n.spatialProperties,...t.defaults.spatialProperties}:n.spatialProperties,n.semantics=t.defaults.semantics?{...n.semantics,...t.defaults.semantics}:n.semantics,n.parentSemantics=t.defaults.parentSemantics?{...n.parentSemantics,...t.defaults.parentSemantics}:n.parentSemantics,n.existingElement=t.defaults.existingElement?{...n.existingElement,...t.defaults.existingElement}:n.existingElement),e.initialize=()=>{if(f){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",a=>{e.exitElement.style.display="block",e.clearStructure(),t.exitElement?.callbacks?.focus&&t.exitElement.callbacks.focus(a)}),e.exitElement.addEventListener("blur",a=>{e.exitElement.style.display="none",t.exitElement?.callbacks?.blur&&t.exitElement.callbacks.blur(a)}),e.root.appendChild(e.exitElement)),f=!0,e.root},e.render=a=>{let d=a.renderId+"",u=t.elementData[d];if(!u){console.warn(`Render data not found with renderId: ${d}. Failed to render.`);return}if(!f){console.error("render() was called before initialize(), renderer must be initialized first.");return}let v=!1,A={},s=(i,o,l)=>{let c=u[i]||n[i],h=l&&v?A[o]:c?.[o],S=n[i]?.[o];return typeof c=="function"?c(u,a.datum):typeof h=="function"?h(u,a.datum):h||S||(o?void 0:c)};v=s("existingElement","useForSpatialProperties"),A=s("existingElement","spatialProperties");let B=parseFloat(s("spatialProperties","width",!0)||0),k=parseFloat(s("spatialProperties","height",!0)||0),b=parseFloat(s("spatialProperties","x",!0)||0),x=parseFloat(s("spatialProperties","y",!0)||0),r=document.createElement(s("parentSemantics","elementType")),E=s("parentSemantics","attributes");typeof E=="object"&&Object.keys(E).forEach(i=>{r.setAttribute(i,E[i])}),r.setAttribute("role",s("parentSemantics","role")),r.id=d,r.classList.add("dn-node"),r.classList.add(s("cssClass")),r.style.width=B+"px",r.style.height=k+"px",r.style.left=b+"px",r.style.top=x+"px",r.setAttribute("tabindex","0"),r.addEventListener("focus",w),r.addEventListener("blur",g);let p=document.createElement(s("semantics","elementType")),y=s("semantics","attributes");typeof y=="object"&&Object.keys(y).forEach(i=>{r.setAttribute(i,y[i])}),p.setAttribute("role",s("semantics","role")),p.classList.add("dn-node-text"),u.showText&&(p.innerText=u.semantics.label);let L=s("semantics","label");L||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),p.setAttribute("aria-label",L),r.appendChild(p);let P=s("spatialProperties","path");if(P){let i=B+b+10,o=k+x+10,l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("width",i+""),l.setAttribute("height",o+""),l.setAttribute("viewBox",`0 0 ${i} ${o}`),l.style.left=-b+"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",P),c.classList.add("dn-node-path"),l.appendChild(c),r.appendChild(l)}return e.wrapper.appendChild(r),r},e.remove=a=>{let d=document.getElementById(a);e.wrapper.getAttribute("aria-activedescendant")===a&&e.wrapper.setAttribute("aria-activedescendant",""),d&&(d.removeEventListener("focus",w),d.removeEventListener("blur",g),d.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(a=>{e.entryButton&&e.entryButton===a||e.remove(a.id)})},e};export{I as default};
1
+ import{j as f}from"./chunk-MPFBSVCV.js";import{a as i}from"./chunk-RGY6OTGO.js";var N=t=>{let v=s=>{e.wrapper.setAttribute("aria-activedescendant",s.srcElement.id)},A=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},x=!1,n={cssClass:f.cssClass,spatialProperties:i({},f.spatialProperties),semantics:i({},f.semantics),parentSemantics:i({},f.parentSemantics),existingElement:i({},f.existingElement)};return t.defaults&&(n.cssClass=t.defaults.cssClass||n.cssClass,n.spatialProperties=t.defaults.spatialProperties?i(i({},n.spatialProperties),t.defaults.spatialProperties):n.spatialProperties,n.semantics=t.defaults.semantics?i(i({},n.semantics),t.defaults.semantics):n.semantics,n.parentSemantics=t.defaults.parentSemantics?i(i({},n.parentSemantics),t.defaults.parentSemantics):n.parentSemantics,n.existingElement=t.defaults.existingElement?i(i({},n.existingElement),t.defaults.existingElement):n.existingElement),e.initialize=()=>{var s;if(x){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),(s=t.exitElement)!=null&&s.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",l=>{var d,m;e.exitElement.style.display="block",e.clearStructure(),(m=(d=t.exitElement)==null?void 0:d.callbacks)!=null&&m.focus&&t.exitElement.callbacks.focus(l)}),e.exitElement.addEventListener("blur",l=>{var d,m;e.exitElement.style.display="none",(m=(d=t.exitElement)==null?void 0:d.callbacks)!=null&&m.blur&&t.exitElement.callbacks.blur(l)}),e.root.appendChild(e.exitElement)),x=!0,e.root},e.render=s=>{let l=s.renderId+"",d=t.elementData[l];if(!d){console.warn(`Render data not found with renderId: ${l}. Failed to render.`);return}if(!x){console.error("render() was called before initialize(), renderer must be initialized first.");return}let m=!1,B={},a=(c,p,o)=>{var C;let u=d[c]||n[c],g=o&&m?B[p]:u==null?void 0:u[p],I=(C=n[c])==null?void 0:C[p];return typeof u=="function"?u(d,s.datum):typeof g=="function"?g(d,s.datum):g||I||(p?void 0:u)};m=a("existingElement","useForSpatialProperties"),B=a("existingElement","spatialProperties");let k=parseFloat(a("spatialProperties","width",!0)||0),L=parseFloat(a("spatialProperties","height",!0)||0),E=parseFloat(a("spatialProperties","x",!0)||0),y=parseFloat(a("spatialProperties","y",!0)||0),r=document.createElement(a("parentSemantics","elementType")),h=a("parentSemantics","attributes");typeof h=="object"&&Object.keys(h).forEach(c=>{r.setAttribute(c,h[c])}),r.setAttribute("role",a("parentSemantics","role")),r.id=l,r.classList.add("dn-node"),r.classList.add(a("cssClass")),r.style.width=k+"px",r.style.height=L+"px",r.style.left=E+"px",r.style.top=y+"px",r.setAttribute("tabindex","0"),r.addEventListener("focus",v),r.addEventListener("blur",A);let b=document.createElement(a("semantics","elementType")),w=a("semantics","attributes");typeof w=="object"&&Object.keys(w).forEach(c=>{r.setAttribute(c,w[c])}),b.setAttribute("role",a("semantics","role")),b.classList.add("dn-node-text"),d.showText&&(b.innerText=d.semantics.label);let P=a("semantics","label");P||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),b.setAttribute("aria-label",P),r.appendChild(b);let S=a("spatialProperties","path");if(S){let c=k+E+10,p=L+y+10,o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width",c+""),o.setAttribute("height",p+""),o.setAttribute("viewBox",`0 0 ${c} ${p}`),o.style.left=-E+"px",o.style.top=-y+"px",o.classList.add("dn-node-svg"),o.setAttribute("role","presentation"),o.setAttribute("focusable","false");let u=document.createElementNS("http://www.w3.org/2000/svg","path");u.setAttribute("d",S),u.classList.add("dn-node-path"),o.appendChild(u),r.appendChild(o)}return e.wrapper.appendChild(r),r},e.remove=s=>{let l=document.getElementById(s);e.wrapper.getAttribute("aria-activedescendant")===s&&e.wrapper.setAttribute("aria-activedescendant",""),l&&(l.removeEventListener("focus",v),l.removeEventListener("blur",A),l.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(s=>{e.entryButton&&e.entryButton===s||e.remove(s.id)})},e};export{N as default};
@@ -1 +1 @@
1
- function e(e,i){if(i==null||i>e.length)i=e.length;for(var n=0,t=new Array(i);n<i;n++)t[n]=e[n];return t}function i(i){if(Array.isArray(i))return e(i)}function n(e,i,n){if(i in e){Object.defineProperty(e,i,{value:n,enumerable:true,configurable:true,writable:true})}else{e[i]=n}return e}function t(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function o(){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 r(e){for(var i=1;i<arguments.length;i++){var t=arguments[i]!=null?arguments[i]:{};var o=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}o.forEach(function(i){n(e,i,t[i])})}return e}function s(e,i){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);if(i){t=t.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})}n.push.apply(n,t)}return n}function a(e,i){i=i!=null?i:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(i))}else{s(Object(i)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))})}return e}function d(e){return i(e)||t(e)||c(e)||o()}function u(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function c(i,n){if(!i)return;if(typeof i==="string")return e(i,n);var t=Object.prototype.toString.call(i).slice(8,-1);if(t==="Object"&&i.constructor)t=i.constructor.name;if(t==="Map"||t==="Set")return Array.from(t);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return e(i,n)}var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=function e(e,i){for(var n in i)l(e,n,{get:i[n],enumerable:!0})},p=function e(e,i,n,t){var o=true,r=false,s=undefined;if(i&&(typeof i==="undefined"?"undefined":u(i))=="object"||typeof i=="function")try{var a=function(){var o=c.value;!g.call(e,o)&&o!==n&&l(e,o,{get:function e(){return i[o]},enumerable:!(t=v(i,o))||t.enumerable})};for(var d=f(i)[Symbol.iterator](),c;!(o=(c=d.next()).done);o=true)a()}catch(e){r=true;s=e}finally{try{if(!o&&d.return!=null){d.return()}}finally{if(r){throw s}}}return e};var m=function e(e){return p(l({},"__esModule",{value:!0}),e)};var h={};y(h,{addSimpleDataIDs:function e(){return S},buildEdges:function e(){return P},buildNodeStructureFromVegaLite:function e(){return _},buildNodes:function e(){return x},buildRules:function e(){return L},buildStructure:function e(){return F},default:function e(){return w},scaffoldDimensions:function e(){return D}});module.exports=m(h);var b={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var O=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var k=[["LeftBracket","RightBracket"],["Slash","Backslash"]],E={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}},K=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var I={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var R=function e(e,i){var n=Object.keys(e),t="";return n.forEach(function(n){t+="".concat(i&&i.omitKeyNames?"":n+": ").concat(e[n],". ")}),t+=i&&i.semanticLabel||"Data point.",t},j=function e(e){return"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_")};var w=function e(e){return e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?_(e):F(e)},_=function e(e){var i=I,n={},t={},o={},r=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:function(){return!0},a=e.itemInclusionCriteria?e.itemInclusionCriteria:function(){return!0},d=e.datumInclusionCriteria?e.datumInclusionCriteria:function(){return!0},u=e.vegaLiteView._renderer._origin,c=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],l=function e(e,i){if(e["data-navigator-id"])return e["data-navigator-id"];var n="dn-node-".concat(i,"-").concat(r);return r++,e["data-navigator-id"]=n,n},v=function i(i){var o=n[i],r=o.index,s=o.level,a=o.parent,d=[],u=a.items[r-1];if(u){var c=l(u,s);if(n[c]){var v="".concat(c,"-").concat(o.id);d.push(v),t[v]||(t[v]={source:c,target:o.id,navigationRules:["left","right"]})}}var f=a.items[r+1];if(f){var g=l(f,s);if(n[g]){var y="".concat(o.id,"-").concat(g);d.push(y),t[y]||(t[y]={source:o.id,target:g,navigationRules:["left","right"]})}}if(s==="group"&&a.items[r].items){var p=(a.items[r].items[0].mark.items[0].items||a.items[r].items)[0],m=l(p,"item");if(n[m]){var h="".concat(o.id,"-").concat(m);d.push(h),t[h]||(t[h]={source:o.id,target:m,navigationRules:["parent","child"]})}}else if(s==="item"){var b=l(a,"group");if(n[b]){var O="".concat(b,"-").concat(o.id);d.push(O),t[O]||(t[O]={source:b,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(d.push("any-exit"),t["any-exit"]||(t["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),d.push("any-undo"),t["any-undo"]||(t["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),d},f=function i(i,t,r,s,a){var u=l(i,t),c="render-"+u,v=r||[0,0];n[u]={},n[u].d={},n[u].id=u,n[u].renderId=c,n[u].index=s,n[u].level=t,n[u].parent=a,o[c]={},o[c].renderId=c,o[c].spatialProperties={},o[c].spatialProperties.x=i.bounds.x1+v[0],o[c].spatialProperties.y=i.bounds.y1+v[1],o[c].spatialProperties.width=i.bounds.x2-i.bounds.x1,o[c].spatialProperties.height=i.bounds.y2-i.bounds.y1,o[c].cssClass="dn-vega-lite-node",i.datum&&Object.keys(i.datum).forEach(function(o){var r=i.datum[o];d(o,r,i.datum,t,e.vegaLiteSpec)&&(n[u].d[e.keyRenamingHash&&e.keyRenamingHash[o]?e.keyRenamingHash[o]:o]=r)}),o[c].semantics={},o[c].semantics.label=e.nodeDescriber?e.nodeDescriber(n[u].d,i,t):R(n[u].d)},g=0;return c.items.forEach(function(i){if(s(i,g,e.vegaLiteSpec)){f(i,"group",u,g,c);var n=0,t=i.items[0].mark.items[0].items?i.items[0].mark.items[0]:i;t.items.forEach(function(o){a(o,n,i,e.vegaLiteSpec)&&f(o,"item",u,n,t),n++})}g++}),Object.keys(n).forEach(function(e){n[e].edges=v(e)}),{nodes:n,edges:t,elementData:o,navigationRules:i}},S=function e(e){var i=0,n={};e.data.forEach(function(t){var o=typeof e.idKey=="function"?e.idKey(t):e.idKey;t[o]="_"+i,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(function(e){e in t&&(typeof t[e]=="string"?(n[e]||(n[e]=0),n[t[e]]||(n[t[e]]=0),t[o]+="_"+e+n[e]+"_"+t[e]+n[t[e]],n[e]++,n[t[e]]++):(n[e]||(n[e]=0),t[o]+="_"+e+n[e],n[e]++))}),i++})},x=function e(e){var i={};return e.data.forEach(function(n){e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");var t=typeof e.idKey=="function"?e.idKey(n):e.idKey,o=n[t];if(!o){console.error("Building nodes. Each datum in options.data must contain an id. When matching the id key string ".concat(t,", this datum has no id: ").concat(JSON.stringify(n),"."));return}if(i[o]){console.error("Building nodes. Each id for data in options.data must be unique. This id is not unique: ".concat(o,"."));return}else{var r=typeof e.renderIdKey=="function"?e.renderIdKey(n):e.renderIdKey;i[o]={id:o,edges:[],renderId:r?n[r]||"":n.renderIdKey||"",data:n}}}),i},D=function e(e,i){var n,t;var o={};if((t=e.dimensions)===null||t===void 0?void 0:(n=t.parentOptions)===null||n===void 0?void 0:n.addLevel0){var s=e.dimensions.parentOptions.addLevel0;i[s.id]=a(r({},s),{dimensionLevel:0})}var c=d(K),l=function e(e,i){var n=i.numericalExtents[0],t=i.numericalExtents[1];i.numericalExtents[0]=n<e?n:e,i.numericalExtents[1]=t>e?t:e};return e.data.forEach(function(n){var t=e.dimensions.values||[],s=0;t.forEach(function(t){if(!t.dimensionKey){console.error("Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ".concat(JSON.stringify(t),"."));return}if(t.dimensionKey in n){var a;var v=n[t.dimensionKey],f=typeof((a=t.operations)===null||a===void 0?void 0:a.filterFunction)=="function"?t.operations.filterFunction(n,t):!0;if(v!==void 0&&f){if(t.type||(t.type=(typeof v==="undefined"?"undefined":u(v))=="bigint"||typeof v=="number"?"numerical":"categorical"),!o[t.dimensionKey]){var g,y;var p=typeof t.nodeId=="function"?t.nodeId(t,e.data):t.nodeId||j(t.dimensionKey),m=typeof t.renderId=="function"?t.renderId(t,e.data):t.renderId||p;o[t.dimensionKey]={dimensionKey:t.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:t.type,operations:{compressSparseDivisions:((g=t.operations)===null||g===void 0?void 0:g.compressSparseDivisions)||!1,sortFunction:((y=t.operations)===null||y===void 0?void 0:y.sortFunction)||void 0},behavior:t.behavior||{extents:"circular"},navigationRules:t.navigationRules||{sibling_sibling:c.length?d(c.shift()):["previous_"+t.dimensionKey,"next_"+t.dimensionKey],parent_child:["parent_"+t.dimensionKey,"child"]}},i[p]={id:p,renderId:m,derivedNode:t.dimensionKey,edges:[],dimensionLevel:1,data:o[t.dimensionKey],renderingStrategy:t.renderingStrategy||"singleSquare"}}var h=o[t.dimensionKey],b=null;if(t.type==="categorical"){var O;var k=typeof((O=t.divisionOptions)===null||O===void 0?void 0:O.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(t.dimensionKey,v,s):j(h.nodeId+"_"+v);if(b=h.divisions[k],!b){var E,K,I;b=h.divisions[k]={id:k,sortFunction:((E=t.divisionOptions)===null||E===void 0?void 0:E.sortFunction)||void 0,values:{}};var R=typeof((K=t.divisionOptions)===null||K===void 0?void 0:K.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(t.dimensionKey,v,s):k;i[k]={id:k,renderId:R,derivedNode:t.dimensionKey,edges:[],dimensionLevel:2,data:r({},b),renderingStrategy:((I=t.divisionOptions)===null||I===void 0?void 0:I.renderingStrategy)||"singleSquare"},i[k].data[t.dimensionKey]=v}}else{var w;b=h.divisions[h.nodeId],b||(b=h.divisions[h.nodeId]={id:h.nodeId,sortFunction:((w=t.divisionOptions)===null||w===void 0?void 0:w.sortFunction)||void 0,values:{}}),t.operations||(t.operations={});var _=t.operations.createNumericalSubdivisions;h.subdivisions=typeof _=="number"&&_<1?1:_||1,_!==1&&(h.divisionOptions||(h.divisionOptions=t.divisionOptions),l(v,h))}var S=typeof e.idKey=="function"?e.idKey(n):e.idKey;b.values[n[S]]=n}}s++})}),Object.keys(o).forEach(function(e){var n;var t=o[e],r=t.divisions;if(t.type==="numerical"){r[t.nodeId].values=Object.fromEntries(Object.entries(r[t.nodeId].values).sort(function(i,n){var o;return typeof((o=t.operations)===null||o===void 0?void 0:o.sortFunction)=="function"?t.operations.sortFunction(i[1],n[1],t):i[1][e]-n[1][e]}));var s=r[t.nodeId].values;if(t.numericalExtents[0]!==1/0&&t.subdivisions!==1){var a=Object.keys(s),d=typeof t.subdivisions=="function"?t.subdivisions(e,s):t.subdivisions,u=(t.numericalExtents[1]-t.numericalExtents[0])/d,c=t.numericalExtents[0]+u,l=0,v=0;for(c=t.numericalExtents[0]+u;c<=t.numericalExtents[1];c+=u){var f,g,y,p;var m=typeof((f=t.divisionOptions)===null||f===void 0?void 0:f.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(e,c,c):t.nodeId+"_"+c;t.divisions[m]={id:m,sortFunction:((g=t.divisionOptions)===null||g===void 0?void 0:g.sortFunction)||void 0,values:{}};var h=typeof((y=t.divisionOptions)===null||y===void 0?void 0:y.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(e,c,c):m;i[m]={id:m,renderId:h,derivedNode:e,edges:[],data:t.divisions[m],dimensionLevel:2,renderingStrategy:((p=t.divisionOptions)===null||p===void 0?void 0:p.renderingStrategy)||"singleSquare"};var b=!1;for(;!b&&v<a.length;){var O=s[a[v]];O[e]<=c?t.divisions[m].values[O.id]=O:(c+=u,b=!0),v++}l++}delete r[e]}}else typeof((n=t.operations)===null||n===void 0?void 0:n.sortFunction)=="function"&&(t.divisions=Object.fromEntries(Object.entries(r).sort(function(e,i){return t.operations.sortFunction(e[1],i[1],t)})));Object.keys(t.divisions).forEach(function(e){var i=t.divisions[e];typeof i.sortFunction=="function"&&(i.values=Object.fromEntries(Object.entries(i.values).sort(function(e,n){return i.sortFunction(e[1],n[1],i)})))})}),Object.keys(o).forEach(function(e){var n=o[e];if(n.operations.compressSparseDivisions){var t=Object.keys(n.divisions),s={},a=!0;if(t.forEach(function(e){var i=n.divisions[e],t=Object.keys(i.values);t.length<=1?t.forEach(function(e){s[e]=r({},i.values[e])}):a=!1}),a){var d={id:n.nodeId,values:s};t.forEach(function(e){delete i[e]}),n.divisions={},n.divisions[n.nodeId]=d}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},P=function e(e,i,n){var t={},o=function e(e,n){i[e].edges.indexOf(n)===-1&&i[e].edges.push(n)},r=function i(i,n,r,s){var a="".concat(i,"-").concat(n),u=e.useDirectedEdges?"".concat(n,"-").concat(a):a,c=!s||s==="source",l=!s||s==="target",v=function e(e){var o;t[e]?(o=t[e].navigationRules).push.apply(o,d(r||[])):t[e]={source:i,target:n,navigationRules:r?d(r):[]}};v(a),e.useDirectedEdges&&l&&v(u),c&&o(i,a),l&&o(n,u)};if(n&&Object.keys(n).length){var s,a,u,c,l,v,f,g,y,p;var m=Object.keys(n),h=(u=e.dimensions)===null||u===void 0?void 0:(a=u.parentOptions)===null||a===void 0?void 0:(s=a.level1Options)===null||s===void 0?void 0:s.order,b=h||m,O=0,k=((c=e.dimensions)===null||c===void 0?void 0:c.parentOptions)||{},E=((v=k.level1Options)===null||v===void 0?void 0:(l=v.behavior)===null||l===void 0?void 0:l.extents)||"terminal",K=k.addLevel0,I=K?((g=k.level1Options)===null||g===void 0?void 0:(f=g.navigationRules)===null||f===void 0?void 0:f.parent_child)||["parent","child"]:[],R=((p=k.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.sibling_sibling)||["left","right"],j=typeof b[0]=="string"?h?i[b[0]]:i[n[b[0]].nodeId]:b[0];K&&r(K.id,j.id,I,"source"),b.forEach(function(t){var o=typeof t=="string"?h?i[t]:i[n[t].nodeId]:t;if(o===t&&!i[o.id]&&(i[o.id]=o),K&&(e.useDirectedEdges?r(o.id,K.id,I,"source"):r(K.id,o.id,I,"target")),O===b.length-1&&E==="circular")r(o.id,j.id,R);else if(O===b.length-1&&E==="bridgedCustom")r(o.id,k.level1Options.behavior.customBridgePost,R);else if(O<b.length-1){var s=typeof b[O+1]=="string"?h?i[b[O+1]]:i[n[b[O+1]].nodeId]:b[O+1];r(o.id,s.id,R)}!O&&E==="bridgedCustom"&&r(k.level1Options.behavior.customBridgePost,o.id,R),O++}),m.forEach(function(i){var t,o,s,a;var d=n[i],u=((t=d.behavior)===null||t===void 0?void 0:t.childmostNavigation)||"within",c=function e(e,i,n,t){return t.values[Object.keys(t.values)[e]]||void 0},l=u==="across"&&((o=d.behavior)===null||o===void 0?void 0:o.childmostMatching)?(s=d.behavior)===null||s===void 0?void 0:s.childmostMatching:c,v=((a=d.behavior)===null||a===void 0?void 0:a.extents)||"circular";d.divisions||console.error("Parsing dimensions. The dimension using the key ".concat(i," is missing the divisions property. dimension.divisions should be supplied. ").concat(JSON.stringify(d),"."));var f=Object.keys(d.divisions),g=d.divisions[f[0]];if(f.length!==1)r(d.nodeId,g.id,d.navigationRules.parent_child,"source");else{var y=Object.keys(g.values),p=typeof e.idKey=="function"?e.idKey(g.values[y[0]]):e.idKey;r(d.nodeId,g.values[y[0]][p],d.navigationRules.parent_child,"source")}var m=0;f.forEach(function(i){var n=d.divisions[i];m===f.length-1&&(v==="circular"||v==="bridgedCousins"||v==="bridgedCustom")?r(n.id,d.divisions[f[0]].id,d.navigationRules.sibling_sibling):m<f.length-1&&r(n.id,d.divisions[f[m+1]].id,d.navigationRules.sibling_sibling);var t=Object.keys(n.values);e.useDirectedEdges?r(n.id,d.nodeId,d.navigationRules.parent_child,"source"):r(d.nodeId,n.id,d.navigationRules.parent_child,"target");var o=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(n.id,n.values[t[0]][o],d.navigationRules.parent_child,"source");var s=0;t.length>1&&t.forEach(function(i){var o=n.values[i],a=typeof e.idKey=="function"?e.idKey(o):e.idKey,c=f.length!==1?n.id:d.nodeId;if(e.useDirectedEdges?r(o[a],c,d.navigationRules.parent_child,"source"):r(c,o[a],d.navigationRules.parent_child,"target"),u==="within"){if(s===t.length-1&&v==="circular"){var g=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(o[a],n.values[t[0]][g],d.navigationRules.sibling_sibling)}else if(s===t.length-1&&v==="bridgedCousins")if(m!==f.length-1){var y=typeof e.idKey=="function"?e.idKey(d.divisions[f[m+1]].values[t[0]]):e.idKey;r(o[a],d.divisions[f[m+1]].values[t[0]][y],d.navigationRules.sibling_sibling)}else{var p=typeof e.idKey=="function"?e.idKey(d.divisions[f[0]].values[t[0]]):e.idKey;r(o[a],d.divisions[f[0]].values[t[0]][p],d.navigationRules.sibling_sibling)}else if(s===t.length-1&&v==="bridgedCustom")r(o[a],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(s<t.length-1){var h=typeof e.idKey=="function"?e.idKey(n.values[t[s+1]]):e.idKey;r(o[a],n.values[t[s+1]][h],d.navigationRules.sibling_sibling)}if(!s&&v==="bridgedCousins")if(m!==0){var b=typeof e.idKey=="function"?e.idKey(d.divisions[f[m-1]].values[t[t.length-1]]):e.idKey;r(d.divisions[f[m-1]].values[t[t.length-1]][b],o[a],d.navigationRules.sibling_sibling)}else{var O=typeof e.idKey=="function"?e.idKey(d.divisions[f[f.length-1]].values[t[t.length-1]]):e.idKey;r(d.divisions[f[f.length-1]].values[t[t.length-1]][O],o[a],d.navigationRules.sibling_sibling)}else!s&&v==="bridgedCustom"&&r(d.behavior.customBridgePrevious,o[a],d.navigationRules.sibling_sibling)}else if(m===f.length-1&&v==="bridgedCustom")r(o[a],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(!m&&v==="bridgedCustom")r(d.behavior.customBridgePrevious,o[a],d.navigationRules.sibling_sibling);else{var k=m===f.length-1&&v==="circular"?d.divisions[f[0]]:d.divisions[f[m+1]];if(k){var E=l(s,o[a],n,k);if(E){var K=typeof e.idKey=="function"?e.idKey(E):e.idKey;r(o[a],E[K],d.navigationRules.sibling_sibling)}}}s++}),m++})})}return Object.keys(i).forEach(function(n){var o;var r=i[n];((o=e.genericEdges)===null||o===void 0?void 0:o.length)&&e.genericEdges.forEach(function(e){t[e.edgeId]||(t[e.edgeId]=e.edge),(!e.conditional||e.conditional&&e.conditional(r,e))&&r.edges.push(e.edgeId)})}),t},L=function e(e,i,n){var t=e.navigationRules;if(!t){var o=Object.keys(n||{});o.length>6&&console.error("Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ".concat(o.length,". Dimensions counted: ").concat(o.join(", "),"."));var s={},a={},u={},c=d(k),l=d(O),v=function i(i,n){var t=i&&n,o=!1,v=!1;if((s[i]||a[i])&&(a[i]=r({},s[i]),o=!0),n&&(s[n]||a[n])&&(a[n]=r({},s[n]),v=!0),t&&!o&&!v){c.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");var f=d(c.shift());l.splice(l.indexOf(f[0]),1),l.splice(l.indexOf(f[1]),1),a[i]={direction:e.useDirectedEdges?"target":"source",key:f[0]},a[n]={direction:"target",key:f[1]}}else{if(!a[i]&&l.length){var g=l.shift(),y=[];c.forEach(function(e){g!==e[0]&&g!==e[1]&&y.push(e)}),c=y,a[i]={direction:e.useDirectedEdges?"target":"source",key:g}}if(n&&!a[n]&&l.length){var p=l.shift(),m=[];c.forEach(function(e){p!==e[0]&&p!==e[1]&&m.push(e)}),c=m,a[n]={direction:"target",key:p}}l.length||(a[i]||(u[i]=i),n&&!a[n]&&(u[n]=n))}};if(Object.keys(E).forEach(function(i){var n=r({},E[i]);e.useDirectedEdges&&(n.direction="target"),s[i]=n}),o.length){var f,g;if((g=e.dimensions)===null||g===void 0?void 0:(f=g.parentOptions)===null||f===void 0?void 0:f.addLevel0){var y,p;var m=((p=e.dimensions.parentOptions.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.parent_child)||["parent","child"];v(m[0],m[1])}o.forEach(function(e){var i=n[e].navigationRules.parent_child,t=n[e].navigationRules.sibling_sibling;v(i[0],i[1]),v(t[0],t[1])})}if(Object.keys(i).forEach(function(e){i[e].navigationRules.forEach(function(e){a[e]||v(e)})}),Object.keys(u).length){var h={};Object.keys(a).forEach(function(e){h[a[e].key]=a[e].key}),Object.keys(s).forEach(function(e){!h[s[e].key]&&!b[s[e].key]&&l.push(s[e].key)});var K=r({},u);u={},Object.keys(K).forEach(function(e){v(e)}),Object.keys(u).length&&console.error("Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ".concat(Object.keys(u).join(", "),"."))}t=a}return t},F=function e(e){e.addIds&&S(e);var i=x(e),n=D(e,i),t=P(e,i,n),o=L(e,t,n);return{nodes:i,edges:t,dimensions:n,navigationRules:o}};0&&(module.exports={addSimpleDataIDs:addSimpleDataIDs,buildEdges:buildEdges,buildNodeStructureFromVegaLite:buildNodeStructureFromVegaLite,buildNodes:buildNodes,buildRules:buildRules,buildStructure:buildStructure,scaffoldDimensions:scaffoldDimensions});
1
+ var U=Object.defineProperty,pe=Object.defineProperties,me=Object.getOwnPropertyDescriptor,Oe=Object.getOwnPropertyDescriptors,Ke=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Q=(e,o,i)=>o in e?U(e,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[o]=i,F=(e,o)=>{for(var i in o||(o={}))X.call(o,i)&&Q(e,i,o[i]);if(z)for(var i of z(o))Ee.call(o,i)&&Q(e,i,o[i]);return e},ee=(e,o)=>pe(e,Oe(o));var Ie=(e,o)=>{for(var i in o)U(e,i,{get:o[i],enumerable:!0})},Re=(e,o,i,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let y of Ke(o))!X.call(e,y)&&y!==i&&U(e,y,{get:()=>o[y],enumerable:!(c=me(o,y))||c.enumerable});return e};var xe=e=>Re(U({},"__esModule",{value:!0}),e);var De={};Ie(De,{addSimpleDataIDs:()=>de,buildEdges:()=>ue,buildNodeStructureFromVegaLite:()=>ae,buildNodes:()=>le,buildRules:()=>ge,buildStructure:()=>fe,default:()=>je,scaffoldDimensions:()=>ce});module.exports=xe(De);var ie={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var te=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var ne=[["LeftBracket","RightBracket"],["Slash","Backslash"]],q={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}},se=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var re={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var oe=(e,o)=>{let i=Object.keys(e),c="";return i.forEach(y=>{c+=`${o&&o.omitKeyNames?"":y+": "}${e[y]}. `}),c+=o&&o.semanticLabel||"Data point.",c},J=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var je=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ae(e):fe(e),ae=e=>{let o=re,i={},c={},y={},d=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,p=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,a=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,m=e.vegaLiteView._renderer._origin,t=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,s)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let f=`dn-node-${s}-${d}`;return d++,n["data-navigator-id"]=f,f},x=n=>{let s=i[n],f=s.index,g=s.level,h=s.parent,l=[],v=h.items[f-1];if(v){let u=E(v,g);if(i[u]){let O=`${u}-${s.id}`;l.push(O),c[O]||(c[O]={source:u,target:s.id,navigationRules:["left","right"]})}}let D=h.items[f+1];if(D){let u=E(D,g);if(i[u]){let O=`${s.id}-${u}`;l.push(O),c[O]||(c[O]={source:s.id,target:u,navigationRules:["left","right"]})}}if(g==="group"&&h.items[f].items){let O=(h.items[f].items[0].mark.items[0].items||h.items[f].items)[0],k=E(O,"item");if(i[k]){let r=`${s.id}-${k}`;l.push(r),c[r]||(c[r]={source:s.id,target:k,navigationRules:["parent","child"]})}}else if(g==="item"){let u=E(h,"group");if(i[u]){let O=`${u}-${s.id}`;l.push(O),c[O]||(c[O]={source:u,target:s.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(l.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),l.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),l},K=(n,s,f,g,h)=>{let l=E(n,s),v="render-"+l,D=f||[0,0];i[l]={},i[l].d={},i[l].id=l,i[l].renderId=v,i[l].index=g,i[l].level=s,i[l].parent=h,y[v]={},y[v].renderId=v,y[v].spatialProperties={},y[v].spatialProperties.x=n.bounds.x1+D[0],y[v].spatialProperties.y=n.bounds.y1+D[1],y[v].spatialProperties.width=n.bounds.x2-n.bounds.x1,y[v].spatialProperties.height=n.bounds.y2-n.bounds.y1,y[v].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(u=>{let O=n.datum[u];a(u,O,n.datum,s,e.vegaLiteSpec)&&(i[l].d[e.keyRenamingHash&&e.keyRenamingHash[u]?e.keyRenamingHash[u]:u]=O)}),y[v].semantics={},y[v].semantics.label=e.nodeDescriber?e.nodeDescriber(i[l].d,n,s):oe(i[l].d)},j=0;return t.items.forEach(n=>{if(P(n,j,e.vegaLiteSpec)){K(n,"group",m,j,t);let s=0,f=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;f.items.forEach(g=>{p(g,s,n,e.vegaLiteSpec)&&K(g,"item",m,s,f),s++})}j++}),Object.keys(i).forEach(n=>{i[n].edges=x(n)}),{nodes:i,edges:c,elementData:y,navigationRules:o}},de=e=>{let o=0,i={};e.data.forEach(c=>{let y=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[y]="_"+o,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in c&&(typeof c[d]=="string"?(i[d]||(i[d]=0),i[c[d]]||(i[c[d]]=0),c[y]+="_"+d+i[d]+"_"+c[d]+i[c[d]],i[d]++,i[c[d]]++):(i[d]||(i[d]=0),c[y]+="_"+d+i[d],i[d]++))}),o++})},le=e=>{let o={};return e.data.forEach(i=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let c=typeof e.idKey=="function"?e.idKey(i):e.idKey,y=i[c];if(!y){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${c}, this datum has no id: ${JSON.stringify(i)}.`);return}if(o[y]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${y}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;o[y]={id:y,edges:[],renderId:d?i[d]||"":i.renderIdKey||"",data:i}}}),o},ce=(e,o)=>{var d,P;let i={};if((P=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&P.addLevel0){let p=e.dimensions.parentOptions.addLevel0;o[p.id]=ee(F({},p),{dimensionLevel:0})}let c=[...se],y=(p,a)=>{let m=a.numericalExtents[0],t=a.numericalExtents[1];a.numericalExtents[0]=m<p?m:p,a.numericalExtents[1]=t>p?t:p};return e.data.forEach(p=>{let a=e.dimensions.values||[],m=0;a.forEach(t=>{var E,x,K,j,b,n,s,f;if(!t.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(t)}.`);return}if(t.dimensionKey in p){let g=p[t.dimensionKey],h=typeof((E=t.operations)==null?void 0:E.filterFunction)=="function"?t.operations.filterFunction(p,t):!0;if(g!==void 0&&h){if(t.type||(t.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[t.dimensionKey]){let u=typeof t.nodeId=="function"?t.nodeId(t,e.data):t.nodeId||J(t.dimensionKey),O=typeof t.renderId=="function"?t.renderId(t,e.data):t.renderId||u;i[t.dimensionKey]={dimensionKey:t.dimensionKey,nodeId:u,divisions:{},numericalExtents:[1/0,-1/0],type:t.type,operations:{compressSparseDivisions:((x=t.operations)==null?void 0:x.compressSparseDivisions)||!1,sortFunction:((K=t.operations)==null?void 0:K.sortFunction)||void 0},behavior:t.behavior||{extents:"circular"},navigationRules:t.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+t.dimensionKey,"next_"+t.dimensionKey],parent_child:["parent_"+t.dimensionKey,"child"]}},o[u]={id:u,renderId:O,derivedNode:t.dimensionKey,edges:[],dimensionLevel:1,data:i[t.dimensionKey],renderingStrategy:t.renderingStrategy||"singleSquare"}}let l=i[t.dimensionKey],v=null;if(t.type==="categorical"){let u=typeof((j=t.divisionOptions)==null?void 0:j.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(t.dimensionKey,g,m):J(l.nodeId+"_"+g);if(v=l.divisions[u],!v){v=l.divisions[u]={id:u,sortFunction:((b=t.divisionOptions)==null?void 0:b.sortFunction)||void 0,values:{}};let O=typeof((n=t.divisionOptions)==null?void 0:n.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(t.dimensionKey,g,m):u;o[u]={id:u,renderId:O,derivedNode:t.dimensionKey,edges:[],dimensionLevel:2,data:F({},v),renderingStrategy:((s=t.divisionOptions)==null?void 0:s.renderingStrategy)||"singleSquare"},o[u].data[t.dimensionKey]=g}}else{v=l.divisions[l.nodeId],v||(v=l.divisions[l.nodeId]={id:l.nodeId,sortFunction:((f=t.divisionOptions)==null?void 0:f.sortFunction)||void 0,values:{}}),t.operations||(t.operations={});let u=t.operations.createNumericalSubdivisions;l.subdivisions=typeof u=="number"&&u<1?1:u||1,u!==1&&(l.divisionOptions||(l.divisionOptions=t.divisionOptions),y(g,l))}let D=typeof e.idKey=="function"?e.idKey(p):e.idKey;v.values[p[D]]=p}}m++})}),Object.keys(i).forEach(p=>{var E,x,K,j,b;let a=i[p],m=a.divisions;if(a.type==="numerical"){m[a.nodeId].values=Object.fromEntries(Object.entries(m[a.nodeId].values).sort((s,f)=>{var g;return typeof((g=a.operations)==null?void 0:g.sortFunction)=="function"?a.operations.sortFunction(s[1],f[1],a):s[1][p]-f[1][p]}));let n=m[a.nodeId].values;if(a.numericalExtents[0]!==1/0&&a.subdivisions!==1){let s=Object.keys(n),f=typeof a.subdivisions=="function"?a.subdivisions(p,n):a.subdivisions,h=(a.numericalExtents[1]-a.numericalExtents[0])/f,l=a.numericalExtents[0]+h,v=0,D=0;for(l=a.numericalExtents[0]+h;l<=a.numericalExtents[1];l+=h){let u=typeof((E=a.divisionOptions)==null?void 0:E.divisionNodeIds)=="function"?a.divisionOptions.divisionNodeIds(p,l,l):a.nodeId+"_"+l;a.divisions[u]={id:u,sortFunction:((x=a.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{}};let O=typeof((K=a.divisionOptions)==null?void 0:K.divisionRenderIds)=="function"?a.divisionOptions.divisionRenderIds(p,l,l):u;o[u]={id:u,renderId:O,derivedNode:p,edges:[],data:a.divisions[u],dimensionLevel:2,renderingStrategy:((j=a.divisionOptions)==null?void 0:j.renderingStrategy)||"singleSquare"};let k=!1;for(;!k&&D<s.length;){let r=n[s[D]];r[p]<=l?a.divisions[u].values[r.id]=r:(l+=h,k=!0),D++}v++}delete m[p]}}else typeof((b=a.operations)==null?void 0:b.sortFunction)=="function"&&(a.divisions=Object.fromEntries(Object.entries(m).sort((n,s)=>a.operations.sortFunction(n[1],s[1],a))));Object.keys(a.divisions).forEach(n=>{let s=a.divisions[n];typeof s.sortFunction=="function"&&(s.values=Object.fromEntries(Object.entries(s.values).sort((f,g)=>s.sortFunction(f[1],g[1],s))))})}),Object.keys(i).forEach(p=>{let a=i[p];if(a.operations.compressSparseDivisions){let m=Object.keys(a.divisions),t={},E=!0;if(m.forEach(x=>{let K=a.divisions[x],j=Object.keys(K.values);j.length<=1?j.forEach(b=>{t[b]=F({},K.values[b])}):E=!1}),E){let x={id:a.nodeId,values:t};m.forEach(K=>{delete o[K]}),a.divisions={},a.divisions[a.nodeId]=x}}}),e.dimensions.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},ue=(e,o,i)=>{var P,p,a,m,t,E,x,K,j,b;let c={},y=(n,s)=>{o[n].edges.indexOf(s)===-1&&o[n].edges.push(s)},d=(n,s,f,g)=>{let h=`${n}-${s}`,l=e.useDirectedEdges?`${s}-${h}`:h,v=!g||g==="source",D=!g||g==="target",u=O=>{c[O]?c[O].navigationRules.push(...f||[]):c[O]={source:n,target:s,navigationRules:f?[...f]:[]}};u(h),e.useDirectedEdges&&D&&u(l),v&&y(n,h),D&&y(s,l)};if(i&&Object.keys(i).length){let n=Object.keys(i),s=(a=(p=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:p.level1Options)==null?void 0:a.order,f=s||n,g=0,h=((m=e.dimensions)==null?void 0:m.parentOptions)||{},l=((E=(t=h.level1Options)==null?void 0:t.behavior)==null?void 0:E.extents)||"terminal",v=h.addLevel0,D=v?((K=(x=h.level1Options)==null?void 0:x.navigationRules)==null?void 0:K.parent_child)||["parent","child"]:[],u=((b=(j=h.level1Options)==null?void 0:j.navigationRules)==null?void 0:b.sibling_sibling)||["left","right"],O=typeof f[0]=="string"?s?o[f[0]]:o[i[f[0]].nodeId]:f[0];v&&d(v.id,O.id,D,"source"),f.forEach(k=>{let r=typeof k=="string"?s?o[k]:o[i[k].nodeId]:k;if(r===k&&!o[r.id]&&(o[r.id]=r),v&&(e.useDirectedEdges?d(r.id,v.id,D,"source"):d(v.id,r.id,D,"target")),g===f.length-1&&l==="circular")d(r.id,O.id,u);else if(g===f.length-1&&l==="bridgedCustom")d(r.id,h.level1Options.behavior.customBridgePost,u);else if(g<f.length-1){let A=typeof f[g+1]=="string"?s?o[f[g+1]]:o[i[f[g+1]].nodeId]:f[g+1];d(r.id,A.id,u)}!g&&l==="bridgedCustom"&&d(h.level1Options.behavior.customBridgePost,r.id,u),g++}),n.forEach(k=>{var M,H,W,Y;let r=i[k],A=((M=r.behavior)==null?void 0:M.childmostNavigation)||"within",ve=($,w,I,G)=>G.values[Object.keys(G.values)[$]]||void 0,ye=A==="across"&&((H=r.behavior)!=null&&H.childmostMatching)?(W=r.behavior)==null?void 0:W.childmostMatching:ve,L=((Y=r.behavior)==null?void 0:Y.extents)||"circular";r.divisions||console.error(`Parsing dimensions. The dimension using the key ${k} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(r)}.`);let R=Object.keys(r.divisions),T=r.divisions[R[0]];if(R.length!==1)d(r.nodeId,T.id,r.navigationRules.parent_child,"source");else{let $=Object.keys(T.values),w=typeof e.idKey=="function"?e.idKey(T.values[$[0]]):e.idKey;d(r.nodeId,T.values[$[0]][w],r.navigationRules.parent_child,"source")}let S=0;R.forEach($=>{let w=r.divisions[$];S===R.length-1&&(L==="circular"||L==="bridgedCousins"||L==="bridgedCustom")?d(w.id,r.divisions[R[0]].id,r.navigationRules.sibling_sibling):S<R.length-1&&d(w.id,r.divisions[R[S+1]].id,r.navigationRules.sibling_sibling);let I=Object.keys(w.values);e.useDirectedEdges?d(w.id,r.nodeId,r.navigationRules.parent_child,"source"):d(r.nodeId,w.id,r.navigationRules.parent_child,"target");let G=typeof e.idKey=="function"?e.idKey(w.values[I[0]]):e.idKey;d(w.id,w.values[I[0]][G],r.navigationRules.parent_child,"source");let B=0;I.length>=1&&I.forEach(he=>{let N=w.values[he],_=typeof e.idKey=="function"?e.idKey(N):e.idKey,Z=R.length!==1?w.id:r.nodeId;if(e.useDirectedEdges?d(N[_],Z,r.navigationRules.parent_child,"source"):d(Z,N[_],r.navigationRules.parent_child,"target"),A==="within"){if(B===I.length-1&&L==="circular"){let C=typeof e.idKey=="function"?e.idKey(w.values[I[0]]):e.idKey;d(N[_],w.values[I[0]][C],r.navigationRules.sibling_sibling)}else if(B===I.length-1&&L==="bridgedCousins")if(S!==R.length-1){let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[S+1]].values[I[0]]):e.idKey;d(N[_],r.divisions[R[S+1]].values[I[0]][C],r.navigationRules.sibling_sibling)}else{let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[0]].values[I[0]]):e.idKey;d(N[_],r.divisions[R[0]].values[I[0]][C],r.navigationRules.sibling_sibling)}else if(B===I.length-1&&L==="bridgedCustom")d(N[_],r.behavior.customBridgePost,r.navigationRules.sibling_sibling);else if(B<I.length-1){let C=typeof e.idKey=="function"?e.idKey(w.values[I[B+1]]):e.idKey;d(N[_],w.values[I[B+1]][C],r.navigationRules.sibling_sibling)}if(!B&&L==="bridgedCousins")if(S!==0){let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[S-1]].values[I[I.length-1]]):e.idKey;d(r.divisions[R[S-1]].values[I[I.length-1]][C],N[_],r.navigationRules.sibling_sibling)}else{let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[R.length-1]].values[I[I.length-1]]):e.idKey;d(r.divisions[R[R.length-1]].values[I[I.length-1]][C],N[_],r.navigationRules.sibling_sibling)}else!B&&L==="bridgedCustom"&&d(r.behavior.customBridgePrevious,N[_],r.navigationRules.sibling_sibling)}else if(S===R.length-1&&L==="bridgedCustom")d(N[_],r.behavior.customBridgePost,r.navigationRules.sibling_sibling);else if(!S&&L==="bridgedCustom")d(r.behavior.customBridgePrevious,N[_],r.navigationRules.sibling_sibling);else{let C=S===R.length-1&&L==="circular"?r.divisions[R[0]]:r.divisions[R[S+1]];if(C){let V=ye(B,N[_],w,C);if(V){let be=typeof e.idKey=="function"?e.idKey(V):e.idKey;d(N[_],V[be],r.navigationRules.sibling_sibling)}}}B++}),S++})})}return Object.keys(o).forEach(n=>{var f;let s=o[n];(f=e.genericEdges)!=null&&f.length&&e.genericEdges.forEach(g=>{c[g.edgeId]||(c[g.edgeId]=g.edge),(!g.conditional||g.conditional&&g.conditional(s,g))&&s.edges.push(g.edgeId)})}),c},ge=(e,o,i)=>{var y,d,P,p;let c=e.navigationRules;if(!c){let a=Object.keys(i||{});a.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${a.length}. Dimensions counted: ${a.join(", ")}.`);let m={},t={},E={},x=[...ne],K=[...te],j=(b,n)=>{let s=b&&n,f=!1,g=!1;if((m[b]||t[b])&&(t[b]=F({},m[b]),f=!0),n&&(m[n]||t[n])&&(t[n]=F({},m[n]),g=!0),s&&!f&&!g){x.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let h=[...x.shift()];K.splice(K.indexOf(h[0]),1),K.splice(K.indexOf(h[1]),1),t[b]={direction:e.useDirectedEdges?"target":"source",key:h[0]},t[n]={direction:"target",key:h[1]}}else{if(!t[b]&&K.length){let h=K.shift(),l=[];x.forEach(v=>{h!==v[0]&&h!==v[1]&&l.push(v)}),x=l,t[b]={direction:e.useDirectedEdges?"target":"source",key:h}}if(n&&!t[n]&&K.length){let h=K.shift(),l=[];x.forEach(v=>{h!==v[0]&&h!==v[1]&&l.push(v)}),x=l,t[n]={direction:"target",key:h}}K.length||(t[b]||(E[b]=b),n&&!t[n]&&(E[n]=n))}};if(Object.keys(q).forEach(b=>{let n=F({},q[b]);e.useDirectedEdges&&(n.direction="target"),m[b]=n}),a.length){if((d=(y=e.dimensions)==null?void 0:y.parentOptions)!=null&&d.addLevel0){let b=((p=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:p.parent_child)||["parent","child"];j(b[0],b[1])}a.forEach(b=>{let n=i[b].navigationRules.parent_child,s=i[b].navigationRules.sibling_sibling;j(n[0],n[1]),j(s[0],s[1])})}if(Object.keys(o).forEach(b=>{o[b].navigationRules.forEach(n=>{t[n]||j(n)})}),Object.keys(E).length){let b={};Object.keys(t).forEach(s=>{b[t[s].key]=t[s].key}),Object.keys(m).forEach(s=>{!b[m[s].key]&&!ie[m[s].key]&&K.push(m[s].key)});let n=F({},E);E={},Object.keys(n).forEach(s=>{j(s)}),Object.keys(E).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(E).join(", ")}.`)}c=t}return c},fe=e=>{e.addIds&&de(e);let o=le(e),i=ce(e,o),c=ue(e,o,i),y=ge(e,c,i);return{nodes:o,edges:c,dimensions:i,navigationRules:y}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
package/dist/structure.js CHANGED
@@ -1 +1 @@
1
- import{a as q,b as P}from"./chunk-YE5N6UCT.js";import{a as w,c as B,e as T,f as $,g as G,i as V}from"./chunk-MPFBSVCV.js";var ee=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?H(e):Q(e),H=e=>{let y=V,o={},u={},h={},t=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,g=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,n=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,l=e.vegaLiteView._renderer._origin,f=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],r=(d,i)=>{if(d["data-navigator-id"])return d["data-navigator-id"];let I=`dn-node-${i}-${t}`;return t++,d["data-navigator-id"]=I,I},a=d=>{let i=o[d],I=i.index,D=i.level,x=i.parent,m=[],v=x.items[I-1];if(v){let p=r(v,D);if(o[p]){let K=`${p}-${i.id}`;m.push(K),u[K]||(u[K]={source:p,target:i.id,navigationRules:["left","right"]})}}let S=x.items[I+1];if(S){let p=r(S,D);if(o[p]){let K=`${i.id}-${p}`;m.push(K),u[K]||(u[K]={source:i.id,target:p,navigationRules:["left","right"]})}}if(D==="group"&&x.items[I].items){let K=(x.items[I].items[0].mark.items[0].items||x.items[I].items)[0],E=r(K,"item");if(o[E]){let O=`${i.id}-${E}`;m.push(O),u[O]||(u[O]={source:i.id,target:E,navigationRules:["parent","child"]})}}else if(D==="item"){let p=r(x,"group");if(o[p]){let K=`${p}-${i.id}`;m.push(K),u[K]||(u[K]={source:p,target:i.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(m.push("any-exit"),u["any-exit"]||(u["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),m.push("any-undo"),u["any-undo"]||(u["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),m},b=(d,i,I,D,x)=>{let m=r(d,i),v="render-"+m,S=I||[0,0];o[m]={},o[m].d={},o[m].id=m,o[m].renderId=v,o[m].index=D,o[m].level=i,o[m].parent=x,h[v]={},h[v].renderId=v,h[v].spatialProperties={},h[v].spatialProperties.x=d.bounds.x1+S[0],h[v].spatialProperties.y=d.bounds.y1+S[1],h[v].spatialProperties.width=d.bounds.x2-d.bounds.x1,h[v].spatialProperties.height=d.bounds.y2-d.bounds.y1,h[v].cssClass="dn-vega-lite-node",d.datum&&Object.keys(d.datum).forEach(p=>{let K=d.datum[p];n(p,K,d.datum,i,e.vegaLiteSpec)&&(o[m].d[e.keyRenamingHash&&e.keyRenamingHash[p]?e.keyRenamingHash[p]:p]=K)}),h[v].semantics={},h[v].semantics.label=e.nodeDescriber?e.nodeDescriber(o[m].d,d,i):q(o[m].d)},c=0;return f.items.forEach(d=>{if(s(d,c,e.vegaLiteSpec)){b(d,"group",l,c,f);let i=0,I=d.items[0].mark.items[0].items?d.items[0].mark.items[0]:d;I.items.forEach(D=>{g(D,i,d,e.vegaLiteSpec)&&b(D,"item",l,i,I),i++})}c++}),Object.keys(o).forEach(d=>{o[d].edges=a(d)}),{nodes:o,edges:u,elementData:h,navigationRules:y}},J=e=>{let y=0,o={};e.data.forEach(u=>{let h=typeof e.idKey=="function"?e.idKey(u):e.idKey;u[h]="_"+y,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(t=>{t in u&&(typeof u[t]=="string"?(o[t]||(o[t]=0),o[u[t]]||(o[u[t]]=0),u[h]+="_"+t+o[t]+"_"+u[t]+o[u[t]],o[t]++,o[u[t]]++):(o[t]||(o[t]=0),u[h]+="_"+t+o[t],o[t]++))}),y++})},U=e=>{let y={};return e.data.forEach(o=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let u=typeof e.idKey=="function"?e.idKey(o):e.idKey,h=o[u];if(!h){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${u}, this datum has no id: ${JSON.stringify(o)}.`);return}if(y[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let t=typeof e.renderIdKey=="function"?e.renderIdKey(o):e.renderIdKey;y[h]={id:h,edges:[],renderId:t?o[t]||"":o.renderIdKey||"",data:o}}}),y},W=(e,y)=>{let o={};if(e.dimensions?.parentOptions?.addLevel0){let t=e.dimensions.parentOptions.addLevel0;y[t.id]={...t,dimensionLevel:0}}let u=[...G],h=(t,s)=>{let g=s.numericalExtents[0],n=s.numericalExtents[1];s.numericalExtents[0]=g<t?g:t,s.numericalExtents[1]=n>t?n:t};return e.data.forEach(t=>{let s=e.dimensions.values||[],g=0;s.forEach(n=>{if(!n.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(n)}.`);return}if(n.dimensionKey in t){let l=t[n.dimensionKey],f=typeof n.operations?.filterFunction=="function"?n.operations.filterFunction(t,n):!0;if(l!==void 0&&f){if(n.type||(n.type=typeof l=="bigint"||typeof l=="number"?"numerical":"categorical"),!o[n.dimensionKey]){let c=typeof n.nodeId=="function"?n.nodeId(n,e.data):n.nodeId||P(n.dimensionKey),j=typeof n.renderId=="function"?n.renderId(n,e.data):n.renderId||c;o[n.dimensionKey]={dimensionKey:n.dimensionKey,nodeId:c,divisions:{},numericalExtents:[1/0,-1/0],type:n.type,operations:{compressSparseDivisions:n.operations?.compressSparseDivisions||!1,sortFunction:n.operations?.sortFunction||void 0},behavior:n.behavior||{extents:"circular"},navigationRules:n.navigationRules||{sibling_sibling:u.length?[...u.shift()]:["previous_"+n.dimensionKey,"next_"+n.dimensionKey],parent_child:["parent_"+n.dimensionKey,"child"]}},y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:1,data:o[n.dimensionKey],renderingStrategy:n.renderingStrategy||"singleSquare"}}let r=o[n.dimensionKey],a=null;if(n.type==="categorical"){let c=typeof n.divisionOptions?.divisionNodeIds=="function"?n.divisionOptions.divisionNodeIds(n.dimensionKey,l,g):P(r.nodeId+"_"+l);if(a=r.divisions[c],!a){a=r.divisions[c]={id:c,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}};let j=typeof n.divisionOptions?.divisionRenderIds=="function"?n.divisionOptions.divisionRenderIds(n.dimensionKey,l,g):c;y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:2,data:{...a},renderingStrategy:n.divisionOptions?.renderingStrategy||"singleSquare"},y[c].data[n.dimensionKey]=l}}else{a=r.divisions[r.nodeId],a||(a=r.divisions[r.nodeId]={id:r.nodeId,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}}),n.operations||(n.operations={});let c=n.operations.createNumericalSubdivisions;r.subdivisions=typeof c=="number"&&c<1?1:c||1,c!==1&&(r.divisionOptions||(r.divisionOptions=n.divisionOptions),h(l,r))}let b=typeof e.idKey=="function"?e.idKey(t):e.idKey;a.values[t[b]]=t}}g++})}),Object.keys(o).forEach(t=>{let s=o[t],g=s.divisions;if(s.type==="numerical"){g[s.nodeId].values=Object.fromEntries(Object.entries(g[s.nodeId].values).sort((f,r)=>typeof s.operations?.sortFunction=="function"?s.operations.sortFunction(f[1],r[1],s):f[1][t]-r[1][t]));let l=g[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let f=Object.keys(l),r=typeof s.subdivisions=="function"?s.subdivisions(t,l):s.subdivisions,b=(s.numericalExtents[1]-s.numericalExtents[0])/r,c=s.numericalExtents[0]+b,j=0,d=0;for(c=s.numericalExtents[0]+b;c<=s.numericalExtents[1];c+=b){let i=typeof s.divisionOptions?.divisionNodeIds=="function"?s.divisionOptions.divisionNodeIds(t,c,c):s.nodeId+"_"+c;s.divisions[i]={id:i,sortFunction:s.divisionOptions?.sortFunction||void 0,values:{}};let I=typeof s.divisionOptions?.divisionRenderIds=="function"?s.divisionOptions.divisionRenderIds(t,c,c):i;y[i]={id:i,renderId:I,derivedNode:t,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:s.divisionOptions?.renderingStrategy||"singleSquare"};let D=!1;for(;!D&&d<f.length;){let x=l[f[d]];x[t]<=c?s.divisions[i].values[x.id]=x:(c+=b,D=!0),d++}j++}delete g[t]}}else typeof s.operations?.sortFunction=="function"&&(s.divisions=Object.fromEntries(Object.entries(g).sort((l,f)=>s.operations.sortFunction(l[1],f[1],s))));Object.keys(s.divisions).forEach(l=>{let f=s.divisions[l];typeof f.sortFunction=="function"&&(f.values=Object.fromEntries(Object.entries(f.values).sort((r,a)=>f.sortFunction(r[1],a[1],f))))})}),Object.keys(o).forEach(t=>{let s=o[t];if(s.operations.compressSparseDivisions){let g=Object.keys(s.divisions),n={},l=!0;if(g.forEach(f=>{let r=s.divisions[f],a=Object.keys(r.values);a.length<=1?a.forEach(b=>{n[b]={...r.values[b]}}):l=!1}),l){let f={id:s.nodeId,values:n};g.forEach(r=>{delete y[r]}),s.divisions={},s.divisions[s.nodeId]=f}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},Y=(e,y,o)=>{let u={},h=(s,g)=>{y[s].edges.indexOf(g)===-1&&y[s].edges.push(g)},t=(s,g,n,l)=>{let f=`${s}-${g}`,r=e.useDirectedEdges?`${g}-${f}`:f,a=!l||l==="source",b=!l||l==="target",c=j=>{u[j]?u[j].navigationRules.push(...n||[]):u[j]={source:s,target:g,navigationRules:n?[...n]:[]}};c(f),e.useDirectedEdges&&b&&c(r),a&&h(s,f),b&&h(g,r)};if(o&&Object.keys(o).length){let s=Object.keys(o),g=e.dimensions?.parentOptions?.level1Options?.order,n=g||s,l=0,f=e.dimensions?.parentOptions||{},r=f.level1Options?.behavior?.extents||"terminal",a=f.addLevel0,b=a?f.level1Options?.navigationRules?.parent_child||["parent","child"]:[],c=f.level1Options?.navigationRules?.sibling_sibling||["left","right"],j=typeof n[0]=="string"?g?y[n[0]]:y[o[n[0]].nodeId]:n[0];a&&t(a.id,j.id,b,"source"),n.forEach(d=>{let i=typeof d=="string"?g?y[d]:y[o[d].nodeId]:d;if(i===d&&!y[i.id]&&(y[i.id]=i),a&&(e.useDirectedEdges?t(i.id,a.id,b,"source"):t(a.id,i.id,b,"target")),l===n.length-1&&r==="circular")t(i.id,j.id,c);else if(l===n.length-1&&r==="bridgedCustom")t(i.id,f.level1Options.behavior.customBridgePost,c);else if(l<n.length-1){let I=typeof n[l+1]=="string"?g?y[n[l+1]]:y[o[n[l+1]].nodeId]:n[l+1];t(i.id,I.id,c)}!l&&r==="bridgedCustom"&&t(f.level1Options.behavior.customBridgePost,i.id,c),l++}),s.forEach(d=>{let i=o[d],I=i.behavior?.childmostNavigation||"within",D=(K,E,O,F)=>F.values[Object.keys(F.values)[K]]||void 0,x=I==="across"&&i.behavior?.childmostMatching?i.behavior?.childmostMatching:D,m=i.behavior?.extents||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${d} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let v=Object.keys(i.divisions),S=i.divisions[v[0]];if(v.length!==1)t(i.nodeId,S.id,i.navigationRules.parent_child,"source");else{let K=Object.keys(S.values),E=typeof e.idKey=="function"?e.idKey(S.values[K[0]]):e.idKey;t(i.nodeId,S.values[K[0]][E],i.navigationRules.parent_child,"source")}let p=0;v.forEach(K=>{let E=i.divisions[K];p===v.length-1&&(m==="circular"||m==="bridgedCousins"||m==="bridgedCustom")?t(E.id,i.divisions[v[0]].id,i.navigationRules.sibling_sibling):p<v.length-1&&t(E.id,i.divisions[v[p+1]].id,i.navigationRules.sibling_sibling);let O=Object.keys(E.values);e.useDirectedEdges?t(E.id,i.nodeId,i.navigationRules.parent_child,"source"):t(i.nodeId,E.id,i.navigationRules.parent_child,"target");let F=typeof e.idKey=="function"?e.idKey(E.values[O[0]]):e.idKey;t(E.id,E.values[O[0]][F],i.navigationRules.parent_child,"source");let C=0;O.length>1&&O.forEach(M=>{let R=E.values[M],N=typeof e.idKey=="function"?e.idKey(R):e.idKey,k=v.length!==1?E.id:i.nodeId;if(e.useDirectedEdges?t(R[N],k,i.navigationRules.parent_child,"source"):t(k,R[N],i.navigationRules.parent_child,"target"),I==="within"){if(C===O.length-1&&m==="circular"){let _=typeof e.idKey=="function"?e.idKey(E.values[O[0]]):e.idKey;t(R[N],E.values[O[0]][_],i.navigationRules.sibling_sibling)}else if(C===O.length-1&&m==="bridgedCousins")if(p!==v.length-1){let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[p+1]].values[O[0]]):e.idKey;t(R[N],i.divisions[v[p+1]].values[O[0]][_],i.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[0]].values[O[0]]):e.idKey;t(R[N],i.divisions[v[0]].values[O[0]][_],i.navigationRules.sibling_sibling)}else if(C===O.length-1&&m==="bridgedCustom")t(R[N],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(C<O.length-1){let _=typeof e.idKey=="function"?e.idKey(E.values[O[C+1]]):e.idKey;t(R[N],E.values[O[C+1]][_],i.navigationRules.sibling_sibling)}if(!C&&m==="bridgedCousins")if(p!==0){let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[p-1]].values[O[O.length-1]]):e.idKey;t(i.divisions[v[p-1]].values[O[O.length-1]][_],R[N],i.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[v.length-1]].values[O[O.length-1]]):e.idKey;t(i.divisions[v[v.length-1]].values[O[O.length-1]][_],R[N],i.navigationRules.sibling_sibling)}else!C&&m==="bridgedCustom"&&t(i.behavior.customBridgePrevious,R[N],i.navigationRules.sibling_sibling)}else if(p===v.length-1&&m==="bridgedCustom")t(R[N],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!p&&m==="bridgedCustom")t(i.behavior.customBridgePrevious,R[N],i.navigationRules.sibling_sibling);else{let _=p===v.length-1&&m==="circular"?i.divisions[v[0]]:i.divisions[v[p+1]];if(_){let L=x(C,R[N],E,_);if(L){let A=typeof e.idKey=="function"?e.idKey(L):e.idKey;t(R[N],L[A],i.navigationRules.sibling_sibling)}}}C++}),p++})})}return Object.keys(y).forEach(s=>{let g=y[s];e.genericEdges?.length&&e.genericEdges.forEach(n=>{u[n.edgeId]||(u[n.edgeId]=n.edge),(!n.conditional||n.conditional&&n.conditional(g,n))&&g.edges.push(n.edgeId)})}),u},z=(e,y,o)=>{let u=e.navigationRules;if(!u){let h=Object.keys(o||{});h.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${h.length}. Dimensions counted: ${h.join(", ")}.`);let t={},s={},g={},n=[...T],l=[...B],f=(r,a)=>{let b=r&&a,c=!1,j=!1;if((t[r]||s[r])&&(s[r]={...t[r]},c=!0),a&&(t[a]||s[a])&&(s[a]={...t[a]},j=!0),b&&!c&&!j){n.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let d=[...n.shift()];l.splice(l.indexOf(d[0]),1),l.splice(l.indexOf(d[1]),1),s[r]={direction:e.useDirectedEdges?"target":"source",key:d[0]},s[a]={direction:"target",key:d[1]}}else{if(!s[r]&&l.length){let d=l.shift(),i=[];n.forEach(I=>{d!==I[0]&&d!==I[1]&&i.push(I)}),n=i,s[r]={direction:e.useDirectedEdges?"target":"source",key:d}}if(a&&!s[a]&&l.length){let d=l.shift(),i=[];n.forEach(I=>{d!==I[0]&&d!==I[1]&&i.push(I)}),n=i,s[a]={direction:"target",key:d}}l.length||(s[r]||(g[r]=r),a&&!s[a]&&(g[a]=a))}};if(Object.keys($).forEach(r=>{let a={...$[r]};e.useDirectedEdges&&(a.direction="target"),t[r]=a}),h.length){if(e.dimensions?.parentOptions?.addLevel0){let r=e.dimensions.parentOptions.level1Options?.navigationRules?.parent_child||["parent","child"];f(r[0],r[1])}h.forEach(r=>{let a=o[r].navigationRules.parent_child,b=o[r].navigationRules.sibling_sibling;f(a[0],a[1]),f(b[0],b[1])})}if(Object.keys(y).forEach(r=>{y[r].navigationRules.forEach(a=>{s[a]||f(a)})}),Object.keys(g).length){let r={};Object.keys(s).forEach(b=>{r[s[b].key]=s[b].key}),Object.keys(t).forEach(b=>{!r[t[b].key]&&!w[t[b].key]&&l.push(t[b].key)});let a={...g};g={},Object.keys(a).forEach(b=>{f(b)}),Object.keys(g).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(g).join(", ")}.`)}u=s}return u},Q=e=>{e.addIds&&J(e);let y=U(e),o=W(e,y),u=Y(e,y,o),h=z(e,u,o);return{nodes:y,edges:u,dimensions:o,navigationRules:h}};export{J as addSimpleDataIDs,Y as buildEdges,H as buildNodeStructureFromVegaLite,U as buildNodes,z as buildRules,Q as buildStructure,ee as default,W as scaffoldDimensions};
1
+ import{a as ne,b as A}from"./chunk-YE5N6UCT.js";import{a as Q,c as X,e as Z,f as M,g as ee,i as ie}from"./chunk-MPFBSVCV.js";import{a as w,b as z}from"./chunk-RGY6OTGO.js";var he=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?de(e):fe(e),de=e=>{let h=ie,o={},g={},m={},d=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,b=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,r=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,p=e.vegaLiteView._renderer._origin,i=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],K=(n,t)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let c=`dn-node-${t}-${d}`;return d++,n["data-navigator-id"]=c,c},R=n=>{let t=o[n],c=t.index,u=t.level,v=t.parent,a=[],f=v.items[c-1];if(f){let l=K(f,u);if(o[l]){let O=`${l}-${t.id}`;a.push(O),g[O]||(g[O]={source:l,target:t.id,navigationRules:["left","right"]})}}let x=v.items[c+1];if(x){let l=K(x,u);if(o[l]){let O=`${t.id}-${l}`;a.push(O),g[O]||(g[O]={source:t.id,target:l,navigationRules:["left","right"]})}}if(u==="group"&&v.items[c].items){let O=(v.items[c].items[0].mark.items[0].items||v.items[c].items)[0],_=K(O,"item");if(o[_]){let s=`${t.id}-${_}`;a.push(s),g[s]||(g[s]={source:t.id,target:_,navigationRules:["parent","child"]})}}else if(u==="item"){let l=K(v,"group");if(o[l]){let O=`${l}-${t.id}`;a.push(O),g[O]||(g[O]={source:l,target:t.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(a.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),a.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),a},I=(n,t,c,u,v)=>{let a=K(n,t),f="render-"+a,x=c||[0,0];o[a]={},o[a].d={},o[a].id=a,o[a].renderId=f,o[a].index=u,o[a].level=t,o[a].parent=v,m[f]={},m[f].renderId=f,m[f].spatialProperties={},m[f].spatialProperties.x=n.bounds.x1+x[0],m[f].spatialProperties.y=n.bounds.y1+x[1],m[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,m[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,m[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(l=>{let O=n.datum[l];r(l,O,n.datum,t,e.vegaLiteSpec)&&(o[a].d[e.keyRenamingHash&&e.keyRenamingHash[l]?e.keyRenamingHash[l]:l]=O)}),m[f].semantics={},m[f].semantics.label=e.nodeDescriber?e.nodeDescriber(o[a].d,n,t):ne(o[a].d)},D=0;return i.items.forEach(n=>{if(P(n,D,e.vegaLiteSpec)){I(n,"group",p,D,i);let t=0,c=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;c.items.forEach(u=>{b(u,t,n,e.vegaLiteSpec)&&I(u,"item",p,t,c),t++})}D++}),Object.keys(o).forEach(n=>{o[n].edges=R(n)}),{nodes:o,edges:g,elementData:m,navigationRules:h}},ae=e=>{let h=0,o={};e.data.forEach(g=>{let m=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[m]="_"+h,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in g&&(typeof g[d]=="string"?(o[d]||(o[d]=0),o[g[d]]||(o[g[d]]=0),g[m]+="_"+d+o[d]+"_"+g[d]+o[g[d]],o[d]++,o[g[d]]++):(o[d]||(o[d]=0),g[m]+="_"+d+o[d],o[d]++))}),h++})},le=e=>{let h={};return e.data.forEach(o=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let g=typeof e.idKey=="function"?e.idKey(o):e.idKey,m=o[g];if(!m){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${g}, this datum has no id: ${JSON.stringify(o)}.`);return}if(h[m]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${m}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(o):e.renderIdKey;h[m]={id:m,edges:[],renderId:d?o[d]||"":o.renderIdKey||"",data:o}}}),h},ue=(e,h)=>{var d,P;let o={};if((P=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&P.addLevel0){let b=e.dimensions.parentOptions.addLevel0;h[b.id]=z(w({},b),{dimensionLevel:0})}let g=[...ee],m=(b,r)=>{let p=r.numericalExtents[0],i=r.numericalExtents[1];r.numericalExtents[0]=p<b?p:b,r.numericalExtents[1]=i>b?i:b};return e.data.forEach(b=>{let r=e.dimensions.values||[],p=0;r.forEach(i=>{var K,R,I,D,y,n,t,c;if(!i.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(i)}.`);return}if(i.dimensionKey in b){let u=b[i.dimensionKey],v=typeof((K=i.operations)==null?void 0:K.filterFunction)=="function"?i.operations.filterFunction(b,i):!0;if(u!==void 0&&v){if(i.type||(i.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!o[i.dimensionKey]){let l=typeof i.nodeId=="function"?i.nodeId(i,e.data):i.nodeId||A(i.dimensionKey),O=typeof i.renderId=="function"?i.renderId(i,e.data):i.renderId||l;o[i.dimensionKey]={dimensionKey:i.dimensionKey,nodeId:l,divisions:{},numericalExtents:[1/0,-1/0],type:i.type,operations:{compressSparseDivisions:((R=i.operations)==null?void 0:R.compressSparseDivisions)||!1,sortFunction:((I=i.operations)==null?void 0:I.sortFunction)||void 0},behavior:i.behavior||{extents:"circular"},navigationRules:i.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+i.dimensionKey,"next_"+i.dimensionKey],parent_child:["parent_"+i.dimensionKey,"child"]}},h[l]={id:l,renderId:O,derivedNode:i.dimensionKey,edges:[],dimensionLevel:1,data:o[i.dimensionKey],renderingStrategy:i.renderingStrategy||"singleSquare"}}let a=o[i.dimensionKey],f=null;if(i.type==="categorical"){let l=typeof((D=i.divisionOptions)==null?void 0:D.divisionNodeIds)=="function"?i.divisionOptions.divisionNodeIds(i.dimensionKey,u,p):A(a.nodeId+"_"+u);if(f=a.divisions[l],!f){f=a.divisions[l]={id:l,sortFunction:((y=i.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}};let O=typeof((n=i.divisionOptions)==null?void 0:n.divisionRenderIds)=="function"?i.divisionOptions.divisionRenderIds(i.dimensionKey,u,p):l;h[l]={id:l,renderId:O,derivedNode:i.dimensionKey,edges:[],dimensionLevel:2,data:w({},f),renderingStrategy:((t=i.divisionOptions)==null?void 0:t.renderingStrategy)||"singleSquare"},h[l].data[i.dimensionKey]=u}}else{f=a.divisions[a.nodeId],f||(f=a.divisions[a.nodeId]={id:a.nodeId,sortFunction:((c=i.divisionOptions)==null?void 0:c.sortFunction)||void 0,values:{}}),i.operations||(i.operations={});let l=i.operations.createNumericalSubdivisions;a.subdivisions=typeof l=="number"&&l<1?1:l||1,l!==1&&(a.divisionOptions||(a.divisionOptions=i.divisionOptions),m(u,a))}let x=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[x]]=b}}p++})}),Object.keys(o).forEach(b=>{var K,R,I,D,y;let r=o[b],p=r.divisions;if(r.type==="numerical"){p[r.nodeId].values=Object.fromEntries(Object.entries(p[r.nodeId].values).sort((t,c)=>{var u;return typeof((u=r.operations)==null?void 0:u.sortFunction)=="function"?r.operations.sortFunction(t[1],c[1],r):t[1][b]-c[1][b]}));let n=p[r.nodeId].values;if(r.numericalExtents[0]!==1/0&&r.subdivisions!==1){let t=Object.keys(n),c=typeof r.subdivisions=="function"?r.subdivisions(b,n):r.subdivisions,v=(r.numericalExtents[1]-r.numericalExtents[0])/c,a=r.numericalExtents[0]+v,f=0,x=0;for(a=r.numericalExtents[0]+v;a<=r.numericalExtents[1];a+=v){let l=typeof((K=r.divisionOptions)==null?void 0:K.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(b,a,a):r.nodeId+"_"+a;r.divisions[l]={id:l,sortFunction:((R=r.divisionOptions)==null?void 0:R.sortFunction)||void 0,values:{}};let O=typeof((I=r.divisionOptions)==null?void 0:I.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(b,a,a):l;h[l]={id:l,renderId:O,derivedNode:b,edges:[],data:r.divisions[l],dimensionLevel:2,renderingStrategy:((D=r.divisionOptions)==null?void 0:D.renderingStrategy)||"singleSquare"};let _=!1;for(;!_&&x<t.length;){let s=n[t[x]];s[b]<=a?r.divisions[l].values[s.id]=s:(a+=v,_=!0),x++}f++}delete p[b]}}else typeof((y=r.operations)==null?void 0:y.sortFunction)=="function"&&(r.divisions=Object.fromEntries(Object.entries(p).sort((n,t)=>r.operations.sortFunction(n[1],t[1],r))));Object.keys(r.divisions).forEach(n=>{let t=r.divisions[n];typeof t.sortFunction=="function"&&(t.values=Object.fromEntries(Object.entries(t.values).sort((c,u)=>t.sortFunction(c[1],u[1],t))))})}),Object.keys(o).forEach(b=>{let r=o[b];if(r.operations.compressSparseDivisions){let p=Object.keys(r.divisions),i={},K=!0;if(p.forEach(R=>{let I=r.divisions[R],D=Object.keys(I.values);D.length<=1?D.forEach(y=>{i[y]=w({},I.values[y])}):K=!1}),K){let R={id:r.nodeId,values:i};p.forEach(I=>{delete h[I]}),r.divisions={},r.divisions[r.nodeId]=R}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},ce=(e,h,o)=>{var P,b,r,p,i,K,R,I,D,y;let g={},m=(n,t)=>{h[n].edges.indexOf(t)===-1&&h[n].edges.push(t)},d=(n,t,c,u)=>{let v=`${n}-${t}`,a=e.useDirectedEdges?`${t}-${v}`:v,f=!u||u==="source",x=!u||u==="target",l=O=>{g[O]?g[O].navigationRules.push(...c||[]):g[O]={source:n,target:t,navigationRules:c?[...c]:[]}};l(v),e.useDirectedEdges&&x&&l(a),f&&m(n,v),x&&m(t,a)};if(o&&Object.keys(o).length){let n=Object.keys(o),t=(r=(b=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:b.level1Options)==null?void 0:r.order,c=t||n,u=0,v=((p=e.dimensions)==null?void 0:p.parentOptions)||{},a=((K=(i=v.level1Options)==null?void 0:i.behavior)==null?void 0:K.extents)||"terminal",f=v.addLevel0,x=f?((I=(R=v.level1Options)==null?void 0:R.navigationRules)==null?void 0:I.parent_child)||["parent","child"]:[],l=((y=(D=v.level1Options)==null?void 0:D.navigationRules)==null?void 0:y.sibling_sibling)||["left","right"],O=typeof c[0]=="string"?t?h[c[0]]:h[o[c[0]].nodeId]:c[0];f&&d(f.id,O.id,x,"source"),c.forEach(_=>{let s=typeof _=="string"?t?h[_]:h[o[_].nodeId]:_;if(s===_&&!h[s.id]&&(h[s.id]=s),f&&(e.useDirectedEdges?d(s.id,f.id,x,"source"):d(f.id,s.id,x,"target")),u===c.length-1&&a==="circular")d(s.id,O.id,l);else if(u===c.length-1&&a==="bridgedCustom")d(s.id,v.level1Options.behavior.customBridgePost,l);else if(u<c.length-1){let T=typeof c[u+1]=="string"?t?h[c[u+1]]:h[o[c[u+1]].nodeId]:c[u+1];d(s.id,T.id,l)}!u&&a==="bridgedCustom"&&d(v.level1Options.behavior.customBridgePost,s.id,l),u++}),n.forEach(_=>{var H,J,U,W;let s=o[_],T=((H=s.behavior)==null?void 0:H.childmostNavigation)||"within",te=(B,N,E,V)=>V.values[Object.keys(V.values)[B]]||void 0,se=T==="across"&&((J=s.behavior)!=null&&J.childmostMatching)?(U=s.behavior)==null?void 0:U.childmostMatching:te,$=((W=s.behavior)==null?void 0:W.extents)||"circular";s.divisions||console.error(`Parsing dimensions. The dimension using the key ${_} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(s)}.`);let j=Object.keys(s.divisions),G=s.divisions[j[0]];if(j.length!==1)d(s.nodeId,G.id,s.navigationRules.parent_child,"source");else{let B=Object.keys(G.values),N=typeof e.idKey=="function"?e.idKey(G.values[B[0]]):e.idKey;d(s.nodeId,G.values[B[0]][N],s.navigationRules.parent_child,"source")}let C=0;j.forEach(B=>{let N=s.divisions[B];C===j.length-1&&($==="circular"||$==="bridgedCousins"||$==="bridgedCustom")?d(N.id,s.divisions[j[0]].id,s.navigationRules.sibling_sibling):C<j.length-1&&d(N.id,s.divisions[j[C+1]].id,s.navigationRules.sibling_sibling);let E=Object.keys(N.values);e.useDirectedEdges?d(N.id,s.nodeId,s.navigationRules.parent_child,"source"):d(s.nodeId,N.id,s.navigationRules.parent_child,"target");let V=typeof e.idKey=="function"?e.idKey(N.values[E[0]]):e.idKey;d(N.id,N.values[E[0]][V],s.navigationRules.parent_child,"source");let k=0;E.length>=1&&E.forEach(oe=>{let S=N.values[oe],F=typeof e.idKey=="function"?e.idKey(S):e.idKey,Y=j.length!==1?N.id:s.nodeId;if(e.useDirectedEdges?d(S[F],Y,s.navigationRules.parent_child,"source"):d(Y,S[F],s.navigationRules.parent_child,"target"),T==="within"){if(k===E.length-1&&$==="circular"){let L=typeof e.idKey=="function"?e.idKey(N.values[E[0]]):e.idKey;d(S[F],N.values[E[0]][L],s.navigationRules.sibling_sibling)}else if(k===E.length-1&&$==="bridgedCousins")if(C!==j.length-1){let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[C+1]].values[E[0]]):e.idKey;d(S[F],s.divisions[j[C+1]].values[E[0]][L],s.navigationRules.sibling_sibling)}else{let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[0]].values[E[0]]):e.idKey;d(S[F],s.divisions[j[0]].values[E[0]][L],s.navigationRules.sibling_sibling)}else if(k===E.length-1&&$==="bridgedCustom")d(S[F],s.behavior.customBridgePost,s.navigationRules.sibling_sibling);else if(k<E.length-1){let L=typeof e.idKey=="function"?e.idKey(N.values[E[k+1]]):e.idKey;d(S[F],N.values[E[k+1]][L],s.navigationRules.sibling_sibling)}if(!k&&$==="bridgedCousins")if(C!==0){let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[C-1]].values[E[E.length-1]]):e.idKey;d(s.divisions[j[C-1]].values[E[E.length-1]][L],S[F],s.navigationRules.sibling_sibling)}else{let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[j.length-1]].values[E[E.length-1]]):e.idKey;d(s.divisions[j[j.length-1]].values[E[E.length-1]][L],S[F],s.navigationRules.sibling_sibling)}else!k&&$==="bridgedCustom"&&d(s.behavior.customBridgePrevious,S[F],s.navigationRules.sibling_sibling)}else if(C===j.length-1&&$==="bridgedCustom")d(S[F],s.behavior.customBridgePost,s.navigationRules.sibling_sibling);else if(!C&&$==="bridgedCustom")d(s.behavior.customBridgePrevious,S[F],s.navigationRules.sibling_sibling);else{let L=C===j.length-1&&$==="circular"?s.divisions[j[0]]:s.divisions[j[C+1]];if(L){let q=se(k,S[F],N,L);if(q){let re=typeof e.idKey=="function"?e.idKey(q):e.idKey;d(S[F],q[re],s.navigationRules.sibling_sibling)}}}k++}),C++})})}return Object.keys(h).forEach(n=>{var c;let t=h[n];(c=e.genericEdges)!=null&&c.length&&e.genericEdges.forEach(u=>{g[u.edgeId]||(g[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(t,u))&&t.edges.push(u.edgeId)})}),g},ge=(e,h,o)=>{var m,d,P,b;let g=e.navigationRules;if(!g){let r=Object.keys(o||{});r.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${r.length}. Dimensions counted: ${r.join(", ")}.`);let p={},i={},K={},R=[...Z],I=[...X],D=(y,n)=>{let t=y&&n,c=!1,u=!1;if((p[y]||i[y])&&(i[y]=w({},p[y]),c=!0),n&&(p[n]||i[n])&&(i[n]=w({},p[n]),u=!0),t&&!c&&!u){R.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let v=[...R.shift()];I.splice(I.indexOf(v[0]),1),I.splice(I.indexOf(v[1]),1),i[y]={direction:e.useDirectedEdges?"target":"source",key:v[0]},i[n]={direction:"target",key:v[1]}}else{if(!i[y]&&I.length){let v=I.shift(),a=[];R.forEach(f=>{v!==f[0]&&v!==f[1]&&a.push(f)}),R=a,i[y]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!i[n]&&I.length){let v=I.shift(),a=[];R.forEach(f=>{v!==f[0]&&v!==f[1]&&a.push(f)}),R=a,i[n]={direction:"target",key:v}}I.length||(i[y]||(K[y]=y),n&&!i[n]&&(K[n]=n))}};if(Object.keys(M).forEach(y=>{let n=w({},M[y]);e.useDirectedEdges&&(n.direction="target"),p[y]=n}),r.length){if((d=(m=e.dimensions)==null?void 0:m.parentOptions)!=null&&d.addLevel0){let y=((b=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:b.parent_child)||["parent","child"];D(y[0],y[1])}r.forEach(y=>{let n=o[y].navigationRules.parent_child,t=o[y].navigationRules.sibling_sibling;D(n[0],n[1]),D(t[0],t[1])})}if(Object.keys(h).forEach(y=>{h[y].navigationRules.forEach(n=>{i[n]||D(n)})}),Object.keys(K).length){let y={};Object.keys(i).forEach(t=>{y[i[t].key]=i[t].key}),Object.keys(p).forEach(t=>{!y[p[t].key]&&!Q[p[t].key]&&I.push(p[t].key)});let n=w({},K);K={},Object.keys(n).forEach(t=>{D(t)}),Object.keys(K).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(K).join(", ")}.`)}g=i}return g},fe=e=>{e.addIds&&ae(e);let h=le(e),o=ue(e,h),g=ce(e,h,o),m=ge(e,g,o);return{nodes:h,edges:g,dimensions:o,navigationRules:m}};export{ae as addSimpleDataIDs,ce as buildEdges,de as buildNodeStructureFromVegaLite,le as buildNodes,ge as buildRules,fe as buildStructure,he as default,ue as scaffoldDimensions};
@@ -0,0 +1,21 @@
1
+ var F=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var a in t)F(e,a,{get:t[a],enumerable:!0})},me=(e,t,a,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of le(t))!de.call(e,n)&&n!==a&&F(e,n,{get:()=>t[n],enumerable:!(l=ce(t,n))||l.enumerable});return e};var pe=e=>me(F({},"__esModule",{value:!0}),e);var K=(e,t,a)=>new Promise((l,n)=>{var r=i=>{try{s(a.next(i))}catch(u){n(u)}},o=i=>{try{s(a.throw(i))}catch(u){n(u)}},s=i=>i.done?l(i.value):Promise.resolve(i.value).then(r,o);s((a=a.apply(e,t)).next())});var we={};ue(we,{default:()=>be});module.exports=pe(we);var Y={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var q={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var ee=e=>{let t={},a=Y,l=q;return t.moveTo=n=>{let r=e.structure.nodes[n];if(r)return r},t.move=(n,r)=>{if(n){let o=e.structure.nodes[n];if(o.edges){let s=null,i=0,u=l[r];if(!u)return;let f=(y,c)=>{if(y!==r)return null;let d={target:typeof c.target=="string"?c.target:c.target(o,n),source:typeof c.source=="string"?c.source:c.source(o,n)};return d[u.direction]!==n?d[u.direction]:null};for(i=0;i<o.edges.length;i++){let y=e.structure.edges[o.edges[i]];if(y.navigationRules.forEach(c=>{s||(s=f(c,y))}),s)break}return s?t.moveTo(s):void 0}}},t.enter=()=>{if(e.entryPoint)return t.moveTo(e.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},t.exit=()=>{if(e.exitPoint)return e.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},t.keydownValidator=n=>{let r=a[n.code];if(r)return r},t.focus=n=>{let r=document.getElementById(n);r&&r.focus()},t.setNavigationKeyBindings=n=>{n?(a={},l=n,Object.keys(n).forEach(r=>{let o=n[r];a[o.key]=r})):(a=Y,l=q)},t.setNavigationKeyBindings(e.navigationRules),t};var he=e=>{var t,a,l,n,r;if((t=e.semantics)!=null&&t.label){let o=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(o)return o}if(!e.derivedNode)return e.data?Object.keys(e.data).map(o=>`${o}: ${e.data[o]}`).join(". ")+". Data point.":e.id;if((a=e.data)!=null&&a.dimensionKey){let o=0,s=Object.keys(e.data.divisions||{});s.forEach(u=>{o+=Object.keys(e.data.divisions[u].values||{}).length});let i=`${e.derivedNode}.`;return i+=s.length&&o?` ${s.length} division${s.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",i+=` ${e.data.type} dimension.`,i}return`${e.derivedNode}: ${(l=e.data)==null?void 0:l[e.derivedNode]}. ${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length} child data point${Object.keys(((r=e.data)==null?void 0:r.values)||{}).length>1?"s":""}. Division.`},ge=(e,t,a)=>{let l=new Set,n=a.navigationRules||{};return t.edges&&t.edges.forEach(r=>{let o=a.edges[r];o&&o.navigationRules.forEach(s=>{let i=n[s];if(!i)return;let u=i.direction==="target"?o.target:o.source,f=typeof u=="function"?u(t,e):u;f&&f!==e&&l.add(s)})}),Array.from(l)},te=e=>e.navigationRules?Object.keys(e.navigationRules):[],J=(e,t)=>{let a=e.length,l=t.length,n=Array(l+1);for(let r=0;r<=l;r++)n[r]=r;for(let r=1;r<=a;r++){let o=n[0];n[0]=r;for(let s=1;s<=l;s++){let i=n[s];n[s]=e[r-1]===t[s-1]?o:1+Math.min(o,n[s],n[s-1]),o=i}}return n[l]},fe=e=>e<=4?1:2,ye=(e,t,a={})=>{let l=e.toLowerCase().trim(),n=t.find(c=>c.toLowerCase()===l);if(n)return{match:n,ambiguous:[]};let r=t.find(c=>a[c]&&a[c].toLowerCase()===l);if(r)return{match:r,ambiguous:[]};let o=t.filter(c=>c.toLowerCase().startsWith(l));if(o.length===1)return{match:o[0],ambiguous:[]};let s=t.filter(c=>{if(!a[c])return!1;let d=a[c].toLowerCase();return d.startsWith(l)?!0:d.split(/\s+/).some(T=>T.startsWith(l))}),i=new Set([...o,...s]),u=Array.from(i);if(u.length===1)return{match:u[0],ambiguous:[]};if(u.length>1)return{match:null,ambiguous:u};let f=fe(l.length),y=[];for(let c=0;c<t.length;c++){let d=t[c],T=J(l,d.toLowerCase());if(T<=f){y.push({candidate:d,dist:T});continue}if(a[d]){let C=a[d].toLowerCase().split(/\s+/);for(let w=0;w<C.length;w++)if(J(l,C[w])<=f){y.push({candidate:d,dist:J(l,C[w])});break}}}return y.length===1?{match:y[0].candidate,ambiguous:[]}:y.length>1?(y.sort((c,d)=>c.dist-d.dist),y[0].dist<y[1].dist?{match:y[0].candidate,ambiguous:[]}:{match:null,ambiguous:y.map(c=>c.candidate)}):{match:null,ambiguous:[]}},G=(e,t)=>t[e]?`${t[e]} (${e})`:e,ve=(e,t,a,l=10)=>{let n=e.toLowerCase(),r=[],o=Object.keys(t.nodes);for(let s=0;s<o.length&&r.length<l;s++){let i=o[s],u=t.nodes[i],f=!1;if(u.data&&!f){let y=Object.keys(u.data);for(let c=0;c<y.length&&!f;c++){let d=u.data[y[c]];d!=null&&typeof d!="object"&&String(d).toLowerCase().includes(n)&&(f=!0)}}!f&&u.derivedNode&&u.derivedNode.toLowerCase().includes(n)&&(f=!0),!f&&i.toLowerCase().includes(n)&&(f=!0),f&&r.push({nodeId:i,description:a(u)})}return r},be=e=>{var _;let{structure:t,container:a,entryPoint:l,describeNode:n=he,commandLabels:r={},onNavigate:o,onExit:s,llm:i,data:u}=e,f=typeof a=="string"?document.getElementById(a):a;if(!f)throw new Error(`textChat: container "${a}" not found`);let y=l||(t.dimensions?(_=t.dimensions[Object.keys(t.dimensions)[0]])==null?void 0:_.nodeId:Object.keys(t.nodes)[0]),c=ee({structure:t,navigationRules:t.navigationRules||{},entryPoint:y}),d=null,T=Math.random().toString(36).slice(2,8),C=[],w=-1,R=null,$=[],ne=()=>{let m=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
+
3
+ `;if(u&&u.length>0){let p=Object.keys(u[0]),h=u.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
+ `);m+=`DATASET SUMMARY:
5
+ - Columns: ${p.join(", ")}
6
+ - Rows: ${u.length}
7
+ - Sample (first 3):
8
+ ${h}
9
+
10
+ `,m+=`FULL DATASET (JSON):
11
+ `+JSON.stringify(u)+`
12
+
13
+ `}if(d){let p=t.nodes[d];m+=`CURRENT POSITION: ${p?n(p):d}
14
+
15
+ `}else m+=`CURRENT POSITION: Not yet navigated into the structure.
16
+
17
+ `;return m+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
18
+
19
+ `,m+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
20
+
21
+ `,m+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',m},L=document.createElement("div");L.className="dn-text-chat";let b=document.createElement("div");b.className="dn-text-chat-log",b.setAttribute("role","log"),b.setAttribute("aria-live","polite"),L.appendChild(b);let B=document.createElement("div");B.className="dn-text-chat-controls";let U=document.createElement("label"),I=document.createElement("input");I.type="checkbox",I.checked=!0,I.addEventListener("change",()=>{b.setAttribute("aria-live",I.checked?"polite":"off")}),U.appendChild(I),U.appendChild(document.createTextNode(" Automatically announce to screen readers")),B.appendChild(U),L.appendChild(B);let O=document.createElement("form");O.className="dn-text-chat-form";let j=document.createElement("label");j.setAttribute("for",`dn-text-chat-input-${T}`),j.className="dn-text-chat-sr-only",j.textContent="Navigation command";let k=document.createElement("input");k.type="text",k.id=`dn-text-chat-input-${T}`,k.autocomplete="off",k.setAttribute("placeholder","Type a command...");let H=document.createElement("button");H.type="submit",H.textContent="Send",O.appendChild(j),O.appendChild(k),O.appendChild(H),L.appendChild(O),f.appendChild(L);let z="";k.addEventListener("keydown",m=>{if(m.key==="ArrowUp"){if(m.preventDefault(),C.length===0)return;w===-1?(z=k.value,w=C.length-1):w>0&&w--,k.value=C[w]}else if(m.key==="ArrowDown"){if(m.preventDefault(),w===-1)return;w<C.length-1?(w++,k.value=C[w]):(w=-1,k.value=z)}});let W=(m,p)=>{let h=document.createElement("div");h.className=`dn-text-chat-message ${p}`,h.textContent=m,b.appendChild(h),b.scrollTop=b.scrollHeight},S=m=>W(m,"dn-text-chat-system"),re=m=>W(`> ${m}`,"dn-text-chat-input-echo"),v=m=>W(m,"dn-text-chat-response"),oe=(m,p)=>{let h=document.createElement("div");h.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=m,h.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",p.forEach(P=>{let A=document.createElement("li");A.textContent=P,E.appendChild(A)}),h.appendChild(E),b.appendChild(h),b.scrollTop=b.scrollHeight},V=m=>K(void 0,null,function*(){let p={role:"system",content:ne()};$.push({role:"user",content:m});let h=document.createElement("div");h.className="dn-text-chat-message dn-text-chat-llm-thinking",h.textContent="Thinking...",b.appendChild(h),b.scrollTop=b.scrollHeight;try{let N=yield i([p,...$]);return b.removeChild(h),N===null?($.pop(),null):($.push({role:"assistant",content:N}),v(N),N)}catch(N){return b.removeChild(h),$.pop(),v(`Error: ${N.message||"Could not get a response."}`),""}});i?(S('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),S('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):S('Text navigation ready. Type "enter" to begin or "help" for available commands.');let Q=["enter","help","more","more help","clear"],Z=m=>{let p=c.moveTo(m);p?(d=p.id,o&&o(p),v(`Moved to: ${n(p)}`)):v("Could not move to that node.")},X=m=>K(void 0,null,function*(){let p=m.trim();if(!p)return;re(p);let h=p.toLowerCase();if(R){let g=parseInt(p,10);if(!isNaN(g)&&g>=1&&g<=R.length){let x=R[g-1];R=null,Z(x.nodeId);return}R=null}if(h==="clear"){b.innerHTML="",S('Chat cleared. Type "help" for available commands.');return}if(h==="enter"){if(d){v('Already in the structure. Type "help" to see available commands.');return}let g=c.enter();if(!g){v("Could not enter the structure. No entry point found.");return}d=g.id,o&&o(g),v(`Entered: ${n(g)}`);return}if(h==="help"){let g=i?" You can also type any question about the data.":"";if(!d)v('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+g);else{let x=t.nodes[d],ie=ge(d,x,t).map(se=>G(se,r));v(`Available: ${ie.join(", ")}, move to <search>.`+g)}return}if(h.startsWith("move to ")){let g=p.slice(8).trim();if(!g){v("Usage: move to <search term>");return}let x=ve(g,t,n);x.length===0?v(`No nodes found matching "${g}".`):x.length===1?Z(x[0].nodeId):(R=x,oe(`Found ${x.length} matches. Type a number to move there:`,x.map(D=>D.description)));return}if(h==="more"||h==="more help"){let x=te(t).map(D=>G(D,r));v(`All navigation rules: ${x.join(", ")}.`);return}if(!d){if(i&&(yield V(p))!==null)return;v('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(i?" Enter an API key above to ask questions about the data.":""));return}let N=te(t),{match:E,ambiguous:P}=ye(h,[...N,...Q],r);if(E&&Q.includes(E)){yield X(E);return}if(!E&&P.length>0){let g=P.map(x=>G(x,r));v(`Did you mean: ${g.join(", ")}?`);return}if(!E){if(i&&(yield V(p))!==null)return;let g=i?" Enter an API key above to ask questions about the data.":"";v(`Unknown command "${p}". Type "help" for available commands.`+g);return}let A=E,ae=r[A]||A;if(A==="exit"){d=null,s&&s(),v('Exited the structure. Type "enter" to re-enter.');return}let M=c.move(d,A);M?(d=M.id,o&&o(M),v(`${ae}: ${n(M)}`)):v(`Cannot move "${A}" from here.`)});return O.addEventListener("submit",m=>K(void 0,null,function*(){m.preventDefault();let p=k.value.trim();p&&(C.push(p),w=-1),yield X(k.value),k.value="",k.focus()})),{destroy(){f.removeChild(L)},getCurrentNode(){return d&&t.nodes[d]||null}}};
@@ -0,0 +1,21 @@
1
+ import{a as X}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as H}from"./chunk-RGY6OTGO.js";var at=t=>{var e,g,l,i,a;if((e=t.semantics)!=null&&e.label){let n=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(n)return n}if(!t.derivedNode)return t.data?Object.keys(t.data).map(n=>`${n}: ${t.data[n]}`).join(". ")+". Data point.":t.id;if((g=t.data)!=null&&g.dimensionKey){let n=0,d=Object.keys(t.data.divisions||{});d.forEach(u=>{n+=Object.keys(t.data.divisions[u].values||{}).length});let h=`${t.derivedNode}.`;return h+=d.length&&n?` ${d.length} division${d.length>1?"s":""}, ${n} datapoint${n>1?"s":""}.`:" No child data points.",h+=` ${t.data.type} dimension.`,h}return`${t.derivedNode}: ${(l=t.data)==null?void 0:l[t.derivedNode]}. ${Object.keys(((i=t.data)==null?void 0:i.values)||{}).length} child data point${Object.keys(((a=t.data)==null?void 0:a.values)||{}).length>1?"s":""}. Division.`},rt=(t,e,g)=>{let l=new Set,i=g.navigationRules||{};return e.edges&&e.edges.forEach(a=>{let n=g.edges[a];n&&n.navigationRules.forEach(d=>{let h=i[d];if(!h)return;let u=h.direction==="target"?n.target:n.source,f=typeof u=="function"?u(e,t):u;f&&f!==t&&l.add(d)})}),Array.from(l)},Z=t=>t.navigationRules?Object.keys(t.navigationRules):[],Y=(t,e)=>{let g=t.length,l=e.length,i=Array(l+1);for(let a=0;a<=l;a++)i[a]=a;for(let a=1;a<=g;a++){let n=i[0];i[0]=a;for(let d=1;d<=l;d++){let h=i[d];i[d]=t[a-1]===e[d-1]?n:1+Math.min(n,i[d],i[d-1]),n=h}}return i[l]},it=t=>t<=4?1:2,ct=(t,e,g={})=>{let l=t.toLowerCase().trim(),i=e.find(c=>c.toLowerCase()===l);if(i)return{match:i,ambiguous:[]};let a=e.find(c=>g[c]&&g[c].toLowerCase()===l);if(a)return{match:a,ambiguous:[]};let n=e.filter(c=>c.toLowerCase().startsWith(l));if(n.length===1)return{match:n[0],ambiguous:[]};let d=e.filter(c=>{if(!g[c])return!1;let s=g[c].toLowerCase();return s.startsWith(l)?!0:s.split(/\s+/).some($=>$.startsWith(l))}),h=new Set([...n,...d]),u=Array.from(h);if(u.length===1)return{match:u[0],ambiguous:[]};if(u.length>1)return{match:null,ambiguous:u};let f=it(l.length),x=[];for(let c=0;c<e.length;c++){let s=e[c],$=Y(l,s.toLowerCase());if($<=f){x.push({candidate:s,dist:$});continue}if(g[s]){let E=g[s].toLowerCase().split(/\s+/);for(let b=0;b<E.length;b++)if(Y(l,E[b])<=f){x.push({candidate:s,dist:Y(l,E[b])});break}}}return x.length===1?{match:x[0].candidate,ambiguous:[]}:x.length>1?(x.sort((c,s)=>c.dist-s.dist),x[0].dist<x[1].dist?{match:x[0].candidate,ambiguous:[]}:{match:null,ambiguous:x.map(c=>c.candidate)}):{match:null,ambiguous:[]}},J=(t,e)=>e[t]?`${e[t]} (${t})`:t,lt=(t,e,g,l=10)=>{let i=t.toLowerCase(),a=[],n=Object.keys(e.nodes);for(let d=0;d<n.length&&a.length<l;d++){let h=n[d],u=e.nodes[h],f=!1;if(u.data&&!f){let x=Object.keys(u.data);for(let c=0;c<x.length&&!f;c++){let s=u.data[x[c]];s!=null&&typeof s!="object"&&String(s).toLowerCase().includes(i)&&(f=!0)}}!f&&u.derivedNode&&u.derivedNode.toLowerCase().includes(i)&&(f=!0),!f&&h.toLowerCase().includes(i)&&(f=!0),f&&a.push({nodeId:h,description:g(u)})}return a},ut=t=>{var Q;let{structure:e,container:g,entryPoint:l,describeNode:i=at,commandLabels:a={},onNavigate:n,onExit:d,llm:h,data:u}=t,f=typeof g=="string"?document.getElementById(g):g;if(!f)throw new Error(`textChat: container "${g}" not found`);let x=l||(e.dimensions?(Q=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:Q.nodeId:Object.keys(e.nodes)[0]),c=X({structure:e,navigationRules:e.navigationRules||{},entryPoint:x}),s=null,$=Math.random().toString(36).slice(2,8),E=[],b=-1,A=null,R=[],_=()=>{let o=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
+
3
+ `;if(u&&u.length>0){let r=Object.keys(u[0]),m=u.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
+ `);o+=`DATASET SUMMARY:
5
+ - Columns: ${r.join(", ")}
6
+ - Rows: ${u.length}
7
+ - Sample (first 3):
8
+ ${m}
9
+
10
+ `,o+=`FULL DATASET (JSON):
11
+ `+JSON.stringify(u)+`
12
+
13
+ `}if(s){let r=e.nodes[s];o+=`CURRENT POSITION: ${r?i(r):s}
14
+
15
+ `}else o+=`CURRENT POSITION: Not yet navigated into the structure.
16
+
17
+ `;return o+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
18
+
19
+ `,o+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
20
+
21
+ `,o+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',o},L=document.createElement("div");L.className="dn-text-chat";let v=document.createElement("div");v.className="dn-text-chat-log",v.setAttribute("role","log"),v.setAttribute("aria-live","polite"),L.appendChild(v);let U=document.createElement("div");U.className="dn-text-chat-controls";let q=document.createElement("label"),O=document.createElement("input");O.type="checkbox",O.checked=!0,O.addEventListener("change",()=>{v.setAttribute("aria-live",O.checked?"polite":"off")}),q.appendChild(O),q.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(q),L.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let j=document.createElement("label");j.setAttribute("for",`dn-text-chat-input-${$}`),j.className="dn-text-chat-sr-only",j.textContent="Navigation command";let w=document.createElement("input");w.type="text",w.id=`dn-text-chat-input-${$}`,w.autocomplete="off",w.setAttribute("placeholder","Type a command...");let F=document.createElement("button");F.type="submit",F.textContent="Send",I.appendChild(j),I.appendChild(w),I.appendChild(F),L.appendChild(I),f.appendChild(L);let K="";w.addEventListener("keydown",o=>{if(o.key==="ArrowUp"){if(o.preventDefault(),E.length===0)return;b===-1?(K=w.value,b=E.length-1):b>0&&b--,w.value=E[b]}else if(o.key==="ArrowDown"){if(o.preventDefault(),b===-1)return;b<E.length-1?(b++,w.value=E[b]):(b=-1,w.value=K)}});let W=(o,r)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${r}`,m.textContent=o,v.appendChild(m),v.scrollTop=v.scrollHeight},M=o=>W(o,"dn-text-chat-system"),tt=o=>W(`> ${o}`,"dn-text-chat-input-echo"),y=o=>W(o,"dn-text-chat-response"),et=(o,r)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=o,m.appendChild(N);let T=document.createElement("ol");T.className="dn-text-chat-choices",r.forEach(S=>{let k=document.createElement("li");k.textContent=S,T.appendChild(k)}),m.appendChild(T),v.appendChild(m),v.scrollTop=v.scrollHeight},z=o=>H(void 0,null,function*(){let r={role:"system",content:_()};R.push({role:"user",content:o});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",v.appendChild(m),v.scrollTop=v.scrollHeight;try{let N=yield h([r,...R]);return v.removeChild(m),N===null?(R.pop(),null):(R.push({role:"assistant",content:N}),y(N),N)}catch(N){return v.removeChild(m),R.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});h?(M('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),M('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):M('Text navigation ready. Type "enter" to begin or "help" for available commands.');let B=["enter","help","more","more help","clear"],V=o=>{let r=c.moveTo(o);r?(s=r.id,n&&n(r),y(`Moved to: ${i(r)}`)):y("Could not move to that node.")},G=o=>H(void 0,null,function*(){let r=o.trim();if(!r)return;tt(r);let m=r.toLowerCase();if(A){let p=parseInt(r,10);if(!isNaN(p)&&p>=1&&p<=A.length){let C=A[p-1];A=null,V(C.nodeId);return}A=null}if(m==="clear"){v.innerHTML="",M('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(s){y('Already in the structure. Type "help" to see available commands.');return}let p=c.enter();if(!p){y("Could not enter the structure. No entry point found.");return}s=p.id,n&&n(p),y(`Entered: ${i(p)}`);return}if(m==="help"){let p=h?" You can also type any question about the data.":"";if(!s)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+p);else{let C=e.nodes[s],ot=rt(s,C,e).map(st=>J(st,a));y(`Available: ${ot.join(", ")}, move to <search>.`+p)}return}if(m.startsWith("move to ")){let p=r.slice(8).trim();if(!p){y("Usage: move to <search term>");return}let C=lt(p,e,i);C.length===0?y(`No nodes found matching "${p}".`):C.length===1?V(C[0].nodeId):(A=C,et(`Found ${C.length} matches. Type a number to move there:`,C.map(D=>D.description)));return}if(m==="more"||m==="more help"){let C=Z(e).map(D=>J(D,a));y(`All navigation rules: ${C.join(", ")}.`);return}if(!s){if(h&&(yield z(r))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(h?" Enter an API key above to ask questions about the data.":""));return}let N=Z(e),{match:T,ambiguous:S}=ct(m,[...N,...B],a);if(T&&B.includes(T)){yield G(T);return}if(!T&&S.length>0){let p=S.map(C=>J(C,a));y(`Did you mean: ${p.join(", ")}?`);return}if(!T){if(h&&(yield z(r))!==null)return;let p=h?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${r}". Type "help" for available commands.`+p);return}let k=T,nt=a[k]||k;if(k==="exit"){s=null,d&&d(),y('Exited the structure. Type "enter" to re-enter.');return}let P=c.move(s,k);P?(s=P.id,n&&n(P),y(`${nt}: ${i(P)}`)):y(`Cannot move "${k}" from here.`)});return I.addEventListener("submit",o=>H(void 0,null,function*(){o.preventDefault();let r=w.value.trim();r&&(E.push(r),b=-1),yield G(w.value),w.value="",w.focus()})),{destroy(){f.removeChild(L)},getCurrentNode(){return s&&e.nodes[s]||null}}};export{ut as default};
@@ -1 +1 @@
1
- function e(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}var r=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var a=function e(e,t){for(var n in t)r(e,n,{get:t[n],enumerable:!0})},u=function a(a,u,c,i){var f=true,l=false,d=undefined;if(u&&(typeof u==="undefined"?"undefined":e(u))=="object"||typeof u=="function")try{var y=function(){var e=p.value;!o.call(a,e)&&e!==c&&r(a,e,{get:function r(){return u[e]},enumerable:!(i=t(u,e))||i.enumerable})};for(var b=n(u)[Symbol.iterator](),p;!(f=(p=b.next()).done);f=true)y()}catch(e){l=true;d=e}finally{try{if(!f&&b.return!=null){b.return()}}finally{if(l){throw d}}}return a};var c=function e(e){return u(r({},"__esModule",{value:!0}),e)};var i={};a(i,{createValidId:function e(){return l},describeNode:function e(){return f}});module.exports=c(i);var f=function e(e,r){var t=Object.keys(e),n="";return t.forEach(function(t){n+="".concat(r&&r.omitKeyNames?"":t+": ").concat(e[t],". ")}),n+=r&&r.semanticLabel||"Data point.",n},l=function e(e){return"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_")};0&&(module.exports={createValidId:createValidId,describeNode:describeNode});
1
+ var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var a in e)o(t,a,{get:e[a],enumerable:!0})},b=(t,e,a,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of n(e))!i.call(t,r)&&r!==a&&o(t,r,{get:()=>e[r],enumerable:!(c=s(e,r))||c.enumerable});return t};var D=t=>b(o({},"__esModule",{value:!0}),t);var u={};m(u,{createValidId:()=>p,describeNode:()=>l});module.exports=D(u);var l=(t,e)=>{let a=Object.keys(t),c="";return a.forEach(r=>{c+=`${e&&e.omitKeyNames?"":r+": "}${t[r]}. `}),c+=e&&e.semanticLabel||"Data point.",c},p=t=>"_"+t.replace(/[^a-zA-Z0-9_-]+/g,"_");0&&(module.exports={createValidId,describeNode});
package/dist/utilities.js CHANGED
@@ -1 +1 @@
1
- import{a,b}from"./chunk-YE5N6UCT.js";export{b as createValidId,a as describeNode};
1
+ import{a,b}from"./chunk-YE5N6UCT.js";import"./chunk-RGY6OTGO.js";export{b as createValidId,a as describeNode};
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "data-navigator",
3
3
  "author": "Frank Elavsky",
4
- "version": "2.2.3",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/src/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
+ "text-chat.css",
11
12
  "README.md",
12
13
  "LICENSE"
13
14
  ],
@@ -21,7 +22,8 @@
21
22
  "types": "./dist/src/index.d.ts",
22
23
  "default": "./dist/index.cjs"
23
24
  }
24
- }
25
+ },
26
+ "./text-chat.css": "./text-chat.css"
25
27
  },
26
28
  "keywords": [
27
29
  "visualization",
@@ -34,7 +36,7 @@
34
36
  "clean": "rm -rf ./dist",
35
37
  "build": "yarn build:index && yarn build:modules",
36
38
  "build:index": "tsup src/index.ts --format cjs,esm",
37
- "build:modules": "tsup src/structure.ts src/input.ts src/rendering.ts src/utilities.ts src/consts.ts --format cjs,esm --minify",
39
+ "build:modules": "tsup src/structure.ts src/input.ts src/rendering.ts src/utilities.ts src/consts.ts src/text-chat.ts --format cjs,esm --minify",
38
40
  "prepublishOnly": "cp ../../README.md ../../LICENSE ."
39
41
  },
40
42
  "devDependencies": {
package/text-chat.css ADDED
@@ -0,0 +1,98 @@
1
+ /* Data Navigator — Text Chat default styles */
2
+
3
+ .dn-text-chat {
4
+ display: flex;
5
+ flex-direction: column;
6
+ font-family: sans-serif;
7
+ font-size: 14px;
8
+ line-height: 1.4;
9
+ max-width: 400px;
10
+ }
11
+
12
+ .dn-text-chat-log {
13
+ max-height: 300px;
14
+ overflow-y: auto;
15
+ padding: 8px;
16
+ border: 1px solid #ccc;
17
+ border-bottom: none;
18
+ }
19
+
20
+ .dn-text-chat-message {
21
+ padding: 2px 0;
22
+ }
23
+
24
+ .dn-text-chat-system {
25
+ color: #666;
26
+ font-style: italic;
27
+ }
28
+
29
+ .dn-text-chat-input-echo {
30
+ font-family: monospace;
31
+ color: #333;
32
+ }
33
+
34
+ .dn-text-chat-response {
35
+ color: #111;
36
+ }
37
+
38
+ .dn-text-chat-controls {
39
+ padding: 4px 8px;
40
+ border: 1px solid #ccc;
41
+ border-bottom: none;
42
+ font-size: 12px;
43
+ }
44
+
45
+ .dn-text-chat-controls label {
46
+ display: flex;
47
+ align-items: center;
48
+ gap: 4px;
49
+ cursor: pointer;
50
+ }
51
+
52
+ .dn-text-chat-form {
53
+ display: flex;
54
+ border: 1px solid #ccc;
55
+ }
56
+
57
+ .dn-text-chat-form input[type="text"] {
58
+ flex: 1;
59
+ padding: 6px 8px;
60
+ border: none;
61
+ font-size: 14px;
62
+ outline: none;
63
+ }
64
+
65
+ .dn-text-chat-form input[type="text"]:focus {
66
+ box-shadow: inset 0 0 0 2px #1e3369;
67
+ }
68
+
69
+ .dn-text-chat-form button {
70
+ padding: 6px 12px;
71
+ border: none;
72
+ border-left: 1px solid #ccc;
73
+ cursor: pointer;
74
+ font-size: 14px;
75
+ }
76
+
77
+ .dn-text-chat-choices {
78
+ margin: 4px 0 0;
79
+ padding-left: 2em;
80
+ font-size: 13px;
81
+ }
82
+
83
+ .dn-text-chat-llm-thinking {
84
+ color: #666;
85
+ font-style: italic;
86
+ }
87
+
88
+ .dn-text-chat-sr-only {
89
+ position: absolute;
90
+ width: 1px;
91
+ height: 1px;
92
+ padding: 0;
93
+ margin: -1px;
94
+ overflow: hidden;
95
+ clip: rect(0, 0, 0, 0);
96
+ white-space: nowrap;
97
+ border: 0;
98
+ }