@carlonicora/nextjs-jsonapi 3.25.0 → 3.26.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/dist/{BlockNoteEditor-HKS6AXDA.js → BlockNoteEditor-4EIKMNY3.js} +20 -10
- package/dist/BlockNoteEditor-4EIKMNY3.js.map +1 -0
- package/dist/{BlockNoteEditor-46O3JC4Z.mjs → BlockNoteEditor-AXYVDDXM.mjs} +13 -3
- package/dist/{BlockNoteEditor-46O3JC4Z.mjs.map → BlockNoteEditor-AXYVDDXM.mjs.map} +1 -1
- package/dist/billing/index.js +335 -335
- package/dist/billing/index.mjs +1 -1
- package/dist/{chunk-Y3OKEQGL.js → chunk-ABVTYQIJ.js} +578 -363
- package/dist/chunk-ABVTYQIJ.js.map +1 -0
- package/dist/{chunk-KLV6RLDE.js → chunk-GKDHYB2R.js} +2 -2
- package/dist/chunk-GKDHYB2R.js.map +1 -0
- package/dist/{chunk-XDYILJ2S.mjs → chunk-QWZAGQWJ.mjs} +546 -331
- package/dist/chunk-QWZAGQWJ.mjs.map +1 -0
- package/dist/{chunk-4Z2UONN2.mjs → chunk-U65JPKO3.mjs} +2 -2
- package/dist/chunk-U65JPKO3.mjs.map +1 -0
- package/dist/client/index.js +2 -2
- package/dist/client/index.mjs +1 -1
- package/dist/components/index.d.mts +16 -3
- package/dist/components/index.d.ts +16 -3
- package/dist/components/index.js +4 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +3 -1
- package/dist/contexts/index.js +2 -2
- package/dist/contexts/index.mjs +1 -1
- package/dist/features/analytics/index.js +100 -100
- package/dist/features/analytics/index.js.map +1 -1
- package/dist/features/analytics/index.mjs +5 -5
- package/dist/features/analytics/index.mjs.map +1 -1
- package/dist/features/help/index.js +36 -36
- package/dist/features/help/index.js.map +1 -1
- package/dist/features/help/index.mjs +6 -6
- package/dist/features/help/index.mjs.map +1 -1
- package/dist/features/tokenusage/index.js +103 -103
- package/dist/features/tokenusage/index.js.map +1 -1
- package/dist/features/tokenusage/index.mjs +4 -4
- package/dist/features/tokenusage/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/containers/PageContainer.tsx +1 -1
- package/src/components/containers/RoundPageContainer.tsx +60 -16
- package/src/components/containers/RoundPageContainerTitle.tsx +75 -35
- package/src/components/editors/BlockNoteEditor.tsx +13 -1
- package/src/components/forms/EntityMultiSelector.tsx +4 -4
- package/src/components/forms/EntitySelector.tsx +4 -4
- package/src/components/forms/FormBlockNote.tsx +21 -1
- package/src/components/forms/FormCheckbox.tsx +6 -2
- package/src/components/forms/__tests__/useEditorDialog.test.ts +47 -0
- package/src/components/forms/useEditorDialog.ts +22 -0
- package/src/components/navigations/Breadcrumb.tsx +45 -16
- package/src/components/navigations/Header.tsx +16 -3
- package/src/components/navigations/MobileNavigationBar.tsx +12 -0
- package/src/components/navigations/__tests__/MobileNavigationBar.spec.tsx +17 -0
- package/src/components/tables/ContentListTable.tsx +52 -32
- package/src/features/analytics/components/AnalyticsAdminFilterBar.tsx +9 -6
- package/src/features/analytics/components/AnalyticsBreakdownTable.tsx +2 -1
- package/src/features/assistant/components/parts/AssistantBlockNoteComposer.tsx +1 -1
- package/src/features/assistant/components/parts/AssistantComposer.tsx +1 -1
- package/src/features/assistant-message/components/MessageItem.tsx +2 -2
- package/src/features/assistant-message/components/parts/tabs/CitationsTab.tsx +23 -5
- package/src/features/auth/components/containers/AuthContainer.tsx +8 -1
- package/src/features/company/components/details/CompanyContent.tsx +3 -1
- package/src/features/company/components/details/CompanyDetails.tsx +9 -1
- package/src/features/company/components/details/TokenStatusIndicator.tsx +42 -13
- package/src/features/help/components/HelpHeader.tsx +7 -5
- package/src/features/tokenusage/components/TokenUsageAdminFilterBar.tsx +9 -6
- package/src/features/tokenusage/lib/__tests__/formatters.spec.ts +21 -0
- package/src/features/tokenusage/lib/formatters.ts +5 -1
- package/src/shadcnui/ui/button.tsx +1 -1
- package/src/shadcnui/ui/checkbox.tsx +1 -1
- package/src/shadcnui/ui/command.tsx +4 -4
- package/src/shadcnui/ui/dialog.tsx +2 -0
- package/src/shadcnui/ui/input.tsx +1 -1
- package/src/shadcnui/ui/popover.tsx +9 -0
- package/src/shadcnui/ui/select.tsx +1 -1
- package/src/shadcnui/ui/sheet.tsx +8 -1
- package/src/shadcnui/ui/table.tsx +2 -2
- package/src/shadcnui/ui/textarea.tsx +1 -1
- package/dist/BlockNoteEditor-HKS6AXDA.js.map +0 -1
- package/dist/chunk-4Z2UONN2.mjs.map +0 -1
- package/dist/chunk-KLV6RLDE.js.map +0 -1
- package/dist/chunk-XDYILJ2S.mjs.map +0 -1
- package/dist/chunk-Y3OKEQGL.js.map +0 -1
|
@@ -13,7 +13,7 @@ function createUsageFormatters(locale, currency) {
|
|
|
13
13
|
const decimal = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (value, decimals) => value.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }), "decimal");
|
|
14
14
|
const dayFormat = new Intl.DateTimeFormat(locale, { day: "numeric", month: "short", timeZone: "UTC" });
|
|
15
15
|
const monthFormat = new Intl.DateTimeFormat(locale, { month: "short", year: "numeric", timeZone: "UTC" });
|
|
16
|
-
const compactFormat = new Intl.NumberFormat(locale, { notation: "compact",
|
|
16
|
+
const compactFormat = new Intl.NumberFormat(locale, { notation: "compact", maximumSignificantDigits: 3 });
|
|
17
17
|
const collator = new Intl.Collator(locale);
|
|
18
18
|
return {
|
|
19
19
|
decimal,
|
|
@@ -107,4 +107,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, seriesColor, "seriesColor");
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
exports.createUsageFormatters = createUsageFormatters; exports.useUsageFormatters = useUsageFormatters; exports.metricValue = metricValue; exports.cacheHitPercentage = cacheHitPercentage; exports.percentageDelta = percentageDelta; exports.CATEGORICAL_CEILING = CATEGORICAL_CEILING; exports.OTHER_COLOR = OTHER_COLOR; exports.SEQUENTIAL_RAMP = SEQUENTIAL_RAMP; exports.seriesColor = seriesColor;
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-GKDHYB2R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-GKDHYB2R.js","../src/features/tokenusage/lib/formatters.ts","../src/features/tokenusage/lib/metrics.ts","../src/features/tokenusage/lib/palette.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACLA,qCAA0B;AAC1B,8BAAwB;AAsCjB,SAAS,qBAAA,CAAsB,MAAA,EAAgB,QAAA,EAAmC;AACvF,EAAA,MAAM,OAAA,mCACJ,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,EAAQ,EAAE,KAAA,EAAO,UAAA,EAAY,QAAA,EAAU,eAAA,EAAiB,eAAe,CAAC,CAAA,mBAC3F,aAAA,mBAAc,CAAC,CAAA,qBACf,IAAA,mBAAK,CAAC,IAAA,EAAA,GAAS,IAAA,CAAK,KAAA,IAAS,UAAU,CAAA,6BAAG,OAAA,UAAS,UAAA;AAExD,EAAA,MAAM,QAAA,kBAAU,qCAAA,CAAC,KAAA,EAAe,QAAA,EAAA,GAC9B,KAAA,CAAM,cAAA,CAAe,MAAA,EAAQ,EAAE,qBAAA,EAAuB,QAAA,EAAU,qBAAA,EAAuB,SAAS,CAAC,CAAA,EADnF,SAAA,CAAA;AAGhB,EAAA,MAAM,UAAA,EAAY,IAAI,IAAA,CAAK,cAAA,CAAe,MAAA,EAAQ,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,MAAM,CAAC,CAAA;AACrG,EAAA,MAAM,YAAA,EAAc,IAAI,IAAA,CAAK,cAAA,CAAe,MAAA,EAAQ,EAAE,KAAA,EAAO,OAAA,EAAS,IAAA,EAAM,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA;AAKxG,EAAA,MAAM,cAAA,EAAgB,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,EAAQ,EAAE,QAAA,EAAU,SAAA,EAAW,wBAAA,EAA0B,EAAE,CAAC,CAAA;AACxG,EAAA,MAAM,SAAA,EAAW,IAAI,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AAEzC,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IAEA,WAAA,CAAY,KAAA,EAAO,MAAA,EAAQ;AACzB,MAAA,GAAA,CAAI,OAAA,IAAW,MAAA,EAAQ,OAAO,CAAA,EAAA;AAIJ,MAAA;AACH,MAAA;AACzB,IAAA;AAE0B,IAAA;AACI,MAAA;AAC9B,IAAA;AAE6B,IAAA;AACF,MAAA;AAC3B,IAAA;AAEe,IAAA;AACe,MAAA;AAC9B,IAAA;AAE6B,IAAA;AACd,MAAA;AACU,MAAA;AACzB,IAAA;AAEc,IAAA;AACgB,MAAA;AAC9B,IAAA;AACF,EAAA;AACF;AAnDgB;AA0DsC;AAC3B,EAAA;AACR,EAAA;AACI,EAAA;AACvB;AAJgB;ADlDqB;AACA;AEzBuC;AACxC,EAAA;AACD,EAAA;AACP,EAAA;AAC5B;AAJgB;AAUmC;AAC3B,EAAA;AACO,EAAA;AAC/B;AAHgB;AAYiC;AACzB,EAAA;AACQ,EAAA;AAChC;AAHgB;AFoBqB;AACA;AGwDQ;AAC3C,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAG4C;AAC1C,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAcmC;AAOR;AAcuB;AAUA;AAE3B;AAYsC;AACjC,EAAA;AACO,EAAA;AACnC;AAHgB;AHzGqB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-GKDHYB2R.js","sourcesContent":[null,"\"use client\";\n\nimport { useLocale } from \"next-intl\";\nimport { useMemo } from \"react\";\nimport type { Metric } from \"../data/tokenusage-admin.types\";\nimport { getTokenUsageCurrency } from \"./config\";\n\nexport type UsageFormatters = {\n /** Locale-aware fixed-decimal number, e.g. 9.46 → \"9,46\" in it-IT. */\n decimal(value: number, decimals: number): string;\n /** Currency for cost, 2 decimals for credits, whole numbers for tokens. */\n metricValue(value: number, metric: Metric): string;\n /** Currency with an explicit decimal count — the per-call tile needs 4. */\n currency(value: number, decimals: number): string;\n /** Percentage with one decimal by default, e.g. 60 → \"60,0 %\" in it-IT. */\n percent(value: number, decimals?: number): string;\n /** Compact notation for axis ticks, e.g. 1500000 → \"1,5 Mln\" in it-IT. */\n compact(value: number): string;\n /** A \"YYYY-MM-DD\" bucket key rendered as an axis or tooltip label, in UTC. */\n bucketDate(iso: string, granularity: \"day\" | \"week\" | \"month\"): string;\n /** Locale collation for client-side table sorting. */\n compare(a: string, b: string): number;\n};\n\n/**\n * Builds every formatter the token-usage surfaces need, for one locale and one\n * currency.\n *\n * A pure factory on purpose: it takes no React context, so the arithmetic and\n * the formatting are unit-testable without rendering, and a server component or\n * a test can construct a set for an arbitrary locale.\n *\n * The currency symbol is placed with a space rather than through\n * `style: \"currency\"`, which is what the previous hard-coded implementation\n * rendered (\"€ 9,46\"). Keeping that shape means a consuming app on EUR sees\n * byte-identical output after this refactor.\n *\n * `bucketDate` formats in UTC, always. The wire value is a `type: \"date\"` — a\n * calendar day — parsed to UTC midnight; reading it back with local getters\n * would shift the label a day early west of UTC.\n */\nexport function createUsageFormatters(locale: string, currency: string): UsageFormatters {\n const symbol =\n new Intl.NumberFormat(locale, { style: \"currency\", currency, currencyDisplay: \"narrowSymbol\" })\n .formatToParts(0)\n .find((part) => part.type === \"currency\")?.value ?? currency;\n\n const decimal = (value: number, decimals: number): string =>\n value.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });\n\n const dayFormat = new Intl.DateTimeFormat(locale, { day: \"numeric\", month: \"short\", timeZone: \"UTC\" });\n const monthFormat = new Intl.DateTimeFormat(locale, { month: \"short\", year: \"numeric\", timeZone: \"UTC\" });\n // Axis ticks step by 1, 2, 2.5 or 5 times a power of ten, so a tick never needs\n // more than three significant digits. A fixed one-decimal cap rounded a 0.05\n // step into repeated labels (0.1, 0.1, 0.2, 0.2); significant digits keep every\n // tick distinct at any scale (0.05, 0.15, 1.25K).\n const compactFormat = new Intl.NumberFormat(locale, { notation: \"compact\", maximumSignificantDigits: 3 });\n const collator = new Intl.Collator(locale);\n\n return {\n decimal,\n\n metricValue(value, metric) {\n if (metric === \"cost\") return `${symbol} ${decimal(value, 2)}`;\n // Credits are stored to 4 decimals (round4(cost / creditCost)), but that\n // precision is noise to a reader comparing rows: one decimal is enough to\n // separate two values and keeps the columns narrow enough to scan.\n if (metric === \"credits\") return decimal(value, 1);\n return decimal(value, 0);\n },\n\n currency(value, decimals) {\n return `${symbol} ${decimal(value, decimals)}`;\n },\n\n percent(value, decimals = 1) {\n return `${decimal(value, decimals)} %`;\n },\n\n compact(value) {\n return compactFormat.format(value);\n },\n\n bucketDate(iso, granularity) {\n const date = new Date(`${iso}T00:00:00.000Z`);\n return granularity === \"month\" ? monthFormat.format(date) : dayFormat.format(date);\n },\n\n compare(a, b) {\n return collator.compare(a, b);\n },\n };\n}\n\n/**\n * The formatter set for the current request's locale and the app's configured\n * currency. Memoised on both, so the Intl objects are built once per locale\n * rather than on every render.\n */\nexport function useUsageFormatters(): UsageFormatters {\n const locale = useLocale();\n const currency = getTokenUsageCurrency();\n return useMemo(() => createUsageFormatters(locale, currency), [locale, currency]);\n}\n","import type { Metric } from \"../data/tokenusage-admin.types\";\n\n/**\n * Locale-free arithmetic for the token-usage surfaces.\n *\n * Everything that turns a number into a STRING lives in `./formatters` instead,\n * because it depends on the request's locale and the app's configured currency.\n * This file stays pure arithmetic so it needs neither.\n */\n\n/**\n * The metric field set every admin token-usage resource carries. Declared\n * structurally so it accepts the summary, timeline and breakdown interfaces\n * alike — all three expose exactly these getters.\n */\nexport type TokenUsageMetrics = {\n cost: number;\n credits: number;\n tokensIn: number;\n tokensOut: number;\n cached: number;\n calls: number;\n};\n\n/** Reads the single number a row contributes for the currently selected metric. */\nexport function metricValue(row: TokenUsageMetrics, metric: Metric): number {\n if (metric === \"cost\") return row.cost;\n if (metric === \"credits\") return row.credits;\n return row.tokensIn + row.tokensOut;\n}\n\n/**\n * Share of cached input tokens. Returns 0 rather than NaN when the window holds\n * no input tokens at all, so the tile renders \"0,0 %\" instead of \"NaN %\".\n */\nexport function cacheHitPercentage(cached: number, tokensIn: number): number {\n if (!tokensIn) return 0;\n return (cached / tokensIn) * 100;\n}\n\n/**\n * Percentage change of `current` against `previous`, rounded to a whole number.\n *\n * Returns `undefined` when the previous window is zero — there is no meaningful\n * percentage change from nothing, and rendering Infinity would be worse than\n * rendering nothing. Callers show an em dash in that slot.\n */\nexport function percentageDelta(current: number, previous: number): number | undefined {\n if (!previous) return undefined;\n return Math.round(((current - previous) / previous) * 100);\n}\n","/**\n * Chart palette for the administrative token-usage dashboard.\n *\n * Every value here is a documented step of the dataviz skill's reference ramps —\n * nothing was eyeballed, nothing was hand-mixed. The palette was run through the\n * skill's validator against THIS application's real chart surfaces in both modes.\n * The verbatim output is below.\n *\n * The surface is `--card`, NOT `--background`. Every chart that uses this palette\n * is painted inside a `<Card>`, so the card is the surface the marks actually sit\n * on — and in dark mode it is the *lighter* of the two (`oklch(0.205 0 0)` vs the\n * background's `oklch(0.145 0 0)`), which is the harder case for contrast. Taken\n * from `apps/web/src/app/globals.css` (narr8 declares two `:root`/`.dark` pairs;\n * the LATER pair wins, and it is the one read here) — light `oklch(1 0 0)`, dark\n * `oklch(0.205 0 0)`. a360ai declares the same two values.\n *\n * oklch→hex conversion: the algebraic inverse of the Björn Ottosson OKLab\n * matrices — the same matrices the validator applies in the forward direction —\n * giving light `#ffffff` and dark `#171717`. Cross-checked by feeding it the\n * previously recorded background value, which it reproduces exactly:\n * `oklch(0.145 0 0)` → `#0a0a0a`. ✓\n *\n * Light and dark are two SELECTED sets of steps, chosen for their own surface —\n * never one set with its lightness flipped at runtime. Consumers pick a set from\n * the resolved theme (`seriesColor(i, mode)` / `sequentialColor(i, mode)`).\n *\n * ---------------------------------------------------------------------------\n * VALIDATOR OUTPUT — dataviz `scripts/validate_palette.js`, run 2026-08-15\n * ---------------------------------------------------------------------------\n *\n * $ node scripts/validate_palette.js \"#2a78d6,#eb6834,#1baf7a,#eda100,#e87ba4,#008300,#4a3aa7\" --mode light --surface \"#ffffff\"\n *\n * Palette (light, surface #ffffff, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.43–0.77\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #eda100↔#1baf7a ΔE 9.1 (protan) · tritan 5.8\n * [PASS] Normal-vision floor worst adjacent #e87ba4↔#eda100 ΔE 19.6 (normal)\n * [WARN] Contrast vs surface below 3:1 — relief required (visible labels or table view): [[\"#1baf7a\",2.82],[\"#eda100\",2.17],[\"#e87ba4\",2.69]]\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#3987e5,#d95926,#199e70,#c98500,#d55181,#008300,#9085e9\" --mode dark --surface \"#171717\"\n *\n * Palette (dark, surface #171717, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.48–0.67\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #c98500↔#199e70 ΔE 8.4 (protan) · tritan 8.7\n * [PASS] Normal-vision floor worst adjacent #d55181↔#c98500 ΔE 19.3 (normal)\n * [PASS] Contrast vs surface all 7 >= 3:1\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#104281,#1c5cab,#2a78d6,#5598e7,#86b6ef\" --mode light --surface \"#ffffff\" --ordinal\n *\n * Palette (light, surface #ffffff, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #86b6ef at 2.11:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * $ node scripts/validate_palette.js \"#9ec5f4,#6da7ec,#3987e5,#256abf,#184f95\" --mode dark --surface \"#171717\" --ordinal\n *\n * Palette (dark, surface #171717, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #184f95 at 2.21:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * OTHER_COLOR is achromatic, so the categorical checks (which gate hue identity)\n * do not apply to it; it was gated on contrast alone with the validator's own\n * `contrast()` export: 3.59:1 on `#ffffff`, 4.99:1 on `#171717` — both clear 3:1.\n *\n * ---------------------------------------------------------------------------\n * WHAT THE RESULTS OBLIGE US TO DO\n * ---------------------------------------------------------------------------\n *\n * - NO COLOUR VALUE CHANGED in the move from `--background` to `--card`. Every\n * gate that passed on the background still passes on the card, so re-stepping\n * a hue would have been churn, not a fix. Only the recorded surface, the\n * recorded numbers and this prose changed.\n * - The dark set still clears 3:1 on the LIGHTER card surface: the worst slot is\n * green `#008300` at 3.63:1, and the ordinal ramp's surface-nearest step lands\n * at 2.21:1 (down from 2.44:1 on the background) — still above the 2:1 gate.\n * That headroom is thin, so a future card-surface lightening MUST re-run these\n * four commands rather than assume the set still holds.\n * - The light-mode contrast WARN is NOT dismissable. Three slots (aqua, yellow,\n * magenta) sit below 3:1 on white, so every surface that paints with this\n * palette MUST ship the relief channel: a visible legend, direct labels and a\n * tooltip carrying the value in text. The timeline chart and the breakdown\n * table both do. The light card is `#ffffff`, identical to the light\n * background, so this WARN is unchanged rather than newly incurred.\n * - CVD separation is measured on ADJACENT pairs, which is the correct pairlist\n * for stacked bars, grouped bars and lines — the only forms this palette paints.\n * A scatter / bubble / small-multiples chart would need `--pairs all`, which\n * caps the usable slot count at three; do not reuse this array there without\n * re-running the validator with that flag.\n */\n\n/** Which surface the colours are being painted on. */\nexport type ChartMode = \"light\" | \"dark\";\n\n/**\n * The chart surfaces the palette was validated against (globals.css `--card`).\n *\n * `--card`, never `--background`: the charts are painted inside a `<Card>`.\n */\nexport const CHART_SURFACE: Readonly<Record<ChartMode, string>> = {\n light: \"#ffffff\",\n dark: \"#171717\",\n};\n\n/**\n * Categorical slots, in FIXED order. Slot n is series n — the order is the\n * CVD-safety mechanism, not decoration, so it is never re-ordered and never\n * cycled. The two-series default (customer / platform) takes slots 0 and 1.\n *\n * Hues, in order: blue, orange, aqua, yellow, magenta, green, violet.\n */\nconst CATEGORICAL_LIGHT: readonly string[] = [\n \"#2a78d6\",\n \"#eb6834\",\n \"#1baf7a\",\n \"#eda100\",\n \"#e87ba4\",\n \"#008300\",\n \"#4a3aa7\",\n];\n\n/** The same seven hues, re-stepped for the dark surface. Not a lightness flip. */\nconst CATEGORICAL_DARK: readonly string[] = [\n \"#3987e5\",\n \"#d95926\",\n \"#199e70\",\n \"#c98500\",\n \"#d55181\",\n \"#008300\",\n \"#9085e9\",\n];\n\n/**\n * The default (light-surface) categorical set.\n *\n * Prefer `seriesColor(index, mode)` — this array exists for consumers that only\n * need the documented default order.\n */\nexport const CATEGORICAL: readonly string[] = CATEGORICAL_LIGHT;\n\n/**\n * How many series may carry their own identity hue. An 8th series is NEVER a\n * generated hue: it folds into `other`.\n */\nexport const CATEGORICAL_CEILING = CATEGORICAL_LIGHT.length;\n\n/**\n * The \"other\" rollup colour: deliberately achromatic so it reads as \"not an\n * identity\" beside the seven hues. Same step in both modes — it clears 3:1 on\n * both card surfaces (3.59:1 on `#ffffff`, 4.99:1 on `#171717`).\n */\nexport const OTHER_COLOR = \"#898781\";\n\n/**\n * Sequential (single-hue, blue) ramp for MAGNITUDE, indexed by rank position:\n * index 0 is rank 1 — the largest value — so the strongest step leads.\n *\n * On the light surface \"strongest\" is the darkest step; on the dark surface it\n * is the lightest. The anchor flips with the surface, which is why there are two\n * selected sets rather than one array reversed at runtime.\n *\n * Five steps, not eight: with the adjacent-ΔL ≥ 0.06 gate and the ≥ 2:1\n * surface-contrast gate on the step nearest the surface, the blue ramp fits\n * exactly five distinguishable steps. Consumers clamp past the end.\n */\nconst SEQUENTIAL_RAMP_LIGHT: readonly string[] = [\"#104281\", \"#1c5cab\", \"#2a78d6\", \"#5598e7\", \"#86b6ef\"];\n\nconst SEQUENTIAL_RAMP_DARK: readonly string[] = [\"#9ec5f4\", \"#6da7ec\", \"#3987e5\", \"#256abf\", \"#184f95\"];\n\n/**\n * The default (light-surface) sequential ramp.\n *\n * Prefer `sequentialColor(index, mode)` — this array exists for consumers that\n * only need the documented default.\n */\nexport const SEQUENTIAL_RAMP: readonly string[] = SEQUENTIAL_RAMP_LIGHT;\n\nconst categoricalSet = (mode: ChartMode): readonly string[] => (mode === \"dark\" ? CATEGORICAL_DARK : CATEGORICAL_LIGHT);\n\nconst sequentialSet = (mode: ChartMode): readonly string[] =>\n mode === \"dark\" ? SEQUENTIAL_RAMP_DARK : SEQUENTIAL_RAMP_LIGHT;\n\n/**\n * The identity colour for series `index`.\n *\n * Never generates a hue and never cycles: anything at or past the ceiling gets\n * `OTHER_COLOR`, because a series past the ceiling should already have been\n * folded into the \"other\" bucket by the caller.\n */\nexport function seriesColor(index: number, mode: ChartMode = \"light\"): string {\n if (index < 0 || index >= CATEGORICAL_CEILING) return OTHER_COLOR;\n return categoricalSet(mode)[index];\n}\n\n/**\n * Both mode steps for series `index`, shaped for a shadcn `ChartConfig` entry's\n * `theme` field.\n */\nexport function seriesTheme(index: number): { light: string; dark: string } {\n return { light: seriesColor(index, \"light\"), dark: seriesColor(index, \"dark\") };\n}\n\n/**\n * The magnitude colour for rank position `index`, clamped to the last step so a\n * long list keeps its weakest step rather than falling off the ramp.\n */\nexport function sequentialColor(index: number, mode: ChartMode = \"light\"): string {\n const ramp = sequentialSet(mode);\n const clamped = Math.min(Math.max(index, 0), ramp.length - 1);\n return ramp[clamped];\n}\n"]}
|