@lark-apaas/coding-steering 0.1.32-dev.4f80f68 → 0.1.32-dev.5abff3b
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/package.json +1 -1
- package/steering/design-html/skills/pptx-style-extract/SKILL.md +18 -16
- package/steering/design-html/skills/pptx-style-extract/scripts/draft.py +1094 -174
- package/steering/design-html/skills/pptx-style-extract/scripts/ooxml.py +18 -1
- package/steering/design-html/skills/pptx-style-extract/scripts/package.py +643 -40
- package/steering/design-html/skills/pptx-style-extract/scripts/test_asset_judgment_package.py +443 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_design_consumer_contract.py +1 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/test_flow_layout_contract.py +157 -7
- package/steering/design-html/skills/pptx-style-extract/scripts/test_layout_css.py +1417 -2
- package/steering/design-html/skills/pptx-style-extract/scripts/test_text_role_contract.py +151 -4
- package/steering/design-html/skills/pptx-style-extract/v2-format-spec.md +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"""Regression tests for inherited layout text and model-decided text roles."""
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
5
|
+
import re
|
|
5
6
|
import sys
|
|
6
7
|
import tempfile
|
|
7
8
|
import unittest
|
|
@@ -142,16 +143,16 @@ class TextRoleContractTest(unittest.TestCase):
|
|
|
142
143
|
with open(path, encoding='utf-8') as stream:
|
|
143
144
|
draft = stream.read()
|
|
144
145
|
|
|
145
|
-
self.assertIn('
|
|
146
|
+
self.assertIn('默认均为 body', draft)
|
|
146
147
|
self.assertIn(
|
|
147
|
-
'layout-1-text-1
|
|
148
|
+
'# text-role: layout-1-text-1',
|
|
148
149
|
draft,
|
|
149
150
|
)
|
|
150
151
|
self.assertEqual(draft.count('box: [120, 80, 840, 120]'), 1)
|
|
151
152
|
|
|
152
153
|
decided = draft.replace(
|
|
153
|
-
'
|
|
154
|
-
'layout-1-text-1: title',
|
|
154
|
+
'layouts:',
|
|
155
|
+
'text_roles:\n layout-1-text-1: title\nlayouts:',
|
|
155
156
|
)
|
|
156
157
|
layouts_md = build_layouts_md(split_top_blocks(decided), (1920, 1080))
|
|
157
158
|
|
|
@@ -163,6 +164,152 @@ class TextRoleContractTest(unittest.TestCase):
|
|
|
163
164
|
)
|
|
164
165
|
self.assertIn('css: "font-size: 48px; color: #C41230"', layouts_md)
|
|
165
166
|
|
|
167
|
+
def test_header_role_uses_a_v2_slot_type(self):
|
|
168
|
+
draft = """names:
|
|
169
|
+
layout-1: 内容页
|
|
170
|
+
roles:
|
|
171
|
+
layout-1: content
|
|
172
|
+
text_roles:
|
|
173
|
+
layout-1-text-1: header
|
|
174
|
+
layouts:
|
|
175
|
+
layout-1:
|
|
176
|
+
slots:
|
|
177
|
+
# text-role: layout-1-text-1
|
|
178
|
+
- {role: body, box: [120, 80, 840, 120], type: body}
|
|
179
|
+
confidence: high
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
layouts_md = build_layouts_md(split_top_blocks(draft), (1920, 1080))
|
|
183
|
+
|
|
184
|
+
self.assertIn(
|
|
185
|
+
'role: header, box: [120, 80, 840, 120], type: body',
|
|
186
|
+
layouts_md,
|
|
187
|
+
)
|
|
188
|
+
self.assertNotIn('type: header', layouts_md)
|
|
189
|
+
|
|
190
|
+
def test_decided_layout_role_replaces_the_draft_default(self):
|
|
191
|
+
draft = """names:
|
|
192
|
+
layout-1: 末页
|
|
193
|
+
roles:
|
|
194
|
+
layout-1: closing
|
|
195
|
+
layouts:
|
|
196
|
+
layout-1:
|
|
197
|
+
role: content
|
|
198
|
+
slots:
|
|
199
|
+
- {role: title, box: [120, 80, 840, 120], type: title}
|
|
200
|
+
confidence: high
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
layouts_md = build_layouts_md(split_top_blocks(draft), (1920, 1080))
|
|
204
|
+
|
|
205
|
+
self.assertIn(' role: closing', layouts_md)
|
|
206
|
+
self.assertNotIn(' role: content', layouts_md)
|
|
207
|
+
self.assertEqual(layouts_md.count(' role:'), 1)
|
|
208
|
+
|
|
209
|
+
def test_last_slide_is_kept_as_a_role_candidate_when_layout_limit_is_full(self):
|
|
210
|
+
shapes, slides = [], []
|
|
211
|
+
for index in range(1, 11):
|
|
212
|
+
slide_part = 'ppt/slides/slide%d.xml' % index
|
|
213
|
+
shapes.append(text_shape(
|
|
214
|
+
slide_part,
|
|
215
|
+
'slide',
|
|
216
|
+
str(index),
|
|
217
|
+
{'x': 120, 'y': 80, 'w': 840, 'h': 120},
|
|
218
|
+
'Slide %d' % index,
|
|
219
|
+
{'type': 'body', 'idx': str(index)},
|
|
220
|
+
))
|
|
221
|
+
slides.append({
|
|
222
|
+
'part': slide_part,
|
|
223
|
+
'layout': 'ppt/slideLayouts/slideLayout1.xml',
|
|
224
|
+
'background': '#%02x0000' % index,
|
|
225
|
+
})
|
|
226
|
+
data = {
|
|
227
|
+
'canvas': {'px': [1920, 1080]},
|
|
228
|
+
'form_hint': {'form': 0},
|
|
229
|
+
'slides': slides,
|
|
230
|
+
'background_composites': {},
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
with tempfile.TemporaryDirectory() as output_dir:
|
|
234
|
+
os.makedirs(os.path.join(output_dir, 'ref'))
|
|
235
|
+
with open(os.path.join(output_dir, 'ref', 'shapes.json'), 'w',
|
|
236
|
+
encoding='utf-8') as stream:
|
|
237
|
+
json.dump({'shapes': shapes}, stream)
|
|
238
|
+
archetypes, _, leftover = draft_layouts(data, output_dir)
|
|
239
|
+
emit_layouts(archetypes, output_dir)
|
|
240
|
+
with open(os.path.join(output_dir, 'layouts.yaml'), encoding='utf-8') as stream:
|
|
241
|
+
draft = stream.read()
|
|
242
|
+
|
|
243
|
+
last_archetype = next(
|
|
244
|
+
archetype for archetype in archetypes if archetype['pages'] == [10]
|
|
245
|
+
)
|
|
246
|
+
self.assertTrue(last_archetype['_last_page_candidate'])
|
|
247
|
+
self.assertNotIn(10, leftover)
|
|
248
|
+
self.assertIn(
|
|
249
|
+
'代表页 %s,共 1 页;' % last_archetype['rep'],
|
|
250
|
+
draft,
|
|
251
|
+
)
|
|
252
|
+
self.assertIn('末页候选,结合样张判断 closing 或实际角色', draft)
|
|
253
|
+
decided = draft.replace(
|
|
254
|
+
'%s: TODO角色' % last_archetype['name'],
|
|
255
|
+
'%s: closing' % last_archetype['name'],
|
|
256
|
+
)
|
|
257
|
+
layouts_md = build_layouts_md(split_top_blocks(decided), (1920, 1080))
|
|
258
|
+
self.assertRegex(
|
|
259
|
+
layouts_md,
|
|
260
|
+
r' %s:\n(?: .*\n)*? role: closing\n'
|
|
261
|
+
% last_archetype['name'],
|
|
262
|
+
)
|
|
263
|
+
self.assertRegex(
|
|
264
|
+
layouts_md,
|
|
265
|
+
r' %s:\n(?: .*\n)*? - \{role: body, box: \[120, 80, 840, 120\]'
|
|
266
|
+
% last_archetype['name'],
|
|
267
|
+
)
|
|
268
|
+
self.assertIn(
|
|
269
|
+
' %s:' % last_archetype['name'],
|
|
270
|
+
layouts_md,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
def test_template_layout_shape_without_ph_key_does_not_crash(self):
|
|
274
|
+
# form=3 模板里,版式层可能有「带 box、带文字、但没有 ph 键」的普通形状
|
|
275
|
+
# (非占位符的文本/装饰)。layouts_from_template 的入口筛选是
|
|
276
|
+
# `s.get('ph') or shape_text(s)`——有文字就放进来,随后按 ph 判类型时若用
|
|
277
|
+
# s['ph'] 直接下标就会 KeyError: 'ph',整份抽取在草案阶段崩掉(EXTRACT_PARTIAL)。
|
|
278
|
+
layout_part = 'ppt/slideLayouts/slideLayout1.xml'
|
|
279
|
+
shape = {
|
|
280
|
+
'part': layout_part,
|
|
281
|
+
'layer': 'layout',
|
|
282
|
+
'id': '7',
|
|
283
|
+
'kind': 'sp',
|
|
284
|
+
'name': '页脚文字',
|
|
285
|
+
# 关键:没有 'ph' 键
|
|
286
|
+
'box': {'x': 100, 'y': 980, 'w': 800, 'h': 60},
|
|
287
|
+
'text': {
|
|
288
|
+
'bodyPr': {},
|
|
289
|
+
'lstStyle': {'lvl1pPr': {'sz_px': 20}},
|
|
290
|
+
'paragraphs': [{'runs': [{'text': '内部资料'}]}],
|
|
291
|
+
},
|
|
292
|
+
}
|
|
293
|
+
data = {
|
|
294
|
+
'canvas': {'px': [1920, 1080]},
|
|
295
|
+
'form_hint': {'form': 3},
|
|
296
|
+
'layouts': [{'part': layout_part}],
|
|
297
|
+
'slides': [{'part': 'ppt/slides/slide1.xml', 'layout': layout_part,
|
|
298
|
+
'background': None}],
|
|
299
|
+
'background_composites': {},
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
with tempfile.TemporaryDirectory() as output_dir:
|
|
303
|
+
os.makedirs(os.path.join(output_dir, 'ref'))
|
|
304
|
+
with open(os.path.join(output_dir, 'ref', 'shapes.json'), 'w',
|
|
305
|
+
encoding='utf-8') as stream:
|
|
306
|
+
json.dump({'shapes': [shape]}, stream)
|
|
307
|
+
# 修复前这里抛 KeyError: 'ph'(draft.py 用 s['ph'] 直接下标),
|
|
308
|
+
# 抽取在草案阶段崩掉、退成 EXTRACT_PARTIAL。修复后应正常返回。
|
|
309
|
+
archetypes, pages, leftover = draft_layouts(data, output_dir)
|
|
310
|
+
|
|
311
|
+
self.assertIsInstance(archetypes, list)
|
|
312
|
+
|
|
166
313
|
|
|
167
314
|
if __name__ == '__main__':
|
|
168
315
|
unittest.main()
|
|
@@ -133,7 +133,7 @@ layouts:
|
|
|
133
133
|
|
|
134
134
|
- **`background` 三形态**:`<asset-id>` / `{<theme>: <asset-id>}` / `{color: <colors-token>}`(`color` 是保留键,主题名禁止叫 color)。`asset` 两形态:`<asset-id>` / `{<theme>: <asset-id>}`。
|
|
135
135
|
- **背景安全扩展**:有真实背景图的 archetype 建议写 `text_safe: [x,y,w,h]`、`avoid: [{box: [x,y,w,h], reason: "..."}]`、`pairing_rule: "..."`。这些是消费约束,不参与封闭枚举;用于避免标题、正文、图表、卡片、表格、时间线及其容器外接矩形覆盖背景视觉主体、强光斑或深色透明区;透明容器也不能跨进禁放区。
|
|
136
|
-
- **流式页型**:内容长度会变化的内容页可用 `flow.regions` 表达纵向区带。`stack` 表达单列顺序,`grid` 表达并列列组,`free` 中的 item 必须带 `box`,用于 logo、页码、页眉和页脚等固定锚点。并列卡片可在 `grid.items` 中使用一层 `{role: group, css, gap, items}`:group 的 `css` 是卡片容器样式,内部 `items` 按顺序排布;不继续嵌套 group
|
|
136
|
+
- **流式页型**:内容长度会变化的内容页可用 `flow.regions` 表达纵向区带。`stack` 表达单列顺序,`grid` 表达并列列组,`free` 中的 item 必须带 `box`,用于 logo、页码、页眉和页脚等固定锚点。并列卡片可在 `grid.items` 中使用一层 `{role: group, css, gap, items}`:group 的 `css` 是卡片容器样式,内部 `items` 按顺序排布;不继续嵌套 group。区带可带自己的 `margin: [左, 右]`,覆盖 `flow` 整块的 `margin`(居中卡片组和贴左标题横向范围本就不同);不带则继承整块 `margin`。纵向位置与留白由消费模型结合实际内容决定,不把样张的 `y` 坐标当作流式硬约束。
|
|
137
137
|
- **`decor`(可选)**:这一页无文字的图形骨架——图标托底的圆、卡片、分隔线。每条 `{box, geom, css}`:`box` 定位,`css` 是可直接写进 style 的声明串,`geom` 取源形状的 prst(`ellipse` 另加 `border-radius: 50%`)。圆角以每条 `css` 为准,没有 `border-radius` 就按 `0`;不得因 `geom: roundRect` 自行补圆角,因为 OOXML 的 roundRect 可以有零圆角调节点。层级在背景之上、`slots` 之下;带 `asset` 的槽落在 decor 之上是版式本意,不算重叠。
|
|
138
138
|
- **slot 样式契约**:`box` 只承载 `[x,y,w,h]` 几何;可渲染属性统一放进 `css`,并可直接写入 HTML `style`。PPTX `bodyPr.insets_px` 转成 `box-sizing: border-box; padding: ...`,字号/字重/颜色/水平与垂直对齐/行高/字距/旋转分别转成标准 CSS。禁止在 slot 中输出 `size` / `weight` / `color` / `align` / `valign` / `insets_px` 等旧字段。
|
|
139
139
|
- **文本角色判断**:脚本把实例页及其引用版式中的现有文本槽、几何和 CSS 完整写入草案;`text_roles` 只供模型把这些槽判断为 `title | subtitle | header | footer | body`,不控制槽位去留。判断不清时用 `body`,不归纳模板中不存在的标题、页眉或页脚。
|