@fullstackunicorn/websites 1.0.8 → 2.0.0
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/modules/images.js +34 -23
- package/package.json +5 -4
- package/package.md +24 -0
package/modules/images.js
CHANGED
|
@@ -2,13 +2,17 @@ import { path, sharp, blurhash } from '#@/index.dep.js'
|
|
|
2
2
|
|
|
3
3
|
class Images {
|
|
4
4
|
extensions = ['.jpg', '.png']
|
|
5
|
+
recipe = 'webp-lossless-sml-v1'
|
|
5
6
|
widths = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
S1: 64,
|
|
8
|
+
S2: 128,
|
|
9
|
+
S3: 256,
|
|
10
|
+
M1: 320,
|
|
11
|
+
M2: 640,
|
|
12
|
+
M3: 960,
|
|
13
|
+
L1: 1280,
|
|
14
|
+
L2: 1920,
|
|
15
|
+
L3: 2560
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
appendFile = (obj, name, data) => {
|
|
@@ -27,25 +31,25 @@ class Images {
|
|
|
27
31
|
getPicture = async ({ file, folder }) => {
|
|
28
32
|
|
|
29
33
|
const picture = {}
|
|
30
|
-
const pathParsed = path.parse(file.path)
|
|
34
|
+
const pathParsed = path.posix.parse(file.path)
|
|
31
35
|
|
|
32
|
-
picture.dir = pathParsed.dir
|
|
36
|
+
picture.dir = pathParsed.dir || ''
|
|
37
|
+
picture.folder = folder
|
|
33
38
|
|
|
34
39
|
picture.original = pathParsed.base
|
|
35
40
|
picture.ext = this.getExtension(pathParsed)
|
|
36
41
|
picture.base = sharp(file.buffer)
|
|
37
42
|
picture.name = pathParsed.name
|
|
38
|
-
picture.src =
|
|
43
|
+
picture.src = path.posix.join(folder, picture.dir, 'S1', `${picture.name}.webp`)
|
|
39
44
|
|
|
40
|
-
picture.pathJson =
|
|
41
|
-
picture.pathImg =
|
|
45
|
+
picture.pathJson = path.posix.join(picture.dir, `${picture.name}.json`)
|
|
46
|
+
picture.pathImg = path.posix.join(picture.dir, `${picture.name}${picture.ext}`)
|
|
42
47
|
|
|
43
48
|
return picture
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
getPathThumbnail = ({ picture, entry }) => {
|
|
47
|
-
|
|
48
|
-
return relPath
|
|
52
|
+
return path.posix.join(picture.dir, entry[0], `${picture.name}.webp`)
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
getPictureData = async ({ picture }) => {
|
|
@@ -56,13 +60,15 @@ class Images {
|
|
|
56
60
|
|
|
57
61
|
const pictureData = {}
|
|
58
62
|
pictureData.original = picture.original
|
|
59
|
-
pictureData.name = `${picture.name}
|
|
63
|
+
pictureData.name = `${picture.name}.webp`
|
|
60
64
|
pictureData.x = size.width
|
|
61
65
|
pictureData.y = size.height
|
|
62
66
|
pictureData.placeholder = await this.getBlurhash({ picture })
|
|
63
67
|
pictureData.src = picture.src
|
|
64
68
|
pictureData.ratio = size.width / size.height
|
|
65
69
|
pictureData.max = this.getMaxSize({ size })
|
|
70
|
+
pictureData.full = path.posix.join(picture.folder, picture.dir, `${picture.name}.webp`)
|
|
71
|
+
pictureData.widths = Object.fromEntries(Object.entries(this.widths).filter(([, width]) => width <= size.width))
|
|
66
72
|
|
|
67
73
|
return pictureData
|
|
68
74
|
}
|
|
@@ -80,7 +86,7 @@ class Images {
|
|
|
80
86
|
|
|
81
87
|
getMaxSize = ({ size }) => {
|
|
82
88
|
const sortedSizes = Object.entries(this.widths).sort(([, a], [, b]) => a - b)
|
|
83
|
-
let maxSize =
|
|
89
|
+
let maxSize = null
|
|
84
90
|
for (const [key, value] of sortedSizes) {
|
|
85
91
|
if (size.width >= value) maxSize = key
|
|
86
92
|
else break
|
|
@@ -89,15 +95,14 @@ class Images {
|
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
getBuffer = async ({ picture, entry }) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return buffer
|
|
98
|
+
return picture.base.clone()
|
|
99
|
+
.resize({ width: entry[1], withoutEnlargement: true })
|
|
100
|
+
.webp({ lossless: true, effort: 4 })
|
|
101
|
+
.toBuffer()
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
generate = async ({ file, folder }) => {
|
|
100
|
-
|
|
105
|
+
|
|
101
106
|
const picture = await this.getPicture({ file, folder })
|
|
102
107
|
const pictureData = await this.getPictureData({ picture })
|
|
103
108
|
|
|
@@ -110,12 +115,18 @@ class Images {
|
|
|
110
115
|
})
|
|
111
116
|
|
|
112
117
|
// original
|
|
113
|
-
const originalBuffer =
|
|
118
|
+
const originalBuffer = Buffer.from(file.buffer)
|
|
114
119
|
this.appendFile(result, 'original', {
|
|
115
120
|
path: picture.pathImg,
|
|
116
121
|
file: originalBuffer
|
|
117
122
|
})
|
|
118
123
|
|
|
124
|
+
const fullBuffer = await picture.base.clone().webp({ lossless: true, effort: 4 }).toBuffer()
|
|
125
|
+
this.appendFile(result, 'full', {
|
|
126
|
+
path: path.posix.join(picture.dir, `${picture.name}.webp`),
|
|
127
|
+
file: fullBuffer
|
|
128
|
+
})
|
|
129
|
+
|
|
119
130
|
const created = []
|
|
120
131
|
for (const entry of Object.entries(this.widths)) {
|
|
121
132
|
|
|
@@ -127,7 +138,7 @@ class Images {
|
|
|
127
138
|
const thumbPath = this.getPathThumbnail({ picture, entry })
|
|
128
139
|
|
|
129
140
|
let buffer
|
|
130
|
-
if (pictureData.x === w) buffer =
|
|
141
|
+
if (pictureData.x === w) buffer = fullBuffer
|
|
131
142
|
else buffer = await this.getBuffer({ picture, entry })
|
|
132
143
|
|
|
133
144
|
this.appendFile(result, key, { path: thumbPath, file: buffer })
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "2.0.0",
|
|
3
3
|
"name": "@fullstackunicorn/websites",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "A development utility for generating icons, favicons, thumbnails and all what is needed for websites",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"private": false,
|
|
9
|
-
"readme": "package.
|
|
9
|
+
"readme": "package.md",
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"files": [
|
|
12
12
|
"index.js",
|
|
13
13
|
"index.dep.js",
|
|
14
|
-
"modules/"
|
|
14
|
+
"modules/",
|
|
15
|
+
"package.md"
|
|
15
16
|
],
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
33
|
"cmd": "chmod +x ./config.cmd.sh && ./config.cmd.sh",
|
|
33
|
-
"test": "
|
|
34
|
+
"test": "node --test tests/*.test.js"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@fullstackunicorn/filesystem": "^1.0.4",
|
package/package.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @fullstackunicorn/websites
|
|
2
|
+
|
|
3
|
+
Versione sorgente: `1.0.10`. Installazione: `npm install @fullstackunicorn/websites` (registro/permessi del pacchetto richiesti).
|
|
4
|
+
|
|
5
|
+
Utility Node per generare immagini e icone con sharp.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
```js
|
|
9
|
+
import { websites } from '@fullstackunicorn/websites'
|
|
10
|
+
```
|
|
11
|
+
| Metodo | Input → risultato |
|
|
12
|
+
|---|---|
|
|
13
|
+
| websites.icons.generate({ favicon, icon }) | Oggetti con name/buffer PNG o SVG → mappa di file generati |
|
|
14
|
+
| websites.images.getPicture({ file, folder }) | file.path/file.buffer e destinazione → elaborazione immagine e metadati |
|
|
15
|
+
|
|
16
|
+
## Formati
|
|
17
|
+
Icone: favicon 32, icone 180/192/512. Immagini: jpg/jpeg/png; larghezze S1 64, S2 128, S3 256, M1 320, M2 640, M3 960, L1 1280, L2 1920, L3 2560. Estensione non supportata: errore. Helper interni non sono un contratto stabile separato.
|
|
18
|
+
|
|
19
|
+
## Requisiti e limiti
|
|
20
|
+
Node con dipendenze native sharp; non importare nel bundle browser. L’entrypoint carica initialize e modifica F3.service nel codice legacy. Verificare file reali e output prima di adozione; nessun nuovo collaudo implicito in questa documentazione.
|
|
21
|
+
|
|
22
|
+
## Images 2.0
|
|
23
|
+
|
|
24
|
+
Original bytes are preserved. Full-resolution and resized display files use lossless WebP, preserving alpha. Each derivative is resized from the source with Sharp (no enlargement). Metadata contains `src` with `/S1/` as a reference template, `full` for the full-resolution WebP, `widths` for available variants, `x`, `y`, `ratio`, `max` (null below 64px), and `placeholder`. Resolve the selected variant before issuing a request. `S1` is not an intermediate download. The image recipe identifier versions processing caches.
|