@vodailoc/kilo-kit-mcp 1.1.0 → 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 (582) hide show
  1. package/.mcp/kilo-kit.codex-windows.toml +5 -0
  2. package/LICENSE +190 -190
  3. package/QUICKSTART.md +265 -255
  4. package/README.md +321 -267
  5. package/mcp/README.md +64 -12
  6. package/mcp/dist/formatters.js +142 -1
  7. package/mcp/dist/orchestration-audit.js +20 -0
  8. package/mcp/dist/orchestration-memory.js +258 -0
  9. package/mcp/dist/orchestration-types.js +1 -0
  10. package/mcp/dist/orchestrator.js +222 -0
  11. package/mcp/dist/question-templates.js +249 -0
  12. package/mcp/dist/route-analytics.js +149 -0
  13. package/mcp/dist/router.js +75 -82
  14. package/mcp/dist/routing-policy-data.js +241 -0
  15. package/mcp/dist/routing-policy.js +145 -0
  16. package/mcp/dist/server.js +93 -4
  17. package/mcp/dist/smoke-env.js +18 -0
  18. package/mcp/dist/smoke.js +68 -1
  19. package/mcp/package.json +1 -2
  20. package/package.json +3 -2
  21. package/skills/README.md +647 -647
  22. package/skills/SKILLS_INDEX.md +139 -139
  23. package/skills/ai-media/ai-multimodal/.env.example +97 -97
  24. package/skills/ai-media/ai-multimodal/SKILL.md +357 -357
  25. package/skills/ai-media/ai-multimodal/references/audio-processing.md +373 -373
  26. package/skills/ai-media/ai-multimodal/references/image-generation.md +558 -558
  27. package/skills/ai-media/ai-multimodal/references/video-analysis.md +502 -502
  28. package/skills/ai-media/ai-multimodal/references/vision-understanding.md +483 -483
  29. package/skills/ai-media/ai-multimodal/scripts/document_converter.py +395 -395
  30. package/skills/ai-media/ai-multimodal/scripts/gemini_batch_process.py +480 -480
  31. package/skills/ai-media/ai-multimodal/scripts/media_optimizer.py +506 -506
  32. package/skills/ai-media/ai-multimodal/scripts/requirements.txt +26 -26
  33. package/skills/ai-media/ai-multimodal/scripts/tests/requirements.txt +20 -20
  34. package/skills/ai-media/ai-multimodal/scripts/tests/test_document_converter.py +299 -299
  35. package/skills/ai-media/ai-multimodal/scripts/tests/test_gemini_batch_process.py +362 -362
  36. package/skills/ai-media/ai-multimodal/scripts/tests/test_media_optimizer.py +373 -373
  37. package/skills/ai-media/media-processing/SKILL.md +358 -358
  38. package/skills/ai-media/media-processing/references/ffmpeg-encoding.md +358 -358
  39. package/skills/ai-media/media-processing/references/ffmpeg-filters.md +503 -503
  40. package/skills/ai-media/media-processing/references/ffmpeg-streaming.md +403 -403
  41. package/skills/ai-media/media-processing/references/format-compatibility.md +375 -375
  42. package/skills/ai-media/media-processing/references/imagemagick-batch.md +612 -612
  43. package/skills/ai-media/media-processing/references/imagemagick-editing.md +623 -623
  44. package/skills/ai-media/media-processing/scripts/batch_resize.py +342 -342
  45. package/skills/ai-media/media-processing/scripts/media_convert.py +311 -311
  46. package/skills/ai-media/media-processing/scripts/requirements.txt +24 -24
  47. package/skills/ai-media/media-processing/scripts/tests/requirements.txt +2 -2
  48. package/skills/ai-media/media-processing/scripts/tests/test_batch_resize.py +372 -372
  49. package/skills/ai-media/media-processing/scripts/tests/test_media_convert.py +259 -259
  50. package/skills/ai-media/media-processing/scripts/tests/test_video_optimize.py +397 -397
  51. package/skills/ai-media/media-processing/scripts/video_optimize.py +414 -414
  52. package/skills/ai-media/screenshot/LICENSE.txt +201 -201
  53. package/skills/ai-media/screenshot/SKILL.md +267 -267
  54. package/skills/ai-media/screenshot/agents/openai.yaml +6 -6
  55. package/skills/ai-media/screenshot/assets/screenshot-small.svg +5 -5
  56. package/skills/ai-media/screenshot/scripts/ensure_macos_permissions.sh +54 -54
  57. package/skills/ai-media/screenshot/scripts/macos_display_info.swift +22 -22
  58. package/skills/ai-media/screenshot/scripts/macos_permissions.swift +40 -40
  59. package/skills/ai-media/screenshot/scripts/macos_window_info.swift +126 -126
  60. package/skills/ai-media/screenshot/scripts/take_screenshot.ps1 +163 -163
  61. package/skills/ai-media/screenshot/scripts/take_screenshot.py +585 -585
  62. package/skills/ai-media/sora/LICENSE.txt +201 -201
  63. package/skills/ai-media/sora/SKILL.md +153 -153
  64. package/skills/ai-media/sora/agents/openai.yaml +6 -6
  65. package/skills/ai-media/sora/assets/sora-small.svg +4 -4
  66. package/skills/ai-media/sora/references/cinematic-shots.md +53 -53
  67. package/skills/ai-media/sora/references/cli.md +248 -248
  68. package/skills/ai-media/sora/references/codex-network.md +28 -28
  69. package/skills/ai-media/sora/references/prompting.md +137 -137
  70. package/skills/ai-media/sora/references/sample-prompts.md +95 -95
  71. package/skills/ai-media/sora/references/social-ads.md +42 -42
  72. package/skills/ai-media/sora/references/troubleshooting.md +58 -58
  73. package/skills/ai-media/sora/references/video-api.md +45 -45
  74. package/skills/ai-media/sora/scripts/sora.py +970 -970
  75. package/skills/design/aesthetic/SKILL.md +121 -121
  76. package/skills/design/aesthetic/assets/design-guideline-template.md +163 -163
  77. package/skills/design/aesthetic/assets/design-story-template.md +135 -135
  78. package/skills/design/aesthetic/references/design-principles.md +62 -62
  79. package/skills/design/aesthetic/references/design-resources.md +75 -75
  80. package/skills/design/aesthetic/references/micro-interactions.md +53 -53
  81. package/skills/design/aesthetic/references/storytelling-design.md +50 -50
  82. package/skills/design/figma/LICENSE.txt +202 -202
  83. package/skills/design/figma/SKILL.md +42 -42
  84. package/skills/design/figma/agents/openai.yaml +14 -14
  85. package/skills/design/figma/assets/figma-small.svg +3 -3
  86. package/skills/design/figma/assets/icon.svg +28 -28
  87. package/skills/design/figma/references/figma-mcp-config.md +35 -35
  88. package/skills/design/figma/references/figma-tools-and-prompts.md +34 -34
  89. package/skills/design/figma-implement-design/LICENSE.txt +202 -202
  90. package/skills/design/figma-implement-design/SKILL.md +264 -264
  91. package/skills/design/figma-implement-design/agents/openai.yaml +14 -14
  92. package/skills/design/figma-implement-design/assets/figma-small.svg +3 -3
  93. package/skills/design/figma-implement-design/assets/icon.svg +28 -28
  94. package/skills/design/frontend-design/SKILL.md +41 -41
  95. package/skills/design/frontend-design/references/animejs.md +395 -395
  96. package/skills/design/ui-styling/LICENSE.txt +201 -201
  97. package/skills/design/ui-styling/SKILL.md +321 -321
  98. package/skills/design/ui-styling/canvas-fonts/ArsenalSC-OFL.txt +93 -93
  99. package/skills/design/ui-styling/canvas-fonts/BigShoulders-OFL.txt +93 -93
  100. package/skills/design/ui-styling/canvas-fonts/Boldonse-OFL.txt +93 -93
  101. package/skills/design/ui-styling/canvas-fonts/BricolageGrotesque-OFL.txt +93 -93
  102. package/skills/design/ui-styling/canvas-fonts/CrimsonPro-OFL.txt +93 -93
  103. package/skills/design/ui-styling/canvas-fonts/DMMono-OFL.txt +93 -93
  104. package/skills/design/ui-styling/canvas-fonts/EricaOne-OFL.txt +94 -94
  105. package/skills/design/ui-styling/canvas-fonts/GeistMono-OFL.txt +93 -93
  106. package/skills/design/ui-styling/canvas-fonts/Gloock-OFL.txt +93 -93
  107. package/skills/design/ui-styling/canvas-fonts/IBMPlexMono-OFL.txt +93 -93
  108. package/skills/design/ui-styling/canvas-fonts/InstrumentSans-OFL.txt +93 -93
  109. package/skills/design/ui-styling/canvas-fonts/Italiana-OFL.txt +93 -93
  110. package/skills/design/ui-styling/canvas-fonts/JetBrainsMono-OFL.txt +93 -93
  111. package/skills/design/ui-styling/canvas-fonts/Jura-OFL.txt +93 -93
  112. package/skills/design/ui-styling/canvas-fonts/LibreBaskerville-OFL.txt +93 -93
  113. package/skills/design/ui-styling/canvas-fonts/Lora-OFL.txt +93 -93
  114. package/skills/design/ui-styling/canvas-fonts/NationalPark-OFL.txt +93 -93
  115. package/skills/design/ui-styling/canvas-fonts/NothingYouCouldDo-OFL.txt +93 -93
  116. package/skills/design/ui-styling/canvas-fonts/Outfit-OFL.txt +93 -93
  117. package/skills/design/ui-styling/canvas-fonts/PixelifySans-OFL.txt +93 -93
  118. package/skills/design/ui-styling/canvas-fonts/PoiretOne-OFL.txt +93 -93
  119. package/skills/design/ui-styling/canvas-fonts/RedHatMono-OFL.txt +93 -93
  120. package/skills/design/ui-styling/canvas-fonts/Silkscreen-OFL.txt +93 -93
  121. package/skills/design/ui-styling/canvas-fonts/SmoochSans-OFL.txt +93 -93
  122. package/skills/design/ui-styling/canvas-fonts/Tektur-OFL.txt +93 -93
  123. package/skills/design/ui-styling/canvas-fonts/WorkSans-OFL.txt +93 -93
  124. package/skills/design/ui-styling/canvas-fonts/YoungSerif-OFL.txt +93 -93
  125. package/skills/design/ui-styling/references/canvas-design-system.md +320 -320
  126. package/skills/design/ui-styling/references/shadcn-accessibility.md +471 -471
  127. package/skills/design/ui-styling/references/shadcn-components.md +424 -424
  128. package/skills/design/ui-styling/references/shadcn-theming.md +373 -373
  129. package/skills/design/ui-styling/references/tailwind-customization.md +483 -483
  130. package/skills/design/ui-styling/references/tailwind-responsive.md +382 -382
  131. package/skills/design/ui-styling/references/tailwind-utilities.md +455 -455
  132. package/skills/design/ui-styling/scripts/requirements.txt +17 -17
  133. package/skills/design/ui-styling/scripts/shadcn_add.py +292 -292
  134. package/skills/design/ui-styling/scripts/tailwind_config_gen.py +456 -456
  135. package/skills/design/ui-styling/scripts/tests/requirements.txt +3 -3
  136. package/skills/design/ui-styling/scripts/tests/test_shadcn_add.py +266 -266
  137. package/skills/design/ui-styling/scripts/tests/test_tailwind_config_gen.py +336 -336
  138. package/skills/engineering/aspnet-core/LICENSE.txt +201 -201
  139. package/skills/engineering/aspnet-core/SKILL.md +61 -61
  140. package/skills/engineering/aspnet-core/agents/openai.yaml +5 -5
  141. package/skills/engineering/aspnet-core/references/_sections.md +40 -40
  142. package/skills/engineering/aspnet-core/references/apis-minimal-and-controllers.md +81 -81
  143. package/skills/engineering/aspnet-core/references/data-state-and-services.md +69 -69
  144. package/skills/engineering/aspnet-core/references/program-and-pipeline.md +103 -103
  145. package/skills/engineering/aspnet-core/references/realtime-grpc-and-background-work.md +58 -58
  146. package/skills/engineering/aspnet-core/references/security-and-identity.md +75 -75
  147. package/skills/engineering/aspnet-core/references/source-map.md +43 -43
  148. package/skills/engineering/aspnet-core/references/stack-selection.md +63 -63
  149. package/skills/engineering/aspnet-core/references/testing-performance-and-operations.md +92 -92
  150. package/skills/engineering/aspnet-core/references/ui-blazor.md +53 -53
  151. package/skills/engineering/aspnet-core/references/ui-mvc.md +56 -56
  152. package/skills/engineering/aspnet-core/references/ui-razor-pages.md +55 -55
  153. package/skills/engineering/aspnet-core/references/versioning-and-upgrades.md +51 -51
  154. package/skills/engineering/backend-development/SKILL.md +95 -95
  155. package/skills/engineering/backend-development/references/backend-api-design.md +495 -495
  156. package/skills/engineering/backend-development/references/backend-architecture.md +454 -454
  157. package/skills/engineering/backend-development/references/backend-authentication.md +338 -338
  158. package/skills/engineering/backend-development/references/backend-code-quality.md +659 -659
  159. package/skills/engineering/backend-development/references/backend-debugging.md +904 -904
  160. package/skills/engineering/backend-development/references/backend-devops.md +494 -494
  161. package/skills/engineering/backend-development/references/backend-mindset.md +387 -387
  162. package/skills/engineering/backend-development/references/backend-performance.md +397 -397
  163. package/skills/engineering/backend-development/references/backend-security.md +290 -290
  164. package/skills/engineering/backend-development/references/backend-technologies.md +256 -256
  165. package/skills/engineering/backend-development/references/backend-testing.md +429 -429
  166. package/skills/engineering/better-auth/SKILL.md +204 -204
  167. package/skills/engineering/better-auth/references/advanced-features.md +553 -553
  168. package/skills/engineering/better-auth/references/database-integration.md +577 -577
  169. package/skills/engineering/better-auth/references/email-password-auth.md +416 -416
  170. package/skills/engineering/better-auth/references/oauth-providers.md +430 -430
  171. package/skills/engineering/better-auth/scripts/better_auth_init.py +521 -521
  172. package/skills/engineering/better-auth/scripts/requirements.txt +15 -15
  173. package/skills/engineering/better-auth/scripts/tests/test_better_auth_init.py +421 -421
  174. package/skills/engineering/code-review/SKILL.md +140 -140
  175. package/skills/engineering/code-review/references/code-review-reception.md +208 -208
  176. package/skills/engineering/code-review/references/requesting-code-review.md +104 -104
  177. package/skills/engineering/code-review/references/verification-before-completion.md +138 -138
  178. package/skills/engineering/context-engineering/SKILL.md +86 -86
  179. package/skills/engineering/context-engineering/references/context-compression.md +84 -84
  180. package/skills/engineering/context-engineering/references/context-degradation.md +93 -93
  181. package/skills/engineering/context-engineering/references/context-fundamentals.md +75 -75
  182. package/skills/engineering/context-engineering/references/context-optimization.md +82 -82
  183. package/skills/engineering/context-engineering/references/evaluation.md +89 -89
  184. package/skills/engineering/context-engineering/references/memory-systems.md +88 -88
  185. package/skills/engineering/context-engineering/references/multi-agent-patterns.md +90 -90
  186. package/skills/engineering/context-engineering/references/project-development.md +97 -97
  187. package/skills/engineering/context-engineering/references/tool-design.md +86 -86
  188. package/skills/engineering/context-engineering/scripts/compression_evaluator.py +329 -329
  189. package/skills/engineering/context-engineering/scripts/context_analyzer.py +294 -294
  190. package/skills/engineering/databases/SKILL.md +232 -232
  191. package/skills/engineering/databases/references/mongodb-aggregation.md +447 -447
  192. package/skills/engineering/databases/references/mongodb-atlas.md +465 -465
  193. package/skills/engineering/databases/references/mongodb-crud.md +408 -408
  194. package/skills/engineering/databases/references/mongodb-indexing.md +442 -442
  195. package/skills/engineering/databases/references/postgresql-administration.md +594 -594
  196. package/skills/engineering/databases/references/postgresql-performance.md +527 -527
  197. package/skills/engineering/databases/references/postgresql-psql-cli.md +467 -467
  198. package/skills/engineering/databases/references/postgresql-queries.md +475 -475
  199. package/skills/engineering/databases/scripts/db_backup.py +502 -502
  200. package/skills/engineering/databases/scripts/db_migrate.py +414 -414
  201. package/skills/engineering/databases/scripts/db_performance_check.py +444 -444
  202. package/skills/engineering/databases/scripts/requirements.txt +20 -20
  203. package/skills/engineering/databases/scripts/tests/requirements.txt +4 -4
  204. package/skills/engineering/databases/scripts/tests/test_db_backup.py +340 -340
  205. package/skills/engineering/databases/scripts/tests/test_db_migrate.py +277 -277
  206. package/skills/engineering/databases/scripts/tests/test_db_performance_check.py +370 -370
  207. package/skills/engineering/diagnose/SKILL.md +117 -117
  208. package/skills/engineering/diagnose/scripts/hitl-loop.template.sh +41 -41
  209. package/skills/engineering/docs-seeker/SKILL.md +207 -207
  210. package/skills/engineering/docs-seeker/WORKFLOWS.md +505 -505
  211. package/skills/engineering/docs-seeker/references/best-practices.md +632 -632
  212. package/skills/engineering/docs-seeker/references/documentation-sources.md +461 -461
  213. package/skills/engineering/docs-seeker/references/error-handling.md +621 -621
  214. package/skills/engineering/docs-seeker/references/limitations.md +821 -821
  215. package/skills/engineering/docs-seeker/references/performance.md +574 -574
  216. package/skills/engineering/docs-seeker/references/tool-selection.md +262 -262
  217. package/skills/engineering/frontend-development/SKILL.md +398 -398
  218. package/skills/engineering/frontend-development/resources/common-patterns.md +330 -330
  219. package/skills/engineering/frontend-development/resources/complete-examples.md +871 -871
  220. package/skills/engineering/frontend-development/resources/component-patterns.md +501 -501
  221. package/skills/engineering/frontend-development/resources/data-fetching.md +766 -766
  222. package/skills/engineering/frontend-development/resources/file-organization.md +501 -501
  223. package/skills/engineering/frontend-development/resources/loading-and-error-states.md +500 -500
  224. package/skills/engineering/frontend-development/resources/performance.md +405 -405
  225. package/skills/engineering/frontend-development/resources/routing-guide.md +363 -363
  226. package/skills/engineering/frontend-development/resources/styling-guide.md +427 -427
  227. package/skills/engineering/frontend-development/resources/typescript-standards.md +417 -417
  228. package/skills/engineering/improve-codebase-architecture/DEEPENING.md +37 -37
  229. package/skills/engineering/improve-codebase-architecture/INTERFACE-DESIGN.md +44 -44
  230. package/skills/engineering/improve-codebase-architecture/LANGUAGE.md +53 -53
  231. package/skills/engineering/improve-codebase-architecture/SKILL.md +71 -71
  232. package/skills/engineering/openai-docs/LICENSE.txt +201 -201
  233. package/skills/engineering/openai-docs/SKILL.md +69 -69
  234. package/skills/engineering/openai-docs/agents/openai.yaml +14 -14
  235. package/skills/engineering/openai-docs/assets/openai-small.svg +3 -3
  236. package/skills/engineering/openai-docs/references/gpt-5p4-prompting-guide.md +433 -433
  237. package/skills/engineering/openai-docs/references/latest-model.md +35 -35
  238. package/skills/engineering/openai-docs/references/upgrading-to-gpt-5p4.md +164 -164
  239. package/skills/engineering/playwright/LICENSE.txt +201 -201
  240. package/skills/engineering/playwright/NOTICE.txt +14 -14
  241. package/skills/engineering/playwright/SKILL.md +147 -147
  242. package/skills/engineering/playwright/agents/openai.yaml +6 -6
  243. package/skills/engineering/playwright/assets/playwright-small.svg +3 -3
  244. package/skills/engineering/playwright/references/cli.md +116 -116
  245. package/skills/engineering/playwright/references/workflows.md +95 -95
  246. package/skills/engineering/playwright/scripts/playwright_cli.sh +25 -25
  247. package/skills/engineering/playwright-interactive/LICENSE.txt +201 -201
  248. package/skills/engineering/playwright-interactive/NOTICE.txt +13 -13
  249. package/skills/engineering/playwright-interactive/SKILL.md +689 -689
  250. package/skills/engineering/playwright-interactive/agents/openai.yaml +6 -6
  251. package/skills/engineering/playwright-interactive/assets/playwright-small.svg +3 -3
  252. package/skills/engineering/render-deploy/LICENSE.txt +201 -201
  253. package/skills/engineering/render-deploy/SKILL.md +479 -479
  254. package/skills/engineering/render-deploy/agents/openai.yaml +14 -14
  255. package/skills/engineering/render-deploy/assets/docker.yaml +62 -62
  256. package/skills/engineering/render-deploy/assets/go-api.yaml +35 -35
  257. package/skills/engineering/render-deploy/assets/nextjs-postgres.yaml +35 -35
  258. package/skills/engineering/render-deploy/assets/node-express.yaml +25 -25
  259. package/skills/engineering/render-deploy/assets/python-django.yaml +89 -89
  260. package/skills/engineering/render-deploy/assets/render-small.svg +3 -3
  261. package/skills/engineering/render-deploy/assets/static-site.yaml +54 -54
  262. package/skills/engineering/render-deploy/references/blueprint-spec.md +718 -718
  263. package/skills/engineering/render-deploy/references/codebase-analysis.md +49 -49
  264. package/skills/engineering/render-deploy/references/configuration-guide.md +603 -603
  265. package/skills/engineering/render-deploy/references/deployment-details.md +224 -224
  266. package/skills/engineering/render-deploy/references/direct-creation.md +113 -113
  267. package/skills/engineering/render-deploy/references/error-patterns.md +13 -13
  268. package/skills/engineering/render-deploy/references/post-deploy-checks.md +36 -36
  269. package/skills/engineering/render-deploy/references/runtimes.md +473 -473
  270. package/skills/engineering/render-deploy/references/service-types.md +450 -450
  271. package/skills/engineering/render-deploy/references/troubleshooting-basics.md +36 -36
  272. package/skills/engineering/repomix/SKILL.md +215 -215
  273. package/skills/engineering/repomix/references/configuration.md +211 -211
  274. package/skills/engineering/repomix/references/usage-patterns.md +232 -232
  275. package/skills/engineering/repomix/scripts/README.md +179 -179
  276. package/skills/engineering/repomix/scripts/repomix_batch.py +455 -455
  277. package/skills/engineering/repomix/scripts/repos.example.json +15 -15
  278. package/skills/engineering/repomix/scripts/requirements.txt +15 -15
  279. package/skills/engineering/repomix/scripts/tests/test_repomix_batch.py +531 -531
  280. package/skills/engineering/setup-matt-pocock-skills/SKILL.md +121 -121
  281. package/skills/engineering/setup-matt-pocock-skills/domain.md +51 -51
  282. package/skills/engineering/setup-matt-pocock-skills/issue-tracker-github.md +22 -22
  283. package/skills/engineering/setup-matt-pocock-skills/issue-tracker-gitlab.md +23 -23
  284. package/skills/engineering/setup-matt-pocock-skills/issue-tracker-local.md +19 -19
  285. package/skills/engineering/setup-matt-pocock-skills/triage-labels.md +15 -15
  286. package/skills/engineering/shopify/README.md +66 -66
  287. package/skills/engineering/shopify/SKILL.md +319 -319
  288. package/skills/engineering/shopify/references/app-development.md +470 -470
  289. package/skills/engineering/shopify/references/extensions.md +493 -493
  290. package/skills/engineering/shopify/references/themes.md +498 -498
  291. package/skills/engineering/shopify/scripts/requirements.txt +19 -19
  292. package/skills/engineering/shopify/scripts/shopify_init.py +423 -423
  293. package/skills/engineering/shopify/scripts/tests/test_shopify_init.py +385 -385
  294. package/skills/engineering/tdd/SKILL.md +109 -109
  295. package/skills/engineering/tdd/deep-modules.md +33 -33
  296. package/skills/engineering/tdd/interface-design.md +31 -31
  297. package/skills/engineering/tdd/mocking.md +59 -59
  298. package/skills/engineering/tdd/refactoring.md +10 -10
  299. package/skills/engineering/tdd/tests.md +61 -61
  300. package/skills/engineering/to-issues/SKILL.md +81 -81
  301. package/skills/engineering/to-prd/SKILL.md +74 -74
  302. package/skills/engineering/triage/AGENT-BRIEF.md +168 -168
  303. package/skills/engineering/triage/OUT-OF-SCOPE.md +101 -101
  304. package/skills/engineering/triage/SKILL.md +103 -103
  305. package/skills/engineering/web-frameworks/SKILL.md +324 -324
  306. package/skills/engineering/web-frameworks/references/nextjs-app-router.md +465 -465
  307. package/skills/engineering/web-frameworks/references/nextjs-data-fetching.md +459 -459
  308. package/skills/engineering/web-frameworks/references/nextjs-optimization.md +511 -511
  309. package/skills/engineering/web-frameworks/references/nextjs-server-components.md +495 -495
  310. package/skills/engineering/web-frameworks/references/remix-icon-integration.md +603 -603
  311. package/skills/engineering/web-frameworks/references/turborepo-caching.md +551 -551
  312. package/skills/engineering/web-frameworks/references/turborepo-pipelines.md +517 -517
  313. package/skills/engineering/web-frameworks/references/turborepo-setup.md +542 -542
  314. package/skills/engineering/web-frameworks/scripts/nextjs_init.py +547 -547
  315. package/skills/engineering/web-frameworks/scripts/requirements.txt +16 -16
  316. package/skills/engineering/web-frameworks/scripts/tests/requirements.txt +3 -3
  317. package/skills/engineering/web-frameworks/scripts/tests/test_nextjs_init.py +319 -319
  318. package/skills/engineering/web-frameworks/scripts/tests/test_turborepo_migrate.py +374 -374
  319. package/skills/engineering/web-frameworks/scripts/turborepo_migrate.py +394 -394
  320. package/skills/engineering/write-a-skill/SKILL.md +117 -117
  321. package/skills/kilo-kit/SKILL.md +346 -346
  322. package/skills/kilo-kit/_template/SKILL.md +185 -185
  323. package/skills/kilo-kit/debugging/root-cause/SKILL.md +360 -360
  324. package/skills/kilo-kit/debugging/systematic/SKILL.md +339 -339
  325. package/skills/kilo-kit/debugging/verification/SKILL.md +424 -424
  326. package/skills/kilo-kit/development/backend/SKILL.md +540 -540
  327. package/skills/kilo-kit/development/security/SKILL.md +529 -529
  328. package/skills/kilo-kit/quality/code-review/SKILL.md +297 -297
  329. package/skills/kilo-kit/quality/testing/SKILL.md +540 -540
  330. package/skills/kilo-kit/references/output-formats.md +204 -204
  331. package/skills/kilo-kit/references/patterns.md +156 -156
  332. package/skills/kilo-kit/references/performance-benchmarks.md +90 -90
  333. package/skills/operations/chrome-devtools/SKILL.md +392 -392
  334. package/skills/operations/chrome-devtools/references/cdp-domains.md +694 -694
  335. package/skills/operations/chrome-devtools/references/performance-guide.md +940 -940
  336. package/skills/operations/chrome-devtools/references/puppeteer-reference.md +953 -953
  337. package/skills/operations/chrome-devtools/scripts/PERSISTENT-BROWSER.md +107 -107
  338. package/skills/operations/chrome-devtools/scripts/README.md +213 -213
  339. package/skills/operations/chrome-devtools/scripts/__tests__/selector.test.js +210 -210
  340. package/skills/operations/chrome-devtools/scripts/click.js +79 -79
  341. package/skills/operations/chrome-devtools/scripts/close-persistent.js +36 -36
  342. package/skills/operations/chrome-devtools/scripts/console.js +75 -75
  343. package/skills/operations/chrome-devtools/scripts/evaluate.js +49 -49
  344. package/skills/operations/chrome-devtools/scripts/fill.js +72 -72
  345. package/skills/operations/chrome-devtools/scripts/install-deps.sh +181 -181
  346. package/skills/operations/chrome-devtools/scripts/install.sh +83 -83
  347. package/skills/operations/chrome-devtools/scripts/launch-persistent.js +71 -71
  348. package/skills/operations/chrome-devtools/scripts/lib/browser.js +144 -144
  349. package/skills/operations/chrome-devtools/scripts/lib/selector.js +178 -178
  350. package/skills/operations/chrome-devtools/scripts/navigate.js +46 -46
  351. package/skills/operations/chrome-devtools/scripts/network.js +102 -102
  352. package/skills/operations/chrome-devtools/scripts/package-lock.json +1206 -1206
  353. package/skills/operations/chrome-devtools/scripts/package.json +15 -15
  354. package/skills/operations/chrome-devtools/scripts/performance.js +145 -145
  355. package/skills/operations/chrome-devtools/scripts/screenshot.js +180 -180
  356. package/skills/operations/chrome-devtools/scripts/snapshot.js +131 -131
  357. package/skills/operations/devops/.env.example +76 -76
  358. package/skills/operations/devops/SKILL.md +285 -285
  359. package/skills/operations/devops/references/browser-rendering.md +305 -305
  360. package/skills/operations/devops/references/cloudflare-d1-kv.md +123 -123
  361. package/skills/operations/devops/references/cloudflare-platform.md +271 -271
  362. package/skills/operations/devops/references/cloudflare-r2-storage.md +280 -280
  363. package/skills/operations/devops/references/cloudflare-workers-advanced.md +312 -312
  364. package/skills/operations/devops/references/cloudflare-workers-apis.md +309 -309
  365. package/skills/operations/devops/references/cloudflare-workers-basics.md +418 -418
  366. package/skills/operations/devops/references/docker-basics.md +297 -297
  367. package/skills/operations/devops/references/docker-compose.md +292 -292
  368. package/skills/operations/devops/references/gcloud-platform.md +297 -297
  369. package/skills/operations/devops/references/gcloud-services.md +304 -304
  370. package/skills/operations/devops/scripts/cloudflare_deploy.py +269 -269
  371. package/skills/operations/devops/scripts/docker_optimize.py +320 -320
  372. package/skills/operations/devops/scripts/requirements.txt +20 -20
  373. package/skills/operations/devops/scripts/tests/requirements.txt +3 -3
  374. package/skills/operations/devops/scripts/tests/test_cloudflare_deploy.py +285 -285
  375. package/skills/operations/devops/scripts/tests/test_docker_optimize.py +436 -436
  376. package/skills/operations/mcp-builder/LICENSE.txt +201 -201
  377. package/skills/operations/mcp-builder/SKILL.md +328 -328
  378. package/skills/operations/mcp-builder/reference/evaluation.md +601 -601
  379. package/skills/operations/mcp-builder/reference/mcp_best_practices.md +915 -915
  380. package/skills/operations/mcp-builder/reference/node_mcp_server.md +915 -915
  381. package/skills/operations/mcp-builder/reference/python_mcp_server.md +751 -751
  382. package/skills/operations/mcp-builder/scripts/connections.py +151 -151
  383. package/skills/operations/mcp-builder/scripts/evaluation.py +373 -373
  384. package/skills/operations/mcp-builder/scripts/example_evaluation.xml +22 -22
  385. package/skills/operations/mcp-builder/scripts/requirements.txt +2 -2
  386. package/skills/operations/mcp-management/README.md +219 -219
  387. package/skills/operations/mcp-management/SKILL.md +175 -175
  388. package/skills/operations/mcp-management/assets/tools.json +3043 -3043
  389. package/skills/operations/mcp-management/references/configuration.md +114 -114
  390. package/skills/operations/mcp-management/references/gemini-cli-integration.md +201 -201
  391. package/skills/operations/mcp-management/references/mcp-protocol.md +116 -116
  392. package/skills/operations/mcp-management/scripts/.env.example +10 -10
  393. package/skills/operations/mcp-management/scripts/cli.ts +155 -155
  394. package/skills/operations/mcp-management/scripts/dist/analyze-tools.js +70 -70
  395. package/skills/operations/mcp-management/scripts/dist/cli.js +131 -131
  396. package/skills/operations/mcp-management/scripts/dist/mcp-client.js +115 -115
  397. package/skills/operations/mcp-management/scripts/mcp-client.ts +163 -163
  398. package/skills/operations/mcp-management/scripts/package.json +18 -18
  399. package/skills/operations/mcp-management/scripts/tsconfig.json +15 -15
  400. package/skills/problem-solving/collision-zone-thinking/SKILL.md +62 -62
  401. package/skills/problem-solving/defense-in-depth/SKILL.md +130 -130
  402. package/skills/problem-solving/inversion-exercise/SKILL.md +58 -58
  403. package/skills/problem-solving/meta-pattern-recognition/SKILL.md +54 -54
  404. package/skills/problem-solving/root-cause-tracing/SKILL.md +177 -177
  405. package/skills/problem-solving/root-cause-tracing/find-polluter.sh +63 -63
  406. package/skills/problem-solving/scale-game/SKILL.md +63 -63
  407. package/skills/problem-solving/sequential-thinking/README.md +118 -118
  408. package/skills/problem-solving/sequential-thinking/SKILL.md +93 -93
  409. package/skills/problem-solving/sequential-thinking/references/advanced.md +122 -122
  410. package/skills/problem-solving/sequential-thinking/references/examples.md +274 -274
  411. package/skills/problem-solving/simplification-cascades/SKILL.md +76 -76
  412. package/skills/problem-solving/when-stuck/SKILL.md +88 -88
  413. package/skills/productivity/caveman/SKILL.md +49 -49
  414. package/skills/productivity/grill-me/SKILL.md +10 -10
  415. package/skills/productivity/grill-with-docs/ADR-FORMAT.md +47 -47
  416. package/skills/productivity/grill-with-docs/CONTEXT-FORMAT.md +77 -77
  417. package/skills/productivity/grill-with-docs/SKILL.md +88 -88
  418. package/skills/productivity/writing-skills/graphviz-conventions.dot +171 -171
  419. package/skills/productivity/zoom-out/SKILL.md +7 -7
  420. package/skills/writing-docs/doc/LICENSE.txt +201 -201
  421. package/skills/writing-docs/doc/SKILL.md +80 -80
  422. package/skills/writing-docs/doc/agents/openai.yaml +6 -6
  423. package/skills/writing-docs/doc/assets/doc-small.svg +3 -3
  424. package/skills/writing-docs/doc/scripts/render_docx.py +296 -296
  425. package/skills/writing-docs/docx/LICENSE.txt +30 -30
  426. package/skills/writing-docs/docx/SKILL.md +196 -196
  427. package/skills/writing-docs/docx/docx-js.md +349 -349
  428. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -1499
  429. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -146
  430. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -1085
  431. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -11
  432. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -3081
  433. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -23
  434. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -185
  435. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -287
  436. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -1676
  437. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -28
  438. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -144
  439. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -174
  440. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -25
  441. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -18
  442. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -59
  443. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -56
  444. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -195
  445. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -582
  446. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -25
  447. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -4439
  448. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -570
  449. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -509
  450. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -12
  451. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -108
  452. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -96
  453. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -3646
  454. package/skills/writing-docs/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -116
  455. package/skills/writing-docs/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -42
  456. package/skills/writing-docs/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -50
  457. package/skills/writing-docs/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -49
  458. package/skills/writing-docs/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -33
  459. package/skills/writing-docs/docx/ooxml/schemas/mce/mc.xsd +75 -75
  460. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -560
  461. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -67
  462. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -14
  463. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -20
  464. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -13
  465. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -4
  466. package/skills/writing-docs/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -8
  467. package/skills/writing-docs/docx/ooxml/scripts/pack.py +159 -159
  468. package/skills/writing-docs/docx/ooxml/scripts/unpack.py +29 -29
  469. package/skills/writing-docs/docx/ooxml/scripts/validate.py +69 -69
  470. package/skills/writing-docs/docx/ooxml/scripts/validation/__init__.py +15 -15
  471. package/skills/writing-docs/docx/ooxml/scripts/validation/base.py +951 -951
  472. package/skills/writing-docs/docx/ooxml/scripts/validation/docx.py +274 -274
  473. package/skills/writing-docs/docx/ooxml/scripts/validation/pptx.py +315 -315
  474. package/skills/writing-docs/docx/ooxml/scripts/validation/redlining.py +279 -279
  475. package/skills/writing-docs/docx/ooxml.md +609 -609
  476. package/skills/writing-docs/docx/scripts/__init__.py +1 -1
  477. package/skills/writing-docs/docx/scripts/document.py +1276 -1276
  478. package/skills/writing-docs/docx/scripts/templates/comments.xml +2 -2
  479. package/skills/writing-docs/docx/scripts/templates/commentsExtended.xml +2 -2
  480. package/skills/writing-docs/docx/scripts/templates/commentsExtensible.xml +2 -2
  481. package/skills/writing-docs/docx/scripts/templates/commentsIds.xml +2 -2
  482. package/skills/writing-docs/docx/scripts/templates/people.xml +2 -2
  483. package/skills/writing-docs/docx/scripts/utilities.py +374 -374
  484. package/skills/writing-docs/mermaidjs-v11/SKILL.md +115 -115
  485. package/skills/writing-docs/mermaidjs-v11/references/cli-usage.md +228 -228
  486. package/skills/writing-docs/mermaidjs-v11/references/configuration.md +232 -232
  487. package/skills/writing-docs/mermaidjs-v11/references/diagram-types.md +315 -315
  488. package/skills/writing-docs/mermaidjs-v11/references/examples.md +344 -344
  489. package/skills/writing-docs/mermaidjs-v11/references/integration.md +310 -310
  490. package/skills/writing-docs/pdf/LICENSE.txt +30 -30
  491. package/skills/writing-docs/pdf/SKILL.md +294 -294
  492. package/skills/writing-docs/pdf/forms.md +205 -205
  493. package/skills/writing-docs/pdf/reference.md +611 -611
  494. package/skills/writing-docs/pdf/scripts/check_bounding_boxes.py +70 -70
  495. package/skills/writing-docs/pdf/scripts/check_bounding_boxes_test.py +226 -226
  496. package/skills/writing-docs/pdf/scripts/check_fillable_fields.py +12 -12
  497. package/skills/writing-docs/pdf/scripts/convert_pdf_to_images.py +35 -35
  498. package/skills/writing-docs/pdf/scripts/create_validation_image.py +41 -41
  499. package/skills/writing-docs/pdf/scripts/extract_form_field_info.py +152 -152
  500. package/skills/writing-docs/pdf/scripts/fill_fillable_fields.py +114 -114
  501. package/skills/writing-docs/pdf/scripts/fill_pdf_form_with_annotations.py +107 -107
  502. package/skills/writing-docs/pptx/LICENSE.txt +30 -30
  503. package/skills/writing-docs/pptx/SKILL.md +483 -483
  504. package/skills/writing-docs/pptx/html2pptx.md +624 -624
  505. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -1499
  506. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -146
  507. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -1085
  508. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -11
  509. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -3081
  510. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -23
  511. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -185
  512. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -287
  513. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -1676
  514. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -28
  515. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -144
  516. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -174
  517. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -25
  518. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -18
  519. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -59
  520. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -56
  521. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -195
  522. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -582
  523. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -25
  524. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -4439
  525. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -570
  526. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -509
  527. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -12
  528. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -108
  529. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -96
  530. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -3646
  531. package/skills/writing-docs/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -116
  532. package/skills/writing-docs/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -42
  533. package/skills/writing-docs/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -50
  534. package/skills/writing-docs/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -49
  535. package/skills/writing-docs/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -33
  536. package/skills/writing-docs/pptx/ooxml/schemas/mce/mc.xsd +75 -75
  537. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -560
  538. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -67
  539. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -14
  540. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -20
  541. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -13
  542. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -4
  543. package/skills/writing-docs/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -8
  544. package/skills/writing-docs/pptx/ooxml/scripts/pack.py +159 -159
  545. package/skills/writing-docs/pptx/ooxml/scripts/unpack.py +29 -29
  546. package/skills/writing-docs/pptx/ooxml/scripts/validate.py +69 -69
  547. package/skills/writing-docs/pptx/ooxml/scripts/validation/__init__.py +15 -15
  548. package/skills/writing-docs/pptx/ooxml/scripts/validation/base.py +951 -951
  549. package/skills/writing-docs/pptx/ooxml/scripts/validation/docx.py +274 -274
  550. package/skills/writing-docs/pptx/ooxml/scripts/validation/pptx.py +315 -315
  551. package/skills/writing-docs/pptx/ooxml/scripts/validation/redlining.py +279 -279
  552. package/skills/writing-docs/pptx/ooxml.md +426 -426
  553. package/skills/writing-docs/pptx/scripts/html2pptx.js +978 -978
  554. package/skills/writing-docs/pptx/scripts/inventory.py +1020 -1020
  555. package/skills/writing-docs/pptx/scripts/rearrange.py +231 -231
  556. package/skills/writing-docs/pptx/scripts/replace.py +385 -385
  557. package/skills/writing-docs/pptx/scripts/thumbnail.py +450 -450
  558. package/skills/writing-docs/slides/LICENSE.txt +201 -201
  559. package/skills/writing-docs/slides/SKILL.md +71 -71
  560. package/skills/writing-docs/slides/agents/openai.yaml +6 -6
  561. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/code.js +104 -104
  562. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/image.js +333 -333
  563. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/index.js +33 -33
  564. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/latex.js +51 -51
  565. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/layout.js +643 -643
  566. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/layout_builders.js +358 -358
  567. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/svg.js +36 -36
  568. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/text.js +789 -789
  569. package/skills/writing-docs/slides/assets/pptxgenjs_helpers/util.js +24 -24
  570. package/skills/writing-docs/slides/assets/slides-small.svg +3 -3
  571. package/skills/writing-docs/slides/references/pptxgenjs-helpers.md +61 -61
  572. package/skills/writing-docs/slides/scripts/create_montage.py +300 -300
  573. package/skills/writing-docs/slides/scripts/detect_font.py +873 -873
  574. package/skills/writing-docs/slides/scripts/ensure_raster_image.py +202 -202
  575. package/skills/writing-docs/slides/scripts/render_slides.py +273 -273
  576. package/skills/writing-docs/slides/scripts/slides_test.py +201 -201
  577. package/skills/writing-docs/template-skill/SKILL.md +26 -26
  578. package/skills/writing-docs/xlsx/LICENSE.txt +30 -30
  579. package/skills/writing-docs/xlsx/SKILL.md +288 -288
  580. package/skills/writing-docs/xlsx/recalc.py +177 -177
  581. package/src/core/KILO_MASTER.md +448 -448
  582. package/src/tools/validate-skill.js +421 -421
