@automattic/charts 1.0.2 → 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.
- package/CHANGELOG.md +11 -0
- package/dist/{chunk-G3PMV62Z.js → chunk-5WRI5ZAA.js} +1 -6
- package/dist/{chunk-EMMSS5I5.cjs → chunk-DZUJEN5N.cjs} +2 -7
- package/dist/chunk-DZUJEN5N.cjs.map +1 -0
- package/dist/index.cjs +519 -1350
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +31 -40
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +619 -1450
- package/dist/index.js.map +1 -1
- package/dist/visx/group/index.cjs +1 -1
- package/dist/visx/group/index.js +1 -1
- package/dist/visx/legend/index.cjs +1 -1
- package/dist/visx/legend/index.js +1 -1
- package/dist/visx/text/index.cjs +1 -1
- package/dist/visx/text/index.js +1 -1
- package/package.json +8 -7
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +19 -26
- package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +1 -1
- package/src/charts/leaderboard-chart/leaderboard-chart.tsx +2 -2
- package/src/charts/line-chart/line-chart.module.scss +3 -3
- package/src/charts/line-chart/private/line-chart-annotation-label-popover.tsx +2 -2
- package/src/charts/pie-chart/pie-chart.tsx +5 -3
- package/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +3 -3
- package/src/components/legend/private/base-legend.module.scss +2 -2
- package/src/components/tooltip/base-tooltip.module.scss +1 -1
- package/src/components/trend-indicator/trend-indicator.module.scss +2 -2
- package/src/hooks/use-chart-margin.tsx +1 -14
- package/src/providers/chart-context/themes.ts +7 -1
- package/src/types.ts +2 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/resolve-font-size.ts +37 -0
- package/src/utils/test/resolve-css-var.test.ts +3 -5
- package/src/utils/test/resolve-font-size.test.ts +66 -0
- package/dist/chunk-EMMSS5I5.cjs.map +0 -1
- /package/dist/{chunk-G3PMV62Z.js.map → chunk-5WRI5ZAA.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-DZUJEN5N.cjs');
|
|
2
2
|
|
|
3
3
|
// src/visx/group/index.ts
|
|
4
4
|
var _group = require('@visx/group');
|
package/dist/visx/group/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-DZUJEN5N.cjs');
|
|
2
2
|
|
|
3
3
|
// src/visx/legend/index.ts
|
|
4
4
|
var _legend = require('@visx/legend');
|
package/dist/visx/text/index.cjs
CHANGED
package/dist/visx/text/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/charts",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Display charts within Automattic products.",
|
|
5
5
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"typecheck": "tsgo --noEmit"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@automattic/number-formatters": "^1.1.
|
|
67
|
-
"@babel/runtime": "7.
|
|
66
|
+
"@automattic/number-formatters": "^1.1.5",
|
|
67
|
+
"@babel/runtime": "7.29.2",
|
|
68
68
|
"@react-spring/web": "9.7.5",
|
|
69
69
|
"@visx/annotation": "^3.12.0",
|
|
70
70
|
"@visx/axis": "^3.12.0",
|
|
@@ -83,14 +83,14 @@
|
|
|
83
83
|
"@visx/vendor": "^3.12.0",
|
|
84
84
|
"@visx/xychart": "^3.12.0",
|
|
85
85
|
"@wordpress/i18n": "^6.0.0",
|
|
86
|
-
"@wordpress/
|
|
86
|
+
"@wordpress/icons": "^12.0.0",
|
|
87
|
+
"@wordpress/theme": "0.10.0",
|
|
87
88
|
"@wordpress/ui": "0.9.0",
|
|
88
89
|
"clsx": "2.1.1",
|
|
89
90
|
"date-fns": "^4.1.0",
|
|
90
91
|
"deepmerge": "4.3.1",
|
|
91
92
|
"dompurify": "^3.3.3",
|
|
92
93
|
"fast-deep-equal": "3.1.3",
|
|
93
|
-
"gridicons": "3.4.2",
|
|
94
94
|
"react-google-charts": "^5.2.1",
|
|
95
95
|
"tslib": "2.8.1"
|
|
96
96
|
},
|
|
@@ -110,8 +110,9 @@
|
|
|
110
110
|
"@types/react-dom": "18.3.7",
|
|
111
111
|
"@typescript/native-preview": "7.0.0-dev.20260225.1",
|
|
112
112
|
"@visx/glyph": "3.12.0",
|
|
113
|
-
"@wordpress/components": "32.
|
|
114
|
-
"@wordpress/element": "6.
|
|
113
|
+
"@wordpress/components": "32.5.0",
|
|
114
|
+
"@wordpress/element": "6.43.0",
|
|
115
|
+
"@wordpress/private-apis": "1.43.0",
|
|
115
116
|
"babel-jest": "30.3.0",
|
|
116
117
|
"babel-plugin-react-remove-properties": "^0.3.1",
|
|
117
118
|
"esbuild": "0.27.4",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
.conversion-funnel-chart {
|
|
2
|
-
font-family: var(--funnel-font-family, "SF Pro Text");
|
|
3
2
|
|
|
4
3
|
&--loading {
|
|
5
4
|
opacity: 0.6;
|
|
@@ -19,22 +18,20 @@
|
|
|
19
18
|
overflow: hidden;
|
|
20
19
|
color: #1e1e1e;
|
|
21
20
|
text-overflow: ellipsis;
|
|
22
|
-
font-
|
|
23
|
-
font-size: 18px;
|
|
21
|
+
font-size: var(--wpds-font-size-xl, 18px);
|
|
24
22
|
font-style: normal;
|
|
25
|
-
font-weight:
|
|
26
|
-
line-height: 20px;
|
|
23
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
24
|
+
line-height: var(--wpds-font-line-height-sm, 20px);
|
|
27
25
|
margin: 0;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
.change-indicator {
|
|
31
29
|
overflow: hidden;
|
|
32
30
|
text-overflow: ellipsis;
|
|
33
|
-
font-
|
|
34
|
-
font-size: 13px;
|
|
31
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
35
32
|
font-style: normal;
|
|
36
|
-
font-weight:
|
|
37
|
-
line-height: 20px;
|
|
33
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
34
|
+
line-height: var(--wpds-font-line-height-sm, 20px);
|
|
38
35
|
margin: 0;
|
|
39
36
|
}
|
|
40
37
|
|
|
@@ -69,11 +66,10 @@
|
|
|
69
66
|
|
|
70
67
|
.step-label {
|
|
71
68
|
color: #757575;
|
|
72
|
-
font-
|
|
73
|
-
font-size: 12px;
|
|
69
|
+
font-size: var(--wpds-font-size-sm, 12px);
|
|
74
70
|
font-style: normal;
|
|
75
|
-
font-weight: 400;
|
|
76
|
-
line-height: 16px;
|
|
71
|
+
font-weight: var(--wpds-font-weight-regular, 400);
|
|
72
|
+
line-height: var(--wpds-font-line-height-xs, 16px);
|
|
77
73
|
margin: 0 0 2px 0;
|
|
78
74
|
display: block;
|
|
79
75
|
overflow: hidden;
|
|
@@ -82,11 +78,10 @@
|
|
|
82
78
|
|
|
83
79
|
.step-rate {
|
|
84
80
|
color: #1e1e1e;
|
|
85
|
-
font-
|
|
86
|
-
font-size: 13px;
|
|
81
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
87
82
|
font-style: normal;
|
|
88
|
-
font-weight:
|
|
89
|
-
line-height: 20px;
|
|
83
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
84
|
+
line-height: var(--wpds-font-line-height-sm, 20px);
|
|
90
85
|
margin: 0;
|
|
91
86
|
display: block;
|
|
92
87
|
}
|
|
@@ -139,25 +134,23 @@
|
|
|
139
134
|
|
|
140
135
|
.tooltip-title {
|
|
141
136
|
color: #1e1e1e;
|
|
142
|
-
font-
|
|
143
|
-
font-size: 12px;
|
|
137
|
+
font-size: var(--wpds-font-size-sm, 12px);
|
|
144
138
|
font-style: normal;
|
|
145
|
-
font-weight: 400;
|
|
146
|
-
line-height: 16px;
|
|
139
|
+
font-weight: var(--wpds-font-weight-regular, 400);
|
|
140
|
+
line-height: var(--wpds-font-line-height-xs, 16px);
|
|
147
141
|
}
|
|
148
142
|
|
|
149
143
|
.tooltip-content {
|
|
150
144
|
color: #1e1e1e;
|
|
151
|
-
font-
|
|
152
|
-
font-size: 13px;
|
|
145
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
153
146
|
font-style: normal;
|
|
154
|
-
font-weight:
|
|
155
|
-
line-height: 20px;
|
|
147
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
148
|
+
line-height: var(--wpds-font-line-height-sm, 20px);
|
|
156
149
|
}
|
|
157
150
|
|
|
158
151
|
.empty-state {
|
|
159
152
|
text-align: center;
|
|
160
153
|
padding: 48px 24px;
|
|
161
154
|
color: #6b7280;
|
|
162
|
-
font-size: 16px;
|
|
155
|
+
font-size: var(--wpds-font-size-lg, 16px);
|
|
163
156
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @wordpress/no-unsafe-wp-apis */
|
|
2
|
-
import { __experimentalGrid as Grid
|
|
2
|
+
import { __experimentalGrid as Grid } from '@wordpress/components';
|
|
3
3
|
import { Fragment } from '@wordpress/element';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { Stack } from '@wordpress/ui';
|
|
5
|
+
import { Stack, Text } from '@wordpress/ui';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import { useContext, useMemo, type FC } from 'react';
|
|
8
8
|
import { Legend } from '../../components/legend';
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
&__tooltip-date {
|
|
24
|
-
font-weight:
|
|
24
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
25
25
|
padding-bottom: 10px;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
&__tooltip-label {
|
|
36
|
-
font-weight:
|
|
36
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
37
37
|
padding-right: 1rem;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
background: #fff;
|
|
66
66
|
border: none;
|
|
67
67
|
border-radius: 4px;
|
|
68
|
-
font-size:
|
|
68
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
69
69
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
|
70
70
|
position: fixed;
|
|
71
71
|
margin: 0.5rem;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
|
+
import { Icon, close } from '@wordpress/icons';
|
|
2
3
|
import clsx from 'clsx';
|
|
3
|
-
import Gridicon from 'gridicons';
|
|
4
4
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
5
5
|
import { isSafari } from '../../../utils';
|
|
6
6
|
import styles from '../line-chart.module.scss';
|
|
@@ -100,7 +100,7 @@ const LineChartAnnotationLabelWithPopover: FC< LineChartAnnotationLabelWithPopov
|
|
|
100
100
|
className={ styles[ 'line-chart__annotation-label-popover-close-button' ] }
|
|
101
101
|
aria-label={ __( 'Close', 'jetpack-charts' ) }
|
|
102
102
|
>
|
|
103
|
-
<
|
|
103
|
+
<Icon icon={ close } size={ 16 } />
|
|
104
104
|
</button>
|
|
105
105
|
</div>
|
|
106
106
|
</div>
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
useGlobalChartsTheme,
|
|
21
21
|
GlobalChartsContext,
|
|
22
22
|
} from '../../providers';
|
|
23
|
-
import { attachSubComponents } from '../../utils';
|
|
23
|
+
import { attachSubComponents, resolveFontSize } from '../../utils';
|
|
24
24
|
import { getStringWidth } from '../../visx/text';
|
|
25
25
|
import { ChartSVG, ChartHTML, useChartChildren } from '../private/chart-composition';
|
|
26
26
|
import { ChartLayout } from '../private/chart-layout';
|
|
@@ -441,10 +441,12 @@ const PieChartInternal = ( {
|
|
|
441
441
|
groupProps.onMouseLeave = onMouseLeave;
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
|
|
445
|
-
const fontSize = 12;
|
|
444
|
+
const svgLabelSmall = providerTheme.svgLabelSmall;
|
|
445
|
+
const fontSize = resolveFontSize( svgLabelSmall?.fontSize ) ?? 12;
|
|
446
446
|
const estimatedTextWidth = getStringWidth( arc.data.label, {
|
|
447
447
|
fontSize,
|
|
448
|
+
fontFamily: svgLabelSmall?.fontFamily,
|
|
449
|
+
fontWeight: svgLabelSmall?.fontWeight,
|
|
448
450
|
} );
|
|
449
451
|
const labelPadding = 6;
|
|
450
452
|
const backgroundWidth = estimatedTextWidth + labelPadding * 2;
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
.label {
|
|
14
|
-
font-weight:
|
|
15
|
-
font-size: 16px;
|
|
14
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
15
|
+
font-size: var(--wpds-font-size-lg, 16px);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
.note {
|
|
19
|
-
font-size:
|
|
19
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
.legend-item {
|
|
45
45
|
display: flex;
|
|
46
46
|
align-items: center;
|
|
47
|
-
font-size:
|
|
47
|
+
font-size: var(--wpds-font-size-md, 13px);
|
|
48
48
|
|
|
49
49
|
&--interactive {
|
|
50
50
|
cursor: pointer;
|
|
@@ -101,6 +101,6 @@
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
.legend-item-value {
|
|
104
|
-
font-weight:
|
|
104
|
+
font-weight: var(--wpds-font-weight-medium, 499);
|
|
105
105
|
flex-shrink: 0; // Prevent value from shrinking when text is ellipsized
|
|
106
106
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createScale, getTicks } from '@visx/scale';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { getLongestTickWidth } from '../utils';
|
|
3
|
+
import { getLongestTickWidth, resolveFontSize } from '../utils';
|
|
4
4
|
import type { BaseChartProps, DataPointDate, SeriesData } from '../types';
|
|
5
5
|
import type { XYChartTheme } from '@visx/xychart';
|
|
6
6
|
|
|
@@ -50,19 +50,6 @@ const DEFAULT_TICK_LENGTH = 8;
|
|
|
50
50
|
*/
|
|
51
51
|
const DEFAULT_Y_TICK_WIDTH = 40;
|
|
52
52
|
|
|
53
|
-
const resolveFontSize = ( val?: number | string ): number | undefined => {
|
|
54
|
-
if ( typeof val === 'number' && ! isNaN( val ) ) {
|
|
55
|
-
return val;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if ( typeof val === 'string' ) {
|
|
59
|
-
const parsed = parseFloat( val );
|
|
60
|
-
return isNaN( parsed ) ? undefined : parsed;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return undefined;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
53
|
const getXAxisLabelMetrics = ( theme: XYChartTheme, orientation: 'top' | 'bottom' ) => {
|
|
67
54
|
const xAxisStyles =
|
|
68
55
|
orientation === 'top' ? theme.axisStyles?.x?.top : theme.axisStyles?.x?.bottom;
|
|
@@ -26,7 +26,13 @@ const defaultTheme: CompleteChartTheme = {
|
|
|
26
26
|
},
|
|
27
27
|
seriesLineStyles: [],
|
|
28
28
|
glyphs: [],
|
|
29
|
-
|
|
29
|
+
// `fontFamily: 'inherit'` overrides visx's hardcoded default font stack
|
|
30
|
+
// (`-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif`)
|
|
31
|
+
// that `buildChartTheme` injects as an inline style on SVG `<text>`
|
|
32
|
+
// elements for axis labels and ticks. Setting `inherit` lets SVG text
|
|
33
|
+
// pick up the host application's font-family via normal CSS inheritance.
|
|
34
|
+
svgLabelSmall: { fill: 'var(--jp-gray-80, #2c3338)', fontFamily: 'inherit' },
|
|
35
|
+
svgLabelBig: { fontFamily: 'inherit' },
|
|
30
36
|
annotationStyles: {
|
|
31
37
|
label: {
|
|
32
38
|
anchorLineStroke: 'var(--jp-gray-80, #2c3338)',
|
package/src/types.ts
CHANGED
|
@@ -243,6 +243,8 @@ export type ChartTheme = {
|
|
|
243
243
|
};
|
|
244
244
|
/** Styles for small SVG text (eg. axis tick labels), passed through to the XYChart theme. */
|
|
245
245
|
svgLabelSmall?: TextProps;
|
|
246
|
+
/** Styles for large SVG text (eg. axis titles), passed through to the XYChart theme. */
|
|
247
|
+
svgLabelBig?: TextProps;
|
|
246
248
|
annotationStyles?: AnnotationStyles;
|
|
247
249
|
/** GeoChart specific settings */
|
|
248
250
|
geoChart?: {
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a theme `fontSize` value into a plain number suitable for
|
|
3
|
+
* canvas-based measurement (e.g. `getStringWidth`).
|
|
4
|
+
*
|
|
5
|
+
* Accepts:
|
|
6
|
+
* - A number — returned as-is
|
|
7
|
+
* - A pixel string like `"12px"` — parsed and returned as a number
|
|
8
|
+
*
|
|
9
|
+
* Returns `undefined` for any other input (missing value, NaN, or
|
|
10
|
+
* relative units like `rem`/`em`/`%`/`vh`) so callers can fall back to
|
|
11
|
+
* their own default. Relative units are intentionally rejected because
|
|
12
|
+
* we cannot resolve them to absolute pixels here without a parent
|
|
13
|
+
* computed style, and silently returning the unitless prefix
|
|
14
|
+
* (`parseFloat("0.875rem") === 0.875`) would produce nearly-zero
|
|
15
|
+
* widths in measurement code.
|
|
16
|
+
* @param val - Raw font size value from a theme, axis style, or props
|
|
17
|
+
* @return Parsed numeric font size in pixels, or `undefined` when unresolvable
|
|
18
|
+
*/
|
|
19
|
+
export const resolveFontSize = ( val?: number | string ): number | undefined => {
|
|
20
|
+
if ( typeof val === 'number' ) {
|
|
21
|
+
return isNaN( val ) ? undefined : val;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( typeof val === 'string' ) {
|
|
25
|
+
// Only accept plain numeric strings or pixel values.
|
|
26
|
+
// Reject rem, em, %, vh, vw, etc. — they cannot be resolved to
|
|
27
|
+
// absolute pixels without a computed style context.
|
|
28
|
+
const match = val.trim().match( /^(-?\d+\.?\d*|-?\.\d+)(px)?$/ );
|
|
29
|
+
if ( ! match ) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const parsed = parseFloat( match[ 1 ] );
|
|
33
|
+
return isNaN( parsed ) ? undefined : parsed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return undefined;
|
|
37
|
+
};
|
|
@@ -414,9 +414,8 @@ describe( 'resolveCssVariable', () => {
|
|
|
414
414
|
if ( element === themedElement ) {
|
|
415
415
|
return {
|
|
416
416
|
getPropertyValue: ( prop: string ) => {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return '#c029dc'; // User's custom accent color
|
|
417
|
+
if ( prop === '--custom-accent-color' ) {
|
|
418
|
+
return '#c029dc';
|
|
420
419
|
}
|
|
421
420
|
return '';
|
|
422
421
|
},
|
|
@@ -428,8 +427,7 @@ describe( 'resolveCssVariable', () => {
|
|
|
428
427
|
} );
|
|
429
428
|
window.getComputedStyle = mockGetComputedStyle as unknown as typeof window.getComputedStyle;
|
|
430
429
|
|
|
431
|
-
|
|
432
|
-
const result = resolveCssVariable( '--wpds-color-bg-interactive-brand-weak', themedElement );
|
|
430
|
+
const result = resolveCssVariable( '--custom-accent-color', themedElement );
|
|
433
431
|
expect( result ).toBe( '#c029dc' );
|
|
434
432
|
} );
|
|
435
433
|
} );
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { resolveFontSize } from '../resolve-font-size';
|
|
2
|
+
|
|
3
|
+
describe( 'resolveFontSize', () => {
|
|
4
|
+
describe( 'numeric input', () => {
|
|
5
|
+
it( 'returns whole numbers as-is', () => {
|
|
6
|
+
expect( resolveFontSize( 12 ) ).toBe( 12 );
|
|
7
|
+
expect( resolveFontSize( 0 ) ).toBe( 0 );
|
|
8
|
+
} );
|
|
9
|
+
|
|
10
|
+
it( 'returns decimal numbers as-is', () => {
|
|
11
|
+
expect( resolveFontSize( 13.5 ) ).toBe( 13.5 );
|
|
12
|
+
} );
|
|
13
|
+
|
|
14
|
+
it( 'returns undefined for NaN', () => {
|
|
15
|
+
expect( resolveFontSize( NaN ) ).toBeUndefined();
|
|
16
|
+
} );
|
|
17
|
+
} );
|
|
18
|
+
|
|
19
|
+
describe( 'string input', () => {
|
|
20
|
+
it( 'parses bare numeric strings', () => {
|
|
21
|
+
expect( resolveFontSize( '12' ) ).toBe( 12 );
|
|
22
|
+
expect( resolveFontSize( '13.5' ) ).toBe( 13.5 );
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
it( 'parses pixel strings', () => {
|
|
26
|
+
expect( resolveFontSize( '12px' ) ).toBe( 12 );
|
|
27
|
+
expect( resolveFontSize( '13.5px' ) ).toBe( 13.5 );
|
|
28
|
+
} );
|
|
29
|
+
|
|
30
|
+
it( 'trims whitespace before parsing', () => {
|
|
31
|
+
expect( resolveFontSize( ' 14px ' ) ).toBe( 14 );
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
it( 'rejects rem values rather than returning the unitless prefix', () => {
|
|
35
|
+
expect( resolveFontSize( '0.875rem' ) ).toBeUndefined();
|
|
36
|
+
} );
|
|
37
|
+
|
|
38
|
+
it( 'rejects em, %, vh, vw and other relative units', () => {
|
|
39
|
+
expect( resolveFontSize( '1em' ) ).toBeUndefined();
|
|
40
|
+
expect( resolveFontSize( '100%' ) ).toBeUndefined();
|
|
41
|
+
expect( resolveFontSize( '2vh' ) ).toBeUndefined();
|
|
42
|
+
expect( resolveFontSize( '2vw' ) ).toBeUndefined();
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
it( 'rejects keywords like inherit, initial, unset', () => {
|
|
46
|
+
expect( resolveFontSize( 'inherit' ) ).toBeUndefined();
|
|
47
|
+
expect( resolveFontSize( 'initial' ) ).toBeUndefined();
|
|
48
|
+
expect( resolveFontSize( 'medium' ) ).toBeUndefined();
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
it( 'returns undefined for empty string', () => {
|
|
52
|
+
expect( resolveFontSize( '' ) ).toBeUndefined();
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
it( 'returns undefined for unparseable strings', () => {
|
|
56
|
+
expect( resolveFontSize( 'abc' ) ).toBeUndefined();
|
|
57
|
+
expect( resolveFontSize( 'pxpx' ) ).toBeUndefined();
|
|
58
|
+
} );
|
|
59
|
+
} );
|
|
60
|
+
|
|
61
|
+
describe( 'missing input', () => {
|
|
62
|
+
it( 'returns undefined for undefined', () => {
|
|
63
|
+
expect( resolveFontSize( undefined ) ).toBeUndefined();
|
|
64
|
+
} );
|
|
65
|
+
} );
|
|
66
|
+
} );
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-EMMSS5I5.cjs"],"names":[],"mappings":"AAAA,6EAAI,SAAS,EAAE,MAAM,CAAC,MAAM;AAC5B,IAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,iBAAiB,EAAE,MAAM,CAAC,wBAAwB;AACtD,IAAI,kBAAkB,EAAE,MAAM,CAAC,mBAAmB;AAClD,IAAI,aAAa,EAAE,MAAM,CAAC,cAAc;AACxC,IAAI,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,cAAc;AAClD,IAAI,WAAW,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS,SAAS,CAAC,EAAE;AACnD,EAAE,OAAO,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO;AACpG,CAAC;AACD,IAAI,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG;AAChC,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,GAAG;AACtB,IAAI,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAI,YAAY,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;AAC9C,EAAE,GAAG,CAAC,KAAK,GAAG,OAAO,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,IAAI,UAAU,EAAE;AACtE,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;AAC3C,MAAM,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,IAAI,MAAM;AACvD,QAAQ,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1H,EAAE;AACF,EAAE,OAAO,EAAE;AACX,CAAC;AACD,IAAI,QAAQ,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW;AAChH;AACA;AACA;AACA;AACA,EAAE,WAAW,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,EAAE,MAAM;AACjH,EAAE;AACF,CAAC,CAAC;AACF;AACA;AACE;AACA;AACA;AACF,wFAAC","file":"/home/runner/work/jetpack/jetpack/projects/js-packages/charts/dist/chunk-EMMSS5I5.cjs"}
|
|
File without changes
|