@fullstackunicorn/websites 1.0.10 → 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 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
- TS: 64,
7
- TM: 256,
8
- TL: 512,
9
- SD: 960,
10
- MD: 1440,
11
- HD: 1920
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) => {
@@ -30,12 +34,13 @@ class Images {
30
34
  const pathParsed = path.posix.parse(file.path)
31
35
 
32
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 = path.posix.join(folder, picture.dir, 'TS', `${picture.name}${picture.ext}`)
43
+ picture.src = path.posix.join(folder, picture.dir, 'S1', `${picture.name}.webp`)
39
44
 
40
45
  picture.pathJson = path.posix.join(picture.dir, `${picture.name}.json`)
41
46
  picture.pathImg = path.posix.join(picture.dir, `${picture.name}${picture.ext}`)
@@ -44,7 +49,7 @@ class Images {
44
49
  }
45
50
 
46
51
  getPathThumbnail = ({ picture, entry }) => {
47
- return path.posix.join(picture.dir, entry[0], `${picture.name}${picture.ext}`)
52
+ return path.posix.join(picture.dir, entry[0], `${picture.name}.webp`)
48
53
  }
49
54
 
50
55
  getPictureData = async ({ picture }) => {
@@ -55,13 +60,15 @@ class Images {
55
60
 
56
61
  const pictureData = {}
57
62
  pictureData.original = picture.original
58
- pictureData.name = `${picture.name}${picture.ext}`
63
+ pictureData.name = `${picture.name}.webp`
59
64
  pictureData.x = size.width
60
65
  pictureData.y = size.height
61
66
  pictureData.placeholder = await this.getBlurhash({ picture })
62
67
  pictureData.src = picture.src
63
68
  pictureData.ratio = size.width / size.height
64
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))
65
72
 
66
73
  return pictureData
67
74
  }
@@ -79,7 +86,7 @@ class Images {
79
86
 
80
87
  getMaxSize = ({ size }) => {
81
88
  const sortedSizes = Object.entries(this.widths).sort(([, a], [, b]) => a - b)
82
- let maxSize = sortedSizes[0][0]
89
+ let maxSize = null
83
90
  for (const [key, value] of sortedSizes) {
84
91
  if (size.width >= value) maxSize = key
85
92
  else break
@@ -88,11 +95,10 @@ class Images {
88
95
  }
89
96
 
90
97
  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
98
+ return picture.base.clone()
99
+ .resize({ width: entry[1], withoutEnlargement: true })
100
+ .webp({ lossless: true, effort: 4 })
101
+ .toBuffer()
96
102
  }
97
103
 
98
104
  generate = async ({ file, folder }) => {
@@ -109,12 +115,18 @@ class Images {
109
115
  })
110
116
 
111
117
  // original
112
- const originalBuffer = await picture.base.clone().toBuffer()
118
+ const originalBuffer = Buffer.from(file.buffer)
113
119
  this.appendFile(result, 'original', {
114
120
  path: picture.pathImg,
115
121
  file: originalBuffer
116
122
  })
117
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
+
118
130
  const created = []
119
131
  for (const entry of Object.entries(this.widths)) {
120
132
 
@@ -126,7 +138,7 @@ class Images {
126
138
  const thumbPath = this.getPathThumbnail({ picture, entry })
127
139
 
128
140
  let buffer
129
- if (pictureData.x === w) buffer = originalBuffer
141
+ if (pictureData.x === w) buffer = fullBuffer
130
142
  else buffer = await this.getBuffer({ picture, entry })
131
143
 
132
144
  this.appendFile(result, key, { path: thumbPath, file: buffer })
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
- "version": "1.0.10",
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.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: `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.