@gv-tech/design-system 2.29.5 → 2.30.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/README.md CHANGED
@@ -46,43 +46,41 @@ The design system includes a Vite-based playground site. Run it locally with `bu
46
46
 
47
47
  ## Install
48
48
 
49
- The public package is published as `@gv-tech/design-system`:
49
+ Pick one path. `@gv-tech/ui-web`, `@gv-tech/ui-native`, `@gv-tech/design-tokens`, and `@gv-tech/ui-core` release together.
50
50
 
51
- ```bash
52
- # npm
53
- npm install @gv-tech/design-system
54
-
55
- # bun
56
- bun add @gv-tech/design-system
57
- ```
51
+ | You want… | Install |
52
+ | :----------------------------------------- | :------------------------------------------------ |
53
+ | Web components from the published build | `@gv-tech/ui-web` and `@gv-tech/design-tokens` |
54
+ | Native components from the published build | `@gv-tech/ui-native` and `@gv-tech/design-tokens` |
55
+ | Every web component from one package | `@gv-tech/design-system` |
56
+ | To own the web source | The shadcn command below |
58
57
 
59
- ## Adding Components via Shadcn CLI
58
+ Web, in the global stylesheet, import tokens before Tailwind:
60
59
 
61
- If you don't want to install the entire library and prefer to own the source code, you can use the `shadcn` CLI to pull individual components directly from our GitHub registry.
60
+ ```css
61
+ @import '@gv-tech/design-tokens/theme.css';
62
+ @import 'tailwindcss';
63
+ ```
62
64
 
63
- For **Web** components:
65
+ ```tsx
66
+ import { Button } from '@gv-tech/ui-web';
64
67
 
65
- ```bash
66
- npx shadcn@latest add "https://github.com/Garcia-Ventures/gvtech-design/tree/main/packages/ui-web"
68
+ export function App() {
69
+ return <Button>Click me</Button>;
70
+ }
67
71
  ```
68
72
 
69
- For **React Native** components:
73
+ Native needs Metro, Babel, NativeWind v5, and `ThemeProvider` before a Button paints. Follow [Set up React Native](docs/how-to/setup-react-native.md).
74
+
75
+ To own the web source instead of the npm build:
70
76
 
71
77
  ```bash
72
- npx shadcn@latest add "https://github.com/Garcia-Ventures/gvtech-design/tree/main/packages/ui-native"
78
+ npx shadcn@latest add "https://github.com/Garcia-Ventures/gvtech-design/tree/main/packages/ui-web"
73
79
  ```
74
80
 
75
- ## Usage
76
-
77
- Example import:
78
-
79
- ```js
80
- import { Button } from '@gv-tech/design-system';
81
+ That command copies web components. It does not set up React Native. The supported native install is `@gv-tech/ui-native` plus the how-to above.
81
82
 
82
- function App() {
83
- return <Button>Click me</Button>;
84
- }
85
- ```
83
+ The first-use walkthrough is [Use in Your App](docs/tutorials/02-first-app-usage.md).
86
84
 
87
85
  ## Development
88
86
 
