@iasiv5/dsh-skills 1.0.6 → 1.2.0

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 (192) hide show
  1. package/NOTICE.md +7 -10
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/skills/answer-me-with-html/SKILL.md +3 -1
  5. package/skills/answer-me-with-html/references/settings.md +1 -1
  6. package/skills/answer-me-with-html/references/video.md +1 -0
  7. package/skills/answer-me-with-html/scripts/am.mjs +2567 -2064
  8. package/skills/docx/LICENSE.txt +202 -0
  9. package/skills/docx/SKILL.md +91 -0
  10. package/skills/docx/scripts/__init__.py +1 -0
  11. package/skills/docx/scripts/accept_changes.py +135 -0
  12. package/skills/docx/scripts/comment.py +368 -0
  13. package/skills/docx/scripts/merge_runs.py +310 -0
  14. package/skills/docx/scripts/office/helpers/__init__.py +111 -0
  15. package/skills/docx/scripts/office/helpers/pptx_chart.py +170 -0
  16. package/skills/docx/scripts/office/helpers/pptx_slide.py +60 -0
  17. package/skills/docx/scripts/office/helpers/pptx_theme.py +114 -0
  18. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  19. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  20. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  21. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  22. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  23. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  24. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  25. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  26. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  27. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  28. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  29. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  30. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  31. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  32. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  33. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  34. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  35. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  36. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  37. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  38. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  39. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  40. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  41. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  42. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  43. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  44. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  45. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  46. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  47. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  48. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  49. package/skills/docx/scripts/office/schemas/mce/mc.xsd +75 -0
  50. package/skills/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  51. package/skills/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  52. package/skills/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  53. package/skills/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  54. package/skills/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  55. package/skills/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  56. package/skills/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  57. package/skills/docx/scripts/office/soffice.py +192 -0
  58. package/skills/docx/scripts/office/validate.py +173 -0
  59. package/skills/docx/scripts/office/validators/__init__.py +15 -0
  60. package/skills/docx/scripts/office/validators/base.py +875 -0
  61. package/skills/docx/scripts/office/validators/docx.py +466 -0
  62. package/skills/docx/scripts/office/validators/pptx.py +441 -0
  63. package/skills/docx/scripts/office/validators/redlining.py +299 -0
  64. package/skills/docx/scripts/templates/comments.xml +3 -0
  65. package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  66. package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  67. package/skills/docx/scripts/templates/commentsIds.xml +3 -0
  68. package/skills/docx/scripts/templates/people.xml +3 -0
  69. package/skills/impeccable/SKILL.md +87 -0
  70. package/skills/impeccable/reference/adapt.md +318 -0
  71. package/skills/impeccable/reference/adapt.native.md +58 -0
  72. package/skills/impeccable/reference/android.md +46 -0
  73. package/skills/impeccable/reference/animate.md +89 -0
  74. package/skills/impeccable/reference/audit.md +150 -0
  75. package/skills/impeccable/reference/audit.native.md +143 -0
  76. package/skills/impeccable/reference/bolder.md +33 -0
  77. package/skills/impeccable/reference/clarify.md +94 -0
  78. package/skills/impeccable/reference/colorize.md +86 -0
  79. package/skills/impeccable/reference/component-review.md +63 -0
  80. package/skills/impeccable/reference/craft-floor.md +44 -0
  81. package/skills/impeccable/reference/craft.md +5 -0
  82. package/skills/impeccable/reference/critique.md +819 -0
  83. package/skills/impeccable/reference/degraded/asset-producer.md +42 -0
  84. package/skills/impeccable/reference/degraded/documenter.md +24 -0
  85. package/skills/impeccable/reference/degraded/finish-reviewer.md +38 -0
  86. package/skills/impeccable/reference/degraded/manual-edit-applier.md +93 -0
  87. package/skills/impeccable/reference/delight.md +70 -0
  88. package/skills/impeccable/reference/distill.md +111 -0
  89. package/skills/impeccable/reference/doctor.md +54 -0
  90. package/skills/impeccable/reference/document.md +416 -0
  91. package/skills/impeccable/reference/extract.md +69 -0
  92. package/skills/impeccable/reference/generate.md +101 -0
  93. package/skills/impeccable/reference/harden.md +362 -0
  94. package/skills/impeccable/reference/hooks.md +120 -0
  95. package/skills/impeccable/reference/init.md +133 -0
  96. package/skills/impeccable/reference/ios.md +51 -0
  97. package/skills/impeccable/reference/layout.md +84 -0
  98. package/skills/impeccable/reference/live-setup.md +104 -0
  99. package/skills/impeccable/reference/live.md +327 -0
  100. package/skills/impeccable/reference/mode-operate.md +21 -0
  101. package/skills/impeccable/reference/mode-persuade.md +19 -0
  102. package/skills/impeccable/reference/mode-read.md +21 -0
  103. package/skills/impeccable/reference/new-work.md +152 -0
  104. package/skills/impeccable/reference/onboard.md +235 -0
  105. package/skills/impeccable/reference/operate.md +61 -0
  106. package/skills/impeccable/reference/optimize.md +257 -0
  107. package/skills/impeccable/reference/overdrive.md +127 -0
  108. package/skills/impeccable/reference/polish.md +105 -0
  109. package/skills/impeccable/reference/quieter.md +99 -0
  110. package/skills/impeccable/reference/region-map.md +26 -0
  111. package/skills/impeccable/reference/routing.md +24 -0
  112. package/skills/impeccable/reference/shape.md +59 -0
  113. package/skills/impeccable/reference/typeset.md +90 -0
  114. package/skills/impeccable/reference/visualize.md +47 -0
  115. package/skills/impeccable/scripts/VERSION +1 -0
  116. package/skills/impeccable/scripts/command-metadata.json +98 -0
  117. package/skills/impeccable/scripts/data/font-index-failures.json +121 -0
  118. package/skills/impeccable/scripts/data/font-index.json +1 -0
  119. package/skills/impeccable/scripts/engine-checksums.txt +9 -0
  120. package/skills/impeccable/scripts/impeccable +291 -0
  121. package/skills/impeccable/scripts/impeccable.cmd +337 -0
  122. package/skills/impeccable/scripts/live-browser-dom.js +320 -0
  123. package/skills/impeccable/scripts/live-browser-ignores.js +246 -0
  124. package/skills/impeccable/scripts/live-browser-session.js +183 -0
  125. package/skills/impeccable/scripts/live-browser.js +13872 -0
  126. package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
  127. package/skills/pdf/LICENSE.txt +202 -0
  128. package/skills/pdf/SKILL.md +314 -0
  129. package/skills/pdf/forms.md +294 -0
  130. package/skills/pdf/reference.md +612 -0
  131. package/skills/pdf/scripts/check_bounding_boxes.py +65 -0
  132. package/skills/pdf/scripts/check_fillable_fields.py +11 -0
  133. package/skills/pdf/scripts/convert_pdf_to_images.py +33 -0
  134. package/skills/pdf/scripts/create_validation_image.py +37 -0
  135. package/skills/pdf/scripts/extract_form_field_info.py +122 -0
  136. package/skills/pdf/scripts/extract_form_structure.py +115 -0
  137. package/skills/pdf/scripts/fill_fillable_fields.py +98 -0
  138. package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
  139. package/skills/xlsx/LICENSE.txt +202 -0
  140. package/skills/xlsx/SKILL.md +99 -0
  141. package/skills/xlsx/scripts/office/helpers/__init__.py +111 -0
  142. package/skills/xlsx/scripts/office/helpers/pptx_chart.py +170 -0
  143. package/skills/xlsx/scripts/office/helpers/pptx_slide.py +60 -0
  144. package/skills/xlsx/scripts/office/helpers/pptx_theme.py +114 -0
  145. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  146. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  147. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  148. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  149. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  150. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  151. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  152. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  153. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  154. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  155. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  156. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  157. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  158. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  159. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  160. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  161. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  162. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  163. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  164. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  165. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  166. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  167. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  168. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  169. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  170. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  171. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  172. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  173. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  174. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  175. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  176. package/skills/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
  177. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  178. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  179. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  180. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  181. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  182. package/skills/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  183. package/skills/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  184. package/skills/xlsx/scripts/office/soffice.py +192 -0
  185. package/skills/xlsx/scripts/office/validate.py +173 -0
  186. package/skills/xlsx/scripts/office/validators/__init__.py +15 -0
  187. package/skills/xlsx/scripts/office/validators/base.py +875 -0
  188. package/skills/xlsx/scripts/office/validators/docx.py +466 -0
  189. package/skills/xlsx/scripts/office/validators/pptx.py +441 -0
  190. package/skills/xlsx/scripts/office/validators/redlining.py +299 -0
  191. package/skills/xlsx/scripts/recalc.py +308 -0
  192. package/skills-manifest.json +36 -0
