Skip to content

Commit

Permalink
Merge pull request #8 from chengpeiquan/develop
Browse files Browse the repository at this point in the history
chore: update docs and rebuild to NPM
  • Loading branch information
chengpeiquan authored Jun 7, 2021
2 parents 505ea63 + b3ef5e0 commit 25b1806
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 117 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# vue-picture-cropper

一个基于cropper.js,支持Vue 3.0的图片裁切工具组件(目前仅支持Vue 3.x)。
一个基于 cropper.js ,支持 Vue 3.0 的图片裁切工具组件(目前仅支持 Vue 3.x )。

## demo

根据平时常见的使用习惯,弄了一个简单的在线demo,点击按钮选择图片后,弹出裁切框,裁切后生成裁切结果。
根据平时常见的使用习惯,弄了一个简单的在线 DEMO ,点击按钮选择图片后,弹出裁切框,裁切后生成裁切结果。

点击查看:[vue-picture-cropper-demo](https://chengpeiquan.github.io/vue-picture-cropper-demo/)

![](https://chengpeiquan.github.io/vue-picture-cropper-demo/static/img/preview.jpg)
![vue-picture-cropper-demo](https://chengpeiquan.github.io/vue-picture-cropper-demo/static/img/preview.jpg)

## 安装

Expand All @@ -18,13 +18,20 @@ npm install --save-dev vue-picture-cropper

## 导入

目前仅支持在Vue组件里按需引入,模板和实例也仅限在组件内使用,根据Vue 3.x的设计思想,官方也不推荐全局导入各类插件。
目前仅支持在 Vue 组件里按需引入,模板和实例也仅限在组件内使用,根据 Vue 3.x 的设计思想,官方也不推荐全局导入各类插件。

```js
// xxx.vue
import VuePictureCropper, { cropper } from 'vue-picture-cropper'
```

需要注意的是,如果是基于 [Vite](https://vitejs.dev/) 的项目,由于 Vite 需要使用 ESM 组件,所以导入方式需要改成从 `ESM` 版本导入:

```js
// xxx.vue(注意 from 后面的路径不同)
import VuePictureCropper, { cropper } from 'vue-picture-cropper/dist/esm'
```

导入的模块说明:

模块名称|作用
Expand All @@ -36,7 +43,7 @@ cropper|工具实例,可用于操作相关的api,必须用花括号导入该

## 用法

工具的渲染方法如下,请注意在Vue 3.x里,除非你使用class风格来编写组件,否则组件都需要通过 `defineComponent` 来定义。
工具的渲染方法如下,请注意在 Vue 3.x 里,除非你使用 class 风格来编写组件,否则组件都需要通过 `defineComponent` 来定义。

```html
<template>
Expand Down Expand Up @@ -73,7 +80,11 @@ export default defineComponent({

上面是设定了一个裁剪区域,对于文件的选择/传入,以及裁切结果,请通过 `<input type="file" >``button` 绑定实例的api来获取。

可参考demo里面的用法:[dialog.vue - vue-picture-cropper-demo](https://github.com/chengpeiquan/vue-picture-cropper-demo/blob/main/src/views/dialog.vue)
可参考 DEMO 里面的用法:

- [Vue 3.0 组合式 API 写法](https://github.com/chengpeiquan/vue-picture-cropper-demo/blob/main/src/components/Dialog.vue)

- [Vue 2.0 选项式 API 写法](https://github.com/chengpeiquan/vue-picture-cropper-demo/blob/main/src/components/DialogWithOptionsAPI.vue)

## Props

Expand All @@ -92,13 +103,13 @@ btw: 远程图片会涉及到跨域问题,要服务端进行配合调整,请

属性|类型|说明
:--|:--|:--
viewMode|number|可以决定裁切框的活动范围,可选0、1、2、3,建议选1(裁切框只能在图片区域内活动)
viewMode|number|可以决定裁切框的活动范围,可选 0、1、2、3,建议选 1 (裁切框只能在图片区域内活动)
aspectRatio|number|可以指定裁剪框的宽高比,不设置则为自由变化(建议按照裁切结果的尺寸设置对应的比例)
preview|element/string|图片预览的容器,一个dom元素。必须可以被document.querySelectorAll获取到
preview|element/string|图片预览的容器,一个 DOM 元素。必须可以被 document.querySelectorAll 获取到

## 常用方法

可通过 `cropper` 实例来调取插件的各种api(也就是在import的时候花括号里的那个实例)。
可通过 `cropper` 实例来调取插件的各种 API (也就是在 import 的时候花括号里的那个实例)。

方法名|功能说明|用法示范
:--|:--|:--
Expand Down Expand Up @@ -126,7 +137,7 @@ imageSmoothingQuality|string|图片平滑质量,可选low、medium、high|low
用法示范:

```js
// 设定裁切后指定尺寸为400x250,通常可以为banner图裁切指定尺寸
// 设定裁切后指定尺寸为 400x250 ,通常可以为 banner 图裁切指定尺寸
const OPT = {
width: 400,
height: 250
Expand All @@ -140,7 +151,8 @@ const DATA_URL = cropper.getDataURL(OPT);

## 其他说明

因为本插件是对做了一层组件化的实现,所以本组件也同步了cropperjs的所有api,均可通过 `cropper.xxxx` 来使用原来的api
因为本插件是对做了一层组件化的实现,所以本组件也同步了 cropperjs 的所有 API ,均可通过 `cropper.xxxx` 来使用原来的 API

如果你需要更多高级功能,可以戳原文档参考使用 [events - cropperjs](https://github.com/fengyuanchen/cropperjs#events)

对 Vue 3.0 还不熟悉的同学,可以查阅我之前总结的文档 [《Vue3.0学习教程与实战案例》](http://vue3.chengpeiquan.com/)
4 changes: 2 additions & 2 deletions dist/esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions dist/vue-picture-cropper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-picture-cropper.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vue-picture-cropper.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-picture-cropper.min.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-picture-cropper",
"version": "0.1.8",
"description": "An picture cropping tool that can be used in Vue 3.0.",
"version": "0.1.9",
"description": "A picture cropping tool that can be used in Vue 3.0.",
"main": "dist/vue-picture-cropper.min.js",
"types": "vue-picture-cropper.d.ts",
"scripts": {
Expand Down Expand Up @@ -37,7 +37,6 @@
"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.27.2",
"rollup-plugin-vue": "^6.0.0",
"stylus": "^0.54.8",
"tslib": "^2.0.1",
"typescript": "^4.0.2",
"vue": "^3.0.5"
Expand Down
2 changes: 0 additions & 2 deletions src/vue-picture-cropper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ const VuePictureCropper = defineComponent({
cropper = this.cropper;
cropper.getDataURL = this.getDataURL;
cropper.getBlob = this.getBlob;
console.log('this.cropper', this.cropper);
console.log('cropper', cropper);
},
/**
Expand Down
93 changes: 2 additions & 91 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,6 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

atob@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

babel-plugin-dynamic-import-node@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"
Expand Down Expand Up @@ -1409,13 +1404,6 @@ css-modules-loader-core@^1.1.0:
postcss-modules-scope "1.1.0"
postcss-modules-values "1.3.0"

css-parse@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/css-parse/-/css-parse-2.0.0.tgz#a468ee667c16d81ccf05c58c38d2a97c780dbfd4"
integrity sha1-pGjuZnwW2BzPBcWMONKpfHgNv9Q=
dependencies:
css "^2.0.0"

css-select-base-adapter@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz#3b2ff4972cc362ab88561507a95408a1432135d7"
Expand Down Expand Up @@ -1460,16 +1448,6 @@ css-what@^3.2.1:
resolved "https://registry.yarnpkg.com/css-what/-/css-what-3.4.2.tgz#ea7026fcb01777edbde52124e21f327e7ae950e4"
integrity sha512-ACUm3L0/jiZTqfzRM3Hi9Q8eZqd6IK37mMWPLz9PJxkLWllYeRf+EHUSHYEtFop2Eqytaq1FizFVh7XfBnXCDQ==

css@^2.0.0:
version "2.2.4"
resolved "https://registry.yarnpkg.com/css/-/css-2.2.4.tgz#c646755c73971f2bba6a601e2cf2fd71b1298929"
integrity sha512-oUnjmWpy0niI3x/mPL8dVEI1l7MnG3+HHyRPHf+YFSbK+svOhXpmSOcDURUh2aOCgl2grzrOPt1nHLuCVFULLw==
dependencies:
inherits "^2.0.3"
source-map "^0.6.1"
source-map-resolve "^0.5.2"
urix "^0.1.0"

cssesc@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
Expand Down Expand Up @@ -1562,18 +1540,6 @@ debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "2.1.2"

debug@~3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=

deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
Expand Down Expand Up @@ -1919,7 +1885,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@^2.0.3:
inherits@2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
Expand Down Expand Up @@ -2193,16 +2159,6 @@ mkdirp@~0.5.1:
dependencies:
minimist "^1.2.5"

mkdirp@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

[email protected]:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
Expand Down Expand Up @@ -2852,11 +2808,6 @@ resolve-from@^5.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69"
integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==

resolve-url@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=

[email protected]:
version "1.17.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
Expand Down Expand Up @@ -2968,11 +2919,6 @@ safe-identifier@^0.4.1:
resolved "https://registry.yarnpkg.com/safe-identifier/-/safe-identifier-0.4.2.tgz#cf6bfca31c2897c588092d1750d30ef501d59fcb"
integrity sha512-6pNbSMW6OhAi9j+N8V+U715yBQsaWJ7eyEUaOrawX+isg5ZxhUlV1NipNtgaKHmFGiABwt+ZF04Ii+3Xjkg+8w==

safer-buffer@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sax@~1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
Expand Down Expand Up @@ -3007,17 +2953,6 @@ source-map-js@^0.6.2:
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e"
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==

source-map-resolve@^0.5.2:
version "0.5.3"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a"
integrity sha512-Htz+RnsXWk5+P2slx5Jh3Q66vhQj1Cllm0zvnaY98+NFx+Dv2CF/f5O/t8x+KaNdrdIAsruNzoh/KpialbqAnw==
dependencies:
atob "^2.1.2"
decode-uri-component "^0.2.0"
resolve-url "^0.2.1"
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@~0.5.19:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
Expand All @@ -3026,11 +2961,6 @@ source-map-support@~0.5.19:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.1.tgz#0af66605a745a5a2f91cf1bbf8a7afbc283dec56"
integrity sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==

source-map@^0.5.0, source-map@^0.5.6:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
Expand All @@ -3041,7 +2971,7 @@ source-map@^0.6.0, source-map@^0.6.1:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

source-map@^0.7.3, source-map@~0.7.2:
source-map@~0.7.2:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
Expand Down Expand Up @@ -3103,20 +3033,6 @@ stylehacks@^4.0.0:
postcss "^7.0.0"
postcss-selector-parser "^3.0.0"

stylus@^0.54.8:
version "0.54.8"
resolved "https://registry.yarnpkg.com/stylus/-/stylus-0.54.8.tgz#3da3e65966bc567a7b044bfe0eece653e099d147"
integrity sha512-vr54Or4BZ7pJafo2mpf0ZcwA74rpuYCZbxrHBsH8kbcXOwSfvBFwsRfpGO5OD5fhG5HDCFW737PKaawI7OqEAg==
dependencies:
css-parse "~2.0.0"
debug "~3.1.0"
glob "^7.1.6"
mkdirp "~1.0.4"
safer-buffer "^2.1.2"
sax "~1.2.4"
semver "^6.3.0"
source-map "^0.7.3"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down Expand Up @@ -3256,11 +3172,6 @@ unquote@~1.1.1:
resolved "https://registry.yarnpkg.com/unquote/-/unquote-1.1.1.tgz#8fded7324ec6e88a0ff8b905e7c098cdc086d544"
integrity sha1-j97XMk7G6IoP+LkF58CYzcCG1UQ=

urix@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=

util-deprecate@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit 25b1806

Please sign in to comment.