banhaten 0.4.0 → 0.5.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/CHANGELOG.md +139 -100
- package/CONTRIBUTING.md +46 -44
- package/README.md +192 -190
- package/SECURITY.md +15 -15
- package/banhaten.config.example.json +11 -11
- package/docs/design-spacing.md +13 -0
- package/docs/design-system/README.md +22 -20
- package/docs/design-system/adoption-quality-remediation.md +87 -87
- package/docs/design-system/agent-usage.md +13 -13
- package/docs/design-system/appearance-presets.md +189 -189
- package/docs/design-system/appearances/default.md +94 -94
- package/docs/design-system/appearances/rounded.md +95 -95
- package/docs/design-system/appearances/sharp.md +95 -95
- package/docs/design-system/component-docs-pattern.md +81 -81
- package/docs/design-system/component-implementation-ownership-audit.md +245 -245
- package/docs/design-system/component-quality-audit-2026-08-20.md +225 -225
- package/docs/design-system/component-showcase-consistency-report.md +219 -219
- package/docs/design-system/component-token-consistency-audit.md +173 -173
- package/docs/design-system/components/README.md +90 -76
- package/docs/design-system/components/accordion.md +53 -53
- package/docs/design-system/components/activity-feed.md +94 -94
- package/docs/design-system/components/activity-heatmap.md +57 -57
- package/docs/design-system/components/agent-input.md +85 -0
- package/docs/design-system/components/alert-dialog.md +72 -72
- package/docs/design-system/components/alert.md +97 -97
- package/docs/design-system/components/approval-card.md +134 -0
- package/docs/design-system/components/aspect-ratio.md +45 -45
- package/docs/design-system/components/attribute.md +88 -88
- package/docs/design-system/components/autocomplete.md +75 -75
- package/docs/design-system/components/avatar.md +54 -54
- package/docs/design-system/components/badge.md +54 -54
- package/docs/design-system/components/banner.md +87 -87
- package/docs/design-system/components/breadcrumbs.md +176 -175
- package/docs/design-system/components/button-group.md +98 -98
- package/docs/design-system/components/button.md +83 -80
- package/docs/design-system/components/card.md +88 -88
- package/docs/design-system/components/carousel.md +46 -46
- package/docs/design-system/components/catalog-components.md +47 -47
- package/docs/design-system/components/chart.md +95 -24
- package/docs/design-system/components/checkbox.md +54 -54
- package/docs/design-system/components/collapsible.md +67 -53
- package/docs/design-system/components/command.md +62 -62
- package/docs/design-system/components/context-menu.md +46 -46
- package/docs/design-system/components/date-picker.md +81 -81
- package/docs/design-system/components/divider.md +102 -102
- package/docs/design-system/components/empty-state.md +56 -56
- package/docs/design-system/components/field.md +70 -70
- package/docs/design-system/components/file-upload.md +187 -187
- package/docs/design-system/components/hover-card.md +48 -48
- package/docs/design-system/components/icons.md +48 -48
- package/docs/design-system/components/inline-citations.md +93 -0
- package/docs/design-system/components/input-group.md +58 -58
- package/docs/design-system/components/input-otp.md +56 -56
- package/docs/design-system/components/input.md +114 -60
- package/docs/design-system/components/item.md +59 -59
- package/docs/design-system/components/kbd.md +51 -49
- package/docs/design-system/components/label.md +49 -49
- package/docs/design-system/components/menu.md +71 -61
- package/docs/design-system/components/menubar.md +47 -47
- package/docs/design-system/components/modal.md +105 -105
- package/docs/design-system/components/native-select.md +54 -54
- package/docs/design-system/components/navigation-menu.md +50 -50
- package/docs/design-system/components/onboarding-step-list-item.md +82 -82
- package/docs/design-system/components/page-header.md +93 -86
- package/docs/design-system/components/pagination.md +57 -57
- package/docs/design-system/components/popover.md +60 -60
- package/docs/design-system/components/progress-slider.md +50 -50
- package/docs/design-system/components/progress.md +76 -76
- package/docs/design-system/components/radio-card.md +51 -51
- package/docs/design-system/components/radio-group.md +57 -57
- package/docs/design-system/components/resizable.md +44 -44
- package/docs/design-system/components/rolling-count.md +61 -0
- package/docs/design-system/components/scroll-area.md +51 -51
- package/docs/design-system/components/segmented-control.md +54 -54
- package/docs/design-system/components/select.md +68 -62
- package/docs/design-system/components/sheet.md +67 -67
- package/docs/design-system/components/shimmer-text.md +67 -0
- package/docs/design-system/components/sidebar.md +110 -99
- package/docs/design-system/components/skeleton.md +75 -75
- package/docs/design-system/components/slideout.md +65 -65
- package/docs/design-system/components/slider.md +63 -63
- package/docs/design-system/components/social-button.md +50 -50
- package/docs/design-system/components/spinner.md +62 -62
- package/docs/design-system/components/steps.md +65 -65
- package/docs/design-system/components/streaming-text.md +82 -0
- package/docs/design-system/components/table.md +419 -414
- package/docs/design-system/components/tabs.md +59 -55
- package/docs/design-system/components/tag.md +80 -80
- package/docs/design-system/components/task-list.md +95 -0
- package/docs/design-system/components/textarea.md +50 -50
- package/docs/design-system/components/thinking-reasoning.md +72 -0
- package/docs/design-system/components/thinking-state.md +67 -0
- package/docs/design-system/components/timeline.md +83 -83
- package/docs/design-system/components/toast.md +58 -58
- package/docs/design-system/components/toggle.md +81 -81
- package/docs/design-system/components/toolbar.md +92 -87
- package/docs/design-system/components/tooltip.md +94 -92
- package/docs/design-system/components/typography.md +18 -18
- package/docs/design-system/density-and-elevation.md +65 -65
- package/docs/design-system/design-system-test-missing-items.md +368 -368
- package/docs/design-system/direction-and-localization.md +23 -23
- package/docs/design-system/form-recipes.md +73 -73
- package/docs/design-system/gap-promotion-policy.md +21 -21
- package/docs/design-system/icons.md +74 -74
- package/docs/design-system/installation.md +70 -68
- package/docs/design-system/launch-comparison-shadcn.md +98 -98
- package/docs/design-system/registry-and-cli.md +64 -64
- package/docs/design-system/release-policy.md +30 -30
- package/docs/design-system/roadmap.md +14 -14
- package/docs/design-system/support-matrix.md +23 -23
- package/docs/design-system/tabs.md +54 -53
- package/docs/design-system/template-gap-audit.md +32 -0
- package/docs/design-system/templates.md +59 -0
- package/docs/design-system/token-governance.md +72 -59
- package/package.json +98 -98
- package/registry/component-contract.json +40 -40
- package/registry/components/accordion.tsx +155 -155
- package/registry/components/agent-input-parts.tsx +552 -0
- package/registry/components/agent-input-state.ts +156 -0
- package/registry/components/agent-input.css +307 -0
- package/registry/components/agent-input.tsx +382 -0
- package/registry/components/alert-dialog.tsx +297 -297
- package/registry/components/alert.tsx +293 -293
- package/registry/components/approval-card.css +409 -0
- package/registry/components/approval-card.tsx +401 -0
- package/registry/components/approval-frame.tsx +108 -0
- package/registry/components/approval-questions.tsx +559 -0
- package/registry/components/aspect-ratio.tsx +30 -30
- package/registry/components/attribute.tsx +454 -454
- package/registry/components/autocomplete.tsx +598 -651
- package/registry/components/avatar.tsx +385 -385
- package/registry/components/badge.tsx +629 -629
- package/registry/components/button-group.tsx +565 -565
- package/registry/components/button.tsx +127 -123
- package/registry/components/card.tsx +638 -638
- package/registry/components/carousel.tsx +296 -296
- package/registry/components/chart-block-data.ts +177 -0
- package/registry/components/chart-block.css +171 -0
- package/registry/components/chart-block.tsx +260 -0
- package/registry/components/chart-interactions.ts +123 -0
- package/registry/components/chart-options.cartesian.ts +162 -0
- package/registry/components/chart-options.paint.ts +99 -0
- package/registry/components/chart-options.parts.ts +72 -0
- package/registry/components/chart-options.radial.ts +109 -0
- package/registry/components/chart-options.ts +44 -0
- package/registry/components/chart-options.types.ts +67 -0
- package/registry/components/chart.tsx +203 -203
- package/registry/components/checkbox.tsx +247 -247
- package/registry/components/collapsible.tsx +109 -69
- package/registry/components/command.tsx +208 -208
- package/registry/components/context-menu.tsx +236 -236
- package/registry/components/data-chart.tsx +40 -0
- package/registry/components/date-picker.tsx +1289 -1289
- package/registry/components/echart-theme.ts +246 -0
- package/registry/components/echart.css +49 -0
- package/registry/components/echart.tsx +178 -0
- package/registry/components/expanded/ActivityFeed.tsx +227 -227
- package/registry/components/expanded/ActivityHeatmap.tsx +64 -64
- package/registry/components/expanded/Banner.tsx +179 -179
- package/registry/components/expanded/Breadcrumbs.tsx +131 -131
- package/registry/components/expanded/CatalogComponentsShowcase.tsx +205 -205
- package/registry/components/expanded/CatalogDivider.tsx +49 -49
- package/registry/components/expanded/EmptyState.tsx +155 -155
- package/registry/components/expanded/FileUpload.tsx +543 -543
- package/registry/components/expanded/OnboardingStepListItem.tsx +60 -60
- package/registry/components/expanded/PageHeader.tsx +179 -166
- package/registry/components/expanded/Slideout.tsx +108 -108
- package/registry/components/expanded/Steps.tsx +402 -402
- package/registry/components/expanded/Table.tsx +1092 -1071
- package/registry/components/expanded/Timeline.tsx +203 -203
- package/registry/components/expanded/activityFeed.css +248 -248
- package/registry/components/expanded/activityHeatmap.css +66 -66
- package/registry/components/expanded/banner.css +260 -260
- package/registry/components/expanded/breadcrumbs.css +140 -140
- package/registry/components/expanded/catalogComponentsShowcase.css +87 -87
- package/registry/components/expanded/divider.css +75 -75
- package/registry/components/expanded/emptyState.css +111 -111
- package/registry/components/expanded/fileUpload.css +457 -457
- package/registry/components/expanded/onboardingStepListItem.css +135 -135
- package/registry/components/expanded/pageHeader.css +248 -290
- package/registry/components/expanded/slideout.css +276 -276
- package/registry/components/expanded/steps.css +356 -356
- package/registry/components/expanded/table.css +606 -606
- package/registry/components/expanded/timeline.css +286 -286
- package/registry/components/field.tsx +283 -283
- package/registry/components/hover-card.tsx +48 -48
- package/registry/components/inline-citations.css +126 -0
- package/registry/components/inline-citations.tsx +292 -0
- package/registry/components/input-content.ts +107 -107
- package/registry/components/input-group.tsx +130 -130
- package/registry/components/input-otp.tsx +584 -584
- package/registry/components/input.tsx +990 -979
- package/registry/components/item.tsx +189 -189
- package/registry/components/kbd.tsx +246 -245
- package/registry/components/label.tsx +78 -78
- package/registry/components/menu.tsx +978 -986
- package/registry/components/menubar.tsx +226 -226
- package/registry/components/modal.tsx +872 -872
- package/registry/components/native-select.tsx +205 -205
- package/registry/components/navigation-menu.tsx +171 -171
- package/registry/components/pagination.css +36 -36
- package/registry/components/pagination.tsx +560 -560
- package/registry/components/popover.tsx +338 -338
- package/registry/components/progress-slider.tsx +216 -216
- package/registry/components/radio-card.tsx +676 -676
- package/registry/components/radio-group.tsx +570 -570
- package/registry/components/resizable.tsx +108 -108
- package/registry/components/rolling-count.css +37 -0
- package/registry/components/rolling-count.tsx +110 -0
- package/registry/components/scroll-area.tsx +91 -91
- package/registry/components/segmented-control.tsx +87 -87
- package/registry/components/select-content.tsx +218 -218
- package/registry/components/select.tsx +937 -932
- package/registry/components/sheet.tsx +305 -305
- package/registry/components/shimmer-text.css +69 -0
- package/registry/components/shimmer-text.tsx +43 -0
- package/registry/components/sidebar.tsx +1433 -1230
- package/registry/components/skeleton.css +54 -54
- package/registry/components/skeleton.tsx +482 -482
- package/registry/components/slider.tsx +380 -380
- package/registry/components/social-button.tsx +387 -387
- package/registry/components/spinner.tsx +78 -78
- package/registry/components/streaming-text.css +45 -0
- package/registry/components/streaming-text.tsx +165 -0
- package/registry/components/table-elements.tsx +128 -128
- package/registry/components/tabs.css +222 -218
- package/registry/components/tabs.tsx +241 -241
- package/registry/components/tag.tsx +423 -423
- package/registry/components/task-list.css +328 -0
- package/registry/components/task-list.tsx +429 -0
- package/registry/components/textarea.tsx +610 -610
- package/registry/components/thinking-reasoning.css +178 -0
- package/registry/components/thinking-reasoning.tsx +253 -0
- package/registry/components/thinking-state.css +8 -0
- package/registry/components/thinking-state.tsx +46 -0
- package/registry/components/toast.tsx +136 -136
- package/registry/components/toggle.tsx +256 -256
- package/registry/components/toolbar.tsx +539 -539
- package/registry/components/tooltip.tsx +433 -431
- package/registry/examples/agent-input-demo.tsx +90 -0
- package/registry/examples/alert-demo.tsx +34 -34
- package/registry/examples/alert-dialog-demo.tsx +42 -42
- package/registry/examples/approval-card-demo.tsx +83 -0
- package/registry/examples/aspect-ratio-demo.tsx +11 -11
- package/registry/examples/attribute-demo.tsx +65 -65
- package/registry/examples/autocomplete-demo.tsx +109 -109
- package/registry/examples/avatar-demo.tsx +132 -132
- package/registry/examples/badge-demo.tsx +69 -69
- package/registry/examples/button-demo.tsx +86 -83
- package/registry/examples/button-group-demo.tsx +63 -63
- package/registry/examples/card-demo.tsx +86 -86
- package/registry/examples/carousel-demo.tsx +43 -43
- package/registry/examples/chart-block-demo.tsx +5 -0
- package/registry/examples/chart-demo.tsx +18 -33
- package/registry/examples/checkbox-demo.tsx +62 -62
- package/registry/examples/collapsible-demo.tsx +16 -16
- package/registry/examples/collection-filter-bar-demo.tsx +135 -135
- package/registry/examples/command-demo.tsx +42 -42
- package/registry/examples/command-palette-demo.tsx +235 -235
- package/registry/examples/context-menu-demo.tsx +29 -29
- package/registry/examples/control-density-contract-demo.tsx +65 -61
- package/registry/examples/date-picker-demo.tsx +127 -127
- package/registry/examples/divider-demo.tsx +17 -17
- package/registry/examples/expanded/activity-heatmap-demo.tsx +29 -29
- package/registry/examples/expanded/banner-demo.tsx +48 -48
- package/registry/examples/expanded/breadcrumbs-demo.tsx +59 -59
- package/registry/examples/expanded/empty-state-demo.tsx +39 -39
- package/registry/examples/expanded/file-upload-demo.tsx +60 -60
- package/registry/examples/expanded/onboarding-step-demo.tsx +11 -11
- package/registry/examples/expanded/slideout-demo.tsx +15 -15
- package/registry/examples/expanded/steps-demo.tsx +29 -29
- package/registry/examples/expanded/tabs-demo.tsx +13 -13
- package/registry/examples/expanded/timeline-demo.tsx +18 -18
- package/registry/examples/field-demo.tsx +51 -51
- package/registry/examples/hover-card-demo.tsx +23 -23
- package/registry/examples/inline-citations-demo.tsx +31 -0
- package/registry/examples/input-actions-demo.tsx +36 -0
- package/registry/examples/input-demo.tsx +87 -87
- package/registry/examples/input-group-demo.tsx +16 -16
- package/registry/examples/input-otp-demo.tsx +72 -72
- package/registry/examples/item-demo.tsx +46 -46
- package/registry/examples/kbd-demo.tsx +12 -12
- package/registry/examples/label-demo.tsx +20 -20
- package/registry/examples/menu-demo.tsx +122 -122
- package/registry/examples/menubar-demo.tsx +34 -34
- package/registry/examples/modal-demo.tsx +74 -74
- package/registry/examples/native-select-demo.tsx +16 -16
- package/registry/examples/navigation-menu-demo.tsx +29 -29
- package/registry/examples/pagination-demo.tsx +20 -20
- package/registry/examples/popover-demo.tsx +547 -546
- package/registry/examples/progress-demo.tsx +37 -37
- package/registry/examples/progress-slider-demo.tsx +29 -29
- package/registry/examples/radio-card-demo.tsx +51 -51
- package/registry/examples/radio-group-demo.tsx +62 -62
- package/registry/examples/resizable-demo.tsx +22 -22
- package/registry/examples/results-toolbar-demo.tsx +44 -44
- package/registry/examples/rolling-count-demo.tsx +39 -0
- package/registry/examples/scroll-area-demo.tsx +15 -15
- package/registry/examples/segmented-control-demo.tsx +39 -39
- package/registry/examples/select-demo.tsx +87 -87
- package/registry/examples/sheet-demo.tsx +47 -47
- package/registry/examples/shimmer-text-demo.tsx +20 -0
- package/registry/examples/sidebar-demo.tsx +101 -101
- package/registry/examples/slider-demo.tsx +31 -31
- package/registry/examples/social-button-demo.tsx +61 -61
- package/registry/examples/spinner-demo.tsx +59 -59
- package/registry/examples/streaming-text-demo.tsx +28 -0
- package/registry/examples/tabs-demo.tsx +13 -13
- package/registry/examples/tag-demo.tsx +29 -29
- package/registry/examples/task-list-demo.tsx +74 -0
- package/registry/examples/textarea-demo.tsx +79 -79
- package/registry/examples/thinking-reasoning-demo.tsx +74 -0
- package/registry/examples/thinking-state-demo.tsx +13 -0
- package/registry/examples/toast-demo.tsx +35 -35
- package/registry/examples/toggle-demo.tsx +59 -59
- package/registry/examples/tooltip-demo.tsx +115 -115
- package/registry/guidance/USAGE.md +27 -27
- package/registry/guidance/charts.LICENSE.txt +24 -0
- package/registry/hooks/use-controllable-state.ts +33 -0
- package/registry/hooks/use-direction.ts +207 -207
- package/registry/hooks/use-listbox-navigation.ts +73 -0
- package/registry/hooks/use-motion-end.ts +55 -0
- package/registry/hooks/use-reduced-motion.ts +28 -0
- package/registry/index.json +1403 -155
- package/registry/styles/globals.css +946 -1088
- package/registry.json +361 -8
- package/schema/config.schema.json +51 -51
- package/schema/registry.schema.json +194 -190
- package/schema/tokens.schema.json +167 -163
- package/src/cli/command-line.js +194 -194
- package/src/cli/config-editors.js +9 -9
- package/src/cli/doctor.js +399 -399
- package/src/cli/file-transaction.js +302 -295
- package/src/cli/global-css.js +153 -153
- package/src/cli/index.js +1002 -1009
- package/src/cli/install-plan.js +592 -592
- package/src/cli/install-receipt.js +171 -171
- package/src/cli/jsonc.js +203 -203
- package/src/cli/package-install-state.js +254 -254
- package/src/cli/package-manager.js +238 -238
- package/src/cli/package-plan.js +185 -185
- package/src/cli/package-version.js +97 -97
- package/src/cli/registry-query.js +207 -207
- package/src/cli/reporting.js +55 -55
- package/src/cli/schema-validation.js +19 -19
- package/src/cli/source-scanner.js +686 -686
- package/src/cli/vite-config.js +478 -478
- package/tokens/banhaten.tokens.json +306 -192
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { EChartsOption } from "echarts"
|
|
2
|
+
|
|
3
|
+
export type EChartTheme = {
|
|
4
|
+
palette: string[]
|
|
5
|
+
foreground: string
|
|
6
|
+
muted: string
|
|
7
|
+
border: string
|
|
8
|
+
surface: string
|
|
9
|
+
subtle: string
|
|
10
|
+
neutral: string
|
|
11
|
+
fontFamily: string
|
|
12
|
+
fontSize: number
|
|
13
|
+
fontWeight: number
|
|
14
|
+
lineHeight: number
|
|
15
|
+
letterSpacing: number
|
|
16
|
+
labelFontSize: number
|
|
17
|
+
mediumWeight: number
|
|
18
|
+
headingFontSize: number
|
|
19
|
+
headingLineHeight: number
|
|
20
|
+
headingWeight: number
|
|
21
|
+
space: { xs: number; sm: number; md: number; lg: number; xl: number; xxl: number; axis: number }
|
|
22
|
+
radius: number
|
|
23
|
+
markRadius: number
|
|
24
|
+
radii?: { sm: number; md: number; lg: number; xl: number }
|
|
25
|
+
translucentOpacity?: number
|
|
26
|
+
borderWidth: number
|
|
27
|
+
lineWidth: number
|
|
28
|
+
opacity: { area: number; muted: number; soft: number }
|
|
29
|
+
duration: number
|
|
30
|
+
reducedMotion: boolean
|
|
31
|
+
rtl: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const paletteTokens = [
|
|
35
|
+
"--bh-chart-categorical-brand",
|
|
36
|
+
"--bh-chart-categorical-success",
|
|
37
|
+
"--bh-chart-categorical-warning",
|
|
38
|
+
"--bh-chart-categorical-danger",
|
|
39
|
+
"--bh-chart-categorical-information",
|
|
40
|
+
"--bh-chart-categorical-purple",
|
|
41
|
+
"--bh-chart-categorical-aqua",
|
|
42
|
+
"--bh-chart-categorical-fuchsia",
|
|
43
|
+
] as const
|
|
44
|
+
|
|
45
|
+
/** Canvas-style APIs need resolved values, read from this chart's inherited theme. */
|
|
46
|
+
export function readEChartTheme(element: HTMLElement, reducedMotion: boolean): EChartTheme {
|
|
47
|
+
const styles = getComputedStyle(element)
|
|
48
|
+
const read = (token: string) => {
|
|
49
|
+
const value = styles.getPropertyValue(token).trim()
|
|
50
|
+
if (!value) throw new Error(`EChart requires the Banhaten token ${token}.`)
|
|
51
|
+
return value
|
|
52
|
+
}
|
|
53
|
+
const number = (token: string) => {
|
|
54
|
+
const value = Number.parseFloat(read(token))
|
|
55
|
+
if (!Number.isFinite(value)) throw new Error(`EChart requires a numeric Banhaten token ${token}.`)
|
|
56
|
+
return value
|
|
57
|
+
}
|
|
58
|
+
const duration = read("--bh-duration-default")
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
palette: paletteTokens.map(read),
|
|
62
|
+
foreground: read("--bh-content-default"),
|
|
63
|
+
muted: read("--bh-content-muted"),
|
|
64
|
+
border: read("--bh-border-subtle"),
|
|
65
|
+
surface: read("--bh-bg-raised"),
|
|
66
|
+
subtle: read("--bh-bg-neutral-subtle"),
|
|
67
|
+
neutral: read("--bh-chart-neutral-default"),
|
|
68
|
+
fontFamily: read("--bh-font-family"),
|
|
69
|
+
fontSize: number("--bh-text-body-xs-regular-font-size"),
|
|
70
|
+
fontWeight: number("--bh-text-body-xs-regular-font-weight"),
|
|
71
|
+
lineHeight: number("--bh-text-body-xs-regular-line-height"),
|
|
72
|
+
letterSpacing: number("--bh-text-body-xs-regular-letter-spacing"),
|
|
73
|
+
labelFontSize: number("--bh-text-body-3xs-regular-font-size"),
|
|
74
|
+
mediumWeight: number("--bh-text-body-xs-medium-font-weight"),
|
|
75
|
+
headingFontSize: number("--bh-text-heading-md-semibold-font-size"),
|
|
76
|
+
headingLineHeight: number("--bh-text-heading-md-semibold-line-height"),
|
|
77
|
+
headingWeight: number("--bh-text-heading-md-semibold-font-weight"),
|
|
78
|
+
space: {
|
|
79
|
+
xs: number("--bh-space-xs-4"),
|
|
80
|
+
sm: number("--bh-space-sm-6"),
|
|
81
|
+
md: number("--bh-space-md-8"),
|
|
82
|
+
lg: number("--bh-space-xl-12"),
|
|
83
|
+
xl: number("--bh-space-3xl-16"),
|
|
84
|
+
xxl: number("--bh-space-5xl-24"),
|
|
85
|
+
axis: number("--bh-space-7xl-40"),
|
|
86
|
+
},
|
|
87
|
+
radius: number("--bh-radius-lg-8"),
|
|
88
|
+
markRadius: number("--bh-radius-sm-4"),
|
|
89
|
+
radii: {
|
|
90
|
+
sm: number("--bh-radius-sm-4"),
|
|
91
|
+
md: number("--bh-radius-md-6"),
|
|
92
|
+
lg: number("--bh-radius-lg-8"),
|
|
93
|
+
xl: number("--bh-radius-xl-10"),
|
|
94
|
+
},
|
|
95
|
+
translucentOpacity: number("--bh-opacity-90"),
|
|
96
|
+
borderWidth: number("--bh-border-width-default"),
|
|
97
|
+
lineWidth: number("--bh-icon-stroke-200"),
|
|
98
|
+
opacity: {
|
|
99
|
+
area: number("--bh-opacity-15"),
|
|
100
|
+
muted: number("--bh-opacity-muted"),
|
|
101
|
+
soft: number("--bh-opacity-30"),
|
|
102
|
+
},
|
|
103
|
+
duration: Number.parseFloat(duration) * (duration.endsWith("ms") ? 1 : 1000),
|
|
104
|
+
reducedMotion,
|
|
105
|
+
rtl: styles.direction === "rtl",
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Shared defaults also cover native ECharts labels that a block does not specify. */
|
|
110
|
+
export function createEChartTheme(theme: EChartTheme) {
|
|
111
|
+
const textStyle = {
|
|
112
|
+
color: theme.foreground,
|
|
113
|
+
fontFamily: theme.fontFamily,
|
|
114
|
+
fontSize: theme.fontSize,
|
|
115
|
+
fontWeight: theme.fontWeight,
|
|
116
|
+
lineHeight: theme.lineHeight,
|
|
117
|
+
textShadowBlur: 0,
|
|
118
|
+
textShadowOffsetX: 0,
|
|
119
|
+
textShadowOffsetY: 0,
|
|
120
|
+
}
|
|
121
|
+
const axis = {
|
|
122
|
+
axisLine: { lineStyle: { color: theme.border, width: theme.borderWidth } },
|
|
123
|
+
axisTick: { show: false, lineStyle: { color: theme.border, width: theme.borderWidth } },
|
|
124
|
+
axisLabel: { ...textStyle, color: theme.muted, fontSize: theme.labelFontSize, margin: theme.space.md },
|
|
125
|
+
nameTextStyle: { ...textStyle, color: theme.muted },
|
|
126
|
+
splitLine: { lineStyle: { color: theme.border, width: theme.borderWidth } },
|
|
127
|
+
splitArea: { areaStyle: { color: [theme.surface, theme.subtle] } },
|
|
128
|
+
}
|
|
129
|
+
const label = { ...textStyle, fontSize: theme.labelFontSize }
|
|
130
|
+
const shadowless = { shadowBlur: 0, shadowOffsetX: 0, shadowOffsetY: 0 }
|
|
131
|
+
const seriesStates = {
|
|
132
|
+
emphasis: { label, itemStyle: { color: "inherit", ...shadowless } },
|
|
133
|
+
select: { label, itemStyle: { color: "inherit", borderColor: theme.border, borderWidth: theme.borderWidth, ...shadowless } },
|
|
134
|
+
blur: { label: { ...label, opacity: theme.opacity.muted }, itemStyle: { opacity: theme.opacity.muted, ...shadowless } },
|
|
135
|
+
}
|
|
136
|
+
const axisPointer = {
|
|
137
|
+
lineStyle: { color: theme.muted, width: theme.borderWidth },
|
|
138
|
+
shadowStyle: { color: theme.subtle, shadowBlur: 0 },
|
|
139
|
+
label: { ...textStyle, backgroundColor: theme.surface, borderColor: theme.border, borderWidth: theme.borderWidth, padding: theme.space.sm },
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
color: theme.palette,
|
|
144
|
+
backgroundColor: "transparent",
|
|
145
|
+
textStyle,
|
|
146
|
+
categoryAxis: axis,
|
|
147
|
+
valueAxis: axis,
|
|
148
|
+
logAxis: axis,
|
|
149
|
+
timeAxis: axis,
|
|
150
|
+
angleAxis: axis,
|
|
151
|
+
radiusAxis: axis,
|
|
152
|
+
axisPointer,
|
|
153
|
+
legend: {
|
|
154
|
+
textStyle,
|
|
155
|
+
itemWidth: theme.space.lg,
|
|
156
|
+
itemHeight: theme.space.md,
|
|
157
|
+
itemGap: theme.space.xl,
|
|
158
|
+
padding: theme.space.xs,
|
|
159
|
+
inactiveColor: theme.neutral,
|
|
160
|
+
inactiveBorderColor: theme.neutral,
|
|
161
|
+
pageTextStyle: textStyle,
|
|
162
|
+
pageIconColor: theme.foreground,
|
|
163
|
+
pageIconInactiveColor: theme.neutral,
|
|
164
|
+
},
|
|
165
|
+
tooltip: {
|
|
166
|
+
...shadowless,
|
|
167
|
+
textStyle,
|
|
168
|
+
backgroundColor: theme.surface,
|
|
169
|
+
borderColor: theme.border,
|
|
170
|
+
borderWidth: theme.borderWidth,
|
|
171
|
+
borderRadius: theme.radius,
|
|
172
|
+
padding: [theme.space.md, theme.space.lg],
|
|
173
|
+
axisPointer,
|
|
174
|
+
},
|
|
175
|
+
line: {
|
|
176
|
+
...seriesStates,
|
|
177
|
+
symbolSize: theme.space.sm,
|
|
178
|
+
lineStyle: { width: theme.lineWidth, shadowBlur: 0 },
|
|
179
|
+
areaStyle: { opacity: theme.opacity.area, shadowBlur: 0 },
|
|
180
|
+
label,
|
|
181
|
+
},
|
|
182
|
+
bar: { ...seriesStates, label, itemStyle: { shadowBlur: 0, borderWidth: 0 } },
|
|
183
|
+
pictorialBar: { ...seriesStates, label, itemStyle: { shadowBlur: 0, borderWidth: 0 } },
|
|
184
|
+
pie: { ...seriesStates, label, labelLine: { lineStyle: { width: theme.borderWidth } }, itemStyle: { borderColor: theme.surface, shadowBlur: 0 } },
|
|
185
|
+
radar: {
|
|
186
|
+
...seriesStates,
|
|
187
|
+
axisName: label,
|
|
188
|
+
axisLine: axis.axisLine,
|
|
189
|
+
splitLine: axis.splitLine,
|
|
190
|
+
splitArea: axis.splitArea,
|
|
191
|
+
lineStyle: { width: theme.lineWidth, shadowBlur: 0 },
|
|
192
|
+
areaStyle: { opacity: theme.opacity.area, shadowBlur: 0 },
|
|
193
|
+
symbolSize: theme.space.sm,
|
|
194
|
+
label,
|
|
195
|
+
},
|
|
196
|
+
sankey: { ...seriesStates, label, lineStyle: { color: "source", opacity: theme.opacity.soft, shadowBlur: 0 }, itemStyle: { borderWidth: 0, shadowBlur: 0 } },
|
|
197
|
+
gauge: {
|
|
198
|
+
...seriesStates,
|
|
199
|
+
title: textStyle,
|
|
200
|
+
detail: { ...textStyle, fontSize: theme.headingFontSize, fontWeight: theme.headingWeight },
|
|
201
|
+
axisLine: { lineStyle: { color: [[1, theme.neutral]], width: theme.space.lg } },
|
|
202
|
+
axisLabel: label,
|
|
203
|
+
axisTick: { lineStyle: { color: theme.border, width: theme.borderWidth } },
|
|
204
|
+
splitLine: { lineStyle: { color: theme.border, width: theme.borderWidth } },
|
|
205
|
+
pointer: { itemStyle: { color: theme.palette[0], shadowBlur: 0 } },
|
|
206
|
+
progress: { itemStyle: { color: theme.palette[0], shadowBlur: 0 } },
|
|
207
|
+
},
|
|
208
|
+
dataZoom: {
|
|
209
|
+
backgroundColor: theme.subtle,
|
|
210
|
+
borderColor: theme.border,
|
|
211
|
+
textStyle,
|
|
212
|
+
fillerColor: theme.subtle,
|
|
213
|
+
handleStyle: { color: theme.surface, borderColor: theme.border, borderWidth: theme.borderWidth, shadowBlur: 0 },
|
|
214
|
+
moveHandleStyle: { color: theme.neutral },
|
|
215
|
+
dataBackground: { lineStyle: { color: theme.neutral }, areaStyle: { color: theme.neutral, opacity: theme.opacity.area } },
|
|
216
|
+
selectedDataBackground: { lineStyle: { color: theme.palette[0] }, areaStyle: { color: theme.palette[0], opacity: theme.opacity.area } },
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function createEChartBaseOption(theme: EChartTheme): EChartsOption {
|
|
222
|
+
return {
|
|
223
|
+
color: theme.palette,
|
|
224
|
+
backgroundColor: "transparent",
|
|
225
|
+
textStyle: {
|
|
226
|
+
color: theme.foreground,
|
|
227
|
+
fontFamily: theme.fontFamily,
|
|
228
|
+
fontSize: theme.fontSize,
|
|
229
|
+
fontWeight: theme.fontWeight,
|
|
230
|
+
},
|
|
231
|
+
animation: !theme.reducedMotion,
|
|
232
|
+
animationDuration: theme.duration,
|
|
233
|
+
animationDurationUpdate: theme.duration,
|
|
234
|
+
// The labelled figure and optional data table provide the accessible content.
|
|
235
|
+
aria: { enabled: false },
|
|
236
|
+
tooltip: {
|
|
237
|
+
confine: true,
|
|
238
|
+
className: "bh-echart__tooltip",
|
|
239
|
+
shadowBlur: 0,
|
|
240
|
+
shadowOffsetX: 0,
|
|
241
|
+
shadowOffsetY: 0,
|
|
242
|
+
extraCssText: "box-shadow: none;",
|
|
243
|
+
transitionDuration: 0,
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.bh-echart {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: var(--bh-space-17xl-288);
|
|
5
|
+
min-width: 0;
|
|
6
|
+
color: var(--bh-content-default);
|
|
7
|
+
font-family: var(--bh-font-family);
|
|
8
|
+
font-size: var(--bh-text-body-xs-regular-font-size);
|
|
9
|
+
font-weight: var(--bh-text-body-xs-regular-font-weight);
|
|
10
|
+
line-height: var(--bh-text-body-xs-regular-line-height);
|
|
11
|
+
letter-spacing: var(--bh-text-body-xs-regular-letter-spacing);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.bh-echart__viewport {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
min-width: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* ECharts positions text in physical SVG coordinates; axes handle RTL order. */
|
|
21
|
+
.bh-echart__viewport svg {
|
|
22
|
+
direction: ltr;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.bh-echart .bh-echart__tooltip {
|
|
26
|
+
box-shadow: none !important;
|
|
27
|
+
font-family: var(--bh-font-family) !important;
|
|
28
|
+
letter-spacing: var(--bh-text-body-xs-regular-letter-spacing);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.bh-echart__status {
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset: 0;
|
|
34
|
+
display: grid;
|
|
35
|
+
place-content: center;
|
|
36
|
+
padding: var(--bh-space-3xl-16);
|
|
37
|
+
color: var(--bh-content-muted);
|
|
38
|
+
text-align: center;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.bh-echart__description {
|
|
42
|
+
position: absolute;
|
|
43
|
+
width: var(--bh-space-xxxs-1);
|
|
44
|
+
height: var(--bh-space-xxxs-1);
|
|
45
|
+
padding: 0;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
clip-path: inset(50%);
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { init, use, type ECharts } from "echarts/core"
|
|
5
|
+
import { BarChart, GaugeChart, LineChart, PictorialBarChart, PieChart, RadarChart, SankeyChart } from "echarts/charts"
|
|
6
|
+
import { AriaComponent, DataZoomComponent, GraphicComponent, GridComponent, LegendComponent, PolarComponent, TooltipComponent } from "echarts/components"
|
|
7
|
+
import { SVGRenderer } from "echarts/renderers"
|
|
8
|
+
import type { EChartsOption } from "echarts"
|
|
9
|
+
|
|
10
|
+
import { cn } from "@/lib/utils"
|
|
11
|
+
import { createEChartBaseOption, createEChartTheme, readEChartTheme, type EChartTheme } from "./echart-theme"
|
|
12
|
+
import "./echart.css"
|
|
13
|
+
|
|
14
|
+
use([BarChart, GaugeChart, LineChart, PictorialBarChart, PieChart, RadarChart, SankeyChart, AriaComponent, DataZoomComponent, GraphicComponent, GridComponent, LegendComponent, PolarComponent, TooltipComponent, SVGRenderer])
|
|
15
|
+
|
|
16
|
+
export type EChartProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
17
|
+
/** Build all chart styling from the resolved, inherited Banhaten tokens. */
|
|
18
|
+
option: (theme: EChartTheme) => EChartsOption
|
|
19
|
+
label: string
|
|
20
|
+
description?: string
|
|
21
|
+
/** Optional instance interactions; return a cleanup for listeners and timers. */
|
|
22
|
+
onReady?: (chart: ECharts, theme: EChartTheme) => void | (() => void)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function EChart({ className, option, label, description, onReady, ...props }: EChartProps) {
|
|
26
|
+
const viewportRef = React.useRef<HTMLDivElement>(null)
|
|
27
|
+
const refreshRef = React.useRef<(() => void) | null>(null)
|
|
28
|
+
const latest = React.useRef({ option, onReady })
|
|
29
|
+
latest.current = { option, onReady }
|
|
30
|
+
const descriptionId = React.useId()
|
|
31
|
+
const [error, setError] = React.useState(false)
|
|
32
|
+
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
const viewport = viewportRef.current
|
|
35
|
+
if (!viewport) return
|
|
36
|
+
|
|
37
|
+
let instance: ECharts | undefined
|
|
38
|
+
let cleanupInteraction: void | (() => void)
|
|
39
|
+
let themeSignature = ""
|
|
40
|
+
let frame: number | undefined
|
|
41
|
+
let visible = typeof IntersectionObserver === "undefined"
|
|
42
|
+
let disposed = false
|
|
43
|
+
const motion = window.matchMedia("(prefers-reduced-motion: reduce)")
|
|
44
|
+
|
|
45
|
+
const paint = () => {
|
|
46
|
+
frame = undefined
|
|
47
|
+
if (disposed || !visible || viewport.clientWidth === 0 || viewport.clientHeight === 0) return
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const theme = readEChartTheme(viewport, motion.matches)
|
|
51
|
+
const nextSignature = JSON.stringify(theme)
|
|
52
|
+
const viewState = instance ? readViewState(instance) : undefined
|
|
53
|
+
cleanupInteraction?.()
|
|
54
|
+
cleanupInteraction = undefined
|
|
55
|
+
if (!instance || themeSignature !== nextSignature) {
|
|
56
|
+
instance?.dispose()
|
|
57
|
+
instance = init(viewport, createEChartTheme(theme), { renderer: "svg" })
|
|
58
|
+
themeSignature = nextSignature
|
|
59
|
+
}
|
|
60
|
+
const requested = latest.current.option(theme)
|
|
61
|
+
const base = createEChartBaseOption(theme)
|
|
62
|
+
const series = requested.series
|
|
63
|
+
? (Array.isArray(requested.series) ? requested.series : [requested.series])
|
|
64
|
+
: []
|
|
65
|
+
const duration = theme.reducedMotion ? 0 : theme.duration
|
|
66
|
+
const shadowlessTooltip = { shadowBlur: 0, shadowOffsetX: 0, shadowOffsetY: 0, extraCssText: "box-shadow: none;" }
|
|
67
|
+
instance.setOption({
|
|
68
|
+
...base,
|
|
69
|
+
...requested,
|
|
70
|
+
animation: theme.reducedMotion ? false : requested.animation ?? base.animation,
|
|
71
|
+
animationDuration: duration,
|
|
72
|
+
animationDurationUpdate: duration,
|
|
73
|
+
// Native series have their own durations, which override global defaults.
|
|
74
|
+
series: series.map((item) => ({
|
|
75
|
+
...item,
|
|
76
|
+
animation: !theme.reducedMotion && requested.animation !== false && item.animation !== false,
|
|
77
|
+
animationDuration: duration,
|
|
78
|
+
animationDurationUpdate: duration,
|
|
79
|
+
stateAnimation: { ...item.stateAnimation, duration },
|
|
80
|
+
})),
|
|
81
|
+
tooltip: requested.tooltip === undefined
|
|
82
|
+
? base.tooltip
|
|
83
|
+
: Array.isArray(requested.tooltip)
|
|
84
|
+
? requested.tooltip.map((tooltip) => ({ ...base.tooltip, ...tooltip, ...shadowlessTooltip }))
|
|
85
|
+
: { ...base.tooltip, ...requested.tooltip, ...shadowlessTooltip },
|
|
86
|
+
}, { notMerge: true })
|
|
87
|
+
if (viewState) instance.setOption(viewState, { silent: true })
|
|
88
|
+
instance.resize()
|
|
89
|
+
cleanupInteraction = latest.current.onReady?.(instance, theme)
|
|
90
|
+
setError(false)
|
|
91
|
+
} catch (cause) {
|
|
92
|
+
instance?.dispose()
|
|
93
|
+
instance = undefined
|
|
94
|
+
setError(true)
|
|
95
|
+
console.error("Unable to render Banhaten chart.", cause)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const schedule = () => {
|
|
99
|
+
if (!disposed && frame === undefined) frame = window.requestAnimationFrame(paint)
|
|
100
|
+
}
|
|
101
|
+
refreshRef.current = schedule
|
|
102
|
+
|
|
103
|
+
const intersection = typeof IntersectionObserver === "undefined" ? undefined : new IntersectionObserver((entries) => {
|
|
104
|
+
visible = entries.some((entry) => entry.isIntersecting)
|
|
105
|
+
if (visible) schedule()
|
|
106
|
+
})
|
|
107
|
+
intersection?.observe(viewport)
|
|
108
|
+
|
|
109
|
+
const resizeChart = () => { if (instance) instance.resize(); else schedule() }
|
|
110
|
+
const resize = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(resizeChart)
|
|
111
|
+
resize?.observe(viewport)
|
|
112
|
+
window.addEventListener("resize", resizeChart)
|
|
113
|
+
motion.addEventListener("change", schedule)
|
|
114
|
+
|
|
115
|
+
// Observe only this chart's ancestry, avoiding rerenders from SVG mutations.
|
|
116
|
+
const mutations = new MutationObserver(schedule)
|
|
117
|
+
let ancestor: HTMLElement | null = viewport.parentElement
|
|
118
|
+
while (ancestor) {
|
|
119
|
+
mutations.observe(ancestor, {
|
|
120
|
+
attributes: true,
|
|
121
|
+
attributeFilter: [
|
|
122
|
+
"class", "style", "dir", "data-theme", "data-color-mode",
|
|
123
|
+
"data-english-font", "data-arabic-font", "data-radius",
|
|
124
|
+
],
|
|
125
|
+
})
|
|
126
|
+
ancestor = ancestor.parentElement
|
|
127
|
+
}
|
|
128
|
+
document.fonts?.addEventListener("loadingdone", schedule)
|
|
129
|
+
void document.fonts?.ready.then(schedule)
|
|
130
|
+
schedule()
|
|
131
|
+
|
|
132
|
+
return () => {
|
|
133
|
+
disposed = true
|
|
134
|
+
refreshRef.current = null
|
|
135
|
+
if (frame !== undefined) window.cancelAnimationFrame(frame)
|
|
136
|
+
intersection?.disconnect()
|
|
137
|
+
resize?.disconnect()
|
|
138
|
+
mutations.disconnect()
|
|
139
|
+
window.removeEventListener("resize", resizeChart)
|
|
140
|
+
motion.removeEventListener("change", schedule)
|
|
141
|
+
document.fonts?.removeEventListener("loadingdone", schedule)
|
|
142
|
+
cleanupInteraction?.()
|
|
143
|
+
instance?.dispose()
|
|
144
|
+
}
|
|
145
|
+
}, [])
|
|
146
|
+
|
|
147
|
+
React.useEffect(() => { refreshRef.current?.() }, [option, onReady])
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
role="figure"
|
|
152
|
+
aria-label={label}
|
|
153
|
+
aria-describedby={description ? descriptionId : undefined}
|
|
154
|
+
data-slot="echart"
|
|
155
|
+
className={cn("bh-echart", className)}
|
|
156
|
+
{...props}
|
|
157
|
+
>
|
|
158
|
+
<div ref={viewportRef} className="bh-echart__viewport" aria-hidden="true" />
|
|
159
|
+
{description ? <span id={descriptionId} className="bh-echart__description">{description}</span> : null}
|
|
160
|
+
{error ? <span className="bh-echart__status" role="status">Chart preview unavailable.</span> : null}
|
|
161
|
+
</div>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Theme refreshes retain the user's selected series and viewport. */
|
|
166
|
+
function readViewState(instance: ECharts): EChartsOption {
|
|
167
|
+
const current = instance.getOption()
|
|
168
|
+
const result: EChartsOption = {}
|
|
169
|
+
if (Array.isArray(current.legend)) {
|
|
170
|
+
result.legend = current.legend.map((legend: { selected?: Record<string, boolean> }) => ({ selected: legend.selected }))
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(current.dataZoom)) {
|
|
173
|
+
result.dataZoom = current.dataZoom.map((zoom: { start?: number; end?: number }) => ({ start: zoom.start, end: zoom.end }))
|
|
174
|
+
}
|
|
175
|
+
return result
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { EChartTheme }
|