kasaframe 0.0.0-stage → 0.1.3

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 (442) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +148 -0
  3. package/README.md +92 -2
  4. package/app/package.json +12 -0
  5. package/app/server/engine.ts +533 -0
  6. package/app/server/main.ts +209 -0
  7. package/app/web/env.d.ts +2 -0
  8. package/app/web/icons.ts +31 -0
  9. package/app/web/index.html +21 -0
  10. package/app/web/main.ts +1195 -0
  11. package/app/web/style.css +463 -0
  12. package/bin/hooks.mjs +64 -0
  13. package/bin/kf.mjs +32 -0
  14. package/docs/AGENTS.md +286 -0
  15. package/music/README.md +37 -0
  16. package/package.json +44 -4
  17. package/packages/adapters/package.json +36 -0
  18. package/packages/adapters/src/css.ts +11 -0
  19. package/packages/adapters/src/gsap.ts +26 -0
  20. package/packages/adapters/src/index.ts +9 -0
  21. package/packages/adapters/src/lottie.ts +22 -0
  22. package/packages/adapters/src/media.ts +59 -0
  23. package/packages/adapters/src/page.ts +229 -0
  24. package/packages/adapters/src/project.ts +214 -0
  25. package/packages/adapters/src/react.ts +36 -0
  26. package/packages/adapters/src/svelte.ts +22 -0
  27. package/packages/adapters/src/three.ts +18 -0
  28. package/packages/adapters/src/vue.ts +27 -0
  29. package/packages/check/package.json +19 -0
  30. package/packages/check/src/check.ts +280 -0
  31. package/packages/check/src/cli.ts +70 -0
  32. package/packages/check/src/image.ts +146 -0
  33. package/packages/check/src/index.ts +9 -0
  34. package/packages/check/src/ocr.swift +37 -0
  35. package/packages/check/src/probe.ts +328 -0
  36. package/packages/check/src/report.ts +44 -0
  37. package/packages/check/src/rules/assets.ts +45 -0
  38. package/packages/check/src/rules/beats.ts +212 -0
  39. package/packages/check/src/rules/camera.ts +217 -0
  40. package/packages/check/src/rules/captions.ts +49 -0
  41. package/packages/check/src/rules/flash.ts +235 -0
  42. package/packages/check/src/rules/frames.ts +136 -0
  43. package/packages/check/src/rules/layout.ts +281 -0
  44. package/packages/check/src/rules/page.ts +87 -0
  45. package/packages/check/src/rules/runs.ts +20 -0
  46. package/packages/check/src/rules/text.ts +326 -0
  47. package/packages/check/src/scan.ts +240 -0
  48. package/packages/check/src/serve.ts +67 -0
  49. package/packages/check/src/types.ts +80 -0
  50. package/packages/check/src/video.ts +137 -0
  51. package/packages/cli/package.json +30 -0
  52. package/packages/cli/src/blur.ts +80 -0
  53. package/packages/cli/src/browser.ts +203 -0
  54. package/packages/cli/src/command.ts +44 -0
  55. package/packages/cli/src/commands/app.ts +25 -0
  56. package/packages/cli/src/commands/beats.ts +36 -0
  57. package/packages/cli/src/commands/bench.ts +123 -0
  58. package/packages/cli/src/commands/blender.ts +293 -0
  59. package/packages/cli/src/commands/check.ts +25 -0
  60. package/packages/cli/src/commands/direct.ts +210 -0
  61. package/packages/cli/src/commands/doctor.ts +30 -0
  62. package/packages/cli/src/commands/gen.ts +173 -0
  63. package/packages/cli/src/commands/look.ts +46 -0
  64. package/packages/cli/src/commands/lyrics.ts +157 -0
  65. package/packages/cli/src/commands/make.ts +1121 -0
  66. package/packages/cli/src/commands/music.ts +78 -0
  67. package/packages/cli/src/commands/narrate.ts +238 -0
  68. package/packages/cli/src/commands/new.ts +185 -0
  69. package/packages/cli/src/commands/preview.ts +43 -0
  70. package/packages/cli/src/commands/render.ts +250 -0
  71. package/packages/cli/src/commands/series.ts +110 -0
  72. package/packages/cli/src/commands/setup.ts +102 -0
  73. package/packages/cli/src/commands/sheet.ts +114 -0
  74. package/packages/cli/src/commands/skill.ts +43 -0
  75. package/packages/cli/src/commands/still.ts +40 -0
  76. package/packages/cli/src/commands/theme.ts +172 -0
  77. package/packages/cli/src/commands/transitions.ts +40 -0
  78. package/packages/cli/src/deps.ts +122 -0
  79. package/packages/cli/src/ffmpeg.ts +81 -0
  80. package/packages/cli/src/index.ts +8 -0
  81. package/packages/cli/src/kf.ts +64 -0
  82. package/packages/cli/src/lock.ts +72 -0
  83. package/packages/cli/src/mix.ts +131 -0
  84. package/packages/cli/src/out.ts +13 -0
  85. package/packages/cli/src/pool.ts +34 -0
  86. package/packages/cli/src/segments.ts +402 -0
  87. package/packages/cli/src/serve.ts +124 -0
  88. package/packages/clock/package.json +14 -0
  89. package/packages/clock/src/index.ts +25 -0
  90. package/packages/clock/src/install.ts +351 -0
  91. package/packages/clock/src/types.ts +45 -0
  92. package/packages/core/package.json +9 -0
  93. package/packages/core/src/beats.ts +283 -0
  94. package/packages/core/src/ease.ts +87 -0
  95. package/packages/core/src/frame.ts +99 -0
  96. package/packages/core/src/index.ts +27 -0
  97. package/packages/core/src/project.ts +157 -0
  98. package/packages/core/src/rand.ts +56 -0
  99. package/packages/core/src/spring.ts +52 -0
  100. package/packages/core/src/style.ts +100 -0
  101. package/packages/core/src/time.ts +88 -0
  102. package/packages/director/package.json +23 -0
  103. package/packages/director/src/assemble.ts +361 -0
  104. package/packages/director/src/brief.ts +122 -0
  105. package/packages/director/src/catalog.ts +49 -0
  106. package/packages/director/src/content.ts +343 -0
  107. package/packages/director/src/fallback.ts +58 -0
  108. package/packages/director/src/index.ts +13 -0
  109. package/packages/director/src/pattern.ts +90 -0
  110. package/packages/director/src/patterns/fill/cells.ts +115 -0
  111. package/packages/director/src/patterns/formula/stack.ts +93 -0
  112. package/packages/director/src/patterns/util.ts +58 -0
  113. package/packages/director/src/scene.ts +62 -0
  114. package/packages/director/src/select.ts +163 -0
  115. package/packages/director/src/transitions.ts +115 -0
  116. package/packages/gen/PROVIDERS.md +90 -0
  117. package/packages/gen/package.json +9 -0
  118. package/packages/gen/src/ask.ts +132 -0
  119. package/packages/gen/src/audio.ts +91 -0
  120. package/packages/gen/src/blender.ts +54 -0
  121. package/packages/gen/src/capabilities.ts +151 -0
  122. package/packages/gen/src/generate.ts +206 -0
  123. package/packages/gen/src/image/codex.ts +117 -0
  124. package/packages/gen/src/image/og.ts +133 -0
  125. package/packages/gen/src/index.ts +26 -0
  126. package/packages/gen/src/keys.ts +86 -0
  127. package/packages/gen/src/media.ts +150 -0
  128. package/packages/gen/src/music/elevenlabs.ts +41 -0
  129. package/packages/gen/src/music/index.ts +120 -0
  130. package/packages/gen/src/music/library.ts +73 -0
  131. package/packages/gen/src/music/lyria.ts +52 -0
  132. package/packages/gen/src/music/types.ts +28 -0
  133. package/packages/gen/src/plan.ts +106 -0
  134. package/packages/gen/src/registry.ts +54 -0
  135. package/packages/gen/src/seam.ts +103 -0
  136. package/packages/gen/src/tts/dashscope.ts +64 -0
  137. package/packages/gen/src/tts/elevenlabs.ts +84 -0
  138. package/packages/gen/src/tts/gemini.ts +73 -0
  139. package/packages/gen/src/tts/index.ts +241 -0
  140. package/packages/gen/src/tts/local.ts +42 -0
  141. package/packages/gen/src/tts/types.ts +44 -0
  142. package/packages/gen/src/types.ts +90 -0
  143. package/packages/gen/src/video/fal.ts +140 -0
  144. package/packages/gen/src/video/h3.ts +112 -0
  145. package/packages/gen/src/video/http.ts +44 -0
  146. package/packages/gen/src/video/ltx.ts +60 -0
  147. package/packages/gen/src/video/minimax.ts +55 -0
  148. package/packages/gen/src/video/veo.ts +71 -0
  149. package/packages/jizura/package.json +16 -0
  150. package/packages/jizura/src/deny.ts +73 -0
  151. package/packages/jizura/src/index.ts +7 -0
  152. package/packages/jizura/src/install.ts +269 -0
  153. package/packages/jizura/src/layer.ts +325 -0
  154. package/packages/jizura/src/lyrics.ts +81 -0
  155. package/packages/jizura/src/pin.ts +8 -0
  156. package/packages/jizura/src/vendor.ts +140 -0
  157. package/packages/jizura/src/vite.ts +63 -0
  158. package/packages/jizura/vendor/JIZURA_LICENSE.txt +21 -0
  159. package/packages/jizura/vendor/NOTICE +43 -0
  160. package/packages/jizura/vendor/engine.json +47 -0
  161. package/packages/jizura/vendor/fonts/BlackHanSans-Regular.woff2 +0 -0
  162. package/packages/jizura/vendor/fonts/DotGothic16-Regular.woff2 +0 -0
  163. package/packages/jizura/vendor/fonts/GowunBatang-Bold.woff2 +0 -0
  164. package/packages/jizura/vendor/fonts/IBMPlexMono-Medium.ttf +0 -0
  165. package/packages/jizura/vendor/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  166. package/packages/jizura/vendor/fonts/NotoSansKR-VF.woff2 +0 -0
  167. package/packages/jizura/vendor/fonts/NotoSerifKR-VF.woff2 +0 -0
  168. package/packages/jizura/vendor/fonts/OFL-blackhansans.txt +93 -0
  169. package/packages/jizura/vendor/fonts/OFL-dotgothic16.txt +93 -0
  170. package/packages/jizura/vendor/fonts/OFL-gowunbatang.txt +94 -0
  171. package/packages/jizura/vendor/fonts/OFL-ibmplexmono.txt +93 -0
  172. package/packages/jizura/vendor/fonts/OFL-notosanskr.txt +93 -0
  173. package/packages/jizura/vendor/fonts/OFL-notoserifkr.txt +94 -0
  174. package/packages/jizura/vendor/fonts/fonts.json +52 -0
  175. package/packages/jizura/vendor/jizura_engine.js +35024 -0
  176. package/packages/motion/README.md +153 -0
  177. package/packages/motion/package.json +30 -0
  178. package/packages/motion/src/camera.ts +97 -0
  179. package/packages/motion/src/captions.ts +487 -0
  180. package/packages/motion/src/enter.ts +128 -0
  181. package/packages/motion/src/hangul.ts +129 -0
  182. package/packages/motion/src/impact.ts +100 -0
  183. package/packages/motion/src/index.ts +17 -0
  184. package/packages/motion/src/moves/brushWipe.ts +103 -0
  185. package/packages/motion/src/moves/cloneArray.ts +111 -0
  186. package/packages/motion/src/moves/curtains.ts +81 -0
  187. package/packages/motion/src/moves/dress.ts +191 -0
  188. package/packages/motion/src/moves/echoStack.ts +70 -0
  189. package/packages/motion/src/moves/fit.ts +70 -0
  190. package/packages/motion/src/moves/flood.ts +61 -0
  191. package/packages/motion/src/moves/ghostStack.ts +88 -0
  192. package/packages/motion/src/moves/gridFloor.ts +100 -0
  193. package/packages/motion/src/moves/imageSwarm.ts +113 -0
  194. package/packages/motion/src/moves/index.ts +38 -0
  195. package/packages/motion/src/moves/irisBlades.ts +113 -0
  196. package/packages/motion/src/moves/karaokeLine.ts +108 -0
  197. package/packages/motion/src/moves/ledBoard.ts +94 -0
  198. package/packages/motion/src/moves/liquidTab.ts +72 -0
  199. package/packages/motion/src/moves/markerWrite.ts +63 -0
  200. package/packages/motion/src/moves/menu.ts +138 -0
  201. package/packages/motion/src/moves/morphBox.ts +96 -0
  202. package/packages/motion/src/moves/neonSign.ts +78 -0
  203. package/packages/motion/src/moves/panelPop.ts +78 -0
  204. package/packages/motion/src/moves/paperTear.ts +75 -0
  205. package/packages/motion/src/moves/path.ts +64 -0
  206. package/packages/motion/src/moves/pathText.ts +107 -0
  207. package/packages/motion/src/moves/pointSphere.ts +109 -0
  208. package/packages/motion/src/moves/ransomLetters.ts +73 -0
  209. package/packages/motion/src/moves/shapeMorph.ts +143 -0
  210. package/packages/motion/src/moves/slamWords.ts +96 -0
  211. package/packages/motion/src/moves/sparkTrail.ts +130 -0
  212. package/packages/motion/src/moves/speedLines.ts +91 -0
  213. package/packages/motion/src/moves/splitFlap.ts +149 -0
  214. package/packages/motion/src/moves/stepWords.ts +128 -0
  215. package/packages/motion/src/moves/strikeOut.ts +98 -0
  216. package/packages/motion/src/moves/sunburst.ts +58 -0
  217. package/packages/motion/src/moves/tickerRows.ts +91 -0
  218. package/packages/motion/src/moves/tokenPicker.ts +115 -0
  219. package/packages/motion/src/moves/truchet.ts +85 -0
  220. package/packages/motion/src/moves/wordWall.ts +78 -0
  221. package/packages/motion/src/moves/worldRoll.ts +32 -0
  222. package/packages/motion/src/particles.ts +102 -0
  223. package/packages/motion/src/react/index.tsx +21 -0
  224. package/packages/motion/src/react/parts.tsx +431 -0
  225. package/packages/motion/src/react/time.tsx +97 -0
  226. package/packages/motion/src/text.ts +103 -0
  227. package/packages/motion/src/transition.ts +82 -0
  228. package/packages/motion/src/transition3d/cards.ts +65 -0
  229. package/packages/motion/src/transition3d/chain.ts +84 -0
  230. package/packages/motion/src/transition3d/dive.ts +181 -0
  231. package/packages/motion/src/transition3d/fold.ts +110 -0
  232. package/packages/motion/src/transition3d/gl.ts +219 -0
  233. package/packages/motion/src/transition3d/index.ts +235 -0
  234. package/packages/motion/src/transition3d/live.ts +70 -0
  235. package/packages/motion/src/transition3d/portal.ts +115 -0
  236. package/packages/motion/src/transition3d/react.tsx +29 -0
  237. package/packages/motion/src/transition3d/rig.ts +600 -0
  238. package/packages/motion/src/transition3d/shatter.ts +104 -0
  239. package/packages/motion/src/transition3d/space.ts +173 -0
  240. package/packages/motion/src/transition3d/whip.ts +78 -0
  241. package/packages/motion/src/transition3d/world.ts +737 -0
  242. package/packages/motion/src/transition3d/zoomOut.ts +114 -0
  243. package/packages/motion/src/transitions2d/catalog.ts +127 -0
  244. package/packages/motion/src/transitions2d/css.d.ts +2 -0
  245. package/packages/motion/src/transitions2d/cult-ui/LICENSE.md +9 -0
  246. package/packages/motion/src/transitions2d/cult-ui/RollingNumber.tsx +43 -0
  247. package/packages/motion/src/transitions2d/gl-transitions/LICENSE +25 -0
  248. package/packages/motion/src/transitions2d/gl-transitions/shaders.ts +1931 -0
  249. package/packages/motion/src/transitions2d/index.ts +2 -0
  250. package/packages/motion/src/transitions2d/kokonutui/LICENSE +21 -0
  251. package/packages/motion/src/transitions2d/kokonutui/MatrixText.css +16 -0
  252. package/packages/motion/src/transitions2d/kokonutui/MatrixText.tsx +94 -0
  253. package/packages/motion/src/transitions2d/magicui/HyperText.css +15 -0
  254. package/packages/motion/src/transitions2d/magicui/HyperText.tsx +115 -0
  255. package/packages/motion/src/transitions2d/magicui/LICENSE.md +21 -0
  256. package/packages/motion/src/transitions2d/magicui/MorphingText.css +25 -0
  257. package/packages/motion/src/transitions2d/magicui/MorphingText.tsx +130 -0
  258. package/packages/motion/src/transitions2d/magicui/WordRotate.tsx +42 -0
  259. package/packages/motion/src/transitions2d/react.ts +13 -0
  260. package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.css +39 -0
  261. package/packages/motion/src/transitions2d/skiper-ui/ClipDiv.tsx +32 -0
  262. package/packages/motion/src/transitions2d/smoothui/LICENSE +21 -0
  263. package/packages/motion/src/transitions2d/smoothui/SharedAxisY.tsx +50 -0
  264. package/packages/motion/src/transitions2d/smoothui/TextMorph.tsx +90 -0
  265. package/packages/motion/src/transitions2d/smoothui/shaders.ts +223 -0
  266. package/packages/motion/src/transitions2d/unlumen/LICENSE +21 -0
  267. package/packages/motion/src/transitions2d/unlumen/ScrambleText.tsx +114 -0
  268. package/packages/motion/src/transitions2d/vengeance-ui/LICENSE +21 -0
  269. package/packages/motion/src/transitions2d/vengeance-ui/MorphText.css +69 -0
  270. package/packages/motion/src/transitions2d/vengeance-ui/MorphText.tsx +45 -0
  271. package/packages/motion/src/type.ts +131 -0
  272. package/packages/motion/src/ui.ts +172 -0
  273. package/packages/patterns/package.json +15 -0
  274. package/packages/patterns/src/bars/rank.ts +119 -0
  275. package/packages/patterns/src/before-after/shrink.ts +127 -0
  276. package/packages/patterns/src/before-after/strike.ts +125 -0
  277. package/packages/patterns/src/code/terminal.ts +133 -0
  278. package/packages/patterns/src/compare/bars.ts +142 -0
  279. package/packages/patterns/src/compare/duel.ts +103 -0
  280. package/packages/patterns/src/end/lockup.ts +85 -0
  281. package/packages/patterns/src/end/slam.ts +91 -0
  282. package/packages/patterns/src/flow/graph.ts +250 -0
  283. package/packages/patterns/src/hook-number/counter.ts +101 -0
  284. package/packages/patterns/src/hook-number/roll.ts +179 -0
  285. package/packages/patterns/src/hook-number/slam.ts +91 -0
  286. package/packages/patterns/src/index.ts +38 -0
  287. package/packages/patterns/src/kit.ts +449 -0
  288. package/packages/patterns/src/limit/gauge.ts +117 -0
  289. package/packages/patterns/src/list/cards.ts +131 -0
  290. package/packages/patterns/src/list/cycle.ts +22 -0
  291. package/packages/patterns/src/media/panels.ts +100 -0
  292. package/packages/patterns/src/objects.ts +234 -0
  293. package/packages/patterns/src/quote/karaoke.ts +126 -0
  294. package/packages/patterns/src/quote/slam.ts +22 -0
  295. package/packages/patterns/src/screen/focus.ts +85 -0
  296. package/packages/patterns/src/steps/path.ts +137 -0
  297. package/packages/patterns/src/steps/stack.ts +111 -0
  298. package/packages/patterns/src/term-reveal/chips.ts +92 -0
  299. package/packages/patterns/src/term-reveal/expand.ts +127 -0
  300. package/packages/patterns/src/timeline/axis.ts +144 -0
  301. package/packages/patterns/src/title/mask.ts +85 -0
  302. package/packages/patterns/src/title/slam.ts +23 -0
  303. package/packages/patterns/src/toggle-sim/switch.ts +92 -0
  304. package/packages/patterns/src/trend/columns.ts +108 -0
  305. package/packages/patterns/src/trend/draw.ts +140 -0
  306. package/packages/patterns/src/types.ts +67 -0
  307. package/packages/patterns/src/words/moves.ts +42 -0
  308. package/packages/patterns/src/words/slam.ts +4 -0
  309. package/packages/plan/package.json +15 -0
  310. package/packages/plan/src/asks.ts +256 -0
  311. package/packages/plan/src/brief.ts +383 -0
  312. package/packages/plan/src/captions.ts +78 -0
  313. package/packages/plan/src/detect.ts +93 -0
  314. package/packages/plan/src/index.ts +27 -0
  315. package/packages/plan/src/layout.ts +176 -0
  316. package/packages/plan/src/llm.ts +172 -0
  317. package/packages/plan/src/look.ts +222 -0
  318. package/packages/plan/src/plan.ts +179 -0
  319. package/packages/plan/src/request.ts +55 -0
  320. package/packages/plan/src/series.ts +76 -0
  321. package/packages/plan/src/studio.ts +53 -0
  322. package/packages/plan/src/templates.ts +42 -0
  323. package/packages/plan/src/themes.ts +48 -0
  324. package/packages/plan/src/types.ts +157 -0
  325. package/packages/studio/package.json +12 -0
  326. package/packages/studio/src/index.ts +1 -0
  327. package/packages/studio/src/plugin.ts +236 -0
  328. package/packages/studio/src/ui/main.ts +503 -0
  329. package/packages/studio/src/ui/studio.css +165 -0
  330. package/packages/studio/src/ui/timeline.ts +317 -0
  331. package/packages/themes/kit/THEME-MAKE.md +68 -0
  332. package/packages/themes/kit/THEME.md +30 -0
  333. package/packages/themes/kit/briefs/og-intro-15s/brief.json +16 -0
  334. package/packages/themes/kit/briefs/og-intro-15s/facts.ts +29 -0
  335. package/packages/themes/kit/briefs/og-intro-15s/logo.svg +12 -0
  336. package/packages/themes/kit/effects.ts +5 -0
  337. package/packages/themes/kit/sample/index.html +11 -0
  338. package/packages/themes/kit/sample/main.ts +9 -0
  339. package/packages/themes/kit/sample/scenes/scene.ts +15 -0
  340. package/packages/themes/package.json +19 -0
  341. package/packages/themes/src/factory.ts +296 -0
  342. package/packages/themes/src/fx.ts +14 -0
  343. package/packages/themes/src/index.ts +114 -0
  344. package/packages/themes/src/slotkit.ts +79 -0
  345. package/packages/themes/src/slots.ts +46 -0
  346. package/packages/themes/src/stage3d.ts +197 -0
  347. package/packages/themes/src/types.ts +58 -0
  348. package/presets/kawaii-pastel.json +94 -0
  349. package/presets/neutral-dark.json +82 -0
  350. package/presets/og.json +98 -0
  351. package/series/og-shorts.json +14 -0
  352. package/skills/kasaframe/SKILL.md +33 -0
  353. package/templates/_shared/project/index.html +11 -0
  354. package/templates/_shared/project/lib/react.ts +22 -0
  355. package/templates/_shared/project/lib/stage.ts +292 -0
  356. package/templates/_shared/project/main.ts +9 -0
  357. package/templates/_shared/scenes/default.ts +21 -0
  358. package/templates/_shared/scenes/drop.ts +33 -0
  359. package/templates/_shared/scenes/end.ts +26 -0
  360. package/templates/_shared/scenes/hook.ts +18 -0
  361. package/templates/_shared/scenes/seam.ts +41 -0
  362. package/templates/_shared/scenes/step.ts +49 -0
  363. package/templates/ad/preview.png +0 -0
  364. package/templates/ad/template.json +151 -0
  365. package/templates/demo/preview.png +0 -0
  366. package/templates/demo/template.json +141 -0
  367. package/templates/explainer/preview.png +0 -0
  368. package/templates/explainer/template.json +193 -0
  369. package/templates/launch/preview.png +0 -0
  370. package/templates/launch/template.json +163 -0
  371. package/templates/mv/preview.png +0 -0
  372. package/templates/mv/scenes/default.ts +98 -0
  373. package/templates/mv/template.json +178 -0
  374. package/templates/promo/preview.png +0 -0
  375. package/templates/promo/template.json +185 -0
  376. package/templates/shorts/preview.png +0 -0
  377. package/templates/shorts/scenes/hook.ts +37 -0
  378. package/templates/shorts/template.json +196 -0
  379. package/templates/square/preview.png +0 -0
  380. package/templates/square/template.json +133 -0
  381. package/themes/debug-hud/THEME.md +39 -0
  382. package/themes/debug-hud/effects.ts +389 -0
  383. package/themes/debug-hud/sample/assets/og/logo.svg +12 -0
  384. package/themes/debug-hud/sample/beats.json +1 -0
  385. package/themes/debug-hud/sample/index.html +11 -0
  386. package/themes/debug-hud/sample/kf.json +59 -0
  387. package/themes/debug-hud/sample/lib/hudkit.ts +49 -0
  388. package/themes/debug-hud/sample/lib/og.ts +29 -0
  389. package/themes/debug-hud/sample/main.ts +9 -0
  390. package/themes/debug-hud/sample/scenes/end.ts +62 -0
  391. package/themes/debug-hud/sample/scenes/gather.ts +67 -0
  392. package/themes/debug-hud/sample/scenes/models.ts +70 -0
  393. package/themes/debug-hud/sample/scenes/price.ts +79 -0
  394. package/themes/debug-hud/sample/style.json +91 -0
  395. package/themes/debug-hud/slots.ts +99 -0
  396. package/themes/debug-hud/still.png +0 -0
  397. package/themes/debug-hud/style.json +91 -0
  398. package/themes/debug-hud/theme.json +68 -0
  399. package/themes/og-measure/THEME.md +47 -0
  400. package/themes/og-measure/effects.ts +432 -0
  401. package/themes/og-measure/sample/assets/brand/og-logo-full.svg +12 -0
  402. package/themes/og-measure/sample/assets/brand/og-logo.svg +12 -0
  403. package/themes/og-measure/sample/assets/data/measure.json +353 -0
  404. package/themes/og-measure/sample/beats.json +1 -0
  405. package/themes/og-measure/sample/index.html +11 -0
  406. package/themes/og-measure/sample/kf.json +66 -0
  407. package/themes/og-measure/sample/lib/data.ts +62 -0
  408. package/themes/og-measure/sample/main.ts +9 -0
  409. package/themes/og-measure/sample/measure.ts +78 -0
  410. package/themes/og-measure/sample/scenes/end.ts +47 -0
  411. package/themes/og-measure/sample/scenes/gather.ts +51 -0
  412. package/themes/og-measure/sample/scenes/models.ts +34 -0
  413. package/themes/og-measure/sample/scenes/one.ts +39 -0
  414. package/themes/og-measure/sample/scenes/price.ts +56 -0
  415. package/themes/og-measure/sample/style.json +97 -0
  416. package/themes/og-measure/slots.ts +88 -0
  417. package/themes/og-measure/still.png +0 -0
  418. package/themes/og-measure/style.json +97 -0
  419. package/themes/og-measure/theme.json +79 -0
  420. package/themes/riso-zine/THEME.md +43 -0
  421. package/themes/riso-zine/effects.ts +321 -0
  422. package/themes/riso-zine/sample/assets/og/logo.svg +12 -0
  423. package/themes/riso-zine/sample/beats.json +1 -0
  424. package/themes/riso-zine/sample/index.html +11 -0
  425. package/themes/riso-zine/sample/kf.json +59 -0
  426. package/themes/riso-zine/sample/lib/og.ts +29 -0
  427. package/themes/riso-zine/sample/lib/shot.ts +86 -0
  428. package/themes/riso-zine/sample/lib/zine.ts +42 -0
  429. package/themes/riso-zine/sample/main.ts +9 -0
  430. package/themes/riso-zine/sample/scenes/end.ts +61 -0
  431. package/themes/riso-zine/sample/scenes/gather.ts +62 -0
  432. package/themes/riso-zine/sample/scenes/models.ts +52 -0
  433. package/themes/riso-zine/sample/scenes/price.ts +82 -0
  434. package/themes/riso-zine/sample/style.json +99 -0
  435. package/themes/riso-zine/slots.ts +81 -0
  436. package/themes/riso-zine/still.png +0 -0
  437. package/themes/riso-zine/style.json +99 -0
  438. package/themes/riso-zine/theme.json +75 -0
  439. package/tools/beats/beats.py +372 -0
  440. package/tools/beats/requirements.txt +3 -0
  441. package/tools/lyrics/align.py +164 -0
  442. package/tools/lyrics/requirements.txt +9 -0
