@graphysdk/react-renderer 1.9.0-beta.1795708068076 → 1.9.0-beta.1795773309240

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/editable.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./editable.css');const c=require("./history-chords-DDZ_6FBc.cjs"),v=require("./start-arrow-button-DjGnXDVD.cjs");let d=require("@graphysdk/viz-engine"),b=require("react"),a=require("react/jsx-runtime"),ee=require("zustand/react/shallow"),Q=require("lodash-es"),ce=require("@vanilla-extract/dynamic"),_t=require("clsx");_t=c.__toESM(_t,1);let ii=require("react-dom"),je=require("@base-ui/react/popover"),en=require("@base-ui/react/direction-provider"),Ae=require("@base-ui/react/accordion"),si=require("@base-ui/react/separator");var no=(e,t)=>{if(e.scope!=="observation")return null;const n=(0,d.findLayerById)(t.layers,e.layerId);if(n===void 0)return null;const[r]=(0,d.resolveObservationsTarget)({layer:n,target:e,parsingLocale:t.config.parsingLocale});if(r===void 0)return null;const o=n.data.getAt(r);if(o===null)return null;const i=(0,d.createObservationAnchorBuilder)(n)(o);return i===null?null:{layer:n,observation:o,observationIndex:r,at:i}},ro=e=>{const t=c.useSceneSelector((0,ee.useShallow)(n=>({layers:n.layers,config:n.config})));return(0,b.useMemo)(()=>no(e,t),[e,t])},li=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M4 3v12M4 6h12M4 10h10M4 14h8",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),ci=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M14 3v12M2 6h12M4 10h10M6 14h8",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),di=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M2 14 16 4",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),ui=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M2 14C2.5 7 6.1 5.5 16 4",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),hi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M2 8h14M2 8v3M16 8v3",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),pi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...e,children:(0,a.jsx)("path",{d:"M2 8h14M3 8v3M7.3 8v3M11.6 8v3M15 8v3",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round"})}),En={stack:"pr583x0",grid:"pr583x1"},Mn="pr583x2",gi={plain:"pr583x4 pr583x3",withIcon:"pr583x5 pr583x3"},N=({label:e,layout:t="grid",icon:n,children:r})=>{const o=(0,b.useId)(),i=(0,b.useId)();return e===void 0?(0,a.jsx)(v.ControlTooltipArea,{className:En[t],children:(0,a.jsx)("div",{className:Mn,children:r})}):(0,a.jsxs)(v.ControlTooltipArea,{className:En[t],children:[(0,a.jsxs)("label",{id:o,htmlFor:i,className:gi[n===void 0?"plain":"withIcon"],children:[n!==void 0&&(0,a.jsx)("span",{"aria-hidden":"true",children:n}),e]}),(0,a.jsx)("div",{className:Mn,children:(0,a.jsx)(v.RowLabelingProvider,{labelId:o,controlId:i,children:r})})]})},tn=({target:e})=>{const t=c.useGraphHandle();return t===null?null:(0,a.jsx)(mi,{graph:t,axis:e.axis})};tn.hasRows=(e,{scene:t})=>t.coordSystem.type!=="polar";var mi=({graph:e,axis:t})=>{const n=c.useHandleScene(e),r=c.useI18n(),{NumberField:o,TextField:i,ToggleGroup:s}=v.useControls(),l=n?.guides.axes.find(L=>L.scaledAesthetic===t);if((0,b.useEffect)(()=>()=>e.commands.commit(),[e.commands]),n===null||l?.geometry!=="linear")return null;const h=!l.visible,u=l.visible||l.showGrid,p=n.scales[t]?.spec.scaleType,g=p==="continuous"||p==="datetime",m=n.guides.legends.drawn.some(L=>L.position==="left"||L.position==="right"),f=t!=="x"&&p==="continuous"&&(l.position==="left"||l.position==="right")&&!m,x=t==="x"?void 0:n.scales[t]?.spec,y=x?.scaleType==="continuous"?x:void 0,w=y!==void 0&&(l.position==="left"||l.position==="right")&&!(0,d.isZeroAnchoredAxis)(n,t),S=y?.transform==="log"?"log":"linear",I=w&&y.transform!=="log",j=y?.domainMin??null,A=y!==void 0&&(l.position==="left"||l.position==="right")&&y.transform!=="log",T=y?.domainMax??null,M=n.config.axes[t]?.label??l.label??"",G=L=>{const B=t==="ySecondary"?{axis:t,label:L}:{axis:t,label:L};e.commands.dispatch(new d.SetAxisLabelCommand(B),{transient:!0})};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:r("editor.axesPanel.controls.title"),children:(0,a.jsx)(i,{value:M,placeholder:r("editor.axesPanel.controls.titlePlaceholder"),onChange:G,onCommit:e.commands.commit,disabled:h})}),g&&(0,a.jsx)(N,{label:r("editor.axesPanel.controls.labels"),children:(0,a.jsx)(s,{value:l.tickMode,disabled:!u,options:[{value:"auto",label:r("editor.axesPanel.labelMode.auto"),icon:(0,a.jsx)(pi,{})},{value:"edges",label:r("editor.axesPanel.labelMode.edges"),icon:(0,a.jsx)(hi,{})}],onChange:L=>{const B=L==="edges"?"edges":"auto";e.commands.dispatch(new d.SetAxisTickModeCommand({axis:t,tickMode:B,keepSecondaryAxis:!0}))}})}),f&&(0,a.jsx)(N,{label:r("editor.axesPanel.controls.position"),children:(0,a.jsx)(s,{value:l.position,disabled:h,options:[{value:"left",label:r("editor.axesPanel.position.left"),icon:(0,a.jsx)(li,{})},{value:"right",label:r("editor.axesPanel.position.right"),icon:(0,a.jsx)(ci,{})}],onChange:L=>{if(L!=="left"&&L!=="right")return;const B=t==="y"?L:L==="left"?"right":"left";e.commands.dispatch(new d.SetAxisPositionCommand({axis:"y",position:B}))}})}),w&&(0,a.jsx)(N,{label:r("editor.axesPanel.controls.scale"),children:(0,a.jsx)(s,{value:S,options:[{value:"linear",label:r("editor.axesPanel.scale.auto"),icon:(0,a.jsx)(di,{})},{value:"log",label:r("editor.axesPanel.scale.log"),icon:(0,a.jsx)(ui,{})}],onChange:L=>{e.commands.dispatch(new d.SetScaleTransformCommand({scaledAesthetic:t,transform:L==="log"?"log":"linear"}))}})}),I&&(0,a.jsx)(N,{label:r("editor.axesPanel.controls.startFrom"),children:(0,a.jsx)(o,{value:j,placeholder:r("editor.axesPanel.startFrom.auto"),onChange:L=>{e.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:t,domainMin:L}),{transient:!0})},onCommit:e.commands.commit})}),A&&(0,a.jsx)(N,{label:r("editor.axesPanel.controls.endAt"),children:(0,a.jsx)(o,{value:T,placeholder:r("editor.axesPanel.endAt.auto"),onChange:L=>{e.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:t,domainMax:L}),{transient:!0})},onCommit:e.commands.commit})})]})},vi={narrow:3,regular:6,wide:11},xi=({barWidth:e,...t})=>{const n=vi[e];return(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("rect",{x:(18-n)/2,y:3,width:n,height:12,fill:"currentColor"})})},fi=6,re=({target:e})=>{const{commands:t,findGeom:n}=c.useGraphContext(),r=c.useI18n(),o=c.useStyleReaderTree(),i=c.useSceneSelector(p=>p),s=ao(e,i,n);(0,b.useEffect)(()=>()=>t.commit(),[t]);const l=(0,b.useMemo)(()=>(0,d.readObservationsColor)({readers:o,layers:i.layers,target:e,parsingLocale:i.config.parsingLocale}),[o,i.config.parsingLocale,i.layers,e]);if(s===null)return null;const h=(p,g)=>{const m=s[0]?.part;t.dispatch(new d.SetObservationsColorCommand({target:e,color:p,...m===void 0?{}:{part:m}}),g?{transient:!0}:void 0)},u=s[0]?.property==="stroke"?r("editor.overlayMenu.lineColor"):r("editor.overlayMenu.fillColor");return(0,a.jsx)(oo,{label:u,palette:(0,d.readColorChoices)(i.scales.color),selectedColor:l,paint:h,commit:()=>t.commit()})},oo=({label:e,palette:t,selectedColor:n,paint:r,commit:o})=>{const{ColorSwatches:i,CustomColor:s}=v.useControls();return(0,a.jsx)(N,{label:e,layout:"stack",children:(0,a.jsx)(i,{colors:yi(t.slice(0,fi),n),value:n,onChange:l=>r(l,!1),trailing:(0,a.jsx)(s,{variant:"chip",value:n,onChange:l=>r(l,!0),onCommit:o})})})};re.hasRows=(e,{scene:t,findGeom:n})=>ao(e,t,n)!==null;var ao=(e,t,n)=>{if((0,d.findLayerById)(t.layers,e.layerId)===void 0)return null;const r=(0,d.readObservationsColorPart)({layers:t.layers,target:e});return(0,d.readObservationsColorRoute)(t.spec,e,n,r)},yi=(e,t)=>t===null||e.some(n=>v.colorsMatch(n,t))?e:[...e,t],ft=[{name:"narrow",width:.4},{name:"regular",width:.7},{name:"wide",width:.95}],nn=({target:e})=>{const t=c.useSceneSelector(m=>m),n=c.useGraphCommands(),r=c.useI18n(),{ToggleGroup:o}=v.useControls(),i=(0,d.findLayerById)(t.spec.layers,e.layerId),s=(0,d.isLayerSpecOf)(i,"bar")?i:null,l=t.coordSystem.type==="polar"&&t.coordSystem.bandAxis===null,h=m=>{const f=ft.find(({name:x})=>x===m);f!==void 0&&n.dispatch(new d.SetBarWidthCommand({layerId:e.layerId,width:f.width}))},u=ft.map(({name:m})=>({value:m,label:r(`editor.graphPanel.barSection.widths.${m}`),icon:(0,a.jsx)(xi,{barWidth:m})})),p=s===null?null:(0,d.resolveBarBandFraction)(s.params,t.coordSystem.type),g=ft.find(({width:m})=>m===p)?.name??"";return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(re,{target:e}),s!==null&&!l?(0,a.jsx)(N,{label:r("editor.graphPanel.barSection.thickness"),children:(0,a.jsx)(o,{value:g,options:u,onChange:h})}):null]})};nn.hasRows=re.hasRows;var Si={smooth:"M2 13C6 13 7 5 10 5s4 6 6 6",linear:"M2 13l5-8 4 6 5-4"},bi=({curve:e,...t})=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("path",{d:Si[e],stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round"})}),Ci={gap:"M2 12l4-5M12 10l4-4",connect:"M2 12l4-5M6 7l6 3M12 10l4-4",zero:"M2 12l4-5v7h6V10l4-4"},wi=({missingValues:e,...t})=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("path",{d:Ci[e],stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round"})}),On={supportsDataLabels:!1,supportsPosition:!1,supportsPercentages:!1,supportsStackTotals:!1,supportsCategoryLabels:!1},io=(e,t,n)=>{if(!n.hasCapability(e.geom,t)||Ti(e))return On;const{showDataLabels:r}=e.dataLabels,o=e.geom==="bar",i=t==="polar";return{supportsDataLabels:!0,supportsPosition:r,supportsPercentages:r&&n.hasPercentageFormat(e,t),supportsStackTotals:o&&!i&&e.position==="stack",supportsCategoryLabels:o&&i&&e.position==="fill"&&r}},Ti=e=>{const t=(0,d.readVariableName)(e.mapping.color);return e.geom==="tile"&&t!==null&&e.data.getType(t)==="categorical"},so=(e,t)=>{switch(t){case"gap":return e("editor.graphPanel.treatEmptyValues.leaveGap.label");case"zero":return e("editor.graphPanel.treatEmptyValues.fillZero.label");case"connect":return e("editor.graphPanel.treatEmptyValues.connectGaps.label");default:return t}};var Dt=["gap","zero","connect"],rn=(e,t,n)=>{const r=(0,d.findLayerById)(e.spec.layers,n);if(!(0,d.isLayerSpecOf)(r,"line","area"))return null;const o=e.coordSystem.type==="polar",i=(0,d.buildLayerStyleAddress)(r.geom,r.id),s=(0,d.readStyleCoord)(e.spec),l=e.spec.styles.overrides,h=(0,d.combineKindStyleDeclarations)(l,i,s),u=(0,d.combineKindStyleDeclarations)((0,d.readStyleRulesBeneath)(l,i,s),i,s),p=typeof h?.strokeWidth=="number"?h.strokeWidth:null,g=ji(r,e.spec.layers),m=o?[]:Pi(r),f=m.length>1,x=r.geom==="line"&&!o,y=x?ki(e,t,r):0;return{layerId:r.id,showPoints:g!==void 0&&Ai(e,t,g.id),pointLayerId:g?.id??null,showFill:x?y>0:null,drawnFillAlpha:y,smooth:o?null:r.params.curve==="smooth",widthMode:p===null?"auto":"custom",hasUnderlyingStrokeWidth:u?.strokeWidth!==void 0,strokeWidth:p??Ii(e,t,r)??d.DEFAULT_STROKE_WIDTH_PX,missingValues:f?r.params.missingValues:null,missingValueOptions:f?m:[]}},ji=(e,t)=>(0,d.filterLayersByGeoms)(t,"point").find(n=>(0,d.isCompanionLayer)(n,[e])),Ai=(e,t,n)=>{const r=(0,d.findLayerById)(e.layers,n);if(r?.geom!=="point")return!1;const o=t.geom.point(r);return r.data.findFirst(i=>o.get("size",i)>0)!==null},Pi=e=>{const t=["gap","zero"];return e.position!=="stack"&&e.position!=="fill"&&t.push("connect"),e.geom==="area"?t.filter(n=>n!=="gap"):t},Ii=(e,t,n)=>{const r=(0,d.findLayerById)(e.layers,n.id);if(r?.geom==="line")return t.geom.line(r).get("strokeWidth");if(r?.geom==="area")return t.geom.area(r).get("strokeWidth")},ki=(e,t,n)=>{const r=(0,d.findLayerById)(e.layers,n.id);return r?.geom==="line"?t.geom.line(r).get("fillAlpha")??0:0},Li=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M0 11 5.5 5.5 10.5 9 16 4v12H0z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M0 11 5.5 5.5 10.5 9 16 4V0H0z"})]}),Ei=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsxs)("g",{fill:"currentColor",fillOpacity:"0.3",children:[(0,a.jsx)("rect",{width:"3.2",height:"3.5",y:"12.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"2.3",y:"9.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.5",x:"4.267",y:"11.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"3.3",x:"4.267",y:"7.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"2.5",x:"8.533",y:"13.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"1.8",x:"8.533",y:"11",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4",x:"12.8",y:"12",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"2.8",x:"12.8",y:"8.5",rx:".533"})]}),(0,a.jsxs)("g",{fill:"currentColor",fillOpacity:"0.8",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeOpacity:"0.8",strokeWidth:".993",children:[(0,a.jsx)("path",{fill:"none",d:"M1.6 6.2 5.867 3.6l4.266 3.8 4.267-3"}),(0,a.jsx)("circle",{cx:"1.6",cy:"6.2",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"5.867",cy:"3.6",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"10.133",cy:"7.4",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"14.4",cy:"4.4",r:".9",stroke:"none"})]})]}),lo=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"currentColor",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:".993",children:[(0,a.jsxs)("g",{fillOpacity:"0.3",strokeOpacity:"0.3",children:[(0,a.jsx)("path",{fill:"none",d:"M1.4 12.2 6 6.4l4.2 1.2 4.4-4.2"}),(0,a.jsx)("circle",{cx:"1.4",cy:"12.2",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"6.4",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"10.2",cy:"7.6",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"14.6",cy:"3.4",r:".9",stroke:"none"})]}),(0,a.jsxs)("g",{fillOpacity:"0.8",strokeOpacity:"0.8",children:[(0,a.jsx)("path",{fill:"none",d:"M1.4 5.6 6 11.4l4.2-1.2 4.4 1.2"}),(0,a.jsx)("circle",{cx:"1.4",cy:"5.6",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"11.4",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"10.2",cy:"10.2",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"14.6",cy:"11.4",r:".9",stroke:"none"})]})]})}),Mi=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M10.394 12.734 5.63 7.652 0 13.822V16h16V8.741z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M5.744 5.565 0 11.826V8l5.744-6.957 4.718 2.087L16 0v6.957l-5.538 4z"})]}),Oi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{transform:"rotate(90 8 8)",children:[(0,a.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]})}),Ri=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{transform:"rotate(90 8 8)",children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M0 13.037h4.267v2.445a.52.52 0 0 1-.519.518H.518A.52.52 0 0 1 0 15.482zM5.867 7.704h4.266v7.778a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.518-.518zM11.733 10.074H16v5.408a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.519-.518z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M0 12.445h4.267V.52A.52.52 0 0 0 3.748 0H.518A.52.52 0 0 0 0 .519zM5.867 7.111h4.266V.52A.52.52 0 0 0 9.615 0h-3.23a.52.52 0 0 0-.518.519zM11.733 9.481H16V.52A.52.52 0 0 0 15.482 0h-3.23a.52.52 0 0 0-.519.519z"})]})}),_i=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{transform:"rotate(90 8 8)",children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M0 13.037h4.267v2.445a.52.52 0 0 1-.519.518H.518A.52.52 0 0 1 0 15.482zM5.867 7.704h4.266v7.778a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.518-.518zM11.733 10.074H16v5.408a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.519-.518z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M0 7.037c0-.286.232-.518.519-.518h3.23c.286 0 .518.232.518.518v5.408H0zM5.867 7.111h4.266V4.074a.52.52 0 0 0-.518-.518h-3.23a.52.52 0 0 0-.518.518zM11.733 9.481H16V.52A.52.52 0 0 0 15.482 0h-3.23a.52.52 0 0 0-.519.519z"})]})}),Di=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]}),Ni=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M0 13.037h4.267v2.445a.52.52 0 0 1-.519.518H.518A.52.52 0 0 1 0 15.482zM5.867 7.704h4.266v7.778a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.518-.518zM11.733 10.074H16v5.408a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.519-.518z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M0 12.445h4.267V.52A.52.52 0 0 0 3.748 0H.518A.52.52 0 0 0 0 .519zM5.867 7.111h4.266V.52A.52.52 0 0 0 9.615 0h-3.23a.52.52 0 0 0-.518.519zM11.733 9.481H16V.52A.52.52 0 0 0 15.482 0h-3.23a.52.52 0 0 0-.519.519z"})]}),Gi=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M0 13.037h4.267v2.445a.52.52 0 0 1-.519.518H.518A.52.52 0 0 1 0 15.482zM5.867 7.704h4.266v7.778a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.518-.518zM11.733 10.074H16v5.408a.52.52 0 0 1-.518.518h-3.23a.52.52 0 0 1-.519-.518z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.3",d:"M0 7.037c0-.286.232-.518.519-.518h3.23c.286 0 .518.232.518.518v5.408H0zM5.867 7.111h4.266V4.074a.52.52 0 0 0-.518-.518h-3.23a.52.52 0 0 0-.518.518zM11.733 9.481H16V.52A.52.52 0 0 0 15.482 0h-3.23a.52.52 0 0 0-.519.519z"})]}),Bi=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsxs)("g",{fill:"currentColor",fillOpacity:"0.3",children:[(0,a.jsx)("rect",{width:"3.2",height:"6.5",y:"9.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"8.5",x:"4.267",y:"7.5",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"5",x:"8.533",y:"11",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"7.5",x:"12.8",y:"8.5",rx:".533"})]}),(0,a.jsxs)("g",{fill:"currentColor",fillOpacity:"0.8",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeOpacity:"0.8",strokeWidth:".993",children:[(0,a.jsx)("path",{fill:"none",d:"M1.6 6.2 5.867 3.6l4.266 3.8 4.267-3"}),(0,a.jsx)("circle",{cx:"1.6",cy:"6.2",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"5.867",cy:"3.6",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"10.133",cy:"7.4",r:".9",stroke:"none"}),(0,a.jsx)("circle",{cx:"14.4",cy:"4.4",r:".9",stroke:"none"})]})]}),Fi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"5",transform:"rotate(-90 8 8)",children:[(0,a.jsx)("circle",{cx:"8",cy:"8",r:"5.5",pathLength:"100",strokeOpacity:"0.3"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"5.5",pathLength:"100",strokeOpacity:"0.6",strokeDasharray:"25 100"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"5.5",pathLength:"100",strokeOpacity:"0.8",strokeDasharray:"25 100",strokeDashoffset:"-25"})]})}),Hi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"currentColor",children:[(0,a.jsx)("rect",{width:"4.267",height:"4.267",y:"0.533",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"5.867",y:"0.533",fillOpacity:"0.55",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"11.733",y:"0.533",fillOpacity:"0.2",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",y:"5.867",fillOpacity:"0.55",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"5.867",y:"5.867",fillOpacity:"0.9",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"11.733",y:"5.867",fillOpacity:"0.45",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",y:"11.2",fillOpacity:"0.2",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"5.867",y:"11.2",fillOpacity:"0.45",rx:".533"}),(0,a.jsx)("rect",{width:"4.267",height:"4.267",x:"11.733",y:"11.2",fillOpacity:"0.75",rx:".533"})]})}),zi=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("rect",{width:"16",height:"16",fill:"currentColor",fillOpacity:"0.3",rx:"8"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.6",d:"m7.999 16 .412-.01A8 8 0 0 0 8 0z"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.8",d:"M15.999 8a8 8 0 0 1-7.588 7.989l-.412.01V8z"})]}),Wi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"none",stroke:"currentColor",strokeLinejoin:"round",children:[(0,a.jsx)("polygon",{points:"8,0.5 15.13,5.68 12.41,14.07 3.59,14.07 0.87,5.68",strokeOpacity:"0.3",strokeWidth:".8"}),(0,a.jsx)("polygon",{points:"8,2.5 14.66,5.84 10.06,10.83 4.47,12.85 3.72,6.61",strokeOpacity:"0.8",strokeWidth:"1.2"})]})}),Vi=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("polygon",{points:"8,0.5 15.13,5.68 12.41,14.07 3.59,14.07 0.87,5.68",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeOpacity:"0.3",strokeWidth:".8"}),(0,a.jsx)("polygon",{points:"8,2.5 14.66,5.84 10.06,10.83 4.47,12.85 3.72,6.61",fill:"currentColor",fillOpacity:"0.6"})]}),Ki=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.5",transform:"rotate(-90 8 8)",children:[(0,a.jsxs)("g",{strokeOpacity:"0.2",children:[(0,a.jsx)("circle",{cx:"8",cy:"8",r:"6.6"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"4.4"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"2.2"})]}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"6.6",pathLength:"100",strokeDasharray:"72 100",strokeOpacity:"0.8"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"4.4",pathLength:"100",strokeDasharray:"52 100",strokeOpacity:"0.6"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"2.2",pathLength:"100",strokeDasharray:"34 100",strokeOpacity:"0.45"})]})}),Ui=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsx)("path",{fill:"currentColor",fillOpacity:"0.75",d:"M8.4 7.31 8.4 1.01A7 7 0 0 1 13.85 4.16ZM8.8 8 13.64 5.2A6.3 6.3 0 0 1 13.64 10.8ZM8.4 8.69 12.64 11.14A5.6 5.6 0 0 1 8.4 13.59ZM7.6 8.69 7.6 12.78A4.8 4.8 0 0 1 4.06 10.74ZM7.2 8 4.27 9.69A4.1 4.1 0 0 1 4.27 6.31ZM7.6 7.31 5.19 5.92A3.5 3.5 0 0 1 7.6 4.52Z"})}),$i=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"currentColor",children:[(0,a.jsx)("path",{fillOpacity:"0.35",d:"M8.4 3.82 8.4 1.01A7 7 0 0 1 13.85 4.16L11.42 5.56A4.2 4.2 0 0 0 8.4 3.82ZM11.46 6.47 13.64 5.2A6.3 6.3 0 0 1 13.64 10.8L11.46 9.53A3.78 3.78 0 0 0 11.46 6.47ZM10.69 10.01 12.64 11.14A5.6 5.6 0 0 1 8.4 13.59L8.4 11.34A3.36 3.36 0 0 0 10.69 10.01ZM7.6 10.85 7.6 12.78A4.8 4.8 0 0 1 4.06 10.74L5.73 9.77A2.88 2.88 0 0 0 7.6 10.85ZM5.7 8.87 4.27 9.69A4.1 4.1 0 0 1 4.27 6.31L5.7 7.13A2.46 2.46 0 0 0 5.7 8.87ZM6.41 6.62 5.19 5.92A3.5 3.5 0 0 1 7.6 4.52L7.6 5.94A2.1 2.1 0 0 0 6.41 6.62Z"}),(0,a.jsx)("path",{fillOpacity:"0.9",d:"M8.4 7.31 8.4 3.82A4.2 4.2 0 0 1 11.42 5.56ZM8.8 8 11.46 6.47A3.78 3.78 0 0 1 11.46 9.53ZM8.4 8.69 10.69 10.01A3.36 3.36 0 0 1 8.4 11.34ZM7.6 8.69 7.6 10.85A2.88 2.88 0 0 1 5.73 9.77ZM7.2 8 5.7 8.87A2.46 2.46 0 0 1 5.7 7.13ZM7.6 7.31 6.41 6.62A2.1 2.1 0 0 1 7.6 5.94Z"})]})}),Xi=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 16 16",...e,children:(0,a.jsxs)("g",{fill:"currentColor",fillOpacity:"0.8",children:[(0,a.jsx)("circle",{cx:"1.028",cy:"13.897",r:"1.028"}),(0,a.jsx)("circle",{cx:"2.57",cy:"8.243",r:"1.028"}),(0,a.jsx)("circle",{cx:"5.653",cy:"12.355",r:"1.028"}),(0,a.jsx)("circle",{cx:"8.223",cy:"8.243",r:"1.028"}),(0,a.jsx)("circle",{cx:"9.252",cy:"3.618",r:"1.028"}),(0,a.jsx)("circle",{cx:"12.849",cy:"7.215",r:"1.028"}),(0,a.jsx)("circle",{cx:"14.905",cy:"1.561",r:"1.028"})]})}),qi=.55,Yi=.15,Pe=[{name:"column",icon:Di,summary:{coordType:"cartesian",geom:"bar",position:"dodge"}},{name:"columnStacked",icon:Gi,summary:{coordType:"cartesian",geom:"bar",position:"stack"}},{name:"columnStackedFill",icon:Ni,summary:{coordType:"cartesian",geom:"bar",position:"fill"}},{name:"bar",icon:Oi,summary:{coordType:"flip",geom:"bar",position:"dodge"}},{name:"barStacked",icon:_i,summary:{coordType:"flip",geom:"bar",position:"stack"}},{name:"barStackedFill",icon:Ri,summary:{coordType:"flip",geom:"bar",position:"fill"}},{name:"line",icon:lo,summary:{coordType:"cartesian",geom:"line",position:"identity"}},{name:"areaStacked",icon:Mi,summary:{coordType:"cartesian",geom:"area",position:"stack"}},{name:"combo",icon:Bi,summary:{coordType:"cartesian",comboType:"groupedBars"}},{name:"scatter",icon:Xi,summary:{coordType:"cartesian",geom:"point",position:"identity"}},{name:"pie",icon:zi,summary:{coordType:"polar",geom:"bar",position:"fill",theta:"y",innerRadius:0}},{name:"donut",icon:Fi,summary:{coordType:"polar",geom:"bar",position:"fill",theta:"y",innerRadius:qi}},{name:"radialBar",icon:Ki,summary:{coordType:"polar",geom:"bar",position:"stack",theta:"y",innerRadius:Yi}},{name:"rose",icon:Ui,summary:{coordType:"polar",geom:"bar",position:"dodge",theta:"x",innerRadius:0}},{name:"roseStacked",icon:$i,summary:{coordType:"polar",geom:"bar",position:"stack",theta:"x",innerRadius:0}},{name:"radar",icon:Wi,summary:{coordType:"polar",geom:"line",position:"identity",theta:"x",innerRadius:0}},{name:"radarFilled",icon:Vi,summary:{coordType:"polar",geom:"area",position:"identity",theta:"x",innerRadius:0}},{name:"heatmap",icon:Hi,summary:{coordType:"cartesian",geom:"tile",position:"identity"}}],Zi=.05,co=(e,t)=>(0,d.isComboGraphType)(e)?(0,d.canBecomeCombo)(t):e.geom==="tile"?(0,d.canBecomeHeatmap)(t):!0,nt=e=>e===null?null:Pe.find(t=>Ji(t.summary,e))??null,uo=(e,t)=>t===null||(0,d.isComboGraphType)(e)?e:e.position==="dodge"&&ho(t)?{...e,position:"identity"}:e.coordType!=="polar"||!rt(e.innerRadius)||t.coordType!=="polar"||!rt(t.innerRadius)?e:{...e,innerRadius:t.innerRadius},ho=e=>!(0,d.isComboGraphType)(e)&&e.geom==="bar"&&e.position==="identity",Ji=(e,t)=>{if((0,d.isComboGraphType)(e)||(0,d.isComboGraphType)(t))return(0,d.isComboGraphType)(e)&&(0,d.isComboGraphType)(t);const n=e.position===t.position||e.position==="dodge"&&ho(t);return e.coordType!==t.coordType||e.geom!==t.geom||!n?!1:e.coordType!=="polar"||t.coordType!=="polar"?!0:e.theta===t.theta&&rt(e.innerRadius)===rt(t.innerRadius)},rt=e=>e>=Zi;var Qi="_1a90obs1",es=[{summary:{coordType:"cartesian",geom:"area",position:"fill"},icon:Li},{summary:{coordType:"cartesian",comboType:"stackedBars"},icon:Ei},{summary:{coordType:"cartesian",comboType:"lines"},icon:lo}],ts=[["column","column"],["bar","bar"],["line","line"],["area","areaStacked"],["combo","combo"],["scatter","scatter"],["pie","pie"],["donut","donut"],["heatmap","heatmap"]],ns=4,rs={dodge:"grouped",identity:"grouped",stack:"stacked",fill:"filled"},os={groupedBars:"grouped",stackedBars:"stacked",lines:"lines"},as=()=>{const e=c.useSceneSelector(M=>M.spec),t=c.useSceneSelector(({layers:M})=>M.some(G=>(0,d.hasMultipleGroups)(G.data,G.mapping))),n=c.useGraphCommands(),r=c.useI18n(),{Button:o,RadioGrid:i}=v.useControls(),[s,l]=(0,b.useState)(!1),h=(0,b.useRef)(null);(0,b.useEffect)(()=>{if(!s)return;const M=({target:G,detail:L})=>{L>0&&ss(G)&&h.current?.contains(G)&&l(!1)};return document.addEventListener("click",M),()=>document.removeEventListener("click",M)},[s]);const u=(0,d.readGraphType)(e);if(u===null)return null;const p=ls(u),g=ot(u),m=nt(u),f=p??m,x=r(f===null?"editor.overlayMenu.customChartType":`editor.graphTypes.${f.name}`),y=(p===void 0?m:_n(p,g))?.icon,w=p!==void 0&&p.arrangements.length>1,S=w&&(t||p.name==="combo"),I=()=>l(!s),j=({summary:M})=>{n.dispatch(new d.SetGraphTypeCommand(uo(M,u)),{transient:!0})},A=M=>{const G=Rn.find(L=>L.name===M);G!==void 0&&j(_n(G,w?g:null))},T=Rn.map(({name:M,arrangements:[G]})=>({value:M,label:r(`editor.graphTypes.${M}`),icon:(0,a.jsx)(G.icon,{size:"md"}),disabled:!co(G.summary,e)}));return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:r("editor.overlayMenu.chartType"),children:y===void 0?(0,a.jsx)(o,{label:x,expanded:s,onClick:I}):(0,a.jsx)(o,{variant:"icon",icon:(0,a.jsx)(y,{size:"sm"}),ariaLabel:x,expanded:s,onClick:I})}),s&&(0,a.jsx)(N,{layout:"stack",children:(0,a.jsx)("div",{ref:h,className:"_1a90obs0",children:(0,a.jsx)(i,{options:T,value:p?.name??"",onChange:A,onCommit:n.commit,columns:ns,itemLayout:"swatch",ariaLabel:r("editor.overlayMenu.chartType")})})}),S&&(0,a.jsx)(is,{type:p,arrangement:g,onPick:j,onCommit:n.commit})]})},po=(e,t)=>(0,d.isComboGraphType)(e)||(0,d.isComboGraphType)(t)?(0,d.isComboGraphType)(e)&&(0,d.isComboGraphType)(t):e.coordType==="polar"?nt(e)===nt(t):e.coordType===t.coordType&&e.geom===t.geom,go=ts.flatMap(([e,t])=>{const n=Pe.find(r=>r.name===t);return n===void 0?[]:[{name:e,arrangements:[n,...[...Pe,...es].filter(r=>r!==n&&po(n.summary,r.summary))]}]}),Rn=go.filter(({name:e})=>e!=="combo"),is=({type:e,arrangement:t,onPick:n,onCommit:r})=>{const o=c.useI18n(),{ToggleGroup:i}=v.useControls(),s=e.arrangements.map(({summary:h,icon:u})=>{const p=ot(h);return{value:p,label:o(`editor.overlayMenu.arrangements.${p}`),icon:(0,a.jsx)(u,{size:"sm"})}}),l=h=>{const u=e.arrangements.find(({summary:p})=>ot(p)===h);u!==void 0&&n(u)};return(0,a.jsx)(N,{label:o("editor.overlayMenu.arrange"),children:(0,a.jsx)("div",{className:Qi,children:(0,a.jsx)(i,{options:s,value:t,onChange:l,onCommit:r})})})},ss=e=>e instanceof Element&&e.closest('[role="radio"]:not([aria-disabled="true"])')!==null,ot=e=>(0,d.isComboGraphType)(e)?os[e.comboType]:rs[e.position],_n=(e,t)=>e.arrangements.find(({summary:n})=>ot(n)===t)??e.arrangements[0],ls=e=>go.find(({arrangements:[t]})=>po(t.summary,e)),cs=()=>{const e=c.useSceneSelector(l=>l.scales.color),t=c.useGraphCommands(),n=c.useI18n(),[r,o]=(0,b.useState)(null);(0,b.useEffect)(()=>()=>t.commit(),[t]);const i=(0,d.readColorChoices)(e),s=(0,d.readColormapColor)(e,r===null?i:[r,...i]);return(s===null?[{label:n("editor.overlayMenu.lowColor"),color:(0,d.readDivergingColor)(e,"low"),buildRange:l=>(0,d.buildDivergingRange)(e,"low",l)},{label:n("editor.overlayMenu.highColor"),color:(0,d.readDivergingColor)(e,"high"),buildRange:l=>(0,d.buildDivergingRange)(e,"high",l)}]:[{label:n("editor.overlayMenu.fillColor"),color:s,buildRange:l=>(0,d.buildColormapRange)(e,l)}]).map(({label:l,color:h,buildRange:u})=>{if(h===null)return null;const p=(g,m)=>{const f=u(g);f!==null&&(o(g),t.dispatch(new d.SetScaleRangeCommand({scaledAesthetic:"color",range:f}),m?{transient:!0}:void 0))};return(0,a.jsx)(oo,{label:l,palette:i,selectedColor:h,paint:p,commit:()=>t.commit()},l)})},mo=({lineStyle:e,...t})=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 18 18",...t,children:[e==="solid"&&(0,a.jsx)("path",{d:"M2 9h14",stroke:"currentColor",strokeWidth:2}),e==="dashed"&&(0,a.jsx)("path",{d:"M1 9h4m2 0h4m2 0h4",stroke:"currentColor",strokeWidth:2}),e==="dotted"&&(0,a.jsxs)("g",{fill:"currentColor",children:[(0,a.jsx)("circle",{cx:2.4,cy:9,r:1.4}),(0,a.jsx)("circle",{cx:9,cy:9,r:1.4}),(0,a.jsx)("circle",{cx:15.6,cy:9,r:1.4})]})]}),vo=({lineWidth:e,...t})=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("path",{d:"M2 9h14",stroke:"currentColor",strokeWidth:e})}),ds={small:2,medium:3.8,large:5.6},us=({pointSize:e,...t})=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("circle",{cx:9,cy:9,r:ds[e],fill:"currentColor"})});var hs=({symbol:e,...t})=>{const n=(0,d.buildPointSymbolInBox)(e,12,12),r=18/2;return(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("path",{d:n.path,fill:"currentColor",transform:`translate(${r+n.offsetX} ${r+n.offsetY})`})})},ps="_1yjsaqt0",gs="_1yjsaqt1",ms="_1yjsaqt2",vs="_1yjsaqt3";var y1=512*1024,xs=e=>new Promise(t=>{if(e.size>524288){t({rejection:"oversized"});return}if(!e.type.startsWith("image/")){t({rejection:"undecodable"});return}const n=new FileReader;n.onerror=()=>t({rejection:"undecodable"}),n.onload=()=>{const r=n.result;if(typeof r!="string"||!r.startsWith("data:image/")){t({rejection:"undecodable"});return}const o=new Image;o.onload=()=>t({image:r}),o.onerror=()=>t({rejection:"undecodable"}),o.src=r},n.readAsDataURL(e)}),Dn=["solid","dashed","dotted"],yt=[{name:"thin",widthPx:2},{name:"medium",widthPx:3},{name:"thick",widthPx:5}],St=[{name:"small",sizePx:6},{name:"medium",sizePx:8},{name:"large",sizePx:10}],fs=["circle","square","diamond","triangle","cross","star"],xo=({widthPx:e,onChange:t})=>{const n=c.useI18n(),{ToggleGroup:r}=v.useControls(),o=i=>{const s=yt.find(({name:l})=>l===i);s!==void 0&&t(s.widthPx)};return(0,a.jsx)(N,{label:n("editor.graphPanel.lineThickness.label"),children:(0,a.jsx)(r,{value:yt.find(i=>i.widthPx===e)?.name??"",options:yt.map(({name:i,widthPx:s})=>({value:i,label:n(`editor.graphPanel.gridSection.lineWidths.${i}`),icon:(0,a.jsx)(vo,{lineWidth:s})})),onChange:o})})},fo=({lineStyle:e,onChange:t})=>{const n=c.useI18n(),{ToggleGroup:r}=v.useControls(),o=i=>{const s=Dn.find(l=>l===i);s!==void 0&&t(s)};return(0,a.jsx)(N,{label:n("editor.fineTunePanel.lineStyleSection.title"),children:(0,a.jsx)(r,{value:e??"",options:Dn.map(i=>({value:i,label:n(`editor.graphPanel.gridSection.lineStyles.${i}`),icon:(0,a.jsx)(mo,{lineStyle:i})})),onChange:o})})},on=({symbol:e,coordType:t,onChange:n})=>{const r=c.useI18n(),{RadioGrid:o}=v.useControls(),[i,s]=(0,b.useState)(null),l=(0,b.useContext)(v.PanelGraphContext),h=c.useGlyphRegistry(),u=c.useGeomRendererResolver(),p=l?l.getPointSymbols(t):u("point",t)?.symbols,g=l?new Map(l.getGlyphs().map(({name:T,definition:M})=>[T,M])):h;if(p===void 0||p.length===0)return null;const m=T=>typeof T=="string"&&p.includes(T),f=T=>m(T)||(0,d.isImageSymbol)(T)||!(0,d.isGeometricSymbol)(T)&&g.has(T),x=T=>!(0,d.isGeometricSymbol)(T)||fs.some(M=>M===T),y=[...g.keys()].filter(T=>!(0,d.isGeometricSymbol)(T)&&!m(T)),w=[...p.filter(x),...y],S=e===null?"":Be(e),I=e===null||w.some(T=>Be(T)===S)||!f(e)?w:[...w,e],j=T=>(0,d.isGeometricSymbol)(T)?r(`editor.graphPanel.pointSymbol.symbols.${T}`):(0,d.isImageSymbol)(T)?r("editor.graphPanel.pointSymbol.custom"):T,A=T=>{s(null);const M=I.find(G=>Be(G)===T);M!==void 0&&n(M)};return(0,a.jsx)(N,{label:r("editor.graphPanel.pointSymbol.label"),layout:"stack",children:(0,a.jsxs)("div",{className:ps,children:[(0,a.jsxs)("div",{className:gs,children:[(0,a.jsx)(o,{itemLayout:"chip",value:S,options:I.map(T=>({value:Be(T),label:j(T),icon:(0,a.jsx)(Ss,{symbol:T,glyphs:g})})),onChange:A}),(0,a.jsxs)("span",{className:v.trailing,children:[(0,a.jsx)("span",{className:v.trailingSeparator,"aria-hidden":"true"}),(0,a.jsx)(ys,{label:r("editor.graphPanel.pointSymbol.custom"),onChange:T=>{s(null),n(T)},onReject:s})]})]}),i!==null&&(0,a.jsx)("p",{className:"_1yjsaqt4",role:"status",children:r(`editor.graphPanel.pointSymbol.${i}`)})]})})},an=({sizePx:e,onChange:t})=>{const n=c.useI18n(),{ToggleGroup:r}=v.useControls(),o=i=>{const s=St.find(({name:l})=>l===i);s!==void 0&&t(s.sizePx)};return(0,a.jsx)(N,{label:n("editor.graphPanel.pointSize.label"),children:(0,a.jsx)(r,{value:St.find(i=>i.sizePx===e)?.name??"",options:St.map(({name:i})=>({value:i,label:n(`editor.graphPanel.pointSize.sizes.${i}`),icon:(0,a.jsx)(us,{pointSize:i})})),onChange:o})})},ys=({label:e,onChange:t,onReject:n})=>{const{FileInput:r}=v.useControls(),o=i=>{xs(i).then(s=>{"image"in s?t({image:s.image}):n(s.rejection)})};return(0,a.jsx)(r,{variant:"chip",label:e,accept:"image/*",onFile:o})},Ss=({symbol:e,glyphs:t})=>{if((0,d.isGeometricSymbol)(e))return(0,a.jsx)(hs,{symbol:e});const n=bs(e,t);if(n!==null&&c.tintsGlyphImage(n))return(0,a.jsx)("span",{className:vs,style:{maskImage:`url(${JSON.stringify(n)})`}});if(n!==null)return(0,a.jsx)("img",{className:ms,src:n,alt:""});const r=18/2;return(0,a.jsx)("svg",{viewBox:`${-r} ${-r} 18 18`,width:16,height:16,"aria-hidden":"true",children:(0,a.jsx)(c.GlyphMark,{symbol:e,glyphs:t,size:12,fill:"currentColor"})})},Be=e=>typeof e=="string"?e:e.image,bs=(e,t)=>{if((0,d.isImageSymbol)(e))return e.image;const n=t.get(e);return n!==void 0&&typeof n!="function"&&"image"in n?n.image:null},yo=(0,b.createContext)({}),Cs=yo.Provider,ws=()=>(0,b.useContext)(yo),Ts="_1qh3fon0",Nt="theme",js=3,Fe=14,Nn=9,So=()=>{const e=c.useSceneSelector(p=>p.scales.color),t=ws(),n=c.useGraphCommands(),r=c.useI18n(),{RadioGrid:o}=v.useControls();if(Object.keys(t).length===0||e?.kind!=="visual"||e.spec.scaleType!=="discrete"||e.defaultPalette===void 0)return null;const{defaultPalette:i,spec:s}=e,l=Object.entries(t),h=[{value:Nt,label:r("editor.overlayMenu.themePalette"),icon:(0,a.jsx)(Gn,{colors:i})},...l.map(([p,g])=>({value:Gt(p),label:p,icon:(0,a.jsx)(Gn,{colors:g})}))],u=p=>{const g=l.find(([f])=>Gt(f)===p);if(p!==Nt&&g===void 0)return;const m=g===void 0?null:[...g[1]];n.dispatch(new d.SetScaleRangeCommand({scaledAesthetic:"color",range:m}),{transient:!0})};return(0,a.jsx)(N,{label:r("editor.overlayMenu.palette"),layout:"stack",children:(0,a.jsx)(o,{options:h,value:As(s.range,l),onChange:u,onCommit:n.commit,columns:4,itemLayout:"track"})})},Gt=e=>`preset:${e}`,As=(e,t)=>{if(e===null)return Nt;const n=t.find(([,r])=>(0,Q.isEqual)(r,e));return n===void 0?"":Gt(n[0])},Gn=({colors:e})=>{const t=e.slice(0,js),n=Fe/2,r=Fe+(t.length-1)*Nn;return(0,a.jsx)("svg",{width:r,height:Fe,viewBox:`0 0 ${r} ${Fe}`,"aria-hidden":"true",children:t.map((o,i)=>(0,a.jsx)("circle",{className:Ts,cx:n+i*Nn,cy:n,r:n-.5,fill:o},i)).reverse()})},Bn=["smooth","linear"],Fn=["auto","inside","outside"],sn=()=>{const e=c.useSceneSelector(C=>C),t=c.useStyleReaderTree(),n=c.useDataLabelPlacementResolver(),r=c.useGraphCommands(),o=c.useI18n(),{Switch:i,ToggleGroup:s}=v.useControls(),l=bo(e.layers,e.coordSystem.type,n),h=C=>l.filter(({support:D})=>C(D)).map(({layer:D})=>D),u=Ps(e,t),p=u.filter(C=>C.smooth!==null),g=u.filter(C=>C.missingValues!==null&&C.missingValueOptions.length>1),m=Dt.filter(C=>g.some(D=>D.missingValueOptions.includes(C))),f=Es(p),x=Ms(g),y=C=>{r.dispatch(new d.SequenceCommand({commands:u.map(D=>new d.ToggleLinePointsCommand({layerId:D.layerId,showPoints:C}))}))},w=C=>{const D=Bn.find(z=>z===C);D!==void 0&&r.dispatch(new d.SequenceCommand({commands:p.map(z=>new d.SetLineCurveCommand({layerId:z.layerId,curve:D}))}))},S=h(C=>C.supportsPosition),I=He(S.map(C=>C.dataLabels.position))??"",j=C=>{const D=Fn.find(z=>z===C);D!==void 0&&r.dispatch(new d.SequenceCommand({commands:S.map(z=>new d.SetDataLabelsCommand({layerId:z.id,position:D}))}))},A=C=>{const D=Dt.find(P=>P===C);if(D===void 0)return;const z=g.filter(P=>P.missingValueOptions.includes(D)).map(P=>new d.SetLineMissingValuesCommand({layerId:P.layerId,missingValues:D}));z.length!==0&&r.dispatch(new d.SequenceCommand({commands:z}))},T=u.filter(C=>C.showFill!==null),M=u.filter(C=>C.showPoints),G=Is(e,t,u),L=T.some(C=>ks(e,C)),B=C=>{C.length>0&&r.dispatch(new d.SequenceCommand({commands:C}))},R=C=>{B(u.map(D=>new d.SetLineStyleCommand({layerId:D.layerId,strokeWidth:C})))},k=C=>{B(u.map(D=>new d.SetLineStyleCommand({layerId:D.layerId,lineStyle:C})))},_=C=>{B(T.map(D=>new d.SetLineStyleCommand({layerId:D.layerId,showFill:C,drawnFillAlpha:D.drawnFillAlpha})))},O=C=>{B(M.flatMap(({pointLayerId:D})=>D===null?[]:[new d.SetPointSizeCommand({layerId:D,size:C})]))};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(as,{}),(0,a.jsx)(ze,{label:o("editor.graphPanel.graphOptions.dataLabels"),layers:h(C=>C.supportsDataLabels),isOn:C=>C.showDataLabels,buildCommand:(C,D)=>new d.ToggleDataLabelsCommand({layerId:C,showDataLabels:D})}),S.length>0&&(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.labelPosition"),children:(0,a.jsx)(s,{value:I,options:Fn.map(C=>({value:C,label:o(`editor.graphPanel.graphOptions.labelPositions.${C}`)})),onChange:j})}),(0,a.jsx)(ze,{label:o("editor.graphPanel.graphOptions.showPercentages"),layers:h(C=>C.supportsPercentages),isOn:C=>C.format==="percentage",buildCommand:(C,D)=>new d.SetDataLabelsFormatCommand({layerId:C,format:D?"percentage":"absolute"})}),(0,a.jsx)(ze,{label:o("editor.graphPanel.graphOptions.stackTotals"),layers:h(C=>C.supportsStackTotals),isOn:C=>C.showStackTotals,buildCommand:(C,D)=>new d.ToggleStackTotalsCommand({layerId:C,showStackTotals:D})}),(0,a.jsx)(ze,{label:o("editor.graphPanel.graphOptions.categoryLabels"),layers:h(C=>C.supportsCategoryLabels),isOn:C=>C.showCategoryLabels,buildCommand:(C,D)=>new d.ToggleCategoryLabelsCommand({layerId:C,showCategoryLabels:D})}),(0,a.jsx)(N,{label:o("editor.elementsPanel.headerSection.toggleTitle"),children:(0,a.jsx)(i,{checked:e.config.content.showTitle,onChange:C=>r.dispatch(new d.ToggleContentVisibilityCommand({part:"title",visible:C}))})}),(0,a.jsx)(N,{label:o("editor.elementsPanel.headerSection.subtitle"),children:(0,a.jsx)(i,{checked:e.config.content.showSubtitle,onChange:C=>r.dispatch(new d.ToggleContentVisibilityCommand({part:"subtitle",visible:C}))})}),(0,a.jsx)(N,{label:o("editor.elementsPanel.footerSection.caption"),children:(0,a.jsx)(i,{checked:e.config.content.showCaption,onChange:C=>r.dispatch(new d.ToggleContentVisibilityCommand({part:"caption",visible:C}))})}),p.length>0&&(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.smoothLines"),children:(0,a.jsx)(s,{value:f,options:Bn.map(C=>({value:C,label:o(`editor.graphPanel.graphOptions.curves.${C}`),icon:(0,a.jsx)(bi,{curve:C})})),onChange:w})}),m.length>1&&(0,a.jsx)(N,{label:o("editor.fineTunePanel.detailSection.missingValues"),children:(0,a.jsx)(s,{value:x,options:m.map(C=>({value:C,label:so(o,C),icon:(0,a.jsx)(wi,{missingValues:C})})),onChange:A})}),u.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(xo,{widthPx:He(G.map(C=>C.strokeWidth)),onChange:R}),(0,a.jsx)(fo,{lineStyle:He(G.map(C=>C.lineStyle)),onChange:k})]}),T.length>0&&(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.lineFill"),children:(0,a.jsx)(i,{checked:L,onChange:_})}),u.length>0&&(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.showPoints"),children:(0,a.jsx)(i,{checked:M.length>0,onChange:y})}),M.length>0&&(0,a.jsx)(an,{sizePx:He(Ls(e,t,M)),onChange:O}),(0,a.jsx)(So,{}),(0,a.jsx)(cs,{})]})};sn.hasRows=(e,{scene:t,dataLabelPlacement:n})=>(0,d.readGraphType)(t.spec)!==null||bo(t.layers,t.coordSystem.type,n).some(({support:r})=>r.supportsDataLabels)||t.spec.layers.some(r=>r.interactive&&(0,d.isLayerSpecOf)(r,"line","area"));var bo=(e,t,n)=>e.filter(r=>r.interactive).map(r=>({layer:r,support:io(r,t,n)})),Ps=(e,t)=>{const n=[];for(const r of e.spec.layers){if(!r.interactive)continue;const o=rn(e,t,r.id);o!==null&&n.push(o)}return n},Is=(e,t,n)=>n.flatMap(r=>{const o=(0,d.findLayerById)(e.layers,r.layerId);if(o?.geom==="line"){const s=t.geom.line(o);return Array.from(o.data,l=>({strokeWidth:s.get("strokeWidth",l),lineStyle:(0,d.toDashPreset)(s.get("dashArray",l))}))}if(o?.geom!=="area")return[];const i=t.geom.area(o);return Array.from(o.data,s=>({strokeWidth:i.get("strokeWidth",s),lineStyle:(0,d.toDashPreset)(i.get("dashArray",s))}))}),ks=(e,t)=>{if(t.showFill===!0)return!0;const n=(0,d.buildLayerStyleAddress)("line",t.layerId),r=(0,d.readStyleCoord)(e.spec);return e.spec.styles.overrides.some(o=>!(0,d.isGeomStyleRule)(o)||o.when?.where===void 0?!1:(0,d.createStyleRuleMatcher)({...n,when:o.when},r)(o)&&"fillAlpha"in o.declarations&&(o.declarations.fillAlpha??0)>0)},Ls=(e,t,n)=>n.flatMap(r=>{const o=r.pointLayerId===null?void 0:(0,d.findLayerById)(e.layers,r.pointLayerId);if(o?.geom!=="point")return[];const i=t.geom.point(o);return Array.from(o.data,s=>i.get("size",s)).filter(s=>s>0)}),He=e=>{const[t]=e;return t!==void 0&&e.every(n=>n===t)?t:null},Es=e=>e.every(t=>t.smooth===!0)?"smooth":e.every(t=>t.smooth!==!0)?"linear":"",Ms=e=>{const[t,...n]=e,r=t?.missingValues??null;return r===null?"":n.every(o=>o.missingValues===r)?r:""},ze=({label:e,layers:t,isOn:n,buildCommand:r})=>{const o=c.useGraphCommands(),{Switch:i}=v.useControls();if(t.length===0)return null;const s=l=>{o.dispatch(new d.SequenceCommand({commands:t.map(h=>r(h.id,l))}))};return(0,a.jsx)(N,{label:e,children:(0,a.jsx)(i,{checked:t.some(l=>n(l.dataLabels)),onChange:s})})},Os=(e,t)=>{const n=(0,d.findLayerById)(t.layers,e);if(n===void 0)return null;const r=(0,d.findLayerById)(t.spec.layers,e),o=r===void 0?null:(0,d.findHostLayer)(r,t.spec.layers),i=o!==null&&o.id!==n.id?o:n;return{geom:i.geom,coord:t.spec.coords.coordType,position:i.position}},We=(e,t)=>{for(const n of e){const r=t(n);if(r!==void 0)return r}return null},Rs=({geom:e,coord:t,position:n},r,o="style",i=null)=>{for(const s of r){const l=Hn(zn(s.layers,e)?.[t]?.[n],o),h=l!==void 0?l:Hn(zn(s.geoms,e),o);if(h===null)return null;if(h!==void 0)return h}return i},_s=e=>typeof e=="object"&&("style"in e||"annotate"in e),Hn=(e,t)=>e==null?e:_s(e)?e[t]:t==="style"?e:void 0,zn=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,at=["solid","dashed","dotted"];var Co=e=>e.scaledAesthetic==="x"||e.scaledAesthetic==="y",wo=(e,t)=>{const n=e.guides.axes.filter(Co);if(n.length===0)return null;const r=t.gridLine.y().resolve();return{axes:n,stylable:e.coordSystem.type!=="polar",lineStyle:(0,d.toDashPreset)(r.dashArray),strokeWidth:r.strokeWidth}},Ds=(e,t)=>{if(e==="both")return t.axes.every(r=>!r.showGrid);const n=t.axes.find(r=>r.scaledAesthetic===e);return n===void 0||!n.showGrid},To=(e,t="both")=>new d.SetGridLineStyleCommand({axis:t,lineStyle:e}),jo=(e,t="both")=>new d.SetGridLineStyleCommand({axis:t,strokeWidth:e}),bt=[{name:"thin",widthPx:1},{name:"medium",widthPx:2},{name:"thick",widthPx:4}],ln=({target:e})=>{const t=c.useSceneSelector(w=>w),n=c.useStyleReaderTree(),r=wo(t,n),o=c.useI18n(),i=c.useGraphCommands(),{ToggleGroup:s}=v.useControls();if(r===null||!r.stylable)return null;const l=e.axis==="both"?"y":e.axis,h=n.gridLine[l]().resolve(),u=(0,d.toDashPreset)(h.dashArray),p=Ds(e.axis,r),g=at.map(w=>({value:w,label:o(`editor.graphPanel.gridSection.lineStyles.${w}`),icon:(0,a.jsx)(mo,{lineStyle:w})})),m=bt.map(({name:w,widthPx:S})=>({value:w,label:o(`editor.graphPanel.gridSection.lineWidths.${w}`),icon:(0,a.jsx)(vo,{lineWidth:S})})),f=bt.find(({widthPx:w})=>w===h.strokeWidth)?.name??"",x=w=>{const S=at.find(I=>I===w);S!==void 0&&i.dispatch(To(S,e.axis))},y=w=>{const S=bt.find(({name:I})=>I===w);S!==void 0&&i.dispatch(jo(S.widthPx,e.axis))};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:o("editor.graphPanel.gridSection.gridStyle"),children:(0,a.jsx)(s,{value:u,options:g,onChange:x,disabled:p})}),(0,a.jsx)(N,{label:o("editor.graphPanel.gridSection.gridThickness"),children:(0,a.jsx)(s,{value:f,options:m,onChange:y,disabled:p})})]})};ln.hasRows=(e,{scene:t})=>{if(t.coordSystem.type==="polar")return!1;const n=t.guides.axes.filter(Co);return n.length===0?!1:e.axis==="both"?!0:n.some(r=>r.scaledAesthetic===e.axis)};var Wn=[{position:"top",align:"start",gridRow:1,gridColumn:1},{position:"top",align:"center",gridRow:1,gridColumn:2},{position:"top",align:"end",gridRow:1,gridColumn:3},{position:"right",align:"center",gridRow:2,gridColumn:3},{position:"bottom",align:"end",gridRow:3,gridColumn:3},{position:"bottom",align:"center",gridRow:3,gridColumn:2},{position:"bottom",align:"start",gridRow:3,gridColumn:1},{position:"left",align:"center",gridRow:2,gridColumn:1}],Ns={start:"Start",center:"Center",end:"End"},Ao=()=>{const e=c.useSceneSelector(h=>h.guides.legends.drawn[0]),t=c.useGraphCommands(),n=c.useI18n(),{RadioGrid:r}=v.useControls(),o=e===void 0,i=o?"":Ct(e),s=Wn.map(h=>{const u=Ct(h);return{value:u,label:n(`editor.overlayMenu.legendPlaces.${u}`),icon:(0,a.jsx)(c.ArrowIcon,{title:"",size:"xs",style:{transform:`rotate(${Bs(h)}deg)`}}),gridRow:h.gridRow,gridColumn:h.gridColumn,disabled:Gs(e,h)}}),l=h=>{const u=Wn.find(p=>Ct(p)===h);u!==void 0&&t.dispatch(new d.SetLegendPlacementCommand({position:u.position,align:u.align}),{transient:!0})};return(0,a.jsx)(N,{label:n("editor.axesPanel.controls.position"),children:(0,a.jsx)(en.DirectionProvider,{direction:"ltr",children:(0,a.jsx)("div",{dir:"ltr",children:(0,a.jsx)(r,{options:s,value:i,onChange:l,onCommit:t.commit,columns:3,itemLayout:"icon",disabled:o})})})})},Ct=({position:e,align:t})=>e==="left"||e==="right"?e:`${e}${Ns[t]}`,Gs=(e,t)=>e?.inHeadlineRow===!0&&t.position==="top"&&t.align!=="end",Bs=({gridRow:e,gridColumn:t})=>Math.atan2(t-2,2-e)*180/Math.PI,Po=(e,t,n,r)=>{const o=ko(e,n,r)?.size;if(typeof o=="number")return o;const i=(0,d.findLayerById)(e.layers,n);return i?.geom==="point"?t.geom.point(i).get("size"):d.DEFAULT_POINT_SIZE_PX},Io=(e,t,n,r)=>{const o=ko(e,n,r)?.symbol;if(o!==void 0)return o;const i=(0,d.findLayerById)(e.layers,n);return i?.geom==="point"?t.geom.point(i).get("symbol"):"circle"},ko=(e,t,n)=>n===void 0?void 0:(0,d.findKindStyleDeclarations)(e.spec.styles.overrides,{...(0,d.buildLayerStyleAddress)("point",t),when:{where:n}},(0,d.readStyleCoord)(e.spec)),it=({target:e})=>{const t=c.useGraphHandle();return t===null?null:(0,a.jsx)(Fs,{graph:t,target:e})};it.hasRows=(e,{scene:t})=>e.scope==="group"&&Lo(t,e.layerId)!==null;var Fs=({graph:e,target:t})=>{const n=c.useHandleScene(e),r=c.useStyleReaderTree(),o=c.useI18n(),{Switch:i}=v.useControls(),s=n===null?null:Lo(n,t.layerId),l=n===null||s===null?null:rn(n,r,s.id);if(n===null||s===null||l===null)return null;const h=Vs(n,t),u=h===void 0?{}:{where:h},p=h===void 0||s.geom!=="line"?void 0:Ws(n,l.layerId,h),g=p===void 0?l.showFill:p>0,m=h===void 0?null:Hs(n,s.geom,l.layerId,h),f=h===void 0?l.strokeWidth:m??zs(n,r,t)??l.strokeWidth,x=l.pointLayerId===null?null:Po(n,r,l.pointLayerId,h),y=l.pointLayerId===null?null:Io(n,r,l.pointLayerId,h),w=x!==null&&x>0,S=L=>{e.commands.dispatch(new d.ToggleLinePointsCommand({layerId:l.layerId,showPoints:L,...u}))},I=L=>{e.commands.dispatch(new d.SetLineStyleCommand({layerId:l.layerId,showFill:L,drawnFillAlpha:l.drawnFillAlpha,...u}))},j=L=>{e.commands.dispatch(new d.SetLineStyleCommand({layerId:l.layerId,strokeWidth:L,...u}))},A=L=>{l.pointLayerId!==null&&e.commands.dispatch(new d.SetPointSizeCommand({layerId:l.pointLayerId,size:L,...u}))},T=L=>{l.pointLayerId!==null&&e.commands.dispatch(new d.SetPointSymbolCommand({layerId:l.pointLayerId,symbol:L,...u}))},M=L=>{e.commands.dispatch(new d.SetLineStyleCommand({layerId:l.layerId,lineStyle:L,...u}))},G=(0,d.readObservationsColorRoute)(n.spec,t)?.some(L=>L.geomKind==="line"||L.geomKind==="area")===!0;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(re,{target:t}),(0,a.jsx)(xo,{widthPx:f,onChange:j}),G&&(0,a.jsx)(fo,{lineStyle:Ks(n,r,t),onChange:M}),l.showFill!==null&&(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.lineFill"),children:(0,a.jsx)(i,{checked:g===!0,onChange:I})}),(0,a.jsx)(N,{label:o("editor.graphPanel.graphOptions.showPoints"),children:(0,a.jsx)(i,{checked:w,onChange:S})}),w&&(0,a.jsx)(an,{sizePx:x,onChange:A}),w&&(0,a.jsx)(on,{symbol:y,coordType:n.coordSystem.type,onChange:T})]})},Hs=(e,t,n,r)=>{const o=(t==="line"?(0,d.findKindStyleDeclarations)(e.spec.styles.overrides,{...(0,d.buildLayerStyleAddress)("line",n),when:{where:r}},(0,d.readStyleCoord)(e.spec)):(0,d.findKindStyleDeclarations)(e.spec.styles.overrides,{...(0,d.buildLayerStyleAddress)("area",n),when:{where:r}},(0,d.readStyleCoord)(e.spec)))?.strokeWidth;return typeof o=="number"?o:null},zs=(e,t,n)=>{const r=(0,d.findLayerById)(e.layers,n.layerId),o=r===void 0?void 0:(0,d.findHostLayer)(r,e.layers);if(o?.geom!=="line"&&o?.geom!=="area")return null;const[i]=(0,d.resolveObservationsTarget)({layer:o,target:n,parsingLocale:e.config.parsingLocale}),s=i===void 0?void 0:o.data.getAt(i)??void 0,l=o.geom==="line"?t.geom.line(o).get("strokeWidth",s):t.geom.area(o).get("strokeWidth",s);return typeof l=="number"?l:null},Ws=(e,t,n)=>{const r=(0,d.findKindStyleDeclarations)(e.spec.styles.overrides,{...(0,d.buildLayerStyleAddress)("line",t),when:{where:n}},(0,d.readStyleCoord)(e.spec))?.fillAlpha;return typeof r=="number"?r:void 0},Vs=(e,t)=>(0,d.readObservationsColorRoute)(e.spec,t)?.find(n=>n.geomKind==="line"||n.geomKind==="area")?.where,Ks=(e,t,n)=>{const r=(0,d.findLayerById)(e.layers,n.layerId),o=r===void 0?void 0:(0,d.findHostLayer)(r,e.layers);if(o?.geom!=="line"&&o?.geom!=="area")return"solid";const[i]=(0,d.resolveObservationsTarget)({layer:o,target:n,parsingLocale:e.config.parsingLocale}),s=i===void 0?null:o.data.getAt(i);return(0,d.toDashPreset)(o.geom==="line"?t.geom.line(o).get("dashArray",s??void 0):t.geom.area(o).get("dashArray",s??void 0))},Lo=(e,t)=>{const n=(0,d.findLayerById)(e.spec.layers,t);if(n===void 0)return null;const r=(0,d.findHostLayer)(n,e.spec.layers);return(0,d.isLayerSpecOf)(r,"line","area")?r:null},Eo=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{fill:"currentColor",fillOpacity:".8",d:"M2.333 3h11.334v8.667c-2 0-4 .333-5.667 2.333-2-2-3.667-2.333-5.667-2.333z",opacity:".12"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:".8",fillRule:"evenodd",d:"M3.325 3.156a.836.836 0 0 0-.836.836v6.832c0 .462.375.836.836.836h2.131a.5.5 0 0 1 .352.145L8 13.975l2.193-2.17a.5.5 0 0 1 .352-.145h2.13a.84.84 0 0 0 .836-.836V3.992a.84.84 0 0 0-.836-.836zm-1.836.836c0-1.014.822-1.836 1.836-1.836h9.35c1.015 0 1.836.825 1.836 1.836v6.832a1.84 1.84 0 0 1-1.836 1.836H10.75l-2.398 2.374a.5.5 0 0 1-.704 0L5.25 12.66H3.325a1.836 1.836 0 0 1-1.836-1.836z",clipRule:"evenodd"}),(0,a.jsx)("path",{fill:"currentColor",fillOpacity:".8",fillRule:"evenodd",d:"M8 4.505a.5.5 0 0 1 .5.5v2.172h2.171a.5.5 0 0 1 0 1H8.5v2.171a.5.5 0 0 1-1 0V8.177H5.329a.5.5 0 0 1 0-1H7.5V5.005a.5.5 0 0 1 .5-.5",clipRule:"evenodd"})]}),Us="_1aafi1g0",$s="_1aafi1g1",Vn=({children:e})=>(0,a.jsxs)("span",{className:Us,"aria-hidden":"true",children:[e,(0,a.jsx)("span",{className:$s})]}),wt=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 15 14",...e,children:(0,a.jsx)("path",{d:"M14.0146 5.20703C14.2118 5.40459 14.2121 5.72447 14.0146 5.92187L12.3291 7.6084C12.2343 7.70313 12.1047 7.75579 11.9707 7.75586C11.8369 7.75573 11.708 7.70291 11.6133 7.6084L9.92773 5.92187C9.73024 5.72438 9.73031 5.40457 9.92773 5.20703C10.1253 5.0095 10.445 5.0095 10.6426 5.20703L11.4658 6.03027L11.4658 1.68652L7.75586 1.68652L7.75586 12.6455C7.75563 12.9246 7.5291 13.1512 7.25 13.1514L2.5293 13.1514C2.2501 13.1514 2.02367 12.9247 2.02344 12.6455L2.02344 5.00781C0.868958 4.77348 0.000106647 3.7528 -1.10559e-07 2.5293C-4.95071e-08 1.13259 1.13261 9.74645e-05 2.5293 -5.23256e-07C3.92588 0.000220668 5.05859 1.13267 5.05859 2.5293C5.05849 3.75251 4.1892 4.77219 3.03516 5.00684L3.03516 12.1396L6.74414 12.1396L6.74414 1.18066C6.74414 0.901394 6.97076 0.674939 7.25 0.674804L11.9707 0.674805C12.2499 0.674939 12.4766 0.901394 12.4766 1.18066L12.4766 6.03027L13.2998 5.20703C13.4973 5.0095 13.8171 5.0095 14.0146 5.20703ZM4.04687 2.5293C4.04687 1.69137 3.36717 1.01194 2.5293 1.01172C1.69132 1.01182 1.01172 1.6913 1.01172 2.5293C1.01184 3.36719 1.6914 4.04678 2.5293 4.04687C3.36709 4.04665 4.04675 3.36712 4.04687 2.5293ZM14.5 11.2969C14.4998 12.6935 13.3673 13.8262 11.9707 13.8262C10.5742 13.826 9.4416 12.6934 9.44141 11.2969C9.44141 9.90018 10.574 8.7677 11.9707 8.76758C13.3675 8.76758 14.5 9.90011 14.5 11.2969ZM13.4883 11.2969C13.4883 10.4588 12.8088 9.7793 11.9707 9.7793C11.1327 9.77942 10.4531 10.4589 10.4531 11.2969C10.4533 12.1347 11.1329 12.8143 11.9707 12.8145C12.8086 12.8145 13.4881 12.1348 13.4883 11.2969Z",fill:"currentColor",fillOpacity:"0.8"})}),Kn=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{opacity:"0.12",d:"M15 4.66667L12.3333 2L2.33334 12L5.00001 14.6667L15 4.66667Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{d:"M5.01683 15.3331C4.84407 15.3343 4.67292 15.2997 4.51421 15.2314C4.3555 15.1632 4.21268 15.0627 4.09476 14.9365L3.88656 14.7283L3.62877 14.8968L3.19253 15.3331H0L2.24072 13.0923L2.03251 12.8445C1.89423 12.7191 1.78392 12.566 1.70875 12.3952C1.63359 12.2244 1.59526 12.0396 1.59626 11.853C1.59579 11.6818 1.63078 11.5124 1.69904 11.3554C1.76729 11.1984 1.86733 11.0573 1.99285 10.9409L11.2036 1.73012C11.3215 1.60384 11.4643 1.5034 11.623 1.43514C11.7817 1.36688 11.9529 1.33228 12.1257 1.33353C12.2969 1.33245 12.4665 1.36716 12.6236 1.43546C12.7807 1.50375 12.9218 1.60412 13.0378 1.73012L15.1496 3.92126C15.2748 4.03899 15.3745 4.1811 15.4427 4.33882C15.5108 4.49654 15.546 4.66655 15.546 4.83837C15.546 5.01019 15.5108 5.1802 15.4427 5.33792C15.3745 5.49564 15.2748 5.63774 15.1496 5.75548L5.93889 14.9662C5.81806 15.0866 5.67403 15.1812 5.51552 15.2443C5.35702 15.3074 5.18736 15.3376 5.01683 15.3331ZM2.48858 11.9125L5.01683 14.4407L9.47843 9.97913L6.95019 7.4608L2.48858 11.9125ZM7.68388 6.72712L10.2022 9.24544L14.644 4.80367L12.1257 2.28534L7.68388 6.72712Z",fill:"currentColor",fillOpacity:"0.8"})]}),Mo=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{opacity:"0.12",d:"M13.5948 4.29016C13.8724 6.22367 12.5301 8.01618 10.5966 8.29384C8.66309 8.57151 6.87058 7.22918 6.59292 5.29567C6.31525 3.36216 7.65758 1.56965 9.59109 1.29198C11.5246 1.01432 13.3171 2.35665 13.5948 4.29016Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.71886 3.51052C6.25611 1.3626 8.43287 0.0568985 10.5808 0.594151C12.7287 1.1314 14.0344 3.30817 13.4972 5.45609C13.0316 7.31748 11.3347 8.54637 9.49237 8.49145L7.50898 12.492C7.46485 12.581 7.40179 12.6548 7.32702 12.7108C7.20005 12.8073 7.03703 12.8532 6.87248 12.8303C6.80957 12.822 6.74697 12.8038 6.68687 12.7749C6.39369 12.6342 6.26689 12.2915 6.3923 11.9963L7.63393 7.97371C6.10249 7.10872 5.27136 5.29962 5.71886 3.51052ZM10.2785 1.80253C8.79799 1.4322 7.29756 2.33222 6.92723 3.81277C6.55691 5.29332 7.45692 6.79375 8.93747 7.16408C10.418 7.5344 11.9185 6.63439 12.2888 5.15384C12.6591 3.67329 11.7591 2.17285 10.2785 1.80253Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{d:"M5.42977 11.1572C5.70072 11.104 5.8772 10.8411 5.82393 10.5702C5.77067 10.2992 5.50784 10.1227 5.23688 10.176C4.31848 10.3565 3.57421 10.6423 3.04695 11.0266C2.51409 11.4149 2.16666 11.936 2.16666 12.557C2.16666 13.0322 2.41215 13.4327 2.74425 13.7433C3.07553 14.0531 3.52776 14.3091 4.04484 14.5137C5.08193 14.9239 6.48048 15.1666 7.99999 15.1666C9.5195 15.1666 10.9181 14.9239 11.9551 14.5137C12.4722 14.3091 12.9244 14.0531 13.2557 13.7433C13.5878 13.4327 13.8333 13.0322 13.8333 12.557C13.8333 11.936 13.4859 11.4149 12.953 11.0266C12.4258 10.6423 11.6815 10.3565 10.7631 10.176C10.4921 10.1227 10.2293 10.2992 10.176 10.5702C10.1228 10.8411 10.2993 11.104 10.5702 11.1572C11.4079 11.3219 11.997 11.5672 12.364 11.8347C12.7255 12.0981 12.8333 12.3496 12.8333 12.557C12.8333 12.6643 12.7803 12.8187 12.5727 13.013C12.3642 13.2079 12.0354 13.4065 11.5873 13.5838C10.6941 13.9371 9.426 14.1666 7.99999 14.1666C6.57398 14.1666 5.30586 13.9371 4.41267 13.5838C3.9646 13.4065 3.63578 13.2079 3.4273 13.013C3.21964 12.8187 3.16666 12.6643 3.16666 12.557C3.16666 12.3496 3.2745 12.0981 3.63595 11.8347C4.00299 11.5672 4.59206 11.3219 5.42977 11.1572Z",fill:"currentColor",fillOpacity:"0.8"})]}),Oo=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("path",{opacity:"0.12",d:"M1.33334 8.00016C1.33334 4.31826 4.31811 1.3335 8.00001 1.3335C11.6819 1.3335 14.6667 4.31826 14.6667 8.00016C14.6667 11.6821 11.6819 14.6668 8.00001 14.6668C4.31811 14.6668 1.33334 11.6821 1.33334 8.00016Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{d:"M5.7328 9.69963C5.56696 9.47884 5.25352 9.43429 5.03273 9.60013C4.81193 9.76598 4.76739 10.0794 4.93323 10.3002C5.63175 11.2302 6.74548 11.8333 7.99993 11.8333C9.25438 11.8333 10.3681 11.2302 11.0666 10.3002C11.2325 10.0794 11.1879 9.76598 10.9671 9.60013C10.7463 9.43429 10.4329 9.47884 10.2671 9.69963C9.74929 10.3889 8.92657 10.8333 7.99993 10.8333C7.07329 10.8333 6.25057 10.3889 5.7328 9.69963Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{d:"M6.66668 6.66658C6.66668 7.03478 6.3682 7.33325 6.00001 7.33325C5.63182 7.33325 5.33334 7.03478 5.33334 6.66658C5.33334 6.29839 5.63182 5.99992 6.00001 5.99992C6.3682 5.99992 6.66668 6.29839 6.66668 6.66658Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{d:"M10 7.33325C10.3682 7.33325 10.6667 7.03478 10.6667 6.66658C10.6667 6.29839 10.3682 5.99992 10 5.99992C9.63182 5.99992 9.33334 6.29839 9.33334 6.66658C9.33334 7.03478 9.63182 7.33325 10 7.33325Z",fill:"currentColor",fillOpacity:"0.8"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8.00001 0.833252C4.04197 0.833252 0.833344 4.04188 0.833344 7.99992C0.833344 11.958 4.04197 15.1666 8.00001 15.1666C11.9581 15.1666 15.1667 11.958 15.1667 7.99992C15.1667 4.04188 11.9581 0.833252 8.00001 0.833252ZM14.1667 7.99992C14.1667 11.4057 11.4058 14.1666 8.00001 14.1666C4.59425 14.1666 1.83334 11.4057 1.83334 7.99992C1.83334 4.59416 4.59425 1.83325 8.00001 1.83325C11.4058 1.83325 14.1667 4.59416 14.1667 7.99992Z",fill:"currentColor",fillOpacity:"0.8"})]}),Xs=e=>{const t=[{scope:"observation",labelKey:"bar"}];if(!(0,d.hasMultipleGroups)(e.data,e.mapping))return t;const n=e.position==="stack"||e.position==="fill";return t.push({scope:"xValue",labelKey:n?"barStack":"barGroup"}),t.push({scope:"group",labelKey:"barSeries"}),t},Ro=e=>{const t=[{scope:"observation",labelKey:"linePoint"}];return(0,d.hasMultipleGroups)(e.data,e.mapping)&&t.push({scope:"group",labelKey:"lineSeries"}),t},_o=e=>{const t=[{scope:"observation",labelKey:"scatterPoint"}];return(0,d.hasMultipleGroups)(e.data,e.mapping)&&t.push({scope:"group",labelKey:"scatterSeries"}),t},qs=()=>[{scope:"group",labelKey:"pieSlice"}];function Ys(e,t){if(e.type==="polar"&&!Zs(t))return qs();switch(t.geom){case"bar":return Xs(t);case"line":case"area":return Ro(t);case"point":return _o(t);default:return[]}}var Zs=e=>{const t=(0,d.readVariableName)(e.mapping.x);return t!==null&&t!==d.CONSTANT_VARIABLES.x},Js=(e,t,n,r)=>{const o=[],i=Qs(e,t,n,r);i!==null&&o.push({id:"gte",valueLabel:i.label,predicate:{variable:i.variable,gte:i.value}});const s=el(e,t,n,r);return s!==null&&o.push({id:"onward",categoryLabel:s.label,predicate:s.predicate}),o},Do=(e,t,n)=>{const r=t.find(o=>st(e.predicate,o.predicate));return r!==void 0?r.id:e.scope!=="observation"?e.scope:n!==null&&st(e.predicate,n)?"observation":null},Qs=(e,t,n,r)=>{const o=(0,d.readVariableName)(e.mapping.y),i=(0,d.readVariableName)(e.mapping.x);if(o===null||i===null||i===d.CONSTANT_VARIABLES.x||!e.data.hasVariable(o)||e.data.getType(o)!=="numeric")return null;const s=No(t,o);return s===null||!ol(e,o,s)?null:{variable:o,value:s,label:Go(e,o,s,n,r)}},el=(e,t,n,r)=>{const o=(0,d.readVariableName)(e.mapping.x);if(o===null||o===d.CONSTANT_VARIABLES.x||!e.data.hasVariable(o)||e.data.getType(o)==="numeric")return null;const i=t[o]??null;if(i===null)return null;const s=tl(e,t);if(s===null)return null;const l=nl(e,o,s),h=l.findIndex(g=>Ie(g)===Ie(i));if(h<0||h>=l.length-1)return null;const u={variable:o,oneOf:l.slice(h)},p=s.length===0?u:{and:[u,...s]};return{label:Go(e,o,i,n,r),predicate:p}},tl=(e,t)=>{const n=[];for(const r of(0,d.getGroupVariables)(e.data,e.mapping)){const o=t[r]??null;if(o===null)return null;n.push({variable:r,eq:o})}return n},nl=(e,t,n)=>{const r=new Map;for(let o=0;o<e.data.size();o+=1){const i=e.data.getAt(o);if(i===null||!rl(i,n))continue;const s=i[t]??null;if(s===null)continue;const l=i[d.POSITION_VARIABLES.x],h=typeof l=="number"?l:o,u=Ie(s),p=r.get(u);(p===void 0||h<p.position)&&r.set(u,{value:s,position:h})}return[...r.values()].sort((o,i)=>o.position-i.position).map(o=>o.value)},rl=(e,t)=>t.every(n=>Ie(e[n.variable]??null)===Ie(n.eq)),ol=(e,t,n)=>{for(let r=0;r<e.data.size();r+=1){const o=e.data.getAt(r);if(o===null)continue;const i=No(o,t);if(i!==null&&i>n)return!0}return!1},No=(e,t)=>{const n=e[d.POSITION_VARIABLES.yRaw],r=typeof n=="number"?n:e[t];return typeof r=="number"&&Number.isFinite(r)?r:null},Go=(e,t,n,r,o)=>{const i=(0,d.createValueFormatter)({valueFormat:e.data.getValueFormat(t),locale:r,numberFormat:o})(n);return i.length>0?i:String(n)},Ie=e=>e instanceof Date?String(e.getTime()):String(e),st=(e,t)=>"and"in e||"and"in t?"and"in e&&"and"in t&&Un(e.and,t.and):"or"in e||"or"in t?"or"in e&&"or"in t&&Un(e.or,t.or):"not"in e||"not"in t?"not"in e&&"not"in t&&st(e.not,t.not):e.variable!==t.variable?!1:"eq"in e||"eq"in t?"eq"in e&&"eq"in t&&me(e.eq,t.eq):"oneOf"in e||"oneOf"in t?"oneOf"in e&&"oneOf"in t&&$n(e.oneOf,t.oneOf):"lt"in e||"lt"in t?"lt"in e&&"lt"in t&&me(e.lt,t.lt):"lte"in e||"lte"in t?"lte"in e&&"lte"in t&&me(e.lte,t.lte):"gt"in e||"gt"in t?"gt"in e&&"gt"in t&&me(e.gt,t.gt):"gte"in e||"gte"in t?"gte"in e&&"gte"in t&&me(e.gte,t.gte):"range"in e&&"range"in t&&$n(e.range,t.range),Un=(e,t)=>e.length===t.length&&e.every((n,r)=>{const o=t[r];return o!==void 0&&st(n,o)}),$n=(e,t)=>e.length===t.length&&e.every((n,r)=>{const o=t[r];return o!==void 0&&me(n,o)}),me=(e,t)=>e instanceof Date||t instanceof Date?e instanceof Date&&t instanceof Date&&e.getTime()===t.getTime():e===t,al=(e,t)=>{const n=c.useSceneSelector(o=>o.spec.highlights),r=c.useSceneSelector(o=>o.config.parsingLocale);return(0,b.useMemo)(()=>(0,d.findHighlightsAtObservation)({layer:e,highlights:n,observation:t,parsingLocale:r}),[e,n,t,r])},il={pinnedNumber:!0,comment:!0,sticker:!0,image:!1},sl=e=>(0,d.isObservationAttachmentKind)(e.kind)&&il[e.kind],dt=(e,t)=>(0,b.useMemo)(()=>{if(e===null)return{options:[],findValue:()=>{}};const{parsingLocale:n,numberFormat:r}=e.config,o=t??n,i=e.guides.colorGroups.map(s=>{const l=(0,d.createValueFormatter)({valueFormat:s.valueFormat,locale:o,numberFormat:r}),h=s.value instanceof Date?s.value.getTime():s.value;return{value:h,option:{value:String(h),label:s.label??l(s.value)}}});return{options:i.map(({option:s})=>s),findValue:s=>i.find(l=>l.option.value===s)?.value}},[e,t]),Bo=({scene:e,layer:t,observation:n,groupOptions:r,locale:o,t:i})=>{const s=Ft(e,t,n,r);return{observation:i(dl(e,t)),xValue:i("editor.overlayMenu.allOf",{name:Fo(e,t,n,o)}),group:s===null?i("editor.overlayMenu.all"):i("editor.overlayMenu.allOf",{name:s})}},Bt=({scene:e,layer:t,observation:n,groupOptions:r,locale:o,t:i},s)=>{const l=(0,d.getGroupVariables)(t.data,t.mapping),h=Fo(e,t,n,o);switch(s){case"observation":{const u=l.length===0?null:Ft(e,t,n,r),p=ll(u,h,i);return{whole:p,value:p}}case"xValue":return Xn((0,d.findAxisGuide)(e.guides,"x")?.label??null,h,i);case"group":{const u=Ft(e,t,n,r)??i("editor.overlayMenu.all");return Xn(cl(e,l),u,i)}default:return s}},ll=(e,t,n)=>e===null?t:t===""?e:n("editor.overlayMenu.groupAtBand",{group:e,band:t}),Xn=(e,t,n)=>({whole:e===null||e===""?t:n("editor.overlayMenu.titledValue",{title:e,value:t}),value:t}),cl=(e,t)=>{const[n,...r]=t;return n===void 0||r.length>0?null:e.guides.variableLabels[n]??null},dl=(e,t)=>{switch(t.geom){case"bar":return e.coordSystem.type==="polar"&&e.coordSystem.bandAxis===null?"editor.overlayMenu.thisSlice":"editor.overlayMenu.thisBar";case"point":return(0,d.readVariableName)(t.mapping.size)===null?"editor.overlayMenu.thisPoint":"editor.overlayMenu.thisBubble";default:return"editor.overlayMenu.thisPoint"}},Fo=(e,t,n,r)=>{const o=(0,d.findAxisGuide)(e.guides,"x");return(0,d.createValueFormatter)({valueFormat:o===null?{type:"text"}:(0,d.resolveLayerAxisValueFormat)(o,t.id),locale:r,numberFormat:e.config.numberFormat})((0,d.createXValueReader)(t.data,t.mapping)(n),n)},Ft=(e,t,n,r)=>{const o=(0,d.getGroupVariables)(t.data,t.mapping);return o.length===0?ul(t,n)??hl(e,t):o.map(i=>pl(n[i]??null,r)).join(", ")},ul=(e,t)=>{const n=(0,d.readColorPart)(e,t);return n===void 0?void 0:e.styles.parts[n]?.label},hl=(e,t)=>{const n=(0,d.readVariableName)(t.mapping.y),r=n===null?void 0:e.guides.variableLabels[n];return r===void 0||r===""?null:r},pl=(e,t)=>{const n=String(e instanceof Date?e.getTime():e);return t.options.find(r=>r.value===n)?.label??n},gl="vez73g0",Ht="vez73g1",Ho="vez73g2",ml="vez73g3",vl="vez73g4";var xl="vez73g6",fl="vez73g7",yl="vez73g8",zo="vez73g9",Wo="vez73ga",Vo=[Ho,xl,vl,ml],Sl=Vo.map(e=>`.${e}`).join(", "),bl=Vo.flatMap(e=>[`.${e} button`,`.${e} input`]).join(", "),Ko=e=>{const t=e.target;if(!(t instanceof HTMLElement))return;const n=e.currentTarget,r=t.closest(`.${Ht}, ${Sl}`),o=t.closest(`.${Ht}`)!==null;if((e.key==="ArrowRight"||e.key==="ArrowLeft")&&t instanceof HTMLButtonElement&&r!==null){const i=[...r.querySelectorAll("button")],s=i.indexOf(t);if(s<0)return;e.preventDefault();const l=getComputedStyle(r).direction==="rtl";i[(s+(e.key==="ArrowRight"?1:-1)*(l?-1:1)+i.length)%i.length]?.focus();return}if(e.key==="ArrowDown"&&o){const i=n.querySelector(bl);if(i===null)return;e.preventDefault(),i.focus();return}e.key==="ArrowUp"&&!o&&r!==null&&(e.preventDefault(),n.querySelector('[aria-expanded="true"]')?.focus())},cn={fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round"},Uo=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M5 19L19 5M10 5h9v9",...cn})}),Cl=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M6 18L18 6M6 18v-6M6 18h6M18 6h-6M18 6v6",...cn})}),wl=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M5 19L19 5",...cn})}),ae={side:"top",delay:200},$o={pinnedNumber:{phrase:"graph.annotations.baseMenu.unpinNumber",Icon:Mo},comment:{phrase:"graph.annotations.baseMenu.removeAnnotation",Icon:Eo},sticker:{phrase:"graph.annotations.baseMenu.removeSticker",Icon:Oo}},Xo=new Set(["barSeries","lineSeries","scatterSeries"]),Tl=new Set(["bar","linePoint","scatterPoint","pieSlice"]),dn=e=>{const t=({target:n})=>{const r=ro(n);return r===null?null:(0,a.jsx)(Al,{anchor:r,readHighlightOptions:e})};return t.hasRows=(n,{scene:r})=>no(n,r)!==null,t},Ye=dn((e,t)=>Ys(t,e)),qn=dn(Ro),jl=dn(_o),Al=({anchor:e,readHighlightOptions:t})=>{const{layer:n,observation:r,observationIndex:o,at:i}=e,s=v.useStartArrowDraw(),l=c.useI18n(),{dispatch:h,paintPreview:u,clearPreview:p}=c.useGraphCommands(),{selectionStore:g,findGeom:m}=c.useGraphContext(),f=v.useRemoveAnnotationCommand(),x=(0,b.useRef)(null),y=(0,b.useRef)(p);y.current=p;const{Button:w}=v.useControls(),S=c.useSceneSelector(E=>E),I=S.spec.annotations,j=S.config.parsingLocale,A=S.config.numberFormat,T=c.useFormattingLocale(),M={scene:S,layer:n,observation:r,groupOptions:dt(S,T),locale:T,t:l},G=Bt(M,"xValue").value,L=Bt(M,"group").value,B=Bo(M).observation,R=(0,b.useMemo)(()=>(0,d.createObservationAnchorParser)(n,j),[n,j]),k=(0,d.findObservationAttachment)(I,i,R,(0,b.useMemo)(()=>(0,d.createObservationAnchorLander)({layers:S.layers,coordSystem:S.coordSystem,findGeom:m,readAnchor:R}),[S.layers,S.coordSystem,m,R])),_=k!==null&&sl(k)?k:null,O=x.current,C=_!==null&&O?.key.startsWith("sticker:")===!0&&_.kind==="sticker"?null:_,D=C?.kind==="comment"?C.annotation.content:null,z=D===null?"":Fl(D)??void 0,[P,F]=(0,b.useState)(()=>Gl(_?.kind)),H=al(n,r),W=S.coordSystem,U=t(n,W),$=U.length===0?[]:Js(n,r,T,A),Y=x.current?.heldHighlight,J=Y===void 0?H:[...H,Y],V=(0,b.useMemo)(()=>(0,d.inferDifferenceArrowEndpoints)({layer:n,at:i,coordSystem:W}),[n,i,W]),X=Rl({layer:n,observation:r,highlights:J,highlightOptions:U,reaches:$,previewedChoiceId:x.current?.choiceId,scopeLabel:E=>Dl(l,E,G,L,B),scopeDescription:E=>Nl(l,E,Yn(l,n,U),G,L,U.some(K=>Xo.has(K.labelKey))),atLeastLabel:E=>l("graph.annotations.highlights.atLeast",{value:E}),atLeastDescription:E=>l("graph.annotations.highlights.atLeastDescription",{noun:Yn(l,n,U),value:E}),onwardLabel:E=>l("graph.annotations.highlights.onward",{label:E}),onwardDescription:E=>l("graph.annotations.highlights.onwardDescription",{label:E})}),ue=(0,d.buildObservationPredicate)(n,r),Ce=new Set(X?.available.map(E=>E.id)??[]),oe=H.filter(E=>{const K=Do(E,$,ue);return K===null||!Ce.has(K)}).at(-1),ne=()=>{x.current!==null&&(x.current=null,y.current())};(0,b.useEffect)(()=>()=>ne(),[]);const De=(E,K,te,we)=>{x.current?.key!==E&&(ne(),x.current={key:E,choiceId:te,heldHighlight:we},u(K)||(x.current=null))},se=E=>{ne(),h(E),g.getState().clearSelection()},Ne=(E,K)=>{if(x.current?.key===E){x.current=null,y.current(),h(K),g.getState().clearSelection();return}se(K)},xt=(E,K,te,we)=>({onPointerEnter:()=>De(E,K,te,we),onPointerLeave:ne,onClick:()=>Ne(E,K)}),he=E=>{ne(),F(K=>K===E?null:E)},Ge=E=>{if(V===null)return;ne();const K=(0,d.areAnchorsEqual)(V.start,i)?V.end:V.start,te=new d.AddAnnotationCommand({kind:"differenceArrow",annotation:{...d.DIFFERENCE_ARROW_DEFAULTS,start:i,end:K,label:E}});h(te),g.getState().setSelection([{kind:"annotation",id:te.params.annotation.id}])};return(0,a.jsxs)("div",{className:gl,role:"toolbar","aria-label":l("graph.annotations.baseMenu.annotate"),onKeyDown:E=>{if(C!==null&&Bl(E)){se(f(C.annotation.id));return}Ko(E)},children:[(0,a.jsxs)("div",{className:Ht,children:[X!==null&&(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.highlight"),icon:(0,a.jsx)(Kn,{}),expanded:P==="highlight",onClick:()=>he("highlight")}),oe!==void 0&&(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.removeHighlight"),icon:(0,a.jsx)(Vn,{children:(0,a.jsx)(Kn,{})}),onClick:()=>se(new d.RemoveHighlightCommand({id:oe.id}))}),C!==null&&(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l($o[C.kind].phrase),icon:(0,a.jsx)(Vn,{children:Pl(C.kind)}),onClick:()=>se(f(C.annotation.id))}),C===null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.pinNumber"),icon:(0,a.jsx)(Mo,{}),onClick:()=>se(new d.AddAnnotationCommand({kind:"pinnedNumber",annotation:{at:i}}))}),(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.addNote"),icon:(0,a.jsx)(Eo,{}),expanded:P==="comment",onClick:()=>he("comment")})]}),V!==null&&(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.differenceArrow"),icon:(0,a.jsx)(wt,{}),expanded:P==="difference",onClick:()=>he("difference")}),(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.arrowFromHere"),icon:(0,a.jsx)(Uo,{}),onClick:(...E)=>{ne(),s({start:{...i,anchorType:"observation",align:"auto"},startObservationIndex:o},E[0])}}),C===null&&(0,a.jsx)(w,{variant:"icon",...ae,ariaLabel:l("graph.annotations.baseMenu.addSticker"),icon:(0,a.jsx)(Oo,{}),expanded:P==="sticker",onClick:()=>he("sticker")})]}),P==="comment"&&z!==void 0&&(0,a.jsx)("div",{className:"vez73g6",children:(0,a.jsx)(Il,{at:i,onRun:se,annotationId:C?.kind==="comment"?C.annotation.id:void 0,initialText:z})}),P==="sticker"&&(0,a.jsx)("div",{className:"vez73g2",children:(0,a.jsx)(kl,{at:i,showPreview:De,dropPreview:ne,keepPreview:Ne,annotationId:C?.kind==="sticker"?C.annotation.id:void 0})}),P==="difference"&&(0,a.jsxs)("div",{className:"vez73g4",children:[(0,a.jsx)(w,{variant:"icon",ariaLabel:l("graph.annotations.differenceArrowToolbar.labelKind.asPercent"),icon:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(wt,{size:"sm"}),(0,a.jsx)("span",{className:"vez73g5","aria-hidden":"true",children:"%"})]}),onClick:()=>Ge("relativeDifference")}),(0,a.jsx)(w,{variant:"icon",ariaLabel:l("graph.annotations.differenceArrowToolbar.labelKind.asNumber"),icon:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(wt,{size:"sm"}),(0,a.jsx)("span",{className:"vez73g5","aria-hidden":"true",children:"+n"})]}),onClick:()=>Ge("absoluteDifference")})]}),P==="highlight"&&X!==null&&(0,a.jsx)("div",{className:"vez73g3",children:X.available.map(E=>{const K=E.appliedHighlightId,te=K===void 0?Ml(E,n.id):new d.RemoveHighlightCommand({id:K}),we=K===void 0?void 0:J.find(ai=>ai.id===K);return(0,a.jsx)(w,{label:E.label,pressed:K!==void 0,tooltip:E.description===E.label?void 0:E.description,...ae,...xt(Ll(E.id),te,K===void 0?E.id:void 0,we)},E.id)})})]})},Pl=e=>{const t=$o[e].Icon;return(0,a.jsx)(t,{})},Il=({at:e,onRun:t,annotationId:n,initialText:r=""})=>{const o=c.useI18n(),{Button:i,TextField:s}=v.useControls(),[l,h]=(0,b.useState)(r),u=(0,b.useRef)(null),p=l.trim();(0,b.useEffect)(()=>{const m=u.current?.querySelector("input");m instanceof HTMLInputElement&&m.focus({preventScroll:!0})},[]);const g=()=>{if(p.length===0)return;const m=Hl(p);t(n===void 0?new d.AddAnnotationCommand({kind:"comment",annotation:{at:e,content:m}}):new d.UpdateAnnotationCommand({kind:"comment",id:n,patch:{content:m}}))};return(0,a.jsxs)("form",{ref:u,className:fl,onSubmit:m=>{m.preventDefault(),g()},children:[(0,a.jsx)("div",{className:yl,children:(0,a.jsx)(s,{value:l,onChange:h,placeholder:o("graph.annotations.textMenu.placeholder")})}),(0,a.jsx)(i,{label:o("graph.annotations.textMenu.addButton"),onClick:g,disabled:p.length===0})]})},kl=({at:e,showPreview:t,dropPreview:n,keepPreview:r,annotationId:o})=>{const i=c.useStickerImages();return i===null?null:(0,a.jsx)(a.Fragment,{children:Object.entries(i).map(([s,l])=>{const h=Ol(e,s,o);return(0,a.jsx)("button",{type:"button",className:Wo,"aria-label":s,onPointerEnter:()=>t(h.key,h.command),onPointerLeave:n,onClick:()=>r(h.key,h.command),children:(0,a.jsx)("img",{className:zo,src:l,alt:""})},s)})})},Ll=e=>`highlight:${e}`,El=e=>`sticker:${e}`,Ml=(e,t)=>new d.AddHighlightCommand({predicate:e.predicate,scope:e.scope,layerId:t}),Ol=(e,t,n)=>n===void 0?{key:El(t),command:new d.AddAnnotationCommand({kind:"sticker",annotation:{at:{anchorType:"observation",...e},sticker:t}})}:{key:`swap:${t}`,command:new d.UpdateAnnotationCommand({kind:"sticker",id:n,patch:{sticker:t}})},Rl=({layer:e,observation:t,highlights:n,highlightOptions:r,reaches:o,previewedChoiceId:i,scopeLabel:s,scopeDescription:l,atLeastLabel:h,atLeastDescription:u,onwardLabel:p,onwardDescription:g})=>{if(e.highlight===null)return null;const m=(0,d.buildObservationPredicate)(e,t),f=new Map;for(const j of n){const A=Do(j,o,m);A===null||A===i||f.set(A,j.id)}const x=m===null?[]:r.map(j=>{const A=s(j.labelKey);return{id:j.scope,label:A,description:l(j.labelKey),icon:j.labelKey,predicate:m,scope:j.scope,appliedHighlightId:f.get(j.scope)}}),y=o.map(j=>({..._l(j,h,u,p,g),appliedHighlightId:f.get(j.id)})),[w,...S]=x,I=w===void 0?y:[w,...y,...S];return I.length===0?null:{available:I}},_l=(e,t,n,r,o)=>{switch(e.id){case"gte":return{id:e.id,label:t(e.valueLabel),description:n(e.valueLabel),icon:null,predicate:e.predicate,scope:"observation"};case"onward":return{id:e.id,label:r(e.categoryLabel),description:o(e.categoryLabel),icon:null,predicate:e.predicate,scope:"observation"};default:return e}},Dl=(e,t,n,r,o)=>{const i=e(`graph.annotations.highlights.labels.${t}`);if(Tl.has(t))return o;if(t==="barGroup"||t==="barStack")return n===""?i:e("editor.overlayMenu.allOf",{name:n});if(!Xo.has(t))return i;const s=e("editor.overlayMenu.all");return r===""||r===s?i:e("editor.overlayMenu.allOf",{name:r})},Yn=(e,t,n)=>{if(t.geom==="point"&&(0,d.readVariableName)(t.mapping.size)!==null)return e("graph.annotations.highlights.nouns.bubble");const r=n.find(o=>o.scope==="observation")??n[0];return e(r===void 0?"graph.annotations.highlights.labels.pointOrBar":`graph.annotations.highlights.labels.${r.labelKey}`)},Nl=(e,t,n,r,o,i)=>{switch(t){case"bar":case"linePoint":case"scatterPoint":case"pieSlice":return!i&&r!==""?e("graph.annotations.highlights.justValue",{label:r}):e("graph.annotations.highlights.justThis",{noun:n});case"barGroup":return r===""?e("graph.annotations.highlights.wholeGroup"):e("graph.annotations.highlights.everyIn",{noun:n,name:r});case"barStack":return r===""?e("graph.annotations.highlights.wholeStack"):e("graph.annotations.highlights.everyIn",{noun:n,name:r});case"barSeries":case"lineSeries":case"scatterSeries":return o===""||o===e("editor.overlayMenu.all")?e("graph.annotations.highlights.wholeSeries"):e("graph.annotations.highlights.everyNamed",{name:o,noun:n});default:return t}},Gl=e=>e==="comment"?"comment":e==="sticker"?"sticker":null,Bl=e=>{if(e.key!=="Delete"&&e.key!=="Backspace")return!1;const t=e.target;return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?!1:(e.preventDefault(),!0)},Fl=e=>{if(e.type!=="doc"||e.content?.length!==1)return null;const t=e.content[0];if(t?.type!=="paragraph"||Zn(t)||Jn(t)||t.content?.length!==1)return null;const n=t.content[0];return n?.type!=="text"||n.text===void 0||n.content!==void 0||Zn(n)||Jn(n)?null:n.text},Zn=e=>e.marks!==void 0&&e.marks.length>0,Jn=e=>e.attrs!==void 0&&Object.keys(e.attrs).length>0,Hl=e=>({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:e}]}]}),un=({target:e})=>{const t=c.useGraphHandle();return t===null?null:(0,a.jsx)(zl,{graph:t,target:e})};un.hasRows=(e,t)=>(0,d.isLayerSpecOf)((0,d.findLayerById)(t.scene.spec.layers,e.layerId),"point")?!0:re.hasRows(e,t);var zl=({graph:e,target:t})=>{const n=c.useHandleScene(e),r=c.useStyleReaderTree(),o=n===null?void 0:(0,d.findLayerById)(n.spec.layers,t.layerId);if(n===null||!(0,d.isLayerSpecOf)(o,"point"))return(0,a.jsx)(re,{target:t});const i=(0,d.readObservationsColorRoute)(n.spec,t)?.find(h=>h.geomKind==="point")?.where,s=i===void 0?{}:{where:i},l=(0,d.readVariableName)((0,d.findLayerById)(n.layers,o.id)?.mapping.size)!==null;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(re,{target:t}),!l&&(0,a.jsx)(an,{sizePx:Po(n,r,o.id,i),onChange:h=>{e.commands.dispatch(new d.SetPointSizeCommand({layerId:o.id,size:h,...s}))}}),(0,a.jsx)(on,{symbol:Io(n,r,o.id,i),coordType:n.coordSystem.type,onChange:h=>{e.commands.dispatch(new d.SetPointSymbolCommand({layerId:o.id,symbol:h,...s}))}})]})},qo={geoms:{point:{style:un,annotate:jl},line:{style:it,annotate:qn},area:{style:it,annotate:qn},bar:{style:nn,annotate:Ye},rule:{style:null,annotate:Ye},tile:{style:re,annotate:Ye}},legend:Ao,axis:tn,grid:ln,graph:sn},hn=(0,b.createContext)([qo]),Wl=({editMenus:e,children:t})=>{const n=(0,b.useMemo)(()=>[e??{},qo],[e]);return(0,a.jsx)(hn.Provider,{value:n,children:t})},Vl=e=>{const t=(0,b.useContext)(hn),n=c.useSceneSelector(s=>s),{findGeom:r}=c.useGraphContext(),o=c.useDataLabelPlacementResolver(),i=Yo(c.useGraphMode());return(0,b.useMemo)(()=>e===null?null:Zo(e,t,{scene:n,dataLabelPlacement:o,findGeom:r},i),[e,t,n,o,r,i])},Kl=()=>{const e=(0,b.useContext)(hn),{store:t,findGeom:n}=c.useGraphContext(),r=c.useDataLabelPlacementResolver(),o=Yo(c.useGraphMode());return(0,b.useCallback)(i=>Zo(i,e,{scene:t.getState().scene,dataLabelPlacement:r,findGeom:n},o)!==null,[e,t,r,n,o])},Yo=e=>e===c.GRAPH_MODES.annotate?"annotate":"style",Zo=(e,t,n,r)=>{if(r==="annotate"&&e.kind!=="observations")return null;switch(e.kind){case"observations":{const o=Os(e.layerId,n.scene),i=o===null?null:Rs(o,t,r,r==="annotate"?Ye:re);return i===null||i.hasRows?.(e,n)===!1?null:(0,a.jsx)(i,{target:e})}case"legend":{const o=We(t,i=>i.legend);return o===null||o.hasRows?.(e,n)===!1?null:(0,a.jsx)(o,{target:e})}case"axis":{const o=We(t,i=>i.axis);return o===null||o.hasRows?.(e,n)===!1?null:(0,a.jsx)(o,{target:e})}case"grid":{const o=We(t,i=>i.grid);return o===null||o.hasRows?.(e,n)===!1?null:(0,a.jsx)(o,{target:e})}case"graph":{const o=We(t,i=>i.graph);return o===null||o.hasRows?.(e,n)===!1?null:(0,a.jsx)(o,{target:e})}default:return e}},Ul={"en-GB":()=>Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs")).then(e=>({"en-GB":e.EDITOR_EN_GB})),"en-US":()=>Promise.all([Promise.resolve().then(()=>require("./en-us-CfL-X7mL.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({"en-US":e.EDITOR_EN_US,"en-GB":t.EDITOR_EN_GB})),ar:()=>Promise.all([Promise.resolve().then(()=>require("./ar-DRJfF3kx.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({ar:e.EDITOR_AR,"en-GB":t.EDITOR_EN_GB})),"pt-PT":()=>Promise.all([Promise.resolve().then(()=>require("./pt-pt-Dl-e1WyP.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({"pt-PT":e.EDITOR_PT_PT,"en-GB":t.EDITOR_EN_GB}))},zt=new Map,Tt=new Map,Qn=e=>zt.get(e)??null,$l=e=>{const t=zt.get(e);if(t!==void 0)return Promise.resolve(t);const n=Tt.get(e);if(n!==void 0)return n;const r=Ul[e]().then(o=>(zt.set(e,o),o)).catch(o=>{throw Tt.delete(e),o});return Tt.set(e,r),r},Xl=e=>{const[,t]=(0,b.useState)(null);return(0,b.useEffect)(()=>{if(Qn(e)!==null)return;let n=!1;return $l(e).then(()=>{n||t(e)},r=>{console.error(r)}),()=>{n=!0}},[e]),Qn(e)},pn=({children:e,locale:t,...n})=>{const r=Xl(c.normalizeLocale(t));return(0,a.jsx)(c.IntlProvider,{dictionaries:(0,b.useMemo)(()=>r===null?[c.dictionaries]:[r,c.dictionaries],[r]),locale:t,...n,children:(0,a.jsx)(ql,{children:e})})},ql=({children:e})=>(0,a.jsx)(en.DirectionProvider,{direction:c.useTextDirection(),children:e}),Yl={Title:null,Caption:null,TextAnnotation:null},Zl=(e,t)=>t===null?Yl:c.MODE_RULES[e].editTextInline?{Title:t.TitleEditor,Caption:t.CaptionEditor,TextAnnotation:t.TextAnnotationEditor}:{Title:null,Caption:null,TextAnnotation:t.TextAnnotationEditor},Ze=null,jt=null,Jl=()=>Ze!==null?Promise.resolve(Ze):(jt??=Promise.resolve().then(()=>require("./rich-text-editor-module-DiUIhnGd.cjs")).then(e=>(Ze=e,e)).catch(e=>{throw jt=null,e}),jt),Jo=()=>{const[e,t]=(0,b.useState)(Ze);return(0,b.useEffect)(()=>{let n=!1;return Jl().then(r=>{n||t(r)},r=>{console.error(r)}),()=>{n=!0}},[]),e},Ql=({children:e})=>{const t=c.useEditorStore();return(0,a.jsx)(c.RememberTextCaretProvider,{remember:(0,b.useCallback)((n,r)=>{t.getState().setPendingTextCaret({slot:n,x:r.clientX,y:r.clientY})},[t]),children:e})},ec="_10igzta0",tc=({rect:e,zIndex:t,container:n,boxRef:r,children:o,...i})=>n===null?null:(0,ii.createPortal)((0,a.jsx)("div",{...i,ref:r,className:ec,style:{transform:`translate(${e.left}px, ${e.top}px)`,width:e.width,height:e.height,zIndex:t},children:o}),n),nc="kwvn4c0",rc="kwvn4c1",oc=(e,t)=>({contextElement:e,getBoundingClientRect:()=>{const n=e.getBoundingClientRect(),r=v.readFrameScale(e,n.width);return new DOMRect(n.left+t.x*r,n.top+t.y*r,t.width*r,t.height*r)}}),ac=({side:e,boundary:t,spans:n,anchor:r,rightToLeft:o})=>{if(!sc(e))return 0;const i=n[e];if(e==="left"||e==="right")return er(i.from-t.y,r.height,t.height);const s=o?t.x+t.width-i.to:i.from-t.x;return er(s,r.width,t.width)},ic=()=>{const[e,t]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{t(!0)},[]),e},sc=e=>c.SIDE_KEYS.some(t=>t===e),er=(e,t,n)=>n===0?0:e*t/n,lc={x:8,y:8},cc={side:"flip",align:"shift",fallbackAxisSide:"end"},Qo=({frameElement:e,boundary:t,spans:n,clearance:r=lc,onEscape:o,children:i})=>{const s=v.useChartChromeContainer(),l=ic(),[h,u]=(0,b.useState)(null),p=(0,b.useRef)(null),g=(0,b.useCallback)(A=>{p.current=A,u(A)},[]),m=(0,b.useRef)(null);(0,b.useLayoutEffect)(()=>()=>{h?.contains(document.activeElement)&&e.focus({preventScroll:!0})},[h,e]);const{x:f,y:x,width:y,height:w}=t,S=(0,b.useMemo)(()=>({box:{x:f,y:x,width:y,height:w},spans:n}),[f,x,y,w,n]),I=(0,b.useMemo)(()=>oc(e,S.box),[e,S]),j=(A,T)=>{A||(T.cancel(),T.reason==="escape-key"&&o())};return(0,a.jsx)(je.Popover.Root,{open:l,modal:!1,onOpenChange:j,children:(0,a.jsx)(je.Popover.Portal,{container:s,className:v.basePortal,children:(0,a.jsx)(v.EditorPortalThemeProvider,{children:(0,a.jsx)(je.Popover.Positioner,{ref:m,anchor:I,side:"right",align:"start",sideOffset:({side:A})=>A==="top"||A==="bottom"?r.y:r.x,alignOffset:({side:A,anchor:T})=>ac({side:A,boundary:S.box,spans:S.spans,anchor:T,rightToLeft:dc(m.current)}),collisionAvoidance:cc,sticky:!0,className:nc,...v.MENU_STAMP,children:(0,a.jsx)(je.Popover.Popup,{ref:g,className:rc,initialFocus:p,finalFocus:!1,"data-testid":"anchored-popover",children:i})})})})})},dc=e=>e!==null&&getComputedStyle(e).direction==="rtl",ye=(e,t)=>{const n=c.useSceneSelector((0,ee.useShallow)(s=>({spec:s.spec.annotations,compiled:s.annotations,layers:s.layers,coordSystem:s.coordSystem}))),r=c.useResolvedAnnotations(e),o=c.useMeasuredBoxes(),i=c.usePaintedObservationBoxes(e);return c.useLatestRef({...n,scene:r,panelRect:e,frameElement:t,measuredBoxes:o,readObservationBox:i})},uc=({drop:e,startRect:t,size:n,panelRect:r,bounds:o})=>{const i=(0,d.readFacingAlign)({x:e.x,y:e.y,width:0,height:0},t),s=i==="center"?"left":i,l=(0,d.readOutwardGapOffset)(s,d.ARROW_TARGET_GAP_PX),h=(0,d.alignUnitFractions)(s),u=e.x-(l?.x??0)-h.x*n.width,p=e.y-(l?.y??0)-h.y*n.height;return{align:s,rect:{x:tr(u,n.width,o.minX*r.width,o.maxX*r.width),y:tr(p,n.height,o.minY*r.height,o.maxY*r.height),...n}}},hc=({rect:e},t,n)=>{const r=(0,d.alignUnitFractions)(t);return{x:(e.x+r.x*e.width)/n.width,y:(e.y+r.y*e.height)/n.height}},tr=(e,t,n,r)=>Math.max(n,Math.min(e,r-t)),Je=(e,t,n)=>e.arrows.find(r=>r.id===t)?.[n]??null,ea=(e,t,n)=>{const r=Je(e,t,n);return r?.anchorType==="panel"?r:null},ta=(e,t)=>e==="start"?{start:t}:{end:t},na=(e,t,n)=>{const{scene:r,panelRect:o,measuredBoxes:i,readObservationBox:s}=n;if(e.anchorType==="annotation"){const u=(0,d.indexSceneAnnotations)(r).get(e.ref),p=u===void 0?null:(0,d.readAnnotationBox)(u,o,i);return p===null?null:(0,d.projectBoxToPanel)(p,o)}if(e.anchorType!=="observation"||e.layerId===void 0||t===void 0)return null;const l={layerId:e.layerId,observationIndex:t};if(e.align==="auto")return pc(l,n);const h=s(l);return h===null?null:(0,d.projectBoxToPanel)(h,o)},gn=(e,t,n)=>{const r=(0,d.projectAnchorToPanel)(t,n.panelRect),o={x:r.x,y:r.y,width:0,height:0};return!("align"in e)||e.align!=="auto"?o:na(e,t.observationIndex,n)??o},pc=({layerId:e,observationIndex:t},{panelRect:n,layers:r,coordSystem:o,readObservationBox:i,anchorResolver:s})=>{const l=r.find(f=>f.id===e),h=o.type==="polar"||l!==void 0&&(0,d.isPointTarget)(s.resolveSnapAligns(l.geom,o))?null:i({layerId:e,observationIndex:t}),u=h===null?null:(0,d.projectBoxToPanel)(h,n);if(u!==null&&u.width>0&&u.height>0)return u;const p=l?.data.getAt(t)??null;if(l===void 0||p===null)return u;const g=s.resolve(l.geom,p,{coordSystem:o,position:l.position,purpose:"pin"});if(g===null)return u;const m=(0,d.projectAnchorToPanel)(g,n);return{x:m.x,y:m.y,width:0,height:0}};var Ee={fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round"},gc=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M5 6V4h14v2M12 4v16M9 20h6",...Ee})}),mc=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M5 4h14v10l-6 6H5zM13 20v-6h6",...Ee})}),vc=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M5 19L19 5M10 5h9v9",...Ee})}),xc=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M4 6h16v12H4z",...Ee})}),fc=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 24 24",...e,children:(0,a.jsx)("path",{d:"M12 3a9 9 0 1 0 0 18 9 9 0 1 0 0-18zM8.5 14.5s1.3 2 3.5 2 3.5-2 3.5-2M9 9.5h.01M15 9.5h.01",...Ee})}),pe={side:"top",delay:200},At=.2,yc={type:"doc",content:[{type:"paragraph"}]},nr={paddingInline:12,paddingBlock:10},Sc=24,bc=({frameElement:e,panelRect:t})=>{const n=c.useEditorState(r=>r.plotMenu);return n===null?null:(0,a.jsx)(Cc,{frameElement:e,panelRect:t,point:n},`${n.x}:${n.y}:${n.arrowId??""}`)},Cc=({frameElement:e,panelRect:t,point:n})=>{const r=c.useI18n(),o=c.useEditorStore(),{commands:i,history:s,selectionStore:l,anchorResolver:h}=c.useGraphContext(),{Button:u,ColorSwatches:p}=v.useControls(),g=v.useCanvasColorNames(),m=v.usePaletteColors(),f=v.usePlaceholderWidthFit(),[x,y]=(0,b.useState)({kind:"choose"}),w=c.useEditorState(P=>P.standingInteraction?.kind==="box-draw"),S=c.useEditorState(P=>P.standingInteraction?.kind==="arrow-draw"),I=!w&&!S,j=n.arrowId,A=ye(t,e),T=c.useStyleReaderTree().graph().get("textScale"),M=c.useSceneSelector(P=>j===void 0||P.spec.annotations.arrows.some(F=>F.id===j)),G=()=>{ge(o),o.getState().setPlotMenu(null),j!==void 0&&l.getState().setSelection([{kind:"annotation",id:j}])};(0,b.useEffect)(()=>{M||o.getState().setPlotMenu(null)},[M,o]);const L=(P,F)=>{const H={at:{anchorType:"panel",x:n.x,y:n.y}};if(j===void 0)return H;const W=A.current,U=W.spec.arrows.find(V=>V.id===j),$=W.scene.arrows.find(V=>V.id===j);if(U===void 0||$===void 0)return H;const Y=uc({drop:{x:n.x*t.width,y:n.y*t.height},startRect:gn(U.start,$.start,{...W,anchorResolver:h}),size:P,panelRect:t,bounds:v.readContainerFractionBoundsFor(t,e)}),J=F??Y.align;return{at:{anchorType:"panel",...hc(Y,J,t)},align:J}},B=(P,F=[])=>{const H=[P,...F];j!==void 0&&H.push(new d.UpdateAnnotationCommand({kind:"arrow",id:j,patch:{end:{anchorType:"annotation",ref:P.params.annotation.id,align:"auto"}}})),i.dispatch(H.length===1?P:new d.SequenceCommand({commands:H}))};(0,b.useEffect)(()=>()=>ge(o),[o]);const R={x:t.x+n.x*t.width,y:t.y+n.y*t.height,width:1,height:1},k={top:{from:R.x,to:R.x+R.width},bottom:{from:R.x,to:R.x+R.width},left:{from:R.y,to:R.y+R.height},right:{from:R.y,to:R.y+R.height}},_=P=>{ge(o),y(F=>F.kind===P?{kind:"choose"}:{kind:P})},O=P=>(...F)=>{o.getState().claimInteraction({kind:"arrow-draw",heads:P,start:{anchorType:"panel",x:n.x,y:n.y},pointer:c.readClickPoint(F[0])})},C=(...P)=>{if(o.getState().standingInteraction?.kind==="box-draw"){o.getState().releaseInteraction("box-draw");return}ge(o),y({kind:"choose"}),o.getState().claimInteraction({kind:"box-draw",start:n,pointer:c.readClickPoint(P[0])})},D=P=>{ge(o);const{at:F,align:H}=L({width:At*t.width,height:Sc}),W=new d.AddAnnotationCommand({kind:"text",annotation:{...d.TEXT_ANNOTATION_DEFAULTS,content:yc,at:F,...H!==void 0&&{align:H},width:At}}),U=W.params.annotation.id,$=f({annotationId:U,anchorX:F.x,align:H??d.TEXT_ANNOTATION_DEFAULTS.align,panelWidth:t.width,minWidth:At,paddingInline:P===null?void 0:nr.paddingInline}),Y=new d.AddAnnotationCommand({kind:"text",annotation:{...W.params.annotation,width:$}}),J=P===null?[]:[new d.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"annotation",kind:"text",annotation:U},declarations:{fill:P,...nr}}})];B(Y,J),l.getState().setSelection([{kind:"annotation",id:U}]),o.getState().setCaret(U,s.stack.getSnapshot().undoStack.at(-1)?.id??null),o.getState().setPlotMenu(null)},z=P=>{const F=c.readStickerSize(P,T);if(F===null)return;const{at:H}=L(F,"center"),W=new d.AddAnnotationCommand({kind:"sticker",annotation:{at:H,sticker:P}});B(W),ge(o),o.getState().setPlotMenu(null)};return(0,a.jsxs)(a.Fragment,{children:[j===void 0&&(0,a.jsx)("span",{className:"_1vbfegu3",style:{left:R.x,top:R.y},"data-testid":"empty-plot-dot","aria-hidden":!0}),I&&(0,a.jsx)(Qo,{frameElement:e,boundary:R,spans:k,onEscape:G,children:(0,a.jsxs)("div",{className:"vez73g0 _1vbfegu0",role:"toolbar","aria-label":r("graph.annotations.baseMenu.annotate"),onKeyDown:Ko,children:[(0,a.jsxs)("div",{className:"vez73g1",children:[(0,a.jsx)(u,{variant:"icon",...pe,ariaLabel:r("graph.annotations.baseMenu.text"),icon:(0,a.jsx)(gc,{}),onClick:()=>D(null)}),(0,a.jsx)(u,{variant:"icon",...pe,ariaLabel:r("graph.annotations.baseMenu.stickyNote"),icon:(0,a.jsx)(mc,{}),expanded:x.kind==="sticky",onClick:()=>_("sticky")}),j===void 0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(u,{variant:"icon",...pe,ariaLabel:r("graph.annotations.baseMenu.arrow"),icon:(0,a.jsx)(vc,{}),expanded:x.kind==="arrow",onClick:()=>_("arrow")}),(0,a.jsx)(u,{variant:"icon",...pe,ariaLabel:r("graph.annotations.baseMenu.box"),icon:(0,a.jsx)(xc,{}),expanded:w,onClick:C})]}),(0,a.jsx)(u,{variant:"icon",...pe,ariaLabel:r("graph.annotations.baseMenu.addSticker"),icon:(0,a.jsx)(fc,{}),expanded:x.kind==="sticker",onClick:()=>_("sticker")})]}),x.kind==="sticky"&&(0,a.jsxs)("div",{className:"vez73g2 _1vbfegu1",children:[(0,a.jsx)(p,{title:r("graph.colorDropdown.colors"),colors:v.CANVAS_COLOR_PRESETS,names:g,value:null,onChange:D,...pe}),m.length>0&&(0,a.jsx)(p,{title:r("graph.colorDropdown.chartColors"),colors:m,value:null,onChange:D})]}),x.kind==="sticker"&&(0,a.jsx)(wc,{onPick:z}),x.kind==="arrow"&&(0,a.jsxs)("div",{className:"vez73g4",children:[(0,a.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowOneWay"),onClick:O("end"),children:(0,a.jsx)(Uo,{})}),(0,a.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowTwoWay"),onClick:O("both"),children:(0,a.jsx)(Cl,{})}),(0,a.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowLine"),onClick:O("none"),children:(0,a.jsx)(wl,{})})]})]})})]})},wc=({onPick:e})=>{const t=c.useStickerImages();return t===null?null:(0,a.jsx)("div",{className:Ho,children:Object.entries(t).map(([n,r])=>(0,a.jsx)("button",{type:"button",className:Wo,"aria-label":n,onClick:()=>e(n),children:(0,a.jsx)("img",{className:zo,src:r,alt:""})},n))})},ge=e=>{const t=e.getState().standingInteraction?.kind;(t==="arrow-draw"||t==="box-draw")&&e.getState().releaseInteraction(t)},Me=e=>e.offset+e.strokeWidth,rr="http://www.w3.org/2000/svg",or=new WeakMap,Tc=(e,t)=>{const n=jc(e);n.setAttribute("d",t);const{x:r,y:o,width:i,height:s}=n.getBBox();return{x:r,y:o,width:i,height:s}},jc=e=>{const t=or.get(e);if(t?.isConnected)return t;const n=e.createElementNS(rr,"svg");n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none";const r=e.createElementNS(rr,"path");return n.append(r),e.body.append(n),or.set(e,r),r},Ac=(e,t)=>{const{panelRect:n,look:r,readGridLineWidth:o}=t,i=Me(r);switch(e.kind){case"observations":return Pt([...e.parts,...e.vertex===null?[]:[e.vertex]].flatMap(s=>Pc(s,t,i)).map(s=>({...s,x:s.x+n.x,y:s.y+n.y})),0);case"guide":return Pt(e.shapes.map(s=>s.kind==="box"?s.rect:c.growRect(Ec(s),o(s.axis)/2)),i);case"graph":return Pt([{x:0,y:0,...e.frameSize}],-r.offset);default:return e}},Pc=(e,{measurePathBox:t,coordSystem:n,panelRect:r},o)=>{const i=kc(e,t).map(l=>c.growRect(l,o)),s=c.buildOverflowClipRect((0,d.findOverflowedPanelEdges)(e.layer,n),r);return i.flatMap(l=>Ic(l,s))},Ic=(e,t)=>{const n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),i=Math.min(e.y+e.height,t.y+t.height);return o<=n||i<=r?[]:[{x:n,y:r,width:o-n,height:i-r}]},kc=(e,t)=>e.kind==="boxes"?e.boxes:Lc(e.shapes,t),Lc=(e,t)=>{const n=[],r=new Map;for(const o of e){if(o.kind==="dots"){n.push(...o.centers.map(l=>c.growRect({...l,width:0,height:0},o.size/2)));continue}if(o.pathData==="")continue;const i=o.kind==="stroke"?o.width/2:0;if(!o.pathData.trimStart().startsWith("M")){n.push(c.growRect(t(o.pathData),i));continue}const s=r.get(i)??[];s.push(o.pathData),r.set(i,s)}for(const[o,i]of r)n.push(c.growRect(t(i.join("")),o));return n},Ec=e=>{switch(e.kind){case"line":return{x:Math.min(e.from.x,e.to.x),y:Math.min(e.from.y,e.to.y),width:Math.abs(e.to.x-e.from.x),height:Math.abs(e.to.y-e.from.y)};case"ring":return{x:e.center.x-e.radius,y:e.center.y-e.radius,width:e.radius*2,height:e.radius*2}}},Pt=(e,t)=>{const n=e.filter(({width:r,height:o})=>r>0||o>0);return n.length===0?null:c.growRect((0,d.getBoundingRect)(n),t)};var Mc=(e,{coordSystem:t,panelRect:n})=>{if(e.kind!=="observations")return null;const r=e.vertex===null?e.parts:[...e.parts,e.vertex],o=r.reduce((s,l)=>Math.max(s,l.rows.length),0),i=o===1&&e.vertex===null;return o===0||i||o>1e3?null:r.flatMap(s=>Oc(s,t,n).map(l=>({...l,x:l.x+n.x,y:l.y+n.y})))},Oc=(e,t,n)=>(0,d.measureObservationsBoxes)({layer:{...e.layer,data:e.layer.data.take(e.rows)},coordSystem:t,panelSize:n,radialExtent:"outerEnd"}),Rc=.5,_c={top:e=>-e.y,right:e=>e.x+e.width,bottom:e=>e.y+e.height,left:e=>-e.x},Dc=(e,t,n)=>e===null||!Nc(e)?{top:Wt(t),right:Vt(t),bottom:Wt(t),left:Vt(t)}:{top:Ve(e,t,"top",n),right:Ve(e,t,"right",n),bottom:Ve(e,t,"bottom",n),left:Ve(e,t,"left",n)},Ve=(e,t,n,r)=>{const o=_c[n],i=n==="left"||n==="right",s=x=>i?x.y:x.x,l=x=>i?x.y+x.height:x.x+x.width;let h=-1/0;for(const x of e)h=Math.max(h,o(x));const u=h-Math.max(r,Rc);let p=1/0,g=-1/0;for(const x of e)o(x)<u||(p=Math.min(p,s(x)),g=Math.max(g,l(x)));const m=i?Vt(t):Wt(t),f={from:(0,Q.clamp)(p-r,m.from,m.to),to:(0,Q.clamp)(g+r,m.from,m.to)};return f.from<f.to?f:m},Nc=e=>{const[t]=e;return t!==void 0&&e.some(n=>!c.areRectsEqual(n,t))},Wt=e=>({from:e.x,to:e.x+e.width}),Vt=e=>({from:e.y,to:e.y+e.height}),Gc=(e,{frameElement:t,panelRect:n,look:r})=>{const o=c.useEditorStore(),i=c.useStyleReaderTree(),s=c.useSceneSelector(g=>g.coordSystem),l=(0,b.useRef)(new Map),h=e?.target??null,u=e?.outline??null;(0,b.useLayoutEffect)(()=>{if(h===null||u===null)return;const g=l.current,m=new Map,x=Ac(u,{panelRect:n,look:r,readGridLineWidth:S=>c.readGridLineStyle(i,S).strokeWidth,measurePathBox:S=>{const I=g.get(S)??Tc(t.ownerDocument,S);return m.set(S,I),I},coordSystem:s});if(l.current=m,x===null){o.getState().setSelectedOutline(null);return}const y=Dc(Mc(u,{coordSystem:s,panelRect:n}),x,Me(r)),w=v.measureFrameScale(t);o.getState().setSelectedOutline({target:h,frame:x,frameSpans:y,frameScale:w})},[o,i,s,h,u,t,n,r]);const p=e!==null;(0,b.useLayoutEffect)(()=>p?()=>o.getState().setSelectedOutline(null):void 0,[o,p])},mn="var(--_1qfw3e00)",Bc="_1qfw3e01",Fc="_1qfw3e02",ar=({pathData:e,animateTransitions:t,source:n,...r})=>t?(0,a.jsx)(Hc,{pathData:e,source:n,...r}):(0,a.jsx)("path",{d:e,...r}),Hc=({pathData:e,source:t,...n})=>(0,a.jsx)(c.AnimatedPath,{d:c.useSvgPathMorph(e,c.DEFAULT_SPRING_TRANSITION,t),...n}),zc="var(--dppmab0)",Wc="data-edit-outline-stroke",ra=e=>({[Wc]:"",style:(0,ce.assignInlineVars)({[zc]:`${e}px`})}),oa=(e,t)=>{const{config:n,guides:r}=t;switch(e.kind){case"legend":{const{position:o}=n.legend,i=o==="none";return{hidden:i,hide:new d.SetLegendPositionCommand({position:"none"}),show:new d.SetLegendPositionCommand({position:i?"auto":o})}}case"axis":{const{axis:o}=e,i=o==="ySecondary"?r.axes.find(s=>s.scaledAesthetic==="ySecondary")?.visible:n.axes[o].visible;return i===void 0?null:{hidden:!i,hide:new d.SetAxisVisibilityCommand({axis:o,visible:!1,keepSecondaryAxis:!0}),show:new d.SetAxisVisibilityCommand({axis:o,visible:!0,keepSecondaryAxis:!0})}}case"grid":{const{axis:o}=e;if(o==="both")return null;const{visible:i}=n.axes[o].grid,s=i===!1;return{hidden:s,hide:new d.SetGridVisibilityCommand({axis:o,visible:!1}),show:new d.SetGridVisibilityCommand({axis:o,visible:s?!0:i})}}case"observations":case"graph":return null;default:return e}},Se=()=>{const e=Kl(),{store:t}=c.useGraphContext();return(0,b.useCallback)(n=>e(n)||oa(n,t.getState().scene)!==null,[e,t])},Oe=(e,t)=>e.geom==="boxplot"&&(0,d.getScaledAesthetic)(t,"outlier")!==null,Vc=()=>{const{showMenuTriggerOnHover:e,layers:t,coordSystem:n,parsingLocale:r,anchorResolver:o,geom:i,hasOverlayMenu:s}=aa(),l=c.useHoverState(h=>e?h.hover.primary:null);return(0,b.useMemo)(()=>{if(l===null)return null;const h=t.find(p=>p.id===l.layerId);if(h===void 0||Oe(h,l.observation))return null;const u=(0,d.buildObservationsTarget)({layer:h,observationIndex:(0,d.readObservationIndex)(l),scope:"observation",parsingLocale:r});return u===null||!s(u)?null:ia({layer:h,observation:l.observation,target:u,coordSystem:n,anchorResolver:o,geom:i,purpose:"pin"})},[l,t,n,r,o,i,s])},Kc=()=>Uc("pin"),Uc=e=>{const{showMenuTriggerOnHover:t,layers:n,coordSystem:r,parsingLocale:o,anchorResolver:i,geom:s,hasOverlayMenu:l}=aa(),[h]=c.useGraphSelection(),u=h?.kind==="observations"&&h.scope==="observation"?h:null;return(0,b.useMemo)(()=>{if(!t||u===null||!l(u))return null;const p=n.find(f=>f.id===u.layerId);if(p===void 0)return null;const[g]=(0,d.resolveObservationsTarget)({layer:p,target:u,parsingLocale:o}),m=g===void 0?void 0:p.data.getAt(g);return m==null||Oe(p,m)?null:ia({layer:p,observation:m,target:u,coordSystem:r,anchorResolver:i,geom:s,purpose:e})},[t,u,l,n,o,r,i,s,e])},aa=()=>{const{showMenuTriggerOnHover:e}=c.MODE_RULES[c.useGraphMode()],t=c.useSceneSelector((0,ee.useShallow)(i=>({layers:i.layers,coordSystem:i.coordSystem,parsingLocale:i.config.parsingLocale}))),{anchorResolver:n}=c.useGraphContext(),r=c.useGeomReaderTree(),o=Se();return{showMenuTriggerOnHover:e,...t,anchorResolver:n,geom:r,hasOverlayMenu:o}},ia=({layer:e,observation:t,target:n,coordSystem:r,anchorResolver:o,geom:i,purpose:s})=>{const l=o.resolve(e.geom,t,{coordSystem:r,position:e.position,purpose:s});return l===null?null:{position:l,color:(0,d.readGeomColor)({geom:i},e,t)??d.DEFAULT_GEOM_COLOR,target:n}},$c=()=>{const e=c.useGraphSelection()[0]??null,{layers:t,parsingLocale:n}=c.useSceneSelector((0,ee.useShallow)(r=>({layers:r.layers,parsingLocale:r.config.parsingLocale})));return(0,b.useMemo)(()=>e===null?null:Xc(e,t,n),[e,t,n])},sa=(e,t,n)=>{const r=(0,d.findLayerById)(t,e.layerId);if(r===void 0)return null;const o=(0,d.resolveObservationsTarget)({layer:r,target:e,parsingLocale:n});if(o.length===0)return null;const i=[{layer:r,rows:o}];for(const s of(0,d.findCompanionLayers)(r,t)){const l=(0,d.resolveObservationsTarget)({layer:s,host:r,target:e,parsingLocale:n});l.length>0&&i.push({layer:s,rows:l})}return{kind:"observations",key:(0,d.readEditTargetKey)(e),layerId:e.layerId,scope:e.scope,parts:i,vertex:null}},Xc=(e,t,n)=>{switch(e.kind){case"observations":{const r=sa(e,t,n);return r===null?null:{outlined:r,target:e}}case"legend":case"axis":case"grid":return{outlined:{kind:"guide",key:(0,d.readEditTargetKey)(e),target:e},target:e};case"graph":return{outlined:{kind:"graph",key:"graph"},target:e};default:return null}},qc=()=>{const e=Vc(),t=c.useHoverState(l=>l.hover.intersection?.intersects===!0),n=c.useGraphSelection()[0]??null,r=c.useEditorState(l=>l.standingInteraction),o=c.useEditorState(l=>l.plotMenu),{layers:i,parsingLocale:s}=c.useSceneSelector((0,ee.useShallow)(l=>({layers:l.layers,parsingLocale:l.config.parsingLocale})));return(0,b.useMemo)(()=>!t||e===null||n!==null||r!==null||o!==null?null:sa(e.target,i,s),[t,e,n,r,o,i,s])};var ir=(e,t)=>{if(e.kind==="observations"&&t.kind==="observations"){if(e.layerId!==t.layerId||e.scope!==t.scope)return!1;const n=e.parts[0]?.rows[0];return n!==void 0&&(t.parts[0]?.rows.includes(n)??!1)}return e.kind==="guide"&&t.kind==="guide"?(0,d.areEditTargetsEqual)(e.target,t.target):e.kind==="graph"&&t.kind==="graph"},Yc=(e,t)=>{const n=Math.max(e.width,8),r=Math.max(e.height,8),o=Math.max(0,e.x+e.width/2-n/2),i=Math.max(0,e.y+e.height/2-r/2),s=Math.min(t.width,e.x+e.width/2+n/2),l=Math.min(t.height,e.y+e.height/2+r/2);return{x:o,y:i,width:Math.max(0,s-o),height:Math.max(0,l-i)}},Zc=[],Jc=e=>{const{layers:t,parsingLocale:n}=c.useSceneSelector((0,ee.useShallow)(m=>({layers:m.layers,parsingLocale:m.config.parsingLocale}))),r=c.useEditorState(m=>m.editTargetUnderPointer),o=r?.kind==="observations"?r.observations:null,i=o===null?void 0:(0,d.findLayerById)(t,o.layerId),s=o?.target.scope??null,l=o===null||i===void 0?null:(0,d.readRowScopeKey)(i,o.target.scope,o.observationIndex),h=(0,b.useMemo)(()=>i===void 0||s===null||l===null?null:Qc(t,i,s,l),[t,i,s,l]),u=(0,b.useMemo)(()=>h!==null&&e!==null&&ir(h,e),[h,e]),p=Se(),g=o!==null&&i!==void 0&&ed(o,i,n,p)?o.observationIndex:null;return(0,b.useMemo)(()=>{switch(r?.kind){case"observations":{const m=h?.parts[0];if(h===null||m===void 0)return null;const f=g===null?null:{layer:m.layer,rows:[g]};return u?f===null?null:{...h,parts:Zc,vertex:f}:{...h,vertex:f}}case"axis":case"legend":case"grid":{const m={kind:"guide",key:(0,d.readEditTargetKey)(r.target),target:r.target};return e!==null&&ir(m,e)?null:m}default:return null}},[r,h,u,g,e])},Qc=(e,t,n,r)=>{const o=[{layer:t,rows:(0,d.readRowsAtScopeKey)(t,n,r)}];for(const i of(0,d.findCompanionLayers)(t,e)){const s=(0,d.readCompanionRowsAtScopeKey)(i,t,n,r);s.length>0&&o.push({layer:i,rows:s})}return{kind:"observations",key:JSON.stringify([t.id,n,r]),layerId:t.id,scope:n,parts:o,vertex:null}},ed=({observationIndex:e,target:t,onObservation:n},r,o,i)=>{if(!n||t.scope!=="group")return!1;const s=(0,d.buildObservationsTarget)({layer:r,observationIndex:e,scope:"observation",parsingLocale:o});return s!==null&&i(s)},td=({frameElement:e,target:t,coordType:n,legendDisplays:r})=>{const o=e.getBoundingClientRect(),i=[...e.querySelectorAll(nd(t))],s=l=>{const h=l.getBoundingClientRect();return{x:h.left-o.left,y:h.top-o.top,width:h.width,height:h.height}};switch(t.kind){case"axis":{const l=i.map(s);return n==="polar"||l.length===0?It(l):It([(0,d.getBoundingRect)(l)])}case"legend":return It([...rd(i.filter(l=>!od(l)))].flatMap(([l,h])=>r[l]==="direct"?h.map(s):[(0,d.getBoundingRect)(h.map(s))]));case"grid":return i.flatMap(l=>{const h=c.readStampedEditTargetInStack([l],e);if(h?.kind!=="grid"||h.target.axis==="both")return[];const{axis:u}=h.target;return t.axis==="both"||u===t.axis?[ad(l,s(l),u)]:[]})}},nd=e=>{const t=`[${c.EDIT_TARGET_KIND_ATTRIBUTE}="${e.kind}"]`;return e.kind!=="axis"?t:`${t}[${c.EDIT_TARGET_AXIS_ATTRIBUTE}="${e.axis}"]`},rd=e=>{const t=new Map;for(const n of e){const r=c.readLegendItemAddress(n);r!==null&&t.set(r.legendIndex,[...t.get(r.legendIndex)??[],n])}return t},od=e=>e.closest(c.LEGEND_OVERFLOW_CONTROL_SELECTOR)!==null,It=e=>e.map(t=>({kind:"box",rect:t})),ad=(e,{x:t,y:n,width:r,height:o},i)=>e.querySelector("circle")!==null?{kind:"ring",axis:i,center:{x:t+r/2,y:n+o/2},radius:r/2}:r<1||o<1?r<o?{kind:"line",axis:i,from:{x:t+r/2,y:n},to:{x:t+r/2,y:n+o}}:{kind:"line",axis:i,from:{x:t,y:n+o/2},to:{x:t+r,y:n+o/2}}:id(e.querySelector("line"))?{kind:"line",axis:i,from:{x:t,y:n},to:{x:t+r,y:n+o}}:{kind:"line",axis:i,from:{x:t,y:n+o},to:{x:t+r,y:n}},id=e=>{const t=n=>Number(e?.getAttribute(n)??0);return(t("x2")-t("x1"))*(t("y2")-t("y1"))>=0},sd=[],ld=(e,{frameElement:t,frameSize:n,panelRect:r})=>{const{animateTransitions:o}=c.useGraphAnimation(),i=c.useSceneSelector(y=>y.coordSystem),s=c.useGeomRendererResolver(),l=c.useGeomReaderTree(),h=dd(e.kind==="guide"?e.target:null,{frameElement:t,frameSize:n}),u=cd(t,n),p=(0,b.useMemo)(()=>({coordSystem:i,panelRect:r,resolveRenderer:s,geomReaders:l}),[i,r,s,l]),g=e.kind==="observations"?e.parts:null,m=e.kind==="observations"?e.vertex:null,f=(0,b.useMemo)(()=>g?.map(y=>sr(y,p,o))??sd,[g,p,o]),x=(0,b.useMemo)(()=>m===null?null:sr(m,p,!1),[m,p]);return(0,b.useMemo)(()=>{switch(e.kind){case"observations":return{kind:"observations",parts:f,vertex:x};case"guide":return{kind:"guide",target:e.target,shapes:h};case"graph":return{kind:"graph",frameSize:u}}},[e,f,x,h,u])},cd=(e,t)=>{const[n,r]=(0,b.useState)(()=>v.readFrameLayoutSize(e,t));return(0,b.useLayoutEffect)(()=>{r(o=>{const i=v.readFrameLayoutSize(e,{width:t.width,height:t.height});return o.width===i.width&&o.height===i.height?o:i})},[e,t.width,t.height]),n},sr=({layer:e,rows:t},{coordSystem:n,panelRect:r,resolveRenderer:o,geomReaders:i},s)=>{const l={...e,data:e.data.take(t)},h=o(e.geom,n.type);return h?.getEditOutlineShapes===void 0?{kind:"boxes",layer:e,rows:t,boxes:(0,d.measureObservationsBoxes)({layer:l,coordSystem:n,panelSize:r}).map(u=>Yc(u,r))}:{kind:"declared",layer:e,rows:t,shapes:h.getEditOutlineShapes({layer:l,sourceLayer:e,coordSystem:n,panelRect:r,styleReaders:i(e),animateTransitions:s,symbols:h.symbols})}},dd=(e,{frameElement:t,frameSize:n})=>{const r=c.useGuideSlidesSettledCount(e!==null),o=c.useSceneSelector(m=>m.coordSystem.type),i=c.useSceneSelector((0,ee.useShallow)(m=>m.guides.legends.drawn.map(f=>f.display))),s=c.useSceneSelector(m=>e===null?null:m),[l,h]=(0,b.useState)([]),u=c.useLatestRef(e),p=(0,b.useRef)(!1),g=(0,b.useCallback)(()=>{const m=u.current;if(m===null)return;const f=td({frameElement:t,target:m,coordType:o,legendDisplays:i}),x=v.measureFrameScale(t);h(f.map(y=>ud(y,1/x)))},[t,u,o,i]);return(0,b.useLayoutEffect)(()=>{if(u.current!==null){if(p.current){const m=requestAnimationFrame(g);return()=>cancelAnimationFrame(m)}p.current=!0,g()}},[g,u,s,n.width,n.height,r]),l},ud=(e,t)=>{switch(e.kind){case"box":{const{x:n,y:r,width:o,height:i}=e.rect;return{kind:"box",rect:{x:n*t,y:r*t,width:o*t,height:i*t}}}case"line":return{...e,from:{x:e.from.x*t,y:e.from.y*t},to:{x:e.to.x*t,y:e.to.y*t}};case"ring":return{...e,center:{x:e.center.x*t,y:e.center.y*t},radius:e.radius*t}}},hd=["x","y"],pd=(0,b.memo)(function({frameElement:t,frameSize:n,panelRect:r}){const o=c.useResolvedStyle(d.resolveEditOutlineStyle,c.useStyleReaderTree()),i=$c(),s=Jc(i?.outlined??null),{selectObservationsOnPress:l,selectGraphOnPress:h,selectGuidesOnPress:u}=c.MODE_RULES[c.useGraphMode()],p=qc(),g=l||h||u,m=g?s:p;if(i===null&&m===null)return null;const f={frameElement:t,frameSize:n,panelRect:r};return!g&&i!==null&&i.target.kind!=="observations"?(0,a.jsx)(kt,{part:"selected",target:i.outlined,editTarget:i.target,look:o.selected,paints:!1,...f}):(0,a.jsxs)("svg",{className:Bc,width:n.width,height:n.height,"aria-hidden":!0,"data-testid":"edit-outline",children:[m!==null&&(0,a.jsx)(kt,{part:"hover",target:m,look:o.hover,paints:!0,...f},m.key),i!==null&&(0,a.jsx)(kt,{part:"selected",target:i.outlined,editTarget:i.target,look:o.selected,paints:!0,...f},i.outlined.key)]})}),kt=({part:e,target:t,editTarget:n,look:r,frameSize:o,panelRect:i,frameElement:s,paints:l})=>{const h=(0,b.useId)(),u=`${h}-shapes`,p=`${h}-hole`,g=ld(t,{frameElement:s,frameSize:o,panelRect:i});return Gc(n===void 0?null:{target:n,outline:g},{frameElement:s,panelRect:i,look:r}),l?(0,a.jsxs)("g",{"data-edit-outline":e,"data-testid":`edit-outline-${e}`,children:[(0,a.jsxs)("defs",{children:[(0,a.jsx)("g",{id:u,className:Fc,children:(0,a.jsx)(yd,{outline:g,look:r,panelRect:i})}),(0,a.jsxs)("mask",{id:p,maskUnits:"userSpaceOnUse",x:"-100%",y:"-100%",width:"300%",height:"300%",children:[(0,a.jsx)("rect",{x:"-100%",y:"-100%",width:"300%",height:"300%",fill:"white"}),(0,a.jsx)("use",{href:`#${u}`,style:gd(r.offset)})]})]}),(0,a.jsxs)("g",{mask:`url(#${p})`,"data-testid":`edit-outline-${e}-ring`,children:[(0,a.jsx)("use",{href:`#${u}`,style:md(r)}),(0,a.jsx)("use",{href:`#${u}`,style:vd(r)})]}),t.kind==="observations"&&(0,a.jsx)(jd,{target:t,look:r,panelRect:i})]}):null},gd=e=>({fill:"black",stroke:"black",strokeLinecap:"round",...(0,ce.assignInlineVars)({[mn]:`${2*e}px`})}),md=e=>({fill:"none",stroke:e.backingColor??c.vars.graphBackground,strokeLinecap:"round",opacity:e.backingAlpha,...(0,ce.assignInlineVars)({[mn]:`${2*Me(e)}px`})}),vd=e=>{const t=(0,d.toStrokeDasharray)(e.dashArray,e.strokeWidth);return{fill:"none",stroke:e.stroke,strokeDasharray:t,strokeLinecap:t===void 0?"round":"butt",opacity:e.strokeAlpha,...(0,ce.assignInlineVars)({[mn]:`${2*Me(e)}px`})}},xd=({dashArray:e,strokeWidth:t})=>{if((0,d.toStrokeDasharray)(e,t)===void 0)return;const n=(e.length%2===0?1:2)*e.reduce((r,o)=>r+o*t,0);return n>0?n:void 0},la=(e,t,n=1)=>{if(!(t===void 0||e<=0))return n*Math.max(1,Math.round(2*Math.PI*e/t))*t},fd=(e,t,n)=>{const r=n.offset+Me(n);return c.buildRoundedRectPath(c.growRect({x:0,y:0,...e},-r),Math.max(0,t-r))},yd=({outline:e,look:t,panelRect:n})=>{const r=c.useStyleReaderTree().graph().get("cornerRadius"),o=c.useSceneSelector(l=>l.coordSystem),{cornerRadius:i}=t,s=xd(t);switch(e.kind){case"observations":return(0,a.jsxs)("g",{transform:`translate(${n.x} ${n.y})`,children:[e.parts.map(l=>(0,a.jsx)(c.PanelOverflowClip,{layer:l.layer,coordSystem:o,panelSize:n,children:(0,a.jsx)(lr,{part:l,borderRadius:i,dashPeriod:s})},l.layer.id)),e.vertex!==null&&(0,a.jsx)(c.PanelOverflowClip,{layer:e.vertex.layer,coordSystem:o,panelSize:n,children:(0,a.jsx)(lr,{part:e.vertex,borderRadius:i,dashPeriod:s})},`vertex-${e.vertex.rows.join()}`)]});case"guide":return(0,a.jsx)(Cd,{target:e.target,shapes:e.shapes,borderRadius:i,dashPeriod:s});case"graph":return(0,a.jsx)("path",{d:fd(e.frameSize,r,t)})}},lr=(0,b.memo)(function({part:t,borderRadius:n,dashPeriod:r}){return t.kind==="boxes"?(0,a.jsx)(bd,{boxes:t.boxes,borderRadius:n}):(0,a.jsx)(Sd,{shapes:t.shapes,layer:t.layer,dashPeriod:r})}),Sd=({shapes:e,layer:t,dashPeriod:n})=>e.map((r,o)=>{const i=r.kind==="dots"||r.key===void 0?String(o):`${r.kind}:${r.key}`;switch(r.kind){case"region":return r.pathData===""?null:(0,a.jsx)(ar,{pathData:r.pathData,fillRule:r.fillRule,animateTransitions:r.animateTransitions??!1,source:t,"data-geom":t.geom},i);case"stroke":return r.pathData===""?null:(0,a.jsx)(ar,{pathData:r.pathData,animateTransitions:r.animateTransitions??!1,source:t,"data-geom":t.geom,...ra(r.width)},i);case"dots":return r.centers.length===0?null:(0,a.jsx)("path",{d:c.buildCirclesPath(r.centers,r.size/2),pathLength:la(r.size/2,n,r.centers.length),"data-geom":t.geom},i)}}),bd=({boxes:e,borderRadius:t})=>{const n=e.map(r=>c.buildRoundedRectPath(r,t)).join("");return n===""?null:(0,a.jsx)("path",{d:n,"data-testid":"edit-outline-boxes"})},Cd=({target:e,shapes:t,borderRadius:n,dashPeriod:r})=>{const o=c.useStyleReaderTree();if(e.kind==="grid")return hd.map(s=>{const l=ra(c.readGridLineStyle(o,s).strokeWidth),h=t.map(p=>wd(p,s)).join(""),u=t.filter(p=>p.kind==="ring"&&p.axis===s);return(0,a.jsxs)(b.Fragment,{children:[h!==""&&(0,a.jsx)("path",{d:h,...l}),u.map((p,g)=>(0,a.jsx)("path",{d:Td(p),pathLength:la(p.radius,r),...l},g))]},s)});const i=t.map(s=>s.kind==="box"?c.buildRoundedRectPath(s.rect,n):"").join("");return i===""?null:(0,a.jsx)("path",{d:i})},wd=(e,t)=>e.kind==="line"&&e.axis===t?`M${e.from.x},${e.from.y}L${e.to.x},${e.to.y}`:"",Td=({center:e,radius:t})=>{const n=`${e.x},${e.y-t}`;return`M${n}A${t},${t} 0 0 1 ${`${e.x},${e.y+t}`}A${t},${t} 0 0 1 ${n}`},jd=({target:e,look:t,panelRect:n})=>{const r=c.useSceneSelector(s=>s.coordSystem),o=e.parts[0];if(e.scope!=="xValue"||o===void 0||o.layer.highlight?.strategy!=="overlayAnchor")return null;const i=Ad(o);return i===null?null:(0,a.jsx)("svg",{x:n.x,y:n.y,width:n.width,height:n.height,overflow:"visible",children:(0,a.jsx)("line",{...c.readCrosshairLine(r,i,n),stroke:t.stroke,strokeOpacity:t.strokeAlpha,strokeWidth:t.strokeWidth,strokeDasharray:"4 3",strokeLinecap:"round","data-testid":"edit-outline-band-guide"})})},Ad=({layer:e,rows:t})=>{for(const n of t){const r=e.data.getAt(n),o=r===null?null:(0,d.getXBand)(r),i=r===null?null:(0,d.getYBand)(r);if(o!==null&&i!==null)return{x:o,y:i}}return null},Pd=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]}),Id=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]}),kd=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 16 16",...e,children:[(0,a.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,a.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:".8",rx:".533"})]}),Ld={observation:Pd,xValue:Id,group:kd},Ed=()=>{const{selectionStore:e}=c.useGraphContext(),t=c.useEditorStore(),n=c.useI18n(),r=c.useFormattingLocale(),o=c.useSceneSelector(w=>w),i=dt(o,r),s=c.useEditorState(w=>w.pressedObservation),l=Se(),h=(0,b.useMemo)(()=>Md({scene:o,pressed:s,groupOptions:i,locale:r,t:n,hasOverlayMenu:l}),[o,s,i,r,n,l]);if(h===null)return null;const{layer:u,levels:p,names:g}=h,{observationIndex:m,selectedFor:f}=h.pressed,x=p.map(w=>{const S=Ld[w];return{value:w,label:g[w],icon:(0,a.jsx)(S,{})}}),y=w=>{const S=p.find(A=>A===w),{parsingLocale:I}=o.config,j=S===void 0?null:(0,d.buildObservationsTarget)({layer:u,observationIndex:m,scope:S,parsingLocale:I});j!==null&&(t.getState().setPressedObservation({...h.pressed,selectedFor:j}),e.getState().setSelection([j]))};return(0,a.jsx)(v.ToggleGroup,{value:f.scope,options:x,onChange:y,ariaLabel:n("editor.overlayMenu.selection")})},Md=({scene:e,pressed:t,groupOptions:n,locale:r,t:o,hasOverlayMenu:i})=>{const s=t===null?null:c.findPressedObservation(t,e.layers,e.config.parsingLocale);if(t===null||s===null)return null;const{layer:l,observation:h}=s,{observationIndex:u,selectedFor:p}=t,{parsingLocale:g}=e.config,m=(0,d.readReachableLevels)({layer:l,observationIndex:u,parsingLocale:g,scales:e.scales}).filter(f=>{const x=(0,d.buildObservationsTarget)({layer:l,observationIndex:u,scope:f,parsingLocale:g});return x!==null&&i(x)});return m.length<2||!m.includes(p.scope)?null:{pressed:t,layer:l,levels:m,names:Bo({scene:e,layer:l,observation:h,groupOptions:n,locale:r,t:o})}},Od=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,a.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),Rd=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,a.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,a.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,a.jsx)("path",{d:"m2 2 20 20"})]})}),_d="_11vjgg60",Dd=({target:e})=>{const t=c.useI18n(),n=c.useGraphCommands(),r=c.useSceneSelector(f=>f),[o,i]=(0,b.useState)(null),s=oa(e,r);if(s===null)return null;const{hidden:l,hide:h,show:u}=s,p=()=>{if(l){n.dispatch(o??u);return}i(u),n.dispatch(h)},g=t(l?"editor.overlayMenu.show":"editor.overlayMenu.hide"),m=l?Rd:Od;return(0,a.jsx)(v.ControlTooltip,{label:g,children:(0,a.jsx)("button",{type:"button",className:_d,onClick:p,children:(0,a.jsx)(m,{title:""})})})},Nd=(e,t)=>t==="polar"||e==="bar",Gd=(e,t)=>e===null||e.key!==t?null:{boundary:{x:e.x,y:e.y,width:0,height:0},spans:{top:{from:e.x,to:e.x},right:{from:e.y,to:e.y},bottom:{from:e.x,to:e.x},left:{from:e.y,to:e.y}}},Bd="_1j45ehx0",Fd="_1j45ehx1",Hd="_1j45ehx2",zd="_1j45ehx3",Wd=(e,t)=>{switch(e.kind){case"observations":return Vd(e.scope,t);case"legend":case"axis":case"grid":return Kd(e.kind,t);case"graph":return t("editor.overlayMenu.chart");default:return e}},Vd=(e,t)=>{switch(e){case"observation":return t("editor.overlayMenu.observation");case"group":return t("editor.overlayMenu.group");case"xValue":return t("editor.overlayMenu.band");default:return e}},Kd=(e,t)=>{switch(e){case"axis":return t("editor.overlayMenu.axis");case"legend":return t("editor.overlayMenu.legend");case"grid":return t("editor.overlayMenu.gridLines");default:return e}},Ud=({target:e})=>{const t=c.useI18n(),n=c.useFormattingLocale(),r=c.useSceneSelector(s=>s),o=dt(r,n),i=(0,b.useMemo)(()=>Xd({target:e,scene:r,groupOptions:o,locale:n,t}),[e,r,o,n,t]);return(0,a.jsx)($d,{title:i})},$d=({title:e})=>{const t=(0,b.useRef)(null),n=(0,b.useRef)(null),[r,o]=(0,b.useState)(!1),i=(0,b.useCallback)(()=>{const h=t.current,u=n.current;h===null||u===null||o(u.offsetWidth>h.clientWidth)},[]);(0,b.useLayoutEffect)(i,[i,e.whole]);const{setElement:s}=c.useResizeObserver({onResize:i}),l=(0,b.useCallback)(h=>{t.current=h,s(h)},[s]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(je.Popover.Title,{ref:l,className:Hd,"data-testid":"overlay-menu-title",children:r?e.value:e.whole}),(0,a.jsx)("span",{ref:n,className:zd,"aria-hidden":!0,children:e.whole})]})},Xd=({target:e,scene:t,groupOptions:n,locale:r,t:o})=>{const i=Wd(e,o),s={whole:i,value:i};if(e.kind!=="observations")return s;const l=(0,d.findLayerById)(t.layers,e.layerId);if(l===void 0)return s;const[h]=(0,d.resolveObservationsTarget)({layer:l,target:e,parsingLocale:t.config.parsingLocale}),u=h===void 0?null:l.data.getAt(h);return u===null?s:Bt({scene:t,layer:l,observation:u,groupOptions:n,locale:r,t:o},e.scope)},qd=({frameElement:e,panelRect:t})=>{const n=v.useBuildRemoveAnnotationCommand(t),{selectionStore:r}=c.useGraphContext(),o=Yd(c.useEditorState(m=>m.selectedOutline)),i=c.useEditorState(m=>m.annotatePress),s=c.MODE_RULES[c.useGraphMode()].showMenuTriggerOnHover,l=Vl(o?.target??null),h=Se(),u=o===null?null:(0,d.readEditTargetKey)(o.target),p=(0,b.useMemo)(()=>s&&u!==null?Gd(i,u):null,[s,i,u]);if(o===null||u===null||!h(o.target))return null;const g=()=>{r.getState().clearSelection()};return(0,a.jsxs)(Qo,{frameElement:e,boundary:p?.boundary??o.frame,spans:p?.spans??o.frameSpans,onEscape:g,children:[(0,a.jsxs)(v.ControlTooltipArea,{className:Bd,children:[(0,a.jsxs)("div",{className:Fd,children:[(0,a.jsx)(Ud,{target:o.target}),(0,a.jsx)(Dd,{target:o.target},u)]}),o.target.kind==="observations"&&(0,a.jsx)(Ed,{})]}),(0,a.jsx)(v.RemoveAnnotationCommandContext.Provider,{value:n,children:(0,a.jsx)(b.Fragment,{children:l},u)})]})},Yd=e=>{const t=c.useGraphSelection(),[n,r]=(0,b.useState)(e),o=n!==null&&(0,d.areEditTargetsEqual)(t[0]??null,n.target),i=e??(o?n:null);return i!==n&&r(i),i},Zd=({frameRect:e})=>{const{targetBoundaryStore:t}=c.useGraphContext(),n=c.useEditorState(s=>s.selectedOutline),{left:r,top:o}=e,i=(0,b.useMemo)(()=>{if(n===null)return null;const{frame:s,frameSpans:l,frameScale:h}=n;return{frame:s,client:{x:r+s.x*h,y:o+s.y*h,width:s.width*h,height:s.height*h},frameSpans:l,clientSpans:{top:Ke(l.top,r,h),right:Ke(l.right,o,h),bottom:Ke(l.bottom,r,h),left:Ke(l.left,o,h)}}},[n,r,o]);return(0,b.useLayoutEffect)(()=>{t.getState().setBoundary(i)},[t,i]),(0,b.useLayoutEffect)(()=>()=>t.getState().setBoundary(null),[t]),null},Ke=(e,t,n)=>({from:t+e.from*n,to:t+e.to*n}),vn=["start","end"],Jd=({anchor:e,point:t,delta:n,bounds:r=d.PANEL_FRACTION_BOUNDS})=>{const o={x:dr(t.x,n.x,r.minX,r.maxX),y:dr(t.y,n.y,r.minY,r.maxY)};return{anchor:{...e,x:e.x+o.x,y:e.y+o.y},point:{x:t.x+o.x,y:t.y+o.y}}},xn=(e,t,n)=>{const{space:r,defer:o,...i}=e[t.endpoint];return{...e,[t.endpoint]:{...i,...(0,d.toPanelCursor)(t.placement.point,n)}}},cr=(e,t,n)=>({type:"free",anchor:e,sourceAlign:null,point:(0,d.projectAnchorToPanel)(t,n),nearby:[]}),ca=(e,t)=>(0,Q.isEqual)(e,t),Qd=(e,t)=>{const n=(0,d.projectAnchorToPanel)(e,t);return{x:t.x+n.x,y:t.y+n.y}},eu=(e,t,n)=>{const r=(0,d.projectAnchorToPanel)(e,n),o=(0,d.projectAnchorToPanel)(t,n);return{x:Math.min(r.x,o.x),y:Math.min(r.y,o.y),width:Math.abs(o.x-r.x),height:Math.abs(o.y-r.y)}},dr=(e,t,n,r)=>!Number.isFinite(t)||!Number.isFinite(e)?0:(0,Q.clamp)(t,Math.min(n-e,0),Math.max(r-e,0)),ut=({stroke:e,strokeAlpha:t})=>`color-mix(in srgb, ${e} ${t*100}%, transparent)`,da=(e,t,n,r)=>{const o=e.textAnnotations.find(i=>i.id===t);return o===void 0?null:c.measureTextAnnotationBox(c.previewResizedText(o,n),r)},be=()=>{const e=c.useGraphSelection();return xe(e)},xe=e=>{if(e.length!==1)return null;const[t]=e;return t?.kind==="annotation"?t.id:null},tu="var(--_1am0al60)";var nu="_1am0al61",ru="_1am0al62",fn=(e,t,n)=>({x:v.normalizeToPanelExtent(t.x-e.x,n.width),y:v.normalizeToPanelExtent(t.y-e.y,n.height)}),ua=e=>e.x!==0||e.y!==0,ha=(e,t)=>({x:e.x*t.width,y:e.y*t.height}),ou=({panelRect:e})=>{const t=c.useResolvedAnnotations(e),n=c.useMeasuredBoxes(),r=c.useStyleReaderTree(),o=be(),i=c.useEditorState(S=>c.readStanding(S,"move-drag")),s=c.useEditorState(S=>c.readStanding(S,"shape-resize-drag")),l=c.useEditorState(S=>c.readStanding(S,"arrow-endpoint-drag")),h=c.useEditorState(S=>c.readStanding(S,"text-resize-drag")),u=c.useEditorState(c.readAnnotationUnderPointer),p={panel:{width:e.width,height:e.height},measuredBoxes:n,readers:r},g=i!==null&&c.readMovedRegionRect(i)!==null,m=g?c.applyDraggedPlacement(t,t,i,e):t,f=ur(m,o,p),x=ur(m,u===o?null:u,p),y=S=>{if(s?.annotationId===S.id){const I=s.annotationKind==="shape"?r.annotation.shape(S.id).get("strokeWidth"):0;return c.measureShapeRegion(s.region,I,p.panel)}if(l?.annotationId===S.id){const I=t.arrows.find(j=>j.id===S.id);return I===void 0?S.geometry:c.measureArrowEnds(xn(I,l,p.panel),p.panel)}return h?.annotationId===S.id?da(t,S.id,h,p)??S.geometry:S.geometry},w=S=>{if(i?.annotationId!==S||g)return e;const I=ha(i.translation,e);return{x:e.x+I.x,y:e.y+I.y}};return(0,a.jsxs)(a.Fragment,{children:[x!==null&&(0,a.jsx)(hr,{annotationId:x.id,geometry:y(x),state:"hovered",origin:w(x.id)}),f!==null&&(0,a.jsx)(hr,{annotationId:f.id,geometry:y(f),state:"selected",origin:w(f.id)})]})},ur=(e,t,n)=>{if(t===null)return null;const r=c.resolveAnnotationChromeGeometry(e,t,n);return r===null?null:{id:t,geometry:r}},hr=({annotationId:e,geometry:t,state:n,origin:r})=>{const o=c.useStyleReaderTree();if(t===null)return null;const i=o.editOutline[n==="hovered"?"hover":"selected"]().resolve(),s=(0,ce.assignInlineVars)({[tu]:ut(i)});return t.shape==="segment"?(0,a.jsxs)("div",{"aria-hidden":"true","data-testid":"annotation-chrome","data-annotation-id":e,"data-state":n,style:s,children:[(0,a.jsx)(pr,{point:t.start,origin:r}),(0,a.jsx)(pr,{point:t.end,origin:r})]}):(0,a.jsx)("div",{"aria-hidden":"true",className:nu,"data-testid":"annotation-chrome","data-annotation-id":e,"data-state":n,style:{...s,left:r.x+t.rect.x-2,top:r.y+t.rect.y-2,width:t.rect.width+4,height:t.rect.height+4}})},pr=({point:e,origin:t})=>(0,a.jsx)("span",{className:ru,style:{left:t.x+e.x,top:t.y+e.y}}),yn="c44vv80",au=({panelRect:e})=>{const t=c.useEditorState(s=>c.readStanding(s,"move-drag")),n=c.useResolvedAnnotations(e);if(t===null)return null;const r=c.readMovedRegionRect(t)!==null,o=r?{x:0,y:0}:ha(t.translation,e),i=r?c.applyDraggedPlacement(n,n,t,e):n;return(0,a.jsx)("svg",{"aria-hidden":"true",className:yn,width:e.width,height:e.height,style:{left:e.x+o.x,top:e.y+o.y},"data-testid":"annotation-preview","data-annotation-id":t.annotationId,children:lu(i,t.annotationId,e)})},iu=({annotation:e,panelSize:t})=>{const n=c.useMeasuredBoxRef(e.id);return(0,a.jsx)(c.TextAnnotation,{annotation:e,panel:t,style:(0,d.resolveTextAnnotationStyle)(c.useStyleReaderTree(),e.id),blockRef:n})},Te=(e,t,n)=>{const r=e.find(o=>o.id===t);return r===void 0?null:n(r)},su={text:(e,t,n)=>Te(e.textAnnotations,t,r=>(0,a.jsx)(iu,{annotation:r,panelSize:n})),shape:(e,t,n)=>Te(e.shapes,t,r=>(0,a.jsx)(du,{shape:r,panelSize:n})),image:(e,t,n)=>Te(e.images,t,r=>(0,a.jsx)(hu,{image:r,panelSize:n})),arrow:(e,t,n)=>Te(e.arrows,t,r=>(0,a.jsx)(cu,{arrow:r,panelSize:n})),sticker:(e,t,n)=>Te(e.stickers,t,r=>(0,a.jsx)(uu,{sticker:r,panelSize:n}))},lu=(e,t,n)=>{for(const r of Object.values(su)){const o=r(e,t,n);if(o!==null)return o}return null},cu=({arrow:e,panelSize:t})=>{const n=(0,d.resolveArrowAnnotationStyle)(c.useStyleReaderTree(),e.id),r=(0,d.computeArrow)({arrow:e,style:n,panelWidth:t.width,panelHeight:t.height});return r===null?null:(0,a.jsx)(c.ArrowAnnotation,{computed:r,style:n,addressable:!1})},du=({shape:e,panelSize:t})=>(0,a.jsx)(c.ShapeAnnotation,{shape:e,style:c.useStyleReaderTree().annotation.shape(e.id).resolve(),panel:t}),uu=({sticker:e,panelSize:t})=>(0,a.jsx)(c.StickerAnnotation,{sticker:e,panel:t,textScale:c.useStyleReaderTree().graph().get("textScale")}),hu=({image:e,panelSize:t})=>(0,a.jsx)(c.ImageAnnotation,{image:e,panel:t,style:c.useStyleReaderTree().annotation.image(e.id).resolve()}),Sn="_1lp7ph20",pu=({panelRect:e})=>{const t=c.useEditorState(r=>c.readStanding(r,"move-drag")?.placement??c.readStanding(r,"arrow-endpoint-drag")?.placement??c.readStanding(r,"arrow-draw")?.placement??c.readStanding(r,"shape-resize-drag")?.placement??c.readStanding(r,"box-draw")?.placement??null),n=c.useEditorState(r=>c.readStanding(r,"move-drag")?.ends??null);return n!==null?(0,a.jsx)(gu,{ends:n,panelRect:e}):t===null?null:"region"in t?(0,a.jsx)(vu,{placement:t,panelRect:e}):(0,a.jsx)(mu,{placement:t,panelRect:e})},gu=({ends:e,panelRect:t})=>{const n=c.useStyleReaderTree().snapTarget.tether().resolve();return(0,a.jsx)("svg",{"aria-hidden":"true",className:Sn,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-chrome","data-placement":"offset",children:vn.map(r=>{const o=e[r].tether;return o===void 0?null:(0,a.jsx)(pa,{...o,style:n,endpoint:r},r)})})},mu=({placement:e,panelRect:t})=>{const n=c.useStyleReaderTree().snapTarget,r=n.nearby().resolve(),o=n.snapped().resolve(),i=n.area().resolve(),s=n.source().resolve(),l=n.tether().resolve(),h=e.type==="snapped"?e.point:null,u=e.type==="snapped"?xu(e):null;return(0,a.jsxs)("svg",{"aria-hidden":"true",className:Sn,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-chrome","data-placement":e.type,children:[e.nearby.map(({point:p,distance:g,nearest:m},f)=>{if(h!==null&&p.x===h.x&&p.y===h.y)return null;const x=r.alpha*(m?1:Math.max(0,1-g/160));return x<=0?null:(0,a.jsx)("circle",{"data-testid":"snap-nearby","data-nearest":m?"":void 0,cx:p.x,cy:p.y,r:r.size/2,fill:"none",...ke(r),strokeOpacity:x},f)}),e.type==="snapped"&&(0,a.jsxs)("g",{"data-testid":"snap-target","data-target-type":e.target.type,"data-target-id":fu(e),children:[u!==null&&e.landing==="area"&&(0,a.jsx)("rect",{"data-testid":"snap-area",x:u.x,y:u.y,width:u.width,height:u.height,rx:i.cornerRadius,fill:(0,d.toPaintColor)(i.fill),fillOpacity:i.alpha,stroke:"none"}),(0,a.jsx)("circle",{cx:e.point.x,cy:e.point.y,r:o.size/2,fill:(0,d.toPaintColor)(o.fill),fillOpacity:o.alpha,stroke:"none"}),(0,a.jsx)("circle",{"data-testid":"snap-source",cx:e.point.x,cy:e.point.y,r:s.size/2,fill:"none",...ke(s)})]}),e.type==="offset"&&(0,a.jsx)(pa,{targetPoint:e.restPoint,point:e.point,style:l})]})},pa=({targetPoint:e,point:t,style:n,endpoint:r})=>(0,a.jsxs)("g",{"data-testid":"snap-tether","data-endpoint":r,children:[(0,a.jsx)("line",{x1:e.x,y1:e.y,x2:t.x,y2:t.y,...ke(n)}),(0,a.jsx)("circle",{cx:e.x,cy:e.y,r:n.size/2,fill:(0,d.toPaintColor)(n.fill),fillOpacity:n.alpha,stroke:"none"})]}),vu=({placement:e,panelRect:t})=>{const n=c.useStyleReaderTree().snapTarget.snapped().resolve();return e.type!=="selection"?null:(0,a.jsxs)("svg",{"aria-hidden":"true",className:Sn,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-target","data-target-type":"selection",children:[e.observationRects.map((r,o)=>(0,a.jsx)("rect",{"data-observation":"",x:r.x,y:r.y,width:r.width,height:r.height,rx:n.cornerRadius,fill:"none",...ke(n)},o)),(0,a.jsx)("rect",{x:e.box.x,y:e.box.y,width:e.box.width,height:e.box.height,rx:n.cornerRadius,fill:"none",...ke(n)})]})},ke=e=>({stroke:e.stroke,strokeOpacity:e.alpha,strokeWidth:e.strokeWidth,strokeDasharray:(0,d.toStrokeDasharray)(e.dashArray,e.strokeWidth)}),xu=e=>e.target.type==="observation"?e.target.box:e.target.rect,fu=e=>e.target.type==="observation"?String(e.target.point.anchor.anchorValue):e.target.id,yu=({panelRect:e})=>{const t=c.useEditorState(l=>c.readStanding(l,"arrow-endpoint-drag")),n=c.useResolvedAnnotations(e).arrows,r=c.useStyleReaderTree();if(t===null)return null;const o=n.find(l=>l.id===t.annotationId);if(o===void 0)return null;const i=(0,d.resolveArrowAnnotationStyle)(r,o.id),s=(0,d.computeArrow)({arrow:xn(o,t,e),style:i,panelWidth:e.width,panelHeight:e.height});return s===null?null:(0,a.jsx)("svg",{"aria-hidden":"true",className:yn,width:e.width,height:e.height,style:{left:e.x,top:e.y},"data-testid":"arrow-endpoint-preview","data-annotation-id":t.annotationId,children:(0,a.jsx)(c.ArrowAnnotation,{computed:s,style:i,addressable:!1})})},Su=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,a.jsx)("path",{d:"M19 12H5"})]})}),ga=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M5 12h14"}),(0,a.jsx)("path",{d:"m12 5 7 7-7 7"})]})}),ma=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{fill:"currentColor",children:[(0,a.jsx)("rect",{x:"3",y:"5",width:"18",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"3",y:"10",width:"18",height:"3",rx:"1.5"}),(0,a.jsx)("rect",{x:"3",y:"16.5",width:"18",height:"4.5",rx:"2.25"})]})}),bu=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",children:[(0,a.jsx)("path",{d:"M5 19 8 16"}),(0,a.jsx)("path",{d:"M10.5 13.5 13.5 10.5"}),(0,a.jsx)("path",{d:"M16 8 19 5"})]})}),Cu=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",children:[(0,a.jsx)("path",{d:"M5 19h0"}),(0,a.jsx)("path",{d:"M8.5 15.5h0"}),(0,a.jsx)("path",{d:"M12 12h0"}),(0,a.jsx)("path",{d:"M15.5 8.5h0"}),(0,a.jsx)("path",{d:"M19 5h0"})]})}),wu=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsx)("path",{d:"M5 19 19 5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})}),Tu=[{value:d.ARROW_STROKE_WIDTHS_PX.thin,key:"graph.annotations.arrowToolbar.thickness.thin"},{value:d.ARROW_STROKE_WIDTHS_PX.medium,key:"graph.annotations.arrowToolbar.thickness.medium"},{value:d.ARROW_STROKE_WIDTHS_PX.thick,key:"graph.annotations.arrowToolbar.thickness.thick"}],gr=[{value:"lineArrow",key:"graph.annotations.arrowToolbar.arrowhead.lineArrow",Icon:ga},{value:"none",key:"graph.annotations.arrowToolbar.arrowhead.none",Icon:c.MinusIcon}],mr=[{value:"solid",key:"graph.annotations.arrowToolbar.lineStyle.solid",Icon:wu},{value:"dashed",key:"graph.annotations.arrowToolbar.lineStyle.dashed",Icon:bu},{value:"dotted",key:"graph.annotations.arrowToolbar.lineStyle.dotted",Icon:Cu}],ju=(e,t)=>e.find(n=>n.value===t)??e[0];var Au=({arrow:e,arrowBox:t,panelRect:n,frameWidth:r,frameHeight:o,frameElement:i})=>{const s=c.useI18n(),{commands:l}=c.useGraphContext(),h=c.useSceneSelector(k=>k.spec.styles.overrides),u=c.useSceneSelector(k=>(0,d.readStyleCoord)(k.spec)),p=v.useToolbarPopups(),g=(0,d.resolveArrowAnnotationStyle)(c.useStyleReaderTree(),e.id),m=ju(mr,(0,d.toDashPreset)(g.dashArray)),f=g.outline.strokeWidth>0||g.outline.shadow!=="none",x=(0,b.useMemo)(()=>({target:"annotation",kind:"arrow",annotation:e.id}),[e.id]),y=(0,b.useMemo)(()=>({...x,part:"outline"}),[x]),w=(k,_)=>{const O=(0,d.findStyleRule)(h,{select:x},u)?.declarations??{};l.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:x,declarations:{...O,...k}}}),_)},S=k=>{const _=(0,d.findStyleRule)(h,{select:y},u)?.declarations??{};l.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:y,declarations:{..._,...k}}}))},I=k=>{w(k),p.close()},j=k=>{l.dispatch(new d.UpdateAnnotationCommand({kind:"arrow",id:e.id,patch:k})),p.close()},A=()=>{l.dispatch(new d.RemoveAnnotationCommand({id:e.id})),i.focus({preventScroll:!0})},T=k=>w({stroke:k},{transient:!0}),M=k=>I({strokeWidth:k}),G=k=>j({startArrowheadStyle:k}),L=k=>I({dashArray:d.DASH_PRESETS.arrow[k]}),B=k=>j({endArrowheadStyle:k}),R=()=>S(f?{strokeWidth:0,shadow:"none"}:d.ARROW_STICKER_DECLARATIONS);return(0,a.jsxs)(v.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameWidth:r,frameHeight:o,label:s("graph.annotations.arrowToolbar.label"),testId:"arrow-toolbar",children:[(0,a.jsx)(v.SelectionToolbar.ColorPicker,{color:g.stroke,label:s("graph.annotations.arrowToolbar.color"),onChange:T,...p.bind("color"),children:(0,a.jsx)(v.SelectionToolbar.Swatch,{color:g.stroke})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:s("graph.annotations.arrowToolbar.thickness.ariaLabel"),trigger:(0,a.jsx)(ma,{size:"sm",title:""}),...p.bind("thickness"),children:(0,a.jsx)(Ue,{options:Tu,current:g.strokeWidth,onPick:M})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:s("graph.annotations.arrowToolbar.startArrowhead"),trigger:(0,a.jsx)(Su,{size:"sm",title:""}),...p.bind("startArrowhead"),children:(0,a.jsx)(Ue,{options:gr,current:e.startArrowheadStyle,onPick:G})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:s("graph.annotations.arrowToolbar.lineStyle.ariaLabel"),trigger:m?.Icon!==void 0&&(0,a.jsx)(m.Icon,{size:"sm",title:""}),...p.bind("lineStyle"),children:(0,a.jsx)(Ue,{options:mr,current:(0,d.toDashPreset)(g.dashArray),onPick:L})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:s("graph.annotations.arrowToolbar.endArrowhead"),trigger:(0,a.jsx)(ga,{size:"sm",title:""}),...p.bind("endArrowhead"),children:(0,a.jsx)(Ue,{options:gr,current:e.endArrowheadStyle,onPick:B})}),(0,a.jsx)(v.SelectionToolbar.ToggleButton,{label:s("graph.annotations.arrowToolbar.sticker"),pressed:f,onClick:R,children:(0,a.jsx)(v.ArrowUpRightIcon,{size:"sm",title:""})}),(0,a.jsx)(v.SelectionToolbar.Separator,{}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:s("graph.annotations.arrowToolbar.remove"),onClick:A,children:(0,a.jsx)(v.TrashIcon,{size:"sm",title:""})})]})},Ue=({options:e,current:t,onPick:n})=>{const r=c.useI18n(),o=i=>()=>n(i);return(0,a.jsx)(a.Fragment,{children:e.map(i=>(0,a.jsxs)(v.SelectionToolbar.MenuItem,{selected:i.value===t,onClick:o(i.value),children:[(0,a.jsx)("span",{children:r(i.key)}),i.Icon!==void 0&&(0,a.jsx)("span",{className:"_112xh5c0",children:(0,a.jsx)(i.Icon,{size:"sm",title:""})})]},String(i.value)))})},Pu="_1me29t10",fe=(e,t,n,r,o)=>{if(e.anchorType==="panel")return null;const i=(0,d.projectAnchorToPanel)(n,r),s=o===void 0?void 0:(0,d.readOutwardGapOffset)(e.align,o),l=n.space==="disk"?void 0:e.offset??s,h=(l?.x??0)*(l?.unit==="px"?1:r.width),u=(l?.y??0)*(l?.unit==="px"?1:r.height);return{anchor:e,sourceAlign:t,targetPoint:{x:i.x-h,y:i.y-u}}},Iu={distance:8,margin:d.SELECTION_PADDING_DEFAULT.x??0},de=(e,t)=>({anchorType:"panel",x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0,width:t.width>0?e.width/t.width:0,height:t.height>0?e.height/t.height:0}),lt=(e,t,n,r)=>{const o=(t==="shape"?e.shapes:e.images).find(i=>i.id===n);return o===void 0?null:(0,d.projectRegionToPanel)(o.region,r)},va=(e,t,n)=>n==="px"?{width:e.width,height:e.height,unit:n}:{width:v.normalizeToPanelExtent(e.width,t.width),height:v.normalizeToPanelExtent(e.height,t.height)},ku=(e,t,n,r,o)=>{if(e.type==="free"){const i=(0,d.alignUnitFractions)(n),s=e.point.x-i.x*t.width,l=e.point.y-i.y*t.height;return de({x:s,y:l,width:t.width,height:t.height},r)}return e.anchor.anchorType!=="observation"&&e.anchor.anchorType!=="annotation"?de(t,r):{...e.anchor,...va(t,r,o),regionAlign:e.sourceAlign??n}},xa=(e,t,n)=>{const r=e.regionAlign??"center",o=(0,d.readRectPoint)(t,r),i={x:v.normalizeToPanelExtent(o.x,n.width),y:v.normalizeToPanelExtent(o.y,n.height)};return fe((0,d.toPlacedRegionPoint)(e),r,i,n)},fa=(e,t,n,r=d.PANEL_FRACTION_BOUNDS)=>({x:vr(e.x,e.width,t.x,r.minX*n.width,r.maxX*n.width),y:vr(e.y,e.height,t.y,r.minY*n.height,r.maxY*n.height)}),bn=({rect:e,panelRect:t,bounds:n,layers:r,readObservationBox:o,mayEnclose:i})=>i?(0,d.resolveRegionPlacement)({rect:e,layers:r,readObservationBox:o,panelRect:t,bounds:n,snap:Iu}):{type:"free",region:de(e,t),rect:e},vr=(e,t,n,r,o)=>{if(!Number.isFinite(n)||!Number.isFinite(e))return 0;const i=Math.min(r-e,0),s=Math.max(o-(e+t),0);return Math.min(Math.max(n,i),s)},ya=e=>e.start.anchorType!=="panel"||e.end.anchorType!=="panel",Lu=({arrow:e,painted:t,compiled:n,travel:r,bounds:o,free:i,...s})=>{const{panelRect:l,coordSystem:h}=s,u={start:(0,d.projectAnchorToPanel)(t.start,l),end:(0,d.projectAnchorToPanel)(t.end,l)},p=fa({x:Math.min(u.start.x,u.end.x),y:Math.min(u.start.y,u.end.y),width:Math.abs(u.end.x-u.start.x),height:Math.abs(u.end.y-u.start.y)},r,l,o),g=x=>gn(Eu(e[x],n?.[x]),t[x],s),m={start:g("start"),end:g("end")},f=x=>{const y=e[x];if(p.x===0&&p.y===0)return{anchor:y};const w={x:u[x].x+p.x,y:u[x].y+p.y};if(y.anchorType==="panel")return{anchor:{...y,x:y.x+v.normalizeToPanelExtent(p.x,l.width),y:y.y+v.normalizeToPanelExtent(p.y,l.height)}};const S={anchor:{anchorType:"panel",x:v.normalizeToPanelExtent(w.x,l.width),y:v.normalizeToPanelExtent(w.y,l.height)}};if(i||h.type==="polar"&&y.anchorType!=="annotation")return S;let I=y,j;if(y.align==="auto"){const T=m[x];if(T.width>0&&T.height>0){const M=m[x==="start"?"end":"start"],G=(0,d.readFacingAlign)(T,M);I={...y,align:G},j=(0,d.readRectPoint)(T,G)}else{const{align:M,...G}=y;I=G,j={x:T.x,y:T.y}}}else{const T=fe(y,null,t[x],l,d.ARROW_TARGET_GAP_PX);if(T===null)return S;j=T.targetPoint}const A={x:w.x-j.x,y:w.y-j.y};return Math.hypot(A.x,A.y)>40?S:{anchor:{...I,offset:{...A,unit:"px"}},tether:{targetPoint:j,point:w}}};return{translation:p,ends:{start:f("start"),end:f("end")}}},Eu=(e,t)=>{if(e.anchorType!=="observation"||e.layerId!==void 0||t?.defer?.type!=="observationBox")return e;const n=t.defer.observations[0]?.layerId;return n===void 0?e:{...e,layerId:n}};var ie=(e,t)=>t?e.altKey:!e.altKey,Sa=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y)>=3,Re=class{constructor(e){this.params=e,this.listeners=new AbortController,this.pendingEvent=null,this.scheduledFrame=null,this.hasMoved=!1,this.hasPublished=!1,this.confirmedDrag=!1,this.releasePoint=null,this.handleMove=t=>{t.pointerId===this.params.pointerId&&(this.pendingEvent=t,this.hasMoved=!0,this.scheduledFrame===null&&(this.scheduledFrame=requestAnimationFrame(this.runFrame)))},this.handleUp=t=>{t.pointerId===this.params.pointerId&&(this.pendingEvent=t,this.releasePoint={x:t.clientX,y:t.clientY},this.finish(!0))},this.handleLost=t=>{t.pointerId===this.params.pointerId&&this.finish(!1)},this.runFrame=()=>{this.scheduledFrame=null;const t=this.pendingEvent;if(this.pendingEvent=null,t===null)return;const n=this.params.editorStore.getState();if(this.hasPublished&&this.readOwn(n)===null)return;const r={x:t.clientX,y:t.clientY};if(!this.hasPublished&&!this.isDragConfirmed(this.params.press,r))return;this.confirmedDrag=!0;const o=this.resolvePreview(r,{altKey:t.altKey});o!==null&&(n.claimInteraction(o),this.hasPublished=!0)}}start(){const{handle:e}=this.params,{signal:t}=this.listeners;e.addEventListener("pointermove",this.handleMove,{signal:t}),e.addEventListener("pointerup",this.handleUp,{signal:t}),e.addEventListener("lostpointercapture",this.handleLost,{signal:t})}finish(e){this.params.onSettled(),this.listeners.abort(),this.cancelFrame();try{e&&this.hasMoved&&this.runFrame()}finally{this.settle(e)}}isDragConfirmed(e,t){return Sa(e,t)}settle(e){this.pendingEvent=null;const t=this.params.editorStore.getState(),n=this.readOwn(t);n!==null&&t.releaseInteraction(this.kind),e&&n!==null&&this.commit(n),e&&!this.confirmedDrag&&this.params.onClick!==void 0&&(document.activeElement===this.params.handle&&this.params.handle.blur(),this.params.onClick(this.releasePoint??this.params.press))}cancelFrame(){this.scheduledFrame!==null&&(cancelAnimationFrame(this.scheduledFrame),this.scheduledFrame=null)}},Cn=["top","bottom","left","right","topLeft","topRight","bottomLeft","bottomRight"],Kt=["center",...Cn],xr=(e,t,n)=>{const r={...e,x:e.x+n.x,y:e.y+n.y};return[t,...Kt.filter(o=>o!==t)].map(o=>({align:o,point:(0,d.readRectPoint)(r,o)}))},ht=(e,t,n,r)=>{const o=[];for(const[i,s]of(0,d.indexSceneAnnotations)(e)){if(t.has(i)||s.kind!=="text"&&s.kind!=="shape"&&s.kind!=="image"&&s.kind!=="sticker")continue;const l=(0,d.readAnnotationBox)(s,n,r);l===null||l.xMax<=l.xMin||l.yMax<=l.yMin||o.push({id:i,rect:(0,d.projectBoxToPanel)(l,n)})}return o},fr=(e,t,n,r)=>{const o=(0,d.readRectPoint)(t,e.sourceAlign??n);return{x:v.normalizeToPanelExtent(e.point.x-o.x,r.width),y:v.normalizeToPanelExtent(e.point.y-o.y,r.height)}},Mu=(e,t)=>{const n=e.sourceAlign??t.align;return n===t.align&&(0,Q.isEqual)(e.anchor,t.at)?null:{at:e.anchor,align:n}},ba=class extends Re{constructor(...e){super(...e),this.kind="move-drag"}readOwn(e){return c.readMovedAnnotationFor(c.readStanding(e,"move-drag"),this.params.annotationId)}resolvePreview(e,t){return new Ut(this.params).resolve(e,t)}commit(e){new Ut(this.params).commit(e)}},Ut=class{constructor(e){this.params=e}resolve(e,t){const{annotationId:n,press:r,readInputs:o}=this.params,i=o(),s=(0,d.findAnnotation)(i.spec,n);if(s===null)return null;if(s.kind==="text")return this.resolveTextPreview(s.annotation,e,t,i);if(s.kind==="sticker")return this.resolveStickerPreview(s.annotation,e,t,i);if(s.kind==="shape"||s.kind==="image")return this.resolveRegionPreview(s,e,t,i);if(s.kind==="arrow"&&ya(s.annotation))return this.resolveArrowPreview(s.annotation,e,t,i);const{panelRect:l,frameElement:h}=i,u=v.readContainerFractionBoundsFor(l,h),p=(0,d.clampAnnotationTranslation)(s,fn(r,e,l),u);return p===null?null:{kind:"move-drag",annotationId:n,translation:p}}commit({translation:e,placement:t,ends:n}){const{annotationId:r,dispatch:o,readInputs:i}=this.params,s=i(),{spec:l,panelRect:h,frameElement:u}=s,p=(0,d.findAnnotation)(l,r);if(p!==null){if(p.kind==="shape"||p.kind==="image"){if(t===void 0)return;const g="region"in t?t.region:this.readPlacedRegion(t,p,s);if(g===null||(0,Q.isEqual)(g,p.annotation.region))return;o(new d.UpdateAnnotationCommand({kind:p.kind,id:r,patch:{region:g}}));return}if(t!==void 0&&!("region"in t)&&p.kind==="text"){const g=Mu(Qe(t,l,r,h),p.annotation);g!==null&&o(new d.UpdateAnnotationCommand({kind:"text",id:r,patch:g}));return}if(t!==void 0&&!("region"in t)&&p.kind==="sticker"){const{anchor:g}=Qe(t,l,r,h);if((0,Q.isEqual)(g,p.annotation.at))return;o(new d.UpdateAnnotationCommand({kind:"sticker",id:r,patch:{at:g}}));return}if(p.kind==="arrow"&&n!==void 0){const g={start:n.start.anchor,end:n.end.anchor};if((0,Q.isEqual)(g.start,p.annotation.start)&&(0,Q.isEqual)(g.end,p.annotation.end))return;o(new d.UpdateAnnotationCommand({kind:"arrow",id:r,patch:g}));return}ua(e)&&o(new d.MoveAnnotationCommand({id:r,translation:e,bounds:v.readContainerFractionBoundsFor(h,u)}))}}resolveArrowPreview(e,t,n,r){const{annotationId:o,press:i,editorStore:s,anchorResolver:l}=this.params,{scene:h,compiled:u,panelRect:p,frameElement:g,layers:m,coordSystem:f,measuredBoxes:x,readObservationBox:y}=r,w=h.arrows.find(j=>j.id===o);if(w===void 0)return null;const{translation:S,ends:I}=Lu({arrow:e,painted:w,compiled:u.arrows.find(j=>j.id===o),travel:{x:t.x-i.x,y:t.y-i.y},bounds:v.readContainerFractionBoundsFor(p,g),free:ie(n,s.getState().snapping),scene:h,panelRect:p,measuredBoxes:x,readObservationBox:y,layers:m,coordSystem:f,anchorResolver:l});return{kind:"move-drag",annotationId:o,translation:{x:v.normalizeToPanelExtent(S.x,p.width),y:v.normalizeToPanelExtent(S.y,p.height)},ends:I}}resolveRegionPreview(e,t,n,r){const{annotationId:o,press:i,editorStore:s,offsetOnly:l=!1}=this.params,{scene:h,panelRect:u,frameElement:p,layers:g,readObservationBox:m}=r,{kind:f,annotation:x}=e,y=lt(h,f,o,u);if(y===null)return null;const w=v.readContainerFractionBoundsFor(u,p),S=fa(y,{x:t.x-i.x,y:t.y-i.y},u,w);if(f==="shape"&&!l){const M=bn({rect:{...y,x:y.x+S.x,y:y.y+S.y},panelRect:u,bounds:w,layers:g,readObservationBox:m,mayEnclose:!ie(n,s.getState().snapping)});if(M.type==="selection")return{kind:"move-drag",annotationId:o,translation:{x:v.normalizeToPanelExtent(M.rect.x-y.x,u.width),y:v.normalizeToPanelExtent(M.rect.y-y.y,u.height)},placement:M}}const I=(0,d.isPlacedRegionAnchor)(x.region)?x.region:null,j=I?.regionAlign??"center",A=I===null?null:xa(I,y,u),T=this.resolvePlacement(xr(y,j,S),(0,d.readRectPoint)(y,j),A,n,r,{targetAligns:Kt});return T===null?null:{kind:"move-drag",annotationId:o,translation:fr(T,y,j,u),placement:T}}readPlacedRegion(e,t,n){const{annotationId:r}=this.params,{spec:o,scene:i,panelRect:s}=n,l=lt(i,t.kind,r,s);if(l===null)return null;const h=(0,d.isPlacedRegionAnchor)(t.annotation.region)?t.annotation.region:null;return ku(Qe(e,o,r,s),l,h?.regionAlign??"center",s,h?.unit)}resolveStickerPreview(e,t,n,r){const{annotationId:o,press:i}=this.params,{scene:s,panelRect:l}=r,h=s.stickers.find(m=>m.id===o);if(h===void 0)return null;const u=(0,d.projectAnchorToPanel)(h.at,l),p={x:t.x-i.x,y:t.y-i.y},g=this.resolvePlacement([{align:null,point:{x:u.x+p.x,y:u.y+p.y}}],u,fe(e.at,null,h.at,l),n,r,{targetAligns:Cn,areaAlign:"center"});return g===null?null:{kind:"move-drag",annotationId:o,translation:{x:v.normalizeToPanelExtent(g.point.x-u.x,l.width),y:v.normalizeToPanelExtent(g.point.y-u.y,l.height)},placement:g}}resolveTextPreview(e,t,n,r){const{annotationId:o,press:i}=this.params,{scene:s,panelRect:l,measuredBoxes:h}=r,u=s.textAnnotations.find(x=>x.id===o);if(u===void 0)return null;const p=(0,d.readAnnotationBox)({kind:"text",annotation:u},l,h);if(p===null)return null;const g=(0,d.projectBoxToPanel)(p,l),m={x:t.x-i.x,y:t.y-i.y},f=this.resolvePlacement(xr(g,e.align,m),(0,d.readRectPoint)(g,e.align),fe(e.at,e.align,u.at,l),n,r,{targetAligns:Kt});return f===null?null:{kind:"move-drag",annotationId:o,translation:fr(f,g,e.align,l),placement:f}}resolvePlacement(e,t,n,r,o,i){const{annotationId:s,engine:l,anchorResolver:h,editorStore:u,offsetOnly:p=!1}=this.params,{spec:g,scene:m,panelRect:f,frameElement:x,layers:y,coordSystem:w,measuredBoxes:S,readObservationBox:I}=o,j=new Set([s,...(0,d.collectDependentAnnotationIds)(g,s)]),A=v.includePointInBounds(v.readContainerFractionBoundsFor(f,x),{x:v.normalizeToPanelExtent(t.x,f.width),y:v.normalizeToPanelExtent(t.y,f.height)}),T=u.getState(),M=this.params.previous?.()??c.readMovedAnnotationFor(c.readStanding(T,"move-drag"),s)?.placement,G=!p&&ie(r,T.snapping);return(0,d.resolvePointPlacement)({sourcePoints:e,current:r.altKey&&!p?null:n,panelRect:f,bounds:A,engine:l,layers:y,coordSystem:w,resolver:h,readObservationBox:I,annotationTargets:G?[]:ht(m,j,f,S),snapDistance:8,releaseDistance:12,revealDistance:160,previous:M?.type==="snapped"?M.target:null,detachDistance:p?Number.POSITIVE_INFINITY:40,targetAligns:i.targetAligns,areaAlign:i.areaAlign,areaSnapDistance:16,purpose:"pin",allow:{observation:!G,annotation:!G,free:!p},currentOnly:p})}},Qe=(e,t,n,r)=>{if(e.anchor.anchorType!=="annotation"||!(0,d.collectDependentAnnotationIds)(t,n).has(e.anchor.ref))return e;const{point:o,sourceAlign:i}=e,s=Math.max(0,Math.min(1,v.normalizeToPanelExtent(o.x,r.width))),l=Math.max(0,Math.min(1,v.normalizeToPanelExtent(o.y,r.height)));return{type:"free",anchor:{anchorType:"panel",x:s,y:l},sourceAlign:i,point:{x:s*r.width,y:l*r.height},nearby:[]}},Ca={snapDistance:8,releaseDistance:12,revealDistance:160,detachDistance:40,targetGapPx:d.ARROW_TARGET_GAP_PX,targetAligns:Cn,areaAlign:"auto",annotationAreaAlign:"auto",areaSnapDistance:16,purpose:"pin"},Ou=new Set,Le=(e,t,n)=>{const r=t.getBoundingClientRect(),o=v.readFrameScale(t,r.width);return{x:(e.x-r.left)/o-n.x,y:(e.y-r.top)/o-n.y}},Ru=({start:e,startObservationIndex:t},n,r)=>{const{panelRect:o}=n;return e.anchorType==="panel"?{x:e.x*o.width,y:e.y*o.height,width:0,height:0}:na(e,t,{...n,anchorResolver:r})},wa=({start:e,startObservationIndex:t,point:n,free:r,previous:o,inputs:i,engine:s,anchorResolver:l})=>{const{scene:h,panelRect:u,frameElement:p,layers:g,coordSystem:m,measuredBoxes:f,readObservationBox:x}=i,y=Ru({start:e,startObservationIndex:t},i,l);if(y===null)return null;const w=_u(e,y),S=e.anchorType==="annotation"?new Set([e.ref]):Ou,I=(0,d.resolvePointPlacement)({...Ca,sourcePoints:[{align:null,point:n}],current:null,panelRect:u,bounds:v.readContainerFractionBoundsFor(u,p),engine:s,layers:g,coordSystem:m,resolver:l,readObservationBox:x,annotationTargets:r?[]:ht(h,S,u,f),previous:o?.type==="snapped"?o.target:null,facing:w===null?y:{...w,width:0,height:0},allow:{observation:!r,annotation:!r,free:!0},excludedObservation:e.anchorType==="observation"&&e.layerId!==void 0&&t!==void 0?{layerId:e.layerId,observationIndex:t}:void 0});if(I===null)return null;const j=I.point;if(w!==null)return{placement:I,startPoint:w,endPoint:j};if(e.anchorType==="observation"&&y.width===0&&y.height===0)return{placement:I,startPoint:{x:y.x,y:y.y},endPoint:j};const A=(0,d.readFacingAlign)(y,Du(I)??{x:j.x,y:j.y,width:0,height:0}),T=(0,d.readOutwardGapOffset)(A,d.ARROW_TARGET_GAP_PX),M=(0,d.readRectPoint)(y,A);return{placement:I,startPoint:{x:M.x+(T?.x??0),y:M.y+(T?.y??0)},endPoint:j}},_u=(e,t)=>{if(e.anchorType==="panel")return{x:t.x,y:t.y};if(!("align"in e)||e.align==="auto")return null;const n=e.align??"center",r=(0,d.readOutwardGapOffset)(n,d.ARROW_TARGET_GAP_PX),o=(0,d.readRectPoint)(t,n);return{x:o.x+(r?.x??0),y:o.y+(r?.y??0)}},Du=e=>e.type!=="snapped"||e.landing!=="area"?null:e.target.type==="annotation"?e.target.rect:e.target.box,Nu=(e,t)=>{if(t===null)return!1;if(e.anchorType==="observation"&&t.anchorType==="observation"){const n=t.layerId??e.layerId;return(0,d.areAnchorsEqual)({...e,align:void 0},{...t,align:void 0,layerId:n})}return e.anchorType==="annotation"&&t.anchorType==="annotation"&&e.ref===t.ref},Gu=class extends Re{constructor(...e){super(...e),this.kind="arrow-endpoint-drag"}readOwn(e){const{annotationId:t,endpoint:n}=this.params;return c.readDraggedArrowEndpointFor(c.readStanding(e,"arrow-endpoint-drag"),t,n)}resolvePreview(e,t){const{annotationId:n,endpoint:r,press:o,readInputs:i,engine:s,anchorResolver:l,editorStore:h}=this.params,u=i(),{spec:p,arrow:g,scene:m,panelRect:f,layers:x,coordSystem:y,measuredBoxes:w,readObservationBox:S}=u,I=Je(p,n,r);if(I===null)return null;const j={x:e.x-o.x,y:e.y-o.y},A=(0,d.projectAnchorToPanel)(g[r],f),T=v.includePointInBounds(v.readContainerFractionBoundsFor(f,u.frameElement),{x:v.normalizeToPanelExtent(A.x,f.width),y:v.normalizeToPanelExtent(A.y,f.height)}),M=r==="start"?"end":"start",G=Je(p,n,M),L=G===null?void 0:gn(G,g[M],{scene:m,panelRect:f,measuredBoxes:w,readObservationBox:S,layers:x,coordSystem:y,anchorResolver:l}),B=new Set([n,...(0,d.collectDependentAnnotationIds)(p,n)]),R=h.getState(),k=this.readOwn(R)?.placement,_=ie(t,R.snapping),O=z=>(0,d.resolvePointPlacement)({...Ca,...z?{}:{areaAlign:void 0,annotationAreaAlign:void 0},sourcePoints:[{align:null,point:{x:A.x+j.x,y:A.y+j.y}}],current:_?null:fe(I,null,g[r],f,d.ARROW_TARGET_GAP_PX),panelRect:f,bounds:T,engine:s,layers:x,coordSystem:y,resolver:l,readObservationBox:S,annotationTargets:_?[]:ht(m,B,f,w),previous:k?.type==="snapped"?k.target:null,facing:L,allow:{observation:!_,annotation:!_,free:!0}}),C=O(!0),D=C?.type==="snapped"&&C.landing==="area"&&Nu(C.anchor,G)?O(!1):C;return D===null?null:{kind:"arrow-endpoint-drag",annotationId:n,endpoint:r,placement:D}}commit({endpoint:e,placement:t}){const{annotationId:n,dispatch:r,readInputs:o}=this.params,{spec:i,panelRect:s}=o(),l=Je(i,n,e);if(l===null)return;const h=Qe(t,i,n,s).anchor;ca(l,h)||r(new d.UpdateAnnotationCommand({kind:"arrow",id:n,patch:ta(e,h)}))}},Bu=({annotationId:e,arrow:t,panelRect:n,frameElement:r})=>{const{commands:o,anchorResolver:i}=c.useGraphContext(),{engine:s}=c.useHoverContext(),l=c.useEditorStore(),h=c.useSceneSelector((0,ee.useShallow)(x=>({spec:x.spec.annotations,layers:x.layers,coordSystem:x.coordSystem}))),u=c.useResolvedAnnotations(n),p=c.useMeasuredBoxes(),g=c.usePaintedObservationBoxes(n),m=c.useLatestRef({...h,arrow:t,scene:u,panelRect:n,frameElement:r,measuredBoxes:p,readObservationBox:g}),f=(0,b.useRef)(null);return(0,b.useEffect)(()=>()=>f.current?.finish(!1),[]),(0,b.useCallback)(x=>({onPointerDown:y=>{if(y.button===0&&f.current===null){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{return}y.currentTarget.focus({preventScroll:!0}),y.preventDefault(),f.current=new Gu({handle:y.currentTarget,pointerId:y.pointerId,annotationId:e,endpoint:x,press:{x:y.clientX,y:y.clientY},readInputs:()=>m.current,editorStore:l,engine:s,anchorResolver:i,dispatch:o.dispatch,onSettled:()=>{f.current=null}}),f.current.start()}}}),[e,m,l,s,i,o])},Fu=[" ","Enter"],yr=4,Hu=({annotationId:e,arrow:t,panelRect:n,frameElement:r})=>{const{commands:o}=c.useGraphContext(),i=c.useEditorStore(),s=c.useSceneSelector(u=>u.spec.annotations),l=c.useLatestRef(s),h=c.useLatestRef(o.dispatch);return(0,b.useEffect)(()=>()=>{for(const u of vn)Sr({editorStore:i,annotationId:e,endpoint:u,annotations:l.current,dispatch:h.current})},[i,e,l,h]),(0,b.useCallback)(u=>({onKeyDown:p=>{if(p.altKey||p.ctrlKey||p.metaKey||p.shiftKey)return;const g=i.getState(),m=c.readDraggedArrowEndpointFor(c.readStanding(g,"arrow-endpoint-drag"),e,u);if(Fu.includes(p.key)){if(p.preventDefault(),p.repeat)return;if(m!==null){Sr({editorStore:i,annotationId:e,endpoint:u,annotations:s,dispatch:o.dispatch});return}const S=ea(s,e,u);if(S===null)return;g.claimInteraction({kind:"arrow-endpoint-drag",annotationId:e,endpoint:u,placement:cr(S,t[u],n)});return}if(m===null)return;const f=m.placement.anchor;if(f.anchorType!=="panel")return;const x=zu(p.key,n);if(x===null)return;p.preventDefault();const{anchor:y,point:w}=Jd({anchor:f,point:(0,d.toPanelCursor)(m.placement.point,n),delta:x,bounds:v.readContainerFractionBoundsFor(n,r)});g.claimInteraction({kind:"arrow-endpoint-drag",annotationId:e,endpoint:u,placement:cr(y,w,n)})}}),[e,s,t,n,r,i,o])},Sr=({editorStore:e,annotationId:t,endpoint:n,annotations:r,dispatch:o})=>{const i=e.getState(),s=c.readDraggedArrowEndpointFor(c.readStanding(i,"arrow-endpoint-drag"),t,n);if(s===null)return;i.releaseInteraction("arrow-endpoint-drag");const l=ea(r,t,n);l===null||ca(l,s.placement.anchor)||o(new d.UpdateAnnotationCommand({kind:"arrow",id:t,patch:ta(n,s.placement.anchor)}))},zu=(e,t)=>{const n=v.normalizeToPanelExtent(yr,t.width),r=v.normalizeToPanelExtent(yr,t.height);switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-r};case"ArrowDown":return{x:0,y:r};default:return null}},Wu=e=>{const t=be(),n=Uu(t),r=$u(e.panelRect,t),o=Xu(t);if(n===null||r===null)return null;const i=o.dragged===null?r:xn(r,o.dragged,e.panelRect);return(0,a.jsx)(Vu,{arrow:n,committed:r,live:i,settled:o.dragged===null&&!o.moving,moving:o.moving,...e})},Vu=({arrow:e,committed:t,live:n,settled:r,moving:o,panelRect:i,frameRect:s,frameElement:l})=>{const h=c.useI18n(),u=Bu({annotationId:e.id,arrow:t,panelRect:i,frameElement:l}),p=Hu({annotationId:e.id,arrow:t,panelRect:i,frameElement:l});return(0,a.jsxs)("div",{"data-testid":"arrow-selection","data-annotation-id":e.id,children:[r&&(0,a.jsx)(Au,{arrow:e,arrowBox:eu(t.start,t.end,i),panelRect:i,frameWidth:s.width,frameHeight:s.height,frameElement:l}),!o&&vn.map(g=>(0,a.jsx)(Ku,{endpoint:g,point:Qd(n[g],i),label:h(`graph.annotations.arrowToolbar.moveEndpoint.${g}`),dragHandlers:u(g),keyboardHandlers:p(g)},g))]})},Ku=({endpoint:e,point:t,label:n,dragHandlers:r,keyboardHandlers:o})=>(0,a.jsx)("div",{"aria-label":n,className:Pu,"data-testid":"arrow-endpoint-handle","data-endpoint":e,role:"button",style:{left:t.x,top:t.y},tabIndex:0,...r,...o}),Uu=e=>{const t=c.useSceneSelector(n=>n.spec.annotations.arrows);return e===null?null:t.find(n=>n.id===e)??null},$u=(e,t)=>{const n=c.useResolvedAnnotations(e).arrows;return t===null?null:n.find(r=>r.id===t)??null},Xu=e=>c.useEditorState((0,ee.useShallow)(t=>{if(e===null)return{dragged:null,moving:!1};const n=c.readStanding(t,"arrow-endpoint-drag");return{dragged:n?.annotationId===e?n:null,moving:c.readMovedAnnotationFor(c.readStanding(t,"move-drag"),e)!==null}})),Ta=({client:e,altKey:t,frameElement:n,inputs:r,editorStore:o,selectionStore:i,engine:s,anchorResolver:l,dispatch:h})=>{const u=o.getState(),p=c.readStanding(u,"arrow-draw");if(p===null)return;const g=n.getBoundingClientRect();if(e.x<g.left||e.x>g.right||e.y<g.top||e.y>g.bottom){u.releaseInteraction("arrow-draw"),u.setPlotMenu(null),i.getState().clearSelection();return}const m=wa({start:p.start,startObservationIndex:p.startObservationIndex,point:Le(e,n,r.panelRect),free:ie({altKey:t},u.snapping),previous:p.placement,inputs:r,engine:s,anchorResolver:l});if(m===null||c.isArrowTooShort(m.startPoint,m.endPoint))return;const f=new d.AddAnnotationCommand({kind:"arrow",annotation:{...d.ARROW_DEFAULTS,...c.arrowHeads(p.heads),start:p.start,end:m.placement.anchor}});h(f),u.releaseInteraction("arrow-draw");const{anchor:x}=m.placement;c.startsOnTarget(p)?x.anchorType==="panel"?u.setPlotMenu({x:x.x,y:x.y,arrowId:f.params.annotation.id}):(u.setPlotMenu(null),i.getState().setSelection([f.target])):u.setPlotMenu(null)},qu="_1vsi7qw1",Yu="_1vsi7qw2",Zu="_1vsi7qw3";var br=24,Ju=new Set,Cr=new WeakMap,wr=(e,t)=>{if(e.coordSystem.type==="polar")return[];const{scene:n,panelRect:r,measuredBoxes:o}=e;return[...ht(n,Ju,r,o).map(({id:i,rect:s})=>({key:`annotation:${i}`,rect:s,draw:{start:{anchorType:"annotation",ref:i,align:"auto"}}})),...nh(e,t)]},Qu=(e,t,n=32)=>{const r=[];for(const o of e){const i=ja(t,o.rect);i<=n&&r.push({target:o,distance:i})}return r.sort((o,i)=>o.distance-i.distance).map(({target:o})=>o)},eh=(e,t,n)=>{const r=[];for(const o of e)for(const{point:i,align:s}of th(o.rect,n,o.snapAligns)){const l=r.some(u=>Math.hypot(u.point.x-i.x,u.point.y-i.y)<16),h=t.some(u=>u.key!==o.key&&ja(i,u.rect)<16/2);!l&&!h&&r.push({point:i,target:o,draw:rh(o.draw,s)})}return r},th=(e,t,n)=>{const r=e.x+e.width/2,o=e.y+e.height/2,i={x:r,y:e.y-10},s={x:r,y:e.y+e.height+10},l=h=>h.x>=t.x&&h.x<=t.x+t.width&&h.y>=t.y&&h.y<=t.y+t.height;if(n===void 0&&e.width<br&&e.height<br){const h=l(i)?i:s;return l(h)?[{point:h,align:"auto"}]:[]}return[{point:i,align:"top"},{point:{x:e.x+e.width+10,y:o},align:"right"},{point:s,align:"bottom"},{point:{x:e.x-10,y:o},align:"left"}].filter(({point:h,align:u})=>(n===void 0||n.includes(u))&&l(h))},nh=({layers:e,panelRect:t,readObservationBox:n,coordSystem:r},o)=>{const i=Cr.get(n);if(i!==void 0&&i.layers===e&&i.resolver===o&&i.coordSystem===r&&i.panelWidth===t.width&&i.panelHeight===t.height)return i.targets;const s=[];for(const l of e){if(!l.interactive)continue;const h=(0,d.createObservationAnchorBuilder)(l),u=o.resolveSnapAligns(l.geom,r);if((0,d.isPointTarget)(u))continue;const p=l.data.size();for(let g=0;g<p;g+=1){const m=l.data.getAt(g),f=n({layerId:l.id,observationIndex:g}),x=m===null?null:h(m);if(f===null||x===null)continue;const y=(0,d.projectBoxToPanel)(f,t);y.width<=0||y.height<=0||s.push({key:`observation:${l.id}:${g}`,rect:y,snapAligns:u,draw:{start:{...x,anchorType:"observation",align:"auto"},startObservationIndex:g}})}}return Cr.set(n,{layers:e,resolver:o,coordSystem:r,panelWidth:t.width,panelHeight:t.height,targets:s}),s},rh=(e,t)=>{const{start:n}=e;return n.anchorType==="observation"||n.anchorType==="annotation"?{...e,start:{...n,align:t}}:e},ja=(e,t)=>{const n=Math.max(t.x-e.x,0,e.x-(t.x+t.width)),r=Math.max(t.y-e.y,0,e.y-(t.y+t.height));return Math.hypot(n,r)},Lt=[],oh=({frameElement:e,panelRect:t})=>{const{chartId:n,commands:r,selectionStore:o,anchorResolver:i}=c.useGraphContext(),{engine:s}=c.useHoverContext(),l=c.useEditorStore(),h=v.useStartArrowDraw(),u=ye(t,e),p=u.current,g=c.useStyleReaderTree().snapTarget.nearby().resolve(),m=c.MODE_RULES[c.useGraphMode()].showMenuTriggerOnHover,f=c.useSceneSelector(B=>B.coordSystem.type==="polar"),x=c.useGraphSelection().length>0,y=c.useEditorState(B=>B.standingInteraction!==null||B.plotMenu!==null||B.caret!==null),w=m&&!f&&!x&&!y,[S,I]=(0,b.useState)(Lt),j=(0,b.useRef)(null),A=(0,b.useRef)(null);if((0,b.useEffect)(()=>{if(!w){j.current=null,I(Lt);return}let B=null;const R=()=>{B=null;const _=j.current;if(_===null)return;const O=u.current,C=_.onChart?Qu(wr(O,i),Le(_.client,e,O.panelRect)):Lt;I(D=>(0,Q.isEqual)(D,C)?D:C)},k=_=>{_.buttons===0&&(j.current={client:{x:_.clientX,y:_.clientY},onChart:_.pointerType!=="touch"&&v.isWithinChart(_.target,e,n)},B??=requestAnimationFrame(R))};return R(),document.addEventListener("pointermove",k,{passive:!0}),()=>{document.removeEventListener("pointermove",k),B!==null&&cancelAnimationFrame(B)}},[w,n,e,u,p.layers,p.coordSystem,p.scene,p.panelRect,p.measuredBoxes,p.readObservationBox,i]),(0,b.useEffect)(()=>{const B=C=>{try{e.releasePointerCapture(C)}catch{}},R=C=>{const D=A.current;return D!==null&&D.pointerId===C.pointerId?D:null},k=C=>{const D=R(C);D===null||D.dragging||(D.dragging=Sa(D.press,{x:C.clientX,y:C.clientY}))},_=C=>{const D=R(C);D!==null&&(A.current=null,B(C.pointerId),D.dragging&&Ta({client:{x:C.clientX,y:C.clientY},altKey:C.altKey,frameElement:e,inputs:u.current,editorStore:l,selectionStore:o,engine:s,anchorResolver:i,dispatch:r.dispatch}))},O=C=>{R(C)!==null&&(A.current=null,B(C.pointerId),l.getState().releaseInteraction("arrow-draw"))};return document.addEventListener("pointermove",k),document.addEventListener("pointerup",_),document.addEventListener("pointercancel",O),e.addEventListener("lostpointercapture",O),()=>{document.removeEventListener("pointermove",k),document.removeEventListener("pointerup",_),document.removeEventListener("pointercancel",O),e.removeEventListener("lostpointercapture",O);const C=A.current;C!==null&&(A.current=null,B(C.pointerId),l.getState().releaseInteraction("arrow-draw"))}},[e,u,l,o,s,i,r]),!w||S.length===0)return null;const T=v.readContainerFractionBoundsFor(t,e),M={x:T.minX*t.width,y:T.minY*t.height,width:(T.maxX-T.minX)*t.width,height:(T.maxY-T.minY)*t.height},G=wr(p,i),L=(B,R)=>{if(B.button===0){B.preventDefault();try{e.setPointerCapture(B.pointerId)}catch{}A.current={pointerId:B.pointerId,press:{x:B.clientX,y:B.clientY},dragging:!1},h(R,{clientX:B.clientX,clientY:B.clientY})}};return(0,a.jsx)("div",{className:qu,"aria-hidden":"true","data-testid":"connector-dots",children:eh(S,G,M).map(({point:B,target:R,draw:k})=>(0,a.jsx)("span",{className:Yu,style:{left:t.x+B.x,top:t.y+B.y,width:16,height:16,margin:-16/2,color:g.stroke},"data-testid":"connector-dot","data-target":R.key,...v.stampChartChrome(n),onPointerDown:_=>L(_,k),children:(0,a.jsx)("span",{className:Zu,style:{width:g.size,height:g.size,borderWidth:g.strokeWidth,borderColor:g.stroke,opacity:g.alpha}})},`${R.key}:${B.x}:${B.y}`))})},ah=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M4 9h16m-4-4 4 4"}),(0,a.jsx)("path",{d:"M20 15H4m4 4-4-4"})]})}),Aa="var(--ydgo3h0)";var ih="ydgo3h1",sh="ydgo3h2",lh="ydgo3h3",ch="ydgo3h4",Tr={small:2,medium:3,large:5},dh=(e,t)=>{const n=Object.keys(Tr),r=n.find(o=>{const i=Tr[o];return i===d.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].arrow.strokeWidth?!1:e.strokeWidth===i&&uh(e.label,d.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].label,t)});return r!==void 0?r:n.find(o=>d.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].arrow.strokeWidth===e.strokeWidth)},uh=(e,t,n)=>!(t.fontSize!==void 0&&e.fontSize!==t.fontSize*n||t.fontWeight!==void 0&&e.fontWeight!==t.fontWeight||t.paddingInline!==void 0&&e.paddingInline!==t.paddingInline||t.paddingBlock!==void 0&&e.paddingBlock!==t.paddingBlock||t.strokeWidth!==void 0&&e.strokeWidth!==t.strokeWidth),hh="q7gcrz0",ph="q7gcrz1",gh="q7gcrz2";var mh=4,vh=6,xh=c.iconSizeMap.sm,fh=3,yh=({textMeasurer:e,textScale:t,labelKindName:n,labelKindValue:r,sizeLabel:o})=>{const i={family:c.DEFAULT_FONT_FAMILY,size:c.emToPx(c.FONT_SIZE_EM.md,t),weight:c.FONT_WEIGHT.medium},s=p=>p.length===0?0:e.measureText(p,i).width,l=p=>p===0?0:p*mh,h=[n,r].filter(p=>p.length>0).length,u=o.length===0?0:1;return s(n)+s(r)+s(o)+l(h)+l(u)+Sh()},Sh=()=>36+34*fh+vh*4+xh*2,bh=["absoluteDifference","relativeDifference","proportion"],jr=["absoluteDifference","relativeDifference"],Ch=["relativeDifference","proportion"],wh={absoluteDifference:"graph.annotations.differenceArrowToolbar.labelKind.absoluteDifference",relativeDifference:"graph.annotations.differenceArrowToolbar.labelKind.relativeDifference",proportion:"graph.annotations.differenceArrowToolbar.labelKind.proportion"},Th=e=>{const{formattingLocale:t}=c.useGraphContext(),n=c.useSceneSelector(o=>o.config.parsingLocale),r=t??n;return(0,b.useMemo)(()=>{const o=(0,d.areEndpointsComparable)(e.start,e.end);return bh.filter(i=>o||!jr.includes(i)||i===e.label).map(i=>({kind:i,key:wh[i],preview:(0,d.formatDifferenceLabel)({locale:r,kind:i,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat}),pickable:o||!jr.includes(i),suspect:Ch.includes(i)&&e.start.measurementValue===0}))},[e,r])},Ar=[{id:"small",key:"graph.annotations.differenceArrowToolbar.size.small"},{id:"medium",key:"graph.annotations.differenceArrowToolbar.size.medium"},{id:"large",key:"graph.annotations.differenceArrowToolbar.size.large"}],jh=({arrow:e,color:t,labelBox:n,start:r,end:o,panelRect:i,frameWidth:s,frameHeight:l,frameElement:h})=>{const u=c.useI18n(),p=c.useTextMeasurer(),{commands:g}=c.useGraphContext(),m=c.useSceneSelector(P=>P.spec.styles.overrides),f=c.useSceneSelector(P=>(0,d.readStyleCoord)(P.spec)),x=v.useToolbarPopups(),y=Th(e),w=c.useStyleReaderTree(),S=(0,d.resolveDifferenceArrowAnnotationStyle)(w,e.id),I=w.graph().get("textScale"),j=(0,b.useMemo)(()=>({target:"annotation",kind:"differenceArrow",annotation:e.id}),[e.id]),A=(0,b.useMemo)(()=>({...j,part:"label"}),[j]),T=y.find(P=>P.kind===e.label),M=y.some(P=>P.pickable&&P.kind!==e.label),G=Ar.find(P=>P.id===dh(S,I)),L=(P,F)=>{g.dispatch(new d.UpdateAnnotationCommand({kind:"differenceArrow",id:e.id,patch:P}),F)},B=P=>({...(0,d.findStyleRule)(m,{select:j},f)?.declarations,...P}),R=P=>({...(0,d.findStyleRule)(m,{select:A},f)?.declarations,...P}),k=P=>{L(P),x.close()},_=()=>{g.dispatch(new d.RemoveAnnotationCommand({id:e.id})),h.focus({preventScroll:!0})},O=P=>g.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:j,declarations:B({stroke:P})}}),{transient:!0}),C=()=>L({start:e.end.anchor,end:e.start.anchor}),D=P=>()=>k({label:P}),z=P=>()=>{const F=d.DIFFERENCE_ARROW_SIZE_DECLARATIONS[P];g.dispatch(new d.SetDifferenceArrowStyleCommand({annotationId:e.id,arrow:B(F.arrow),label:(0,d.omitLegacyDifferenceArrowLabelPlate)(R(F.label))})),x.close()};return(0,a.jsxs)(v.SelectionToolbar.Root,{anchorBox:n,panelRect:i,frameWidth:s,frameHeight:l,avoidBoxes:[Pr(i,r),Pr(i,o)],estimatedPillWidthPx:yh({textMeasurer:p,textScale:I,labelKindName:T===void 0?"":u(T.key),labelKindValue:T===void 0?"":`(${T.preview})`,sizeLabel:G===void 0?"":u(G.key)}),label:u("graph.annotations.differenceArrowToolbar.label"),testId:"difference-arrow-toolbar",children:[(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:u("graph.annotations.differenceArrowToolbar.labelKind.ariaLabel"),trigger:(0,a.jsx)(Ah,{option:T}),disabled:!M,...x.bind("labelKind"),children:y.map(P=>(0,a.jsxs)(v.SelectionToolbar.MenuItem,{selected:P.kind===e.label,disabled:!P.pickable,onClick:D(P.kind),children:[(0,a.jsx)("span",{children:u(P.key)}),(P.suspect||!P.pickable)&&(0,a.jsx)("span",{"aria-label":u(P.pickable?"graph.annotations.differenceArrowToolbar.labelKind.suspectValue":"graph.annotations.differenceArrowToolbar.labelKind.incomparableEnds"),className:"q7gcrz3",role:"img",children:"⚠"}),(0,a.jsx)("span",{className:gh,children:P.preview})]},P.kind))}),(0,a.jsx)(v.SelectionToolbar.Separator,{}),(0,a.jsx)(v.SelectionToolbar.ColorPicker,{color:t,label:u("graph.annotations.differenceArrowToolbar.color"),onChange:O,...x.bind("color"),children:(0,a.jsx)(v.SelectionToolbar.Swatch,{color:t})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:u("graph.annotations.differenceArrowToolbar.size.ariaLabel"),trigger:G===void 0?"":u(G.key),...x.bind("size"),children:Ar.map(P=>(0,a.jsx)(v.SelectionToolbar.MenuItem,{selected:P.id===G?.id,onClick:z(P.id),children:u(P.key)},P.id))}),(0,a.jsx)(v.SelectionToolbar.Separator,{}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:u("graph.annotations.differenceArrowToolbar.swap"),onClick:C,children:(0,a.jsx)(ah,{size:"sm",title:""})}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:u("graph.annotations.differenceArrowToolbar.remove"),onClick:_,children:(0,a.jsx)(v.TrashIcon,{size:"sm",title:""})})]})},Ah=({option:e})=>{const t=c.useI18n();return e===void 0?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:ph,children:t(e.key)}),(0,a.jsxs)("span",{className:hh,children:["(",e.preview,")"]})]})},Pr=(e,t)=>({x:e.x+t.x-24/2,y:e.y+t.y-24/2,width:24,height:24}),Pa=e=>e==="start"?"end":"start",Ia=({dispatch:e,arrow:t,endpoint:n,anchor:r})=>{(0,d.areAnchorsEqual)(r,t[n].anchor)||e(new d.UpdateAnnotationCommand({kind:"differenceArrow",id:t.id,patch:{[n]:r}}))},Ph=({clientPoint:e,panelOrigin:t,panelRect:n,engine:r,layers:o,coordSystem:i,resolver:s,fixedAnchor:l,align:h})=>{const u=(0,d.resolvePointPlacement)({sourcePoints:[{align:null,point:{x:Math.max(0,Math.min(e.x-t.x,n.width)),y:Math.max(0,Math.min(e.y-t.y,n.height))}}],current:null,panelRect:n,engine:r,layers:o,coordSystem:i,resolver:s,readObservationBox:()=>null,annotationTargets:[],snapDistance:null,detachDistance:0,targetAligns:h===void 0?[]:[h],purpose:"value",allow:{observation:!0,annotation:!1,free:!1},rejectObservation:p=>{if((0,d.areAnchorsEqual)(p,l))return!0;const g=o.find(m=>m.id===p.layerId);return g!==void 0&&(0,d.areSameStackEndpoints)(g,p,l)}});return u===null||u.type!=="snapped"||u.target.type!=="observation"?null:u.target.point},Ih=class extends Re{constructor(...e){super(...e),this.kind="difference-arrow-endpoint-drag"}readOwn(e){const{endpoint:t,readInputs:n}=this.params;return c.readDraggedDifferenceArrowEndpointFor(c.readStanding(e,"difference-arrow-endpoint-drag"),n().arrow.id,t)}resolvePreview(e){const{endpoint:t,readInputs:n,engine:r,anchorResolver:o}=this.params,{arrow:i,panelOrigin:s,panelRect:l,layers:h,coordSystem:u}=n(),p=Ph({clientPoint:e,panelOrigin:s,panelRect:l,engine:r,layers:h,coordSystem:u,resolver:o,fixedAnchor:i[Pa(t)].anchor,align:i[t].anchor.align});return p===null?null:{kind:"difference-arrow-endpoint-drag",annotationId:i.id,endpoint:t,point:p}}commit({point:e,endpoint:t}){const{dispatch:n,readInputs:r}=this.params;Ia({dispatch:n,arrow:r().arrow,endpoint:t,anchor:e.anchor})}},kh=({arrow:e,panelOrigin:t,panelRect:n,onClick:r})=>{const{commands:o,anchorResolver:i}=c.useGraphContext(),{engine:s}=c.useHoverContext(),l=c.useEditorStore(),h=c.useLatestRef({arrow:e,panelOrigin:t,panelRect:n,...c.useSceneSelector((0,ee.useShallow)(g=>({layers:g.layers,coordSystem:g.coordSystem})))}),u=c.useLatestRef(r),p=(0,b.useRef)(null);return(0,b.useEffect)(()=>()=>p.current?.finish(!1),[]),(0,b.useCallback)(g=>({onPointerDown:m=>{if(m.button===0&&p.current===null){try{m.currentTarget.setPointerCapture(m.pointerId)}catch{return}m.currentTarget.focus({preventScroll:!0}),m.preventDefault(),p.current=new Ih({handle:m.currentTarget,pointerId:m.pointerId,press:{x:m.clientX,y:m.clientY},endpoint:g,readInputs:()=>h.current,editorStore:l,engine:s,anchorResolver:i,dispatch:o.dispatch,onClick:f=>u.current(f),onSettled:()=>{p.current=null}}),p.current.start()}}}),[h,u,l,s,i,o])},Lh=[" ","Enter"],Eh=({arrow:e})=>{const{commands:t,anchorResolver:n}=c.useGraphContext(),r=c.useEditorStore(),{layers:o,coordSystem:i,mainAxis:s}=c.useSceneSelector((0,ee.useShallow)(h=>({layers:h.layers,coordSystem:h.coordSystem,mainAxis:(0,d.readMainAxis)(h.coordSystem)}))),l=e.id;return(0,b.useEffect)(()=>()=>{const h=r.getState();c.readStanding(h,"difference-arrow-endpoint-drag")?.annotationId===l&&h.releaseInteraction("difference-arrow-endpoint-drag")},[r,l]),(0,b.useCallback)(h=>({onKeyDown:u=>{if(u.altKey||u.ctrlKey||u.metaKey||u.shiftKey)return;const p=r.getState(),g=c.readDraggedDifferenceArrowEndpointFor(c.readStanding(p,"difference-arrow-endpoint-drag"),e.id,h);if(Lh.includes(u.key)){if(u.preventDefault(),u.repeat)return;if(g===null)return p.claimInteraction({kind:"difference-arrow-endpoint-drag",annotationId:e.id,endpoint:h,point:e[h]});p.releaseInteraction("difference-arrow-endpoint-drag"),Ia({dispatch:t.dispatch,arrow:e,endpoint:h,anchor:g.point.anchor});return}if(g===null)return;const m=Mh(u.key,s);if(m===null)return;u.preventDefault();const f=Oh({arrow:e,endpoint:h,from:g.point.anchor,move:m,layers:o,coordSystem:i,resolver:n});f!==null&&p.claimInteraction({kind:"difference-arrow-endpoint-drag",annotationId:e.id,endpoint:h,point:f})}}),[e,r,t,n,o,i,s])},Mh=(e,t)=>{const n=e==="ArrowUp"||e==="ArrowDown";return!n&&!(e==="ArrowLeft"||e==="ArrowRight")?null:{axis:t==="x"===n?"cross":"main",step:e==="ArrowDown"||e==="ArrowRight"?1:-1}},Oh=({arrow:e,endpoint:t,from:n,move:r,layers:o,coordSystem:i,resolver:s})=>{const l=o.find(p=>p.id===n.layerId);if(l===void 0)return null;const h=s.createLayerMeasurement(l);if(h===null)return null;const{align:u}=e[t].anchor;return(0,d.stepDifferenceArrowEndpoint)({layer:l,from:n,partner:e[Pa(t)].anchor,axis:r.axis,step:r.step,getObservationPoint:(p,g)=>(0,d.resolveObservationPoint)({resolver:s,layer:l,observation:p,observationIndex:g,coordSystem:i,align:u,measurement:h})})?.point??null},Rh=e=>{const t=be(),n=c.useDifferenceArrowGeometries(),r=(0,b.useCallback)(o=>{const i=e.frameElement.querySelector('[data-testid="pointer-capture-layer"]');i!==null&&i.dispatchEvent(new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,button:0,clientX:o.x,clientY:o.y,pointerId:1,pointerType:"mouse"}))},[e.frameElement]);return(0,a.jsxs)("div",{className:ih,children:[t!==null&&(0,a.jsx)(_h,{annotationId:t,...e}),n.map(o=>o.id!==t&&!o.dragging?null:(0,a.jsx)(Nh,{geometry:o,shown:o.id===t||o.dragging,keyboard:o.id===t,panelRect:e.panelRect,panelOrigin:e.panelOrigin,onClick:r},o.id))]})},_h=({annotationId:e,panelOrigin:t,...n})=>{const r=c.useDifferenceArrowGeometries(),o=(0,b.useMemo)(()=>r.find(i=>i.id===e),[r,e]);return o===void 0?null:(0,a.jsx)(Dh,{committedArrow:o.committedArrow,color:o.color,labelCornerRadius:o.style.label.cornerRadius,committedLabelBox:o.committedLabelBox,labelBox:o.labelBox,start:o.start,end:o.end,dragging:o.dragging,...n})},Dh=({committedArrow:e,color:t,labelCornerRadius:n,committedLabelBox:r,labelBox:o,start:i,end:s,panelRect:l,frameRect:h,frameElement:u,dragging:p})=>{const g=ut(c.useStyleReaderTree().editOutline.selected().resolve());return(0,a.jsxs)("div",{"data-testid":"difference-arrow-selection",style:(0,ce.assignInlineVars)({[Aa]:g}),children:[!p&&(0,a.jsx)(jh,{arrow:e,color:t,labelBox:r,start:i,end:s,panelRect:l,frameWidth:h.width,frameHeight:h.height,frameElement:u}),(0,a.jsx)("div",{"aria-hidden":"true",className:ch,"data-testid":"difference-arrow-selection-label",style:{left:l.x+o.x-2,top:l.y+o.y-2,width:o.width+4,height:o.height+4,borderRadius:c.toBorderRadiusCss(n,2)}})]})},Nh=({geometry:e,shown:t,keyboard:n,panelRect:r,panelOrigin:o,onClick:i})=>{const s=c.useEditorStore(),l=(0,b.useRef)(n),h=e.committedArrow.id;(0,b.useEffect)(()=>{if(l.current&&!n){const m=s.getState();c.readStanding(m,"difference-arrow-endpoint-drag")?.annotationId===h&&m.releaseInteraction("difference-arrow-endpoint-drag")}l.current=n},[n,s,h]);const u=kh({arrow:e.committedArrow,panelOrigin:o,panelRect:r,onClick:i}),p=Eh({arrow:e.committedArrow}),g=ut(c.useStyleReaderTree().editOutline.selected().resolve());return(0,a.jsxs)("div",{style:(0,ce.assignInlineVars)({[Aa]:g}),children:[(0,a.jsx)(Ir,{endpoint:"start",point:e.start,panelRect:r,shown:t,keyboard:n,dragHandlers:u("start"),keyboardHandlers:p("start")}),(0,a.jsx)(Ir,{endpoint:"end",point:e.end,panelRect:r,shown:t,keyboard:n,dragHandlers:u("end"),keyboardHandlers:p("end")})]})},Ir=({endpoint:e,point:t,panelRect:n,shown:r,keyboard:o,dragHandlers:i,keyboardHandlers:s})=>(0,a.jsx)("div",{className:sh,"data-testid":"difference-arrow-selection-handle","data-endpoint":e,"data-shown":r||void 0,role:"button",style:{left:n.x+t.x,top:n.y+t.y},tabIndex:o?0:-1,...i,...o?s:{},children:(0,a.jsx)("span",{"aria-hidden":"true",className:lh})}),ka=(e,t,n,{panelRect:r,frameElement:o,layers:i,readObservationBox:s})=>{const l=v.readContainerFractionBoundsFor(r,o),h=e.x*r.width,u=e.y*r.height,p=Math.max(l.minX*r.width,Math.min(l.maxX*r.width,t.x)),g=Math.max(l.minY*r.height,Math.min(l.maxY*r.height,t.y));return bn({rect:{x:Math.min(h,p),y:Math.min(u,g),width:Math.abs(p-h),height:Math.abs(g-u)},panelRect:r,bounds:l,layers:i,readObservationBox:s,mayEnclose:!n})},Gh="s8eewu0",kr="s8eewu1",wn=e=>({readTopCommandId:()=>e.stack.getSnapshot().undoStack.at(-1)?.id??null,undo:()=>e.undo()}),Tn=(e,t,n,r=null)=>{const o=e.getState().caret;if(o===null)return;const i=o.editor?.getText().trim();if(i!==void 0){if(i.length>0)return}else{const l=t.textAnnotations.find(h=>h.id===o.annotationId);if(l===void 0||v.hasStyleableText(l.content))return}const s=o.placementCommandId;s!==null&&r!==null&&r.readTopCommandId()===s&&r.undo()||n(o.annotationId)},Bh=(e,t,n)=>{const r=[];for(let o=e.layers.length-1;o>=0;o-=1){const i=e.layers[o];i===void 0||!i.interactive||i.attachment!==null||r.push(...Fh(i,e,t,n))}return r},Lr=(e,t)=>{if(t===null)return-1;const n=(0,d.readObservationIndex)(t);return e.findIndex(r=>r.target.layerId===t.layerId&&r.target.observationIndex===n)},Fh=(e,t,n,r)=>{const o=[];for(let i=0;i<e.data.size();i+=1){const s=e.data.getAt(i);if(s===null||Oe(e,s))continue;const l=(0,d.buildObservationsTarget)({layer:e,observationIndex:i,scope:"observation",parsingLocale:t.config.parsingLocale});if(l===null||!r(l))continue;const h=n.resolve(e.geom,s,{coordSystem:t.coordSystem,position:e.position,purpose:"pin"});if(h===null)continue;const u=Hh(s,t.coordSystem,h);o.push({x:h.x,target:l,primary:{anchored:!0,layerId:e.id,pointIndex:i,observation:s,x:u.x,y:u.y}})}return o.sort((i,s)=>i.x-s.x),o},Hh=(e,t,n)=>{if(t.type!=="polar")return n;const r=e[d.POSITION_VARIABLES.x],o=e[d.POSITION_VARIABLES.y];return typeof r!="number"||typeof o!="number"||!Number.isFinite(r)||!Number.isFinite(o)?n:{x:r,y:o}},zh=(e,t)=>{const{selectionStore:n,chartId:r,history:o,store:i,anchorResolver:s}=c.useGraphContext(),{store:l,engine:h,overlayRef:u}=c.useHoverContext(),p=Se(),g=c.useEditorStore(),m=c.useLatestRef(c.useSceneSelector(G=>G.spec.annotations.textAnnotations)),f=(0,b.useRef)(null),x=(0,b.useRef)(null),y=(0,b.useRef)(!0),w=(0,b.useRef)(new WeakSet),{showAnnotations:S,showMenuTriggerOnHover:I}=c.MODE_RULES[c.useGraphMode()],j=v.useRemoveAnnotation(t),A=(0,b.useCallback)(G=>{const{selection:L}=n.getState(),B=S?xe(L):null;B!==null&&(G.preventDefault(),j(B),e.focus({preventScroll:!0}))},[e,j,n,S]),T=(0,b.useCallback)(G=>{if(v.isWithinChartChrome(G.target,r))return;const L=S?xe(n.getState().selection):null;L!==null&&m.current.some(B=>B.id===L)&&(G.preventDefault(),g.getState().setCaret(L))},[g,n,m,r,S]),M=(0,b.useCallback)(G=>{const L=g.getState(),B=L.standingInteraction?.kind;if(B!==void 0){B!=="chrome-popup"&&B!=="arrow-draw"&&B!=="box-draw"&&L.releaseInteraction(B);return}if(L.caret!==null){Tn(g,i.getState().scene.annotations,j,wn(o)),L.setCaret(null),e.focus({preventScroll:!0});return}return v.isWithinChartChrome(G.target,r)?e.focus({preventScroll:!0}):n.getState().clearSelection()},[g,n,e,r,i,j,o]);(0,b.useEffect)(()=>{const G=O=>{if(!v.isWithinChart(O.target,e,r)||v.isWithinMenu(O.target))return;const C=le(O.target),D=g.getState(),z=D.caret!==null&&!v.isWithinChartChrome(O.target,r);if(C&&!z)return;const P=()=>I&&O.target===e&&!C&&!O.metaKey&&!O.ctrlKey&&!O.altKey&&!O.shiftKey&&D.standingInteraction===null&&n.getState().selection.length===0,F=()=>{if(!P())return;const W=Bh(i.getState().scene,s,p);if(W.length===0)return;const U=l.getState().hover.primary,$=O.key==="ArrowRight"||O.key==="ArrowDown"?1:-1,Y=f.current===null?Lr(W,U):Lr(W,f.current.primary),J=W[Y<0?$>0?0:W.length-1:Math.min(W.length-1,Math.max(0,Y+$))];if(J!==void 0){if(x.current===null){const V=ve(U);V!==null&&!et(V,ve(J.primary))&&(x.current=V)}f.current=J,O.preventDefault(),L(J)}},H=()=>{if(!P())return;const W=f.current;W!==null&&(f.current=null,x.current=null,O.preventDefault(),g.getState().setPlotMenu(null),g.getState().setAnnotatePress(null),n.getState().setSelection([W.target]))};switch(O.key){case"Escape":return M(O);case"Enter":return C||(T(O),g.getState().caret!==null)?void 0:H();case"Delete":case"Backspace":return C?void 0:A(O);case"n":case"N":if(O.metaKey||O.ctrlKey||O.altKey||C||!I||O.target!==e||D.standingInteraction!==null)return;O.preventDefault(),n.getState().clearSelection(),g.getState().setPlotMenu({x:.5,y:.5});return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":return F();default:return}},L=O=>{const C=Vh(h,O,i.getState().scene.coordSystem,Xh(h,u.current));w.current.add(C),l.getState().setHoverState(C)},B=l.subscribe(O=>{const C=f.current;if(C===null||w.current.has(O.hover))return;const D=O.hover.primary;if(D===null){if(y.current){L(C);return}f.current=null,x.current=null;return}const z=ve(D);if(et(z,ve(C.primary))){x.current=z;return}if(et(z,x.current)){L(C);return}f.current=null,x.current=null}),R=u.current,k=()=>{y.current=!0},_=O=>{y.current=!1,!(f.current===null||Wh(O,R,l))&&(f.current=null,x.current=null,l.getState().setHoverState(d.RESTING_HOVER_STATE))};return R?.addEventListener("pointerenter",k),R?.addEventListener("pointerleave",_),document.addEventListener("keydown",G),()=>{B(),R?.removeEventListener("pointerenter",k),R?.removeEventListener("pointerleave",_),document.removeEventListener("keydown",G)}},[e,A,T,M,r,g,I,n,i,s,p,l,h,u])},le=e=>e instanceof HTMLElement&&(e.isContentEditable||e.closest('[contenteditable="true"]')!==null||e.closest("[data-text-entry]")!==null||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement),Wh=(e,t,n)=>{if(t===null)return!1;const r=n.getState().pointerRegions;if(r.length===0)return!1;const o=t.getBoundingClientRect();return o.width<=0||o.height<=0?!1:(0,d.findPointerRegion)({x:e.clientX-o.left,y:e.clientY-o.top},r)!==null},ve=e=>e===null?null:{layerId:e.layerId,observationIndex:(0,d.readObservationIndex)(e)},Vh=(e,t,n,r)=>{const o=Kh(t.primary,n,r);if(o!==null){const i=e.query(o,{tolerance:c.ANNOTATE_ON_THE_MARK});if(et(ve(i.primary),ve(t.primary)))return{primary:i.primary,group:[...i.group],related:new Map(i.related),intersection:i.intersection}}return{primary:t.primary,group:[],related:new Map}},Kh=(e,t,n)=>{if(!e.anchored)return null;switch(t.type){case"polar":return Uh(e.x,e.y,n);case"cartesian":return $h(e);default:return t}},Uh=(e,t,n)=>{const r=(0,d.polarToUnit)(e,t);return n>=1?{x:.5+r.x/(2*n),y:.5-r.y/2}:{x:.5+r.x/2,y:.5-r.y*n/2}},$h=e=>{const{observation:t,x:n,y:r}=e,o=$e(t,d.POSITION_VARIABLES.xMin),i=$e(t,d.POSITION_VARIABLES.xMax),s=$e(t,d.POSITION_VARIABLES.yMin),l=$e(t,d.POSITION_VARIABLES.yMax);return o===null||i===null||s===null||l===null?{x:n,y:r}:[o,i,s,l].every(h=>h>=0&&h<=1)?{x:(o+i)/2,y:(s+l)/2}:null},Xh=(e,t)=>{const n=t?.getBoundingClientRect();return n===void 0||n.width<=0||n.height<=0?1:(e.setViewport({width:n.width,height:n.height}),n.width/n.height)},$e=(e,t)=>{const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:null},et=(e,t)=>e!==null&&t!==null&&e.layerId===t.layerId&&e.observationIndex===t.observationIndex,qh=e=>{const t=c.useEditorStore(),{chartId:n}=c.useGraphContext(),r=c.useEditorState(i=>i.standingInteraction?.kind==="arrow-draw"||i.standingInteraction?.kind==="box-draw"),o=c.useEditorState(i=>{const s=c.readStanding(i,"arrow-draw");return s!==null&&c.startsOnTarget(s)});(0,b.useEffect)(()=>()=>{const i=t.getState().standingInteraction?.kind;(i==="arrow-draw"||i==="box-draw")&&t.getState().releaseInteraction(i)},[t]),(0,b.useEffect)(()=>{o&&e.focus({preventScroll:!0})},[o,e]),(0,b.useEffect)(()=>{if(!r)return;const i=s=>{if(s.key!=="Escape"||!v.isWithinChart(s.target,e,n)||v.isWithinMenu(s.target))return;const l=le(s.target),h=t.getState().caret!==null&&!v.isWithinChartChrome(s.target,n);if(l&&!h)return;const u=t.getState().standingInteraction?.kind;u!=="arrow-draw"&&u!=="box-draw"||(s.preventDefault(),t.getState().releaseInteraction(u))};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[n,r,t,e])},Yh=({frameElement:e,panelRect:t})=>{const n=c.useEditorState(I=>c.readStanding(I,"arrow-draw")),r=c.useEditorState(I=>c.readStanding(I,"box-draw")),o=c.useEditorStore(),{engine:i}=c.useHoverContext(),{anchorResolver:s}=c.useGraphContext(),l=ye(t,e);qh(e);const[h,u]=(0,b.useState)(null),p=n!==null||r!==null,g=n?.pointer?.x??r?.pointer?.x,m=n?.pointer?.y??r?.pointer?.y;(0,b.useEffect)(()=>{if(!p)return;const I=(R,k)=>{const _=e.getBoundingClientRect(),O=v.readFrameScale(e,_.width);u({x:Er(R-_.left,0,_.width)/O,y:Er(k-_.top,0,_.height)/O})},j=(R,k)=>{I(R.x,R.y);const _=o.getState(),O=c.readStanding(_,"arrow-draw"),C=c.readStanding(_,"box-draw");if(C!==null){const P=l.current,F=ka(C.start,Le(R,e,P.panelRect),ie({altKey:k},_.snapping),P);_.claimInteraction({...C,placement:F});return}if(O===null)return;const D=l.current,z=wa({start:O.start,startObservationIndex:O.startObservationIndex,point:Le(R,e,D.panelRect),free:ie({altKey:k},_.snapping),previous:O.placement,inputs:D,engine:i,anchorResolver:s});if(z===null&&c.startsOnTarget(O)){_.releaseInteraction("arrow-draw");return}_.claimInteraction({...O,placement:z?.placement,startPoint:z?.startPoint})};if(g!==void 0&&m!==void 0){const R=c.readStanding(o.getState(),"arrow-draw");R!==null&&c.startsOnTarget(R)?j({x:g,y:m},!1):I(g,m)}let A=null,T=null;const M=()=>{A=null,T!==null&&cancelAnimationFrame(T),T=null},G=()=>{T=null;const R=A;A=null,R!==null&&j({x:R.clientX,y:R.clientY},R.altKey)},L=R=>{A=R,T??=requestAnimationFrame(G)},B=R=>{M(),j({x:R.clientX,y:R.clientY},R.altKey)};return document.addEventListener("pointermove",L,!0),document.addEventListener("pointerdown",B,!0),()=>{document.removeEventListener("pointermove",L,!0),document.removeEventListener("pointerdown",B,!0),M(),u(null)}},[p,g,m,e,o,l,i,s]);const f=Zh(n,r,t);if(f===null||h===null)return null;const x=t.x+f.x,y=t.y+f.y,w=n?.placement?.type==="snapped"?n.placement.point:null,S=w===null?h:{x:t.x+w.x,y:t.y+w.y};return(0,a.jsx)("svg",{className:Gh,children:r===null?(0,a.jsx)("line",{className:kr,x1:x,y1:y,x2:S.x,y2:S.y}):(0,a.jsx)("rect",{className:kr,fill:"none","data-testid":"box-draw-preview",x:r.placement===void 0?Math.min(x,h.x):t.x+r.placement.rect.x,y:r.placement===void 0?Math.min(y,h.y):t.y+r.placement.rect.y,width:r.placement?.rect.width??Math.abs(h.x-x),height:r.placement?.rect.height??Math.abs(h.y-y)})})},Zh=(e,t,n)=>t!==null?{x:t.start.x*n.width,y:t.start.y*n.height}:e===null?null:e.startPoint!==void 0?e.startPoint:e.start.anchorType!=="panel"?null:{x:e.start.x*n.width,y:e.start.y*n.height},Er=(e,t,n)=>Math.min(Math.max(e,t),n),Jh=({panelRect:e})=>{const t=c.useEditorState(l=>c.readStanding(l,"shape-resize-drag")),{shapes:n,images:r}=c.useResolvedAnnotations(e),o=c.useStyleReaderTree();if(t===null)return null;const i=t.annotationKind==="image"?r.find(l=>l.id===t.annotationId):void 0,s=t.annotationKind==="shape"?n.find(l=>l.id===t.annotationId):void 0;return s===void 0&&i===void 0?null:(0,a.jsxs)("svg",{"aria-hidden":"true",className:yn,width:e.width,height:e.height,style:{left:e.x,top:e.y},"data-testid":"shape-resize-preview","data-annotation-id":t.annotationId,children:[s!==void 0&&(0,a.jsx)(c.ShapeAnnotation,{shape:{...s,region:t.region},style:o.annotation.shape(s.id).resolve(),panel:e}),i!==void 0&&(0,a.jsx)(c.ImageAnnotation,{image:{...i,region:t.region},style:o.annotation.image(i.id).resolve(),panel:e})]})},Qh="var(--o49ib40)",e0={sm:"o49ib41",md:"o49ib42"},t0={horizontal:"o49ib43",diagonalDown:"o49ib44",diagonalUp:"o49ib45"},La=({point:e,label:t,pull:n,size:r,attributes:o,dragHandlers:i,keyboardHandlers:s})=>{const l=ut(c.useStyleReaderTree().editOutline.selected().resolve());return(0,a.jsx)("div",{"aria-label":t,className:t0[n],role:"button",style:{left:e.x,top:e.y,...(0,ce.assignInlineVars)({[Qh]:l})},tabIndex:0,...o,...i,...s,children:(0,a.jsx)("span",{"aria-hidden":"true",className:e0[r]})})},n0=({image:e,imageBox:t,panelRect:n,frameWidth:r,frameHeight:o,frameElement:i})=>{const s=c.useI18n(),l=v.useRemoveAnnotation(n),h=()=>{l(e.id),i.focus({preventScroll:!0})};return(0,a.jsxs)(v.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameWidth:r,frameHeight:o,label:s("graph.annotations.imageToolbar.label"),testId:"image-toolbar",children:[(0,a.jsx)(v.StartArrowButton,{annotationId:e.id}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:s("graph.annotations.imageToolbar.remove"),onClick:h,children:(0,a.jsx)(v.TrashIcon,{size:"sm",title:""})})]})},$t=[{width:0,key:"graph.annotations.shapeToolbar.border.none"},{width:2,key:"graph.annotations.shapeToolbar.border.thin"},{width:8,key:"graph.annotations.shapeToolbar.border.medium"},{width:16,key:"graph.annotations.shapeToolbar.border.thick"}],r0=e=>[...$t].reverse().find(t=>t.width<=e)??$t[0],o0=({shape:e,shapeBox:t,panelRect:n,frameWidth:r,frameHeight:o,frameElement:i})=>{const s=c.useI18n(),{commands:l}=c.useGraphContext(),h=v.useRemoveAnnotation(n),u=c.useSceneSelector(A=>A.spec.styles.overrides),p=c.useSceneSelector(A=>(0,d.readStyleCoord)(A.spec)),g=v.useToolbarPopups(),m=c.useStyleReaderTree().annotation.shape(e.id).resolve(),f=r0(m.strokeWidth),x=(0,b.useMemo)(()=>({target:"annotation",kind:"shape",annotation:e.id}),[e.id]),y=(A,T)=>{const M=(0,d.findStyleRule)(u,{select:x},p)?.declarations??{};l.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:x,declarations:{...M,...A}}}),T)},w=()=>{h(e.id),i.focus({preventScroll:!0})},S=A=>y({fill:A},{transient:!0}),I=A=>y({fillAlpha:A},{transient:!0}),j=A=>()=>{y({strokeWidth:A}),g.close()};return(0,a.jsxs)(v.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameWidth:r,frameHeight:o,label:s("graph.annotations.shapeToolbar.label"),testId:"shape-toolbar",children:[(0,a.jsx)(v.SelectionToolbar.ColorPicker,{color:(0,d.toPaintColor)(m.fill),label:s("graph.annotations.shapeToolbar.color"),onChange:S,opacity:m.fillAlpha,onOpacityChange:I,...g.bind("color"),children:(0,a.jsx)(v.SelectionToolbar.Swatch,{color:(0,d.toPaintColor)(m.fill),opacity:m.fillAlpha})}),(0,a.jsx)(v.SelectionToolbar.Dropdown,{label:s("graph.annotations.shapeToolbar.border.ariaLabel"),trigger:(0,a.jsx)(ma,{size:"sm",title:""}),...g.bind("border"),children:$t.map(A=>(0,a.jsx)(v.SelectionToolbar.MenuItem,{selected:A.width===f?.width,onClick:j(A.width),children:s(A.key)},A.width))}),(0,a.jsx)(v.SelectionToolbar.Separator,{}),(0,a.jsx)(v.StartArrowButton,{annotationId:e.id}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:s("graph.annotations.shapeToolbar.remove"),onClick:w,children:(0,a.jsx)(v.TrashIcon,{size:"sm",title:""})})]})},Xt=({start:e,extent:t,moveStartEdge:n,delta:r,minExtent:o,bounds:i})=>{if(!Number.isFinite(r))return{start:e,extent:t};const s=i?.min??0,l=i?.max??1,h=e+t,u=Math.min(o,t);if(n){const m=Math.min(s,e),f=Math.min(Math.max(l,e),h-u),x=(0,Q.clamp)(e+r,m,f);return{start:x,extent:h-x}}const p=Math.max(Math.min(s,h),e+u),g=Math.max(l,h);return{start:e,extent:(0,Q.clamp)(h+r,p,g)-e}},a0=["top-left","top-right","bottom-right","bottom-left"];var i0=({width:e,height:t})=>({x:v.normalizeToPanelExtent(16,e),y:v.normalizeToPanelExtent(16,t)}),s0=(e,t)=>({x:Ea(t)?e.x:e.x+e.width,y:Ma(t)?e.y:e.y+e.height}),l0=({region:e,corner:t,delta:n,minSize:r,bounds:o})=>{const i=Xt({start:e.x,extent:e.width,moveStartEdge:Ea(t),delta:n.x,minExtent:r.x,...o===void 0?{}:{bounds:{min:o.minX,max:o.maxX}}}),s=Xt({start:e.y,extent:e.height,moveStartEdge:Ma(t),delta:n.y,minExtent:r.y,...o===void 0?{}:{bounds:{min:o.minY,max:o.maxY}}});return{anchorType:"panel",x:i.start,y:s.start,width:i.extent,height:s.extent}},Ea=e=>e==="top-left"||e==="bottom-left",Ma=e=>e==="top-left"||e==="top-right",Oa=e=>{const t=c.useLatestRef(e),n=(0,b.useRef)(null);return(0,b.useEffect)(()=>()=>n.current?.finish(!1),[]),(0,b.useCallback)(r=>({onPointerDown:o=>{if(o.button!==0||n.current!==null)return;try{o.currentTarget.setPointerCapture(o.pointerId)}catch{return}o.currentTarget.focus({preventScroll:!0}),o.preventDefault();const i=t.current(r,{handle:o.currentTarget,pointerId:o.pointerId,press:{x:o.clientX,y:o.clientY},onSettled:()=>{n.current=null}});n.current=i,i.start()}}),[t])},Et=(e,t)=>{const n=e.shapes.find(o=>o.id===t);if(n!==void 0)return{kind:"shape",region:n.region};const r=e.images.find(o=>o.id===t);return r===void 0?null:{kind:"image",region:r.region}},Ra=class{constructor(e){this.params=e}readInitialPreview(){const{annotationId:e,readInputs:t}=this.params,{spec:n,scene:r,panelRect:o}=t(),i=Et(n,e);if(i===null)return null;const s=lt(r,i.kind,e,o);return s===null?null:{kind:"shape-resize-drag",annotationId:e,annotationKind:i.kind,region:de(s,o)}}resolve(e,t,n,r){const{annotationId:o,readInputs:i,editorStore:s}=this.params,{spec:l,scene:h,panelRect:u,frameElement:p,layers:g,readObservationBox:m}=i(),f=Et(l,o);if(f===null)return null;const x=lt(h,f.kind,o,u);if(x===null)return null;const y=de(x,u),w=i0(u),S=v.readContainerFractionBoundsFor(u,p),I=l0({region:r??y,corner:e,delta:t,minSize:{x:Math.min(w.x,y.width),y:Math.min(w.y,y.height)},bounds:S}),j=(0,d.projectRegionToPanel)(I,u),A=(0,d.isPlacedRegionAnchor)(f.region)?c0(f.region,x,j,u):bn({rect:j,panelRect:u,bounds:S,layers:g,readObservationBox:m,mayEnclose:f.kind==="shape"&&!ie(n,s.getState().snapping)});return{preview:{kind:"shape-resize-drag",annotationId:o,annotationKind:f.kind,region:de(A.rect,u),placement:A},unsnappedRegion:I}}commit({placement:e,annotationKind:t}){if(e===void 0)return;const{annotationId:n,dispatch:r,readInputs:o}=this.params,i=Et(o().spec,n);i===null||(0,Q.isEqual)(i.region,e.region)||r(new d.UpdateAnnotationCommand({kind:t,id:n,patch:{region:e.region}}))}},c0=(e,t,n,r)=>{const o=xa(e,t,r);if(o===null)return{type:"free",region:de(n,r),rect:n};const i=(0,d.readRectPoint)(n,e.regionAlign??"center"),s={x:i.x-o.targetPoint.x,y:i.y-o.targetPoint.y,unit:"px"};return{type:"attached",region:{...e,...va(n,r,e.unit),offset:s},rect:n}},d0=class extends Re{constructor(...e){super(...e),this.kind="shape-resize-drag",this.placement=new Ra(this.params)}readOwn(e){return c.readResizedShapeFor(c.readStanding(e,"shape-resize-drag"),this.params.annotationId)}resolvePreview(e,t){const{corner:n,press:r,readInputs:o}=this.params,i=fn(r,e,o().panelRect);return this.placement.resolve(n,i,t)?.preview??null}commit(e){this.placement.commit(e)}},_a=(e,t)=>{const n=c.useSceneSelector(o=>o.spec.annotations),r=c.useSceneSelector(o=>o.layers);return c.useLatestRef({spec:n,scene:c.useResolvedAnnotations(e),panelRect:e,frameElement:t,layers:r,readObservationBox:c.usePaintedObservationBoxes(e)})},u0=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=c.useGraphContext(),o=c.useEditorStore(),i=_a(t,n);return Oa((s,l)=>new d0({...l,annotationId:e,corner:s,readInputs:()=>i.current,editorStore:o,dispatch:r.dispatch}))},h0=[" ","Enter"],Da=e=>{const t=c.useEditorStore(),n=c.useLatestRef(e);return(0,b.useEffect)(()=>()=>Mr(t,n.current),[t,n]),(0,b.useCallback)(r=>({onKeyDown:o=>{if(o.altKey||o.ctrlKey||o.metaKey||o.shiftKey)return;const i=t.getState(),s=n.current.readHeld();if(h0.includes(o.key)){if(o.preventDefault(),o.repeat)return;if(s!==null){Mr(t,n.current);return}const h=n.current.claim(r);if(h===null)return;i.claimInteraction(h);return}if(s===null)return;const l=n.current.step(s,r,o.key);l!==null&&(o.preventDefault(),i.claimInteraction(l))}}),[t,n])},Mr=(e,t)=>{const n=t.readHeld();n!==null&&(e.getState().releaseInteraction(n.kind),t.commit(n))},Or=4,Xe=1e-7,p0=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=c.useGraphContext(),o=c.useEditorStore(),i=_a(t,n),s=(0,b.useRef)(null),l=new Ra({annotationId:e,readInputs:()=>i.current,editorStore:o,dispatch:r.dispatch}),h=u=>{const p=s.current;return p?.preview===u?p:null};return Da({readHeld:()=>c.readResizedShapeFor(c.readStanding(o.getState(),"shape-resize-drag"),e),claim:()=>{const u=l.readInitialPreview();return u===null?null:(s.current={preview:u,initialPreview:u,unsnappedRegion:u.region},u)},step:(u,p,g)=>{const m=i.current,f=m0(g,m.panelRect);if(f===null)return null;const x=h(u),y=l.resolve(p,f,{altKey:!1},x?.unsnappedRegion??u.region);if(y===null)return null;const w=x?.initialPreview??null,S=w!==null&&g0(w.region,y.unsnappedRegion,m.panelRect)?w:y.preview,I=c.areShapeResizesEqual(u,S)?u:S;return s.current={preview:I,initialPreview:w,unsnappedRegion:y.unsnappedRegion},I},commit:u=>{s.current=null,l.commit(u)}})},g0=(e,t,n)=>Math.abs(e.x-t.x)*n.width<=Xe&&Math.abs(e.y-t.y)*n.height<=Xe&&Math.abs(e.width-t.width)*n.width<=Xe&&Math.abs(e.height-t.height)*n.height<=Xe,m0=(e,t)=>{const n=v.normalizeToPanelExtent(Or,t.width),r=v.normalizeToPanelExtent(Or,t.height);switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-r};case"ArrowDown":return{x:0,y:r};default:return null}},v0={"top-left":"diagonalDown","bottom-right":"diagonalDown","top-right":"diagonalUp","bottom-left":"diagonalUp"},x0=e=>{const t=be(),n=y0(t),r=S0(e.panelRect,n),o=b0(t);if(n===null)return null;const i=o.resizedRegion??r;return i===null?null:(0,a.jsx)(f0,{selected:n,region:i,settled:o.resizedRegion===null&&!o.moving,moving:o.moving,...e})},f0=({selected:e,region:t,settled:n,moving:r,panelRect:o,frameRect:i,frameElement:s})=>{const l=c.useI18n(),{id:h}=e.annotation,u=u0({annotationId:h,panelRect:o,frameElement:s}),p=p0({annotationId:h,panelRect:o,frameElement:s}),g=c.useStyleReaderTree(),{rect:m}=c.measureShapeRegion(t,e.kind==="shape"?g.annotation.shape(h).resolve().strokeWidth:0,o);return(0,a.jsxs)("div",{"data-testid":"shape-selection","data-annotation-id":h,children:[n&&e.kind==="image"&&(0,a.jsx)(n0,{image:e.annotation,imageBox:m,panelRect:o,frameWidth:i.width,frameHeight:i.height,frameElement:s}),n&&e.kind==="shape"&&(0,a.jsx)(o0,{shape:e.annotation,shapeBox:m,panelRect:o,frameWidth:i.width,frameHeight:i.height,frameElement:s}),!r&&a0.map(f=>{const x=s0(m,f);return(0,a.jsx)(La,{point:{x:o.x+x.x,y:o.y+x.y},label:l(`graph.annotations.shapeToolbar.resize.${f}`),pull:v0[f],size:"md",attributes:{"data-testid":"shape-resize-handle","data-corner":f},dragHandlers:u(f),keyboardHandlers:p(f)},f)})]})},y0=e=>c.useSceneSelector((0,ee.useShallow)(t=>{const{shapes:n,images:r}=t.spec.annotations,o=n.find(s=>s.id===e);if(o!==void 0)return{kind:"shape",annotation:o};const i=r.find(s=>s.id===e);return i===void 0?null:{kind:"image",annotation:i}})),S0=(e,t)=>{const{shapes:n,images:r}=c.useResolvedAnnotations(e);if(t===null)return null;const o=(t.kind==="shape"?n:r).find(u=>u.id===t.annotation.id);if(o===void 0)return null;const{x:i,y:s,width:l,height:h}=o.region;return{anchorType:"panel",x:i,y:s,width:l,height:h}},b0=e=>c.useEditorState((0,ee.useShallow)(t=>e===null?{resizedRegion:null,moving:!1}:{resizedRegion:c.readResizedShapeFor(c.readStanding(t,"shape-resize-drag"),e)?.region??null,moving:c.readMovedAnnotationFor(c.readStanding(t,"move-drag"),e)!==null}));var C0=(e,t,n)=>{const{commands:r,anchorResolver:o}=c.useGraphContext(),{engine:i}=c.useHoverContext(),s=c.useEditorStore(),l=ye(t,n),h=(0,b.useRef)(null);return(0,b.useEffect)(()=>()=>h.current?.finish(!1),[]),{onPointerDown:(0,b.useCallback)(u=>{if(!(u.button!==0||h.current!==null)){try{u.currentTarget.setPointerCapture(u.pointerId)}catch{return}n.focus({preventScroll:!0}),u.preventDefault(),h.current=new ba({handle:u.currentTarget,pointerId:u.pointerId,annotationId:e,press:{x:u.clientX,y:u.clientY},readInputs:()=>l.current,editorStore:s,engine:i,anchorResolver:o,dispatch:r.dispatch,offsetOnly:!0,onSettled:()=>{h.current=null}}),h.current.start()}},[e,n,l,s,i,o,r])}},Na=({annotationId:e,anchor:t,sourceAlign:n,scenePoint:r,panelRect:o,frameElement:i,moving:s=!1,hideHandle:l=!1})=>{const h=c.useI18n(),u=c.useStyleReaderTree().snapTarget.tether().resolve(),p=C0(e,o,i),g=c.useSceneSelector(S=>S.coordSystem.type==="polar"),m=fe(t,n,r,o);if(m===null)return null;const f=m.targetPoint,x=(0,d.projectAnchorToPanel)(r,o),y=n===null||n==="center",w=!g||t.anchorType==="annotation";return(0,a.jsxs)(a.Fragment,{children:[!s&&(0,a.jsxs)("svg",{"aria-hidden":"true",className:"_1khwdhw0",width:o.width,height:o.height,style:{left:o.x,top:o.y},"data-testid":"attachment-tether",children:[(0,a.jsx)("line",{x1:f.x,y1:f.y,x2:x.x,y2:x.y,stroke:u.stroke,strokeOpacity:u.alpha,strokeWidth:u.strokeWidth,strokeDasharray:(0,d.toStrokeDasharray)(u.dashArray,u.strokeWidth)}),(0,a.jsx)("circle",{cx:f.x,cy:f.y,r:u.size/2,fill:(0,d.toPaintColor)(u.fill),fillOpacity:u.alpha})]}),!y&&w&&!l&&(0,a.jsx)("div",{"aria-label":h("graph.annotations.attachment.tether"),className:"_1khwdhw1","data-testid":"attachment-tether-handle",role:"button",style:{left:o.x+x.x,top:o.y+x.y,visibility:s?"hidden":void 0},tabIndex:0,...p})]})},w0=({sticker:e,stickerBox:t,panelRect:n,frameWidth:r,frameHeight:o,frameElement:i})=>{const s=c.useI18n(),{commands:l}=c.useGraphContext(),h=v.useRemoveAnnotation(n),u=v.useToolbarPopups(),p=m=>{l.dispatch(new d.UpdateAnnotationCommand({kind:"sticker",id:e.id,patch:{sticker:m}}))},g=()=>{h(e.id),i.focus({preventScroll:!0})};return(0,a.jsxs)(v.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameWidth:r,frameHeight:o,label:s("graph.annotations.stickerToolbar.label"),testId:"sticker-toolbar",children:[(0,a.jsx)(v.SelectionToolbar.StickerPicker,{value:e.sticker,label:s("graph.annotations.stickerToolbar.swap"),onChange:p,...u.bind("sticker")}),(0,a.jsx)(v.SelectionToolbar.Separator,{}),(0,a.jsx)(v.StartArrowButton,{annotationId:e.id}),(0,a.jsx)(v.SelectionToolbar.IconButton,{label:s("graph.annotations.stickerToolbar.remove"),onClick:g,children:(0,a.jsx)(v.TrashIcon,{size:"sm",title:""})})]})},T0=({panelRect:e,frameRect:t,frameElement:n})=>{const r=be(),o=c.useSceneSelector(u=>u.spec.annotations.stickers.find(p=>p.id===r)),i=c.useResolvedAnnotations(e).stickers.find(u=>u.id===r),s=c.useStyleReaderTree().graph().get("textScale"),l=c.useEditorState(u=>c.readStanding(u,"move-drag")?.annotationId===r);if(o===void 0||i===void 0)return null;const h=c.readStickerBox(i,e,s);return h===null?null:(0,a.jsxs)("div",{"data-testid":"sticker-selection","data-annotation-id":o.id,children:[v.hasAttachment(o.at)&&(0,a.jsx)(Na,{annotationId:o.id,anchor:o.at,sourceAlign:null,scenePoint:i.at,panelRect:e,frameElement:n,moving:l}),!l&&(0,a.jsx)(w0,{sticker:o,stickerBox:h,panelRect:e,frameWidth:t.width,frameHeight:t.height,frameElement:n})]})},Rr=["left","right"];var Ga=({width:e})=>v.normalizeToPanelExtent(60,e),_r=(e,t)=>({x:t==="left"?e.x:e.x+e.width,y:e.y+e.height/2}),Ba=({at:e,width:t,align:n,edge:r,delta:o,minWidth:i,panelWidth:s,panelHeight:l,paintedAt:h,bounds:u})=>{if(o===0||!Number.isFinite(o))return{at:e,width:t,shift:0};const p=(0,d.alignUnitFractions)(n).x,g=j0(e.offset,s),m=h?.x??(e.anchorType==="panel"?e.x+g:0),f=e.anchorType!=="panel"&&(n==="top"||n==="bottom");let x;if(f){const w=Math.max(0,Math.min(m-(u?.minX??0),(u?.maxX??1)-m)),S=(0,Q.clamp)(t+(r==="left"?-o:o)*2,Math.min(i,t),Math.max(t,w*2));x={start:m-S/2,extent:S}}else x=Xt({start:m-p*t,extent:t,moveStartEdge:r==="left",delta:o,minExtent:i,...u===void 0?{}:{bounds:{min:u.minX,max:u.maxX}}});const y=f?0:x.start+p*x.extent-m;return x.extent===t&&Math.abs(y)<1e-12?{at:e,width:t,shift:0}:{at:e.anchorType==="panel"?{...e,x:e.x+y}:{...e,offset:{x:(g+y)*s,y:(e.offset?.y??0)*(e.offset?.unit==="px"?1:l),unit:"px"}},width:x.extent,shift:y,...h===void 0?{}:{point:{x:m+y,y:h.y}}}},Fa=(e,t)=>(0,Q.isEqual)(e.at,t.at)&&e.width===t.width,j0=(e,t)=>e?.x===void 0?0:e.unit==="px"?v.normalizeToPanelExtent(e.x,t):e.x,ct=(e,t,n,r=!0)=>{const o=e.textAnnotations.find(s=>s.id===t);if(o===void 0)return null;const i=n?.textAnnotations.find(s=>s.id===t)?.at;return o.at.anchorType!=="panel"&&(!r||i===void 0||i.space==="disk")?null:{at:o.at,width:o.width,align:o.align,...i===void 0?{}:{paintedAt:i}}},A0=class extends Re{constructor(...e){super(...e),this.kind="text-resize-drag"}readOwn(e){return c.readResizedTextFor(c.readStanding(e,"text-resize-drag"),this.params.annotationId)}resolvePreview(e){const{annotationId:t,edge:n,press:r,readInputs:o}=this.params,{annotations:i,painted:s,cartesian:l,panelRect:h,frameElement:u}=o(),p=ct(i,t,s,l);if(p===null)return null;const g=fn(r,e,h).x;return{kind:"text-resize-drag",annotationId:t,delta:g,...Ba({...p,edge:n,delta:g,minWidth:Ga(h),panelWidth:h.width,panelHeight:h.height,bounds:v.readContainerFractionBoundsFor(h,u)})}}commit(e){const{annotationId:t,dispatch:n,readInputs:r}=this.params,{annotations:o,painted:i,cartesian:s}=r(),l=ct(o,t,i,s);l===null||Fa(l,e)||n(new d.UpdateAnnotationCommand({kind:"text",id:t,patch:{at:e.at,width:e.width}}))}},P0=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=c.useGraphContext(),o=c.useEditorStore(),i=c.useLatestRef({annotations:c.useSceneSelector(s=>s.spec.annotations),painted:c.useResolvedAnnotations(t),cartesian:c.useSceneSelector(s=>s.coordSystem.type==="cartesian"),panelRect:t,frameElement:n});return Oa((s,l)=>new A0({...l,annotationId:e,edge:s,readInputs:()=>i.current,editorStore:o,dispatch:r.dispatch}))},I0=4,k0=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=c.useGraphContext(),o=c.useEditorStore(),i=c.useSceneSelector(u=>u.spec.annotations),s=c.useResolvedAnnotations(t),l=c.useSceneSelector(u=>u.coordSystem.type==="cartesian"),h=(u,p)=>{const g=ct(i,e,s,l);return g===null?null:{kind:"text-resize-drag",annotationId:e,delta:p,...Ba({...g,edge:u,delta:p,minWidth:Ga(t),panelWidth:t.width,panelHeight:t.height,bounds:v.readContainerFractionBoundsFor(t,n)})}};return Da({readHeld:()=>c.readResizedTextFor(c.readStanding(o.getState(),"text-resize-drag"),e),claim:u=>h(u,0),step:(u,p,g)=>{const m=L0(g,t);return m===null?null:h(p,u.delta+m)},commit:u=>{const p=ct(i,e,s,l);p===null||Fa(p,u)||r.dispatch(new d.UpdateAnnotationCommand({kind:"text",id:e,patch:{at:u.at,width:u.width}}))}})},L0=(e,t)=>{const n=v.normalizeToPanelExtent(I0,t.width);switch(e){case"ArrowLeft":return-n;case"ArrowRight":return n;default:return null}},E0=e=>{const t=be(),n=c.useSceneSelector(l=>l.coordSystem.type==="cartesian"),r=O0(t),o=R0(t),i=c.useEditorState(l=>l.caret?.annotationId===t),s=_0(e.panelRect,t,o.resized);return r===null||s===null?null:(0,a.jsx)(M0,{annotation:r,textBox:s,settled:o.resized===null&&!o.moving,moving:o.moving,resizable:r.at.anchorType==="panel"||n,hasCaret:i,...e})},M0=({annotation:e,textBox:t,settled:n,moving:r,resizable:o,hasCaret:i,panelRect:s,frameRect:l,frameElement:h})=>{const u=c.useI18n(),p=Jo()?.TextToolbar,g=P0({annotationId:e.id,panelRect:s,frameElement:h}),m=k0({annotationId:e.id,panelRect:s,frameElement:h}),f=c.useResolvedAnnotations(s).textAnnotations.find(x=>x.id===e.id);return(0,a.jsxs)("div",{"data-testid":"text-selection","data-annotation-id":e.id,children:[(n||r)&&f!==void 0&&v.hasAttachment(e.at)&&(0,a.jsx)(Na,{annotationId:e.id,anchor:e.at,sourceAlign:e.align,scenePoint:f.at,panelRect:s,frameElement:h,moving:r,hideHandle:o&&!i&&Rr.some(x=>{const y=_r(t,x),w=(0,d.projectAnchorToPanel)(f.at,s);return Math.abs(y.x-w.x)<24&&Math.abs(y.y-w.y)<24})}),n&&p!==void 0&&(0,a.jsx)(p,{annotation:e,textBox:t,panelRect:s,frameWidth:l.width,frameHeight:l.height,frameElement:h}),o&&!r&&!i&&Rr.map(x=>{const y=_r(t,x);return(0,a.jsx)(La,{point:{x:s.x+y.x,y:s.y+y.y},label:u(`graph.annotations.textToolbar.resize.${x}`),pull:"horizontal",size:"sm",attributes:{"data-testid":"text-resize-handle","data-edge":x},dragHandlers:g(x),keyboardHandlers:m(x)},x)})]})},O0=e=>{const t=c.useSceneSelector(n=>n.spec.annotations.textAnnotations);return e===null?null:t.find(n=>n.id===e)??null},R0=e=>c.useEditorState((0,ee.useShallow)(t=>e===null?{resized:null,moving:!1}:{resized:c.readResizedTextFor(c.readStanding(t,"text-resize-drag"),e),moving:c.readMovedAnnotationFor(c.readStanding(t,"move-drag"),e)!==null})),_0=(e,t,n)=>{const r=c.useResolvedAnnotations(e),o=c.useMeasuredBoxes(),i=c.useStyleReaderTree(),s=(0,b.useMemo)(()=>({panel:{width:e.width,height:e.height},measuredBoxes:o,readers:i}),[e.width,e.height,o,i]);return t===null?null:da(r,t,n,s)?.rect??null},jn=(e,t)=>typeof document.elementsFromPoint=="function"?document.elementsFromPoint(e,t):[],D0=(e,t,n)=>c.readStampedEditTargetInStack(jn(e,t),n),N0="_1rpuha50";var Dr=["pointerdown","mousedown","pointerup","mouseup","click"],qt=e=>e instanceof Element&&e.closest("[data-menu-shield]")!==null,G0=()=>{const e=c.useEditorState(h=>h.plotMenu!==null),t=c.useEditorState(h=>H0(h.standingInteraction?.kind)),n=c.useGraphSelection()[0]?.kind==="observations",r=c.MODE_RULES[c.useGraphMode()].showMenuTriggerOnHover,{store:o}=c.useHoverContext(),i=c.useEditorStore(),s=r&&!t&&(e||n),l=(0,b.useRef)(null);return(0,b.useEffect)(()=>{if(!s)return;const h=o.getState();h.setHoverState(d.RESTING_HOVER_STATE),h.setTooltipAnchor(null)},[s,o]),(0,b.useEffect)(()=>{const h=l.current;if(h===null)return;const u=p=>{if(!(p instanceof MouseEvent)||p.button!==0||i.getState().plotMenu?.arrowId!==void 0)return;const g=B0(p.clientX,p.clientY);g!==null&&(p.stopPropagation(),g.dispatchEvent(F0(p)))};for(const p of Dr)h.addEventListener(p,u);return()=>{for(const p of Dr)h.removeEventListener(p,u)}},[s,i]),s?(0,a.jsx)("div",{ref:l,className:N0,"data-menu-shield":"","data-testid":"menu-shield"}):null},B0=(e,t)=>jn(e,t).find(n=>!qt(n))??null,F0=e=>new MouseEvent(e.type,{bubbles:!0,cancelable:!0,clientX:e.clientX,clientY:e.clientY,button:e.button,buttons:e.buttons}),H0=e=>e==="arrow-draw"||e==="box-draw",z0=1,W0=10,V0=1e-7,K0=(e,t)=>{const{selectionStore:n,commands:r,chartId:o,anchorResolver:i,store:s,history:l}=c.useGraphContext(),{engine:h}=c.useHoverContext(),u=c.useEditorStore(),p=ye(t,e),{showAnnotations:g}=c.MODE_RULES[c.useGraphMode()],m=c.useLatestRef(g);(0,b.useEffect)(()=>{let f=null,x={x:0,y:0},y={x:0,y:0},w,S=!1,I=!1,j=p.current;const A=new Set,T=P=>new Ut({annotationId:P,press:{x:0,y:0},readInputs:()=>p.current,engine:h,anchorResolver:i,editorStore:u,dispatch:r.dispatch,previous:()=>w}),M=()=>{y={x:0,y:0},w=void 0,A.clear()},G=P=>{const F=f;if(f=null,A.clear(),F===null||(c.readStanding(u.getState(),"move-drag")===F&&u.getState().releaseInteraction("move-drag"),!P))return;const H=p.current,W=F.placement!==void 0,U=W||F.ends!==void 0;y=W?{x:x.x-F.translation.x*H.panelRect.width,y:x.y-F.translation.y*H.panelRect.height}:{x:0,y:0},S=!0;try{U?Math.hypot(F.translation.x*H.panelRect.width,F.translation.y*H.panelRect.height)>V0&&T(F.annotationId).commit(F):ua(F.translation)&&r.dispatch(new d.MoveAnnotationCommand({id:F.annotationId,translation:F.translation,bounds:v.readContainerFractionBoundsFor(H.panelRect,e)}))}finally{S=!1}},L=()=>{G(!0),M()},B=()=>{G(!1),M()},R=n.subscribe((P,F)=>{xe(P.selection)!==xe(F.selection)&&L()}),k=u.subscribe((P,F)=>{I||S||((P.caret!==F.caret||P.snapping!==F.snapping)&&L(),P.standingInteraction!==F.standingInteraction&&(f!==null&&P.standingInteraction!==f?P.standingInteraction===null?B():L():P.standingInteraction!==null&&M()))}),_=s.subscribe((P,F)=>{!S&&P.scene!==F.scene&&B()}),O=l.stack.subscribe(()=>{S||B()}),C=P=>{if(!v.isWithinChart(P.target,e,o)||v.isWithinMenu(P.target)||v.isWithinChartChrome(P.target,o)||le(P.target)||u.getState().caret!==null||U0(P.target,e))return;if(c.resolveHistoryStep(P)!==null){L();return}if(P.defaultPrevented||P.altKey||P.ctrlKey||P.metaKey)return;const F=$0(P.key,P.shiftKey);if(F===null)return;const H=m.current?xe(n.getState().selection):null;if(H===null)return;const W=u.getState().standingInteraction;if(W!==null&&W!==f)return;const U=p.current;(!(0,Q.isEqual)(j.panelRect,U.panelRect)||!(0,Q.isEqual)(j.measuredBoxes,U.measuredBoxes))&&B(),j=U;const $=(0,d.findAnnotation)(U.spec,H);if($===null)return;f===null&&(x=y),x={x:x.x+F.x,y:x.y+F.y};let Y;const J=$.kind==="arrow"&&ya($.annotation);if($.kind==="text"||$.kind==="sticker"||J)Y=T(H).resolve(x,{altKey:!1});else{const V=(0,d.clampAnnotationTranslation)($,{x:v.normalizeToPanelExtent(x.x,U.panelRect.width),y:v.normalizeToPanelExtent(x.y,U.panelRect.height)},v.readContainerFractionBoundsFor(U.panelRect,e));Y=V===null?null:{kind:"move-drag",annotationId:H,translation:V}}Y!==null&&(P.preventDefault(),A.add(P.key),w=Y.placement,I=!0,u.getState().claimInteraction(Y),f=c.readStanding(u.getState(),"move-drag"),I=!1)},D=P=>{A.delete(P.key)&&A.size===0&&G(!0)},z=P=>{v.isWithinChart(P.target,e,o)&&P.target!==P.relatedTarget&&L()};return document.addEventListener("pointerdown",L,!0),document.addEventListener("keydown",C),document.addEventListener("keyup",D),document.addEventListener("focusout",z),window.addEventListener("blur",L),()=>{L(),R(),k(),_(),O(),document.removeEventListener("pointerdown",L,!0),document.removeEventListener("keydown",C),document.removeEventListener("keyup",D),document.removeEventListener("focusout",z),window.removeEventListener("blur",L)}},[e,o,u,n,r,s,l,p,h,i,m])},U0=(e,t)=>e instanceof Element&&e!==t&&e.closest('button, select, a[href], [role="button"], [role="slider"], [role="combobox"], [tabindex]')!==t,$0=(e,t)=>{const n=t?W0:z0;switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-n};case"ArrowDown":return{x:0,y:n};default:return null}},X0='button:not([disabled]):not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])',q0=(e,t)=>{const{chartId:n}=c.useGraphContext(),r=c.useEditorStore();(0,b.useEffect)(()=>{if(t===null)return;const o=i=>{if(i.key!=="Tab"||i.defaultPrevented||!v.isWithinChart(i.target,e,n)||v.isWithinMenu(i.target)||r.getState().standingInteraction?.kind==="chrome-popup")return;const s=[...t.querySelectorAll(X0)];if(s.length===0)return;i.preventDefault();const l=s.findIndex(h=>h===document.activeElement);s[l===-1?i.shiftKey?s.length-1:0:(l+(i.shiftKey?-1:1)+s.length)%s.length]?.focus()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[e,t,n,r])},Y0=e=>{const{selectionStore:t,chartId:n}=c.useGraphContext(),r=c.useEditorStore();(0,b.useEffect)(()=>{let o=null;const i=h=>{if(le(h.target))return;const{caret:u}=r.getState(),p=u===null?null:D0(h.clientX,h.clientY,e);p?.kind==="annotation"&&p.target.id===u?.annotationId||e.focus({preventScroll:!0})},s=h=>{const{selection:u,clearSelection:p}=t.getState();u.length!==0&&(v.isWithinChart(h.target,e,n)||p())},l=h=>{t.getState().selection.length!==0&&v.isWithinChart(h.target,e,n)&&h.relatedTarget===null&&(o!==null&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=null,document.hasFocus()&&(v.isWithinChart(document.activeElement,e,n)||t.getState().clearSelection())}))};return e.addEventListener("pointerdown",i),document.addEventListener("focusin",s),document.addEventListener("focusout",l),()=>{o!==null&&cancelAnimationFrame(o),e.removeEventListener("pointerdown",i),document.removeEventListener("focusin",s),document.removeEventListener("focusout",l)}},[r,t,e,n])},Z0=(e,t)=>{switch(e.kind){case"legend":{const n=t.legends[e.part.legendIndex],r=n?.items[e.part.itemIndex];if(n===void 0||r===void 0)return null;const o=J0(n,r.layerId,t.layers);return o===null?null:(0,d.buildObservationsTargetAtValue)({layer:o.layer,scope:"group",variable:o.variable,value:r.value,parsingLocale:t.parsingLocale})}case"axis":{const n=e.part;if(n===null||e.target.axis!=="x")return null;const r=t.formattedAxes.find(i=>i.scaledAesthetic==="x");if(r===void 0||r.bandwidth===void 0)return null;const o=r.ticks[n.tickIndex];return o===void 0?null:tp(t.layers,o.value,t.parsingLocale)}case"annotation":case"grid":return null}},J0=(e,t,n)=>{const r=t===void 0?n:n.filter(o=>o.id===t);for(const o of e.aesthetics){const i=Q0(r,o);if(i!==null)return i}return null},Q0=(e,t)=>{for(const n of e){const r=(0,d.readVariableName)(n.mapping[t]);if(r!==null&&ep(n,r))return{layer:n,variable:r}}return null},ep=(e,t)=>e.data.hasVariable(t)&&e.data.getType(t)==="categorical",tp=(e,t,n)=>{let r=null;for(const o of e){if(!o.interactive)continue;const i=(0,d.readScopeXVariable)(o.mapping);if(i===null)continue;const s=(0,d.buildObservationsTargetAtValue)({layer:o,scope:"xValue",variable:i,value:t,parsingLocale:n});if(s!==null){if(r!==null)return null;r=s}}return r},np=({hover:e,layers:t,scales:n,parsingLocale:r})=>{const{primary:o,intersection:i}=e;if(o===null)return null;const s=(0,d.findLayerById)(t,o.layerId);if(s===void 0)return null;const l=(0,d.readObservationIndex)(o),h=i?.intersects!==!1,u=(0,d.readBroadestObservationsScope)(s),p=h||!(0,d.hasMainAxisBand)(n)?[u]:["xValue",u];for(const g of p){const m=(0,d.buildObservationsTarget)({layer:s,observationIndex:l,scope:g,parsingLocale:r});if(m!==null)return{layerId:s.id,observationIndex:l,onObservation:h,target:m}}return null},rp=(e,t,n)=>{if(!e.onObservation||e.target.scope!=="group")return null;const r=(0,d.findLayerById)(t,e.layerId);return r===void 0?null:(0,d.buildObservationsTarget)({layer:r,observationIndex:e.observationIndex,scope:"observation",parsingLocale:n})},Yt=(e,t)=>{const{target:n}=e,{frameElement:r,captureRect:o,resolvesObservations:i,scene:s}=t;if(!(n instanceof Element&&r.contains(n))){const x=Nr(!1,!1,e,t);return{targetAtPoint:c.resolveEditTargetAtPoint({stamped:x.stamped,observations:null}),hover:null,elements:x.elements}}const l=o!==null&&n===o,h=l&&i?op(o):null,u=h===null?null:ap(e,h,t),p=u===null?null:np({hover:u,layers:s.layers,scales:s.scales,parsingLocale:s.config.parsingLocale}),g=p!==null&&t.hasOverlayMenu(p.target)?p:null,m=Nr(l,g!==null,e,t),f=c.resolveEditTargetAtPoint({stamped:m.stamped,observations:g});return{targetAtPoint:f,hover:f?.kind==="observations"?u:null,elements:m.elements}},op=e=>{const t=e.getBoundingClientRect();return t.width>0&&t.height>0?t:null},Nr=(e,t,n,{showAnnotations:r,selectGuidesOnPress:o,frameElement:i,scene:s,hasOverlayMenu:l})=>{if(!r&&s.coordSystem.type==="cartesian"&&e&&t)return{stamped:null,elements:[]};const h=e||r?jn(n.clientX,n.clientY):n.target instanceof Element?[n.target]:[],u=c.readStampedEditTargetInStack(h,i);return u===null?{stamped:null,elements:h}:{stamped:(u.kind==="annotation"?r:o&&l(u.target))?u:null,elements:h}},ap=(e,t,n)=>{const r=(0,d.toPanelCursor)({x:e.clientX-t.left,y:e.clientY-t.top},t);return n.engine.query(r,{tolerance:n.tolerance,viewport:t,includeAttached:!0})},ip=({client:e,capture:t,engine:n,layers:r,parsingLocale:o,hasMenu:i})=>{if(t===null||t.width===0||t.height===0||e.x<t.left||e.x>t.right||e.y<t.top||e.y>t.bottom)return null;const s={x:e.x-t.left,y:e.y-t.top},{primary:l,intersection:h}=n.query((0,d.toPanelCursor)(s,t),{tolerance:c.ANNOTATE_ON_THE_MARK,viewport:{width:t.width,height:t.height}});if(l===null||h?.intersects!==!0)return null;const u=r.find(m=>m.id===l.layerId);if(u===void 0||Oe(u,l.observation)||!sp(u.spatialKind))return null;const p=(0,d.readObservationIndex)(l),g=(0,d.buildObservationsTarget)({layer:u,observationIndex:p,scope:"observation",parsingLocale:o});return g===null||!i(g)?null:{target:g,observationIndex:p}},sp=e=>{switch(e){case"noop":return!1;case"points":return!0;case"buckets":case"filledBuckets":case"spannedBuckets":case"rects":case"cells":case"renderHitTest":return!0;default:return e}},Gr="data-annotation-id",lp='[data-testid="pinnedNumber"], [data-testid="comment"]',Br=(e,t,n)=>{if(e.target instanceof Element){const r=Fr(e.target,t);if(r!==null)return r}for(const r of n){if(r===e.target)continue;const o=Fr(r,t);if(o!==null)return o}return null},cp=(e,t)=>{const n=e.annotations.pinnedNumbers.find(r=>r.id===t)??e.annotations.comments.find(r=>r.id===t);return n===void 0?null:dp(e,n.at.anchor.layerId,n.at.observationIndex)},Fr=(e,t)=>{if(!t.contains(e))return null;const n=e.closest(lp);if(n===null||!t.contains(n))return null;const r=e.closest(`[${Gr}]`);if(r===null||!n.contains(r))return null;const o=r.getAttribute(Gr);return o===null||o.length===0?null:o},dp=(e,t,n)=>{const r=t===void 0?void 0:e.layers.find(o=>o.id===t);return r===void 0?null:(0,d.buildObservationsTarget)({layer:r,observationIndex:n,scope:"observation",parsingLocale:e.config.parsingLocale})},up={on:{edge:0,stroke:6,point:8},near:{main:0,cross:0}},hp=({client:e,capture:t,frame:n,engine:r,layers:o})=>{if(t===null||t.width===0||t.height===0||n===null||!zr(n,e))return null;const i={x:e.x-t.left,y:e.y-t.top};if(zr(t,e)){const{primary:l,intersection:h}=r.query((0,d.toPanelCursor)(i,t),{tolerance:up,viewport:{width:t.width,height:t.height}}),u=l===null?void 0:o.find(g=>g.id===l.layerId),p=l!==null&&u!==void 0&&Oe(u,l.observation);if(l!==null&&h?.intersects!==!1&&!p)return null}const s=v.readContainerFractionBounds({x:t.left-n.left,y:t.top-n.top,width:t.width,height:t.height},n);return{x:Hr(i.x/t.width,s.minX,s.maxX),y:Hr(i.y/t.height,s.minY,s.maxY)}},Hr=(e,t,n)=>Math.min(Math.max(e,t),n),zr=(e,t)=>t.x>=e.left&&t.x<=e.right&&t.y>=e.top&&t.y<=e.bottom,pp=(e,{canSelectGraph:t,withinFrame:n,caretAnnotationId:r})=>{switch(e?.kind){case"annotation":return e.target.id===r?{kind:"keep-caret"}:{kind:"select-annotation",target:e.target};case"axis":case"legend":case"grid":return{kind:"select-guide",target:e.target};case"observations":return gp(e.observations);case void 0:break}return t&&n?{kind:"select-graph",target:{kind:"graph"}}:{kind:"clear"}},gp=({target:e,observationIndex:t,onObservation:n})=>e.scope==="xValue"?{kind:"select-band",target:e}:{kind:"select-observations",target:e,observationIndex:n?t:null},mp=`[${c.CHART_LABEL_ATTRIBUTE}], [${c.EDIT_TARGET_KIND_ATTRIBUTE}="axis"], [${c.EDIT_TARGET_KIND_ATTRIBUTE}="legend"]`,vp=(e,t,n,r)=>{const{commands:o,history:i,selectionStore:s,store:l,anchorResolver:h,chartId:u}=c.useGraphContext(),{engine:p}=c.useHoverContext(),g=c.useEditorStore(),m=c.useGraphMode(),{selectGraphOnPress:f}=c.MODE_RULES[m],x=c.useLatestRef(f),y=c.useLatestRef(m===c.GRAPH_MODES.annotate),w=c.useLatestRef(m===c.GRAPH_MODES.annotate),S=ye(t,e),I=v.useRemoveAnnotation(t),j=c.useLatestRef(r),A=(0,b.useRef)(null);(0,b.useEffect)(()=>()=>A.current?.finish(!1),[]),(0,b.useEffect)(()=>s.subscribe(({selection:T})=>{const M=g.getState().pressedObservation,[G,...L]=T,B=G!==void 0&&L.length===0&&M!==null&&(0,d.areEditTargetsEqual)(G,M.selectedFor);M!==null&&!B&&g.getState().setPressedObservation(null)}),[g,s]),(0,b.useEffect)(()=>{const T=k=>Yt({target:k.target,clientX:k.clientX,clientY:k.clientY},n()).targetAtPoint,M=k=>{if(!(k.target instanceof Element))return!1;const _=k.target.closest(c.LEGEND_OVERFLOW_CONTROL_SELECTOR);return _!==null&&e.contains(_)&&c.readStampedEditTargetInStack([k.target],e)===null},G=(k,_)=>{if(A.current!==null||!c.canMoveAnnotationOnCanvas(S.current.spec,_.id))return;try{e.setPointerCapture(k.pointerId)}catch{return}k.preventDefault();const O=new ba({handle:e,pointerId:k.pointerId,annotationId:_.id,press:{x:k.clientX,y:k.clientY},readInputs:()=>S.current,editorStore:g,engine:p,anchorResolver:h,dispatch:o.dispatch,onSettled:()=>{A.current=null}});A.current=O,O.start()},L=(k,_)=>{const O=s.getState(),{layers:C,config:D,coordSystem:z}=l.getState().scene,P=_.kind==="select-observations"&&_.observationIndex!==null?c.readPressedObservation(_.observationIndex,C,_.target,D.parsingLocale):null;if(g.getState().setPressedObservation(P),y.current&&(_.kind==="select-observations"||_.kind==="select-band")){const F=(0,d.findLayerById)(C,_.target.layerId);if(F!==void 0&&Nd(F.geom,z.type)){const H=e.getBoundingClientRect(),W=v.readFrameScale(e,H.width);g.getState().setAnnotatePress({key:(0,d.readEditTargetKey)(_.target),x:(k.clientX-H.left)/W,y:(k.clientY-H.top)/W})}else g.getState().setAnnotatePress(null)}switch(_.kind){case"select-annotation":O.setSelection([_.target]),G(k,_.target);return;case"select-observations":case"select-band":case"select-guide":case"select-graph":O.setSelection([_.target]);return;case"clear":O.clearSelection();return;default:throw new d.InternalError({message:`No press outcome for: ${JSON.stringify(_)}`})}},B=k=>{if(le(k.target)||g.getState().setPendingTextCaret(null),k.button!==0)return;const _=g.getState().plotMenu?.arrowId;if(_!==void 0&&(qt(k.target)||!v.isWithinAnyChartChrome(k.target))&&(g.getState().setPlotMenu(null),v.isWithinChart(k.target,e,u))){s.getState().setSelection([{kind:"annotation",id:_}]);return}if(qt(k.target)){g.getState().setPlotMenu(null),s.getState().clearSelection();return}if(v.isWithinAnyChartChrome(k.target))return;const O=g.getState().caret?.annotationId??null,C=s.getState().selection.length>0||O!==null,D=k.target instanceof Element?k.target.closest("[data-edit-id]")?.getAttribute("data-edit-id")??null:null;!le(k.target)&&D!==O&&Tn(g,l.getState().scene.annotations,I,wn(i));const z=g.getState().standingInteraction,P=v.readContainerFractionBoundsFor(S.current.panelRect,S.current.frameElement),F=V=>{const X=e.getBoundingClientRect();return V.x<X.left||V.x>X.right||V.y<X.top||V.y>X.bottom};if(z?.kind==="arrow-draw"){const V=n().captureRect?.getBoundingClientRect()??null,X={x:k.clientX,y:k.clientY};if(!F(X)&&c.readDrawnPanelPoint(X,V,P)===null)return;Ta({client:X,altKey:k.altKey,frameElement:e,inputs:S.current,editorStore:g,selectionStore:s,engine:p,anchorResolver:h,dispatch:o.dispatch});return}if(z?.kind==="box-draw"){const V=n().captureRect?.getBoundingClientRect()??null,X={x:k.clientX,y:k.clientY};if(F(X)){g.getState().releaseInteraction("box-draw"),g.getState().setPlotMenu(null),s.getState().clearSelection();return}const ue=c.readDrawnPanelPoint(X,V,P);if(ue===null||V===null||c.isTinySpan(z.start,ue,V))return;const Ce=ka(z.start,Le(X,e,S.current.panelRect),ie({altKey:k.altKey},g.getState().snapping),S.current),oe=new d.AddAnnotationCommand({kind:"shape",annotation:{...d.SHAPE_DEFAULTS,region:Ce.region}});o.dispatch(oe),g.getState().releaseInteraction("box-draw"),g.getState().setPlotMenu(null),s.getState().setSelection([oe.target]);return}if(g.getState().setPlotMenu(null),M(k)||c.isOnLiveGeomMark(k.target,e))return;const H=n(),W=Yt({target:k.target,clientX:k.clientX,clientY:k.clientY},H);if(w.current){const V=Br(k,e,W.elements),X=V===null?null:cp(l.getState().scene,V);if(X?.observationIndex!==void 0){g.getState().setCaret(null),L(k,{kind:"select-observations",target:X,observationIndex:X.observationIndex});return}}const U=k.target instanceof Node&&e.contains(k.target),$=pp(W.targetAtPoint,{canSelectGraph:x.current&&!le(k.target)&&n().hasOverlayMenu({kind:"graph"}),withinFrame:U,caretAnnotationId:g.getState().caret?.annotationId??null});if($.kind==="keep-caret")return;const Y=$.kind==="select-annotation"&&l.getState().scene.spec.annotations.differenceArrows.some(V=>V.id===$.target.id);if(($.kind==="clear"||Y)&&y.current){const V=n();if(k.target===V.captureRect){const X=ip({client:{x:k.clientX,y:k.clientY},capture:V.captureRect?.getBoundingClientRect()??null,engine:V.engine,layers:V.scene.layers,parsingLocale:V.scene.config.parsingLocale,hasMenu:V.hasOverlayMenu});if(X!==null){g.getState().setCaret(null),L(k,{kind:"select-observations",target:X.target,observationIndex:X.observationIndex});return}}}const J=H.scene.coordSystem.type==="polar"&&$.kind==="select-observations";if(U&&($.kind==="clear"||J)&&w.current&&Br(k,e,W.elements)===null&&!xp(k.target,W.elements)){const V=hp({client:{x:k.clientX,y:k.clientY},capture:H.captureRect?.getBoundingClientRect()??null,frame:e.getBoundingClientRect(),engine:H.engine,layers:H.scene.layers});if(V!==null){g.getState().setCaret(null),L(k,{kind:"clear"}),C||g.getState().setPlotMenu(V);return}}g.getState().setCaret(null),L(k,$)},R=k=>{if(v.isWithinAnyChartChrome(k.target)||M(k)||c.isOnLiveGeomMark(k.target,e))return;const _=T(k),{layers:O,guides:C,config:D}=l.getState().scene,{hasOverlayMenu:z}=n(),P=s.getState(),F=g.getState();switch(_?.kind){case"observations":{const{observations:H}=_,W=rp(H,O,D.parsingLocale);if(W===null||!z(W))return;const{observationIndex:U}=H;F.setPressedObservation({observationIndex:U,predicate:W.predicate,selectedFor:W}),P.setSelection([W]);return}case"axis":case"legend":{const H=Z0(_,{layers:O,legends:C.legends.drawn,formattedAxes:j.current,parsingLocale:D.parsingLocale});if(H===null||!z(H))return;P.setSelection([H]);return}case"annotation":{const{target:H}=_;if(!S.current.spec.textAnnotations.some(W=>W.id===H.id))return;P.setSelection([H]),F.setCaret(H.id);return}case"grid":case void 0:return}};return document.addEventListener("pointerdown",B),document.addEventListener("dblclick",R),()=>{document.removeEventListener("pointerdown",B),document.removeEventListener("dblclick",R)}},[e,g,s,l,o,I,i,S,j,x,y,w,n,p,h,u])},xp=(e,t)=>le(e)||Wr(e)||t.some(Wr),Wr=e=>e instanceof Element&&e.closest(mp)!==null,fp=e=>{const{store:t}=c.useGraphContext(),{engine:n,overlayRef:r}=c.useHoverContext(),{showAnnotations:o,selectObservationsOnPress:i,selectGuidesOnPress:s,hoverTolerance:l}=c.MODE_RULES[c.useGraphMode()],{waitingForView:h}=c.useGraphAnimation(),u=Se(),p=i&&!h;return(0,b.useCallback)(()=>({frameElement:e,captureRect:r.current,selectGuidesOnPress:s,showAnnotations:o,resolvesObservations:p,engine:n,tolerance:l??void 0,scene:t.getState().scene,hasOverlayMenu:u}),[u,e,r,s,o,p,n,l,t])},yp={kind:"idle"},Sp=()=>{const e=c.useEditorState(n=>n.standingInteraction),t=Kc();return(0,b.useMemo)(()=>e!==null?e:t===null?yp:{kind:"trigger",anchor:t,isOpen:!0},[e,t])},bp=(e,t)=>e.x>=0&&e.x<=t.width&&e.y>=0&&e.y<=t.height,Cp=(e,t,n)=>{const{selectionStore:r}=c.useGraphContext(),{store:o,engine:i}=c.useHoverContext(),s=c.useLatestRef(e),l=c.useLatestRef(t),h=c.useLatestRef(n);(0,b.useEffect)(()=>{const u=f=>{if(r.getState().selection.length>0)return;const x=h.current,y=l.current,w={x:f.clientX-y.x,y:f.clientY-y.y},S=bp(w,x)?i.query((0,d.toPanelCursor)(w,x)):d.RESTING_HOVER_STATE;o.getState().setHoverState(S)};let p=!1;const g=()=>{const f=s.current;p=f.kind==="trigger"&&f.isOpen},m=f=>{v.isWithinAnyChartChrome(f.target)||p&&r.getState().selection.length===0&&u(f)};return document.addEventListener("pointerdown",g,!0),document.addEventListener("click",m),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("click",m)}},[r,s,o,i,l,h])},wp=(e,t)=>{const n=c.useEditorStore(),{store:r}=c.useGraphContext(),{store:o}=c.useHoverContext(),{selectObservationsOnPress:i}=c.MODE_RULES[c.useGraphMode()];(0,b.useEffect)(()=>(o.getState().setEditorOwnsQuery(i),()=>o.getState().setEditorOwnsQuery(!1)),[o,i]),(0,b.useEffect)(()=>{let s=null,l=null,h=!1;const u=I=>{if(!i)return;const j=o.getState();j.suspendsHover||I===null&&j.hover.primary===null||j.setHoverState(I??d.RESTING_HOVER_STATE)},p=()=>{if(s=null,l===null)return;const I=n.getState();if(qe(I.standingInteraction))return;if(h&&(h=!1,l={...l,target:Tp(l)}),c.isOnLiveGeomMark(l.target,e)){I.setEditTargetUnderPointer(null);return}const{targetAtPoint:j,hover:A}=Yt(l,t()),T=Mt(I.standingInteraction)&&j?.kind==="annotation";I.setEditTargetUnderPointer(T?null:j),u(A)},g=()=>{s===null&&(s=requestAnimationFrame(p))},m=()=>{l!==null&&(h=!0,g())},f=()=>{n.getState().setEditTargetUnderPointer(null),u(null)},x=I=>{l={target:I.target,clientX:I.clientX,clientY:I.clientY},h=!1,g()},y=()=>{l=null,s!==null&&(cancelAnimationFrame(s),s=null),f()},w=n.subscribe((I,j)=>{const A=qe(j.standingInteraction)&&!qe(I.standingInteraction),T=Mt(j.standingInteraction)!==Mt(I.standingInteraction);(A||T)&&m()}),S=r.subscribe((I,j)=>{I.scene!==j.scene&&(qe(n.getState().standingInteraction)||m())});return e.addEventListener("pointermove",x),e.addEventListener("pointerleave",y),()=>{s!==null&&cancelAnimationFrame(s),w(),S(),e.removeEventListener("pointermove",x),e.removeEventListener("pointerleave",y),f()}},[e,n,r,o,i,t])},Tp=e=>typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):e.target,Mt=e=>e?.kind==="arrow-draw",qe=e=>{if(e===null)return!1;switch(e.kind){case"move-drag":case"shape-resize-drag":case"difference-arrow-endpoint-drag":case"arrow-endpoint-drag":case"text-resize-drag":return!0;case"arrow-draw":case"box-draw":case"chrome-popup":return!1}},jp=(e,t,n,r,o)=>{const i=Sp(),{store:s}=c.useHoverContext(),l=c.useGraphSelection().length>0,{freezeHoverWhileSelected:h}=c.MODE_RULES[c.useGraphMode()],u=fp(e);wp(e,u),vp(e,n,u,o),Cp(i,t,n),Y0(e),zh(e,n),K0(e,n),q0(e,r);const p=l&&h;(0,b.useEffect)(()=>(s.getState().setSuspendsHover(p),()=>s.getState().setSuspendsHover(!1)),[s,p]),(0,b.useEffect)(()=>{if(!l||!h)return;const g=s.getState();g.setHoverState(d.RESTING_HOVER_STATE),g.setTooltipAnchor(null)},[s,l,h])},Ap=new Set(["Shift","Control","Alt","Meta"]),Pp=e=>{(0,b.useEffect)(()=>{if(e===null)return;const t=r=>{Ap.has(r.key)||e.setAttribute(v.KEYBOARD_INPUT_ATTRIBUTE,"")},n=()=>e.removeAttribute(v.KEYBOARD_INPUT_ATTRIBUTE);return document.addEventListener("keydown",t,!0),document.addEventListener("pointerdown",n,!0),()=>{document.removeEventListener("keydown",t,!0),document.removeEventListener("pointerdown",n,!0),e.removeAttribute(v.KEYBOARD_INPUT_ATTRIBUTE)}},[e])},Ip=({frameElement:e,panelRect:t,formattedAxes:n})=>{const{measureRef:r,screenRect:o}=c.useElementScreenRect(),{selectionStore:i,store:s,history:l}=c.useGraphContext(),h=c.useEditorStore(),u=v.useRemoveAnnotation(t),p=(0,b.useRef)(()=>{});(0,b.useEffect)(()=>{p.current=()=>{Tn(h,s.getState().scene.annotations,u,wn(l))}},[u,h,l,s]);const g=o?.width??0,m=o?.height??0,f=(0,b.useRef)({width:g,height:m});(0,b.useEffect)(()=>{const S=f.current;f.current={width:g,height:m},!(S.width===g&&S.height===m)&&h.getState().setAnnotatePress(null)},[g,m,h]);const x=c.useEditorState(S=>S.caret?.annotationId??null),y=c.useGraphMode(),w=(0,b.useRef)(y);return(0,b.useEffect)(()=>(r(e),()=>r(null)),[r,e]),(0,b.useEffect)(()=>()=>{p.current();const S=h.getState();S.setCaret(null),S.setPressedObservation(null),S.setPlotMenu(null),i.getState().clearSelection()},[h,i]),(0,b.useEffect)(()=>{if(w.current===y)return;w.current=y,p.current();const S=h.getState();S.setCaret(null),S.setEditTargetUnderPointer(null),S.setPlotMenu(null),i.getState().clearSelection()},[y,h,i]),o===null?null:(0,a.jsxs)(v.ChartChromeRoot,{children:[x!==null&&(0,a.jsx)(kp,{annotationId:x,panelRect:t}),(0,a.jsx)(Lp,{frameElement:e,frameRect:o,panelRect:t,formattedAxes:n})]})},kp=({annotationId:e,panelRect:t})=>{const n=c.useEditorStore(),{textAnnotations:r}=c.useResolvedAnnotations(t);return(0,b.useEffect)(()=>{r.some(({id:o})=>o===e)||n.getState().setCaret(null)},[e,r,n]),null},Lp=({frameElement:e,frameRect:t,panelRect:n,formattedAxes:r})=>{const o=(0,b.useMemo)(()=>({x:t.left+n.x,y:t.top+n.y}),[t.left,t.top,n.x,n.y]),[i,s]=(0,b.useState)(null);return jp(e,o,n,i,r),(0,a.jsx)(Ep,{frameElement:e,frameRect:t,panelOrigin:o,panelRect:n,boxRef:s})},Ep=({frameElement:e,frameRect:t,panelOrigin:n,panelRect:r,boxRef:o})=>{const i=v.useChartChromeContainer();Pp(i);const{showAnnotations:s}=c.MODE_RULES[c.useGraphMode()];return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(pd,{frameElement:e,frameSize:(0,b.useMemo)(()=>({width:t.width,height:t.height}),[t.width,t.height]),panelRect:r}),(0,a.jsx)(Zd,{frameRect:t}),(0,a.jsx)(tc,{rect:t,zIndex:c.Z_INDEX.editorOverlay,container:i,"data-testid":"editor-overlay",boxRef:o,children:(0,a.jsxs)(c.PortalThemeProvider,{children:[s&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Rh,{panelRect:r,panelOrigin:n,frameRect:t,frameElement:e}),(0,a.jsx)(x0,{panelRect:r,frameRect:t,frameElement:e}),(0,a.jsx)(Wu,{panelRect:r,frameRect:t,frameElement:e}),(0,a.jsx)(E0,{panelRect:r,frameRect:t,frameElement:e}),(0,a.jsx)(T0,{panelRect:r,frameRect:t,frameElement:e}),(0,a.jsx)(au,{panelRect:r}),(0,a.jsx)(Yh,{frameElement:e,panelRect:r}),(0,a.jsx)(Jh,{panelRect:r}),(0,a.jsx)(yu,{panelRect:r}),(0,a.jsx)(ou,{panelRect:r}),(0,a.jsx)(pu,{panelRect:r}),(0,a.jsx)(oh,{frameElement:e,panelRect:r})]}),(0,a.jsx)(qd,{frameElement:e,panelRect:r}),s&&(0,a.jsx)(bc,{frameElement:e,panelRect:r}),(0,a.jsx)(G0,{})]})})]})},Mp={},Op=({slots:e,palettePresets:t=Mp,editMenus:n,...r})=>{const o=c.useChartI18nProps(c.useFormattingLocale()),i=c.useGraphMode(),s=Jo(),l=(0,b.useMemo)(()=>({EditorSurface:Ip,...e}),[e]),h=(0,b.useMemo)(()=>Zl(i,s),[i,s]);return(0,a.jsx)(pn,{...o,children:(0,a.jsx)(Wl,{editMenus:n,children:(0,a.jsx)(c.EditorProvider,{children:(0,a.jsx)(Ql,{children:(0,a.jsx)(Cs,{value:t,children:(0,a.jsx)(c.InlineEditorsProvider,{editors:h,children:(0,a.jsx)(c.GraphRendererBody,{slots:l,...r})})})})})})})},Rp="_12lhx9e0",Ha=({children:e})=>(0,a.jsx)("div",{className:Rp,children:e}),_p="_139ohwv0",Z=({children:e})=>(0,a.jsx)("div",{className:_p,children:e}),za=(0,b.createContext)(null),Dp=za.Provider,Wa=()=>{const e=(0,b.useContext)(za);if(!e)throw new Error("A section must be rendered inside <EditorPanel.Root>.");return e},Np="_1jlczkt0",Va="data-graphy-editor-panel",Gp={List:Z,Grid:Ha};function Bp(e){if(e===void 0)return!1;const t=e.split(/\s+/);return t.includes("_1ii3bsb0")||t.includes("_1ii3bsb1")}var Fp=()=>()=>{},Hp=e=>{const t=(0,b.useSyncExternalStore)(e?.subscribe??Fp,()=>e?.getScene()?.config.parsingLocale);return e?.formattingLocale??t},zp=e=>{const t=(0,b.useContext)(c.GraphContext),n=c.useChartI18nProps(Hp(c.useGraphHandle(e.handle))),r=c.useHasThemeContext();let o=(0,a.jsx)(Wp,{...e});return!r&&t&&(o=(0,a.jsx)(c.ThemeProvider,{colorScheme:t.colorScheme,children:o})),(0,a.jsx)(pn,{...n,children:o})},An={Root:zp,Controls:Gp},Wp=({handle:e,children:t,controls:n,defaultExpandedSection:r=void 0,className:o})=>{const i=c.useGraphHandle(e),{themeClass:s,inlineVarsStyle:l}=c.useThemeContext(),[h,u]=(0,b.useState)(()=>r?[r]:[]),p=(0,b.useMemo)(()=>({expandSection:g=>u([g]),collapseAllSections:()=>u([])}),[]);return(0,a.jsx)(v.PanelGraphContext.Provider,{value:i,children:(0,a.jsx)(v.ControlRegistryProvider,{controls:n,children:(0,a.jsx)(Dp,{value:p,children:(0,a.jsx)(Ae.Accordion.Root,{[Va]:"",className:(0,_t.default)(Np,o,{[s]:!Bp(o)}),style:l,value:h,onValueChange:g=>u(g),children:t})})})})},Vp="_2m7wuq0",Kp=()=>(0,a.jsx)(si.Separator,{className:Vp}),Up=e=>(0,a.jsx)(c.Icon,{...e,children:(0,a.jsx)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"m9 6 6 6-6 6"})})}),Pn="_40zvwv0",In="_40zvwv1",$p="_40zvwv2",Ka="_40zvwv3",Xp="_40zvwv4 _40zvwv3";var qp="_40zvwv6";var Yp="_40zvwv8",q=({title:e,layout:t="fixed",preview:n,accessory:r,onOpenChange:o,children:i})=>t==="collapsible"?(0,a.jsx)(Jp,{title:e,preview:n,accessory:r,onOpenChange:o,children:i}):t==="inline"&&n===void 0?(0,a.jsx)(Zp,{title:e,accessory:r,children:i}):(0,a.jsxs)("div",{className:Pn,children:[(0,a.jsxs)("div",{className:In,children:[(0,a.jsx)("span",{className:Ka,children:e}),n!==void 0&&(0,a.jsx)("span",{className:"_40zvwv5",children:n}),r!==void 0&&(0,a.jsx)("span",{className:"_40zvwv7",children:r})]}),(0,a.jsx)("div",{children:i})]}),Zp=({title:e,accessory:t,children:n})=>{const r=(0,b.useId)(),o=(0,b.useId)();return(0,a.jsx)("div",{className:Pn,children:(0,a.jsxs)("div",{className:In,children:[(0,a.jsx)("label",{id:r,htmlFor:o,className:Xp,children:e}),(0,a.jsx)("span",{className:qp,children:(0,a.jsx)(v.RowLabelingProvider,{labelId:r,controlId:o,children:n})}),t!==void 0&&(0,a.jsx)("span",{className:"_40zvwv7",children:t})]})})},Jp=({title:e,preview:t,accessory:n,onOpenChange:r,children:o})=>{const i=c.useI18n();return(0,a.jsxs)(Ae.Accordion.Item,{value:e,className:Pn,onOpenChange:r,children:[(0,a.jsxs)(Ae.Accordion.Header,{className:In,render:(0,a.jsx)("div",{}),children:[(0,a.jsx)(Ae.Accordion.Trigger,{className:$p,"aria-label":i("editor.accessibility.toggleSection",{title:e})}),(0,a.jsx)("span",{className:Ka,children:e}),t!==void 0&&(0,a.jsx)("span",{className:"_40zvwv5",children:t}),n!==void 0&&(0,a.jsx)("span",{className:"_40zvwv7",children:n}),(0,a.jsx)("span",{className:Yp,children:(0,a.jsx)(Up,{size:"sm"})})]}),(0,a.jsx)(Ae.Accordion.Panel,{children:(0,a.jsx)("div",{children:o})})]})},Ua=({title:e,checked:t,onToggle:n,disabled:r,preview:o,children:i})=>{const{expandSection:s,collapseAllSections:l}=Wa(),{Switch:h}=v.useControls(),u=g=>{n(g),g?s(e):l()},p=g=>{g&&!t&&r!==!0&&n(!0)};return(0,a.jsx)(q,{title:e,layout:"collapsible",preview:o,onOpenChange:p,accessory:(0,a.jsx)(h,{checked:t,onChange:u,disabled:r,ariaLabel:e}),children:i})},Qp={horizontal:["bottom","top"],vertical:["left","right"]},eg={left:"editor.axesPanel.position.left",right:"editor.axesPanel.position.right",top:"editor.axesPanel.position.top",bottom:"editor.axesPanel.position.bottom"},tg={x:"editor.axesPanel.mainAxisSection.xAxis",y:"editor.axesPanel.mainAxisSection.yAxis",ySecondary:"editor.axesPanel.mainAxisSection.ySecondaryAxis"},tt=({axis:e,title:t,layout:n="collapsible",preview:r})=>{const o=v.usePanelGraph(),i=c.useHandleScene(o),s=c.useI18n(),{DateField:l,NumberField:h,Switch:u,TextField:p,ToggleGroup:g}=v.useControls();if(!i||e==="ySecondary"&&(i.coordSystem.type!=="cartesian"||i.scales.ySecondary===void 0))return null;const m=e==="ySecondary"||i.coordSystem.type!=="polar"?"linear":i.coordSystem.axisMapping[e].geometry,f=i.scales[e],x=f?.spec,y=x?.scaleType==="continuous"?x:void 0,w=x?.scaleType==="datetime",S=x?.scaleType==="continuous"||w?x:void 0;if(m==="circular"||m==="radial"&&y===void 0)return null;const I=x?.scaleType==="continuous"||x?.scaleType==="datetime",j=y!==void 0&&(0,d.isZeroAnchoredAxis)(i,e),A=y?.transform==="log",T=S?.domainMax??null,M=ng(S),G=(E,K)=>E.map(te=>({value:te,label:K(te)})),L=i.guides.axes.find(E=>E.scaledAesthetic===e);if(L===void 0)return null;const B=L.position,R=i.guides.axes.filter(E=>E.scaledAesthetic===e),k=R.some(E=>E.visible),_=R.some(E=>E.visible||E.showGrid),O=e==="ySecondary"?i.config.axes.ySecondary?.label??L.label??"":i.config.axes[e].label??L.label??"",C=Qp[B==="bottom"||B==="top"?"horizontal":"vertical"],D=e==="y"?(0,d.readComboLineLayerId)(i.spec):null,z=D===null?void 0:(0,d.findLayerById)(i.spec.layers,D),P=i.guides.legends.drawn.some(E=>!E.inHeadlineRow&&C.some(K=>K===E.position)),F=C.map(E=>({value:E,label:s(eg[E])})),H=G(["auto","edges"],E=>s(E==="edges"?"editor.axesPanel.labelMode.edges":"editor.axesPanel.labelMode.auto")),W=G(["linear","log"],E=>s(E==="log"?"editor.axesPanel.scale.log":"editor.axesPanel.scale.auto")),U=G(w?["auto","custom"]:["auto","zero","custom"],E=>s(E==="zero"?"editor.axesPanel.startFrom.zero":E==="custom"?"editor.axesPanel.startFrom.custom":"editor.axesPanel.startFrom.auto")),$=G(["auto","custom"],E=>s(E==="custom"?"editor.axesPanel.endAt.custom":"editor.axesPanel.endAt.auto")),Y=G(["single","double"],E=>s(E==="double"?"editor.axesPanel.axisCount.double":"editor.axesPanel.axisCount.single")),J=E=>{if(e==="ySecondary"){o.commands.dispatch(new d.SetAxisVisibilityCommand({axis:e,visible:Ot(E,i.config.axes.y.visible)}));return}o.commands.dispatch(new d.SetAxisVisibilityCommand({axis:e,visible:E,keepSecondaryAxis:!0}))},V=E=>{o.commands.dispatch(new d.SetAxisLabelCommand({axis:e,label:E}),{transient:!0})},X=E=>{if(e==="ySecondary"){o.commands.dispatch(new d.SetAxisTicksVisibilityCommand({axis:e,visible:Ot(E,i.config.axes.y.ticks.visible)}));return}o.commands.dispatch(new d.SetAxisTicksVisibilityCommand({axis:e,visible:E,keepSecondaryAxis:!0}))},ue=E=>{const K=E==="edges"?"edges":"auto";if(e==="ySecondary"){o.commands.dispatch(new d.SetAxisTickModeCommand({axis:e,tickMode:Ot(K,i.config.axes.y.ticks.mode)}));return}o.commands.dispatch(new d.SetAxisTickModeCommand({axis:e,tickMode:K,keepSecondaryAxis:!0}))},Ce=E=>{o.commands.dispatch(new d.SetScaleTransformCommand({scaledAesthetic:e,transform:E==="log"?"log":"linear"}))},oe=E=>{o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,...E}),{transient:!0})},ne=E=>{E!==null&&oe({domainMin:E})},De=E=>{E!==null&&oe({domainMax:E})},se=E=>{const K=$a(E);K!==null&&oe({domainMax:K})},Ne=E=>{if(E==="auto"){o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,domainMin:null}));return}if(E==="zero"){o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,domainMin:0}));return}const K=Vr(f?.domain,"start");K!==null&&o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,domainMin:K}))},xt=E=>{if(E!=="custom"){o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,domainMax:null}));return}const K=Vr(f?.domain,"end");K!==null&&o.commands.dispatch(new d.SetScaleDomainCommand({scaledAesthetic:e,domainMax:K}))},he=E=>{z!==void 0&&o.commands.dispatch(new d.SetLayerYScaleTypeCommand({layerId:z.id,yScaleType:E==="double"?"secondary":"primary"}))},Ge=E=>{if(e==="ySecondary")return;const K=C.find(te=>te===E);K&&o.commands.dispatch(new d.SetAxisPositionCommand({axis:e,position:K}))};return(0,a.jsx)(q,{title:t??s(tg[e]),layout:n,preview:r,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:s("editor.axesPanel.controls.visible"),children:(0,a.jsx)(u,{checked:L.visible,onChange:J})}),z!==void 0&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.numberOfAxes"),children:(0,a.jsx)(g,{value:z.yScaleType==="secondary"?"double":"single",options:Y,onChange:he})}),m==="linear"&&(0,a.jsxs)(a.Fragment,{children:[L.visible&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.title"),children:(0,a.jsx)(p,{value:O,placeholder:s("editor.axesPanel.controls.titlePlaceholder"),onChange:V,onCommit:o.commands.commit})}),k&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.ticks"),children:(0,a.jsx)(u,{checked:L.showTicks,onChange:X})})]}),I&&_&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.labels"),children:(0,a.jsx)(g,{value:L.tickMode,options:H,onChange:ue})}),e!=="ySecondary"&&y&&m==="linear"&&L.visible&&!P&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.position"),children:(0,a.jsx)(g,{value:L.position,options:F,onChange:Ge})}),y&&!j&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.scale"),children:(0,a.jsx)(g,{value:A?"log":"linear",options:W,onChange:Ce})}),S&&!A&&(0,a.jsxs)(a.Fragment,{children:[!j&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:s("editor.axesPanel.controls.startFrom"),children:(0,a.jsx)(g,{value:M,options:U,onChange:Ne})}),M!=="auto"&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.value"),children:w?(0,a.jsx)(l,{value:pt(S.domainMin??null),onChange:ne,onCommit:o.commands.commit}):(0,a.jsx)(h,{value:S.domainMin??null,onChange:ne,onCommit:o.commands.commit})})]}),(0,a.jsx)(N,{label:s("editor.axesPanel.controls.endAt"),children:(0,a.jsx)(g,{value:T===null?"auto":"custom",options:$,onChange:xt})}),T!==null&&(0,a.jsx)(N,{label:s("editor.axesPanel.controls.value"),children:w?(0,a.jsx)(l,{value:rg(T),onChange:se,onCommit:o.commands.commit}):(0,a.jsx)(h,{value:T,onChange:De,onCommit:o.commands.commit})})]})]})})},Ot=(e,t)=>e===t?void 0:e,ng=e=>{const t=e?.domainMin??null;return t===null?"auto":e?.scaleType==="datetime"?"custom":t===0?"zero":"custom"},Vr=(e,t)=>{const n=t==="start"?e?.[0]:e?.[e.length-1];return n instanceof Date?t==="start"?pt(n.getTime()):$a(n.getTime()):typeof n=="number"?n:null},pt=e=>{if(e===null||!Number.isFinite(e))return null;const t=new Date(e).toISOString().slice(0,10),n=Date.parse(`${t}T00:00:00.000Z`);return Number.isNaN(n)?null:n},$a=e=>{const t=pt(e);return t===null?null:t+864e5},rg=e=>e===null||!Number.isFinite(e)?null:pt(e-1),kn=({value:e,onChange:t})=>{const n=v.usePanelGraph(),r=c.useI18n(),{TextField:o}=v.useControls(),i=e!==null&&typeof e!="string"?Xa(e):null,s=e!==null&&typeof e!="string"&&i===null,l=typeof e=="string"?e:i?.words??"",h=u=>{if(u==="")return t(null);t(i?i.write(u):u)};return(0,a.jsx)(N,{label:r("editor.elementsPanel.contentValue"),children:(0,a.jsx)(o,{value:l,onChange:h,onCommit:n.commands.commit,disabled:s})})},Xa=e=>{if(e.type==="doc"){const[r,...o]=e.content??[],i=r!==void 0&&o.length===0?Xa(r):null;return i===null?null:{words:i.words,write:s=>({...e,content:[i.write(s)]})}}if(e.type!=="paragraph"&&e.type!=="heading")return null;const[t,...n]=e.content??[];return t?.type==="text"&&n.length===0&&(t.marks??[]).length===0?{words:t.text??"",write:r=>({...e,content:[{...t,text:r}]})}:null},qa=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Switch:s}=v.useControls();if(!o)return null;const l=o.config.content,h=p=>{r.commands.dispatch(new d.ToggleContentVisibilityCommand({part:"caption",visible:p}))},u=p=>{r.commands.dispatch(new d.SetContentCaptionCommand({caption:p}),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.elementsPanel.footerSection.caption"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.elementsPanel.contentVisible"),children:(0,a.jsx)(s,{checked:l.showCaption,onChange:h})}),(0,a.jsx)(kn,{value:l.caption,onChange:u})]})})},Kr=/^[a-z][a-z\d+.-]*:/i,og={},Ya=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Switch:s}=v.useControls();if(!o)return null;const l=o.config.content,h=u=>{r.commands.dispatch(new d.ToggleContentVisibilityCommand({part:"source",visible:u}))};return(0,a.jsx)(q,{title:e??i("editor.elementsPanel.sourceSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.elementsPanel.contentVisible"),children:(0,a.jsx)(s,{checked:l.showSource,onChange:h})}),(0,a.jsx)(ag,{source:l.source??og})]})})},ag=({source:e})=>{const t=v.usePanelGraph(),n=c.useI18n(),{TextField:r}=v.useControls(),o=h=>{const u=(h.label??"")!==""||(h.url??"")!=="";t.commands.dispatch(new d.SetContentSourceCommand({source:u?h:null}),{transient:!0})},i=()=>{const h=e.url??"";h!==""&&!Kr.test(h)&&o({...e,url:`https://${h}`}),t.commands.commit()},s=h=>o({...e,url:h}),l=h=>o({...e,label:h});return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:n("editor.elementsPanel.sourceSection.url"),children:(0,a.jsx)(r,{value:e.url??"",onChange:s,onCommit:i,hasError:Kr.test(e.url??"")&&!(0,d.isSafeUrl)(e.url)})}),(0,a.jsx)(N,{label:n("editor.elementsPanel.sourceSection.name"),children:(0,a.jsx)(r,{value:e.label??"",onChange:l,onCommit:t.commands.commit})})]})},Za=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Switch:s}=v.useControls();if(!o)return null;const l=o.config.content,h=p=>{r.commands.dispatch(new d.ToggleContentVisibilityCommand({part:"subtitle",visible:p}))},u=p=>{r.commands.dispatch(new d.SetContentSubtitleCommand({subtitle:p}),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.elementsPanel.headerSection.subtitle"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.elementsPanel.contentVisible"),children:(0,a.jsx)(s,{checked:l.showSubtitle,onChange:h})}),(0,a.jsx)(kn,{value:l.subtitle,onChange:u})]})})},_e=e=>{const{colorScheme:t}=c.useThemeContext(),n=(0,b.useMemo)(()=>(0,d.createStyleResolver)({colorScheme:t}),[t]);return(0,b.useMemo)(()=>e===null?null:n.readers(e),[e,n])},Ln=(e,t,n)=>{const r=_e(e);return(0,b.useMemo)(()=>{if(r===null||e===null||t===null)return null;const o=(0,d.findLayerById)(e.layers,t);return o===void 0?null:r.geom[n](o)},[r,e,t,n])},Zt=[.8,1,1.2,1.4,1.6,1.8,2,2.5,3,4],ig=Zt.length/2,sg={select:{target:"graph"}},Ja=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{RadioGrid:s}=v.useControls(),l=_e(o);if(!o||!l)return null;const h=l.graph().get("textScale"),u=m=>i("editor.elementsPanel.textSizeSection.scaleFormat",{value:`${m}`}),p=Zt.map(m=>({value:`${m}`,label:u(m)})),g=m=>{const f=Zt.find(y=>`${y}`===m);if(f===void 0)return;const x=(0,d.findStyleRule)(o.spec.styles.overrides,sg,(0,d.readStyleCoord)(o.spec))?.declarations??{};r.commands.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"graph"},declarations:{...x,textScale:f}}}))};return(0,a.jsx)(q,{title:e??i("editor.elementsPanel.textSizeSection.title"),layout:t,preview:n??u(h),children:(0,a.jsx)(s,{value:`${h}`,options:p,columns:ig,onChange:g,ariaLabel:i("editor.elementsPanel.textSizeSection.title")})})},Qa=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Switch:s}=v.useControls();if(!o)return null;const l=o.config.content,h=p=>{r.commands.dispatch(new d.ToggleContentVisibilityCommand({part:"title",visible:p}))},u=p=>{r.commands.dispatch(new d.SetContentTitleCommand({title:p}),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.elementsPanel.headerSection.toggleTitle"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.elementsPanel.contentVisible"),children:(0,a.jsx)(s,{checked:l.showTitle,onChange:h})}),(0,a.jsx)(kn,{value:l.title,onChange:u})]})})},lg=({children:e,...t})=>(0,a.jsx)(An.Root,{...t,children:e??(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Qa,{}),(0,a.jsx)(Za,{}),(0,a.jsx)(qa,{}),(0,a.jsx)(Ya,{}),(0,a.jsx)(Ja,{})]})}),cg=({children:e,...t})=>(0,a.jsx)(An.Root,{...t,children:e??(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tt,{axis:"x"}),(0,a.jsx)(tt,{axis:"y"}),(0,a.jsx)(tt,{axis:"ySecondary"})]})}),gt=e=>`${e}px`,ei=e=>`${Math.round(e*100)}%`,dg=e=>`${e}°`,ug=24,hg={select:{target:"graph"}},Ur=["dim","desaturate"],pg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Slider:s,ToggleGroup:l}=v.useControls(),h=_e(o);if(!o||!h)return null;const u=h.graph().get("cornerRadius"),p=(0,d.readHighlightDimStyle)(o.spec),g=Ur.map(x=>({value:x,label:i(x==="dim"?"editor.highlighting.highlightStyle.tint":"editor.highlighting.highlightStyle.gray")})),m=x=>{const y=(0,d.findStyleRule)(o.spec.styles.overrides,hg,(0,d.readStyleCoord)(o.spec))?.declarations??{};r.commands.dispatch(new d.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"graph"},declarations:{...y,cornerRadius:x}}}),{transient:!0})},f=x=>{const y=Ur.find(w=>w===x);y&&r.commands.dispatch(new d.SetHighlightDimStyleCommand({dimStyle:y}))};return(0,a.jsx)(q,{title:e??i("editor.colorPanel.appearanceSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.colorPanel.borderSection.cornerRadius"),children:(0,a.jsx)(s,{value:u,min:0,max:ug,step:1,formatValue:gt,onChange:m,onCommit:r.commands.commit})}),(0,a.jsx)(N,{label:i("editor.colorPanel.appearanceSection.highlightStyle"),children:(0,a.jsx)(l,{value:p,options:g,onChange:f})})]})})},gg={none:0,md:3.5,full:6.5},mg=({cornerRadius:e,...t})=>(0,a.jsx)(c.Icon,{viewBox:"0 0 18 18",...t,children:(0,a.jsx)("rect",{x:2.5,y:2.5,width:13,height:13,rx:gg[e],stroke:"currentColor",strokeWidth:1.5})}),vg=.05,$r=["none","md","full"],ti={base:["baseStart","baseEnd"],tip:["tipStart","tipEnd"]},xg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Slider:s,ToggleGroup:l}=v.useControls(),h=o?(0,d.findLayerByGeom)(o.spec.layers,"bar"):void 0,u=Ln(o,h?.id??null,"bar");if(!o||!h||o.coordSystem.type==="polar"&&o.coordSystem.bandAxis===null)return null;const p=y=>{r.commands.dispatch(new d.SetBarWidthCommand({layerId:h.id,width:y}),{transient:!0})},g=u?.get("cornerRadius")??d.DEFAULT_BAR_CORNER_RADII,m=(y,w)=>{const S=$r.find(A=>A===w);if(!S)return;const[I,j]=ti[y];r.commands.dispatch(new d.SetBarCornerRadiusCommand({layerId:h.id,corners:{...g,[I]:S,[j]:S}}))},f=$r.map(y=>({value:y,label:i(`editor.graphPanel.barSection.radiusOptions.${y}`),icon:(0,a.jsx)(mg,{cornerRadius:y})})),x=(0,d.resolveBarBandFraction)(h.params,o.coordSystem.type);return(0,a.jsx)(q,{title:e??i("editor.graphPanel.barSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.barSection.thickness"),children:(0,a.jsx)(s,{value:x,min:d.MIN_BAR_WIDTH_FRACTION,max:d.MAX_BAR_WIDTH_FRACTION,step:vg,formatValue:ei,onChange:p,onCommit:r.commands.commit})}),(0,a.jsx)(N,{label:i("editor.graphPanel.barSection.tipRadius"),children:(0,a.jsx)(l,{value:Xr(g,"tip"),options:f,onChange:y=>m("tip",y)})}),(0,a.jsx)(N,{label:i("editor.graphPanel.barSection.baseRadius"),children:(0,a.jsx)(l,{value:Xr(g,"base"),options:f,onChange:y=>m("base",y)})})]})})},Xr=(e,t)=>{const[n,r]=ti[t],o=e[n];return typeof o!="string"||o!==e[r]?"":o==="none"||o==="full"?o:"md"},mt=({children:e})=>{const t=(0,b.useId)();return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("g",{filter:`url(#${t})`,children:e}),(0,a.jsx)("defs",{children:(0,a.jsxs)("filter",{id:t,x:"-20%",y:"-20%",width:"140%",height:"140%",children:[(0,a.jsx)("feDropShadow",{dx:"0",dy:"0",stdDeviation:"0.586",floodColor:"#0F0F18",floodOpacity:"0.12"}),(0,a.jsx)("feDropShadow",{dx:"0",dy:"1.172",stdDeviation:"0.586",floodColor:"#0E0E34",floodOpacity:"0.16"})]})})]})},vt="qdaoth0",fg=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 31 33",...e,children:[(0,a.jsx)(mt,{children:(0,a.jsx)("path",{className:vt,fillRule:"evenodd",clipRule:"evenodd",d:"M25.7417 6.23664C25.7417 6.09417 25.7076 5.95967 25.6471 5.84086C25.5633 5.67624 25.4288 5.54173 25.2641 5.4579C25.1453 5.39739 25.0108 5.36328 24.8684 5.36328H12.0591C11.5767 5.36328 11.1857 5.7543 11.1857 6.23664C11.1857 6.71899 11.5767 7.11 12.0591 7.11H22.7599L5.61908 24.2508C5.27801 24.5919 5.27801 25.1448 5.61908 25.4859C5.96015 25.827 6.51313 25.827 6.8542 25.4859L23.995 8.34513V19.0459C23.995 19.5283 24.386 19.9193 24.8684 19.9193C25.3507 19.9193 25.7417 19.5283 25.7417 19.0459V6.23664ZM20.995 15.5878V19.0459C20.995 21.1851 22.7292 22.9193 24.8684 22.9193C27.0076 22.9193 28.7417 21.1851 28.7417 19.0459V6.23664C28.7417 4.09744 27.0076 2.36328 24.8684 2.36328H12.0591C9.91985 2.36328 8.18569 4.09744 8.18569 6.23664C8.18569 8.37584 9.91985 10.11 12.0591 10.11H15.5172L3.49777 22.1295C1.98512 23.6421 1.98513 26.0946 3.49776 27.6072C5.0104 29.1199 7.46288 29.1199 8.97552 27.6072L20.995 15.5878Z"})}),(0,a.jsx)("path",{fill:"currentColor",d:"M12.0591 7.11C11.5767 7.11 11.1857 6.71899 11.1857 6.23664C11.1857 5.7543 11.5767 5.36328 12.0591 5.36328H24.8684C25.3507 5.36328 25.7417 5.7543 25.7417 6.23664V19.0459C25.7417 19.5283 25.3507 19.9193 24.8684 19.9193C24.386 19.9193 23.995 19.5283 23.995 19.0459V8.34512L6.8542 25.4859C6.51313 25.827 5.96015 25.827 5.61908 25.4859C5.27801 25.1448 5.27801 24.5919 5.61908 24.2508L22.7599 7.11H12.0591Z"})]}),yg=e=>(0,a.jsx)(c.Icon,{viewBox:"0 0 32 32",...e,children:(0,a.jsxs)(mt,{children:[(0,a.jsx)("path",{className:vt,d:"M11 21H21V11H11V21ZM29 23C29 26.3137 26.3137 29 23 29H9C5.68629 29 3 26.3137 3 23V9C3 5.68629 5.68629 3 9 3H23C26.3137 3 29 5.68629 29 9V23Z"}),(0,a.jsx)("path",{fill:"currentColor",d:"M24.25 9C24.25 8.30964 23.6904 7.75 23 7.75H9C8.30964 7.75 7.75 8.30964 7.75 9V23C7.75 23.6904 8.30964 24.25 9 24.25H23C23.6904 24.25 24.25 23.6904 24.25 23V9ZM25.75 23C25.75 24.5188 24.5188 25.75 23 25.75H9C7.48122 25.75 6.25 24.5188 6.25 23V9C6.25 7.48122 7.48122 6.25 9 6.25H23C24.5188 6.25 25.75 7.48122 25.75 9V23Z"})]})}),Sg=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 32 33",...e,children:[(0,a.jsx)(mt,{children:(0,a.jsx)("path",{className:vt,fillRule:"evenodd",clipRule:"evenodd",d:"M4.89961 14.7968C3.08522 13.5116 1.89961 11.3966 1.89961 9.00039C1.89961 5.07917 5.07839 1.90039 8.99961 1.90039C10.7798 1.90039 12.4069 2.55553 13.6531 3.63785C14.3179 3.17306 15.1269 2.90039 15.9996 2.90039L22.9996 2.90039C25.264 2.90039 27.0996 4.73602 27.0996 7.00039L27.0996 9.7243C27.5717 9.92414 28.014 10.2165 28.3987 10.6013C29.9999 12.2024 29.9999 14.7984 28.3987 16.3995L27.9182 16.8801C29.2628 18.172 30.0996 19.9885 30.0996 22.0004C30.0996 25.9216 26.9208 29.1004 22.9996 29.1004C21.2195 29.1004 19.5923 28.4453 18.3461 27.3629C17.6813 27.8277 16.8723 28.1004 15.9996 28.1004L8.99961 28.1004C6.73524 28.1004 4.89961 26.2648 4.89961 24.0004L4.89961 14.7968Z"})}),(0,a.jsx)("path",{fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd",d:"M25.25 22C25.25 20.7574 24.2426 19.75 23 19.75C21.7574 19.75 20.75 20.7574 20.75 22C20.75 23.2426 21.7574 24.25 23 24.25C24.2426 24.25 25.25 23.2426 25.25 22ZM23 18.25C25.0711 18.25 26.75 19.9289 26.75 22C26.75 24.0711 25.0711 25.75 23 25.75C20.9289 25.75 19.25 24.0711 19.25 22C19.25 19.9289 20.9289 18.25 23 18.25ZM11.25 9C11.25 7.75736 10.2426 6.75 9 6.75C7.75736 6.75 6.75 7.75736 6.75 9C6.75 10.2426 7.75736 11.25 9 11.25C10.2426 11.25 11.25 10.2426 11.25 9ZM9.75 12.675C11.4617 12.3275 12.75 10.8142 12.75 9C12.75 6.92893 11.0711 5.25 9 5.25C6.92893 5.25 5.25 6.92893 5.25 9C5.25 10.8142 6.53832 12.3275 8.25 12.675L8.25 24C8.25 24.4142 8.58579 24.75 9 24.75L16 24.75C16.4142 24.75 16.75 24.4142 16.75 24L16.75 7.75L22.25 7.75L22.25 14.1893L21.0303 12.9697C20.7374 12.6768 20.2626 12.6768 19.9697 12.9697C19.6768 13.2626 19.6768 13.7374 19.9697 14.0303L22.4697 16.5303C22.7626 16.8232 23.2374 16.8232 23.5303 16.5303L26.0303 14.0303C26.3232 13.7374 26.3232 13.2626 26.0303 12.9697C25.7374 12.6768 25.2626 12.6768 24.9697 12.9697L23.75 14.1893L23.75 7C23.75 6.58579 23.4142 6.25 23 6.25L16 6.25C15.5858 6.25 15.25 6.58579 15.25 7L15.25 23.25L9.75 23.25L9.75 12.675Z"})]}),bg=e=>(0,a.jsxs)(c.Icon,{viewBox:"0 0 32 33",...e,children:[(0,a.jsx)(mt,{children:(0,a.jsx)("path",{className:vt,d:"M20.7271 2C21.4372 2 21.7114 2.00463 22.0841 2.03504C22.8228 2.0954 23.4839 2.25122 24.1592 2.59527C25.1865 3.1188 26.0219 3.9541 26.5458 4.98208C26.8896 5.65706 27.0454 6.31812 27.1057 7.05672C27.1301 7.35469 27.1379 7.58979 27.14 8.03558L27.1408 9.10155C27.1408 11.2114 25.4304 12.922 23.3205 12.922C21.4083 12.922 19.8243 11.5172 19.5441 9.68336L19.538 9.64H18.39V21.687L20.0392 21.6877C22.149 21.6877 23.8595 23.398 23.8595 25.508C23.8595 27.6178 22.149 29.3283 20.0392 29.3283H9.10159C6.99169 29.3283 5.28127 27.6178 5.28127 25.508C5.28127 23.398 6.99172 21.6877 9.10159 21.6877L10.75 21.687V9.64H9.601L9.59661 9.68334C9.32609 11.4539 7.84018 12.8246 6.01692 12.917L5.82032 12.922C3.71035 12.922 2 11.2114 2 9.10155V8.41371C2 7.70349 2.00463 7.42929 2.03504 7.05674C2.09538 6.31803 2.25122 5.65681 2.59521 4.98173C3.11877 3.95419 3.95418 3.11876 4.98174 2.5952C5.65683 2.25122 6.31798 2.09539 7.057 2.03501C7.42935 2.00463 7.70354 2 8.41371 2H20.7271Z"})}),(0,a.jsx)("path",{fill:"currentColor",d:"M8.41371 5H20.7271C21.1595 5 21.5325 5 21.8398 5.02507C22.1641 5.05157 22.4867 5.11007 22.7971 5.26822C23.2601 5.50416 23.6366 5.88064 23.8726 6.3437C24.0307 6.65409 24.0892 6.97666 24.1157 7.30097C24.1408 7.60823 24.1408 7.98127 24.1408 8.41369V9.10155C24.1408 9.55465 23.7735 9.92195 23.3205 9.92195C22.8674 9.92195 22.5001 9.55465 22.5001 9.10155V8.44533C22.5001 7.97237 22.4995 7.66699 22.4805 7.43457C22.4623 7.21172 22.4314 7.12909 22.4107 7.08853C22.3321 6.93418 22.2066 6.80869 22.0522 6.73004C22.0117 6.70938 21.9291 6.67847 21.7062 6.66026C21.4738 6.64127 21.1684 6.64063 20.6954 6.64063H15.3907V24.6877H20.0392C20.4922 24.6877 20.8595 25.0549 20.8595 25.508C20.8595 25.961 20.4922 26.3283 20.0392 26.3283H9.10159C8.64854 26.3283 8.28127 25.961 8.28127 25.508C8.28127 25.0549 8.64854 24.6877 9.10159 24.6877H13.7501V6.64063H8.44533C7.97238 6.64063 7.66699 6.64127 7.43457 6.66026C7.21172 6.67847 7.1291 6.70938 7.08854 6.73004C6.93418 6.80869 6.80869 6.93418 6.73004 7.08853C6.70938 7.12909 6.67847 7.21172 6.66026 7.43457C6.64127 7.66699 6.64063 7.97237 6.64063 8.44533V9.10155C6.64063 9.55465 6.27337 9.92195 5.82032 9.92195C5.36727 9.92195 5 9.55465 5 9.10155V8.41371C5 7.98128 5 7.60823 5.02508 7.30097C5.05157 6.97666 5.11007 6.65409 5.26823 6.3437C5.50417 5.88064 5.88064 5.50416 6.3437 5.26822C6.65409 5.11007 6.97666 5.05157 7.30097 5.02507C7.60824 5 7.98129 5 8.41371 5Z"})]}),Cg={x:.5,y:.5},wg=.2,Tg={x:.375,y:.25,width:.25,height:.5},jg={zOrder:"background"},Ag={x:.4,y:.6},Pg={x:.6,y:.4},Ig="relativeDifference",kg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Button:s}=v.useControls();if(!o)return null;const l=()=>{r.commands.dispatch(new d.AddAnnotationCommand({kind:"text",annotation:{...d.TEXT_ANNOTATION_DEFAULTS,content:Lg(i("editor.annotatePanel.callOutSection.text")),at:{anchorType:"panel",...Cg},width:wg}}))},h=()=>{r.commands.dispatch(new d.AddAnnotationCommand({kind:"arrow",annotation:{...d.ARROW_DEFAULTS,start:{anchorType:"panel",...Ag},end:{anchorType:"panel",...Pg}}}))},u=()=>{r.commands.dispatch(new d.AddAnnotationCommand({kind:"shape",annotation:{...d.SHAPE_DEFAULTS,...jg,region:{anchorType:"panel",...Tg}}}))},p=()=>{const m=(0,d.inferDefaultDifferenceArrowEndpoints)(o);m!==null&&r.commands.dispatch(new d.AddAnnotationCommand({kind:"differenceArrow",annotation:{...d.DIFFERENCE_ARROW_DEFAULTS,...m,label:Ig}}))},g=o.coordSystem.type==="cartesian";return(0,a.jsx)(q,{title:e??i("editor.annotatePanel.callOutSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Ha,{children:[(0,a.jsx)(s,{variant:"tile",icon:(0,a.jsx)(bg,{size:"xl"}),label:i("editor.annotatePanel.callOutSection.text"),onClick:l}),(0,a.jsx)(s,{variant:"tile",icon:(0,a.jsx)(fg,{size:"xl"}),label:i("editor.annotatePanel.callOutSection.arrow"),onClick:h}),(0,a.jsx)(s,{variant:"tile",icon:(0,a.jsx)(yg,{size:"xl"}),label:i("editor.annotatePanel.callOutSection.box"),onClick:u}),g&&(0,a.jsx)(s,{variant:"tile",icon:(0,a.jsx)(Sg,{size:"xl"}),label:i("editor.annotatePanel.callOutSection.difference"),onClick:p})]})})},Lg=e=>({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:e}]}]}),Eg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{ToggleGroup:s}=v.useControls();if(!o)return null;const l=(0,d.readGraphType)(o.spec);if(l===null||!(0,d.isComboGraphType)(l))return null;const h=d.COMBO_TYPES.map(p=>({value:p,label:i(`editor.graphPanel.comboSection.types.${p}`)})),u=p=>{const g=d.COMBO_TYPES.find(m=>m===p);g&&r.commands.dispatch(new d.SetGraphTypeCommand({coordType:"cartesian",comboType:g}))};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.comboSection.title"),layout:t,preview:n??i(`editor.graphPanel.comboSection.types.${l.comboType}`),children:(0,a.jsx)(s,{value:l.comboType,options:h,onChange:u,ariaLabel:i("editor.graphPanel.comboSection.title")})})},Mg=.1,Og=20,Rg=({title:e,preview:t})=>{const n=v.usePanelGraph(),r=c.useHandleScene(n),o=c.useI18n(),{NumberField:i,TextField:s}=v.useControls();if(!r||r.coordSystem.type==="polar")return null;const l=(0,d.findGoalLineLayer)(r.spec.layers),h=e??o("editor.annotationsPanel.goalSection.title"),u=(0,d.readConstantValue)(l?.mapping.y),p=typeof u=="number"?u:null,g=x=>{const y=new d.ToggleGoalLineCommand({showGoalLine:x,value:_g(r),...l!==void 0&&{layerId:l.id}});n.commands.dispatch(y)},m=x=>{if(l===void 0)return;const y=new d.SetRuleLabelCommand({layerId:l.id,label:x===""?null:x});n.commands.dispatch(y,{transient:!0})},f=x=>{if(l===void 0||x===null)return;const y=new d.SetRuleValueCommand({layerId:l.id,value:x});n.commands.dispatch(y,{transient:!0})};return(0,a.jsx)(Ua,{title:h,preview:t,checked:l!==void 0,onToggle:g,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:o("editor.annotationsPanel.goalSection.labelControl"),children:(0,a.jsx)(s,{value:l?.params.label??"",placeholder:o("editor.annotationsPanel.goalSection.labelPlaceholder"),onChange:m,onCommit:n.commands.commit,ariaLabel:o("editor.annotationsPanel.goalSection.labelAriaLabel")})}),(0,a.jsx)(N,{label:o("editor.annotationsPanel.goalSection.valueControl"),children:(0,a.jsx)(i,{value:p,placeholder:o("editor.powerUpPanel.valueInput.numberPlaceholder"),onChange:f,onCommit:n.commands.commit,ariaLabel:o("editor.annotationsPanel.goalSection.valueAriaLabel")})})]})})},_g=e=>{const t=(e.scales.y?.domain??[]).filter(s=>typeof s=="number");if(t.length===0)return 0;const n=Math.max(...t),r=n-Math.min(...t),o=r>0?r:Math.abs(n);if(o===0)return 0;const i=Math.min(Og,Math.max(0,1-Math.floor(Math.log10(o))));return Number((n+o*Mg).toFixed(i))},qr=["auto","inside","outside"],Dg=({layerId:e,title:t,layout:n="collapsible",preview:r})=>{const o=v.usePanelGraph(),i=c.useHandleScene(o),s=c.useI18n(),{Switch:l,ToggleGroup:h}=v.useControls();if(!i)return null;const u=e===void 0?i.layers[0]:(0,d.findLayerById)(i.layers,e);if(!u)return null;const{showDataLabels:p,format:g,showStackTotals:m,showCategoryLabels:f,position:x}=u.dataLabels,y=io(u,i.coordSystem.type,{hasCapability:o.canPlaceDataLabels,hasPercentageFormat:o.canFormatDataLabelsAsPercentages});if(!y.supportsDataLabels)return null;const w=T=>{const M=new d.ToggleDataLabelsCommand({layerId:u.id,showDataLabels:T});o.commands.dispatch(M)},S=T=>{const M=qr.find(G=>G===T);M!==void 0&&o.commands.dispatch(new d.SetDataLabelsCommand({layerId:u.id,position:M}))},I=T=>{const M=new d.SetDataLabelsFormatCommand({layerId:u.id,format:T?"percentage":"absolute"});o.commands.dispatch(M)},j=T=>{const M=new d.ToggleStackTotalsCommand({layerId:u.id,showStackTotals:T});o.commands.dispatch(M)},A=T=>{const M=new d.ToggleCategoryLabelsCommand({layerId:u.id,showCategoryLabels:T});o.commands.dispatch(M)};return(0,a.jsx)(q,{title:t??s("editor.graphPanel.graphOptionsSection.title"),layout:n,preview:r,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:s("editor.graphPanel.graphOptions.dataLabels"),children:(0,a.jsx)(l,{checked:p,onChange:w})}),y.supportsPosition&&(0,a.jsx)(N,{label:s("editor.graphPanel.graphOptions.labelPosition"),children:(0,a.jsx)(h,{value:x,options:qr.map(T=>({value:T,label:s(`editor.graphPanel.graphOptions.labelPositions.${T}`)})),onChange:S})}),y.supportsPercentages&&(0,a.jsx)(N,{label:s("editor.graphPanel.graphOptions.showPercentages"),children:(0,a.jsx)(l,{checked:g==="percentage",onChange:I})}),y.supportsStackTotals&&(0,a.jsx)(N,{label:s("editor.graphPanel.graphOptions.stackTotals"),children:(0,a.jsx)(l,{checked:m,onChange:j})}),y.supportsCategoryLabels&&(0,a.jsx)(N,{label:s("editor.graphPanel.graphOptions.categoryLabels"),children:(0,a.jsx)(l,{checked:f,onChange:A})})]})})},Ng=3,Gg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{RadioGrid:s}=v.useControls(),l=(0,b.useMemo)(()=>Pe.map(({name:g,icon:m,summary:f})=>({value:g,label:i(`editor.graphTypes.${g}`),icon:(0,a.jsx)(m,{size:"md"}),disabled:!co(f,o?.spec)})),[i,o]);if(!o)return null;const h=(0,d.readGraphType)(o.spec),u=nt(h),p=g=>{const m=Pe.find(f=>f.name===g);m&&r.commands.dispatch(new d.SetGraphTypeCommand(uo(m.summary,h)))};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.graphTypeSection.title"),layout:t,preview:n??(u===null?void 0:i(`editor.graphTypes.${u.name}`)),children:(0,a.jsx)(s,{value:u?.name??"",options:l,columns:Ng,onChange:p,ariaLabel:i("editor.graphPanel.graphTypeSection.title")})})},Bg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Slider:s,Switch:l,ToggleGroup:h}=v.useControls(),u=_e(o),p=o!==null&&u!==null?wo(o,u):null;if(p===null)return null;const g=p.axes.filter(S=>S.supportsGrid);if(g.length===0)return null;const m=p.axes.some(S=>S.showGrid),f=at.map(S=>({value:S,label:i(`editor.graphPanel.gridSection.lineStyles.${S}`)})),x=S=>I=>{r.commands.dispatch(new d.SetGridVisibilityCommand({axis:S,visible:I}))},y=S=>{const I=at.find(j=>j===S);I!==void 0&&r.commands.dispatch(To(I))},w=S=>{r.commands.dispatch(jo(S),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.gridSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[g.map(S=>(0,a.jsx)(N,{label:i(Fg(S)),children:(0,a.jsx)(l,{checked:S.showGrid,onChange:x(S.scaledAesthetic)})},S.scaledAesthetic)),p.stylable&&m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.gridSection.gridStyle"),children:(0,a.jsx)(h,{value:p.lineStyle,options:f,onChange:y})}),(0,a.jsx)(N,{label:i("editor.graphPanel.gridSection.gridThickness"),children:(0,a.jsx)(s,{value:p.strokeWidth,min:0,max:8,step:.5,formatValue:gt,onChange:w,onCommit:r.commands.commit})})]})]})})},Fg=e=>e.geometry==="radial"?"editor.graphPanel.gridSection.rings":e.geometry==="circular"?"editor.graphPanel.gridSection.spokes":e.scaledAesthetic==="x"?"editor.graphPanel.gridSection.verticalGridLines":"editor.graphPanel.gridSection.horizontalGridLines",Hg="total",ni=["total","average","current"],zg=["total"],Yr=["previous","first"],Zr=["auto","small","medium","large"],Wg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Switch:s,ToggleGroup:l}=v.useControls();if(!o)return null;const h=o.config.headline,u=h.show!=="none",p=o.coordSystem,g=p.type==="polar",m=p.type==="polar"&&p.innerRadius>0,f=o.layers.some(R=>R.summary.grandTotal!==void 0);if(g&&!f)return null;const x=g?zg:ni,y=o.guides.headline,w=y?.kind==="perGroup"&&y.items.some(R=>R.comparison!==null),S=x.map(R=>({value:R,label:i(`editor.graphPanel.headlineNumberSection.metrics.${R}`)})),I=Yr.map(R=>({value:R,label:i(`editor.graphPanel.headlineNumberSection.comparison.${R}`)})),j=Zr.map(R=>({value:R,label:i(R==="auto"?"editor.graphPanel.numberFormat.options.auto":`editor.graphPanel.headlineNumberSize.sizes.${R}`)})),A=[{value:"above",label:i("editor.graphPanel.headlineNumberSection.position.above")},{value:"center",label:i("editor.graphPanel.headlineNumberSection.position.center")}],T=R=>{r.commands.dispatch(new d.SetHeadlineShowCommand({show:R?Hg:"none"}))},M=R=>{const k=x.find(_=>_===R);k&&r.commands.dispatch(new d.SetHeadlineShowCommand({show:k}))},G=R=>{const k=Yr.find(_=>_===R);k&&r.commands.dispatch(new d.SetHeadlineCompareWithCommand({compareWith:k}))},L=R=>{const k=Zr.find(_=>_===R);k&&r.commands.dispatch(new d.SetHeadlineSizeCommand({size:k}))},B=R=>{r.commands.dispatch(new d.SetHeadlinePositionCommand({position:R==="center"?"center":"above"}))};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.headlineNumberSection.title"),layout:t,preview:n??Vg(i,h.show),children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.headlineNumberSection.toggle"),children:(0,a.jsx)(s,{checked:u,onChange:T})}),u&&(0,a.jsxs)(a.Fragment,{children:[S.length>1&&(0,a.jsx)(N,{label:i("editor.graphPanel.headlineNumberSection.metricLabel"),layout:"stack",children:(0,a.jsx)(l,{value:h.show,options:S,onChange:M})}),w&&(0,a.jsx)(N,{label:i("editor.graphPanel.headlineNumberSection.compareWithLabel"),layout:"stack",children:(0,a.jsx)(l,{value:(0,d.resolveComparisonBasis)(h.compareWith),options:I,onChange:G})}),(0,a.jsx)(N,{label:i("editor.graphPanel.headlineNumberSize.sizeLabel"),children:(0,a.jsx)(l,{value:h.size,options:j,onChange:L})}),m&&(0,a.jsx)(N,{label:i("editor.axesPanel.controls.position"),children:(0,a.jsx)(l,{value:h.position,options:A,onChange:B})})]})]})})},Vg=(e,t)=>{const n=ni.find(r=>r===t);return n&&e(`editor.graphPanel.headlineNumberSection.metrics.${n}`)};var Rt=["top","bottom","left","right","none"],Jr=["auto","start","center","end"],Kg={row:{start:"left",end:"right"},column:{start:"top",end:"bottom"}},Qr=["auto","pill","direct"],Ug=({positions:e,title:t,layout:n="collapsible",preview:r})=>{const o=v.usePanelGraph(),i=c.useHandleScene(o),s=c.useI18n(),{ToggleGroup:l}=v.useControls(),h=c.useTextDirection();if(!i)return null;const u=i.config.legend.position,p=e??Rt,g=i.guides.legends.drawn[0],m=(0,d.canAnchorDirectLabels)({legendPosition:i.guides.legends.position,coordSystem:i.coordSystem,layers:i.layers}),f=i.guides.headline?.kind==="perGroup",x=i.guides.colorGroups.length>0;if(u==="auto"&&g===void 0&&!m&&(f||!x))return null;const y=g?.position??"none",w=u==="auto"?y:u,S=Rt.filter(O=>O===w||p.includes(O)).map(O=>({value:O,label:s(`editor.graphPanel.legendSection.${O}`)})),I=O=>{const C=Rt.find(D=>D===O);C&&o.commands.dispatch(new d.SetLegendPositionCommand({position:C}))},j=O=>{const C=Jr.find(D=>D===O);C&&o.commands.dispatch(new d.SetLegendAlignCommand({align:C}))},A=O=>{const C=Qr.find(D=>D===O);C&&o.commands.dispatch(new d.SetLegendDisplayCommand({display:C}))},T=g?.position==="left"||g?.position==="right"?"column":"row",M=T==="row"?"ltr":h,G=O=>s(O==="start"||O==="end"?`editor.graphPanel.legendSection.${Kg[T][O]}`:`editor.graphPanel.legendSection.align.${O}`),L=Jr.map(O=>({value:O,label:G(O)})),B=Qr.map(O=>({value:O,label:s(`editor.graphPanel.legendSection.display.${O}`)})),R=t??s("editor.graphPanel.legendSection.title"),k=S.find(O=>O.value===w)?.label,_=g!==void 0&&!g.inHeadlineRow;return(0,a.jsx)(q,{title:R,layout:n,preview:r??k,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:s("editor.axesPanel.controls.position"),layout:"stack",children:(0,a.jsx)(l,{value:w,options:S,onChange:I})}),_&&(0,a.jsx)(N,{label:s("editor.graphPanel.legendSection.alignLabel"),layout:"stack",children:(0,a.jsx)(en.DirectionProvider,{direction:M,children:(0,a.jsx)("div",{dir:M,className:"_1v6dqrh0",children:(0,a.jsx)(l,{value:i.config.legend.align,options:L,onChange:j})})})}),m&&(0,a.jsx)(N,{label:s("editor.graphPanel.legendSection.displayLabel"),layout:"stack",children:(0,a.jsx)(l,{value:i.config.legend.display,options:B,onChange:A})})]})})},$g=1,Xg=20,qg=.5,ri=({layerId:e})=>{const t=v.usePanelGraph(),n=c.useHandleScene(t),{Slider:r}=v.useControls(),o=Ln(n,e,"point");if(!n)return null;const i=(0,d.findLayerById)(n.layers,e)?.data?.findFirst(h=>(o?.get("size",h)??0)>0)??void 0,s=o?.get("size",i)??d.DEFAULT_POINT_SIZE_PX,l=h=>{const u=new d.SetPointSizeCommand({layerId:e,size:h});t.commands.dispatch(u,{transient:!0})};return(0,a.jsx)(r,{value:s,min:$g,max:Xg,step:qg,formatValue:gt,onChange:l,onCommit:t.commands.commit})},oi=({layerId:e})=>{const t=v.usePanelGraph(),n=c.useHandleScene(t),r=Ln(n,e,"point");return n?(0,a.jsx)(on,{symbol:r?.get("symbol")??"circle",coordType:n.coordSystem.type,onChange:o=>{t.commands.dispatch(new d.SetPointSymbolCommand({layerId:e,symbol:o}))}}):null},Yg=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Select:s,Slider:l,Switch:h,ToggleGroup:u}=v.useControls(),p=_e(o),g=(0,d.findLayerByGeom)(o?.spec.layers??[],"line","area"),m=o&&p&&g?rn(o,p,g.id):null;if(!o||!m)return null;const f=m.missingValueOptions.map(T=>({value:T,label:so(i,T)})),x=[{value:"auto",label:i("editor.graphPanel.numberFormat.options.auto"),disabled:m.hasUnderlyingStrokeWidth},{value:"custom",label:i("editor.graphPanel.numberFormat.options.custom")}],y=T=>{r.commands.dispatch(new d.ToggleLinePointsCommand({layerId:m.layerId,showPoints:T}))},w=T=>{r.commands.dispatch(new d.SetLineStyleCommand({layerId:m.layerId,showFill:T,drawnFillAlpha:m.drawnFillAlpha}))},S=T=>{r.commands.dispatch(new d.SetLineCurveCommand({layerId:m.layerId,curve:T?"smooth":"linear"}))},I=T=>{r.commands.dispatch(new d.SetLineStyleCommand({layerId:m.layerId,strokeWidth:T==="custom"?m.strokeWidth:null}))},j=T=>{r.commands.dispatch(new d.SetLineStyleCommand({layerId:m.layerId,strokeWidth:T}),{transient:!0})},A=T=>{const M=Dt.find(G=>G===T);M&&r.commands.dispatch(new d.SetLineMissingValuesCommand({layerId:m.layerId,missingValues:M}))};return(0,a.jsx)(q,{title:e??i("editor.fineTunePanel.lineStyleSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.graphOptions.showPoints"),children:(0,a.jsx)(h,{checked:m.showPoints,onChange:y})}),m.pointLayerId&&(0,a.jsx)(N,{label:i("editor.graphPanel.pointSize.label"),children:(0,a.jsx)(ri,{layerId:m.pointLayerId})}),m.showPoints&&m.pointLayerId!==null&&(0,a.jsx)(oi,{layerId:m.pointLayerId}),m.showFill!==null&&(0,a.jsx)(N,{label:i("editor.graphPanel.graphOptions.lineFill"),children:(0,a.jsx)(h,{checked:m.showFill,onChange:w})}),m.smooth!==null&&(0,a.jsx)(N,{label:i("editor.graphPanel.graphOptions.smoothLines"),children:(0,a.jsx)(h,{checked:m.smooth,onChange:S})}),(0,a.jsx)(N,{label:i("editor.graphPanel.lineThickness.label"),children:(0,a.jsx)(u,{value:m.widthMode,options:x,onChange:I})}),m.widthMode==="custom"&&(0,a.jsx)(N,{label:i("editor.graphPanel.numberFormat.valueLabel"),children:(0,a.jsx)(l,{value:m.strokeWidth,min:1,max:10,step:.1,formatValue:gt,onChange:j,onCommit:r.commands.commit})}),m.missingValues!==null&&(0,a.jsx)(N,{label:i("editor.fineTunePanel.detailSection.missingValues"),children:(0,a.jsx)(s,{value:m.missingValues,options:f,onChange:A})})]})})},Jt="\0none",Zg=["x","y","color","size","label"],Jg={x:"editor.graphPanel.mappingSection.x",y:"editor.graphPanel.mappingSection.y",color:"editor.graphPanel.mappingSection.color",size:"editor.graphPanel.mappingSection.size",label:"editor.graphPanel.mappingSection.label"},Qg=({title:e,layout:t="collapsible"})=>{const n=v.usePanelGraph(),r=c.useHandleScene(n),o=c.useI18n(),{Select:i}=v.useControls(),s=o("editor.graphPanel.mappingSection.none"),l=r?.spec,h=(0,b.useMemo)(()=>l===void 0?[]:(0,d.readMappableAesthetics)(l,Zg).map(({aesthetic:u,variables:p,required:g})=>{const m=(0,d.readMappedVariable)(l.mapping,u);return{aesthetic:u,label:o(Jg[u]),value:m??(g?null:Jt),options:e1(p,m,g?null:s),chooseColumn:f=>{n.commands.dispatch(new d.SetMappingCommand({aesthetic:u,variable:f===Jt?null:f}))}}}),[l,o,s,n]);return r?(0,a.jsx)(q,{title:e??o("editor.graphPanel.mappingSection.title"),layout:t,children:(0,a.jsx)(Z,{children:h.map(({aesthetic:u,label:p,value:g,options:m,chooseColumn:f})=>(0,a.jsx)(N,{label:p,children:(0,a.jsx)(i,{value:g,options:m,placeholder:s,onChange:f})},u))})}):null},e1=(e,t,n)=>{const r=t!==null&&!e.includes(t)?[t,...e]:e;return[...n===null?[]:[{value:Jt,label:n}],...r.map(o=>({value:o,label:o}))]},t1="k",n1=2,r1=0,o1=5,Qt=[{value:"k",labelKey:"thousands"},{value:"m",labelKey:"millions"},{value:"b",labelKey:"billions"}],a1=["auto","none"],i1=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{NumberField:s,ToggleGroup:l}=v.useControls();if(!o)return null;const{abbreviation:h,decimals:u}=o.config.numberFormat,p=s1(h)!==void 0,g=u!=="auto",m=j=>j.map(A=>({value:A,label:i(`editor.graphPanel.numberFormat.options.${A}`)})),f=Qt.map(({value:j,labelKey:A})=>({value:j,label:i(`common.abbreviations.${A}`)})),x=j=>{r.commands.dispatch(new d.SetNumberFormatAbbreviationCommand({abbreviation:j}))},y=j=>{const A=a1.find(T=>T===j);x(A??t1)},w=j=>{const A=Qt.find(T=>T.value===j);A&&x(A.value)},S=j=>{r.commands.dispatch(new d.SetNumberFormatDecimalsCommand({decimals:j==="custom"?n1:"auto"}))},I=j=>{j!==null&&r.commands.dispatch(new d.SetNumberFormatDecimalsCommand({decimals:j}),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.numberFormatSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.numberFormat.abbreviationLabel"),children:(0,a.jsx)(l,{value:p?"custom":h,options:m(["auto","none","custom"]),onChange:y})}),p&&(0,a.jsx)(N,{label:i("editor.graphPanel.numberFormat.valueLabel"),children:(0,a.jsx)(l,{value:h,options:f,onChange:w})}),(0,a.jsx)(N,{label:i("editor.graphPanel.numberFormat.decimalPlacesLabel"),children:(0,a.jsx)(l,{value:g?"custom":"auto",options:m(["auto","custom"]),onChange:S})}),g&&(0,a.jsx)(N,{label:i("editor.graphPanel.numberFormat.valueLabel"),children:(0,a.jsx)(s,{value:u,min:r1,max:o1,onChange:I,onCommit:r.commands.commit})})]})})},s1=e=>Qt.find(t=>t.value===e),l1=({title:e,layout:t="collapsible",preview:n})=>{const r=c.useHandleScene(v.usePanelGraph()),o=c.useI18n();if(!r)return null;const i=c1(r.spec.layers);return i?(0,a.jsx)(q,{title:e??o("editor.graphPanel.pointSize.label"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:o("editor.graphPanel.numberFormat.valueLabel"),children:(0,a.jsx)(ri,{layerId:i.id})}),(0,a.jsx)(oi,{layerId:i.id})]})}):null},c1=e=>{const t=(0,d.filterLayersByGeoms)(e,"line","area");return(0,d.filterLayersByGeoms)(e,"point").find(n=>!(0,d.isCompanionLayer)(n,t))},d1=.9,u1=360,h1=.05,p1=15,g1=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Slider:s}=v.useControls();if(!o||o.spec.coords.coordType!=="polar")return null;const{innerRadius:l,startAngle:h}=o.spec.coords.params,u=g=>{r.commands.dispatch(new d.SetPolarInnerRadiusCommand({innerRadius:g}),{transient:!0})},p=g=>{r.commands.dispatch(new d.SetPolarStartAngleCommand({startAngle:g}),{transient:!0})};return(0,a.jsx)(q,{title:e??i("editor.graphPanel.polarSection.title"),layout:t,preview:n,children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.graphPanel.polarSection.innerRadius"),children:(0,a.jsx)(s,{value:l,min:0,max:d1,step:h1,formatValue:ei,onChange:u,onCommit:r.commands.commit})}),(0,a.jsx)(N,{label:i("editor.graphPanel.polarSection.startAngle"),children:(0,a.jsx)(s,{value:h,min:0,max:u1-1,step:p1,formatValue:dg,onChange:p,onCommit:r.commands.commit})})]})})},m1=e=>(0,a.jsxs)(c.Icon,{...e,children:[(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",opacity:"0.12",d:"M2 10C2 7.19974 2 5.79961 2.54497 4.73005C3.02433 3.78924 3.78924 3.02433 4.73005 2.54497C5.79961 2 7.19974 2 10 2H14C16.8003 2 18.2004 2 19.27 2.54497C20.2108 3.02433 20.9757 3.78924 21.455 4.73005C22 5.79961 22 7.19974 22 10V14C22 16.8003 22 18.2004 21.455 19.27C20.9757 20.2108 20.2108 20.9757 19.27 21.455C18.2004 22 16.8003 22 14 22H10C7.19974 22 5.79961 22 4.73005 21.455C3.78924 20.9757 3.02433 20.2108 2.54497 19.27C2 18.2004 2 16.8003 2 14V10Z",fill:"currentColor"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.96644 1.25C8.59472 1.25 7.51929 1.24999 6.65494 1.32061C5.77479 1.39252 5.04768 1.54138 4.38955 1.87671C3.30762 2.42798 2.42798 3.30762 1.87671 4.38955C1.54138 5.04768 1.39252 5.77479 1.32061 6.65494C1.24999 7.51929 1.25 8.59472 1.25 9.96644V14.0336C1.25 15.4053 1.24999 16.4807 1.32061 17.3451C1.39252 18.2252 1.54138 18.9523 1.87671 19.6104C2.42798 20.6924 3.30762 21.572 4.38955 22.1233C5.04768 22.4586 5.77479 22.6075 6.65494 22.6794C7.51927 22.75 8.59469 22.75 9.96637 22.75H14.0336C15.4053 22.75 16.4807 22.75 17.3451 22.6794C18.2252 22.6075 18.9523 22.4586 19.6104 22.1233C20.6924 21.572 21.572 20.6924 22.1233 19.6104C22.4586 18.9523 22.6075 18.2252 22.6794 17.3451C22.75 16.4807 22.75 15.4053 22.75 14.0336V9.96642C22.75 8.59473 22.75 7.51927 22.6794 6.65494C22.6075 5.77479 22.4586 5.04768 22.1233 4.38955C21.572 3.30762 20.6924 2.42798 19.6104 1.87671C18.9523 1.54138 18.2252 1.39252 17.3451 1.32061C16.4807 1.24999 15.4053 1.25 14.0336 1.25H9.96644ZM5.07054 3.21322C5.48197 3.00359 5.9897 2.87996 6.77708 2.81563C7.57322 2.75058 8.58749 2.75 10 2.75H14C15.4125 2.75 16.4268 2.75058 17.2229 2.81563C18.0103 2.87996 18.518 3.00359 18.9295 3.21322C19.7291 3.62068 20.3793 4.27085 20.7868 5.07054C20.9964 5.48197 21.12 5.9897 21.1844 6.77708C21.2494 7.57322 21.25 8.58749 21.25 10V14C21.25 15.4125 21.2494 16.4268 21.1844 17.2229C21.12 18.0103 20.9964 18.518 20.7868 18.9295C20.3793 19.7291 19.7291 20.3793 18.9295 20.7868C18.518 20.9964 18.0103 21.12 17.2229 21.1844C16.4268 21.2494 15.4125 21.25 14 21.25H10C8.58749 21.25 7.57322 21.2494 6.77708 21.1844C5.9897 21.12 5.48197 20.9964 5.07054 20.7868C4.27085 20.3793 3.62068 19.7291 3.21322 18.9295C3.00359 18.518 2.87996 18.0103 2.81563 17.2229C2.75058 16.4268 2.75 15.4125 2.75 14V10C2.75 8.58749 2.75058 7.57322 2.81563 6.77708C2.87996 5.9897 3.00359 5.48197 3.21322 5.07054C3.62068 4.27085 4.27085 3.62068 5.07054 3.21322Z",fill:"currentColor"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19.4796 12.2222L17.6085 12.2291L17.6029 10.7291L19.474 10.7222L19.4796 12.2222ZM15.3662 12.2375L13.124 12.2459L13.1184 10.7459L15.3606 10.7375L15.3662 12.2375ZM10.8817 12.2542L8.63945 12.2626L8.63386 10.7626L10.8761 10.7542L10.8817 12.2542ZM6.39719 12.2709L4.52607 12.2779L4.52048 10.7779L6.3916 10.7709L6.39719 12.2709Z",fill:"currentColor"})]}),eo=e=>(0,a.jsxs)(c.Icon,{...e,children:[(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",opacity:"0.12",d:"M2 10C2 7.19974 2 5.79961 2.54497 4.73005C3.02433 3.78924 3.78924 3.02433 4.73005 2.54497C5.79961 2 7.19974 2 10 2H14C16.8003 2 18.2004 2 19.27 2.54497C20.2108 3.02433 20.9757 3.78924 21.455 4.73005C22 5.79961 22 7.19974 22 10V14C22 16.8003 22 18.2004 21.455 19.27C20.9757 20.2108 20.2108 20.9757 19.27 21.455C18.2004 22 16.8003 22 14 22H10C7.19974 22 5.79961 22 4.73005 21.455C3.78924 20.9757 3.02433 20.2108 2.54497 19.27C2 18.2004 2 16.8003 2 14V10Z",fill:"currentColor"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.96644 1.25C8.59472 1.25 7.51929 1.24999 6.65494 1.32061C5.77479 1.39252 5.04768 1.54138 4.38955 1.87671C3.30762 2.42798 2.42798 3.30762 1.87671 4.38955C1.54138 5.04768 1.39252 5.77479 1.32061 6.65494C1.24999 7.51929 1.25 8.59472 1.25 9.96644V14.0336C1.25 15.4053 1.24999 16.4807 1.32061 17.3451C1.39252 18.2252 1.54138 18.9523 1.87671 19.6104C2.42798 20.6924 3.30762 21.572 4.38955 22.1233C5.04768 22.4586 5.77479 22.6075 6.65494 22.6794C7.51927 22.75 8.59469 22.75 9.96637 22.75H14.0336C15.4053 22.75 16.4807 22.75 17.3451 22.6794C18.2252 22.6075 18.9523 22.4586 19.6104 22.1233C20.6924 21.572 21.572 20.6924 22.1233 19.6104C22.4586 18.9523 22.6075 18.2252 22.6794 17.3451C22.75 16.4807 22.75 15.4053 22.75 14.0336V9.96642C22.75 8.59473 22.75 7.51927 22.6794 6.65494C22.6075 5.77479 22.4586 5.04768 22.1233 4.38955C21.572 3.30762 20.6924 2.42798 19.6104 1.87671C18.9523 1.54138 18.2252 1.39252 17.3451 1.32061C16.4807 1.24999 15.4053 1.25 14.0336 1.25H9.96644ZM5.07054 3.21322C5.48197 3.00359 5.9897 2.87996 6.77708 2.81563C7.57322 2.75058 8.58749 2.75 10 2.75H14C15.4125 2.75 16.4268 2.75058 17.2229 2.81563C18.0103 2.87996 18.518 3.00359 18.9295 3.21322C19.7291 3.62068 20.3793 4.27085 20.7868 5.07054C20.9964 5.48197 21.12 5.9897 21.1844 6.77708C21.2494 7.57322 21.25 8.58749 21.25 10V14C21.25 15.4125 21.2494 16.4268 21.1844 17.2229C21.12 18.0103 20.9964 18.518 20.7868 18.9295C20.3793 19.7291 19.7291 20.3793 18.9295 20.7868C18.518 20.9964 18.0103 21.12 17.2229 21.1844C16.4268 21.2494 15.4125 21.25 14 21.25H10C8.58749 21.25 7.57322 21.2494 6.77708 21.1844C5.9897 21.12 5.48197 20.9964 5.07054 20.7868C4.27085 20.3793 3.62068 19.7291 3.21322 18.9295C3.00359 18.518 2.87996 18.0103 2.81563 17.2229C2.75058 16.4268 2.75 15.4125 2.75 14V10C2.75 8.58749 2.75058 7.57322 2.81563 6.77708C2.87996 5.9897 3.00359 5.48197 3.21322 5.07054C3.62068 4.27085 4.27085 3.62068 5.07054 3.21322Z",fill:"currentColor"}),(0,a.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18.6749 8.04877L17.1069 9.06975L16.2884 7.81273L17.8564 6.79175L18.6749 8.04877ZM15.2278 10.2932L13.3488 11.5167L12.5303 10.2597L14.4093 9.03622L15.2278 10.2932ZM11.4697 12.7402L9.59064 13.9637L8.77217 12.7067L10.6512 11.4832L11.4697 12.7402ZM7.71158 15.1872L6.14354 16.2082L5.32507 14.9511L6.89311 13.9302L7.71158 15.1872Z",fill:"currentColor"})]}),to=["linear","exponential","quadratic","polynomial","logarithmic","power","loess"],v1="linear",x1=({title:e,layout:t="collapsible",preview:n})=>{const r=v.usePanelGraph(),o=c.useHandleScene(r),i=c.useI18n(),{Select:s,Switch:l}=v.useControls(),{options:h,findValue:u}=dt(o,r.formattingLocale);if(!o||o.coordSystem.type==="polar")return null;const p=(0,d.findTrendLineLayer)(o.spec.layers),g=(0,d.findAverageLineLayer)(o.spec.layers),m=p?.stat.type==="smooth"?p.stat.method:v1,f=f1(g),x=to.map(A=>({value:A,label:i(`editor.annotationsPanel.trendType.options.${A}`)})),y=(A,T={})=>{const M=p??g,G=new d.SetStatLineCommand({line:A,...T,...M!==void 0&&{layerId:M.id},label:i("editor.annotationsPanel.trendsAndAveragesSection.average")});r.commands.dispatch(G)},w=A=>y(A?"trend":"none",{method:m}),S=A=>y(A?"average":"none",{group:f??u(h[0]?.value??"")}),I=A=>{const T=to.find(M=>M===A);T!==void 0&&y("trend",{method:T})},j=A=>{const T=A===null?void 0:u(A);T!==void 0&&y("average",{group:T})};return(0,a.jsx)(q,{title:e??i("editor.annotationsPanel.trendsAndAveragesSection.title"),layout:t,preview:n??(0,a.jsx)(eo,{size:"lg"}),children:(0,a.jsxs)(Z,{children:[(0,a.jsx)(N,{label:i("editor.annotationsPanel.trendsAndAveragesSection.trend"),icon:(0,a.jsx)(eo,{size:"lg"}),children:(0,a.jsx)(l,{checked:p!==void 0,onChange:w})}),p!==void 0&&(0,a.jsx)(N,{label:i("editor.annotationsPanel.trendType.label"),children:(0,a.jsx)(s,{value:m,options:x,onChange:I,placeholder:i("editor.annotationsPanel.trendType.placeholder")})}),(0,a.jsx)(N,{label:i("editor.annotationsPanel.trendsAndAveragesSection.average"),icon:(0,a.jsx)(m1,{size:"lg"}),children:(0,a.jsx)(l,{checked:g!==void 0,onChange:S})}),g!==void 0&&h.length>0&&(0,a.jsx)(N,{label:i("editor.annotationsPanel.averageLineSeries.label"),children:(0,a.jsx)(s,{value:f===void 0?null:String(f),options:h,onChange:j,placeholder:i("editor.annotationsPanel.averageLineSeries.placeholder"),ariaLabel:i("editor.annotationsPanel.averageLineSeries.ariaLabel")})})]})})},f1=e=>{const t=e?.transforms.find(n=>n.transformType==="filter")?.options.value;return t instanceof Date?t.getTime():t};exports.AppearanceSection=pg;exports.AxesPanel=cg;exports.AxisEditMenu=tn;exports.AxisSection=tt;exports.BarEditMenu=nn;exports.BarSection=xg;exports.Button=v.Button;exports.CalloutsSection=kg;exports.CaptionSection=qa;exports.ChartEditMenu=sn;exports.ColorRow=re;exports.ColorSwatches=v.ColorSwatches;exports.ComboSection=Eg;exports.ControlRegistryProvider=v.ControlRegistryProvider;exports.ControlTooltip=v.ControlTooltip;exports.CustomColor=v.CustomColor;exports.DateField=v.DateField;exports.EditableGraphRenderer=Op;exports.EditorIntlProvider=pn;exports.EditorPanel=An;exports.ElementsPanel=lg;exports.FileInput=v.FileInput;exports.GoalSection=Rg;exports.GraphOptionsSection=Dg;exports.GraphTypeSection=Gg;exports.GridEditMenu=ln;exports.GridSection=Bg;exports.HeadlineSection=Wg;exports.LegendEditMenu=Ao;exports.LegendSection=Ug;exports.LineEditMenu=it;exports.LineSection=Yg;exports.MappingSection=Qg;exports.NumberField=v.NumberField;exports.NumberFormatSection=i1;exports.PANEL_ROOT_ATTRIBUTE=Va;exports.PaletteRow=So;exports.PointEditMenu=un;exports.PointSection=l1;exports.PolarSection=g1;exports.RadioGrid=v.RadioGrid;exports.Row=N;exports.Section=q;exports.Select=v.Select;exports.Separator=Kp;exports.Slider=v.Slider;exports.SourceSection=Ya;exports.Stepper=v.Stepper;exports.SubtitleSection=Za;exports.Switch=v.Switch;exports.TextField=v.TextField;exports.TextSizeSection=Ja;exports.TitleSection=Qa;exports.ToggleGroup=v.ToggleGroup;exports.ToggledSection=Ua;exports.TrendsAndAveragesSection=x1;exports.useAnnotateAnchor=ro;exports.useControls=v.useControls;exports.usePanelExpansion=Wa;exports.usePanelGraph=v.usePanelGraph;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./editable.css');const l=require("./history-chords-B2-10FJz.cjs"),h=require("./start-arrow-button-B1mfKZVJ.cjs");let p=require("@graphysdk/viz-engine"),w=require("react"),s=require("react/jsx-runtime"),J=require("zustand/react/shallow"),q=require("lodash-es"),te=require("@vanilla-extract/dynamic"),Ke=require("clsx");Ke=l.__toESM(Ke,1);let Gr=require("react-dom"),Br=require("@base-ui/react/popover"),An=require("@base-ui/react/direction-provider"),de=require("@base-ui/react/accordion"),Hr=require("@base-ui/react/separator");var zr={"en-GB":()=>Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs")).then(e=>({"en-GB":e.EDITOR_EN_GB})),"en-US":()=>Promise.all([Promise.resolve().then(()=>require("./en-us-CfL-X7mL.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({"en-US":e.EDITOR_EN_US,"en-GB":t.EDITOR_EN_GB})),ar:()=>Promise.all([Promise.resolve().then(()=>require("./ar-DRJfF3kx.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({ar:e.EDITOR_AR,"en-GB":t.EDITOR_EN_GB})),"pt-PT":()=>Promise.all([Promise.resolve().then(()=>require("./pt-pt-Dl-e1WyP.cjs")),Promise.resolve().then(()=>require("./en-gb-wV0MmZLj.cjs"))]).then(([e,t])=>({"pt-PT":e.EDITOR_PT_PT,"en-GB":t.EDITOR_EN_GB}))},$e=new Map,De=new Map,Ct=e=>$e.get(e)??null,Wr=e=>{const t=$e.get(e);if(t!==void 0)return Promise.resolve(t);const n=De.get(e);if(n!==void 0)return n;const r=zr[e]().then(o=>($e.set(e,o),o)).catch(o=>{throw De.delete(e),o});return De.set(e,r),r},Vr=e=>{const[,t]=(0,w.useState)(null);return(0,w.useEffect)(()=>{if(Ct(e)!==null)return;let n=!1;return Wr(e).then(()=>{n||t(e)},r=>{console.error(r)}),()=>{n=!0}},[e]),Ct(e)},st=({children:e,locale:t,...n})=>{const r=Vr(l.normalizeLocale(t));return(0,s.jsx)(l.IntlProvider,{dictionaries:(0,w.useMemo)(()=>r===null?[l.dictionaries]:[r,l.dictionaries],[r]),locale:t,...n,children:(0,s.jsx)(Ur,{children:e})})},Ur=({children:e})=>(0,s.jsx)(An.DirectionProvider,{direction:l.useTextDirection(),children:e}),Xr={Title:null,Caption:null,TextAnnotation:null},Kr=(e,t)=>t===null?Xr:l.MODE_RULES[e].editTextInline?{Title:t.TitleEditor,Caption:t.CaptionEditor,TextAnnotation:t.TextAnnotationEditor}:{Title:null,Caption:null,TextAnnotation:t.TextAnnotationEditor},Ce=null,Fe=null,$r=()=>Ce!==null?Promise.resolve(Ce):(Fe??=Promise.resolve().then(()=>require("./rich-text-editor-module-q1jI1hQi.cjs")).then(e=>(Ce=e,e)).catch(e=>{throw Fe=null,e}),Fe),Pn=()=>{const[e,t]=(0,w.useState)(Ce);return(0,w.useEffect)(()=>{let n=!1;return $r().then(r=>{n||t(r)},r=>{console.error(r)}),()=>{n=!0}},[]),e},Yr=({children:e})=>{const t=l.useEditorStore();return(0,s.jsx)(l.RememberTextCaretProvider,{remember:(0,w.useCallback)((n,r)=>{t.getState().setPendingTextCaret({slot:n,x:r.clientX,y:r.clientY})},[t]),children:e})},qr="_10igzta0",Zr=({rect:e,zIndex:t,container:n,boxRef:r,children:o,...a})=>n===null?null:(0,Gr.createPortal)((0,s.jsx)("div",{...a,ref:r,className:qr,style:{transform:`translate(${e.left}px, ${e.top}px)`,width:e.width,height:e.height,zIndex:t},children:o}),n),ie=(e,t)=>{const n=l.useSceneSelector((0,J.useShallow)(i=>({spec:i.spec.annotations,compiled:i.annotations,layers:i.layers,coordSystem:i.coordSystem}))),r=l.useResolvedAnnotations(e),o=l.useMeasuredBoxes(),a=l.usePaintedObservationBoxes(e);return l.useLatestRef({...n,scene:r,panelRect:e,frameElement:t,measuredBoxes:o,readObservationBox:a})},Jr=({drop:e,startRect:t,size:n,panelRect:r,bounds:o})=>{const a=(0,p.readFacingAlign)({x:e.x,y:e.y,width:0,height:0},t),i=a==="center"?"left":a,d=(0,p.readOutwardGapOffset)(i,p.ARROW_TARGET_GAP_PX),u=(0,p.alignUnitFractions)(i),c=e.x-(d?.x??0)-u.x*n.width,g=e.y-(d?.y??0)-u.y*n.height;return{align:i,rect:{x:Tt(c,n.width,o.minX*r.width,o.maxX*r.width),y:Tt(g,n.height,o.minY*r.height,o.maxY*r.height),...n}}},Qr=({rect:e},t,n)=>{const r=(0,p.alignUnitFractions)(t);return{x:(e.x+r.x*e.width)/n.width,y:(e.y+r.y*e.height)/n.height}},Tt=(e,t,n,r)=>Math.max(n,Math.min(e,r-t)),Te=(e,t,n)=>e.arrows.find(r=>r.id===t)?.[n]??null,In=(e,t,n)=>{const r=Te(e,t,n);return r?.anchorType==="panel"?r:null},En=(e,t)=>e==="start"?{start:t}:{end:t},jn=(e,t,n)=>{const{scene:r,panelRect:o,measuredBoxes:a,readObservationBox:i}=n;if(e.anchorType==="annotation"){const c=(0,p.indexSceneAnnotations)(r).get(e.ref),g=c===void 0?null:(0,p.readAnnotationBox)(c,o,a);return g===null?null:(0,p.projectBoxToPanel)(g,o)}if(e.anchorType!=="observation"||e.layerId===void 0||t===void 0)return null;const d={layerId:e.layerId,observationIndex:t};if(e.align==="auto")return eo(d,n);const u=i(d);return u===null?null:(0,p.projectBoxToPanel)(u,o)},it=(e,t,n)=>{const r=(0,p.projectAnchorToPanel)(t,n.panelRect),o={x:r.x,y:r.y,width:0,height:0};return!("align"in e)||e.align!=="auto"?o:jn(e,t.observationIndex,n)??o},eo=({layerId:e,observationIndex:t},{panelRect:n,layers:r,coordSystem:o,readObservationBox:a,anchorResolver:i})=>{const d=r.find(x=>x.id===e),u=o.type==="polar"||d!==void 0&&(0,p.isPointTarget)(i.resolveSnapAligns(d.geom,o))?null:a({layerId:e,observationIndex:t}),c=u===null?null:(0,p.projectBoxToPanel)(u,n);if(c!==null&&c.width>0&&c.height>0)return c;const g=d?.data.getAt(t)??null;if(d===void 0||g===null)return c;const m=i.resolve(d.geom,g,{coordSystem:o,position:d.position,purpose:"pin"});if(m===null)return c;const v=(0,p.projectAnchorToPanel)(m,n);return{x:v.x,y:v.y,width:0,height:0}};var he={fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round"},to=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 24 24",...e,children:(0,s.jsx)("path",{d:"M5 6V4h14v2M12 4v16M9 20h6",...he})}),no=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 24 24",...e,children:(0,s.jsx)("path",{d:"M5 4h14v10l-6 6H5zM13 20v-6h6",...he})}),ro=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 24 24",...e,children:(0,s.jsx)("path",{d:"M5 19L19 5M10 5h9v9",...he})}),oo=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 24 24",...e,children:(0,s.jsx)("path",{d:"M4 6h16v12H4z",...he})}),ao=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 24 24",...e,children:(0,s.jsx)("path",{d:"M12 3a9 9 0 1 0 0 18 9 9 0 1 0 0-18zM8.5 14.5s1.3 2 3.5 2 3.5-2 3.5-2M9 9.5h.01M15 9.5h.01",...he})}),oe={side:"top",delay:200},Ne=.2,so={type:"doc",content:[{type:"paragraph"}]},At={paddingInline:12,paddingBlock:10},io=24,lo=({frameElement:e,panelRect:t})=>{const n=l.useEditorState(r=>r.plotMenu);return n===null?null:(0,s.jsx)(co,{frameElement:e,panelRect:t,point:n},`${n.x}:${n.y}:${n.arrowId??""}`)},co=({frameElement:e,panelRect:t,point:n})=>{const r=l.useI18n(),o=l.useEditorStore(),{commands:a,history:i,selectionStore:d,anchorResolver:u}=l.useGraphContext(),{Button:c,ColorSwatches:g}=h.useControls(),m=h.useCanvasColorNames(),v=h.usePaletteColors(),x=h.usePlaceholderWidthFit(),[f,y]=(0,w.useState)({kind:"choose"}),C=l.useEditorState(L=>L.standingInteraction?.kind==="box-draw"),S=l.useEditorState(L=>L.standingInteraction?.kind==="arrow-draw"),b=!C&&!S,T=n.arrowId,E=ie(t,e),A=l.useStyleReaderTree().graph().get("textScale"),M=l.useSceneSelector(L=>T===void 0||L.spec.annotations.arrows.some(D=>D.id===T)),N=()=>{ae(o),o.getState().setPlotMenu(null),T!==void 0&&d.getState().setSelection([{kind:"annotation",id:T}])};(0,w.useEffect)(()=>{M||o.getState().setPlotMenu(null)},[M,o]);const G=(L,D)=>{const B={at:{anchorType:"panel",x:n.x,y:n.y}};if(T===void 0)return B;const z=E.current,V=z.spec.arrows.find(H=>H.id===T),K=z.scene.arrows.find(H=>H.id===T);if(V===void 0||K===void 0)return B;const Z=Jr({drop:{x:n.x*t.width,y:n.y*t.height},startRect:it(V.start,K.start,{...z,anchorResolver:u}),size:L,panelRect:t,bounds:h.readContainerFractionBoundsFor(t,e)}),Q=D??Z.align;return{at:{anchorType:"panel",...Qr(Z,Q,t)},align:Q}},R=(L,D=[])=>{const B=[L,...D];T!==void 0&&B.push(new p.UpdateAnnotationCommand({kind:"arrow",id:T,patch:{end:{anchorType:"annotation",ref:L.params.annotation.id,align:"auto"}}})),a.dispatch(B.length===1?L:new p.SequenceCommand({commands:B}))};(0,w.useEffect)(()=>()=>ae(o),[o]);const j={x:t.x+n.x*t.width,y:t.y+n.y*t.height,width:1,height:1},P={top:{from:j.x,to:j.x+j.width},bottom:{from:j.x,to:j.x+j.width},left:{from:j.y,to:j.y+j.height},right:{from:j.y,to:j.y+j.height}},k=L=>{ae(o),y(D=>D.kind===L?{kind:"choose"}:{kind:L})},O=L=>(...D)=>{o.getState().claimInteraction({kind:"arrow-draw",heads:L,start:{anchorType:"panel",x:n.x,y:n.y},pointer:l.readClickPoint(D[0])})},I=(...L)=>{if(o.getState().standingInteraction?.kind==="box-draw"){o.getState().releaseInteraction("box-draw");return}ae(o),y({kind:"choose"}),o.getState().claimInteraction({kind:"box-draw",start:n,pointer:l.readClickPoint(L[0])})},F=L=>{ae(o);const{at:D,align:B}=G({width:Ne*t.width,height:io}),z=new p.AddAnnotationCommand({kind:"text",annotation:{...p.TEXT_ANNOTATION_DEFAULTS,content:so,at:D,...B!==void 0&&{align:B},width:Ne}}),V=z.params.annotation.id,K=x({annotationId:V,anchorX:D.x,align:B??p.TEXT_ANNOTATION_DEFAULTS.align,panelWidth:t.width,minWidth:Ne,paddingInline:L===null?void 0:At.paddingInline}),Z=new p.AddAnnotationCommand({kind:"text",annotation:{...z.params.annotation,width:K}}),Q=L===null?[]:[new p.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"annotation",kind:"text",annotation:V},declarations:{fill:L,...At}}})];R(Z,Q),d.getState().setSelection([{kind:"annotation",id:V}]),o.getState().setCaret(V,i.stack.getSnapshot().undoStack.at(-1)?.id??null),o.getState().setPlotMenu(null)},W=L=>{const D=l.readStickerSize(L,A);if(D===null)return;const{at:B}=G(D,"center"),z=new p.AddAnnotationCommand({kind:"sticker",annotation:{at:B,sticker:L}});R(z),ae(o),o.getState().setPlotMenu(null)};return(0,s.jsxs)(s.Fragment,{children:[T===void 0&&(0,s.jsx)("span",{className:"_1vbfegu3",style:{left:j.x,top:j.y},"data-testid":"empty-plot-dot","aria-hidden":!0}),b&&(0,s.jsx)(h.AnchoredPopover,{frameElement:e,boundary:j,spans:P,onEscape:N,children:(0,s.jsxs)("div",{className:"vez73g0 _1vbfegu0",role:"toolbar","aria-label":r("graph.annotations.baseMenu.annotate"),onKeyDown:h.moveStripFocus,children:[(0,s.jsxs)("div",{className:"vez73g1",children:[(0,s.jsx)(c,{variant:"icon",...oe,ariaLabel:r("graph.annotations.baseMenu.text"),icon:(0,s.jsx)(to,{}),onClick:()=>F(null)}),(0,s.jsx)(c,{variant:"icon",...oe,ariaLabel:r("graph.annotations.baseMenu.stickyNote"),icon:(0,s.jsx)(no,{}),expanded:f.kind==="sticky",onClick:()=>k("sticky")}),T===void 0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c,{variant:"icon",...oe,ariaLabel:r("graph.annotations.baseMenu.arrow"),icon:(0,s.jsx)(ro,{}),expanded:f.kind==="arrow",onClick:()=>k("arrow")}),(0,s.jsx)(c,{variant:"icon",...oe,ariaLabel:r("graph.annotations.baseMenu.box"),icon:(0,s.jsx)(oo,{}),expanded:C,onClick:I})]}),(0,s.jsx)(c,{variant:"icon",...oe,ariaLabel:r("graph.annotations.baseMenu.addSticker"),icon:(0,s.jsx)(ao,{}),expanded:f.kind==="sticker",onClick:()=>k("sticker")})]}),f.kind==="sticky"&&(0,s.jsxs)("div",{className:"vez73g2 _1vbfegu1",children:[(0,s.jsx)(g,{title:r("graph.colorDropdown.colors"),colors:h.CANVAS_COLOR_PRESETS,names:m,value:null,onChange:F,...oe}),v.length>0&&(0,s.jsx)(g,{title:r("graph.colorDropdown.chartColors"),colors:v,value:null,onChange:F})]}),f.kind==="sticker"&&(0,s.jsx)(uo,{onPick:W}),f.kind==="arrow"&&(0,s.jsxs)("div",{className:"vez73g4",children:[(0,s.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowOneWay"),onClick:O("end"),children:(0,s.jsx)(h.ArrowOneWayIcon,{})}),(0,s.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowTwoWay"),onClick:O("both"),children:(0,s.jsx)(h.ArrowTwoWayIcon,{})}),(0,s.jsx)("button",{type:"button",className:"_1vbfegu2","aria-label":r("graph.annotations.baseMenu.arrowLine"),onClick:O("none"),children:(0,s.jsx)(h.ArrowLineIcon,{})})]})]})})]})},uo=({onPick:e})=>{const t=l.useStickerImages();return t===null?null:(0,s.jsx)("div",{className:h.choices,children:Object.entries(t).map(([n,r])=>(0,s.jsx)("button",{type:"button",className:h.stickerButton,"aria-label":n,onClick:()=>e(n),children:(0,s.jsx)("img",{className:h.stickerImage,src:r,alt:""})},n))})},ae=e=>{const t=e.getState().standingInteraction?.kind;(t==="arrow-draw"||t==="box-draw")&&e.getState().releaseInteraction(t)},ge=e=>e.offset+e.strokeWidth,Pt="http://www.w3.org/2000/svg",It=new WeakMap,ho=(e,t)=>{const n=go(e);n.setAttribute("d",t);const{x:r,y:o,width:a,height:i}=n.getBBox();return{x:r,y:o,width:a,height:i}},go=e=>{const t=It.get(e);if(t?.isConnected)return t;const n=e.createElementNS(Pt,"svg");n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none";const r=e.createElementNS(Pt,"path");return n.append(r),e.body.append(n),It.set(e,r),r},po=(e,t)=>{const{panelRect:n,look:r,readGridLineWidth:o}=t,a=ge(r);switch(e.kind){case"observations":return Ge([...e.parts,...e.vertex===null?[]:[e.vertex]].flatMap(i=>mo(i,t,a)).map(i=>({...i,x:i.x+n.x,y:i.y+n.y})),0);case"guide":return Ge(e.shapes.map(i=>i.kind==="box"?i.rect:l.growRect(yo(i),o(i.axis)/2)),a);case"graph":return Ge([{x:0,y:0,...e.frameSize}],-r.offset);default:return e}},mo=(e,{measurePathBox:t,coordSystem:n,panelRect:r},o)=>{const a=xo(e,t).map(d=>l.growRect(d,o)),i=l.buildOverflowClipRect((0,p.findOverflowedPanelEdges)(e.layer,n),r);return a.flatMap(d=>vo(d,i))},vo=(e,t)=>{const n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return o<=n||a<=r?[]:[{x:n,y:r,width:o-n,height:a-r}]},xo=(e,t)=>e.kind==="boxes"?e.boxes:fo(e.shapes,t),fo=(e,t)=>{const n=[],r=new Map;for(const o of e){if(o.kind==="dots"){n.push(...o.centers.map(d=>l.growRect({...d,width:0,height:0},o.size/2)));continue}if(o.pathData==="")continue;const a=o.kind==="stroke"?o.width/2:0;if(!o.pathData.trimStart().startsWith("M")){n.push(l.growRect(t(o.pathData),a));continue}const i=r.get(a)??[];i.push(o.pathData),r.set(a,i)}for(const[o,a]of r)n.push(l.growRect(t(a.join("")),o));return n},yo=e=>{switch(e.kind){case"line":return{x:Math.min(e.from.x,e.to.x),y:Math.min(e.from.y,e.to.y),width:Math.abs(e.to.x-e.from.x),height:Math.abs(e.to.y-e.from.y)};case"ring":return{x:e.center.x-e.radius,y:e.center.y-e.radius,width:e.radius*2,height:e.radius*2}}},Ge=(e,t)=>{const n=e.filter(({width:r,height:o})=>r>0||o>0);return n.length===0?null:l.growRect((0,p.getBoundingRect)(n),t)};var So=(e,{coordSystem:t,panelRect:n})=>{if(e.kind!=="observations")return null;const r=e.vertex===null?e.parts:[...e.parts,e.vertex],o=r.reduce((i,d)=>Math.max(i,d.rows.length),0),a=o===1&&e.vertex===null;return o===0||a||o>1e3?null:r.flatMap(i=>wo(i,t,n).map(d=>({...d,x:d.x+n.x,y:d.y+n.y})))},wo=(e,t,n)=>(0,p.measureObservationsBoxes)({layer:{...e.layer,data:e.layer.data.take(e.rows)},coordSystem:t,panelSize:n,radialExtent:"outerEnd"}),bo=.5,Co={top:e=>-e.y,right:e=>e.x+e.width,bottom:e=>e.y+e.height,left:e=>-e.x},To=(e,t,n)=>e===null||!Ao(e)?{top:Ye(t),right:qe(t),bottom:Ye(t),left:qe(t)}:{top:fe(e,t,"top",n),right:fe(e,t,"right",n),bottom:fe(e,t,"bottom",n),left:fe(e,t,"left",n)},fe=(e,t,n,r)=>{const o=Co[n],a=n==="left"||n==="right",i=f=>a?f.y:f.x,d=f=>a?f.y+f.height:f.x+f.width;let u=-1/0;for(const f of e)u=Math.max(u,o(f));const c=u-Math.max(r,bo);let g=1/0,m=-1/0;for(const f of e)o(f)<c||(g=Math.min(g,i(f)),m=Math.max(m,d(f)));const v=a?qe(t):Ye(t),x={from:(0,q.clamp)(g-r,v.from,v.to),to:(0,q.clamp)(m+r,v.from,v.to)};return x.from<x.to?x:v},Ao=e=>{const[t]=e;return t!==void 0&&e.some(n=>!l.areRectsEqual(n,t))},Ye=e=>({from:e.x,to:e.x+e.width}),qe=e=>({from:e.y,to:e.y+e.height}),Po=(e,{frameElement:t,panelRect:n,look:r})=>{const o=l.useEditorStore(),a=l.useStyleReaderTree(),i=l.useSceneSelector(m=>m.coordSystem),d=(0,w.useRef)(new Map),u=e?.target??null,c=e?.outline??null;(0,w.useLayoutEffect)(()=>{if(u===null||c===null)return;const m=d.current,v=new Map,f=po(c,{panelRect:n,look:r,readGridLineWidth:S=>l.readGridLineStyle(a,S).strokeWidth,measurePathBox:S=>{const b=m.get(S)??ho(t.ownerDocument,S);return v.set(S,b),b},coordSystem:i});if(d.current=v,f===null){o.getState().setSelectedOutline(null);return}const y=To(So(c,{coordSystem:i,panelRect:n}),f,ge(r)),C=h.measureFrameScale(t);o.getState().setSelectedOutline({target:u,frame:f,frameSpans:y,frameScale:C})},[o,a,i,u,c,t,n,r]);const g=e!==null;(0,w.useLayoutEffect)(()=>g?()=>o.getState().setSelectedOutline(null):void 0,[o,g])},lt="var(--_1qfw3e00)",Io="_1qfw3e01",Eo="_1qfw3e02",Et=({pathData:e,animateTransitions:t,source:n,...r})=>t?(0,s.jsx)(jo,{pathData:e,source:n,...r}):(0,s.jsx)("path",{d:e,...r}),jo=({pathData:e,source:t,...n})=>(0,s.jsx)(l.AnimatedPath,{d:l.useSvgPathMorph(e,l.DEFAULT_SPRING_TRANSITION,t),...n}),ko="var(--dppmab0)",Ro="data-edit-outline-stroke",kn=e=>({[Ro]:"",style:(0,te.assignInlineVars)({[ko]:`${e}px`})}),Lo=()=>{const{showMenuTriggerOnHover:e,layers:t,coordSystem:n,parsingLocale:r,anchorResolver:o,geom:a,hasOverlayMenu:i}=Rn(),d=l.useHoverState(u=>e?u.hover.primary:null);return(0,w.useMemo)(()=>{if(d===null)return null;const u=t.find(g=>g.id===d.layerId);if(u===void 0||h.isBoxplotOutlier(u,d.observation))return null;const c=(0,p.buildObservationsTarget)({layer:u,observationIndex:(0,p.readObservationIndex)(d),scope:"observation",parsingLocale:r});return c===null||!i(c)?null:Ln({layer:u,observation:d.observation,target:c,coordSystem:n,anchorResolver:o,geom:a,purpose:"pin"})},[d,t,n,r,o,a,i])},Oo=()=>Mo("pin"),Mo=e=>{const{showMenuTriggerOnHover:t,layers:n,coordSystem:r,parsingLocale:o,anchorResolver:a,geom:i,hasOverlayMenu:d}=Rn(),[u]=l.useGraphSelection(),c=u?.kind==="observations"&&u.scope==="observation"?u:null;return(0,w.useMemo)(()=>{if(!t||c===null||!d(c))return null;const g=n.find(x=>x.id===c.layerId);if(g===void 0)return null;const[m]=(0,p.resolveObservationsTarget)({layer:g,target:c,parsingLocale:o}),v=m===void 0?void 0:g.data.getAt(m);return v==null||h.isBoxplotOutlier(g,v)?null:Ln({layer:g,observation:v,target:c,coordSystem:r,anchorResolver:a,geom:i,purpose:e})},[t,c,d,n,o,r,a,i,e])},Rn=()=>{const{showMenuTriggerOnHover:e}=l.MODE_RULES[l.useGraphMode()],t=l.useSceneSelector((0,J.useShallow)(a=>({layers:a.layers,coordSystem:a.coordSystem,parsingLocale:a.config.parsingLocale}))),{anchorResolver:n}=l.useGraphContext(),r=l.useGeomReaderTree(),o=h.useHasOverlayMenu();return{showMenuTriggerOnHover:e,...t,anchorResolver:n,geom:r,hasOverlayMenu:o}},Ln=({layer:e,observation:t,target:n,coordSystem:r,anchorResolver:o,geom:a,purpose:i})=>{const d=o.resolve(e.geom,t,{coordSystem:r,position:e.position,purpose:i});return d===null?null:{position:d,color:(0,p.readGeomColor)({geom:a},e,t)??p.DEFAULT_GEOM_COLOR,target:n}},_o=()=>{const e=l.useGraphSelection()[0]??null,{layers:t,parsingLocale:n}=l.useSceneSelector((0,J.useShallow)(r=>({layers:r.layers,parsingLocale:r.config.parsingLocale})));return(0,w.useMemo)(()=>e===null?null:Do(e,t,n),[e,t,n])},On=(e,t,n)=>{const r=(0,p.findLayerById)(t,e.layerId);if(r===void 0)return null;const o=(0,p.resolveObservationsTarget)({layer:r,target:e,parsingLocale:n});if(o.length===0)return null;const a=[{layer:r,rows:o}];for(const i of(0,p.findCompanionLayers)(r,t)){const d=(0,p.resolveObservationsTarget)({layer:i,host:r,target:e,parsingLocale:n});d.length>0&&a.push({layer:i,rows:d})}return{kind:"observations",key:(0,p.readEditTargetKey)(e),layerId:e.layerId,scope:e.scope,parts:a,vertex:null}},Do=(e,t,n)=>{switch(e.kind){case"observations":{const r=On(e,t,n);return r===null?null:{outlined:r,target:e}}case"legend":case"axis":case"grid":return{outlined:{kind:"guide",key:(0,p.readEditTargetKey)(e),target:e},target:e};case"graph":return{outlined:{kind:"graph",key:"graph"},target:e};default:return null}},Fo=()=>{const e=Lo(),t=l.useHoverState(d=>d.hover.intersection?.intersects===!0),n=l.useGraphSelection()[0]??null,r=l.useEditorState(d=>d.standingInteraction),o=l.useEditorState(d=>d.plotMenu),{layers:a,parsingLocale:i}=l.useSceneSelector((0,J.useShallow)(d=>({layers:d.layers,parsingLocale:d.config.parsingLocale})));return(0,w.useMemo)(()=>!t||e===null||n!==null||r!==null||o!==null?null:On(e.target,a,i),[t,e,n,r,o,a,i])};var jt=(e,t)=>{if(e.kind==="observations"&&t.kind==="observations"){if(e.layerId!==t.layerId||e.scope!==t.scope)return!1;const n=e.parts[0]?.rows[0];return n!==void 0&&(t.parts[0]?.rows.includes(n)??!1)}return e.kind==="guide"&&t.kind==="guide"?(0,p.areEditTargetsEqual)(e.target,t.target):e.kind==="graph"&&t.kind==="graph"},No=(e,t)=>{const n=Math.max(e.width,8),r=Math.max(e.height,8),o=Math.max(0,e.x+e.width/2-n/2),a=Math.max(0,e.y+e.height/2-r/2),i=Math.min(t.width,e.x+e.width/2+n/2),d=Math.min(t.height,e.y+e.height/2+r/2);return{x:o,y:a,width:Math.max(0,i-o),height:Math.max(0,d-a)}},Go=[],Bo=e=>{const{layers:t,parsingLocale:n}=l.useSceneSelector((0,J.useShallow)(v=>({layers:v.layers,parsingLocale:v.config.parsingLocale}))),r=l.useEditorState(v=>v.editTargetUnderPointer),o=r?.kind==="observations"?r.observations:null,a=o===null?void 0:(0,p.findLayerById)(t,o.layerId),i=o?.target.scope??null,d=o===null||a===void 0?null:(0,p.readRowScopeKey)(a,o.target.scope,o.observationIndex),u=(0,w.useMemo)(()=>a===void 0||i===null||d===null?null:Ho(t,a,i,d),[t,a,i,d]),c=(0,w.useMemo)(()=>u!==null&&e!==null&&jt(u,e),[u,e]),g=h.useHasOverlayMenu(),m=o!==null&&a!==void 0&&zo(o,a,n,g)?o.observationIndex:null;return(0,w.useMemo)(()=>{switch(r?.kind){case"observations":{const v=u?.parts[0];if(u===null||v===void 0)return null;const x=m===null?null:{layer:v.layer,rows:[m]};return c?x===null?null:{...u,parts:Go,vertex:x}:{...u,vertex:x}}case"axis":case"legend":case"grid":{const v={kind:"guide",key:(0,p.readEditTargetKey)(r.target),target:r.target};return e!==null&&jt(v,e)?null:v}default:return null}},[r,u,c,m,e])},Ho=(e,t,n,r)=>{const o=[{layer:t,rows:(0,p.readRowsAtScopeKey)(t,n,r)}];for(const a of(0,p.findCompanionLayers)(t,e)){const i=(0,p.readCompanionRowsAtScopeKey)(a,t,n,r);i.length>0&&o.push({layer:a,rows:i})}return{kind:"observations",key:JSON.stringify([t.id,n,r]),layerId:t.id,scope:n,parts:o,vertex:null}},zo=({observationIndex:e,target:t,onObservation:n},r,o,a)=>{if(!n||t.scope!=="group")return!1;const i=(0,p.buildObservationsTarget)({layer:r,observationIndex:e,scope:"observation",parsingLocale:o});return i!==null&&a(i)},Wo=({frameElement:e,target:t,coordType:n,legendDisplays:r})=>{const o=e.getBoundingClientRect(),a=[...e.querySelectorAll(Vo(t))],i=d=>{const u=d.getBoundingClientRect();return{x:u.left-o.left,y:u.top-o.top,width:u.width,height:u.height}};switch(t.kind){case"axis":{const d=a.map(i);return n==="polar"||d.length===0?Be(d):Be([(0,p.getBoundingRect)(d)])}case"legend":return Be([...Uo(a.filter(d=>!Xo(d)))].flatMap(([d,u])=>r[d]==="direct"?u.map(i):[(0,p.getBoundingRect)(u.map(i))]));case"grid":return a.flatMap(d=>{const u=l.readStampedEditTargetInStack([d],e);if(u?.kind!=="grid"||u.target.axis==="both")return[];const{axis:c}=u.target;return t.axis==="both"||c===t.axis?[Ko(d,i(d),c)]:[]})}},Vo=e=>{const t=`[${l.EDIT_TARGET_KIND_ATTRIBUTE}="${e.kind}"]`;return e.kind!=="axis"?t:`${t}[${l.EDIT_TARGET_AXIS_ATTRIBUTE}="${e.axis}"]`},Uo=e=>{const t=new Map;for(const n of e){const r=l.readLegendItemAddress(n);r!==null&&t.set(r.legendIndex,[...t.get(r.legendIndex)??[],n])}return t},Xo=e=>e.closest(l.LEGEND_OVERFLOW_CONTROL_SELECTOR)!==null,Be=e=>e.map(t=>({kind:"box",rect:t})),Ko=(e,{x:t,y:n,width:r,height:o},a)=>e.querySelector("circle")!==null?{kind:"ring",axis:a,center:{x:t+r/2,y:n+o/2},radius:r/2}:r<1||o<1?r<o?{kind:"line",axis:a,from:{x:t+r/2,y:n},to:{x:t+r/2,y:n+o}}:{kind:"line",axis:a,from:{x:t,y:n+o/2},to:{x:t+r,y:n+o/2}}:$o(e.querySelector("line"))?{kind:"line",axis:a,from:{x:t,y:n},to:{x:t+r,y:n+o}}:{kind:"line",axis:a,from:{x:t,y:n+o},to:{x:t+r,y:n}},$o=e=>{const t=n=>Number(e?.getAttribute(n)??0);return(t("x2")-t("x1"))*(t("y2")-t("y1"))>=0},Yo=[],qo=(e,{frameElement:t,frameSize:n,panelRect:r})=>{const{animateTransitions:o}=l.useGraphAnimation(),a=l.useSceneSelector(y=>y.coordSystem),i=l.useGeomRendererResolver(),d=l.useGeomReaderTree(),u=Jo(e.kind==="guide"?e.target:null,{frameElement:t,frameSize:n}),c=Zo(t,n),g=(0,w.useMemo)(()=>({coordSystem:a,panelRect:r,resolveRenderer:i,geomReaders:d}),[a,r,i,d]),m=e.kind==="observations"?e.parts:null,v=e.kind==="observations"?e.vertex:null,x=(0,w.useMemo)(()=>m?.map(y=>kt(y,g,o))??Yo,[m,g,o]),f=(0,w.useMemo)(()=>v===null?null:kt(v,g,!1),[v,g]);return(0,w.useMemo)(()=>{switch(e.kind){case"observations":return{kind:"observations",parts:x,vertex:f};case"guide":return{kind:"guide",target:e.target,shapes:u};case"graph":return{kind:"graph",frameSize:c}}},[e,x,f,u,c])},Zo=(e,t)=>{const[n,r]=(0,w.useState)(()=>h.readFrameLayoutSize(e,t));return(0,w.useLayoutEffect)(()=>{r(o=>{const a=h.readFrameLayoutSize(e,{width:t.width,height:t.height});return o.width===a.width&&o.height===a.height?o:a})},[e,t.width,t.height]),n},kt=({layer:e,rows:t},{coordSystem:n,panelRect:r,resolveRenderer:o,geomReaders:a},i)=>{const d={...e,data:e.data.take(t)},u=o(e.geom,n.type);return u?.getEditOutlineShapes===void 0?{kind:"boxes",layer:e,rows:t,boxes:(0,p.measureObservationsBoxes)({layer:d,coordSystem:n,panelSize:r}).map(c=>No(c,r))}:{kind:"declared",layer:e,rows:t,shapes:u.getEditOutlineShapes({layer:d,sourceLayer:e,coordSystem:n,panelRect:r,styleReaders:a(e),animateTransitions:i,symbols:u.symbols})}},Jo=(e,{frameElement:t,frameSize:n})=>{const r=l.useGuideSlidesSettledCount(e!==null),o=l.useSceneSelector(v=>v.coordSystem.type),a=l.useSceneSelector((0,J.useShallow)(v=>v.guides.legends.drawn.map(x=>x.display))),i=l.useSceneSelector(v=>e===null?null:v),[d,u]=(0,w.useState)([]),c=l.useLatestRef(e),g=(0,w.useRef)(!1),m=(0,w.useCallback)(()=>{const v=c.current;if(v===null)return;const x=Wo({frameElement:t,target:v,coordType:o,legendDisplays:a}),f=h.measureFrameScale(t);u(x.map(y=>Qo(y,1/f)))},[t,c,o,a]);return(0,w.useLayoutEffect)(()=>{if(c.current!==null){if(g.current){const v=requestAnimationFrame(m);return()=>cancelAnimationFrame(v)}g.current=!0,m()}},[m,c,i,n.width,n.height,r]),d},Qo=(e,t)=>{switch(e.kind){case"box":{const{x:n,y:r,width:o,height:a}=e.rect;return{kind:"box",rect:{x:n*t,y:r*t,width:o*t,height:a*t}}}case"line":return{...e,from:{x:e.from.x*t,y:e.from.y*t},to:{x:e.to.x*t,y:e.to.y*t}};case"ring":return{...e,center:{x:e.center.x*t,y:e.center.y*t},radius:e.radius*t}}},ea=["x","y"],ta=(0,w.memo)(function({frameElement:t,frameSize:n,panelRect:r}){const o=l.useResolvedStyle(p.resolveEditOutlineStyle,l.useStyleReaderTree()),a=_o(),i=Bo(a?.outlined??null),{selectObservationsOnPress:d,selectGraphOnPress:u,selectGuidesOnPress:c}=l.MODE_RULES[l.useGraphMode()],g=Fo(),m=d||u||c,v=m?i:g;if(a===null&&v===null)return null;const x={frameElement:t,frameSize:n,panelRect:r};return!m&&a!==null&&a.target.kind!=="observations"?(0,s.jsx)(He,{part:"selected",target:a.outlined,editTarget:a.target,look:o.selected,paints:!1,...x}):(0,s.jsxs)("svg",{className:Io,width:n.width,height:n.height,"aria-hidden":!0,"data-testid":"edit-outline",children:[v!==null&&(0,s.jsx)(He,{part:"hover",target:v,look:o.hover,paints:!0,...x},v.key),a!==null&&(0,s.jsx)(He,{part:"selected",target:a.outlined,editTarget:a.target,look:o.selected,paints:!0,...x},a.outlined.key)]})}),He=({part:e,target:t,editTarget:n,look:r,frameSize:o,panelRect:a,frameElement:i,paints:d})=>{const u=(0,w.useId)(),c=`${u}-shapes`,g=`${u}-hole`,m=qo(t,{frameElement:i,frameSize:o,panelRect:a});return Po(n===void 0?null:{target:n,outline:m},{frameElement:i,panelRect:a,look:r}),d?(0,s.jsxs)("g",{"data-edit-outline":e,"data-testid":`edit-outline-${e}`,children:[(0,s.jsxs)("defs",{children:[(0,s.jsx)("g",{id:c,className:Eo,children:(0,s.jsx)(ia,{outline:m,look:r,panelRect:a})}),(0,s.jsxs)("mask",{id:g,maskUnits:"userSpaceOnUse",x:"-100%",y:"-100%",width:"300%",height:"300%",children:[(0,s.jsx)("rect",{x:"-100%",y:"-100%",width:"300%",height:"300%",fill:"white"}),(0,s.jsx)("use",{href:`#${c}`,style:na(r.offset)})]})]}),(0,s.jsxs)("g",{mask:`url(#${g})`,"data-testid":`edit-outline-${e}-ring`,children:[(0,s.jsx)("use",{href:`#${c}`,style:ra(r)}),(0,s.jsx)("use",{href:`#${c}`,style:oa(r)})]}),t.kind==="observations"&&(0,s.jsx)(ga,{target:t,look:r,panelRect:a})]}):null},na=e=>({fill:"black",stroke:"black",strokeLinecap:"round",...(0,te.assignInlineVars)({[lt]:`${2*e}px`})}),ra=e=>({fill:"none",stroke:e.backingColor??l.vars.graphBackground,strokeLinecap:"round",opacity:e.backingAlpha,...(0,te.assignInlineVars)({[lt]:`${2*ge(e)}px`})}),oa=e=>{const t=(0,p.toStrokeDasharray)(e.dashArray,e.strokeWidth);return{fill:"none",stroke:e.stroke,strokeDasharray:t,strokeLinecap:t===void 0?"round":"butt",opacity:e.strokeAlpha,...(0,te.assignInlineVars)({[lt]:`${2*ge(e)}px`})}},aa=({dashArray:e,strokeWidth:t})=>{if((0,p.toStrokeDasharray)(e,t)===void 0)return;const n=(e.length%2===0?1:2)*e.reduce((r,o)=>r+o*t,0);return n>0?n:void 0},Mn=(e,t,n=1)=>{if(!(t===void 0||e<=0))return n*Math.max(1,Math.round(2*Math.PI*e/t))*t},sa=(e,t,n)=>{const r=n.offset+ge(n);return l.buildRoundedRectPath(l.growRect({x:0,y:0,...e},-r),Math.max(0,t-r))},ia=({outline:e,look:t,panelRect:n})=>{const r=l.useStyleReaderTree().graph().get("cornerRadius"),o=l.useSceneSelector(d=>d.coordSystem),{cornerRadius:a}=t,i=aa(t);switch(e.kind){case"observations":return(0,s.jsxs)("g",{transform:`translate(${n.x} ${n.y})`,children:[e.parts.map(d=>(0,s.jsx)(l.PanelOverflowClip,{layer:d.layer,coordSystem:o,panelSize:n,children:(0,s.jsx)(Rt,{part:d,borderRadius:a,dashPeriod:i})},d.layer.id)),e.vertex!==null&&(0,s.jsx)(l.PanelOverflowClip,{layer:e.vertex.layer,coordSystem:o,panelSize:n,children:(0,s.jsx)(Rt,{part:e.vertex,borderRadius:a,dashPeriod:i})},`vertex-${e.vertex.rows.join()}`)]});case"guide":return(0,s.jsx)(ca,{target:e.target,shapes:e.shapes,borderRadius:a,dashPeriod:i});case"graph":return(0,s.jsx)("path",{d:sa(e.frameSize,r,t)})}},Rt=(0,w.memo)(function({part:t,borderRadius:n,dashPeriod:r}){return t.kind==="boxes"?(0,s.jsx)(da,{boxes:t.boxes,borderRadius:n}):(0,s.jsx)(la,{shapes:t.shapes,layer:t.layer,dashPeriod:r})}),la=({shapes:e,layer:t,dashPeriod:n})=>e.map((r,o)=>{const a=r.kind==="dots"||r.key===void 0?String(o):`${r.kind}:${r.key}`;switch(r.kind){case"region":return r.pathData===""?null:(0,s.jsx)(Et,{pathData:r.pathData,fillRule:r.fillRule,animateTransitions:r.animateTransitions??!1,source:t,"data-geom":t.geom},a);case"stroke":return r.pathData===""?null:(0,s.jsx)(Et,{pathData:r.pathData,animateTransitions:r.animateTransitions??!1,source:t,"data-geom":t.geom,...kn(r.width)},a);case"dots":return r.centers.length===0?null:(0,s.jsx)("path",{d:l.buildCirclesPath(r.centers,r.size/2),pathLength:Mn(r.size/2,n,r.centers.length),"data-geom":t.geom},a)}}),da=({boxes:e,borderRadius:t})=>{const n=e.map(r=>l.buildRoundedRectPath(r,t)).join("");return n===""?null:(0,s.jsx)("path",{d:n,"data-testid":"edit-outline-boxes"})},ca=({target:e,shapes:t,borderRadius:n,dashPeriod:r})=>{const o=l.useStyleReaderTree();if(e.kind==="grid")return ea.map(i=>{const d=kn(l.readGridLineStyle(o,i).strokeWidth),u=t.map(g=>ua(g,i)).join(""),c=t.filter(g=>g.kind==="ring"&&g.axis===i);return(0,s.jsxs)(w.Fragment,{children:[u!==""&&(0,s.jsx)("path",{d:u,...d}),c.map((g,m)=>(0,s.jsx)("path",{d:ha(g),pathLength:Mn(g.radius,r),...d},m))]},i)});const a=t.map(i=>i.kind==="box"?l.buildRoundedRectPath(i.rect,n):"").join("");return a===""?null:(0,s.jsx)("path",{d:a})},ua=(e,t)=>e.kind==="line"&&e.axis===t?`M${e.from.x},${e.from.y}L${e.to.x},${e.to.y}`:"",ha=({center:e,radius:t})=>{const n=`${e.x},${e.y-t}`;return`M${n}A${t},${t} 0 0 1 ${`${e.x},${e.y+t}`}A${t},${t} 0 0 1 ${n}`},ga=({target:e,look:t,panelRect:n})=>{const r=l.useSceneSelector(i=>i.coordSystem),o=e.parts[0];if(e.scope!=="xValue"||o===void 0||o.layer.highlight?.strategy!=="overlayAnchor")return null;const a=pa(o);return a===null?null:(0,s.jsx)("svg",{x:n.x,y:n.y,width:n.width,height:n.height,overflow:"visible",children:(0,s.jsx)("line",{...l.readCrosshairLine(r,a,n),stroke:t.stroke,strokeOpacity:t.strokeAlpha,strokeWidth:t.strokeWidth,strokeDasharray:"4 3",strokeLinecap:"round","data-testid":"edit-outline-band-guide"})})},pa=({layer:e,rows:t})=>{for(const n of t){const r=e.data.getAt(n),o=r===null?null:(0,p.getXBand)(r),a=r===null?null:(0,p.getYBand)(r);if(o!==null&&a!==null)return{x:o,y:a}}return null},ma="_1esxxdm0",va=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 16 16",...e,children:[(0,s.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]}),xa=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 16 16",...e,children:[(0,s.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:"0.3",rx:".533"})]}),fa=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 16 16",...e,children:[(0,s.jsx)("rect",{width:"3.2",height:"7.704",y:"8.296",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"4.741",x:"8.533",y:"11.259",fill:"currentColor",fillOpacity:"0.3",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"11.259",x:"4.267",y:"4.741",fill:"currentColor",fillOpacity:"0.8",rx:".533"}),(0,s.jsx)("rect",{width:"3.2",height:"16",x:"12.8",fill:"currentColor",fillOpacity:".8",rx:".533"})]}),ya={observation:va,xValue:xa,group:fa},Sa=()=>{const{selectionStore:e}=l.useGraphContext(),t=l.useEditorStore(),n=l.useI18n(),r=l.useFormattingLocale(),o=l.useSceneSelector(C=>C),a=h.useGroupOptions(o,r),i=l.useEditorState(C=>C.pressedObservation),d=h.useHasOverlayMenu(),u=(0,w.useMemo)(()=>wa({scene:o,pressed:i,groupOptions:a,locale:r,t:n,hasOverlayMenu:d}),[o,i,a,r,n,d]);if(u===null)return null;const{layer:c,levels:g,names:m}=u,{observationIndex:v,selectedFor:x}=u.pressed,f=g.map(C=>{const S=ya[C];return{value:C,label:m[C],icon:(0,s.jsx)(S,{})}}),y=C=>{const S=g.find(E=>E===C),{parsingLocale:b}=o.config,T=S===void 0?null:(0,p.buildObservationsTarget)({layer:c,observationIndex:v,scope:S,parsingLocale:b});T!==null&&(t.getState().setPressedObservation({...u.pressed,selectedFor:T}),e.getState().setSelection([T]))};return(0,s.jsx)(h.ToggleGroup,{value:x.scope,options:f,onChange:y,ariaLabel:n("editor.overlayMenu.selection")})},wa=({scene:e,pressed:t,groupOptions:n,locale:r,t:o,hasOverlayMenu:a})=>{const i=t===null?null:l.findPressedObservation(t,e.layers,e.config.parsingLocale);if(t===null||i===null)return null;const{layer:d,observation:u}=i,{observationIndex:c,selectedFor:g}=t,{parsingLocale:m}=e.config,v=(0,p.readReachableLevels)({layer:d,observationIndex:c,parsingLocale:m,scales:e.scales}).filter(x=>{const f=(0,p.buildObservationsTarget)({layer:d,observationIndex:c,scope:x,parsingLocale:m});return f!==null&&a(f)});return v.length<2||!v.includes(g.scope)?null:{pressed:t,layer:d,levels:v,names:h.readLevelNames({scene:e,layer:d,observation:u,groupOptions:n,locale:r,t:o})}},ba=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"}),(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),Ca=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"}),(0,s.jsx)("path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242"}),(0,s.jsx)("path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"}),(0,s.jsx)("path",{d:"m2 2 20 20"})]})}),Ta="_11vjgg60",Aa=({target:e})=>{const t=l.useI18n(),n=l.useGraphCommands(),r=l.useSceneSelector(x=>x),[o,a]=(0,w.useState)(null),i=h.readTargetVisibility(e,r);if(i===null)return null;const{hidden:d,hide:u,show:c}=i,g=()=>{if(d){n.dispatch(o??c);return}a(c),n.dispatch(u)},m=t(d?"editor.overlayMenu.show":"editor.overlayMenu.hide"),v=d?Ca:ba;return(0,s.jsx)(h.ControlTooltip,{label:m,children:(0,s.jsx)("button",{type:"button",className:Ta,onClick:g,children:(0,s.jsx)(v,{title:""})})})},Pa=(e,t)=>t==="polar"||e==="bar",Ia=(e,t)=>e===null||e.key!==t?null:{boundary:{x:e.x,y:e.y,width:0,height:0},spans:{top:{from:e.x,to:e.x},right:{from:e.y,to:e.y},bottom:{from:e.x,to:e.x},left:{from:e.y,to:e.y}}},Ea="_1j45ehx0",ja="_1j45ehx1",ka="_1j45ehx2",Ra="_1j45ehx3",La=(e,t)=>{switch(e.kind){case"observations":return Oa(e.scope,t);case"legend":case"axis":case"grid":return Ma(e.kind,t);case"graph":return t("editor.overlayMenu.chart");default:return e}},Oa=(e,t)=>{switch(e){case"observation":return t("editor.overlayMenu.observation");case"group":return t("editor.overlayMenu.group");case"xValue":return t("editor.overlayMenu.band");default:return e}},Ma=(e,t)=>{switch(e){case"axis":return t("editor.overlayMenu.axis");case"legend":return t("editor.overlayMenu.legend");case"grid":return t("editor.overlayMenu.gridLines");default:return e}},_a=({target:e})=>{const t=l.useI18n(),n=l.useFormattingLocale(),r=l.useSceneSelector(i=>i),o=h.useGroupOptions(r,n),a=(0,w.useMemo)(()=>Fa({target:e,scene:r,groupOptions:o,locale:n,t}),[e,r,o,n,t]);return(0,s.jsx)(Da,{title:a})},Da=({title:e})=>{const t=(0,w.useRef)(null),n=(0,w.useRef)(null),[r,o]=(0,w.useState)(!1),a=(0,w.useCallback)(()=>{const u=t.current,c=n.current;u===null||c===null||o(c.offsetWidth>u.clientWidth)},[]);(0,w.useLayoutEffect)(a,[a,e.whole]);const{setElement:i}=l.useResizeObserver({onResize:a}),d=(0,w.useCallback)(u=>{t.current=u,i(u)},[i]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Br.Popover.Title,{ref:d,className:ka,"data-testid":"overlay-menu-title",children:r?e.value:e.whole}),(0,s.jsx)("span",{ref:n,className:Ra,"aria-hidden":!0,children:e.whole})]})},Fa=({target:e,scene:t,groupOptions:n,locale:r,t:o})=>{const a=La(e,o),i={whole:a,value:a};if(e.kind!=="observations")return i;const d=(0,p.findLayerById)(t.layers,e.layerId);if(d===void 0)return i;const[u]=(0,p.resolveObservationsTarget)({layer:d,target:e,parsingLocale:t.config.parsingLocale}),c=u===void 0?null:d.data.getAt(u);return c===null?i:h.readLevelTitle({scene:t,layer:d,observation:c,groupOptions:n,locale:r,t:o},e.scope)},Na=({frameElement:e,panelRect:t})=>{const n=h.useBuildRemoveAnnotationCommand(t),{selectionStore:r}=l.useGraphContext(),o=Ga(l.useEditorState(v=>v.selectedOutline)),a=l.useEditorState(v=>v.annotatePress),i=l.MODE_RULES[l.useGraphMode()].showMenuTriggerOnHover,d=h.useEditMenu(o?.target??null),u=h.useHasOverlayMenu(),c=o===null?null:(0,p.readEditTargetKey)(o.target),g=(0,w.useMemo)(()=>i&&c!==null?Ia(a,c):null,[i,a,c]);if(o===null||c===null||!u(o.target))return null;const m=()=>{r.getState().clearSelection()};return(0,s.jsx)(h.AnchoredPopover,{frameElement:e,boundary:g?.boundary??o.frame,spans:g?.spans??o.frameSpans,onEscape:m,children:(0,s.jsxs)("div",{className:ma,children:[(0,s.jsxs)(h.ControlTooltipArea,{className:Ea,children:[(0,s.jsxs)("div",{className:ja,children:[(0,s.jsx)(_a,{target:o.target}),(0,s.jsx)(Aa,{target:o.target},c)]}),o.target.kind==="observations"&&(0,s.jsx)(Sa,{})]}),(0,s.jsx)(h.RemoveAnnotationCommandContext.Provider,{value:n,children:(0,s.jsx)(w.Fragment,{children:d},c)})]})})},Ga=e=>{const t=l.useGraphSelection(),[n,r]=(0,w.useState)(e),o=n!==null&&(0,p.areEditTargetsEqual)(t[0]??null,n.target),a=e??(o?n:null);return a!==n&&r(a),a},Ba=({frameRect:e})=>{const{targetBoundaryStore:t}=l.useGraphContext(),n=l.useEditorState(i=>i.selectedOutline),{left:r,top:o}=e,a=(0,w.useMemo)(()=>{if(n===null)return null;const{frame:i,frameSpans:d,frameScale:u}=n;return{frame:i,client:{x:r+i.x*u,y:o+i.y*u,width:i.width*u,height:i.height*u},frameSpans:d,clientSpans:{top:ye(d.top,r,u),right:ye(d.right,o,u),bottom:ye(d.bottom,r,u),left:ye(d.left,o,u)}}},[n,r,o]);return(0,w.useLayoutEffect)(()=>{t.getState().setBoundary(a)},[t,a]),(0,w.useLayoutEffect)(()=>()=>t.getState().setBoundary(null),[t]),null},ye=(e,t,n)=>({from:t+e.from*n,to:t+e.to*n}),dt=["start","end"],Ha=({anchor:e,point:t,delta:n,bounds:r=p.PANEL_FRACTION_BOUNDS})=>{const o={x:Ot(t.x,n.x,r.minX,r.maxX),y:Ot(t.y,n.y,r.minY,r.maxY)};return{anchor:{...e,x:e.x+o.x,y:e.y+o.y},point:{x:t.x+o.x,y:t.y+o.y}}},ct=(e,t,n)=>{const{space:r,defer:o,...a}=e[t.endpoint];return{...e,[t.endpoint]:{...a,...(0,p.toPanelCursor)(t.placement.point,n)}}},Lt=(e,t,n)=>({type:"free",anchor:e,sourceAlign:null,point:(0,p.projectAnchorToPanel)(t,n),nearby:[]}),_n=(e,t)=>(0,q.isEqual)(e,t),za=(e,t)=>{const n=(0,p.projectAnchorToPanel)(e,t);return{x:t.x+n.x,y:t.y+n.y}},Wa=(e,t,n)=>{const r=(0,p.projectAnchorToPanel)(e,n),o=(0,p.projectAnchorToPanel)(t,n);return{x:Math.min(r.x,o.x),y:Math.min(r.y,o.y),width:Math.abs(o.x-r.x),height:Math.abs(o.y-r.y)}},Ot=(e,t,n,r)=>!Number.isFinite(t)||!Number.isFinite(e)?0:(0,q.clamp)(t,Math.min(n-e,0),Math.max(r-e,0)),je=({stroke:e,strokeAlpha:t})=>`color-mix(in srgb, ${e} ${t*100}%, transparent)`,Dn=(e,t,n,r)=>{const o=e.textAnnotations.find(a=>a.id===t);return o===void 0?null:l.measureTextAnnotationBox(l.previewResizedText(o,n),r)},Va="var(--_1am0al60)";var Ua="_1am0al61",Xa="_1am0al62",ut=(e,t,n)=>({x:h.normalizeToPanelExtent(t.x-e.x,n.width),y:h.normalizeToPanelExtent(t.y-e.y,n.height)}),Fn=e=>e.x!==0||e.y!==0,Nn=(e,t)=>({x:e.x*t.width,y:e.y*t.height}),Ka=({panelRect:e})=>{const t=l.useResolvedAnnotations(e),n=l.useMeasuredBoxes(),r=l.useStyleReaderTree(),o=h.useSelectedAnnotationId(),a=l.useEditorState(S=>l.readStanding(S,"move-drag")),i=l.useEditorState(S=>l.readStanding(S,"shape-resize-drag")),d=l.useEditorState(S=>l.readStanding(S,"arrow-endpoint-drag")),u=l.useEditorState(S=>l.readStanding(S,"text-resize-drag")),c=l.useEditorState(l.readAnnotationUnderPointer),g={panel:{width:e.width,height:e.height},measuredBoxes:n,readers:r},m=a!==null&&l.readMovedRegionRect(a)!==null,v=m?l.applyDraggedPlacement(t,t,a,e):t,x=Mt(v,o,g),f=Mt(v,c===o?null:c,g),y=S=>{if(i?.annotationId===S.id){const b=i.annotationKind==="shape"?r.annotation.shape(S.id).get("strokeWidth"):0;return l.measureShapeRegion(i.region,b,g.panel)}if(d?.annotationId===S.id){const b=t.arrows.find(T=>T.id===S.id);return b===void 0?S.geometry:l.measureArrowEnds(ct(b,d,g.panel),g.panel)}return u?.annotationId===S.id?Dn(t,S.id,u,g)??S.geometry:S.geometry},C=S=>{if(a?.annotationId!==S||m)return e;const b=Nn(a.translation,e);return{x:e.x+b.x,y:e.y+b.y}};return(0,s.jsxs)(s.Fragment,{children:[f!==null&&(0,s.jsx)(_t,{annotationId:f.id,geometry:y(f),state:"hovered",origin:C(f.id)}),x!==null&&(0,s.jsx)(_t,{annotationId:x.id,geometry:y(x),state:"selected",origin:C(x.id)})]})},Mt=(e,t,n)=>{if(t===null)return null;const r=l.resolveAnnotationChromeGeometry(e,t,n);return r===null?null:{id:t,geometry:r}},_t=({annotationId:e,geometry:t,state:n,origin:r})=>{const o=l.useStyleReaderTree();if(t===null)return null;const a=o.editOutline[n==="hovered"?"hover":"selected"]().resolve(),i=(0,te.assignInlineVars)({[Va]:je(a)});return t.shape==="segment"?(0,s.jsxs)("div",{"aria-hidden":"true","data-testid":"annotation-chrome","data-annotation-id":e,"data-state":n,style:i,children:[(0,s.jsx)(Dt,{point:t.start,origin:r}),(0,s.jsx)(Dt,{point:t.end,origin:r})]}):(0,s.jsx)("div",{"aria-hidden":"true",className:Ua,"data-testid":"annotation-chrome","data-annotation-id":e,"data-state":n,style:{...i,left:r.x+t.rect.x-2,top:r.y+t.rect.y-2,width:t.rect.width+4,height:t.rect.height+4}})},Dt=({point:e,origin:t})=>(0,s.jsx)("span",{className:Xa,style:{left:t.x+e.x,top:t.y+e.y}}),ht="c44vv80",$a=({panelRect:e})=>{const t=l.useEditorState(i=>l.readStanding(i,"move-drag")),n=l.useResolvedAnnotations(e);if(t===null)return null;const r=l.readMovedRegionRect(t)!==null,o=r?{x:0,y:0}:Nn(t.translation,e),a=r?l.applyDraggedPlacement(n,n,t,e):n;return(0,s.jsx)("svg",{"aria-hidden":"true",className:ht,width:e.width,height:e.height,style:{left:e.x+o.x,top:e.y+o.y},"data-testid":"annotation-preview","data-annotation-id":t.annotationId,children:Za(a,t.annotationId,e)})},Ya=({annotation:e,panelSize:t})=>{const n=l.useMeasuredBoxRef(e.id);return(0,s.jsx)(l.TextAnnotation,{annotation:e,panel:t,style:(0,p.resolveTextAnnotationStyle)(l.useStyleReaderTree(),e.id),blockRef:n})},le=(e,t,n)=>{const r=e.find(o=>o.id===t);return r===void 0?null:n(r)},qa={text:(e,t,n)=>le(e.textAnnotations,t,r=>(0,s.jsx)(Ya,{annotation:r,panelSize:n})),shape:(e,t,n)=>le(e.shapes,t,r=>(0,s.jsx)(Qa,{shape:r,panelSize:n})),image:(e,t,n)=>le(e.images,t,r=>(0,s.jsx)(ts,{image:r,panelSize:n})),arrow:(e,t,n)=>le(e.arrows,t,r=>(0,s.jsx)(Ja,{arrow:r,panelSize:n})),sticker:(e,t,n)=>le(e.stickers,t,r=>(0,s.jsx)(es,{sticker:r,panelSize:n}))},Za=(e,t,n)=>{for(const r of Object.values(qa)){const o=r(e,t,n);if(o!==null)return o}return null},Ja=({arrow:e,panelSize:t})=>{const n=(0,p.resolveArrowAnnotationStyle)(l.useStyleReaderTree(),e.id),r=(0,p.computeArrow)({arrow:e,style:n,panelWidth:t.width,panelHeight:t.height});return r===null?null:(0,s.jsx)(l.ArrowAnnotation,{computed:r,style:n,addressable:!1})},Qa=({shape:e,panelSize:t})=>(0,s.jsx)(l.ShapeAnnotation,{shape:e,style:l.useStyleReaderTree().annotation.shape(e.id).resolve(),panel:t}),es=({sticker:e,panelSize:t})=>(0,s.jsx)(l.StickerAnnotation,{sticker:e,panel:t,textScale:l.useStyleReaderTree().graph().get("textScale")}),ts=({image:e,panelSize:t})=>(0,s.jsx)(l.ImageAnnotation,{image:e,panel:t,style:l.useStyleReaderTree().annotation.image(e.id).resolve()}),gt="_1lp7ph20",ns=({panelRect:e})=>{const t=l.useEditorState(r=>l.readStanding(r,"move-drag")?.placement??l.readStanding(r,"arrow-endpoint-drag")?.placement??l.readStanding(r,"arrow-draw")?.placement??l.readStanding(r,"shape-resize-drag")?.placement??l.readStanding(r,"box-draw")?.placement??null),n=l.useEditorState(r=>l.readStanding(r,"move-drag")?.ends??null);return n!==null?(0,s.jsx)(rs,{ends:n,panelRect:e}):t===null?null:"region"in t?(0,s.jsx)(as,{placement:t,panelRect:e}):(0,s.jsx)(os,{placement:t,panelRect:e})},rs=({ends:e,panelRect:t})=>{const n=l.useStyleReaderTree().snapTarget.tether().resolve();return(0,s.jsx)("svg",{"aria-hidden":"true",className:gt,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-chrome","data-placement":"offset",children:dt.map(r=>{const o=e[r].tether;return o===void 0?null:(0,s.jsx)(Gn,{...o,style:n,endpoint:r},r)})})},os=({placement:e,panelRect:t})=>{const n=l.useStyleReaderTree().snapTarget,r=n.nearby().resolve(),o=n.snapped().resolve(),a=n.area().resolve(),i=n.source().resolve(),d=n.tether().resolve(),u=e.type==="snapped"?e.point:null,c=e.type==="snapped"?ss(e):null;return(0,s.jsxs)("svg",{"aria-hidden":"true",className:gt,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-chrome","data-placement":e.type,children:[e.nearby.map(({point:g,distance:m,nearest:v},x)=>{if(u!==null&&g.x===u.x&&g.y===u.y)return null;const f=r.alpha*(v?1:Math.max(0,1-m/160));return f<=0?null:(0,s.jsx)("circle",{"data-testid":"snap-nearby","data-nearest":v?"":void 0,cx:g.x,cy:g.y,r:r.size/2,fill:"none",...ce(r),strokeOpacity:f},x)}),e.type==="snapped"&&(0,s.jsxs)("g",{"data-testid":"snap-target","data-target-type":e.target.type,"data-target-id":is(e),children:[c!==null&&e.landing==="area"&&(0,s.jsx)("rect",{"data-testid":"snap-area",x:c.x,y:c.y,width:c.width,height:c.height,rx:a.cornerRadius,fill:(0,p.toPaintColor)(a.fill),fillOpacity:a.alpha,stroke:"none"}),(0,s.jsx)("circle",{cx:e.point.x,cy:e.point.y,r:o.size/2,fill:(0,p.toPaintColor)(o.fill),fillOpacity:o.alpha,stroke:"none"}),(0,s.jsx)("circle",{"data-testid":"snap-source",cx:e.point.x,cy:e.point.y,r:i.size/2,fill:"none",...ce(i)})]}),e.type==="offset"&&(0,s.jsx)(Gn,{targetPoint:e.restPoint,point:e.point,style:d})]})},Gn=({targetPoint:e,point:t,style:n,endpoint:r})=>(0,s.jsxs)("g",{"data-testid":"snap-tether","data-endpoint":r,children:[(0,s.jsx)("line",{x1:e.x,y1:e.y,x2:t.x,y2:t.y,...ce(n)}),(0,s.jsx)("circle",{cx:e.x,cy:e.y,r:n.size/2,fill:(0,p.toPaintColor)(n.fill),fillOpacity:n.alpha,stroke:"none"})]}),as=({placement:e,panelRect:t})=>{const n=l.useStyleReaderTree().snapTarget.snapped().resolve();return e.type!=="selection"?null:(0,s.jsxs)("svg",{"aria-hidden":"true",className:gt,width:t.width,height:t.height,style:{left:t.x,top:t.y},"data-testid":"snap-target","data-target-type":"selection",children:[e.observationRects.map((r,o)=>(0,s.jsx)("rect",{"data-observation":"",x:r.x,y:r.y,width:r.width,height:r.height,rx:n.cornerRadius,fill:"none",...ce(n)},o)),(0,s.jsx)("rect",{x:e.box.x,y:e.box.y,width:e.box.width,height:e.box.height,rx:n.cornerRadius,fill:"none",...ce(n)})]})},ce=e=>({stroke:e.stroke,strokeOpacity:e.alpha,strokeWidth:e.strokeWidth,strokeDasharray:(0,p.toStrokeDasharray)(e.dashArray,e.strokeWidth)}),ss=e=>e.target.type==="observation"?e.target.box:e.target.rect,is=e=>e.target.type==="observation"?String(e.target.point.anchor.anchorValue):e.target.id,ls=({panelRect:e})=>{const t=l.useEditorState(d=>l.readStanding(d,"arrow-endpoint-drag")),n=l.useResolvedAnnotations(e).arrows,r=l.useStyleReaderTree();if(t===null)return null;const o=n.find(d=>d.id===t.annotationId);if(o===void 0)return null;const a=(0,p.resolveArrowAnnotationStyle)(r,o.id),i=(0,p.computeArrow)({arrow:ct(o,t,e),style:a,panelWidth:e.width,panelHeight:e.height});return i===null?null:(0,s.jsx)("svg",{"aria-hidden":"true",className:ht,width:e.width,height:e.height,style:{left:e.x,top:e.y},"data-testid":"arrow-endpoint-preview","data-annotation-id":t.annotationId,children:(0,s.jsx)(l.ArrowAnnotation,{computed:i,style:a,addressable:!1})})},ds=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,s.jsx)("path",{d:"M19 12H5"})]})}),Bn=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M5 12h14"}),(0,s.jsx)("path",{d:"m12 5 7 7-7 7"})]})}),Hn=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{fill:"currentColor",children:[(0,s.jsx)("rect",{x:"3",y:"5",width:"18",height:"1.5",rx:"0.75"}),(0,s.jsx)("rect",{x:"3",y:"10",width:"18",height:"3",rx:"1.5"}),(0,s.jsx)("rect",{x:"3",y:"16.5",width:"18",height:"4.5",rx:"2.25"})]})}),cs=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",children:[(0,s.jsx)("path",{d:"M5 19 8 16"}),(0,s.jsx)("path",{d:"M10.5 13.5 13.5 10.5"}),(0,s.jsx)("path",{d:"M16 8 19 5"})]})}),us=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",children:[(0,s.jsx)("path",{d:"M5 19h0"}),(0,s.jsx)("path",{d:"M8.5 15.5h0"}),(0,s.jsx)("path",{d:"M12 12h0"}),(0,s.jsx)("path",{d:"M15.5 8.5h0"}),(0,s.jsx)("path",{d:"M19 5h0"})]})}),hs=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsx)("path",{d:"M5 19 19 5",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})}),gs=[{value:p.ARROW_STROKE_WIDTHS_PX.thin,key:"graph.annotations.arrowToolbar.thickness.thin"},{value:p.ARROW_STROKE_WIDTHS_PX.medium,key:"graph.annotations.arrowToolbar.thickness.medium"},{value:p.ARROW_STROKE_WIDTHS_PX.thick,key:"graph.annotations.arrowToolbar.thickness.thick"}],Ft=[{value:"lineArrow",key:"graph.annotations.arrowToolbar.arrowhead.lineArrow",Icon:Bn},{value:"none",key:"graph.annotations.arrowToolbar.arrowhead.none",Icon:l.MinusIcon}],Nt=[{value:"solid",key:"graph.annotations.arrowToolbar.lineStyle.solid",Icon:hs},{value:"dashed",key:"graph.annotations.arrowToolbar.lineStyle.dashed",Icon:cs},{value:"dotted",key:"graph.annotations.arrowToolbar.lineStyle.dotted",Icon:us}],ps=(e,t)=>e.find(n=>n.value===t)??e[0];var ms=({arrow:e,arrowBox:t,panelRect:n,frameElement:r})=>{const o=l.useI18n(),{commands:a}=l.useGraphContext(),i=l.useSceneSelector(R=>R.spec.styles.overrides),d=l.useSceneSelector(R=>(0,p.readStyleCoord)(R.spec)),u=h.useToolbarPopups(),c=(0,p.resolveArrowAnnotationStyle)(l.useStyleReaderTree(),e.id),g=ps(Nt,(0,p.toDashPreset)(c.dashArray)),m=c.outline.strokeWidth>0||c.outline.shadow!=="none",v=(0,w.useMemo)(()=>({target:"annotation",kind:"arrow",annotation:e.id}),[e.id]),x=(0,w.useMemo)(()=>({...v,part:"outline"}),[v]),f=(R,j)=>{const P=(0,p.findStyleRule)(i,{select:v},d)?.declarations??{};a.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:v,declarations:{...P,...R}}}),j)},y=R=>{const j=(0,p.findStyleRule)(i,{select:x},d)?.declarations??{};a.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:x,declarations:{...j,...R}}}))},C=R=>{f(R),u.close()},S=R=>{a.dispatch(new p.UpdateAnnotationCommand({kind:"arrow",id:e.id,patch:R})),u.close()},b=()=>{a.dispatch(new p.RemoveAnnotationCommand({id:e.id})),r.focus({preventScroll:!0})},T=R=>f({stroke:R},{transient:!0}),E=R=>C({strokeWidth:R}),A=R=>S({startArrowheadStyle:R}),M=R=>C({dashArray:p.DASH_PRESETS.arrow[R]}),N=R=>S({endArrowheadStyle:R}),G=()=>y(m?{strokeWidth:0,shadow:"none"}:p.ARROW_STICKER_DECLARATIONS);return(0,s.jsxs)(h.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameElement:r,label:o("graph.annotations.arrowToolbar.label"),testId:"arrow-toolbar",children:[(0,s.jsx)(h.FloatingToolbar.ColorPicker,{color:c.stroke,label:o("graph.annotations.arrowToolbar.color"),onChange:T,...u.bind("color"),children:(0,s.jsx)(h.FloatingToolbar.Swatch,{color:c.stroke})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:o("graph.annotations.arrowToolbar.thickness.ariaLabel"),trigger:(0,s.jsx)(Hn,{size:"sm",title:""}),...u.bind("thickness"),children:(0,s.jsx)(Se,{options:gs,current:c.strokeWidth,onPick:E})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:o("graph.annotations.arrowToolbar.startArrowhead"),trigger:(0,s.jsx)(ds,{size:"sm",title:""}),...u.bind("startArrowhead"),children:(0,s.jsx)(Se,{options:Ft,current:e.startArrowheadStyle,onPick:A})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:o("graph.annotations.arrowToolbar.lineStyle.ariaLabel"),trigger:g?.Icon!==void 0&&(0,s.jsx)(g.Icon,{size:"sm",title:""}),...u.bind("lineStyle"),children:(0,s.jsx)(Se,{options:Nt,current:(0,p.toDashPreset)(c.dashArray),onPick:M})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:o("graph.annotations.arrowToolbar.endArrowhead"),trigger:(0,s.jsx)(Bn,{size:"sm",title:""}),...u.bind("endArrowhead"),children:(0,s.jsx)(Se,{options:Ft,current:e.endArrowheadStyle,onPick:N})}),(0,s.jsx)(h.FloatingToolbar.Button,{label:o("graph.annotations.arrowToolbar.sticker"),pressed:m,onClick:G,children:(0,s.jsx)(h.ArrowUpRightIcon,{size:"sm",title:""})}),(0,s.jsx)(h.FloatingToolbar.Separator,{}),(0,s.jsx)(h.FloatingToolbar.Button,{label:o("graph.annotations.arrowToolbar.remove"),onClick:b,children:(0,s.jsx)(h.TrashIcon,{size:"sm",title:""})})]})},Se=({options:e,current:t,onPick:n})=>{const r=l.useI18n(),o=a=>()=>n(a);return(0,s.jsx)(s.Fragment,{children:e.map(a=>(0,s.jsxs)(h.FloatingToolbar.MenuItem,{selected:a.value===t,onClick:o(a.value),children:[(0,s.jsx)("span",{children:r(a.key)}),a.Icon!==void 0&&(0,s.jsx)("span",{className:"_112xh5c0",children:(0,s.jsx)(a.Icon,{size:"sm",title:""})})]},String(a.value)))})},vs="_1me29t10",se=(e,t,n,r,o)=>{if(e.anchorType==="panel")return null;const a=(0,p.projectAnchorToPanel)(n,r),i=o===void 0?void 0:(0,p.readOutwardGapOffset)(e.align,o),d=n.space==="disk"?void 0:e.offset??i,u=(d?.x??0)*(d?.unit==="px"?1:r.width),c=(d?.y??0)*(d?.unit==="px"?1:r.height);return{anchor:e,sourceAlign:t,targetPoint:{x:a.x-u,y:a.y-c}}},xs={distance:8,margin:p.SELECTION_PADDING_DEFAULT.x??0},ne=(e,t)=>({anchorType:"panel",x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0,width:t.width>0?e.width/t.width:0,height:t.height>0?e.height/t.height:0}),Ie=(e,t,n,r)=>{const o=(t==="shape"?e.shapes:e.images).find(a=>a.id===n);return o===void 0?null:(0,p.projectRegionToPanel)(o.region,r)},zn=(e,t,n)=>n==="px"?{width:e.width,height:e.height,unit:n}:{width:h.normalizeToPanelExtent(e.width,t.width),height:h.normalizeToPanelExtent(e.height,t.height)},fs=(e,t,n,r,o)=>{if(e.type==="free"){const a=(0,p.alignUnitFractions)(n),i=e.point.x-a.x*t.width,d=e.point.y-a.y*t.height;return ne({x:i,y:d,width:t.width,height:t.height},r)}return e.anchor.anchorType!=="observation"&&e.anchor.anchorType!=="annotation"?ne(t,r):{...e.anchor,...zn(t,r,o),regionAlign:e.sourceAlign??n}},Wn=(e,t,n)=>{const r=e.regionAlign??"center",o=(0,p.readRectPoint)(t,r),a={x:h.normalizeToPanelExtent(o.x,n.width),y:h.normalizeToPanelExtent(o.y,n.height)};return se((0,p.toPlacedRegionPoint)(e),r,a,n)},Vn=(e,t,n,r=p.PANEL_FRACTION_BOUNDS)=>({x:Gt(e.x,e.width,t.x,r.minX*n.width,r.maxX*n.width),y:Gt(e.y,e.height,t.y,r.minY*n.height,r.maxY*n.height)}),pt=({rect:e,panelRect:t,bounds:n,layers:r,readObservationBox:o,mayEnclose:a})=>a?(0,p.resolveRegionPlacement)({rect:e,layers:r,readObservationBox:o,panelRect:t,bounds:n,snap:xs}):{type:"free",region:ne(e,t),rect:e},Gt=(e,t,n,r,o)=>{if(!Number.isFinite(n)||!Number.isFinite(e))return 0;const a=Math.min(r-e,0),i=Math.max(o-(e+t),0);return Math.min(Math.max(n,a),i)},Un=e=>e.start.anchorType!=="panel"||e.end.anchorType!=="panel",ys=({arrow:e,painted:t,compiled:n,travel:r,bounds:o,free:a,...i})=>{const{panelRect:d,coordSystem:u}=i,c={start:(0,p.projectAnchorToPanel)(t.start,d),end:(0,p.projectAnchorToPanel)(t.end,d)},g=Vn({x:Math.min(c.start.x,c.end.x),y:Math.min(c.start.y,c.end.y),width:Math.abs(c.end.x-c.start.x),height:Math.abs(c.end.y-c.start.y)},r,d,o),m=f=>it(Ss(e[f],n?.[f]),t[f],i),v={start:m("start"),end:m("end")},x=f=>{const y=e[f];if(g.x===0&&g.y===0)return{anchor:y};const C={x:c[f].x+g.x,y:c[f].y+g.y};if(y.anchorType==="panel")return{anchor:{...y,x:y.x+h.normalizeToPanelExtent(g.x,d.width),y:y.y+h.normalizeToPanelExtent(g.y,d.height)}};const S={anchor:{anchorType:"panel",x:h.normalizeToPanelExtent(C.x,d.width),y:h.normalizeToPanelExtent(C.y,d.height)}};if(a||u.type==="polar"&&y.anchorType!=="annotation")return S;let b=y,T;if(y.align==="auto"){const A=v[f];if(A.width>0&&A.height>0){const M=v[f==="start"?"end":"start"],N=(0,p.readFacingAlign)(A,M);b={...y,align:N},T=(0,p.readRectPoint)(A,N)}else{const{align:M,...N}=y;b=N,T={x:A.x,y:A.y}}}else{const A=se(y,null,t[f],d,p.ARROW_TARGET_GAP_PX);if(A===null)return S;T=A.targetPoint}const E={x:C.x-T.x,y:C.y-T.y};return Math.hypot(E.x,E.y)>40?S:{anchor:{...b,offset:{...E,unit:"px"}},tether:{targetPoint:T,point:C}}};return{translation:g,ends:{start:x("start"),end:x("end")}}},Ss=(e,t)=>{if(e.anchorType!=="observation"||e.layerId!==void 0||t?.defer?.type!=="observationBox")return e;const n=t.defer.observations[0]?.layerId;return n===void 0?e:{...e,layerId:n}};var ee=(e,t)=>t?e.altKey:!e.altKey,Xn=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y)>=3,pe=class{constructor(e){this.params=e,this.listeners=new AbortController,this.pendingEvent=null,this.scheduledFrame=null,this.hasMoved=!1,this.hasPublished=!1,this.confirmedDrag=!1,this.releasePoint=null,this.handleMove=t=>{t.pointerId===this.params.pointerId&&(this.pendingEvent=t,this.hasMoved=!0,this.scheduledFrame===null&&(this.scheduledFrame=requestAnimationFrame(this.runFrame)))},this.handleUp=t=>{t.pointerId===this.params.pointerId&&(this.pendingEvent=t,this.releasePoint={x:t.clientX,y:t.clientY},this.finish(!0))},this.handleLost=t=>{t.pointerId===this.params.pointerId&&this.finish(!1)},this.runFrame=()=>{this.scheduledFrame=null;const t=this.pendingEvent;if(this.pendingEvent=null,t===null)return;const n=this.params.editorStore.getState();if(this.hasPublished&&this.readOwn(n)===null)return;const r={x:t.clientX,y:t.clientY};if(!this.hasPublished&&!this.isDragConfirmed(this.params.press,r))return;this.confirmedDrag=!0;const o=this.resolvePreview(r,{altKey:t.altKey});o!==null&&(n.claimInteraction(o),this.hasPublished=!0)}}start(){const{handle:e}=this.params,{signal:t}=this.listeners;e.addEventListener("pointermove",this.handleMove,{signal:t}),e.addEventListener("pointerup",this.handleUp,{signal:t}),e.addEventListener("lostpointercapture",this.handleLost,{signal:t})}finish(e){this.params.onSettled(),this.listeners.abort(),this.cancelFrame();try{e&&this.hasMoved&&this.runFrame()}finally{this.settle(e)}}isDragConfirmed(e,t){return Xn(e,t)}settle(e){this.pendingEvent=null;const t=this.params.editorStore.getState(),n=this.readOwn(t);n!==null&&t.releaseInteraction(this.kind),e&&n!==null&&this.commit(n),e&&!this.confirmedDrag&&this.params.onClick!==void 0&&(document.activeElement===this.params.handle&&this.params.handle.blur(),this.params.onClick(this.releasePoint??this.params.press))}cancelFrame(){this.scheduledFrame!==null&&(cancelAnimationFrame(this.scheduledFrame),this.scheduledFrame=null)}},mt=["top","bottom","left","right","topLeft","topRight","bottomLeft","bottomRight"],Ze=["center",...mt],Bt=(e,t,n)=>{const r={...e,x:e.x+n.x,y:e.y+n.y};return[t,...Ze.filter(o=>o!==t)].map(o=>({align:o,point:(0,p.readRectPoint)(r,o)}))},ke=(e,t,n,r)=>{const o=[];for(const[a,i]of(0,p.indexSceneAnnotations)(e)){if(t.has(a)||i.kind!=="text"&&i.kind!=="shape"&&i.kind!=="image"&&i.kind!=="sticker")continue;const d=(0,p.readAnnotationBox)(i,n,r);d===null||d.xMax<=d.xMin||d.yMax<=d.yMin||o.push({id:a,rect:(0,p.projectBoxToPanel)(d,n)})}return o},Ht=(e,t,n,r)=>{const o=(0,p.readRectPoint)(t,e.sourceAlign??n);return{x:h.normalizeToPanelExtent(e.point.x-o.x,r.width),y:h.normalizeToPanelExtent(e.point.y-o.y,r.height)}},ws=(e,t)=>{const n=e.sourceAlign??t.align;return n===t.align&&(0,q.isEqual)(e.anchor,t.at)?null:{at:e.anchor,align:n}},Kn=class extends pe{constructor(...e){super(...e),this.kind="move-drag"}readOwn(e){return l.readMovedAnnotationFor(l.readStanding(e,"move-drag"),this.params.annotationId)}resolvePreview(e,t){return new Je(this.params).resolve(e,t)}commit(e){new Je(this.params).commit(e)}},Je=class{constructor(e){this.params=e}resolve(e,t){const{annotationId:n,press:r,readInputs:o}=this.params,a=o(),i=(0,p.findAnnotation)(a.spec,n);if(i===null)return null;if(i.kind==="text")return this.resolveTextPreview(i.annotation,e,t,a);if(i.kind==="sticker")return this.resolveStickerPreview(i.annotation,e,t,a);if(i.kind==="shape"||i.kind==="image")return this.resolveRegionPreview(i,e,t,a);if(i.kind==="arrow"&&Un(i.annotation))return this.resolveArrowPreview(i.annotation,e,t,a);const{panelRect:d,frameElement:u}=a,c=h.readContainerFractionBoundsFor(d,u),g=(0,p.clampAnnotationTranslation)(i,ut(r,e,d),c);return g===null?null:{kind:"move-drag",annotationId:n,translation:g}}commit({translation:e,placement:t,ends:n}){const{annotationId:r,dispatch:o,readInputs:a}=this.params,i=a(),{spec:d,panelRect:u,frameElement:c}=i,g=(0,p.findAnnotation)(d,r);if(g!==null){if(g.kind==="shape"||g.kind==="image"){if(t===void 0)return;const m="region"in t?t.region:this.readPlacedRegion(t,g,i);if(m===null||(0,q.isEqual)(m,g.annotation.region))return;o(new p.UpdateAnnotationCommand({kind:g.kind,id:r,patch:{region:m}}));return}if(t!==void 0&&!("region"in t)&&g.kind==="text"){const m=ws(Ae(t,d,r,u),g.annotation);m!==null&&o(new p.UpdateAnnotationCommand({kind:"text",id:r,patch:m}));return}if(t!==void 0&&!("region"in t)&&g.kind==="sticker"){const{anchor:m}=Ae(t,d,r,u);if((0,q.isEqual)(m,g.annotation.at))return;o(new p.UpdateAnnotationCommand({kind:"sticker",id:r,patch:{at:m}}));return}if(g.kind==="arrow"&&n!==void 0){const m={start:n.start.anchor,end:n.end.anchor};if((0,q.isEqual)(m.start,g.annotation.start)&&(0,q.isEqual)(m.end,g.annotation.end))return;o(new p.UpdateAnnotationCommand({kind:"arrow",id:r,patch:m}));return}Fn(e)&&o(new p.MoveAnnotationCommand({id:r,translation:e,bounds:h.readContainerFractionBoundsFor(u,c)}))}}resolveArrowPreview(e,t,n,r){const{annotationId:o,press:a,editorStore:i,anchorResolver:d}=this.params,{scene:u,compiled:c,panelRect:g,frameElement:m,layers:v,coordSystem:x,measuredBoxes:f,readObservationBox:y}=r,C=u.arrows.find(T=>T.id===o);if(C===void 0)return null;const{translation:S,ends:b}=ys({arrow:e,painted:C,compiled:c.arrows.find(T=>T.id===o),travel:{x:t.x-a.x,y:t.y-a.y},bounds:h.readContainerFractionBoundsFor(g,m),free:ee(n,i.getState().snapping),scene:u,panelRect:g,measuredBoxes:f,readObservationBox:y,layers:v,coordSystem:x,anchorResolver:d});return{kind:"move-drag",annotationId:o,translation:{x:h.normalizeToPanelExtent(S.x,g.width),y:h.normalizeToPanelExtent(S.y,g.height)},ends:b}}resolveRegionPreview(e,t,n,r){const{annotationId:o,press:a,editorStore:i,offsetOnly:d=!1}=this.params,{scene:u,panelRect:c,frameElement:g,layers:m,readObservationBox:v}=r,{kind:x,annotation:f}=e,y=Ie(u,x,o,c);if(y===null)return null;const C=h.readContainerFractionBoundsFor(c,g),S=Vn(y,{x:t.x-a.x,y:t.y-a.y},c,C);if(x==="shape"&&!d){const M=pt({rect:{...y,x:y.x+S.x,y:y.y+S.y},panelRect:c,bounds:C,layers:m,readObservationBox:v,mayEnclose:!ee(n,i.getState().snapping)});if(M.type==="selection")return{kind:"move-drag",annotationId:o,translation:{x:h.normalizeToPanelExtent(M.rect.x-y.x,c.width),y:h.normalizeToPanelExtent(M.rect.y-y.y,c.height)},placement:M}}const b=(0,p.isPlacedRegionAnchor)(f.region)?f.region:null,T=b?.regionAlign??"center",E=b===null?null:Wn(b,y,c),A=this.resolvePlacement(Bt(y,T,S),(0,p.readRectPoint)(y,T),E,n,r,{targetAligns:Ze});return A===null?null:{kind:"move-drag",annotationId:o,translation:Ht(A,y,T,c),placement:A}}readPlacedRegion(e,t,n){const{annotationId:r}=this.params,{spec:o,scene:a,panelRect:i}=n,d=Ie(a,t.kind,r,i);if(d===null)return null;const u=(0,p.isPlacedRegionAnchor)(t.annotation.region)?t.annotation.region:null;return fs(Ae(e,o,r,i),d,u?.regionAlign??"center",i,u?.unit)}resolveStickerPreview(e,t,n,r){const{annotationId:o,press:a}=this.params,{scene:i,panelRect:d}=r,u=i.stickers.find(v=>v.id===o);if(u===void 0)return null;const c=(0,p.projectAnchorToPanel)(u.at,d),g={x:t.x-a.x,y:t.y-a.y},m=this.resolvePlacement([{align:null,point:{x:c.x+g.x,y:c.y+g.y}}],c,se(e.at,null,u.at,d),n,r,{targetAligns:mt,areaAlign:"center"});return m===null?null:{kind:"move-drag",annotationId:o,translation:{x:h.normalizeToPanelExtent(m.point.x-c.x,d.width),y:h.normalizeToPanelExtent(m.point.y-c.y,d.height)},placement:m}}resolveTextPreview(e,t,n,r){const{annotationId:o,press:a}=this.params,{scene:i,panelRect:d,measuredBoxes:u}=r,c=i.textAnnotations.find(f=>f.id===o);if(c===void 0)return null;const g=(0,p.readAnnotationBox)({kind:"text",annotation:c},d,u);if(g===null)return null;const m=(0,p.projectBoxToPanel)(g,d),v={x:t.x-a.x,y:t.y-a.y},x=this.resolvePlacement(Bt(m,e.align,v),(0,p.readRectPoint)(m,e.align),se(e.at,e.align,c.at,d),n,r,{targetAligns:Ze});return x===null?null:{kind:"move-drag",annotationId:o,translation:Ht(x,m,e.align,d),placement:x}}resolvePlacement(e,t,n,r,o,a){const{annotationId:i,engine:d,anchorResolver:u,editorStore:c,offsetOnly:g=!1}=this.params,{spec:m,scene:v,panelRect:x,frameElement:f,layers:y,coordSystem:C,measuredBoxes:S,readObservationBox:b}=o,T=new Set([i,...(0,p.collectDependentAnnotationIds)(m,i)]),E=h.includePointInBounds(h.readContainerFractionBoundsFor(x,f),{x:h.normalizeToPanelExtent(t.x,x.width),y:h.normalizeToPanelExtent(t.y,x.height)}),A=c.getState(),M=this.params.previous?.()??l.readMovedAnnotationFor(l.readStanding(A,"move-drag"),i)?.placement,N=!g&&ee(r,A.snapping);return(0,p.resolvePointPlacement)({sourcePoints:e,current:r.altKey&&!g?null:n,panelRect:x,bounds:E,engine:d,layers:y,coordSystem:C,resolver:u,readObservationBox:b,annotationTargets:N?[]:ke(v,T,x,S),snapDistance:8,releaseDistance:12,revealDistance:160,previous:M?.type==="snapped"?M.target:null,detachDistance:g?Number.POSITIVE_INFINITY:40,targetAligns:a.targetAligns,areaAlign:a.areaAlign,areaSnapDistance:16,purpose:"pin",allow:{observation:!N,annotation:!N,free:!g},currentOnly:g})}},Ae=(e,t,n,r)=>{if(e.anchor.anchorType!=="annotation"||!(0,p.collectDependentAnnotationIds)(t,n).has(e.anchor.ref))return e;const{point:o,sourceAlign:a}=e,i=Math.max(0,Math.min(1,h.normalizeToPanelExtent(o.x,r.width))),d=Math.max(0,Math.min(1,h.normalizeToPanelExtent(o.y,r.height)));return{type:"free",anchor:{anchorType:"panel",x:i,y:d},sourceAlign:a,point:{x:i*r.width,y:d*r.height},nearby:[]}},$n={snapDistance:8,releaseDistance:12,revealDistance:160,detachDistance:40,targetGapPx:p.ARROW_TARGET_GAP_PX,targetAligns:mt,areaAlign:"auto",annotationAreaAlign:"auto",areaSnapDistance:16,purpose:"pin"},bs=new Set,ue=(e,t,n)=>{const r=t.getBoundingClientRect(),o=h.readFrameScale(t,r.width);return{x:(e.x-r.left)/o-n.x,y:(e.y-r.top)/o-n.y}},Cs=({start:e,startObservationIndex:t},n,r)=>{const{panelRect:o}=n;return e.anchorType==="panel"?{x:e.x*o.width,y:e.y*o.height,width:0,height:0}:jn(e,t,{...n,anchorResolver:r})},Yn=({start:e,startObservationIndex:t,point:n,free:r,previous:o,inputs:a,engine:i,anchorResolver:d})=>{const{scene:u,panelRect:c,frameElement:g,layers:m,coordSystem:v,measuredBoxes:x,readObservationBox:f}=a,y=Cs({start:e,startObservationIndex:t},a,d);if(y===null)return null;const C=Ts(e,y),S=e.anchorType==="annotation"?new Set([e.ref]):bs,b=(0,p.resolvePointPlacement)({...$n,sourcePoints:[{align:null,point:n}],current:null,panelRect:c,bounds:h.readContainerFractionBoundsFor(c,g),engine:i,layers:m,coordSystem:v,resolver:d,readObservationBox:f,annotationTargets:r?[]:ke(u,S,c,x),previous:o?.type==="snapped"?o.target:null,facing:C===null?y:{...C,width:0,height:0},allow:{observation:!r,annotation:!r,free:!0},excludedObservation:e.anchorType==="observation"&&e.layerId!==void 0&&t!==void 0?{layerId:e.layerId,observationIndex:t}:void 0});if(b===null)return null;const T=b.point;if(C!==null)return{placement:b,startPoint:C,endPoint:T};if(e.anchorType==="observation"&&y.width===0&&y.height===0)return{placement:b,startPoint:{x:y.x,y:y.y},endPoint:T};const E=(0,p.readFacingAlign)(y,As(b)??{x:T.x,y:T.y,width:0,height:0}),A=(0,p.readOutwardGapOffset)(E,p.ARROW_TARGET_GAP_PX),M=(0,p.readRectPoint)(y,E);return{placement:b,startPoint:{x:M.x+(A?.x??0),y:M.y+(A?.y??0)},endPoint:T}},Ts=(e,t)=>{if(e.anchorType==="panel")return{x:t.x,y:t.y};if(!("align"in e)||e.align==="auto")return null;const n=e.align??"center",r=(0,p.readOutwardGapOffset)(n,p.ARROW_TARGET_GAP_PX),o=(0,p.readRectPoint)(t,n);return{x:o.x+(r?.x??0),y:o.y+(r?.y??0)}},As=e=>e.type!=="snapped"||e.landing!=="area"?null:e.target.type==="annotation"?e.target.rect:e.target.box,Ps=(e,t)=>{if(t===null)return!1;if(e.anchorType==="observation"&&t.anchorType==="observation"){const n=t.layerId??e.layerId;return(0,p.areAnchorsEqual)({...e,align:void 0},{...t,align:void 0,layerId:n})}return e.anchorType==="annotation"&&t.anchorType==="annotation"&&e.ref===t.ref},Is=class extends pe{constructor(...e){super(...e),this.kind="arrow-endpoint-drag"}readOwn(e){const{annotationId:t,endpoint:n}=this.params;return l.readDraggedArrowEndpointFor(l.readStanding(e,"arrow-endpoint-drag"),t,n)}resolvePreview(e,t){const{annotationId:n,endpoint:r,press:o,readInputs:a,engine:i,anchorResolver:d,editorStore:u}=this.params,c=a(),{spec:g,arrow:m,scene:v,panelRect:x,layers:f,coordSystem:y,measuredBoxes:C,readObservationBox:S}=c,b=Te(g,n,r);if(b===null)return null;const T={x:e.x-o.x,y:e.y-o.y},E=(0,p.projectAnchorToPanel)(m[r],x),A=h.includePointInBounds(h.readContainerFractionBoundsFor(x,c.frameElement),{x:h.normalizeToPanelExtent(E.x,x.width),y:h.normalizeToPanelExtent(E.y,x.height)}),M=r==="start"?"end":"start",N=Te(g,n,M),G=N===null?void 0:it(N,m[M],{scene:v,panelRect:x,measuredBoxes:C,readObservationBox:S,layers:f,coordSystem:y,anchorResolver:d}),R=new Set([n,...(0,p.collectDependentAnnotationIds)(g,n)]),j=u.getState(),P=this.readOwn(j)?.placement,k=ee(t,j.snapping),O=W=>(0,p.resolvePointPlacement)({...$n,...W?{}:{areaAlign:void 0,annotationAreaAlign:void 0},sourcePoints:[{align:null,point:{x:E.x+T.x,y:E.y+T.y}}],current:k?null:se(b,null,m[r],x,p.ARROW_TARGET_GAP_PX),panelRect:x,bounds:A,engine:i,layers:f,coordSystem:y,resolver:d,readObservationBox:S,annotationTargets:k?[]:ke(v,R,x,C),previous:P?.type==="snapped"?P.target:null,facing:G,allow:{observation:!k,annotation:!k,free:!0}}),I=O(!0),F=I?.type==="snapped"&&I.landing==="area"&&Ps(I.anchor,N)?O(!1):I;return F===null?null:{kind:"arrow-endpoint-drag",annotationId:n,endpoint:r,placement:F}}commit({endpoint:e,placement:t}){const{annotationId:n,dispatch:r,readInputs:o}=this.params,{spec:a,panelRect:i}=o(),d=Te(a,n,e);if(d===null)return;const u=Ae(t,a,n,i).anchor;_n(d,u)||r(new p.UpdateAnnotationCommand({kind:"arrow",id:n,patch:En(e,u)}))}},Es=({annotationId:e,arrow:t,panelRect:n,frameElement:r})=>{const{commands:o,anchorResolver:a}=l.useGraphContext(),{engine:i}=l.useHoverContext(),d=l.useEditorStore(),u=l.useSceneSelector((0,J.useShallow)(f=>({spec:f.spec.annotations,layers:f.layers,coordSystem:f.coordSystem}))),c=l.useResolvedAnnotations(n),g=l.useMeasuredBoxes(),m=l.usePaintedObservationBoxes(n),v=l.useLatestRef({...u,arrow:t,scene:c,panelRect:n,frameElement:r,measuredBoxes:g,readObservationBox:m}),x=(0,w.useRef)(null);return(0,w.useEffect)(()=>()=>x.current?.finish(!1),[]),(0,w.useCallback)(f=>({onPointerDown:y=>{if(y.button===0&&x.current===null){try{y.currentTarget.setPointerCapture(y.pointerId)}catch{return}y.currentTarget.focus({preventScroll:!0}),y.preventDefault(),x.current=new Is({handle:y.currentTarget,pointerId:y.pointerId,annotationId:e,endpoint:f,press:{x:y.clientX,y:y.clientY},readInputs:()=>v.current,editorStore:d,engine:i,anchorResolver:a,dispatch:o.dispatch,onSettled:()=>{x.current=null}}),x.current.start()}}}),[e,v,d,i,a,o])},js=[" ","Enter"],zt=4,ks=({annotationId:e,arrow:t,panelRect:n,frameElement:r})=>{const{commands:o}=l.useGraphContext(),a=l.useEditorStore(),i=l.useSceneSelector(c=>c.spec.annotations),d=l.useLatestRef(i),u=l.useLatestRef(o.dispatch);return(0,w.useEffect)(()=>()=>{for(const c of dt)Wt({editorStore:a,annotationId:e,endpoint:c,annotations:d.current,dispatch:u.current})},[a,e,d,u]),(0,w.useCallback)(c=>({onKeyDown:g=>{if(g.altKey||g.ctrlKey||g.metaKey||g.shiftKey)return;const m=a.getState(),v=l.readDraggedArrowEndpointFor(l.readStanding(m,"arrow-endpoint-drag"),e,c);if(js.includes(g.key)){if(g.preventDefault(),g.repeat)return;if(v!==null){Wt({editorStore:a,annotationId:e,endpoint:c,annotations:i,dispatch:o.dispatch});return}const S=In(i,e,c);if(S===null)return;m.claimInteraction({kind:"arrow-endpoint-drag",annotationId:e,endpoint:c,placement:Lt(S,t[c],n)});return}if(v===null)return;const x=v.placement.anchor;if(x.anchorType!=="panel")return;const f=Rs(g.key,n);if(f===null)return;g.preventDefault();const{anchor:y,point:C}=Ha({anchor:x,point:(0,p.toPanelCursor)(v.placement.point,n),delta:f,bounds:h.readContainerFractionBoundsFor(n,r)});m.claimInteraction({kind:"arrow-endpoint-drag",annotationId:e,endpoint:c,placement:Lt(y,C,n)})}}),[e,i,t,n,r,a,o])},Wt=({editorStore:e,annotationId:t,endpoint:n,annotations:r,dispatch:o})=>{const a=e.getState(),i=l.readDraggedArrowEndpointFor(l.readStanding(a,"arrow-endpoint-drag"),t,n);if(i===null)return;a.releaseInteraction("arrow-endpoint-drag");const d=In(r,t,n);d===null||_n(d,i.placement.anchor)||o(new p.UpdateAnnotationCommand({kind:"arrow",id:t,patch:En(n,i.placement.anchor)}))},Rs=(e,t)=>{const n=h.normalizeToPanelExtent(zt,t.width),r=h.normalizeToPanelExtent(zt,t.height);switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-r};case"ArrowDown":return{x:0,y:r};default:return null}},Ls=e=>{const t=h.useSelectedAnnotationId(),n=_s(t),r=Ds(e.panelRect,t),o=Fs(t);if(n===null||r===null)return null;const a=o.dragged===null?r:ct(r,o.dragged,e.panelRect);return(0,s.jsx)(Os,{arrow:n,committed:r,live:a,settled:o.dragged===null&&!o.moving,moving:o.moving,...e})},Os=({arrow:e,committed:t,live:n,settled:r,moving:o,panelRect:a,frameElement:i})=>{const d=l.useI18n(),u=Es({annotationId:e.id,arrow:t,panelRect:a,frameElement:i}),c=ks({annotationId:e.id,arrow:t,panelRect:a,frameElement:i});return(0,s.jsxs)("div",{"data-testid":"arrow-selection","data-annotation-id":e.id,children:[r&&(0,s.jsx)(ms,{arrow:e,arrowBox:Wa(t.start,t.end,a),panelRect:a,frameElement:i}),!o&&dt.map(g=>(0,s.jsx)(Ms,{endpoint:g,point:za(n[g],a),label:d(`graph.annotations.arrowToolbar.moveEndpoint.${g}`),dragHandlers:u(g),keyboardHandlers:c(g)},g))]})},Ms=({endpoint:e,point:t,label:n,dragHandlers:r,keyboardHandlers:o})=>(0,s.jsx)("div",{"aria-label":n,className:vs,"data-testid":"arrow-endpoint-handle","data-endpoint":e,role:"button",style:{left:t.x,top:t.y},tabIndex:0,...r,...o}),_s=e=>{const t=l.useSceneSelector(n=>n.spec.annotations.arrows);return e===null?null:t.find(n=>n.id===e)??null},Ds=(e,t)=>{const n=l.useResolvedAnnotations(e).arrows;return t===null?null:n.find(r=>r.id===t)??null},Fs=e=>l.useEditorState((0,J.useShallow)(t=>{if(e===null)return{dragged:null,moving:!1};const n=l.readStanding(t,"arrow-endpoint-drag");return{dragged:n?.annotationId===e?n:null,moving:l.readMovedAnnotationFor(l.readStanding(t,"move-drag"),e)!==null}})),qn=({client:e,altKey:t,frameElement:n,inputs:r,editorStore:o,selectionStore:a,engine:i,anchorResolver:d,dispatch:u})=>{const c=o.getState(),g=l.readStanding(c,"arrow-draw");if(g===null)return;const m=n.getBoundingClientRect();if(e.x<m.left||e.x>m.right||e.y<m.top||e.y>m.bottom){c.releaseInteraction("arrow-draw"),c.setPlotMenu(null),a.getState().clearSelection();return}const v=Yn({start:g.start,startObservationIndex:g.startObservationIndex,point:ue(e,n,r.panelRect),free:ee({altKey:t},c.snapping),previous:g.placement,inputs:r,engine:i,anchorResolver:d});if(v===null||l.isArrowTooShort(v.startPoint,v.endPoint))return;const x=new p.AddAnnotationCommand({kind:"arrow",annotation:{...p.ARROW_DEFAULTS,...l.arrowHeads(g.heads),start:g.start,end:v.placement.anchor}});u(x),c.releaseInteraction("arrow-draw");const{anchor:f}=v.placement;l.startsOnTarget(g)?f.anchorType==="panel"?c.setPlotMenu({x:f.x,y:f.y,arrowId:x.params.annotation.id}):(c.setPlotMenu(null),a.getState().setSelection([x.target])):c.setPlotMenu(null)},Ns="_1vsi7qw1",Gs="_1vsi7qw2",Bs="_1vsi7qw3";var Vt=24,Hs=new Set,Ut=new WeakMap,Xt=(e,t)=>{if(e.coordSystem.type==="polar")return[];const{scene:n,panelRect:r,measuredBoxes:o}=e;return[...ke(n,Hs,r,o).map(({id:a,rect:i})=>({key:`annotation:${a}`,rect:i,draw:{start:{anchorType:"annotation",ref:a,align:"auto"}}})),...Us(e,t)]},zs=(e,t,n=32)=>{const r=[];for(const o of e){const a=Zn(t,o.rect);a<=n&&r.push({target:o,distance:a})}return r.sort((o,a)=>o.distance-a.distance).map(({target:o})=>o)},Ws=(e,t,n)=>{const r=[];for(const o of e)for(const{point:a,align:i}of Vs(o.rect,n,o.snapAligns)){const d=r.some(c=>Math.hypot(c.point.x-a.x,c.point.y-a.y)<16),u=t.some(c=>c.key!==o.key&&Zn(a,c.rect)<16/2);!d&&!u&&r.push({point:a,target:o,draw:Xs(o.draw,i)})}return r},Vs=(e,t,n)=>{const r=e.x+e.width/2,o=e.y+e.height/2,a={x:r,y:e.y-10},i={x:r,y:e.y+e.height+10},d=u=>u.x>=t.x&&u.x<=t.x+t.width&&u.y>=t.y&&u.y<=t.y+t.height;if(n===void 0&&e.width<Vt&&e.height<Vt){const u=d(a)?a:i;return d(u)?[{point:u,align:"auto"}]:[]}return[{point:a,align:"top"},{point:{x:e.x+e.width+10,y:o},align:"right"},{point:i,align:"bottom"},{point:{x:e.x-10,y:o},align:"left"}].filter(({point:u,align:c})=>(n===void 0||n.includes(c))&&d(u))},Us=({layers:e,panelRect:t,readObservationBox:n,coordSystem:r},o)=>{const a=Ut.get(n);if(a!==void 0&&a.layers===e&&a.resolver===o&&a.coordSystem===r&&a.panelWidth===t.width&&a.panelHeight===t.height)return a.targets;const i=[];for(const d of e){if(!d.interactive)continue;const u=(0,p.createObservationAnchorBuilder)(d),c=o.resolveSnapAligns(d.geom,r);if((0,p.isPointTarget)(c))continue;const g=d.data.size();for(let m=0;m<g;m+=1){const v=d.data.getAt(m),x=n({layerId:d.id,observationIndex:m}),f=v===null?null:u(v);if(x===null||f===null)continue;const y=(0,p.projectBoxToPanel)(x,t);y.width<=0||y.height<=0||i.push({key:`observation:${d.id}:${m}`,rect:y,snapAligns:c,draw:{start:{...f,anchorType:"observation",align:"auto"},startObservationIndex:m}})}}return Ut.set(n,{layers:e,resolver:o,coordSystem:r,panelWidth:t.width,panelHeight:t.height,targets:i}),i},Xs=(e,t)=>{const{start:n}=e;return n.anchorType==="observation"||n.anchorType==="annotation"?{...e,start:{...n,align:t}}:e},Zn=(e,t)=>{const n=Math.max(t.x-e.x,0,e.x-(t.x+t.width)),r=Math.max(t.y-e.y,0,e.y-(t.y+t.height));return Math.hypot(n,r)},ze=[],Ks=({frameElement:e,panelRect:t})=>{const{chartId:n,commands:r,selectionStore:o,anchorResolver:a}=l.useGraphContext(),{engine:i}=l.useHoverContext(),d=l.useEditorStore(),u=h.useStartArrowDraw(),c=ie(t,e),g=c.current,m=l.useStyleReaderTree().snapTarget.nearby().resolve(),v=l.MODE_RULES[l.useGraphMode()].showMenuTriggerOnHover,x=l.useSceneSelector(R=>R.coordSystem.type==="polar"),f=l.useGraphSelection().length>0,y=l.useEditorState(R=>R.standingInteraction!==null||R.plotMenu!==null||R.caret!==null),C=v&&!x&&!f&&!y,[S,b]=(0,w.useState)(ze),T=(0,w.useRef)(null),E=(0,w.useRef)(null);if((0,w.useEffect)(()=>{if(!C){T.current=null,b(ze);return}let R=null;const j=()=>{R=null;const k=T.current;if(k===null)return;const O=c.current,I=k.onChart?zs(Xt(O,a),ue(k.client,e,O.panelRect)):ze;b(F=>(0,q.isEqual)(F,I)?F:I)},P=k=>{k.buttons===0&&(T.current={client:{x:k.clientX,y:k.clientY},onChart:k.pointerType!=="touch"&&h.isWithinChart(k.target,e,n)},R??=requestAnimationFrame(j))};return j(),document.addEventListener("pointermove",P,{passive:!0}),()=>{document.removeEventListener("pointermove",P),R!==null&&cancelAnimationFrame(R)}},[C,n,e,c,g.layers,g.coordSystem,g.scene,g.panelRect,g.measuredBoxes,g.readObservationBox,a]),(0,w.useEffect)(()=>{const R=I=>{try{e.releasePointerCapture(I)}catch{}},j=I=>{const F=E.current;return F!==null&&F.pointerId===I.pointerId?F:null},P=I=>{const F=j(I);F===null||F.dragging||(F.dragging=Xn(F.press,{x:I.clientX,y:I.clientY}))},k=I=>{const F=j(I);F!==null&&(E.current=null,R(I.pointerId),F.dragging&&qn({client:{x:I.clientX,y:I.clientY},altKey:I.altKey,frameElement:e,inputs:c.current,editorStore:d,selectionStore:o,engine:i,anchorResolver:a,dispatch:r.dispatch}))},O=I=>{j(I)!==null&&(E.current=null,R(I.pointerId),d.getState().releaseInteraction("arrow-draw"))};return document.addEventListener("pointermove",P),document.addEventListener("pointerup",k),document.addEventListener("pointercancel",O),e.addEventListener("lostpointercapture",O),()=>{document.removeEventListener("pointermove",P),document.removeEventListener("pointerup",k),document.removeEventListener("pointercancel",O),e.removeEventListener("lostpointercapture",O);const I=E.current;I!==null&&(E.current=null,R(I.pointerId),d.getState().releaseInteraction("arrow-draw"))}},[e,c,d,o,i,a,r]),!C||S.length===0)return null;const A=h.readContainerFractionBoundsFor(t,e),M={x:A.minX*t.width,y:A.minY*t.height,width:(A.maxX-A.minX)*t.width,height:(A.maxY-A.minY)*t.height},N=Xt(g,a),G=(R,j)=>{if(R.button===0){R.preventDefault();try{e.setPointerCapture(R.pointerId)}catch{}E.current={pointerId:R.pointerId,press:{x:R.clientX,y:R.clientY},dragging:!1},u(j,{clientX:R.clientX,clientY:R.clientY})}};return(0,s.jsx)("div",{className:Ns,"aria-hidden":"true","data-testid":"connector-dots",children:Ws(S,N,M).map(({point:R,target:j,draw:P})=>(0,s.jsx)("span",{className:Gs,style:{left:t.x+R.x,top:t.y+R.y,width:16,height:16,margin:-16/2,color:m.stroke},"data-testid":"connector-dot","data-target":j.key,...h.stampChartChrome(n),onPointerDown:k=>G(k,P),children:(0,s.jsx)("span",{className:Bs,style:{width:m.size,height:m.size,borderWidth:m.strokeWidth,borderColor:m.stroke,opacity:m.alpha}})},`${j.key}:${R.x}:${R.y}`))})},$s=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M4 9h16m-4-4 4 4"}),(0,s.jsx)("path",{d:"M20 15H4m4 4-4-4"})]})}),Jn="var(--ydgo3h0)";var Ys="ydgo3h1",qs="ydgo3h2",Zs="ydgo3h3",Kt={small:2,medium:3,large:5},Js=(e,t)=>{const n=Object.keys(Kt),r=n.find(o=>{const a=Kt[o];return a===p.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].arrow.strokeWidth?!1:e.strokeWidth===a&&Qs(e.label,p.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].label,t)});return r!==void 0?r:n.find(o=>p.DIFFERENCE_ARROW_SIZE_DECLARATIONS[o].arrow.strokeWidth===e.strokeWidth)},Qs=(e,t,n)=>!(t.fontSize!==void 0&&e.fontSize!==t.fontSize*n||t.fontWeight!==void 0&&e.fontWeight!==t.fontWeight||t.paddingInline!==void 0&&e.paddingInline!==t.paddingInline||t.paddingBlock!==void 0&&e.paddingBlock!==t.paddingBlock||t.strokeWidth!==void 0&&e.strokeWidth!==t.strokeWidth),ei="q7gcrz0",ti="q7gcrz1";var ni=["absoluteDifference","relativeDifference","proportion"],$t=["absoluteDifference","relativeDifference"],ri=["relativeDifference","proportion"],oi={absoluteDifference:"graph.annotations.differenceArrowToolbar.labelKind.absoluteDifference",relativeDifference:"graph.annotations.differenceArrowToolbar.labelKind.relativeDifference",proportion:"graph.annotations.differenceArrowToolbar.labelKind.proportion"},ai=e=>{const{formattingLocale:t}=l.useGraphContext(),n=l.useSceneSelector(o=>o.config.parsingLocale),r=t??n;return(0,w.useMemo)(()=>{const o=(0,p.areEndpointsComparable)(e.start,e.end);return ni.filter(a=>o||!$t.includes(a)||a===e.label).map(a=>({kind:a,key:oi[a],preview:(0,p.formatDifferenceLabel)({locale:r,kind:a,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat}),pickable:o||!$t.includes(a),suspect:ri.includes(a)&&e.start.measurementValue===0}))},[e,r])},Yt=[{id:"small",key:"graph.annotations.differenceArrowToolbar.size.small"},{id:"medium",key:"graph.annotations.differenceArrowToolbar.size.medium"},{id:"large",key:"graph.annotations.differenceArrowToolbar.size.large"}],si=({arrow:e,color:t,labelBox:n,start:r,end:o,panelRect:a,frameElement:i})=>{const d=l.useI18n(),{commands:u}=l.useGraphContext(),c=l.useSceneSelector(I=>I.spec.styles.overrides),g=l.useSceneSelector(I=>(0,p.readStyleCoord)(I.spec)),m=h.useToolbarPopups(),v=ai(e),x=l.useStyleReaderTree(),f=(0,p.resolveDifferenceArrowAnnotationStyle)(x,e.id),y=x.graph().get("textScale"),C=(0,w.useMemo)(()=>({target:"annotation",kind:"differenceArrow",annotation:e.id}),[e.id]),S=(0,w.useMemo)(()=>({...C,part:"label"}),[C]),b=v.find(I=>I.kind===e.label),T=v.some(I=>I.pickable&&I.kind!==e.label),E=Yt.find(I=>I.id===Js(f,y)),A=(I,F)=>{u.dispatch(new p.UpdateAnnotationCommand({kind:"differenceArrow",id:e.id,patch:I}),F)},M=I=>({...(0,p.findStyleRule)(c,{select:C},g)?.declarations,...I}),N=I=>({...(0,p.findStyleRule)(c,{select:S},g)?.declarations,...I}),G=I=>{A(I),m.close()},R=()=>{u.dispatch(new p.RemoveAnnotationCommand({id:e.id})),i.focus({preventScroll:!0})},j=I=>u.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:C,declarations:M({stroke:I})}}),{transient:!0}),P=()=>A({start:e.end.anchor,end:e.start.anchor}),k=I=>()=>G({label:I}),O=I=>()=>{const F=p.DIFFERENCE_ARROW_SIZE_DECLARATIONS[I];u.dispatch(new p.SetDifferenceArrowStyleCommand({annotationId:e.id,arrow:M(F.arrow),label:(0,p.omitLegacyDifferenceArrowLabelPlate)(N(F.label))})),m.close()};return(0,s.jsxs)(h.SelectionToolbar.Root,{frameElement:i,anchorBox:n,avoidBoxes:[qt(r),qt(o)],panelRect:a,label:d("graph.annotations.differenceArrowToolbar.label"),testId:"difference-arrow-toolbar",children:[(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:d("graph.annotations.differenceArrowToolbar.labelKind.ariaLabel"),trigger:(0,s.jsx)(ii,{option:b}),disabled:!T,...m.bind("labelKind"),children:v.map(I=>(0,s.jsxs)(h.FloatingToolbar.MenuItem,{selected:I.kind===e.label,disabled:!I.pickable,onClick:k(I.kind),children:[(0,s.jsx)("span",{children:d(I.key)}),(I.suspect||!I.pickable)&&(0,s.jsx)("span",{"aria-label":d(I.pickable?"graph.annotations.differenceArrowToolbar.labelKind.suspectValue":"graph.annotations.differenceArrowToolbar.labelKind.incomparableEnds"),className:"q7gcrz2",role:"img",children:"⚠"}),(0,s.jsx)("span",{className:ti,children:I.preview})]},I.kind))}),(0,s.jsx)(h.FloatingToolbar.Separator,{}),(0,s.jsx)(h.FloatingToolbar.ColorPicker,{color:t,label:d("graph.annotations.differenceArrowToolbar.color"),onChange:j,...m.bind("color"),children:(0,s.jsx)(h.FloatingToolbar.Swatch,{color:t})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:d("graph.annotations.differenceArrowToolbar.size.ariaLabel"),trigger:E===void 0?"":d(E.key),...m.bind("size"),children:Yt.map(I=>(0,s.jsx)(h.FloatingToolbar.MenuItem,{selected:I.id===E?.id,onClick:O(I.id),children:d(I.key)},I.id))}),(0,s.jsx)(h.FloatingToolbar.Separator,{}),(0,s.jsx)(h.FloatingToolbar.Button,{label:d("graph.annotations.differenceArrowToolbar.swap"),onClick:P,children:(0,s.jsx)($s,{size:"sm",title:""})}),(0,s.jsx)(h.FloatingToolbar.Button,{label:d("graph.annotations.differenceArrowToolbar.remove"),onClick:R,children:(0,s.jsx)(h.TrashIcon,{size:"sm",title:""})})]})},ii=({option:e})=>{const t=l.useI18n();return e===void 0?null:(0,s.jsx)("span",{className:ei,children:t(e.key)})},qt=e=>({x:e.x-24/2,y:e.y-24/2,width:24,height:24}),Qn=e=>e==="start"?"end":"start",er=({dispatch:e,arrow:t,endpoint:n,anchor:r})=>{(0,p.areAnchorsEqual)(r,t[n].anchor)||e(new p.UpdateAnnotationCommand({kind:"differenceArrow",id:t.id,patch:{[n]:r}}))},li=({clientPoint:e,panelOrigin:t,panelRect:n,engine:r,layers:o,coordSystem:a,resolver:i,fixedAnchor:d,align:u})=>{const c=(0,p.resolvePointPlacement)({sourcePoints:[{align:null,point:{x:Math.max(0,Math.min(e.x-t.x,n.width)),y:Math.max(0,Math.min(e.y-t.y,n.height))}}],current:null,panelRect:n,engine:r,layers:o,coordSystem:a,resolver:i,readObservationBox:()=>null,annotationTargets:[],snapDistance:null,detachDistance:0,targetAligns:u===void 0?[]:[u],purpose:"value",allow:{observation:!0,annotation:!1,free:!1},rejectObservation:g=>{if((0,p.areAnchorsEqual)(g,d))return!0;const m=o.find(v=>v.id===g.layerId);return m!==void 0&&(0,p.areSameStackEndpoints)(m,g,d)}});return c===null||c.type!=="snapped"||c.target.type!=="observation"?null:c.target.point},di=class extends pe{constructor(...e){super(...e),this.kind="difference-arrow-endpoint-drag"}readOwn(e){const{endpoint:t,readInputs:n}=this.params;return l.readDraggedDifferenceArrowEndpointFor(l.readStanding(e,"difference-arrow-endpoint-drag"),n().arrow.id,t)}resolvePreview(e){const{endpoint:t,readInputs:n,engine:r,anchorResolver:o}=this.params,{arrow:a,panelOrigin:i,panelRect:d,layers:u,coordSystem:c}=n(),g=li({clientPoint:e,panelOrigin:i,panelRect:d,engine:r,layers:u,coordSystem:c,resolver:o,fixedAnchor:a[Qn(t)].anchor,align:a[t].anchor.align});return g===null?null:{kind:"difference-arrow-endpoint-drag",annotationId:a.id,endpoint:t,point:g}}commit({point:e,endpoint:t}){const{dispatch:n,readInputs:r}=this.params;er({dispatch:n,arrow:r().arrow,endpoint:t,anchor:e.anchor})}},ci=({arrow:e,panelOrigin:t,panelRect:n,onClick:r})=>{const{commands:o,anchorResolver:a}=l.useGraphContext(),{engine:i}=l.useHoverContext(),d=l.useEditorStore(),u=l.useLatestRef({arrow:e,panelOrigin:t,panelRect:n,...l.useSceneSelector((0,J.useShallow)(m=>({layers:m.layers,coordSystem:m.coordSystem})))}),c=l.useLatestRef(r),g=(0,w.useRef)(null);return(0,w.useEffect)(()=>()=>g.current?.finish(!1),[]),(0,w.useCallback)(m=>({onPointerDown:v=>{if(v.button===0&&g.current===null){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{return}v.currentTarget.focus({preventScroll:!0}),v.preventDefault(),g.current=new di({handle:v.currentTarget,pointerId:v.pointerId,press:{x:v.clientX,y:v.clientY},endpoint:m,readInputs:()=>u.current,editorStore:d,engine:i,anchorResolver:a,dispatch:o.dispatch,onClick:x=>c.current(x),onSettled:()=>{g.current=null}}),g.current.start()}}}),[u,c,d,i,a,o])},ui=[" ","Enter"],hi=({arrow:e})=>{const{commands:t,anchorResolver:n}=l.useGraphContext(),r=l.useEditorStore(),{layers:o,coordSystem:a,mainAxis:i}=l.useSceneSelector((0,J.useShallow)(u=>({layers:u.layers,coordSystem:u.coordSystem,mainAxis:(0,p.readMainAxis)(u.coordSystem)}))),d=e.id;return(0,w.useEffect)(()=>()=>{const u=r.getState();l.readStanding(u,"difference-arrow-endpoint-drag")?.annotationId===d&&u.releaseInteraction("difference-arrow-endpoint-drag")},[r,d]),(0,w.useCallback)(u=>({onKeyDown:c=>{if(c.altKey||c.ctrlKey||c.metaKey||c.shiftKey)return;const g=r.getState(),m=l.readDraggedDifferenceArrowEndpointFor(l.readStanding(g,"difference-arrow-endpoint-drag"),e.id,u);if(ui.includes(c.key)){if(c.preventDefault(),c.repeat)return;if(m===null)return g.claimInteraction({kind:"difference-arrow-endpoint-drag",annotationId:e.id,endpoint:u,point:e[u]});g.releaseInteraction("difference-arrow-endpoint-drag"),er({dispatch:t.dispatch,arrow:e,endpoint:u,anchor:m.point.anchor});return}if(m===null)return;const v=gi(c.key,i);if(v===null)return;c.preventDefault();const x=pi({arrow:e,endpoint:u,from:m.point.anchor,move:v,layers:o,coordSystem:a,resolver:n});x!==null&&g.claimInteraction({kind:"difference-arrow-endpoint-drag",annotationId:e.id,endpoint:u,point:x})}}),[e,r,t,n,o,a,i])},gi=(e,t)=>{const n=e==="ArrowUp"||e==="ArrowDown";return!n&&!(e==="ArrowLeft"||e==="ArrowRight")?null:{axis:t==="x"===n?"cross":"main",step:e==="ArrowDown"||e==="ArrowRight"?1:-1}},pi=({arrow:e,endpoint:t,from:n,move:r,layers:o,coordSystem:a,resolver:i})=>{const d=o.find(g=>g.id===n.layerId);if(d===void 0)return null;const u=i.createLayerMeasurement(d);if(u===null)return null;const{align:c}=e[t].anchor;return(0,p.stepDifferenceArrowEndpoint)({layer:d,from:n,partner:e[Qn(t)].anchor,axis:r.axis,step:r.step,getObservationPoint:(g,m)=>(0,p.resolveObservationPoint)({resolver:i,layer:d,observation:g,observationIndex:m,coordSystem:a,align:c,measurement:u})})?.point??null},mi=e=>{const t=h.useSelectedAnnotationId(),n=l.useDifferenceArrowGeometries(),r=(0,w.useCallback)(o=>{const a=e.frameElement.querySelector('[data-testid="pointer-capture-layer"]');a!==null&&a.dispatchEvent(new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,button:0,clientX:o.x,clientY:o.y,pointerId:1,pointerType:"mouse"}))},[e.frameElement]);return(0,s.jsxs)(s.Fragment,{children:[t!==null&&(0,s.jsx)(vi,{annotationId:t,...e}),n.map(o=>o.id!==t&&!o.dragging?null:(0,s.jsx)(fi,{geometry:o,shown:o.id===t||o.dragging,keyboard:o.id===t,panelRect:e.panelRect,panelOrigin:e.panelOrigin,onClick:r},o.id))]})},vi=({annotationId:e,panelOrigin:t,...n})=>{const r=l.useDifferenceArrowGeometries(),o=(0,w.useMemo)(()=>r.find(a=>a.id===e),[r,e]);return o===void 0?null:(0,s.jsx)(xi,{committedArrow:o.committedArrow,color:o.color,labelCornerRadius:o.style.label.cornerRadius,committedLabelBox:o.committedLabelBox,labelBox:o.labelBox,start:o.start,end:o.end,dragging:o.dragging,...n})},xi=({committedArrow:e,color:t,labelCornerRadius:n,committedLabelBox:r,labelBox:o,start:a,end:i,panelRect:d,frameElement:u,dragging:c})=>{const g=je(l.useStyleReaderTree().editOutline.selected().resolve());return(0,s.jsxs)("div",{"data-testid":"difference-arrow-selection",style:(0,te.assignInlineVars)({[Jn]:g}),children:[!c&&(0,s.jsx)(si,{arrow:e,color:t,labelBox:r,start:a,end:i,panelRect:d,frameElement:u}),(0,s.jsx)("div",{"aria-hidden":"true",className:Zs,"data-testid":"difference-arrow-selection-label",style:{left:d.x+o.x-2,top:d.y+o.y-2,width:o.width+4,height:o.height+4,borderRadius:l.toBorderRadiusCss(n,2)}})]})},fi=({geometry:e,shown:t,keyboard:n,panelRect:r,panelOrigin:o,onClick:a})=>{const i=l.useEditorStore(),d=(0,w.useRef)(n),u=e.committedArrow.id;(0,w.useEffect)(()=>{if(d.current&&!n){const v=i.getState();l.readStanding(v,"difference-arrow-endpoint-drag")?.annotationId===u&&v.releaseInteraction("difference-arrow-endpoint-drag")}d.current=n},[n,i,u]);const c=ci({arrow:e.committedArrow,panelOrigin:o,panelRect:r,onClick:a}),g=hi({arrow:e.committedArrow}),m=je(l.useStyleReaderTree().editOutline.selected().resolve());return(0,s.jsxs)("div",{style:(0,te.assignInlineVars)({[Jn]:m}),children:[(0,s.jsx)(Zt,{endpoint:"start",point:e.start,panelRect:r,shown:t,keyboard:n,dragHandlers:c("start"),keyboardHandlers:g("start")}),(0,s.jsx)(Zt,{endpoint:"end",point:e.end,panelRect:r,shown:t,keyboard:n,dragHandlers:c("end"),keyboardHandlers:g("end")})]})},Zt=({endpoint:e,point:t,panelRect:n,shown:r,keyboard:o,dragHandlers:a,keyboardHandlers:i})=>(0,s.jsx)("div",{className:Ys,"data-testid":"difference-arrow-selection-handle","data-endpoint":e,"data-shown":r||void 0,role:"button",style:{left:n.x+t.x,top:n.y+t.y},tabIndex:o?0:-1,...a,...o?i:{},children:(0,s.jsx)("span",{"aria-hidden":"true",className:qs})}),tr=(e,t,n,{panelRect:r,frameElement:o,layers:a,readObservationBox:i})=>{const d=h.readContainerFractionBoundsFor(r,o),u=e.x*r.width,c=e.y*r.height,g=Math.max(d.minX*r.width,Math.min(d.maxX*r.width,t.x)),m=Math.max(d.minY*r.height,Math.min(d.maxY*r.height,t.y));return pt({rect:{x:Math.min(u,g),y:Math.min(c,m),width:Math.abs(g-u),height:Math.abs(m-c)},panelRect:r,bounds:d,layers:a,readObservationBox:i,mayEnclose:!n})},yi="s8eewu0",Jt="s8eewu1",Si=e=>{const t=l.useEditorStore(),{chartId:n}=l.useGraphContext(),r=l.useEditorState(a=>a.standingInteraction?.kind==="arrow-draw"||a.standingInteraction?.kind==="box-draw"),o=l.useEditorState(a=>{const i=l.readStanding(a,"arrow-draw");return i!==null&&l.startsOnTarget(i)});(0,w.useEffect)(()=>()=>{const a=t.getState().standingInteraction?.kind;(a==="arrow-draw"||a==="box-draw")&&t.getState().releaseInteraction(a)},[t]),(0,w.useEffect)(()=>{o&&e.focus({preventScroll:!0})},[o,e]),(0,w.useEffect)(()=>{if(!r)return;const a=i=>{if(i.key!=="Escape"||!h.isWithinChart(i.target,e,n)||h.isWithinMenu(i.target))return;const d=h.isWithinTextEntry(i.target),u=t.getState().caret!==null&&!h.isWithinChartChrome(i.target,n);if(d&&!u)return;const c=t.getState().standingInteraction?.kind;c!=="arrow-draw"&&c!=="box-draw"||(i.preventDefault(),t.getState().releaseInteraction(c))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[n,r,t,e])},wi=({frameElement:e,panelRect:t})=>{const n=l.useEditorState(b=>l.readStanding(b,"arrow-draw")),r=l.useEditorState(b=>l.readStanding(b,"box-draw")),o=l.useEditorStore(),{engine:a}=l.useHoverContext(),{anchorResolver:i}=l.useGraphContext(),d=ie(t,e);Si(e);const[u,c]=(0,w.useState)(null),g=n!==null||r!==null,m=n?.pointer?.x??r?.pointer?.x,v=n?.pointer?.y??r?.pointer?.y;(0,w.useEffect)(()=>{if(!g)return;const b=(j,P)=>{const k=e.getBoundingClientRect(),O=h.readFrameScale(e,k.width);c({x:Qt(j-k.left,0,k.width)/O,y:Qt(P-k.top,0,k.height)/O})},T=(j,P)=>{b(j.x,j.y);const k=o.getState(),O=l.readStanding(k,"arrow-draw"),I=l.readStanding(k,"box-draw");if(I!==null){const L=d.current,D=tr(I.start,ue(j,e,L.panelRect),ee({altKey:P},k.snapping),L);k.claimInteraction({...I,placement:D});return}if(O===null)return;const F=d.current,W=Yn({start:O.start,startObservationIndex:O.startObservationIndex,point:ue(j,e,F.panelRect),free:ee({altKey:P},k.snapping),previous:O.placement,inputs:F,engine:a,anchorResolver:i});if(W===null&&l.startsOnTarget(O)){k.releaseInteraction("arrow-draw");return}k.claimInteraction({...O,placement:W?.placement,startPoint:W?.startPoint})};if(m!==void 0&&v!==void 0){const j=l.readStanding(o.getState(),"arrow-draw");j!==null&&l.startsOnTarget(j)?T({x:m,y:v},!1):b(m,v)}let E=null,A=null;const M=()=>{E=null,A!==null&&cancelAnimationFrame(A),A=null},N=()=>{A=null;const j=E;E=null,j!==null&&T({x:j.clientX,y:j.clientY},j.altKey)},G=j=>{E=j,A??=requestAnimationFrame(N)},R=j=>{M(),T({x:j.clientX,y:j.clientY},j.altKey)};return document.addEventListener("pointermove",G,!0),document.addEventListener("pointerdown",R,!0),()=>{document.removeEventListener("pointermove",G,!0),document.removeEventListener("pointerdown",R,!0),M(),c(null)}},[g,m,v,e,o,d,a,i]);const x=bi(n,r,t);if(x===null||u===null)return null;const f=t.x+x.x,y=t.y+x.y,C=n?.placement?.type==="snapped"?n.placement.point:null,S=C===null?u:{x:t.x+C.x,y:t.y+C.y};return(0,s.jsx)("svg",{className:yi,children:r===null?(0,s.jsx)("line",{className:Jt,x1:f,y1:y,x2:S.x,y2:S.y}):(0,s.jsx)("rect",{className:Jt,fill:"none","data-testid":"box-draw-preview",x:r.placement===void 0?Math.min(f,u.x):t.x+r.placement.rect.x,y:r.placement===void 0?Math.min(y,u.y):t.y+r.placement.rect.y,width:r.placement?.rect.width??Math.abs(u.x-f),height:r.placement?.rect.height??Math.abs(u.y-y)})})},bi=(e,t,n)=>t!==null?{x:t.start.x*n.width,y:t.start.y*n.height}:e===null?null:e.startPoint!==void 0?e.startPoint:e.start.anchorType!=="panel"?null:{x:e.start.x*n.width,y:e.start.y*n.height},Qt=(e,t,n)=>Math.min(Math.max(e,t),n),Ci=({panelRect:e})=>{const t=l.useEditorState(d=>l.readStanding(d,"shape-resize-drag")),{shapes:n,images:r}=l.useResolvedAnnotations(e),o=l.useStyleReaderTree();if(t===null)return null;const a=t.annotationKind==="image"?r.find(d=>d.id===t.annotationId):void 0,i=t.annotationKind==="shape"?n.find(d=>d.id===t.annotationId):void 0;return i===void 0&&a===void 0?null:(0,s.jsxs)("svg",{"aria-hidden":"true",className:ht,width:e.width,height:e.height,style:{left:e.x,top:e.y},"data-testid":"shape-resize-preview","data-annotation-id":t.annotationId,children:[i!==void 0&&(0,s.jsx)(l.ShapeAnnotation,{shape:{...i,region:t.region},style:o.annotation.shape(i.id).resolve(),panel:e}),a!==void 0&&(0,s.jsx)(l.ImageAnnotation,{image:{...a,region:t.region},style:o.annotation.image(a.id).resolve(),panel:e})]})},Ti="var(--o49ib40)",Ai={sm:"o49ib41",md:"o49ib42"},Pi={horizontal:"o49ib43",diagonalDown:"o49ib44",diagonalUp:"o49ib45"},nr=({point:e,label:t,pull:n,size:r,attributes:o,dragHandlers:a,keyboardHandlers:i})=>{const d=je(l.useStyleReaderTree().editOutline.selected().resolve());return(0,s.jsx)("div",{"aria-label":t,className:Pi[n],role:"button",style:{left:e.x,top:e.y,...(0,te.assignInlineVars)({[Ti]:d})},tabIndex:0,...o,...a,...i,children:(0,s.jsx)("span",{"aria-hidden":"true",className:Ai[r]})})},Ii=({image:e,imageBox:t,panelRect:n,frameElement:r})=>{const o=l.useI18n(),a=h.useRemoveAnnotation(n),i=()=>{a(e.id),r.focus({preventScroll:!0})};return(0,s.jsxs)(h.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameElement:r,label:o("graph.annotations.imageToolbar.label"),testId:"image-toolbar",children:[(0,s.jsx)(h.StartArrowButton,{annotationId:e.id}),(0,s.jsx)(h.FloatingToolbar.Button,{label:o("graph.annotations.imageToolbar.remove"),onClick:i,children:(0,s.jsx)(h.TrashIcon,{size:"sm",title:""})})]})},Qe=[{width:0,key:"graph.annotations.shapeToolbar.border.none"},{width:2,key:"graph.annotations.shapeToolbar.border.thin"},{width:8,key:"graph.annotations.shapeToolbar.border.medium"},{width:16,key:"graph.annotations.shapeToolbar.border.thick"}],Ei=e=>[...Qe].reverse().find(t=>t.width<=e)??Qe[0],ji=({shape:e,shapeBox:t,panelRect:n,frameElement:r})=>{const o=l.useI18n(),{commands:a}=l.useGraphContext(),i=h.useRemoveAnnotation(n),d=l.useSceneSelector(b=>b.spec.styles.overrides),u=l.useSceneSelector(b=>(0,p.readStyleCoord)(b.spec)),c=h.useToolbarPopups(),g=l.useStyleReaderTree().annotation.shape(e.id).resolve(),m=Ei(g.strokeWidth),v=(0,w.useMemo)(()=>({target:"annotation",kind:"shape",annotation:e.id}),[e.id]),x=(b,T)=>{const E=(0,p.findStyleRule)(d,{select:v},u)?.declarations??{};a.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:v,declarations:{...E,...b}}}),T)},f=()=>{i(e.id),r.focus({preventScroll:!0})},y=b=>x({fill:b},{transient:!0}),C=b=>x({fillAlpha:b},{transient:!0}),S=b=>()=>{x({strokeWidth:b}),c.close()};return(0,s.jsxs)(h.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameElement:r,label:o("graph.annotations.shapeToolbar.label"),testId:"shape-toolbar",children:[(0,s.jsx)(h.FloatingToolbar.ColorPicker,{color:(0,p.toPaintColor)(g.fill),label:o("graph.annotations.shapeToolbar.color"),onChange:y,opacity:g.fillAlpha,onOpacityChange:C,...c.bind("color"),children:(0,s.jsx)(h.FloatingToolbar.Swatch,{color:(0,p.toPaintColor)(g.fill),opacity:g.fillAlpha})}),(0,s.jsx)(h.FloatingToolbar.Dropdown,{label:o("graph.annotations.shapeToolbar.border.ariaLabel"),trigger:(0,s.jsx)(Hn,{size:"sm",title:""}),...c.bind("border"),children:Qe.map(b=>(0,s.jsx)(h.FloatingToolbar.MenuItem,{selected:b.width===m?.width,onClick:S(b.width),children:o(b.key)},b.width))}),(0,s.jsx)(h.FloatingToolbar.Separator,{}),(0,s.jsx)(h.StartArrowButton,{annotationId:e.id}),(0,s.jsx)(h.FloatingToolbar.Button,{label:o("graph.annotations.shapeToolbar.remove"),onClick:f,children:(0,s.jsx)(h.TrashIcon,{size:"sm",title:""})})]})},et=({start:e,extent:t,moveStartEdge:n,delta:r,minExtent:o,bounds:a})=>{if(!Number.isFinite(r))return{start:e,extent:t};const i=a?.min??0,d=a?.max??1,u=e+t,c=Math.min(o,t);if(n){const v=Math.min(i,e),x=Math.min(Math.max(d,e),u-c),f=(0,q.clamp)(e+r,v,x);return{start:f,extent:u-f}}const g=Math.max(Math.min(i,u),e+c),m=Math.max(d,u);return{start:e,extent:(0,q.clamp)(u+r,g,m)-e}},ki=["top-left","top-right","bottom-right","bottom-left"];var Ri=({width:e,height:t})=>({x:h.normalizeToPanelExtent(16,e),y:h.normalizeToPanelExtent(16,t)}),Li=(e,t)=>({x:rr(t)?e.x:e.x+e.width,y:or(t)?e.y:e.y+e.height}),Oi=({region:e,corner:t,delta:n,minSize:r,bounds:o})=>{const a=et({start:e.x,extent:e.width,moveStartEdge:rr(t),delta:n.x,minExtent:r.x,...o===void 0?{}:{bounds:{min:o.minX,max:o.maxX}}}),i=et({start:e.y,extent:e.height,moveStartEdge:or(t),delta:n.y,minExtent:r.y,...o===void 0?{}:{bounds:{min:o.minY,max:o.maxY}}});return{anchorType:"panel",x:a.start,y:i.start,width:a.extent,height:i.extent}},rr=e=>e==="top-left"||e==="bottom-left",or=e=>e==="top-left"||e==="top-right",ar=e=>{const t=l.useLatestRef(e),n=(0,w.useRef)(null);return(0,w.useEffect)(()=>()=>n.current?.finish(!1),[]),(0,w.useCallback)(r=>({onPointerDown:o=>{if(o.button!==0||n.current!==null)return;try{o.currentTarget.setPointerCapture(o.pointerId)}catch{return}o.currentTarget.focus({preventScroll:!0}),o.preventDefault();const a=t.current(r,{handle:o.currentTarget,pointerId:o.pointerId,press:{x:o.clientX,y:o.clientY},onSettled:()=>{n.current=null}});n.current=a,a.start()}}),[t])},We=(e,t)=>{const n=e.shapes.find(o=>o.id===t);if(n!==void 0)return{kind:"shape",region:n.region};const r=e.images.find(o=>o.id===t);return r===void 0?null:{kind:"image",region:r.region}},sr=class{constructor(e){this.params=e}readInitialPreview(){const{annotationId:e,readInputs:t}=this.params,{spec:n,scene:r,panelRect:o}=t(),a=We(n,e);if(a===null)return null;const i=Ie(r,a.kind,e,o);return i===null?null:{kind:"shape-resize-drag",annotationId:e,annotationKind:a.kind,region:ne(i,o)}}resolve(e,t,n,r){const{annotationId:o,readInputs:a,editorStore:i}=this.params,{spec:d,scene:u,panelRect:c,frameElement:g,layers:m,readObservationBox:v}=a(),x=We(d,o);if(x===null)return null;const f=Ie(u,x.kind,o,c);if(f===null)return null;const y=ne(f,c),C=Ri(c),S=h.readContainerFractionBoundsFor(c,g),b=Oi({region:r??y,corner:e,delta:t,minSize:{x:Math.min(C.x,y.width),y:Math.min(C.y,y.height)},bounds:S}),T=(0,p.projectRegionToPanel)(b,c),E=(0,p.isPlacedRegionAnchor)(x.region)?Mi(x.region,f,T,c):pt({rect:T,panelRect:c,bounds:S,layers:m,readObservationBox:v,mayEnclose:x.kind==="shape"&&!ee(n,i.getState().snapping)});return{preview:{kind:"shape-resize-drag",annotationId:o,annotationKind:x.kind,region:ne(E.rect,c),placement:E},unsnappedRegion:b}}commit({placement:e,annotationKind:t}){if(e===void 0)return;const{annotationId:n,dispatch:r,readInputs:o}=this.params,a=We(o().spec,n);a===null||(0,q.isEqual)(a.region,e.region)||r(new p.UpdateAnnotationCommand({kind:t,id:n,patch:{region:e.region}}))}},Mi=(e,t,n,r)=>{const o=Wn(e,t,r);if(o===null)return{type:"free",region:ne(n,r),rect:n};const a=(0,p.readRectPoint)(n,e.regionAlign??"center"),i={x:a.x-o.targetPoint.x,y:a.y-o.targetPoint.y,unit:"px"};return{type:"attached",region:{...e,...zn(n,r,e.unit),offset:i},rect:n}},_i=class extends pe{constructor(...e){super(...e),this.kind="shape-resize-drag",this.placement=new sr(this.params)}readOwn(e){return l.readResizedShapeFor(l.readStanding(e,"shape-resize-drag"),this.params.annotationId)}resolvePreview(e,t){const{corner:n,press:r,readInputs:o}=this.params,a=ut(r,e,o().panelRect);return this.placement.resolve(n,a,t)?.preview??null}commit(e){this.placement.commit(e)}},ir=(e,t)=>{const n=l.useSceneSelector(o=>o.spec.annotations),r=l.useSceneSelector(o=>o.layers);return l.useLatestRef({spec:n,scene:l.useResolvedAnnotations(e),panelRect:e,frameElement:t,layers:r,readObservationBox:l.usePaintedObservationBoxes(e)})},Di=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=l.useGraphContext(),o=l.useEditorStore(),a=ir(t,n);return ar((i,d)=>new _i({...d,annotationId:e,corner:i,readInputs:()=>a.current,editorStore:o,dispatch:r.dispatch}))},Fi=[" ","Enter"],lr=e=>{const t=l.useEditorStore(),n=l.useLatestRef(e);return(0,w.useEffect)(()=>()=>en(t,n.current),[t,n]),(0,w.useCallback)(r=>({onKeyDown:o=>{if(o.altKey||o.ctrlKey||o.metaKey||o.shiftKey)return;const a=t.getState(),i=n.current.readHeld();if(Fi.includes(o.key)){if(o.preventDefault(),o.repeat)return;if(i!==null){en(t,n.current);return}const u=n.current.claim(r);if(u===null)return;a.claimInteraction(u);return}if(i===null)return;const d=n.current.step(i,r,o.key);d!==null&&(o.preventDefault(),a.claimInteraction(d))}}),[t,n])},en=(e,t)=>{const n=t.readHeld();n!==null&&(e.getState().releaseInteraction(n.kind),t.commit(n))},tn=4,we=1e-7,Ni=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=l.useGraphContext(),o=l.useEditorStore(),a=ir(t,n),i=(0,w.useRef)(null),d=new sr({annotationId:e,readInputs:()=>a.current,editorStore:o,dispatch:r.dispatch}),u=c=>{const g=i.current;return g?.preview===c?g:null};return lr({readHeld:()=>l.readResizedShapeFor(l.readStanding(o.getState(),"shape-resize-drag"),e),claim:()=>{const c=d.readInitialPreview();return c===null?null:(i.current={preview:c,initialPreview:c,unsnappedRegion:c.region},c)},step:(c,g,m)=>{const v=a.current,x=Bi(m,v.panelRect);if(x===null)return null;const f=u(c),y=d.resolve(g,x,{altKey:!1},f?.unsnappedRegion??c.region);if(y===null)return null;const C=f?.initialPreview??null,S=C!==null&&Gi(C.region,y.unsnappedRegion,v.panelRect)?C:y.preview,b=l.areShapeResizesEqual(c,S)?c:S;return i.current={preview:b,initialPreview:C,unsnappedRegion:y.unsnappedRegion},b},commit:c=>{i.current=null,d.commit(c)}})},Gi=(e,t,n)=>Math.abs(e.x-t.x)*n.width<=we&&Math.abs(e.y-t.y)*n.height<=we&&Math.abs(e.width-t.width)*n.width<=we&&Math.abs(e.height-t.height)*n.height<=we,Bi=(e,t)=>{const n=h.normalizeToPanelExtent(tn,t.width),r=h.normalizeToPanelExtent(tn,t.height);switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-r};case"ArrowDown":return{x:0,y:r};default:return null}},Hi={"top-left":"diagonalDown","bottom-right":"diagonalDown","top-right":"diagonalUp","bottom-left":"diagonalUp"},zi=e=>{const t=h.useSelectedAnnotationId(),n=Vi(t),r=Ui(e.panelRect,n),o=Xi(t);if(n===null)return null;const a=o.resizedRegion??r;return a===null?null:(0,s.jsx)(Wi,{selected:n,region:a,settled:o.resizedRegion===null&&!o.moving,moving:o.moving,...e})},Wi=({selected:e,region:t,settled:n,moving:r,panelRect:o,frameElement:a})=>{const i=l.useI18n(),{id:d}=e.annotation,u=Di({annotationId:d,panelRect:o,frameElement:a}),c=Ni({annotationId:d,panelRect:o,frameElement:a}),g=l.useStyleReaderTree(),{rect:m}=l.measureShapeRegion(t,e.kind==="shape"?g.annotation.shape(d).resolve().strokeWidth:0,o);return(0,s.jsxs)("div",{"data-testid":"shape-selection","data-annotation-id":d,children:[n&&e.kind==="image"&&(0,s.jsx)(Ii,{image:e.annotation,imageBox:m,panelRect:o,frameElement:a}),n&&e.kind==="shape"&&(0,s.jsx)(ji,{shape:e.annotation,shapeBox:m,panelRect:o,frameElement:a}),!r&&ki.map(v=>{const x=Li(m,v);return(0,s.jsx)(nr,{point:{x:o.x+x.x,y:o.y+x.y},label:i(`graph.annotations.shapeToolbar.resize.${v}`),pull:Hi[v],size:"md",attributes:{"data-testid":"shape-resize-handle","data-corner":v},dragHandlers:u(v),keyboardHandlers:c(v)},v)})]})},Vi=e=>l.useSceneSelector((0,J.useShallow)(t=>{const{shapes:n,images:r}=t.spec.annotations,o=n.find(i=>i.id===e);if(o!==void 0)return{kind:"shape",annotation:o};const a=r.find(i=>i.id===e);return a===void 0?null:{kind:"image",annotation:a}})),Ui=(e,t)=>{const{shapes:n,images:r}=l.useResolvedAnnotations(e);if(t===null)return null;const o=(t.kind==="shape"?n:r).find(c=>c.id===t.annotation.id);if(o===void 0)return null;const{x:a,y:i,width:d,height:u}=o.region;return{anchorType:"panel",x:a,y:i,width:d,height:u}},Xi=e=>l.useEditorState((0,J.useShallow)(t=>e===null?{resizedRegion:null,moving:!1}:{resizedRegion:l.readResizedShapeFor(l.readStanding(t,"shape-resize-drag"),e)?.region??null,moving:l.readMovedAnnotationFor(l.readStanding(t,"move-drag"),e)!==null}));var Ki=(e,t,n)=>{const{commands:r,anchorResolver:o}=l.useGraphContext(),{engine:a}=l.useHoverContext(),i=l.useEditorStore(),d=ie(t,n),u=(0,w.useRef)(null);return(0,w.useEffect)(()=>()=>u.current?.finish(!1),[]),{onPointerDown:(0,w.useCallback)(c=>{if(!(c.button!==0||u.current!==null)){try{c.currentTarget.setPointerCapture(c.pointerId)}catch{return}n.focus({preventScroll:!0}),c.preventDefault(),u.current=new Kn({handle:c.currentTarget,pointerId:c.pointerId,annotationId:e,press:{x:c.clientX,y:c.clientY},readInputs:()=>d.current,editorStore:i,engine:a,anchorResolver:o,dispatch:r.dispatch,offsetOnly:!0,onSettled:()=>{u.current=null}}),u.current.start()}},[e,n,d,i,a,o,r])}},dr=({annotationId:e,anchor:t,sourceAlign:n,scenePoint:r,panelRect:o,frameElement:a,moving:i=!1,hideHandle:d=!1})=>{const u=l.useI18n(),c=l.useStyleReaderTree().snapTarget.tether().resolve(),g=Ki(e,o,a),m=l.useSceneSelector(S=>S.coordSystem.type==="polar"),v=se(t,n,r,o);if(v===null)return null;const x=v.targetPoint,f=(0,p.projectAnchorToPanel)(r,o),y=n===null||n==="center",C=!m||t.anchorType==="annotation";return(0,s.jsxs)(s.Fragment,{children:[!i&&(0,s.jsxs)("svg",{"aria-hidden":"true",className:"_1khwdhw0",width:o.width,height:o.height,style:{left:o.x,top:o.y},"data-testid":"attachment-tether",children:[(0,s.jsx)("line",{x1:x.x,y1:x.y,x2:f.x,y2:f.y,stroke:c.stroke,strokeOpacity:c.alpha,strokeWidth:c.strokeWidth,strokeDasharray:(0,p.toStrokeDasharray)(c.dashArray,c.strokeWidth)}),(0,s.jsx)("circle",{cx:x.x,cy:x.y,r:c.size/2,fill:(0,p.toPaintColor)(c.fill),fillOpacity:c.alpha})]}),!y&&C&&!d&&(0,s.jsx)("div",{"aria-label":u("graph.annotations.attachment.tether"),className:"_1khwdhw1","data-testid":"attachment-tether-handle",role:"button",style:{left:o.x+f.x,top:o.y+f.y,visibility:i?"hidden":void 0},tabIndex:0,...g})]})},$i=({sticker:e,stickerBox:t,panelRect:n,frameElement:r})=>{const o=l.useI18n(),{commands:a}=l.useGraphContext(),i=h.useRemoveAnnotation(n),d=h.useToolbarPopups(),u=g=>{a.dispatch(new p.UpdateAnnotationCommand({kind:"sticker",id:e.id,patch:{sticker:g}}))},c=()=>{i(e.id),r.focus({preventScroll:!0})};return(0,s.jsxs)(h.SelectionToolbar.Root,{anchorBox:t,panelRect:n,frameElement:r,label:o("graph.annotations.stickerToolbar.label"),testId:"sticker-toolbar",children:[(0,s.jsx)(h.FloatingToolbar.StickerPicker,{value:e.sticker,label:o("graph.annotations.stickerToolbar.swap"),onChange:u,...d.bind("sticker")}),(0,s.jsx)(h.FloatingToolbar.Separator,{}),(0,s.jsx)(h.StartArrowButton,{annotationId:e.id}),(0,s.jsx)(h.FloatingToolbar.Button,{label:o("graph.annotations.stickerToolbar.remove"),onClick:c,children:(0,s.jsx)(h.TrashIcon,{size:"sm",title:""})})]})},Yi=({panelRect:e,frameElement:t})=>{const n=h.useSelectedAnnotationId(),r=l.useSceneSelector(u=>u.spec.annotations.stickers.find(c=>c.id===n)),o=l.useResolvedAnnotations(e).stickers.find(u=>u.id===n),a=l.useStyleReaderTree().graph().get("textScale"),i=l.useEditorState(u=>l.readStanding(u,"move-drag")?.annotationId===n);if(r===void 0||o===void 0)return null;const d=l.readStickerBox(o,e,a);return d===null?null:(0,s.jsxs)("div",{"data-testid":"sticker-selection","data-annotation-id":r.id,children:[h.hasAttachment(r.at)&&(0,s.jsx)(dr,{annotationId:r.id,anchor:r.at,sourceAlign:null,scenePoint:o.at,panelRect:e,frameElement:t,moving:i}),!i&&(0,s.jsx)($i,{sticker:r,stickerBox:d,panelRect:e,frameElement:t})]})},nn=["left","right"];var cr=({width:e})=>h.normalizeToPanelExtent(60,e),rn=(e,t)=>({x:t==="left"?e.x:e.x+e.width,y:e.y+e.height/2}),ur=({at:e,width:t,align:n,edge:r,delta:o,minWidth:a,panelWidth:i,panelHeight:d,paintedAt:u,bounds:c})=>{if(o===0||!Number.isFinite(o))return{at:e,width:t,shift:0};const g=(0,p.alignUnitFractions)(n).x,m=qi(e.offset,i),v=u?.x??(e.anchorType==="panel"?e.x+m:0),x=e.anchorType!=="panel"&&(n==="top"||n==="bottom");let f;if(x){const C=Math.max(0,Math.min(v-(c?.minX??0),(c?.maxX??1)-v)),S=(0,q.clamp)(t+(r==="left"?-o:o)*2,Math.min(a,t),Math.max(t,C*2));f={start:v-S/2,extent:S}}else f=et({start:v-g*t,extent:t,moveStartEdge:r==="left",delta:o,minExtent:a,...c===void 0?{}:{bounds:{min:c.minX,max:c.maxX}}});const y=x?0:f.start+g*f.extent-v;return f.extent===t&&Math.abs(y)<1e-12?{at:e,width:t,shift:0}:{at:e.anchorType==="panel"?{...e,x:e.x+y}:{...e,offset:{x:(m+y)*i,y:(e.offset?.y??0)*(e.offset?.unit==="px"?1:d),unit:"px"}},width:f.extent,shift:y,...u===void 0?{}:{point:{x:v+y,y:u.y}}}},hr=(e,t)=>(0,q.isEqual)(e.at,t.at)&&e.width===t.width,qi=(e,t)=>e?.x===void 0?0:e.unit==="px"?h.normalizeToPanelExtent(e.x,t):e.x,Ee=(e,t,n,r=!0)=>{const o=e.textAnnotations.find(i=>i.id===t);if(o===void 0)return null;const a=n?.textAnnotations.find(i=>i.id===t)?.at;return o.at.anchorType!=="panel"&&(!r||a===void 0||a.space==="disk")?null:{at:o.at,width:o.width,align:o.align,...a===void 0?{}:{paintedAt:a}}},Zi=class extends pe{constructor(...e){super(...e),this.kind="text-resize-drag"}readOwn(e){return l.readResizedTextFor(l.readStanding(e,"text-resize-drag"),this.params.annotationId)}resolvePreview(e){const{annotationId:t,edge:n,press:r,readInputs:o}=this.params,{annotations:a,painted:i,cartesian:d,panelRect:u,frameElement:c}=o(),g=Ee(a,t,i,d);if(g===null)return null;const m=ut(r,e,u).x;return{kind:"text-resize-drag",annotationId:t,delta:m,...ur({...g,edge:n,delta:m,minWidth:cr(u),panelWidth:u.width,panelHeight:u.height,bounds:h.readContainerFractionBoundsFor(u,c)})}}commit(e){const{annotationId:t,dispatch:n,readInputs:r}=this.params,{annotations:o,painted:a,cartesian:i}=r(),d=Ee(o,t,a,i);d===null||hr(d,e)||n(new p.UpdateAnnotationCommand({kind:"text",id:t,patch:{at:e.at,width:e.width}}))}},Ji=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=l.useGraphContext(),o=l.useEditorStore(),a=l.useLatestRef({annotations:l.useSceneSelector(i=>i.spec.annotations),painted:l.useResolvedAnnotations(t),cartesian:l.useSceneSelector(i=>i.coordSystem.type==="cartesian"),panelRect:t,frameElement:n});return ar((i,d)=>new Zi({...d,annotationId:e,edge:i,readInputs:()=>a.current,editorStore:o,dispatch:r.dispatch}))},Qi=4,el=({annotationId:e,panelRect:t,frameElement:n})=>{const{commands:r}=l.useGraphContext(),o=l.useEditorStore(),a=l.useSceneSelector(c=>c.spec.annotations),i=l.useResolvedAnnotations(t),d=l.useSceneSelector(c=>c.coordSystem.type==="cartesian"),u=(c,g)=>{const m=Ee(a,e,i,d);return m===null?null:{kind:"text-resize-drag",annotationId:e,delta:g,...ur({...m,edge:c,delta:g,minWidth:cr(t),panelWidth:t.width,panelHeight:t.height,bounds:h.readContainerFractionBoundsFor(t,n)})}};return lr({readHeld:()=>l.readResizedTextFor(l.readStanding(o.getState(),"text-resize-drag"),e),claim:c=>u(c,0),step:(c,g,m)=>{const v=tl(m,t);return v===null?null:u(g,c.delta+v)},commit:c=>{const g=Ee(a,e,i,d);g===null||hr(g,c)||r.dispatch(new p.UpdateAnnotationCommand({kind:"text",id:e,patch:{at:c.at,width:c.width}}))}})},tl=(e,t)=>{const n=h.normalizeToPanelExtent(Qi,t.width);switch(e){case"ArrowLeft":return-n;case"ArrowRight":return n;default:return null}},nl=e=>{const t=h.useSelectedAnnotationId(),n=l.useSceneSelector(d=>d.coordSystem.type==="cartesian"),r=ol(t),o=al(t),a=l.useEditorState(d=>d.caret?.annotationId===t),i=sl(e.panelRect,t,o.resized);return r===null||i===null?null:(0,s.jsx)(rl,{annotation:r,textBox:i,settled:o.resized===null&&!o.moving,moving:o.moving,resizable:r.at.anchorType==="panel"||n,hasCaret:a,...e})},rl=({annotation:e,textBox:t,settled:n,moving:r,resizable:o,hasCaret:a,panelRect:i,frameElement:d})=>{const u=l.useI18n(),c=Pn()?.TextToolbar,g=Ji({annotationId:e.id,panelRect:i,frameElement:d}),m=el({annotationId:e.id,panelRect:i,frameElement:d}),v=l.useResolvedAnnotations(i).textAnnotations.find(x=>x.id===e.id);return(0,s.jsxs)("div",{"data-testid":"text-selection","data-annotation-id":e.id,children:[(n||r)&&v!==void 0&&h.hasAttachment(e.at)&&(0,s.jsx)(dr,{annotationId:e.id,anchor:e.at,sourceAlign:e.align,scenePoint:v.at,panelRect:i,frameElement:d,moving:r,hideHandle:o&&!a&&nn.some(x=>{const f=rn(t,x),y=(0,p.projectAnchorToPanel)(v.at,i);return Math.abs(f.x-y.x)<24&&Math.abs(f.y-y.y)<24})}),n&&c!==void 0&&(0,s.jsx)(c,{annotation:e,textBox:t,panelRect:i,frameElement:d}),o&&!r&&!a&&nn.map(x=>{const f=rn(t,x);return(0,s.jsx)(nr,{point:{x:i.x+f.x,y:i.y+f.y},label:u(`graph.annotations.textToolbar.resize.${x}`),pull:"horizontal",size:"sm",attributes:{"data-testid":"text-resize-handle","data-edge":x},dragHandlers:g(x),keyboardHandlers:m(x)},x)})]})},ol=e=>{const t=l.useSceneSelector(n=>n.spec.annotations.textAnnotations);return e===null?null:t.find(n=>n.id===e)??null},al=e=>l.useEditorState((0,J.useShallow)(t=>e===null?{resized:null,moving:!1}:{resized:l.readResizedTextFor(l.readStanding(t,"text-resize-drag"),e),moving:l.readMovedAnnotationFor(l.readStanding(t,"move-drag"),e)!==null})),sl=(e,t,n)=>{const r=l.useResolvedAnnotations(e),o=l.useMeasuredBoxes(),a=l.useStyleReaderTree(),i=(0,w.useMemo)(()=>({panel:{width:e.width,height:e.height},measuredBoxes:o,readers:a}),[e.width,e.height,o,a]);return t===null?null:Dn(r,t,n,i)?.rect??null},vt=(e,t)=>typeof document.elementsFromPoint=="function"?document.elementsFromPoint(e,t):[],il=(e,t,n)=>l.readStampedEditTargetInStack(vt(e,t),n),ll="_1rpuha50";var on=["pointerdown","mousedown","pointerup","mouseup","click"],tt=e=>e instanceof Element&&e.closest("[data-menu-shield]")!==null,dl=()=>{const e=l.useEditorState(u=>u.plotMenu!==null),t=l.useEditorState(u=>hl(u.standingInteraction?.kind)),n=l.useGraphSelection()[0]?.kind==="observations",r=l.MODE_RULES[l.useGraphMode()].showMenuTriggerOnHover,{store:o}=l.useHoverContext(),a=l.useEditorStore(),i=r&&!t&&(e||n),d=(0,w.useRef)(null);return(0,w.useEffect)(()=>{if(!i)return;const u=o.getState();u.setHoverState(p.RESTING_HOVER_STATE),u.setTooltipAnchor(null)},[i,o]),(0,w.useEffect)(()=>{const u=d.current;if(u===null)return;const c=g=>{if(!(g instanceof MouseEvent)||g.button!==0||a.getState().plotMenu?.arrowId!==void 0)return;const m=cl(g.clientX,g.clientY);m!==null&&(g.stopPropagation(),m.dispatchEvent(ul(g)))};for(const g of on)u.addEventListener(g,c);return()=>{for(const g of on)u.removeEventListener(g,c)}},[i,a]),i?(0,s.jsx)("div",{ref:d,className:ll,"data-menu-shield":"","data-testid":"menu-shield"}):null},cl=(e,t)=>vt(e,t).find(n=>!tt(n))??null,ul=e=>new MouseEvent(e.type,{bubbles:!0,cancelable:!0,clientX:e.clientX,clientY:e.clientY,button:e.button,buttons:e.buttons}),hl=e=>e==="arrow-draw"||e==="box-draw",gl=1,pl=10,ml=1e-7,vl=(e,t)=>{const{selectionStore:n,commands:r,chartId:o,anchorResolver:a,store:i,history:d}=l.useGraphContext(),{engine:u}=l.useHoverContext(),c=l.useEditorStore(),g=ie(t,e),{showAnnotations:m}=l.MODE_RULES[l.useGraphMode()],v=l.useLatestRef(m);(0,w.useEffect)(()=>{let x=null,f={x:0,y:0},y={x:0,y:0},C,S=!1,b=!1,T=g.current;const E=new Set,A=L=>new Je({annotationId:L,press:{x:0,y:0},readInputs:()=>g.current,engine:u,anchorResolver:a,editorStore:c,dispatch:r.dispatch,previous:()=>C}),M=()=>{y={x:0,y:0},C=void 0,E.clear()},N=L=>{const D=x;if(x=null,E.clear(),D===null||(l.readStanding(c.getState(),"move-drag")===D&&c.getState().releaseInteraction("move-drag"),!L))return;const B=g.current,z=D.placement!==void 0,V=z||D.ends!==void 0;y=z?{x:f.x-D.translation.x*B.panelRect.width,y:f.y-D.translation.y*B.panelRect.height}:{x:0,y:0},S=!0;try{V?Math.hypot(D.translation.x*B.panelRect.width,D.translation.y*B.panelRect.height)>ml&&A(D.annotationId).commit(D):Fn(D.translation)&&r.dispatch(new p.MoveAnnotationCommand({id:D.annotationId,translation:D.translation,bounds:h.readContainerFractionBoundsFor(B.panelRect,e)}))}finally{S=!1}},G=()=>{N(!0),M()},R=()=>{N(!1),M()},j=n.subscribe((L,D)=>{h.readSelectedAnnotationId(L.selection)!==h.readSelectedAnnotationId(D.selection)&&G()}),P=c.subscribe((L,D)=>{b||S||((L.caret!==D.caret||L.snapping!==D.snapping)&&G(),L.standingInteraction!==D.standingInteraction&&(x!==null&&L.standingInteraction!==x?L.standingInteraction===null?R():G():L.standingInteraction!==null&&M()))}),k=i.subscribe((L,D)=>{!S&&L.scene!==D.scene&&R()}),O=d.stack.subscribe(()=>{S||R()}),I=L=>{if(!h.isWithinChart(L.target,e,o)||h.isWithinMenu(L.target)||h.isWithinChartChrome(L.target,o)||h.isWithinTextEntry(L.target)||c.getState().caret!==null||xl(L.target,e))return;if(l.resolveHistoryStep(L)!==null){G();return}if(L.defaultPrevented||L.altKey||L.ctrlKey||L.metaKey)return;const D=fl(L.key,L.shiftKey);if(D===null)return;const B=v.current?h.readSelectedAnnotationId(n.getState().selection):null;if(B===null)return;const z=c.getState().standingInteraction;if(z!==null&&z!==x)return;const V=g.current;(!(0,q.isEqual)(T.panelRect,V.panelRect)||!(0,q.isEqual)(T.measuredBoxes,V.measuredBoxes))&&R(),T=V;const K=(0,p.findAnnotation)(V.spec,B);if(K===null)return;x===null&&(f=y),f={x:f.x+D.x,y:f.y+D.y};let Z;const Q=K.kind==="arrow"&&Un(K.annotation);if(K.kind==="text"||K.kind==="sticker"||Q)Z=A(B).resolve(f,{altKey:!1});else{const H=(0,p.clampAnnotationTranslation)(K,{x:h.normalizeToPanelExtent(f.x,V.panelRect.width),y:h.normalizeToPanelExtent(f.y,V.panelRect.height)},h.readContainerFractionBoundsFor(V.panelRect,e));Z=H===null?null:{kind:"move-drag",annotationId:B,translation:H}}Z!==null&&(L.preventDefault(),E.add(L.key),C=Z.placement,b=!0,c.getState().claimInteraction(Z),x=l.readStanding(c.getState(),"move-drag"),b=!1)},F=L=>{E.delete(L.key)&&E.size===0&&N(!0)},W=L=>{h.isWithinChart(L.target,e,o)&&L.target!==L.relatedTarget&&G()};return document.addEventListener("pointerdown",G,!0),document.addEventListener("keydown",I),document.addEventListener("keyup",F),document.addEventListener("focusout",W),window.addEventListener("blur",G),()=>{G(),j(),P(),k(),O(),document.removeEventListener("pointerdown",G,!0),document.removeEventListener("keydown",I),document.removeEventListener("keyup",F),document.removeEventListener("focusout",W),window.removeEventListener("blur",G)}},[e,o,c,n,r,i,d,g,u,a,v])},xl=(e,t)=>e instanceof Element&&e!==t&&e.closest('button, select, a[href], [role="button"], [role="slider"], [role="combobox"], [tabindex]')!==t,fl=(e,t)=>{const n=t?pl:gl;switch(e){case"ArrowLeft":return{x:-n,y:0};case"ArrowRight":return{x:n,y:0};case"ArrowUp":return{x:0,y:-n};case"ArrowDown":return{x:0,y:n};default:return null}},gr=`[${h.SELECTION_TOOLBAR_ATTRIBUTE}]`,pr='button:not([disabled]):not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]):not([data-base-ui-focus-guard])',yl=(e,t)=>{const{chartId:n}=l.useGraphContext(),r=l.useEditorStore(),o=h.useChartChromeContainer();(0,w.useEffect)(()=>{if(t===null||o===null)return;const a=i=>{if(i.key!=="Tab"||i.defaultPrevented||!h.isWithinChart(i.target,e,n)||h.isWithinMenu(i.target))return;if(r.getState().standingInteraction?.kind==="chrome-popup"){i.target===e&&wl(i,n);return}const d=[...Sl(o,t),...t.querySelectorAll(pr)];if(d.length===0)return;i.preventDefault();const u=d.findIndex(g=>g.contains(document.activeElement)),c=u===-1?i.shiftKey?d.length-1:0:(u+(i.shiftKey?-1:1)+d.length)%d.length;bl(d[c])};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[e,t,o,n,r])},Sl=(e,t)=>[...e.querySelectorAll(gr)].filter(n=>!t.contains(n)),wl=(e,t)=>{const n=document.querySelector(`[${h.CHART_CHROME_ATTRIBUTE}="${t}"][data-open]`),r=n===null?[]:[...n.querySelectorAll(pr)],o=e.shiftKey?r.at(-1):r[0];o!==void 0&&(e.preventDefault(),o.focus())},bl=e=>{(e?.matches(gr)?e.querySelector("button:not([disabled])"):e)?.focus()},Cl=e=>{const{selectionStore:t,chartId:n}=l.useGraphContext(),r=l.useEditorStore();(0,w.useEffect)(()=>{let o=null;const a=u=>{if(h.isWithinTextEntry(u.target))return;const{caret:c}=r.getState(),g=c===null?null:il(u.clientX,u.clientY,e);g?.kind==="annotation"&&g.target.id===c?.annotationId||e.focus({preventScroll:!0})},i=u=>{const{selection:c,clearSelection:g}=t.getState();c.length!==0&&(h.isWithinChart(u.target,e,n)||g())},d=u=>{t.getState().selection.length!==0&&h.isWithinChart(u.target,e,n)&&u.relatedTarget===null&&(o!==null&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=null,document.hasFocus()&&(h.isWithinChart(document.activeElement,e,n)||t.getState().clearSelection())}))};return e.addEventListener("pointerdown",a),document.addEventListener("focusin",i),document.addEventListener("focusout",d),()=>{o!==null&&cancelAnimationFrame(o),e.removeEventListener("pointerdown",a),document.removeEventListener("focusin",i),document.removeEventListener("focusout",d)}},[r,t,e,n])},Tl=(e,t)=>{switch(e.kind){case"legend":{const n=t.legends[e.part.legendIndex],r=n?.items[e.part.itemIndex];if(n===void 0||r===void 0)return null;const o=Al(n,r.layerId,t.layers);return o===null?null:(0,p.buildObservationsTargetAtValue)({layer:o.layer,scope:"group",variable:o.variable,value:r.value,parsingLocale:t.parsingLocale})}case"axis":{const n=e.part;if(n===null||e.target.axis!=="x")return null;const r=t.formattedAxes.find(a=>a.scaledAesthetic==="x");if(r===void 0||r.bandwidth===void 0)return null;const o=r.ticks[n.tickIndex];return o===void 0?null:El(t.layers,o.value,t.parsingLocale)}case"annotation":case"grid":return null}},Al=(e,t,n)=>{const r=t===void 0?n:n.filter(o=>o.id===t);for(const o of e.aesthetics){const a=Pl(r,o);if(a!==null)return a}return null},Pl=(e,t)=>{for(const n of e){const r=(0,p.readVariableName)(n.mapping[t]);if(r!==null&&Il(n,r))return{layer:n,variable:r}}return null},Il=(e,t)=>e.data.hasVariable(t)&&e.data.getType(t)==="categorical",El=(e,t,n)=>{let r=null;for(const o of e){if(!o.interactive)continue;const a=(0,p.readScopeXVariable)(o.mapping);if(a===null)continue;const i=(0,p.buildObservationsTargetAtValue)({layer:o,scope:"xValue",variable:a,value:t,parsingLocale:n});if(i!==null){if(r!==null)return null;r=i}}return r},jl=({hover:e,layers:t,scales:n,parsingLocale:r})=>{const{primary:o,intersection:a}=e;if(o===null)return null;const i=(0,p.findLayerById)(t,o.layerId);if(i===void 0)return null;const d=(0,p.readObservationIndex)(o),u=a?.intersects!==!1,c=(0,p.readBroadestObservationsScope)(i),g=u||!(0,p.hasMainAxisBand)(n)?[c]:["xValue",c];for(const m of g){const v=(0,p.buildObservationsTarget)({layer:i,observationIndex:d,scope:m,parsingLocale:r});if(v!==null)return{layerId:i.id,observationIndex:d,onObservation:u,target:v}}return null},kl=(e,t,n)=>{if(!e.onObservation||e.target.scope!=="group")return null;const r=(0,p.findLayerById)(t,e.layerId);return r===void 0?null:(0,p.buildObservationsTarget)({layer:r,observationIndex:e.observationIndex,scope:"observation",parsingLocale:n})},nt=(e,t)=>{const{target:n}=e,{frameElement:r,captureRect:o,resolvesObservations:a,scene:i}=t;if(!(n instanceof Element&&r.contains(n))){const f=an(!1,!1,e,t);return{targetAtPoint:l.resolveEditTargetAtPoint({stamped:f.stamped,observations:null}),hover:null,elements:f.elements}}const d=o!==null&&n===o,u=d&&a?Rl(o):null,c=u===null?null:Ll(e,u,t),g=c===null?null:jl({hover:c,layers:i.layers,scales:i.scales,parsingLocale:i.config.parsingLocale}),m=g!==null&&t.hasOverlayMenu(g.target)?g:null,v=an(d,m!==null,e,t),x=l.resolveEditTargetAtPoint({stamped:v.stamped,observations:m});return{targetAtPoint:x,hover:x?.kind==="observations"?c:null,elements:v.elements}},Rl=e=>{const t=e.getBoundingClientRect();return t.width>0&&t.height>0?t:null},an=(e,t,n,{showAnnotations:r,selectGuidesOnPress:o,frameElement:a,scene:i,hasOverlayMenu:d})=>{if(!r&&i.coordSystem.type==="cartesian"&&e&&t)return{stamped:null,elements:[]};const u=e||r?vt(n.clientX,n.clientY):n.target instanceof Element?[n.target]:[],c=l.readStampedEditTargetInStack(u,a);return c===null?{stamped:null,elements:u}:{stamped:(c.kind==="annotation"?r:o&&d(c.target))?c:null,elements:u}},Ll=(e,t,n)=>{const r=(0,p.toPanelCursor)({x:e.clientX-t.left,y:e.clientY-t.top},t);return n.engine.query(r,{tolerance:n.tolerance,viewport:t,includeAttached:!0})},Ol=({client:e,capture:t,engine:n,layers:r,parsingLocale:o,hasMenu:a})=>{if(t===null||t.width===0||t.height===0||e.x<t.left||e.x>t.right||e.y<t.top||e.y>t.bottom)return null;const i={x:e.x-t.left,y:e.y-t.top},{primary:d,intersection:u}=n.query((0,p.toPanelCursor)(i,t),{tolerance:l.ANNOTATE_ON_THE_MARK,viewport:{width:t.width,height:t.height}});if(d===null||u?.intersects!==!0)return null;const c=r.find(v=>v.id===d.layerId);if(c===void 0||h.isBoxplotOutlier(c,d.observation)||!Ml(c.spatialKind))return null;const g=(0,p.readObservationIndex)(d),m=(0,p.buildObservationsTarget)({layer:c,observationIndex:g,scope:"observation",parsingLocale:o});return m===null||!a(m)?null:{target:m,observationIndex:g}},Ml=e=>{switch(e){case"noop":return!1;case"points":return!0;case"buckets":case"filledBuckets":case"spannedBuckets":case"rects":case"cells":case"renderHitTest":return!0;default:return e}},sn="data-annotation-id",_l='[data-testid="pinnedNumber"], [data-testid="comment"]',ln=(e,t,n)=>{if(e.target instanceof Element){const r=dn(e.target,t);if(r!==null)return r}for(const r of n){if(r===e.target)continue;const o=dn(r,t);if(o!==null)return o}return null},Dl=(e,t)=>{const n=e.annotations.pinnedNumbers.find(r=>r.id===t)??e.annotations.comments.find(r=>r.id===t);return n===void 0?null:Fl(e,n.at.anchor.layerId,n.at.observationIndex)},dn=(e,t)=>{if(!t.contains(e))return null;const n=e.closest(_l);if(n===null||!t.contains(n))return null;const r=e.closest(`[${sn}]`);if(r===null||!n.contains(r))return null;const o=r.getAttribute(sn);return o===null||o.length===0?null:o},Fl=(e,t,n)=>{const r=t===void 0?void 0:e.layers.find(o=>o.id===t);return r===void 0?null:(0,p.buildObservationsTarget)({layer:r,observationIndex:n,scope:"observation",parsingLocale:e.config.parsingLocale})},Nl={on:{edge:0,stroke:6,point:8},near:{main:0,cross:0}},Gl=({client:e,capture:t,frame:n,engine:r,layers:o})=>{if(t===null||t.width===0||t.height===0||n===null||!un(n,e))return null;const a={x:e.x-t.left,y:e.y-t.top};if(un(t,e)){const{primary:d,intersection:u}=r.query((0,p.toPanelCursor)(a,t),{tolerance:Nl,viewport:{width:t.width,height:t.height}}),c=d===null?void 0:o.find(m=>m.id===d.layerId),g=d!==null&&c!==void 0&&h.isBoxplotOutlier(c,d.observation);if(d!==null&&u?.intersects!==!1&&!g)return null}const i=h.readContainerFractionBounds({x:t.left-n.left,y:t.top-n.top,width:t.width,height:t.height},n);return{x:cn(a.x/t.width,i.minX,i.maxX),y:cn(a.y/t.height,i.minY,i.maxY)}},cn=(e,t,n)=>Math.min(Math.max(e,t),n),un=(e,t)=>t.x>=e.left&&t.x<=e.right&&t.y>=e.top&&t.y<=e.bottom,Bl=(e,{canSelectGraph:t,withinFrame:n,caretAnnotationId:r})=>{switch(e?.kind){case"annotation":return e.target.id===r?{kind:"keep-caret"}:{kind:"select-annotation",target:e.target};case"axis":case"legend":case"grid":return{kind:"select-guide",target:e.target};case"observations":return Hl(e.observations);case void 0:break}return t&&n?{kind:"select-graph",target:{kind:"graph"}}:{kind:"clear"}},Hl=({target:e,observationIndex:t,onObservation:n})=>e.scope==="xValue"?{kind:"select-band",target:e}:{kind:"select-observations",target:e,observationIndex:n?t:null},zl=`[${l.CHART_LABEL_ATTRIBUTE}], [${l.EDIT_TARGET_KIND_ATTRIBUTE}="axis"], [${l.EDIT_TARGET_KIND_ATTRIBUTE}="legend"]`,Wl=(e,t,n,r)=>{const{commands:o,history:a,selectionStore:i,store:d,anchorResolver:u,chartId:c}=l.useGraphContext(),{engine:g}=l.useHoverContext(),m=l.useEditorStore(),v=l.useGraphMode(),{selectGraphOnPress:x}=l.MODE_RULES[v],f=l.useLatestRef(x),y=l.useLatestRef(v===l.GRAPH_MODES.annotate),C=l.useLatestRef(v===l.GRAPH_MODES.annotate),S=ie(t,e),b=h.useRemoveAnnotation(t),T=l.useLatestRef(r),E=(0,w.useRef)(null);(0,w.useEffect)(()=>()=>E.current?.finish(!1),[]),(0,w.useEffect)(()=>i.subscribe(({selection:A})=>{const M=m.getState().pressedObservation,[N,...G]=A,R=N!==void 0&&G.length===0&&M!==null&&(0,p.areEditTargetsEqual)(N,M.selectedFor);M!==null&&!R&&m.getState().setPressedObservation(null)}),[m,i]),(0,w.useEffect)(()=>{const A=P=>nt({target:P.target,clientX:P.clientX,clientY:P.clientY},n()).targetAtPoint,M=P=>{if(!(P.target instanceof Element))return!1;const k=P.target.closest(l.LEGEND_OVERFLOW_CONTROL_SELECTOR);return k!==null&&e.contains(k)&&l.readStampedEditTargetInStack([P.target],e)===null},N=(P,k)=>{if(E.current!==null||!l.canMoveAnnotationOnCanvas(S.current.spec,k.id))return;try{e.setPointerCapture(P.pointerId)}catch{return}P.preventDefault();const O=new Kn({handle:e,pointerId:P.pointerId,annotationId:k.id,press:{x:P.clientX,y:P.clientY},readInputs:()=>S.current,editorStore:m,engine:g,anchorResolver:u,dispatch:o.dispatch,onSettled:()=>{E.current=null}});E.current=O,O.start()},G=(P,k)=>{const O=i.getState(),{layers:I,config:F,coordSystem:W}=d.getState().scene,L=k.kind==="select-observations"&&k.observationIndex!==null?l.readPressedObservation(k.observationIndex,I,k.target,F.parsingLocale):null;if(m.getState().setPressedObservation(L),y.current&&(k.kind==="select-observations"||k.kind==="select-band")){const D=(0,p.findLayerById)(I,k.target.layerId);if(D!==void 0&&Pa(D.geom,W.type)){const B=e.getBoundingClientRect(),z=h.readFrameScale(e,B.width);m.getState().setAnnotatePress({key:(0,p.readEditTargetKey)(k.target),x:(P.clientX-B.left)/z,y:(P.clientY-B.top)/z})}else m.getState().setAnnotatePress(null)}switch(k.kind){case"select-annotation":O.setSelection([k.target]),N(P,k.target);return;case"select-observations":case"select-band":case"select-guide":case"select-graph":O.setSelection([k.target]);return;case"clear":O.clearSelection();return;default:throw new p.InternalError({message:`No press outcome for: ${JSON.stringify(k)}`})}},R=P=>{if(h.isWithinTextEntry(P.target)||m.getState().setPendingTextCaret(null),P.button!==0)return;const k=m.getState().plotMenu?.arrowId;if(k!==void 0&&(tt(P.target)||!h.isWithinAnyChartChrome(P.target))&&(m.getState().setPlotMenu(null),h.isWithinChart(P.target,e,c))){i.getState().setSelection([{kind:"annotation",id:k}]);return}if(tt(P.target)){m.getState().setPlotMenu(null),i.getState().clearSelection();return}if(h.isWithinAnyChartChrome(P.target))return;const O=m.getState().caret?.annotationId??null,I=i.getState().selection.length>0||O!==null,F=P.target instanceof Element?P.target.closest("[data-edit-id]")?.getAttribute("data-edit-id")??null:null;!h.isWithinTextEntry(P.target)&&F!==O&&h.discardEmptyTextCaret(m,d.getState().scene.annotations,b,h.readAnnotationPlacementHistory(a));const W=m.getState().standingInteraction,L=h.readContainerFractionBoundsFor(S.current.panelRect,S.current.frameElement),D=H=>{const X=e.getBoundingClientRect();return H.x<X.left||H.x>X.right||H.y<X.top||H.y>X.bottom};if(W?.kind==="arrow-draw"){const H=n().captureRect?.getBoundingClientRect()??null,X={x:P.clientX,y:P.clientY};if(!D(X)&&l.readDrawnPanelPoint(X,H,L)===null)return;qn({client:X,altKey:P.altKey,frameElement:e,inputs:S.current,editorStore:m,selectionStore:i,engine:g,anchorResolver:u,dispatch:o.dispatch});return}if(W?.kind==="box-draw"){const H=n().captureRect?.getBoundingClientRect()??null,X={x:P.clientX,y:P.clientY};if(D(X)){m.getState().releaseInteraction("box-draw"),m.getState().setPlotMenu(null),i.getState().clearSelection();return}const ve=l.readDrawnPanelPoint(X,H,L);if(ve===null||H===null||l.isTinySpan(W.start,ve,H))return;const _e=tr(W.start,ue(X,e,S.current.panelRect),ee({altKey:P.altKey},m.getState().snapping),S.current),re=new p.AddAnnotationCommand({kind:"shape",annotation:{...p.SHAPE_DEFAULTS,region:_e.region}});o.dispatch(re),m.getState().releaseInteraction("box-draw"),m.getState().setPlotMenu(null),i.getState().setSelection([re.target]);return}if(m.getState().setPlotMenu(null),M(P)||l.isOnLiveGeomMark(P.target,e))return;const B=n(),z=nt({target:P.target,clientX:P.clientX,clientY:P.clientY},B);if(C.current){const H=ln(P,e,z.elements),X=H===null?null:Dl(d.getState().scene,H);if(X?.observationIndex!==void 0){m.getState().setCaret(null),G(P,{kind:"select-observations",target:X,observationIndex:X.observationIndex});return}}const V=P.target instanceof Node&&e.contains(P.target),K=Bl(z.targetAtPoint,{canSelectGraph:f.current&&!h.isWithinTextEntry(P.target)&&n().hasOverlayMenu({kind:"graph"}),withinFrame:V,caretAnnotationId:m.getState().caret?.annotationId??null});if(K.kind==="keep-caret")return;const Z=K.kind==="select-annotation"&&d.getState().scene.spec.annotations.differenceArrows.some(H=>H.id===K.target.id);if((K.kind==="clear"||Z)&&y.current){const H=n();if(P.target===H.captureRect){const X=Ol({client:{x:P.clientX,y:P.clientY},capture:H.captureRect?.getBoundingClientRect()??null,engine:H.engine,layers:H.scene.layers,parsingLocale:H.scene.config.parsingLocale,hasMenu:H.hasOverlayMenu});if(X!==null){m.getState().setCaret(null),G(P,{kind:"select-observations",target:X.target,observationIndex:X.observationIndex});return}}}const Q=B.scene.coordSystem.type==="polar"&&K.kind==="select-observations";if(V&&(K.kind==="clear"||Q)&&C.current&&ln(P,e,z.elements)===null&&!Vl(P.target,z.elements)){const H=Gl({client:{x:P.clientX,y:P.clientY},capture:B.captureRect?.getBoundingClientRect()??null,frame:e.getBoundingClientRect(),engine:B.engine,layers:B.scene.layers});if(H!==null){m.getState().setCaret(null),G(P,{kind:"clear"}),I||m.getState().setPlotMenu(H);return}}m.getState().setCaret(null),G(P,K)},j=P=>{if(h.isWithinAnyChartChrome(P.target)||M(P)||l.isOnLiveGeomMark(P.target,e))return;const k=A(P),{layers:O,guides:I,config:F}=d.getState().scene,{hasOverlayMenu:W}=n(),L=i.getState(),D=m.getState();switch(k?.kind){case"observations":{const{observations:B}=k,z=kl(B,O,F.parsingLocale);if(z===null||!W(z))return;const{observationIndex:V}=B;D.setPressedObservation({observationIndex:V,predicate:z.predicate,selectedFor:z}),L.setSelection([z]);return}case"axis":case"legend":{const B=Tl(k,{layers:O,legends:I.legends.drawn,formattedAxes:T.current,parsingLocale:F.parsingLocale});if(B===null||!W(B))return;L.setSelection([B]);return}case"annotation":{const{target:B}=k;if(!S.current.spec.textAnnotations.some(z=>z.id===B.id))return;L.setSelection([B]),D.setCaret(B.id);return}case"grid":case void 0:return}};return document.addEventListener("pointerdown",R),document.addEventListener("dblclick",j),()=>{document.removeEventListener("pointerdown",R),document.removeEventListener("dblclick",j)}},[e,m,i,d,o,b,a,S,T,f,y,C,n,g,u,c])},Vl=(e,t)=>h.isWithinTextEntry(e)||hn(e)||t.some(hn),hn=e=>e instanceof Element&&e.closest(zl)!==null,Ul=e=>{const{store:t}=l.useGraphContext(),{engine:n,overlayRef:r}=l.useHoverContext(),{showAnnotations:o,selectObservationsOnPress:a,selectGuidesOnPress:i,hoverTolerance:d}=l.MODE_RULES[l.useGraphMode()],{waitingForView:u}=l.useGraphAnimation(),c=h.useHasOverlayMenu(),g=a&&!u;return(0,w.useCallback)(()=>({frameElement:e,captureRect:r.current,selectGuidesOnPress:i,showAnnotations:o,resolvesObservations:g,engine:n,tolerance:d??void 0,scene:t.getState().scene,hasOverlayMenu:c}),[c,e,r,i,o,g,n,d,t])},Xl={kind:"idle"},Kl=()=>{const e=l.useEditorState(n=>n.standingInteraction),t=Oo();return(0,w.useMemo)(()=>e!==null?e:t===null?Xl:{kind:"trigger",anchor:t,isOpen:!0},[e,t])},$l=(e,t)=>e.x>=0&&e.x<=t.width&&e.y>=0&&e.y<=t.height,Yl=(e,t,n)=>{const{selectionStore:r}=l.useGraphContext(),{store:o,engine:a}=l.useHoverContext(),i=l.useLatestRef(e),d=l.useLatestRef(t),u=l.useLatestRef(n);(0,w.useEffect)(()=>{const c=x=>{if(r.getState().selection.length>0)return;const f=u.current,y=d.current,C={x:x.clientX-y.x,y:x.clientY-y.y},S=$l(C,f)?a.query((0,p.toPanelCursor)(C,f)):p.RESTING_HOVER_STATE;o.getState().setHoverState(S)};let g=!1;const m=()=>{const x=i.current;g=x.kind==="trigger"&&x.isOpen},v=x=>{h.isWithinAnyChartChrome(x.target)||g&&r.getState().selection.length===0&&c(x)};return document.addEventListener("pointerdown",m,!0),document.addEventListener("click",v),()=>{document.removeEventListener("pointerdown",m,!0),document.removeEventListener("click",v)}},[r,i,o,a,d,u])},ql=(e,t)=>{const n=l.useEditorStore(),{store:r}=l.useGraphContext(),{store:o}=l.useHoverContext(),{selectObservationsOnPress:a}=l.MODE_RULES[l.useGraphMode()];(0,w.useEffect)(()=>(o.getState().setEditorOwnsQuery(a),()=>o.getState().setEditorOwnsQuery(!1)),[o,a]),(0,w.useEffect)(()=>{let i=null,d=null,u=!1;const c=b=>{if(!a)return;const T=o.getState();T.suspendsHover||b===null&&T.hover.primary===null||T.setHoverState(b??p.RESTING_HOVER_STATE)},g=()=>{if(i=null,d===null)return;const b=n.getState();if(be(b.standingInteraction))return;if(u&&(u=!1,d={...d,target:Zl(d)}),l.isOnLiveGeomMark(d.target,e)){b.setEditTargetUnderPointer(null);return}const{targetAtPoint:T,hover:E}=nt(d,t()),A=Ve(b.standingInteraction)&&T?.kind==="annotation";b.setEditTargetUnderPointer(A?null:T),c(E)},m=()=>{i===null&&(i=requestAnimationFrame(g))},v=()=>{d!==null&&(u=!0,m())},x=()=>{n.getState().setEditTargetUnderPointer(null),c(null)},f=b=>{d={target:b.target,clientX:b.clientX,clientY:b.clientY},u=!1,m()},y=()=>{d=null,i!==null&&(cancelAnimationFrame(i),i=null),x()},C=n.subscribe((b,T)=>{const E=be(T.standingInteraction)&&!be(b.standingInteraction),A=Ve(T.standingInteraction)!==Ve(b.standingInteraction);(E||A)&&v()}),S=r.subscribe((b,T)=>{b.scene!==T.scene&&(be(n.getState().standingInteraction)||v())});return e.addEventListener("pointermove",f),e.addEventListener("pointerleave",y),()=>{i!==null&&cancelAnimationFrame(i),C(),S(),e.removeEventListener("pointermove",f),e.removeEventListener("pointerleave",y),x()}},[e,n,r,o,a,t])},Zl=e=>typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):e.target,Ve=e=>e?.kind==="arrow-draw",be=e=>{if(e===null)return!1;switch(e.kind){case"move-drag":case"shape-resize-drag":case"difference-arrow-endpoint-drag":case"arrow-endpoint-drag":case"text-resize-drag":return!0;case"arrow-draw":case"box-draw":case"chrome-popup":return!1}},Jl=(e,t,n,r,o)=>{const a=Kl(),{store:i}=l.useHoverContext(),d=l.useGraphSelection().length>0,{freezeHoverWhileSelected:u}=l.MODE_RULES[l.useGraphMode()],c=Ul(e);ql(e,c),Wl(e,n,c,o),Yl(a,t,n),Cl(e),h.useSelectionShortcuts(e,n),vl(e,n),yl(e,r);const g=d&&u;(0,w.useEffect)(()=>(i.getState().setSuspendsHover(g),()=>i.getState().setSuspendsHover(!1)),[i,g]),(0,w.useEffect)(()=>{if(!d||!u)return;const m=i.getState();m.setHoverState(p.RESTING_HOVER_STATE),m.setTooltipAnchor(null)},[i,d,u])},Ql=new Set(["Shift","Control","Alt","Meta"]),ed=e=>{(0,w.useEffect)(()=>{if(e===null)return;const t=r=>{Ql.has(r.key)||e.setAttribute(h.KEYBOARD_INPUT_ATTRIBUTE,"")},n=()=>e.removeAttribute(h.KEYBOARD_INPUT_ATTRIBUTE);return document.addEventListener("keydown",t,!0),document.addEventListener("pointerdown",n,!0),()=>{document.removeEventListener("keydown",t,!0),document.removeEventListener("pointerdown",n,!0),e.removeAttribute(h.KEYBOARD_INPUT_ATTRIBUTE)}},[e])},td=({frameElement:e,panelRect:t,formattedAxes:n})=>{const{measureRef:r,screenRect:o}=l.useElementScreenRect(),{selectionStore:a,store:i,history:d}=l.useGraphContext(),u=l.useEditorStore(),c=h.useRemoveAnnotation(t),g=(0,w.useRef)(()=>{});(0,w.useEffect)(()=>{g.current=()=>{h.discardEmptyTextCaret(u,i.getState().scene.annotations,c,h.readAnnotationPlacementHistory(d))}},[c,u,d,i]);const m=o?.width??0,v=o?.height??0,x=(0,w.useRef)({width:m,height:v});(0,w.useEffect)(()=>{const S=x.current;x.current={width:m,height:v},!(S.width===m&&S.height===v)&&u.getState().setAnnotatePress(null)},[m,v,u]);const f=l.useEditorState(S=>S.caret?.annotationId??null),y=l.useGraphMode(),C=(0,w.useRef)(y);return(0,w.useEffect)(()=>(r(e),()=>r(null)),[r,e]),(0,w.useEffect)(()=>()=>{g.current();const S=u.getState();S.setCaret(null),S.setPressedObservation(null),S.setPlotMenu(null),a.getState().clearSelection()},[u,a]),(0,w.useEffect)(()=>{if(C.current===y)return;C.current=y,g.current();const S=u.getState();S.setCaret(null),S.setEditTargetUnderPointer(null),S.setPlotMenu(null),a.getState().clearSelection()},[y,u,a]),o===null?null:(0,s.jsxs)(s.Fragment,{children:[f!==null&&(0,s.jsx)(nd,{annotationId:f,panelRect:t}),(0,s.jsx)(rd,{frameElement:e,frameRect:o,panelRect:t,formattedAxes:n})]})},nd=({annotationId:e,panelRect:t})=>{const n=l.useEditorStore(),{textAnnotations:r}=l.useResolvedAnnotations(t);return(0,w.useEffect)(()=>{r.some(({id:o})=>o===e)||n.getState().setCaret(null)},[e,r,n]),null},rd=({frameElement:e,frameRect:t,panelRect:n,formattedAxes:r})=>{const o=(0,w.useMemo)(()=>({x:t.left+n.x,y:t.top+n.y}),[t.left,t.top,n.x,n.y]),[a,i]=(0,w.useState)(null);return Jl(e,o,n,a,r),(0,s.jsx)(od,{frameElement:e,frameRect:t,panelOrigin:o,panelRect:n,boxRef:i})},od=({frameElement:e,frameRect:t,panelOrigin:n,panelRect:r,boxRef:o})=>{const a=h.useChartChromeContainer();ed(a);const{showAnnotations:i}=l.MODE_RULES[l.useGraphMode()];return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ta,{frameElement:e,frameSize:(0,w.useMemo)(()=>({width:t.width,height:t.height}),[t.width,t.height]),panelRect:r}),(0,s.jsx)(Ba,{frameRect:t}),(0,s.jsx)(Zr,{rect:t,zIndex:l.Z_INDEX.editorOverlay,container:a,"data-testid":"editor-overlay",boxRef:o,children:(0,s.jsxs)(l.PortalThemeProvider,{children:[i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(mi,{panelRect:r,panelOrigin:n,frameElement:e}),(0,s.jsx)(zi,{panelRect:r,frameElement:e}),(0,s.jsx)(Ls,{panelRect:r,frameElement:e}),(0,s.jsx)(nl,{panelRect:r,frameElement:e}),(0,s.jsx)(Yi,{panelRect:r,frameElement:e}),(0,s.jsx)($a,{panelRect:r}),(0,s.jsx)(wi,{frameElement:e,panelRect:r}),(0,s.jsx)(Ci,{panelRect:r}),(0,s.jsx)(ls,{panelRect:r}),(0,s.jsx)(Ka,{panelRect:r}),(0,s.jsx)(ns,{panelRect:r}),(0,s.jsx)(Ks,{frameElement:e,panelRect:r})]}),(0,s.jsx)(Na,{frameElement:e,panelRect:r}),i&&(0,s.jsx)(lo,{frameElement:e,panelRect:r}),(0,s.jsx)(dl,{})]})})]})},ad={},sd=({slots:e,palettePresets:t=ad,editMenus:n,...r})=>{const o=l.useChartI18nProps(l.useFormattingLocale()),a=l.useGraphMode(),i=Pn(),d=(0,w.useMemo)(()=>({EditorSurface:td,...e}),[e]),u=(0,w.useMemo)(()=>Kr(a,i),[a,i]);return(0,s.jsx)(st,{...o,children:(0,s.jsx)(h.EditMenuRegistryProvider,{editMenus:n,children:(0,s.jsx)(l.EditorProvider,{children:(0,s.jsx)(Yr,{children:(0,s.jsx)(h.PalettePresetsProvider,{value:t,children:(0,s.jsx)(l.InlineEditorsProvider,{editors:u,children:(0,s.jsx)(h.ChartChromeRoot,{children:(0,s.jsx)(l.GraphRendererBody,{slots:d,...r})})})})})})})})},id="_12lhx9e0",mr=({children:e})=>(0,s.jsx)("div",{className:id,children:e}),ld="_139ohwv0",$=({children:e})=>(0,s.jsx)("div",{className:ld,children:e}),vr=(0,w.createContext)(null),dd=vr.Provider,xr=()=>{const e=(0,w.useContext)(vr);if(!e)throw new Error("A section must be rendered inside <EditorPanel.Root>.");return e},cd="_1jlczkt0",fr="data-graphy-editor-panel",ud={List:$,Grid:mr};function hd(e){if(e===void 0)return!1;const t=e.split(/\s+/);return t.includes("_1ii3bsb0")||t.includes("_1ii3bsb1")}var gd=()=>()=>{},pd=e=>{const t=(0,w.useSyncExternalStore)(e?.subscribe??gd,()=>e?.getScene()?.config.parsingLocale);return e?.formattingLocale??t},md=e=>{const t=(0,w.useContext)(l.GraphContext),n=l.useChartI18nProps(pd(l.useGraphHandle(e.handle))),r=l.useHasThemeContext();let o=(0,s.jsx)(vd,{...e});return!r&&t&&(o=(0,s.jsx)(l.ThemeProvider,{colorScheme:t.colorScheme,children:o})),(0,s.jsx)(st,{...n,children:o})},xt={Root:md,Controls:ud},vd=({handle:e,children:t,controls:n,defaultExpandedSection:r=void 0,className:o})=>{const a=l.useGraphHandle(e),{themeClass:i,inlineVarsStyle:d}=l.useThemeContext(),[u,c]=(0,w.useState)(()=>r?[r]:[]),g=(0,w.useMemo)(()=>({expandSection:m=>c([m]),collapseAllSections:()=>c([])}),[]);return(0,s.jsx)(h.PanelGraphContext.Provider,{value:a,children:(0,s.jsx)(h.ControlRegistryProvider,{controls:n,children:(0,s.jsx)(dd,{value:g,children:(0,s.jsx)(de.Accordion.Root,{[fr]:"",className:(0,Ke.default)(cd,o,{[i]:!hd(o)}),style:d,value:u,onValueChange:m=>c(m),children:t})})})})},xd="_2m7wuq0",fd=()=>(0,s.jsx)(Hr.Separator,{className:xd}),yd=e=>(0,s.jsx)(l.Icon,{...e,children:(0,s.jsx)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"m9 6 6 6-6 6"})})}),ft="_40zvwv0",yt="_40zvwv1",Sd="_40zvwv2",yr="_40zvwv3",wd="_40zvwv4 _40zvwv3";var bd="_40zvwv6";var Cd="_40zvwv8",U=({title:e,layout:t="fixed",preview:n,accessory:r,onOpenChange:o,children:a})=>t==="collapsible"?(0,s.jsx)(Ad,{title:e,preview:n,accessory:r,onOpenChange:o,children:a}):t==="inline"&&n===void 0?(0,s.jsx)(Td,{title:e,accessory:r,children:a}):(0,s.jsxs)("div",{className:ft,children:[(0,s.jsxs)("div",{className:yt,children:[(0,s.jsx)("span",{className:yr,children:e}),n!==void 0&&(0,s.jsx)("span",{className:"_40zvwv5",children:n}),r!==void 0&&(0,s.jsx)("span",{className:"_40zvwv7",children:r})]}),(0,s.jsx)("div",{children:a})]}),Td=({title:e,accessory:t,children:n})=>{const r=(0,w.useId)(),o=(0,w.useId)();return(0,s.jsx)("div",{className:ft,children:(0,s.jsxs)("div",{className:yt,children:[(0,s.jsx)("label",{id:r,htmlFor:o,className:wd,children:e}),(0,s.jsx)("span",{className:bd,children:(0,s.jsx)(h.RowLabelingProvider,{labelId:r,controlId:o,children:n})}),t!==void 0&&(0,s.jsx)("span",{className:"_40zvwv7",children:t})]})})},Ad=({title:e,preview:t,accessory:n,onOpenChange:r,children:o})=>{const a=l.useI18n();return(0,s.jsxs)(de.Accordion.Item,{value:e,className:ft,onOpenChange:r,children:[(0,s.jsxs)(de.Accordion.Header,{className:yt,render:(0,s.jsx)("div",{}),children:[(0,s.jsx)(de.Accordion.Trigger,{className:Sd,"aria-label":a("editor.accessibility.toggleSection",{title:e})}),(0,s.jsx)("span",{className:yr,children:e}),t!==void 0&&(0,s.jsx)("span",{className:"_40zvwv5",children:t}),n!==void 0&&(0,s.jsx)("span",{className:"_40zvwv7",children:n}),(0,s.jsx)("span",{className:Cd,children:(0,s.jsx)(yd,{size:"sm"})})]}),(0,s.jsx)(de.Accordion.Panel,{children:(0,s.jsx)("div",{children:o})})]})},Sr=({title:e,checked:t,onToggle:n,disabled:r,preview:o,children:a})=>{const{expandSection:i,collapseAllSections:d}=xr(),{Switch:u}=h.useControls(),c=m=>{n(m),m?i(e):d()},g=m=>{m&&!t&&r!==!0&&n(!0)};return(0,s.jsx)(U,{title:e,layout:"collapsible",preview:o,onOpenChange:g,accessory:(0,s.jsx)(u,{checked:t,onChange:c,disabled:r,ariaLabel:e}),children:a})},Pd={horizontal:["bottom","top"],vertical:["left","right"]},Id={left:"editor.axesPanel.position.left",right:"editor.axesPanel.position.right",top:"editor.axesPanel.position.top",bottom:"editor.axesPanel.position.bottom"},Ed={x:"editor.axesPanel.mainAxisSection.xAxis",y:"editor.axesPanel.mainAxisSection.yAxis",ySecondary:"editor.axesPanel.mainAxisSection.ySecondaryAxis"},Pe=({axis:e,title:t,layout:n="collapsible",preview:r})=>{const o=h.usePanelGraph(),a=l.useHandleScene(o),i=l.useI18n(),{DateField:d,NumberField:u,Switch:c,TextField:g,ToggleGroup:m}=h.useControls();if(!a||e==="ySecondary"&&(a.coordSystem.type!=="cartesian"||a.scales.ySecondary===void 0))return null;const v=e==="ySecondary"||a.coordSystem.type!=="polar"?"linear":a.coordSystem.axisMapping[e].geometry,x=a.scales[e],f=x?.spec,y=f?.scaleType==="continuous"?f:void 0,C=f?.scaleType==="datetime",S=f?.scaleType==="continuous"||C?f:void 0;if(v==="circular"||v==="radial"&&y===void 0)return null;const b=f?.scaleType==="continuous"||f?.scaleType==="datetime",T=y!==void 0&&(0,p.isZeroAnchoredAxis)(a,e),E=y?.transform==="log",A=S?.domainMax??null,M=jd(S),N=(_,Y)=>_.map(xe=>({value:xe,label:Y(xe)})),G=a.guides.axes.find(_=>_.scaledAesthetic===e);if(G===void 0)return null;const R=G.position,j=a.guides.axes.filter(_=>_.scaledAesthetic===e),P=j.some(_=>_.visible),k=j.some(_=>_.visible||_.showGrid),O=e==="ySecondary"?a.config.axes.ySecondary?.label??G.label??"":a.config.axes[e].label??G.label??"",I=Pd[R==="bottom"||R==="top"?"horizontal":"vertical"],F=e==="y"?(0,p.readComboLineLayerId)(a.spec):null,W=F===null?void 0:(0,p.findLayerById)(a.spec.layers,F),L=a.guides.legends.drawn.some(_=>!_.inHeadlineRow&&I.some(Y=>Y===_.position)),D=I.map(_=>({value:_,label:i(Id[_])})),B=N(["auto","edges"],_=>i(_==="edges"?"editor.axesPanel.labelMode.edges":"editor.axesPanel.labelMode.auto")),z=N(["linear","log"],_=>i(_==="log"?"editor.axesPanel.scale.log":"editor.axesPanel.scale.auto")),V=N(C?["auto","custom"]:["auto","zero","custom"],_=>i(_==="zero"?"editor.axesPanel.startFrom.zero":_==="custom"?"editor.axesPanel.startFrom.custom":"editor.axesPanel.startFrom.auto")),K=N(["auto","custom"],_=>i(_==="custom"?"editor.axesPanel.endAt.custom":"editor.axesPanel.endAt.auto")),Z=N(["single","double"],_=>i(_==="double"?"editor.axesPanel.axisCount.double":"editor.axesPanel.axisCount.single")),Q=_=>{if(e==="ySecondary"){o.commands.dispatch(new p.SetAxisVisibilityCommand({axis:e,visible:Ue(_,a.config.axes.y.visible)}));return}o.commands.dispatch(new p.SetAxisVisibilityCommand({axis:e,visible:_,keepSecondaryAxis:!0}))},H=_=>{o.commands.dispatch(new p.SetAxisLabelCommand({axis:e,label:_}),{transient:!0})},X=_=>{if(e==="ySecondary"){o.commands.dispatch(new p.SetAxisTicksVisibilityCommand({axis:e,visible:Ue(_,a.config.axes.y.ticks.visible)}));return}o.commands.dispatch(new p.SetAxisTicksVisibilityCommand({axis:e,visible:_,keepSecondaryAxis:!0}))},ve=_=>{const Y=_==="edges"?"edges":"auto";if(e==="ySecondary"){o.commands.dispatch(new p.SetAxisTickModeCommand({axis:e,tickMode:Ue(Y,a.config.axes.y.ticks.mode)}));return}o.commands.dispatch(new p.SetAxisTickModeCommand({axis:e,tickMode:Y,keepSecondaryAxis:!0}))},_e=_=>{o.commands.dispatch(new p.SetScaleTransformCommand({scaledAesthetic:e,transform:_==="log"?"log":"linear"}))},re=_=>{o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,..._}),{transient:!0})},bt=_=>{_!==null&&re({domainMin:_})},Or=_=>{_!==null&&re({domainMax:_})},Mr=_=>{const Y=wr(_);Y!==null&&re({domainMax:Y})},_r=_=>{if(_==="auto"){o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,domainMin:null}));return}if(_==="zero"){o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,domainMin:0}));return}const Y=gn(x?.domain,"start");Y!==null&&o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,domainMin:Y}))},Dr=_=>{if(_!=="custom"){o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,domainMax:null}));return}const Y=gn(x?.domain,"end");Y!==null&&o.commands.dispatch(new p.SetScaleDomainCommand({scaledAesthetic:e,domainMax:Y}))},Fr=_=>{W!==void 0&&o.commands.dispatch(new p.SetLayerYScaleTypeCommand({layerId:W.id,yScaleType:_==="double"?"secondary":"primary"}))},Nr=_=>{if(e==="ySecondary")return;const Y=I.find(xe=>xe===_);Y&&o.commands.dispatch(new p.SetAxisPositionCommand({axis:e,position:Y}))};return(0,s.jsx)(U,{title:t??i(Ed[e]),layout:n,preview:r,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.visible"),children:(0,s.jsx)(c,{checked:G.visible,onChange:Q})}),W!==void 0&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.numberOfAxes"),children:(0,s.jsx)(m,{value:W.yScaleType==="secondary"?"double":"single",options:Z,onChange:Fr})}),v==="linear"&&(0,s.jsxs)(s.Fragment,{children:[G.visible&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.title"),children:(0,s.jsx)(g,{value:O,placeholder:i("editor.axesPanel.controls.titlePlaceholder"),onChange:H,onCommit:o.commands.commit})}),P&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.ticks"),children:(0,s.jsx)(c,{checked:G.showTicks,onChange:X})})]}),b&&k&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.labels"),children:(0,s.jsx)(m,{value:G.tickMode,options:B,onChange:ve})}),e!=="ySecondary"&&y&&v==="linear"&&G.visible&&!L&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.position"),children:(0,s.jsx)(m,{value:G.position,options:D,onChange:Nr})}),y&&!T&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.scale"),children:(0,s.jsx)(m,{value:E?"log":"linear",options:z,onChange:_e})}),S&&!E&&(0,s.jsxs)(s.Fragment,{children:[!T&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.startFrom"),children:(0,s.jsx)(m,{value:M,options:V,onChange:_r})}),M!=="auto"&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.value"),children:C?(0,s.jsx)(d,{value:Re(S.domainMin??null),onChange:bt,onCommit:o.commands.commit}):(0,s.jsx)(u,{value:S.domainMin??null,onChange:bt,onCommit:o.commands.commit})})]}),(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.endAt"),children:(0,s.jsx)(m,{value:A===null?"auto":"custom",options:K,onChange:Dr})}),A!==null&&(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.value"),children:C?(0,s.jsx)(d,{value:kd(A),onChange:Mr,onCommit:o.commands.commit}):(0,s.jsx)(u,{value:A,onChange:Or,onCommit:o.commands.commit})})]})]})})},Ue=(e,t)=>e===t?void 0:e,jd=e=>{const t=e?.domainMin??null;return t===null?"auto":e?.scaleType==="datetime"?"custom":t===0?"zero":"custom"},gn=(e,t)=>{const n=t==="start"?e?.[0]:e?.[e.length-1];return n instanceof Date?t==="start"?Re(n.getTime()):wr(n.getTime()):typeof n=="number"?n:null},Re=e=>{if(e===null||!Number.isFinite(e))return null;const t=new Date(e).toISOString().slice(0,10),n=Date.parse(`${t}T00:00:00.000Z`);return Number.isNaN(n)?null:n},wr=e=>{const t=Re(e);return t===null?null:t+864e5},kd=e=>e===null||!Number.isFinite(e)?null:Re(e-1),St=({value:e,onChange:t})=>{const n=h.usePanelGraph(),r=l.useI18n(),{TextField:o}=h.useControls(),a=e!==null&&typeof e!="string"?br(e):null,i=e!==null&&typeof e!="string"&&a===null,d=typeof e=="string"?e:a?.words??"",u=c=>{if(c==="")return t(null);t(a?a.write(c):c)};return(0,s.jsx)(h.Row,{label:r("editor.elementsPanel.contentValue"),children:(0,s.jsx)(o,{value:d,onChange:u,onCommit:n.commands.commit,disabled:i})})},br=e=>{if(e.type==="doc"){const[r,...o]=e.content??[],a=r!==void 0&&o.length===0?br(r):null;return a===null?null:{words:a.words,write:i=>({...e,content:[a.write(i)]})}}if(e.type!=="paragraph"&&e.type!=="heading")return null;const[t,...n]=e.content??[];return t?.type==="text"&&n.length===0&&(t.marks??[]).length===0?{words:t.text??"",write:r=>({...e,content:[{...t,text:r}]})}:null},Cr=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Switch:i}=h.useControls();if(!o)return null;const d=o.config.content,u=g=>{r.commands.dispatch(new p.ToggleContentVisibilityCommand({part:"caption",visible:g}))},c=g=>{r.commands.dispatch(new p.SetContentCaptionCommand({caption:g}),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.elementsPanel.footerSection.caption"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.elementsPanel.contentVisible"),children:(0,s.jsx)(i,{checked:d.showCaption,onChange:u})}),(0,s.jsx)(St,{value:d.caption,onChange:c})]})})},pn=/^[a-z][a-z\d+.-]*:/i,Rd={},Tr=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Switch:i}=h.useControls();if(!o)return null;const d=o.config.content,u=c=>{r.commands.dispatch(new p.ToggleContentVisibilityCommand({part:"source",visible:c}))};return(0,s.jsx)(U,{title:e??a("editor.elementsPanel.sourceSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.elementsPanel.contentVisible"),children:(0,s.jsx)(i,{checked:d.showSource,onChange:u})}),(0,s.jsx)(Ld,{source:d.source??Rd})]})})},Ld=({source:e})=>{const t=h.usePanelGraph(),n=l.useI18n(),{TextField:r}=h.useControls(),o=u=>{const c=(u.label??"")!==""||(u.url??"")!=="";t.commands.dispatch(new p.SetContentSourceCommand({source:c?u:null}),{transient:!0})},a=()=>{const u=e.url??"";u!==""&&!pn.test(u)&&o({...e,url:`https://${u}`}),t.commands.commit()},i=u=>o({...e,url:u}),d=u=>o({...e,label:u});return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.Row,{label:n("editor.elementsPanel.sourceSection.url"),children:(0,s.jsx)(r,{value:e.url??"",onChange:i,onCommit:a,hasError:pn.test(e.url??"")&&!(0,p.isSafeUrl)(e.url)})}),(0,s.jsx)(h.Row,{label:n("editor.elementsPanel.sourceSection.name"),children:(0,s.jsx)(r,{value:e.label??"",onChange:d,onCommit:t.commands.commit})})]})},Ar=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Switch:i}=h.useControls();if(!o)return null;const d=o.config.content,u=g=>{r.commands.dispatch(new p.ToggleContentVisibilityCommand({part:"subtitle",visible:g}))},c=g=>{r.commands.dispatch(new p.SetContentSubtitleCommand({subtitle:g}),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.elementsPanel.headerSection.subtitle"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.elementsPanel.contentVisible"),children:(0,s.jsx)(i,{checked:d.showSubtitle,onChange:u})}),(0,s.jsx)(St,{value:d.subtitle,onChange:c})]})})},me=e=>{const{colorScheme:t}=l.useThemeContext(),n=(0,w.useMemo)(()=>(0,p.createStyleResolver)({colorScheme:t}),[t]);return(0,w.useMemo)(()=>e===null?null:n.readers(e),[e,n])},wt=(e,t,n)=>{const r=me(e);return(0,w.useMemo)(()=>{if(r===null||e===null||t===null)return null;const o=(0,p.findLayerById)(e.layers,t);return o===void 0?null:r.geom[n](o)},[r,e,t,n])},rt=[.8,1,1.2,1.4,1.6,1.8,2,2.5,3,4],Od=rt.length/2,Md={select:{target:"graph"}},Pr=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{RadioGrid:i}=h.useControls(),d=me(o);if(!o||!d)return null;const u=d.graph().get("textScale"),c=v=>a("editor.elementsPanel.textSizeSection.scaleFormat",{value:`${v}`}),g=rt.map(v=>({value:`${v}`,label:c(v)})),m=v=>{const x=rt.find(y=>`${y}`===v);if(x===void 0)return;const f=(0,p.findStyleRule)(o.spec.styles.overrides,Md,(0,p.readStyleCoord)(o.spec))?.declarations??{};r.commands.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"graph"},declarations:{...f,textScale:x}}}))};return(0,s.jsx)(U,{title:e??a("editor.elementsPanel.textSizeSection.title"),layout:t,preview:n??c(u),children:(0,s.jsx)(i,{value:`${u}`,options:g,columns:Od,onChange:m,ariaLabel:a("editor.elementsPanel.textSizeSection.title")})})},Ir=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Switch:i}=h.useControls();if(!o)return null;const d=o.config.content,u=g=>{r.commands.dispatch(new p.ToggleContentVisibilityCommand({part:"title",visible:g}))},c=g=>{r.commands.dispatch(new p.SetContentTitleCommand({title:g}),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.elementsPanel.headerSection.toggleTitle"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.elementsPanel.contentVisible"),children:(0,s.jsx)(i,{checked:d.showTitle,onChange:u})}),(0,s.jsx)(St,{value:d.title,onChange:c})]})})},_d=({children:e,...t})=>(0,s.jsx)(xt.Root,{...t,children:e??(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ir,{}),(0,s.jsx)(Ar,{}),(0,s.jsx)(Cr,{}),(0,s.jsx)(Tr,{}),(0,s.jsx)(Pr,{})]})}),Dd=({children:e,...t})=>(0,s.jsx)(xt.Root,{...t,children:e??(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Pe,{axis:"x"}),(0,s.jsx)(Pe,{axis:"y"}),(0,s.jsx)(Pe,{axis:"ySecondary"})]})}),Le=e=>`${e}px`,Er=e=>`${Math.round(e*100)}%`,Fd=e=>`${e}°`,Nd=24,Gd={select:{target:"graph"}},mn=["dim","desaturate"],Bd=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Slider:i,ToggleGroup:d}=h.useControls(),u=me(o);if(!o||!u)return null;const c=u.graph().get("cornerRadius"),g=(0,p.readHighlightDimStyle)(o.spec),m=mn.map(f=>({value:f,label:a(f==="dim"?"editor.highlighting.highlightStyle.tint":"editor.highlighting.highlightStyle.gray")})),v=f=>{const y=(0,p.findStyleRule)(o.spec.styles.overrides,Gd,(0,p.readStyleCoord)(o.spec))?.declarations??{};r.commands.dispatch(new p.SetStyleRuleCommand({list:"overrides",rule:{select:{target:"graph"},declarations:{...y,cornerRadius:f}}}),{transient:!0})},x=f=>{const y=mn.find(C=>C===f);y&&r.commands.dispatch(new p.SetHighlightDimStyleCommand({dimStyle:y}))};return(0,s.jsx)(U,{title:e??a("editor.colorPanel.appearanceSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.colorPanel.borderSection.cornerRadius"),children:(0,s.jsx)(i,{value:c,min:0,max:Nd,step:1,formatValue:Le,onChange:v,onCommit:r.commands.commit})}),(0,s.jsx)(h.Row,{label:a("editor.colorPanel.appearanceSection.highlightStyle"),children:(0,s.jsx)(d,{value:g,options:m,onChange:x})})]})})},Hd={none:0,md:3.5,full:6.5},zd=({cornerRadius:e,...t})=>(0,s.jsx)(l.Icon,{viewBox:"0 0 18 18",...t,children:(0,s.jsx)("rect",{x:2.5,y:2.5,width:13,height:13,rx:Hd[e],stroke:"currentColor",strokeWidth:1.5})}),Wd=.05,vn=["none","md","full"],jr={base:["baseStart","baseEnd"],tip:["tipStart","tipEnd"]},Vd=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Slider:i,ToggleGroup:d}=h.useControls(),u=o?(0,p.findLayerByGeom)(o.spec.layers,"bar"):void 0,c=wt(o,u?.id??null,"bar");if(!o||!u||o.coordSystem.type==="polar"&&o.coordSystem.bandAxis===null)return null;const g=y=>{r.commands.dispatch(new p.SetBarWidthCommand({layerId:u.id,width:y}),{transient:!0})},m=c?.get("cornerRadius")??p.DEFAULT_BAR_CORNER_RADII,v=(y,C)=>{const S=vn.find(E=>E===C);if(!S)return;const[b,T]=jr[y];r.commands.dispatch(new p.SetBarCornerRadiusCommand({layerId:u.id,corners:{...m,[b]:S,[T]:S}}))},x=vn.map(y=>({value:y,label:a(`editor.graphPanel.barSection.radiusOptions.${y}`),icon:(0,s.jsx)(zd,{cornerRadius:y})})),f=(0,p.resolveBarBandFraction)(u.params,o.coordSystem.type);return(0,s.jsx)(U,{title:e??a("editor.graphPanel.barSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.barSection.thickness"),children:(0,s.jsx)(i,{value:f,min:p.MIN_BAR_WIDTH_FRACTION,max:p.MAX_BAR_WIDTH_FRACTION,step:Wd,formatValue:Er,onChange:g,onCommit:r.commands.commit})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.barSection.tipRadius"),children:(0,s.jsx)(d,{value:xn(m,"tip"),options:x,onChange:y=>v("tip",y)})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.barSection.baseRadius"),children:(0,s.jsx)(d,{value:xn(m,"base"),options:x,onChange:y=>v("base",y)})})]})})},xn=(e,t)=>{const[n,r]=jr[t],o=e[n];return typeof o!="string"||o!==e[r]?"":o==="none"||o==="full"?o:"md"},Oe=({children:e})=>{const t=(0,w.useId)();return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("g",{filter:`url(#${t})`,children:e}),(0,s.jsx)("defs",{children:(0,s.jsxs)("filter",{id:t,x:"-20%",y:"-20%",width:"140%",height:"140%",children:[(0,s.jsx)("feDropShadow",{dx:"0",dy:"0",stdDeviation:"0.586",floodColor:"#0F0F18",floodOpacity:"0.12"}),(0,s.jsx)("feDropShadow",{dx:"0",dy:"1.172",stdDeviation:"0.586",floodColor:"#0E0E34",floodOpacity:"0.16"})]})})]})},Me="qdaoth0",Ud=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 31 33",...e,children:[(0,s.jsx)(Oe,{children:(0,s.jsx)("path",{className:Me,fillRule:"evenodd",clipRule:"evenodd",d:"M25.7417 6.23664C25.7417 6.09417 25.7076 5.95967 25.6471 5.84086C25.5633 5.67624 25.4288 5.54173 25.2641 5.4579C25.1453 5.39739 25.0108 5.36328 24.8684 5.36328H12.0591C11.5767 5.36328 11.1857 5.7543 11.1857 6.23664C11.1857 6.71899 11.5767 7.11 12.0591 7.11H22.7599L5.61908 24.2508C5.27801 24.5919 5.27801 25.1448 5.61908 25.4859C5.96015 25.827 6.51313 25.827 6.8542 25.4859L23.995 8.34513V19.0459C23.995 19.5283 24.386 19.9193 24.8684 19.9193C25.3507 19.9193 25.7417 19.5283 25.7417 19.0459V6.23664ZM20.995 15.5878V19.0459C20.995 21.1851 22.7292 22.9193 24.8684 22.9193C27.0076 22.9193 28.7417 21.1851 28.7417 19.0459V6.23664C28.7417 4.09744 27.0076 2.36328 24.8684 2.36328H12.0591C9.91985 2.36328 8.18569 4.09744 8.18569 6.23664C8.18569 8.37584 9.91985 10.11 12.0591 10.11H15.5172L3.49777 22.1295C1.98512 23.6421 1.98513 26.0946 3.49776 27.6072C5.0104 29.1199 7.46288 29.1199 8.97552 27.6072L20.995 15.5878Z"})}),(0,s.jsx)("path",{fill:"currentColor",d:"M12.0591 7.11C11.5767 7.11 11.1857 6.71899 11.1857 6.23664C11.1857 5.7543 11.5767 5.36328 12.0591 5.36328H24.8684C25.3507 5.36328 25.7417 5.7543 25.7417 6.23664V19.0459C25.7417 19.5283 25.3507 19.9193 24.8684 19.9193C24.386 19.9193 23.995 19.5283 23.995 19.0459V8.34512L6.8542 25.4859C6.51313 25.827 5.96015 25.827 5.61908 25.4859C5.27801 25.1448 5.27801 24.5919 5.61908 24.2508L22.7599 7.11H12.0591Z"})]}),Xd=e=>(0,s.jsx)(l.Icon,{viewBox:"0 0 32 32",...e,children:(0,s.jsxs)(Oe,{children:[(0,s.jsx)("path",{className:Me,d:"M11 21H21V11H11V21ZM29 23C29 26.3137 26.3137 29 23 29H9C5.68629 29 3 26.3137 3 23V9C3 5.68629 5.68629 3 9 3H23C26.3137 3 29 5.68629 29 9V23Z"}),(0,s.jsx)("path",{fill:"currentColor",d:"M24.25 9C24.25 8.30964 23.6904 7.75 23 7.75H9C8.30964 7.75 7.75 8.30964 7.75 9V23C7.75 23.6904 8.30964 24.25 9 24.25H23C23.6904 24.25 24.25 23.6904 24.25 23V9ZM25.75 23C25.75 24.5188 24.5188 25.75 23 25.75H9C7.48122 25.75 6.25 24.5188 6.25 23V9C6.25 7.48122 7.48122 6.25 9 6.25H23C24.5188 6.25 25.75 7.48122 25.75 9V23Z"})]})}),Kd=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 32 33",...e,children:[(0,s.jsx)(Oe,{children:(0,s.jsx)("path",{className:Me,fillRule:"evenodd",clipRule:"evenodd",d:"M4.89961 14.7968C3.08522 13.5116 1.89961 11.3966 1.89961 9.00039C1.89961 5.07917 5.07839 1.90039 8.99961 1.90039C10.7798 1.90039 12.4069 2.55553 13.6531 3.63785C14.3179 3.17306 15.1269 2.90039 15.9996 2.90039L22.9996 2.90039C25.264 2.90039 27.0996 4.73602 27.0996 7.00039L27.0996 9.7243C27.5717 9.92414 28.014 10.2165 28.3987 10.6013C29.9999 12.2024 29.9999 14.7984 28.3987 16.3995L27.9182 16.8801C29.2628 18.172 30.0996 19.9885 30.0996 22.0004C30.0996 25.9216 26.9208 29.1004 22.9996 29.1004C21.2195 29.1004 19.5923 28.4453 18.3461 27.3629C17.6813 27.8277 16.8723 28.1004 15.9996 28.1004L8.99961 28.1004C6.73524 28.1004 4.89961 26.2648 4.89961 24.0004L4.89961 14.7968Z"})}),(0,s.jsx)("path",{fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd",d:"M25.25 22C25.25 20.7574 24.2426 19.75 23 19.75C21.7574 19.75 20.75 20.7574 20.75 22C20.75 23.2426 21.7574 24.25 23 24.25C24.2426 24.25 25.25 23.2426 25.25 22ZM23 18.25C25.0711 18.25 26.75 19.9289 26.75 22C26.75 24.0711 25.0711 25.75 23 25.75C20.9289 25.75 19.25 24.0711 19.25 22C19.25 19.9289 20.9289 18.25 23 18.25ZM11.25 9C11.25 7.75736 10.2426 6.75 9 6.75C7.75736 6.75 6.75 7.75736 6.75 9C6.75 10.2426 7.75736 11.25 9 11.25C10.2426 11.25 11.25 10.2426 11.25 9ZM9.75 12.675C11.4617 12.3275 12.75 10.8142 12.75 9C12.75 6.92893 11.0711 5.25 9 5.25C6.92893 5.25 5.25 6.92893 5.25 9C5.25 10.8142 6.53832 12.3275 8.25 12.675L8.25 24C8.25 24.4142 8.58579 24.75 9 24.75L16 24.75C16.4142 24.75 16.75 24.4142 16.75 24L16.75 7.75L22.25 7.75L22.25 14.1893L21.0303 12.9697C20.7374 12.6768 20.2626 12.6768 19.9697 12.9697C19.6768 13.2626 19.6768 13.7374 19.9697 14.0303L22.4697 16.5303C22.7626 16.8232 23.2374 16.8232 23.5303 16.5303L26.0303 14.0303C26.3232 13.7374 26.3232 13.2626 26.0303 12.9697C25.7374 12.6768 25.2626 12.6768 24.9697 12.9697L23.75 14.1893L23.75 7C23.75 6.58579 23.4142 6.25 23 6.25L16 6.25C15.5858 6.25 15.25 6.58579 15.25 7L15.25 23.25L9.75 23.25L9.75 12.675Z"})]}),$d=e=>(0,s.jsxs)(l.Icon,{viewBox:"0 0 32 33",...e,children:[(0,s.jsx)(Oe,{children:(0,s.jsx)("path",{className:Me,d:"M20.7271 2C21.4372 2 21.7114 2.00463 22.0841 2.03504C22.8228 2.0954 23.4839 2.25122 24.1592 2.59527C25.1865 3.1188 26.0219 3.9541 26.5458 4.98208C26.8896 5.65706 27.0454 6.31812 27.1057 7.05672C27.1301 7.35469 27.1379 7.58979 27.14 8.03558L27.1408 9.10155C27.1408 11.2114 25.4304 12.922 23.3205 12.922C21.4083 12.922 19.8243 11.5172 19.5441 9.68336L19.538 9.64H18.39V21.687L20.0392 21.6877C22.149 21.6877 23.8595 23.398 23.8595 25.508C23.8595 27.6178 22.149 29.3283 20.0392 29.3283H9.10159C6.99169 29.3283 5.28127 27.6178 5.28127 25.508C5.28127 23.398 6.99172 21.6877 9.10159 21.6877L10.75 21.687V9.64H9.601L9.59661 9.68334C9.32609 11.4539 7.84018 12.8246 6.01692 12.917L5.82032 12.922C3.71035 12.922 2 11.2114 2 9.10155V8.41371C2 7.70349 2.00463 7.42929 2.03504 7.05674C2.09538 6.31803 2.25122 5.65681 2.59521 4.98173C3.11877 3.95419 3.95418 3.11876 4.98174 2.5952C5.65683 2.25122 6.31798 2.09539 7.057 2.03501C7.42935 2.00463 7.70354 2 8.41371 2H20.7271Z"})}),(0,s.jsx)("path",{fill:"currentColor",d:"M8.41371 5H20.7271C21.1595 5 21.5325 5 21.8398 5.02507C22.1641 5.05157 22.4867 5.11007 22.7971 5.26822C23.2601 5.50416 23.6366 5.88064 23.8726 6.3437C24.0307 6.65409 24.0892 6.97666 24.1157 7.30097C24.1408 7.60823 24.1408 7.98127 24.1408 8.41369V9.10155C24.1408 9.55465 23.7735 9.92195 23.3205 9.92195C22.8674 9.92195 22.5001 9.55465 22.5001 9.10155V8.44533C22.5001 7.97237 22.4995 7.66699 22.4805 7.43457C22.4623 7.21172 22.4314 7.12909 22.4107 7.08853C22.3321 6.93418 22.2066 6.80869 22.0522 6.73004C22.0117 6.70938 21.9291 6.67847 21.7062 6.66026C21.4738 6.64127 21.1684 6.64063 20.6954 6.64063H15.3907V24.6877H20.0392C20.4922 24.6877 20.8595 25.0549 20.8595 25.508C20.8595 25.961 20.4922 26.3283 20.0392 26.3283H9.10159C8.64854 26.3283 8.28127 25.961 8.28127 25.508C8.28127 25.0549 8.64854 24.6877 9.10159 24.6877H13.7501V6.64063H8.44533C7.97238 6.64063 7.66699 6.64127 7.43457 6.66026C7.21172 6.67847 7.1291 6.70938 7.08854 6.73004C6.93418 6.80869 6.80869 6.93418 6.73004 7.08853C6.70938 7.12909 6.67847 7.21172 6.66026 7.43457C6.64127 7.66699 6.64063 7.97237 6.64063 8.44533V9.10155C6.64063 9.55465 6.27337 9.92195 5.82032 9.92195C5.36727 9.92195 5 9.55465 5 9.10155V8.41371C5 7.98128 5 7.60823 5.02508 7.30097C5.05157 6.97666 5.11007 6.65409 5.26823 6.3437C5.50417 5.88064 5.88064 5.50416 6.3437 5.26822C6.65409 5.11007 6.97666 5.05157 7.30097 5.02507C7.60824 5 7.98129 5 8.41371 5Z"})]}),Yd={x:.5,y:.5},qd=.2,Zd={x:.375,y:.25,width:.25,height:.5},Jd={zOrder:"background"},Qd={x:.4,y:.6},ec={x:.6,y:.4},tc="relativeDifference",nc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Button:i}=h.useControls();if(!o)return null;const d=()=>{r.commands.dispatch(new p.AddAnnotationCommand({kind:"text",annotation:{...p.TEXT_ANNOTATION_DEFAULTS,content:rc(a("editor.annotatePanel.callOutSection.text")),at:{anchorType:"panel",...Yd},width:qd}}))},u=()=>{r.commands.dispatch(new p.AddAnnotationCommand({kind:"arrow",annotation:{...p.ARROW_DEFAULTS,start:{anchorType:"panel",...Qd},end:{anchorType:"panel",...ec}}}))},c=()=>{r.commands.dispatch(new p.AddAnnotationCommand({kind:"shape",annotation:{...p.SHAPE_DEFAULTS,...Jd,region:{anchorType:"panel",...Zd}}}))},g=()=>{const v=(0,p.inferDefaultDifferenceArrowEndpoints)(o);v!==null&&r.commands.dispatch(new p.AddAnnotationCommand({kind:"differenceArrow",annotation:{...p.DIFFERENCE_ARROW_DEFAULTS,...v,label:tc}}))},m=o.coordSystem.type==="cartesian";return(0,s.jsx)(U,{title:e??a("editor.annotatePanel.callOutSection.title"),layout:t,preview:n,children:(0,s.jsxs)(mr,{children:[(0,s.jsx)(i,{variant:"tile",icon:(0,s.jsx)($d,{size:"xl"}),label:a("editor.annotatePanel.callOutSection.text"),onClick:d}),(0,s.jsx)(i,{variant:"tile",icon:(0,s.jsx)(Ud,{size:"xl"}),label:a("editor.annotatePanel.callOutSection.arrow"),onClick:u}),(0,s.jsx)(i,{variant:"tile",icon:(0,s.jsx)(Xd,{size:"xl"}),label:a("editor.annotatePanel.callOutSection.box"),onClick:c}),m&&(0,s.jsx)(i,{variant:"tile",icon:(0,s.jsx)(Kd,{size:"xl"}),label:a("editor.annotatePanel.callOutSection.difference"),onClick:g})]})})},rc=e=>({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:e}]}]}),oc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{ToggleGroup:i}=h.useControls();if(!o)return null;const d=(0,p.readGraphType)(o.spec);if(d===null||!(0,p.isComboGraphType)(d))return null;const u=p.COMBO_TYPES.map(g=>({value:g,label:a(`editor.graphPanel.comboSection.types.${g}`)})),c=g=>{const m=p.COMBO_TYPES.find(v=>v===g);m&&r.commands.dispatch(new p.SetGraphTypeCommand({coordType:"cartesian",comboType:m}))};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.comboSection.title"),layout:t,preview:n??a(`editor.graphPanel.comboSection.types.${d.comboType}`),children:(0,s.jsx)(i,{value:d.comboType,options:u,onChange:c,ariaLabel:a("editor.graphPanel.comboSection.title")})})},ac=.1,sc=20,ic=({title:e,preview:t})=>{const n=h.usePanelGraph(),r=l.useHandleScene(n),o=l.useI18n(),{NumberField:a,TextField:i}=h.useControls();if(!r||r.coordSystem.type==="polar")return null;const d=(0,p.findGoalLineLayer)(r.spec.layers),u=e??o("editor.annotationsPanel.goalSection.title"),c=(0,p.readConstantValue)(d?.mapping.y),g=typeof c=="number"?c:null,m=f=>{const y=new p.ToggleGoalLineCommand({showGoalLine:f,value:lc(r),...d!==void 0&&{layerId:d.id}});n.commands.dispatch(y)},v=f=>{if(d===void 0)return;const y=new p.SetRuleLabelCommand({layerId:d.id,label:f===""?null:f});n.commands.dispatch(y,{transient:!0})},x=f=>{if(d===void 0||f===null)return;const y=new p.SetRuleValueCommand({layerId:d.id,value:f});n.commands.dispatch(y,{transient:!0})};return(0,s.jsx)(Sr,{title:u,preview:t,checked:d!==void 0,onToggle:m,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:o("editor.annotationsPanel.goalSection.labelControl"),children:(0,s.jsx)(i,{value:d?.params.label??"",placeholder:o("editor.annotationsPanel.goalSection.labelPlaceholder"),onChange:v,onCommit:n.commands.commit,ariaLabel:o("editor.annotationsPanel.goalSection.labelAriaLabel")})}),(0,s.jsx)(h.Row,{label:o("editor.annotationsPanel.goalSection.valueControl"),children:(0,s.jsx)(a,{value:g,placeholder:o("editor.powerUpPanel.valueInput.numberPlaceholder"),onChange:x,onCommit:n.commands.commit,ariaLabel:o("editor.annotationsPanel.goalSection.valueAriaLabel")})})]})})},lc=e=>{const t=(e.scales.y?.domain??[]).filter(i=>typeof i=="number");if(t.length===0)return 0;const n=Math.max(...t),r=n-Math.min(...t),o=r>0?r:Math.abs(n);if(o===0)return 0;const a=Math.min(sc,Math.max(0,1-Math.floor(Math.log10(o))));return Number((n+o*ac).toFixed(a))},fn=["auto","inside","outside"],dc=({layerId:e,title:t,layout:n="collapsible",preview:r})=>{const o=h.usePanelGraph(),a=l.useHandleScene(o),i=l.useI18n(),{Switch:d,ToggleGroup:u}=h.useControls();if(!a)return null;const c=e===void 0?a.layers[0]:(0,p.findLayerById)(a.layers,e);if(!c)return null;const{showDataLabels:g,format:m,showStackTotals:v,showCategoryLabels:x,position:f}=c.dataLabels,y=h.readDataLabelsSupport(c,a.coordSystem.type,{hasCapability:o.canPlaceDataLabels,hasPercentageFormat:o.canFormatDataLabelsAsPercentages});if(!y.supportsDataLabels)return null;const C=A=>{const M=new p.ToggleDataLabelsCommand({layerId:c.id,showDataLabels:A});o.commands.dispatch(M)},S=A=>{const M=fn.find(N=>N===A);M!==void 0&&o.commands.dispatch(new p.SetDataLabelsCommand({layerId:c.id,position:M}))},b=A=>{const M=new p.SetDataLabelsFormatCommand({layerId:c.id,format:A?"percentage":"absolute"});o.commands.dispatch(M)},T=A=>{const M=new p.ToggleStackTotalsCommand({layerId:c.id,showStackTotals:A});o.commands.dispatch(M)},E=A=>{const M=new p.ToggleCategoryLabelsCommand({layerId:c.id,showCategoryLabels:A});o.commands.dispatch(M)};return(0,s.jsx)(U,{title:t??i("editor.graphPanel.graphOptionsSection.title"),layout:n,preview:r,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:i("editor.graphPanel.graphOptions.dataLabels"),children:(0,s.jsx)(d,{checked:g,onChange:C})}),y.supportsPosition&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.graphOptions.labelPosition"),children:(0,s.jsx)(u,{value:f,options:fn.map(A=>({value:A,label:i(`editor.graphPanel.graphOptions.labelPositions.${A}`)})),onChange:S})}),y.supportsPercentages&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.graphOptions.showPercentages"),children:(0,s.jsx)(d,{checked:m==="percentage",onChange:b})}),y.supportsStackTotals&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.graphOptions.stackTotals"),children:(0,s.jsx)(d,{checked:v,onChange:T})}),y.supportsCategoryLabels&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.graphOptions.categoryLabels"),children:(0,s.jsx)(d,{checked:x,onChange:E})})]})})},cc=3,uc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{RadioGrid:i}=h.useControls(),d=(0,w.useMemo)(()=>h.GRAPH_TYPE_OPTIONS.map(({name:m,icon:v,summary:x})=>({value:m,label:a(`editor.graphTypes.${m}`),icon:(0,s.jsx)(v,{size:"md"}),disabled:!h.canBecomeGraphType(x,o?.spec)})),[a,o]);if(!o)return null;const u=(0,p.readGraphType)(o.spec),c=h.findGraphTypeOption(u),g=m=>{const v=h.GRAPH_TYPE_OPTIONS.find(x=>x.name===m);v&&r.commands.dispatch(new p.SetGraphTypeCommand(h.resolveGraphTypeSummary(v.summary,u)))};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.graphTypeSection.title"),layout:t,preview:n??(c===null?void 0:a(`editor.graphTypes.${c.name}`)),children:(0,s.jsx)(i,{value:c?.name??"",options:d,columns:cc,onChange:g,ariaLabel:a("editor.graphPanel.graphTypeSection.title")})})},hc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Slider:i,Switch:d,ToggleGroup:u}=h.useControls(),c=me(o),g=o!==null&&c!==null?h.readGridEditModel(o,c):null;if(g===null)return null;const m=g.axes.filter(S=>S.supportsGrid);if(m.length===0)return null;const v=g.axes.some(S=>S.showGrid),x=h.GRID_LINE_STYLES.map(S=>({value:S,label:a(`editor.graphPanel.gridSection.lineStyles.${S}`)})),f=S=>b=>{r.commands.dispatch(new p.SetGridVisibilityCommand({axis:S,visible:b}))},y=S=>{const b=h.GRID_LINE_STYLES.find(T=>T===S);b!==void 0&&r.commands.dispatch(h.buildGridLineStyleCommand(b))},C=S=>{r.commands.dispatch(h.buildGridLineWidthCommand(S),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.gridSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[m.map(S=>(0,s.jsx)(h.Row,{label:a(gc(S)),children:(0,s.jsx)(d,{checked:S.showGrid,onChange:f(S.scaledAesthetic)})},S.scaledAesthetic)),g.stylable&&v&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.gridSection.gridStyle"),children:(0,s.jsx)(u,{value:g.lineStyle,options:x,onChange:y})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.gridSection.gridThickness"),children:(0,s.jsx)(i,{value:g.strokeWidth,min:0,max:8,step:.5,formatValue:Le,onChange:C,onCommit:r.commands.commit})})]})]})})},gc=e=>e.geometry==="radial"?"editor.graphPanel.gridSection.rings":e.geometry==="circular"?"editor.graphPanel.gridSection.spokes":e.scaledAesthetic==="x"?"editor.graphPanel.gridSection.verticalGridLines":"editor.graphPanel.gridSection.horizontalGridLines",pc="total",kr=["total","average","current"],mc=["total"],yn=["previous","first"],Sn=["auto","small","medium","large"],vc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Switch:i,ToggleGroup:d}=h.useControls();if(!o)return null;const u=o.config.headline,c=u.show!=="none",g=o.coordSystem,m=g.type==="polar",v=g.type==="polar"&&g.innerRadius>0,x=o.layers.some(j=>j.summary.grandTotal!==void 0);if(m&&!x)return null;const f=m?mc:kr,y=o.guides.headline,C=y?.kind==="perGroup"&&y.items.some(j=>j.comparison!==null),S=f.map(j=>({value:j,label:a(`editor.graphPanel.headlineNumberSection.metrics.${j}`)})),b=yn.map(j=>({value:j,label:a(`editor.graphPanel.headlineNumberSection.comparison.${j}`)})),T=Sn.map(j=>({value:j,label:a(j==="auto"?"editor.graphPanel.numberFormat.options.auto":`editor.graphPanel.headlineNumberSize.sizes.${j}`)})),E=[{value:"above",label:a("editor.graphPanel.headlineNumberSection.position.above")},{value:"center",label:a("editor.graphPanel.headlineNumberSection.position.center")}],A=j=>{r.commands.dispatch(new p.SetHeadlineShowCommand({show:j?pc:"none"}))},M=j=>{const P=f.find(k=>k===j);P&&r.commands.dispatch(new p.SetHeadlineShowCommand({show:P}))},N=j=>{const P=yn.find(k=>k===j);P&&r.commands.dispatch(new p.SetHeadlineCompareWithCommand({compareWith:P}))},G=j=>{const P=Sn.find(k=>k===j);P&&r.commands.dispatch(new p.SetHeadlineSizeCommand({size:P}))},R=j=>{r.commands.dispatch(new p.SetHeadlinePositionCommand({position:j==="center"?"center":"above"}))};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.headlineNumberSection.title"),layout:t,preview:n??xc(a,u.show),children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.headlineNumberSection.toggle"),children:(0,s.jsx)(i,{checked:c,onChange:A})}),c&&(0,s.jsxs)(s.Fragment,{children:[S.length>1&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.headlineNumberSection.metricLabel"),layout:"stack",children:(0,s.jsx)(d,{value:u.show,options:S,onChange:M})}),C&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.headlineNumberSection.compareWithLabel"),layout:"stack",children:(0,s.jsx)(d,{value:(0,p.resolveComparisonBasis)(u.compareWith),options:b,onChange:N})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.headlineNumberSize.sizeLabel"),children:(0,s.jsx)(d,{value:u.size,options:T,onChange:G})}),v&&(0,s.jsx)(h.Row,{label:a("editor.axesPanel.controls.position"),children:(0,s.jsx)(d,{value:u.position,options:E,onChange:R})})]})]})})},xc=(e,t)=>{const n=kr.find(r=>r===t);return n&&e(`editor.graphPanel.headlineNumberSection.metrics.${n}`)};var Xe=["top","bottom","left","right","none"],wn=["auto","start","center","end"],fc={row:{start:"left",end:"right"},column:{start:"top",end:"bottom"}},bn=["auto","pill","direct"],yc=({positions:e,title:t,layout:n="collapsible",preview:r})=>{const o=h.usePanelGraph(),a=l.useHandleScene(o),i=l.useI18n(),{ToggleGroup:d}=h.useControls(),u=l.useTextDirection();if(!a)return null;const c=a.config.legend.position,g=e??Xe,m=a.guides.legends.drawn[0],v=(0,p.canAnchorDirectLabels)({legendPosition:a.guides.legends.position,coordSystem:a.coordSystem,layers:a.layers}),x=a.guides.headline?.kind==="perGroup",f=a.guides.colorGroups.length>0;if(c==="auto"&&m===void 0&&!v&&(x||!f))return null;const y=m?.position??"none",C=c==="auto"?y:c,S=Xe.filter(O=>O===C||g.includes(O)).map(O=>({value:O,label:i(`editor.graphPanel.legendSection.${O}`)})),b=O=>{const I=Xe.find(F=>F===O);I&&o.commands.dispatch(new p.SetLegendPositionCommand({position:I}))},T=O=>{const I=wn.find(F=>F===O);I&&o.commands.dispatch(new p.SetLegendAlignCommand({align:I}))},E=O=>{const I=bn.find(F=>F===O);I&&o.commands.dispatch(new p.SetLegendDisplayCommand({display:I}))},A=m?.position==="left"||m?.position==="right"?"column":"row",M=A==="row"?"ltr":u,N=O=>i(O==="start"||O==="end"?`editor.graphPanel.legendSection.${fc[A][O]}`:`editor.graphPanel.legendSection.align.${O}`),G=wn.map(O=>({value:O,label:N(O)})),R=bn.map(O=>({value:O,label:i(`editor.graphPanel.legendSection.display.${O}`)})),j=t??i("editor.graphPanel.legendSection.title"),P=S.find(O=>O.value===C)?.label,k=m!==void 0&&!m.inHeadlineRow;return(0,s.jsx)(U,{title:j,layout:n,preview:r??P,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:i("editor.axesPanel.controls.position"),layout:"stack",children:(0,s.jsx)(d,{value:C,options:S,onChange:b})}),k&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.legendSection.alignLabel"),layout:"stack",children:(0,s.jsx)(An.DirectionProvider,{direction:M,children:(0,s.jsx)("div",{dir:M,className:"_1v6dqrh0",children:(0,s.jsx)(d,{value:a.config.legend.align,options:G,onChange:T})})})}),v&&(0,s.jsx)(h.Row,{label:i("editor.graphPanel.legendSection.displayLabel"),layout:"stack",children:(0,s.jsx)(d,{value:a.config.legend.display,options:R,onChange:E})})]})})},Sc=1,wc=20,bc=.5,Rr=({layerId:e})=>{const t=h.usePanelGraph(),n=l.useHandleScene(t),{Slider:r}=h.useControls(),o=wt(n,e,"point");if(!n)return null;const a=(0,p.findLayerById)(n.layers,e)?.data?.findFirst(u=>(o?.get("size",u)??0)>0)??void 0,i=o?.get("size",a)??p.DEFAULT_POINT_SIZE_PX,d=u=>{const c=new p.SetPointSizeCommand({layerId:e,size:u});t.commands.dispatch(c,{transient:!0})};return(0,s.jsx)(r,{value:i,min:Sc,max:wc,step:bc,formatValue:Le,onChange:d,onCommit:t.commands.commit})},Lr=({layerId:e})=>{const t=h.usePanelGraph(),n=l.useHandleScene(t),r=wt(n,e,"point");return n?(0,s.jsx)(h.PointSymbolRow,{symbol:r?.get("symbol")??"circle",coordType:n.coordSystem.type,onChange:o=>{t.commands.dispatch(new p.SetPointSymbolCommand({layerId:e,symbol:o}))}}):null},Cc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Select:i,Slider:d,Switch:u,ToggleGroup:c}=h.useControls(),g=me(o),m=(0,p.findLayerByGeom)(o?.spec.layers??[],"line","area"),v=o&&g&&m?h.readLineEditModel(o,g,m.id):null;if(!o||!v)return null;const x=v.missingValueOptions.map(A=>({value:A,label:h.missingValueLabel(a,A)})),f=[{value:"auto",label:a("editor.graphPanel.numberFormat.options.auto"),disabled:v.hasUnderlyingStrokeWidth},{value:"custom",label:a("editor.graphPanel.numberFormat.options.custom")}],y=A=>{r.commands.dispatch(new p.ToggleLinePointsCommand({layerId:v.layerId,showPoints:A}))},C=A=>{r.commands.dispatch(new p.SetLineStyleCommand({layerId:v.layerId,showFill:A,drawnFillAlpha:v.drawnFillAlpha}))},S=A=>{r.commands.dispatch(new p.SetLineCurveCommand({layerId:v.layerId,curve:A?"smooth":"linear"}))},b=A=>{r.commands.dispatch(new p.SetLineStyleCommand({layerId:v.layerId,strokeWidth:A==="custom"?v.strokeWidth:null}))},T=A=>{r.commands.dispatch(new p.SetLineStyleCommand({layerId:v.layerId,strokeWidth:A}),{transient:!0})},E=A=>{const M=h.MISSING_VALUES.find(N=>N===A);M&&r.commands.dispatch(new p.SetLineMissingValuesCommand({layerId:v.layerId,missingValues:M}))};return(0,s.jsx)(U,{title:e??a("editor.fineTunePanel.lineStyleSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.graphOptions.showPoints"),children:(0,s.jsx)(u,{checked:v.showPoints,onChange:y})}),v.pointLayerId&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.pointSize.label"),children:(0,s.jsx)(Rr,{layerId:v.pointLayerId})}),v.showPoints&&v.pointLayerId!==null&&(0,s.jsx)(Lr,{layerId:v.pointLayerId}),v.showFill!==null&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.graphOptions.lineFill"),children:(0,s.jsx)(u,{checked:v.showFill,onChange:C})}),v.smooth!==null&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.graphOptions.smoothLines"),children:(0,s.jsx)(u,{checked:v.smooth,onChange:S})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.lineThickness.label"),children:(0,s.jsx)(c,{value:v.widthMode,options:f,onChange:b})}),v.widthMode==="custom"&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.numberFormat.valueLabel"),children:(0,s.jsx)(d,{value:v.strokeWidth,min:1,max:10,step:.1,formatValue:Le,onChange:T,onCommit:r.commands.commit})}),v.missingValues!==null&&(0,s.jsx)(h.Row,{label:a("editor.fineTunePanel.detailSection.missingValues"),children:(0,s.jsx)(i,{value:v.missingValues,options:x,onChange:E})})]})})},ot="\0none",Tc=["x","y","color","size","label"],Ac={x:"editor.graphPanel.mappingSection.x",y:"editor.graphPanel.mappingSection.y",color:"editor.graphPanel.mappingSection.color",size:"editor.graphPanel.mappingSection.size",label:"editor.graphPanel.mappingSection.label"},Pc=({title:e,layout:t="collapsible"})=>{const n=h.usePanelGraph(),r=l.useHandleScene(n),o=l.useI18n(),{Select:a}=h.useControls(),i=o("editor.graphPanel.mappingSection.none"),d=r?.spec,u=(0,w.useMemo)(()=>d===void 0?[]:(0,p.readMappableAesthetics)(d,Tc).map(({aesthetic:c,variables:g,required:m})=>{const v=(0,p.readMappedVariable)(d.mapping,c);return{aesthetic:c,label:o(Ac[c]),value:v??(m?null:ot),options:Ic(g,v,m?null:i),chooseColumn:x=>{n.commands.dispatch(new p.SetMappingCommand({aesthetic:c,variable:x===ot?null:x}))}}}),[d,o,i,n]);return r?(0,s.jsx)(U,{title:e??o("editor.graphPanel.mappingSection.title"),layout:t,children:(0,s.jsx)($,{children:u.map(({aesthetic:c,label:g,value:m,options:v,chooseColumn:x})=>(0,s.jsx)(h.Row,{label:g,children:(0,s.jsx)(a,{value:m,options:v,placeholder:i,onChange:x})},c))})}):null},Ic=(e,t,n)=>{const r=t!==null&&!e.includes(t)?[t,...e]:e;return[...n===null?[]:[{value:ot,label:n}],...r.map(o=>({value:o,label:o}))]},Ec="k",jc=2,kc=0,Rc=5,at=[{value:"k",labelKey:"thousands"},{value:"m",labelKey:"millions"},{value:"b",labelKey:"billions"}],Lc=["auto","none"],Oc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{NumberField:i,ToggleGroup:d}=h.useControls();if(!o)return null;const{abbreviation:u,decimals:c}=o.config.numberFormat,g=Mc(u)!==void 0,m=c!=="auto",v=T=>T.map(E=>({value:E,label:a(`editor.graphPanel.numberFormat.options.${E}`)})),x=at.map(({value:T,labelKey:E})=>({value:T,label:a(`common.abbreviations.${E}`)})),f=T=>{r.commands.dispatch(new p.SetNumberFormatAbbreviationCommand({abbreviation:T}))},y=T=>{const E=Lc.find(A=>A===T);f(E??Ec)},C=T=>{const E=at.find(A=>A.value===T);E&&f(E.value)},S=T=>{r.commands.dispatch(new p.SetNumberFormatDecimalsCommand({decimals:T==="custom"?jc:"auto"}))},b=T=>{T!==null&&r.commands.dispatch(new p.SetNumberFormatDecimalsCommand({decimals:T}),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.numberFormatSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.numberFormat.abbreviationLabel"),children:(0,s.jsx)(d,{value:g?"custom":u,options:v(["auto","none","custom"]),onChange:y})}),g&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.numberFormat.valueLabel"),children:(0,s.jsx)(d,{value:u,options:x,onChange:C})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.numberFormat.decimalPlacesLabel"),children:(0,s.jsx)(d,{value:m?"custom":"auto",options:v(["auto","custom"]),onChange:S})}),m&&(0,s.jsx)(h.Row,{label:a("editor.graphPanel.numberFormat.valueLabel"),children:(0,s.jsx)(i,{value:c,min:kc,max:Rc,onChange:b,onCommit:r.commands.commit})})]})})},Mc=e=>at.find(t=>t.value===e),_c=({title:e,layout:t="collapsible",preview:n})=>{const r=l.useHandleScene(h.usePanelGraph()),o=l.useI18n();if(!r)return null;const a=Dc(r.spec.layers);return a?(0,s.jsx)(U,{title:e??o("editor.graphPanel.pointSize.label"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:o("editor.graphPanel.numberFormat.valueLabel"),children:(0,s.jsx)(Rr,{layerId:a.id})}),(0,s.jsx)(Lr,{layerId:a.id})]})}):null},Dc=e=>{const t=(0,p.filterLayersByGeoms)(e,"line","area");return(0,p.filterLayersByGeoms)(e,"point").find(n=>!(0,p.isCompanionLayer)(n,t))},Fc=.9,Nc=360,Gc=.05,Bc=15,Hc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Slider:i}=h.useControls();if(!o||o.spec.coords.coordType!=="polar")return null;const{innerRadius:d,startAngle:u}=o.spec.coords.params,c=m=>{r.commands.dispatch(new p.SetPolarInnerRadiusCommand({innerRadius:m}),{transient:!0})},g=m=>{r.commands.dispatch(new p.SetPolarStartAngleCommand({startAngle:m}),{transient:!0})};return(0,s.jsx)(U,{title:e??a("editor.graphPanel.polarSection.title"),layout:t,preview:n,children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.graphPanel.polarSection.innerRadius"),children:(0,s.jsx)(i,{value:d,min:0,max:Fc,step:Gc,formatValue:Er,onChange:c,onCommit:r.commands.commit})}),(0,s.jsx)(h.Row,{label:a("editor.graphPanel.polarSection.startAngle"),children:(0,s.jsx)(i,{value:u,min:0,max:Nc-1,step:Bc,formatValue:Fd,onChange:g,onCommit:r.commands.commit})})]})})},zc=e=>(0,s.jsxs)(l.Icon,{...e,children:[(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",opacity:"0.12",d:"M2 10C2 7.19974 2 5.79961 2.54497 4.73005C3.02433 3.78924 3.78924 3.02433 4.73005 2.54497C5.79961 2 7.19974 2 10 2H14C16.8003 2 18.2004 2 19.27 2.54497C20.2108 3.02433 20.9757 3.78924 21.455 4.73005C22 5.79961 22 7.19974 22 10V14C22 16.8003 22 18.2004 21.455 19.27C20.9757 20.2108 20.2108 20.9757 19.27 21.455C18.2004 22 16.8003 22 14 22H10C7.19974 22 5.79961 22 4.73005 21.455C3.78924 20.9757 3.02433 20.2108 2.54497 19.27C2 18.2004 2 16.8003 2 14V10Z",fill:"currentColor"}),(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.96644 1.25C8.59472 1.25 7.51929 1.24999 6.65494 1.32061C5.77479 1.39252 5.04768 1.54138 4.38955 1.87671C3.30762 2.42798 2.42798 3.30762 1.87671 4.38955C1.54138 5.04768 1.39252 5.77479 1.32061 6.65494C1.24999 7.51929 1.25 8.59472 1.25 9.96644V14.0336C1.25 15.4053 1.24999 16.4807 1.32061 17.3451C1.39252 18.2252 1.54138 18.9523 1.87671 19.6104C2.42798 20.6924 3.30762 21.572 4.38955 22.1233C5.04768 22.4586 5.77479 22.6075 6.65494 22.6794C7.51927 22.75 8.59469 22.75 9.96637 22.75H14.0336C15.4053 22.75 16.4807 22.75 17.3451 22.6794C18.2252 22.6075 18.9523 22.4586 19.6104 22.1233C20.6924 21.572 21.572 20.6924 22.1233 19.6104C22.4586 18.9523 22.6075 18.2252 22.6794 17.3451C22.75 16.4807 22.75 15.4053 22.75 14.0336V9.96642C22.75 8.59473 22.75 7.51927 22.6794 6.65494C22.6075 5.77479 22.4586 5.04768 22.1233 4.38955C21.572 3.30762 20.6924 2.42798 19.6104 1.87671C18.9523 1.54138 18.2252 1.39252 17.3451 1.32061C16.4807 1.24999 15.4053 1.25 14.0336 1.25H9.96644ZM5.07054 3.21322C5.48197 3.00359 5.9897 2.87996 6.77708 2.81563C7.57322 2.75058 8.58749 2.75 10 2.75H14C15.4125 2.75 16.4268 2.75058 17.2229 2.81563C18.0103 2.87996 18.518 3.00359 18.9295 3.21322C19.7291 3.62068 20.3793 4.27085 20.7868 5.07054C20.9964 5.48197 21.12 5.9897 21.1844 6.77708C21.2494 7.57322 21.25 8.58749 21.25 10V14C21.25 15.4125 21.2494 16.4268 21.1844 17.2229C21.12 18.0103 20.9964 18.518 20.7868 18.9295C20.3793 19.7291 19.7291 20.3793 18.9295 20.7868C18.518 20.9964 18.0103 21.12 17.2229 21.1844C16.4268 21.2494 15.4125 21.25 14 21.25H10C8.58749 21.25 7.57322 21.2494 6.77708 21.1844C5.9897 21.12 5.48197 20.9964 5.07054 20.7868C4.27085 20.3793 3.62068 19.7291 3.21322 18.9295C3.00359 18.518 2.87996 18.0103 2.81563 17.2229C2.75058 16.4268 2.75 15.4125 2.75 14V10C2.75 8.58749 2.75058 7.57322 2.81563 6.77708C2.87996 5.9897 3.00359 5.48197 3.21322 5.07054C3.62068 4.27085 4.27085 3.62068 5.07054 3.21322Z",fill:"currentColor"}),(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M19.4796 12.2222L17.6085 12.2291L17.6029 10.7291L19.474 10.7222L19.4796 12.2222ZM15.3662 12.2375L13.124 12.2459L13.1184 10.7459L15.3606 10.7375L15.3662 12.2375ZM10.8817 12.2542L8.63945 12.2626L8.63386 10.7626L10.8761 10.7542L10.8817 12.2542ZM6.39719 12.2709L4.52607 12.2779L4.52048 10.7779L6.3916 10.7709L6.39719 12.2709Z",fill:"currentColor"})]}),Cn=e=>(0,s.jsxs)(l.Icon,{...e,children:[(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",opacity:"0.12",d:"M2 10C2 7.19974 2 5.79961 2.54497 4.73005C3.02433 3.78924 3.78924 3.02433 4.73005 2.54497C5.79961 2 7.19974 2 10 2H14C16.8003 2 18.2004 2 19.27 2.54497C20.2108 3.02433 20.9757 3.78924 21.455 4.73005C22 5.79961 22 7.19974 22 10V14C22 16.8003 22 18.2004 21.455 19.27C20.9757 20.2108 20.2108 20.9757 19.27 21.455C18.2004 22 16.8003 22 14 22H10C7.19974 22 5.79961 22 4.73005 21.455C3.78924 20.9757 3.02433 20.2108 2.54497 19.27C2 18.2004 2 16.8003 2 14V10Z",fill:"currentColor"}),(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.96644 1.25C8.59472 1.25 7.51929 1.24999 6.65494 1.32061C5.77479 1.39252 5.04768 1.54138 4.38955 1.87671C3.30762 2.42798 2.42798 3.30762 1.87671 4.38955C1.54138 5.04768 1.39252 5.77479 1.32061 6.65494C1.24999 7.51929 1.25 8.59472 1.25 9.96644V14.0336C1.25 15.4053 1.24999 16.4807 1.32061 17.3451C1.39252 18.2252 1.54138 18.9523 1.87671 19.6104C2.42798 20.6924 3.30762 21.572 4.38955 22.1233C5.04768 22.4586 5.77479 22.6075 6.65494 22.6794C7.51927 22.75 8.59469 22.75 9.96637 22.75H14.0336C15.4053 22.75 16.4807 22.75 17.3451 22.6794C18.2252 22.6075 18.9523 22.4586 19.6104 22.1233C20.6924 21.572 21.572 20.6924 22.1233 19.6104C22.4586 18.9523 22.6075 18.2252 22.6794 17.3451C22.75 16.4807 22.75 15.4053 22.75 14.0336V9.96642C22.75 8.59473 22.75 7.51927 22.6794 6.65494C22.6075 5.77479 22.4586 5.04768 22.1233 4.38955C21.572 3.30762 20.6924 2.42798 19.6104 1.87671C18.9523 1.54138 18.2252 1.39252 17.3451 1.32061C16.4807 1.24999 15.4053 1.25 14.0336 1.25H9.96644ZM5.07054 3.21322C5.48197 3.00359 5.9897 2.87996 6.77708 2.81563C7.57322 2.75058 8.58749 2.75 10 2.75H14C15.4125 2.75 16.4268 2.75058 17.2229 2.81563C18.0103 2.87996 18.518 3.00359 18.9295 3.21322C19.7291 3.62068 20.3793 4.27085 20.7868 5.07054C20.9964 5.48197 21.12 5.9897 21.1844 6.77708C21.2494 7.57322 21.25 8.58749 21.25 10V14C21.25 15.4125 21.2494 16.4268 21.1844 17.2229C21.12 18.0103 20.9964 18.518 20.7868 18.9295C20.3793 19.7291 19.7291 20.3793 18.9295 20.7868C18.518 20.9964 18.0103 21.12 17.2229 21.1844C16.4268 21.2494 15.4125 21.25 14 21.25H10C8.58749 21.25 7.57322 21.2494 6.77708 21.1844C5.9897 21.12 5.48197 20.9964 5.07054 20.7868C4.27085 20.3793 3.62068 19.7291 3.21322 18.9295C3.00359 18.518 2.87996 18.0103 2.81563 17.2229C2.75058 16.4268 2.75 15.4125 2.75 14V10C2.75 8.58749 2.75058 7.57322 2.81563 6.77708C2.87996 5.9897 3.00359 5.48197 3.21322 5.07054C3.62068 4.27085 4.27085 3.62068 5.07054 3.21322Z",fill:"currentColor"}),(0,s.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18.6749 8.04877L17.1069 9.06975L16.2884 7.81273L17.8564 6.79175L18.6749 8.04877ZM15.2278 10.2932L13.3488 11.5167L12.5303 10.2597L14.4093 9.03622L15.2278 10.2932ZM11.4697 12.7402L9.59064 13.9637L8.77217 12.7067L10.6512 11.4832L11.4697 12.7402ZM7.71158 15.1872L6.14354 16.2082L5.32507 14.9511L6.89311 13.9302L7.71158 15.1872Z",fill:"currentColor"})]}),Tn=["linear","exponential","quadratic","polynomial","logarithmic","power","loess"],Wc="linear",Vc=({title:e,layout:t="collapsible",preview:n})=>{const r=h.usePanelGraph(),o=l.useHandleScene(r),a=l.useI18n(),{Select:i,Switch:d}=h.useControls(),{options:u,findValue:c}=h.useGroupOptions(o,r.formattingLocale);if(!o||o.coordSystem.type==="polar")return null;const g=(0,p.findTrendLineLayer)(o.spec.layers),m=(0,p.findAverageLineLayer)(o.spec.layers),v=g?.stat.type==="smooth"?g.stat.method:Wc,x=Uc(m),f=Tn.map(E=>({value:E,label:a(`editor.annotationsPanel.trendType.options.${E}`)})),y=(E,A={})=>{const M=g??m,N=new p.SetStatLineCommand({line:E,...A,...M!==void 0&&{layerId:M.id},label:a("editor.annotationsPanel.trendsAndAveragesSection.average")});r.commands.dispatch(N)},C=E=>y(E?"trend":"none",{method:v}),S=E=>y(E?"average":"none",{group:x??c(u[0]?.value??"")}),b=E=>{const A=Tn.find(M=>M===E);A!==void 0&&y("trend",{method:A})},T=E=>{const A=E===null?void 0:c(E);A!==void 0&&y("average",{group:A})};return(0,s.jsx)(U,{title:e??a("editor.annotationsPanel.trendsAndAveragesSection.title"),layout:t,preview:n??(0,s.jsx)(Cn,{size:"lg"}),children:(0,s.jsxs)($,{children:[(0,s.jsx)(h.Row,{label:a("editor.annotationsPanel.trendsAndAveragesSection.trend"),icon:(0,s.jsx)(Cn,{size:"lg"}),children:(0,s.jsx)(d,{checked:g!==void 0,onChange:C})}),g!==void 0&&(0,s.jsx)(h.Row,{label:a("editor.annotationsPanel.trendType.label"),children:(0,s.jsx)(i,{value:v,options:f,onChange:b,placeholder:a("editor.annotationsPanel.trendType.placeholder")})}),(0,s.jsx)(h.Row,{label:a("editor.annotationsPanel.trendsAndAveragesSection.average"),icon:(0,s.jsx)(zc,{size:"lg"}),children:(0,s.jsx)(d,{checked:m!==void 0,onChange:S})}),m!==void 0&&u.length>0&&(0,s.jsx)(h.Row,{label:a("editor.annotationsPanel.averageLineSeries.label"),children:(0,s.jsx)(i,{value:x===void 0?null:String(x),options:u,onChange:T,placeholder:a("editor.annotationsPanel.averageLineSeries.placeholder"),ariaLabel:a("editor.annotationsPanel.averageLineSeries.ariaLabel")})})]})})},Uc=e=>{const t=e?.transforms.find(n=>n.transformType==="filter")?.options.value;return t instanceof Date?t.getTime():t};exports.AppearanceSection=Bd;exports.AxesPanel=Dd;exports.AxisEditMenu=h.AxisEditMenu;exports.AxisSection=Pe;exports.BarEditMenu=h.BarEditMenu;exports.BarSection=Vd;exports.Button=h.Button;exports.CalloutsSection=nc;exports.CaptionSection=Cr;exports.ChartEditMenu=h.ChartEditMenu;exports.ColorRow=h.ColorRow;exports.ColorSwatches=h.ColorSwatches;exports.ComboSection=oc;exports.ControlRegistryProvider=h.ControlRegistryProvider;exports.ControlTooltip=h.ControlTooltip;exports.CustomColor=h.CustomColor;exports.DateField=h.DateField;exports.EditableGraphRenderer=sd;exports.EditorIntlProvider=st;exports.EditorPanel=xt;exports.ElementsPanel=_d;exports.FileInput=h.FileInput;exports.FloatingToolbar=h.PublicFloatingToolbar;exports.GoalSection=ic;exports.GraphOptionsSection=dc;exports.GraphTypeSection=uc;exports.GridEditMenu=h.GridEditMenu;exports.GridSection=hc;exports.HeadlineSection=vc;exports.LegendEditMenu=h.LegendEditMenu;exports.LegendSection=yc;exports.LineEditMenu=h.LineEditMenu;exports.LineSection=Cc;exports.MappingSection=Pc;exports.NumberField=h.NumberField;exports.NumberFormatSection=Oc;exports.PANEL_ROOT_ATTRIBUTE=fr;exports.PaletteRow=h.PaletteRow;exports.PointEditMenu=h.PointEditMenu;exports.PointSection=_c;exports.PolarSection=Hc;exports.RadioGrid=h.RadioGrid;exports.Row=h.Row;exports.Section=U;exports.Select=h.Select;exports.Separator=fd;exports.Slider=h.Slider;exports.SourceSection=Tr;exports.Stepper=h.Stepper;exports.SubtitleSection=Ar;exports.Switch=h.Switch;exports.TextField=h.TextField;exports.TextSizeSection=Pr;exports.TitleSection=Ir;exports.ToggleGroup=h.ToggleGroup;exports.ToggledSection=Sr;exports.TrendsAndAveragesSection=Vc;exports.useAnnotateAnchor=h.useAnnotateAnchor;exports.useControls=h.useControls;exports.usePanelExpansion=xr;exports.usePanelGraph=h.usePanelGraph;