@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.
Files changed (120) hide show
  1. package/README-Ko-KR.md +10 -10
  2. package/README.md +10 -10
  3. package/dist/install/generated-skill-payload-hashes.d.ts +101 -40
  4. package/dist/install/generated-skill-payload-hashes.js +101 -40
  5. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
  6. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  7. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  8. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  9. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  10. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  11. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  12. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  13. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  14. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  15. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/THIRD-PARTY-NOTICE.txt +0 -2
  16. package/marketplace/plugins/litcodex/skills/lit-docx/SKILL.md +16 -12
  17. package/marketplace/plugins/litcodex/skills/lit-docx/references/components.md +113 -0
  18. package/marketplace/plugins/litcodex/skills/lit-docx/references/direction-step.md +164 -0
  19. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/01-report-ko.md +95 -0
  20. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/02-brief-ko.md +45 -0
  21. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/03-manual-ko.md +105 -0
  22. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/04-proposal-ko.md +97 -0
  23. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/05-memo-en.md +34 -0
  24. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/06-journal-en.md +89 -0
  25. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/07-report-en.md +101 -0
  26. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/08-proposal-en.md +94 -0
  27. package/marketplace/plugins/litcodex/skills/lit-docx/references/examples/09-memo-ko.md +34 -0
  28. package/marketplace/plugins/litcodex/skills/lit-docx/references/page-composition.md +141 -0
  29. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/brief.md +70 -0
  30. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/journal.md +73 -0
  31. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/manual.md +70 -0
  32. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/memo.md +75 -0
  33. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/proposal.md +71 -0
  34. package/marketplace/plugins/litcodex/skills/lit-docx/references/tonalities/report.md +83 -0
  35. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_docx.py +401 -58
  36. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_craft.py +124 -1
  37. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_design.py +2446 -0
  38. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/docx_layout.py +960 -0
  39. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/slop_lint.py +21 -6
  40. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/brief.yaml +28 -0
  41. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/journal.yaml +26 -0
  42. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/manual.yaml +26 -0
  43. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/memo.yaml +27 -0
  44. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/proposal.yaml +27 -0
  45. package/marketplace/plugins/litcodex/skills/lit-docx/templates/tonalities/report.yaml +27 -0
  46. package/marketplace/plugins/litcodex/skills/lit-pptx/SKILL.md +12 -11
  47. package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/Pretendard-Bold.otf +0 -0
  48. package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/Pretendard-Regular.otf +0 -0
  49. package/marketplace/plugins/litcodex/skills/lit-pptx/references/anti-slop-checklist.md +33 -29
  50. package/marketplace/plugins/litcodex/skills/lit-pptx/references/authoring-guide.md +11 -2
  51. package/marketplace/plugins/litcodex/skills/lit-pptx/references/density-and-fill.md +179 -0
  52. package/marketplace/plugins/litcodex/skills/lit-pptx/references/design-system-azure.md +1 -1
  53. package/marketplace/plugins/litcodex/skills/lit-pptx/references/direction-step.md +203 -0
  54. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +185 -0
  55. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/02-pitch-studio-en.md +162 -0
  56. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +229 -0
  57. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/04-research-talk-paper-en.md +212 -0
  58. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/05-research-keynote-night-ko.md +191 -0
  59. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +175 -0
  60. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/07-data-review-night-en.md +241 -0
  61. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/08-field-report-atlas-ko.md +168 -0
  62. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +219 -0
  63. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/10-status-update-ledger-en.md +157 -0
  64. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/11-portfolio-studio-ko.md +183 -0
  65. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/12-tutorial-chalk-en.md +176 -0
  66. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/13-status-update-gazette-ko.md +157 -0
  67. package/marketplace/plugins/litcodex/skills/lit-pptx/references/interview-protocol.md +1 -1
  68. package/marketplace/plugins/litcodex/skills/lit-pptx/references/layout-families.md +210 -0
  69. package/marketplace/plugins/litcodex/skills/lit-pptx/references/title-treatments.md +146 -0
  70. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/atlas.md +113 -0
  71. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/chalk.md +115 -0
  72. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/gazette.md +118 -0
  73. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/ledger.md +129 -0
  74. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/night.md +126 -0
  75. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/paper.md +109 -0
  76. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/signal.md +121 -0
  77. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/studio.md +111 -0
  78. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/compile-deck.js +65 -17
  79. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/craft_extras.py +654 -11
  80. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/embed_fonts.py +1 -1
  81. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/inventory.py +32 -2
  82. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/directive-parser.js +2 -2
  83. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/grid-resolver.js +521 -0
  84. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/layout-resolver.js +401 -16
  85. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/markdown-loader.js +6 -4
  86. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-adapter-html.js +2 -2
  87. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-adapter-pptx.js +498 -145
  88. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-pack.js +3558 -0
  89. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/slide-ast.js +54 -6
  90. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/template-registry.js +335 -11
  91. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +2 -1
  92. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/qa_deck.py +99 -19
  93. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/validate_pptx.py +6 -1
  94. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/boilerplate_professional.css +6 -6
  95. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-A2Z/layout-mapping.yaml +1 -1
  96. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-A2Z/template.yaml +4 -1
  97. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-PRO/layout-mapping.yaml +1 -1
  98. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/enrolled/AZURE-PRO/template.yaml +4 -1
  99. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +105 -0
  100. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +110 -0
  101. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +105 -0
  102. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +106 -0
  103. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/night/pack.yaml +106 -0
  104. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/paper/pack.yaml +111 -0
  105. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/signal/pack.yaml +107 -0
  106. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/studio/pack.yaml +105 -0
  107. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +1 -1
  108. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +6 -6
  109. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/gate.mjs +1 -1
  110. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.mjs +2 -2
  111. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +1 -1
  112. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +1 -1
  113. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/style-bibles.md +2 -2
  114. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +1 -1
  115. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/type-and-timing.md +3 -3
  116. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  117. package/package.json +2 -2
  118. package/readme-assets/badge-version.svg +1 -1
  119. package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/PretendardGOV-Bold.otf +0 -0
  120. package/marketplace/plugins/litcodex/skills/lit-pptx/pretendard-font/public/static/PretendardGOV-Regular.otf +0 -0
@@ -1,12 +1,24 @@
1
1
  """Deterministic office craft findings for python-pptx decks.
2
2
 
3
- The limits live here so spec revisions change data rather than scattered checks.
3
+ OF-101..OF-109 judge each slide. OF-110..OF-115 judge the output of a tonality pack as a whole:
4
+ how many title treatments the deck shows, whether its layouts vary, whether bodies are used,
5
+ whether each treatment keeps one frame, whether titles are labels rather than sentences, and
6
+ whether a region stands empty beside a full one (the floor under a bottom title, a side rail,
7
+ a takeaway column, a title panel, the page above a plate). OF-116 compares the deck with
8
+ another tonality of the same source (qa_deck.py --sibling), OF-117 fails a light figure
9
+ card on a dark ground, OF-118 a bold run-in label with no separator after it, and OF-119 a count
10
+ numeral beside an agenda's title. A pack deck carries its own marks (the subject stamp, `family@` and
11
+ `title@` shape names); a deck without them is judged by OF-101..OF-109 and OF-117 alone. The
12
+ limits live here so spec revisions change data rather than scattered checks.
4
13
  """