@@ -0,0 +1,600 @@
1
+ import { clamp, progress, rand, toEase, type Beats, type BeatGrid, type Ease, type EaseName } from "@kasaframe/core";
2
+ import type { Vec3 } from "../camera.ts";
3
+
4
+ export type { Vec3 };
5
+
6
+ /** 3D 일곱 가지 + gl-transitions(`gl:<이름>`) + SmoothUI 덮개(`smooth:<이름>`) */
7
+ export type Transition3dName = "dive" | "portal" | "cards" | "shatter" | "zoomOut" | "fold" | "diveChain" | "whip" | "rise" | "land" | `gl:${string}` | `smooth:${string}`;
8
+
9
+ export const TRANSITIONS_3D = ["dive", "portal", "cards", "shatter", "zoomOut", "fold", "diveChain", "whip", "rise", "land"] as const satisfies readonly Transition3dName[];
10
+
11
+ /** 혼자 쓸 때(장면 길이를 안 줄 때) 기본 길이 */
12
+ export const DUR_3D: Record<(typeof TRANSITIONS_3D)[number], number> = { dive: 2.8, portal: 2.2, cards: 2.6, shatter: 2.2, zoomOut: 2.4, fold: 2.0, diveChain: 2.4, whip: 1.2, rise: 1.8, land: 1.6 };
13
+
14
+ /** 혼자 쓸 때 기본 길이 — 셰이더 전환(gl·smooth)은 짧게 */
15
+ export const durOf = (kind: Transition3dName): number => (kind in DUR_3D ? DUR_3D[kind as keyof typeof DUR_3D] : 1.2);
16
+
17
+ /** 세로 시야각(도). 높이 1 인 판이 화면을 꽉 채우는 거리가 FIT */
18
+ export const FOV = 40;
19
+ export const FIT = 0.5 / Math.tan((FOV * Math.PI) / 360);
20
+
21
+ export interface Pose {
22
+ pos: Vec3;
23
+ look: Vec3;
24
+ /** 시선 축 둘레 기울기(라디안) */
25
+ roll?: number;
26
+ /** 더하는 화각(도) */
27
+ fov?: number;
28
+ }
29
+
30
+ export interface TimingOpts {
31
+ /** 시작 시각(장면 안 초). 기본 0 */
32
+ at?: number;
33
+ /** 길이. 장면 ctx 가 있으면 기본은 장면 끝까지 */
34
+ dur?: number;
35
+ /** 이 시각에 끝나게 — 드롭·박 시각을 그대로 넣는다. at 을 안 주면 at = endAt - dur */
36
+ endAt?: number;
37
+ /** 끝을 가장 가까운 박·마디·드롭에 붙인다(beats 필요) */
38
+ snap?: BeatGrid;
39
+ beats?: Beats;
40
+ }
41
+
42
+ export interface Timing {
43
+ at: number;
44
+ dur: number;
45
+ }
46
+
47
+ /** at·dur·endAt·snap 을 한 가지 구간으로. 장면 길이(sceneDur)가 있으면 그 안으로 자른다 */
48
+ export function resolveTiming(o: TimingOpts, fallbackDur: number, sceneDur?: number): Timing {
49
+ let at = o.at ?? 0;
50
+ let dur = o.dur ?? (sceneDur !== undefined ? sceneDur - at : fallbackDur);
51
+ if (o.endAt !== undefined) {
52
+ if (o.at === undefined) at = o.endAt - dur;
53
+ else dur = o.endAt - at;
54
+ }
55
+ if (o.snap && o.beats) {
56
+ const end = o.beats.nearestBeat(at + dur, o.snap);
57
+ // 너무 짧아지면 붙이지 않는다 — 그림이 반쯤 넘어가다 잘린다
58
+ if (Number.isFinite(end) && end - at >= 0.4) dur = end - at;
59
+ }
60
+ if (sceneDur !== undefined) {
61
+ at = Math.max(0, at);
62
+ dur = Math.min(dur, sceneDur - at);
63
+ }
64
+ return { at, dur: Math.max(0, dur) };
65
+ }
66
+
67
+ /** 구간 진행도 0..1 — 앞은 0(앞 장면 그대로), 뒤는 1(뒤 장면 그대로) */
68
+ export const rawProgress = (t: number, tm: Timing): number => progress(t, tm.at, tm.dur);
69
+
70
+ /** u 의 [a, b] 부분을 0..1 로 */
71
+ export const seg = (u: number, a: number, b: number, e?: EaseName | Ease): number => {
72
+ const p = clamp((u - a) / (b - a));
73
+ return e ? toEase(e)(p) : p;
74
+ };
75
+
76
+ export const mix = (a: number, b: number, p: number): number => a + (b - a) * p;
77
+ export const mixV = (a: Vec3, b: Vec3, p: number): Vec3 => [mix(a[0], b[0], p), mix(a[1], b[1], p), mix(a[2], b[2], p)];
78
+ export const addV = (a: Vec3, b: Vec3): Vec3 => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
79
+ export const scaleV = (a: Vec3, k: number): Vec3 => [a[0] * k, a[1] * k, a[2] * k];
80
+
81
+ /** 0 과 1 에서 0 인 봉우리 — 양 끝 그림을 정확히 지키면서 가운데에만 얹는 흔들림·비틀기에 */
82
+ export const hump = (u: number): number => Math.sin(Math.PI * clamp(u)) ** 2;
83
+
84
+ /** 판(높이 h, 중심 c, 바라보는 방향 n)을 화면에 꽉 채우는 카메라 자리 */
85
+ export function fitPose(c: Vec3 = [0, 0, 0], h = 1, n: Vec3 = [0, 0, 1]): Pose {
86
+ return { pos: addV(c, scaleV(n, FIT * h)), look: [...c] };
87
+ }
88
+
89
+ /** 카트멀-롬 한 묶음 — 키 사이 속도가 이어진다(키마다 멈추지 않는다). s 는 0..1 */
90
+ export function spline(keys: Vec3[], s: number): Vec3 {
91
+ if (keys.length === 1) return [...keys[0]];
92
+ const n = keys.length - 1;
93
+ const x = clamp(s) * n;
94
+ const i = Math.min(n - 1, Math.floor(x));
95
+ const u = x - i;
96
+ const a = keys[Math.max(0, i - 1)];
97
+ const b = keys[i];
98
+ const c = keys[i + 1];
99
+ const d = keys[Math.min(n, i + 2)];
100
+ const cr = (p0: number, p1: number, p2: number, p3: number) =>
101
+ 0.5 * (2 * p1 + (-p0 + p2) * u + (2 * p0 - 5 * p1 + 4 * p2 - p3) * u * u + (-p0 + 3 * p1 - 3 * p2 + p3) * u * u * u);
102
+ return [0, 1, 2].map((j) => cr(a[j], b[j], c[j], d[j])) as Vec3;
103
+ }
104
+
105
+ /** 시드 난수 [lo, hi) */
106
+ export const rr = (seed: string, i: number, lo: number, hi: number): number => lo + (hi - lo) * rand(seed, i);
107
+
108
+ // ── 종류별 카메라 리그. 순수 함수라 브라우저 없이 시험한다 ──
109
+
110
+ export interface Env {
111
+ aspect: number;
112
+ seed: string;
113
+ }
114
+
115
+ export interface DiveState {
116
+ cam: Pose;
117
+ /** 앞 장면 화면이 녹아 사라진 정도 0..1 */
118
+ dissolve: number;
119
+ /** 카메라가 화면 면을 지나 안쪽 공간에 들어섰는가 */
120
+ inside: boolean;
121
+ /** 화면 결 흔들림(지직) 0..1 */
122
+ glitch: number;
123
+ }
124
+
125
+ /** 깊이 — 화면 뒤 안쪽 공간에서 뒤 장면 판이 서는 자리. 깊을수록 통로를 나는 빠르기가 커진다 */
126
+ export const DIVE_DEPTH = 18;
127
+
128
+ export function diveRig(u: number, env: Env): DiveState {
129
+ const side = rand(env.seed, 1) < 0.5 ? -1 : 1;
130
+ // 물러났다가 다가가는 길을 한 곡선으로 — 앞뒤 방향이 바뀌는 동안에도 옆으로 쓸고 지나가 카메라가 서는 순간이 없다.
131
+ // 앞 절반에 몰아 짧게 물러나고 빨리 뚫는다
132
+ const keys: Vec3[] = [
133
+ [0, 0, FIT],
134
+ [side * 0.55, 0.22, FIT * 2.1],
135
+ [-side * 0.35, 0.16, FIT * 1.8],
136
+ [-side * 0.1, 0.04, FIT * 0.85],
137
+ [0, 0, -0.06],
138
+ ];
139
+ const looks: Vec3[] = [
140
+ [0, 0, 0],
141
+ [side * 0.08, -0.1, 0],
142
+ [-side * 0.04, -0.06, 0],
143
+ [0, 0, -0.5],
144
+ [0, 0, -1],
145
+ ];
146
+ let pos: Vec3;
147
+ let look: Vec3;
148
+ let barrel = 0;
149
+ if (u < 0.5) {
150
+ const x = u / 0.5;
151
+ // 처음부터 움직이며(0 이 아닌 출발 속도) 점점 빨라져 화면을 뚫는다
152
+ const s = 0.35 * x + 0.65 * x * x;
153
+ pos = spline(keys, s);
154
+ look = spline(looks, s);
155
+ } else {
156
+ const fly = seg(u, 0.5, 1, "outCubic");
157
+ pos = mixV([0, 0, -0.06], [0, 0, -DIVE_DEPTH + FIT], fly);
158
+ look = mixV([0, 0, -1], [0, 0, -DIVE_DEPTH], Math.min(1, fly * 1.6));
159
+ // 통로를 나는 동안 한 바퀴 통째로 돈다 — 끝 판이 화면의 25% 를 넘기 전(u 0.78)에 다 돈다. 커진 밝은 판이 어두운 통로 위에서 돌면
160
+ // 칸마다 밝음·어둠이 빠르게 오가 섬광 검사(frame.flash)에 걸린다
161
+ barrel = side * 2 * Math.PI * seg(u, 0.52, 0.78, "inOutCubic");
162
+ }
163
+ const roll = side * -0.14 * hump(seg(u, 0.28, 0.9)) + barrel;
164
+ return {
165
+ cam: { pos, look, roll: u <= 0 || u >= 1 ? 0 : roll },
166
+ // 화면은 가장 멀리 물러난 동안 통로로 녹는다 — 다시 다가가 화면이 시야를 채울 때 밝은 앞 장면이 한 번 더 차오르면
167
+ // 밝음·어둠이 한 전환 안에서 두 번 오가 섬광 검사(frame.flash)에 걸린다
168
+ dissolve: seg(u, 0.18, 0.32, "inOutQuad"),
169
+ inside: pos[2] < 0.04,
170
+ glitch: hump(seg(u, 0.08, 0.26)),
171
+ };
172
+ }
173
+
174
+ export interface PortalState {
175
+ cam: Pose;
176
+ /** 구멍 반지름 — 화면 높이 1 기준 */
177
+ radius: number;
178
+ center: [number, number];
179
+ }
180
+
181
+ export const PORTAL_DEPTH = 8;
182
+
183
+ export function portalRig(u: number, env: Env): PortalState {
184
+ const cx = rr(env.seed, 2, -0.12, 0.12) * env.aspect;
185
+ const cy = rr(env.seed, 3, -0.08, 0.08);
186
+ const far = Math.hypot(env.aspect / 2 + Math.abs(cx), 0.5 + Math.abs(cy));
187
+ const open = seg(u, 0, 0.42, "inOutCubic");
188
+ // 처음엔 작게 열려 안을 보여 주고(0.18), 그다음 화면 밖까지 벌어진다
189
+ const radius = mix(0, 0.2, seg(u, 0, 0.16, "outBack")) + (far - 0.2 + 0.05) * seg(u, 0.16, 0.42, "inCubic") * (open > 0 ? 1 : 0);
190
+ const travel = seg(u, 0.18, 1, "inOutCubic");
191
+ const z = mix(FIT, -PORTAL_DEPTH + FIT, travel);
192
+ // 구멍 쪽으로 살짝 끌려갔다가 터널 축으로 돌아온다
193
+ const pullToHole = hump(seg(u, 0, 0.6)) * 0.7;
194
+ const pos: Vec3 = [cx * pullToHole * 0.6, cy * pullToHole * 0.6, z];
195
+ const look: Vec3 = [cx * pullToHole * 0.4, cy * pullToHole * 0.4, z - 1];
196
+ const side = rand(env.seed, 4) < 0.5 ? -1 : 1;
197
+ return { cam: { pos, look, roll: side * 0.35 * hump(seg(u, 0.2, 1)) }, radius: u <= 0 ? 0 : u >= 1 ? far + 0.05 : radius, center: [cx, cy] };
198
+ }
199
+
200
+ export interface CardSlot {
201
+ pos: Vec3;
202
+ /** y 축 회전(라디안) */
203
+ yaw: number;
204
+ /** 0 = 앞 장면, 1 = 뒤 장면, 2.. = 꾸밈 판(앞·뒤 그림을 흐리게) */
205
+ img: number;
206
+ scale: number;
207
+ }
208
+
209
+ export function cardSlots(env: Env): CardSlot[] {
210
+ const side = rand(env.seed, 5) < 0.5 ? -1 : 1;
211
+ const slots: CardSlot[] = [
212
+ { pos: [0, 0, 0], yaw: 0, img: 0, scale: 1 },
213
+ { pos: [side * 2.7, 0.35, -2.6], yaw: -side * 0.55, img: 1, scale: 1 },
214
+ ];
215
+ const ring = 9;
216
+ for (let i = 0; i < ring; i++) {
217
+ const a = (i / ring) * Math.PI * 2 + rr(env.seed, 10 + i, -0.3, 0.3);
218
+ const r = rr(env.seed, 30 + i, 2.6, 4.6);
219
+ slots.push({
220
+ pos: [Math.cos(a) * r * 1.1 + side * 1.2, rr(env.seed, 50 + i, -1.4, 1.6), -1.4 + Math.sin(a) * r * 0.9 - 1.6],
221
+ yaw: rr(env.seed, 70 + i, -0.7, 0.7),
222
+ img: 2 + (i % 2),
223
+ scale: rr(env.seed, 90 + i, 0.45, 0.85),
224
+ });
225
+ }
226
+ // 꾸밈 판이 처음·끝 카메라와 주인공 판 사이에 끼면 경계 프레임이 가려진다 — 주인공 판 뒤로 민다
227
+ const ends = [fitPose(slots[0].pos), fitPose(slots[1].pos, slots[1].scale, slotNormal(slots[1]))];
228
+ for (const d of slots.slice(2)) {
229
+ for (const pose of ends) {
230
+ const reach = FIT + 0.4;
231
+ const z = depthIn(pose, d.pos, env.aspect, (d.scale * env.aspect) / 2 + 0.2);
232
+ if (z !== null && z < reach) d.pos = addV(d.pos, scaleV(forward(pose), reach + 1 - z));
233
+ }
234
+ }
235
+ return slots;
236
+ }
237
+
238
+ const sub = (a: Vec3, b: Vec3): Vec3 => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
239
+ const dot = (a: Vec3, b: Vec3): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
240
+ const cross = (a: Vec3, b: Vec3): Vec3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
241
+ const norm = (a: Vec3): Vec3 => scaleV(a, 1 / (Math.hypot(...a) || 1));
242
+ const forward = (p: Pose): Vec3 => norm(sub(p.look, p.pos));
243
+
244
+ /** 점이 카메라 시야(가장자리 pad 만큼 넓혀서) 안에 있으면 시선 방향 깊이, 아니면 null */
245
+ export function depthIn(pose: Pose, p: Vec3, aspect: number, pad = 0): number | null {
246
+ const f = forward(pose);
247
+ const r = norm(cross(f, [0, 1, 0]));
248
+ const up = cross(r, f);
249
+ const d = sub(p, pose.pos);
250
+ const z = dot(d, f);
251
+ if (z <= -pad) return null;
252
+ const k = Math.tan((FOV * Math.PI) / 360) * Math.max(z, 0);
253
+ return Math.abs(dot(d, r)) < k * aspect + pad && Math.abs(dot(d, up)) < k + pad ? z : null;
254
+ }
255
+
256
+ /** 판 하나가 바라보는 방향(앞면 법선) */
257
+ export const slotNormal = (s: CardSlot): Vec3 => [Math.sin(s.yaw), 0, Math.cos(s.yaw)];
258
+
259
+ export function cardsRig(u: number, env: Env): { cam: Pose } {
260
+ const [a, b] = cardSlots(env);
261
+ const start = fitPose(a.pos);
262
+ const end = fitPose(b.pos, b.scale, slotNormal(b));
263
+ const mid1: Vec3 = [b.pos[0] * 0.15, 0.55, FIT + 2.4];
264
+ const mid2: Vec3 = addV(b.pos, addV(scaleV(slotNormal(b), FIT + 2.2), [0, 0.35, 0]));
265
+ const s = toEase("inOutCubic")(clamp(u));
266
+ const pos = spline([start.pos, mid1, mid2, end.pos], s);
267
+ // 시선은 앞 판 → 두 판 사이 → 뒤 판으로 넘어간다
268
+ const between = mixV(a.pos, b.pos, 0.5);
269
+ const look = spline([start.look, mixV(a.pos, between, 0.6), mixV(between, b.pos, 0.8), end.look], toEase("inOutQuad")(clamp(u)));
270
+ return { cam: { pos, look } };
271
+ }
272
+
273
+ export interface Tile {
274
+ /** 칸 중심(화면 좌표, 높이 1 기준) */
275
+ c: [number, number];
276
+ /** 출발 지연 0..1 */
277
+ delay: number;
278
+ /** 날아가는 방향·회전축·회전량 */
279
+ vel: Vec3;
280
+ axis: Vec3;
281
+ spin: number;
282
+ }
283
+
284
+ export function tileGrid(env: Env, rows = 9): { cols: number; rows: number; tw: number; th: number } {
285
+ const cols = Math.max(2, Math.round(rows * env.aspect));
286
+ return { cols, rows, tw: env.aspect / cols, th: 1 / rows };
287
+ }
288
+
289
+ /** 쪼개질 칸들 — side 0 은 흩어지는 앞 장면, 1 은 조립되는 뒤 장면 */
290
+ export function tiles(env: Env, side: 0 | 1, rows = 9): Tile[] {
291
+ const { cols, tw, th } = tileGrid(env, rows);
292
+ const seed = `${env.seed}:${side}`;
293
+ const ix = rr(env.seed, 7, -0.2, 0.2) * env.aspect;
294
+ const iy = rr(env.seed, 8, -0.15, 0.15);
295
+ const far = Math.hypot(env.aspect / 2 + Math.abs(ix), 0.5 + Math.abs(iy));
296
+ const out: Tile[] = [];
297
+ for (let r = 0; r < rows; r++) {
298
+ for (let c = 0; c < cols; c++) {
299
+ const i = r * cols + c;
300
+ const x = -env.aspect / 2 + (c + 0.5) * tw;
301
+ const y = -0.5 + (r + 0.5) * th;
302
+ const dx = x - ix;
303
+ const dy = y - iy;
304
+ const d = Math.hypot(dx, dy) / far;
305
+ // 앞 장면은 맞은 자리부터 터지고, 뒤 장면은 가장자리부터 모여 가운데가 마지막에 닫힌다
306
+ const delay = side === 0 ? d * 0.55 + rr(seed, i, 0, 0.12) : (1 - d) * 0.5 + rr(seed, i, 0, 0.12);
307
+ const len = Math.hypot(dx, dy) || 1;
308
+ const push = rr(seed, 1000 + i, 0.8, 2.2);
309
+ const vel: Vec3 = [(dx / len) * push + rr(seed, 2000 + i, -0.4, 0.4), (dy / len) * push + rr(seed, 3000 + i, -0.3, 0.6), side === 0 ? rr(seed, 4000 + i, 0.6, 2.4) : rr(seed, 4000 + i, -4, -1.5)];
310
+ const ax: Vec3 = [rr(seed, 5000 + i, -1, 1), rr(seed, 6000 + i, -1, 1), rr(seed, 7000 + i, -0.4, 0.4)];
311
+ const al = Math.hypot(...ax) || 1;
312
+ out.push({ c: [x, y], delay, vel, axis: [ax[0] / al, ax[1] / al, ax[2] / al], spin: rr(seed, 8000 + i, 1.5, 4.5) * (rand(seed, 9000 + i) < 0.5 ? -1 : 1) });
313
+ }
314
+ }
315
+ return out;
316
+ }
317
+
318
+ /** 칸 하나의 진행 — 0 이면 제자리. 흩어짐은 u 가 지날수록, 조립은 u=1 에서 정확히 0 */
319
+ export function tileAmount(u: number, tile: Tile, side: 0 | 1): number {
320
+ if (side === 0) return seg(u, tile.delay * 0.6, tile.delay * 0.6 + 0.45, "inQuad");
321
+ return 1 - seg(u, 0.35 + tile.delay * 0.45, 0.35 + tile.delay * 0.45 + 0.2, "outCubic");
322
+ }
323
+
324
+ export function shatterRig(u: number, env: Env): { cam: Pose } {
325
+ const side = rand(env.seed, 9) < 0.5 ? -1 : 1;
326
+ const k = hump(u);
327
+ return { cam: { pos: [side * 0.55 * k, 0.12 * k, FIT + 0.9 * k], look: [side * -0.1 * k, 0, 0], roll: side * 0.05 * k } };
328
+ }
329
+
330
+ export interface ZoomOutState {
331
+ cam: Pose;
332
+ /** 창(앞 장면)의 중심·높이 — 뒤 장면 판 위 좌표 */
333
+ win: { c: Vec3; h: number };
334
+ /** 창이 뒤 장면에서 떠 있는 높이 */
335
+ lift: number;
336
+ /** 창 테두리·그림자 보이기 0..1 */
337
+ chrome: number;
338
+ /** 창 그림이 뒤 장면의 그 자리 그림으로 넘어간 정도 */
339
+ blend: number;
340
+ /** 뒤 장면을 어둡게 누르는 정도 */
341
+ dim: number;
342
+ }
343
+
344
+ export interface WindowRect {
345
+ /** 뒤 장면 안 창 중심(0..1, 왼쪽 위가 0) */
346
+ x: number;
347
+ y: number;
348
+ /** 창 높이(뒤 장면 높이 대비 0..1). 창 비율은 화면과 같다 */
349
+ h: number;
350
+ }
351
+
352
+ export function zoomOutRig(u: number, env: Env, win: WindowRect): ZoomOutState {
353
+ const c: Vec3 = [(win.x - 0.5) * env.aspect, 0.5 - win.y, 0];
354
+ const h = win.h;
355
+ const lift = 0.5 * (1 - seg(u, 0.55, 0.92, "inOutCubic"));
356
+ const wc: Vec3 = [c[0], c[1], lift];
357
+ const start = fitPose(wc, h);
358
+ const end = fitPose([0, 0, 0]);
359
+ const side = rand(env.seed, 11) < 0.5 ? -1 : 1;
360
+ const s = toEase("inOutCubic")(clamp(u));
361
+ const midA: Vec3 = [c[0] + side * 0.35, c[1] + 0.2, lift + FIT * h * 2.4];
362
+ const midB: Vec3 = [side * 0.7, 0.35, FIT * 1.5];
363
+ const pos = spline([start.pos, midA, midB, end.pos], s);
364
+ const look = mixV(wc, [0, 0, 0], toEase("inOutQuad")(seg(u, 0.15, 1)));
365
+ return {
366
+ cam: { pos, look },
367
+ win: { c: wc, h },
368
+ lift,
369
+ chrome: hump(seg(u, 0, 0.9)) * (u < 0.85 ? 1 : 1 - seg(u, 0.85, 0.95)),
370
+ blend: seg(u, 0.78, 0.97, "inOutQuad"),
371
+ dim: 0.45 * hump(seg(u, 0, 1)),
372
+ };
373
+ }
374
+
375
+ export type FoldStyle = "accordion" | "roll";
376
+
377
+ export interface FoldState {
378
+ cam: Pose;
379
+ /** 아코디언: 접힌 각(라디안). 말기: 말린 선의 높이 */
380
+ amount: number;
381
+ /** 접힌 묶음이 옆으로 빠지는 거리 */
382
+ slide: number;
383
+ /** 앞 장면이 남아 보이는 정도 */
384
+ alpha: number;
385
+ }
386
+
387
+ export function foldRig(u: number, env: Env, style: FoldStyle): FoldState {
388
+ const side = rand(env.seed, 12) < 0.5 ? -1 : 1;
389
+ const k = hump(u);
390
+ const cam: Pose = { pos: [side * 0.5 * k, -0.18 * k, FIT + 0.75 * k], look: [side * -0.12 * k, 0, 0] };
391
+ if (style === "roll") {
392
+ return { cam, amount: mix(-0.62, 0.85, seg(u, 0, 0.9, "inOutCubic")), slide: 0, alpha: 1 - seg(u, 0.88, 0.98) };
393
+ }
394
+ return {
395
+ cam,
396
+ amount: (Math.PI / 2) * 0.94 * seg(u, 0, 0.62, "inOutCubic"),
397
+ slide: seg(u, 0.55, 0.95, "inCubic") * (env.aspect + 0.6),
398
+ alpha: 1 - seg(u, 0.85, 0.96),
399
+ };
400
+ }
401
+
402
+ // ── 연속 다이브: 화면 속 화면을 끊김 없이 뚫고 들어간다 ──
403
+
404
+ /** 이어지는 화면 사이 깊이 */
405
+ export const CHAIN_GAP = 6;
406
+
407
+ export interface ChainOpts {
408
+ /** 화면 k 가 꽉 차는 시각(장면 안 초) — 늘어나는 순서 */
409
+ arrivals: number[];
410
+ /** 0 이면 같은 빠르기로 흘러가고, 1 이면 화면마다 멈췄다 간다. 기본 0.35 */
411
+ settle?: number;
412
+ gap?: number;
413
+ }
414
+
415
+ export interface ChainState {
416
+ cam: Pose;
417
+ /** 카메라가 지금 지나는(또는 머문) 화면 번호 */
418
+ index: number;
419
+ /** 화면마다 녹은 정도 0..1. 카메라가 지나간 화면은 1 */
420
+ dissolve: number[];
421
+ }
422
+
423
+ /** 화면 k 가 꽉 차는 카메라 z 를 지나는 단조 에르미트 곡선 — 도착 사이 속도가 이어진다 */
424
+ export function chainZ(t: number, o: ChainOpts): number {
425
+ const a = o.arrivals;
426
+ const gap = o.gap ?? CHAIN_GAP;
427
+ const Z = (k: number) => -k * gap + FIT;
428
+ const n = a.length;
429
+ if (n === 1 || t <= a[0]) return Z(0);
430
+ if (t >= a[n - 1]) return Z(n - 1);
431
+ let i = 0;
432
+ while (i < n - 2 && t >= a[i + 1]) i++;
433
+ const settle = clamp(o.settle ?? 0.35);
434
+ const secant = (k: number) => (Z(k + 1) - Z(k)) / (a[k + 1] - a[k]);
435
+ // 양 끝은 멈춘 채 시작·끝(앞·뒤 장면과 이어진다). 가운데는 이웃 기울기, 단조를 지키게 세 배 안으로
436
+ const tangent = (k: number) => {
437
+ if (k === 0 || k === n - 1) return 0;
438
+ const m = ((1 - settle) * (Z(k + 1) - Z(k - 1))) / (a[k + 1] - a[k - 1]);
439
+ const lim = 3 * Math.min(Math.abs(secant(k - 1)), Math.abs(secant(k)));
440
+ return Math.sign(m) * Math.min(Math.abs(m), lim);
441
+ };
442
+ const hseg = a[i + 1] - a[i];
443
+ const s = (t - a[i]) / hseg;
444
+ const s2 = s * s;
445
+ const s3 = s2 * s;
446
+ return (2 * s3 - 3 * s2 + 1) * Z(i) + (s3 - 2 * s2 + s) * hseg * tangent(i) + (-2 * s3 + 3 * s2) * Z(i + 1) + (s3 - s2) * hseg * tangent(i + 1);
447
+ }
448
+
449
+ export function chainRig(t: number, env: Env, o: ChainOpts): ChainState {
450
+ const gap = o.gap ?? CHAIN_GAP;
451
+ const a = o.arrivals;
452
+ const z = chainZ(t, o);
453
+ const n = a.length;
454
+ let index = 0;
455
+ while (index < n - 1 && t >= a[index + 1]) index++;
456
+ const dissolve = a.map((_, k) => {
457
+ if (k === n - 1) return 0;
458
+ const d = z - -k * gap;
459
+ // 꽉 찬 순간(d = FIT)은 반올림 찌꺼기 없이 정확히 0 — 그 프레임이 화면 그림 그대로여야 한다
460
+ return d <= 0 ? 1 : d >= FIT - 1e-9 ? 0 : 1 - clamp((d - 0.25) / (FIT - 0.25));
461
+ });
462
+ // 도착 사이에만 살짝 기운다 — 도착 순간은 0 이라 화면이 똑바로 찬다
463
+ let roll = 0;
464
+ if (t > a[0] && t < a[n - 1]) {
465
+ const s = (t - a[index]) / (a[Math.min(n - 1, index + 1)] - a[index] || 1);
466
+ roll = (rand(env.seed, 20 + index) < 0.5 ? -1 : 1) * 0.16 * hump(s);
467
+ }
468
+ return { cam: { pos: [0, 0, z], look: [0, 0, z - 1], roll }, index, dissolve };
469
+ }
470
+
471
+ /** 박자 격자에서 n 번의 도착 — 첫 도착은 from, 그다음은 격자의 다음 칸마다 */
472
+ export function arrivalsOn(beats: Beats, grid: BeatGrid, from: number, n: number): number[] {
473
+ const out = [from];
474
+ while (out.length < n) {
475
+ const prev = out[out.length - 1];
476
+ let next = beats.next(prev + 1e-3, grid);
477
+ if (!Number.isFinite(next)) next = prev + (out.length > 1 ? prev - out[out.length - 2] : 0.5);
478
+ out.push(next);
479
+ }
480
+ return out;
481
+ }
482
+
483
+ // ── 휙 넘기기: 제자리에서 90° 를 휙 돈다 ──
484
+
485
+ /**
486
+ * 반대로 살짝 감았다가(예비 동작) 확 돌고, 1.5% 넘쳤다가 되돌아와 선다. 도는 동안 몸을 기울이고 화각을 넓힌다.
487
+ * 양 끝은 기울기·화각 0 — 앞 판·뒤 판이 꽉 찬다
488
+ */
489
+ export function whipRig(u: number, env: Env): { cam: Pose; side: 1 | -1 } {
490
+ const side = rand(env.seed, 13) < 0.5 ? -1 : 1;
491
+ const edge = u <= 0 || u >= 1;
492
+ const wind = -0.045 * Math.sin(Math.PI * seg(u, 0, 0.24));
493
+ // 넘침은 1.5% — 밝은 판 가장자리가 되돌아오며 칸을 한 번 더 쓸면 섬광 검사(frame.flash)가 꺾임을 두 번 더 센다
494
+ const turn = u < 0.8 ? 1.015 * seg(u, 0.14, 0.8, "inOutQuart") : 1 + 0.015 * (0.5 + 0.5 * Math.cos(Math.PI * seg(u, 0.8, 1)));
495
+ const p = u <= 0 ? 0 : u >= 1 ? 1 : turn + wind;
496
+ const yaw = (side * Math.PI * p) / 2;
497
+ return {
498
+ side,
499
+ cam: {
500
+ pos: [0, 0, 0],
501
+ look: [-Math.sin(yaw), 0, -Math.cos(yaw)],
502
+ roll: edge ? 0 : side * -0.22 * hump(seg(u, 0.14, 0.86)),
503
+ fov: edge ? 0 : 14 * hump(seg(u, 0.18, 0.8)),
504
+ },
505
+ };
506
+ }
507
+
508
+ // ── 공간 잇기: 2D 와 3D 사이를 같은 공간으로 ──
509
+
510
+ /** 판 위 주인공 상자 — 판 좌표(가로 aspect·세로 1, 가운데가 0, 위가 +). 앞 장면이 stage.hero 로 짚은 요소를 잰다 */
511
+ export interface HeroBox {
512
+ x: number;
513
+ y: number;
514
+ w: number;
515
+ h: number;
516
+ }
517
+
518
+ /** 주인공 블록이 서는 높이 — 2D 상자가 클수록 높게, 화면 높이의 1/3 안에서 */
519
+ export const liftOf = (hero: HeroBox): number => Math.min(0.22, 0.08 + 0.45 * Math.min(hero.w, hero.h));
520
+
521
+ /** rise — 뒤 장면 벽이 서는 깊이. 누운 앞 판(깊이 1) 끝보다 멀어 끝 구도에서 블록이 카메라 뒤로 빠진다 */
522
+ export const RISE_WALL = 1 + FIT + 0.35;
523
+
524
+ export interface RiseState {
525
+ cam: Pose;
526
+ /** 앞 판이 아래 가장자리를 축으로 뒤로 누운 각(0 → -π/2) — 판의 법선이 위를 보게 되어 블록이 바로 선다 */
527
+ lie: number;
528
+ /** 주인공 블록 높이(판 법선 방향) */
529
+ lift: number;
530
+ }
531
+
532
+ /**
533
+ * 2D → 3D. 처음엔 앞 장면 판이 화면을 꽉 채우고(경계 프레임 그대로), 주인공 상자가 같은 화면 자리에서 블록으로 솟는다.
534
+ * 판이 아래 가장자리를 축으로 뒤로 누워 바닥이 되면 블록은 그 위에 선 물체가 되고, 카메라가 깊이로 기울어 들어가
535
+ * 블록 위를 지나 바닥 끝 벽(뒤 장면 첫 화면)을 정면으로 꽉 채우며 선다
536
+ */
537
+ export function riseRig(u: number, env: Env, hero: HeroBox): RiseState {
538
+ const hx = hero.x;
539
+ const near = -(hero.y + 0.5);
540
+ // 블록 위를 높이 지난다 — 낮게 스치면 블록 옆면이 화면을 크게 쓸어 섬광 검사(frame.flash)에 걸린다
541
+ const keys: Vec3[] = [
542
+ [0, 0, FIT],
543
+ [hx * 0.2, 0.16, FIT * 0.85],
544
+ [hx * 0.1, 0.52, near - 0.35],
545
+ [0, 0, -RISE_WALL + FIT],
546
+ ];
547
+ const looks: Vec3[] = [
548
+ [0, 0, 0],
549
+ [hx * 0.45, -0.32, near * 0.7],
550
+ [0, -0.1, -RISE_WALL],
551
+ [0, 0, -RISE_WALL],
552
+ ];
553
+ const sway = rand(env.seed, 70) < 0.5 ? -1 : 1;
554
+ const edge = u <= 0 || u >= 1;
555
+ return {
556
+ cam: { pos: spline(keys, u), look: spline(looks, u), roll: edge ? 0 : sway * 0.06 * hump(seg(u, 0.15, 0.9)) },
557
+ lie: (-Math.PI / 2) * seg(u, 0.1, 0.6, "inOutCubic"),
558
+ lift: u <= 0 ? 0 : liftOf(hero) * seg(u, 0, 0.42, "outCubic"),
559
+ };
560
+ }
561
+
562
+ /** land — 뒤 장면 판의 크기와 자리. 작게 두어야 카메라가 다가가며(뒤로 물러나지 않고) 판이 화면을 꽉 채운다 */
563
+ export const LAND_CARD = 0.4;
564
+ export const LAND_Z = 0.3;
565
+
566
+ export interface LandState {
567
+ cam: Pose;
568
+ /** 뒤 장면 판이 누운 각(-π/2 누움 → 0 섰다) — 아래 가장자리가 축 */
569
+ lie: number;
570
+ /** 뒤 장면 주인공 블록 높이 — 판이 서며 평면으로 내려앉는다 */
571
+ lift: number;
572
+ /** 뒤 장면 판의 불투명도 — 처음 프레임은 앞 장면 그대로 */
573
+ alpha: number;
574
+ }
575
+
576
+ /**
577
+ * 3D → 2D. 앞 장면(3D 샷 마지막 화면)이 꽉 찬 채 시작해, 그 앞 공간에 누워 있던 판 하나가 일어서고 카메라가 그 판으로 다가간다.
578
+ * 판 위 주인공 블록은 평면으로 내려앉고, 판이 화면을 정면으로 꽉 채운 순간이 뒤 장면 첫 화면이다
579
+ */
580
+ export function landRig(u: number, env: Env, hero: HeroBox): LandState {
581
+ const z = LAND_Z;
582
+ const keys: Vec3[] = [
583
+ [0, 0, FIT],
584
+ [hero.x * LAND_CARD * 0.2, 0.08, FIT * 0.85],
585
+ [0, 0.04, z + FIT * LAND_CARD * 1.5],
586
+ [0, 0, z + FIT * LAND_CARD],
587
+ ];
588
+ const looks: Vec3[] = [
589
+ [0, 0, 0],
590
+ [0, -0.12, z - 0.2],
591
+ [0, -0.02, z],
592
+ [0, 0, z],
593
+ ];
594
+ return {
595
+ cam: { pos: spline(keys, u), look: spline(looks, u) },
596
+ lie: (-Math.PI / 2) * (1 - seg(u, 0.12, 0.85, "inOutCubic")),
597
+ lift: u >= 1 ? 0 : liftOf(hero) * LAND_CARD * (1 - seg(u, 0.45, 0.95, "inOutCubic")),
598
+ alpha: seg(u, 0, 0.14),
599
+ };
600
+ }