-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from jrafaaael/feat/crop
feat: crop
- Loading branch information
Showing
11 changed files
with
179 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { videoStatus } from '../stores/video-status.store'; | ||
import Cropper from './cropper.svelte'; | ||
let canvasRef: HTMLCanvasElement; | ||
onMount(() => { | ||
if (!$videoStatus.ref) return; | ||
const ctx = canvasRef.getContext('2d'); | ||
ctx?.drawImage( | ||
$videoStatus.ref, | ||
0, | ||
0, | ||
$videoStatus.ref.videoWidth, | ||
$videoStatus.ref.videoHeight | ||
); | ||
}); | ||
</script> | ||
|
||
<div class="w-full rounded-md relative"> | ||
{#if $videoStatus.ref} | ||
<canvas | ||
class="max-w-full max-h-[720px] block" | ||
width={$videoStatus.ref.videoWidth} | ||
height={$videoStatus.ref.videoHeight} | ||
bind:this={canvasRef} | ||
/> | ||
{/if} | ||
{#if canvasRef} | ||
<Cropper img={canvasRef} on:crop /> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts"> | ||
import * as Dialog from '$lib/components/dialog'; | ||
import { crop, type Crop as ICrop } from '../stores/crop.store'; | ||
import Crop from './icons/crop.svelte'; | ||
import CropFrame from './crop-frame.svelte'; | ||
let cropValue: ICrop | null = null; | ||
</script> | ||
|
||
<Dialog.Root> | ||
<Dialog.Trigger | ||
class="py-[5px] px-3 rounded-md text-neutral-300 flex justify-center items-center gap-2 absolute right-10 transition-all hover:bg-white/5 hover:text-neutral-200" | ||
> | ||
<span class="w-4 aspect-square"> | ||
<Crop /> | ||
</span> | ||
<span>Crop</span> | ||
</Dialog.Trigger> | ||
<Dialog.Content | ||
title="Crop recording" | ||
className={{ | ||
dialog: | ||
'w-[90vw] max-w-[1024px] h-fit p-6 bg-neutral-800 border border-white/5 rounded-xl flex flex-col gap-4 fixed left-1/2 top-1/2 z-20 shadow-lg -translate-x-1/2 -translate-y-1/2', | ||
title: 'text-lg font-medium' | ||
}} | ||
> | ||
<Dialog.Overlay slot="overlay" class="fixed inset-0 z-20 bg-black/50 backdrop-blur-sm" /> | ||
<CropFrame on:crop={({ detail }) => (cropValue = detail)} /> | ||
<div class="flex justify-end gap-2"> | ||
<Dialog.Close | ||
class="w-20 py-1 bg-white/5 border border-white/5 rounded-md text-sm text-neutral-50 hover:bg-white/10 hover:border-white/10" | ||
> | ||
Cancel | ||
</Dialog.Close> | ||
<Dialog.Close | ||
class="w-20 py-1 bg-purple-600 rounded-md text-sm text-neutral-50 hover:bg-purple-600/90" | ||
on:m-click={() => { | ||
$crop = cropValue; | ||
cropValue = null; | ||
}} | ||
> | ||
Save | ||
</Dialog.Close> | ||
</div> | ||
</Dialog.Content> | ||
</Dialog.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher, onMount } from 'svelte'; | ||
import Cropper from 'cropperjs'; | ||
import 'cropperjs/dist/cropper.min.css'; | ||
export let img: HTMLImageElement | HTMLCanvasElement; | ||
const dispatch = createEventDispatcher(); | ||
let cropper: Cropper | null = null; | ||
onMount(() => { | ||
cropper = new Cropper(img as HTMLImageElement, { | ||
dragMode: 'none', | ||
viewMode: 2, | ||
autoCropArea: 1, | ||
background: false, | ||
movable: false, | ||
rotatable: false, | ||
scalable: false, | ||
zoomable: false, | ||
crop(event) { | ||
const { detail } = event; | ||
dispatch('crop', { ...detail }); | ||
} | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
class="lucide lucide-crop" | ||
><path d="M6 2v14a2 2 0 0 0 2 2h14" /> | ||
<path d="M18 22V8a2 2 0 0 0-2-2H2" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export interface Crop { | ||
width: number; | ||
height: number; | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export const crop = writable<Crop | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const videoStatus = writable({ | ||
currentTime: 0 | ||
}); | ||
interface VideoStatus { | ||
currentTime: number; | ||
ref: HTMLVideoElement | null; | ||
} | ||
|
||
export const DEFAULT_VALUE: VideoStatus = { | ||
currentTime: 0, | ||
ref: null | ||
}; | ||
|
||
export const videoStatus = writable<VideoStatus>(DEFAULT_VALUE); |