@graphysdk/react-renderer 1.9.0-beta.1792407460425 → 1.9.0-beta.1792410301640

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const o=require("./history-chords-B9ozn71x.cjs");let m=require("@graphysdk/viz-engine"),d=require("react"),a=require("react/jsx-runtime"),F=require("zustand"),O=require("motion/react"),Y=require("zustand/vanilla"),U=require("clsx");U=o.__toESM(U,1);var me="_1a5iqpb0",ge="_1a5iqpb1";var pe="_1a5iqpb3",ve="_1a5iqpb4",fe="_1a5iqpb5";var z=({errors:e})=>{const[t,...r]=e;return(0,a.jsxs)("div",{role:"alert",className:me,children:[(0,a.jsx)("strong",{className:ge,children:"This chart could not be rendered."}),t&&(0,a.jsx)(V,{diagnostic:t}),r.length>0&&(0,a.jsx)("ul",{className:"_1a5iqpb2",children:r.map((n,s)=>(0,a.jsx)("li",{children:(0,a.jsx)(V,{diagnostic:n})},`${n.code}-${s}`))})]})},V=({diagnostic:e})=>(0,a.jsxs)("div",{className:pe,children:[(0,a.jsx)("span",{className:ve,children:e.code}),(0,a.jsx)("p",{className:fe,children:e.message}),e.suggestion&&(0,a.jsx)("p",{className:"_1a5iqpb6",children:e.suggestion})]});function Se(e=[],t=[]){return e.length===t.length&&e.every((r,n)=>Object.is(r,t[n]))}var te=class extends d.Component{constructor(...e){super(...e),this.state={caughtDiagnostic:null}}static getDerivedStateFromError(e){return{caughtDiagnostic:(0,m.buildDiagnostic)(e)}}componentDidCatch(e,t){const r=(0,m.buildDiagnostic)(e);o.logDiagnostics([r]),this.props.onError?.([r]),console.error("Chart render component stack:",t.componentStack)}componentDidUpdate(e){this.state.caughtDiagnostic&&!Se(e.resetKeys,this.props.resetKeys)&&this.setState({caughtDiagnostic:null})}render(){const{caughtDiagnostic:e}=this.state;if(e)return(0,a.jsx)(z,{errors:[e]});const{forcedErrors:t,children:r}=this.props;return t&&t.length>0?(0,a.jsx)(z,{errors:t}):r}},re=e=>typeof e=="object"&&"geom"in e&&"render"in e,ne=e=>{const t=(0,m.resolveDefinition)(e);return t instanceof m.Geom?t:null},se=(e,t)=>{const r=e.filter(n=>ye(n,t));return r.length===e.length?e:r},ye=(e,t)=>e.kind==="annotation"?(0,m.findAnnotation)(t.annotations,e.id)!==null:e.kind==="observations"||e.kind==="layer"&&e.layerId!==void 0?(0,m.findLayerById)(t.layers,e.layerId)!==void 0:!0,X=[],be=()=>(0,Y.createStore)(e=>({selection:X,setSelection:t=>e(r=>Ge(r.selection,t)?r:{selection:t}),clearSelection:()=>e(t=>t.selection.length===0?t:{selection:X})})),Ge=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>{const s=t[n];return s!==void 0&&(0,m.areEditTargetsEqual)(r,s)}),xe=process.env.NODE_ENV!=="production",Ee=5,Te=e=>{if(!xe)return{emit:()=>{},subscribe:()=>Pe,getLastTrigger:()=>null,getLastCompile:()=>null,getCacheStats:()=>e.getCacheStats()};const t=new Set;let r=null;return{emit:n=>{const s=e.getLastCompile();if(s){r=n;for(const c of t)c(n,s)}},subscribe:n=>(t.add(n),()=>{t.delete(n)}),getLastTrigger:()=>r,getLastCompile:()=>e.getLastCompile(),getCacheStats:()=>e.getCacheStats()}},Re=()=>(0,Y.createStore)(e=>({lastCompile:null,history:[],nextId:1,lastSnapshot:null,recordCompile:(t,r)=>e(n=>{if(n.lastSnapshot===r)return n;const s={id:n.nextId,label:Ce(t),stages:r.stages,stageDurationsMs:r.stageDurationsMs,durationMs:r.durationMs};return{lastCompile:s,history:je(n.history,s,Ee),nextId:n.nextId+1,lastSnapshot:r}})})),Pe=()=>{},Ce=e=>{switch(e.kind){case"init":return"init";case"spec":return"spec change";case"data":return"data change";case"command":return e.command.metadata.description}},je=(e,t,r)=>{const n=e.length>=r?e.length-(r-1):0;return[...e.slice(n),t]};function Q(e){const t=e.filter(re),r=new Set([...Object.keys(o.BUILT_IN_GEOM_RENDERERS),...t.map(u=>u.geom)]),n=[],s=new Set;for(const u of e){const h=ne(u);h===null||r.has(h.type)||s.has(h.type)||(s.add(h.type),n.push({kind:"user-input",severity:"error",code:"MISSING_GEOM_RENDERER",message:`Custom geom '${h.type}' is registered but has no renderer.`,context:{requested:h.type,kind:"geom-renderer"},suggestion:`Add a render half for it: \`defineGeomRenderer(${h.type}Geom, { coord, render })\`, then include it in \`plugins\`.`}))}const c=new Map;for(const u of t){if("definition"in u)continue;const h=`${u.geom}|${u.coord}`,p=c.get(h);p?p.count+=1:c.set(h,{geom:u.geom,coord:u.coord,count:1})}const l=[];for(const{geom:u,coord:h,count:p}of c.values())p<2||l.push({kind:"user-input",severity:"warning",code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple render-only overrides register ('${u}', '${h}') (${p} entries); the last in the array wins.`,context:{requested:`${u}@${h}`,kind:"geom-renderer"},suggestion:`Keep a single render-only override for ('${u}', '${h}').`});return l.push(...Me(e)),{errors:n,warnings:l}}function Ne(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n)t(l.geom,r.type)!==null||s.has(l.geom)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"MISSING_GEOM_RENDERER",message:`No renderer for geom '${l.geom}' under ${r.type} coords; the layer is not painted.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:`Register a renderer for ('${l.geom}', '${r.type}') via \`defineGeomRenderer\`.`}));return c}function De(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind!=="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||u.hitTest||o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"MISSING_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares spatialKind 'render-hit-test' but its renderer provides no hit-test; the layer has no hover.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:`Add a \`hitTest\` factory (precomputed geometry) or a live render (\`{ fn, options: { live: true } }\`, live simulation) to the renderer for ('${l.geom}', '${r.type}').`}))}return c}function _e(e){const t=new Set,r=[];for(const n of e.layers){const s=n.identityKey;n.interactive!==!1&&(n.spatialKind!=="render-hit-test"||typeof s!="object"||t.has(n.geom)||n.data.hasVariable(s.variable)||(t.add(n.geom),r.push({kind:"user-input",severity:"warning",code:"RENDER_HIT_TEST_IDENTITY",message:`Geom '${n.geom}' keys its identity on '${s.variable}', a column its compile output does not emit; its hover lookup is empty.`,context:{requested:n.geom,kind:"geom-renderer"},suggestion:`Emit the '${s.variable}' column from the geom's \`compile()\`, or point \`identityKey\` at a column it does emit.`})))}return r}function ke(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind!=="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||!u.hitTest||!o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"CONFLICTING_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares both a \`hitTest\` factory and a live render; these are alternatives, so only the live render is used.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:"Keep one: a `hitTest` factory for precomputed geometry, OR a live render (`{ fn, options: { live: true } }`) for a live simulation."}))}return c}function Ie(e,t){const r=new Set,n=[];for(const s of e.layers)s.interactive!==!1&&(s.spatialKind!=="render-hit-test"||r.has(s.geom)||t.hasCapability(s.geom)||(r.add(s.geom),n.push({kind:"user-input",severity:"warning",code:"MISSING_ANCHOR_CAPABILITY",message:`Geom '${s.geom}' declares no \`resolveAnchorPosition\`; its observations cannot be annotated, so the editor overlay paints no creation trigger on them.`,context:{requested:s.geom,kind:"geom-renderer"},suggestion:"Implement `resolveAnchorPosition(observation, context)` on the geom, returning the normalised panel position an annotation on that observation belongs at."})));return n}function qe(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind==="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||!o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"LIVE_RENDER_REQUIRES_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares a live render but its layer's spatialKind is '${l.spatialKind}', not 'render-hit-test'; its push-path hover resolves to nothing.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:"Have the geom's manifest yield spatialKind 'render-hit-test' so the scene layer carries the `byKey` index the live render's `pushHover` resolves against."}))}return c}function Le(e,t){let r;return e.layers.flatMap((n,s)=>o.isLiveRender(t(n.geom,e.coordSystem.type))?we(n)?(r??=(0,m.createStyleResolver)().readers(e),(r.geom(n).get("overpaint",void 0,"hovered")?.length??0)===0?[]:[{kind:"user-input",severity:"warning",code:"INVALID_STYLE_RULE",message:`Style 'overpaint' in state 'hovered' is not supported on live geom '${n.geom}' (layer '${n.id}'); it is ignored.`,context:{param:"overpaint",layerIndex:s,requested:n.geom},suggestion:"Remove the hovered overpaint, or paint the hover treatment in the geom's live render."}]):[]:[])}var we=e=>[e.styles.defaults,e.styles.overrides].some(t=>t.some(r=>r.state==="hovered"&&(r.declarations.overpaint?.length??0)>0));function Me(e){const t=new Set,r=[];for(const n of e){const s=ne(n);s===null||t.has(s.type)||s.dataLabelCoordTypes.length===0||s.getDataLabelPlacements!==void 0||(t.add(s.type),r.push({kind:"user-input",severity:"warning",code:"MISSING_DATA_LABEL_PLACEMENT",message:`Geom '${s.type}' declares \`dataLabelCoordTypes\` but implements no \`getDataLabelPlacements\`; its layers paint no data labels.`,context:{requested:s.type,kind:"geom-renderer"},suggestion:"Implement `getDataLabelPlacements(context)` on the geom, or drop `dataLabelCoordTypes` so the compiler warns the author off the flag."}))}return r}var He=e=>(0,Y.createStore)(t=>({scene:e,setScene:r=>t(n=>n.scene===r?n:{scene:r})})),$e=({spec:e,data:t,colorScheme:r,plugins:n,theme:s,resolveRenderer:c,anchorResolver:l,onSpecChange:u,onError:h,onWarnings:p})=>{const R=o.useLatestRef(u),P=o.useLatestRef(h),x=o.useLatestRef(p),[{session:f,compileBus:g}]=(0,d.useState)(()=>{const i=(0,m.createCompiler)({plugins:n,theme:s});return{session:new m.GraphCompilationSession(i),compileBus:Te(i)}}),[S]=(0,d.useState)(()=>{const i=Q(n??[]),v=Q(s?.plugins??[]);return{errors:[...v.errors,...i.errors],warnings:[...v.warnings,...i.warnings]}}),E=(0,d.useRef)(null),[y]=(0,d.useState)(Ae),C=(0,d.useRef)(null),D=(0,d.useCallback)(i=>S.errors.length===0?i:[...S.errors,...i??[]],[S]),T=(0,d.useCallback)(i=>{if(!i.ok)return i.errors;if(C.current)C.current.getState().setScene(i.scene);else{const v=He(i.scene);v.subscribe(y.notify),C.current=v,y.notify()}return null},[y]),[M,k]=(0,d.useState)(()=>{const i=f.compile({spec:e,data:t,colorScheme:r});return E.current=i,D(T(i))}),G=(0,d.useCallback)(i=>i.ok?[...i.warnings,...Ne(i.scene,c),...De(i.scene,c),..._e(i.scene),...ke(i.scene,c),...qe(i.scene,c),...Le(i.scene,c),...Ie(i.scene,l)]:i.warnings,[c,l]),j=(0,d.useCallback)(i=>{i.length!==0&&(o.logDiagnostics(i),P.current?.(i))},[P]),N=(0,d.useCallback)(i=>{i.length!==0&&(o.logDiagnostics(i),x.current?.(i))},[x]);(0,d.useEffect)(()=>{const i=E.current;i&&(j([...S.errors,...i.ok?[]:i.errors]),N([...S.warnings,...G(i)]),i.ok&&g.emit({kind:"init"}))},[g,j,N,S,G]),(0,d.useEffect)(()=>{const i=f.update({spec:e,data:t,colorScheme:r});if(!i)return;i.committedSpec&&R.current?.(i.committedSpec);const v=T(i.result);k(D(v)),v&&j(v),N(G(i.result)),v||g.emit({kind:i.specChanged?"spec":"data"})},[e,t,r,f,g,T,j,N,D,G,R]);const I=(0,d.useCallback)(i=>{k(v=>v===null?v:D(null)),N(G(i))},[D,N,G]),H=(0,d.useCallback)(i=>{i.scene&&C.current?.getState().setScene(i.scene),i.result&&I(i.result),i.command&&g.emit({kind:"command",command:i.command}),i.spec&&R.current?.(i.spec),i.errors&&j([...i.errors])},[I,g,R,j]),b=(0,d.useCallback)(i=>{for(const v of i)H(v);return i.some(v=>!!v.scene)},[H]),$=(0,d.useCallback)((i,v)=>{b(f.applyCommand(i,v))},[f,b]),_=(0,d.useCallback)(()=>{b(f.commit())},[f,b]),A=(0,d.useCallback)(()=>b(f.undo()),[f,b]),q=(0,d.useCallback)(()=>b(f.redo()),[f,b]),K=(0,d.useMemo)(()=>({stack:f.history,undo:A,redo:q}),[f,A,q]),he=(0,d.useCallback)(()=>C.current?.getState().scene??null,[]);return{store:C.current,dispatch:$,commit:_,history:K,subscribe:y.subscribe,getScene:he,compileBus:g,compileErrors:M}},Ae=()=>{const e=new Set;return{subscribe:t=>(e.add(t),()=>{e.delete(t)}),notify:()=>e.forEach(t=>t())}},oe=({data:e,spec:t,plugins:r=[],theme:n,formattingLocale:s,handleRef:c,onSpecChange:l,onError:u,onWarnings:h,colorScheme:p="light",children:R})=>{const[P]=(0,d.useState)(()=>n),x=P?.colorScheme??p,[f]=(0,d.useState)(()=>o.createGeomRendererResolver([...P?.plugins??[],...r].filter(re))),g=(0,d.useId)(),[S]=(0,d.useState)(()=>(0,m.createAnchorResolver)(r)),[E]=(0,d.useState)(()=>(0,m.createDataLabelPlacementResolver)(r)),[y]=(0,d.useState)(()=>be()),[C]=(0,d.useState)(()=>o.createTargetBoundaryStore()),D=(0,d.useMemo)(()=>(0,m.createStyleResolver)({colorScheme:x}),[x]),{store:T,dispatch:M,commit:k,history:G,subscribe:j,getScene:N,compileBus:I,compileErrors:H}=$e({spec:t,data:e,colorScheme:x,plugins:r,theme:P,resolveRenderer:f,anchorResolver:S,onSpecChange:l,onError:u,onWarnings:h});(0,d.useEffect)(()=>{if(T)return T.subscribe((_,A)=>{if(_.scene.spec===A.scene.spec)return;const{selection:q,setSelection:K}=y.getState();q.length!==0&&K(se(q,_.scene.spec))})},[T,y]);const b=(0,d.useMemo)(()=>({dispatch:M,commit:k}),[M,k]);(0,d.useImperativeHandle)(c,()=>({commands:b,undo:G.undo,redo:G.redo,subscribe:j,getScene:N,getSelection:()=>y.getState().selection,setSelection:_=>y.getState().setSelection(_),subscribeSelection:y.subscribe,canPlaceDataLabels:E.hasCapability,canFormatDataLabelsAsPercentages:E.hasPercentageFormat}),[b,G,j,N,y,E]);const $=(0,d.useMemo)(()=>T?{chartId:g,store:T,selectionStore:y,targetBoundaryStore:C,commands:b,history:G,formattingLocale:s,compileBus:I,colorScheme:x,styleResolver:D,anchorResolver:S}:null,[g,T,y,C,b,G,s,I,x,D,S]);return(0,a.jsx)(te,{forcedErrors:H,onError:u,resetKeys:[t,e],children:$?(0,a.jsx)(o.GraphContext.Provider,{value:$,children:(0,a.jsx)(o.GeomRendererResolverProvider,{value:f,children:(0,a.jsx)(o.DataLabelPlacementResolverProvider,{value:E,children:(0,a.jsx)(o.GeomShapesProvider,{shapes:P?.shapes,children:R})})})}):null})};function Be({theme:e,...t}={}){const r=(0,m.createSpecBuilder)(t);return{...r,GraphProvider:s=>(0,a.jsx)(oe,{...s,plugins:r.plugins,theme:e})}}var w=(e,t)=>{if(typeof e!="string"||!e.endsWith("%"))return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r/100*t:null},ae=({x:e,y:t,width:r,height:n},s)=>{const c=w(e,s.width),l=w(t,s.height),u=w(r,s.width),h=w(n,s.height);return c===null||l===null||u===null||h===null?null:{x:c,y:l,width:u,height:h}},ie=({shouldAnimateTransitions:e,cx:t,cy:r,r:n,effects:s,...c})=>{const l=o.toGeomEffectsStyle(s);return e?(0,a.jsx)(O.motion.circle,{initial:!1,animate:{cx:t,cy:r,r:n},transition:o.DEFAULT_SPRING_TRANSITION,style:l,...c}):(0,a.jsx)("circle",{cx:t,cy:r,r:n,style:l,...c})},le=({shouldAnimateTransitions:e,x1:t,y1:r,x2:n,y2:s,effects:c,...l})=>{const u=o.toGeomEffectsStyle(c);return e?(0,a.jsx)(O.motion.line,{initial:!1,animate:{x1:t,y1:r,x2:n,y2:s},transition:o.DEFAULT_SPRING_TRANSITION,style:u,...l}):(0,a.jsx)("line",{x1:t,y1:r,x2:n,y2:s,style:u,...l})},ce=({shouldAnimateTransitions:e,x:t,y:r,width:n,height:s,rx:c,ry:l,effects:u,...h})=>{const p=o.toGeomEffectsStyle(u);return e?(0,a.jsx)(O.motion.rect,{initial:!1,animate:{attrX:t,attrY:r,width:n,height:s,...c!==void 0&&l!==void 0?{rx:c,ry:l}:{}},transition:o.DEFAULT_SPRING_TRANSITION,style:p,...h}):(0,a.jsx)("rect",{x:t,y:r,width:n,height:s,rx:c,ry:l,style:p,...h})},ue=({shouldAnimateTransitions:e,d:t,source:r,effects:n,...s})=>{const c=o.toGeomEffectsStyle(n);return e?(0,a.jsx)(ze,{d:t,source:r,style:c,...s}):(0,a.jsx)("path",{d:t,style:c,...s})},Oe=e=>{const{Circle:t}=o.useGeomShapes();return t===void 0?ie(e):(0,a.jsx)(o.GeomShapesProvider,{children:(0,a.jsx)(t,{...e})})},Ke=e=>{const{Line:t}=o.useGeomShapes();return t===void 0?le(e):(0,a.jsx)(o.GeomShapesProvider,{children:(0,a.jsx)(t,{...e})})},Fe=({cornerRadius:e,...t})=>{const{Rect:r}=o.useGeomShapes(),n=o.useGeomPanelPixelSize(),s=o.useGeomPixelsPerUnit(),c={...t,...Ye(e,t,n,s)};return r===void 0?ce(c):(0,a.jsx)(o.GeomShapesProvider,{children:(0,a.jsx)(r,{...c})})},Ue=e=>{const{Path:t}=o.useGeomShapes();return t===void 0?ue(e):(0,a.jsx)(o.GeomShapesProvider,{children:(0,a.jsx)(t,{...e})})},ze=({d:e,source:t,...r})=>{const n=o.useSvgPathMorph(e,o.DEFAULT_SPRING_TRANSITION,t);return(0,a.jsx)(O.motion.path,{d:n,...r})},Ye=(e,t,r,n)=>{if(e===void 0)return{};const s=We(t,r,n);if(s===null)return e==="full"?{}:J((0,m.resolveGeomCornerRadiusPx)({cornerRadius:e}),n);const c=Math.min((0,m.resolveGeomCornerRadiusPx)({cornerRadius:e,box:s}),Math.min(s.width,s.height)/2);return J(c,n)},We=(e,t,r)=>typeof e.width=="number"&&typeof e.height=="number"?{width:Math.abs(e.width)*r.x,height:Math.abs(e.height)*r.y}:t===null?null:ae(e,t),J=(e,t)=>({rx:e/t.x,ry:e/t.y}),Ve=({children:e,...t})=>{const r=o.useGeomPanelPixelSize();return(0,a.jsx)("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",width:"100%",height:"100%",pointerEvents:"none",...t,children:(0,a.jsx)(o.GeomPanelSizeProvider,{size:r,space:"unit",children:e})})},Xe=({box:e,children:t})=>{const r=o.useGeomPanelSize(),n=r===null?null:r.width*(e.x1-e.x0),s=r===null?null:r.height*(e.y1-e.y0),c=(0,d.useMemo)(()=>n===null||s===null?null:{width:n,height:s},[n,s]);return(0,a.jsx)("svg",{x:(0,m.toPercent)(e.x0),y:(0,m.toPercent)(e.y0),width:(0,m.toPercent)(e.x1-e.x0),height:(0,m.toPercent)(e.y1-e.y0),overflow:"hidden",pointerEvents:"none",children:(0,a.jsx)(o.GeomPanelSizeProvider,{size:c,children:t})})},Qe="drqe3u0",Je="drqe3u1",Ze="drqe3u2",et="drqe3u3",L="drqe3u4",tt="drqe3u5",rt="drqe3u6",nt="drqe3u7",B="drqe3u8",st="drqe3u9",ot="drqe3ua";var at="drqe3uc",it="drqe3ud",lt="drqe3ue",ct="drqe3uf";var ut="drqe3uh",dt="drqe3ui",Z={enabled:"drqe3uk drqe3uj",disabled:"drqe3ul drqe3uj"},ee={ran:"drqe3un drqe3um",dim:"drqe3uo drqe3um"},de={ran:"drqe3uq drqe3up",cached:"drqe3ur drqe3up",untouched:"drqe3us drqe3up"},ht=({width:e=440,style:t,className:r}={})=>{const{compileBus:n}=o.useGraphContext(),[s]=(0,d.useState)(()=>Re()),[c,l]=(0,d.useState)(!1),[u,h]=(0,d.useState)(m.isCompilerCachingEnabled);(0,d.useEffect)(()=>{const{recordCompile:g}=s.getState(),S=n.getLastTrigger(),E=n.getLastCompile();return S&&E&&g(S,E),n.subscribe(g)},[s,n]);const p=(0,F.useStore)(s,g=>g.lastCompile),R=(0,F.useStore)(s,g=>g.history),P=n.getCacheStats(),x=p===null&&R.length===0,f=()=>{h(g=>{const S=!g;return(0,m.setCompilerCachingEnabled)(S),S})};return(0,a.jsxs)("div",{className:(0,U.default)(ot,r),style:{width:e,...t},children:[(0,a.jsxs)("div",{className:Qe,children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:Je,children:"compile cache"}),(0,a.jsx)("div",{className:lt,children:x?"production: stats disabled":p?`last: ${p.label} · ${W(p.durationMs)}`:"awaiting first compile…"})]}),(0,a.jsx)("button",{type:"button",onClick:()=>l(g=>!g),className:ct,children:c?"▾":"▴"})]}),!c&&(0,a.jsxs)("div",{className:"drqe3ub",children:[(0,a.jsxs)("button",{type:"button",onClick:f,className:u?Z.enabled:Z.disabled,"aria-pressed":u,children:["cache ",u?"enabled":"disabled"]}),(0,a.jsx)("span",{className:"drqe3ug",children:"next compile reflects this toggle"})]}),!c&&!x&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(mt,{delta:p?.stages,durations:p?.stageDurationsMs,cumulative:P}),(0,a.jsx)(gt,{entries:R})]})]})},mt=({delta:e,durations:t,cumulative:r})=>(0,a.jsxs)("table",{className:Ze,children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{className:ut,children:[(0,a.jsx)("th",{className:et,children:"stage"}),(0,a.jsx)("th",{className:L,children:"time"}),(0,a.jsx)("th",{className:L,children:"Δ miss"}),(0,a.jsx)("th",{className:L,children:"Δ hit"}),(0,a.jsx)("th",{className:L,children:"total miss"}),(0,a.jsx)("th",{className:L,children:"total hit"})]})}),(0,a.jsx)("tbody",{children:m.COMPILER_STAGE_KEYS.map(n=>{const s=e?.[n],c=pt(s);return(0,a.jsxs)("tr",{className:at,children:[(0,a.jsxs)("td",{className:tt,children:[(0,a.jsx)("span",{className:de[c],"aria-hidden":!0})," ",n]}),(0,a.jsx)("td",{className:B,children:t===void 0||c==="untouched"?"—":W(t[n])}),(0,a.jsx)("td",{className:c==="ran"?ee.ran:ee.dim,children:s?.misses??0}),(0,a.jsx)("td",{className:B,children:s?.hits??0}),(0,a.jsx)("td",{className:B,children:r[n].misses}),(0,a.jsx)("td",{className:B,children:r[n].hits})]},n)})})]}),gt=({entries:e})=>e.length===0?null:(0,a.jsxs)("div",{className:it,children:[(0,a.jsx)("div",{className:dt,children:"recent compiles"}),e.map(t=>{const r=vt(t.stages,c=>c.misses>0),n=m.COMPILER_STAGE_KEYS.length,s=r===0?"cached":"ran";return(0,a.jsxs)("div",{className:rt,children:[(0,a.jsx)("span",{className:de[s],"aria-hidden":!0}),(0,a.jsx)("span",{className:nt,title:t.label,children:t.label}),(0,a.jsxs)("span",{className:st,children:[r,"/",n," ran · ",W(t.durationMs)]})]},t.id)})]}),pt=e=>!e||e.hits===0&&e.misses===0?"untouched":e.misses>0?"ran":"cached",vt=(e,t)=>{let r=0;for(const n of m.COMPILER_STAGE_KEYS)t(e[n])&&(r+=1);return r},W=e=>e<.1?"<0.1ms":e>=10?`${e.toFixed(0)}ms`:`${e.toFixed(2)}ms`,ft=()=>{const{history:e}=o.useGraphContext(),{stack:t,undo:r,redo:n}=e,s=(0,d.useCallback)(u=>t.subscribe(u),[t]),c=(0,d.useCallback)(()=>t.getSnapshot(),[t]),l=(0,d.useSyncExternalStore)(s,c,c);return(0,d.useMemo)(()=>({...l,undo:r,redo:n}),[l,r,n])},St=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]),yt=(e,t={})=>{const{target:r,enabled:n=!0}=t;(0,d.useEffect)(()=>{const s=bt(r);if(!n||!s)return;const c=l=>{if(!Gt(l)||l.defaultPrevented||xt(l.target))return;const u=o.resolveHistoryStep(l);if(!u)return;const h=e.current;h&&(u==="undo"?h.undo():h.redo())&&l.preventDefault()};return s.addEventListener("keydown",c),()=>s.removeEventListener("keydown",c)},[e,r,n])},bt=e=>e===void 0?window:e!==null&&"current"in e?e.current:e,Gt=e=>"key"in e,xt=e=>e instanceof HTMLInputElement?!St.has(e.type):e instanceof HTMLElement?e.isContentEditable||e.tagName==="TEXTAREA":!1,Et=()=>{const{targetBoundaryStore:e}=o.useGraphContext();return(0,F.useStore)(e,t=>t.boundary)};exports.BrandMark=o.BrandMark;exports.CanvasTextMeasurer=o.CanvasTextMeasurer;exports.DefaultFooter=o.DefaultFooter;exports.DefaultGeomCircle=ie;exports.DefaultGeomLine=le;exports.DefaultGeomPath=ue;exports.DefaultGeomRect=ce;exports.DefaultGrid=o.DefaultGrid;exports.DefaultHeader=o.DefaultHeader;exports.DefaultSwatch=o.DefaultSwatch;exports.DefaultTooltip=o.DefaultTooltip;exports.DevToolsPanel=ht;exports.GRAPH_MODES=o.GRAPH_MODES;exports.GeomCircle=Oe;exports.GeomLine=Ke;exports.GeomOverpaint=o.GeomOverpaint;exports.GeomPath=Ue;exports.GeomRect=Fe;exports.GraphErrorBoundary=te;exports.GraphErrorPanel=z;exports.GraphProvider=oe;exports.GraphRenderer=o.GraphRenderer;exports.HoverProvider=o.HoverProvider;exports.IntroFade=o.IntroFade;exports.IntroWipeClip=o.IntroWipeClip;exports.TextMeasurerProvider=o.TextMeasurerProvider;exports.ThemeProvider=o.ThemeProvider;exports.UnitBoxSvg=Xe;exports.UnitSpaceSvg=Ve;exports.buildDotsEditOutlineShapes=o.buildDotsEditOutlineShapes;exports.createGraphyKit=Be;exports.darkTheme=o.darkTheme;exports.defineGeomRenderer=o.defineGeomRenderer;exports.lightTheme=o.lightTheme;exports.lightenCss=o.lightenCss;exports.projectPointCartesian=o.projectPointCartesian;exports.pruneSelection=se;exports.readShapePixelRect=ae;exports.readShapePixels=w;exports.resolveBrandMarkVisual=o.resolveBrandMarkVisual;exports.resolvePathStroke=o.resolvePathStroke;exports.scalePointToPanel=o.scalePointToPanel;exports.stampAxisEditTarget=o.stampAxisEditTarget;exports.stampGridEditTarget=o.stampGridEditTarget;exports.stampLegendEditTarget=o.stampLegendEditTarget;exports.useElementScreenRect=o.useElementScreenRect;exports.useGeomHitTest=o.useGeomHitTest;exports.useGeomHover=o.useGeomHover;exports.useGeomPanelSize=o.useGeomPanelSize;exports.useGeomReaderTree=o.useGeomReaderTree;exports.useGeomStyleReader=o.useGeomStyleReader;exports.useGraphCommands=o.useGraphCommands;exports.useGraphHandle=o.useGraphHandle;exports.useGraphHistory=ft;exports.useGraphHistoryShortcuts=yt;exports.useGraphLocale=o.useGraphLocale;exports.useGraphSelection=o.useGraphSelection;exports.useGuidesTakePress=o.useGuidesTakePress;exports.useHandleScene=o.useHandleScene;exports.useHoverState=o.useHoverState;exports.usePaintDefs=o.usePaintDefs;exports.useResolvedStyle=o.useResolvedStyle;exports.useSceneSelector=o.useSceneSelector;exports.useStyleReaderTree=o.useStyleReaderTree;exports.useStyleResolver=o.useStyleResolver;exports.useTargetBoundary=Et;exports.useTextMeasurer=o.useTextMeasurer;exports.vars=o.vars;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const o=require("./history-chords-Coid8oNw.cjs");let h=require("@graphysdk/viz-engine"),d=require("react"),i=require("react/jsx-runtime"),F=require("zustand"),O=require("motion/react"),Y=require("zustand/vanilla"),U=require("clsx");U=o.__toESM(U,1);var he="_1a5iqpb0",ge="_1a5iqpb1";var pe="_1a5iqpb3",ve="_1a5iqpb4",fe="_1a5iqpb5";var z=({errors:e})=>{const[t,...r]=e;return(0,i.jsxs)("div",{role:"alert",className:he,children:[(0,i.jsx)("strong",{className:ge,children:"This chart could not be rendered."}),t&&(0,i.jsx)(V,{diagnostic:t}),r.length>0&&(0,i.jsx)("ul",{className:"_1a5iqpb2",children:r.map((n,s)=>(0,i.jsx)("li",{children:(0,i.jsx)(V,{diagnostic:n})},`${n.code}-${s}`))})]})},V=({diagnostic:e})=>(0,i.jsxs)("div",{className:pe,children:[(0,i.jsx)("span",{className:ve,children:e.code}),(0,i.jsx)("p",{className:fe,children:e.message}),e.suggestion&&(0,i.jsx)("p",{className:"_1a5iqpb6",children:e.suggestion})]});function Se(e=[],t=[]){return e.length===t.length&&e.every((r,n)=>Object.is(r,t[n]))}var re=class extends d.Component{constructor(...e){super(...e),this.state={caughtDiagnostic:null}}static getDerivedStateFromError(e){return{caughtDiagnostic:(0,h.buildDiagnostic)(e)}}componentDidCatch(e,t){const r=(0,h.buildDiagnostic)(e);o.logDiagnostics([r]),this.props.onError?.([r]),console.error("Chart render component stack:",t.componentStack)}componentDidUpdate(e){this.state.caughtDiagnostic&&!Se(e.resetKeys,this.props.resetKeys)&&this.setState({caughtDiagnostic:null})}render(){const{caughtDiagnostic:e}=this.state;if(e)return(0,i.jsx)(z,{errors:[e]});const{forcedErrors:t,children:r}=this.props;return t&&t.length>0?(0,i.jsx)(z,{errors:t}):r}},ne=e=>typeof e=="object"&&"geom"in e&&"render"in e,se=e=>{const t=(0,h.resolveDefinition)(e);return t instanceof h.Geom?t:null},oe=(e,t)=>{const r=e.filter(n=>ye(n,t));return r.length===e.length?e:r},ye=(e,t)=>e.kind==="annotation"?(0,h.findAnnotation)(t.annotations,e.id)!==null:e.kind==="observations"||e.kind==="layer"&&e.layerId!==void 0?(0,h.findLayerById)(t.layers,e.layerId)!==void 0:!0,X=[],be=()=>(0,Y.createStore)(e=>({selection:X,setSelection:t=>e(r=>Ge(r.selection,t)?r:{selection:t}),clearSelection:()=>e(t=>t.selection.length===0?t:{selection:X})})),Ge=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>{const s=t[n];return s!==void 0&&(0,h.areEditTargetsEqual)(r,s)}),xe=process.env.NODE_ENV!=="production",Ee=5,Te=e=>{if(!xe)return{emit:()=>{},subscribe:()=>Pe,getLastTrigger:()=>null,getLastCompile:()=>null,getCacheStats:()=>e.getCacheStats()};const t=new Set;let r=null;return{emit:n=>{const s=e.getLastCompile();if(s){r=n;for(const c of t)c(n,s)}},subscribe:n=>(t.add(n),()=>{t.delete(n)}),getLastTrigger:()=>r,getLastCompile:()=>e.getLastCompile(),getCacheStats:()=>e.getCacheStats()}},Re=()=>(0,Y.createStore)(e=>({lastCompile:null,history:[],nextId:1,lastSnapshot:null,recordCompile:(t,r)=>e(n=>{if(n.lastSnapshot===r)return n;const s={id:n.nextId,label:Ce(t),stages:r.stages,stageDurationsMs:r.stageDurationsMs,durationMs:r.durationMs};return{lastCompile:s,history:je(n.history,s,Ee),nextId:n.nextId+1,lastSnapshot:r}})})),Pe=()=>{},Ce=e=>{switch(e.kind){case"init":return"init";case"spec":return"spec change";case"data":return"data change";case"command":return e.command.metadata.description}},je=(e,t,r)=>{const n=e.length>=r?e.length-(r-1):0;return[...e.slice(n),t]};function Q(e){const t=e.filter(ne),r=new Set([...Object.keys(o.BUILT_IN_GEOM_RENDERERS),...t.map(u=>u.geom)]),n=[],s=new Set;for(const u of e){const m=se(u);m===null||r.has(m.type)||s.has(m.type)||(s.add(m.type),n.push({kind:"user-input",severity:"error",code:"MISSING_GEOM_RENDERER",message:`Custom geom '${m.type}' is registered but has no renderer.`,context:{requested:m.type,kind:"geom-renderer"},suggestion:`Add a render half for it: \`defineGeomRenderer(${m.type}Geom, { coord, render })\`, then include it in \`plugins\`.`}))}const c=new Map;for(const u of t){if("definition"in u)continue;const m=`${u.geom}|${u.coord}`,p=c.get(m);p?p.count+=1:c.set(m,{geom:u.geom,coord:u.coord,count:1})}const l=[];for(const{geom:u,coord:m,count:p}of c.values())p<2||l.push({kind:"user-input",severity:"warning",code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple render-only overrides register ('${u}', '${m}') (${p} entries); the last in the array wins.`,context:{requested:`${u}@${m}`,kind:"geom-renderer"},suggestion:`Keep a single render-only override for ('${u}', '${m}').`});return l.push(...Me(e)),{errors:n,warnings:l}}function Ne(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n)t(l.geom,r.type)!==null||s.has(l.geom)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"MISSING_GEOM_RENDERER",message:`No renderer for geom '${l.geom}' under ${r.type} coords; the layer is not painted.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:`Register a renderer for ('${l.geom}', '${r.type}') via \`defineGeomRenderer\`.`}));return c}function De(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind!=="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||u.hitTest||o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"MISSING_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares spatialKind 'render-hit-test' but its renderer provides no hit-test; the layer has no hover.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:`Add a \`hitTest\` factory (precomputed geometry) or a live render (\`{ fn, options: { live: true } }\`, live simulation) to the renderer for ('${l.geom}', '${r.type}').`}))}return c}function _e(e){const t=new Set,r=[];for(const n of e.layers){const s=n.identityKey;n.interactive!==!1&&(n.spatialKind!=="render-hit-test"||typeof s!="object"||t.has(n.geom)||n.data.hasVariable(s.variable)||(t.add(n.geom),r.push({kind:"user-input",severity:"warning",code:"RENDER_HIT_TEST_IDENTITY",message:`Geom '${n.geom}' keys its identity on '${s.variable}', a column its compile output does not emit; its hover lookup is empty.`,context:{requested:n.geom,kind:"geom-renderer"},suggestion:`Emit the '${s.variable}' column from the geom's \`compile()\`, or point \`identityKey\` at a column it does emit.`})))}return r}function ke(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind!=="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||!u.hitTest||!o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"CONFLICTING_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares both a \`hitTest\` factory and a live render; these are alternatives, so only the live render is used.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:"Keep one: a `hitTest` factory for precomputed geometry, OR a live render (`{ fn, options: { live: true } }`) for a live simulation."}))}return c}function Ie(e,t){const r=new Set,n=[];for(const s of e.layers)s.interactive!==!1&&(s.spatialKind!=="render-hit-test"||r.has(s.geom)||t.hasCapability(s.geom)||(r.add(s.geom),n.push({kind:"user-input",severity:"warning",code:"MISSING_ANCHOR_CAPABILITY",message:`Geom '${s.geom}' declares no \`resolveAnchorPosition\`; its observations cannot be annotated, so the editor overlay paints no creation trigger on them.`,context:{requested:s.geom,kind:"geom-renderer"},suggestion:"Implement `resolveAnchorPosition(observation, context)` on the geom, returning the normalised panel position an annotation on that observation belongs at."})));return n}function qe(e,t){const{coordSystem:r,layers:n}=e,s=new Set,c=[];for(const l of n){if(l.interactive===!1||l.spatialKind==="render-hit-test"||s.has(l.geom))continue;const u=t(l.geom,r.type);u===null||!o.isLiveRender(u)||(s.add(l.geom),c.push({kind:"user-input",severity:"warning",code:"LIVE_RENDER_REQUIRES_RENDER_HIT_TEST",message:`Geom '${l.geom}' declares a live render but its layer's spatialKind is '${l.spatialKind}', not 'render-hit-test'; its push-path hover resolves to nothing.`,context:{requested:l.geom,kind:"geom-renderer"},suggestion:"Have the geom's manifest yield spatialKind 'render-hit-test' so the scene layer carries the `byKey` index the live render's `pushHover` resolves against."}))}return c}function Le(e,t){let r;return e.layers.flatMap((n,s)=>o.isLiveRender(t(n.geom,e.coordSystem.type))?we(n)?(r??=(0,h.createStyleResolver)().readers(e),(r.geom(n).get("overpaint",void 0,"hovered")?.length??0)===0?[]:[{kind:"user-input",severity:"warning",code:"INVALID_STYLE_RULE",message:`Style 'overpaint' in state 'hovered' is not supported on live geom '${n.geom}' (layer '${n.id}'); it is ignored.`,context:{param:"overpaint",layerIndex:s,requested:n.geom},suggestion:"Remove the hovered overpaint, or paint the hover treatment in the geom's live render."}]):[]:[])}var we=e=>[e.styles.defaults,e.styles.overrides].some(t=>t.some(r=>r.state==="hovered"&&(r.declarations.overpaint?.length??0)>0));function Me(e){const t=new Set,r=[];for(const n of e){const s=se(n);s===null||t.has(s.type)||s.dataLabelCoordTypes.length===0||s.getDataLabelPlacements!==void 0||(t.add(s.type),r.push({kind:"user-input",severity:"warning",code:"MISSING_DATA_LABEL_PLACEMENT",message:`Geom '${s.type}' declares \`dataLabelCoordTypes\` but implements no \`getDataLabelPlacements\`; its layers paint no data labels.`,context:{requested:s.type,kind:"geom-renderer"},suggestion:"Implement `getDataLabelPlacements(context)` on the geom, or drop `dataLabelCoordTypes` so the compiler warns the author off the flag."}))}return r}var He=e=>(0,Y.createStore)(t=>({scene:e,setScene:r=>t(n=>n.scene===r?n:{scene:r})})),$e=({spec:e,data:t,colorScheme:r,plugins:n,theme:s,resolveRenderer:c,anchorResolver:l,onSpecChange:u,onError:m,onWarnings:p})=>{const R=o.useLatestRef(u),P=o.useLatestRef(m),x=o.useLatestRef(p),[{session:f,compileBus:g}]=(0,d.useState)(()=>{const a=(0,h.createCompiler)({plugins:n,theme:s});return{session:new h.GraphCompilationSession(a),compileBus:Te(a)}}),[S]=(0,d.useState)(()=>{const a=Q(n??[]),v=Q(s?.plugins??[]);return{errors:[...v.errors,...a.errors],warnings:[...v.warnings,...a.warnings]}}),E=(0,d.useRef)(null),[y]=(0,d.useState)(Ae),C=(0,d.useRef)(null),D=(0,d.useCallback)(a=>S.errors.length===0?a:[...S.errors,...a??[]],[S]),T=(0,d.useCallback)(a=>{if(!a.ok)return a.errors;if(C.current)C.current.getState().setScene(a.scene);else{const v=He(a.scene);v.subscribe(y.notify),C.current=v,y.notify()}return null},[y]),[M,I]=(0,d.useState)(()=>{const a=f.compile({spec:e,data:t,colorScheme:r});return E.current=a,D(T(a))}),G=(0,d.useCallback)(a=>a.ok?[...a.warnings,...Ne(a.scene,c),...De(a.scene,c),..._e(a.scene),...ke(a.scene,c),...qe(a.scene,c),...Le(a.scene,c),...Ie(a.scene,l)]:a.warnings,[c,l]),j=(0,d.useCallback)(a=>{a.length!==0&&(o.logDiagnostics(a),P.current?.(a))},[P]),N=(0,d.useCallback)(a=>{a.length!==0&&(o.logDiagnostics(a),x.current?.(a))},[x]);(0,d.useEffect)(()=>{const a=E.current;a&&(j([...S.errors,...a.ok?[]:a.errors]),N([...S.warnings,...G(a)]),a.ok&&g.emit({kind:"init"}))},[g,j,N,S,G]),(0,d.useEffect)(()=>{const a=f.update({spec:e,data:t,colorScheme:r});if(!a)return;a.committedSpec&&R.current?.(a.committedSpec);const v=T(a.result);I(D(v)),v&&j(v),N(G(a.result)),v||g.emit({kind:a.specChanged?"spec":"data"})},[e,t,r,f,g,T,j,N,D,G,R]);const q=(0,d.useCallback)(a=>{I(v=>v===null?v:D(null)),N(G(a))},[D,N,G]),H=(0,d.useCallback)(a=>{a.scene&&C.current?.getState().setScene(a.scene),a.result&&q(a.result),a.command&&g.emit({kind:"command",command:a.command}),a.spec&&R.current?.(a.spec),a.errors&&j([...a.errors])},[q,g,R,j]),b=(0,d.useCallback)(a=>{for(const v of a)H(v);return a.some(v=>!!v.scene)},[H]),$=(0,d.useCallback)((a,v)=>{b(f.applyCommand(a,v))},[f,b]),_=(0,d.useCallback)(()=>{b(f.commit())},[f,b]),A=(0,d.useCallback)(()=>b(f.undo()),[f,b]),L=(0,d.useCallback)(()=>b(f.redo()),[f,b]),K=(0,d.useMemo)(()=>({stack:f.history,undo:A,redo:L}),[f,A,L]),me=(0,d.useCallback)(()=>C.current?.getState().scene??null,[]);return{store:C.current,dispatch:$,commit:_,history:K,subscribe:y.subscribe,getScene:me,compileBus:g,compileErrors:M}},Ae=()=>{const e=new Set;return{subscribe:t=>(e.add(t),()=>{e.delete(t)}),notify:()=>e.forEach(t=>t())}},ie=({data:e,spec:t,plugins:r=[],theme:n,formattingLocale:s,handleRef:c,onSpecChange:l,onError:u,onWarnings:m,colorScheme:p="light",children:R})=>{const[P]=(0,d.useState)(()=>n),x=P?.colorScheme??p,[f]=(0,d.useState)(()=>o.createGeomRendererResolver([...P?.plugins??[],...r].filter(ne))),g=(0,d.useId)(),[S]=(0,d.useState)(()=>(0,h.createAnchorResolver)(r)),[E]=(0,d.useState)(()=>(0,h.createDataLabelPlacementResolver)(r)),[y]=(0,d.useState)(()=>be()),[C]=(0,d.useState)(()=>o.createTargetBoundaryStore()),D=(0,d.useMemo)(()=>(0,h.createStyleResolver)({colorScheme:x}),[x]),{store:T,dispatch:M,commit:I,history:G,subscribe:j,getScene:N,compileBus:q,compileErrors:H}=$e({spec:t,data:e,colorScheme:x,plugins:r,theme:P,resolveRenderer:f,anchorResolver:S,onSpecChange:l,onError:u,onWarnings:m});(0,d.useEffect)(()=>{if(T)return T.subscribe((_,A)=>{if(_.scene.spec===A.scene.spec)return;const{selection:L,setSelection:K}=y.getState();L.length!==0&&K(oe(L,_.scene.spec))})},[T,y]);const b=(0,d.useMemo)(()=>({dispatch:M,commit:I}),[M,I]);(0,d.useImperativeHandle)(c,()=>({commands:b,undo:G.undo,redo:G.redo,subscribe:j,getScene:N,getSelection:()=>y.getState().selection,setSelection:_=>y.getState().setSelection(_),subscribeSelection:y.subscribe,canPlaceDataLabels:E.hasCapability,canFormatDataLabelsAsPercentages:E.hasPercentageFormat}),[b,G,j,N,y,E]);const $=(0,d.useMemo)(()=>T?{chartId:g,store:T,selectionStore:y,targetBoundaryStore:C,commands:b,history:G,formattingLocale:s,compileBus:q,colorScheme:x,styleResolver:D,anchorResolver:S}:null,[g,T,y,C,b,G,s,q,x,D,S]);return(0,i.jsx)(re,{forcedErrors:H,onError:u,resetKeys:[t,e],children:$?(0,i.jsx)(o.GraphContext.Provider,{value:$,children:(0,i.jsx)(o.GeomRendererResolverProvider,{value:f,children:(0,i.jsx)(o.DataLabelPlacementResolverProvider,{value:E,children:(0,i.jsx)(o.GeomShapesProvider,{shapes:P?.shapes,children:R})})})}):null})};function Be({theme:e,...t}={}){const r=(0,h.createSpecBuilder)(t);return{...r,GraphProvider:s=>(0,i.jsx)(ie,{...s,plugins:r.plugins,theme:e})}}var k=(e,t)=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(!e.endsWith("%"))return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r/100*t:null},Oe=({x:e,y:t,width:r,height:n},s)=>{const c=k(e,s.width),l=k(t,s.height),u=k(r,s.width),m=k(n,s.height);return c===null||l===null||u===null||m===null?null:{x:c,y:l,width:u,height:m}},ae=({shouldAnimateTransitions:e,cx:t,cy:r,r:n,effects:s,...c})=>{const l=o.toGeomEffectsStyle(s);return e?(0,i.jsx)(O.motion.circle,{initial:!1,animate:{cx:t,cy:r,r:n},transition:o.DEFAULT_SPRING_TRANSITION,style:l,...c}):(0,i.jsx)("circle",{cx:t,cy:r,r:n,style:l,...c})},le=({shouldAnimateTransitions:e,x1:t,y1:r,x2:n,y2:s,effects:c,...l})=>{const u=o.toGeomEffectsStyle(c);return e?(0,i.jsx)(O.motion.line,{initial:!1,animate:{x1:t,y1:r,x2:n,y2:s},transition:o.DEFAULT_SPRING_TRANSITION,style:u,...l}):(0,i.jsx)("line",{x1:t,y1:r,x2:n,y2:s,style:u,...l})},ce=({shouldAnimateTransitions:e,x:t,y:r,width:n,height:s,rx:c,ry:l,effects:u,...m})=>{const p=o.toGeomEffectsStyle(u);return e?(0,i.jsx)(O.motion.rect,{initial:!1,animate:{attrX:t,attrY:r,width:n,height:s,...c!==void 0&&l!==void 0?{rx:c,ry:l}:{}},transition:o.DEFAULT_SPRING_TRANSITION,style:p,...m}):(0,i.jsx)("rect",{x:t,y:r,width:n,height:s,rx:c,ry:l,style:p,...m})},ue=({shouldAnimateTransitions:e,d:t,source:r,effects:n,...s})=>{const c=o.toGeomEffectsStyle(n);return e?(0,i.jsx)(Ye,{d:t,source:r,style:c,...s}):(0,i.jsx)("path",{d:t,style:c,...s})},Ke=e=>{const{Circle:t}=o.useGeomShapes();return t===void 0?ae(e):(0,i.jsx)(o.GeomShapesProvider,{children:(0,i.jsx)(t,{...e})})},Fe=e=>{const{Line:t}=o.useGeomShapes();return t===void 0?le(e):(0,i.jsx)(o.GeomShapesProvider,{children:(0,i.jsx)(t,{...e})})},Ue=({cornerRadius:e,...t})=>{const{Rect:r}=o.useGeomShapes(),n=o.useGeomPanelPixelSize(),s=o.useGeomPixelsPerUnit(),c={...t,...We(e,t,n,s)};return r===void 0?ce(c):(0,i.jsx)(o.GeomShapesProvider,{children:(0,i.jsx)(r,{...c})})},ze=e=>{const{Path:t}=o.useGeomShapes();return t===void 0?ue(e):(0,i.jsx)(o.GeomShapesProvider,{children:(0,i.jsx)(t,{...e})})},Ye=({d:e,source:t,...r})=>{const n=o.useSvgPathMorph(e,o.DEFAULT_SPRING_TRANSITION,t);return(0,i.jsx)(O.motion.path,{d:n,...r})},We=(e,t,r,n)=>{if(e===void 0)return{};const s=Ve(t,r,n);if(s===null)return e==="full"?{}:Z((0,h.resolveGeomCornerRadiusPx)({cornerRadius:e}),n);const c=Math.min((0,h.resolveGeomCornerRadiusPx)({cornerRadius:e,box:s}),Math.min(s.width,s.height)/2);return Z(c,n)},Ve=(e,t,r)=>{const n=J(e.width,t?.width,r.x),s=J(e.height,t?.height,r.y);return n===null||s===null?null:{width:n,height:s}},J=(e,t,r)=>{if(typeof e=="number")return Number.isFinite(e)?Math.abs(e)*r:null;if(t===void 0)return null;const n=k(e,t);return n===null?null:Math.abs(n)},Z=(e,t)=>t.x<=0||t.y<=0?{rx:0,ry:0}:{rx:e/t.x,ry:e/t.y},Xe=({children:e,...t})=>{const r=o.useGeomPanelPixelSize();return(0,i.jsx)("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",width:"100%",height:"100%",pointerEvents:"none",...t,children:(0,i.jsx)(o.GeomPanelSizeProvider,{size:r,space:"unit",children:e})})},Qe=({box:e,children:t})=>{const r=o.useGeomPanelSize(),n=r===null?null:r.width*(e.x1-e.x0),s=r===null?null:r.height*(e.y1-e.y0),c=(0,d.useMemo)(()=>n===null||s===null?null:{width:n,height:s},[n,s]);return(0,i.jsx)("svg",{x:(0,h.toPercent)(e.x0),y:(0,h.toPercent)(e.y0),width:(0,h.toPercent)(e.x1-e.x0),height:(0,h.toPercent)(e.y1-e.y0),overflow:"hidden",pointerEvents:"none",children:(0,i.jsx)(o.GeomPanelSizeProvider,{size:c,children:t})})},Je="drqe3u0",Ze="drqe3u1",et="drqe3u2",tt="drqe3u3",w="drqe3u4",rt="drqe3u5",nt="drqe3u6",st="drqe3u7",B="drqe3u8",ot="drqe3u9",it="drqe3ua";var at="drqe3uc",lt="drqe3ud",ct="drqe3ue",ut="drqe3uf";var dt="drqe3uh",mt="drqe3ui",ee={enabled:"drqe3uk drqe3uj",disabled:"drqe3ul drqe3uj"},te={ran:"drqe3un drqe3um",dim:"drqe3uo drqe3um"},de={ran:"drqe3uq drqe3up",cached:"drqe3ur drqe3up",untouched:"drqe3us drqe3up"},ht=({width:e=440,style:t,className:r}={})=>{const{compileBus:n}=o.useGraphContext(),[s]=(0,d.useState)(()=>Re()),[c,l]=(0,d.useState)(!1),[u,m]=(0,d.useState)(h.isCompilerCachingEnabled);(0,d.useEffect)(()=>{const{recordCompile:g}=s.getState(),S=n.getLastTrigger(),E=n.getLastCompile();return S&&E&&g(S,E),n.subscribe(g)},[s,n]);const p=(0,F.useStore)(s,g=>g.lastCompile),R=(0,F.useStore)(s,g=>g.history),P=n.getCacheStats(),x=p===null&&R.length===0,f=()=>{m(g=>{const S=!g;return(0,h.setCompilerCachingEnabled)(S),S})};return(0,i.jsxs)("div",{className:(0,U.default)(it,r),style:{width:e,...t},children:[(0,i.jsxs)("div",{className:Je,children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:Ze,children:"compile cache"}),(0,i.jsx)("div",{className:ct,children:x?"production: stats disabled":p?`last: ${p.label} · ${W(p.durationMs)}`:"awaiting first compile…"})]}),(0,i.jsx)("button",{type:"button",onClick:()=>l(g=>!g),className:ut,children:c?"▾":"▴"})]}),!c&&(0,i.jsxs)("div",{className:"drqe3ub",children:[(0,i.jsxs)("button",{type:"button",onClick:f,className:u?ee.enabled:ee.disabled,"aria-pressed":u,children:["cache ",u?"enabled":"disabled"]}),(0,i.jsx)("span",{className:"drqe3ug",children:"next compile reflects this toggle"})]}),!c&&!x&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(gt,{delta:p?.stages,durations:p?.stageDurationsMs,cumulative:P}),(0,i.jsx)(pt,{entries:R})]})]})},gt=({delta:e,durations:t,cumulative:r})=>(0,i.jsxs)("table",{className:et,children:[(0,i.jsx)("thead",{children:(0,i.jsxs)("tr",{className:dt,children:[(0,i.jsx)("th",{className:tt,children:"stage"}),(0,i.jsx)("th",{className:w,children:"time"}),(0,i.jsx)("th",{className:w,children:"Δ miss"}),(0,i.jsx)("th",{className:w,children:"Δ hit"}),(0,i.jsx)("th",{className:w,children:"total miss"}),(0,i.jsx)("th",{className:w,children:"total hit"})]})}),(0,i.jsx)("tbody",{children:h.COMPILER_STAGE_KEYS.map(n=>{const s=e?.[n],c=vt(s);return(0,i.jsxs)("tr",{className:at,children:[(0,i.jsxs)("td",{className:rt,children:[(0,i.jsx)("span",{className:de[c],"aria-hidden":!0})," ",n]}),(0,i.jsx)("td",{className:B,children:t===void 0||c==="untouched"?"—":W(t[n])}),(0,i.jsx)("td",{className:c==="ran"?te.ran:te.dim,children:s?.misses??0}),(0,i.jsx)("td",{className:B,children:s?.hits??0}),(0,i.jsx)("td",{className:B,children:r[n].misses}),(0,i.jsx)("td",{className:B,children:r[n].hits})]},n)})})]}),pt=({entries:e})=>e.length===0?null:(0,i.jsxs)("div",{className:lt,children:[(0,i.jsx)("div",{className:mt,children:"recent compiles"}),e.map(t=>{const r=ft(t.stages,c=>c.misses>0),n=h.COMPILER_STAGE_KEYS.length,s=r===0?"cached":"ran";return(0,i.jsxs)("div",{className:nt,children:[(0,i.jsx)("span",{className:de[s],"aria-hidden":!0}),(0,i.jsx)("span",{className:st,title:t.label,children:t.label}),(0,i.jsxs)("span",{className:ot,children:[r,"/",n," ran · ",W(t.durationMs)]})]},t.id)})]}),vt=e=>!e||e.hits===0&&e.misses===0?"untouched":e.misses>0?"ran":"cached",ft=(e,t)=>{let r=0;for(const n of h.COMPILER_STAGE_KEYS)t(e[n])&&(r+=1);return r},W=e=>e<.1?"<0.1ms":e>=10?`${e.toFixed(0)}ms`:`${e.toFixed(2)}ms`,St=()=>{const{history:e}=o.useGraphContext(),{stack:t,undo:r,redo:n}=e,s=(0,d.useCallback)(u=>t.subscribe(u),[t]),c=(0,d.useCallback)(()=>t.getSnapshot(),[t]),l=(0,d.useSyncExternalStore)(s,c,c);return(0,d.useMemo)(()=>({...l,undo:r,redo:n}),[l,r,n])},yt=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]),bt=(e,t={})=>{const{target:r,enabled:n=!0}=t;(0,d.useEffect)(()=>{const s=Gt(r);if(!n||!s)return;const c=l=>{if(!xt(l)||l.defaultPrevented||Et(l.target))return;const u=o.resolveHistoryStep(l);if(!u)return;const m=e.current;m&&(u==="undo"?m.undo():m.redo())&&l.preventDefault()};return s.addEventListener("keydown",c),()=>s.removeEventListener("keydown",c)},[e,r,n])},Gt=e=>e===void 0?window:e!==null&&"current"in e?e.current:e,xt=e=>"key"in e,Et=e=>e instanceof HTMLInputElement?!yt.has(e.type):e instanceof HTMLElement?e.isContentEditable||e.tagName==="TEXTAREA":!1,Tt=()=>{const{targetBoundaryStore:e}=o.useGraphContext();return(0,F.useStore)(e,t=>t.boundary)};exports.BrandMark=o.BrandMark;exports.CanvasTextMeasurer=o.CanvasTextMeasurer;exports.DefaultFooter=o.DefaultFooter;exports.DefaultGeomCircle=ae;exports.DefaultGeomLine=le;exports.DefaultGeomPath=ue;exports.DefaultGeomRect=ce;exports.DefaultGrid=o.DefaultGrid;exports.DefaultHeader=o.DefaultHeader;exports.DefaultSwatch=o.DefaultSwatch;exports.DefaultTooltip=o.DefaultTooltip;exports.DevToolsPanel=ht;exports.GRAPH_MODES=o.GRAPH_MODES;exports.GeomCircle=Ke;exports.GeomLine=Fe;exports.GeomOverpaint=o.GeomOverpaint;exports.GeomPath=ze;exports.GeomRect=Ue;exports.GraphErrorBoundary=re;exports.GraphErrorPanel=z;exports.GraphProvider=ie;exports.GraphRenderer=o.GraphRenderer;exports.HoverProvider=o.HoverProvider;exports.IntroFade=o.IntroFade;exports.IntroWipeClip=o.IntroWipeClip;exports.TextMeasurerProvider=o.TextMeasurerProvider;exports.ThemeProvider=o.ThemeProvider;exports.UnitBoxSvg=Qe;exports.UnitSpaceSvg=Xe;exports.buildDotsEditOutlineShapes=o.buildDotsEditOutlineShapes;exports.createGraphyKit=Be;exports.darkTheme=o.darkTheme;exports.defineGeomRenderer=o.defineGeomRenderer;exports.lightTheme=o.lightTheme;exports.lightenCss=o.lightenCss;exports.projectPointCartesian=o.projectPointCartesian;exports.pruneSelection=oe;exports.readPositionPixels=k;exports.readRectPixels=Oe;exports.resolveBrandMarkVisual=o.resolveBrandMarkVisual;exports.resolvePathStroke=o.resolvePathStroke;exports.scalePointToPanel=o.scalePointToPanel;exports.stampAxisEditTarget=o.stampAxisEditTarget;exports.stampGridEditTarget=o.stampGridEditTarget;exports.stampLegendEditTarget=o.stampLegendEditTarget;exports.useElementScreenRect=o.useElementScreenRect;exports.useGeomHitTest=o.useGeomHitTest;exports.useGeomHover=o.useGeomHover;exports.useGeomPanelSize=o.useGeomPanelSize;exports.useGeomReaderTree=o.useGeomReaderTree;exports.useGeomStyleReader=o.useGeomStyleReader;exports.useGraphCommands=o.useGraphCommands;exports.useGraphHandle=o.useGraphHandle;exports.useGraphHistory=St;exports.useGraphHistoryShortcuts=bt;exports.useGraphLocale=o.useGraphLocale;exports.useGraphSelection=o.useGraphSelection;exports.useGuidesTakePress=o.useGuidesTakePress;exports.useHandleScene=o.useHandleScene;exports.useHoverState=o.useHoverState;exports.usePaintDefs=o.usePaintDefs;exports.useResolvedStyle=o.useResolvedStyle;exports.useSceneSelector=o.useSceneSelector;exports.useStyleReaderTree=o.useStyleReaderTree;exports.useStyleResolver=o.useStyleResolver;exports.useTargetBoundary=Tt;exports.useTextMeasurer=o.useTextMeasurer;exports.vars=o.vars;
package/dist/index.d.ts CHANGED
@@ -1349,16 +1349,17 @@ export declare const projectPointCartesian: PointProjection;
1349
1349
  export declare const pruneSelection: (selection: readonly EditTarget[], spec: ResolvedSpec) => readonly EditTarget[];
1350
1350
 
1351
1351
  /**
1352
- * A shared rect's box in pixels from the top-left of the panel (or `UnitBoxSvg`) it is drawn in, not from the graph
1353
- * container as a layout rect is. `null` when any side is a unit-space coordinate, as in {@link readShapePixels}.
1352
+ * A position in pixels along a panel `extent` pixels long, in the panel `useGeomPanelSize` gives: a number is
1353
+ * already pixels there, a percentage scales by `extent`. `null` for a non-finite number or a string that holds no
1354
+ * percentage.
1354
1355
  */
1355
- export declare const readShapePixelRect: ({ x, y, width, height }: Pick<GeomRectProps, "x" | "y" | "width" | "height">, panel: BoxSize) => Rect | null;
1356
+ export declare const readPositionPixels: (position: ShapePosition, extent: number) => number | null;
1356
1357
 
1357
1358
  /**
1358
- * A position in pixels along a panel `extent` pixels long. `null` for a unit-space coordinate, which the
1359
- * panel's size does not scale, so a theme shape draws the default there.
1359
+ * A shared rect's box in pixels from the top-left of the panel (or `UnitBoxSvg`) it is drawn in, not from the graph
1360
+ * container as a layout rect is. `null` when any side reads no pixels, as in {@link readPositionPixels}.
1360
1361
  */
1361
- export declare const readShapePixels: (position: ShapePosition, extent: number) => number | null;
1362
+ export declare const readRectPixels: ({ x, y, width, height }: Pick<GeomRectProps, "x" | "y" | "width" | "height">, panel: BoxSize) => Rect | null;
1362
1363
 
1363
1364
  export { RenderHitTester }
1364
1365
 
@@ -1433,8 +1434,8 @@ declare interface SelectionStoreActions {
1433
1434
  export declare type SelectionStoreState = SelectionSlice & SelectionStoreActions;
1434
1435
 
1435
1436
  /**
1436
- * A position in the space the geom paints in: a panel percentage (`'42.5%'`) or a user coordinate
1437
- * inside a unit-space nested SVG. Both sides of a transition must be in the same units to spring.
1437
+ * A position in the space the geom paints in: a panel percentage (`'42.5%'`), panel-local pixels, or a user
1438
+ * coordinate inside a unit-space nested SVG. Both sides of a transition must be in the same units to spring.
1438
1439
  */
1439
1440
  declare type ShapePosition = string | number;
1440
1441
 
@@ -1765,7 +1766,8 @@ export declare function useGeomHover(layerId: string): GeomHoverPush;
1765
1766
  * The pixel size of the panel the shape is drawn in, for a theme shape whose drawing depends on pixels (chalk
1766
1767
  * strokes a set distance apart, a grid of typed characters). `null` outside a geom layer and inside a `UnitSpaceSvg`,
1767
1768
  * whose unit coordinates no pixel size scales. Inside a `UnitBoxSvg` it is the box's size, since a shape's percentages
1768
- * resolve against the nearest `<svg>`.
1769
+ * resolve against the nearest `<svg>`. A hand-written `<svg viewBox>` declares no space, so shapes under it still read
1770
+ * as pixels: draw unit coordinates in a `UnitSpaceSvg`.
1769
1771
  */
1770
1772
  export declare const useGeomPanelSize: () => BoxSize | null;
1771
1773