strata-react 1.0.26 → 1.0.29
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-audio.d.ts +30 -0
- package/dist/components/compare-parts.d.ts +2 -1
- package/dist/components/compare-text.d.ts +32 -0
- package/dist/components/compare-video.d.ts +33 -0
- package/dist/components/compare.d.ts +25 -1
- package/dist/components/pair-vote.d.ts +22 -10
- package/dist/components/viewport.d.ts +4 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +972 -18
- package/dist/index.js.map +1 -1
- package/dist/lib/loudness.d.ts +18 -0
- package/dist/lib/text-diff.d.ts +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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));
|
|
@@ -6538,6 +6538,7 @@ function viewportTransform(v) {
|
|
|
6538
6538
|
return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
|
|
6539
6539
|
}
|
|
6540
6540
|
// src/components/compare-parts.tsx
|
|
6541
|
+
var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
|
|
6541
6542
|
/** A word for a picture's name on the page: its label, with its note unless blind. */
|
|
6542
6543
|
function Caption({ c, blind }) {
|
|
6543
6544
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -6816,7 +6817,7 @@ function useViewport(initial = FIT) {
|
|
|
6816
6817
|
}
|
|
6817
6818
|
var PAN_STEP = 48;
|
|
6818
6819
|
/** 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, className }, forwardedRef) {
|
|
6820
|
+
var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, viewport, setViewport, children, cover, overlay, maxHeight, className }, forwardedRef) {
|
|
6820
6821
|
const ref = React.useRef(null);
|
|
6821
6822
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6822
6823
|
const latest = React.useRef(viewport);
|
|
@@ -6916,6 +6917,10 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6916
6917
|
},
|
|
6917
6918
|
style: {
|
|
6918
6919
|
aspectRatio: String(aspect),
|
|
6920
|
+
...maxHeight ? {
|
|
6921
|
+
maxWidth: `calc(${maxHeight} * ${aspect})`,
|
|
6922
|
+
marginInline: "auto"
|
|
6923
|
+
} : {},
|
|
6919
6924
|
touchAction: zoomed ? "none" : "pan-y"
|
|
6920
6925
|
},
|
|
6921
6926
|
className: cn("relative w-full overflow-hidden rounded-surface border border-border bg-muted select-none", zoomed ? "cursor-grab active:cursor-grabbing" : "cursor-zoom-in", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", className),
|
|
@@ -6951,7 +6956,7 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
|
|
|
6951
6956
|
});
|
|
6952
6957
|
});
|
|
6953
6958
|
// src/components/compare.tsx
|
|
6954
|
-
var MODE_LABEL = {
|
|
6959
|
+
var MODE_LABEL$1 = {
|
|
6955
6960
|
side: "Side by side",
|
|
6956
6961
|
swipe: "Swipe",
|
|
6957
6962
|
fade: "Fade",
|
|
@@ -6966,7 +6971,7 @@ var ALL_MODES = [
|
|
|
6966
6971
|
"difference"
|
|
6967
6972
|
];
|
|
6968
6973
|
/** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
|
|
6969
|
-
function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, keys = true, extraShortcuts = [], footer, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
|
|
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 }) {
|
|
6970
6975
|
const { viewport, setViewport } = useViewport();
|
|
6971
6976
|
const [full, setFull] = React.useState(false);
|
|
6972
6977
|
const pairKey = `${a.media.src}|${b.media.src}`;
|
|
@@ -6994,7 +6999,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
6994
6999
|
...extraShortcuts,
|
|
6995
7000
|
...offered.map((m, i) => ({
|
|
6996
7001
|
keys: [String(i + 1)],
|
|
6997
|
-
label: MODE_LABEL[m],
|
|
7002
|
+
label: MODE_LABEL$1[m],
|
|
6998
7003
|
run: () => onModeChange(m)
|
|
6999
7004
|
})),
|
|
7000
7005
|
{
|
|
@@ -7020,7 +7025,8 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7020
7025
|
const frameProps = {
|
|
7021
7026
|
viewport,
|
|
7022
7027
|
setViewport,
|
|
7023
|
-
aspect
|
|
7028
|
+
aspect,
|
|
7029
|
+
maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
|
|
7024
7030
|
};
|
|
7025
7031
|
let body;
|
|
7026
7032
|
if (mode === "side") body = /* @__PURE__ */ jsx("div", {
|
|
@@ -7161,7 +7167,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7161
7167
|
label: "View",
|
|
7162
7168
|
options: offered.map((m) => ({
|
|
7163
7169
|
value: m,
|
|
7164
|
-
label: MODE_LABEL[m]
|
|
7170
|
+
label: MODE_LABEL$1[m]
|
|
7165
7171
|
})),
|
|
7166
7172
|
value: mode,
|
|
7167
7173
|
onChange: (v) => onModeChange(v),
|
|
@@ -7288,8 +7294,30 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
|
|
|
7288
7294
|
});
|
|
7289
7295
|
}
|
|
7290
7296
|
// src/components/pair-vote.tsx
|
|
7291
|
-
/** A blind pairwise judgment
|
|
7292
|
-
function PairVote({ pair, skeleton, empty, onAnswer, pending, progress, flagReasons, preload, last, words
|
|
7297
|
+
/** A blind pairwise judgment of two pictures: `Compare`, answer keys in its legend, and a vote bar that never leans on either side. */
|
|
7298
|
+
function PairVote({ pair, skeleton, empty, onAnswer, pending, progress, flagReasons, preload, last, words, ...compare }) {
|
|
7299
|
+
return /* @__PURE__ */ jsx(PairJudge, {
|
|
7300
|
+
pair,
|
|
7301
|
+
skeleton,
|
|
7302
|
+
empty,
|
|
7303
|
+
onAnswer,
|
|
7304
|
+
pending,
|
|
7305
|
+
progress,
|
|
7306
|
+
flagReasons,
|
|
7307
|
+
preload,
|
|
7308
|
+
last,
|
|
7309
|
+
words,
|
|
7310
|
+
view: (slot, p) => /* @__PURE__ */ jsx(Compare, {
|
|
7311
|
+
...compare,
|
|
7312
|
+
label: p.label,
|
|
7313
|
+
a: p.a,
|
|
7314
|
+
b: p.b,
|
|
7315
|
+
...slot
|
|
7316
|
+
})
|
|
7317
|
+
});
|
|
7318
|
+
}
|
|
7319
|
+
/** A blind pairwise judgment of anything: the answer keys, vote bar, pending, flag menu, progress, preload and Undo around a `view` that draws the pair (`CompareAudio`, `CompareText`, your own). */
|
|
7320
|
+
function PairJudge({ pair, skeleton, empty, onAnswer, pending, progress, flagReasons, preload, last, words = {}, view }) {
|
|
7293
7321
|
React.useEffect(() => {
|
|
7294
7322
|
for (const src of preload ?? []) new Image().src = src;
|
|
7295
7323
|
}, [preload]);
|
|
@@ -7320,7 +7348,7 @@ function PairVote({ pair, skeleton, empty, onAnswer, pending, progress, flagReas
|
|
|
7320
7348
|
flagReasons,
|
|
7321
7349
|
words: w,
|
|
7322
7350
|
last,
|
|
7323
|
-
|
|
7351
|
+
view
|
|
7324
7352
|
})
|
|
7325
7353
|
}),
|
|
7326
7354
|
last && !(pair.status === "ready" && pair.data) && /* @__PURE__ */ jsx(LastAnswer, { last })
|
|
@@ -7343,7 +7371,7 @@ function LastAnswer({ last }) {
|
|
|
7343
7371
|
]
|
|
7344
7372
|
});
|
|
7345
7373
|
}
|
|
7346
|
-
function Judged({ pair, onAnswer, pending, flagReasons, words, last,
|
|
7374
|
+
function Judged({ pair, onAnswer, pending, flagReasons, words, last, view }) {
|
|
7347
7375
|
const { a, b } = pair;
|
|
7348
7376
|
const answer = (x) => !pending && onAnswer(x);
|
|
7349
7377
|
const shortcuts = [
|
|
@@ -7428,13 +7456,939 @@ function Judged({ pair, onAnswer, pending, flagReasons, words, last, compare })
|
|
|
7428
7456
|
last && /* @__PURE__ */ jsx(LastAnswer, { last })
|
|
7429
7457
|
]
|
|
7430
7458
|
});
|
|
7431
|
-
return /* @__PURE__ */ jsx(
|
|
7432
|
-
...compare,
|
|
7433
|
-
label: pair.label,
|
|
7434
|
-
a,
|
|
7435
|
-
b,
|
|
7459
|
+
return /* @__PURE__ */ jsx(Fragment, { children: view({
|
|
7436
7460
|
extraShortcuts: shortcuts,
|
|
7437
7461
|
footer
|
|
7462
|
+
}, pair) });
|
|
7463
|
+
}
|
|
7464
|
+
var db$1 = (x) => x > 0 ? 20 * Math.log10(x) : -Infinity;
|
|
7465
|
+
/** The RMS and peak of channel data (-1 to 1), over all channels together. */
|
|
7466
|
+
function loudnessOf(channels) {
|
|
7467
|
+
let sum = 0;
|
|
7468
|
+
let count = 0;
|
|
7469
|
+
let peak = 0;
|
|
7470
|
+
for (const c of channels) for (let i = 0; i < c.length; i++) {
|
|
7471
|
+
const v = c[i];
|
|
7472
|
+
sum += v * v;
|
|
7473
|
+
const a = Math.abs(v);
|
|
7474
|
+
if (a > peak) peak = a;
|
|
7475
|
+
}
|
|
7476
|
+
count = channels.reduce((n, c) => n + c.length, 0);
|
|
7477
|
+
return {
|
|
7478
|
+
rms: db$1(Math.sqrt(count ? sum / count : 0)),
|
|
7479
|
+
peak: db$1(peak)
|
|
7480
|
+
};
|
|
7481
|
+
}
|
|
7482
|
+
/** How much to turn each of two clips down (in dB, zero or less) so they play at the same RMS: the louder is lowered to the quieter. */
|
|
7483
|
+
function matchGains(a, b) {
|
|
7484
|
+
if (!Number.isFinite(a.rms) || !Number.isFinite(b.rms)) return {
|
|
7485
|
+
a: 0,
|
|
7486
|
+
b: 0
|
|
7487
|
+
};
|
|
7488
|
+
const diff = a.rms - b.rms;
|
|
7489
|
+
return diff > 0 ? {
|
|
7490
|
+
a: -diff,
|
|
7491
|
+
b: 0
|
|
7492
|
+
} : {
|
|
7493
|
+
a: 0,
|
|
7494
|
+
b: diff
|
|
7495
|
+
};
|
|
7496
|
+
}
|
|
7497
|
+
/** dB to a media element's volume (0 to 1). */
|
|
7498
|
+
var gainToVolume = (decibels) => Math.min(1, Math.max(0, 10 ** (decibels / 20)));
|
|
7499
|
+
/** Fetches and decodes a clip and measures it. Needs the Web Audio API; reads at most `MAX_SECONDS`. */
|
|
7500
|
+
async function measureLoudness(src) {
|
|
7501
|
+
const response = await fetch(src);
|
|
7502
|
+
if (!response.ok) throw new Error(`Could not read ${src}: ${response.status}`);
|
|
7503
|
+
const context = new (window.AudioContext ?? window.webkitAudioContext)();
|
|
7504
|
+
try {
|
|
7505
|
+
const buffer = await context.decodeAudioData(await response.arrayBuffer());
|
|
7506
|
+
const frames = Math.min(buffer.length, Math.floor(buffer.sampleRate * 120));
|
|
7507
|
+
return loudnessOf(Array.from({ length: buffer.numberOfChannels }, (_, c) => buffer.getChannelData(c).subarray(0, frames)));
|
|
7508
|
+
} finally {
|
|
7509
|
+
context.close();
|
|
7510
|
+
}
|
|
7511
|
+
}
|
|
7512
|
+
// src/components/compare-audio.tsx
|
|
7513
|
+
var db = (x) => `${Math.abs(x).toFixed(1)} dB`;
|
|
7514
|
+
/** Two clips to judge by ear: one transport, a switch that keeps the playhead, a loop, and matched levels. */
|
|
7515
|
+
function CompareAudio({ label, a, b, blind, missing, levelMatch = true, align = "auto", measure = measureLoudness, keys = true, extraShortcuts = [], footer, className }) {
|
|
7516
|
+
const refA = React.useRef(null);
|
|
7517
|
+
const refB = React.useRef(null);
|
|
7518
|
+
const sa = useMediaElement(refA);
|
|
7519
|
+
const sb = useMediaElement(refB);
|
|
7520
|
+
const [showing, setShowing] = React.useState("a");
|
|
7521
|
+
const [volume, setVolume] = React.useState(100);
|
|
7522
|
+
const [matching, setMatching] = React.useState(levelMatch);
|
|
7523
|
+
const [loop, setLoop] = React.useState({
|
|
7524
|
+
start: null,
|
|
7525
|
+
end: null
|
|
7526
|
+
});
|
|
7527
|
+
const [levels, setLevels] = React.useState(null);
|
|
7528
|
+
const active = showing === "a" ? sa : sb;
|
|
7529
|
+
const keyOf = `${a.media.src}|${b.media.src}`;
|
|
7530
|
+
React.useEffect(() => {
|
|
7531
|
+
if (!matching) return;
|
|
7532
|
+
let live = true;
|
|
7533
|
+
setLevels(null);
|
|
7534
|
+
Promise.all([measure(a.media.src), measure(b.media.src)]).then(([la, lb]) => live && setLevels({
|
|
7535
|
+
key: keyOf,
|
|
7536
|
+
a: la,
|
|
7537
|
+
b: lb
|
|
7538
|
+
}), () => live && setLevels("failed"));
|
|
7539
|
+
return () => {
|
|
7540
|
+
live = false;
|
|
7541
|
+
};
|
|
7542
|
+
}, [
|
|
7543
|
+
matching,
|
|
7544
|
+
keyOf,
|
|
7545
|
+
a.media.src,
|
|
7546
|
+
b.media.src,
|
|
7547
|
+
measure
|
|
7548
|
+
]);
|
|
7549
|
+
const gains = matching && levels && levels !== "failed" && levels.key === keyOf ? matchGains(levels.a, levels.b) : {
|
|
7550
|
+
a: 0,
|
|
7551
|
+
b: 0
|
|
7552
|
+
};
|
|
7553
|
+
React.useEffect(() => {
|
|
7554
|
+
if (refA.current) refA.current.volume = volume / 100 * gainToVolume(gains.a);
|
|
7555
|
+
if (refB.current) refB.current.volume = volume / 100 * gainToVolume(gains.b);
|
|
7556
|
+
}, [
|
|
7557
|
+
volume,
|
|
7558
|
+
gains.a,
|
|
7559
|
+
gains.b
|
|
7560
|
+
]);
|
|
7561
|
+
const carry = (time, from, to) => {
|
|
7562
|
+
if (!(from.duration && to.duration) || align === "time") return time;
|
|
7563
|
+
const differ = Math.abs(from.duration - to.duration) / Math.max(from.duration, to.duration) > .02;
|
|
7564
|
+
return align === "proportion" || differ ? time / from.duration * to.duration : time;
|
|
7565
|
+
};
|
|
7566
|
+
const hear = (side) => {
|
|
7567
|
+
if (side === showing) return;
|
|
7568
|
+
const from = showing === "a" ? sa : sb;
|
|
7569
|
+
const to = side === "a" ? sa : sb;
|
|
7570
|
+
const wasPlaying = from.playing;
|
|
7571
|
+
from.pause();
|
|
7572
|
+
to.seek(carry(from.time, from, to));
|
|
7573
|
+
if (from.duration && to.duration) {
|
|
7574
|
+
const move = (share) => share === null ? null : Math.min(1, carry(share * from.duration, from, to) / to.duration);
|
|
7575
|
+
setLoop((l) => ({
|
|
7576
|
+
start: move(l.start),
|
|
7577
|
+
end: move(l.end)
|
|
7578
|
+
}));
|
|
7579
|
+
}
|
|
7580
|
+
if (wasPlaying) to.play();
|
|
7581
|
+
setShowing(side);
|
|
7582
|
+
};
|
|
7583
|
+
const flip = () => hear(showing === "a" ? "b" : "a");
|
|
7584
|
+
const duration = active.duration ?? 0;
|
|
7585
|
+
const at = (share) => share === null || !duration ? null : share * duration;
|
|
7586
|
+
const setPoint = (point) => {
|
|
7587
|
+
if (!duration) return;
|
|
7588
|
+
const share = active.time / duration;
|
|
7589
|
+
setLoop((l) => {
|
|
7590
|
+
const next = {
|
|
7591
|
+
...l,
|
|
7592
|
+
[point]: share
|
|
7593
|
+
};
|
|
7594
|
+
if (next.start !== null && next.end !== null && next.start >= next.end) return point === "start" ? {
|
|
7595
|
+
start: share,
|
|
7596
|
+
end: null
|
|
7597
|
+
} : {
|
|
7598
|
+
start: null,
|
|
7599
|
+
end: share
|
|
7600
|
+
};
|
|
7601
|
+
return next;
|
|
7602
|
+
});
|
|
7603
|
+
};
|
|
7604
|
+
const clearLoop = () => setLoop({
|
|
7605
|
+
start: null,
|
|
7606
|
+
end: null
|
|
7607
|
+
});
|
|
7608
|
+
const looping = loop.start !== null && loop.end !== null;
|
|
7609
|
+
const enforce = React.useCallback(() => {
|
|
7610
|
+
const e = (showing === "a" ? refA : refB).current;
|
|
7611
|
+
if (!e || !looping || !Number.isFinite(e.duration)) return;
|
|
7612
|
+
if (e.currentTime >= loop.end * e.duration || e.currentTime < loop.start * e.duration - .05) e.currentTime = loop.start * e.duration;
|
|
7613
|
+
}, [
|
|
7614
|
+
showing,
|
|
7615
|
+
looping,
|
|
7616
|
+
loop.start,
|
|
7617
|
+
loop.end
|
|
7618
|
+
]);
|
|
7619
|
+
React.useEffect(() => {
|
|
7620
|
+
if (looping && active.playing && active.time >= loop.end * duration) enforce();
|
|
7621
|
+
}, [
|
|
7622
|
+
active.time,
|
|
7623
|
+
active.playing,
|
|
7624
|
+
looping,
|
|
7625
|
+
loop.end,
|
|
7626
|
+
duration,
|
|
7627
|
+
enforce
|
|
7628
|
+
]);
|
|
7629
|
+
React.useEffect(() => {
|
|
7630
|
+
if (!looping || !active.playing) return;
|
|
7631
|
+
let frame = requestAnimationFrame(function tick() {
|
|
7632
|
+
enforce();
|
|
7633
|
+
frame = requestAnimationFrame(tick);
|
|
7634
|
+
});
|
|
7635
|
+
return () => cancelAnimationFrame(frame);
|
|
7636
|
+
}, [
|
|
7637
|
+
looping,
|
|
7638
|
+
active.playing,
|
|
7639
|
+
enforce
|
|
7640
|
+
]);
|
|
7641
|
+
const shortcuts = [
|
|
7642
|
+
...extraShortcuts,
|
|
7643
|
+
{
|
|
7644
|
+
keys: ["1"],
|
|
7645
|
+
label: `Hear ${a.label}`,
|
|
7646
|
+
run: () => hear("a")
|
|
7647
|
+
},
|
|
7648
|
+
{
|
|
7649
|
+
keys: ["2"],
|
|
7650
|
+
label: `Hear ${b.label}`,
|
|
7651
|
+
run: () => hear("b")
|
|
7652
|
+
},
|
|
7653
|
+
{
|
|
7654
|
+
keys: ["x"],
|
|
7655
|
+
label: `Flip ${a.label} and ${b.label}`,
|
|
7656
|
+
run: flip
|
|
7657
|
+
},
|
|
7658
|
+
{
|
|
7659
|
+
keys: [" ", "k"],
|
|
7660
|
+
label: "Play or pause",
|
|
7661
|
+
run: active.toggle
|
|
7662
|
+
},
|
|
7663
|
+
{
|
|
7664
|
+
keys: ["j"],
|
|
7665
|
+
label: "Back 1 s",
|
|
7666
|
+
run: () => active.seek(Math.max(0, active.time - 1)),
|
|
7667
|
+
repeat: true
|
|
7668
|
+
},
|
|
7669
|
+
{
|
|
7670
|
+
keys: ["l"],
|
|
7671
|
+
label: "Forward 1 s",
|
|
7672
|
+
run: () => active.seek(active.time + 1),
|
|
7673
|
+
repeat: true
|
|
7674
|
+
},
|
|
7675
|
+
{
|
|
7676
|
+
keys: ["i"],
|
|
7677
|
+
label: "Loop starts here",
|
|
7678
|
+
run: () => setPoint("start")
|
|
7679
|
+
},
|
|
7680
|
+
{
|
|
7681
|
+
keys: ["o"],
|
|
7682
|
+
label: "Loop ends here",
|
|
7683
|
+
run: () => setPoint("end")
|
|
7684
|
+
},
|
|
7685
|
+
{
|
|
7686
|
+
keys: ["c"],
|
|
7687
|
+
label: "Clear the loop",
|
|
7688
|
+
run: clearLoop,
|
|
7689
|
+
disabled: loop.start === null && loop.end === null
|
|
7690
|
+
}
|
|
7691
|
+
];
|
|
7692
|
+
useHotkeys(shortcuts, { enabled: keys });
|
|
7693
|
+
const failed = sa.error || sb.error;
|
|
7694
|
+
const marks = [...loop.start !== null && at(loop.start) !== null ? [{
|
|
7695
|
+
time: at(loop.start),
|
|
7696
|
+
label: "Loop start"
|
|
7697
|
+
}] : [], ...loop.end !== null && at(loop.end) !== null ? [{
|
|
7698
|
+
time: at(loop.end),
|
|
7699
|
+
label: "Loop end"
|
|
7700
|
+
}] : []];
|
|
7701
|
+
const range = (share) => share === null || !duration ? format.missing : format.timecode(share * duration, { precision: "seconds" });
|
|
7702
|
+
let levelLine = null;
|
|
7703
|
+
if (matching) {
|
|
7704
|
+
if (levels === "failed") levelLine = "Could not measure the levels, so the clips are not matched.";
|
|
7705
|
+
else if (!levels || levels.key !== keyOf) levelLine = "Measuring levels…";
|
|
7706
|
+
else if (gains.a === 0 && gains.b === 0) levelLine = "Both clips are at the same level.";
|
|
7707
|
+
else {
|
|
7708
|
+
const [loud, quiet, cut] = gains.a < 0 ? [
|
|
7709
|
+
a.label,
|
|
7710
|
+
b.label,
|
|
7711
|
+
gains.a
|
|
7712
|
+
] : [
|
|
7713
|
+
b.label,
|
|
7714
|
+
a.label,
|
|
7715
|
+
gains.b
|
|
7716
|
+
];
|
|
7717
|
+
levelLine = `${loud} is louder than ${quiet}, so it is turned down by ${db(cut)}.`;
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7720
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
7721
|
+
"aria-label": label,
|
|
7722
|
+
className: cn("grid gap-3", className),
|
|
7723
|
+
children: [
|
|
7724
|
+
/* @__PURE__ */ jsx("audio", {
|
|
7725
|
+
ref: refA,
|
|
7726
|
+
src: a.media.src,
|
|
7727
|
+
preload: "auto",
|
|
7728
|
+
"aria-label": `Clip ${a.label}`
|
|
7729
|
+
}),
|
|
7730
|
+
/* @__PURE__ */ jsx("audio", {
|
|
7731
|
+
ref: refB,
|
|
7732
|
+
src: b.media.src,
|
|
7733
|
+
preload: "auto",
|
|
7734
|
+
"aria-label": `Clip ${b.label}`
|
|
7735
|
+
}),
|
|
7736
|
+
/* @__PURE__ */ jsxs("div", {
|
|
7737
|
+
className: "flex flex-wrap items-center gap-3",
|
|
7738
|
+
children: [/* @__PURE__ */ jsx(ToggleGroup, {
|
|
7739
|
+
label: "Listen to",
|
|
7740
|
+
options: [{
|
|
7741
|
+
value: "a",
|
|
7742
|
+
label: a.label
|
|
7743
|
+
}, {
|
|
7744
|
+
value: "b",
|
|
7745
|
+
label: b.label
|
|
7746
|
+
}],
|
|
7747
|
+
value: showing,
|
|
7748
|
+
onChange: (v) => hear(v)
|
|
7749
|
+
}), /* @__PURE__ */ jsx(Switch, {
|
|
7750
|
+
label: "Match loudness",
|
|
7751
|
+
on: matching,
|
|
7752
|
+
onChange: setMatching
|
|
7753
|
+
})]
|
|
7754
|
+
}),
|
|
7755
|
+
!blind && (a.note || b.note) && /* @__PURE__ */ jsx("p", {
|
|
7756
|
+
className: "type-caption text-muted-foreground",
|
|
7757
|
+
children: [a, b].filter((c) => c.note).map((c) => `${c.label}: ${c.note}`).join(" · ")
|
|
7758
|
+
}),
|
|
7759
|
+
failed && /* @__PURE__ */ jsx("p", {
|
|
7760
|
+
role: "alert",
|
|
7761
|
+
className: "type-body-sm text-danger",
|
|
7762
|
+
children: missing
|
|
7763
|
+
}),
|
|
7764
|
+
/* @__PURE__ */ jsxs(Transport, {
|
|
7765
|
+
playing: active.playing,
|
|
7766
|
+
onPlayPause: active.toggle,
|
|
7767
|
+
children: [
|
|
7768
|
+
/* @__PURE__ */ jsx(TimeReadout, {
|
|
7769
|
+
time: active.time,
|
|
7770
|
+
duration: active.duration
|
|
7771
|
+
}),
|
|
7772
|
+
/* @__PURE__ */ jsx(SeekBar, {
|
|
7773
|
+
time: active.time,
|
|
7774
|
+
duration: active.duration,
|
|
7775
|
+
onSeek: active.seek,
|
|
7776
|
+
marks,
|
|
7777
|
+
buffered: active.buffered,
|
|
7778
|
+
label: `Position in ${(showing === "a" ? a : b).label}`,
|
|
7779
|
+
step: 1
|
|
7780
|
+
}),
|
|
7781
|
+
/* @__PURE__ */ jsx(VolumeControl, {
|
|
7782
|
+
volume,
|
|
7783
|
+
onVolumeChange: setVolume
|
|
7784
|
+
})
|
|
7785
|
+
]
|
|
7786
|
+
}),
|
|
7787
|
+
/* @__PURE__ */ jsxs("div", {
|
|
7788
|
+
className: "flex flex-wrap items-center gap-2",
|
|
7789
|
+
children: [
|
|
7790
|
+
/* @__PURE__ */ jsx(Button, {
|
|
7791
|
+
size: "sm",
|
|
7792
|
+
onPress: () => setPoint("start"),
|
|
7793
|
+
disabled: !duration,
|
|
7794
|
+
children: "Loop starts here"
|
|
7795
|
+
}),
|
|
7796
|
+
/* @__PURE__ */ jsx(Button, {
|
|
7797
|
+
size: "sm",
|
|
7798
|
+
onPress: () => setPoint("end"),
|
|
7799
|
+
disabled: !duration,
|
|
7800
|
+
children: "Loop ends here"
|
|
7801
|
+
}),
|
|
7802
|
+
/* @__PURE__ */ jsx(Button, {
|
|
7803
|
+
size: "sm",
|
|
7804
|
+
variant: "ghost",
|
|
7805
|
+
onPress: clearLoop,
|
|
7806
|
+
disabled: loop.start === null && loop.end === null,
|
|
7807
|
+
children: "Clear the loop"
|
|
7808
|
+
}),
|
|
7809
|
+
/* @__PURE__ */ jsx("span", {
|
|
7810
|
+
role: "status",
|
|
7811
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
7812
|
+
children: looping ? `Looping ${range(loop.start)} to ${range(loop.end)}` : loop.start !== null ? `Loop starts at ${range(loop.start)}` : loop.end !== null ? `Loop ends at ${range(loop.end)}` : "No loop"
|
|
7813
|
+
})
|
|
7814
|
+
]
|
|
7815
|
+
}),
|
|
7816
|
+
levelLine && /* @__PURE__ */ jsx("p", {
|
|
7817
|
+
role: "status",
|
|
7818
|
+
className: "type-body-sm text-muted-foreground",
|
|
7819
|
+
children: levelLine
|
|
7820
|
+
}),
|
|
7821
|
+
footer,
|
|
7822
|
+
keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
|
|
7823
|
+
]
|
|
7824
|
+
});
|
|
7825
|
+
}
|
|
7826
|
+
// src/components/compare-video.tsx
|
|
7827
|
+
var MODES = [
|
|
7828
|
+
"side",
|
|
7829
|
+
"swipe",
|
|
7830
|
+
"fade",
|
|
7831
|
+
"blink"
|
|
7832
|
+
];
|
|
7833
|
+
var MODE_LABEL = {
|
|
7834
|
+
side: "Side by side",
|
|
7835
|
+
swipe: "Swipe",
|
|
7836
|
+
fade: "Fade",
|
|
7837
|
+
blink: "Blink"
|
|
7838
|
+
};
|
|
7839
|
+
function useWidth(ref) {
|
|
7840
|
+
const [width, setWidth] = React.useState(0);
|
|
7841
|
+
React.useLayoutEffect(() => {
|
|
7842
|
+
const el = ref.current;
|
|
7843
|
+
if (!el) return;
|
|
7844
|
+
const read = () => setWidth(el.getBoundingClientRect().width);
|
|
7845
|
+
read();
|
|
7846
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
7847
|
+
const ro = new ResizeObserver(read);
|
|
7848
|
+
ro.observe(el);
|
|
7849
|
+
return () => ro.disconnect();
|
|
7850
|
+
});
|
|
7851
|
+
return width;
|
|
7852
|
+
}
|
|
7853
|
+
/** 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 }) {
|
|
7855
|
+
const refA = React.useRef(null);
|
|
7856
|
+
const refB = React.useRef(null);
|
|
7857
|
+
const sa = useMediaElement(refA);
|
|
7858
|
+
const sb = useMediaElement(refB);
|
|
7859
|
+
const { viewport, setViewport } = useViewport();
|
|
7860
|
+
const [full, setFull] = React.useState(false);
|
|
7861
|
+
const [divider, setDivider] = React.useState(50);
|
|
7862
|
+
const [blend, setBlend] = React.useState(50);
|
|
7863
|
+
const [showing, setShowing] = React.useState("a");
|
|
7864
|
+
const [volume, setVolume] = React.useState(100);
|
|
7865
|
+
const [muted, setMuted] = React.useState(false);
|
|
7866
|
+
const [wanted, setWanted] = React.useState(false);
|
|
7867
|
+
const frameRef = React.useRef(null);
|
|
7868
|
+
const frameWidth = useWidth(frameRef);
|
|
7869
|
+
const fps = a.media.fps ?? 30;
|
|
7870
|
+
const known = [sa.duration, sb.duration].filter((d) => d !== null);
|
|
7871
|
+
const duration = known.length ? Math.min(...known) : null;
|
|
7872
|
+
const failed = sa.error || sb.error;
|
|
7873
|
+
const play = () => {
|
|
7874
|
+
setWanted(true);
|
|
7875
|
+
sa.play();
|
|
7876
|
+
sb.play();
|
|
7877
|
+
};
|
|
7878
|
+
const pause = () => {
|
|
7879
|
+
setWanted(false);
|
|
7880
|
+
sa.pause();
|
|
7881
|
+
sb.pause();
|
|
7882
|
+
};
|
|
7883
|
+
const toggle = () => wanted ? pause() : play();
|
|
7884
|
+
const seek = (time) => {
|
|
7885
|
+
const t = Math.max(0, duration === null ? time : Math.min(time, duration));
|
|
7886
|
+
sa.seek(t);
|
|
7887
|
+
sb.seek(t);
|
|
7888
|
+
};
|
|
7889
|
+
const chosenRate = React.useRef(1);
|
|
7890
|
+
const setRate = (rate) => {
|
|
7891
|
+
chosenRate.current = rate;
|
|
7892
|
+
sa.setRate(rate);
|
|
7893
|
+
sb.setRate(rate);
|
|
7894
|
+
};
|
|
7895
|
+
React.useEffect(() => {
|
|
7896
|
+
if (sa.ended || sb.ended) {
|
|
7897
|
+
setWanted(false);
|
|
7898
|
+
refA.current?.pause();
|
|
7899
|
+
refB.current?.pause();
|
|
7900
|
+
}
|
|
7901
|
+
}, [sa.ended, sb.ended]);
|
|
7902
|
+
React.useEffect(() => {
|
|
7903
|
+
if (!wanted) return;
|
|
7904
|
+
let held = false;
|
|
7905
|
+
let frame = requestAnimationFrame(function tick() {
|
|
7906
|
+
const A = refA.current;
|
|
7907
|
+
const B = refB.current;
|
|
7908
|
+
if (A && B && !A.ended && !B.ended) {
|
|
7909
|
+
if (!(A.readyState >= 3 && B.readyState >= 3)) {
|
|
7910
|
+
if (!held) {
|
|
7911
|
+
held = true;
|
|
7912
|
+
A.pause();
|
|
7913
|
+
B.pause();
|
|
7914
|
+
}
|
|
7915
|
+
} else if (held) {
|
|
7916
|
+
held = false;
|
|
7917
|
+
A.play();
|
|
7918
|
+
B.play();
|
|
7919
|
+
} else if (!A.paused) {
|
|
7920
|
+
const drift = B.currentTime - A.currentTime;
|
|
7921
|
+
const one = 1 / fps;
|
|
7922
|
+
if (Math.abs(drift) > .3) B.currentTime = A.currentTime;
|
|
7923
|
+
else if (Math.abs(drift) > one) B.playbackRate = A.playbackRate * (drift > 0 ? .97 : 1.03);
|
|
7924
|
+
else if (Math.abs(drift) < one / 2 && B.playbackRate !== A.playbackRate) B.playbackRate = A.playbackRate;
|
|
7925
|
+
}
|
|
7926
|
+
}
|
|
7927
|
+
frame = requestAnimationFrame(tick);
|
|
7928
|
+
});
|
|
7929
|
+
return () => cancelAnimationFrame(frame);
|
|
7930
|
+
}, [wanted, fps]);
|
|
7931
|
+
const resume = React.useRef({
|
|
7932
|
+
time: 0,
|
|
7933
|
+
playing: false
|
|
7934
|
+
});
|
|
7935
|
+
if (sa.duration !== null) resume.current = {
|
|
7936
|
+
time: sa.time,
|
|
7937
|
+
playing: wanted
|
|
7938
|
+
};
|
|
7939
|
+
const restore = (e) => {
|
|
7940
|
+
const el = e.currentTarget;
|
|
7941
|
+
el.defaultPlaybackRate = chosenRate.current;
|
|
7942
|
+
el.playbackRate = chosenRate.current;
|
|
7943
|
+
if (resume.current.time > 0) el.currentTime = resume.current.time;
|
|
7944
|
+
if (resume.current.playing) el.play();
|
|
7945
|
+
};
|
|
7946
|
+
React.useEffect(() => {
|
|
7947
|
+
[[refA.current, "a"], [refB.current, "b"]].forEach(([el, side]) => {
|
|
7948
|
+
if (!(el instanceof HTMLVideoElement)) return;
|
|
7949
|
+
el.muted = audio !== side || muted || volume === 0;
|
|
7950
|
+
el.volume = volume / 100;
|
|
7951
|
+
});
|
|
7952
|
+
});
|
|
7953
|
+
const aspect = a.media.width / a.media.height;
|
|
7954
|
+
const natural = [a.media.width, a.media.height];
|
|
7955
|
+
const frameHeight = frameWidth / aspect;
|
|
7956
|
+
const sharpFor = (c) => {
|
|
7957
|
+
if (pixelated !== "zoomed") return pixelated === "always";
|
|
7958
|
+
const drawn = Math.min(frameWidth, frameHeight * (c.media.width / c.media.height));
|
|
7959
|
+
return drawn > 0 && viewport.scale * drawn / c.media.width > 1;
|
|
7960
|
+
};
|
|
7961
|
+
const zoom = useZoom({
|
|
7962
|
+
viewport,
|
|
7963
|
+
setViewport,
|
|
7964
|
+
frame: frameRef,
|
|
7965
|
+
natural
|
|
7966
|
+
});
|
|
7967
|
+
const flip = () => setShowing((s) => s === "a" ? "b" : "a");
|
|
7968
|
+
const video = (c, ref) => /* @__PURE__ */ jsx("video", {
|
|
7969
|
+
ref,
|
|
7970
|
+
src: c.media.src,
|
|
7971
|
+
poster: c.media.poster,
|
|
7972
|
+
preload: "auto",
|
|
7973
|
+
playsInline: true,
|
|
7974
|
+
"aria-label": `Video ${c.label}`,
|
|
7975
|
+
onLoadedMetadata: restore,
|
|
7976
|
+
style: sharpFor(c) ? { imageRendering: "pixelated" } : void 0,
|
|
7977
|
+
className: "absolute inset-0 size-full object-contain"
|
|
7978
|
+
});
|
|
7979
|
+
const skeleton = !failed && (sa.duration === null || sb.duration === null) && /* @__PURE__ */ jsx(Skeleton, {
|
|
7980
|
+
"aria-hidden": true,
|
|
7981
|
+
className: "absolute inset-0 size-full rounded-none"
|
|
7982
|
+
});
|
|
7983
|
+
const frameProps = {
|
|
7984
|
+
viewport,
|
|
7985
|
+
setViewport,
|
|
7986
|
+
aspect,
|
|
7987
|
+
maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
|
|
7988
|
+
};
|
|
7989
|
+
const shortcuts = [
|
|
7990
|
+
...extraShortcuts,
|
|
7991
|
+
...MODES.map((m, i) => ({
|
|
7992
|
+
keys: [String(i + 1)],
|
|
7993
|
+
label: MODE_LABEL[m],
|
|
7994
|
+
run: () => onModeChange(m)
|
|
7995
|
+
})),
|
|
7996
|
+
{
|
|
7997
|
+
keys: ["x"],
|
|
7998
|
+
label: `Flip ${a.label} and ${b.label}`,
|
|
7999
|
+
run: flip,
|
|
8000
|
+
disabled: mode !== "blink"
|
|
8001
|
+
},
|
|
8002
|
+
{
|
|
8003
|
+
keys: [" ", "k"],
|
|
8004
|
+
label: "Play or pause",
|
|
8005
|
+
run: toggle
|
|
8006
|
+
},
|
|
8007
|
+
{
|
|
8008
|
+
keys: ["j"],
|
|
8009
|
+
label: "Back 1 s",
|
|
8010
|
+
run: () => seek(sa.time - 1),
|
|
8011
|
+
repeat: true
|
|
8012
|
+
},
|
|
8013
|
+
{
|
|
8014
|
+
keys: ["l"],
|
|
8015
|
+
label: "Forward 1 s",
|
|
8016
|
+
run: () => seek(sa.time + 1),
|
|
8017
|
+
repeat: true
|
|
8018
|
+
},
|
|
8019
|
+
...audio === "none" ? [] : [{
|
|
8020
|
+
keys: ["m"],
|
|
8021
|
+
label: "Mute",
|
|
8022
|
+
run: () => setMuted((m) => !m)
|
|
8023
|
+
}],
|
|
8024
|
+
...zoomShortcuts(zoom, full, setFull)
|
|
8025
|
+
];
|
|
8026
|
+
useHotkeys(shortcuts, { enabled: keys });
|
|
8027
|
+
let body;
|
|
8028
|
+
if (mode === "side") body = /* @__PURE__ */ jsx("div", {
|
|
8029
|
+
className: "grid gap-3 sm:grid-cols-2",
|
|
8030
|
+
children: [[a, refA], [b, refB]].map(([c, ref], i) => /* @__PURE__ */ jsxs("figure", {
|
|
8031
|
+
className: "grid gap-1.5",
|
|
8032
|
+
children: [/* @__PURE__ */ jsx(Caption, {
|
|
8033
|
+
c,
|
|
8034
|
+
blind
|
|
8035
|
+
}), /* @__PURE__ */ jsxs(ViewportFrame, {
|
|
8036
|
+
...frameProps,
|
|
8037
|
+
label: `Frame ${c.label}`,
|
|
8038
|
+
ref: i === 0 ? frameRef : void 0,
|
|
8039
|
+
children: [i === 0 && skeleton, video(c, ref)]
|
|
8040
|
+
})]
|
|
8041
|
+
}, i))
|
|
8042
|
+
});
|
|
8043
|
+
else body = /* @__PURE__ */ jsxs("figure", {
|
|
8044
|
+
className: "grid gap-1.5",
|
|
8045
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
8046
|
+
className: "flex justify-between gap-4",
|
|
8047
|
+
children: [mode === "blink" ? /* @__PURE__ */ jsx(Caption, {
|
|
8048
|
+
c: showing === "a" ? a : b,
|
|
8049
|
+
blind
|
|
8050
|
+
}) : /* @__PURE__ */ jsx(Caption, {
|
|
8051
|
+
c: a,
|
|
8052
|
+
blind
|
|
8053
|
+
}), mode !== "blink" && /* @__PURE__ */ jsx(Caption, {
|
|
8054
|
+
c: b,
|
|
8055
|
+
blind
|
|
8056
|
+
})]
|
|
8057
|
+
}), /* @__PURE__ */ jsxs(ViewportFrame, {
|
|
8058
|
+
...frameProps,
|
|
8059
|
+
ref: frameRef,
|
|
8060
|
+
cover: mode === "swipe" ? {
|
|
8061
|
+
content: video(a, refA),
|
|
8062
|
+
shown: divider
|
|
8063
|
+
} : void 0,
|
|
8064
|
+
label: mode === "blink" ? `Frame ${(showing === "a" ? a : b).label}` : `${a.label} over ${b.label}`,
|
|
8065
|
+
overlay: mode === "swipe" && /* @__PURE__ */ jsx(Slider$1, {
|
|
8066
|
+
"aria-label": `Divider between ${a.label} and ${b.label}`,
|
|
8067
|
+
value: divider,
|
|
8068
|
+
onChange: (v) => setDivider(v),
|
|
8069
|
+
minValue: 0,
|
|
8070
|
+
maxValue: 100,
|
|
8071
|
+
step: 1,
|
|
8072
|
+
className: "absolute inset-0",
|
|
8073
|
+
children: /* @__PURE__ */ jsx(SliderTrack, {
|
|
8074
|
+
className: "pointer-events-none h-full w-full",
|
|
8075
|
+
children: /* @__PURE__ */ jsxs(SliderThumb, {
|
|
8076
|
+
className: "pointer-events-auto grid h-full w-8 cursor-ew-resize place-items-center focus-visible:outline-2 focus-visible:outline-ring",
|
|
8077
|
+
style: { top: "50%" },
|
|
8078
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
8079
|
+
"aria-hidden": true,
|
|
8080
|
+
className: "col-start-1 row-start-1 h-full w-1 border-x border-background bg-foreground"
|
|
8081
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
8082
|
+
"aria-hidden": true,
|
|
8083
|
+
className: "col-start-1 row-start-1 size-6 rounded-pill border-2 border-foreground bg-background"
|
|
8084
|
+
})]
|
|
8085
|
+
})
|
|
8086
|
+
})
|
|
8087
|
+
}),
|
|
8088
|
+
children: [
|
|
8089
|
+
skeleton,
|
|
8090
|
+
video(b, refB),
|
|
8091
|
+
mode !== "swipe" && /* @__PURE__ */ jsx("div", {
|
|
8092
|
+
className: "absolute inset-0",
|
|
8093
|
+
style: mode === "fade" ? { opacity: 1 - blend / 100 } : mode === "blink" ? { opacity: showing === "a" ? 1 : 0 } : void 0,
|
|
8094
|
+
children: video(a, refA)
|
|
8095
|
+
})
|
|
8096
|
+
]
|
|
8097
|
+
})]
|
|
8098
|
+
});
|
|
8099
|
+
return /* @__PURE__ */ jsx(FullscreenFrame, {
|
|
8100
|
+
label,
|
|
8101
|
+
active: full,
|
|
8102
|
+
onActiveChange: setFull,
|
|
8103
|
+
className,
|
|
8104
|
+
children: /* @__PURE__ */ jsxs("section", {
|
|
8105
|
+
"aria-label": label,
|
|
8106
|
+
className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
|
|
8107
|
+
children: [
|
|
8108
|
+
/* @__PURE__ */ jsxs(Toolbar, {
|
|
8109
|
+
label: "Comparison view",
|
|
8110
|
+
className: "items-center gap-2",
|
|
8111
|
+
children: [
|
|
8112
|
+
/* @__PURE__ */ jsx(ToggleGroup, {
|
|
8113
|
+
label: "View",
|
|
8114
|
+
options: MODES.map((m) => ({
|
|
8115
|
+
value: m,
|
|
8116
|
+
label: MODE_LABEL[m]
|
|
8117
|
+
})),
|
|
8118
|
+
value: mode,
|
|
8119
|
+
onChange: (v) => onModeChange(v),
|
|
8120
|
+
size: "sm"
|
|
8121
|
+
}),
|
|
8122
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
8123
|
+
/* @__PURE__ */ jsx(ZoomControls, {
|
|
8124
|
+
viewport,
|
|
8125
|
+
zoom,
|
|
8126
|
+
natural
|
|
8127
|
+
}),
|
|
8128
|
+
/* @__PURE__ */ jsx(ToolbarSeparator, {}),
|
|
8129
|
+
/* @__PURE__ */ jsx(FullscreenButton, {
|
|
8130
|
+
full,
|
|
8131
|
+
setFull
|
|
8132
|
+
})
|
|
8133
|
+
]
|
|
8134
|
+
}),
|
|
8135
|
+
mode === "fade" && /* @__PURE__ */ jsxs("div", {
|
|
8136
|
+
className: "flex items-center gap-3",
|
|
8137
|
+
children: [
|
|
8138
|
+
/* @__PURE__ */ jsx("span", {
|
|
8139
|
+
className: "type-caption text-muted-foreground",
|
|
8140
|
+
children: a.label
|
|
8141
|
+
}),
|
|
8142
|
+
/* @__PURE__ */ jsx(Slider, {
|
|
8143
|
+
"aria-label": `Blend from ${a.label} to ${b.label}`,
|
|
8144
|
+
value: blend,
|
|
8145
|
+
onChange: setBlend,
|
|
8146
|
+
min: 0,
|
|
8147
|
+
max: 100,
|
|
8148
|
+
unit: "%",
|
|
8149
|
+
hideValue: true,
|
|
8150
|
+
className: "flex-1"
|
|
8151
|
+
}),
|
|
8152
|
+
/* @__PURE__ */ jsx("span", {
|
|
8153
|
+
className: "type-caption text-muted-foreground",
|
|
8154
|
+
children: b.label
|
|
8155
|
+
})
|
|
8156
|
+
]
|
|
8157
|
+
}),
|
|
8158
|
+
mode === "blink" && /* @__PURE__ */ jsx(ToggleGroup, {
|
|
8159
|
+
label: "Showing",
|
|
8160
|
+
options: [{
|
|
8161
|
+
value: "a",
|
|
8162
|
+
label: a.label
|
|
8163
|
+
}, {
|
|
8164
|
+
value: "b",
|
|
8165
|
+
label: b.label
|
|
8166
|
+
}],
|
|
8167
|
+
value: showing,
|
|
8168
|
+
onChange: (v) => setShowing(v),
|
|
8169
|
+
size: "sm",
|
|
8170
|
+
className: "justify-self-start"
|
|
8171
|
+
}),
|
|
8172
|
+
failed && /* @__PURE__ */ jsx("p", {
|
|
8173
|
+
role: "alert",
|
|
8174
|
+
className: "type-body-sm text-danger",
|
|
8175
|
+
children: missing
|
|
8176
|
+
}),
|
|
8177
|
+
body,
|
|
8178
|
+
/* @__PURE__ */ jsxs(Transport, {
|
|
8179
|
+
playing: wanted,
|
|
8180
|
+
onPlayPause: toggle,
|
|
8181
|
+
children: [
|
|
8182
|
+
/* @__PURE__ */ jsx(TimeReadout, {
|
|
8183
|
+
time: sa.time,
|
|
8184
|
+
duration
|
|
8185
|
+
}),
|
|
8186
|
+
/* @__PURE__ */ jsx(SeekBar, {
|
|
8187
|
+
time: sa.time,
|
|
8188
|
+
duration,
|
|
8189
|
+
onSeek: seek,
|
|
8190
|
+
buffered: sa.buffered,
|
|
8191
|
+
label: "Position",
|
|
8192
|
+
step: 1,
|
|
8193
|
+
precision: "frames",
|
|
8194
|
+
fps
|
|
8195
|
+
}),
|
|
8196
|
+
/* @__PURE__ */ jsx(RateChoice, {
|
|
8197
|
+
rate: sa.rate,
|
|
8198
|
+
onRateChange: setRate
|
|
8199
|
+
}),
|
|
8200
|
+
audio !== "none" && /* @__PURE__ */ jsx(VolumeControl, {
|
|
8201
|
+
volume: muted ? 0 : volume,
|
|
8202
|
+
onVolumeChange: (v) => (setMuted(false), setVolume(v))
|
|
8203
|
+
})
|
|
8204
|
+
]
|
|
8205
|
+
}),
|
|
8206
|
+
footer,
|
|
8207
|
+
keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
|
|
8208
|
+
]
|
|
8209
|
+
})
|
|
8210
|
+
});
|
|
8211
|
+
}
|
|
8212
|
+
var tokens = (text) => text.split(/(\s+)/).filter((t) => t !== "");
|
|
8213
|
+
var isSpace = (t) => /^\s+$/.test(t);
|
|
8214
|
+
/** Marks the words that differ between two texts, or returns null when the pair is too long to compare. */
|
|
8215
|
+
function diffWords(a, b) {
|
|
8216
|
+
const ta = tokens(a);
|
|
8217
|
+
const tb = tokens(b);
|
|
8218
|
+
const wa = ta.filter((t) => !isSpace(t));
|
|
8219
|
+
const wb = tb.filter((t) => !isSpace(t));
|
|
8220
|
+
if ((wa.length + 1) * (wb.length + 1) > 25e5) return null;
|
|
8221
|
+
const w = wb.length + 1;
|
|
8222
|
+
const table = new Uint32Array((wa.length + 1) * w);
|
|
8223
|
+
for (let i = wa.length - 1; i >= 0; i--) for (let j = wb.length - 1; j >= 0; j--) table[i * w + j] = wa[i] === wb[j] ? table[(i + 1) * w + j + 1] + 1 : Math.max(table[(i + 1) * w + j], table[i * w + j + 1]);
|
|
8224
|
+
const sameA = /* @__PURE__ */ new Set();
|
|
8225
|
+
const sameB = /* @__PURE__ */ new Set();
|
|
8226
|
+
for (let i = 0, j = 0; i < wa.length && j < wb.length;) if (wa[i] === wb[j]) {
|
|
8227
|
+
sameA.add(i++);
|
|
8228
|
+
sameB.add(j++);
|
|
8229
|
+
} else if (table[(i + 1) * w + j] >= table[i * w + j + 1]) i++;
|
|
8230
|
+
else j++;
|
|
8231
|
+
const cut = (all, same) => {
|
|
8232
|
+
let word = 0;
|
|
8233
|
+
const out = [];
|
|
8234
|
+
let changed = 0;
|
|
8235
|
+
for (const t of all) {
|
|
8236
|
+
if (isSpace(t)) {
|
|
8237
|
+
out.push({
|
|
8238
|
+
text: t,
|
|
8239
|
+
changed: false
|
|
8240
|
+
});
|
|
8241
|
+
continue;
|
|
8242
|
+
}
|
|
8243
|
+
const diff = !same.has(word++);
|
|
8244
|
+
if (diff) changed++;
|
|
8245
|
+
out.push({
|
|
8246
|
+
text: t,
|
|
8247
|
+
changed: diff
|
|
8248
|
+
});
|
|
8249
|
+
}
|
|
8250
|
+
return {
|
|
8251
|
+
out,
|
|
8252
|
+
changed
|
|
8253
|
+
};
|
|
8254
|
+
};
|
|
8255
|
+
const ra = cut(ta, sameA);
|
|
8256
|
+
const rb = cut(tb, sameB);
|
|
8257
|
+
return {
|
|
8258
|
+
a: ra.out,
|
|
8259
|
+
b: rb.out,
|
|
8260
|
+
changedA: ra.changed,
|
|
8261
|
+
changedB: rb.changed
|
|
8262
|
+
};
|
|
8263
|
+
}
|
|
8264
|
+
// src/components/compare-text.tsx
|
|
8265
|
+
function Words({ segments, changed }) {
|
|
8266
|
+
return /* @__PURE__ */ jsx(Fragment, { children: segments.map((s, i) => changed && s.changed ? /* @__PURE__ */ jsx("mark", {
|
|
8267
|
+
className: "rounded-control bg-warning-subtle text-foreground underline decoration-2 underline-offset-2",
|
|
8268
|
+
children: s.text
|
|
8269
|
+
}, i) : /* @__PURE__ */ jsx(React.Fragment, { children: s.text }, i)) });
|
|
8270
|
+
}
|
|
8271
|
+
/** Two texts side by side with scrolling together, an optional reference, and a word diff on request. */
|
|
8272
|
+
function CompareText({ label, a, b, blind, reference, defaultDiff = false, tooLong = "These texts are too long to compare word by word.", linkedScroll = true, keys = true, extraShortcuts = [], footer, className }) {
|
|
8273
|
+
const [diff, setDiff] = React.useState(defaultDiff);
|
|
8274
|
+
const [against, setAgainst] = React.useState(reference ? "reference" : "other");
|
|
8275
|
+
const boxA = React.useRef(null);
|
|
8276
|
+
const boxB = React.useRef(null);
|
|
8277
|
+
const syncing = React.useRef(false);
|
|
8278
|
+
const result = React.useMemo(() => {
|
|
8279
|
+
if (!diff) return null;
|
|
8280
|
+
if (against === "reference" && reference) {
|
|
8281
|
+
const ra = diffWords(a.media.text, reference.text);
|
|
8282
|
+
const rb = diffWords(b.media.text, reference.text);
|
|
8283
|
+
return ra && rb ? {
|
|
8284
|
+
a: ra.a,
|
|
8285
|
+
b: rb.a,
|
|
8286
|
+
changedA: ra.changedA,
|
|
8287
|
+
changedB: rb.changedA,
|
|
8288
|
+
missingA: ra.changedB,
|
|
8289
|
+
missingB: rb.changedB
|
|
8290
|
+
} : "long";
|
|
8291
|
+
}
|
|
8292
|
+
const r = diffWords(a.media.text, b.media.text);
|
|
8293
|
+
return r ? {
|
|
8294
|
+
...r,
|
|
8295
|
+
missingA: 0,
|
|
8296
|
+
missingB: 0
|
|
8297
|
+
} : "long";
|
|
8298
|
+
}, [
|
|
8299
|
+
diff,
|
|
8300
|
+
against,
|
|
8301
|
+
reference,
|
|
8302
|
+
a.media.text,
|
|
8303
|
+
b.media.text
|
|
8304
|
+
]);
|
|
8305
|
+
const follow = (from, to) => {
|
|
8306
|
+
if (!linkedScroll || !from || !to || syncing.current) return;
|
|
8307
|
+
const range = from.scrollHeight - from.clientHeight;
|
|
8308
|
+
syncing.current = true;
|
|
8309
|
+
to.scrollTop = range > 0 ? from.scrollTop / range * (to.scrollHeight - to.clientHeight) : 0;
|
|
8310
|
+
requestAnimationFrame(() => syncing.current = false);
|
|
8311
|
+
};
|
|
8312
|
+
const pane = (c, ref, other, segments) => /* @__PURE__ */ jsxs("figure", {
|
|
8313
|
+
className: "grid min-w-0 gap-1.5",
|
|
8314
|
+
children: [/* @__PURE__ */ jsxs("figcaption", {
|
|
8315
|
+
className: "flex items-baseline gap-2",
|
|
8316
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
8317
|
+
className: "type-label",
|
|
8318
|
+
children: c.label
|
|
8319
|
+
}), !blind && c.note && /* @__PURE__ */ jsx("span", {
|
|
8320
|
+
className: "type-caption text-muted-foreground",
|
|
8321
|
+
children: c.note
|
|
8322
|
+
})]
|
|
8323
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
8324
|
+
ref,
|
|
8325
|
+
tabIndex: 0,
|
|
8326
|
+
role: "region",
|
|
8327
|
+
"aria-label": `Text ${c.label}`,
|
|
8328
|
+
onScroll: () => follow(ref.current, other.current),
|
|
8329
|
+
className: "max-h-96 overflow-auto whitespace-pre-wrap rounded-surface border border-border bg-muted p-3 type-body focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
|
|
8330
|
+
children: segments ? /* @__PURE__ */ jsx(Words, {
|
|
8331
|
+
segments,
|
|
8332
|
+
changed: true
|
|
8333
|
+
}) : c.media.text
|
|
8334
|
+
})]
|
|
8335
|
+
});
|
|
8336
|
+
const counts = result && result !== "long" ? result : null;
|
|
8337
|
+
const words = (n) => `${n} ${n === 1 ? "word" : "words"}`;
|
|
8338
|
+
const ref = against === "reference" && reference;
|
|
8339
|
+
const say = (who, differ, missing) => ref ? `${who}: ${words(differ)} ${differ === 1 ? "differs" : "differ"}, ${missing} missing.` : `${who}: ${words(differ)} ${differ === 1 ? "differs" : "differ"}.`;
|
|
8340
|
+
const shortcuts = [...extraShortcuts, {
|
|
8341
|
+
keys: ["d"],
|
|
8342
|
+
label: diff ? "Hide the differences" : "Mark the differences",
|
|
8343
|
+
run: () => setDiff((d) => !d)
|
|
8344
|
+
}];
|
|
8345
|
+
useHotkeys(shortcuts, { enabled: keys });
|
|
8346
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
8347
|
+
"aria-label": label,
|
|
8348
|
+
className: cn("grid gap-3", className),
|
|
8349
|
+
children: [
|
|
8350
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8351
|
+
className: "flex flex-wrap items-center gap-3",
|
|
8352
|
+
children: [/* @__PURE__ */ jsx(Switch, {
|
|
8353
|
+
label: "Mark the words that differ",
|
|
8354
|
+
on: diff,
|
|
8355
|
+
onChange: setDiff
|
|
8356
|
+
}), diff && reference && /* @__PURE__ */ jsx(ToggleGroup, {
|
|
8357
|
+
label: "Differences against",
|
|
8358
|
+
options: [{
|
|
8359
|
+
value: "other",
|
|
8360
|
+
label: "The other text"
|
|
8361
|
+
}, {
|
|
8362
|
+
value: "reference",
|
|
8363
|
+
label: reference.label
|
|
8364
|
+
}],
|
|
8365
|
+
value: against,
|
|
8366
|
+
onChange: (v) => setAgainst(v),
|
|
8367
|
+
size: "sm"
|
|
8368
|
+
})]
|
|
8369
|
+
}),
|
|
8370
|
+
reference && /* @__PURE__ */ jsxs("figure", {
|
|
8371
|
+
className: "grid gap-1.5",
|
|
8372
|
+
children: [/* @__PURE__ */ jsx("figcaption", {
|
|
8373
|
+
className: "type-label",
|
|
8374
|
+
children: reference.label
|
|
8375
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
8376
|
+
className: "whitespace-pre-wrap rounded-surface border border-border p-3 type-body",
|
|
8377
|
+
children: reference.text
|
|
8378
|
+
})]
|
|
8379
|
+
}),
|
|
8380
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8381
|
+
className: "grid gap-3 sm:grid-cols-2",
|
|
8382
|
+
children: [pane(a, boxA, boxB, counts ? counts.a : null), pane(b, boxB, boxA, counts ? counts.b : null)]
|
|
8383
|
+
}),
|
|
8384
|
+
diff && /* @__PURE__ */ jsx("p", {
|
|
8385
|
+
role: "status",
|
|
8386
|
+
className: "type-body-sm text-muted-foreground",
|
|
8387
|
+
children: result === "long" ? tooLong : counts && counts.changedA + counts.missingA + counts.changedB + counts.missingB === 0 ? ref && reference ? `Both match ${reference.label} word for word.` : "The texts are the same word for word." : counts ? `${say(a.label, counts.changedA, counts.missingA)} ${say(b.label, counts.changedB, counts.missingB)}` : null
|
|
8388
|
+
}),
|
|
8389
|
+
footer,
|
|
8390
|
+
keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
|
|
8391
|
+
]
|
|
7438
8392
|
});
|
|
7439
8393
|
}
|
|
7440
8394
|
// src/components/compare-grid.tsx
|
|
@@ -8169,6 +9123,6 @@ function SaveStatus({ state, onRetry, className }) {
|
|
|
8169
9123
|
]
|
|
8170
9124
|
});
|
|
8171
9125
|
}
|
|
8172
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, 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, 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, differences, fetchJson, fieldErrorsOf, format, formatChord, geo, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, 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 };
|
|
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 };
|
|
8173
9127
|
|
|
8174
9128
|
//# sourceMappingURL=index.js.map
|