@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.7

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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
  4. package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
  5. package/bundled-assets/skill/LICENSE +21 -0
  6. package/bundled-assets/skill/README.md +61 -0
  7. package/bundled-assets/skill/SKILL.md +185 -0
  8. package/bundled-assets/skill/references/art-directions.md +99 -0
  9. package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
  10. package/bundled-assets/skill/references/design-baseline.txt +1 -0
  11. package/bundled-assets/skill/references/prompt-compiler.md +99 -0
  12. package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
  13. package/bundled-assets/skill/references/staged-pptx.md +71 -0
  14. package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
  15. package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
  16. package/bundled-assets/skill/scripts/brand_ref.py +776 -0
  17. package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
  18. package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
  19. package/bundled-assets/skill/scripts/export_images.py +280 -0
  20. package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
  21. package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
  22. package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
  23. package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
  24. package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
  25. package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
  26. package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
  27. package/bundled-assets/skill/scripts/render_gradient.py +258 -0
  28. package/bundled-assets/skill/scripts/slide_brand.py +111 -0
  29. package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
  30. package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
  31. package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
  32. package/bundled-assets/skill/vendor/README.md +4 -0
  33. package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
  34. package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
  35. package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
  36. package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
  37. package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
  38. package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
  39. package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
  40. package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
  41. package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
  42. package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
  43. package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
  44. package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
  45. package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
  46. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
  47. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
  48. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
  49. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
  50. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
  51. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
  52. package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
  53. package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
  54. package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
  55. package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
  56. package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
  57. package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
  58. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
  59. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
  60. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
  61. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
  62. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
  63. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
  64. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
  65. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
  66. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
  67. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
  68. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
  69. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
  70. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
  71. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
  72. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
  73. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
  74. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
  75. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
  76. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
  77. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
  78. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
  79. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
  80. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
  81. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
  82. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
  83. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
  84. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
  85. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
  86. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
  87. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
  88. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
  89. package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
  90. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
  91. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
  92. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
  93. package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
  94. package/cordis.patch.yml +3 -0
  95. package/lib/client.js +11282 -0
  96. package/lib/index.js +2638 -0
  97. package/package.json +140 -4
