@purestack/ts-components 1.1.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.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/ts-components.d.mts +1662 -0
  4. package/dist/ts-components.d.mts.map +1 -0
  5. package/dist/ts-components.mjs +9200 -0
  6. package/dist/ts-components.mjs.map +1 -0
  7. package/package.json +130 -0
  8. package/src/defineComponents.ts +87 -0
  9. package/src/index.ts +270 -0
  10. package/src/registerStyles.ts +63 -0
  11. package/src/standard/alertBox/alertBox.ts +64 -0
  12. package/src/standard/autoId.ts +25 -0
  13. package/src/standard/badge/badge.ts +41 -0
  14. package/src/standard/badge/badgeStyle.ts +21 -0
  15. package/src/standard/barChart/barChart.ts +338 -0
  16. package/src/standard/barChart/barChartStyle.ts +81 -0
  17. package/src/standard/btn/btn.ts +191 -0
  18. package/src/standard/btn/btnStyle.ts +59 -0
  19. package/src/standard/btnGroup/btnGroup.ts +208 -0
  20. package/src/standard/btnGroup/btnGroupStyle.ts +85 -0
  21. package/src/standard/chart/cartesianChart.ts +99 -0
  22. package/src/standard/chart/chartDefaults.ts +25 -0
  23. package/src/standard/chart/chartUtils.ts +84 -0
  24. package/src/standard/classicLogo/classicLogo.ts +429 -0
  25. package/src/standard/classicLogo/classicLogoStyle.ts +292 -0
  26. package/src/standard/componentVariant.ts +153 -0
  27. package/src/standard/composer/composer.ts +1035 -0
  28. package/src/standard/composer/composerCanvasInitialStyle.ts +225 -0
  29. package/src/standard/composer/composerCanvasRevertStyle.ts +14 -0
  30. package/src/standard/composer/composerCanvasSharedStyle.ts +60 -0
  31. package/src/standard/composer/composerCanvasStyleTypes.ts +8 -0
  32. package/src/standard/composer/composerCanvasThemeStyle.ts +53 -0
  33. package/src/standard/composer/composerStyle.ts +156 -0
  34. package/src/standard/composer/emailHtmlPolicy.ts +474 -0
  35. package/src/standard/consent/consent.ts +173 -0
  36. package/src/standard/consent/consentStyle.ts +44 -0
  37. package/src/standard/contactForm/contactForm.ts +135 -0
  38. package/src/standard/contactForm/contactFormStyle.ts +116 -0
  39. package/src/standard/doughnutChart/doughnutChart.ts +527 -0
  40. package/src/standard/doughnutChart/doughnutChartStyle.ts +64 -0
  41. package/src/standard/dropFiles/dropFiles.ts +480 -0
  42. package/src/standard/dropFiles/dropFilesStyle.ts +171 -0
  43. package/src/standard/expandablePanel/expandablePanel.ts +106 -0
  44. package/src/standard/expandablePanel/expandablePanelStyle.ts +56 -0
  45. package/src/standard/flex/flex.ts +269 -0
  46. package/src/standard/flex/flexStyle.ts +556 -0
  47. package/src/standard/footer/footer.ts +93 -0
  48. package/src/standard/footer/footerStyle.ts +39 -0
  49. package/src/standard/form/autoCompleteInput.ts +567 -0
  50. package/src/standard/form/form.ts +205 -0
  51. package/src/standard/form/formCheck.ts +96 -0
  52. package/src/standard/form/formInputField.ts +184 -0
  53. package/src/standard/form/formSelectField.ts +152 -0
  54. package/src/standard/form/formStyle.ts +585 -0
  55. package/src/standard/form/multiAutoCompleteInput.ts +880 -0
  56. package/src/standard/grid/grid.ts +177 -0
  57. package/src/standard/grid/gridStyle.ts +56 -0
  58. package/src/standard/icon/icon.ts +96 -0
  59. package/src/standard/icon/iconStyle.ts +50 -0
  60. package/src/standard/landing/codeShowcase.ts +54 -0
  61. package/src/standard/landing/comparisonColumn.ts +30 -0
  62. package/src/standard/landing/comparisonFeature.ts +22 -0
  63. package/src/standard/landing/comparisonTable.ts +38 -0
  64. package/src/standard/landing/ctaSection.ts +59 -0
  65. package/src/standard/landing/featureCard.ts +41 -0
  66. package/src/standard/landing/landing.ts +52 -0
  67. package/src/standard/landing/landingBand.ts +217 -0
  68. package/src/standard/landing/landingSection.ts +43 -0
  69. package/src/standard/landing/landingTypes.ts +141 -0
  70. package/src/standard/landing/metricItem.ts +25 -0
  71. package/src/standard/landing/metricStrip.ts +20 -0
  72. package/src/standard/lineChart/lineChart.ts +462 -0
  73. package/src/standard/lineChart/lineChartStyle.ts +91 -0
  74. package/src/standard/logo/logo.ts +192 -0
  75. package/src/standard/logo/logoStyle.ts +164 -0
  76. package/src/standard/modal/modal.ts +171 -0
  77. package/src/standard/modal/modalStore.ts +154 -0
  78. package/src/standard/modal/modalStyle.ts +190 -0
  79. package/src/standard/navMenu/navMenu.ts +278 -0
  80. package/src/standard/navMenu/navMenuStyle.ts +323 -0
  81. package/src/standard/pageLinks/pageLinks.ts +90 -0
  82. package/src/standard/pageScript/pageScript.ts +155 -0
  83. package/src/standard/pageToc/pageToc.ts +154 -0
  84. package/src/standard/pageToc/pageTocStyle.ts +372 -0
  85. package/src/standard/panel/panel.ts +55 -0
  86. package/src/standard/panel/panelStyle.ts +15 -0
  87. package/src/standard/pricing/pricing.ts +146 -0
  88. package/src/standard/searchBox/searchBox.ts +54 -0
  89. package/src/standard/searchBox/searchBoxStyle.ts +180 -0
  90. package/src/standard/sectionHeader/sectionHeader.ts +99 -0
  91. package/src/standard/signIn/signIn.ts +167 -0
  92. package/src/standard/signIn/signInStyle.ts +70 -0
  93. package/src/standard/tabs/tabs.ts +193 -0
  94. package/src/standard/tabs/tabsStyle.ts +231 -0
  95. package/src/standard/themeToggle/themeToggle.ts +33 -0
  96. package/src/standard/themeToggle/themeToggleStyle.ts +88 -0
  97. package/src/standard/toast/toastHost.ts +42 -0
  98. package/src/standard/toast/toastStore.ts +50 -0
  99. package/src/standard/topBar/topBar.ts +101 -0
  100. package/src/standard/topBar/topBarStyle.ts +169 -0
  101. package/src/standard/virtualList/variableVirtualTable.ts +371 -0
  102. package/src/standard/virtualList/virtualList.ts +423 -0
  103. package/src/standard/virtualList/virtualListStyle.ts +34 -0
  104. package/src/standard/virtualList/virtualTable.ts +179 -0
  105. package/src/standard/virtualList/virtualTableStyle.ts +24 -0
  106. package/tsconfig.json +23 -0
