Με λίγα λόγια
Ένας ζωντανός επεξεργαστής για μια μικρή έκδοση τσέπης της «Μηχανής του χρόνου». Κάθε φορά που πληκτρολογείτε, η σελίδα σελιδοποιείται ξανά στο παρασκήνιο, ώστε η οθόνη να συνεχίζει να ανταποκρίνεται.
Τι θα στοιχειοθετήσετε
Στοιχειοθετείτε το κεφάλαιο I της Μηχανής του χρόνου του H. G. Wells ως έκδοση τσέπης 110 × 147 mm, με το Markdown δίπλα της. Η σελίδα τίτλου έχει μια φωτογραφία ενός ορειχάλκινου καντράν με τέσσερα μικρά καντράν, φτιαγμένη με μοντέλα διάχυσης, σε ένα βυσσινί πεδίο σχεδιασμένο σε κώδικα, πάνω από τον τίτλο σε Cinzel. Το κείμενο του κεφαλαίου αρχίζει στην ένατη γραμμή, κάτω από έναν λατινικό αριθμό και μια ορειχάλκινη γραμμή, και τρέχει σε Baskervville 9,5 σε 13 pt κάτω από τρέχουσες κεφαλίδες σε μικρά κεφαλαία. Κάθε πάτημα πλήκτρου στοιχειοθετεί ξανά ολόκληρο το κεφάλαιο σε έναν Web Worker, και ο καμβάς στα δεξιά γυρίζει στη σελίδα όπου βρίσκεται ο δρομέας. Κάτω από τον επεξεργαστή, ένας δείκτης που γυρίζει το κύριο νήμα σε κάθε καρέ σταματά όσο το νήμα είναι απασχολημένο, και η γραμμή κατάστασης δίνει τον χρόνο της δημιουργίας, το μακρύτερο καρέ και πόσες δημιουργίες ακύρωσε ένα νεότερο πάτημα πλήκτρου. Ένα μενού πάνω δεξιά μεταφέρει τη δημιουργία στο κύριο νήμα για σύγκριση.
Αυτή η συνταγή απαντά
- Πώς κρατώ τη σελίδα να ανταποκρίνεται όσο σελιδοποιείται ένα μεγάλο βιβλίο (Web Worker, ακύρωση);
- Γιατί αλλάζουν οι αλλαγές γραμμής μου ή επικαλύπτονται λέξεις στο PDF, και πώς φορτώνω σωστά τις γραμματοσειρές;
- Μπορώ να παράγω σελίδες ή PDF σε διακομιστή ή σε CLI (Node);
Η σύντομη απάντηση
async function startLayoutWorker(faces) {
// No options: from a CDN the engine starts its worker entry, at the page's own version,
// through a same-origin blob; in a bundle it starts the worker file next to the module.
const layout = createLayoutWorker();
// The worker measures with its own FontFaceSet, not the page's. Without the bytes of every
// face it measures in a fallback font, and the console names each missing family once.
const payloads = await Promise.all(faces.map(async ({ family, weight, style, url }) => {
// Check the status: a 404 page sent as a font only logs a warning inside the worker.
const response = await fetch(url);
if (!response.ok) throw new Error(`${family} ${weight} ${style}: HTTP ${response.status}`);
return { family, weight, style, buffer: await response.arrayBuffer() };
}));
await layout.registerFonts(payloads); // the buffers move to the worker, not copied
let inFlight = null;
return async function typeset(content) {
inFlight?.abort(); // cancel the build that the previous keystroke asked for
const build = (inFlight = new AbortController());
try {
return await layout.build(content, config(), { signal: build.signal });
} catch (error) {
if (error.name === 'AbortError') return null; // superseded: a newer build is on its way
throw error;
}
};
}
Υλικά
- Λειτουργίες
- Σελιδοποίηση σε Web WorkerΓραμματοσειρές πριν από τη σελιδοποίησηΣελίδες σε καμβάΔιάσταση σελίδαςΣυμμετρικά περιθώριαΓράμματα κυρίως κειμένουΚεφάλαια που ανοίγουν σε δεξιά σελίδαΣχεδιασμένες εναρκτήριες σελίδεςΑριθμημένες επικεφαλίδεςΣτιλ επικεφαλίδωνΚεφάλαια χωρίς αρίθμησηΤρέχουσες κεφαλίδες ανά ενότηταΤρέχουσες κεφαλίδες και αριθμοί σελίδαςΚεφαλίδες ανά ρόλο σελίδαςΕικόνες στις σχεδιάσεις σελίδαςΕικόνες και πίνακες ως πόροιΣτιλ παραγράφωνΧρώμα χαρτιούΡητό κατακόρυφο διάστημα
- Χρησιμοποιεί επίσης
- Ιδιότητες επικεφαλίδων
- Γραμματοσειρές
- Baskervville, Baskervville SC, Cinzel (SIL OFL 1.1)
- Αρχεία
dial-1120.jpg- The title page’s brass dial, a photograph (Generated With Diffusion Models, πρωτότυπο)
- The title page’s oxblood cloth and gilt frame, drawn in code in the page’s palette (Ignacio Ferro, MIT)
Προετοιμασία
#1 · Ξεκινήστε τον worker με μία κλήση
Ο κώδικας αυτού του βήματος βρίσκεται στη σύντομη απάντηση παραπάνω. Το createLayoutWorker() δεν παίρνει επιλογές. Όταν η ενότητα (module) έρχεται από το esm.sh, το αρχείο του worker βρίσκεται στην προέλευση του esm.sh, όπου ο κατασκευαστής Worker το απορρίπτει, οπότε η μηχανή ξεκινά την είσοδο του worker της μέσα από ένα blob της ίδιας προέλευσης, στην έκδοση που εισήγαγε η σελίδα. Σε μια εφαρμογή με bundler, η ίδια κλήση ξεκινά το αρχείο του worker δίπλα στην ενότητα. Το build() του χειριστηρίου παίρνει το ίδιο περιεχόμενο και την ίδια διαμόρφωση με το buildDocument() και επιστρέφει το ίδιο είδος εγγράφου (Σελιδοποίηση σε Web Worker).
#2 · Φορτώστε κάθε γραμματοσειρά δύο φορές
const FONTS = { // every face the pages use: the page loads them, and so must the worker
Baskervville: ['400', '400i'], // text, folios, subtitle, colophon
'Baskervville SC': ['500'], // running heads, the author
Cinzel: ['700'], // title, numeral, chapter title
};
// The worker gets the same Fontsource files the page loads: identical metrics on both threads.
const faces = Object.entries(FONTS).flatMap(([family, specs]) => specs.map((spec) => {
const [id, weight, style] = [family.toLowerCase().replace(/ /g, '-'), parseInt(spec, 10),
spec.endsWith('i') ? 'italic' : 'normal'];
const file = `${id}@5/files/${id}-latin-${weight}-${style}.woff2`;
return { family, weight: String(weight), style,
url: `https://cdn.jsdelivr.net/npm/@fontsource/${file}` };
}));
Ο worker έχει δικό του FontFaceSet και δεν βλέπει τις γραμματοσειρές που έχει φορτώσει η σελίδα, οπότε η σύντομη απάντηση φέρνει τα ίδια αρχεία του Fontsource και περνά τα bytes τους στο registerFonts(), με κάθε βάρος ως συμβολοσειρά ('400'). Αν παραλείψετε αυτή την κλήση, ο worker μετρά με μια εφεδρική γραμματοσειρά: στοιχειοθετεί το κεφάλαιο σε 175 γραμμές αντί για 190, η πρώτη γραμμή τελειώνει στο «him)» αντί για «of», και η κονσόλα της σελίδας αναφέρει μία φορά κάθε οικογένεια που λείπει. Ένα αρχείο γραμματοσειράς που αποτυγχάνει να κατέβει φαίνεται δυσκολότερα. Αν ο worker λάβει μια σελίδα 404 στη θέση της όρθιας Baskervville, το registerFonts() ολοκληρώνεται κανονικά και το κεφάλαιο βγαίνει σε 186 γραμμές, με προειδοποίηση μόνο στην κονσόλα του worker. Γι’ αυτό η σύντομη απάντηση ελέγχει την κατάσταση κάθε απόκρισης πριν στείλει οποιοδήποτε byte, και πετά σφάλμα με τη γραμματοσειρά και την κατάσταση HTTP. Η σελίδα φορτώνει επίσης τις ίδιες γραμματοσειρές με το loadFonts(), επειδή ο καμβάς βάφει με τις γραμματοσειρές της σελίδας.
#3 · Δημιουργία σε κάθε πάτημα πλήκτρου, βαφή στο κύριο νήμα
let [doc, shown, builds, cancelled] = [null, 0, 0, 0];
// For the comparison, the main thread keeps a measurement cache between keystrokes, as the
// worker does: both threads then time a build that measures only what changed.
const mainCache = createMeasurementCache();
function paint(n = shown) { // the canvas is sized to its box, in device pixels
shown = Math.max(0, Math.min(doc.pages.length - 1, n));
const vdtPage = doc.pages[shown]; // a laid-out page, not the page config above
const height = ($('proof').clientHeight || 640) * Math.min(devicePixelRatio || 1, 2);
renderPageToCanvas(vdtPage, doc, $('proof'), { scale: height / vdtPage.height });
$('proof').setAttribute('aria-label', `Page ${vdtPage.pageLabel}`);
$('folio').value = `${shown + 1} / ${doc.pages.length}`;
}
function follow() { // turn to the page that holds the caret: every block keeps its source offset
const caret = $('source').selectionStart;
paint(doc.pages.findLastIndex((vdtPage) => vdtPage.columns.some((column) =>
column.blocks.some((block) => block.sourceStart <= caret))));
}
async function refresh() {
const [ticket, onMain, started] = [++builds, $('thread').value === 'main', performance.now()];
frames.worst = 0;
const content = { markdown: $('source').value, resources };
const next = onMain ? buildDocument(content, config(), mainCache) : await typeset(content);
await new Promise(requestAnimationFrame); // the first frame after the build shows any stall
if (!next || ticket !== builds) { cancelled++; return; } // a newer build has been asked for
doc = next;
if (document.activeElement === $('source')) follow(); else paint();
showPages(doc, { title: 'The Time Machine · chapter I, set in a Web Worker' });
$('clock').value = `${onMain ? 'Main thread' : 'Worker'} · ${doc.pages.length} pages in `
+ `${Math.round(performance.now() - started)} ms · longest frame ${Math.round(frames.worst)}`
+ ` ms · ${builds} ${builds === 1 ? 'build' : 'builds'}, ${cancelled} cancelled`;
}
$('source').addEventListener('input', refresh);
for (const type of ['click', 'keyup']) $('source').addEventListener(type, () => doc && follow());
$('thread').addEventListener('change', refresh);
$('prev').addEventListener('click', () => paint(shown - 1));
$('next').addEventListener('click', () => paint(shown + 1));
// A dial the main thread turns on every frame: it stops while that thread is busy.
const frames = { last: 0, worst: 0 };
requestAnimationFrame(function turn() { // the clock, not the frame's timestamp: a late frame
const now = performance.now(); // keeps the time it was due, which hides the stall
frames.worst = Math.max(frames.worst, now - (frames.last || now));
frames.last = now;
const deg = ((now * 0.06) % 360).toFixed(1); // a turn in 6 s
$('hand').setAttribute('transform', `rotate(${deg})`);
requestAnimationFrame(turn);
});
await refresh();
Το typeset() διακόπτει τη δημιουργία που βρίσκεται σε εξέλιξη πριν ζητήσει την επόμενη. Η υπόσχεση (promise) της διακομμένης δημιουργίας απορρίπτεται αμέσως με ένα AbortError, που το typeset() μετατρέπει σε null. Στον worker, μια δημιουργία που περιμένει ακόμη στην ουρά απορρίπτεται αμέσως, και μια που τρέχει σταματά στο τέλος του τρέχοντος περάσματος τοποθέτησης, επειδή η δημιουργία ελέγχει για ακύρωση μόνο ανάμεσα στα περάσματα. Το refresh() αριθμεί τις δημιουργίες του και βάφει μόνο τη νεότερη, ώστε μια δημιουργία του worker που φτάνει αργά να μη βάψει πάνω σε μια του κύριου νήματος. Το έγγραφο επιστρέφει στο κύριο νήμα, όπου το renderPageToCanvas() το βάφει με τις εικόνες που είναι καταχωρισμένες εκεί. Ο worker χρειάζεται μόνο το μέγεθος κάθε εικόνας, που το φέρει η καταχώριση του πόρου (1100 × 840). Κάθε μπλοκ κρατά τη θέση του στο Markdown (sourceStart), και το follow() δείχνει την τελευταία σελίδα με μπλοκ που αρχίζει στον δρομέα ή πριν από αυτόν.
#4 · Μια σελίδα τίτλου που είναι στιλ επικεφαλίδας
// # The Time Machine {style="title"}: numbered false, so the Introduction is still chapter I.
const PLATE = TRIM.width * (840 / 1100); // mm: the plate's depth at full width (84 mm)
const DIAL = { x: 20, y: 7, size: 70 }; // mm: the dial's photograph, centred on the plate
const titlePage = {
id: 'title', numbered: false,
span: 'page', // the author's name stands below the column's foot, which would cut it
header: { elements: [] }, footer: { elements: [] }, // no running head, no folio
advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'image', id: 'plate', resourceId: 'plate',
placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { width: 'fill' } } },
{ kind: 'image', id: 'dial', resourceId: 'dial', placement: { anchor: { to: 'bleed',
edge: 'top-left' }, offset: { x: mm(DIAL.x), y: mm(DIAL.y) },
size: { width: mm(DIAL.size), height: mm(DIAL.size) } } },
text('title', '{titleText}', DISPLAY, 28, { fontWeight: 700, lineHeight: 1.04,
overflow: 'wrap' }, // the title takes two lines
onPage(PLATE + 11)),
text('subtitle', '{subtitle}', TEXT, 12, { italic: true, color: col('oxblood') },
onPage(PLATE + 34.5)),
brassRule('rule', onPage(PLATE + 43), 12),
text('author', '{author}', LABEL, 10, { fontWeight: 500, letterSpacing: pt(2) },
onPage(PLATE + 46.5)),
] } },
};
Η γραμμή # The Time Machine {style="title"} στοιχειοθετεί τη σελίδα 1 στο στιλ επικεφαλίδας title, του οποίου τα κενά header και footer αφήνουν τη σελίδα χωρίς τρέχουσες κεφαλίδες και αριθμό σελίδας. Το numbered: false κρατά τον τίτλο έξω από τη μέτρηση των κεφαλαίων, οπότε η «Introduction» είναι ακόμη το κεφάλαιο I. Η εικόνα αγκυρώνεται στην πάνω αριστερή γωνία της αιμορραγίας, και το όνομα του συγγραφέα στοιχειοθετείται κάτω από το τέλος της στήλης. Μια σχεδίαση που μένει στη στήλη της κόβεται στο κάτω άκρο της στήλης, γι’ αυτό το στιλ ορίζει span: 'page'· χωρίς αυτό, το όνομα του συγγραφέα δεν βάφεται.
#5 · Τρέχουσες κεφαλίδες ανάλογα με τον ρόλο της σελίδας
// pages: 'body' keeps the heads off the title page and the opener; parity puts the book's
// title on the verso and the chapter on the recto, folios on the outer edge.
const HEAD_Y = 8.2; // mm from the top edge to the top of the running heads
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre is off the page's centre
const head = (id, content, parity, edge, x, style) => ({ kind: 'text', id, content, parity,
pages: 'body', fontSize: pt(8), color: col('oxblood'), ...style,
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(HEAD_Y) } } });
const smallCaps = { fontFamily: LABEL, fontWeight: 500, letterSpacing: pt(1.2) };
const folio = { fontFamily: TEXT, color: col('ink') }; // the heads' size: the same baseline
const header = { elements: [
head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folio),
head('verso-title', '{title}', 'even', 'top', -SHIFT, smallCaps),
head('recto-chapter', '{chapterTitle}', 'odd', 'top', SHIFT, smallCaps),
head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folio),
] };
const footer = { elements: [{ ...text('drop-folio', '{pageNumber}', TEXT, 8,
{ color: col('muted') }, inColumn(6.5)), pages: 'opener' }] };
Το pages: 'body' κρατά τις τρέχουσες κεφαλίδες έξω από τη σελίδα τίτλου και την εναρκτήρια σελίδα, και το parity βάζει τον τίτλο του βιβλίου στις αριστερές σελίδες και του κεφαλαίου στις δεξιές, με τους αριθμούς σελίδας στην εξωτερική άκρη. Η εναρκτήρια σελίδα παίρνει αντί γι’ αυτό έναν αριθμό σελίδας στο κάτω μέρος, από ένα στοιχείο υποσέλιδου με pages: 'opener'. Οι αριθμοί σελίδας και οι κεφαλίδες είναι όλοι 8 pt και κρέμονται 8,2 mm κάτω από το πάνω άκρο, ώστε τα ψηφία του αριθμού σελίδας να στέκονται στη γραμμή βάσης των κεφαλίδων.
#6 · Η εναρκτήρια σελίδα του κεφαλαίου
const chapter = { level: 1, numberingTemplate: '{1:I}', // {number} prints 'I'
breakBefore: { enabled: true, parity: 'any' }, // the next page, on either side
marginTop: pt(0), marginBottom: pt(0),
advancedDesign: { enabled: true, minHeight: line(8), slot: { elements: [
text('numeral', '{number}', DISPLAY, 24, { fontWeight: 700, color: col('oxblood') },
inColumn(5)),
brassRule('rule', inColumn(18.5), 10),
text('chapter', '{titleText}', DISPLAY, 12, { fontWeight: 700, letterSpacing: pt(1.8),
textTransform: 'uppercase', overflow: 'wrap' }, inColumn(22.5)), // a longer title wraps
] } } };
const colophon = { id: 'colophon', fontSize: pt(7.5), lineHeight: pt(10.5), color: col('muted'),
textAlign: 'center', firstLineIndent: pt(0) };
Το {number} της σχεδίασης τυπώνει τον αριθμό του κεφαλαίου στη μορφή που του δίνει το numberingTemplate: '{1:I}', ένα λατινικό I. Το minHeight κρατά τουλάχιστον οκτώ γραμμές, ώστε το κείμενο να αρχίζει στην ένατη όταν ο τίτλος πιάνει μία ή δύο γραμμές, και πιο κάτω όταν ένας μακρύτερος τίτλος χρειάζεται περισσότερο χώρο. Το breakBefore με parity: 'any' αφήνει το κεφάλαιο να ανοίξει στη σελίδα 2, απέναντι από τη δεύτερη σελίδα του· η προεπιλογή θα το έστελνε στη σελίδα 3, μια δεξιά σελίδα.
Η πλήρης συνταγή
// ═══ Postext Cookbook · Nº 056 · Live editor with layout in a Web Worker ═══════════
// https://postext.dev/en/cookbook/web-worker-live-editor
// Code: MIT · Text: H. G. Wells, The Time Machine, 1895 (PD, Gutenberg #35) · Dial: generated
// Fonts: Baskervville, Baskervville SC, Cinzel (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocument, createMeasurementCache, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { createLayoutWorker } from 'https://esm.sh/postext/worker';
const LANG = 'en'; // @lang: the language of the sample document (this recipe is English only)
const RECIPE = 'web-worker-live-editor';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config links to one of these
ink: '#231f1a', // the text: a warm near-black
oxblood: '#7a1f1f', // the accent: running heads, the numeral, the subtitle, the plate's cloth
brass: '#a88a4a', // rules (never text: 2.7:1 on the paper)
gilt: '#d8bd7c', // the plate's frame, on the oxblood
muted: '#6b5d4b', // the drop folio and the colophon (5.3:1 on the paper)
paper: '#f2ead8', // a cream pocket-book paper
};
// Each colour names its palette entry and carries its hex.
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 engine's defaults link to 'main-color'. The editor takes any Markdown, and without this
// entry a list typed into it gets the default blue markers.
{ id: 'main-color', name: 'oxblood (defaults)', value: { hex: palette.oxblood, model: 'hex' } },
];
const [TEXT, LABEL, DISPLAY] = ['Baskervville', 'Baskervville SC', 'Cinzel'];
// The page: 110 × 147 mm, a text block of 25 whole lines.
const TRIM = { width: 110, height: 147 }; // mm: a Victorian pocket size, close to A6
const [BODY, LEAD, LINES] = [9.5, 13, 25]; // pt, pt, lines: the text block is LINES leads deep
const [TOP, INNER, OUTER] = [15, 11, 9]; // mm; mirrored, so INNER is the spine side
const MM_PER_PT = 25.4 / 72;
const MEASURE = TRIM.width - INNER - OUTER; // 90 mm: about 60 characters of Baskervville
const line = (n) => pt(n * LEAD); // n grid lines
const page = {
sizePreset: 'custom', width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150,
backgroundColor: col('paper'),
margins: { top: mm(TOP), bottom: mm(TRIM.height - TOP - LINES * LEAD * MM_PER_PT),
left: mm(INNER), right: mm(OUTER), mirror: true },
};
const onPage = (y) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) } }); // centred
const inColumn = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });
const text = (id, content, fontFamily, fontSize, style, placement) => ({ kind: 'text', id,
/* The editor: the Markdown on the left, the page it sets on the right, on a walnut desk. */
#editor {
--desk: #1c1814; --well: #120f0c; --text: #e4d9c1; --dim: #a39680; --brass: #c9a75e;
display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto 1fr auto;
gap: 0 30px; box-sizing: border-box; width: min(1152px, 100% - 32px); margin: 24px auto 0;
padding: 0 30px; background: var(--desk); border-radius: 14px;
box-shadow: 0 0 0 1px #2c261f, 0 30px 60px -30px rgb(0 0 0 / .9);
font: 500 12px/1.4 system-ui, sans-serif; color: var(--dim);
}
#editor > header, #editor > footer {
grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; min-height: 58px;
letter-spacing: .12em; text-transform: uppercase;
}
#editor > header { justify-content: space-between; }
#editor select {
margin-left: 8px; padding: 5px 8px; border: 1px solid #3a3229; border-radius: 6px;
background: var(--well); color: var(--text); font: inherit; letter-spacing: .06em;
}
#source {
box-sizing: border-box; width: 100%; height: 100%; min-height: 360px; resize: none;
padding: 20px 22px; border: 0; border-radius: 8px; outline: 1px solid #2c261f;
background: var(--well); color: var(--text); caret-color: var(--brass);
font: 13.5px/1.7 ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
scrollbar-width: thin; scrollbar-color: #3a3229 transparent;
}
#source:focus { outline-color: var(--brass); }
#source::selection { background: rgb(201 167 94 / .35); }
#editor figure { margin: 0; display: flex; flex-direction: column; align-items: center; }
/* The page at 110 × 147 mm, as tall as the desk allows. */
#proof {
display: block; height: min(700px, 100vh - 170px); aspect-ratio: 110 / 147; background: #f2ead8;
box-shadow: 0 1px 2px rgb(0 0 0 / .6), 0 24px 44px -18px rgb(0 0 0 / .9);
}
#editor figcaption { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
#editor figcaption button {
width: 30px; height: 30px; border: 1px solid #3a3229; border-radius: 50%; padding: 0;
background: none; color: var(--text); font: 16px/1 system-ui, sans-serif; cursor: pointer;
}
#editor figcaption button:hover { border-color: var(--brass); color: var(--brass); }
#folio { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
#editor > footer { color: var(--text); font-variant-numeric: tabular-nums; }
/* The heartbeat: a hand the main thread turns every frame. */
#beat { width: 24px; height: 24px; flex: none; }
#beat circle { fill: none; stroke: var(--brass); stroke-width: 1.5; }
#beat path { stroke: var(--brass); stroke-width: 2; stroke-linecap: round; }
@media (max-width: 760px) {
#editor { grid-template-columns: 1fr; padding: 0 16px; gap: 0; }
#editor > header { flex-direction: column; align-items: flex-start; padding: 14px 0; }
Το συντεθειμένο script.js εκτελείται ως έχει: επικολλήστε το στο module script οποιασδήποτε σελίδας ή ανοίξτε τη συνταγή στο CodePen. Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)
Συνήθη λάθη
Συνηθισμένο λάθος
Ο worker διάταξης μετρά με τις δικές του γραμματοσειρές
Ένας worker έχει δικό του FontFaceSet, οπότε οι μορφές που έχει φορτώσει η σελίδα είναι αόρατες γι' αυτόν. Στείλτε του τα bytes κάθε μορφής με το registerFonts() πριν από την πρώτη κατασκευή· το βάρος μπορεί να είναι συμβολοσειρά ('400') ή, από το postext 1.5, αριθμός. Χωρίς αυτά ο worker μετρά με εφεδρική γραμματοσειρά και αλλάζουν οι αλλαγές γραμμής και ο αριθμός σελίδων· από την 1.5 η κονσόλα το αναφέρει, μία φορά για κάθε οικογένεια που λείπει. Σελιδοποίηση σε Web Worker →
Ευχαριστίες
- Συνταγή
- Ignacio Ferro
- Κείμενο
- The Time Machine, chapter I · H. G. Wells · κοινό κτήμα
- Εικόνες
- The title page’s brass dial, a photograph · Generated With Diffusion Models · πρωτότυπο
- The title page’s oxblood cloth and gilt frame, drawn in code in the page’s palette · Ignacio Ferro · MIT
- Γραμματοσειρές
- Baskervville (SIL OFL 1.1) · Baskervville SC (SIL OFL 1.1) · Cinzel (SIL OFL 1.1)
- Κώδικας
- MIT, όπως το Postext
Επεξεργασία αυτού του κειμένου ↗ (ανοίγει σε νέα καρτέλα)Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)


