@graphysdk/react-renderer 2.0.0-beta.1788530029487 → 2.0.0-beta.1788534616557

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 l=require("./history-chords-DcAuPQlE.cjs"),z=require("./dev.utils-CXRlUmw2.cjs");let y=require("@graphysdk/viz-engine"),c=require("react"),i=require("react/jsx-runtime"),Y=require("zustand"),O=require("zustand/vanilla"),P=require("clsx");P=l.__toESM(P,1);function L(e){for(const t of e)(t.severity==="error"?console.error:console.warn)(`[graphy] ${t.code}: ${t.message}`,t)}var ne="_1a5iqpb0",oe="_1a5iqpb1";var ie="_1a5iqpb3",ae="_1a5iqpb4",ce="_1a5iqpb5";var K=({errors:e})=>{const[t,...r]=e;return(0,i.jsxs)("div",{role:"alert",className:ne,children:[(0,i.jsx)("strong",{className:oe,children:"This chart could not be rendered."}),t&&(0,i.jsx)(U,{diagnostic:t}),r.length>0&&(0,i.jsx)("ul",{className:"_1a5iqpb2",children:r.map((s,n)=>(0,i.jsx)("li",{children:(0,i.jsx)(U,{diagnostic:s})},`${s.code}-${n}`))})]})},U=({diagnostic:e})=>(0,i.jsxs)("div",{className:ie,children:[(0,i.jsx)("span",{className:ae,children:e.code}),(0,i.jsx)("p",{className:ce,children:e.message}),e.suggestion&&(0,i.jsx)("p",{className:"_1a5iqpb6",children:e.suggestion})]});function le(e=[],t=[]){return e.length===t.length&&e.every((r,s)=>Object.is(r,t[s]))}var X=class extends c.Component{constructor(...e){super(...e),this.state={caughtDiagnostic:null}}static getDerivedStateFromError(e){return{caughtDiagnostic:(0,y.buildDiagnostic)(e)}}componentDidCatch(e,t){const r=(0,y.buildDiagnostic)(e);L([r]),this.props.onError?.([r]),console.error("Chart render component stack:",t.componentStack)}componentDidUpdate(e){this.state.caughtDiagnostic&&!le(e.resetKeys,this.props.resetKeys)&&this.setState({caughtDiagnostic:null})}render(){const{caughtDiagnostic:e}=this.state;if(e)return(0,i.jsx)(K,{errors:[e]});const{forcedErrors:t,children:r}=this.props;return t&&t.length>0?(0,i.jsx)(K,{errors:t}):r}},Q=e=>typeof e=="object"&&"geom"in e&&"render"in e,de=e=>{const t=(0,y.resolveDefinition)(e);return t instanceof y.Geom?t:null},J=(e,t)=>{const r=e.filter(s=>ue(s,t));return r.length===e.length?e:r},ue=(e,t)=>e.kind!=="annotation"?!0:(0,y.findAnnotation)(t.annotations,e.id)!==null,F=[],me=()=>(0,O.createStore)(e=>({selection:F,setSelection:t=>e(r=>he(r.selection,t)?r:{selection:t}),clearSelection:()=>e(t=>t.selection.length===0?t:{selection:F})})),he=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,s)=>{const n=t[s];return n!==void 0&&(0,y.areEditTargetsEqual)(r,n)}),ge=5,pe=e=>{if(!z.IS_DEV)return{emit:()=>{},subscribe:()=>ve,getLastTrigger:()=>null,getLastCompile:()=>null,getCacheStats:()=>e.getCacheStats()};const t=new Set;let r=null;return{emit:s=>{const n=e.getLastCompile();if(n){r=s;for(const u of t)u(s,n)}},subscribe:s=>(t.add(s),()=>{t.delete(s)}),getLastTrigger:()=>r,getLastCompile:()=>e.getLastCompile(),getCacheStats:()=>e.getCacheStats()}},fe=()=>(0,O.createStore)(e=>({lastCompile:null,history:[],nextId:1,lastSnapshot:null,recordCompile:(t,r)=>e(s=>{if(s.lastSnapshot===r)return s;const n={id:s.nextId,label:ye(t),stages:r.stages,durationMs:r.durationMs};return{lastCompile:n,history:Se(s.history,n,ge),nextId:s.nextId+1,lastSnapshot:r}})})),ve=()=>{},ye=e=>{switch(e.kind){case"init":return"init";case"input":return"input change";case"data":return"data change";case"command":return e.command.metadata.description}},Se=(e,t,r)=>{const s=e.length>=r?e.length-(r-1):0;return[...e.slice(s),t]};function be(e){const t=e.filter(Q),r=new Set([...Object.keys(l.BUILT_IN_GEOM_RENDERERS),...t.map(d=>d.geom)]),s=[],n=new Set;for(const d of e){const m=de(d);m===null||r.has(m.type)||n.has(m.type)||(n.add(m.type),s.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 u=new Map;for(const d of t){if("definition"in d)continue;const m=`${d.geom}|${d.coord}`,g=u.get(m);g?g.count+=1:u.set(m,{geom:d.geom,coord:d.coord,count:1})}const a=[];for(const{geom:d,coord:m,count:g}of u.values())g<2||a.push({kind:"user-input",severity:"warning",code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple render-only overrides register ('${d}', '${m}') (${g} entries); the last in the array wins.`,context:{requested:`${d}@${m}`,kind:"geom-renderer"},suggestion:`Keep a single render-only override for ('${d}', '${m}').`});return{errors:s,warnings:a}}function Ee(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s)t(a.geom,r.type)!==null||n.has(a.geom)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"MISSING_GEOM_RENDERER",message:`No renderer for geom '${a.geom}' under ${r.type} coords; the layer is not painted.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:`Register a renderer for ('${a.geom}', '${r.type}') via \`defineGeomRenderer\`.`}));return u}function Ce(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind!=="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||d.hitTest||l.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"MISSING_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares spatialKind 'render-hit-test' but its renderer provides no hit-test; the layer has no hover.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:`Add a \`hitTest\` factory (precomputed geometry) or an overlay render (\`{ fn, options: { overlay: true } }\`, live simulation) to the renderer for ('${a.geom}', '${r.type}').`}))}return u}function xe(e){const t=new Set,r=[];for(const s of e.layers){const n=s.identityKey;s.interactive!==!1&&(s.spatialKind!=="render-hit-test"||typeof n!="object"||t.has(s.geom)||s.data.hasVariable(n.variable)||(t.add(s.geom),r.push({kind:"user-input",severity:"warning",code:"RENDER_HIT_TEST_IDENTITY",message:`Geom '${s.geom}' keys its identity on '${n.variable}', a column its compile output does not emit; its hover lookup is empty.`,context:{requested:s.geom,kind:"geom-renderer"},suggestion:`Emit the '${n.variable}' column from the geom's \`compile()\`, or point \`identityKey\` at a column it does emit.`})))}return r}function Te(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind!=="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||!d.hitTest||!l.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"CONFLICTING_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares both a \`hitTest\` factory and an overlay render; these are alternatives, so only the overlay is used.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:"Keep one: a `hitTest` factory for precomputed geometry, OR an overlay render (`{ fn, options: { overlay: true } }`) for a live simulation."}))}return u}function Re(e,t){const r=new Set,s=[];for(const n of e.layers)n.interactive!==!1&&(n.spatialKind!=="render-hit-test"||r.has(n.geom)||t.hasCapability(n.geom)||(r.add(n.geom),s.push({kind:"user-input",severity:"warning",code:"MISSING_ANCHOR_CAPABILITY",message:`Geom '${n.geom}' declares no \`resolveAnchorPosition\`; its observations cannot be annotated, so the editor overlay paints no creation trigger on them.`,context:{requested:n.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 s}function qe(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind==="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||!l.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"OVERLAY_REQUIRES_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares an overlay render but its layer's spatialKind is '${a.spatialKind}', not 'render-hit-test'; the overlay's push-path hover resolves to nothing.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:"Have the geom's manifest yield spatialKind 'render-hit-test' so the compiled layer carries the `byKey` index the overlay's `pushHover` resolves against."}))}return u}var Ge=e=>(0,O.createStore)(t=>({compiled:e,setCompiled:r=>t(s=>s.compiled===r?s:{compiled:r})})),ke=({input:e,data:t,customPalettes:r,plugins:s,resolveRenderer:n,anchorResolver:u,onChange:a,onError:d,onWarnings:m})=>{const g=l.useLatestRef(a),q=l.useLatestRef(d),j=l.useLatestRef(m),[{session:p,compileBus:b}]=(0,c.useState)(()=>{const o=(0,y.createCompiler)({plugins:s});return{session:new y.GraphCompilationSession(o),compileBus:pe(o)}}),[h]=(0,c.useState)(()=>be(s??[])),f=(0,c.useRef)(null),[S]=(0,c.useState)(Ne),x=(0,c.useRef)(null),G=(0,c.useCallback)(o=>h.errors.length===0?o:[...h.errors,...o??[]],[h]),T=(0,c.useCallback)(o=>{if(!o.ok)return o.errors;if(x.current)x.current.getState().setCompiled(o.compiled);else{const v=Ge(o.compiled);v.subscribe(S.notify),x.current=v,S.notify()}return null},[S]),[I,_]=(0,c.useState)(()=>{const o=p.compile({input:e,data:t,customPalettes:r});return f.current=o,G(T(o))}),R=(0,c.useCallback)(o=>o.ok?[...o.warnings,...Ee(o.compiled,n),...Ce(o.compiled,n),...xe(o.compiled),...Te(o.compiled,n),...qe(o.compiled,n),...Re(o.compiled,u)]:o.warnings,[n,u]),k=(0,c.useCallback)(o=>{o.length!==0&&(L(o),q.current?.(o))},[q]),E=(0,c.useCallback)(o=>{o.length!==0&&(L(o),j.current?.(o))},[j]);(0,c.useEffect)(()=>{const o=f.current;o&&(k([...h.errors,...o.ok?[]:o.errors]),E([...h.warnings,...R(o)]),o.ok&&b.emit({kind:"init"}))},[b,k,E,h,R]),(0,c.useEffect)(()=>{const o=p.update({input:e,data:t,customPalettes:r});if(!o)return;o.sealedInput&&g.current?.(o.sealedInput);const v=T(o.result);_(G(v)),v&&k(v),E(R(o.result)),v||b.emit({kind:o.inputChanged?"input":"data"})},[e,t,r,p,b,T,k,E,G,R,g]);const D=(0,c.useCallback)(o=>{_(v=>v===null?v:G(null)),E(R(o))},[G,E,R]),N=(0,c.useCallback)(o=>{o.compiled&&x.current?.getState().setCompiled(o.compiled),o.result&&D(o.result),o.command&&b.emit({kind:"command",command:o.command}),o.input&&g.current?.(o.input),o.errors&&k([...o.errors])},[D,b,g,k]),C=(0,c.useCallback)(o=>{for(const v of o)N(v);return o.some(v=>!!v.compiled)},[N]),w=(0,c.useCallback)((o,v)=>{C(p.applyCommand(o,v))},[p,C]),M=(0,c.useCallback)(()=>{C(p.seal())},[p,C]),B=(0,c.useCallback)(()=>C(p.undo()),[p,C]),A=(0,c.useCallback)(()=>C(p.redo()),[p,C]),re=(0,c.useMemo)(()=>({stack:p.history,undo:B,redo:A}),[p,B,A]),se=(0,c.useCallback)(()=>x.current?.getState().compiled??null,[]);return{store:x.current,dispatch:w,seal:M,history:re,subscribe:S.subscribe,getCompiled:se,compileBus:b,compileErrors:I}},Ne=()=>{const e=new Set;return{subscribe:t=>(e.add(t),()=>{e.delete(t)}),notify:()=>e.forEach(t=>t())}},je={},Z=({data:e,input:t,plugins:r=[],formattingLocale:s,handleRef:n,onChange:u,onError:a,onWarnings:d,customPalettes:m,colorScheme:g="light",themeOverrides:q=je,children:j})=>{const[p]=(0,c.useState)(()=>l.createGeomRendererResolver(r.filter(Q))),b=(0,c.useId)(),[h]=(0,c.useState)(()=>(0,y.createAnchorResolver)(r)),[f]=(0,c.useState)(()=>me()),{store:S,dispatch:x,seal:G,history:T,subscribe:I,getCompiled:_,compileBus:R,compileErrors:k}=ke({input:t,data:e,customPalettes:m,plugins:r,resolveRenderer:p,anchorResolver:h,onChange:u,onError:a,onWarnings:d});(0,c.useEffect)(()=>{if(S)return S.subscribe((N,C)=>{if(N.compiled.spec===C.compiled.spec)return;const{selection:w,setSelection:M}=f.getState();w.length!==0&&M(J(w,N.compiled.spec))})},[S,f]);const E=(0,c.useMemo)(()=>({dispatch:x,seal:G}),[x,G]);(0,c.useImperativeHandle)(n,()=>({commands:E,undo:T.undo,redo:T.redo,subscribe:I,getCompiled:_,getSelection:()=>f.getState().selection,setSelection:N=>f.getState().setSelection(N),subscribeSelection:f.subscribe}),[E,T,I,_,f]);const D=(0,c.useMemo)(()=>S?{chartId:b,store:S,selectionStore:f,commands:E,history:T,formattingLocale:s,compileBus:R,colorScheme:g,themeOverrides:q,anchorResolver:h}:null,[b,S,f,E,T,s,R,g,q,h]);return(0,i.jsx)(X,{forcedErrors:k,onError:a,resetKeys:[t,e],children:D?(0,i.jsx)(l.GraphContext.Provider,{value:D,children:(0,i.jsx)(l.GeomRendererResolverProvider,{value:p,children:j})}):null})};function _e(e){const t=(0,y.createGraphyBuilder)(e);return{...t,GraphProvider:s=>(0,i.jsx)(Z,{...s,plugins:t.plugins})}}var De=({children:e,...t})=>(0,i.jsx)("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",width:"100%",height:"100%",pointerEvents:"none",...t,children:e}),Ie="drqe3u0",we="drqe3u1",He="drqe3u2",Me="drqe3u3",H="drqe3u4",$e="drqe3u5",Pe="drqe3u6",Le="drqe3u7",$="drqe3u8",Ke="drqe3u9",Oe="drqe3ua";var Be="drqe3uc",Ae="drqe3ud",Ye="drqe3ue",Ue="drqe3uf";var Fe="drqe3uh",Ve="drqe3ui",V={enabled:"drqe3uk drqe3uj",disabled:"drqe3ul drqe3uj"},W={ran:"drqe3un drqe3um",dim:"drqe3uo drqe3um"},ee={ran:"drqe3uq drqe3up",cached:"drqe3ur drqe3up",untouched:"drqe3us drqe3up"},We=({width:e=380,style:t,className:r}={})=>{const{compileBus:s}=l.useGraphContext(),[n]=(0,c.useState)(()=>fe()),[u,a]=(0,c.useState)(!1),[d,m]=(0,c.useState)(y.isCompilerCachingEnabled);(0,c.useEffect)(()=>{const{recordCompile:h}=n.getState(),f=s.getLastTrigger(),S=s.getLastCompile();return f&&S&&h(f,S),s.subscribe(h)},[n,s]);const g=(0,Y.useStore)(n,h=>h.lastCompile),q=(0,Y.useStore)(n,h=>h.history),j=s.getCacheStats(),p=g===null&&q.length===0,b=()=>{m(h=>{const f=!h;return(0,y.setCompilerCachingEnabled)(f),f})};return(0,i.jsxs)("div",{className:(0,P.default)(Oe,r),style:{width:e,...t},children:[(0,i.jsxs)("div",{className:Ie,children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:we,children:"compile cache"}),(0,i.jsx)("div",{className:Ye,children:p?"production: stats disabled":g?`last: ${g.label} · ${te(g.durationMs)}`:"awaiting first compile…"})]}),(0,i.jsx)("button",{type:"button",onClick:()=>a(h=>!h),className:Ue,children:u?"▾":"▴"})]}),!u&&(0,i.jsxs)("div",{className:"drqe3ub",children:[(0,i.jsxs)("button",{type:"button",onClick:b,className:d?V.enabled:V.disabled,"aria-pressed":d,children:["cache ",d?"enabled":"disabled"]}),(0,i.jsx)("span",{className:"drqe3ug",children:"next compile reflects this toggle"})]}),!u&&!p&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(ze,{delta:g?.stages,cumulative:j}),(0,i.jsx)(Xe,{entries:q})]})]})},ze=({delta:e,cumulative:t})=>(0,i.jsxs)("table",{className:He,children:[(0,i.jsx)("thead",{children:(0,i.jsxs)("tr",{className:Fe,children:[(0,i.jsx)("th",{className:Me,children:"stage"}),(0,i.jsx)("th",{className:H,children:"Δ miss"}),(0,i.jsx)("th",{className:H,children:"Δ hit"}),(0,i.jsx)("th",{className:H,children:"total miss"}),(0,i.jsx)("th",{className:H,children:"total hit"})]})}),(0,i.jsx)("tbody",{children:y.COMPILER_STAGE_KEYS.map(r=>{const s=e?.[r],n=Qe(s);return(0,i.jsxs)("tr",{className:Be,children:[(0,i.jsxs)("td",{className:$e,children:[(0,i.jsx)("span",{className:ee[n],"aria-hidden":!0})," ",r]}),(0,i.jsx)("td",{className:n==="ran"?W.ran:W.dim,children:s?.misses??0}),(0,i.jsx)("td",{className:$,children:s?.hits??0}),(0,i.jsx)("td",{className:$,children:t[r].misses}),(0,i.jsx)("td",{className:$,children:t[r].hits})]},r)})})]}),Xe=({entries:e})=>e.length===0?null:(0,i.jsxs)("div",{className:Ae,children:[(0,i.jsx)("div",{className:Ve,children:"recent compiles"}),e.map(t=>{const r=Je(t.stages,u=>u.misses>0),s=y.COMPILER_STAGE_KEYS.length,n=r===0?"cached":"ran";return(0,i.jsxs)("div",{className:Pe,children:[(0,i.jsx)("span",{className:ee[n],"aria-hidden":!0}),(0,i.jsx)("span",{className:Le,title:t.label,children:t.label}),(0,i.jsxs)("span",{className:Ke,children:[r,"/",s," ran · ",te(t.durationMs)]})]},t.id)})]}),Qe=e=>!e||e.hits===0&&e.misses===0?"untouched":e.misses>0?"ran":"cached",Je=(e,t)=>{let r=0;for(const s of y.COMPILER_STAGE_KEYS)t(e[s])&&(r+=1);return r},te=e=>e>=10?`${e.toFixed(0)}ms`:`${e.toFixed(2)}ms`,Ze=()=>{const{history:e}=l.useGraphContext(),{stack:t,undo:r,redo:s}=e,n=(0,c.useCallback)(d=>t.subscribe(d),[t]),u=(0,c.useCallback)(()=>t.getSnapshot(),[t]),a=(0,c.useSyncExternalStore)(n,u,u);return(0,c.useMemo)(()=>({...a,undo:r,redo:s}),[a,r,s])},et=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]),tt=(e,t={})=>{const{target:r,enabled:s=!0}=t;(0,c.useEffect)(()=>{const n=rt(r);if(!s||!n)return;const u=a=>{if(!st(a)||a.defaultPrevented||nt(a.target))return;const d=l.resolveHistoryStep(a);if(!d)return;const m=e.current;m&&(d==="undo"?m.undo():m.redo())&&a.preventDefault()};return n.addEventListener("keydown",u),()=>n.removeEventListener("keydown",u)},[e,r,s])},rt=e=>e===void 0?window:e!==null&&"current"in e?e.current:e,st=e=>"key"in e,nt=e=>e instanceof HTMLInputElement?!et.has(e.type):e instanceof HTMLElement?e.isContentEditable||e.tagName==="TEXTAREA":!1;exports.BrandMark=l.BrandMark;exports.CanvasTextMeasurer=l.CanvasTextMeasurer;exports.DefaultFooter=l.DefaultFooter;exports.DefaultGrid=l.DefaultGrid;exports.DefaultHeader=l.DefaultHeader;exports.DefaultSwatch=l.DefaultSwatch;exports.DefaultTooltip=l.DefaultTooltip;exports.DevToolsPanel=We;exports.GraphErrorBoundary=X;exports.GraphErrorPanel=K;exports.GraphProvider=Z;exports.GraphRenderer=l.GraphRenderer;exports.HoverProvider=l.HoverProvider;exports.TextMeasurerProvider=l.TextMeasurerProvider;exports.ThemeProvider=l.ThemeProvider;exports.UnitSpaceSvg=De;exports.createGraphyKit=_e;exports.darkTheme=l.darkTheme;exports.defineGeomRenderer=l.defineGeomRenderer;exports.lightTheme=l.lightTheme;exports.lightenCss=l.lightenCss;exports.pruneSelection=J;exports.resolveBrandMarkVisual=l.resolveBrandMarkVisual;exports.useCompiledSelector=l.useCompiledSelector;exports.useElementScreenRect=l.useElementScreenRect;exports.useGeomHitTest=l.useGeomHitTest;exports.useGeomHover=l.useGeomHover;exports.useGraphCommands=l.useGraphCommands;exports.useGraphHandle=l.useGraphHandle;exports.useGraphHistory=Ze;exports.useGraphHistoryShortcuts=tt;exports.useGraphSelection=l.useGraphSelection;exports.useHandleCompiled=l.useHandleCompiled;exports.useHoverState=l.useHoverState;exports.useTextMeasurer=l.useTextMeasurer;exports.vars=z.vars;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const c=require("./history-chords-Dn-_MJlI.cjs"),z=require("./dev.utils-CXRlUmw2.cjs");let y=require("@graphysdk/viz-engine"),l=require("react"),i=require("react/jsx-runtime"),Y=require("zustand"),O=require("zustand/vanilla"),P=require("clsx");P=c.__toESM(P,1);function L(e){for(const t of e)(t.severity==="error"?console.error:console.warn)(`[graphy] ${t.code}: ${t.message}`,t)}var ne="_1a5iqpb0",oe="_1a5iqpb1";var ie="_1a5iqpb3",ae="_1a5iqpb4",ce="_1a5iqpb5";var K=({errors:e})=>{const[t,...r]=e;return(0,i.jsxs)("div",{role:"alert",className:ne,children:[(0,i.jsx)("strong",{className:oe,children:"This chart could not be rendered."}),t&&(0,i.jsx)(U,{diagnostic:t}),r.length>0&&(0,i.jsx)("ul",{className:"_1a5iqpb2",children:r.map((s,n)=>(0,i.jsx)("li",{children:(0,i.jsx)(U,{diagnostic:s})},`${s.code}-${n}`))})]})},U=({diagnostic:e})=>(0,i.jsxs)("div",{className:ie,children:[(0,i.jsx)("span",{className:ae,children:e.code}),(0,i.jsx)("p",{className:ce,children:e.message}),e.suggestion&&(0,i.jsx)("p",{className:"_1a5iqpb6",children:e.suggestion})]});function le(e=[],t=[]){return e.length===t.length&&e.every((r,s)=>Object.is(r,t[s]))}var X=class extends l.Component{constructor(...e){super(...e),this.state={caughtDiagnostic:null}}static getDerivedStateFromError(e){return{caughtDiagnostic:(0,y.buildDiagnostic)(e)}}componentDidCatch(e,t){const r=(0,y.buildDiagnostic)(e);L([r]),this.props.onError?.([r]),console.error("Chart render component stack:",t.componentStack)}componentDidUpdate(e){this.state.caughtDiagnostic&&!le(e.resetKeys,this.props.resetKeys)&&this.setState({caughtDiagnostic:null})}render(){const{caughtDiagnostic:e}=this.state;if(e)return(0,i.jsx)(K,{errors:[e]});const{forcedErrors:t,children:r}=this.props;return t&&t.length>0?(0,i.jsx)(K,{errors:t}):r}},Q=e=>typeof e=="object"&&"geom"in e&&"render"in e,de=e=>{const t=(0,y.resolveDefinition)(e);return t instanceof y.Geom?t:null},J=(e,t)=>{const r=e.filter(s=>ue(s,t));return r.length===e.length?e:r},ue=(e,t)=>e.kind!=="annotation"?!0:(0,y.findAnnotation)(t.annotations,e.id)!==null,F=[],me=()=>(0,O.createStore)(e=>({selection:F,setSelection:t=>e(r=>he(r.selection,t)?r:{selection:t}),clearSelection:()=>e(t=>t.selection.length===0?t:{selection:F})})),he=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,s)=>{const n=t[s];return n!==void 0&&(0,y.areEditTargetsEqual)(r,n)}),ge=5,pe=e=>{if(!z.IS_DEV)return{emit:()=>{},subscribe:()=>ve,getLastTrigger:()=>null,getLastCompile:()=>null,getCacheStats:()=>e.getCacheStats()};const t=new Set;let r=null;return{emit:s=>{const n=e.getLastCompile();if(n){r=s;for(const u of t)u(s,n)}},subscribe:s=>(t.add(s),()=>{t.delete(s)}),getLastTrigger:()=>r,getLastCompile:()=>e.getLastCompile(),getCacheStats:()=>e.getCacheStats()}},fe=()=>(0,O.createStore)(e=>({lastCompile:null,history:[],nextId:1,lastSnapshot:null,recordCompile:(t,r)=>e(s=>{if(s.lastSnapshot===r)return s;const n={id:s.nextId,label:ye(t),stages:r.stages,durationMs:r.durationMs};return{lastCompile:n,history:Se(s.history,n,ge),nextId:s.nextId+1,lastSnapshot:r}})})),ve=()=>{},ye=e=>{switch(e.kind){case"init":return"init";case"input":return"input change";case"data":return"data change";case"command":return e.command.metadata.description}},Se=(e,t,r)=>{const s=e.length>=r?e.length-(r-1):0;return[...e.slice(s),t]};function be(e){const t=e.filter(Q),r=new Set([...Object.keys(c.BUILT_IN_GEOM_RENDERERS),...t.map(d=>d.geom)]),s=[],n=new Set;for(const d of e){const m=de(d);m===null||r.has(m.type)||n.has(m.type)||(n.add(m.type),s.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 u=new Map;for(const d of t){if("definition"in d)continue;const m=`${d.geom}|${d.coord}`,g=u.get(m);g?g.count+=1:u.set(m,{geom:d.geom,coord:d.coord,count:1})}const a=[];for(const{geom:d,coord:m,count:g}of u.values())g<2||a.push({kind:"user-input",severity:"warning",code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple render-only overrides register ('${d}', '${m}') (${g} entries); the last in the array wins.`,context:{requested:`${d}@${m}`,kind:"geom-renderer"},suggestion:`Keep a single render-only override for ('${d}', '${m}').`});return{errors:s,warnings:a}}function Ee(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s)t(a.geom,r.type)!==null||n.has(a.geom)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"MISSING_GEOM_RENDERER",message:`No renderer for geom '${a.geom}' under ${r.type} coords; the layer is not painted.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:`Register a renderer for ('${a.geom}', '${r.type}') via \`defineGeomRenderer\`.`}));return u}function Ce(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind!=="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||d.hitTest||c.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"MISSING_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares spatialKind 'render-hit-test' but its renderer provides no hit-test; the layer has no hover.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:`Add a \`hitTest\` factory (precomputed geometry) or an overlay render (\`{ fn, options: { overlay: true } }\`, live simulation) to the renderer for ('${a.geom}', '${r.type}').`}))}return u}function xe(e){const t=new Set,r=[];for(const s of e.layers){const n=s.identityKey;s.interactive!==!1&&(s.spatialKind!=="render-hit-test"||typeof n!="object"||t.has(s.geom)||s.data.hasVariable(n.variable)||(t.add(s.geom),r.push({kind:"user-input",severity:"warning",code:"RENDER_HIT_TEST_IDENTITY",message:`Geom '${s.geom}' keys its identity on '${n.variable}', a column its compile output does not emit; its hover lookup is empty.`,context:{requested:s.geom,kind:"geom-renderer"},suggestion:`Emit the '${n.variable}' column from the geom's \`compile()\`, or point \`identityKey\` at a column it does emit.`})))}return r}function Te(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind!=="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||!d.hitTest||!c.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"CONFLICTING_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares both a \`hitTest\` factory and an overlay render; these are alternatives, so only the overlay is used.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:"Keep one: a `hitTest` factory for precomputed geometry, OR an overlay render (`{ fn, options: { overlay: true } }`) for a live simulation."}))}return u}function Re(e,t){const r=new Set,s=[];for(const n of e.layers)n.interactive!==!1&&(n.spatialKind!=="render-hit-test"||r.has(n.geom)||t.hasCapability(n.geom)||(r.add(n.geom),s.push({kind:"user-input",severity:"warning",code:"MISSING_ANCHOR_CAPABILITY",message:`Geom '${n.geom}' declares no \`resolveAnchorPosition\`; its observations cannot be annotated, so the editor overlay paints no creation trigger on them.`,context:{requested:n.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 s}function qe(e,t){const{coordSystem:r,layers:s}=e,n=new Set,u=[];for(const a of s){if(a.interactive===!1||a.spatialKind==="render-hit-test"||n.has(a.geom))continue;const d=t(a.geom,r.type);d===null||!c.isOverlayHosted(d)||(n.add(a.geom),u.push({kind:"user-input",severity:"warning",code:"OVERLAY_REQUIRES_RENDER_HIT_TEST",message:`Geom '${a.geom}' declares an overlay render but its layer's spatialKind is '${a.spatialKind}', not 'render-hit-test'; the overlay's push-path hover resolves to nothing.`,context:{requested:a.geom,kind:"geom-renderer"},suggestion:"Have the geom's manifest yield spatialKind 'render-hit-test' so the compiled layer carries the `byKey` index the overlay's `pushHover` resolves against."}))}return u}var Ge=e=>(0,O.createStore)(t=>({compiled:e,setCompiled:r=>t(s=>s.compiled===r?s:{compiled:r})})),ke=({input:e,data:t,customPalettes:r,plugins:s,resolveRenderer:n,anchorResolver:u,onChange:a,onError:d,onWarnings:m})=>{const g=c.useLatestRef(a),q=c.useLatestRef(d),j=c.useLatestRef(m),[{session:p,compileBus:b}]=(0,l.useState)(()=>{const o=(0,y.createCompiler)({plugins:s});return{session:new y.GraphCompilationSession(o),compileBus:pe(o)}}),[h]=(0,l.useState)(()=>be(s??[])),f=(0,l.useRef)(null),[S]=(0,l.useState)(Ne),x=(0,l.useRef)(null),G=(0,l.useCallback)(o=>h.errors.length===0?o:[...h.errors,...o??[]],[h]),T=(0,l.useCallback)(o=>{if(!o.ok)return o.errors;if(x.current)x.current.getState().setCompiled(o.compiled);else{const v=Ge(o.compiled);v.subscribe(S.notify),x.current=v,S.notify()}return null},[S]),[I,_]=(0,l.useState)(()=>{const o=p.compile({input:e,data:t,customPalettes:r});return f.current=o,G(T(o))}),R=(0,l.useCallback)(o=>o.ok?[...o.warnings,...Ee(o.compiled,n),...Ce(o.compiled,n),...xe(o.compiled),...Te(o.compiled,n),...qe(o.compiled,n),...Re(o.compiled,u)]:o.warnings,[n,u]),k=(0,l.useCallback)(o=>{o.length!==0&&(L(o),q.current?.(o))},[q]),E=(0,l.useCallback)(o=>{o.length!==0&&(L(o),j.current?.(o))},[j]);(0,l.useEffect)(()=>{const o=f.current;o&&(k([...h.errors,...o.ok?[]:o.errors]),E([...h.warnings,...R(o)]),o.ok&&b.emit({kind:"init"}))},[b,k,E,h,R]),(0,l.useEffect)(()=>{const o=p.update({input:e,data:t,customPalettes:r});if(!o)return;o.sealedInput&&g.current?.(o.sealedInput);const v=T(o.result);_(G(v)),v&&k(v),E(R(o.result)),v||b.emit({kind:o.inputChanged?"input":"data"})},[e,t,r,p,b,T,k,E,G,R,g]);const D=(0,l.useCallback)(o=>{_(v=>v===null?v:G(null)),E(R(o))},[G,E,R]),N=(0,l.useCallback)(o=>{o.compiled&&x.current?.getState().setCompiled(o.compiled),o.result&&D(o.result),o.command&&b.emit({kind:"command",command:o.command}),o.input&&g.current?.(o.input),o.errors&&k([...o.errors])},[D,b,g,k]),C=(0,l.useCallback)(o=>{for(const v of o)N(v);return o.some(v=>!!v.compiled)},[N]),w=(0,l.useCallback)((o,v)=>{C(p.applyCommand(o,v))},[p,C]),M=(0,l.useCallback)(()=>{C(p.seal())},[p,C]),B=(0,l.useCallback)(()=>C(p.undo()),[p,C]),A=(0,l.useCallback)(()=>C(p.redo()),[p,C]),re=(0,l.useMemo)(()=>({stack:p.history,undo:B,redo:A}),[p,B,A]),se=(0,l.useCallback)(()=>x.current?.getState().compiled??null,[]);return{store:x.current,dispatch:w,seal:M,history:re,subscribe:S.subscribe,getCompiled:se,compileBus:b,compileErrors:I}},Ne=()=>{const e=new Set;return{subscribe:t=>(e.add(t),()=>{e.delete(t)}),notify:()=>e.forEach(t=>t())}},je={},Z=({data:e,input:t,plugins:r=[],formattingLocale:s,handleRef:n,onChange:u,onError:a,onWarnings:d,customPalettes:m,colorScheme:g="light",themeOverrides:q=je,children:j})=>{const[p]=(0,l.useState)(()=>c.createGeomRendererResolver(r.filter(Q))),b=(0,l.useId)(),[h]=(0,l.useState)(()=>(0,y.createAnchorResolver)(r)),[f]=(0,l.useState)(()=>me()),{store:S,dispatch:x,seal:G,history:T,subscribe:I,getCompiled:_,compileBus:R,compileErrors:k}=ke({input:t,data:e,customPalettes:m,plugins:r,resolveRenderer:p,anchorResolver:h,onChange:u,onError:a,onWarnings:d});(0,l.useEffect)(()=>{if(S)return S.subscribe((N,C)=>{if(N.compiled.spec===C.compiled.spec)return;const{selection:w,setSelection:M}=f.getState();w.length!==0&&M(J(w,N.compiled.spec))})},[S,f]);const E=(0,l.useMemo)(()=>({dispatch:x,seal:G}),[x,G]);(0,l.useImperativeHandle)(n,()=>({commands:E,undo:T.undo,redo:T.redo,subscribe:I,getCompiled:_,getSelection:()=>f.getState().selection,setSelection:N=>f.getState().setSelection(N),subscribeSelection:f.subscribe}),[E,T,I,_,f]);const D=(0,l.useMemo)(()=>S?{chartId:b,store:S,selectionStore:f,commands:E,history:T,formattingLocale:s,compileBus:R,colorScheme:g,themeOverrides:q,anchorResolver:h}:null,[b,S,f,E,T,s,R,g,q,h]);return(0,i.jsx)(X,{forcedErrors:k,onError:a,resetKeys:[t,e],children:D?(0,i.jsx)(c.GraphContext.Provider,{value:D,children:(0,i.jsx)(c.GeomRendererResolverProvider,{value:p,children:j})}):null})};function _e(e){const t=(0,y.createGraphyBuilder)(e);return{...t,GraphProvider:s=>(0,i.jsx)(Z,{...s,plugins:t.plugins})}}var De=({children:e,...t})=>(0,i.jsx)("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",width:"100%",height:"100%",pointerEvents:"none",...t,children:e}),Ie="drqe3u0",we="drqe3u1",He="drqe3u2",Me="drqe3u3",H="drqe3u4",$e="drqe3u5",Pe="drqe3u6",Le="drqe3u7",$="drqe3u8",Ke="drqe3u9",Oe="drqe3ua";var Be="drqe3uc",Ae="drqe3ud",Ye="drqe3ue",Ue="drqe3uf";var Fe="drqe3uh",Ve="drqe3ui",V={enabled:"drqe3uk drqe3uj",disabled:"drqe3ul drqe3uj"},W={ran:"drqe3un drqe3um",dim:"drqe3uo drqe3um"},ee={ran:"drqe3uq drqe3up",cached:"drqe3ur drqe3up",untouched:"drqe3us drqe3up"},We=({width:e=380,style:t,className:r}={})=>{const{compileBus:s}=c.useGraphContext(),[n]=(0,l.useState)(()=>fe()),[u,a]=(0,l.useState)(!1),[d,m]=(0,l.useState)(y.isCompilerCachingEnabled);(0,l.useEffect)(()=>{const{recordCompile:h}=n.getState(),f=s.getLastTrigger(),S=s.getLastCompile();return f&&S&&h(f,S),s.subscribe(h)},[n,s]);const g=(0,Y.useStore)(n,h=>h.lastCompile),q=(0,Y.useStore)(n,h=>h.history),j=s.getCacheStats(),p=g===null&&q.length===0,b=()=>{m(h=>{const f=!h;return(0,y.setCompilerCachingEnabled)(f),f})};return(0,i.jsxs)("div",{className:(0,P.default)(Oe,r),style:{width:e,...t},children:[(0,i.jsxs)("div",{className:Ie,children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:we,children:"compile cache"}),(0,i.jsx)("div",{className:Ye,children:p?"production: stats disabled":g?`last: ${g.label} · ${te(g.durationMs)}`:"awaiting first compile…"})]}),(0,i.jsx)("button",{type:"button",onClick:()=>a(h=>!h),className:Ue,children:u?"▾":"▴"})]}),!u&&(0,i.jsxs)("div",{className:"drqe3ub",children:[(0,i.jsxs)("button",{type:"button",onClick:b,className:d?V.enabled:V.disabled,"aria-pressed":d,children:["cache ",d?"enabled":"disabled"]}),(0,i.jsx)("span",{className:"drqe3ug",children:"next compile reflects this toggle"})]}),!u&&!p&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(ze,{delta:g?.stages,cumulative:j}),(0,i.jsx)(Xe,{entries:q})]})]})},ze=({delta:e,cumulative:t})=>(0,i.jsxs)("table",{className:He,children:[(0,i.jsx)("thead",{children:(0,i.jsxs)("tr",{className:Fe,children:[(0,i.jsx)("th",{className:Me,children:"stage"}),(0,i.jsx)("th",{className:H,children:"Δ miss"}),(0,i.jsx)("th",{className:H,children:"Δ hit"}),(0,i.jsx)("th",{className:H,children:"total miss"}),(0,i.jsx)("th",{className:H,children:"total hit"})]})}),(0,i.jsx)("tbody",{children:y.COMPILER_STAGE_KEYS.map(r=>{const s=e?.[r],n=Qe(s);return(0,i.jsxs)("tr",{className:Be,children:[(0,i.jsxs)("td",{className:$e,children:[(0,i.jsx)("span",{className:ee[n],"aria-hidden":!0})," ",r]}),(0,i.jsx)("td",{className:n==="ran"?W.ran:W.dim,children:s?.misses??0}),(0,i.jsx)("td",{className:$,children:s?.hits??0}),(0,i.jsx)("td",{className:$,children:t[r].misses}),(0,i.jsx)("td",{className:$,children:t[r].hits})]},r)})})]}),Xe=({entries:e})=>e.length===0?null:(0,i.jsxs)("div",{className:Ae,children:[(0,i.jsx)("div",{className:Ve,children:"recent compiles"}),e.map(t=>{const r=Je(t.stages,u=>u.misses>0),s=y.COMPILER_STAGE_KEYS.length,n=r===0?"cached":"ran";return(0,i.jsxs)("div",{className:Pe,children:[(0,i.jsx)("span",{className:ee[n],"aria-hidden":!0}),(0,i.jsx)("span",{className:Le,title:t.label,children:t.label}),(0,i.jsxs)("span",{className:Ke,children:[r,"/",s," ran · ",te(t.durationMs)]})]},t.id)})]}),Qe=e=>!e||e.hits===0&&e.misses===0?"untouched":e.misses>0?"ran":"cached",Je=(e,t)=>{let r=0;for(const s of y.COMPILER_STAGE_KEYS)t(e[s])&&(r+=1);return r},te=e=>e>=10?`${e.toFixed(0)}ms`:`${e.toFixed(2)}ms`,Ze=()=>{const{history:e}=c.useGraphContext(),{stack:t,undo:r,redo:s}=e,n=(0,l.useCallback)(d=>t.subscribe(d),[t]),u=(0,l.useCallback)(()=>t.getSnapshot(),[t]),a=(0,l.useSyncExternalStore)(n,u,u);return(0,l.useMemo)(()=>({...a,undo:r,redo:s}),[a,r,s])},et=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]),tt=(e,t={})=>{const{target:r,enabled:s=!0}=t;(0,l.useEffect)(()=>{const n=rt(r);if(!s||!n)return;const u=a=>{if(!st(a)||a.defaultPrevented||nt(a.target))return;const d=c.resolveHistoryStep(a);if(!d)return;const m=e.current;m&&(d==="undo"?m.undo():m.redo())&&a.preventDefault()};return n.addEventListener("keydown",u),()=>n.removeEventListener("keydown",u)},[e,r,s])},rt=e=>e===void 0?window:e!==null&&"current"in e?e.current:e,st=e=>"key"in e,nt=e=>e instanceof HTMLInputElement?!et.has(e.type):e instanceof HTMLElement?e.isContentEditable||e.tagName==="TEXTAREA":!1;exports.BrandMark=c.BrandMark;exports.CanvasTextMeasurer=c.CanvasTextMeasurer;exports.DefaultFooter=c.DefaultFooter;exports.DefaultGrid=c.DefaultGrid;exports.DefaultHeader=c.DefaultHeader;exports.DefaultSwatch=c.DefaultSwatch;exports.DefaultTooltip=c.DefaultTooltip;exports.DevToolsPanel=We;exports.GraphErrorBoundary=X;exports.GraphErrorPanel=K;exports.GraphProvider=Z;exports.GraphRenderer=c.GraphRenderer;exports.HoverProvider=c.HoverProvider;exports.TextMeasurerProvider=c.TextMeasurerProvider;exports.ThemeProvider=c.ThemeProvider;exports.UnitSpaceSvg=De;exports.createGraphyKit=_e;exports.darkTheme=c.darkTheme;exports.defineGeomRenderer=c.defineGeomRenderer;exports.lightTheme=c.lightTheme;exports.lightenCss=c.lightenCss;exports.pruneSelection=J;exports.resolveBrandMarkVisual=c.resolveBrandMarkVisual;exports.useCompiledSelector=c.useCompiledSelector;exports.useElementScreenRect=c.useElementScreenRect;exports.useGeomHitTest=c.useGeomHitTest;exports.useGeomHover=c.useGeomHover;exports.useGraphCommands=c.useGraphCommands;exports.useGraphHandle=c.useGraphHandle;exports.useGraphHistory=Ze;exports.useGraphHistoryShortcuts=tt;exports.useGraphSelection=c.useGraphSelection;exports.useHandleCompiled=c.useHandleCompiled;exports.useHoverState=c.useHoverState;exports.useStyleReaders=c.useStyleReaders;exports.useTextMeasurer=c.useTextMeasurer;exports.vars=z.vars;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { AnchorPlacement } from '@graphysdk/viz-engine';
2
+ import { AreaStyleReaders } from '@graphysdk/viz-engine';
3
+ import { BarStyleReaders } from '@graphysdk/viz-engine';
2
4
  import { BrandMarkVariant } from '@graphysdk/viz-engine';
