Added horizontal support for transcript tool
This commit is contained in:
parent
c69b4478f7
commit
ebd3f75804
|
@ -18,9 +18,14 @@ import { cIf, cJoin } from "helpers/className";
|
||||||
* ────────────────────────────────────────╯ CONSTANTS ╰──────────────────────────────────────────
|
* ────────────────────────────────────────╯ CONSTANTS ╰──────────────────────────────────────────
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
type Orientation = "horizontal" | "vertical";
|
||||||
|
|
||||||
const textAtom = atomPairing(atomWithStorage("transcriptText", ""));
|
const textAtom = atomPairing(atomWithStorage("transcriptText", ""));
|
||||||
const fontSizeAtom = atomPairing(atomWithStorage("transcriptFontSize", 1));
|
const fontSizeAtom = atomPairing(atomWithStorage("transcriptFontSize", 1));
|
||||||
const textOffset = atomPairing(atomWithStorage("transcriptTextOffset", 0));
|
const textOffsetAtom = atomPairing(atomWithStorage("transcriptTextOffset", 0));
|
||||||
|
const orientationAtom = atomPairing(
|
||||||
|
atomWithStorage<Orientation>("transcriptOrientation", "vertical")
|
||||||
|
);
|
||||||
|
|
||||||
const SIZE_MULTIPLIER = 1000;
|
const SIZE_MULTIPLIER = 1000;
|
||||||
|
|
||||||
|
@ -50,7 +55,8 @@ const swapChar = (char: string, swaps: string[]): string => {
|
||||||
const Transcript = (props: Props): JSX.Element => {
|
const Transcript = (props: Props): JSX.Element => {
|
||||||
const [text, setText] = useAtomPair(textAtom);
|
const [text, setText] = useAtomPair(textAtom);
|
||||||
const [fontSize, setFontSize] = useAtomPair(fontSizeAtom);
|
const [fontSize, setFontSize] = useAtomPair(fontSizeAtom);
|
||||||
const [xOffset, setXOffset] = useAtomPair(textOffset);
|
const [offset, setOffset] = useAtomPair(textOffsetAtom);
|
||||||
|
const [orientation, setOrientation] = useAtomPair(orientationAtom);
|
||||||
const [lineIndex, setLineIndex] = useState(0);
|
const [lineIndex, setLineIndex] = useState(0);
|
||||||
|
|
||||||
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
@ -409,52 +415,32 @@ const Transcript = (props: Props): JSX.Element => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const contentPanel = (
|
const contentPanel = (
|
||||||
<ContentPanel width={ContentPanelWidthSizes.Full} className="!pr-0 !pt-0">
|
<ContentPanel width={ContentPanelWidthSizes.Full} className="!pt-2">
|
||||||
<div
|
<div className="flex flex-wrap items-end gap-4 pr-24">
|
||||||
className={cJoin("grid", cIf(image, "grid-cols-[1fr_5rem_20rem]", "grid-cols-[1fr_5rem]"))}>
|
<ButtonGroup
|
||||||
<textarea
|
buttonsProps={[
|
||||||
ref={textAreaRef}
|
{
|
||||||
onChange={updateDisplayedText}
|
active: orientation === "horizontal",
|
||||||
onClick={updateLineIndex}
|
icon: "text_rotation_none",
|
||||||
onKeyUp={updateLineIndex}
|
onClick: () => setOrientation("horizontal"),
|
||||||
title="Input textarea"
|
},
|
||||||
className="mt-4 whitespace-pre"
|
{
|
||||||
value={text}
|
active: orientation === "vertical",
|
||||||
|
icon: "text_rotate_vertical",
|
||||||
|
onClick: () => setOrientation("vertical"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p
|
|
||||||
className="z-10 mt-4 h-[80vh] whitespace-nowrap
|
|
||||||
font-bold [font-family:Noto_Serif_JP] [transform-origin:top_right]
|
|
||||||
[writing-mode:vertical-rl]"
|
|
||||||
style={{
|
|
||||||
transform: `scale(${fontSize}) translateX(${fontSize * xOffset}px)`,
|
|
||||||
}}>
|
|
||||||
{text.split("\n")[lineIndex]}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{image && (
|
|
||||||
<TransformWrapper
|
|
||||||
panning={{ velocityDisabled: true }}
|
|
||||||
alignmentAnimation={{ disabled: true }}
|
|
||||||
wheel={{ step: 0.05 }}
|
|
||||||
limitToBounds={false}>
|
|
||||||
<TransformComponent wrapperStyle={{ height: "95vh" }}>
|
|
||||||
<img src={image} alt="This provided image" className="w-full object-cover" />
|
|
||||||
</TransformComponent>
|
|
||||||
</TransformWrapper>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-wrap place-items-center gap-4 pr-24">
|
|
||||||
<div className="grid place-items-center">
|
<div className="grid place-items-center">
|
||||||
<p>Text offset: {xOffset}px</p>
|
<p>Text offset: {offset}px</p>
|
||||||
<input
|
<input
|
||||||
title="Font size multiplier"
|
title="Font size multiplier"
|
||||||
type="range"
|
type="range"
|
||||||
min="0"
|
min="0"
|
||||||
max="100"
|
max="100"
|
||||||
value={xOffset * 5}
|
value={offset * 5}
|
||||||
onChange={(event) => setXOffset(parseInt(event.target.value, 10) / 5)}
|
onChange={(event) => setOffset(parseInt(event.target.value, 10) / 5)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -586,6 +572,56 @@ const Transcript = (props: Props): JSX.Element => {
|
||||||
|
|
||||||
<input type="file" accept="image/png, image/jpeg, image/webp" onChange={onImageUploaded} />
|
<input type="file" accept="image/png, image/jpeg, image/webp" onChange={onImageUploaded} />
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
className={cJoin(
|
||||||
|
"grid h-[90vh]",
|
||||||
|
cIf(
|
||||||
|
orientation === "vertical",
|
||||||
|
cIf(image, "grid-cols-[1fr_5rem_20rem]", "grid-cols-[1fr_5rem]"),
|
||||||
|
cIf(image, "grid-rows-[1fr_5rem_20rem]", "grid-rows-[1fr_5rem]")
|
||||||
|
)
|
||||||
|
)}>
|
||||||
|
<textarea
|
||||||
|
ref={textAreaRef}
|
||||||
|
onChange={updateDisplayedText}
|
||||||
|
onClick={updateLineIndex}
|
||||||
|
onKeyUp={updateLineIndex}
|
||||||
|
title="Input textarea"
|
||||||
|
className="mt-4 whitespace-pre"
|
||||||
|
value={text}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<p
|
||||||
|
className={cJoin(
|
||||||
|
`z-10 mt-4 whitespace-nowrap
|
||||||
|
font-bold [font-family:Noto_Serif_JP]`,
|
||||||
|
cIf(
|
||||||
|
orientation === "vertical",
|
||||||
|
"[transform-origin:top_right] [writing-mode:vertical-rl]",
|
||||||
|
"[transform-origin:top_left]"
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
style={{
|
||||||
|
transform: `scale(${fontSize}) ${
|
||||||
|
orientation === "vertical" ? "translateX" : "translateY"
|
||||||
|
}(${fontSize * offset}px)`,
|
||||||
|
}}>
|
||||||
|
{text.split("\n")[lineIndex]}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{image && (
|
||||||
|
<TransformWrapper
|
||||||
|
panning={{ velocityDisabled: true }}
|
||||||
|
alignmentAnimation={{ disabled: true }}
|
||||||
|
wheel={{ step: 0.05 }}
|
||||||
|
limitToBounds={false}
|
||||||
|
minScale={0.5}>
|
||||||
|
<TransformComponent wrapperStyle={{ height: "100%", width: "100%" }}>
|
||||||
|
<img src={image} alt="The provided image" className="w-full object-cover" />
|
||||||
|
</TransformComponent>
|
||||||
|
</TransformWrapper>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</ContentPanel>
|
</ContentPanel>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue