senangwebs-photobooth 1.0.2 → 2.0.2

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.
Files changed (43) hide show
  1. package/README.md +220 -236
  2. package/dist/swp.css +790 -256
  3. package/dist/swp.js +1 -1
  4. package/examples/data-attribute.html +69 -0
  5. package/examples/index.html +56 -51
  6. package/examples/studio.html +83 -0
  7. package/package.json +10 -6
  8. package/src/css/swp.css +790 -256
  9. package/src/js/core/Canvas.js +398 -0
  10. package/src/js/core/EventEmitter.js +188 -0
  11. package/src/js/core/History.js +250 -0
  12. package/src/js/core/Keyboard.js +323 -0
  13. package/src/js/filters/FilterManager.js +248 -0
  14. package/src/js/index.js +48 -0
  15. package/src/js/io/Clipboard.js +52 -0
  16. package/src/js/io/FileManager.js +150 -0
  17. package/src/js/layers/BlendModes.js +342 -0
  18. package/src/js/layers/Layer.js +415 -0
  19. package/src/js/layers/LayerManager.js +459 -0
  20. package/src/js/selection/Selection.js +167 -0
  21. package/src/js/swp.js +247 -761
  22. package/src/js/tools/BaseTool.js +264 -0
  23. package/src/js/tools/BrushTool.js +314 -0
  24. package/src/js/tools/CropTool.js +400 -0
  25. package/src/js/tools/EraserTool.js +155 -0
  26. package/src/js/tools/EyedropperTool.js +184 -0
  27. package/src/js/tools/FillTool.js +109 -0
  28. package/src/js/tools/GradientTool.js +141 -0
  29. package/src/js/tools/HandTool.js +51 -0
  30. package/src/js/tools/MarqueeTool.js +103 -0
  31. package/src/js/tools/MoveTool.js +465 -0
  32. package/src/js/tools/ShapeTool.js +285 -0
  33. package/src/js/tools/TextTool.js +253 -0
  34. package/src/js/tools/ToolManager.js +277 -0
  35. package/src/js/tools/ZoomTool.js +68 -0
  36. package/src/js/ui/ColorManager.js +71 -0
  37. package/src/js/ui/UI.js +1211 -0
  38. package/swp_preview1.png +0 -0
  39. package/swp_preview2.png +0 -0
  40. package/webpack.config.js +4 -11
  41. package/dist/styles.js +0 -1
  42. package/examples/customization.html +0 -360
  43. package/swp_preview.png +0 -0
package/README.md CHANGED
@@ -1,297 +1,281 @@
1
- # SenangWebs Photobooth (SWP)
1
+ # SenangWebs Photobooth
2
2
 
3
- A lightweight and easy-to-use JavaScript library for client-side photo editing. No dependencies, no server-side processing - everything happens in your browser!
3
+ A browser-based image editor featuring layers, drawing tools, and filters.
4
4
 
