@github/image-crop-element

中文文档
5.0.0发布于 2021/04/16MITTypeScriptES Module零依赖近 30 天下载 13万

Select area for cropping an image. This does not actually crop.

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Plain
  4. Rounded crop area
  5. With loading state
  6. With autoupdate inputs
  7. Listen to the change event
  8. CSS encapsulation
  9. Browser support

<image-crop-element>

This loads an image and creates a crop area that user can modify. An event is fired with x, y, width, and height as the crop area changes.

Installation

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

Usage

Plain

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

Rounded crop area

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

With loading state

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

With autoupdate inputs

<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>

Listen to the change event

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 encapsulation

The elements HTML structure is initialized in a Shadow DOM, so it is impossible to apply CSS to it. If you need to change the element's default style for any reason, you should open up a new issue (or a pull request!), describing your use case, and we'll work with you on solving the problem.

Browser support

Browsers without native custom element support require a polyfill. Legacy browsers require various other polyfills. See examples/index.html for details.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

版本与发布记录

@github/image-crop-element 共发布 16 个版本,首次发布于 2018/06/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2021/04/165 年前
4.1.12021/03/155 年前
4.1.02020/12/025 年前
4.0.02020/11/056 年前
3.0.82020/02/296 年前
3.0.72020/01/206 年前

关于 @github/image-crop-element 的常见问题

@github/image-crop-element 是什么?

Select area for cropping an image. This does not actually crop.

如何安装 @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 和提交记录判断。