انتقل إلى المحتوى الرئيسي
الوصفة رقم 100

دليل الوصفات · الفصل 10 · الإخراج والدمج

كتاب مُخرَج على المكتب، بالأبعاد الثلاثة

تفتح الدالة createFolioFromDocument من الحزمة postext-folio فصلًا مُخرَجًا ككتاب مجلَّد بالقماش على مكتب من خشب الجوز، بمظهر يحدده config.folio.

في هذه الصفحة
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 129 × 198 مم
  • عمود واحد
  • Literata 9.8/14
  • Fraunces
  • Work Sans
  • 4 صفحات
  • المستوى
  • Postext 1.57.1
  • أُخرجت في 49 ms
  • أسطر الشيفرة: 119

باختصار

الفصل الأول من رواية قصيرة، معروضًا ككتاب حقيقي مفتوح على مكتب. تقلّب صفحاته بالفأرة، وتختار الورق والغلاف والمكتب من الإعدادات.

ما الذي ستنضده

الفصل الأول من The Ferryman’s Ledger، رواية قصيرة بمقاس صفحة 129 × 198 مم، مفتوحًا ككتاب على مكتب من خشب الجوز. الغلاف قماش أخضر داكن كلون الزجاجات، والصفحات ورق روايات كريمي منفوش، ويمسك القارئ الصفحة اليمنى من حافتها ويقلبها، فتنثني الورقة وتلقي ظلها على الصفحة التي تحتها. يُنضَّد النص مرة واحدة بـbuildDocument؛ ثم يحوّل استدعاء واحد للحزمة postext-folio هذا الإخراج إلى الكتاب. كل ما يُصنع منه الكتاب (الورق والتجليد والمكتب والإضاءة وزاوية النظر) جزء من الإعدادات، فيأخذ المستند نفسه مظهره معه إلى تبويب Folio في Sandbox.

تجيب هذه الوصفة عن

  • كيف أعرض مستندي كتابًا ثلاثي الأبعاد يقلّب القارئ صفحاته بيده؟
  • كيف أعاين تجليد الكتاب وغلافه وورقه وإضاءته قبل إرساله إلى الطباعة؟

الجواب المختصر

script.js · الأسطر 174–185في الشيفرة الكاملة
const stage = document.createElement('section');
stage.id = 'folio';
stage.ariaLabel = 'The book in 3D';
stage.style.cssText = 'height: min(78vh, 720px); margin: 0 auto; max-width: 1280px';
document.getElementById('pages').before(stage);
createFolioFromDocument(stage, doc, {
  // The paper, binding, desk and light come from doc.config.folio. Only the photographed
  // desk is the host's choice: without textureBaseUrl the walnut is drawn procedurally.
  appearance: { textureBaseUrl: 'https://postext.dev/folio/textures' },
  onChange: ({ pages }) => kitStatus(`${doc.pages.length} pages · open at `
    + pages.map((i) => doc.pages[i].pageLabel || i + 1).join('–')),
});

المكونات

الخطوط
Literata, Fraunces, Work Sans (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

طريقة التحضير

#1 · قل مِمَّ يُصنع الكتاب

script.js · الأسطر 34–41في الشيفرة الكاملة
const folio = {
  tilt: 26, // degrees from straight above: enough to see the depth of the page block
  paper: { type: 'bookWove', grammage: 70, shade: col('cream') }, // a bulky cream novel paper
  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
  surface: { type: 'walnut' },
  lighting: { environment: 'studio', intensity: 1, shadows: true },
};

لا يقرأ config.folio إلا العارض ثلاثي الأبعاد: يتجاهله الإخراج وCanvas وملف PDF ومخرجات HTML، فتغيير الورق لا يحرّك سطرًا. bookWove ورق روايات منفوش، و70 غ/م² بنفشه هذا تعطي ورقة سمكها نحو 112 ميكرومترًا؛ ويضرب العارض هذا السمك في عدد الصفحات ليحسب عمق كتلة الصفحات. لون القماش مرتبط بلون التمييز في لوحة الألوان، وهو الأخضر نفسه الذي في العبارة التمهيدية وأرقام الصفحات.

#2 · صفحة افتتاح هادئة وترويسات

script.js · الأسطر 45–57في الشيفرة الكاملة
const opener = { enabled: true, minHeight: mm(50), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: 'Work Sans',
    fontSize: pt(7.5), fontWeight: 600, letterSpacing: pt(1.5), textTransform: 'uppercase',
    color: col('accent'), align: 'left',
    placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(10) } } },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Fraunces', fontSize: pt(28),
    lineHeight: 1.05, fontWeight: 600, color: col('ink'), align: 'left', overflow: 'wrap',
    placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(3) },
      size: { width: mm(90) } } },
  { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1.25), color: col('accent'),
    placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(4.5) },
      size: { width: mm(12) } } },
] } };

يبدأ الفصل على بعد ثلث الصفحة من أعلى صفحة فردية، تحت عبارة تمهيدية مأخوذة من سمات العنوان. في العرض ثلاثي الأبعاد تُقرأ صفحة الافتتاح المنخفضة كما تُقرأ في رواية مطبوعة: البياض في رأس الصفحة أول ما يراه القارئ حين يفتح الغلاف.