3
5
  import { CartesianCoordSystem } from '@graphysdk/viz-engine';
4
6
  import { ColorScheme } from '@graphysdk/viz-engine';
@@ -26,6 +28,7 @@ import { FormattedHeadline } from '@graphysdk/viz-engine';
26
28
  import { FormattedLegend } from '@graphysdk/viz-engine';
27
29
  import { Geom } from '@graphysdk/viz-engine';
28
30
  import { GeomName } from '@graphysdk/viz-engine';
31
+ import { GeomStyleReaders } from '@graphysdk/viz-engine';
29
32
  import { GraphLayout } from '@graphysdk/viz-engine';
30
33
  import { GraphyBuilder } from '@graphysdk/viz-engine';
31
34
  import { HeadlineMeasurer } from '@graphysdk/viz-engine';
@@ -35,12 +38,14 @@ import { IntroStaggerOrder } from '@graphysdk/viz-engine';
35
38
  import { JSX } from 'react/jsx-runtime';
36
39
  import { LayerIntroPlan } from '@graphysdk/viz-engine';
37
40
  import { LayoutEdge } from '@graphysdk/viz-engine';
41
+ import { LineStyleReaders } from '@graphysdk/viz-engine';
38
42
  import { LineStyleType } from '@graphysdk/viz-engine';
