En poques paraules
Un cartell de xerrades d'astronomia abans d'un eclipsi de sol. Ensenya a col·locar cada element mesurant des de la vora de la pàgina o des d'un altre element.
Què compondràs
Cartell d'un club d'astronomia fictici per a quatre xerrades, els dijous d'abril, abans de l'eclipsi total de Sol del 2 d'agost de 2027. Un cel blau ultramar omple els dos terços superiors d'un A3. Una Lluna negra tapa un Sol groc llimona tallat per la vora dreta, i darrere de tots dos s'estén una corona dibuixada amb codi. El títol, Vuelve la sombra en Funnel Display de 120 pt, es recolza en la seva entradeta al peu del cel. Sota l'horitzó, quatre dates blaves encapçalen les xerrades, i la lletra petita va a dues columnes sobre una banda blava. Cada element penja de la sang, de la pàgina, de la seva ranura o d'un altre, i els seus desplaçaments es mesuren des d'allà. El segon full emmarca en rosa la caixa de cada element i els contenidors de capçalera i peu, i retola tretze elements amb el seu ancoratge.
Aquesta recepta respon a
- Com col·loco els elements de disseny respecte a la pàgina, la sang o entre si, en lloc de per coordenades?
- Com afegeixo una marca d'aigua, un fons de color o una imatge decorativa a totes les pàgines?
La resposta curta
const SKY = 272; // mm from the trim's top edge to the horizon, the sky's lower edge
const INSET = BLEED + MARGIN; // from the bleed's edge to the text's edge
const AIR = 14; // mm between the standfirst and the horizon
const poster = () => ({ enabled: true, slot: { elements: [ // array order is paint order
// 'bleed' and 'page' are frames of the sheet; 'container' would be this heading's own box.
{ kind: 'box', id: 'sky', style: { backgroundColor: col('sky') }, // no width: fills the bleed
placement: at('bleed', 'top-left', 0, 0, { height: mm(BLEED + SKY) }) },
...eclipse(), // the Sun hangs from the trim's corner, the Moon and the corona from the Sun
// The headline stands on the horizon and grows upwards: 'above' puts an element's
// bottom-left corner on the top-left corner of its anchor, so a longer title lifts the kicker.
text('deck', '{attr.deck}', FACE.deck, { ...at('#sky', 'align-bottom', INSET, -AIR),
size: { maxWidth: mm(153) } }), // shrink-wraps its lines, but wraps at 153 mm
text('title', '{titleText}', FACE.title, at('#deck', 'above', 0, -9)), // breaks at the \\
text('kicker', '{attr.kicker}', FACE.kicker, at('#title', 'above', 0, -7)),
...programme(), // four columns chained off the horizon
] } }); // hook-up: headings.levels[0] = { span: 'page', breakBefore, advancedDesign: poster() }
// {titleText} is the heading's text; each {attr.*} is written on its line in content.md.
Ingredients
- Funcions
- Ancoratge d'elements de dissenyTextos, filets i caixes als dissenys de pàginaImatges als dissenys de pàginaObertures dissenyadesBanda de capítol d'amplada completaBandes a sang i pestanyesEstils de títolCapçaleres per seccióAtributs de títolSalts de línia als títolsPaleta de color semànticaEstils de paràgrafFigures i taules com a recursosPàgines en un canvas
- També fa servir
- Sang i marques de tall
- Tipografia
- Funnel Display, Funnel Sans, Martian Mono (SIL OFL 1.1)
- Recursos
- Cap: totes les imatges es dibuixen en codi
Elaboració
#1 · Ancora dos elements al full i penja-hi els altres
El codi és la resposta curta de dalt. En aquest codi, anchor.to diu de què penja un element: 'bleed' i 'page' són marcs del full (la mateixa caixa mentre page.cutLines estigui desactivat), 'container' és la caixa de la ranura mateixa i '#id' és un altre element (posicionament d'elements). Una caixa sense amplada arriba fins a la vora oposada del seu marc, de manera que el cel ocupa la sang d'un costat a l'altre. Un element col·locat respecte al cel es mesura des de la vora esquerra del cel, que és la de la sang; per això la x de l'entradeta és INSET, 18 mm. El titular es munta de baix a dalt des de la vora inferior del cel. 'align-bottom' deixa la base de la caixa de l'entradeta AIR, 14 mm, per sobre d'aquesta vora, i 'above' recolza cada element sobre el de sota, de manera que un títol amb més línies fa pujar l'avanttítol en comptes de trepitjar l'entradeta. Sota el disseny, la lletra petita comença a la primera línia de la retícula de base de 16 pt que queda com a mínim 3,2 mm per sota de l'element més baix, la línia dels ponents; aquests 3,2 mm són el marge inferior que el títol porta per defecte.
#2 · Penja la Lluna i la corona del Sol
const SUN = 150; // mm across; the Moon is drawn the same size
const CORONA = 300; // mm, the square picture of the corona
const HALO = (CORONA - SUN) / 2; // how far the corona reaches past the Sun on every side
const BITE = { x: 2, y: 2.5 }; // mm the Moon sits off the Sun: a sliver is left at upper left
const disc = (id, colour, placement) => ({ kind: 'box', id, placement: { ...placement,
size: square(SUN) }, style: { backgroundColor: col(colour), borderRadius: mm(SUN / 2) } });
const eclipse = () => [
{ kind: 'image', id: 'corona', resourceId: 'corona', // listed before the discs: painted behind
placement: at('#sun', 'align-top', -HALO, -HALO, square(CORONA)) },
disc('sun', 'sun', at('page', 'top-right', 30, 25)), // 30 mm of it past the right edge
disc('moon', 'ink', at('#sun', 'align-top', BITE.x, BITE.y)),
];
El Sol és l'únic element ancorat a la pàgina, que és la caixa de tall. Comptada des de la cantonada 'top-right', una x positiva surt per la vora dreta, i 30 mm del disc queden fora. La Lluna i la corona pengen del Sol amb 'align-top', així que es mouen amb ell. Els seus desplaçaments es compten des de la cantonada superior esquerra del Sol: la Lluna es desplaça 2 mm a la dreta i 2,5 mm cap avall, cosa que deixa un fil de Sol a dalt a l'esquerra, i la corona comença HALO, 75 mm, més amunt i més a l'esquerra, cosa que centra el seu quadrat de 300 mm sobre el disc de 150 mm. La corona és un element d'imatge que pren la mida de la seva caixa (elements d'imatge) i va a la llista abans que els discos per pintar-se darrere seu.
#3 · Encadena les quatre tardes en columnes
const GUT = 7; // mm between the evenings, and between the two columns of text under them
const COL = (A3.width - 2 * MARGIN - 3 * GUT) / 4; // four columns across the text width: 60 mm
const DROP = 12; // mm from the horizon to the dates
const programme = () => [1, 2, 3, 4].flatMap((n) => [
text(`day${n}`, `{attr.d${n}}`, FACE.day, n === 1
? at('#sky', 'below', INSET, DROP, wide(COL)) // the first date hangs from the horizon
: at(`#day${n - 1}`, 'right-of', GUT, 0, wide(COL))), // the others from the one before
text(`talk${n}`, `{attr.t${n}}`, FACE.talk, at(`#day${n}`, 'below', 0, 3, wide(COL))),
text(`who${n}`, `{attr.s${n}}`, FACE.who, at(`#talk${n}`, 'below', 0, 2.5, wide(COL))),
]);
Cada data, xerrada i ponent té un size.width fix de COL, i 'right-of' més GUT posa la data següent una columna més enllà. Sense amplada, una data s'ajusta a les seves xifres (el «8» fa 17 mm), així que el «15» començaria 7 mm després i cada xerrada correria en una sola línia fins a ficar-se a la columna següent. COL reparteix l'amplada del text entre quatre amb el mateix espai entre columnes de 7 mm que les dues columnes de lletra petita de sota, de manera que la segona columna de lletra petita comença sota el 22. Cada xerrada penja 'below' de la seva data i cada ponent de la seva xerrada, de manera que una xerrada que ocupés tres línies faria baixar el seu ponent i cap altre.
#4 · Porta la banda al peu, a totes les pàgines
const MARK = 10; // mm, the club's mark
const PAD = (FOOT - MARK) / 2; // centres the mark in the bottom margin
const markTall = { height: mm(MARK) }; // as tall as the mark: the line is centred on it
const footer = { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('sky') }, // the bottom margin, bled
placement: at('bleed', 'bottom-left', 0, 0, { height: mm(BLEED + FOOT) }) },
// The container runs from the text down to the trim: 'bottom-*' counts up, 'top-*' down.
{ kind: 'image', id: 'mark', resourceId: 'mark',
placement: at('container', 'bottom-left', 0, -PAD, square(MARK)) },
text('club', '{attr.club}', FACE.foot, at('#mark', 'right-of', 3, 0, markTall)),
text('free', '{attr.free}', FACE.foot, at('container', 'top-right', 0, PAD, markTall)),
] };
El que hagi de sortir a totes les pàgines, com aquesta banda, va a la ranura de la capçalera o del peu, i un estil de títol amb capçalera o peu propis la substitueix a les pàgines de la seva secció. El peu de l'estil de les guies repeteix aquests quatre elements amb els seus marcs i les seves etiquetes; per això la banda i l'emblema surten als dos fulls. El contenidor del peu és el marge inferior, del text al tall: 'bottom-left' compta cap amunt des del tall i 'top-right' cap avall des del text, i el −10 de l'emblema i el +10 de la línia «Entrada libre» cauen a la mateixa franja de 10 mm, al mig de la banda (capçaleres i peus). El peu es pinta després del text i no li treu lloc, de manera que FOOT és alhora el marge inferior i l'alçada de la banda, que així mai no trepitja les línies de sobre.
#5 · Dibuixa les línies de construcció des de la mateixa configuració
const GUIDE = { borderColor: col('guide'), borderWidth: pt(1) };
const signed = ({ value }) => `${value < 0 ? '−' : '+'}${Math.abs(value)}`; // all offsets in mm
const describe = ({ id, placement: { anchor: { to, edge }, offset = {} } }) => [`#${id}`,
`${edge} ${to}`, // the two words of anchor: { to, edge }
['x', 'y'].filter((k) => offset[k]?.value).map((k) => `${k} ${signed(offset[k])}`).join(' '),
].filter(Boolean).join(' · ');
// A border never changes an element's size (padding does), so each frame traces its box.
// An image or a rounded box gets a square frame of its size, hung from its top-left corner.
const frame = (el) => (el.kind === 'text' ? [{ ...el, box: { ...el.box, ...GUIDE } }]
: el.kind === 'box' && !el.style.borderRadius ? [{ ...el, style: { ...el.style, ...GUIDE } }]
: [el, { kind: 'box', id: `${el.id}-box`, style: GUIDE,
placement: at(`#${el.id}`, 'align-top', 0, 0, el.placement.size) }]);
const tag = (el, [edge, x = 0, y = 0, note]) => text(`${el.id}-tag`, note ?? describe(el),
face('Martian Mono', 8.5, 500, 'ink', { box: { backgroundColor: col('guide'),
padding: { top: pt(1.6), bottom: pt(1.2), left: pt(3), right: pt(3) } } }),
at(`#${el.id}`, edge, x, y));
const guides = (elements, tags) => [...elements.flatMap(frame),
...elements.filter((el) => tags[el.id]).map((el) => tag(el, tags[el.id]))];
const container = (id) => ({ kind: 'box', id, style: GUIDE, // the slot's own box, drawn
placement: at('container', 'top-left', 0, 0, { width: 'fill', height: 'fill' }) });
const TAGS = { // where each tag sits against its element: [edge, x, y, text]
sky: ['align-bottom', INSET, -3], corona: ['align-bottom', 90, -2], sun: ['above'],
moon: ['below', 20, 2], kicker: ['above'], title: ['above'], deck: ['above'],
day1: ['above', 0, -6], day2: ['above'], who1: ['below'],
mark: ['above', 0, -2], club: ['above', 69, -2], free: ['above', -30, -2],
header: ['align-bottom', 0, -2, t({ en: 'header container', es: 'contenedor de la cabecera' })],
footer: ['align-bottom', 0, -2, t({ en: 'footer container', es: 'contenedor del pie' })],
};
guides() recorre els elements del cartell. Un text rep una vora a la seva caixa, i una caixa quadrada, una vora al seu estil; cap de les dues no mou res, perquè només el padding fa més gran una caixa. Una imatge o un disc rodó rep una caixa quadrada de la mateixa mida penjada de la seva cantonada superior esquerra, així que també queda dibuixada la cantonada del Sol de la qual pengen la Lluna i la corona. Cada etiqueta és un text penjat del seu element i escrit per describe() a partir del placement d'aquest element, de manera que cap etiqueta no pot contradir la configuració que retola. {style="guides"} al segon títol porta aquest disseny, amb una capçalera i un peu propis (estils de capçalera). Una etiqueta sense amplada només disposa de l'espai entre la seva àncora i la vora dreta del contenidor; per això l'etiqueta de #free comença 30 mm a l'esquerra del seu text. pageIndexOffset: 1, a la continuation del contingut, converteix el cartell en pàgina parella, i així el visor posa els dos fulls l'un al costat de l'altre.
La recepta completa
// ═══ Postext Cookbook · Nº 029 · Anchoring cheat sheet: a poster built from chained elements ═══ // https://postext.dev/en/cookbook/anchoring-cheat-sheet // Code: MIT · Text: original (CC BY 4.0) · Drawings: generated in code (CC BY 4.0) // Fonts: Funnel Display, Funnel Sans, Martian Mono (SIL OFL 1.1) · Needs postext ≥ 1.4.1 // An A3 poster whose elements hang from the bleed, the page, their slot or one another, never // from coordinates; the second sheet is the same poster with each element framed and tagged. import { buildDocument, renderPageToCanvas, clearMeasurementCache, registerResourceImage, } from 'https://esm.sh/postext'; const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es') const RECIPE = 'anchoring-cheat-sheet'; // ─── 1 · Design ───────────────────────────────────────────────────────────── const palette = { ink: '#0b0b0c', // text, and the Moon sky: '#1b3bff', // the sky, the foot band and the dates sun: '#ffe53b', // the Sun and the kicker paper: '#ffffff', // type on the sky muted: '#5c5f66', // speakers and the colophon guide: '#ff2d9b', // frames and tags on the construction sheet }; // col(id): a palette-linked colour that also carries its hex, because 1.4.1 paints design // elements from the hex (gotcha: palette-skips-designs). 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' } })), { id: 'main-color', name: 'sky (defaults)', value: { hex: palette.sky, model: 'hex' } }, ]; const A3 = { width: 297, height: 420 }; // mm, the trim const MARGIN = 18; // mm at the top and sides: the body's edges, and the header container's const FOOT = 30; // mm, the bottom margin: the footer container and its band const BLEED = 0; // mm; 3 for the printer, which switches on page.cutLines below // at(): a placement. Offsets are distances from the anchor point, never page coordinates. const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) }, ...(size && { size }) }); const wide = (w) => ({ width: mm(w) }); // fixed, so a text is as wide as its column const square = (d) => ({ width: mm(d), height: mm(d) }); // Design text is centred and cut with '…' by default (gotcha: overflow-ellipsis-default). const text = (id, content, face, placement) => ({ kind: 'text', id, content, overflow: 'wrap', align: 'left', ...face, placement }); const face = (fontFamily, size, fontWeight, colour, more) => ({ fontFamily, fontSize: pt(size), fontWeight, color: col(colour), ...more }); const caps = (tracking) => ({ letterSpacing: pt(tracking), textTransform: 'uppercase' }); const FACE = { // lineHeight: a multiple, never pt() (gotcha: design-lineheight-multiple) kicker: face('Martian Mono', 12, 500, 'sun', caps(1.8)), title: face('Funnel Display', 120, 800, 'paper', { lineHeight: 0.86 }), deck: face('Funnel Sans', 22, 400, 'paper', { lineHeight: 1.22 }), day: face('Funnel Display', 84, 800, 'sky', { lineHeight: 0.9 }), talk: face('Funnel Sans', 19, 600, 'ink', { lineHeight: 1.14 }), who: face('Funnel Sans', 12.5, 400, 'muted', { lineHeight: 1.3, italic: true }), foot: face('Martian Mono', 9, 500, 'paper', caps(0.9)), }; // #region answer: two elements pinned to frames of the sheet, every other one to an element const SKY = 272; // mm from the trim's top edge to the horizon, the sky's lower edge const INSET = BLEED + MARGIN; // from the bleed's edge to the text's edge const AIR = 14; // mm between the standfirst and the horizon const poster = () => ({ enabled: true, slot: { elements: [ // array order is paint order // 'bleed' and 'page' are frames of the sheet; 'container' would be this heading's own box. { kind: 'box', id: 'sky', style: { backgroundColor: col('sky') }, // no width: fills the bleed placement: at('bleed', 'top-left', 0, 0, { height: mm(BLEED + SKY) }) }, ...eclipse(), // the Sun hangs from the trim's corner, the Moon and the corona from the Sun // The headline stands on the horizon and grows upwards: 'above' puts an element's // bottom-left corner on the top-left corner of its anchor, so a longer title lifts the kicker. text('deck', '{attr.deck}', FACE.deck, { ...at('#sky', 'align-bottom', INSET, -AIR), size: { maxWidth: mm(153) } }), // shrink-wraps its lines, but wraps at 153 mm text('title', '{titleText}', FACE.title, at('#deck', 'above', 0, -9)), // breaks at the \\ text('kicker', '{attr.kicker}', FACE.kicker, at('#title', 'above', 0, -7)), ...programme(), // four columns chained off the horizon ] } }); // hook-up: headings.levels[0] = { span: 'page', breakBefore, advancedDesign: poster() } // {titleText} is the heading's text; each {attr.*} is written on its line in content.md. // #endregion // #region eclipse: the Sun pinned to the trim's corner, the Moon and the corona to the Sun const SUN = 150; // mm across; the Moon is drawn the same size const CORONA = 300; // mm, the square picture of the corona const HALO = (CORONA - SUN) / 2; // how far the corona reaches past the Sun on every side const BITE = { x: 2, y: 2.5 }; // mm the Moon sits off the Sun: a sliver is left at upper left const disc = (id, colour, placement) => ({ kind: 'box', id, placement: { ...placement, size: square(SUN) }, style: { backgroundColor: col(colour), borderRadius: mm(SUN / 2) } }); const eclipse = () => [ { kind: 'image', id: 'corona', resourceId: 'corona', // listed before the discs: painted behind placement: at('#sun', 'align-top', -HALO, -HALO, square(CORONA)) }, disc('sun', 'sun', at('page', 'top-right', 30, 25)), // 30 mm of it past the right edge disc('moon', 'ink', at('#sun', 'align-top', BITE.x, BITE.y)), ]; // #endregion // #region programme: four evenings in fixed-width columns, chained right-of and below const GUT = 7; // mm between the evenings, and between the two columns of text under them const COL = (A3.width - 2 * MARGIN - 3 * GUT) / 4; // four columns across the text width: 60 mm const DROP = 12; // mm from the horizon to the dates const programme = () => [1, 2, 3, 4].flatMap((n) => [ text(`day${n}`, `{attr.d${n}}`, FACE.day, n === 1 ? at('#sky', 'below', INSET, DROP, wide(COL)) // the first date hangs from the horizon : at(`#day${n - 1}`, 'right-of', GUT, 0, wide(COL))), // the others from the one before text(`talk${n}`, `{attr.t${n}}`, FACE.talk, at(`#day${n}`, 'below', 0, 3, wide(COL))), text(`who${n}`, `{attr.s${n}}`, FACE.who, at(`#talk${n}`, 'below', 0, 2.5, wide(COL))), ]); // #endregion // #region footer: a band and the club's mark in the footer slot, which prints on every page const MARK = 10; // mm, the club's mark const PAD = (FOOT - MARK) / 2; // centres the mark in the bottom margin const markTall = { height: mm(MARK) }; // as tall as the mark: the line is centred on it const footer = { elements: [ { kind: 'box', id: 'band', style: { backgroundColor: col('sky') }, // the bottom margin, bled placement: at('bleed', 'bottom-left', 0, 0, { height: mm(BLEED + FOOT) }) }, // The container runs from the text down to the trim: 'bottom-*' counts up, 'top-*' down. { kind: 'image', id: 'mark', resourceId: 'mark', placement: at('container', 'bottom-left', 0, -PAD, square(MARK)) }, text('club', '{attr.club}', FACE.foot, at('#mark', 'right-of', 3, 0, markTall)), text('free', '{attr.free}', FACE.foot, at('container', 'top-right', 0, PAD, markTall)), ] }; // #endregion // #region guides: the same slots, each element framed and tagged with its own placement const GUIDE = { borderColor: col('guide'), borderWidth: pt(1) }; const signed = ({ value }) => `${value < 0 ? '−' : '+'}${Math.abs(value)}`; // all offsets in mm const describe = ({ id, placement: { anchor: { to, edge }, offset = {} } }) => [`#${id}`, `${edge} ${to}`, // the two words of anchor: { to, edge } ['x', 'y'].filter((k) => offset[k]?.value).map((k) => `${k} ${signed(offset[k])}`).join(' '), ].filter(Boolean).join(' · '); // A border never changes an element's size (padding does), so each frame traces its box. // An image or a rounded box gets a square frame of its size, hung from its top-left corner. const frame = (el) => (el.kind === 'text' ? [{ ...el, box: { ...el.box, ...GUIDE } }] : el.kind === 'box' && !el.style.borderRadius ? [{ ...el, style: { ...el.style, ...GUIDE } }] : [el, { kind: 'box', id: `${el.id}-box`, style: GUIDE, placement: at(`#${el.id}`, 'align-top', 0, 0, el.placement.size) }]); const tag = (el, [edge, x = 0, y = 0, note]) => text(`${el.id}-tag`, note ?? describe(el), face('Martian Mono', 8.5, 500, 'ink', { box: { backgroundColor: col('guide'), padding: { top: pt(1.6), bottom: pt(1.2), left: pt(3), right: pt(3) } } }), at(`#${el.id}`, edge, x, y)); const guides = (elements, tags) => [...elements.flatMap(frame), ...elements.filter((el) => tags[el.id]).map((el) => tag(el, tags[el.id]))]; const container = (id) => ({ kind: 'box', id, style: GUIDE, // the slot's own box, drawn placement: at('container', 'top-left', 0, 0, { width: 'fill', height: 'fill' }) }); const TAGS = { // where each tag sits against its element: [edge, x, y, text] sky: ['align-bottom', INSET, -3], corona: ['align-bottom', 90, -2], sun: ['above'], moon: ['below', 20, 2], kicker: ['above'], title: ['above'], deck: ['above'], day1: ['above', 0, -6], day2: ['above'], who1: ['below'], mark: ['above', 0, -2], club: ['above', 69, -2], free: ['above', -30, -2], header: ['align-bottom', 0, -2, t({ en: 'header container', es: 'contenedor de la cabecera' })], footer: ['align-bottom', 0, -2, t({ en: 'footer container', es: 'contenedor del pie' })], }; // #endregion const LEAD = 16; // body leading in pt const config = () => ({ // a factory: configs are cached by identity (gotcha: config-cache-identity) colorPalette, page: { width: mm(A3.width), height: mm(A3.height), dpi: 150, // 150 dpi is for the screen cutLines: { enabled: BLEED > 0, bleed: mm(BLEED) }, margins: { top: mm(MARGIN), bottom: mm(FOOT), left: mm(MARGIN), right: mm(MARGIN) } }, layout: { layoutType: 'double', gutterWidth: mm(GUT) }, // the text columns under the evenings bodyText: { fontFamily: 'Funnel Sans', fontSize: pt(12), lineHeight: pt(LEAD), color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), textAlign: 'left', firstLineIndent: pt(0), paragraphSpacing: true }, // The hidden title is still measured, so it needs a face FONTS loads. headings: { fontFamily: 'Funnel Display', fontWeight: 800, levels: [{ level: 1, span: 'page', advancedDesign: poster(), breakBefore: { enabled: true, parity: 'any' } }] }, // gotcha: headings-drop-h1-break // {style="guides"}: the same design framed and tagged, and a header and footer of its own. headingStyles: [{ id: 'guides', advancedDesign: { enabled: true, slot: { elements: guides(poster().slot.elements, TAGS) } }, header: { elements: guides([container('header')], TAGS) }, footer: { elements: guides([...footer.elements, container('footer')], TAGS) } }], paragraphStyles: [{ id: 'colophon', fontFamily: 'Martian Mono', fontSize: pt(8), lineHeight: pt(LEAD * 0.75), color: col('muted') }], header: { elements: [] }, // the poster has none; the guides page draws the empty container footer, }); // ─── 2 · Content ──────────────────────────────────────────────────────────── const markdown = String.raw`# Vuelve\\la\\sombra {kicker="Jueves de abril de 2027 · 19:30" deck="Cuatro charlas para preparar el eclipse total del 2 de agosto de 2027, cuando la sombra de la Luna cruce el Estrecho." d1="8" t1="Por qué la Luna tapa justo el Sol" s1="Marta Iribarren, astrónoma" d2="15" t2="Por dónde cruzará la sombra" s2="Óscar Beltrán, meteorólogo" d3="22" t3="Lo que nos cuenta la corona" s3="Lucía Ferrándiz, física" d4="29" t4="Mirar al Sol sin quemarse los ojos" s4="Tomás Rey, optometrista" club="Círculo Umbra · astrónomos aficionados desde 1987" free="Entrada libre · sin reserva"}Mostra en Markdown · 14 línies · content.es.md
Cada charla empieza a las 19:30 y dura alrededor de una hora, con preguntas. La sede del Círculo Umbra está en la calle del Faro, 14; las puertas se abren a las 19:00, la entrada es libre y no hay reserva, así que las 120 butacas son para quien llegue antes. El 29 de abril cada asistente se lleva unas gafas de eclipse conformes a la norma ISO 12312-2: úsalas en cada fase parcial y quítatelas solo mientras el Sol esté cubierto del todo. La mañana del eclipse, el Círculo monta telescopios con filtro en el muelle. # Vuelve\\la\\sombra {style="guides" kicker="Jueves de abril de 2027 · 19:30" deck="Cuatro charlas para preparar el eclipse total del 2 de agosto de 2027, cuando la sombra de la Luna cruce el Estrecho." d1="8" t1="Por qué la Luna tapa justo el Sol" s1="Marta Iribarren, astrónoma" d2="15" t2="Por dónde cruzará la sombra" s2="Óscar Beltrán, meteorólogo" d3="22" t3="Lo que nos cuenta la corona" s3="Lucía Ferrándiz, física" d4="29" t4="Mirar al Sol sin quemarse los ojos" s4="Tomás Rey, optometrista" club="Círculo Umbra · astrónomos aficionados desde 1987" free="Entrada libre · sin reserva"} **Cómo leer esta hoja.** Cada marco rosa traza la caja de un elemento, y una etiqueta da su id, el borde por el que se ancla, a qué se ancla y el desplazamiento en milímetros, si lo hay. Por encima del pie, solo dos elementos cuelgan de la hoja misma: el cielo, de la sangre, y el Sol, de la página, que es el corte. Todos los demás cuelgan de otro elemento, así que un título más largo sube el antetítulo y las cuatro tardes siguen al horizonte. Los marcos de los márgenes superior e inferior son los contenedores de la cabecera y del pie. El del pie va del texto al corte, así que las anclas de abajo cuentan hacia arriba desde el corte y las de arriba, hacia abajo desde el texto. :::paragraphs{style="colophon"} Tipos: Funnel Display, Funnel Sans y Martian Mono (SIL OFL) · Texto y dibujos: originales, CC BY 4.0 · El Círculo Umbra y sus ponentes son ficticios. :::`; // content.<lang>.md, inlined by the Cookbook // #region art: the corona and the club's mark, drawn in code, and their resources function mulberry32(seed) { // a seeded generator: the same corona on every run return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } function coronaSvg() { // a glow, then 14 streamers, 70 polar plumes and 160 fine rays const rand = mulberry32(20270802); const R = (500 * SUN) / CORONA; // the Sun's radius in the 1000-unit square const TILT = Math.PI / 4; // the Sun's equator: long streamers go up-left, clear of the kicker const TYPE = [2.2, 3.05]; // radians from the centre where the type is: rays there stop at 9 mm const p = (r, a) => `${(500 + r * Math.cos(a)).toFixed(1)} ${(500 + r * Math.sin(a)).toFixed(1)}`; const ray = (a, full, half, opacity) => { // a petal from the limb, tapered to a point const turn = ((a % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI); const length = turn > TYPE[0] && turn < TYPE[1] ? Math.min(full, R * 0.12) : full; const bend = (rand() - 0.5) * 0.06; return `<path d="M${p(R * 0.97, a - half)}C${p(R + length * 0.35, a - half * 1.1)} ` + `${p(R + length * 0.7, a + bend - half * 0.25)} ${p(R + length, a + bend)}` + `C${p(R + length * 0.7, a + bend + half * 0.25)} ${p(R + length * 0.35, a + half * 1.1)} ` + `${p(R * 0.97, a + half)}Z" fill="${palette.paper}" fill-opacity="${opacity.toFixed(3)}"/>`; }; const glow = Array.from({ length: 28 }, (_, i) => `<circle cx="500" cy="500" ` + `r="${(R * (1.01 + i * 0.022)).toFixed(1)}" fill="${palette.paper}" fill-opacity="0.022"/>`) .reverse().join(''); const out = []; for (let i = 0; i < 14; i++) { // helmet streamers, two fans across the equator const a = TILT + (i % 2) * Math.PI + (rand() - 0.5) * 1.1; out.push(ray(a, R * (0.55 + 0.45 * rand()), 0.1 + 0.14 * rand(), 0.06 + 0.06 * rand())); } for (let i = 0; i < 70; i++) { // polar plumes, shorter and thinner than the streamers const a = TILT + Math.PI / 2 + (i % 2) * Math.PI + (rand() - 0.5) * 1.3; out.push(ray(a, R * (0.18 + 0.3 * rand()), 0.008 + 0.012 * rand(), 0.1 + 0.12 * rand())); } for (let i = 0; i < 160; i++) { // fine rays all round const a = (i / 160) * 2 * Math.PI + (rand() - 0.5) * 0.04; out.push(ray(a, R * (0.12 + 0.3 * rand()), 0.006 + 0.014 * rand(), 0.05 + 0.07 * rand())); } return `<svg xmlns="http://www.w3.org/2000/svg" width="1500" height="1500" ` + `viewBox="0 0 1000 1000">${glow}${out.join('')}</svg>`; } function markSvg() { // the Umbra Circle's mark: a ring round an eclipsed Sun return `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 100 100">` + `<circle cx="50" cy="50" r="45" fill="none" stroke="${palette.paper}" stroke-width="6"/>` + `<circle cx="50" cy="50" r="27" fill="${palette.sun}"/>` + `<circle cx="56" cy="45" r="27" fill="${palette.sky}"/></svg>`; } const svg = (id, size, altText) => ({ id, typeId: 'figure', kind: 'svg', altText, svg: { fileId: `${id}.svg`, width: size, height: size }, createdAt: 0, updatedAt: 0 }); // Image elements draw resources. Nothing cites them, so neither is placed or numbered as a figure. const resources = [ svg('corona', 1500, t({ en: 'The solar corona round the eclipsed Sun', es: 'La corona solar alrededor del Sol eclipsado' })), svg('mark', 200, t({ en: 'The Umbra Circle’s mark', es: 'El emblema del Círculo Umbra' })), ]; // #endregion // ─── 3 · Fonts ────────────────────────────────────────────────────────────── // Every face the pages paint, loaded before the first build (gotcha: fonts-first). const FONTS = { 'Funnel Display': ['800'], 'Funnel Sans': ['400', '400i', '600', '700'], 'Martian Mono': ['400', '500'], }; // ─── 4 · Build & show ─────────────────────────────────────────────────────── await loadSvg('corona.svg', coronaSvg()); await loadSvg('mark.svg', markSvg()); await loadFonts(FONTS, markdown); // pageIndexOffset 1 makes the poster a verso, so the viewer sets the two sheets side by side. const content = { markdown, resources, continuation: { pageIndexOffset: 1 } }; const doc = await buildWithFonts(() => buildDocument(content, config()), markdown); showPages(doc, { title: t({ en: 'Anchoring cheat sheet', es: 'Chuleta de anclajes' }) });Kit · core, fonts, viewer, images: igual a totes les receptes · 270 línies
// ─── 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 v1 ── the same in every recipe · postext.dev/cookbook ──────── // Postext measures text with the faces the browser has loaded, and caches the // widths, so every face must be ready before the first build. Faces come from // Fontsource: the same static files the PDF embeds, so screen and PDF agree. /** faces = { 'Family Name': ['400', '400i', '700'] }. `text` is the sample: * letters beyond Latin-1 (č, ł, ő…) also load the latin-ext files. With * `optional`, a face Fontsource does not ship is skipped instead of failing. * Resolves to the number of faces added. */ async function loadFonts(faces, text = '', { optional = false } = {}) { kitStatus('Loading fonts…'); const ranges = { 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', }; const subsets = /[Ā-˿Ḁ-ỿ]/.test(text) ? ['latin', 'latin-ext'] : ['latin']; const jobs = []; let added = 0; for (const [family, specs] of Object.entries(faces)) { const id = fontsourceId(family); const meta = optional ? await fontsourceMeta(family) : null; for (const spec of new Set(specs)) { const weight = parseInt(spec, 10); const style = spec.endsWith('i') ? 'italic' : 'normal'; if (hasFace(family, weight, style)) continue; if (optional && !(meta?.weights.includes(weight) && meta.styles.includes(style))) continue; for (const subset of subsets) { const url = `https://cdn.jsdelivr.net/npm/@fontsource/${id}@5/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().then((ready) => { document.fonts.add(ready); added++; }, () => { if (subset === 'latin' && !optional) throw new Error(`Fontsource has no ${family} ${weight} ${style}`); })); } } } await Promise.all(jobs).catch((error) => { kitFail(error); throw error; }); return added; } /** Runs `build` (a buildDocument or buildBundle call) and checks the faces * the pages use. A regular face missing from FONTS is loaded with a warning; * bold and italic variants are loaded when the family ships them. Then the * measurement caches are cleared and the build runs again. */ async function buildWithFonts(build, text = '') { const tried = new Set(); for (let round = 0; round < 3; round++) { kitStatus('Laying out…'); await new Promise(requestAnimationFrame); // let the status paint first const result = await Promise.resolve().then(build).catch((error) => { kitFail(error); throw error; }); const wanted = { base: {}, variants: {} }; for (const { font, base } of [result].flat().flatMap(fontStringsOf)) { const { family, weight, style } = parseFont(font); const key = `${family}|${weight}|${style}`; if (tried.has(key) || hasFace(family, weight, style)) continue; tried.add(key); (wanted[base ? 'base' : 'variants'][family] ??= []).push(`${weight}${style === 'italic' ? 'i' : ''}`); } if (Object.keys(wanted.base).length) { console.warn(`[cookbook] FONTS does not list ${JSON.stringify(wanted.base)}: loading them.`); } const added = await loadFonts(wanted.base, text) + await loadFonts(wanted.variants, text, { optional: true }); if (added === 0) return result; clearMeasurementCache(); } throw new Error('The fonts did not settle after three builds.'); } /** Every font string of the layout. `base` marks a block's own face; its * bold, italic and bold-italic variants are listed whether or not used. */ function fontStringsOf(doc) { const found = new Map(); const walk = (node) => { if (!node || typeof node !== 'object') return; if (Array.isArray(node)) { node.forEach(walk); return; } for (const [key, value] of Object.entries(node)) { if (typeof value === 'string' && /fontString$/i.test(key)) { found.set(value, found.get(value) || key === 'fontString'); } else if (value && typeof value === 'object') walk(value); } }; walk(doc.pages); walk(doc.blocks); return [...found].map(([font, base]) => ({ font, base })); } /** '700 37.5px Open Sans' / 'italic 400 13px "Source Serif 4"' → { family, weight, style }. * A string with no weight ('95.8px Young Serif', from a design text) is 400. */ function parseFont(font) { const m = /^(?:(italic|oblique)\s+)?(?:small-caps\s+)?(?:(\d+|bold|normal)\s+)?[\d.]+px\s+(.+)$/.exec(font.trim()); if (!m) throw new Error(`Unexpected font string: ${font}`); const weight = m[2] === 'bold' ? 700 : !m[2] || m[2] === 'normal' ? 400 : Number(m[2]); return { family: m[3].replace(/^["']|["']$/g, ''), weight, style: m[1] ? 'italic' : 'normal' }; } /** True when a loaded FontFace covers exactly this family, weight and style * (document.fonts.check() is also true for families nobody declared). */ 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; } /** Fontsource's id for a family: 'Source Serif 4' → 'source-serif-4'. */ function fontsourceId(family) { return family.toLowerCase().replace(/\s+/g, '-'); } /** The weights and styles a family ships ({ weights: [400, 700], styles: ['normal', 'italic'] }), or null. */ function fontsourceMeta(family) { fontsourceMeta.cache ??= new Map(); const id = fontsourceId(family); if (!fontsourceMeta.cache.has(id)) { fontsourceMeta.cache.set(id, fetch(`https://api.fontsource.org/v1/fonts/${id}`) .then((res) => (res.ok ? res.json() : null), () => null)); } return fontsourceMeta.cache.get(id); } // ─── Kit · viewer v1 ── the same in every recipe · postext.dev/cookbook ─────── /** Shows the pages as facing spreads on a dark desk: the first page is a * recto on its own, then verso | recto pairs, as in a bound book. Pages * are painted when they scroll near the screen. */ function showPages(docs, { title, width = 460 } = {}) { 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, { 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 v1 ── 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 (drawn in code, or fetched) as a vector image. */ async function loadSvg(fileId, svg) { const img = new Image(); img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`; await img.decode(); registerResourceImage(fileId, img); (loadImage.bytes ??= new Map()).set(fileId, new TextEncoder().encode(svg)); } /** 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 ───────────────────────────────────────────────────────────────────────
L'script.js compost funciona tal com és: enganxa'l com a script de mòdul en qualsevol pàgina o obre la recepta a CodePen. Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)
Variants
#Afegeix 3 mm de sang i marques de tall
Amb 3 mm de BLEED s'activen les marques de tall, i el cel i la banda del peu, que pengen de la sang, hi entren 3 mm mentre INSET deixa el text al marge; el Sol, la Lluna i la corona pengen de la pàgina, i com que la 1.4.1 no retalla els elements de disseny a la sang, continuen pel marge blanc fins a la vora del full.
-const BLEED = 0; // mm; 3 for the printer, which switches on page.cutLines below
+const BLEED = 3; // mm; 3 for the printer, which switches on page.cutLines below#Puja l'horitzó
Amb 20 mm menys de SKY puja la vora del cel, i amb ella l'entradeta, el títol, l'avanttítol i els dotze textos del programa, mentre la lletra petita passa a una línia més alta de la retícula de base; el Sol penja de la pàgina, així que el segon canvi el puja els mateixos 20 mm perquè mantingui la distància amb el títol, que a l'edició anglesa arribaria a tocar el fil de Sol.
-const SKY = 272; // mm from the trim's top edge to the horizon, the sky's lower edge
+const SKY = 252; // mm from the trim's top edge to the horizon, the sky's lower edge
- disc('sun', 'sun', at('page', 'top-right', 30, 25)), // 30 mm of it past the right edge
+ disc('sun', 'sun', at('page', 'top-right', 30, 5)), // 30 mm of it past the right edgeErrors freqüents
Error freqüent
Els elements de capçalera i peu es pinten damunt del text
Els elements de capçalera i peu es pinten sobre la pàgina i l'àrea de text no els deixa lloc. Mantén-los dins dels marges, que són els que els reserven l'espai. Capçaleres i folis →
Error freqüent
Valors d'atribut: sense { ni }; cometes simples si porten "
Un valor d'atribut acaba a la clau de tancament, així que no pot contenir { ni }. Un valor que porti cometes dobles va entre cometes simples; el signe de dòlar no dona problemes. Atributs de títol →
Error freqüent
El desbordament del text de disseny és 'ellipsis-end' per defecte
Un element de text de disseny que no cap en la seva amplada acaba en punts suspensius per defecte. Posa overflow: 'wrap' als títols que hagin de passar a més línies. Textos, filets i caixes als dissenys de pàgina →
Error freqüent
El lineHeight d'un text de disseny és un múltiple, mai una mesura
En una ranura de disseny, el lineHeight d'un element de text multiplica el seu cos (lineHeight: 1.05). A postext 1.4.1 una mesura com pt(15) no dona error: l'alçada de l'obertura surt NaN, l'espai que reserva, minHeight inclòs, es perd sense avís i el text se superposa al títol. Textos, filets i caixes als dissenys de pàgina →
Error freqüent
Una paleta canviada no arriba als elements de disseny ni al color de les remissions
postext 1.4.1 aplica colorPalette als estils de text (cos, títols, llistes, peus, taules, requadres), però no als elements de capçaleres, peus de pàgina, obertures i portadelles, ni a bodyText.referenceColor: conserven l'hex escrit al costat del seu paletteId. Si canvies la paleta, per a una edició de pantalla fosca o per recolorejar, reescriu cada color enllaçat a partir de colorPalette abans de compondre. Paleta de color semàntica →
Error freqüent
Qualsevol objecte headings desactiva el salt de pàgina de l'H1
Per defecte un H1 salta a una pàgina senar (always-odd), però qualsevol objecte headings anul·la aquest valor, de manera que els capítols van seguits i span: 'page' no fa res. Torna a declarar headings.levels[0].breakBefore: { enabled: true, parity } a cada configuració. Capítols que obren en pàgina senar →
Error freqüent
Una configuració es desa a la memòria cau per identitat: crea un objecte nou
El motor desa a la memòria cau les configuracions resoltes segons la identitat de l'objecte, de manera que modificar el mateix objecte i tornar a compondre reutilitza el resultat anterior. Crea un objecte nou a cada composició: per això la configuració d'una recepta és una funció, config(). Pàgines en un canvas →
Error freqüent
Carrega totes les fonts abans de compondre
La composició mesura el text amb les fonts que el navegador ha carregat i en desa les amplades, així que una font que arriba després de la primera composició deixa talls de línia erronis i un PDF que ja no coincideix amb la pantalla. Carrega abans tots els pesos i estils, i crida clearMeasurementCache() abans de recompondre si alguna arriba tard. Fonts abans de compondre →
Comprovació del Sandbox · designCyclicAnchor
Referència d'ancoratge cíclica
Per què. Els elements de disseny s'ancoren els uns als altres en bucle, de manera que cap no es pot col·locar.
Solució. Ancora un element de la cadena al contenidor, a la pàgina o a la sang. Documentació →
Comprovació del Sandbox · designDanglingAnchor
Referència d'ancoratge trencada
Per què. Un element de disseny s'ancora a un #id que no té cap element de la ranura.
Solució. Corregeix l'id o afegeix l'element al qual es refereix. Documentació →
- En un pen, la versió 1.4.1 no avisa d'un ancoratge cíclic ni d'un de trencat. El tauler Revisió del Sandbox els assenyala a la capçalera, al peu, a les portadelles de part i als nivells de títol, però no als estils de títol com
guides. Un element ancorat a un#idque no existeix es col·loca respecte al contenidor: una vora d'element com'below'cau a la cantonada superior esquerra del contenidor, amb el seu desplaçament, i una vora de contenidor com'top-right', en aquesta cantonada. En un bucle, un element cau de la mateixa manera i els altres s'hi encadenen. - A la 1.4.1,
'align-left'i'align-top'porten al mateix punt: tots dos posen la cantonada superior esquerra de l'element sobre la de la seva àncora. - Una vora es pinta centrada sobre el contorn de la caixa, així que cada marc rosa d'1 pt sobresurt 0,5 pt de la caixa que traça, tot i que la documentació de la configuració diu que els traços es pinten per dins.
Crèdits
- Recepta
- Ignacio Ferro
- Text
- Text original, CC BY 4.0
- Fonts
- Funnel Display (SIL OFL 1.1) · Funnel Sans (SIL OFL 1.1) · Martian Mono (SIL OFL 1.1)
- Codi
- MIT, com Postext
Editar aquest text ↗ (s'obre en una pestanya nova)Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)


