gradio/js/image/interactive/Cropper.svelte
pngwn 1419538ea7
Refactor component directories (#5074)
* asd

* changes

* fix everything

* cleanup

* add changeset

* fix casing

* lockfile

* fix casing

* fix ci, enable linting

* fix test

* add changeset

* add changeset

* delete changeset

* fix dirs

* fix casing

* fix notebooks

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2023-08-03 23:01:18 +01:00

34 lines
663 B
Svelte

<svelte:options accessors={true} />
<script lang="ts">
import Cropper from "cropperjs";
import { onMount, createEventDispatcher } from "svelte";
export let image: string;
let el: HTMLImageElement;
const dispatch = createEventDispatcher();
let cropper: Cropper;
export function destroy(): void {
cropper.destroy();
}
export function create(): void {
if (cropper) {
destroy();
}
cropper = new Cropper(el, {
autoCropArea: 1,
cropend(): void {
const image_data = cropper.getCroppedCanvas().toDataURL();
dispatch("crop", image_data);
}
});
dispatch("crop", image);
}
</script>
<img src={image} bind:this={el} alt="" />