package/dist/chart.cjs CHANGED
@@ -4,5 +4,5 @@ ${n.map(([e,n])=>{let r=n.theme?.[t]??n.color;return r?` --color-${e}: ${r};`:n
4
4
  `)}
5
5
  }
6
6
  `).join(`
7
- `)}}):null},u=t.I;function d({active:e,payload:i,className:a,indicator:o=`dot`,hideLabel:c=!1,hideIndicator:l=!1,label:u,labelFormatter:d,labelClassName:f,formatter:p,color:h,nameKey:g,labelKey:_}){let{config:v}=s(),y=n.useMemo(()=>{if(c||!i?.length)return null;let[e]=i,n=`${_??e?.dataKey??e?.name??`value`}`,a=m(v,e,n),o=!_&&typeof u==`string`?v[u]?.label??u:a?.label;return d?(0,r.jsx)(`div`,{className:t.ei(`font-medium`,f),children:d(o,i)}):o?(0,r.jsx)(`div`,{className:t.ei(`font-medium`,f),children:o}):null},[u,d,i,c,f,v,_]);if(!e||!i?.length)return null;let b=i.length===1&&o!==`dot`;return(0,r.jsxs)(`div`,{className:t.ei(`border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl`,a),children:[b?null:y,(0,r.jsx)(`div`,{className:`grid gap-1.5`,children:i.filter(e=>e.type!==`none`).map((e,n)=>{let i=`${g??e.name??e.dataKey??`value`}`,a=m(v,e,i),s=h??e.payload?.fill??e.color;return(0,r.jsx)(`div`,{className:t.ei(`[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5`,o===`dot`&&`items-center`),children:p&&e?.value!==void 0&&e.name?p(e.value,e.name,e,n,e.payload):(0,r.jsxs)(r.Fragment,{children:[a?.icon?(0,r.jsx)(a.icon,{}):!l&&(0,r.jsx)(`div`,{className:t.ei(`shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)`,{"h-2.5 w-2.5":o===`dot`,"w-1":o===`line`,"w-0 border-[1.5px] border-dashed bg-transparent":o===`dashed`,"my-0.5":b&&o===`dashed`}),style:{"--color-bg":s,"--color-border":s}}),(0,r.jsxs)(`div`,{className:t.ei(`flex flex-1 justify-between leading-none`,b?`items-end`:`items-center`),children:[(0,r.jsxs)(`div`,{className:`grid gap-1.5`,children:[b?y:null,(0,r.jsx)(`span`,{className:`text-muted-foreground`,children:a?.label??e.name})]}),e.value!=null&&(0,r.jsx)(`span`,{className:`text-foreground font-mono font-medium tabular-nums`,children:typeof e.value==`number`?e.value.toLocaleString():String(e.value)})]})]})},n)})})]})}var f=t.L;function p({className:e,hideIcon:n=!1,payload:i,verticalAlign:a=`bottom`,nameKey:o}){let{config:c}=s();return i?.length?(0,r.jsx)(`div`,{className:t.ei(`flex items-center justify-center gap-4`,a===`top`?`pb-3`:`pt-3`,e),children:i.filter(e=>e.type!==`none`).map((e,i)=>{let a=`${o??e.dataKey??`value`}`,s=m(c,e,a);return(0,r.jsxs)(`div`,{className:t.ei(`[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3`),children:[s?.icon&&!n?(0,r.jsx)(s.icon,{}):(0,r.jsx)(`div`,{className:`h-2 w-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),s?.label]},i)})}):null}function m(e,t,n){if(typeof t!=`object`||!t)return;let r=`payload`in t&&typeof t.payload==`object`&&t.payload!==null?t.payload:void 0,i=n;return n in t&&typeof t[n]==`string`?i=t[n]:r&&n in r&&typeof r[n]==`string`&&(i=r[n]),i in e?e[i]:e[n]}exports.ChartContainer=c,exports.ChartLegend=f,exports.ChartLegendContent=p,exports.ChartStyle=l,exports.ChartTooltip=u,exports.ChartTooltipContent=d;
7
+ `)}}):null},u=t.I;function d({active:e,payload:i,className:a,indicator:o=`dot`,hideLabel:c=!1,hideIndicator:l=!1,label:u,labelFormatter:d,labelClassName:f,formatter:p,color:h,nameKey:g,labelKey:_}){let{config:v}=s(),y=n.useMemo(()=>{if(c||!i?.length)return null;let[e]=i,n=`${_??e?.dataKey??e?.name??`value`}`,a=m(v,e,n),o=!_&&typeof u==`string`?v[u]?.label??u:a?.label;return d?(0,r.jsx)(`div`,{className:t.ei(`font-medium`,f),children:d(o,i)}):o?(0,r.jsx)(`div`,{className:t.ei(`font-medium`,f),children:o}):null},[u,d,i,c,f,v,_]);if(!e||!i?.length)return null;let b=i.length===1&&o!==`dot`;return(0,r.jsxs)(`div`,{className:t.ei(`border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl`,a),children:[b?null:y,(0,r.jsx)(`div`,{className:`grid gap-1.5`,children:i.filter(e=>e.type!==`none`).map((e,n)=>{let i=`${g??e.name??e.dataKey??`value`}`,a=m(v,e,i),s=h??e.payload?.fill??e.color;return(0,r.jsx)(`div`,{className:t.ei(`[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5`,o===`dot`&&`items-center`),children:p&&e?.value!==void 0&&e.name?p(e.value,e.name,e,n,e.payload):(0,r.jsxs)(r.Fragment,{children:[a?.icon?(0,r.jsx)(a.icon,{}):!l&&(0,r.jsx)(`div`,{className:t.ei(`shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)`,{"h-2.5 w-2.5":o===`dot`,"w-1":o===`line`,"w-0 border-[1.5px] border-dashed bg-transparent":o===`dashed`,"my-0.5":b&&o===`dashed`}),style:{"--color-bg":s,"--color-border":s}}),(0,r.jsxs)(`div`,{className:t.ei(`flex flex-1 justify-between leading-none`,b?`items-end`:`items-center`),children:[(0,r.jsxs)(`div`,{className:`grid gap-1.5`,children:[b?y:null,(0,r.jsx)(`span`,{className:`text-muted-foreground`,children:a?.label??e.name})]}),e.value!==null&&e.value!==void 0&&(0,r.jsx)(`span`,{className:`text-foreground font-mono font-medium tabular-nums`,children:typeof e.value==`number`?e.value.toLocaleString():String(e.value)})]})]})},n)})})]})}var f=t.L;function p({className:e,hideIcon:n=!1,payload:i,verticalAlign:a=`bottom`,nameKey:o}){let{config:c}=s();return i?.length?(0,r.jsx)(`div`,{className:t.ei(`flex items-center justify-center gap-4`,a===`top`?`pb-3`:`pt-3`,e),children:i.filter(e=>e.type!==`none`).map((e,i)=>{let a=`${o??e.dataKey??`value`}`,s=m(c,e,a);return(0,r.jsxs)(`div`,{className:t.ei(`[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3`),children:[s?.icon&&!n?(0,r.jsx)(s.icon,{}):(0,r.jsx)(`div`,{className:`h-2 w-2 shrink-0 rounded-[2px]`,style:{backgroundColor:e.color}}),s?.label]},i)})}):null}function m(e,t,n){if(typeof t!=`object`||!t)return;let r=`payload`in t&&typeof t.payload==`object`&&t.payload!==null?t.payload:void 0,i=n;return n in t&&typeof t[n]==`string`?i=t[n]:r&&n in r&&typeof r[n]==`string`&&(i=r[n]),i in e?e[i]:e[n]}exports.ChartContainer=c,exports.ChartLegend=f,exports.ChartLegendContent=p,exports.ChartStyle=l,exports.ChartTooltip=u,exports.ChartTooltipContent=d;
8
8
  //# sourceMappingURL=chart.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart.cjs","names":["React","cn","_Fragment","require_rolldown_runtime","require_vendor","react","import_jsx_runtime","THEMES","INITIAL_DIMENSION","ChartContext","useChart","context","ChartContainer","props","uniqueId","chartId","id","className","ChartStyle","colorConfig","config","theme","prefix","key","itemConfig","color","ChartTooltip","ChartTooltipContent","tooltipLabel","hideLabel","payload","item","labelKey","getPayloadConfigFromPayload","value","label","labelFormatter","labelClassName","active","nestLabel","indicator","nameKey","indicatorColor","formatter","index","hideIndicator","ChartLegend","ChartLegendContent","verticalAlign","hideIcon","payloadPayload","configLabelKey"],"sources":["../packages/ui-web/src/chart.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from 'cn';\nimport * as React from 'react';\nimport type { TooltipValueType } from 'recharts';\nimport * as RechartsPrimitive from 'recharts';\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n string,\n {\n label?: React.ReactNode;\n icon?: React.ComponentType;\n } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\ntype ChartContextProps = {\n config: ChartConfig;\n};\n\nconst ChartContext = React.createContext<ChartContextProps | null>(null);\n\nfunction useChart() {\n const context = React.useContext(ChartContext);\n\n if (!context) {\n throw new Error('useChart must be used within a <ChartContainer />');\n }\n\n return context;\n}\n\nfunction ChartContainer({\n id,\n className,\n children,\n config,\n initialDimension = INITIAL_DIMENSION,\n ...props\n}: React.ComponentProps<'div'> & {\n config: ChartConfig;\n children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];\n initialDimension?: {\n width: number;\n height: number;\n };\n}) {\n const uniqueId = React.useId();\n const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-slot=\"chart\"\n data-chart={chartId}\n className={cn(\n \"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n className,\n )}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>\n {children}\n </RechartsPrimitive.ResponsiveContainer>\n </div>\n </ChartContext.Provider>\n );\n}\n\nconst ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {\n const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);\n\n if (!colorConfig.length) {\n return null;\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, itemConfig]) => {\n const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;\n return color ? ` --color-${key}: ${color};` : null;\n })\n .join('\\n')}\n}\n`,\n )\n .join('\\n'),\n }}\n />\n );\n};\n\nconst ChartTooltip = RechartsPrimitive.Tooltip;\n\nfunction ChartTooltipContent({\n active,\n payload,\n className,\n indicator = 'dot',\n hideLabel = false,\n hideIndicator = false,\n label,\n labelFormatter,\n labelClassName,\n formatter,\n color,\n nameKey,\n labelKey,\n}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &\n React.ComponentProps<'div'> & {\n hideLabel?: boolean;\n hideIndicator?: boolean;\n indicator?: 'line' | 'dot' | 'dashed';\n nameKey?: string;\n labelKey?: string;\n } & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>) {\n const { config } = useChart();\n\n const tooltipLabel = React.useMemo(() => {\n if (hideLabel || !payload?.length) {\n return null;\n }\n\n const [item] = payload;\n const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n\n if (labelFormatter) {\n return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;\n }\n\n if (!value) {\n return null;\n }\n\n return <div className={cn('font-medium', labelClassName)}>{value}</div>;\n }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n if (!active || !payload?.length) {\n return null;\n }\n\n const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n return (\n <div\n className={cn(\n 'border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',\n className,\n )}\n >\n {!nestLabel ? tooltipLabel : null}\n <div className=\"grid gap-1.5\">\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n return (\n <div\n key={index}\n className={cn(\n '[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',\n indicator === 'dot' && 'items-center',\n )}\n >\n {formatter && item?.value !== undefined && item.name ? (\n formatter(item.value, item.name, item, index, item.payload)\n ) : (\n <>\n {itemConfig?.icon ? (\n <itemConfig.icon />\n ) : (\n !hideIndicator && (\n <div\n className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {\n 'h-2.5 w-2.5': indicator === 'dot',\n 'w-1': indicator === 'line',\n 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',\n 'my-0.5': nestLabel && indicator === 'dashed',\n })}\n style={\n {\n '--color-bg': indicatorColor,\n '--color-border': indicatorColor,\n } as React.CSSProperties\n }\n />\n )\n )}\n <div\n className={cn(\n 'flex flex-1 justify-between leading-none',\n nestLabel ? 'items-end' : 'items-center',\n )}\n >\n <div className=\"grid gap-1.5\">\n {nestLabel ? tooltipLabel : null}\n <span className=\"text-muted-foreground\">{itemConfig?.label ?? item.name}</span>\n </div>\n {item.value != null && (\n <span className=\"text-foreground font-mono font-medium tabular-nums\">\n {typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)}\n </span>\n )}\n </div>\n </>\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nconst ChartLegend = RechartsPrimitive.Legend;\n\nfunction ChartLegendContent({\n className,\n hideIcon = false,\n payload,\n verticalAlign = 'bottom',\n nameKey,\n}: React.ComponentProps<'div'> & {\n hideIcon?: boolean;\n nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps) {\n const { config } = useChart();\n\n if (!payload?.length) {\n return null;\n }\n\n return (\n <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n\n return (\n <div\n key={index}\n className={cn('[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3')}\n >\n {itemConfig?.icon && !hideIcon ? (\n <itemConfig.icon />\n ) : (\n <div\n className=\"h-2 w-2 shrink-0 rounded-[2px]\"\n style={{\n backgroundColor: item.color,\n }}\n />\n )}\n {itemConfig?.label}\n </div>\n );\n })}\n </div>\n );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n if (typeof payload !== 'object' || payload === null) {\n return undefined;\n }\n\n const payloadPayload =\n 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null\n ? payload.payload\n : undefined;\n\n let configLabelKey: string = key;\n\n if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {\n configLabelKey = payload[key as keyof typeof payload] as string;\n } else if (\n payloadPayload &&\n key in payloadPayload &&\n typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'\n ) {\n configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;\n }\n\n return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent };\n"],"mappings":"A,8NAQMO,EAAS,CAAE,MAAO,GAAI,KAAM,OAAQ,EAEpCC,EAAoB,CAAE,MAAO,IAAK,OAAQ,GAAI,EAe9CC,EAAeT,EAAM,cAAwC,IAAI,EAEvE,SAASU,GAAW,CAClB,IAAMC,EAAUX,EAAM,WAAWS,CAAY,EAE7C,GAAI,CAACE,EACH,MAAU,MAAM,mDAAmD,EAGrE,OAAOA,CACT,CAEA,SAASC,EAAe,CACtB,KACA,YACA,WACA,SACA,mBAAmBJ,EACnB,GAAGK,GAQF,CACD,IAAMC,EAAWd,EAAM,MAAM,EACvBe,EAAU,SAASC,GAAMF,EAAS,QAAQ,KAAM,EAAE,IAExD,OACE,EAAAR,EAAA,IAAA,CAACG,EAAa,SAAd,CAAuB,MAAO,CAAE,QAAO,EACrC,UAAA,EAAAH,EAAA,KAAA,CAAC,MAAD,CACE,YAAU,QACV,aAAYS,EACZ,UAAWd,EAAAA,GACT,8pBACAgB,CACF,EACA,GAAIJ,EAPN,SAAA,EASE,EAAAP,EAAA,IAAA,CAACY,EAAD,CAAY,GAAIH,EAAiB,QAAS,CAAA,GAC1C,EAAAT,EAAA,IAAA,CAAAF,EAAA,EAAA,CAAyD,mBACtD,UACoC,CAAA,CACpC,C,EACgB,CAAA,CAE3B,CAEA,IAAMc,GAAc,CAAE,KAAI,YAAkD,CAC1E,IAAMC,EAAc,OAAO,QAAQC,CAAM,CAAC,CAAC,QAAQ,EAAGA,KAAYA,EAAO,OAASA,EAAO,KAAK,EAM9F,OAJKD,EAAY,QAKf,EAAAb,EAAA,IAAA,CAAC,QAAD,CACE,wBAAyB,CACvB,OAAQ,OAAO,QAAQC,CAAM,CAAC,CAC3B,KACE,CAACc,EAAOC,KAAY;EAC/BA,EAAO,eAAeN,EAAG;EACzBG,EACC,KAAK,CAACI,EAAKC,KAAgB,CAC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P,GAEzB2B,GACA3B,KAAO2B,GACP,OAAOA,EAAe3B,IAAwC,WAE9D,EAAiB2B,EAAe3B,IAG3B4B,KAAkB/B,EAASA,EAAO+B,GAAkB/B,EAAOG,EACpE,C"}
1
+ {"version":3,"file":"chart.cjs","names":["React","cn","_Fragment","require_rolldown_runtime","require_vendor","react","import_jsx_runtime","THEMES","INITIAL_DIMENSION","ChartContext","useChart","context","ChartContainer","props","uniqueId","chartId","id","className","ChartStyle","colorConfig","config","theme","prefix","key","itemConfig","color","ChartTooltip","ChartTooltipContent","tooltipLabel","hideLabel","payload","item","labelKey","getPayloadConfigFromPayload","value","label","labelFormatter","labelClassName","active","nestLabel","indicator","nameKey","indicatorColor","formatter","index","hideIndicator","ChartLegend","ChartLegendContent","verticalAlign","hideIcon","payloadPayload","configLabelKey"],"sources":["../packages/ui-web/src/chart.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from 'cn';\nimport * as React from 'react';\nimport type { TooltipValueType } from 'recharts';\nimport * as RechartsPrimitive from 'recharts';\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n string,\n {\n label?: React.ReactNode;\n icon?: React.ComponentType;\n } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\ntype ChartContextProps = {\n config: ChartConfig;\n};\n\nconst ChartContext = React.createContext<ChartContextProps | null>(null);\n\nfunction useChart() {\n const context = React.useContext(ChartContext);\n\n if (!context) {\n throw new Error('useChart must be used within a <ChartContainer />');\n }\n\n return context;\n}\n\nfunction ChartContainer({\n id,\n className,\n children,\n config,\n initialDimension = INITIAL_DIMENSION,\n ...props\n}: React.ComponentProps<'div'> & {\n config: ChartConfig;\n children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];\n initialDimension?: {\n width: number;\n height: number;\n };\n}) {\n const uniqueId = React.useId();\n const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-slot=\"chart\"\n data-chart={chartId}\n className={cn(\n \"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n className,\n )}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>\n {children}\n </RechartsPrimitive.ResponsiveContainer>\n </div>\n </ChartContext.Provider>\n );\n}\n\nconst ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {\n const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);\n\n if (!colorConfig.length) {\n return null;\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, itemConfig]) => {\n const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;\n return color ? ` --color-${key}: ${color};` : null;\n })\n .join('\\n')}\n}\n`,\n )\n .join('\\n'),\n }}\n />\n );\n};\n\nconst ChartTooltip = RechartsPrimitive.Tooltip;\n\nfunction ChartTooltipContent({\n active,\n payload,\n className,\n indicator = 'dot',\n hideLabel = false,\n hideIndicator = false,\n label,\n labelFormatter,\n labelClassName,\n formatter,\n color,\n nameKey,\n labelKey,\n}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &\n React.ComponentProps<'div'> & {\n hideLabel?: boolean;\n hideIndicator?: boolean;\n indicator?: 'line' | 'dot' | 'dashed';\n nameKey?: string;\n labelKey?: string;\n } & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>) {\n const { config } = useChart();\n\n const tooltipLabel = React.useMemo(() => {\n if (hideLabel || !payload?.length) {\n return null;\n }\n\n const [item] = payload;\n const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n\n if (labelFormatter) {\n return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;\n }\n\n if (!value) {\n return null;\n }\n\n return <div className={cn('font-medium', labelClassName)}>{value}</div>;\n }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n if (!active || !payload?.length) {\n return null;\n }\n\n const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n return (\n <div\n className={cn(\n 'border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',\n className,\n )}\n >\n {!nestLabel ? tooltipLabel : null}\n <div className=\"grid gap-1.5\">\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n return (\n <div\n key={index}\n className={cn(\n '[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',\n indicator === 'dot' && 'items-center',\n )}\n >\n {formatter && item?.value !== undefined && item.name ? (\n formatter(item.value, item.name, item, index, item.payload)\n ) : (\n <>\n {itemConfig?.icon ? (\n <itemConfig.icon />\n ) : (\n !hideIndicator && (\n <div\n className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {\n 'h-2.5 w-2.5': indicator === 'dot',\n 'w-1': indicator === 'line',\n 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',\n 'my-0.5': nestLabel && indicator === 'dashed',\n })}\n style={\n {\n '--color-bg': indicatorColor,\n '--color-border': indicatorColor,\n } as React.CSSProperties\n }\n />\n )\n )}\n <div\n className={cn(\n 'flex flex-1 justify-between leading-none',\n nestLabel ? 'items-end' : 'items-center',\n )}\n >\n <div className=\"grid gap-1.5\">\n {nestLabel ? tooltipLabel : null}\n <span className=\"text-muted-foreground\">{itemConfig?.label ?? item.name}</span>\n </div>\n {item.value !== null && item.value !== undefined && (\n <span className=\"text-foreground font-mono font-medium tabular-nums\">\n {typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)}\n </span>\n )}\n </div>\n </>\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nconst ChartLegend = RechartsPrimitive.Legend;\n\nfunction ChartLegendContent({\n className,\n hideIcon = false,\n payload,\n verticalAlign = 'bottom',\n nameKey,\n}: React.ComponentProps<'div'> & {\n hideIcon?: boolean;\n nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps) {\n const { config } = useChart();\n\n if (!payload?.length) {\n return null;\n }\n\n return (\n <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n\n return (\n <div\n key={index}\n className={cn('[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3')}\n >\n {itemConfig?.icon && !hideIcon ? (\n <itemConfig.icon />\n ) : (\n <div\n className=\"h-2 w-2 shrink-0 rounded-[2px]\"\n style={{\n backgroundColor: item.color,\n }}\n />\n )}\n {itemConfig?.label}\n </div>\n );\n })}\n </div>\n );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n if (typeof payload !== 'object' || payload === null) {\n return undefined;\n }\n\n const payloadPayload =\n 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null\n ? payload.payload\n : undefined;\n\n let configLabelKey: string = key;\n\n if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {\n configLabelKey = payload[key as keyof typeof payload] as string;\n } else if (\n payloadPayload &&\n key in payloadPayload &&\n typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'\n ) {\n configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;\n }\n\n return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent };\n"],"mappings":"A,8NAQMO,EAAS,CAAE,MAAO,GAAI,KAAM,OAAQ,EAEpCC,EAAoB,CAAE,MAAO,IAAK,OAAQ,GAAI,EAe9CC,EAAeT,EAAM,cAAwC,IAAI,EAEvE,SAASU,GAAW,CAClB,IAAMC,EAAUX,EAAM,WAAWS,CAAY,EAE7C,GAAI,CAACE,EACH,MAAU,MAAM,mDAAmD,EAGrE,OAAOA,CACT,CAEA,SAASC,EAAe,CACtB,KACA,YACA,WACA,SACA,mBAAmBJ,EACnB,GAAGK,GAQF,CACD,IAAMC,EAAWd,EAAM,MAAM,EACvBe,EAAU,SAASC,GAAMF,EAAS,QAAQ,KAAM,EAAE,IAExD,OACE,EAAAR,EAAA,IAAA,CAACG,EAAa,SAAd,CAAuB,MAAO,CAAE,QAAO,EACrC,UAAA,EAAAH,EAAA,KAAA,CAAC,MAAD,CACE,YAAU,QACV,aAAYS,EACZ,UAAWd,EAAAA,GACT,8pBACAgB,CACF,EACA,GAAIJ,EAPN,SAAA,EASE,EAAAP,EAAA,IAAA,CAACY,EAAD,CAAY,GAAIH,EAAiB,QAAS,CAAA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,CAACkB,EAAW,KAAZ,CAAkB,CAAA,GAElB,EAAAlB,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,iCACV,MAAO,CACL,gBAAiByB,EAAK,KACxB,CACD,CAAA,EAEFP,GAAY,KACV,CAdE,EAAAoB,CAcF,CAET,CAAC,CACA,CAAA,EA9BE,IAgCX,CAEA,SAASX,EAA4B,EAAqB,EAAkB,EAAa,CACvF,GAAI,OAAOH,GAAY,WAAYA,EACjC,OAGF,IAAMoB,EACJ,YAAapB,GAAW,OAAOA,EAAQ,SAAY,UAAYA,EAAQ,UAAY,KAC/EA,EAAQ,QACR,IAAA,GAEFqB,EAAyB5B,EAY7B,OAVIA,KAAOO,GAAW,OAAOA,EAAQP,IAAiC,SACpE,EAAiBO,EAAQP,GAEzB2B,GACA3B,KAAO2B,GACP,OAAOA,EAAe3B,IAAwC,WAE9D,EAAiB2B,EAAe3B,IAG3B4B,KAAkB/B,EAASA,EAAO+B,GAAkB/B,EAAOG,EACpE,C"}
package/dist/chart.mjs CHANGED
@@ -94,7 +94,7 @@ function m({ active: e, payload: t, className: n, indicator: r = "dot", hideLabe
94
94
  className: "text-muted-foreground",
95
95
  children: a?.label ?? e.name
96
96
  })]
97
- }), e.value != null && /* @__PURE__ */ (0, o.jsx)("span", {
97
+ }), e.value !== null && e.value !== void 0 && /* @__PURE__ */ (0, o.jsx)("span", {
98
98
  className: "text-foreground font-mono font-medium tabular-nums",
99
99
  children: typeof e.value == "number" ? e.value.toLocaleString() : String(e.value)
100
100
  })]
@@ -1 +1 @@
1
- {"version":3,"file":"chart.mjs","names":["React","RechartsPrimitive.ResponsiveContainer","RechartsPrimitive.Tooltip","_Fragment","RechartsPrimitive.Legend","require_jsx_runtime","Tooltip","Legend","ResponsiveContainer","cn","React$1","import_jsx_runtime","THEMES","INITIAL_DIMENSION","ChartContext","useChart","context","ChartContainer","props","uniqueId","chartId","id","className","ChartStyle","colorConfig","config","theme","prefix","key","itemConfig","color","ChartTooltip","ChartTooltipContent","tooltipLabel","hideLabel","payload","item","labelKey","getPayloadConfigFromPayload","value","label","labelFormatter","labelClassName","active","nestLabel","indicator","nameKey","indicatorColor","formatter","index","hideIndicator","ChartLegend","ChartLegendContent","verticalAlign","hideIcon","payloadPayload","configLabelKey"],"sources":["../packages/ui-web/src/chart.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from 'cn';\nimport * as React from 'react';\nimport type { TooltipValueType } from 'recharts';\nimport * as RechartsPrimitive from 'recharts';\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n string,\n {\n label?: React.ReactNode;\n icon?: React.ComponentType;\n } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\ntype ChartContextProps = {\n config: ChartConfig;\n};\n\nconst ChartContext = React.createContext<ChartContextProps | null>(null);\n\nfunction useChart() {\n const context = React.useContext(ChartContext);\n\n if (!context) {\n throw new Error('useChart must be used within a <ChartContainer />');\n }\n\n return context;\n}\n\nfunction ChartContainer({\n id,\n className,\n children,\n config,\n initialDimension = INITIAL_DIMENSION,\n ...props\n}: React.ComponentProps<'div'> & {\n config: ChartConfig;\n children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];\n initialDimension?: {\n width: number;\n height: number;\n };\n}) {\n const uniqueId = React.useId();\n const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-slot=\"chart\"\n data-chart={chartId}\n className={cn(\n \"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n className,\n )}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>\n {children}\n </RechartsPrimitive.ResponsiveContainer>\n </div>\n </ChartContext.Provider>\n );\n}\n\nconst ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {\n const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);\n\n if (!colorConfig.length) {\n return null;\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, itemConfig]) => {\n const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;\n return color ? ` --color-${key}: ${color};` : null;\n })\n .join('\\n')}\n}\n`,\n )\n .join('\\n'),\n }}\n />\n );\n};\n\nconst ChartTooltip = RechartsPrimitive.Tooltip;\n\nfunction ChartTooltipContent({\n active,\n payload,\n className,\n indicator = 'dot',\n hideLabel = false,\n hideIndicator = false,\n label,\n labelFormatter,\n labelClassName,\n formatter,\n color,\n nameKey,\n labelKey,\n}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &\n React.ComponentProps<'div'> & {\n hideLabel?: boolean;\n hideIndicator?: boolean;\n indicator?: 'line' | 'dot' | 'dashed';\n nameKey?: string;\n labelKey?: string;\n } & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>) {\n const { config } = useChart();\n\n const tooltipLabel = React.useMemo(() => {\n if (hideLabel || !payload?.length) {\n return null;\n }\n\n const [item] = payload;\n const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n\n if (labelFormatter) {\n return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;\n }\n\n if (!value) {\n return null;\n }\n\n return <div className={cn('font-medium', labelClassName)}>{value}</div>;\n }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n if (!active || !payload?.length) {\n return null;\n }\n\n const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n return (\n <div\n className={cn(\n 'border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',\n className,\n )}\n >\n {!nestLabel ? tooltipLabel : null}\n <div className=\"grid gap-1.5\">\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n return (\n <div\n key={index}\n className={cn(\n '[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',\n indicator === 'dot' && 'items-center',\n )}\n >\n {formatter && item?.value !== undefined && item.name ? (\n formatter(item.value, item.name, item, index, item.payload)\n ) : (\n <>\n {itemConfig?.icon ? (\n <itemConfig.icon />\n ) : (\n !hideIndicator && (\n <div\n className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {\n 'h-2.5 w-2.5': indicator === 'dot',\n 'w-1': indicator === 'line',\n 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',\n 'my-0.5': nestLabel && indicator === 'dashed',\n })}\n style={\n {\n '--color-bg': indicatorColor,\n '--color-border': indicatorColor,\n } as React.CSSProperties\n }\n />\n )\n )}\n <div\n className={cn(\n 'flex flex-1 justify-between leading-none',\n nestLabel ? 'items-end' : 'items-center',\n )}\n >\n <div className=\"grid gap-1.5\">\n {nestLabel ? tooltipLabel : null}\n <span className=\"text-muted-foreground\">{itemConfig?.label ?? item.name}</span>\n </div>\n {item.value != null && (\n <span className=\"text-foreground font-mono font-medium tabular-nums\">\n {typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)}\n </span>\n )}\n </div>\n </>\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nconst ChartLegend = RechartsPrimitive.Legend;\n\nfunction ChartLegendContent({\n className,\n hideIcon = false,\n payload,\n verticalAlign = 'bottom',\n nameKey,\n}: React.ComponentProps<'div'> & {\n hideIcon?: boolean;\n nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps) {\n const { config } = useChart();\n\n if (!payload?.length) {\n return null;\n }\n\n return (\n <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n\n return (\n <div\n key={index}\n className={cn('[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3')}\n >\n {itemConfig?.icon && !hideIcon ? (\n <itemConfig.icon />\n ) : (\n <div\n className=\"h-2 w-2 shrink-0 rounded-[2px]\"\n style={{\n backgroundColor: item.color,\n }}\n />\n )}\n {itemConfig?.label}\n </div>\n );\n })}\n </div>\n );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n if (typeof payload !== 'object' || payload === null) {\n return undefined;\n }\n\n const payloadPayload =\n 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null\n ? payload.payload\n : undefined;\n\n let configLabelKey: string = key;\n\n if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {\n configLabelKey = payload[key as keyof typeof payload] as string;\n } else if (\n payloadPayload &&\n key in payloadPayload &&\n typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'\n ) {\n configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;\n }\n\n return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent };\n"],"mappings":";;;;;A,aAQMY,IAAS;CAAE,OAAO;CAAI,MAAM;AAAQ,GAEpCC,IAAoB;CAAE,OAAO;CAAK,QAAQ;AAAI,GAe9CC,IAAed,EAAM,cAAwC,IAAI;AAEvE,SAASe,IAAW;CAClB,IAAMC,IAAUhB,EAAM,WAAWc,CAAY;CAE7C,IAAI,CAACE,GACH,MAAU,MAAM,mDAAmD;CAGrE,OAAOA;AACT;AAEA,SAASC,EAAe,EACtB,OACA,cACA,aACA,WACA,sBAAmBJ,GACnB,GAAGK,KAQF;CACD,IAAMC,IAAWnB,EAAM,MAAM,GACvBoB,IAAU,SAASC,KAAMF,EAAS,QAAQ,MAAM,EAAE;CAExD,OACE,iBAAA,GAAAR,EAAA,IAAA,CAACG,EAAa,UAAd;EAAuB,OAAO,EAAE,UAAO;EACrC,UAAA,iBAAA,GAAAH,EAAA,KAAA,CAAC,OAAD;GACE,aAAU;GACV,cAAYS;GACZ,WAAWX,EACT,+pBACAa,CACF;GACA,GAAIJ;GAPN,UAAA,CASE,iBAAA,GAAAP,EAAA,IAAA,CAACY,GAAD;IAAY,IAAIH;IAAiB;GAAS,CAAA,GAC1C,iBAAA,GAAAT,EAAA,IAAA,CAACV,GAAD;IAAyD;IACtD;GACoC,CAAA,CACpC;;CACgB,CAAA;AAE3B;AAEA,IAAMsB,KAAc,EAAE,OAAI,gBAAkD;CAC1E,IAAMC,IAAc,OAAO,QAAQC,CAAM,CAAC,CAAC,QAAQ,GAAGA,OAAYA,EAAO,SAASA,EAAO,KAAK;CAM9F,OAJKD,EAAY,SAKf,iBAAA,GAAAb,EAAA,IAAA,CAAC,SAAD,EACE,yBAAyB,EACvB,QAAQ,OAAO,Q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AW,OAAOA,EAAQ,WAAY,YAAYA,EAAQ,YAAY,OAC/EA,EAAQ,UACR,KAAA,GAEFqB,IAAyB5B;CAY7B,OAVIA,KAAOO,KAAW,OAAOA,EAAQP,MAAiC,WACpE,IAAiBO,EAAQP,KAEzB2B,KACA3B,KAAO2B,KACP,OAAOA,EAAe3B,MAAwC,aAE9D,IAAiB2B,EAAe3B,KAG3B4B,KAAkB/B,IAASA,EAAO+B,KAAkB/B,EAAOG;AACpE"}
1
+ {"version":3,"file":"chart.mjs","names":["React","RechartsPrimitive.ResponsiveContainer","RechartsPrimitive.Tooltip","_Fragment","RechartsPrimitive.Legend","require_jsx_runtime","Tooltip","Legend","ResponsiveContainer","cn","React$1","import_jsx_runtime","THEMES","INITIAL_DIMENSION","ChartContext","useChart","context","ChartContainer","props","uniqueId","chartId","id","className","ChartStyle","colorConfig","config","theme","prefix","key","itemConfig","color","ChartTooltip","ChartTooltipContent","tooltipLabel","hideLabel","payload","item","labelKey","getPayloadConfigFromPayload","value","label","labelFormatter","labelClassName","active","nestLabel","indicator","nameKey","indicatorColor","formatter","index","hideIndicator","ChartLegend","ChartLegendContent","verticalAlign","hideIcon","payloadPayload","configLabelKey"],"sources":["../packages/ui-web/src/chart.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from 'cn';\nimport * as React from 'react';\nimport type { TooltipValueType } from 'recharts';\nimport * as RechartsPrimitive from 'recharts';\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n string,\n {\n label?: React.ReactNode;\n icon?: React.ComponentType;\n } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\ntype ChartContextProps = {\n config: ChartConfig;\n};\n\nconst ChartContext = React.createContext<ChartContextProps | null>(null);\n\nfunction useChart() {\n const context = React.useContext(ChartContext);\n\n if (!context) {\n throw new Error('useChart must be used within a <ChartContainer />');\n }\n\n return context;\n}\n\nfunction ChartContainer({\n id,\n className,\n children,\n config,\n initialDimension = INITIAL_DIMENSION,\n ...props\n}: React.ComponentProps<'div'> & {\n config: ChartConfig;\n children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];\n initialDimension?: {\n width: number;\n height: number;\n };\n}) {\n const uniqueId = React.useId();\n const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-slot=\"chart\"\n data-chart={chartId}\n className={cn(\n \"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n className,\n )}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>\n {children}\n </RechartsPrimitive.ResponsiveContainer>\n </div>\n </ChartContext.Provider>\n );\n}\n\nconst ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {\n const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);\n\n if (!colorConfig.length) {\n return null;\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, itemConfig]) => {\n const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;\n return color ? ` --color-${key}: ${color};` : null;\n })\n .join('\\n')}\n}\n`,\n )\n .join('\\n'),\n }}\n />\n );\n};\n\nconst ChartTooltip = RechartsPrimitive.Tooltip;\n\nfunction ChartTooltipContent({\n active,\n payload,\n className,\n indicator = 'dot',\n hideLabel = false,\n hideIndicator = false,\n label,\n labelFormatter,\n labelClassName,\n formatter,\n color,\n nameKey,\n labelKey,\n}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &\n React.ComponentProps<'div'> & {\n hideLabel?: boolean;\n hideIndicator?: boolean;\n indicator?: 'line' | 'dot' | 'dashed';\n nameKey?: string;\n labelKey?: string;\n } & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>) {\n const { config } = useChart();\n\n const tooltipLabel = React.useMemo(() => {\n if (hideLabel || !payload?.length) {\n return null;\n }\n\n const [item] = payload;\n const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n\n if (labelFormatter) {\n return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;\n }\n\n if (!value) {\n return null;\n }\n\n return <div className={cn('font-medium', labelClassName)}>{value}</div>;\n }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n if (!active || !payload?.length) {\n return null;\n }\n\n const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n return (\n <div\n className={cn(\n 'border-border/50 bg-background grid min-w-32 items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',\n className,\n )}\n >\n {!nestLabel ? tooltipLabel : null}\n <div className=\"grid gap-1.5\">\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n return (\n <div\n key={index}\n className={cn(\n '[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',\n indicator === 'dot' && 'items-center',\n )}\n >\n {formatter && item?.value !== undefined && item.name ? (\n formatter(item.value, item.name, item, index, item.payload)\n ) : (\n <>\n {itemConfig?.icon ? (\n <itemConfig.icon />\n ) : (\n !hideIndicator && (\n <div\n className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {\n 'h-2.5 w-2.5': indicator === 'dot',\n 'w-1': indicator === 'line',\n 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',\n 'my-0.5': nestLabel && indicator === 'dashed',\n })}\n style={\n {\n '--color-bg': indicatorColor,\n '--color-border': indicatorColor,\n } as React.CSSProperties\n }\n />\n )\n )}\n <div\n className={cn(\n 'flex flex-1 justify-between leading-none',\n nestLabel ? 'items-end' : 'items-center',\n )}\n >\n <div className=\"grid gap-1.5\">\n {nestLabel ? tooltipLabel : null}\n <span className=\"text-muted-foreground\">{itemConfig?.label ?? item.name}</span>\n </div>\n {item.value !== null && item.value !== undefined && (\n <span className=\"text-foreground font-mono font-medium tabular-nums\">\n {typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)}\n </span>\n )}\n </div>\n </>\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nconst ChartLegend = RechartsPrimitive.Legend;\n\nfunction ChartLegendContent({\n className,\n hideIcon = false,\n payload,\n verticalAlign = 'bottom',\n nameKey,\n}: React.ComponentProps<'div'> & {\n hideIcon?: boolean;\n nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps) {\n const { config } = useChart();\n\n if (!payload?.length) {\n return null;\n }\n\n return (\n <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n\n return (\n <div\n key={index}\n className={cn('[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3')}\n >\n {itemConfig?.icon && !hideIcon ? (\n <itemConfig.icon />\n ) : (\n <div\n className=\"h-2 w-2 shrink-0 rounded-[2px]\"\n style={{\n backgroundColor: item.color,\n }}\n />\n )}\n {itemConfig?.label}\n </div>\n );\n })}\n </div>\n );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n if (typeof payload !== 'object' || payload === null) {\n return undefined;\n }\n\n const payloadPayload =\n 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null\n ? payload.payload\n : undefined;\n\n let configLabelKey: string = key;\n\n if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {\n configLabelKey = payload[key as keyof typeof payload] as string;\n } else if (\n payloadPayload &&\n key in payloadPayload &&\n typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'\n ) {\n configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;\n }\n\n return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport { ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent };\n"],"mappings":";;;;;A,aAQMY,IAAS;CAAE,OAAO;CAAI,MAAM;AAAQ,GAEpCC,IAAoB;CAAE,OAAO;CAAK,QAAQ;AAAI,GAe9CC,IAAed,EAAM,cAAwC,IAAI;AAEvE,SAASe,IAAW;CAClB,IAAMC,IAAUhB,EAAM,WAAWc,CAAY;CAE7C,IAAI,CAACE,GACH,MAAU,MAAM,mDAAmD;CAGrE,OAAOA;AACT;AAEA,SAASC,EAAe,EACtB,OACA,cACA,aACA,WACA,sBAAmBJ,GACnB,GAAGK,KAQF;CACD,IAAMC,IAAWnB,EAAM,MAAM,GACvBoB,IAAU,SAASC,KAAMF,EAAS,QAAQ,MAAM,EAAE;CAExD,OACE,iBAAA,GAAAR,EAAA,I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