@fullstackunicorn/websites 3.0.0 → 4.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/covers.js CHANGED
@@ -2,29 +2,34 @@ import { sharp } from '#@/index.dep.js'
2
2
 
3
3
  class Covers {
4
4
 
5
+ recipe = 'social-1200x630-webp-q85-e4-v1'
5
6
  width = 1200
6
7
  height = 630
7
8
 
8
- generate = async ({ trademark, background = '#ffffff' }) => {
9
+ generate = async ({ trademark, background = '#ffffff', format = 'jpeg' }) => {
9
10
  if (!trademark) throw new Error('cover_trademark_missing')
11
+ if (!['jpeg', 'webp'].includes(format)) throw new Error('cover_format_invalid')
10
12
  const source = Buffer.isBuffer(trademark) ? trademark : Buffer.from(await trademark.arrayBuffer())
11
13
  const mark = await sharp(source)
12
14
  .resize(720, 180, { fit: 'inside', withoutEnlargement: true })
13
15
  .png()
14
16
  .toBuffer()
15
- return await sharp({ create: { width: this.width, height: this.height, channels: 3, background } })
17
+ const output = sharp({ create: { width: this.width, height: this.height, channels: 3, background } })
16
18
  .composite([{ input: mark, gravity: 'centre' }])
17
- .jpeg({ quality: 90, chromaSubsampling: '4:4:4' })
18
- .toBuffer()
19
+ return await (format === 'webp'
20
+ ? output.webp({ quality: 85, effort: 4, smartSubsample: true })
21
+ : output.jpeg({ quality: 90, chromaSubsampling: '4:4:4' })).toBuffer()
19
22
  }
20
23
 
21
- fromImage = async ({ image }) => {
24
+ fromImage = async ({ image, format = 'jpeg' }) => {
22
25
  if (!image) throw new Error('cover_image_missing')
26
+ if (!['jpeg', 'webp'].includes(format)) throw new Error('cover_format_invalid')
23
27
  const source = Buffer.isBuffer(image) ? image : Buffer.from(await image.arrayBuffer())
24
- return await sharp(source)
28
+ const output = sharp(source)
25
29
  .resize(this.width, this.height, { fit: 'cover', position: 'attention' })
26
- .jpeg({ quality: 90, chromaSubsampling: '4:4:4' })
27
- .toBuffer()
30
+ return await (format === 'webp'
31
+ ? output.webp({ quality: 85, effort: 4, smartSubsample: true })
32
+ : output.jpeg({ quality: 90, chromaSubsampling: '4:4:4' })).toBuffer()
28
33
  }
29
34
  }
30
35
 
package/modules/images.js CHANGED
@@ -3,8 +3,8 @@ import { path, sharp, blurhash } from '#@/index.dep.js'
3
3
 
4
4
  class Images {
5
5
  extensions = ['.jpg', '.png']
6
- recipe = 'webp-lossless-responsive-v2'
7
- sizesVersion = 2
6
+ recipe = 'webp-q85-e4-smart-original-lossless-v3'
7
+ sizesVersion = 3
8
8
  minimumWidth = 40
9
9
  widths = {
10
10
  S40: 40,
@@ -92,7 +92,7 @@ class Images {
92
92
  if (entry[0] === 'OO') return picture.base.clone().webp({ lossless: true, effort: 4 }).toBuffer()
93
93
  return picture.base.clone()
94
94
  .resize({ width: entry[1], withoutEnlargement: true })
95
- .webp({ lossless: true, effort: 4 })
95
+ .webp({ lossless: false, quality: 85, effort: 4, smartSubsample: true })
96
96
  .toBuffer()
97
97
  }
98
98
 
@@ -110,7 +110,11 @@ class Images {
110
110
  generate = async ({ file, folder, sizes }) => {
111
111
  const picture = await this.getPicture({ file, folder })
112
112
  const pictureData = await this.getPictureData({ picture })
113
- const entries = [['OO', pictureData.x], ...this.getSizes(sizes).filter(([, width]) => width <= pictureData.x)]
113
+ // A lossy display original covers small/non-ladder sources without
114
+ // making clients fall back to the download-only lossless OO.
115
+ const displaySizes = new Map(this.getSizes(sizes).filter(([, width]) => width <= pictureData.x))
116
+ displaySizes.set(`S${pictureData.x}`, pictureData.x)
117
+ const entries = [['OO', pictureData.x], ...[...displaySizes].sort((a, b) => a[1] - b[1])]
114
118
  const generated = await Promise.all(entries.map(async entry => ({
115
119
  entry,
116
120
  buffer: await this.getBuffer({ picture, entry })
@@ -132,7 +136,6 @@ class Images {
132
136
  file: { ...pictureData, sizes: hashes }
133
137
  })
134
138
 
135
- F3.logs(`✅ Created: ${Object.keys(hashes).join(' ')}\n`)
136
139
  return result
137
140
  }
138
141
  }
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
1
  {
2
- "version": "3.0.0",
3
- "name": "@fullstackunicorn/websites",
4
- "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
- "description": "A development utility for generating icons, favicons, thumbnails and all what is needed for websites",
6
- "license": "MIT",
7
- "type": "module",
8
- "private": false,
9
- "readme": "package.md",
10
- "main": "index.js",
11
- "files": [
12
- "index.js",
13
- "index.dep.js",
14
- "modules/",
15
- "package.md"
16
- ],
17
- "repository": {
18
- "type": "git",
19
- "url": "https://gitlab.com/fullstackunicorn/websites.git"
20
- },
21
- "keywords": [
22
- "icon-generator",
23
- "favicon-generator",
24
- "react-native",
25
- "react",
26
- "fullstackunicorn"
27
- ],
28
- "imports": {
29
- "#@": "./",
30
- "#@/*": "./*"
31
- },
32
- "scripts": {
33
- "test": "node --test tests/*.test.js"
34
- },
35
- "dependencies": {
36
- "@fullstackunicorn/filesystem": "^1.0.4",
37
- "@fullstackunicorn/initialize": "^1.0.7",
38
- "blurhash": "^2.0.5",
39
- "sharp": "^0.34.5"
40
- },
41
- "devDependencies": {
42
- "@fullstackunicorn/cli": "^1.0.3",
43
- "@fullstackunicorn/reduce": "^1.0.19"
44
- }
45
- }
2
+ "version": "4.1.0",
3
+ "name": "@fullstackunicorn/websites",
4
+ "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
+ "description": "A development utility for generating icons, favicons, thumbnails and all what is needed for websites",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "packageManager": "yarn@4.18.1",
9
+ "readme": "package.md",
10
+ "main": "index.js",
11
+ "files": [
12
+ "index.js",
13
+ "index.dep.js",
14
+ "modules/",
15
+ "package.md"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://gitlab.com/fullstackunicorn/websites.git"
20
+ },
21
+ "keywords": [
22
+ "icon-generator",
23
+ "favicon-generator",
24
+ "react-native",
25
+ "react",
26
+ "fullstackunicorn"
27
+ ],
28
+ "imports": {
29
+ "#@": "./",
30
+ "#@/*": "./*"
31
+ },
32
+ "scripts": {
33
+ "test": "node --test tests/*.test.js"
34
+ },
35
+ "dependencies": {
36
+ "@fullstackunicorn/filesystem": "^1.0.4",
37
+ "@fullstackunicorn/initialize": "^1.0.7",
38
+ "blurhash": "^2.0.5",
39
+ "sharp": "^0.34.5"
40
+ },
41
+ "devDependencies": {
42
+ "@fullstackunicorn/cli": "^1.0.3",
43
+ "@fullstackunicorn/reduce": "^1.0.19"
44
+ }
45
+ }
package/package.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @fullstackunicorn/websites
2
2
 
3
- Versione sorgente: `3.0.0`. Installazione: `npm install @fullstackunicorn/websites` (registro/permessi del pacchetto richiesti).
3
+ Versione sorgente: `4.1.0`. Installazione: `yarn add @fullstackunicorn/websites` (registro/permessi del pacchetto richiesti).
4
4
 
5
5
  Utility Node per generare immagini, icone e cover sociali condivise con sharp.
6
6
 
@@ -15,16 +15,32 @@ import { websites } from '@fullstackunicorn/websites'
15
15
  | Metodo | Input → risultato |
16
16
  |---|---|
17
17
  | websites.icons.generate({ favicon, icon }) | Oggetti con name/buffer PNG o SVG → mappa di file generati |
18
- | websites.images.generate({ file, folder, sizes }) | file.path/file.buffer, destinazione e larghezze richieste → sole varianti disponibili e metadata v2 |
18
+ | websites.images.generate({ file, folder, sizes }) | file.path/file.buffer, destinazione e larghezze richieste → sole varianti disponibili e metadata v3 |
19
19
 
20
20
  ## Formati
21
- Icone: favicon 32, icone 180/192/512. Immagini: jpg/jpeg/png; media sizes version 2 con chiavi che dichiarano direttamente la larghezza: S40, S80, S160, S320, S400, S480, S640, S800, S960, S1280, S1600, S1920, S2560, S3200 e S3840. Estensione non supportata o originale più stretto di 40 px: errore. Helper interni non sono un contratto stabile separato.
21
+ Icone: favicon 32, icone 180/192/512. Immagini: jpg/jpeg/png; media sizes version 3 con chiavi che dichiarano direttamente la larghezza: S40, S80, S160, S320, S400, S480, S640, S800, S960, S1280, S1600, S1920, S2560, S3200 e S3840. Estensione non supportata o originale più stretto di 40 px: errore. Helper interni non sono un contratto stabile separato.
22
22
 
23
23
  ## Requisiti e limiti
24
24
  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.
25
25
 
26
- ## Images 3.0
26
+ ## Images 4.0
27
27
 
28
28
  `generate({ file, folder, sizes })` richiede l'elenco delle sole varianti necessarie al progetto. `S40` è sempre aggiunta e garantita; `OO` è sempre il WebP lossless alla risoluzione originale. Ogni derivata nasce direttamente dalla sorgente con Sharp e `withoutEnlargement`; le varianti richieste più larghe dell'originale non vengono create.
29
29
 
30
- I metadata pubblici contengono `sizesVersion: 2`, `src` con `/S40/` come template stabile, `sizes` come mappa diretta `{ OO: hash, S40: hash, ... }`, `x`, `y`, `ratio` e `placeholder`. L'assenza di una chiave in `sizes` significa che la variante non esiste. Non esistono più i campi pubblici `max`, `full`, `widths`, `hashes` o `original`. Il chiamante ricava disponibilità e hash dalla stessa mappa e sostituisce `/S40/` nel path soltanto dopo avere scelto una chiave presente.
30
+ I metadata pubblici contengono `sizesVersion: 3`, `src` con `/S40/` come template stabile, `sizes` come mappa diretta `{ OO: hash, S40: hash, ... }`, `x`, `y`, `ratio` e `placeholder`. L'assenza di una chiave in `sizes` significa che la variante non esiste. Non esistono più i campi pubblici `max`, `full`, `widths`, `hashes` o `original`. Il chiamante ricava disponibilità e hash dalla stessa mappa e sostituisce `/S40/` nel path soltanto dopo avere scelto una chiave presente.
31
+
32
+ ## Ricetta e visualizzazione
33
+
34
+ Ricetta `webp-q85-e4-smart-original-lossless-v3`: il sorgente resta invariato, `OO` usa `lossless:true, effort:4`; ogni `S<n>` usa `lossless:false, quality:85, effort:4, smartSubsample:true`. Ogni variante deriva direttamente dal sorgente. Q85 non significa conservare l’85% della qualità.
35
+
36
+ Oltre a `S40` e alla selezione responsive, il generatore produce sempre `S<larghezza sorgente>` lossy, deduplicandola se è già richiesta. Esempi: una sorgente da 600 px produce `S600`; una da 661 px produce `S661`. Questa aggiunta automatica non estende la scala accettata da `getSizes`: la selezione responsive resta calcolata dalla Geometry sulla scala canonica. Nessun upscale.
37
+
38
+ `OO` è riservato al download esplicito, non è un fallback per display, zoom, preload o riuso di un’immagine già caricata. I selettori condivisi accettano le chiavi numeriche `S<n>` realmente presenti e non superiori a `picture.x`. Per target maggiori del sorgente scelgono il più grande `S<n>` disponibile. Gli ingrandimenti a schermo restano lossy; il download dell’originale offre il sorgente o `OO`.
39
+
40
+ La ricetta e `sizesVersion` partecipano alla cache di conversione. Il cambio da v2 richiede rigenerazione dei descrittori e allineamento del selettore condiviso prima dell’attivazione. La versione sorgente non prova la pubblicazione NPM né l’attivazione dei siti.
41
+
42
+ ## Covers: WebP opt-in
43
+
44
+ `covers.generate({ trademark, background, format })` e `covers.fromImage({ image, format })` accettano soltanto `jpeg` e `webp`. Il formato omesso resta JPEG Q90 con chroma 4:4:4, con gli stessi byte della precedente implementazione. La dimensione resta 1200×630. WebP richiede `format: 'webp'` e usa quality 85, effort 4 e smartSubsample. Il chiamante deve assegnare estensione e MIME coerenti.
45
+
46
+ `covers.recipe` identifica esclusivamente la conversione WebP opt-in: `social-1200x630-webp-q85-e4-v1`. I consumer includono questa ricetta nella cache soltanto per le cover convertite in WebP; non devono invalidare le unità JPEG legacy o i file statici estranei.