dsh-office-kit 0.3.0 → 0.3.2

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 (73) hide show
  1. package/assets/skills/office-documents/render_docx.py +7 -0
  2. package/assets/skills/office-documents/scripts/a11y_audit.py +7 -0
  3. package/assets/skills/office-documents/scripts/accept_tracked_changes.py +7 -0
  4. package/assets/skills/office-documents/scripts/add_tracked_replacements.py +7 -0
  5. package/assets/skills/office-documents/scripts/append_blocks.py +7 -0
  6. package/assets/skills/office-documents/scripts/apply_template_styles.py +7 -0
  7. package/assets/skills/office-documents/scripts/captions_and_crossrefs.py +7 -0
  8. package/assets/skills/office-documents/scripts/comments_add.py +7 -0
  9. package/assets/skills/office-documents/scripts/comments_apply_patch.py +7 -0
  10. package/assets/skills/office-documents/scripts/comments_extract.py +7 -0
  11. package/assets/skills/office-documents/scripts/comments_strip.py +7 -0
  12. package/assets/skills/office-documents/scripts/content_controls.py +7 -0
  13. package/assets/skills/office-documents/scripts/core_properties.py +7 -0
  14. package/assets/skills/office-documents/scripts/docx_kit.py +7 -0
  15. package/assets/skills/office-documents/scripts/docx_ooxml_patch.py +7 -0
  16. package/assets/skills/office-documents/scripts/docx_table_to_csv.py +7 -0
  17. package/assets/skills/office-documents/scripts/fields_materialize.py +7 -0
  18. package/assets/skills/office-documents/scripts/fields_report.py +7 -0
  19. package/assets/skills/office-documents/scripts/flatten_ref_fields.py +7 -0
  20. package/assets/skills/office-documents/scripts/footnotes_report.py +7 -0
  21. package/assets/skills/office-documents/scripts/google_docs_title_sanitize.py +7 -0
  22. package/assets/skills/office-documents/scripts/heading_audit.py +7 -0
  23. package/assets/skills/office-documents/scripts/images_audit.py +7 -0
  24. package/assets/skills/office-documents/scripts/insert_note.py +7 -0
  25. package/assets/skills/office-documents/scripts/insert_ref_fields.py +7 -0
  26. package/assets/skills/office-documents/scripts/insert_toc.py +7 -0
  27. package/assets/skills/office-documents/scripts/internal_nav.py +7 -0
  28. package/assets/skills/office-documents/scripts/make_fixtures.py +7 -0
  29. package/assets/skills/office-documents/scripts/merge_docx_append.py +7 -0
  30. package/assets/skills/office-documents/scripts/privacy_scrub.py +7 -0
  31. package/assets/skills/office-documents/scripts/redact_docx.py +7 -0
  32. package/assets/skills/office-documents/scripts/render_and_diff.py +7 -0
  33. package/assets/skills/office-documents/scripts/replace_text.py +7 -0
  34. package/assets/skills/office-documents/scripts/section_audit.py +7 -0
  35. package/assets/skills/office-documents/scripts/set_protection.py +7 -0
  36. package/assets/skills/office-documents/scripts/style_lint.py +7 -0
  37. package/assets/skills/office-documents/scripts/style_normalize.py +7 -0
  38. package/assets/skills/office-documents/scripts/table_geometry.py +7 -0
  39. package/assets/skills/office-documents/scripts/watermark_add.py +7 -0
  40. package/assets/skills/office-documents/scripts/watermark_audit_remove.py +7 -0
  41. package/assets/skills/office-documents/scripts/xlsx_to_docx_table.py +7 -0
  42. package/assets/skills/office-presentations/container_tools/add_slides.py +7 -0
  43. package/assets/skills/office-presentations/container_tools/core_properties.py +7 -0
  44. package/assets/skills/office-presentations/container_tools/create_montage.py +7 -0
  45. package/assets/skills/office-presentations/container_tools/inspect_presentation_layout_geometry.py +7 -0
  46. package/assets/skills/office-presentations/container_tools/inspect_presentation_package_integrity.py +7 -0
  47. package/assets/skills/office-presentations/container_tools/native_chart_title_gate.py +7 -0
  48. package/assets/skills/office-presentations/container_tools/native_quantitative_chart_gate.py +7 -0
  49. package/assets/skills/office-presentations/container_tools/native_table_arithmetic_gate.py +7 -0
  50. package/assets/skills/office-presentations/container_tools/ooxml_helpers.py +7 -0
  51. package/assets/skills/office-presentations/container_tools/preview_render.py +7 -0
  52. package/assets/skills/office-presentations/container_tools/render_slides.py +7 -0
  53. package/assets/skills/office-presentations/container_tools/replace_text.py +7 -0
  54. package/assets/skills/office-presentations/container_tools/template_source_fidelity_gate.py +7 -0
  55. package/assets/skills/office-presentations/template_following_scripts/check_template_fidelity.py +7 -0
  56. package/assets/skills/office-presentations/template_following_scripts/inspect_template_deck.py +7 -0
  57. package/assets/skills/office-presentations/template_following_scripts/make_contact_sheet.py +7 -0
  58. package/assets/skills/office-presentations/template_following_scripts/prepare_template_starter_deck.py +7 -0
  59. package/assets/skills/office-presentations/template_following_scripts/validate_template_plan.py +7 -0
  60. package/assets/skills/office-spreadsheets/container_tools/add_chart.py +7 -0
  61. package/assets/skills/office-spreadsheets/container_tools/add_image.py +7 -0
  62. package/assets/skills/office-spreadsheets/container_tools/append_rows.py +7 -0
  63. package/assets/skills/office-spreadsheets/container_tools/diff_workbooks.py +7 -0
  64. package/assets/skills/office-spreadsheets/container_tools/inspect_workbook.py +7 -0
  65. package/assets/skills/office-spreadsheets/container_tools/recalc_gate.py +19 -7
  66. package/assets/skills/office-spreadsheets/container_tools/set_cells.py +7 -0
  67. package/assets/skills/office-spreadsheets/container_tools/sheet_ops.py +7 -0
  68. package/assets/skills/office-spreadsheets/container_tools/style_cells.py +7 -0
  69. package/assets/skills/shared/check_runtime.py +7 -0
  70. package/dist/index.js +31 -18
  71. package/package.json +1 -1
  72. package/postinstall.mjs +41 -18
  73. package/python/office_cli.py +52 -9
