@squadbase/vantage 0.7.0-dev1.70b058b → 0.7.0-dev1.78e4b64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-4KMBJHNZ.js → chunk-GNGDOPBT.js} +1187 -213
- package/dist/chunk-GNGDOPBT.js.map +1 -0
- package/dist/{chunk-TRMHNMMZ.js → chunk-LYUGDHSF.js} +3 -3
- package/dist/{chunk-TRMHNMMZ.js.map → chunk-LYUGDHSF.js.map} +1 -1
- package/dist/{chunk-QNOX7WLZ.js → chunk-MQUIAP66.js} +69 -4
- package/dist/chunk-MQUIAP66.js.map +1 -0
- package/dist/{chunk-2IAPIOPS.js → chunk-P2KIHF65.js} +2 -2
- package/dist/chunk-P2KIHF65.js.map +1 -0
- package/dist/{chunk-3RJEOP3J.js → chunk-XRKSIC5Z.js} +5 -3
- package/dist/chunk-XRKSIC5Z.js.map +1 -0
- package/dist/components/index.d.ts +170 -6
- package/dist/components/index.js +4 -4
- package/dist/{delta-text-CbrOaW83.d.ts → delta-text-tav2Lh5d.d.ts} +1 -1
- package/dist/doc/index.d.ts +2 -2
- package/dist/doc/index.js +4 -4
- package/dist/{format-DihQkL1N.d.ts → format-D34piCei.d.ts} +2 -1
- package/dist/slide/index.d.ts +2 -2
- package/dist/slide/index.js +3 -3
- package/dist/table/index.js +4 -5
- package/dist/table/index.js.map +1 -1
- package/dist/ui/index.js +2 -3
- package/dist/ui/index.js.map +1 -1
- package/docs/en/parts/page-shell.md +1 -1
- package/docs/ja/parts/page-shell.md +1 -1
- package/package.json +2 -2
- package/registry/parts.json +4974 -0
- package/registry/ui/combo-chart.tsx +2 -1
- package/registry/ui/dashboard-card.tsx +3 -1
- package/registry/ui/data-table.tsx +3 -1
- package/registry/ui/delta.tsx +3 -1
- package/registry/ui/filter-bar.tsx +3 -1
- package/registry/ui/funnel-steps.tsx +1 -1
- package/registry/ui/kpi-card.tsx +3 -1
- package/registry/ui/metric-value.tsx +2 -2
- package/registry/ui/page-shell.tsx +25 -4
- package/registry/ui/paired-chart.tsx +1 -1
- package/registry/ui/pivot-table.tsx +2 -1
- package/registry/ui/progress-circle.tsx +2 -2
- package/registry/ui/sparkline.tsx +1 -1
- package/registry/ui/treemap.tsx +2 -1
- package/dist/chunk-2IAPIOPS.js.map +0 -1
- package/dist/chunk-3RJEOP3J.js.map +0 -1
- package/dist/chunk-4KMBJHNZ.js.map +0 -1
- package/dist/chunk-NZ5QIIG4.js +0 -74
- package/dist/chunk-NZ5QIIG4.js.map +0 -1
- package/dist/chunk-QNOX7WLZ.js.map +0 -1
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* ComboChart — bars, lines and areas on one category / time axis, with up to two value axes (left and right).
|
|
6
|
+
* ComboChart — bars, lines and areas on one category / time axis, with up to two value axes (left and right); use it only to migrate a Tableau dual-axis sheet, and use `PairedChart` for a new dashboard.
|
|
7
|
+
*
|
|
7
8
|
* It exists to reproduce a Tableau dual-axis sheet faithfully (a Pareto: sales as bars, the cumulative share as a
|
|
8
9
|
* line on the right). For a new dashboard prefer PairedChart, which stacks the two measures in panels over a
|
|
9
10
|
* shared axis instead of reading two scales off one plot.
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* DashboardCardPreset — a card (title, description, action, content) for one tile that holds a chart, ranking or table; not for a single KPI, since `KpiCard` is itself a card.
|
|
7
|
+
*
|
|
8
|
+
* `DashboardCard` is the tighter card used for dashboard tiles: smaller padding
|
|
7
9
|
* than the plain `Card`, a title/description/action header, and a matching
|
|
8
10
|
* skeleton for the loading state. `DashboardCardPreset` wires the common
|
|
9
11
|
* arrangement in one prop-driven component.
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* DataTablePreset — a table (toolbar, body, pagination) over TanStack Table.
|
|
7
|
+
*
|
|
8
|
+
* `DataTable` is the compound form: `<DataTable>` owns the
|
|
7
9
|
* table instance and publishes it on context; the toolbar, body, pagination and
|
|
8
10
|
* column-visibility parts read from that context, so a page composes only the
|
|
9
11
|
* pieces it wants. `DataTablePreset` assembles the usual arrangement.
|
package/registry/ui/delta.tsx
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Delta — the change of a value against a comparison,
|
|
6
|
+
* Delta — the change of a value against a comparison, as arrow + signed change + comparison label on one line; it is not a card, so place it beside a value.
|
|
7
|
+
*
|
|
8
|
+
* It renders as arrow + signed
|
|
7
9
|
* change + comparison label ("↑ +12.4% vs. prior month"; ja: "↑ +12.4% 前月比") on one line, in the page's
|
|
8
10
|
* language (`<html lang>`) unless `locale` is given.
|
|
9
11
|
*
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* FilterBarPreset — a whole filter row built from a `FilterConfig[]`, placed at the top of a page or section.
|
|
7
|
+
*
|
|
8
|
+
* `FilterBar` is the compound form: `<FilterBar>` holds the (always
|
|
7
9
|
* controlled) filter values on context; the select, multi-select, active-chip
|
|
8
10
|
* and clear parts read and update them. `FilterBarPreset` builds the whole row
|
|
9
11
|
* from a `FilterConfig[]`.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* FunnelSteps — proportional bars for a conversion funnel. Bars are sized
|
|
6
|
+
* FunnelSteps — proportional bars for a conversion funnel; put no parts inside it. Bars are sized
|
|
7
7
|
* against the first step, so pass the steps in descending order. Set
|
|
8
8
|
* `showConversion` to print the step-to-step rate between them; the lowest
|
|
9
9
|
* rate is then the only one emphasised (in the `--negative` colour). Pass
|
package/registry/ui/kpi-card.tsx
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* KpiCard — one metric
|
|
6
|
+
* KpiCard — one metric as a card of its own (label, value, delta, target, history), so do not put it in `DashboardCardPreset`.
|
|
7
|
+
*
|
|
8
|
+
* Five tiers, following shadcn dashboard-01 SectionCards:
|
|
7
9
|
*
|
|
8
10
|
* 1. label (CardDescription, muted)
|
|
9
11
|
* 2. value (CardTitle, tabular-nums; text-4xl once the card is ≥ 320px wide (a comparison label is ~180px, so narrower cards would overlap the value))
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* MetricValue
|
|
7
|
-
* trailing unit, sized as a pair so the unit stays subordinate at every size.
|
|
6
|
+
* MetricValue — the large number in a dashboard tile (with `MetricUnit`, its
|
|
7
|
+
* trailing unit, sized as a pair so the unit stays subordinate at every size).
|
|
8
8
|
*
|
|
9
9
|
* @deprecated KPI の数字は KpiCard を使う。KpiCard は書式(`format`、単位は
|
|
10
10
|
* `{ type: "number", unit: "社" }`)・比較ラベル・増減を値から計算するので、
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* PageShell — the
|
|
6
|
+
* PageShell — the outermost frame of a page; every other part goes inside it.
|
|
7
|
+
*
|
|
8
|
+
* It is the standard page frame: a bordered header band (title,
|
|
7
9
|
* description, meta, actions), an optional summary card row, and the content
|
|
8
10
|
* area. Composed from parts so a page can use only what it needs.
|
|
9
11
|
*/
|
|
@@ -149,11 +151,30 @@ function useLocale(locale?: string | null): string {
|
|
|
149
151
|
|
|
150
152
|
/* ---------- end of inlined code ---------- */
|
|
151
153
|
|
|
152
|
-
export interface PageShellProps extends HTMLAttributes<HTMLDivElement> {
|
|
154
|
+
export interface PageShellProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
|
|
155
|
+
/** The page heading. When given, the header (title and `description`) and the content area are drawn for you; `children` go in the content area. */
|
|
156
|
+
title?: string
|
|
157
|
+
/** One line under the title. Used only with `title`. */
|
|
158
|
+
description?: string
|
|
159
|
+
}
|
|
153
160
|
|
|
154
161
|
export const PageShell = forwardRef<HTMLDivElement, PageShellProps>(
|
|
155
|
-
({ className, ...props }, ref) => (
|
|
156
|
-
<div ref={ref} data-slot="page-shell" className={cn("flex flex-col", className)} {...props}
|
|
162
|
+
({ className, title, description, children, ...props }, ref) => (
|
|
163
|
+
<div ref={ref} data-slot="page-shell" className={cn("flex flex-col", className)} {...props}>
|
|
164
|
+
{title === undefined ? (
|
|
165
|
+
children
|
|
166
|
+
) : (
|
|
167
|
+
<>
|
|
168
|
+
<PageShellHeader>
|
|
169
|
+
<PageShellHeading>
|
|
170
|
+
<PageShellTitle>{title}</PageShellTitle>
|
|
171
|
+
{description ? <PageShellDescription>{description}</PageShellDescription> : null}
|
|
172
|
+
</PageShellHeading>
|
|
173
|
+
</PageShellHeader>
|
|
174
|
+
<PageShellContent>{children}</PageShellContent>
|
|
175
|
+
</>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
157
178
|
),
|
|
158
179
|
)
|
|
159
180
|
PageShell.displayName = "PageShell"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* PairedChart — 量(棒)と率・単価(線)を、同じ期間軸の上下 2
|
|
6
|
+
* PairedChart — 量(棒)と率・単価(線)を、同じ期間軸の上下 2 段で見せる型付きグラフ(`DashboardCardPreset` の中に置く)。
|
|
7
7
|
* 二重 Y 軸は持たない: 上段が棒の値軸、下段が線の値軸で、横軸(期間)とツールチップの位置は
|
|
8
8
|
* 1 つの ECharts の中で揃っている(ホバーすると同じ期間の棒と線の値が 1 枚のツールチップに出る)。
|
|
9
9
|
* 段ごとに `format`(件数・金額・%)を持ち、率を分子・分母から計算することはしない(呼び元が値を渡す)。
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* PivotTable — a crosstab of already-aggregated rows
|
|
6
|
+
* PivotTable — a crosstab of already-aggregated rows.
|
|
7
|
+
* Row dimensions down the side (nested, with merged header
|
|
7
8
|
* cells), column dimensions across the top, and one or more measures in the cells (several measures become
|
|
8
9
|
* sub-columns). The part does not aggregate: it only places each row in its cell, and when two rows land in the
|
|
9
10
|
* same cell the later one wins.
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* ProgressCircle — a ring that fills to `value / max
|
|
7
|
-
* as children in the middle
|
|
6
|
+
* ProgressCircle — a ring that fills to `value / max`; put no parts inside it, only text (usually
|
|
7
|
+
* the percentage) as children in the middle. Plain SVG, coloured by
|
|
8
8
|
* a chart token, so a row of them in KPI tiles stays light.
|
|
9
9
|
*/
|
|
10
10
|
import { forwardRef, useEffect, useState, type ComponentProps } from "react"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Sparkline — an inline trend micro-chart. Deliberately *not* an `EChart`: a
|
|
6
|
+
* Sparkline — an inline trend micro-chart; put no parts inside it. Deliberately *not* an `EChart`: a
|
|
7
7
|
* sparkline sits inside table cells and KPI tiles by the dozen, where one
|
|
8
8
|
* ECharts instance per cell would be wasteful. This renders a single stateless
|
|
9
9
|
* `<svg>` instead, so hundreds of them stay cheap.
|
package/registry/ui/treemap.tsx
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"use client"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Treemap — parts of a whole as nested rectangles whose areas are the values
|
|
6
|
+
* Treemap — parts of a whole as nested rectangles whose areas are the values.
|
|
7
|
+
* Pass rows, the leaf column (`index`),
|
|
7
8
|
* optionally a parent column (`group`, for two levels) and the number (`value`) instead of an ECharts option.
|
|
8
9
|
*
|
|
9
10
|
* Colour is categorical by `group` (or by `index` without one): `--chart-1..5` for the largest five, the rest the
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../squadkit/registry/charts/sparkline.tsx"],"names":["Sparkline"],"mappings":";;;;;AAuCA,IAAM,QAAA,GAAW,GAAA;AAGjB,SAAS,aAAA,CAAc,MAAA,EAAkB,MAAA,EAAgB,IAAA,GAAO,CAAA,EAAa;AAC3E,EAAA,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,GAAG,MAAM,CAAA;AAC9B,EAAA,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,GAAG,MAAM,CAAA;AAC9B,EAAA,MAAM,QAAQ,GAAA,GAAM,GAAA;AACpB,EAAA,MAAM,UAAA,GAAa,SAAS,IAAA,GAAO,CAAA;AACnC,EAAA,IAAI,KAAA,KAAU,GAAG,OAAO,MAAA,CAAO,IAAI,MAAM,IAAA,GAAO,aAAa,CAAC,CAAA;AAC9D,EAAA,OAAO,MAAA,CAAO,IAAI,CAAC,CAAA,KAAM,SAAS,IAAA,GAAA,CAAS,CAAA,GAAI,GAAA,IAAO,KAAA,GAAS,UAAU,CAAA;AAC3E;AAEA,SAAS,cAAc,EAAA,EAAsB;AAC3C,EAAA,IAAI,EAAA,CAAG,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAC5B,EAAA,MAAM,OAAO,EAAA,CAAG,MAAA,GAAS,IAAI,QAAA,IAAY,EAAA,CAAG,SAAS,CAAA,CAAA,GAAK,CAAA;AAC1D,EAAA,OAAO,EAAA,CACJ,GAAA,CAAI,CAAC,CAAA,EAAG,CAAA,KAAM,GAAG,CAAA,KAAM,CAAA,GAAI,GAAA,GAAM,GAAG,CAAA,EAAA,CAAI,CAAA,GAAI,MAAM,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAA,EAAI,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,CAAA,CAAE,CAAA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WAAA,EAAa,CAAA,CAAE,IAAA,KAAS,QAAA,GAAW,CAAA,GAAI,CAAA;AAAA,gBACvC,aAAA,EAAc,OAAA;AAAA,gBACd,YAAA,EAAa,oBAAA;AAAA,gBACb,WAAW,EAAA,CAAG,gBAAA,EAAkB,EAAE,IAAA,KAAS,QAAA,GAAW,QAAQ,uBAAuB;AAAA,eAAA;AAAA,cARhF,CAAA,CAAE;AAAA,aAST;AAAA,UAEJ,CAAC;AAAA,SAAA,EACH,CAAA;AAAA,QAGD,OAAA,KAAY,SACX,aAAA,CAAc,EAAA,EAAI,MAAM,CAAA,CAAE,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,qBACnC,GAAA;AAAA,UAAC,MAAA;AAAA,UAAA;AAAA,YAEC,GAAG,IAAA,CAAK,CAAA;AAAA,YACR,GAAG,OAAA,GAAW,OAAA,GAAU,IAAA,CAAK,CAAA,GAAI,SAAU,IAAA,CAAK,CAAA;AAAA,YAChD,OAAO,IAAA,CAAK,CAAA;AAAA,YACZ,QAAQ,OAAA,GAAW,OAAA,GAAU,IAAA,CAAK,CAAA,GAAI,IAAK,IAAA,CAAK,CAAA;AAAA,YAChD,EAAA,EAAI,GAAA;AAAA,YACJ,SAAA,EAAW,EAAA,CAAG,cAAA,EAAgB,OAAA,IAAW,kCAAkC,KAAK,CAAA;AAAA,YAChF,OACE,OAAA,GACI;AAAA,cACE,YAAY,CAAA,qBAAA,EAAwB,CAAA,GAAI,IAAI,CAAA,mBAAA,EAAsB,IAAI,IAAI,CAAA,CAAA;AAAA,aAC5E,GACA;AAAA,WAAA;AAAA,UAZD;AAAA,SAeR;AAAA;AAAA;AAAA,GACL;AAEJ,CAAC;AACD,SAAA,CAAU,WAAA,GAAc,WAAA","file":"chunk-2IAPIOPS.js","sourcesContent":["\"use client\"\n\n/**\n * Sparkline — an inline trend micro-chart. Deliberately *not* an `EChart`: a\n * sparkline sits inside table cells and KPI tiles by the dozen, where one\n * ECharts instance per cell would be wasteful. This renders a single stateless\n * `<svg>` instead, so hundreds of them stay cheap.\n */\nimport { forwardRef, useEffect, useState, type SVGAttributes } from \"react\"\n\nimport { cn } from \"../lib/utils\"\nimport type { ChartHighlight } from \"../lib/types\"\n\nexport type SparklineVariant = \"line\" | \"bar\"\n\nexport interface SparklineDataPoint {\n value: number\n label?: string\n}\n\nexport interface SparklineProps extends SVGAttributes<SVGSVGElement> {\n data: SparklineDataPoint[]\n variant?: SparklineVariant\n height?: number\n /** Tailwind text-colour class; drives both stroke and fill via `currentColor`. */\n color?: string\n area?: boolean\n /** マウント時に線を引く / 棒を伸ばす。既定 `false`(`prefers-reduced-motion` では常に無効)。 */\n animate?: boolean\n /**\n * 点の強調(Tufte 流)。`\"auto\"` は最新・最大・最小の 3 点だけに小さな点を打つ\n * (最新は系列の色、最大・最小は muted)。`\"latest\"` は最新の 1 点だけ、`\"none\"` は線だけ。`variant=\"line\"` のときだけ効く。既定 `\"auto\"`。\n */\n highlight?: ChartHighlight | \"latest\"\n /** 指定すると `role=\"img\"` で読み上げ対象にする。省略時は装飾として `aria-hidden`。 */\n \"aria-label\"?: string\n className?: string\n}\n\nconst VB_WIDTH = 100\n\n/** Map raw values onto SVG y-coordinates (inverted, padded). */\nfunction normalizeData(values: number[], height: number, vPad = 2): number[] {\n const min = Math.min(...values)\n const max = Math.max(...values)\n const range = max - min\n const drawHeight = height - vPad * 2\n if (range === 0) return values.map(() => vPad + drawHeight / 2)\n return values.map((v) => height - vPad - ((v - min) / range) * drawHeight)\n}\n\nfunction buildLinePath(ys: number[]): string {\n if (ys.length === 0) return \"\"\n const step = ys.length > 1 ? VB_WIDTH / (ys.length - 1) : 0\n return ys\n .map((y, i) => `${i === 0 ? \"M\" : \"L\"}${(i * step).toFixed(2)},${y.toFixed(2)}`)\n .join(\" \")\n}\n\nfunction buildAreaPath(ys: number[], height: number): string {\n if (ys.length === 0) return \"\"\n const step = ys.length > 1 ? VB_WIDTH / (ys.length - 1) : 0\n const lastX = ((ys.length - 1) * step).toFixed(2)\n return `${buildLinePath(ys)} L${lastX},${height} L0,${height} Z`\n}\n\nexport type SparklinePointKind = \"latest\" | \"max\" | \"min\"\n\nexport interface SparklinePoint {\n kind: SparklinePointKind\n index: number\n}\n\n/**\n * The points a Tufte-style sparkline marks: the latest, the max and the min.\n * A point that is both latest and max/min is drawn once, as `latest`; a flat\n * series marks only the latest. Ties pick the most recent occurrence.\n */\nexport function sparklineHighlightPoints(values: number[]): SparklinePoint[] {\n if (values.length === 0) return []\n const last = values.length - 1\n const points: SparklinePoint[] = [{ kind: \"latest\", index: last }]\n let maxI = 0\n let minI = 0\n let max = values[0] as number\n let min = max\n values.forEach((v, i) => {\n if (v >= max) [max, maxI] = [v, i]\n if (v <= min) [min, minI] = [v, i]\n })\n const latest = values[last] as number\n if (max === min) return points\n if (max !== latest) points.push({ kind: \"max\", index: maxI })\n if (min !== latest) points.push({ kind: \"min\", index: minI })\n return points\n}\n\ninterface BarRect {\n x: number\n y: number\n w: number\n h: number\n}\n\nfunction buildBarRects(ys: number[], height: number, gap = 1): BarRect[] {\n const barW = Math.max(1, VB_WIDTH / ys.length - gap)\n return ys.map((y, i) => ({ x: i * (barW + gap), y, w: barW, h: height - y }))\n}\n\n/** Rows not given yet (a draft fills props in steps): draw the empty state, keep the same array between renders. */\nconst NO_ROWS: never[] = []\n\nexport const Sparkline = forwardRef<SVGSVGElement, SparklineProps>(function Sparkline(\n {\n data = NO_ROWS,\n variant = \"line\",\n height = 40,\n color = \"text-chart-1\",\n area = false,\n animate = false,\n highlight = \"auto\",\n \"aria-label\": ariaLabel,\n className,\n ...props\n },\n ref,\n) {\n const [mounted, setMounted] = useState(false)\n\n useEffect(() => {\n if (animate) setMounted(true)\n }, [animate])\n\n if (data.length === 0) return null\n\n const values = data.map((d) => d.value)\n const ys = normalizeData(values, height)\n const step = ys.length > 1 ? VB_WIDTH / (ys.length - 1) : 0\n const points =\n variant !== \"line\"\n ? []\n : highlight === \"auto\"\n ? sparklineHighlightPoints(values)\n : highlight === \"latest\"\n ? [{ kind: \"latest\" as const, index: values.length - 1 }]\n : []\n\n return (\n <svg\n ref={ref}\n data-slot=\"sparkline\"\n viewBox={`0 0 ${VB_WIDTH} ${height}`}\n preserveAspectRatio=\"none\"\n width=\"100%\"\n height={height}\n role={ariaLabel ? \"img\" : undefined}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? undefined : true}\n className={cn(\"overflow-visible\", className)}\n {...props}\n >\n {variant === \"line\" && (\n <>\n {area && (\n <path\n d={buildAreaPath(ys, height)}\n strokeWidth={0}\n className={cn(\"fill-current opacity-15\", color)}\n />\n )}\n <path\n d={buildLinePath(ys)}\n fill=\"none\"\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n vectorEffect=\"non-scaling-stroke\"\n pathLength={animate ? 1 : undefined}\n strokeDasharray={animate ? 1 : undefined}\n strokeDashoffset={animate ? (mounted ? 0 : 1) : undefined}\n className={cn(\"stroke-current\", animate && \"motion-reduce:transition-none!\", color)}\n style={animate ? { transition: \"stroke-dashoffset 0.6s ease-in-out\" } : undefined}\n />\n {/* A zero-length round-capped stroke with a non-scaling width stays a\n circle even though the viewBox stretches (`preserveAspectRatio=\"none\"`). */}\n {points.map((p) => {\n const x = (p.index * step).toFixed(2)\n const y = (ys[p.index] ?? 0).toFixed(2)\n return (\n <path\n key={p.kind}\n data-slot=\"sparkline-point\"\n data-point={p.kind}\n d={`M${x},${y} L${x},${y}`}\n fill=\"none\"\n strokeWidth={p.kind === \"latest\" ? 5 : 4}\n strokeLinecap=\"round\"\n vectorEffect=\"non-scaling-stroke\"\n className={cn(\"stroke-current\", p.kind === \"latest\" ? color : \"text-muted-foreground\")}\n />\n )\n })}\n </>\n )}\n\n {variant === \"bar\" &&\n buildBarRects(ys, height).map((rect, i) => (\n <rect\n key={i}\n x={rect.x}\n y={animate ? (mounted ? rect.y : height) : rect.y}\n width={rect.w}\n height={animate ? (mounted ? rect.h : 0) : rect.h}\n rx={0.5}\n className={cn(\"fill-current\", animate && \"motion-reduce:transition-none!\", color)}\n style={\n animate\n ? {\n transition: `height 0.4s ease-out ${i * 0.02}s, y 0.4s ease-out ${i * 0.02}s`,\n }\n : undefined\n }\n />\n ))}\n </svg>\n )\n})\nSparkline.displayName = \"Sparkline\"\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../squadkit/registry/lib/format.ts"],"names":[],"mappings":";;;;;AA2FO,IAAM,cAAA,GAAiB;AAGvB,IAAM,WAAA,GAAc;AAGpB,IAAM,UAAA,GAAa;AAGnB,IAAM,cAAA,GAAiB,CAAA;AAE9B,IAAM,eAAA,GAAkB,MAAA;AAExB,IAAM,aAAA,GAAgB,IAAA;AAYtB,SAAS,UAAU,MAAA,EAAmD;AACpE,EAAA,IAAI,MAAA,KAAW,MAAA,EAAW,OAAO,EAAE,MAAM,SAAA,EAAU;AACnD,EAAA,OAAO,OAAO,MAAA,KAAW,QAAA,GAAW,EAAE,IAAA,EAAM,QAAO,GAAI,MAAA;AACzD;AAeO,SAAS,WAAW,MAAA,EAA6C;AACtE,EAAA,OAAO,SAAA,CAAU,MAAM,CAAA,CAAE,IAAA;AAC3B;AAEA,SAAS,YAAA,CACP,MAAA,EACA,UAAA,EACA,iBAAA,EAC0B;AAC1B,EAAA,IAAI,iBAAA,KAAsB,MAAA,EAAW,OAAO,EAAE,0BAA0B,iBAAA,EAAkB;AAC1F,EAAA,IAAI,WAAW,MAAA,EAAW,OAAO,EAAE,qBAAA,EAAuB,MAAA,EAAQ,uBAAuB,MAAA,EAAO;AAChG,EAAA,OAAO,eAAe,MAAA,GAAY,EAAC,GAAI,EAAE,uBAAuB,UAAA,EAAW;AAC7E;AAOA,SAAS,WAAA,CAAY,MAAA,EAAgB,OAAA,EAAmC,KAAA,EAAuB;AAC7F,EAAA,IAAI,OAAA,CAAQ,aAAa,SAAA,EAAW;AAClC,IAAA,MAAM,OAAA,GAAU,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,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CAAE,QAAA,EAAU,CAAA,CAAE,MAAA,CAAO,EAAE,IAAI,CAAA;AAC3F,EAAA,MAAM,SAAA,GAAY,IAAA,CAAK,CAAA,EAAG,IAAI,CAAA;AAC9B,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,CAAC,CAAA,KAAM,KAAK,CAAC,CAAA;AACnC,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,CAAA,EAAG,IAAI,CAAA;AAC5B,EAAA,IAAI,SAAA,KAAc,SAAS,OAAO,SAAA;AAClC,EAAA,MAAM,SAAA,GAAY,eAAA,CAAgB,UAAA,CAAW,MAAM,CAAC,CAAA;AACpD,EAAA,OAAO,CAAA,EAAG,SAAS,CAAA,EAAG,SAAS,CAAA,EAAG,WAAW,IAAA,CAAK,CAAA,EAAG,KAAK,CAAA,GAAI,OAAO,CAAA,CAAA;AACvE;AAUO,SAAS,iBAAA,CAAkB,MAAc,MAAA,EAAyB;AACvE,EAAA,MAAM,QAAA,GAAW,cAAc,MAAM,CAAA;AACrC,EAAA,OAAO,IAAA,CAAK,OAAA;AAAA,IAAQ,sEAAA;AAAA,IAAwE,CAAC,KAAA,EAAO,EAAA,EAAI,EAAA,EAAI,GAAA,KAC1G,WAAW,KAAA,EAAO,GAAA,GAAM,MAAA,GAAS,YAAA,EAAc,QAAQ;AAAA,GACzD;AACF","file":"chunk-3RJEOP3J.js","sourcesContent":["import { defaultCurrency, FALLBACK_LOCALE, resolveLocale, uiLanguage } from \"./locale\"\n\n/**\n * Locale-aware number formatting shared by KPI cards, tables and charts. All\n * shortening is delegated to `Intl.NumberFormat` (`notation: \"compact\"`); this\n * module never hard-codes unit thresholds or unit strings.\n *\n * Outputs below are for ja-JP (`<html lang=\"ja\">`); en-US reads `48.2M`, `$48.2M`, `3 h 20 min`, `10/20/2026`.\n *\n * | `format` | input | ja-JP output |\n * |--------------------------------------------|--------------|----------------|\n * | `\"compact\"` (default) | `48_200_000` | `4,820万` |\n * | `\"number\"` | `1234.567` | `1,234.57` |\n * | `\"currency\"` (JPY, compact) | `48_200_000` | `¥4,820万` |\n * | `{ type: \"currency\", notation: \"standard\" }` | `48_200_000` | `¥48,200,000` |\n * | `{ type: \"currency\", currency: \"USD\" }` | `1234.5` | `$1,234.5` |\n * | `\"percent\"` — pass a **ratio** | `0.124` | `12.4%` |\n * | `{ type: \"percent\", digits: 0 }` | `0.124` | `12%` |\n * | `\"multiple\"` | `1.5` | `1.5×` |\n * | `{ type: \"number\", unit: \"件\" }` | `48_210` | `48,210件` |\n * | `{ type: \"compact\", unit: \"人\" }` | `12_345` | `1.2万人` |\n * | `\"duration\"` — pass **seconds** | `12_000` | `3時間20分` |\n * | `{ type: \"duration\", durationUnit: \"minute\" }` | `2160` | `1.5日` |\n *\n * - `percent` takes a ratio (0.124 → 12.4%). Passing 12.4 renders 1,240%. The fraction\n * digits are **fixed**, never trimmed (`PERCENT_DIGITS` = 1: 0.14 → \"14.0%\", never \"14%\"\n * beside \"11.9%\"). Pass `digits` in the format to share another count across cards.\n * - A minus sign is always U+2212 (`MINUS_SIGN`, \"−1,234\" / \"−5.0%\"), never the hyphen-minus.\n * - `currency` defaults to JPY in ja (USD otherwise) and to compact notation (万・億 in ja, K・M・B in en); pass\n * `notation: \"standard\"` for every digit (tables, invoices). In ja-JP the yen\n * sign is the half-width `¥`.\n * - `unit` is a counter appended right after the number, with no space\n * (\"48,210件\", \"1.2万人\"), for `number` / `compact` / `currency`. It is\n * ignored for `percent` and `duration`, and for `multiple` it replaces the\n * default `×` (\"2.7倍\"). Do not write it into a `valueFormatter` by hand.\n * - Charts take the same `format` a KpiCard takes (`format=\"currency\"`).\n * `toValueFormatter(format)` turns it into a function for places that need\n * one (a `valueFormatter`, table cells).\n * - Missing values (null / undefined / NaN) render as `—` (`EMPTY_VALUE`).\n * - Without a `locale`, every function here uses the page's (`<html lang>`, else `\"en-US\"`).\n * - Dates go through `formatDate` (`Intl.DateTimeFormat`): `\"date\"` → `2026/10/20`,\n * `\"datetime\"` → `2026/10/20 14:30`, `\"year-month\"` → `2026年10月`, `\"month\"` → `10月`,\n * `\"year\"` → `2026年`.\n * - A period goes through `formatDateRange`: `2026/9/23〜10/20` (same year drops the end year),\n * `2025/12/20〜2026/1/18` across years; month and day are not zero-padded.\n */\n\n/**\n * The kind of number a value is. Pick by what the number means, not by how\n * long it is: `currency` for money, `percent` for a ratio, `multiple` for a\n * factor (\"1.5×\"), `duration` for a length of time (\"3時間20分\"), `number` for\n * exact counts in tables, `compact` (default) for large headline counts (万・億).\n */\nexport type FormatKind = \"number\" | \"compact\" | \"currency\" | \"percent\" | \"multiple\" | \"duration\"\n\n/** The unit a `duration` value is measured in. */\nexport type DurationUnit = \"second\" | \"minute\" | \"hour\" | \"day\"\n\n/**\n * How to display a number: a `FormatKind` alone, or an object for digits,\n * currency, notation and a counter. The same value is accepted by KpiCard,\n * Delta, the charts (`format`) and `formatValue`.\n *\n * @example\n * \"currency\" // ¥4,820万\n * { type: \"currency\", notation: \"standard\" } // ¥48,200,000\n * { type: \"percent\", digits: 1 } // 2.0%\n * { type: \"number\", unit: \"件\" } // 48,210件\n */\nexport type ValueFormat =\n | FormatKind\n | {\n type: FormatKind\n /** Fixed number of fraction digits. */\n digits?: number\n /** ISO 4217 code for `currency`. Default `\"JPY\"` when the locale is ja, else `\"USD\"`. */\n currency?: string\n /** `currency` only: `\"compact\"` (default, 万・億) or `\"standard\"` (every digit). */\n notation?: \"compact\" | \"standard\"\n /** Counter appended after the number, e.g. `\"件\"`, `\"人\"`. Ignored for `percent` and `duration`. For `multiple` it replaces the default `×` (`\"倍\"` → `2.7倍`). */\n unit?: string\n /** 値をこの数で割ってから整形する。例: `divisor: 100`(セント → ドル)。0 と非有限は無視。 */\n divisor?: number\n /** `duration` only: the unit the value is in. Default `\"second\"`. Reads as \"45秒\" / \"12分\" / \"3時間20分\" / \"1.5日\" (`digits` sets the fraction digits of days). */\n durationUnit?: DurationUnit\n }\n\n/**\n * The fallback locale (`\"en-US\"`). A function given no `locale` uses the page's (`<html lang>`) and falls back to\n * this one when there is none (SSR, no `lang`). Every function here takes a `locale` to override it.\n */\nexport const DEFAULT_LOCALE = FALLBACK_LOCALE\n\n/** Shown in place of a missing value (null / undefined / NaN). */\nexport const EMPTY_VALUE = \"—\"\n\n/** The minus sign every formatter writes (U+2212), so a negative never mixes with a hyphen-minus. */\nexport const MINUS_SIGN = \"\\u2212\"\n\n/** Fraction digits of a `percent` value (and of the points in `formatPoints`) when `digits` is not given. Fixed, never trimmed. */\nexport const PERCENT_DIGITS = 1\n\nconst MULTIPLE_SUFFIX = \"×\"\n/** Suffix for a difference between two rates, in percentage points. */\nconst POINTS_SUFFIX = \"pt\"\n\n/** Extra options for `formatValue`. */\nexport interface FormatValueOptions {\n /** `\"auto\"` (default) signs negatives only; `\"exceptZero\"` also writes `+` on positives (for differences). */\n signDisplay?: \"auto\" | \"exceptZero\"\n /** Round to this many significant digits (e.g. 3 for an estimate: 79,653,985 → 7,970万). */\n significantDigits?: number\n}\n\ntype NormalizedFormat = Exclude<ValueFormat, FormatKind>\n\nfunction normalize(format: ValueFormat | undefined): NormalizedFormat {\n if (format === undefined) return { type: \"compact\" }\n return typeof format === \"string\" ? { type: format } : format\n}\n\n/**\n * The kind of a format, whether it was given as a string or an object. Use it\n * to branch on the meaning of a metric (e.g. a `percent` metric compares in\n * points) without unpacking `ValueFormat` yourself.\n *\n * @param format - The format as a KpiCard / chart takes it. `undefined` means the default.\n * @returns The `FormatKind`; `\"compact\"` when `format` is omitted.\n *\n * @example\n * formatKind(\"percent\") // \"percent\"\n * formatKind({ type: \"currency\", notation: \"standard\" }) // \"currency\"\n * formatKind(undefined) // \"compact\"\n */\nexport function formatKind(format: ValueFormat | undefined): FormatKind {\n return normalize(format).type\n}\n\nfunction digitOptions(\n digits: number | undefined,\n defaultMax: number | undefined,\n significantDigits: number | undefined,\n): Intl.NumberFormatOptions {\n if (significantDigits !== undefined) return { maximumSignificantDigits: significantDigits }\n if (digits !== undefined) return { minimumFractionDigits: digits, maximumFractionDigits: digits }\n return defaultMax === undefined ? {} : { maximumFractionDigits: defaultMax }\n}\n\n/**\n * Format through Intl, letting Intl decide whether the number is large enough to\n * shorten. Shortened numbers keep digit grouping (\"7,965万\"), and the full-width\n * currency sign some locales emit (\"¥\") is folded to its half-width form (\"¥\").\n */\nfunction formatParts(locale: string, options: Intl.NumberFormatOptions, value: number): string {\n if (options.notation === \"compact\") {\n const compact = new Intl.NumberFormat(locale, {\n ...options,\n useGrouping: \"always\" as unknown as boolean,\n }).formatToParts(value)\n if (!compact.some((p) => p.type === \"compact\")) return formatParts(locale, { ...options, notation: \"standard\" }, value)\n return joinParts(compact)\n }\n return joinParts(new Intl.NumberFormat(locale, options).formatToParts(value))\n}\n\nconst joinParts = (parts: Intl.NumberFormatPart[]): string =>\n parts\n .map((p) => (p.type === \"currency\" ? p.value.normalize(\"NFKC\") : p.type === \"minusSign\" ? MINUS_SIGN : p.value))\n .join(\"\")\n\n/**\n * Format a number for display — KPI values, table cells, chart labels and\n * sentences built from data (titles, summaries). See the table at the top of\n * this module.\n *\n * @param value - The number. `null` / `undefined` / `NaN` render as `—`.\n * For `percent`, a ratio (0.124 means 12.4%).\n * @param format - How to display it. Default `\"compact\"`.\n * @param locale - BCP 47 locale. Default: the page's (`<html lang>`, else `\"en-US\"`).\n * @param options - `signDisplay` and `significantDigits` (rounding for estimates).\n * @returns The display string. In ja-JP the yen sign is the half-width `¥`.\n *\n * @example\n * formatValue(48_200_000, \"currency\") // \"¥4,820万\"\n * formatValue(48_200_000, { type: \"currency\", notation: \"standard\" }) // \"¥48,200,000\"\n * formatValue(0.021, \"percent\") // \"2.1%\"\n * formatValue(0.124, \"percent\", \"ja-JP\", { signDisplay: \"exceptZero\" }) // \"+12.4%\"\n * formatValue(79_653_985, \"currency\", \"ja-JP\", { significantDigits: 3 }) // \"¥7,970万\"\n * formatValue(48_210, { type: \"number\", unit: \"件\" }) // \"48,210件\"\n * formatValue(1.5, \"multiple\") // \"1.5×\"\n * formatValue(null) // \"—\"\n */\nexport function formatValue(\n value: number | null | undefined,\n format?: ValueFormat,\n locale?: string,\n options?: FormatValueOptions,\n): string {\n if (value === null || value === undefined || Number.isNaN(value)) return EMPTY_VALUE\n locale = resolveLocale(locale)\n const { type, digits, currency, notation, unit, divisor, durationUnit } = normalize(format)\n if (divisor !== undefined && Number.isFinite(divisor) && divisor !== 0) value = value / divisor\n const signDisplay = options?.signDisplay ?? \"auto\"\n const sig = options?.significantDigits\n const withUnit = (s: string) => (unit ? `${s}${unit}` : s)\n\n switch (type) {\n case \"number\":\n return withUnit(formatParts(locale, { ...digitOptions(digits, 2, sig), signDisplay }, value))\n case \"percent\":\n return formatParts(locale, { style: \"percent\", ...digitOptions(digits ?? PERCENT_DIGITS, undefined, sig), signDisplay }, value)\n case \"currency\":\n return withUnit(\n formatParts(\n locale,\n {\n style: \"currency\",\n currency: currency ?? defaultCurrency(locale),\n notation: notation ?? \"compact\",\n ...digitOptions(digits, notation === \"standard\" ? undefined : 1, sig),\n // Compact amounts drop the currency's own minimum fraction digits outside ja (\"$50M\", not \"$50.0M\").\n ...(notation !== \"standard\" && digits === undefined && sig === undefined && uiLanguage(locale) !== \"ja\"\n ? { minimumFractionDigits: 0 }\n : {}),\n signDisplay,\n },\n value,\n ),\n )\n case \"multiple\":\n return `${formatParts(locale, { ...digitOptions(digits, 2, sig), signDisplay }, value)}${unit || MULTIPLE_SUFFIX}`\n case \"compact\":\n return withUnit(formatParts(locale, { ...digitOptions(digits, 1, sig), signDisplay, notation: \"compact\" }, value))\n case \"duration\":\n return formatDuration(value, durationUnit ?? \"second\", locale, digits, signDisplay)\n }\n}\n\nconst SECONDS_PER: Record<DurationUnit, number> = { second: 1, minute: 60, hour: 3600, day: 86_400 }\n\n/**\n * Unit words and spacing: Japanese reads \"3時間20分\" (no space, like \"48,210件\"),\n * other locales \"3 h 20 min\".\n */\nconst DURATION_WORDS = {\n ja: { day: \"日\", hour: \"時間\", minute: \"分\", second: \"秒\", sep: \"\" },\n en: { day: \"d\", hour: \"h\", minute: \"min\", second: \"s\", sep: \" \" },\n}\n\nfunction durationWords(locale: string) {\n return DURATION_WORDS[uiLanguage(locale)]\n}\n\n/**\n * A length of time in the largest sensible unit: under a minute in seconds, under\n * an hour in minutes (+ seconds), under a day in hours + minutes, from a day on\n * in days with a decimal (\"1.5日\"). Rounded before splitting, so 59.6 minutes\n * never reads \"59分60秒\".\n */\nfunction formatDuration(\n value: number,\n unit: DurationUnit,\n locale: string,\n digits: number | undefined,\n signDisplay: \"auto\" | \"exceptZero\",\n): string {\n const w = durationWords(locale)\n const abs = Math.round(Math.abs(value) * SECONDS_PER[unit])\n const join = (...parts: Array<[number, string]>) =>\n parts\n .filter(([n]) => n !== 0)\n .map(([n, u]) => `${n}${w.sep}${u}`)\n .join(w.sep) || `0${w.sep}${parts.at(-1)?.[1] ?? w.second}`\n let body: string\n let zero = false\n if (abs >= 86_400) {\n const days = new Intl.NumberFormat(locale, { maximumFractionDigits: digits ?? 1, minimumFractionDigits: digits ?? 0 })\n body = `${days.format(abs / 86_400)}${w.sep}${w.day}`\n } else if (abs >= 3600) {\n const minutes = Math.round(abs / 60)\n body = join([Math.floor(minutes / 60), w.hour], [minutes % 60, w.minute])\n } else if (abs >= 60) {\n body = join([Math.floor(abs / 60), w.minute], [abs % 60, w.second])\n } else {\n zero = abs === 0\n body = `${abs}${w.sep}${w.second}`\n }\n const sign = zero ? \"\" : value < 0 ? MINUS_SIGN : signDisplay === \"exceptZero\" ? \"+\" : \"\"\n return `${sign}${body}`\n}\n\n/**\n * Like `formatValue`, but always signed (except zero) — for a difference\n * between two values (\"+¥530万\", \"−120件\"). Use `formatPoints` instead for a\n * difference between two rates.\n *\n * @param value - The difference (current − previous). Missing values render as `—`.\n * @param format - Format of the metric itself. Default `\"compact\"`.\n * @param locale - BCP 47 locale. Default: the page's (`<html lang>`, else `\"en-US\"`).\n * @returns The signed display string; zero has no sign.\n *\n * @example\n * formatDelta(5_300_000, \"currency\") // \"+¥530万\"\n * formatDelta(-120, { type: \"number\", unit: \"件\" }) // \"−120件\"\n * formatDelta(0.031, \"percent\") // \"+3.1%\"\n * formatDelta(0, \"currency\") // \"¥0\"\n */\nexport function formatDelta(value: number | null | undefined, format?: ValueFormat, locale?: string): string {\n return formatValue(value, format, locale, { signDisplay: \"exceptZero\" })\n}\n\n/**\n * A difference between two rates in percentage points, always signed:\n * `formatPoints(0.021 - 0.026)` → `\"−0.5pt\"`. Use it instead of a relative\n * change for rate metrics (churn, conversion), where \"−19.2%\" reads as a drop\n * of nineteen points. `signDisplay: \"never\"` drops the sign (\"あと 0.5pt\").\n *\n * @param difference - The difference of two **ratios** (0.021 − 0.026). Missing values render as `—`.\n * @param locale - BCP 47 locale. Default: the page's (`<html lang>`, else `\"en-US\"`).\n * @param options - `digits`: fixed fraction digits (default `PERCENT_DIGITS` = 1, so \"0.0pt\" / \"+0.5pt\"); `signDisplay`:\n * `\"exceptZero\"` (default) or `\"never\"` when the sentence already says the direction.\n * @returns The difference in points with the `pt` suffix.\n *\n * @example\n * formatPoints(0.021 - 0.026) // \"−0.5pt\"\n * formatPoints(0.031 - 0.026) // \"+0.5pt\"\n * formatPoints(0.02 - 0.015, \"ja-JP\", { signDisplay: \"never\" }) // \"0.5pt\"(「目標まであと 0.5pt」)\n */\nexport function formatPoints(\n difference: number | null | undefined,\n locale?: string,\n options?: { digits?: number; signDisplay?: \"exceptZero\" | \"never\" },\n): string {\n if (difference === null || difference === undefined || Number.isNaN(difference)) return EMPTY_VALUE\n const digits = options?.digits ?? PERCENT_DIGITS\n const number = formatParts(\n resolveLocale(locale),\n { minimumFractionDigits: digits, maximumFractionDigits: digits, signDisplay: options?.signDisplay ?? \"exceptZero\" },\n difference * 100,\n )\n return `${number}${POINTS_SUFFIX}`\n}\n\n/**\n * Binds a format and locale into a single-argument formatter, for a chart\n * `valueFormatter` or a table cell: `valueFormatter={toValueFormatter(\"currency\")}`.\n * Prefer passing `format` to the chart directly; this is for APIs that only\n * take a function.\n *\n * @param format - How to display each value. Default `\"compact\"`.\n * @param locale - BCP 47 locale. Default: the page's (`<html lang>`, else `\"en-US\"`), read when the formatter is made.\n * @returns `(value) => string`, rendering missing values as `—`.\n *\n * @example\n * const yen = toValueFormatter(\"currency\")\n * yen(48_200_000) // \"¥4,820万\"\n * yen(null) // \"—\"\n * const count = toValueFormatter({ type: \"number\", unit: \"件\" })\n * count(48_210) // \"48,210件\"(表のセル)\n */\nexport function toValueFormatter(\n format?: ValueFormat,\n locale?: string,\n): (value: number | null | undefined) => string {\n const resolved = resolveLocale(locale)\n return (value) => formatValue(value, format, resolved)\n}\n\n/**\n * 日付の書式。何を表す日付かで選ぶ: 日単位は `\"date\"`、時刻まで要るなら `\"datetime\"`、\n * 月次の集計は `\"year-month\"`(年をまたぐ軸)か `\"month\"`(同じ年の中の軸)、年次は `\"year\"`。\n */\nexport type DateStyle = \"date\" | \"datetime\" | \"month\" | \"year-month\" | \"year\"\n\n/** `formatDate` の追加オプション。 */\nexport interface FormatDateOptions {\n /**\n * IANA のタイムゾーン名(例: `\"Asia/Tokyo\"`)。既定は実行環境のタイムゾーン。\n * サーバーとブラウザで描画が食い違う(SSR)なら固定する。日付だけの文字列(`\"2026-10-20\"`)には効かず、常にその暦日のまま出す。\n */\n timeZone?: string\n}\n\nconst DATE_STYLE_OPTIONS: Record<DateStyle, Intl.DateTimeFormatOptions> = {\n date: { year: \"numeric\", month: \"2-digit\", day: \"2-digit\" },\n datetime: { year: \"numeric\", month: \"2-digit\", day: \"2-digit\", hour: \"2-digit\", minute: \"2-digit\", hourCycle: \"h23\" },\n month: { month: \"short\" },\n \"year-month\": { year: \"numeric\", month: \"long\" },\n year: { year: \"numeric\" },\n}\n\n/** `\"2026-10-20\"` / `\"2026-10\"` はタイムゾーンを持たない暦日。UTC で解釈して UTC で出し、ずれを防ぐ。 */\nconst CALENDAR_DATE = /^\\d{4}-\\d{2}(-\\d{2})?$/\n\n/**\n * 日付を表示用の文字列にする。表のセル・タイトル・文に埋める日付に使い、`toLocaleString` や手組みの\n * `getMonth() + 1` は使わない。\n *\n * @param value - `Date`、エポックミリ秒、または日付文字列(`\"2026-10-20\"`、ISO 8601)。`null` / `undefined` / 解釈できない値は `—`。\n * @param style - 何を表す日付か。既定 `\"date\"`。\n * @param locale - BCP 47 ロケール。既定はページのロケール(`<html lang>`、無ければ `\"en-US\"`)。\n * @param options - `timeZone`。\n * @returns 表示文字列。\n *\n * @example\n * formatDate(\"2026-10-20\") // \"2026/10/20\"\n * formatDate(new Date(\"2026-10-20T05:30:00Z\"), \"datetime\", \"ja-JP\", { timeZone: \"Asia/Tokyo\" }) // \"2026/10/20 14:30\"\n * formatDate(\"2026-10-01\", \"year-month\") // \"2026年10月\"\n * formatDate(\"2026-10-01\", \"month\") // \"10月\"\n * formatDate(null) // \"—\"\n */\nexport function formatDate(\n value: Date | string | number | null | undefined,\n style: DateStyle = \"date\",\n locale?: string,\n options?: FormatDateOptions,\n): string {\n if (value === null || value === undefined || value === \"\") return EMPTY_VALUE\n const calendar = typeof value === \"string\" && CALENDAR_DATE.test(value)\n const date = value instanceof Date ? value : new Date(value)\n if (!Number.isFinite(date.getTime())) return EMPTY_VALUE\n return new Intl.DateTimeFormat(resolveLocale(locale), {\n ...DATE_STYLE_OPTIONS[style],\n timeZone: calendar ? \"UTC\" : options?.timeZone,\n }).format(date)\n}\n\nconst RANGE_SEPARATOR = { ja: \"〜\", en: \" – \" }\n\n/** `formatDateRange` のオプション。 */\nexport interface FormatDateRangeOptions extends FormatDateOptions {\n /** BCP 47 ロケール。既定はページのロケール(`<html lang>`、無ければ `\"en-US\"`)。 */\n locale?: string\n}\n\n/**\n * 期間を「2026/9/23〜10/20」の形にする。同じ年なら終了側の年を省き、年をまたぐときは両方に付ける。\n * 月日はゼロ詰めしない。区切りは日本語で「〜」、それ以外のロケールでは「 – 」。始まりと終わりが同じ日なら 1 日だけ出す。\n *\n * @param start - 期間の最初の日(`Date`、エポックミリ秒、日付文字列)。`\"2026-09-23\"` のような日付だけの文字列はその暦日のまま出す。\n * @param end - 期間の最後の日。\n * @param options - `locale` と `timeZone`。\n * @returns 表示文字列。どちらかが解釈できなければ `—`。\n *\n * @example\n * formatDateRange(\"2026-09-23\", \"2026-10-20\") // \"2026/9/23〜10/20\"\n * formatDateRange(\"2025-12-20\", \"2026-01-18\") // \"2025/12/20〜2026/1/18\"\n */\nexport function formatDateRange(\n start: Date | string | number | null | undefined,\n end: Date | string | number | null | undefined,\n options?: FormatDateRangeOptions,\n): string {\n const locale = resolveLocale(options?.locale)\n const parse = (value: Date | string | number | null | undefined) => {\n if (value === null || value === undefined || value === \"\") return null\n const calendar = typeof value === \"string\" && CALENDAR_DATE.test(value)\n const date = value instanceof Date ? value : new Date(value)\n if (!Number.isFinite(date.getTime())) return null\n return { date, timeZone: calendar ? \"UTC\" : options?.timeZone }\n }\n const a = parse(start)\n const b = parse(end)\n if (!a || !b) return EMPTY_VALUE\n const full = (x: NonNullable<typeof a>, withYear: boolean) =>\n new Intl.DateTimeFormat(locale, {\n ...(withYear ? { year: \"numeric\" } : {}),\n month: \"numeric\",\n day: \"numeric\",\n timeZone: x.timeZone,\n } as Intl.DateTimeFormatOptions).format(x.date)\n const year = (x: NonNullable<typeof a>) =>\n new Intl.DateTimeFormat(\"en-US\", { year: \"numeric\", timeZone: x.timeZone }).format(x.date)\n const startText = full(a, true)\n const sameYear = year(a) === year(b)\n const endFull = full(b, true)\n if (startText === endFull) return startText\n const separator = RANGE_SEPARATOR[uiLanguage(locale)]\n return `${startText}${separator}${sameYear ? full(b, false) : endFull}`\n}\n\n/**\n * 文中の ISO の年月・日付(`2023-04`、`2026-10-20`)を `formatDate` の書式に置き換える。期間や出典の注記のように、\n * 利用者が文字列で渡す文に日付が混ざるときの表示用(`\"2023-04 以降\"` → `\"2023年4月 以降\"`)。日付でない数字は触らない。\n *\n * @param text - 日付を含みうる文。\n * @param locale - BCP 47 ロケール。既定はページのロケール(`<html lang>`、無ければ `\"en-US\"`)。\n * @returns ISO の年月は `\"year-month\"`、年月日は `\"date\"` で整形した文。\n */\nexport function formatDatesInText(text: string, locale?: string): string {\n const resolved = resolveLocale(locale)\n return text.replace(/(?<![\\d-])(\\d{4})-(0[1-9]|1[0-2])(-(0[1-9]|[12]\\d|3[01]))?(?![\\d-])/g, (match, _y, _m, day) =>\n formatDate(match, day ? \"date\" : \"year-month\", resolved),\n )\n}\n"]}
|