Install
openclaw skills install @yuanxinluo12345/pptx-craft把结构化数据/看板/报表渲染成【可编辑】PowerPoint(.pptx), 重点=高质量排版(不重叠/有气口/不裁切)。引擎用文本优先多遍布局+模板克隆——你给PPT模板路径, 它自动测量可用区、原生生成内容填进去(零复制粘贴, 继承主题)。触发词: 做一份可编辑PPT / 用我的模板生成PPT / 把这个看板导出成PPT / pptx-craft。注意: 引擎吃数据模型, 不解析HTML。
openclaw skills install @yuanxinluo12345/pptx-craft原命名 html2ppt 已不准确 —— 本技能并非"解析 HTML 转 PPT", 已正式更名
pptx-craft。它从一份数据模型渲染可编辑 PPT; HTML / 画布只是用户在过程中可选的"可视化预览兄弟产物", 不参与引擎输入。引擎只认数据。
Generate editable, pixel-precise PowerPoint files without hand-computing absolute
coordinates. The root cause of "PPT 永远做不好排版、永远元素重复、永远没气口" is that
PPT / pptxgenjs is an absolute-positioning engine: 50+ elements = 200+ hand-written
(x,y,w,h), and one miscalculation cascades into overlap/truncation. Worse, even when
coordinates are correct, the gaps (气口) between elements end up too tight because the
layout is a single sequential pass that packs elements to "minimal fit".
This skill replaces hand coordinates with a text-first multi-pass layout that simulates how a human actually builds a slide:
人类工作流 引擎对应 Pass
───────────────────────────── ──────────────────────────────
1. 按尺寸/比例画区域边框 Pass0 flex 容器(区域框)
2. 先放文字(占地最大),四周留白; Pass1 文本优先放置(字体度量测高 + pad 气口)
放不下则缩字号(不删内容) Pass2 字号自适应(溢出按比例缩,保最小字号)
3. 再放装饰(条/图)填空余空间 Pass3 装饰按"文字块底部+气口"定位(填空者)
4. 初稿→QA→二稿→QA→终稿 Pass4-5 QA 迭代(留白不足全局缩字号重排,最多3轮)
Key guarantee: no overlap, no truncation, and measured breathing room (气口) — the
validator refuses to write the file unless every element is in-bounds, non-overlapping
across groups, and cross-group gaps meet a MIN_BREATH floor.
① 输入层 : 数据模型(真相源) + 设计令牌(TOKENS) + 间距令牌(SP) + 密度(DENSITY)
—— HTML/画布是可选的可视化兄弟产物, 不进引擎输入
② 虚拟画布 : 1440×680 px 抽象坐标空间(可随目标比例重设 VW/VH), 均匀缩放+居中 映射目标可用区
③ 容器系统 : Row/Column + flex 权重, 仅用于"区域框"层级(区域内部改文本优先)
④ 组件库 : KpiCard / CompareCard / build_chart / build_progress —— 内部文本优先, 装饰填空
⑤ 文本优先布局 : layout_texts() 字体度量测高 + 上下左右 pad 气口 + 字号自适应(保最小,不删内容)
⑥ 校验层 : 写文件前强制 越界 + 跨组重叠 + 留白下限(防拥挤) 检测; 不过则拒绝产出(终稿轮)
⑦ QA迭代器 : 初稿→二稿→终稿, 用留白提示驱动全局字号缩放(G_TS)
气口(呼吸感)是怎么解决的 (v3 三条杠杆):
- 文本优先 + 字体度量: 文字先"占地",上下左右按
pad留气口、多文字间按breath留气口, 尺寸由字体度量真实估算(宁多勿少,文字绝不裁切),不再"塞满即止"。- 间距令牌 + 密度系数: 所有 gap/padding 取自
SP阶梯表,由DENSITY整体缩放 (1.0 紧凑 / 1.2 舒适 / 1.4 宽松)—— 调一个旋钮即可整体松紧,不用逐块挪。- QA 迭代器: 若终稿仍有留白提示,全局缩小字号
G_TS(每轮 -0.06)重排,最多 3 轮, 用"规则+迭代"替代"人眼反复截图调"。
收到技能请求时, 第一件事就是问用户: "你有没有专用 PPT 模板?" 不要先谈 HTML 尺寸、不要先问画布比例 —— 模板才是唯一锚点。这个回答决定整个输入契约与引擎首动作。
为什么先问模板 (尺寸一致性的根因): PPT 翻车第一因是"生成物与目标模板尺寸/比例不一致 → 复制进去变小/错位"。当模板作锚点, 内容永远按模板本身的真实可用区原生生成, 不存在"另一个尺寸去匹配"的对象 —— 于是"HTML尺寸和PPT尺寸不匹配、能不能自适应"这个伪问题从根上消失: 自适应不是去匹配, 而是以模板为准直接生成。
Branch A — 无专用模板 (use_generic: true)
Presentation + 设尺寸 + 文本优先多遍 + QA。Branch B — 有专用模板 (has_template: true) — 用户只需提供:
template_path (必填): 真实 .pptx 模板路径。start_page (可选, 默认自动探测首个"正文页"): 内容从这一页开始生成; 模板封面/目录/结构页(P1-3等)一律不动。MARGIN_CM(默认1cm) → x∈[M, W-M]。MARGIN_CM:
max(页眉底)+M, 在下半=页脚区取 min(页脚顶)-M;H-M; 溢出续页时对后续页用同规则重算。slide.shapes + slide.slide_layout.shapes(页眉页脚通常在版式上, 漏扫会压页脚)。Presentation(template_path) → 克隆 → 在算出的可用区原生生成内容(直接 add 进 spTree, 零复制粘贴)。主题/字体/页脚/logo 全继承。CONTENT_AREA 或手填包围盒 (x_cm,y_cm,w_cm,h_cm)。经验: 曾用「缩放粘贴」(整页生成→×0.796缩放进可用区) 导致"整体小一圈"; 正确范式是虚拟画布直接映射到可用区 + 原生生成, 字号走 px→pt 不随区域缩小。
Reference sizes (used by Branch A default or as sanity check):
| Type | Width × Height | Ruler range | Aspect |
|---|---|---|---|
| Standard 16:9 | 33.87 × 19.05 cm | -16~+16 / -9~+9 | 1.78:1 |
| Standard 4:3 | 25.4 × 19.05 cm | -12~+12 / -9~+9 | 1.33:1 |
| Custom ultra-wide | 31 × 14 cm | -15~+15 / -6~+6 | 2.21:1 |
Set TOKENS (colors/fonts/radii) and a DASHBOARD_DATA-style model. This is the single
source of truth — keep it consistent with any HTML/canvas sibling so all outputs stay
aligned (but HTML/canvas are optional previews, not inputs). If the data is "live", pass a
snapshot at export time (PPT is a period snapshot, not realtime).
Use VW,VH as the virtual pixel canvas. VW/VH should be derived from the target available
area's aspect ratio (not hardcoded to one size) so the layout re-flows natively:
VW,VH → slide size aspect; SCALE = min(SLIDE_W/VW, SLIDE_H/VH), OFFX centers.VW=1440, VH=round(area_h/area_w*1440), SCALE=area_w/VW,
and OFFX/OFFY = available-area top-left EMU — content placed inside the frame, natively.
Map with uniform scale + area anchoring (no vertical squeeze). Helpers X/Y/W_/H_/FS convert virtual px → EMU/pt.
Slide size: prs.slide_width = Emu(target_cm * 360000) (Branch A only; Branch B reuses template size).Use hbox(deck, box, items, gap, pad) and vbox(deck, box, items, gap, pad) to carve
region frames only. Each item is {"flex": n, "size": px, "group": "g", "build": fn}.
The engine computes child positions from weights — change a parent's height and children
reflow. Note: flex is used for the region level; inside each card the layout switches
to text-first (Step 4).
Call KpiCard, CompareCard, build_progress, build_chart. Each card:
layout_texts(deck, items, box, pad, breath, ...) which:
text_h() (font metrics, CJK-aware),pad (outer) + breath (between) 气口,scale to shrink all fonts
(each keeps its min_fs — content never deleted),leftover space below the text,leftover space — decorations
are "fillers", never the cause of overlap.This is the core fix for "标题贴边 / 标签没气口 / 批次条拥挤": text owns the space first, decorations fill what's left.
validate(deck.recs) returns (errors, warnings) and checks three things:
< MIN_BREATH (default 10px) is reported as a warning.If errors non-empty → raise, do not write the file. Warnings do not block (tuning
hints for DENSITY/G_TS) but a clean run reports "留白校验通过".
Three knobs, in increasing strength:
SP_RAW ladder + DENSITY (1.0/1.2/1.4) — global spacing scale; sp(k) = SP_RAW[k]*DENSITY.pad / breath args inside layout_texts — per-card inner 气口.G_TS (driven by QA iterator) — global font-size scale when gaps still too tight.The engine also emits preview.svg (virtual-coord 1:1) so you can
eyeball 气口 without opening PowerPoint.
deck.render(slide) iterates recorded ops into python-pptx shapes. Set slide background
fill, then prs.save(out).
scripts/pptx_flex_engine.py is a complete, runnable reference implementation (the
switch-migration dashboard case) using the v3 text-first multi-pass architecture.
python scripts/pptx_flex_engine.py → produces migration-dashboard-m3-v4.pptx
migration-dashboard-m3-preview.svg (standard 16:9, 33.87×19.05cm single-page editable deck).template_path (+ optional start_page); the engine
auto-measures the template's available area (scans slide + layout shapes) and fills
it natively — no CONTENT_AREA box or manual dimensions needed.KPI / CMP / BATCHES / DAYS data + build_* functions with target content;
keep TOKENS, hbox/vbox, layout_texts, Deck, and validate unchanged.python-pptx (pip install python-pptx). Uses Microsoft YaHei for editable
Chinese text on Windows.template_path(+可选 start_page), WB 自动扫描模板算可用区(无需画框/报尺寸),
原生生成进 spTree。模板克隆让 PowerPoint 复制粘贴过时(无坐标漂移, 风格自动继承)。
→ 因此"画布/HTML/PPT 尺寸一致性"由模板锚点天然保证, "尺寸不匹配"伪问题消失。slide.shapes + slide.slide_layout.shapes + (必要时) slide.master.shapes;
排除全屏背景; 上下按已有元素留 MARGIN_CM; 漏扫 layout 会压页脚(页眉页脚多在版式上)。(x,y,w,h) for leaf elements — declare structure, let the engine compute.text_h() estimates CJK-aware line height; tune the
0.98/0.55/0.30 width factors if a font renders differently, but keep them conservative
(prefer slightly-too-tall over clipping).min_fs per text item guarantees content survives
even when the frame is tight — the QA iterator then relaxes spacing globally.group so the validator can tell nested-text from
real overlap. Forgetting this yields false overlap errors or missed collisions.为把"个人孵化 → 多场景覆盖 → 产品/专家化"这条路径固化, 命名分三层, 彼此解耦:
| 层级 | 名称 (id) | 显示名 | 角色 |
|---|---|---|---|
| SKILL (引擎) | pptx-craft | PPT匠·可编辑生成引擎 | 数据模型→可编辑PPT + 文本优先多遍 + QA + 模板克隆 |
| EXPERT TEAM (专家团) | ppt-studio | PPT工作室 | 编排多个子专家, 拆解需求并派活 |
| 子专家 (团队内角色) | 见下 | 版式专家 / 数据专家 / QA专家 / 主题专家 | 各管布局 / 适配 / 校验 / 美化 |
pptx-craft 是地基: 不挑使用者, 只吃结构化数据 (人格无关)。ppt-studio 是人格封装: 同一引擎, 不同上车点 ——
技术流专家 (吃 HTML / 数据模型, 适合你本人)零代码专家 (吃画布 / 表单, 适合非技术同事)ppt-studio 编排专家串起来:
命名原则: 名称落到"能力本质"(数据驱动 / 可编辑 / 工艺感), 而非"输入介质"(HTML); 因此强烈建议不要回退到 html2ppt 这类介质名, 以免重新埋下"引擎解析 HTML"的预期坑。