strata-react 1.3.26 → 1.3.28
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 +3 -2
- package/UPGRADING.md +4 -0
- package/dist/index.d.ts +119 -4
- package/dist/index.js +775 -14
- package/dist/index.js.map +1 -1
- package/dist/strata.bare.css +18 -0
- package/dist/strata.css +18 -0
- package/dist/strata.migrate.css +18 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4647,7 +4647,7 @@ const idle = {
|
|
|
4647
4647
|
loading: false,
|
|
4648
4648
|
error: null
|
|
4649
4649
|
};
|
|
4650
|
-
const LOAD_MESSAGES = {
|
|
4650
|
+
const LOAD_MESSAGES$1 = {
|
|
4651
4651
|
2: "The connection dropped while it was loading.",
|
|
4652
4652
|
3: "The file could not be decoded.",
|
|
4653
4653
|
4: "This format is not supported or the file is not there."
|
|
@@ -4725,7 +4725,7 @@ function useMediaElement(ref, options = {}) {
|
|
|
4725
4725
|
} : null);
|
|
4726
4726
|
if (el.error && el.error.code !== 1) error = {
|
|
4727
4727
|
kind: "load",
|
|
4728
|
-
message: LOAD_MESSAGES[el.error.code] ?? "It could not be played."
|
|
4728
|
+
message: LOAD_MESSAGES$1[el.error.code] ?? "It could not be played."
|
|
4729
4729
|
};
|
|
4730
4730
|
const next = {
|
|
4731
4731
|
ready,
|
|
@@ -7547,6 +7547,714 @@ function TimelinePlayer({ clock, label, stage, rates, onRateChange, legend = fal
|
|
|
7547
7547
|
});
|
|
7548
7548
|
}
|
|
7549
7549
|
|
|
7550
|
+
// src/lib/edit-list.ts
|
|
7551
|
+
/** Below this, two times are the same (a frame at 120 fps is 8 ms; float sums of rationals drift by far less). */
|
|
7552
|
+
const EDIT_EPS = 1e-6;
|
|
7553
|
+
const length = (c) => Math.max(0, c.end - c.start);
|
|
7554
|
+
/** The start of each clip in edit time, and the total. */
|
|
7555
|
+
function editTimes(clips) {
|
|
7556
|
+
const at = [];
|
|
7557
|
+
let t = 0;
|
|
7558
|
+
for (const c of clips) {
|
|
7559
|
+
at.push(t);
|
|
7560
|
+
t += length(c);
|
|
7561
|
+
}
|
|
7562
|
+
return {
|
|
7563
|
+
at,
|
|
7564
|
+
duration: t
|
|
7565
|
+
};
|
|
7566
|
+
}
|
|
7567
|
+
/** The clip playing at edit `time` and the time in its file. At a cut the later clip is playing (clips are half-open); at or past the end, the last clip at its end. Null for an empty edit. */
|
|
7568
|
+
function locateInEdit(clips, times, time) {
|
|
7569
|
+
if (clips.length === 0) return null;
|
|
7570
|
+
if (time >= times.duration - 1e-6) {
|
|
7571
|
+
const last = clips.length - 1;
|
|
7572
|
+
return {
|
|
7573
|
+
index: last,
|
|
7574
|
+
source: clips[last].end
|
|
7575
|
+
};
|
|
7576
|
+
}
|
|
7577
|
+
const t = Math.max(0, time);
|
|
7578
|
+
let lo = 0;
|
|
7579
|
+
let hi = clips.length - 1;
|
|
7580
|
+
while (lo < hi) {
|
|
7581
|
+
const mid = lo + hi + 1 >> 1;
|
|
7582
|
+
if (times.at[mid] <= t + 1e-6) lo = mid;
|
|
7583
|
+
else hi = mid - 1;
|
|
7584
|
+
}
|
|
7585
|
+
while (lo > 0 && length(clips[lo]) === 0) lo--;
|
|
7586
|
+
return {
|
|
7587
|
+
index: lo,
|
|
7588
|
+
source: clips[lo].start + Math.max(0, t - times.at[lo])
|
|
7589
|
+
};
|
|
7590
|
+
}
|
|
7591
|
+
/** Edit time of `source` seconds into clip `index`'s file, held inside the clip. */
|
|
7592
|
+
function editTimeOf(clips, times, index, source) {
|
|
7593
|
+
const c = clips[index];
|
|
7594
|
+
return times.at[index] + Math.min(Math.max(source - c.start, 0), length(c));
|
|
7595
|
+
}
|
|
7596
|
+
/** Whether `b` carries straight on from `a` in the same file, so playing through the cut needs no seek. */
|
|
7597
|
+
function continues(a, b) {
|
|
7598
|
+
return a.src === b.src && Math.abs(b.start - a.end) < 1e-6;
|
|
7599
|
+
}
|
|
7600
|
+
/** The first clip after `index` that does not carry straight on from the one before it: the next one a second element must have ready. Null when the rest of the edit is one stretch of the same file. */
|
|
7601
|
+
function nextBreak(clips, index) {
|
|
7602
|
+
for (let k = index + 1; k < clips.length; k++) if (!continues(clips[k - 1], clips[k])) return k;
|
|
7603
|
+
return null;
|
|
7604
|
+
}
|
|
7605
|
+
|
|
7606
|
+
// src/components/edit-list-player.tsx
|
|
7607
|
+
const LOAD_MESSAGES = {
|
|
7608
|
+
2: "The connection dropped while it was loading.",
|
|
7609
|
+
3: "A file could not be decoded.",
|
|
7610
|
+
4: "A file is in a format this browser cannot play, or is not there."
|
|
7611
|
+
};
|
|
7612
|
+
/** Plays an edit list through two stacked `<video>` elements with no gap at the cuts. `EditListPlayer` is it with the bar. */
|
|
7613
|
+
function useEditList(clips, options = {}) {
|
|
7614
|
+
const { fps, keys = true } = options;
|
|
7615
|
+
const a = React.useRef(null);
|
|
7616
|
+
const b = React.useRef(null);
|
|
7617
|
+
const refs = React.useMemo(() => [a, b], []);
|
|
7618
|
+
const times = React.useMemo(() => editTimes(clips), [clips]);
|
|
7619
|
+
const [front, setFront] = React.useState(0);
|
|
7620
|
+
const [index, setIndex] = React.useState(clips.length ? 0 : -1);
|
|
7621
|
+
const [time, setTime] = React.useState(0);
|
|
7622
|
+
const [playing, setPlaying] = React.useState(false);
|
|
7623
|
+
const [loading, setLoading] = React.useState(false);
|
|
7624
|
+
const [error, setError] = React.useState(null);
|
|
7625
|
+
const [volume, setVolumeState] = React.useState(100);
|
|
7626
|
+
const live = React.useRef({
|
|
7627
|
+
clips,
|
|
7628
|
+
times,
|
|
7629
|
+
front: 0,
|
|
7630
|
+
index: clips.length ? 0 : -1,
|
|
7631
|
+
holds: [null, null],
|
|
7632
|
+
pending: [null, null],
|
|
7633
|
+
playing: false,
|
|
7634
|
+
quiet: [false, false],
|
|
7635
|
+
unlocked: [false, false],
|
|
7636
|
+
busy: false,
|
|
7637
|
+
volume: 100,
|
|
7638
|
+
lead: fps ? .5 / fps : .02,
|
|
7639
|
+
refresh: 1 / 60,
|
|
7640
|
+
frames: false
|
|
7641
|
+
});
|
|
7642
|
+
live.current.clips = clips;
|
|
7643
|
+
live.current.times = times;
|
|
7644
|
+
live.current.lead = fps ? .5 / fps : .02;
|
|
7645
|
+
const onClip = React.useRef(options.onClipChange);
|
|
7646
|
+
onClip.current = options.onClipChange;
|
|
7647
|
+
const el = (slot) => refs[slot].current;
|
|
7648
|
+
const setIdx = React.useCallback((i) => {
|
|
7649
|
+
if (live.current.index === i) return;
|
|
7650
|
+
live.current.index = i;
|
|
7651
|
+
setIndex(i);
|
|
7652
|
+
onClip.current?.(i);
|
|
7653
|
+
}, []);
|
|
7654
|
+
const hold = React.useCallback((slot, i, source) => {
|
|
7655
|
+
const v = el(slot);
|
|
7656
|
+
const c = live.current.clips[i];
|
|
7657
|
+
if (!v || !c) return;
|
|
7658
|
+
const at = source ?? c.start;
|
|
7659
|
+
live.current.holds[slot] = i;
|
|
7660
|
+
v.volume = live.current.volume / 100;
|
|
7661
|
+
if (v.getAttribute("src") !== c.src) {
|
|
7662
|
+
live.current.quiet[slot] = true;
|
|
7663
|
+
live.current.pending[slot] = at;
|
|
7664
|
+
v.src = c.src;
|
|
7665
|
+
v.load();
|
|
7666
|
+
live.current.quiet[slot] = false;
|
|
7667
|
+
} else if (v.readyState >= 1) {
|
|
7668
|
+
if (Math.abs(v.currentTime - at) > 1e-6) v.currentTime = at;
|
|
7669
|
+
} else live.current.pending[slot] = at;
|
|
7670
|
+
}, []);
|
|
7671
|
+
const muteFor = (v, vol) => {
|
|
7672
|
+
v.muted = vol === 0;
|
|
7673
|
+
};
|
|
7674
|
+
const prepareBehind = React.useCallback((i) => {
|
|
7675
|
+
const behind = 1 - live.current.front;
|
|
7676
|
+
const k = nextBreak(live.current.clips, i);
|
|
7677
|
+
if (k === null) return;
|
|
7678
|
+
if (live.current.holds[behind] === k && live.current.pending[behind] === null) {
|
|
7679
|
+
const v = el(behind);
|
|
7680
|
+
const c = live.current.clips[k];
|
|
7681
|
+
if (v && Math.abs(v.currentTime - c.start) <= 1e-6) return;
|
|
7682
|
+
}
|
|
7683
|
+
el(behind)?.pause();
|
|
7684
|
+
hold(behind, k);
|
|
7685
|
+
}, [hold]);
|
|
7686
|
+
const reject = React.useCallback(() => {
|
|
7687
|
+
setError({
|
|
7688
|
+
kind: "blocked",
|
|
7689
|
+
message: "The browser did not let it play. Press Play to start it."
|
|
7690
|
+
});
|
|
7691
|
+
live.current.playing = false;
|
|
7692
|
+
setPlaying(false);
|
|
7693
|
+
}, []);
|
|
7694
|
+
const playFront = React.useCallback(() => {
|
|
7695
|
+
const v = el(live.current.front);
|
|
7696
|
+
if (!v) return;
|
|
7697
|
+
muteFor(v, live.current.volume);
|
|
7698
|
+
const p = v.play();
|
|
7699
|
+
if (p && typeof p.catch === "function") p.catch(reject);
|
|
7700
|
+
}, [reject]);
|
|
7701
|
+
const show = (slot) => refs.forEach((r, i) => {
|
|
7702
|
+
const v = r.current;
|
|
7703
|
+
if (!v) return;
|
|
7704
|
+
v.style.opacity = i === slot ? "" : "0";
|
|
7705
|
+
v.style.pointerEvents = i === slot ? "" : "none";
|
|
7706
|
+
});
|
|
7707
|
+
React.useLayoutEffect(() => show(live.current.front));
|
|
7708
|
+
const bringForward = React.useCallback((slot) => {
|
|
7709
|
+
const old = live.current.front;
|
|
7710
|
+
if (old === slot) return;
|
|
7711
|
+
live.current.front = slot;
|
|
7712
|
+
show(slot);
|
|
7713
|
+
setFront(slot);
|
|
7714
|
+
if (live.current.playing) playFront();
|
|
7715
|
+
el(old)?.pause();
|
|
7716
|
+
}, [playFront]);
|
|
7717
|
+
const advance = React.useCallback((j) => {
|
|
7718
|
+
const s = live.current;
|
|
7719
|
+
if (j >= s.clips.length) {
|
|
7720
|
+
s.playing = false;
|
|
7721
|
+
setPlaying(false);
|
|
7722
|
+
el(s.front)?.pause();
|
|
7723
|
+
setTime(s.times.duration);
|
|
7724
|
+
return;
|
|
7725
|
+
}
|
|
7726
|
+
const i = s.index;
|
|
7727
|
+
if (i >= 0 && continues(s.clips[i], s.clips[j]) && s.holds[s.front] === i) {
|
|
7728
|
+
s.holds[s.front] = j;
|
|
7729
|
+
setIdx(j);
|
|
7730
|
+
return;
|
|
7731
|
+
}
|
|
7732
|
+
const behind = 1 - s.front;
|
|
7733
|
+
if (s.holds[behind] !== j) hold(behind, j);
|
|
7734
|
+
setIdx(j);
|
|
7735
|
+
bringForward(behind);
|
|
7736
|
+
prepareBehind(j);
|
|
7737
|
+
}, [
|
|
7738
|
+
bringForward,
|
|
7739
|
+
hold,
|
|
7740
|
+
prepareBehind,
|
|
7741
|
+
setIdx
|
|
7742
|
+
]);
|
|
7743
|
+
const cut = React.useCallback((i) => {
|
|
7744
|
+
const s = live.current;
|
|
7745
|
+
if (s.busy || s.index !== i || !s.playing) return;
|
|
7746
|
+
s.busy = true;
|
|
7747
|
+
try {
|
|
7748
|
+
advance(i + 1);
|
|
7749
|
+
} finally {
|
|
7750
|
+
s.busy = false;
|
|
7751
|
+
}
|
|
7752
|
+
}, [advance]);
|
|
7753
|
+
const tick = React.useCallback(() => {
|
|
7754
|
+
const s = live.current;
|
|
7755
|
+
const v = el(s.front);
|
|
7756
|
+
const i = s.index;
|
|
7757
|
+
if (!v || i < 0 || s.busy) return;
|
|
7758
|
+
const c = s.clips[i];
|
|
7759
|
+
if (!c) return;
|
|
7760
|
+
const early = s.frames ? 0 : Math.max(s.lead, s.refresh);
|
|
7761
|
+
if (s.playing && s.pending[s.front] === null && (v.currentTime >= c.end - early || v.ended)) {
|
|
7762
|
+
cut(i);
|
|
7763
|
+
return;
|
|
7764
|
+
}
|
|
7765
|
+
setTime(editTimeOf(s.clips, s.times, i, v.currentTime));
|
|
7766
|
+
setLoading(s.playing && (s.pending[s.front] !== null || v.readyState < 3));
|
|
7767
|
+
}, [cut]);
|
|
7768
|
+
React.useEffect(() => {
|
|
7769
|
+
if (!playing) return;
|
|
7770
|
+
const s = live.current;
|
|
7771
|
+
let stopped = false;
|
|
7772
|
+
let timer;
|
|
7773
|
+
let watching = null;
|
|
7774
|
+
let lastMedia = null;
|
|
7775
|
+
let frameLength = fps ? 1 / fps : 0;
|
|
7776
|
+
const watch = () => {
|
|
7777
|
+
const v = el(s.front);
|
|
7778
|
+
if (stopped || !v || typeof v.requestVideoFrameCallback !== "function") return;
|
|
7779
|
+
s.frames = true;
|
|
7780
|
+
watching = {
|
|
7781
|
+
v,
|
|
7782
|
+
id: v.requestVideoFrameCallback((now, meta) => {
|
|
7783
|
+
if (stopped) return;
|
|
7784
|
+
if (v !== el(s.front)) return;
|
|
7785
|
+
if (!fps && lastMedia !== null && meta.mediaTime > lastMedia) frameLength = meta.mediaTime - lastMedia;
|
|
7786
|
+
lastMedia = meta.mediaTime;
|
|
7787
|
+
const i = s.index;
|
|
7788
|
+
const c = s.clips[i];
|
|
7789
|
+
if (c && frameLength > 0 && meta.mediaTime + frameLength >= c.end - 1e-6) {
|
|
7790
|
+
const wait = (meta.expectedDisplayTime ?? now) + frameLength * 1e3 - s.refresh * 500 - performance.now();
|
|
7791
|
+
clearTimeout(timer);
|
|
7792
|
+
timer = setTimeout(() => cut(i), Math.max(0, wait));
|
|
7793
|
+
}
|
|
7794
|
+
watch();
|
|
7795
|
+
})
|
|
7796
|
+
};
|
|
7797
|
+
};
|
|
7798
|
+
watch();
|
|
7799
|
+
return () => {
|
|
7800
|
+
stopped = true;
|
|
7801
|
+
clearTimeout(timer);
|
|
7802
|
+
if (watching) watching.v.cancelVideoFrameCallback(watching.id);
|
|
7803
|
+
};
|
|
7804
|
+
}, [
|
|
7805
|
+
playing,
|
|
7806
|
+
fps,
|
|
7807
|
+
cut,
|
|
7808
|
+
front
|
|
7809
|
+
]);
|
|
7810
|
+
React.useEffect(() => {
|
|
7811
|
+
if (!playing) return;
|
|
7812
|
+
let last = null;
|
|
7813
|
+
let id = requestAnimationFrame(function loop(now) {
|
|
7814
|
+
if (last !== null) live.current.refresh = .8 * live.current.refresh + .2 * Math.min(.05, (now - last) / 1e3);
|
|
7815
|
+
last = now;
|
|
7816
|
+
tick();
|
|
7817
|
+
id = requestAnimationFrame(loop);
|
|
7818
|
+
});
|
|
7819
|
+
return () => cancelAnimationFrame(id);
|
|
7820
|
+
}, [playing, tick]);
|
|
7821
|
+
React.useEffect(() => {
|
|
7822
|
+
const unbind = [];
|
|
7823
|
+
refs.forEach((ref, slot) => {
|
|
7824
|
+
const v = ref.current;
|
|
7825
|
+
if (!v) return;
|
|
7826
|
+
const on = (e) => {
|
|
7827
|
+
const s = live.current;
|
|
7828
|
+
if (e.type === "loadedmetadata" && s.pending[slot] !== null) {
|
|
7829
|
+
v.currentTime = s.pending[slot];
|
|
7830
|
+
s.pending[slot] = null;
|
|
7831
|
+
if (slot === s.front && s.playing) playFront();
|
|
7832
|
+
}
|
|
7833
|
+
if (e.type === "error" && v.error && v.error.code !== 1 && slot === s.front) {
|
|
7834
|
+
setError({
|
|
7835
|
+
kind: "load",
|
|
7836
|
+
message: LOAD_MESSAGES[v.error.code] ?? "It could not be played."
|
|
7837
|
+
});
|
|
7838
|
+
s.playing = false;
|
|
7839
|
+
setPlaying(false);
|
|
7840
|
+
}
|
|
7841
|
+
if (e.type === "pause" && slot === s.front && s.playing && !s.quiet[slot] && !v.ended) {
|
|
7842
|
+
const c = s.clips[s.index];
|
|
7843
|
+
if (c && v.currentTime < c.end - s.lead) {
|
|
7844
|
+
s.playing = false;
|
|
7845
|
+
setPlaying(false);
|
|
7846
|
+
}
|
|
7847
|
+
}
|
|
7848
|
+
if (slot === s.front) tick();
|
|
7849
|
+
};
|
|
7850
|
+
const types = [
|
|
7851
|
+
"loadedmetadata",
|
|
7852
|
+
"timeupdate",
|
|
7853
|
+
"waiting",
|
|
7854
|
+
"playing",
|
|
7855
|
+
"canplay",
|
|
7856
|
+
"seeked",
|
|
7857
|
+
"error",
|
|
7858
|
+
"pause",
|
|
7859
|
+
"ended"
|
|
7860
|
+
];
|
|
7861
|
+
for (const t of types) v.addEventListener(t, on);
|
|
7862
|
+
unbind.push(() => types.forEach((t) => v.removeEventListener(t, on)));
|
|
7863
|
+
});
|
|
7864
|
+
return () => unbind.forEach((u) => u());
|
|
7865
|
+
}, [
|
|
7866
|
+
refs,
|
|
7867
|
+
tick,
|
|
7868
|
+
playFront
|
|
7869
|
+
]);
|
|
7870
|
+
const signature = clips.map((c) => `${c.id}|${c.src}|${c.start}|${c.end}`).join(";");
|
|
7871
|
+
const previous = React.useRef([]);
|
|
7872
|
+
React.useEffect(() => {
|
|
7873
|
+
const s = live.current;
|
|
7874
|
+
const was = s.index >= 0 ? previous.current[s.index] : void 0;
|
|
7875
|
+
const source = was ? el(s.front)?.currentTime ?? was.start : 0;
|
|
7876
|
+
previous.current = s.clips;
|
|
7877
|
+
s.holds = [null, null];
|
|
7878
|
+
s.pending = [null, null];
|
|
7879
|
+
if (s.clips.length === 0) {
|
|
7880
|
+
s.index = -1;
|
|
7881
|
+
s.playing = false;
|
|
7882
|
+
refs.forEach((r, slot) => {
|
|
7883
|
+
const v = r.current;
|
|
7884
|
+
if (!v) return;
|
|
7885
|
+
v.pause();
|
|
7886
|
+
if (v.getAttribute("src")) {
|
|
7887
|
+
s.quiet[slot] = true;
|
|
7888
|
+
v.removeAttribute("src");
|
|
7889
|
+
v.load();
|
|
7890
|
+
s.quiet[slot] = false;
|
|
7891
|
+
}
|
|
7892
|
+
});
|
|
7893
|
+
setIndex(-1);
|
|
7894
|
+
setPlaying(false);
|
|
7895
|
+
setTime(0);
|
|
7896
|
+
return;
|
|
7897
|
+
}
|
|
7898
|
+
const same = was ? s.clips.findIndex((c) => c.id === was.id && source >= c.start && source < c.end) : -1;
|
|
7899
|
+
const found = same >= 0 ? {
|
|
7900
|
+
index: same,
|
|
7901
|
+
source
|
|
7902
|
+
} : locateInEdit(s.clips, s.times, Math.min(timeRef.current, s.times.duration));
|
|
7903
|
+
s.busy = true;
|
|
7904
|
+
try {
|
|
7905
|
+
setIdx(found.index);
|
|
7906
|
+
hold(s.front, found.index, found.source);
|
|
7907
|
+
setTime(editTimeOf(s.clips, s.times, found.index, found.source));
|
|
7908
|
+
prepareBehind(found.index);
|
|
7909
|
+
if (s.playing) playFront();
|
|
7910
|
+
} finally {
|
|
7911
|
+
s.busy = false;
|
|
7912
|
+
}
|
|
7913
|
+
}, [signature]);
|
|
7914
|
+
const timeRef = React.useRef(time);
|
|
7915
|
+
timeRef.current = time;
|
|
7916
|
+
React.useEffect(() => () => {
|
|
7917
|
+
refs.forEach((r) => r.current?.pause());
|
|
7918
|
+
}, [refs]);
|
|
7919
|
+
const unlockBehind = () => {
|
|
7920
|
+
const s = live.current;
|
|
7921
|
+
const slot = 1 - s.front;
|
|
7922
|
+
const v = el(slot);
|
|
7923
|
+
if (!v || s.unlocked[slot] || !v.getAttribute("src")) return;
|
|
7924
|
+
s.unlocked[slot] = true;
|
|
7925
|
+
const at = s.pending[slot] ?? v.currentTime;
|
|
7926
|
+
const held = s.holds[slot];
|
|
7927
|
+
v.muted = true;
|
|
7928
|
+
s.quiet[slot] = true;
|
|
7929
|
+
const p = v.play();
|
|
7930
|
+
const done = () => {
|
|
7931
|
+
s.quiet[slot] = false;
|
|
7932
|
+
if (live.current.front === slot) return;
|
|
7933
|
+
v.pause();
|
|
7934
|
+
muteFor(v, s.volume);
|
|
7935
|
+
if (s.holds[slot] !== held || s.pending[slot] !== null) return;
|
|
7936
|
+
if (Math.abs(v.currentTime - at) > 1e-6) v.currentTime = at;
|
|
7937
|
+
};
|
|
7938
|
+
if (p && typeof p.then === "function") p.then(done, done);
|
|
7939
|
+
else done();
|
|
7940
|
+
};
|
|
7941
|
+
const play = React.useCallback(() => {
|
|
7942
|
+
const s = live.current;
|
|
7943
|
+
if (s.clips.length === 0) return;
|
|
7944
|
+
setError(null);
|
|
7945
|
+
if (timeRef.current >= s.times.duration - 1e-6) {
|
|
7946
|
+
if (el(s.front)) {
|
|
7947
|
+
hold(s.front, 0);
|
|
7948
|
+
setIdx(0);
|
|
7949
|
+
setTime(0);
|
|
7950
|
+
prepareBehind(0);
|
|
7951
|
+
}
|
|
7952
|
+
}
|
|
7953
|
+
s.playing = true;
|
|
7954
|
+
setPlaying(true);
|
|
7955
|
+
s.unlocked[s.front] = true;
|
|
7956
|
+
playFront();
|
|
7957
|
+
unlockBehind();
|
|
7958
|
+
}, [
|
|
7959
|
+
hold,
|
|
7960
|
+
playFront,
|
|
7961
|
+
prepareBehind,
|
|
7962
|
+
setIdx
|
|
7963
|
+
]);
|
|
7964
|
+
const pause = React.useCallback(() => {
|
|
7965
|
+
live.current.playing = false;
|
|
7966
|
+
setPlaying(false);
|
|
7967
|
+
setLoading(false);
|
|
7968
|
+
el(live.current.front)?.pause();
|
|
7969
|
+
}, []);
|
|
7970
|
+
const seek = React.useCallback((to) => {
|
|
7971
|
+
const s = live.current;
|
|
7972
|
+
const found = locateInEdit(s.clips, s.times, Math.min(Math.max(to, 0), s.times.duration));
|
|
7973
|
+
if (!found) return;
|
|
7974
|
+
const { index: j, source } = found;
|
|
7975
|
+
const behind = 1 - s.front;
|
|
7976
|
+
const src = s.clips[j].src;
|
|
7977
|
+
const holdsSrc = (slot) => el(slot)?.getAttribute("src") === src;
|
|
7978
|
+
s.busy = true;
|
|
7979
|
+
try {
|
|
7980
|
+
setIdx(j);
|
|
7981
|
+
if (!holdsSrc(s.front) && (s.holds[behind] === j || holdsSrc(behind))) {
|
|
7982
|
+
hold(behind, j, source);
|
|
7983
|
+
bringForward(behind);
|
|
7984
|
+
} else hold(s.front, j, source);
|
|
7985
|
+
setTime(editTimeOf(s.clips, s.times, j, source));
|
|
7986
|
+
prepareBehind(j);
|
|
7987
|
+
if (s.playing) playFront();
|
|
7988
|
+
} finally {
|
|
7989
|
+
s.busy = false;
|
|
7990
|
+
}
|
|
7991
|
+
}, [
|
|
7992
|
+
bringForward,
|
|
7993
|
+
hold,
|
|
7994
|
+
playFront,
|
|
7995
|
+
prepareBehind,
|
|
7996
|
+
setIdx
|
|
7997
|
+
]);
|
|
7998
|
+
const step = React.useCallback((count) => {
|
|
7999
|
+
if (!fps) return;
|
|
8000
|
+
pause();
|
|
8001
|
+
seek(timeRef.current + count / fps);
|
|
8002
|
+
}, [
|
|
8003
|
+
fps,
|
|
8004
|
+
pause,
|
|
8005
|
+
seek
|
|
8006
|
+
]);
|
|
8007
|
+
const setVolume = React.useCallback((v) => {
|
|
8008
|
+
const s = live.current;
|
|
8009
|
+
s.volume = v;
|
|
8010
|
+
setVolumeState(v);
|
|
8011
|
+
refs.forEach((r, slot) => {
|
|
8012
|
+
const e = r.current;
|
|
8013
|
+
if (!e) return;
|
|
8014
|
+
e.volume = Math.max(0, Math.min(1, v / 100));
|
|
8015
|
+
if (!s.quiet[slot]) muteFor(e, v);
|
|
8016
|
+
});
|
|
8017
|
+
}, [refs]);
|
|
8018
|
+
const retry = React.useCallback(() => {
|
|
8019
|
+
const s = live.current;
|
|
8020
|
+
setError(null);
|
|
8021
|
+
for (const slot of [0, 1]) {
|
|
8022
|
+
const v = el(slot);
|
|
8023
|
+
if (v) v.removeAttribute("src");
|
|
8024
|
+
}
|
|
8025
|
+
s.holds = [null, null];
|
|
8026
|
+
seek(timeRef.current);
|
|
8027
|
+
}, [seek]);
|
|
8028
|
+
const owner = useKeyOwner(keys, playing);
|
|
8029
|
+
const regionProps = React.useMemo(() => ({
|
|
8030
|
+
onFocusCapture: owner.claim,
|
|
8031
|
+
onPointerDownCapture: owner.claim
|
|
8032
|
+
}), [owner.claim]);
|
|
8033
|
+
return {
|
|
8034
|
+
slots: [{
|
|
8035
|
+
ref: a,
|
|
8036
|
+
front: front === 0
|
|
8037
|
+
}, {
|
|
8038
|
+
ref: b,
|
|
8039
|
+
front: front === 1
|
|
8040
|
+
}],
|
|
8041
|
+
time,
|
|
8042
|
+
duration: times.duration,
|
|
8043
|
+
index,
|
|
8044
|
+
starts: times.at,
|
|
8045
|
+
playing,
|
|
8046
|
+
ended: !playing && clips.length > 0 && time >= times.duration - 1e-6,
|
|
8047
|
+
loading,
|
|
8048
|
+
error,
|
|
8049
|
+
volume,
|
|
8050
|
+
play,
|
|
8051
|
+
pause,
|
|
8052
|
+
toggle: () => live.current.playing ? pause() : play(),
|
|
8053
|
+
seek,
|
|
8054
|
+
step,
|
|
8055
|
+
setVolume,
|
|
8056
|
+
retry,
|
|
8057
|
+
ownsKeys: owner.owns,
|
|
8058
|
+
regionProps
|
|
8059
|
+
};
|
|
8060
|
+
}
|
|
8061
|
+
/** Plays an edit list (stretches of files) as one timeline with no gap at the cuts, with a seek bar marked at every clip, frame steps and the page's keys. */
|
|
8062
|
+
function EditListPlayer({ clips, label, empty, aspect = 16 / 9, fps, onClipChange, shortcuts = true, playerRef, className }) {
|
|
8063
|
+
const edit = useEditList(clips, {
|
|
8064
|
+
fps,
|
|
8065
|
+
onClipChange,
|
|
8066
|
+
keys: shortcuts
|
|
8067
|
+
});
|
|
8068
|
+
React.useImperativeHandle(playerRef, () => edit, [edit]);
|
|
8069
|
+
const marks = React.useMemo(() => clips.map((c, i) => ({
|
|
8070
|
+
time: edit.starts[i],
|
|
8071
|
+
label: c.label ?? `Clip ${i + 1}`,
|
|
8072
|
+
kind: "scene"
|
|
8073
|
+
})), [clips, edit.starts]);
|
|
8074
|
+
const toClip = (dir) => {
|
|
8075
|
+
const i = edit.index;
|
|
8076
|
+
if (dir < 0) {
|
|
8077
|
+
const into = edit.time - edit.starts[i];
|
|
8078
|
+
edit.seek(edit.starts[into > 1 || i === 0 ? i : i - 1]);
|
|
8079
|
+
} else if (i + 1 < clips.length) edit.seek(edit.starts[i + 1]);
|
|
8080
|
+
};
|
|
8081
|
+
const frame = fps ? 1 / fps : void 0;
|
|
8082
|
+
const keyList = [
|
|
8083
|
+
{
|
|
8084
|
+
keys: [" ", "k"],
|
|
8085
|
+
label: "Play or pause",
|
|
8086
|
+
run: edit.toggle
|
|
8087
|
+
},
|
|
8088
|
+
{
|
|
8089
|
+
keys: ["j"],
|
|
8090
|
+
label: "Back 10 seconds",
|
|
8091
|
+
run: () => edit.seek(edit.time - 10)
|
|
8092
|
+
},
|
|
8093
|
+
{
|
|
8094
|
+
keys: ["l"],
|
|
8095
|
+
label: "Forward 10 seconds",
|
|
8096
|
+
run: () => edit.seek(edit.time + 10)
|
|
8097
|
+
},
|
|
8098
|
+
{
|
|
8099
|
+
keys: ["p"],
|
|
8100
|
+
label: "Previous clip",
|
|
8101
|
+
run: () => toClip(-1)
|
|
8102
|
+
},
|
|
8103
|
+
{
|
|
8104
|
+
keys: ["n"],
|
|
8105
|
+
label: "Next clip",
|
|
8106
|
+
run: () => toClip(1)
|
|
8107
|
+
},
|
|
8108
|
+
...frame ? [{
|
|
8109
|
+
keys: [","],
|
|
8110
|
+
label: "Back one frame",
|
|
8111
|
+
run: () => edit.step(-1)
|
|
8112
|
+
}, {
|
|
8113
|
+
keys: ["."],
|
|
8114
|
+
label: "Forward one frame",
|
|
8115
|
+
run: () => edit.step(1)
|
|
8116
|
+
}] : [],
|
|
8117
|
+
{
|
|
8118
|
+
keys: ["Home"],
|
|
8119
|
+
label: "Go to start",
|
|
8120
|
+
run: () => edit.seek(0)
|
|
8121
|
+
},
|
|
8122
|
+
{
|
|
8123
|
+
keys: ["End"],
|
|
8124
|
+
label: "Go to end",
|
|
8125
|
+
run: () => edit.seek(edit.duration)
|
|
8126
|
+
}
|
|
8127
|
+
];
|
|
8128
|
+
useHotkeys(keyList, { enabled: shortcuts && edit.ownsKeys && clips.length > 0 });
|
|
8129
|
+
const current = edit.index >= 0 ? clips[edit.index] : void 0;
|
|
8130
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
8131
|
+
role: "group",
|
|
8132
|
+
"aria-label": label,
|
|
8133
|
+
...edit.regionProps,
|
|
8134
|
+
className: cn("grid min-w-0 gap-2", className),
|
|
8135
|
+
children: [
|
|
8136
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8137
|
+
className: "relative w-full overflow-hidden rounded-surface bg-surface-sunken",
|
|
8138
|
+
style: { aspectRatio: aspect },
|
|
8139
|
+
children: [
|
|
8140
|
+
edit.slots.map((slot, i) => /* @__PURE__ */ jsx("video", {
|
|
8141
|
+
ref: slot.ref,
|
|
8142
|
+
playsInline: true,
|
|
8143
|
+
preload: "auto",
|
|
8144
|
+
"aria-hidden": !slot.front,
|
|
8145
|
+
"data-front": slot.front ? "" : void 0,
|
|
8146
|
+
onClick: slot.front && clips.length ? edit.toggle : void 0,
|
|
8147
|
+
className: "absolute inset-0 size-full object-contain"
|
|
8148
|
+
}, i)),
|
|
8149
|
+
clips.length === 0 && /* @__PURE__ */ jsx("div", {
|
|
8150
|
+
className: "absolute inset-0 grid place-items-center p-4 text-center type-body-sm text-muted-foreground",
|
|
8151
|
+
children: empty
|
|
8152
|
+
}),
|
|
8153
|
+
edit.loading && !edit.error && /* @__PURE__ */ jsx("div", {
|
|
8154
|
+
className: "pointer-events-none absolute top-3 left-3",
|
|
8155
|
+
children: /* @__PURE__ */ jsx(Status, {
|
|
8156
|
+
tone: "info",
|
|
8157
|
+
icon: LoaderCircle,
|
|
8158
|
+
children: "Loading"
|
|
8159
|
+
})
|
|
8160
|
+
})
|
|
8161
|
+
]
|
|
8162
|
+
}),
|
|
8163
|
+
edit.error && /* @__PURE__ */ jsx(Alert, {
|
|
8164
|
+
tone: edit.error.kind === "load" ? "danger" : "info",
|
|
8165
|
+
announce: true,
|
|
8166
|
+
action: edit.error.kind === "load" ? /* @__PURE__ */ jsx(Button, {
|
|
8167
|
+
size: "sm",
|
|
8168
|
+
onPress: edit.retry,
|
|
8169
|
+
children: "Try again"
|
|
8170
|
+
}) : void 0,
|
|
8171
|
+
children: edit.error.message
|
|
8172
|
+
}),
|
|
8173
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8174
|
+
className: "flex min-w-0 items-center gap-3",
|
|
8175
|
+
children: [/* @__PURE__ */ jsx(SeekBar, {
|
|
8176
|
+
time: edit.time,
|
|
8177
|
+
duration: clips.length ? edit.duration : null,
|
|
8178
|
+
onSeek: edit.seek,
|
|
8179
|
+
marks,
|
|
8180
|
+
onMarkPress: (m) => edit.seek(m.time),
|
|
8181
|
+
step: 10,
|
|
8182
|
+
bigStep: 60,
|
|
8183
|
+
label: `Seek in ${label}`,
|
|
8184
|
+
disabled: clips.length === 0
|
|
8185
|
+
}), /* @__PURE__ */ jsx(TimeReadout, {
|
|
8186
|
+
time: edit.time,
|
|
8187
|
+
duration: clips.length ? edit.duration : null
|
|
8188
|
+
})]
|
|
8189
|
+
}),
|
|
8190
|
+
/* @__PURE__ */ jsxs("div", {
|
|
8191
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
8192
|
+
children: [
|
|
8193
|
+
/* @__PURE__ */ jsxs(Toolbar, {
|
|
8194
|
+
label: "Playback",
|
|
8195
|
+
className: "gap-2",
|
|
8196
|
+
children: [
|
|
8197
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
8198
|
+
icon: SkipBack,
|
|
8199
|
+
label: "Previous clip",
|
|
8200
|
+
hint: "P",
|
|
8201
|
+
disabled: clips.length === 0,
|
|
8202
|
+
onPress: () => toClip(-1)
|
|
8203
|
+
}),
|
|
8204
|
+
frame && /* @__PURE__ */ jsx(IconButton, {
|
|
8205
|
+
icon: StepBack,
|
|
8206
|
+
label: "Back one frame",
|
|
8207
|
+
hint: ",",
|
|
8208
|
+
disabled: clips.length === 0,
|
|
8209
|
+
onPress: () => edit.step(-1)
|
|
8210
|
+
}),
|
|
8211
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
8212
|
+
icon: edit.playing ? Pause : Play,
|
|
8213
|
+
label: edit.playing ? "Pause" : "Play",
|
|
8214
|
+
hint: "Space",
|
|
8215
|
+
variant: "outline",
|
|
8216
|
+
disabled: clips.length === 0,
|
|
8217
|
+
onPress: edit.toggle
|
|
8218
|
+
}),
|
|
8219
|
+
frame && /* @__PURE__ */ jsx(IconButton, {
|
|
8220
|
+
icon: StepForward,
|
|
8221
|
+
label: "Forward one frame",
|
|
8222
|
+
hint: ".",
|
|
8223
|
+
disabled: clips.length === 0,
|
|
8224
|
+
onPress: () => edit.step(1)
|
|
8225
|
+
}),
|
|
8226
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
8227
|
+
icon: SkipForward,
|
|
8228
|
+
label: "Next clip",
|
|
8229
|
+
hint: "N",
|
|
8230
|
+
disabled: clips.length === 0 || edit.index >= clips.length - 1,
|
|
8231
|
+
onPress: () => toClip(1)
|
|
8232
|
+
})
|
|
8233
|
+
]
|
|
8234
|
+
}),
|
|
8235
|
+
current && /* @__PURE__ */ jsxs("span", {
|
|
8236
|
+
className: "min-w-0 truncate type-body-sm text-muted-foreground",
|
|
8237
|
+
children: [
|
|
8238
|
+
"Clip ",
|
|
8239
|
+
edit.index + 1,
|
|
8240
|
+
" of ",
|
|
8241
|
+
clips.length,
|
|
8242
|
+
current.label ? `: ${current.label}` : ""
|
|
8243
|
+
]
|
|
8244
|
+
}),
|
|
8245
|
+
/* @__PURE__ */ jsx("span", {
|
|
8246
|
+
className: "ml-auto flex items-center gap-x-3",
|
|
8247
|
+
children: /* @__PURE__ */ jsx(VolumeControl, {
|
|
8248
|
+
volume: edit.volume,
|
|
8249
|
+
onVolumeChange: edit.setVolume
|
|
8250
|
+
})
|
|
8251
|
+
})
|
|
8252
|
+
]
|
|
8253
|
+
})
|
|
8254
|
+
]
|
|
8255
|
+
});
|
|
8256
|
+
}
|
|
8257
|
+
|
|
7550
8258
|
// src/lib/timeline.ts
|
|
7551
8259
|
/** Steps a person would write on a scale, in seconds: 1, 2, 5 and 10 × 10ⁿ below a minute, then 15 s, 30 s, minutes, quarter hours, hours, days. ux-research components.md §3.8: ticks land on values people would write. */
|
|
7552
8260
|
const STEPS = [
|
|
@@ -11706,18 +12414,63 @@ function ViewOptions({ view, shown, total, label = "View options", className })
|
|
|
11706
12414
|
});
|
|
11707
12415
|
}
|
|
11708
12416
|
|
|
12417
|
+
// src/lib/beckon.ts
|
|
12418
|
+
/** The thing to pulse next: any of `open` but `last`, at random (or the only one). */
|
|
12419
|
+
function nextBeckon(open, last) {
|
|
12420
|
+
const others = open.length > 1 ? open.filter((k) => k !== last) : open;
|
|
12421
|
+
return others[Math.floor(Math.random() * others.length)] ?? null;
|
|
12422
|
+
}
|
|
12423
|
+
const SEP$1 = "\0";
|
|
12424
|
+
/** Which of `open` pulses now, moving every `ms` while `on`; null when off or none is open. The class alternates
|
|
12425
|
+
* between two names of the same pulse each beat: a CSS animation runs again only when its name changes, so the last
|
|
12426
|
+
* open tile, lit beat after beat, still pulses each time (Codex on #400). */
|
|
12427
|
+
function useBeckon(on, open, ms) {
|
|
12428
|
+
const [lit, setLit] = React.useState(null);
|
|
12429
|
+
const openKey = open.join(SEP$1);
|
|
12430
|
+
React.useEffect(() => {
|
|
12431
|
+
if (!on || openKey === "") return;
|
|
12432
|
+
const keys = openKey.split(SEP$1);
|
|
12433
|
+
let last = null;
|
|
12434
|
+
let beat = 0;
|
|
12435
|
+
const t = setInterval(() => {
|
|
12436
|
+
last = nextBeckon(keys, last);
|
|
12437
|
+
beat += 1;
|
|
12438
|
+
setLit(last === null ? null : {
|
|
12439
|
+
key: last,
|
|
12440
|
+
beat
|
|
12441
|
+
});
|
|
12442
|
+
}, ms);
|
|
12443
|
+
return () => {
|
|
12444
|
+
clearInterval(t);
|
|
12445
|
+
setLit(null);
|
|
12446
|
+
};
|
|
12447
|
+
}, [
|
|
12448
|
+
on,
|
|
12449
|
+
openKey,
|
|
12450
|
+
ms
|
|
12451
|
+
]);
|
|
12452
|
+
return lit !== null && open.includes(lit.key) ? {
|
|
12453
|
+
key: lit.key,
|
|
12454
|
+
className: lit.beat % 2 ? "beckon" : "beckon-again"
|
|
12455
|
+
} : null;
|
|
12456
|
+
}
|
|
12457
|
+
/** A tile's picture: the `type-picture` step, but never more than 75% of the tile it sits in (the tile is a size
|
|
12458
|
+
* container), so an app that grows the step on a wide screen does not push a picture out of a small tile. */
|
|
12459
|
+
const pictureInTile = { fontSize: "min(var(--type-picture-size, 4.5rem), 75cqi)" };
|
|
12460
|
+
|
|
11709
12461
|
// src/components/choice-grid.tsx
|
|
11710
12462
|
const minSide = {
|
|
11711
12463
|
md: 120,
|
|
11712
12464
|
lg: 160
|
|
11713
12465
|
};
|
|
11714
12466
|
const closed = (s) => s === "right" || s === "answer" || s === "picked";
|
|
11715
|
-
const columns = (size) => ({ gridTemplateColumns: `repeat(auto-fill, minmax(min(${minSide[size]}px, 100%), 1fr))` });
|
|
12467
|
+
const columns = (size, stretch = false) => ({ gridTemplateColumns: `repeat(${stretch ? "auto-fit" : "auto-fill"}, minmax(min(${minSide[size]}px, 100%), 1fr))` });
|
|
11716
12468
|
/** A grid of large picture tiles for answering one question with a tap: each tile open, wrong, right, shown as the answer or (no answer key) picked, with its word; answered tiles cannot be pressed again, and the grid closes once the answer shows. */
|
|
11717
|
-
function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, marks, onChoose, size = "md", className }) {
|
|
12469
|
+
function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, marks, onChoose, size = "md", stretch = false, beckon = false, beckonMs = 1600, className }) {
|
|
11718
12470
|
const byKey = new Map(items.map((item) => [itemKey(item), item]));
|
|
11719
12471
|
const over = items.some((item) => closed(state(item)));
|
|
11720
12472
|
const disabledKeys = items.filter((item) => over || state(item) !== "open").map(itemKey);
|
|
12473
|
+
const lit = useBeckon(beckon && !over, items.filter((item) => state(item) === "open").map(itemKey), beckonMs);
|
|
11721
12474
|
return /* @__PURE__ */ jsx(GridList, {
|
|
11722
12475
|
"aria-label": label,
|
|
11723
12476
|
layout: "grid",
|
|
@@ -11728,7 +12481,7 @@ function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, ma
|
|
|
11728
12481
|
if (item !== void 0) onChoose(item);
|
|
11729
12482
|
},
|
|
11730
12483
|
className: cn("grid min-w-0 gap-4 outline-none", className),
|
|
11731
|
-
style: columns(size),
|
|
12484
|
+
style: columns(size, stretch),
|
|
11732
12485
|
children: items.map((item) => {
|
|
11733
12486
|
const key = itemKey(item);
|
|
11734
12487
|
const s = state(item);
|
|
@@ -11738,10 +12491,12 @@ function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, ma
|
|
|
11738
12491
|
textValue: itemLabel(item),
|
|
11739
12492
|
"aria-label": mark ? `${itemLabel(item)}, ${mark.toLowerCase()}` : itemLabel(item),
|
|
11740
12493
|
"data-choice": s,
|
|
11741
|
-
|
|
12494
|
+
"data-beckon": key === lit?.key || void 0,
|
|
12495
|
+
className: cn("@container flex aspect-square min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-2 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", key === lit?.key && cn(lit.className, "border-primary"), (s === "right" || s === "answer") && "border-4 border-success bg-success-subtle disabled:hover:border-success", s === "picked" && "border-4 border-primary bg-surface-sunken disabled:hover:border-primary"),
|
|
11742
12496
|
children: [/* @__PURE__ */ jsx("span", {
|
|
11743
12497
|
"aria-hidden": true,
|
|
11744
12498
|
className: cn("type-picture transition-state", s === "wrong" && "opacity-40"),
|
|
12499
|
+
style: pictureInTile,
|
|
11745
12500
|
children: renderPicture(item)
|
|
11746
12501
|
}), mark && /* @__PURE__ */ jsx(Status, {
|
|
11747
12502
|
tone: s === "wrong" || s === "picked" ? "neutral" : "success",
|
|
@@ -11753,11 +12508,11 @@ function ChoiceGrid({ label, items, itemKey, itemLabel, renderPicture, state, ma
|
|
|
11753
12508
|
});
|
|
11754
12509
|
}
|
|
11755
12510
|
/** The loading shape of a `ChoiceGrid`: `count` tiles at the same size, for a `DataView` skeleton. */
|
|
11756
|
-
function ChoiceGridSkeleton({ count = 4, size = "md", className }) {
|
|
12511
|
+
function ChoiceGridSkeleton({ count = 4, size = "md", stretch = false, className }) {
|
|
11757
12512
|
return /* @__PURE__ */ jsx("div", {
|
|
11758
12513
|
"aria-hidden": true,
|
|
11759
12514
|
className: cn("grid min-w-0 gap-4", className),
|
|
11760
|
-
style: columns(size),
|
|
12515
|
+
style: columns(size, stretch),
|
|
11761
12516
|
children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx("span", { className: "block aspect-square rounded-overlay bg-muted" }, i))
|
|
11762
12517
|
});
|
|
11763
12518
|
}
|
|
@@ -11768,7 +12523,8 @@ const placedSide = 72;
|
|
|
11768
12523
|
const placedPicture = { "--type-picture-size": "2.5rem" };
|
|
11769
12524
|
const placeSide = 160;
|
|
11770
12525
|
/** Pictures put into places with two taps (pick up, put down) for an answer that is an arrangement: give a number, order, match, sort. The app owns where each piece is and checks it; the board only moves what the learner asks. */
|
|
11771
|
-
function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, className }) {
|
|
12526
|
+
function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, className }) {
|
|
12527
|
+
const fill = stretch ? "auto-fit" : "auto-fill";
|
|
11772
12528
|
const [heldKey, setHeld] = React.useState(null);
|
|
11773
12529
|
const [follow, setFollow] = React.useState(null);
|
|
11774
12530
|
const buttons = React.useRef(/* @__PURE__ */ new Map());
|
|
@@ -11779,6 +12535,7 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
|
|
|
11779
12535
|
};
|
|
11780
12536
|
const held = locked ? void 0 : pieces.find((p) => pieceKey(p) === heldKey);
|
|
11781
12537
|
const heldAt = held === void 0 ? null : where(held);
|
|
12538
|
+
const lit = useBeckon(beckon && !locked && held === void 0, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
|
|
11782
12539
|
React.useEffect(() => {
|
|
11783
12540
|
if (follow === null) return;
|
|
11784
12541
|
buttons.current.get(follow)?.focus();
|
|
@@ -11804,11 +12561,15 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
|
|
|
11804
12561
|
isDisabled: locked,
|
|
11805
12562
|
"aria-label": isHeld ? `${pieceLabel(p)}, ${marks.held.toLowerCase()}` : pieceLabel(p),
|
|
11806
12563
|
"data-held": isHeld || void 0,
|
|
11807
|
-
|
|
12564
|
+
"data-beckon": key === lit?.key || void 0,
|
|
12565
|
+
className: cn("@container flex aspect-square min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-4 selected:border-primary selected:bg-muted", key === lit?.key && cn(lit.className, "border-primary")),
|
|
11808
12566
|
children: [/* @__PURE__ */ jsx("span", {
|
|
11809
12567
|
"aria-hidden": true,
|
|
11810
12568
|
className: "type-picture",
|
|
11811
|
-
style: placed ?
|
|
12569
|
+
style: placed ? {
|
|
12570
|
+
...placedPicture,
|
|
12571
|
+
...pictureInTile
|
|
12572
|
+
} : pictureInTile,
|
|
11812
12573
|
children: renderPiece(p)
|
|
11813
12574
|
}), isHeld && /* @__PURE__ */ jsx(Status, {
|
|
11814
12575
|
tone: "info",
|
|
@@ -11821,7 +12582,7 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
|
|
|
11821
12582
|
role: "group",
|
|
11822
12583
|
"aria-label": name,
|
|
11823
12584
|
className: "grid min-w-0 gap-2",
|
|
11824
|
-
style: { gridTemplateColumns: `repeat(auto-fill, minmax(min(${side}px, 100%), 1fr))` },
|
|
12585
|
+
style: { gridTemplateColumns: `repeat(${side === placedSide ? "auto-fill" : fill}, minmax(min(${side}px, 100%), 1fr))` },
|
|
11825
12586
|
children: inside.map((p) => piece(p, side === placedSide))
|
|
11826
12587
|
});
|
|
11827
12588
|
const pile = pieces.filter((p) => where(p) === null);
|
|
@@ -11837,7 +12598,7 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
|
|
|
11837
12598
|
})]
|
|
11838
12599
|
}), /* @__PURE__ */ jsx("div", {
|
|
11839
12600
|
className: "grid min-w-0 gap-4",
|
|
11840
|
-
style: { gridTemplateColumns: `repeat(
|
|
12601
|
+
style: { gridTemplateColumns: `repeat(${fill}, minmax(min(${placeSide}px, 100%), 1fr))` },
|
|
11841
12602
|
children: places.map((s) => {
|
|
11842
12603
|
const key = placeKey(s);
|
|
11843
12604
|
const state = placeState(s);
|
|
@@ -20296,5 +21057,5 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
|
|
|
20296
21057
|
});
|
|
20297
21058
|
}
|
|
20298
21059
|
|
|
20299
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
|
|
21060
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EditListPlayer, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, continues, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, editTimeOf, editTimes, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, followAim, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, locateInEdit, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, nextBreak, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useEditList, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSettledStatus, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewPointers, useViewport, useWheelZoom, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
|
|
20300
21061
|
//# sourceMappingURL=index.js.map
|