@@ -21,7 +21,18 @@ import tempfile
21
21
  from pathlib import Path
22
22
  from typing import Any, Iterable
23
23
 
24
- VERSION = "0.1.0"
24
+ PACKAGE_ROOT = Path(__file__).resolve().parents[1]
25
+
26
+
27
+ def _package_version() -> str:
28
+ try:
29
+ data = json.loads((PACKAGE_ROOT / "package.json").read_text(encoding="utf-8"))
30
+ return str(data["version"])
31
+ except (OSError, ValueError, KeyError, TypeError):
32
+ return "0.0.0"
33
+
34
+
35
+ VERSION = _package_version()
25
36
 
26
37
  # Windows consoles default to a legacy code page; every payload is UTF-8 JSON.
27
38
  for _stream in (sys.stdout, sys.stderr):
@@ -339,6 +350,16 @@ def _docx_add_equation(paragraph, latex: str) -> bool:
339
350
  return False
340
351
 
341
352
 
353
+ def _docx_mark_header_row(row) -> None:
354
+ """Repeat this row across pages and mark it as a header for assistive tech."""
355
+ from docx.oxml.ns import qn
356
+
357
+ properties = row._tr.get_or_add_trPr()
358
+ if properties.find(qn("w:tblHeader")) is None:
359
+ header = properties.makeelement(qn("w:tblHeader"), {})
360
+ properties.append(header)
361
+
362
+
342
363
  def _docx_add_block(document, block: dict[str, Any], counters: dict[str, int]) -> None:
343
364
  from docx.shared import Inches, Pt
344
365
 
@@ -391,6 +412,7 @@ def _docx_add_block(document, block: dict[str, Any], counters: dict[str, int]) -
391
412
  for paragraph in cells[index].paragraphs:
392
413
  for run in paragraph.runs:
393
414
  run.bold = True
415
+ _docx_mark_header_row(table.rows[0])
394
416
  for row in rows:
395
417
  cells = table.add_row().cells
396
418
  for index, value in enumerate(row):
