Skip to content

Commit

Permalink
unfuck imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sphinxrave committed Dec 27, 2024
1 parent 1ec0fe9 commit 7b6e596
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 208 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/Kitchensink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FancyMultiSelect } from "./shadcn/ui/fancy-multiselect";
import { Switch } from "./shadcn/ui/switch";
import { Label } from "./shadcn/ui/label";
import { Checkbox } from "./shadcn/ui/checkbox";
import DemoTimeline from "./components/tldex/new-editor/components/Timeline/DemoTimeline";
// import DemoTimeline from "./components/tldex/new-editor/components/Timeline/DemoTimeline";

export function Kitchensink() {
const [count, setCount] = useState(0);
Expand Down Expand Up @@ -116,7 +116,7 @@ export function Kitchensink() {

{/* <WaveformTestPage /> */}

<DemoTimeline />
{/* <DemoTimeline /> */}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,106 +1,106 @@
import React from "react";
import { Rnd } from "react-rnd";
import { useSpecificSubtitle } from "../../hooks/subtitles";
// import React from "react";
// import { Rnd } from "react-rnd";
// import { useSpecificSubtitle } from "../../hooks/subtitles";

/**
* Properties for the RndSubtitle component.
*
* @property {string} subtitleId Unique identifier for the subtitle.
* @property {number} startTime Start time of the timeline range for the subtitle.
* @property {number} endTime End time of the timeline range for the subtitle.
* @property {number} containerWidth Width of the container in which the subtitle is displayed.
*/
interface RndSubtitleProps {
subtitleId: string;
startTime: number;
endTime: number;
containerWidth: number;
}
/**
* RndSubtitle is a resizable and draggable subtitle component for editing video subtitles.
* It utilizes the react-rnd library to allow users to adjust the position
* and duration of a subtitle by dragging or resizing the subtitle box.
*
* Props:
* - subtitleId: Unique identifier for the subtitle.
* - startTime: Start time of the timeline range for the subtitle.
* - endTime: End time of the timeline range for the subtitle.
* - containerWidth: Width of the container in which the subtitle is displayed.
*
* The component provides internal functions to convert time to position and vice versa,
* and handlers to update subtitle start time and duration upon dragging or resizing.
*/
export const RndSubtitle: React.FC<RndSubtitleProps> = ({
subtitleId,
startTime,
endTime,
containerWidth,
}) => {
const [subtitle, edit] = useSpecificSubtitle(subtitleId);
// /**
// * Properties for the RndSubtitle component.
// *
// * @property {string} subtitleId Unique identifier for the subtitle.
// * @property {number} startTime Start time of the timeline range for the subtitle.
// * @property {number} endTime End time of the timeline range for the subtitle.
// * @property {number} containerWidth Width of the container in which the subtitle is displayed.
// */
// interface RndSubtitleProps {
// subtitleId: string;
// startTime: number;
// endTime: number;
// containerWidth: number;
// }
// /**
// * RndSubtitle is a resizable and draggable subtitle component for editing video subtitles.
// * It utilizes the react-rnd library to allow users to adjust the position
// * and duration of a subtitle by dragging or resizing the subtitle box.
// *
// * Props:
// * - subtitleId: Unique identifier for the subtitle.
// * - startTime: Start time of the timeline range for the subtitle.
// * - endTime: End time of the timeline range for the subtitle.
// * - containerWidth: Width of the container in which the subtitle is displayed.
// *
// * The component provides internal functions to convert time to position and vice versa,
// * and handlers to update subtitle start time and duration upon dragging or resizing.
// */
// export const RndSubtitle: React.FC<RndSubtitleProps> = ({
// subtitleId,
// startTime,
// endTime,
// containerWidth,
// }) => {
// const [subtitle, edit] = useSpecificSubtitle(subtitleId);

const timeToPosition = (time: number) => {
const timeRange = endTime - startTime;
const position = ((time - startTime) / timeRange) * containerWidth;
return position;
};
// const timeToPosition = (time: number) => {
// const timeRange = endTime - startTime;
// const position = ((time - startTime) / timeRange) * containerWidth;
// return position;
// };

const positionToTime = (position: number) => {
const timeRange = endTime - startTime;
const time = (position / containerWidth) * timeRange + startTime;
return Math.max(startTime, Math.min(time, endTime));
};
// const positionToTime = (position: number) => {
// const timeRange = endTime - startTime;
// const time = (position / containerWidth) * timeRange + startTime;
// return Math.max(startTime, Math.min(time, endTime));
// };

const handleDrag = (_: unknown, d: { x: number; y: number }) => {
const newStartTime = positionToTime(d.x);
edit({
type: "UPDATE_SUBTITLE",
payload: {
...subtitle,
video_offset: newStartTime,
end: newStartTime + subtitle.duration / 1000,
},
});
};
// const handleDrag = (_: unknown, d: { x: number; y: number }) => {
// const newStartTime = positionToTime(d.x);
// edit({
// type: "UPDATE_SUBTITLE",
// payload: {
// ...subtitle,
// video_offset: newStartTime,
// end: newStartTime + subtitle.duration / 1000,
// },
// });
// };

const handleResize = (_: unknown, _direction: string, ref: HTMLElement) => {
const newWidth = ref.offsetWidth;
const newDuration =
(newWidth / containerWidth) * (endTime - startTime) * 1000;
edit({
type: "UPDATE_SUBTITLE",
payload: {
...subtitle,
duration: newDuration,
end: subtitle.video_offset + newDuration / 1000,
},
});
};
// const handleResize = (_: unknown, _direction: string, ref: HTMLElement) => {
// const newWidth = ref.offsetWidth;
// const newDuration =
// (newWidth / containerWidth) * (endTime - startTime) * 1000;
// edit({
// type: "UPDATE_SUBTITLE",
// payload: {
// ...subtitle,
// duration: newDuration,
// end: subtitle.video_offset + newDuration / 1000,
// },
// });
// };

return (
<Rnd
position={{
x: timeToPosition(subtitle.video_offset),
y: 15,
}}
size={{
width:
timeToPosition(
subtitle.video_offset + (subtitle.duration || 3000) / 1000,
) - timeToPosition(subtitle.video_offset),
height: 30,
}}
onDragStop={handleDrag}
onResize={handleResize}
bounds="parent"
className="border border-x-2 border-primary-9"
enableResizing={{ left: true, right: true }}
>
<div
className="h-full w-full cursor-move text-wrap bg-base-3 text-base-12 opacity-80 bg-blend-multiply"
title={subtitle.message}
>
<span className="truncate text-xs text-white">{subtitle.message}</span>
</div>
</Rnd>
);
};
// return (
// <Rnd
// position={{
// x: timeToPosition(subtitle.video_offset),
// y: 15,
// }}
// size={{
// width:
// timeToPosition(
// subtitle.video_offset + (subtitle.duration || 3000) / 1000,
// ) - timeToPosition(subtitle.video_offset),
// height: 30,
// }}
// onDragStop={handleDrag}
// onResize={handleResize}
// bounds="parent"
// className="border border-x-2 border-primary-9"
// enableResizing={{ left: true, right: true }}
// >
// <div
// className="h-full w-full cursor-move text-wrap bg-base-3 text-base-12 opacity-80 bg-blend-multiply"
// title={subtitle.message}
// >
// <span className="truncate text-xs text-white">{subtitle.message}</span>
// </div>
// </Rnd>
// );
// };
Loading

0 comments on commit 7b6e596

Please sign in to comment.