odforge 0.3.0__tar.gz → 0.3.2__tar.gz

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 (174) hide show
  1. {odforge-0.3.0 → odforge-0.3.2}/.gitignore +0 -3
  2. {odforge-0.3.0 → odforge-0.3.2}/PKG-INFO +1 -1
  3. odforge-0.3.2/src/odforge/__init__.py +1 -0
  4. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/mcp_server.py +9 -5
  5. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/odpedit.py +63 -3
  6. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/render/odp.py +10 -2
  7. {odforge-0.3.0 → odforge-0.3.2}/tests/test_editor.py +38 -0
  8. {odforge-0.3.0 → odforge-0.3.2}/tests/test_render_odp.py +26 -0
  9. odforge-0.3.2/web/editor.html +13 -0
  10. odforge-0.3.2/web/index.html +23 -0
  11. {odforge-0.3.0 → odforge-0.3.2}/web/src/App.tsx +10 -1
  12. {odforge-0.3.0 → odforge-0.3.2}/web/src/styles/app.css +3 -10
  13. odforge-0.3.0/src/odforge/__init__.py +0 -1
  14. odforge-0.3.0/web/editor.html +0 -12
  15. odforge-0.3.0/web/index.html +0 -23
  16. {odforge-0.3.0 → odforge-0.3.2}/LICENSE +0 -0
  17. {odforge-0.3.0 → odforge-0.3.2}/README.md +0 -0
  18. {odforge-0.3.0 → odforge-0.3.2}/constraints.txt +0 -0
  19. {odforge-0.3.0 → odforge-0.3.2}/hatch_build.py +0 -0
  20. {odforge-0.3.0 → odforge-0.3.2}/pyproject.toml +0 -0
  21. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/SKILL.md +0 -0
  22. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/academic.md +0 -0
  23. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/clay.md +0 -0
  24. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/color-system.md +0 -0
  25. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/crimson.md +0 -0
  26. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/dark.md +0 -0
  27. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/forest.md +0 -0
  28. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/gold.md +0 -0
  29. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/minimal.md +0 -0
  30. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/navy.md +0 -0
  31. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/plum.md +0 -0
  32. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/sky.md +0 -0
  33. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/slate.md +0 -0
  34. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/teal.md +0 -0
  35. {odforge-0.3.0 → odforge-0.3.2}/skills/odforge-design/themes/violet.md +0 -0
  36. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/benchmark.py +0 -0
  37. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/check.py +0 -0
  38. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/cli.py +0 -0
  39. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/components.py +0 -0
  40. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/critic.py +0 -0
  41. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/docfonts.py +0 -0
  42. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/editor_api.py +0 -0
  43. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/editor_launch.py +0 -0
  44. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/editor_routes.py +0 -0
  45. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/extract.py +0 -0
  46. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/feedback.py +0 -0
  47. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/fontembed.py +0 -0
  48. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/ir.py +0 -0
  49. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/layoutcheck.py +0 -0
  50. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/llm.py +0 -0
  51. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/localguard.py +0 -0
  52. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/media.py +0 -0
  53. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/package.py +0 -0
  54. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/pagefacts.py +0 -0
  55. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/preview.py +0 -0
  56. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/references.py +0 -0
  57. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/render/__init__.py +0 -0
  58. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/render/ods.py +0 -0
  59. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/render/odt.py +0 -0
  60. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/scene.py +0 -0
  61. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/setup_agents.py +0 -0
  62. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/templates.py +0 -0
  63. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/textmetrics.py +0 -0
  64. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/textutil.py +0 -0
  65. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/themes.py +0 -0
  66. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/validate.py +0 -0
  67. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/watch.py +0 -0
  68. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/webapi.py +0 -0
  69. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/xmlsafe.py +0 -0
  70. {odforge-0.3.0 → odforge-0.3.2}/src/odforge/zipguard.py +0 -0
  71. {odforge-0.3.0 → odforge-0.3.2}/tests/conftest.py +0 -0
  72. {odforge-0.3.0 → odforge-0.3.2}/tests/test_benchmark.py +0 -0
  73. {odforge-0.3.0 → odforge-0.3.2}/tests/test_check.py +0 -0
  74. {odforge-0.3.0 → odforge-0.3.2}/tests/test_cli.py +0 -0
  75. {odforge-0.3.0 → odforge-0.3.2}/tests/test_critic.py +0 -0
  76. {odforge-0.3.0 → odforge-0.3.2}/tests/test_deck_quality.py +0 -0
  77. {odforge-0.3.0 → odforge-0.3.2}/tests/test_editor_launch.py +0 -0
  78. {odforge-0.3.0 → odforge-0.3.2}/tests/test_extract.py +0 -0
  79. {odforge-0.3.0 → odforge-0.3.2}/tests/test_integration_pipeline.py +0 -0
  80. {odforge-0.3.0 → odforge-0.3.2}/tests/test_ir.py +0 -0
  81. {odforge-0.3.0 → odforge-0.3.2}/tests/test_layoutcheck.py +0 -0
  82. {odforge-0.3.0 → odforge-0.3.2}/tests/test_llm.py +0 -0
  83. {odforge-0.3.0 → odforge-0.3.2}/tests/test_localguard.py +0 -0
  84. {odforge-0.3.0 → odforge-0.3.2}/tests/test_mcp.py +0 -0
  85. {odforge-0.3.0 → odforge-0.3.2}/tests/test_media.py +0 -0
  86. {odforge-0.3.0 → odforge-0.3.2}/tests/test_package.py +0 -0
  87. {odforge-0.3.0 → odforge-0.3.2}/tests/test_pagefacts.py +0 -0
  88. {odforge-0.3.0 → odforge-0.3.2}/tests/test_preview.py +0 -0
  89. {odforge-0.3.0 → odforge-0.3.2}/tests/test_render_ods.py +0 -0
  90. {odforge-0.3.0 → odforge-0.3.2}/tests/test_render_odt.py +0 -0
  91. {odforge-0.3.0 → odforge-0.3.2}/tests/test_setup_agents.py +0 -0
  92. {odforge-0.3.0 → odforge-0.3.2}/tests/test_sources.py +0 -0
  93. {odforge-0.3.0 → odforge-0.3.2}/tests/test_templates.py +0 -0
  94. {odforge-0.3.0 → odforge-0.3.2}/tests/test_textmetrics.py +0 -0
  95. {odforge-0.3.0 → odforge-0.3.2}/tests/test_validate.py +0 -0
  96. {odforge-0.3.0 → odforge-0.3.2}/tests/test_watch.py +0 -0
  97. {odforge-0.3.0 → odforge-0.3.2}/tests/test_webapi.py +0 -0
  98. {odforge-0.3.0 → odforge-0.3.2}/tests/test_zipguard.py +0 -0
  99. {odforge-0.3.0 → odforge-0.3.2}/web/package-lock.json +0 -0
  100. {odforge-0.3.0 → odforge-0.3.2}/web/package.json +0 -0
  101. {odforge-0.3.0 → odforge-0.3.2}/web/src/App.test.tsx +0 -0
  102. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/ConfirmBar.test.tsx +0 -0
  103. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/ConfirmBar.tsx +0 -0
  104. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/DiscoveryPanel.test.tsx +0 -0
  105. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/DiscoveryPanel.tsx +0 -0
  106. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/DownloadDock.test.tsx +0 -0
  107. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/DownloadDock.tsx +0 -0
  108. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/ErrorPanel.test.tsx +0 -0
  109. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/ErrorPanel.tsx +0 -0
  110. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/GateRail.test.tsx +0 -0
  111. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/GateRail.tsx +0 -0
  112. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/HomeDashboard.test.tsx +0 -0
  113. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/HomeDashboard.tsx +0 -0
  114. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/OutlineRail.test.tsx +0 -0
  115. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/OutlineRail.tsx +0 -0
  116. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/PreviewStage.tsx +0 -0
  117. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/PromptBar.test.tsx +0 -0
  118. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/PromptBar.tsx +0 -0
  119. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/SideNav.tsx +0 -0
  120. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/StatusNarrator.tsx +0 -0
  121. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/TemplateGallery.test.tsx +0 -0
  122. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/TemplateGallery.tsx +0 -0
  123. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/TemplatesPage.tsx +0 -0
  124. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/UnitCell.tsx +0 -0
  125. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/UnitDetail.test.tsx +0 -0
  126. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/UnitDetail.tsx +0 -0
  127. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/WaitingCard.tsx +0 -0
  128. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/display.test.tsx +0 -0
  129. {odforge-0.3.0 → odforge-0.3.2}/web/src/components/preview.test.tsx +0 -0
  130. {odforge-0.3.0 → odforge-0.3.2}/web/src/main.tsx +0 -0
  131. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/Bars.tsx +0 -0
  132. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/Canvas.tsx +0 -0
  133. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/Comments.tsx +0 -0
  134. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/EditorApp.tsx +0 -0
  135. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/Elements.tsx +0 -0
  136. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/PageList.tsx +0 -0
  137. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/SlideView.test.tsx +0 -0
  138. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/SlideView.tsx +0 -0
  139. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/api.ts +0 -0
  140. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/editor.css +0 -0
  141. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/geometry.test.ts +0 -0
  142. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/geometry.ts +0 -0
  143. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/main.tsx +0 -0
  144. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/richtext.test.ts +0 -0
  145. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/richtext.ts +0 -0
  146. {odforge-0.3.0 → odforge-0.3.2}/web/src/next/types.ts +0 -0
  147. {odforge-0.3.0 → odforge-0.3.2}/web/src/smoke.test.ts +0 -0
  148. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/api.test.ts +0 -0
  149. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/api.ts +0 -0
  150. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/cockpit.test.ts +0 -0
  151. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/cockpit.ts +0 -0
  152. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/discovery.test.ts +0 -0
  153. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/discovery.ts +0 -0
  154. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/errors.test.ts +0 -0
  155. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/errors.ts +0 -0
  156. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/mockStream.test.ts +0 -0
  157. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/mockStream.ts +0 -0
  158. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/sse.test.ts +0 -0
  159. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/sse.ts +0 -0
  160. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/subscribe.test.ts +0 -0
  161. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/taskName.test.ts +0 -0
  162. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/taskName.ts +0 -0
  163. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/throttle.test.ts +0 -0
  164. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/throttle.ts +0 -0
  165. {odforge-0.3.0 → odforge-0.3.2}/web/src/state/types.ts +0 -0
  166. {odforge-0.3.0 → odforge-0.3.2}/web/src/styles/layout.test.ts +0 -0
  167. {odforge-0.3.0 → odforge-0.3.2}/web/src/test/setup.ts +0 -0
  168. {odforge-0.3.0 → odforge-0.3.2}/web/src/theme/contrast.test.ts +0 -0
  169. {odforge-0.3.0 → odforge-0.3.2}/web/src/theme/tokens.css +0 -0
  170. {odforge-0.3.0 → odforge-0.3.2}/web/src/theme/useTheme.test.ts +0 -0
  171. {odforge-0.3.0 → odforge-0.3.2}/web/src/theme/useTheme.ts +0 -0
  172. {odforge-0.3.0 → odforge-0.3.2}/web/tsconfig.json +0 -0
  173. {odforge-0.3.0 → odforge-0.3.2}/web/tsconfig.test.json +0 -0
  174. {odforge-0.3.0 → odforge-0.3.2}/web/vite.config.ts +0 -0
