basalt-ui 2.22.0 → 2.23.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 +27 -0
- package/MIGRATING.md +187 -12
- package/agent/agents/basalt-design-reviewer.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +51 -5
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +2 -1
- package/dist/charts/CartesianChart.d.ts +2 -0
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/ChartCard.d.ts +1 -1
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +25 -15
- package/dist/charts/Sparkline.d.ts +8 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +67 -13
- package/dist/charts/band-fold.d.ts +22 -4
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +10 -2
- package/dist/charts/chart-dates.d.ts +12 -0
- package/dist/charts/chart-dates.d.ts.map +1 -0
- package/dist/charts/chart-dates.js +16 -0
- package/dist/charts/compile.d.ts +8 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +30 -21
- package/dist/charts/date-tick-format.d.ts +5 -5
- package/dist/charts/date-tick-format.d.ts.map +1 -1
- package/dist/charts/date-tick-format.js +3 -7
- package/dist/charts/labels.d.ts +7 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +28 -17
- package/dist/charts/ref-label.d.ts +17 -0
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +13 -1
- package/dist/charts/sparkline.module.css +8 -11
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +3 -1
- package/dist/charts/types.d.ts +4 -3
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +9 -5
- package/dist/cli/shot/detect.js +8 -5
- package/dist/cli/shot/playwright.d.ts +8 -0
- package/dist/cli/shot/playwright.d.ts.map +1 -1
- package/dist/cli/shot/playwright.js +5 -1
- package/dist/cli/shot/types.d.ts +2 -0
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/tokens-css.d.ts +5 -7
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +11 -12
- package/dist/dashboard/bar-list.d.ts +6 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +8 -0
- package/dist/dashboard/bar-list.module.css +30 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +2 -2
- package/dist/dashboard/meter-model.d.ts +25 -20
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +24 -12
- package/dist/dashboard/meter-parts.d.ts +1 -1
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +39 -4
- package/dist/dashboard/meter.d.ts +14 -8
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +1 -1
- package/dist/dashboard/meter.module.css +15 -0
- package/dist/dashboard/meter.module.css.d.ts +1 -0
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/stat-card-parts.js +1 -1
- package/dist/dashboard/stat-card.module.css +25 -6
- package/dist/dashboard/stat-group.module.css +7 -0
- package/dist/dashboard/stat-strip.d.ts +15 -5
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +50 -34
- package/dist/dashboard/stat-strip.module.css +83 -61
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +0 -5
- package/dist/styles.css +18 -11
- package/dist/theme/controls.module.css +14 -0
- package/dist/theme/controls.module.css.d.ts +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +10 -7
- package/dist/theme/status-verdict.d.ts.map +1 -1
- package/dist/theme/status-verdict.js +9 -1
- package/dist/tokens/palette.d.ts +7 -10
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +7 -10
- package/llms.txt +6 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +55 -5
- package/src/charts/Bars.tsx +2 -1
- package/src/charts/CartesianChart.tsx +2 -0
- package/src/charts/ChartCard.tsx +32 -19
- package/src/charts/Sparkline.tsx +92 -19
- package/src/charts/band-fold.ts +25 -6
- package/src/charts/chart-dates.ts +30 -0
- package/src/charts/compile.ts +64 -23
- package/src/charts/date-tick-format.ts +10 -13
- package/src/charts/labels.ts +43 -22
- package/src/charts/ref-label.ts +27 -0
- package/src/charts/sparkline.module.css +8 -11
- package/src/charts/state.tsx +6 -3
- package/src/charts/types.ts +4 -3
- package/src/cli/shot/capture.ts +15 -3
- package/src/cli/shot/detect.ts +9 -9
- package/src/cli/shot/playwright.ts +18 -2
- package/src/cli/shot/types.ts +2 -0
- package/src/cli/tokens-css.ts +18 -20
- package/src/dashboard/bar-list.module.css +30 -0
- package/src/dashboard/bar-list.tsx +29 -0
- package/src/dashboard/delta-badge.tsx +6 -2
- package/src/dashboard/meter-model.ts +58 -41
- package/src/dashboard/meter-parts.tsx +66 -5
- package/src/dashboard/meter.module.css +15 -0
- package/src/dashboard/meter.module.css.d.ts +1 -0
- package/src/dashboard/meter.tsx +15 -11
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/stat-card-parts.tsx +1 -1
- package/src/dashboard/stat-card.module.css +25 -6
- package/src/dashboard/stat-group.module.css +7 -0
- package/src/dashboard/stat-strip.module.css +83 -61
- package/src/dashboard/stat-strip.tsx +93 -54
- package/src/guard/index.ts +0 -5
- package/src/styles.css +18 -11
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +14 -8
- package/src/theme/controls.module.css +14 -0
- package/src/theme/controls.module.css.d.ts +1 -0
- package/src/theme/index.ts +10 -7
- package/src/theme/status-verdict.tsx +5 -1
- package/src/tokens/palette.ts +7 -10
package/src/charts/compile.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* binding, the tooltip content, and the container-class guide ladder.
|
|
6
6
|
* TanStack owns margins (measured), layout, focus and keyboard, the tooltip surface and SSR.
|
|
7
7
|
*/
|
|
8
|
+
import { headerDay, readoutClock } from './chart-dates'
|
|
8
9
|
import { dateTickFormat, utcAxisDate } from './date-tick-format'
|
|
9
10
|
import { crosshair } from '@tanstack/charts/crosshair'
|
|
10
11
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
@@ -26,7 +27,7 @@ import type {
|
|
|
26
27
|
StoredChartSpec,
|
|
27
28
|
} from '@tanstack/charts/types/core'
|
|
28
29
|
import { compact } from '../format/number'
|
|
29
|
-
import { NON_FINITE,
|
|
30
|
+
import { NON_FINITE, numberFormat } from '../format/shared'
|
|
30
31
|
import { VX } from '../tokens'
|
|
31
32
|
import type { ContainerClass } from '../tokens/size-classes'
|
|
32
33
|
import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
|
|
@@ -98,6 +99,8 @@ export type CartesianInput<T, X extends ChartX> = Pick<
|
|
|
98
99
|
tooltipBelow?: boolean
|
|
99
100
|
/** The vertical rule under the cursor. Default `true`; a bar kind has none (its hover is the bar). */
|
|
100
101
|
crosshair?: boolean
|
|
102
|
+
/** The engine's point marker on the focused datum. Default `true`; a bar kind has none (its hover is the bar). */
|
|
103
|
+
focusRing?: boolean
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/** The one tick-label size, at every container width: the caption size, so a card never mixes sizes. */
|
|
@@ -113,7 +116,7 @@ const LADDER = {
|
|
|
113
116
|
|
|
114
117
|
/**
|
|
115
118
|
* A tick within this share of the x domain from its start counts as on the left edge: half a
|
|
116
|
-
*
|
|
119
|
+
* day label is ~15 px, 4–5% of a compact plot. Round ticks rarely land on the domain start
|
|
117
120
|
* exactly, so an equality test would miss the common case.
|
|
118
121
|
*/
|
|
119
122
|
const LEFT_EDGE_SHARE = 0.05
|
|
@@ -127,7 +130,7 @@ export function defaultNumberFormat(v: number): string {
|
|
|
127
130
|
* calendar date (east of UTC it is `22:00` UTC of the day before); any other key is its UTC date, so
|
|
128
131
|
* a key at 12:00 UTC or later never rolls to the next day.
|
|
129
132
|
*/
|
|
130
|
-
function bucketDay(d: Date): Date {
|
|
133
|
+
export function bucketDay(d: Date): Date {
|
|
131
134
|
const local = d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0
|
|
132
135
|
return new Date(
|
|
133
136
|
local
|
|
@@ -144,22 +147,9 @@ function bucketDay(d: Date): Date {
|
|
|
144
147
|
*/
|
|
145
148
|
export function utcHeaderDate(d: Date, dayOnly = false): string {
|
|
146
149
|
if (!Number.isFinite(d.getTime())) return NON_FINITE
|
|
147
|
-
const
|
|
148
|
-
const date = dateFormat(undefined, {
|
|
149
|
-
weekday: 'short',
|
|
150
|
-
day: 'numeric',
|
|
151
|
-
month: 'short',
|
|
152
|
-
year: 'numeric',
|
|
153
|
-
timeZone: 'UTC',
|
|
154
|
-
}).format(at)
|
|
150
|
+
const date = headerDay(dayOnly ? bucketDay(d) : d)
|
|
155
151
|
if (dayOnly || d.getTime() % DAY_MS === 0) return date
|
|
156
|
-
|
|
157
|
-
hour: '2-digit',
|
|
158
|
-
minute: '2-digit',
|
|
159
|
-
hourCycle: 'h23',
|
|
160
|
-
timeZone: 'UTC',
|
|
161
|
-
}).format(d)
|
|
162
|
-
return `${date} ${clock}`
|
|
152
|
+
return `${date} ${readoutClock(d)}`
|
|
163
153
|
}
|
|
164
154
|
|
|
165
155
|
const DAY_MS = 86_400_000
|
|
@@ -273,6 +263,40 @@ export function visibleSeries<T>(
|
|
|
273
263
|
|
|
274
264
|
type YAxis = { domain: readonly [number, number]; format: (v: number) => string }
|
|
275
265
|
|
|
266
|
+
/** The page locale's decimal separator (`.` or `,`). */
|
|
267
|
+
const decimalSeparator = (): string =>
|
|
268
|
+
numberFormat(undefined, {})
|
|
269
|
+
.formatToParts(1.1)
|
|
270
|
+
.find((p) => p.type === 'decimal')?.value ?? '.'
|
|
271
|
+
|
|
272
|
+
/** A trailing zero fraction behind a digit (`2.0`, `2,00`), the separator being a decimal one. */
|
|
273
|
+
const zeroFraction = (separator: string): RegExp =>
|
|
274
|
+
new RegExp(`(\\d)${separator.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}0+(?!\\d)`, 'g')
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The tick formatter. When every tick is a whole number (a whole step), a formatter that pads
|
|
278
|
+
* decimals (`toFixed(1)`) prints integers: `2 s`, not `2.0 s`. Only the page locale's decimal
|
|
279
|
+
* separator is read as one, so a thousands group (`1,000`, `1.000` in de) is never cut; a formatter
|
|
280
|
+
* that writes `.` under a `,` locale keeps its padding. The tooltip keeps the full format. The
|
|
281
|
+
* ticks are the engine's own (`count` goes through the same linear scale the engine builds).
|
|
282
|
+
*/
|
|
283
|
+
function wholeStepFormat<T>(
|
|
284
|
+
axis: YAxis,
|
|
285
|
+
cfg: AxisConfig<T> | undefined,
|
|
286
|
+
ticks: { values: readonly number[] } | { count: number },
|
|
287
|
+
): (v: number) => string {
|
|
288
|
+
const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)]
|
|
289
|
+
const values =
|
|
290
|
+
'values' in ticks
|
|
291
|
+
? ticks.values
|
|
292
|
+
: cfg?.scale === 'log'
|
|
293
|
+
? []
|
|
294
|
+
: scaleLinear().domain([lo, hi]).ticks(ticks.count)
|
|
295
|
+
if (values.length === 0 || !values.every(Number.isInteger)) return axis.format
|
|
296
|
+
const padded = zeroFraction(decimalSeparator())
|
|
297
|
+
return (v) => axis.format(v).replace(padded, '$1')
|
|
298
|
+
}
|
|
299
|
+
|
|
276
300
|
export function yGuide<T>(opts: {
|
|
277
301
|
cfg: AxisConfig<T> | undefined
|
|
278
302
|
axis: YAxis
|
|
@@ -288,13 +312,14 @@ export function yGuide<T>(opts: {
|
|
|
288
312
|
: { count: typeof cfg?.ticks === 'number' ? cfg.ticks : ladder.yTicks }
|
|
289
313
|
const gridLine = grid ? { grid: GRID_LINE } : {}
|
|
290
314
|
if (cls === 'micro') return { ...gridLine, axis: false }
|
|
315
|
+
const tickFormat = wholeStepFormat(axis, cfg, ticks)
|
|
291
316
|
// Labels sit in a gutter OUTSIDE the plot, against its edge: a line never runs through one.
|
|
292
317
|
return {
|
|
293
318
|
...gridLine,
|
|
294
319
|
...(side === 'right' && { side: 'right' as const }),
|
|
295
320
|
axis: {
|
|
296
321
|
line: false,
|
|
297
|
-
ticks: { ...ticks, format:
|
|
322
|
+
ticks: { ...ticks, format: tickFormat, line: false },
|
|
298
323
|
tickLabels: { fontSize: TICK_FONT, opacity: 1 },
|
|
299
324
|
},
|
|
300
325
|
}
|
|
@@ -708,6 +733,8 @@ function underlayMarks<T, X extends ChartX>(
|
|
|
708
733
|
return [...zones, ...xZones]
|
|
709
734
|
}
|
|
710
735
|
|
|
736
|
+
/** A band's bar spans this share of its half step (`paddingInner` 0.2 leaves 0.8 of the step). */
|
|
737
|
+
const BAR_BODY = 0.8
|
|
711
738
|
const REF_LABEL_DX = 6
|
|
712
739
|
const REF_LABEL_DY_ABOVE = -5
|
|
713
740
|
const REF_LABEL_DY_BELOW = 11
|
|
@@ -831,7 +858,11 @@ function buildScales<T, X extends ChartX>(opts: {
|
|
|
831
858
|
}
|
|
832
859
|
}
|
|
833
860
|
|
|
834
|
-
/**
|
|
861
|
+
/**
|
|
862
|
+
* The tooltip title: the consumer's header, a long UTC date for a Date x, else the axis format. A
|
|
863
|
+
* day-granular series keeps its long date under a consumer `formatX` too: that formatter shortens
|
|
864
|
+
* the ticks (`2 Sep`), it does not rename the day.
|
|
865
|
+
*/
|
|
835
866
|
function tooltipHeader<T, X extends ChartX>(
|
|
836
867
|
input: CartesianInput<T, X>,
|
|
837
868
|
formatX: (v: ChartValue) => string,
|
|
@@ -840,7 +871,7 @@ function tooltipHeader<T, X extends ChartX>(
|
|
|
840
871
|
d: T,
|
|
841
872
|
): string {
|
|
842
873
|
if (input.tooltip && input.tooltip.formatHeader) return input.tooltip.formatHeader(v as X, d)
|
|
843
|
-
if (v instanceof Date && !input.formatX) return utcHeaderDate(v, dayOnly)
|
|
874
|
+
if (v instanceof Date && (!input.formatX || dayOnly)) return utcHeaderDate(v, dayOnly)
|
|
844
875
|
return formatX(v)
|
|
845
876
|
}
|
|
846
877
|
|
|
@@ -1019,14 +1050,23 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
1019
1050
|
)
|
|
1020
1051
|
const dayOnly = dayGranular(model.values)
|
|
1021
1052
|
const names = (input.refLines ?? []).some((r) => r.label !== undefined && r.label !== '')
|
|
1022
|
-
// What an unpinned reference caption avoids: each visible series as (x share, y) points.
|
|
1053
|
+
// What an unpinned reference caption avoids: each visible series as (x share, y) points. A bar is
|
|
1054
|
+
// a filled column from zero, so it walks round its body instead of through its top centre.
|
|
1055
|
+
const barHalf = model.halfStep * BAR_BODY
|
|
1023
1056
|
const linesOn = (side: 'left' | 'right' | undefined): RefLabelPoint[][] =>
|
|
1024
1057
|
visible
|
|
1025
1058
|
.filter((s) => shared.onRight(s) === (side === 'right' && shared.right !== null))
|
|
1026
1059
|
.map((s) =>
|
|
1027
1060
|
rows(s.key).flatMap((r) => {
|
|
1028
1061
|
const fx = model.fraction(r.x)
|
|
1029
|
-
|
|
1062
|
+
if (fx === null || r.y === null) return []
|
|
1063
|
+
if (!(model.band && s.mark === 'bar')) return [{ fx, y: r.y }]
|
|
1064
|
+
return [
|
|
1065
|
+
{ fx: fx - barHalf, y: 0 },
|
|
1066
|
+
{ fx: fx - barHalf, y: r.y },
|
|
1067
|
+
{ fx: fx + barHalf, y: r.y },
|
|
1068
|
+
{ fx: fx + barHalf, y: 0 },
|
|
1069
|
+
]
|
|
1030
1070
|
}),
|
|
1031
1071
|
)
|
|
1032
1072
|
|
|
@@ -1090,6 +1130,7 @@ export function compileCartesian<T, X extends ChartX>(
|
|
|
1090
1130
|
// Followers resolve the leader's group, so they draw its dots; `quietWhileFollowing` mutes the
|
|
1091
1131
|
// tooltip unless the chart opts into following tooltips.
|
|
1092
1132
|
focus: 'group-x',
|
|
1133
|
+
...(input.focusRing === false && { focusRing: false as const }),
|
|
1093
1134
|
maxFocusDistance: Number.POSITIVE_INFINITY,
|
|
1094
1135
|
cursor: cursorBinding({
|
|
1095
1136
|
group: input.cursorGroup,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The default Date x tick labels: chosen from the TICK step (not the data step), read in UTC like
|
|
3
3
|
* the scale that placed them. A label may recur on one axis only behind a MARKER label (a day or a
|
|
4
|
-
* year) — `12:00, 18:00, 18
|
|
4
|
+
* year) — `12:00, 18:00, 18 Oct, 06:00, 12:00` is fine, `17 Oct, 17 Oct, 18 Oct` is not. Each span has
|
|
5
5
|
* a ladder of levels, plainest first; the first level that holds the invariant wins. The last rung
|
|
6
6
|
* of every ladder names the whole date (or instant) of its tick, so the invariant always holds.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
export const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
9
|
+
import { axisDay, axisDayYear, monthName } from './chart-dates'
|
|
11
10
|
|
|
12
|
-
export const
|
|
11
|
+
export const pad2 = (n: number): string => String(n).padStart(2, '0')
|
|
13
12
|
|
|
14
13
|
const DAY_MS = 86_400_000
|
|
15
14
|
const HOUR_MS = 3_600_000
|
|
@@ -19,18 +18,16 @@ const HOUR_MS = 3_600_000
|
|
|
19
18
|
*/
|
|
20
19
|
const MONTH_STEP_MS = 27 * DAY_MS
|
|
21
20
|
|
|
22
|
-
/** `
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
21
|
+
/** The day (`4 Oct`, in the page locale), read in UTC like the time scale (a local read shifts a
|
|
22
|
+
* day west of UTC). */
|
|
23
|
+
export const utcAxisDate = axisDay
|
|
26
24
|
|
|
27
25
|
const utcClock = (d: Date): string => `${pad2(d.getUTCHours())}:${pad2(d.getUTCMinutes())}`
|
|
28
26
|
const utcClockSeconds = (d: Date): string => `${utcClock(d)}:${pad2(d.getUTCSeconds())}`
|
|
29
27
|
const utcClockMillis = (d: Date): string =>
|
|
30
28
|
`${utcClockSeconds(d)}.${String(d.getUTCMilliseconds()).padStart(3, '0')}`
|
|
31
|
-
/** Two digits: a widened day label stays
|
|
32
|
-
const utcAxisDateYear =
|
|
33
|
-
`${utcAxisDate(d)}.${String(d.getUTCFullYear()).slice(2)}`
|
|
29
|
+
/** Two digits: a widened day label stays the same family (`4 Oct 26`). */
|
|
30
|
+
const utcAxisDateYear = axisDayYear
|
|
34
31
|
|
|
35
32
|
const isMidnight = (t: number): boolean => t % DAY_MS === 0
|
|
36
33
|
const isJanuary = (d: Date): boolean => d.getUTCMonth() === 0
|
|
@@ -69,7 +66,7 @@ const subDayLevels: Level[] = [
|
|
|
69
66
|
]
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
|
-
* A day or more: `
|
|
69
|
+
* A day or more: the day (`18 Oct`). Ticks are at least a day apart here, so they fall on different UTC days
|
|
73
70
|
* and the last rung, which names the full date, cannot repeat.
|
|
74
71
|
*/
|
|
75
72
|
const dayLevels: Level[] = [
|
|
@@ -121,7 +118,7 @@ function stepOf(times: readonly number[]): number {
|
|
|
121
118
|
|
|
122
119
|
/**
|
|
123
120
|
* A formatter for one tick set. A Date that is not among the ticks (a hover, a consumer reading
|
|
124
|
-
* the axis format) reads as plain
|
|
121
|
+
* the axis format) reads as the plain day: its position in the set is undefined.
|
|
125
122
|
*/
|
|
126
123
|
export function dateTickFormat(ticks: readonly Date[]): (d: Date) => string {
|
|
127
124
|
const times = [...new Set(ticks.map((t) => t.getTime()))].toSorted((a, b) => a - b)
|
package/src/charts/labels.ts
CHANGED
|
@@ -19,10 +19,15 @@ const END_LABEL_DX = 6
|
|
|
19
19
|
* that did not need to flip sits above its point, one that needed to and did not is cut.
|
|
20
20
|
*/
|
|
21
21
|
const END_LABEL_GLYPH_EM = 0.85
|
|
22
|
-
/** A label flipped inside the plot sits this far above its point. */
|
|
22
|
+
/** A label flipped inside the plot sits this far above (or, below its point, `BELOW`) its point. */
|
|
23
23
|
const END_LABEL_FLIP_DY = -9
|
|
24
|
+
const END_LABEL_FLIP_DY_BELOW = 13
|
|
25
|
+
/** The room a label's centre keeps from the plot's top and bottom edge, px: half its line. */
|
|
26
|
+
const END_LABEL_EDGE = 7
|
|
24
27
|
|
|
25
28
|
export type EndLabelAnchor = 'start' | 'end'
|
|
29
|
+
/** Which side of its line a flipped label sits: away from the line's last segment. */
|
|
30
|
+
export type EndLabelSide = 'above' | 'below'
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* The side of its point an end label takes: `start` (right of the point) unless the point leaves
|
|
@@ -49,6 +54,8 @@ export type EndLabel<T, X extends ChartX> = {
|
|
|
49
54
|
series: ChartSeries<T>
|
|
50
55
|
row: PlotRow<T, X>
|
|
51
56
|
anchor: EndLabelAnchor
|
|
57
|
+
/** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
|
|
58
|
+
side: EndLabelSide
|
|
52
59
|
/** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
|
|
53
60
|
nudge: number
|
|
54
61
|
}
|
|
@@ -58,24 +65,26 @@ type LastPoint<T, X extends ChartX> = {
|
|
|
58
65
|
row: PlotRow<T, X>
|
|
59
66
|
y: number
|
|
60
67
|
fraction: number
|
|
68
|
+
/** The value one finite point earlier: where the line's last segment comes from. */
|
|
69
|
+
prev: number | null
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
64
73
|
* Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
|
|
65
74
|
* shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
|
|
66
|
-
* topmost
|
|
75
|
+
* lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot. Order is kept.
|
|
67
76
|
*/
|
|
68
77
|
export function spreadLabels(ys: readonly number[], plotHeight: number): number[] {
|
|
69
78
|
const order = ys.map((y, i) => i).toSorted((a, b) => (ys[a] as number) - (ys[b] as number))
|
|
70
79
|
const placed = new Map<number, number>()
|
|
71
|
-
let floor =
|
|
80
|
+
let floor = END_LABEL_EDGE
|
|
72
81
|
for (const i of order) {
|
|
73
82
|
const at = Math.max(ys[i] as number, floor)
|
|
74
83
|
placed.set(i, at)
|
|
75
84
|
floor = at + END_LABEL_MIN_GAP
|
|
76
85
|
}
|
|
77
86
|
// Pushed past the top: slide the whole stack back down, then re-sweep from the top.
|
|
78
|
-
const top = plotHeight -
|
|
87
|
+
const top = plotHeight - END_LABEL_EDGE
|
|
79
88
|
let ceiling = Infinity
|
|
80
89
|
for (const i of order.toReversed()) {
|
|
81
90
|
const at = Math.min(placed.get(i) as number, ceiling, top)
|
|
@@ -101,40 +110,52 @@ export function endLabelPlan<T, X extends ChartX>(
|
|
|
101
110
|
if (naming === 'auto' && (plot.containerClass !== 'wide' || lines.length > MAX_END_LABELS))
|
|
102
111
|
return []
|
|
103
112
|
const last = lines.flatMap((series): LastPoint<T, X>[] => {
|
|
104
|
-
const
|
|
113
|
+
const finite = plot.rows(series.key).filter((r) => r.y !== null)
|
|
114
|
+
const row = finite.at(-1)
|
|
105
115
|
if (row === undefined || row.y === null) return []
|
|
106
116
|
const fraction = plot.xFraction(row.x)
|
|
107
117
|
if (fraction === null || fraction < 0 || fraction > 1) return []
|
|
108
|
-
return [{ series, row, y: row.y, fraction }]
|
|
118
|
+
return [{ series, row, y: row.y, fraction, prev: finite.at(-2)?.y ?? null }]
|
|
109
119
|
})
|
|
110
120
|
// No `y2` here (returned above), so every label reads the left domain.
|
|
111
121
|
const [lo, hi] = plot.yDomain
|
|
122
|
+
const placed = last.map(({ series, fraction, y, prev }) => {
|
|
123
|
+
const anchor = endLabelAnchor({
|
|
124
|
+
fraction,
|
|
125
|
+
plotWidth: plot.plotWidth,
|
|
126
|
+
label: series.label,
|
|
127
|
+
fontSize: VX.text.micro,
|
|
128
|
+
})
|
|
129
|
+
// A line falling into its end point comes from above: the label drops below it.
|
|
130
|
+
const side = prev !== null && prev > y ? ('below' as const) : ('above' as const)
|
|
131
|
+
// The label's centre, px from the plot's bottom, with its flip: what the spread keeps apart.
|
|
132
|
+
const centre = ((y - lo) / (hi - lo || 1)) * plot.plotHeight - endLabelOffset(anchor, side).dy
|
|
133
|
+
return { anchor, side, centre }
|
|
134
|
+
})
|
|
112
135
|
const shifts = spreadLabels(
|
|
113
|
-
|
|
136
|
+
placed.map((p) => p.centre),
|
|
114
137
|
plot.plotHeight,
|
|
115
138
|
)
|
|
116
|
-
return last.map(({ series, row
|
|
139
|
+
return last.map(({ series, row }, i) => ({
|
|
117
140
|
series,
|
|
118
141
|
row,
|
|
119
|
-
anchor:
|
|
120
|
-
|
|
121
|
-
plotWidth: plot.plotWidth,
|
|
122
|
-
label: series.label,
|
|
123
|
-
fontSize: VX.text.micro,
|
|
124
|
-
}),
|
|
142
|
+
anchor: (placed[i] as (typeof placed)[number]).anchor,
|
|
143
|
+
side: (placed[i] as (typeof placed)[number]).side,
|
|
125
144
|
nudge: 0 - (shifts[i] as number),
|
|
126
145
|
}))
|
|
127
146
|
}
|
|
128
147
|
|
|
129
|
-
/** The offset of a label from its point: right of it, level; or left of it
|
|
130
|
-
export function endLabelOffset(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
148
|
+
/** The offset of a label from its point: right of it, level; or left of it, above or below. */
|
|
149
|
+
export function endLabelOffset(
|
|
150
|
+
anchor: EndLabelAnchor,
|
|
151
|
+
side: EndLabelSide = 'above',
|
|
152
|
+
): { dx: number; dy: number } {
|
|
153
|
+
if (anchor === 'start') return { dx: END_LABEL_DX, dy: 0 }
|
|
154
|
+
return { dx: -END_LABEL_DX, dy: side === 'above' ? END_LABEL_FLIP_DY : END_LABEL_FLIP_DY_BELOW }
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>[]): ChartMarks {
|
|
137
|
-
return plan.map(({ series, row, anchor, nudge }) =>
|
|
158
|
+
return plan.map(({ series, row, anchor, side, nudge }) =>
|
|
138
159
|
decorative(
|
|
139
160
|
text([row], {
|
|
140
161
|
id: `${series.key}-end-label`,
|
|
@@ -144,8 +165,8 @@ export function endLabelMarks<T, X extends ChartX>(plan: readonly EndLabel<T, X>
|
|
|
144
165
|
fill: series.color,
|
|
145
166
|
fontSize: VX.text.micro,
|
|
146
167
|
anchor,
|
|
147
|
-
dx: endLabelOffset(anchor).dx,
|
|
148
|
-
dy: endLabelOffset(anchor).dy + nudge,
|
|
168
|
+
dx: endLabelOffset(anchor, side).dx,
|
|
169
|
+
dy: endLabelOffset(anchor, side).dy + nudge,
|
|
149
170
|
}),
|
|
150
171
|
),
|
|
151
172
|
)
|
package/src/charts/ref-label.ts
CHANGED
|
@@ -102,3 +102,30 @@ export function refLabelPosition(opts: {
|
|
|
102
102
|
order.find((p) => inPlot(p) && clear(p)) ?? order.find(inPlot) ?? (order[0] as RefLabelPosition)
|
|
103
103
|
)
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
/** The gap between a sparkline reference label's box and its line, px. */
|
|
107
|
+
const SPARK_LABEL_GAP = 2
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Which side of its line a sparkline's reference label sits on, and its `dy` (the engine centres
|
|
111
|
+
* the text on its y): above by default, below when the line is too near the plot top for the label
|
|
112
|
+
* box to fit above it. The box clears the line by {@link SPARK_LABEL_GAP}, so the dashed rule never
|
|
113
|
+
* strikes the text, and stays inside the plot (`height` less the line inset each side).
|
|
114
|
+
*/
|
|
115
|
+
export function referenceLabelPlacement(opts: {
|
|
116
|
+
value: number
|
|
117
|
+
domain: readonly [number, number]
|
|
118
|
+
height: number
|
|
119
|
+
/** The plot's margin inside the svg box, px. */
|
|
120
|
+
inset: number
|
|
121
|
+
fontSize: number
|
|
122
|
+
}): { side: 'above' | 'below'; dy: number } {
|
|
123
|
+
const { value, domain, height, inset, fontSize } = opts
|
|
124
|
+
const [lo, hi] = [Math.min(...domain), Math.max(...domain)]
|
|
125
|
+
const share = hi === lo ? 0 : (value - lo) / (hi - lo)
|
|
126
|
+
const line = inset + (height - 2 * inset) * (1 - share)
|
|
127
|
+
const reach = SPARK_LABEL_GAP + fontSize + 1
|
|
128
|
+
const side = line - reach >= 0 || line + reach > height ? 'above' : 'below'
|
|
129
|
+
const dy = (SPARK_LABEL_GAP + (fontSize + 1) / 2) * (side === 'above' ? -1 : 1)
|
|
130
|
+
return { side, dy }
|
|
131
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The sparkline's hover / focus readout: one quiet chip, never a floating tooltip, so a narrow cell
|
|
3
|
-
* cannot be escaped. It sits
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* fraction of its own width, so it is centred on a mid point and flush with the box at either end.
|
|
3
|
+
* cannot be escaped. It sits INSIDE the plot box, beside the hovered point (the roomier side, so it
|
|
4
|
+
* flips at the edges) and on the half of the box away from the point, so it covers neither the dot
|
|
5
|
+
* nor anything the host draws round the sparkline (a card's delta period, a strip's caption): a chip
|
|
6
|
+
* above the box landed on that text, and a host slot that clips took it off the page. Where it
|
|
7
|
+
* crosses the line it is opaque, so it reads over it. Placement is inline (`Sparkline.tsx`).
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
.root {
|
|
@@ -14,10 +13,8 @@
|
|
|
14
13
|
|
|
15
14
|
.readout {
|
|
16
15
|
position: absolute;
|
|
17
|
-
/* The layer is inset from the root by the line's plot margin; lifting by it puts the chip back
|
|
18
|
-
* on the root's top edge, the line a host slot reserves. */
|
|
19
|
-
bottom: calc(100% + var(--basalt-spark-lift, 0px));
|
|
20
16
|
z-index: 1;
|
|
17
|
+
max-height: 100%;
|
|
21
18
|
max-width: 100%;
|
|
22
19
|
box-sizing: border-box;
|
|
23
20
|
padding: 0 4px;
|
|
@@ -25,8 +22,8 @@
|
|
|
25
22
|
font-family: var(--basalt-font-numeral, var(--basalt-font-sans));
|
|
26
23
|
font-variant-numeric: lining-nums;
|
|
27
24
|
font-size: var(--vx-text-xs);
|
|
28
|
-
/* The
|
|
29
|
-
* value (`stat-card.module.css`, `stat-strip.module.css`)
|
|
25
|
+
/* The chip's height: hosts that reserve a line for it set `--basalt-spark-readout-h` to the same
|
|
26
|
+
* value (`stat-card.module.css`, `stat-strip.module.css`). */
|
|
30
27
|
block-size: var(--basalt-spark-readout-h, 1.125rem);
|
|
31
28
|
line-height: calc(var(--basalt-spark-readout-h, 1.125rem) - 2px);
|
|
32
29
|
color: var(--vx-tooltip-text);
|
package/src/charts/state.tsx
CHANGED
|
@@ -53,6 +53,8 @@ const dotStyle: CSSProperties = {
|
|
|
53
53
|
const errorStyle: CSSProperties = {
|
|
54
54
|
...boxStyle,
|
|
55
55
|
alignItems: 'flex-start',
|
|
56
|
+
justifyContent: 'flex-start',
|
|
57
|
+
paddingBottom: VX.space.controlGap,
|
|
56
58
|
textAlign: 'start',
|
|
57
59
|
fontSize: VX.text.sm,
|
|
58
60
|
gap: VX.space.controlGap,
|
|
@@ -68,7 +70,7 @@ const errorHeadStyle: CSSProperties = {
|
|
|
68
70
|
const errorMessageStyle: CSSProperties = { color: VX.muted }
|
|
69
71
|
|
|
70
72
|
const emptyLabel = (state: ChartState | undefined): string =>
|
|
71
|
-
typeof state?.empty === 'string' ? state.empty : '
|
|
73
|
+
typeof state?.empty === 'string' ? state.empty : 'Nothing recorded in this range.'
|
|
72
74
|
|
|
73
75
|
/** Fills the same {@link ChartBox} the chart will, so a pending, failed or empty chart (and a
|
|
74
76
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
@@ -90,8 +92,9 @@ export function ChartPlaceholder(props: {
|
|
|
90
92
|
const kind = resolveChartState(props.state)
|
|
91
93
|
if (kind === null) return null
|
|
92
94
|
const style = kind === 'pending' ? pendingStyle : kind === 'error' ? errorStyle : boxStyle
|
|
93
|
-
// An error
|
|
94
|
-
//
|
|
95
|
+
// An error keeps the chart's height as a floor (the frame does not jump, `ssr-contract`) and may
|
|
96
|
+
// grow past it rather than clip its action; its anatomy is top-aligned, so the room is plain
|
|
97
|
+
// card below the content, not a block of text floating mid-card.
|
|
95
98
|
const fit = (node: ReactElement): ReactElement => (
|
|
96
99
|
<ChartBox height={props.height} {...(kind === 'error' && { className: growClass })}>
|
|
97
100
|
{node}
|
package/src/charts/types.ts
CHANGED
|
@@ -199,8 +199,9 @@ export type ChartTooltipRow = {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export type ChartTooltipConfig<T, X extends ChartX = ChartX> = {
|
|
202
|
-
/** The tooltip title. Default:
|
|
203
|
-
* `
|
|
202
|
+
/** The tooltip title. Default: a Date x reads weekday, day, month and year in the page locale
|
|
203
|
+
* (`Tue 1 Sep 2026`; a non-day instant adds its time) whatever `formatX` shortens the ticks to;
|
|
204
|
+
* any other x goes through `formatX`. */
|
|
204
205
|
formatHeader?: ((x: X, d: T) => string) | undefined
|
|
205
206
|
/** Rows after the per-series rows (a total, a zone badge, a context line). `visible`/`hidden` are
|
|
206
207
|
* the legend's split, so a row never names a series the plot no longer draws. */
|
|
@@ -320,7 +321,7 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
320
321
|
xDomain?: readonly [X, X] | undefined
|
|
321
322
|
/**
|
|
322
323
|
* Tick label for an x value. Default: compact numbers, strings verbatim, and dates by tick step
|
|
323
|
-
* (`HH:MM` with the day on midnight, `
|
|
324
|
+
* (`HH:MM` with the day on midnight, the day (`4 Oct`, in the page locale), a month with the year on January; a label recurs
|
|
324
325
|
* only behind a day or year label).
|
|
325
326
|
*/
|
|
326
327
|
formatX?: ((x: X) => string) | undefined
|
package/src/cli/shot/capture.ts
CHANGED
|
@@ -64,6 +64,8 @@ export type CaptureInput = {
|
|
|
64
64
|
type PageFacts = {
|
|
65
65
|
anchors: string[]
|
|
66
66
|
declared: string[]
|
|
67
|
+
/** Anchors that hold a basalt state surface (ChartCard, StatCard, a chart state). */
|
|
68
|
+
stateful?: string[]
|
|
67
69
|
/** Anchor → the URL states it declares itself absent in (`data-shot-absent="empty error"`). */
|
|
68
70
|
absent?: Record<string, string[]>
|
|
69
71
|
}
|
|
@@ -94,6 +96,7 @@ type Outcome = {
|
|
|
94
96
|
status: ShotRecord['status']
|
|
95
97
|
file?: string
|
|
96
98
|
note?: string
|
|
99
|
+
stateful?: true
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
/** Thrown inside a capture when the anchor simply has no such target: recorded `not-declared`, not `error`. */
|
|
@@ -167,7 +170,7 @@ const snap = (
|
|
|
167
170
|
...extra,
|
|
168
171
|
})
|
|
169
172
|
|
|
170
|
-
function record(c: Ctx, { name, state, status, file, note }: Outcome): void {
|
|
173
|
+
function record(c: Ctx, { name, state, status, file, note, stateful }: Outcome): void {
|
|
171
174
|
const { route, scheme, viewport } = c
|
|
172
175
|
c.shots.push({
|
|
173
176
|
route,
|
|
@@ -178,6 +181,7 @@ function record(c: Ctx, { name, state, status, file, note }: Outcome): void {
|
|
|
178
181
|
file: file ?? null,
|
|
179
182
|
status,
|
|
180
183
|
...(note ? { note } : {}),
|
|
184
|
+
...(stateful ? { stateful } : {}),
|
|
181
185
|
})
|
|
182
186
|
if (status === 'error')
|
|
183
187
|
c.input.log(`[shot] ${route} ${name} ${scheme}/${viewport}/${state}: ${note}`)
|
|
@@ -199,12 +203,17 @@ export function tagAutoAnchors(): void {
|
|
|
199
203
|
})
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
/** The DOM marks of a basalt state surface: `ChartCard` and the chart state write theirs; `StatCard` has none but its `basalt-card` container. */
|
|
207
|
+
const STATE_SURFACE =
|
|
208
|
+
'[data-basalt-chart-card], [data-basalt-chart-state], [style*="container-name: basalt-card"]'
|
|
209
|
+
|
|
202
210
|
const readFacts = (page: PwPage): Promise<PageFacts> =>
|
|
203
|
-
page.evaluate(`(() => ({
|
|
211
|
+
page.evaluate(`(() => { const STATE_SURFACE = ${JSON.stringify(STATE_SURFACE)}; return {
|
|
204
212
|
anchors: [...new Set([...document.querySelectorAll('[data-shot]')].map((e) => e.getAttribute('data-shot')).filter(Boolean))],
|
|
205
213
|
declared: [...document.querySelectorAll('[data-shot-states]')].flatMap((e) => (e.getAttribute('data-shot-states') ?? '').split(/\\s+/)).filter(Boolean),
|
|
214
|
+
stateful: [...new Set([...document.querySelectorAll('[data-shot]')].filter((e) => e.matches(STATE_SURFACE) || e.querySelector(STATE_SURFACE)).map((e) => e.getAttribute('data-shot')).filter(Boolean))],
|
|
206
215
|
absent: Object.fromEntries([...document.querySelectorAll('[data-shot][data-shot-absent]')].map((e) => [e.getAttribute('data-shot'), (e.getAttribute('data-shot-absent') ?? '').split(/\\s+/).filter(Boolean)])),
|
|
207
|
-
})
|
|
216
|
+
}; })()`)
|
|
208
217
|
|
|
209
218
|
const addProblem = (c: Ctx, problem: string): void => {
|
|
210
219
|
if (!c.problems.includes(problem)) c.problems.push(problem)
|
|
@@ -679,6 +688,9 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
|
|
|
679
688
|
state,
|
|
680
689
|
status: 'not-declared',
|
|
681
690
|
note: c.facts.declared.length === 0 ? NO_STATES_NOTE : 'page does not declare this state',
|
|
691
|
+
...(c.facts.declared.length === 0 && c.facts.stateful?.includes(name)
|
|
692
|
+
? { stateful: true as const }
|
|
693
|
+
: {}),
|
|
682
694
|
})
|
|
683
695
|
}
|
|
684
696
|
return
|
package/src/cli/shot/detect.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* |-|-|-|
|
|
10
10
|
* | scan/shot-error | content | P0 |
|
|
11
11
|
* | scan/no-anchors | content | P0 |
|
|
12
|
-
* | craft-7/no-declared-states | content |
|
|
12
|
+
* | craft-7/no-declared-states | content | P2 (only when an anchor renders a state surface) |
|
|
13
13
|
* | craft-5/contrast | content | P0 |
|
|
14
14
|
* | craft-5/assumed-backdrop | content | P2 |
|
|
15
15
|
* | craft-1/scale-error, -missing| layout | P1 |
|
|
@@ -291,20 +291,20 @@ export function detectFindings(m: ShotMetrics, lint?: LintReport): Finding[] {
|
|
|
291
291
|
defect: `The shot failed${s.note ? `: ${s.note}` : ''}.`,
|
|
292
292
|
})
|
|
293
293
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
const stateful = new Map<string, Set<string>>()
|
|
295
|
+
for (const s of m.shots) {
|
|
296
|
+
if (s.status !== 'not-declared' || s.note !== NO_STATES_NOTE || !s.stateful) continue
|
|
297
|
+
stateful.set(s.route, (stateful.get(s.route) ?? new Set()).add(s.name))
|
|
298
|
+
}
|
|
299
|
+
for (const [route, names] of stateful) {
|
|
299
300
|
drafts.push({
|
|
300
301
|
...scan,
|
|
301
302
|
rule: 'craft-7/no-declared-states',
|
|
302
|
-
severity: '
|
|
303
|
+
severity: 'P2',
|
|
303
304
|
anchor: '—',
|
|
304
305
|
route,
|
|
305
306
|
cite: `metrics.json shots[${route} not-declared]`,
|
|
306
|
-
defect:
|
|
307
|
-
'No anchor declares data-shot-states, so empty, loading and error were never rendered or scored: declare them with data-shot-states.',
|
|
307
|
+
defect: `${[...names].join(', ')} render${names.size === 1 ? 's' : ''} a state surface but no anchor declares data-shot-states, so empty, loading and error were never scored: add data-shot-states="empty loading error" to ${names.size === 1 ? 'it' : 'each'}.`,
|
|
308
308
|
})
|
|
309
309
|
}
|
|
310
310
|
if (m.scaleError || m.scale.length === 0) {
|
|
@@ -13,6 +13,16 @@ export const INSTALL_LINE =
|
|
|
13
13
|
|
|
14
14
|
const KILL_TIMEOUT_MS = 10_000
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A headless Chromium with no pointing device reports `(hover: none) (pointer: coarse)`, so no
|
|
18
|
+
* `@media (hover: hover)` rule applies in a desktop hover shot. These blink settings make the
|
|
19
|
+
* browser's primary input a mouse (hover 2, fine 4); a `hasTouch` mobile context still emulates
|
|
20
|
+
* touch over them.
|
|
21
|
+
*/
|
|
22
|
+
export const POINTER_ARGS = [
|
|
23
|
+
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4',
|
|
24
|
+
]
|
|
25
|
+
|
|
16
26
|
export type Box = { x: number; y: number; width: number; height: number }
|
|
17
27
|
|
|
18
28
|
export type ShotOptions = {
|
|
@@ -69,7 +79,11 @@ export type PwBrowser<C extends PwContext = PwContext> = {
|
|
|
69
79
|
type PwServer = { wsEndpoint(): string; kill(): Promise<void> }
|
|
70
80
|
export type Playwright<B extends PwBrowser = PwBrowser> = {
|
|
71
81
|
chromium: {
|
|
72
|
-
launchServer(options: {
|
|
82
|
+
launchServer(options: {
|
|
83
|
+
channel?: string
|
|
84
|
+
chromiumSandbox: boolean
|
|
85
|
+
args: string[]
|
|
86
|
+
}): Promise<PwServer>
|
|
73
87
|
connect(wsEndpoint: string): Promise<B>
|
|
74
88
|
}
|
|
75
89
|
}
|
|
@@ -132,7 +146,9 @@ export async function withBrowser<B extends PwBrowser, T>(
|
|
|
132
146
|
let browser: B
|
|
133
147
|
try {
|
|
134
148
|
server = await pw.chromium.launchServer(
|
|
135
|
-
channel
|
|
149
|
+
channel
|
|
150
|
+
? { channel, chromiumSandbox, args: POINTER_ARGS }
|
|
151
|
+
: { chromiumSandbox, args: POINTER_ARGS },
|
|
136
152
|
)
|
|
137
153
|
browser = await pw.chromium.connect(server.wsEndpoint())
|
|
138
154
|
} catch (error) {
|