5
14
  from __future__ import annotations
6
15
 
7
16
  import colorsys
17
+ import io
8
18
  import re
19
+ from pathlib import Path
9
20
 
21
+ from pptx import Presentation
10
22
  from pptx.enum.shapes import MSO_SHAPE, MSO_SHAPE_TYPE
11
23
  from pptx.enum.text import PP_ALIGN
12
24
  from pptx.util import Inches
@@ -21,6 +33,28 @@ OF_LIMITS = {
21
33
  "frame_outer_radius_min_in": .04, "group_ratio": 2,
22
34
  "empty_medium": .25, "empty_high": .35, "row_tolerance_in": .05,
23
35
  }
36
+ # OF-110..OF-113 read geometry in points, the unit of the design spec's treatment frames.
37
+ OUTPUT_LIMITS = {
38
+ "tol": 2.0, "size_tol": .5, "min_slides": 8, "min_treatments": 3,
39
+ "variety_cap": 5, "max_share": .40, "band_floor": 486.0, "footer_top": 492.0, "band_deck_max": .20,
40
+ "band_caps": ((2, .28), (4, .24), (6, .20), (8, .16), (10, .12)), "anchor_tol": 1.0,
41
+ }
42
+ # OF-115: a region is empty past 40 % of its own height; a bottom title may end at most 12 pt above the floor.
43
+ REGION_LIMITS = {"floor_gap": 12.0, "share": .40}
44
+ # OF-117: on a ground darker than this luminance, a picture more than half near-white is a light card.
45
+ FIGURE_LIMITS = {"ground_max": .25, "near_white": 235, "share": .5, "min_area": .03}
46
+ TREATMENTS = ("top-rule", "top-plain-large", "side-rail", "band", "statement", "overlay", "kicker-numeral", "bottom-anchor")
47
+ TITLE_ZONE = {"top-rule": "top", "top-plain-large": "top", "kicker-numeral": "top", "side-rail": "side",
48
+ "band": "band", "overlay": "overlay", "bottom-anchor": "bottom", "statement": "none"}
49
+ # Widest four-column title and the earliest column-5 start, per canvas width in points.
50
+ RAIL = {960: (288.0, 336.0), 720: (216.0, 252.0)}
51
+ GRID_MARGIN = {960: {"airy": 60.0, "standard": 48.0, "dense": 36.0, "compact": 24.0},
52
+ 720: {"airy": 54.0, "standard": 42.0, "dense": 30.0, "compact": 24.0}}
53
+ PACK_STAMP = re.compile(r"\blit-pptx tonality=(\S+) density=(\d+) grid=(\w+) variance=(\d+)")
54
+ NUMERAL = re.compile(r"\d+(?:[.:/-]\d+)?\.?")
55
+ # Families the engine draws as display pages: covers, sections, statements, quotes, full pictures.
56
+ DISPLAY_FAMILY = re.compile(r"^(?:cover|section)(?:-|$)|^(?:statement|quote|closing-statement|image-full)$")
57
+ QUOTE_GLYPHS = set("“”‘’\"«»「」『』")
24
58
  EMU = Inches(1)
25
59
  NS = {"a": "http://schemas.openxmlformats.org/drawingml/2006/main"}
26
60
  EMOJI = re.compile(r"[\U0001F000-\U0001F0FF\U0001F300-\U0001FAFF\u2600-\u27BF]")
@@ -38,6 +72,26 @@ def _finding(items, rule, severity, slide, detail, **extra):
38
72
  items.append({"rule": rule, "severity": severity, "slide": slide, "detail": detail, **extra})
39
73
 
40
74
 
75
+ def family_of(shapes):
76
+ """The `family@<id>` mark the engine puts on a slide's first shape, or ""."""
77
+ return next((s.name.split("@", 1)[1] for s in shapes if s.name.startswith("family@")), "")
78
+
79
+
80
+ def title_frame(shapes):
81
+ """The frame the engine named `title@<treatment>`, wherever the treatment puts it."""
82
+ return next((s for s in shapes if s.name.startswith("title@") and _text(s)), None)
83
+
84
+
85
+ def bleeds(box, W, H, tol=.03):
86
+ """A fill touching two or more canvas edges is a band, rail or field: page decoration."""
87
+ x, y, w, h = box
88
+ return sum((x <= tol, y <= tol, x + w >= W - tol, y + h >= H - tol)) >= 2
89
+
90
+
91
+ def _wrap_em(line):
92
+ return sum(.90 if ord(ch) >= 0x1100 else .55 for ch in line)
93
+
94
+
41
95
  def _numeric(value):
42
96
  raw = value.strip()
43
97
  if not raw:
@@ -70,14 +124,20 @@ def analyze_craft(prs):
70
124
  """Return HIGH blockers and MEDIUM advisories; no render claims."""
71
125
  findings = []
72
126
  W, H = prs.slide_width / EMU, prs.slide_height / EMU
127
+ stamp = PACK_STAMP.search(prs.core_properties.subject or "")
128
+ margin = GRID_MARGIN[960 if round(W * 72) == 960 else 720].get(stamp.group(3), 48.0) / 72 if stamp else .5
73
129
  for sn, slide in enumerate(prs.slides, 1):
74
- shapes = list(slide.shapes)
75
- title = next((s for s in shapes if _text(s) and _box(s)[1] < H * .22), None)
130
+ # The notice line and a lone quotation-mark ornament are furniture, not content.
131
+ shapes = [s for s in slide.shapes if not s.name.startswith("lit-notice") and _text(s) not in QUOTE_GLYPHS]
132
+ family = family_of(shapes)
133
+ title = title_frame(shapes) or next((s for s in shapes if _text(s) and _box(s)[1] < H * .22), None)
76
134
  display = len([s for s in shapes if _text(s)]) <= 2 and any(
77
135
  (r.font.size.pt if r.font.size else 0) >= OF_LIMITS["body_max_pt"]
78
136
  for s in shapes if getattr(s, "has_text_frame", False)
79
137
  for p in s.text_frame.paragraphs for r in p.runs
80
138
  )
139
+ if family:
140
+ display = bool(DISPLAY_FAMILY.search(family))
81
141
 
82
142
  accents = []
83
143
  for s in shapes:
@@ -95,6 +155,8 @@ def analyze_craft(prs):
95
155
  accents.append(angle)
96
156
  except (AttributeError, TypeError):
97
157
  continue
158
+ findings += light_figures(sn, slide, W * 72, H * 72)
159
+ findings += check_run_ins(sn, slide)
98
160
  count = len(accents)
99
161
  if count >= (4 if display else 3):
100
162
  _finding(findings, "OF-101", "HIGH", sn, f"{count} accent families")
@@ -111,14 +173,19 @@ def analyze_craft(prs):
111
173
  for r in p.runs:
112
174
  if r._r.xpath("./a:rPr/a:gradFill"):
