basalt-ui 2.26.0 → 2.27.1
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 +34 -0
- package/MIGRATING.md +91 -12
- package/dist/charts/Bars.d.ts.map +1 -1
- package/dist/charts/Bars.js +37 -1
- package/dist/charts/ChartCard.d.ts +8 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +2 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +76 -15
- package/dist/charts/chart-box.module.css +78 -1
- package/dist/charts/chart-box.module.css.d.ts +1 -0
- package/dist/charts/chart-legend.module.css +0 -14
- package/dist/charts/compile.d.ts +20 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +85 -12
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +37 -87
- package/dist/charts/sparkline.module.css +4 -0
- package/dist/charts/state.d.ts +7 -0
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +14 -3
- package/dist/cli/shot/capture.d.ts +32 -3
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +17 -7
- package/dist/dashboard/meter-model.d.ts +17 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +69 -19
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +28 -12
- package/dist/dashboard/meter.module.css +17 -1
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +90 -22
- package/dist/dashboard/stat-strip.module.css +13 -3
- package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/src/charts/Bars.tsx +50 -2
- package/src/charts/ChartCard.tsx +9 -1
- package/src/charts/Sparkline.tsx +113 -20
- package/src/charts/chart-box.module.css +78 -1
- package/src/charts/chart-box.module.css.d.ts +1 -0
- package/src/charts/chart-legend.module.css +0 -14
- package/src/charts/compile.ts +140 -18
- package/src/charts/legend.tsx +10 -74
- package/src/charts/sparkline.module.css +4 -0
- package/src/charts/state.tsx +30 -5
- package/src/cli/shot/capture.ts +25 -9
- package/src/dashboard/meter-model.ts +122 -31
- package/src/dashboard/meter-parts.tsx +53 -19
- package/src/dashboard/meter.module.css +17 -1
- package/src/dashboard/stat-strip.module.css +13 -3
- package/src/dashboard/stat-strip.module.css.d.ts +1 -0
- package/src/dashboard/stat-strip.tsx +114 -26
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@container (min-width: 240px) {
|
|
18
|
-
/* `foldLegend` (legend.tsx) folds the zones / references that wrap the row into `+N`; series never fold. */
|
|
19
18
|
.auto {
|
|
20
|
-
--bc-fold: 1;
|
|
21
19
|
flex-wrap: wrap;
|
|
22
20
|
display: flex;
|
|
23
21
|
column-gap: var(--bc-dots-gap);
|
|
@@ -27,7 +25,6 @@
|
|
|
27
25
|
|
|
28
26
|
@container (min-width: 480px) {
|
|
29
27
|
.auto {
|
|
30
|
-
--bc-fold: 0;
|
|
31
28
|
column-gap: var(--bc-legend-gap);
|
|
32
29
|
--vx-hit-gap: var(--bc-legend-gap);
|
|
33
30
|
}
|
|
@@ -47,14 +44,3 @@
|
|
|
47
44
|
display: none;
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
/* The compact fold (`foldLegend`, which only folds while `--bc-fold` is 1); wide keeps every entry.
|
|
52
|
-
* `!important`: an entry's inline `all: unset` (legend.tsx) would otherwise reset `display`. */
|
|
53
|
-
.auto [data-legend-folded] {
|
|
54
|
-
display: none !important;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.auto [data-legend-more] {
|
|
58
|
-
order: 1;
|
|
59
|
-
flex: none;
|
|
60
|
-
}
|
package/dist/charts/compile.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChartTooltipPortalPositionContext } from '@tanstack/charts/tooltip/portal';
|
|
1
2
|
import type { ChartGradient, ChartPositionScaleOptions, ChartTooltipRow as EngineTooltipRow, ChartValue, ResponsiveChartDefinition } from '@tanstack/charts/types/core';
|
|
2
3
|
import type { ContainerClass } from '../tokens/size-classes.js';
|
|
3
4
|
import type { PlotSizes } from './plot-context.js';
|
|
@@ -121,6 +122,25 @@ export declare function zoneAreaGradient(index: number, zones: readonly ZoneSpec
|
|
|
121
122
|
* a clock time (a bucket keyed by local midnight is `22:00` UTC in a UTC+2 zone).
|
|
122
123
|
*/
|
|
123
124
|
export declare function dayGranular(values: readonly ChartX[]): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The engine places a portalled tooltip against the viewport, so it opens past the card's edge, over
|
|
127
|
+
* the neighbouring card or the section heading above. Its placements (a hover, and its own resize /
|
|
128
|
+
* scroll repositions, which never pass through `position`) all write the element's inline `left` and
|
|
129
|
+
* `top`, so each write is followed by a settle inside the card (`settleInCard`).
|
|
130
|
+
*/
|
|
131
|
+
/** What a card clamp does: `card` a chart tooltip (both axes, the card's width), `slot` a slotted
|
|
132
|
+
* `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways only, as before Wave 39). */
|
|
133
|
+
type TipMode = 'card' | 'slot' | 'strip';
|
|
134
|
+
/**
|
|
135
|
+
* Keeps a tooltip inside its card on both axes. A card with room lets the tooltip grow up to its
|
|
136
|
+
* width before a label wraps, and re-centres it on the anchor at that width. A tooltip that would
|
|
137
|
+
* cross the card's top or bottom flips to the other side of its anchor when that side fits; neither
|
|
138
|
+
* fitting, it slides in; taller than the card, it aligns to the card's top (the only overflow).
|
|
139
|
+
* A `slot` tooltip (a slotted `Bars`, one line) keeps its place above the plot, centred on the
|
|
140
|
+
* anchor, capped at the card's width and held inside the card sideways and at its top. A hidden or unmeasured tooltip is left alone, and an unchanged position
|
|
141
|
+
* is not written back (a write re-runs this).
|
|
142
|
+
*/
|
|
143
|
+
export declare function settleInCard(tip: HTMLElement, within: Element, ctx: ChartTooltipPortalPositionContext, mode?: TipMode): void;
|
|
124
144
|
export declare function compileCartesian<T, X extends ChartX>(input: CartesianInput<T, X>): CartesianDefinition;
|
|
125
145
|
export {};
|
|
126
146
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/charts/compile.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,iCAAiC,EAClC,MAAM,iCAAiC,CAAA;AACxC,OAAO,KAAK,EAGV,aAAa,EAEb,yBAAyB,EACzB,eAAe,IAAI,gBAAgB,EACnC,UAAU,EACV,yBAAyB,EAE1B,MAAM,6BAA6B,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAO5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,WAAW,EACX,eAAe,EACf,MAAM,EAEN,OAAO,EAEP,QAAQ,EACT,MAAM,SAAS,CAAA;AAEhB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AAE/F,gGAAgG;AAChG,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,IAAI,CACpD,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,MAAM,GACN,GAAG,GACH,QAAQ,GACR,OAAO,GACP,GAAG,GACH,IAAI,GACJ,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,QAAQ,GACR,UA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AAS,MAAM,EAAE,GAAG,OAAO,CAO9D;AAkID;;;;;GAKG;AACH;qGACqG;AACrG,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AA2BxC;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,iCAAiC,EACtC,IAAI,GAAE,OAAgB,GACrB,IAAI,CA4EN;AA0ED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAClD,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1B,mBAAmB,CA2HrB"}
|
package/dist/charts/compile.js
CHANGED
|
@@ -602,6 +602,12 @@ const stripAnchor = (points, { plot }) => {
|
|
|
602
602
|
};
|
|
603
603
|
const STRIP_TOOLTIP_PLACEMENT = ["bottom", "top"];
|
|
604
604
|
const STRIP_TOOLTIP_OFFSET = 8;
|
|
605
|
+
const slotAnchor = (points, { plot }) => {
|
|
606
|
+
const xs = points.map((p) => p.x);
|
|
607
|
+
return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y };
|
|
608
|
+
};
|
|
609
|
+
const SLOT_TOOLTIP_PLACEMENT = ["top"];
|
|
610
|
+
const SLOT_RING_CLEARANCE = 2 + 2;
|
|
605
611
|
const TIP_CHROME = 30;
|
|
606
612
|
const TIP_ROW = 18;
|
|
607
613
|
const TIP_TOP_AIR = 4;
|
|
@@ -620,42 +626,108 @@ const barAnchor = (rows) => (points, { plot }) => {
|
|
|
620
626
|
};
|
|
621
627
|
const TIP_CARD = "[data-basalt-chart-card], [data-strip-cell], .mantine-Card-root";
|
|
622
628
|
const TIP_CARD_AIR = 4;
|
|
623
|
-
const
|
|
629
|
+
const TIP_CARD_ROOMY = 192;
|
|
630
|
+
const cardPortal = (mode) => ({
|
|
624
631
|
id: portal.id,
|
|
625
632
|
create(context, options) {
|
|
626
633
|
const inner = portal.create(context, options);
|
|
627
634
|
const { element, container } = context;
|
|
628
|
-
|
|
635
|
+
if (mode === "slot") element.dataset["basaltSlot"] = "";
|
|
636
|
+
let last;
|
|
637
|
+
const watch = new MutationObserver(() => {
|
|
638
|
+
if (last) settleInCard(element, container, last, mode);
|
|
639
|
+
});
|
|
629
640
|
watch.observe(element, { attributes: true, attributeFilter: ["style"] });
|
|
630
641
|
return {
|
|
631
642
|
...inner,
|
|
643
|
+
position(next) {
|
|
644
|
+
last = next;
|
|
645
|
+
return inner.position(next);
|
|
646
|
+
},
|
|
632
647
|
destroy() {
|
|
633
648
|
watch.disconnect();
|
|
634
649
|
inner.destroy();
|
|
635
650
|
}
|
|
636
651
|
};
|
|
637
652
|
}
|
|
638
|
-
};
|
|
639
|
-
function
|
|
653
|
+
});
|
|
654
|
+
function settleInCard(tip, within, ctx, mode = "card") {
|
|
655
|
+
const slot = mode === "slot";
|
|
656
|
+
if (tip.hidden || tip.offsetHeight === 0) return;
|
|
640
657
|
const card = within.closest(TIP_CARD)?.getBoundingClientRect();
|
|
641
|
-
const
|
|
642
|
-
const width =
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
if (
|
|
658
|
+
const surface = ctx.surface.element.getBoundingClientRect();
|
|
659
|
+
const { width: sceneW, height: sceneH } = ctx.scene;
|
|
660
|
+
let left = Number.parseFloat(tip.style.left);
|
|
661
|
+
let top = Number.parseFloat(tip.style.top);
|
|
662
|
+
if (!card || Number.isNaN(left) || Number.isNaN(top) || !surface.width || !sceneW || !sceneH)
|
|
663
|
+
return;
|
|
664
|
+
const w0 = tip.offsetWidth;
|
|
665
|
+
const toClient = (p) => ({
|
|
666
|
+
x: surface.left + p.x / sceneW * surface.width,
|
|
667
|
+
y: surface.top + p.y / sceneH * surface.height
|
|
668
|
+
});
|
|
669
|
+
if (mode === "strip") {
|
|
670
|
+
if (w0 + 2 * TIP_CARD_AIR <= card.width)
|
|
671
|
+
left = Math.min(Math.max(left, card.left + TIP_CARD_AIR), card.right - w0 - TIP_CARD_AIR);
|
|
672
|
+
if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`;
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const roomy = card.width >= TIP_CARD_ROOMY;
|
|
676
|
+
const grown = roomy || slot;
|
|
677
|
+
if (!grown) {
|
|
678
|
+
if (tip.dataset["basaltMax"] !== void 0) {
|
|
679
|
+
tip.style.maxWidth = tip.dataset["basaltMax"];
|
|
680
|
+
tip.style.removeProperty("width");
|
|
681
|
+
delete tip.dataset["basaltMax"];
|
|
682
|
+
}
|
|
683
|
+
} else {
|
|
684
|
+
tip.dataset["basaltMax"] ??= tip.style.maxWidth;
|
|
685
|
+
const cap = `${card.width - 2 * TIP_CARD_AIR}px`;
|
|
686
|
+
if (tip.style.maxWidth !== cap) tip.style.maxWidth = cap;
|
|
687
|
+
if (tip.style.width !== "max-content") tip.style.width = "max-content";
|
|
688
|
+
}
|
|
689
|
+
const [w, h] = [tip.offsetWidth, tip.offsetHeight];
|
|
690
|
+
const anchor = toClient(ctx.anchor);
|
|
691
|
+
const gap = Math.max(0, Number.isFinite(ctx.offset) ? ctx.offset ?? 10 : 10);
|
|
692
|
+
const maxTop = card.bottom - TIP_CARD_AIR - h;
|
|
693
|
+
const headerBottom = slot ? void 0 : within.closest(TIP_CARD)?.querySelector("[data-basalt-facts]")?.parentElement?.getBoundingClientRect().bottom;
|
|
694
|
+
const belowHeader = headerBottom === void 0 ? void 0 : headerBottom + TIP_CARD_AIR;
|
|
695
|
+
const minTop = belowHeader !== void 0 && belowHeader <= maxTop ? belowHeader : card.top + TIP_CARD_AIR;
|
|
696
|
+
const side = tip.dataset["placement"];
|
|
697
|
+
if (slot) {
|
|
698
|
+
top = Math.max(anchor.y - gap - SLOT_RING_CLEARANCE - h, card.top);
|
|
699
|
+
left = anchor.x - w / 2;
|
|
700
|
+
} else if (side === "top" || side === "bottom") {
|
|
701
|
+
const above = anchor.y - gap - h;
|
|
702
|
+
const below = anchor.y + gap;
|
|
703
|
+
const order = side === "top" ? [above, below] : [below, above];
|
|
704
|
+
const fits = order.findIndex((t) => t >= minTop && t <= maxTop);
|
|
705
|
+
top = order[Math.max(fits, 0)] ?? top;
|
|
706
|
+
if (fits > 0) tip.dataset["placement"] = side === "top" ? "bottom" : "top";
|
|
707
|
+
if (roomy) left = anchor.x - w / 2;
|
|
708
|
+
}
|
|
709
|
+
if (!slot) top = maxTop < minTop ? minTop : Math.min(Math.max(top, minTop), maxTop);
|
|
710
|
+
if (grown || w + 2 * TIP_CARD_AIR <= card.width)
|
|
711
|
+
left = Math.min(
|
|
712
|
+
Math.max(left, card.left + TIP_CARD_AIR),
|
|
713
|
+
Math.max(card.right - w - TIP_CARD_AIR, card.left + TIP_CARD_AIR)
|
|
714
|
+
);
|
|
715
|
+
if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`;
|
|
716
|
+
if (Math.abs(top - Number.parseFloat(tip.style.top)) > 0.5) tip.style.top = `${top}px`;
|
|
646
717
|
}
|
|
647
718
|
function tooltipSpec(opts) {
|
|
648
719
|
const { input, axes, visible, keys, visibleKeys, formatX, dayOnly } = opts;
|
|
649
720
|
const hidden = input.series.filter((s) => !visibleKeys.has(s.key));
|
|
721
|
+
const slot = input.tooltipBelow === true && input.bare === true;
|
|
650
722
|
const rowSeries = (input.reverseRows ? visible.toReversed() : visible).filter(
|
|
651
723
|
(s) => s.tooltip !== false
|
|
652
724
|
);
|
|
653
725
|
return {
|
|
654
726
|
use: quietWhileFollowing,
|
|
655
727
|
...followerOptions(input.tooltip, input.cursorGroup, input.chartId),
|
|
656
|
-
portal: cardPortal,
|
|
657
|
-
anchor: input.tooltipBelow ? stripAnchor : visible.some((s) => s.mark === "bar") ? barAnchor(rowSeries.length) : "group-center",
|
|
658
|
-
...input.tooltipBelow && { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET },
|
|
728
|
+
portal: cardPortal(slot ? "slot" : input.tooltipBelow === true ? "strip" : "card"),
|
|
729
|
+
anchor: input.tooltipBelow ? slot ? slotAnchor : stripAnchor : visible.some((s) => s.mark === "bar") ? barAnchor(rowSeries.length) : "group-center",
|
|
730
|
+
...input.tooltipBelow && (slot ? { placement: SLOT_TOOLTIP_PLACEMENT, offset: 0 } : { placement: STRIP_TOOLTIP_PLACEMENT, offset: STRIP_TOOLTIP_OFFSET }),
|
|
659
731
|
content: (points) => {
|
|
660
732
|
const primary = points[0];
|
|
661
733
|
if (!primary) return { rows: [] };
|
|
@@ -810,6 +882,7 @@ export {
|
|
|
810
882
|
engineRow,
|
|
811
883
|
refLegendSeries,
|
|
812
884
|
seriesRow,
|
|
885
|
+
settleInCard,
|
|
813
886
|
strideTicks,
|
|
814
887
|
utcHeaderDate,
|
|
815
888
|
visibleSeries,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/charts/legend.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAA;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAelD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,CAAC,EAC7B,MAAM,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,EACjC,MAAM,EAAE,OAAO,GACd,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAOpB;AA+DD;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAWrF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CAGd,CAAA;AAuDV,MAAM,MAAM,gBAAgB,CAAC,CA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AM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACzC,kGAAkG;IAClG,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAcD,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAsF9E"}
|
package/dist/charts/legend.js
CHANGED
|
@@ -122,73 +122,26 @@ function Swatch({ s, mode }) {
|
|
|
122
122
|
}
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
position: "absolute",
|
|
127
|
-
width: "1px",
|
|
128
|
-
height: "1px",
|
|
129
|
-
overflow: "hidden",
|
|
130
|
-
clipPath: "inset(50%)",
|
|
131
|
-
whiteSpace: "nowrap"
|
|
132
|
-
};
|
|
133
|
-
function lineCount(row, more) {
|
|
134
|
-
const shown = [...row.querySelectorAll("[data-legend-key]")].filter(
|
|
135
|
-
(it) => !it.hasAttribute("data-legend-folded")
|
|
136
|
-
);
|
|
137
|
-
if (!more.hidden) shown.push(more);
|
|
138
|
-
const centres = shown.map((it) => {
|
|
139
|
-
const r = it.getBoundingClientRect();
|
|
140
|
-
return r.top + r.height / 2;
|
|
141
|
-
}).toSorted((x, y) => x - y);
|
|
142
|
-
return centres.filter((c, i) => i === 0 || c - (centres[i - 1] ?? c) > 6).length;
|
|
143
|
-
}
|
|
144
|
-
function foldLegend(row) {
|
|
145
|
-
const items = [...row.querySelectorAll("[data-legend-key]")];
|
|
146
|
-
const more = row.querySelector("[data-legend-more]");
|
|
147
|
-
for (const it of items) it.removeAttribute("data-legend-folded");
|
|
148
|
-
more?.setAttribute("hidden", "");
|
|
125
|
+
function titleClipped(row) {
|
|
149
126
|
for (const label of row.querySelectorAll("[data-legend-label]")) {
|
|
150
127
|
if (label.scrollWidth > label.clientWidth + 0.5) label.title = label.textContent ?? "";
|
|
151
128
|
else label.removeAttribute("title");
|
|
152
129
|
}
|
|
153
|
-
if (more === null || getComputedStyle(row).getPropertyValue("--bc-fold").trim() !== "1") return;
|
|
154
|
-
const references = items.filter((it) => it.dataset["legendRole"] === "reference");
|
|
155
|
-
for (const r of references) r.setAttribute("data-legend-folded", "");
|
|
156
|
-
const floor = lineCount(row, more);
|
|
157
|
-
for (const r of references) r.removeAttribute("data-legend-folded");
|
|
158
|
-
const folded = [];
|
|
159
|
-
while (folded.length < references.length && lineCount(row, more) > floor) {
|
|
160
|
-
const last = references[references.length - 1 - folded.length];
|
|
161
|
-
if (last === void 0) break;
|
|
162
|
-
last.setAttribute("data-legend-folded", "");
|
|
163
|
-
folded.push(last);
|
|
164
|
-
more.removeAttribute("hidden");
|
|
165
|
-
const names = folded.map((f) => f.textContent).join(", ");
|
|
166
|
-
more.textContent = `+${folded.length}`;
|
|
167
|
-
more.title = names;
|
|
168
|
-
const hiddenNames = document.createElement("span");
|
|
169
|
-
hiddenNames.textContent = `: ${names}`;
|
|
170
|
-
Object.assign(hiddenNames.style, VISUALLY_HIDDEN);
|
|
171
|
-
more.append(hiddenNames);
|
|
172
|
-
}
|
|
173
|
-
if (folded.length > 0 && lineCount(row, more) > floor) {
|
|
174
|
-
for (const f of folded) f.removeAttribute("data-legend-folded");
|
|
175
|
-
more.setAttribute("hidden", "");
|
|
176
|
-
}
|
|
177
130
|
}
|
|
178
131
|
function ChartLegend(props) {
|
|
179
132
|
const rowRef = useRef(null);
|
|
180
133
|
const auto = props.mode === "auto";
|
|
181
134
|
const signature = props.series.map((s) => s.key).join("|");
|
|
182
135
|
useLayoutEffect(() => {
|
|
183
|
-
if (auto && rowRef.current !== null)
|
|
136
|
+
if (auto && rowRef.current !== null) titleClipped(rowRef.current);
|
|
184
137
|
}, [auto, signature]);
|
|
185
138
|
useEffect(() => {
|
|
186
139
|
const row = rowRef.current;
|
|
187
140
|
if (!auto || row === null || typeof ResizeObserver === "undefined") return;
|
|
188
|
-
const observer = new ResizeObserver(() =>
|
|
141
|
+
const observer = new ResizeObserver(() => titleClipped(row));
|
|
189
142
|
observer.observe(row);
|
|
190
143
|
let live = true;
|
|
191
|
-
void document.fonts?.ready?.then(() => live &&
|
|
144
|
+
void document.fonts?.ready?.then(() => live && titleClipped(row));
|
|
192
145
|
return () => {
|
|
193
146
|
live = false;
|
|
194
147
|
observer.disconnect();
|
|
@@ -196,7 +149,7 @@ function ChartLegend(props) {
|
|
|
196
149
|
}, [auto, signature]);
|
|
197
150
|
const groups = legendEntries(props.series, props.groups);
|
|
198
151
|
if (groups.length === 0) return null;
|
|
199
|
-
return /* @__PURE__ */
|
|
152
|
+
return /* @__PURE__ */ jsx(
|
|
200
153
|
"fieldset",
|
|
201
154
|
{
|
|
202
155
|
ref: rowRef,
|
|
@@ -206,52 +159,49 @@ function ChartLegend(props) {
|
|
|
206
159
|
...auto && { className: classes.auto },
|
|
207
160
|
...auto && props.hideAtWide && { "data-hide-wide": "" },
|
|
208
161
|
style: rowLayout(props.mode, props.concealed === true),
|
|
209
|
-
children: [
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (!props.toggle)
|
|
221
|
-
return /* @__PURE__ */ jsx(
|
|
222
|
-
"span",
|
|
223
|
-
{
|
|
224
|
-
"data-legend-key": s.key,
|
|
225
|
-
"data-legend-role": s.role ?? "series",
|
|
226
|
-
style: itemStyle,
|
|
227
|
-
onMouseEnter: () => props.onHighlight(s.key),
|
|
228
|
-
onMouseLeave: () => props.onHighlight(null),
|
|
229
|
-
children: content
|
|
230
|
-
},
|
|
231
|
-
s.key
|
|
232
|
-
);
|
|
162
|
+
children: groups.map((group, gi) => [
|
|
163
|
+
gi > 0 && /* @__PURE__ */ jsx("span", { "aria-hidden": true, style: dividerStyle }, `divider-${gi}`),
|
|
164
|
+
...group.map((s) => {
|
|
165
|
+
const off = props.hidden.has(s.key);
|
|
166
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
167
|
+
/* @__PURE__ */ jsx(Swatch, { s, mode: props.mode }),
|
|
168
|
+
/* @__PURE__ */ jsx("span", { style: labelStyle, "data-legend-label": "", children: s.label }),
|
|
169
|
+
s.note !== void 0 && /* @__PURE__ */ jsx("span", { style: noteStyle, children: s.note })
|
|
170
|
+
] });
|
|
171
|
+
const itemStyle = { ...buttonStyle, opacity: off ? 0.4 : 1 };
|
|
172
|
+
if (!props.toggle)
|
|
233
173
|
return /* @__PURE__ */ jsx(
|
|
234
|
-
"
|
|
174
|
+
"span",
|
|
235
175
|
{
|
|
236
|
-
type: "button",
|
|
237
176
|
"data-legend-key": s.key,
|
|
238
177
|
"data-legend-role": s.role ?? "series",
|
|
239
|
-
"data-basalt-hit": "",
|
|
240
|
-
"aria-pressed": !off,
|
|
241
178
|
style: itemStyle,
|
|
242
|
-
onClick: () => props.onToggle(s.key),
|
|
243
179
|
onMouseEnter: () => props.onHighlight(s.key),
|
|
244
180
|
onMouseLeave: () => props.onHighlight(null),
|
|
245
|
-
onFocus: () => props.onHighlight(s.key),
|
|
246
|
-
onBlur: () => props.onHighlight(null),
|
|
247
181
|
children: content
|
|
248
182
|
},
|
|
249
183
|
s.key
|
|
250
184
|
);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
185
|
+
return /* @__PURE__ */ jsx(
|
|
186
|
+
"button",
|
|
187
|
+
{
|
|
188
|
+
type: "button",
|
|
189
|
+
"data-legend-key": s.key,
|
|
190
|
+
"data-legend-role": s.role ?? "series",
|
|
191
|
+
"data-basalt-hit": "",
|
|
192
|
+
"aria-pressed": !off,
|
|
193
|
+
style: itemStyle,
|
|
194
|
+
onClick: () => props.onToggle(s.key),
|
|
195
|
+
onMouseEnter: () => props.onHighlight(s.key),
|
|
196
|
+
onMouseLeave: () => props.onHighlight(null),
|
|
197
|
+
onFocus: () => props.onHighlight(s.key),
|
|
198
|
+
onBlur: () => props.onHighlight(null),
|
|
199
|
+
children: content
|
|
200
|
+
},
|
|
201
|
+
s.key
|
|
202
|
+
);
|
|
203
|
+
})
|
|
204
|
+
])
|
|
255
205
|
}
|
|
256
206
|
);
|
|
257
207
|
}
|
package/dist/charts/state.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ import type { ChartBoxHeight } from './box.js';
|
|
|
7
7
|
import type { ChartState } from './types.js';
|
|
8
8
|
export type ResolvedChartState = 'pending' | 'error' | 'empty' | null;
|
|
9
9
|
export declare function resolveChartState(state: ChartState | undefined): ResolvedChartState;
|
|
10
|
+
/**
|
|
11
|
+
* The shape a pending plot draws: `'bars'` (default), `'line'` for a line or area chart, or a bar
|
|
12
|
+
* count when the loaded chart's data length is known (a 6-month chart loads 6 bars).
|
|
13
|
+
*/
|
|
14
|
+
export type PlotGhostShape = 'bars' | 'line' | number;
|
|
10
15
|
/** Fills the same {@link ChartBox} the chart will, so a pending, failed or empty chart (and a
|
|
11
16
|
* `<Suspense>` fallback built from one) occupies the final chart's height. */
|
|
12
17
|
export declare function ChartPlaceholder(props: {
|
|
@@ -25,5 +30,7 @@ export declare function ChartPlaceholder(props: {
|
|
|
25
30
|
compact?: boolean;
|
|
26
31
|
/** Error only: what failed to load, "Could not load {noun}". Default: no noun. */
|
|
27
32
|
noun?: string;
|
|
33
|
+
/** Pending only: the ghost's shape. Default `'bars'`. */
|
|
34
|
+
ghost?: PlotGhostShape;
|
|
28
35
|
}): ReactElement | null;
|
|
29
36
|
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/charts/state.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAA;AAErE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAMnF;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/charts/state.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAA;AAErE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAMnF;AAsBD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAiErD;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAA;IAC7B;0GACsG;IACtG,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAA;IACnC,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;2DACuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB,GAAG,YAAY,GAAG,IAAI,CAgEtB"}
|
package/dist/charts/state.js
CHANGED
|
@@ -27,8 +27,19 @@ const pendingStyle = {
|
|
|
27
27
|
background: `linear-gradient(90deg, transparent, ${VX.surface.subtle}, transparent)`
|
|
28
28
|
};
|
|
29
29
|
const GHOST_BARS = [38, 52, 44, 66, 58, 74, 62, 48];
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const GHOST_LINE = "0,30 12,26 25,28 38,18 50,22 62,12 75,16 88,8 100,12";
|
|
31
|
+
function PlotGhost({ shape = "bars" }) {
|
|
32
|
+
if (shape === "line")
|
|
33
|
+
return /* @__PURE__ */ jsx("div", { "aria-hidden": "true", "data-basalt-plot-ghost": "line", className: boxClasses.ghost, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 100 40", preserveAspectRatio: "none", className: boxClasses.ghostLine, children: /* @__PURE__ */ jsx("polyline", { points: GHOST_LINE, vectorEffect: "non-scaling-stroke" }) }) });
|
|
34
|
+
const count = typeof shape === "number" ? Math.max(1, Math.min(Math.floor(shape), 60)) : GHOST_BARS.length;
|
|
35
|
+
return /* @__PURE__ */ jsx("div", { "aria-hidden": "true", "data-basalt-plot-ghost": "bars", className: boxClasses.ghost, children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx(
|
|
36
|
+
"span",
|
|
37
|
+
{
|
|
38
|
+
className: boxClasses.ghostBar,
|
|
39
|
+
style: { height: `${GHOST_BARS[i % GHOST_BARS.length]}%` }
|
|
40
|
+
},
|
|
41
|
+
i
|
|
42
|
+
)) });
|
|
32
43
|
}
|
|
33
44
|
const dotStyle = {
|
|
34
45
|
display: "inline-block",
|
|
@@ -72,7 +83,7 @@ function ChartPlaceholder(props) {
|
|
|
72
83
|
);
|
|
73
84
|
if (kind === "pending")
|
|
74
85
|
return fit(
|
|
75
|
-
/* @__PURE__ */ jsx("output", { "aria-label": "Loading chart", "aria-busy": "true", className: stateClass, style, children: !props.compact && /* @__PURE__ */ jsx(PlotGhost, {}) })
|
|
86
|
+
/* @__PURE__ */ jsx("output", { "aria-label": "Loading chart", "aria-busy": "true", className: stateClass, style, children: !props.compact && /* @__PURE__ */ jsx(PlotGhost, { ...props.ghost !== void 0 && { shape: props.ghost } }) })
|
|
76
87
|
);
|
|
77
88
|
const label = kind === "error" ? toErrorMessage(props.state?.error, "The request failed.") : emptyLabel(props.state);
|
|
78
89
|
const body = props.compact ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2014" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Pair } from './real-data.js';
|
|
2
|
-
import type { Box, PwBrowser, PwContext, PwLocator } from './playwright.js';
|
|
2
|
+
import type { Box, PwBrowser, PwContext, PwLocator, PwPage } from './playwright.js';
|
|
3
3
|
import type { AnchorMetrics, Measurement, Scale, Scheme, ShotRecord, ShotState, Viewport } from './types.js';
|
|
4
4
|
export type CaptureInput = {
|
|
5
5
|
browser: PwBrowser;
|
|
@@ -19,12 +19,41 @@ export type CaptureInput = {
|
|
|
19
19
|
measure?: (anchor: PwLocator) => Promise<Measurement>;
|
|
20
20
|
log: (line: string) => void;
|
|
21
21
|
};
|
|
22
|
+
type PageFacts = {
|
|
23
|
+
anchors: string[];
|
|
24
|
+
declared: string[];
|
|
25
|
+
/** Anchors that hold a basalt state surface (ChartCard, StatCard, a chart state). */
|
|
26
|
+
stateful?: string[];
|
|
27
|
+
/** Anchor → the URL states it declares itself absent in (`data-shot-absent="empty error"`). */
|
|
28
|
+
absent?: Record<string, string[]>;
|
|
29
|
+
};
|
|
30
|
+
/** Everything one page visit shares: where the records go and what was already measured. */
|
|
31
|
+
type Ctx = {
|
|
32
|
+
page: PwPage;
|
|
33
|
+
input: CaptureInput;
|
|
34
|
+
route: string;
|
|
35
|
+
scheme: Scheme;
|
|
36
|
+
viewport: Viewport;
|
|
37
|
+
/** The viewport's current height: a tall anchor grows it for one shot. */
|
|
38
|
+
height: number;
|
|
39
|
+
facts: PageFacts;
|
|
40
|
+
anchors: AnchorMetrics[];
|
|
41
|
+
shots: ShotRecord[];
|
|
42
|
+
measured: Set<string>;
|
|
43
|
+
/** What the last visit showed to be wrong about the data itself: a failed seed, a 401/403, no API answer. */
|
|
44
|
+
problems: string[];
|
|
45
|
+
/** Read on the first page of a context that loads. */
|
|
46
|
+
scale?: Steps | undefined;
|
|
47
|
+
scaleError?: string | undefined;
|
|
48
|
+
};
|
|
22
49
|
/** `<route>-<hash>__<name>-<hash>__…`: the hash of the RAW text keeps `/a/b` and `/a-b` apart. */
|
|
23
50
|
export declare const fileName: (route: string, name: string, scheme: Scheme, viewport: Viewport, state: ShotState) => string;
|
|
24
51
|
/** The state URL: the query goes before any `#fragment`. */
|
|
25
52
|
export declare function withParam(route: string, state: ShotState): string;
|
|
26
|
-
/** The rect union of `boxes`, grown by `margin` and clamped to the viewport (`tall`: its current height). */
|
|
27
|
-
export declare function unionClip(boxes: readonly Box[], margin: number, viewport: Viewport, tall?: number): Box;
|
|
53
|
+
/** The rect union of `boxes`, grown by `margin` and clamped to the viewport (`tall`: its current height); null when nothing of it is inside. */
|
|
54
|
+
export declare function unionClip(boxes: readonly Box[], margin: number, viewport: Viewport, tall?: number): Box | null;
|
|
55
|
+
/** A clip of `targets` re-measured against the live page height (`c.height` goes stale after a reflow); an empty clip is retried once after a frame, then fails. */
|
|
56
|
+
export declare function snapClip(c: Ctx, path: string, targets: readonly PwLocator[]): Promise<void>;
|
|
28
57
|
/** Runs in the page: numbers every Card, Paper and table in DOM order, tagging those over 120×60 px as anchors. */
|
|
29
58
|
export declare function tagAutoAnchors(): void;
|
|
30
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../../src/cli/shot/capture.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../../src/cli/shot/capture.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAe,MAAM,cAAc,CAAA;AAS7F,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,KAAK,EACL,MAAM,EACN,UAAU,EACV,SAAS,EACT,QAAQ,EACT,MAAM,SAAS,CAAA;AAiBhB,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,SAAS,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,MAAM,EAAE,SAAS,SAAS,EAAE,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,2FAA2F;IAC3F,YAAY,CAAC,EAAE,SAAS,IAAI,EAAE,CAAA;IAC9B,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,MAAM,EAAE,CAAA;IAC5B,wFAAwF;IACxF,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;IACrD,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5B,CAAA;AAED,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,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,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAA;AAE/D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAyD1D;AAED,sHAAsH;AACtH,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,CAY5D;AAyED,qHAAqH;AACrH,wBAAsB,WAAW,CAAC,CAAC,SAAS,SAAS,EACnD,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,MAAM,GAAE,SAAS,IAAI,EAAO,EAC5B,MAAM,SAAK,GACV,OAAO,CAAC,CAAC,CAAC,CAaZ;AAID,kGAAkG;AAClG,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,MAC2B,CAAA;AAsDnF,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,KAAK,EAAE,KAAK,EAAE,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAC,CAmDD"}
|
package/dist/cli/shot/capture.js
CHANGED
|
@@ -54,7 +54,7 @@ function unionClip(boxes, margin, viewport, tall) {
|
|
|
54
54
|
const top = Math.max(0, Math.min(...boxes.map((b) => b.y)) - margin);
|
|
55
55
|
const right = Math.min(width, Math.max(...boxes.map((b) => b.x + b.width)) + margin);
|
|
56
56
|
const bottom = Math.min(height, Math.max(...boxes.map((b) => b.y + b.height)) + margin);
|
|
57
|
-
return { x: left, y: top, width:
|
|
57
|
+
return right <= left || bottom <= top ? null : { x: left, y: top, width: right - left, height: bottom - top };
|
|
58
58
|
}
|
|
59
59
|
const snap = (target, path, extra = {}) => target.screenshot({
|
|
60
60
|
path,
|
|
@@ -63,6 +63,16 @@ const snap = (target, path, extra = {}) => target.screenshot({
|
|
|
63
63
|
timeout: SHOT_TIMEOUT_MS,
|
|
64
64
|
...extra
|
|
65
65
|
});
|
|
66
|
+
async function snapClip(c, path, targets) {
|
|
67
|
+
for (let retry = true; ; retry = false) {
|
|
68
|
+
const live = await c.page.evaluate("window.innerHeight");
|
|
69
|
+
const boxes = (await Promise.all(targets.map((t) => t.boundingBox()))).filter((b) => b !== null);
|
|
70
|
+
const clip = boxes.length === targets.length && unionClip(boxes, FOCUS_MARGIN_PX, c.viewport, live);
|
|
71
|
+
if (clip) return void await snap(c.page, path, { clip });
|
|
72
|
+
if (!retry) throw new Error("Clipped area is either empty or outside the resulting image");
|
|
73
|
+
await c.page.evaluate(FRAMES);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
66
76
|
function record(c, { name, state, status, file, note, stateful }) {
|
|
67
77
|
const { route, scheme, viewport } = c;
|
|
68
78
|
c.shots.push({
|
|
@@ -331,8 +341,9 @@ async function hoverTrigger(target) {
|
|
|
331
341
|
const position = at && box ? { x: at.x * box.width, y: at.y * box.height } : void 0;
|
|
332
342
|
await target.hover({ timeout: HOVER_TIMEOUT_MS, ...position && { position } });
|
|
333
343
|
}
|
|
344
|
+
const tipOf = (c, describedBy) => c.page.locator(visibleTooltip(describedBy)).first();
|
|
334
345
|
async function openTooltipBox(c, describedBy, timeout = TIP_PROBE_MS) {
|
|
335
|
-
const tip = c
|
|
346
|
+
const tip = tipOf(c, describedBy);
|
|
336
347
|
try {
|
|
337
348
|
await tip.waitFor({ state: "visible", timeout });
|
|
338
349
|
} catch {
|
|
@@ -361,7 +372,7 @@ async function captureHover(c, name) {
|
|
|
361
372
|
const describedBy = idOf(await target.evaluate(describedByOf));
|
|
362
373
|
const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)];
|
|
363
374
|
if (!box || !tip) return void await snap(anchor, path);
|
|
364
|
-
await
|
|
375
|
+
await snapClip(c, path, [anchor, tipOf(c, describedBy)]);
|
|
365
376
|
});
|
|
366
377
|
await c.page.mouse.move(0, 0);
|
|
367
378
|
}
|
|
@@ -400,9 +411,7 @@ async function captureFocus(c, name) {
|
|
|
400
411
|
)
|
|
401
412
|
);
|
|
402
413
|
const tip = await openTooltipBox(c, focused);
|
|
403
|
-
await
|
|
404
|
-
clip: unionClip(tip ? [box, tip] : [box], FOCUS_MARGIN_PX, c.viewport, c.height)
|
|
405
|
-
});
|
|
414
|
+
await snapClip(c, path, tip ? [anchor, tipOf(c, focused)] : [anchor]);
|
|
406
415
|
});
|
|
407
416
|
await c.page.evaluate("document.activeElement?.blur()");
|
|
408
417
|
}
|
|
@@ -420,7 +429,7 @@ async function captureTooltip(c, name) {
|
|
|
420
429
|
if (!t) throw new Error('no visible [role="tooltip"] after hover');
|
|
421
430
|
const a = await settledBox(anchor);
|
|
422
431
|
if (!a) throw new Error("tooltip or anchor has no box");
|
|
423
|
-
await
|
|
432
|
+
await snapClip(c, path, [anchor, tipOf(c, describedBy)]);
|
|
424
433
|
});
|
|
425
434
|
await c.page.mouse.move(0, 0);
|
|
426
435
|
}
|
|
@@ -719,6 +728,7 @@ export {
|
|
|
719
728
|
revealInPage,
|
|
720
729
|
sheetName,
|
|
721
730
|
showChrome,
|
|
731
|
+
snapClip,
|
|
722
732
|
tagAutoAnchors,
|
|
723
733
|
tooltipSelector,
|
|
724
734
|
unionClip,
|