39
43
  import { Locale } from '@graphysdk/viz-engine';
40
44
  import { MeasuredText } from '@graphysdk/viz-engine';
41
45
  import { Observation } from '@graphysdk/viz-engine';
42
46
  import { Plugin as Plugin_2 } from '@graphysdk/viz-engine';
43
47
  import { PointerRegion } from '@graphysdk/viz-engine';
48
+ import { PointStyleReaders } from '@graphysdk/viz-engine';
44
49
  import { PolarCoordSystem } from '@graphysdk/viz-engine';
45
50
  import { ReactElement } from 'react';
46
51
  import { ReactNode } from 'react';
@@ -49,6 +54,7 @@ import { Ref } from 'react';
49
54
  import { RefObject } from 'react';
50
55
  import { RenderHitTester } from '@graphysdk/viz-engine';
51
56
  import { ResolvedHeadlineSize } from '@graphysdk/viz-engine';
57
+ import { RuleStyleReaders } from '@graphysdk/viz-engine';
52
58
  import { SourceContent } from '@graphysdk/viz-engine';
53
59
  import { Spec } from '@graphysdk/viz-engine';
54
60
  import { SpecInput } from '@graphysdk/viz-engine';
@@ -320,6 +326,18 @@ export declare interface GeomOverlayRenderInput<G extends GeomName | string = st
320
326
  overlay: InteractiveOverlayApi;
