@clipen/clipen-cli 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
  4. package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
  5. package/apps/web/dist/favicon.svg +1 -0
  6. package/apps/web/dist/index.html +16 -0
  7. package/bin/clipen.js +157 -0
  8. package/clipen +18 -0
  9. package/install +25 -0
  10. package/package.json +55 -4
  11. package/pyproject.toml +44 -0
  12. package/requirements/asr-runtime.txt +13 -0
  13. package/requirements/dev.txt +2 -0
  14. package/requirements/runtime.txt +20 -0
  15. package/src/clipen/__init__.py +3 -0
  16. package/src/clipen/analysis/__init__.py +89 -0
  17. package/src/clipen/analysis/artifacts.py +410 -0
  18. package/src/clipen/analysis/audio.py +394 -0
  19. package/src/clipen/analysis/evidence.py +102 -0
  20. package/src/clipen/analysis/evidence_service.py +929 -0
  21. package/src/clipen/analysis/image_similarity.py +134 -0
  22. package/src/clipen/analysis/keyframes.py +159 -0
  23. package/src/clipen/analysis/models.py +228 -0
  24. package/src/clipen/analysis/qwen_worker.py +594 -0
  25. package/src/clipen/analysis/resources.py +22 -0
  26. package/src/clipen/analysis/runtime.py +62 -0
  27. package/src/clipen/analysis/service.py +594 -0
  28. package/src/clipen/analysis/setup.py +921 -0
  29. package/src/clipen/analysis/setup_cli.py +107 -0
  30. package/src/clipen/analysis/storage.py +1864 -0
  31. package/src/clipen/analysis/transcription.py +906 -0
  32. package/src/clipen/analysis/visual.py +237 -0
  33. package/src/clipen/annotations/__init__.py +13 -0
  34. package/src/clipen/annotations/models.py +22 -0
  35. package/src/clipen/annotations/storage.py +428 -0
  36. package/src/clipen/annotations/suggestions.py +115 -0
  37. package/src/clipen/asr_release.py +132 -0
  38. package/src/clipen/bootstrap.py +978 -0
  39. package/src/clipen/candidates.py +222 -0
  40. package/src/clipen/cli.py +84 -0
  41. package/src/clipen/controller/__init__.py +17 -0
  42. package/src/clipen/controller/app.py +1657 -0
  43. package/src/clipen/controller/server.py +533 -0
  44. package/src/clipen/domain/__init__.py +30 -0
  45. package/src/clipen/domain/errors.py +5 -0
  46. package/src/clipen/domain/media_time.py +110 -0
  47. package/src/clipen/domain/timeline.py +582 -0
  48. package/src/clipen/domain/validation.py +14 -0
  49. package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
  50. package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
  51. package/src/clipen/editing/README.md +115 -0
  52. package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
  53. package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
  54. package/src/clipen/editing/__init__.py +15 -0
  55. package/src/clipen/editing/agent.py +13 -0
  56. package/src/clipen/editing/agent_models.py +127 -0
  57. package/src/clipen/editing/agent_repository.py +978 -0
  58. package/src/clipen/editing/agent_tools.py +613 -0
  59. package/src/clipen/editing/alignment.py +150 -0
  60. package/src/clipen/editing/alignment_setup.py +156 -0
  61. package/src/clipen/editing/alignment_worker.py +24 -0
  62. package/src/clipen/editing/change_report.py +128 -0
  63. package/src/clipen/editing/compiler.py +40 -0
  64. package/src/clipen/editing/component_looks.py +131 -0
  65. package/src/clipen/editing/component_review.py +74 -0
  66. package/src/clipen/editing/coordinator.py +497 -0
  67. package/src/clipen/editing/editorial_review.py +309 -0
  68. package/src/clipen/editing/evidence_jobs.py +552 -0
  69. package/src/clipen/editing/history_changes.py +192 -0
  70. package/src/clipen/editing/music_choices.py +18 -0
  71. package/src/clipen/editing/production_catalog.py +629 -0
  72. package/src/clipen/editing/production_limits.py +85 -0
  73. package/src/clipen/editing/production_media.py +435 -0
  74. package/src/clipen/editing/production_preview.py +373 -0
  75. package/src/clipen/editing/production_progress.py +236 -0
  76. package/src/clipen/editing/production_requirements.py +117 -0
  77. package/src/clipen/editing/production_tools.py +1198 -0
  78. package/src/clipen/editing/program_audio.py +248 -0
  79. package/src/clipen/editing/program_direction.py +83 -0
  80. package/src/clipen/editing/program_story.py +91 -0
  81. package/src/clipen/editing/program_subtitles.py +232 -0
  82. package/src/clipen/editing/programme_review.py +121 -0
  83. package/src/clipen/editing/prompt_history.py +84 -0
  84. package/src/clipen/editing/recut.py +167 -0
  85. package/src/clipen/editing/refinement_references.py +278 -0
  86. package/src/clipen/editing/resolve_export.py +847 -0
  87. package/src/clipen/editing/resolve_titles.py +291 -0
  88. package/src/clipen/editing/skill_tools.py +951 -0
  89. package/src/clipen/editing/source_dialogue.py +192 -0
  90. package/src/clipen/editing/speech_coverage.py +50 -0
  91. package/src/clipen/editing/speech_quality.py +11 -0
  92. package/src/clipen/editing/tool_receipts.py +98 -0
  93. package/src/clipen/editing/versions.py +219 -0
  94. package/src/clipen/editing/visual_preview.py +189 -0
  95. package/src/clipen/editing/workbench.py +136 -0
  96. package/src/clipen/filesystem.py +25 -0
  97. package/src/clipen/finishing/README.md +103 -0
  98. package/src/clipen/finishing/__init__.py +1 -0
  99. package/src/clipen/finishing/audio.py +188 -0
  100. package/src/clipen/finishing/catalog.py +264 -0
  101. package/src/clipen/finishing/models.py +14 -0
  102. package/src/clipen/finishing/renderer.py +45 -0
  103. package/src/clipen/mcp_editing/__init__.py +5 -0
  104. package/src/clipen/mcp_editing/__main__.py +42 -0
  105. package/src/clipen/mcp_editing/server.py +396 -0
  106. package/src/clipen/media/__init__.py +50 -0
  107. package/src/clipen/media/discovery.py +253 -0
  108. package/src/clipen/media/models.py +349 -0
  109. package/src/clipen/media/preview.py +137 -0
  110. package/src/clipen/media/probe.py +418 -0
  111. package/src/clipen/media/service.py +304 -0
  112. package/src/clipen/media/storage.py +694 -0
  113. package/src/clipen/music_vocabulary.py +34 -0
  114. package/src/clipen/power.py +28 -0
  115. package/src/clipen/projects/__init__.py +26 -0
  116. package/src/clipen/projects/agent_schema.py +94 -0
  117. package/src/clipen/projects/annotation_schema.py +40 -0
  118. package/src/clipen/projects/deletion.py +256 -0
  119. package/src/clipen/projects/evidence_schema.py +52 -0
  120. package/src/clipen/projects/finishing_schema.py +36 -0
  121. package/src/clipen/projects/models.py +189 -0
  122. package/src/clipen/projects/picker.py +232 -0
  123. package/src/clipen/projects/preview_schema.py +29 -0
  124. package/src/clipen/projects/service.py +159 -0
  125. package/src/clipen/projects/storage.py +1458 -0
  126. package/src/clipen/projects/timeline_schema.py +32 -0
  127. package/src/clipen/projects/validation_schema.py +28 -0
  128. package/src/clipen/provider_registry.py +77 -0
  129. package/src/clipen/providers/__init__.py +43 -0
  130. package/src/clipen/providers/account.py +245 -0
  131. package/src/clipen/providers/claude.py +409 -0
  132. package/src/clipen/providers/claude_editing.py +118 -0
  133. package/src/clipen/providers/codex.py +991 -0
  134. package/src/clipen/providers/codex_editing.py +91 -0
  135. package/src/clipen/providers/editing_agent.py +567 -0
  136. package/src/clipen/providers/errors.py +51 -0
  137. package/src/clipen/providers/recovery.py +269 -0
  138. package/src/clipen/py.typed +1 -0
  139. package/src/clipen/rendering/__init__.py +12 -0
  140. package/src/clipen/rendering/cover.py +139 -0
  141. package/src/clipen/rendering/custom_components.py +328 -0
  142. package/src/clipen/rendering/custom_render.py +218 -0
  143. package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
  144. package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
  145. package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
  146. package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
  147. package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
  148. package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
  149. package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
  150. package/src/clipen/rendering/fonts/manifest.json +145 -0
  151. package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
  152. package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
  153. package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
  154. package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
  155. package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
  156. package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
  157. package/src/clipen/rendering/production_effects.py +96 -0
  158. package/src/clipen/rendering/program_components.py +254 -0
  159. package/src/clipen/rendering/program_creator.py +804 -0
  160. package/src/clipen/rendering/program_identities.py +350 -0
  161. package/src/clipen/rendering/program_motion.py +186 -0
  162. package/src/clipen/rendering/program_studio.py +227 -0
  163. package/src/clipen/rendering/program_styles.py +321 -0
  164. package/src/clipen/rendering/program_subtitles.py +89 -0
  165. package/src/clipen/rendering/renderer.py +737 -0
  166. package/src/clipen/rendering/storage.py +230 -0
  167. package/src/clipen/rendering/titles.py +467 -0
  168. package/src/clipen/skills/__init__.py +5 -0
  169. package/src/clipen/skills/builtin/SKILL.md +72 -0
  170. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  171. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  172. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  173. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  174. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  175. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  176. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  177. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  178. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  179. package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
  180. package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
  181. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  182. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  183. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  184. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  185. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  186. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  187. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  188. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  189. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  190. package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
  191. package/src/clipen/skills/builtin/components.json +133 -0
  192. package/src/clipen/skills/builtin/font_sources.json +20 -0
  193. package/src/clipen/skills/builtin/font_styles.json +329 -0
  194. package/src/clipen/skills/builtin/manifest.json +32 -0
  195. package/src/clipen/skills/builtin/presets.json +8 -0
  196. package/src/clipen/skills/builtin/references/captions.md +14 -0
  197. package/src/clipen/skills/builtin/references/channel-design.md +37 -0
  198. package/src/clipen/skills/builtin/references/editing.md +30 -0
  199. package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
  200. package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
  201. package/src/clipen/skills/builtin/references/graphics.md +59 -0
  202. package/src/clipen/skills/builtin/references/review.md +16 -0
  203. package/src/clipen/skills/builtin/references/sound.md +8 -0
  204. package/src/clipen/skills/builtin/references/story.md +7 -0
  205. package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
  206. package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
  207. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
  208. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
  209. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
  210. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
  211. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
  212. package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
  213. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
  214. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
  215. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
  216. package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
  217. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
  218. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
  219. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
  220. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
  221. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
  222. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
  223. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
  224. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
  225. package/src/clipen/skills/builtin/templates.json +284 -0
  226. package/src/clipen/skills/builtin/visual_styles.json +1074 -0
  227. package/src/clipen/skills/catalog.py +314 -0
  228. package/src/clipen/skills/library.py +137 -0
  229. package/src/clipen/skills/package.py +254 -0
  230. package/src/clipen/skills/visual_styles.py +55 -0
  231. package/src/clipen/workspace.py +181 -0
  232. package/uninstall +25 -0