@@ -1,1020 +1,1020 @@
1
- #!/usr/bin/env python3
2
- """
3
- Extract structured text content from PowerPoint presentations.
4
-
5
- This module provides functionality to:
6
- - Extract all text content from PowerPoint shapes
7
- - Preserve paragraph formatting (alignment, bullets, fonts, spacing)
8
- - Handle nested GroupShapes recursively with correct absolute positions
9
- - Sort shapes by visual position on slides
10
- - Filter out slide numbers and non-content placeholders
11
- - Export to JSON with clean, structured data
12
-
13
- Classes:
14
- ParagraphData: Represents a text paragraph with formatting
15
- ShapeData: Represents a shape with position and text content
16
-
17
- Main Functions:
18
- extract_text_inventory: Extract all text from a presentation
19
- save_inventory: Save extracted data to JSON
20
-
21
- Usage:
22
- python inventory.py input.pptx output.json
23
- """
24
-
25
- import argparse
26
- import json
27
- import platform
28
- import sys
29
- from dataclasses import dataclass
30
- from pathlib import Path
31
- from typing import Any, Dict, List, Optional, Tuple, Union
32
-
33
- from PIL import Image, ImageDraw, ImageFont
34
- from pptx import Presentation
35
- from pptx.enum.text import PP_ALIGN
36
- from pptx.shapes.base import BaseShape
37
-
38
- # Type aliases for cleaner signatures
39
- JsonValue = Union[str, int, float, bool, None]
40
- ParagraphDict = Dict[str, JsonValue]
41
- ShapeDict = Dict[
42
- str, Union[str, float, bool, List[ParagraphDict], List[str], Dict[str, Any], None]
43
- ]
44
- InventoryData = Dict[
45
- str, Dict[str, "ShapeData"]
46
- ] # Dict of slide_id -> {shape_id -> ShapeData}
47
- InventoryDict = Dict[str, Dict[str, ShapeDict]] # JSON-serializable inventory
48
-
49
-
50
- def main():
51
- """Main entry point for command-line usage."""
52
- parser = argparse.ArgumentParser(
53
- description="Extract text inventory from PowerPoint with proper GroupShape support.",
54
- formatter_class=argparse.RawDescriptionHelpFormatter,
55
- epilog="""
56
- Examples:
57
- python inventory.py presentation.pptx inventory.json
58
- Extracts text inventory with correct absolute positions for grouped shapes
59
-
60
- python inventory.py presentation.pptx inventory.json --issues-only
61
- Extracts only text shapes that have overflow or overlap issues
62
-
63
- The output JSON includes:
64
- - All text content organized by slide and shape
65
- - Correct absolute positions for shapes in groups
66
- - Visual position and size in inches
67
- - Paragraph properties and formatting
68
- - Issue detection: text overflow and shape overlaps
69
- """,
70
- )
71
-
72
- parser.add_argument("input", help="Input PowerPoint file (.pptx)")
73
- parser.add_argument("output", help="Output JSON file for inventory")
74
- parser.add_argument(
75
- "--issues-only",
76
- action="store_true",
77
- help="Include only text shapes that have overflow or overlap issues",
78
- )
79
-
80
- args = parser.parse_args()
81
-
82
- input_path = Path(args.input)
83
- if not input_path.exists():
84
- print(f"Error: Input file not found: {args.input}")
85
- sys.exit(1)
86
-
87
- if not input_path.suffix.lower() == ".pptx":
88
- print("Error: Input must be a PowerPoint file (.pptx)")
89
- sys.exit(1)
90
-
91
- try:
92
- print(f"Extracting text inventory from: {args.input}")
93
- if args.issues_only:
94
- print(
95
- "Filtering to include only text shapes with issues (overflow/overlap)"
96
- )
97
- inventory = extract_text_inventory(input_path, issues_only=args.issues_only)
98
-
99
- output_path = Path(args.output)
100
- output_path.parent.mkdir(parents=True, exist_ok=True)
101
- save_inventory(inventory, output_path)
102
-
103
- print(f"Output saved to: {args.output}")
104
-
105
- # Report statistics
106
- total_slides = len(inventory)
107
- total_shapes = sum(len(shapes) for shapes in inventory.values())
108
- if args.issues_only:
109
- if total_shapes > 0:
110
- print(
111
- f"Found {total_shapes} text elements with issues in {total_slides} slides"
112
- )
113
- else:
114
- print("No issues discovered")
115
- else:
116
- print(
117
- f"Found text in {total_slides} slides with {total_shapes} text elements"
118
- )
119
-
120
- except Exception as e:
121
- print(f"Error processing presentation: {e}")
122
- import traceback
123
-
124
- traceback.print_exc()
125
- sys.exit(1)
126
-
127
-
128
- @dataclass
129
- class ShapeWithPosition:
130
- """A shape with its absolute position on the slide."""
131
-
132
- shape: BaseShape
133
- absolute_left: int # in EMUs
134
- absolute_top: int # in EMUs
135
-
136
-
137
- class ParagraphData:
138
- """Data structure for paragraph properties extracted from a PowerPoint paragraph."""
139
-
140
- def __init__(self, paragraph: Any):
141
- """Initialize from a PowerPoint paragraph object.
142
-
143
- Args:
144
- paragraph: The PowerPoint paragraph object
145
- """
146
- self.text: str = paragraph.text.strip()
147
- self.bullet: bool = False
148
- self.level: Optional[int] = None
149
- self.alignment: Optional[str] = None
150
- self.space_before: Optional[float] = None
151
- self.space_after: Optional[float] = None
152
- self.font_name: Optional[str] = None
153
- self.font_size: Optional[float] = None
154
- self.bold: Optional[bool] = None
155
- self.italic: Optional[bool] = None
156
- self.underline: Optional[bool] = None
157
- self.color: Optional[str] = None
158
- self.theme_color: Optional[str] = None
159
- self.line_spacing: Optional[float] = None
160
-
161
- # Check for bullet formatting
162
- if (
163
- hasattr(paragraph, "_p")
164
- and paragraph._p is not None
165
- and paragraph._p.pPr is not None
166
- ):
167
- pPr = paragraph._p.pPr
168
- ns = "{http://schemas.openxmlformats.org/drawingml/2006/main}"
169
- if (
170
- pPr.find(f"{ns}buChar") is not None
171
- or pPr.find(f"{ns}buAutoNum") is not None
172
- ):
173
- self.bullet = True
174
- if hasattr(paragraph, "level"):
175
- self.level = paragraph.level
176
-
177
- # Add alignment if not LEFT (default)
178
- if hasattr(paragraph, "alignment") and paragraph.alignment is not None:
179
- alignment_map = {
180
- PP_ALIGN.CENTER: "CENTER",
181
- PP_ALIGN.RIGHT: "RIGHT",
182
- PP_ALIGN.JUSTIFY: "JUSTIFY",
183
- }
184
- if paragraph.alignment in alignment_map:
185
- self.alignment = alignment_map[paragraph.alignment]
186
-
187
- # Add spacing properties if set
188
- if hasattr(paragraph, "space_before") and paragraph.space_before:
189
- self.space_before = paragraph.space_before.pt
190
- if hasattr(paragraph, "space_after") and paragraph.space_after:
191
- self.space_after = paragraph.space_after.pt
192
-
193
- # Extract font properties from first run
194
- if paragraph.runs:
195
- first_run = paragraph.runs[0]
196
- if hasattr(first_run, "font"):
197
- font = first_run.font
198
- if font.name:
199
- self.font_name = font.name
200
- if font.size:
201
- self.font_size = font.size.pt
202
- if font.bold is not None:
203
- self.bold = font.bold
204
- if font.italic is not None:
205
- self.italic = font.italic
206
- if font.underline is not None:
207
- self.underline = font.underline
208
-
209
- # Handle color - both RGB and theme colors
210
- try:
211
- # Try RGB color first
212
- if font.color.rgb:
213
- self.color = str(font.color.rgb)
214
- except (AttributeError, TypeError):
215
- # Fall back to theme color
216
- try:
217
- if font.color.theme_color:
218
- self.theme_color = font.color.theme_color.name
219
- except (AttributeError, TypeError):
220
- pass
221
-
222
- # Add line spacing if set
223
- if hasattr(paragraph, "line_spacing") and paragraph.line_spacing is not None:
224
- if hasattr(paragraph.line_spacing, "pt"):
225
- self.line_spacing = round(paragraph.line_spacing.pt, 2)
226
- else:
227
- # Multiplier - convert to points
228
- font_size = self.font_size if self.font_size else 12.0
229
- self.line_spacing = round(paragraph.line_spacing * font_size, 2)
230
-
231
- def to_dict(self) -> ParagraphDict:
232
- """Convert to dictionary for JSON serialization, excluding None values."""
233
- result: ParagraphDict = {"text": self.text}
234
-
235
- # Add optional fields only if they have values
236
- if self.bullet:
237
- result["bullet"] = self.bullet
238
- if self.level is not None:
239
- result["level"] = self.level
240
- if self.alignment:
241
- result["alignment"] = self.alignment
242
- if self.space_before is not None:
243
- result["space_before"] = self.space_before
244
- if self.space_after is not None:
245
- result["space_after"] = self.space_after
246
- if self.font_name:
247
- result["font_name"] = self.font_name
248
- if self.font_size is not None:
249
- result["font_size"] = self.font_size
250
- if self.bold is not None:
251
- result["bold"] = self.bold
252
- if self.italic is not None:
253
- result["italic"] = self.italic
254
- if self.underline is not None:
255
- result["underline"] = self.underline
256
- if self.color:
257
- result["color"] = self.color
258
- if self.theme_color:
259
- result["theme_color"] = self.theme_color
260
- if self.line_spacing is not None:
261
- result["line_spacing"] = self.line_spacing
262
-
263
- return result
264
-
265
-
266
- class ShapeData:
267
- """Data structure for shape properties extracted from a PowerPoint shape."""
268
-
269
- @staticmethod
270
- def emu_to_inches(emu: int) -> float:
271
- """Convert EMUs (English Metric Units) to inches."""
272
- return emu / 914400.0
273
-
274
- @staticmethod
275
- def inches_to_pixels(inches: float, dpi: int = 96) -> int:
276
- """Convert inches to pixels at given DPI."""
277
- return int(inches * dpi)
278
-
279
- @staticmethod
280
- def get_font_path(font_name: str) -> Optional[str]:
281
- """Get the font file path for a given font name.
282
-
283
- Args:
284
- font_name: Name of the font (e.g., 'Arial', 'Calibri')
285
-
286
- Returns:
287
- Path to the font file, or None if not found
288
- """
289
- system = platform.system()
290
-
291
- # Common font file variations to try
292
- font_variations = [
293
- font_name,
294
- font_name.lower(),
295
- font_name.replace(" ", ""),
296
- font_name.replace(" ", "-"),
297
- ]
298
-
299
- # Define font directories and extensions by platform
300
- if system == "Darwin": # macOS
301
- font_dirs = [
302
- "/System/Library/Fonts/",
303
- "/Library/Fonts/",
304
- "~/Library/Fonts/",
305
- ]
306
- extensions = [".ttf", ".otf", ".ttc", ".dfont"]
307
- else: # Linux
308
- font_dirs = [
309
- "/usr/share/fonts/truetype/",
310
- "/usr/local/share/fonts/",
311
- "~/.fonts/",
312
- ]
313
- extensions = [".ttf", ".otf"]
314
-
315
- # Try to find the font file
316
- from pathlib import Path
317
-
318
- for font_dir in font_dirs:
319
- font_dir_path = Path(font_dir).expanduser()
320
- if not font_dir_path.exists():
321
- continue
322
-
323
- # First try exact matches
324
- for variant in font_variations:
325
- for ext in extensions:
326
- font_path = font_dir_path / f"{variant}{ext}"
327
- if font_path.exists():
328
- return str(font_path)
329
-
330
- # Then try fuzzy matching - find files containing the font name
331
- try:
332
- for file_path in font_dir_path.iterdir():
333
- if file_path.is_file():
334
- file_name_lower = file_path.name.lower()
335
- font_name_lower = font_name.lower().replace(" ", "")
336
- if font_name_lower in file_name_lower and any(
337
- file_name_lower.endswith(ext) for ext in extensions
338
- ):
339
- return str(file_path)
340
- except (OSError, PermissionError):
341
- continue
342
-
343
- return None
344
-
345
- @staticmethod
346
- def get_slide_dimensions(slide: Any) -> tuple[Optional[int], Optional[int]]:
347
- """Get slide dimensions from slide object.
348
-
349
- Args:
350
- slide: Slide object
351
-
352
- Returns:
353
- Tuple of (width_emu, height_emu) or (None, None) if not found
354
- """
355
- try:
356
- prs = slide.part.package.presentation_part.presentation
357
- return prs.slide_width, prs.slide_height
358
- except (AttributeError, TypeError):
359
- return None, None
360
-
361
- @staticmethod
362
- def get_default_font_size(shape: BaseShape, slide_layout: Any) -> Optional[float]:
363
- """Extract default font size from slide layout for a placeholder shape.
364
-
365
- Args:
366
- shape: Placeholder shape
367
- slide_layout: Slide layout containing the placeholder definition
368
-
369
- Returns:
370
- Default font size in points, or None if not found
371
- """
372
- try:
373
- if not hasattr(shape, "placeholder_format"):
374
- return None
375
-
376
- shape_type = shape.placeholder_format.type # type: ignore
377
- for layout_placeholder in slide_layout.placeholders:
378
- if layout_placeholder.placeholder_format.type == shape_type:
379
- # Find first defRPr element with sz (size) attribute
380
- for elem in layout_placeholder.element.iter():
381
- if "defRPr" in elem.tag and (sz := elem.get("sz")):
382
- return float(sz) / 100.0 # Convert EMUs to points
383
- break
384
- except Exception:
385
- pass
386
- return None
387
-
388
- def __init__(
389
- self,
390
- shape: BaseShape,
391
- absolute_left: Optional[int] = None,
392
- absolute_top: Optional[int] = None,
393
- slide: Optional[Any] = None,
394
- ):
395
- """Initialize from a PowerPoint shape object.
396
-
397
- Args:
398
- shape: The PowerPoint shape object (should be pre-validated)
399
- absolute_left: Absolute left position in EMUs (for shapes in groups)
400
- absolute_top: Absolute top position in EMUs (for shapes in groups)
401
- slide: Optional slide object to get dimensions and layout information
402
- """
403
- self.shape = shape # Store reference to original shape
404
- self.shape_id: str = "" # Will be set after sorting
405
-
406
- # Get slide dimensions from slide object
407
- self.slide_width_emu, self.slide_height_emu = (
408
- self.get_slide_dimensions(slide) if slide else (None, None)
409
- )
410
-
411
- # Get placeholder type if applicable
412
- self.placeholder_type: Optional[str] = None
413
- self.default_font_size: Optional[float] = None
414
- if hasattr(shape, "is_placeholder") and shape.is_placeholder: # type: ignore
415
- if shape.placeholder_format and shape.placeholder_format.type: # type: ignore
416
- self.placeholder_type = (
417
- str(shape.placeholder_format.type).split(".")[-1].split(" ")[0] # type: ignore
418
- )
419
-
420
- # Get default font size from layout
421
- if slide and hasattr(slide, "slide_layout"):
422
- self.default_font_size = self.get_default_font_size(
423
- shape, slide.slide_layout
424
- )
425
-
426
- # Get position information
427
- # Use absolute positions if provided (for shapes in groups), otherwise use shape's position
428
- left_emu = (
429
- absolute_left
430
- if absolute_left is not None
431
- else (shape.left if hasattr(shape, "left") else 0)
432
- )
433
- top_emu = (
434
- absolute_top
435
- if absolute_top is not None
436
- else (shape.top if hasattr(shape, "top") else 0)
437
- )
438
-
439
- self.left: float = round(self.emu_to_inches(left_emu), 2) # type: ignore
440
- self.top: float = round(self.emu_to_inches(top_emu), 2) # type: ignore
441
- self.width: float = round(
442
- self.emu_to_inches(shape.width if hasattr(shape, "width") else 0),
443
- 2, # type: ignore
444
- )
445
- self.height: float = round(
446
- self.emu_to_inches(shape.height if hasattr(shape, "height") else 0),
447
- 2, # type: ignore
448
- )
449
-
450
- # Store EMU positions for overflow calculations
451
- self.left_emu = left_emu
452
- self.top_emu = top_emu
453
- self.width_emu = shape.width if hasattr(shape, "width") else 0
454
- self.height_emu = shape.height if hasattr(shape, "height") else 0
455
-
456
- # Calculate overflow status
457
- self.frame_overflow_bottom: Optional[float] = None
458
- self.slide_overflow_right: Optional[float] = None
459
- self.slide_overflow_bottom: Optional[float] = None
460
- self.overlapping_shapes: Dict[
461
- str, float
462
- ] = {} # Dict of shape_id -> overlap area in sq inches
463
- self.warnings: List[str] = []
464
- self._estimate_frame_overflow()
465
- self._calculate_slide_overflow()
466
- self._detect_bullet_issues()
467
-
468
- @property
469
- def paragraphs(self) -> List[ParagraphData]:
470
- """Calculate paragraphs from the shape's text frame."""
471
- if not self.shape or not hasattr(self.shape, "text_frame"):
472
- return []
473
-
474
- paragraphs = []
475
- for paragraph in self.shape.text_frame.paragraphs: # type: ignore
476
- if paragraph.text.strip():
477
- paragraphs.append(ParagraphData(paragraph))
478
- return paragraphs
479
-
480
- def _get_default_font_size(self) -> int:
481
- """Get default font size from theme text styles or use conservative default."""
482
- try:
483
- if not (
484
- hasattr(self.shape, "part") and hasattr(self.shape.part, "slide_layout")
485
- ):
486
- return 14
487
-
488
- slide_master = self.shape.part.slide_layout.slide_master # type: ignore
489
- if not hasattr(slide_master, "element"):
490
- return 14
491
-
492
- # Determine theme style based on placeholder type
493
- style_name = "bodyStyle" # Default
494
- if self.placeholder_type and "TITLE" in self.placeholder_type:
495
- style_name = "titleStyle"
496
-
497
- # Find font size in theme styles
498
- for child in slide_master.element.iter():
499
- tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
500
- if tag == style_name:
501
- for elem in child.iter():
502
- if "sz" in elem.attrib:
503
- return int(elem.attrib["sz"]) // 100
504
- except Exception:
505
- pass
506
-
507
- return 14 # Conservative default for body text
508
-
509
- def _get_usable_dimensions(self, text_frame) -> Tuple[int, int]:
510
- """Get usable width and height in pixels after accounting for margins."""
511
- # Default PowerPoint margins in inches
512
- margins = {"top": 0.05, "bottom": 0.05, "left": 0.1, "right": 0.1}
513
-
514
- # Override with actual margins if set
515
- if hasattr(text_frame, "margin_top") and text_frame.margin_top:
516
- margins["top"] = self.emu_to_inches(text_frame.margin_top)
517
- if hasattr(text_frame, "margin_bottom") and text_frame.margin_bottom:
518
- margins["bottom"] = self.emu_to_inches(text_frame.margin_bottom)
519
- if hasattr(text_frame, "margin_left") and text_frame.margin_left:
520
- margins["left"] = self.emu_to_inches(text_frame.margin_left)
521
- if hasattr(text_frame, "margin_right") and text_frame.margin_right:
522
- margins["right"] = self.emu_to_inches(text_frame.margin_right)
523
-
524
- # Calculate usable area
525
- usable_width = self.width - margins["left"] - margins["right"]
526
- usable_height = self.height - margins["top"] - margins["bottom"]
527
-
528
- # Convert to pixels
529
- return (
530
- self.inches_to_pixels(usable_width),
531
- self.inches_to_pixels(usable_height),
532
- )
533
-
534
- def _wrap_text_line(self, line: str, max_width_px: int, draw, font) -> List[str]:
535
- """Wrap a single line of text to fit within max_width_px."""
536
- if not line:
537
- return [""]
538
-
539
- # Use textlength for efficient width calculation
540
- if draw.textlength(line, font=font) <= max_width_px:
541
- return [line]
542
-
543
- # Need to wrap - split into words
544
- wrapped = []
545
- words = line.split(" ")
546
- current_line = ""
547
-
548
- for word in words:
549
- test_line = current_line + (" " if current_line else "") + word
550
- if draw.textlength(test_line, font=font) <= max_width_px:
551
- current_line = test_line
552
- else:
553
- if current_line:
554
- wrapped.append(current_line)
555
- current_line = word
556
-
557
- if current_line:
558
- wrapped.append(current_line)
559
-
560
- return wrapped
561
-
562
- def _estimate_frame_overflow(self) -> None:
563
- """Estimate if text overflows the shape bounds using PIL text measurement."""
564
- if not self.shape or not hasattr(self.shape, "text_frame"):
565
- return
566
-
567
- text_frame = self.shape.text_frame # type: ignore
568
- if not text_frame or not text_frame.paragraphs:
569
- return
570
-
571
- # Get usable dimensions after accounting for margins
572
- usable_width_px, usable_height_px = self._get_usable_dimensions(text_frame)
573
- if usable_width_px <= 0 or usable_height_px <= 0:
574
- return
575
-
576
- # Set up PIL for text measurement
577
- dummy_img = Image.new("RGB", (1, 1))
578
- draw = ImageDraw.Draw(dummy_img)
579
-
580
- # Get default font size from placeholder or use conservative estimate
581
- default_font_size = self._get_default_font_size()
582
-
583
- # Calculate total height of all paragraphs
584
- total_height_px = 0
585
-
586
- for para_idx, paragraph in enumerate(text_frame.paragraphs):
587
- if not paragraph.text.strip():
588
- continue
589
-
590
- para_data = ParagraphData(paragraph)
591
-
592
- # Load font for this paragraph
593
- font_name = para_data.font_name or "Arial"
594
- font_size = int(para_data.font_size or default_font_size)
595
-
596
- font = None
597
- font_path = self.get_font_path(font_name)
598
- if font_path:
599
- try:
600
- font = ImageFont.truetype(font_path, size=font_size)
601
- except Exception:
602
- font = ImageFont.load_default()
603
- else:
604
- font = ImageFont.load_default()
605
-
606
- # Wrap all lines in this paragraph
607
- all_wrapped_lines = []
608
- for line in paragraph.text.split("\n"):
609
- wrapped = self._wrap_text_line(line, usable_width_px, draw, font)
610
- all_wrapped_lines.extend(wrapped)
611
-
612
- if all_wrapped_lines:
613
- # Calculate line height
614
- if para_data.line_spacing:
615
- # Custom line spacing explicitly set
616
- line_height_px = para_data.line_spacing * 96 / 72
617
- else:
618
- # PowerPoint default single spacing (1.0x font size)
619
- line_height_px = font_size * 96 / 72
620
-
621
- # Add space_before (except first paragraph)
622
- if para_idx > 0 and para_data.space_before:
623
- total_height_px += para_data.space_before * 96 / 72
624
-
625
- # Add paragraph text height
626
- total_height_px += len(all_wrapped_lines) * line_height_px
627
-
628
- # Add space_after
629
- if para_data.space_after:
630
- total_height_px += para_data.space_after * 96 / 72
631
-
632
- # Check for overflow (ignore negligible overflows <= 0.05")
633
- if total_height_px > usable_height_px:
634
- overflow_px = total_height_px - usable_height_px
635
- overflow_inches = round(overflow_px / 96.0, 2)
636
- if overflow_inches > 0.05: # Only report significant overflows
637
- self.frame_overflow_bottom = overflow_inches
638
-
639
- def _calculate_slide_overflow(self) -> None:
640
- """Calculate if shape overflows the slide boundaries."""
641
- if self.slide_width_emu is None or self.slide_height_emu is None:
642
- return
643
-
644
- # Check right overflow (ignore negligible overflows <= 0.01")
645
- right_edge_emu = self.left_emu + self.width_emu
646
- if right_edge_emu > self.slide_width_emu:
647
- overflow_emu = right_edge_emu - self.slide_width_emu
648
- overflow_inches = round(self.emu_to_inches(overflow_emu), 2)
649
- if overflow_inches > 0.01: # Only report significant overflows
650
- self.slide_overflow_right = overflow_inches
651
-
652
- # Check bottom overflow (ignore negligible overflows <= 0.01")
653
- bottom_edge_emu = self.top_emu + self.height_emu
654
- if bottom_edge_emu > self.slide_height_emu:
655
- overflow_emu = bottom_edge_emu - self.slide_height_emu
656
- overflow_inches = round(self.emu_to_inches(overflow_emu), 2)
657
- if overflow_inches > 0.01: # Only report significant overflows
658
- self.slide_overflow_bottom = overflow_inches
659
-
660
- def _detect_bullet_issues(self) -> None:
661
- """Detect bullet point formatting issues in paragraphs."""
662
- if not self.shape or not hasattr(self.shape, "text_frame"):
663
- return
664
-
665
- text_frame = self.shape.text_frame # type: ignore
666
- if not text_frame or not text_frame.paragraphs:
667
- return
668
-
669
- # Common bullet symbols that indicate manual bullets
670
- bullet_symbols = ["•", "●", "○"]
671
-
672
- for paragraph in text_frame.paragraphs:
673
- text = paragraph.text.strip()
674
- # Check for manual bullet symbols
675
- if text and any(text.startswith(symbol + " ") for symbol in bullet_symbols):
676
- self.warnings.append(
677
- "manual_bullet_symbol: use proper bullet formatting"
678
- )
679
- break
680
-
681
- @property
682
- def has_any_issues(self) -> bool:
683
- """Check if shape has any issues (overflow, overlap, or warnings)."""
684
- return (
685
- self.frame_overflow_bottom is not None
686
- or self.slide_overflow_right is not None
687
- or self.slide_overflow_bottom is not None
688
- or len(self.overlapping_shapes) > 0
689
- or len(self.warnings) > 0
690
- )
691
-
692
- def to_dict(self) -> ShapeDict:
693
- """Convert to dictionary for JSON serialization."""
694
- result: ShapeDict = {
695
- "left": self.left,
696
- "top": self.top,
697
- "width": self.width,
698
- "height": self.height,
699
- }
700
-
701
- # Add optional fields if present
702
- if self.placeholder_type:
703
- result["placeholder_type"] = self.placeholder_type
704
-
705
- if self.default_font_size:
706
- result["default_font_size"] = self.default_font_size
707
-
708
- # Add overflow information only if there is overflow
709
- overflow_data = {}
710
-
711
- # Add frame overflow if present
712
- if self.frame_overflow_bottom is not None:
713
- overflow_data["frame"] = {"overflow_bottom": self.frame_overflow_bottom}
714
-
715
- # Add slide overflow if present
716
- slide_overflow = {}
717
- if self.slide_overflow_right is not None:
718
- slide_overflow["overflow_right"] = self.slide_overflow_right
719
- if self.slide_overflow_bottom is not None:
720
- slide_overflow["overflow_bottom"] = self.slide_overflow_bottom
721
- if slide_overflow:
722
- overflow_data["slide"] = slide_overflow
723
-
724
- # Only add overflow field if there is overflow
725
- if overflow_data:
726
- result["overflow"] = overflow_data
727
-
728
- # Add overlap field if there are overlapping shapes
729
- if self.overlapping_shapes:
730
- result["overlap"] = {"overlapping_shapes": self.overlapping_shapes}
731
-
732
- # Add warnings field if there are warnings
733
- if self.warnings:
734
- result["warnings"] = self.warnings
735
-
736
- # Add paragraphs after placeholder_type
737
- result["paragraphs"] = [para.to_dict() for para in self.paragraphs]
738
-
739
- return result
740
-
741
-
742
- def is_valid_shape(shape: BaseShape) -> bool:
743
- """Check if a shape contains meaningful text content."""
744
- # Must have a text frame with content
745
- if not hasattr(shape, "text_frame") or not shape.text_frame: # type: ignore
746
- return False
747
-
748
- text = shape.text_frame.text.strip() # type: ignore
749
- if not text:
750
- return False
751
-
752
- # Skip slide numbers and numeric footers
753
- if hasattr(shape, "is_placeholder") and shape.is_placeholder: # type: ignore
754
- if shape.placeholder_format and shape.placeholder_format.type: # type: ignore
755
- placeholder_type = (
756
- str(shape.placeholder_format.type).split(".")[-1].split(" ")[0] # type: ignore
757
- )
758
- if placeholder_type == "SLIDE_NUMBER":
759
- return False
760
- if placeholder_type == "FOOTER" and text.isdigit():
761
- return False
762
-
763
- return True
764
-
765
-
766
- def collect_shapes_with_absolute_positions(
767
- shape: BaseShape, parent_left: int = 0, parent_top: int = 0
768
- ) -> List[ShapeWithPosition]:
769
- """Recursively collect all shapes with valid text, calculating absolute positions.
770
-
771
- For shapes within groups, their positions are relative to the group.
772
- This function calculates the absolute position on the slide by accumulating
773
- parent group offsets.
774
-
775
- Args:
776
- shape: The shape to process
777
- parent_left: Accumulated left offset from parent groups (in EMUs)
778
- parent_top: Accumulated top offset from parent groups (in EMUs)
779
-
780
- Returns:
781
- List of ShapeWithPosition objects with absolute positions
782
- """
783
- if hasattr(shape, "shapes"): # GroupShape
784
- result = []
785
- # Get this group's position
786
- group_left = shape.left if hasattr(shape, "left") else 0
787
- group_top = shape.top if hasattr(shape, "top") else 0
788
-
789
- # Calculate absolute position for this group
790
- abs_group_left = parent_left + group_left
791
- abs_group_top = parent_top + group_top
792
-
793
- # Process children with accumulated offsets
794
- for child in shape.shapes: # type: ignore
795
- result.extend(
796
- collect_shapes_with_absolute_positions(
797
- child, abs_group_left, abs_group_top
798
- )
799
- )
800
- return result
801
-
802
- # Regular shape - check if it has valid text
803
- if is_valid_shape(shape):
804
- # Calculate absolute position
805
- shape_left = shape.left if hasattr(shape, "left") else 0
806
- shape_top = shape.top if hasattr(shape, "top") else 0
807
-
808
- return [
809
- ShapeWithPosition(
810
- shape=shape,
811
- absolute_left=parent_left + shape_left,
812
- absolute_top=parent_top + shape_top,
813
- )
814
- ]
815
-
816
- return []
817
-
818
-
819
- def sort_shapes_by_position(shapes: List[ShapeData]) -> List[ShapeData]:
820
- """Sort shapes by visual position (top-to-bottom, left-to-right).
821
-
822
- Shapes within 0.5 inches vertically are considered on the same row.
823
- """
824
- if not shapes:
825
- return shapes
826
-
827
- # Sort by top position first
828
- shapes = sorted(shapes, key=lambda s: (s.top, s.left))
829
-
830
- # Group shapes by row (within 0.5 inches vertically)
831
- result = []
832
- row = [shapes[0]]
833
- row_top = shapes[0].top
834
-
835
- for shape in shapes[1:]:
836
- if abs(shape.top - row_top) <= 0.5:
837
- row.append(shape)
838
- else:
839
- # Sort current row by left position and add to result
840
- result.extend(sorted(row, key=lambda s: s.left))
841
- row = [shape]
842
- row_top = shape.top
843
-
844
- # Don't forget the last row
845
- result.extend(sorted(row, key=lambda s: s.left))
846
- return result
847
-
848
-
849
- def calculate_overlap(
850
- rect1: Tuple[float, float, float, float],
851
- rect2: Tuple[float, float, float, float],
852
- tolerance: float = 0.05,
853
- ) -> Tuple[bool, float]:
854
- """Calculate if and how much two rectangles overlap.
855
-
856
- Args:
857
- rect1: (left, top, width, height) of first rectangle in inches
858
- rect2: (left, top, width, height) of second rectangle in inches
859
- tolerance: Minimum overlap in inches to consider as overlapping (default: 0.05")
860
-
861
- Returns:
862
- Tuple of (overlaps, overlap_area) where:
863
- - overlaps: True if rectangles overlap by more than tolerance
864
- - overlap_area: Area of overlap in square inches
865
- """
866
- left1, top1, w1, h1 = rect1
867
- left2, top2, w2, h2 = rect2
868
-
869
- # Calculate overlap dimensions
870
- overlap_width = min(left1 + w1, left2 + w2) - max(left1, left2)
871
- overlap_height = min(top1 + h1, top2 + h2) - max(top1, top2)
872
-
873
- # Check if there's meaningful overlap (more than tolerance)
874
- if overlap_width > tolerance and overlap_height > tolerance:
875
- # Calculate overlap area in square inches
876
- overlap_area = overlap_width * overlap_height
877
- return True, round(overlap_area, 2)
878
-
879
- return False, 0
880
-
881
-
882
- def detect_overlaps(shapes: List[ShapeData]) -> None:
883
- """Detect overlapping shapes and update their overlapping_shapes dictionaries.
884
-
885
- This function requires each ShapeData to have its shape_id already set.
886
- It modifies the shapes in-place, adding shape IDs with overlap areas in square inches.
887
-
888
- Args:
889
- shapes: List of ShapeData objects with shape_id attributes set
890
- """
891
- n = len(shapes)
892
-
893
- # Compare each pair of shapes
894
- for i in range(n):
895
- for j in range(i + 1, n):
896
- shape1 = shapes[i]
897
- shape2 = shapes[j]
898
-
899
- # Ensure shape IDs are set
900
- assert shape1.shape_id, f"Shape at index {i} has no shape_id"
901
- assert shape2.shape_id, f"Shape at index {j} has no shape_id"
902
-
903
- rect1 = (shape1.left, shape1.top, shape1.width, shape1.height)
904
- rect2 = (shape2.left, shape2.top, shape2.width, shape2.height)
905
-
906
- overlaps, overlap_area = calculate_overlap(rect1, rect2)
907
-
908
- if overlaps:
909
- # Add shape IDs with overlap area in square inches
910
- shape1.overlapping_shapes[shape2.shape_id] = overlap_area
911
- shape2.overlapping_shapes[shape1.shape_id] = overlap_area
912
-
913
-
914
- def extract_text_inventory(
915
- pptx_path: Path, prs: Optional[Any] = None, issues_only: bool = False
916
- ) -> InventoryData:
917
- """Extract text content from all slides in a PowerPoint presentation.
918
-
919
- Args:
920
- pptx_path: Path to the PowerPoint file
921
- prs: Optional Presentation object to use. If not provided, will load from pptx_path.
922
- issues_only: If True, only include shapes that have overflow or overlap issues
923
-
924
- Returns a nested dictionary: {slide-N: {shape-N: ShapeData}}
925
- Shapes are sorted by visual position (top-to-bottom, left-to-right).
926
- The ShapeData objects contain the full shape information and can be
927
- converted to dictionaries for JSON serialization using to_dict().
928
- """
929
- if prs is None:
930
- prs = Presentation(str(pptx_path))
931
- inventory: InventoryData = {}
932
-
933
- for slide_idx, slide in enumerate(prs.slides):
934
- # Collect all valid shapes from this slide with absolute positions
935
- shapes_with_positions = []
936
- for shape in slide.shapes: # type: ignore
937
- shapes_with_positions.extend(collect_shapes_with_absolute_positions(shape))
938
-
939
- if not shapes_with_positions:
940
- continue
941
-
942
- # Convert to ShapeData with absolute positions and slide reference
943
- shape_data_list = [
944
- ShapeData(
945
- swp.shape,
946
- swp.absolute_left,
947
- swp.absolute_top,
948
- slide,
949
- )
950
- for swp in shapes_with_positions
951
- ]
952
-
953
- # Sort by visual position and assign stable IDs in one step
954
- sorted_shapes = sort_shapes_by_position(shape_data_list)
955
- for idx, shape_data in enumerate(sorted_shapes):
956
- shape_data.shape_id = f"shape-{idx}"
957
-
958
- # Detect overlaps using the stable shape IDs
959
- if len(sorted_shapes) > 1:
960
- detect_overlaps(sorted_shapes)
961
-
962
- # Filter for issues only if requested (after overlap detection)
963
- if issues_only:
964
- sorted_shapes = [sd for sd in sorted_shapes if sd.has_any_issues]
965
-
966
- if not sorted_shapes:
967
- continue
968
-
969
- # Create slide inventory using the stable shape IDs
970
- inventory[f"slide-{slide_idx}"] = {
971
- shape_data.shape_id: shape_data for shape_data in sorted_shapes
972
- }
973
-
974
- return inventory
975
-
976
-
977
- def get_inventory_as_dict(pptx_path: Path, issues_only: bool = False) -> InventoryDict:
978
- """Extract text inventory and return as JSON-serializable dictionaries.
979
-
980
- This is a convenience wrapper around extract_text_inventory that returns
981
- dictionaries instead of ShapeData objects, useful for testing and direct
982
- JSON serialization.
983
-
984
- Args:
985
- pptx_path: Path to the PowerPoint file
986
- issues_only: If True, only include shapes that have overflow or overlap issues
987
-
988
- Returns:
989
- Nested dictionary with all data serialized for JSON
990
- """
991
- inventory = extract_text_inventory(pptx_path, issues_only=issues_only)
992
-
993
- # Convert ShapeData objects to dictionaries
994
- dict_inventory: InventoryDict = {}
995
- for slide_key, shapes in inventory.items():
996
- dict_inventory[slide_key] = {
997
- shape_key: shape_data.to_dict() for shape_key, shape_data in shapes.items()
998
- }
999
-
1000
- return dict_inventory
1001
-
1002
-
1003
- def save_inventory(inventory: InventoryData, output_path: Path) -> None:
1004
- """Save inventory to JSON file with proper formatting.
1005
-
1006
- Converts ShapeData objects to dictionaries for JSON serialization.
1007
- """
1008
- # Convert ShapeData objects to dictionaries
1009
- json_inventory: InventoryDict = {}
1010
- for slide_key, shapes in inventory.items():
1011
- json_inventory[slide_key] = {
1012
- shape_key: shape_data.to_dict() for shape_key, shape_data in shapes.items()
1013
- }
1014
-
1015
- with open(output_path, "w", encoding="utf-8") as f:
1016
- json.dump(json_inventory, f, indent=2, ensure_ascii=False)
1017
-
1018
-
1019
- if __name__ == "__main__":
1020
- main()
1
+ #!/usr/bin/env python3
2
+ """
3
+ Extract structured text content from PowerPoint presentations.
4
+
5
+ This module provides functionality to:
6
+ - Extract all text content from PowerPoint shapes
7
+ - Preserve paragraph formatting (alignment, bullets, fonts, spacing)
8
+ - Handle nested GroupShapes recursively with correct absolute positions
9
+ - Sort shapes by visual position on slides
10
+ - Filter out slide numbers and non-content placeholders
11
+ - Export to JSON with clean, structured data
12
+
13
+ Classes:
14
+ ParagraphData: Represents a text paragraph with formatting
15
+ ShapeData: Represents a shape with position and text content
16
+
17
+ Main Functions:
18
+ extract_text_inventory: Extract all text from a presentation
19
+ save_inventory: Save extracted data to JSON
20
+
21
+ Usage:
22
+ python inventory.py input.pptx output.json
23
+ """
24
+
25
+ import argparse
26
+ import json
27
+ import platform
28
+ import sys
29
+ from dataclasses import dataclass
30
+ from pathlib import Path
31
+ from typing import Any, Dict, List, Optional, Tuple, Union
32
+
33
+ from PIL import Image, ImageDraw, ImageFont
34
+ from pptx import Presentation
35
+ from pptx.enum.text import PP_ALIGN
36
+ from pptx.shapes.base import BaseShape
37
+
38
+ # Type aliases for cleaner signatures
39
+ JsonValue = Union[str, int, float, bool, None]
40
+ ParagraphDict = Dict[str, JsonValue]
41
+ ShapeDict = Dict[
42
+ str, Union[str, float, bool, List[ParagraphDict], List[str], Dict[str, Any], None]
43
+ ]
44
+ InventoryData = Dict[
45
+ str, Dict[str, "ShapeData"]
46
+ ] # Dict of slide_id -> {shape_id -> ShapeData}
47
+ InventoryDict = Dict[str, Dict[str, ShapeDict]] # JSON-serializable inventory
48
+
49
+
50
+ def main():
51
+ """Main entry point for command-line usage."""
52
+ parser = argparse.ArgumentParser(
53
+ description="Extract text inventory from PowerPoint with proper GroupShape support.",
54
+ formatter_class=argparse.RawDescriptionHelpFormatter,
55
+ epilog="""
56
+ Examples:
57
+ python inventory.py presentation.pptx inventory.json
58
+ Extracts text inventory with correct absolute positions for grouped shapes
59
+
60
+ python inventory.py presentation.pptx inventory.json --issues-only
61
+ Extracts only text shapes that have overflow or overlap issues
62
+
63
+ The output JSON includes:
64
+ - All text content organized by slide and shape
65
+ - Correct absolute positions for shapes in groups
66
+ - Visual position and size in inches
67
+ - Paragraph properties and formatting
68
+ - Issue detection: text overflow and shape overlaps
69
+ """,
70
+ )
71
+
72
+ parser.add_argument("input", help="Input PowerPoint file (.pptx)")
73
+ parser.add_argument("output", help="Output JSON file for inventory")
74
+ parser.add_argument(
75
+ "--issues-only",
76
+ action="store_true",
77
+ help="Include only text shapes that have overflow or overlap issues",
78
+ )
79
+
80
+ args = parser.parse_args()
81
+
82
+ input_path = Path(args.input)
83
+ if not input_path.exists():
84
+ print(f"Error: Input file not found: {args.input}")
85
+ sys.exit(1)
86
+
87
+ if not input_path.suffix.lower() == ".pptx":
88
+ print("Error: Input must be a PowerPoint file (.pptx)")
89
+ sys.exit(1)
90
+
91
+ try:
92
+ print(f"Extracting text inventory from: {args.input}")
93
+ if args.issues_only:
94
+ print(
95
+ "Filtering to include only text shapes with issues (overflow/overlap)"
96
+ )
97
+ inventory = extract_text_inventory(input_path, issues_only=args.issues_only)
98
+
99
+ output_path = Path(args.output)
100
+ output_path.parent.mkdir(parents=True, exist_ok=True)
101
+ save_inventory(inventory, output_path)
102
+
103
+ print(f"Output saved to: {args.output}")
104
+
105
+ # Report statistics
106
+ total_slides = len(inventory)
107
+ total_shapes = sum(len(shapes) for shapes in inventory.values())
108
+ if args.issues_only:
109
+ if total_shapes > 0:
110
+ print(
111
+ f"Found {total_shapes} text elements with issues in {total_slides} slides"
112
+ )
113
+ else:
114
+ print("No issues discovered")
115
+ else:
116
+ print(
117
+ f"Found text in {total_slides} slides with {total_shapes} text elements"
118
+ )
119
+
120
+ except Exception as e:
121
+ print(f"Error processing presentation: {e}")
122
+ import traceback
123
+
124
+ traceback.print_exc()
125
+ sys.exit(1)
126
+
127
+
128
+ @dataclass
129
+ class ShapeWithPosition:
130
+ """A shape with its absolute position on the slide."""
131
+
132
+ shape: BaseShape
133
+ absolute_left: int # in EMUs
134
+ absolute_top: int # in EMUs
135
+
136
+
137
+ class ParagraphData:
138
+ """Data structure for paragraph properties extracted from a PowerPoint paragraph."""
139
+
140
+ def __init__(self, paragraph: Any):
141
+ """Initialize from a PowerPoint paragraph object.
142
+
143
+ Args:
144
+ paragraph: The PowerPoint paragraph object
145
+ """
146
+ self.text: str = paragraph.text.strip()
147
+ self.bullet: bool = False
148
+ self.level: Optional[int] = None
149
+ self.alignment: Optional[str] = None
150
+ self.space_before: Optional[float] = None
151
+ self.space_after: Optional[float] = None
152
+ self.font_name: Optional[str] = None
153
+ self.font_size: Optional[float] = None
154
+ self.bold: Optional[bool] = None
155
+ self.italic: Optional[bool] = None
156
+ self.underline: Optional[bool] = None
157
+ self.color: Optional[str] = None
158
+ self.theme_color: Optional[str] = None
159
+ self.line_spacing: Optional[float] = None
160
+
161
+ # Check for bullet formatting
162
+ if (
163
+ hasattr(paragraph, "_p")
164
+ and paragraph._p is not None
165
+ and paragraph._p.pPr is not None
166
+ ):
167
+ pPr = paragraph._p.pPr
168
+ ns = "{http://schemas.openxmlformats.org/drawingml/2006/main}"
169
+ if (
170
+ pPr.find(f"{ns}buChar") is not None
171
+ or pPr.find(f"{ns}buAutoNum") is not None
172
+ ):
173
+ self.bullet = True
174
+ if hasattr(paragraph, "level"):
175
+ self.level = paragraph.level
176
+
177
+ # Add alignment if not LEFT (default)
178
+ if hasattr(paragraph, "alignment") and paragraph.alignment is not None:
179
+ alignment_map = {
180
+ PP_ALIGN.CENTER: "CENTER",
181
+ PP_ALIGN.RIGHT: "RIGHT",
182
+ PP_ALIGN.JUSTIFY: "JUSTIFY",
183
+ }
184
+ if paragraph.alignment in alignment_map:
185
+ self.alignment = alignment_map[paragraph.alignment]
186
+
187
+ # Add spacing properties if set
188
+ if hasattr(paragraph, "space_before") and paragraph.space_before:
189
+ self.space_before = paragraph.space_before.pt
190
+ if hasattr(paragraph, "space_after") and paragraph.space_after:
191
+ self.space_after = paragraph.space_after.pt
192
+
193
+ # Extract font properties from first run
194
+ if paragraph.runs:
195
+ first_run = paragraph.runs[0]
196
+ if hasattr(first_run, "font"):
197
+ font = first_run.font
198
+ if font.name:
199
+ self.font_name = font.name
200
+ if font.size:
201
+ self.font_size = font.size.pt
202
+ if font.bold is not None:
203
+ self.bold = font.bold
204
+ if font.italic is not None:
205
+ self.italic = font.italic
206
+ if font.underline is not None:
207
+ self.underline = font.underline
208
+
209
+ # Handle color - both RGB and theme colors
210
+ try:
211
+ # Try RGB color first
212
+ if font.color.rgb:
213
+ self.color = str(font.color.rgb)
214
+ except (AttributeError, TypeError):
215
+ # Fall back to theme color
216
+ try:
217
+ if font.color.theme_color:
218
+ self.theme_color = font.color.theme_color.name
219
+ except (AttributeError, TypeError):
220
+ pass
221
+
222
+ # Add line spacing if set
223
+ if hasattr(paragraph, "line_spacing") and paragraph.line_spacing is not None:
224
+ if hasattr(paragraph.line_spacing, "pt"):
225
+ self.line_spacing = round(paragraph.line_spacing.pt, 2)
226
+ else:
227
+ # Multiplier - convert to points
228
+ font_size = self.font_size if self.font_size else 12.0
229
+ self.line_spacing = round(paragraph.line_spacing * font_size, 2)
230
+
231
+ def to_dict(self) -> ParagraphDict:
232
+ """Convert to dictionary for JSON serialization, excluding None values."""
233
+ result: ParagraphDict = {"text": self.text}
234
+
235
+ # Add optional fields only if they have values
236
+ if self.bullet:
237
+ result["bullet"] = self.bullet
238
+ if self.level is not None:
239
+ result["level"] = self.level
240
+ if self.alignment:
241
+ result["alignment"] = self.alignment
242
+ if self.space_before is not None:
243
+ result["space_before"] = self.space_before
244
+ if self.space_after is not None:
245
+ result["space_after"] = self.space_after
246
+ if self.font_name:
247
+ result["font_name"] = self.font_name
248
+ if self.font_size is not None:
249
+ result["font_size"] = self.font_size
250
+ if self.bold is not None:
251
+ result["bold"] = self.bold
252
+ if self.italic is not None:
253
+ result["italic"] = self.italic
254
+ if self.underline is not None:
255
+ result["underline"] = self.underline
256
+ if self.color:
257
+ result["color"] = self.color
258
+ if self.theme_color:
259
+ result["theme_color"] = self.theme_color
260
+ if self.line_spacing is not None:
261
+ result["line_spacing"] = self.line_spacing
262
+
263
+ return result
264
+
265
+
266
+ class ShapeData:
267
+ """Data structure for shape properties extracted from a PowerPoint shape."""
268
+
269
+ @staticmethod
270
+ def emu_to_inches(emu: int) -> float:
271
+ """Convert EMUs (English Metric Units) to inches."""
272
+ return emu / 914400.0
273
+
274
+ @staticmethod
275
+ def inches_to_pixels(inches: float, dpi: int = 96) -> int:
276
+ """Convert inches to pixels at given DPI."""
277
+ return int(inches * dpi)
278
+
279
+ @staticmethod
280
+ def get_font_path(font_name: str) -> Optional[str]:
281
+ """Get the font file path for a given font name.
282
+
283
+ Args:
284
+ font_name: Name of the font (e.g., 'Arial', 'Calibri')
285
+
286
+ Returns:
287
+ Path to the font file, or None if not found
288
+ """
289
+ system = platform.system()
290
+
291
+ # Common font file variations to try
292
+ font_variations = [
293
+ font_name,
294
+ font_name.lower(),
295
+ font_name.replace(" ", ""),
296
+ font_name.replace(" ", "-"),
297
+ ]
298
+
299
+ # Define font directories and extensions by platform
300
+ if system == "Darwin": # macOS
301
+ font_dirs = [
302
+ "/System/Library/Fonts/",
303
+ "/Library/Fonts/",
304
+ "~/Library/Fonts/",
305
+ ]
306
+ extensions = [".ttf", ".otf", ".ttc", ".dfont"]
307
+ else: # Linux
308
+ font_dirs = [
309
+ "/usr/share/fonts/truetype/",
310
+ "/usr/local/share/fonts/",
311
+ "~/.fonts/",
312
+ ]
313
+ extensions = [".ttf", ".otf"]
314
+
315
+ # Try to find the font file
316
+ from pathlib import Path
317
+
318
+ for font_dir in font_dirs:
319
+ font_dir_path = Path(font_dir).expanduser()
320
+ if not font_dir_path.exists():
321
+ continue
322
+
323
+ # First try exact matches
324
+ for variant in font_variations:
325
+ for ext in extensions:
326
+ font_path = font_dir_path / f"{variant}{ext}"
327
+ if font_path.exists():
328
+ return str(font_path)
329
+
330
+ # Then try fuzzy matching - find files containing the font name
331
+ try:
332
+ for file_path in font_dir_path.iterdir():
333
+ if file_path.is_file():
334
+ file_name_lower = file_path.name.lower()
335
+ font_name_lower = font_name.lower().replace(" ", "")
336
+ if font_name_lower in file_name_lower and any(
337
+ file_name_lower.endswith(ext) for ext in extensions
338
+ ):
339
+ return str(file_path)
340
+ except (OSError, PermissionError):
341
+ continue
342
+
343
+ return None
344
+
345
+ @staticmethod
346
+ def get_slide_dimensions(slide: Any) -> tuple[Optional[int], Optional[int]]:
347
+ """Get slide dimensions from slide object.
348
+
349
+ Args:
350
+ slide: Slide object
351
+
352
+ Returns:
353
+ Tuple of (width_emu, height_emu) or (None, None) if not found
354
+ """
355
+ try:
356
+ prs = slide.part.package.presentation_part.presentation
357
+ return prs.slide_width, prs.slide_height
358
+ except (AttributeError, TypeError):
359
+ return None, None
360
+
361
+ @staticmethod
362
+ def get_default_font_size(shape: BaseShape, slide_layout: Any) -> Optional[float]:
363
+ """Extract default font size from slide layout for a placeholder shape.
364
+
365
+ Args:
366
+ shape: Placeholder shape
367
+ slide_layout: Slide layout containing the placeholder definition
368
+
369
+ Returns:
370
+ Default font size in points, or None if not found
371
+ """
372
+ try:
373
+ if not hasattr(shape, "placeholder_format"):
374
+ return None
375
+
376
+ shape_type = shape.placeholder_format.type # type: ignore
377
+ for layout_placeholder in slide_layout.placeholders:
378
+ if layout_placeholder.placeholder_format.type == shape_type:
379
+ # Find first defRPr element with sz (size) attribute
380
+ for elem in layout_placeholder.element.iter():
381
+ if "defRPr" in elem.tag and (sz := elem.get("sz")):
382
+ return float(sz) / 100.0 # Convert EMUs to points
383
+ break
384
+ except Exception:
385
+ pass
386
+ return None
387
+
388
+ def __init__(
389
+ self,
390
+ shape: BaseShape,
391
+ absolute_left: Optional[int] = None,
392
+ absolute_top: Optional[int] = None,
393
+ slide: Optional[Any] = None,
394
+ ):
395
+ """Initialize from a PowerPoint shape object.
396
+
397
+ Args:
398
+ shape: The PowerPoint shape object (should be pre-validated)
399
+ absolute_left: Absolute left position in EMUs (for shapes in groups)
400
+ absolute_top: Absolute top position in EMUs (for shapes in groups)
401
+ slide: Optional slide object to get dimensions and layout information
402
+ """
403
+ self.shape = shape # Store reference to original shape
404
+ self.shape_id: str = "" # Will be set after sorting
405
+
406
+ # Get slide dimensions from slide object
407
+ self.slide_width_emu, self.slide_height_emu = (
408
+ self.get_slide_dimensions(slide) if slide else (None, None)
409
+ )
410
+
411
+ # Get placeholder type if applicable
412
+ self.placeholder_type: Optional[str] = None
413
+ self.default_font_size: Optional[float] = None
414
+ if hasattr(shape, "is_placeholder") and shape.is_placeholder: # type: ignore
415
+ if shape.placeholder_format and shape.placeholder_format.type: # type: ignore
416
+ self.placeholder_type = (
417
+ str(shape.placeholder_format.type).split(".")[-1].split(" ")[0] # type: ignore
418
+ )
419
+
420
+ # Get default font size from layout
421
+ if slide and hasattr(slide, "slide_layout"):
422
+ self.default_font_size = self.get_default_font_size(
423
+ shape, slide.slide_layout
424
+ )
425
+
426
+ # Get position information
427
+ # Use absolute positions if provided (for shapes in groups), otherwise use shape's position
428
+ left_emu = (
429
+ absolute_left
430
+ if absolute_left is not None
431
+ else (shape.left if hasattr(shape, "left") else 0)
432
+ )
433
+ top_emu = (
434
+ absolute_top
435
+ if absolute_top is not None
436
+ else (shape.top if hasattr(shape, "top") else 0)
437
+ )
438
+
439
+ self.left: float = round(self.emu_to_inches(left_emu), 2) # type: ignore
440
+ self.top: float = round(self.emu_to_inches(top_emu), 2) # type: ignore
441
+ self.width: float = round(
442
+ self.emu_to_inches(shape.width if hasattr(shape, "width") else 0),
443
+ 2, # type: ignore
444
+ )
445
+ self.height: float = round(
446
+ self.emu_to_inches(shape.height if hasattr(shape, "height") else 0),
447
+ 2, # type: ignore
448
+ )
449
+
450
+ # Store EMU positions for overflow calculations
451
+ self.left_emu = left_emu
452
+ self.top_emu = top_emu
453
+ self.width_emu = shape.width if hasattr(shape, "width") else 0
454
+ self.height_emu = shape.height if hasattr(shape, "height") else 0
455
+
456
+ # Calculate overflow status
457
+ self.frame_overflow_bottom: Optional[float] = None
458
+ self.slide_overflow_right: Optional[float] = None
459
+ self.slide_overflow_bottom: Optional[float] = None
460
+ self.overlapping_shapes: Dict[
461
+ str, float
462
+ ] = {} # Dict of shape_id -> overlap area in sq inches
463
+ self.warnings: List[str] = []
464
+ self._estimate_frame_overflow()
465
+ self._calculate_slide_overflow()
466
+ self._detect_bullet_issues()
467
+
468
+ @property
469
+ def paragraphs(self) -> List[ParagraphData]:
470
+ """Calculate paragraphs from the shape's text frame."""
471
+ if not self.shape or not hasattr(self.shape, "text_frame"):
472
+ return []
473
+
474
+ paragraphs = []
475
+ for paragraph in self.shape.text_frame.paragraphs: # type: ignore
476
+ if paragraph.text.strip():
477
+ paragraphs.append(ParagraphData(paragraph))
478
+ return paragraphs
479
+
480
+ def _get_default_font_size(self) -> int:
481
+ """Get default font size from theme text styles or use conservative default."""
482
+ try:
483
+ if not (
484
+ hasattr(self.shape, "part") and hasattr(self.shape.part, "slide_layout")
485
+ ):
486
+ return 14
487
+
488
+ slide_master = self.shape.part.slide_layout.slide_master # type: ignore
489
+ if not hasattr(slide_master, "element"):
490
+ return 14
491
+
492
+ # Determine theme style based on placeholder type
493
+ style_name = "bodyStyle" # Default
494
+ if self.placeholder_type and "TITLE" in self.placeholder_type:
495
+ style_name = "titleStyle"
496
+
497
+ # Find font size in theme styles
498
+ for child in slide_master.element.iter():
499
+ tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
500
+ if tag == style_name:
501
+ for elem in child.iter():
502
+ if "sz" in elem.attrib:
503
+ return int(elem.attrib["sz"]) // 100
504
+ except Exception:
505
+ pass
506
+
507
+ return 14 # Conservative default for body text
508
+
509
+ def _get_usable_dimensions(self, text_frame) -> Tuple[int, int]:
510
+ """Get usable width and height in pixels after accounting for margins."""
511
+ # Default PowerPoint margins in inches
512
+ margins = {"top": 0.05, "bottom": 0.05, "left": 0.1, "right": 0.1}
513
+
514
+ # Override with actual margins if set
515
+ if hasattr(text_frame, "margin_top") and text_frame.margin_top:
516
+ margins["top"] = self.emu_to_inches(text_frame.margin_top)
517
+ if hasattr(text_frame, "margin_bottom") and text_frame.margin_bottom:
518
+ margins["bottom"] = self.emu_to_inches(text_frame.margin_bottom)
519
+ if hasattr(text_frame, "margin_left") and text_frame.margin_left:
520
+ margins["left"] = self.emu_to_inches(text_frame.margin_left)
521
+ if hasattr(text_frame, "margin_right") and text_frame.margin_right:
522
+ margins["right"] = self.emu_to_inches(text_frame.margin_right)
523
+
524
+ # Calculate usable area
525
+ usable_width = self.width - margins["left"] - margins["right"]
526
+ usable_height = self.height - margins["top"] - margins["bottom"]
527
+
528
+ # Convert to pixels
529
+ return (
530
+ self.inches_to_pixels(usable_width),
531
+ self.inches_to_pixels(usable_height),
532
+ )
533
+
534
+ def _wrap_text_line(self, line: str, max_width_px: int, draw, font) -> List[str]:
535
+ """Wrap a single line of text to fit within max_width_px."""
536
+ if not line:
537
+ return [""]
538
+
539
+ # Use textlength for efficient width calculation
540
+ if draw.textlength(line, font=font) <= max_width_px:
541
+ return [line]
542
+
543
+ # Need to wrap - split into words
544
+ wrapped = []
545
+ words = line.split(" ")
546
+ current_line = ""
547
+
548
+ for word in words:
549
+ test_line = current_line + (" " if current_line else "") + word
550
+ if draw.textlength(test_line, font=font) <= max_width_px:
551
+ current_line = test_line
552
+ else:
553
+ if current_line:
554
+ wrapped.append(current_line)
555
+ current_line = word
556
+
557
+ if current_line:
558
+ wrapped.append(current_line)
559
+
560
+ return wrapped
561
+
562
+ def _estimate_frame_overflow(self) -> None:
563
+ """Estimate if text overflows the shape bounds using PIL text measurement."""
564
+ if not self.shape or not hasattr(self.shape, "text_frame"):
565
+ return
566
+
567
+ text_frame = self.shape.text_frame # type: ignore
568
+ if not text_frame or not text_frame.paragraphs:
569
+ return
570
+
571
+ # Get usable dimensions after accounting for margins
572
+ usable_width_px, usable_height_px = self._get_usable_dimensions(text_frame)
573
+ if usable_width_px <= 0 or usable_height_px <= 0:
574
+ return
575
+
576
+ # Set up PIL for text measurement
577
+ dummy_img = Image.new("RGB", (1, 1))
578
+ draw = ImageDraw.Draw(dummy_img)
579
+
580
+ # Get default font size from placeholder or use conservative estimate
581
+ default_font_size = self._get_default_font_size()
582
+
583
+ # Calculate total height of all paragraphs
584
+ total_height_px = 0
585
+
586
+ for para_idx, paragraph in enumerate(text_frame.paragraphs):
587
+ if not paragraph.text.strip():
588
+ continue
589
+
590
+ para_data = ParagraphData(paragraph)
591
+
592
+ # Load font for this paragraph
593
+ font_name = para_data.font_name or "Arial"
594
+ font_size = int(para_data.font_size or default_font_size)
595
+
596
+ font = None
597
+ font_path = self.get_font_path(font_name)
598
+ if font_path:
599
+ try:
600
+ font = ImageFont.truetype(font_path, size=font_size)
601
+ except Exception:
602
+ font = ImageFont.load_default()
603
+ else:
604
+ font = ImageFont.load_default()
605
+
606
+ # Wrap all lines in this paragraph
607
+ all_wrapped_lines = []
608
+ for line in paragraph.text.split("\n"):
609
+ wrapped = self._wrap_text_line(line, usable_width_px, draw, font)
610
+ all_wrapped_lines.extend(wrapped)
611
+
612
+ if all_wrapped_lines:
613
+ # Calculate line height
614
+ if para_data.line_spacing:
615
+ # Custom line spacing explicitly set
616
+ line_height_px = para_data.line_spacing * 96 / 72
617
+ else:
618
+ # PowerPoint default single spacing (1.0x font size)
619
+ line_height_px = font_size * 96 / 72
620
+
621
+ # Add space_before (except first paragraph)
622
+ if para_idx > 0 and para_data.space_before:
623
+ total_height_px += para_data.space_before * 96 / 72
624
+
625
+ # Add paragraph text height
626
+ total_height_px += len(all_wrapped_lines) * line_height_px
627
+
628
+ # Add space_after
629
+ if para_data.space_after:
630
+ total_height_px += para_data.space_after * 96 / 72
631
+
632
+ # Check for overflow (ignore negligible overflows <= 0.05")
633
+ if total_height_px > usable_height_px:
634
+ overflow_px = total_height_px - usable_height_px
635
+ overflow_inches = round(overflow_px / 96.0, 2)
636
+ if overflow_inches > 0.05: # Only report significant overflows
637
+ self.frame_overflow_bottom = overflow_inches
638
+
639
+ def _calculate_slide_overflow(self) -> None:
640
+ """Calculate if shape overflows the slide boundaries."""
641
+ if self.slide_width_emu is None or self.slide_height_emu is None:
642
+ return
643
+
644
+ # Check right overflow (ignore negligible overflows <= 0.01")
645
+ right_edge_emu = self.left_emu + self.width_emu
646
+ if right_edge_emu > self.slide_width_emu:
647
+ overflow_emu = right_edge_emu - self.slide_width_emu
648
+ overflow_inches = round(self.emu_to_inches(overflow_emu), 2)
649
+ if overflow_inches > 0.01: # Only report significant overflows
650
+ self.slide_overflow_right = overflow_inches
651
+
652
+ # Check bottom overflow (ignore negligible overflows <= 0.01")
653
+ bottom_edge_emu = self.top_emu + self.height_emu
654
+ if bottom_edge_emu > self.slide_height_emu:
655
+ overflow_emu = bottom_edge_emu - self.slide_height_emu
656
+ overflow_inches = round(self.emu_to_inches(overflow_emu), 2)
657
+ if overflow_inches > 0.01: # Only report significant overflows
658
+ self.slide_overflow_bottom = overflow_inches
659
+
660
+ def _detect_bullet_issues(self) -> None:
661
+ """Detect bullet point formatting issues in paragraphs."""
662
+ if not self.shape or not hasattr(self.shape, "text_frame"):
663
+ return
664
+
665
+ text_frame = self.shape.text_frame # type: ignore
666
+ if not text_frame or not text_frame.paragraphs:
667
+ return
668
+
669
+ # Common bullet symbols that indicate manual bullets
670
+ bullet_symbols = ["•", "●", "○"]
671
+
672
+ for paragraph in text_frame.paragraphs:
673
+ text = paragraph.text.strip()
674
+ # Check for manual bullet symbols
675
+ if text and any(text.startswith(symbol + " ") for symbol in bullet_symbols):
676
+ self.warnings.append(
677
+ "manual_bullet_symbol: use proper bullet formatting"
678
+ )
679
+ break
680
+
681
+ @property
682
+ def has_any_issues(self) -> bool:
683
+ """Check if shape has any issues (overflow, overlap, or warnings)."""
684
+ return (
685
+ self.frame_overflow_bottom is not None
686
+ or self.slide_overflow_right is not None
687
+ or self.slide_overflow_bottom is not None
688
+ or len(self.overlapping_shapes) > 0
689
+ or len(self.warnings) > 0
690
+ )
691
+
692
+ def to_dict(self) -> ShapeDict:
693
+ """Convert to dictionary for JSON serialization."""
694
+ result: ShapeDict = {
695
+ "left": self.left,
696
+ "top": self.top,
697
+ "width": self.width,
698
+ "height": self.height,
699
+ }
700
+
701
+ # Add optional fields if present
702
+ if self.placeholder_type:
703
+ result["placeholder_type"] = self.placeholder_type
704
+
705
+ if self.default_font_size:
706
+ result["default_font_size"] = self.default_font_size
707
+
708
+ # Add overflow information only if there is overflow
709
+ overflow_data = {}
710
+
711
+ # Add frame overflow if present
712
+ if self.frame_overflow_bottom is not None:
713
+ overflow_data["frame"] = {"overflow_bottom": self.frame_overflow_bottom}
714
+
715
+ # Add slide overflow if present
716
+ slide_overflow = {}
717
+ if self.slide_overflow_right is not None:
718
+ slide_overflow["overflow_right"] = self.slide_overflow_right
719
+ if self.slide_overflow_bottom is not None:
720
+ slide_overflow["overflow_bottom"] = self.slide_overflow_bottom
721
+ if slide_overflow:
722
+ overflow_data["slide"] = slide_overflow
723
+
724
+ # Only add overflow field if there is overflow
725
+ if overflow_data:
726
+ result["overflow"] = overflow_data
727
+
728
+ # Add overlap field if there are overlapping shapes
729
+ if self.overlapping_shapes:
730
+ result["overlap"] = {"overlapping_shapes": self.overlapping_shapes}
731
+
732
+ # Add warnings field if there are warnings
733
+ if self.warnings:
734
+ result["warnings"] = self.warnings
735
+
736
+ # Add paragraphs after placeholder_type
737
+ result["paragraphs"] = [para.to_dict() for para in self.paragraphs]
738
+
739
+ return result
740
+
741
+
742
+ def is_valid_shape(shape: BaseShape) -> bool:
743
+ """Check if a shape contains meaningful text content."""
744
+ # Must have a text frame with content
745
+ if not hasattr(shape, "text_frame") or not shape.text_frame: # type: ignore
746
+ return False
747
+
748
+ text = shape.text_frame.text.strip() # type: ignore
749
+ if not text:
750
+ return False
751
+
752
+ # Skip slide numbers and numeric footers
753
+ if hasattr(shape, "is_placeholder") and shape.is_placeholder: # type: ignore
754
+ if shape.placeholder_format and shape.placeholder_format.type: # type: ignore
755
+ placeholder_type = (
756
+ str(shape.placeholder_format.type).split(".")[-1].split(" ")[0] # type: ignore
757
+ )
758
+ if placeholder_type == "SLIDE_NUMBER":
759
+ return False
760
+ if placeholder_type == "FOOTER" and text.isdigit():
761
+ return False
762
+
763
+ return True
764
+
765
+
766
+ def collect_shapes_with_absolute_positions(
767
+ shape: BaseShape, parent_left: int = 0, parent_top: int = 0
768
+ ) -> List[ShapeWithPosition]:
769
+ """Recursively collect all shapes with valid text, calculating absolute positions.
770
+
771
+ For shapes within groups, their positions are relative to the group.
772
+ This function calculates the absolute position on the slide by accumulating
773
+ parent group offsets.
774
+
775
+ Args:
776
+ shape: The shape to process
777
+ parent_left: Accumulated left offset from parent groups (in EMUs)
778
+ parent_top: Accumulated top offset from parent groups (in EMUs)
779
+
780
+ Returns:
781
+ List of ShapeWithPosition objects with absolute positions
782
+ """
783
+ if hasattr(shape, "shapes"): # GroupShape
784
+ result = []
785
+ # Get this group's position
786
+ group_left = shape.left if hasattr(shape, "left") else 0
787
+ group_top = shape.top if hasattr(shape, "top") else 0
788
+
789
+ # Calculate absolute position for this group
790
+ abs_group_left = parent_left + group_left
791
+ abs_group_top = parent_top + group_top
792
+
793
+ # Process children with accumulated offsets
794
+ for child in shape.shapes: # type: ignore
795
+ result.extend(
796
+ collect_shapes_with_absolute_positions(
797
+ child, abs_group_left, abs_group_top
798
+ )
799
+ )
800
+ return result
801
+
802
+ # Regular shape - check if it has valid text
803
+ if is_valid_shape(shape):
804
+ # Calculate absolute position
805
+ shape_left = shape.left if hasattr(shape, "left") else 0
806
+ shape_top = shape.top if hasattr(shape, "top") else 0
807
+
808
+ return [
809
+ ShapeWithPosition(
810
+ shape=shape,
811
+ absolute_left=parent_left + shape_left,
812
+ absolute_top=parent_top + shape_top,
813
+ )
814
+ ]
815
+
816
+ return []
817
+
818
+
819
+ def sort_shapes_by_position(shapes: List[ShapeData]) -> List[ShapeData]:
820
+ """Sort shapes by visual position (top-to-bottom, left-to-right).
821
+
822
+ Shapes within 0.5 inches vertically are considered on the same row.
823
+ """
824
+ if not shapes:
825
+ return shapes
826
+
827
+ # Sort by top position first
828
+ shapes = sorted(shapes, key=lambda s: (s.top, s.left))
829
+
830
+ # Group shapes by row (within 0.5 inches vertically)
831
+ result = []
832
+ row = [shapes[0]]
833
+ row_top = shapes[0].top
834
+
835
+ for shape in shapes[1:]:
836
+ if abs(shape.top - row_top) <= 0.5:
837
+ row.append(shape)
838
+ else:
839
+ # Sort current row by left position and add to result
840
+ result.extend(sorted(row, key=lambda s: s.left))
841
+ row = [shape]
842
+ row_top = shape.top
843
+
844
+ # Don't forget the last row
845
+ result.extend(sorted(row, key=lambda s: s.left))
846
+ return result
847
+
848
+
849
+ def calculate_overlap(
850
+ rect1: Tuple[float, float, float, float],
851
+ rect2: Tuple[float, float, float, float],
852
+ tolerance: float = 0.05,
853
+ ) -> Tuple[bool, float]:
854
+ """Calculate if and how much two rectangles overlap.
855
+
856
+ Args:
857
+ rect1: (left, top, width, height) of first rectangle in inches
858
+ rect2: (left, top, width, height) of second rectangle in inches
859
+ tolerance: Minimum overlap in inches to consider as overlapping (default: 0.05")
860
+
861
+ Returns:
862
+ Tuple of (overlaps, overlap_area) where:
863
+ - overlaps: True if rectangles overlap by more than tolerance
864
+ - overlap_area: Area of overlap in square inches
865
+ """
866
+ left1, top1, w1, h1 = rect1
867
+ left2, top2, w2, h2 = rect2
868
+
869
+ # Calculate overlap dimensions
870
+ overlap_width = min(left1 + w1, left2 + w2) - max(left1, left2)
871
+ overlap_height = min(top1 + h1, top2 + h2) - max(top1, top2)
872
+
873
+ # Check if there's meaningful overlap (more than tolerance)
874
+ if overlap_width > tolerance and overlap_height > tolerance:
875
+ # Calculate overlap area in square inches
876
+ overlap_area = overlap_width * overlap_height
877
+ return True, round(overlap_area, 2)
878
+
879
+ return False, 0
880
+
881
+
882
+ def detect_overlaps(shapes: List[ShapeData]) -> None:
883
+ """Detect overlapping shapes and update their overlapping_shapes dictionaries.
884
+
885
+ This function requires each ShapeData to have its shape_id already set.
886
+ It modifies the shapes in-place, adding shape IDs with overlap areas in square inches.
887
+
888
+ Args:
889
+ shapes: List of ShapeData objects with shape_id attributes set
890
+ """
891
+ n = len(shapes)
892
+
893
+ # Compare each pair of shapes
894
+ for i in range(n):
895
+ for j in range(i + 1, n):
896
+ shape1 = shapes[i]
897
+ shape2 = shapes[j]
898
+
899
+ # Ensure shape IDs are set
900
+ assert shape1.shape_id, f"Shape at index {i} has no shape_id"
901
+ assert shape2.shape_id, f"Shape at index {j} has no shape_id"
902
+
903
+ rect1 = (shape1.left, shape1.top, shape1.width, shape1.height)
904
+ rect2 = (shape2.left, shape2.top, shape2.width, shape2.height)
905
+
906
+ overlaps, overlap_area = calculate_overlap(rect1, rect2)
907
+
908
+ if overlaps:
909
+ # Add shape IDs with overlap area in square inches
910
+ shape1.overlapping_shapes[shape2.shape_id] = overlap_area
911
+ shape2.overlapping_shapes[shape1.shape_id] = overlap_area
912
+
913
+
914
+ def extract_text_inventory(
915
+ pptx_path: Path, prs: Optional[Any] = None, issues_only: bool = False
916
+ ) -> InventoryData:
917
+ """Extract text content from all slides in a PowerPoint presentation.
918
+
919
+ Args:
920
+ pptx_path: Path to the PowerPoint file
921
+ prs: Optional Presentation object to use. If not provided, will load from pptx_path.
922
+ issues_only: If True, only include shapes that have overflow or overlap issues
923
+
924
+ Returns a nested dictionary: {slide-N: {shape-N: ShapeData}}
925
+ Shapes are sorted by visual position (top-to-bottom, left-to-right).
926
+ The ShapeData objects contain the full shape information and can be
927
+ converted to dictionaries for JSON serialization using to_dict().
928
+ """
929
+ if prs is None:
930
+ prs = Presentation(str(pptx_path))
931
+ inventory: InventoryData = {}
932
+
933
+ for slide_idx, slide in enumerate(prs.slides):
934
+ # Collect all valid shapes from this slide with absolute positions
935
+ shapes_with_positions = []
936
+ for shape in slide.shapes: # type: ignore
937
+ shapes_with_positions.extend(collect_shapes_with_absolute_positions(shape))
938
+
939
+ if not shapes_with_positions:
940
+ continue
941
+
942
+ # Convert to ShapeData with absolute positions and slide reference
943
+ shape_data_list = [
944
+ ShapeData(
945
+ swp.shape,
946
+ swp.absolute_left,
947
+ swp.absolute_top,
948
+ slide,
949
+ )
950
+ for swp in shapes_with_positions
951
+ ]
952
+
953
+ # Sort by visual position and assign stable IDs in one step
954
+ sorted_shapes = sort_shapes_by_position(shape_data_list)
955
+ for idx, shape_data in enumerate(sorted_shapes):
956
+ shape_data.shape_id = f"shape-{idx}"
957
+
958
+ # Detect overlaps using the stable shape IDs
959
+ if len(sorted_shapes) > 1:
960
+ detect_overlaps(sorted_shapes)
961
+
962
+ # Filter for issues only if requested (after overlap detection)
963
+ if issues_only:
964
+ sorted_shapes = [sd for sd in sorted_shapes if sd.has_any_issues]
965
+
966
+ if not sorted_shapes:
967
+ continue
968
+
969
+ # Create slide inventory using the stable shape IDs
970
+ inventory[f"slide-{slide_idx}"] = {
971
+ shape_data.shape_id: shape_data for shape_data in sorted_shapes
972
+ }
973
+
974
+ return inventory
975
+
976
+
977
+ def get_inventory_as_dict(pptx_path: Path, issues_only: bool = False) -> InventoryDict:
978
+ """Extract text inventory and return as JSON-serializable dictionaries.
979
+
980
+ This is a convenience wrapper around extract_text_inventory that returns
981
+ dictionaries instead of ShapeData objects, useful for testing and direct
982
+ JSON serialization.
983
+
984
+ Args:
985
+ pptx_path: Path to the PowerPoint file
986
+ issues_only: If True, only include shapes that have overflow or overlap issues
987
+
988
+ Returns:
989
+ Nested dictionary with all data serialized for JSON
990
+ """
991
+ inventory = extract_text_inventory(pptx_path, issues_only=issues_only)
992
+
993
+ # Convert ShapeData objects to dictionaries
994
+ dict_inventory: InventoryDict = {}
995
+ for slide_key, shapes in inventory.items():
996
+ dict_inventory[slide_key] = {
997
+ shape_key: shape_data.to_dict() for shape_key, shape_data in shapes.items()
998
+ }
999
+
1000
+ return dict_inventory
1001
+
1002
+
1003
+ def save_inventory(inventory: InventoryData, output_path: Path) -> None:
1004
+ """Save inventory to JSON file with proper formatting.
1005
+
1006
+ Converts ShapeData objects to dictionaries for JSON serialization.
1007
+ """
1008
+ # Convert ShapeData objects to dictionaries
1009
+ json_inventory: InventoryDict = {}
1010
+ for slide_key, shapes in inventory.items():
1011
+ json_inventory[slide_key] = {
1012
+ shape_key: shape_data.to_dict() for shape_key, shape_data in shapes.items()
1013
+ }
1014
+
1015
+ with open(output_path, "w", encoding="utf-8") as f:
1016
+ json.dump(json_inventory, f, indent=2, ensure_ascii=False)
1017
+
1018
+
1019
+ if __name__ == "__main__":
1020
+ main()