vue-cropperjs2 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -3
- package/package.json +10 -10
- package/dist/index.d.ts +0 -145
- package/dist/index.js +0 -1633
- package/dist/index.umd.cjs +0 -1
- package/dist/vite.svg +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,156 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vue-cropperjs2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A modern Vue 3 wrapper for [Cropper.js v2](https://github.com/fengyuanchen/cropperjs) using Web Components. This library provides a seamless way to integrate Cropper.js v2 features directly into your Vue 3 applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
|
+
- Fully compatible with Vue 3 (Composition API / `<script setup>`)
|
|
7
|
+
- Wraps all standard `cropperjs` Web Components as native Vue components
|
|
8
|
+
- Full TypeScript support
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install `vue-cropperjs2` alongside its peer dependency `cropperjs`:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install vue-cropperjs2 cropperjs
|
|
16
|
+
# or using yarn
|
|
17
|
+
yarn add vue-cropperjs2 cropperjs
|
|
18
|
+
# or using pnpm
|
|
19
|
+
pnpm add vue-cropperjs2 cropperjs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Available Components
|
|
23
|
+
|
|
24
|
+
The library exports the following components mapping to `cropperjs` custom elements:
|
|
25
|
+
|
|
26
|
+
- `CropperCanvas`
|
|
27
|
+
- `CropperImage`
|
|
28
|
+
- `CropperShade`
|
|
29
|
+
- `CropperHandle`
|
|
30
|
+
- `CropperSelection`
|
|
31
|
+
- `CropperCrosshair`
|
|
32
|
+
- `CropperGrid`
|
|
33
|
+
- `CropperViewer`
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### 1. Global Registration (Optional)
|
|
38
|
+
|
|
39
|
+
If you want to make all components available globally throughout your application without needing to import them in every file, register the library as a plugin in your main entry file (e.g. `main.ts`):
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createApp } from "vue";
|
|
43
|
+
import App from "./App.vue";
|
|
44
|
+
import VueCropperJs from "vue-cropperjs2";
|
|
45
|
+
|
|
46
|
+
const app = createApp(App);
|
|
47
|
+
|
|
48
|
+
// Registers all cropper components globally
|
|
49
|
+
app.use(VueCropperJs);
|
|
50
|
+
|
|
51
|
+
app.mount("#app");
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Local Usage / `<script setup>`
|
|
55
|
+
|
|
56
|
+
If you prefer to import components locally, you can import them directly from `vue-cropperjs2`.
|
|
57
|
+
|
|
58
|
+
Here is a full example of a basic image cropping interface:
|
|
59
|
+
|
|
60
|
+
```vue
|
|
61
|
+
<script setup lang="ts">
|
|
62
|
+
import { useTemplateRef } from "vue";
|
|
63
|
+
import {
|
|
64
|
+
CropperCanvas,
|
|
65
|
+
CropperImage,
|
|
66
|
+
CropperShade,
|
|
67
|
+
CropperHandle,
|
|
68
|
+
CropperSelection,
|
|
69
|
+
CropperGrid,
|
|
70
|
+
CropperCrosshair,
|
|
71
|
+
CropperViewer
|
|
72
|
+
} from "vue-cropperjs2";
|
|
73
|
+
|
|
74
|
+
// Access the selection component to trigger cropping actions
|
|
75
|
+
const selectionRef = useTemplateRef("selectionRef");
|
|
76
|
+
const target = useTemplateRef("target");
|
|
77
|
+
|
|
78
|
+
const onChange = (e: Event) => {
|
|
79
|
+
console.log("Selection changed", e);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const toCanvas = async () => {
|
|
83
|
+
// Extract the cropped image canvas and append it to the DOM
|
|
84
|
+
if (selectionRef.value?.selection) {
|
|
85
|
+
const canvas = await selectionRef.value.selection.$toCanvas();
|
|
86
|
+
target.value?.appendChild(canvas);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<template>
|
|
92
|
+
<!-- Main Cropping Area -->
|
|
93
|
+
<CropperCanvas :background="true">
|
|
94
|
+
<CropperImage
|
|
95
|
+
src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg"
|
|
96
|
+
alt="Picture"
|
|
97
|
+
:rotatable="true"
|
|
98
|
+
:scalable="true"
|
|
99
|
+
:skewable="true"
|
|
100
|
+
:translatable="true"
|
|
101
|
+
/>
|
|
102
|
+
<CropperShade :hidden="true" />
|
|
103
|
+
<CropperHandle action="select" :plain="true" />
|
|
104
|
+
<CropperSelection
|
|
105
|
+
id="Sel"
|
|
106
|
+
:movable="true"
|
|
107
|
+
:resizable="true"
|
|
108
|
+
:initial-coverage="0.5"
|
|
109
|
+
:aspect-ratio="1"
|
|
110
|
+
@change="onChange"
|
|
111
|
+
ref="selectionRef"
|
|
112
|
+
>
|
|
113
|
+
<CropperGrid role="grid" :covered="true" />
|
|
114
|
+
<CropperCrosshair :centered="true" />
|
|
115
|
+
<CropperHandle action="move" theme-color="rgba(255, 255, 255, 0.1)" />
|
|
116
|
+
|
|
117
|
+
<!-- Resize Handles -->
|
|
118
|
+
<CropperHandle action="n-resize" />
|
|
119
|
+
<CropperHandle action="e-resize" />
|
|
120
|
+
<CropperHandle action="s-resize" />
|
|
121
|
+
<CropperHandle action="w-resize" />
|
|
122
|
+
<CropperHandle action="ne-resize" />
|
|
123
|
+
<CropperHandle action="nw-resize" />
|
|
124
|
+
<CropperHandle action="se-resize" />
|
|
125
|
+
<CropperHandle action="sw-resize" />
|
|
126
|
+
</CropperSelection>
|
|
127
|
+
</CropperCanvas>
|
|
128
|
+
|
|
129
|
+
<div class="actions">
|
|
130
|
+
<!-- Preview Viewer -->
|
|
131
|
+
<CropperViewer selection="#Sel" style="width: 200px; height: 200px;" />
|
|
132
|
+
|
|
133
|
+
<!-- Action Button -->
|
|
134
|
+
<button @click="toCanvas">Get Cropped Image</button>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<!-- Container for the exported cropped image -->
|
|
138
|
+
<div ref="target" />
|
|
139
|
+
</template>
|
|
140
|
+
|
|
141
|
+
<style scoped>
|
|
142
|
+
.actions {
|
|
143
|
+
display: flex;
|
|
144
|
+
gap: 20px;
|
|
145
|
+
align-items: flex-start;
|
|
146
|
+
margin-top: 20px;
|
|
147
|
+
}
|
|
148
|
+
</style>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Props and Events
|
|
152
|
+
Because `vue-cropperjs2` components are direct wrappers over Cropper.js Web Components, all native properties and events of Cropper.js v2 are supported. Please refer to the [official Cropper.js v2 documentation](https://github.com/fengyuanchen/cropperjs) for a complete list of properties, methods, and events for each element.
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-cropperjs2",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"preview": "vite preview"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"cropperjs": "^2.
|
|
24
|
-
"vue": "^3.5.
|
|
23
|
+
"cropperjs": "^2.1.1",
|
|
24
|
+
"vue": "^3.5.39"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@vitejs/plugin-vue": "^
|
|
28
|
-
"@vue/tsconfig": "^0.
|
|
29
|
-
"typescript": "~
|
|
30
|
-
"vite": "^
|
|
31
|
-
"vite-plugin-dts": "^
|
|
32
|
-
"vue-tsc": "^
|
|
27
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
28
|
+
"@vue/tsconfig": "^0.9.1",
|
|
29
|
+
"typescript": "~6.0.3",
|
|
30
|
+
"vite": "^8.1.3",
|
|
31
|
+
"vite-plugin-dts": "^5.0.3",
|
|
32
|
+
"vue-tsc": "^3.3.6"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { App } from 'vue';
|
|
2
|
-
import { ComponentOptionsMixin } from 'vue';
|
|
3
|
-
import { ComponentProvideOptions } from 'vue';
|
|
4
|
-
import { CropperCanvas as CropperCanvas_2 } from 'cropperjs';
|
|
5
|
-
import { DefineComponent } from 'vue';
|
|
6
|
-
import { PublicProps } from 'vue';
|
|
7
|
-
|
|
8
|
-
declare const __VLS_component: DefineComponent<CropperCanvasProps, {
|
|
9
|
-
$setAction: ((action: string) => CropperCanvas_2) | undefined;
|
|
10
|
-
$toCanvas: ((options?: {
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
beforeDraw?: (context: CanvasRenderingContext2D, canvas: HTMLCanvasElement) => void;
|
|
14
|
-
}) => Promise<HTMLCanvasElement>) | undefined;
|
|
15
|
-
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CropperCanvasProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
16
|
-
|
|
17
|
-
declare const __VLS_component_2: DefineComponent<SelectionProperty, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<SelectionProperty> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
18
|
-
|
|
19
|
-
declare type __VLS_Props = {
|
|
20
|
-
resize?: "both" | "horizontal" | "vertical" | "none";
|
|
21
|
-
selection?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
declare function __VLS_template(): {
|
|
25
|
-
attrs: Partial<{}>;
|
|
26
|
-
slots: {
|
|
27
|
-
default?(_: {}): any;
|
|
28
|
-
};
|
|
29
|
-
refs: {
|
|
30
|
-
canvasRef: unknown;
|
|
31
|
-
};
|
|
32
|
-
rootEl: any;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
declare function __VLS_template_2(): {
|
|
36
|
-
attrs: Partial<{}>;
|
|
37
|
-
slots: {
|
|
38
|
-
default?(_: {}): any;
|
|
39
|
-
};
|
|
40
|
-
refs: {};
|
|
41
|
-
rootEl: any;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
45
|
-
|
|
46
|
-
declare type __VLS_TemplateResult_2 = ReturnType<typeof __VLS_template_2>;
|
|
47
|
-
|
|
48
|
-
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
49
|
-
new (): {
|
|
50
|
-
$slots: S;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
declare type __VLS_WithTemplateSlots_2<T, S> = T & {
|
|
55
|
-
new (): {
|
|
56
|
-
$slots: S;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
declare type CanvasImageProps = {
|
|
61
|
-
src: string;
|
|
62
|
-
alt?: string;
|
|
63
|
-
initialCenterSize?: "contain" | "cover";
|
|
64
|
-
rotatable?: boolean;
|
|
65
|
-
scalable?: boolean;
|
|
66
|
-
skewable?: boolean;
|
|
67
|
-
slottable?: boolean;
|
|
68
|
-
translatable?: boolean;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export declare const CropperCanvas: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
72
|
-
|
|
73
|
-
declare type CropperCanvasProps = {
|
|
74
|
-
background?: boolean;
|
|
75
|
-
disabled?: boolean;
|
|
76
|
-
scaleStep?: number;
|
|
77
|
-
themeColor?: string;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export declare const CropperCrosshair: DefineComponent<CropperCrosshairProperty, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CropperCrosshairProperty> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
81
|
-
|
|
82
|
-
declare type CropperCrosshairProperty = {
|
|
83
|
-
centered: boolean;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export declare const CropperGrid: DefineComponent<CropperGridProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CropperGridProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
87
|
-
|
|
88
|
-
declare type CropperGridProps = {
|
|
89
|
-
role?: "grid";
|
|
90
|
-
covered?: boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export declare const CropperHandle: DefineComponent<CropperHandleProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CropperHandleProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
94
|
-
|
|
95
|
-
declare type CropperHandleProps = {
|
|
96
|
-
action?: HandleAction;
|
|
97
|
-
plain?: boolean;
|
|
98
|
-
slottable?: boolean;
|
|
99
|
-
themeColor?: string;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export declare const CropperImage: DefineComponent<CanvasImageProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CanvasImageProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
103
|
-
|
|
104
|
-
export declare const CropperSelection: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, __VLS_TemplateResult_2["slots"]>;
|
|
105
|
-
|
|
106
|
-
export declare const CropperShade: DefineComponent<CropperShadeProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CropperShadeProps> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
107
|
-
|
|
108
|
-
declare type CropperShadeProps = {
|
|
109
|
-
x?: number;
|
|
110
|
-
y?: number;
|
|
111
|
-
width?: number;
|
|
112
|
-
height?: number;
|
|
113
|
-
slottable?: boolean;
|
|
114
|
-
themeColor?: string;
|
|
115
|
-
hidden?: boolean;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export declare const CropperViewer: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
|
|
119
|
-
|
|
120
|
-
declare const _default: {
|
|
121
|
-
install: (app: App) => void;
|
|
122
|
-
};
|
|
123
|
-
export default _default;
|
|
124
|
-
|
|
125
|
-
declare type HandleAction = "select" | "move" | "n-resize" | "e-resize" | "s-resize" | "w-resize" | "ne-resize" | "nw-resize" | "se-resize" | "sw-resize" | "none";
|
|
126
|
-
|
|
127
|
-
declare type SelectionProperty = {
|
|
128
|
-
x?: number;
|
|
129
|
-
y?: number;
|
|
130
|
-
width?: number;
|
|
131
|
-
height?: number;
|
|
132
|
-
aspectRatio?: number;
|
|
133
|
-
initialAspectRatio?: number;
|
|
134
|
-
initialCoverage?: number;
|
|
135
|
-
dynamic?: boolean;
|
|
136
|
-
movable?: boolean;
|
|
137
|
-
resizable?: boolean;
|
|
138
|
-
zoomable?: boolean;
|
|
139
|
-
multiple?: boolean;
|
|
140
|
-
keyboard?: boolean;
|
|
141
|
-
outlined?: boolean;
|
|
142
|
-
precise?: boolean;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export { }
|