Image Cropper
移动选区或调整它的大小,或者在选区下方平移和缩放图片,选出图片里要保留的部分。
用图片裁剪器选出照片里要保留的部分,比如头像或封面图。裁剪区域是图片自身像素里的一个方框,带有顺时针四分之一圈的旋转和一次翻转,可以直接传给 cropImage。
<script setup lang="ts">
import { CheckIcon, ChevronDownIcon } from "@lucide/vue"
import { cropImage } from "@ui-sdk/vue/image"
import {
ImageCropper,
ImageCropperGrid,
ImageCropperHandle,
ImageCropperImage,
ImageCropperSelection,
ImageCropperViewport,
type ImageCrop,
} from "@ui-sdk/vue/image-cropper"
import {
Select,
SelectContent,
SelectItem,
SelectItemIndicator,
SelectTrigger,
SelectValue,
} from "@ui-sdk/vue/select"
import { computed, onBeforeUnmount, ref } from "vue"
const photo = `data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="640" height="420"><rect width="640" height="420" fill="#e5e5e5"/><circle cx="460" cy="150" r="56" fill="#fafafa"/><path d="M0 280 120 170l110 100 120-130 130 125 90-60 70 40v175H0z" fill="#a3a3a3"/><path d="M0 330l160-80 120 70 150-80 210 85v95H0z" fill="#525252"/><path d="M0 380q160-35 320-10t320-5v55H0z" fill="#262626"/></svg>`
)}`
const ratios = [
{ value: "free", label: "Free", ratio: undefined },
{ value: "square", label: "Square", ratio: 1 },
{ value: "landscape", label: "4:3", ratio: 4 / 3 },
{ value: "wide", label: "16:9", ratio: 16 / 9 },
]
const handles = ["nw", "n", "ne", "e", "se", "s", "sw", "w"] as const
const ratio = ref<string | null>("free")
const aspectRatio = computed(
() => ratios.find((item) => item.value === ratio.value)?.ratio
)
const crop = ref<ImageCrop>()
const result = ref<string>()
async function save() {
if (!crop.value) {
return
}
const file = await cropImage(photo, crop.value)
if (result.value) {
URL.revokeObjectURL(result.value)
}
result.value = URL.createObjectURL(file)
}
onBeforeUnmount(() => result.value && URL.revokeObjectURL(result.value))
</script>
<template>
<div data-slot="stack">
<div data-slot="controls">
<Select v-model:value="ratio">
<SelectTrigger aria-label="Aspect ratio">
<SelectValue />
<ChevronDownIcon />
</SelectTrigger>
<SelectContent>
<SelectItem
v-for="item in ratios"
:key="item.value"
:value="item.value"
>
{{ item.label }}
<SelectItemIndicator>
<CheckIcon />
</SelectItemIndicator>
</SelectItem>
</SelectContent>
</Select>
<button type="button" data-variant="solid" @click="save">Crop</button>
</div>
<ImageCropper
v-model:crop="crop"
aria-label="Photo"
:src="photo"
:aspect-ratio="aspectRatio"
:min-width="64"
:min-height="64"
>
<ImageCropperViewport>
<ImageCropperImage alt="Mountains at sunset" />
<ImageCropperSelection>
<ImageCropperGrid />
</ImageCropperSelection>
<ImageCropperHandle
v-for="position in handles"
:key="position"
:position="position"
/>
</ImageCropperViewport>
</ImageCropper>
<div data-slot="image-cropper-result">
<img v-if="result" :src="result" alt="Your crop" />
</div>
</div>
</template>安装
npm install @ui-sdk/vue @ui-sdk/core组合
用下面的组合构建 ImageCropper:
ImageCropper
├── ImageCropperViewport
│ ├── ImageCropperImage
│ ├── ImageCropperSelection
│ │ └── ImageCropperGrid
│ └── ImageCropperHandle
├── ImageCropperZoom
├── ImageCropperRotate
└── ImageCropperFlip- ImageCropper 持有裁剪区域和图片的
src,是包住各部件的一组。 - ImageCropperViewport 是图片显示的区域。给它一个尺寸,它的内边距会让图片与边缘保持距离。
- ImageCropperImage 是图片本身,会被旋转和翻转。给它
alt。 - ImageCropperSelection 在图片上显示裁剪区域。它是一个滑块,你可以拖动它,或者用方向键移动它。
- ImageCropperGrid 在选区上画出三等分的线,供你设置样式。
- ImageCropperHandle 从一条边或一个角调整选区大小,位置由它的
position决定,比如"se"表示右下角。它放在选区旁边,而不是里面,落在选区的边或角上。 - ImageCropperZoom 是范围输入框,从 1(最大的裁剪区域)到
max-zoom。 - ImageCropperRotate 把图片顺时针旋转四分之一圈。
- ImageCropperFlip 左右镜像图片;设置
direction="vertical"时上下镜像。
视口、图片和选区是必需的,其余都是可选的。
用法
导入部件并把它们组合起来:
<script setup lang="ts">
import {
ImageCropper,
ImageCropperHandle,
ImageCropperImage,
ImageCropperSelection,
ImageCropperViewport,
} from "@ui-sdk/vue/image-cropper"
defineProps<{ src: string }>()
</script>
<template>
<ImageCropper aria-label="Cover photo" :src="src" :aspect-ratio="3">
<ImageCropperViewport>
<ImageCropperImage alt="Your cover photo" />
<ImageCropperSelection />
<ImageCropperHandle position="nw" />
<ImageCropperHandle position="se" />
</ImageCropperViewport>
</ImageCropper>
</template>用 aria-label 给裁剪器命名。在图片加载完成之前,根部件带有 data-loading 和 aria-busy,选区是隐藏的。之后裁剪区域从中间开始,按 aspectRatio 取图片允许的最大尺寸的五分之四,好让裁剪区域的边缘露出来;在外框里则取允许的最大尺寸,除非你传入 default-crop:
<ImageCropper
aria-label="Photo"
:src="src"
:default-crop="{ x: 40, y: 40, width: 320, height: 240 }"
>
<!-- … -->
</ImageCropper>宽高比
设置 aspect-ratio,让裁剪区域的宽度和高度保持固定比例,比如 1 表示正方形,或者 16 / 9。修改它时,裁剪区域会以中心为基准适应新的比例。不设置时,裁剪区域是自由的;拖动某个手柄时按住 Shift,会保持当前的比例。min-width 和 min-height 以图片像素为单位,防止它变得太小。
<script setup lang="ts">
import { ref } from "vue"
import {
ImageCropper,
ImageCropperFlip,
ImageCropperGrid,
ImageCropperHandle,
ImageCropperImage,
ImageCropperSelection,
ImageCropperViewport,
} from "@ui-sdk/vue/image-cropper"
const photo = `data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="640" height="420"><rect width="640" height="420" fill="#e5e5e5"/><circle cx="460" cy="150" r="56" fill="#fafafa"/><path d="M0 280 120 170l110 100 120-130 130 125 90-60 70 40v175H0z" fill="#a3a3a3"/><path d="M0 330l160-80 120 70 150-80 210 85v95H0z" fill="#525252"/><path d="M0 380q160-35 320-10t320-5v55H0z" fill="#262626"/></svg>`
)}`
const ratios = [
{ label: "Free", value: undefined },
{ label: "Square", value: 1 },
{ label: "Wide", value: 16 / 9 },
]
const handles = ["nw", "n", "ne", "e", "se", "s", "sw", "w"] as const
const aspectRatio = ref<number>()
</script>
<template>
<div data-slot="stack">
<div data-slot="controls">
<button
v-for="ratio in ratios"
:key="ratio.label"
type="button"
:aria-pressed="aspectRatio === ratio.value"
@click="aspectRatio = ratio.value"
>
{{ ratio.label }}
</button>
</div>
<ImageCropper
aria-label="Photo"
:src="photo"
:aspect-ratio="aspectRatio"
:min-width="64"
:min-height="64"
>
<ImageCropperViewport>
<ImageCropperImage alt="Mountains at sunset" />
<ImageCropperSelection>
<ImageCropperGrid />
</ImageCropperSelection>
<ImageCropperHandle
v-for="position in handles"
:key="position"
:position="position"
/>
</ImageCropperViewport>
<div data-slot="row">
<ImageCropperFlip>Flip</ImageCropperFlip>
<ImageCropperFlip direction="vertical"
>Flip Vertically</ImageCropperFlip
>
</div>
</ImageCropper>
</div>
</template>外框模式
设置 mode="frame",得到一个头像编辑器。选区保持不动,并占据能放下的最大尺寸;拖动可以在选区下面平移图片,转轮、双指捏合或缩放输入框可以缩放。外框里不显示手柄。
设置 shape="circle" 会把选区变成圆形,但裁剪区域仍然是它的方框,所以也要把 shape: "circle" 传给 cropImage。这里的 Save Avatar 会裁出一个 128 像素的圆形文件:
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue"
import { cropImage } from "@ui-sdk/vue/image"
import {
ImageCropper,
ImageCropperImage,
ImageCropperRotate,
ImageCropperSelection,
ImageCropperViewport,
ImageCropperZoom,
type ImageCrop,
} from "@ui-sdk/vue/image-cropper"
const photo = `data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="640" height="420"><rect width="640" height="420" fill="#e5e5e5"/><circle cx="460" cy="150" r="56" fill="#fafafa"/><path d="M0 280 120 170l110 100 120-130 130 125 90-60 70 40v175H0z" fill="#a3a3a3"/><path d="M0 330l160-80 120 70 150-80 210 85v95H0z" fill="#525252"/><path d="M0 380q160-35 320-10t320-5v55H0z" fill="#262626"/></svg>`
)}`
const crop = ref<ImageCrop>()
const avatar = ref<string>()
async function save() {
if (!crop.value) {
return
}
const file = await cropImage(photo, crop.value, {
width: 128,
shape: "circle",
})
if (avatar.value) {
URL.revokeObjectURL(avatar.value)
}
avatar.value = URL.createObjectURL(file)
}
onBeforeUnmount(() => avatar.value && URL.revokeObjectURL(avatar.value))
</script>
<template>
<ImageCropper
v-model:crop="crop"
aria-label="Profile photo"
:src="photo"
mode="frame"
:aspect-ratio="1"
shape="circle"
:max-zoom="4"
>
<ImageCropperViewport>
<ImageCropperImage alt="Mountains at sunset" />
<ImageCropperSelection />
</ImageCropperViewport>
<div data-slot="row">
<ImageCropperZoom />
<ImageCropperRotate>Rotate</ImageCropperRotate>
</div>
<div data-slot="row">
<button type="button" @click="save">Save Avatar</button>
<img
v-if="avatar"
data-slot="image-cropper-avatar"
:src="avatar"
alt="Your new avatar"
/>
</div>
</ImageCropper>
</template>旋转与翻转
ImageCropperRotate 把图片顺时针旋转四分之一圈,键盘上的 R 也能做到,按 Shift 则转回来。ImageCropperFlip 镜像图片。裁剪区域随图片一起旋转和翻转,所以它保留照片的同一部分。它的 x 和 y 从图片显示时的左上角算起,此时已经过旋转和翻转,这正是 cropImage 接收的值。
禁用
设置 disabled。选区和手柄不能获得焦点,也不能拖动,缩放输入框和按钮会被禁用。
<ImageCropper aria-label="Photo" :src="src" disabled>
<!-- … -->
</ImageCropper>受控
用 v-model:crop 绑定 crop,并监听 @crop-change 获取详情。每次变更都带一个原因,比如 drag、step-key 或 zoom-input。在监听器里调用 details.cancel() 保留当前的裁剪区域。
@crop-change 在拖动的每一步触发,图片加载完成时也触发一次。@crop-commit 只触发一次,在拖动、按键或转轮结束时,所以用它来保存。来自 createImageCropperController() 的控制器可以从任何地方设置裁剪区域:
<script setup lang="ts">
import {
createImageCropperController,
ImageCropper,
ImageCropperImage,
ImageCropperSelection,
ImageCropperViewport,
} from "@ui-sdk/vue/image-cropper"
defineProps<{ src: string }>()
const controller = createImageCropperController()
</script>
<template>
<ImageCropper
aria-label="Photo"
:src="src"
:controller="controller"
@crop-commit="(crop, details) => console.log(crop, details.reason)"
>
<ImageCropperViewport>
<ImageCropperImage alt="Your photo" />
<ImageCropperSelection />
</ImageCropperViewport>
</ImageCropper>
<button type="button" @click="controller.setZoom(2)">Zoom In</button>
</template>受控状态、取消和调试见状态与事件。
自定义渲染
每个部件都接受 render,用来在它的位置渲染不同的元素或组件,它的默认槽位会收到 state。每个部件都有 crop、zoom,以及它是否 loading、是否有 error、是否 dragging:
<ImageCropper v-slot="{ state }" aria-label="Photo" :src="src">
<ImageCropperViewport>
<ImageCropperImage alt="Your photo" />
<ImageCropperSelection />
</ImageCropperViewport>
<p v-if="state.loading">Loading…</p>
<p v-if="state.error">The image didn't load.</p>
<output>{{ Math.round(state.zoom * 100) }}%</output>
</ImageCropper>样式
部件没有样式,除了它们需要的位置:视口是 position: relative 加 overflow: hidden,图片、选区和每个手柄的位置都来自以像素为单位的内联样式。手柄的位置是它所在边或角上的那个点,所以要给它尺寸,并用 translate: -50% -50% 把它居中。也要给视口一个尺寸。
方框模式的视口会装下整张图片,所以把它的 aspect-ratio 设为 --image-cropper-aspect-ratio。在选区上放一个很大的 box-shadow,会压暗它外面的图片。只在选区带有 data-dragging 时显示网格。
每个部件都有一个 data-slot,比如 image-cropper-selection,它的状态属性列在数据属性下。
ImageCropperViewport
| 变量 | 内容 |
|---|---|
--image-cropper-aspect-ratio | The image's width over its height as it shows, turned, once it loads. Give the viewport aspect-ratio: var(--image-cropper-aspect-ratio) to fit the image. |
数据属性
ImageCropper
[data-slot="image-cropper"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
data-dragging | Present while a pointer drags the selection, the image or, on a handle, that handle. Show the grid with it. |
ImageCropperViewport
[data-slot="image-cropper-viewport"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
data-dragging | Present while a pointer drags the selection, the image or, on a handle, that handle. Show the grid with it. |
ImageCropperImage
[data-slot="image-cropper-image"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
ImageCropperSelection
[data-slot="image-cropper-selection"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
data-dragging | Present while a pointer drags the selection, the image or, on a handle, that handle. Show the grid with it. |
ImageCropperGrid
[data-slot="image-cropper-grid"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
data-dragging | Present while a pointer drags the selection, the image or, on a handle, that handle. Show the grid with it. |
ImageCropperHandle
[data-slot="image-cropper-handle"]
| 属性 | 含义 |
|---|---|
data-position | neswnenwseswThe edge or corner the handle resizes. |
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
data-dragging | Present while a pointer drags the selection, the image or, on a handle, that handle. Show the grid with it. |
ImageCropperZoom
[data-slot="image-cropper-zoom"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
ImageCropperRotate
[data-slot="image-cropper-rotate"]
| 属性 | 含义 |
|---|---|
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
ImageCropperFlip
[data-slot="image-cropper-flip"]
| 属性 | 含义 |
|---|---|
data-direction | horizontalverticalWhich way the button mirrors the image. |
data-mode | boxframeHow the crop changes. |
data-shape | rectanglecircleThe selection's shape. |
data-loading | Present until the image loads, while nothing can change. |
data-disabled | Present when the cropper is disabled. |
data-error | Present when the image failed to load. |
API 参考
属性与下面相同。onCropChange 是 v-model:crop,要详情则用 @crop-change;onCropCommit 是 @crop-commit。
ImageCropper
src?string- The image's URL, like an object URL for a file someone picked.
crop?ImageCrop- The crop, in the image's own pixels, from the top left of the image as it shows once turned and flipped, with its
rotation,flipXandflipY. Pass it straight tocropImage. Pass it to control the cropper. defaultCrop?ImageCrop- The crop at first, when uncontrolled.
@crop-change((crop: Required<ImageCrop>, details: ImageCropperCropChangeDetails) => void)- Runs while the crop changes: on every step of a drag, a key or the wheel, and once an image loads.
details.cancel()stops it. @crop-commit((crop: Required<ImageCrop>, details: ImageCropperCropCommitDetails) => void)- Runs once an interaction that changed the crop ends: the pointer lifts, a key is pressed, the wheel pauses. For saving.
mode?ImageCropperMode"box"moves and resizes a selection over the whole image."frame"keeps the selection still and as large as it fits, and pans and zooms the image under it, like an avatar editor.aspectRatio?number- Keeps the crop's width over its height, like
1for a square or16 / 9. Changing it fits the crop to the new ratio. shape?ImageCropperShape- The selection's shape, as
data-shape. A circle is still a box to the crop, so passshape: "circle"tocropImagetoo. minWidth?number- The narrowest the crop gets, in image pixels.
minHeight?number- The shortest the crop gets, in image pixels.
maxZoom?number- How far the crop magnifies the image, where 1 is the largest crop the image allows.
disabled?boolean- Stops every change: the selection can't be focused, and the buttons and zoom are disabled.
controller?object- Sets the crop from anywhere. Create one with
createImageCropperController(). debug?boolean- Logs every state change with its reason to the console, in development builds.
ImageCropperHandle
positionImageCropperHandlePosition- The edge or corner it resizes, like
"nw"for the top left corner.
ImageCropperFlip
direction?ImageCropperFlipDirection- Which way it mirrors the image.
状态
渲染函数、基于状态的类名和槽位会收到什么。每个部件都会收到裁剪器的状态。
cropRequired<ImageCrop> | null- The crop, or null until the image loads.
zoomnumber- How far the crop magnifies: 1 when it's as large as the image allows at its ratio.
loadingboolean- Whether the image is still loading, so nothing can change yet.
errorboolean- Whether the image failed to load.
draggingboolean- Whether a pointer is dragging the selection, a handle or the image.
modeImageCropperMode- How the crop changes.
shapeImageCropperShape- The selection's shape.
disabledboolean- Whether the
disabledoption stops every change.
手柄会增加自己的字段:
cropRequired<ImageCrop> | null- The crop, or null until the image loads.
zoomnumber- How far the crop magnifies: 1 when it's as large as the image allows at its ratio.
loadingboolean- Whether the image is still loading, so nothing can change yet.
errorboolean- Whether the image failed to load.
draggingboolean- Whether a pointer is dragging the selection, a handle or the image.
modeImageCropperMode- How the crop changes.
shapeImageCropperShape- The selection's shape.
disabledboolean- Whether the
disabledoption stops every change. positionImageCropperHandlePosition- The edge or corner it resizes.
原因
details.reason 说明裁剪区域为什么变化。
image-loadEvent | undefined- An image loaded. No event when it was already in the browser's cache.
dragPointerEvent- A slider thumb or a resize handle was dragged, or an item was dragged to a new place in a list.
pinchwheelWheelEvent- The mouse wheel stepped a focused number input.
step-keyKeyboardEvent- Arrow, Page Up, Page Down, Home or End stepped a slider or a number input.
zoom-keyzoom-inputrotate-keyrotate-pressflip-pressaspect-ratio-changeimperativenone- A controller or
apicall.
控制器
用 createImageCropperController() 创建一个,并作为 controller 传入。
每个写入方法接受可选的 { reason, event },像拖动一样触发变更事件,并在没有任何变化或变更被取消时返回 false。
getCrop()() => Required<ImageCrop> | null- The crop, or null until the image loads.
setCrop(crop, options?)(crop: ImageCrop, options?: ImageCropperChangeOptions | undefined) => boolean- Sets the crop, as a user would. Returns whether it changed.
rotate(direction?, options?)(direction?: 1 | -1 | undefined, options?: ImageCropperChangeOptions | undefined) => boolean- Turns the image a quarter clockwise, or counterclockwise with
-1. flip(direction?, options?)(direction?: ImageCropperFlipDirection | undefined, options?: ImageCropperChangeOptions | undefined) => boolean- Mirrors the image left to right, or top to bottom with
"vertical". getZoom()() => number- How far the crop magnifies: 1 when it's as large as the image allows at its ratio.
setZoom(zoom, options?)(zoom: number, options?: ImageCropperChangeOptions | undefined) => boolean- Zooms to a level, about the crop's middle, within 1 and
maxZoom. focus()() => void- Moves focus to the selection.
事件
事件先收到新的裁剪区域,然后收到详情。只有变更事件没有被取消时,v-model 才会更新。
| 绑定 | 所属 | 收到 |
|---|---|---|
v-model:crop | ImageCropper | 裁剪区域 |
@crop-change | ImageCropper | (crop, details):新的裁剪范围和原因 |
@crop-commit | ImageCropper | (crop, details):交互结束时的裁剪范围和它的原因 |
无障碍
没有 WAI-ARIA 模式直接覆盖图片裁剪器,所以它由已有的模式搭成。裁剪器是一个分组。选区和每个手柄遵循 WAI-ARIA 滑块模式,并用文字说出裁剪区域,比如“300 by 300 pixels, at 50, 0”。缩放是一个原生范围输入框,会说出它的级别,比如“125%”。
选区、手柄和缩放默认用英语命名。传入 aria-label 来用其他语言命名它们。
键盘
| 按键 | 作用 |
|---|---|
| Arrow keys | 移动选区;在手柄上时,移动它的边 |
| Shift with an arrow | 移动十倍远 |
| Plus or Minus | 以裁剪区域的中心为基准放大或缩小 |
| R | 把图片顺时针旋转四分之一圈,加 Shift 转回来 |
| Escape | 拖动过程中,把裁剪区域放回拖动开始的位置 |
每次按键都会提交,就像一次拖动结束。
经过测试的行为
下面每一行都是一个自动化测试。
- The crop starts once the image loads, as four fifths of the largest at the ratio.
- A drag moves the selection over the image and commits once.
- A handle resizes from its corner, within the image.
- Each handle sits on its edge or corner of the selection, and follows it.
- At a ratio, a handle keeps it.
- Escape during a drag puts the selection back.
- Arrows move the selection, ten times as far with Shift.
- Arrows on a handle move its edges, and the next Tab reaches it.
- Plus and minus zoom about the middle, and R turns the image.
- The zoom input zooms the crop.
- Rotate turns the image a quarter clockwise, and flip mirrors it.
- A controller sets the crop, and a canceled change keeps it.
- Disabled, nothing takes focus or changes.
- The selection stays put and a drag pans the image under it.
- Escape during a pan puts the image back.
- The wheel zooms at the pointer and commits after a pause.
运行于 React、Vue 和 web components。