# Κεφάλαια παιδικού βιβλίου με βινιέτες και περιλήψεις

> Ένα στιλ επικεφαλίδας ανοίγει κάθε κεφάλαιο· κάθε επικεφαλίδα ονομάζει σε ιδιότητες τη βινιέτα της και την πλάγια περίληψή της, που τις βάφει η εναρκτήρια ζώνη.

- Έκδοση HTML: https://postext.dev/el/cookbook/storybook-chapter-vignettes
- Συνταγή Αρ. 066 · Επικεφαλίδες και εναρκτήριες σελίδες · Επίπεδο 2 (Μεσαίο) · Έξοδοι: Canvas
- Είδη: Πεζογραφία, θέατρο και λογοτεχνικός λόγος
- Απαιτεί postext ≥ 1.25.0 · δοκιμασμένη με 1.65.0 στις 2026-10-31
- Σελίδες: [6](https://postext.dev/cookbook/storybook-chapter-vignettes/en/p01.webp?v=1c17504d), [7](https://postext.dev/cookbook/storybook-chapter-vignettes/en/p02.webp?v=1c17504d), [8](https://postext.dev/cookbook/storybook-chapter-vignettes/en/p03.webp?v=1c17504d), [9](https://postext.dev/cookbook/storybook-chapter-vignettes/en/p04.webp?v=1c17504d), [10](https://postext.dev/cookbook/storybook-chapter-vignettes/en/p05.webp?v=1c17504d)
- Άνοιγμα στο Sandbox: https://postext.dev/el/sandbox#recipe=storybook-chapter-vignettes&lang=en (.postext: https://postext.dev/cookbook/storybook-chapter-vignettes/en/storybook-chapter-vignettes.postext)
- Τελευταία ενημέρωση: 2026-10-10
- Άλλες γλώσσες: [en](https://postext.dev/en/cookbook/storybook-chapter-vignettes.md), [es](https://postext.dev/es/cookbook/storybook-chapter-vignettes.md), [ca](https://postext.dev/ca/cookbook/storybook-chapter-vignettes.md), [de](https://postext.dev/de/cookbook/storybook-chapter-vignettes.md), [fr](https://postext.dev/fr/cookbook/storybook-chapter-vignettes.md), [it](https://postext.dev/it/cookbook/storybook-chapter-vignettes.md), [pt](https://postext.dev/pt/cookbook/storybook-chapter-vignettes.md), [zh](https://postext.dev/zh/cookbook/storybook-chapter-vignettes.md), [ja](https://postext.dev/ja/cookbook/storybook-chapter-vignettes.md), [ar](https://postext.dev/ar/cookbook/storybook-chapter-vignettes.md)

## Με λίγα λόγια

Οι πρώτες σελίδες μιας ιταλικής παιδικής έκδοσης του Πινόκιο. Κάθε κεφάλαιο ανοίγει με τη δική του απαλή ζωγραφιστή εικόνα και μια σύντομη περίληψη όσων συμβαίνουν.

## Τι θα στοιχειοθετήσετε

Οι πρώτες σελίδες μιας ιταλικής παιδικής έκδοσης του *Le avventure di Pinocchio* του Collodi, στοιχειοθετημένες σε Averia Serif Libre 13 σε 19 pt σε σελίδα 190 × 240 mm. Μια σελίδα τίτλου στην αριστερή σελίδα στέκεται απέναντι από το κεφάλαιο I: μια ακουαρέλα με τους λόφους της Τοσκάνης, όπου ένα κάρο με γαϊδούρι φέρνει καυσόξυλα σε ένα εργαστήριο ξυλουργού, πάνω από τον τίτλο σε Fredericka the Great. Κάθε κεφάλαιο ανοίγει κάτω από μια βινιέτα σε ακουαρέλα που σβήνει μέσα στο χαρτί (ο Maestro Ciliegia με το τσεκούρι σηκωμένο πάνω από το κούτσουρο που μιλά για το κεφάλαιο I, ο Geppetto με την κίτρινη περούκα του να παίρνει το κούτσουρο για το κεφάλαιο II), έπειτα η γραμμή του κεφαλαίου και η περίληψη του Collodi σε κεντραρισμένα πλάγια. Και οι τέσσερις εικόνες φτιάχτηκαν με μοντέλα διάχυσης από μία περιγραφή στιλ και την παλέτα της σελίδας. Οι τρέχουσες κεφαλίδες τυπώνονται μόνο στις σελίδες 8 και 9, τις δύο χωρίς εναρκτήρια ζώνη. Οι αριθμοί σελίδας κάθονται σε δίσκους σε χρώμα ξύλου, και δύο κεράσια κλείνουν το κεφάλαιο I χωρίς λεζάντα ή αριθμό.

**Αυτή η συνταγή απαντά:**

- Πώς βάζω σε κάθε κεφάλαιο ενός παιδικού βιβλίου τη δική του βινιέτα και μια πλάγια περίληψη;
- Πώς στοιχειοθετώ μη αριθμημένα εικαστικά: κοσμήματα, βινιέτες, λογότυπα;
- Πώς προσθέτω σε μια εναρκτήρια σελίδα γραμμή συγγραφέα, εισαγωγικό κείμενο ή εισαγωγή με αρχίγραμμα;
- Πώς κρύβω τις τρέχουσες κεφαλίδες στις εναρκτήριες και στις κενές σελίδες, ή χρωματίζω μια κενή αριστερή σελίδα με το χρώμα του μέρους;

## Η σύντομη απάντηση

```js
// script.js, γραμμές 44–64
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's
const opener = { enabled: true,
  // A floor for the height the opener reserves, in whole lines, so the text under chapter I's
  // two-line summary starts on the same grid line as the text under chapter II's three lines.
  minHeight: pt(14 * LEAD),
  slot: { elements: [
    { kind: 'image', id: 'vignette', resourceId: '{attr.vignetta}',
      placement: at('container', 'top', 0, 0,
        { width: mm(VIGNETTE.width), height: mm(VIGNETTE.height) }) },
    // The chapter line 6 mm under the picture's foot, the summary 5 mm under the chapter line.
    text('chapter', '{titleText}', DISPLAY, 24, at('container', 'top-left', 0,
      VIGNETTE.height + 6, { width: mm(MEASURE) }), { ...caps(2.4), lineHeight: 1 }),
    text('summary', '{attr.summary}', TEXT, 12.5, at('#chapter', 'below',
      (MEASURE - SUMMARY) / 2, 5, { width: mm(SUMMARY) }), { italic: true, lineHeight: 1.38 }),
  ] },
};
const chapter = { id: 'capitolo', advancedDesign: opener };
```

## Υλικά

**Διδάσκει**

- [Σχεδιασμένες εναρκτήριες σελίδες](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση): Μια επικεφαλίδα σχεδιασμένη ως ελεύθερη σύνθεση από κείμενο, γραμμές, πλαίσια και εικόνες, που δεσμεύει το ύψος που χρειάζεται πάνω από το κυρίως κείμενο.
- [Εικόνες στις σχεδιάσεις σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-εικόνας): Λογότυπα, φωτογραφίες και κοσμήματα τοποθετημένα σε κεφαλίδες, υποσέλιδα, εναρκτήριες σελίδες και σελίδες μέρους, με μέγεθος που διατηρεί τις αναλογίες τους.
- [Τρέχουσες κεφαλίδες και αριθμοί σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα): Θέσεις κεφαλίδας και υποσέλιδου με σύμβολα κράτησης θέσης ({pageNumber}, {chapterTitle}, {title}…), που ορίζονται χωριστά για δεξιά και αριστερή σελίδα, με τους μεγάλους τίτλους να περικόπτονται ή να αναδιπλώνονται.

**Χρησιμοποιεί επίσης**

- [Στιλ επικεφαλίδων](https://postext.dev/el/docs/configuration-styles.md#στιλ-επικεφαλίδων)
- [Ιδιότητες επικεφαλίδων](https://postext.dev/el/docs/document-format.md#χαρακτηριστικά-επικεφαλίδων)
- [Κεφάλαια που ανοίγουν σε δεξιά σελίδα](https://postext.dev/el/docs/configuration-headings.md#αλλαγή-σελίδας-πριν-από-επικεφαλίδα)
- [Κείμενο, γραμμές και πλαίσια στις σχεδιάσεις σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα)
- [Κεφαλίδες ανά ρόλο σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-κειμένου)
- [Προσαρμοσμένοι τύποι πόρων](https://postext.dev/el/docs/configuration-resources.md#τύποι-πόρων)
- [Εικόνες ακριβώς εδώ](https://postext.dev/el/docs/document-format-resources.md#ενσωμάτωση-μπλοκ-προαιρετική-ρητή-τοποθέτηση-μέσα-στη-ροή)
- [Εικόνες και πίνακες ως πόροι](https://postext.dev/el/docs/document-format-resources.md#πόροι)
- [Συλλαβισμός και γλώσσα του εγγράφου](https://postext.dev/el/docs/justification.md#υποστηριζόμενες-γλώσσες)
- [Συμμετρικά περιθώρια](https://postext.dev/el/docs/configuration-page-layout.md#κατοπτρικά-περιθώρια)
- [Σημασιολογική χρωματική παλέτα](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων)
- [Σελίδες σε καμβά](https://postext.dev/el/docs/configuration-programmatic-usage.md#απόδοση-σελίδας-σε-bitmap)
- [Χρώμα χαρτιού](https://postext.dev/el/docs/configuration-page-layout.md#σελίδα)
- [Στιλ παραγράφων](https://postext.dev/el/docs/configuration-styles.md#στιλ-παραγράφων)
- [Τρέχουσες κεφαλίδες ανά ενότητα](https://postext.dev/el/docs/configuration-styles.md#στιλ-επικεφαλίδων)

**Η διαμόρφωση με μια ματιά**

- [`bodyText`](https://postext.dev/el/docs/configuration-text.md#κυρίως-κείμενο), [`colorPalette`](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων), [`footer`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`header`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`headingStyles`](https://postext.dev/el/docs/configuration-styles.md#στιλ-επικεφαλίδων), [`headings`](https://postext.dev/el/docs/configuration-headings.md#επικεφαλίδες), [`layout`](https://postext.dev/el/docs/configuration-page-layout.md#διάταξη), [`locale`](https://postext.dev/el/docs/configuration-language.md#συλλαβισμός), [`page`](https://postext.dev/el/docs/configuration-page-layout.md#σελίδα), [`paragraphStyles`](https://postext.dev/el/docs/configuration-styles.md#στιλ-παραγράφων), [`resourceTypes`](https://postext.dev/el/docs/configuration-resources.md#τύποι-πόρων)

**API**

- [`buildDocumentWithFonts`](https://postext.dev/el/docs/configuration-programmatic-usage.md#φόρτωση-γραμματοσειρών-πριν-από-τη-σελιδοποίηση), [`registerResourceImage`](https://postext.dev/el/docs/architecture.md#η-επιφάνεια-του-api), [`renderPageToCanvas`](https://postext.dev/el/docs/configuration-programmatic-usage.md#απόδοση-σελίδας-σε-bitmap)

**Γραμματοσειρές**

- Averia Serif Libre (OFL-1.1), Fredericka the Great (OFL-1.1), Quicksand (OFL-1.1)

## Προετοιμασία

### 1 · Ένα στιλ επικεφαλίδας, μια βινιέτα ονομασμένη σε κάθε επικεφαλίδα

Ο κώδικας αυτού του βήματος βρίσκεται στη [σύντομη απάντηση](https://postext.dev/el/cookbook/storybook-chapter-vignettes.md#η-σύντομη-απάντηση). Το `resourceId` ενός στοιχείου εικόνας δέχεται τα ίδια σύμβολα κράτησης θέσης με ένα κείμενο σχεδίασης, οπότε το `'{attr.vignetta}'` σχεδιάζει τον πόρο που ονομάζει η επικεφαλίδα, όπως το `{attr.summary}` τυπώνει την περίληψή της. Και τα δύο κεφάλαια μοιράζονται το στιλ `capitolo` και ονομάζουν την εικόνα τους στη γραμμή της επικεφαλίδας: `# Capitolo II {style="capitolo" vignetta="polenta" summary="…"}`. Ένα τρίτο κεφάλαιο χρειάζεται έναν πόρο και μία επικεφαλίδα ακόμη, όχι άλλο στιλ ([στοιχεία εικόνας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-εικόνας)). Η γραμμή του κεφαλαίου τοποθετείται από την κορυφή του περιέκτη, 6 mm κάτω από το κουτί της βινιέτας, και η περίληψη κρέμεται 5 mm κάτω από αυτήν· η εναρκτήρια ζώνη κρατά χώρο ως την τελευταία γραμμή της περίληψης. Με το `minHeight` ως κατώτατο όριο 14 γραμμών, το κείμενο του κεφαλαίου I αρχίζει στην ίδια γραμμή με του κεφαλαίου II, του οποίου η περίληψη έχει μία γραμμή παραπάνω· χωρίς αυτό, το κείμενο του κεφαλαίου I αρχίζει 6,7 mm ψηλότερα ([έκταση και προχωρημένη σχεδίαση](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση)).

### 2 · Φορτώστε τους πίνακες ως πόρους bitmap

```js
// script.js, γραμμές 122–133
const PICTURES = { // id: [file, width, height, alt text in the book's language]
  frontespizio: ['frontespizio-1400.jpg', 1400, 1105, 'Colline toscane con cipressi e un borgo; '
    + 'un contadino guida un asinello con un carretto di legna verso la bottega di un falegname.'],
  ceppo: ['ceppo-1200.jpg', 1200, 800, 'Maestro Ciliegia, con la scure alzata sopra un pezzo di '
    + 'legno sul banco, si guarda intorno spaventato.'],
  polenta: ['polenta-1200.jpg', 1200, 800, 'Geppetto, con la parrucca gialla, riceve il pezzo di '
    + 'legno da Maestro Ciliegia; accanto, un paiolo di polenta fumante.'],
  ciliegie: ['ciliegie-600.jpg', 600, 626, 'Due ciliegie rosse su un picciolo, con una foglia.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
  id, typeId: 'fregio', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
  bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
```

Κάθε εικόνα είναι ένα JPEG στον φάκελο `assets/` της συνταγής, δηλωμένο στο μέγεθός του σε pixel: η σελιδοποίηση διαβάζει μόνο αυτά τα μεγέθη, και ο καμβάς βάφει ό,τι έχει καταχωρίσει το `loadImage()` με κάθε αναγνωριστικό αρχείου όταν σχεδιάζει τη σελίδα. Οι βινιέτες και τα κεράσια φτιάχτηκαν σε λευκό και έπειτα πολλαπλασιάστηκαν με το χρώμα του χαρτιού `#fffaf0`, ώστε τα περιθώριά τους να τυπώνονται όπως η σελίδα και οι εικόνες να μην έχουν ορατή άκρη. Η προμετωπίδα είναι κομμένη σε 190:150, το σχήμα του πεδίου της, ώστε η προσαρμοσμένη εικόνα να γεμίζει το πεδίο χωρίς λωρίδα χαρτιού. Το τοπίο και οι βινιέτες βάφονται από στοιχεία εικόνας στις σχεδιάσεις, τα κεράσια από το `::resource{id="ciliegie"}` στο Markdown.

### 3 · Κάντε τη σελίδα τίτλου στιλ επικεφαλίδας

```js
// script.js, γραμμές 68–85
const SKY = 150; // mm from the top edge: the foot of the painted field
// # Pinocchio {style="frontespizio" kicker="Le avventure di"}; subtitle and author come from
// the frontmatter. Every element hangs from the page, so the field runs off three edges.
const frontispiece = {
  id: 'frontespizio',
  footer: { elements: [] }, // no folio; the running heads already skip openers
  advancedDesign: { enabled: true, slot: { elements: [ // array order is paint order
    { kind: 'image', id: 'landscape', resourceId: 'frontespizio', // cut to the field's 190:150
      placement: at('page', 'top-left', 0, 0, { width: 'fill', height: mm(SKY) }) },
    text('kicker', '{attr.kicker}', LABEL, 11, at('page', 'top', 0, SKY + 11),
      { ...caps(2.6), fontWeight: 700 }),
    text('title', '{titleText}', DISPLAY, 70, at('page', 'top', 0, SKY + 17),
      { lineHeight: 1, color: col('bark') }),
    text('subtitle', '{subtitle}', TEXT, 15, at('page', 'top', 0, SKY + 44), { italic: true }),
    text('author', '{author}', LABEL, 9, at('page', 'top', 0, SKY + 58),
      { ...caps(2), fontWeight: 600 }),
  ] } },
};
```

Η σελίδα τίτλου είναι η πρώτη επικεφαλίδα του Markdown, `# Pinocchio {style="frontespizio" kicker="Le avventure di"}`, και το στιλ της βάφει ό,τι υπάρχει στη σελίδα: το τοπίο, βάθους 150 mm από το πάνω άκρο, έπειτα τον υπέρτιτλο από την ιδιότητα, τον τίτλο, και τον υπότιτλο και τον συγγραφέα από το frontmatter. Κάθε στοιχείο κρέμεται από τη σελίδα, όχι από την επιφάνεια στοιχειοθεσίας, ώστε ο πίνακας να φτάνει στο πάνω άκρο και στις δύο πλευρές του φύλλου ενώ η ίδια η επικεφαλίδα μένει στη μία στήλη του βιβλίου. Το κενό `footer` αφαιρεί τον δίσκο του αριθμού σελίδας που τυπώνουν οι εναρκτήριες σελίδες των κεφαλαίων, και το `pages: 'body'` κρατά ήδη τις τρέχουσες κεφαλίδες έξω από τη σελίδα ([στιλ επικεφαλίδων](https://postext.dev/el/docs/configuration-styles.md#στιλ-επικεφαλίδων)).

### 4 · Τρέχουσες κεφαλίδες στις σελίδες κειμένου, αριθμοί σελίδας σε δίσκους

```js
// script.js, γραμμές 89–110
// The excerpt opens on book page 6, a verso, so the title page faces chapter I.
const continuation = { pageIndexOffset: 5, pageNumbering: { startAt: 6 } };
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre sits off the page's centre
const head = (id, content, parity, x) => text(id, content, LABEL, 8,
  at('page', 'top', x, 12), { ...caps(1.8), fontWeight: 600, parity, pages: 'body' });
const DISC = 7.4; // mm: the folio's disc
// A fixed square with a radius of half its side is a circle; the figures sit in its middle.
// lineHeight 1.17: the baseline falls at 0.8 of the line, 0.94 em down, so Quicksand's
// figures (0.70 em tall) leave 0.23 em above and below them, and 'middle' centres that line.
const disc = (id, parity, pages, edge, x) => text(id, '{pageNumber}', LABEL, 8.5,
  at('page', edge, x, -(BOTTOM - DISC) / 2, { width: mm(DISC), height: mm(DISC) }),
  { fontWeight: 700, color: col('paper'), lineHeight: 1.17, verticalAlign: 'middle', parity,
    pages, box: { backgroundColor: col('wood'), borderRadius: mm(DISC / 2) } });
const header = { elements: [
  head('verso-title', '{title}', 'even', -SHIFT), // the book on the left-hand page
  head('recto-chapter', '{chapterTitle}', 'odd', SHIFT), // the chapter on the right
] };
const footer = { elements: [
  disc('verso-folio', 'even', 'body', 'bottom-left', OUTER),
  disc('recto-folio', 'odd', 'body', 'bottom-right', -OUTER),
  disc('opener-folio', 'all', 'opener', 'bottom', 0), // a chapter opens on either side
] };
```

Το `continuation` αριθμεί το απόσπασμα από τη σελίδα 6 του βιβλίου, μια αριστερή σελίδα, ώστε η σελίδα τίτλου να στέκεται απέναντι από το κεφάλαιο I και ο πρώτος αριθμός σελίδας που τυπώνεται να είναι το 7. Το `pages: 'body'` κρατά τις τρέχουσες κεφαλίδες έξω από τη σελίδα τίτλου και τις δύο εναρκτήριες σελίδες, οπότε τυπώνονται μόνο στις σελίδες 8 και 9, ο τίτλος του βιβλίου στην αριστερή και του κεφαλαίου στη δεξιά ([στοιχεία κειμένου](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-κειμένου)). Ο αριθμός σελίδας είναι ένα κείμενο σχεδίασης σε σταθερό τετράγωνο 7,4 mm του οποίου η ακτίνα γωνίας είναι η μισή πλευρά του, κάτι που δίνει κύκλο· το `verticalAlign: 'middle'` και το διάστιχο που υπολογίζεται στο σχόλιο κεντράρουν τα ψηφία μέσα του. Τα ψηφία στο χρώμα του χαρτιού έχουν λόγο αντίθεσης 4,98:1 με το ξύλο. Οι αραιωμένες ετικέτες δεν χρειάζονται μετατόπιση: η αραίωση μετά το τελευταίο γράμμα μιας γραμμής μένει έξω όταν η γραμμή κεντράρεται.

### 5 · Κλείστε το κεφάλαιο με ένα ακροτελεύτιο κόσμημα χωρίς αριθμό

```js
// script.js, γραμμές 114–118
// No caption prefix and no caption, so the cherries that close chapter I print with no
// label or number. The pictures the design slots paint are of this type too.
const resourceTypes = [{ id: 'fregio', name: 'Fregio', namePlural: 'Fregi', shortLabel: 'Fregio',
  captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
  defaultPlacement: { position: 'here', width: 0.16, align: 'center' } }];
```

Ένας τύπος πόρου τυπώνει το `captionPrefix` και τον αριθμό του πριν από τη λεζάντα. Με κενό πρόθεμα και χωρίς λεζάντα, τίποτα δεν τυπώνεται κάτω από τα κεράσια· με `captionPrefix: 'Fregio'`, ο ίδιος πόρος τυπώνει *Fregio 1.* κάτω από το σχέδιο και ψηλώνει κατά 10 mm ([τύποι πόρων](https://postext.dev/el/docs/configuration-resources.md#τύποι-πόρων)). Το `defaultPlacement` του τύπου βάζει κάθε πόρο εκεί όπου στέκεται η γραμμή `::resource` του, στο ένα έκτο του πλάτους στοιχειοθεσίας και στο κέντρο, οπότε το Markdown χρειάζεται μόνο ένα `::resource{id="ciliegie"}` μετά την τελευταία παράγραφο του κεφαλαίου. Οι άλλες εικόνες μοιράζονται τον τύπο, αλλά κανένα `:ref` ή `::resource` δεν τις ονομάζει, οπότε δεν τοποθετούνται ούτε μετρώνται ποτέ.

## Η πλήρης συνταγή

Ένα αρχείο, συντεθειμένο από τον φάκελο της συνταγής με το δείγμα κειμένου και το κοινό κιτ του Συνταγολογίου ενσωματωμένα· φτιάχνει τη δική του σελίδα. Για να το εκτελέσετε, βάλτε το σε ένα `<script type="module">` σε μια κενή σελίδα, ή επικολλήστε το στο πάνελ JS ενός νέου CodePen (ως module). Εισάγει το postext από το esm.sh, οπότε δεν χρειάζεται εγκατάσταση ούτε build.

- Φάκελος πηγής: https://github.com/drnachio/postext/tree/main/cookbook/storybook-chapter-vignettes

### script.js

```js
// ═══ Postext Cookbook · Nº 066 · Storybook chapters with vignettes and summaries ═══
// https://postext.dev/en/cookbook/storybook-chapter-vignettes
// Code: MIT · Text: C. Collodi, 1883 (PD, Gutenberg #52484) · Pictures: diffusion models
// Fonts: Averia Serif Libre, Fredericka the Great, Quicksand (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document (the sample is Italian in both)
const RECIPE = 'storybook-chapter-vignettes';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config comes from here; the pictures were painted to it
  ink: '#2b2118', // text: a brown near-black
  paper: '#fffaf0', // a warm book paper, which the vignettes' margins were tinted to
  bark: '#6b4224', // chapter lines, running heads, the title
  wood: '#9a5f30', // the folio discs
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  // The defaults linked to main-color, bold among them, print in bark instead of blue.
  { id: 'main-color', name: 'bark (defaults)', value: { hex: palette.bark, model: 'hex' } },
];
// Text and summaries; the book's title and the chapter lines; running heads and folios.
const [TEXT, DISPLAY, LABEL] = ['Averia Serif Libre', 'Fredericka the Great', 'Quicksand'];
const TRIM = { width: 190, height: 240 }; // mm
const [TOP, INNER, OUTER] = [22, 22, 20]; // mm; mirrored, so the spine margin swaps sides
const MEASURE = TRIM.width - INNER - OUTER; // 148 mm
const [BODY, LEAD, LINES] = [13, 19, 29]; // pt, pt, and whole lines in the text block
const BOTTOM = TRIM.height - TOP - (LINES * LEAD * 25.4) / 72; // mm: 23.6
// Design-slot shorthands: a placement from an anchor's edge (mm), and a design text.
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const text = (id, content, fontFamily, size, placement, extra = {}) => ({ kind: 'text', id,
  content, fontFamily, fontSize: pt(size), color: col('ink'), align: 'center',
  overflow: 'wrap', // a long line wraps in every slot, the running heads too
  placement, ...extra });
const caps = (tracking) => ({ textTransform: 'uppercase', letterSpacing: pt(tracking),
  color: col('bark') });

// #region answer: one opener for every chapter: the vignette the heading names, then its summary
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's
const opener = { enabled: true,
  // A floor for the height the opener reserves, in whole lines, so the text under chapter I's
  // two-line summary starts on the same grid line as the text under chapter II's three lines.
  minHeight: pt(14 * LEAD),
  slot: { elements: [
    { kind: 'image', id: 'vignette', resourceId: '{attr.vignetta}',
      placement: at('container', 'top', 0, 0,
        { width: mm(VIGNETTE.width), height: mm(VIGNETTE.height) }) },
    // The chapter line 6 mm under the picture's foot, the summary 5 mm under the chapter line.
    text('chapter', '{titleText}', DISPLAY, 24, at('container', 'top-left', 0,
      VIGNETTE.height + 6, { width: mm(MEASURE) }), { ...caps(2.4), lineHeight: 1 }),
    text('summary', '{attr.summary}', TEXT, 12.5, at('#chapter', 'below',
      (MEASURE - SUMMARY) / 2, 5, { width: mm(SUMMARY) }), { italic: true, lineHeight: 1.38 }),
  ] },
};
const chapter = { id: 'capitolo', advancedDesign: opener };
// #endregion

// #region frontispiece: the title page as a heading style: a painted field, then the title
const SKY = 150; // mm from the top edge: the foot of the painted field
// # Pinocchio {style="frontespizio" kicker="Le avventure di"}; subtitle and author come from
// the frontmatter. Every element hangs from the page, so the field runs off three edges.
const frontispiece = {
  id: 'frontespizio',
  footer: { elements: [] }, // no folio; the running heads already skip openers
  advancedDesign: { enabled: true, slot: { elements: [ // array order is paint order
    { kind: 'image', id: 'landscape', resourceId: 'frontespizio', // cut to the field's 190:150
      placement: at('page', 'top-left', 0, 0, { width: 'fill', height: mm(SKY) }) },
    text('kicker', '{attr.kicker}', LABEL, 11, at('page', 'top', 0, SKY + 11),
      { ...caps(2.6), fontWeight: 700 }),
    text('title', '{titleText}', DISPLAY, 70, at('page', 'top', 0, SKY + 17),
      { lineHeight: 1, color: col('bark') }),
    text('subtitle', '{subtitle}', TEXT, 15, at('page', 'top', 0, SKY + 44), { italic: true }),
    text('author', '{author}', LABEL, 9, at('page', 'top', 0, SKY + 58),
      { ...caps(2), fontWeight: 600 }),
  ] } },
};
// #endregion

// #region folios: running heads on body pages only, folios in wood-coloured discs
// The excerpt opens on book page 6, a verso, so the title page faces chapter I.
const continuation = { pageIndexOffset: 5, pageNumbering: { startAt: 6 } };
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre sits off the page's centre
const head = (id, content, parity, x) => text(id, content, LABEL, 8,
  at('page', 'top', x, 12), { ...caps(1.8), fontWeight: 600, parity, pages: 'body' });
const DISC = 7.4; // mm: the folio's disc
// A fixed square with a radius of half its side is a circle; the figures sit in its middle.
// lineHeight 1.17: the baseline falls at 0.8 of the line, 0.94 em down, so Quicksand's
// figures (0.70 em tall) leave 0.23 em above and below them, and 'middle' centres that line.
const disc = (id, parity, pages, edge, x) => text(id, '{pageNumber}', LABEL, 8.5,
  at('page', edge, x, -(BOTTOM - DISC) / 2, { width: mm(DISC), height: mm(DISC) }),
  { fontWeight: 700, color: col('paper'), lineHeight: 1.17, verticalAlign: 'middle', parity,
    pages, box: { backgroundColor: col('wood'), borderRadius: mm(DISC / 2) } });
const header = { elements: [
  head('verso-title', '{title}', 'even', -SHIFT), // the book on the left-hand page
  head('recto-chapter', '{chapterTitle}', 'odd', SHIFT), // the chapter on the right
] };
const footer = { elements: [
  disc('verso-folio', 'even', 'body', 'bottom-left', OUTER),
  disc('recto-folio', 'odd', 'body', 'bottom-right', -OUTER),
  disc('opener-folio', 'all', 'opener', 'bottom', 0), // a chapter opens on either side
] };
// #endregion

// #region tailpiece: an unnumbered resource type, set where ::resource stands
// No caption prefix and no caption, so the cherries that close chapter I print with no
// label or number. The pictures the design slots paint are of this type too.
const resourceTypes = [{ id: 'fregio', name: 'Fregio', namePlural: 'Fregi', shortLabel: 'Fregio',
  captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
  defaultPlacement: { position: 'here', width: 0.16, align: 'center' } }];
// #endregion

// #region pictures: four paintings, declared at their pixel size under the file ids they load as
const PICTURES = { // id: [file, width, height, alt text in the book's language]
  frontespizio: ['frontespizio-1400.jpg', 1400, 1105, 'Colline toscane con cipressi e un borgo; '
    + 'un contadino guida un asinello con un carretto di legna verso la bottega di un falegname.'],
  ceppo: ['ceppo-1200.jpg', 1200, 800, 'Maestro Ciliegia, con la scure alzata sopra un pezzo di '
    + 'legno sul banco, si guarda intorno spaventato.'],
  polenta: ['polenta-1200.jpg', 1200, 800, 'Geppetto, con la parrucca gialla, riceve il pezzo di '
    + 'legno da Maestro Ciliegia; accanto, un paiolo di polenta fumante.'],
  ciliegie: ['ciliegie-600.jpg', 600, 626, 'Due ciliegie rosse su un picciolo, con una foglia.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
  id, typeId: 'fregio', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
  bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
// #endregion

const config = () => ({
  locale: 'it', // Italian hyphenation
  resourceTypes, colorPalette, header, footer, layout: { layoutType: 'single' },
  page: { width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
    margins: { top: mm(TOP), bottom: mm(BOTTOM), left: mm(INNER), right: mm(OUTER),
      mirror: true } },
  bodyText: {
    fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
    italicColor: col('ink'), // *ohi* in ink, not in the defaults' bark
    referenceColor: col('ink'), // the book cites nothing; a :ref added later prints in ink too
    firstLineIndent: mm(5), indentAfterHeading: false,
    // Word spaces from 0.8 to 1.45 of the face's own, and up to 8 ‰ of tracking for a line
    // that would pass either limit. The default maximum of 2 lets 14 lines stretch past
    // 1.45×; 1.45 alone left three, to 1.58×, beside lines squeezed towards the default 0.6.
    minWordSpacing: 0.8, maxWordSpacing: 1.45, maxJustifyTracking: 8,
  },
  headings: {
    fontFamily: DISPLAY, fontWeight: 400, // the designs paint the titles: no Open Sans to load
    // Every chapter on a new page, on either side, so chapter II opens on a verso.
    levels: [{ level: 1, breakBefore: { enabled: true, parity: 'any' } }],
  },
  headingStyles: [frontispiece, chapter],
  paragraphStyles: [{ id: 'colofon', fontFamily: LABEL, fontSize: pt(7.5), lineHeight: pt(11),
    color: col('bark'), textAlign: 'center', firstLineIndent: pt(0), marginTop: pt(LEAD) }],
});

// ─── 2 · Content ────────────────────────────────────────────────────────────
const markdown = String.raw`---
title: "Le avventure di Pinocchio"
subtitle: "Storia di un burattino"
author: "Carlo Collodi"
---

# Pinocchio {style="frontespizio" kicker="Le avventure di"}

# Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia, falegname, trovò un pezzo di legno che piangeva e rideva come un bambino."}

— C’era una volta…

— Un re! — diranno subito i miei piccoli lettori.

— No, ragazzi, avete sbagliato. C’era una volta un pezzo di legno.

Non era un legno di lusso, ma un semplice pezzo da catasta, di quelli che d’inverno si mettono nelle stufe e nei caminetti per accendere il fuoco e per riscaldare le stanze.

Non so come andasse, ma il fatto gli è che un bel giorno questo pezzo di legno capitò nella bottega di un vecchio falegname, il quale aveva nome mastr’Antonio, se non che tutti lo chiamavano maestro Ciliegia, per via della punta del suo naso, che era sempre lustra e paonazza, come una ciliegia matura.

Appena maestro Ciliegia ebbe visto quel pezzo di legno, si rallegrò tutto; e dandosi una fregatina di mani per la contentezza, borbottò a mezza voce:

— Questo legno è capitato a tempo; voglio servirmene per fare una gamba di tavolino. —

Detto fatto, prese subito l’ascia arrotata per cominciare a levargli la scorza e a digrossarlo; ma quando fu lì per lasciare andare la prima asciata, rimase col braccio sospeso in aria, perchè sentì una vocina sottile sottile, che disse raccomandandosi:

— Non mi picchiar tanto forte! —

Figuratevi come rimase quel buon vecchio di maestro Ciliegia!

Girò gli occhi smarriti intorno alla stanza per vedere di dove mai poteva essere uscita quella vocina, e non vide nessuno! Guardò sotto il banco, e nessuno: guardò dentro un armadio che stava sempre chiuso, e nessuno; guardò nel corbello dei trucioli e della segatura, e nessuno; aprì l’uscio di bottega per dare un’occhiata anche sulla strada, e nessuno. O dunque?…

— Ho capito; — disse allora ridendo e grattandosi la parrucca — si vede che quella vocina me la son figurata io. Rimettiamoci a lavorare. —

E ripresa l’ascia in mano, tirò giù un solennissimo colpo sul pezzo di legno.

— Ohi! tu m’hai fatto male! — gridò rammaricandosi la solita vocina.

Questa volta maestro Ciliegia restò di stucco, cogli occhi fuori del capo per la paura, colla bocca spalancata e colla lingua giù ciondoloni fino al mento, come un mascherone da fontana.

Appena riebbe l’uso della parola, cominciò a dire tremando e balbettando dallo spavento:

— Ma di dove sarà uscita questa vocina che ha detto ohi?… Eppure qui non c’è anima viva. Che sia per caso questo pezzo di legno che abbia imparato a piangere e a lamentarsi come un bambino? Io non lo posso credere. Questo legno eccolo qui; è un pezzo di legno da caminetto, come tutti gli altri, e a buttarlo sul fuoco, c’è da far bollire una pentola di fagioli… O dunque? Che ci sia nascosto dentro qualcuno? Se c’è nascosto qualcuno, tanto peggio per lui. Ora l’accomodo io! —

E così dicendo, agguantò con tutt’e due le mani quel povero pezzo di legno, e si pose a sbatacchiarlo senza carità contro le pareti della stanza.

Poi si messe in ascolto, per sentire se c’era qualche vocina che si lamentasse. Aspettò due minuti, e nulla; cinque minuti, e nulla; dieci minuti, e nulla!

— Ho capito — disse allora sforzandosi di ridere e arruffandosi la parrucca — si vede che quella vocina che ha detto *ohi*, me la son figurata io! Rimettiamoci a lavorare. —

E perchè gli era entrato addosso una gran paura, si provò a canterellare per farsi un po’ di coraggio.

Intanto, posata da una parte l’ascia, prese in mano la pialla, per piallare e tirare a pulimento il pezzo di legno; ma nel mentre che lo piallava in su e in giù, sentì la solita vocina che gli disse ridendo:

— Smetti! tu mi fai il pizzicorino sul corpo! —

Questa volta il povero maestro Ciliegia cadde giù come fulminato. Quando riaprì gli occhi, si trovò seduto per terra.

Il suo viso pareva trasfigurito, e perfino la punta del naso, di paonazza come era quasi sempre, gli era diventata turchina dalla gran paura.

::resource{id="ciliegie"}

# Capitolo II {style="capitolo" vignetta="polenta" summary="Maestro Ciliegia regala il pezzo di legno al suo amico Geppetto, il quale lo prende per fabbricarsi un burattino maraviglioso, che sappia ballare, tirar di scherma e fare i salti mortali."}

In quel punto fu bussato alla porta.

— Passate pure, — disse il falegname, senza aver la forza di rizzarsi in piedi.

Allora entrò in bottega un vecchietto tutto arzillo, il quale aveva nome Geppetto; ma i ragazzi del vicinato, quando lo volevano far montare su tutte le furie, lo chiamavano col soprannome di Polendina, a motivo della sua parrucca gialla, che somigliava moltissimo alla polendina di granturco.

Geppetto era bizzosissimo. Guai a chiamarlo Polendina! Diventava subito una bestia, e non c’era più verso di tenerlo.

:::paragraphs{style="colofon"}
Composto in Averia Serif Libre, Fredericka the Great e Quicksand (SIL Open Font License). Testo di Carlo Collodi (1883) secondo l’edizione Bemporad del 1902, Project Gutenberg n. 52484. Illustrazioni generate con modelli di diffusione.
:::
`; // content.<lang>.md: Collodi's Italian in both editions


// ─── 3 · Fonts ──────────────────────────────────────────────────────────────
const FONTS = { 'Averia Serif Libre': ['400', '400i'], 'Fredericka the Great': ['400'],
  Quicksand: ['400', '600', '700'] }; // every face, loaded before layout

// ─── 4 · Build & show ───────────────────────────────────────────────────────
// A design slot or ::resource names a resource, the resource a file id: load each file.
await Promise.all(Object.values(PICTURES).map(([file]) => loadImage(file, asset(file))));
const doc = await buildDocumentWithFonts({ markdown, resources, continuation }, config(),
  kitFonts(FONTS));
showPages(doc, { title: 'Le avventure di Pinocchio' });

// ─── Kit ── helpers shared by every Cookbook recipe · postext.dev/cookbook ─────

// ─── Kit · core v1 ── the same in every recipe · postext.dev/cookbook
function mm(value) { return { value, unit: 'mm' }; }
function pt(value) { return { value, unit: 'pt' }; }
function em(value) { return { value, unit: 'em' }; }
/** The sample language's string: t({ en: 'Figure', es: 'Figura' }). */
function t(strings) { return strings[LANG] ?? Object.values(strings)[0]; }
/** A file in this recipe's assets folder, served from the Postext repo by jsDelivr. */
function asset(file) { return `https://cdn.jsdelivr.net/gh/drnachio/postext@main/cookbook/${RECIPE}/assets/${file}`; }

// ─── Kit · fonts v3 ── the same in every recipe · postext.dev/cookbook
// Postext loads the faces a config asks for before layout and asks the kit
// for Fontsource's files, the ones the PDF embeds too.

/** buildDocumentWithFonts' options: the resolver, and FONTS' faces loaded
 *  with the config's. FONTS = { 'Family Name': ['400', '400i', '700'] }. */
function kitFonts(FONTS = {}) {
  const faces = Object.entries(FONTS).flatMap(([family, specs]) => specs.map((spec) =>
    ({ family, weight: parseInt(spec, 10), style: spec.endsWith('i') ? 'italic' : 'normal' })));
  return { resolve: fontsourceResolver, faces };
}

/** A face's files with their ranges: latin, then latin-ext and greek when
 *  `text` needs them (kitSubsetsFor). Null for a face Fontsource lacks. */
async function fontsourceResolver(family, weight, style, { text = '' } = {}) {
  const id = fontsourceId(family);
  const meta = await fontsourceMeta(family);
  if (meta && !(await fontsourceWeights(family, style)).includes(weight)) return null;
  kitStatus('Loading fonts…');
  const at = await fontsourceAt(id);
  return ['latin', ...kitSubsetsFor(text, meta)].map((subset) => ({
    source: `${at}files/${id}-${subset}-${weight}-${style}.woff2`,
    unicodeRange: kitRanges()[subset],
  }));
}

/** Each file's unicode-range (a function: the kit runs after the pen's code). */
function kitRanges() {
  return {
    latin: 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,'
      + 'U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD',
    'latin-ext': 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,'
      + 'U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF',
    greek: 'U+0370-03FF',
  };
}

/** For the cjk, arabic and comics blocks: loads `faces` (as FONTS) for the
 *  sample `text`; `optional` skips a face Fontsource lacks. Files are added in
 *  the order asked, the last winning a shared character. Resolves to the count. */
async function loadFonts(faces, text = '', { optional = false } = {}) {
  kitStatus('Loading fonts…');
  const ranges = kitRanges();
  const jobs = [];
  for (const [family, specs] of Object.entries(faces)) {
    const id = fontsourceId(family);
    const todo = [...new Set(specs)].map((spec) => [parseInt(spec, 10), spec.endsWith('i') ? 'italic' : 'normal'])
      .filter(([weight, style]) => !hasFace(family, weight, style)); // before any await
    const at = fontsourceAt(id);
    const meta = optional || /[^\0-ÿ]/u.test(text) ? await fontsourceMeta(family) : null;
    const subsets = ['latin', ...kitSubsetsFor(text, meta)];
    for (const [weight, style] of todo) {
      if (optional && !(meta && (await fontsourceWeights(family, style)).includes(weight))) continue;
      for (const subset of subsets) {
        const url = `${await at}files/${id}-${subset}-${weight}-${style}.woff2`;
        const face = new FontFace(family, `url(${url}) format('woff2')`,
          { weight: String(weight), style, unicodeRange: ranges[subset] });
        jobs.push(face.load().catch(() => {
          if (subset === 'latin' && !optional) throw new Error(`Fontsource has no ${family} ${weight} ${style}`);
        }));
      }
    }
  }
  const ready = await Promise.all(jobs).catch((error) => { kitFail(error); throw error; });
  return ready.filter((face) => face && document.fonts.add(face)).length;
}

/** A loaded FontFace covers this face (fonts.check() says yes to any family). */
function hasFace(family, weight, style) {
  for (const face of document.fonts) {
    if (face.status !== 'loaded' || face.style !== style) continue;
    if (face.family.replace(/^["']|["']$/g, '') !== family) continue;
    const [low, high = low] = face.weight.split(' ').map(Number);
    if (weight >= low && weight <= high) return true;
  }
  return false;
}

/** The files beyond latin `text` needs that `meta`'s family ships. */
function kitSubsetsFor(text, meta) {
  return [[/[Ā-˿ᴀ-ᶿḀ-ỿ†ℓⱠ-Ɀ꜠-ꟿ]/u, 'latin-ext'], [/[Ͱ-Ͽ]/u, 'greek']]
    .filter(([re, x]) => re.test(text) && meta?.subsets?.includes(x)).map(([, x]) => x);
}

/** Fontsource's id for a family: 'Source Serif 4' → 'source-serif-4'. */
function fontsourceId(family) { return family.toLowerCase().replace(/\s+/g, '-'); }

/** A package's folder at the one version @5 names now (#766). */
function fontsourceAt(id, u = `https://cdn.jsdelivr.net/npm/@fontsource/${id}@`) {
  return (fontsourceAt.c ??= {})[id] ??= fetch(u + '5/package.json').then((r) => r.json())
    .then((p) => p.version || 5, () => 5).then((v) => `${u}${v}/`);
}

/** The family's Fontsource metadata (weights, styles, subsets), or null. */
function fontsourceMeta(family, id = fontsourceId(family)) {
  return (fontsourceMeta.c ??= {})[id] ??= fetch(`https://api.fontsource.org/v1/fonts/${id}`)
    .then((res) => (res.ok ? res.json() : null), () => null);
}

/** The weights the package ships in `style`: the API pairs none (no Libre
 *  Caslon 700 italic file), so italics are read from latin-italic.css. */
function fontsourceWeights(family, style, id = fontsourceId(family)) {
  return (fontsourceWeights.c ??= {})[id + style] ??= fontsourceMeta(family).then(async (m) => {
    if (!m?.styles.includes(style)) return m ? [] : [400, 700];
    const css = style === 'italic' ? await fetch(`${await fontsourceAt(id)}latin-italic.css`).then((r) => (r.ok ? r.text() : ''), () => '') : '';
    const w = [...css.matchAll(/weight: (\d+)/g)].map((x) => +x[1]);
    return w.length ? w : m.weights;
  });
}

// ─── Kit · viewer v2 ── the same in every recipe · postext.dev/cookbook
/** The pages as spreads on a dark desk, page 1 alone, then verso | recto,
 *  each painted when it scrolls near. Other options go to renderPageToCanvas. */
function showPages(docs, { title, width = 460, ...render } = {}) {
  const root = viewer(title);
  const pages = [docs].flat().flatMap((doc) =>
    doc.pages.map((page) => ({ doc, page, n: (doc.pageIndexOffset ?? 0) + page.index })));
  const spreads = [];
  let verso = null;
  for (const p of pages) {
    if (p.n % 2 === 1) { if (verso) spreads.push([verso, null]); verso = p; }
    else { spreads.push([verso, p]); verso = null; }
  }
  if (verso) spreads.push([verso, null]);
  const density = Math.min(window.devicePixelRatio || 1, 2);
  showPages.painter?.disconnect();
  const painter = new IntersectionObserver((entries) => {
    for (const { isIntersecting, target } of entries) {
      if (!isIntersecting) continue;
      painter.unobserve(target);
      const { doc, page } = target.postext;
      renderPageToCanvas(page, doc, target, { ...render, scale: (width * density) / page.width });
    }
  }, { rootMargin: '800px' });
  showPages.painter = painter;
  root.replaceChildren(...spreads.map((pair) => {
    const spread = document.createElement('div');
    spread.className = 'pt-spread';
    for (const p of pair) {
      const figure = document.createElement('figure');
      if (p) {
        const label = p.page.pageLabel || String(p.n + 1);
        const canvas = document.createElement('canvas');
        canvas.postext = p;
        canvas.style.aspectRatio = `${p.page.width} / ${p.page.height}`;
        canvas.setAttribute('role', 'img');
        canvas.setAttribute('aria-label', `Page ${label}`);
        const folio = document.createElement('figcaption');
        folio.textContent = label;
        figure.append(canvas, folio);
        painter.observe(canvas);
      } else figure.className = 'pt-blank';
      spread.append(figure);
    }
    return spread;
  }));
  kitStatus(`${pages.length} ${pages.length === 1 ? 'page' : 'pages'}`);
  document.documentElement.dataset.postext = 'ready';
  return pages.length;
}

/** The desk, the bar and the error reporting, created once. */
function viewer(title) {
  if (!document.getElementById('pt-kit')) {
    document.head.insertAdjacentHTML('beforeend', `<style id="pt-kit">
      :root { color-scheme: dark; }
      body { margin: 0; background: #0e1014; color: #b9bcc4; font: 13px/1.45 system-ui, sans-serif; }
      #pt-bar { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center;
        gap: 6px 16px; padding: 10px 16px; background: rgb(14 16 20 / .92); backdrop-filter: blur(6px);
        border-bottom: 1px solid #23262d; }
      #pt-bar strong { color: #f4f1ea; font-weight: 600; }
      #pt-actions { display: flex; gap: 12px; margin-left: auto; }
      #pt-actions a, #pt-actions button { color: #d8a21a; font: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
      #pages { display: grid; justify-items: center; gap: 48px; padding: 32px 16px 72px; }
      .pt-spread { display: flex; }
      .pt-spread figure { margin: 0; width: min(460px, 44vw); }
      .pt-spread canvas { display: block; width: 100%; background: #fff;
        box-shadow: 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figure:first-child canvas { box-shadow: inset -14px 0 14px -14px rgb(0 0 0 / .18), 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figcaption { margin-top: 10px; text-align: center; font: 600 10px/1 system-ui, sans-serif;
        letter-spacing: .18em; text-transform: uppercase; color: #6c7079; }
      .pt-blank { visibility: hidden; }
      @media (max-width: 760px) {
        .pt-spread { flex-direction: column; gap: 32px; }
        .pt-spread figure { width: min(460px, 92vw); }
        .pt-blank { display: none; }
      }
    </style>`);
    document.body.insertAdjacentHTML('afterbegin',
      '<header id="pt-bar"><strong id="pt-title"></strong><span id="pt-status" role="status"></span><span id="pt-actions"></span></header>');
    document.getElementById('pt-title').textContent = document.title || 'Postext';
    addEventListener('error', (event) => kitFail(event.error ?? event.message));
    addEventListener('unhandledrejection', (event) => kitFail(event.reason));
  }
  if (title) document.getElementById('pt-title').textContent = title;
  return document.getElementById('pages')
    ?? document.body.appendChild(Object.assign(document.createElement('main'), { id: 'pages' }));
}

function kitStatus(text) {
  viewer();
  document.getElementById('pt-status').textContent = text;
}

function kitFail(error) {
  document.documentElement.dataset.postext = 'error';
  kitStatus(`Error: ${error?.message ?? error}`);
}

// ─── Kit · images v3 ── recipes with pictures · postext.dev/cookbook
/** Registers a photo or PNG for the canvas and keeps its bytes for the PDF.
 *  fetch → ImageBitmap never taints the canvas (a plain cross-origin <img> would). */
async function loadImage(fileId, url) {
  const res = await fetch(url);
  if (!res.ok) throw new Error(`Image not found (${res.status}): ${url}`);
  const bytes = new Uint8Array(await res.arrayBuffer());
  registerResourceImage(fileId, await createImageBitmap(new Blob([bytes])));
  (loadImage.bytes ??= new Map()).set(fileId, bytes);
}

/** Registers SVG markup as a vector image, its fonts inside (inlineSvgFonts, ≥ 1.25).
 *  `options` go to registerResourceImage: { singleInk: true } tints it on the canvas. */
async function loadSvg(fileId, svg, options) {
  if (typeof inlineSvgFonts === 'function') svg = await inlineSvgFonts(svg, svgFaces);
  const img = new Image();
  img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
  await img.decode();
  registerResourceImage(fileId, img, options);
  (loadImage.bytes ??= new Map()).set(fileId, new TextEncoder().encode(svg));
}

/** A face's Fontsource files: nearest weight; latin + what the SVG sets. */
async function svgFaces(family, weight, style, { codePoints = [] } = {}) {
  const [id, m] = [fontsourceId(family), await fontsourceMeta(family)];
  const w = m?.weights.reduce((a, b) => (Math.abs(b - weight) < Math.abs(a - weight) ? b : a)) ?? weight;
  const s = m?.styles.includes(style) === false ? 'normal' : style;
  return Promise.all(['latin', ...kitSubsetsFor(String.fromCodePoint(...codePoints), m)].map(async (x) => new Uint8Array(
    await (await fetch(`${await fontsourceAt(id)}files/${id}-${x}-${w}-${s}.woff2`)).arrayBuffer())));
}

/** renderToPdf({ resourceBytes: imageBytes }) */
function imageBytes(fileId) { return loadImage.bytes?.get(fileId); }

/** renderToHtml({ resourceImageUrl: imageUrl }) */
function imageUrl(fileId) {
  const bytes = imageBytes(fileId);
  if (!bytes) return undefined;
  imageUrl.urls ??= new Map();
  if (!imageUrl.urls.has(fileId)) {
    const type = /\.svg$/i.test(fileId) ? 'image/svg+xml' : /\.png$/i.test(fileId) ? 'image/png' : 'image/jpeg';
    imageUrl.urls.set(fileId, URL.createObjectURL(new Blob([bytes], { type })));
  }
  return imageUrl.urls.get(fileId);
}

// ─── /Kit ───────────────────────────────────────────────────────────────────────
```

## Παραλλαγές

### Ανοίξτε κάθε κεφάλαιο σε δεξιά σελίδα

Με `'odd'`, το κεφάλαιο II πηγαίνει στη σελίδα 11 και η σελίδα 10 μένει λευκή· η σελίδα τίτλου απενεργοποιεί τη δική της αλλαγή σελίδας, επειδή κληρονομεί εκείνη του επιπέδου και διαφορετικά θα πήγαινε στη σελίδα 7 μετά από μια λευκή σελίδα 6.

```diff
@@ the frontispiece style @@
   id: 'frontespizio',
+  breakBefore: { enabled: false },
@@ headings, in config() @@
-    levels: [{ level: 1, breakBefore: { enabled: true, parity: 'any' } }],
+    levels: [{ level: 1, breakBefore: { enabled: true, parity: 'odd' } }],
```

## Συνήθη λάθη

- **Τιμές ιδιοτήτων: χωρίς { ή }· μονά εισαγωγικά για τιμή με ".** Μια τιμή ιδιότητας τελειώνει στο άγκιστρο κλεισίματος, οπότε δεν μπορεί να περιέχει { ή }. Μια τιμή που περιέχει διπλό εισαγωγικό μπαίνει σε μονά εισαγωγικά· το σύμβολο του δολαρίου δεν δημιουργεί πρόβλημα.

- Στο Markdown, ένα αδιάσπαστο διάστημα (U+00A0) δένει κάθε παύλα διαλόγου του Collodi με τη λέξη της, ώστε μια παύλα κλεισίματος να μην ανοίγει ποτέ γραμμή· δύο ακόμη κρατούν μαζί το *di legno* και το *in piedi* στο τέλος των παραγράφων τους. Τα δεσίματα ισχύουν και σε παράγραφο με έντονα ή πλάγια, όπως αυτή με το *ohi* στη σελίδα 9, που έχει τέσσερα.

## Ευχαριστίες

- Συνταγή: Ignacio Ferro ([@drnachio](https://github.com/drnachio))
- Κείμενο: Le avventure di Pinocchio (1883): chapter I and the opening of chapter II with Collodi’s chapter summaries, from the 1902 Bemporad edition, with typographic apostrophes, dashes and ellipses; chapter I’s summary has the comma after “falegname” that the edition’s table of contents prints and its chapter head leaves out: Carlo Collodi ([πηγή](https://www.gutenberg.org/ebooks/52484)), κοινό κτήμα
- Εικόνες: The frontispiece: Tuscan hills, a hill village and a donkey cart of firewood on its way to the carpenter’s workshop: Generated With Diffusion Models, πρωτότυπο
- Εικόνες: Chapter I’s vignette: Maestro Ciliegia, axe raised over the talking log: Generated With Diffusion Models, πρωτότυπο
- Εικόνες: Chapter II’s vignette: Geppetto in his yellow wig receives the log, beside a pot of polenta: Generated With Diffusion Models, πρωτότυπο
- Εικόνες: The cherry tailpiece: Generated With Diffusion Models, πρωτότυπο
- Γραμματοσειρές: Averia Serif Libre (OFL-1.1), Fredericka the Great (OFL-1.1), Quicksand (OFL-1.1)
- Κώδικας: MIT · Δείγμα περιεχομένου: CC-BY-4.0

## Σχετικές συνταγές

- [Αρ. 017 · Πέντε εναρκτήριες σελίδες κεφαλαίων σε ένα βιβλίο](https://postext.dev/el/cookbook/five-chapter-openers.md): Μία εναρκτήρια στο επίπεδο 1 και τέσσερα στιλ επικεφαλίδας από το Markdown· όλα αλλάζουν το χρώμα έμφασης, κάποια και περιθώρια, στήλες ή σελιδαρίθμηση. · Επίπεδο 3 (Προχωρημένο) · Οποιοδήποτε είδος
- [Αρ. 016 · Ισπανικά με πλήρη στοίχιση σε μυθιστόρημα τσέπης](https://postext.dev/el/cookbook/spanish-pocket-novel.md): Αρχή του κεφαλαίου I της Marianela σε έκδοση τσέπης: ισπανικός συλλαβισμός, κενά κάτω από 1,7×, χωρίς κοντές γραμμές, υψωμένο αρχίγραμμα, χάρτης ως Figura 1. · Επίπεδο 2 (Μεσαίο) · Πεζογραφία, θέατρο και λογοτεχνικός λόγος
- [Αρ. 003 · Εναρκτήρια σελίδα κεφαλαίου σε ταινία ως την αιμορραγία](https://postext.dev/el/cookbook/chapter-opener-bleed-band.md): Εναρκτήρια σελίδα advancedDesign στην επικεφαλίδα επιπέδου 1: ταινία ως την αιμορραγία, ο αριθμός στη βάση της, υπέρτιτλος και εισαγωγή από την επικεφαλίδα. · Επίπεδο 3 (Προχωρημένο) · Σχολικά βιβλία
