# @github/image-crop-element 中文文档

规范地址：https://npmcn.com/package/%40github/image-crop-element/

版本：5\.0\.0
npm 元数据更新时间：2026-10-15T16:21:04.912Z
中文译文更新时间：2026-11-16T10:57:40.501Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40github/image-crop-element
原文对照：https://npmcn.com/package/%40github/image-crop-element/?lang=original
项目主页：https://github.com/github/image-crop-element#readme
源码仓库：https://github.com/github/image-crop-element

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：16.4 kB，5 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2018-06-22T22:51:05.176Z
- 最新版本发布：2021-04-16T10:06:15.262Z
- 近 30 天下载量：129921（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：16（近 12 个月 0 个）

## 中文简介

选择绘制图像的区域。 这实际上并不收割.

## 安装

```sh
npm install @github/image-crop-element
```

也可以使用：`pnpm add @github/image-crop-element`、`yarn add @github/image-crop-element`、`bun add @github/image-crop-element`

## README

# <图像-作物元素>

这将加载一个图像并创建一个用户可以修改的裁剪区域. 当作物面积发生变化时,用x、y、宽度和高度发射一个事件.

## 安装

```
$ npm install --save @github/image-crop-element
```

## 使用量

### 平面

```html
<image-crop src="/avatar.jpg"></image-crop>
```

### 四舍五入的作物面积

```html
<image-crop src="/avatar.jpg" rounded></image-crop>
```

### 装入状态

```html
<image-crop src="/avatar.jpg">
  <img src="spinner.gif" alt="" data-loading-slot />
</image-crop>
```

### 自动更新输入

```html
<image-crop src="/avatar.jpg">
  <input type="hidden" data-image-crop-input="x" name="x">
  <input type="hidden" data-image-crop-input="y" name="y">
  <input type="hidden" data-image-crop-input="width" name="width">
  <input type="hidden" data-image-crop-input="height" name="height">
</image-crop>
```

### 聆听更改事件

```javascript
document.addEventListener('image-crop-change', function (event){
  console.log(
    'Crop area changed.',
    event.detail.x,
    event.detail.y,
    event.detail.width,
    event.detail.height
  )
})
```

## CSS 封装

元素 HTML 结构以 a 初始化 [阴影DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM),因此不可能对它应用CSS. 如果您出于任何理由需要改变元素的默认样式,您应该打开一个新问题(或拉出请求!),描述您的使用大小写,我们将与您合作解决问题.

## 浏览器支持

浏览器, 不本地 [自定义元素支持](https://caniuse.com/#feat=custom-elementsv1) 需要一个 [多边填充](https://github.com/webcomponents/custom-elements). 后遗症浏览器需要各种其他多填充. 见 [`examples/index.html`](https://github.com/github/image-crop-element/blob/57080ad88d26e05b42fa10a95470da8035f53967/examples/polyfill.html#L17-L22) 详细情况.

-   颜色
-   火花
-   萨法里
-   微软边缘

## 常见问题

### @github/image-crop-element 是什么？

选择绘制图像的区域。 这实际上并不收割\.

### 如何安装 @github/image-crop-element？

在项目目录运行 npm install @github/image-crop-element，或使用 pnpm add / yarn add / bun add。

### @github/image-crop-element 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @github/image-crop-element 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @github/image-crop-element 可以商用吗？

@github/image-crop-element 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @github/image-crop-element 的下载量有多少？

根据 npm 官方下载统计，@github/image-crop-element 在 2026/10/17 – 2026/11/15 这 30 天内被下载 129,921 次，日均约 4,331 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @github/image-crop-element 还在维护吗？

最新版本 5\.0\.0 发布于 2021/04/16（5 年前）；至今共发布 16 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/06/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