321
327
  }
322
328
 
329
+ /**
330
+ * The cascade paint context every geom render handler receives. Visual readers such as `getColor`
331
+ * see the data tier only; plugin paint should read {@link GeomPaintInput.styleReaders} so tokens,
332
+ * overrides, and the built-in default reach the mark.
333
+ */
334
+ export declare interface GeomPaintInput {
335
+ /** The provider's colour scheme — pass to `createStyleResolver` when a plugin needs readers beyond this layer. */
336
+ colorScheme: ColorScheme;
337
+ /** Cascade readers for this layer: override → data → default, resolved for {@link GeomPaintInput.colorScheme}. */
338
+ styleReaders: GeomStyleReaders;
339
+ }
340
+
323
341
  /**
324
342
  * A geom's `render`: either a plain panel-SVG paint function, or an overlay-hosted one paired with
325
343
  * `options` — so a geom that must paint into the interactive overlay declares
@@ -395,13 +413,13 @@ export declare interface GeomRendererDefinition extends ResolvedGeomRenderer {
395
413
  readonly definition: Geom<unknown>;
396
414
  }
397
415
 
398
- /** A custom geom render handler's input — the base instantiation of the typed built-in inputs. */
416
+ /** A custom geom render handler's input — the base instantiation of the typed built-in inputs, including the style cascade. */
399
417
  export declare type GeomRendererInput = GeomRenderInput;
