@fullstackunicorn/websites 1.0.10 → 2.1.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 CHANGED
@@ -2,13 +2,21 @@ 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'
6
+ sizesVersion = 1
5
7
  widths = {
6
- TS: 64,
7
- TM: 256,
8
- TL: 512,
9
- SD: 960,
10
- MD: 1440,
11
- HD: 1920
8
+ S1: 64,
9
+ S2: 128,
10
+ S3: 256,
11
+ M1: 320,
12
+ M2: 400,
13
+ M3: 480,
14
+ M4: 640,
15
+ M5: 800,
16
+ M6: 960,
17
+ L1: 1280,
18
+ L2: 1920,
19
+ L3: 2560
12
20
  }
13
21
 
14
22
  appendFile = (obj, name, data) => {
@@ -30,12 +38,13 @@ class Images {
30
38
  const pathParsed = path.posix.parse(file.path)
31
39
 
32
40
  picture.dir = pathParsed.dir || ''
41
+ picture.folder = folder
33
42
 
34
43
  picture.original = pathParsed.base
35
44
  picture.ext = this.getExtension(pathParsed)
36
45
  picture.base = sharp(file.buffer)
37
46
  picture.name = pathParsed.name
38
- picture.src = path.posix.join(folder, picture.dir, 'TS', `${picture.name}${picture.ext}`)
47
+ picture.src = path.posix.join(folder, picture.dir, 'S1', `${picture.name}.webp`)
39
48
 
40
49
  picture.pathJson = path.posix.join(picture.dir, `${picture.name}.json`)
41
50
  picture.pathImg = path.posix.join(picture.dir, `${picture.name}${picture.ext}`)
@@ -44,7 +53,7 @@ class Images {
44
53
  }
45
54
 
46
55
  getPathThumbnail = ({ picture, entry }) => {
47
- return path.posix.join(picture.dir, entry[0], `${picture.name}${picture.ext}`)
56
+ return path.posix.join(picture.dir, entry[0], `${picture.name}.webp`)
48
57
  }
49
58
 
50
59
  getPictureData = async ({ picture }) => {
@@ -55,13 +64,16 @@ class Images {
55
64
 
56
65
  const pictureData = {}
57
66
  pictureData.original = picture.original
58
- pictureData.name = `${picture.name}${picture.ext}`
67
+ pictureData.name = `${picture.name}.webp`
59
68
  pictureData.x = size.width
60
69
  pictureData.y = size.height
61
70
  pictureData.placeholder = await this.getBlurhash({ picture })
62
71
  pictureData.src = picture.src
63
72
  pictureData.ratio = size.width / size.height
64
73
  pictureData.max = this.getMaxSize({ size })
74
+ pictureData.sizesVersion = this.sizesVersion
75
+ pictureData.full = path.posix.join(picture.folder, picture.dir, `${picture.name}.webp`)
76
+ pictureData.widths = Object.fromEntries(Object.entries(this.widths).filter(([, width]) => width <= size.width))
65
77
 
66
78
  return pictureData
67
79
  }
@@ -79,7 +91,7 @@ class Images {
79
91
 
80
92
  getMaxSize = ({ size }) => {
81
93
  const sortedSizes = Object.entries(this.widths).sort(([, a], [, b]) => a - b)
82
- let maxSize = sortedSizes[0][0]
94
+ let maxSize = null
83
95
  for (const [key, value] of sortedSizes) {
84
96
  if (size.width >= value) maxSize = key
85
97
  else break
@@ -88,11 +100,10 @@ class Images {
88
100
  }
89
101
 
90
102
  getBuffer = async ({ picture, entry }) => {
91
- const image = picture.base.clone().resize({ width: entry[1] })
92
- if (picture.ext === '.png') image.png({ compressionLevel: 9, progressive: true })
93
- else image.jpeg({ quality: 75, progressive: true })
94
- const buffer = await image.toBuffer()
95
- return buffer
103
+ return picture.base.clone()
104
+ .resize({ width: entry[1], withoutEnlargement: true })
105
+ .webp({ lossless: true, effort: 4 })
106
+ .toBuffer()
96
107
  }
97
108
 
98
109
  generate = async ({ file, folder }) => {
@@ -109,12 +120,18 @@ class Images {
109
120
  })
110
121
 
111
122
  // original
112
- const originalBuffer = await picture.base.clone().toBuffer()
123
+ const originalBuffer = Buffer.from(file.buffer)
113
124
  this.appendFile(result, 'original', {
114
125
  path: picture.pathImg,
115
126
  file: originalBuffer
116
127
  })
117
128
 
129
+ const fullBuffer = await picture.base.clone().webp({ lossless: true, effort: 4 }).toBuffer()
130
+ this.appendFile(result, 'full', {
131
+ path: path.posix.join(picture.dir, `${picture.name}.webp`),
132
+ file: fullBuffer
133
+ })
134
+
118
135
  const created = []
119
136
  for (const entry of Object.entries(this.widths)) {
120
137
 
@@ -126,7 +143,7 @@ class Images {
126
143
  const thumbPath = this.getPathThumbnail({ picture, entry })
127
144
 
128
145
  let buffer
129
- if (pictureData.x === w) buffer = originalBuffer
146
+ if (pictureData.x === w) buffer = fullBuffer
130
147
  else buffer = await this.getBuffer({ picture, entry })
131
148
 
132
149
  this.appendFile(result, key, { path: thumbPath, file: buffer })
@@ -139,4 +156,4 @@ class Images {
139
156
  }
140
157
  }
141
158
 
142
- export const images = new Images()
159
+ export const images = new Images()
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
- "version": "1.0.10",
2
+ "version": "2.1.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.readme.md",
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": "exit 1"
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: `2.1.0`. 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; media sizes version 1 con larghezze S1 64, S2 128, S3 256, M1 320, M2 400, M3 480, M4 640, M5 800, M6 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 `sizesVersion: 1`, `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 and the sizes version together identify processing caches.