@@ -0,0 +1,227 @@
1
+ """Original editorial identity: type lockups, cut-paper tickets and drawn marks.
2
+
3
+ All decoration and motion stays inside the measured component footprint. This is
4
+ procedural artwork, so no remote assets, invented source facts or raster scaling.
5
+ """
6
+
7
+ import math
8
+
9
+ from .program_styles import draw_style_text, load_style_font, styled_text_length, type_outline
10
+ from .titles import TitleRenderError
11
+
12
+ HERO = {"program_title", "headline", "impact", "chapter", "burst"}
13
+
14
+
15
+ def title_lines(value):
16
+ if "・" in value:
17
+ return tuple(value.split("・", 1))
18
+ if len(value) > 3:
19
+ middle = (len(value) + 1) // 2
20
+ return value[:middle], value[middle:]
21
+ return (value,)
22
+
23
+
24
+ def layout(draw, font_path, timeline, item, profile):
25
+ kind = profile["component_id"]
26
+ hero = kind in HERO
27
+ w, h = timeline.width, timeline.height
28
+ x, y = round(w * profile["x"]), round(h * profile["y"])
29
+ primary, _, detail = item.text.partition("\n")
30
+ split = kind == "program_title"
31
+ lines = title_lines(primary) if split else (primary,)
32
+ scale = 0.108 if split else 0.091 if hero else 0.061 if kind == "reaction" else 0.040
33
+ pad = max(8, round(h * 0.022))
34
+ limit = min(w * (0.83 if hero else 0.58), w * 0.945 - x)
35
+ minimum = max(14, round(h * scale * 0.70))
36
+ size = max(14, round(h * scale))
37
+ small = load_style_font(font_path, max(12, round(h * 0.024)), profile, role="detail")
38
+ # Reserve a separate column for a rosette; artwork never covers title type.
39
+ ornament = h * 0.13 if split else pad * 2
40
+ while True:
41
+ font = load_style_font(font_path, size, profile)
42
+ text_width = max(styled_text_length(line, font) for line in lines)
43
+ width = max(
44
+ text_width + pad * 4 + ornament,
45
+ styled_text_length(detail, small) + pad * 4 if detail else 0,
46
+ w * (0.39 if split else 0.19 if hero else 0.13),
47
+ )
48
+ if width <= limit or size <= minimum:
49
+ break
50
+ size -= 1
51
+ height = round(size * len(lines) * 1.18 + pad * 3 + (small.size * 1.35 if detail else 0))
52
+ if split:
53
+ height += round(pad * 0.5)
54
+ if width > limit or y + height > h * 0.77:
55
+ raise TitleRenderError("program_component_overflow")
56
+ return (x, y, x + math.ceil(width), y + height), font, pad
57
+
58
+
59
+ def draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
60
+ kind = profile["component_id"]
61
+ hero = kind in HERO
62
+ appearance = profile["presets"]["appearance"]
63
+ motion = profile["presets"]["motion"]
64
+ entry = appearance["hero_entry_frames"] if hero else motion["entry_frames"]
65
+ end = appearance["hero_exit_frames"] if hero else motion["exit_frames"]
66
+ relative = entry if relative_frame is None else relative_frame
67
+ p = min(1.0, max(0.0, (relative + 1) / entry))
68
+ exit_progress = min(1.0, max(0.0, (item.duration_frames - relative) / end))
69
+ alpha = min(1.0, p * 3, exit_progress)
70
+ ease = 1 - (1 - p) ** 3
71
+ x, y, right, bottom = bounds
72
+ width, height = right - x, bottom - y
73
+ primary, _, detail = item.text.partition("\n")
74
+ palette = profile["presets"]["palette"]
75
+ stroke = max(1, round(timeline.height * 0.0025))
76
+ small = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
77
+ micro = load_style_font(font_path, max(9, round(timeline.height * 0.017)), profile, role="detail")
78
+
79
+ def color(name, opacity=1):
80
+ r, g, b, a = palette[name]
81
+ return r, g, b, round(a * alpha * opacity)
82
+
83
+ def text(pos, value, selected=font, fill="paper", outline=False):
84
+ draw_style_text(
85
+ draw,
86
+ pos,
87
+ value,
88
+ selected,
89
+ color(fill),
90
+ type_outline(profile, selected, stroke * 3) if outline else 0,
91
+ color("ink"),
92
+ )
93
+ if selected is font and not profile["presets"].get("font_roles"):
94
+ draw_style_text(draw, pos, value, selected, color(fill), max(1, stroke), color(fill))
95
+
96
+ def rosette(cx, cy, radius, fill="accent"):
97
+ points = []
98
+ for n in range(32):
99
+ angle = math.tau * n / 32 - 0.18 * (1 - ease)
100
+ r = radius * (1 if n % 2 == 0 else 0.76) * (0.65 + 0.35 * ease)
101
+ points.append((cx + math.cos(angle) * r, cy + math.sin(angle) * r))
102
+ draw.polygon(points, fill=color(fill))
103
+ # Original four-point cutout inside the print rosette.
104
+ r = radius * 0.40
105
+ draw.polygon(
106
+ [
107
+ (cx, cy - r),
108
+ (cx + r * 0.22, cy - r * 0.22),
109
+ (cx + r, cy),
110
+ (cx + r * 0.22, cy + r * 0.22),
111
+ (cx, cy + r),
112
+ (cx - r * 0.22, cy + r * 0.22),
113
+ (cx - r, cy),
114
+ (cx - r * 0.22, cy - r * 0.22),
115
+ ],
116
+ fill=color("paper"),
117
+ )
118
+
119
+ if kind == "program_title":
120
+ # Open typographic lockup with staggered rows, a registration rail and
121
+ # a separate decorative seal. No enclosing title rectangle.
122
+ rail = x + pad * 0.25
123
+ draw.line((rail, y + pad, rail, y + height * ease - pad), fill=color("paper"), width=stroke)
124
+ for dy in (pad, height * 0.49, height - pad):
125
+ draw.line((rail - stroke * 2, y + dy, rail + stroke * 2, y + dy), fill=color("paper"), width=stroke)
126
+ badge_x = x + pad * 1.2
127
+ badge_w = micro.getlength("FIELD NOTES") + pad * 1.8
128
+ draw.rounded_rectangle(
129
+ (badge_x, y + pad * 0.2, badge_x + badge_w, y + pad * 1.35), radius=pad * 0.55, fill=color("accent")
130
+ )
131
+ text((badge_x + pad * 0.9, y + pad * 0.40), "FIELD NOTES", micro, "ink")
132
+ lines = title_lines(primary)
133
+ ty = y + pad * 1.9
134
+ for n, line in enumerate(lines):
135
+ phase = min(1.0, max(0.0, p * 1.65 - n * 0.35))
136
+ if not phase:
137
+ continue
138
+ shift = (1 - phase) ** 3 * pad
139
+ tx = x + pad * (1.2 + n * 0.7) + shift
140
+ yy = ty + n * font.size * 1.18
141
+ shadow = stroke if profile["presets"].get("font_roles") else stroke * 2
142
+ text((tx + shadow, yy + shadow), line, fill="ink", outline=True)
143
+ text((tx, yy), line, outline=True)
144
+ r = min(timeline.height * 0.055, height * 0.19)
145
+ rosette(right - r - pad * 0.6, y + pad * 2 + r, r)
146
+ underline_y = ty + font.size * len(lines) * 1.18 + pad * 0.12
147
+ length = max(styled_text_length(line, font) for line in lines)
148
+ draw.line(
149
+ [
150
+ (x + pad * 1.4, underline_y),
151
+ (x + pad + length * ease, underline_y - pad * 0.3),
152
+ (x + pad + length * ease, underline_y + stroke * 2),
153
+ ],
154
+ fill=color("accent"),
155
+ width=stroke * 3,
156
+ )
157
+ elif kind in {"impact", "reaction", "burst"}:
158
+ # A cut-paper sticker with offset ink edge and an asymmetrical silhouette.
159
+ top = y + pad * 0.7
160
+ points = [
161
+ (x + pad, top),
162
+ (right - pad * 2, y + pad * 0.2),
163
+ (right - pad * 0.3, top + pad),
164
+ (right - pad, bottom - pad * 0.65),
165
+ (x + pad * 0.5, bottom - pad * 0.3),
166
+ (x + pad * 0.15, top + pad),
167
+ ]
168
+ draw.polygon([(a + stroke * 2, b + stroke * 2) for a, b in points], fill=color("ink"))
169
+ draw.polygon(points, fill=color("accent"), outline=color("paper"), width=stroke * 2)
170
+ if kind == "burst":
171
+ rosette(right - pad * 1.25, y + pad * 1.25, pad * 0.8, "secondary")
172
+ if p > 0.18:
173
+ text((x + pad * 1.3, y + pad * 1.3 + (1 - ease) * pad * 0.5), primary, fill="ink")
174
+ for n in range(3):
175
+ xx = x + pad * (1.2 + n * 0.5)
176
+ draw.line((xx, y + pad * 0.5, xx + pad * 0.2, y + pad * 0.1), fill=color("paper"), width=stroke)
177
+ elif kind == "chapter":
178
+ # A coloured tab and open ruled heading, without a full panel.
179
+ tab_width = styled_text_length("CHAPTER", micro) + pad * 1.2
180
+ draw.rounded_rectangle(
181
+ (x + pad * 0.3, y + pad * 0.2, x + pad * 0.3 + tab_width, y + pad * 1.35),
182
+ radius=pad * 0.2,
183
+ fill=color("accent"),
184
+ )
185
+ text((x + pad * 0.6, y + pad * 0.35), "CHAPTER", micro, "ink")
186
+ text((x + pad, y + pad * 1.9 + (1 - ease) * pad), primary, outline=True)
187
+ draw.line(
188
+ (x + pad, bottom - pad * 0.5, x + pad + (width - pad * 2) * ease, bottom - pad * 0.5),
189
+ fill=color("paper"),
190
+ width=stroke * 2,
191
+ )
192
+ else:
193
+ # Ticket shape: clipped corners, perforation line, coloured folded tab.
194
+ notch = pad * 0.4
195
+ bx, by, br, bb = x + pad * 0.15, y + pad * 0.2, right - pad * 0.2, bottom - pad * 0.2
196
+ draw.polygon(
197
+ [
198
+ (bx + notch, by),
199
+ (br - notch, by),
200
+ (br, by + notch),
201
+ (br, bb - notch),
202
+ (br - notch, bb),
203
+ (bx + notch, bb),
204
+ (bx, bb - notch),
205
+ (bx, by + notch),
206
+ ],
207
+ fill=color("paper"),
208
+ )
209
+ draw.polygon([(bx, by), (bx + pad * 0.9, by), (bx, by + pad * 0.9)], fill=color("accent"))
210
+ for yy in range(round(by + pad * 0.5), round(bb - pad * 0.3), max(3, stroke * 4)):
211
+ draw.line((br - pad * 0.65, yy, br - pad * 0.65, yy + stroke), fill=color("secondary"), width=stroke)
212
+ text((bx + pad, y + pad * 0.85 + (1 - ease) * pad * 0.2), primary, fill="ink")
213
+ draw.line(
214
+ (bx + pad, bb - pad * 0.35, bx + pad + (width - pad * 3) * ease, bb - pad * 0.35),
215
+ fill=color("accent"),
216
+ width=stroke * 2,
217
+ )
218
+ if detail:
219
+ # Secondary line is reserved below the primary composition.
220
+ ty = bottom - small.size - pad * 0.7
221
+ if kind in {"program_title", "chapter"}:
222
+ tw = styled_text_length(detail, small)
223
+ draw.rectangle((x + pad, ty - pad * 0.25, x + pad * 2 + tw, bottom - pad * 0.35), fill=color("ink"))
224
+ text((x + pad * 1.5, ty), detail, small)
225
+ else:
226
+ text((x + pad * 1.3, ty), detail, small, "ink")
227
+ return bounds
@@ -0,0 +1,321 @@
1
+ """Distinct, trusted art directions for the same semantic programme components."""
2
+
3
+ import hashlib
4
+ import os
5
+ from functools import lru_cache
6
+ from importlib.resources import files
7
+ from pathlib import Path
8
+
9
+ from PIL import ImageFont
10
+
11
+
12
+ def skin(profile):
13
+ return profile.get("presets", {}).get("appearance", {}).get("skin", "variety")
14
+
15
+
16
+ def style_font(font_path, profile):
17
+ if os.environ.get("CLIPEN_TITLE_FONT") or profile["presets"].get("appearance", {}).get("font_family") != "serif":
18
+ return font_path
19
+ for path in (
20
+ "/System/Library/Fonts/Supplemental/Songti.ttc",
21
+ "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc",
22
+ "C:/Windows/Fonts/simsun.ttc",
23
+ ):
24
+ if Path(path).is_file():
25
+ return Path(path)
26
+ return font_path
27
+
28
+
29
+ @lru_cache(maxsize=32)
30
+ def _font_face(path, direction):
31
+ preferred = "Light" if direction == "cinema" else "Regular"
32
+ fallback = None
33
+ for index in range(16):
34
+ try:
35
+ family, weight = ImageFont.truetype(path, 12, index=index).getname()
36
+ except OSError:
37
+ break
38
+ if family in {"Songti TC", "Noto Serif CJK TC", "NotoSerifCJKtc"}:
39
+ if weight == preferred:
40
+ return index
41
+ if fallback is None:
42
+ fallback = index
43
+ return fallback or 0
44
+
45
+
46
+ def font_role(profile):
47
+ kind = profile.get("component_id")
48
+ return (
49
+ "impact"
50
+ if kind in {"impact", "burst", "reaction"}
51
+ else "title"
52
+ if kind in {"program_title", "headline", "chapter"}
53
+ else "information"
54
+ )
55
+
56
+
57
+ @lru_cache(maxsize=64)
58
+ def _role_face(path, weight):
59
+ preferred = {
60
+ "bold": ("Bold", "W6", "Semibold", "Heavy", "Black"),
61
+ "medium": ("Medium", "W6", "Regular"),
62
+ "light": ("Light", "W3", "Regular"),
63
+ "regular": ("Regular", "W3", "Medium"),
64
+ }[weight]
65
+ faces = []
66
+ for index in range(32):
67
+ try:
68
+ family, face = ImageFont.truetype(path, 12, index=index).getname()
69
+ except OSError:
70
+ break
71
+ # Prefer Traditional Chinese faces when a collection contains both.
72
+ if " SC" not in family and "Interface" not in family and family != "STSong":
73
+ faces.append((index, face, family.endswith(" TC")))
74
+ # Taiwan forms first when a collection also ships HK or other regional faces.
75
+ faces = [(index, face) for index, face, _ in sorted(faces, key=lambda entry: not entry[2])]
76
+ for desired in preferred:
77
+ for index, face in faces:
78
+ if face == desired:
79
+ return index
80
+ return faces[0][0] if faces else 0
81
+
82
+
83
+ @lru_cache(maxsize=16)
84
+ def _verify_font(path, expected, modified_ns, length):
85
+ from .titles import TitleRenderError
86
+
87
+ if hashlib.sha256(Path(path).read_bytes()).hexdigest() != expected:
88
+ raise TitleRenderError("program_font_unavailable")
89
+ return path
90
+
91
+
92
+ def bundled_font(specification):
93
+ from .titles import TitleRenderError
94
+
95
+ identifier = specification["bundled_font"]
96
+ if identifier not in {"chenyu", "iansui"}:
97
+ raise TitleRenderError("program_font_unavailable")
98
+ path = Path(str(files("clipen.rendering").joinpath("fonts", identifier + ".ttf")))
99
+ try:
100
+ stat = path.stat()
101
+ return _verify_font(str(path), specification["sha256"], stat.st_mtime_ns, stat.st_size)
102
+ except (OSError, KeyError) as error:
103
+ raise TitleRenderError("program_font_unavailable") from error
104
+
105
+
106
+ @lru_cache(maxsize=8)
107
+ def _system_asset(name):
108
+ """macOS installs some fonts on demand under a hashed asset folder."""
109
+ from glob import glob
110
+
111
+ return tuple(sorted(glob("/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/" + name)))[:1]
112
+
113
+
114
+ def type_outline(profile, font, fallback):
115
+ specification = profile["presets"].get("font_roles", {}).get(font_role(profile), {})
116
+ ratio = specification.get("outline_em")
117
+ return fallback if ratio is None else max(1, round(font.size * ratio))
118
+
119
+
120
+ def load_style_font(font_path, size, profile, role=None):
121
+ specification = profile["presets"].get("font_roles", {}).get(role or font_role(profile))
122
+ if specification:
123
+ if specification.get("bundled_font") and not os.environ.get("CLIPEN_TITLE_FONT"):
124
+ return ImageFont.truetype(bundled_font(specification), size)
125
+ family = specification["family"]
126
+ if family == "handwriting":
127
+ family = "sans"
128
+ candidates = {
129
+ "gothic": ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
130
+ "sans": ("/System/Library/Fonts/STHeiti Medium.ttc", "/System/Library/Fonts/Hiragino Sans GB.ttc"),
131
+ "serif": ("/System/Library/Fonts/Supplemental/Songti.ttc",),
132
+ # PingFang is the clean system sans creators expect on macOS; it is
133
+ # an on-demand system asset, so fall back to Hiragino Sans GB.
134
+ "modern": _system_asset("PingFang.ttc")
135
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
136
+ # Display faces popular in Taiwanese variety and vlog packaging.
137
+ "lantinghei": _system_asset("Lantinghei.ttc")
138
+ + _system_asset("PingFang.ttc")
139
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
140
+ "wawa": _system_asset("WawaTC-Regular.otf")
141
+ + _system_asset("PingFang.ttc")
142
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
143
+ "hannotate": _system_asset("Hannotate.ttc")
144
+ + _system_asset("PingFang.ttc")
145
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
146
+ "hanzipen": _system_asset("Hanzipen.ttc")
147
+ + _system_asset("PingFang.ttc")
148
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
149
+ "yuanti": _system_asset("Yuanti.ttc")
150
+ + _system_asset("PingFang.ttc")
151
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
152
+ "kaiti": _system_asset("Kaiti.ttc") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
153
+ "lingwai": _system_asset("LingWaiTC-Medium.otf") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
154
+ "weibei": _system_asset("WeibeiTC-Bold.otf")
155
+ + _system_asset("Lantinghei.ttc")
156
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
157
+ }[family]
158
+ candidates += (
159
+ "/usr/share/fonts/opentype/noto/Noto" + ("Serif" if family == "serif" else "Sans") + "CJK-Regular.ttc",
160
+ "C:/Windows/Fonts/" + ("simsun.ttc" if family == "serif" else "msjh.ttc"),
161
+ )
162
+ # The explicit local font override still has priority. No arbitrary font
163
+ # paths or remote URLs can be supplied through the editing MCP tools.
164
+ path = (
165
+ str(font_path)
166
+ if os.environ.get("CLIPEN_TITLE_FONT")
167
+ else next((p for p in candidates if Path(p).is_file()), str(font_path))
168
+ )
169
+ return ImageFont.truetype(path, size, index=_role_face(path, specification["weight"]))
170
+ path = str(style_font(font_path, profile))
171
+ face = (
172
+ _font_face(path, skin(profile)) if profile["presets"].get("appearance", {}).get("font_family") == "serif" else 0
173
+ )
174
+ return ImageFont.truetype(path, size, index=face)
175
+
176
+
177
+ @lru_cache(maxsize=2048)
178
+ def _has_glyph(path, size, index, character):
179
+ if character.isspace():
180
+ return True
181
+ font = ImageFont.truetype(path, size, index=index)
182
+ glyph = font.getmask(character)
183
+ missing = font.getmask("\U0010ffff")
184
+ return glyph.getbbox() is not None and (glyph.size != missing.size or bytes(glyph) != bytes(missing))
185
+
186
+
187
+ def _text_runs(value, font):
188
+ from .titles import TitleCardRenderer, TitleRenderError
189
+
190
+ fallback = None
191
+ runs = []
192
+ for char in value:
193
+ selected = font
194
+ if not _has_glyph(str(font.path), font.size, font.index, char):
195
+ if fallback is None:
196
+ path = TitleCardRenderer._font_path()
197
+ if path is None:
198
+ raise TitleRenderError("program_component_missing_glyph")
199
+ fallback = ImageFont.truetype(str(path), font.size)
200
+ if not _has_glyph(str(fallback.path), fallback.size, fallback.index, char):
201
+ raise TitleRenderError("program_component_missing_glyph")
202
+ selected = fallback
203
+ if runs and runs[-1][1] is selected:
204
+ runs[-1] = (runs[-1][0] + char, selected)
205
+ else:
206
+ runs.append((char, selected))
207
+ return runs
208
+
209
+
210
+ def styled_text_length(value, font):
211
+ return sum(selected.getlength(part) for part, selected in _text_runs(value, font))
212
+
213
+
214
+ def draw_style_text(draw, position, value, font, fill, stroke_width=0, stroke_fill=None):
215
+ if not value:
216
+ return
217
+ # Share a real baseline across font runs so a fallback middle dot stays in
218
+ # the middle of CJK type rather than jumping to the top of the line.
219
+ baseline = position[1] - font.getbbox(value, anchor="ls")[1]
220
+ x = position[0]
221
+ for part, selected in _text_runs(value, font):
222
+ draw.text(
223
+ (x, baseline),
224
+ part,
225
+ font=selected,
226
+ fill=fill,
227
+ anchor="ls",
228
+ stroke_width=stroke_width,
229
+ stroke_fill=stroke_fill,
230
+ )
231
+ x += selected.getlength(part)
232
+
233
+
234
+ def draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
235
+ if skin(profile) == "studio":
236
+ from .program_studio import draw_graphic
237
+
238
+ return draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
239
+ kind = profile["component_id"]
240
+ hero = kind in {"program_title", "headline", "impact", "chapter", "burst"}
241
+ appearance = profile["presets"].get("appearance", {})
242
+ motion = profile["presets"]["motion"]
243
+ entry = appearance.get("hero_entry_frames", 18) if hero else motion["entry_frames"]
244
+ exit_frames = appearance.get("hero_exit_frames", 8) if hero else motion["exit_frames"]
245
+ relative = entry if relative_frame is None else relative_frame
246
+ progress = min(1.0, max(0.0, (relative + 1) / entry))
247
+ ease = 1 - (1 - progress) ** 3
248
+ opacity = min(progress, min(1.0, max(0.0, (item.duration_frames - relative) / exit_frames)))
249
+ x, y, right, bottom = bounds
250
+ w = right - x
251
+ h = bottom - y
252
+ # The full entrance remains within the validated static footprint.
253
+ y += round((1 - ease) * pad * 0.35)
254
+ primary, _, detail = item.text.partition("\n")
255
+ font_path = style_font(font_path, profile)
256
+ small = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
257
+ line = max(1, round(timeline.height * 0.002))
258
+ palette = profile["presets"]["palette"]
259
+
260
+ def color(name, alpha=1.0):
261
+ r, g, b, a = palette[name]
262
+ return r, g, b, round(a * opacity * alpha)
263
+
264
+ def text(position, value, selected=font, fill="ink", shadow=False):
265
+ if shadow:
266
+ draw_style_text(
267
+ draw, (position[0] + line, position[1] + line), value, selected, color("ink"), line, color("ink")
268
+ )
269
+ draw_style_text(draw, position, value, selected, color(fill))
270
+
271
+ if skin(profile) == "editorial":
272
+ # Paper, ink and seal geometry: no slanted yellow panels or comic strokes.
273
+ draw.rounded_rectangle(
274
+ (x, y, right, bottom), radius=max(2, pad // 3), fill=color("paper"), outline=color("ink"), width=line
275
+ )
276
+ if kind == "burst":
277
+ cx, cy = (x + right) / 2, y + h * 0.43
278
+ radius = min(w * 0.45, h * 0.40)
279
+ draw.ellipse((cx - radius, cy - radius, cx + radius, cy + radius), outline=color("accent"), width=line * 2)
280
+ draw.ellipse(
281
+ (cx - radius + line * 4, cy - radius + line * 4, cx + radius - line * 4, cy + radius - line * 4),
282
+ outline=color("accent"),
283
+ width=line,
284
+ )
285
+ elif kind == "program_title":
286
+ draw.rectangle((x + pad, y + pad * 0.65, x + pad * 2, y + pad * 1.5), fill=color("accent"))
287
+ draw.line((x + pad * 2.5, y + pad * 1.1, x + w * ease - pad, y + pad * 1.1), fill=color("ink"), width=line)
288
+ elif kind in {"headline", "impact"}:
289
+ draw.line(
290
+ (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
291
+ fill=color("accent"),
292
+ width=line * 3,
293
+ )
294
+ else:
295
+ draw.rectangle((x, y, x + line * 3, bottom), fill=color("accent"))
296
+ ty = y + h * (0.31 if kind == "program_title" else 0.23 if hero else 0.22)
297
+ text((x + pad * 1.5, ty), primary, fill="accent" if kind in {"impact", "burst"} else "ink")
298
+ if detail:
299
+ text((x + pad * 1.5, bottom - pad * 1.9), detail, small)
300
+ else:
301
+ # Quiet lower-third grammar, hairline brackets and serif type. The small
302
+ # translucent backing preserves contrast on bright source footage.
303
+ draw.rectangle((x, y, right, bottom), fill=color("ink", 0.30))
304
+ length = min(pad * 2, w * 0.16) * ease
305
+ if kind == "chapter":
306
+ draw.line((x, y + pad * 0.5, x + pad * 0.8, bottom - pad * 0.5), fill=color("accent"), width=line * 2)
307
+ elif kind in {"program_title", "burst"}:
308
+ for cx, cy, sx, sy in ((x, y, 1, 1), (right, bottom, -1, -1)):
309
+ draw.line((cx, cy, cx + sx * length, cy), fill=color("accent"), width=line)
310
+ draw.line((cx, cy, cx, cy + sy * length), fill=color("accent"), width=line)
311
+ else:
312
+ draw.line(
313
+ (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
314
+ fill=color("accent"),
315
+ width=line,
316
+ )
317
+ ty = y + h * (0.30 if kind == "program_title" else 0.23 if hero else 0.22)
318
+ text((x + pad * 1.5, ty), primary, fill="paper", shadow=True)
319
+ if detail:
320
+ text((x + pad * 1.5, bottom - pad * 1.9), detail, small, fill="paper", shadow=True)
321
+ return bounds
@@ -0,0 +1,89 @@
1
+ """Outlined programme captions with in-sentence emphasis and bounded animation.
2
+
3
+ Rendered as native RGBA events, so the pipeline does not depend on libass being
4
+ installed in the user's FFmpeg build. No text box, chapter card or logo is drawn.
5
+ """
6
+
7
+ from PIL import ImageFont
8
+
9
+
10
+ def animation_boundaries(item):
11
+ return {
12
+ item.start_frame + n
13
+ for n in (0, 2, 4, 7, item.duration_frames - 2, item.duration_frames)
14
+ if 0 <= n <= item.duration_frames
15
+ }
16
+
17
+
18
+ def draw_program_subtitle(draw, font_path, timeline, item, profile, relative_frame=None):
19
+ relative = 7 if relative_frame is None or profile.get("motion") == "none" else relative_frame
20
+ scale = 0.88 if relative < 2 else 1.06 if relative < 4 else 0.98 if relative < 7 else 1.0
21
+ size = max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * scale))
22
+ index = 0
23
+ # Hiragino's W6 face is heavier than W3. Other families use their configured
24
+ # face and a small foreground stroke rather than assuming a TTC index.
25
+ try:
26
+ candidate = ImageFont.truetype(str(font_path), size, index=2)
27
+ if "W6" in candidate.getname()[1]:
28
+ index = 2
29
+ except OSError:
30
+ pass
31
+ font = ImageFont.truetype(str(font_path), size, index=index)
32
+ layout_font = ImageFont.truetype(
33
+ str(font_path), max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * 1.06)), index=index
34
+ )
35
+ text = item.text.replace("\n", " ")
36
+ maximum = timeline.width * 0.86
37
+ lines = []
38
+ line = ""
39
+ for character in text:
40
+ if line and draw.textlength(line + character, font=layout_font) > maximum:
41
+ lines.append(line)
42
+ line = ""
43
+ line += character
44
+ if line:
45
+ lines.append(line)
46
+ if len(lines) > 2:
47
+ from .titles import TitleRenderError
48
+
49
+ raise TitleRenderError("program_subtitle_overflow")
50
+ highlighted = set()
51
+ for word in profile.get("emphasis", []):
52
+ start = 0
53
+ while (start := text.find(word, start)) >= 0:
54
+ highlighted.update(range(start, start + len(word)))
55
+ start += len(word)
56
+ opacity = 255 if item.duration_frames - relative > 2 else 180
57
+ stroke = max(2, round(size * 0.095))
58
+ line_height = round(size * 1.35)
59
+ baseline = round(timeline.height * 0.90) - (len(lines) - 1) * line_height
60
+ offset = 0
61
+ for line in lines:
62
+ x = (timeline.width - draw.textlength(line, font=font)) / 2
63
+ for character in line:
64
+ color = (
65
+ tuple(profile.get("emphasis_color", [255, 217, 55, 255])[:3]) + (opacity,)
66
+ if offset in highlighted
67
+ else (255, 255, 255, opacity)
68
+ )
69
+ draw.text(
70
+ (x + 2, baseline + 3),
71
+ character,
72
+ font=font,
73
+ anchor="ls",
74
+ fill=(0, 0, 0, 110),
75
+ stroke_width=stroke + 1,
76
+ stroke_fill=(0, 0, 0, 110),
77
+ )
78
+ draw.text(
79
+ (x, baseline),
80
+ character,
81
+ font=font,
82
+ anchor="ls",
83
+ fill=color,
84
+ stroke_width=stroke,
85
+ stroke_fill=tuple(profile.get("outline_color", [10, 10, 14, 255])[:3]) + (opacity,),
86
+ )
87
+ x += draw.textlength(character, font=font)
88
+ offset += 1
89
+ baseline += line_height