@h4md1/visual-image-tool 0.2.0 → 0.2.1

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 CHANGED
@@ -23,10 +23,10 @@ npm install @h4md1/visual-image-tool
23
23
 
24
24
  ```javascript
25
25
  // ES modules import (recommended)
26
- import VisualImageTool from '@h4md1/visual-image-tool';
26
+ import VisualImageTool from "@h4md1/visual-image-tool";
27
27
 
28
28
  // OR CommonJS import
29
- const VisualImageTool = require('@h4md1/visual-image-tool');
29
+ const VisualImageTool = require("@h4md1/visual-image-tool");
30
30
 
31
31
  // OR direct usage via script tag (UMD)
32
32
  // <script src="node_modules/image-tool/dist/image-tool.umd.js"></script>
@@ -37,12 +37,12 @@ const VisualImageTool = require('@h4md1/visual-image-tool');
37
37
  ```javascript
38
38
  // Create an instance with an image
39
39
  const imageTool = new VisualImageTool.VisualImageTool({
40
- imageElement: document.getElementById('myImage'),
40
+ imageElement: document.getElementById("myImage"),
41
41
  debug: true, // Enable debug logs for overlay positioning (optional)
42
42
  onChange: (data) => {
43
- console.log('Focus point:', data.focusPoint);
44
- console.log('Crop zone:', data.cropZone);
45
- }
43
+ console.log("Focus point:", data.focusPoint);
44
+ console.log("Crop zone:", data.cropZone);
45
+ },
46
46
  });
47
47
  ```
48
48
 
@@ -71,7 +71,7 @@ const cropZone = imageTool.getCropZone();
71
71
  ```javascript
72
72
  const imageTool = new VisualImageTool.VisualImageTool({
73
73
  // Image element (required) - can be a CSS selector or a DOM element
74
- imageElement: '#myImage',
74
+ imageElement: "#myImage",
75
75
 
76
76
  // Enable debug logs for overlay positioning (optional)
77
77
  debug: true, // Set to true to see overlay positioning logs in the console
@@ -80,34 +80,34 @@ const imageTool = new VisualImageTool.VisualImageTool({
80
80
  focusPoint: {
81
81
  enabled: true, // Enable/disable the feature
82
82
  style: {
83
- width: '30px',
84
- height: '30px',
85
- border: '3px solid white',
86
- boxShadow: '0 0 0 2px black, 0 0 5px rgba(0,0,0,0.5)',
87
- backgroundColor: 'rgba(255, 0, 0, 0.5)'
88
- }
83
+ width: "30px",
84
+ height: "30px",
85
+ border: "3px solid white",
86
+ boxShadow: "0 0 0 2px black, 0 0 5px rgba(0,0,0,0.5)",
87
+ backgroundColor: "rgba(255, 0, 0, 0.5)",
88
+ },
89
89
  },
90
90
 
91
91
  // Crop zone configuration (optional)
92
92
  cropZone: {
93
93
  enabled: true, // Enable/disable the feature
94
94
  style: {
95
- border: '1px dashed #fff',
96
- backgroundColor: 'rgba(0, 0, 0, 0.4)'
95
+ border: "1px dashed #fff",
96
+ backgroundColor: "rgba(0, 0, 0, 0.4)",
97
97
  },
98
98
  handleStyle: {
99
- width: '14px',
100
- height: '14px',
101
- backgroundColor: 'white',
102
- border: '2px solid black',
103
- boxShadow: '0 0 3px rgba(0,0,0,0.5)'
104
- }
99
+ width: "14px",
100
+ height: "14px",
101
+ backgroundColor: "white",
102
+ border: "2px solid black",
103
+ boxShadow: "0 0 3px rgba(0,0,0,0.5)",
104
+ },
105
105
  },
106
106
 
107
107
  // Callback called on changes (optional)
108
- onChange: function(data) {
108
+ onChange: function (data) {
109
109
  // data contains focusPoint, cropZone, focusActive, cropActive
110
- }
110
+ },
111
111
  });