@@ -3,11 +3,8 @@
3
3
  __pycache__/
4
4
  *.egg-info
5
5
  dist/
6
- .superpowers/
7
6
  src/odforge/webui/
8
7
  dist_test/
9
8
  .coverage
10
9
  coverage.xml
11
10
  htmlcov/
12
- # Scratch left behind by the QA smoke run (holds one job id, nothing reusable).
13
- qajob.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: odforge
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Forge natural language into native ODF documents (.odt/.odp/.ods)
5
5
  Project-URL: Homepage, https://github.com/FantasySakura0515/ODForge
6
6
  Project-URL: Source, https://github.com/FantasySakura0515/ODForge
@@ -0,0 +1 @@
1
+ __version__ = "0.3.2"
@@ -441,8 +441,10 @@ def edit_odp(path: str, ops: list) -> str:
441
441
  file by hand (``odforge edit``): it changes only what you name, so their edits
442
442
  survive. If the user has the editor open, they see your change within a second.
443
443
 
444
- ``ops`` is a list applied atomically (all or nothing); ids come from
445
- ``outline_odp`` and refer to positions *before* this batch:
444
+ ``ops`` is a list applied atomically (all or nothing); element ids come from
445
+ ``outline_odp`` and refer to elements *before* this batch, whatever earlier ops
446
+ in it delete or add. Ids of elements created in the batch are returned after it
447
+ — style new elements in a second call:
446
448
 
