strata-react 1.0.28 → 1.0.31
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/README.md +1 -1
- package/dist/components/compare-grid.d.ts +4 -1
- package/dist/components/compare-parts.d.ts +4 -2
- package/dist/components/compare-regions.d.ts +37 -0
- package/dist/components/compare-video.d.ts +51 -0
- package/dist/components/compare.d.ts +16 -1
- package/dist/components/media.d.ts +6 -1
- package/dist/components/viewport.d.ts +19 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +809 -21
- package/dist/index.js.map +1 -1
- package/dist/lib/viewport.d.ts +26 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2671,7 +2671,7 @@ function TimeReadout({ time, duration, precision = "seconds", fps = 30, classNam
|
|
|
2671
2671
|
});
|
|
2672
2672
|
}
|
|
2673
2673
|
/** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
|
|
2674
|
-
function SeekBar({ time, duration: known, onSeek, marks = [], buffered, step = 5, bigStep = 30, label = "Seek", precision = "seconds", fps = 30, disabled: off, className }) {
|
|
2674
|
+
function SeekBar({ time, duration: known, onSeek, marks = [], onMarkPress, buffered, step = 5, bigStep = 30, label = "Seek", precision = "seconds", fps = 30, disabled: off, className }) {
|
|
2675
2675
|
const duration = known && Number.isFinite(known) && known > 0 ? known : 0;
|
|
2676
2676
|
const disabled = off || duration === 0;
|
|
2677
2677
|
const track = React.useRef(null);
|
|
@@ -2764,7 +2764,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], buffered, step = 5
|
|
|
2764
2764
|
})}`,
|
|
2765
2765
|
onPointerDown: (e) => e.stopPropagation(),
|
|
2766
2766
|
onMouseDown: (e) => e.stopPropagation(),
|
|
2767
|
-
onClick: () => seekTo(m.time),
|
|
2767
|
+
onClick: () => onMarkPress ? onMarkPress(m) : seekTo(m.time),
|
|
2768
2768
|
className: "absolute top-1/2 h-3 w-1 -translate-y-1/2 cursor-pointer rounded-pill bg-foreground",
|
|
2769
2769
|
style: { left: `${m.time / duration * 100}%` }
|
|
2770
2770
|
}, `${m.time}-${m.label}`)),
|
|
@@ -5285,7 +5285,7 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
|
|
|
5285
5285
|
});
|
|
5286
5286
|
}
|
|
5287
5287
|
// src/components/line-chart.tsx
|
|
5288
|
-
function useWidth() {
|
|
5288
|
+
function useWidth$1() {
|
|
5289
5289
|
const ref = React.useRef(null);
|
|
5290
5290
|
const [width, setWidth] = React.useState(0);
|
|
5291
5291
|
React.useLayoutEffect(() => {
|
|
@@ -5369,7 +5369,7 @@ function fitTicks(ticks, scale, widthOf, gap = 12) {
|
|
|
5369
5369
|
}
|
|
5370
5370
|
/** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
|
|
5371
5371
|
function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, xLabel = "Time", formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, current, end, formatCurrent, readout, onPick, area, height = 280, className }) {
|
|
5372
|
-
const [ref, width] = useWidth();
|
|
5372
|
+
const [ref, width] = useWidth$1();
|
|
5373
5373
|
const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
|
|
5374
5374
|
const all = [...series, ...planned ?? []];
|
|
5375
5375
|
const xMin = Math.min(...all.map((p) => p.x));
|
|
@@ -6537,7 +6537,50 @@ function actualPixelsScale(naturalWidth, fittedWidth) {
|
|
|
6537
6537
|
function viewportTransform(v) {
|
|
6538
6538
|
return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
|
|
6539
6539
|
}
|
|
6540
|
+
/** A region as shares of the frame, so it lands on the same part of every candidate whatever its pixel size. */
|
|
6541
|
+
function regionShares(region) {
|
|
6542
|
+
const [x, y, w, h] = region.box;
|
|
6543
|
+
if (!region.of) return [
|
|
6544
|
+
x,
|
|
6545
|
+
y,
|
|
6546
|
+
w,
|
|
6547
|
+
h
|
|
6548
|
+
];
|
|
6549
|
+
const [ow, oh] = region.of;
|
|
6550
|
+
return [
|
|
6551
|
+
x / ow,
|
|
6552
|
+
y / oh,
|
|
6553
|
+
w / ow,
|
|
6554
|
+
h / oh
|
|
6555
|
+
];
|
|
6556
|
+
}
|
|
6557
|
+
/** The viewport that fills the frame with a box (as much of it as fits, centred): the scale that fits the box, the offset that puts its centre at the frame's centre. */
|
|
6558
|
+
function boxViewport(box, frame) {
|
|
6559
|
+
const [x, y, w, h] = box;
|
|
6560
|
+
const scale = Math.min(32, Math.max(1, Math.min(1 / Math.max(w, 1e-6), 1 / Math.max(h, 1e-6))));
|
|
6561
|
+
return clampViewport({
|
|
6562
|
+
scale,
|
|
6563
|
+
x: -scale * (x + w / 2 - .5) * frame.width,
|
|
6564
|
+
y: -scale * (y + h / 2 - .5) * frame.height
|
|
6565
|
+
}, frame);
|
|
6566
|
+
}
|
|
6567
|
+
/** A rectangle drawn on the frame (pixels from its top left) as shares of the picture under the viewport now. */
|
|
6568
|
+
function frameBoxToShares(rect, v, frame) {
|
|
6569
|
+
const toShare = (p, offset, size) => size ? (p - size / 2 - offset) / v.scale / size + .5 : 0;
|
|
6570
|
+
const clamp = (n) => Math.min(1, Math.max(0, n));
|
|
6571
|
+
const xa = clamp(toShare(Math.min(rect.x0, rect.x1), v.x, frame.width));
|
|
6572
|
+
const xb = clamp(toShare(Math.max(rect.x0, rect.x1), v.x, frame.width));
|
|
6573
|
+
const ya = clamp(toShare(Math.min(rect.y0, rect.y1), v.y, frame.height));
|
|
6574
|
+
const yb = clamp(toShare(Math.max(rect.y0, rect.y1), v.y, frame.height));
|
|
6575
|
+
return [
|
|
6576
|
+
xa,
|
|
6577
|
+
ya,
|
|
6578
|
+
xb - xa,
|
|
6579
|
+
yb - ya
|
|
6580
|
+
];
|
|
6581
|
+
}
|
|
6540
6582
|
// src/components/compare-parts.tsx
|
|
6583
|
+
var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
|
|
6541
6584
|
/** A word for a picture's name on the page: its label, with its note unless blind. */
|
|
6542
6585
|
function Caption({ c, blind }) {
|
|
6543
6586
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -6552,7 +6595,7 @@ function Caption({ c, blind }) {
|
|
|
6552
6595
|
});
|
|
6553
6596
|
}
|
|
6554
6597
|
/** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
|
|
6555
|
-
function Picture({ c, blind, missing, onNatural, imgRef }) {
|
|
6598
|
+
function Picture({ c, blind, missing, onNatural, imgRef, pixelated }) {
|
|
6556
6599
|
const [state, setState] = React.useState("loading");
|
|
6557
6600
|
React.useEffect(() => setState("loading"), [c.media.src]);
|
|
6558
6601
|
const alt = blind ? c.label : c.media.alt;
|
|
@@ -6576,6 +6619,7 @@ function Picture({ c, blind, missing, onNatural, imgRef }) {
|
|
|
6576
6619
|
src: c.media.src,
|
|
6577
6620
|
alt,
|
|
6578
6621
|
draggable: false,
|
|
6622
|
+
style: pixelated ? { imageRendering: "pixelated" } : void 0,
|
|
6579
6623
|
onLoad: (e) => {
|
|
6580
6624
|
setState("ready");
|
|
6581
6625
|
onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
|
|
@@ -6816,12 +6860,22 @@ function useViewport(initial = FIT) {
|
|
|
6816
6860
|
}
|
|
6817
6861
|
var PAN_STEP = 48;
|
|
6818
6862
|
/** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
|
|
6819
|
-
var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, viewport, setViewport, children, cover, overlay, maxHeight, className }, forwardedRef) {
|
|
6863
|
+
var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, viewport, setViewport, children, cover, overlay, maxHeight, onBox, outline, className }, forwardedRef) {
|
|
6820
6864
|
const ref = React.useRef(null);
|
|
6821
6865
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6822
6866
|
const latest = React.useRef(viewport);
|
|
6823
6867
|
latest.current = viewport;
|
|
6824
6868
|
const drag = React.useRef(null);
|
|
6869
|
+
const [band, setBand] = React.useState(null);
|
|
6870
|
+
const bandRef = React.useRef(band);
|
|
6871
|
+
bandRef.current = band;
|
|
6872
|
+
const inFrame = (clientX, clientY) => {
|
|
6873
|
+
const r = ref.current.getBoundingClientRect();
|
|
6874
|
+
return {
|
|
6875
|
+
x: clientX - r.left,
|
|
6876
|
+
y: clientY - r.top
|
|
6877
|
+
};
|
|
6878
|
+
};
|
|
6825
6879
|
const size = () => {
|
|
6826
6880
|
const r = ref.current.getBoundingClientRect();
|
|
6827
6881
|
return {
|
|
@@ -6887,6 +6941,17 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6887
6941
|
tabIndex: 0,
|
|
6888
6942
|
onKeyDown,
|
|
6889
6943
|
onPointerDown: (e) => {
|
|
6944
|
+
if (e.shiftKey && onBox && e.button === 0) {
|
|
6945
|
+
const p = inFrame(e.clientX, e.clientY);
|
|
6946
|
+
setBand({
|
|
6947
|
+
x0: p.x,
|
|
6948
|
+
y0: p.y,
|
|
6949
|
+
x1: p.x,
|
|
6950
|
+
y1: p.y
|
|
6951
|
+
});
|
|
6952
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
6953
|
+
return;
|
|
6954
|
+
}
|
|
6890
6955
|
if (!zoomed || e.button !== 0) return;
|
|
6891
6956
|
drag.current = {
|
|
6892
6957
|
x: e.clientX,
|
|
@@ -6895,6 +6960,15 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6895
6960
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
6896
6961
|
},
|
|
6897
6962
|
onPointerMove: (e) => {
|
|
6963
|
+
if (bandRef.current) {
|
|
6964
|
+
const p = inFrame(e.clientX, e.clientY);
|
|
6965
|
+
setBand({
|
|
6966
|
+
...bandRef.current,
|
|
6967
|
+
x1: p.x,
|
|
6968
|
+
y1: p.y
|
|
6969
|
+
});
|
|
6970
|
+
return;
|
|
6971
|
+
}
|
|
6898
6972
|
if (!drag.current) return;
|
|
6899
6973
|
const dx = e.clientX - drag.current.x;
|
|
6900
6974
|
const dy = e.clientY - drag.current.y;
|
|
@@ -6908,8 +6982,18 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6908
6982
|
y: latest.current.y + dy
|
|
6909
6983
|
}, size()));
|
|
6910
6984
|
},
|
|
6911
|
-
onPointerUp: () =>
|
|
6912
|
-
|
|
6985
|
+
onPointerUp: () => {
|
|
6986
|
+
drag.current = null;
|
|
6987
|
+
const b = bandRef.current;
|
|
6988
|
+
if (b) {
|
|
6989
|
+
setBand(null);
|
|
6990
|
+
if (Math.abs(b.x1 - b.x0) > 6 && Math.abs(b.y1 - b.y0) > 6) onBox?.(b);
|
|
6991
|
+
}
|
|
6992
|
+
},
|
|
6993
|
+
onPointerCancel: () => {
|
|
6994
|
+
drag.current = null;
|
|
6995
|
+
setBand(null);
|
|
6996
|
+
},
|
|
6913
6997
|
onDoubleClick: (e) => {
|
|
6914
6998
|
const v = latest.current;
|
|
6915
6999
|
setViewport(v.scale > 1 ? FIT : zoomAt(v, 2, fromCentre(e.clientX, e.clientY), size()));
|
|
@@ -6944,6 +7028,26 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6944
7028
|
children: cover.content
|
|
6945
7029
|
})
|
|
6946
7030
|
}),
|
|
7031
|
+
outline && viewport.scale === 1 && /* @__PURE__ */ jsx("div", {
|
|
7032
|
+
"aria-hidden": true,
|
|
7033
|
+
className: "pointer-events-none absolute border-2 border-foreground ring-1 ring-background",
|
|
7034
|
+
style: {
|
|
7035
|
+
left: `${outline[0] * 100}%`,
|
|
7036
|
+
top: `${outline[1] * 100}%`,
|
|
7037
|
+
width: `${outline[2] * 100}%`,
|
|
7038
|
+
height: `${outline[3] * 100}%`
|
|
7039
|
+
}
|
|
7040
|
+
}),
|
|
7041
|
+
band && /* @__PURE__ */ jsx("div", {
|
|
7042
|
+
"aria-hidden": true,
|
|
7043
|
+
className: "pointer-events-none absolute border-2 border-dashed border-foreground",
|
|
7044
|
+
style: {
|
|
7045
|
+
left: Math.min(band.x0, band.x1),
|
|
7046
|
+
top: Math.min(band.y0, band.y1),
|
|
7047
|
+
width: Math.abs(band.x1 - band.x0),
|
|
7048
|
+
height: Math.abs(band.y1 - band.y0)
|
|
7049
|
+
}
|
|
7050
|
+
}),
|
|
6947
7051
|
overlay != null && /* @__PURE__ */ jsx("div", {
|
|
6948
7052
|
className: "pointer-events-none absolute inset-0",
|
|
6949
7053
|
onPointerDown: (e) => e.stopPropagation(),
|
|
@@ -6954,15 +7058,141 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6954
7058
|
]
|
|
6955
7059
|
});
|
|
6956
7060
|
});
|
|
7061
|
+
// src/components/compare-regions.tsx
|
|
7062
|
+
var REGION_KEYS = [
|
|
7063
|
+
"q",
|
|
7064
|
+
"w",
|
|
7065
|
+
"e",
|
|
7066
|
+
"r",
|
|
7067
|
+
"y",
|
|
7068
|
+
"u"
|
|
7069
|
+
];
|
|
7070
|
+
/** Regions for one item: `reset` is a key that changes with the item, which drops the regions drawn by hand. */
|
|
7071
|
+
function useRegions({ regions = [], viewport, setViewport, frame, reset }) {
|
|
7072
|
+
const [drawn, setDrawn] = React.useState({
|
|
7073
|
+
key: reset,
|
|
7074
|
+
list: []
|
|
7075
|
+
});
|
|
7076
|
+
const hand = drawn.key === reset ? drawn.list : [];
|
|
7077
|
+
const all = React.useMemo(() => [...regions, ...hand], [regions, hand]);
|
|
7078
|
+
const [active, setActive] = React.useState(null);
|
|
7079
|
+
const [peekId, setPeek] = React.useState(null);
|
|
7080
|
+
const size = () => {
|
|
7081
|
+
const r = frame.current?.getBoundingClientRect();
|
|
7082
|
+
return {
|
|
7083
|
+
width: r?.width ?? 0,
|
|
7084
|
+
height: r?.height ?? 0
|
|
7085
|
+
};
|
|
7086
|
+
};
|
|
7087
|
+
const choose = (id) => {
|
|
7088
|
+
const region = all.find((r) => r.id === id);
|
|
7089
|
+
if (!region) {
|
|
7090
|
+
setActive(null);
|
|
7091
|
+
setViewport({
|
|
7092
|
+
scale: 1,
|
|
7093
|
+
x: 0,
|
|
7094
|
+
y: 0
|
|
7095
|
+
});
|
|
7096
|
+
return;
|
|
7097
|
+
}
|
|
7098
|
+
applied.current = size();
|
|
7099
|
+
setViewport(boxViewport(regionShares(region), applied.current));
|
|
7100
|
+
setActive(region.id);
|
|
7101
|
+
setPeek(null);
|
|
7102
|
+
};
|
|
7103
|
+
React.useEffect(() => setActive(null), [reset]);
|
|
7104
|
+
const add = (rect) => {
|
|
7105
|
+
const box = frameBoxToShares(rect, viewport, size());
|
|
7106
|
+
if (box[2] <= 0 || box[3] <= 0) return;
|
|
7107
|
+
const region = {
|
|
7108
|
+
id: `region-${all.length + 1}`,
|
|
7109
|
+
label: `Region ${all.length + 1}`,
|
|
7110
|
+
box
|
|
7111
|
+
};
|
|
7112
|
+
setDrawn({
|
|
7113
|
+
key: reset,
|
|
7114
|
+
list: [...hand, region]
|
|
7115
|
+
});
|
|
7116
|
+
applied.current = size();
|
|
7117
|
+
setViewport(boxViewport(box, applied.current));
|
|
7118
|
+
setActive(region.id);
|
|
7119
|
+
};
|
|
7120
|
+
const applied = React.useRef({
|
|
7121
|
+
width: 0,
|
|
7122
|
+
height: 0
|
|
7123
|
+
});
|
|
7124
|
+
const [, bump] = React.useState(0);
|
|
7125
|
+
React.useLayoutEffect(() => {
|
|
7126
|
+
const now = size();
|
|
7127
|
+
if (now.width === applied.current.width && now.height === applied.current.height) return;
|
|
7128
|
+
applied.current = now;
|
|
7129
|
+
const region = all.find((r) => r.id === active);
|
|
7130
|
+
if (region && now.width > 0) setViewport(boxViewport(regionShares(region), now));
|
|
7131
|
+
});
|
|
7132
|
+
React.useLayoutEffect(() => {
|
|
7133
|
+
const el = frame.current;
|
|
7134
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
7135
|
+
const ro = new ResizeObserver(() => {
|
|
7136
|
+
const r = el.getBoundingClientRect();
|
|
7137
|
+
if (r.width !== applied.current.width || r.height !== applied.current.height) bump((n) => n + 1);
|
|
7138
|
+
});
|
|
7139
|
+
ro.observe(el);
|
|
7140
|
+
return () => ro.disconnect();
|
|
7141
|
+
});
|
|
7142
|
+
const peekRegion = all.find((r) => r.id === peekId);
|
|
7143
|
+
return {
|
|
7144
|
+
regions: all,
|
|
7145
|
+
active,
|
|
7146
|
+
choose,
|
|
7147
|
+
setViewport: (next) => {
|
|
7148
|
+
setActive(null);
|
|
7149
|
+
setViewport(next);
|
|
7150
|
+
},
|
|
7151
|
+
add,
|
|
7152
|
+
peek: peekRegion ? regionShares(peekRegion) : null,
|
|
7153
|
+
setPeek,
|
|
7154
|
+
shortcuts: all.slice(0, REGION_KEYS.length).map((r, i) => ({
|
|
7155
|
+
keys: [REGION_KEYS[i]],
|
|
7156
|
+
label: `Region: ${r.label}`,
|
|
7157
|
+
run: () => choose(r.id)
|
|
7158
|
+
}))
|
|
7159
|
+
};
|
|
7160
|
+
}
|
|
7161
|
+
/** The chip strip: the whole frame and each region, one chosen. Renders nothing when there are no regions. */
|
|
7162
|
+
function RegionChips({ state }) {
|
|
7163
|
+
if (state.regions.length === 0) return null;
|
|
7164
|
+
const byLabel = (target) => {
|
|
7165
|
+
const text = target.closest?.("[role=\"radio\"]")?.textContent;
|
|
7166
|
+
return state.regions.find((r) => r.label === text)?.id ?? null;
|
|
7167
|
+
};
|
|
7168
|
+
return /* @__PURE__ */ jsx("div", {
|
|
7169
|
+
onPointerOver: (e) => state.setPeek(byLabel(e.target)),
|
|
7170
|
+
onFocus: (e) => state.setPeek(byLabel(e.target)),
|
|
7171
|
+
onPointerLeave: () => state.setPeek(null),
|
|
7172
|
+
onBlur: () => state.setPeek(null),
|
|
7173
|
+
children: /* @__PURE__ */ jsx(ToggleGroup, {
|
|
7174
|
+
label: "Region",
|
|
7175
|
+
options: [{
|
|
7176
|
+
value: "",
|
|
7177
|
+
label: "Whole frame"
|
|
7178
|
+
}, ...state.regions.map((r) => ({
|
|
7179
|
+
value: r.id,
|
|
7180
|
+
label: r.label
|
|
7181
|
+
}))],
|
|
7182
|
+
value: state.active ?? "",
|
|
7183
|
+
onChange: (v) => state.choose(v === "" ? null : v),
|
|
7184
|
+
size: "sm"
|
|
7185
|
+
})
|
|
7186
|
+
});
|
|
7187
|
+
}
|
|
6957
7188
|
// src/components/compare.tsx
|
|
6958
|
-
var MODE_LABEL = {
|
|
7189
|
+
var MODE_LABEL$1 = {
|
|
6959
7190
|
side: "Side by side",
|
|
6960
7191
|
swipe: "Swipe",
|
|
6961
7192
|
fade: "Fade",
|
|
6962
7193
|
blink: "Blink",
|
|
6963
7194
|
difference: "Difference"
|
|
6964
7195
|
};
|
|
6965
|
-
var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
|
|
6966
7196
|
var ALL_MODES = [
|
|
6967
7197
|
"side",
|
|
6968
7198
|
"swipe",
|
|
@@ -6971,7 +7201,7 @@ var ALL_MODES = [
|
|
|
6971
7201
|
"difference"
|
|
6972
7202
|
];
|
|
6973
7203
|
/** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
|
|
6974
|
-
function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, keys = true, extraShortcuts = [], footer, maxHeight, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
|
|
7204
|
+
function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, regions, keys = true, extraShortcuts = [], footer, maxHeight, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
|
|
6975
7205
|
const { viewport, setViewport } = useViewport();
|
|
6976
7206
|
const [full, setFull] = React.useState(false);
|
|
6977
7207
|
const pairKey = `${a.media.src}|${b.media.src}`;
|
|
@@ -6987,10 +7217,17 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
6987
7217
|
const frameRef = React.useRef(null);
|
|
6988
7218
|
const imgRef = React.useRef(null);
|
|
6989
7219
|
const aspect = natural ? natural[0] / natural[1] : 3 / 2;
|
|
6990
|
-
const
|
|
7220
|
+
const rg = useRegions({
|
|
7221
|
+
regions,
|
|
6991
7222
|
viewport,
|
|
6992
7223
|
setViewport,
|
|
6993
7224
|
frame: frameRef,
|
|
7225
|
+
reset: pairKey
|
|
7226
|
+
});
|
|
7227
|
+
const zoom = useZoom({
|
|
7228
|
+
viewport,
|
|
7229
|
+
setViewport: rg.setViewport,
|
|
7230
|
+
frame: frameRef,
|
|
6994
7231
|
natural
|
|
6995
7232
|
});
|
|
6996
7233
|
const flip = () => setShowing((s) => s === "a" ? "b" : "a");
|
|
@@ -6999,7 +7236,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
6999
7236
|
...extraShortcuts,
|
|
7000
7237
|
...offered.map((m, i) => ({
|
|
7001
7238
|
keys: [String(i + 1)],
|
|
7002
|
-
label: MODE_LABEL[m],
|
|
7239
|
+
label: MODE_LABEL$1[m],
|
|
7003
7240
|
run: () => onModeChange(m)
|
|
7004
7241
|
})),
|
|
7005
7242
|
{
|
|
@@ -7008,6 +7245,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7008
7245
|
run: flip,
|
|
7009
7246
|
disabled: mode !== "blink"
|
|
7010
7247
|
},
|
|
7248
|
+
...rg.shortcuts,
|
|
7011
7249
|
...zoomShortcuts(zoom, full, setFull)
|
|
7012
7250
|
];
|
|
7013
7251
|
useHotkeys(shortcuts, { enabled: keys });
|
|
@@ -7016,7 +7254,8 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7016
7254
|
blind,
|
|
7017
7255
|
missing,
|
|
7018
7256
|
imgRef: ref,
|
|
7019
|
-
onNatural
|
|
7257
|
+
onNatural,
|
|
7258
|
+
pixelated: rg.active !== null
|
|
7020
7259
|
});
|
|
7021
7260
|
const learn = (w, h) => setLearned({
|
|
7022
7261
|
key: pairKey,
|
|
@@ -7024,7 +7263,9 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7024
7263
|
});
|
|
7025
7264
|
const frameProps = {
|
|
7026
7265
|
viewport,
|
|
7027
|
-
setViewport,
|
|
7266
|
+
setViewport: rg.setViewport,
|
|
7267
|
+
onBox: rg.add,
|
|
7268
|
+
outline: rg.peek,
|
|
7028
7269
|
aspect,
|
|
7029
7270
|
maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
|
|
7030
7271
|
};
|
|
@@ -7167,7 +7408,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7167
7408
|
label: "View",
|
|
7168
7409
|
options: offered.map((m) => ({
|
|
7169
7410
|
value: m,
|
|
7170
|
-
label: MODE_LABEL[m]
|
|
7411
|
+
label: MODE_LABEL$1[m]
|
|
7171
7412
|
})),
|
|
7172
7413
|
value: mode,
|
|
7173
7414
|
onChange: (v) => onModeChange(v),
|
|
@@ -7186,6 +7427,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7186
7427
|
})
|
|
7187
7428
|
]
|
|
7188
7429
|
}),
|
|
7430
|
+
/* @__PURE__ */ jsx(RegionChips, { state: rg }),
|
|
7189
7431
|
mode === "fade" && /* @__PURE__ */ jsxs("div", {
|
|
7190
7432
|
className: "flex items-center gap-3",
|
|
7191
7433
|
children: [
|
|
@@ -7823,6 +8065,541 @@ function CompareAudio({ label, a, b, blind, missing, levelMatch = true, align =
|
|
|
7823
8065
|
]
|
|
7824
8066
|
});
|
|
7825
8067
|
}
|
|
8068
|
+
// src/components/compare-video.tsx
|
|
8069
|
+
var MODES = [
|
|
8070
|
+
"side",
|
|
8071
|
+
"swipe",
|
|
8072
|
+
"fade",
|
|
8073
|
+
"blink"
|
|
8074
|
+
];
|
|
8075
|
+
var MODE_LABEL = {
|
|
8076
|
+
side: "Side by side",
|
|
8077
|
+
swipe: "Swipe",
|
|
8078
|
+
fade: "Fade",
|
|
8079
|
+
blink: "Blink"
|
|
8080
|
+
};
|
|
8081
|
+
var SLOW_RATES = [
|
|
8082
|
+
.1,
|
|
8083
|
+
.25,
|
|
8084
|
+
.5,
|
|
8085
|
+
1,
|
|
8086
|
+
1.25,
|
|
8087
|
+
1.5,
|
|
8088
|
+
2
|
|
8089
|
+
];
|
|
8090
|
+
function useWidth(ref) {
|
|
8091
|
+
const [width, setWidth] = React.useState(0);
|
|
8092
|
+
React.useLayoutEffect(() => {
|
|
8093
|
+
const el = ref.current;
|
|
8094
|
+
if (!el) return;
|
|
8095
|
+
const read = () => setWidth(el.getBoundingClientRect().width);
|
|
8096
|
+
read();
|
|
8097
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
8098
|
+
const ro = new ResizeObserver(read);
|
|
8099
|
+
ro.observe(el);
|
|
8100
|
+
return () => ro.disconnect();
|
|
8101
|
+
});
|
|
8102
|
+
return width;
|
|
8103
|
+
}
|
|
8104
|
+
/** Two videos to judge by eye on one clock: side by side, swipe, fade or blink, zoomed together, with matched sound and full screen. */
|
|
8105
|
+
function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates = SLOW_RATES, regions, moments = [], loop: loopProp, onLoopChange, audio = "a", pixelated = "zoomed", maxHeight, keys = true, extraShortcuts = [], footer, className }) {
|
|
8106
|
+
const refA = React.useRef(null);
|
|
8107
|
+
const refB = React.useRef(null);
|
|
8108
|
+
const sa = useMediaElement(refA);
|
|
8109
|
+
const sb = useMediaElement(refB);
|
|
8110
|
+
const { viewport, setViewport } = useViewport();
|
|
8111
|
+
const [full, setFull] = React.useState(false);
|
|
8112
|
+
const [divider, setDivider] = React.useState(50);
|
|
8113
|
+
const [blend, setBlend] = React.useState(50);
|
|
8114
|
+
const [showing, setShowing] = React.useState("a");
|
|
8115
|
+
const [volume, setVolume] = React.useState(100);
|
|
8116
|
+
const [muted, setMuted] = React.useState(false);
|
|
8117
|
+
const [wanted, setWanted] = React.useState(false);
|
|
8118
|
+
const frameRef = React.useRef(null);
|
|
8119
|
+
const frameWidth = useWidth(frameRef);
|
|
8120
|
+
const fps = a.media.fps ?? 30;
|
|
8121
|
+
const known = [sa.duration, sb.duration].filter((d) => d !== null);
|
|
8122
|
+
const duration = known.length ? Math.min(...known) : null;
|
|
8123
|
+
const failed = sa.error || sb.error;
|
|
8124
|
+
const play = () => {
|
|
8125
|
+
setWanted(true);
|
|
8126
|
+
sa.play();
|
|
8127
|
+
sb.play();
|
|
8128
|
+
};
|
|
8129
|
+
const pause = () => {
|
|
8130
|
+
setWanted(false);
|
|
8131
|
+
sa.pause();
|
|
8132
|
+
sb.pause();
|
|
8133
|
+
};
|
|
8134
|
+
const toggle = () => wanted ? pause() : play();
|
|
8135
|
+
const seek = (time) => {
|
|
8136
|
+
const t = Math.max(0, duration === null ? time : Math.min(time, duration));
|
|
8137
|
+
sa.seek(t);
|
|
8138
|
+
sb.seek(t);
|
|
8139
|
+
};
|
|
8140
|
+
const now = () => refA.current?.currentTime ?? sa.time;
|
|
8141
|
+
const step = (direction) => {
|
|
8142
|
+
pause();
|
|
8143
|
+
const frame = Math.floor(now() * fps + 1e-6);
|
|
8144
|
+
seek(Math.max(0, (frame + direction + .5) / fps));
|
|
8145
|
+
};
|
|
8146
|
+
const [ownLoop, setOwnLoop] = React.useState({
|
|
8147
|
+
start: null,
|
|
8148
|
+
end: null
|
|
8149
|
+
});
|
|
8150
|
+
const loop = loopProp ?? ownLoop;
|
|
8151
|
+
const setLoop = (next) => {
|
|
8152
|
+
setOwnLoop(next);
|
|
8153
|
+
onLoopChange?.(next);
|
|
8154
|
+
};
|
|
8155
|
+
const loopRef = React.useRef(loop);
|
|
8156
|
+
loopRef.current = loop;
|
|
8157
|
+
const setPoint = (point) => {
|
|
8158
|
+
const t = now();
|
|
8159
|
+
const other = point === "start" ? loop.end : loop.start;
|
|
8160
|
+
setLoop(other !== null && (point === "start" ? t >= other : t <= other) ? {
|
|
8161
|
+
start: point === "start" ? t : null,
|
|
8162
|
+
end: point === "end" ? t : null
|
|
8163
|
+
} : {
|
|
8164
|
+
...loop,
|
|
8165
|
+
[point]: t
|
|
8166
|
+
});
|
|
8167
|
+
};
|
|
8168
|
+
const clearLoop = () => setLoop({
|
|
8169
|
+
start: null,
|
|
8170
|
+
end: null
|
|
8171
|
+
});
|
|
8172
|
+
const looping = loop.start !== null && loop.end !== null;
|
|
8173
|
+
const chosenRate = React.useRef(1);
|
|
8174
|
+
const setRate = (rate) => {
|
|
8175
|
+
chosenRate.current = rate;
|
|
8176
|
+
sa.setRate(rate);
|
|
8177
|
+
sb.setRate(rate);
|
|
8178
|
+
};
|
|
8179
|
+
React.useEffect(() => {
|
|
8180
|
+
if (!(sa.ended || sb.ended)) return;
|
|
8181
|
+
const { start, end } = loopRef.current;
|
|
8182
|
+
const A = refA.current;
|
|
8183
|
+
const B = refB.current;
|
|
8184
|
+
if (wanted && start !== null && end !== null && A && B) {
|
|
8185
|
+
A.currentTime = start;
|
|
8186
|
+
B.currentTime = start;
|
|
8187
|
+
A.play();
|
|
8188
|
+
B.play();
|
|
8189
|
+
return;
|
|
8190
|
+
}
|
|
8191
|
+
setWanted(false);
|
|
8192
|
+
A?.pause();
|
|
8193
|
+
B?.pause();
|
|
8194
|
+
}, [sa.ended, sb.ended]);
|
|
8195
|
+
React.useEffect(() => {
|
|
8196
|
+
if (!wanted) return;
|
|
8197
|
+
let held = false;
|
|
8198
|
+
let frame = requestAnimationFrame(function tick() {
|
|
8199
|
+
const A = refA.current;
|
|
8200
|
+
const B = refB.current;
|
|
8201
|
+
if (A && B && !A.ended && !B.ended) {
|
|
8202
|
+
if (!(A.readyState >= 3 && B.readyState >= 3)) {
|
|
8203
|
+
if (!held) {
|
|
8204
|
+
held = true;
|
|
8205
|
+
A.pause();
|
|
8206
|
+
B.pause();
|
|
8207
|
+
}
|
|
8208
|
+
} else if (held) {
|
|
8209
|
+
held = false;
|
|
8210
|
+
A.play();
|
|
8211
|
+
B.play();
|
|
8212
|
+
} else if (!A.paused) {
|
|
8213
|
+
const { start, end } = loopRef.current;
|
|
8214
|
+
if (start !== null && end !== null && A.currentTime >= end) {
|
|
8215
|
+
A.currentTime = start;
|
|
8216
|
+
B.currentTime = start;
|
|
8217
|
+
frame = requestAnimationFrame(tick);
|
|
8218
|
+
return;
|
|
8219
|
+
}
|
|
8220
|
+
const drift = B.currentTime - A.currentTime;
|
|
8221
|
+
const one = 1 / fps;
|
|
8222
|
+
if (Math.abs(drift) > .3) B.currentTime = A.currentTime;
|
|
8223
|
+
else if (Math.abs(drift) > one) B.playbackRate = A.playbackRate * (drift > 0 ? .97 : 1.03);
|
|
8224
|
+
else if (Math.abs(drift) < one / 2 && B.playbackRate !== A.playbackRate) B.playbackRate = A.playbackRate;
|
|
8225
|
+
}
|
|
8226
|
+
}
|
|
8227
|
+
frame = requestAnimationFrame(tick);
|
|
8228
|
+
});
|
|
8229
|
+
return () => cancelAnimationFrame(frame);
|
|
8230
|
+
}, [wanted, fps]);
|
|
8231
|
+
const resume = React.useRef({
|
|
8232
|
+
time: 0,
|
|
8233
|
+
playing: false
|
|
8234
|
+
});
|
|
8235
|
+
if (sa.duration !== null) resume.current = {
|
|
8236
|
+
time: sa.time,
|
|
8237
|
+
playing: wanted
|
|
8238
|
+
};
|
|
8239
|
+
const restore = (e) => {
|
|
8240
|
+
const el = e.currentTarget;
|
|
8241
|
+
el.defaultPlaybackRate = chosenRate.current;
|
|
8242
|
+
el.playbackRate = chosenRate.current;
|
|
8243
|
+
if (resume.current.time > 0) el.currentTime = resume.current.time;
|
|
8244
|
+
if (resume.current.playing) el.play();
|
|
8245
|
+
};
|
|
8246
|
+
React.useEffect(() => {
|
|
8247
|
+
[[refA.current, "a"], [refB.current, "b"]].forEach(([el, side]) => {
|
|
8248
|
+
if (!(el instanceof HTMLVideoElement)) return;
|
|
8249
|
+
el.muted = audio !== side || muted || volume === 0;
|
|
8250
|
+
el.volume = volume / 100;
|
|
8251
|
+
});
|
|
8252
|
+
});
|
|
8253
|
+
const aspect = a.media.width / a.media.height;
|
|
8254
|
+
const natural = [a.media.width, a.media.height];
|
|
8255
|
+
const frameHeight = frameWidth / aspect;
|
|
8256
|
+
const sharpFor = (c) => {
|
|
8257
|
+
if (rg.active !== null) return true;
|
|
8258
|
+
if (pixelated !== "zoomed") return pixelated === "always";
|
|
8259
|
+
const drawn = Math.min(frameWidth, frameHeight * (c.media.width / c.media.height));
|
|
8260
|
+
return drawn > 0 && viewport.scale * drawn / c.media.width > 1;
|
|
8261
|
+
};
|
|
8262
|
+
const rg = useRegions({
|
|
8263
|
+
regions,
|
|
8264
|
+
viewport,
|
|
8265
|
+
setViewport,
|
|
8266
|
+
frame: frameRef,
|
|
8267
|
+
reset: `${a.media.src}|${b.media.src}`
|
|
8268
|
+
});
|
|
8269
|
+
const zoom = useZoom({
|
|
8270
|
+
viewport,
|
|
8271
|
+
setViewport: rg.setViewport,
|
|
8272
|
+
frame: frameRef,
|
|
8273
|
+
natural
|
|
8274
|
+
});
|
|
8275
|
+
const flip = () => setShowing((s) => s === "a" ? "b" : "a");
|
|
8276
|
+
const video = (c, ref) => /* @__PURE__ */ jsx("video", {
|
|
8277
|
+
ref,
|
|
8278
|
+
src: c.media.src,
|
|
8279
|
+
poster: c.media.poster,
|
|
8280
|
+
preload: "auto",
|
|
8281
|
+
playsInline: true,
|
|
8282
|
+
"aria-label": `Video ${c.label}`,
|
|
8283
|
+
onLoadedMetadata: restore,
|
|
8284
|
+
style: sharpFor(c) ? { imageRendering: "pixelated" } : void 0,
|
|
8285
|
+
className: "absolute inset-0 size-full object-contain"
|
|
8286
|
+
});
|
|
8287
|
+
const skeleton = !failed && (sa.duration === null || sb.duration === null) && /* @__PURE__ */ jsx(Skeleton, {
|
|
8288
|
+
"aria-hidden": true,
|
|
8289
|
+
className: "absolute inset-0 size-full rounded-none"
|
|
8290
|
+
});
|
|
8291
|
+
const frameProps = {
|
|
8292
|
+
viewport,
|
|
8293
|
+
setViewport: rg.setViewport,
|
|
8294
|
+
onBox: wanted ? void 0 : rg.add,
|
|
8295
|
+
outline: rg.peek,
|
|
8296
|
+
aspect,
|
|
8297
|
+
maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
|
|
8298
|
+
};
|
|
8299
|
+
const shortcuts = [
|
|
8300
|
+
...extraShortcuts,
|
|
8301
|
+
...MODES.map((m, i) => ({
|
|
8302
|
+
keys: [String(i + 1)],
|
|
8303
|
+
label: MODE_LABEL[m],
|
|
8304
|
+
run: () => onModeChange(m)
|
|
8305
|
+
})),
|
|
8306
|
+
{
|
|
8307
|
+
keys: ["x"],
|
|
8308
|
+
label: `Flip ${a.label} and ${b.label}`,
|
|
8309
|
+
run: flip,
|
|
8310
|
+
disabled: mode !== "blink"
|
|
8311
|
+
},
|
|
8312
|
+
{
|
|
8313
|
+
keys: [" ", "k"],
|
|
8314
|
+
label: "Play or pause",
|
|
8315
|
+
run: toggle
|
|
8316
|
+
},
|
|
8317
|
+
{
|
|
8318
|
+
keys: ["j"],
|
|
8319
|
+
label: "Back 1 s",
|
|
8320
|
+
run: () => seek(sa.time - 1),
|
|
8321
|
+
repeat: true
|
|
8322
|
+
},
|
|
8323
|
+
{
|
|
8324
|
+
keys: ["l"],
|
|
8325
|
+
label: "Forward 1 s",
|
|
8326
|
+
run: () => seek(sa.time + 1),
|
|
8327
|
+
repeat: true
|
|
8328
|
+
},
|
|
8329
|
+
{
|
|
8330
|
+
keys: [","],
|
|
8331
|
+
label: "Back one frame",
|
|
8332
|
+
run: () => step(-1),
|
|
8333
|
+
repeat: true
|
|
8334
|
+
},
|
|
8335
|
+
{
|
|
8336
|
+
keys: ["."],
|
|
8337
|
+
label: "Forward one frame",
|
|
8338
|
+
run: () => step(1),
|
|
8339
|
+
repeat: true
|
|
8340
|
+
},
|
|
8341
|
+
{
|
|
8342
|
+
keys: ["i"],
|
|
8343
|
+
label: "Loop starts here",
|
|
8344
|
+
run: () => setPoint("start")
|
|
8345
|
+
},
|
|
8346
|
+
{
|
|
8347
|
+
keys: ["o"],
|
|
8348
|
+
label: "Loop ends here",
|
|
8349
|
+
run: () => setPoint("end")
|
|
8350
|
+
},
|
|
8351
|
+
{
|
|
8352
|
+
keys: ["c"],
|
|
8353
|
+
label: "Clear the loop",
|
|
8354
|
+
run: clearLoop,
|
|
8355
|
+
disabled: loop.start === null && loop.end === null
|
|
8356
|
+
},
|
|
8357
|
+
...audio === "none" ? [] : [{
|
|
8358
|
+
keys: ["m"],
|
|
8359
|
+
label: "Mute",
|
|
8360
|
+
run: () => setMuted((m) => !m)
|
|
8361
|
+
}],
|
|
8362
|
+
...rg.shortcuts,
|
|
8363
|
+
...zoomShortcuts(zoom, full, setFull)
|
|
8364
|
+
];
|
|
8365
|
+
useHotkeys(shortcuts, { enabled: keys });
|
|
8366
|
+
const at = (t) => t === null ? format.missing : format.timecode(t, {
|
|
8367
|
+
precision: "frames",
|
|
8368
|
+
fps
|
|
8369
|
+
});
|
|
8370
|
+
const marks = [
|
|
8371
|
+
...moments,
|
|
8372
|
+
...loop.start !== null ? [{
|
|
8373
|
+
time: loop.start,
|
|
8374
|
+
label: "Loop start"
|
|
8375
|
+
}] : [],
|
|
8376
|
+
...loop.end !== null ? [{
|
|
8377
|
+
time: loop.end,
|
|
8378
|
+
label: "Loop end"
|
|
8379
|
+
}] : []
|
|
8380
|
+
];
|
|
8381
|
+
let body;
|
|
8382
|
+
if (mode === "side") body = /* @__PURE__ */ jsx("div", {
|
|
8383
|
+
className: "grid gap-3 sm:grid-cols-2",
|
|
8384
|
+
children: [[a, refA], [b, refB]].map(([c, ref], i) => /* @__PURE__ */ jsxs("figure", {
|
|
8385
|
+
className: "grid gap-1.5",
|
|
8386
|
+
children: [/* @__PURE__ */ jsx(Caption, {
|
|
8387
|
+
c,
|
|
8388
|
+
blind
|
|
8389
|
+
}), /* @__PURE__ */ jsxs(ViewportFrame, {
|
|
8390
|
+
...frameProps,
|
|
8391
|
+
label: `Frame ${c.label}`,
|
|
8392
|
+
ref: i === 0 ? frameRef : void 0,
|
|
8393
|
+
children: [i === 0 && skeleton, video(c, ref)]
|
|
8394
|
+
})]
|
|
8395
|
+
}, i))
|
|
8396
|
+
});
|
|
8397
|
+
else body = /* @__PURE__ */ jsxs("figure", {
|
|
8398
|
+
className: "grid gap-1.5",
|
|
8399
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
8400
|
+
className: "flex justify-between gap-4",
|
|
8401
|
+
children: [mode === "blink" ? /* @__PURE__ */ jsx(Caption, {
|
|
8402
|
+
c: showing === "a" ? a : b,
|
|
8403
|
+
blind
|
|
8404
|
+
}) : /* @__PURE__ */ jsx(Caption, {
|
|
8405
|
+
c: a,
|
|
8406
|
+
blind
|
|
8407
|
+
}), mode !== "blink" && /* @__PURE__ */ jsx(Caption, {
|
|
8408
|
+
c: b,
|
|
8409
|
+
blind
|
|
8410
|
+
})]
|
|
8411
|
+
}), /* @__PURE__ */ jsxs(ViewportFrame, {
|
|
8412
|
+
...frameProps,
|
|
8413
|
+
ref: frameRef,
|
|
8414
|
+
cover: mode === "swipe" ? {
|
|
8415
|
+
content: video(a, refA),
|
|
8416
|
+
shown: divider
|
|
8417
|
+
} : void 0,
|
|
8418
|
+
label: mode === "blink" ? `Frame ${(showing === "a" ? a : b).label}` : `${a.label} over ${b.label}`,
|
|
8419
|
+
overlay: mode === "swipe" && /* @__PURE__ */ jsx(Slider$1, {
|
|
8420
|
+
"aria-label": `Divider between ${a.label} and ${b.label}`,
|
|
8421
|
+
value: divider,
|
|
8422
|
+
onChange: (v) => setDivider(v),
|
|
8423
|
+
minValue: 0,
|
|
8424
|
+
maxValue: 100,
|
|
8425
|
+
step: 1,
|
|
8426
|
+
className: "absolute inset-0",
|
|
8427
|
+
children: /* @__PURE__ */ jsx(SliderTrack, {
|
|
8428
|
+
className: "pointer-events-none h-full w-full",
|
|
8429
|
+
children: /* @__PURE__ */ jsxs(SliderThumb, {
|
|
8430
|
+
className: "pointer-events-auto grid h-full w-8 cursor-ew-resize place-items-center focus-visible:outline-2 focus-visible:outline-ring",
|
|
8431
|
+
style: { top: "50%" },
|
|
8432
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
8433
|
+
"aria-hidden": true,
|
|
8434
|
+
className: "col-start-1 row-start-1 h-full w-1 border-x border-background bg-foreground"
|
|
8435
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
8436
|
+
"aria-hidden": true,
|
|
8437
|
+
className: "col-start-1 row-start-1 size-6 rounded-pill border-2 border-foreground bg-background"
|
|
8438
|
+
})]
|
|
8439
|
+
})
|
|
8440
|
+
})
|
|
8441
|
+
}),
|
|
8442
|
+
children: [
|
|
8443
|
+
skeleton,
|
|
8444
|
+
video(b, refB),
|
|
8445
|
+
mode !== "swipe" && /* @__PURE__ */ jsx("div", {
|
|
8446
|
+
className: "absolute inset-0",
|
|
8447
|
+
style: mode === "fade" ? { opacity: 1 - blend / 100 } : mode === "blink" ? { opacity: showing === "a" ? 1 : 0 } : void 0,
|
|
8448
|
+
children: video(a, refA)
|
|
8449
|
+
})
|
|
8450
|
+
]
|
|
8451
|
+
})]
|
|
8452
|
+
});
|
|
8453
|
+
return /* @__PURE__ */ jsx(FullscreenFrame, {
|
|
8454
|
+
label,
|
|
8455
|
+
active: full,
|
|
8456
|
+
onActiveChange: setFull,
|
|
8457
|
+
className,
|
|
8458
|
+
children: /* @__PURE__ */ jsxs("section", {
|
|
8459
|
+
"aria-label": label,
|
|
8460
|
+
className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
|
|
8461
|
+
children: [
|
|
8462
|
+
/* @__PURE__ */ jsxs(Toolbar, {
|
|
8463
|
+
label: "Comparison view",
|
|
8464
|
+
className: "items-center gap-2",
|
|
8465
|
+
children: [
|
|
8466
|
+
/* @__PURE__ */ jsx(ToggleGroup, {
|
|
8467
|
+
label: "View",
|
|
8468
|
+
options: MODES.map((m) => ({
|
|
8469
|
+
value: m,
|
|
8470
|
+
label: MODE_LABEL[m]
|
|
8471
|
+
})),
|
|
8472
|
+
value: mode,
|
|
8473
|
+
onChange: (v) => onModeChange(v),
|
|
8474
|
+
size: "sm"
|
|
8475
|
+
}),
|
|
8476
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
8477
|
+
/* @__PURE__ */ jsx(ZoomControls, {
|
|
8478
|
+
viewport,
|
|
8479
|
+
zoom,
|
|
8480
|
+
natural
|
|
8481
|
+
}),
|
|
8482
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
8483
|
+
/* @__PURE__ */ jsx(FullscreenButton, {
|
|
8484
|
+
full,
|
|
8485
|
+
setFull
|
|
8486
|
+
})
|
|
8487
|
+
]
|
|
8488
|
+
}),
|
|
8489
|
+
/* @__PURE__ */ jsx(RegionChips, { state: rg }),
|
|
8490
|
+
mode === "fade" && /* @__PURE__ */ jsxs("div", {
|
|
8491
|
+
className: "flex items-center gap-3",
|
|
8492
|
+
children: [
|
|
8493
|
+
/* @__PURE__ */ jsx("span", {
|
|
8494
|
+
className: "type-caption text-muted-foreground",
|
|
8495
|
+
children: a.label
|
|
8496
|
+
}),
|
|
8497
|
+
/* @__PURE__ */ jsx(Slider, {
|
|
8498
|
+
"aria-label": `Blend from ${a.label} to ${b.label}`,
|
|
8499
|
+
value: blend,
|
|
8500
|
+
onChange: setBlend,
|
|
8501
|
+
min: 0,
|
|
8502
|
+
max: 100,
|
|
8503
|
+
unit: "%",
|
|
8504
|
+
hideValue: true,
|
|
8505
|
+
className: "flex-1"
|
|
8506
|
+
}),
|
|
8507
|
+
/* @__PURE__ */ jsx("span", {
|
|
8508
|
+
className: "type-caption text-muted-foreground",
|
|
8509
|
+
children: b.label
|
|
8510
|
+
})
|
|
8511
|
+
]
|
|
8512
|
+
}),
|
|
8513
|
+
mode === "blink" && /* @__PURE__ */ jsx(ToggleGroup, {
|
|
8514
|
+
label: "Showing",
|
|
8515
|
+
options: [{
|
|
8516
|
+
value: "a",
|
|
8517
|
+
label: a.label
|
|
8518
|
+
}, {
|
|
8519
|
+
value: "b",
|
|
8520
|
+
label: b.label
|
|
8521
|
+
}],
|
|
8522
|
+
value: showing,
|
|
8523
|
+
onChange: (v) => setShowing(v),
|
|
8524
|
+
size: "sm",
|
|
8525
|
+
className: "justify-self-start"
|
|
8526
|
+
}),
|
|
8527
|
+
failed && /* @__PURE__ */ jsx("p", {
|
|
8528
|
+
role: "alert",
|
|
8529
|
+
className: "type-body-sm text-danger",
|
|
8530
|
+
children: missing
|
|
8531
|
+
}),
|
|
8532
|
+
body,
|
|
8533
|
+
/* @__PURE__ */ jsxs(Transport, {
|
|
8534
|
+
playing: wanted,
|
|
8535
|
+
onPlayPause: toggle,
|
|
8536
|
+
onStepBack: () => step(-1),
|
|
8537
|
+
onStepForward: () => step(1),
|
|
8538
|
+
children: [
|
|
8539
|
+
/* @__PURE__ */ jsx(TimeReadout, {
|
|
8540
|
+
time: sa.time,
|
|
8541
|
+
duration,
|
|
8542
|
+
precision: "frames",
|
|
8543
|
+
fps
|
|
8544
|
+
}),
|
|
8545
|
+
/* @__PURE__ */ jsx(SeekBar, {
|
|
8546
|
+
time: sa.time,
|
|
8547
|
+
duration,
|
|
8548
|
+
onSeek: seek,
|
|
8549
|
+
marks,
|
|
8550
|
+
onMarkPress: (m) => (pause(), seek(m.time)),
|
|
8551
|
+
buffered: sa.buffered,
|
|
8552
|
+
label: "Position",
|
|
8553
|
+
step: 1,
|
|
8554
|
+
precision: "frames",
|
|
8555
|
+
fps
|
|
8556
|
+
}),
|
|
8557
|
+
/* @__PURE__ */ jsx(RateChoice, {
|
|
8558
|
+
rate: sa.rate,
|
|
8559
|
+
onRateChange: setRate,
|
|
8560
|
+
rates
|
|
8561
|
+
}),
|
|
8562
|
+
audio !== "none" && /* @__PURE__ */ jsx(VolumeControl, {
|
|
8563
|
+
volume: muted ? 0 : volume,
|
|
8564
|
+
onVolumeChange: (v) => (setMuted(false), setVolume(v))
|
|
8565
|
+
})
|
|
8566
|
+
]
|
|
8567
|
+
}),
|
|
8568
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8569
|
+
className: "flex flex-wrap items-center gap-2",
|
|
8570
|
+
children: [
|
|
8571
|
+
/* @__PURE__ */ jsx(Button, {
|
|
8572
|
+
size: "sm",
|
|
8573
|
+
onPress: () => setPoint("start"),
|
|
8574
|
+
disabled: duration === null,
|
|
8575
|
+
children: "Loop starts here"
|
|
8576
|
+
}),
|
|
8577
|
+
/* @__PURE__ */ jsx(Button, {
|
|
8578
|
+
size: "sm",
|
|
8579
|
+
onPress: () => setPoint("end"),
|
|
8580
|
+
disabled: duration === null,
|
|
8581
|
+
children: "Loop ends here"
|
|
8582
|
+
}),
|
|
8583
|
+
/* @__PURE__ */ jsx(Button, {
|
|
8584
|
+
size: "sm",
|
|
8585
|
+
variant: "ghost",
|
|
8586
|
+
onPress: clearLoop,
|
|
8587
|
+
disabled: loop.start === null && loop.end === null,
|
|
8588
|
+
children: "Clear the loop"
|
|
8589
|
+
}),
|
|
8590
|
+
/* @__PURE__ */ jsx("span", {
|
|
8591
|
+
role: "status",
|
|
8592
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
8593
|
+
children: looping ? `Looping ${at(loop.start)} to ${at(loop.end)}` : loop.start !== null ? `Loop starts at ${at(loop.start)}` : loop.end !== null ? `Loop ends at ${at(loop.end)}` : "No loop"
|
|
8594
|
+
})
|
|
8595
|
+
]
|
|
8596
|
+
}),
|
|
8597
|
+
footer,
|
|
8598
|
+
keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
|
|
8599
|
+
]
|
|
8600
|
+
})
|
|
8601
|
+
});
|
|
8602
|
+
}
|
|
7826
8603
|
var tokens = (text) => text.split(/(\s+)/).filter((t) => t !== "");
|
|
7827
8604
|
var isSpace = (t) => /^\s+$/.test(t);
|
|
7828
8605
|
/** Marks the words that differ between two texts, or returns null when the pair is too long to compare. */
|
|
@@ -8012,7 +8789,7 @@ var COLUMNS = {
|
|
|
8012
8789
|
4: "sm:grid-cols-2 lg:grid-cols-4"
|
|
8013
8790
|
};
|
|
8014
8791
|
/** Many pictures in a grid, zoomed and panned together, and full screen. */
|
|
8015
|
-
function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys = true, className }) {
|
|
8792
|
+
function CompareGrid({ label, items, blind, missing, actions, columns = 3, regions, keys = true, className }) {
|
|
8016
8793
|
const { viewport, setViewport } = useViewport();
|
|
8017
8794
|
const [full, setFull] = React.useState(false);
|
|
8018
8795
|
const key = items.map((i) => i.media.src).join("|");
|
|
@@ -8020,13 +8797,20 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
8020
8797
|
const natural = items[0]?.media.size ?? (learned?.key === key ? learned.size : null);
|
|
8021
8798
|
const aspect = natural ? natural[0] / natural[1] : 3 / 2;
|
|
8022
8799
|
const first = React.useRef(null);
|
|
8023
|
-
const
|
|
8800
|
+
const rg = useRegions({
|
|
8801
|
+
regions,
|
|
8024
8802
|
viewport,
|
|
8025
8803
|
setViewport,
|
|
8026
8804
|
frame: first,
|
|
8805
|
+
reset: key
|
|
8806
|
+
});
|
|
8807
|
+
const zoom = useZoom({
|
|
8808
|
+
viewport,
|
|
8809
|
+
setViewport: rg.setViewport,
|
|
8810
|
+
frame: first,
|
|
8027
8811
|
natural
|
|
8028
8812
|
});
|
|
8029
|
-
const shortcuts = zoomShortcuts(zoom, full, setFull);
|
|
8813
|
+
const shortcuts = [...rg.shortcuts, ...zoomShortcuts(zoom, full, setFull)];
|
|
8030
8814
|
useHotkeys(shortcuts, { enabled: keys });
|
|
8031
8815
|
return /* @__PURE__ */ jsx(FullscreenFrame, {
|
|
8032
8816
|
label,
|
|
@@ -8053,6 +8837,7 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
8053
8837
|
})
|
|
8054
8838
|
]
|
|
8055
8839
|
}),
|
|
8840
|
+
/* @__PURE__ */ jsx(RegionChips, { state: rg }),
|
|
8056
8841
|
/* @__PURE__ */ jsx("div", {
|
|
8057
8842
|
className: cn("grid gap-3", COLUMNS[columns]),
|
|
8058
8843
|
children: items.map((c, i) => /* @__PURE__ */ jsxs("figure", {
|
|
@@ -8064,7 +8849,9 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
8064
8849
|
}),
|
|
8065
8850
|
/* @__PURE__ */ jsx(ViewportFrame, {
|
|
8066
8851
|
viewport,
|
|
8067
|
-
setViewport,
|
|
8852
|
+
setViewport: rg.setViewport,
|
|
8853
|
+
onBox: rg.add,
|
|
8854
|
+
outline: rg.peek,
|
|
8068
8855
|
aspect,
|
|
8069
8856
|
label: blind ? `Picture ${c.label}` : c.label,
|
|
8070
8857
|
ref: i === 0 ? first : void 0,
|
|
@@ -8072,6 +8859,7 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
8072
8859
|
c,
|
|
8073
8860
|
blind,
|
|
8074
8861
|
missing,
|
|
8862
|
+
pixelated: rg.active !== null,
|
|
8075
8863
|
onNatural: i === 0 ? (w, h) => setLearned({
|
|
8076
8864
|
key,
|
|
8077
8865
|
size: [w, h]
|
|
@@ -8737,6 +9525,6 @@ function SaveStatus({ state, onRetry, className }) {
|
|
|
8737
9525
|
]
|
|
8738
9526
|
});
|
|
8739
9527
|
}
|
|
8740
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, Workspace, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, diffWords, differences, fetchJson, fieldErrorsOf, format, formatChord, gainToVolume, geo, isReservedChord, isTypingTarget, labelOf, loudnessOf, matchGains, matchesAccept, matchesChord, measureLoudness, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, zoomAt };
|
|
9528
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, Workspace, actualPixelsScale, boxViewport, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, diffWords, differences, fetchJson, fieldErrorsOf, format, formatChord, gainToVolume, geo, isReservedChord, isTypingTarget, labelOf, loudnessOf, matchGains, matchesAccept, matchesChord, measureLoudness, noOverlap, parseChord, parseSort, readErrorBody, readPixels, regionShares, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, zoomAt };
|
|
8741
9529
|
|
|
8742
9530
|
//# sourceMappingURL=index.js.map
|