112
112
  ```
113
113
 
@@ -116,23 +116,31 @@ const imageTool = new VisualImageTool.VisualImageTool({
116
116
  ### Methods
117
117
 
118
118
  #### `toggleFocusPoint(active)`
119
+
119
120
  Enables or disables the focus point.
121
+
120
122
  - `active` (boolean, optional): If set, forces the state to this value. If omitted, toggles the current state.
121
123
  - Returns: The VisualImageTool instance for chaining.
122
124
 
123
125
  #### `toggleCropZone(active)`
126
+
124
127
  Enables or disables the crop zone.
128
+
125
129
  - `active` (boolean, optional): If set, forces the state to this value. If omitted, toggles the current state.
126
130
  - Returns: The VisualImageTool instance for chaining.
127
131
 
128
132
  #### `setFocusPoint(x, y)`
133
+
129
134
  Sets the position of the focus point.
135
+
130
136
  - `x` (number): X coordinate in original pixels.
131
137
  - `y` (number): Y coordinate in original pixels.
132
138
  - Returns: The VisualImageTool instance for chaining.
133
139
 
134
140
  #### `setCropZone(x, y, width, height)`
141
+
135
142
  Sets the position and dimensions of the crop zone.
143
+
136
144
  - `x` (number): X coordinate in original pixels.
137
145
  - `y` (number): Y coordinate in original pixels.
138
146
  - `width` (number): Width in original pixels.
@@ -140,18 +148,25 @@ Sets the position and dimensions of the crop zone.
140
148
  - Returns: The VisualImageTool instance for chaining.
141
149
 
142
150
  #### `getFocusPoint()`
151
+
143
152
  Gets the current position of the focus point.
153
+
144
154
  - Returns: An object `{x, y}` with coordinates in original pixels.
145
155
 
146
156
  #### `getCropZone()`
157
+
147
158
  Gets the current position and dimensions of the crop zone.
159
+
148
160
  - Returns: An object `{x, y, width, height}` with values in original pixels.
149
161
 
150
162
  #### `getImageDimensions()`
163
+
151
164
  Gets the original dimensions of the image.
165
+
152
166
  - Returns: An object `{width, height}` with dimensions in original pixels.
153
167
 
154
168
  #### `destroy()`
169
+
155
170
  Destroys the instance and cleans up resources.
156
171
 
157
172
  ### Events
@@ -172,27 +187,27 @@ The tool uses the `onChange` callback to notify about changes. This callback rec
172
187
  ### React
173
188
 
174
189
  ```jsx
175
- import React, { useEffect, useRef } from 'react';
176
- import VisualImageTool from '@h4md1/visual-image-tool';
190
+ import React, { useEffect, useRef } from "react";
191
+ import VisualImageTool from "@h4md1/visual-image-tool";
177
192
 
178
193
  function ImageEditor() {
179
194
  const imageRef = useRef(null);
180
195
  const toolRef = useRef(null);
181
-
196
+
182
197
  useEffect(() => {
183
198
  if (imageRef.current && !toolRef.current) {
184
199
  toolRef.current = new VisualImageTool({
185
200
  imageElement: imageRef.current,
186
201
  onChange: (data) => {
187
- console.log('Updated data:', data);
188
- }
202
+ console.log("Updated data:", data);
203
+ },
189
204
  });
190
-
205
+
191
206
  // Enable features
192
207
  toolRef.current.toggleFocusPoint(true);
193
208
  toolRef.current.toggleCropZone(true);
194
209
  }
195
-
210
+
196
211
  // Cleanup
197
212
  return () => {
198
213
  if (toolRef.current) {
@@ -201,7 +216,7 @@ function ImageEditor() {
201
216
  }
202
217
  };
203
218
  }, []);
204
-
219
+
205
220
  return (
206
221
  <div>
207
222
  <img ref={imageRef} src="path/to/image.jpg" alt="Editable" />
@@ -220,22 +235,22 @@ function ImageEditor() {
220
235
  </template>
221
236
 
222
237
  <script>
223
- import VisualImageTool from '@h4md1/visual-image-tool';
238
+ import VisualImageTool from "@h4md1/visual-image-tool";
224
239
 
225
240
  export default {
226
241
  data() {
227
242
  return {
228
- imageTool: null
243
+ imageTool: null,
229
244
  };
230
245
  },
231
246
  mounted() {
232
247
  this.imageTool = new VisualImageTool({
233
248
  imageElement: this.$refs.editableImage,
234
249
  onChange: (data) => {
235
- console.log('Updated data:', data);
236
- }
250
+ console.log("Updated data:", data);
251
+ },
237
252
  });
238
-
253
+
239
254
  // Enable features
240
255
  this.imageTool.toggleFocusPoint(true);
241
256
  this.imageTool.toggleCropZone(true);
@@ -245,7 +260,7 @@ export default {
245
260
  this.imageTool.destroy();
246
261
  this.imageTool = null;
247
262
  }
248
- }
263
+ },
249
264
  };
250
265
  </script>
251
266
  ```
@@ -271,6 +286,19 @@ The `demo/` folder contains the following examples:
271
286
  - Safari (latest versions)
272
287
  - Edge (latest versions)
273
288
 
289
+ ## Code Formatting
290
+
291
+ This project uses a combination of tools for code formatting and linting to ensure consistency:
292
+
293
+ - **[Biome](https://biomejs.dev/)**: Handles formatting and linting for JavaScript (`.js`, `.jsx`), TypeScript (`.ts`, `.tsx`), and JSON (`.json`) files.
294
+ - Check: `npm run lint:check` (`biome check .`)
295
+ - Fix: `npm run lint:fix` (`biome check --write .`)
296
+ - **[Prettier](https://prettier.io/)**: Handles formatting for other file types like HTML, CSS, Markdown, etc.
297
+ - Check: `npm run format:check` (`prettier --check --ignore-unknown .`)
298
+ - Fix: `npm run format:write` (`prettier --write --ignore-unknown .`)
299
+
300
+ These formatting checks are automatically enforced in the CI pipeline (see `.github/workflows/code-quality.yml`) to maintain code quality.
301
+
274
302
  ## License
275
303
 
276
304
  MIT