@litfamily/litcodex 1.0.15 → 1.0.16
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/README-Ko-KR.md +10 -10
- package/README.md +10 -10
- package/dist/install/generated-skill-payload-hashes.d.ts +101 -40
- package/dist/install/generated-skill-payload-hashes.js +101 -40
- package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
- package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
- package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
- package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
- package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
- package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
- package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
- package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
- package/marketplace/plugins/litcodex/skills/frontend-ui-ux/THIRD-PARTY-NOTICE.txt +0 -2
- package/marketplace/plugins/litcodex/skills/lit-docx/SKILL.md +16 -12
- package/marketplace/plugins/litcodex/skills/lit-docx/references/components.md +113 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/direction-step.md +164 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/01-report-ko.md +95 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/02-brief-ko.md +45 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/03-manual-ko.md +105 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/04-proposal-ko.md +97 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/05-memo-en.md +34 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/06-journal-en.md +89 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/07-report-en.md +101 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/08-proposal-en.md +94 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/09-memo-ko.md +34 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/page-composition.md +141 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/brief.md +70 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/journal.md +73 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/manual.md +70 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/memo.md +75 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/proposal.md +71 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/report.md +83 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_docx.py +401 -58
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_craft.py +124 -1
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_design.py +2446 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_layout.py +960 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/slop_lint.py +21 -6
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/brief.yaml +28 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/journal.yaml +26 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/manual.yaml +26 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/memo.yaml +27 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/proposal.yaml +27 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/report.yaml +27 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/SKILL.md +12 -11
- package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/Pretendard-Bold.otf +0 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/Pretendard-Regular.otf +0 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/anti-slop-checklist.md +33 -29
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/authoring-guide.md +11 -2
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/density-and-fill.md +179 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/design-system-azure.md +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/direction-step.md +203 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +185 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/02-pitch-studio-en.md +162 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +229 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/04-research-talk-paper-en.md +212 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/05-research-keynote-night-ko.md +191 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +175 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/07-data-review-night-en.md +241 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/08-field-report-atlas-ko.md +168 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +219 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/10-status-update-ledger-en.md +157 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/11-portfolio-studio-ko.md +183 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/12-tutorial-chalk-en.md +176 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/13-status-update-gazette-ko.md +157 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/interview-protocol.md +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/layout-families.md +210 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/title-treatments.md +146 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/atlas.md +113 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/chalk.md +115 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/gazette.md +118 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/ledger.md +129 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/night.md +126 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/paper.md +109 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/signal.md +121 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/studio.md +111 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/compile-deck.js +65 -17
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/craft_extras.py +654 -11
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/embed_fonts.py +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/inventory.py +32 -2
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/directive-parser.js +2 -2
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/grid-resolver.js +521 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/layout-resolver.js +401 -16
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/markdown-loader.js +6 -4
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-adapter-html.js +2 -2
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-adapter-pptx.js +498 -145
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-pack.js +3558 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/slide-ast.js +54 -6
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/template-registry.js +335 -11
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +2 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/qa_deck.py +99 -19
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/validate_pptx.py +6 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/boilerplate_professional.css +6 -6
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-A2Z/layout-mapping.yaml +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-A2Z/template.yaml +4 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-PRO/layout-mapping.yaml +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-PRO/template.yaml +4 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +105 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +110 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +105 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +106 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/night/pack.yaml +106 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/paper/pack.yaml +111 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/signal/pack.yaml +107 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/studio/pack.yaml +105 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +1 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +6 -6
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/gate.mjs +1 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.mjs +2 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +1 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +1 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/style-bibles.md +2 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +1 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/type-and-timing.md +3 -3
- package/node_modules/@litcodex/lit-loop/package.json +1 -1
- package/package.json +2 -2
- package/readme-assets/badge-version.svg +1 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/PretendardGOV-Bold.otf +0 -0
- package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/PretendardGOV-Regular.otf +0 -0
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const os = require("os");
|
|
16
16
|
const path = require("path");
|
|
17
|
-
const PptxGenJS = require("pptxgenjs");
|
|
18
17
|
const { extractContent, looksLikeKpi } = require("./layout-resolver");
|
|
18
|
+
const { LEGACY_TOKENS } = require("./template-registry");
|
|
19
19
|
|
|
20
|
-
// Narrowest a KPI badge can be and still read as one glance.
|
|
21
|
-
|
|
20
|
+
// Narrowest a KPI badge can be and still read as one glance (template token kpi.minCardWidth).
|
|
21
|
+
let KPI_MIN_CARD_WIDTH_IN = LEGACY_TOKENS.kpi.minCardWidth;
|
|
22
|
+
let KPI_GAP = LEGACY_TOKENS.kpi.gap;
|
|
22
23
|
|
|
23
24
|
const TOOLKIT_ROOT = path.resolve(__dirname, "../..");
|
|
24
25
|
const ASSETS_MEDIA = path.join(TOOLKIT_ROOT, "assets", "media");
|
|
@@ -56,13 +57,15 @@ function linkedTableCell(text, options) {
|
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
// ── Text style constants (template
|
|
60
|
+
// ── Text style constants (defaults; every template reassigns them in render()).
|
|
60
61
|
// These are reassigned from the template at the start of render() so the same
|
|
61
62
|
// adapter serves any enrolled template (e.g. BOILERPLATE-PRETENDARD).
|
|
62
63
|
let FONT_BOLD = "Pretendard";
|
|
63
64
|
let FONT_MEDIUM = "Pretendard";
|
|
64
65
|
let FONT_LIGHT = "Pretendard";
|
|
65
66
|
let CHAR_SPACING = -0.7;
|
|
67
|
+
// Chart colours and faces for templates without the rich palette; set per render().
|
|
68
|
+
let PLAIN_CHART_STYLE = { series: ["3C3836", "689D6A", "D79921", "B16286"], ink: "3C3836", ink_muted: "6E6256", line: "CBC2B5", titleFont: "Pretendard", bodyFont: "Pretendard" };
|
|
66
69
|
|
|
67
70
|
function expandHome(p) {
|
|
68
71
|
if (p === "~") return os.homedir();
|
|
@@ -122,43 +125,52 @@ function containBox(x, y, w, h, imageSize) {
|
|
|
122
125
|
return { x: x + (w - fittedW) / 2, y, w: fittedW, h };
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
// Bullet items
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
let
|
|
129
|
-
let SECTION_ACCENT = "334155"; // neutral fallback, reassigned per-template
|
|
128
|
+
// Bullet items. Geometry comes from the template's tokens (bullet.*, secHeader.*, summary.*,
|
|
129
|
+
// toc.*), reassigned in render(); these defaults are the legacy values.
|
|
130
|
+
let BULLET_COLOR = "1D4ED8"; // bullet color (reassigned per template)
|
|
131
|
+
let SECTION_ACCENT = "1D4ED8"; // section-card / accent color (reassigned per template)
|
|
130
132
|
const BULLET_PREFIX = "\u2022 "; // "• " (bullet + two spaces)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const BULLET_H = 0.38;
|
|
134
|
-
const BULLET_Y_SPACING = 0.42;
|
|
135
|
-
const BULLET_LINE_SPACING = 1.25;
|
|
133
|
+
let BULLET_X = LEGACY_TOKENS.bullet.x;
|
|
134
|
+
let BULLET_W = LEGACY_TOKENS.bullet.w;
|
|
136
135
|
|
|
137
136
|
// Section headers
|
|
138
137
|
let SEC_HEADER_FONT = FONT_BOLD;
|
|
139
|
-
|
|
138
|
+
let SEC_HEADER_SIZE = LEGACY_TOKENS.secHeader.size;
|
|
140
139
|
const SEC_HEADER_COLOR = "000000";
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
let SEC_HEADER_X = LEGACY_TOKENS.secHeader.x;
|
|
141
|
+
let SEC_HEADER_W = LEGACY_TOKENS.secHeader.w;
|
|
142
|
+
let SEC_HEADER_H = LEGACY_TOKENS.secHeader.h;
|
|
144
143
|
|
|
145
144
|
// Summary (narrow width)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
let SUMMARY_HEADER_W = LEGACY_TOKENS.summary.headerW;
|
|
146
|
+
let SUMMARY_BULLET_W = LEGACY_TOKENS.summary.bulletW;
|
|
147
|
+
let SUMMARY_BULLET_SIZE = LEGACY_TOKENS.summary.bulletSize;
|
|
148
|
+
let SUMMARY_BULLET_H = LEGACY_TOKENS.summary.bulletH;
|
|
149
|
+
let SUMMARY_BULLET_Y_SPACING = LEGACY_TOKENS.summary.ySpacing;
|
|
150
|
+
let SUMMARY_BULLET_LINE_SPACING = LEGACY_TOKENS.summary.lineSpacing;
|
|
152
151
|
|
|
153
152
|
// TOC items (separate shapes)
|
|
154
153
|
let TOC_FONT = FONT_BOLD;
|
|
155
|
-
|
|
154
|
+
let TOC_SIZE = LEGACY_TOKENS.toc.size;
|
|
156
155
|
const TOC_COLOR = "000000";
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
let TOC_X = LEGACY_TOKENS.toc.x;
|
|
157
|
+
let TOC_W = LEGACY_TOKENS.toc.w;
|
|
158
|
+
let TOC_H = LEGACY_TOKENS.toc.h;
|
|
159
|
+
let TOC_Y_START = LEGACY_TOKENS.toc.yStart;
|
|
160
|
+
let TOC_Y_SPACING = LEGACY_TOKENS.toc.ySpacing;
|
|
161
|
+
|
|
162
|
+
/** Reassign the token-driven geometry from the template's pack (legacy values when absent). */
|
|
163
|
+
function applyTokens(tokens) {
|
|
164
|
+
const t = tokens || LEGACY_TOKENS;
|
|
165
|
+
({ x: BULLET_X, w: BULLET_W } = t.bullet);
|
|
166
|
+
({ size: SEC_HEADER_SIZE, x: SEC_HEADER_X, w: SEC_HEADER_W, h: SEC_HEADER_H } = t.secHeader);
|
|
167
|
+
({ headerW: SUMMARY_HEADER_W, bulletW: SUMMARY_BULLET_W, bulletSize: SUMMARY_BULLET_SIZE, bulletH: SUMMARY_BULLET_H,
|
|
168
|
+
ySpacing: SUMMARY_BULLET_Y_SPACING, lineSpacing: SUMMARY_BULLET_LINE_SPACING } = t.summary);
|
|
169
|
+
({ size: TOC_SIZE, x: TOC_X, w: TOC_W, h: TOC_H, yStart: TOC_Y_START, ySpacing: TOC_Y_SPACING } = t.toc);
|
|
170
|
+
({ pad: CARD_PAD, chip: CARD_CHIP, minH: CARD_MIN_H, gap: CARD_GAP, radius: CARD_RADIUS } = t.card);
|
|
171
|
+
({ minCardWidth: KPI_MIN_CARD_WIDTH_IN, gap: KPI_GAP } = t.kpi);
|
|
172
|
+
NOTICE = { ...t.notice };
|
|
173
|
+
}
|
|
162
174
|
|
|
163
175
|
function weightedTextLength(text) {
|
|
164
176
|
let total = 0;
|
|
@@ -397,7 +409,7 @@ function estimateDiagnosticCardHeight(card, w) {
|
|
|
397
409
|
return Math.max(0.56, Math.min(2.35, padY * 2 + titleH + bodyH));
|
|
398
410
|
}
|
|
399
411
|
|
|
400
|
-
function renderCramStressBody(slide, items,
|
|
412
|
+
function renderCramStressBody(slide, items, pageH) {
|
|
401
413
|
const cards = bodyItemsToDiagnosticCards(items);
|
|
402
414
|
const columns = 3;
|
|
403
415
|
const groups = cards.length ? splitCardsByWeight(cards, columns) : splitLinesByWeight(bodyItemsToDiagnosticLines(items), columns).map((group) => [{ title: "", body: group }]);
|
|
@@ -543,7 +555,7 @@ function renderCramStressSlide(slide, slideSpec, pageW, pageH, sourceDir) {
|
|
|
543
555
|
});
|
|
544
556
|
}
|
|
545
557
|
if (regions.body && regions.body.content && regions.body.content.type === "body") {
|
|
546
|
-
renderCramStressBody(slide, regions.body.content.items || [],
|
|
558
|
+
renderCramStressBody(slide, regions.body.content.items || [], pageH);
|
|
547
559
|
}
|
|
548
560
|
if (regions.image && regions.image.content) {
|
|
549
561
|
renderCramStressImageSheet(slide, regions.image.content, sourceDir, pageW, pageH);
|
|
@@ -607,7 +619,7 @@ function buildFontRoles(templateObj) {
|
|
|
607
619
|
* Add decoration elements to a pptxgenjs slide.
|
|
608
620
|
* Note: slide_number is intentionally omitted — the reference template has none.
|
|
609
621
|
*/
|
|
610
|
-
function addDecorations(slide, decorations,
|
|
622
|
+
function addDecorations(slide, decorations, fontRoles) {
|
|
611
623
|
if (!decorations || !Array.isArray(decorations)) return;
|
|
612
624
|
|
|
613
625
|
for (const d of decorations) {
|
|
@@ -685,7 +697,7 @@ function addDecorations(slide, decorations, slideIdx, fontRoles) {
|
|
|
685
697
|
});
|
|
686
698
|
slide.addText(d.text || "Confidential", {
|
|
687
699
|
x: mX, y: mY, w: mW, h: mH,
|
|
688
|
-
fontFace: role.font ||
|
|
700
|
+
fontFace: role.font || FONT_MEDIUM,
|
|
689
701
|
fontSize: role.size || 14,
|
|
690
702
|
color: role.color || "C00000",
|
|
691
703
|
align: role.align || "center",
|
|
@@ -985,7 +997,7 @@ function addSummaryShapes(slide, content, region) {
|
|
|
985
997
|
|
|
986
998
|
/**
|
|
987
999
|
* Add TOC items as separate text shapes, matching TEMPLATE-PPTX.pptx exactly.
|
|
988
|
-
* Each item is: "N. text" in the
|
|
1000
|
+
* Each item is: "N. text" in the bold face at 18pt, w=7.5, h=0.55, spaced 0.65" apart.
|
|
989
1001
|
*/
|
|
990
1002
|
function addTocShapes(slide, items) {
|
|
991
1003
|
let y = TOC_Y_START;
|
|
@@ -1106,7 +1118,7 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1106
1118
|
fontSize: opts.fontSize,
|
|
1107
1119
|
color: opts.color,
|
|
1108
1120
|
...(opts.charSpacing != null ? { charSpacing: opts.charSpacing } : {}),
|
|
1109
|
-
}), opts);
|
|
1121
|
+
}), name === "title" ? { ...opts, objectName: "title@legacy" } : opts);
|
|
1110
1122
|
return;
|
|
1111
1123
|
}
|
|
1112
1124
|
|
|
@@ -1122,7 +1134,14 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1122
1134
|
}
|
|
1123
1135
|
|
|
1124
1136
|
// ── KPI Table ──────────────────────────────────────────────────────
|
|
1137
|
+
if (content.type === "kpi-table" && content.chart) {
|
|
1138
|
+
renderChart(slide, content, region, PLAIN_CHART_STYLE, regionBottom);
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1125
1141
|
if (content.type === "kpi-table") {
|
|
1142
|
+
const numeric = numericColumns(content.headers || [], content.rows || []);
|
|
1143
|
+
const metrics = tableMetrics((content.rows || []).length + 1, region.y || 0, regionBottom,
|
|
1144
|
+
{ rowH: 0.35, maxRowH: 0.55, headerSize: 14, dataSize: 14 });
|
|
1126
1145
|
const headerRole = fontRoles[region.font_role_header] || fontRoles.table_header;
|
|
1127
1146
|
const dataRole = fontRoles[region.font_role_data] || fontRoles.table_data;
|
|
1128
1147
|
|
|
@@ -1137,7 +1156,7 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1137
1156
|
fontSize: headerRole ? headerRole.size : 14,
|
|
1138
1157
|
fontFace: headerRole ? headerRole.font : FONT_BOLD,
|
|
1139
1158
|
color: headerRole ? headerRole.color : "000000",
|
|
1140
|
-
align: headerRole ? headerRole.align : "left",
|
|
1159
|
+
align: numeric[content.headers.indexOf(h)] ? "right" : (headerRole ? headerRole.align : "left"),
|
|
1141
1160
|
valign: "middle",
|
|
1142
1161
|
...(headerRole && headerRole.charSpacing != null
|
|
1143
1162
|
? { charSpacing: headerRole.charSpacing }
|
|
@@ -1153,11 +1172,11 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1153
1172
|
if (content.rows) {
|
|
1154
1173
|
for (const row of content.rows) {
|
|
1155
1174
|
tableData.push(
|
|
1156
|
-
row.map((cell) => linkedTableCell(cell, {
|
|
1175
|
+
row.map((cell, ci) => linkedTableCell(cell, {
|
|
1157
1176
|
fontSize: dataRole ? dataRole.size : 14,
|
|
1158
1177
|
fontFace: dataRole ? dataRole.font : FONT_MEDIUM,
|
|
1159
1178
|
color: dataRole ? dataRole.color : "000000",
|
|
1160
|
-
align: dataRole ? dataRole.align : "left",
|
|
1179
|
+
align: numeric[ci] ? "right" : (dataRole ? dataRole.align : "left"),
|
|
1161
1180
|
valign: "middle",
|
|
1162
1181
|
...(dataRole && dataRole.charSpacing != null
|
|
1163
1182
|
? { charSpacing: dataRole.charSpacing }
|
|
@@ -1176,9 +1195,9 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1176
1195
|
y: tblY,
|
|
1177
1196
|
w: tblW,
|
|
1178
1197
|
border: { pt: 1.5, color: "000000" },
|
|
1179
|
-
colW: Array(numCols).fill(tblW / numCols),
|
|
1198
|
+
colW: numCols > 0 && content.headers ? proportionalWidths(content.headers, content.rows || [], tblW) : Array(numCols).fill(tblW / numCols),
|
|
1180
1199
|
margin: [3.6, 7.2, 3.6, 7.2],
|
|
1181
|
-
rowH:
|
|
1200
|
+
rowH: metrics.rowH,
|
|
1182
1201
|
});
|
|
1183
1202
|
return;
|
|
1184
1203
|
}
|
|
@@ -1299,7 +1318,7 @@ function addRegion(slide, name, region, fontRoles, pageH, regionBottom, isToc, s
|
|
|
1299
1318
|
}
|
|
1300
1319
|
}
|
|
1301
1320
|
|
|
1302
|
-
// ──
|
|
1321
|
+
// ── Rich card, KPI and table rendering (templates with the rich-blocks capability) ──
|
|
1303
1322
|
|
|
1304
1323
|
/** Split a title string into runs, emphasizing **word** in the primary color. */
|
|
1305
1324
|
function azureTitleRuns(text, P) {
|
|
@@ -1317,6 +1336,7 @@ function cleanMd(s) {
|
|
|
1317
1336
|
.replace(/^#{1,6}\s+/, "")
|
|
1318
1337
|
.replace(/^\s*[*-]\s+/, "")
|
|
1319
1338
|
.replace(/\*\*(.+?)\*\*/g, "$1")
|
|
1339
|
+
.replace(/(?<![\w*])\*([^*\s](?:[^*]*[^*\s])?)\*(?![\w*])/gu, "$1")
|
|
1320
1340
|
.replace(/`/g, "")
|
|
1321
1341
|
.trim();
|
|
1322
1342
|
}
|
|
@@ -1330,12 +1350,15 @@ function mdRuns(text, runOpts = {}) {
|
|
|
1330
1350
|
.replace(/^#{1,6}\s+/, "")
|
|
1331
1351
|
.replace(/^\s*[*-]\s+/, "")
|
|
1332
1352
|
.replace(/`/g, "");
|
|
1333
|
-
|
|
1353
|
+
// **x** is bold; *x* (a journal or book name) is italic.
|
|
1354
|
+
const parts = clean.split(/(\*\*[^*]+\*\*|(?<![\w*])\*[^*\s](?:[^*]*[^*\s])?\*(?![\w*]))/gu).filter((p) => p !== "");
|
|
1334
1355
|
if (parts.length === 0) return [{ text: "", options: { ...runOpts } }];
|
|
1335
1356
|
return parts.map((p) =>
|
|
1336
1357
|
p.startsWith("**") && p.endsWith("**")
|
|
1337
1358
|
? { text: p.slice(2, -2), options: { ...runOpts, bold: true } }
|
|
1338
|
-
:
|
|
1359
|
+
: p.length > 2 && p.startsWith("*") && p.endsWith("*")
|
|
1360
|
+
? { text: p.slice(1, -1), options: { ...runOpts, italic: true } }
|
|
1361
|
+
: { text: p, options: { ...runOpts } }
|
|
1339
1362
|
);
|
|
1340
1363
|
}
|
|
1341
1364
|
|
|
@@ -1370,15 +1393,63 @@ function bodyToCards(items) {
|
|
|
1370
1393
|
return cards.slice(0, 4);
|
|
1371
1394
|
}
|
|
1372
1395
|
|
|
1396
|
+
// Card geometry shared by drawing and sizing, so a card is exactly as tall as its text
|
|
1397
|
+
// (template tokens card.*; reassigned in render()).
|
|
1398
|
+
let CARD_PAD = LEGACY_TOKENS.card.pad;
|
|
1399
|
+
let CARD_CHIP = LEGACY_TOKENS.card.chip;
|
|
1400
|
+
let CARD_MIN_H = LEGACY_TOKENS.card.minH;
|
|
1401
|
+
let CARD_GAP = LEGACY_TOKENS.card.gap;
|
|
1402
|
+
let CARD_RADIUS = LEGACY_TOKENS.card.radius;
|
|
1403
|
+
|
|
1404
|
+
// Primary reading text stays at or above the 12 pt floor of the design laws.
|
|
1405
|
+
function cardBodySize(card) {
|
|
1406
|
+
return card.lines && card.lines.length > 4 ? 12 : 13;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// Card text height: the conservative wrap count, but line boxes at their real
|
|
1410
|
+
// leading (estimateTextHeight pads every paragraph, which left short cards hollow).
|
|
1411
|
+
function cardTextHeight(text, innerW, fontSize, lineSpacing) {
|
|
1412
|
+
return (estimateWrappedLines(text, innerW, fontSize) * fontSize * lineSpacing * 1.2) / 72;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
function cardHeadingHeight(card, innerW) {
|
|
1416
|
+
return card.heading ? cardTextHeight(card.heading, innerW, 15, 1.05) + 0.06 : 0;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function cardBodyHeight(card, innerW) {
|
|
1420
|
+
if (card.bodyRuns && card.bodyRuns.length) return card.bodyHeight || 0;
|
|
1421
|
+
const fs = cardBodySize(card);
|
|
1422
|
+
return (card.lines || []).reduce((sum, line) => sum + cardTextHeight(line, innerW, fs, 1.3), 0.1);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/** Height a card needs for its chip, heading and body at the width it is drawn. */
|
|
1426
|
+
function azureCardHeight(card, w) {
|
|
1427
|
+
const innerW = w - 2 * CARD_PAD;
|
|
1428
|
+
const head = card.heading ? 0.18 + Math.max(0.4, cardHeadingHeight(card, innerW)) + 0.04 : 0.18;
|
|
1429
|
+
return CARD_PAD + CARD_CHIP + head + cardBodyHeight(card, innerW) + CARD_PAD;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* The height a row of cards is drawn at: the tallest card's content, never taller
|
|
1434
|
+
* than the region the template reserves and never shorter than CARD_MIN_H. A fixed
|
|
1435
|
+
* region height left short cards mostly empty; the space below a short row is free
|
|
1436
|
+
* for the takeaway, and the craft gate reports a slide that stays thin.
|
|
1437
|
+
*/
|
|
1438
|
+
function fittedCardHeight(cards, w, regionH) {
|
|
1439
|
+
const need = Math.max(...cards.map((c) => azureCardHeight(c, w)));
|
|
1440
|
+
return Math.min(regionH, Math.max(CARD_MIN_H, need));
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1373
1443
|
/** Draw one rounded card with a numbered chip, heading, and body lines. */
|
|
1374
1444
|
function drawAzureCard(slide, x, y, w, h, card, idx, P, emphasized) {
|
|
1375
1445
|
const bg = emphasized ? hex(P.primary_deep) : hex(P.tint);
|
|
1376
1446
|
const headColor = emphasized ? "FFFFFF" : hex(P.ink);
|
|
1377
1447
|
const bodyColor = emphasized ? hex(P.emphasisTextColor) : hex(P.ink_muted);
|
|
1378
|
-
slide.addShape("roundRect", { x, y, w, h, rectRadius:
|
|
1379
|
-
const pad =
|
|
1448
|
+
slide.addShape("roundRect", { x, y, w, h, rectRadius: CARD_RADIUS, fill: { color: bg }, line: { type: "none" } });
|
|
1449
|
+
const pad = CARD_PAD;
|
|
1450
|
+
const innerW = w - 2 * pad;
|
|
1380
1451
|
// numbered chip
|
|
1381
|
-
const chip =
|
|
1452
|
+
const chip = CARD_CHIP;
|
|
1382
1453
|
slide.addShape("roundRect", {
|
|
1383
1454
|
x: x + pad, y: y + pad, w: chip, h: chip, rectRadius: 0.12,
|
|
1384
1455
|
fill: { color: emphasized ? "FFFFFF" : hex(P.primary) }, line: { type: "none" },
|
|
@@ -1391,43 +1462,45 @@ function drawAzureCard(slide, x, y, w, h, card, idx, P, emphasized) {
|
|
|
1391
1462
|
color: emphasized ? hex(P.primary_deep) : "FFFFFF",
|
|
1392
1463
|
margin: 0, lineSpacingMultiple: 1,
|
|
1393
1464
|
});
|
|
1465
|
+
const headH = cardHeadingHeight(card, innerW);
|
|
1394
1466
|
if (card.heading) {
|
|
1395
1467
|
slide.addText(card.heading, {
|
|
1396
|
-
x: x + pad, y: y + pad + chip + 0.18, w:
|
|
1468
|
+
x: x + pad, y: y + pad + chip + 0.18, w: innerW, h: Math.max(0.4, headH),
|
|
1397
1469
|
fontFace: P.titleFont, fontSize: 15, bold: true, color: headColor, align: "left", valign: "top",
|
|
1398
1470
|
charSpacing: -0.3,
|
|
1399
1471
|
});
|
|
1400
1472
|
}
|
|
1401
|
-
const bodyY = y + pad + chip + (card.heading ? 0.
|
|
1402
|
-
const bodyH = h - (bodyY - y) - 0.18;
|
|
1473
|
+
const bodyY = y + pad + chip + 0.18 + (card.heading ? Math.max(0.4, headH) + 0.04 : 0);
|
|
1474
|
+
const bodyH = Math.max(0.3, h - (bodyY - y) - 0.18);
|
|
1403
1475
|
if (card.bodyRuns && card.bodyRuns.length) {
|
|
1404
1476
|
slide.addText(card.bodyRuns, {
|
|
1405
|
-
x: x + pad, y: bodyY, w:
|
|
1477
|
+
x: x + pad, y: bodyY, w: innerW, h: bodyH,
|
|
1406
1478
|
color: bodyColor, align: "left", valign: "top", lineSpacingMultiple: card.lineSpacing || 1.28, charSpacing: -0.2,
|
|
1407
1479
|
});
|
|
1408
1480
|
} else if (card.lines && card.lines.length) {
|
|
1409
1481
|
// Shrink body font when there are many lines so it never exceeds the frame.
|
|
1410
|
-
const fs = card
|
|
1482
|
+
const fs = cardBodySize(card);
|
|
1411
1483
|
slide.addText(card.lines.join("\n"), {
|
|
1412
|
-
x: x + pad, y: bodyY, w:
|
|
1484
|
+
x: x + pad, y: bodyY, w: innerW, h: bodyH,
|
|
1413
1485
|
fontFace: P.bodyFont, fontSize: fs, color: bodyColor, align: "left", valign: "top",
|
|
1414
1486
|
lineSpacingMultiple: 1.3, charSpacing: -0.2,
|
|
1415
1487
|
});
|
|
1416
1488
|
}
|
|
1417
1489
|
}
|
|
1418
1490
|
|
|
1419
|
-
/** Render content/main body as a row of cards. */
|
|
1491
|
+
/** Render content/main body as a row of cards, as tall as the longest card needs. */
|
|
1420
1492
|
function renderAzureCards(slide, items, region, P) {
|
|
1421
1493
|
const cards = bodyToCards(items);
|
|
1422
1494
|
if (!cards.length) return;
|
|
1423
1495
|
const n = cards.length;
|
|
1424
1496
|
const x0 = region.x || 0.6, y0 = region.y || 1.6, w = region.w || 12.1;
|
|
1425
|
-
const
|
|
1426
|
-
const gap = 0.28;
|
|
1497
|
+
const gap = CARD_GAP;
|
|
1427
1498
|
const cardW = (w - (n - 1) * gap) / n;
|
|
1499
|
+
const h = fittedCardHeight(cards, cardW, region.h || 3.0);
|
|
1428
1500
|
cards.forEach((c, i) => {
|
|
1429
1501
|
drawAzureCard(slide, x0 + i * (cardW + gap), y0, cardW, h, c, i, P, n >= 3 && i === n - 1);
|
|
1430
1502
|
});
|
|
1503
|
+
return y0 + h;
|
|
1431
1504
|
}
|
|
1432
1505
|
|
|
1433
1506
|
/** Flatten body/summary items (sections + children + bullets) into styled runs.
|
|
@@ -1437,12 +1510,12 @@ function itemsToRuns(items, P, scale = 1) {
|
|
|
1437
1510
|
const runs = [];
|
|
1438
1511
|
for (const it of items || []) {
|
|
1439
1512
|
if (it.type === "section") {
|
|
1440
|
-
runs.push({ text: cleanMd(it.heading || ""), options: { bold: true, fontFace: P.titleFont, fontSize: s(
|
|
1513
|
+
runs.push({ text: cleanMd(it.heading || ""), options: { bold: true, fontFace: P.titleFont, fontSize: s(14), color: hex(P.ink), breakLine: true } });
|
|
1441
1514
|
for (const c of it.children || []) {
|
|
1442
|
-
runs.push({ text: " " + cleanMd(c.text || ""), options: { fontFace: P.bodyFont, fontSize: s(
|
|
1515
|
+
runs.push({ text: " " + cleanMd(c.text || ""), options: { fontFace: P.bodyFont, fontSize: s(12.5), color: hex(P.ink_muted), breakLine: true } });
|
|
1443
1516
|
}
|
|
1444
1517
|
} else if (it.text) {
|
|
1445
|
-
runs.push({ text: (it.type === "numbered" ? " " : "• ") + cleanMd(it.text), options: { fontFace: P.bodyFont, fontSize: s(
|
|
1518
|
+
runs.push({ text: (it.type === "numbered" ? " " : "• ") + cleanMd(it.text), options: { fontFace: P.bodyFont, fontSize: s(13), color: hex(P.ink_muted), breakLine: true } });
|
|
1446
1519
|
}
|
|
1447
1520
|
}
|
|
1448
1521
|
return runs;
|
|
@@ -1454,87 +1527,231 @@ function estimateGroupHeight(items, innerW, scale, lineSpacing) {
|
|
|
1454
1527
|
let hsum = 0;
|
|
1455
1528
|
for (const it of items || []) {
|
|
1456
1529
|
if (it.type === "section") {
|
|
1457
|
-
hsum += estimateTextHeight(it.heading || "", innerW,
|
|
1458
|
-
for (const c of it.children || []) hsum += estimateTextHeight(" " + (c.text || ""), innerW - 0.1,
|
|
1530
|
+
hsum += estimateTextHeight(it.heading || "", innerW, 14 * scale, lineSpacing);
|
|
1531
|
+
for (const c of it.children || []) hsum += estimateTextHeight(" " + (c.text || ""), innerW - 0.1, 12.5 * scale, lineSpacing);
|
|
1459
1532
|
} else if (it.text) {
|
|
1460
|
-
hsum += estimateTextHeight(it.text, innerW,
|
|
1533
|
+
hsum += estimateTextHeight(it.text, innerW, 13 * scale, lineSpacing);
|
|
1461
1534
|
}
|
|
1462
1535
|
}
|
|
1463
1536
|
return hsum;
|
|
1464
1537
|
}
|
|
1465
1538
|
|
|
1466
|
-
/**
|
|
1467
|
-
function
|
|
1468
|
-
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1539
|
+
/** The height a group's runs take at their real leading, for sizing (not fitting) the card. */
|
|
1540
|
+
function groupTextHeight(items, innerW, scale, lineSpacing) {
|
|
1541
|
+
let hsum = 0.1;
|
|
1542
|
+
for (const it of items || []) {
|
|
1543
|
+
if (it.type === "section") {
|
|
1544
|
+
hsum += cardTextHeight(it.heading || "", innerW, 14 * scale, lineSpacing);
|
|
1545
|
+
for (const c of it.children || []) hsum += cardTextHeight(" " + (c.text || ""), innerW - 0.1, 12.5 * scale, lineSpacing);
|
|
1546
|
+
} else if (it.text) {
|
|
1547
|
+
hsum += cardTextHeight("• " + it.text, innerW, 13 * scale, lineSpacing);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return hsum;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
/** A summary group as a card: the largest font scale (1 down to 0.55) whose text fits
|
|
1554
|
+
* `maxH`, and the height that text needs at that scale. */
|
|
1555
|
+
function groupCard(content, w, maxH, P) {
|
|
1556
|
+
const innerW = w - 2 * CARD_PAD;
|
|
1557
|
+
const heading = cleanMd(content.heading || "");
|
|
1558
|
+
const headH = heading ? 0.18 + Math.max(0.4, cardHeadingHeight({ heading }, innerW)) + 0.04 : 0.18;
|
|
1559
|
+
const fixed = CARD_PAD + CARD_CHIP + headH + 0.18;
|
|
1471
1560
|
let scale = 0.55, ls = 1.12;
|
|
1472
1561
|
for (const s of [1, 0.92, 0.85, 0.78, 0.72, 0.66, 0.6, 0.55]) {
|
|
1473
|
-
if (estimateGroupHeight(content.items, innerW, s, s < 1 ? 1.12 : 1.28) <=
|
|
1562
|
+
if (estimateGroupHeight(content.items, innerW, s, s < 1 ? 1.12 : 1.28) <= maxH - fixed) { scale = s; ls = s < 1 ? 1.12 : 1.28; break; }
|
|
1474
1563
|
}
|
|
1475
|
-
const
|
|
1476
|
-
|
|
1477
|
-
bodyRuns: itemsToRuns(content.items, P, scale),
|
|
1478
|
-
|
|
1564
|
+
const bodyHeight = groupTextHeight(content.items, innerW, scale, ls);
|
|
1565
|
+
return {
|
|
1566
|
+
card: { heading, bodyRuns: itemsToRuns(content.items, P, scale), lineSpacing: ls, bodyHeight },
|
|
1567
|
+
need: Math.min(maxH, fixed + bodyHeight + CARD_PAD - 0.18),
|
|
1479
1568
|
};
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
/** Render a single summary-group as one card, at `opts.height` (shared by the
|
|
1572
|
+
* groups of one slide) or at the height its own text needs. */
|
|
1573
|
+
function renderAzureGroupCard(slide, content, region, P, idx, height) {
|
|
1574
|
+
const w = region.w || 5.6, maxH = region.h || 2.4;
|
|
1575
|
+
const { card, need } = groupCard(content, w, maxH, P);
|
|
1576
|
+
const h = Math.min(maxH, Math.max(CARD_MIN_H, height || need));
|
|
1480
1577
|
drawAzureCard(slide, region.x || 0.6, region.y || 1.6, w, h, card, idx, P, false);
|
|
1481
1578
|
}
|
|
1482
1579
|
|
|
1483
1580
|
/** Render a general data table (palette-styled): primary header, zebra tint rows. */
|
|
1484
|
-
|
|
1581
|
+
// ── Tables and charts that fill their region ────────────────────────────────
|
|
1582
|
+
|
|
1583
|
+
// A cell reads as a number when, after units and signs, only digits remain.
|
|
1584
|
+
const NUMERIC_CELL = /^(?:[▲▼△▽]\s*)?[+\-−±]?\s*[\d.,]+\s*(?:%p?|배|x|pt|bp|[가-힣]{1,3}|[A-Za-z]{1,3})?$/u;
|
|
1585
|
+
const isNumericCell = (text) => NUMERIC_CELL.test(cleanMd(String(text)).trim());
|
|
1586
|
+
|
|
1587
|
+
/** Columns whose data cells are all numbers are right-aligned; a dash for a missing value is blank. */
|
|
1588
|
+
function numericColumns(headers, rows) {
|
|
1589
|
+
return headers.map((_, ci) => {
|
|
1590
|
+
const cells = rows.map((r) => r[ci]).filter((c) => c != null && !/^[\s—–\-]*$/u.test(cleanMd(String(c))));
|
|
1591
|
+
return cells.length > 0 && cells.every(isNumericCell);
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/** Column widths proportional to the longest cell, Hangul counted wider, with a floor. */
|
|
1596
|
+
function proportionalWidths(headers, rows, totalW) {
|
|
1597
|
+
const len = (t) => [...cleanMd(String(t || ""))].reduce((n, ch) => n + (/[\u3131-\uD7A3]/u.test(ch) ? 1.7 : 1), 0);
|
|
1598
|
+
const want = headers.map((h, ci) => Math.max(len(h), ...rows.map((r) => len(r[ci])), 4));
|
|
1599
|
+
const floor = Math.min(0.9, totalW / headers.length);
|
|
1600
|
+
const sum = want.reduce((a, b) => a + b, 0);
|
|
1601
|
+
let widths = want.map((w) => Math.max(floor, (w / sum) * totalW));
|
|
1602
|
+
const scale = totalW / widths.reduce((a, b) => a + b, 0);
|
|
1603
|
+
widths = widths.map((w) => w * scale);
|
|
1604
|
+
return widths;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* Row height and font size for a table that should use the room it has: rows
|
|
1609
|
+
* grow toward `bottom` (up to a comfortable maximum) instead of leaving the lower
|
|
1610
|
+
* half of the slide empty, and a roomy table gets a larger font.
|
|
1611
|
+
*/
|
|
1612
|
+
function tableMetrics(rowCount, y, bottom, base) {
|
|
1613
|
+
const room = Math.max(0, (bottom || y + rowCount * base.rowH) - y);
|
|
1614
|
+
const rowH = Math.min(base.maxRowH, Math.max(base.rowH, (room * 0.92) / rowCount));
|
|
1615
|
+
const scale = rowH >= 0.55 ? 1.2 : rowH >= 0.47 ? 1.1 : 1;
|
|
1616
|
+
return { rowH, headerSize: +(base.headerSize * scale).toFixed(1), dataSize: +(base.dataSize * scale).toFixed(1) };
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
function renderAzureTable(slide, content, region, P, bottom) {
|
|
1485
1620
|
const headers = content.headers || [];
|
|
1486
1621
|
const rows = content.rows || [];
|
|
1487
1622
|
if (!headers.length) return;
|
|
1488
1623
|
const x = region.x || 0.6, y = region.y || 1.6, w = region.w || 6.0;
|
|
1489
|
-
const
|
|
1624
|
+
const numeric = numericColumns(headers, rows);
|
|
1625
|
+
const m = tableMetrics(rows.length + 1, y, bottom, { rowH: 0.4, maxRowH: 0.72, headerSize: 12, dataSize: 11.5 });
|
|
1490
1626
|
const tableRows = [];
|
|
1491
|
-
tableRows.push(headers.map((h,
|
|
1627
|
+
tableRows.push(headers.map((h, ci) => ({
|
|
1492
1628
|
text: cleanMd(h),
|
|
1493
|
-
options: { bold: true, color: "FFFFFF", fill: { color: hex(P.primary) }, fontFace: P.titleFont, fontSize:
|
|
1629
|
+
options: { bold: true, color: "FFFFFF", fill: { color: hex(P.primary) }, fontFace: P.titleFont, fontSize: m.headerSize, align: numeric[ci] ? "right" : "left", valign: "middle" },
|
|
1494
1630
|
})));
|
|
1495
1631
|
rows.forEach((r, ri) => {
|
|
1496
|
-
tableRows.push(r.map((c,
|
|
1497
|
-
color: hex(P.ink), fill: { color: ri % 2 ? "FFFFFF" : hex(P.tint) }, fontFace: P.bodyFont, fontSize:
|
|
1632
|
+
tableRows.push(r.map((c, ci) => linkedTableCell(c, {
|
|
1633
|
+
color: hex(P.ink), fill: { color: ri % 2 ? "FFFFFF" : hex(P.tint) }, fontFace: P.bodyFont, fontSize: m.dataSize,
|
|
1634
|
+
align: numeric[ci] ? "right" : "left", valign: "middle", bold: ci === 0 && !numeric[0],
|
|
1498
1635
|
})));
|
|
1499
1636
|
});
|
|
1500
1637
|
slide.addTable(tableRows, {
|
|
1501
|
-
x, y, w, colW:
|
|
1502
|
-
border: { type: "solid", color: hex(P.line), pt: 0.5 }, rowH:
|
|
1638
|
+
x, y, w, colW: proportionalWidths(headers, rows, w),
|
|
1639
|
+
border: { type: "solid", color: hex(P.line), pt: 0.5 }, rowH: m.rowH, margin: [0.04, 0.12, 0.04, 0.12], autoPage: false,
|
|
1503
1640
|
});
|
|
1504
1641
|
}
|
|
1505
1642
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1643
|
+
/** Parse "1,234", "▲12.5%", "−3" into a number; anything else is null. */
|
|
1644
|
+
function chartNumber(text) {
|
|
1645
|
+
const t = cleanMd(String(text || "")).trim().replace(/[,\s]/g, "").replace(/^[▲△+]/u, "").replace(/^[▼▽−]/u, "-");
|
|
1646
|
+
const m = t.match(/^-?\d+(?:\.\d+)?/);
|
|
1647
|
+
return m ? parseFloat(m[0]) : null;
|
|
1509
1648
|
}
|
|
1510
1649
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1650
|
+
const CHART_TYPE = { bar: "bar", column: "bar", stacked: "bar", line: "line", area: "area", pie: "pie", doughnut: "doughnut" };
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* A native PowerPoint chart (editable in PowerPoint: right-click > Edit Data)
|
|
1654
|
+
* from a `::: chart` block. It takes the whole region down to `bottom`.
|
|
1655
|
+
*/
|
|
1656
|
+
function renderChart(slide, content, region, style, bottom) {
|
|
1657
|
+
const headers = content.headers || [];
|
|
1658
|
+
const rows = content.rows || [];
|
|
1659
|
+
const spec = content.chart || {};
|
|
1660
|
+
const kind = CHART_TYPE[spec.type] || "bar";
|
|
1661
|
+
const labels = rows.map((r) => cleanMd(String(r[0] || "")));
|
|
1662
|
+
const series = headers.slice(1).map((name, si) => ({
|
|
1663
|
+
name: cleanMd(String(name)),
|
|
1664
|
+
labels,
|
|
1665
|
+
// A cell with no number stays null and becomes a blank point, so its line breaks rather than diving to zero.
|
|
1666
|
+
values: rows.map((r) => chartNumber(r[si + 1])),
|
|
1520
1667
|
}));
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1668
|
+
// Data labels carry as many decimals as the table writes (at most three): beside a table that says 46.0
|
|
1669
|
+
// the label says 46.0, not 46.
|
|
1670
|
+
const decimals = Math.min(3, Math.max(0, ...rows.flatMap((r) => r.slice(1).map((v) => ((/\.(\d+)/u.exec(cleanMd(String(v == null ? "" : v)).replace(/,/gu, "")) || [, ""])[1]).length))));
|
|
1671
|
+
const x = region.x || 0.6, y = region.y || 1.6, w = region.w || 8;
|
|
1672
|
+
const h = Math.max(1.6, ((bottom || y + (region.h || 3.2)) - y));
|
|
1673
|
+
const colors = style.series.map((c) => hex(c));
|
|
1674
|
+
const round = kind === "pie" || kind === "doughnut";
|
|
1675
|
+
const data = round ? series.slice(0, 1) : series;
|
|
1676
|
+
// Crowding, estimated in points: a category label wider than its slot is slanted; side-by-side
|
|
1677
|
+
// value labels wider than their bars collide, so the values are read off a shown axis instead.
|
|
1678
|
+
const ems = (t) => [...String(t)].reduce((a, ch) => a + (/[\u3131-\uD7A3]/u.test(ch) ? 0.94 : /\s/u.test(ch) ? 0.28 : 0.56), 0);
|
|
1679
|
+
const labelPt = style.labelSize || 11;
|
|
1680
|
+
const slot = (w * 72 * 0.85) / Math.max(1, labels.length);
|
|
1681
|
+
// A renderer adds space between Hangul and digits ("25 년 2Q"), so a label needs a quarter of its slot spare.
|
|
1682
|
+
// Horizontal bars list their categories down the side: slanted there, LibreOffice leaves some out.
|
|
1683
|
+
const slanted = !round && kind !== "line" && spec.type !== "bar" && Math.max(0, ...labels.map(ems)) * labelPt > slot * 0.75;
|
|
1684
|
+
const clustered = kind === "bar" && spec.type !== "stacked" && data.length > 1;
|
|
1685
|
+
const valueW = Math.max(0, ...data.flatMap((d) => d.values.map((v) => ems(Number(v).toLocaleString("en-US"))))) * labelPt;
|
|
1686
|
+
// With more than one line, the series cross the same rows of the plot and their point labels pile up.
|
|
1687
|
+
const crowded = !round && ((clustered && valueW > (slot / 1.6 / data.length) * 1.1) || (kind === "line" && data.length > 1));
|
|
1688
|
+
const values = data.flatMap((d) => d.values).filter((v) => v !== null);
|
|
1689
|
+
// Horizontal bars of several series share each row; a bar thinner than one line of label text leaves its value label touching the next one.
|
|
1690
|
+
const horizontal = !round && spec.type === "bar";
|
|
1691
|
+
const dataPt = style.labelSize || (round ? 12 : 10);
|
|
1692
|
+
const barPt = (h * 72 - 54) / Math.max(1, labels.length) / (data.length + 0.6);
|
|
1693
|
+
const thin = horizontal && data.length > 1 && spec.labels !== false && barPt < dataPt * 1.2;
|
|
1694
|
+
// On a narrow horizontal bar chart the value axis steps wide enough for each number to sit level; a crowded automatic axis gets slanted.
|
|
1695
|
+
const top = Math.max(0, ...values), low = Math.min(0, ...values);
|
|
1696
|
+
const tickW = ems(Math.round(Math.max(top, -low)).toLocaleString("en-US")) * dataPt;
|
|
1697
|
+
const catW = Math.min(w * 72 * 0.4, Math.max(0, ...labels.map(ems)) * labelPt + 8);
|
|
1698
|
+
const ticks = Math.floor((w * 72 - catW - 16) / (tickW * 2));
|
|
1699
|
+
const nice = (step) => { const p = 10 ** Math.floor(Math.log10(step)); return [1, 2, 2.5, 5, 10].find((m) => m * p >= step) * p; };
|
|
1700
|
+
const majorUnit = horizontal && top > low && ticks < 6 ? nice((top - low) / Math.max(1, ticks - 1)) : null;
|
|
1701
|
+
const zeroBased = !round && values.length > 0 && values.every((v) => v >= 0);
|
|
1702
|
+
// The unit stands once: a legend whose series names carry it already says it, so the axis title goes;
|
|
1703
|
+
// otherwise it is set level (a rotated title stacks Hangul a glyph a line and reads tiny; 360 degrees, since
|
|
1704
|
+
// pptxgenjs writes no angle for 0 and the axis default is vertical).
|
|
1705
|
+
const unitShown = spec.unit && data.length > 1 && data.every((d) => String(d.name || "").includes(spec.unit));
|
|
1706
|
+
const axisTitle = spec.unit && !unitShown && !(Boolean(style.valAxisHidden) && !crowded && !thin);
|
|
1707
|
+
slide.addChart(kind, data, {
|
|
1708
|
+
x, y, w, h,
|
|
1709
|
+
barDir: spec.type === "bar" ? "bar" : "col",
|
|
1710
|
+
barGrouping: spec.type === "stacked" ? "stacked" : "clustered",
|
|
1711
|
+
barGapWidthPct: 60,
|
|
1712
|
+
chartColors: round ? labels.map((_, i) => colors[i % colors.length]) : colors,
|
|
1713
|
+
showLegend: round || data.length > 1,
|
|
1714
|
+
legendPos: round ? "r" : "t",
|
|
1715
|
+
legendFontFace: style.bodyFont, legendFontSize: 11, legendColor: hex(style.ink),
|
|
1716
|
+
showValue: !round && spec.labels !== false && !crowded && !thin,
|
|
1717
|
+
showPercent: round && spec.labels !== false, showLabel: false,
|
|
1718
|
+
dataLabelFontFace: style.bodyFont, dataLabelFontSize: style.labelSize || (round ? 12 : 10),
|
|
1719
|
+
dataLabelColor: round ? "FFFFFF" : hex(style.ink),
|
|
1720
|
+
dataLabelPosition: round ? "ctr" : kind === "line" ? "t" : "outEnd",
|
|
1721
|
+
dataLabelFormatCode: round ? "0%" : decimals ? `#,##0.${"0".repeat(decimals)}` : "#,##0",
|
|
1722
|
+
catAxisLabelFontFace: style.bodyFont, catAxisLabelFontSize: style.labelSize || 11, catAxisLabelColor: hex(style.ink),
|
|
1723
|
+
valAxisLabelFontFace: style.bodyFont, valAxisLabelFontSize: style.labelSize || 10, valAxisLabelColor: hex(style.ink_muted),
|
|
1724
|
+
valAxisLabelFormatCode: "#,##0",
|
|
1725
|
+
// A pack with direct labels and no gridlines drops the value axis: the labels carry the values.
|
|
1726
|
+
valAxisHidden: Boolean(style.valAxisHidden) && !crowded && !thin,
|
|
1727
|
+
...(majorUnit ? { valAxisMajorUnit: majorUnit } : {}),
|
|
1728
|
+
// Negative values move the zero line into the plot, so category names sit at the axis minimum instead of on the bars.
|
|
1729
|
+
...(horizontal && low < 0 ? { catAxisLabelPos: "low" } : {}),
|
|
1730
|
+
// A blank point is a break in the line.
|
|
1731
|
+
displayBlanksAs: "gap",
|
|
1732
|
+
...(style.valMax ? { valAxisMaxVal: style.valMax } : {}),
|
|
1733
|
+
...(zeroBased ? { valAxisMinVal: 0 } : {}),
|
|
1734
|
+
...(slanted ? { catAxisLabelRotate: -45 } : {}),
|
|
1735
|
+
catAxisLineShow: true, catAxisLineColor: hex(style.line),
|
|
1736
|
+
valGridLine: style.grid === false && !crowded && !thin ? { style: "none" } : { color: hex(style.line), size: 0.5 },
|
|
1737
|
+
valAxisLineShow: false,
|
|
1738
|
+
lineSize: 2.5, lineDataSymbol: "circle", lineDataSymbolSize: 7,
|
|
1739
|
+
holeSize: 58,
|
|
1740
|
+
...(axisTitle ? { showValAxisTitle: true, valAxisTitle: spec.unit, valAxisTitleRotate: 360, valAxisTitleFontSize: style.labelSize || 10, valAxisTitleColor: hex(style.ink_muted), valAxisTitleFontFace: style.bodyFont } : {}),
|
|
1741
|
+
...(spec.title ? { showTitle: true, title: spec.title, titleFontFace: style.titleFont, titleFontSize: 13, titleColor: hex(style.ink) } : {}),
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
/** A main-box as a tinted callout sized to its text, not an outlined frame. */
|
|
1746
|
+
function renderAzureCallout(slide, text, region, P) {
|
|
1747
|
+
const x = region.x || 0.84, y = region.y || 5.8, w = region.w || 11.6;
|
|
1748
|
+
const lines = Math.max(1, Math.ceil(cleanMd(text).length / Math.max(20, w * 9)));
|
|
1749
|
+
const h = Math.min(region.h || 1.0, 0.28 + lines * 0.3);
|
|
1750
|
+
slide.addShape("roundRect", { x, y, w, h, rectRadius: 0.1, fill: { color: hex(P.tint) }, line: { type: "none" } });
|
|
1751
|
+
slide.addText(cleanMd(text), {
|
|
1752
|
+
x: x + 0.24, y, w: w - 0.48, h, fontFace: P.bodyFont, fontSize: 13, bold: true,
|
|
1753
|
+
color: hex(P.primary_deep), align: "left", valign: "middle", margin: 0,
|
|
1536
1754
|
});
|
|
1537
|
-
return true;
|
|
1538
1755
|
}
|
|
1539
1756
|
|
|
1540
1757
|
/** Render a kpi-table as a row of KPI cards (value + label); first card filled. */
|
|
@@ -1544,8 +1761,8 @@ function renderAzureKpi(slide, content, region, P) {
|
|
|
1544
1761
|
const labels = cards.map((c) => c.label);
|
|
1545
1762
|
const n = Math.min(values.length, 4);
|
|
1546
1763
|
if (!n) return;
|
|
1547
|
-
const x0 = region.x || 0.6, y0 = region.y || 1.6, w = region.w || 12.1, h =
|
|
1548
|
-
const gap =
|
|
1764
|
+
const x0 = region.x || 0.6, y0 = region.y || 1.6, w = region.w || 12.1, h = region.h || 1.7;
|
|
1765
|
+
const gap = KPI_GAP;
|
|
1549
1766
|
const cardW = (w - (n - 1) * gap) / n;
|
|
1550
1767
|
for (let i = 0; i < n; i++) {
|
|
1551
1768
|
const fill = i === 0;
|
|
@@ -1556,12 +1773,12 @@ function renderAzureKpi(slide, content, region, P) {
|
|
|
1556
1773
|
line: fill ? { type: "none" } : { color: hex(P.line), width: 1 },
|
|
1557
1774
|
});
|
|
1558
1775
|
slide.addText(cleanMd(values[i]), {
|
|
1559
|
-
x: x + 0.28, y: y0 + 0.
|
|
1776
|
+
x: x + 0.28, y: y0 + 0.20, w: cardW - 0.56, h: 0.8,
|
|
1560
1777
|
fontFace: P.titleFont, fontSize: 30, bold: true,
|
|
1561
1778
|
color: fill ? "FFFFFF" : hex(P.primary), align: "left", valign: "middle", charSpacing: -1, margin: 0,
|
|
1562
1779
|
});
|
|
1563
1780
|
slide.addText(cleanMd(labels[i]).toUpperCase(), {
|
|
1564
|
-
x: x + 0.30, y: y0 + h - 0.
|
|
1781
|
+
x: x + 0.30, y: y0 + h - 0.5, w: cardW - 0.56, h: 0.32,
|
|
1565
1782
|
fontFace: P.bodyFont, fontSize: 9.5, bold: false,
|
|
1566
1783
|
color: fill ? hex(P.emphasisTextColor) : hex(P.ink_muted), align: "left", valign: "middle", charSpacing: 0.4, margin: 0,
|
|
1567
1784
|
});
|
|
@@ -1596,7 +1813,9 @@ function kpiCards(content) {
|
|
|
1596
1813
|
return [headers, ...rows].slice(0, 4).map((p) => ({ value: p[0], label: p[1] }));
|
|
1597
1814
|
}
|
|
1598
1815
|
const row = rows[0] || [];
|
|
1599
|
-
|
|
1816
|
+
// A second body row is each figure's basis or comparison ("전년 대비 +12%", "목표 50%").
|
|
1817
|
+
const basis = rows[1] || [];
|
|
1818
|
+
return headers.slice(0, 6).map((lab, i) => ({ value: row[i] != null ? row[i] : "", label: lab, ...(basis[i] ? { note: basis[i] } : {}) }));
|
|
1600
1819
|
}
|
|
1601
1820
|
|
|
1602
1821
|
/** Azure region dispatch. Returns true if it fully handled the region.
|
|
@@ -1604,9 +1823,17 @@ function kpiCards(content) {
|
|
|
1604
1823
|
function renderAzureRegion(slide, layout, name, region, fontRoles, P, opts = {}) {
|
|
1605
1824
|
const content = region.content;
|
|
1606
1825
|
if (content == null) return false;
|
|
1826
|
+
if (name === "main_box" && typeof content === "string" && content.trim()) {
|
|
1827
|
+
// Below a card row that came out shorter than its region, the takeaway follows
|
|
1828
|
+
// the cards instead of leaving a band of empty slide between them.
|
|
1829
|
+
const follow = opts.flow && opts.flow.cardsBottom != null ? opts.flow.cardsBottom + 0.32 : null;
|
|
1830
|
+
renderAzureCallout(slide, content, follow != null && follow < (region.y || 5.8) ? { ...region, y: follow } : region, P);
|
|
1831
|
+
return true;
|
|
1832
|
+
}
|
|
1607
1833
|
if (layout === "cover" && name === "title" && typeof content === "string" && content.includes("**")) {
|
|
1608
1834
|
const role = fontRoles.cover_title || {};
|
|
1609
1835
|
slide.addText(azureTitleRuns(content, P), {
|
|
1836
|
+
objectName: "title@legacy",
|
|
1610
1837
|
x: region.x || 0, y: region.y || 0, w: region.w || 8, h: region.h || 1,
|
|
1611
1838
|
fontFace: role.font || P.titleFont, fontSize: role.size || 48, bold: role.bold !== false,
|
|
1612
1839
|
align: role.align || "left", valign: "middle",
|
|
@@ -1621,22 +1848,28 @@ function renderAzureRegion(slide, layout, name, region, fontRoles, P, opts = {})
|
|
|
1621
1848
|
// normal text column (fall through to addRegion) so nothing is cramped.
|
|
1622
1849
|
const sections = (content.items || []).filter((i) => i.type === "section");
|
|
1623
1850
|
if (sections.length >= 2 && !opts.hasImage) {
|
|
1624
|
-
renderAzureCards(slide, content.items, region, P);
|
|
1851
|
+
const bottom = renderAzureCards(slide, content.items, region, P);
|
|
1852
|
+
if (opts.flow) opts.flow.cardsBottom = bottom;
|
|
1625
1853
|
return true;
|
|
1626
1854
|
}
|
|
1627
1855
|
return false;
|
|
1628
1856
|
}
|
|
1629
1857
|
if (content.type === "kpi-table") {
|
|
1630
|
-
if (
|
|
1631
|
-
|
|
1858
|
+
if (content.chart) {
|
|
1859
|
+
// Pie and doughnut slices carry white labels, so they use the darker tones only.
|
|
1860
|
+
const round = ["pie", "doughnut"].includes(content.chart.type);
|
|
1861
|
+
const series = round ? [P.primary, P.primary_deep, P.azure, P.ink_muted] : [P.primary, P.azure_soft, P.primary_deep, P.ink_muted];
|
|
1862
|
+
renderChart(slide, content, region, { ...P, series }, opts.bottom);
|
|
1863
|
+
}
|
|
1864
|
+
else if (looksLikeKpi(content) && kpiFits(content, region.w)) {
|
|
1632
1865
|
renderAzureKpi(slide, content, region, P);
|
|
1633
1866
|
}
|
|
1634
|
-
else renderAzureTable(slide, content, region, P);
|
|
1867
|
+
else renderAzureTable(slide, content, region, P, opts.bottom);
|
|
1635
1868
|
return true;
|
|
1636
1869
|
}
|
|
1637
1870
|
if (content.type === "summary-group") {
|
|
1638
1871
|
const idx = name === "group_bottom" ? 1 : 0;
|
|
1639
|
-
renderAzureGroupCard(slide, content, region, P, idx);
|
|
1872
|
+
renderAzureGroupCard(slide, content, region, P, idx, opts.groupHeight);
|
|
1640
1873
|
return true;
|
|
1641
1874
|
}
|
|
1642
1875
|
}
|
|
@@ -1744,7 +1977,7 @@ function renderPlacementBox(slide, placement, ctx) {
|
|
|
1744
1977
|
|
|
1745
1978
|
const name = partRegionName(block.type);
|
|
1746
1979
|
const rendered = useRich &&
|
|
1747
|
-
renderAzureRegion(slide, ctx.layout, name, region, ctx.fontRoles, ctx.P, {
|
|
1980
|
+
renderAzureRegion(slide, ctx.layout, name, region, ctx.fontRoles, ctx.P, {});
|
|
1748
1981
|
if (!rendered) {
|
|
1749
1982
|
addRegion(slide, name, region, ctx.fontRoles, ctx.pageH, y + h, false, ctx.sourceDir);
|
|
1750
1983
|
}
|
|
@@ -1756,7 +1989,7 @@ function renderPlacements(slide, placements, band, ctx) {
|
|
|
1756
1989
|
for (const placement of placements) {
|
|
1757
1990
|
if (placement.z !== band) continue;
|
|
1758
1991
|
if (placement.kind === "shape") {
|
|
1759
|
-
addDecorations(slide, [shapeToDecoration(placement, ctx.sourceDir)], ctx.
|
|
1992
|
+
addDecorations(slide, [shapeToDecoration(placement, ctx.sourceDir)], ctx.fontRoles);
|
|
1760
1993
|
} else {
|
|
1761
1994
|
renderPlacementBox(slide, placement, ctx);
|
|
1762
1995
|
}
|
|
@@ -1773,10 +2006,67 @@ function renderPlacements(slide, placements, band, ctx) {
|
|
|
1773
2006
|
* @param {string} outputPath - Where to write the .pptx file
|
|
1774
2007
|
* @returns {Promise<string>} Resolves with the output path
|
|
1775
2008
|
*/
|
|
2009
|
+
/**
|
|
2010
|
+
* The deck-wide `notice:` (for example "예시 데이터 — 실제 수치로 바꿔 주세요") as a
|
|
2011
|
+
* coloured tag at the bottom left of every slide, cover included, so a sample or
|
|
2012
|
+
* draft deck can never be mistaken for a sourced one. A 9 pt grey footnote was easy
|
|
2013
|
+
* to miss; the tag keeps its own fill and text colour (template palette
|
|
2014
|
+
* `notice_fill` / `notice_ink`, default a light red with dark red text, 6:1).
|
|
2015
|
+
*/
|
|
2016
|
+
const NOTICE_FILL = "FDECEA";
|
|
2017
|
+
const NOTICE_INK = "A21B12";
|
|
2018
|
+
let NOTICE = { ...LEGACY_TOKENS.notice };
|
|
2019
|
+
|
|
2020
|
+
function addNotice(slide, text, pageW, pageH, pal) {
|
|
2021
|
+
const label = cleanMd(text);
|
|
2022
|
+
const fontSize = NOTICE.size;
|
|
2023
|
+
const textW = (weightedTextLength(label) * fontSize * 0.98) / 72;
|
|
2024
|
+
const w = Math.min(pageW * 0.55, textW + 0.46);
|
|
2025
|
+
const h = NOTICE.h;
|
|
2026
|
+
const x = NOTICE.x, y = pageH - h - NOTICE.bottom;
|
|
2027
|
+
const fill = ((pal && pal.notice_fill) || NOTICE_FILL).replace("#", "");
|
|
2028
|
+
const ink = ((pal && pal.notice_ink) || NOTICE_INK).replace("#", "");
|
|
2029
|
+
slide.addShape("roundRect", { x, y, w, h, rectRadius: 0.15, fill: { color: fill }, line: { type: "none" }, objectName: "lit-notice tag" });
|
|
2030
|
+
slide.addText(label, {
|
|
2031
|
+
objectName: "lit-notice text",
|
|
2032
|
+
x: x + 0.16, y, w: w - 0.32, h,
|
|
2033
|
+
fontFace: FONT_BOLD, fontSize, bold: true, color: ink,
|
|
2034
|
+
align: "left", valign: "middle", margin: 0, fit: "shrink",
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
/**
|
|
2039
|
+
* Give the first object drawn on a slide that has no name of its own the name `family@<id>`, so a
|
|
2040
|
+
* checker can read the layout family the source asked for and compare it with what it measures.
|
|
2041
|
+
*/
|
|
2042
|
+
function stampFamily(slide, family) {
|
|
2043
|
+
const at = { addText: 1, addShape: 1, addImage: 0, addTable: 1, addChart: 2 };
|
|
2044
|
+
const originals = {};
|
|
2045
|
+
let done = false;
|
|
2046
|
+
const restore = () => { for (const m of Object.keys(originals)) slide[m] = originals[m]; };
|
|
2047
|
+
for (const [method, index] of Object.entries(at)) {
|
|
2048
|
+
originals[method] = slide[method];
|
|
2049
|
+
slide[method] = (...args) => {
|
|
2050
|
+
if (!(args[index] && args[index].objectName)) {
|
|
2051
|
+
restore();
|
|
2052
|
+
done = true;
|
|
2053
|
+
args[index] = { ...(args[index] || {}), objectName: `family@${family}` };
|
|
2054
|
+
}
|
|
2055
|
+
return originals[method].apply(slide, args);
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
/** Whether a shape took the name; unwraps the slide either way. */
|
|
2059
|
+
return () => { restore(); return done; };
|
|
2060
|
+
}
|
|
2061
|
+
|
|
1776
2062
|
async function render(resolved, templateObj, outputPath) {
|
|
2063
|
+
const pack = (templateObj && templateObj.pack) || null;
|
|
2064
|
+
if (pack && !pack.legacy) return require("./render-pack").renderPack(resolved, templateObj, outputPath);
|
|
2065
|
+
applyTokens(pack && pack.tokens);
|
|
1777
2066
|
const fontRoles = buildFontRoles(templateObj);
|
|
1778
2067
|
|
|
1779
|
-
//
|
|
2068
|
+
// Brand-neutralize: derive font/spacing/accent from the template, falling back
|
|
2069
|
+
// to Pretendard when a template names no family.
|
|
1780
2070
|
const tpl = (templateObj && templateObj.template) || {};
|
|
1781
2071
|
const tplFonts = tpl.fonts || {};
|
|
1782
2072
|
const tplType = tpl.global_typography || {};
|
|
@@ -1784,20 +2074,25 @@ async function render(resolved, templateObj, outputPath) {
|
|
|
1784
2074
|
FONT_MEDIUM = tplFonts.body || "Pretendard";
|
|
1785
2075
|
FONT_LIGHT = tplFonts.light || "Pretendard";
|
|
1786
2076
|
CHAR_SPACING = tplType.char_spacing != null ? tplType.char_spacing : -0.7;
|
|
1787
|
-
BULLET_FONT = FONT_BOLD;
|
|
1788
2077
|
SEC_HEADER_FONT = FONT_BOLD;
|
|
1789
2078
|
TOC_FONT = FONT_BOLD;
|
|
1790
|
-
BULLET_COLOR = (tplType.bullet_color || "
|
|
1791
|
-
SECTION_ACCENT = (tplType.section_accent || "
|
|
2079
|
+
BULLET_COLOR = (tplType.bullet_color || "1D4ED8").replace("#", "");
|
|
2080
|
+
SECTION_ACCENT = (tplType.section_accent || "1D4ED8").replace("#", "");
|
|
1792
2081
|
|
|
1793
|
-
// Rich card/KPI/divider rendering
|
|
1794
|
-
|
|
2082
|
+
// Rich card/KPI/divider rendering — palette-driven, for templates with the rich-blocks
|
|
2083
|
+
// capability. Tokens come from the template palette.
|
|
2084
|
+
const rich = Boolean(pack && (pack.capabilities || []).includes("rich-blocks"));
|
|
1795
2085
|
const pal = tpl.palette || {};
|
|
2086
|
+
PLAIN_CHART_STYLE = {
|
|
2087
|
+
series: [pal.ink || "#3C3836", pal.accent_green_2 || pal.primary || "#689D6A", pal.accent_amber || "#D79921", pal.accent_purple || "#B16286"],
|
|
2088
|
+
ink: pal.ink || "#3C3836", ink_muted: pal.ink_muted || "#6E6256", line: pal.line || "#CBC2B5",
|
|
2089
|
+
titleFont: FONT_BOLD, bodyFont: FONT_MEDIUM,
|
|
2090
|
+
};
|
|
1796
2091
|
const P = {
|
|
1797
2092
|
titleFont: FONT_BOLD, bodyFont: FONT_MEDIUM,
|
|
1798
2093
|
primary: pal.primary || "#1D4ED8", primary_deep: pal.primary_deep || "#0B2E6F",
|
|
1799
2094
|
ink: pal.ink || "#0E1B2C", ink_muted: pal.ink_muted || "#51607A",
|
|
1800
|
-
tint: pal.tint || "#EEF4FF", line: pal.line || "#D5DEEC", azure_soft: pal.azure_soft || "#93C5FD",
|
|
2095
|
+
tint: pal.tint || "#EEF4FF", line: pal.line || "#D5DEEC", azure_soft: pal.azure_soft || "#93C5FD", azure: pal.azure || "#3B82F6",
|
|
1801
2096
|
emphasisTextColor: pal.emphasis_text || "#C9D8F5",
|
|
1802
2097
|
};
|
|
1803
2098
|
|
|
@@ -1806,6 +2101,8 @@ async function render(resolved, templateObj, outputPath) {
|
|
|
1806
2101
|
const pageW = dims.width || 10.833;
|
|
1807
2102
|
const pageH = dims.height || 7.5;
|
|
1808
2103
|
|
|
2104
|
+
// Loaded here, not at module load, so AST-only and --list-* runs never install.
|
|
2105
|
+
const PptxGenJS = require("pptxgenjs");
|
|
1809
2106
|
const pptx = new PptxGenJS();
|
|
1810
2107
|
pptx.defineLayout({ name: "A4_LANDSCAPE", width: pageW, height: pageH });
|
|
1811
2108
|
pptx.layout = "A4_LANDSCAPE";
|
|
@@ -1814,36 +2111,26 @@ async function render(resolved, templateObj, outputPath) {
|
|
|
1814
2111
|
pptx.title = title;
|
|
1815
2112
|
const sourceDir = resolved.sourceDir;
|
|
1816
2113
|
const cramStress = isCramStressDeck(resolved);
|
|
2114
|
+
const deckMeta = (resolved.deck && resolved.deck.metadata) || {};
|
|
2115
|
+
const notice = typeof deckMeta.notice === "string" && deckMeta.notice.trim() ? deckMeta.notice.trim() : null;
|
|
1817
2116
|
|
|
1818
2117
|
for (const slideSpec of resolved.slides || []) {
|
|
1819
2118
|
const slide = pptx.addSlide();
|
|
2119
|
+
stampFamily(slide, slideSpec.family || slideSpec.layout);
|
|
1820
2120
|
|
|
1821
2121
|
// Draw order is a band at a time: template decorations, then anything the
|
|
1822
2122
|
// author put under the content, then the template's regions, then the
|
|
1823
2123
|
// columns that replaced the body, then anything sitting on top.
|
|
1824
|
-
addDecorations(slide, slideSpec.decorations,
|
|
2124
|
+
addDecorations(slide, slideSpec.decorations, fontRoles);
|
|
1825
2125
|
|
|
1826
2126
|
const placements = slideSpec.placements || [];
|
|
1827
2127
|
const placementCtx = {
|
|
1828
|
-
rich, P, fontRoles, pageH, sourceDir,
|
|
2128
|
+
rich, P, fontRoles, pageH, sourceDir,
|
|
1829
2129
|
layout: slideSpec.layout,
|
|
1830
|
-
slideIndex: slideSpec.index,
|
|
1831
2130
|
};
|
|
1832
2131
|
renderPlacements(slide, placements, "under", placementCtx);
|
|
1833
2132
|
|
|
1834
2133
|
const regions = adjustedRegionsForImageColumn(slideSpec.regions || {});
|
|
1835
|
-
const chartRegionName = ["table", "kpi_table"].find((name) => regions[name] && chartSeries(regions[name].content || {}));
|
|
1836
|
-
if (rich && chartRegionName && regions.body?.content) {
|
|
1837
|
-
// Keep one concise takeaway above the plot instead of stacking prose on
|
|
1838
|
-
// top of the editable chart's data area.
|
|
1839
|
-
regions.body = { ...regions.body, x: 0.84, y: 1.53, w: pageW - 1.68, h: 0.58 };
|
|
1840
|
-
const items = regions.body.content.items || [];
|
|
1841
|
-
if (items.length && items.every((item) => item.type === "text")) {
|
|
1842
|
-
regions.body.content = items.map((item) => item.text).join(" ");
|
|
1843
|
-
regions.body.h = 0.78;
|
|
1844
|
-
}
|
|
1845
|
-
regions[chartRegionName] = { ...regions[chartRegionName], y: 2.40, h: 3.15 };
|
|
1846
|
-
}
|
|
1847
2134
|
if (cramStress && ["content", "main"].includes(slideSpec.layout) && regions.body) {
|
|
1848
2135
|
renderCramStressSlide(slide, { ...slideSpec, regions }, pageW, pageH, sourceDir);
|
|
1849
2136
|
continue;
|
|
@@ -1869,17 +2156,83 @@ async function render(resolved, templateObj, outputPath) {
|
|
|
1869
2156
|
(n === "image" || n === "figure") && r.content &&
|
|
1870
2157
|
(r.content.type === "image" || r.content.type === "image-grid"));
|
|
1871
2158
|
|
|
2159
|
+
// Summary groups sit side by side, so they share the height the fuller one needs.
|
|
2160
|
+
const groups = Object.values(regions).filter((r) => r.content && r.content.type === "summary-group");
|
|
2161
|
+
const groupHeight = rich && groups.length
|
|
2162
|
+
? Math.max(...groups.map((r) => groupCard(r.content, r.w || 5.6, r.h || 2.4, P).need))
|
|
2163
|
+
: null;
|
|
2164
|
+
|
|
2165
|
+
const flow = {};
|
|
1872
2166
|
for (const [name, region] of Object.entries(regions)) {
|
|
1873
|
-
if (rich && renderAzureRegion(slide, slideSpec.layout, name, region, fontRoles, P, { hasImage,
|
|
2167
|
+
if (rich && renderAzureRegion(slide, slideSpec.layout, name, region, fontRoles, P, { hasImage, bottom: bottomBoundary[name], groupHeight, flow })) continue;
|
|
1874
2168
|
addRegion(slide, name, region, fontRoles, pageH, bottomBoundary[name], tocSlide, sourceDir);
|
|
1875
2169
|
}
|
|
1876
2170
|
|
|
1877
2171
|
renderPlacements(slide, placements, "content", placementCtx);
|
|
1878
2172
|
renderPlacements(slide, placements, "over", placementCtx);
|
|
2173
|
+
if (notice) addNotice(slide, notice, pageW, pageH, pal);
|
|
1879
2174
|
}
|
|
1880
2175
|
|
|
1881
|
-
await pptx
|
|
2176
|
+
await writeTagged(pptx, outputPath);
|
|
1882
2177
|
return outputPath;
|
|
1883
2178
|
}
|
|
1884
2179
|
|
|
1885
|
-
|
|
2180
|
+
const HANGUL = /[\u1100-\u11FF\u3130-\u318F\uAC00-\uD7A3]/u;
|
|
2181
|
+
|
|
2182
|
+
/**
|
|
2183
|
+
* Korean runs say they are Korean. pptxgenjs marks every run lang="en-US", and a renderer then sets Hangul
|
|
2184
|
+
* by Latin rules: LibreOffice under a non-Korean system locale puts extra space between Hangul and digits
|
|
2185
|
+
* ("주 2회" comes out as "주 2 회"). A run holding Hangul becomes ko-KR with en-US as its alternate
|
|
2186
|
+
* language, and a chart holding Hangul names ko-KR for its text; Latin-only runs stay en-US.
|
|
2187
|
+
*/
|
|
2188
|
+
function tagLanguages(name, xml) {
|
|
2189
|
+
if (/^ppt\/slides\/slide\d+\.xml$/u.test(name)) {
|
|
2190
|
+
return xml.replace(/<a:r><a:rPr\b([^>]*?)(\/?>)([\s\S]*?)<a:t>([^<]*)<\/a:t><\/a:r>/gu, (m, attrs, close, mid, text) => {
|
|
2191
|
+
if (!HANGUL.test(text)) return m;
|
|
2192
|
+
const rest = attrs.replace(/\s(?:lang|altLang)="[^"]*"/gu, "");
|
|
2193
|
+
return `<a:r><a:rPr lang="ko-KR" altLang="en-US"${rest}${close}${mid}<a:t>${text}</a:t></a:r>`;
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
if (/^ppt\/charts\/chart\d+\.xml$/u.test(name) && HANGUL.test(xml)) {
|
|
2197
|
+
let out = xml.replace(/<a:defRPr\b(?![^>]*\blang=)/gu, '<a:defRPr lang="ko-KR" altLang="en-US"')
|
|
2198
|
+
.replace(/<a:endParaRPr lang="en-US"/gu, '<a:endParaRPr lang="ko-KR" altLang="en-US"');
|
|
2199
|
+
if (!/<c:lang\b/u.test(out)) out = out.replace(/(<c:date1904 val="[01]"\/>)/u, '$1<c:lang val="ko-KR"/>');
|
|
2200
|
+
return out;
|
|
2201
|
+
}
|
|
2202
|
+
return xml;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
/**
|
|
2206
|
+
* Write a deck with its Korean runs and charts tagged (tagLanguages). `edit` may rewrite a slide, chart or
|
|
2207
|
+
* theme part first. jszip comes with pptxgenjs in the office runtime.
|
|
2208
|
+
*/
|
|
2209
|
+
async function writeTagged(pptx, outputPath, edit = (name, xml) => xml) {
|
|
2210
|
+
const JSZip = require("jszip");
|
|
2211
|
+
const zip = await JSZip.loadAsync(await pptx.write({ outputType: "nodebuffer" }));
|
|
2212
|
+
for (const name of Object.keys(zip.files).filter((n) => /^ppt\/(slides\/slide|charts\/chart|theme\/theme)\d+\.xml$/u.test(n))) {
|
|
2213
|
+
const xml = await zip.file(name).async("string");
|
|
2214
|
+
zip.file(name, tagLanguages(name, edit(name, xml)));
|
|
2215
|
+
}
|
|
2216
|
+
fs.writeFileSync(outputPath, await zip.generateAsync({ type: "nodebuffer", compression: "DEFLATE" }));
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// ── Tonality packs ──────────────────────────────────────────────────────────
|
|
2220
|
+
//
|
|
2221
|
+
// A pack deck is drawn by render-pack.js. It reuses the helpers below, and the font globals the
|
|
2222
|
+
// free placement boxes read are switched to the pack's faces before it draws.
|
|
2223
|
+
|
|
2224
|
+
function usePackFonts(titleFont, bodyFont, tokens) {
|
|
2225
|
+
FONT_BOLD = titleFont;
|
|
2226
|
+
FONT_MEDIUM = bodyFont;
|
|
2227
|
+
FONT_LIGHT = bodyFont;
|
|
2228
|
+
CHAR_SPACING = 0;
|
|
2229
|
+
applyTokens(tokens);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
module.exports = {
|
|
2233
|
+
render,
|
|
2234
|
+
shared: {
|
|
2235
|
+
hex, cleanMd, mdRuns, linkedTableCell, resolveImagePath, readImageSize, containBox,
|
|
2236
|
+
kpiCards, numericColumns, proportionalWidths, renderChart, stampFamily, renderPlacements, usePackFonts, writeTagged,
|
|
2237
|
+
},
|
|
2238
|
+
};
|