@@ -459,6 +481,10 @@ def docx_create(spec: dict[str, Any], out: Path) -> dict[str, Any]:
459
481
  if spec.get("author") or spec.get("title"):
460
482
  document.core_properties.title = str(spec.get("title", ""))
461
483
  document.core_properties.author = str(spec.get("author", ""))
484
+ # A fresh python-docx document carries the library name in comments; a
485
+ # delivered file should not advertise the tool that wrote it.
486
+ document.core_properties.comments = str(spec.get("comments", ""))
487
+ document.core_properties.last_modified_by = str(spec.get("author", ""))
462
488
  if spec.get("header"):
463
489
  document.sections[0].header.paragraphs[0].text = str(spec["header"])
464
490
  if spec.get("footer"):
@@ -568,6 +594,9 @@ def _pdf_font() -> str:
568
594
  r"C:\Windows\Fonts\simsun.ttc",
569
595
  "/System/Library/Fonts/PingFang.ttc",
570
596
  "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
597
+ "/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
598
+ "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",
599
+ "/usr/share/fonts/truetype/arphic/uming.ttc",
571
600
  "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
572
601
  ]
573
602
  for candidate in candidates:
@@ -577,7 +606,13 @@ def _pdf_font() -> str:
577
606
  return "OfficeCJK"
578
607
  except Exception:
579
608
  continue
580
- return "Helvetica"
609
+ try:
610
+ from reportlab.pdfbase.cidfonts import UnicodeCIDFont
611
+
612
+ pdfmetrics.registerFont(UnicodeCIDFont("STSong-Light"))
613
+ return "STSong-Light"
614
+ except Exception:
615
+ return "Helvetica"
581
616
 
582
617
 
583
618
  def _pdf_flowables(blocks: Iterable[dict[str, Any]], font: str, counters: dict[str, int]):
@@ -659,17 +694,21 @@ def pdf_create(spec: dict[str, Any], out: Path) -> dict[str, Any]:
659
694
  author=str(spec.get("author", "")),
660
695
  )
661
696
  counters = {key: 0 for key in ("headings", "paragraphs", "list_items", "tables", "images")}
697
+ following: list[dict[str, Any]] = []
698
+ for page in spec.get("pages", []):
699
+ if isinstance(page, dict):
700
+ following.extend(page.get("blocks", []))
701
+ if page.get("break", True):
702
+ following.append({"type": "page_break"})
703
+ following.extend(spec.get("blocks", []))
704
+ kinds = {str(block.get("type", "")).lower() for block in following if isinstance(block, dict)}
662
705
  blocks: list[dict[str, Any]] = []
663
- if spec.get("title"):
706
+ # `title` is metadata; only draw it when the blocks do not already carry one.
707
+ if spec.get("title") and "title" not in kinds:
664
708
  blocks.append({"type": "title", "text": spec["title"]})
665
709
  if spec.get("subtitle"):
666
710
  blocks.append({"type": "paragraph", "text": spec["subtitle"]})
667
- for page in spec.get("pages", []):
668
- if isinstance(page, dict):
669
- blocks.extend(page.get("blocks", []))
670
- if page.get("break", True):
671
- blocks.append({"type": "page_break"})
672
- blocks.extend(spec.get("blocks", []))
711
+ blocks.extend(following)
673
712
  document.build(_pdf_flowables(blocks, font, counters))
674
713
  return {"ok": True, "kind": "pdf", "command": "create", "output": str(out), "font": font, "counts": counters}
675
714
 
@@ -849,6 +888,10 @@ def pptx_create(spec: dict[str, Any], out: Path) -> dict[str, Any]:
849
888
  prs.slide_height = int(7.5 * 914400)
850
889
  prs.core_properties.title = str(spec.get("title", ""))
851
890
  prs.core_properties.author = str(spec.get("author", "DSH Office Suite"))
891
+ # python-pptx leaves its own name in the properties; a delivered deck should
892
+ # carry the author's, not the library's.
893
+ prs.core_properties.comments = str(spec.get("comments", ""))
894
+ prs.core_properties.last_modified_by = str(spec.get("author", "DSH Office Suite"))
852
895
  counters = {key: 0 for key in ("slides", "bullets", "tables", "charts", "images")}
853
896
  for slide_spec in spec.get("slides", []):
854
897
  if isinstance(slide_spec, dict):