odforge 0.3.1__tar.gz → 0.3.3__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.
- {odforge-0.3.1 → odforge-0.3.3}/PKG-INFO +1 -1
- odforge-0.3.3/src/odforge/__init__.py +1 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/mcp_server.py +9 -5
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/odpedit.py +70 -4
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_editor.py +53 -0
- odforge-0.3.1/src/odforge/__init__.py +0 -1
- {odforge-0.3.1 → odforge-0.3.3}/.gitignore +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/LICENSE +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/README.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/constraints.txt +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/hatch_build.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/pyproject.toml +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/SKILL.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/academic.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/clay.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/color-system.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/crimson.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/dark.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/forest.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/gold.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/minimal.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/navy.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/plum.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/sky.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/slate.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/teal.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/skills/odforge-design/themes/violet.md +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/benchmark.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/check.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/cli.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/components.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/critic.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/docfonts.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/editor_api.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/editor_launch.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/editor_routes.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/extract.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/feedback.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/fontembed.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/ir.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/layoutcheck.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/llm.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/localguard.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/media.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/package.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/pagefacts.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/preview.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/references.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/render/__init__.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/render/odp.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/render/ods.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/render/odt.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/scene.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/setup_agents.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/templates.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/textmetrics.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/textutil.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/themes.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/validate.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/watch.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/webapi.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/xmlsafe.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/src/odforge/zipguard.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/conftest.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_benchmark.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_check.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_cli.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_critic.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_deck_quality.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_editor_launch.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_extract.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_integration_pipeline.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_ir.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_layoutcheck.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_llm.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_localguard.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_mcp.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_media.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_package.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_pagefacts.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_preview.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_render_odp.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_render_ods.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_render_odt.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_setup_agents.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_sources.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_templates.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_textmetrics.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_validate.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_watch.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_webapi.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/tests/test_zipguard.py +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/editor.html +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/index.html +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/package-lock.json +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/package.json +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/App.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/App.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/ConfirmBar.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/ConfirmBar.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/DiscoveryPanel.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/DiscoveryPanel.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/DownloadDock.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/DownloadDock.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/ErrorPanel.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/ErrorPanel.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/GateRail.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/GateRail.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/HomeDashboard.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/HomeDashboard.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/OutlineRail.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/OutlineRail.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/PreviewStage.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/PromptBar.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/PromptBar.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/SideNav.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/StatusNarrator.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/TemplateGallery.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/TemplateGallery.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/TemplatesPage.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/UnitCell.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/UnitDetail.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/UnitDetail.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/WaitingCard.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/display.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/components/preview.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/main.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/Bars.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/Canvas.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/Comments.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/EditorApp.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/Elements.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/PageList.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/SlideView.test.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/SlideView.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/api.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/editor.css +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/geometry.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/geometry.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/main.tsx +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/richtext.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/richtext.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/next/types.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/smoke.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/api.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/api.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/cockpit.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/cockpit.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/discovery.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/discovery.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/errors.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/errors.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/mockStream.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/mockStream.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/sse.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/sse.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/subscribe.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/taskName.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/taskName.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/throttle.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/throttle.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/state/types.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/styles/app.css +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/styles/layout.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/test/setup.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/theme/contrast.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/theme/tokens.css +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/theme/useTheme.test.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/src/theme/useTheme.ts +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/tsconfig.json +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/tsconfig.test.json +0 -0
- {odforge-0.3.1 → odforge-0.3.3}/web/vite.config.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: odforge
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
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.3"
|
|
@@ -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
|
|
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
|
-
|
|
468
|
-
|
|
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()
|
|
@@ -291,8 +345,14 @@ class Document:
|
|
|
291
345
|
for key, attr in (("x", "x"), ("y", "y"), ("w", "width"), ("h", "height")):
|
|
292
346
|
if key in op:
|
|
293
347
|
value = float(op[key])
|
|
348
|
+
# The floor stops a resize from collapsing an element to nothing.
|
|
349
|
+
# A hairline rule that is already thinner (0.02 cm dividers are
|
|
350
|
+
# common) must still be movable: the editor sends the size along
|
|
351
|
+
# with every move, so only a size that *shrinks* is refused.
|
|
294
352
|
if key in ("w", "h") and value < 0.05:
|
|
295
|
-
|
|
353
|
+
current = cm(el.get(q("svg", attr)), 0.0)
|
|
354
|
+
if value < current - 0.001:
|
|
355
|
+
raise EditError("寬度和高度至少要 0.05 cm")
|
|
296
356
|
el.set(q("svg", attr), _len(value))
|
|
297
357
|
|
|
298
358
|
def _text_root(self, el: etree._Element) -> etree._Element:
|
|
@@ -939,8 +999,14 @@ class Document:
|
|
|
939
999
|
def _op_add_rect(self, op: Dict[str, Any]) -> List[str]:
|
|
940
1000
|
page_i = int(op.get("page", 0))
|
|
941
1001
|
page = self._page(page_i)
|
|
1002
|
+
fill = _hex_or_none(op.get("fill"), "fill")
|
|
1003
|
+
stroke = _hex_or_none(op.get("stroke"), "stroke")
|
|
942
1004
|
rect = etree.Element(q("draw", "rect"))
|
|
943
|
-
|
|
1005
|
+
if fill or stroke:
|
|
1006
|
+
style = self._graphic_style(fill=fill, stroke=stroke)
|
|
1007
|
+
else:
|
|
1008
|
+
style = self._ensure_rect_style()
|
|
1009
|
+
rect.set(q("draw", "style-name"), style)
|
|
944
1010
|
for key, attr, default in (
|
|
945
1011
|
("x", "x", 4),
|
|
946
1012
|
("y", "y", 4),
|
|
@@ -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
|
|
@@ -675,3 +713,18 @@ def test_parts_validate_and_use_the_deck_style(deck):
|
|
|
675
713
|
doc.apply([{"op": "add_component", "page": 1, "kind": "rocket"}])
|
|
676
714
|
report = validate_odf(deck, with_soffice=find_soffice() is not None)
|
|
677
715
|
assert report.ok, report.gates
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
def test_a_hairline_rule_can_be_moved_but_not_shrunk_further(deck):
|
|
719
|
+
# Dragging a card moves everything on it, and the editor sends each element's
|
|
720
|
+
# size with its new position. The 0.02 cm divider on the cover card used to
|
|
721
|
+
# fail the minimum-size check, which refused the whole drag.
|
|
722
|
+
doc = Document(deck)
|
|
723
|
+
rule = _el(doc.state(), "0/4")
|
|
724
|
+
assert rule["h"] < 0.05
|
|
725
|
+
state = doc.apply(
|
|
726
|
+
[{"op": "geom", "id": "0/4", "x": rule["x"] + 2, "y": rule["y"] + 1, "w": rule["w"], "h": rule["h"]}]
|
|
727
|
+
)
|
|
728
|
+
assert _el(state, "0/4")["x"] == pytest.approx(rule["x"] + 2)
|
|
729
|
+
with pytest.raises(EditError, match="至少要 0.05"):
|
|
730
|
+
doc.apply([{"op": "geom", "id": "0/4", "h": 0.005}])
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.1"
|
|
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
|
|
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
|
|
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
|