113
175
  _finding(findings, "OF-106", "HIGH", sn, "gradient text")
114
- if s is not title and _text(s):
176
+ # A section's preview of what it opens is set wide on purpose (two lines an entry, at most 70 % of
177
+ # the page and about 70 characters), so the body-text measure does not apply to it.
178
+ if s is not title and _text(s) and not family.startswith("section"):
115
179
  sizes = [r.font.size.pt for p in s.text_frame.paragraphs for r in p.runs if r.font.size]
116
180
  if sizes and OF_LIMITS["body_min_pt"] < max(sizes) < OF_LIMITS["body_max_pt"]:
117
181
  line_count = sum(max(1, len(p.text.splitlines())) for p in s.text_frame.paragraphs)
118
- # Explicit lines are exact; estimated wrapping is a conservative fallback.
182
+ # Explicit lines are exact; wrapping is a conservative estimate per line: 0.55 em a
183
+ # character, 0.90 em a Hangul or other wide glyph (almost twice a Latin letter).
119
184
  width = max(.1, _box(s)[2] - (s.text_frame.margin_left + s.text_frame.margin_right) / EMU)
120
- estimate = max(1, round(width * 72 / (max(sizes) * .55)))
121
- line_count = max(line_count, (len(_text(s)) + estimate - 1) // estimate)
185
+ per_line = width * 72 / max(sizes)
186
+ wrapped = sum(max(1, -(-_wrap_em(line) // per_line)) for p in s.text_frame.paragraphs
187
+ for line in (p.text.splitlines() or [""]))
188
+ line_count = max(line_count, int(wrapped))
122
189
  if line_count >= 2:
123
190
  chars = len(_text(s).replace("\n", ""))
124
191
  cjk = sum('\uac00' <= c <= '\ud7a3' for c in _text(s)) / max(1, chars) >= .5
@@ -170,7 +237,7 @@ def analyze_craft(prs):
170
237
  # Explicit card boundaries make group membership measurable. Until the
171
238
  # template corpus is recalibrated, OF-105 remains advisory.
172
239
  cards = [s for s in shapes if s.shape_type == MSO_SHAPE_TYPE.AUTO_SHAPE and
173
- _box(s)[2] > 1 and _box(s)[3] > .7 and s is not title]
240
+ _box(s)[2] > 1 and _box(s)[3] > .7 and s is not title and not bleeds(_box(s), W, H)]
174
241
  groups = []
175
242
  for card in cards:
176
243
  cx, cy, cw, ch = _box(card)
@@ -198,9 +265,16 @@ def analyze_craft(prs):
198
265
 
199
266
  if not display:
200
267
  top = (_box(title)[1] + _box(title)[3] + .1) if title else .5
201
- bottom = H - .55
202
- content = [_box(s) for s in shapes if s is not title and
203
- (_text(s) or s in cards or getattr(s, "has_table", False) or s.shape_type == MSO_SHAPE_TYPE.PICTURE) and
268
+ left, bottom = 0, H - .55
269
+ if title is not None and title.name == "title@side-rail":
270
+ # Nothing sits under a side rail by design: the body is the column beside it, from the top.
271
+ top, left = _box(title)[1], _box(title)[0] + _box(title)[2]
272
+ elif title is not None and title.name == "title@bottom-anchor":
273
+ # A bottom title closes the page: the body runs from the top margin down to it.
274
+ top, bottom = margin, _box(title)[1]
275
+ content = [_box(s) for s in shapes if s is not title and _box(s)[0] >= left - .05 and
276
+ (_text(s) or s in cards or getattr(s, "has_table", False) or getattr(s, "has_chart", False)
277
+ or s.shape_type == MSO_SHAPE_TYPE.PICTURE) and
204
278
  _box(s)[1] >= top and _box(s)[1] < bottom]
205
279
  fraction = _gap_fraction(content, top, bottom)
206
280
  if fraction > OF_LIMITS["empty_high"]:
@@ -243,4 +317,573 @@ def analyze_craft(prs):
243
317
  elif fraction >= OF_LIMITS["empty_medium"]:
244
318
  _finding(findings, "OF-109", "MEDIUM", sn, f"card-row empty band {fraction:.2f}")
245
319
 
320
+ findings += analyze_output(prs) + check_labels(prs)
246
321
  return {"pass": not any(f["severity"] == "HIGH" for f in findings), "findings": findings}
322
+
323
+
324
+ # ── OF-110..OF-113: the deck as a tonality pack drew it ─────────────────────
325
+
326
+ def _pt(shape):
327
+ try:
328
+ return tuple(v / 12700 for v in (shape.left, shape.top, shape.width, shape.height))
329
+ except (TypeError, ValueError):
330
+ return None
331
+
332
+
333
+ def _drawn(slide, W, H):
334
+ """Each drawn shape in points with its kind and its role (content, card or decoration)."""
335
+ items = []
336
+ for s in slide.shapes:
337
+ box = _pt(s)
338
+ if box is None or box[2] + box[3] <= 0 or s.name.startswith("lit-notice"):
339
+ continue
340
+ text = _text(s)
341
+ if s.shape_type == MSO_SHAPE_TYPE.PICTURE:
342
+ kind = "picture"
343
+ elif getattr(s, "has_table", False) and s.has_table:
344
+ kind = "table"
345
+ box = (*box[:3], max(box[3], sum(row.height for row in s.table.rows) / 12700))
346
+ elif getattr(s, "has_chart", False) and s.has_chart:
347
+ kind = "chart"
348
+ else:
349
+ kind = "text" if text else "shape"
350
+ try:
351
+ filled = kind == "shape" and s.fill.type == 1
352
+ except (AttributeError, TypeError):
353
+ filled = False
354
+ sizes = [r.font.size.pt for p in s.text_frame.paragraphs for r in p.runs
355
+ if r.text.strip() and r.font.size] if getattr(s, "has_text_frame", False) else []
356
+ items.append({"name": s.name, "kind": kind, "x": box[0], "y": box[1], "w": box[2], "h": box[3],
357
+ "text": text, "sizes": sizes, "filled": filled})
358
+ for item in items:
359
+ if item["kind"] != "shape":
360
+ item["role"] = "content"
361
+ continue
362
+ holds = any(o["kind"] != "shape" and _inside(o, item) for o in items if o is not item)
363
+ edge = bleeds(tuple(v / 72 for v in (item["x"], item["y"], item["w"], item["h"])), W / 72, H / 72)
364
+ card = (item["filled"] and holds and not edge and item["w"] >= 100 and item["h"] >= 40
365
+ and item["w"] * item["h"] < .5 * W * H)
366
+ item["role"] = "card" if card else "decoration"
367
+ return items
368
+
369
+
370
+ def _inside(item, box, tol=1.0):
371
+ cx, cy = item["x"] + item["w"] / 2, item["y"] + item["h"] / 2
372
+ return box["x"] - tol <= cx <= box["x"] + box["w"] + tol and box["y"] - tol <= cy <= box["y"] + box["h"] + tol
373
+
374
+
375
+ def _in_footer(item):
376
+ return item["y"] >= OUTPUT_LIMITS["footer_top"]
377
+
378
+
379
+ def treatment_of(title, items, W, H):
380
+ """The treatment a title frame shows, tested in the spec's order; the first match wins."""
381
+ tol, slack = OUTPUT_LIMITS["tol"], OUTPUT_LIMITS["size_tol"]
382
+ size = max(title["sizes"] or [0])
383
+ bottom = title["y"] + title["h"]
384
+ others = [o for o in items if o is not title]
385
+ body = [o for o in others if not _in_footer(o) and o["role"] != "decoration"]
386
+
387
+ def behind(o):
388
+ return (o["x"] - tol <= title["x"] and title["x"] + title["w"] <= o["x"] + o["w"] + tol
389
+ and o["y"] - tol <= title["y"] and bottom <= o["y"] + o["h"] + tol)
390
+
391
+ if (any(o["kind"] == "picture" and o["w"] * o["h"] >= .8 * W * H for o in others) and title["y"] >= 300 - tol
392
+ and any(o["kind"] == "shape" and o["filled"] and behind(o) for o in others)):
393
+ return "overlay"
394
+ if any(o["kind"] == "shape" and o["filled"] and o["y"] <= 2 + tol and 96 - tol <= o["h"] <= 120 + tol
395
+ and o["w"] >= .9 * W and _inside(title, o, tol) for o in others):
396
+ return "band"
397
+ if (size >= 36 - slack and 220 - tol <= title["y"] + title["h"] / 2 <= 380 + tol
398
+ and not any(o["kind"] in ("table", "chart", "picture") or o["role"] == "card" for o in body)
399
+ and sum(o["kind"] == "text" for o in body) <= 1):
400
+ return "statement"
401
+ if title["y"] >= 360 - tol and all(o["y"] <= title["y"] + tol for o in body if o["kind"] == "text"):
402
+ return "bottom-anchor"
403
+ rail_w, column_5 = RAIL.get(round(W), RAIL[960])
404
+ beside = [o for o in body if o["x"] + o["w"] / 2 > title["x"] + title["w"]]
405
+ # Criteria labels, takeaways and the source may stand in the rail under the title; only a block that
406
+ # runs from the rail into the body makes the title something else.
407
+ if (title["w"] <= rail_w + tol and beside and min(o["x"] for o in beside) >= column_5 - tol
408
+ and not any(o["x"] < column_5 - tol and o["y"] > bottom and o["x"] + o["w"] > column_5 + tol for o in body)):
409
+ return "side-rail"
410
+ for o in others:
411
+ if (o["kind"] == "text" and o["sizes"] and NUMERAL.fullmatch(o["text"]) and max(o["sizes"]) >= 44 - slack
412
+ and o["x"] + o["w"] <= title["x"] + tol and o["y"] >= 30 - tol and o["y"] + o["h"] <= 114 + tol):
413
+ return "kicker-numeral"
414
+ if title["y"] <= 48 + tol:
415
+ # A rule is a line under the title, never a list-marker dot.
416
+ rule = any(o["kind"] == "shape" and o["h"] <= 8 and o["w"] >= max(16, 4 * o["h"])
417
+ and bottom - tol <= o["y"] <= bottom + 24 and o["x"] < title["x"] + title["w"]
418
+ and o["x"] + o["w"] > title["x"] for o in others)
419
+ if size >= 36 - slack and not rule:
420
+ return "top-plain-large"
421
+ if size <= 32 + slack and rule:
422
+ return "top-rule"
423
+ return "unclassified"
424
+
425
+
426
+ def _is_figure(item):
427
+ """Display-size text that is mostly digits reads as a number, not text."""
428
+ compact = re.sub(r"\s+", "", item["text"])
429
+ digits = len(re.findall(r"\d", compact))
430
+ return (item["kind"] == "text" and bool(item["sizes"]) and max(item["sizes"]) >= 44 - OUTPUT_LIMITS["size_tol"]
431
+ and digits / max(1, len(compact)) >= .5)
432
+
433
+
434
+ def signature_of(title, treatment, items, W, margin):
435
+ """(title zone, body partition, dominant content) of one content slide.
436
+
437
+ Body boxes share a column when they overlap by half the narrower one; a box wider than 70 %
438
+ of the body (a takeaway under two columns) never joins columns.
439
+ """
440
+ zone = TITLE_ZONE.get(treatment, "none")
441
+ if treatment == "statement":
442
+ return (zone, "one", "text")
443
+ column_5 = RAIL.get(round(W), RAIL[960])[1]
444
+ body = [o for o in items if o is not title and not _in_footer(o) and o["role"] != "decoration"
445
+ # what stands in a side title's rail belongs to the title zone, not to the body's columns
446
+ and not (treatment == "side-rail" and o["x"] + o["w"] <= column_5 + OUTPUT_LIMITS["tol"])
447
+ and not (o["kind"] == "shape" and title is not None and _inside(title, o, 0))
448
+ and not (treatment == "kicker-numeral" and o["kind"] == "text" and NUMERAL.fullmatch(o["text"])
449
+ and o["y"] + o["h"] <= 116)]
450
+ cards = [o for o in body if o["role"] == "card"]
451
+ blocks = [o for o in body if not any(c is not o and _inside(o, c) for c in cards)]
452
+ if any(o["kind"] == "picture" and o["w"] * o["h"] >= .8 * W * 540 for o in items):
453
+ partition = "full-bleed"
454
+ elif not blocks:
455
+ partition = "one"
456
+ else:
457
+ narrow = [o for o in blocks if o["w"] < .7 * (W - 2 * margin)] or blocks
458
+ columns = []
459
+ for o in sorted(narrow, key=lambda o: o["x"]):
460
+ hits = [c for c in columns if min(c["r"], o["x"] + o["w"]) - max(c["l"], o["x"]) >= .5 * min(c["r"] - c["l"], o["w"])]
461
+ if hits:
462
+ keep = hits[0]
463
+ for extra in hits[1:]:
464
+ keep["l"], keep["r"] = min(keep["l"], extra["l"]), max(keep["r"], extra["r"])
465
+ keep["items"] += extra["items"]
466
+ columns.remove(extra)
467
+ keep["l"], keep["r"] = min(keep["l"], o["x"]), max(keep["r"], o["x"] + o["w"])
468
+ keep["items"].append(o)
469
+ else:
470
+ columns.append({"l": o["x"], "r": o["x"] + o["w"], "items": [o]})
471
+ column = {id(i): n for n, c in enumerate(columns) for i in c["items"]}
472
+ rows = []
473
+ for o in sorted(narrow, key=lambda o: o["y"]):
474
+ if rows and o["y"] < rows[-1]["bottom"] - 2:
475
+ rows[-1]["bottom"] = max(rows[-1]["bottom"], o["y"] + o["h"])
476
+ rows[-1]["items"].append(o)
477
+ else:
478
+ rows.append({"bottom": o["y"] + o["h"], "items": [o]})
479
+ multi = sum(1 for r in rows if len({column[id(i)] for i in r["items"]}) >= 2)
480
+ k = len(columns)
481
+ if k >= 4 or (k >= 2 and multi >= 2):
482
+ partition = "grid"
483
+ elif k == 3:
484
+ partition = "three"
485
+ elif k == 2:
486
+ a, b = (c["r"] - c["l"] for c in columns)
487
+ partition = "two-even" if min(a, b) / max(a, b) >= .85 else "two-asym"
488
+ else:
489
+ partition = "one"
490
+ area = {}
491
+ for o in blocks:
492
+ key = {"picture": "image", "table": "table", "chart": "chart"}.get(o["kind"])
493
+ if o["kind"] == "text":
494
+ key = "number" if _is_figure(o) else "text"
495
+ if key:
496
+ area[key] = area.get(key, 0) + o["w"] * o["h"]
497
+ for c in cards:
498
+ key = "number" if any(_is_figure(o) for o in body if o is not c and _inside(o, c)) else "text"
499
+ area[key] = area.get(key, 0) + c["w"] * c["h"]
500
+ return (zone, partition, max(area, key=area.get) if area else "text")
501
+
502
+
503
+ def empty_under(title, items, top_margin=36.0):
504
+ """Share of the body left empty under its lowest block, from the title (or the top margin when
505
+ the title sits low) to the body floor; decoration, footer and notice excluded."""
506
+ floor = OUTPUT_LIMITS["band_floor"]
507
+ top = title["y"] + title["h"] if title is not None and title["y"] + title["h"] < floor * .6 else top_margin
508
+ if floor - top < 10:
509
+ return None
510
+ ink = [o for o in items if o["role"] != "decoration" and not _in_footer(o) and o["y"] < floor and o["y"] + o["h"] > top]
511
+ lowest = max((min(floor, o["y"] + o["h"]) for o in ink), default=top)
512
+ return max(0.0, (floor - lowest) / (floor - top))
513
+
514
+
515
+ def _role(family):
516
+ return next((k for k in ("cover", "section", "closing") if family == k or family.startswith(k + "-")), "content")
517
+
518
+
519
+ def read_slides(prs):
520
+ """Each slide's drawn items, family, role, written and drawn treatment, and a content slide's signature."""
521
+ W, H = prs.slide_width / 12700, prs.slide_height / 12700
522
+ stamp = PACK_STAMP.search(prs.core_properties.subject or "")
523
+ margin = GRID_MARGIN[960 if round(W) == 960 else 720].get(stamp.group(3) if stamp else "standard", 48.0)
524
+ slides = []
525
+ for n, slide in enumerate(prs.slides, 1):
526
+ items = _drawn(slide, W, H)
527
+ family = family_of(list(slide.shapes))
528
+ title = next((o for o in items if o["name"].startswith("title@")), None)
529
+ s = {"n": n, "items": items, "family": family, "role": _role(family), "title": title,
530
+ "named": title["name"].split("@", 1)[1] if title else None}
531
+ s["drawn"] = treatment_of(title, items, W, H) if title and title["sizes"] else None
532
+ if s["role"] == "content":
533
+ s["signature"] = signature_of(title, s["drawn"], items, W, margin)
534
+ slides.append(s)
535
+ return W, H, stamp, slides
536
+
537
+
538
+ def analyze_output(prs):
539
+ """OF-110..OF-113 and OF-115 over a deck the engine stamped; [] for any other deck."""
540
+ found = []
541
+ W, H, stamp, slides = read_slides(prs)
542
+ density, variance = (int(stamp.group(2)), int(stamp.group(4))) if stamp else (5, 5)
543
+ if not any(s["named"] for s in slides):
544
+ return found
545
+ # A legacy template has no fill policies or treatments of its own: its variety is advisory.
546
+ weight = "MEDIUM" if any(s["named"] == "legacy" for s in slides) else "HIGH"
547
+ for s in slides:
548
+ if s["named"] in TREATMENTS and s["drawn"] not in (None, s["named"]):
549
+ _finding(found, "OF-110", "HIGH", s["n"], f"title drawn as {s['drawn']}, named {s['named']}",
550
+ hint="Draw the treatment with its own frame and companions; the name must match the page.")
551
+ titled = [s for s in slides if s["role"] not in ("cover", "section") and s["drawn"]]
552
+ used = sorted({s["drawn"] for s in titled} - {"unclassified"})
553
+ loose = [s["n"] for s in titled if s["drawn"] == "unclassified"]
554
+ allowed = 2 if variance <= 3 else 3 if variance == 4 else 4 if variance <= 6 else 5
555
+ if len(slides) >= OUTPUT_LIMITS["min_slides"]:
556
+ if variance <= 3 and len(used) < OUTPUT_LIMITS["min_treatments"]:
557
+ _finding(found, "OF-110", "MEDIUM", None, f"{len(used)} title treatment(s) at variance {variance}, lowered on request",
558
+ hint="Variance under 4 is the user's call; say so in the reply.")
559
+ elif len(used) < OUTPUT_LIMITS["min_treatments"]:
560
+ _finding(found, "OF-110", weight, None, f"{len(used)} title treatment(s) ({', '.join(used) or 'none'}) on {len(slides)} slides",
561
+ hint="Give slide roles the pack's treatments: data beside a rail or over a bottom title, steps under a numeral.")
562
+ elif stamp and len(used) > allowed:
563
+ _finding(found, "OF-110", weight, None, f"{len(used)} title treatments where variance {variance} allows {allowed}",
564
+ hint="Drop a treatment or raise variance by at most 2.")
565
+ if loose:
566
+ _finding(found, "OF-110", weight, loose[0], f"no treatment recognised on slide(s) {', '.join(map(str, loose))}",
567
+ hint="Put the title on one of the eight treatment frames.")
568
+ content = [s for s in slides if s["role"] == "content"]
569
+ if len(content) >= 3:
570
+ need = min(OUTPUT_LIMITS["variety_cap"], -(-len(content) * 3 // 5))
571
+ problems = []
572
+ for label, key in (("signature", lambda s: s["signature"]), ("layout", lambda s: s["signature"][:2])):
573
+ counts = {}
574
+ for s in content:
575
+ counts[key(s)] = counts.get(key(s), 0) + 1
576
+ top, top_n = max(counts.items(), key=lambda kv: kv[1])
577
+ if len(counts) < need:
578
+ problems.append(f"{label}: {len(counts)} distinct of {need} needed")
579
+ if top_n / len(content) > OUTPUT_LIMITS["max_share"]:
580
+ problems.append(f"{label}: {'/'.join(top)} on {top_n} of {len(content)} content slides")
581
+ if problems:
582
+ _finding(found, "OF-111", weight, None, "; ".join(problems),
583
+ hint="Change the family or treatment on the repeated slides; let each slide's job choose its shape.")
584
+ cap = next(c for upto, c in OUTPUT_LIMITS["band_caps"] if density <= upto)
585
+ bands = []
586
+ for s in slides:
587
+ if s["role"] in ("cover", "section") or s["family"] in ("statement", "quote", "closing-statement") or s["drawn"] == "statement":
588
+ continue
589
+ band = empty_under(s["title"], s["items"])
590
+ if band is None:
591
+ continue
592
+ bands.append(band)
593
+ if band > cap:
594
+ _finding(found, "OF-112", "MEDIUM", s["n"], f"{band:.0%} of the body empty under the last block (cap {cap:.0%} at density {density})",
595
+ hint="Use the pack's fill order: larger type, a grown visual, wider gaps, or a family that fits.")
596
+ if bands:
597
+ bands.sort()
598
+ mid = len(bands) // 2
599
+ median = bands[mid] if len(bands) % 2 else (bands[mid - 1] + bands[mid]) / 2
600
+ if median > OUTPUT_LIMITS["band_deck_max"]:
601
+ _finding(found, "OF-112", weight, None, f"median empty band {median:.2f} over {len(bands)} slides",
602
+ hint="Give content slides content that reaches the floor: a takeaway under a table, a next step under an ask.")
603
+ groups = {}
604
+ for s in titled:
605
+ if s["drawn"] in TREATMENTS and s["named"] in TREATMENTS:
606
+ groups.setdefault(s["drawn"], []).append(s)
607
+ # A statement is centred, so only its x and width repeat. A bottom title stands on the floor: its bottom
608
+ # edge repeats and its top follows its line count.
609
+ edge = lambda t, k: t["y"] + t["h"] if k == "bottom" else t[k] # noqa: E731
610
+ for treatment, group in groups.items():
611
+ keys = ("x", "w") if treatment == "statement" else ("x", "w", "bottom") if treatment == "bottom-anchor" else ("x", "y", "w")
612
+ modes = {}
613
+ for k in keys:
614
+ values = [round(edge(s["title"], k)) for s in group]
615
+ modes[k] = max(set(values), key=values.count)
616
+ for s in group:
617
+ off = [f"{k} {edge(s['title'], k):.0f} vs {modes[k]}" for k in keys if abs(edge(s["title"], k) - modes[k]) > OUTPUT_LIMITS["anchor_tol"]]
618
+ if off:
619
+ _finding(found, "OF-113", "HIGH", s["n"], f"{treatment} title off its frame: {', '.join(off)}",
620
+ hint="Keep one frame per treatment; fix the source rather than nudging a title.")
621
+ return found + empty_regions(slides, W, H) + agenda_numerals(slides)
622
+
623
+
624
+ # ── OF-115: no region stands empty beside a full one ────────────────────────
625
+ # OF-112 reads the body as one page; a region can still be empty beside a full one. Each region is
626
+ # measured against its own height (40 %), and the floor under a bottom title as a distance (12 pt).
627
+
628
+ def _title_lines(title):
629
+ """Lines the title's text takes: explicit breaks, each wrapped at its frame width (Hangul 0.90 em)."""
630
+ size = max(title["sizes"] or [1.0])
631
+ inner = max(1.0, title["w"] - 14.4)
632
+ return sum(max(1, -(-_wrap_em(line) * size // inner)) for line in (title["text"].splitlines() or [""]))
633
+
634
+
635
+ def _open_stretch(top, bottom, spans):
636
+ """The tallest stretch of [top, bottom] that no (y0, y1) span covers."""
637
+ gap, cursor = 0.0, top
638
+ for y0, y1 in sorted(spans):
639
+ if y1 <= cursor:
640
+ continue
641
+ gap = max(gap, min(y0, bottom) - cursor)
642
+ cursor = max(cursor, y1)
643
+ return max(gap, bottom - cursor)
644
+
645
+
646
+ def _short_column(n, content, title, treatment, body_floor, column_5, fields, family=None):
647
+ """OF-115 for a column of a two-column body that stops short of its neighbour: the largest empty band inside
648
+ it, from the body's top down to where the neighbour ends, is over 40 % of the body. A source or note strip
649
+ that closes the column does not hide the band above it. Beside the figures of a kpi-row or big-number slide
650
+ the column is measured to the body floor (spec-v2 Amendments 9)."""
651
+ tol = OUTPUT_LIMITS["tol"]
652
+ # The body starts under a top title; beside a side title (in its rail) or over a bottom title, at the top.
653
+ top_of_title = title["y"] + title["h"] if treatment not in ("bottom-anchor", "side-rail") else 0.0
654
+ body = [o for o in content if top_of_title - tol <= o["y"] < body_floor and o["w"] > 0 and o["h"] > 0
655
+ and not (treatment == "side-rail" and o["x"] + o["w"] <= column_5 + tol) and not any(_inside(o, f) for f in fields)]
656
+ if len(body) < 2:
657
+ return None
658
+ left_edge, right_edge = min(o["x"] for o in body), max(o["x"] + o["w"] for o in body)
659
+ for cut in sorted({o["x"] + o["w"] for o in body}):
660
+ a = [o for o in body if o["x"] + o["w"] <= cut + tol]
661
+ b = [o for o in body if o["x"] >= cut - tol]
662
+ # A block across most of the body (a note under both columns) belongs to neither column; a narrower
663
+ # block across the cut means there is no column line here.
664
+ across = [o for o in body if o not in a and o not in b]
665
+ if not a or not b or any(o["w"] < .7 * (right_edge - left_edge) for o in across):
666
+ continue
667
+ top = min(o["y"] for o in a + b)
668
+ for column, other in ((a, b), (b, a)):
669
+ # Takeaways beside a chart that close with the chart's values: the table counts as a block of the
670
+ # column at its drawn extent (the reader already takes the taller of frame and rows).
671
+ values = (any(o["kind"] == "chart" for o in other) and any(o["kind"] == "text" for o in column)
672
+ and not any(o["kind"] in ("chart", "picture") for o in column))
673
+ # A text column, or a picture drawn smaller than its column, beside a column that runs on.
674
+ if not any(o["kind"] in ("text", "picture") for o in column) or (
675
+ any(o["kind"] in ("chart", "table") for o in column) and not values):
676
+ continue
677
+ # Row heads (a matrix's or a comparison's short labels, each level with its row) are no column to fill.
678
+ if all(o["kind"] == "text" and o["h"] <= 56 and len(re.sub(r"\s+", "", o["text"])) <= 16 for o in column):
679
+ continue
680
+ # Read whatever the neighbour's length: one that stops short still marks how far this column should run.
681
+ reach = min(body_floor, max(o["y"] + o["h"] for o in other))
682
+ # A takeaway column beside the figures of a kpi-row or big-number slide runs to the body floor: the rows stop
683
+ # where their spacing ends. The figures' own labels stand exactly level with figures below the first row.
684
+ size = lambda side: max([max(o["sizes"]) for o in side if o["kind"] == "text" and o["sizes"]] or [0.0]) # noqa: E731
685
+ figures = [o for o in other if o["kind"] == "text" and o["sizes"] and max(o["sizes"]) > size(column) + 4]
686
+ labels = any(abs(o["y"] - f["y"]) <= .5 and f["y"] > top + tol for o in column for f in figures)
687
+ if family in ("kpi-row", "big-number") and figures and not labels:
688
+ reach = body_floor
689
+ share = _open_stretch(top, reach, [(o["y"], o["y"] + o["h"]) for o in column]) / max(1.0, body_floor - top)
690
+ if share > REGION_LIMITS["share"]:
691
+ kind = "picture" if any(o["kind"] == "picture" for o in column) else "text"
692
+ items = []
693
+ _finding(items, "OF-115", "HIGH", n, f"the {kind} column beside a longer one leaves {share:.0%} of the body empty inside it",
694
+ hint="Fill the column by layout: lead size, the source and values in the column, a narrower column with a wider visual, or the points under the visual.")
695
+ return items[0]
696
+ return None
697
+
698
+
699
+ def empty_regions(slides, W, H):
700
+ found = []
701
+ floor, tol, share_max = OUTPUT_LIMITS["band_floor"], OUTPUT_LIMITS["tol"], REGION_LIMITS["share"]
702
+ column_5 = RAIL.get(round(W), RAIL[960])[1]
703
+ for s in slides:
704
+ title, treatment = s["title"], s["drawn"]
705
+ if title is None:
706
+ continue
707
+ full_bleed = lambda o: o["kind"] == "picture" and o["w"] * o["h"] >= .8 * W * H # noqa: E731
708
+ content = [o for o in s["items"] if o is not title and o["role"] != "decoration" and not _in_footer(o) and not full_bleed(o)]
709
+ if s["role"] in ("content", "closing") and title["sizes"]:
710
+ if treatment == "bottom-anchor":
711
+ gap = floor - (title["y"] + _title_lines(title) * max(title["sizes"]) * 1.15)
712
+ if gap > REGION_LIMITS["floor_gap"]:
713
+ _finding(found, "OF-115", "HIGH", s["n"], f"the bottom title ends {gap:.0f} pt above the body floor",
714
+ hint="Stand the title's last line on the floor and give the visual above it the room.")
715
+ if treatment == "side-rail" and s["family"] not in ("quote", "statement"):
716
+ top = title["y"] + title["h"] # the frame keeps a spare line for a title that wraps once more
717
+ rail = [(o["y"], o["y"] + o["h"]) for o in content if o["x"] + o["w"] <= column_5 + tol and o["y"] + o["h"] > top]
718
+ share = _open_stretch(top, floor, rail) / max(1.0, floor - top)
719
+ if share > share_max:
720
+ _finding(found, "OF-115", "HIGH", s["n"], f"{share:.0%} of the side rail under the title is empty",
721
+ hint="Stand the slide's criteria labels, takeaways or source in the rail, or take a top or bottom title.")
722
+ # A takeaway column beside a chart, table or picture that runs on below the column's last block.
723
+ body_floor = title["y"] - tol if treatment == "bottom-anchor" else floor
724
+ fields = [o for o in s["items"] if o["kind"] == "shape" and o["filled"] and o["w"] * o["h"] >= .1 * W * H]
725
+ short = _short_column(s["n"], content, title, treatment, body_floor, column_5, fields, s["family"])
726
+ if short:
727
+ found.append(short)
728
+ for v in ([] if short else (o for o in content if o["kind"] in ("chart", "table", "picture"))):
729
+ # Text on a colour field (a closing's ask) stands on its own ground, not in a column.
730
+ beside = [o for o in content if o["kind"] == "text" and o["y"] < v["y"] + v["h"] and o["y"] + o["h"] > v["y"]
731
+ and (o["x"] >= v["x"] + v["w"] - tol or o["x"] + o["w"] <= v["x"] + tol)
732
+ and not any(_inside(o, f) for f in fields)]
733
+ if not beside:
734
+ continue
735
+ left, right = min(o["x"] for o in beside), max(o["x"] + o["w"] for o in beside)
736
+ top = min([v["y"]] + [o["y"] for o in beside])
737
+ column = max(o["y"] + o["h"] for o in content if left - tol <= o["x"] + o["w"] / 2 <= right + tol)
738
+ visual = min(body_floor, max(o["y"] + o["h"] for o in content if v["x"] - tol <= o["x"] + o["w"] / 2 <= v["x"] + v["w"] + tol))
739
+ share = (visual - column) / max(1.0, body_floor - top)
740
+ if share > share_max:
741
+ _finding(found, "OF-115", "HIGH", s["n"], f"the column beside the {v['kind']} leaves {share:.0%} of the body empty under its last block",
742
+ hint="Close the column with the source and note lines, the chart's values or the takeaways; never stretch the visual alone.")
743
+ break
744
+ if s["role"] in ("cover", "section") or treatment in ("statement", "overlay"):
745
+ # A title panel over a picture, and a plate under a statement or quote; a type-led cover's plate
746
+ # is a device of the cover, not a region its text must fill.
747
+ pictured = any(full_bleed(o) for o in s["items"])
748
+ for p in (o for o in s["items"] if o["kind"] == "shape" and o["filled"] and _inside(title, o) and o["w"] * o["h"] < .9 * W * H):
749
+ inside = [o for o in content + [title] if o is not p and _inside(o, p)]
750
+ if p["y"] > tol and pictured:
751
+ bottom = min(p["y"] + p["h"], floor)
752
+ share = _open_stretch(p["y"], bottom, [(o["y"], o["y"] + o["h"]) for o in inside]) / max(1.0, bottom - p["y"])
753
+ if share > share_max:
754
+ _finding(found, "OF-115", "HIGH", s["n"], f"{share:.0%} of the panel that carries the title is empty",
755
+ hint="Make the panel as tall as the title and its lines, standing on the page foot.")
756
+ if p["y"] > tol and treatment == "statement" and p["w"] >= .9 * W and not any(o["y"] + o["h"] <= p["y"] + tol for o in content):
757
+ _finding(found, "OF-115", "HIGH", s["n"], "a plate under part of the page leaves the open page above it empty",
758
+ hint="Set the sentence on the whole-page field or on the open page; a plate needs content above it.")
759
+ return found
760
+
761
+
762
+ # ── OF-116: another tonality of the same source draws another skeleton ─────
763
+ # The skeleton is each content slide's title zone and column partition, as OF-111 reads them. Two
764
+ # tonalities of one source with the same skeleton differ in colour only.
765
+
766
+ def skeleton(prs):
767
+ return [s["signature"][:2] for s in read_slides(prs)[3] if s["role"] == "content"]
768
+
769
+
770
+ def compare_skeletons(path, sibling):
771
+ """OF-116 for a deck and the same source compiled under another tonality (qa_deck.py --sibling)."""
772
+ mine, other = skeleton(Presentation(str(path))), skeleton(Presentation(str(sibling)))
773
+ n = min(len(mine), len(other))
774
+ differ = sum(1 for a, b in zip(mine, other) if a != b)
775
+ # Two slides once the deck has four content slides: one differing slide still reads as one deck in two colours.
776
+ need = 2 if n >= 4 else 1
777
+ found = []
778
+ if n and differ < need:
779
+ _finding(found, "OF-116", "HIGH", None, f"{differ} of {n} content slides differ in title zone or partition from {Path(sibling).name} (needs {need})",
780
+ hint="Give the tonality its own structure: its role defaults, another title zone or partition on the slides both decks share.")
781
+ return found
782
+
783
+
784
+ # ── OF-117: no light figure card on a dark ground ───────────────────────────
785
+ # A chart or diagram exported on white reads as a white card with small grey labels on a dark ground.
786
+ # A figure is a picture of mostly near-white pixels; a photograph seldom is.
787
+
788
+ def light_figures(sn, slide, W, H):
789
+ found = []
790
+ try:
791
+ rgb = slide.background.fill.fore_color.rgb if slide.background.fill.type == 1 else None
792
+ except (AttributeError, TypeError, ValueError):
793
+ rgb = None
794
+ if rgb is None:
795
+ return found
796
+ r, g, b = (v / 255 for v in rgb)
797
+ if .2126 * r + .7152 * g + .0722 * b > FIGURE_LIMITS["ground_max"]:
798
+ return found
799
+ from PIL import Image # the office runtime's imaging library, needed only for a dark slide with a picture
800
+ for s in slide.shapes:
801
+ box = _pt(s) if s.shape_type == MSO_SHAPE_TYPE.PICTURE else None
802
+ if not box or not FIGURE_LIMITS["min_area"] * W * H <= box[2] * box[3] < .8 * W * H:
803
+ continue
804
+ with Image.open(io.BytesIO(s.image.blob)) as im:
805
+ raw = im.convert("RGB").resize((64, 64)).tobytes()
806
+ share = sum(1 for i in range(0, len(raw), 3) if min(raw[i:i + 3]) >= FIGURE_LIMITS["near_white"]) / (len(raw) / 3)
807
+ if share > FIGURE_LIMITS["share"]:
808
+ _finding(found, "OF-117", "HIGH", sn, f"a light figure ({share:.0%} near-white) on a dark ground",
809
+ hint="Put the figure's dark variant beside it (name.dark.png) or draw it as a native chart.")
810
+ return found
811
+
812
+
813
+ # ── OF-118: a run-in label keeps its separator ─────────────────────────────
814
+ # A point that opens with a bold label and runs on in regular weight reads as one sentence when nothing parts
815
+ # the two ("요약 앱에서 …"): the label takes a colon unless it ends in a separator of its own.
816
+ RUN_IN_SEPARATOR = re.compile(r"[::.)\]?!–—\-]$")
817
+
818
+
819
+ def check_run_ins(sn, slide):
820
+ found = []
821
+ for shape in slide.shapes:
822
+ if not getattr(shape, "has_text_frame", False) or shape.name.startswith(("title@", "lit-notice")):
823
+ continue
824
+ for paragraph in shape.text_frame.paragraphs:
825
+ runs = [r for r in paragraph.runs if r.text]
826
+ if len(runs) < 2 or not runs[0].font.bold or runs[1].font.bold:
827
+ continue
828
+ label, rest = runs[0].text.strip(), runs[1].text
829
+ if not label or not re.search(r"\w", rest) or RUN_IN_SEPARATOR.search(label) or rest.lstrip()[:1] in "::":
830
+ continue
831
+ _finding(found, "OF-118", "HIGH", sn, f"bold run-in label without a separator: {(runs[0].text + rest)[:40]}",
832
+ hint="Write the label with its colon (**요약:** …), or let the engine set it; never run a bold label into the sentence.")
833
+ return found
834
+
835
+
836
+ # ── OF-119: no count numeral beside an agenda title ────────────────────────
837
+ # An agenda numbers its own rows; a numeral beside its title reads as a stray section number.
838
+
839
+ def agenda_numerals(slides):
840
+ found = []
841
+ for s in slides:
842
+ if s["family"] == "agenda" and "kicker-numeral" in (s["drawn"], s["named"]):
843
+ _finding(found, "OF-119", "HIGH", s["n"], "a numeral beside the agenda title repeats the count of its numbered rows",
844
+ hint="Give the agenda a title without a numeral; its rows carry the numbers.")
845
+ return found
846
+
847
+
848
+ # ── OF-114: titles name a topic ─────────────────────────────────────────────
849
+ # Korean is read on its last word: a sentence ending or a nominalised claim makes a sentence.
850
+ # English is read for a closing period or a finite verb. A trailing parenthesis is set aside
851
+ # first, and a question or a quotation is never a claim.
852
+
853
+ KO_CLAIM = re.compile(r"(?:니다|[어아해세에예네지군래게]요|죠|[었았였했겠됐](?:다|음)|[가-힣]다|[가-힣](?:함|됨)|(?:있|없)음)$")
854
+ KO_NOUNS = {"바다", "판다", "소다", "람다", "캐나다", "어젠다", "아젠다", "포함", "보다", "함", "다"}
855
+ EN_FINITE = re.compile(r"\b(?:is|are|was|were|has|have|had|will|would|can|could|should|must|does|did|won't|isn't|aren't|wasn't|doesn't|didn't)\b", re.I)
856
+ EN_CLAIM_VERBS = set("""grew grows rose rises fell falls doubled doubles tripled triples halved halves increased increases
857
+ decreased decreases declined declines improved improves dropped drops climbed climbs beats outperforms outperformed leads
858
+ drives drove shows showed needs makes reached reaches exceeded exceeds missed misses stays stayed remains remained comes
859
+ came takes took works worked pays paid saves saved explains explained matters wins won lost loses cuts lifts lifted
860
+ slowed slows fails failed""".split())
861
+
862
+
863
+ def declarative_title(text):
864
+ """True when a title or subtitle states a claim as a sentence instead of naming a topic."""
865
+ t = re.sub(r"\s+", " ", str(text or "")).strip()
866
+ t = re.sub(r"\s*\([^()]*\)$", "", t).strip().rstrip("\"'”’")
867
+ if not t or t.endswith("?") or t[0] in "“\"「『‘'":
868
+ return False
869
+ if re.search(r"[가-힣]", t):
870
+ last = re.sub(r"[.!…]+$", "", t.split(" ")[-1])
871
+ return last not in KO_NOUNS and bool(KO_CLAIM.search(last))
872
+ if t.endswith((".", "!")):
873
+ return True
874
+ return bool(EN_FINITE.search(t)) or any(w.lower() in EN_CLAIM_VERBS for w in re.findall(r"[A-Za-z']+", t)[1:])
875
+
876
+
877
+ def check_labels(prs):
878
+ """OF-114 over every engine-drawn title and the cover subtitle."""
879
+ found = []
880
+ named = [(n, s) for n, slide in enumerate(prs.slides, 1) for s in slide.shapes
881
+ if s.name.startswith(("title@", "subtitle@")) and getattr(s, "has_text_frame", False)]
882
+ legacy = any(s.name == "title@legacy" for _, s in named)
883
+ for n, s in named:
884
+ text = re.sub(r"\s+", " ", s.text_frame.text).strip()
885
+ if declarative_title(text):
886
+ what = "subtitle" if s.name.startswith("subtitle@") else "title"
887
+ _finding(found, "OF-114", "MEDIUM" if legacy else "HIGH", n, f"the {what} is a sentence: {text[:60]}",
888
+ hint="Name the topic as a label (분기별 매출 추이; Conversion by feed rate) and open the body with the claim.")
889
+ return found