data-navigator 2.4.0 → 3.0.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
- 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};
1
+ var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(r,t)=>{for(var o in t)p(r,o,{get:t[o],enumerable:!0})},x=(r,t,o,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of m(t))!b.call(r,e)&&e!==o&&p(r,e,{get:()=>t[e],enumerable:!(l=k(t,e))||l.enumerable});return r};var h=r=>x(p({},"__esModule",{value:!0}),r);var R={};v(R,{default:()=>N});module.exports=h(R);var g={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var f={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{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 N=r=>{let t={},o=g,l=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 d=null,s=0,u=l[i];if(!u)return;let w=(c,n)=>{if(c!==i)return null;let y={target:typeof n.target=="string"?n.target:n.target(a,e),source:typeof n.source=="string"?n.source:n.source(a,e)};return y[u.direction]!==e?y[u.direction]:null};for(s=0;s<a.edges.length;s++){let c=r.structure.edges[a.edges[s]];if(c.navigationRules.forEach(n=>{d||(d=w(n,c))}),d)break}return d?t.moveTo(d):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=o[e.code];if(i)return i},t.focus=e=>{let i=document.getElementById(e);i&&i.focus()},t.setNavigationKeyBindings=e=>{e?(o={},l=e,Object.keys(e).forEach(i=>{let a=e[i];o[a.key]=i})):(o=g,l=f)},t.setNavigationKeyBindings(r.navigationRules),t};
package/dist/input.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import"./chunk-RGY6OTGO.js";export{a as default};
1
+ import{a}from"./chunk-UNB4R2QN.js";import"./chunk-7YO7HC2V.js";export{a as default};
@@ -1 +1 @@
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};
1
+ var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var W=(e,r,n)=>r in e?T(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,p=(e,r)=>{for(var n in r||(r={}))Z.call(r,n)&&W(e,n,r[n]);if(H)for(var n of H(r))q.call(r,n)&&W(e,n,r[n]);return e};var X=(e,r)=>{for(var n in r)T(e,n,{get:r[n],enumerable:!0})},ee=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of Q(r))!Z.call(e,m)&&m!==n&&T(e,m,{get:()=>r[m],enumerable:!(t=Y(r,m))||t.enumerable});return e};var te=e=>ee(T({},"__esModule",{value:!0}),e);var G=(e,r,n)=>{if(!r.has(e))throw TypeError("Cannot "+n)};var f=(e,r,n)=>(G(e,r,"read from private field"),n?n.call(e):r.get(e)),L=(e,r,n)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,n)},B=(e,r,n,t)=>(G(e,r,"write to private field"),t?t.call(e,n):r.set(e,n),n);var N=(e,r,n)=>(G(e,r,"access private method"),n);var ne={};X(ne,{default:()=>re});module.exports=te(ne);var R={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}},_={"drill-in":{label:"Enter",description:"Drill in"},"drill-out":{label:"Backspace",description:"Drill out"},exit:{label:"Esc",description:"Exit"},left:{label:"\u2190",description:"Previous data point"},right:{label:"\u2192",description:"Next data point"},up:{label:"\u2191",description:"Previous data point"},down:{label:"\u2193",description:"Next data point"},backward:{label:",",description:"Move backward"},forward:{label:".",description:"Move forward"},previous:{label:";",description:"Previous"},next:{label:"'",description:"Next"},undo:{label:"Z",description:"Undo"},help:{label:"Y",description:"Help"},legend:{label:"L",description:"Legend"}},J=[{label:"Command",id:"description"},{label:"Key",id:"label"}];var D,v,k,y,x,P,S=class extends HTMLElement{constructor(){super(...arguments);L(this,x);L(this,D,[]);L(this,v,J);L(this,k,"label");L(this,y,!1)}static get observedAttributes(){return["title"]}set commands(n){B(this,D,n),f(this,y)&&N(this,x,P).call(this)}get commands(){return f(this,D)}set columns(n){B(this,v,n),f(this,y)&&N(this,x,P).call(this)}get columns(){return f(this,v)}set kbdColumn(n){B(this,k,n),f(this,y)&&N(this,x,P).call(this)}get kbdColumn(){return f(this,k)}attributeChangedCallback(){f(this,y)&&N(this,x,P).call(this)}connectedCallback(){B(this,y,!0),N(this,x,P).call(this)}disconnectedCallback(){B(this,y,!1)}};D=new WeakMap,v=new WeakMap,k=new WeakMap,y=new WeakMap,x=new WeakSet,P=function(){this.replaceChildren();let n=[];for(let s of f(this,v)){let o=document.createElement("th");o.classList.add("dn-commands-table-th"),o.textContent=s.label,n.push(o)}let t=document.createElement("tr");t.classList.add("dn-commands-table-thead-tr");for(let s of n)t.appendChild(s);let m=document.createElement("thead");m.classList.add("dn-commands-table-thead"),m.appendChild(t);let l=document.createElement("tbody");l.classList.add("dn-commands-table-tbody");for(let s of f(this,D)){let o=[];for(let i of f(this,v)){let A=s[i.id],w=document.createElement("td");if(w.classList.add("dn-commands-table-td"),f(this,k)!==null&&i.id===f(this,k)&&A){let E=document.createElement("kbd");E.classList.add("dn-commands-table-td-kbd"),E.textContent=A,w.append(E)}else w.textContent=A;o.push(w)}let u=document.createElement("tr");u.classList.add("dn-commands-table-tbody-tr");for(let i of o)u.appendChild(i);l.appendChild(u)}let a=document.createElement("table");a.classList.add("dn-commands-table");let d=this.getAttribute("title");if(d){let s=document.createElement("caption");s.classList.add("dn-commands-table-caption"),s.textContent=d,a.appendChild(s)}else a.setAttribute("aria-label","Commands table");a.appendChild(m),a.appendChild(l),this.appendChild(a)};function z(e){return e?Object.keys(e).map(r=>_[r]).filter(Boolean):[]}var re=e=>{let r=a=>{t.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},n=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},m=!1,l={cssClass:R.cssClass,spatialProperties:p({},R.spatialProperties),semantics:p({},R.semantics),parentSemantics:p({},R.parentSemantics),existingElement:p({},R.existingElement)};return e.defaults&&(l.cssClass=e.defaults.cssClass||l.cssClass,l.spatialProperties=e.defaults.spatialProperties?p(p({},l.spatialProperties),e.defaults.spatialProperties):l.spatialProperties,l.semantics=e.defaults.semantics?p(p({},l.semantics),e.defaults.semantics):l.semantics,l.parentSemantics=e.defaults.parentSemantics?p(p({},l.parentSemantics),e.defaults.parentSemantics):l.parentSemantics,l.existingElement=e.defaults.existingElement?p(p({},l.existingElement),e.defaults.existingElement):l.existingElement),t.initialize=()=>{var a,d;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),(a=e.commandsElement)!=null&&a.include&&t.initializeCommands(e.commandsElement),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),(d=e.exitElement)!=null&&d.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",s=>{var o,u;t.exitElement.style.display="block",t.clearStructure(),(u=(o=e.exitElement)==null?void 0:o.callbacks)!=null&&u.focus&&e.exitElement.callbacks.focus(s)}),t.exitElement.addEventListener("blur",s=>{var o,u;t.exitElement.style.display="none",(u=(o=e.exitElement)==null?void 0:o.callbacks)!=null&&u.blur&&e.exitElement.callbacks.blur(s)}),t.root.appendChild(t.exitElement)),m=!0,t.root},t.render=a=>{let d=a.renderId+"",s=e.elementData[d];if(!s){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 o=!1,u={},i=(b,C,h)=>{var $;let g=s[b]||l[b],O=h&&o?u[C]:g==null?void 0:g[C],V=($=l[b])==null?void 0:$[C];return typeof g=="function"?g(s,a.datum):typeof O=="function"?O(s,a.datum):O||V||(C?void 0:g)};o=i("existingElement","useForSpatialProperties"),u=i("existingElement","spatialProperties");let A=parseFloat(i("spatialProperties","width",!0)||0),w=parseFloat(i("spatialProperties","height",!0)||0),E=parseFloat(i("spatialProperties","x",!0)||0),I=parseFloat(i("spatialProperties","y",!0)||0),c=document.createElement(i("parentSemantics","elementType")),F=i("parentSemantics","attributes");typeof F=="object"&&Object.keys(F).forEach(b=>{c.setAttribute(b,F[b])}),c.setAttribute("role",i("parentSemantics","role")),c.id=d,c.classList.add("dn-node"),c.classList.add(i("cssClass")),c.style.width=A+"px",c.style.height=w+"px",c.style.left=E+"px",c.style.top=I+"px",c.setAttribute("tabindex","0"),c.addEventListener("focus",r),c.addEventListener("blur",n);let j=document.createElement(i("semantics","elementType")),K=i("semantics","attributes");typeof K=="object"&&Object.keys(K).forEach(b=>{c.setAttribute(b,K[b])}),j.setAttribute("role",i("semantics","role")),j.classList.add("dn-node-text"),s.showText&&(j.innerText=s.semantics.label);let U=i("semantics","label");U||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),j.setAttribute("aria-label",U),c.appendChild(j);let M=i("spatialProperties","path");if(M){let b=A+E+10,C=w+I+10,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("width",b+""),h.setAttribute("height",C+""),h.setAttribute("viewBox",`0 0 ${b} ${C}`),h.style.left=-E+"px",h.style.top=-I+"px",h.classList.add("dn-node-svg"),h.setAttribute("role","presentation"),h.setAttribute("focusable","false");let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.setAttribute("d",M),g.classList.add("dn-node-path"),h.appendChild(g),c.appendChild(h)}return t.wrapper.appendChild(c),c},t.remove=a=>{let d=document.getElementById(a);t.wrapper.getAttribute("aria-activedescendant")===a&&t.wrapper.setAttribute("aria-activedescendant",""),d&&(d.removeEventListener("focus",r),d.removeEventListener("blur",n),d.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(a=>{t.entryButton&&t.entryButton===a||t.remove(a.id)})},t.initializeCommands=a=>{let d=document.getElementById(a==null?void 0:a.rootId);if(!d){console.error("Commands root element not found in document.");return}let s=a.commands,o=z(a.navigationRules),u=s?typeof s=="function"?s(o):s:o;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",S);let i=document.createElement("dn-commands-table");return a!=null&&a.title&&i.setAttribute("title",a.title),i.commands=u,a.columns&&(i.columns=a.columns),d.appendChild(i),i},t.getGenericCommandsFromNavRules=z,t.CommandsTable=S,t};
package/dist/rendering.js CHANGED
@@ -1 +1 @@
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
+ import{c as H}from"./chunk-XOJI42HR.js";import{a as o,c as m,d as L,e as k,f as B,q as P,s as O}from"./chunk-7YO7HC2V.js";var T,w,v,h,E,S,j=class extends HTMLElement{constructor(){super(...arguments);L(this,E);L(this,T,[]);L(this,w,O);L(this,v,"label");L(this,h,!1)}static get observedAttributes(){return["title"]}set commands(b){k(this,T,b),m(this,h)&&B(this,E,S).call(this)}get commands(){return m(this,T)}set columns(b){k(this,w,b),m(this,h)&&B(this,E,S).call(this)}get columns(){return m(this,w)}set kbdColumn(b){k(this,v,b),m(this,h)&&B(this,E,S).call(this)}get kbdColumn(){return m(this,v)}attributeChangedCallback(){m(this,h)&&B(this,E,S).call(this)}connectedCallback(){k(this,h,!0),B(this,E,S).call(this)}disconnectedCallback(){k(this,h,!1)}};T=new WeakMap,w=new WeakMap,v=new WeakMap,h=new WeakMap,E=new WeakSet,S=function(){this.replaceChildren();let b=[];for(let a of m(this,w)){let i=document.createElement("th");i.classList.add("dn-commands-table-th"),i.textContent=a.label,b.push(i)}let e=document.createElement("tr");e.classList.add("dn-commands-table-thead-tr");for(let a of b)e.appendChild(a);let x=document.createElement("thead");x.classList.add("dn-commands-table-thead"),x.appendChild(e);let r=document.createElement("tbody");r.classList.add("dn-commands-table-tbody");for(let a of m(this,T)){let i=[];for(let s of m(this,w)){let A=a[s.id],C=document.createElement("td");if(C.classList.add("dn-commands-table-td"),m(this,v)!==null&&s.id===m(this,v)&&A){let y=document.createElement("kbd");y.classList.add("dn-commands-table-td-kbd"),y.textContent=A,C.append(y)}else C.textContent=A;i.push(C)}let c=document.createElement("tr");c.classList.add("dn-commands-table-tbody-tr");for(let s of i)c.appendChild(s);r.appendChild(c)}let n=document.createElement("table");n.classList.add("dn-commands-table");let l=this.getAttribute("title");if(l){let a=document.createElement("caption");a.classList.add("dn-commands-table-caption"),a.textContent=l,n.appendChild(a)}else n.setAttribute("aria-label","Commands table");n.appendChild(x),n.appendChild(r),this.appendChild(n)};var X=t=>{let R=n=>{e.wrapper.setAttribute("aria-activedescendant",n.srcElement.id)},b=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},x=!1,r={cssClass:P.cssClass,spatialProperties:o({},P.spatialProperties),semantics:o({},P.semantics),parentSemantics:o({},P.parentSemantics),existingElement:o({},P.existingElement)};return t.defaults&&(r.cssClass=t.defaults.cssClass||r.cssClass,r.spatialProperties=t.defaults.spatialProperties?o(o({},r.spatialProperties),t.defaults.spatialProperties):r.spatialProperties,r.semantics=t.defaults.semantics?o(o({},r.semantics),t.defaults.semantics):r.semantics,r.parentSemantics=t.defaults.parentSemantics?o(o({},r.parentSemantics),t.defaults.parentSemantics):r.parentSemantics,r.existingElement=t.defaults.existingElement?o(o({},r.existingElement),t.defaults.existingElement):r.existingElement),e.initialize=()=>{var n,l;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),(n=t.commandsElement)!=null&&n.include&&e.initializeCommands(t.commandsElement),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),(l=t.exitElement)!=null&&l.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=>{var i,c;e.exitElement.style.display="block",e.clearStructure(),(c=(i=t.exitElement)==null?void 0:i.callbacks)!=null&&c.focus&&t.exitElement.callbacks.focus(a)}),e.exitElement.addEventListener("blur",a=>{var i,c;e.exitElement.style.display="none",(c=(i=t.exitElement)==null?void 0:i.callbacks)!=null&&c.blur&&t.exitElement.callbacks.blur(a)}),e.root.appendChild(e.exitElement)),x=!0,e.root},e.render=n=>{let l=n.renderId+"",a=t.elementData[l];if(!a){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 i=!1,c={},s=(u,g,f)=>{var G;let p=a[u]||r[u],z=f&&i?c[g]:p==null?void 0:p[g],V=(G=r[u])==null?void 0:G[g];return typeof p=="function"?p(a,n.datum):typeof z=="function"?z(a,n.datum):z||V||(g?void 0:p)};i=s("existingElement","useForSpatialProperties"),c=s("existingElement","spatialProperties");let A=parseFloat(s("spatialProperties","width",!0)||0),C=parseFloat(s("spatialProperties","height",!0)||0),y=parseFloat(s("spatialProperties","x",!0)||0),N=parseFloat(s("spatialProperties","y",!0)||0),d=document.createElement(s("parentSemantics","elementType")),D=s("parentSemantics","attributes");typeof D=="object"&&Object.keys(D).forEach(u=>{d.setAttribute(u,D[u])}),d.setAttribute("role",s("parentSemantics","role")),d.id=l,d.classList.add("dn-node"),d.classList.add(s("cssClass")),d.style.width=A+"px",d.style.height=C+"px",d.style.left=y+"px",d.style.top=N+"px",d.setAttribute("tabindex","0"),d.addEventListener("focus",R),d.addEventListener("blur",b);let I=document.createElement(s("semantics","elementType")),F=s("semantics","attributes");typeof F=="object"&&Object.keys(F).forEach(u=>{d.setAttribute(u,F[u])}),I.setAttribute("role",s("semantics","role")),I.classList.add("dn-node-text"),a.showText&&(I.innerText=a.semantics.label);let M=s("semantics","label");M||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),I.setAttribute("aria-label",M),d.appendChild(I);let $=s("spatialProperties","path");if($){let u=A+y+10,g=C+N+10,f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("width",u+""),f.setAttribute("height",g+""),f.setAttribute("viewBox",`0 0 ${u} ${g}`),f.style.left=-y+"px",f.style.top=-N+"px",f.classList.add("dn-node-svg"),f.setAttribute("role","presentation"),f.setAttribute("focusable","false");let p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",$),p.classList.add("dn-node-path"),f.appendChild(p),d.appendChild(f)}return e.wrapper.appendChild(d),d},e.remove=n=>{let l=document.getElementById(n);e.wrapper.getAttribute("aria-activedescendant")===n&&e.wrapper.setAttribute("aria-activedescendant",""),l&&(l.removeEventListener("focus",R),l.removeEventListener("blur",b),l.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(n=>{e.entryButton&&e.entryButton===n||e.remove(n.id)})},e.initializeCommands=n=>{let l=document.getElementById(n==null?void 0:n.rootId);if(!l){console.error("Commands root element not found in document.");return}let a=n.commands,i=H(n.navigationRules),c=a?typeof a=="function"?a(i):a:i;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let s=document.createElement("dn-commands-table");return n!=null&&n.title&&s.setAttribute("title",n.title),s.commands=c,n.columns&&(s.columns=n.columns),l.appendChild(s),s},e.getGenericCommandsFromNavRules=H,e.CommandsTable=j,e};export{X as default};
@@ -1 +1 @@
1
- var V=Object.defineProperty,be=Object.defineProperties,pe=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,Ke=Object.prototype.propertyIsEnumerable;var ee=(e,a,i)=>a in e?V(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,F=(e,a)=>{for(var i in a||(a={}))ie.call(a,i)&&ee(e,i,a[i]);if(X)for(var i of X(a))Ke.call(a,i)&&ee(e,i,a[i]);return e},te=(e,a)=>be(e,me(a));var Ee=(e,a)=>{for(var i in a)V(e,i,{get:a[i],enumerable:!0})},Ie=(e,a,i,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let h of Oe(a))!ie.call(e,h)&&h!==i&&V(e,h,{get:()=>a[h],enumerable:!(c=pe(a,h))||c.enumerable});return e};var xe=e=>Ie(V({},"__esModule",{value:!0}),e);var je={};Ee(je,{addSimpleDataIDs:()=>ce,buildEdges:()=>fe,buildNodeStructureFromVegaLite:()=>le,buildNodes:()=>ue,buildRules:()=>ve,buildStructure:()=>ye,default:()=>Re,scaffoldDimensions:()=>ge});module.exports=xe(je);var ne={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var se=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var re=[["LeftBracket","RightBracket"],["Slash","Backslash"]],H={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"}},oe=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ae={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 de=(e,a)=>{let i=Object.keys(e),c="";return i.forEach(h=>{c+=`${a&&a.omitKeyNames?"":h+": "}${e[h]}. `}),c+=a&&a.semanticLabel||"Data point.",c},q=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var Re=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?le(e):ye(e),le=e=>{let a=ae,i={},c={},h={},d=0,B=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,P=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,m=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,b=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],I=(n,o)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let l=`dn-node-${o}-${d}`;return d++,n["data-navigator-id"]=l,l},r=n=>{let o=i[n],l=o.index,u=o.level,y=o.parent,g=[],f=y.items[l-1];if(f){let v=I(f,u);if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["left","right"]})}}let E=y.items[l+1];if(E){let v=I(E,u);if(i[v]){let K=`${o.id}-${v}`;g.push(K),c[K]||(c[K]={source:o.id,target:v,navigationRules:["left","right"]})}}if(u==="group"&&y.items[l].items){let K=(y.items[l].items[0].mark.items[0].items||y.items[l].items)[0],O=I(K,"item");if(i[O]){let t=`${o.id}-${O}`;g.push(t),c[t]||(c[t]={source:o.id,target:O,navigationRules:["parent","child"]})}}else if(u==="item"){let v=I(y,"group");if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(g.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),g.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),g},x=(n,o,l,u,y)=>{let g=I(n,o),f="render-"+g,E=l||[0,0];i[g]={},i[g].d={},i[g].id=g,i[g].renderId=f,i[g].index=u,i[g].level=o,i[g].parent=y,h[f]={},h[f].renderId=f,h[f].spatialProperties={},h[f].spatialProperties.x=n.bounds.x1+E[0],h[f].spatialProperties.y=n.bounds.y1+E[1],h[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,h[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,h[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(v=>{let K=n.datum[v];m(v,K,n.datum,o,e.vegaLiteSpec)&&(i[g].d[e.keyRenamingHash&&e.keyRenamingHash[v]?e.keyRenamingHash[v]:v]=K)}),h[f].semantics={},h[f].semantics.label=e.nodeDescriber?e.nodeDescriber(i[g].d,n,o):de(i[g].d)},j=0;return b.items.forEach(n=>{if(B(n,j,e.vegaLiteSpec)){x(n,"group",s,j,b);let o=0,l=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;l.items.forEach(u=>{P(u,o,n,e.vegaLiteSpec)&&x(u,"item",s,o,l),o++})}j++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:h,navigationRules:a}},ce=e=>{let a=0,i={};e.data.forEach(c=>{let h=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[h]="_"+a,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[h]+="_"+d+i[d]+"_"+c[d]+i[c[d]],i[d]++,i[c[d]]++):(i[d]||(i[d]=0),c[h]+="_"+d+i[d],i[d]++))}),a++})},ue=e=>{let a={};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,h=i[c];if(!h){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(a[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;a[h]={id:h,edges:[],renderId:d?i[d]||"":i.renderIdKey||"",data:i}}}),a},ge=(e,a)=>{var d,B,P;let i={};if((B=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&B.addLevel0){let m=e.dimensions.parentOptions.addLevel0;a[m.id]=te(F({},m),{dimensionLevel:0})}let c=[...oe],h=(m,s)=>{let b=s.numericalExtents[0],I=s.numericalExtents[1];s.numericalExtents[0]=b<m?b:m,s.numericalExtents[1]=I>m?I:m};return e.data.forEach(m=>{var I;let s=((I=e.dimensions)==null?void 0:I.values)||[],b=0;s.forEach(r=>{var x,j,p,n,o,l,u,y;if(!r.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(r)}.`);return}if(r.dimensionKey in m){let g=m[r.dimensionKey],f=typeof((x=r.operations)==null?void 0:x.filterFunction)=="function"?r.operations.filterFunction(m,r):!0;if(g!==void 0&&f){if(r.type||(r.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[r.dimensionKey]){let O=typeof r.nodeId=="function"?r.nodeId(r,e.data):r.nodeId||q(r.dimensionKey),t=typeof r.renderId=="function"?r.renderId(r,e.data):r.renderId||O;i[r.dimensionKey]={dimensionKey:r.dimensionKey,nodeId:O,divisions:{},numericalExtents:[1/0,-1/0],type:r.type,operations:{compressSparseDivisions:((j=r.operations)==null?void 0:j.compressSparseDivisions)||!1,sortFunction:((p=r.operations)==null?void 0:p.sortFunction)||void 0},behavior:r.behavior||{extents:"circular"},navigationRules:r.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+r.dimensionKey,"next_"+r.dimensionKey],parent_child:["parent_"+r.dimensionKey,"child"]}},a[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:1,data:i[r.dimensionKey],renderingStrategy:r.renderingStrategy||"singleSquare"}}let E=i[r.dimensionKey],v=null;if(r.type==="categorical"){let O=typeof((n=r.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(r.dimensionKey,g,b):q(E.nodeId+"_"+g);if(v=E.divisions[O],!v){v=E.divisions[O]={id:O,sortFunction:((o=r.divisionOptions)==null?void 0:o.sortFunction)||void 0,values:{}};let t=typeof((l=r.divisionOptions)==null?void 0:l.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(r.dimensionKey,g,b):O;a[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:2,data:F({},v),renderingStrategy:((u=r.divisionOptions)==null?void 0:u.renderingStrategy)||"singleSquare"},a[O].data[r.dimensionKey]=g}}else{v=E.divisions[E.nodeId],v||(v=E.divisions[E.nodeId]={id:E.nodeId,sortFunction:((y=r.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}}),r.operations||(r.operations={});let O=r.operations.createNumericalSubdivisions;E.subdivisions=typeof O=="number"&&O<1?1:O||1,O!==1&&(E.divisionOptions||(E.divisionOptions=r.divisionOptions),h(g,E))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}b++})}),Object.keys(i).forEach(m=>{var r,x,j,p,n;let s=i[m],b=s.divisions;if(s.type==="numerical"){b[s.nodeId].values=Object.fromEntries(Object.entries(b[s.nodeId].values).sort((l,u)=>{var y;return typeof((y=s.operations)==null?void 0:y.sortFunction)=="function"?s.operations.sortFunction(l[1],u[1],s):l[1][m]-u[1][m]}));let o=b[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let l=Object.keys(o),u=typeof s.subdivisions=="function"?s.subdivisions(m,o):s.subdivisions,g=(s.numericalExtents[1]-s.numericalExtents[0])/u,f=s.numericalExtents[0]+g,E=0,v=0,K=null,O=s.numericalExtents[0];for(f=s.numericalExtents[0]+g;f<=s.numericalExtents[1];f+=g){let t=typeof((r=s.divisionOptions)==null?void 0:r.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(m,f,f):q(s.nodeId+"_"+f);K=t,s.divisions[t]={id:t,sortFunction:((x=s.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{},numericalExtents:[O,f]};let $=typeof((j=s.divisionOptions)==null?void 0:j.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(m,f,f):t;a[t]={id:t,renderId:$,derivedNode:m,edges:[],data:s.divisions[t],dimensionLevel:2,renderingStrategy:((p=s.divisionOptions)==null?void 0:p.renderingStrategy)||"singleSquare"};let G=!1;for(;!G&&v<l.length;){let T=o[l[v]];T[m]<=f?(s.divisions[t].values[T.id]=T,v++):G=!0}O=f,E++}if(K&&v<l.length)for(;v<l.length;){let t=o[l[v]];s.divisions[K].values[t.id]=t,v++}delete b[m]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(b).sort((o,l)=>s.operations.sortFunction(o[1],l[1],s))));Object.keys(s.divisions).forEach(o=>{let l=s.divisions[o];typeof l.sortFunction=="function"&&(l.values=Object.fromEntries(Object.entries(l.values).sort((u,y)=>l.sortFunction(u[1],y[1],l))))})}),Object.keys(i).forEach(m=>{let s=i[m];if(s.operations.compressSparseDivisions){let b=Object.keys(s.divisions),I={},r=!0;if(b.forEach(x=>{let j=s.divisions[x],p=Object.keys(j.values);p.length<=1?p.forEach(n=>{I[n]=F({},j.values[n])}):r=!1}),r){let x={id:s.nodeId,values:I};b.forEach(j=>{delete a[j]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},fe=(e,a,i)=>{var B,P,m,s,b,I,r,x,j,p;let c={},h=(n,o)=>{a[n].edges.indexOf(o)===-1&&a[n].edges.push(o)},d=(n,o,l,u)=>{let y=`${n}-${o}`,g=e.useDirectedEdges?`${o}-${y}`:y,f=!u||u==="source",E=!u||u==="target",v=K=>{c[K]?c[K].navigationRules.push(...l||[]):c[K]={source:n,target:o,navigationRules:l?[...l]:[]}};v(y),e.useDirectedEdges&&E&&v(g),f&&h(n,y),E&&h(o,g)};if(i&&Object.keys(i).length){let n=Object.keys(i),o=(m=(P=(B=e.dimensions)==null?void 0:B.parentOptions)==null?void 0:P.level1Options)==null?void 0:m.order,l=o||n,u=0,y=((s=e.dimensions)==null?void 0:s.parentOptions)||{},g=((I=(b=y.level1Options)==null?void 0:b.behavior)==null?void 0:I.extents)||"terminal",f=y.addLevel0,E=f?((x=(r=y.level1Options)==null?void 0:r.navigationRules)==null?void 0:x.parent_child)||["parent","child"]:[],v=((p=(j=y.level1Options)==null?void 0:j.navigationRules)==null?void 0:p.sibling_sibling)||["left","right"],K=typeof l[0]=="string"?o?a[l[0]]:a[i[l[0]].nodeId]:l[0];f&&d(f.id,K.id,E,"source"),l.forEach(O=>{let t=typeof O=="string"?o?a[O]:a[i[O].nodeId]:O;if(t===O&&!a[t.id]&&(a[t.id]=t),f&&(e.useDirectedEdges?d(t.id,f.id,E,"source"):d(f.id,t.id,E,"target")),u===l.length-1&&g==="circular")d(t.id,K.id,v);else if(u===l.length-1&&g==="bridgedCustom")d(t.id,y.level1Options.behavior.customBridgePost,v);else if(u<l.length-1){let $=typeof l[u+1]=="string"?o?a[l[u+1]]:a[i[l[u+1]].nodeId]:l[u+1];d(t.id,$.id,v)}!u&&g==="bridgedCustom"&&d(y.level1Options.behavior.customBridgePost,t.id,v),u++}),n.forEach(O=>{var W,Y,Z,z;let t=i[O],$=((W=t.behavior)==null?void 0:W.childmostNavigation)||"within",G=(A,w,R,C)=>C.values[Object.keys(C.values)[A]]||void 0,T=$==="across"&&((Y=t.behavior)!=null&&Y.childmostMatching)?(Z=t.behavior)==null?void 0:Z.childmostMatching:G,L=((z=t.behavior)==null?void 0:z.extents)||"circular";t.divisions||console.error(`Parsing dimensions. The dimension using the key ${O} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(t)}.`);let D=Object.keys(t.divisions),U=t.divisions[D[0]];if(D.length!==1)d(t.nodeId,U.id,t.navigationRules.parent_child,"source");else{let A=Object.keys(U.values),w=typeof e.idKey=="function"?e.idKey(U.values[A[0]]):e.idKey;d(t.nodeId,U.values[A[0]][w],t.navigationRules.parent_child,"source")}let N=0;D.forEach(A=>{let w=t.divisions[A];N===D.length-1&&(L==="circular"||L==="bridgedCousins"||L==="bridgedCustom")?d(w.id,t.divisions[D[0]].id,t.navigationRules.sibling_sibling):N<D.length-1&&d(w.id,t.divisions[D[N+1]].id,t.navigationRules.sibling_sibling);let R=Object.keys(w.values);if(e.useDirectedEdges?d(w.id,t.nodeId,t.navigationRules.parent_child,"source"):d(t.nodeId,w.id,t.navigationRules.parent_child,"target"),R.length>0){let J=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(w.id,w.values[R[0]][J],t.navigationRules.parent_child,"source")}let C=0;R.length>=1&&R.forEach(J=>{let k=w.values[J],S=typeof e.idKey=="function"?e.idKey(k):e.idKey,Q=D.length!==1?w.id:t.nodeId;if(e.useDirectedEdges?d(k[S],Q,t.navigationRules.parent_child,"source"):d(Q,k[S],t.navigationRules.parent_child,"target"),$==="within"){if(C===R.length-1&&L==="circular"){let _=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(k[S],w.values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCousins")if(N!==D.length-1){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N+1]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[N+1]].values[R[0]][_],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[0]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[0]].values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(C<R.length-1){let _=typeof e.idKey=="function"?e.idKey(w.values[R[C+1]]):e.idKey;d(k[S],w.values[R[C+1]][_],t.navigationRules.sibling_sibling)}if(!C&&L==="bridgedCousins")if(N!==0){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[N-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[D.length-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else!C&&L==="bridgedCustom"&&d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling)}else if(N===D.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(!N&&L==="bridgedCustom")d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling);else{let _=N===D.length-1&&L==="circular"?t.divisions[D[0]]:t.divisions[D[N+1]];if(_){let M=T(C,k[S],w,_);if(M){let he=typeof e.idKey=="function"?e.idKey(M):e.idKey;d(k[S],M[he],t.navigationRules.sibling_sibling)}}}C++}),N++})})}return Object.keys(a).forEach(n=>{var l;let o=a[n];(l=e.genericEdges)!=null&&l.length&&e.genericEdges.forEach(u=>{c[u.edgeId]||(c[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(o,u))&&o.edges.push(u.edgeId)})}),c},ve=(e,a,i)=>{var h,d,B,P;let c=e.navigationRules;if(!c){let m=Object.keys(i||{});m.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 ${m.length}. Dimensions counted: ${m.join(", ")}.`);let s={},b={},I={},r=[...re],x=[...se],j=(p,n)=>{let o=p&&n,l=!1,u=!1;if((s[p]||b[p])&&(b[p]=F({},s[p]),l=!0),n&&(s[n]||b[n])&&(b[n]=F({},s[n]),u=!0),o&&!l&&!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 y=[...r.shift()];x.splice(x.indexOf(y[0]),1),x.splice(x.indexOf(y[1]),1),b[p]={direction:e.useDirectedEdges?"target":"source",key:y[0]},b[n]={direction:"target",key:y[1]}}else{if(!b[p]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[p]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!b[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[n]={direction:"target",key:y}}x.length||(b[p]||(I[p]=p),n&&!b[n]&&(I[n]=n))}};if(Object.keys(H).forEach(p=>{let n=F({},H[p]);e.useDirectedEdges&&(n.direction="target"),s[p]=n}),m.length){if((d=(h=e.dimensions)==null?void 0:h.parentOptions)!=null&&d.addLevel0){let p=((P=(B=e.dimensions.parentOptions.level1Options)==null?void 0:B.navigationRules)==null?void 0:P.parent_child)||["parent","child"];j(p[0],p[1])}m.forEach(p=>{let n=i[p].navigationRules.parent_child,o=i[p].navigationRules.sibling_sibling;j(n[0],n[1]),j(o[0],o[1])})}if(Object.keys(a).forEach(p=>{a[p].navigationRules.forEach(n=>{b[n]||j(n)})}),Object.keys(I).length){let p={};Object.keys(b).forEach(o=>{p[b[o].key]=b[o].key}),Object.keys(s).forEach(o=>{!p[s[o].key]&&!ne[s[o].key]&&x.push(s[o].key)});let n=F({},I);I={},Object.keys(n).forEach(o=>{j(o)}),Object.keys(I).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(I).join(", ")}.`)}c=b}return c},ye=e=>{e.addIds&&ce(e);let a=ue(e),i=ge(e,a),c=fe(e,a,i),h=ve(e,c,i);return{nodes:a,edges:c,dimensions:i,navigationRules:h}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
1
+ var J=Object.defineProperty,Ke=Object.defineProperties,Ee=Object.getOwnPropertyDescriptor,Ie=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertyNames,te=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var ne=(e,d,i)=>d in e?J(e,d,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[d]=i,T=(e,d)=>{for(var i in d||(d={}))se.call(d,i)&&ne(e,i,d[i]);if(te)for(var i of te(d))je.call(d,i)&&ne(e,i,d[i]);return e},re=(e,d)=>Ke(e,Ie(d));var Re=(e,d)=>{for(var i in d)J(e,i,{get:d[i],enumerable:!0})},De=(e,d,i,c)=>{if(d&&typeof d=="object"||typeof d=="function")for(let b of xe(d))!se.call(e,b)&&b!==i&&J(e,b,{get:()=>d[b],enumerable:!(c=Ee(d,b))||c.enumerable});return e};var ke=e=>De(J({},"__esModule",{value:!0}),e);var Ne={};Re(Ne,{addSimpleDataIDs:()=>fe,buildEdges:()=>be,buildNodeStructureFromVegaLite:()=>ge,buildNodes:()=>ve,buildRules:()=>he,buildStructure:()=>pe,default:()=>we,scaffoldDimensions:()=>ye});module.exports=ke(Ne);var oe={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var de=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var ae=[["LeftBracket","RightBracket"],["Slash","Backslash"]],Z={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{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"}},le=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ce={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var ue=(e,d)=>{let i=Object.keys(e),c="";return i.forEach(b=>{c+=`${d&&d.omitKeyNames?"":b+": "}${e[b]}. `}),c+=d&&d.semanticLabel||"Data point.",c},H=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var we=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ge(e):pe(e),ge=e=>{let d=ce,i={},c={},b={},l=0,L=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,P=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,m=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,h=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],I=(n,o)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let a=`dn-node-${o}-${l}`;return l++,n["data-navigator-id"]=a,a},r=n=>{let o=i[n],a=o.index,u=o.level,y=o.parent,g=[],f=y.items[a-1];if(f){let v=I(f,u);if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["left","right"]})}}let E=y.items[a+1];if(E){let v=I(E,u);if(i[v]){let K=`${o.id}-${v}`;g.push(K),c[K]||(c[K]={source:o.id,target:v,navigationRules:["left","right"]})}}if(u==="group"&&y.items[a].items){let K=(y.items[a].items[0].mark.items[0].items||y.items[a].items)[0],O=I(K,"item");if(i[O]){let t=`${o.id}-${O}`;g.push(t),c[t]||(c[t]={source:o.id,target:O,navigationRules:["drill-out","drill-in"]})}}else if(u==="item"){let v=I(y,"group");if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["drill-out","drill-in"]})}}return e.exitFunction&&(g.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),g.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),g},x=(n,o,a,u,y)=>{let g=I(n,o),f="render-"+g,E=a||[0,0];i[g]={},i[g].d={},i[g].id=g,i[g].renderId=f,i[g].index=u,i[g].level=o,i[g].parent=y,b[f]={},b[f].renderId=f,b[f].spatialProperties={},b[f].spatialProperties.x=n.bounds.x1+E[0],b[f].spatialProperties.y=n.bounds.y1+E[1],b[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,b[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,b[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(v=>{let K=n.datum[v];m(v,K,n.datum,o,e.vegaLiteSpec)&&(i[g].d[e.keyRenamingHash&&e.keyRenamingHash[v]?e.keyRenamingHash[v]:v]=K)}),b[f].semantics={},b[f].semantics.label=e.nodeDescriber?e.nodeDescriber(i[g].d,n,o):ue(i[g].d)},R=0;return h.items.forEach(n=>{if(L(n,R,e.vegaLiteSpec)){x(n,"group",s,R,h);let o=0,a=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;a.items.forEach(u=>{P(u,o,n,e.vegaLiteSpec)&&x(u,"item",s,o,a),o++})}R++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:b,navigationRules:d}},fe=e=>{let d=0,i={};e.data.forEach(c=>{let b=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[b]="_"+d,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(l=>{l in c&&(typeof c[l]=="string"?(i[l]||(i[l]=0),i[c[l]]||(i[c[l]]=0),c[b]+="_"+l+i[l]+"_"+c[l]+i[c[l]],i[l]++,i[c[l]]++):(i[l]||(i[l]=0),c[b]+="_"+l+i[l],i[l]++))}),d++})},ve=e=>{let d={};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,b=i[c];if(!b){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(d[b]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${b}.`);return}else{let l=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;d[b]={id:b,edges:[],renderId:l?i[l]||"":i.renderIdKey||"",data:i}}}),d},ye=(e,d)=>{var l,L,P;let i={};if((L=(l=e.dimensions)==null?void 0:l.parentOptions)!=null&&L.addLevel0){let m=e.dimensions.parentOptions.addLevel0;d[m.id]=re(T({},m),{dimensionLevel:0})}let c=[...le],b=(m,s)=>{let h=s.numericalExtents[0],I=s.numericalExtents[1];s.numericalExtents[0]=h<m?h:m,s.numericalExtents[1]=I>m?I:m};return e.data.forEach(m=>{var I;let s=((I=e.dimensions)==null?void 0:I.values)||[],h=0;s.forEach(r=>{var x,R,p,n,o,a,u,y;if(!r.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(r)}.`);return}if(r.dimensionKey in m){let g=m[r.dimensionKey],f=typeof((x=r.operations)==null?void 0:x.filterFunction)=="function"?r.operations.filterFunction(m,r):!0;if(g!==void 0&&f){if(r.type||(r.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[r.dimensionKey]){let O=typeof r.nodeId=="function"?r.nodeId(r,e.data):r.nodeId||H(r.dimensionKey),t=typeof r.renderId=="function"?r.renderId(r,e.data):r.renderId||O;i[r.dimensionKey]={dimensionKey:r.dimensionKey,nodeId:O,divisions:{},numericalExtents:[1/0,-1/0],type:r.type,operations:{compressSparseDivisions:((R=r.operations)==null?void 0:R.compressSparseDivisions)||!1,sortFunction:((p=r.operations)==null?void 0:p.sortFunction)||void 0},behavior:r.behavior||{extents:"circular"},navigationRules:r.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+r.dimensionKey,"next_"+r.dimensionKey],parent_child:["drill-out_"+r.dimensionKey,"drill-in"]}},d[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:1,data:i[r.dimensionKey],renderingStrategy:r.renderingStrategy||"singleSquare"}}let E=i[r.dimensionKey],v=null;if(r.type==="categorical"){let O=typeof((n=r.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(r.dimensionKey,g,h):H(E.nodeId+"_"+g);if(v=E.divisions[O],!v){v=E.divisions[O]={id:O,sortFunction:((o=r.divisionOptions)==null?void 0:o.sortFunction)||void 0,values:{}};let t=typeof((a=r.divisionOptions)==null?void 0:a.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(r.dimensionKey,g,h):O;d[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:2,data:T({},v),renderingStrategy:((u=r.divisionOptions)==null?void 0:u.renderingStrategy)||"singleSquare"},d[O].data[r.dimensionKey]=g}}else{v=E.divisions[E.nodeId],v||(v=E.divisions[E.nodeId]={id:E.nodeId,sortFunction:((y=r.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}}),r.operations||(r.operations={});let O=r.operations.createNumericalSubdivisions;E.subdivisions=typeof O=="number"&&O<1?1:O||1,O!==1&&(E.divisionOptions||(E.divisionOptions=r.divisionOptions),b(g,E))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}h++})}),Object.keys(i).forEach(m=>{var r,x,R,p,n;let s=i[m],h=s.divisions;if(s.type==="numerical"){h[s.nodeId].values=Object.fromEntries(Object.entries(h[s.nodeId].values).sort((a,u)=>{var y;return typeof((y=s.operations)==null?void 0:y.sortFunction)=="function"?s.operations.sortFunction(a[1],u[1],s):a[1][m]-u[1][m]}));let o=h[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let a=Object.keys(o),u=typeof s.subdivisions=="function"?s.subdivisions(m,o):s.subdivisions,g=(s.numericalExtents[1]-s.numericalExtents[0])/u,f=s.numericalExtents[0]+g,E=0,v=0,K=null,O=s.numericalExtents[0];for(f=s.numericalExtents[0]+g;f<=s.numericalExtents[1];f+=g){let t=typeof((r=s.divisionOptions)==null?void 0:r.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(m,f,f):H(s.nodeId+"_"+f);K=t,s.divisions[t]={id:t,sortFunction:((x=s.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{},numericalExtents:[O,f]};let A=typeof((R=s.divisionOptions)==null?void 0:R.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(m,f,f):t;d[t]={id:t,renderId:A,derivedNode:m,edges:[],data:s.divisions[t],dimensionLevel:2,renderingStrategy:((p=s.divisionOptions)==null?void 0:p.renderingStrategy)||"singleSquare"};let M=!1;for(;!M&&v<a.length;){let G=o[a[v]];if(G[m]<=f){let D=typeof e.idKey=="function"?e.idKey(G):G[e.idKey];s.divisions[t].values[D]=G,v++}else M=!0}O=f,E++}if(K&&v<a.length)for(;v<a.length;){let t=o[a[v]],A=typeof e.idKey=="function"?e.idKey(t):t[e.idKey];s.divisions[K].values[A]=t,v++}delete h[s.nodeId]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(h).sort((o,a)=>s.operations.sortFunction(o[1],a[1],s))));Object.keys(s.divisions).forEach(o=>{let a=s.divisions[o];typeof a.sortFunction=="function"&&(a.values=Object.fromEntries(Object.entries(a.values).sort((u,y)=>a.sortFunction(u[1],y[1],a))))})}),Object.keys(i).forEach(m=>{let s=i[m];if(s.operations.compressSparseDivisions){let h=Object.keys(s.divisions),I={},r=!0;if(h.forEach(x=>{let R=s.divisions[x],p=Object.keys(R.values);p.length<=1?p.forEach(n=>{I[n]=T({},R.values[n])}):r=!1}),r){let x={id:s.nodeId,values:I};h.forEach(R=>{delete d[R]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},be=(e,d,i)=>{var L,P,m,s,h,I,r,x,R,p;let c={},b=(n,o)=>{d[n].edges.indexOf(o)===-1&&d[n].edges.push(o)},l=(n,o,a,u)=>{let y=`${n}-${o}`,g=e.useDirectedEdges?`${o}-${y}`:y,f=!u||u==="source",E=!u||u==="target",v=K=>{c[K]?c[K].navigationRules.push(...a||[]):c[K]={source:n,target:o,navigationRules:a?[...a]:[]}};v(y),e.useDirectedEdges&&E&&v(g),f&&b(n,y),E&&b(o,g)};if(i&&Object.keys(i).length){let n=Object.keys(i),o=(m=(P=(L=e.dimensions)==null?void 0:L.parentOptions)==null?void 0:P.level1Options)==null?void 0:m.order,a=o||n,u=0,y=((s=e.dimensions)==null?void 0:s.parentOptions)||{},g=((I=(h=y.level1Options)==null?void 0:h.behavior)==null?void 0:I.extents)||"terminal",f=y.addLevel0,E=f?((x=(r=y.level1Options)==null?void 0:r.navigationRules)==null?void 0:x.parent_child)||["drill-out","drill-in"]:[],v=((p=(R=y.level1Options)==null?void 0:R.navigationRules)==null?void 0:p.sibling_sibling)||["left","right"],K=typeof a[0]=="string"?o?d[a[0]]:d[i[a[0]].nodeId]:a[0];f&&l(f.id,K.id,E,"source"),a.forEach(O=>{let t=typeof O=="string"?o?d[O]:d[i[O].nodeId]:O;if(t===O&&!d[t.id]&&(d[t.id]=t),f&&(e.useDirectedEdges?l(t.id,f.id,E,"source"):l(f.id,t.id,E,"target")),u===a.length-1&&g==="circular")l(t.id,K.id,v);else if(u===a.length-1&&g==="bridgedCustom")l(t.id,y.level1Options.behavior.customBridgePost,v);else if(u<a.length-1){let A=typeof a[u+1]=="string"?o?d[a[u+1]]:d[i[a[u+1]].nodeId]:a[u+1];l(t.id,A.id,v)}!u&&g==="bridgedCustom"&&l(y.level1Options.behavior.customBridgePost,t.id,v),u++}),n.forEach(O=>{var z,Q,X,ee;let t=i[O],A=((z=t.behavior)==null?void 0:z.childmostNavigation)||"within",M=(F,j,k,w)=>w.values[Object.keys(w.values)[F]]||void 0,G=A==="across"&&((Q=t.behavior)!=null&&Q.childmostMatching)?(X=t.behavior)==null?void 0:X.childmostMatching:M,S=((ee=t.behavior)==null?void 0:ee.extents)||"circular";t.divisions||console.error(`Parsing dimensions. The dimension using the key ${O} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(t)}.`);let D=Object.keys(t.divisions),q=t.divisions[D[0]];if(D.length!==1)l(t.nodeId,q.id,t.navigationRules.parent_child,"source");else{let F=Object.keys(q.values),j=typeof e.idKey=="function"?e.idKey(q.values[F[0]]):e.idKey;l(t.nodeId,q.values[F[0]][j],t.navigationRules.parent_child,"source")}let me=F=>{for(let j=1;j<D.length;j++){let k=(F+j)%D.length;if(Object.keys(t.divisions[D[k]].values).length>0)return k}return null},Oe=F=>{for(let j=1;j<D.length;j++){let k=(F-j+D.length)%D.length;if(Object.keys(t.divisions[D[k]].values).length>0)return k}return null},B=0;D.forEach(F=>{let j=t.divisions[F];B===D.length-1&&(S==="circular"||S==="bridgedCousins"||S==="bridgedCustom")?l(j.id,t.divisions[D[0]].id,t.navigationRules.sibling_sibling):B<D.length-1&&l(j.id,t.divisions[D[B+1]].id,t.navigationRules.sibling_sibling);let k=Object.keys(j.values);if(e.useDirectedEdges?l(j.id,t.nodeId,t.navigationRules.parent_child,"source"):l(t.nodeId,j.id,t.navigationRules.parent_child,"target"),k.length>0){let W=typeof e.idKey=="function"?e.idKey(j.values[k[0]]):e.idKey;l(j.id,j.values[k[0]][W],t.navigationRules.parent_child,"source")}let w=0;k.length>=1&&k.forEach(W=>{let N=j.values[W],_=typeof e.idKey=="function"?e.idKey(N):e.idKey,ie=D.length!==1?j.id:t.nodeId;if(e.useDirectedEdges?l(N[_],ie,t.navigationRules.parent_child,"source"):l(ie,N[_],t.navigationRules.parent_child,"target"),A==="within"){if(w===k.length-1&&S==="circular"){let C=typeof e.idKey=="function"?e.idKey(j.values[k[0]]):e.idKey;l(N[_],j.values[k[0]][C],t.navigationRules.sibling_sibling)}else if(w===k.length-1&&S==="bridgedCousins"){let C=me(B);if(C!==null){let $=t.divisions[D[C]].values,V=Object.keys($),U=$[V[0]],Y=typeof e.idKey=="function"?e.idKey(U):e.idKey;l(N[_],U[Y],t.navigationRules.sibling_sibling)}}else if(w===k.length-1&&S==="bridgedCustom")l(N[_],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(w<k.length-1){let C=typeof e.idKey=="function"?e.idKey(j.values[k[w+1]]):e.idKey;l(N[_],j.values[k[w+1]][C],t.navigationRules.sibling_sibling)}if(!w&&S==="bridgedCousins"){let C=Oe(B);if(C!==null){let $=t.divisions[D[C]].values,V=Object.keys($),U=$[V[V.length-1]],Y=typeof e.idKey=="function"?e.idKey(U):e.idKey;l(U[Y],N[_],t.navigationRules.sibling_sibling)}}else!w&&S==="bridgedCustom"&&l(t.behavior.customBridgePrevious,N[_],t.navigationRules.sibling_sibling)}else if(B===D.length-1&&S==="bridgedCustom")l(N[_],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(!B&&S==="bridgedCustom")l(t.behavior.customBridgePrevious,N[_],t.navigationRules.sibling_sibling);else{let C=B===D.length-1&&S==="circular"?t.divisions[D[0]]:t.divisions[D[B+1]];if(C){let $=G(w,N[_],j,C);if($){let V=typeof e.idKey=="function"?e.idKey($):e.idKey;l(N[_],$[V],t.navigationRules.sibling_sibling)}}}w++}),B++})})}return Object.keys(d).forEach(n=>{var a;let o=d[n];(a=e.genericEdges)!=null&&a.length&&e.genericEdges.forEach(u=>{c[u.edgeId]||(c[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(o,u))&&o.edges.push(u.edgeId)})}),c},he=(e,d,i)=>{var b,l,L,P;let c=e.navigationRules;if(!c){let m=Object.keys(i||{});m.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 ${m.length}. Dimensions counted: ${m.join(", ")}.`);let s={},h={},I={},r=[...ae],x=[...de],R=(p,n)=>{let o=p&&n,a=!1,u=!1;if((s[p]||h[p])&&(h[p]=T({},s[p]),a=!0),n&&(s[n]||h[n])&&(h[n]=T({},s[n]),u=!0),o&&!a&&!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 y=[...r.shift()];x.splice(x.indexOf(y[0]),1),x.splice(x.indexOf(y[1]),1),h[p]={direction:e.useDirectedEdges?"target":"source",key:y[0]},h[n]={direction:"target",key:y[1]}}else{if(!h[p]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,h[p]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!h[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,h[n]={direction:"target",key:y}}x.length||(h[p]||(I[p]=p),n&&!h[n]&&(I[n]=n))}};if(Object.keys(Z).forEach(p=>{let n=T({},Z[p]);e.useDirectedEdges&&(n.direction="target"),s[p]=n}),m.length){if((l=(b=e.dimensions)==null?void 0:b.parentOptions)!=null&&l.addLevel0){let p=((P=(L=e.dimensions.parentOptions.level1Options)==null?void 0:L.navigationRules)==null?void 0:P.parent_child)||["drill-out","drill-in"];R(p[0],p[1])}m.forEach(p=>{let n=i[p].navigationRules.parent_child,o=i[p].navigationRules.sibling_sibling;R(n[0],n[1]),R(o[0],o[1])})}if(Object.keys(d).forEach(p=>{d[p].navigationRules.forEach(n=>{h[n]||R(n)})}),Object.keys(I).length){let p={};Object.keys(h).forEach(o=>{p[h[o].key]=h[o].key}),Object.keys(s).forEach(o=>{!p[s[o].key]&&!oe[s[o].key]&&x.push(s[o].key)});let n=T({},I);I={},Object.keys(n).forEach(o=>{R(o)}),Object.keys(I).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(I).join(", ")}.`)}c=h}return c},pe=e=>{e.addIds&&fe(e);let d=ve(e),i=ye(e,d),c=be(e,d,i),b=he(e,c,i);return{nodes:d,edges:c,dimensions:i,navigationRules:b}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
package/dist/structure.js CHANGED
@@ -1 +1 @@
1
- import{a as se,b as M}from"./chunk-YE5N6UCT.js";import{a as Z,c as ee,e as ie,f as J,g as ne,i as te}from"./chunk-MPFBSVCV.js";import{a as k,b as X}from"./chunk-RGY6OTGO.js";var ye=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?de(e):ge(e),de=e=>{let m=te,t={},g={},O={},r=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,w=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,y=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,d)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let a=`dn-node-${d}-${r}`;return r++,n["data-navigator-id"]=a,a},o=n=>{let d=t[n],a=d.index,l=d.level,v=d.parent,u=[],c=v.items[a-1];if(c){let f=E(c,l);if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.id,navigationRules:["left","right"]})}}let K=v.items[a+1];if(K){let f=E(K,l);if(t[f]){let I=`${d.id}-${f}`;u.push(I),g[I]||(g[I]={source:d.id,target:f,navigationRules:["left","right"]})}}if(l==="group"&&v.items[a].items){let I=(v.items[a].items[0].mark.items[0].items||v.items[a].items)[0],p=E(I,"item");if(t[p]){let i=`${d.id}-${p}`;u.push(i),g[i]||(g[i]={source:d.id,target:p,navigationRules:["parent","child"]})}}else if(l==="item"){let f=E(v,"group");if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(u.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},j=(n,d,a,l,v)=>{let u=E(n,d),c="render-"+u,K=a||[0,0];t[u]={},t[u].d={},t[u].id=u,t[u].renderId=c,t[u].index=l,t[u].level=d,t[u].parent=v,O[c]={},O[c].renderId=c,O[c].spatialProperties={},O[c].spatialProperties.x=n.bounds.x1+K[0],O[c].spatialProperties.y=n.bounds.y1+K[1],O[c].spatialProperties.width=n.bounds.x2-n.bounds.x1,O[c].spatialProperties.height=n.bounds.y2-n.bounds.y1,O[c].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(f=>{let I=n.datum[f];b(f,I,n.datum,d,e.vegaLiteSpec)&&(t[u].d[e.keyRenamingHash&&e.keyRenamingHash[f]?e.keyRenamingHash[f]:f]=I)}),O[c].semantics={},O[c].semantics.label=e.nodeDescriber?e.nodeDescriber(t[u].d,n,d):se(t[u].d)},x=0;return y.items.forEach(n=>{if(P(n,x,e.vegaLiteSpec)){j(n,"group",s,x,y);let d=0,a=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;a.items.forEach(l=>{w(l,d,n,e.vegaLiteSpec)&&j(l,"item",s,d,a),d++})}x++}),Object.keys(t).forEach(n=>{t[n].edges=o(n)}),{nodes:t,edges:g,elementData:O,navigationRules:m}},re=e=>{let m=0,t={};e.data.forEach(g=>{let O=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[O]="_"+m,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(r=>{r in g&&(typeof g[r]=="string"?(t[r]||(t[r]=0),t[g[r]]||(t[g[r]]=0),g[O]+="_"+r+t[r]+"_"+g[r]+t[g[r]],t[r]++,t[g[r]]++):(t[r]||(t[r]=0),g[O]+="_"+r+t[r],t[r]++))}),m++})},ae=e=>{let m={};return e.data.forEach(t=>{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(t):e.idKey,O=t[g];if(!O){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(t)}.`);return}if(m[O]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${O}.`);return}else{let r=typeof e.renderIdKey=="function"?e.renderIdKey(t):e.renderIdKey;m[O]={id:O,edges:[],renderId:r?t[r]||"":t.renderIdKey||"",data:t}}}),m},le=(e,m)=>{var r,P,w;let t={};if((P=(r=e.dimensions)==null?void 0:r.parentOptions)!=null&&P.addLevel0){let b=e.dimensions.parentOptions.addLevel0;m[b.id]=X(k({},b),{dimensionLevel:0})}let g=[...ne],O=(b,s)=>{let y=s.numericalExtents[0],E=s.numericalExtents[1];s.numericalExtents[0]=y<b?y:b,s.numericalExtents[1]=E>b?E:b};return e.data.forEach(b=>{var E;let s=((E=e.dimensions)==null?void 0:E.values)||[],y=0;s.forEach(o=>{var j,x,h,n,d,a,l,v;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in b){let u=b[o.dimensionKey],c=typeof((j=o.operations)==null?void 0:j.filterFunction)=="function"?o.operations.filterFunction(b,o):!0;if(u!==void 0&&c){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!t[o.dimensionKey]){let p=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||M(o.dimensionKey),i=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||p;t[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((x=o.operations)==null?void 0:x.compressSparseDivisions)||!1,sortFunction:((h=o.operations)==null?void 0:h.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["parent_"+o.dimensionKey,"child"]}},m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:t[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let K=t[o.dimensionKey],f=null;if(o.type==="categorical"){let p=typeof((n=o.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,y):M(K.nodeId+"_"+u);if(f=K.divisions[p],!f){f=K.divisions[p]={id:p,sortFunction:((d=o.divisionOptions)==null?void 0:d.sortFunction)||void 0,values:{}};let i=typeof((a=o.divisionOptions)==null?void 0:a.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,y):p;m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:k({},f),renderingStrategy:((l=o.divisionOptions)==null?void 0:l.renderingStrategy)||"singleSquare"},m[p].data[o.dimensionKey]=u}}else{f=K.divisions[K.nodeId],f||(f=K.divisions[K.nodeId]={id:K.nodeId,sortFunction:((v=o.divisionOptions)==null?void 0:v.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let p=o.operations.createNumericalSubdivisions;K.subdivisions=typeof p=="number"&&p<1?1:p||1,p!==1&&(K.divisionOptions||(K.divisionOptions=o.divisionOptions),O(u,K))}let I=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[I]]=b}}y++})}),Object.keys(t).forEach(b=>{var o,j,x,h,n;let s=t[b],y=s.divisions;if(s.type==="numerical"){y[s.nodeId].values=Object.fromEntries(Object.entries(y[s.nodeId].values).sort((a,l)=>{var v;return typeof((v=s.operations)==null?void 0:v.sortFunction)=="function"?s.operations.sortFunction(a[1],l[1],s):a[1][b]-l[1][b]}));let d=y[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let a=Object.keys(d),l=typeof s.subdivisions=="function"?s.subdivisions(b,d):s.subdivisions,u=(s.numericalExtents[1]-s.numericalExtents[0])/l,c=s.numericalExtents[0]+u,K=0,f=0,I=null,p=s.numericalExtents[0];for(c=s.numericalExtents[0]+u;c<=s.numericalExtents[1];c+=u){let i=typeof((o=s.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(b,c,c):M(s.nodeId+"_"+c);I=i,s.divisions[i]={id:i,sortFunction:((j=s.divisionOptions)==null?void 0:j.sortFunction)||void 0,values:{},numericalExtents:[p,c]};let B=typeof((x=s.divisionOptions)==null?void 0:x.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(b,c,c):i;m[i]={id:i,renderId:B,derivedNode:b,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:((h=s.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"};let V=!1;for(;!V&&f<a.length;){let G=d[a[f]];G[b]<=c?(s.divisions[i].values[G.id]=G,f++):V=!0}p=c,K++}if(I&&f<a.length)for(;f<a.length;){let i=d[a[f]];s.divisions[I].values[i.id]=i,f++}delete y[b]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(y).sort((d,a)=>s.operations.sortFunction(d[1],a[1],s))));Object.keys(s.divisions).forEach(d=>{let a=s.divisions[d];typeof a.sortFunction=="function"&&(a.values=Object.fromEntries(Object.entries(a.values).sort((l,v)=>a.sortFunction(l[1],v[1],a))))})}),Object.keys(t).forEach(b=>{let s=t[b];if(s.operations.compressSparseDivisions){let y=Object.keys(s.divisions),E={},o=!0;if(y.forEach(j=>{let x=s.divisions[j],h=Object.keys(x.values);h.length<=1?h.forEach(n=>{E[n]=k({},x.values[n])}):o=!1}),o){let j={id:s.nodeId,values:E};y.forEach(x=>{delete m[x]}),s.divisions={},s.divisions[s.nodeId]=j}}}),(w=e.dimensions)!=null&&w.adjustDimensions&&(t=e.dimensions.adjustDimensions(t)),t},ue=(e,m,t)=>{var P,w,b,s,y,E,o,j,x,h;let g={},O=(n,d)=>{m[n].edges.indexOf(d)===-1&&m[n].edges.push(d)},r=(n,d,a,l)=>{let v=`${n}-${d}`,u=e.useDirectedEdges?`${d}-${v}`:v,c=!l||l==="source",K=!l||l==="target",f=I=>{g[I]?g[I].navigationRules.push(...a||[]):g[I]={source:n,target:d,navigationRules:a?[...a]:[]}};f(v),e.useDirectedEdges&&K&&f(u),c&&O(n,v),K&&O(d,u)};if(t&&Object.keys(t).length){let n=Object.keys(t),d=(b=(w=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:w.level1Options)==null?void 0:b.order,a=d||n,l=0,v=((s=e.dimensions)==null?void 0:s.parentOptions)||{},u=((E=(y=v.level1Options)==null?void 0:y.behavior)==null?void 0:E.extents)||"terminal",c=v.addLevel0,K=c?((j=(o=v.level1Options)==null?void 0:o.navigationRules)==null?void 0:j.parent_child)||["parent","child"]:[],f=((h=(x=v.level1Options)==null?void 0:x.navigationRules)==null?void 0:h.sibling_sibling)||["left","right"],I=typeof a[0]=="string"?d?m[a[0]]:m[t[a[0]].nodeId]:a[0];c&&r(c.id,I.id,K,"source"),a.forEach(p=>{let i=typeof p=="string"?d?m[p]:m[t[p].nodeId]:p;if(i===p&&!m[i.id]&&(m[i.id]=i),c&&(e.useDirectedEdges?r(i.id,c.id,K,"source"):r(c.id,i.id,K,"target")),l===a.length-1&&u==="circular")r(i.id,I.id,f);else if(l===a.length-1&&u==="bridgedCustom")r(i.id,v.level1Options.behavior.customBridgePost,f);else if(l<a.length-1){let B=typeof a[l+1]=="string"?d?m[a[l+1]]:m[t[a[l+1]].nodeId]:a[l+1];r(i.id,B.id,f)}!l&&u==="bridgedCustom"&&r(v.level1Options.behavior.customBridgePost,i.id,f),l++}),n.forEach(p=>{var U,W,Y,z;let i=t[p],B=((U=i.behavior)==null?void 0:U.childmostNavigation)||"within",V=(T,N,R,L)=>L.values[Object.keys(L.values)[T]]||void 0,G=B==="across"&&((W=i.behavior)!=null&&W.childmostMatching)?(Y=i.behavior)==null?void 0:Y.childmostMatching:V,$=((z=i.behavior)==null?void 0:z.extents)||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${p} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let D=Object.keys(i.divisions),q=i.divisions[D[0]];if(D.length!==1)r(i.nodeId,q.id,i.navigationRules.parent_child,"source");else{let T=Object.keys(q.values),N=typeof e.idKey=="function"?e.idKey(q.values[T[0]]):e.idKey;r(i.nodeId,q.values[T[0]][N],i.navigationRules.parent_child,"source")}let S=0;D.forEach(T=>{let N=i.divisions[T];S===D.length-1&&($==="circular"||$==="bridgedCousins"||$==="bridgedCustom")?r(N.id,i.divisions[D[0]].id,i.navigationRules.sibling_sibling):S<D.length-1&&r(N.id,i.divisions[D[S+1]].id,i.navigationRules.sibling_sibling);let R=Object.keys(N.values);if(e.useDirectedEdges?r(N.id,i.nodeId,i.navigationRules.parent_child,"source"):r(i.nodeId,N.id,i.navigationRules.parent_child,"target"),R.length>0){let A=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(N.id,N.values[R[0]][A],i.navigationRules.parent_child,"source")}let L=0;R.length>=1&&R.forEach(A=>{let _=N.values[A],C=typeof e.idKey=="function"?e.idKey(_):e.idKey,Q=D.length!==1?N.id:i.nodeId;if(e.useDirectedEdges?r(_[C],Q,i.navigationRules.parent_child,"source"):r(Q,_[C],i.navigationRules.parent_child,"target"),B==="within"){if(L===R.length-1&&$==="circular"){let F=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(_[C],N.values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCousins")if(S!==D.length-1){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S+1]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[S+1]].values[R[0]][F],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[0]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[0]].values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(L<R.length-1){let F=typeof e.idKey=="function"?e.idKey(N.values[R[L+1]]):e.idKey;r(_[C],N.values[R[L+1]][F],i.navigationRules.sibling_sibling)}if(!L&&$==="bridgedCousins")if(S!==0){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[S-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[D.length-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else!L&&$==="bridgedCustom"&&r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling)}else if(S===D.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!S&&$==="bridgedCustom")r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling);else{let F=S===D.length-1&&$==="circular"?i.divisions[D[0]]:i.divisions[D[S+1]];if(F){let H=G(L,_[C],N,F);if(H){let oe=typeof e.idKey=="function"?e.idKey(H):e.idKey;r(_[C],H[oe],i.navigationRules.sibling_sibling)}}}L++}),S++})})}return Object.keys(m).forEach(n=>{var a;let d=m[n];(a=e.genericEdges)!=null&&a.length&&e.genericEdges.forEach(l=>{g[l.edgeId]||(g[l.edgeId]=l.edge),(!l.conditional||l.conditional&&l.conditional(d,l))&&d.edges.push(l.edgeId)})}),g},ce=(e,m,t)=>{var O,r,P,w;let g=e.navigationRules;if(!g){let b=Object.keys(t||{});b.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 ${b.length}. Dimensions counted: ${b.join(", ")}.`);let s={},y={},E={},o=[...ie],j=[...ee],x=(h,n)=>{let d=h&&n,a=!1,l=!1;if((s[h]||y[h])&&(y[h]=k({},s[h]),a=!0),n&&(s[n]||y[n])&&(y[n]=k({},s[n]),l=!0),d&&!a&&!l){o.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=[...o.shift()];j.splice(j.indexOf(v[0]),1),j.splice(j.indexOf(v[1]),1),y[h]={direction:e.useDirectedEdges?"target":"source",key:v[0]},y[n]={direction:"target",key:v[1]}}else{if(!y[h]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[h]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!y[n]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[n]={direction:"target",key:v}}j.length||(y[h]||(E[h]=h),n&&!y[n]&&(E[n]=n))}};if(Object.keys(J).forEach(h=>{let n=k({},J[h]);e.useDirectedEdges&&(n.direction="target"),s[h]=n}),b.length){if((r=(O=e.dimensions)==null?void 0:O.parentOptions)!=null&&r.addLevel0){let h=((w=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:w.parent_child)||["parent","child"];x(h[0],h[1])}b.forEach(h=>{let n=t[h].navigationRules.parent_child,d=t[h].navigationRules.sibling_sibling;x(n[0],n[1]),x(d[0],d[1])})}if(Object.keys(m).forEach(h=>{m[h].navigationRules.forEach(n=>{y[n]||x(n)})}),Object.keys(E).length){let h={};Object.keys(y).forEach(d=>{h[y[d].key]=y[d].key}),Object.keys(s).forEach(d=>{!h[s[d].key]&&!Z[s[d].key]&&j.push(s[d].key)});let n=k({},E);E={},Object.keys(n).forEach(d=>{x(d)}),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(", ")}.`)}g=y}return g},ge=e=>{e.addIds&&re(e);let m=ae(e),t=le(e,m),g=ue(e,m,t),O=ce(e,g,t);return{nodes:m,edges:g,dimensions:t,navigationRules:O}};export{re as addSimpleDataIDs,ue as buildEdges,de as buildNodeStructureFromVegaLite,ae as buildNodes,ce as buildRules,ge as buildStructure,ye as default,le as scaffoldDimensions};
1
+ import{a as de,b as J}from"./chunk-XOJI42HR.js";import{a as V,b as ie,h as ne,j as te,l as se,m as Y,n as oe,p as re}from"./chunk-7YO7HC2V.js";var pe=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ue(e):he(e),ue=e=>{let m=re,s={},g={},O={},a=0,$=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,k=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,t=e.vegaLiteView._renderer._origin,y=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,r)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let d=`dn-node-${r}-${a}`;return a++,n["data-navigator-id"]=d,d},o=n=>{let r=s[n],d=r.index,l=r.level,v=r.parent,u=[],c=v.items[d-1];if(c){let f=E(c,l);if(s[f]){let I=`${f}-${r.id}`;u.push(I),g[I]||(g[I]={source:f,target:r.id,navigationRules:["left","right"]})}}let K=v.items[d+1];if(K){let f=E(K,l);if(s[f]){let I=`${r.id}-${f}`;u.push(I),g[I]||(g[I]={source:r.id,target:f,navigationRules:["left","right"]})}}if(l==="group"&&v.items[d].items){let I=(v.items[d].items[0].mark.items[0].items||v.items[d].items)[0],p=E(I,"item");if(s[p]){let i=`${r.id}-${p}`;u.push(i),g[i]||(g[i]={source:r.id,target:p,navigationRules:["drill-out","drill-in"]})}}else if(l==="item"){let f=E(v,"group");if(s[f]){let I=`${f}-${r.id}`;u.push(I),g[I]||(g[I]={source:f,target:r.id,navigationRules:["drill-out","drill-in"]})}}return e.exitFunction&&(u.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},j=(n,r,d,l,v)=>{let u=E(n,r),c="render-"+u,K=d||[0,0];s[u]={},s[u].d={},s[u].id=u,s[u].renderId=c,s[u].index=l,s[u].level=r,s[u].parent=v,O[c]={},O[c].renderId=c,O[c].spatialProperties={},O[c].spatialProperties.x=n.bounds.x1+K[0],O[c].spatialProperties.y=n.bounds.y1+K[1],O[c].spatialProperties.width=n.bounds.x2-n.bounds.x1,O[c].spatialProperties.height=n.bounds.y2-n.bounds.y1,O[c].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(f=>{let I=n.datum[f];b(f,I,n.datum,r,e.vegaLiteSpec)&&(s[u].d[e.keyRenamingHash&&e.keyRenamingHash[f]?e.keyRenamingHash[f]:f]=I)}),O[c].semantics={},O[c].semantics.label=e.nodeDescriber?e.nodeDescriber(s[u].d,n,r):de(s[u].d)},D=0;return y.items.forEach(n=>{if($(n,D,e.vegaLiteSpec)){j(n,"group",t,D,y);let r=0,d=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;d.items.forEach(l=>{k(l,r,n,e.vegaLiteSpec)&&j(l,"item",t,r,d),r++})}D++}),Object.keys(s).forEach(n=>{s[n].edges=o(n)}),{nodes:s,edges:g,elementData:O,navigationRules:m}},ce=e=>{let m=0,s={};e.data.forEach(g=>{let O=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[O]="_"+m,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(a=>{a in g&&(typeof g[a]=="string"?(s[a]||(s[a]=0),s[g[a]]||(s[g[a]]=0),g[O]+="_"+a+s[a]+"_"+g[a]+s[g[a]],s[a]++,s[g[a]]++):(s[a]||(s[a]=0),g[O]+="_"+a+s[a],s[a]++))}),m++})},ge=e=>{let m={};return e.data.forEach(s=>{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(s):e.idKey,O=s[g];if(!O){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(s)}.`);return}if(m[O]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${O}.`);return}else{let a=typeof e.renderIdKey=="function"?e.renderIdKey(s):e.renderIdKey;m[O]={id:O,edges:[],renderId:a?s[a]||"":s.renderIdKey||"",data:s}}}),m},fe=(e,m)=>{var a,$,k;let s={};if(($=(a=e.dimensions)==null?void 0:a.parentOptions)!=null&&$.addLevel0){let b=e.dimensions.parentOptions.addLevel0;m[b.id]=ie(V({},b),{dimensionLevel:0})}let g=[...oe],O=(b,t)=>{let y=t.numericalExtents[0],E=t.numericalExtents[1];t.numericalExtents[0]=y<b?y:b,t.numericalExtents[1]=E>b?E:b};return e.data.forEach(b=>{var E;let t=((E=e.dimensions)==null?void 0:E.values)||[],y=0;t.forEach(o=>{var j,D,h,n,r,d,l,v;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in b){let u=b[o.dimensionKey],c=typeof((j=o.operations)==null?void 0:j.filterFunction)=="function"?o.operations.filterFunction(b,o):!0;if(u!==void 0&&c){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!s[o.dimensionKey]){let p=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||J(o.dimensionKey),i=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||p;s[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((D=o.operations)==null?void 0:D.compressSparseDivisions)||!1,sortFunction:((h=o.operations)==null?void 0:h.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["drill-out_"+o.dimensionKey,"drill-in"]}},m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:s[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let K=s[o.dimensionKey],f=null;if(o.type==="categorical"){let p=typeof((n=o.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,y):J(K.nodeId+"_"+u);if(f=K.divisions[p],!f){f=K.divisions[p]={id:p,sortFunction:((r=o.divisionOptions)==null?void 0:r.sortFunction)||void 0,values:{}};let i=typeof((d=o.divisionOptions)==null?void 0:d.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,y):p;m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:V({},f),renderingStrategy:((l=o.divisionOptions)==null?void 0:l.renderingStrategy)||"singleSquare"},m[p].data[o.dimensionKey]=u}}else{f=K.divisions[K.nodeId],f||(f=K.divisions[K.nodeId]={id:K.nodeId,sortFunction:((v=o.divisionOptions)==null?void 0:v.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let p=o.operations.createNumericalSubdivisions;K.subdivisions=typeof p=="number"&&p<1?1:p||1,p!==1&&(K.divisionOptions||(K.divisionOptions=o.divisionOptions),O(u,K))}let I=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[I]]=b}}y++})}),Object.keys(s).forEach(b=>{var o,j,D,h,n;let t=s[b],y=t.divisions;if(t.type==="numerical"){y[t.nodeId].values=Object.fromEntries(Object.entries(y[t.nodeId].values).sort((d,l)=>{var v;return typeof((v=t.operations)==null?void 0:v.sortFunction)=="function"?t.operations.sortFunction(d[1],l[1],t):d[1][b]-l[1][b]}));let r=y[t.nodeId].values;if(t.numericalExtents[0]!==1/0&&t.subdivisions!==1){let d=Object.keys(r),l=typeof t.subdivisions=="function"?t.subdivisions(b,r):t.subdivisions,u=(t.numericalExtents[1]-t.numericalExtents[0])/l,c=t.numericalExtents[0]+u,K=0,f=0,I=null,p=t.numericalExtents[0];for(c=t.numericalExtents[0]+u;c<=t.numericalExtents[1];c+=u){let i=typeof((o=t.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(b,c,c):J(t.nodeId+"_"+c);I=i,t.divisions[i]={id:i,sortFunction:((j=t.divisionOptions)==null?void 0:j.sortFunction)||void 0,values:{},numericalExtents:[p,c]};let T=typeof((D=t.divisionOptions)==null?void 0:D.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(b,c,c):i;m[i]={id:i,renderId:T,derivedNode:b,edges:[],data:t.divisions[i],dimensionLevel:2,renderingStrategy:((h=t.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"};let A=!1;for(;!A&&f<d.length;){let G=r[d[f]];if(G[b]<=c){let R=typeof e.idKey=="function"?e.idKey(G):G[e.idKey];t.divisions[i].values[R]=G,f++}else A=!0}p=c,K++}if(I&&f<d.length)for(;f<d.length;){let i=r[d[f]],T=typeof e.idKey=="function"?e.idKey(i):i[e.idKey];t.divisions[I].values[T]=i,f++}delete y[t.nodeId]}}else typeof((n=t.operations)==null?void 0:n.sortFunction)=="function"&&(t.divisions=Object.fromEntries(Object.entries(y).sort((r,d)=>t.operations.sortFunction(r[1],d[1],t))));Object.keys(t.divisions).forEach(r=>{let d=t.divisions[r];typeof d.sortFunction=="function"&&(d.values=Object.fromEntries(Object.entries(d.values).sort((l,v)=>d.sortFunction(l[1],v[1],d))))})}),Object.keys(s).forEach(b=>{let t=s[b];if(t.operations.compressSparseDivisions){let y=Object.keys(t.divisions),E={},o=!0;if(y.forEach(j=>{let D=t.divisions[j],h=Object.keys(D.values);h.length<=1?h.forEach(n=>{E[n]=V({},D.values[n])}):o=!1}),o){let j={id:t.nodeId,values:E};y.forEach(D=>{delete m[D]}),t.divisions={},t.divisions[t.nodeId]=j}}}),(k=e.dimensions)!=null&&k.adjustDimensions&&(s=e.dimensions.adjustDimensions(s)),s},ve=(e,m,s)=>{var $,k,b,t,y,E,o,j,D,h;let g={},O=(n,r)=>{m[n].edges.indexOf(r)===-1&&m[n].edges.push(r)},a=(n,r,d,l)=>{let v=`${n}-${r}`,u=e.useDirectedEdges?`${r}-${v}`:v,c=!l||l==="source",K=!l||l==="target",f=I=>{g[I]?g[I].navigationRules.push(...d||[]):g[I]={source:n,target:r,navigationRules:d?[...d]:[]}};f(v),e.useDirectedEdges&&K&&f(u),c&&O(n,v),K&&O(r,u)};if(s&&Object.keys(s).length){let n=Object.keys(s),r=(b=(k=($=e.dimensions)==null?void 0:$.parentOptions)==null?void 0:k.level1Options)==null?void 0:b.order,d=r||n,l=0,v=((t=e.dimensions)==null?void 0:t.parentOptions)||{},u=((E=(y=v.level1Options)==null?void 0:y.behavior)==null?void 0:E.extents)||"terminal",c=v.addLevel0,K=c?((j=(o=v.level1Options)==null?void 0:o.navigationRules)==null?void 0:j.parent_child)||["drill-out","drill-in"]:[],f=((h=(D=v.level1Options)==null?void 0:D.navigationRules)==null?void 0:h.sibling_sibling)||["left","right"],I=typeof d[0]=="string"?r?m[d[0]]:m[s[d[0]].nodeId]:d[0];c&&a(c.id,I.id,K,"source"),d.forEach(p=>{let i=typeof p=="string"?r?m[p]:m[s[p].nodeId]:p;if(i===p&&!m[i.id]&&(m[i.id]=i),c&&(e.useDirectedEdges?a(i.id,c.id,K,"source"):a(c.id,i.id,K,"target")),l===d.length-1&&u==="circular")a(i.id,I.id,f);else if(l===d.length-1&&u==="bridgedCustom")a(i.id,v.level1Options.behavior.customBridgePost,f);else if(l<d.length-1){let T=typeof d[l+1]=="string"?r?m[d[l+1]]:m[s[d[l+1]].nodeId]:d[l+1];a(i.id,T.id,f)}!l&&u==="bridgedCustom"&&a(v.level1Options.behavior.customBridgePost,i.id,f),l++}),n.forEach(p=>{var z,Q,X,Z;let i=s[p],T=((z=i.behavior)==null?void 0:z.childmostNavigation)||"within",A=(w,x,N,S)=>S.values[Object.keys(S.values)[w]]||void 0,G=T==="across"&&((Q=i.behavior)!=null&&Q.childmostMatching)?(X=i.behavior)==null?void 0:X.childmostMatching:A,C=((Z=i.behavior)==null?void 0:Z.extents)||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${p} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let R=Object.keys(i.divisions),H=i.divisions[R[0]];if(R.length!==1)a(i.nodeId,H.id,i.navigationRules.parent_child,"source");else{let w=Object.keys(H.values),x=typeof e.idKey=="function"?e.idKey(H.values[w[0]]):e.idKey;a(i.nodeId,H.values[w[0]][x],i.navigationRules.parent_child,"source")}let ae=w=>{for(let x=1;x<R.length;x++){let N=(w+x)%R.length;if(Object.keys(i.divisions[R[N]].values).length>0)return N}return null},le=w=>{for(let x=1;x<R.length;x++){let N=(w-x+R.length)%R.length;if(Object.keys(i.divisions[R[N]].values).length>0)return N}return null},P=0;R.forEach(w=>{let x=i.divisions[w];P===R.length-1&&(C==="circular"||C==="bridgedCousins"||C==="bridgedCustom")?a(x.id,i.divisions[R[0]].id,i.navigationRules.sibling_sibling):P<R.length-1&&a(x.id,i.divisions[R[P+1]].id,i.navigationRules.sibling_sibling);let N=Object.keys(x.values);if(e.useDirectedEdges?a(x.id,i.nodeId,i.navigationRules.parent_child,"source"):a(i.nodeId,x.id,i.navigationRules.parent_child,"target"),N.length>0){let U=typeof e.idKey=="function"?e.idKey(x.values[N[0]]):e.idKey;a(x.id,x.values[N[0]][U],i.navigationRules.parent_child,"source")}let S=0;N.length>=1&&N.forEach(U=>{let _=x.values[U],F=typeof e.idKey=="function"?e.idKey(_):e.idKey,ee=R.length!==1?x.id:i.nodeId;if(e.useDirectedEdges?a(_[F],ee,i.navigationRules.parent_child,"source"):a(ee,_[F],i.navigationRules.parent_child,"target"),T==="within"){if(S===N.length-1&&C==="circular"){let L=typeof e.idKey=="function"?e.idKey(x.values[N[0]]):e.idKey;a(_[F],x.values[N[0]][L],i.navigationRules.sibling_sibling)}else if(S===N.length-1&&C==="bridgedCousins"){let L=ae(P);if(L!==null){let B=i.divisions[R[L]].values,q=Object.keys(B),M=B[q[0]],W=typeof e.idKey=="function"?e.idKey(M):e.idKey;a(_[F],M[W],i.navigationRules.sibling_sibling)}}else if(S===N.length-1&&C==="bridgedCustom")a(_[F],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(S<N.length-1){let L=typeof e.idKey=="function"?e.idKey(x.values[N[S+1]]):e.idKey;a(_[F],x.values[N[S+1]][L],i.navigationRules.sibling_sibling)}if(!S&&C==="bridgedCousins"){let L=le(P);if(L!==null){let B=i.divisions[R[L]].values,q=Object.keys(B),M=B[q[q.length-1]],W=typeof e.idKey=="function"?e.idKey(M):e.idKey;a(M[W],_[F],i.navigationRules.sibling_sibling)}}else!S&&C==="bridgedCustom"&&a(i.behavior.customBridgePrevious,_[F],i.navigationRules.sibling_sibling)}else if(P===R.length-1&&C==="bridgedCustom")a(_[F],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!P&&C==="bridgedCustom")a(i.behavior.customBridgePrevious,_[F],i.navigationRules.sibling_sibling);else{let L=P===R.length-1&&C==="circular"?i.divisions[R[0]]:i.divisions[R[P+1]];if(L){let B=G(S,_[F],x,L);if(B){let q=typeof e.idKey=="function"?e.idKey(B):e.idKey;a(_[F],B[q],i.navigationRules.sibling_sibling)}}}S++}),P++})})}return Object.keys(m).forEach(n=>{var d;let r=m[n];(d=e.genericEdges)!=null&&d.length&&e.genericEdges.forEach(l=>{g[l.edgeId]||(g[l.edgeId]=l.edge),(!l.conditional||l.conditional&&l.conditional(r,l))&&r.edges.push(l.edgeId)})}),g},ye=(e,m,s)=>{var O,a,$,k;let g=e.navigationRules;if(!g){let b=Object.keys(s||{});b.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 ${b.length}. Dimensions counted: ${b.join(", ")}.`);let t={},y={},E={},o=[...se],j=[...te],D=(h,n)=>{let r=h&&n,d=!1,l=!1;if((t[h]||y[h])&&(y[h]=V({},t[h]),d=!0),n&&(t[n]||y[n])&&(y[n]=V({},t[n]),l=!0),r&&!d&&!l){o.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=[...o.shift()];j.splice(j.indexOf(v[0]),1),j.splice(j.indexOf(v[1]),1),y[h]={direction:e.useDirectedEdges?"target":"source",key:v[0]},y[n]={direction:"target",key:v[1]}}else{if(!y[h]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[h]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!y[n]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[n]={direction:"target",key:v}}j.length||(y[h]||(E[h]=h),n&&!y[n]&&(E[n]=n))}};if(Object.keys(Y).forEach(h=>{let n=V({},Y[h]);e.useDirectedEdges&&(n.direction="target"),t[h]=n}),b.length){if((a=(O=e.dimensions)==null?void 0:O.parentOptions)!=null&&a.addLevel0){let h=((k=($=e.dimensions.parentOptions.level1Options)==null?void 0:$.navigationRules)==null?void 0:k.parent_child)||["drill-out","drill-in"];D(h[0],h[1])}b.forEach(h=>{let n=s[h].navigationRules.parent_child,r=s[h].navigationRules.sibling_sibling;D(n[0],n[1]),D(r[0],r[1])})}if(Object.keys(m).forEach(h=>{m[h].navigationRules.forEach(n=>{y[n]||D(n)})}),Object.keys(E).length){let h={};Object.keys(y).forEach(r=>{h[y[r].key]=y[r].key}),Object.keys(t).forEach(r=>{!h[t[r].key]&&!ne[t[r].key]&&j.push(t[r].key)});let n=V({},E);E={},Object.keys(n).forEach(r=>{D(r)}),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(", ")}.`)}g=y}return g},he=e=>{e.addIds&&ce(e);let m=ge(e),s=fe(e,m),g=ve(e,m,s),O=ye(e,g,s);return{nodes:m,edges:g,dimensions:s,navigationRules:O}};export{ce as addSimpleDataIDs,ve as buildEdges,ue as buildNodeStructureFromVegaLite,ge as buildNodes,ye as buildRules,he as buildStructure,pe as default,fe as scaffoldDimensions};
@@ -1,21 +1,21 @@
1
- var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var i in e)q(t,i,{get:e[i],enumerable:!0})},ge=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of he(e))!me.call(t,r)&&r!==i&&q(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var fe=t=>ge(q({},"__esModule",{value:!0}),t);var B=(t,e,i)=>new Promise((s,r)=>{var n=l=>{try{h(i.next(l))}catch(d){r(d)}},o=l=>{try{h(i.throw(l))}catch(d){r(d)}},h=l=>l.done?s(l.value):Promise.resolve(l.value).then(n,o);h((i=i.apply(t,e)).next())});var Ne={};pe(Ne,{default:()=>xe});module.exports=fe(Ne);var J={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var G={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 ne=t=>{let e={},i=J,s=G;return e.moveTo=r=>{let n=t.structure.nodes[r];if(n)return n},e.move=(r,n)=>{if(r){let o=t.structure.nodes[r];if(o.edges){let h=null,l=0,d=s[n];if(!d)return;let f=(g,a)=>{if(g!==n)return null;let b={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return b[d.direction]!==r?b[d.direction]:null};for(l=0;l<o.edges.length;l++){let g=t.structure.edges[o.edges[l]];if(g.navigationRules.forEach(a=>{h||(h=f(a,g))}),h)break}return h?e.moveTo(h):void 0}}},e.enter=()=>{if(t.entryPoint)return e.moveTo(t.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},e.exit=()=>{if(t.exitPoint)return t.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},e.keydownValidator=r=>{let n=i[r.code];if(n)return n},e.focus=r=>{let n=document.getElementById(r);n&&n.focus()},e.setNavigationKeyBindings=r=>{r?(i={},s=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=J,s=G)},e.setNavigationKeyBindings(t.navigationRules),e};var ye=t=>{var e,i,s,r,n;if((e=t.semantics)!=null&&e.label){let o=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(o)return o}if(!t.derivedNode)return t.data?Object.keys(t.data).map(o=>`${o}: ${t.data[o]}`).join(". ")+". Data point.":t.id;if((i=t.data)!=null&&i.dimensionKey){let o=0,h=Object.keys(t.data.divisions||{});h.forEach(d=>{o+=Object.keys(t.data.divisions[d].values||{}).length});let l=`${t.derivedNode}.`;return l+=h.length&&o?` ${h.length} division${h.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",l+=` ${t.data.type} dimension.`,l}return`${t.derivedNode}: ${(s=t.data)==null?void 0:s[t.derivedNode]}. ${Object.keys(((r=t.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((n=t.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},ve=(t,e,i)=>{let s=new Set,r=i.navigationRules||{};return e.edges&&e.edges.forEach(n=>{let o=i.edges[n];o&&o.navigationRules.forEach(h=>{let l=r[h];if(!l)return;let d=l.direction==="target"?o.target:o.source,f=typeof d=="function"?d(e,t):d;f&&f!==t&&s.add(h)})}),Array.from(s)},re=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let i=t.length,s=e.length,r=Array.from({length:i+1},()=>Array(s+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=s;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=s;o++){let h=t[n-1]===e[o-1]?0:1;r[n][o]=Math.min(r[n-1][o]+1,r[n][o-1]+1,r[n-1][o-1]+h),n>1&&o>1&&t[n-1]===e[o-2]&&t[n-2]===e[o-1]&&(r[n][o]=Math.min(r[n][o],r[n-2][o-2]+h))}return r[i][s]},be=t=>t<=4?1:2,we=(t,e,i={})=>{let s=t.toLowerCase().trim(),r=e.find(a=>a.toLowerCase()===s);if(r)return{match:r,ambiguous:[]};let n=e.find(a=>i[a]&&i[a].toLowerCase()===s);if(n)return{match:n,ambiguous:[]};let o=e.filter(a=>a.toLowerCase().startsWith(s));if(o.length===1)return{match:o[0],ambiguous:[]};let h=e.filter(a=>{if(!i[a])return!1;let b=i[a].toLowerCase();return b.startsWith(s)?!0:b.split(/\s+/).some(A=>A.startsWith(s))}),l=new Set([...o,...h]),d=Array.from(l);if(d.length===1)return{match:d[0],ambiguous:[]};if(d.length>1)return{match:null,ambiguous:d};let f=be(s.length),g=[];for(let a=0;a<e.length;a++){let b=e[a],A=z(s,b.toLowerCase());if(A<=f){g.push({candidate:b,dist:A});continue}if(i[b]){let v=i[b].toLowerCase().split(/\s+/);for(let R=0;R<v.length;R++)if(z(s,v[R])<=f){g.push({candidate:b,dist:z(s,v[R])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,b)=>a.dist-b.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(a=>a.candidate)}):{match:null,ambiguous:[]}},V=(t,e)=>e[t]?`${e[t]} (${t})`:t,ke=(t,e,i,s=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let h=0;h<o.length&&n.length<s;h++){let l=o[h],d=e.nodes[l],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let a=0;a<g.length&&!f;a++){let b=d.data[g[a]];b!=null&&typeof b!="object"&&String(b).toLowerCase().includes(r)&&(f=!0)}}!f&&d.derivedNode&&d.derivedNode.toLowerCase().includes(r)&&(f=!0),!f&&l.toLowerCase().includes(r)&&(f=!0),f&&n.push({nodeId:l,description:i(d)})}return n},xe=t=>{var te;let{structure:e,container:i,entryPoint:s,describeNode:r=ye,commandLabels:n={},onNavigate:o,onExit:h,onClick:l,onHover:d,llm:f,data:g}=t,a=typeof i=="string"?document.getElementById(i):i;if(!a)throw new Error(`textChat: container "${i}" not found`);let b=s||(e.dimensions?(te=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:te.nodeId:Object.keys(e.nodes)[0]),A=ne({structure:e,navigationRules:e.navigationRules||{},entryPoint:b}),v=null,R=Math.random().toString(36).slice(2,8),L=[],C=-1,O=null,S=[],oe=()=>{let c=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var he=(t,e)=>{for(var i in e)q(t,i,{get:e[i],enumerable:!0})},ge=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!me.call(t,r)&&r!==i&&q(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var fe=t=>ge(q({},"__esModule",{value:!0}),t);var B=(t,e,i)=>new Promise((s,r)=>{var n=c=>{try{p(i.next(c))}catch(d){r(d)}},o=c=>{try{p(i.throw(c))}catch(d){r(d)}},p=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,o);p((i=i.apply(t,e)).next())});var Ne={};he(Ne,{default:()=>xe});module.exports=fe(Ne);var G={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var J={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{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 ne=t=>{let e={},i=G,s=J;return e.moveTo=r=>{let n=t.structure.nodes[r];if(n)return n},e.move=(r,n)=>{if(r){let o=t.structure.nodes[r];if(o.edges){let p=null,c=0,d=s[n];if(!d)return;let f=(g,a)=>{if(g!==n)return null;let b={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return b[d.direction]!==r?b[d.direction]:null};for(c=0;c<o.edges.length;c++){let g=t.structure.edges[o.edges[c]];if(g.navigationRules.forEach(a=>{p||(p=f(a,g))}),p)break}return p?e.moveTo(p):void 0}}},e.enter=()=>{if(t.entryPoint)return e.moveTo(t.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},e.exit=()=>{if(t.exitPoint)return t.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},e.keydownValidator=r=>{let n=i[r.code];if(n)return n},e.focus=r=>{let n=document.getElementById(r);n&&n.focus()},e.setNavigationKeyBindings=r=>{r?(i={},s=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=G,s=J)},e.setNavigationKeyBindings(t.navigationRules),e};var ye=t=>{var e,i,s,r,n;if((e=t.semantics)!=null&&e.label){let o=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(o)return o}if(!t.derivedNode)return t.data?Object.keys(t.data).map(o=>`${o}: ${t.data[o]}`).join(". ")+". Data point.":t.id;if((i=t.data)!=null&&i.dimensionKey){let o=0,p=Object.keys(t.data.divisions||{});p.forEach(d=>{o+=Object.keys(t.data.divisions[d].values||{}).length});let c=`${t.derivedNode}.`;return c+=p.length&&o?` ${p.length} division${p.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",c+=` ${t.data.type} dimension.`,c}return`${t.derivedNode}: ${(s=t.data)==null?void 0:s[t.derivedNode]}. ${Object.keys(((r=t.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((n=t.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},ve=(t,e,i)=>{let s=new Set,r=i.navigationRules||{};return e.edges&&e.edges.forEach(n=>{let o=i.edges[n];o&&o.navigationRules.forEach(p=>{let c=r[p];if(!c)return;let d=c.direction==="target"?o.target:o.source,f=typeof d=="function"?d(e,t):d;f&&f!==t&&s.add(p)})}),Array.from(s)},re=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let i=t.length,s=e.length,r=Array.from({length:i+1},()=>Array(s+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=s;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=s;o++){let p=t[n-1]===e[o-1]?0:1;r[n][o]=Math.min(r[n-1][o]+1,r[n][o-1]+1,r[n-1][o-1]+p),n>1&&o>1&&t[n-1]===e[o-2]&&t[n-2]===e[o-1]&&(r[n][o]=Math.min(r[n][o],r[n-2][o-2]+p))}return r[i][s]},be=t=>t<=4?1:2,we=(t,e,i={})=>{let s=t.toLowerCase().trim(),r=e.find(a=>a.toLowerCase()===s);if(r)return{match:r,ambiguous:[]};let n=e.find(a=>i[a]&&i[a].toLowerCase()===s);if(n)return{match:n,ambiguous:[]};let o=e.filter(a=>a.toLowerCase().startsWith(s));if(o.length===1)return{match:o[0],ambiguous:[]};let p=e.filter(a=>{if(!i[a])return!1;let b=i[a].toLowerCase();return b.startsWith(s)?!0:b.split(/\s+/).some(T=>T.startsWith(s))}),c=new Set([...o,...p]),d=Array.from(c);if(d.length===1)return{match:d[0],ambiguous:[]};if(d.length>1)return{match:null,ambiguous:d};let f=be(s.length),g=[];for(let a=0;a<e.length;a++){let b=e[a],T=z(s,b.toLowerCase());if(T<=f){g.push({candidate:b,dist:T});continue}if(i[b]){let v=i[b].toLowerCase().split(/\s+/);for(let R=0;R<v.length;R++)if(z(s,v[R])<=f){g.push({candidate:b,dist:z(s,v[R])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,b)=>a.dist-b.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(a=>a.candidate)}):{match:null,ambiguous:[]}},V=(t,e)=>e[t]?`${e[t]} (${t})`:t,ke=(t,e,i,s=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let p=0;p<o.length&&n.length<s;p++){let c=o[p],d=e.nodes[c],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let a=0;a<g.length&&!f;a++){let b=d.data[g[a]];b!=null&&typeof b!="object"&&String(b).toLowerCase().includes(r)&&(f=!0)}}!f&&d.derivedNode&&d.derivedNode.toLowerCase().includes(r)&&(f=!0),!f&&c.toLowerCase().includes(r)&&(f=!0),f&&n.push({nodeId:c,description:i(d)})}return n},xe=t=>{var te;let{structure:e,container:i,entryPoint:s,describeNode:r=ye,commandLabels:n={},onNavigate:o,onExit:p,onClick:c,onHover:d,llm:f,data:g}=t,a=typeof i=="string"?document.getElementById(i):i;if(!a)throw new Error(`textChat: container "${i}" not found`);let b=s||(e.dimensions?(te=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:te.nodeId:Object.keys(e.nodes)[0]),T=ne({structure:e,navigationRules:e.navigationRules||{},entryPoint:b}),v=null,R=Math.random().toString(36).slice(2,8),L=[],C=-1,O=null,P=[],oe=()=>{let l=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
- `;if(g&&g.length>0){let p=Object.keys(g[0]),m=g.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
- `);c+=`DATASET SUMMARY:
5
- - Columns: ${p.join(", ")}
3
+ `;if(g&&g.length>0){let h=Object.keys(g[0]),m=g.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
+ `);l+=`DATASET SUMMARY:
5
+ - Columns: ${h.join(", ")}
6
6
  - Rows: ${g.length}
7
7
  - Sample (first 3):
8
8
  ${m}
9
9
 
10
- `,c+=`FULL DATASET (JSON):
10
+ `,l+=`FULL DATASET (JSON):
11
11
  `+JSON.stringify(g)+`
12
12
 
13
- `}if(v){let p=e.nodes[v];c+=`CURRENT POSITION: ${p?r(p):v}
13
+ `}if(v){let h=e.nodes[v];l+=`CURRENT POSITION: ${h?r(h):v}
14
14
 
15
- `}else c+=`CURRENT POSITION: Not yet navigated into the structure.
15
+ `}else l+=`CURRENT POSITION: Not yet navigated into the structure.
16
16
 
17
- `;return c+=`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.
17
+ `;return l+=`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
18
 
19
- `,c+=`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.
19
+ `,l+=`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
20
 
21
- `,c+='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.',c},$=document.createElement("div");$.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),$.appendChild(k);let U=document.createElement("div");U.className="dn-text-chat-controls";let W=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{k.setAttribute("aria-live",P.checked?"polite":"off")}),W.appendChild(P),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(W),$.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${R}`),M.className="dn-text-chat-sr-only",M.textContent="Navigation command";let x=document.createElement("input");x.type="text",x.id=`dn-text-chat-input-${R}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let F=document.createElement("button");F.type="submit",F.textContent="Send",I.appendChild(M),I.appendChild(x),I.appendChild(F),$.appendChild(I),a.appendChild($);let Q="";x.addEventListener("keydown",c=>{if(c.key==="ArrowUp"){if(c.preventDefault(),L.length===0)return;C===-1?(Q=x.value,C=L.length-1):C>0&&C--,x.value=L[C]}else if(c.key==="ArrowDown"){if(c.preventDefault(),C===-1)return;C<L.length-1?(C++,x.value=L[C]):(C=-1,x.value=Q)}});let Y=(c,p)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${p}`,m.textContent=c,k.appendChild(m),k.scrollTop=k.scrollHeight},D=c=>Y(c,"dn-text-chat-system"),ie=c=>Y(`> ${c}`,"dn-text-chat-input-echo"),y=c=>Y(c,"dn-text-chat-response"),ae=(c,p)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=c,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",p.forEach(H=>{let T=document.createElement("li");T.textContent=H,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},Z=c=>B(void 0,null,function*(){let p={role:"system",content:oe()};S.push({role:"user",content:c});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",k.appendChild(m),k.scrollTop=k.scrollHeight;try{let N=yield f([p,...S]);return k.removeChild(m),N===null?(S.pop(),null):(S.push({role:"assistant",content:N}),y(N),N)}catch(N){return k.removeChild(m),S.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});f?(D('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),D('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.')):D('Text navigation ready. Type "enter" to begin or "help" for available commands.');let X=["enter","help","more","more help","clear","click","select","hover","inspect"],_=c=>{let p=A.moveTo(c);p?(v=p.id,o&&o(p),y(`Moved to: ${r(p)}`)):y("Could not move to that node.")},ee=c=>B(void 0,null,function*(){let p=c.trim();if(!p)return;ie(p);let m=p.toLowerCase();if(O){let u=parseInt(p,10);if(!isNaN(u)&&u>=1&&u<=O.length){let w=O[u-1];O=null,_(w.nodeId);return}O=null}if(m==="clear"){k.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(v){y('Already in the structure. Type "help" to see available commands.');return}let u=A.enter();if(!u){y("Could not enter the structure. No entry point found.");return}v=u.id,o&&o(u),y(`Entered: ${r(u)}`);return}if(m==="help"){let u=f?" You can also type any question about the data.":"",w=[];l&&w.push('"click" or "select"'),d&&w.push('"hover" or "inspect"');let j=w.length?` Interaction: ${w.join(", ")}.`:"";if(!v)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let ce=e.nodes[v],le=ve(v,ce,e).map(de=>V(de,n));y(`Available: ${le.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];l&&u?(l(u),y(`Clicked: ${r(u)}`)):y(l?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(m==="hover"||m==="inspect"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];d&&u?(d(u),y(`Hovering over: ${r(u)}`)):y(d?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(m.startsWith("move to ")){let u=p.slice(8).trim();if(!u){y("Usage: move to <search term>");return}let w=ke(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?_(w[0].nodeId):(O=w,ae(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=re(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield Z(p))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(f?" Enter an API key above to ask questions about the data.":""));return}let N=re(e),{match:E,ambiguous:H}=we(m,[...N,...X],n);if(E&&X.includes(E)){yield ee(E);return}if(!E&&H.length>0){let u=H.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield Z(p))!==null)return;let u=f?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${p}". Type "help" for available commands.`+u);return}let T=E,se=n[T]||T;if(T==="exit"){v=null,h&&h(),y('Exited the structure. Type "enter" to re-enter.');return}let K=A.move(v,T);K?(v=K.id,o&&o(K),y(`${se}: ${r(K)}`)):y(`Cannot move "${T}" from here.`)});return I.addEventListener("submit",c=>B(void 0,null,function*(){c.preventDefault();let p=x.value.trim();p&&(L.push(p),C=-1),yield ee(x.value),x.value="",x.focus()})),{destroy(){a.removeChild($)},getCurrentNode(){return v&&e.nodes[v]||null}}};
21
+ `,l+='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.',l},$=document.createElement("div");$.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),$.appendChild(k);let U=document.createElement("div");U.className="dn-text-chat-controls";let W=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=!0,S.addEventListener("change",()=>{k.setAttribute("aria-live",S.checked?"polite":"off")}),W.appendChild(S),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(W),$.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${R}`),M.className="dn-text-chat-sr-only",M.textContent="Navigation command";let x=document.createElement("input");x.type="text",x.id=`dn-text-chat-input-${R}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let Y=document.createElement("button");Y.type="submit",Y.textContent="Send",I.appendChild(M),I.appendChild(x),I.appendChild(Y),$.appendChild(I),a.appendChild($);let Z="";x.addEventListener("keydown",l=>{if(l.key==="ArrowUp"){if(l.preventDefault(),L.length===0)return;C===-1?(Z=x.value,C=L.length-1):C>0&&C--,x.value=L[C]}else if(l.key==="ArrowDown"){if(l.preventDefault(),C===-1)return;C<L.length-1?(C++,x.value=L[C]):(C=-1,x.value=Z)}});let F=(l,h)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${h}`,m.textContent=l,k.appendChild(m),k.scrollTop=k.scrollHeight},D=l=>F(l,"dn-text-chat-system"),ie=l=>F(`> ${l}`,"dn-text-chat-input-echo"),y=l=>F(l,"dn-text-chat-response"),ae=(l,h)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=l,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",h.forEach(H=>{let A=document.createElement("li");A.textContent=H,E.appendChild(A)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},Q=l=>B(void 0,null,function*(){let h={role:"system",content:oe()};P.push({role:"user",content:l});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",k.appendChild(m),k.scrollTop=k.scrollHeight;try{let N=yield f([h,...P]);return k.removeChild(m),N===null?(P.pop(),null):(P.push({role:"assistant",content:N}),y(N),N)}catch(N){return k.removeChild(m),P.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});f?(D('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),D('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.')):D('Text navigation ready. Type "enter" to begin or "help" for available commands.');let X=["enter","help","more","more help","clear","click","select","hover","inspect"],_=l=>{let h=T.moveTo(l);h?(v=h.id,o&&o(h),y(`Moved to: ${r(h)}`)):y("Could not move to that node.")},ee=l=>B(void 0,null,function*(){let h=l.trim();if(!h)return;ie(h);let m=h.toLowerCase();if(O){let u=parseInt(h,10);if(!isNaN(u)&&u>=1&&u<=O.length){let w=O[u-1];O=null,_(w.nodeId);return}O=null}if(m==="clear"){k.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(v){y('Already in the structure. Type "help" to see available commands.');return}let u=T.enter();if(!u){y("Could not enter the structure. No entry point found.");return}v=u.id,o&&o(u),y(`Entered: ${r(u)}`);return}if(m==="help"){let u=f?" You can also type any question about the data.":"",w=[];c&&w.push('"click" or "select"'),d&&w.push('"hover" or "inspect"');let j=w.length?` Interaction: ${w.join(", ")}.`:"";if(!v)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let le=e.nodes[v],ce=ve(v,le,e).map(de=>V(de,n));y(`Available: ${ce.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];c&&u?(c(u),y(`Clicked: ${r(u)}`)):y(c?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(m==="hover"||m==="inspect"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];d&&u?(d(u),y(`Hovering over: ${r(u)}`)):y(d?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(m.startsWith("move to ")){let u=h.slice(8).trim();if(!u){y("Usage: move to <search term>");return}let w=ke(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?_(w[0].nodeId):(O=w,ae(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=re(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield Q(h))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(f?" Enter an API key above to ask questions about the data.":""));return}let N=re(e),{match:E,ambiguous:H}=we(m,[...N,...X],n);if(E&&X.includes(E)){yield ee(E);return}if(!E&&H.length>0){let u=H.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield Q(h))!==null)return;let u=f?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${h}". Type "help" for available commands.`+u);return}let A=E,se=n[A]||A;if(A==="exit"){v=null,p&&p(),y('Exited the structure. Type "enter" to re-enter.');return}let K=T.move(v,A);K?(v=K.id,o&&o(K),y(`${se}: ${r(K)}`)):y(`Cannot move "${A}" from here.`)});return I.addEventListener("submit",l=>B(void 0,null,function*(){l.preventDefault();let h=x.value.trim();h&&(L.push(h),C=-1),yield ee(x.value),x.value="",x.focus()})),{destroy(){a.removeChild($)},getCurrentNode(){return v&&e.nodes[v]||null}}};
package/dist/text-chat.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as _}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as q}from"./chunk-RGY6OTGO.js";var ce=e=>{var o,d,u,a,n;if((o=e.semantics)!=null&&o.label){let t=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(t)return t}if(!e.derivedNode)return e.data?Object.keys(e.data).map(t=>`${t}: ${e.data[t]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let t=0,v=Object.keys(e.data.divisions||{});v.forEach(p=>{t+=Object.keys(e.data.divisions[p].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&t?` ${v.length} division${v.length>1?"s":""}, ${t} datapoint${t>1?"s":""}.`:" No child data points.",b+=` ${e.data.type} dimension.`,b}return`${e.derivedNode}: ${(u=e.data)==null?void 0:u[e.derivedNode]}. ${Object.keys(((a=e.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},le=(e,o,d)=>{let u=new Set,a=d.navigationRules||{};return o.edges&&o.edges.forEach(n=>{let t=d.edges[n];t&&t.navigationRules.forEach(v=>{let b=a[v];if(!b)return;let p=b.direction==="target"?t.target:t.source,g=typeof p=="function"?p(o,e):p;g&&g!==e&&u.add(v)})}),Array.from(u)},ee=e=>e.navigationRules?Object.keys(e.navigationRules):[],K=(e,o)=>{let d=e.length,u=o.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let n=0;n<=d;n++)a[n][0]=n;for(let n=0;n<=u;n++)a[0][n]=n;for(let n=1;n<=d;n++)for(let t=1;t<=u;t++){let v=e[n-1]===o[t-1]?0:1;a[n][t]=Math.min(a[n-1][t]+1,a[n][t-1]+1,a[n-1][t-1]+v),n>1&&t>1&&e[n-1]===o[t-2]&&e[n-2]===o[t-1]&&(a[n][t]=Math.min(a[n][t],a[n-2][t-2]+v))}return a[d][u]},de=e=>e<=4?1:2,ue=(e,o,d={})=>{let u=e.toLowerCase().trim(),a=o.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let n=o.find(l=>d[l]&&d[l].toLowerCase()===u);if(n)return{match:n,ambiguous:[]};let t=o.filter(l=>l.toLowerCase().startsWith(u));if(t.length===1)return{match:t[0],ambiguous:[]};let v=o.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(T=>T.startsWith(u))}),b=new Set([...t,...v]),p=Array.from(b);if(p.length===1)return{match:p[0],ambiguous:[]};if(p.length>1)return{match:null,ambiguous:p};let g=de(u.length),f=[];for(let l=0;l<o.length;l++){let x=o[l],T=K(u,x.toLowerCase());if(T<=g){f.push({candidate:x,dist:T});continue}if(d[x]){let m=d[x].toLowerCase().split(/\s+/);for(let A=0;A<m.length;A++)if(K(u,m[A])<=g){f.push({candidate:x,dist:K(u,m[A])});break}}}return f.length===1?{match:f[0].candidate,ambiguous:[]}:f.length>1?(f.sort((l,x)=>l.dist-x.dist),f[0].dist<f[1].dist?{match:f[0].candidate,ambiguous:[]}:{match:null,ambiguous:f.map(l=>l.candidate)}):{match:null,ambiguous:[]}},z=(e,o)=>o[e]?`${o[e]} (${e})`:e,he=(e,o,d,u=10)=>{let a=e.toLowerCase(),n=[],t=Object.keys(o.nodes);for(let v=0;v<t.length&&n.length<u;v++){let b=t[v],p=o.nodes[b],g=!1;if(p.data&&!g){let f=Object.keys(p.data);for(let l=0;l<f.length&&!g;l++){let x=p.data[f[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(g=!0)}}!g&&p.derivedNode&&p.derivedNode.toLowerCase().includes(a)&&(g=!0),!g&&b.toLowerCase().includes(a)&&(g=!0),g&&n.push({nodeId:b,description:d(p)})}return n},ge=e=>{var Z;let{structure:o,container:d,entryPoint:u,describeNode:a=ce,commandLabels:n={},onNavigate:t,onExit:v,onClick:b,onHover:p,llm:g,data:f}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=u||(o.dimensions?(Z=o.dimensions[Object.keys(o.dimensions)[0]])==null?void 0:Z.nodeId:Object.keys(o.nodes)[0]),T=_({structure:o,navigationRules:o.navigationRules||{},entryPoint:x}),m=null,A=Math.random().toString(36).slice(2,8),L=[],E=-1,I=null,M=[],te=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ import{a as _}from"./chunk-UNB4R2QN.js";import{g as q}from"./chunk-7YO7HC2V.js";var ce=e=>{var o,d,u,a,n;if((o=e.semantics)!=null&&o.label){let t=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(t)return t}if(!e.derivedNode)return e.data?Object.keys(e.data).map(t=>`${t}: ${e.data[t]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let t=0,v=Object.keys(e.data.divisions||{});v.forEach(p=>{t+=Object.keys(e.data.divisions[p].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&t?` ${v.length} division${v.length>1?"s":""}, ${t} datapoint${t>1?"s":""}.`:" No child data points.",b+=` ${e.data.type} dimension.`,b}return`${e.derivedNode}: ${(u=e.data)==null?void 0:u[e.derivedNode]}. ${Object.keys(((a=e.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},le=(e,o,d)=>{let u=new Set,a=d.navigationRules||{};return o.edges&&o.edges.forEach(n=>{let t=d.edges[n];t&&t.navigationRules.forEach(v=>{let b=a[v];if(!b)return;let p=b.direction==="target"?t.target:t.source,g=typeof p=="function"?p(o,e):p;g&&g!==e&&u.add(v)})}),Array.from(u)},ee=e=>e.navigationRules?Object.keys(e.navigationRules):[],K=(e,o)=>{let d=e.length,u=o.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let n=0;n<=d;n++)a[n][0]=n;for(let n=0;n<=u;n++)a[0][n]=n;for(let n=1;n<=d;n++)for(let t=1;t<=u;t++){let v=e[n-1]===o[t-1]?0:1;a[n][t]=Math.min(a[n-1][t]+1,a[n][t-1]+1,a[n-1][t-1]+v),n>1&&t>1&&e[n-1]===o[t-2]&&e[n-2]===o[t-1]&&(a[n][t]=Math.min(a[n][t],a[n-2][t-2]+v))}return a[d][u]},de=e=>e<=4?1:2,ue=(e,o,d={})=>{let u=e.toLowerCase().trim(),a=o.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let n=o.find(l=>d[l]&&d[l].toLowerCase()===u);if(n)return{match:n,ambiguous:[]};let t=o.filter(l=>l.toLowerCase().startsWith(u));if(t.length===1)return{match:t[0],ambiguous:[]};let v=o.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(T=>T.startsWith(u))}),b=new Set([...t,...v]),p=Array.from(b);if(p.length===1)return{match:p[0],ambiguous:[]};if(p.length>1)return{match:null,ambiguous:p};let g=de(u.length),f=[];for(let l=0;l<o.length;l++){let x=o[l],T=K(u,x.toLowerCase());if(T<=g){f.push({candidate:x,dist:T});continue}if(d[x]){let m=d[x].toLowerCase().split(/\s+/);for(let A=0;A<m.length;A++)if(K(u,m[A])<=g){f.push({candidate:x,dist:K(u,m[A])});break}}}return f.length===1?{match:f[0].candidate,ambiguous:[]}:f.length>1?(f.sort((l,x)=>l.dist-x.dist),f[0].dist<f[1].dist?{match:f[0].candidate,ambiguous:[]}:{match:null,ambiguous:f.map(l=>l.candidate)}):{match:null,ambiguous:[]}},z=(e,o)=>o[e]?`${o[e]} (${e})`:e,he=(e,o,d,u=10)=>{let a=e.toLowerCase(),n=[],t=Object.keys(o.nodes);for(let v=0;v<t.length&&n.length<u;v++){let b=t[v],p=o.nodes[b],g=!1;if(p.data&&!g){let f=Object.keys(p.data);for(let l=0;l<f.length&&!g;l++){let x=p.data[f[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(g=!0)}}!g&&p.derivedNode&&p.derivedNode.toLowerCase().includes(a)&&(g=!0),!g&&b.toLowerCase().includes(a)&&(g=!0),g&&n.push({nodeId:b,description:d(p)})}return n},ge=e=>{var Z;let{structure:o,container:d,entryPoint:u,describeNode:a=ce,commandLabels:n={},onNavigate:t,onExit:v,onClick:b,onHover:p,llm:g,data:f}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=u||(o.dimensions?(Z=o.dimensions[Object.keys(o.dimensions)[0]])==null?void 0:Z.nodeId:Object.keys(o.nodes)[0]),T=_({structure:o,navigationRules:o.navigationRules||{},entryPoint:x}),m=null,A=Math.random().toString(36).slice(2,8),L=[],E=-1,I=null,M=[],te=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
3
  `;if(f&&f.length>0){let c=Object.keys(f[0]),i=f.slice(0,3).map(w=>JSON.stringify(w)).join(`
4
4
  `);s+=`DATASET SUMMARY:
@@ -1 +1 @@
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});
1
+ var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},p=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!c.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var u=t=>p(a({},"__esModule",{value:!0}),t);var w={};s(w,{createValidId:()=>m,describeNode:()=>g,getGenericCommandsFromNavRules:()=>y});module.exports=u(w);var n={"drill-in":{label:"Enter",description:"Drill in"},"drill-out":{label:"Backspace",description:"Drill out"},exit:{label:"Esc",description:"Exit"},left:{label:"\u2190",description:"Previous data point"},right:{label:"\u2192",description:"Next data point"},up:{label:"\u2191",description:"Previous data point"},down:{label:"\u2193",description:"Next data point"},backward:{label:",",description:"Move backward"},forward:{label:".",description:"Move forward"},previous:{label:";",description:"Previous"},next:{label:"'",description:"Next"},undo:{label:"Z",description:"Undo"},help:{label:"Y",description:"Help"},legend:{label:"L",description:"Legend"}};var g=(t,e)=>{let i=Object.keys(t),o="";return i.forEach(r=>{o+=`${e&&e.omitKeyNames?"":r+": "}${t[r]}. `}),o+=e&&e.semanticLabel||"Data point.",o},m=t=>"_"+t.replace(/[^a-zA-Z0-9_-]+/g,"_");function y(t){return t?Object.keys(t).map(e=>n[e]).filter(Boolean):[]}0&&(module.exports={createValidId,describeNode,getGenericCommandsFromNavRules});
package/dist/utilities.js CHANGED
@@ -1 +1 @@
1
- import{a,b}from"./chunk-YE5N6UCT.js";import"./chunk-RGY6OTGO.js";export{b as createValidId,a as describeNode};
1
+ import{a,b,c}from"./chunk-XOJI42HR.js";import"./chunk-7YO7HC2V.js";export{b as createValidId,a as describeNode,c as getGenericCommandsFromNavRules};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "data-navigator",
3
3
  "author": "Frank Elavsky",
4
- "version": "2.4.0",
4
+ "version": "3.0.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
package/text-chat.css CHANGED
@@ -54,7 +54,7 @@
54
54
  border: 1px solid #ccc;
55
55
  }
56
56
 
57
- .dn-text-chat-form input[type="text"] {
57
+ .dn-text-chat-form input[type='text'] {
58
58
  flex: 1;
59
59
  padding: 6px 8px;
60
60
  border: none;
@@ -62,7 +62,7 @@
62
62
  outline: none;
63
63
  }
64
64
 
65
- .dn-text-chat-form input[type="text"]:focus {
65
+ .dn-text-chat-form input[type='text']:focus {
66
66
  box-shadow: inset 0 0 0 2px #1e3369;
67
67
  }
68
68