باختصار
ملصق لمحاضرات في علم الفلك تسبق كسوفًا كليًا للشمس. يبيّن كيف تضع كل عنصر بالقياس من حافة الصفحة أو من عنصر آخر.
ما الذي ستنضده
ملصق من نادٍ فلكي متخيَّل لأربع محاضرات تُلقى أيام الخميس قبل الكسوف الكلي للشمس في 2 أغسطس 2027. سماء بالأزرق البحري الداكن تملأ الثلثين العلويين من ورقة A3. وعلى اليمين قمر أسود يغطي شمسًا ليمونية يقطعها حدّ القص، وهالة مرسومة بالشيفرة تنتشر خلفهما. يقف العنوان، The Shadow Returns بخط Funnel Display بحجم 120 pt، على تقديمه أسفل السماء. وتحت الأفق أربعة تواريخ زرقاء تتصدّر المحاضرات، ويجري النص الصغير في عمودين فوق شريط أزرق. يتعلّق كل عنصر بالنزف أو بالصفحة أو بخانته أو بعنصر آخر، وتُحسب إزاحاته من هناك. وتكرّر الورقة الثانية الملصق مع إطار وردي حول مستطيل كل عنصر وحول حاويتي الترويسة والتذييل، ووسم على ثلاثة عشر عنصرًا يطبع موضع كل منها.
تجيب هذه الوصفة عن
- كيف أضع عناصر التصميم نسبةً إلى الصفحة أو النزف أو بعضها إلى بعض بدل الإحداثيات؟
- كيف أضيف علامة مائية أو لونًا خفيفًا للخلفية أو صورة زخرفية في كل صفحة؟
الجواب المختصر
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.
المكونات
- الميزات
- تثبيت عناصر التصميمالنصوص والخطوط والمربعات في تصاميم الصفحةالصور في تصاميم الصفحةصفحات افتتاح مصمَّمةشريط فصل بعرض الصفحةأشرطة النزف وألسنة الإبهامأنماط العناوينترويسات لكل قسمسمات العنوانفواصل الأسطر في العناوينلوحة ألوان دلاليةأنماط الفقراتالأشكال والجداول بوصفها مواردصفحات على اللوحة (Canvas)
- تستخدم أيضًا
- النزف وعلامات القص
- الخطوط
- Funnel Display, Funnel Sans, Martian Mono (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · ثبّت عنصرين إلى الورقة وعلّق الباقي بهما
الشيفرة هي الجواب المختصر أعلاه. تحدّد فيها الخاصية anchor.to ما يُربط به العنصر: 'bleed' و'page' إطاران للورقة (وهما المستطيل نفسه ما دام page.cutLines معطّلًا)، و'container' مستطيل الخانة نفسها، و'#id' عنصر آخر (موضع العناصر). الصندوق الذي لا عرض له يمتد إلى الحافة البعيدة من إطاره، فتملأ السماء النزف من جانب إلى جانب. والعنصر الموضوع بالنسبة إلى السماء يقيس من حافتها اليسرى، وهي حافة النزف، لذلك يأخذ التقديم INSET، أي 18 mm، قيمةً للإحداثي x. ويُبنى العنوان صعودًا من الحافة السفلى للسماء. تضع 'align-bottom' أسفل مستطيل التقديم على بعد AIR، أي 14 mm، فوق تلك الحافة، وتضع 'above' أسفل كل عنصر على أعلى العنصر الذي تحته، فإذا امتد العنوان إلى أسطر أكثر رفع العنوان التمهيدي بدل أن يغطي التقديم. وتحت التصميم يبدأ النص الصغير على أول خط من شبكة 16 pt يقع على بعد 3.2 mm على الأقل تحت أدنى عنصر، وهو سطر المحاضرين؛ وهذه المسافة البالغة 3.2 mm هي الهامش السفلي الافتراضي للعنوان.
#2 · علّق القمر والهالة بالشمس
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)),
];
الشمس هي العنصر الوحيد المربوط بالصفحة، أي مستطيل القصّ. وبالقياس من الزاوية 'top-right' تمتد قيمة x الموجبة إلى ما بعد الحافة اليمنى، فيُقطع 30 mm من القرص. ويتعلّق القمر والهالة بالشمس عبر 'align-top'، فإذا حرّكت الشمس تحرّكا معها. وتُحسب إزاحتاهما من الزاوية العليا اليسرى للشمس: يقع القمر 2 mm إلى اليمين و2.5 mm إلى الأسفل، فيترك هلالًا رفيعًا من الشمس في أعلى اليسار، وتبدأ الهالة على بعد HALO، أي 75 mm، إلى الأعلى واليسار، فيتوسّط مربعها البالغ 300 mm القرص البالغ 150 mm. والهالة عنصر صورة يأخذ حجم مستطيله (عناصر الصور) ويأتي قبل القرصين في القائمة، فيُرسم خلفهما.
#3 · سلسِل الأمسيات في أعمدة
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))),
]);
لكل تاريخ ومحاضرة وسطر محاضر عرض ثابت size.width قيمته COL، وتضع 'right-of' مع GUT التاريخ التالي في العمود المجاور. ولو لم يكن للتاريخ عرض لانكمش على أرقامه (عرض ‘8’ يبلغ 17 mm)، فيبدأ ‘15’ بعده بمسافة 7 mm وتجري كل محاضرة على سطر واحد داخل العمود التالي. يقسم COL عرض النص أربعة أقسام بالفاصل نفسه البالغ 7 mm الذي بين عمودَي النص الصغير في الأسفل، فيقع العمود الثاني من النص الصغير تحت التاريخ 22. تتعلّق كل محاضرة 'below' تاريخها، وكل سطر محاضر تحت محاضرته، فإذا التفّت محاضرة إلى سطر ثالث دفعت محاضرها وحده إلى الأسفل.
#4 · ضع الشريط في التذييل، على كل صفحة
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)),
] };
كل ما يجب أن يُطبع على كل صفحة، مثل هذا الشريط، يوضع في خانة الترويسة أو التذييل، ونمط العنوان الذي له ترويسة أو تذييل خاص يستبدل تلك الخانة في صفحات قسمه. يكرّر تذييل النمط guides هذه العناصر الأربعة مع إطاراتها ووسومها، ولهذا يُطبع الشريط والشعار على الورقتين. حاوية التذييل هي الهامش السفلي، من النص نزولًا إلى حدّ القص: 'bottom-left' تعدّ صعودًا من حدّ القص و'top-right' نزولًا من النص، فتقع إزاحة الشعار −10 وإزاحة سطر “Free entry” +10 على الشريحة نفسها البالغة 10 mm في وسط الشريط (الترويسات والتذييلات). يُرسم التذييل بعد النص ولا يأخذ منه مساحة، لذلك يحدّد FOOT الهامش السفلي وارتفاع الشريط معًا، فيبقى الشريط بعيدًا عن الأسطر التي فوقه.
#5 · ارسم خطوط البناء من الإعدادات نفسها
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() على عناصر الملصق. يأخذ النص حدًّا على مستطيله، ويأخذ الصندوق المربع حدًّا على أسلوبه؛ ولا يحرّك أيٌّ منهما شيئًا، لأن الحشو وحده يكبّر الصندوق. وتأخذ الصورة أو القرص الدائري مستطيلًا مربعًا بحجمها معلّقًا من زاويتها العليا اليسرى، فتُرسم أيضًا زاوية الشمس التي يُربط بها القمر والهالة. كل وسم نص معلّق بعنصره، تكتبه describe() من placement الخاص بذلك العنصر، فلا يمكن أن يخالف الوسم الإعدادات التي يصفها. يجلب {style="guides"} على العنوان الثاني هذا التصميم وترويسة وتذييلًا خاصين به (أساليب العناوين). والوسم الذي لا عرض له لا يملك إلا المسافة بين نقطة ارتكازه والحافة اليمنى للحاوية، ولهذا يبدأ وسم #free على بعد 30 mm يسار نصه. ويجعل pageIndexOffset: 1، في continuation الخاص بالمحتوى، الملصق صفحة زوجية، فيضع العارض الورقتين جنبًا إلى جنب.
الوصفة كاملة
// ═══ 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.34.0
// 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 {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @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 colour linked to its palette entry, so a swapped palette recolours the sheet.
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 by default, and in a footer it is cut with '…': these wrap, set left.
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 as a multiple of each size
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 }),
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#أضف نزفًا بمقدار 3 mm وعلامات القص
ثلاثة مليمترات من BLEED تشغّل خطوط القص وتدفع السماء وشريط الأسفل 3 mm داخل النزف الذي يُربطان به، بينما يُبقي INSET النص على الهامش؛ أما الشمس والقمر والهالة فمربوطة بالصفحة، وكل ما ترسمه الصفحة يُقصّ عند النزف، فتنتهي الشمس بعد خط القص بثلاثة مليمترات ولا يبقى خارج النزف إلا علامات القص.
-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#ارفع الأفق
إنقاص 20 mm من SKY يرفع حافة السماء، ومعها التقديم والعنوان والعنوان التمهيدي ونصوص البرنامج الاثني عشر، بينما يبدأ النص الصغير على خط أعلى من الشبكة؛ والشمس معلّقة بالصفحة، لذلك يرفعها التغيير الثاني بمقدار 20 mm نفسه، وإلا لمسَ حرف ‘w’ في Shadow الهلال.
-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 edgeأخطاء شائعة
خطأ شائع
عناصر الترويسة والتذييل تُرسَم فوق النص
تُرسَم عناصر الترويسة والتذييل فوق الصفحة، ولا تُفسح منطقة النص لها مكانًا. أبقِها داخل الهوامش، فالهوامش هي التي تحجز مساحتها. الترويسات وأرقام الصفحات →
خطأ شائع
قيم السمات: لا { ولا }؛ ضع القيمة التي فيها " بين علامتي اقتباس مفردتين
تنتهي قيمة السمة عند القوس المعقوف الختامي، فلا يمكن أن تحتوي { أو }. القيمة التي فيها علامة اقتباس مزدوجة توضع بين علامتي اقتباس مفردتين؛ أما علامة الدولار فلا مشكلة فيها. سمات العنوان →
فحص Sandbox · designCyclicAnchor
مرجع ربط دائري
السبب. عناصر التصميم مربوط بعضها ببعض في حلقة، فلا يمكن وضع أي منها.
الحل. اربط عنصرًا واحدًا من السلسلة بالحاوية أو الصفحة أو منطقة النزف. التوثيق →
فحص Sandbox · designDanglingAnchor
مرجع ربط معلّق
السبب. عنصر تصميم مربوط بـ#id لا يملكه أي عنصر في الخانة.
الحل. صحّح المعرّف، أو أضف العنصر الذي يشير إليه. التوثيق →
- في المثال، لا يظهر التحذير «مرجع ربط دائري» ولا التحذير «مرجع ربط معلّق». تسردها لوحة الفحوص في Sandbox في الترويسة والتذييل وصفحات الأجزاء ومستويات العناوين، لكن لا تسردها في أنماط العناوين مثل
guides. والعنصر المربوط بـ#idغير موجود يوضع بالنسبة إلى الحاوية: حافة عنصر مثل'below'تعود إلى الزاوية العليا اليسرى للحاوية، مع الإزاحة، وحافة حاوية مثل'top-right'تعود إلى تلك الزاوية. وفي الحلقة الدائرية يعود عنصر واحد بالطريقة نفسها وتتسلسل العناصر الأخرى منه. - تقع
'align-left'و'align-top'على النقطة نفسها: كلتاهما تضع الزاوية العليا اليسرى للعنصر على الزاوية العليا اليسرى لنقطة ارتكازه. - يُرسم الحدّ متمركزًا على حافة المستطيل، فيتجاوز كل إطار وردي بسماكة 1 pt المستطيلَ الذي يحيط به بمقدار 0.5 pt، مع أن توثيق الإعدادات ينصّ على أن الخطوط تُرسم في الداخل.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- نص أصلي, CC BY 4.0
- الخطوط
- Funnel Display (SIL OFL 1.1) · Funnel Sans (SIL OFL 1.1) · Martian Mono (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