@@ -0,0 +1,111 @@
1
+ import os
2
+ import posixpath
3
+ import re
4
+ import stat
5
+ import tempfile
6
+ import urllib.parse
7
+ import zipfile
8
+ from pathlib import Path
9
+
10
+ OOXML_FAMILY = {
11
+ ".docx": "docx",
12
+ ".dotx": "docx",
13
+ ".pptx": "pptx",
14
+ ".potx": "pptx",
15
+ ".xlsx": "xlsx",
16
+ ".xltx": "xlsx",
17
+ }
18
+
19
+ _SCHEME_RE = re.compile(r"^[A-Za-z][A-Za-z0-9+.\-]*:")
20
+
21
+ SLIDE_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
22
+
23
+
24
+ def opc_target(target: str, source_part: str, target_mode: str = "") -> str | None:
25
+ if not target:
26
+ return None
27
+ if target_mode.lower() == "external":
28
+ return None
29
+ if _SCHEME_RE.match(target):
30
+ return None
31
+
32
+ target = urllib.parse.unquote(target)
33
+
34
+ if "\\" in target:
35
+ raise ValueError(f"relationship target is not a POSIX part name: {target!r}")
36
+
37
+ if target.startswith("/"):
38
+ joined = target.lstrip("/")
39
+ else:
40
+ joined = posixpath.join(posixpath.dirname(source_part), target)
41
+
42
+ parts: list[str] = []
43
+ for segment in posixpath.normpath(joined).split("/"):
44
+ if segment in ("", "."):
45
+ continue
46
+ if segment == "..":
47
+ if not parts:
48
+ raise ValueError(f"relationship target escapes the package: {target!r}")
49
+ parts.pop()
50
+ else:
51
+ parts.append(segment)
52
+
53
+ if not parts:
54
+ raise ValueError(f"relationship target resolves to nothing: {target!r}")
55
+ return "/".join(parts)
56
+
57
+
58
+ def rels_source_part(rels_file: Path, unpacked_dir: Path) -> str:
59
+ owner_dir = rels_file.parent.parent.relative_to(unpacked_dir)
60
+ return posixpath.join(owner_dir.as_posix(), rels_file.name[: -len(".rels")]).lstrip("./")
61
+
62
+
63
+ def part_text(data: bytes) -> str:
64
+ return data.decode("utf-8", "surrogateescape")
65
+
66
+
67
+ XML_SPACE = " \t\r\n"
68
+
69
+
70
+ def rendered_text(text: str, preserve: bool) -> str:
71
+ return text if preserve else text.strip(XML_SPACE)
72
+
73
+
74
+ def safe_extract(zf: zipfile.ZipFile, dest: Path) -> None:
75
+ dest = dest.resolve()
76
+ for m in zf.infolist():
77
+ if stat.S_ISLNK(m.external_attr >> 16):
78
+ raise ValueError(f"symlink archive entry not allowed: {m.filename!r}")
79
+ target = (dest / m.filename).resolve()
80
+ if not target.is_relative_to(dest):
81
+ raise ValueError(f"unsafe archive entry: {m.filename!r}")
82
+ zf.extract(m, dest)
83
+
84
+
85
+ def rezip(src_dir: Path, out_path: Path) -> None:
86
+ files = sorted(p for p in src_dir.rglob("*") if p.is_file())
87
+ ct = src_dir / "[Content_Types].xml"
88
+ fd, tmp_name = tempfile.mkstemp(
89
+ prefix=out_path.name + ".", suffix=".tmp", dir=out_path.parent
90
+ )
91
+ tmp_out = Path(tmp_name)
92
+ try:
93
+ with os.fdopen(fd, "wb") as fh:
94
+ with zipfile.ZipFile(fh, "w", zipfile.ZIP_DEFLATED) as zf:
95
+ if ct.exists():
96
+ zf.write(ct, ct.relative_to(src_dir), compress_type=zipfile.ZIP_STORED)
97
+ for f in files:
98
+ if f == ct:
99
+ continue
100
+ zf.write(f, f.relative_to(src_dir))
101
+ if out_path.exists():
102
+ mode = out_path.stat().st_mode & 0o777
103
+ else:
104
+ umask = os.umask(0)
105
+ os.umask(umask)
106
+ mode = 0o666 & ~umask
107
+ os.chmod(tmp_out, mode)
108
+ os.replace(tmp_out, out_path)
109
+ finally:
110
+ if tmp_out.exists():
111
+ tmp_out.unlink()
@@ -0,0 +1,170 @@
1
+ """Find chart XML that PowerPoint refuses but the schema accepts.
2
+
3
+ Detection only: for either fault more than one repair is valid, and only the
4
+ author knows which was meant.
5
+ """
6
+
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from typing import Mapping
12
+
13
+ from . import part_text
14
+
15
+
16
+ _CHART_PART_RE = re.compile(r"ppt/charts/chart\d+\.xml")
17
+
18
+ _GROUPING_RE = re.compile(r"""<c:grouping\b[^>]*?\bval=["'](\w+)["']""")
19
+ _DLBL_POS_RE = re.compile(r"""<c:dLblPos\b[^>]*?\bval=["'](\w+)["']""")
20
+
21
+ def _strip_ext_lst(text: str) -> str:
22
+ out, cursor = [], 0
23
+ for lo, hi in _ext_lst_spans(text):
24
+ out.append(text[cursor:lo])
25
+ cursor = hi
26
+ out.append(text[cursor:])
27
+ return "".join(out)
28
+
29
+ _BAR_GROUP_RE = re.compile(r"<c:(bar3DChart|barChart)\b[^>]*(?<!/)>.*?</c:\1\s*>", re.DOTALL)
30
+
31
+ STACKED_GROUPINGS = frozenset({"stacked", "percentStacked"})
32
+ ILLEGAL_ON_STACKED = frozenset({"outEnd"})
33
+ LEGAL_ON_STACKED = ("ctr", "inEnd", "inBase")
34
+
35
+
36
+ def _check_stacked_label_positions(part: str, xml: str) -> list[str]:
37
+ problems: list[str] = []
38
+ for match in _BAR_GROUP_RE.finditer(xml):
39
+ block = _strip_ext_lst(match.group(0))
40
+ group = match.group(1)
41
+
42
+ grouping = _GROUPING_RE.search(block)
43
+ if grouping is None or grouping.group(1) not in STACKED_GROUPINGS:
44
+ continue
45
+
46
+ bad = [p for p in _DLBL_POS_RE.findall(block) if p in ILLEGAL_ON_STACKED]
47
+ for pos in sorted(set(bad)):
48
+ problems.append(
49
+ f'{part}: {bad.count(pos)} data label(s) use dLblPos="{pos}" on a '
50
+ f"{grouping.group(1)} {group}; PowerPoint allows only "
51
+ f"{', '.join(LEGAL_ON_STACKED)} there"
52
+ )
53
+ return problems
54
+
55
+
56
+
57
+ _ANY_CHART_GROUP_RE = re.compile(r"<c:(\w+Chart)\b[^>]*(?<!/)>.*?</c:\1\s*>", re.DOTALL)
58
+
59
+ _AXID_RE = re.compile(
60
+ r"""\s*<c:axId\b[^>]*?\bval=["'](-?\d+)["']\s*(?:/>|>\s*</c:axId\s*>)"""
61
+ )
62
+
63
+ _AXIS_DECL_RE = re.compile(
64
+ r"""<c:(catAx|valAx|serAx|dateAx)\b[^>]*(?<!/)>\s*<c:axId\b[^>]*?\bval=["'](-?\d+)["']"""
65
+ )
66
+
67
+ AXID_LIMIT = {
68
+ "barChart": 2, "lineChart": 2, "areaChart": 2, "scatterChart": 2,
69
+ "bubbleChart": 2, "radarChart": 2, "stockChart": 2,
70
+ "bar3DChart": 3, "line3DChart": 3, "area3DChart": 3,
71
+ "surfaceChart": 3, "surface3DChart": 3,
72
+ }
73
+
74
+ AXID_MINIMUM = {
75
+ "barChart": 2, "lineChart": 2, "areaChart": 2, "scatterChart": 2,
76
+ "bubbleChart": 2, "radarChart": 2, "stockChart": 2,
77
+ "bar3DChart": 2, "area3DChart": 2, "surfaceChart": 2,
78
+ "line3DChart": 3, "surface3DChart": 3,
79
+ }
80
+
81
+
82
+ def _declared_axes(xml: str) -> dict[str, list[str]]:
83
+ axes: dict[str, list[str]] = {}
84
+ for kind, axid in _AXIS_DECL_RE.findall(xml):
85
+ axes.setdefault(kind, []).append(axid)
86
+ return axes
87
+
88
+
89
+ def _canonical_ids(axes: dict[str, list[str]], limit: int) -> list[str] | None:
90
+ category = axes.get("catAx", []) + axes.get("dateAx", [])
91
+ value = axes.get("valAx", [])
92
+ series = axes.get("serAx", [])
93
+ if len(category) != 1 or len(value) != 1 or len(series) > 1:
94
+ return None
95
+ ids = [category[0], value[0]]
96
+ if limit >= 3 and series:
97
+ ids.append(series[0])
98
+ return ids
99
+
100
+
101
+ def _undeclared_axes(kind: str, block: str, axes: dict[str, list[str]]) -> list[str] | None:
102
+ if kind not in AXID_LIMIT:
103
+ return None
104
+ ids = _AXID_RE.findall(block)
105
+ declared = {i for group in axes.values() for i in group}
106
+ if len([i for i in ids if i in declared]) >= 2:
107
+ return None
108
+ return ids
109
+
110
+
111
+ def _check_chart_axis_references(part: str, xml: str) -> list[str]:
112
+ axes = _declared_axes(xml)
113
+ problems: list[str] = []
114
+ declared = {i for group in axes.values() for i in group}
115
+ for match in _ANY_CHART_GROUP_RE.finditer(xml):
116
+ kind, block = match.group(1), match.group(0)
117
+ ids = _undeclared_axes(kind, block, axes)
118
+ if ids is None:
119
+ continue
120
+ if not ids:
121
+ problems.append(
122
+ f"{part}: <c:{kind}> declares no <c:axId> this part can resolve; a chart "
123
+ f"group needs {AXID_MINIMUM[kind]}, and PowerPoint discards one with fewer"
124
+ )
125
+ continue
126
+ dead = [i for i in ids if i not in declared]
127
+ canonical = _canonical_ids(axes, AXID_LIMIT[kind])
128
+ if canonical is not None and len(canonical) >= AXID_MINIMUM[kind]:
129
+ hint = f"Fix: point them at the axes this part declares ({', '.join(canonical)})"
130
+ else:
131
+ hint = ("Fix: the part declares several axes of a kind -- declare the "
132
+ "secondary axes the series expects, or drop them")
133
+ detail = (f"of which {', '.join(dead)} name no declared axis"
134
+ if dead else f"only {len(ids)} of which this part declares")
135
+ problems.append(
136
+ f"{part}: <c:{kind}> references axId {', '.join(ids)}, {detail}, "
137
+ f"leaving fewer than two live axes; PowerPoint discards the chart. {hint}"
138
+ )
139
+ return problems
140
+
141
+
142
+ def _ext_lst_spans(text: str) -> list[tuple[int, int]]:
143
+ spans: list[tuple[int, int]] = []
144
+ depth = 0
145
+ start = 0
146
+ for match in re.finditer(r"<(/?)c:extLst\b[^>]*?(/?)>", text):
147
+ closing, self_closing = match.group(1), match.group(2)
148
+ if self_closing:
149
+ continue
150
+ if closing:
151
+ depth -= 1
152
+ if depth == 0:
153
+ spans.append((start, match.end()))
154
+ else:
155
+ if depth == 0:
156
+ start = match.start()
157
+ depth += 1
158
+ return spans
159
+
160
+
161
+ CHART_CHECKS = (_check_stacked_label_positions, _check_chart_axis_references)
162
+
163
+
164
+ def find_chart_problems(files: Mapping[str, bytes]) -> list[str]:
165
+ problems: list[str] = []
166
+ for part in sorted(n for n in files if _CHART_PART_RE.fullmatch(n)):
167
+ xml = part_text(files[part])
168
+ for check in CHART_CHECKS:
169
+ problems.extend(check(part, xml))
170
+ return problems
@@ -0,0 +1,60 @@
1
+ """Pick the slide-XML schema errors PowerPoint refuses the file over.
2
+
3
+ A denylist over lxml's messages, so an unrecognised error class is a miss rather
4
+ than a false alarm.
5
+ """
6
+
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+
12
+ SLIDE_PART_RE = re.compile(
13
+ r"ppt/(slides|slideLayouts|slideMasters|notesSlides|notesMasters|handoutMasters)"
14
+ r"/[^/]+\.xml"
15
+ )
16
+
17
+ FATAL_SLIDE_ERRORS: tuple[tuple[re.Pattern[str], str], ...] = (
18
+ (
19
+ re.compile(r"\}tableStyleId': This element is not expected"),
20
+ "two <a:tableStyleId> in one <a:tblPr> (the schema allows one)",
21
+ ),
22
+ (
23
+ re.compile(r"\}srgbClr', attribute 'val'"),
24
+ "a colour that is not six hex digits",
25
+ ),
26
+ (
27
+ re.compile(r"\}txBody': Missing child element"),
28
+ "a <p:txBody> with no children",
29
+ ),
30
+ (
31
+ re.compile(r"\}miter', attribute 'lim'"),
32
+ 'a line join with lim="NaN"',
33
+ ),
34
+ (
35
+ re.compile(r"\}uLnTx': This element is not expected"),
36
+ "<a:uLnTx> in a position the schema forbids",
37
+ ),
38
+ (
39
+ re.compile(r"\}overrideClrMapping': This element is not expected"),
40
+ "<p:overrideClrMapping> in a position the schema forbids",
41
+ ),
42
+ (
43
+ re.compile(r"\}nvGrpSpPr': Missing child element"),
44
+ "a <p:nvGrpSpPr> with no children",
45
+ ),
46
+ )
47
+
48
+
49
+ def is_schema_verdict(error: str) -> bool:
50
+ return error.startswith("Element ")
51
+
52
+
53
+ def fatal_slide_errors(errors: set[str]) -> list[str]:
54
+ out = []
55
+ for error in sorted(errors):
56
+ for pattern, meaning in FATAL_SLIDE_ERRORS:
57
+ if pattern.search(error):
58
+ out.append(f"{meaning}: {error}")
59
+ break
60
+ return out
@@ -0,0 +1,114 @@
1
+ """Find masters sharing a theme part in the way PowerPoint refuses to open.
2
+
3
+ Reports only; the fix is to move <p:notesMasterIdLst> back to directly after
4
+ <p:sldIdLst> in ppt/presentation.xml.
5
+ """
6
+
7
+
8
+ from __future__ import annotations
9
+
10
+ import posixpath
11
+ import re
12
+ from typing import Mapping
13
+
14
+ from . import part_text
15
+
16
+ THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
17
+
18
+ _MASTER_RE = re.compile(
19
+ r"^ppt/(?P<group>slideMasters|notesMasters|handoutMasters)/"
20
+ r"(?:slide|notes|handout)Master(?P<num>\d+)\.xml$"
21
+ )
22
+ _GROUP_ORDER = {"slideMasters": 0, "notesMasters": 1, "handoutMasters": 2}
23
+
24
+ _RELATIONSHIP_RE = re.compile(
25
+ r"<Relationship\b[^>]*?(?:/>|>.*?</Relationship\s*>)", re.DOTALL
26
+ )
27
+
28
+
29
+ def _sort_key(name: str) -> tuple[int, int]:
30
+ m = _MASTER_RE.match(name)
31
+ assert m is not None
32
+ return (_GROUP_ORDER[m.group("group")], int(m.group("num")))
33
+
34
+
35
+ def _rels_path(part: str) -> str:
36
+ directory, base = posixpath.split(part)
37
+ return f"{directory}/_rels/{base}.rels"
38
+
39
+
40
+ def _resolve(rels_path: str, target: str) -> str:
41
+ if target.startswith("/"):
42
+ return target.lstrip("/")
43
+ part_dir = posixpath.dirname(posixpath.dirname(rels_path))
44
+ return posixpath.normpath(posixpath.join(part_dir, target))
45
+
46
+
47
+ def _theme_rel(files: Mapping[str, bytes], master: str):
48
+ rels_path = _rels_path(master)
49
+ rels = files.get(rels_path)
50
+ if rels is None:
51
+ return None
52
+ for element in _RELATIONSHIP_RE.findall(part_text(rels)):
53
+ if f'Type="{THEME_REL_TYPE}"' not in element:
54
+ continue
55
+ target = re.search(r'\bTarget="([^"]+)"', element)
56
+ if target is None:
57
+ continue
58
+ return rels_path, element, _resolve(rels_path, target.group(1))
59
+ return None
60
+
61
+
62
+ def _masters(files: Mapping[str, bytes]) -> list[str]:
63
+ return sorted((n for n in files if _MASTER_RE.match(n)), key=_sort_key)
64
+
65
+
66
+ _PRESENTATION = "ppt/presentation.xml"
67
+ _NOTES_MASTERS = "ppt/notesMasters/"
68
+ _IGNORABLE_RE = re.compile(r"<!--.*?-->|<\?.*?\?>", re.DOTALL)
69
+ _AFTER_SLDIDLST_RE = re.compile(
70
+ r"<p:sldIdLst\b(?:[^>]*/>|[^>]*>.*?</p:sldIdLst\s*>)\s*(<[^>\s/]+)", re.DOTALL
71
+ )
72
+
73
+
74
+ def _notes_master_share_is_inert(files: Mapping[str, bytes]) -> bool:
75
+ data = files.get(_PRESENTATION)
76
+ if data is None:
77
+ return False
78
+ match = _AFTER_SLDIDLST_RE.search(_IGNORABLE_RE.sub("", part_text(data)))
79
+ return match is not None and match.group(1) == "<p:notesMasterIdLst"
80
+
81
+
82
+ def _shares(files: Mapping[str, bytes]):
83
+ owner: dict[str, str] = {}
84
+ for master in _masters(files):
85
+ found = _theme_rel(files, master)
86
+ if found is None:
87
+ continue
88
+ rels_path, element, theme = found
89
+ if theme not in files:
90
+ continue
91
+ if theme in owner:
92
+ yield master, rels_path, element, theme, owner[theme]
93
+ else:
94
+ owner[theme] = master
95
+
96
+
97
+ def _is_inert(master: str, inert_notes: bool) -> bool:
98
+ return inert_notes and master.startswith(_NOTES_MASTERS)
99
+
100
+
101
+ def find_shared_master_themes(files: Mapping[str, bytes]) -> list[str]:
102
+ return [
103
+ f"{master} shares {theme} with {first}"
104
+ for master, _, _, theme, first in _shares(files)
105
+ ]
106
+
107
+
108
+ def live_shared_master_themes(files: Mapping[str, bytes]) -> list[str]:
109
+ inert_notes = _notes_master_share_is_inert(files)
110
+ return [
111
+ f"{master} shares {theme} with {first}"
112
+ for master, _, _, theme, first in _shares(files)
113
+ if not _is_inert(master, inert_notes)
114
+ ]