odforge 0.3.0__py3-none-any.whl
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/__init__.py +1 -0
- odforge/benchmark.py +287 -0
- odforge/check.py +416 -0
- odforge/cli.py +1027 -0
- odforge/components.py +270 -0
- odforge/critic.py +1260 -0
- odforge/docfonts.py +104 -0
- odforge/editor_api.py +33 -0
- odforge/editor_launch.py +134 -0
- odforge/editor_routes.py +131 -0
- odforge/extract.py +478 -0
- odforge/feedback.py +86 -0
- odforge/fontembed.py +166 -0
- odforge/ir.py +1181 -0
- odforge/layoutcheck.py +602 -0
- odforge/llm.py +1865 -0
- odforge/localguard.py +42 -0
- odforge/mcp_server.py +552 -0
- odforge/media.py +352 -0
- odforge/odpedit.py +1219 -0
- odforge/package.py +114 -0
- odforge/pagefacts.py +388 -0
- odforge/preview.py +104 -0
- odforge/references.py +153 -0
- odforge/render/__init__.py +40 -0
- odforge/render/odp.py +5687 -0
- odforge/render/ods.py +155 -0
- odforge/render/odt.py +223 -0
- odforge/scene.py +657 -0
- odforge/setup_agents.py +274 -0
- odforge/skills/odforge-design/SKILL.md +298 -0
- odforge/skills/odforge-design/themes/academic.md +52 -0
- odforge/skills/odforge-design/themes/clay.md +53 -0
- odforge/skills/odforge-design/themes/color-system.md +59 -0
- odforge/skills/odforge-design/themes/crimson.md +53 -0
- odforge/skills/odforge-design/themes/dark.md +53 -0
- odforge/skills/odforge-design/themes/forest.md +54 -0
- odforge/skills/odforge-design/themes/gold.md +53 -0
- odforge/skills/odforge-design/themes/minimal.md +53 -0
- odforge/skills/odforge-design/themes/navy.md +56 -0
- odforge/skills/odforge-design/themes/plum.md +53 -0
- odforge/skills/odforge-design/themes/sky.md +53 -0
- odforge/skills/odforge-design/themes/slate.md +53 -0
- odforge/skills/odforge-design/themes/teal.md +53 -0
- odforge/skills/odforge-design/themes/violet.md +56 -0
- odforge/templates.py +250 -0
- odforge/textmetrics.py +616 -0
- odforge/textutil.py +24 -0
- odforge/themes.py +886 -0
- odforge/validate.py +403 -0
- odforge/watch.py +266 -0
- odforge/webapi.py +2617 -0
- odforge/webui/assets/editor-CjpYXM1a.css +1 -0
- odforge/webui/assets/editor-DPToJGio.js +3 -0
- odforge/webui/assets/jsx-runtime-C7KMcVI_.js +8 -0
- odforge/webui/assets/main-BLOs7Hnk.js +7 -0
- odforge/webui/assets/main-D21yFVE6.css +1 -0
- odforge/webui/editor.html +14 -0
- odforge/webui/index.html +25 -0
- odforge/xmlsafe.py +46 -0
- odforge/zipguard.py +91 -0
- odforge-0.3.0.dist-info/METADATA +95 -0
- odforge-0.3.0.dist-info/RECORD +66 -0
- odforge-0.3.0.dist-info/WHEEL +4 -0
- odforge-0.3.0.dist-info/entry_points.txt +3 -0
- odforge-0.3.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# violet — 午夜紫 + 電光紫
|
|
2
|
+
|
|
3
|
+
給 LLM 讀的規格書。這些數值是 `odforge.themes.THEMES["violet"]` 與
|
|
4
|
+
`SCALES["standard"]` 的鏡像,兩者以測試 lockstep 綁定,改一邊必須改另一邊。
|
|
5
|
+
|
|
6
|
+
**定位**:午夜紫黑底配電光紫強調、淺色文字——暗底的第二選擇。比 dark 的亮青更暖、
|
|
7
|
+
更有創意戲劇性。適合創意提案、設計與品牌敘事、技術 demo、暗場舞台簡報——任何想要
|
|
8
|
+
科技感又帶一點高級創意氛圍的場合。深底讓電光紫與大數字像會發光一樣跳出來。
|
|
9
|
+
|
|
10
|
+
與 **dark** 的區隔:dark 是深靛 + 亮青,偏冷、偏工程;violet 是午夜紫 + 電光紫,
|
|
11
|
+
偏暖、偏創意。想要冷靜技術感選 dark,想要創意戲劇感選 violet。
|
|
12
|
+
|
|
13
|
+
## 調色盤(hex)
|
|
14
|
+
|
|
15
|
+
| token | hex | 說明 |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| bg | #1A1526 | 頁面背景:午夜紫黑,接近夜色 |
|
|
18
|
+
| surface | #2A2440 | 卡片/色塊底:比 bg 亮一階的深紫 |
|
|
19
|
+
| text | #ECEAF4 | 主要內文:近白的冷灰,暗底上清楚可讀 |
|
|
20
|
+
| muted | #9A93B8 | 次要文字:註解、attribution、caption |
|
|
21
|
+
| accent | #B49BF5 | 強調色:電光紫,用在標題、highlight 長條、關鍵字 |
|
|
22
|
+
| title_color | #ECEAF4 | 標題色:與 text 同(此主題不另外覆寫)|
|
|
23
|
+
|
|
24
|
+
對比:text/bg、accent/bg、muted/bg 皆已通過 WCAG 門檻
|
|
25
|
+
(text/bg ≥ 4.5、accent/bg ≥ 3.0、muted/bg ≥ 3.0)。暗底主題尤其要守住這條,
|
|
26
|
+
淺文字掉到中灰就會糊。若你另外覆寫 DesignSpec 調色盤,務必自行重算對比。
|
|
27
|
+
|
|
28
|
+
## 字級刻度(pt,standard 密度)
|
|
29
|
+
|
|
30
|
+
| role | pt | 用途 |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| display | 54 | 封面主標、big-fact 數字 |
|
|
33
|
+
| h1 | 28 | 內頁標題、section 分隔標題 |
|
|
34
|
+
| body | 18 | 條列與內文 |
|
|
35
|
+
| caption | 13 | 註解、資料來源、attribution |
|
|
36
|
+
|
|
37
|
+
## 字型
|
|
38
|
+
|
|
39
|
+
- 標題(display):**Noto Sans TC** — sans 在暗底最俐落,避免 serif 細筆糊掉。
|
|
40
|
+
- 內文(body):**Noto Sans TC** — 同家族,靠字級與電光紫強調分層次。
|
|
41
|
+
- 皆在 `FONT_WHITELIST` 內,CJK 覆蓋完整。
|
|
42
|
+
|
|
43
|
+
## 各版型使用時機
|
|
44
|
+
|
|
45
|
+
| 版型 | 使用時機 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| title | 封面:講題大字,電光紫點在關鍵詞,暗場開場最有戲 |
|
|
48
|
+
| agenda | 大綱頁:長講的路線圖,先讓聽眾知道會走到哪 |
|
|
49
|
+
| title-content | 主力內頁:一頁一個概念,條列別塞滿,留黑呼吸 |
|
|
50
|
+
| section | 章節分隔:切換 demo 段落、切換主題時的過場 |
|
|
51
|
+
| two-col | 並列:概念前後、程式碼 vs 結果 |
|
|
52
|
+
| comparison | 對照:舊做法 vs 新做法,電光紫標出改良的一欄 |
|
|
53
|
+
| big-fact | 關鍵數據:效能提升、成長倍數——大數字在暗底最發光 |
|
|
54
|
+
| quote | 引述:使用者回饋、名言,attribution 標出處 |
|
|
55
|
+
| chart | 圖表:**只有真實數據**才用,最多 8 條長條,highlight 用電光紫 |
|
|
56
|
+
| closing | 結尾:一句收束 + repo/聯絡資訊 |
|
odforge/templates.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""Deck templates (範本庫): the built-in presets plus the user's own designs.
|
|
2
|
+
|
|
3
|
+
A *template* is a name and a :class:`~odforge.ir.DesignSpec`. The thirteen
|
|
4
|
+
built-in art directions (:data:`odforge.themes.THEMES`) are exposed through the
|
|
5
|
+
same shape as user-saved ones so a gallery can list them together, but they are
|
|
6
|
+
read-only: deleting or overwriting a preset would break every deck that names it
|
|
7
|
+
by id.
|
|
8
|
+
|
|
9
|
+
User templates are stored as one JSON file inside the sessions directory, which
|
|
10
|
+
is where everything else the user owns already lives (so a backup of that folder
|
|
11
|
+
keeps their templates too). Writes go through a temp file + ``os.replace`` so an
|
|
12
|
+
interrupted save cannot leave a half-written library behind.
|
|
13
|
+
|
|
14
|
+
Two ways to make one, both of which end at the same ``DesignSpec``:
|
|
15
|
+
|
|
16
|
+
* hand-picked colours and fonts (validated by ``DesignSpec`` — an unreadable
|
|
17
|
+
palette is rejected by the same WCAG bars the renderer trusts), and
|
|
18
|
+
* :func:`odforge.extract.extract_design` on an existing ``.otp``/``.odp``
|
|
19
|
+
template file, which is how a school's official deck becomes a template here.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import time
|
|
27
|
+
import uuid
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
from typing import List, Optional
|
|
30
|
+
|
|
31
|
+
from pydantic import Field, field_validator
|
|
32
|
+
|
|
33
|
+
from odforge.ir import DesignSpec, FontPair, Palette, StrictModel
|
|
34
|
+
from odforge.themes import (
|
|
35
|
+
DEFAULT_STYLE,
|
|
36
|
+
STYLES,
|
|
37
|
+
THEME_LABELS,
|
|
38
|
+
THEME_STYLE,
|
|
39
|
+
THEMES,
|
|
40
|
+
theme_scale,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# A library is a personal shortlist, not a catalogue. The cap exists so a script
|
|
44
|
+
# in a loop cannot grow the file without bound.
|
|
45
|
+
MAX_USER_TEMPLATES = 50
|
|
46
|
+
MAX_NAME_CHARS = 40
|
|
47
|
+
|
|
48
|
+
TEMPLATES_FILENAME = "templates.json"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Template(StrictModel):
|
|
52
|
+
"""One entry in the gallery: a named design, built-in or user-owned."""
|
|
53
|
+
|
|
54
|
+
id: str = Field(min_length=1, max_length=64)
|
|
55
|
+
name: str = Field(min_length=1, max_length=MAX_NAME_CHARS)
|
|
56
|
+
design: DesignSpec
|
|
57
|
+
# 版式: the layout personality. Colour alone made every template the same
|
|
58
|
+
# document in different paint; this is the half that changes composition.
|
|
59
|
+
style: str = DEFAULT_STYLE
|
|
60
|
+
# Built-ins are read-only and are sent to the API as ``theme: <id>``;
|
|
61
|
+
# user templates travel as a full ``design`` payload.
|
|
62
|
+
builtin: bool = False
|
|
63
|
+
# "builtin" | "custom" (hand-picked) | "extracted" (from an ODF template).
|
|
64
|
+
source: str = "custom"
|
|
65
|
+
created_at: float = 0.0
|
|
66
|
+
|
|
67
|
+
@field_validator("style")
|
|
68
|
+
@classmethod
|
|
69
|
+
def _known_style(cls, value: str) -> str:
|
|
70
|
+
if value not in STYLES:
|
|
71
|
+
raise ValueError(f"unknown style; available: {sorted(STYLES)}")
|
|
72
|
+
return value
|
|
73
|
+
|
|
74
|
+
@field_validator("name")
|
|
75
|
+
@classmethod
|
|
76
|
+
def _name_not_blank(cls, value: str) -> str:
|
|
77
|
+
value = value.strip()
|
|
78
|
+
if not value:
|
|
79
|
+
raise ValueError("template name must not be blank")
|
|
80
|
+
return value
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def design_of_theme(theme_id: str) -> DesignSpec:
|
|
84
|
+
"""The built-in preset ``theme_id`` expressed as an editable DesignSpec.
|
|
85
|
+
|
|
86
|
+
This is what makes "以內建主題為底改一版" possible in the gallery: the preset
|
|
87
|
+
is a resolved :class:`~odforge.themes.Theme` (four point sizes), and a spec
|
|
88
|
+
needs the tier name those sizes came from.
|
|
89
|
+
"""
|
|
90
|
+
theme = THEMES[theme_id]
|
|
91
|
+
return DesignSpec(
|
|
92
|
+
palette=Palette(
|
|
93
|
+
bg=theme.bg,
|
|
94
|
+
surface=theme.surface,
|
|
95
|
+
text=theme.text,
|
|
96
|
+
muted=theme.muted,
|
|
97
|
+
accent=theme.accent,
|
|
98
|
+
),
|
|
99
|
+
fonts=FontPair(display=theme.font_display, body=theme.font_body),
|
|
100
|
+
scale=theme_scale(theme),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def builtin_templates() -> List[Template]:
|
|
105
|
+
"""The thirteen presets, in the order :data:`THEME_LABELS` declares them."""
|
|
106
|
+
return [
|
|
107
|
+
Template(
|
|
108
|
+
id=theme_id,
|
|
109
|
+
name=THEME_LABELS[theme_id],
|
|
110
|
+
design=design_of_theme(theme_id),
|
|
111
|
+
style=THEME_STYLE.get(theme_id, DEFAULT_STYLE),
|
|
112
|
+
builtin=True,
|
|
113
|
+
source="builtin",
|
|
114
|
+
)
|
|
115
|
+
for theme_id in THEME_LABELS
|
|
116
|
+
if theme_id in THEMES
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def templates_path(sessions_dir: Path) -> Path:
|
|
121
|
+
"""Where the user's library lives for a given sessions directory."""
|
|
122
|
+
return Path(sessions_dir) / TEMPLATES_FILENAME
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def load_user_templates(path: Path) -> List[Template]:
|
|
126
|
+
"""Read the user's templates; an unreadable library reads as empty.
|
|
127
|
+
|
|
128
|
+
A corrupt file must not take the whole console down with it — the gallery
|
|
129
|
+
degrades to "built-ins only". Nothing is deleted here: :func:`save_template`
|
|
130
|
+
moves the bad file aside (rather than overwriting it) the next time the user
|
|
131
|
+
saves, so the original is still on disk to look at.
|
|
132
|
+
"""
|
|
133
|
+
if not path.is_file():
|
|
134
|
+
return []
|
|
135
|
+
try:
|
|
136
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
137
|
+
except (OSError, json.JSONDecodeError):
|
|
138
|
+
return []
|
|
139
|
+
if not isinstance(data, list):
|
|
140
|
+
return []
|
|
141
|
+
templates: List[Template] = []
|
|
142
|
+
for item in data:
|
|
143
|
+
try:
|
|
144
|
+
template = Template.model_validate(item)
|
|
145
|
+
except Exception: # one bad row must not lose the rest
|
|
146
|
+
continue
|
|
147
|
+
if template.builtin:
|
|
148
|
+
# A preset id in the user file would shadow the read-only original.
|
|
149
|
+
continue
|
|
150
|
+
templates.append(template)
|
|
151
|
+
return templates
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def all_templates(path: Path) -> List[Template]:
|
|
155
|
+
"""Built-ins first, then the user's own (newest last)."""
|
|
156
|
+
return builtin_templates() + load_user_templates(path)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _write(path: Path, templates: List[Template]) -> None:
|
|
160
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
161
|
+
payload = json.dumps(
|
|
162
|
+
[t.model_dump(mode="json") for t in templates],
|
|
163
|
+
ensure_ascii=False,
|
|
164
|
+
indent=2,
|
|
165
|
+
)
|
|
166
|
+
tmp = path.with_suffix(path.suffix + ".tmp")
|
|
167
|
+
tmp.write_text(payload, encoding="utf-8")
|
|
168
|
+
os.replace(tmp, path)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def save_template(
|
|
172
|
+
path: Path,
|
|
173
|
+
*,
|
|
174
|
+
name: str,
|
|
175
|
+
design: DesignSpec,
|
|
176
|
+
style: str = DEFAULT_STYLE,
|
|
177
|
+
source: str = "custom",
|
|
178
|
+
template_id: Optional[str] = None,
|
|
179
|
+
) -> Template:
|
|
180
|
+
"""Add a template, or replace the one whose id is ``template_id``.
|
|
181
|
+
|
|
182
|
+
Raises ``ValueError`` when the library is full, when ``template_id`` names a
|
|
183
|
+
built-in preset, or when it names a template that no longer exists (editing
|
|
184
|
+
something another tab already deleted must not silently re-create it).
|
|
185
|
+
"""
|
|
186
|
+
if template_id is not None and template_id in THEMES:
|
|
187
|
+
raise ValueError("內建範本不可覆寫,請另存新範本。")
|
|
188
|
+
existing = load_user_templates(path)
|
|
189
|
+
if path.is_file() and not existing and path.stat().st_size > 0:
|
|
190
|
+
# Unreadable library + a save on top of it would destroy whatever was
|
|
191
|
+
# there. Keep the original under a new name instead.
|
|
192
|
+
path.replace(path.with_suffix(path.suffix + ".corrupt"))
|
|
193
|
+
now = time.time()
|
|
194
|
+
if template_id is None:
|
|
195
|
+
if len(existing) >= MAX_USER_TEMPLATES:
|
|
196
|
+
raise ValueError(
|
|
197
|
+
f"自訂範本已達上限 {MAX_USER_TEMPLATES} 個,請先刪除不用的範本。"
|
|
198
|
+
)
|
|
199
|
+
template = Template(
|
|
200
|
+
id=f"tpl-{uuid.uuid4().hex[:12]}",
|
|
201
|
+
name=name,
|
|
202
|
+
design=design,
|
|
203
|
+
style=style,
|
|
204
|
+
source=source,
|
|
205
|
+
created_at=now,
|
|
206
|
+
)
|
|
207
|
+
existing.append(template)
|
|
208
|
+
_write(path, existing)
|
|
209
|
+
return template
|
|
210
|
+
|
|
211
|
+
for index, current in enumerate(existing):
|
|
212
|
+
if current.id == template_id:
|
|
213
|
+
template = Template(
|
|
214
|
+
id=template_id,
|
|
215
|
+
name=name,
|
|
216
|
+
design=design,
|
|
217
|
+
style=style,
|
|
218
|
+
source=source,
|
|
219
|
+
created_at=current.created_at or now,
|
|
220
|
+
)
|
|
221
|
+
existing[index] = template
|
|
222
|
+
_write(path, existing)
|
|
223
|
+
return template
|
|
224
|
+
raise ValueError("找不到這個範本,可能已被刪除。")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def delete_template(path: Path, template_id: str) -> bool:
|
|
228
|
+
"""Remove a user template. Returns False when there was nothing to remove."""
|
|
229
|
+
if template_id in THEMES:
|
|
230
|
+
raise ValueError("內建範本不可刪除。")
|
|
231
|
+
existing = load_user_templates(path)
|
|
232
|
+
remaining = [t for t in existing if t.id != template_id]
|
|
233
|
+
if len(remaining) == len(existing):
|
|
234
|
+
return False
|
|
235
|
+
_write(path, remaining)
|
|
236
|
+
return True
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
__all__ = [
|
|
240
|
+
"MAX_USER_TEMPLATES",
|
|
241
|
+
"TEMPLATES_FILENAME",
|
|
242
|
+
"Template",
|
|
243
|
+
"all_templates",
|
|
244
|
+
"builtin_templates",
|
|
245
|
+
"delete_template",
|
|
246
|
+
"design_of_theme",
|
|
247
|
+
"load_user_templates",
|
|
248
|
+
"save_template",
|
|
249
|
+
"templates_path",
|
|
250
|
+
]
|