data-navigator 3.2.1 → 3.2.2
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 +14 -10
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -10
- package/dist/rendering.cjs +1 -1
- package/dist/rendering.js +1 -1
- package/dist/text-chat.cjs +1 -1
- package/dist/text-chat.js +3 -3
- package/package.json +1 -1
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 ?
|
|
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
|
|
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)
|
|
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
|
-
|
|
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
|
|
2101
|
-
|
|
2102
|
-
|
|
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 ((
|
|
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}: ${(
|
|
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();
|
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 = {
|
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 = {
|
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 ?
|
|
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
|
|
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)
|
|
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
|
-
|
|
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
|
|
2067
|
-
|
|
2068
|
-
|
|
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 ((
|
|
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}: ${(
|
|
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();
|
package/dist/rendering.cjs
CHANGED
|
@@ -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
|
|
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};
|
package/dist/text-chat.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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 i,s,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}: ${(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.
|
|
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
4
|
`);l+=`DATASET SUMMARY:
|
package/dist/text-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as st}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js";var mt=e=>{var d,u,a,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,f=Object.keys(e.data.divisions||{});f.forEach(m=>{n+=Object.keys(e.data.divisions[m].values||{}).length});let b=`${e.derivedNode}.`;return b+=f.length&&n?` ${f.length} division${f.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(((a=e.data)==null?void 0:a.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,a=d.navigationRules||{};return t.edges&&t.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(t,e):m;p&&p!==e&&u.add(f)})}),Array.from(u)},at=e=>e.navigationRules?Object.keys(e.navigationRules):[],z=(e,t)=>{let d=e.length,u=t.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=e[o-1]===t[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&&e[o-1]===t[n-2]&&e[o-2]===t[n-1]&&(a[o][n]=Math.min(a[o][n],a[o-2][n-2]+f))}return a[d][u]},gt=e=>e<=4?1:2,ft=(e,t,d={})=>{let u=e.toLowerCase().trim(),a=t.find(l=>l.toLowerCase()===u);if(a)return{match:a,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 f=t.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=gt(u.length),g=[];for(let l=0;l<t.length;l++){let x=t[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=(e,t)=>t[e]?`${t[e]} (${e})`:e,vt=(e,t,d,u=10)=>{let a=e.toLowerCase(),o=[],n=Object.keys(t.nodes);for(let f=0;f<n.length&&o.length<u;f++){let b=n[f],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(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},Ct=e=>{var tt,et,nt,ot;let{structure:t,container:d,entryPoint:u,describeNode:a=mt,commandLabels:o={},onNavigate:n,onExit:f,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),I=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)||I||Object.keys(t.nodes)[0],T=st({structure:t,navigationRules:t.navigationRules||{},entryPoint:M}),v=null,G=Math.random().toString(36).slice(2,8),L=[],E=-1,A=null,S=[],rt=()=>{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=
|
|
13
|
+
`}if(v){let c=t.nodes[v];s+=`CURRENT POSITION: ${c?a(c):v}
|
|
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"),
|
|
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"),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},Q=s=>F(void 0,null,function*(){let c={role:"system",content:rt()};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;it(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 dt=t.nodes[v],ut=pt(v,dt,t).map(ht=>B(ht,o));h(`Available: ${ut.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=t.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=t.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=vt(r,t,a);y.length===0?h(`No nodes found matching "${r}".`):y.length===1?Z(y[0].nodeId):(A=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=at(t).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=at(t),{match:k,ambiguous:U}=ft(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,lt=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(`${lt}: ${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&&t.nodes[v]||null}}};export{Ct as default};
|