markdown-pdf-export 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -2
- package/cli.mjs +695 -0
- package/default.css +230 -0
- package/export.mjs +1369 -0
- package/lib/asset-resolver.mjs +493 -0
- package/lib/config-merger.mjs +488 -0
- package/lib/doctor-report.mjs +52 -0
- package/lib/editor-setup.mjs +280 -0
- package/lib/frontmatter-parser.mjs +595 -0
- package/lib/html-generator.mjs +837 -0
- package/lib/looks.mjs +150 -0
- package/lib/placeholder-resolver.mjs +490 -0
- package/lib/schema-validator.mjs +725 -0
- package/lib/settings-loader.mjs +167 -0
- package/lib/settings-schema.mjs +192 -0
- package/lib/studio-server.mjs +490 -0
- package/lib/types.mjs +334 -0
- package/looks/academic.css +8 -0
- package/looks/compact.css +5 -0
- package/looks/report.css +8 -0
- package/looks/technical.css +11 -0
- package/mcp.mjs +263 -0
- package/package.json +97 -4
- package/schema/settings.schema.json +768 -0
- package/studio/app.mjs +589 -0
- package/studio/index.html +113 -0
- package/studio/model.mjs +316 -0
- package/studio/sample.md +53 -0
- package/studio/style.css +497 -0
- package/templates/academic.json +26 -0
- package/templates/corporate.json +24 -0
- package/templates/minimal.json +6 -0
- package/templates/simple.json +12 -0
- package/templates/two-logo.json +27 -0
- package/tool-schemas.mjs +215 -0
- package/vendor/katex-inline.css +1 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Studio: design your PDF pages</title>
|
|
7
|
+
<link rel="icon" href="data:,">
|
|
8
|
+
<link rel="stylesheet" href="/style.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div class="app" id="app">
|
|
12
|
+
<section class="rail" aria-label="Page design">
|
|
13
|
+
<header class="rail-head">
|
|
14
|
+
<h1>Design your pages</h1>
|
|
15
|
+
<p class="lede">Every choice shows on the real PDF, on the right.</p>
|
|
16
|
+
</header>
|
|
17
|
+
|
|
18
|
+
<div class="rail-body">
|
|
19
|
+
<div id="notices"></div>
|
|
20
|
+
|
|
21
|
+
<section class="group">
|
|
22
|
+
<h2>Page style</h2>
|
|
23
|
+
<div class="looks" id="looks" role="radiogroup" aria-label="Page style"></div>
|
|
24
|
+
</section>
|
|
25
|
+
|
|
26
|
+
<section class="group">
|
|
27
|
+
<h2>Fonts and paper</h2>
|
|
28
|
+
<div class="fields">
|
|
29
|
+
<label class="label" for="font">Text font</label>
|
|
30
|
+
<select id="font"></select>
|
|
31
|
+
|
|
32
|
+
<label class="label" for="heading-font">Title font</label>
|
|
33
|
+
<select id="heading-font"></select>
|
|
34
|
+
|
|
35
|
+
<label class="label" for="format">Paper</label>
|
|
36
|
+
<div class="pair">
|
|
37
|
+
<select id="format"></select>
|
|
38
|
+
<div class="seg" id="orientation" role="radiogroup" aria-label="Orientation"></div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<span class="label" id="margin-label">Margins</span>
|
|
42
|
+
<div class="seg" id="margin" role="radiogroup" aria-labelledby="margin-label"></div>
|
|
43
|
+
|
|
44
|
+
<label class="label" for="highlight">Code colours</label>
|
|
45
|
+
<select id="highlight"></select>
|
|
46
|
+
</div>
|
|
47
|
+
</section>
|
|
48
|
+
|
|
49
|
+
<section class="group">
|
|
50
|
+
<h2>Header and footer</h2>
|
|
51
|
+
<p class="hint">Pick a starting point, then click any spot on the page to change it.</p>
|
|
52
|
+
<div class="seg wrap" id="layouts" aria-label="Starting layout"></div>
|
|
53
|
+
|
|
54
|
+
<div class="sheet" id="sheet">
|
|
55
|
+
<div class="band-box"><div class="band" id="band-header"></div></div>
|
|
56
|
+
<div class="sheet-body" aria-hidden="true">
|
|
57
|
+
<i class="ln t"></i><i class="ln"></i><i class="ln"></i><i class="ln s"></i>
|
|
58
|
+
<i class="fold"></i>
|
|
59
|
+
<i class="ln"></i><i class="ln s"></i>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="band-box"><div class="band" id="band-footer"></div></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="slot-editor" id="slot-editor"></div>
|
|
65
|
+
|
|
66
|
+
<div class="row">
|
|
67
|
+
<label class="check"><input type="checkbox" id="line-header"> Line under the header</label>
|
|
68
|
+
<label class="check"><input type="checkbox" id="line-footer"> Line above the footer</label>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="fields spaced">
|
|
71
|
+
<span class="label" id="size-label">Text</span>
|
|
72
|
+
<div class="pair">
|
|
73
|
+
<div class="seg" id="size" role="radiogroup" aria-labelledby="size-label"></div>
|
|
74
|
+
<input type="color" class="color fixed" id="color" aria-label="Text colour" title="Text colour">
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</section>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<footer class="rail-foot">
|
|
81
|
+
<div class="where">
|
|
82
|
+
<span id="save-state">Not saved yet</span>
|
|
83
|
+
<code id="save-path"></code>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="actions">
|
|
86
|
+
<button type="button" class="btn" id="editors-open">Add to my editor</button>
|
|
87
|
+
<button type="button" class="btn primary" id="save">Save</button>
|
|
88
|
+
</div>
|
|
89
|
+
</footer>
|
|
90
|
+
</section>
|
|
91
|
+
|
|
92
|
+
<section class="desk" aria-label="Preview">
|
|
93
|
+
<div class="frames">
|
|
94
|
+
<iframe id="frame-a" title="PDF preview"></iframe>
|
|
95
|
+
<iframe id="frame-b" class="back" title="PDF preview, loading" tabindex="-1"></iframe>
|
|
96
|
+
</div>
|
|
97
|
+
<div class="problem" id="problem" hidden></div>
|
|
98
|
+
<p class="status" id="status" role="status">Drawing the first page…</p>
|
|
99
|
+
</section>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<dialog id="editors">
|
|
103
|
+
<div class="dialog-head">
|
|
104
|
+
<h2>Add to my editor</h2>
|
|
105
|
+
<button type="button" class="btn quiet" id="editors-close">Close</button>
|
|
106
|
+
</div>
|
|
107
|
+
<p class="hint">Do this once per editor. After that, exporting a Markdown file uses the layout you saved here.</p>
|
|
108
|
+
<div id="editors-list"></div>
|
|
109
|
+
</dialog>
|
|
110
|
+
|
|
111
|
+
<script type="module" src="/app.mjs"></script>
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|
package/studio/model.mjs
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio model: converts between a settings file and the handful of choices
|
|
3
|
+
* the Studio screen offers. Pure functions, no DOM and no Node APIs, so the
|
|
4
|
+
* browser and the unit tests share this file.
|
|
5
|
+
*
|
|
6
|
+
* Draft shape:
|
|
7
|
+
* { look, font, heading_font, highlight, page_format, orientation, margin,
|
|
8
|
+
* header: Area, footer: Area, text_size, color }
|
|
9
|
+
* font / heading_font = a preset name, "look" (whatever the page style
|
|
10
|
+
* brings) or "custom" (a hand-written font_family kept from the file)
|
|
11
|
+
* Area = { left: Slot, center: Slot, right: Slot, line: boolean, custom: boolean }
|
|
12
|
+
* Slot = { kind: "none" | "text" | "image", text: string, image: string, size: number }
|
|
13
|
+
* size = logo size in percent (100 = 12 mm tall)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const ZONES = ["left", "center", "right"];
|
|
17
|
+
export const MARGINS = { narrow: 10, normal: 15, wide: 25 };
|
|
18
|
+
export const TEXT_SIZES = { s: "8px", m: "10px", l: "12px" };
|
|
19
|
+
export const LINE = "1px solid #c9d1d9";
|
|
20
|
+
export const DEFAULT_COLOR = "#5b6773";
|
|
21
|
+
export const DEFAULT_HIGHLIGHT = "github.css";
|
|
22
|
+
export const LOGO = { baseMm: 12, min: 50, max: 200, step: 5 };
|
|
23
|
+
|
|
24
|
+
export const CHIPS = [
|
|
25
|
+
{ label: "Title", insert: "{title}" },
|
|
26
|
+
{ label: "Page number", insert: "{page}" },
|
|
27
|
+
{ label: "Page 1 of 9", insert: "Page {page} of {pages}" },
|
|
28
|
+
{ label: "Date", insert: "{date}" },
|
|
29
|
+
{ label: "Author", insert: "{author}" },
|
|
30
|
+
{ label: "File name", insert: "{filename}" },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const slot = (text = "") => ({ kind: text ? "text" : "none", text, image: "", size: 100 });
|
|
34
|
+
const logo = (image = "", size = 100) => ({ kind: "image", text: "", image, size });
|
|
35
|
+
const area = (left, center, right, line = false) => ({
|
|
36
|
+
left: typeof left === "object" ? left : slot(left),
|
|
37
|
+
center: typeof center === "object" ? center : slot(center),
|
|
38
|
+
right: typeof right === "object" ? right : slot(right),
|
|
39
|
+
line,
|
|
40
|
+
custom: false,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** Starting points offered above the page diagram. */
|
|
44
|
+
export const LAYOUTS = [
|
|
45
|
+
{
|
|
46
|
+
id: "none",
|
|
47
|
+
label: "None",
|
|
48
|
+
header: () => area(),
|
|
49
|
+
footer: () => area(),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "numbers",
|
|
53
|
+
label: "Page numbers",
|
|
54
|
+
header: () => area(),
|
|
55
|
+
footer: () => area("", "{page} / {pages}", ""),
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "titled",
|
|
59
|
+
label: "Title and date",
|
|
60
|
+
header: () => area("{title}", "", "{date}", true),
|
|
61
|
+
footer: () => area("", "Page {page} of {pages}", ""),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "report",
|
|
65
|
+
label: "Report",
|
|
66
|
+
header: () => area("{title}", "", "{author}", true),
|
|
67
|
+
footer: () => area("{date}", "", "Page {page} of {pages}", true),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "letterhead",
|
|
71
|
+
label: "Logo",
|
|
72
|
+
header: () => area(logo(), "", "{title}", true),
|
|
73
|
+
footer: () => area("", "Page {page} of {pages}", ""),
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/** What Studio proposes to someone who has no settings file yet. */
|
|
78
|
+
export const FIRST_LAYOUT = "titled";
|
|
79
|
+
|
|
80
|
+
export function emptyDraft() {
|
|
81
|
+
return {
|
|
82
|
+
look: "clean",
|
|
83
|
+
font: "look",
|
|
84
|
+
heading_font: "look",
|
|
85
|
+
highlight: DEFAULT_HIGHLIGHT,
|
|
86
|
+
page_format: "A4",
|
|
87
|
+
orientation: "portrait",
|
|
88
|
+
margin: "normal",
|
|
89
|
+
header: area(),
|
|
90
|
+
footer: area(),
|
|
91
|
+
text_size: "m",
|
|
92
|
+
color: DEFAULT_COLOR,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const isPlain = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
97
|
+
const mm = (value) => {
|
|
98
|
+
const m = /^\s*([\d.]+)\s*mm\s*$/.exec(String(value ?? ""));
|
|
99
|
+
return m ? Number(m[1]) : null;
|
|
100
|
+
};
|
|
101
|
+
const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
|
|
102
|
+
const nameOfMargin = (side) => Object.entries(MARGINS).find(([, v]) => v === side)?.[0] ?? null;
|
|
103
|
+
|
|
104
|
+
/** Side margin a look brings, in mm (15 when it has none). */
|
|
105
|
+
export function lookMargin(look, looks = {}) {
|
|
106
|
+
return mm(looks[look]?.margin?.left) ?? MARGINS.normal;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What picking a look suggests for the controls it influences. */
|
|
110
|
+
export function lookDefaults(look, looks = {}) {
|
|
111
|
+
return {
|
|
112
|
+
margin: nameOfMargin(lookMargin(look, looks)) ?? "normal",
|
|
113
|
+
highlight: looks[look]?.highlight ?? DEFAULT_HIGHLIGHT,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const sizeFromHeight = (height) => {
|
|
118
|
+
const h = mm(height);
|
|
119
|
+
return h === null ? 100 : clamp(Math.round((h / LOGO.baseMm) * 100), LOGO.min, LOGO.max);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** One zone of a settings header/footer → Slot, or null when Studio cannot show it. */
|
|
123
|
+
function readZone(cfg, zone) {
|
|
124
|
+
const structured = cfg[zone];
|
|
125
|
+
if (structured !== undefined && structured !== null) {
|
|
126
|
+
if (isPlain(structured) && structured.type === "text" && typeof structured.content === "string") {
|
|
127
|
+
return slot(structured.content);
|
|
128
|
+
}
|
|
129
|
+
if (isPlain(structured) && structured.type === "image" && typeof structured.src === "string") {
|
|
130
|
+
return logo(structured.src, sizeFromHeight(structured.height));
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const image = cfg[`${zone}_image`];
|
|
135
|
+
if (typeof image === "string" && image) return logo(image, sizeFromHeight(cfg[`${zone}_image_height`]));
|
|
136
|
+
const text = cfg[`${zone}_text`];
|
|
137
|
+
return slot(typeof text === "string" ? text : "");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function readArea(cfg, lineKey) {
|
|
141
|
+
const out = area();
|
|
142
|
+
if (!isPlain(cfg)) return out;
|
|
143
|
+
for (const zone of ZONES) {
|
|
144
|
+
const s = readZone(cfg, zone);
|
|
145
|
+
if (s === null) return { ...area(), custom: true };
|
|
146
|
+
out[zone] = s;
|
|
147
|
+
}
|
|
148
|
+
out.line = Boolean(cfg[lineKey]);
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const SIDES = ["top", "right", "bottom", "left"];
|
|
153
|
+
const sameMargin = (a, b) => isPlain(a) && isPlain(b) && SIDES.every((s) => mm(a[s]) === mm(b[s]));
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Settings file content → draft.
|
|
157
|
+
* @param {object} raw parsed settings file (not expanded)
|
|
158
|
+
* @param {{looks?: object, templates?: object}} [ctx] preset data from the server
|
|
159
|
+
*/
|
|
160
|
+
export function settingsToDraft(raw, ctx = {}) {
|
|
161
|
+
const draft = emptyDraft();
|
|
162
|
+
if (!isPlain(raw)) return draft;
|
|
163
|
+
const looks = ctx.looks ?? {};
|
|
164
|
+
const template = isPlain(ctx.templates?.[raw.template]) ? ctx.templates[raw.template] : {};
|
|
165
|
+
|
|
166
|
+
if (typeof raw.look === "string" && looks[raw.look]) draft.look = raw.look;
|
|
167
|
+
const defaults = lookDefaults(draft.look, looks);
|
|
168
|
+
if (typeof raw.font === "string") draft.font = raw.font;
|
|
169
|
+
else if (typeof raw.font_family === "string" && raw.font_family) draft.font = "custom";
|
|
170
|
+
if (typeof raw.heading_font === "string") draft.heading_font = raw.heading_font;
|
|
171
|
+
else if (typeof raw.heading_font_family === "string" && raw.heading_font_family) draft.heading_font = "custom";
|
|
172
|
+
draft.highlight = typeof raw.highlight_style === "string" ? raw.highlight_style : defaults.highlight;
|
|
173
|
+
if (typeof raw.page_format === "string") draft.page_format = raw.page_format;
|
|
174
|
+
if (raw.orientation === "landscape") draft.orientation = "landscape";
|
|
175
|
+
|
|
176
|
+
const header = raw.header ?? template.header;
|
|
177
|
+
const footer = raw.footer ?? template.footer;
|
|
178
|
+
draft.header = readArea(header, "border_bottom");
|
|
179
|
+
draft.footer = readArea(footer, "border_top");
|
|
180
|
+
|
|
181
|
+
const size = (isPlain(header) && header.font_size) || (isPlain(footer) && footer.font_size);
|
|
182
|
+
draft.text_size = size === TEXT_SIZES.s ? "s" : size === TEXT_SIZES.l ? "l" : "m";
|
|
183
|
+
const color = (isPlain(header) && header.color) || (isPlain(footer) && footer.color);
|
|
184
|
+
if (typeof color === "string" && /^#[0-9a-f]{3,8}$/i.test(color)) draft.color = color;
|
|
185
|
+
|
|
186
|
+
draft.margin = defaults.margin;
|
|
187
|
+
if (isPlain(raw.margin)) {
|
|
188
|
+
// Named only when Studio would write these exact margins back; anything
|
|
189
|
+
// else was set by hand and is kept as it is.
|
|
190
|
+
draft.margin = nameOfMargin(mm(raw.margin.left)) ?? "custom";
|
|
191
|
+
if (draft.margin !== "custom" && !sameMargin(draftToSettings(draft, raw, ctx).margin, raw.margin)) {
|
|
192
|
+
draft.margin = "custom";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return draft;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const filledImage = (s) => s.kind === "image" && s.image;
|
|
199
|
+
const hasContent = (a) => ZONES.some((z) => (a[z].kind === "text" && a[z].text.trim()) || filledImage(a[z]));
|
|
200
|
+
const logoMm = (s) => Number(((LOGO.baseMm * clamp(s.size ?? 100, LOGO.min, LOGO.max)) / 100).toFixed(1));
|
|
201
|
+
|
|
202
|
+
const AREA_KEYS = [
|
|
203
|
+
"height", "padding", "font_size", "color", "border_bottom", "border_top",
|
|
204
|
+
...ZONES.flatMap((z) => [z, `${z}_text`, `${z}_image`, `${z}_image_height`]),
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
function writeArea(a, previous, { lineKey, side, size, color }) {
|
|
208
|
+
if (!hasContent(a)) return null;
|
|
209
|
+
const out = isPlain(previous) ? { ...previous } : {};
|
|
210
|
+
for (const key of AREA_KEYS) delete out[key];
|
|
211
|
+
const tallest = Math.max(0, ...ZONES.filter((z) => filledImage(a[z])).map((z) => logoMm(a[z])));
|
|
212
|
+
const height = Math.max(12, Math.ceil(tallest + 6));
|
|
213
|
+
out.height = `${height}mm`;
|
|
214
|
+
out.padding = `0 ${side}mm`; // text and rule line up with the page margins
|
|
215
|
+
out.font_size = size;
|
|
216
|
+
out.color = color;
|
|
217
|
+
if (a.line) out[lineKey] = LINE;
|
|
218
|
+
for (const zone of ZONES) {
|
|
219
|
+
const s = a[zone];
|
|
220
|
+
if (s.kind === "text" && s.text.trim()) out[`${zone}_text`] = s.text;
|
|
221
|
+
if (filledImage(s)) {
|
|
222
|
+
out[`${zone}_image`] = s.image;
|
|
223
|
+
out[`${zone}_image_height`] = `${logoMm(s)}mm`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return { cfg: out, height };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Draft → settings file content. Keys Studio does not manage are kept as-is.
|
|
231
|
+
* @param {object} draft
|
|
232
|
+
* @param {object} [raw] current file content
|
|
233
|
+
* @param {{looks?: object}} [ctx]
|
|
234
|
+
*/
|
|
235
|
+
export function draftToSettings(draft, raw = {}, ctx = {}) {
|
|
236
|
+
const out = isPlain(raw) ? { ...raw } : {};
|
|
237
|
+
delete out.template; // expanded into header/footer below
|
|
238
|
+
const looks = ctx.looks ?? {};
|
|
239
|
+
const defaults = lookDefaults(draft.look, looks);
|
|
240
|
+
|
|
241
|
+
if (draft.look === "clean") delete out.look;
|
|
242
|
+
else out.look = draft.look;
|
|
243
|
+
|
|
244
|
+
for (const [choice, preset, stack] of [
|
|
245
|
+
[draft.font, "font", "font_family"],
|
|
246
|
+
[draft.heading_font, "heading_font", "heading_font_family"],
|
|
247
|
+
]) {
|
|
248
|
+
if (choice === "custom") continue; // hand-written stack stays
|
|
249
|
+
delete out[stack];
|
|
250
|
+
if (choice === "look") delete out[preset];
|
|
251
|
+
else out[preset] = choice;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (draft.highlight === defaults.highlight) delete out.highlight_style;
|
|
255
|
+
else out.highlight_style = draft.highlight;
|
|
256
|
+
|
|
257
|
+
if (draft.page_format === "A4") delete out.page_format;
|
|
258
|
+
else out.page_format = draft.page_format;
|
|
259
|
+
if (draft.orientation === "landscape") out.orientation = "landscape";
|
|
260
|
+
else delete out.orientation;
|
|
261
|
+
|
|
262
|
+
const fromLook = lookMargin(draft.look, looks);
|
|
263
|
+
const base =
|
|
264
|
+
draft.margin === "custom" ? (mm(raw?.margin?.left) ?? fromLook) : (MARGINS[draft.margin] ?? fromLook);
|
|
265
|
+
const style = { side: base, size: TEXT_SIZES[draft.text_size] ?? TEXT_SIZES.m, color: draft.color };
|
|
266
|
+
|
|
267
|
+
// Header and footer are drawn inside the page margin: grow it to make room.
|
|
268
|
+
let top = base;
|
|
269
|
+
let bottom = base;
|
|
270
|
+
if (!draft.header.custom) {
|
|
271
|
+
const h = writeArea(draft.header, raw?.header, { ...style, lineKey: "border_bottom" });
|
|
272
|
+
if (h) {
|
|
273
|
+
out.header = h.cfg;
|
|
274
|
+
top = Math.max(base, h.height + 8);
|
|
275
|
+
} else delete out.header;
|
|
276
|
+
}
|
|
277
|
+
if (!draft.footer.custom) {
|
|
278
|
+
const f = writeArea(draft.footer, raw?.footer, { ...style, lineKey: "border_top" });
|
|
279
|
+
if (f) {
|
|
280
|
+
out.footer = f.cfg;
|
|
281
|
+
bottom = Math.max(base, f.height + 8);
|
|
282
|
+
} else delete out.footer;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (draft.margin !== "custom") {
|
|
286
|
+
const asTheLook = base === fromLook && top === base && bottom === base;
|
|
287
|
+
if (asTheLook) delete out.margin;
|
|
288
|
+
else out.margin = { top: `${top}mm`, right: `${base}mm`, bottom: `${bottom}mm`, left: `${base}mm` };
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Which starting layout a draft matches, if any (for highlighting the picker). */
|
|
294
|
+
export function matchLayout(draft) {
|
|
295
|
+
const key = (a) => ZONES.map((z) => `${a[z].kind}:${a[z].kind === "text" ? a[z].text : ""}`).join("|") + a.line;
|
|
296
|
+
for (const l of LAYOUTS) {
|
|
297
|
+
if (key(l.header()) === key(draft.header) && key(l.footer()) === key(draft.footer)) return l.id;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Human rendering of a slot text for the page diagram ("{page}" → "1"). */
|
|
303
|
+
export function renderText(text, sample = {}) {
|
|
304
|
+
const today = sample.date ?? new Date().toISOString().slice(0, 10);
|
|
305
|
+
const values = {
|
|
306
|
+
page: "1",
|
|
307
|
+
pages: String(sample.pages ?? 2),
|
|
308
|
+
title: sample.title ?? "Document title",
|
|
309
|
+
author: sample.author ?? "Author",
|
|
310
|
+
filename: sample.filename ?? "document.md",
|
|
311
|
+
date: today,
|
|
312
|
+
time: "09:30",
|
|
313
|
+
datetime: `${today} 09:30`,
|
|
314
|
+
};
|
|
315
|
+
return String(text).replace(/\{(\w+)(?::[^}]*)?\}/g, (all, name) => values[name] ?? all);
|
|
316
|
+
}
|
package/studio/sample.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Quarterly report
|
|
3
|
+
author: Alex Morgan
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Quarterly report
|
|
7
|
+
|
|
8
|
+
This is a sample document. It is here so you can see your page style, fonts,
|
|
9
|
+
header and footer on a real PDF while you choose them. Your own documents are
|
|
10
|
+
not changed.
|
|
11
|
+
|
|
12
|
+
## Summary
|
|
13
|
+
|
|
14
|
+
Revenue grew for the third quarter in a row. The team shipped two releases,
|
|
15
|
+
closed the oldest support tickets and cut the build time in half.
|
|
16
|
+
|
|
17
|
+
- Releases: **2**, both on schedule
|
|
18
|
+
- Support backlog: down from 41 tickets to 12
|
|
19
|
+
- Build time: 9 minutes, was 18
|
|
20
|
+
|
|
21
|
+
> Headers and footers repeat on every page. Page numbers update by themselves.
|
|
22
|
+
|
|
23
|
+
## Figures
|
|
24
|
+
|
|
25
|
+
| Month | Revenue | Change |
|
|
26
|
+
|-----------|--------:|-------:|
|
|
27
|
+
| July | 41,200 | +4 % |
|
|
28
|
+
| August | 43,900 | +7 % |
|
|
29
|
+
| September | 47,300 | +8 % |
|
|
30
|
+
|
|
31
|
+
## A little code
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
function total(rows) {
|
|
35
|
+
return rows.reduce((sum, row) => sum + row.revenue, 0);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
<div style="page-break-after: always"></div>
|
|
40
|
+
|
|
41
|
+
## Next quarter
|
|
42
|
+
|
|
43
|
+
The plan for the coming months is short on purpose.
|
|
44
|
+
|
|
45
|
+
1. Finish the migration started in August.
|
|
46
|
+
2. Publish the new documentation.
|
|
47
|
+
3. Keep the support backlog under 15 tickets.
|
|
48
|
+
|
|
49
|
+
### Notes
|
|
50
|
+
|
|
51
|
+
Text in a document like this one is mostly paragraphs, so this page has one
|
|
52
|
+
more. It shows how line length, spacing and margins feel when there is a full
|
|
53
|
+
block of prose on the sheet rather than a list or a table.
|