diff --git a/package.json b/package.json index f0ccc17e..f1d5a3a7 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "scripts": { "build": "lerna run --stream x -- build", "watch": "lerna run --since HEAD --exclude-dependents --parallel x -- watch", - "watch-package": "lerna run --scope @*/mini-frame --include-dependencies --parallel x -- watch", "watch-all": "lerna run --parallel x -- watch", "storybook": "lerna run --scope storybook start --stream", "playground": "lerna run --scope @*/playground dev --stream", diff --git a/packages/player/package.json b/packages/player/package.json deleted file mode 100644 index 3b58b005..00000000 --- a/packages/player/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@code-hike/player", - "version": "0.3.0-next.0", - "private": "true", - "main": "dist/index.cjs.js", - "typings": "dist/index.d.ts", - "module": "dist/index.esm.js", - "files": [ - "dist" - ], - "scripts": { - "x": "x" - }, - "devDependencies": { - "@code-hike/script": "0.0.1", - "@types/react": "^17.0.2", - "react": "^17.0.2" - }, - "peerDependencies": { - "react": "^16.8.3 || ^17 || ^18" - }, - "keywords": [ - "react" - ], - "homepage": "https://codehike.org", - "repository": "code-hike/codehike", - "publishConfig": { - "access": "public" - }, - "author": "Rodrigo Pombo", - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/codehike" - } -} diff --git a/packages/player/readme.md b/packages/player/readme.md deleted file mode 100644 index 2a3bd5f6..00000000 --- a/packages/player/readme.md +++ /dev/null @@ -1 +0,0 @@ -See [codehike.org](https://codehike.org) diff --git a/packages/player/src/controls.tsx b/packages/player/src/controls.tsx deleted file mode 100644 index c2480b9a..00000000 --- a/packages/player/src/controls.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import React from "react"; - -export { Controls, useTimeData }; - -type Step = { - src: string; - start: number; - end: number; -}; - -type ControlsProps = { - steps: Step[]; - stepIndex: number; - videoTime: number; - onChange: (payload: { - stepIndex: number; - videoTime: number; - }) => void; -}; - -function Controls({ - steps, - stepIndex, - videoTime, - onChange, -}: ControlsProps) { - let cumulativeDuration = 0; - const stepsWithDuration = steps.map((s) => { - const duration = s.end - s.start; - cumulativeDuration += duration; - return { - ...s, - duration, - globalStart: cumulativeDuration - duration, - globalEnd: cumulativeDuration, - }; - }); - - const totalDuration = stepsWithDuration.reduce( - (t, s) => s.duration + t, - 0 - ); - - const stepTime = videoTime - stepsWithDuration[stepIndex].start; - const value = stepsWithDuration[stepIndex].globalStart + stepTime; - return ( - { - const value = +e.target.value; - for (let i = 0; i < stepsWithDuration.length; i++) { - if (value < stepsWithDuration[i].globalEnd) { - const stepTime = - value - stepsWithDuration[i].globalStart; - onChange({ - stepIndex: i, - videoTime: stepsWithDuration[i].start + stepTime, - }); - return; - } - } - }} - /> - ); -} - -function useTimeData({ - steps, - stepIndex, - videoTime, -}: ControlsProps) { - const [ - stepsWithDuration, - totalSeconds, - getStepAndTime, - ] = React.useMemo(() => { - let cumulativeDuration = 0; - const stepsWithDuration = steps.map((s) => { - const duration = s.end - s.start; - cumulativeDuration += duration; - return { - ...s, - duration, - globalStart: cumulativeDuration - duration, - globalEnd: cumulativeDuration, - }; - }); - const totalSeconds = stepsWithDuration.reduce( - (t, s) => s.duration + t, - 0 - ); - const getStepAndTime = (value: number) => { - for (let i = 0; i < stepsWithDuration.length; i++) { - if (value < stepsWithDuration[i].globalEnd) { - const stepTime = value - stepsWithDuration[i].globalStart; - return { - stepIndex: i, - videoTime: stepsWithDuration[i].start + stepTime, - }; - } - } - throw new Error("Value out of range"); - }; - return [stepsWithDuration, totalSeconds, getStepAndTime]; - }, [steps]); - - const currentStep = stepsWithDuration[stepIndex]; - const stepTime = videoTime - currentStep.start; - const currentSeconds = Math.min( - currentStep.globalStart + stepTime, - totalSeconds - ); - return { currentSeconds, totalSeconds, getStepAndTime }; -} diff --git a/packages/player/src/index.tsx b/packages/player/src/index.tsx deleted file mode 100644 index 8315ea11..00000000 --- a/packages/player/src/index.tsx +++ /dev/null @@ -1,4 +0,0 @@ -import { Controls, useTimeData } from "./controls" -import { VideoWrapper } from "./video-wrapper" - -export { VideoWrapper as Video, Controls, useTimeData } diff --git a/packages/player/src/video-wrapper.tsx b/packages/player/src/video-wrapper.tsx deleted file mode 100644 index c9dd2159..00000000 --- a/packages/player/src/video-wrapper.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import React from "react" -import { - PlayerHandle, - Step, - Video, - VideoProps, -} from "./video" - -const VideoWrapper = React.forwardRef(WrapperWithRef) - -export { VideoWrapper } - -function WrapperWithRef( - { - steps, - onTimeChange = () => {}, - onStepChange = () => {}, - ...props - }: VideoProps, - parentRef: React.Ref -) { - const stepGroups = useStepGroups( - steps, - onTimeChange, - onStepChange - ) - return ( -