minimal-agent 0.8.2 → 0.10.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.
- package/README.md +14 -12
- package/package.json +34 -1
- package/plugins/cron-runner/.claude-plugin/plugin.json +5 -0
- package/plugins/cron-runner/commands/cron.md +26 -0
- package/plugins/cron-runner/commands/crons.md +7 -0
- package/plugins/cron-runner/plugin.js +34 -0
- package/plugins/cron-runner/src/commands.js +348 -0
- package/plugins/cron-runner/src/cronTime.js +148 -0
- package/plugins/cron-runner/src/lock.js +68 -0
- package/plugins/cron-runner/src/runs.js +89 -0
- package/plugins/cron-runner/src/scheduleEngine.js +72 -0
- package/plugins/cron-runner/src/scheduler.js +355 -0
- package/plugins/cron-runner/src/schema.js +140 -0
- package/plugins/cron-runner/src/service.js +167 -0
- package/plugins/cron-runner/src/store.js +298 -0
- package/plugins/cron-runner/src/types.js +1 -0
- package/plugins/workflow-runner/commands/workflow.md +4 -4
- package/plugins/workflow-runner/commands/workflows.md +1 -1
- package/plugins/workflow-runner/plugin.js +3 -1
- package/plugins/workflow-runner/src/agentCommon.js +249 -51
- package/plugins/workflow-runner/src/dslManifest.js +72 -0
- package/plugins/workflow-runner/src/expressions.js +198 -15
- package/plugins/workflow-runner/src/index.js +40 -8
- package/plugins/workflow-runner/src/jsonPayload.js +1 -1
- package/plugins/workflow-runner/src/loader.js +286 -72
- package/plugins/workflow-runner/src/multimodal.js +37 -0
- package/plugins/workflow-runner/src/recovery.js +49 -39
- package/plugins/workflow-runner/src/runner.js +802 -287
- package/plugins/workflow-runner/src/stepExecutors/agent.js +157 -39
- package/plugins/workflow-runner/src/stepExecutors/assert.js +16 -3
- package/plugins/workflow-runner/src/stepExecutors/llm.js +60 -111
- package/plugins/workflow-runner/src/stepExecutors/skill.js +47 -47
- package/plugins/workflow-runner/src/stepExecutors/tool.js +76 -10
- package/plugins/workflow-runner/src/stepExecutors/verify.js +27 -10
- package/plugins/workflow-runner/src/taskIdentity.js +296 -0
- package/plugins/workflow-runner/src/types.js +19 -9
- package/plugins/workflow-runner/src/workflowState.js +516 -33
- package/skills/adversarial-review/SKILL.md +0 -1
- package/skills/ai-image/SKILL.md +89 -0
- package/skills/ai-image/scripts/generate.mjs +497 -0
- package/skills/ai-image/scripts/generate_from_plan.mjs +469 -0
- package/skills/ai-image/scripts/generate_from_plan_test.mjs +223 -0
- package/skills/ai-image/scripts/generate_test.mjs +74 -0
- package/skills/browser-automation/SKILL.md +47 -0
- package/skills/docx/SKILL.md +25 -3
- package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
- package/skills/docx/scripts/opc_check.py +253 -0
- package/skills/image-gen-openrouter/SKILL.md +10 -2
- package/skills/image-stats/SKILL.md +65 -0
- package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/image_stats.py +368 -0
- package/skills/image-stats/scripts/image_stats_test.py +181 -0
- package/skills/pptx/SKILL.md +123 -95
- package/skills/pptx/design.md +82 -0
- package/skills/pptx/examples/README.md +29 -0
- package/skills/pptx/examples/hybrid_example.mjs +107 -0
- package/skills/pptx/examples/hybrid_example.pptx +0 -0
- package/skills/pptx/pptxgenjs.md +41 -0
- package/skills/pptx/scripts/deck_helpers.mjs +224 -0
- package/skills/pptx/scripts/layout_lint.py +293 -0
- package/skills/pptx/scripts/layout_lint_test.py +160 -0
- package/skills/pptx/scripts/opc_check.py +339 -0
- package/skills/pptx/scripts/svg_fallback.mjs +145 -0
- package/skills/pptx/svg.md +67 -0
- package/skills/tts-zh/SKILL.md +19 -2
- package/skills/ui-design/SKILL.md +158 -0
- package/skills/ui-design/claude_design.md +309 -0
- package/skills/ui-design/evals/evals.json +254 -0
- package/skills/ui-design/references/aesthetic-direction.md +83 -0
- package/skills/ui-design/references/claude-design-protocol.md +36 -0
- package/skills/ui-design/references/design-context.md +53 -0
- package/skills/ui-design/references/design-execution-playbook.md +82 -0
- package/skills/ui-design/references/export-pptx.md +124 -0
- package/skills/ui-design/references/layout-composition.md +654 -0
- package/skills/ui-design/references/preview-feedback.md +37 -0
- package/skills/ui-design/references/source-image-layout.md +189 -0
- package/skills/ui-design/references/starter-components.md +78 -0
- package/skills/ui-design/references/vi-aegis-vector.md +144 -0
- package/skills/ui-design/references/vi-amber-prism.md +133 -0
- package/skills/ui-design/references/vi-aqua-glass.md +200 -0
- package/skills/ui-design/references/vi-comfort-vision.md +147 -0
- package/skills/ui-design/references/vi-ember-prism.md +140 -0
- package/skills/ui-design/references/vi-nebula-console.md +151 -0
- package/skills/ui-design/references/vi-obsidian-optics.md +139 -0
- package/skills/ui-design/references/vi-obsidian-xui.md +143 -0
- package/skills/ui-design/references/vi-precision-horizon-dark.md +117 -0
- package/skills/ui-design/references/vi-precision-horizon.md +215 -0
- package/skills/ui-design/references/vi-solar-relay.md +130 -0
- package/skills/ui-design/references/vi-template-workflow.md +48 -0
- package/skills/ui-design/references/vi-verdant-grid.md +141 -0
- package/skills/ui-design/references/vi-violet-meridian.md +172 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/assemble_material.py +217 -0
- package/skills/ui-design/scripts/assemble_material_test.py +149 -0
- package/skills/ui-design/scripts/browser_check_ui_artifact.mjs +221 -0
- package/skills/ui-design/scripts/chart_sanity_check.py +261 -0
- package/skills/ui-design/scripts/chart_sanity_check_test.py +165 -0
- package/skills/ui-design/scripts/check_language_policy.py +351 -0
- package/skills/ui-design/scripts/check_ui_artifact.py +435 -0
- package/skills/ui-design/scripts/check_ui_artifact_pptx_test.py +251 -0
- package/skills/ui-design/scripts/deck_pages_check.py +158 -0
- package/skills/ui-design/scripts/deck_pages_check_test.py +134 -0
- package/skills/ui-design/scripts/deck_visual_style_check.py +767 -0
- package/skills/ui-design/scripts/deck_visual_style_check_test.py +713 -0
- package/skills/ui-design/scripts/design_budget_check.py +271 -0
- package/skills/ui-design/scripts/design_budget_check_test.py +183 -0
- package/skills/ui-design/scripts/design_repair_hints.py +162 -0
- package/skills/ui-design/scripts/design_repair_hints_test.py +54 -0
- package/skills/ui-design/scripts/design_style_check.py +397 -0
- package/skills/ui-design/scripts/design_style_check_test.py +233 -0
- package/skills/ui-design/scripts/draft_coverage_check.py +184 -0
- package/skills/ui-design/scripts/draft_coverage_check_test.py +131 -0
- package/skills/ui-design/scripts/export_pptx_from_html.mjs +2367 -0
- package/skills/ui-design/scripts/extract_source_assets.py +607 -0
- package/skills/ui-design/scripts/extract_source_assets_test.py +256 -0
- package/skills/ui-design/scripts/generated_image_review_collect.py +206 -0
- package/skills/ui-design/scripts/generated_image_review_collect_test.py +91 -0
- package/skills/ui-design/scripts/image_plan_lint.py +571 -0
- package/skills/ui-design/scripts/image_plan_lint_test.py +515 -0
- package/skills/ui-design/scripts/image_prompt_rewrite.py +713 -0
- package/skills/ui-design/scripts/image_prompt_rewrite_test.py +966 -0
- package/skills/ui-design/scripts/layout_balance.py +881 -0
- package/skills/ui-design/scripts/layout_balance_test.py +927 -0
- package/skills/ui-design/scripts/normalize_design_json.py +272 -0
- package/skills/ui-design/scripts/normalize_design_json_test.py +119 -0
- package/skills/ui-design/scripts/plan_source_layout.py +1450 -0
- package/skills/ui-design/scripts/plan_source_layout_test.py +1136 -0
- package/skills/ui-design/scripts/resolve_source_input.py +270 -0
- package/skills/ui-design/scripts/resolve_source_input_test.py +98 -0
- package/skills/ui-design/scripts/scaffold_ui_artifact.py +377 -0
- package/skills/ui-design/scripts/source_usage_check.py +581 -0
- package/skills/ui-design/scripts/source_usage_check_test.py +427 -0
- package/skills/ui-design/scripts/text_readability_pixel.py +340 -0
- package/skills/ui-design/scripts/text_readability_pixel_test.py +219 -0
- package/skills/ui-design/scripts/visual_quality_gate.py +301 -0
- package/skills/ui-design/scripts/visual_quality_gate_test.py +233 -0
- package/skills/ui-design/tests/e2e/prompts/deck.md +19 -0
- package/skills/ui-design/tests/e2e/prompts/webpage.md +17 -0
- package/skills/ui-design/tests/e2e/render_check.mjs +101 -0
- package/skills/ui-design/tests/e2e/rubric.json +54 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/language-check.txt +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/static-check.txt +15 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/outputs/index.html +837 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/review.md +21 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/outputs/index.html +656 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/render_check.mjs +67 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/review.md +36 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/language-check.txt +8 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/static-check.txt +16 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/outputs/index.html +739 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/prompt.md +11 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/review.md +22 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/checks/browser-check.json +52 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/outputs/index.html +641 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/outputs/index.html +467 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/language-check.txt +4 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/execution_notes.md +10 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/review.md +13 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/browser-check.json +24 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/execution_notes.md +21 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/outputs/deck.html +451 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-01.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-02.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/review.md +79 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/browser-check.json +26 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/execution_notes.md +20 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/outputs/index.html +534 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/browser-check.json +64 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/language-check.txt +7 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-console.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-homepage.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/console.html +600 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/homepage.html +556 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/prompt.md +29 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/review.md +57 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/browser-check.json +33 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/outputs/index.html +682 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-01.html +466 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-02.html +433 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/language-check.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/execution_notes.md +24 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/outputs/index.html +723 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-dark.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-light.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/language-check.txt +11 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-dark.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-light.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/execution_notes.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/dark.html +392 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/light.html +476 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/prompt.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/review.md +41 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/language-check.txt +5 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/outputs/index.html +765 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/outputs/index.html +508 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/outputs/index.html +788 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/review.md +60 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/mobile.png +0 -0
- package/skills/video-compose/SKILL.md +8 -1
- package/skills/web-crawler/SKILL.md +70 -0
- package/skills/web-crawler/scripts/crawl.mjs +538 -0
- package/skills/web-crawler/scripts/crawl.test.mjs +204 -0
- package/skills/xlsx/SKILL.md +12 -0
- package/skills/xlsx/scripts/opc_check.py +253 -0
- package/src/advisorState.js +22 -0
- package/src/askBridge.js +97 -3
- package/src/bootstrap/workingDir.js +12 -1
- package/src/cli/args.js +17 -1
- package/src/cli/configMenu.js +236 -0
- package/src/cli/configWizard.js +7 -5
- package/src/cli/print.js +37 -4
- package/src/cli/streamJson.js +77 -24
- package/src/cli/wizards/advisorWizard.js +147 -0
- package/src/cli/wizards/fieldForm.js +149 -0
- package/src/cli/wizards/imageWizard.js +60 -0
- package/src/cli/wizards/openRouterWizard.js +23 -0
- package/src/cli/wizards/providerPresets.js +95 -0
- package/src/cli/wizards/providerWizard.js +219 -0
- package/src/cli/wizards/searchWizard.js +23 -0
- package/src/cli/wizards/ttsWizard.js +34 -0
- package/src/config/configFile.js +441 -83
- package/src/config/configService.js +446 -0
- package/src/config.js +24 -64
- package/src/context/agentHome.js +9 -0
- package/src/context/archive.js +7 -2
- package/src/context/compact.js +8 -5
- package/src/context/contextLock.js +81 -0
- package/src/context/persistContext.js +30 -11
- package/src/context/reactiveCompact.js +4 -2
- package/src/context/recentDirs.js +21 -61
- package/src/context/sessionPath.js +97 -23
- package/src/context/sessionRegistry.js +303 -24
- package/src/context/tokenCounter.js +18 -0
- package/src/context/workspaceIndex.js +731 -0
- package/src/infra/verification.js +28 -15
- package/src/llm/client.js +394 -159
- package/src/llm/providers/anthropicFormat.js +241 -0
- package/src/llm/providers/openaiFormat.js +190 -0
- package/src/loop.js +219 -32
- package/src/main.js +61 -11
- package/src/messageQueue.js +97 -0
- package/src/multimodal.js +203 -0
- package/src/plugin-sdk.js +15 -0
- package/src/plugins/commandRouter.js +3 -0
- package/src/plugins/hookEngine.js +5 -1
- package/src/plugins/pluginLifecycle.js +28 -0
- package/src/plugins/pluginLoader.js +2 -1
- package/src/plugins/pluginRunner.js +49 -21
- package/src/plugins/transcript.js +4 -3
- package/src/prompts/pluginList.js +5 -5
- package/src/prompts/projectInstructions.js +3 -3
- package/src/prompts/promptAssembly.js +133 -144
- package/src/prompts/skillList.js +12 -22
- package/src/prompts/system.js +0 -1
- package/src/session/runAgentTurn.js +70 -0
- package/src/session/runTurn.js +41 -6
- package/src/toolGate.js +17 -0
- package/src/tools/advisor/advisor.js +379 -0
- package/src/tools/agent/agent.js +555 -0
- package/src/tools/agent/agentTypes.js +59 -0
- package/src/tools/agent/coordinator.js +93 -0
- package/src/tools/agent/worktree.js +270 -0
- package/src/tools/ask/ask.js +7 -2
- package/src/tools/bash/bash.js +112 -18
- package/src/tools/download/download.js +144 -0
- package/src/tools/edit/edit.js +1 -0
- package/src/tools/edit/multi-edit.js +1 -0
- package/src/tools/genimage/genimage.js +242 -0
- package/src/tools/genspeech/genspeech.js +67 -0
- package/src/tools/glob/glob.js +1 -0
- package/src/tools/grep/grep.js +3 -0
- package/src/tools/grep/rgPath.js +2 -0
- package/src/tools/index.js +25 -2
- package/src/tools/read/read.js +1 -0
- package/src/tools/shared/killTree.js +52 -0
- package/src/tools/toolProgressBridge.js +48 -0
- package/src/tools/webbrowser/agentBrowserPath.js +258 -0
- package/src/tools/webbrowser/browser.js +59 -42
- package/src/tools/webbrowser/browserControl.js +118 -0
- package/src/tools/webbrowser/browserDaemon.js +97 -0
- package/src/tools/webbrowser/browserService.js +27 -0
- package/src/tools/webbrowser/browserStream.js +119 -0
- package/src/tools/webbrowser/webbrowser.js +699 -130
- package/src/tools/webfetch/webfetch.js +1 -0
- package/src/tools/websearch/websearch.js +134 -51
- package/src/tools/write/write.js +1 -0
- package/src/ui/App.js +249 -22
- package/src/ui/AskQuestion.js +29 -10
- package/src/ui/InputBox.js +104 -12
- package/src/ui/LiveArea.js +112 -19
- package/src/ui/MessageList.js +100 -14
- package/src/ui/ModelPicker.js +56 -0
- package/src/ui/QueuedMessagesBanner.js +14 -0
- package/src/ui/Root.js +18 -10
- package/src/ui/SessionPicker.js +102 -0
- package/src/ui/StatusLine.js +13 -4
- package/src/ui/WorkspacePicker.js +55 -0
- package/src/ui/figures.js +44 -0
- package/src/ui/hooks/askSlot.js +82 -0
- package/src/ui/hooks/useChat.js +358 -64
- package/src/ui/hooks/usePasteHandler.js +11 -1
- package/src/ui/hooks/useTextBuffer.js +1 -3
- package/src/ui/liveViewport.js +5 -1
- package/src/ui/markdown.js +206 -0
- package/src/ui/textBuffer.js +0 -7
- package/src/ui/theme.js +32 -0
- package/src/utils/debugLog.js +0 -4
- package/src/utils/resourcePaths.js +2 -2
- package/src/utils/stripThink.js +50 -0
- package/src/web/browserBridge.js +447 -0
- package/src/web/protocol.js +19 -0
- package/workflows/adaptive-research.yaml +13 -5
- package/workflows/book-review-short.yaml +36 -10
- package/workflows/e2e-write-greet.yaml +6 -2
- package/workflows/illustrate.yaml +227 -0
- package/workflows/plan.yaml +460 -179
- package/workflows/ppt.yaml +1659 -0
- package/workflows/ralph-loop.yaml +199 -0
- package/workflows/schema.json +81 -23
- package/workflows/webppt.yaml +496 -0
- package/workflows/word.yaml +710 -0
- package/workflows/youtube-shorts.yaml +46 -15
- package/MINIMAL-TRACE.md +0 -77
- package/plugins/HOW-TO-WRITE-A-PLUGIN.md +0 -186
- package/plugins/ralph-wiggum/.claude-plugin/plugin.json +0 -9
- package/plugins/ralph-wiggum/README.md +0 -197
- package/plugins/ralph-wiggum/commands/cancel-ralph.md +0 -18
- package/plugins/ralph-wiggum/commands/help.md +0 -137
- package/plugins/ralph-wiggum/commands/ralph-loop.md +0 -85
- package/plugins/ralph-wiggum/hooks/hooks.json +0 -15
- package/plugins/ralph-wiggum/hooks/stop-hook.sh +0 -191
- package/plugins/ralph-wiggum/plugin.js +0 -280
- package/plugins/ralph-wiggum/src/goalState.js +0 -258
- package/plugins/ralph-wiggum/src/sentinels.js +0 -76
- package/plugins/ralph-wiggum/src/stopHookRunner.js +0 -104
- package/plugins/ralph-wiggum/src/verificationGate.js +0 -202
- package/plugins/workflow-runner/src/miniReAct.js +0 -223
- package/plugins/workflow-runner/src/voteHelpers.js +0 -110
- package/skills/config/SKILL.md +0 -123
- package/skills/frontend-design/LICENSE.txt +0 -177
- package/skills/frontend-design/SKILL.md +0 -42
- package/src/ui/ProgressPanel.js +0 -54
- package/src/ui/StreamingBlock.js +0 -11
- package/src/ui/ToolStatus.js +0 -11
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// skills/pptx/scripts/deck_helpers.mjs
|
|
4
|
+
// ----------------------------------------------------------------------------
|
|
5
|
+
// 可复用的「原生 addShape 矢量原语」库(结构图路线)。import 即用,省得每次重写
|
|
6
|
+
// 并重新踩 PptxGenJS 的坑。这些图形是 **PowerPoint 原生对象**,天然每个独立可选中、
|
|
7
|
+
// 可改色、可移动、内部文字可重排 —— 比 SVG 还省事(连「转换为形状」都不用)。
|
|
8
|
+
//
|
|
9
|
+
// 用法(Node,不要 Bun —— 见 pptxgenjs.md 文首铁律):
|
|
10
|
+
// import PptxGenJS from 'pptxgenjs';
|
|
11
|
+
// import { drawCard, drawNode, drawArrow, connect, drawTitle, drawFooter, inkFor } from './deck_helpers.mjs';
|
|
12
|
+
// const pres = new PptxGenJS(); pres.layout = 'LAYOUT_WIDE';
|
|
13
|
+
// const s = pres.addSlide(); s.background = { color: '0F172A' };
|
|
14
|
+
// drawTitle(s, '§1', '架构全景', { bg: '0F172A' }); // 深底 → 标题自动取白字
|
|
15
|
+
// const a = { x: 1, y: 3, w: 2.5, h: 1.2 }, b = { x: 5, y: 3, w: 2.5, h: 1.2 };
|
|
16
|
+
// drawNode(s, a.x, a.y, a.w, a.h, '输入'); drawNode(s, b.x, b.y, b.w, b.h, '输出');
|
|
17
|
+
// connect(s, a, b); // 由两形状边框自动算端点,绝不残桩
|
|
18
|
+
//
|
|
19
|
+
// 说明:位置/尺寸默认值按 LAYOUT_WIDE(13.3" × 7.5")调好;其它 layout 自己传坐标。
|
|
20
|
+
// 颜色一律 6 位 hex、不带 '#'、不带 8 位透明度(透明度走 opacity/transparency 字段)。
|
|
21
|
+
//
|
|
22
|
+
// 内嵌的 PptxGenJS 踩坑防御(每条都曾真实损坏文件或产出难看页,别绕过):
|
|
23
|
+
// - 阴影/option 对象 **每次新建**:PptxGenJS 会 in-place 把值转成 EMU,复用同一对象损坏后续形状。
|
|
24
|
+
// - 颜色禁 '#' 前缀、禁 8 位 hex(assertColor 兜底)。
|
|
25
|
+
// - roundRect 不要叠矩形 accent 条当左边框(盖不住圆角);要精确对齐色条用 rect。
|
|
26
|
+
// - 标题下不画双下划线 accent line(AI 生成 PPT 的典型痕迹,用留白/底色代替)。
|
|
27
|
+
// - **文字对比**:drawTitle / drawNode / drawSectionBadge 会按背景断言可读(assertReadable),
|
|
28
|
+
// 暗字暗底直接抛错 —— 别绕过去手写不检查的 addText。不确定字色就用 inkFor(bg) 自动取。
|
|
29
|
+
// - **连线**:drawArrow 守卫最短长度(< 0.25" 抛错,杜绝残桩箭头);连两个形状一律用
|
|
30
|
+
// connect(from, to)(自动算边到边端点),别手填易飘/易残桩的坐标。
|
|
31
|
+
// ============================================================================
|
|
32
|
+
|
|
33
|
+
const MIN_CONNECTOR_LEN = 0.25; // 英寸:短于此基本是端点重合/算错的残桩箭头(AI PPT 典型缺陷)
|
|
34
|
+
|
|
35
|
+
function assertColor(c) {
|
|
36
|
+
if (typeof c === 'string' && (c.startsWith('#') || c.length === 8)) {
|
|
37
|
+
throw new Error(`bad color "${c}": 用 6 位 hex、不带 #;透明度用 opacity/transparency 字段`);
|
|
38
|
+
}
|
|
39
|
+
return c;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ──────────────── 对比度原语(WCAG 2.1):把「强对比」从口号变成生成期断言 ────────────────
|
|
43
|
+
|
|
44
|
+
function hexToRgb(hex) {
|
|
45
|
+
const h = String(hex).replace(/^#/, '');
|
|
46
|
+
if (!/^[0-9a-fA-F]{6}$/.test(h)) throw new Error(`bad hex "${hex}": 需 6 位十六进制`);
|
|
47
|
+
return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 相对亮度(WCAG 2.1):0(纯黑)~ 1(纯白)。
|
|
51
|
+
export function relLuminance(hex) {
|
|
52
|
+
const [r, g, b] = hexToRgb(hex)
|
|
53
|
+
.map((v) => v / 255)
|
|
54
|
+
.map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
|
|
55
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 对比比(WCAG):1(同色,最差)~ 21(黑白,最佳)。
|
|
59
|
+
export function contrastRatio(a, b) {
|
|
60
|
+
const la = relLuminance(a);
|
|
61
|
+
const lb = relLuminance(b);
|
|
62
|
+
const hi = Math.max(la, lb);
|
|
63
|
+
const lo = Math.min(la, lb);
|
|
64
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 给定背景,返回 dark / light 里与之对比更高的一个(自动选可读字色)。
|
|
68
|
+
export function inkFor(bg, { dark = '0F172A', light = 'FFFFFF' } = {}) {
|
|
69
|
+
return contrastRatio(dark, bg) >= contrastRatio(light, bg) ? dark : light;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 对比不足直接抛错(生成期就炸,附自救提示):把「画不出不可读文字」变成硬约束。
|
|
73
|
+
export function assertReadable(fg, bg, { min = 4.5, label = '' } = {}) {
|
|
74
|
+
const r = contrastRatio(fg, bg);
|
|
75
|
+
if (r < min) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`文字对比度不足:字色 ${fg} / 底色 ${bg} = ${r.toFixed(2)}:1 < ${min}:1` +
|
|
78
|
+
`${label ? `(${label})` : ''}。用 inkFor(bg) 自动取可读字色,或换背景。`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return r;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 尽力从 slide 读已设置的背景色(标准 s.background = { color } 写法);读不到返回 undefined。
|
|
85
|
+
function readSlideBg(slide) {
|
|
86
|
+
try {
|
|
87
|
+
const b = slide && slide.background;
|
|
88
|
+
if (b && typeof b.color === 'string') return b.color;
|
|
89
|
+
const bk = slide && slide.bkgd;
|
|
90
|
+
if (bk && typeof bk.color === 'string') return bk.color;
|
|
91
|
+
} catch {
|
|
92
|
+
/* 内部结构因版本而异,读不到就算了:契约是显式传 bg */
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 阴影:⚠️ 每次返回新对象,绝不复用(PptxGenJS in-place mutate 会损坏第二个形状)。
|
|
98
|
+
export const makeShadow = (o = {}) => ({
|
|
99
|
+
type: 'outer', blur: 8, offset: 2, angle: 90, color: '000000', opacity: 0.12, ...o,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// 矩形(无圆角):用于需要精确对齐的标题底色/分隔条/色块。
|
|
103
|
+
export function drawRect(slide, x, y, w, h, { fill = '1E2761', line, lineWidth = 0, shadow = false } = {}) {
|
|
104
|
+
slide.addShape('rect', {
|
|
105
|
+
x, y, w, h,
|
|
106
|
+
fill: { color: assertColor(fill) },
|
|
107
|
+
...(line ? { line: { color: assertColor(line), width: lineWidth } } : { line: { type: 'none' } }),
|
|
108
|
+
...(shadow ? { shadow: makeShadow() } : {}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 圆角卡片:内容卡/分组容器。
|
|
113
|
+
export function drawCard(slide, x, y, w, h, { fill = 'F8FAFC', border = 'E2E8F0', borderWidth = 1, radius = 0.08, shadow = true } = {}) {
|
|
114
|
+
slide.addShape('roundRect', {
|
|
115
|
+
x, y, w, h,
|
|
116
|
+
fill: { color: assertColor(fill) },
|
|
117
|
+
line: { color: assertColor(border), width: borderWidth },
|
|
118
|
+
rectRadius: radius,
|
|
119
|
+
...(shadow ? { shadow: makeShadow() } : {}),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 架构图节点(圆角矩形/矩形/椭圆 + 居中文字)。kind ∈ round | rect | oval。
|
|
124
|
+
// 文字色与填充色对比不足直接抛错(节点字多为大字,按 AA 大字 3:1 把关)。
|
|
125
|
+
export function drawNode(slide, x, y, w, h, label, { kind = 'round', fill = '1E2761', textColor = 'FFFFFF', fontFace = 'Calibri', fontSize = 12, bold = true, radius = 0.06 } = {}) {
|
|
126
|
+
const shape = kind === 'oval' ? 'ellipse' : kind === 'rect' ? 'rect' : 'roundRect';
|
|
127
|
+
slide.addShape(shape, {
|
|
128
|
+
x, y, w, h,
|
|
129
|
+
fill: { color: assertColor(fill) },
|
|
130
|
+
line: { color: 'FFFFFF', width: 1 },
|
|
131
|
+
...(shape === 'roundRect' ? { rectRadius: radius } : {}),
|
|
132
|
+
});
|
|
133
|
+
if (label) {
|
|
134
|
+
assertReadable(textColor, fill, { min: 3, label: `node "${String(label).replace(/\n/g, ' ')}"` });
|
|
135
|
+
slide.addText(label, { x, y, w, h, fontFace, fontSize, bold, color: assertColor(textColor), align: 'center', valign: 'middle', margin: 0 });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 连线(带可选箭头)。支持任意方向(用 flipV 处理向上)。
|
|
140
|
+
// ⚠️ 守卫最短长度:端点几乎重合(< 0.25")时抛错,杜绝「残桩/无连接箭头」这一 AI PPT 典型缺陷。
|
|
141
|
+
// 要连两个形状请用 connect(slide, from, to)——由形状边框自动算端点,永不残桩、永不飘。
|
|
142
|
+
export function drawArrow(slide, x1, y1, x2, y2, { color = '94A3B8', width = 1.5, dashed = false, arrow = true } = {}) {
|
|
143
|
+
const dx = x2 - x1;
|
|
144
|
+
const dy = y2 - y1;
|
|
145
|
+
const len = Math.hypot(dx, dy);
|
|
146
|
+
if (len < MIN_CONNECTOR_LEN) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`连线过短:长度 ${len.toFixed(3)}" < ${MIN_CONNECTOR_LEN}"(端点 (${x1},${y1})→(${x2},${y2}) 几乎重合)。` +
|
|
149
|
+
'残桩/无连接箭头是 AI PPT 的典型缺陷;连两个形状请用 connect(slide, from, to)。',
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const x = Math.min(x1, x2);
|
|
153
|
+
const y = Math.min(y1, y2);
|
|
154
|
+
const w = Math.abs(dx) || 0.001; // 垂直线给 PptxGenJS 一个极小正宽;总长已由 len 守卫保证
|
|
155
|
+
const h = Math.abs(dy) || 0.001;
|
|
156
|
+
slide.addShape('line', {
|
|
157
|
+
x, y, w, h,
|
|
158
|
+
flipV: y2 < y1,
|
|
159
|
+
line: { color: assertColor(color), width, ...(dashed ? { dashType: 'dash' } : {}), ...(arrow ? { endArrowType: 'triangle' } : {}) },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 连接两个形状:传两个矩形 {x,y,w,h}(英寸),算「中心连线裁到各自边框」得到边到边端点再画箭头。
|
|
164
|
+
// → 端点永远贴住两个真实锚点,杜绝飘移/残桩。两矩形重叠时抛错(没有合理的可见连线)。
|
|
165
|
+
export function connect(slide, from, to, opts = {}) {
|
|
166
|
+
for (const [n, r] of [['from', from], ['to', to]]) {
|
|
167
|
+
if (!r || ['x', 'y', 'w', 'h'].some((k) => typeof r[k] !== 'number')) {
|
|
168
|
+
throw new Error(`connect(): ${n} 需为 {x,y,w,h} 数值矩形(英寸)`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const overlap = !(
|
|
172
|
+
from.x + from.w <= to.x ||
|
|
173
|
+
to.x + to.w <= from.x ||
|
|
174
|
+
from.y + from.h <= to.y ||
|
|
175
|
+
to.y + to.h <= from.y
|
|
176
|
+
);
|
|
177
|
+
if (overlap) {
|
|
178
|
+
throw new Error('connect(): 两个形状重叠,无法画出有意义的连线(先检查布局是否叠加)。');
|
|
179
|
+
}
|
|
180
|
+
const center = (r) => ({ cx: r.x + r.w / 2, cy: r.y + r.h / 2 });
|
|
181
|
+
// 从矩形中心朝 (tx,ty) 方向射线与该矩形边框的交点。
|
|
182
|
+
const edge = (r, tx, ty) => {
|
|
183
|
+
const { cx, cy } = center(r);
|
|
184
|
+
const dx = tx - cx;
|
|
185
|
+
const dy = ty - cy;
|
|
186
|
+
const hw = r.w / 2;
|
|
187
|
+
const hh = r.h / 2;
|
|
188
|
+
const tdx = dx === 0 ? Infinity : hw / Math.abs(dx);
|
|
189
|
+
const tdy = dy === 0 ? Infinity : hh / Math.abs(dy);
|
|
190
|
+
const t = Math.min(tdx, tdy);
|
|
191
|
+
return { x: cx + dx * t, y: cy + dy * t };
|
|
192
|
+
};
|
|
193
|
+
const a = center(from);
|
|
194
|
+
const b = center(to);
|
|
195
|
+
const p1 = edge(from, b.cx, b.cy);
|
|
196
|
+
const p2 = edge(to, a.cx, a.cy);
|
|
197
|
+
drawArrow(slide, p1.x, p1.y, p2.x, p2.y, opts);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 章节徽章(小色块 + 文字),放在标题左上。文字落在 slide 背景上,按背景把可读性把关。
|
|
201
|
+
export function drawSectionBadge(slide, x, y, label, { color = '00A896', textColor, fontFace = 'Consolas', fontSize = 14, bg } = {}) {
|
|
202
|
+
drawRect(slide, x, y, 0.35, 0.32, { fill: color });
|
|
203
|
+
const background = bg ?? readSlideBg(slide);
|
|
204
|
+
const ink = textColor ?? (background ? inkFor(background) : '0F172A');
|
|
205
|
+
if (background) assertReadable(ink, background, { min: 3, label: 'section badge label' });
|
|
206
|
+
slide.addText(label, { x: x + 0.4, y: y - 0.02, w: 4, h: 0.36, fontFace, fontSize, bold: true, color: assertColor(ink), valign: 'middle', margin: 0 });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 标题栏(徽章 + 大标题)。⚠️ 不画标题下的双下划线。
|
|
210
|
+
// 传 bg(或 slide 已设 background)时:标题色默认按背景自动取可读色(inkFor),并断言对比 ≥3:1(大字)。
|
|
211
|
+
// 不传也读不到背景时:保持近黑默认、不断言(向后兼容;但深色页务必传 bg,否则暗字暗底看不清)。
|
|
212
|
+
export function drawTitle(slide, badge, title, { x = 0.5, badgeColor = '00A896', titleColor, titleSize = 28, fontFace = 'Consolas', w = 12.3, bg } = {}) {
|
|
213
|
+
const background = bg ?? readSlideBg(slide);
|
|
214
|
+
const ink = titleColor ?? (background ? inkFor(background) : '0F172A');
|
|
215
|
+
if (background) assertReadable(ink, background, { min: 3, label: 'title' });
|
|
216
|
+
drawSectionBadge(slide, x, 0.35, badge, { color: badgeColor, bg: background });
|
|
217
|
+
slide.addText(title, { x, y: 0.75, w, h: 0.7, fontFace, fontSize: titleSize, bold: true, color: assertColor(ink), valign: 'middle', margin: 0 });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 页脚(左侧文档名 + 右侧页码)。次要文字,按设计可较弱,不强制对比断言。
|
|
221
|
+
export function drawFooter(slide, text, pageLabel, { y = 7.15, x = 0.5, leftW = 8, rightX = 11.3, color = '94A3B8', fontFace = 'Calibri' } = {}) {
|
|
222
|
+
if (text) slide.addText(text, { x, y, w: leftW, h: 0.25, fontFace, fontSize: 9, color: assertColor(color), align: 'left', valign: 'middle', margin: 0 });
|
|
223
|
+
if (pageLabel) slide.addText(pageLabel, { x: rightX, y, w: 1.5, h: 0.25, fontFace, fontSize: 9, color: assertColor(color), align: 'right', valign: 'middle', margin: 0 });
|
|
224
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
layout_lint.py —— PPTX「布局/对比」确定性质量闸门(与 opc_check.py 互补)。
|
|
5
|
+
|
|
6
|
+
为什么需要这个脚本?
|
|
7
|
+
====================
|
|
8
|
+
opc_check.py 管「OPC 合规 = PowerPoint 能否干净打开」(硬阻断)。但合规的包仍可能
|
|
9
|
+
「能打开却难看」:文字与背景对比过低看不清、形状互相叠加、极短/无连接的残桩箭头。
|
|
10
|
+
这些缺陷此前只靠「soffice 截图 + 子 agent 眼检」的视觉 QA 抓——对**其他 agent / 弱模型**
|
|
11
|
+
不可靠(会跳过、会看漏)。
|
|
12
|
+
|
|
13
|
+
本脚本做**不依赖渲染、纯解析 OOXML** 的确定性检查:只读 slide xml 的坐标/颜色,把
|
|
14
|
+
「可计算」的三类缺陷在产物上拦下,给弱模型一道绕不过的防呆门槛。它**不替代**视觉 QA
|
|
15
|
+
(主题色/跨形状层叠/文字截断等仍需眼睛),是其前置硬门槛。
|
|
16
|
+
|
|
17
|
+
和 opc_check.py 一样:只用标准库(zipfile / xml.etree / math / re),忠实于最终消费者
|
|
18
|
+
(Office),不依赖任何宽容的高层库。
|
|
19
|
+
|
|
20
|
+
检查项(任一命中 → 非零退出码 + 人话问题 + 修复提示)
|
|
21
|
+
====================================================
|
|
22
|
+
A. 残桩/过短连线:连接符或 line 类形状长度 < 0.2"(端点重合/算错的残桩箭头,AI PPT 典型缺陷)。
|
|
23
|
+
B. 形状叠加:两个非背景、非包含、非连线形状的包围盒显著相交。
|
|
24
|
+
C. 低对比文字(限可靠场景):形状有显式 solidFill 且其文字 run 有显式颜色时,二者对比
|
|
25
|
+
低于阈值(大字 3:1 / 正文 4.5:1,WCAG)。
|
|
26
|
+
|
|
27
|
+
局限(诚实声明):不解析 theme/scheme 引用色,也不解析「文字浮于其它背景形状之上」的
|
|
28
|
+
跨形状 z-order 层叠——那些由 deck_helpers 的 assertReadable / drawTitle(bg) 与视觉 QA
|
|
29
|
+
覆盖。本脚本只抓「能确定、误报近零」的场景,避免像宽容库一样用噪声侵蚀信任。
|
|
30
|
+
|
|
31
|
+
用法
|
|
32
|
+
====
|
|
33
|
+
python layout_lint.py <file.pptx> # 校验,无缺陷退出 0,有缺陷退出 1
|
|
34
|
+
python layout_lint.py <file.pptx> --verbose # 额外打印 PASSED 明细
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
import argparse
|
|
38
|
+
import math
|
|
39
|
+
import re
|
|
40
|
+
import sys
|
|
41
|
+
import zipfile
|
|
42
|
+
import xml.etree.ElementTree as ET
|
|
43
|
+
|
|
44
|
+
EMU_PER_INCH = 914400.0
|
|
45
|
+
|
|
46
|
+
# OOXML 命名空间(presentationml / drawingml),固定不变。
|
|
47
|
+
P = "{http://schemas.openxmlformats.org/presentationml/2006/main}"
|
|
48
|
+
A = "{http://schemas.openxmlformats.org/drawingml/2006/main}"
|
|
49
|
+
|
|
50
|
+
# 判定「连线/连接符」用的 prstGeom 前缀(line 类原语)。
|
|
51
|
+
LINE_PREFIXES = ("straightConnector", "bentConnector", "curvedConnector")
|
|
52
|
+
|
|
53
|
+
# 阈值
|
|
54
|
+
MIN_CONNECTOR_IN = 0.2 # 短于此判残桩连线
|
|
55
|
+
OVERLAP_MIN_AREA = 0.02 # 叠加最小绝对面积(in²),压住浮点/贴边噪声
|
|
56
|
+
OVERLAP_MIN_FRAC = 0.10 # 叠加须 > 较小形状面积的 10%,才算「显著」
|
|
57
|
+
BIG_BG_FRAC = 0.80 # 面积 ≥ 画布 80% 视为满铺背景,不参与叠加判定
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ──────────────── 对比度(WCAG 2.1,与 deck_helpers.mjs 同一套公式) ────────────────
|
|
61
|
+
|
|
62
|
+
def _hex_to_rgb(h: str):
|
|
63
|
+
h = h.strip().lstrip("#")
|
|
64
|
+
if not re.fullmatch(r"[0-9a-fA-F]{6}", h):
|
|
65
|
+
raise ValueError(f"非 6 位 hex:{h}")
|
|
66
|
+
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _rel_luminance(h: str) -> float:
|
|
70
|
+
def chan(c: float) -> float:
|
|
71
|
+
c = c / 255.0
|
|
72
|
+
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
|
|
73
|
+
|
|
74
|
+
r, g, b = _hex_to_rgb(h)
|
|
75
|
+
return 0.2126 * chan(r) + 0.7152 * chan(g) + 0.0722 * chan(b)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _contrast(a: str, b: str) -> float:
|
|
79
|
+
la, lb = _rel_luminance(a), _rel_luminance(b)
|
|
80
|
+
hi, lo = max(la, lb), min(la, lb)
|
|
81
|
+
return (hi + 0.05) / (lo + 0.05)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# ──────────────── XML 提取小工具 ────────────────
|
|
85
|
+
|
|
86
|
+
def _local(el) -> str:
|
|
87
|
+
return el.tag.split("}")[-1]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _xfrm(el):
|
|
91
|
+
"""返回该形状自身的 (x, y, w, h)(英寸),取不到返回 None。只看自身 xfrm,不下钻子形状。"""
|
|
92
|
+
holder = el.find(P + "spPr")
|
|
93
|
+
if holder is None:
|
|
94
|
+
holder = el.find(P + "grpSpPr")
|
|
95
|
+
xf = holder.find(A + "xfrm") if holder is not None else None
|
|
96
|
+
if xf is None:
|
|
97
|
+
xf = el.find(P + "xfrm") # graphicFrame 用 p:xfrm
|
|
98
|
+
if xf is None:
|
|
99
|
+
return None
|
|
100
|
+
off = xf.find(A + "off")
|
|
101
|
+
ext = xf.find(A + "ext")
|
|
102
|
+
if off is None or ext is None:
|
|
103
|
+
return None
|
|
104
|
+
try:
|
|
105
|
+
return (
|
|
106
|
+
int(off.get("x")) / EMU_PER_INCH,
|
|
107
|
+
int(off.get("y")) / EMU_PER_INCH,
|
|
108
|
+
int(ext.get("cx")) / EMU_PER_INCH,
|
|
109
|
+
int(ext.get("cy")) / EMU_PER_INCH,
|
|
110
|
+
)
|
|
111
|
+
except (TypeError, ValueError):
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _name(el) -> str:
|
|
116
|
+
c = el.find(".//" + P + "cNvPr")
|
|
117
|
+
if c is not None and c.get("name"):
|
|
118
|
+
return c.get("name")
|
|
119
|
+
return _local(el)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _is_connector(el) -> bool:
|
|
123
|
+
if _local(el) == "cxnSp":
|
|
124
|
+
return True
|
|
125
|
+
if _local(el) == "sp":
|
|
126
|
+
g = el.find(P + "spPr/" + A + "prstGeom")
|
|
127
|
+
prst = g.get("prst") if g is not None else None
|
|
128
|
+
if prst == "line" or (prst and prst.startswith(LINE_PREFIXES)):
|
|
129
|
+
return True
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _shape_fill(el):
|
|
134
|
+
sf = el.find(P + "spPr/" + A + "solidFill/" + A + "srgbClr")
|
|
135
|
+
return sf.get("val") if sf is not None and sf.get("val") else None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _low_contrast_runs(el, fill):
|
|
139
|
+
"""形状有显式 fill 时,逐文字 run 检查显式字色与 fill 的对比,返回不达标项。"""
|
|
140
|
+
out = []
|
|
141
|
+
for r in el.findall(".//" + A + "r"):
|
|
142
|
+
rpr = r.find(A + "rPr")
|
|
143
|
+
if rpr is None:
|
|
144
|
+
continue
|
|
145
|
+
clr = rpr.find(A + "solidFill/" + A + "srgbClr")
|
|
146
|
+
if clr is None or not clr.get("val"):
|
|
147
|
+
continue # 主题/方案色不在 v1 范围(局限已在文首声明)
|
|
148
|
+
run_color = clr.get("val")
|
|
149
|
+
try:
|
|
150
|
+
ratio = _contrast(run_color, fill)
|
|
151
|
+
except ValueError:
|
|
152
|
+
continue
|
|
153
|
+
try:
|
|
154
|
+
sz = int(rpr.get("sz")) if rpr.get("sz") else 0
|
|
155
|
+
except ValueError:
|
|
156
|
+
sz = 0
|
|
157
|
+
bold = rpr.get("b") in ("1", "true")
|
|
158
|
+
large = sz >= 1800 or (sz >= 1400 and bold) # WCAG 大字:≥18pt 或 ≥14pt 粗体
|
|
159
|
+
min_ratio = 3.0 if large else 4.5
|
|
160
|
+
if ratio < min_ratio:
|
|
161
|
+
t = r.find(A + "t")
|
|
162
|
+
snippet = (t.text or "").strip()[:20] if t is not None else ""
|
|
163
|
+
out.append((run_color, fill, ratio, min_ratio, snippet))
|
|
164
|
+
return out
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def check_layout(path: str, verbose: bool = False) -> list:
|
|
168
|
+
"""对 pptx 做布局/对比检查,返回问题列表(空 = 无可计算缺陷)。"""
|
|
169
|
+
problems = []
|
|
170
|
+
|
|
171
|
+
if not zipfile.is_zipfile(path):
|
|
172
|
+
return [f"不是合法的 zip/OOXML 包:{path}"]
|
|
173
|
+
|
|
174
|
+
with zipfile.ZipFile(path, "r") as zf:
|
|
175
|
+
names = zf.namelist()
|
|
176
|
+
|
|
177
|
+
# 画布尺寸(取不到则按 LAYOUT_WIDE 13.333"×7.5" 兜底)。
|
|
178
|
+
slide_w, slide_h = 13.333, 7.5
|
|
179
|
+
if "ppt/presentation.xml" in names:
|
|
180
|
+
try:
|
|
181
|
+
pres = ET.fromstring(zf.read("ppt/presentation.xml"))
|
|
182
|
+
sz = pres.find(P + "sldSz")
|
|
183
|
+
if sz is not None and sz.get("cx") and sz.get("cy"):
|
|
184
|
+
slide_w = int(sz.get("cx")) / EMU_PER_INCH
|
|
185
|
+
slide_h = int(sz.get("cy")) / EMU_PER_INCH
|
|
186
|
+
except (ET.ParseError, ValueError):
|
|
187
|
+
pass
|
|
188
|
+
slide_area = slide_w * slide_h
|
|
189
|
+
|
|
190
|
+
slide_names = sorted(
|
|
191
|
+
(n for n in names if re.fullmatch(r"ppt/slides/slide\d+\.xml", n)),
|
|
192
|
+
key=lambda n: int(re.search(r"(\d+)", n.rsplit("/", 1)[-1]).group(1)),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
for sn in slide_names:
|
|
196
|
+
try:
|
|
197
|
+
root = ET.fromstring(zf.read(sn))
|
|
198
|
+
except ET.ParseError:
|
|
199
|
+
continue # 良构由 opc_check 负责,这里跳过
|
|
200
|
+
tree = root.find(P + "cSld/" + P + "spTree")
|
|
201
|
+
if tree is None:
|
|
202
|
+
continue
|
|
203
|
+
label = sn.rsplit("/", 1)[-1]
|
|
204
|
+
rects = [] # 非连线、非满铺背景形状的 (x, y, w, h, name)
|
|
205
|
+
|
|
206
|
+
for el in list(tree):
|
|
207
|
+
if _local(el) not in ("sp", "cxnSp", "pic", "graphicFrame", "grpSp"):
|
|
208
|
+
continue
|
|
209
|
+
box = _xfrm(el)
|
|
210
|
+
|
|
211
|
+
# ── A. 残桩/过短连线 ──
|
|
212
|
+
if _is_connector(el):
|
|
213
|
+
if box is not None:
|
|
214
|
+
length = math.hypot(box[2], box[3])
|
|
215
|
+
if length < MIN_CONNECTOR_IN:
|
|
216
|
+
problems.append(
|
|
217
|
+
f'{label}: 残桩/过短连线「{_name(el)}」长度 {length:.3f}" '
|
|
218
|
+
f'< {MIN_CONNECTOR_IN}"(端点几乎重合,疑似无连接的残桩箭头)'
|
|
219
|
+
)
|
|
220
|
+
continue # 连线不参与叠加判定(穿过形状属正常)
|
|
221
|
+
|
|
222
|
+
# ── C. 低对比文字(仅 sp,限显式色对) ──
|
|
223
|
+
if _local(el) == "sp":
|
|
224
|
+
fill = _shape_fill(el)
|
|
225
|
+
if fill:
|
|
226
|
+
for rc, fc, ratio, minr, snippet in _low_contrast_runs(el, fill):
|
|
227
|
+
tip = f"「{snippet}…」" if snippet else ""
|
|
228
|
+
problems.append(
|
|
229
|
+
f"{label}: 低对比文字{tip}字色 {rc} / 底色 {fc} = "
|
|
230
|
+
f"{ratio:.2f}:1 < {minr}:1(看不清;改字色或底色,用 inkFor(bg))"
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
# ── B. 收集叠加候选 rect ──
|
|
234
|
+
if box is not None:
|
|
235
|
+
x, y, w, h = box
|
|
236
|
+
if w * h >= BIG_BG_FRAC * slide_area:
|
|
237
|
+
continue # 满铺背景,不参与叠加
|
|
238
|
+
rects.append((x, y, w, h, _name(el)))
|
|
239
|
+
|
|
240
|
+
# ── B. 两两包围盒比对 ──
|
|
241
|
+
for i in range(len(rects)):
|
|
242
|
+
ax, ay, aw, ah, an = rects[i]
|
|
243
|
+
for j in range(i + 1, len(rects)):
|
|
244
|
+
bx, by, bw, bh, bn = rects[j]
|
|
245
|
+
ix, iy = max(ax, bx), max(ay, by)
|
|
246
|
+
ix2, iy2 = min(ax + aw, bx + bw), min(ay + ah, by + bh)
|
|
247
|
+
if ix2 <= ix or iy2 <= iy:
|
|
248
|
+
continue # 不相交
|
|
249
|
+
# 包含关系 = 正常(如卡片内文字),跳过
|
|
250
|
+
a_in_b = ax >= bx and ay >= by and ax + aw <= bx + bw and ay + ah <= by + bh
|
|
251
|
+
b_in_a = bx >= ax and by >= ay and bx + bw <= ax + aw and by + bh <= ay + ah
|
|
252
|
+
if a_in_b or b_in_a:
|
|
253
|
+
continue
|
|
254
|
+
inter = (ix2 - ix) * (iy2 - iy)
|
|
255
|
+
smaller = min(aw * ah, bw * bh)
|
|
256
|
+
if inter > OVERLAP_MIN_AREA and inter > OVERLAP_MIN_FRAC * smaller:
|
|
257
|
+
problems.append(
|
|
258
|
+
f'{label}: 形状叠加「{an}」×「{bn}」重叠 {inter:.2f} in²'
|
|
259
|
+
f"(约占较小形状 {inter / smaller * 100:.0f}%;拉开间距 ≥0.3\")"
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
if verbose and not problems:
|
|
263
|
+
print("PASSED 布局/对比检查:无残桩连线 / 无显著叠加 / 无低对比文字")
|
|
264
|
+
|
|
265
|
+
return problems
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def main() -> int:
|
|
269
|
+
parser = argparse.ArgumentParser(
|
|
270
|
+
description="PPTX 布局/对比 确定性质量闸门(与 opc_check.py 互补,仅依赖标准库)"
|
|
271
|
+
)
|
|
272
|
+
parser.add_argument("file", help="要校验的 .pptx 文件")
|
|
273
|
+
parser.add_argument("-v", "--verbose", action="store_true", help="打印 PASSED 明细")
|
|
274
|
+
args = parser.parse_args()
|
|
275
|
+
|
|
276
|
+
problems = check_layout(args.file, verbose=args.verbose)
|
|
277
|
+
if problems:
|
|
278
|
+
print(f"布局/对比检查 FAILED —— {args.file} 存在 {len(problems)} 处问题:")
|
|
279
|
+
for p in problems:
|
|
280
|
+
print(" - " + p)
|
|
281
|
+
print(
|
|
282
|
+
"提示:对比用 deck_helpers 的 inkFor(bg)/assertReadable;"
|
|
283
|
+
"连线用 connect(from, to);叠加拉开间距 ≥0.3\"。"
|
|
284
|
+
"(本检查不替代视觉 QA。)"
|
|
285
|
+
)
|
|
286
|
+
return 1
|
|
287
|
+
|
|
288
|
+
print(f"布局/对比检查 PASSED —— {args.file} 无可计算的布局/对比缺陷(视觉 QA 仍需进行)。")
|
|
289
|
+
return 0
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
if __name__ == "__main__":
|
|
293
|
+
sys.exit(main())
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
layout_lint_test.py —— layout_lint.py 的回归锚(stdlib unittest,仿 opc_check 测试风格)。
|
|
5
|
+
|
|
6
|
+
手搓最小 OOXML(只含 presentation.xml + 一张 slide)分别命中 A/B/C 三类缺陷,
|
|
7
|
+
外加一个「干净例」与一个「卡内文字(包含关系)不应误报」例,断言标记/通过。
|
|
8
|
+
不依赖 PptxGenJS / python-pptx,只用标准库 zip 出最小包喂给 check_layout。
|
|
9
|
+
|
|
10
|
+
运行:python skills/pptx/scripts/layout_lint_test.py
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import tempfile
|
|
16
|
+
import unittest
|
|
17
|
+
import zipfile
|
|
18
|
+
|
|
19
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
20
|
+
from layout_lint import check_layout # noqa: E402
|
|
21
|
+
|
|
22
|
+
EMU = 914400 # 每英寸
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def emu(inches):
|
|
26
|
+
return int(round(inches * EMU))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
PRESENTATION = (
|
|
30
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
31
|
+
'<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" '
|
|
32
|
+
'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">'
|
|
33
|
+
'<p:sldSz cx="12192000" cy="6858000" type="screen16x9"/>'
|
|
34
|
+
'</p:presentation>'
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def filled_text_sp(x, y, w, h, fill, text_color, text="文字", sz=2800, bold=True, name="Box"):
|
|
39
|
+
"""带显式 solidFill + 显式字色文字 run 的矩形 sp。"""
|
|
40
|
+
bold_attr = ' b="1"' if bold else "" # 别在 f-string 表达式里写反斜杠(Py<3.12 报错)
|
|
41
|
+
return (
|
|
42
|
+
f'<p:sp><p:nvSpPr><p:cNvPr id="2" name="{name}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>'
|
|
43
|
+
f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
|
|
44
|
+
f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
|
|
45
|
+
f'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'
|
|
46
|
+
f'<a:solidFill><a:srgbClr val="{fill}"/></a:solidFill></p:spPr>'
|
|
47
|
+
f'<p:txBody><a:bodyPr/><a:p><a:r>'
|
|
48
|
+
f'<a:rPr lang="zh-CN" sz="{sz}"{bold_attr}>'
|
|
49
|
+
f'<a:solidFill><a:srgbClr val="{text_color}"/></a:solidFill></a:rPr>'
|
|
50
|
+
f'<a:t>{text}</a:t></a:r></a:p></p:txBody></p:sp>'
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def plain_rect_sp(x, y, w, h, name="Plain"):
|
|
55
|
+
"""无填充、无文字的矩形(纯叠加候选)。"""
|
|
56
|
+
return (
|
|
57
|
+
f'<p:sp><p:nvSpPr><p:cNvPr id="9" name="{name}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>'
|
|
58
|
+
f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
|
|
59
|
+
f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
|
|
60
|
+
f'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr>'
|
|
61
|
+
f'<p:txBody><a:bodyPr/><a:p/></p:txBody></p:sp>'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def connector(x, y, w, h, name="Conn"):
|
|
66
|
+
return (
|
|
67
|
+
f'<p:cxnSp><p:nvCxnSpPr><p:cNvPr id="5" name="{name}"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>'
|
|
68
|
+
f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
|
|
69
|
+
f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
|
|
70
|
+
f'<a:prstGeom prst="straightConnector1"><a:avLst/></a:prstGeom></p:spPr></p:cxnSp>'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def slide_xml(*shapes):
|
|
75
|
+
body = "".join(shapes)
|
|
76
|
+
return (
|
|
77
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
78
|
+
'<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" '
|
|
79
|
+
'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">'
|
|
80
|
+
f'<p:cSld><p:spTree>{body}</p:spTree></p:cSld></p:sld>'
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def build_pptx(slide_body):
|
|
85
|
+
fd, path = tempfile.mkstemp(suffix=".pptx")
|
|
86
|
+
os.close(fd)
|
|
87
|
+
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:
|
|
88
|
+
z.writestr("ppt/presentation.xml", PRESENTATION)
|
|
89
|
+
z.writestr("ppt/slides/slide1.xml", slide_body)
|
|
90
|
+
return path
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class LayoutLintTest(unittest.TestCase):
|
|
94
|
+
def setUp(self):
|
|
95
|
+
self._paths = []
|
|
96
|
+
|
|
97
|
+
def tearDown(self):
|
|
98
|
+
for p in self._paths:
|
|
99
|
+
try:
|
|
100
|
+
os.remove(p)
|
|
101
|
+
except OSError:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
def _run(self, slide_body):
|
|
105
|
+
path = build_pptx(slide_body)
|
|
106
|
+
self._paths.append(path)
|
|
107
|
+
return check_layout(path)
|
|
108
|
+
|
|
109
|
+
def test_clean_deck_passes(self):
|
|
110
|
+
# 两个不重叠、高对比的填充框 + 一条正常长度连线 → 零问题。
|
|
111
|
+
problems = self._run(
|
|
112
|
+
slide_xml(
|
|
113
|
+
filled_text_sp(1, 1, 3, 1.2, "F8FAFC", "0F172A", name="A"), # 深字浅底
|
|
114
|
+
filled_text_sp(6, 1, 3, 1.2, "1E2761", "FFFFFF", name="B"), # 白字深底
|
|
115
|
+
connector(4.1, 1.6, 1.8, 0.0, name="A→B"), # 1.8" 长,正常
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
self.assertEqual(problems, [], f"干净例不应报问题:{problems}")
|
|
119
|
+
|
|
120
|
+
def test_short_connector_flagged(self):
|
|
121
|
+
problems = self._run(slide_xml(connector(2, 2, 0.05, 0.0, name="Stub")))
|
|
122
|
+
self.assertTrue(any("残桩" in p or "过短连线" in p for p in problems), problems)
|
|
123
|
+
|
|
124
|
+
def test_overlap_flagged(self):
|
|
125
|
+
# A=(1,1,3,3) 与 B=(3,3,3,3) 重叠 1in²,互不包含 → 标记。
|
|
126
|
+
problems = self._run(
|
|
127
|
+
slide_xml(plain_rect_sp(1, 1, 3, 3, name="A"), plain_rect_sp(3, 3, 3, 3, name="B"))
|
|
128
|
+
)
|
|
129
|
+
self.assertTrue(any("叠加" in p for p in problems), problems)
|
|
130
|
+
|
|
131
|
+
def test_low_contrast_flagged(self):
|
|
132
|
+
# 深底(1E2761) + 深字(0F172A) ≈ 1.3:1 < 3 → 标记。
|
|
133
|
+
problems = self._run(
|
|
134
|
+
slide_xml(filled_text_sp(1, 1, 4, 1.5, "1E2761", "0F172A", text="看不清的标题"))
|
|
135
|
+
)
|
|
136
|
+
self.assertTrue(any("低对比" in p for p in problems), problems)
|
|
137
|
+
|
|
138
|
+
def test_containment_not_flagged_as_overlap(self):
|
|
139
|
+
# 小文字框完全落在大卡片内(= 卡内文字),不应被当成叠加。
|
|
140
|
+
problems = self._run(
|
|
141
|
+
slide_xml(
|
|
142
|
+
plain_rect_sp(1, 1, 5, 3, name="Card"),
|
|
143
|
+
filled_text_sp(1.3, 1.3, 3, 1, "F8FAFC", "0F172A", name="Label"),
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
self.assertFalse(any("叠加" in p for p in problems), problems)
|
|
147
|
+
|
|
148
|
+
def test_full_bleed_background_not_overlap(self):
|
|
149
|
+
# 满铺背景(0,0,13.333,7.5) 不参与叠加,即便上面压着内容框也不报叠加。
|
|
150
|
+
problems = self._run(
|
|
151
|
+
slide_xml(
|
|
152
|
+
plain_rect_sp(0, 0, 13.333, 7.5, name="BG"),
|
|
153
|
+
filled_text_sp(1, 1, 4, 1.2, "F8FAFC", "0F172A", name="Content"),
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
self.assertFalse(any("叠加" in p for p in problems), problems)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if __name__ == "__main__":
|
|
160
|
+
unittest.main(verbosity=2)
|