@@ -0,0 +1,462 @@
1
+ import type { SemanticTone } from '@purestack/ts-style'
2
+ import {
3
+ type ComputedRef,
4
+ computed,
5
+ defineComponent,
6
+ type RefOrValue,
7
+ svg,
8
+ unref,
9
+ } from 'regor'
10
+ import {
11
+ type CartesianChartDomain,
12
+ pointIndexToCartesianChartX,
13
+ type ResolvedCartesianChartGridLine,
14
+ resolveCartesianChartDomain,
15
+ resolveCartesianChartGridLines,
16
+ valueToCartesianChartY,
17
+ } from '../chart/cartesianChart'
18
+ import {
19
+ DEFAULT_CARTESIAN_CHART_HEIGHT,
20
+ DEFAULT_CARTESIAN_CHART_WIDTH,
21
+ DEFAULT_CHART_COLORS,
22
+ DEFAULT_CHART_EMPTY_LABEL,
23
+ } from '../chart/chartDefaults'
24
+ import {
25
+ formatChartNumber,
26
+ formatChartPoint,
27
+ formatChartValue,
28
+ readChartNumber,
29
+ resolveChartSize,
30
+ resolveChartText,
31
+ } from '../chart/chartUtils'
32
+ import type {
33
+ ComponentVariant,
34
+ ComponentVariantMode,
35
+ } from '../componentVariant'
36
+ import { resolveComponentClasses } from '../componentVariant'
37
+
38
+ export type LineChartCurve = 'linear' | 'smooth'
39
+
40
+ export interface LineChartPoint {
41
+ label?: RefOrValue<string>
42
+ value?: RefOrValue<number | string>
43
+ }
44
+
45
+ export interface LineChartSeries {
46
+ label?: RefOrValue<string>
47
+ color?: RefOrValue<string>
48
+ points?: RefOrValue<Array<RefOrValue<LineChartPoint>>>
49
+ }
50
+
51
+ export interface ResolvedLineChartPoint {
52
+ label: string
53
+ value: number
54
+ formattedValue: string
55
+ x: number
56
+ y: number
57
+ valueLabelY: number
58
+ valueLabelBaseline: string
59
+ }
60
+
61
+ export interface ResolvedLineChartSeries {
62
+ label: string
63
+ color: string
64
+ path: string
65
+ areaPath: string
66
+ points: ResolvedLineChartPoint[]
67
+ }
68
+
69
+ export interface ResolvedLineChartGridLine
70
+ extends ResolvedCartesianChartGridLine {}
71
+
72
+ export interface ResolvedLineChartLabel {
73
+ label: string
74
+ x: number
75
+ y: number
76
+ }
77
+
78
+ export interface LineChart {
79
+ series?: RefOrValue<Array<RefOrValue<LineChartSeries>>>
80
+ title?: RefOrValue<string>
81
+ description?: RefOrValue<string>
82
+ ariaLabel?: RefOrValue<string>
83
+ emptyLabel?: RefOrValue<string>
84
+ valueSuffix?: RefOrValue<string>
85
+ width?: RefOrValue<number | string>
86
+ height?: RefOrValue<number | string>
87
+ minValue?: RefOrValue<number | string>
88
+ maxValue?: RefOrValue<number | string>
89
+ curve?: RefOrValue<LineChartCurve>
90
+ animated?: RefOrValue<boolean | string>
91
+ showArea?: RefOrValue<boolean | string>
92
+ showPoints?: RefOrValue<boolean | string>
93
+ showValues?: RefOrValue<boolean | string>
94
+ showLabels?: RefOrValue<boolean | string>
95
+ showAxis?: RefOrValue<boolean | string>
96
+ tone?: RefOrValue<SemanticTone>
97
+ variant?: RefOrValue<ComponentVariant>
98
+ variantMode?: RefOrValue<ComponentVariantMode>
99
+ classes?: ComputedRef<string>
100
+ resolvedWidth?: ComputedRef<string | number>
101
+ resolvedHeight?: ComputedRef<string | number | undefined>
102
+ resolvedAriaLabel?: ComputedRef<string>
103
+ resolvedEmptyLabel?: ComputedRef<string>
104
+ chartSeries?: ComputedRef<ResolvedLineChartSeries[]>
105
+ gridLines?: ComputedRef<ResolvedLineChartGridLine[]>
106
+ xLabels?: ComputedRef<ResolvedLineChartLabel[]>
107
+ hasSeries?: ComputedRef<boolean>
108
+ zeroLineY?: ComputedRef<number>
109
+ }
110
+
111
+ const VALUE_LABEL_OFFSET = 2.6
112
+ const CATEGORY_LABEL_Y = 60
113
+ const MAX_X_LABEL_COUNT = 7
114
+
115
+ const lineChartTemplate = svg`<svg
116
+ class="line-chart"
117
+ :class="classes"
118
+ viewBox="-6 0 112 64"
119
+ :width="resolvedWidth"
120
+ :height="resolvedHeight"
121
+ role="img"
122
+ :aria-label="resolvedAriaLabel"
123
+ >
124
+ <title r-if="title">{{ title }}</title>
125
+ <desc r-if="description">{{ description }}</desc>
126
+ <g class="line-chart__grid" r-if="hasSeries && showAxis">
127
+ <g r-for="line in gridLines" class="line-chart__grid-line">
128
+ <line x1="8" x2="94" :y1="line.y" :y2="line.y"/>
129
+ <text x="5.4" :y="line.y">{{ line.formattedValue }}</text>
130
+ </g>
131
+ </g>
132
+ <line
133
+ r-if="hasSeries && showAxis"
134
+ class="line-chart__zero-line"
135
+ x1="8"
136
+ x2="94"
137
+ :y1="zeroLineY"
138
+ :y2="zeroLineY"/>
139
+ <g class="line-chart__areas" r-if="hasSeries && showArea">
140
+ <path
141
+ r-for="item in chartSeries"
142
+ class="line-chart__area"
143
+ :d="item.areaPath"
144
+ :fill="item.color"
145
+ :aria-label="item.label"
146
+ ></path>
147
+ </g>
148
+ <g class="line-chart__series" r-if="hasSeries">
149
+ <path
150
+ r-for="item in chartSeries"
151
+ class="line-chart__line"
152
+ :d="item.path"
153
+ :stroke="item.color"
154
+ :aria-label="item.label"
155
+ >
156
+ <title>{{ item.label }}</title>
157
+ <animate
158
+ r-if="animated"
159
+ attributeName="stroke-opacity"
160
+ from="0"
161
+ to="1"
162
+ dur="820ms"
163
+ fill="freeze"/>
164
+ </path>
165
+ </g>
166
+ <g class="line-chart__points" r-if="hasSeries && showPoints">
167
+ <g r-for="item in chartSeries" class="line-chart__point-series">
168
+ <circle
169
+ r-for="point in item.points"
170
+ class="line-chart__point"
171
+ :cx="point.x"
172
+ :cy="point.y"
173
+ r="0.9"
174
+ :fill="item.color"
175
+ :aria-label="item.label + ', ' + point.label + ': ' + point.formattedValue"
176
+ >
177
+ <title>{{ item.label + ', ' + point.label + ': ' + point.formattedValue }}</title>
178
+ <animate
179
+ r-if="animated"
180
+ attributeName="r"
181
+ from="0"
182
+ to="0.9"
183
+ dur="520ms"
184
+ fill="freeze"/>
185
+ </circle>
186
+ </g>
187
+ </g>
188
+ <g class="line-chart__values" r-if="hasSeries && showValues">
189
+ <g r-for="item in chartSeries" class="line-chart__value-series">
190
+ <text
191
+ r-for="point in item.points"
192
+ class="line-chart__value"
193
+ :x="point.x"
194
+ :y="point.valueLabelY"
195
+ text-anchor="middle"
196
+ :dominant-baseline="point.valueLabelBaseline"
197
+ >
198
+ {{ point.formattedValue }}
199
+ </text>
200
+ </g>
201
+ </g>
202
+ <g class="line-chart__labels" r-if="hasSeries && showLabels">
203
+ <text
204
+ r-for="label in xLabels"
205
+ class="line-chart__label"
206
+ :x="label.x"
207
+ :y="label.y"
208
+ text-anchor="middle"
209
+ >
210
+ {{ label.label }}
211
+ </text>
212
+ </g>
213
+ <text
214
+ r-if="!hasSeries"
215
+ class="line-chart__empty"
216
+ x="50"
217
+ y="30"
218
+ text-anchor="middle"
219
+ >
220
+ {{ resolvedEmptyLabel }}
221
+ </text>
222
+ </svg>`
223
+
224
+ function defineLineChartComponent() {
225
+ return defineComponent<LineChart>(lineChartTemplate, {
226
+ props: [
227
+ 'series',
228
+ 'title',
229
+ 'description',
230
+ 'ariaLabel',
231
+ 'emptyLabel',
232
+ 'valueSuffix',
233
+ 'width',
234
+ 'height',
235
+ 'minValue',
236
+ 'maxValue',
237
+ 'curve',
238
+ 'animated',
239
+ 'showArea',
240
+ 'showPoints',
241
+ 'showValues',
242
+ 'showLabels',
243
+ 'showAxis',
244
+ 'tone',
245
+ 'variant',
246
+ 'variantMode',
247
+ ],
248
+ context: (head) => resolveLineChart(head.props),
249
+ })
250
+ }
251
+
252
+ export function defineLineChartComponents() {
253
+ return {
254
+ lineChart: defineLineChartComponent(),
255
+ }
256
+ }
257
+
258
+ function resolveLineChart(props: LineChart): LineChart {
259
+ const domain = computed(() => resolveDomain(props))
260
+ const chartSeries = computed(() => resolveChartSeries(props, domain()))
261
+
262
+ return {
263
+ animated: true,
264
+ showArea: false,
265
+ showPoints: true,
266
+ showValues: false,
267
+ showLabels: true,
268
+ showAxis: true,
269
+ ...props,
270
+ classes: computed(() =>
271
+ resolveComponentClasses(props, {
272
+ defaultVariant: 'none',
273
+ defaultVariantMode: 'stateless',
274
+ }),
275
+ ),
276
+ resolvedWidth: computed(() =>
277
+ resolveChartSize(props.width, DEFAULT_CARTESIAN_CHART_WIDTH),
278
+ ),
279
+ resolvedHeight: computed(() =>
280
+ resolveChartSize(props.height, DEFAULT_CARTESIAN_CHART_HEIGHT),
281
+ ),
282
+ resolvedAriaLabel: computed(() => resolveAriaLabel(props)),
283
+ resolvedEmptyLabel: computed(
284
+ () => resolveChartText(props.emptyLabel) || DEFAULT_CHART_EMPTY_LABEL,
285
+ ),
286
+ chartSeries,
287
+ gridLines: computed(() =>
288
+ resolveCartesianChartGridLines(domain(), props.valueSuffix),
289
+ ),
290
+ xLabels: computed(() => resolveXLabels(chartSeries())),
291
+ hasSeries: computed(() => chartSeries().length > 0),
292
+ zeroLineY: computed(() => valueToCartesianChartY(0, domain())),
293
+ }
294
+ }
295
+
296
+ interface ResolvedLineChartSourceSeries {
297
+ label: string
298
+ color: string
299
+ points: ResolvedLineChartSourcePoint[]
300
+ }
301
+
302
+ interface ResolvedLineChartSourcePoint {
303
+ label: string
304
+ value: number
305
+ }
306
+
307
+ function resolveChartSeries(
308
+ props: LineChart,
309
+ domain: CartesianChartDomain,
310
+ ): ResolvedLineChartSeries[] {
311
+ const valueSuffix = resolveChartText(props.valueSuffix)
312
+ const curve = resolveCurve(props.curve)
313
+ const zeroY = valueToCartesianChartY(0, domain)
314
+
315
+ return resolveSeries(props.series).map((series, index) => {
316
+ const points = series.points.map((point, pointIndex) => {
317
+ const x = pointIndexToCartesianChartX(pointIndex, series.points.length)
318
+ const y = valueToCartesianChartY(point.value, domain)
319
+ const valueLabelY =
320
+ point.value < 0
321
+ ? y + VALUE_LABEL_OFFSET
322
+ : Math.max(2, y - VALUE_LABEL_OFFSET)
323
+
324
+ return {
325
+ label: point.label,
326
+ value: point.value,
327
+ formattedValue: formatChartValue(point.value, valueSuffix),
328
+ x,
329
+ y,
330
+ valueLabelY,
331
+ valueLabelBaseline: point.value < 0 ? 'hanging' : 'auto',
332
+ }
333
+ })
334
+
335
+ return {
336
+ label: series.label,
337
+ color:
338
+ series.color ||
339
+ DEFAULT_CHART_COLORS[index % DEFAULT_CHART_COLORS.length],
340
+ path: resolveLinePath(points, curve),
341
+ areaPath: resolveAreaPath(points, zeroY, curve),
342
+ points,
343
+ }
344
+ })
345
+ }
346
+
347
+ function resolveSeries(
348
+ seriesInput: LineChart['series'],
349
+ ): ResolvedLineChartSourceSeries[] {
350
+ return (unref(seriesInput) || [])
351
+ .map((series, index) => {
352
+ const resolvedSeries = unref(series)
353
+ return {
354
+ label: resolveChartText(resolvedSeries?.label) || `Series ${index + 1}`,
355
+ color: resolveChartText(resolvedSeries?.color),
356
+ points: resolvePoints(resolvedSeries?.points),
357
+ }
358
+ })
359
+ .filter((series) => series.points.length > 0)
360
+ }
361
+
362
+ function resolvePoints(
363
+ pointsInput: LineChartSeries['points'],
364
+ ): ResolvedLineChartSourcePoint[] {
365
+ return (unref(pointsInput) || [])
366
+ .map((pointInput, index) => {
367
+ const point = unref(pointInput)
368
+ const value = readChartNumber(point?.value, Number.NaN)
369
+ return {
370
+ label: resolveChartText(point?.label) || `Point ${index + 1}`,
371
+ value,
372
+ }
373
+ })
374
+ .filter((point) => Number.isFinite(point.value))
375
+ }
376
+
377
+ function resolveLinePath(
378
+ points: ResolvedLineChartPoint[],
379
+ curve: LineChartCurve,
380
+ ) {
381
+ if (!points.length) return ''
382
+ if (points.length === 1) return `M ${formatChartPoint(points[0])}`
383
+ if (curve === 'linear') {
384
+ return points
385
+ .map(
386
+ (point, index) =>
387
+ `${index === 0 ? 'M' : 'L'} ${formatChartPoint(point)}`,
388
+ )
389
+ .join(' ')
390
+ }
391
+
392
+ return [
393
+ `M ${formatChartPoint(points[0])}`,
394
+ ...points.slice(1).map((point, index) => {
395
+ const previous = points[index]
396
+ const midpointX = (previous.x + point.x) / 2
397
+ return [
398
+ 'C',
399
+ formatChartNumber(midpointX),
400
+ formatChartNumber(previous.y),
401
+ formatChartNumber(midpointX),
402
+ formatChartNumber(point.y),
403
+ formatChartPoint(point),
404
+ ].join(' ')
405
+ }),
406
+ ].join(' ')
407
+ }
408
+
409
+ function resolveAreaPath(
410
+ points: ResolvedLineChartPoint[],
411
+ zeroY: number,
412
+ curve: LineChartCurve,
413
+ ) {
414
+ if (!points.length) return ''
415
+ const first = points[0]
416
+ const last = points.at(-1) || first
417
+ return [
418
+ `M ${formatChartNumber(first.x)} ${formatChartNumber(zeroY)}`,
419
+ resolveLinePath(points, curve).replace(/^M /, 'L '),
420
+ `L ${formatChartNumber(last.x)} ${formatChartNumber(zeroY)}`,
421
+ 'Z',
422
+ ].join(' ')
423
+ }
424
+
425
+ function resolveXLabels(
426
+ series: ResolvedLineChartSeries[],
427
+ ): ResolvedLineChartLabel[] {
428
+ const points = series[0]?.points || []
429
+ if (!points.length) return []
430
+
431
+ const step = Math.max(1, Math.ceil(points.length / MAX_X_LABEL_COUNT))
432
+ return points
433
+ .filter((_, index) => index % step === 0 || index === points.length - 1)
434
+ .map((point) => ({
435
+ label: point.label,
436
+ x: point.x,
437
+ y: CATEGORY_LABEL_Y,
438
+ }))
439
+ }
440
+
441
+ function resolveDomain(props: LineChart): CartesianChartDomain {
442
+ const values = resolveSeries(props.series).flatMap((series) =>
443
+ series.points.map((point) => point.value),
444
+ )
445
+ return resolveCartesianChartDomain({
446
+ values,
447
+ minValue: props.minValue,
448
+ maxValue: props.maxValue,
449
+ })
450
+ }
451
+
452
+ function resolveAriaLabel(props: LineChart) {
453
+ return (
454
+ resolveChartText(props.ariaLabel) ||
455
+ resolveChartText(props.title) ||
456
+ 'Line chart'
457
+ )
458
+ }
459
+
460
+ function resolveCurve(value: RefOrValue<LineChartCurve> | undefined) {
461
+ return unref(value) === 'linear' ? 'linear' : 'smooth'
462
+ }
@@ -0,0 +1,91 @@
1
+ import {
2
+ styleBuilder,
3
+ type ThemeMode,
4
+ type ThemePalette,
5
+ themes,
6
+ } from '@purestack/ts-style'
7
+
8
+ const LINE_CHART_VALUE_FONT_SIZE = '0.15rem'
9
+ const LINE_CHART_LABEL_FONT_SIZE = '0.1375rem'
10
+ const LINE_CHART_AXIS_FONT_SIZE = '0.11875rem'
11
+ const LINE_CHART_EMPTY_FONT_SIZE = '0.1625rem'
12
+
13
+ export function registerLineChartStyles() {
14
+ themes.forEach((theme, palette) => {
15
+ registerLineChartBaseStyles(theme)
16
+ registerLineChartPaintStyles(theme, palette)
17
+ })
18
+ }
19
+
20
+ function registerLineChartBaseStyles(theme: ThemeMode) {
21
+ styleBuilder
22
+ .select('.line-chart__line', theme)
23
+ .fill('none')
24
+ .strokeWidth('0.72')
25
+ .strokeLinecap('round')
26
+ .strokeLinejoin('round')
27
+ .transition('opacity 180ms ease, filter 180ms ease')
28
+
29
+ styleBuilder
30
+ .select('.line-chart__area', theme)
31
+ .opacity('0.34')
32
+ .transition('opacity 180ms ease')
33
+
34
+ styleBuilder.select('.line-chart__point', theme).strokeWidth('0')
35
+
36
+ styleBuilder
37
+ .select('.line-chart__series:hover .line-chart__line', theme)
38
+ .opacity('0.54')
39
+
40
+ styleBuilder
41
+ .select('.line-chart__series:hover .line-chart__line:hover', theme)
42
+ .opacity('1')
43
+ .filter('brightness(1.12)')
44
+
45
+ styleBuilder
46
+ .select(
47
+ '.line-chart__label, .line-chart__value, .line-chart__empty, .line-chart__grid-line text',
48
+ theme,
49
+ )
50
+ .pointerEvents('none')
51
+ .letterSpacing('normal')
52
+ }
53
+
54
+ function registerLineChartPaintStyles(theme: ThemeMode, palette: ThemePalette) {
55
+ styleBuilder
56
+ .select('.line-chart__grid-line line', theme)
57
+ .stroke(palette.current.surfaceAlt.rest.border)
58
+ .strokeWidth('0.22')
59
+
60
+ styleBuilder
61
+ .select('.line-chart__zero-line', theme)
62
+ .stroke(palette.current.border.subtle)
63
+ .strokeWidth('0.36')
64
+
65
+ styleBuilder
66
+ .select('.line-chart__value', theme)
67
+ .fill(palette.current.text.default)
68
+ .fontSize(LINE_CHART_VALUE_FONT_SIZE)
69
+ .fontWeight(palette.font.weight.w700)
70
+
71
+ styleBuilder
72
+ .select('.line-chart__label', theme)
73
+ .fill(palette.current.text.subtle)
74
+ .fontSize(LINE_CHART_LABEL_FONT_SIZE)
75
+ .fontWeight(palette.font.weight.w700)
76
+
77
+ styleBuilder
78
+ .select('.line-chart__grid-line text', theme)
79
+ .fill(palette.current.text.subtle)
80
+ .fontSize(LINE_CHART_AXIS_FONT_SIZE)
81
+ .fontWeight(palette.font.weight.w500)
82
+ .set('dominant-baseline', 'middle')
83
+ .set('text-anchor', 'end')
84
+
85
+ styleBuilder
86
+ .select('.line-chart__empty', theme)
87
+ .fill(palette.current.text.subtle)
88
+ .fontSize(LINE_CHART_EMPTY_FONT_SIZE)
89
+ .fontWeight(palette.font.weight.w700)
90
+ .set('dominant-baseline', 'middle')
91
+ }