400
418
 
401
419
  /** A geom's panel-SVG paint function — the plain `render` form. */
402
420
  export declare type GeomRenderFn<G extends GeomName | string = string, C extends CoordKind = CoordKind> = (input: GeomRenderInput<G, C>) => ReactNode;
403
421
 
404
- declare interface GeomRenderInput<G extends GeomName | string = string, C extends CoordKind = CoordKind> {
422
+ declare interface GeomRenderInput<G extends GeomName | string = string, C extends CoordKind = CoordKind> extends GeomPaintInput {
405
423
  layer: CompiledLayerOf<G>;
406
424
  coordSystem: CoordSystemFor<C>;
407
425
  shouldAnimateTransitions: boolean;
@@ -738,7 +756,7 @@ declare interface HighlightRenderInput<G extends GeomName | string = string, C e
738
756
  sourceLayer: CompiledLayerOf<G>;
739
757
  }
740
758
 
741
- declare interface HoverCompanionsRenderInput<G extends GeomName | string = string> {
759
+ declare interface HoverCompanionsRenderInput<G extends GeomName | string = string> extends GeomPaintInput {
742
760
  layer: CompiledLayerOf<G>;
743
761
  primary: HoverHit;
744
762
  related: HoverHit[];
@@ -770,7 +788,7 @@ declare interface HoverProviderProps {
770
788
  children: ReactNode;
771
789
  }
772
790
 
773
- declare interface HoverRenderInput<G extends GeomName | string = string, C extends CoordKind = CoordKind> {
791
+ declare interface HoverRenderInput<G extends GeomName | string = string, C extends CoordKind = CoordKind> extends GeomPaintInput {
774
792
  layer: CompiledLayerOf<G>;
775
793
  coordSystem: CoordSystemFor<C>;
776
794
  primary: HoverHit;
@@ -1231,6 +1249,25 @@ export declare const useHandleCompiled: (handle: GraphHandle) => CompiledSpec |
1231
1249
  */
1232
1250
  export declare function useHoverState<T>(selector: (state: HoverStoreState) => T): T;
1233
1251
 
1252
+ /**
1253
+ * Style readers for a layer, resolving paint through the stylesheet cascade. Takes either a base layer
1254
+ * or a highlight's filtered sub-layer. A known geom kind gets back its own readers (for example
1255
+ * {@link BarStyleReaders}), whose builtin-backed properties resolve NonNullable.
1256
+ *
1257
+ * Plugin paint can also read the same cascade from `input.styleReaders` on the geom render contract.
1258
+ */
1259
+ export declare function useStyleReaders(layer: CompiledLayerFor<'bar'>): BarStyleReaders;
1260
+
1261
+ export declare function useStyleReaders(layer: CompiledLayerFor<'line'>): LineStyleReaders;
1262
+
1263
+ export declare function useStyleReaders(layer: CompiledLayerFor<'area'>): AreaStyleReaders;
1264
+
1265
+ export declare function useStyleReaders(layer: CompiledLayerFor<'point'>): PointStyleReaders;
1266
+
1267
+ export declare function useStyleReaders(layer: CompiledLayerFor<'rule'>): RuleStyleReaders;
1268
+
1269
+ export declare function useStyleReaders(layer: CompiledLayer): GeomStyleReaders;
1270
+
1234
1271
  /** Returns the {@link TextMeasurer} from context; throws outside a `<TextMeasurerProvider>`. */
1235
1272
  export declare const useTextMeasurer: () => TextMeasurer;
1236
1273
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { Ct as kt, M as wt, Mt as It, Nt as ae, O as Dt, Pt as te, St as ce, Tt as $t, X as xt, Y as Ht, _ as Mt, _t as le, a as Pt, bt as de, ct as Lt, gt as K, i as Kt, it as Bt, j as Ot, jt as At, k as jt, lt as Yt, mt as Ft, n as Ut, pt as Wt, r as Vt, rt as Xt, s as Qt, t as ue, tt as zt, vt as Jt, wt as Zt, xt as er, yt as A } from "./history-chords-CbytJGVn.js";
2
- import { f as rr, t as me } from "./dev.utils-CzXWvwtn.js";
1
+ import { Ct as kt, Ft as te, M as wt, Mt as It, Nt as Dt, O as $t, Pt as ae, St as ce, Tt as xt, X as Ht, Y as Mt, _ as Pt, _t as le, a as Lt, bt as de, ct as Kt, gt as K, i as Bt, it as Ot, j as At, jt, k as Yt, lt as Ft, mt as Ut, n as Wt, pt as Vt, r as Xt, rt as Qt, s as zt, t as ue, tt as Jt, vt as Zt, wt as er, xt as tr, yt as A } from "./history-chords-WjboHZs5.js";
2
+ import { f as nr, t as me } from "./dev.utils-CzXWvwtn.js";
3
3
  import { COMPILER_STAGE_KEYS as j, Geom as ge, GraphCompilationSession as he, areEditTargetsEqual as pe, buildDiagnostic as W, createAnchorResolver as fe, createCompiler as ve, createGraphyBuilder as ye, findAnnotation as be, isCompilerCachingEnabled as Se, resolveDefinition as Ee, setCompilerCachingEnabled as Te } from "@graphysdk/viz-engine";
4
4
  import { Component as Ce, useCallback as f, useEffect as $, useId as Ne, useImperativeHandle as Re, useMemo as P, useRef as V, useState as T, useSyncExternalStore as qe } from "react";
5
5
  import { Fragment as Ge, jsx as c, jsxs as v } from "react/jsx-runtime";
@@ -490,7 +490,7 @@ var et = (e) => Y((t) => ({
490
490
  }) : null
491
491
  });
492
492
  };
493
- function lr(e) {
493
+ function dr(e) {
494
494
  const t = ye(e);
495
495
  return {
496
496
  ...t,
@@ -500,7 +500,7 @@ function lr(e) {
500
500
  })
501
501
  };
502
502
  }
503
- var dr = ({ children: e, ...t }) => /* @__PURE__ */ c("svg", {
503
+ var ur = ({ children: e, ...t }) => /* @__PURE__ */ c("svg", {
504
504
  viewBox: "0 0 1 1",
505
505
  preserveAspectRatio: "none",
506
506
  width: "100%",
@@ -520,7 +520,7 @@ var yt = "drqe3uh", bt = "drqe3ui", Z = {
520
520
  ran: "drqe3uq drqe3up",
521
521
  cached: "drqe3ur drqe3up",
522
522
  untouched: "drqe3us drqe3up"
523
- }, ur = ({ width: e = 380, style: t, className: r } = {}) => {
523
+ }, mr = ({ width: e = 380, style: t, className: r } = {}) => {
524
524
  const { compileBus: n } = te(), [o] = T(() => je()), [l, i] = T(!1), [a, d] = T(Se);
525
525
  $(() => {
526
526
  const { recordCompile: u } = o.getState(), h = n.getLastTrigger(), y = n.getLastCompile();
@@ -670,7 +670,7 @@ var yt = "drqe3uh", bt = "drqe3ui", Z = {
670
670
  let r = 0;
671
671
  for (const n of j) t(e[n]) && (r += 1);
672
672
  return r;
673
- }, se = (e) => e >= 10 ? `${e.toFixed(0)}ms` : `${e.toFixed(2)}ms`, mr = () => {
673
+ }, se = (e) => e >= 10 ? `${e.toFixed(0)}ms` : `${e.toFixed(2)}ms`, gr = () => {
674
674
  const { history: e } = te(), { stack: t, undo: r, redo: n } = e, o = f((a) => t.subscribe(a), [t]), l = f(() => t.getSnapshot(), [t]), i = qe(o, l, l);
675
675
  return P(() => ({
676
676
  ...i,
@@ -692,7 +692,7 @@ var yt = "drqe3uh", bt = "drqe3ui", Z = {
692
692
  "range",
693
693
  "reset",
694
694
  "submit"
695
- ]), gr = (e, t = {}) => {
695
+ ]), hr = (e, t = {}) => {
696
696
  const { target: r, enabled: n = !0 } = t;
697
697
  $(() => {
698
698
  const o = Rt(r);
@@ -712,40 +712,41 @@ var yt = "drqe3uh", bt = "drqe3ui", Z = {
712
712
  ]);
713
713
  }, Rt = (e) => e === void 0 ? window : e !== null && "current" in e ? e.current : e, qt = (e) => "key" in e, Gt = (e) => e instanceof HTMLInputElement ? !Nt.has(e.type) : e instanceof HTMLElement ? e.isContentEditable || e.tagName === "TEXTAREA" : !1;
714
714
  export {
715
- Ot as BrandMark,
716
- $t as CanvasTextMeasurer,
717
- jt as DefaultFooter,
718
- Qt as DefaultGrid,
719
- Dt as DefaultHeader,
720
- er as DefaultSwatch,
721
- Ht as DefaultTooltip,
722
- ur as DevToolsPanel,
715
+ At as BrandMark,
716
+ xt as CanvasTextMeasurer,
717
+ Yt as DefaultFooter,
718
+ zt as DefaultGrid,
719
+ $t as DefaultHeader,
720
+ tr as DefaultSwatch,
721
+ Mt as DefaultTooltip,
722
+ mr as DevToolsPanel,
723
723
  He as GraphErrorBoundary,
724
724
  Q as GraphErrorPanel,
725
725
  st as GraphProvider,
726
- Pt as GraphRenderer,
727
- Ft as HoverProvider,
726
+ Lt as GraphRenderer,
727
+ Ut as HoverProvider,
728
728
  kt as TextMeasurerProvider,
729
- zt as ThemeProvider,
730
- dr as UnitSpaceSvg,
731
- lr as createGraphyKit,
732
- Xt as darkTheme,
733
- Jt as defineGeomRenderer,
734
- Bt as lightTheme,
735
- At as lightenCss,
729
+ Jt as ThemeProvider,
730
+ ur as UnitSpaceSvg,
731
+ dr as createGraphyKit,
732
+ Qt as darkTheme,
733
+ Zt as defineGeomRenderer,
734
+ Ot as lightTheme,
735
+ jt as lightenCss,
736
736
  Pe as pruneSelection,
737
737
  wt as resolveBrandMarkVisual,
738
- It as useCompiledSelector,
739
- Yt as useElementScreenRect,
740
- Wt as useGeomHitTest,
741
- Lt as useGeomHover,
742
- Ut as useGraphCommands,
743
- Kt as useGraphHandle,
744
- mr as useGraphHistory,
745
- gr as useGraphHistoryShortcuts,
746
- Mt as useGraphSelection,
747
- Vt as useHandleCompiled,
748
- xt as useHoverState,
749
- Zt as useTextMeasurer,
750
- rr as vars
738
+ Dt as useCompiledSelector,
739
+ Ft as useElementScreenRect,
740
+ Vt as useGeomHitTest,
741
+ Kt as useGeomHover,
742
+ Wt as useGraphCommands,
743
+ Bt as useGraphHandle,
744
+ gr as useGraphHistory,
745
+ hr as useGraphHistoryShortcuts,
746
+ Pt as useGraphSelection,
747
+ Xt as useHandleCompiled,
748
+ Ht as useHoverState,
749
+ It as useStyleReaders,
750
+ er as useTextMeasurer,
751
+ nr as vars
751
752
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "visualization",
12
12
  "renderer"
13
13
  ],
14
- "version": "2.0.0-beta.1788530029487",
14
+ "version": "2.0.0-beta.1788534616557",
15
15
  "type": "module",
16
16
  "sideEffects": [
17
17
  "**/*.css.ts",
@@ -55,7 +55,7 @@
55
55
  "react-colorful": "^5.6.1",
56
56
  "react-intl": "^8.1.3",
57
57
  "zustand": "^5.0.12",
58
- "@graphysdk/viz-engine": "2.0.0-beta.1788530029487"
58
+ "@graphysdk/viz-engine": "2.0.0-beta.1788534616557"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@tiptap/core": "^3.0.0",