strata-react 1.0.29 → 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/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}`)),
@@ -6537,6 +6537,48 @@ 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
6541
6583
  var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
6542
6584
  /** A word for a picture's name on the page: its label, with its note unless blind. */
@@ -6553,7 +6595,7 @@ function Caption({ c, blind }) {
6553
6595
  });
6554
6596
  }
6555
6597
  /** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
6556
- function Picture({ c, blind, missing, onNatural, imgRef }) {
6598
+ function Picture({ c, blind, missing, onNatural, imgRef, pixelated }) {
6557
6599
  const [state, setState] = React.useState("loading");
6558
6600
  React.useEffect(() => setState("loading"), [c.media.src]);
6559
6601
  const alt = blind ? c.label : c.media.alt;
@@ -6577,6 +6619,7 @@ function Picture({ c, blind, missing, onNatural, imgRef }) {
6577
6619
  src: c.media.src,
6578
6620
  alt,
6579
6621
  draggable: false,
6622
+ style: pixelated ? { imageRendering: "pixelated" } : void 0,
6580
6623
  onLoad: (e) => {
6581
6624
  setState("ready");
6582
6625
  onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
@@ -6817,12 +6860,22 @@ function useViewport(initial = FIT) {
6817
6860
  }
6818
6861
  var PAN_STEP = 48;
6819
6862
  /** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
6820
- 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) {
6821
6864
  const ref = React.useRef(null);
6822
6865
  React.useImperativeHandle(forwardedRef, () => ref.current);
6823
6866
  const latest = React.useRef(viewport);
6824
6867
  latest.current = viewport;
6825
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
+ };
6826
6879
  const size = () => {
6827
6880
  const r = ref.current.getBoundingClientRect();
6828
6881
  return {
@@ -6888,6 +6941,17 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6888
6941
  tabIndex: 0,
6889
6942
  onKeyDown,
6890
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
+ }
6891
6955
  if (!zoomed || e.button !== 0) return;
6892
6956
  drag.current = {
6893
6957
  x: e.clientX,
@@ -6896,6 +6960,15 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6896
6960
  e.currentTarget.setPointerCapture?.(e.pointerId);
6897
6961
  },
6898
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
+ }
6899
6972
  if (!drag.current) return;
6900
6973
  const dx = e.clientX - drag.current.x;
6901
6974
  const dy = e.clientY - drag.current.y;
@@ -6909,8 +6982,18 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6909
6982
  y: latest.current.y + dy
6910
6983
  }, size()));
6911
6984
  },
6912
- onPointerUp: () => drag.current = null,
6913
- onPointerCancel: () => drag.current = null,
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
+ },
6914
6997
  onDoubleClick: (e) => {
6915
6998
  const v = latest.current;
6916
6999
  setViewport(v.scale > 1 ? FIT : zoomAt(v, 2, fromCentre(e.clientX, e.clientY), size()));
@@ -6945,6 +7028,26 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6945
7028
  children: cover.content
6946
7029
  })
6947
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
+ }),
6948
7051
  overlay != null && /* @__PURE__ */ jsx("div", {
6949
7052
  className: "pointer-events-none absolute inset-0",
6950
7053
  onPointerDown: (e) => e.stopPropagation(),
@@ -6955,6 +7058,133 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6955
7058
  ]
6956
7059
  });
6957
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
+ }
6958
7188
  // src/components/compare.tsx
6959
7189
  var MODE_LABEL$1 = {
6960
7190
  side: "Side by side",
@@ -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 zoom = useZoom({
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");
@@ -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
  };
@@ -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: [
@@ -7836,6 +8078,15 @@ var MODE_LABEL = {
7836
8078
  fade: "Fade",
7837
8079
  blink: "Blink"
7838
8080
  };
8081
+ var SLOW_RATES = [
8082
+ .1,
8083
+ .25,
8084
+ .5,
8085
+ 1,
8086
+ 1.25,
8087
+ 1.5,
8088
+ 2
8089
+ ];
7839
8090
  function useWidth(ref) {
7840
8091
  const [width, setWidth] = React.useState(0);
7841
8092
  React.useLayoutEffect(() => {
@@ -7851,7 +8102,7 @@ function useWidth(ref) {
7851
8102
  return width;
7852
8103
  }
7853
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. */
7854
- function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio = "a", pixelated = "zoomed", maxHeight, keys = true, extraShortcuts = [], footer, className }) {
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 }) {
7855
8106
  const refA = React.useRef(null);
7856
8107
  const refB = React.useRef(null);
7857
8108
  const sa = useMediaElement(refA);
@@ -7886,6 +8137,39 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
7886
8137
  sa.seek(t);
7887
8138
  sb.seek(t);
7888
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;
7889
8173
  const chosenRate = React.useRef(1);
7890
8174
  const setRate = (rate) => {
7891
8175
  chosenRate.current = rate;
@@ -7893,11 +8177,20 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
7893
8177
  sb.setRate(rate);
7894
8178
  };
7895
8179
  React.useEffect(() => {
7896
- if (sa.ended || sb.ended) {
7897
- setWanted(false);
7898
- refA.current?.pause();
7899
- refB.current?.pause();
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;
7900
8190
  }
8191
+ setWanted(false);
8192
+ A?.pause();
8193
+ B?.pause();
7901
8194
  }, [sa.ended, sb.ended]);
7902
8195
  React.useEffect(() => {
7903
8196
  if (!wanted) return;
@@ -7917,6 +8210,13 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
7917
8210
  A.play();
7918
8211
  B.play();
7919
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
+ }
7920
8220
  const drift = B.currentTime - A.currentTime;
7921
8221
  const one = 1 / fps;
7922
8222
  if (Math.abs(drift) > .3) B.currentTime = A.currentTime;
@@ -7954,14 +8254,22 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
7954
8254
  const natural = [a.media.width, a.media.height];
7955
8255
  const frameHeight = frameWidth / aspect;
7956
8256
  const sharpFor = (c) => {
8257
+ if (rg.active !== null) return true;
7957
8258
  if (pixelated !== "zoomed") return pixelated === "always";
7958
8259
  const drawn = Math.min(frameWidth, frameHeight * (c.media.width / c.media.height));
7959
8260
  return drawn > 0 && viewport.scale * drawn / c.media.width > 1;
7960
8261
  };
7961
- const zoom = useZoom({
8262
+ const rg = useRegions({
8263
+ regions,
7962
8264
  viewport,
7963
8265
  setViewport,
7964
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,
7965
8273
  natural
7966
8274
  });
7967
8275
  const flip = () => setShowing((s) => s === "a" ? "b" : "a");
@@ -7982,7 +8290,9 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
7982
8290
  });
7983
8291
  const frameProps = {
7984
8292
  viewport,
7985
- setViewport,
8293
+ setViewport: rg.setViewport,
8294
+ onBox: wanted ? void 0 : rg.add,
8295
+ outline: rg.peek,
7986
8296
  aspect,
7987
8297
  maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
7988
8298
  };
@@ -8016,14 +8326,58 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
8016
8326
  run: () => seek(sa.time + 1),
8017
8327
  repeat: true
8018
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
+ },
8019
8357
  ...audio === "none" ? [] : [{
8020
8358
  keys: ["m"],
8021
8359
  label: "Mute",
8022
8360
  run: () => setMuted((m) => !m)
8023
8361
  }],
8362
+ ...rg.shortcuts,
8024
8363
  ...zoomShortcuts(zoom, full, setFull)
8025
8364
  ];
8026
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
+ ];
8027
8381
  let body;
8028
8382
  if (mode === "side") body = /* @__PURE__ */ jsx("div", {
8029
8383
  className: "grid gap-3 sm:grid-cols-2",
@@ -8132,6 +8486,7 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
8132
8486
  })
8133
8487
  ]
8134
8488
  }),
8489
+ /* @__PURE__ */ jsx(RegionChips, { state: rg }),
8135
8490
  mode === "fade" && /* @__PURE__ */ jsxs("div", {
8136
8491
  className: "flex items-center gap-3",
8137
8492
  children: [
@@ -8178,15 +8533,21 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
8178
8533
  /* @__PURE__ */ jsxs(Transport, {
8179
8534
  playing: wanted,
8180
8535
  onPlayPause: toggle,
8536
+ onStepBack: () => step(-1),
8537
+ onStepForward: () => step(1),
8181
8538
  children: [
8182
8539
  /* @__PURE__ */ jsx(TimeReadout, {
8183
8540
  time: sa.time,
8184
- duration
8541
+ duration,
8542
+ precision: "frames",
8543
+ fps
8185
8544
  }),
8186
8545
  /* @__PURE__ */ jsx(SeekBar, {
8187
8546
  time: sa.time,
8188
8547
  duration,
8189
8548
  onSeek: seek,
8549
+ marks,
8550
+ onMarkPress: (m) => (pause(), seek(m.time)),
8190
8551
  buffered: sa.buffered,
8191
8552
  label: "Position",
8192
8553
  step: 1,
@@ -8195,7 +8556,8 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
8195
8556
  }),
8196
8557
  /* @__PURE__ */ jsx(RateChoice, {
8197
8558
  rate: sa.rate,
8198
- onRateChange: setRate
8559
+ onRateChange: setRate,
8560
+ rates
8199
8561
  }),
8200
8562
  audio !== "none" && /* @__PURE__ */ jsx(VolumeControl, {
8201
8563
  volume: muted ? 0 : volume,
@@ -8203,6 +8565,35 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio =
8203
8565
  })
8204
8566
  ]
8205
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
+ }),
8206
8597
  footer,
8207
8598
  keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
8208
8599
  ]
@@ -8398,7 +8789,7 @@ var COLUMNS = {
8398
8789
  4: "sm:grid-cols-2 lg:grid-cols-4"
8399
8790
  };
8400
8791
  /** Many pictures in a grid, zoomed and panned together, and full screen. */
8401
- 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 }) {
8402
8793
  const { viewport, setViewport } = useViewport();
8403
8794
  const [full, setFull] = React.useState(false);
8404
8795
  const key = items.map((i) => i.media.src).join("|");
@@ -8406,13 +8797,20 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
8406
8797
  const natural = items[0]?.media.size ?? (learned?.key === key ? learned.size : null);
8407
8798
  const aspect = natural ? natural[0] / natural[1] : 3 / 2;
8408
8799
  const first = React.useRef(null);
8409
- const zoom = useZoom({
8800
+ const rg = useRegions({
8801
+ regions,
8410
8802
  viewport,
8411
8803
  setViewport,
8412
8804
  frame: first,
8805
+ reset: key
8806
+ });
8807
+ const zoom = useZoom({
8808
+ viewport,
8809
+ setViewport: rg.setViewport,
8810
+ frame: first,
8413
8811
  natural
8414
8812
  });
8415
- const shortcuts = zoomShortcuts(zoom, full, setFull);
8813
+ const shortcuts = [...rg.shortcuts, ...zoomShortcuts(zoom, full, setFull)];
8416
8814
  useHotkeys(shortcuts, { enabled: keys });
8417
8815
  return /* @__PURE__ */ jsx(FullscreenFrame, {
8418
8816
  label,
@@ -8439,6 +8837,7 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
8439
8837
  })
8440
8838
  ]
8441
8839
  }),
8840
+ /* @__PURE__ */ jsx(RegionChips, { state: rg }),
8442
8841
  /* @__PURE__ */ jsx("div", {
8443
8842
  className: cn("grid gap-3", COLUMNS[columns]),
8444
8843
  children: items.map((c, i) => /* @__PURE__ */ jsxs("figure", {
@@ -8450,7 +8849,9 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
8450
8849
  }),
8451
8850
  /* @__PURE__ */ jsx(ViewportFrame, {
8452
8851
  viewport,
8453
- setViewport,
8852
+ setViewport: rg.setViewport,
8853
+ onBox: rg.add,
8854
+ outline: rg.peek,
8454
8855
  aspect,
8455
8856
  label: blind ? `Picture ${c.label}` : c.label,
8456
8857
  ref: i === 0 ? first : void 0,
@@ -8458,6 +8859,7 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
8458
8859
  c,
8459
8860
  blind,
8460
8861
  missing,
8862
+ pixelated: rg.active !== null,
8461
8863
  onNatural: i === 0 ? (w, h) => setLearned({
8462
8864
  key,
8463
8865
  size: [w, h]
@@ -9123,6 +9525,6 @@ function SaveStatus({ state, onRetry, className }) {
9123
9525
  ]
9124
9526
  });
9125
9527
  }
9126
- 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, 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 };
9127
9529
 
9128
9530
  //# sourceMappingURL=index.js.map