data-navigator 3.2.0 → 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 +23 -14
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -14
- 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
|
@@ -1870,12 +1870,13 @@ var rendering_default = (options) => {
|
|
|
1870
1870
|
parentSemantics: __spreadValues({}, NodeElementDefaults.parentSemantics),
|
|
1871
1871
|
existingElement: __spreadValues({}, NodeElementDefaults.existingElement)
|
|
1872
1872
|
};
|
|
1873
|
+
const mergeDefault = (base, o) => typeof o === "function" ? o : __spreadValues(__spreadValues({}, base), o);
|
|
1873
1874
|
if (options.defaults) {
|
|
1874
1875
|
defaults.cssClass = options.defaults.cssClass || defaults.cssClass;
|
|
1875
|
-
defaults.spatialProperties = options.defaults.spatialProperties ?
|
|
1876
|
-
defaults.semantics = options.defaults.semantics ?
|
|
1877
|
-
defaults.parentSemantics = options.defaults.parentSemantics ?
|
|
1878
|
-
defaults.existingElement = options.defaults.existingElement ?
|
|
1876
|
+
defaults.spatialProperties = options.defaults.spatialProperties ? mergeDefault(defaults.spatialProperties, options.defaults.spatialProperties) : defaults.spatialProperties;
|
|
1877
|
+
defaults.semantics = options.defaults.semantics ? mergeDefault(defaults.semantics, options.defaults.semantics) : defaults.semantics;
|
|
1878
|
+
defaults.parentSemantics = options.defaults.parentSemantics ? mergeDefault(defaults.parentSemantics, options.defaults.parentSemantics) : defaults.parentSemantics;
|
|
1879
|
+
defaults.existingElement = options.defaults.existingElement ? mergeDefault(defaults.existingElement, options.defaults.existingElement) : defaults.existingElement;
|
|
1879
1880
|
}
|
|
1880
1881
|
renderer.initialize = () => {
|
|
1881
1882
|
var _a, _b;
|
|
@@ -1968,12 +1969,17 @@ var rendering_default = (options) => {
|
|
|
1968
1969
|
}
|
|
1969
1970
|
let useExisting = false;
|
|
1970
1971
|
let existingSpatialProperties = {};
|
|
1971
|
-
const
|
|
1972
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1973
|
+
const resolve = (v) => {
|
|
1972
1974
|
var _a;
|
|
1973
|
-
|
|
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);
|
|
1976
|
+
};
|
|
1977
|
+
const resolveProp = (prop, subprop, checkExisting) => {
|
|
1978
|
+
var _a, _b, _c, _d, _e;
|
|
1979
|
+
const p1 = resolve(d[prop] || defaults[prop]);
|
|
1974
1980
|
const s1 = !(checkExisting && useExisting) ? p1 == null ? void 0 : p1[subprop] : existingSpatialProperties[subprop];
|
|
1975
|
-
const s2 = (_a = defaults[prop]) == null ? void 0 : _a[subprop];
|
|
1976
|
-
return
|
|
1981
|
+
const s2 = (_c = (_a = resolve(defaults[prop])) == null ? void 0 : _a[subprop]) != null ? _c : (_b = NodeElementDefaults[prop]) == null ? void 0 : _b[subprop];
|
|
1982
|
+
return (_e = (_d = resolve(s1)) != null ? _d : resolve(s2)) != null ? _e : !subprop ? p1 : void 0;
|
|
1977
1983
|
};
|
|
1978
1984
|
useExisting = resolveProp("existingElement", "useForSpatialProperties");
|
|
1979
1985
|
existingSpatialProperties = resolveProp("existingElement", "spatialProperties");
|
|
@@ -1991,7 +1997,9 @@ var rendering_default = (options) => {
|
|
|
1991
1997
|
node.setAttribute("role", resolveProp("parentSemantics", "role"));
|
|
1992
1998
|
node.id = id;
|
|
1993
1999
|
node.classList.add("dn-node");
|
|
1994
|
-
|
|
2000
|
+
const cssClass = resolveProp("cssClass");
|
|
2001
|
+
if (cssClass)
|
|
2002
|
+
node.classList.add(cssClass);
|
|
1995
2003
|
node.style.width = width + "px";
|
|
1996
2004
|
node.style.height = height + "px";
|
|
1997
2005
|
node.style.left = x + "px";
|
|
@@ -2092,9 +2100,10 @@ var rendering_default = (options) => {
|
|
|
2092
2100
|
|
|
2093
2101
|
// src/text-chat.ts
|
|
2094
2102
|
var defaultDescribeNode = (node) => {
|
|
2095
|
-
var _a, _b, _c, _d
|
|
2096
|
-
|
|
2097
|
-
|
|
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;
|
|
2098
2107
|
if (label)
|
|
2099
2108
|
return label;
|
|
2100
2109
|
}
|
|
@@ -2104,7 +2113,7 @@ var defaultDescribeNode = (node) => {
|
|
|
2104
2113
|
}
|
|
2105
2114
|
return node.id;
|
|
2106
2115
|
}
|
|
2107
|
-
if ((
|
|
2116
|
+
if ((_a = node.data) == null ? void 0 : _a.dimensionKey) {
|
|
2108
2117
|
let count = 0;
|
|
2109
2118
|
const divisions = Object.keys(node.data.divisions || {});
|
|
2110
2119
|
divisions.forEach((div) => {
|
|
@@ -2115,7 +2124,7 @@ var defaultDescribeNode = (node) => {
|
|
|
2115
2124
|
label += ` ${node.data.type} dimension.`;
|
|
2116
2125
|
return label;
|
|
2117
2126
|
}
|
|
2118
|
-
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.`;
|
|
2119
2128
|
};
|
|
2120
2129
|
var getAvailableRules = (nodeId, node, structure) => {
|
|
2121
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
|
@@ -1836,12 +1836,13 @@ var rendering_default = (options) => {
|
|
|
1836
1836
|
parentSemantics: __spreadValues({}, NodeElementDefaults.parentSemantics),
|
|
1837
1837
|
existingElement: __spreadValues({}, NodeElementDefaults.existingElement)
|
|
1838
1838
|
};
|
|
1839
|
+
const mergeDefault = (base, o) => typeof o === "function" ? o : __spreadValues(__spreadValues({}, base), o);
|
|
1839
1840
|
if (options.defaults) {
|
|
1840
1841
|
defaults.cssClass = options.defaults.cssClass || defaults.cssClass;
|
|
1841
|
-
defaults.spatialProperties = options.defaults.spatialProperties ?
|
|
1842
|
-
defaults.semantics = options.defaults.semantics ?
|
|
1843
|
-
defaults.parentSemantics = options.defaults.parentSemantics ?
|
|
1844
|
-
defaults.existingElement = options.defaults.existingElement ?
|
|
1842
|
+
defaults.spatialProperties = options.defaults.spatialProperties ? mergeDefault(defaults.spatialProperties, options.defaults.spatialProperties) : defaults.spatialProperties;
|
|
1843
|
+
defaults.semantics = options.defaults.semantics ? mergeDefault(defaults.semantics, options.defaults.semantics) : defaults.semantics;
|
|
1844
|
+
defaults.parentSemantics = options.defaults.parentSemantics ? mergeDefault(defaults.parentSemantics, options.defaults.parentSemantics) : defaults.parentSemantics;
|
|
1845
|
+
defaults.existingElement = options.defaults.existingElement ? mergeDefault(defaults.existingElement, options.defaults.existingElement) : defaults.existingElement;
|
|
1845
1846
|
}
|
|
1846
1847
|
renderer.initialize = () => {
|
|
1847
1848
|
var _a, _b;
|
|
@@ -1934,12 +1935,17 @@ var rendering_default = (options) => {
|
|
|
1934
1935
|
}
|
|
1935
1936
|
let useExisting = false;
|
|
1936
1937
|
let existingSpatialProperties = {};
|
|
1937
|
-
const
|
|
1938
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1939
|
+
const resolve = (v) => {
|
|
1938
1940
|
var _a;
|
|
1939
|
-
|
|
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);
|
|
1942
|
+
};
|
|
1943
|
+
const resolveProp = (prop, subprop, checkExisting) => {
|
|
1944
|
+
var _a, _b, _c, _d, _e;
|
|
1945
|
+
const p1 = resolve(d[prop] || defaults[prop]);
|
|
1940
1946
|
const s1 = !(checkExisting && useExisting) ? p1 == null ? void 0 : p1[subprop] : existingSpatialProperties[subprop];
|
|
1941
|
-
const s2 = (_a = defaults[prop]) == null ? void 0 : _a[subprop];
|
|
1942
|
-
return
|
|
1947
|
+
const s2 = (_c = (_a = resolve(defaults[prop])) == null ? void 0 : _a[subprop]) != null ? _c : (_b = NodeElementDefaults[prop]) == null ? void 0 : _b[subprop];
|
|
1948
|
+
return (_e = (_d = resolve(s1)) != null ? _d : resolve(s2)) != null ? _e : !subprop ? p1 : void 0;
|
|
1943
1949
|
};
|
|
1944
1950
|
useExisting = resolveProp("existingElement", "useForSpatialProperties");
|
|
1945
1951
|
existingSpatialProperties = resolveProp("existingElement", "spatialProperties");
|
|
@@ -1957,7 +1963,9 @@ var rendering_default = (options) => {
|
|
|
1957
1963
|
node.setAttribute("role", resolveProp("parentSemantics", "role"));
|
|
1958
1964
|
node.id = id;
|
|
1959
1965
|
node.classList.add("dn-node");
|
|
1960
|
-
|
|
1966
|
+
const cssClass = resolveProp("cssClass");
|
|
1967
|
+
if (cssClass)
|
|
1968
|
+
node.classList.add(cssClass);
|
|
1961
1969
|
node.style.width = width + "px";
|
|
1962
1970
|
node.style.height = height + "px";
|
|
1963
1971
|
node.style.left = x + "px";
|
|
@@ -2058,9 +2066,10 @@ var rendering_default = (options) => {
|
|
|
2058
2066
|
|
|
2059
2067
|
// src/text-chat.ts
|
|
2060
2068
|
var defaultDescribeNode = (node) => {
|
|
2061
|
-
var _a, _b, _c, _d
|
|
2062
|
-
|
|
2063
|
-
|
|
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;
|
|
2064
2073
|
if (label)
|
|
2065
2074
|
return label;
|
|
2066
2075
|
}
|
|
@@ -2070,7 +2079,7 @@ var defaultDescribeNode = (node) => {
|
|
|
2070
2079
|
}
|
|
2071
2080
|
return node.id;
|
|
2072
2081
|
}
|
|
2073
|
-
if ((
|
|
2082
|
+
if ((_a = node.data) == null ? void 0 : _a.dimensionKey) {
|
|
2074
2083
|
let count = 0;
|
|
2075
2084
|
const divisions = Object.keys(node.data.divisions || {});
|
|
2076
2085
|
divisions.forEach((div) => {
|
|
@@ -2081,7 +2090,7 @@ var defaultDescribeNode = (node) => {
|
|
|
2081
2090
|
label += ` ${node.data.type} dimension.`;
|
|
2082
2091
|
return label;
|
|
2083
2092
|
}
|
|
2084
|
-
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.`;
|
|
2085
2094
|
};
|
|
2086
2095
|
var getAvailableRules = (nodeId, node, structure) => {
|
|
2087
2096
|
const available = /* @__PURE__ */ new Set();
|
package/dist/rendering.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var _=(e,r,n)=>r in e?T(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,p=(e,r)=>{for(var n in r||(r={}))W.call(r,n)&&_(e,n,r[n]);if(H)for(var n of H(r))X.call(r,n)&&_(e,n,r[n]);return e};var ee=(e,r)=>{for(var n in r)T(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of q(r))!W.call(e,l)&&l!==n&&T(e,l,{get:()=>r[l],enumerable:!(t=Y(r,l))||t.enumerable});return e};var re=e=>te(T({},"__esModule",{value:!0}),e);var z=(e,r,n)=>{if(!r.has(e))throw TypeError("Cannot "+n)};var f=(e,r,n)=>(z(e,r,"read from private field"),n?n.call(e):r.get(e)),B=(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)},N=(e,r,n,t)=>(z(e,r,"write to private field"),t?t.call(e,n):r.set(e,n),n);var R=(e,r,n)=>(z(e,r,"access private method"),n);var se={};ee(se,{default:()=>ie});module.exports=re(se);var P={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}},Z={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:"="},J={"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,k,v,y,x,D,j=class extends HTMLElement{constructor(){super(...arguments);B(this,x);B(this,S,[]);B(this,k,Q);B(this,v,"label");B(this,y,!1)}static get observedAttributes(){return["title"]}set commands(n){N(this,S,n),f(this,y)&&R(this,x,D).call(this)}get commands(){return f(this,S)}set columns(n){N(this,k,n),f(this,y)&&R(this,x,D).call(this)}get columns(){return f(this,k)}set kbdColumn(n){N(this,v,n),f(this,y)&&R(this,x,D).call(this)}get kbdColumn(){return f(this,v)}attributeChangedCallback(){f(this,y)&&R(this,x,D).call(this)}connectedCallback(){N(this,y,!0),R(this,x,D).call(this)}disconnectedCallback(){N(this,y,!1)}};S=new WeakMap,k=new WeakMap,v=new WeakMap,y=new WeakMap,x=new WeakSet,D=function(){this.replaceChildren();let n=[];for(let s of f(this,k)){let d=document.createElement("th");d.classList.add("dn-commands-table-th"),d.textContent=s.label,n.push(d)}let t=document.createElement("tr");t.classList.add("dn-commands-table-thead-tr");for(let s of n)t.appendChild(s);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 s of f(this,S)){let d=[];for(let i of f(this,k)){let A=s[i.id],w=document.createElement("td");if(w.classList.add("dn-commands-table-td"),f(this,v)!==null&&i.id===f(this,v)&&A){let E=document.createElement("kbd");E.classList.add("dn-commands-table-td-kbd"),E.textContent=A,w.append(E)}else w.textContent=A;d.push(w)}let m=document.createElement("tr");m.classList.add("dn-commands-table-tbody-tr");for(let i of d)m.appendChild(i);o.appendChild(m)}let a=document.createElement("table");a.classList.add("dn-commands-table");let c=this.getAttribute("title");if(c){let s=document.createElement("caption");s.classList.add("dn-commands-table-caption"),s.textContent=c,a.appendChild(s)}else a.setAttribute("aria-label","Commands table");a.appendChild(l),a.appendChild(o),this.appendChild(a)};var ne=e=>e?Z[e]||e.replace(/^Key/,"").replace(/^Digit/,""):"",ae=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=J[n];return{label:t!=null&&t.key?ne(t.key):(l==null?void 0:l.label)||"",description:(r==null?void 0:r[n])||(l==null?void 0:l.description)||ae(n),command:n}}):[]}var ie=e=>{let r=a=>{t.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},n=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},l=!1,o={cssClass:P.cssClass,spatialProperties:p({},P.spatialProperties),semantics:p({},P.semantics),parentSemantics:p({},P.parentSemantics),existingElement:p({},P.existingElement)};return e.defaults&&(o.cssClass=e.defaults.cssClass||o.cssClass,o.spatialProperties=e.defaults.spatialProperties?p(p({},o.spatialProperties),e.defaults.spatialProperties):o.spatialProperties,o.semantics=e.defaults.semantics?p(p({},o.semantics),e.defaults.semantics):o.semantics,o.parentSemantics=e.defaults.parentSemantics?p(p({},o.parentSemantics),e.defaults.parentSemantics):o.parentSemantics,o.existingElement=e.defaults.existingElement?p(p({},o.existingElement),e.defaults.existingElement):o.existingElement),t.initialize=()=>{var a,c;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),(c=e.exitElement)!=null&&c.include&&(t.exitElement=document.createElement("div"),t.exitElement.id="dn-exit-"+e.suffixId,t.exitElement.classList.add("dn-exit-position"),t.exitElement.innerText="End of data structure.",t.exitElement.setAttribute("aria-label","End of data structure."),t.exitElement.setAttribute("role","note"),t.exitElement.setAttribute("tabindex","-1"),t.exitElement.style.display="none",t.exitElement.addEventListener("focus",s=>{var d,m;t.exitElement.style.display="block",t.clearStructure(),(m=(d=e.exitElement)==null?void 0:d.callbacks)!=null&&m.focus&&e.exitElement.callbacks.focus(s)}),t.exitElement.addEventListener("blur",s=>{var d,m;t.exitElement.style.display="none",(m=(d=e.exitElement)==null?void 0:d.callbacks)!=null&&m.blur&&e.exitElement.callbacks.blur(s)}),t.root.appendChild(t.exitElement)),l=!0,t.root},t.render=a=>{let c=a.renderId+"",s=e.elementData[c];if(!s){console.warn(`Render data not found with renderId: ${c}. Failed to render.`);return}if(!l){console.error("render() was called before initialize(), renderer must be initialized first.");return}let d=!1,m={},i=(b,C,h)=>{var $;let g=s[b]||o[b],U=h&&d?m[C]:g==null?void 0:g[C],V=($=o[b])==null?void 0:$[C];return typeof g=="function"?g(s,a.datum):typeof U=="function"?U(s,a.datum):U||V||(C?void 0:g)};d=i("existingElement","useForSpatialProperties"),m=i("existingElement","spatialProperties");let A=parseFloat(i("spatialProperties","width",!0)||0),w=parseFloat(i("spatialProperties","height",!0)||0),E=parseFloat(i("spatialProperties","x",!0)||0),K=parseFloat(i("spatialProperties","y",!0)||0),u=document.createElement(i("parentSemantics","elementType")),I=i("parentSemantics","attributes");typeof I=="object"&&Object.keys(I).forEach(b=>{u.setAttribute(b,I[b])}),u.setAttribute("role",i("parentSemantics","role")),u.id=c,u.classList.add("dn-node"),u.classList.add(i("cssClass")),u.style.width=A+"px",u.style.height=w+"px",u.style.left=E+"px",u.style.top=K+"px",u.setAttribute("tabindex","0"),u.addEventListener("focus",r),u.addEventListener("blur",n);let L=document.createElement(i("semantics","elementType")),F=i("semantics","attributes");typeof F=="object"&&Object.keys(F).forEach(b=>{L.setAttribute(b,F[b])}),L.setAttribute("role",i("semantics","role")),L.classList.add("dn-node-text");let O=i("semantics","label");s.showText&&(L.innerText=O),O||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),L.setAttribute("aria-label",O),u.appendChild(L);let M=i("spatialProperties","path");if(M){let b=A+E+10,C=w+K+10,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("width",b+""),h.setAttribute("height",C+""),h.setAttribute("viewBox",`0 0 ${b} ${C}`),h.style.left=-E+"px",h.style.top=-K+"px",h.classList.add("dn-node-svg"),h.setAttribute("role","presentation"),h.setAttribute("focusable","false");let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.setAttribute("d",M),g.classList.add("dn-node-path"),h.appendChild(g),u.appendChild(h)}return t.wrapper.appendChild(u),u},t.remove=a=>{let c=document.getElementById(a);t.wrapper.getAttribute("aria-activedescendant")===a&&t.wrapper.setAttribute("aria-activedescendant",""),c&&(c.removeEventListener("focus",r),c.removeEventListener("blur",n),c.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(a=>{t.entryButton&&t.entryButton===a||t.remove(a.id)})},t.initializeCommands=a=>{let c=document.getElementById(a==null?void 0:a.rootId);if(!c){console.error("Commands root element not found in document.");return}let s=a.commands,d=G(a.navigationRules,a.descriptions),m=s?typeof s=="function"?s(d):s:d;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let i=document.createElement("dn-commands-table");return a!=null&&a.title&&i.setAttribute("title",a.title),i.commands=m,a.columns&&(i.columns=a.columns),c.appendChild(i),i},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};
|