@@ -0,0 +1,873 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import hashlib
4
+ import json
5
+ import posixpath
6
+ import re
7
+ import zipfile
8
+ from pathlib import Path
9
+ from xml.etree import ElementTree as ET
10
+
11
+ from build_pptx_from_manifest import TEXT_ALIGNMENTS, TEXT_VERTICAL_ALIGNMENTS, normalize_manifest, slide_xml
12
+
13
+
14
+ NS = {
15
+ "a": "http://schemas.openxmlformats.org/drawingml/2006/main",
16
+ "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
17
+ "rel": "http://schemas.openxmlformats.org/package/2006/relationships",
18
+ }
19
+
20
+ ALLOWED_SOURCE_TYPES = {
21
+ "asset-sheet-separated",
22
+ "imagegen",
23
+ "latex-rendered-formula",
24
+ "user-provided",
25
+ "user-approved-rasterization",
26
+ }
27
+ REQUIRED_QUALITY_CHECKS = {
28
+ "font_size_calibrated",
29
+ "visual_inventory_matched",
30
+ "background_strategy_checked",
31
+ "shape_corner_geometry_checked",
32
+ }
33
+ FOREGROUND_TERMS = {
34
+ "badge",
35
+ "decorative",
36
+ "foreground",
37
+ "hand-drawn",
38
+ "icon",
39
+ "illustration",
40
+ "image block",
41
+ "logo",
42
+ "mark",
43
+ "photo",
44
+ "pictogram",
45
+ "screenshot",
46
+ "semantic",
47
+ "sticker",
48
+ "symbol",
49
+ "trend",
50
+ "visual object",
51
+ "前景",
52
+ "图标",
53
+ "照片",
54
+ "截图",
55
+ "徽章",
56
+ "贴纸",
57
+ "语义",
58
+ "视觉对象",
59
+ }
60
+ NON_FOREGROUND_TERMS = {
61
+ "background",
62
+ "clean base",
63
+ "formula",
64
+ "latex",
65
+ "native structural",
66
+ "structural shape",
67
+ "背景",
68
+ "公式",
69
+ "结构",
70
+ }
71
+ ASSET_SHEET_TERMS = {
72
+ "asset-sheet",
73
+ "asset sheet",
74
+ "asset_sheet",
75
+ "image edit",
76
+ "imagegen",
77
+ "separated",
78
+ "source-faithful",
79
+ "source faithful",
80
+ "split",
81
+ "分离",
82
+ }
83
+ FORBIDDEN_FOREGROUND_FALLBACK_TERMS = {
84
+ "approximate",
85
+ "approximation",
86
+ "approximated",
87
+ "crop",
88
+ "cropped",
89
+ "direct crop",
90
+ "direct source",
91
+ "emoji",
92
+ "fallback",
93
+ "native approximation",
94
+ "source crop",
95
+ "source snippet",
96
+ "text symbol",
97
+ "warning only",
98
+ "warning_only",
99
+ "近似",
100
+ "裁切",
101
+ "裁剪",
102
+ "降级",
103
+ }
104
+
105
+
106
+ def read_manifest(path):
107
+ if not path:
108
+ return {}
109
+ return json.loads(Path(path).read_text(encoding="utf-8"))
110
+
111
+
112
+ def contains_any(text, terms):
113
+ # English terms are words, not substrings (e.g. mark != benchmark).
114
+ return any(re.search(r"(?<![a-z0-9])" + re.escape(term) + r"(?![a-z0-9])", text.lower()) for term in terms)
115
+
116
+
117
+ def visual_item_path(item):
118
+ for key in ("path", "asset", "asset_path", "image", "image_path", "corresponding_asset"):
119
+ value = item.get(key) if isinstance(item, dict) else None
120
+ if isinstance(value, str) and value.strip():
121
+ return Path(value).as_posix()
122
+ return None
123
+
124
+
125
+ def is_foreground_visual_item(item):
126
+ if isinstance(item, dict):
127
+ role = item.get("role")
128
+ if role in {"foreground", "background", "structure", "formula"}:
129
+ return role == "foreground"
130
+ # Free-form notes, file names and provenance explanations are not types.
131
+ text = str(item.get("object_type") or item.get("description") or "")
132
+ else:
133
+ text = str(item)
134
+ if contains_any(text, NON_FOREGROUND_TERMS):
135
+ return False
136
+ return contains_any(text, FOREGROUND_TERMS)
137
+
138
+
139
+ def has_forbidden_decision(decision):
140
+ # Legacy decisions may describe the method in prose; ignore simple negative
141
+ # statements, but never mine arbitrary notes for forbidden keywords.
142
+ text = str(decision).lower()
143
+ terms = "|".join(re.escape(term) for term in sorted(FORBIDDEN_FOREGROUND_FALLBACK_TERMS, key=len, reverse=True))
144
+ text = re.sub(r"\b(?:no|not|without|never)(?:\s+using)?\s+(?:" + terms + r")(?![a-z0-9])", "", text)
145
+ text = re.sub(r"(?:没有|未使用|不使用|无需|禁止)(?:" + terms + r")", "", text)
146
+ return contains_any(text, FORBIDDEN_FOREGROUND_FALLBACK_TERMS)
147
+
148
+
149
+ def foreground_asset_contract_violations(manifest):
150
+ violations = []
151
+ allowed_foreground_sources = {"asset-sheet-separated", "imagegen"}
152
+ provenance_by_path = {
153
+ Path(entry["path"]).as_posix(): entry
154
+ for entry in manifest.get("asset_provenance", [])
155
+ if isinstance(entry, dict) and entry.get("path")
156
+ }
157
+ foreground_paths = set()
158
+
159
+ for index, item in enumerate(manifest.get("visual_inventory", [])):
160
+ field = f"visual_inventory[{index}]"
161
+ if isinstance(item, dict) and "role" in item and item["role"] not in {"foreground", "background", "structure", "formula"}:
162
+ violations.append({"field": field + ".role", "reason": "role must be foreground, background, structure, or formula"})
163
+ if not is_foreground_visual_item(item):
164
+ continue
165
+ structured = isinstance(item, dict) and any(key in item for key in ("role", "object_type", "source_type"))
166
+ decision = item.get("decision", "") if isinstance(item, dict) else item
167
+ declared_source = item.get("source_type") if isinstance(item, dict) else None
168
+ if (not structured and has_forbidden_decision(decision)) or (declared_source is not None and declared_source not in allowed_foreground_sources):
169
+ violations.append({"field": field, "reason": "foreground visual decisions must not use direct crops, native approximations, emoji/text symbols, or warning-only fallbacks"})
170
+ path = visual_item_path(item)
171
+ if path:
172
+ foreground_paths.add(path)
173
+ provenance = provenance_by_path.get(path)
174
+ if not provenance or provenance.get("source_type") not in allowed_foreground_sources:
175
+ violations.append({"field": field, "path": path, "reason": "foreground visual objects require matching asset-sheet-separated or imagegen provenance"})
176
+ elif declared_source is not None and declared_source != provenance.get("source_type"):
177
+ violations.append({"field": field + ".source_type", "path": path, "reason": "source_type must match the linked asset provenance"})
178
+ elif structured:
179
+ violations.append({"field": field, "reason": "structured foreground visual objects require an asset path linked to provenance"})
180
+ elif not contains_any(str(decision), ASSET_SHEET_TERMS) or not any(
181
+ entry.get("source_type") in allowed_foreground_sources for entry in provenance_by_path.values()
182
+ ):
183
+ # Legacy inventories sometimes summarize several assets without paths.
184
+ # Keep them readable, but a claim of separation alone is not evidence.
185
+ violations.append({"field": field, "reason": "legacy foreground visual objects require an asset-sheet separation decision and matching permitted asset provenance"})
186
+
187
+ for index, entry in enumerate(manifest.get("asset_provenance", [])):
188
+ if not isinstance(entry, dict):
189
+ continue
190
+ path = Path(entry.get("path", "")).as_posix()
191
+ if (path in foreground_paths or is_foreground_visual_item(entry)) and entry.get("source_type") not in allowed_foreground_sources:
192
+ violations.append({"field": f"asset_provenance[{index}]", "path": path, "reason": "foreground asset provenance must use asset-sheet-separated or imagegen"})
193
+ return violations
194
+
195
+
196
+ def is_full_slide_image(item, slide):
197
+ width = float(slide.get("width", 13.333))
198
+ height = float(slide.get("height", 7.5))
199
+ left = float(item.get("left", 0))
200
+ top = float(item.get("top", 0))
201
+ image_width = float(item.get("width", 0))
202
+ image_height = float(item.get("height", 0))
203
+ return (
204
+ abs(left) <= 0.02
205
+ and abs(top) <= 0.02
206
+ and image_width >= width * 0.98
207
+ and image_height >= height * 0.98
208
+ )
209
+
210
+
211
+ def page_contract_violations(manifest):
212
+ violations = []
213
+ slide = manifest.get("slide", {})
214
+ images = manifest.get("images", [])
215
+ text_boxes = manifest.get("text_boxes", []) or manifest.get("tables", [])
216
+ provenance_by_path = {
217
+ Path(entry.get("path", "")).as_posix(): entry
218
+ for entry in manifest.get("asset_provenance", [])
219
+ if entry.get("path")
220
+ }
221
+ for image in images:
222
+ path = Path(image.get("path", "")).as_posix()
223
+ provenance = provenance_by_path.get(path, {})
224
+ source_type = provenance.get("source_type")
225
+ if is_full_slide_image(image, slide) and Path(path).name == "source.png" and text_boxes:
226
+ violations.append(
227
+ {
228
+ "field": "images",
229
+ "path": path,
230
+ "reason": "full-slide source.png background with editable text overlays causes baked-text overlap",
231
+ }
232
+ )
233
+ if (
234
+ is_full_slide_image(image, slide)
235
+ and source_type in {"user-provided", "user-approved-rasterization"}
236
+ and text_boxes
237
+ ):
238
+ violations.append(
239
+ {
240
+ "field": "asset_provenance",
241
+ "path": path,
242
+ "reason": "full-slide raster background cannot be assembled with editable text",
243
+ }
244
+ )
245
+
246
+ return violations
247
+
248
+
249
+ def quality_contract_violations(manifest):
250
+ violations = []
251
+
252
+ if "visual_inventory" not in manifest:
253
+ violations.append(
254
+ {
255
+ "field": "visual_inventory",
256
+ "reason": "page manifest must record the non-text visual inventory, even when it is empty",
257
+ }
258
+ )
259
+ elif not isinstance(manifest.get("visual_inventory"), list):
260
+ violations.append({"field": "visual_inventory", "reason": "visual_inventory must be a list"})
261
+
262
+ background_strategy = manifest.get("background_strategy")
263
+ if not background_strategy:
264
+ violations.append(
265
+ {
266
+ "field": "background_strategy",
267
+ "reason": "page manifest must record how the background was rebuilt or preserved",
268
+ }
269
+ )
270
+
271
+ quality_checks = manifest.get("quality_checks")
272
+ if not isinstance(quality_checks, dict):
273
+ violations.append({"field": "quality_checks", "reason": "quality_checks must be an object"})
274
+ else:
275
+ for key in sorted(REQUIRED_QUALITY_CHECKS):
276
+ if quality_checks.get(key) is not True:
277
+ violations.append(
278
+ {
279
+ "field": f"quality_checks.{key}",
280
+ "reason": "required page QA check must be explicitly true",
281
+ }
282
+ )
283
+
284
+ for index, shape in enumerate(manifest.get("shapes", [])):
285
+ is_round_rect = shape.get("type") == "roundRect" or shape.get("preset") == "roundRect"
286
+ if is_round_rect and not shape.get("source_corner_radius_px"):
287
+ violations.append(
288
+ {
289
+ "field": f"shapes[{index}]",
290
+ "reason": "roundRect requires source_corner_radius_px; use rect for source straight-corner containers",
291
+ }
292
+ )
293
+ if is_round_rect and shape.get("source_corner_radius_px") and shape.get("box_px"):
294
+ box = shape.get("box_px")
295
+ radius = float(shape.get("source_corner_radius_px") or 0)
296
+ min_dim = max(1.0, min(float(box[2]), float(box[3])))
297
+ if radius > min_dim / 2:
298
+ violations.append(
299
+ {
300
+ "field": f"shapes[{index}].source_corner_radius_px",
301
+ "reason": "roundRect source radius cannot exceed half of the smaller shape dimension",
302
+ }
303
+ )
304
+
305
+ for index, text_box in enumerate(manifest.get("text_boxes", [])):
306
+ align = str(text_box.get("align", "left") or "left").strip().lower()
307
+ if align not in TEXT_ALIGNMENTS:
308
+ violations.append(
309
+ {
310
+ "field": f"text_boxes[{index}].align",
311
+ "reason": "text align must be left, center, right, or the equivalent DrawingML token l, ctr, r",
312
+ }
313
+ )
314
+ valign = str(text_box.get("valign", "top") or "top").strip().lower()
315
+ if valign not in TEXT_VERTICAL_ALIGNMENTS:
316
+ violations.append(
317
+ {
318
+ "field": f"text_boxes[{index}].valign",
319
+ "reason": "text valign must be top, middle, bottom, or the equivalent DrawingML token t, ctr, b",
320
+ }
321
+ )
322
+
323
+ violations.extend(foreground_asset_contract_violations(manifest))
324
+ return violations
325
+
326
+
327
+ def pixel_authoring_violations(manifest):
328
+ violations = []
329
+ source = manifest.get("source", {})
330
+ if not source.get("width_px") or not source.get("height_px"):
331
+ violations.append(
332
+ {
333
+ "field": "source.width_px/source.height_px",
334
+ "reason": "page manifest must record the source image pixel size",
335
+ }
336
+ )
337
+
338
+ for section in ("text_boxes", "images", "tables"):
339
+ for index, item in enumerate(manifest.get(section, [])):
340
+ if "box_px" not in item:
341
+ violations.append(
342
+ {
343
+ "field": f"{section}[{index}].box_px",
344
+ "reason": "positioned text, image, and table objects must use source-image pixel coordinates",
345
+ }
346
+ )
347
+
348
+ for index, item in enumerate(manifest.get("shapes", [])):
349
+ if item.get("type") == "line":
350
+ if "points_px" not in item:
351
+ violations.append(
352
+ {
353
+ "field": f"shapes[{index}].points_px",
354
+ "reason": "line shapes must use source-image pixel endpoints",
355
+ }
356
+ )
357
+ elif "box_px" not in item:
358
+ violations.append(
359
+ {
360
+ "field": f"shapes[{index}].box_px",
361
+ "reason": "positioned shapes must use source-image pixel coordinates",
362
+ }
363
+ )
364
+
365
+ return violations
366
+
367
+
368
+ def normalize_for_validation(manifest):
369
+ violations = pixel_authoring_violations(manifest)
370
+ try:
371
+ return normalize_manifest(manifest), violations
372
+ except Exception as exc:
373
+ violations.append({"field": "manifest", "reason": str(exc)})
374
+ return manifest, violations
375
+
376
+
377
+ def line_geometry_violations(manifest, root):
378
+ """Check actual slide objects, rather than trusting the page's QA flags."""
379
+ if not any(item.get("type") == "path" or item.get("dash") or item.get("start_arrow") or item.get("end_arrow") or item.get("semantic_line_id")
380
+ for item in manifest.get("shapes", [])):
381
+ return []
382
+ expected = ET.fromstring(slide_xml(normalize_manifest(manifest))).findall(".//p:sp", NS)
383
+ actual = root.findall(".//p:sp", NS)
384
+ if len(actual) != len(expected):
385
+ return [{"field": "shapes", "reason": "slide object count differs from manifest; a line may be fragmented or missing"}]
386
+ violations = []
387
+ for index, (wanted, found) in enumerate(zip(expected, actual)):
388
+ props = wanted.find("p:spPr", NS)
389
+ name = wanted.find("p:nvSpPr/p:cNvPr", NS).get("name", "")
390
+ if not name.startswith(("Path ", "Line ")) and not any(props.find(f"a:ln/a:{tag}", NS) is not None for tag in ("prstDash", "headEnd", "tailEnd")):
391
+ continue
392
+ # Whitespace and namespace prefix changes do not affect the structure.
393
+ def structure(element):
394
+ if element is None:
395
+ return None
396
+ return element.tag, sorted(element.attrib.items()), [structure(child) for child in element]
397
+
398
+ if structure(props) != structure(found.find("p:spPr", NS)):
399
+ violations.append({"field": f"slide.shapes[{index}]", "reason": "path geometry, position, dash or arrow properties differ from manifest"})
400
+ return violations
401
+
402
+
403
+ def table_structure_violations(manifest, root):
404
+ """Verify native table geometry, cells, merges and formatting in the actual PPTX."""
405
+ def frames(slide):
406
+ return [frame for frame in slide.findall(".//p:graphicFrame", NS)
407
+ if frame.find("a:graphic/a:graphicData/a:tbl", NS) is not None]
408
+
409
+ actual = frames(root)
410
+ if len(actual) != len(manifest.get("tables", [])):
411
+ return [{"field": "tables", "reason": "native table count differs from manifest"}]
412
+ if not actual:
413
+ return []
414
+ expected = frames(ET.fromstring(slide_xml(normalize_manifest(manifest))))
415
+
416
+ def structure(node):
417
+ if node is None:
418
+ return None
419
+ return (node.tag, sorted(node.attrib.items()), node.text if node.tag == f"{{{NS['a']}}}t" else None,
420
+ [structure(child) for child in node])
421
+
422
+ violations = []
423
+ for index, (wanted, found) in enumerate(zip(expected, actual)):
424
+ for path in ("p:xfrm", "a:graphic"):
425
+ if structure(wanted.find(path, NS)) != structure(found.find(path, NS)):
426
+ violations.append({"field": f"tables[{index}]", "reason": "native table geometry, content, merges or style differs from manifest"})
427
+ break
428
+ return violations
429
+
430
+
431
+ def sha256_text(value):
432
+ return hashlib.sha256(str(value).encode("utf-8")).hexdigest()
433
+
434
+
435
+ def flatten_required_text(value):
436
+ """Return exact text strings that should be verified in the PPTX."""
437
+ items = []
438
+ if value is None:
439
+ return items
440
+ if isinstance(value, str):
441
+ text = value.strip()
442
+ return [text] if text else []
443
+ if isinstance(value, (int, float)):
444
+ return [str(value)]
445
+ if isinstance(value, dict):
446
+ if "required_text" in value:
447
+ return flatten_required_text(value.get("required_text"))
448
+ if "items" in value:
449
+ return flatten_required_text(value.get("items"))
450
+ if "texts" in value:
451
+ return flatten_required_text(value.get("texts"))
452
+ if "text" in value:
453
+ return flatten_required_text(value.get("text"))
454
+ return items
455
+ if isinstance(value, (list, tuple, set)):
456
+ for item in value:
457
+ items.extend(flatten_required_text(item))
458
+ return items
459
+
460
+
461
+ def required_texts_from_manifest(manifest):
462
+ required = []
463
+ required.extend(flatten_required_text(manifest.get("required_text", [])))
464
+ required.extend(flatten_required_text(manifest.get("text_inventory", [])))
465
+ for table in manifest.get("tables", []):
466
+ for text in flatten_required_text(table.get("cells", [])):
467
+ required.extend(line for line in text.splitlines() if line)
468
+ return required
469
+
470
+
471
+ def collect_text(xml_bytes):
472
+ root = ET.fromstring(xml_bytes)
473
+ return "".join(node.text or "" for node in root.findall(".//a:t", NS))
474
+
475
+
476
+ def collect_paragraph_text(xml_bytes):
477
+ root = ET.fromstring(xml_bytes)
478
+ paragraphs = []
479
+ for paragraph in root.findall(".//a:p", NS):
480
+ text = "".join(node.text or "" for node in paragraph.findall(".//a:t", NS))
481
+ if text:
482
+ paragraphs.append(text)
483
+ return "\n".join(paragraphs)
484
+
485
+
486
+ def collect_notes_texts(z, names):
487
+ notes = {}
488
+ for name in sorted(n for n in names if re.match(r"ppt/notesSlides/notesSlide\d+\.xml$", n)):
489
+ match = re.search(r"notesSlide(\d+)\.xml$", name)
490
+ if not match:
491
+ continue
492
+ notes[int(match.group(1))] = collect_paragraph_text(z.read(name))
493
+ return notes
494
+
495
+
496
+ def validate_deck(args):
497
+ deck_path = Path(args.deck_manifest).resolve()
498
+ deck = read_manifest(deck_path)
499
+ root = Path(deck.get("job_dir", deck_path.parent)).resolve()
500
+ expected_pages = int(deck.get("page_count", len(deck.get("pages", []))))
501
+ notes_manifest = {}
502
+ notes_path = deck.get("notes_manifest")
503
+ if notes_path:
504
+ notes_file = Path(notes_path)
505
+ if not notes_file.is_absolute():
506
+ notes_file = root / notes_file
507
+ if notes_file.exists():
508
+ notes_manifest = read_manifest(notes_file)
509
+
510
+ report = {
511
+ "pptx": str(Path(args.pptx).resolve()),
512
+ "deck_manifest": str(deck_path),
513
+ "expected_pages": expected_pages,
514
+ "slides": 0,
515
+ "page_manifests_missing": [],
516
+ "page_validation_missing": [],
517
+ "failed_page_validations": [],
518
+ "page_contract_violations": [],
519
+ "notes_expected": len(notes_manifest.get("notes", [])),
520
+ "notes_found": 0,
521
+ "notes_hash_mismatches": [],
522
+ "missing_parts": [],
523
+ "warnings": [],
524
+ "passed": False,
525
+ }
526
+
527
+ geometry_manifests = []
528
+ for page_index, page in enumerate(deck.get("pages", []), start=1):
529
+ manifest_path = Path(page.get("manifest", ""))
530
+ validation_path = Path(page.get("validation", ""))
531
+ if not manifest_path.is_absolute():
532
+ manifest_path = root / manifest_path
533
+ if not validation_path.is_absolute():
534
+ validation_path = root / validation_path
535
+ if not manifest_path.exists():
536
+ report["page_manifests_missing"].append(str(manifest_path))
537
+ else:
538
+ try:
539
+ raw_manifest = read_manifest(manifest_path)
540
+ normalized_manifest, authoring_violations = normalize_for_validation(raw_manifest)
541
+ if not authoring_violations:
542
+ geometry_manifests.append((page_index, normalized_manifest))
543
+ violations = (
544
+ authoring_violations
545
+ + page_contract_violations(normalized_manifest)
546
+ + quality_contract_violations(raw_manifest)
547
+ )
548
+ if violations:
549
+ report["page_contract_violations"].append(
550
+ {
551
+ "page_id": page.get("page_id"),
552
+ "manifest": str(manifest_path),
553
+ "violations": violations,
554
+ }
555
+ )
556
+ except Exception as exc:
557
+ report["page_contract_violations"].append(
558
+ {
559
+ "page_id": page.get("page_id"),
560
+ "manifest": str(manifest_path),
561
+ "violations": [{"field": "manifest", "reason": str(exc)}],
562
+ }
563
+ )
564
+ if not validation_path.exists():
565
+ report["page_validation_missing"].append(str(validation_path))
566
+ else:
567
+ try:
568
+ page_report = read_manifest(validation_path)
569
+ if page_report.get("passed") is False:
570
+ report["failed_page_validations"].append(str(validation_path))
571
+ except Exception as exc:
572
+ report["failed_page_validations"].append(f"{validation_path}: {exc}")
573
+
574
+ try:
575
+ with zipfile.ZipFile(args.pptx) as z:
576
+ names = z.namelist()
577
+ report["slides"] = len([n for n in names if re.match(r"ppt/slides/slide\d+\.xml$", n)])
578
+ for page_index, page_manifest in geometry_manifests:
579
+ slide_part = f"ppt/slides/slide{page_index}.xml"
580
+ if slide_part in names:
581
+ slide_root = ET.fromstring(z.read(slide_part))
582
+ violations = (line_geometry_violations(page_manifest, slide_root)
583
+ + table_structure_violations(page_manifest, slide_root))
584
+ if violations:
585
+ report["page_contract_violations"].append({"page_index": page_index, "violations": violations})
586
+ for part in ("[Content_Types].xml", "_rels/.rels", "ppt/presentation.xml", "ppt/_rels/presentation.xml.rels"):
587
+ if part not in names:
588
+ report["missing_parts"].append(part)
589
+ notes_texts = collect_notes_texts(z, names)
590
+ report["notes_found"] = len(notes_texts)
591
+ for entry in notes_manifest.get("notes", []):
592
+ page_index = int(entry.get("page_index", 0))
593
+ expected_hash = entry.get("text_sha256", sha256_text(entry.get("text", "")))
594
+ actual = notes_texts.get(page_index)
595
+ if actual is None:
596
+ report["notes_hash_mismatches"].append({"page_index": page_index, "reason": "missing notes slide"})
597
+ elif sha256_text(actual) != expected_hash:
598
+ report["notes_hash_mismatches"].append({"page_index": page_index, "reason": "text hash mismatch"})
599
+ except Exception as exc:
600
+ report["warnings"].append(f"Unable to read pptx: {exc}")
601
+
602
+ report["passed"] = (
603
+ report["slides"] == expected_pages
604
+ and not report["page_manifests_missing"]
605
+ and not report["page_validation_missing"]
606
+ and not report["failed_page_validations"]
607
+ and not report["page_contract_violations"]
608
+ and not report["missing_parts"]
609
+ and not report["notes_hash_mismatches"]
610
+ )
611
+ output = json.dumps(report, ensure_ascii=False, indent=2)
612
+ if args.report:
613
+ Path(args.report).parent.mkdir(parents=True, exist_ok=True)
614
+ Path(args.report).write_text(output + "\n", encoding="utf-8")
615
+ print(output)
616
+ raise SystemExit(0 if report["passed"] else 1)
617
+
618
+
619
+ def rel_source_part(rels_name):
620
+ if not rels_name.endswith(".rels"):
621
+ return posixpath.dirname(rels_name)
622
+ directory = posixpath.dirname(rels_name)
623
+ if directory.endswith("/_rels"):
624
+ directory = posixpath.dirname(directory)
625
+ source = posixpath.basename(rels_name)[:-5]
626
+ return posixpath.normpath(posixpath.join(directory, source))
627
+
628
+
629
+ def resolve_target(rels_name, target):
630
+ if not target or re.match(r"^[a-zA-Z][a-zA-Z0-9+.-]*:", target):
631
+ return None
632
+ source = rel_source_part(rels_name)
633
+ return posixpath.normpath(posixpath.join(posixpath.dirname(source), target))
634
+
635
+
636
+ def relationship_targets(z, rels_name, names):
637
+ if rels_name not in names:
638
+ return []
639
+ root = ET.fromstring(z.read(rels_name))
640
+ targets = []
641
+ for rel in root.findall("rel:Relationship", NS):
642
+ mode = rel.attrib.get("TargetMode")
643
+ target = rel.attrib.get("Target")
644
+ resolved = resolve_target(rels_name, target)
645
+ targets.append(
646
+ {
647
+ "id": rel.attrib.get("Id"),
648
+ "type": rel.attrib.get("Type", ""),
649
+ "target": target,
650
+ "resolved": resolved,
651
+ "external": mode == "External",
652
+ }
653
+ )
654
+ return targets
655
+
656
+
657
+ def file_sha256(path):
658
+ digest = hashlib.sha256()
659
+ with Path(path).open("rb") as handle:
660
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
661
+ digest.update(chunk)
662
+ return digest.hexdigest()
663
+
664
+
665
+ def main():
666
+ parser = argparse.ArgumentParser()
667
+ parser.add_argument("pptx")
668
+ parser.add_argument("--manifest")
669
+ parser.add_argument("--deck-manifest")
670
+ parser.add_argument("--required-text", action="append", default=[])
671
+ parser.add_argument("--report")
672
+ args = parser.parse_args()
673
+
674
+ if args.deck_manifest:
675
+ validate_deck(args)
676
+
677
+ raw_manifest = read_manifest(args.manifest)
678
+ manifest, authoring_violations = normalize_for_validation(raw_manifest)
679
+ manifest_base = Path(args.manifest).resolve().parent if args.manifest else Path.cwd()
680
+ required = list(args.required_text)
681
+ required.extend(required_texts_from_manifest(manifest))
682
+
683
+ report = {
684
+ "pptx": str(Path(args.pptx).resolve()),
685
+ "zip_ok": False,
686
+ "slides": 0,
687
+ "images": 0,
688
+ "editable_text_shapes": 0,
689
+ "native_tables": 0,
690
+ "editable_table_cells": 0,
691
+ "shape_count": 0,
692
+ "all_text": "",
693
+ "required_text": required,
694
+ "missing_required_text": [],
695
+ "missing_parts": [],
696
+ "missing_relationship_targets": [],
697
+ "missing_asset_provenance": [],
698
+ "missing_manifest_images": [],
699
+ "missing_provenance_sources": [],
700
+ "invalid_asset_provenance": [],
701
+ "media_hash_mismatches": [],
702
+ "asset_provenance_checked": 0,
703
+ "manifest_image_count": len(manifest.get("images", [])),
704
+ "media_manifest_mismatch": False,
705
+ "relationship_targets_checked": 0,
706
+ "warnings": [],
707
+ "page_contract_violations": [],
708
+ "line_geometry_violations": [],
709
+ "table_structure_violations": [],
710
+ }
711
+
712
+ try:
713
+ with zipfile.ZipFile(args.pptx) as z:
714
+ bad = z.testzip()
715
+ report["zip_ok"] = bad is None
716
+ if bad:
717
+ report["warnings"].append(f"Bad zip member: {bad}")
718
+ names = z.namelist()
719
+ required_parts = [
720
+ "[Content_Types].xml",
721
+ "_rels/.rels",
722
+ "ppt/presentation.xml",
723
+ "ppt/_rels/presentation.xml.rels",
724
+ ]
725
+ for part in required_parts:
726
+ if part not in names:
727
+ report["missing_parts"].append(part)
728
+ slide_names = sorted(n for n in names if re.match(r"ppt/slides/slide\d+\.xml$", n))
729
+ report["slides"] = len(slide_names)
730
+ report["images"] = len([n for n in names if n.startswith("ppt/media/")])
731
+ report["media_manifest_mismatch"] = report["images"] != report["manifest_image_count"]
732
+ for index, image in enumerate(manifest.get("images", []), start=1):
733
+ image_path = image.get("path")
734
+ if not image_path:
735
+ continue
736
+ ext = Path(image_path).suffix.lower()
737
+ if ext == ".jpeg":
738
+ ext = ".jpg"
739
+ media_name = f"ppt/media/image{index}{ext}"
740
+ source_path = Path(image_path)
741
+ if not source_path.is_absolute():
742
+ source_path = manifest_base / source_path
743
+ if media_name not in names:
744
+ report["media_hash_mismatches"].append(
745
+ {"path": image_path, "media": media_name, "reason": "missing media part"}
746
+ )
747
+ continue
748
+ if source_path.exists():
749
+ manifest_hash = file_sha256(source_path)
750
+ media_hash = hashlib.sha256(z.read(media_name)).hexdigest()
751
+ if manifest_hash != media_hash:
752
+ report["media_hash_mismatches"].append(
753
+ {"path": image_path, "media": media_name, "reason": "hash mismatch"}
754
+ )
755
+ else:
756
+ report["missing_manifest_images"].append(str(image_path))
757
+ for slide_name in slide_names:
758
+ rels_name = f"{posixpath.dirname(slide_name)}/_rels/{posixpath.basename(slide_name)}.rels"
759
+ if rels_name not in names:
760
+ report["missing_parts"].append(rels_name)
761
+ rel_files = [name for name in names if name.endswith(".rels")]
762
+ for rels_name in rel_files:
763
+ for target in relationship_targets(z, rels_name, names):
764
+ if target["external"] or not target["resolved"]:
765
+ continue
766
+ report["relationship_targets_checked"] += 1
767
+ if target["resolved"] not in names:
768
+ report["missing_relationship_targets"].append(
769
+ {
770
+ "rels": rels_name,
771
+ "id": target["id"],
772
+ "target": target["target"],
773
+ "resolved": target["resolved"],
774
+ }
775
+ )
776
+ texts = []
777
+ for slide_name in slide_names:
778
+ xml = z.read(slide_name)
779
+ root = ET.fromstring(xml)
780
+ if not authoring_violations:
781
+ report["line_geometry_violations"].extend(line_geometry_violations(manifest, root))
782
+ report["table_structure_violations"].extend(table_structure_violations(manifest, root))
783
+ tables = root.findall(".//a:tbl", NS)
784
+ report["native_tables"] += len(tables)
785
+ report["editable_table_cells"] += sum(
786
+ 1 for table in tables for cell in table.findall("a:tr/a:tc", NS)
787
+ if cell.get("hMerge", "0") not in ("1", "true")
788
+ and cell.get("vMerge", "0") not in ("1", "true")
789
+ and any(node.text for node in cell.findall(".//a:t", NS))
790
+ )
791
+ shapes = root.findall(".//p:sp", NS)
792
+ report["shape_count"] += len(shapes)
793
+ report["editable_text_shapes"] += sum(1 for shape in shapes if shape.findall(".//a:t", NS))
794
+ texts.append(collect_text(xml))
795
+ report["all_text"] = "\n".join(texts)
796
+ except Exception as exc:
797
+ report["warnings"].append(f"Unable to read pptx: {exc}")
798
+
799
+ for text in required:
800
+ if text and text not in report["all_text"]:
801
+ report["missing_required_text"].append(text)
802
+
803
+ provenance = {}
804
+ for entry in manifest.get("asset_provenance", []):
805
+ path = entry.get("path")
806
+ if path:
807
+ provenance[Path(path).as_posix()] = entry
808
+
809
+ for image in manifest.get("images", []):
810
+ image_path = image.get("path")
811
+ if not image_path:
812
+ continue
813
+ key = Path(image_path).as_posix()
814
+ entry = provenance.get(key)
815
+ if not entry:
816
+ report["missing_asset_provenance"].append(key)
817
+ continue
818
+ report["asset_provenance_checked"] += 1
819
+ source_type = entry.get("source_type")
820
+ provenance_note = entry.get("provenance_note")
821
+ if source_type not in ALLOWED_SOURCE_TYPES:
822
+ report["invalid_asset_provenance"].append(
823
+ {"path": key, "field": "source_type", "value": source_type}
824
+ )
825
+ if not provenance_note:
826
+ report["invalid_asset_provenance"].append(
827
+ {"path": key, "field": "provenance_note", "value": provenance_note}
828
+ )
829
+ if source_type == "user-approved-rasterization" and not entry.get("approval_note"):
830
+ report["invalid_asset_provenance"].append(
831
+ {"path": key, "field": "approval_note", "value": entry.get("approval_note")}
832
+ )
833
+ source = entry.get("source")
834
+ if not source:
835
+ report["missing_provenance_sources"].append({"path": key, "source": source})
836
+ continue
837
+ source_path = Path(source)
838
+ if not source_path.is_absolute():
839
+ source_path = manifest_base / source_path
840
+ if not source_path.exists():
841
+ report["missing_provenance_sources"].append({"path": key, "source": str(source)})
842
+ report["page_contract_violations"] = (
843
+ authoring_violations + page_contract_violations(manifest) + quality_contract_violations(raw_manifest)
844
+ )
845
+
846
+ report["passed"] = (
847
+ report["zip_ok"]
848
+ and report["slides"] >= 1
849
+ and not report["media_manifest_mismatch"]
850
+ and not report["missing_parts"]
851
+ and not report["missing_relationship_targets"]
852
+ and not report["media_hash_mismatches"]
853
+ and not report["missing_required_text"]
854
+ and not report["missing_asset_provenance"]
855
+ and not report["missing_manifest_images"]
856
+ and not report["missing_provenance_sources"]
857
+ and not report["invalid_asset_provenance"]
858
+ and not report["page_contract_violations"]
859
+ and not report["line_geometry_violations"]
860
+ and not report["table_structure_violations"]
861
+ and (report["editable_text_shapes"] > 0 or report["editable_table_cells"] > 0 or not required)
862
+ )
863
+
864
+ output = json.dumps(report, ensure_ascii=False, indent=2)
865
+ if args.report:
866
+ Path(args.report).parent.mkdir(parents=True, exist_ok=True)
867
+ Path(args.report).write_text(output + "\n", encoding="utf-8")
868
+ print(output)
869
+ raise SystemExit(0 if report["passed"] else 1)
870
+
871
+
872
+ if __name__ == "__main__":
873
+ main()