import { CSSProperties, useEffect, useState } from 'react';
import create from 'zustand';
import { loopSlide } from '../timeline';
import { TimedVideoPlayer } from './present';
import AppBar from '@material-ui/core/AppBar';
import Button from '@material-ui/core/Button';
import ButtonGroup from '@material-ui/core/ButtonGroup';
import Fab from '@material-ui/core/Fab';
import Slider from '@material-ui/core/Slider';
import Toolbar from '@material-ui/core/Toolbar';
import ZoomInRoundedIcon from '@material-ui/icons/ZoomInRounded';
import ZoomOutRoundedIcon from '@material-ui/icons/ZoomOutRounded';
import Icon from '@mdi/react';
import { PressureIcon, SlideKeyframe } from '../components/icons';
import Loop from '../components/loop';
import FullscreenRoundedIcon from '@material-ui/icons/FullscreenRounded';
import NavigateBeforeRoundedIcon from '@material-ui/icons/NavigateBeforeRounded';
import NavigateNextRoundedIcon from '@material-ui/icons/NavigateNextRounded';
import PauseRoundedIcon from '@material-ui/icons/PauseRounded';
import SkipPreviousRoundedIcon from '@material-ui/icons/SkipPreviousRounded';
import { mdiCursorDefault } from '@mdi/js';
var getTimelineZoom = create(set => ({
zoom: 0.2,
changeZoom: (delta: number) => set((st: any) => ({ zoom: Math.min(1, Math.max(0, st.zoom + delta)) })),
setZoom: (newValue: number) => set(() => ({ zoom: newValue })),
}));
function TimelineEditor(props: {
player: TimedVideoPlayer;
}) {
var keyframes = props.player?.timeline?.slides.map(slide =>
{slide.type == 'loop'
?
: }
);
useEffect(() => {
var canvas = document.getElementById('timeScaleCanvas') as HTMLCanvasElement;
var ctx = canvas.getContext('2d');
var mouseX = 0;
var mouseY = 0;
window.addEventListener('mousemove', e => {
var rect = canvas.getBoundingClientRect();
mouseX = e.clientX - rect.x;
mouseY = e.clientY - rect.y;
});
var css = (varname: string) => getComputedStyle(document.body).getPropertyValue(varname).trim();
var baseColor = css('--c100');
var frameColor = css('--c250');
var markerFrame = css('--c400');
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
var offset = document.querySelector('.timeline .timelineInner').scrollLeft;
var d = true;
var frameWidth = Number(
getComputedStyle(document.querySelector('.timeline')).getPropertyValue('--zoom').trim(),
);
var a = 1;
var ns = [300, 150, 120, 90, 60, 30, 30, 30, 20, 20, 20, 20, 20];
var everyN = ns[Math.floor(frameWidth)];
for (var x = -offset; x < canvas.width + offset; x += frameWidth) {
ctx.fillStyle = baseColor;
var rect = [Math.round(x + (frameWidth - 2) / 2), 28, 2, canvas.height];
var drawFrame = false;
if (frameWidth >= 3) {
ctx.fillStyle = d ? baseColor : frameColor;
rect = [x, 28, frameWidth, canvas.height];
drawFrame = !d;
}
/* if (a * 2 % everyN == 0) { */
/* ctx.fillStyle = frameColor; */
/* drawFrame = true; */
/* } */
if (a % everyN == 0) {
ctx.fillStyle = markerFrame;
drawFrame = true;
}
if (drawFrame) ctx.fillRect(rect[0], rect[1], rect[2], rect[3]);
d = !d;
a++;
}
requestAnimationFrame(draw);
}
draw();
function onresize() {
var size = document.querySelector('.timeline .timelineInner .keyframes');
canvas.width = size.clientWidth;
canvas.height = size.clientHeight;
}
onresize();
window.addEventListener('resize', onresize);
}, []);
return <>
>;
}
export default function Index() {
var [dummy, setDummy] = useState(false);
var rerender = () => setDummy(!dummy);
var [player, setPlayer] = useState(new TimedVideoPlayer());
var timelineZoom = getTimelineZoom((st: any) => st.zoom);
var setTimelineZoom = getTimelineZoom((st: any) => st.setZoom);
useEffect(() => {
var videoEL = document.getElementById('player') as HTMLVideoElement;
player.registerPlayer(videoEL);
}, []);
var changeZoom = getTimelineZoom(st => (st as any).changeZoom);
useEffect(() => {
document.querySelector('.timeline').addEventListener('wheel', (e: WheelEvent) => {
if (!e.ctrlKey && !e.altKey) return;
e.preventDefault();
changeZoom(-e.deltaY / 1000);
}, { passive: false });
}, []);
return <>
>;
}