5
- ![SenangWebs Photobooth Preview](https://raw.githubusercontent.com/a-hakim/senangwebs-photobooth/master/swp_preview.png)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)
6
+ [![Built with SenangStart Icons](https://img.shields.io/badge/Built%20with-SenangStart%20Icons-2563EB.svg)](https://github.com/bookklik-technologies/senangstart-icons)
6
7
 
7
- ## Quick Start
8
-
9
- ### Development
10
-
11
- 1. **Install dependencies:**
12
-
13
- ```bash
14
- npm install
15
- ```
16
-
17
- 2. **Start development server:**
18
-
19
- ```bash
20
- npm run dev
21
- ```
22
-
23
- This will start a dev server at `http://localhost:3000` with hot reloading.
8
+ | example 1 | example 2 |
9
+ | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
10
+ | ![SenangWebs Photobooth Preview 1](https://raw.githubusercontent.com/a-hakim/senangwebs-photobooth/master/swp_preview1.png) | ![SenangWebs Photobooth Preview 2](https://raw.githubusercontent.com/a-hakim/senangwebs-photobooth/master/swp_preview2.png) |
24
11
 
25
- 3. **Build for production:**
26
-
27
- ```bash
28
- npm run build
29
- ```
30
-
31
- This creates optimized files in the `dist/` directory.
32
-
33
- ### Using the Library
34
-
35
- #### Include the built files:
12
+ ## Features
36
13
 
37
- ```html
38
- <link rel="stylesheet" href="dist/swp.min.css" />
39
- <script src="dist/swp.min.js"></script>
14
+ ### Layer System
15
+ - Multiple layers with full compositing
16
+ - 24 blend modes (Normal, Multiply, Screen, Overlay, etc.)
17
+ - Layer opacity, visibility, and locking
18
+ - Merge, duplicate, and reorder layers
19
+ - Layers panel with real-time updates
20
+
21
+ ### History & Layers Panels
22
+ - **History Panel** - View and navigate undo/redo history
23
+ - **Layers Panel** - Manage layers with visibility toggles and selection
24
+ - Collapsible side panels with clean UI
25
+
26
+ ### Editing Tools
27
+ | Menu | Description |
28
+ |------|-------------|
29
+ | Crop | Crop with aspect ratio presets (Free, 1:1, 4:3, 16:9) |
30
+ | Rotate | Rotate by ±90° or custom angle slider |
31
+ | Flip | Flip horizontal or vertical |
32
+ | Resize | Resize canvas with presets and aspect ratio lock |
33
+ | Draw | Brush tool with customizable size and color |
34
+ | Shape | Rectangle, ellipse, line with fill and stroke options |
35
+ | Text | Add text with font, size, color, and style controls |
36
+ | Filter | Apply filters with intensity control |
37
+
38
+ ### Filters & Adjustments
39
+ - Brightness, Contrast
40
+ - Blur, Sharpen
41
+ - Grayscale, Sepia, Invert
42
+
43
+ ### Keyboard Shortcuts
44
+ - `Ctrl+Z` / `Ctrl+Shift+Z` - Undo / Redo
45
+ - `Ctrl+N` - New document
46
+ - `Ctrl+O` - Open image
47
+ - `Ctrl+S` - Save project
48
+ - `Ctrl+E` - Export image
49
+ - `[` / `]` - Decrease / Increase brush size
50
+ - `X` - Swap foreground/background colors
51
+ - `D` - Reset to black/white
52
+ - `Tab` - Toggle panels
53
+ - `Space` - Temporary hand tool
54
+ - `DEL` - Delete selected layer
55
+
56
+ ### File Operations
57
+ - Load images (PNG, JPEG, WebP)
58
+ - Download with format selection (PNG, JPEG, WebP)
59
+ - Save projects as `.swp` files
60
+ - Export to PNG, JPEG, WebP
61
+
62
+ ## Installation
63
+
64
+ ### NPM
65
+ ```bash
66
+ npm install senangwebs-photobooth
40
67
  ```
41
68
 
42
- #### Or use source files directly:
43
-
69
+ ### CDN
44
70
  ```html
45
- <link rel="stylesheet" href="src/css/swp.css" />
46
- <script src="src/js/swp.js"></script>
71
+ <link rel="stylesheet" href="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.css">
72
+ <script src="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.js"></script>
47
73
  ```
48
74
 
49
- ## Features
75
+ ### Manual Download
76
+ Download `swp.js` and `swp.css` from the `dist` folder.
50
77
 
51
- - Cropping\*\* - Select and crop image areas with predefined aspect ratios
52
- - Rotating\*\* - Rotate images in 90-degree increments
53
- - Flipping\*\* - Flip images horizontally and vertically
54
- - Adjustments\*\* - Fine-tune brightness, contrast, and saturation
55
- - Filters\*\* - Apply pre-defined filters (Grayscale, Sepia, Invert, Blur)
56
- - **Export** - Save edited images in JPEG or PNG format
78
+ ## Quick Start
57
79
 
58
- ## Usage
80
+ SenangWebs Photobooth supports two initialization methods: JavaScript API and data attributes.
59
81
 
60
- ### Programmatic Approach
82
+ ### JavaScript API
61
83
 
62
84
  ```html
63
- <div id="photobooth-container"></div>
64
-
65
- <script>
66
- const container = document.getElementById("photobooth-container");
67
- const swp = new SWP(container, {
68
- imageUrl: "path/to/your/image.jpg",
69
- width: 800,
70
- height: 600,
71
- });
72
-
73
- // Listen to events
74
- swp.on("load", () => console.log("Image loaded"));
75
- swp.on("change", () => console.log("Image changed"));
76
- swp.on("save", () => console.log("Image saved"));
77
- </script>
85
+ <!DOCTYPE html>
86
+ <html>
87
+ <head>
88
+ <link rel="stylesheet" href="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.css">
89
+ <style>
90
+ #editor { width: 100%; height: 100vh; }
91
+ </style>
92
+ </head>
93
+ <body>
94
+ <div id="editor"></div>
95
+ <script src="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.js"></script>
96
+ <script>
97
+ const editor = new SWP('#editor', {
98
+ width: 1920,
99
+ height: 1080,
100
+ theme: 'dark',
101
+ accentColor: '#00FF99'
102
+ });
103
+
104
+ editor.on('ready', () => {
105
+ console.log('Editor ready!');
106
+ });
107
+ </script>
108
+ </body>
109
+ </html>
78
110
  ```
79
111
 
80
- ### Declarative Approach
112
+ ### Data Attribute Initialization
81
113
 
82
- Use HTML data attributes for zero-JavaScript configuration:
114
+ You can also initialize the editor using data attributes for a no-code setup:
83
115
 
84
116
  ```html
85
- <!-- Basic -->
86
- <div data-swp></div>
87
-
88
- <!-- With configuration -->
89
- <div
90
- data-swp
91
- data-swp-width="900"
92
- data-swp-height="600"
93
- data-swp-show-labels="false"
94
- ></div>
95
-
96
- <!-- With custom labels (simple format) -->
97
- <div
98
- data-swp
99
- data-swp-labels="upload: 'Muat Naik'; save: 'Simpan'; reset: 'Set Semula'"
100
- ></div>
101
-
102
- <!-- With custom labels (JSON format) -->
103
- <div
104
- data-swp
105
- data-swp-labels='{"upload":"Télécharger","save":"Enregistrer"}'
106
- ></div>
117
+ <!DOCTYPE html>
118
+ <html>
119
+ <head>
120
+ <link rel="stylesheet" href="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.css">
121
+ <style>
122
+ #editor { width: 100%; height: 100vh; }
123
+ </style>
124
+ </head>
125
+ <body>
126
+ <div id="editor"
127
+ data-swp
128
+ data-swp-width="1920"
129
+ data-swp-height="1080"
130
+ data-swp-theme="dark"
131
+ data-swp-accent-color="#00FF99">
132
+ </div>
133
+ <script src="https://unpkg.com/senangwebs-photobooth@latest/dist/swp.js"></script>
134
+ </body>
135
+ </html>
107
136
  ```
108
137
 
109
- **Available Data Attributes:**
110
-
111
- - `data-swp` - Enable auto-initialization
112
- - `data-swp-width` - Canvas width (number)
113
- - `data-swp-height` - Canvas height (number)
114
- - `data-swp-image-url` - Initial image URL
115
- - `data-swp-show-icons` - Show/hide icons ("true" or "false")
116
- - `data-swp-show-labels` - Show/hide labels ("true" or "false")
117
- - `data-swp-labels` - Custom labels (see formats above)
118
-
119
- The library will automatically initialize when the DOM is ready.
120
-
121
- ## API Reference
122
-
123
- ### Initialization
138
+ #### Accessing Data Attribute Instances
124
139
 
125
140
  ```javascript
126
- const swp = new SWP(container, options);
127
- ```
141
+ // Access via element property
142
+ const editor = document.getElementById('editor').swpInstance;
128
143
 
129
- **Options:**
130
-
131
- - `imageUrl` (String) - URL of the image to load
132
- - `width` (Number) - Width of the editor in pixels (default: 800)
133
- - `height` (Number) - Height of the editor in pixels (default: 600)
134
- - `showIcons` (Boolean) - Show icons in toolbar buttons (default: true)
135
- - `showLabels` (Boolean) - Show text labels in toolbar buttons (default: true)
136
- - `labels` (Object) - Custom labels for toolbar buttons
137
- - `upload` (String|null) - Label for upload button (default: 'Upload')
138
- - `rotateLeft` (String|null) - Label for rotate left button (default: null)
139
- - `rotateRight` (String|null) - Label for rotate right button (default: null)
140
- - `flipH` (String|null) - Label for flip horizontal button (default: null)
141
- - `flipV` (String|null) - Label for flip vertical button (default: null)
142
- - `resize` (String|null) - Label for resize button (default: 'Resize')
143
- - `adjust` (String|null) - Label for adjustments button (default: 'Adjust')
144
- - `filters` (String|null) - Label for filters button (default: 'Filters')
145
- - `reset` (String|null) - Label for reset button (default: 'Reset')
146
- - `save` (String|null) - Label for save button (default: 'Save')
147
-
148
- **Customization Examples:**
144
+ // Access all auto-initialized instances
145
+ const allEditors = SWP.instances;
149
146
 
150
- ```javascript
151
- // Icons only (compact view)
152
- const swp = new SWP(container, {
153
- showLabels: false,
154
- });
155
-
156
- // Custom labels (multilingual support)
157
- const swp = new SWP(container, {
158
- labels: {
159
- upload: "Télécharger",
160
- save: "Enregistrer",
161
- reset: "Réinitialiser",
162
- },
163
- });
164
-
165
- // Hide specific labels (set to null)
166
- const swp = new SWP(container, {
167
- labels: {
168
- rotateLeft: null, // No label, icon only
169
- rotateRight: null,
170
- },
171
- });
172
-
173
- // Show labels for rotate and flip buttons
174
- const swp = new SWP(container, {
175
- labels: {
176
- rotateLeft: "Rotate Left",
177
- rotateRight: "Rotate Right",
178
- flipH: "Flip Horizontal",
179
- flipV: "Flip Vertical",
180
- },
181
- });
147
+ // Manually trigger auto-init (if needed after dynamic content load)
148
+ SWP.autoInit();
182
149
  ```
183
150
 
184
- **Note:** By default, `rotateLeft`, `rotateRight`, `flipH`, and `flipV` have `null` labels (icon-only display) to keep the toolbar compact. You can add custom labels to these buttons as shown above.
151
+ #### Available Data Attributes
185
152
 
186
- ### Methods
187
-
188
- #### `loadImage(imageUrl)`
153
+ | Attribute | Type | Default | Description |
154
+ |-----------|------|---------|-------------|
155
+ | `data-swp` | - | - | Required. Marks element for auto-initialization |
156
+ | `data-swp-width` | number | 1920 | Canvas width in pixels |
157
+ | `data-swp-height` | number | 1080 | Canvas height in pixels |
158
+ | `data-swp-theme` | string | 'dark' | UI theme ('dark' or 'light') |
159
+ | `data-swp-accent-color` | string | '#00FF99' | UI accent color (hex format) |
189
160
 
190
- Load a new image into the editor.
161
+ ## API Reference
191
162
 
163
+ ### Constructor
192
164
  ```javascript
193
- swp.loadImage("path/to/image.jpg");
165
+ const editor = new SWP(container, options);
194
166
  ```
195
167
 
196
- #### `rotate(degrees)`
168
+ | Option | Type | Default | Description |
169
+ |--------|------|---------|-------------|
170
+ | `width` | number | 1920 | Canvas width |
171
+ | `height` | number | 1080 | Canvas height |
172
+ | `theme` | string | 'dark' | UI theme ('dark' or 'light') |
173
+ | `accentColor` | string | '#00FF99' | UI accent color |
197
174
 
198
- Rotate the image by specified degrees.
175
+ ### Methods
199
176
 
177
+ #### Document Operations
200
178
  ```javascript
201
- swp.rotate(90); // Rotate 90 degrees clockwise
202
- swp.rotate(-90); // Rotate 90 degrees counter-clockwise
203
- ```
179
+ // Create new document
180
+ editor.newDocument(width, height, background);
204
181
 
205
- #### `flip(direction)`
182
+ // Load image from URL
183
+ await editor.loadImage('path/to/image.jpg');
206
184
 
207
- Flip the image horizontally or vertically.
185
+ // Export as data URL
186
+ const dataURL = editor.getImageData('png', 1.0);
208
187
 
209
- ```javascript
210
- swp.flip("horizontal");
211
- swp.flip("vertical");
188
+ // Download export (format: 'png', 'jpeg', or 'webp')
189
+ editor.export('png', 1.0);
212
190
  ```
213
191
 
214
- #### `setAdjustment(adjustment, value)`
215
-
216
- Apply adjustments to the image.
217
-
192
+ #### History
218
193
  ```javascript
219
- swp.setAdjustment("brightness", 150); // Range: 0-200
220
- swp.setAdjustment("contrast", 120); // Range: 0-200
221
- swp.setAdjustment("saturation", 80); // Range: 0-200
194
+ editor.undo();
195
+ editor.redo();
222
196
  ```
223
197
 
224
- #### `applyFilter(filterName)`
225
-
226
- Apply a pre-defined filter.
227
-
198
+ #### Tools
228
199
  ```javascript
229
- swp.applyFilter("grayscale");
230
- swp.applyFilter("sepia");
231
- swp.applyFilter("invert");
232
- swp.applyFilter("blur");
233
- swp.applyFilter("none"); // Remove filter
200
+ editor.setTool('brush');
201
+ editor.setTool('move');
234
202
  ```
235
203
 
236
- #### `crop(x, y, width, height)`
237
-
238
- Crop the image to specified dimensions.
239
-
204
+ #### Filters
240
205
  ```javascript
241
- swp.crop(100, 100, 400, 300);
206
+ editor.applyFilter('brightness', { value: 20 });
207
+ editor.applyFilter('blur', { radius: 5 });
208
+ editor.applyFilter('grayscale');
242
209
  ```
243
210
 
244
- #### `reset()`
245
-
246
- Reset all edits and revert to original image.
247
-
211
+ #### Theming
248
212
  ```javascript
249
- swp.reset();
250
- ```
251
-
252
- #### `getImageData(format, quality)`
213
+ // Change theme at runtime
214
+ editor.setTheme('light'); // or 'dark'
253
215
 
254
- Export the edited image data.
255
-
256
- ```javascript
257
- const dataUrl = swp.getImageData("png"); // PNG format
258
- const dataUrl = swp.getImageData("jpeg", 0.9); // JPEG with 90% quality
216
+ // Change accent color at runtime
217
+ editor.setAccentColor('#FF6B6B');
259
218
  ```
260
219
 
261
- ### Events
262
-
263
- Listen to events using the `on()` method:
264
-
220
+ #### Events
265
221
  ```javascript
266
- swp.on("load", () => {
267
- console.log("Image loaded successfully");
268
- });
269
-
270
- swp.on("change", () => {
271
- console.log("Image has been edited");
272
- });
273
-
274
- swp.on("save", () => {
275
- console.log("Image saved");
276
- });
222
+ editor.on('ready', () => { });
223
+ editor.on('tool:select', (data) => { });
224
+ editor.on('layer:add', (data) => { });
225
+ editor.on('history:push', (data) => { });
277
226
  ```
278
227
 
279
- ## NPM Scripts
280
-
281
- - `npm run dev` - Start development server with hot reload
282
- - `npm run build` - Build for production
228
+ ### Available Events
229
+ - `ready` - Editor initialized
230
+ - `change` - Theme or accent color changed
231
+ - `tool:select` - Tool changed
232
+ - `tool:start` - Tool action started
233
+ - `tool:end` - Tool action ended
234
+ - `layer:add` - Layer added
235
+ - `layer:remove` - Layer removed
236
+ - `layer:select` - Layer selected
237
+ - `history:push` - History state added
238
+ - `history:undo` - Undo performed
239
+ - `history:redo` - Redo performed
240
+ - `canvas:zoom` - Zoom changed
241
+ - `color:foreground` - Foreground color changed
242
+ - `color:background` - Background color changed
243
+
244
+ ## UI Overview
245
+
246
+ ### Header Bar
247
+ - **Load** - Open image file
248
+ - **Download** - Export with format selection (PNG/JPEG/WebP)
249
+ - **Undo/Redo** - History navigation
250
+ - **History** - Toggle history panel
251
+ - **Layers** - Toggle layers panel
252
+ - **Reset** - Reset canvas
253
+ - **Center** - Fit canvas to screen
254
+ - **Fullscreen** - Toggle fullscreen mode
255
+
256
+ ### Menu Bar (Bottom)
257
+ - **Crop** - Crop with aspect ratio presets
258
+ - **Rotate** - Rotate canvas by angle
259
+ - **Flip** - Flip horizontal/vertical
260
+ - **Resize** - Resize canvas dimensions
261
+ - **Draw** - Brush tool with size and color
262
+ - **Shape** - Draw shapes (rectangle, ellipse, line)
263
+ - **Text** - Add and style text
264
+ - **Filter** - Apply image filters
265
+
266
+ ## Development
267
+
268
+ ```bash
269
+ # Install dependencies
270
+ npm install
271
+
272
+ # Development mode with watch
273
+ npm run dev
274
+
275
+ # Production build
276
+ npm run build
277
+ ```
283
278
 
284
279
  ## License
285
280
 
286
- MIT License
287
-
288
- ## Contributing
289
-
290
- Contributions are welcome! Please feel free to submit a Pull Request.
291
-
292
- ## Future Enhancements
293
-
294
- - More filters and adjustments
295
- - Text and sticker overlays
296
- - Touch gesture support
297
- - Framework integrations (React, Vue, Angular)
281
+ MIT License