data-navigator 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/structure.js CHANGED
@@ -1 +1 @@
1
- import{a as ne,b as A}from"./chunk-YE5N6UCT.js";import{a as Q,c as X,e as Z,f as M,g as ee,i as ie}from"./chunk-MPFBSVCV.js";import{a as w,b as z}from"./chunk-RGY6OTGO.js";var he=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?de(e):fe(e),de=e=>{let h=ie,o={},g={},m={},d=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,b=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,r=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,p=e.vegaLiteView._renderer._origin,i=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],K=(n,t)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let c=`dn-node-${t}-${d}`;return d++,n["data-navigator-id"]=c,c},R=n=>{let t=o[n],c=t.index,u=t.level,v=t.parent,a=[],f=v.items[c-1];if(f){let l=K(f,u);if(o[l]){let O=`${l}-${t.id}`;a.push(O),g[O]||(g[O]={source:l,target:t.id,navigationRules:["left","right"]})}}let x=v.items[c+1];if(x){let l=K(x,u);if(o[l]){let O=`${t.id}-${l}`;a.push(O),g[O]||(g[O]={source:t.id,target:l,navigationRules:["left","right"]})}}if(u==="group"&&v.items[c].items){let O=(v.items[c].items[0].mark.items[0].items||v.items[c].items)[0],_=K(O,"item");if(o[_]){let s=`${t.id}-${_}`;a.push(s),g[s]||(g[s]={source:t.id,target:_,navigationRules:["parent","child"]})}}else if(u==="item"){let l=K(v,"group");if(o[l]){let O=`${l}-${t.id}`;a.push(O),g[O]||(g[O]={source:l,target:t.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(a.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),a.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),a},I=(n,t,c,u,v)=>{let a=K(n,t),f="render-"+a,x=c||[0,0];o[a]={},o[a].d={},o[a].id=a,o[a].renderId=f,o[a].index=u,o[a].level=t,o[a].parent=v,m[f]={},m[f].renderId=f,m[f].spatialProperties={},m[f].spatialProperties.x=n.bounds.x1+x[0],m[f].spatialProperties.y=n.bounds.y1+x[1],m[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,m[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,m[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(l=>{let O=n.datum[l];r(l,O,n.datum,t,e.vegaLiteSpec)&&(o[a].d[e.keyRenamingHash&&e.keyRenamingHash[l]?e.keyRenamingHash[l]:l]=O)}),m[f].semantics={},m[f].semantics.label=e.nodeDescriber?e.nodeDescriber(o[a].d,n,t):ne(o[a].d)},D=0;return i.items.forEach(n=>{if(P(n,D,e.vegaLiteSpec)){I(n,"group",p,D,i);let t=0,c=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;c.items.forEach(u=>{b(u,t,n,e.vegaLiteSpec)&&I(u,"item",p,t,c),t++})}D++}),Object.keys(o).forEach(n=>{o[n].edges=R(n)}),{nodes:o,edges:g,elementData:m,navigationRules:h}},ae=e=>{let h=0,o={};e.data.forEach(g=>{let m=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[m]="_"+h,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in g&&(typeof g[d]=="string"?(o[d]||(o[d]=0),o[g[d]]||(o[g[d]]=0),g[m]+="_"+d+o[d]+"_"+g[d]+o[g[d]],o[d]++,o[g[d]]++):(o[d]||(o[d]=0),g[m]+="_"+d+o[d],o[d]++))}),h++})},le=e=>{let h={};return e.data.forEach(o=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let g=typeof e.idKey=="function"?e.idKey(o):e.idKey,m=o[g];if(!m){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${g}, this datum has no id: ${JSON.stringify(o)}.`);return}if(h[m]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${m}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(o):e.renderIdKey;h[m]={id:m,edges:[],renderId:d?o[d]||"":o.renderIdKey||"",data:o}}}),h},ue=(e,h)=>{var d,P;let o={};if((P=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&P.addLevel0){let b=e.dimensions.parentOptions.addLevel0;h[b.id]=z(w({},b),{dimensionLevel:0})}let g=[...ee],m=(b,r)=>{let p=r.numericalExtents[0],i=r.numericalExtents[1];r.numericalExtents[0]=p<b?p:b,r.numericalExtents[1]=i>b?i:b};return e.data.forEach(b=>{let r=e.dimensions.values||[],p=0;r.forEach(i=>{var K,R,I,D,y,n,t,c;if(!i.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(i)}.`);return}if(i.dimensionKey in b){let u=b[i.dimensionKey],v=typeof((K=i.operations)==null?void 0:K.filterFunction)=="function"?i.operations.filterFunction(b,i):!0;if(u!==void 0&&v){if(i.type||(i.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!o[i.dimensionKey]){let l=typeof i.nodeId=="function"?i.nodeId(i,e.data):i.nodeId||A(i.dimensionKey),O=typeof i.renderId=="function"?i.renderId(i,e.data):i.renderId||l;o[i.dimensionKey]={dimensionKey:i.dimensionKey,nodeId:l,divisions:{},numericalExtents:[1/0,-1/0],type:i.type,operations:{compressSparseDivisions:((R=i.operations)==null?void 0:R.compressSparseDivisions)||!1,sortFunction:((I=i.operations)==null?void 0:I.sortFunction)||void 0},behavior:i.behavior||{extents:"circular"},navigationRules:i.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+i.dimensionKey,"next_"+i.dimensionKey],parent_child:["parent_"+i.dimensionKey,"child"]}},h[l]={id:l,renderId:O,derivedNode:i.dimensionKey,edges:[],dimensionLevel:1,data:o[i.dimensionKey],renderingStrategy:i.renderingStrategy||"singleSquare"}}let a=o[i.dimensionKey],f=null;if(i.type==="categorical"){let l=typeof((D=i.divisionOptions)==null?void 0:D.divisionNodeIds)=="function"?i.divisionOptions.divisionNodeIds(i.dimensionKey,u,p):A(a.nodeId+"_"+u);if(f=a.divisions[l],!f){f=a.divisions[l]={id:l,sortFunction:((y=i.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}};let O=typeof((n=i.divisionOptions)==null?void 0:n.divisionRenderIds)=="function"?i.divisionOptions.divisionRenderIds(i.dimensionKey,u,p):l;h[l]={id:l,renderId:O,derivedNode:i.dimensionKey,edges:[],dimensionLevel:2,data:w({},f),renderingStrategy:((t=i.divisionOptions)==null?void 0:t.renderingStrategy)||"singleSquare"},h[l].data[i.dimensionKey]=u}}else{f=a.divisions[a.nodeId],f||(f=a.divisions[a.nodeId]={id:a.nodeId,sortFunction:((c=i.divisionOptions)==null?void 0:c.sortFunction)||void 0,values:{}}),i.operations||(i.operations={});let l=i.operations.createNumericalSubdivisions;a.subdivisions=typeof l=="number"&&l<1?1:l||1,l!==1&&(a.divisionOptions||(a.divisionOptions=i.divisionOptions),m(u,a))}let x=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[x]]=b}}p++})}),Object.keys(o).forEach(b=>{var K,R,I,D,y;let r=o[b],p=r.divisions;if(r.type==="numerical"){p[r.nodeId].values=Object.fromEntries(Object.entries(p[r.nodeId].values).sort((t,c)=>{var u;return typeof((u=r.operations)==null?void 0:u.sortFunction)=="function"?r.operations.sortFunction(t[1],c[1],r):t[1][b]-c[1][b]}));let n=p[r.nodeId].values;if(r.numericalExtents[0]!==1/0&&r.subdivisions!==1){let t=Object.keys(n),c=typeof r.subdivisions=="function"?r.subdivisions(b,n):r.subdivisions,v=(r.numericalExtents[1]-r.numericalExtents[0])/c,a=r.numericalExtents[0]+v,f=0,x=0;for(a=r.numericalExtents[0]+v;a<=r.numericalExtents[1];a+=v){let l=typeof((K=r.divisionOptions)==null?void 0:K.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(b,a,a):r.nodeId+"_"+a;r.divisions[l]={id:l,sortFunction:((R=r.divisionOptions)==null?void 0:R.sortFunction)||void 0,values:{}};let O=typeof((I=r.divisionOptions)==null?void 0:I.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(b,a,a):l;h[l]={id:l,renderId:O,derivedNode:b,edges:[],data:r.divisions[l],dimensionLevel:2,renderingStrategy:((D=r.divisionOptions)==null?void 0:D.renderingStrategy)||"singleSquare"};let _=!1;for(;!_&&x<t.length;){let s=n[t[x]];s[b]<=a?r.divisions[l].values[s.id]=s:(a+=v,_=!0),x++}f++}delete p[b]}}else typeof((y=r.operations)==null?void 0:y.sortFunction)=="function"&&(r.divisions=Object.fromEntries(Object.entries(p).sort((n,t)=>r.operations.sortFunction(n[1],t[1],r))));Object.keys(r.divisions).forEach(n=>{let t=r.divisions[n];typeof t.sortFunction=="function"&&(t.values=Object.fromEntries(Object.entries(t.values).sort((c,u)=>t.sortFunction(c[1],u[1],t))))})}),Object.keys(o).forEach(b=>{let r=o[b];if(r.operations.compressSparseDivisions){let p=Object.keys(r.divisions),i={},K=!0;if(p.forEach(R=>{let I=r.divisions[R],D=Object.keys(I.values);D.length<=1?D.forEach(y=>{i[y]=w({},I.values[y])}):K=!1}),K){let R={id:r.nodeId,values:i};p.forEach(I=>{delete h[I]}),r.divisions={},r.divisions[r.nodeId]=R}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},ce=(e,h,o)=>{var P,b,r,p,i,K,R,I,D,y;let g={},m=(n,t)=>{h[n].edges.indexOf(t)===-1&&h[n].edges.push(t)},d=(n,t,c,u)=>{let v=`${n}-${t}`,a=e.useDirectedEdges?`${t}-${v}`:v,f=!u||u==="source",x=!u||u==="target",l=O=>{g[O]?g[O].navigationRules.push(...c||[]):g[O]={source:n,target:t,navigationRules:c?[...c]:[]}};l(v),e.useDirectedEdges&&x&&l(a),f&&m(n,v),x&&m(t,a)};if(o&&Object.keys(o).length){let n=Object.keys(o),t=(r=(b=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:b.level1Options)==null?void 0:r.order,c=t||n,u=0,v=((p=e.dimensions)==null?void 0:p.parentOptions)||{},a=((K=(i=v.level1Options)==null?void 0:i.behavior)==null?void 0:K.extents)||"terminal",f=v.addLevel0,x=f?((I=(R=v.level1Options)==null?void 0:R.navigationRules)==null?void 0:I.parent_child)||["parent","child"]:[],l=((y=(D=v.level1Options)==null?void 0:D.navigationRules)==null?void 0:y.sibling_sibling)||["left","right"],O=typeof c[0]=="string"?t?h[c[0]]:h[o[c[0]].nodeId]:c[0];f&&d(f.id,O.id,x,"source"),c.forEach(_=>{let s=typeof _=="string"?t?h[_]:h[o[_].nodeId]:_;if(s===_&&!h[s.id]&&(h[s.id]=s),f&&(e.useDirectedEdges?d(s.id,f.id,x,"source"):d(f.id,s.id,x,"target")),u===c.length-1&&a==="circular")d(s.id,O.id,l);else if(u===c.length-1&&a==="bridgedCustom")d(s.id,v.level1Options.behavior.customBridgePost,l);else if(u<c.length-1){let T=typeof c[u+1]=="string"?t?h[c[u+1]]:h[o[c[u+1]].nodeId]:c[u+1];d(s.id,T.id,l)}!u&&a==="bridgedCustom"&&d(v.level1Options.behavior.customBridgePost,s.id,l),u++}),n.forEach(_=>{var H,J,U,W;let s=o[_],T=((H=s.behavior)==null?void 0:H.childmostNavigation)||"within",te=(B,N,E,V)=>V.values[Object.keys(V.values)[B]]||void 0,se=T==="across"&&((J=s.behavior)!=null&&J.childmostMatching)?(U=s.behavior)==null?void 0:U.childmostMatching:te,$=((W=s.behavior)==null?void 0:W.extents)||"circular";s.divisions||console.error(`Parsing dimensions. The dimension using the key ${_} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(s)}.`);let j=Object.keys(s.divisions),G=s.divisions[j[0]];if(j.length!==1)d(s.nodeId,G.id,s.navigationRules.parent_child,"source");else{let B=Object.keys(G.values),N=typeof e.idKey=="function"?e.idKey(G.values[B[0]]):e.idKey;d(s.nodeId,G.values[B[0]][N],s.navigationRules.parent_child,"source")}let C=0;j.forEach(B=>{let N=s.divisions[B];C===j.length-1&&($==="circular"||$==="bridgedCousins"||$==="bridgedCustom")?d(N.id,s.divisions[j[0]].id,s.navigationRules.sibling_sibling):C<j.length-1&&d(N.id,s.divisions[j[C+1]].id,s.navigationRules.sibling_sibling);let E=Object.keys(N.values);e.useDirectedEdges?d(N.id,s.nodeId,s.navigationRules.parent_child,"source"):d(s.nodeId,N.id,s.navigationRules.parent_child,"target");let V=typeof e.idKey=="function"?e.idKey(N.values[E[0]]):e.idKey;d(N.id,N.values[E[0]][V],s.navigationRules.parent_child,"source");let k=0;E.length>=1&&E.forEach(oe=>{let S=N.values[oe],F=typeof e.idKey=="function"?e.idKey(S):e.idKey,Y=j.length!==1?N.id:s.nodeId;if(e.useDirectedEdges?d(S[F],Y,s.navigationRules.parent_child,"source"):d(Y,S[F],s.navigationRules.parent_child,"target"),T==="within"){if(k===E.length-1&&$==="circular"){let L=typeof e.idKey=="function"?e.idKey(N.values[E[0]]):e.idKey;d(S[F],N.values[E[0]][L],s.navigationRules.sibling_sibling)}else if(k===E.length-1&&$==="bridgedCousins")if(C!==j.length-1){let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[C+1]].values[E[0]]):e.idKey;d(S[F],s.divisions[j[C+1]].values[E[0]][L],s.navigationRules.sibling_sibling)}else{let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[0]].values[E[0]]):e.idKey;d(S[F],s.divisions[j[0]].values[E[0]][L],s.navigationRules.sibling_sibling)}else if(k===E.length-1&&$==="bridgedCustom")d(S[F],s.behavior.customBridgePost,s.navigationRules.sibling_sibling);else if(k<E.length-1){let L=typeof e.idKey=="function"?e.idKey(N.values[E[k+1]]):e.idKey;d(S[F],N.values[E[k+1]][L],s.navigationRules.sibling_sibling)}if(!k&&$==="bridgedCousins")if(C!==0){let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[C-1]].values[E[E.length-1]]):e.idKey;d(s.divisions[j[C-1]].values[E[E.length-1]][L],S[F],s.navigationRules.sibling_sibling)}else{let L=typeof e.idKey=="function"?e.idKey(s.divisions[j[j.length-1]].values[E[E.length-1]]):e.idKey;d(s.divisions[j[j.length-1]].values[E[E.length-1]][L],S[F],s.navigationRules.sibling_sibling)}else!k&&$==="bridgedCustom"&&d(s.behavior.customBridgePrevious,S[F],s.navigationRules.sibling_sibling)}else if(C===j.length-1&&$==="bridgedCustom")d(S[F],s.behavior.customBridgePost,s.navigationRules.sibling_sibling);else if(!C&&$==="bridgedCustom")d(s.behavior.customBridgePrevious,S[F],s.navigationRules.sibling_sibling);else{let L=C===j.length-1&&$==="circular"?s.divisions[j[0]]:s.divisions[j[C+1]];if(L){let q=se(k,S[F],N,L);if(q){let re=typeof e.idKey=="function"?e.idKey(q):e.idKey;d(S[F],q[re],s.navigationRules.sibling_sibling)}}}k++}),C++})})}return Object.keys(h).forEach(n=>{var c;let t=h[n];(c=e.genericEdges)!=null&&c.length&&e.genericEdges.forEach(u=>{g[u.edgeId]||(g[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(t,u))&&t.edges.push(u.edgeId)})}),g},ge=(e,h,o)=>{var m,d,P,b;let g=e.navigationRules;if(!g){let r=Object.keys(o||{});r.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${r.length}. Dimensions counted: ${r.join(", ")}.`);let p={},i={},K={},R=[...Z],I=[...X],D=(y,n)=>{let t=y&&n,c=!1,u=!1;if((p[y]||i[y])&&(i[y]=w({},p[y]),c=!0),n&&(p[n]||i[n])&&(i[n]=w({},p[n]),u=!0),t&&!c&&!u){R.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let v=[...R.shift()];I.splice(I.indexOf(v[0]),1),I.splice(I.indexOf(v[1]),1),i[y]={direction:e.useDirectedEdges?"target":"source",key:v[0]},i[n]={direction:"target",key:v[1]}}else{if(!i[y]&&I.length){let v=I.shift(),a=[];R.forEach(f=>{v!==f[0]&&v!==f[1]&&a.push(f)}),R=a,i[y]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!i[n]&&I.length){let v=I.shift(),a=[];R.forEach(f=>{v!==f[0]&&v!==f[1]&&a.push(f)}),R=a,i[n]={direction:"target",key:v}}I.length||(i[y]||(K[y]=y),n&&!i[n]&&(K[n]=n))}};if(Object.keys(M).forEach(y=>{let n=w({},M[y]);e.useDirectedEdges&&(n.direction="target"),p[y]=n}),r.length){if((d=(m=e.dimensions)==null?void 0:m.parentOptions)!=null&&d.addLevel0){let y=((b=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:b.parent_child)||["parent","child"];D(y[0],y[1])}r.forEach(y=>{let n=o[y].navigationRules.parent_child,t=o[y].navigationRules.sibling_sibling;D(n[0],n[1]),D(t[0],t[1])})}if(Object.keys(h).forEach(y=>{h[y].navigationRules.forEach(n=>{i[n]||D(n)})}),Object.keys(K).length){let y={};Object.keys(i).forEach(t=>{y[i[t].key]=i[t].key}),Object.keys(p).forEach(t=>{!y[p[t].key]&&!Q[p[t].key]&&I.push(p[t].key)});let n=w({},K);K={},Object.keys(n).forEach(t=>{D(t)}),Object.keys(K).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(K).join(", ")}.`)}g=i}return g},fe=e=>{e.addIds&&ae(e);let h=le(e),o=ue(e,h),g=ce(e,h,o),m=ge(e,g,o);return{nodes:h,edges:g,dimensions:o,navigationRules:m}};export{ae as addSimpleDataIDs,ce as buildEdges,de as buildNodeStructureFromVegaLite,le as buildNodes,ge as buildRules,fe as buildStructure,he as default,ue as scaffoldDimensions};
1
+ import{a as se,b as M}from"./chunk-YE5N6UCT.js";import{a as Z,c as ee,e as ie,f as J,g as ne,i as te}from"./chunk-MPFBSVCV.js";import{a as k,b as X}from"./chunk-RGY6OTGO.js";var ye=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?de(e):ge(e),de=e=>{let m=te,t={},g={},O={},r=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,w=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,y=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,d)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let a=`dn-node-${d}-${r}`;return r++,n["data-navigator-id"]=a,a},o=n=>{let d=t[n],a=d.index,l=d.level,v=d.parent,u=[],c=v.items[a-1];if(c){let f=E(c,l);if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.id,navigationRules:["left","right"]})}}let K=v.items[a+1];if(K){let f=E(K,l);if(t[f]){let I=`${d.id}-${f}`;u.push(I),g[I]||(g[I]={source:d.id,target:f,navigationRules:["left","right"]})}}if(l==="group"&&v.items[a].items){let I=(v.items[a].items[0].mark.items[0].items||v.items[a].items)[0],p=E(I,"item");if(t[p]){let i=`${d.id}-${p}`;u.push(i),g[i]||(g[i]={source:d.id,target:p,navigationRules:["parent","child"]})}}else if(l==="item"){let f=E(v,"group");if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(u.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},j=(n,d,a,l,v)=>{let u=E(n,d),c="render-"+u,K=a||[0,0];t[u]={},t[u].d={},t[u].id=u,t[u].renderId=c,t[u].index=l,t[u].level=d,t[u].parent=v,O[c]={},O[c].renderId=c,O[c].spatialProperties={},O[c].spatialProperties.x=n.bounds.x1+K[0],O[c].spatialProperties.y=n.bounds.y1+K[1],O[c].spatialProperties.width=n.bounds.x2-n.bounds.x1,O[c].spatialProperties.height=n.bounds.y2-n.bounds.y1,O[c].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(f=>{let I=n.datum[f];b(f,I,n.datum,d,e.vegaLiteSpec)&&(t[u].d[e.keyRenamingHash&&e.keyRenamingHash[f]?e.keyRenamingHash[f]:f]=I)}),O[c].semantics={},O[c].semantics.label=e.nodeDescriber?e.nodeDescriber(t[u].d,n,d):se(t[u].d)},x=0;return y.items.forEach(n=>{if(P(n,x,e.vegaLiteSpec)){j(n,"group",s,x,y);let d=0,a=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;a.items.forEach(l=>{w(l,d,n,e.vegaLiteSpec)&&j(l,"item",s,d,a),d++})}x++}),Object.keys(t).forEach(n=>{t[n].edges=o(n)}),{nodes:t,edges:g,elementData:O,navigationRules:m}},re=e=>{let m=0,t={};e.data.forEach(g=>{let O=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[O]="_"+m,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(r=>{r in g&&(typeof g[r]=="string"?(t[r]||(t[r]=0),t[g[r]]||(t[g[r]]=0),g[O]+="_"+r+t[r]+"_"+g[r]+t[g[r]],t[r]++,t[g[r]]++):(t[r]||(t[r]=0),g[O]+="_"+r+t[r],t[r]++))}),m++})},ae=e=>{let m={};return e.data.forEach(t=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let g=typeof e.idKey=="function"?e.idKey(t):e.idKey,O=t[g];if(!O){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${g}, this datum has no id: ${JSON.stringify(t)}.`);return}if(m[O]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${O}.`);return}else{let r=typeof e.renderIdKey=="function"?e.renderIdKey(t):e.renderIdKey;m[O]={id:O,edges:[],renderId:r?t[r]||"":t.renderIdKey||"",data:t}}}),m},le=(e,m)=>{var r,P,w;let t={};if((P=(r=e.dimensions)==null?void 0:r.parentOptions)!=null&&P.addLevel0){let b=e.dimensions.parentOptions.addLevel0;m[b.id]=X(k({},b),{dimensionLevel:0})}let g=[...ne],O=(b,s)=>{let y=s.numericalExtents[0],E=s.numericalExtents[1];s.numericalExtents[0]=y<b?y:b,s.numericalExtents[1]=E>b?E:b};return e.data.forEach(b=>{var E;let s=((E=e.dimensions)==null?void 0:E.values)||[],y=0;s.forEach(o=>{var j,x,h,n,d,a,l,v;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in b){let u=b[o.dimensionKey],c=typeof((j=o.operations)==null?void 0:j.filterFunction)=="function"?o.operations.filterFunction(b,o):!0;if(u!==void 0&&c){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!t[o.dimensionKey]){let p=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||M(o.dimensionKey),i=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||p;t[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((x=o.operations)==null?void 0:x.compressSparseDivisions)||!1,sortFunction:((h=o.operations)==null?void 0:h.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["parent_"+o.dimensionKey,"child"]}},m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:t[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let K=t[o.dimensionKey],f=null;if(o.type==="categorical"){let p=typeof((n=o.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,y):M(K.nodeId+"_"+u);if(f=K.divisions[p],!f){f=K.divisions[p]={id:p,sortFunction:((d=o.divisionOptions)==null?void 0:d.sortFunction)||void 0,values:{}};let i=typeof((a=o.divisionOptions)==null?void 0:a.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,y):p;m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:k({},f),renderingStrategy:((l=o.divisionOptions)==null?void 0:l.renderingStrategy)||"singleSquare"},m[p].data[o.dimensionKey]=u}}else{f=K.divisions[K.nodeId],f||(f=K.divisions[K.nodeId]={id:K.nodeId,sortFunction:((v=o.divisionOptions)==null?void 0:v.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let p=o.operations.createNumericalSubdivisions;K.subdivisions=typeof p=="number"&&p<1?1:p||1,p!==1&&(K.divisionOptions||(K.divisionOptions=o.divisionOptions),O(u,K))}let I=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[I]]=b}}y++})}),Object.keys(t).forEach(b=>{var o,j,x,h,n;let s=t[b],y=s.divisions;if(s.type==="numerical"){y[s.nodeId].values=Object.fromEntries(Object.entries(y[s.nodeId].values).sort((a,l)=>{var v;return typeof((v=s.operations)==null?void 0:v.sortFunction)=="function"?s.operations.sortFunction(a[1],l[1],s):a[1][b]-l[1][b]}));let d=y[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let a=Object.keys(d),l=typeof s.subdivisions=="function"?s.subdivisions(b,d):s.subdivisions,u=(s.numericalExtents[1]-s.numericalExtents[0])/l,c=s.numericalExtents[0]+u,K=0,f=0,I=null,p=s.numericalExtents[0];for(c=s.numericalExtents[0]+u;c<=s.numericalExtents[1];c+=u){let i=typeof((o=s.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(b,c,c):M(s.nodeId+"_"+c);I=i,s.divisions[i]={id:i,sortFunction:((j=s.divisionOptions)==null?void 0:j.sortFunction)||void 0,values:{},numericalExtents:[p,c]};let B=typeof((x=s.divisionOptions)==null?void 0:x.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(b,c,c):i;m[i]={id:i,renderId:B,derivedNode:b,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:((h=s.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"};let V=!1;for(;!V&&f<a.length;){let G=d[a[f]];G[b]<=c?(s.divisions[i].values[G.id]=G,f++):V=!0}p=c,K++}if(I&&f<a.length)for(;f<a.length;){let i=d[a[f]];s.divisions[I].values[i.id]=i,f++}delete y[b]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(y).sort((d,a)=>s.operations.sortFunction(d[1],a[1],s))));Object.keys(s.divisions).forEach(d=>{let a=s.divisions[d];typeof a.sortFunction=="function"&&(a.values=Object.fromEntries(Object.entries(a.values).sort((l,v)=>a.sortFunction(l[1],v[1],a))))})}),Object.keys(t).forEach(b=>{let s=t[b];if(s.operations.compressSparseDivisions){let y=Object.keys(s.divisions),E={},o=!0;if(y.forEach(j=>{let x=s.divisions[j],h=Object.keys(x.values);h.length<=1?h.forEach(n=>{E[n]=k({},x.values[n])}):o=!1}),o){let j={id:s.nodeId,values:E};y.forEach(x=>{delete m[x]}),s.divisions={},s.divisions[s.nodeId]=j}}}),(w=e.dimensions)!=null&&w.adjustDimensions&&(t=e.dimensions.adjustDimensions(t)),t},ue=(e,m,t)=>{var P,w,b,s,y,E,o,j,x,h;let g={},O=(n,d)=>{m[n].edges.indexOf(d)===-1&&m[n].edges.push(d)},r=(n,d,a,l)=>{let v=`${n}-${d}`,u=e.useDirectedEdges?`${d}-${v}`:v,c=!l||l==="source",K=!l||l==="target",f=I=>{g[I]?g[I].navigationRules.push(...a||[]):g[I]={source:n,target:d,navigationRules:a?[...a]:[]}};f(v),e.useDirectedEdges&&K&&f(u),c&&O(n,v),K&&O(d,u)};if(t&&Object.keys(t).length){let n=Object.keys(t),d=(b=(w=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:w.level1Options)==null?void 0:b.order,a=d||n,l=0,v=((s=e.dimensions)==null?void 0:s.parentOptions)||{},u=((E=(y=v.level1Options)==null?void 0:y.behavior)==null?void 0:E.extents)||"terminal",c=v.addLevel0,K=c?((j=(o=v.level1Options)==null?void 0:o.navigationRules)==null?void 0:j.parent_child)||["parent","child"]:[],f=((h=(x=v.level1Options)==null?void 0:x.navigationRules)==null?void 0:h.sibling_sibling)||["left","right"],I=typeof a[0]=="string"?d?m[a[0]]:m[t[a[0]].nodeId]:a[0];c&&r(c.id,I.id,K,"source"),a.forEach(p=>{let i=typeof p=="string"?d?m[p]:m[t[p].nodeId]:p;if(i===p&&!m[i.id]&&(m[i.id]=i),c&&(e.useDirectedEdges?r(i.id,c.id,K,"source"):r(c.id,i.id,K,"target")),l===a.length-1&&u==="circular")r(i.id,I.id,f);else if(l===a.length-1&&u==="bridgedCustom")r(i.id,v.level1Options.behavior.customBridgePost,f);else if(l<a.length-1){let B=typeof a[l+1]=="string"?d?m[a[l+1]]:m[t[a[l+1]].nodeId]:a[l+1];r(i.id,B.id,f)}!l&&u==="bridgedCustom"&&r(v.level1Options.behavior.customBridgePost,i.id,f),l++}),n.forEach(p=>{var U,W,Y,z;let i=t[p],B=((U=i.behavior)==null?void 0:U.childmostNavigation)||"within",V=(T,N,R,L)=>L.values[Object.keys(L.values)[T]]||void 0,G=B==="across"&&((W=i.behavior)!=null&&W.childmostMatching)?(Y=i.behavior)==null?void 0:Y.childmostMatching:V,$=((z=i.behavior)==null?void 0:z.extents)||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${p} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let D=Object.keys(i.divisions),q=i.divisions[D[0]];if(D.length!==1)r(i.nodeId,q.id,i.navigationRules.parent_child,"source");else{let T=Object.keys(q.values),N=typeof e.idKey=="function"?e.idKey(q.values[T[0]]):e.idKey;r(i.nodeId,q.values[T[0]][N],i.navigationRules.parent_child,"source")}let S=0;D.forEach(T=>{let N=i.divisions[T];S===D.length-1&&($==="circular"||$==="bridgedCousins"||$==="bridgedCustom")?r(N.id,i.divisions[D[0]].id,i.navigationRules.sibling_sibling):S<D.length-1&&r(N.id,i.divisions[D[S+1]].id,i.navigationRules.sibling_sibling);let R=Object.keys(N.values);if(e.useDirectedEdges?r(N.id,i.nodeId,i.navigationRules.parent_child,"source"):r(i.nodeId,N.id,i.navigationRules.parent_child,"target"),R.length>0){let A=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(N.id,N.values[R[0]][A],i.navigationRules.parent_child,"source")}let L=0;R.length>=1&&R.forEach(A=>{let _=N.values[A],C=typeof e.idKey=="function"?e.idKey(_):e.idKey,Q=D.length!==1?N.id:i.nodeId;if(e.useDirectedEdges?r(_[C],Q,i.navigationRules.parent_child,"source"):r(Q,_[C],i.navigationRules.parent_child,"target"),B==="within"){if(L===R.length-1&&$==="circular"){let F=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(_[C],N.values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCousins")if(S!==D.length-1){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S+1]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[S+1]].values[R[0]][F],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[0]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[0]].values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(L<R.length-1){let F=typeof e.idKey=="function"?e.idKey(N.values[R[L+1]]):e.idKey;r(_[C],N.values[R[L+1]][F],i.navigationRules.sibling_sibling)}if(!L&&$==="bridgedCousins")if(S!==0){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[S-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[D.length-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else!L&&$==="bridgedCustom"&&r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling)}else if(S===D.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!S&&$==="bridgedCustom")r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling);else{let F=S===D.length-1&&$==="circular"?i.divisions[D[0]]:i.divisions[D[S+1]];if(F){let H=G(L,_[C],N,F);if(H){let oe=typeof e.idKey=="function"?e.idKey(H):e.idKey;r(_[C],H[oe],i.navigationRules.sibling_sibling)}}}L++}),S++})})}return Object.keys(m).forEach(n=>{var a;let d=m[n];(a=e.genericEdges)!=null&&a.length&&e.genericEdges.forEach(l=>{g[l.edgeId]||(g[l.edgeId]=l.edge),(!l.conditional||l.conditional&&l.conditional(d,l))&&d.edges.push(l.edgeId)})}),g},ce=(e,m,t)=>{var O,r,P,w;let g=e.navigationRules;if(!g){let b=Object.keys(t||{});b.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${b.length}. Dimensions counted: ${b.join(", ")}.`);let s={},y={},E={},o=[...ie],j=[...ee],x=(h,n)=>{let d=h&&n,a=!1,l=!1;if((s[h]||y[h])&&(y[h]=k({},s[h]),a=!0),n&&(s[n]||y[n])&&(y[n]=k({},s[n]),l=!0),d&&!a&&!l){o.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let v=[...o.shift()];j.splice(j.indexOf(v[0]),1),j.splice(j.indexOf(v[1]),1),y[h]={direction:e.useDirectedEdges?"target":"source",key:v[0]},y[n]={direction:"target",key:v[1]}}else{if(!y[h]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[h]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!y[n]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[n]={direction:"target",key:v}}j.length||(y[h]||(E[h]=h),n&&!y[n]&&(E[n]=n))}};if(Object.keys(J).forEach(h=>{let n=k({},J[h]);e.useDirectedEdges&&(n.direction="target"),s[h]=n}),b.length){if((r=(O=e.dimensions)==null?void 0:O.parentOptions)!=null&&r.addLevel0){let h=((w=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:w.parent_child)||["parent","child"];x(h[0],h[1])}b.forEach(h=>{let n=t[h].navigationRules.parent_child,d=t[h].navigationRules.sibling_sibling;x(n[0],n[1]),x(d[0],d[1])})}if(Object.keys(m).forEach(h=>{m[h].navigationRules.forEach(n=>{y[n]||x(n)})}),Object.keys(E).length){let h={};Object.keys(y).forEach(d=>{h[y[d].key]=y[d].key}),Object.keys(s).forEach(d=>{!h[s[d].key]&&!Z[s[d].key]&&j.push(s[d].key)});let n=k({},E);E={},Object.keys(n).forEach(d=>{x(d)}),Object.keys(E).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(E).join(", ")}.`)}g=y}return g},ge=e=>{e.addIds&&re(e);let m=ae(e),t=le(e,m),g=ue(e,m,t),O=ce(e,g,t);return{nodes:m,edges:g,dimensions:t,navigationRules:O}};export{re as addSimpleDataIDs,ue as buildEdges,de as buildNodeStructureFromVegaLite,ae as buildNodes,ce as buildRules,ge as buildStructure,ye as default,le as scaffoldDimensions};
@@ -1,21 +1,21 @@
1
- var F=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var a in t)F(e,a,{get:t[a],enumerable:!0})},me=(e,t,a,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of le(t))!de.call(e,n)&&n!==a&&F(e,n,{get:()=>t[n],enumerable:!(l=ce(t,n))||l.enumerable});return e};var pe=e=>me(F({},"__esModule",{value:!0}),e);var K=(e,t,a)=>new Promise((l,n)=>{var r=i=>{try{s(a.next(i))}catch(u){n(u)}},o=i=>{try{s(a.throw(i))}catch(u){n(u)}},s=i=>i.done?l(i.value):Promise.resolve(i.value).then(r,o);s((a=a.apply(e,t)).next())});var we={};ue(we,{default:()=>be});module.exports=pe(we);var Y={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var q={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var ee=e=>{let t={},a=Y,l=q;return t.moveTo=n=>{let r=e.structure.nodes[n];if(r)return r},t.move=(n,r)=>{if(n){let o=e.structure.nodes[n];if(o.edges){let s=null,i=0,u=l[r];if(!u)return;let f=(y,c)=>{if(y!==r)return null;let d={target:typeof c.target=="string"?c.target:c.target(o,n),source:typeof c.source=="string"?c.source:c.source(o,n)};return d[u.direction]!==n?d[u.direction]:null};for(i=0;i<o.edges.length;i++){let y=e.structure.edges[o.edges[i]];if(y.navigationRules.forEach(c=>{s||(s=f(c,y))}),s)break}return s?t.moveTo(s):void 0}}},t.enter=()=>{if(e.entryPoint)return t.moveTo(e.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},t.exit=()=>{if(e.exitPoint)return e.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},t.keydownValidator=n=>{let r=a[n.code];if(r)return r},t.focus=n=>{let r=document.getElementById(n);r&&r.focus()},t.setNavigationKeyBindings=n=>{n?(a={},l=n,Object.keys(n).forEach(r=>{let o=n[r];a[o.key]=r})):(a=Y,l=q)},t.setNavigationKeyBindings(e.navigationRules),t};var he=e=>{var t,a,l,n,r;if((t=e.semantics)!=null&&t.label){let o=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(o)return o}if(!e.derivedNode)return e.data?Object.keys(e.data).map(o=>`${o}: ${e.data[o]}`).join(". ")+". Data point.":e.id;if((a=e.data)!=null&&a.dimensionKey){let o=0,s=Object.keys(e.data.divisions||{});s.forEach(u=>{o+=Object.keys(e.data.divisions[u].values||{}).length});let i=`${e.derivedNode}.`;return i+=s.length&&o?` ${s.length} division${s.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",i+=` ${e.data.type} dimension.`,i}return`${e.derivedNode}: ${(l=e.data)==null?void 0:l[e.derivedNode]}. ${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length} child data point${Object.keys(((r=e.data)==null?void 0:r.values)||{}).length>1?"s":""}. Division.`},ge=(e,t,a)=>{let l=new Set,n=a.navigationRules||{};return t.edges&&t.edges.forEach(r=>{let o=a.edges[r];o&&o.navigationRules.forEach(s=>{let i=n[s];if(!i)return;let u=i.direction==="target"?o.target:o.source,f=typeof u=="function"?u(t,e):u;f&&f!==e&&l.add(s)})}),Array.from(l)},te=e=>e.navigationRules?Object.keys(e.navigationRules):[],J=(e,t)=>{let a=e.length,l=t.length,n=Array(l+1);for(let r=0;r<=l;r++)n[r]=r;for(let r=1;r<=a;r++){let o=n[0];n[0]=r;for(let s=1;s<=l;s++){let i=n[s];n[s]=e[r-1]===t[s-1]?o:1+Math.min(o,n[s],n[s-1]),o=i}}return n[l]},fe=e=>e<=4?1:2,ye=(e,t,a={})=>{let l=e.toLowerCase().trim(),n=t.find(c=>c.toLowerCase()===l);if(n)return{match:n,ambiguous:[]};let r=t.find(c=>a[c]&&a[c].toLowerCase()===l);if(r)return{match:r,ambiguous:[]};let o=t.filter(c=>c.toLowerCase().startsWith(l));if(o.length===1)return{match:o[0],ambiguous:[]};let s=t.filter(c=>{if(!a[c])return!1;let d=a[c].toLowerCase();return d.startsWith(l)?!0:d.split(/\s+/).some(T=>T.startsWith(l))}),i=new Set([...o,...s]),u=Array.from(i);if(u.length===1)return{match:u[0],ambiguous:[]};if(u.length>1)return{match:null,ambiguous:u};let f=fe(l.length),y=[];for(let c=0;c<t.length;c++){let d=t[c],T=J(l,d.toLowerCase());if(T<=f){y.push({candidate:d,dist:T});continue}if(a[d]){let C=a[d].toLowerCase().split(/\s+/);for(let w=0;w<C.length;w++)if(J(l,C[w])<=f){y.push({candidate:d,dist:J(l,C[w])});break}}}return y.length===1?{match:y[0].candidate,ambiguous:[]}:y.length>1?(y.sort((c,d)=>c.dist-d.dist),y[0].dist<y[1].dist?{match:y[0].candidate,ambiguous:[]}:{match:null,ambiguous:y.map(c=>c.candidate)}):{match:null,ambiguous:[]}},G=(e,t)=>t[e]?`${t[e]} (${e})`:e,ve=(e,t,a,l=10)=>{let n=e.toLowerCase(),r=[],o=Object.keys(t.nodes);for(let s=0;s<o.length&&r.length<l;s++){let i=o[s],u=t.nodes[i],f=!1;if(u.data&&!f){let y=Object.keys(u.data);for(let c=0;c<y.length&&!f;c++){let d=u.data[y[c]];d!=null&&typeof d!="object"&&String(d).toLowerCase().includes(n)&&(f=!0)}}!f&&u.derivedNode&&u.derivedNode.toLowerCase().includes(n)&&(f=!0),!f&&i.toLowerCase().includes(n)&&(f=!0),f&&r.push({nodeId:i,description:a(u)})}return r},be=e=>{var _;let{structure:t,container:a,entryPoint:l,describeNode:n=he,commandLabels:r={},onNavigate:o,onExit:s,llm:i,data:u}=e,f=typeof a=="string"?document.getElementById(a):a;if(!f)throw new Error(`textChat: container "${a}" not found`);let y=l||(t.dimensions?(_=t.dimensions[Object.keys(t.dimensions)[0]])==null?void 0:_.nodeId:Object.keys(t.nodes)[0]),c=ee({structure:t,navigationRules:t.navigationRules||{},entryPoint:y}),d=null,T=Math.random().toString(36).slice(2,8),C=[],w=-1,R=null,$=[],ne=()=>{let m=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var i in e)q(t,i,{get:e[i],enumerable:!0})},ge=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of he(e))!me.call(t,r)&&r!==i&&q(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var fe=t=>ge(q({},"__esModule",{value:!0}),t);var B=(t,e,i)=>new Promise((s,r)=>{var n=l=>{try{h(i.next(l))}catch(d){r(d)}},o=l=>{try{h(i.throw(l))}catch(d){r(d)}},h=l=>l.done?s(l.value):Promise.resolve(l.value).then(n,o);h((i=i.apply(t,e)).next())});var Ne={};pe(Ne,{default:()=>xe});module.exports=fe(Ne);var J={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var G={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var ne=t=>{let e={},i=J,s=G;return e.moveTo=r=>{let n=t.structure.nodes[r];if(n)return n},e.move=(r,n)=>{if(r){let o=t.structure.nodes[r];if(o.edges){let h=null,l=0,d=s[n];if(!d)return;let f=(g,a)=>{if(g!==n)return null;let b={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return b[d.direction]!==r?b[d.direction]:null};for(l=0;l<o.edges.length;l++){let g=t.structure.edges[o.edges[l]];if(g.navigationRules.forEach(a=>{h||(h=f(a,g))}),h)break}return h?e.moveTo(h):void 0}}},e.enter=()=>{if(t.entryPoint)return e.moveTo(t.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},e.exit=()=>{if(t.exitPoint)return t.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},e.keydownValidator=r=>{let n=i[r.code];if(n)return n},e.focus=r=>{let n=document.getElementById(r);n&&n.focus()},e.setNavigationKeyBindings=r=>{r?(i={},s=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=J,s=G)},e.setNavigationKeyBindings(t.navigationRules),e};var ye=t=>{var e,i,s,r,n;if((e=t.semantics)!=null&&e.label){let o=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(o)return o}if(!t.derivedNode)return t.data?Object.keys(t.data).map(o=>`${o}: ${t.data[o]}`).join(". ")+". Data point.":t.id;if((i=t.data)!=null&&i.dimensionKey){let o=0,h=Object.keys(t.data.divisions||{});h.forEach(d=>{o+=Object.keys(t.data.divisions[d].values||{}).length});let l=`${t.derivedNode}.`;return l+=h.length&&o?` ${h.length} division${h.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",l+=` ${t.data.type} dimension.`,l}return`${t.derivedNode}: ${(s=t.data)==null?void 0:s[t.derivedNode]}. ${Object.keys(((r=t.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((n=t.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},ve=(t,e,i)=>{let s=new Set,r=i.navigationRules||{};return e.edges&&e.edges.forEach(n=>{let o=i.edges[n];o&&o.navigationRules.forEach(h=>{let l=r[h];if(!l)return;let d=l.direction==="target"?o.target:o.source,f=typeof d=="function"?d(e,t):d;f&&f!==t&&s.add(h)})}),Array.from(s)},re=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let i=t.length,s=e.length,r=Array.from({length:i+1},()=>Array(s+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=s;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=s;o++){let h=t[n-1]===e[o-1]?0:1;r[n][o]=Math.min(r[n-1][o]+1,r[n][o-1]+1,r[n-1][o-1]+h),n>1&&o>1&&t[n-1]===e[o-2]&&t[n-2]===e[o-1]&&(r[n][o]=Math.min(r[n][o],r[n-2][o-2]+h))}return r[i][s]},be=t=>t<=4?1:2,we=(t,e,i={})=>{let s=t.toLowerCase().trim(),r=e.find(a=>a.toLowerCase()===s);if(r)return{match:r,ambiguous:[]};let n=e.find(a=>i[a]&&i[a].toLowerCase()===s);if(n)return{match:n,ambiguous:[]};let o=e.filter(a=>a.toLowerCase().startsWith(s));if(o.length===1)return{match:o[0],ambiguous:[]};let h=e.filter(a=>{if(!i[a])return!1;let b=i[a].toLowerCase();return b.startsWith(s)?!0:b.split(/\s+/).some(A=>A.startsWith(s))}),l=new Set([...o,...h]),d=Array.from(l);if(d.length===1)return{match:d[0],ambiguous:[]};if(d.length>1)return{match:null,ambiguous:d};let f=be(s.length),g=[];for(let a=0;a<e.length;a++){let b=e[a],A=z(s,b.toLowerCase());if(A<=f){g.push({candidate:b,dist:A});continue}if(i[b]){let v=i[b].toLowerCase().split(/\s+/);for(let R=0;R<v.length;R++)if(z(s,v[R])<=f){g.push({candidate:b,dist:z(s,v[R])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,b)=>a.dist-b.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(a=>a.candidate)}):{match:null,ambiguous:[]}},V=(t,e)=>e[t]?`${e[t]} (${t})`:t,ke=(t,e,i,s=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let h=0;h<o.length&&n.length<s;h++){let l=o[h],d=e.nodes[l],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let a=0;a<g.length&&!f;a++){let b=d.data[g[a]];b!=null&&typeof b!="object"&&String(b).toLowerCase().includes(r)&&(f=!0)}}!f&&d.derivedNode&&d.derivedNode.toLowerCase().includes(r)&&(f=!0),!f&&l.toLowerCase().includes(r)&&(f=!0),f&&n.push({nodeId:l,description:i(d)})}return n},xe=t=>{var te;let{structure:e,container:i,entryPoint:s,describeNode:r=ye,commandLabels:n={},onNavigate:o,onExit:h,onClick:l,onHover:d,llm:f,data:g}=t,a=typeof i=="string"?document.getElementById(i):i;if(!a)throw new Error(`textChat: container "${i}" not found`);let b=s||(e.dimensions?(te=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:te.nodeId:Object.keys(e.nodes)[0]),A=ne({structure:e,navigationRules:e.navigationRules||{},entryPoint:b}),v=null,R=Math.random().toString(36).slice(2,8),L=[],C=-1,O=null,S=[],oe=()=>{let c=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
- `;if(u&&u.length>0){let p=Object.keys(u[0]),h=u.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
- `);m+=`DATASET SUMMARY:
3
+ `;if(g&&g.length>0){let p=Object.keys(g[0]),m=g.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
+ `);c+=`DATASET SUMMARY:
5
5
  - Columns: ${p.join(", ")}
6
- - Rows: ${u.length}
6
+ - Rows: ${g.length}
7
7
  - Sample (first 3):
8
- ${h}
8
+ ${m}
9
9
 
10
- `,m+=`FULL DATASET (JSON):
11
- `+JSON.stringify(u)+`
10
+ `,c+=`FULL DATASET (JSON):
11
+ `+JSON.stringify(g)+`
12
12
 
13
- `}if(d){let p=t.nodes[d];m+=`CURRENT POSITION: ${p?n(p):d}
13
+ `}if(v){let p=e.nodes[v];c+=`CURRENT POSITION: ${p?r(p):v}
14
14
 
15
- `}else m+=`CURRENT POSITION: Not yet navigated into the structure.
15
+ `}else c+=`CURRENT POSITION: Not yet navigated into the structure.
16
16
 
17
- `;return m+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
17
+ `;return c+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
18
18
 
19
- `,m+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
19
+ `,c+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
20
20
 
21
- `,m+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',m},L=document.createElement("div");L.className="dn-text-chat";let b=document.createElement("div");b.className="dn-text-chat-log",b.setAttribute("role","log"),b.setAttribute("aria-live","polite"),L.appendChild(b);let B=document.createElement("div");B.className="dn-text-chat-controls";let U=document.createElement("label"),I=document.createElement("input");I.type="checkbox",I.checked=!0,I.addEventListener("change",()=>{b.setAttribute("aria-live",I.checked?"polite":"off")}),U.appendChild(I),U.appendChild(document.createTextNode(" Automatically announce to screen readers")),B.appendChild(U),L.appendChild(B);let O=document.createElement("form");O.className="dn-text-chat-form";let j=document.createElement("label");j.setAttribute("for",`dn-text-chat-input-${T}`),j.className="dn-text-chat-sr-only",j.textContent="Navigation command";let k=document.createElement("input");k.type="text",k.id=`dn-text-chat-input-${T}`,k.autocomplete="off",k.setAttribute("placeholder","Type a command...");let H=document.createElement("button");H.type="submit",H.textContent="Send",O.appendChild(j),O.appendChild(k),O.appendChild(H),L.appendChild(O),f.appendChild(L);let z="";k.addEventListener("keydown",m=>{if(m.key==="ArrowUp"){if(m.preventDefault(),C.length===0)return;w===-1?(z=k.value,w=C.length-1):w>0&&w--,k.value=C[w]}else if(m.key==="ArrowDown"){if(m.preventDefault(),w===-1)return;w<C.length-1?(w++,k.value=C[w]):(w=-1,k.value=z)}});let W=(m,p)=>{let h=document.createElement("div");h.className=`dn-text-chat-message ${p}`,h.textContent=m,b.appendChild(h),b.scrollTop=b.scrollHeight},S=m=>W(m,"dn-text-chat-system"),re=m=>W(`> ${m}`,"dn-text-chat-input-echo"),v=m=>W(m,"dn-text-chat-response"),oe=(m,p)=>{let h=document.createElement("div");h.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=m,h.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",p.forEach(P=>{let A=document.createElement("li");A.textContent=P,E.appendChild(A)}),h.appendChild(E),b.appendChild(h),b.scrollTop=b.scrollHeight},V=m=>K(void 0,null,function*(){let p={role:"system",content:ne()};$.push({role:"user",content:m});let h=document.createElement("div");h.className="dn-text-chat-message dn-text-chat-llm-thinking",h.textContent="Thinking...",b.appendChild(h),b.scrollTop=b.scrollHeight;try{let N=yield i([p,...$]);return b.removeChild(h),N===null?($.pop(),null):($.push({role:"assistant",content:N}),v(N),N)}catch(N){return b.removeChild(h),$.pop(),v(`Error: ${N.message||"Could not get a response."}`),""}});i?(S('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),S('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):S('Text navigation ready. Type "enter" to begin or "help" for available commands.');let Q=["enter","help","more","more help","clear"],Z=m=>{let p=c.moveTo(m);p?(d=p.id,o&&o(p),v(`Moved to: ${n(p)}`)):v("Could not move to that node.")},X=m=>K(void 0,null,function*(){let p=m.trim();if(!p)return;re(p);let h=p.toLowerCase();if(R){let g=parseInt(p,10);if(!isNaN(g)&&g>=1&&g<=R.length){let x=R[g-1];R=null,Z(x.nodeId);return}R=null}if(h==="clear"){b.innerHTML="",S('Chat cleared. Type "help" for available commands.');return}if(h==="enter"){if(d){v('Already in the structure. Type "help" to see available commands.');return}let g=c.enter();if(!g){v("Could not enter the structure. No entry point found.");return}d=g.id,o&&o(g),v(`Entered: ${n(g)}`);return}if(h==="help"){let g=i?" You can also type any question about the data.":"";if(!d)v('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+g);else{let x=t.nodes[d],ie=ge(d,x,t).map(se=>G(se,r));v(`Available: ${ie.join(", ")}, move to <search>.`+g)}return}if(h.startsWith("move to ")){let g=p.slice(8).trim();if(!g){v("Usage: move to <search term>");return}let x=ve(g,t,n);x.length===0?v(`No nodes found matching "${g}".`):x.length===1?Z(x[0].nodeId):(R=x,oe(`Found ${x.length} matches. Type a number to move there:`,x.map(D=>D.description)));return}if(h==="more"||h==="more help"){let x=te(t).map(D=>G(D,r));v(`All navigation rules: ${x.join(", ")}.`);return}if(!d){if(i&&(yield V(p))!==null)return;v('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(i?" Enter an API key above to ask questions about the data.":""));return}let N=te(t),{match:E,ambiguous:P}=ye(h,[...N,...Q],r);if(E&&Q.includes(E)){yield X(E);return}if(!E&&P.length>0){let g=P.map(x=>G(x,r));v(`Did you mean: ${g.join(", ")}?`);return}if(!E){if(i&&(yield V(p))!==null)return;let g=i?" Enter an API key above to ask questions about the data.":"";v(`Unknown command "${p}". Type "help" for available commands.`+g);return}let A=E,ae=r[A]||A;if(A==="exit"){d=null,s&&s(),v('Exited the structure. Type "enter" to re-enter.');return}let M=c.move(d,A);M?(d=M.id,o&&o(M),v(`${ae}: ${n(M)}`)):v(`Cannot move "${A}" from here.`)});return O.addEventListener("submit",m=>K(void 0,null,function*(){m.preventDefault();let p=k.value.trim();p&&(C.push(p),w=-1),yield X(k.value),k.value="",k.focus()})),{destroy(){f.removeChild(L)},getCurrentNode(){return d&&t.nodes[d]||null}}};
21
+ `,c+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',c},$=document.createElement("div");$.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),$.appendChild(k);let U=document.createElement("div");U.className="dn-text-chat-controls";let W=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{k.setAttribute("aria-live",P.checked?"polite":"off")}),W.appendChild(P),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(W),$.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${R}`),M.className="dn-text-chat-sr-only",M.textContent="Navigation command";let x=document.createElement("input");x.type="text",x.id=`dn-text-chat-input-${R}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let F=document.createElement("button");F.type="submit",F.textContent="Send",I.appendChild(M),I.appendChild(x),I.appendChild(F),$.appendChild(I),a.appendChild($);let Q="";x.addEventListener("keydown",c=>{if(c.key==="ArrowUp"){if(c.preventDefault(),L.length===0)return;C===-1?(Q=x.value,C=L.length-1):C>0&&C--,x.value=L[C]}else if(c.key==="ArrowDown"){if(c.preventDefault(),C===-1)return;C<L.length-1?(C++,x.value=L[C]):(C=-1,x.value=Q)}});let Y=(c,p)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${p}`,m.textContent=c,k.appendChild(m),k.scrollTop=k.scrollHeight},D=c=>Y(c,"dn-text-chat-system"),ie=c=>Y(`> ${c}`,"dn-text-chat-input-echo"),y=c=>Y(c,"dn-text-chat-response"),ae=(c,p)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=c,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",p.forEach(H=>{let T=document.createElement("li");T.textContent=H,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},Z=c=>B(void 0,null,function*(){let p={role:"system",content:oe()};S.push({role:"user",content:c});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",k.appendChild(m),k.scrollTop=k.scrollHeight;try{let N=yield f([p,...S]);return k.removeChild(m),N===null?(S.pop(),null):(S.push({role:"assistant",content:N}),y(N),N)}catch(N){return k.removeChild(m),S.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});f?(D('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),D('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):D('Text navigation ready. Type "enter" to begin or "help" for available commands.');let X=["enter","help","more","more help","clear","click","select","hover","inspect"],_=c=>{let p=A.moveTo(c);p?(v=p.id,o&&o(p),y(`Moved to: ${r(p)}`)):y("Could not move to that node.")},ee=c=>B(void 0,null,function*(){let p=c.trim();if(!p)return;ie(p);let m=p.toLowerCase();if(O){let u=parseInt(p,10);if(!isNaN(u)&&u>=1&&u<=O.length){let w=O[u-1];O=null,_(w.nodeId);return}O=null}if(m==="clear"){k.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(v){y('Already in the structure. Type "help" to see available commands.');return}let u=A.enter();if(!u){y("Could not enter the structure. No entry point found.");return}v=u.id,o&&o(u),y(`Entered: ${r(u)}`);return}if(m==="help"){let u=f?" You can also type any question about the data.":"",w=[];l&&w.push('"click" or "select"'),d&&w.push('"hover" or "inspect"');let j=w.length?` Interaction: ${w.join(", ")}.`:"";if(!v)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let ce=e.nodes[v],le=ve(v,ce,e).map(de=>V(de,n));y(`Available: ${le.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];l&&u?(l(u),y(`Clicked: ${r(u)}`)):y(l?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(m==="hover"||m==="inspect"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];d&&u?(d(u),y(`Hovering over: ${r(u)}`)):y(d?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(m.startsWith("move to ")){let u=p.slice(8).trim();if(!u){y("Usage: move to <search term>");return}let w=ke(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?_(w[0].nodeId):(O=w,ae(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=re(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield Z(p))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(f?" Enter an API key above to ask questions about the data.":""));return}let N=re(e),{match:E,ambiguous:H}=we(m,[...N,...X],n);if(E&&X.includes(E)){yield ee(E);return}if(!E&&H.length>0){let u=H.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield Z(p))!==null)return;let u=f?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${p}". Type "help" for available commands.`+u);return}let T=E,se=n[T]||T;if(T==="exit"){v=null,h&&h(),y('Exited the structure. Type "enter" to re-enter.');return}let K=A.move(v,T);K?(v=K.id,o&&o(K),y(`${se}: ${r(K)}`)):y(`Cannot move "${T}" from here.`)});return I.addEventListener("submit",c=>B(void 0,null,function*(){c.preventDefault();let p=x.value.trim();p&&(L.push(p),C=-1),yield ee(x.value),x.value="",x.focus()})),{destroy(){a.removeChild($)},getCurrentNode(){return v&&e.nodes[v]||null}}};
package/dist/text-chat.js CHANGED
@@ -1,21 +1,21 @@
1
- import{a as X}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as H}from"./chunk-RGY6OTGO.js";var at=t=>{var e,g,l,i,a;if((e=t.semantics)!=null&&e.label){let n=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(n)return n}if(!t.derivedNode)return t.data?Object.keys(t.data).map(n=>`${n}: ${t.data[n]}`).join(". ")+". Data point.":t.id;if((g=t.data)!=null&&g.dimensionKey){let n=0,d=Object.keys(t.data.divisions||{});d.forEach(u=>{n+=Object.keys(t.data.divisions[u].values||{}).length});let h=`${t.derivedNode}.`;return h+=d.length&&n?` ${d.length} division${d.length>1?"s":""}, ${n} datapoint${n>1?"s":""}.`:" No child data points.",h+=` ${t.data.type} dimension.`,h}return`${t.derivedNode}: ${(l=t.data)==null?void 0:l[t.derivedNode]}. ${Object.keys(((i=t.data)==null?void 0:i.values)||{}).length} child data point${Object.keys(((a=t.data)==null?void 0:a.values)||{}).length>1?"s":""}. Division.`},rt=(t,e,g)=>{let l=new Set,i=g.navigationRules||{};return e.edges&&e.edges.forEach(a=>{let n=g.edges[a];n&&n.navigationRules.forEach(d=>{let h=i[d];if(!h)return;let u=h.direction==="target"?n.target:n.source,f=typeof u=="function"?u(e,t):u;f&&f!==t&&l.add(d)})}),Array.from(l)},Z=t=>t.navigationRules?Object.keys(t.navigationRules):[],Y=(t,e)=>{let g=t.length,l=e.length,i=Array(l+1);for(let a=0;a<=l;a++)i[a]=a;for(let a=1;a<=g;a++){let n=i[0];i[0]=a;for(let d=1;d<=l;d++){let h=i[d];i[d]=t[a-1]===e[d-1]?n:1+Math.min(n,i[d],i[d-1]),n=h}}return i[l]},it=t=>t<=4?1:2,ct=(t,e,g={})=>{let l=t.toLowerCase().trim(),i=e.find(c=>c.toLowerCase()===l);if(i)return{match:i,ambiguous:[]};let a=e.find(c=>g[c]&&g[c].toLowerCase()===l);if(a)return{match:a,ambiguous:[]};let n=e.filter(c=>c.toLowerCase().startsWith(l));if(n.length===1)return{match:n[0],ambiguous:[]};let d=e.filter(c=>{if(!g[c])return!1;let s=g[c].toLowerCase();return s.startsWith(l)?!0:s.split(/\s+/).some($=>$.startsWith(l))}),h=new Set([...n,...d]),u=Array.from(h);if(u.length===1)return{match:u[0],ambiguous:[]};if(u.length>1)return{match:null,ambiguous:u};let f=it(l.length),x=[];for(let c=0;c<e.length;c++){let s=e[c],$=Y(l,s.toLowerCase());if($<=f){x.push({candidate:s,dist:$});continue}if(g[s]){let E=g[s].toLowerCase().split(/\s+/);for(let b=0;b<E.length;b++)if(Y(l,E[b])<=f){x.push({candidate:s,dist:Y(l,E[b])});break}}}return x.length===1?{match:x[0].candidate,ambiguous:[]}:x.length>1?(x.sort((c,s)=>c.dist-s.dist),x[0].dist<x[1].dist?{match:x[0].candidate,ambiguous:[]}:{match:null,ambiguous:x.map(c=>c.candidate)}):{match:null,ambiguous:[]}},J=(t,e)=>e[t]?`${e[t]} (${t})`:t,lt=(t,e,g,l=10)=>{let i=t.toLowerCase(),a=[],n=Object.keys(e.nodes);for(let d=0;d<n.length&&a.length<l;d++){let h=n[d],u=e.nodes[h],f=!1;if(u.data&&!f){let x=Object.keys(u.data);for(let c=0;c<x.length&&!f;c++){let s=u.data[x[c]];s!=null&&typeof s!="object"&&String(s).toLowerCase().includes(i)&&(f=!0)}}!f&&u.derivedNode&&u.derivedNode.toLowerCase().includes(i)&&(f=!0),!f&&h.toLowerCase().includes(i)&&(f=!0),f&&a.push({nodeId:h,description:g(u)})}return a},ut=t=>{var Q;let{structure:e,container:g,entryPoint:l,describeNode:i=at,commandLabels:a={},onNavigate:n,onExit:d,llm:h,data:u}=t,f=typeof g=="string"?document.getElementById(g):g;if(!f)throw new Error(`textChat: container "${g}" not found`);let x=l||(e.dimensions?(Q=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:Q.nodeId:Object.keys(e.nodes)[0]),c=X({structure:e,navigationRules:e.navigationRules||{},entryPoint:x}),s=null,$=Math.random().toString(36).slice(2,8),E=[],b=-1,A=null,R=[],_=()=>{let o=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
1
+ import{a as _}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as q}from"./chunk-RGY6OTGO.js";var ce=e=>{var o,d,u,a,n;if((o=e.semantics)!=null&&o.label){let t=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(t)return t}if(!e.derivedNode)return e.data?Object.keys(e.data).map(t=>`${t}: ${e.data[t]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let t=0,v=Object.keys(e.data.divisions||{});v.forEach(p=>{t+=Object.keys(e.data.divisions[p].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&t?` ${v.length} division${v.length>1?"s":""}, ${t} datapoint${t>1?"s":""}.`:" No child data points.",b+=` ${e.data.type} dimension.`,b}return`${e.derivedNode}: ${(u=e.data)==null?void 0:u[e.derivedNode]}. ${Object.keys(((a=e.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},le=(e,o,d)=>{let u=new Set,a=d.navigationRules||{};return o.edges&&o.edges.forEach(n=>{let t=d.edges[n];t&&t.navigationRules.forEach(v=>{let b=a[v];if(!b)return;let p=b.direction==="target"?t.target:t.source,g=typeof p=="function"?p(o,e):p;g&&g!==e&&u.add(v)})}),Array.from(u)},ee=e=>e.navigationRules?Object.keys(e.navigationRules):[],K=(e,o)=>{let d=e.length,u=o.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let n=0;n<=d;n++)a[n][0]=n;for(let n=0;n<=u;n++)a[0][n]=n;for(let n=1;n<=d;n++)for(let t=1;t<=u;t++){let v=e[n-1]===o[t-1]?0:1;a[n][t]=Math.min(a[n-1][t]+1,a[n][t-1]+1,a[n-1][t-1]+v),n>1&&t>1&&e[n-1]===o[t-2]&&e[n-2]===o[t-1]&&(a[n][t]=Math.min(a[n][t],a[n-2][t-2]+v))}return a[d][u]},de=e=>e<=4?1:2,ue=(e,o,d={})=>{let u=e.toLowerCase().trim(),a=o.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let n=o.find(l=>d[l]&&d[l].toLowerCase()===u);if(n)return{match:n,ambiguous:[]};let t=o.filter(l=>l.toLowerCase().startsWith(u));if(t.length===1)return{match:t[0],ambiguous:[]};let v=o.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(T=>T.startsWith(u))}),b=new Set([...t,...v]),p=Array.from(b);if(p.length===1)return{match:p[0],ambiguous:[]};if(p.length>1)return{match:null,ambiguous:p};let g=de(u.length),f=[];for(let l=0;l<o.length;l++){let x=o[l],T=K(u,x.toLowerCase());if(T<=g){f.push({candidate:x,dist:T});continue}if(d[x]){let m=d[x].toLowerCase().split(/\s+/);for(let A=0;A<m.length;A++)if(K(u,m[A])<=g){f.push({candidate:x,dist:K(u,m[A])});break}}}return f.length===1?{match:f[0].candidate,ambiguous:[]}:f.length>1?(f.sort((l,x)=>l.dist-x.dist),f[0].dist<f[1].dist?{match:f[0].candidate,ambiguous:[]}:{match:null,ambiguous:f.map(l=>l.candidate)}):{match:null,ambiguous:[]}},z=(e,o)=>o[e]?`${o[e]} (${e})`:e,he=(e,o,d,u=10)=>{let a=e.toLowerCase(),n=[],t=Object.keys(o.nodes);for(let v=0;v<t.length&&n.length<u;v++){let b=t[v],p=o.nodes[b],g=!1;if(p.data&&!g){let f=Object.keys(p.data);for(let l=0;l<f.length&&!g;l++){let x=p.data[f[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(g=!0)}}!g&&p.derivedNode&&p.derivedNode.toLowerCase().includes(a)&&(g=!0),!g&&b.toLowerCase().includes(a)&&(g=!0),g&&n.push({nodeId:b,description:d(p)})}return n},ge=e=>{var Z;let{structure:o,container:d,entryPoint:u,describeNode:a=ce,commandLabels:n={},onNavigate:t,onExit:v,onClick:b,onHover:p,llm:g,data:f}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=u||(o.dimensions?(Z=o.dimensions[Object.keys(o.dimensions)[0]])==null?void 0:Z.nodeId:Object.keys(o.nodes)[0]),T=_({structure:o,navigationRules:o.navigationRules||{},entryPoint:x}),m=null,A=Math.random().toString(36).slice(2,8),L=[],E=-1,I=null,M=[],te=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
2
2
 
3
- `;if(u&&u.length>0){let r=Object.keys(u[0]),m=u.slice(0,3).map(N=>JSON.stringify(N)).join(`
4
- `);o+=`DATASET SUMMARY:
5
- - Columns: ${r.join(", ")}
6
- - Rows: ${u.length}
3
+ `;if(f&&f.length>0){let c=Object.keys(f[0]),i=f.slice(0,3).map(w=>JSON.stringify(w)).join(`
4
+ `);s+=`DATASET SUMMARY:
5
+ - Columns: ${c.join(", ")}
6
+ - Rows: ${f.length}
7
7
  - Sample (first 3):
8
- ${m}
8
+ ${i}
9
9
 
10
- `,o+=`FULL DATASET (JSON):
11
- `+JSON.stringify(u)+`
10
+ `,s+=`FULL DATASET (JSON):
11
+ `+JSON.stringify(f)+`
12
12
 
13
- `}if(s){let r=e.nodes[s];o+=`CURRENT POSITION: ${r?i(r):s}
13
+ `}if(m){let c=o.nodes[m];s+=`CURRENT POSITION: ${c?a(c):m}
14
14
 
15
- `}else o+=`CURRENT POSITION: Not yet navigated into the structure.
15
+ `}else s+=`CURRENT POSITION: Not yet navigated into the structure.
16
16
 
17
- `;return o+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
17
+ `;return s+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
18
18
 
19
- `,o+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
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
- `,o+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',o},L=document.createElement("div");L.className="dn-text-chat";let v=document.createElement("div");v.className="dn-text-chat-log",v.setAttribute("role","log"),v.setAttribute("aria-live","polite"),L.appendChild(v);let U=document.createElement("div");U.className="dn-text-chat-controls";let q=document.createElement("label"),O=document.createElement("input");O.type="checkbox",O.checked=!0,O.addEventListener("change",()=>{v.setAttribute("aria-live",O.checked?"polite":"off")}),q.appendChild(O),q.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(q),L.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let j=document.createElement("label");j.setAttribute("for",`dn-text-chat-input-${$}`),j.className="dn-text-chat-sr-only",j.textContent="Navigation command";let w=document.createElement("input");w.type="text",w.id=`dn-text-chat-input-${$}`,w.autocomplete="off",w.setAttribute("placeholder","Type a command...");let F=document.createElement("button");F.type="submit",F.textContent="Send",I.appendChild(j),I.appendChild(w),I.appendChild(F),L.appendChild(I),f.appendChild(L);let K="";w.addEventListener("keydown",o=>{if(o.key==="ArrowUp"){if(o.preventDefault(),E.length===0)return;b===-1?(K=w.value,b=E.length-1):b>0&&b--,w.value=E[b]}else if(o.key==="ArrowDown"){if(o.preventDefault(),b===-1)return;b<E.length-1?(b++,w.value=E[b]):(b=-1,w.value=K)}});let W=(o,r)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${r}`,m.textContent=o,v.appendChild(m),v.scrollTop=v.scrollHeight},M=o=>W(o,"dn-text-chat-system"),tt=o=>W(`> ${o}`,"dn-text-chat-input-echo"),y=o=>W(o,"dn-text-chat-response"),et=(o,r)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=o,m.appendChild(N);let T=document.createElement("ol");T.className="dn-text-chat-choices",r.forEach(S=>{let k=document.createElement("li");k.textContent=S,T.appendChild(k)}),m.appendChild(T),v.appendChild(m),v.scrollTop=v.scrollHeight},z=o=>H(void 0,null,function*(){let r={role:"system",content:_()};R.push({role:"user",content:o});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",v.appendChild(m),v.scrollTop=v.scrollHeight;try{let N=yield h([r,...R]);return v.removeChild(m),N===null?(R.pop(),null):(R.push({role:"assistant",content:N}),y(N),N)}catch(N){return v.removeChild(m),R.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});h?(M('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),M('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):M('Text navigation ready. Type "enter" to begin or "help" for available commands.');let B=["enter","help","more","more help","clear"],V=o=>{let r=c.moveTo(o);r?(s=r.id,n&&n(r),y(`Moved to: ${i(r)}`)):y("Could not move to that node.")},G=o=>H(void 0,null,function*(){let r=o.trim();if(!r)return;tt(r);let m=r.toLowerCase();if(A){let p=parseInt(r,10);if(!isNaN(p)&&p>=1&&p<=A.length){let C=A[p-1];A=null,V(C.nodeId);return}A=null}if(m==="clear"){v.innerHTML="",M('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(s){y('Already in the structure. Type "help" to see available commands.');return}let p=c.enter();if(!p){y("Could not enter the structure. No entry point found.");return}s=p.id,n&&n(p),y(`Entered: ${i(p)}`);return}if(m==="help"){let p=h?" You can also type any question about the data.":"";if(!s)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+p);else{let C=e.nodes[s],ot=rt(s,C,e).map(st=>J(st,a));y(`Available: ${ot.join(", ")}, move to <search>.`+p)}return}if(m.startsWith("move to ")){let p=r.slice(8).trim();if(!p){y("Usage: move to <search term>");return}let C=lt(p,e,i);C.length===0?y(`No nodes found matching "${p}".`):C.length===1?V(C[0].nodeId):(A=C,et(`Found ${C.length} matches. Type a number to move there:`,C.map(D=>D.description)));return}if(m==="more"||m==="more help"){let C=Z(e).map(D=>J(D,a));y(`All navigation rules: ${C.join(", ")}.`);return}if(!s){if(h&&(yield z(r))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(h?" Enter an API key above to ask questions about the data.":""));return}let N=Z(e),{match:T,ambiguous:S}=ct(m,[...N,...B],a);if(T&&B.includes(T)){yield G(T);return}if(!T&&S.length>0){let p=S.map(C=>J(C,a));y(`Did you mean: ${p.join(", ")}?`);return}if(!T){if(h&&(yield z(r))!==null)return;let p=h?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${r}". Type "help" for available commands.`+p);return}let k=T,nt=a[k]||k;if(k==="exit"){s=null,d&&d(),y('Exited the structure. Type "enter" to re-enter.');return}let P=c.move(s,k);P?(s=P.id,n&&n(P),y(`${nt}: ${i(P)}`)):y(`Cannot move "${k}" from here.`)});return I.addEventListener("submit",o=>H(void 0,null,function*(){o.preventDefault();let r=w.value.trim();r&&(E.push(r),b=-1),yield G(w.value),w.value="",w.focus()})),{destroy(){f.removeChild(L)},getCurrentNode(){return s&&e.nodes[s]||null}}};export{ut as default};
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},R=document.createElement("div");R.className="dn-text-chat";let C=document.createElement("div");C.className="dn-text-chat-log",C.setAttribute("role","log"),C.setAttribute("aria-live","polite"),R.appendChild(C);let F=document.createElement("div");F.className="dn-text-chat-controls";let W=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=!0,S.addEventListener("change",()=>{C.setAttribute("aria-live",S.checked?"polite":"off")}),W.appendChild(S),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),F.appendChild(W),R.appendChild(F);let j=document.createElement("form");j.className="dn-text-chat-form";let P=document.createElement("label");P.setAttribute("for",`dn-text-chat-input-${A}`),P.className="dn-text-chat-sr-only",P.textContent="Navigation command";let N=document.createElement("input");N.type="text",N.id=`dn-text-chat-input-${A}`,N.autocomplete="off",N.setAttribute("placeholder","Type a command...");let Y=document.createElement("button");Y.type="submit",Y.textContent="Send",j.appendChild(P),j.appendChild(N),j.appendChild(Y),R.appendChild(j),l.appendChild(R);let B="";N.addEventListener("keydown",s=>{if(s.key==="ArrowUp"){if(s.preventDefault(),L.length===0)return;E===-1?(B=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=B)}});let J=(s,c)=>{let i=document.createElement("div");i.className=`dn-text-chat-message ${c}`,i.textContent=s,C.appendChild(i),C.scrollTop=C.scrollHeight},H=s=>J(s,"dn-text-chat-system"),ne=s=>J(`> ${s}`,"dn-text-chat-input-echo"),h=s=>J(s,"dn-text-chat-response"),oe=(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(D=>{let $=document.createElement("li");$.textContent=D,k.appendChild($)}),i.appendChild(k),C.appendChild(i),C.scrollTop=C.scrollHeight},V=s=>q(void 0,null,function*(){let c={role:"system",content:te()};M.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 g([c,...M]);return C.removeChild(i),w===null?(M.pop(),null):(M.push({role:"assistant",content:w}),h(w),w)}catch(w){return C.removeChild(i),M.pop(),h(`Error: ${w.message||"Could not get a response."}`),""}});g?(H('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),H('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.')):H('Text navigation ready. Type "enter" to begin or "help" for available commands.');let G=["enter","help","more","more help","clear","click","select","hover","inspect"],Q=s=>{let c=T.moveTo(s);c?(m=c.id,t&&t(c),h(`Moved to: ${a(c)}`)):h("Could not move to that node.")},X=s=>q(void 0,null,function*(){let c=s.trim();if(!c)return;ne(c);let i=c.toLowerCase();if(I){let r=parseInt(c,10);if(!isNaN(r)&&r>=1&&r<=I.length){let y=I[r-1];I=null,Q(y.nodeId);return}I=null}if(i==="clear"){C.innerHTML="",H('Chat cleared. Type "help" for available commands.');return}if(i==="enter"){if(m){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}m=r.id,t&&t(r),h(`Entered: ${a(r)}`);return}if(i==="help"){let r=g?" You can also type any question about the data.":"",y=[];b&&y.push('"click" or "select"'),p&&y.push('"hover" or "inspect"');let O=y.length?` Interaction: ${y.join(", ")}.`:"";if(!m)h('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+O+r);else{let ae=o.nodes[m],re=le(m,ae,o).map(ie=>z(ie,n));h(`Available: ${re.join(", ")}, move to <search>.`+O+r)}return}if(i==="click"||i==="select"){if(!m){h('Not in the structure. Type "enter" to begin.');return}let r=o.nodes[m];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(!m){h('Not in the structure. Type "enter" to begin.');return}let r=o.nodes[m];p&&r?(p(r),h(`Hovering over: ${a(r)}`)):h(p?"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=he(r,o,a);y.length===0?h(`No nodes found matching "${r}".`):y.length===1?Q(y[0].nodeId):(I=y,oe(`Found ${y.length} matches. Type a number to move there:`,y.map(O=>O.description)));return}if(i==="more"||i==="more help"){let y=ee(o).map(O=>z(O,n));h(`All navigation rules: ${y.join(", ")}.`);return}if(!m){if(g&&(yield V(c))!==null)return;h('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(g?" Enter an API key above to ask questions about the data.":""));return}let w=ee(o),{match:k,ambiguous:D}=ue(i,[...w,...G],n);if(k&&G.includes(k)){yield X(k);return}if(!k&&D.length>0){let r=D.map(y=>z(y,n));h(`Did you mean: ${r.join(", ")}?`);return}if(!k){if(g&&(yield V(c))!==null)return;let r=g?" Enter an API key above to ask questions about the data.":"";h(`Unknown command "${c}". Type "help" for available commands.`+r);return}let $=k,se=n[$]||$;if($==="exit"){m=null,v&&v(),h('Exited the structure. Type "enter" to re-enter.');return}let U=T.move(m,$);U?(m=U.id,t&&t(U),h(`${se}: ${a(U)}`)):h(`Cannot move "${$}" from here.`)});return j.addEventListener("submit",s=>q(void 0,null,function*(){s.preventDefault();let c=N.value.trim();c&&(L.push(c),E=-1),yield X(N.value),N.value="",N.focus()})),{destroy(){l.removeChild(R)},getCurrentNode(){return m&&o.nodes[m]||null}}};export{ge as default};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "data-navigator",
3
3
  "author": "Frank Elavsky",
4
- "version": "2.3.0",
4
+ "version": "2.4.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
8
- "types": "./dist/src/index.d.ts",
8
+ "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
11
  "text-chat.css",
@@ -15,11 +15,11 @@
15
15
  "exports": {
16
16
  ".": {
17
17
  "import": {
18
- "types": "./dist/src/index.d.ts",
18
+ "types": "./dist/index.d.ts",
19
19
  "default": "./dist/index.js"
20
20
  },
21
21
  "require": {
22
- "types": "./dist/src/index.d.ts",
22
+ "types": "./dist/index.d.ts",
23
23
  "default": "./dist/index.cjs"
24
24
  }
25
25
  },
@@ -35,7 +35,7 @@
35
35
  "scripts": {
36
36
  "clean": "rm -rf ./dist",
37
37
  "build": "yarn build:index && yarn build:modules",
38
- "build:index": "tsup src/index.ts --format cjs,esm",
38
+ "build:index": "tsup src/index.ts --format cjs,esm --dts",
39
39
  "build:modules": "tsup src/structure.ts src/input.ts src/rendering.ts src/utilities.ts src/consts.ts src/text-chat.ts --format cjs,esm --minify",
40
40
  "prepublishOnly": "cp ../../README.md ../../LICENSE ."
41
41
  },