data-navigator 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1876,7 +1876,7 @@ var rendering_default = (options) => {
1876
1876
  defaults.spatialProperties = options.defaults.spatialProperties ? mergeDefault(defaults.spatialProperties, options.defaults.spatialProperties) : defaults.spatialProperties;
1877
1877
  defaults.semantics = options.defaults.semantics ? mergeDefault(defaults.semantics, options.defaults.semantics) : defaults.semantics;
1878
1878
  defaults.parentSemantics = options.defaults.parentSemantics ? mergeDefault(defaults.parentSemantics, options.defaults.parentSemantics) : defaults.parentSemantics;
1879
- defaults.existingElement = options.defaults.existingElement ? __spreadValues(__spreadValues({}, defaults.existingElement), options.defaults.existingElement) : defaults.existingElement;
1879
+ defaults.existingElement = options.defaults.existingElement ? mergeDefault(defaults.existingElement, options.defaults.existingElement) : defaults.existingElement;
1880
1880
  }
1881
1881
  renderer.initialize = () => {
1882
1882
  var _a, _b;
@@ -1969,16 +1969,17 @@ var rendering_default = (options) => {
1969
1969
  }
1970
1970
  let useExisting = false;
1971
1971
  let existingSpatialProperties = {};
1972
+ const resolved = /* @__PURE__ */ new Map();
1972
1973
  const resolve = (v) => {
1973
1974
  var _a;
1974
- return typeof v === "function" ? v(d, (_a = nodeData.datum) != null ? _a : nodeData.data) : v;
1975
+ return typeof v !== "function" ? v : resolved.has(v) ? resolved.get(v) : resolved.set(v, v(d, (_a = nodeData.datum) != null ? _a : nodeData.data)).get(v);
1975
1976
  };
1976
1977
  const resolveProp = (prop, subprop, checkExisting) => {
1977
- var _a, _b, _c;
1978
+ var _a, _b, _c, _d, _e;
1978
1979
  const p1 = resolve(d[prop] || defaults[prop]);
1979
1980
  const s1 = !(checkExisting && useExisting) ? p1 == null ? void 0 : p1[subprop] : existingSpatialProperties[subprop];
1980
1981
  const s2 = (_c = (_a = resolve(defaults[prop])) == null ? void 0 : _a[subprop]) != null ? _c : (_b = NodeElementDefaults[prop]) == null ? void 0 : _b[subprop];
1981
- return resolve(s1) || resolve(s2) || (!subprop ? p1 : void 0);
1982
+ return (_e = (_d = resolve(s1)) != null ? _d : resolve(s2)) != null ? _e : !subprop ? p1 : void 0;
1982
1983
  };
1983
1984
  useExisting = resolveProp("existingElement", "useForSpatialProperties");
1984
1985
  existingSpatialProperties = resolveProp("existingElement", "spatialProperties");
@@ -1996,7 +1997,9 @@ var rendering_default = (options) => {
1996
1997
  node.setAttribute("role", resolveProp("parentSemantics", "role"));
1997
1998
  node.id = id;
1998
1999
  node.classList.add("dn-node");
1999
- node.classList.add(resolveProp("cssClass"));
2000
+ const cssClass = resolveProp("cssClass");
2001
+ if (cssClass)
2002
+ node.classList.add(cssClass);
2000
2003
  node.style.width = width + "px";
2001
2004
  node.style.height = height + "px";
2002
2005
  node.style.left = x + "px";
@@ -2097,9 +2100,10 @@ var rendering_default = (options) => {
2097
2100
 
2098
2101
  // src/text-chat.ts
2099
2102
  var defaultDescribeNode = (node) => {
2100
- var _a, _b, _c, _d, _e;
2101
- if ((_a = node.semantics) == null ? void 0 : _a.label) {
2102
- const label = typeof node.semantics.label === "function" ? node.semantics.label() : node.semantics.label;
2103
+ var _a, _b, _c, _d;
2104
+ const semantics = typeof node.semantics === "function" ? node.semantics(node, node.data) : node.semantics;
2105
+ if (semantics == null ? void 0 : semantics.label) {
2106
+ const label = typeof semantics.label === "function" ? semantics.label(node, node.data) : semantics.label;
2103
2107
  if (label)
2104
2108
  return label;
2105
2109
  }
@@ -2109,7 +2113,7 @@ var defaultDescribeNode = (node) => {
2109
2113
  }
2110
2114
  return node.id;
2111
2115
  }
2112
- if ((_b = node.data) == null ? void 0 : _b.dimensionKey) {
2116
+ if ((_a = node.data) == null ? void 0 : _a.dimensionKey) {
2113
2117
  let count = 0;
2114
2118
  const divisions = Object.keys(node.data.divisions || {});
2115
2119
  divisions.forEach((div) => {
@@ -2120,7 +2124,7 @@ var defaultDescribeNode = (node) => {
2120
2124
  label += ` ${node.data.type} dimension.`;
2121
2125
  return label;
2122
2126
  }
2123
- return `${node.derivedNode}: ${(_c = node.data) == null ? void 0 : _c[node.derivedNode]}. ${Object.keys(((_d = node.data) == null ? void 0 : _d.values) || {}).length} child data point${Object.keys(((_e = node.data) == null ? void 0 : _e.values) || {}).length > 1 ? "s" : ""}. Division.`;
2127
+ return `${node.derivedNode}: ${(_b = node.data) == null ? void 0 : _b[node.derivedNode]}. ${Object.keys(((_c = node.data) == null ? void 0 : _c.values) || {}).length} child data point${Object.keys(((_d = node.data) == null ? void 0 : _d.values) || {}).length > 1 ? "s" : ""}. Division.`;
2124
2128
  };
2125
2129
  var getAvailableRules = (nodeId, node, structure) => {
2126
2130
  const available = /* @__PURE__ */ new Set();
@@ -2646,6 +2650,13 @@ var text_chat_default = (options) => {
2646
2650
  },
2647
2651
  getCurrentNode() {
2648
2652
  return currentNodeId ? structure.nodes[currentNodeId] || null : null;
2653
+ },
2654
+ submit(text) {
2655
+ return handleCommand(text);
2656
+ },
2657
+ setCurrentNode(nodeId) {
2658
+ currentNodeId = nodeId && structure.nodes[nodeId] ? nodeId : null;
2659
+ pendingChoices = null;
2649
2660
  }
2650
2661
  };
2651
2662
  };
package/dist/index.d.cts CHANGED
@@ -200,7 +200,7 @@ type RenderObject = {
200
200
  spatialProperties?: SpatialProperties;
201
201
  semantics?: Semantics;
202
202
  parentSemantics?: Semantics;
203
- existingElement?: ExistingElement;
203
+ existingElement?: ExistingElement | ((r?: RenderObject, d?: DatumObject) => ExistingElement);
204
204
  showText?: boolean;
205
205
  };
206
206
  type RootObject = {
@@ -333,6 +333,8 @@ type TextChatOptions = {
333
333
  type TextChatInstance = {
334
334
  destroy: () => void;
335
335
  getCurrentNode: () => NodeObject | null;
336
+ submit: (text: string) => Promise<void>;
337
+ setCurrentNode: (nodeId: string | null) => void;
336
338
  };
337
339
 
338
340
  /**
package/dist/index.d.ts CHANGED
@@ -200,7 +200,7 @@ type RenderObject = {
200
200
  spatialProperties?: SpatialProperties;
201
201
  semantics?: Semantics;
202
202
  parentSemantics?: Semantics;
203
- existingElement?: ExistingElement;
203
+ existingElement?: ExistingElement | ((r?: RenderObject, d?: DatumObject) => ExistingElement);
204
204
  showText?: boolean;
205
205
  };
206
206
  type RootObject = {
@@ -333,6 +333,8 @@ type TextChatOptions = {
333
333
  type TextChatInstance = {
334
334
  destroy: () => void;
335
335
  getCurrentNode: () => NodeObject | null;
336
+ submit: (text: string) => Promise<void>;
337
+ setCurrentNode: (nodeId: string | null) => void;
336
338
  };
337
339
 
338
340
  /**
package/dist/index.js CHANGED
@@ -1842,7 +1842,7 @@ var rendering_default = (options) => {
1842
1842
  defaults.spatialProperties = options.defaults.spatialProperties ? mergeDefault(defaults.spatialProperties, options.defaults.spatialProperties) : defaults.spatialProperties;
1843
1843
  defaults.semantics = options.defaults.semantics ? mergeDefault(defaults.semantics, options.defaults.semantics) : defaults.semantics;
1844
1844
  defaults.parentSemantics = options.defaults.parentSemantics ? mergeDefault(defaults.parentSemantics, options.defaults.parentSemantics) : defaults.parentSemantics;
1845
- defaults.existingElement = options.defaults.existingElement ? __spreadValues(__spreadValues({}, defaults.existingElement), options.defaults.existingElement) : defaults.existingElement;
1845
+ defaults.existingElement = options.defaults.existingElement ? mergeDefault(defaults.existingElement, options.defaults.existingElement) : defaults.existingElement;
1846
1846
  }
1847
1847
  renderer.initialize = () => {
1848
1848
  var _a, _b;
@@ -1935,16 +1935,17 @@ var rendering_default = (options) => {
1935
1935
  }
1936
1936
  let useExisting = false;
1937
1937
  let existingSpatialProperties = {};
1938
+ const resolved = /* @__PURE__ */ new Map();
1938
1939
  const resolve = (v) => {
1939
1940
  var _a;
1940
- return typeof v === "function" ? v(d, (_a = nodeData.datum) != null ? _a : nodeData.data) : v;
1941
+ return typeof v !== "function" ? v : resolved.has(v) ? resolved.get(v) : resolved.set(v, v(d, (_a = nodeData.datum) != null ? _a : nodeData.data)).get(v);
1941
1942
  };
1942
1943
  const resolveProp = (prop, subprop, checkExisting) => {
1943
- var _a, _b, _c;
1944
+ var _a, _b, _c, _d, _e;
1944
1945
  const p1 = resolve(d[prop] || defaults[prop]);
1945
1946
  const s1 = !(checkExisting && useExisting) ? p1 == null ? void 0 : p1[subprop] : existingSpatialProperties[subprop];
1946
1947
  const s2 = (_c = (_a = resolve(defaults[prop])) == null ? void 0 : _a[subprop]) != null ? _c : (_b = NodeElementDefaults[prop]) == null ? void 0 : _b[subprop];
1947
- return resolve(s1) || resolve(s2) || (!subprop ? p1 : void 0);
1948
+ return (_e = (_d = resolve(s1)) != null ? _d : resolve(s2)) != null ? _e : !subprop ? p1 : void 0;
1948
1949
  };
1949
1950
  useExisting = resolveProp("existingElement", "useForSpatialProperties");
1950
1951
  existingSpatialProperties = resolveProp("existingElement", "spatialProperties");
@@ -1962,7 +1963,9 @@ var rendering_default = (options) => {
1962
1963
  node.setAttribute("role", resolveProp("parentSemantics", "role"));
1963
1964
  node.id = id;
1964
1965
  node.classList.add("dn-node");
1965
- node.classList.add(resolveProp("cssClass"));
1966
+ const cssClass = resolveProp("cssClass");
1967
+ if (cssClass)
1968
+ node.classList.add(cssClass);
1966
1969
  node.style.width = width + "px";
1967
1970
  node.style.height = height + "px";
1968
1971
  node.style.left = x + "px";
@@ -2063,9 +2066,10 @@ var rendering_default = (options) => {
2063
2066
 
2064
2067
  // src/text-chat.ts
2065
2068
  var defaultDescribeNode = (node) => {
2066
- var _a, _b, _c, _d, _e;
2067
- if ((_a = node.semantics) == null ? void 0 : _a.label) {
2068
- const label = typeof node.semantics.label === "function" ? node.semantics.label() : node.semantics.label;
2069
+ var _a, _b, _c, _d;
2070
+ const semantics = typeof node.semantics === "function" ? node.semantics(node, node.data) : node.semantics;
2071
+ if (semantics == null ? void 0 : semantics.label) {
2072
+ const label = typeof semantics.label === "function" ? semantics.label(node, node.data) : semantics.label;
2069
2073
  if (label)
2070
2074
  return label;
2071
2075
  }
@@ -2075,7 +2079,7 @@ var defaultDescribeNode = (node) => {
2075
2079
  }
2076
2080
  return node.id;
2077
2081
  }
2078
- if ((_b = node.data) == null ? void 0 : _b.dimensionKey) {
2082
+ if ((_a = node.data) == null ? void 0 : _a.dimensionKey) {
2079
2083
  let count = 0;
2080
2084
  const divisions = Object.keys(node.data.divisions || {});
2081
2085
  divisions.forEach((div) => {
@@ -2086,7 +2090,7 @@ var defaultDescribeNode = (node) => {
2086
2090
  label += ` ${node.data.type} dimension.`;
2087
2091
  return label;
2088
2092
  }
2089
- return `${node.derivedNode}: ${(_c = node.data) == null ? void 0 : _c[node.derivedNode]}. ${Object.keys(((_d = node.data) == null ? void 0 : _d.values) || {}).length} child data point${Object.keys(((_e = node.data) == null ? void 0 : _e.values) || {}).length > 1 ? "s" : ""}. Division.`;
2093
+ return `${node.derivedNode}: ${(_b = node.data) == null ? void 0 : _b[node.derivedNode]}. ${Object.keys(((_c = node.data) == null ? void 0 : _c.values) || {}).length} child data point${Object.keys(((_d = node.data) == null ? void 0 : _d.values) || {}).length > 1 ? "s" : ""}. Division.`;
2090
2094
  };
2091
2095
  var getAvailableRules = (nodeId, node, structure) => {
2092
2096
  const available = /* @__PURE__ */ new Set();
@@ -2612,6 +2616,13 @@ var text_chat_default = (options) => {
2612
2616
  },
2613
2617
  getCurrentNode() {
2614
2618
  return currentNodeId ? structure.nodes[currentNodeId] || null : null;
2619
+ },
2620
+ submit(text) {
2621
+ return handleCommand(text);
2622
+ },
2623
+ setCurrentNode(nodeId) {
2624
+ currentNodeId = nodeId && structure.nodes[nodeId] ? nodeId : null;
2625
+ pendingChoices = null;
2615
2626
  }
2616
2627
  };
2617
2628
  };
@@ -1 +1 @@
1
- var T=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames,Z=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var J=(e,r,n)=>r in e?T(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,x=(e,r)=>{for(var n in r||(r={}))Q.call(r,n)&&J(e,n,r[n]);if(Z)for(var n of Z(r))ne.call(r,n)&&J(e,n,r[n]);return e};var ae=(e,r)=>{for(var n in r)T(e,n,{get:r[n],enumerable:!0})},ie=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of re(r))!Q.call(e,s)&&s!==n&&T(e,s,{get:()=>r[s],enumerable:!(t=te(r,s))||t.enumerable});return e};var se=e=>ie(T({},"__esModule",{value:!0}),e);var z=(e,r,n)=>{if(!r.has(e))throw TypeError("Cannot "+n)};var b=(e,r,n)=>(z(e,r,"read from private field"),n?n.call(e):r.get(e)),N=(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)},R=(e,r,n,t)=>(z(e,r,"write to private field"),t?t.call(e,n):r.set(e,n),n);var P=(e,r,n)=>(z(e,r,"access private method"),n);var ce={};ae(ce,{default:()=>de});module.exports=se(ce);var k={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}},V={ArrowLeft:"\u2190",ArrowRight:"\u2192",ArrowUp:"\u2191",ArrowDown:"\u2193",Enter:"Enter",Backspace:"Backspace",Escape:"Esc",Space:"Space",Tab:"Tab",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Slash:"/",Comma:",",Period:".",Semicolon:";",Quote:"'",Minus:"-",Equal:"="},Y={"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"}},q=[{label:"Command",id:"description"},{label:"Key",id:"label"}];var S,v,A,w,C,D,j=class extends HTMLElement{constructor(){super(...arguments);N(this,C);N(this,S,[]);N(this,v,q);N(this,A,"label");N(this,w,!1)}static get observedAttributes(){return["title"]}set commands(n){R(this,S,n),b(this,w)&&P(this,C,D).call(this)}get commands(){return b(this,S)}set columns(n){R(this,v,n),b(this,w)&&P(this,C,D).call(this)}get columns(){return b(this,v)}set kbdColumn(n){R(this,A,n),b(this,w)&&P(this,C,D).call(this)}get kbdColumn(){return b(this,A)}attributeChangedCallback(){b(this,w)&&P(this,C,D).call(this)}connectedCallback(){R(this,w,!0),P(this,C,D).call(this)}disconnectedCallback(){R(this,w,!1)}};S=new WeakMap,v=new WeakMap,A=new WeakMap,w=new WeakMap,C=new WeakSet,D=function(){this.replaceChildren();let n=[];for(let i of b(this,v)){let o=document.createElement("th");o.classList.add("dn-commands-table-th"),o.textContent=i.label,n.push(o)}let t=document.createElement("tr");t.classList.add("dn-commands-table-thead-tr");for(let i of n)t.appendChild(i);let s=document.createElement("thead");s.classList.add("dn-commands-table-thead"),s.appendChild(t);let l=document.createElement("tbody");l.classList.add("dn-commands-table-tbody");for(let i of b(this,S)){let o=[];for(let p of b(this,v)){let f=i[p.id],d=document.createElement("td");if(d.classList.add("dn-commands-table-td"),b(this,A)!==null&&p.id===b(this,A)&&f){let L=document.createElement("kbd");L.classList.add("dn-commands-table-td-kbd"),L.textContent=f,d.append(L)}else d.textContent=f;o.push(d)}let m=document.createElement("tr");m.classList.add("dn-commands-table-tbody-tr");for(let p of o)m.appendChild(p);l.appendChild(m)}let y=document.createElement("table");y.classList.add("dn-commands-table");let a=this.getAttribute("title");if(a){let i=document.createElement("caption");i.classList.add("dn-commands-table-caption"),i.textContent=a,y.appendChild(i)}else y.setAttribute("aria-label","Commands table");y.appendChild(s),y.appendChild(l),this.appendChild(y)};var le=e=>e?V[e]||e.replace(/^Key/,"").replace(/^Digit/,""):"",oe=e=>{let r=e.replace(/[-_]+/g," ").trim();return r.charAt(0).toUpperCase()+r.slice(1)};function G(e,r){return e?Object.keys(e).map(n=>{let t=e[n],s=Y[n];return{label:t!=null&&t.key?le(t.key):(s==null?void 0:s.label)||"",description:(r==null?void 0:r[n])||(s==null?void 0:s.description)||oe(n),command:n}}):[]}var de=e=>{let r=a=>{t.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},n=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},s=!1,l={cssClass:k.cssClass,spatialProperties:x({},k.spatialProperties),semantics:x({},k.semantics),parentSemantics:x({},k.parentSemantics),existingElement:x({},k.existingElement)},y=(a,i)=>typeof i=="function"?i:x(x({},a),i);return e.defaults&&(l.cssClass=e.defaults.cssClass||l.cssClass,l.spatialProperties=e.defaults.spatialProperties?y(l.spatialProperties,e.defaults.spatialProperties):l.spatialProperties,l.semantics=e.defaults.semantics?y(l.semantics,e.defaults.semantics):l.semantics,l.parentSemantics=e.defaults.parentSemantics?y(l.parentSemantics,e.defaults.parentSemantics):l.parentSemantics,l.existingElement=e.defaults.existingElement?x(x({},l.existingElement),e.defaults.existingElement):l.existingElement),t.initialize=()=>{var a,i;if(s){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),(i=e.exitElement)!=null&&i.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",o=>{var m,p;t.exitElement.style.display="block",t.clearStructure(),(p=(m=e.exitElement)==null?void 0:m.callbacks)!=null&&p.focus&&e.exitElement.callbacks.focus(o)}),t.exitElement.addEventListener("blur",o=>{var m,p;t.exitElement.style.display="none",(p=(m=e.exitElement)==null?void 0:m.callbacks)!=null&&p.blur&&e.exitElement.callbacks.blur(o)}),t.root.appendChild(t.exitElement)),s=!0,t.root},t.render=a=>{let i=a.renderId+"",o=e.elementData[i];if(!o){console.warn(`Render data not found with renderId: ${i}. Failed to render.`);return}if(!s){console.error("render() was called before initialize(), renderer must be initialized first.");return}let m=!1,p={},f=c=>{var g;return typeof c=="function"?c(o,(g=a.datum)!=null?g:a.data):c},d=(c,g,h)=>{var H,_,W;let E=f(o[c]||l[c]),X=h&&m?p[g]:E==null?void 0:E[g],ee=(W=(H=f(l[c]))==null?void 0:H[g])!=null?W:(_=k[c])==null?void 0:_[g];return f(X)||f(ee)||(g?void 0:E)};m=d("existingElement","useForSpatialProperties"),p=d("existingElement","spatialProperties");let L=parseFloat(d("spatialProperties","width",!0)||0),M=parseFloat(d("spatialProperties","height",!0)||0),K=parseFloat(d("spatialProperties","x",!0)||0),I=parseFloat(d("spatialProperties","y",!0)||0),u=document.createElement(d("parentSemantics","elementType")),F=d("parentSemantics","attributes");typeof F=="object"&&Object.keys(F).forEach(c=>{u.setAttribute(c,F[c])}),u.setAttribute("role",d("parentSemantics","role")),u.id=i,u.classList.add("dn-node"),u.classList.add(d("cssClass")),u.style.width=L+"px",u.style.height=M+"px",u.style.left=K+"px",u.style.top=I+"px",u.setAttribute("tabindex","0"),u.addEventListener("focus",r),u.addEventListener("blur",n);let B=document.createElement(d("semantics","elementType")),O=d("semantics","attributes");typeof O=="object"&&Object.keys(O).forEach(c=>{B.setAttribute(c,O[c])}),B.setAttribute("role",d("semantics","role")),B.classList.add("dn-node-text");let U=d("semantics","label");o.showText&&(B.innerText=U),U||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),B.setAttribute("aria-label",U),u.appendChild(B);let $=d("spatialProperties","path");if($){let c=L+K+10,g=M+I+10,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("width",c+""),h.setAttribute("height",g+""),h.setAttribute("viewBox",`0 0 ${c} ${g}`),h.style.left=-K+"px",h.style.top=-I+"px",h.classList.add("dn-node-svg"),h.setAttribute("role","presentation"),h.setAttribute("focusable","false");let E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d",$),E.classList.add("dn-node-path"),h.appendChild(E),u.appendChild(h)}return t.wrapper.appendChild(u),u},t.remove=a=>{let i=document.getElementById(a);t.wrapper.getAttribute("aria-activedescendant")===a&&t.wrapper.setAttribute("aria-activedescendant",""),i&&(i.removeEventListener("focus",r),i.removeEventListener("blur",n),i.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(a=>{t.entryButton&&t.entryButton===a||t.remove(a.id)})},t.initializeCommands=a=>{let i=document.getElementById(a==null?void 0:a.rootId);if(!i){console.error("Commands root element not found in document.");return}let o=a.commands,m=G(a.navigationRules,a.descriptions),p=o?typeof o=="function"?o(m):o:m;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let f=document.createElement("dn-commands-table");return a!=null&&a.title&&f.setAttribute("title",a.title),f.commands=p,a.columns&&(f.columns=a.columns),i.appendChild(f),f},t.getGenericCommandsFromNavRules=G,t.CommandsTable=j,t};
1
+ var T=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var q=(e,r,n)=>r in e?T(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,k=(e,r)=>{for(var n in r||(r={}))X.call(r,n)&&q(e,n,r[n]);if(Y)for(var n of Y(r))le.call(r,n)&&q(e,n,r[n]);return e};var oe=(e,r)=>{for(var n in r)T(e,n,{get:r[n],enumerable:!0})},de=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of se(r))!X.call(e,l)&&l!==n&&T(e,l,{get:()=>r[l],enumerable:!(t=ie(r,l))||t.enumerable});return e};var ce=e=>de(T({},"__esModule",{value:!0}),e);var z=(e,r,n)=>{if(!r.has(e))throw TypeError("Cannot "+n)};var b=(e,r,n)=>(z(e,r,"read from private field"),n?n.call(e):r.get(e)),N=(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)},R=(e,r,n,t)=>(z(e,r,"write to private field"),t?t.call(e,n):r.set(e,n),n);var P=(e,r,n)=>(z(e,r,"access private method"),n);var fe={};oe(fe,{default:()=>pe});module.exports=ce(fe);var v={cssClass:void 0,spatialProperties:{x:0,y:0,width:0,height:0,path:""},semantics:{label:"",elementType:"div",role:"image",attributes:void 0},parentSemantics:{label:"",elementType:"figure",role:"figure",attributes:void 0},existingElement:{useForSpatialProperties:!1,spatialProperties:void 0}},ee={ArrowLeft:"\u2190",ArrowRight:"\u2192",ArrowUp:"\u2191",ArrowDown:"\u2193",Enter:"Enter",Backspace:"Backspace",Escape:"Esc",Space:"Space",Tab:"Tab",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Slash:"/",Comma:",",Period:".",Semicolon:";",Quote:"'",Minus:"-",Equal:"="},te={"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"}},re=[{label:"Command",id:"description"},{label:"Key",id:"label"}];var S,A,L,w,C,D,j=class extends HTMLElement{constructor(){super(...arguments);N(this,C);N(this,S,[]);N(this,A,re);N(this,L,"label");N(this,w,!1)}static get observedAttributes(){return["title"]}set commands(n){R(this,S,n),b(this,w)&&P(this,C,D).call(this)}get commands(){return b(this,S)}set columns(n){R(this,A,n),b(this,w)&&P(this,C,D).call(this)}get columns(){return b(this,A)}set kbdColumn(n){R(this,L,n),b(this,w)&&P(this,C,D).call(this)}get kbdColumn(){return b(this,L)}attributeChangedCallback(){b(this,w)&&P(this,C,D).call(this)}connectedCallback(){R(this,w,!0),P(this,C,D).call(this)}disconnectedCallback(){R(this,w,!1)}};S=new WeakMap,A=new WeakMap,L=new WeakMap,w=new WeakMap,C=new WeakSet,D=function(){this.replaceChildren();let n=[];for(let i of b(this,A)){let d=document.createElement("th");d.classList.add("dn-commands-table-th"),d.textContent=i.label,n.push(d)}let t=document.createElement("tr");t.classList.add("dn-commands-table-thead-tr");for(let i of n)t.appendChild(i);let l=document.createElement("thead");l.classList.add("dn-commands-table-thead"),l.appendChild(t);let o=document.createElement("tbody");o.classList.add("dn-commands-table-tbody");for(let i of b(this,S)){let d=[];for(let p of b(this,A)){let f=i[p.id],x=document.createElement("td");if(x.classList.add("dn-commands-table-td"),b(this,L)!==null&&p.id===b(this,L)&&f){let c=document.createElement("kbd");c.classList.add("dn-commands-table-td-kbd"),c.textContent=f,x.append(c)}else x.textContent=f;d.push(x)}let m=document.createElement("tr");m.classList.add("dn-commands-table-tbody-tr");for(let p of d)m.appendChild(p);o.appendChild(m)}let g=document.createElement("table");g.classList.add("dn-commands-table");let a=this.getAttribute("title");if(a){let i=document.createElement("caption");i.classList.add("dn-commands-table-caption"),i.textContent=a,g.appendChild(i)}else g.setAttribute("aria-label","Commands table");g.appendChild(l),g.appendChild(o),this.appendChild(g)};var ue=e=>e?ee[e]||e.replace(/^Key/,"").replace(/^Digit/,""):"",me=e=>{let r=e.replace(/[-_]+/g," ").trim();return r.charAt(0).toUpperCase()+r.slice(1)};function G(e,r){return e?Object.keys(e).map(n=>{let t=e[n],l=te[n];return{label:t!=null&&t.key?ue(t.key):(l==null?void 0:l.label)||"",description:(r==null?void 0:r[n])||(l==null?void 0:l.description)||me(n),command:n}}):[]}var pe=e=>{let r=a=>{t.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},n=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},l=!1,o={cssClass:v.cssClass,spatialProperties:k({},v.spatialProperties),semantics:k({},v.semantics),parentSemantics:k({},v.parentSemantics),existingElement:k({},v.existingElement)},g=(a,i)=>typeof i=="function"?i:k(k({},a),i);return e.defaults&&(o.cssClass=e.defaults.cssClass||o.cssClass,o.spatialProperties=e.defaults.spatialProperties?g(o.spatialProperties,e.defaults.spatialProperties):o.spatialProperties,o.semantics=e.defaults.semantics?g(o.semantics,e.defaults.semantics):o.semantics,o.parentSemantics=e.defaults.parentSemantics?g(o.parentSemantics,e.defaults.parentSemantics):o.parentSemantics,o.existingElement=e.defaults.existingElement?g(o.existingElement,e.defaults.existingElement):o.existingElement),t.initialize=()=>{var a,i;if(l){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),(i=e.exitElement)!=null&&i.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 m,p;t.exitElement.style.display="block",t.clearStructure(),(p=(m=e.exitElement)==null?void 0:m.callbacks)!=null&&p.focus&&e.exitElement.callbacks.focus(d)}),t.exitElement.addEventListener("blur",d=>{var m,p;t.exitElement.style.display="none",(p=(m=e.exitElement)==null?void 0:m.callbacks)!=null&&p.blur&&e.exitElement.callbacks.blur(d)}),t.root.appendChild(t.exitElement)),l=!0,t.root},t.render=a=>{let i=a.renderId+"",d=e.elementData[i];if(!d){console.warn(`Render data not found with renderId: ${i}. Failed to render.`);return}if(!l){console.error("render() was called before initialize(), renderer must be initialized first.");return}let m=!1,p={},f=new Map,x=s=>{var y;return typeof s!="function"?s:f.has(s)?f.get(s):f.set(s,s(d,(y=a.datum)!=null?y:a.data)).get(s)},c=(s,y,h)=>{var W,Z,J,Q,V;let E=x(d[s]||o[s]),ne=h&&m?p[y]:E==null?void 0:E[y],ae=(J=(W=x(o[s]))==null?void 0:W[y])!=null?J:(Z=v[s])==null?void 0:Z[y];return(V=(Q=x(ne))!=null?Q:x(ae))!=null?V:y?void 0:E};m=c("existingElement","useForSpatialProperties"),p=c("existingElement","spatialProperties");let M=parseFloat(c("spatialProperties","width",!0)||0),$=parseFloat(c("spatialProperties","height",!0)||0),K=parseFloat(c("spatialProperties","x",!0)||0),I=parseFloat(c("spatialProperties","y",!0)||0),u=document.createElement(c("parentSemantics","elementType")),F=c("parentSemantics","attributes");typeof F=="object"&&Object.keys(F).forEach(s=>{u.setAttribute(s,F[s])}),u.setAttribute("role",c("parentSemantics","role")),u.id=i,u.classList.add("dn-node");let H=c("cssClass");H&&u.classList.add(H),u.style.width=M+"px",u.style.height=$+"px",u.style.left=K+"px",u.style.top=I+"px",u.setAttribute("tabindex","0"),u.addEventListener("focus",r),u.addEventListener("blur",n);let B=document.createElement(c("semantics","elementType")),O=c("semantics","attributes");typeof O=="object"&&Object.keys(O).forEach(s=>{B.setAttribute(s,O[s])}),B.setAttribute("role",c("semantics","role")),B.classList.add("dn-node-text");let U=c("semantics","label");d.showText&&(B.innerText=U),U||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),B.setAttribute("aria-label",U),u.appendChild(B);let _=c("spatialProperties","path");if(_){let s=M+K+10,y=$+I+10,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("width",s+""),h.setAttribute("height",y+""),h.setAttribute("viewBox",`0 0 ${s} ${y}`),h.style.left=-K+"px",h.style.top=-I+"px",h.classList.add("dn-node-svg"),h.setAttribute("role","presentation"),h.setAttribute("focusable","false");let E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d",_),E.classList.add("dn-node-path"),h.appendChild(E),u.appendChild(h)}return t.wrapper.appendChild(u),u},t.remove=a=>{let i=document.getElementById(a);t.wrapper.getAttribute("aria-activedescendant")===a&&t.wrapper.setAttribute("aria-activedescendant",""),i&&(i.removeEventListener("focus",r),i.removeEventListener("blur",n),i.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(a=>{t.entryButton&&t.entryButton===a||t.remove(a.id)})},t.initializeCommands=a=>{let i=document.getElementById(a==null?void 0:a.rootId);if(!i){console.error("Commands root element not found in document.");return}let d=a.commands,m=G(a.navigationRules,a.descriptions),p=d?typeof d=="function"?d(m):d:m;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let f=document.createElement("dn-commands-table");return a!=null&&a.title&&f.setAttribute("title",a.title),f.commands=p,a.columns&&(f.columns=a.columns),i.appendChild(f),f},t.getGenericCommandsFromNavRules=G,t.CommandsTable=j,t};
package/dist/rendering.js CHANGED
@@ -1 +1 @@
1
- import{d as M}from"./chunk-ZTY2OAPD.js";import{a as E,c as u,d as B,e as P,f as S,q as w,t as J}from"./chunk-B5HGEXMZ.js";var I,v,A,x,y,T,j=class extends HTMLElement{constructor(){super(...arguments);B(this,y);B(this,I,[]);B(this,v,J);B(this,A,"label");B(this,x,!1)}static get observedAttributes(){return["title"]}set commands(b){P(this,I,b),u(this,x)&&S(this,y,T).call(this)}get commands(){return u(this,I)}set columns(b){P(this,v,b),u(this,x)&&S(this,y,T).call(this)}get columns(){return u(this,v)}set kbdColumn(b){P(this,A,b),u(this,x)&&S(this,y,T).call(this)}get kbdColumn(){return u(this,A)}attributeChangedCallback(){u(this,x)&&S(this,y,T).call(this)}connectedCallback(){P(this,x,!0),S(this,y,T).call(this)}disconnectedCallback(){P(this,x,!1)}};I=new WeakMap,v=new WeakMap,A=new WeakMap,x=new WeakMap,y=new WeakSet,T=function(){this.replaceChildren();let b=[];for(let s of u(this,v)){let r=document.createElement("th");r.classList.add("dn-commands-table-th"),r.textContent=s.label,b.push(r)}let e=document.createElement("tr");e.classList.add("dn-commands-table-thead-tr");for(let s of b)e.appendChild(s);let g=document.createElement("thead");g.classList.add("dn-commands-table-thead"),g.appendChild(e);let a=document.createElement("tbody");a.classList.add("dn-commands-table-tbody");for(let s of u(this,I)){let r=[];for(let o of u(this,v)){let m=s[o.id],i=document.createElement("td");if(i.classList.add("dn-commands-table-td"),u(this,A)!==null&&o.id===u(this,A)&&m){let L=document.createElement("kbd");L.classList.add("dn-commands-table-td-kbd"),L.textContent=m,i.append(L)}else i.textContent=m;r.push(i)}let c=document.createElement("tr");c.classList.add("dn-commands-table-tbody-tr");for(let o of r)c.appendChild(o);a.appendChild(c)}let h=document.createElement("table");h.classList.add("dn-commands-table");let n=this.getAttribute("title");if(n){let s=document.createElement("caption");s.classList.add("dn-commands-table-caption"),s.textContent=n,h.appendChild(s)}else h.setAttribute("aria-label","Commands table");h.appendChild(g),h.appendChild(a),this.appendChild(h)};var ee=t=>{let R=n=>{e.wrapper.setAttribute("aria-activedescendant",n.srcElement.id)},b=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},g=!1,a={cssClass:w.cssClass,spatialProperties:E({},w.spatialProperties),semantics:E({},w.semantics),parentSemantics:E({},w.parentSemantics),existingElement:E({},w.existingElement)},h=(n,s)=>typeof s=="function"?s:E(E({},n),s);return t.defaults&&(a.cssClass=t.defaults.cssClass||a.cssClass,a.spatialProperties=t.defaults.spatialProperties?h(a.spatialProperties,t.defaults.spatialProperties):a.spatialProperties,a.semantics=t.defaults.semantics?h(a.semantics,t.defaults.semantics):a.semantics,a.parentSemantics=t.defaults.parentSemantics?h(a.parentSemantics,t.defaults.parentSemantics):a.parentSemantics,a.existingElement=t.defaults.existingElement?E(E({},a.existingElement),t.defaults.existingElement):a.existingElement),e.initialize=()=>{var n,s;if(g){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),(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",r=>{var c,o;e.exitElement.style.display="block",e.clearStructure(),(o=(c=t.exitElement)==null?void 0:c.callbacks)!=null&&o.focus&&t.exitElement.callbacks.focus(r)}),e.exitElement.addEventListener("blur",r=>{var c,o;e.exitElement.style.display="none",(o=(c=t.exitElement)==null?void 0:c.callbacks)!=null&&o.blur&&t.exitElement.callbacks.blur(r)}),e.root.appendChild(e.exitElement)),g=!0,e.root},e.render=n=>{let s=n.renderId+"",r=t.elementData[s];if(!r){console.warn(`Render data not found with renderId: ${s}. Failed to render.`);return}if(!g){console.error("render() was called before initialize(), renderer must be initialized first.");return}let c=!1,o={},m=l=>{var p;return typeof l=="function"?l(r,(p=n.datum)!=null?p:n.data):l},i=(l,p,f)=>{var V,W,q;let C=m(r[l]||a[l]),K=f&&c?o[p]:C==null?void 0:C[p],O=(q=(V=m(a[l]))==null?void 0:V[p])!=null?q:(W=w[l])==null?void 0:W[p];return m(K)||m(O)||(p?void 0:C)};c=i("existingElement","useForSpatialProperties"),o=i("existingElement","spatialProperties");let L=parseFloat(i("spatialProperties","width",!0)||0),$=parseFloat(i("spatialProperties","height",!0)||0),D=parseFloat(i("spatialProperties","x",!0)||0),N=parseFloat(i("spatialProperties","y",!0)||0),d=document.createElement(i("parentSemantics","elementType")),F=i("parentSemantics","attributes");typeof F=="object"&&Object.keys(F).forEach(l=>{d.setAttribute(l,F[l])}),d.setAttribute("role",i("parentSemantics","role")),d.id=s,d.classList.add("dn-node"),d.classList.add(i("cssClass")),d.style.width=L+"px",d.style.height=$+"px",d.style.left=D+"px",d.style.top=N+"px",d.setAttribute("tabindex","0"),d.addEventListener("focus",R),d.addEventListener("blur",b);let k=document.createElement(i("semantics","elementType")),z=i("semantics","attributes");typeof z=="object"&&Object.keys(z).forEach(l=>{k.setAttribute(l,z[l])}),k.setAttribute("role",i("semantics","role")),k.classList.add("dn-node-text");let H=i("semantics","label");r.showText&&(k.innerText=H),H||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),k.setAttribute("aria-label",H),d.appendChild(k);let G=i("spatialProperties","path");if(G){let l=L+D+10,p=$+N+10,f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("width",l+""),f.setAttribute("height",p+""),f.setAttribute("viewBox",`0 0 ${l} ${p}`),f.style.left=-D+"px",f.style.top=-N+"px",f.classList.add("dn-node-svg"),f.setAttribute("role","presentation"),f.setAttribute("focusable","false");let C=document.createElementNS("http://www.w3.org/2000/svg","path");C.setAttribute("d",G),C.classList.add("dn-node-path"),f.appendChild(C),d.appendChild(f)}return e.wrapper.appendChild(d),d},e.remove=n=>{let s=document.getElementById(n);e.wrapper.getAttribute("aria-activedescendant")===n&&e.wrapper.setAttribute("aria-activedescendant",""),s&&(s.removeEventListener("focus",R),s.removeEventListener("blur",b),s.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(n=>{e.entryButton&&e.entryButton===n||e.remove(n.id)})},e.initializeCommands=n=>{let s=document.getElementById(n==null?void 0:n.rootId);if(!s){console.error("Commands root element not found in document.");return}let r=n.commands,c=M(n.navigationRules,n.descriptions),o=r?typeof r=="function"?r(c):r:c;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let m=document.createElement("dn-commands-table");return n!=null&&n.title&&m.setAttribute("title",n.title),m.commands=o,n.columns&&(m.columns=n.columns),s.appendChild(m),m},e.getGenericCommandsFromNavRules=M,e.CommandsTable=j,e};export{ee as default};
1
+ import{d as H}from"./chunk-ZTY2OAPD.js";import{a as w,c as u,d as B,e as P,f as S,q as v,t as U}from"./chunk-B5HGEXMZ.js";var I,A,L,x,g,T,j=class extends HTMLElement{constructor(){super(...arguments);B(this,g);B(this,I,[]);B(this,A,U);B(this,L,"label");B(this,x,!1)}static get observedAttributes(){return["title"]}set commands(b){P(this,I,b),u(this,x)&&S(this,g,T).call(this)}get commands(){return u(this,I)}set columns(b){P(this,A,b),u(this,x)&&S(this,g,T).call(this)}get columns(){return u(this,A)}set kbdColumn(b){P(this,L,b),u(this,x)&&S(this,g,T).call(this)}get kbdColumn(){return u(this,L)}attributeChangedCallback(){u(this,x)&&S(this,g,T).call(this)}connectedCallback(){P(this,x,!0),S(this,g,T).call(this)}disconnectedCallback(){P(this,x,!1)}};I=new WeakMap,A=new WeakMap,L=new WeakMap,x=new WeakMap,g=new WeakSet,T=function(){this.replaceChildren();let b=[];for(let s of u(this,A)){let i=document.createElement("th");i.classList.add("dn-commands-table-th"),i.textContent=s.label,b.push(i)}let e=document.createElement("tr");e.classList.add("dn-commands-table-thead-tr");for(let s of b)e.appendChild(s);let y=document.createElement("thead");y.classList.add("dn-commands-table-thead"),y.appendChild(e);let r=document.createElement("tbody");r.classList.add("dn-commands-table-tbody");for(let s of u(this,I)){let i=[];for(let o of u(this,A)){let m=s[o.id],E=document.createElement("td");if(E.classList.add("dn-commands-table-td"),u(this,L)!==null&&o.id===u(this,L)&&m){let l=document.createElement("kbd");l.classList.add("dn-commands-table-td-kbd"),l.textContent=m,E.append(l)}else E.textContent=m;i.push(E)}let c=document.createElement("tr");c.classList.add("dn-commands-table-tbody-tr");for(let o of i)c.appendChild(o);r.appendChild(c)}let p=document.createElement("table");p.classList.add("dn-commands-table");let n=this.getAttribute("title");if(n){let s=document.createElement("caption");s.classList.add("dn-commands-table-caption"),s.textContent=n,p.appendChild(s)}else p.setAttribute("aria-label","Commands table");p.appendChild(y),p.appendChild(r),this.appendChild(p)};var ae=t=>{let R=n=>{e.wrapper.setAttribute("aria-activedescendant",n.srcElement.id)},b=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},y=!1,r={cssClass:v.cssClass,spatialProperties:w({},v.spatialProperties),semantics:w({},v.semantics),parentSemantics:w({},v.parentSemantics),existingElement:w({},v.existingElement)},p=(n,s)=>typeof s=="function"?s:w(w({},n),s);return t.defaults&&(r.cssClass=t.defaults.cssClass||r.cssClass,r.spatialProperties=t.defaults.spatialProperties?p(r.spatialProperties,t.defaults.spatialProperties):r.spatialProperties,r.semantics=t.defaults.semantics?p(r.semantics,t.defaults.semantics):r.semantics,r.parentSemantics=t.defaults.parentSemantics?p(r.parentSemantics,t.defaults.parentSemantics):r.parentSemantics,r.existingElement=t.defaults.existingElement?p(r.existingElement,t.defaults.existingElement):r.existingElement),e.initialize=()=>{var n,s;if(y){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),(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",i=>{var c,o;e.exitElement.style.display="block",e.clearStructure(),(o=(c=t.exitElement)==null?void 0:c.callbacks)!=null&&o.focus&&t.exitElement.callbacks.focus(i)}),e.exitElement.addEventListener("blur",i=>{var c,o;e.exitElement.style.display="none",(o=(c=t.exitElement)==null?void 0:c.callbacks)!=null&&o.blur&&t.exitElement.callbacks.blur(i)}),e.root.appendChild(e.exitElement)),y=!0,e.root},e.render=n=>{let s=n.renderId+"",i=t.elementData[s];if(!i){console.warn(`Render data not found with renderId: ${s}. Failed to render.`);return}if(!y){console.error("render() was called before initialize(), renderer must be initialized first.");return}let c=!1,o={},m=new Map,E=a=>{var h;return typeof a!="function"?a:m.has(a)?m.get(a):m.set(a,a(i,(h=n.datum)!=null?h:n.data)).get(a)},l=(a,h,f)=>{var q,J,K,O,Q;let C=E(i[a]||r[a]),X=f&&c?o[h]:C==null?void 0:C[h],Y=(K=(q=E(r[a]))==null?void 0:q[h])!=null?K:(J=v[a])==null?void 0:J[h];return(Q=(O=E(X))!=null?O:E(Y))!=null?Q:h?void 0:C};c=l("existingElement","useForSpatialProperties"),o=l("existingElement","spatialProperties");let $=parseFloat(l("spatialProperties","width",!0)||0),G=parseFloat(l("spatialProperties","height",!0)||0),D=parseFloat(l("spatialProperties","x",!0)||0),N=parseFloat(l("spatialProperties","y",!0)||0),d=document.createElement(l("parentSemantics","elementType")),F=l("parentSemantics","attributes");typeof F=="object"&&Object.keys(F).forEach(a=>{d.setAttribute(a,F[a])}),d.setAttribute("role",l("parentSemantics","role")),d.id=s,d.classList.add("dn-node");let V=l("cssClass");V&&d.classList.add(V),d.style.width=$+"px",d.style.height=G+"px",d.style.left=D+"px",d.style.top=N+"px",d.setAttribute("tabindex","0"),d.addEventListener("focus",R),d.addEventListener("blur",b);let k=document.createElement(l("semantics","elementType")),z=l("semantics","attributes");typeof z=="object"&&Object.keys(z).forEach(a=>{k.setAttribute(a,z[a])}),k.setAttribute("role",l("semantics","role")),k.classList.add("dn-node-text");let M=l("semantics","label");i.showText&&(k.innerText=M),M||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),k.setAttribute("aria-label",M),d.appendChild(k);let W=l("spatialProperties","path");if(W){let a=$+D+10,h=G+N+10,f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("width",a+""),f.setAttribute("height",h+""),f.setAttribute("viewBox",`0 0 ${a} ${h}`),f.style.left=-D+"px",f.style.top=-N+"px",f.classList.add("dn-node-svg"),f.setAttribute("role","presentation"),f.setAttribute("focusable","false");let C=document.createElementNS("http://www.w3.org/2000/svg","path");C.setAttribute("d",W),C.classList.add("dn-node-path"),f.appendChild(C),d.appendChild(f)}return e.wrapper.appendChild(d),d},e.remove=n=>{let s=document.getElementById(n);e.wrapper.getAttribute("aria-activedescendant")===n&&e.wrapper.setAttribute("aria-activedescendant",""),s&&(s.removeEventListener("focus",R),s.removeEventListener("blur",b),s.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(n=>{e.entryButton&&e.entryButton===n||e.remove(n.id)})},e.initializeCommands=n=>{let s=document.getElementById(n==null?void 0:n.rootId);if(!s){console.error("Commands root element not found in document.");return}let i=n.commands,c=H(n.navigationRules,n.descriptions),o=i?typeof i=="function"?i(c):i:c;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let m=document.createElement("dn-commands-table");return n!=null&&n.title&&m.setAttribute("title",n.title),m.commands=o,n.columns&&(m.columns=n.columns),s.appendChild(m),m},e.getGenericCommandsFromNavRules=H,e.CommandsTable=j,e};export{ae as default};
@@ -1,21 +1,21 @@
1
- var G=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var be=(t,e)=>{for(var i in e)G(t,i,{get:e[i],enumerable:!0})},we=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ye(e))!ve.call(t,r)&&r!==i&&G(t,r,{get:()=>e[r],enumerable:!(s=fe(e,r))||s.enumerable});return t};var ke=t=>we(G({},"__esModule",{value:!0}),t);var U=(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 Re={};be(Re,{default:()=>Te});module.exports=ke(Re);var J={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var 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"}};var se=t=>{let e={},i=J,s=z;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 v={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return v[d.direction]!==r?v[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=J,s=z)},e.setNavigationKeyBindings(t.navigationRules),e};var xe=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.`},Ne=(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)},le=t=>t.navigationRules?Object.keys(t.navigationRules):[],Q=(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]},Ce=t=>t<=4?1:2,Ee=(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 v=i[a].toLowerCase();return v.startsWith(s)?!0:v.split(/\s+/).some(R=>R.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=Ce(s.length),g=[];for(let a=0;a<e.length;a++){let v=e[a],R=Q(s,v.toLowerCase());if(R<=f){g.push({candidate:v,dist:R});continue}if(i[v]){let S=i[v].toLowerCase().split(/\s+/);for(let A=0;A<S.length;A++)if(Q(s,S[A])<=f){g.push({candidate:v,dist:Q(s,S[A])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,v)=>a.dist-v.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,Ae=(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 v=d.data[g[a]];v!=null&&typeof v!="object"&&String(v).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},Te=t=>{var re,oe,ie,ae;let{structure:e,container:i,entryPoint:s,describeNode:r=xe,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 v=Object.keys(e.nodes).find(l=>e.nodes[l].dimensionLevel===0),R=e.dimensions?(re=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:re.nodeId:void 0,S=s||((oe=e.frame)==null?void 0:oe.rootId)||v||((ie=e.spatialGrid)==null?void 0:ie.rootId)||((ae=e.hierarchy)==null?void 0:ae.rootId)||R||Object.keys(e.nodes)[0],A=se({structure:e,navigationRules:e.navigationRules||{},entryPoint:S}),b=null,Z=Math.random().toString(36).slice(2,8),L=[],C=-1,I=null,P=[],ce=()=>{let l=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ var J=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var be=(t,e)=>{for(var i in e)J(t,i,{get:e[i],enumerable:!0})},we=(t,e,i,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ye(e))!ve.call(t,r)&&r!==i&&J(t,r,{get:()=>e[r],enumerable:!(l=fe(e,r))||l.enumerable});return t};var ke=t=>we(J({},"__esModule",{value:!0}),t);var U=(t,e,i)=>new Promise((l,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?l(c.value):Promise.resolve(c.value).then(n,o);p((i=i.apply(t,e)).next())});var Re={};be(Re,{default:()=>Te});module.exports=ke(Re);var z={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var Q={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 se=t=>{let e={},i=z,l=Q;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=l[n];if(!d)return;let f=(g,s)=>{if(g!==n)return null;let b={target:typeof s.target=="string"?s.target:s.target(o,r),source:typeof s.source=="string"?s.source:s.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(s=>{p||(p=f(s,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={},l=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=z,l=Q)},e.setNavigationKeyBindings(t.navigationRules),e};var xe=t=>{var i,l,r,n;let e=typeof t.semantics=="function"?t.semantics(t,t.data):t.semantics;if(e!=null&&e.label){let o=typeof e.label=="function"?e.label(t,t.data):e.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}: ${(l=t.data)==null?void 0:l[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.`},Ne=(t,e,i)=>{let l=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&&l.add(p)})}),Array.from(l)},le=t=>t.navigationRules?Object.keys(t.navigationRules):[],V=(t,e)=>{let i=t.length,l=e.length,r=Array.from({length:i+1},()=>Array(l+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=l;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=l;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][l]},Ce=t=>t<=4?1:2,Ee=(t,e,i={})=>{let l=t.toLowerCase().trim(),r=e.find(s=>s.toLowerCase()===l);if(r)return{match:r,ambiguous:[]};let n=e.find(s=>i[s]&&i[s].toLowerCase()===l);if(n)return{match:n,ambiguous:[]};let o=e.filter(s=>s.toLowerCase().startsWith(l));if(o.length===1)return{match:o[0],ambiguous:[]};let p=e.filter(s=>{if(!i[s])return!1;let b=i[s].toLowerCase();return b.startsWith(l)?!0:b.split(/\s+/).some(L=>L.startsWith(l))}),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=Ce(l.length),g=[];for(let s=0;s<e.length;s++){let b=e[s],L=V(l,b.toLowerCase());if(L<=f){g.push({candidate:b,dist:L});continue}if(i[b]){let S=i[b].toLowerCase().split(/\s+/);for(let A=0;A<S.length;A++)if(V(l,S[A])<=f){g.push({candidate:b,dist:V(l,S[A])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((s,b)=>s.dist-b.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(s=>s.candidate)}):{match:null,ambiguous:[]}},Z=(t,e)=>e[t]?`${e[t]} (${t})`:t,Ae=(t,e,i,l=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let p=0;p<o.length&&n.length<l;p++){let c=o[p],d=e.nodes[c],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let s=0;s<g.length&&!f;s++){let b=d.data[g[s]];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},Te=t=>{var re,oe,ie,ae;let{structure:e,container:i,entryPoint:l,describeNode:r=xe,commandLabels:n={},onNavigate:o,onExit:p,onClick:c,onHover:d,llm:f,data:g}=t,s=typeof i=="string"?document.getElementById(i):i;if(!s)throw new Error(`textChat: container "${i}" not found`);let b=Object.keys(e.nodes).find(a=>e.nodes[a].dimensionLevel===0),L=e.dimensions?(re=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:re.nodeId:void 0,S=l||((oe=e.frame)==null?void 0:oe.rootId)||b||((ie=e.spatialGrid)==null?void 0:ie.rootId)||((ae=e.hierarchy)==null?void 0:ae.rootId)||L||Object.keys(e.nodes)[0],A=se({structure:e,navigationRules:e.navigationRules||{},entryPoint:S}),v=null,X=Math.random().toString(36).slice(2,8),O=[],C=-1,R=null,P=[],ce=()=>{let a=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
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:
4
+ `);a+=`DATASET SUMMARY:
5
5
  - Columns: ${h.join(", ")}
6
6
  - Rows: ${g.length}
7
7
  - Sample (first 3):
8
8
  ${m}
9
9
 
10
- `,l+=`FULL DATASET (JSON):
10
+ `,a+=`FULL DATASET (JSON):
11
11
  `+JSON.stringify(g)+`
12
12
 
13
- `}if(b){let h=e.nodes[b];l+=`CURRENT POSITION: ${h?r(h):b}
13
+ `}if(v){let h=e.nodes[v];a+=`CURRENT POSITION: ${h?r(h):v}
14
14
 
15
- `}else l+=`CURRENT POSITION: Not yet navigated into the structure.
15
+ `}else a+=`CURRENT POSITION: Not yet navigated into the structure.
16
16
 
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.
17
+ `;return a+=`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
- `,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.
19
+ `,a+=`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
- `,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},O=document.createElement("div");O.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),O.appendChild(k);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),D=document.createElement("input");D.type="checkbox",D.checked=!0,D.addEventListener("change",()=>{k.setAttribute("aria-live",D.checked?"polite":"off")}),Y.appendChild(D),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),O.appendChild(W);let $=document.createElement("form");$.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${Z}`),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-${Z}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let q=document.createElement("button");q.type="submit",q.textContent="Send",$.appendChild(M),$.appendChild(x),$.appendChild(q),O.appendChild($),a.appendChild(O);let X="";x.addEventListener("keydown",l=>{if(l.key==="ArrowUp"){if(l.preventDefault(),L.length===0)return;C===-1?(X=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=X)}});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},B=l=>F(l,"dn-text-chat-system"),de=l=>F(`> ${l}`,"dn-text-chat-input-echo"),y=l=>F(l,"dn-text-chat-response"),ue=(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(K=>{let T=document.createElement("li");T.textContent=K,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},_=l=>U(void 0,null,function*(){let h={role:"system",content:ce()};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?(B('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),B('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.')):B('Text navigation ready. Type "enter" to begin or "help" for available commands.');let ee=["enter","help","more","more help","clear","click","select","hover","inspect"],te=l=>{let h=A.moveTo(l);h?(b=h.id,o&&o(h),y(`Moved to: ${r(h)}`)):y("Could not move to that node.")},ne=l=>U(void 0,null,function*(){let h=l.trim();if(!h)return;de(h);let m=h.toLowerCase();if(I){let u=parseInt(h,10);if(!isNaN(u)&&u>=1&&u<=I.length){let w=I[u-1];I=null,te(w.nodeId);return}I=null}if(m==="clear"){k.innerHTML="",B('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(b){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}b=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(!b)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let me=e.nodes[b],he=Ne(b,me,e).map(ge=>V(ge,n));y(`Available: ${he.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!b){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[b];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(!b){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[b];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=Ae(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?te(w[0].nodeId):(I=w,ue(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=le(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!b){if(f&&(yield _(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=le(e),{match:E,ambiguous:K}=Ee(m,[...N,...ee],n);if(E&&ee.includes(E)){yield ne(E);return}if(!E&&K.length>0){let u=K.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield _(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 T=E,pe=n[T]||T;if(T==="exit"){b=null,p&&p(),y('Exited the structure. Type "enter" to re-enter.');return}let H=A.move(b,T);H?(b=H.id,o&&o(H),y(`${pe}: ${r(H)}`)):y(`Cannot move "${T}" from here.`)});return $.addEventListener("submit",l=>U(void 0,null,function*(){l.preventDefault();let h=x.value.trim();h&&(L.push(h),C=-1),yield ne(x.value),x.value="",x.focus()})),{destroy(){a.removeChild(O)},getCurrentNode(){return b&&e.nodes[b]||null}}};
21
+ `,a+='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.',a},I=document.createElement("div");I.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),I.appendChild(k);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),D=document.createElement("input");D.type="checkbox",D.checked=!0,D.addEventListener("change",()=>{k.setAttribute("aria-live",D.checked?"polite":"off")}),Y.appendChild(D),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),I.appendChild(W);let $=document.createElement("form");$.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${X}`),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-${X}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let q=document.createElement("button");q.type="submit",q.textContent="Send",$.appendChild(M),$.appendChild(x),$.appendChild(q),I.appendChild($),s.appendChild(I);let _="";x.addEventListener("keydown",a=>{if(a.key==="ArrowUp"){if(a.preventDefault(),O.length===0)return;C===-1?(_=x.value,C=O.length-1):C>0&&C--,x.value=O[C]}else if(a.key==="ArrowDown"){if(a.preventDefault(),C===-1)return;C<O.length-1?(C++,x.value=O[C]):(C=-1,x.value=_)}});let F=(a,h)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${h}`,m.textContent=a,k.appendChild(m),k.scrollTop=k.scrollHeight},B=a=>F(a,"dn-text-chat-system"),de=a=>F(`> ${a}`,"dn-text-chat-input-echo"),y=a=>F(a,"dn-text-chat-response"),ue=(a,h)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=a,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",h.forEach(K=>{let T=document.createElement("li");T.textContent=K,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},ee=a=>U(void 0,null,function*(){let h={role:"system",content:ce()};P.push({role:"user",content:a});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?(B('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),B('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.')):B('Text navigation ready. Type "enter" to begin or "help" for available commands.');let te=["enter","help","more","more help","clear","click","select","hover","inspect"],ne=a=>{let h=A.moveTo(a);h?(v=h.id,o&&o(h),y(`Moved to: ${r(h)}`)):y("Could not move to that node.")},G=a=>U(void 0,null,function*(){let h=a.trim();if(!h)return;de(h);let m=h.toLowerCase();if(R){let u=parseInt(h,10);if(!isNaN(u)&&u>=1&&u<=R.length){let w=R[u-1];R=null,ne(w.nodeId);return}R=null}if(m==="clear"){k.innerHTML="",B('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=[];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 me=e.nodes[v],he=Ne(v,me,e).map(ge=>Z(ge,n));y(`Available: ${he.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=Ae(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?ne(w[0].nodeId):(R=w,ue(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=le(e).map(j=>Z(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield ee(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=le(e),{match:E,ambiguous:K}=Ee(m,[...N,...te],n);if(E&&te.includes(E)){yield G(E);return}if(!E&&K.length>0){let u=K.map(w=>Z(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield ee(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 T=E,pe=n[T]||T;if(T==="exit"){v=null,p&&p(),y('Exited the structure. Type "enter" to re-enter.');return}let H=A.move(v,T);H?(v=H.id,o&&o(H),y(`${pe}: ${r(H)}`)):y(`Cannot move "${T}" from here.`)});return $.addEventListener("submit",a=>U(void 0,null,function*(){a.preventDefault();let h=x.value.trim();h&&(O.push(h),C=-1),yield G(x.value),x.value="",x.focus()})),{destroy(){s.removeChild(I)},getCurrentNode(){return v&&e.nodes[v]||null},submit(a){return G(a)},setCurrentNode(a){v=a&&e.nodes[a]?a:null,R=null}}};
package/dist/text-chat.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as se}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js";var me=t=>{var e,d,u,a,o;if((e=t.semantics)!=null&&e.label){let n=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(n)return n}if(!t.derivedNode)return t.data?Object.keys(t.data).map(n=>`${n}: ${t.data[n]}`).join(". ")+". Data point.":t.id;if((d=t.data)!=null&&d.dimensionKey){let n=0,f=Object.keys(t.data.divisions||{});f.forEach(m=>{n+=Object.keys(t.data.divisions[m].values||{}).length});let b=`${t.derivedNode}.`;return b+=f.length&&n?` ${f.length} division${f.length>1?"s":""}, ${n} datapoint${n>1?"s":""}.`:" No child data points.",b+=` ${t.data.type} dimension.`,b}return`${t.derivedNode}: ${(u=t.data)==null?void 0:u[t.derivedNode]}. ${Object.keys(((a=t.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((o=t.data)==null?void 0:o.values)||{}).length>1?"s":""}. Division.`},pe=(t,e,d)=>{let u=new Set,a=d.navigationRules||{};return e.edges&&e.edges.forEach(o=>{let n=d.edges[o];n&&n.navigationRules.forEach(f=>{let b=a[f];if(!b)return;let m=b.direction==="target"?n.target:n.source,p=typeof m=="function"?m(e,t):m;p&&p!==t&&u.add(f)})}),Array.from(u)},ae=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let d=t.length,u=e.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let o=0;o<=d;o++)a[o][0]=o;for(let o=0;o<=u;o++)a[0][o]=o;for(let o=1;o<=d;o++)for(let n=1;n<=u;n++){let f=t[o-1]===e[n-1]?0:1;a[o][n]=Math.min(a[o-1][n]+1,a[o][n-1]+1,a[o-1][n-1]+f),o>1&&n>1&&t[o-1]===e[n-2]&&t[o-2]===e[n-1]&&(a[o][n]=Math.min(a[o][n],a[o-2][n-2]+f))}return a[d][u]},ge=t=>t<=4?1:2,fe=(t,e,d={})=>{let u=t.toLowerCase().trim(),a=e.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let o=e.find(l=>d[l]&&d[l].toLowerCase()===u);if(o)return{match:o,ambiguous:[]};let n=e.filter(l=>l.toLowerCase().startsWith(u));if(n.length===1)return{match:n[0],ambiguous:[]};let f=e.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(I=>I.startsWith(u))}),b=new Set([...n,...f]),m=Array.from(b);if(m.length===1)return{match:m[0],ambiguous:[]};if(m.length>1)return{match:null,ambiguous:m};let p=ge(u.length),g=[];for(let l=0;l<e.length;l++){let x=e[l],I=z(u,x.toLowerCase());if(I<=p){g.push({candidate:x,dist:I});continue}if(d[x]){let M=d[x].toLowerCase().split(/\s+/);for(let T=0;T<M.length;T++)if(z(u,M[T])<=p){g.push({candidate:x,dist:z(u,M[T])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((l,x)=>l.dist-x.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(l=>l.candidate)}):{match:null,ambiguous:[]}},B=(t,e)=>e[t]?`${e[t]} (${t})`:t,ve=(t,e,d,u=10)=>{let a=t.toLowerCase(),o=[],n=Object.keys(e.nodes);for(let f=0;f<n.length&&o.length<u;f++){let b=n[f],m=e.nodes[b],p=!1;if(m.data&&!p){let g=Object.keys(m.data);for(let l=0;l<g.length&&!p;l++){let x=m.data[g[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(p=!0)}}!p&&m.derivedNode&&m.derivedNode.toLowerCase().includes(a)&&(p=!0),!p&&b.toLowerCase().includes(a)&&(p=!0),p&&o.push({nodeId:b,description:d(m)})}return o},Ce=t=>{var ee,te,ne,oe;let{structure:e,container:d,entryPoint:u,describeNode:a=me,commandLabels:o={},onNavigate:n,onExit:f,onClick:b,onHover:m,llm:p,data:g}=t,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=Object.keys(e.nodes).find(s=>e.nodes[s].dimensionLevel===0),I=e.dimensions?(ee=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:ee.nodeId:void 0,M=u||((te=e.frame)==null?void 0:te.rootId)||x||((ne=e.spatialGrid)==null?void 0:ne.rootId)||((oe=e.hierarchy)==null?void 0:oe.rootId)||I||Object.keys(e.nodes)[0],T=se({structure:e,navigationRules:e.navigationRules||{},entryPoint:M}),v=null,G=Math.random().toString(36).slice(2,8),L=[],E=-1,A=null,S=[],re=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ import{a as st}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js";var mt=e=>{var d,u,r,o;let t=typeof e.semantics=="function"?e.semantics(e,e.data):e.semantics;if(t!=null&&t.label){let n=typeof t.label=="function"?t.label(e,e.data):t.label;if(n)return n}if(!e.derivedNode)return e.data?Object.keys(e.data).map(n=>`${n}: ${e.data[n]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let n=0,v=Object.keys(e.data.divisions||{});v.forEach(m=>{n+=Object.keys(e.data.divisions[m].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&n?` ${v.length} division${v.length>1?"s":""}, ${n} datapoint${n>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(((r=e.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((o=e.data)==null?void 0:o.values)||{}).length>1?"s":""}. Division.`},pt=(e,t,d)=>{let u=new Set,r=d.navigationRules||{};return t.edges&&t.edges.forEach(o=>{let n=d.edges[o];n&&n.navigationRules.forEach(v=>{let b=r[v];if(!b)return;let m=b.direction==="target"?n.target:n.source,p=typeof m=="function"?m(t,e):m;p&&p!==e&&u.add(v)})}),Array.from(u)},rt=e=>e.navigationRules?Object.keys(e.navigationRules):[],B=(e,t)=>{let d=e.length,u=t.length,r=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let o=0;o<=d;o++)r[o][0]=o;for(let o=0;o<=u;o++)r[0][o]=o;for(let o=1;o<=d;o++)for(let n=1;n<=u;n++){let v=e[o-1]===t[n-1]?0:1;r[o][n]=Math.min(r[o-1][n]+1,r[o][n-1]+1,r[o-1][n-1]+v),o>1&&n>1&&e[o-1]===t[n-2]&&e[o-2]===t[n-1]&&(r[o][n]=Math.min(r[o][n],r[o-2][n-2]+v))}return r[d][u]},gt=e=>e<=4?1:2,ft=(e,t,d={})=>{let u=e.toLowerCase().trim(),r=t.find(l=>l.toLowerCase()===u);if(r)return{match:r,ambiguous:[]};let o=t.find(l=>d[l]&&d[l].toLowerCase()===u);if(o)return{match:o,ambiguous:[]};let n=t.filter(l=>l.toLowerCase().startsWith(u));if(n.length===1)return{match:n[0],ambiguous:[]};let v=t.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(A=>A.startsWith(u))}),b=new Set([...n,...v]),m=Array.from(b);if(m.length===1)return{match:m[0],ambiguous:[]};if(m.length>1)return{match:null,ambiguous:m};let p=gt(u.length),g=[];for(let l=0;l<t.length;l++){let x=t[l],A=B(u,x.toLowerCase());if(A<=p){g.push({candidate:x,dist:A});continue}if(d[x]){let M=d[x].toLowerCase().split(/\s+/);for(let T=0;T<M.length;T++)if(B(u,M[T])<=p){g.push({candidate:x,dist:B(u,M[T])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((l,x)=>l.dist-x.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(l=>l.candidate)}):{match:null,ambiguous:[]}},G=(e,t)=>t[e]?`${t[e]} (${e})`:e,vt=(e,t,d,u=10)=>{let r=e.toLowerCase(),o=[],n=Object.keys(t.nodes);for(let v=0;v<n.length&&o.length<u;v++){let b=n[v],m=t.nodes[b],p=!1;if(m.data&&!p){let g=Object.keys(m.data);for(let l=0;l<g.length&&!p;l++){let x=m.data[g[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(r)&&(p=!0)}}!p&&m.derivedNode&&m.derivedNode.toLowerCase().includes(r)&&(p=!0),!p&&b.toLowerCase().includes(r)&&(p=!0),p&&o.push({nodeId:b,description:d(m)})}return o},Ct=e=>{var tt,et,nt,ot;let{structure:t,container:d,entryPoint:u,describeNode:r=mt,commandLabels:o={},onNavigate:n,onExit:v,onClick:b,onHover:m,llm:p,data:g}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=Object.keys(t.nodes).find(s=>t.nodes[s].dimensionLevel===0),A=t.dimensions?(tt=t.dimensions[Object.keys(t.dimensions)[0]])==null?void 0:tt.nodeId:void 0,M=u||((et=t.frame)==null?void 0:et.rootId)||x||((nt=t.spatialGrid)==null?void 0:nt.rootId)||((ot=t.hierarchy)==null?void 0:ot.rootId)||A||Object.keys(t.nodes)[0],T=st({structure:t,navigationRules:t.navigationRules||{},entryPoint:M}),f=null,V=Math.random().toString(36).slice(2,8),I=[],E=-1,L=null,S=[],at=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
3
  `;if(g&&g.length>0){let c=Object.keys(g[0]),i=g.slice(0,3).map(w=>JSON.stringify(w)).join(`
4
4
  `);s+=`DATASET SUMMARY:
@@ -10,7 +10,7 @@ import{a as se}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js"
10
10
  `,s+=`FULL DATASET (JSON):
11
11
  `+JSON.stringify(g)+`
12
12
 
13
- `}if(v){let c=e.nodes[v];s+=`CURRENT POSITION: ${c?a(c):v}
13
+ `}if(f){let c=t.nodes[f];s+=`CURRENT POSITION: ${c?r(c):f}
14
14
 
15
15
  `}else s+=`CURRENT POSITION: Not yet navigated into the structure.
16
16
 
@@ -18,4 +18,4 @@ import{a as se}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js"
18
18
 
19
19
  `,s+=`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
- `,s+='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.',s},j=document.createElement("div");j.className="dn-text-chat";let C=document.createElement("div");C.className="dn-text-chat-log",C.setAttribute("role","log"),C.setAttribute("aria-live","polite"),j.appendChild(C);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{C.setAttribute("aria-live",P.checked?"polite":"off")}),Y.appendChild(P),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),j.appendChild(W);let O=document.createElement("form");O.className="dn-text-chat-form";let H=document.createElement("label");H.setAttribute("for",`dn-text-chat-input-${G}`),H.className="dn-text-chat-sr-only",H.textContent="Navigation command";let N=document.createElement("input");N.type="text",N.id=`dn-text-chat-input-${G}`,N.autocomplete="off",N.setAttribute("placeholder","Type a command...");let J=document.createElement("button");J.type="submit",J.textContent="Send",O.appendChild(H),O.appendChild(N),O.appendChild(J),j.appendChild(O),l.appendChild(j);let V="";N.addEventListener("keydown",s=>{if(s.key==="ArrowUp"){if(s.preventDefault(),L.length===0)return;E===-1?(V=N.value,E=L.length-1):E>0&&E--,N.value=L[E]}else if(s.key==="ArrowDown"){if(s.preventDefault(),E===-1)return;E<L.length-1?(E++,N.value=L[E]):(E=-1,N.value=V)}});let K=(s,c)=>{let i=document.createElement("div");i.className=`dn-text-chat-message ${c}`,i.textContent=s,C.appendChild(i),C.scrollTop=C.scrollHeight},D=s=>K(s,"dn-text-chat-system"),ie=s=>K(`> ${s}`,"dn-text-chat-input-echo"),h=s=>K(s,"dn-text-chat-response"),ce=(s,c)=>{let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-response";let w=document.createElement("span");w.textContent=s,i.appendChild(w);let k=document.createElement("ol");k.className="dn-text-chat-choices",c.forEach(U=>{let $=document.createElement("li");$.textContent=U,k.appendChild($)}),i.appendChild(k),C.appendChild(i),C.scrollTop=C.scrollHeight},Q=s=>F(void 0,null,function*(){let c={role:"system",content:re()};S.push({role:"user",content:s});let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-llm-thinking",i.textContent="Thinking...",C.appendChild(i),C.scrollTop=C.scrollHeight;try{let w=yield p([c,...S]);return C.removeChild(i),w===null?(S.pop(),null):(S.push({role:"assistant",content:w}),h(w),w)}catch(w){return C.removeChild(i),S.pop(),h(`Error: ${w.message||"Could not get a response."}`),""}});p?(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"],Z=s=>{let c=T.moveTo(s);c?(v=c.id,n&&n(c),h(`Moved to: ${a(c)}`)):h("Could not move to that node.")},_=s=>F(void 0,null,function*(){let c=s.trim();if(!c)return;ie(c);let i=c.toLowerCase();if(A){let r=parseInt(c,10);if(!isNaN(r)&&r>=1&&r<=A.length){let y=A[r-1];A=null,Z(y.nodeId);return}A=null}if(i==="clear"){C.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(i==="enter"){if(v){h('Already in the structure. Type "help" to see available commands.');return}let r=T.enter();if(!r){h("Could not enter the structure. No entry point found.");return}v=r.id,n&&n(r),h(`Entered: ${a(r)}`);return}if(i==="help"){let r=p?" You can also type any question about the data.":"",y=[];b&&y.push('"click" or "select"'),m&&y.push('"hover" or "inspect"');let R=y.length?` Interaction: ${y.join(", ")}.`:"";if(!v)h('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+R+r);else{let de=e.nodes[v],ue=pe(v,de,e).map(he=>B(he,o));h(`Available: ${ue.join(", ")}, move to <search>.`+R+r)}return}if(i==="click"||i==="select"){if(!v){h('Not in the structure. Type "enter" to begin.');return}let r=e.nodes[v];b&&r?(b(r),h(`Clicked: ${a(r)}`)):h(b?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(i==="hover"||i==="inspect"){if(!v){h('Not in the structure. Type "enter" to begin.');return}let r=e.nodes[v];m&&r?(m(r),h(`Hovering over: ${a(r)}`)):h(m?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(i.startsWith("move to ")){let r=c.slice(8).trim();if(!r){h("Usage: move to <search term>");return}let y=ve(r,e,a);y.length===0?h(`No nodes found matching "${r}".`):y.length===1?Z(y[0].nodeId):(A=y,ce(`Found ${y.length} matches. Type a number to move there:`,y.map(R=>R.description)));return}if(i==="more"||i==="more help"){let y=ae(e).map(R=>B(R,o));h(`All navigation rules: ${y.join(", ")}.`);return}if(!v){if(p&&(yield Q(c))!==null)return;h('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(p?" Enter an API key above to ask questions about the data.":""));return}let w=ae(e),{match:k,ambiguous:U}=fe(i,[...w,...X],o);if(k&&X.includes(k)){yield _(k);return}if(!k&&U.length>0){let r=U.map(y=>B(y,o));h(`Did you mean: ${r.join(", ")}?`);return}if(!k){if(p&&(yield Q(c))!==null)return;let r=p?" Enter an API key above to ask questions about the data.":"";h(`Unknown command "${c}". Type "help" for available commands.`+r);return}let $=k,le=o[$]||$;if($==="exit"){v=null,f&&f(),h('Exited the structure. Type "enter" to re-enter.');return}let q=T.move(v,$);q?(v=q.id,n&&n(q),h(`${le}: ${a(q)}`)):h(`Cannot move "${$}" from here.`)});return O.addEventListener("submit",s=>F(void 0,null,function*(){s.preventDefault();let c=N.value.trim();c&&(L.push(c),E=-1),yield _(N.value),N.value="",N.focus()})),{destroy(){l.removeChild(j)},getCurrentNode(){return v&&e.nodes[v]||null}}};export{Ce as default};
21
+ `,s+='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.',s},j=document.createElement("div");j.className="dn-text-chat";let C=document.createElement("div");C.className="dn-text-chat-log",C.setAttribute("role","log"),C.setAttribute("aria-live","polite"),j.appendChild(C);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{C.setAttribute("aria-live",P.checked?"polite":"off")}),Y.appendChild(P),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),j.appendChild(W);let O=document.createElement("form");O.className="dn-text-chat-form";let H=document.createElement("label");H.setAttribute("for",`dn-text-chat-input-${V}`),H.className="dn-text-chat-sr-only",H.textContent="Navigation command";let N=document.createElement("input");N.type="text",N.id=`dn-text-chat-input-${V}`,N.autocomplete="off",N.setAttribute("placeholder","Type a command...");let J=document.createElement("button");J.type="submit",J.textContent="Send",O.appendChild(H),O.appendChild(N),O.appendChild(J),j.appendChild(O),l.appendChild(j);let Q="";N.addEventListener("keydown",s=>{if(s.key==="ArrowUp"){if(s.preventDefault(),I.length===0)return;E===-1?(Q=N.value,E=I.length-1):E>0&&E--,N.value=I[E]}else if(s.key==="ArrowDown"){if(s.preventDefault(),E===-1)return;E<I.length-1?(E++,N.value=I[E]):(E=-1,N.value=Q)}});let K=(s,c)=>{let i=document.createElement("div");i.className=`dn-text-chat-message ${c}`,i.textContent=s,C.appendChild(i),C.scrollTop=C.scrollHeight},D=s=>K(s,"dn-text-chat-system"),it=s=>K(`> ${s}`,"dn-text-chat-input-echo"),h=s=>K(s,"dn-text-chat-response"),ct=(s,c)=>{let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-response";let w=document.createElement("span");w.textContent=s,i.appendChild(w);let k=document.createElement("ol");k.className="dn-text-chat-choices",c.forEach(U=>{let $=document.createElement("li");$.textContent=U,k.appendChild($)}),i.appendChild(k),C.appendChild(i),C.scrollTop=C.scrollHeight},X=s=>F(void 0,null,function*(){let c={role:"system",content:at()};S.push({role:"user",content:s});let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-llm-thinking",i.textContent="Thinking...",C.appendChild(i),C.scrollTop=C.scrollHeight;try{let w=yield p([c,...S]);return C.removeChild(i),w===null?(S.pop(),null):(S.push({role:"assistant",content:w}),h(w),w)}catch(w){return C.removeChild(i),S.pop(),h(`Error: ${w.message||"Could not get a response."}`),""}});p?(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 Z=["enter","help","more","more help","clear","click","select","hover","inspect"],_=s=>{let c=T.moveTo(s);c?(f=c.id,n&&n(c),h(`Moved to: ${r(c)}`)):h("Could not move to that node.")},z=s=>F(void 0,null,function*(){let c=s.trim();if(!c)return;it(c);let i=c.toLowerCase();if(L){let a=parseInt(c,10);if(!isNaN(a)&&a>=1&&a<=L.length){let y=L[a-1];L=null,_(y.nodeId);return}L=null}if(i==="clear"){C.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(i==="enter"){if(f){h('Already in the structure. Type "help" to see available commands.');return}let a=T.enter();if(!a){h("Could not enter the structure. No entry point found.");return}f=a.id,n&&n(a),h(`Entered: ${r(a)}`);return}if(i==="help"){let a=p?" You can also type any question about the data.":"",y=[];b&&y.push('"click" or "select"'),m&&y.push('"hover" or "inspect"');let R=y.length?` Interaction: ${y.join(", ")}.`:"";if(!f)h('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+R+a);else{let dt=t.nodes[f],ut=pt(f,dt,t).map(ht=>G(ht,o));h(`Available: ${ut.join(", ")}, move to <search>.`+R+a)}return}if(i==="click"||i==="select"){if(!f){h('Not in the structure. Type "enter" to begin.');return}let a=t.nodes[f];b&&a?(b(a),h(`Clicked: ${r(a)}`)):h(b?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(i==="hover"||i==="inspect"){if(!f){h('Not in the structure. Type "enter" to begin.');return}let a=t.nodes[f];m&&a?(m(a),h(`Hovering over: ${r(a)}`)):h(m?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(i.startsWith("move to ")){let a=c.slice(8).trim();if(!a){h("Usage: move to <search term>");return}let y=vt(a,t,r);y.length===0?h(`No nodes found matching "${a}".`):y.length===1?_(y[0].nodeId):(L=y,ct(`Found ${y.length} matches. Type a number to move there:`,y.map(R=>R.description)));return}if(i==="more"||i==="more help"){let y=rt(t).map(R=>G(R,o));h(`All navigation rules: ${y.join(", ")}.`);return}if(!f){if(p&&(yield X(c))!==null)return;h('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(p?" Enter an API key above to ask questions about the data.":""));return}let w=rt(t),{match:k,ambiguous:U}=ft(i,[...w,...Z],o);if(k&&Z.includes(k)){yield z(k);return}if(!k&&U.length>0){let a=U.map(y=>G(y,o));h(`Did you mean: ${a.join(", ")}?`);return}if(!k){if(p&&(yield X(c))!==null)return;let a=p?" Enter an API key above to ask questions about the data.":"";h(`Unknown command "${c}". Type "help" for available commands.`+a);return}let $=k,lt=o[$]||$;if($==="exit"){f=null,v&&v(),h('Exited the structure. Type "enter" to re-enter.');return}let q=T.move(f,$);q?(f=q.id,n&&n(q),h(`${lt}: ${r(q)}`)):h(`Cannot move "${$}" from here.`)});return O.addEventListener("submit",s=>F(void 0,null,function*(){s.preventDefault();let c=N.value.trim();c&&(I.push(c),E=-1),yield z(N.value),N.value="",N.focus()})),{destroy(){l.removeChild(j)},getCurrentNode(){return f&&t.nodes[f]||null},submit(s){return z(s)},setCurrentNode(s){f=s&&t.nodes[s]?s:null,L=null}}};export{Ct as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "data-navigator",
3
3
  "author": "Frank Elavsky",
4
- "version": "3.2.1",
4
+ "version": "3.3.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",