@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.8
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/LICENSE +21 -0
- package/README.md +90 -2
- package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
- package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
- package/bundled-assets/skill/LICENSE +21 -0
- package/bundled-assets/skill/README.md +61 -0
- package/bundled-assets/skill/SKILL.md +185 -0
- package/bundled-assets/skill/references/art-directions.md +99 -0
- package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
- package/bundled-assets/skill/references/design-baseline.txt +1 -0
- package/bundled-assets/skill/references/prompt-compiler.md +99 -0
- package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
- package/bundled-assets/skill/references/staged-pptx.md +71 -0
- package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
- package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
- package/bundled-assets/skill/scripts/brand_ref.py +776 -0
- package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
- package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
- package/bundled-assets/skill/scripts/export_images.py +280 -0
- package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
- package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
- package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
- package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
- package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
- package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
- package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
- package/bundled-assets/skill/scripts/render_gradient.py +258 -0
- package/bundled-assets/skill/scripts/slide_brand.py +111 -0
- package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
- package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
- package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
- package/bundled-assets/skill/vendor/README.md +4 -0
- package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
- package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
- package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +11423 -0
- package/lib/index.js +2638 -0
- package/package.json +140 -4
|
@@ -0,0 +1,2322 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic Deck Shell Assembler for oil-slide (16:9, 3:4, 9:16, 1:1).
|
|
3
|
+
|
|
4
|
+
Strips 150+ lines of repetitive HTML/CSS/JS boilerplate (@font-face CJK weight
|
|
5
|
+
binding, seamless no-letterbox .deck-stage scaling, fitStage(),
|
|
6
|
+
?slide=1..N capture mode, keyboard/click navigation, subtle controls) into a
|
|
7
|
+
single reusable assembler so agents only emit compact per-slide fragments:
|
|
8
|
+
{ "slide_number": 1, "bg": "#F4EFE3", "css": "...", "html": "..." }
|
|
9
|
+
|
|
10
|
+
Supports both Python import (`assemble_deck_html`, `compose_deck_file`) and CLI:
|
|
11
|
+
python3 scripts/deck_shell.py --input fragments.json --out web/index.html --json
|
|
12
|
+
python3 scripts/deck_shell.py --slides-dir fragments/ --theme theme.json --out web/index.html --json
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import html as html_lib
|
|
18
|
+
from html.parser import HTMLParser
|
|
19
|
+
import json
|
|
20
|
+
import re
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
CANVAS_PRESETS: dict[str, tuple[int, int, str]] = {
|
|
26
|
+
"16:9": (1920, 1080, "16:9"),
|
|
27
|
+
"3:4": (1080, 1440, "3:4"),
|
|
28
|
+
"9:16": (1080, 1920, "9:16"),
|
|
29
|
+
"1:1": (1440, 1440, "1:1"),
|
|
30
|
+
"1920x1080": (1920, 1080, "16:9"),
|
|
31
|
+
"1080x1440": (1080, 1440, "3:4"),
|
|
32
|
+
"1080x1920": (1080, 1920, "9:16"),
|
|
33
|
+
"1440x1440": (1440, 1440, "1:1"),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def resolve_canvas_dimensions(
|
|
38
|
+
ratio: str | None = None,
|
|
39
|
+
width: int | None = None,
|
|
40
|
+
height: int | None = None,
|
|
41
|
+
theme: dict[str, Any] | None = None,
|
|
42
|
+
) -> tuple[int, int, str]:
|
|
43
|
+
"""Resolve (canvas_w, canvas_h, ratio_str) from explicit args or theme config (default 16:9 -> 1920x1080)."""
|
|
44
|
+
theme_cfg = theme if isinstance(theme, dict) else {}
|
|
45
|
+
w = width if width is not None else theme_cfg.get("width")
|
|
46
|
+
h = height if height is not None else theme_cfg.get("height")
|
|
47
|
+
canvas_obj = theme_cfg.get("canvas")
|
|
48
|
+
if isinstance(canvas_obj, dict):
|
|
49
|
+
w = w if w is not None else canvas_obj.get("width")
|
|
50
|
+
h = h if h is not None else canvas_obj.get("height")
|
|
51
|
+
if ratio is None and canvas_obj.get("ratio"):
|
|
52
|
+
ratio = str(canvas_obj["ratio"])
|
|
53
|
+
if w is not None and h is not None:
|
|
54
|
+
cw, ch = int(w), int(h)
|
|
55
|
+
if cw > 0 and ch > 0:
|
|
56
|
+
preset = CANVAS_PRESETS.get(f"{cw}x{ch}")
|
|
57
|
+
return (cw, ch, preset[2] if preset else f"{cw}:{ch}")
|
|
58
|
+
|
|
59
|
+
raw_ratio = (
|
|
60
|
+
ratio
|
|
61
|
+
or theme_cfg.get("ratio")
|
|
62
|
+
or theme_cfg.get("aspect_ratio")
|
|
63
|
+
or (canvas_obj if isinstance(canvas_obj, str) else None)
|
|
64
|
+
or theme_cfg.get("size")
|
|
65
|
+
)
|
|
66
|
+
if raw_ratio:
|
|
67
|
+
token = str(raw_ratio).strip().lower().replace("×", "x").replace("/", ":")
|
|
68
|
+
if token in CANVAS_PRESETS:
|
|
69
|
+
return CANVAS_PRESETS[token]
|
|
70
|
+
m = re.fullmatch(r"(\d+)\s*x\s*(\d+)", token)
|
|
71
|
+
if m:
|
|
72
|
+
cw, ch = int(m.group(1)), int(m.group(2))
|
|
73
|
+
if cw > 0 and ch > 0:
|
|
74
|
+
preset = CANVAS_PRESETS.get(f"{cw}x{ch}")
|
|
75
|
+
return (cw, ch, preset[2] if preset else f"{cw}:{ch}")
|
|
76
|
+
raise ValueError(
|
|
77
|
+
f"Unsupported canvas ratio/size: {raw_ratio!r} (expected '16:9', '3:4', '9:16', '1:1', or 'WxH')"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
return (1920, 1080, "16:9")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
HEX_RE = re.compile(r"#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b")
|
|
84
|
+
RGB_RE = re.compile(r"rgba?\(\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})\s*[,\s]\s*(\d{1,3})", re.IGNORECASE)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _extract_solid_hex(bg: str | None, fallback: str = "#FFFFFF") -> str:
|
|
88
|
+
"""Extract a clean 6-digit solid fallback hex color from any CSS background string."""
|
|
89
|
+
for candidate in (bg, fallback):
|
|
90
|
+
if not candidate:
|
|
91
|
+
continue
|
|
92
|
+
m = HEX_RE.search(candidate)
|
|
93
|
+
if m:
|
|
94
|
+
h = m.group(1)
|
|
95
|
+
if len(h) == 3:
|
|
96
|
+
h = "".join(c * 2 for c in h)
|
|
97
|
+
return f"#{h.upper()}"
|
|
98
|
+
mr = RGB_RE.search(candidate)
|
|
99
|
+
if mr:
|
|
100
|
+
r = max(0, min(255, int(mr.group(1))))
|
|
101
|
+
g = max(0, min(255, int(mr.group(2))))
|
|
102
|
+
b = max(0, min(255, int(mr.group(3))))
|
|
103
|
+
return f"#{r:02X}{g:02X}{b:02X}"
|
|
104
|
+
return "#FFFFFF"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _escape_double_quoted_attr(val: str) -> str:
|
|
108
|
+
return (
|
|
109
|
+
val.replace("&", "&")
|
|
110
|
+
.replace('"', """)
|
|
111
|
+
.replace("<", "<")
|
|
112
|
+
.replace(">", ">")
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _escape_css_url(url: str) -> str:
|
|
117
|
+
return url.strip().replace("\\", "\\\\").replace("'", "%27").replace('"', "%22")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _infer_polarity(bg: str | None, fallback: str = "light") -> str:
|
|
121
|
+
"""Infer 'light' or 'dark' polarity from the first hex color in a CSS background."""
|
|
122
|
+
if not bg:
|
|
123
|
+
return fallback
|
|
124
|
+
m = HEX_RE.search(bg)
|
|
125
|
+
if not m:
|
|
126
|
+
return fallback
|
|
127
|
+
h = m.group(1)
|
|
128
|
+
if len(h) == 3:
|
|
129
|
+
h = "".join(c * 2 for c in h)
|
|
130
|
+
r, g, b = int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)
|
|
131
|
+
lum = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255.0
|
|
132
|
+
return "light" if lum >= 0.5 else "dark"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _build_font_faces(font_style: str) -> tuple[str, str, str, str, str]:
|
|
136
|
+
"""Emit full 400–900 @font-face rules using curated free-commercial CJK + Latin fonts.
|
|
137
|
+
|
|
138
|
+
Supported `font_style` presets:
|
|
139
|
+
- 'sans' : MiSans / Alibaba PuHuiTi 3.0 (400–900) + Plus Jakarta Sans + JetBrains Mono
|
|
140
|
+
- 'tech' : MiSans / Alibaba PuHuiTi 3.0 (400–900) + Space Grotesk + JetBrains Mono
|
|
141
|
+
- 'serif' : Source Han Serif CN / Noto Serif SC (400–900) + Fraunces + IBM Plex Mono
|
|
142
|
+
- 'editorial' : Zhuque Fangsong + Instrument Serif + IBM Plex Mono
|
|
143
|
+
- 'poster' : Alimama ShuHeiTi + MiSans / Alibaba PuHuiTi 3.0 + Syne / Space Grotesk
|
|
144
|
+
- 'kinetic' : Smiley Sans (得意黑, OFL) + Space Grotesk + MiSans
|
|
145
|
+
- 'wenkai' : LXGW WenKai (霞鹜文楷, OFL) + Plus Jakarta Sans + IBM Plex Mono
|
|
146
|
+
|
|
147
|
+
CRITICAL: In macOS fallback chains, local('HiraginoSansGB-W6') MUST precede
|
|
148
|
+
local('PingFangSC-Semibold') so hosts without custom fonts still render heavy strokes.
|
|
149
|
+
"""
|
|
150
|
+
style = (font_style or "sans").strip().lower()
|
|
151
|
+
|
|
152
|
+
# Core commercial-free CJK @font-face ladders (400..900 real weights, zero-network local first, macOS/Windows/Linux fallback)
|
|
153
|
+
heavy_cjk_800 = (
|
|
154
|
+
"local('AlibabaPuHuiTi_3_95_ExtraBold'), local('Alibaba PuHuiTi 3.0 95 ExtraBold'), "
|
|
155
|
+
"local('AlibabaPuHuiTi_3_105_Heavy'), local('Alibaba PuHuiTi 3.0 105 Heavy'), "
|
|
156
|
+
"local('AlibabaPuHuiTi_3_115_Black'), local('Alibaba PuHuiTi 3.0 115 Black'), "
|
|
157
|
+
"local('AlimamaShuHeiTi'), local('Alimama ShuHeiTi Bold'), "
|
|
158
|
+
"local('Source Han Sans SC Heavy'), local('SourceHanSansSC-Heavy'), local('Source Han Sans CN Heavy'), "
|
|
159
|
+
"local('Noto Sans CJK SC Black'), local('NotoSansCJKsc-Black'), "
|
|
160
|
+
"local('Lantinghei SC Heavy'), local('FZLanTingHeiS-H-GB'), "
|
|
161
|
+
"local('AlibabaPuHuiTi_3_85_Bold'), local('Alibaba PuHuiTi 3.0 85 Bold'), "
|
|
162
|
+
"local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), "
|
|
163
|
+
"local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), local('Microsoft YaHei Bold')"
|
|
164
|
+
)
|
|
165
|
+
heavy_cjk_900 = (
|
|
166
|
+
"local('AlibabaPuHuiTi_3_115_Black'), local('Alibaba PuHuiTi 3.0 115 Black'), "
|
|
167
|
+
"local('AlibabaPuHuiTi_3_105_Heavy'), local('Alibaba PuHuiTi 3.0 105 Heavy'), "
|
|
168
|
+
"local('AlimamaShuHeiTi'), local('Alimama ShuHeiTi Bold'), "
|
|
169
|
+
"local('Source Han Sans SC Heavy'), local('SourceHanSansSC-Heavy'), local('Source Han Sans CN Heavy'), "
|
|
170
|
+
"local('Noto Sans CJK SC Black'), local('NotoSansCJKsc-Black'), "
|
|
171
|
+
"local('Lantinghei SC Heavy'), local('FZLanTingHeiS-H-GB'), "
|
|
172
|
+
"local('AlibabaPuHuiTi_3_95_ExtraBold'), local('Alibaba PuHuiTi 3.0 95 ExtraBold'), "
|
|
173
|
+
"local('AlibabaPuHuiTi_3_85_Bold'), local('Alibaba PuHuiTi 3.0 85 Bold'), "
|
|
174
|
+
"local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), "
|
|
175
|
+
"local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), local('Microsoft YaHei Bold')"
|
|
176
|
+
)
|
|
177
|
+
bold_cjk_700 = (
|
|
178
|
+
"local('AlibabaPuHuiTi_3_85_Bold'), local('Alibaba PuHuiTi 3.0 85 Bold'), "
|
|
179
|
+
"local('Source Han Sans SC Bold'), local('SourceHanSansSC-Bold'), "
|
|
180
|
+
"local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), "
|
|
181
|
+
"local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), local('Microsoft YaHei Bold')"
|
|
182
|
+
)
|
|
183
|
+
shared_faces = f""" /* Alibaba PuHuiTi 3.0 — full 400..900 weight ladder (Free Commercial) */
|
|
184
|
+
@font-face {{
|
|
185
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
186
|
+
src: local('AlibabaPuHuiTi_3_55_Regular'), local('Alibaba PuHuiTi 3.0 55 Regular'), local('PingFangSC-Regular'), local('HiraginoSansGB-W3'), local('Noto Sans CJK SC'), local('NotoSansCJKsc-Regular'), local('Source Han Sans SC'), local('Microsoft YaHei'), local('WenQuanYi Micro Hei');
|
|
187
|
+
font-weight: 400;
|
|
188
|
+
font-style: normal;
|
|
189
|
+
}}
|
|
190
|
+
@font-face {{
|
|
191
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
192
|
+
src: local('AlibabaPuHuiTi_3_65_Medium'), local('Alibaba PuHuiTi 3.0 65 Medium'), local('PingFangSC-Medium'), local('HiraginoSansGB-W3'), local('Noto Sans CJK SC Medium'), local('NotoSansCJKsc-Medium'), local('Source Han Sans SC Medium'), local('Microsoft YaHei');
|
|
193
|
+
font-weight: 500;
|
|
194
|
+
font-style: normal;
|
|
195
|
+
}}
|
|
196
|
+
@font-face {{
|
|
197
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
198
|
+
src: local('AlibabaPuHuiTi_3_75_SemiBold'), local('Alibaba PuHuiTi 3.0 75 SemiBold'), local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), local('Source Han Sans SC Bold'), local('Microsoft YaHei Bold');
|
|
199
|
+
font-weight: 600;
|
|
200
|
+
font-style: normal;
|
|
201
|
+
}}
|
|
202
|
+
@font-face {{
|
|
203
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
204
|
+
src: {bold_cjk_700};
|
|
205
|
+
font-weight: 700;
|
|
206
|
+
font-style: normal;
|
|
207
|
+
}}
|
|
208
|
+
@font-face {{
|
|
209
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
210
|
+
src: {heavy_cjk_800};
|
|
211
|
+
font-weight: 800;
|
|
212
|
+
font-style: normal;
|
|
213
|
+
}}
|
|
214
|
+
@font-face {{
|
|
215
|
+
font-family: 'AlibabaPuHuiTi3';
|
|
216
|
+
src: {heavy_cjk_900};
|
|
217
|
+
font-weight: 900;
|
|
218
|
+
font-style: normal;
|
|
219
|
+
}}
|
|
220
|
+
|
|
221
|
+
/* Alimama ShuHeiTi — heavy poster display sans (Free Commercial) */
|
|
222
|
+
@font-face {{
|
|
223
|
+
font-family: 'AlimamaShuHei';
|
|
224
|
+
src: local('AlimamaShuHeiTi'), local('Alimama ShuHeiTi Bold'), local('AlibabaPuHuiTi_3_115_Black'), local('Alibaba PuHuiTi 3.0 115 Black'), local('AlibabaPuHuiTi_3_105_Heavy'), local('Alibaba PuHuiTi 3.0 105 Heavy'), local('Source Han Sans SC Heavy'), local('SourceHanSansSC-Heavy'), local('Source Han Sans CN Heavy'), local('Noto Sans CJK SC Black'), local('NotoSansCJKsc-Black'), local('Lantinghei SC Heavy'), local('FZLanTingHeiS-H-GB'), local('AlibabaPuHuiTi_3_95_ExtraBold'), local('Alibaba PuHuiTi 3.0 95 ExtraBold'), local('AlibabaPuHuiTi_3_85_Bold'), local('Alibaba PuHuiTi 3.0 85 Bold'), local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), local('Microsoft YaHei Bold');
|
|
225
|
+
font-weight: 600 900;
|
|
226
|
+
font-style: normal;
|
|
227
|
+
}}
|
|
228
|
+
|
|
229
|
+
/* Smiley Sans (得意黑) — narrow kinetic oblique display (OFL 1.1) */
|
|
230
|
+
@font-face {{
|
|
231
|
+
font-family: 'SmileySans';
|
|
232
|
+
src: local('Smiley Sans Oblique'), local('SmileySans-Oblique'), local('Smiley Sans'), local('AlimamaShuHeiTi'), local('HiraginoSansGB-W6'), local('Noto Sans CJK SC Bold');
|
|
233
|
+
font-weight: 400 900;
|
|
234
|
+
font-style: normal;
|
|
235
|
+
}}
|
|
236
|
+
|
|
237
|
+
/* LXGW WenKai (霞鹜文楷) — refined humanist literary Kai (OFL 1.1) */
|
|
238
|
+
@font-face {{
|
|
239
|
+
font-family: 'LXGWWenKai';
|
|
240
|
+
src: local('LXGW WenKai'), local('LXGW WenKai Lite'), local('LXGWWenKai-Regular'), local('LXGWWenKai-Medium'), local('Kaiti SC'), local('STKaiti'), local('Noto Serif CJK SC');
|
|
241
|
+
font-weight: 400 700;
|
|
242
|
+
font-style: normal;
|
|
243
|
+
}}
|
|
244
|
+
|
|
245
|
+
/* Zhuque Fangsong — literary editorial Fangsong (OFL 1.1) */
|
|
246
|
+
@font-face {{
|
|
247
|
+
font-family: 'ZhuqueFangsong';
|
|
248
|
+
src: local('ZhuqueFangsong-Regular'), local('Zhuque Fangsong (technical preview)'), local('STSongti-SC-Regular'), local('Noto Serif CJK SC'), local('NotoSerifCJKsc-Regular'), local('Source Han Serif SC'), local('FangSong'), local('SimSun');
|
|
249
|
+
font-weight: 400 900;
|
|
250
|
+
font-style: normal;
|
|
251
|
+
}}
|
|
252
|
+
|
|
253
|
+
/* Legacy compatibility aliases mapped to full 400..900 Alibaba PuHuiTi 3.0 & Serif */
|
|
254
|
+
@font-face {{
|
|
255
|
+
font-family: 'BrandDisplay';
|
|
256
|
+
src: local('AlibabaPuHuiTi_3_75_SemiBold'), local('Alibaba PuHuiTi 3.0 75 SemiBold'), local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), local('Microsoft YaHei Bold');
|
|
257
|
+
font-weight: 600;
|
|
258
|
+
font-style: normal;
|
|
259
|
+
}}
|
|
260
|
+
@font-face {{
|
|
261
|
+
font-family: 'BrandDisplay';
|
|
262
|
+
src: {bold_cjk_700};
|
|
263
|
+
font-weight: 700;
|
|
264
|
+
font-style: normal;
|
|
265
|
+
}}
|
|
266
|
+
@font-face {{
|
|
267
|
+
font-family: 'BrandDisplay';
|
|
268
|
+
src: {heavy_cjk_800};
|
|
269
|
+
font-weight: 800;
|
|
270
|
+
font-style: normal;
|
|
271
|
+
}}
|
|
272
|
+
@font-face {{
|
|
273
|
+
font-family: 'BrandDisplay';
|
|
274
|
+
src: {heavy_cjk_900};
|
|
275
|
+
font-weight: 900;
|
|
276
|
+
font-style: normal;
|
|
277
|
+
}}
|
|
278
|
+
@font-face {{
|
|
279
|
+
font-family: 'BrandSerif';
|
|
280
|
+
src: local('STSongti-SC-Bold'), local('Songti SC Bold'), local('STSongti-SC-Black'), local('Noto Serif CJK SC Bold'), local('NotoSerifCJKsc-Bold'), local('Source Han Serif SC Bold'), local('SimSun');
|
|
281
|
+
font-weight: 600 900;
|
|
282
|
+
font-style: normal;
|
|
283
|
+
}}
|
|
284
|
+
@font-face {{
|
|
285
|
+
font-family: 'BrandNumeric';
|
|
286
|
+
src: local('SFProDisplay-Bold'), local('SFProDisplay-Semibold'), local('SF Pro Display Bold'), local('HelveticaNeue-Bold'), local('AlibabaPuHuiTi_3_85_Bold'), local('Alibaba PuHuiTi 3.0 85 Bold'), local('Segoe UI Bold'), local('Noto Sans Bold');
|
|
287
|
+
font-weight: 600 700;
|
|
288
|
+
font-style: normal;
|
|
289
|
+
}}
|
|
290
|
+
@font-face {{
|
|
291
|
+
font-family: 'BrandNumeric';
|
|
292
|
+
src: local('SFProDisplay-Black'), local('SFProDisplay-Heavy'), local('SF Pro Display Black'), local('SF Pro Display Heavy'), local('Arial Black'), local('HelveticaNeue-CondensedBlack'), local('AlibabaPuHuiTi_3_105_Heavy'), local('Alibaba PuHuiTi 3.0 105 Heavy'), local('AlibabaPuHuiTi_3_115_Black'), local('Alibaba PuHuiTi 3.0 115 Black'), local('Noto Sans Black'), local('Segoe UI Black');
|
|
293
|
+
font-weight: 800 900;
|
|
294
|
+
font-style: normal;
|
|
295
|
+
}}
|
|
296
|
+
@font-face {{
|
|
297
|
+
font-family: 'BrandSans';
|
|
298
|
+
src: local('AlibabaPuHuiTi_3_55_Regular'), local('Alibaba PuHuiTi 3.0 55 Regular'), local('PingFangSC-Regular'), local('HiraginoSansGB-W3'), local('Noto Sans CJK SC'), local('NotoSansCJKsc-Regular'), local('Microsoft YaHei');
|
|
299
|
+
font-weight: 400;
|
|
300
|
+
font-style: normal;
|
|
301
|
+
}}
|
|
302
|
+
@font-face {{
|
|
303
|
+
font-family: 'BrandSans';
|
|
304
|
+
src: local('AlibabaPuHuiTi_3_65_Medium'), local('Alibaba PuHuiTi 3.0 65 Medium'), local('PingFangSC-Medium'), local('HiraginoSansGB-W3'), local('Noto Sans CJK SC Medium'), local('NotoSansCJKsc-Medium'), local('Microsoft YaHei');
|
|
305
|
+
font-weight: 500;
|
|
306
|
+
font-style: normal;
|
|
307
|
+
}}
|
|
308
|
+
@font-face {{
|
|
309
|
+
font-family: 'BrandSans';
|
|
310
|
+
src: local('AlibabaPuHuiTi_3_75_SemiBold'), local('Alibaba PuHuiTi 3.0 75 SemiBold'), local('HiraginoSansGB-W6'), local('PingFangSC-Semibold'), local('Noto Sans CJK SC Bold'), local('NotoSansCJKsc-Bold'), local('Microsoft YaHei Bold');
|
|
311
|
+
font-weight: 600;
|
|
312
|
+
font-style: normal;
|
|
313
|
+
}}
|
|
314
|
+
@font-face {{
|
|
315
|
+
font-family: 'BrandSans';
|
|
316
|
+
src: {bold_cjk_700};
|
|
317
|
+
font-weight: 700;
|
|
318
|
+
font-style: normal;
|
|
319
|
+
}}
|
|
320
|
+
@font-face {{
|
|
321
|
+
font-family: 'BrandSans';
|
|
322
|
+
src: {heavy_cjk_900};
|
|
323
|
+
font-weight: 800 900;
|
|
324
|
+
font-style: normal;
|
|
325
|
+
}}"""
|
|
326
|
+
|
|
327
|
+
if style == "tech":
|
|
328
|
+
display_stack = "'Space Grotesk', 'MiSans', 'AlibabaPuHuiTi3', 'BrandDisplay', 'Hiragino Sans GB', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
329
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
330
|
+
num_stack = "'Space Grotesk', 'MiSans', 'AlibabaPuHuiTi3', 'BrandNumeric', 'Microsoft YaHei', sans-serif"
|
|
331
|
+
mono_stack = "'JetBrains Mono', 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
332
|
+
elif style == "serif":
|
|
333
|
+
display_stack = "'Fraunces', 'Source Han Serif CN VF', 'Noto Serif SC', 'Noto Serif CJK SC', 'BrandSerif', 'STSongti-SC-Bold', 'Songti SC', 'SimSun', Georgia, serif"
|
|
334
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
335
|
+
num_stack = "'Fraunces', 'Source Han Serif CN VF', 'Noto Serif SC', 'Noto Serif CJK SC', 'BrandNumeric', Georgia, serif"
|
|
336
|
+
mono_stack = "'IBM Plex Mono', 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
337
|
+
elif style == "editorial":
|
|
338
|
+
display_stack = "'Instrument Serif', 'Zhuque Fangsong (technical preview)', 'ZhuqueFangsong', 'Source Han Serif CN VF', 'Noto Serif SC', 'Noto Serif CJK SC', 'BrandSerif', 'STSongti-SC-Regular', 'FangSong', Georgia, serif"
|
|
339
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
340
|
+
num_stack = "'Instrument Serif', 'Fraunces', 'Source Han Serif CN VF', 'Noto Serif SC', 'Noto Serif CJK SC', Georgia, serif"
|
|
341
|
+
mono_stack = "'IBM Plex Mono', 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
342
|
+
elif style == "poster":
|
|
343
|
+
display_stack = "'Syne', 'Space Grotesk', 'Alimama ShuHeiTi', 'AlimamaShuHei', 'MiSans', 'AlibabaPuHuiTi3', 'BrandDisplay', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
344
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
345
|
+
num_stack = "'Space Grotesk', 'Alimama ShuHeiTi', 'AlimamaShuHei', 'MiSans', 'AlibabaPuHuiTi3', 'Microsoft YaHei', sans-serif"
|
|
346
|
+
mono_stack = "'JetBrains Mono', 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
347
|
+
elif style == "kinetic":
|
|
348
|
+
display_stack = "'Space Grotesk', 'Smiley Sans', 'SmileySans', 'Alimama ShuHeiTi', 'AlimamaShuHei', 'MiSans', 'Hiragino Sans GB', 'Noto Sans CJK SC', sans-serif"
|
|
349
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
350
|
+
num_stack = "'Space Grotesk', 'Smiley Sans', 'SmileySans', 'MiSans', sans-serif"
|
|
351
|
+
mono_stack = "'JetBrains Mono', 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
352
|
+
elif style == "wenkai":
|
|
353
|
+
display_stack = "'Fraunces', 'LXGW WenKai Lite', 'LXGWWenKai', 'LXGW WenKai', 'Source Han Serif CN VF', 'Noto Serif SC', Georgia, serif"
|
|
354
|
+
body_stack = "'Plus Jakarta Sans', 'LXGW WenKai Lite', 'LXGWWenKai', 'MiSans', 'PingFang SC', 'Noto Sans CJK SC', sans-serif"
|
|
355
|
+
num_stack = "'Plus Jakarta Sans', 'LXGW WenKai Lite', 'LXGWWenKai', sans-serif"
|
|
356
|
+
mono_stack = "'IBM Plex Mono', 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
357
|
+
else: # 'sans' (default modern display + body)
|
|
358
|
+
display_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandDisplay', 'Hiragino Sans GB', 'PingFang SC', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
359
|
+
body_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandSans', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif"
|
|
360
|
+
num_stack = "'Plus Jakarta Sans', 'MiSans', 'AlibabaPuHuiTi3', 'BrandNumeric', 'Microsoft YaHei', sans-serif"
|
|
361
|
+
mono_stack = "'JetBrains Mono', 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace"
|
|
362
|
+
|
|
363
|
+
return shared_faces, display_stack, body_stack, num_stack, mono_stack
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _build_header_html(header_cfg: dict[str, Any], slide_num: int, total_slides: int) -> str:
|
|
367
|
+
"""Render a pixel-locked <header class="slide-header"> when theme.header is configured."""
|
|
368
|
+
logo_svg = (header_cfg.get("logo_svg") or "").strip()
|
|
369
|
+
logo_src = (header_cfg.get("logo_src") or "").strip()
|
|
370
|
+
brand_name = (header_cfg.get("brand_name") or "").strip()
|
|
371
|
+
logo_h = int(header_cfg.get("logo_height") or 42)
|
|
372
|
+
show_page_num = bool(header_cfg.get("show_page_num", True))
|
|
373
|
+
|
|
374
|
+
left_parts: list[str] = []
|
|
375
|
+
if logo_svg:
|
|
376
|
+
left_parts.append(f'<span class="brand-logo-svg" style="height:{logo_h}px;">{logo_svg}</span>')
|
|
377
|
+
elif logo_src:
|
|
378
|
+
alt_txt = html_lib.escape(brand_name or "Logo", quote=True)
|
|
379
|
+
src_txt = html_lib.escape(logo_src, quote=True)
|
|
380
|
+
left_parts.append(f'<img class="brand-logo" src="{src_txt}" alt="{alt_txt}" style="height:{logo_h}px;" />')
|
|
381
|
+
if brand_name:
|
|
382
|
+
left_parts.append(f'<span class="brand-name">{html_lib.escape(brand_name)}</span>')
|
|
383
|
+
|
|
384
|
+
left_html = f'<div class="brand-lockup">{"".join(left_parts)}</div>'
|
|
385
|
+
if show_page_num:
|
|
386
|
+
counter = f"{slide_num:02d} / {total_slides:02d}"
|
|
387
|
+
right_html = f'<span class="page-num">{counter}</span>'
|
|
388
|
+
else:
|
|
389
|
+
right_html = ""
|
|
390
|
+
|
|
391
|
+
return f' <header class="slide-header">{left_html}{right_html}</header>'
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
_BAKED_REF_RE = re.compile(
|
|
395
|
+
r"assets/reference/(?:s\d+|deck-2x2|overview[^\s\"'()]*)\.(?:png|jpe?g|webp)",
|
|
396
|
+
re.IGNORECASE,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def find_baked_reference_embeds(text: str) -> list[str]:
|
|
401
|
+
"""Return any text-baked reference draft image paths embedded in HTML/CSS."""
|
|
402
|
+
if not text:
|
|
403
|
+
return []
|
|
404
|
+
return sorted(set(_BAKED_REF_RE.findall(text)))
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def lint_deck_html(html_text: str) -> list[str]:
|
|
408
|
+
"""Static guardrails matching verify_deck & tool runtime checks."""
|
|
409
|
+
warnings: list[str] = []
|
|
410
|
+
baked = find_baked_reference_embeds(html_text)
|
|
411
|
+
if baked:
|
|
412
|
+
warnings.append(
|
|
413
|
+
f"Forbidden text-baked reference draft(s) embedded in HTML: {', '.join(baked)}. "
|
|
414
|
+
"Restore slides into editable HTML text with clean assets/plates/ or assets/crops/ instead."
|
|
415
|
+
)
|
|
416
|
+
if "calc(100vw" in html_text or "calc(100vh" in html_text:
|
|
417
|
+
warnings.append("Detected calc(100vw/100vh) in CSS; use JS fitStage() scaling instead.")
|
|
418
|
+
if 'rel="icon"' not in html_text and "rel='icon'" not in html_text:
|
|
419
|
+
warnings.append('Missing <link rel="icon" href="data:,">.')
|
|
420
|
+
if "deck-stage" not in html_text:
|
|
421
|
+
warnings.append("Missing .deck-stage container.")
|
|
422
|
+
if "URLSearchParams" not in html_text:
|
|
423
|
+
warnings.append("Missing ?slide=1..N URLSearchParams handler.")
|
|
424
|
+
if "fetch(" in html_text:
|
|
425
|
+
warnings.append("Avoid fetch() in web/index.html so file:// works without CORS errors.")
|
|
426
|
+
for block in re.findall(r"@font-face\s*\{[^}]+\}", html_text, re.I | re.S):
|
|
427
|
+
if re.search(r"font-weight\s*:\s*(?:700|800|900)", block):
|
|
428
|
+
idx_pf = block.find("PingFangSC-Semibold")
|
|
429
|
+
idx_hi = block.find("HiraginoSansGB-W6")
|
|
430
|
+
if idx_pf != -1 and idx_hi != -1 and idx_pf < idx_hi:
|
|
431
|
+
warnings.append(
|
|
432
|
+
"local('PingFangSC-Semibold') appears before local('HiraginoSansGB-W6') in heavy @font-face."
|
|
433
|
+
)
|
|
434
|
+
break
|
|
435
|
+
return warnings
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _split_css_top_level(text: str, sep: str = ",") -> list[str]:
|
|
439
|
+
"""Split CSS text by `sep` outside strings, comments, and (...) / [...] groups."""
|
|
440
|
+
parts: list[str] = []
|
|
441
|
+
buf: list[str] = []
|
|
442
|
+
n = len(text)
|
|
443
|
+
i = 0
|
|
444
|
+
paren = 0
|
|
445
|
+
bracket = 0
|
|
446
|
+
quote: str | None = None
|
|
447
|
+
while i < n:
|
|
448
|
+
ch = text[i]
|
|
449
|
+
if quote:
|
|
450
|
+
buf.append(ch)
|
|
451
|
+
if ch == "\\" and i + 1 < n:
|
|
452
|
+
i += 1
|
|
453
|
+
buf.append(text[i])
|
|
454
|
+
elif ch == quote:
|
|
455
|
+
quote = None
|
|
456
|
+
i += 1
|
|
457
|
+
continue
|
|
458
|
+
if ch == "/" and i + 1 < n and text[i + 1] == "*":
|
|
459
|
+
end = text.find("*/", i + 2)
|
|
460
|
+
if end == -1:
|
|
461
|
+
buf.append(text[i:])
|
|
462
|
+
break
|
|
463
|
+
buf.append(text[i : end + 2])
|
|
464
|
+
i = end + 2
|
|
465
|
+
continue
|
|
466
|
+
if ch in ("'", '"'):
|
|
467
|
+
quote = ch
|
|
468
|
+
buf.append(ch)
|
|
469
|
+
i += 1
|
|
470
|
+
continue
|
|
471
|
+
if ch == "(":
|
|
472
|
+
paren += 1
|
|
473
|
+
elif ch == ")" and paren > 0:
|
|
474
|
+
paren -= 1
|
|
475
|
+
elif ch == "[":
|
|
476
|
+
bracket += 1
|
|
477
|
+
elif ch == "]" and bracket > 0:
|
|
478
|
+
bracket -= 1
|
|
479
|
+
elif ch == sep and paren == 0 and bracket == 0:
|
|
480
|
+
parts.append("".join(buf))
|
|
481
|
+
buf = []
|
|
482
|
+
i += 1
|
|
483
|
+
continue
|
|
484
|
+
buf.append(ch)
|
|
485
|
+
i += 1
|
|
486
|
+
if buf or parts:
|
|
487
|
+
parts.append("".join(buf))
|
|
488
|
+
return parts
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
_ALREADY_SCOPED_RE = re.compile(
|
|
492
|
+
r"^(?:section)?\.slide\s*\[\s*data-slide\s*=|^:root\b|^html\b|^body\b",
|
|
493
|
+
re.IGNORECASE,
|
|
494
|
+
)
|
|
495
|
+
_LEADING_SLIDE_SELF_RE = re.compile(
|
|
496
|
+
r"^(?:section)?\.slide(?=$|[\s:.\[>+~])",
|
|
497
|
+
re.IGNORECASE,
|
|
498
|
+
)
|
|
499
|
+
_NESTABLE_AT_RULE_RE = re.compile(r"^@(?:media|supports|container|layer)\b", re.IGNORECASE)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _scope_selector_list(selector_text: str, scope: str) -> str:
|
|
503
|
+
scoped: list[str] = []
|
|
504
|
+
for raw_sel in _split_css_top_level(selector_text, ","):
|
|
505
|
+
sel = raw_sel.strip()
|
|
506
|
+
if not sel:
|
|
507
|
+
continue
|
|
508
|
+
if _ALREADY_SCOPED_RE.match(sel):
|
|
509
|
+
scoped.append(sel)
|
|
510
|
+
elif _LEADING_SLIDE_SELF_RE.match(sel):
|
|
511
|
+
scoped.append(_LEADING_SLIDE_SELF_RE.sub(scope, sel, count=1))
|
|
512
|
+
else:
|
|
513
|
+
scoped.append(f"{scope} {sel}")
|
|
514
|
+
return ", ".join(scoped) if scoped else selector_text.strip()
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def scope_slide_css(css_text: str, slide_pos: int) -> str:
|
|
518
|
+
"""Scope per-slide CSS rules under `.slide[data-slide="<slide_pos>"]` to prevent cross-slide collisions.
|
|
519
|
+
|
|
520
|
+
Preserves `@keyframes` / `@font-face` / already-scoped selectors, rewrites `.slide` self-rules
|
|
521
|
+
to `.slide[data-slide="<slide_pos>"]`, and recursively scopes `@media` / `@supports` blocks.
|
|
522
|
+
"""
|
|
523
|
+
src = (css_text or "").strip()
|
|
524
|
+
if not src:
|
|
525
|
+
return ""
|
|
526
|
+
scope = f'.slide[data-slide="{int(slide_pos)}"]'
|
|
527
|
+
|
|
528
|
+
def _transform(text: str) -> str:
|
|
529
|
+
out: list[str] = []
|
|
530
|
+
n = len(text)
|
|
531
|
+
i = 0
|
|
532
|
+
while i < n:
|
|
533
|
+
# Preserve whitespace
|
|
534
|
+
ws_start = i
|
|
535
|
+
while i < n and text[i].isspace():
|
|
536
|
+
i += 1
|
|
537
|
+
if i > ws_start:
|
|
538
|
+
out.append(text[ws_start:i])
|
|
539
|
+
if i >= n:
|
|
540
|
+
break
|
|
541
|
+
# Preserve comments
|
|
542
|
+
if text[i] == "/" and i + 1 < n and text[i + 1] == "*":
|
|
543
|
+
end = text.find("*/", i + 2)
|
|
544
|
+
if end == -1:
|
|
545
|
+
out.append(text[i:])
|
|
546
|
+
break
|
|
547
|
+
out.append(text[i : end + 2])
|
|
548
|
+
i = end + 2
|
|
549
|
+
continue
|
|
550
|
+
# Read prelude until '{' or ';' (respecting strings/comments)
|
|
551
|
+
prelude_start = i
|
|
552
|
+
quote: str | None = None
|
|
553
|
+
brace_pos = -1
|
|
554
|
+
semi_pos = -1
|
|
555
|
+
while i < n:
|
|
556
|
+
ch = text[i]
|
|
557
|
+
if quote:
|
|
558
|
+
if ch == "\\" and i + 1 < n:
|
|
559
|
+
i += 2
|
|
560
|
+
continue
|
|
561
|
+
if ch == quote:
|
|
562
|
+
quote = None
|
|
563
|
+
i += 1
|
|
564
|
+
continue
|
|
565
|
+
if ch == "/" and i + 1 < n and text[i + 1] == "*":
|
|
566
|
+
end = text.find("*/", i + 2)
|
|
567
|
+
i = n if end == -1 else end + 2
|
|
568
|
+
continue
|
|
569
|
+
if ch in ("'", '"'):
|
|
570
|
+
quote = ch
|
|
571
|
+
i += 1
|
|
572
|
+
continue
|
|
573
|
+
if ch == "{":
|
|
574
|
+
brace_pos = i
|
|
575
|
+
i += 1
|
|
576
|
+
break
|
|
577
|
+
if ch == ";":
|
|
578
|
+
semi_pos = i
|
|
579
|
+
i += 1
|
|
580
|
+
break
|
|
581
|
+
i += 1
|
|
582
|
+
if semi_pos != -1:
|
|
583
|
+
out.append(text[prelude_start : semi_pos + 1])
|
|
584
|
+
continue
|
|
585
|
+
if brace_pos == -1:
|
|
586
|
+
out.append(text[prelude_start:])
|
|
587
|
+
break
|
|
588
|
+
prelude = text[prelude_start:brace_pos].strip()
|
|
589
|
+
# Find matching closing '}'
|
|
590
|
+
depth = 1
|
|
591
|
+
body_start = brace_pos + 1
|
|
592
|
+
quote = None
|
|
593
|
+
while i < n and depth > 0:
|
|
594
|
+
ch = text[i]
|
|
595
|
+
if quote:
|
|
596
|
+
if ch == "\\" and i + 1 < n:
|
|
597
|
+
i += 2
|
|
598
|
+
continue
|
|
599
|
+
if ch == quote:
|
|
600
|
+
quote = None
|
|
601
|
+
i += 1
|
|
602
|
+
continue
|
|
603
|
+
if ch == "/" and i + 1 < n and text[i + 1] == "*":
|
|
604
|
+
end = text.find("*/", i + 2)
|
|
605
|
+
i = n if end == -1 else end + 2
|
|
606
|
+
continue
|
|
607
|
+
if ch in ("'", '"'):
|
|
608
|
+
quote = ch
|
|
609
|
+
i += 1
|
|
610
|
+
continue
|
|
611
|
+
if ch == "{":
|
|
612
|
+
depth += 1
|
|
613
|
+
elif ch == "}":
|
|
614
|
+
depth -= 1
|
|
615
|
+
if depth == 0:
|
|
616
|
+
break
|
|
617
|
+
i += 1
|
|
618
|
+
body_end = i
|
|
619
|
+
if i < n and text[i] == "}":
|
|
620
|
+
i += 1
|
|
621
|
+
body = text[body_start:body_end]
|
|
622
|
+
if prelude.startswith("@"):
|
|
623
|
+
if _NESTABLE_AT_RULE_RE.match(prelude):
|
|
624
|
+
out.append(f"{prelude} {{{_transform(body)}}}")
|
|
625
|
+
else:
|
|
626
|
+
out.append(f"{prelude} {{{body}}}")
|
|
627
|
+
else:
|
|
628
|
+
scoped_sel = _scope_selector_list(prelude, scope)
|
|
629
|
+
out.append(f"{scoped_sel} {{{body}}}")
|
|
630
|
+
return "".join(out)
|
|
631
|
+
|
|
632
|
+
return _transform(src)
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
_SLIDE_META_COMMENT_RE = re.compile(r"^\s*<!--\s*slide\s*:\s*(\{.*?\})\s*-->", re.IGNORECASE | re.DOTALL)
|
|
636
|
+
_STYLE_TAG_RE = re.compile(r"<style\b[^>]*>(.*?)</style>", re.IGNORECASE | re.DOTALL)
|
|
637
|
+
_OUTER_SECTION_RE = re.compile(
|
|
638
|
+
r"^\s*<section\b([^>]*)>(.*)</section>\s*$",
|
|
639
|
+
re.IGNORECASE | re.DOTALL,
|
|
640
|
+
)
|
|
641
|
+
_HTML_ATTR_RE = re.compile(r'([a-zA-Z0-9_-]+)\s*=\s*(?:"([^"]*)"|\'([^\']*)\')')
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def parse_slide_fragment_html(text: str, default_slide_number: int = 1) -> dict[str, Any]:
|
|
645
|
+
"""Parse a single-slide `.html` fragment file into a standard slide dict.
|
|
646
|
+
|
|
647
|
+
Supports optional leading `<!-- slide: {"bg": "#...", "bg_image": "..."} -->` JSON metadata,
|
|
648
|
+
one or more `<style>...</style>` blocks (extracted into `css`), and either raw inner HTML
|
|
649
|
+
or a single `<section data-slide="..." data-bg="...">...</section>` wrapper.
|
|
650
|
+
"""
|
|
651
|
+
meta: dict[str, Any] = {}
|
|
652
|
+
working = text or ""
|
|
653
|
+
|
|
654
|
+
m_meta = _SLIDE_META_COMMENT_RE.match(working)
|
|
655
|
+
if m_meta:
|
|
656
|
+
try:
|
|
657
|
+
parsed = json.loads(m_meta.group(1))
|
|
658
|
+
if isinstance(parsed, dict):
|
|
659
|
+
meta.update(parsed)
|
|
660
|
+
except json.JSONDecodeError as exc:
|
|
661
|
+
raise ValueError(f"Invalid <!-- slide: {{...}} --> JSON metadata: {exc}") from exc
|
|
662
|
+
working = working[m_meta.end() :]
|
|
663
|
+
|
|
664
|
+
css_parts: list[str] = []
|
|
665
|
+
|
|
666
|
+
def _collect_style(match: re.Match[str]) -> str:
|
|
667
|
+
block = (match.group(1) or "").strip()
|
|
668
|
+
if block:
|
|
669
|
+
css_parts.append(block)
|
|
670
|
+
return ""
|
|
671
|
+
|
|
672
|
+
working = _STYLE_TAG_RE.sub(_collect_style, working).strip()
|
|
673
|
+
|
|
674
|
+
m_sec = _OUTER_SECTION_RE.match(working)
|
|
675
|
+
if m_sec:
|
|
676
|
+
attrs_raw = m_sec.group(1) or ""
|
|
677
|
+
attrs: dict[str, str] = {}
|
|
678
|
+
for k, v1, v2 in _HTML_ATTR_RE.findall(attrs_raw):
|
|
679
|
+
attrs[k.lower()] = v1 if v1 != "" else v2
|
|
680
|
+
cls = attrs.get("class", "")
|
|
681
|
+
if "slide" in cls.split() or "data-slide" in attrs or "data-bg" in attrs:
|
|
682
|
+
if "slide_number" not in meta and attrs.get("data-slide", "").isdigit():
|
|
683
|
+
meta["slide_number"] = int(attrs["data-slide"])
|
|
684
|
+
if "bg" not in meta and attrs.get("data-bg"):
|
|
685
|
+
meta["bg"] = attrs["data-bg"]
|
|
686
|
+
if "bg_image" not in meta and "data-bg-image" in attrs:
|
|
687
|
+
meta["bg_image"] = attrs["data-bg-image"]
|
|
688
|
+
if "polarity" not in meta and attrs.get("data-polarity"):
|
|
689
|
+
meta["polarity"] = attrs["data-polarity"]
|
|
690
|
+
if "tier" not in meta and attrs.get("data-tier"):
|
|
691
|
+
meta["tier"] = attrs["data-tier"]
|
|
692
|
+
if "transition" not in meta and attrs.get("data-transition"):
|
|
693
|
+
meta["transition"] = attrs["data-transition"]
|
|
694
|
+
if "transition_dur" not in meta and attrs.get("data-transition-dur"):
|
|
695
|
+
meta["transition_dur"] = attrs["data-transition-dur"]
|
|
696
|
+
working = (m_sec.group(2) or "").strip()
|
|
697
|
+
|
|
698
|
+
slide_num = int(meta.get("slide_number") or default_slide_number)
|
|
699
|
+
result: dict[str, Any] = {**meta, "slide_number": slide_num}
|
|
700
|
+
if css_parts:
|
|
701
|
+
existing_css = str(result.get("css") or "").strip()
|
|
702
|
+
joined_css = "\n\n".join(css_parts)
|
|
703
|
+
result["css"] = f"{existing_css}\n\n{joined_css}".strip() if existing_css else joined_css
|
|
704
|
+
result["html"] = working
|
|
705
|
+
return result
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
def serialize_slide_fragment_html(slide: dict[str, Any]) -> str:
|
|
709
|
+
"""Serialize a slide fragment dict into a clean single-slide `.html` source file."""
|
|
710
|
+
meta_keys = (
|
|
711
|
+
"slide_number",
|
|
712
|
+
"bg",
|
|
713
|
+
"bg_image",
|
|
714
|
+
"polarity",
|
|
715
|
+
"tier",
|
|
716
|
+
"include_header",
|
|
717
|
+
"transition",
|
|
718
|
+
"transition_dur",
|
|
719
|
+
)
|
|
720
|
+
meta = {k: slide[k] for k in meta_keys if k in slide and slide[k] is not None}
|
|
721
|
+
parts: list[str] = []
|
|
722
|
+
if meta:
|
|
723
|
+
parts.append(f"<!-- slide: {json.dumps(meta, ensure_ascii=False)} -->")
|
|
724
|
+
css = str(slide.get("css") or "").strip()
|
|
725
|
+
if css:
|
|
726
|
+
parts.append(f"<style>\n{css}\n</style>")
|
|
727
|
+
html = str(slide.get("html") or "").strip()
|
|
728
|
+
if html:
|
|
729
|
+
parts.append(html)
|
|
730
|
+
return "\n".join(parts) + "\n"
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
_CJK_CHAR_RE = re.compile(r"[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]")
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
class _VisibleTextExtractor(HTMLParser):
|
|
737
|
+
_SKIP_TAGS = frozenset({"script", "style", "noscript", "template"})
|
|
738
|
+
|
|
739
|
+
def __init__(self) -> None:
|
|
740
|
+
super().__init__(convert_charrefs=True)
|
|
741
|
+
self._skip_depth = 0
|
|
742
|
+
self.chunks: list[str] = []
|
|
743
|
+
|
|
744
|
+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
|
|
745
|
+
if tag.lower() in self._SKIP_TAGS:
|
|
746
|
+
self._skip_depth += 1
|
|
747
|
+
|
|
748
|
+
def handle_endtag(self, tag: str) -> None:
|
|
749
|
+
if tag.lower() in self._SKIP_TAGS and self._skip_depth > 0:
|
|
750
|
+
self._skip_depth -= 1
|
|
751
|
+
|
|
752
|
+
def handle_data(self, data: str) -> None:
|
|
753
|
+
if self._skip_depth == 0 and data:
|
|
754
|
+
self.chunks.append(data)
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def _extract_visible_html_text(raw_html: str) -> str:
|
|
758
|
+
parser = _VisibleTextExtractor()
|
|
759
|
+
parser.feed(raw_html)
|
|
760
|
+
parser.close()
|
|
761
|
+
return " ".join(parser.chunks)
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
def resolve_deck_lang(
|
|
765
|
+
slides: list[dict[str, Any]],
|
|
766
|
+
*,
|
|
767
|
+
title: str | None = None,
|
|
768
|
+
theme: dict[str, Any] | None = None,
|
|
769
|
+
lang: str | None = None,
|
|
770
|
+
) -> str:
|
|
771
|
+
"""Resolve HTML document lang attribute: explicit value, theme.lang, or auto-detect ('zh-CN' if CJK text else 'en')."""
|
|
772
|
+
raw_explicit = (lang or "").strip()
|
|
773
|
+
if raw_explicit and raw_explicit.lower() != "auto":
|
|
774
|
+
return raw_explicit
|
|
775
|
+
theme_lang = str((theme or {}).get("lang") or "").strip()
|
|
776
|
+
if theme_lang and theme_lang.lower() != "auto":
|
|
777
|
+
return theme_lang
|
|
778
|
+
|
|
779
|
+
samples: list[str] = []
|
|
780
|
+
if title:
|
|
781
|
+
samples.append(html_lib.unescape(str(title)))
|
|
782
|
+
if isinstance(theme, dict) and theme.get("title"):
|
|
783
|
+
samples.append(html_lib.unescape(str(theme["title"])))
|
|
784
|
+
for sl in slides or []:
|
|
785
|
+
if not isinstance(sl, dict):
|
|
786
|
+
continue
|
|
787
|
+
raw_html = str(sl.get("html") or "")
|
|
788
|
+
if raw_html:
|
|
789
|
+
samples.append(_extract_visible_html_text(raw_html))
|
|
790
|
+
if _CJK_CHAR_RE.search("\n".join(samples)):
|
|
791
|
+
return "zh-CN"
|
|
792
|
+
return "en"
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
def assemble_deck_html(
|
|
796
|
+
slides: list[dict[str, Any]],
|
|
797
|
+
theme: dict[str, Any] | None = None,
|
|
798
|
+
title: str | None = None,
|
|
799
|
+
*,
|
|
800
|
+
ratio: str | None = None,
|
|
801
|
+
width: int | None = None,
|
|
802
|
+
height: int | None = None,
|
|
803
|
+
lang: str | None = None,
|
|
804
|
+
) -> str:
|
|
805
|
+
"""Assemble a complete self-contained HTML presentation from per-slide fragments.
|
|
806
|
+
|
|
807
|
+
Parameters
|
|
808
|
+
----------
|
|
809
|
+
slides:
|
|
810
|
+
Ordered list of slide fragment dicts:
|
|
811
|
+
- slide_number (int, optional; defaults to 1..N)
|
|
812
|
+
- bg (str, optional; CSS color or gradient, e.g. '#F4EFE3' or 'radial-gradient(...)')
|
|
813
|
+
- bg_image (str | None, optional; relative/URL backdrop image path; '' explicitly disables theme.bg_image)
|
|
814
|
+
- css (str, optional; per-slide CSS rules)
|
|
815
|
+
- html (str; inner HTML markup for the slide)
|
|
816
|
+
- tier (str, optional; e.g. 'T1'/'T2'/'T3'/'T4')
|
|
817
|
+
- polarity (str, optional; 'light' or 'dark', auto-inferred from bg)
|
|
818
|
+
- include_header (bool, optional; default True if theme.header is configured)
|
|
819
|
+
- transition (str, optional; 'auto' | 'none' | 'fade' | 'push' | 'morph')
|
|
820
|
+
- transition_dur (int, optional; transition duration in ms, 150..2000)
|
|
821
|
+
theme:
|
|
822
|
+
Optional theme dict:
|
|
823
|
+
- title (str)
|
|
824
|
+
- font_style ('sans' | 'serif', default 'sans')
|
|
825
|
+
- motion ('none' | 'refined' | 'cinematic', default 'none' — static unless the user asks for motion)
|
|
826
|
+
- polarity ('light' | 'dark', auto-inferred if omitted)
|
|
827
|
+
- bg, ink, ink_muted, accent, surface, border (CSS color strings)
|
|
828
|
+
- bg_image (str, optional; deck-wide default backdrop image path)
|
|
829
|
+
- tokens (dict of extra CSS custom properties)
|
|
830
|
+
- global_css (str; shared CSS injected after shell defaults)
|
|
831
|
+
- header (dict; optional pixel-locked shared header config)
|
|
832
|
+
title:
|
|
833
|
+
Optional HTML <title> override.
|
|
834
|
+
"""
|
|
835
|
+
if not slides:
|
|
836
|
+
raise ValueError("slides must be a non-empty list of slide fragment objects.")
|
|
837
|
+
|
|
838
|
+
# Hard guard: reject embedding text-baked Stage-1 reference drafts directly into editable HTML
|
|
839
|
+
baked_hits: list[str] = []
|
|
840
|
+
theme_bg_img = (theme or {}).get("bg_image")
|
|
841
|
+
if isinstance(theme_bg_img, str):
|
|
842
|
+
baked_hits.extend(find_baked_reference_embeds(theme_bg_img))
|
|
843
|
+
for sl in slides:
|
|
844
|
+
if isinstance(sl, dict):
|
|
845
|
+
for field_name in ("bg_image", "css", "html"):
|
|
846
|
+
val = sl.get(field_name)
|
|
847
|
+
if isinstance(val, str):
|
|
848
|
+
baked_hits.extend(find_baked_reference_embeds(val))
|
|
849
|
+
if baked_hits:
|
|
850
|
+
uniq = ", ".join(sorted(set(baked_hits)))
|
|
851
|
+
raise ValueError(
|
|
852
|
+
f"Refusing to embed text-baked reference draft(s) ({uniq}) into web/index.html. "
|
|
853
|
+
"Stage-1 reference images contain baked raster text and are NOT editable HTML slides. "
|
|
854
|
+
"Extract clean illustrations with crop_asset.py into assets/crops/, generate text-free backdrops "
|
|
855
|
+
"into assets/plates/, or render native editable HTML/CSS/SVG text and shapes."
|
|
856
|
+
)
|
|
857
|
+
|
|
858
|
+
theme_cfg: dict[str, Any] = dict(theme or {})
|
|
859
|
+
canvas_w, canvas_h, ratio_str = resolve_canvas_dimensions(
|
|
860
|
+
ratio=ratio, width=width, height=height, theme=theme_cfg
|
|
861
|
+
)
|
|
862
|
+
deck_title = (title or theme_cfg.get("title") or "Presentation").strip()
|
|
863
|
+
font_style = str(theme_cfg.get("font_style") or "sans").strip().lower()
|
|
864
|
+
motion_preset = str(theme_cfg.get("motion") or "none").strip().lower()
|
|
865
|
+
if motion_preset not in ("none", "refined", "cinematic"):
|
|
866
|
+
motion_preset = "none"
|
|
867
|
+
|
|
868
|
+
# Sort slides by slide_number if explicitly provided, otherwise keep input order
|
|
869
|
+
normalized_slides: list[dict[str, Any]] = []
|
|
870
|
+
for idx, raw in enumerate(slides, start=1):
|
|
871
|
+
if not isinstance(raw, dict):
|
|
872
|
+
raise ValueError(f"slides[{idx - 1}] must be an object/dict.")
|
|
873
|
+
s_num = int(raw.get("slide_number") or idx)
|
|
874
|
+
normalized_slides.append({**raw, "slide_number": s_num})
|
|
875
|
+
normalized_slides.sort(key=lambda s: s["slide_number"])
|
|
876
|
+
|
|
877
|
+
# Re-index sequentially 1..N if needed while preserving explicit ordering
|
|
878
|
+
total_slides = len(normalized_slides)
|
|
879
|
+
default_bg = str(theme_cfg.get("bg") or normalized_slides[0].get("bg") or "#FFFFFF").strip()
|
|
880
|
+
default_bg_hex = _extract_solid_hex(default_bg, "#FFFFFF")
|
|
881
|
+
default_bg_image = str(theme_cfg.get("bg_image") or "").strip()
|
|
882
|
+
default_polarity = str(theme_cfg.get("polarity") or _infer_polarity(default_bg_hex)).strip().lower()
|
|
883
|
+
if default_polarity not in ("light", "dark"):
|
|
884
|
+
default_polarity = _infer_polarity(default_bg_hex)
|
|
885
|
+
|
|
886
|
+
default_ink = str(theme_cfg.get("ink") or ("#1A1F1C" if default_polarity == "light" else "#F4F7FB")).strip()
|
|
887
|
+
default_ink_muted = str(
|
|
888
|
+
theme_cfg.get("ink_muted") or ("#5B635E" if default_polarity == "light" else "#9FB0C9")
|
|
889
|
+
).strip()
|
|
890
|
+
default_accent = str(theme_cfg.get("accent") or "#4D6BFE").strip()
|
|
891
|
+
default_surface = str(
|
|
892
|
+
theme_cfg.get("surface") or ("rgba(255, 255, 255, 0.78)" if default_polarity == "light" else "rgba(255, 255, 255, 0.06)")
|
|
893
|
+
).strip()
|
|
894
|
+
default_border = str(
|
|
895
|
+
theme_cfg.get("border") or ("rgba(26, 31, 28, 0.14)" if default_polarity == "light" else "rgba(255, 255, 255, 0.14)")
|
|
896
|
+
).strip()
|
|
897
|
+
|
|
898
|
+
font_face_css, display_stack, body_stack, num_stack, mono_stack = _build_font_faces(font_style)
|
|
899
|
+
|
|
900
|
+
# Extra CSS tokens
|
|
901
|
+
extra_token_lines: list[str] = []
|
|
902
|
+
raw_tokens = theme_cfg.get("tokens")
|
|
903
|
+
if isinstance(raw_tokens, dict):
|
|
904
|
+
for k, v in raw_tokens.items():
|
|
905
|
+
key = str(k).strip()
|
|
906
|
+
if not key:
|
|
907
|
+
continue
|
|
908
|
+
if not key.startswith("--"):
|
|
909
|
+
key = f"--{key}"
|
|
910
|
+
extra_token_lines.append(f" {key}: {v};")
|
|
911
|
+
extra_tokens_block = ("\n" + "\n".join(extra_token_lines)) if extra_token_lines else ""
|
|
912
|
+
|
|
913
|
+
# Header geometry overrides
|
|
914
|
+
header_cfg = theme_cfg.get("header") if isinstance(theme_cfg.get("header"), dict) else None
|
|
915
|
+
hdr_top = int(header_cfg.get("top", 56)) if header_cfg else 56
|
|
916
|
+
hdr_left = int(header_cfg.get("left", 112)) if header_cfg else 112
|
|
917
|
+
hdr_right = int(header_cfg.get("right", 112)) if header_cfg else 112
|
|
918
|
+
hdr_color = str(header_cfg.get("color") or "var(--ink)") if header_cfg else "var(--ink)"
|
|
919
|
+
hdr_page_color = str(header_cfg.get("page_num_color") or "var(--ink-muted)") if header_cfg else "var(--ink-muted)"
|
|
920
|
+
|
|
921
|
+
global_css = (theme_cfg.get("global_css") or "").strip()
|
|
922
|
+
|
|
923
|
+
per_slide_css_blocks: list[str] = []
|
|
924
|
+
slide_sections: list[str] = []
|
|
925
|
+
|
|
926
|
+
for pos, slide in enumerate(normalized_slides, start=1):
|
|
927
|
+
slide_bg = str(slide.get("bg") or default_bg).strip()
|
|
928
|
+
slide_bg_hex = _extract_solid_hex(slide_bg, default_bg_hex)
|
|
929
|
+
if "bg_image" in slide and slide["bg_image"] is not None:
|
|
930
|
+
slide_bg_image = str(slide["bg_image"]).strip()
|
|
931
|
+
else:
|
|
932
|
+
slide_bg_image = default_bg_image
|
|
933
|
+
|
|
934
|
+
slide_polarity = str(slide.get("polarity") or _infer_polarity(slide_bg_hex, default_polarity)).strip().lower()
|
|
935
|
+
slide_tier = str(slide.get("tier") or "").strip()
|
|
936
|
+
slide_transition = str(slide.get("transition") or "auto").strip().lower()
|
|
937
|
+
if slide_transition not in ("auto", "none", "fade", "push", "morph"):
|
|
938
|
+
slide_transition = "auto"
|
|
939
|
+
raw_dur = slide.get("transition_dur")
|
|
940
|
+
slide_transition_dur: int | None = None
|
|
941
|
+
if raw_dur is not None and str(raw_dur).strip() != "":
|
|
942
|
+
try:
|
|
943
|
+
slide_transition_dur = max(150, min(2000, int(float(raw_dur))))
|
|
944
|
+
except (TypeError, ValueError):
|
|
945
|
+
slide_transition_dur = None
|
|
946
|
+
slide_css = (slide.get("css") or "").strip()
|
|
947
|
+
slide_html = (slide.get("html") or "").strip()
|
|
948
|
+
|
|
949
|
+
if slide_css:
|
|
950
|
+
scoped_css = scope_slide_css(slide_css, pos)
|
|
951
|
+
per_slide_css_blocks.append(f" /* --- Slide {pos} --- */\n{scoped_css}")
|
|
952
|
+
|
|
953
|
+
header_snippet = ""
|
|
954
|
+
include_header = slide.get("include_header", True)
|
|
955
|
+
if header_cfg and include_header and "<header" not in slide_html.lower():
|
|
956
|
+
header_snippet = _build_header_html(header_cfg, pos, total_slides) + "\n"
|
|
957
|
+
|
|
958
|
+
active_cls = " is-active" if pos == 1 else ""
|
|
959
|
+
tier_attr = f' data-tier="{html_lib.escape(slide_tier, quote=True)}"' if slide_tier else ""
|
|
960
|
+
trans_attr = (
|
|
961
|
+
f' data-transition="{html_lib.escape(slide_transition, quote=True)}"'
|
|
962
|
+
if slide_transition != "auto"
|
|
963
|
+
else ""
|
|
964
|
+
)
|
|
965
|
+
trans_dur_attr = f' data-transition-dur="{slide_transition_dur}"' if slide_transition_dur is not None else ""
|
|
966
|
+
# Keep data-bg strictly as the solid fallback hex color so outer viewport letterbox never stretches artwork
|
|
967
|
+
data_bg_attr = html_lib.escape(slide_bg_hex, quote=True)
|
|
968
|
+
pol_attr = html_lib.escape(slide_polarity, quote=True)
|
|
969
|
+
|
|
970
|
+
if slide_bg_image:
|
|
971
|
+
escaped_url = _escape_css_url(slide_bg_image)
|
|
972
|
+
bg_style = f"{slide_bg_hex} url('{escaped_url}') center / cover no-repeat"
|
|
973
|
+
else:
|
|
974
|
+
bg_style = slide_bg
|
|
975
|
+
bg_style_attr = _escape_double_quoted_attr(bg_style)
|
|
976
|
+
|
|
977
|
+
section = (
|
|
978
|
+
f' <section class="slide{active_cls}" data-slide="{pos}" '
|
|
979
|
+
f'data-bg="{data_bg_attr}" data-polarity="{pol_attr}"{tier_attr}{trans_attr}{trans_dur_attr} '
|
|
980
|
+
f'style="background: {bg_style_attr};">\n'
|
|
981
|
+
f"{header_snippet}"
|
|
982
|
+
f"{slide_html}\n"
|
|
983
|
+
f" </section>"
|
|
984
|
+
)
|
|
985
|
+
slide_sections.append(section)
|
|
986
|
+
|
|
987
|
+
global_css_section = f"\n /* === Theme Global CSS === */\n{global_css}\n" if global_css else ""
|
|
988
|
+
slides_css_section = ("\n /* === Per-Slide CSS === */\n" + "\n\n".join(per_slide_css_blocks) + "\n") if per_slide_css_blocks else ""
|
|
989
|
+
sections_html = "\n".join(slide_sections)
|
|
990
|
+
escaped_title = html_lib.escape(deck_title)
|
|
991
|
+
escaped_bg = html_lib.escape(default_bg_hex, quote=True)
|
|
992
|
+
resolved_lang = resolve_deck_lang(slides, title=deck_title, theme=theme_cfg, lang=lang)
|
|
993
|
+
escaped_lang = html_lib.escape(resolved_lang, quote=True)
|
|
994
|
+
|
|
995
|
+
return f"""<!DOCTYPE html>
|
|
996
|
+
<html lang="{escaped_lang}">
|
|
997
|
+
<head>
|
|
998
|
+
<meta charset="UTF-8" />
|
|
999
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
1000
|
+
<title>{escaped_title}</title>
|
|
1001
|
+
<link rel="icon" href="data:," />
|
|
1002
|
+
<style>
|
|
1003
|
+
{font_face_css}
|
|
1004
|
+
|
|
1005
|
+
:root {{
|
|
1006
|
+
--font-display: {display_stack};
|
|
1007
|
+
--font-serif: 'Fraunces', 'Noto Serif SC', 'BrandSerif', 'STSongti-SC-Bold', 'Songti SC', Georgia, serif;
|
|
1008
|
+
--font-editorial: 'Instrument Serif', 'ZhuqueFangsong', 'Noto Serif SC', Georgia, serif;
|
|
1009
|
+
--font-poster: 'Space Grotesk', 'Syne', 'AlimamaShuHei', 'AlibabaPuHuiTi3', sans-serif;
|
|
1010
|
+
--font-num: {num_stack};
|
|
1011
|
+
--font-sans: {body_stack};
|
|
1012
|
+
--font-mono: {mono_stack};
|
|
1013
|
+
--bg: {default_bg};
|
|
1014
|
+
--ink: {default_ink};
|
|
1015
|
+
--ink-muted: {default_ink_muted};
|
|
1016
|
+
--accent: {default_accent};
|
|
1017
|
+
--surface: {default_surface};
|
|
1018
|
+
--border: {default_border};{extra_tokens_block}
|
|
1019
|
+
}}
|
|
1020
|
+
|
|
1021
|
+
*, *::before, *::after {{
|
|
1022
|
+
box-sizing: border-box;
|
|
1023
|
+
}}
|
|
1024
|
+
|
|
1025
|
+
html, body {{
|
|
1026
|
+
width: 100vw;
|
|
1027
|
+
height: 100vh;
|
|
1028
|
+
margin: 0;
|
|
1029
|
+
padding: 0;
|
|
1030
|
+
overflow: hidden;
|
|
1031
|
+
background: {default_bg_hex};
|
|
1032
|
+
color: var(--ink);
|
|
1033
|
+
font-family: var(--font-sans);
|
|
1034
|
+
-webkit-font-smoothing: antialiased;
|
|
1035
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1036
|
+
box-shadow: none;
|
|
1037
|
+
}}
|
|
1038
|
+
|
|
1039
|
+
.deck-viewport {{
|
|
1040
|
+
position: relative;
|
|
1041
|
+
width: 100vw;
|
|
1042
|
+
height: 100vh;
|
|
1043
|
+
overflow: hidden;
|
|
1044
|
+
}}
|
|
1045
|
+
|
|
1046
|
+
.deck-stage {{
|
|
1047
|
+
position: absolute;
|
|
1048
|
+
left: 50%;
|
|
1049
|
+
top: 50%;
|
|
1050
|
+
width: {canvas_w}px;
|
|
1051
|
+
height: {canvas_h}px;
|
|
1052
|
+
transform: translate(-50%, -50%);
|
|
1053
|
+
transform-origin: center center;
|
|
1054
|
+
overflow: hidden;
|
|
1055
|
+
box-shadow: none;
|
|
1056
|
+
}}
|
|
1057
|
+
|
|
1058
|
+
.slide {{
|
|
1059
|
+
position: absolute;
|
|
1060
|
+
inset: 0;
|
|
1061
|
+
width: {canvas_w}px;
|
|
1062
|
+
height: {canvas_h}px;
|
|
1063
|
+
display: none;
|
|
1064
|
+
overflow: hidden;
|
|
1065
|
+
}}
|
|
1066
|
+
|
|
1067
|
+
.slide.is-active {{
|
|
1068
|
+
display: block;
|
|
1069
|
+
z-index: 2;
|
|
1070
|
+
}}
|
|
1071
|
+
|
|
1072
|
+
.slide.is-leaving {{
|
|
1073
|
+
display: block;
|
|
1074
|
+
z-index: 1;
|
|
1075
|
+
pointer-events: none;
|
|
1076
|
+
}}
|
|
1077
|
+
|
|
1078
|
+
.slide.is-entering {{
|
|
1079
|
+
display: block;
|
|
1080
|
+
z-index: 3;
|
|
1081
|
+
}}
|
|
1082
|
+
|
|
1083
|
+
.deck-morph-underlay {{
|
|
1084
|
+
position: absolute;
|
|
1085
|
+
inset: 0;
|
|
1086
|
+
width: {canvas_w}px;
|
|
1087
|
+
height: {canvas_h}px;
|
|
1088
|
+
z-index: 0;
|
|
1089
|
+
pointer-events: none;
|
|
1090
|
+
}}
|
|
1091
|
+
|
|
1092
|
+
.is-step-hidden {{
|
|
1093
|
+
opacity: 0 !important;
|
|
1094
|
+
pointer-events: none !important;
|
|
1095
|
+
}}
|
|
1096
|
+
|
|
1097
|
+
body.capture-mode .is-step-hidden {{
|
|
1098
|
+
opacity: 1 !important;
|
|
1099
|
+
pointer-events: auto !important;
|
|
1100
|
+
}}
|
|
1101
|
+
|
|
1102
|
+
body.capture-mode .slide.is-leaving,
|
|
1103
|
+
body.capture-mode .deck-morph-underlay {{
|
|
1104
|
+
display: none !important;
|
|
1105
|
+
}}
|
|
1106
|
+
|
|
1107
|
+
body.capture-mode *,
|
|
1108
|
+
body.capture-mode *::before,
|
|
1109
|
+
body.capture-mode *::after {{
|
|
1110
|
+
animation: none !important;
|
|
1111
|
+
transition: none !important;
|
|
1112
|
+
}}
|
|
1113
|
+
|
|
1114
|
+
.slide-header {{
|
|
1115
|
+
position: absolute;
|
|
1116
|
+
top: {hdr_top}px;
|
|
1117
|
+
left: {hdr_left}px;
|
|
1118
|
+
right: {hdr_right}px;
|
|
1119
|
+
display: flex;
|
|
1120
|
+
justify-content: space-between;
|
|
1121
|
+
align-items: center;
|
|
1122
|
+
z-index: 20;
|
|
1123
|
+
color: {hdr_color};
|
|
1124
|
+
}}
|
|
1125
|
+
|
|
1126
|
+
.brand-lockup {{
|
|
1127
|
+
display: flex;
|
|
1128
|
+
align-items: center;
|
|
1129
|
+
gap: 12px;
|
|
1130
|
+
}}
|
|
1131
|
+
|
|
1132
|
+
.brand-logo {{
|
|
1133
|
+
display: block;
|
|
1134
|
+
height: 42px;
|
|
1135
|
+
width: auto;
|
|
1136
|
+
object-fit: contain;
|
|
1137
|
+
}}
|
|
1138
|
+
|
|
1139
|
+
.brand-logo-svg {{
|
|
1140
|
+
display: inline-flex;
|
|
1141
|
+
align-items: center;
|
|
1142
|
+
}}
|
|
1143
|
+
|
|
1144
|
+
.brand-logo-svg svg {{
|
|
1145
|
+
height: 100%;
|
|
1146
|
+
width: auto;
|
|
1147
|
+
display: block;
|
|
1148
|
+
}}
|
|
1149
|
+
|
|
1150
|
+
.brand-name {{
|
|
1151
|
+
font-family: var(--font-sans);
|
|
1152
|
+
font-size: 25px;
|
|
1153
|
+
font-weight: 700;
|
|
1154
|
+
letter-spacing: 0.03em;
|
|
1155
|
+
line-height: 1;
|
|
1156
|
+
}}
|
|
1157
|
+
|
|
1158
|
+
.page-num {{
|
|
1159
|
+
font-family: var(--font-sans);
|
|
1160
|
+
font-size: 22px;
|
|
1161
|
+
font-weight: 600;
|
|
1162
|
+
letter-spacing: 0.06em;
|
|
1163
|
+
font-variant-numeric: tabular-nums;
|
|
1164
|
+
color: {hdr_page_color};
|
|
1165
|
+
}}
|
|
1166
|
+
|
|
1167
|
+
.deck-controls {{
|
|
1168
|
+
position: fixed;
|
|
1169
|
+
right: 24px;
|
|
1170
|
+
bottom: 20px;
|
|
1171
|
+
z-index: 100;
|
|
1172
|
+
display: flex;
|
|
1173
|
+
align-items: center;
|
|
1174
|
+
gap: 8px;
|
|
1175
|
+
padding: 6px 10px;
|
|
1176
|
+
border-radius: 999px;
|
|
1177
|
+
background: rgba(20, 24, 28, 0.56);
|
|
1178
|
+
color: #F4F7FB;
|
|
1179
|
+
backdrop-filter: blur(8px);
|
|
1180
|
+
-webkit-backdrop-filter: blur(8px);
|
|
1181
|
+
font-family: var(--font-sans);
|
|
1182
|
+
font-size: 13px;
|
|
1183
|
+
font-variant-numeric: tabular-nums;
|
|
1184
|
+
opacity: 0.72;
|
|
1185
|
+
transition: opacity 240ms ease;
|
|
1186
|
+
user-select: none;
|
|
1187
|
+
}}
|
|
1188
|
+
|
|
1189
|
+
body[data-polarity="light"] .deck-controls {{
|
|
1190
|
+
background: rgba(255, 255, 255, 0.76);
|
|
1191
|
+
color: #1F2421;
|
|
1192
|
+
border: 1px solid rgba(26, 31, 28, 0.12);
|
|
1193
|
+
}}
|
|
1194
|
+
|
|
1195
|
+
.deck-controls.is-idle {{
|
|
1196
|
+
opacity: 0.16;
|
|
1197
|
+
}}
|
|
1198
|
+
|
|
1199
|
+
.deck-controls:hover {{
|
|
1200
|
+
opacity: 1;
|
|
1201
|
+
}}
|
|
1202
|
+
|
|
1203
|
+
.deck-controls button {{
|
|
1204
|
+
border: none;
|
|
1205
|
+
background: transparent;
|
|
1206
|
+
color: inherit;
|
|
1207
|
+
cursor: pointer;
|
|
1208
|
+
width: 26px;
|
|
1209
|
+
height: 26px;
|
|
1210
|
+
border-radius: 50%;
|
|
1211
|
+
display: inline-flex;
|
|
1212
|
+
align-items: center;
|
|
1213
|
+
justify-content: center;
|
|
1214
|
+
font-size: 14px;
|
|
1215
|
+
padding: 0;
|
|
1216
|
+
}}
|
|
1217
|
+
|
|
1218
|
+
.deck-controls button:hover {{
|
|
1219
|
+
background: rgba(127, 127, 127, 0.18);
|
|
1220
|
+
}}
|
|
1221
|
+
|
|
1222
|
+
.deck-controls .ctrl-counter {{
|
|
1223
|
+
min-width: 54px;
|
|
1224
|
+
text-align: center;
|
|
1225
|
+
letter-spacing: 0.06em;
|
|
1226
|
+
}}
|
|
1227
|
+
|
|
1228
|
+
body.capture-mode .deck-controls,
|
|
1229
|
+
body.studio-embed .deck-controls {{
|
|
1230
|
+
display: none !important;
|
|
1231
|
+
}}
|
|
1232
|
+
|
|
1233
|
+
.deck-tapzones {{
|
|
1234
|
+
position: fixed;
|
|
1235
|
+
inset: 0;
|
|
1236
|
+
z-index: 90;
|
|
1237
|
+
display: flex;
|
|
1238
|
+
pointer-events: none;
|
|
1239
|
+
}}
|
|
1240
|
+
|
|
1241
|
+
.deck-tapzone {{
|
|
1242
|
+
height: 100%;
|
|
1243
|
+
pointer-events: auto;
|
|
1244
|
+
touch-action: manipulation;
|
|
1245
|
+
-webkit-tap-highlight-color: transparent;
|
|
1246
|
+
}}
|
|
1247
|
+
|
|
1248
|
+
.deck-tapzone--prev,
|
|
1249
|
+
.deck-tapzone--next {{
|
|
1250
|
+
flex: 0 0 28%;
|
|
1251
|
+
}}
|
|
1252
|
+
|
|
1253
|
+
.deck-tapzone--mid {{
|
|
1254
|
+
flex: 1 1 auto;
|
|
1255
|
+
pointer-events: none;
|
|
1256
|
+
}}
|
|
1257
|
+
|
|
1258
|
+
@media (hover: hover) and (pointer: fine) {{
|
|
1259
|
+
.deck-tapzones {{
|
|
1260
|
+
display: none !important;
|
|
1261
|
+
}}
|
|
1262
|
+
}}
|
|
1263
|
+
|
|
1264
|
+
body.capture-mode .deck-tapzones,
|
|
1265
|
+
body.studio-embed .deck-tapzones {{
|
|
1266
|
+
display: none !important;
|
|
1267
|
+
}}
|
|
1268
|
+
|
|
1269
|
+
@page {{
|
|
1270
|
+
size: {canvas_w}px {canvas_h}px;
|
|
1271
|
+
margin: 0;
|
|
1272
|
+
}}
|
|
1273
|
+
|
|
1274
|
+
@media print {{
|
|
1275
|
+
*, *::before, *::after {{
|
|
1276
|
+
-webkit-print-color-adjust: exact !important;
|
|
1277
|
+
print-color-adjust: exact !important;
|
|
1278
|
+
animation: none !important;
|
|
1279
|
+
transition: none !important;
|
|
1280
|
+
}}
|
|
1281
|
+
|
|
1282
|
+
html, body {{
|
|
1283
|
+
width: {canvas_w}px !important;
|
|
1284
|
+
height: auto !important;
|
|
1285
|
+
margin: 0 !important;
|
|
1286
|
+
padding: 0 !important;
|
|
1287
|
+
overflow: visible !important;
|
|
1288
|
+
background: #FFFFFF !important;
|
|
1289
|
+
}}
|
|
1290
|
+
|
|
1291
|
+
.deck-viewport {{
|
|
1292
|
+
position: static !important;
|
|
1293
|
+
width: {canvas_w}px !important;
|
|
1294
|
+
height: auto !important;
|
|
1295
|
+
overflow: visible !important;
|
|
1296
|
+
}}
|
|
1297
|
+
|
|
1298
|
+
.deck-stage {{
|
|
1299
|
+
position: static !important;
|
|
1300
|
+
left: auto !important;
|
|
1301
|
+
top: auto !important;
|
|
1302
|
+
width: {canvas_w}px !important;
|
|
1303
|
+
height: auto !important;
|
|
1304
|
+
transform: none !important;
|
|
1305
|
+
overflow: visible !important;
|
|
1306
|
+
}}
|
|
1307
|
+
|
|
1308
|
+
.slide {{
|
|
1309
|
+
position: relative !important;
|
|
1310
|
+
inset: auto !important;
|
|
1311
|
+
display: block !important;
|
|
1312
|
+
width: {canvas_w}px !important;
|
|
1313
|
+
height: {canvas_h}px !important;
|
|
1314
|
+
opacity: 1 !important;
|
|
1315
|
+
visibility: visible !important;
|
|
1316
|
+
pointer-events: auto !important;
|
|
1317
|
+
overflow: hidden !important;
|
|
1318
|
+
break-after: page;
|
|
1319
|
+
page-break-after: always;
|
|
1320
|
+
break-inside: avoid;
|
|
1321
|
+
page-break-inside: avoid;
|
|
1322
|
+
}}
|
|
1323
|
+
|
|
1324
|
+
.slide:last-child {{
|
|
1325
|
+
break-after: auto;
|
|
1326
|
+
page-break-after: auto;
|
|
1327
|
+
}}
|
|
1328
|
+
|
|
1329
|
+
.is-step-hidden {{
|
|
1330
|
+
opacity: 1 !important;
|
|
1331
|
+
pointer-events: auto !important;
|
|
1332
|
+
}}
|
|
1333
|
+
|
|
1334
|
+
.deck-controls,
|
|
1335
|
+
.deck-tapzones,
|
|
1336
|
+
.deck-morph-underlay {{
|
|
1337
|
+
display: none !important;
|
|
1338
|
+
}}
|
|
1339
|
+
}}
|
|
1340
|
+
{global_css_section}{slides_css_section} </style>
|
|
1341
|
+
</head>
|
|
1342
|
+
<body data-polarity="{default_polarity}" data-bg="{escaped_bg}" data-motion="{motion_preset}" data-ratio="{ratio_str}" data-canvas="{canvas_w}x{canvas_h}">
|
|
1343
|
+
<main class="deck-viewport">
|
|
1344
|
+
<div class="deck-stage" id="deck-stage">
|
|
1345
|
+
{sections_html}
|
|
1346
|
+
</div>
|
|
1347
|
+
</main>
|
|
1348
|
+
|
|
1349
|
+
<div class="deck-tapzones" id="deck-tapzones" aria-hidden="true">
|
|
1350
|
+
<div class="deck-tapzone deck-tapzone--prev" id="deck-tap-prev"></div>
|
|
1351
|
+
<div class="deck-tapzone deck-tapzone--mid"></div>
|
|
1352
|
+
<div class="deck-tapzone deck-tapzone--next" id="deck-tap-next"></div>
|
|
1353
|
+
</div>
|
|
1354
|
+
|
|
1355
|
+
<nav class="deck-controls" id="deck-controls" aria-label="Slide navigation">
|
|
1356
|
+
<button type="button" id="deck-prev" aria-label="Previous slide">←</button>
|
|
1357
|
+
<span class="ctrl-counter" id="deck-counter">01 / {total_slides:02d}</span>
|
|
1358
|
+
<button type="button" id="deck-next" aria-label="Next slide">→</button>
|
|
1359
|
+
</nav>
|
|
1360
|
+
|
|
1361
|
+
<script>
|
|
1362
|
+
(function () {{
|
|
1363
|
+
const stage = document.getElementById('deck-stage');
|
|
1364
|
+
const controls = document.getElementById('deck-controls');
|
|
1365
|
+
const counterEl = document.getElementById('deck-counter');
|
|
1366
|
+
const prevBtn = document.getElementById('deck-prev');
|
|
1367
|
+
const nextBtn = document.getElementById('deck-next');
|
|
1368
|
+
const tapPrev = document.getElementById('deck-tap-prev');
|
|
1369
|
+
const tapNext = document.getElementById('deck-tap-next');
|
|
1370
|
+
const slides = Array.from(stage.querySelectorAll('.slide'));
|
|
1371
|
+
const total = slides.length;
|
|
1372
|
+
let currentIndex = 0;
|
|
1373
|
+
let lastNotifiedSlideIndex = -1;
|
|
1374
|
+
let idleTimer = null;
|
|
1375
|
+
|
|
1376
|
+
const EASE_OUT_EXPO = 'cubic-bezier(0.22, 1, 0.36, 1)';
|
|
1377
|
+
const EASE_MORPH = 'cubic-bezier(0.4, 0, 0.2, 1)';
|
|
1378
|
+
const MOTION_PRESETS = {{
|
|
1379
|
+
none: {{ fade: 0, push: 0, morph: 0, enter: 0, stagger: 0, slideScale: 1 }},
|
|
1380
|
+
refined: {{ fade: 340, push: 420, morph: 840, enter: 380, stagger: 75, slideScale: 0.996 }},
|
|
1381
|
+
cinematic: {{ fade: 460, push: 540, morph: 1040, enter: 480, stagger: 95, slideScale: 0.988 }},
|
|
1382
|
+
}};
|
|
1383
|
+
|
|
1384
|
+
let activeAnimations = [];
|
|
1385
|
+
let cleanupCallbacks = [];
|
|
1386
|
+
let settleTimer = null;
|
|
1387
|
+
let clickGroups = [];
|
|
1388
|
+
let clickStepIndex = 0;
|
|
1389
|
+
|
|
1390
|
+
function getMotionPreset() {{
|
|
1391
|
+
const raw = (document.body.getAttribute('data-motion') || 'none').trim().toLowerCase();
|
|
1392
|
+
return Object.prototype.hasOwnProperty.call(MOTION_PRESETS, raw) ? raw : 'none';
|
|
1393
|
+
}}
|
|
1394
|
+
|
|
1395
|
+
function isMotionDisabled() {{
|
|
1396
|
+
if (document.body.classList.contains('capture-mode')) return true;
|
|
1397
|
+
if (getMotionPreset() === 'none') return true;
|
|
1398
|
+
try {{
|
|
1399
|
+
if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) {{
|
|
1400
|
+
return true;
|
|
1401
|
+
}}
|
|
1402
|
+
}} catch (_e) {{}}
|
|
1403
|
+
return false;
|
|
1404
|
+
}}
|
|
1405
|
+
|
|
1406
|
+
function trackAnim(anim) {{
|
|
1407
|
+
if (anim) activeAnimations.push(anim);
|
|
1408
|
+
return anim;
|
|
1409
|
+
}}
|
|
1410
|
+
|
|
1411
|
+
function addCleanup(fn) {{
|
|
1412
|
+
if (typeof fn === 'function') cleanupCallbacks.push(fn);
|
|
1413
|
+
}}
|
|
1414
|
+
|
|
1415
|
+
function settleAll() {{
|
|
1416
|
+
if (settleTimer) {{
|
|
1417
|
+
clearTimeout(settleTimer);
|
|
1418
|
+
settleTimer = null;
|
|
1419
|
+
}}
|
|
1420
|
+
const anims = activeAnimations.splice(0);
|
|
1421
|
+
for (let i = 0; i < anims.length; i++) {{
|
|
1422
|
+
try {{ anims[i].cancel(); }} catch (_e) {{}}
|
|
1423
|
+
}}
|
|
1424
|
+
const fns = cleanupCallbacks.splice(0);
|
|
1425
|
+
for (let i = fns.length - 1; i >= 0; i--) {{
|
|
1426
|
+
try {{ fns[i](); }} catch (_e) {{}}
|
|
1427
|
+
}}
|
|
1428
|
+
slides.forEach((el) => {{
|
|
1429
|
+
el.classList.remove('is-leaving', 'is-entering');
|
|
1430
|
+
}});
|
|
1431
|
+
stage.querySelectorAll('.deck-morph-underlay').forEach((n) => n.remove());
|
|
1432
|
+
}}
|
|
1433
|
+
|
|
1434
|
+
function fitStage() {{
|
|
1435
|
+
const s = Math.min(window.innerWidth / {canvas_w}, window.innerHeight / {canvas_h});
|
|
1436
|
+
stage.style.transform = `translate(-50%, -50%) scale(${{s}})`;
|
|
1437
|
+
}}
|
|
1438
|
+
|
|
1439
|
+
function formatCounter(idx) {{
|
|
1440
|
+
const cur = String(idx + 1).padStart(2, '0');
|
|
1441
|
+
const tot = String(total).padStart(2, '0');
|
|
1442
|
+
return `${{cur}} / ${{tot}}`;
|
|
1443
|
+
}}
|
|
1444
|
+
|
|
1445
|
+
function getStageCoords(el) {{
|
|
1446
|
+
const sr = stage.getBoundingClientRect();
|
|
1447
|
+
const r = el.getBoundingClientRect();
|
|
1448
|
+
const sx = sr.width > 0 ? {canvas_w} / sr.width : 1;
|
|
1449
|
+
const sy = sr.height > 0 ? {canvas_h} / sr.height : 1;
|
|
1450
|
+
const x = (r.left - sr.left) * sx;
|
|
1451
|
+
const y = (r.top - sr.top) * sy;
|
|
1452
|
+
const w = r.width * sx;
|
|
1453
|
+
const h = r.height * sy;
|
|
1454
|
+
return {{ x, y, w, h, cx: x + w * 0.5, cy: y + h * 0.5 }};
|
|
1455
|
+
}}
|
|
1456
|
+
|
|
1457
|
+
function collectMorphMap(slideEl) {{
|
|
1458
|
+
const map = new Map();
|
|
1459
|
+
if (!slideEl) return map;
|
|
1460
|
+
const nodes = slideEl.querySelectorAll('[data-morph-id]');
|
|
1461
|
+
for (let i = 0; i < nodes.length; i++) {{
|
|
1462
|
+
const node = nodes[i];
|
|
1463
|
+
const id = (node.getAttribute('data-morph-id') || '').trim();
|
|
1464
|
+
if (!id || map.has(id)) continue;
|
|
1465
|
+
const cs = getComputedStyle(node);
|
|
1466
|
+
if (cs.display === 'none' || cs.visibility === 'hidden') continue;
|
|
1467
|
+
map.set(id, node);
|
|
1468
|
+
}}
|
|
1469
|
+
return map;
|
|
1470
|
+
}}
|
|
1471
|
+
|
|
1472
|
+
function isPureTextElement(el) {{
|
|
1473
|
+
const tag = (el.tagName || '').toUpperCase();
|
|
1474
|
+
if (!['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P', 'SPAN', 'LABEL', 'LI'].includes(tag)) return false;
|
|
1475
|
+
const cs = getComputedStyle(el);
|
|
1476
|
+
const bg = cs.backgroundColor || '';
|
|
1477
|
+
const hasBg = bg && bg !== 'transparent' && !/^rgba\\([^)]*,\\s*0(?:\\.0+)?\\s*\\)$/i.test(bg);
|
|
1478
|
+
const hasBgImg = cs.backgroundImage && cs.backgroundImage !== 'none';
|
|
1479
|
+
const hasBorder = (parseFloat(cs.borderTopWidth) || 0) > 0.5 || (parseFloat(cs.borderBottomWidth) || 0) > 0.5;
|
|
1480
|
+
return !hasBg && !hasBgImg && !hasBorder;
|
|
1481
|
+
}}
|
|
1482
|
+
|
|
1483
|
+
function buildEntranceKeyframes(el, kind) {{
|
|
1484
|
+
const cs = getComputedStyle(el);
|
|
1485
|
+
const baseTf = cs.transform && cs.transform !== 'none' ? cs.transform : '';
|
|
1486
|
+
const targetOp = parseFloat(cs.opacity || '1');
|
|
1487
|
+
const endTf = baseTf || 'translate3d(0, 0, 0)';
|
|
1488
|
+
const joinTf = (prefix) => (baseTf ? `${{prefix}} ${{baseTf}}` : prefix);
|
|
1489
|
+
if (kind === 'fade') {{
|
|
1490
|
+
return [{{ opacity: 0 }}, {{ opacity: targetOp }}];
|
|
1491
|
+
}}
|
|
1492
|
+
if (kind === 'float-left') {{
|
|
1493
|
+
return [
|
|
1494
|
+
{{ opacity: 0, transform: joinTf('translate3d(26px, 0, 0)') }},
|
|
1495
|
+
{{ opacity: targetOp, transform: endTf }},
|
|
1496
|
+
];
|
|
1497
|
+
}}
|
|
1498
|
+
if (kind === 'scale-in') {{
|
|
1499
|
+
return [
|
|
1500
|
+
{{ opacity: 0, transform: joinTf('scale(0.95)') }},
|
|
1501
|
+
{{ opacity: targetOp, transform: endTf }},
|
|
1502
|
+
];
|
|
1503
|
+
}}
|
|
1504
|
+
if (kind === 'wipe') {{
|
|
1505
|
+
return [
|
|
1506
|
+
{{ clipPath: 'inset(0 100% 0 0)', opacity: Math.min(targetOp, 0.2) }},
|
|
1507
|
+
{{ clipPath: 'inset(0 0 0 0)', opacity: targetOp }},
|
|
1508
|
+
];
|
|
1509
|
+
}}
|
|
1510
|
+
// Default: subtle refined float-up
|
|
1511
|
+
return [
|
|
1512
|
+
{{ opacity: 0, transform: joinTf('translate3d(0, 18px, 0)') }},
|
|
1513
|
+
{{ opacity: targetOp, transform: endTf }},
|
|
1514
|
+
];
|
|
1515
|
+
}}
|
|
1516
|
+
|
|
1517
|
+
function isFullBleedBackdrop(el) {{
|
|
1518
|
+
if (!el || el.nodeType !== 1) return false;
|
|
1519
|
+
const cls = typeof el.className === 'string' ? el.className : '';
|
|
1520
|
+
if (/(^|\\s)(s\\d+-bg|slide-bg|bg-layer|plate|backdrop)(\\s|$)/i.test(cls)) return true;
|
|
1521
|
+
const c = getStageCoords(el);
|
|
1522
|
+
return c.w >= 1840 && c.h >= 1000 && el.tagName.toUpperCase() === 'IMG';
|
|
1523
|
+
}}
|
|
1524
|
+
|
|
1525
|
+
function collectAutoEntranceTargets(slideEl, morphMatchedSet) {{
|
|
1526
|
+
let container = slideEl;
|
|
1527
|
+
const direct = Array.from(slideEl.children).filter((ch) => {{
|
|
1528
|
+
const tag = ch.tagName.toUpperCase();
|
|
1529
|
+
if (tag === 'HEADER' || ch.classList.contains('slide-header')) return false;
|
|
1530
|
+
if (tag === 'SCRIPT' || tag === 'STYLE') return false;
|
|
1531
|
+
if (isFullBleedBackdrop(ch)) return false;
|
|
1532
|
+
return true;
|
|
1533
|
+
}});
|
|
1534
|
+
// Unwrap single full-canvas wrapper (e.g. <div class="pg">)
|
|
1535
|
+
if (direct.length === 1 && direct[0].children.length >= 2) {{
|
|
1536
|
+
const c = getStageCoords(direct[0]);
|
|
1537
|
+
if (c.w >= 1400 && c.h >= 700 && !direct[0].hasAttribute('data-morph-id')) {{
|
|
1538
|
+
container = direct[0];
|
|
1539
|
+
}}
|
|
1540
|
+
}}
|
|
1541
|
+
const candidates = Array.from(container.children).filter((ch) => {{
|
|
1542
|
+
const tag = ch.tagName.toUpperCase();
|
|
1543
|
+
if (tag === 'HEADER' || ch.classList.contains('slide-header')) return false;
|
|
1544
|
+
if (tag === 'SCRIPT' || tag === 'STYLE') return false;
|
|
1545
|
+
if (ch.getAttribute('data-anim') === 'none') return false;
|
|
1546
|
+
if (isFullBleedBackdrop(ch)) return false;
|
|
1547
|
+
if (morphMatchedSet.has(ch)) return false;
|
|
1548
|
+
for (const m of morphMatchedSet) {{
|
|
1549
|
+
if (ch.contains(m) || m.contains(ch)) return false;
|
|
1550
|
+
}}
|
|
1551
|
+
const cs = getComputedStyle(ch);
|
|
1552
|
+
if (cs.display === 'none' || cs.visibility === 'hidden' || parseFloat(cs.opacity || '1') <= 0.01) return false;
|
|
1553
|
+
const r = getStageCoords(ch);
|
|
1554
|
+
return r.w > 4 && r.h > 4;
|
|
1555
|
+
}});
|
|
1556
|
+
if (!candidates.length) return [];
|
|
1557
|
+
const sorted = candidates
|
|
1558
|
+
.map((el) => ({{ el, y: getStageCoords(el).y }}))
|
|
1559
|
+
.sort((a, b) => a.y - b.y)
|
|
1560
|
+
.slice(0, 6);
|
|
1561
|
+
// Group into at most 3 calm reading tiers
|
|
1562
|
+
const minY = sorted[0].y;
|
|
1563
|
+
const maxY = sorted[sorted.length - 1].y;
|
|
1564
|
+
const span = Math.max(1, maxY - minY);
|
|
1565
|
+
return sorted.map((item) => {{
|
|
1566
|
+
const tier = span < 120 ? 1 : Math.min(3, Math.floor(((item.y - minY) / span) * 2.4) + 1);
|
|
1567
|
+
return {{ el: item.el, kind: 'float-up', order: tier, delay: null, dur: null }};
|
|
1568
|
+
}});
|
|
1569
|
+
}}
|
|
1570
|
+
|
|
1571
|
+
function setupClickSteps(slideEl, revealAll) {{
|
|
1572
|
+
clickGroups = [];
|
|
1573
|
+
clickStepIndex = 0;
|
|
1574
|
+
slides.forEach((s) => {{
|
|
1575
|
+
s.querySelectorAll('.is-step-hidden').forEach((n) => n.classList.remove('is-step-hidden'));
|
|
1576
|
+
}});
|
|
1577
|
+
if (!slideEl || revealAll || isMotionDisabled()) return;
|
|
1578
|
+
const rawClickEls = Array.from(slideEl.querySelectorAll('[data-anim-trigger="click"]')).filter(
|
|
1579
|
+
(el) => (el.getAttribute('data-anim') || 'float-up').toLowerCase() !== 'none'
|
|
1580
|
+
);
|
|
1581
|
+
if (!rawClickEls.length) return;
|
|
1582
|
+
const byOrder = new Map();
|
|
1583
|
+
rawClickEls.forEach((el, idx) => {{
|
|
1584
|
+
const ord = parseInt(el.getAttribute('data-anim-order') || '', 10);
|
|
1585
|
+
const key = Number.isFinite(ord) ? ord : idx + 1;
|
|
1586
|
+
if (!byOrder.has(key)) byOrder.set(key, []);
|
|
1587
|
+
byOrder.get(key).push(el);
|
|
1588
|
+
el.classList.add('is-step-hidden');
|
|
1589
|
+
}});
|
|
1590
|
+
const keys = Array.from(byOrder.keys()).sort((a, b) => a - b);
|
|
1591
|
+
clickGroups = keys.map((k) => byOrder.get(k));
|
|
1592
|
+
}}
|
|
1593
|
+
|
|
1594
|
+
function revealClickGroup(group) {{
|
|
1595
|
+
const cfg = MOTION_PRESETS[getMotionPreset()];
|
|
1596
|
+
group.forEach((el, idx) => {{
|
|
1597
|
+
el.classList.remove('is-step-hidden');
|
|
1598
|
+
if (typeof el.animate !== 'function' || isMotionDisabled()) return;
|
|
1599
|
+
const kind = (el.getAttribute('data-anim') || 'float-up').trim().toLowerCase();
|
|
1600
|
+
const durAttr = parseInt(el.getAttribute('data-anim-dur') || '', 10);
|
|
1601
|
+
const dur = Number.isFinite(durAttr) ? Math.max(120, Math.min(1400, durAttr)) : cfg.enter;
|
|
1602
|
+
const delay = idx * Math.round(cfg.stagger * 0.7);
|
|
1603
|
+
const anim = trackAnim(
|
|
1604
|
+
el.animate(buildEntranceKeyframes(el, kind), {{
|
|
1605
|
+
duration: dur,
|
|
1606
|
+
delay,
|
|
1607
|
+
easing: EASE_OUT_EXPO,
|
|
1608
|
+
fill: 'both',
|
|
1609
|
+
}})
|
|
1610
|
+
);
|
|
1611
|
+
if (anim) {{
|
|
1612
|
+
anim.onfinish = () => {{
|
|
1613
|
+
try {{ anim.cancel(); }} catch (_e) {{}}
|
|
1614
|
+
}};
|
|
1615
|
+
}}
|
|
1616
|
+
}});
|
|
1617
|
+
}}
|
|
1618
|
+
|
|
1619
|
+
function runSlideEntrances(slideEl, morphMatchedSet, baseDelayMs) {{
|
|
1620
|
+
if (!slideEl || isMotionDisabled() || typeof slideEl.animate !== 'function') return 0;
|
|
1621
|
+
const cfg = MOTION_PRESETS[getMotionPreset()];
|
|
1622
|
+
const explicitAll = Array.from(slideEl.querySelectorAll('[data-anim]'));
|
|
1623
|
+
let items = [];
|
|
1624
|
+
if (explicitAll.length > 0) {{
|
|
1625
|
+
explicitAll.forEach((el, idx) => {{
|
|
1626
|
+
const kind = (el.getAttribute('data-anim') || '').trim().toLowerCase();
|
|
1627
|
+
if (!kind || kind === 'none') return;
|
|
1628
|
+
if ((el.getAttribute('data-anim-trigger') || 'auto').trim().toLowerCase() === 'click') return;
|
|
1629
|
+
if (morphMatchedSet.has(el)) return;
|
|
1630
|
+
for (const m of morphMatchedSet) {{
|
|
1631
|
+
if (el.contains(m)) return;
|
|
1632
|
+
}}
|
|
1633
|
+
const ord = parseInt(el.getAttribute('data-anim-order') || '', 10);
|
|
1634
|
+
const delayAttr = parseInt(el.getAttribute('data-anim-delay') || '', 10);
|
|
1635
|
+
const durAttr = parseInt(el.getAttribute('data-anim-dur') || '', 10);
|
|
1636
|
+
items.push({{
|
|
1637
|
+
el,
|
|
1638
|
+
kind,
|
|
1639
|
+
order: Number.isFinite(ord) ? Math.max(1, ord) : Math.min(3, idx + 1),
|
|
1640
|
+
delay: Number.isFinite(delayAttr) ? Math.max(0, delayAttr) : null,
|
|
1641
|
+
dur: Number.isFinite(durAttr) ? Math.max(120, Math.min(1400, durAttr)) : null,
|
|
1642
|
+
}});
|
|
1643
|
+
}});
|
|
1644
|
+
}} else {{
|
|
1645
|
+
items = collectAutoEntranceTargets(slideEl, morphMatchedSet);
|
|
1646
|
+
}}
|
|
1647
|
+
if (!items.length) return 0;
|
|
1648
|
+
|
|
1649
|
+
let maxEnd = 0;
|
|
1650
|
+
items.forEach((item) => {{
|
|
1651
|
+
const delay = item.delay !== null ? baseDelayMs + item.delay : baseDelayMs + (item.order - 1) * cfg.stagger;
|
|
1652
|
+
const dur = item.dur !== null ? item.dur : cfg.enter;
|
|
1653
|
+
maxEnd = Math.max(maxEnd, delay + dur);
|
|
1654
|
+
const anim = trackAnim(
|
|
1655
|
+
item.el.animate(buildEntranceKeyframes(item.el, item.kind), {{
|
|
1656
|
+
duration: dur,
|
|
1657
|
+
delay,
|
|
1658
|
+
easing: EASE_OUT_EXPO,
|
|
1659
|
+
fill: 'both',
|
|
1660
|
+
}})
|
|
1661
|
+
);
|
|
1662
|
+
if (anim) {{
|
|
1663
|
+
anim.onfinish = () => {{
|
|
1664
|
+
try {{ anim.cancel(); }} catch (_e) {{}}
|
|
1665
|
+
}};
|
|
1666
|
+
}}
|
|
1667
|
+
}});
|
|
1668
|
+
return maxEnd;
|
|
1669
|
+
}}
|
|
1670
|
+
|
|
1671
|
+
function resolveTransition(fromSlide, toSlide) {{
|
|
1672
|
+
const preset = getMotionPreset();
|
|
1673
|
+
const cfg = MOTION_PRESETS[preset];
|
|
1674
|
+
if (!fromSlide || !toSlide || fromSlide === toSlide || isMotionDisabled()) {{
|
|
1675
|
+
return {{ type: 'none', dur: 0, pairs: [] }};
|
|
1676
|
+
}}
|
|
1677
|
+
const fromMap = collectMorphMap(fromSlide);
|
|
1678
|
+
const toMap = collectMorphMap(toSlide);
|
|
1679
|
+
const pairs = [];
|
|
1680
|
+
toMap.forEach((toEl, id) => {{
|
|
1681
|
+
if (fromMap.has(id)) {{
|
|
1682
|
+
pairs.push({{ id, fromEl: fromMap.get(id), toEl }});
|
|
1683
|
+
}}
|
|
1684
|
+
}});
|
|
1685
|
+
const rawType = (toSlide.getAttribute('data-transition') || 'auto').trim().toLowerCase();
|
|
1686
|
+
const rawDur = parseInt(toSlide.getAttribute('data-transition-dur') || '', 10);
|
|
1687
|
+
const customDur = Number.isFinite(rawDur) ? Math.max(150, Math.min(2000, rawDur)) : null;
|
|
1688
|
+
|
|
1689
|
+
if (rawType === 'none') return {{ type: 'none', dur: 0, pairs: [] }};
|
|
1690
|
+
if (rawType === 'morph' || (rawType === 'auto' && pairs.length > 0)) {{
|
|
1691
|
+
if (pairs.length > 0) {{
|
|
1692
|
+
return {{ type: 'morph', dur: customDur || cfg.morph, pairs }};
|
|
1693
|
+
}}
|
|
1694
|
+
return {{ type: 'fade', dur: customDur || cfg.fade, pairs: [] }};
|
|
1695
|
+
}}
|
|
1696
|
+
if (rawType === 'push') {{
|
|
1697
|
+
return {{ type: 'push', dur: customDur || cfg.push, pairs: [] }};
|
|
1698
|
+
}}
|
|
1699
|
+
return {{ type: 'fade', dur: customDur || cfg.fade, pairs: [] }};
|
|
1700
|
+
}}
|
|
1701
|
+
|
|
1702
|
+
function applySlideChrome(active, clamped) {{
|
|
1703
|
+
const bg = active.getAttribute('data-bg') || getComputedStyle(active).background || '';
|
|
1704
|
+
const pol = active.getAttribute('data-polarity') || 'light';
|
|
1705
|
+
if (bg) {{
|
|
1706
|
+
document.documentElement.style.background = bg;
|
|
1707
|
+
document.body.style.background = bg;
|
|
1708
|
+
}}
|
|
1709
|
+
document.body.setAttribute('data-polarity', pol);
|
|
1710
|
+
if (counterEl) counterEl.textContent = formatCounter(clamped);
|
|
1711
|
+
if (window.parent && window.parent !== window && clamped !== lastNotifiedSlideIndex) {{
|
|
1712
|
+
lastNotifiedSlideIndex = clamped;
|
|
1713
|
+
try {{
|
|
1714
|
+
window.parent.postMessage({{ type: 'oil-deck:slide', index: clamped, slide: clamped + 1, total }}, '*');
|
|
1715
|
+
}} catch (_e) {{}}
|
|
1716
|
+
}}
|
|
1717
|
+
}}
|
|
1718
|
+
|
|
1719
|
+
function goTo(index, opts) {{
|
|
1720
|
+
if (total === 0) return;
|
|
1721
|
+
const options = opts || {{}};
|
|
1722
|
+
const clamped = Math.max(0, Math.min(total - 1, index));
|
|
1723
|
+
const prevIndex = currentIndex;
|
|
1724
|
+
const fromSlide = slides[prevIndex];
|
|
1725
|
+
const toSlide = slides[clamped];
|
|
1726
|
+
const instant = Boolean(options.instant) || isMotionDisabled() || typeof toSlide.animate !== 'function';
|
|
1727
|
+
const direction = typeof options.direction === 'number'
|
|
1728
|
+
? (options.direction >= 0 ? 1 : -1)
|
|
1729
|
+
: (clamped >= prevIndex ? 1 : -1);
|
|
1730
|
+
|
|
1731
|
+
settleAll();
|
|
1732
|
+
currentIndex = clamped;
|
|
1733
|
+
|
|
1734
|
+
if (instant || !fromSlide || fromSlide === toSlide) {{
|
|
1735
|
+
slides.forEach((el, i) => {{
|
|
1736
|
+
el.classList.toggle('is-active', i === clamped);
|
|
1737
|
+
el.classList.remove('is-leaving', 'is-entering');
|
|
1738
|
+
}});
|
|
1739
|
+
applySlideChrome(toSlide, clamped);
|
|
1740
|
+
const revealSteps = typeof options.revealAll === 'boolean' ? options.revealAll : instant;
|
|
1741
|
+
setupClickSteps(toSlide, revealSteps);
|
|
1742
|
+
return;
|
|
1743
|
+
}}
|
|
1744
|
+
|
|
1745
|
+
// Keep both slides rendered briefly so geometry can be measured for FLIP Morph
|
|
1746
|
+
slides.forEach((el, i) => {{
|
|
1747
|
+
el.classList.toggle('is-active', i === clamped);
|
|
1748
|
+
el.classList.toggle('is-leaving', i === prevIndex);
|
|
1749
|
+
el.classList.toggle('is-entering', i === clamped);
|
|
1750
|
+
}});
|
|
1751
|
+
applySlideChrome(toSlide, clamped);
|
|
1752
|
+
setupClickSteps(toSlide, Boolean(options.revealAll));
|
|
1753
|
+
|
|
1754
|
+
const plan = resolveTransition(fromSlide, toSlide);
|
|
1755
|
+
const cfg = MOTION_PRESETS[getMotionPreset()];
|
|
1756
|
+
const morphMatchedSet = new Set(plan.pairs.map((p) => p.toEl));
|
|
1757
|
+
let totalMs = plan.dur;
|
|
1758
|
+
|
|
1759
|
+
if (plan.type === 'morph' && plan.pairs.length > 0) {{
|
|
1760
|
+
// 3-layer zero-clone Keynote Magic Move:
|
|
1761
|
+
// z0: toSlide background underlay | z1: fromSlide fading out (fromEls hidden) | z2: toSlide transparent bg with real toEls FLIP-gliding
|
|
1762
|
+
const underlay = document.createElement('div');
|
|
1763
|
+
underlay.className = 'deck-morph-underlay';
|
|
1764
|
+
underlay.style.background = toSlide.style.background || getComputedStyle(toSlide).background;
|
|
1765
|
+
stage.insertBefore(underlay, stage.firstChild);
|
|
1766
|
+
|
|
1767
|
+
const prevToBg = toSlide.style.background;
|
|
1768
|
+
toSlide.style.background = 'transparent';
|
|
1769
|
+
addCleanup(() => {{
|
|
1770
|
+
toSlide.style.background = prevToBg;
|
|
1771
|
+
underlay.remove();
|
|
1772
|
+
}});
|
|
1773
|
+
|
|
1774
|
+
plan.pairs.forEach((pair) => {{
|
|
1775
|
+
const rFrom = getStageCoords(pair.fromEl);
|
|
1776
|
+
const rTo = getStageCoords(pair.toEl);
|
|
1777
|
+
if (rFrom.w < 1 || rFrom.h < 1 || rTo.w < 1 || rTo.h < 1) return;
|
|
1778
|
+
|
|
1779
|
+
const csFrom = getComputedStyle(pair.fromEl);
|
|
1780
|
+
const csTo = getComputedStyle(pair.toEl);
|
|
1781
|
+
const dx = rFrom.cx - rTo.cx;
|
|
1782
|
+
const dy = rFrom.cy - rTo.cy;
|
|
1783
|
+
let sx = Math.max(0.12, Math.min(8, rFrom.w / rTo.w));
|
|
1784
|
+
let sy = Math.max(0.12, Math.min(8, rFrom.h / rTo.h));
|
|
1785
|
+
if (isPureTextElement(pair.toEl)) {{
|
|
1786
|
+
const u = Math.max(0.25, Math.min(4, rFrom.h / rTo.h));
|
|
1787
|
+
sx = u;
|
|
1788
|
+
sy = u;
|
|
1789
|
+
}}
|
|
1790
|
+
const baseTf = csTo.transform && csTo.transform !== 'none' ? csTo.transform : '';
|
|
1791
|
+
const fromOp = parseFloat(csFrom.opacity || '1');
|
|
1792
|
+
const toOp = parseFloat(csTo.opacity || '1');
|
|
1793
|
+
|
|
1794
|
+
const prevFromVis = pair.fromEl.style.visibility;
|
|
1795
|
+
pair.fromEl.style.visibility = 'hidden';
|
|
1796
|
+
const prevOrigin = pair.toEl.style.transformOrigin;
|
|
1797
|
+
pair.toEl.style.transformOrigin = 'center center';
|
|
1798
|
+
addCleanup(() => {{
|
|
1799
|
+
pair.fromEl.style.visibility = prevFromVis;
|
|
1800
|
+
pair.toEl.style.transformOrigin = prevOrigin;
|
|
1801
|
+
}});
|
|
1802
|
+
|
|
1803
|
+
const startFrame = {{
|
|
1804
|
+
transform: `translate3d(${{dx.toFixed(2)}}px, ${{dy.toFixed(2)}}px, 0) scale(${{sx.toFixed(4)}}, ${{sy.toFixed(4)}})${{baseTf ? ' ' + baseTf : ''}}`,
|
|
1805
|
+
opacity: fromOp,
|
|
1806
|
+
}};
|
|
1807
|
+
const endFrame = {{
|
|
1808
|
+
transform: baseTf || 'translate3d(0, 0, 0) scale(1, 1)',
|
|
1809
|
+
opacity: toOp,
|
|
1810
|
+
}};
|
|
1811
|
+
if (!isPureTextElement(pair.toEl) && csFrom.borderRadius !== csTo.borderRadius) {{
|
|
1812
|
+
startFrame.borderRadius = csFrom.borderRadius;
|
|
1813
|
+
endFrame.borderRadius = csTo.borderRadius;
|
|
1814
|
+
}}
|
|
1815
|
+
trackAnim(
|
|
1816
|
+
pair.toEl.animate([startFrame, endFrame], {{
|
|
1817
|
+
duration: plan.dur,
|
|
1818
|
+
easing: EASE_MORPH,
|
|
1819
|
+
fill: 'both',
|
|
1820
|
+
}})
|
|
1821
|
+
);
|
|
1822
|
+
}});
|
|
1823
|
+
|
|
1824
|
+
// Cross-fade outgoing slide background & non-morph items
|
|
1825
|
+
trackAnim(
|
|
1826
|
+
fromSlide.animate([{{ opacity: 1 }}, {{ opacity: 0 }}], {{
|
|
1827
|
+
duration: Math.round(plan.dur * 0.48),
|
|
1828
|
+
easing: 'ease-out',
|
|
1829
|
+
fill: 'both',
|
|
1830
|
+
}})
|
|
1831
|
+
);
|
|
1832
|
+
|
|
1833
|
+
// Fade in non-morph incoming children slightly after morph starts gliding
|
|
1834
|
+
const nonMorphDelay = Math.round(plan.dur * 0.30);
|
|
1835
|
+
const nonMorphDur = Math.round(plan.dur * 0.54);
|
|
1836
|
+
Array.from(toSlide.children).forEach((ch) => {{
|
|
1837
|
+
if (ch.classList.contains('slide-header') || ch.tagName.toUpperCase() === 'HEADER') return;
|
|
1838
|
+
if (ch.classList.contains('is-step-hidden')) return;
|
|
1839
|
+
if (morphMatchedSet.has(ch)) return;
|
|
1840
|
+
for (const m of morphMatchedSet) {{
|
|
1841
|
+
if (ch.contains(m)) return;
|
|
1842
|
+
}}
|
|
1843
|
+
trackAnim(
|
|
1844
|
+
ch.animate([{{ opacity: 0 }}, {{ opacity: 1 }}], {{
|
|
1845
|
+
duration: nonMorphDur,
|
|
1846
|
+
delay: nonMorphDelay,
|
|
1847
|
+
easing: EASE_OUT_EXPO,
|
|
1848
|
+
fill: 'both',
|
|
1849
|
+
}})
|
|
1850
|
+
);
|
|
1851
|
+
}});
|
|
1852
|
+
|
|
1853
|
+
const entEnd = runSlideEntrances(toSlide, morphMatchedSet, Math.round(plan.dur * 0.38));
|
|
1854
|
+
totalMs = Math.max(plan.dur, entEnd);
|
|
1855
|
+
}} else if (plan.type === 'push') {{
|
|
1856
|
+
const shift = getMotionPreset() === 'cinematic' ? 96 : 64;
|
|
1857
|
+
trackAnim(
|
|
1858
|
+
fromSlide.animate(
|
|
1859
|
+
[
|
|
1860
|
+
{{ opacity: 1, transform: 'translate3d(0, 0, 0)' }},
|
|
1861
|
+
{{ opacity: 0, transform: `translate3d(${{-direction * shift}}px, 0, 0)` }},
|
|
1862
|
+
],
|
|
1863
|
+
{{ duration: plan.dur, easing: EASE_OUT_EXPO, fill: 'both' }}
|
|
1864
|
+
)
|
|
1865
|
+
);
|
|
1866
|
+
trackAnim(
|
|
1867
|
+
toSlide.animate(
|
|
1868
|
+
[
|
|
1869
|
+
{{ opacity: 0, transform: `translate3d(${{direction * shift}}px, 0, 0)` }},
|
|
1870
|
+
{{ opacity: 1, transform: 'translate3d(0, 0, 0)' }},
|
|
1871
|
+
],
|
|
1872
|
+
{{ duration: plan.dur, easing: EASE_OUT_EXPO, fill: 'both' }}
|
|
1873
|
+
)
|
|
1874
|
+
);
|
|
1875
|
+
const entEnd = runSlideEntrances(toSlide, morphMatchedSet, Math.round(plan.dur * 0.25));
|
|
1876
|
+
totalMs = Math.max(plan.dur, entEnd);
|
|
1877
|
+
}} else if (plan.type === 'fade') {{
|
|
1878
|
+
trackAnim(
|
|
1879
|
+
fromSlide.animate([{{ opacity: 1 }}, {{ opacity: 0 }}], {{
|
|
1880
|
+
duration: Math.round(plan.dur * 0.85),
|
|
1881
|
+
easing: 'ease-out',
|
|
1882
|
+
fill: 'both',
|
|
1883
|
+
}})
|
|
1884
|
+
);
|
|
1885
|
+
trackAnim(
|
|
1886
|
+
toSlide.animate(
|
|
1887
|
+
[
|
|
1888
|
+
{{ opacity: 0, transform: `scale(${{cfg.slideScale}})` }},
|
|
1889
|
+
{{ opacity: 1, transform: 'scale(1)' }},
|
|
1890
|
+
],
|
|
1891
|
+
{{ duration: plan.dur, easing: EASE_OUT_EXPO, fill: 'both' }}
|
|
1892
|
+
)
|
|
1893
|
+
);
|
|
1894
|
+
const entEnd = runSlideEntrances(toSlide, morphMatchedSet, Math.round(plan.dur * 0.22));
|
|
1895
|
+
totalMs = Math.max(plan.dur, entEnd);
|
|
1896
|
+
}} else {{
|
|
1897
|
+
fromSlide.classList.remove('is-leaving');
|
|
1898
|
+
toSlide.classList.remove('is-entering');
|
|
1899
|
+
const entEnd = runSlideEntrances(toSlide, morphMatchedSet, 0);
|
|
1900
|
+
totalMs = entEnd;
|
|
1901
|
+
}}
|
|
1902
|
+
|
|
1903
|
+
settleTimer = setTimeout(() => {{
|
|
1904
|
+
settleAll();
|
|
1905
|
+
}}, Math.max(60, totalMs + 32));
|
|
1906
|
+
}}
|
|
1907
|
+
|
|
1908
|
+
function hasNextStep() {{
|
|
1909
|
+
return clickStepIndex < clickGroups.length;
|
|
1910
|
+
}}
|
|
1911
|
+
|
|
1912
|
+
function stepForward() {{
|
|
1913
|
+
if (!hasNextStep()) return false;
|
|
1914
|
+
const group = clickGroups[clickStepIndex++];
|
|
1915
|
+
revealClickGroup(group);
|
|
1916
|
+
return true;
|
|
1917
|
+
}}
|
|
1918
|
+
|
|
1919
|
+
function stepBackward() {{
|
|
1920
|
+
if (clickStepIndex <= 0) return false;
|
|
1921
|
+
clickStepIndex -= 1;
|
|
1922
|
+
const group = clickGroups[clickStepIndex];
|
|
1923
|
+
group.forEach((el) => el.classList.add('is-step-hidden'));
|
|
1924
|
+
return true;
|
|
1925
|
+
}}
|
|
1926
|
+
|
|
1927
|
+
function next() {{
|
|
1928
|
+
if (stepForward()) return;
|
|
1929
|
+
if (currentIndex < total - 1) goTo(currentIndex + 1, {{ direction: 1 }});
|
|
1930
|
+
}}
|
|
1931
|
+
|
|
1932
|
+
function prev() {{
|
|
1933
|
+
if (stepBackward()) return;
|
|
1934
|
+
if (currentIndex > 0) goTo(currentIndex - 1, {{ direction: -1, revealAll: true }});
|
|
1935
|
+
}}
|
|
1936
|
+
|
|
1937
|
+
function replay() {{
|
|
1938
|
+
const active = slides[currentIndex];
|
|
1939
|
+
if (!active || isMotionDisabled()) return;
|
|
1940
|
+
settleAll();
|
|
1941
|
+
setupClickSteps(active, false);
|
|
1942
|
+
const entEnd = runSlideEntrances(active, new Set(), 0);
|
|
1943
|
+
if (entEnd > 0) {{
|
|
1944
|
+
settleTimer = setTimeout(() => settleAll(), entEnd + 32);
|
|
1945
|
+
}}
|
|
1946
|
+
}}
|
|
1947
|
+
|
|
1948
|
+
function setMotionPreset(preset) {{
|
|
1949
|
+
const norm = String(preset || 'none').trim().toLowerCase();
|
|
1950
|
+
const nextPreset = Object.prototype.hasOwnProperty.call(MOTION_PRESETS, norm) ? norm : 'none';
|
|
1951
|
+
document.body.setAttribute('data-motion', nextPreset);
|
|
1952
|
+
if (nextPreset === 'none') {{
|
|
1953
|
+
settleAll();
|
|
1954
|
+
setupClickSteps(slides[currentIndex], true);
|
|
1955
|
+
}}
|
|
1956
|
+
return nextPreset;
|
|
1957
|
+
}}
|
|
1958
|
+
|
|
1959
|
+
function pokeControls() {{
|
|
1960
|
+
if (!controls) return;
|
|
1961
|
+
controls.classList.remove('is-idle');
|
|
1962
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
1963
|
+
idleTimer = setTimeout(() => controls.classList.add('is-idle'), 2400);
|
|
1964
|
+
}}
|
|
1965
|
+
|
|
1966
|
+
const params = new URLSearchParams(window.location.search);
|
|
1967
|
+
const slideParam = params.get('slide');
|
|
1968
|
+
if (slideParam !== null) {{
|
|
1969
|
+
document.body.classList.add('capture-mode');
|
|
1970
|
+
const parsed = parseInt(slideParam, 10);
|
|
1971
|
+
if (!Number.isNaN(parsed) && parsed >= 1 && parsed <= total) {{
|
|
1972
|
+
currentIndex = parsed - 1;
|
|
1973
|
+
}}
|
|
1974
|
+
}}
|
|
1975
|
+
|
|
1976
|
+
fitStage();
|
|
1977
|
+
goTo(currentIndex, {{ instant: true }});
|
|
1978
|
+
if (!isMotionDisabled() && slides[currentIndex]) {{
|
|
1979
|
+
setupClickSteps(slides[currentIndex], false);
|
|
1980
|
+
const initEnd = runSlideEntrances(slides[currentIndex], new Set(), 60);
|
|
1981
|
+
if (initEnd > 0) {{
|
|
1982
|
+
settleTimer = setTimeout(() => settleAll(), initEnd + 32);
|
|
1983
|
+
}}
|
|
1984
|
+
}}
|
|
1985
|
+
pokeControls();
|
|
1986
|
+
|
|
1987
|
+
window.addEventListener('resize', fitStage);
|
|
1988
|
+
window.addEventListener('mousemove', pokeControls, {{ passive: true }});
|
|
1989
|
+
window.addEventListener('beforeprint', () => {{
|
|
1990
|
+
settleAll();
|
|
1991
|
+
setupClickSteps(null, true);
|
|
1992
|
+
}});
|
|
1993
|
+
|
|
1994
|
+
let lastSwipeAt = 0;
|
|
1995
|
+
let touchStartX = 0;
|
|
1996
|
+
let touchStartY = 0;
|
|
1997
|
+
let touchTracking = false;
|
|
1998
|
+
|
|
1999
|
+
if (prevBtn) prevBtn.addEventListener('click', (e) => {{ e.stopPropagation(); prev(); }});
|
|
2000
|
+
if (nextBtn) nextBtn.addEventListener('click', (e) => {{ e.stopPropagation(); next(); }});
|
|
2001
|
+
if (tapPrev) tapPrev.addEventListener('click', (e) => {{
|
|
2002
|
+
e.stopPropagation();
|
|
2003
|
+
if (Date.now() - lastSwipeAt < 350) return;
|
|
2004
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2005
|
+
prev();
|
|
2006
|
+
}});
|
|
2007
|
+
if (tapNext) tapNext.addEventListener('click', (e) => {{
|
|
2008
|
+
e.stopPropagation();
|
|
2009
|
+
if (Date.now() - lastSwipeAt < 350) return;
|
|
2010
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2011
|
+
next();
|
|
2012
|
+
}});
|
|
2013
|
+
|
|
2014
|
+
document.addEventListener('touchstart', (e) => {{
|
|
2015
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2016
|
+
if (e.target && e.target.closest && e.target.closest('button, a, input, textarea, [contenteditable="true"], .deck-controls')) return;
|
|
2017
|
+
if (!e.touches || e.touches.length !== 1) {{
|
|
2018
|
+
touchTracking = false;
|
|
2019
|
+
return;
|
|
2020
|
+
}}
|
|
2021
|
+
touchStartX = e.touches[0].clientX;
|
|
2022
|
+
touchStartY = e.touches[0].clientY;
|
|
2023
|
+
touchTracking = true;
|
|
2024
|
+
}}, {{ passive: true }});
|
|
2025
|
+
document.addEventListener('touchend', (e) => {{
|
|
2026
|
+
if (!touchTracking) return;
|
|
2027
|
+
touchTracking = false;
|
|
2028
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2029
|
+
if (!e.changedTouches || e.changedTouches.length !== 1) return;
|
|
2030
|
+
const dx = e.changedTouches[0].clientX - touchStartX;
|
|
2031
|
+
const dy = e.changedTouches[0].clientY - touchStartY;
|
|
2032
|
+
if (Math.abs(dx) >= 48 && Math.abs(dx) > Math.abs(dy) * 1.2) {{
|
|
2033
|
+
lastSwipeAt = Date.now();
|
|
2034
|
+
if (dx < 0) next();
|
|
2035
|
+
else prev();
|
|
2036
|
+
}}
|
|
2037
|
+
}}, {{ passive: true }});
|
|
2038
|
+
|
|
2039
|
+
document.addEventListener('keydown', (e) => {{
|
|
2040
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2041
|
+
const tag = (e.target && e.target.tagName || '').toLowerCase();
|
|
2042
|
+
if (tag === 'input' || tag === 'textarea' || (e.target && e.target.isContentEditable)) return;
|
|
2043
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown' || e.key === 'PageDown' || e.key === ' ') {{
|
|
2044
|
+
e.preventDefault();
|
|
2045
|
+
next();
|
|
2046
|
+
}} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp' || e.key === 'PageUp') {{
|
|
2047
|
+
e.preventDefault();
|
|
2048
|
+
prev();
|
|
2049
|
+
}} else if (e.key === 'Home') {{
|
|
2050
|
+
e.preventDefault();
|
|
2051
|
+
goTo(0, {{ direction: -1 }});
|
|
2052
|
+
}} else if (e.key === 'End') {{
|
|
2053
|
+
e.preventDefault();
|
|
2054
|
+
goTo(total - 1, {{ direction: 1 }});
|
|
2055
|
+
}} else if (/^[1-9]$/.test(e.key)) {{
|
|
2056
|
+
const n = parseInt(e.key, 10) - 1;
|
|
2057
|
+
if (n < total) goTo(n);
|
|
2058
|
+
}}
|
|
2059
|
+
}});
|
|
2060
|
+
|
|
2061
|
+
document.addEventListener('click', (e) => {{
|
|
2062
|
+
if (Date.now() - lastSwipeAt < 350) return;
|
|
2063
|
+
if (document.body.classList.contains('capture-mode') || document.body.classList.contains('studio-embed')) return;
|
|
2064
|
+
if (e.target && e.target.closest && e.target.closest('button, a, input, textarea, [contenteditable="true"], .deck-controls, .deck-tapzones')) return;
|
|
2065
|
+
const ratio = e.clientX / Math.max(1, window.innerWidth);
|
|
2066
|
+
if (ratio < 0.25) prev();
|
|
2067
|
+
else next();
|
|
2068
|
+
}});
|
|
2069
|
+
|
|
2070
|
+
window.addEventListener('message', (e) => {{
|
|
2071
|
+
if (window.parent && window.parent !== window && e.source !== window.parent) return;
|
|
2072
|
+
const msg = e && e.data;
|
|
2073
|
+
if (!msg || typeof msg !== 'object') return;
|
|
2074
|
+
if (msg.type === 'oil-deck:go') {{
|
|
2075
|
+
let targetIdx = null;
|
|
2076
|
+
if (typeof msg.index === 'number' && Number.isFinite(msg.index)) {{
|
|
2077
|
+
targetIdx = Math.trunc(msg.index);
|
|
2078
|
+
}} else if (typeof msg.slide === 'number' && Number.isFinite(msg.slide)) {{
|
|
2079
|
+
targetIdx = Math.trunc(msg.slide) - 1;
|
|
2080
|
+
}}
|
|
2081
|
+
if (targetIdx !== null && total > 0) {{
|
|
2082
|
+
const clampedTarget = Math.max(0, Math.min(total - 1, targetIdx));
|
|
2083
|
+
if (clampedTarget === currentIndex) return;
|
|
2084
|
+
if (clampedTarget === targetIdx) {{
|
|
2085
|
+
lastNotifiedSlideIndex = clampedTarget;
|
|
2086
|
+
}}
|
|
2087
|
+
goTo(clampedTarget, {{ instant: Boolean(msg.instant) }});
|
|
2088
|
+
}}
|
|
2089
|
+
}} else if (msg.type === 'oil-deck:next') {{
|
|
2090
|
+
next();
|
|
2091
|
+
}} else if (msg.type === 'oil-deck:prev') {{
|
|
2092
|
+
prev();
|
|
2093
|
+
}}
|
|
2094
|
+
}});
|
|
2095
|
+
|
|
2096
|
+
window.deckApi = {{
|
|
2097
|
+
version: 2,
|
|
2098
|
+
goTo: (n, opts) => goTo((n || 1) - 1, opts),
|
|
2099
|
+
next,
|
|
2100
|
+
prev,
|
|
2101
|
+
stepForward,
|
|
2102
|
+
stepBackward,
|
|
2103
|
+
hasNextStep,
|
|
2104
|
+
replay,
|
|
2105
|
+
settle: settleAll,
|
|
2106
|
+
getMotionPreset,
|
|
2107
|
+
setMotionPreset,
|
|
2108
|
+
current: () => currentIndex + 1,
|
|
2109
|
+
count: () => total,
|
|
2110
|
+
}};
|
|
2111
|
+
}})();
|
|
2112
|
+
</script>
|
|
2113
|
+
</body>
|
|
2114
|
+
</html>
|
|
2115
|
+
"""
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
def compose_deck_file(
|
|
2119
|
+
slides: list[dict[str, Any]],
|
|
2120
|
+
out_path: Path,
|
|
2121
|
+
theme: dict[str, Any] | None = None,
|
|
2122
|
+
title: str | None = None,
|
|
2123
|
+
*,
|
|
2124
|
+
ratio: str | None = None,
|
|
2125
|
+
width: int | None = None,
|
|
2126
|
+
height: int | None = None,
|
|
2127
|
+
lang: str | None = None,
|
|
2128
|
+
) -> dict[str, Any]:
|
|
2129
|
+
"""Assemble and write web/index.html, returning a structured summary with lint warnings."""
|
|
2130
|
+
canvas_w, canvas_h, ratio_str = resolve_canvas_dimensions(
|
|
2131
|
+
ratio=ratio, width=width, height=height, theme=theme
|
|
2132
|
+
)
|
|
2133
|
+
resolved_lang = resolve_deck_lang(slides, title=title, theme=theme, lang=lang)
|
|
2134
|
+
html_text = assemble_deck_html(
|
|
2135
|
+
slides=slides, theme=theme, title=title, ratio=ratio, width=width, height=height, lang=resolved_lang
|
|
2136
|
+
)
|
|
2137
|
+
out_abs = out_path.resolve()
|
|
2138
|
+
out_abs.parent.mkdir(parents=True, exist_ok=True)
|
|
2139
|
+
out_abs.write_text(html_text, encoding="utf-8")
|
|
2140
|
+
return {
|
|
2141
|
+
"ok": True,
|
|
2142
|
+
"out": str(out_abs),
|
|
2143
|
+
"slide_count": len(slides),
|
|
2144
|
+
"lang": resolved_lang,
|
|
2145
|
+
"canvas": {"width": canvas_w, "height": canvas_h, "ratio": ratio_str},
|
|
2146
|
+
"bytes": out_abs.stat().st_size,
|
|
2147
|
+
"lines": len(html_text.splitlines()),
|
|
2148
|
+
"warnings": lint_deck_html(html_text),
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
|
|
2152
|
+
def _load_slides_from_dir(slides_dir: Path) -> list[dict[str, Any]]:
|
|
2153
|
+
candidates = [
|
|
2154
|
+
p
|
|
2155
|
+
for p in sorted(slides_dir.iterdir(), key=lambda x: x.name.lower())
|
|
2156
|
+
if p.is_file()
|
|
2157
|
+
and not p.name.startswith(".")
|
|
2158
|
+
and p.name.lower() != "index.html"
|
|
2159
|
+
and p.suffix.lower() in (".html", ".htm", ".json")
|
|
2160
|
+
]
|
|
2161
|
+
by_number: dict[int, tuple[float, int, dict[str, Any]]] = {}
|
|
2162
|
+
for idx, f in enumerate(candidates, start=1):
|
|
2163
|
+
m = re.search(r"(\d+)", f.stem)
|
|
2164
|
+
default_num = int(m.group(1)) if m else idx
|
|
2165
|
+
if f.suffix.lower() == ".json":
|
|
2166
|
+
obj = json.loads(f.read_text(encoding="utf-8"))
|
|
2167
|
+
if not isinstance(obj, dict):
|
|
2168
|
+
raise ValueError(f"{f} must contain a JSON object for one slide fragment.")
|
|
2169
|
+
if "slide_number" not in obj:
|
|
2170
|
+
obj["slide_number"] = default_num
|
|
2171
|
+
else:
|
|
2172
|
+
obj["slide_number"] = int(obj["slide_number"])
|
|
2173
|
+
else:
|
|
2174
|
+
obj = parse_slide_fragment_html(f.read_text(encoding="utf-8"), default_slide_number=default_num)
|
|
2175
|
+
s_num = int(obj["slide_number"])
|
|
2176
|
+
mtime = f.stat().st_mtime
|
|
2177
|
+
# If both s1.json and s1.html exist, keep the newest file (preferring .html on equal mtime)
|
|
2178
|
+
pref = 1 if f.suffix.lower() in (".html", ".htm") else 0
|
|
2179
|
+
prev = by_number.get(s_num)
|
|
2180
|
+
if prev is None or (mtime, pref) >= (prev[0], prev[1]):
|
|
2181
|
+
by_number[s_num] = (mtime, pref, obj)
|
|
2182
|
+
return [by_number[k][2] for k in sorted(by_number.keys())]
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
def assemble_from_slides_dir(
|
|
2186
|
+
slides_dir: Path,
|
|
2187
|
+
out_path: Path,
|
|
2188
|
+
*,
|
|
2189
|
+
theme_path: Path | None = None,
|
|
2190
|
+
title: str | None = None,
|
|
2191
|
+
ratio: str | None = None,
|
|
2192
|
+
width: int | None = None,
|
|
2193
|
+
height: int | None = None,
|
|
2194
|
+
lang: str | None = None,
|
|
2195
|
+
) -> dict[str, Any]:
|
|
2196
|
+
"""Load per-slide `.html`/`.json` files from `slides_dir` + optional `theme.json` and assemble `out_path`."""
|
|
2197
|
+
slides_dir_abs = Path(slides_dir).resolve()
|
|
2198
|
+
if not slides_dir_abs.is_dir():
|
|
2199
|
+
raise FileNotFoundError(f"Slides directory not found: {slides_dir}")
|
|
2200
|
+
slides = _load_slides_from_dir(slides_dir_abs)
|
|
2201
|
+
if not slides:
|
|
2202
|
+
raise ValueError(f"No slide fragments found in {slides_dir}")
|
|
2203
|
+
theme: dict[str, Any] = {}
|
|
2204
|
+
if theme_path is not None:
|
|
2205
|
+
tp = Path(theme_path)
|
|
2206
|
+
if tp.is_file():
|
|
2207
|
+
loaded = json.loads(tp.read_text(encoding="utf-8"))
|
|
2208
|
+
if isinstance(loaded, dict):
|
|
2209
|
+
theme = loaded
|
|
2210
|
+
return compose_deck_file(
|
|
2211
|
+
slides=slides,
|
|
2212
|
+
out_path=out_path,
|
|
2213
|
+
theme=theme,
|
|
2214
|
+
title=title,
|
|
2215
|
+
ratio=ratio,
|
|
2216
|
+
width=width,
|
|
2217
|
+
height=height,
|
|
2218
|
+
lang=lang,
|
|
2219
|
+
)
|
|
2220
|
+
|
|
2221
|
+
|
|
2222
|
+
def _configure_utf8_stdio() -> None:
|
|
2223
|
+
for stream in (sys.stdout, sys.stderr):
|
|
2224
|
+
if stream is not None:
|
|
2225
|
+
try:
|
|
2226
|
+
if not stream.isatty() and hasattr(stream, "reconfigure"):
|
|
2227
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
2228
|
+
except Exception:
|
|
2229
|
+
pass
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
def main() -> int:
|
|
2233
|
+
_configure_utf8_stdio()
|
|
2234
|
+
parser = argparse.ArgumentParser(
|
|
2235
|
+
description="Assemble a seamless HTML presentation (16:9, 3:4, 9:16, 1:1) from compact per-slide fragments."
|
|
2236
|
+
)
|
|
2237
|
+
parser.add_argument("--input", type=str, default=None, help="JSON file with {title?, ratio?, lang?, theme?, slides:[...]} (or '-' for stdin)")
|
|
2238
|
+
parser.add_argument("--slides-dir", type=Path, default=None, help="Directory of per-slide JSON fragments (s1.json..sN.json)")
|
|
2239
|
+
parser.add_argument("--theme", type=Path, default=None, help="Optional theme JSON file when using --slides-dir")
|
|
2240
|
+
parser.add_argument("--title", type=str, default=None, help="Optional HTML <title> override")
|
|
2241
|
+
parser.add_argument(
|
|
2242
|
+
"--lang",
|
|
2243
|
+
type=str,
|
|
2244
|
+
default="auto",
|
|
2245
|
+
help="HTML document lang attribute (default: auto -> 'zh-CN' if CJK text detected else 'en', or explicit e.g. 'en', 'zh-CN')",
|
|
2246
|
+
)
|
|
2247
|
+
parser.add_argument("--ratio", "--aspect-ratio", dest="ratio", type=str, default=None, help="Canvas aspect ratio: 16:9 (default), 3:4, 9:16, 1:1, or WxH")
|
|
2248
|
+
parser.add_argument("--width", type=int, default=None, help="Explicit canvas width override (px)")
|
|
2249
|
+
parser.add_argument("--height", type=int, default=None, help="Explicit canvas height override (px)")
|
|
2250
|
+
parser.add_argument("--out", type=Path, required=True, help="Output HTML path (e.g. web/index.html)")
|
|
2251
|
+
parser.add_argument("--json", action="store_true", help="Print JSON summary to stdout")
|
|
2252
|
+
args = parser.parse_args()
|
|
2253
|
+
|
|
2254
|
+
theme: dict[str, Any] = {}
|
|
2255
|
+
slides: list[dict[str, Any]] = []
|
|
2256
|
+
title: str | None = args.title
|
|
2257
|
+
payload_ratio: str | None = None
|
|
2258
|
+
payload_w: int | None = None
|
|
2259
|
+
payload_h: int | None = None
|
|
2260
|
+
payload_lang: str | None = None
|
|
2261
|
+
|
|
2262
|
+
if args.input:
|
|
2263
|
+
raw_text = sys.stdin.read() if args.input == "-" else Path(args.input).read_text(encoding="utf-8")
|
|
2264
|
+
payload = json.loads(raw_text)
|
|
2265
|
+
if isinstance(payload, list):
|
|
2266
|
+
slides = payload
|
|
2267
|
+
elif isinstance(payload, dict):
|
|
2268
|
+
slides = list(payload.get("slides") or [])
|
|
2269
|
+
theme = dict(payload.get("theme") or {})
|
|
2270
|
+
if not title and payload.get("title"):
|
|
2271
|
+
title = str(payload["title"])
|
|
2272
|
+
if payload.get("lang"):
|
|
2273
|
+
payload_lang = str(payload["lang"])
|
|
2274
|
+
if payload.get("ratio") or payload.get("aspect_ratio"):
|
|
2275
|
+
payload_ratio = str(payload.get("ratio") or payload.get("aspect_ratio"))
|
|
2276
|
+
canvas_field = payload.get("canvas")
|
|
2277
|
+
if isinstance(canvas_field, dict):
|
|
2278
|
+
if canvas_field.get("width") and canvas_field.get("height"):
|
|
2279
|
+
payload_w = int(canvas_field["width"])
|
|
2280
|
+
payload_h = int(canvas_field["height"])
|
|
2281
|
+
if not payload_ratio and canvas_field.get("ratio"):
|
|
2282
|
+
payload_ratio = str(canvas_field["ratio"])
|
|
2283
|
+
elif isinstance(canvas_field, str) and not payload_ratio:
|
|
2284
|
+
payload_ratio = canvas_field
|
|
2285
|
+
else:
|
|
2286
|
+
print("Error: --input JSON must be an object or array of slides.", file=sys.stderr)
|
|
2287
|
+
return 2
|
|
2288
|
+
elif args.slides_dir:
|
|
2289
|
+
if not args.slides_dir.is_dir():
|
|
2290
|
+
print(f"Error: slides directory not found: {args.slides_dir}", file=sys.stderr)
|
|
2291
|
+
return 2
|
|
2292
|
+
slides = _load_slides_from_dir(args.slides_dir)
|
|
2293
|
+
if args.theme and args.theme.is_file():
|
|
2294
|
+
theme = json.loads(args.theme.read_text(encoding="utf-8"))
|
|
2295
|
+
else:
|
|
2296
|
+
print("Error: provide either --input or --slides-dir.", file=sys.stderr)
|
|
2297
|
+
return 2
|
|
2298
|
+
|
|
2299
|
+
if not slides:
|
|
2300
|
+
print("Error: no slide fragments found.", file=sys.stderr)
|
|
2301
|
+
return 2
|
|
2302
|
+
|
|
2303
|
+
effective_lang = args.lang if (args.lang and args.lang.strip().lower() != "auto") else payload_lang
|
|
2304
|
+
res = compose_deck_file(
|
|
2305
|
+
slides=slides,
|
|
2306
|
+
out_path=args.out,
|
|
2307
|
+
theme=theme,
|
|
2308
|
+
title=title,
|
|
2309
|
+
ratio=args.ratio or payload_ratio,
|
|
2310
|
+
width=args.width if args.width is not None else payload_w,
|
|
2311
|
+
height=args.height if args.height is not None else payload_h,
|
|
2312
|
+
lang=effective_lang,
|
|
2313
|
+
)
|
|
2314
|
+
if args.json:
|
|
2315
|
+
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2316
|
+
else:
|
|
2317
|
+
print(f"deck_shell: ok={res['ok']} slides={res['slide_count']} out={res['out']} ({res['lines']} lines)")
|
|
2318
|
+
return 0
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
if __name__ == "__main__":
|
|
2322
|
+
raise SystemExit(main())
|