script.js · الأسطر 61–74في الشيفرة الكاملة
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content, parity,
  pages: 'body', fontFamily: 'Work Sans', fontSize: pt(7), fontWeight: 500,
  letterSpacing: pt(1.1), textTransform: 'uppercase', color: col('muted'),
  placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(11) } }, ...extra });
const folioNumber = { fontWeight: 600, color: col('accent') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folioNumber),
  head('verso-author', '{author}', 'even', 'top-left', OUTER + 8),
  head('recto-title', '{title}', 'odd', 'top-right', -(OUTER + 8)),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folioNumber),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'bottom', 0,
  { ...folioNumber, pages: 'opener', placement: { anchor: { to: 'page', edge: 'bottom' },
    offset: { y: mm(-11) } } })] };

#3 · افتح المستند ككتاب

الشيفرة هي الجواب المختصر أعلاه. تأخذ createFolioFromDocument حاوية والمستند المُخرَج: ترسم كل صفحة بـrenderPageToCanvas بالمقاس الدقيق لخانة الصفحة، وحول الصفحتين المتقابلتين المفتوحتين فقط، وتُدخل الكتاب في الحاوية. يجب أن يكون للحاوية ارتفاع خاص بها، وإلا لم يجد الكتاب مكانًا. يشير textureBaseUrl إلى صور المكاتب الفوتوغرافية على postext.dev؛ ومن دونه يُرسم خشب الجوز بخرائط إجرائية.

الوصفة كاملة

Sandbox
// ═══ Postext Cookbook · Nº 100 · A laid-out book on the desk, in 3D ═══════════════════
// https://postext.dev/en/cookbook/folio-book-on-a-desk
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Literata, Fraunces, Work Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
//
// A chapter of a short novel, laid out on a trade-book page and opened with postext-folio as a
// cloth-bound book lying on a walnut desk. Take the right-hand page by its edge and drag it
// over, click a page, or use the arrow keys. The flat pages follow under the book.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'folio-book-on-a-desk';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
  ink: '#211d1a', // text: a warm near-black
  accent: '#2f5d50', // bottle green: kicker, rule, folios, and the cloth of the case
  rule: '#c9bfae', // the colophon's hairline
  muted: '#6d655c', // running heads and the colophon
  cream: '#f7f0e1', // the book wove the pages are printed on (the 3D paper only)
};
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: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// #endregion
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER] = [129, 198, 20, 22, 17, 15]; // mm: B-format
const LEAD = 14; // pt: the body leading

// #region folio: what the book is made of and where it lies; layout never reads it
const folio = {
  tilt: 26, // degrees from straight above: enough to see the depth of the page block
  paper: { type: 'bookWove', grammage: 70, shade: col('cream') }, // a bulky cream novel paper
  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
  surface: { type: 'walnut' },
  lighting: { environment: 'studio', intensity: 1, shadows: true },
};
// #endregion

// #region opener: a sunk chapter opening, kicker, title and a short rule
const opener = { enabled: true, minHeight: mm(50), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: 'Work Sans',
    fontSize: pt(7.5), fontWeight: 600, letterSpacing: pt(1.5), textTransform: 'uppercase',
    color: col('accent'), align: 'left',

يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

تنويعات

#كتاب بغلاف ورقي على خشب البلوط في ضوء النهار

غيّر ثلاثة إعدادات فيصير الفصل نفسه كتابًا بغلاف لين على مكتب فاتح؛ ولا يُعاد إخراج أي شيء.

-  binding: { type: 'hardcover', cover: 'case', coverMaterial: 'cloth',
-    coverColor: col('accent') }, // the case wraps the pages; boards a little larger
-  surface: { type: 'walnut' },
-  lighting: { environment: 'studio', intensity: 1, shadows: true },
+  binding: { type: 'paperback', cover: 'case', coverMaterial: 'paper',
+    coverColor: col('accent') },
+  surface: { type: 'oak' },
+  lighting: { environment: 'daylight', intensity: 1, shadows: true },

#كل ورقة على ورق مختلف

يطبع كتاب عيّنات الورق كل ورقة على نوع ورق خاص بها بـ:::paper، ويغيّر منضدة الإعدادات كل إعداد مباشرة بـsetAppearance.

أخطاء شائعة

خطأ شائع

يأخذ عارض Folio مقاس حاويته

يضع createFolioFromDocument الكتاب داخل العنصر الذي تعطيه إياه، مع الأزرار وعدد الصفحات في هوامشه. والعنصر الذي لا ارتفاع له (div فارغ في التدفق العادي) لا يعرض شيئًا: أعطه ارتفاعًا في CSS. عارض الكتاب ثلاثي الأبعاد (Folio) →

الحقوق

الوصفة
Ignacio Ferro
النص
نص أصلي, CC BY 4.0
الخطوط
Literata (SIL OFL 1.1) · Fraunces (SIL OFL 1.1) · Work Sans (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext
Sandbox