447
449
  * ``{"op": "text", "id": "7/2", "paragraphs": ["第一段", "第二段\n段內換行"]}``
448
450
  — replace text, keeping each paragraph's style. A paragraph may instead be
@@ -451,7 +453,8 @@ def edit_odp(path: str, ops: list) -> str:
451
453
  * ``{"op": "geom", "id": "7/2", "x": 2, "y": 3, "w": 10, "h": 2}`` (cm; any
452
454
  subset). Lines take ``x1/y1/x2/y2``.
453
455
  * ``{"op": "add_text", "page": 0, "x": 2, "y": 2, "w": 10, "h": 1.5, "text": "..."}``,
454
- ``{"op": "add_rect", "page": 0, "x": .., "y": .., "w": .., "h": ..}``
456
+ ``{"op": "add_rect", "page": 0, "x": .., "y": .., "w": .., "h": .., "fill": "#0B6BA8",
457
+ "stroke": "#C9D0D7"}`` (``fill``/``stroke`` optional ``#RRGGBB``; no fill → light grey)
455
458
  * ``{"op": "delete", "id": "7/2"}``, ``{"op": "duplicate", "id": "7/2", "dx": 0.5, "dy": 0.5}``,
456
459
  ``{"op": "order", "id": "7/2", "to": "front" | "back" | "forward" | "backward"}``
457
460
  * ``{"op": "page_add", "after": 3}``, ``{"op": "page_duplicate", "page": 3}``,
@@ -464,8 +467,9 @@ def edit_odp(path: str, ops: list) -> str:
464
467
  ``outline_odp``, make each change, and delete each comment you resolved in the
465
468
  same ``edit_odp`` call — the open editor then shows the page without it.
466
469
 
467
- Deleting several elements of one page: list them from the highest index down,
468
- or later ids shift. Returns ``"ok: ..."`` with the ids of anything created, then
470
+ Page numbers (``page_*`` ops) and comment ids are not pinned: they shift as
471
+ earlier ops in the batch add or remove pages and comments, so delete those
472
+ from the highest index down. Returns ``"ok: ..."`` with the ids of anything created, then
469
473
  the new outline of the pages touched; ``"error: ..."`` if any op was refused.
470
474
  """
471
475
  try:
@@ -17,6 +17,7 @@ import copy
17
17
  import hashlib
18
18
  import json
19
19
  import os
20
+ import re
20
21
  import tempfile
21
22
  import threading
22
23
  import zipfile
@@ -57,12 +58,21 @@ def _len(value: float) -> str:
57
58
  return f"{round(value, 4):g}cm"
58
59
 
59
60
 
61
+ def _hex_or_none(value: Any, field: str) -> Optional[str]:
62
+ if value is None:
63
+ return None
64
+ if not (isinstance(value, str) and re.fullmatch(r"#[0-9A-Fa-f]{6}", value)):
65
+ raise EditError(f"{field} 要是 #RRGGBB 六碼色碼:{value!r}")
66
+ return value.upper()
67
+
68
+
60
69
  class Document:
61
70
  """One ``.odp`` open for editing. Thread-safe; every method saves to disk."""
62
71
 
63
72
  def __init__(self, path: Path) -> None:
64
73
  self.path = Path(path)
65
74
  self._lock = threading.Lock()
75
+ self._pinned: Dict[str, etree._Element] = {}
66
76
  self.version = 0
67
77
  self._load()
68
78
 
@@ -201,7 +211,27 @@ class Document:
201
211
  return pages[i]
202
212
 
203
213
  def _element(self, element_id: Any) -> Tuple[int, int, etree._Element]:
204
- """``"7/2"`` is the third drawable of page 8; ``"7/2.1"`` the second inside that group."""
214
+ """``"7/2"`` is the third drawable of page 8; ``"7/2.1"`` the second inside that group.
215
+
216
+ Inside a batch an id means what it meant before the batch (see ``apply``).
217
+ """
218
+ pinned = self._pinned.get(str(element_id))
219
+ if pinned is not None:
220
+ return self._locate(element_id, pinned)
221
+ return self._resolve(element_id)
222
+
223
+ def _locate(self, element_id: Any, el: etree._Element) -> Tuple[int, int, etree._Element]:
224
+ top = el
225
+ while top.getparent() is not None and top.getparent().tag != q("draw", "page"):
226
+ top = top.getparent()
227
+ page = top.getparent()
228
+ pages = self._pages()
229
+ if page is None or not any(p is page for p in pages):
230
+ raise EditError(f"元素 {element_id} 已在這批操作中被刪除")
231
+ page_i = next(i for i, p in enumerate(pages) if p is page)
232
+ return page_i, drawables(page).index(top), el
233
+
234
+ def _resolve(self, element_id: Any) -> Tuple[int, int, etree._Element]:
205
235
  try:
206
236
  page_part, path = str(element_id).split("/")
207
237
  page_i = int(page_part)
@@ -222,11 +252,18 @@ class Document:
222
252
  # -- history ----------------------------------------------------------------
223
253
 
224
254
  def apply(self, ops: List[Dict[str, Any]]) -> Dict[str, Any]:
225
- """Apply a batch atomically: all of it lands, or none of it does."""
255
+ """Apply a batch atomically: all of it lands, or none of it does.
256
+
257
+ Every element id in the batch is resolved against the document as it was
258
+ before the batch, so ``[delete 6/3, text 6/5]`` edits the element that was
259
+ ``6/5`` and deletes listed in any order remove what was listed. An id that
260
+ did not exist before the batch (one just created) resolves live.
261
+ """
226
262
  with self._lock:
227
263
  self._sync()
228
264
  before = self._serialise()
229
265
  created: List[str] = []
266
+ self._pinned = self._pin_ids(ops)
230
267
  try:
231
268
  for op in ops:
232
269
  created.extend(self._apply_one(op))
@@ -236,6 +273,8 @@ class Document:
236
273
  except Exception as exc:
237
274
  self.content = safe_fromstring(before)
238
275
  raise EditError(f"無法套用這個修改:{type(exc).__name__}: {exc}") from exc
276
+ finally:
277
+ self._pinned = {}
239
278
  if self._serialise() == before:
240
279
  return self._state(created)
241
280
  self._refresh_fonts()
@@ -245,6 +284,21 @@ class Document:
245
284
  self._save()
246
285
  return self._state(created)
247
286
 
287
+ def _pin_ids(self, ops: List[Dict[str, Any]]) -> Dict[str, etree._Element]:
288
+ pinned: Dict[str, etree._Element] = {}
289
+ for op in ops:
290
+ if not isinstance(op, dict):
291
+ continue
292
+ ids = [op.get("id")] + (op.get("ids") if isinstance(op.get("ids"), list) else [])
293
+ for element_id in ids:
294
+ if element_id is None or str(element_id) in pinned:
295
+ continue
296
+ try:
297
+ pinned[str(element_id)] = self._resolve(element_id)[2]
298
+ except EditError:
299
+ pass # reported by the op itself, or created earlier in the batch
300
+ return pinned
301
+
248
302
  def undo(self) -> Dict[str, Any]:
249
303
  with self._lock:
250
304
  self._sync()
@@ -939,8 +993,14 @@ class Document:
939
993
  def _op_add_rect(self, op: Dict[str, Any]) -> List[str]:
940
994
  page_i = int(op.get("page", 0))
941
995
  page = self._page(page_i)
996
+ fill = _hex_or_none(op.get("fill"), "fill")
997
+ stroke = _hex_or_none(op.get("stroke"), "stroke")
942
998
  rect = etree.Element(q("draw", "rect"))
943
- rect.set(q("draw", "style-name"), self._ensure_rect_style())
999
+ if fill or stroke:
1000
+ style = self._graphic_style(fill=fill, stroke=stroke)
1001
+ else:
1002
+ style = self._ensure_rect_style()
1003
+ rect.set(q("draw", "style-name"), style)
944
1004
  for key, attr, default in (
945
1005
  ("x", "x", 4),
946
1006
  ("y", "y", 4),
@@ -1653,8 +1653,16 @@ _COVER_META_W = 8.2
1653
1653
  def _cover_meta(slide: Slide, branding: Branding | None) -> list[str]:
1654
1654
  """What the cover's info card lists: the title slide's own bullets
1655
1655
  (單位、講者、日期、期間). The app-owned byline stays verbatim on its own
1656
- line — it is the user's words, not material to re-layout."""
1657
- return [_line_text(b) for b in slide.bullets if _line_text(b).strip()][:5]
1656
+ line — it is the user's words, not material to re-layout. A nested item
1657
+ is a label with its value, so it reads as one ``標題:內容`` row."""
1658
+ rows = []
1659
+ for item in _coerce_bullet_items(slide.bullets):
1660
+ if isinstance(item, tuple):
1661
+ text, children = item
1662
+ item = f"{text}:{'、'.join(children)}"
1663
+ if item.strip():
1664
+ rows.append(item)
1665
+ return rows[:5]
1658
1666
 
1659
1667
 
1660
1668
  def _cover_meta_xml(
@@ -165,6 +165,44 @@ def test_add_duplicate_order_delete(deck):
165
165
  assert len(_page(state, 0)["elements"]) == count + 2
166
166
 
167
167
 
168
+ def test_ids_in_a_batch_mean_what_they_meant_before_it(deck):
169
+ doc = Document(deck)
170
+ before = doc.state()
171
+ ids = [e["id"] for e in _page(before, 7)["elements"]]
172
+ kept = _el(before, ids[5])
173
+ # Deletes in ascending order used to shift the later ids onto other elements.
174
+ state = doc.apply(
175
+ [
176
+ {"op": "delete", "id": ids[1]},
177
+ {"op": "delete", "id": ids[2]},
178
+ {"op": "geom", "id": ids[5], "x": 1.25},
179
+ ]
180
+ )
181
+ after = _page(state, 7)["elements"]
182
+ assert len(after) == len(ids) - 2
183
+ moved = after[3]
184
+ assert moved["x"] == pytest.approx(1.25)
185
+ assert moved["kind"] == kept["kind"] and moved.get("text") == kept.get("text")
186
+
187
+
188
+ def test_an_element_deleted_earlier_in_the_batch_is_reported(deck):
189
+ doc = Document(deck)
190
+ with pytest.raises(EditError, match="已在這批操作中被刪除"):
191
+ doc.apply([{"op": "delete", "id": "7/2"}, {"op": "text", "id": "7/2", "paragraphs": ["x"]}])
192
+ assert not doc.state()["canUndo"]
193
+
194
+
195
+ def test_add_rect_takes_fill_and_stroke(deck):
196
+ doc = Document(deck)
197
+ state = doc.apply([{"op": "add_rect", "page": 0, "fill": "#0b6ba8", "stroke": "#C9D0D7"}])
198
+ (rect_id,) = state["created"]
199
+ assert _el(state, rect_id)["fill"] == "#0B6BA8"
200
+ state = doc.apply([{"op": "add_rect", "page": 0}])
201
+ assert _el(state, state["created"][0])["fill"] == "#E8ECF4"
202
+ with pytest.raises(EditError, match="#RRGGBB"):
203
+ doc.apply([{"op": "add_rect", "page": 0, "fill": "blue"}])
204
+
205
+
168
206
  def test_page_operations(deck):
169
207
  doc = Document(deck)
170
208
  titles = lambda st: [p["name"] for p in st["scene"]["pages"]] # noqa: E731
@@ -2431,6 +2431,32 @@ def test_byline_is_drawn_on_the_cover_verbatim():
2431
2431
  assert not [x for x in page.findall(".//text:p", NS) if x.text and "王小明" in x.text]
2432
2432
 
2433
2433
 
2434
+ @pytest.mark.parametrize("style", ["passport", "classic", "keynote"])
2435
+ def test_a_cover_with_nested_bullets_lists_them_as_label_and_value(style):
2436
+ # Agents give the cover's facts as nested bullets too; this used to crash
2437
+ # the whole deck with "'BulletItem' object has no attribute 'strip'".
2438
+ deck = Presentation(
2439
+ title="封面資訊",
2440
+ style=style,
2441
+ slides=[
2442
+ {
2443
+ "layout": "title",
2444
+ "title": "臺灣入侵植物離線辨識",
2445
+ "bullets": [
2446
+ {"text": "研究範圍", "children": ["40 種入侵植物"]},
2447
+ {"text": "執行期程"},
2448
+ "申請經費 73,000 元",
2449
+ ],
2450
+ },
2451
+ {"layout": "title-content", "title": "內容頁", "bullets": ["一點"]},
2452
+ ],
2453
+ )
2454
+ page = _content_root(deck, THEMES["academic"]).findall(".//draw:page", NS)[0]
2455
+ drawn = "".join(page.itertext())
2456
+ for row in ("研究範圍:40 種入侵植物", "執行期程", "申請經費 73,000 元"):
2457
+ assert row in drawn
2458
+
2459
+
2434
2460
  def test_no_branding_renders_exactly_as_before():
2435
2461
  plain = _branded_deck()
2436
2462
  plain = Presentation(title=plain.title, slides=plain.slides)
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="zh-Hant">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGl0bGU+T0RGb3JnZSDmlofpjZs8L3RpdGxlPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiByeD0iMjIiIGZpbGw9IiMxZDQzODQiLz48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSg5IDcpIHNjYWxlKC44MikiPjxwYXRoIGQ9Ik00IDYwSDkwVjY3UTkwIDcxIDg2IDcxSDcwTDY0IDc5SDc0VjkySDI2Vjc5SDM2TDMwIDcxSDIwUTggNzEgNCA2MFoiIGZpbGw9IiM5ZmMwZjUiLz48cGF0aCBkPSJNMzAgOEg1OEw3MiAyMlY1OEgzMFoiIGZpbGw9IiNmZmYiIHN0cm9rZT0iIzEzMjk0ZiIgc3Ryb2tlLXdpZHRoPSI2IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTU4IDhWMjJINzIiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzEzMjk0ZiIgc3Ryb2tlLXdpZHRoPSI2IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTM5IDMySDYzTTM5IDQxSDYzTTM5IDQ5SDUzIiBzdHJva2U9IiMxMzI5NGYiIHN0cm9rZS13aWR0aD0iNSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+PHBhdGggZD0iTTc3IDE3TDg2IDlNODAgMjdMOTIgMjVNNzEgMTBMNzMgMyIgc3Ryb2tlPSIjZTA0NTdiIiBzdHJva2Utd2lkdGg9IjYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPjwvZz48L3N2Zz4=" />
7
+ <title>文鍛 編輯器</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/next/main.tsx"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,23 @@
1
+ <!doctype html>
2
+ <html lang="zh-Hant">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <meta name="color-scheme" content="light dark" />
7
+ <meta
8
+ name="description"
9
+ content="用一句話生成可編輯、經過結構與 LibreOffice 驗證的原生 OpenDocument 文件。"
10
+ />
11
+ <meta name="theme-color" content="#e9e6dc" />
12
+ <link
13
+ rel="icon"
14
+ type="image/svg+xml"
15
+ href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGl0bGU+T0RGb3JnZSDmlofpjZs8L3RpdGxlPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiByeD0iMjIiIGZpbGw9IiMxZDQzODQiLz48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSg5IDcpIHNjYWxlKC44MikiPjxwYXRoIGQ9Ik00IDYwSDkwVjY3UTkwIDcxIDg2IDcxSDcwTDY0IDc5SDc0VjkySDI2Vjc5SDM2TDMwIDcxSDIwUTggNzEgNCA2MFoiIGZpbGw9IiM5ZmMwZjUiLz48cGF0aCBkPSJNMzAgOEg1OEw3MiAyMlY1OEgzMFoiIGZpbGw9IiNmZmYiIHN0cm9rZT0iIzEzMjk0ZiIgc3Ryb2tlLXdpZHRoPSI2IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTU4IDhWMjJINzIiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzEzMjk0ZiIgc3Ryb2tlLXdpZHRoPSI2IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTM5IDMySDYzTTM5IDQxSDYzTTM5IDQ5SDUzIiBzdHJva2U9IiMxMzI5NGYiIHN0cm9rZS13aWR0aD0iNSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+PHBhdGggZD0iTTc3IDE3TDg2IDlNODAgMjdMOTIgMjVNNzEgMTBMNzMgMyIgc3Ryb2tlPSIjZTA0NTdiIiBzdHJva2Utd2lkdGg9IjYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPjwvZz48L3N2Zz4="
16
+ />
17
+ <title>文鍛 ODForge|把一句話鍛成可交付的文件</title>
18
+ </head>
19
+ <body>
20
+ <div id="root"></div>
21
+ <script type="module" src="/src/main.tsx"></script>
22
+ </body>
23
+ </html>
@@ -385,7 +385,16 @@ export default function App() {
385
385
  <header className="sitebar">
386
386
  <div className="sitebar-inner">
387
387
  <button type="button" className="brand" aria-label="回到首頁" onClick={goHome}>
388
- <span className="brand-seal" aria-hidden="true">文</span>
388
+ <svg className="brand-seal" viewBox="0 0 100 100" aria-hidden="true">
389
+ <rect width="100" height="100" rx="22" fill="#1d4384" />
390
+ <g transform="translate(9 7) scale(.82)">
391
+ <path d="M4 60H90V67Q90 71 86 71H70L64 79H74V92H26V79H36L30 71H20Q8 71 4 60Z" fill="#9fc0f5" />
392
+ <path d="M30 8H58L72 22V58H30Z" fill="#fff" stroke="#13294f" strokeWidth="6" strokeLinejoin="round" />
393
+ <path d="M58 8V22H72" fill="none" stroke="#13294f" strokeWidth="6" strokeLinejoin="round" />
394
+ <path d="M39 32H63M39 41H63M39 49H53" stroke="#13294f" strokeWidth="5" strokeLinecap="round" />
395
+ <path d="M77 17L86 9M80 27L92 25M71 10L73 3" stroke="#e0457b" strokeWidth="6" strokeLinecap="round" />
396
+ </g>
397
+ </svg>
389
398
  <span className="brand-copy">
390
399
  <span className="mark">文鍛</span>
391
400
  <span className="en">ODForge</span>
@@ -112,17 +112,10 @@ button { color: inherit; }
112
112
  .brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }
113
113
 
114
114
  .brand-seal {
115
- display: grid;
115
+ display: block;
116
116
  width: 38px;
117
117
  height: 38px;
118
- place-items: center;
119
- color: var(--on-accent);
120
- background: var(--accent);
121
- border-radius: 4px 11px 4px 4px;
122
- font-family: var(--f-brand);
123
- font-size: 20px;
124
- font-weight: 700;
125
- line-height: 1;
118
+ border-radius: 9px;
126
119
  box-shadow: 0 8px 20px -10px var(--glow);
127
120
  }
128
121
 
@@ -3591,7 +3584,7 @@ button.finding:focus-visible { outline: 2px solid var(--accent); outline-offset:
3591
3584
  }
3592
3585
 
3593
3586
  .brand { gap: 9px; }
3594
- .brand-seal { width: 34px; height: 34px; font-size: 18px; }
3587
+ .brand-seal { width: 34px; height: 34px; }
3595
3588
  .brand .mark { font-size: 17px; }
3596
3589
  .brand .en { display: none; }
3597
3590
  .sitebar-status { gap: 7px; }
@@ -1 +0,0 @@
1
- __version__ = "0.3.0"
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-Hant">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>文鍛 編輯器</title>
7
- </head>
8
- <body>
9
- <div id="root"></div>
10
- <script type="module" src="/src/next/main.tsx"></script>
11
- </body>
12
- </html>
@@ -1,23 +0,0 @@
1
- <!doctype html>
2
- <html lang="zh-Hant">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <meta name="color-scheme" content="light dark" />
7
- <meta
8
- name="description"
9
- content="用一句話生成可編輯、經過結構與 LibreOffice 驗證的原生 OpenDocument 文件。"
10
- />
11
- <meta name="theme-color" content="#e9e6dc" />
12
- <link
13
- rel="icon"
14
- type="image/svg+xml"
15
- href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMiAzMiI+PHJlY3Qgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIiByeD0iNyIgZmlsbD0iIzIzNGU5ZSIvPjx0ZXh0IHg9IjE2IiB5PSIyMyIgZm9udC1zaXplPSIyMSIgZm9udC1mYW1pbHk9Ikdlb3JnaWEsJmFwb3M7Tm90byBTZXJpZiBUQyZhcG9zOyxzZXJpZiIgZm9udC13ZWlnaHQ9IjcwMCIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZmlsbD0iI2ZmZiI+5paHPC90ZXh0Pjwvc3ZnPg=="
16
- />
17
- <title>文鍛 ODForge|把一句話鍛成可交付的文件</title>
18
- </head>
19
- <body>
20
- <div id="root"></div>
21
- <script type="module" src="/src/main.tsx"></script>
22
- </body>
23
- </html>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes