@synertech/ui 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/use-synertech-ui/SKILL.md +49 -1
- package/README.md +23 -0
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/bar-chart/BarChart.cjs +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/box-plot/BoxPlot.cjs +1 -1
- package/dist/components/box-plot/BoxPlot.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/bullet-chart/BulletChart.cjs +1 -1
- package/dist/components/bullet-chart/BulletChart.js +1 -1
- package/dist/components/calendar/Calendar.cjs +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
- package/dist/components/chart/ChartPeriodPicker.cjs +1 -1
- package/dist/components/chart/ChartPeriodPicker.js +1 -1
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
- package/dist/components/footer/FooterLink.cjs +1 -1
- package/dist/components/footer/FooterLink.js +1 -1
- package/dist/components/footer/FooterSocial.cjs +1 -1
- package/dist/components/footer/FooterSocial.js +1 -1
- package/dist/components/form/number-input/NumberInput.cjs +1 -1
- package/dist/components/form/number-input/NumberInput.js +1 -1
- package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
- package/dist/components/funnel-chart/FunnelChart.js +1 -1
- package/dist/components/gantt-chart/GanttChart.cjs +1 -1
- package/dist/components/gantt-chart/GanttChart.js +1 -1
- package/dist/components/header/Header.cjs +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/heat-map/Heatmap.cjs +1 -1
- package/dist/components/heat-map/Heatmap.js +1 -1
- package/dist/components/help-button/HelpButton.cjs +5 -5
- package/dist/components/help-button/HelpButton.js +6 -6
- package/dist/components/help-button/sanitize-html.cjs +1 -0
- package/dist/components/help-button/sanitize-html.js +1 -0
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/pie-chart/PieChart.cjs +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/sidebar/Sidebar.cjs +1 -1
- package/dist/components/sidebar/Sidebar.js +1 -1
- package/dist/components/stat-card/StatCard.cjs +1 -1
- package/dist/components/stat-card/StatCard.js +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +187 -25
- package/dist/index.d.ts +187 -25
- package/dist/index.js +1 -1
- package/dist/lib/i18n.cjs +1 -1
- package/dist/lib/i18n.js +1 -1
- package/dist/lib/safe-href.cjs +1 -0
- package/dist/lib/safe-href.js +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
2
|
-
${Y[
|
|
1
|
+
"use client";import{useState as b,useRef as C,useEffect as W,useCallback as B}from"react";import K from"react-markdown";import G from"remark-gfm";import{useUILabels as q}from"../../lib/i18n.js";import{sanitizeHelpHtml as V}from"./sanitize-html.js";import{Fragment as ne,jsx as e,jsxs as n}from"react/jsx-runtime";var j=n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),F=n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),e("polyline",{points:"17 21 17 13 7 13 7 21"}),e("polyline",{points:"7 3 7 8 15 8"})]}),J=n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Q=n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e("polyline",{points:"1 4 1 10 7 10"}),e("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]}),X=n("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10"}),e("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z",fill:"currentColor"})]}),Y={xs:"w-4 h-4 text-[10px]",sm:"w-5 h-5 text-xs",md:"w-6 h-6 text-sm",lg:"w-7 h-7 text-base"},Z={top:"bottom-full left-1/2 -translate-x-1/2 mb-2",bottom:"top-full left-1/2 -translate-x-1/2 mt-2",left:"right-full top-1/2 -translate-y-1/2 mr-2",right:"left-full top-1/2 -translate-y-1/2 ml-2"},ee={sm:"w-56",md:"w-72",lg:"w-96",xl:"w-[32rem]"},te=[G],re=["img"],oe={h1:({node:o,...t})=>e("h1",{className:"text-xl font-bold mb-2 text-gray-900 dark:text-gray-100",...t}),h2:({node:o,...t})=>e("h2",{className:"text-lg font-semibold mt-4 mb-2 text-gray-900 dark:text-gray-100",...t}),h3:({node:o,...t})=>e("h3",{className:"text-base font-semibold mt-3 mb-1 text-gray-900 dark:text-gray-100",...t}),p:({node:o,...t})=>e("p",{className:"my-1 text-gray-700 dark:text-gray-300",...t}),ul:({node:o,...t})=>e("ul",{className:"list-disc list-inside space-y-1 my-2 text-gray-700 dark:text-gray-300",...t}),ol:({node:o,...t})=>e("ol",{className:"list-decimal list-inside space-y-1 my-2 text-gray-700 dark:text-gray-300",...t}),code:({node:o,className:t,children:i,...d})=>!t?.includes("language-")?e("code",{className:"bg-gray-100 dark:bg-gray-800 px-1.5 py-0.5 rounded text-sm font-mono text-gray-900 dark:text-gray-100",...d,children:i}):e("code",{className:"block bg-gray-100 dark:bg-gray-800 rounded-lg p-3 my-2 overflow-x-auto text-sm font-mono text-gray-900 dark:text-gray-100",...d,children:i}),pre:({node:o,...t})=>e("pre",{className:"my-2",...t}),a:({node:o,...t})=>e("a",{className:"text-synertech-primary-600 dark:text-synertech-primary-400 hover:underline",...t}),strong:({node:o,...t})=>e("strong",{className:"font-semibold text-gray-900 dark:text-gray-100",...t}),em:({node:o,...t})=>e("em",{className:"italic",...t}),blockquote:({node:o,...t})=>e("blockquote",{className:"border-l-4 border-gray-300 dark:border-gray-600 pl-4 my-2 italic text-gray-600 dark:text-gray-400",...t})};function ae({content:o,markdown:t=!1,position:i="bottom",size:d="sm",className:f="",visible:_=!0,editable:h=!1,onSave:g,onReset:c,width:R="md",title:m,markdownEditor:v,markdownEditorUnavailableLabel:L,labels:M}){let r=q(M),[p,S]=b(!1),[l,y]=b(!1),[k,x]=b(""),[I,N]=b(!1),[T,a]=b(null),H=C(null),O=C(null),P=C(null),s=C(null);W(()=>{if(!p)return;let u=E=>{H.current&&!H.current.contains(E.target)&&O.current&&!O.current.contains(E.target)&&(l||S(!1))},z=E=>{E.key==="Escape"&&(l?(y(!1),x("")):S(!1))};return document.addEventListener("mousedown",u),document.addEventListener("keydown",z),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",z)}},[p,l]),W(()=>{l&&P.current&&P.current.focus()},[l]),W(()=>()=>{s.current&&clearTimeout(s.current)},[]);let A=B(()=>{x(typeof o=="string"?o:""),y(!0),a(null)},[o]),D=B(()=>{y(!1),x(""),a(null)},[]),U=B(async()=>{if(!g){a({type:"error",text:r.helpButtonNoSave});return}N(!0);try{await g(k)?(a({type:"success",text:r.helpButtonSaved}),y(!1),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>a(null),2e3)):a({type:"error",text:r.helpButtonSaveError})}catch{a({type:"error",text:r.helpButtonSaveError})}finally{N(!1)}},[k,g,r]),$=B(async()=>{if(c&&confirm(r.helpButtonResetConfirm)){N(!0);try{await c()?(a({type:"success",text:r.helpButtonResetDone}),y(!1),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>a(null),2e3)):a({type:"error",text:r.helpButtonResetError})}catch{a({type:"error",text:r.helpButtonResetError})}finally{N(!1)}}},[c,r]),w=o;return _?n("div",{className:"relative inline-flex items-center",children:[e("button",{type:"button",ref:H,onClick:()=>S(!p),className:`
|
|
2
|
+
${Y[d]}
|
|
3
3
|
inline-flex items-center justify-center
|
|
4
4
|
rounded-full border border-gray-300 dark:border-gray-600
|
|
5
5
|
bg-white dark:bg-gray-800
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
hover:border-gray-400 dark:hover:border-gray-500
|
|
11
11
|
transition-all duration-150
|
|
12
12
|
focus:outline-none focus:ring-2 focus:ring-synertech-primary-500/50
|
|
13
|
-
${
|
|
14
|
-
`,"aria-label":r.helpButtonShow,"aria-expanded":
|
|
13
|
+
${f}
|
|
14
|
+
`,"aria-label":r.helpButtonShow,"aria-expanded":p,children:e("span",{className:"font-medium",children:"?"})}),p&&n("div",{ref:O,className:`
|
|
15
15
|
absolute z-50 ${Z[i]}
|
|
16
|
-
${ee[
|
|
16
|
+
${ee[R]} max-h-[80vh] overflow-hidden flex flex-col
|
|
17
17
|
bg-white dark:bg-gray-900
|
|
18
18
|
border border-gray-200 dark:border-gray-700
|
|
19
19
|
rounded-xl shadow-xl
|
|
20
20
|
text-sm text-gray-700 dark:text-gray-300
|
|
21
21
|
animate-in fade-in-0 zoom-in-95 duration-150
|
|
22
|
-
`,role:"tooltip",children:[(
|
|
22
|
+
`,role:"tooltip",children:[(m||h)&&n("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50",children:[e("div",{className:"flex items-center gap-2",children:m&&e("h3",{className:"text-sm font-semibold",children:m})}),h&&e("div",{className:"flex items-center gap-1",children:l?n(ne,{children:[e("button",{type:"button",onClick:U,disabled:I,className:"p-1.5 rounded-md hover:bg-green-100 dark:hover:bg-green-900/30 text-green-700 dark:text-green-400 transition-colors disabled:opacity-50 cursor-pointer",title:r.helpButtonSave,children:I?X:F}),e("button",{type:"button",onClick:D,className:"p-1.5 rounded-md hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors cursor-pointer",title:r.helpButtonCancel,children:J}),c&&e("button",{type:"button",onClick:$,disabled:I,className:"p-1.5 rounded-md hover:bg-orange-100 dark:hover:bg-orange-900/30 text-orange-700 dark:text-orange-400 transition-colors disabled:opacity-50 cursor-pointer",title:r.helpButtonReset,children:Q})]}):e("button",{type:"button",onClick:A,className:"p-1.5 rounded-md hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors cursor-pointer",title:r.helpButtonEdit,children:j})})]}),T&&e("div",{className:`px-4 py-2 text-xs ${T.type==="success"?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-400"}`,children:T.text}),e("div",{className:"flex-1 overflow-y-auto p-4",children:l?t?v?e(v,{value:k,onChange:x,placeholder:r.markdownEditorPlaceholder}):e("p",{role:"alert",className:"p-3 text-sm text-gray-500 dark:text-gray-400",children:L??r.markdownEditorUnavailable}):e("div",{className:"space-y-2",children:e("textarea",{ref:P,"aria-label":r.helpButtonContent,value:k,onChange:u=>x(u.target.value),className:"w-full h-64 p-3 text-sm bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-synertech-primary-500/50 text-gray-700 dark:text-gray-300 font-mono",placeholder:r.helpButtonContentPlaceholder})}):typeof w=="string"?e("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:t?e(K,{remarkPlugins:te,components:oe,disallowedElements:re,children:w}):e("div",{dangerouslySetInnerHTML:{__html:V(w)}})}):w})]})]}):null}function ue({children:o,content:t,markdown:i=!1,position:d="bottom",size:f="sm",visible:_=!0,editable:h=!1,onSave:g,onReset:c,width:R="md",title:m,className:v,markdownEditor:L,markdownEditorUnavailableLabel:M,labels:r}){return n("div",{className:"inline-flex items-center gap-2.5",children:[o,e(ae,{content:t,markdown:i,position:d,size:f,visible:_,editable:h,onSave:g,onReset:c,width:R,title:m,className:v,markdownEditor:L,markdownEditorUnavailableLabel:M,labels:r})]})}export{ae as HelpButton,ue as WithHelpButton};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.create;var i=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var A=(t,e)=>{for(var n in e)i(t,n,{get:e[n],enumerable:!0})},f=(t,e,n,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!p.call(t,r)&&r!==n&&i(t,r,{get:()=>e[r],enumerable:!(l=c(e,r))||l.enumerable});return t};var L=(t,e,n)=>(n=t!=null?a(h(t)):{},f(e||!t||!t.__esModule?i(n,"default",{value:t,enumerable:!0}):n,t)),T=t=>f(i({},"__esModule",{value:!0}),t);var y={};A(y,{sanitizeHelpHtml:()=>S});module.exports=T(y);var u=L(require("dompurify"),1),s=require("../../lib/safe-href.cjs"),b=["h1","h2","h3","h4","h5","h6","p","br","hr","blockquote","pre","div","span","ul","ol","li","table","thead","tbody","tr","th","td","a","strong","b","em","i","del","s","code","kbd"],g={ALLOWED_TAGS:b,ALLOWED_ATTR:["href","title"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1};function m(t){try{let e=new URL(t,window.location.href);return(e.protocol==="http:"||e.protocol==="https:")&&e.origin!==window.location.origin}catch{return!1}}function _(t){if(t.nodeType!==1)return;let e=t,n=e.getAttribute("href");if(n!==null){if(e.tagName!=="A"||(0,s.safeHref)(n)===void 0){e.removeAttribute("href");return}m(n)&&e.setAttribute("rel","noopener noreferrer")}}var o=null;function w(){if(o)return o;if(typeof window>"u")return null;let t=(0,u.default)(window);return t.isSupported?(t.addHook("afterSanitizeAttributes",_),o=t,o):null}function S(t){let e=w();return e?e.sanitize(t,g):""}0&&(module.exports={sanitizeHelpHtml});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import i from"dompurify";import{safeHref as o}from"../../lib/safe-href.js";var l=["h1","h2","h3","h4","h5","h6","p","br","hr","blockquote","pre","div","span","ul","ol","li","table","thead","tbody","tr","th","td","a","strong","b","em","i","del","s","code","kbd"],f={ALLOWED_TAGS:l,ALLOWED_ATTR:["href","title"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1};function u(e){try{let t=new URL(e,window.location.href);return(t.protocol==="http:"||t.protocol==="https:")&&t.origin!==window.location.origin}catch{return!1}}function s(e){if(e.nodeType!==1)return;let t=e,r=t.getAttribute("href");if(r!==null){if(t.tagName!=="A"||o(r)===void 0){t.removeAttribute("href");return}u(r)&&t.setAttribute("rel","noopener noreferrer")}}var n=null;function a(){if(n)return n;if(typeof window>"u")return null;let e=i(window);return e.isSupported?(e.addHook("afterSanitizeAttributes",s),n=e,n):null}function h(e){let t=a();return t?t.sanitize(e,f):""}export{h as sanitizeHelpHtml};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Se=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var _e=Object.prototype.hasOwnProperty;var ze=(u,s)=>{for(var r in s)Se(u,r,{get:s[r],enumerable:!0})},Ue=(u,s,r,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of Oe(s))!_e.call(u,c)&&c!==r&&Se(u,c,{get:()=>s[c],enumerable:!(i=Ge(s,c))||i.enumerable});return u};var je=u=>Ue(Se({},"__esModule",{value:!0}),u);var et={};ze(et,{LineChart:()=>Ze});module.exports=je(et);var l=require("react"),Ve=require("../../lib/cn.cjs"),Ae=require("../../lib/i18n.cjs"),j=require("../chart/ChartAnnotations.cjs"),Re=require("../chart/ChartAxis.cjs"),le=require("../chart/ChartBrush.cjs"),Te=require("../chart/ChartContainer.cjs"),Be=require("../chart/ChartGrid.cjs"),Ee=require("../chart/ChartLegend.cjs"),He=require("../chart/ChartSync.cjs"),We=require("../chart/ChartTableView.cjs"),he=require("../chart/ChartTooltip.cjs"),E=require("../chart/palette.cjs"),k=require("../chart/utils/cartesian.cjs"),F=require("../chart/utils/data.cjs"),ue=require("../chart/utils/decimate.cjs"),ce=require("../chart/utils/format.cjs"),de=require("../chart/utils/keyboard.cjs"),H=require("../chart/utils/path.cjs"),B=require("../chart/utils/scales.cjs"),Ie=require("../chart/utils/ticks.cjs"),Ne=require("../chart/utils/timestamp.cjs"),De=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Fe=24,Ye=10,qe=10,Je=(0,l.memo)(function({lines:s,showMarkers:r}){return(0,n.jsx)("g",{children:s.map(i=>(0,n.jsxs)("g",{children:[i.solid?(0,n.jsx)("path",{d:i.solid,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,i.dashed?(0,n.jsx)("path",{d:i.dashed,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(r?i.markers:i.isolated).map(c=>(0,n.jsx)("circle",{cx:c.x,cy:c.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${c.x}-${c.y}`))]},i.key))})});function Qe({width:u,height:s,data:r,resolvedSeries:i,x:c,y:W,grid:C,size:Y,curve:b,forecastFrom:X,forecastLabel:v,markers:P,connectNulls:L,referenceLines:me,annotations:S,annotationsLabel:fe,overlay:ge,maxPoints:R,brush:q,onBrush:J,brushLabel:pe,syncEnabled:ye,margin:Q,tooltip:w,onPointClick:V,plotLabel:Ce,formatValue:A,formatX:I}){let[$,G]=(0,l.useState)(null),h=$!==null&&$<r.length?$:null,[be,xe]=(0,l.useState)(null),ke=(0,He.useChartSync)(),m=ye?ke:null,e=(0,l.useMemo)(()=>{let t=i.filter(f=>!f.hidden),o=(0,k.buildCartesianGeometry)({width:u,height:s,data:r,x:c,y:W,bounds:(0,Ie.extent)((0,F.collectAllValues)(r,t.map(f=>f.key))),margin:Q,placement:"point",formatValue:A,formatX:I,extraTop:v?Ye:0}),d=o.categoryCenters,T=o.valueScale,re=X===void 0?-1:o.xValues.findIndex(f=>(0,B.toKey)(f)===(0,B.toKey)(X)),Ke=t.map(f=>{let U=r.map((ie,$e)=>{let Le=(0,F.readNumber)(ie,f.key);return{x:d[$e],y:Le===null?Number.NaN:T(Le),defined:Le!==null}}),we={connectNulls:L},oe=re>=0,Pe=ie=>R&&R>0?(0,ue.decimatePath)(ie,R):ie,ae=Pe(oe?U.slice(0,re+1):U),se=f.dashed?Pe(U):oe?Pe(U.slice(re)):[];R||(0,ue.warnPointBudget)("LineChart",U.length);let Xe=f.dashed?se:oe?[...ae,...se.slice(1)]:ae;return{key:f.key,color:f.color,solid:f.dashed?"":(0,H.buildLinePath)(ae,b,we),dashed:f.dashed||oe?(0,H.buildLinePath)(se,b,we):"",markers:[...ae,...f.dashed?[]:se].filter(H.isDrawable),isolated:(0,H.isolatedPoints)(Xe,L)}}),Me=r.length>1?o.innerWidth/(r.length-1):0;return{visible:t,locate:(0,k.createCategoryLocator)(o),plot:(0,k.createPlotContext)({geometry:o,width:u,height:s,data:r,series:t,formatValue:A,formatX:I}),xValues:o.xValues,xPositions:d,xTicks:o.categoryTicks,yTicks:o.valueTicks,yScale:T,innerWidth:o.innerWidth,innerHeight:o.innerHeight,margin:o.margin,lines:Ke,forecastIndex:re,showMarkers:P==="always"||P==="auto"&&Me>=Fe&&r.length>1}},[r,i,c,W,u,s,Q,b,L,X,v,P,R,A,I]),y=(0,l.useCallback)(t=>e.visible.map(o=>{let d=(0,F.readNumber)(r[t],o.key);return{seriesKey:o.key,seriesLabel:(0,E.getSeriesLabel)(o),color:o.color,value:d,formattedValue:d===null?"\u2014":A(d),datum:r[t]}}),[r,e.visible,A]),Z=m?m.brush:be,ve=(0,l.useCallback)(t=>{xe(t),m?.setBrush(t),J?.(t)},[m,J]),g=(0,le.useChartBrush)({enabled:q,active:Z!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ve}),ee=(0,l.useCallback)(t=>{if(g.onPointerMove(t),w===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),d=t.clientX-o.left-e.margin.left,T=(0,B.nearestIndex)(e.xPositions,d);G(T>=0?T:null),m?.setHovered(T>=0?e.xValues[T]:null)},[g,w,r.length,e.margin.left,e.xPositions,e.xValues,m]),O=(0,l.useCallback)(()=>{G(null),m?.setHovered(null)},[m]),N=(0,l.useCallback)(()=>{if(!V||h===null)return;let[t]=y(h);t&&V({...t,index:h,x:e.xValues[h]})},[V,h,y,e.xValues]),D=(0,l.useCallback)(t=>{if(r.length===0)return;let o=V&&h!==null&&e.visible.length>0;if((0,de.pressChartMark)(t,o?N:null))return;g.onKeyDown(t,h);let d=(0,de.chartCursorTarget)(t.key,h,r.length,"x");d!==void 0&&(t.preventDefault(),G(d),m?.setHovered(d===null?null:e.xValues[d]))},[r.length,h,g,m,e.xValues,e.visible.length,V,N]),te=(0,l.useCallback)(()=>{g.consumedClick()||N()},[g,N]),ne=h!==null||!m?.hovered?null:(()=>{let t=(0,B.toKey)(m.hovered),o=e.xValues.findIndex(d=>(0,B.toKey)(d)===t);return o<0?null:o})(),x=h??ne,_=x===null?null:y(x),K=(_??[]).filter(t=>t.value!==null),z=g.dragging??Z,a=(()=>{if(!z)return null;let t=e.locate(z.from),o=e.locate(z.to);return t===null||o===null?null:{from:t,to:o}})(),M=(0,k.splitOverlay)(ge),p=h===null||_===null?null:{x:e.xValues[h],xLabel:I(e.xValues[h],h),index:h,points:_};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:u,height:s,role:"img","aria-label":Ce??[e.visible.map(t=>(0,E.getSeriesLabel)(t)).join(", "),(0,j.describeAnnotations)(S,fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ve.cn)(De.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",q&&"select-none"),onPointerDown:g.onPointerDown,onPointerMove:ee,onPointerUp:g.onPointerUp,onPointerCancel:g.onPointerUp,onPointerLeave:O,onKeyDown:D,onBlur:O,onClick:te,children:[(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Be.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:C==="y"||C==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:C==="x"||C==="both"?e.xTicks.map(t=>t.offset):void 0}),S?(0,n.jsx)(j.ChartAnnotationLayer,{layer:"under",annotations:S,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a?(0,n.jsx)(le.ChartBrushLayer,{from:a.from,to:a.to,width:e.innerWidth,height:e.innerHeight,live:g.dragging!==null,label:pe}):null,M.under?.(e.plot),me?.map(t=>{let o=e.yScale(t.value),d=o<qe?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:d,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),v?(0,n.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:v}):null]}):null,(0,n.jsx)(Je,{lines:e.lines,showMarkers:e.showMarkers}),S?(0,n.jsx)(j.ChartAnnotationLayer,{annotations:S,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,M.over?.(e.plot),x!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.xPositions[x],y1:0,x2:e.xPositions[x],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:h===null?"3 3":void 0}),K.map(t=>(0,n.jsx)("circle",{cx:e.xPositions[x],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:c.hidden?null:(0,n.jsx)(Re.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:c.label,size:Y})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:W?.hidden?null:(0,n.jsx)(Re.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:W?.label,size:Y})})]}),p&&w!==!1?(0,n.jsx)(he.ChartTooltip,{x:e.margin.left+e.xPositions[p.index],y:e.margin.top+(K.length>0?Math.min(...K.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:u,children:typeof w=="function"?w(p):(0,n.jsx)(he.ChartTooltipContent,{title:p.xLabel,points:p.points})}):null]})}function Ze({data:u,series:s,x:r,y:i,height:c=240,width:W,size:C="md",grid:Y="y",legend:b,tooltip:X=!0,tableView:v=!1,emphasis:P,title:L,description:me,loading:S=!1,emptyState:fe,error:ge=!1,errorState:R,onRetry:q,actions:J,onPointClick:pe,curve:ye="monotone",forecastFrom:Q,forecastLabel:w,markers:V="auto",connectNulls:Ce=!1,referenceLines:A,annotations:I,overlay:$,legendToggle:G=!0,maxPoints:h,brush:be=!1,onBrush:xe,brushLabel:ke,sync:m=!0,margin:e,locale:y,plotLabel:Z,className:ve,...g}){let ee=(0,Ae.useUILabels)(),[O,N]=(0,l.useState)(()=>new Set),D=(0,l.useMemo)(()=>s.map((a,M)=>({...a,hidden:a.hidden||O.has(a.key),color:(0,E.resolveSeriesColor)(a,M,P)})),[s,O,P]),te=(0,l.useMemo)(()=>i?.format??(a=>(0,ce.formatAuto)(a,y)),[i?.format,y]),ne=(0,l.useMemo)(()=>r.format??(a=>r.scale==="time"?(0,Ne.formatTimeValue)(a,y):(0,ce.formatXValue)(a,y)),[r.format,r.scale,y]),x=(0,l.useCallback)(a=>{N(M=>{let p=new Set(M);return p.has(a)?p.delete(a):p.add(a),p})},[]),_=b===void 0?s.length>=2:b!==!1,K=typeof b=="string"?b:"bottom",z=D.filter(a=>!a.hidden).length;return(0,n.jsx)(Te.ChartContainer,{title:L,description:me,height:c,width:W,size:C,loading:S,empty:u.length===0||z===0,emptyState:fe,error:ge,errorState:R,onRetry:q,actions:J,tableView:v,legendPosition:K,legend:_?(0,n.jsx)(Ee.ChartLegend,{items:(0,E.toLegendItems)(D,P),position:K,marker:"line",size:C,onToggle:G?x:void 0}):void 0,table:v?(0,n.jsx)(We.ChartTableView,{data:u,series:D,xKey:r.key,xLabel:r.label??r.key,formatX:ne,formatValue:te,caption:typeof L=="string"?L:void 0}):void 0,className:ve,...g,children:({width:a})=>(0,n.jsx)(Qe,{width:a,height:c,data:u,resolvedSeries:D,x:r,y:i,grid:Y,size:C,curve:ye,forecastFrom:Q,forecastLabel:w,markers:V,connectNulls:Ce,referenceLines:A,annotations:I,annotationsLabel:ee.chartAnnotations,overlay:$,maxPoints:h,brush:be,onBrush:xe,brushLabel:ke??ee.chartBrush,syncEnabled:m,margin:e,tooltip:X,onPointClick:pe,plotLabel:Z,formatValue:te,formatX:ne})})}0&&(module.exports={LineChart});
|
|
1
|
+
"use strict";"use client";var Re=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var _e=Object.prototype.hasOwnProperty;var ze=(u,a)=>{for(var r in a)Re(u,r,{get:a[r],enumerable:!0})},Ue=(u,a,r,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Oe(a))!_e.call(u,c)&&c!==r&&Re(u,c,{get:()=>a[c],enumerable:!(s=Ge(a,c))||s.enumerable});return u};var je=u=>Ue(Re({},"__esModule",{value:!0}),u);var et={};ze(et,{LineChart:()=>Ze});module.exports=je(et);var l=require("react"),Ae=require("../../lib/cn.cjs"),ie=require("../../lib/i18n.cjs"),F=require("../chart/ChartAnnotations.cjs"),we=require("../chart/ChartAxis.cjs"),le=require("../chart/ChartBrush.cjs"),Te=require("../chart/ChartContainer.cjs"),Be=require("../chart/ChartGrid.cjs"),Ee=require("../chart/ChartLegend.cjs"),He=require("../chart/ChartSync.cjs"),We=require("../chart/ChartTableView.cjs"),he=require("../chart/ChartTooltip.cjs"),H=require("../chart/palette.cjs"),x=require("../chart/utils/cartesian.cjs"),Y=require("../chart/utils/data.cjs"),ue=require("../chart/utils/decimate.cjs"),ce=require("../chart/utils/format.cjs"),de=require("../chart/utils/keyboard.cjs"),W=require("../chart/utils/path.cjs"),E=require("../chart/utils/scales.cjs"),Ie=require("../chart/utils/ticks.cjs"),Ne=require("../chart/utils/timestamp.cjs"),De=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),Fe=24,Ye=10,qe=10,Je=(0,l.memo)(function({lines:a,showMarkers:r}){return(0,n.jsx)("g",{children:a.map(s=>(0,n.jsxs)("g",{children:[s.solid?(0,n.jsx)("path",{d:s.solid,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,s.dashed?(0,n.jsx)("path",{d:s.dashed,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(r?s.markers:s.isolated).map(c=>(0,n.jsx)("circle",{cx:c.x,cy:c.y,r:3,fill:s.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${c.x}-${c.y}`))]},s.key))})});function Qe({width:u,height:a,data:r,resolvedSeries:s,x:c,y:I,grid:C,size:q,curve:b,forecastFrom:M,forecastLabel:k,markers:v,connectNulls:P,referenceLines:me,annotations:L,annotationsLabel:fe,overlay:ge,maxPoints:S,brush:J,onBrush:Q,brushLabel:pe,syncEnabled:ye,margin:Z,tooltip:R,onPointClick:w,plotLabel:Ce,formatValue:V,formatX:N}){let[X,$]=(0,l.useState)(null),h=X!==null&&X<r.length?X:null,[be,xe]=(0,l.useState)(null),ke=(0,He.useChartSync)(),m=ye?ke:null,e=(0,l.useMemo)(()=>{let t=s.filter(f=>!f.hidden),o=(0,x.buildCartesianGeometry)({width:u,height:a,data:r,x:c,y:I,bounds:(0,Ie.extent)((0,Y.collectAllValues)(r,t.map(f=>f.key))),margin:Z,placement:"point",formatValue:V,formatX:N,extraTop:k?Ye:0}),d=o.categoryCenters,B=o.valueScale,ne=M===void 0?-1:o.xValues.findIndex(f=>(0,E.toKey)(f)===(0,E.toKey)(M)),Ke=t.map(f=>{let j=r.map((se,$e)=>{let Se=(0,Y.readNumber)(se,f.key);return{x:d[$e],y:Se===null?Number.NaN:B(Se),defined:Se!==null}}),Ve={connectNulls:P},re=ne>=0,Le=se=>S&&S>0?(0,ue.decimatePath)(se,S):se,oe=Le(re?j.slice(0,ne+1):j),ae=f.dashed?Le(j):re?Le(j.slice(ne)):[];S||(0,ue.warnPointBudget)("LineChart",j.length);let Xe=f.dashed?ae:re?[...oe,...ae.slice(1)]:oe;return{key:f.key,color:f.color,solid:f.dashed?"":(0,W.buildLinePath)(oe,b,Ve),dashed:f.dashed||re?(0,W.buildLinePath)(ae,b,Ve):"",markers:[...oe,...f.dashed?[]:ae].filter(W.isDrawable),isolated:(0,W.isolatedPoints)(Xe,P)}}),Me=r.length>1?o.innerWidth/(r.length-1):0;return{visible:t,locate:(0,x.createCategoryLocator)(o),plot:(0,x.createPlotContext)({geometry:o,width:u,height:a,data:r,series:t,formatValue:V,formatX:N}),xValues:o.xValues,xPositions:d,xTicks:o.categoryTicks,yTicks:o.valueTicks,yScale:B,innerWidth:o.innerWidth,innerHeight:o.innerHeight,margin:o.margin,lines:Ke,forecastIndex:ne,showMarkers:v==="always"||v==="auto"&&Me>=Fe&&r.length>1}},[r,s,c,I,u,a,Z,b,P,M,k,v,S,V,N]),G=(0,l.useCallback)(t=>e.visible.map(o=>{let d=(0,Y.readNumber)(r[t],o.key);return{seriesKey:o.key,seriesLabel:(0,H.getSeriesLabel)(o),color:o.color,value:d,formattedValue:d===null?"\u2014":V(d),datum:r[t]}}),[r,e.visible,V]),ee=m?m.brush:be,ve=(0,l.useCallback)(t=>{xe(t),m?.setBrush(t),Q?.(t)},[m,Q]),g=(0,le.useChartBrush)({enabled:J,active:ee!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ve}),A=(0,l.useCallback)(t=>{if(g.onPointerMove(t),R===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),d=t.clientX-o.left-e.margin.left,B=(0,E.nearestIndex)(e.xPositions,d);$(B>=0?B:null),m?.setHovered(B>=0?e.xValues[B]:null)},[g,R,r.length,e.margin.left,e.xPositions,e.xValues,m]),O=(0,l.useCallback)(()=>{$(null),m?.setHovered(null)},[m]),T=(0,l.useCallback)(()=>{if(!w||h===null)return;let[t]=G(h);t&&w({...t,index:h,x:e.xValues[h]})},[w,h,G,e.xValues]),Pe=(0,l.useCallback)(t=>{if(r.length===0)return;let o=w&&h!==null&&e.visible.length>0;if((0,de.pressChartMark)(t,o?T:null))return;g.onKeyDown(t,h);let d=(0,de.chartCursorTarget)(t.key,h,r.length,"x");d!==void 0&&(t.preventDefault(),$(d),m?.setHovered(d===null?null:e.xValues[d]))},[r.length,h,g,m,e.xValues,e.visible.length,w,T]),D=(0,l.useCallback)(()=>{g.consumedClick()||T()},[g,T]),te=h!==null||!m?.hovered?null:(()=>{let t=(0,E.toKey)(m.hovered),o=e.xValues.findIndex(d=>(0,E.toKey)(d)===t);return o<0?null:o})(),p=h??te,_=p===null?null:G(p),z=(_??[]).filter(t=>t.value!==null),K=g.dragging??ee,U=(()=>{if(!K)return null;let t=e.locate(K.from),o=e.locate(K.to);return t===null||o===null?null:{from:t,to:o}})(),i=(0,x.splitOverlay)(ge),y=h===null||_===null?null:{x:e.xValues[h],xLabel:N(e.xValues[h],h),index:h,points:_};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:u,height:a,role:"img","aria-label":Ce??[e.visible.map(t=>(0,H.getSeriesLabel)(t)).join(", "),(0,F.describeAnnotations)(L,fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ae.cn)(De.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",J&&"select-none"),onPointerDown:g.onPointerDown,onPointerMove:A,onPointerUp:g.onPointerUp,onPointerCancel:g.onPointerUp,onPointerLeave:O,onKeyDown:Pe,onBlur:O,onClick:D,children:[(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Be.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:C==="y"||C==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:C==="x"||C==="both"?e.xTicks.map(t=>t.offset):void 0}),L?(0,n.jsx)(F.ChartAnnotationLayer,{layer:"under",annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,U?(0,n.jsx)(le.ChartBrushLayer,{from:U.from,to:U.to,width:e.innerWidth,height:e.innerHeight,live:g.dragging!==null,label:pe}):null,i.under?.(e.plot),me?.map(t=>{let o=e.yScale(t.value),d=o<qe?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:d,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),k?(0,n.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:k}):null]}):null,(0,n.jsx)(Je,{lines:e.lines,showMarkers:e.showMarkers}),L?(0,n.jsx)(F.ChartAnnotationLayer,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,i.over?.(e.plot),p!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.xPositions[p],y1:0,x2:e.xPositions[p],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:h===null?"3 3":void 0}),z.map(t=>(0,n.jsx)("circle",{cx:e.xPositions[p],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:c.hidden?null:(0,n.jsx)(we.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:c.label,size:q})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:I?.hidden?null:(0,n.jsx)(we.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:I?.label,size:q})})]}),y&&R!==!1?(0,n.jsx)(he.ChartTooltip,{x:e.margin.left+e.xPositions[y.index],y:e.margin.top+(z.length>0?Math.min(...z.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:u,children:typeof R=="function"?R(y):(0,n.jsx)(he.ChartTooltipContent,{title:y.xLabel,points:y.points})}):null]})}function Ze({data:u,series:a,x:r,y:s,height:c=240,width:I,size:C="md",grid:q="y",legend:b,tooltip:M=!0,tableView:k=!1,emphasis:v,title:P,description:me,loading:L=!1,emptyState:fe,error:ge=!1,errorState:S,onRetry:J,actions:Q,onPointClick:pe,curve:ye="monotone",forecastFrom:Z,forecastLabel:R,markers:w="auto",connectNulls:Ce=!1,referenceLines:V,annotations:N,overlay:X,legendToggle:$=!0,maxPoints:h,brush:be=!1,onBrush:xe,brushLabel:ke,sync:m=!0,margin:e,locale:G,plotLabel:ee,className:ve,...g}){let A=(0,ie.useUILocale)(G),O=(0,ie.useUILabels)(),[T,Pe]=(0,l.useState)(()=>new Set),D=(0,l.useMemo)(()=>a.map((i,y)=>({...i,hidden:i.hidden||T.has(i.key),color:(0,H.resolveSeriesColor)(i,y,v)})),[a,T,v]),te=(0,l.useMemo)(()=>s?.format??(i=>(0,ce.formatAuto)(i,A)),[s?.format,A]),p=(0,l.useMemo)(()=>r.format??(i=>r.scale==="time"?(0,Ne.formatTimeValue)(i,A):(0,ce.formatXValue)(i,A)),[r.format,r.scale,A]),_=(0,l.useCallback)(i=>{Pe(y=>{let t=new Set(y);return t.has(i)?t.delete(i):t.add(i),t})},[]),z=b===void 0?a.length>=2:b!==!1,K=typeof b=="string"?b:"bottom",U=D.filter(i=>!i.hidden).length;return(0,n.jsx)(Te.ChartContainer,{title:P,description:me,height:c,width:I,size:C,loading:L,empty:u.length===0||U===0,emptyState:fe,error:ge,errorState:S,onRetry:J,actions:Q,tableView:k,legendPosition:K,legend:z?(0,n.jsx)(Ee.ChartLegend,{items:(0,H.toLegendItems)(D,v),position:K,marker:"line",size:C,onToggle:$?_:void 0}):void 0,table:k?(0,n.jsx)(We.ChartTableView,{data:u,series:D,xKey:r.key,xLabel:r.label??r.key,formatX:p,formatValue:te,caption:typeof P=="string"?P:void 0}):void 0,className:ve,...g,children:({width:i})=>(0,n.jsx)(Qe,{width:i,height:c,data:u,resolvedSeries:D,x:r,y:s,grid:q,size:C,curve:ye,forecastFrom:Z,forecastLabel:R,markers:w,connectNulls:Ce,referenceLines:V,annotations:N,annotationsLabel:O.chartAnnotations,overlay:X,maxPoints:h,brush:be,onBrush:xe,brushLabel:ke??O.chartBrush,syncEnabled:m,margin:e,tooltip:M,onPointClick:pe,plotLabel:ee,formatValue:te,formatX:p})})}0&&(module.exports={LineChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Ve,useCallback as
|
|
1
|
+
"use client";import{memo as Ve,useCallback as b,useMemo as re,useState as ye}from"react";import{cn as Ae}from"../../lib/cn.js";import{useUILabels as Te,useUILocale as Be}from"../../lib/i18n.js";import{ChartAnnotationLayer as be,describeAnnotations as Ee}from"../chart/ChartAnnotations.js";import{ChartAxis as xe}from"../chart/ChartAxis.js";import{ChartBrushLayer as He,useChartBrush as We}from"../chart/ChartBrush.js";import{ChartContainer as Ie}from"../chart/ChartContainer.js";import{ChartGrid as Ne}from"../chart/ChartGrid.js";import{ChartLegend as De}from"../chart/ChartLegend.js";import{useChartSync as Ke}from"../chart/ChartSync.js";import{ChartTableView as Me}from"../chart/ChartTableView.js";import{ChartTooltip as Xe,ChartTooltipContent as $e}from"../chart/ChartTooltip.js";import{getSeriesLabel as ke,resolveSeriesColor as Ge,toLegendItems as Oe}from"../chart/palette.js";import{buildCartesianGeometry as _e,createCategoryLocator as ze,createPlotContext as Ue,splitOverlay as je}from"../chart/utils/cartesian.js";import{collectAllValues as Fe,readNumber as ve}from"../chart/utils/data.js";import{decimatePath as Ye,warnPointBudget as qe}from"../chart/utils/decimate.js";import{formatAuto as Je,formatXValue as Qe}from"../chart/utils/format.js";import{chartCursorTarget as Ze,pressChartMark as et}from"../chart/utils/keyboard.js";import{buildLinePath as Pe,isDrawable as tt,isolatedPoints as nt}from"../chart/utils/path.js";import{nearestIndex as rt,toKey as ne}from"../chart/utils/scales.js";import{extent as ot}from"../chart/utils/ticks.js";import{formatTimeValue as at}from"../chart/utils/timestamp.js";import{CHART_TOUCH as st}from"../chart/utils/touch.js";import{Fragment as dt,jsx as o,jsxs as B}from"react/jsx-runtime";var it=24,lt=10,ht=10,ut=Ve(function({lines:f,showMarkers:r}){return o("g",{children:f.map(i=>B("g",{children:[i.solid?o("path",{d:i.solid,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,i.dashed?o("path",{d:i.dashed,fill:"none",stroke:i.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(r?i.markers:i.isolated).map(d=>o("circle",{cx:d.x,cy:d.y,r:3,fill:i.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${d.x}-${d.y}`))]},i.key))})});function ct({width:m,height:f,data:r,resolvedSeries:i,x:d,y:E,grid:y,size:z,curve:C,forecastFrom:N,forecastLabel:x,markers:k,connectNulls:v,referenceLines:oe,annotations:P,annotationsLabel:ae,overlay:se,maxPoints:L,brush:U,onBrush:j,brushLabel:ie,syncEnabled:le,margin:F,tooltip:S,onPointClick:R,plotLabel:he,formatValue:w,formatX:H}){let[D,K]=ye(null),s=D!==null&&D<r.length?D:null,[ue,ce]=ye(null),de=Ke(),h=le?de:null,e=re(()=>{let t=i.filter(u=>!u.hidden),n=_e({width:m,height:f,data:r,x:d,y:E,bounds:ot(Fe(r,t.map(u=>u.key))),margin:F,placement:"point",formatValue:w,formatX:H,extraTop:x?lt:0}),l=n.categoryCenters,T=n.valueScale,J=N===void 0?-1:n.xValues.findIndex(u=>ne(u)===ne(N)),Le=t.map(u=>{let _=r.map((te,we)=>{let pe=ve(te,u.key);return{x:l[we],y:pe===null?Number.NaN:T(pe),defined:pe!==null}}),Ce={connectNulls:v},Q=J>=0,ge=te=>L&&L>0?Ye(te,L):te,Z=ge(Q?_.slice(0,J+1):_),ee=u.dashed?ge(_):Q?ge(_.slice(J)):[];L||qe("LineChart",_.length);let Re=u.dashed?ee:Q?[...Z,...ee.slice(1)]:Z;return{key:u.key,color:u.color,solid:u.dashed?"":Pe(Z,C,Ce),dashed:u.dashed||Q?Pe(ee,C,Ce):"",markers:[...Z,...u.dashed?[]:ee].filter(tt),isolated:nt(Re,v)}}),Se=r.length>1?n.innerWidth/(r.length-1):0;return{visible:t,locate:ze(n),plot:Ue({geometry:n,width:m,height:f,data:r,series:t,formatValue:w,formatX:H}),xValues:n.xValues,xPositions:l,xTicks:n.categoryTicks,yTicks:n.valueTicks,yScale:T,innerWidth:n.innerWidth,innerHeight:n.innerHeight,margin:n.margin,lines:Le,forecastIndex:J,showMarkers:k==="always"||k==="auto"&&Se>=it&&r.length>1}},[r,i,d,E,m,f,F,C,v,N,x,k,L,w,H]),M=b(t=>e.visible.map(n=>{let l=ve(r[t],n.key);return{seriesKey:n.key,seriesLabel:ke(n),color:n.color,value:l,formattedValue:l===null?"\u2014":w(l),datum:r[t]}}),[r,e.visible,w]),Y=h?h.brush:ue,me=b(t=>{ce(t),h?.setBrush(t),j?.(t)},[h,j]),c=We({enabled:U,active:Y!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:me}),V=b(t=>{if(c.onPointerMove(t),S===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),l=t.clientX-n.left-e.margin.left,T=rt(e.xPositions,l);K(T>=0?T:null),h?.setHovered(T>=0?e.xValues[T]:null)},[c,S,r.length,e.margin.left,e.xPositions,e.xValues,h]),X=b(()=>{K(null),h?.setHovered(null)},[h]),A=b(()=>{if(!R||s===null)return;let[t]=M(s);t&&R({...t,index:s,x:e.xValues[s]})},[R,s,M,e.xValues]),fe=b(t=>{if(r.length===0)return;let n=R&&s!==null&&e.visible.length>0;if(et(t,n?A:null))return;c.onKeyDown(t,s);let l=Ze(t.key,s,r.length,"x");l!==void 0&&(t.preventDefault(),K(l),h?.setHovered(l===null?null:e.xValues[l]))},[r.length,s,c,h,e.xValues,e.visible.length,R,A]),W=b(()=>{c.consumedClick()||A()},[c,A]),q=s!==null||!h?.hovered?null:(()=>{let t=ne(h.hovered),n=e.xValues.findIndex(l=>ne(l)===t);return n<0?null:n})(),g=s??q,$=g===null?null:M(g),G=($??[]).filter(t=>t.value!==null),I=c.dragging??Y,O=(()=>{if(!I)return null;let t=e.locate(I.from),n=e.locate(I.to);return t===null||n===null?null:{from:t,to:n}})(),a=je(se),p=s===null||$===null?null:{x:e.xValues[s],xLabel:H(e.xValues[s],s),index:s,points:$};return B(dt,{children:[B("svg",{width:m,height:f,role:"img","aria-label":he??[e.visible.map(t=>ke(t)).join(", "),Ee(P,ae)].filter(Boolean).join(". "),tabIndex:0,className:Ae(st,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",U&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:V,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:X,onKeyDown:fe,onBlur:X,onClick:W,children:[B("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o(Ne,{width:e.innerWidth,height:e.innerHeight,horizontal:y==="y"||y==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:y==="x"||y==="both"?e.xTicks.map(t=>t.offset):void 0}),P?o(be,{layer:"under",annotations:P,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,O?o(He,{from:O.from,to:O.to,width:e.innerWidth,height:e.innerHeight,live:c.dragging!==null,label:ie}):null,a.under?.(e.plot),oe?.map(t=>{let n=e.yScale(t.value),l=n<ht?n+12:n-4;return B("g",{children:[o("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?B("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),x?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:x}):null]}):null,o(ut,{lines:e.lines,showMarkers:e.showMarkers}),P?o(be,{annotations:P,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a.over?.(e.plot),g!==null?B("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[g],y1:0,x2:e.xPositions[g],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:s===null?"3 3":void 0}),G.map(t=>o("circle",{cx:e.xPositions[g],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:o(xe,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:z})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:E?.hidden?null:o(xe,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:E?.label,size:z})})]}),p&&S!==!1?o(Xe,{x:e.margin.left+e.xPositions[p.index],y:e.margin.top+(G.length>0?Math.min(...G.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:m,children:typeof S=="function"?S(p):o($e,{title:p.xLabel,points:p.points})}):null]})}function Nt({data:m,series:f,x:r,y:i,height:d=240,width:E,size:y="md",grid:z="y",legend:C,tooltip:N=!0,tableView:x=!1,emphasis:k,title:v,description:oe,loading:P=!1,emptyState:ae,error:se=!1,errorState:L,onRetry:U,actions:j,onPointClick:ie,curve:le="monotone",forecastFrom:F,forecastLabel:S,markers:R="auto",connectNulls:he=!1,referenceLines:w,annotations:H,overlay:D,legendToggle:K=!0,maxPoints:s,brush:ue=!1,onBrush:ce,brushLabel:de,sync:h=!0,margin:e,locale:M,plotLabel:Y,className:me,...c}){let V=Be(M),X=Te(),[A,fe]=ye(()=>new Set),W=re(()=>f.map((a,p)=>({...a,hidden:a.hidden||A.has(a.key),color:Ge(a,p,k)})),[f,A,k]),q=re(()=>i?.format??(a=>Je(a,V)),[i?.format,V]),g=re(()=>r.format??(a=>r.scale==="time"?at(a,V):Qe(a,V)),[r.format,r.scale,V]),$=b(a=>{fe(p=>{let t=new Set(p);return t.has(a)?t.delete(a):t.add(a),t})},[]),G=C===void 0?f.length>=2:C!==!1,I=typeof C=="string"?C:"bottom",O=W.filter(a=>!a.hidden).length;return o(Ie,{title:v,description:oe,height:d,width:E,size:y,loading:P,empty:m.length===0||O===0,emptyState:ae,error:se,errorState:L,onRetry:U,actions:j,tableView:x,legendPosition:I,legend:G?o(De,{items:Oe(W,k),position:I,marker:"line",size:y,onToggle:K?$:void 0}):void 0,table:x?o(Me,{data:m,series:W,xKey:r.key,xLabel:r.label??r.key,formatX:g,formatValue:q,caption:typeof v=="string"?v:void 0}):void 0,className:me,...c,children:({width:a})=>o(ct,{width:a,height:d,data:m,resolvedSeries:W,x:r,y:i,grid:z,size:y,curve:le,forecastFrom:F,forecastLabel:S,markers:R,connectNulls:he,referenceLines:w,annotations:H,annotationsLabel:X.chartAnnotations,overlay:D,maxPoints:s,brush:ue,onBrush:ce,brushLabel:de??X.chartBrush,syncEnabled:h,margin:e,tooltip:N,onPointClick:ie,plotLabel:Y,formatValue:q,formatX:g})})}export{Nt as LineChart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var j=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var ge=(s,t)=>{for(var a in t)j(s,a,{get:t[a],enumerable:!0})},be=(s,t,a,C)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of de(t))!pe.call(s,d)&&d!==a&&j(s,d,{get:()=>t[d],enumerable:!(C=me(t,d))||C.enumerable});return s};var fe=s=>be(j({},"__esModule",{value:!0}),s);var Ne={};ge(Ne,{PieChart:()=>xe,resetPieWarnings:()=>Le});module.exports=fe(Ne);var m=require("react"),$=require("../../lib/i18n.cjs"),ae=require("../chart/ChartContainer.cjs"),oe=require("../chart/ChartLegend.cjs"),B=require("../chart/ChartPatterns.cjs"),ne=require("../chart/ChartTableView.cjs"),O=require("../chart/ChartTooltip.cjs"),D=require("../chart/palette.cjs"),_=require("../chart/utils/data.cjs"),x=require("../chart/utils/format.cjs"),re=require("../chart/utils/keyboard.cjs"),le=require("../chart/utils/path.cjs"),se=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),ye=.62,Ce=2,ve=3,Ae=.16,ke=64,Pe=22,q=6,J=!1;function Re({width:s,height:t,slices:a,variant:C,innerRadius:d,showLabels:v,centerLabel:A,tooltip:k,patterns:I,patternBaseId:V,plotLabel:T,formatValue:S,locale:K,onSliceClick:R}){let[P,L]=(0,m.useState)(null),p=P!==null&&P<a.length?P:null,M=(0,m.useMemo)(()=>{let e=v?ke:8,o=v?Pe:8,u=Math.max(0,Math.min((s-e*2)/2,(t-o*2)/2));return{cx:s/2,cy:t/2,outerRadius:u,inner:C==="donut"?u*(d??ye):(d??0)*u,pad:u>0&&a.length>1?Ce/u/2:0}},[s,t,C,d,v,a.length]),{cx:f,cy:y,outerRadius:g,inner:X,pad:w}=M,W=(0,m.useCallback)(e=>{let o=(e.startAngle+e.endAngle)/2,u=Math.sin(o)>=0,c={x:f+Math.sin(o)*(g+4),y:y-Math.cos(o)*(g+4)},b={x:f+Math.sin(o)*(g+14),y:y-Math.cos(o)*(g+14)},G={x:u?b.x+10:b.x-10,y:b.y};return{from:c,elbow:b,end:G,anchor:u?"start":"end"}},[f,y,g]),E=(0,m.useCallback)(e=>{let o=a[e];o&&R?.({key:o.key,label:o.label,value:o.value,share:o.share})},[a,R]),z=(0,m.useCallback)(e=>(0,re.handleChartKeyDown)(e,{count:a.length,current:p,axis:"both",onMove:L,pick:R&&p!==null?()=>E(p):null}),[a.length,p,R,E]),r=p===null?null:a[p];return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:s,height:t,role:"img","aria-label":T??a.map(e=>e.label).join(", "),tabIndex:0,className:`${se.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerLeave:()=>L(null),onBlur:()=>L(null),onKeyDown:z,children:[I?(0,n.jsx)(B.ChartPatternDefs,{id:V,entries:a.map(e=>({slot:e.slot,color:e.color}))}):null,a.map((e,o)=>(0,n.jsx)("path",{d:(0,le.buildArcPath)({cx:f,cy:y,innerRadius:X,outerRadius:g+(p===o?ve:0),startAngle:e.startAngle+w,endAngle:Math.max(e.startAngle+w,e.endAngle-w)}),fill:(0,B.patternFill)(I,V,e.slot,e.color),onPointerEnter:()=>k===!1?void 0:L(o),onClick:()=>E(o)},e.key)),v?a.filter(e=>e.endAngle-e.startAngle>=Ae).map(e=>{let{from:o,elbow:u,end:c,anchor:b}=W(e);return(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:`${o.x},${o.y} ${u.x},${u.y} ${c.x},${c.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),(0,n.jsx)("text",{x:b==="start"?c.x+3:c.x-3,y:c.y,textAnchor:b,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,C==="donut"&&A?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("text",{x:f,y:y-(A.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:A.value}),A.label?(0,n.jsx)("text",{x:f,y:y+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A.label}):null]}):null]}),r&&k!==!1?(0,n.jsx)(O.ChartTooltip,{x:f+Math.sin((r.startAngle+r.endAngle)/2)*(g*.7),y:y-Math.cos((r.startAngle+r.endAngle)/2)*(g*.7),containerWidth:s,children:typeof k=="function"?k({seriesKey:r.key,seriesLabel:r.label,color:r.color,value:r.value,formattedValue:S(r.value),datum:{},share:r.share}):(0,n.jsx)(O.ChartTooltipContent,{title:r.label,points:[{seriesKey:r.key,seriesLabel:(0,x.formatPercent)(r.share,{locale:K}),color:r.color,value:r.value,formattedValue:S(r.value),datum:{}}]})}):null]})}function xe({data:s,x:t,value:a,variant:C="pie",innerRadius:d,maxSlices:v=q,otherLabel:A,sort:k="desc",showLabels:I=!0,centerLabel:V,patterns:T=!1,height:S=260,width:K,size:R="md",legend:P,tooltip:L=!0,tableView:p=!1,title:M,description:f,loading:y=!1,emptyState:g,error:X=!1,errorState:w,onRetry:W,actions:E,locale:z,plotLabel:r,onSliceClick:e,className:o,...u}){let c=(0,$.useUILocale)(z),b=(0,$.useUILabels)(),G=(0,m.useId)(),Q=(0,m.useCallback)(i=>(0,x.formatAuto)(i,c),[c]),Y=(0,m.useCallback)(i=>t.format?t.format(i,0):(0,x.formatXValue)(i,c),[t,c]),{slices:H,total:ie,rows:ue}=(0,m.useMemo)(()=>{let i=s.map((l,h)=>({key:String((0,_.readXValue)(l,t.key,h)),label:Y((0,_.readXValue)(l,t.key,h)),value:(0,_.readNumber)(l,a)??0,color:(0,D.getSeriesColor)(h),slot:h,datum:l})),ee=k==="none"?i:[...i].sort((l,h)=>k==="asc"?l.value-h.value:h.value-l.value),N=ee.slice(0,v),te=ee.slice(v);te.length>0&&N.push({key:"__other__",label:A??b.chartOther,value:te.reduce((l,h)=>l+h.value,0),color:D.CHART_MUTED_COLOR,slot:-1,datum:{}}),N.length>q&&!J&&(J=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${N.length} slices. Past ${q} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let U=N.reduce((l,h)=>l+Math.max(0,h.value),0),F=0;return{slices:N.map(l=>{let h=U===0?0:Math.max(0,l.value)/U,he=F;return F+=h*Math.PI*2,{...l,share:h,startAngle:he,endAngle:F}}),total:U,rows:N.map(l=>({[t.key]:l.label,[a]:l.value}))}},[s,t.key,a,k,v,A,b.chartOther,Y]),ce=P===void 0?!0:P!==!1,Z=typeof P=="string"?P:"bottom";return(0,n.jsx)(ae.ChartContainer,{title:M,description:f,height:S,width:K,size:R,loading:y,empty:H.length===0||ie===0,emptyState:g,error:X,errorState:w,onRetry:W,actions:E,tableView:p,legendPosition:Z,legend:ce?(0,n.jsx)(oe.ChartLegend,{items:H.map(i=>({key:i.key,label:`${i.label} \xB7 ${(0,x.formatPercent)(i.share,{locale:c})}`,color:i.color,...T?{pattern:i.slot}:{}})),position:Z,marker:"rect",size:R}):void 0,table:p?(0,n.jsx)(ne.ChartTableView,{data:ue,series:[{key:a,label:t.label??a}],xKey:t.key,xLabel:t.label??t.key,formatValue:Q,caption:typeof M=="string"?M:void 0}):void 0,className:o,...u,children:({width:i})=>(0,n.jsx)(Re,{width:i,height:S,slices:H,variant:C,innerRadius:d,showLabels:I,centerLabel:V,tooltip:L,patterns:T,patternBaseId:G,plotLabel:r,formatValue:Q,locale:c,onSliceClick:e})})}function Le(){J=!1}0&&(module.exports={PieChart,resetPieWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useCallback as
|
|
1
|
+
"use client";import{useCallback as w,useId as oe,useMemo as Q,useState as ne}from"react";import{useUILabels as re,useUILocale as le}from"../../lib/i18n.js";import{ChartContainer as se}from"../chart/ChartContainer.js";import{ChartLegend as ie}from"../chart/ChartLegend.js";import{ChartPatternDefs as ue,patternFill as ce}from"../chart/ChartPatterns.js";import{ChartTableView as he}from"../chart/ChartTableView.js";import{ChartTooltip as me,ChartTooltipContent as de}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as pe,getSeriesColor as ge}from"../chart/palette.js";import{readNumber as be,readXValue as J}from"../chart/utils/data.js";import{formatAuto as fe,formatPercent as Y,formatXValue as ye}from"../chart/utils/format.js";import{handleChartKeyDown as Ce}from"../chart/utils/keyboard.js";import{buildArcPath as ve}from"../chart/utils/path.js";import{CHART_TOUCH as Ae}from"../chart/utils/touch.js";import{Fragment as Me,jsx as c,jsxs as V}from"react/jsx-runtime";var ke=.62,Pe=2,Re=3,xe=.16,Le=64,Ne=22,z=6,G=!1;function Se({width:b,height:r,slices:o,variant:R,innerRadius:x,showLabels:f,centerLabel:y,tooltip:C,patterns:E,patternBaseId:_,plotLabel:I,formatValue:L,locale:T,onSliceClick:A}){let[v,k]=ne(null),h=v!==null&&v<o.length?v:null,N=Q(()=>{let e=f?Le:8,t=f?Ne:8,s=Math.max(0,Math.min((b-e*2)/2,(r-t*2)/2));return{cx:b/2,cy:r/2,outerRadius:s,inner:R==="donut"?s*(x??ke):(x??0)*s,pad:s>0&&o.length>1?Pe/s/2:0}},[b,r,R,x,f,o.length]),{cx:p,cy:g,outerRadius:m,inner:$,pad:S}=N,B=w(e=>{let t=(e.startAngle+e.endAngle)/2,s=Math.sin(t)>=0,i={x:p+Math.sin(t)*(m+4),y:g-Math.cos(t)*(m+4)},d={x:p+Math.sin(t)*(m+14),y:g-Math.cos(t)*(m+14)},D={x:s?d.x+10:d.x-10,y:d.y};return{from:i,elbow:d,end:D,anchor:s?"start":"end"}},[p,g,m]),M=w(e=>{let t=o[e];t&&A?.({key:t.key,label:t.label,value:t.value,share:t.share})},[o,A]),O=w(e=>Ce(e,{count:o.length,current:h,axis:"both",onMove:k,pick:A&&h!==null?()=>M(h):null}),[o.length,h,A,M]),a=h===null?null:o[h];return V(Me,{children:[V("svg",{width:b,height:r,role:"img","aria-label":I??o.map(e=>e.label).join(", "),tabIndex:0,className:`${Ae} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerLeave:()=>k(null),onBlur:()=>k(null),onKeyDown:O,children:[E?c(ue,{id:_,entries:o.map(e=>({slot:e.slot,color:e.color}))}):null,o.map((e,t)=>c("path",{d:ve({cx:p,cy:g,innerRadius:$,outerRadius:m+(h===t?Re:0),startAngle:e.startAngle+S,endAngle:Math.max(e.startAngle+S,e.endAngle-S)}),fill:ce(E,_,e.slot,e.color),onPointerEnter:()=>C===!1?void 0:k(t),onClick:()=>M(t)},e.key)),f?o.filter(e=>e.endAngle-e.startAngle>=xe).map(e=>{let{from:t,elbow:s,end:i,anchor:d}=B(e);return V("g",{"aria-hidden":"true",children:[c("polyline",{points:`${t.x},${t.y} ${s.x},${s.y} ${i.x},${i.y}`,fill:"none",className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1}),c("text",{x:d==="start"?i.x+3:i.x-3,y:i.y,textAnchor:d,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] dark:fill-gray-300",children:e.label})]},`label-${e.key}`)}):null,R==="donut"&&y?V("g",{"aria-hidden":"true",children:[c("text",{x:p,y:g-(y.label?2:0),textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-900 text-lg font-semibold dark:fill-gray-100",children:y.value}),y.label?c("text",{x:p,y:g+14,textAnchor:"middle",dominantBaseline:"middle",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:y.label}):null]}):null]}),a&&C!==!1?c(me,{x:p+Math.sin((a.startAngle+a.endAngle)/2)*(m*.7),y:g-Math.cos((a.startAngle+a.endAngle)/2)*(m*.7),containerWidth:b,children:typeof C=="function"?C({seriesKey:a.key,seriesLabel:a.label,color:a.color,value:a.value,formattedValue:L(a.value),datum:{},share:a.share}):c(de,{title:a.label,points:[{seriesKey:a.key,seriesLabel:Y(a.share,{locale:T}),color:a.color,value:a.value,formattedValue:L(a.value),datum:{}}]})}):null]})}function Ge({data:b,x:r,value:o,variant:R="pie",innerRadius:x,maxSlices:f=z,otherLabel:y,sort:C="desc",showLabels:E=!0,centerLabel:_,patterns:I=!1,height:L=260,width:T,size:A="md",legend:v,tooltip:k=!0,tableView:h=!1,title:N,description:p,loading:g=!1,emptyState:m,error:$=!1,errorState:S,onRetry:B,actions:M,locale:O,plotLabel:a,onSliceClick:e,className:t,...s}){let i=le(O),d=re(),D=oe(),H=w(l=>fe(l,i),[i]),U=w(l=>r.format?r.format(l,0):ye(l,i),[r,i]),{slices:K,total:Z,rows:ee}=Q(()=>{let l=b.map((n,u)=>({key:String(J(n,r.key,u)),label:U(J(n,r.key,u)),value:be(n,o)??0,color:ge(u),slot:u,datum:n})),j=C==="none"?l:[...l].sort((n,u)=>C==="asc"?n.value-u.value:u.value-n.value),P=j.slice(0,f),q=j.slice(f);q.length>0&&P.push({key:"__other__",label:y??d.chartOther,value:q.reduce((n,u)=>n+u.value,0),color:pe,slot:-1,datum:{}}),P.length>z&&!G&&(G=!0,console.warn(`[@synertech/ui] A PieChart is drawing ${P.length} slices. Past ${z} the slices stop being tellable apart: lower \`maxSlices\`, or use a BarChart, which compares lengths rather than angles.`));let X=P.reduce((n,u)=>n+Math.max(0,u.value),0),W=0;return{slices:P.map(n=>{let u=X===0?0:Math.max(0,n.value)/X,ae=W;return W+=u*Math.PI*2,{...n,share:u,startAngle:ae,endAngle:W}}),total:X,rows:P.map(n=>({[r.key]:n.label,[o]:n.value}))}},[b,r.key,o,C,f,y,d.chartOther,U]),te=v===void 0?!0:v!==!1,F=typeof v=="string"?v:"bottom";return c(se,{title:N,description:p,height:L,width:T,size:A,loading:g,empty:K.length===0||Z===0,emptyState:m,error:$,errorState:S,onRetry:B,actions:M,tableView:h,legendPosition:F,legend:te?c(ie,{items:K.map(l=>({key:l.key,label:`${l.label} \xB7 ${Y(l.share,{locale:i})}`,color:l.color,...I?{pattern:l.slot}:{}})),position:F,marker:"rect",size:A}):void 0,table:h?c(he,{data:ee,series:[{key:o,label:r.label??o}],xKey:r.key,xLabel:r.label??r.key,formatValue:H,caption:typeof N=="string"?N:void 0}):void 0,className:t,...s,children:({width:l})=>c(Se,{width:l,height:L,slices:K,variant:R,innerRadius:x,showLabels:E,centerLabel:_,tooltip:k,patterns:I,patternBaseId:D,plotLabel:a,formatValue:H,locale:i,onSliceClick:e})})}function He(){G=!1}export{Ge as PieChart,He as resetPieWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var ne=Object.defineProperty;var
|
|
1
|
+
"use strict";"use client";var ne=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var Pe=(s,o)=>{for(var r in o)ne(s,r,{get:o[r],enumerable:!0})},Ve=(s,o,r,C)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of ve(o))!Se.call(s,m)&&m!==r&&ne(s,m,{get:()=>o[m],enumerable:!(C=ke(o,m))||C.enumerable});return s};var Re=s=>Ve(ne({},"__esModule",{value:!0}),s);var Ee={};Pe(Ee,{ScatterChart:()=>Ie,resetScatterWarnings:()=>Me});module.exports=Re(Ee);var g=require("react"),de=require("../../lib/i18n.cjs"),oe=require("../chart/ChartAxis.cjs"),me=require("../chart/ChartContainer.cjs"),he=require("../chart/ChartGrid.cjs"),fe=require("../chart/ChartLegend.cjs"),ge=require("../chart/ChartTableView.cjs"),J=require("../chart/ChartTooltip.cjs"),w=require("../chart/palette.cjs"),O=require("../chart/utils/cartesian.cjs"),G=require("../chart/utils/data.cjs"),Q=require("../chart/utils/decimate.cjs"),ae=require("../chart/utils/format.cjs"),X=require("../chart/utils/keyboard.cjs"),ye=require("../chart/utils/scales.cjs"),ie=require("../chart/utils/ticks.cjs"),pe=require("../chart/utils/timestamp.cjs"),xe=require("../chart/utils/touch.cjs"),i=require("react/jsx-runtime"),Le=4.5,we=48,se=!1;function ue(s){return`${s.index}:${s.seriesKey}`}function Te(s,o){return s.reduce((r,C)=>Math.abs(C.cx-o)<Math.abs(r.cx-o)?C:r)}var Ke=(0,g.memo)(function({points:o}){return(0,i.jsx)("g",{children:o.map(r=>(0,i.jsx)("circle",{cx:r.cx,cy:r.cy,r:r.r,fill:r.color,fillOpacity:.85,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${r.seriesKey}-${r.index}`))})});function Ae({width:s,height:o,data:r,resolvedSeries:C,x:m,y:$,grid:K,size:Y,bubble:k,trendLine:_,quadrants:W,pointRadius:D,overlay:z,maxPoints:A,margin:U,tooltip:I,onPointClick:M,plotLabel:Z,formatValue:T,formatX:E}){let[q,H]=(0,g.useState)(null),t=(0,g.useMemo)(()=>{let a=C.filter(u=>!u.hidden),x=a.map(u=>u.key),l=(0,O.buildCartesianGeometry)({width:s,height:o,data:r,x:{...m,scale:m.scale==="time"?"time":"linear"},y:$,bounds:(0,ie.extent)((0,G.collectAllValues)(r,x)),margin:U,formatValue:T,formatX:E}),R=k?(0,G.collectAllValues)(r,[k.key]):[],L=k?(0,ie.extent)(R):null,[c,d]=k?.range??[4,14],f=u=>{if(!k||!L)return D;let h=(0,G.readNumber)(u,k.key);if(h===null)return c;let[S,n]=L,y=n===S?1:(h-S)/(n-S);return Math.sqrt(c*c+y*(d*d-c*c))},b=[],v=[],N=[];a.forEach(u=>{let h=[];r.forEach((n,y)=>{let V=(0,G.readNumber)(n,u.key),p=l.categoryPositions[y];V===null||!Number.isFinite(p)||h.push({seriesKey:u.key,seriesLabel:(0,w.getSeriesLabel)(u),color:u.color,index:y,cx:p,cy:l.valueScale(V),r:f(n),xValue:l.toCategoryNumber(l.xValues[y]),yValue:V})}),A||(0,Q.warnPointBudget)("ScatterChart",h.length);let S=A&&A>0?(0,Q.sampleEvenly)(h,A):h;v.push(...h),b.push(...S),S.length>0&&N.push([...S].sort((n,y)=>n.cx-y.cx||n.index-y.index))});let j=null;if(_&&v.length>1){let u=v.length,h=v.reduce((p,P)=>p+P.xValue,0),S=v.reduce((p,P)=>p+P.yValue,0),n=v.reduce((p,P)=>p+P.xValue*P.yValue,0),y=v.reduce((p,P)=>p+P.xValue*P.xValue,0),V=u*y-h*h;if(V!==0){let p=(u*n-h*S)/V,P=(S-p*h)/u,le=v.map(re=>re.xValue),[be,Ce]=[Math.min(...le),Math.max(...le)],ce=v.map(re=>re.cx);j={x1:Math.min(...ce),y1:l.valueScale(p*be+P),x2:Math.max(...ce),y2:l.valueScale(p*Ce+P)}}}return{visible:a,points:b,tracks:N,marks:new Map(b.map(u=>[ue(u),u])),plot:(0,O.createPlotContext)({geometry:l,width:s,height:o,data:r,series:a,formatValue:T,formatX:E}),trend:j,xTicks:l.categoryTicks,yTicks:l.valueTicks,valueScale:l.valueScale,positions:l.categoryPositions,innerWidth:l.innerWidth,innerHeight:l.innerHeight,margin:l.margin,xValues:l.xValues}},[r,C,m,$,s,o,U,k,_,D,A,T,E]),e=q===null?null:t.marks.get(ue(q))??null,ee=(0,g.useCallback)(a=>{if(I===!1||t.points.length===0)return;let x=a.currentTarget.getBoundingClientRect(),l=a.clientX-x.left-t.margin.left,R=a.clientY-x.top-t.margin.top,L=null,c=we;for(let d of t.points){let f=Math.hypot(d.cx-l,d.cy-R);f<c&&(c=f,L=d)}H(L)},[I,t.points,t.margin]),B=(0,g.useCallback)(()=>{if(!M||!e)return;let a=r[e.index];a&&M({seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:T(e.yValue),datum:a,index:e.index,x:t.xValues[e.index]})},[M,e,T,r,t.xValues]),te=(0,g.useCallback)(a=>{let{tracks:x}=t;if(x.length===0||(0,X.pressChartMark)(a,M&&e?B:null))return;let l=e?x.findIndex(b=>b[0].seriesKey===e.seriesKey):-1,R=l<0?null:x[l],L=R&&e?R.indexOf(e):-1,c=R&&L>=0?{track:R,trackIndex:l,markIndex:L}:null,d=c?.track??x[0],f;switch(a.key){case"ArrowRight":f=d[(0,X.stepChartCursor)(c?.markIndex??null,1,d.length)];break;case"ArrowLeft":f=d[(0,X.stepChartCursor)(c?.markIndex??null,-1,d.length)];break;case"ArrowDown":case"ArrowUp":{if(!c||!e){f=d[0];break}let b=(0,X.stepChartCursor)(c.trackIndex,a.key==="ArrowDown"?1:-1,x.length);f=b===c.trackIndex?e:Te(x[b],e.cx);break}case"Home":f=d[0];break;case"End":f=d[d.length-1];break;case"Escape":f=null;break;default:return}a.preventDefault(),H(f)},[t,e,M,B]),F=(0,O.splitOverlay)(z);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("svg",{width:s,height:o,role:"img","aria-label":Z??t.visible.map(a=>(0,w.getSeriesLabel)(a)).join(", "),tabIndex:0,className:`${xe.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:ee,onPointerLeave:()=>H(null),onKeyDown:te,onBlur:()=>H(null),onClick:B,children:[(0,i.jsxs)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[(0,i.jsx)(he.ChartGrid,{width:t.innerWidth,height:t.innerHeight,horizontal:K==="y"||K==="both"?t.yTicks.map(a=>a.offset):void 0,vertical:K==="x"||K==="both"?t.xTicks.map(a=>a.offset):void 0}),W?.y!==void 0?(0,i.jsx)("line",{x1:0,y1:t.valueScale(W.y),x2:t.innerWidth,y2:t.valueScale(W.y),stroke:"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:"4 4"}):null,F.under?.(t.plot),t.trend?(0,i.jsx)("line",{x1:t.trend.x1,y1:t.trend.y1,x2:t.trend.x2,y2:t.trend.y2,stroke:"var(--color-chart-muted)",strokeWidth:1.5,strokeDasharray:"4 4"}):null,(0,i.jsx)(Ke,{points:t.points}),F.over?.(t.plot),e?(0,i.jsx)("circle",{cx:e.cx,cy:e.cy,r:e.r+3,fill:"none",stroke:e.color,strokeWidth:2,"aria-hidden":"true"}):null]}),(0,i.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:m.hidden?null:(0,i.jsx)(oe.ChartAxis,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:m.label,size:Y})}),(0,i.jsx)("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:$?.hidden?null:(0,i.jsx)(oe.ChartAxis,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:$?.label,size:Y})})]}),e&&r[e.index]&&I!==!1?(0,i.jsx)(J.ChartTooltip,{x:t.margin.left+e.cx,y:t.margin.top+e.cy,containerWidth:s,children:typeof I=="function"?I({x:t.xValues[e.index],xLabel:E(t.xValues[e.index],e.index),index:e.index,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:T(e.yValue),datum:r[e.index]}]}):(0,i.jsx)(J.ChartTooltipContent,{title:`${m.label??m.key} ${E(t.xValues[e.index],e.index)}`,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:T(e.yValue),datum:r[e.index]}]})}):null]})}function Ie({data:s,series:o,x:r,y:C,height:m=280,width:$,size:K="md",grid:Y="both",legend:k,tooltip:_=!0,tableView:W=!1,emphasis:D,title:z,description:A,loading:U=!1,emptyState:I,error:M=!1,errorState:Z,onRetry:T,actions:E,onPointClick:q,bubble:H,trendLine:t=!1,quadrants:e,pointRadius:ee=Le,overlay:B,legendToggle:te=!0,maxPoints:F,margin:a,locale:x,plotLabel:l,className:R,...L}){let c=(0,de.useUILocale)(x),[d,f]=(0,g.useState)(()=>new Set);o.length>w.CHART_ALL_PAIRS_LIMIT&&!se&&(se=!0,console.warn(`[@synertech/ui] A ScatterChart was given ${o.length} series. Any two marks can sit side by side here, and only the first ${w.CHART_ALL_PAIRS_LIMIT} palette slots stay tellable apart under that test: facet the chart instead.`));let b=(0,g.useMemo)(()=>o.map((n,y)=>({...n,hidden:n.hidden||d.has(n.key),color:(0,w.resolveSeriesColor)(n,y,D)})),[o,d,D]),v=(0,g.useMemo)(()=>C?.format??(n=>(0,ae.formatAuto)(n,c)),[C?.format,c]),N=(0,g.useMemo)(()=>r.format??(n=>r.scale==="time"?(0,pe.formatTimeValue)(n,c):(0,ae.formatAuto)((0,ye.toNumber)(n),c)),[r.format,r.scale,c]),j=(0,g.useCallback)(n=>{f(y=>{let V=new Set(y);return V.has(n)?V.delete(n):V.add(n),V})},[]),u=k===void 0?o.length>=2:k!==!1,h=typeof k=="string"?k:"bottom",S=b.filter(n=>!n.hidden).length;return(0,i.jsx)(me.ChartContainer,{title:z,description:A,height:m,width:$,size:K,loading:U,empty:s.length===0||S===0,emptyState:I,error:M,errorState:Z,onRetry:T,actions:E,tableView:W,legendPosition:h,legend:u?(0,i.jsx)(fe.ChartLegend,{items:(0,w.toLegendItems)(b,D),position:h,marker:"dot",size:K,onToggle:te?j:void 0}):void 0,table:W?(0,i.jsx)(ge.ChartTableView,{data:s,series:b,xKey:r.key,xLabel:r.label??r.key,formatX:N,formatValue:v,caption:typeof z=="string"?z:void 0}):void 0,className:R,...L,children:({width:n})=>(0,i.jsx)(Ae,{width:n,height:m,data:s,resolvedSeries:b,x:r,y:C,grid:Y,size:K,bubble:H,trendLine:t,quadrants:e,pointRadius:ee,overlay:B,maxPoints:F,margin:a,tooltip:_,onPointClick:q,plotLabel:l,formatValue:v,formatX:N})})}function Me(){se=!1}0&&(module.exports={ScatterChart,resetScatterWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as fe,useCallback as _,useMemo as U,useState as de}from"react";import{ChartAxis as ne}from"../chart/ChartAxis.js";import{ChartContainer as
|
|
1
|
+
"use client";import{memo as fe,useCallback as _,useMemo as U,useState as de}from"react";import{useUILocale as ge}from"../../lib/i18n.js";import{ChartAxis as ne}from"../chart/ChartAxis.js";import{ChartContainer as ye}from"../chart/ChartContainer.js";import{ChartGrid as pe}from"../chart/ChartGrid.js";import{ChartLegend as xe}from"../chart/ChartLegend.js";import{ChartTableView as be}from"../chart/ChartTableView.js";import{ChartTooltip as Ce,ChartTooltipContent as ke}from"../chart/ChartTooltip.js";import{CHART_ALL_PAIRS_LIMIT as oe,getSeriesLabel as ae,resolveSeriesColor as ve,toLegendItems as Se}from"../chart/palette.js";import{buildCartesianGeometry as Pe,createPlotContext as Ve,splitOverlay as Re}from"../chart/utils/cartesian.js";import{collectAllValues as ie,readNumber as se}from"../chart/utils/data.js";import{sampleEvenly as Le,warnPointBudget as we}from"../chart/utils/decimate.js";import{formatAuto as le}from"../chart/utils/format.js";import{pressChartMark as Te,stepChartCursor as Q}from"../chart/utils/keyboard.js";import{toNumber as Ke}from"../chart/utils/scales.js";import{extent as ce}from"../chart/utils/ticks.js";import{formatTimeValue as Ae}from"../chart/utils/timestamp.js";import{CHART_TOUCH as Ie}from"../chart/utils/touch.js";import{Fragment as He,jsx as c,jsxs as Z}from"react/jsx-runtime";var Me=4.5,Ee=48,ee=!1;function ue(d){return`${d.index}:${d.seriesKey}`}function $e(d,m){return d.reduce((r,R)=>Math.abs(R.cx-m)<Math.abs(r.cx-m)?R:r)}var We=fe(function({points:m}){return c("g",{children:m.map(r=>c("circle",{cx:r.cx,cy:r.cy,r:r.r,fill:r.color,fillOpacity:.85,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${r.seriesKey}-${r.index}`))})});function De({width:d,height:m,data:r,resolvedSeries:R,x:S,y:M,grid:w,size:G,bubble:x,trendLine:O,quadrants:E,pointRadius:$,overlay:D,maxPoints:T,margin:z,tooltip:K,onPointClick:A,plotLabel:q,formatValue:L,formatX:I}){let[B,W]=de(null),t=U(()=>{let o=R.filter(s=>!s.hidden),y=o.map(s=>s.key),a=Pe({width:d,height:m,data:r,x:{...S,scale:S.scale==="time"?"time":"linear"},y:M,bounds:ce(ie(r,y)),margin:z,formatValue:L,formatX:I}),P=x?ie(r,[x.key]):[],V=x?ce(P):null,[i,l]=x?.range??[4,14],h=s=>{if(!x||!V)return $;let u=se(s,x.key);if(u===null)return i;let[C,n]=V,f=n===C?1:(u-C)/(n-C);return Math.sqrt(i*i+f*(l*l-i*i))},p=[],b=[],X=[];o.forEach(s=>{let u=[];r.forEach((n,f)=>{let v=se(n,s.key),g=a.categoryPositions[f];v===null||!Number.isFinite(g)||u.push({seriesKey:s.key,seriesLabel:ae(s),color:s.color,index:f,cx:g,cy:a.valueScale(v),r:h(n),xValue:a.toCategoryNumber(a.xValues[f]),yValue:v})}),T||we("ScatterChart",u.length);let C=T&&T>0?Le(u,T):u;b.push(...u),p.push(...C),C.length>0&&X.push([...C].sort((n,f)=>n.cx-f.cx||n.index-f.index))});let Y=null;if(O&&b.length>1){let s=b.length,u=b.reduce((g,k)=>g+k.xValue,0),C=b.reduce((g,k)=>g+k.yValue,0),n=b.reduce((g,k)=>g+k.xValue*k.yValue,0),f=b.reduce((g,k)=>g+k.xValue*k.xValue,0),v=s*f-u*u;if(v!==0){let g=(s*n-u*C)/v,k=(C-g*u)/s,te=b.map(J=>J.xValue),[me,he]=[Math.min(...te),Math.max(...te)],re=b.map(J=>J.cx);Y={x1:Math.min(...re),y1:a.valueScale(g*me+k),x2:Math.max(...re),y2:a.valueScale(g*he+k)}}}return{visible:o,points:p,tracks:X,marks:new Map(p.map(s=>[ue(s),s])),plot:Ve({geometry:a,width:d,height:m,data:r,series:o,formatValue:L,formatX:I}),trend:Y,xTicks:a.categoryTicks,yTicks:a.valueTicks,valueScale:a.valueScale,positions:a.categoryPositions,innerWidth:a.innerWidth,innerHeight:a.innerHeight,margin:a.margin,xValues:a.xValues}},[r,R,S,M,d,m,z,x,O,$,T,L,I]),e=B===null?null:t.marks.get(ue(B))??null,F=_(o=>{if(K===!1||t.points.length===0)return;let y=o.currentTarget.getBoundingClientRect(),a=o.clientX-y.left-t.margin.left,P=o.clientY-y.top-t.margin.top,V=null,i=Ee;for(let l of t.points){let h=Math.hypot(l.cx-a,l.cy-P);h<i&&(i=h,V=l)}W(V)},[K,t.points,t.margin]),H=_(()=>{if(!A||!e)return;let o=r[e.index];o&&A({seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:o,index:e.index,x:t.xValues[e.index]})},[A,e,L,r,t.xValues]),j=_(o=>{let{tracks:y}=t;if(y.length===0||Te(o,A&&e?H:null))return;let a=e?y.findIndex(p=>p[0].seriesKey===e.seriesKey):-1,P=a<0?null:y[a],V=P&&e?P.indexOf(e):-1,i=P&&V>=0?{track:P,trackIndex:a,markIndex:V}:null,l=i?.track??y[0],h;switch(o.key){case"ArrowRight":h=l[Q(i?.markIndex??null,1,l.length)];break;case"ArrowLeft":h=l[Q(i?.markIndex??null,-1,l.length)];break;case"ArrowDown":case"ArrowUp":{if(!i||!e){h=l[0];break}let p=Q(i.trackIndex,o.key==="ArrowDown"?1:-1,y.length);h=p===i.trackIndex?e:$e(y[p],e.cx);break}case"Home":h=l[0];break;case"End":h=l[l.length-1];break;case"Escape":h=null;break;default:return}o.preventDefault(),W(h)},[t,e,A,H]),N=Re(D);return Z(He,{children:[Z("svg",{width:d,height:m,role:"img","aria-label":q??t.visible.map(o=>ae(o)).join(", "),tabIndex:0,className:`${Ie} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:F,onPointerLeave:()=>W(null),onKeyDown:j,onBlur:()=>W(null),onClick:H,children:[Z("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:[c(pe,{width:t.innerWidth,height:t.innerHeight,horizontal:w==="y"||w==="both"?t.yTicks.map(o=>o.offset):void 0,vertical:w==="x"||w==="both"?t.xTicks.map(o=>o.offset):void 0}),E?.y!==void 0?c("line",{x1:0,y1:t.valueScale(E.y),x2:t.innerWidth,y2:t.valueScale(E.y),stroke:"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:"4 4"}):null,N.under?.(t.plot),t.trend?c("line",{x1:t.trend.x1,y1:t.trend.y1,x2:t.trend.x2,y2:t.trend.y2,stroke:"var(--color-chart-muted)",strokeWidth:1.5,strokeDasharray:"4 4"}):null,c(We,{points:t.points}),N.over?.(t.plot),e?c("circle",{cx:e.cx,cy:e.cy,r:e.r+3,fill:"none",stroke:e.color,strokeWidth:2,"aria-hidden":"true"}):null]}),c("g",{transform:`translate(${t.margin.left}, ${t.margin.top+t.innerHeight})`,children:S.hidden?null:c(ne,{orientation:"bottom",ticks:t.xTicks,length:t.innerWidth,label:S.label,size:G})}),c("g",{transform:`translate(${t.margin.left}, ${t.margin.top})`,children:M?.hidden?null:c(ne,{orientation:"left",ticks:t.yTicks,length:t.innerHeight,showLine:!1,label:M?.label,size:G})})]}),e&&r[e.index]&&K!==!1?c(Ce,{x:t.margin.left+e.cx,y:t.margin.top+e.cy,containerWidth:d,children:typeof K=="function"?K({x:t.xValues[e.index],xLabel:I(t.xValues[e.index],e.index),index:e.index,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:r[e.index]}]}):c(ke,{title:`${S.label??S.key} ${I(t.xValues[e.index],e.index)}`,points:[{seriesKey:e.seriesKey,seriesLabel:e.seriesLabel,color:e.color,value:e.yValue,formattedValue:L(e.yValue),datum:r[e.index]}]})}):null]})}function nt({data:d,series:m,x:r,y:R,height:S=280,width:M,size:w="md",grid:G="both",legend:x,tooltip:O=!0,tableView:E=!1,emphasis:$,title:D,description:T,loading:z=!1,emptyState:K,error:A=!1,errorState:q,onRetry:L,actions:I,onPointClick:B,bubble:W,trendLine:t=!1,quadrants:e,pointRadius:F=Me,overlay:H,legendToggle:j=!0,maxPoints:N,margin:o,locale:y,plotLabel:a,className:P,...V}){let i=ge(y),[l,h]=de(()=>new Set);m.length>oe&&!ee&&(ee=!0,console.warn(`[@synertech/ui] A ScatterChart was given ${m.length} series. Any two marks can sit side by side here, and only the first ${oe} palette slots stay tellable apart under that test: facet the chart instead.`));let p=U(()=>m.map((n,f)=>({...n,hidden:n.hidden||l.has(n.key),color:ve(n,f,$)})),[m,l,$]),b=U(()=>R?.format??(n=>le(n,i)),[R?.format,i]),X=U(()=>r.format??(n=>r.scale==="time"?Ae(n,i):le(Ke(n),i)),[r.format,r.scale,i]),Y=_(n=>{h(f=>{let v=new Set(f);return v.has(n)?v.delete(n):v.add(n),v})},[]),s=x===void 0?m.length>=2:x!==!1,u=typeof x=="string"?x:"bottom",C=p.filter(n=>!n.hidden).length;return c(ye,{title:D,description:T,height:S,width:M,size:w,loading:z,empty:d.length===0||C===0,emptyState:K,error:A,errorState:q,onRetry:L,actions:I,tableView:E,legendPosition:u,legend:s?c(xe,{items:Se(p,$),position:u,marker:"dot",size:w,onToggle:j?Y:void 0}):void 0,table:E?c(be,{data:d,series:p,xKey:r.key,xLabel:r.label??r.key,formatX:X,formatValue:b,caption:typeof D=="string"?D:void 0}):void 0,className:P,...V,children:({width:n})=>c(De,{width:n,height:S,data:d,resolvedSeries:p,x:r,y:R,grid:G,size:w,bubble:W,trendLine:t,quadrants:e,pointRadius:F,overlay:H,maxPoints:N,margin:o,tooltip:O,onPointClick:B,plotLabel:a,formatValue:b,formatX:X})})}function ot(){ee=!1}export{nt as ScatterChart,ot as resetScatterWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var T=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var ee=(t,r)=>{for(var a in r)T(t,a,{get:r[a],enumerable:!0})},te=(t,r,a,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Z(r))!_.call(t,s)&&s!==a&&T(t,s,{get:()=>r[s],enumerable:!(n=K(r,s))||n.enumerable});return t};var re=t=>te(T({},"__esModule",{value:!0}),t);var ge={};ee(ge,{Sidebar:()=>se,SidebarContent:()=>de,SidebarFooter:()=>ce,SidebarGroup:()=>ue,SidebarHeader:()=>le,SidebarItem:()=>pe,SidebarSubMenu:()=>be,SidebarToggle:()=>fe,useSidebar:()=>ae});module.exports=re(ge);var o=require("react"),j=require("../../hooks/useDialogA11y.cjs"),i=require("../../lib/cn.cjs"),M=require("../../lib/i18n.cjs"),e=require("react/jsx-runtime"),E=(0,o.createContext)(null);function v(){let t=(0,o.useContext)(E);if(!t)throw new Error("Sidebar sub-components must be used within <Sidebar>");return t}function ae(){return v()}var oe=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})}),ne=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),ie=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-5 h-5",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})});function B({text:t,position:r,children:a}){let[n,s]=(0,o.useState)(!1),[c,f]=(0,o.useState)({top:0,left:0}),u=(0,o.useRef)(null);return(0,e.jsxs)("div",{ref:u,onMouseEnter:()=>{if(u.current){let d=u.current.getBoundingClientRect();f({top:d.top+d.height/2,left:r==="left"?d.right+8:d.left-8})}s(!0)},onMouseLeave:()=>s(!1),className:"relative",children:[a,n&&(0,e.jsx)("div",{className:(0,i.cn)("fixed z-[9999] px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900 dark:bg-gray-700 rounded-md shadow-lg whitespace-nowrap pointer-events-none",r==="right"&&"-translate-x-full"),style:{top:c.top,left:c.left,transform:`translateY(-50%)${r==="right"?" translateX(-100%)":""}`},role:"tooltip",children:t})]})}function se({collapsed:t,defaultCollapsed:r=!1,onCollapsedChange:a,expandedWidth:n=260,collapsedWidth:s=64,position:c="left",variant:f="default",mobileBreakpoint:u=768,mobileOpen:x,onMobileOpenChange:d,className:m,"aria-label":p,closeLabel:N,trapFocus:g=!0,initialFocus:S,returnFocus:w,lockScroll:C=!0,children:O}){let G=(0,M.useUILabels)(),D=(0,o.useRef)(null),F=(0,o.useRef)(null),[q,Q]=(0,o.useState)(r),[W,R]=(0,o.useState)(!1),[b,$]=(0,o.useState)(!1),L=t!==void 0,k=L?t:q,y=x!==void 0,h=y?x:W;(0,o.useEffect)(()=>{if(typeof window.matchMedia!="function")return;let l=window.matchMedia(`(max-width: ${u}px)`),I=A=>{$(A.matches),A.matches||(y||R(!1),d?.(!1))};return I(l),l.addEventListener("change",I),()=>l.removeEventListener("change",I)},[u,y,d]);let U=(0,o.useCallback)(()=>{if(b){let l=!h;y||R(l),d?.(l)}else{let l=!k;L||Q(l),a?.(l)}},[b,h,k,y,L,d,a]),P=(0,o.useCallback)(()=>{y||R(!1),d?.(!1)},[y,d]);(0,o.useEffect)(()=>{let l=F.current;l&&(b&&!h?(l.setAttribute("inert",""),l.setAttribute("aria-hidden","true")):(l.removeAttribute("inert"),l.removeAttribute("aria-hidden")))},[b,h]);let{dialogRef:X,dialogProps:Y}=(0,j.useDialogA11y)({open:b&&h,onClose:P,trapFocus:g,initialFocus:S,returnFocus:w,lockScroll:C,keepInteractive:[D]}),J={default:"bg-white dark:bg-gray-900",bordered:(0,i.cn)("bg-white dark:bg-gray-900",c==="left"?"border-r border-gray-200 dark:border-gray-700":"border-l border-gray-200 dark:border-gray-700"),floating:"bg-white dark:bg-gray-900 m-3 rounded-xl shadow-xl border border-gray-200 dark:border-gray-700"},H=k&&!b?s:n,V=(0,e.jsx)("aside",{className:(0,i.cn)("flex flex-col h-full overflow-hidden transition-[width] duration-200 ease-in-out",J[f],m),style:{width:b?n:H,minWidth:b?n:H},"data-testid":"sidebar","data-collapsed":k&&!b,"data-mobile":b,"data-position":c,children:O}),z={collapsed:k&&!b,isMobile:b,mobileOpen:h,position:c,variant:f,expandedWidth:n,collapsedWidth:s,toggle:U,closeMobile:P,closeLabel:N};return b?(0,e.jsxs)(E.Provider,{value:z,children:[h&&(0,e.jsx)("div",{ref:D,className:"fixed inset-0 z-40 bg-black/50 transition-opacity",onClick:P,"aria-hidden":"true","data-testid":"sidebar-overlay"}),(0,e.jsx)("div",{ref:l=>{F.current=l,X.current=l},...Y,"aria-label":p??G.sidebar,className:(0,i.cn)("fixed top-0 z-50 h-full transition-transform duration-200 ease-in-out focus:outline-none",c==="left"?"left-0":"right-0",h?"translate-x-0":c==="left"?"-translate-x-full":"translate-x-full"),children:V})]}):(0,e.jsx)(E.Provider,{value:z,children:V})}function le({className:t,children:r}){let a=v(),n=(0,M.useUILabels)();return(0,e.jsxs)("div",{className:(0,i.cn)("flex items-center shrink-0 px-4 h-14 overflow-hidden",a.collapsed&&"justify-center px-2",t),"data-testid":"sidebar-header",children:[r,a.isMobile&&a.mobileOpen&&(0,e.jsx)("button",{type:"button",onClick:a.closeMobile,className:"ml-auto p-1 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer","aria-label":a.closeLabel??n.closeSidebar,children:(0,e.jsx)(ie,{})})]})}function de({className:t,children:r}){return(0,e.jsx)("div",{className:(0,i.cn)("flex-1 overflow-y-auto overflow-x-hidden py-2",t),"data-testid":"sidebar-content",children:r})}function ce({className:t,children:r}){let a=v();return(0,e.jsx)("div",{className:(0,i.cn)("shrink-0 border-t border-gray-200 dark:border-gray-700 px-4 py-3 overflow-hidden",a.collapsed&&"px-2 flex justify-center",t),"data-testid":"sidebar-footer",children:r})}function ue({label:t,className:r,children:a}){let n=v();return(0,e.jsxs)("div",{className:(0,i.cn)("py-2",r),"data-testid":"sidebar-group",children:[t&&!n.collapsed&&(0,e.jsx)("div",{className:"px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400",children:t}),t&&n.collapsed&&(0,e.jsx)("div",{className:"mx-auto my-1 w-6 border-t border-gray-200 dark:border-gray-700"}),(0,e.jsx)("div",{className:"space-y-0.5 px-2",children:a})]})}function pe({icon:t,label:r,badge:a,badgeColor:n="bg-synertech-primary-600 text-synertech-on-primary",active:s=!1,disabled:c=!1,href:f,onClick:u,tooltip:x,className:d}){let m=v(),p=m.collapsed,N=x??r,g=(0,e.jsxs)(e.Fragment,{children:[t&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 w-5 h-5",p&&"w-5 h-5"),children:t}),!p&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"flex-1 truncate",children:r}),a!=null&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1",n),children:a})]}),p&&a!==void 0&&a!==null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-synertech-primary-600"})]}),S=(0,i.cn)("relative flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full",p?"justify-center px-2 py-2.5":"px-3 py-2",s?"bg-synertech-primary-50 text-synertech-primary-700 dark:bg-synertech-primary-900/30 dark:text-synertech-primary-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",c&&"opacity-50 pointer-events-none",!c&&"cursor-pointer",d),w=()=>{c||(u?.(),m.isMobile&&m.closeMobile())},C=f?(0,e.jsx)("a",{href:c?void 0:f,className:S,onClick:w,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g}):(0,e.jsx)("button",{type:"button",className:S,onClick:w,disabled:c,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g});return p?(0,e.jsx)(B,{text:N,position:m.position,children:C}):C}function be({icon:t,label:r,badge:a,defaultOpen:n=!1,className:s,children:c}){let f=v(),[u,x]=(0,o.useState)(n),d=(0,o.useRef)(null),[m,p]=(0,o.useState)(n?void 0:0),N=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{if(N.current){N.current=!1,p(u?void 0:0);return}if(u){let g=d.current;if(g){p(g.scrollHeight);let S=setTimeout(()=>p(void 0),200);return()=>clearTimeout(S)}}else{let g=d.current;g&&(p(g.scrollHeight),requestAnimationFrame(()=>p(0)))}},[u]),f.collapsed?(0,e.jsx)(B,{text:r,position:f.position,children:(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("relative flex items-center justify-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-2 py-2.5","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer",s),onClick:()=>{f.toggle(),x(!0)},"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),a!=null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-synertech-primary-600"})]})}):(0,e.jsxs)("div",{className:s,"data-testid":"sidebar-submenu",children:[(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-3 py-2","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"),onClick:()=>x(!u),"aria-expanded":u,"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),(0,e.jsx)("span",{className:"flex-1 truncate text-left",children:r}),a!=null&&(0,e.jsx)("span",{className:"shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1 bg-synertech-primary-600 text-synertech-on-primary",children:a}),(0,e.jsx)(ne,{className:(0,i.cn)("shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-200",u&&"rotate-180")})]}),(0,e.jsx)("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:m===void 0?"auto":m},children:(0,e.jsx)("div",{ref:d,className:"pl-4 py-0.5",children:c})})]})}function fe({className:t}){let r=v(),a=(0,M.useUILabels)(),n=r.isMobile?r.mobileOpen?r.closeLabel??a.closeSidebar:a.openSidebar:r.collapsed?a.expandSidebar:a.collapseSidebar;return(0,e.jsx)("button",{type:"button",onClick:r.toggle,className:(0,i.cn)("p-1.5 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer",t),"aria-label":n,"data-testid":"sidebar-toggle",children:(0,e.jsx)(oe,{className:(0,i.cn)("transition-transform duration-200",r.collapsed&&"rotate-180",r.position==="right"&&!r.collapsed&&"rotate-180",r.position==="right"&&r.collapsed&&"rotate-0")})})}0&&(module.exports={Sidebar,SidebarContent,SidebarFooter,SidebarGroup,SidebarHeader,SidebarItem,SidebarSubMenu,SidebarToggle,useSidebar});
|
|
1
|
+
"use strict";"use client";var E=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(t,r)=>{for(var a in r)E(t,a,{get:r[a],enumerable:!0})},re=(t,r,a,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of _(r))!ee.call(t,s)&&s!==a&&E(t,s,{get:()=>r[s],enumerable:!(n=Z(r,s))||n.enumerable});return t};var ae=t=>re(E({},"__esModule",{value:!0}),t);var me={};te(me,{Sidebar:()=>le,SidebarContent:()=>ce,SidebarFooter:()=>ue,SidebarGroup:()=>pe,SidebarHeader:()=>de,SidebarItem:()=>be,SidebarSubMenu:()=>fe,SidebarToggle:()=>ge,useSidebar:()=>oe});module.exports=ae(me);var o=require("react"),B=require("../../hooks/useDialogA11y.cjs"),i=require("../../lib/cn.cjs"),O=require("../../lib/safe-href.cjs"),R=require("../../lib/i18n.cjs"),e=require("react/jsx-runtime"),H=(0,o.createContext)(null);function v(){let t=(0,o.useContext)(H);if(!t)throw new Error("Sidebar sub-components must be used within <Sidebar>");return t}function oe(){return v()}var ne=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})}),ie=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),se=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-5 h-5",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})});function G({text:t,position:r,children:a}){let[n,s]=(0,o.useState)(!1),[c,f]=(0,o.useState)({top:0,left:0}),u=(0,o.useRef)(null);return(0,e.jsxs)("div",{ref:u,onMouseEnter:()=>{if(u.current){let d=u.current.getBoundingClientRect();f({top:d.top+d.height/2,left:r==="left"?d.right+8:d.left-8})}s(!0)},onMouseLeave:()=>s(!1),className:"relative",children:[a,n&&(0,e.jsx)("div",{className:(0,i.cn)("fixed z-[9999] px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900 dark:bg-gray-700 rounded-md shadow-lg whitespace-nowrap pointer-events-none",r==="right"&&"-translate-x-full"),style:{top:c.top,left:c.left,transform:`translateY(-50%)${r==="right"?" translateX(-100%)":""}`},role:"tooltip",children:t})]})}function le({collapsed:t,defaultCollapsed:r=!1,onCollapsedChange:a,expandedWidth:n=260,collapsedWidth:s=64,position:c="left",variant:f="default",mobileBreakpoint:u=768,mobileOpen:x,onMobileOpenChange:d,className:m,"aria-label":p,closeLabel:N,trapFocus:g=!0,initialFocus:S,returnFocus:w,lockScroll:C=!0,children:M}){let q=(0,R.useUILabels)(),D=(0,o.useRef)(null),F=(0,o.useRef)(null),[Q,W]=(0,o.useState)(r),[$,L]=(0,o.useState)(!1),[b,U]=(0,o.useState)(!1),P=t!==void 0,k=P?t:Q,y=x!==void 0,h=y?x:$;(0,o.useEffect)(()=>{if(typeof window.matchMedia!="function")return;let l=window.matchMedia(`(max-width: ${u}px)`),T=j=>{U(j.matches),j.matches||(y||L(!1),d?.(!1))};return T(l),l.addEventListener("change",T),()=>l.removeEventListener("change",T)},[u,y,d]);let X=(0,o.useCallback)(()=>{if(b){let l=!h;y||L(l),d?.(l)}else{let l=!k;P||W(l),a?.(l)}},[b,h,k,y,P,d,a]),I=(0,o.useCallback)(()=>{y||L(!1),d?.(!1)},[y,d]);(0,o.useEffect)(()=>{let l=F.current;l&&(b&&!h?(l.setAttribute("inert",""),l.setAttribute("aria-hidden","true")):(l.removeAttribute("inert"),l.removeAttribute("aria-hidden")))},[b,h]);let{dialogRef:Y,dialogProps:J}=(0,B.useDialogA11y)({open:b&&h,onClose:I,trapFocus:g,initialFocus:S,returnFocus:w,lockScroll:C,keepInteractive:[D]}),K={default:"bg-white dark:bg-gray-900",bordered:(0,i.cn)("bg-white dark:bg-gray-900",c==="left"?"border-r border-gray-200 dark:border-gray-700":"border-l border-gray-200 dark:border-gray-700"),floating:"bg-white dark:bg-gray-900 m-3 rounded-xl shadow-xl border border-gray-200 dark:border-gray-700"},V=k&&!b?s:n,z=(0,e.jsx)("aside",{className:(0,i.cn)("flex flex-col h-full overflow-hidden transition-[width] duration-200 ease-in-out",K[f],m),style:{width:b?n:V,minWidth:b?n:V},"data-testid":"sidebar","data-collapsed":k&&!b,"data-mobile":b,"data-position":c,children:M}),A={collapsed:k&&!b,isMobile:b,mobileOpen:h,position:c,variant:f,expandedWidth:n,collapsedWidth:s,toggle:X,closeMobile:I,closeLabel:N};return b?(0,e.jsxs)(H.Provider,{value:A,children:[h&&(0,e.jsx)("div",{ref:D,className:"fixed inset-0 z-40 bg-black/50 transition-opacity",onClick:I,"aria-hidden":"true","data-testid":"sidebar-overlay"}),(0,e.jsx)("div",{ref:l=>{F.current=l,Y.current=l},...J,"aria-label":p??q.sidebar,className:(0,i.cn)("fixed top-0 z-50 h-full transition-transform duration-200 ease-in-out focus:outline-none",c==="left"?"left-0":"right-0",h?"translate-x-0":c==="left"?"-translate-x-full":"translate-x-full"),children:z})]}):(0,e.jsx)(H.Provider,{value:A,children:z})}function de({className:t,children:r}){let a=v(),n=(0,R.useUILabels)();return(0,e.jsxs)("div",{className:(0,i.cn)("flex items-center shrink-0 px-4 h-14 overflow-hidden",a.collapsed&&"justify-center px-2",t),"data-testid":"sidebar-header",children:[r,a.isMobile&&a.mobileOpen&&(0,e.jsx)("button",{type:"button",onClick:a.closeMobile,className:"ml-auto p-1 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer","aria-label":a.closeLabel??n.closeSidebar,children:(0,e.jsx)(se,{})})]})}function ce({className:t,children:r}){return(0,e.jsx)("div",{className:(0,i.cn)("flex-1 overflow-y-auto overflow-x-hidden py-2",t),"data-testid":"sidebar-content",children:r})}function ue({className:t,children:r}){let a=v();return(0,e.jsx)("div",{className:(0,i.cn)("shrink-0 border-t border-gray-200 dark:border-gray-700 px-4 py-3 overflow-hidden",a.collapsed&&"px-2 flex justify-center",t),"data-testid":"sidebar-footer",children:r})}function pe({label:t,className:r,children:a}){let n=v();return(0,e.jsxs)("div",{className:(0,i.cn)("py-2",r),"data-testid":"sidebar-group",children:[t&&!n.collapsed&&(0,e.jsx)("div",{className:"px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400",children:t}),t&&n.collapsed&&(0,e.jsx)("div",{className:"mx-auto my-1 w-6 border-t border-gray-200 dark:border-gray-700"}),(0,e.jsx)("div",{className:"space-y-0.5 px-2",children:a})]})}function be({icon:t,label:r,badge:a,badgeColor:n="bg-synertech-primary-600 text-synertech-on-primary",active:s=!1,disabled:c=!1,href:f,onClick:u,tooltip:x,className:d}){let m=v(),p=m.collapsed,N=x??r,g=(0,e.jsxs)(e.Fragment,{children:[t&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 w-5 h-5",p&&"w-5 h-5"),children:t}),!p&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"flex-1 truncate",children:r}),a!=null&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1",n),children:a})]}),p&&a!==void 0&&a!==null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-synertech-primary-600"})]}),S=(0,i.cn)("relative flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full",p?"justify-center px-2 py-2.5":"px-3 py-2",s?"bg-synertech-primary-50 text-synertech-primary-700 dark:bg-synertech-primary-900/30 dark:text-synertech-primary-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",c&&"opacity-50 pointer-events-none",!c&&"cursor-pointer",d),w=()=>{c||(u?.(),m.isMobile&&m.closeMobile())},C=(0,O.componentHref)("SidebarItem",f),M=C?(0,e.jsx)("a",{href:c?void 0:C,className:S,onClick:w,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g}):(0,e.jsx)("button",{type:"button",className:S,onClick:w,disabled:c,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g});return p?(0,e.jsx)(G,{text:N,position:m.position,children:M}):M}function fe({icon:t,label:r,badge:a,defaultOpen:n=!1,className:s,children:c}){let f=v(),[u,x]=(0,o.useState)(n),d=(0,o.useRef)(null),[m,p]=(0,o.useState)(n?void 0:0),N=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{if(N.current){N.current=!1,p(u?void 0:0);return}if(u){let g=d.current;if(g){p(g.scrollHeight);let S=setTimeout(()=>p(void 0),200);return()=>clearTimeout(S)}}else{let g=d.current;g&&(p(g.scrollHeight),requestAnimationFrame(()=>p(0)))}},[u]),f.collapsed?(0,e.jsx)(G,{text:r,position:f.position,children:(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("relative flex items-center justify-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-2 py-2.5","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer",s),onClick:()=>{f.toggle(),x(!0)},"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),a!=null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-synertech-primary-600"})]})}):(0,e.jsxs)("div",{className:s,"data-testid":"sidebar-submenu",children:[(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-3 py-2","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"),onClick:()=>x(!u),"aria-expanded":u,"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),(0,e.jsx)("span",{className:"flex-1 truncate text-left",children:r}),a!=null&&(0,e.jsx)("span",{className:"shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1 bg-synertech-primary-600 text-synertech-on-primary",children:a}),(0,e.jsx)(ie,{className:(0,i.cn)("shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-200",u&&"rotate-180")})]}),(0,e.jsx)("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:m===void 0?"auto":m},children:(0,e.jsx)("div",{ref:d,className:"pl-4 py-0.5",children:c})})]})}function ge({className:t}){let r=v(),a=(0,R.useUILabels)(),n=r.isMobile?r.mobileOpen?r.closeLabel??a.closeSidebar:a.openSidebar:r.collapsed?a.expandSidebar:a.collapseSidebar;return(0,e.jsx)("button",{type:"button",onClick:r.toggle,className:(0,i.cn)("p-1.5 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer",t),"aria-label":n,"data-testid":"sidebar-toggle",children:(0,e.jsx)(ne,{className:(0,i.cn)("transition-transform duration-200",r.collapsed&&"rotate-180",r.position==="right"&&!r.collapsed&&"rotate-180",r.position==="right"&&r.collapsed&&"rotate-0")})})}0&&(module.exports={Sidebar,SidebarContent,SidebarFooter,SidebarGroup,SidebarHeader,SidebarItem,SidebarSubMenu,SidebarToggle,useSidebar});
|