@fullstackunicorn/websites 4.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.0.0",
2
+ "version": "4.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",
package/package.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @fullstackunicorn/websites
2
2
 
3
- Versione sorgente: `4.0.0`. Installazione: `yarn add @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
 
@@ -38,3 +38,9 @@ Oltre a `S40` e alla selezione responsive, il generatore produce sempre `S<largh
38
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
39
 
40
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.