dphelper 3.7.1 → 3.7.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.
- package/docs/README.md +385 -0
- package/docs/SUMMARY.md +83 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/ai.md +345 -0
- package/docs/markdown/anchor.md +156 -0
- package/docs/markdown/array.md +208 -0
- package/docs/markdown/audio.md +113 -0
- package/docs/markdown/avoid.md +53 -0
- package/docs/markdown/biometric.md +338 -0
- package/docs/markdown/browser.md +203 -0
- package/docs/markdown/check.md +65 -0
- package/docs/markdown/color.md +159 -0
- package/docs/markdown/compress.md +310 -0
- package/docs/markdown/cookie.md +115 -0
- package/docs/markdown/coords.md +127 -0
- package/docs/markdown/credits.md +56 -0
- package/docs/markdown/date.md +260 -0
- package/docs/markdown/disable.md +109 -0
- package/docs/markdown/dispatch.md +108 -0
- package/docs/markdown/element.md +53 -0
- package/docs/markdown/event.md +85 -0
- package/docs/markdown/fetch.md +122 -0
- package/docs/markdown/form.md +302 -0
- package/docs/markdown/format.md +122 -0
- package/docs/markdown/i18n.md +292 -0
- package/docs/markdown/image.md +298 -0
- package/docs/markdown/json.md +269 -0
- package/docs/markdown/load.md +133 -0
- package/docs/markdown/logging.md +99 -0
- package/docs/markdown/math.md +172 -0
- package/docs/markdown/memory.md +85 -0
- package/docs/markdown/navigation.md +152 -0
- package/docs/markdown/net.md +60 -0
- package/docs/markdown/obj.md +242 -0
- package/docs/markdown/path.md +46 -0
- package/docs/markdown/promise.md +94 -0
- package/docs/markdown/sanitize.md +118 -0
- package/docs/markdown/screen.md +78 -0
- package/docs/markdown/scrollbar.md +82 -0
- package/docs/markdown/security.md +289 -0
- package/docs/markdown/shortcut.md +100 -0
- package/docs/markdown/socket.md +134 -0
- package/docs/markdown/sse.md +120 -0
- package/docs/markdown/svg.md +167 -0
- package/docs/markdown/sync.md +147 -0
- package/docs/markdown/system.md +78 -0
- package/docs/markdown/terminal.md +73 -0
- package/docs/markdown/text.md +245 -0
- package/docs/markdown/timer.md +98 -0
- package/docs/markdown/tools.md +111 -0
- package/docs/markdown/translators.md +65 -0
- package/docs/markdown/trigger.md +99 -0
- package/docs/markdown/triggers.md +133 -0
- package/docs/markdown/type.md +109 -0
- package/docs/markdown/types.md +102 -0
- package/docs/markdown/ui.md +45 -0
- package/docs/markdown/window.md +211 -0
- package/docs/markdown/worker.md +223 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# i18n
|
|
2
|
+
|
|
3
|
+
Internationalization and localization utilities for multi-language support, including translations, pluralization, date/number formatting, and relative time.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `setLocale` | Set current locale | `dphelper.i18n.setLocale('it')` |
|
|
10
|
+
| `getLocale` | Get current locale | `dphelper.i18n.getLocale()` |
|
|
11
|
+
| `t` | Translate a key | `dphelper.i18n.t('hello', { name: 'World' })` |
|
|
12
|
+
| `addTranslations` | Add translation strings | `dphelper.i18n.addTranslations('it', { hello: 'Ciao!' })` |
|
|
13
|
+
| `pluralize` | Get pluralized string | `dphelper.i18n.pluralize(5, { one: 'item', other: 'items' })` |
|
|
14
|
+
| `number` | Format number by locale | `dphelper.i18n.number(1234.56, 'de-DE', { currency: 'EUR' })` |
|
|
15
|
+
| `date` | Format date by locale | `dphelper.i18n.date(new Date(), 'en-US', { dateStyle: 'long' })` |
|
|
16
|
+
| `relativeTime` | Get relative time string | `dphelper.i18n.relativeTime(Date.now() - 3600000)` |
|
|
17
|
+
| `list` | Format list by locale | `dphelper.i18n.list(['a', 'b', 'c'], 'en')` |
|
|
18
|
+
| `getSupportedLocales` | Get list of locales | `dphelper.i18n.getSupportedLocales()` |
|
|
19
|
+
|
|
20
|
+
## Description
|
|
21
|
+
|
|
22
|
+
Complete internationalization module featuring:
|
|
23
|
+
- **Translation System** - Key-based translations with variable interpolation
|
|
24
|
+
- **Pluralization** - Support for multiple plural forms (zero, one, two, few, many, other)
|
|
25
|
+
- **Locale-aware Formatting** - Numbers, dates, and lists formatted per locale
|
|
26
|
+
- **Relative Time** - "2 hours ago", "in 5 minutes" style strings
|
|
27
|
+
- **Auto-detection** - Automatic browser locale detection
|
|
28
|
+
- **Extensible** - Add custom translations for any language
|
|
29
|
+
|
|
30
|
+
## Usage Examples
|
|
31
|
+
|
|
32
|
+
### Basic Translation
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// Set locale
|
|
36
|
+
dphelper.i18n.setLocale('en');
|
|
37
|
+
|
|
38
|
+
// Simple translation
|
|
39
|
+
console.log(dphelper.i18n.t('hello')); // "Hello {name}!"
|
|
40
|
+
console.log(dphelper.i18n.t('hello', { name: 'World' })); // "Hello World!"
|
|
41
|
+
console.log(dphelper.i18n.t('goodbye')); // "Goodbye!"
|
|
42
|
+
|
|
43
|
+
// Change locale
|
|
44
|
+
dphelper.i18n.setLocale('it');
|
|
45
|
+
console.log(dphelper.i18n.t('hello', { name: 'Mario' })); // "Ciao Mario!"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Adding Custom Translations
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// Add Italian translations
|
|
52
|
+
dphelper.i18n.addTranslations('it', {
|
|
53
|
+
'hello': 'Ciao {name}!',
|
|
54
|
+
'goodbye': 'Arrivederci!',
|
|
55
|
+
'welcome': 'Benvenuto nella nostra app!',
|
|
56
|
+
'items_count': 'Hai {count} oggetti'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Add Spanish translations
|
|
60
|
+
dphelper.i18n.addTranslations('es', {
|
|
61
|
+
'hello': '¡Hola {name}!',
|
|
62
|
+
'goodbye': '¡Adiós!',
|
|
63
|
+
'welcome': '¡Bienvenido a nuestra aplicación!'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Use translations
|
|
67
|
+
dphelper.i18n.setLocale('es');
|
|
68
|
+
console.log(dphelper.i18n.t('welcome')); // "¡Bienvenido a nuestra aplicación!"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Pluralization
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
dphelper.i18n.setLocale('en');
|
|
75
|
+
|
|
76
|
+
// Basic pluralization
|
|
77
|
+
console.log(dphelper.i18n.pluralize(0, { one: 'item', other: 'items' }));
|
|
78
|
+
// "items" (uses 'other' for 0 in English)
|
|
79
|
+
|
|
80
|
+
console.log(dphelper.i18n.pluralize(1, { one: 'item', other: 'items' }));
|
|
81
|
+
// "item"
|
|
82
|
+
|
|
83
|
+
console.log(dphelper.i18n.pluralize(5, { one: 'item', other: 'items' }));
|
|
84
|
+
// "items"
|
|
85
|
+
|
|
86
|
+
// With translation keys
|
|
87
|
+
dphelper.i18n.addTranslations('en', {
|
|
88
|
+
'items': '{count} item',
|
|
89
|
+
'items_plural': '{count} items'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// In a message
|
|
93
|
+
const count = 10;
|
|
94
|
+
const message = count === 1
|
|
95
|
+
? dphelper.i18n.t('items', { count })
|
|
96
|
+
: dphelper.i18n.t('items_plural', { count });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Number Formatting
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
dphelper.i18n.setLocale('en-US');
|
|
103
|
+
|
|
104
|
+
// Basic number formatting
|
|
105
|
+
console.log(dphelper.i18n.number(1234.56)); // "1,234.56"
|
|
106
|
+
|
|
107
|
+
// Currency
|
|
108
|
+
console.log(dphelper.i18n.number(1234.56, 'en-US', {
|
|
109
|
+
style: 'currency',
|
|
110
|
+
currency: 'USD'
|
|
111
|
+
})); // "$1,234.56"
|
|
112
|
+
|
|
113
|
+
console.log(dphelper.i18n.number(1234.56, 'de-DE', {
|
|
114
|
+
style: 'currency',
|
|
115
|
+
currency: 'EUR'
|
|
116
|
+
})); // "1.234,56 €"
|
|
117
|
+
|
|
118
|
+
// Percentages
|
|
119
|
+
console.log(dphelper.i18n.number(0.75, 'en-US', { style: 'percent' })); // "75%"
|
|
120
|
+
|
|
121
|
+
// Different locales
|
|
122
|
+
console.log(dphelper.i18n.number(1234.56, 'ja-JP')); // "1,234.56"
|
|
123
|
+
console.log(dphelper.i18n.number(1234.56, 'fr-FR')); // "1 234,56"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Date Formatting
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const date = new Date('2026-03-15T14:30:00Z');
|
|
130
|
+
|
|
131
|
+
// Date only
|
|
132
|
+
console.log(dphelper.i18n.date(date, 'en-US', { dateStyle: 'short' }));
|
|
133
|
+
// "3/15/2026"
|
|
134
|
+
|
|
135
|
+
console.log(dphelper.i18n.date(date, 'en-US', { dateStyle: 'long' }));
|
|
136
|
+
// "March 15, 2026"
|
|
137
|
+
|
|
138
|
+
// Time only
|
|
139
|
+
console.log(dphelper.i18n.date(date, 'en-US', { timeStyle: 'short' }));
|
|
140
|
+
// "2:30 PM"
|
|
141
|
+
|
|
142
|
+
// Full date and time
|
|
143
|
+
console.log(dphelper.i18n.date(date, 'it-IT', {
|
|
144
|
+
dateStyle: 'full',
|
|
145
|
+
timeStyle: 'short' }));
|
|
146
|
+
// "domenica 15 marzo 2026, 14:30"
|
|
147
|
+
|
|
148
|
+
// Custom format
|
|
149
|
+
console.log(dphelper.i18n.date(date, 'en-GB', {
|
|
150
|
+
year: 'numeric',
|
|
151
|
+
month: 'long',
|
|
152
|
+
day: 'numeric'
|
|
153
|
+
})); // "15 March 2026"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Relative Time
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const now = Date.now();
|
|
160
|
+
|
|
161
|
+
// Past
|
|
162
|
+
console.log(dphelper.i18n.relativeTime(now - 60000)); // "1 minute ago"
|
|
163
|
+
console.log(dphelper.i18n.relativeTime(now - 3600000)); // "1 hour ago"
|
|
164
|
+
console.log(dphelper.i18n.relativeTime(now - 86400000)); // "1 day ago"
|
|
165
|
+
|
|
166
|
+
// Future
|
|
167
|
+
console.log(dphelper.i18n.relativeTime(now + 60000)); // "in 1 minute"
|
|
168
|
+
console.log(dphelper.i18n.relativeTime(now + 3600000)); // "in 1 hour"
|
|
169
|
+
|
|
170
|
+
// With locale
|
|
171
|
+
console.log(dphelper.i18n.relativeTime(now - 3600000, 'es')); // "hace 1 hora"
|
|
172
|
+
console.log(dphelper.i18n.relativeTime(now + 3600000, 'es')); // "dentro de 1 hora"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### List Formatting
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
const items = ['Apple', 'Banana', 'Orange'];
|
|
179
|
+
|
|
180
|
+
// Basic list
|
|
181
|
+
console.log(dphelper.i18n.list(items, 'en'));
|
|
182
|
+
// "Apple, Banana, and Orange"
|
|
183
|
+
|
|
184
|
+
console.log(dphelper.i18n.list(items, 'it'));
|
|
185
|
+
// "Apple, Banana e Orange"
|
|
186
|
+
|
|
187
|
+
// With options
|
|
188
|
+
console.log(dphelper.i18n.list(items, 'en', { type: 'disjunction' }));
|
|
189
|
+
// "Apple, Banana, or Orange"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Advanced Usage
|
|
193
|
+
|
|
194
|
+
### Complete i18n Setup
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
// Initialize i18n with custom translations
|
|
198
|
+
function initI18n(locale) {
|
|
199
|
+
// Set locale
|
|
200
|
+
dphelper.i18n.setLocale(locale);
|
|
201
|
+
|
|
202
|
+
// Add translations for common strings
|
|
203
|
+
dphelper.i18n.addTranslations(locale, {
|
|
204
|
+
'app.name': 'My Application',
|
|
205
|
+
'app.tagline': 'Building the future',
|
|
206
|
+
'nav.home': 'Home',
|
|
207
|
+
'nav.about': 'About',
|
|
208
|
+
'nav.contact': 'Contact',
|
|
209
|
+
'common.save': 'Save',
|
|
210
|
+
'common.cancel': 'Cancel',
|
|
211
|
+
'common.delete': 'Delete',
|
|
212
|
+
'common.loading': 'Loading...',
|
|
213
|
+
'error.generic': 'An error occurred',
|
|
214
|
+
'error.network': 'Network error. Please try again.',
|
|
215
|
+
'user.greeting': 'Welcome, {name}!',
|
|
216
|
+
'items.count': '{count, plural, =0{No items} one{# item} other{# items}}'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Usage
|
|
221
|
+
initI18n('en');
|
|
222
|
+
console.log(dphelper.i18n.t('user.greeting', { name: 'John' }));
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Dynamic Locale Switching
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
class I18nManager {
|
|
229
|
+
constructor() {
|
|
230
|
+
this.locale = 'en';
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async setLocale(locale) {
|
|
234
|
+
// Fetch translations from server
|
|
235
|
+
const translations = await fetch(`/api/translations/${locale}`)
|
|
236
|
+
.then(r => r.json());
|
|
237
|
+
|
|
238
|
+
// Add translations
|
|
239
|
+
dphelper.i18n.addTranslations(locale, translations);
|
|
240
|
+
|
|
241
|
+
// Set locale
|
|
242
|
+
dphelper.i18n.setLocale(locale);
|
|
243
|
+
this.locale = locale;
|
|
244
|
+
|
|
245
|
+
// Dispatch event for UI update
|
|
246
|
+
window.dispatchEvent(new CustomEvent('localechange', { detail: { locale } }));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
t(key, vars) {
|
|
250
|
+
return dphelper.i18n.t(key, vars);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
formatNumber(value, options) {
|
|
254
|
+
return dphelper.i18n.number(value, this.locale, options);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
formatDate(date, options) {
|
|
258
|
+
return dphelper.i18n.date(date, this.locale, options);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const i18n = new I18nManager();
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### React-like Translation Component
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
// Simple translation helper for templates
|
|
269
|
+
function tr(key, vars) {
|
|
270
|
+
return dphelper.i18n.t(key, vars);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Usage in templates
|
|
274
|
+
const template = `
|
|
275
|
+
<h1>${tr('app.name')}</h1>
|
|
276
|
+
<p>${tr('user.greeting', { name: userName })}</p>
|
|
277
|
+
<p>${tr('items.count', { count: itemCount })}</p>
|
|
278
|
+
<p>${tr('common.lastUpdated', { date: dphelper.i18n.date(lastUpdate) })}</p>
|
|
279
|
+
`;
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Details
|
|
283
|
+
|
|
284
|
+
- **Author:** Dario Passariello
|
|
285
|
+
- **Version:** 0.0.1
|
|
286
|
+
- **Creation Date:** 20260313
|
|
287
|
+
- **Last Modified:** 20260313
|
|
288
|
+
- **Environment:** Works in both client and server environments
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# image
|
|
2
|
+
|
|
3
|
+
Comprehensive image processing utilities for client-side image manipulation, including resize, crop, rotate, flip, filters, and format conversion.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `resize` | Resize image to dimensions | `dphelper.image.resize(img, 100, 100)` |
|
|
10
|
+
| `crop` | Crop image to region | `dphelper.image.crop(img, { x: 0, y: 0, width: 100, height: 100 })` |
|
|
11
|
+
| `toDataURL` | Convert to data URL | `dphelper.image.toDataURL(img, 'image/webp', 0.8)` |
|
|
12
|
+
| `fromDataURL` | Create image from data URL | `dphelper.image.fromDataURL(dataUrl)` |
|
|
13
|
+
| `filter` | Apply CSS filters | `dphelper.image.filter(img, { brightness: 1.2, contrast: 1.1 })` |
|
|
14
|
+
| `rotate` | Rotate image by degrees | `dphelper.image.rotate(img, 90)` |
|
|
15
|
+
| `flip` | Flip horizontally/vertically | `dphelper.image.flip(img, 'horizontal')` |
|
|
16
|
+
| `grayscale` | Convert to grayscale | `dphelper.image.grayscale(img)` |
|
|
17
|
+
| `blur` | Apply blur effect | `dphelper.image.blur(img, 5)` |
|
|
18
|
+
| `getDimensions` | Get image dimensions | `dphelper.image.getDimensions(img)` |
|
|
19
|
+
| `load` | Load image from URL | `dphelper.image.load('image.jpg')` |
|
|
20
|
+
| `composite` | Composite two images | `dphelper.image.composite(img1, img2, 'multiply')` |
|
|
21
|
+
|
|
22
|
+
## Description
|
|
23
|
+
|
|
24
|
+
Powerful client-side image processing module providing:
|
|
25
|
+
- **Resize & Crop** - Precise dimension control with quality options
|
|
26
|
+
- **Rotation & Flipping** - Rotate by degrees, flip horizontally or vertically
|
|
27
|
+
- **Filters** - Brightness, contrast, saturation, hue, blur, sepia, and more
|
|
28
|
+
- **Format Conversion** - Convert between PNG, JPEG, WebP with quality control
|
|
29
|
+
- **Compositing** - Blend multiple images with different blend modes
|
|
30
|
+
- **Canvas-based** - All operations use HTML5 Canvas for performance
|
|
31
|
+
|
|
32
|
+
## Usage Examples
|
|
33
|
+
|
|
34
|
+
### Loading Images
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Load image from URL
|
|
38
|
+
const img = await dphelper.image.load('photo.jpg');
|
|
39
|
+
console.log(dphelper.image.getDimensions(img));
|
|
40
|
+
// { width: 1920, height: 1080 }
|
|
41
|
+
|
|
42
|
+
// Load from different source
|
|
43
|
+
const img2 = await dphelper.image.load('https://example.com/image.png');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Resize & Crop
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const img = await dphelper.image.load('photo.jpg');
|
|
50
|
+
|
|
51
|
+
// Resize to specific dimensions
|
|
52
|
+
const thumb = dphelper.image.resize(img, 150, 150);
|
|
53
|
+
document.getElementById('thumbnail').src = thumb;
|
|
54
|
+
|
|
55
|
+
// Resize with pixelated (nearest neighbor) quality
|
|
56
|
+
const pixelArt = dphelper.image.resize(img, 32, 32, 'pixelated');
|
|
57
|
+
document.getElementById('sprite').src = pixelArt;
|
|
58
|
+
|
|
59
|
+
// Crop to region
|
|
60
|
+
const cropped = dphelper.image.crop(img, {
|
|
61
|
+
x: 100,
|
|
62
|
+
y: 100,
|
|
63
|
+
width: 200,
|
|
64
|
+
height: 200
|
|
65
|
+
});
|
|
66
|
+
document.getElementById('cropped').src = cropped;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Rotation & Flipping
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const img = await dphelper.image.load('photo.jpg');
|
|
73
|
+
|
|
74
|
+
// Rotate 90 degrees clockwise
|
|
75
|
+
const rotated90 = dphelper.image.rotate(img, 90);
|
|
76
|
+
document.getElementById('rotated').src = rotated90;
|
|
77
|
+
|
|
78
|
+
// Rotate 45 degrees
|
|
79
|
+
const rotated45 = dphelper.image.rotate(img, 45);
|
|
80
|
+
|
|
81
|
+
// Flip horizontally
|
|
82
|
+
const flippedH = dphelper.image.flip(img, 'horizontal');
|
|
83
|
+
|
|
84
|
+
// Flip vertically
|
|
85
|
+
const flippedV = dphelper.image.flip(img, 'vertical');
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Applying Filters
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const img = await dphelper.image.load('photo.jpg');
|
|
92
|
+
|
|
93
|
+
// Brightness adjustment (1 = normal, 0.5 = darker, 1.5 = brighter)
|
|
94
|
+
const brightened = dphelper.image.filter(img, { brightness: 1.3 });
|
|
95
|
+
|
|
96
|
+
// Contrast adjustment
|
|
97
|
+
const contrasted = dphelper.image.filter(img, { contrast: 1.2 });
|
|
98
|
+
|
|
99
|
+
// Saturation
|
|
100
|
+
const saturated = dphelper.image.filter(img, { saturate: 1.5 });
|
|
101
|
+
const desaturated = dphelper.image.filter(img, { saturate: 0.3 });
|
|
102
|
+
|
|
103
|
+
// Hue rotation (degrees)
|
|
104
|
+
const hueShifted = dphelper.image.filter(img, { hueRotate: 90 });
|
|
105
|
+
|
|
106
|
+
// Blur (pixels)
|
|
107
|
+
const blurred = dphelper.image.filter(img, { blur: 5 });
|
|
108
|
+
|
|
109
|
+
// Sepia effect
|
|
110
|
+
const sepia = dphelper.image.filter(img, { sepia: 1 });
|
|
111
|
+
|
|
112
|
+
// Invert colors
|
|
113
|
+
const inverted = dphelper.image.filter(img, { invert: 1 });
|
|
114
|
+
|
|
115
|
+
// Grayscale
|
|
116
|
+
const gray = dphelper.image.filter(img, { grayscale: 1 });
|
|
117
|
+
|
|
118
|
+
// Combined filters
|
|
119
|
+
const vintage = dphelper.image.filter(img, {
|
|
120
|
+
brightness: 1.1,
|
|
121
|
+
contrast: 1.2,
|
|
122
|
+
sepia: 0.3
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Format Conversion
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const img = await dphelper.image.load('photo.png');
|
|
130
|
+
|
|
131
|
+
// Convert to JPEG with quality
|
|
132
|
+
const jpeg80 = dphelper.image.toDataURL(img, 'image/jpeg', 0.8);
|
|
133
|
+
const jpeg50 = dphelper.image.toDataURL(img, 'image/jpeg', 0.5);
|
|
134
|
+
|
|
135
|
+
// Convert to WebP (better compression)
|
|
136
|
+
const webp = dphelper.image.toDataURL(img, 'image/webp', 0.9);
|
|
137
|
+
|
|
138
|
+
// Keep as PNG (lossless)
|
|
139
|
+
const png = dphelper.image.toDataURL(img, 'image/png', 1);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Image Compositing
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const img1 = await dphelper.image.load('background.jpg');
|
|
146
|
+
const img2 = await dphelper.image.load('overlay.png');
|
|
147
|
+
|
|
148
|
+
// Overlay with normal blending
|
|
149
|
+
const normal = dphelper.image.composite(img1, img2, 'source-over', 0, 0);
|
|
150
|
+
|
|
151
|
+
// Multiply blend (for shadows/overlays)
|
|
152
|
+
const multiplied = dphelper.image.composite(img1, img2, 'multiply', 50, 50);
|
|
153
|
+
|
|
154
|
+
// Screen blend (for light effects)
|
|
155
|
+
const screened = dphelper.image.composite(img1, img2, 'screen', 0, 0);
|
|
156
|
+
|
|
157
|
+
// Overlay blend
|
|
158
|
+
const overlaid = dphelper.image.composite(img1, img2, 'overlay', 0, 0);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Advanced Usage
|
|
162
|
+
|
|
163
|
+
### Thumbnail Generator
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
async function generateThumbnail(file, maxSize = 150) {
|
|
167
|
+
// Load the uploaded file
|
|
168
|
+
const dataUrl = await readFileAsDataURL(file);
|
|
169
|
+
const img = await dphelper.image.fromDataURL(dataUrl);
|
|
170
|
+
|
|
171
|
+
// Get original dimensions
|
|
172
|
+
const { width, height } = dphelper.image.getDimensions(img);
|
|
173
|
+
|
|
174
|
+
// Calculate new dimensions (maintain aspect ratio)
|
|
175
|
+
let newWidth, newHeight;
|
|
176
|
+
if (width > height) {
|
|
177
|
+
newWidth = maxSize;
|
|
178
|
+
newHeight = (height / width) * maxSize;
|
|
179
|
+
} else {
|
|
180
|
+
newHeight = maxSize;
|
|
181
|
+
newWidth = (width / height) * maxSize;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Resize and convert to JPEG
|
|
185
|
+
const thumbnail = dphelper.image.resize(img, newWidth, newHeight);
|
|
186
|
+
return dphelper.image.toDataURL(thumbnail, 'image/jpeg', 0.8);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Helper to read file as data URL
|
|
190
|
+
function readFileAsDataURL(file) {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
const reader = new FileReader();
|
|
193
|
+
reader.onload = () => resolve(reader.result);
|
|
194
|
+
reader.onerror = reject;
|
|
195
|
+
reader.readAsDataURL(file);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Usage
|
|
200
|
+
document.querySelector('input[type="file"]').addEventListener('change', async (e) => {
|
|
201
|
+
const thumbnail = await generateThumbnail(e.target.files[0]);
|
|
202
|
+
document.getElementById('preview').src = thumbnail;
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Image Editor
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
class ImageEditor {
|
|
210
|
+
constructor(imageElement) {
|
|
211
|
+
this.img = imageElement;
|
|
212
|
+
this.history = [];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async applyFilter(options) {
|
|
216
|
+
const result = dphelper.image.filter(this.img, options);
|
|
217
|
+
this.history.push(result);
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async resize(width, height) {
|
|
222
|
+
const result = dphelper.image.resize(this.img, width, height);
|
|
223
|
+
this.history.push(result);
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async rotate(degrees) {
|
|
228
|
+
const result = dphelper.image.rotate(this.img, degrees);
|
|
229
|
+
this.history.push(result);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async crop(region) {
|
|
234
|
+
const result = dphelper.image.crop(this.img, region);
|
|
235
|
+
this.history.push(result);
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async undo() {
|
|
240
|
+
if (this.history.length > 0) {
|
|
241
|
+
const prev = this.history.pop();
|
|
242
|
+
this.img = await dphelper.image.fromDataURL(prev);
|
|
243
|
+
}
|
|
244
|
+
return this.img;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async export(format = 'image/png', quality = 0.92) {
|
|
248
|
+
return dphelper.image.toDataURL(this.img, format, quality);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Usage
|
|
253
|
+
const editor = new ImageEditor(document.getElementById('original'));
|
|
254
|
+
const filtered = await editor.applyFilter({ brightness: 1.2, contrast: 1.1 });
|
|
255
|
+
document.getElementById('result').src = filtered;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Profile Picture Processor
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
async function processProfilePicture(file) {
|
|
262
|
+
const dataUrl = await readFileAsDataURL(file);
|
|
263
|
+
const img = await dphelper.image.fromDataURL(dataUrl);
|
|
264
|
+
|
|
265
|
+
// Get dimensions
|
|
266
|
+
const { width, height } = dphelper.image.getDimensions(img);
|
|
267
|
+
|
|
268
|
+
// Calculate square crop (center)
|
|
269
|
+
const size = Math.min(width, height);
|
|
270
|
+
const x = (width - size) / 2;
|
|
271
|
+
const y = (height - size) / 2;
|
|
272
|
+
|
|
273
|
+
// Crop to square
|
|
274
|
+
const cropped = dphelper.image.crop(img, { x, y, width: size, height: size });
|
|
275
|
+
|
|
276
|
+
// Resize to standard profile size
|
|
277
|
+
const resized = dphelper.image.resize(
|
|
278
|
+
await dphelper.image.fromDataURL(cropped),
|
|
279
|
+
200,
|
|
280
|
+
200
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Convert to JPEG with good quality
|
|
284
|
+
return dphelper.image.toDataURL(resized, 'image/jpeg', 0.9);
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Details
|
|
289
|
+
|
|
290
|
+
- **Author:** Dario Passariello
|
|
291
|
+
- **Version:** 0.0.1
|
|
292
|
+
- **Creation Date:** 20260313
|
|
293
|
+
- **Last Modified:** 20260313
|
|
294
|
+
- **Environment:** Client-side only (browser)
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
*Automatically generated document*
|