@nodetool-ai/timeline 0.8.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 (505) hide show
  1. package/README.md +55 -0
  2. package/dist/.nodetool-build-stamp +1 -0
  3. package/dist/animation/bakedAnimation.d.ts +84 -0
  4. package/dist/animation/bakedAnimation.d.ts.map +1 -0
  5. package/dist/animation/bakedAnimation.js +95 -0
  6. package/dist/animation/bakedAnimation.js.map +1 -0
  7. package/dist/animation/beat.d.ts +7 -0
  8. package/dist/animation/beat.d.ts.map +1 -0
  9. package/dist/animation/beat.js +36 -0
  10. package/dist/animation/beat.js.map +1 -0
  11. package/dist/animation/compile.d.ts +184 -0
  12. package/dist/animation/compile.d.ts.map +1 -0
  13. package/dist/animation/compile.js +312 -0
  14. package/dist/animation/compile.js.map +1 -0
  15. package/dist/animation/custom.d.ts +183 -0
  16. package/dist/animation/custom.d.ts.map +1 -0
  17. package/dist/animation/custom.js +583 -0
  18. package/dist/animation/custom.js.map +1 -0
  19. package/dist/animation/easing.d.ts +34 -0
  20. package/dist/animation/easing.d.ts.map +1 -0
  21. package/dist/animation/easing.js +332 -0
  22. package/dist/animation/easing.js.map +1 -0
  23. package/dist/animation/index.d.ts +20 -0
  24. package/dist/animation/index.d.ts.map +1 -0
  25. package/dist/animation/index.js +20 -0
  26. package/dist/animation/index.js.map +1 -0
  27. package/dist/animation/links.d.ts +33 -0
  28. package/dist/animation/links.d.ts.map +1 -0
  29. package/dist/animation/links.js +126 -0
  30. package/dist/animation/links.js.map +1 -0
  31. package/dist/animation/presets.d.ts +86 -0
  32. package/dist/animation/presets.d.ts.map +1 -0
  33. package/dist/animation/presets.js +642 -0
  34. package/dist/animation/presets.js.map +1 -0
  35. package/dist/animation/sample.d.ts +145 -0
  36. package/dist/animation/sample.d.ts.map +1 -0
  37. package/dist/animation/sample.js +390 -0
  38. package/dist/animation/sample.js.map +1 -0
  39. package/dist/animation/simplify.d.ts +70 -0
  40. package/dist/animation/simplify.d.ts.map +1 -0
  41. package/dist/animation/simplify.js +278 -0
  42. package/dist/animation/simplify.js.map +1 -0
  43. package/dist/animation/sourceCurves.d.ts +45 -0
  44. package/dist/animation/sourceCurves.d.ts.map +1 -0
  45. package/dist/animation/sourceCurves.js +168 -0
  46. package/dist/animation/sourceCurves.js.map +1 -0
  47. package/dist/animation/styleTracks.d.ts +23 -0
  48. package/dist/animation/styleTracks.d.ts.map +1 -0
  49. package/dist/animation/styleTracks.js +341 -0
  50. package/dist/animation/styleTracks.js.map +1 -0
  51. package/dist/animation/types.d.ts +269 -0
  52. package/dist/animation/types.d.ts.map +1 -0
  53. package/dist/animation/types.js +173 -0
  54. package/dist/animation/types.js.map +1 -0
  55. package/dist/animation/typewriter.d.ts +8 -0
  56. package/dist/animation/typewriter.d.ts.map +1 -0
  57. package/dist/animation/typewriter.js +32 -0
  58. package/dist/animation/typewriter.js.map +1 -0
  59. package/dist/audioFade.d.ts +73 -0
  60. package/dist/audioFade.d.ts.map +1 -0
  61. package/dist/audioFade.js +134 -0
  62. package/dist/audioFade.js.map +1 -0
  63. package/dist/authoredStyles.d.ts +61 -0
  64. package/dist/authoredStyles.d.ts.map +1 -0
  65. package/dist/authoredStyles.js +90 -0
  66. package/dist/authoredStyles.js.map +1 -0
  67. package/dist/authoring.d.ts +50 -0
  68. package/dist/authoring.d.ts.map +1 -0
  69. package/dist/authoring.js +207 -0
  70. package/dist/authoring.js.map +1 -0
  71. package/dist/beats.d.ts +103 -0
  72. package/dist/beats.d.ts.map +1 -0
  73. package/dist/beats.js +228 -0
  74. package/dist/beats.js.map +1 -0
  75. package/dist/clone.d.ts +32 -0
  76. package/dist/clone.d.ts.map +1 -0
  77. package/dist/clone.js +53 -0
  78. package/dist/clone.js.map +1 -0
  79. package/dist/composition.d.ts +87 -0
  80. package/dist/composition.d.ts.map +1 -0
  81. package/dist/composition.js +253 -0
  82. package/dist/composition.js.map +1 -0
  83. package/dist/crop.d.ts +48 -0
  84. package/dist/crop.d.ts.map +1 -0
  85. package/dist/crop.js +75 -0
  86. package/dist/crop.js.map +1 -0
  87. package/dist/defaults.d.ts +142 -0
  88. package/dist/defaults.d.ts.map +1 -0
  89. package/dist/defaults.js +335 -0
  90. package/dist/defaults.js.map +1 -0
  91. package/dist/dependencyHash.d.ts +14 -0
  92. package/dist/dependencyHash.d.ts.map +1 -0
  93. package/dist/dependencyHash.js +19 -0
  94. package/dist/dependencyHash.js.map +1 -0
  95. package/dist/dropResolve.d.ts +40 -0
  96. package/dist/dropResolve.d.ts.map +1 -0
  97. package/dist/dropResolve.js +137 -0
  98. package/dist/dropResolve.js.map +1 -0
  99. package/dist/examples/node.d.ts +11 -0
  100. package/dist/examples/node.d.ts.map +1 -0
  101. package/dist/examples/node.js +87 -0
  102. package/dist/examples/node.js.map +1 -0
  103. package/dist/extension.d.ts +52 -0
  104. package/dist/extension.d.ts.map +1 -0
  105. package/dist/extension.js +269 -0
  106. package/dist/extension.js.map +1 -0
  107. package/dist/extensionRequest.d.ts +40 -0
  108. package/dist/extensionRequest.d.ts.map +1 -0
  109. package/dist/extensionRequest.js +135 -0
  110. package/dist/extensionRequest.js.map +1 -0
  111. package/dist/fill-text.d.ts +30 -0
  112. package/dist/fill-text.d.ts.map +1 -0
  113. package/dist/fill-text.js +73 -0
  114. package/dist/fill-text.js.map +1 -0
  115. package/dist/fonts/catalog.d.ts +97 -0
  116. package/dist/fonts/catalog.d.ts.map +1 -0
  117. package/dist/fonts/catalog.js +276 -0
  118. package/dist/fonts/catalog.js.map +1 -0
  119. package/dist/fonts/css.d.ts +24 -0
  120. package/dist/fonts/css.d.ts.map +1 -0
  121. package/dist/fonts/css.js +50 -0
  122. package/dist/fonts/css.js.map +1 -0
  123. package/dist/fonts/index.d.ts +10 -0
  124. package/dist/fonts/index.d.ts.map +1 -0
  125. package/dist/fonts/index.js +10 -0
  126. package/dist/fonts/index.js.map +1 -0
  127. package/dist/fonts/register-node.d.ts +45 -0
  128. package/dist/fonts/register-node.d.ts.map +1 -0
  129. package/dist/fonts/register-node.js +71 -0
  130. package/dist/fonts/register-node.js.map +1 -0
  131. package/dist/generatedMatte.d.ts +86 -0
  132. package/dist/generatedMatte.d.ts.map +1 -0
  133. package/dist/generatedMatte.js +152 -0
  134. package/dist/generatedMatte.js.map +1 -0
  135. package/dist/generative.d.ts +145 -0
  136. package/dist/generative.d.ts.map +1 -0
  137. package/dist/generative.js +396 -0
  138. package/dist/generative.js.map +1 -0
  139. package/dist/group.d.ts +47 -0
  140. package/dist/group.d.ts.map +1 -0
  141. package/dist/group.js +131 -0
  142. package/dist/group.js.map +1 -0
  143. package/dist/index.d.ts +55 -0
  144. package/dist/index.d.ts.map +1 -0
  145. package/dist/index.js +58 -0
  146. package/dist/index.js.map +1 -0
  147. package/dist/interchange.d.ts +47 -0
  148. package/dist/interchange.d.ts.map +1 -0
  149. package/dist/interchange.js +158 -0
  150. package/dist/interchange.js.map +1 -0
  151. package/dist/keyframes.d.ts +44 -0
  152. package/dist/keyframes.d.ts.map +1 -0
  153. package/dist/keyframes.js +148 -0
  154. package/dist/keyframes.js.map +1 -0
  155. package/dist/lineDelivery.d.ts +108 -0
  156. package/dist/lineDelivery.d.ts.map +1 -0
  157. package/dist/lineDelivery.js +154 -0
  158. package/dist/lineDelivery.js.map +1 -0
  159. package/dist/linked.d.ts +41 -0
  160. package/dist/linked.d.ts.map +1 -0
  161. package/dist/linked.js +166 -0
  162. package/dist/linked.js.map +1 -0
  163. package/dist/lipSyncRequest.d.ts +65 -0
  164. package/dist/lipSyncRequest.d.ts.map +1 -0
  165. package/dist/lipSyncRequest.js +73 -0
  166. package/dist/lipSyncRequest.js.map +1 -0
  167. package/dist/measureClipDurations.d.ts +7 -0
  168. package/dist/measureClipDurations.d.ts.map +1 -0
  169. package/dist/measureClipDurations.js +17 -0
  170. package/dist/measureClipDurations.js.map +1 -0
  171. package/dist/mediaTrack.d.ts +120 -0
  172. package/dist/mediaTrack.d.ts.map +1 -0
  173. package/dist/mediaTrack.js +269 -0
  174. package/dist/mediaTrack.js.map +1 -0
  175. package/dist/midi/cacheKey.d.ts +25 -0
  176. package/dist/midi/cacheKey.d.ts.map +1 -0
  177. package/dist/midi/cacheKey.js +54 -0
  178. package/dist/midi/cacheKey.js.map +1 -0
  179. package/dist/midi/edit.d.ts +48 -0
  180. package/dist/midi/edit.d.ts.map +1 -0
  181. package/dist/midi/edit.js +93 -0
  182. package/dist/midi/edit.js.map +1 -0
  183. package/dist/midi/engines/bl1.d.ts +29 -0
  184. package/dist/midi/engines/bl1.d.ts.map +1 -0
  185. package/dist/midi/engines/bl1.js +128 -0
  186. package/dist/midi/engines/bl1.js.map +1 -0
  187. package/dist/midi/engines/dr1.d.ts +28 -0
  188. package/dist/midi/engines/dr1.d.ts.map +1 -0
  189. package/dist/midi/engines/dr1.js +101 -0
  190. package/dist/midi/engines/dr1.js.map +1 -0
  191. package/dist/midi/engines/dsp.d.ts +126 -0
  192. package/dist/midi/engines/dsp.d.ts.map +1 -0
  193. package/dist/midi/engines/dsp.js +371 -0
  194. package/dist/midi/engines/dsp.js.map +1 -0
  195. package/dist/midi/engines/index.d.ts +13 -0
  196. package/dist/midi/engines/index.d.ts.map +1 -0
  197. package/dist/midi/engines/index.js +13 -0
  198. package/dist/midi/engines/index.js.map +1 -0
  199. package/dist/midi/engines/kits.d.ts +12 -0
  200. package/dist/midi/engines/kits.d.ts.map +1 -0
  201. package/dist/midi/engines/kits.js +121 -0
  202. package/dist/midi/engines/kits.js.map +1 -0
  203. package/dist/midi/engines/wavetables.d.ts +45 -0
  204. package/dist/midi/engines/wavetables.d.ts.map +1 -0
  205. package/dist/midi/engines/wavetables.js +334 -0
  206. package/dist/midi/engines/wavetables.js.map +1 -0
  207. package/dist/midi/engines/wt1.d.ts +30 -0
  208. package/dist/midi/engines/wt1.d.ts.map +1 -0
  209. package/dist/midi/engines/wt1.js +91 -0
  210. package/dist/midi/engines/wt1.js.map +1 -0
  211. package/dist/midi/grid.d.ts +51 -0
  212. package/dist/midi/grid.d.ts.map +1 -0
  213. package/dist/midi/grid.js +104 -0
  214. package/dist/midi/grid.js.map +1 -0
  215. package/dist/midi/index.d.ts +20 -0
  216. package/dist/midi/index.d.ts.map +1 -0
  217. package/dist/midi/index.js +20 -0
  218. package/dist/midi/index.js.map +1 -0
  219. package/dist/midi/instrument.d.ts +32 -0
  220. package/dist/midi/instrument.d.ts.map +1 -0
  221. package/dist/midi/instrument.js +73 -0
  222. package/dist/midi/instrument.js.map +1 -0
  223. package/dist/midi/notes.d.ts +46 -0
  224. package/dist/midi/notes.d.ts.map +1 -0
  225. package/dist/midi/notes.js +121 -0
  226. package/dist/midi/notes.js.map +1 -0
  227. package/dist/midi/notesEdit.d.ts +94 -0
  228. package/dist/midi/notesEdit.d.ts.map +1 -0
  229. package/dist/midi/notesEdit.js +159 -0
  230. package/dist/midi/notesEdit.js.map +1 -0
  231. package/dist/midi/presets.d.ts +29 -0
  232. package/dist/midi/presets.d.ts.map +1 -0
  233. package/dist/midi/presets.js +281 -0
  234. package/dist/midi/presets.js.map +1 -0
  235. package/dist/midi/tempo.d.ts +27 -0
  236. package/dist/midi/tempo.d.ts.map +1 -0
  237. package/dist/midi/tempo.js +57 -0
  238. package/dist/midi/tempo.js.map +1 -0
  239. package/dist/midi/ticks.d.ts +25 -0
  240. package/dist/midi/ticks.d.ts.map +1 -0
  241. package/dist/midi/ticks.js +35 -0
  242. package/dist/midi/ticks.js.map +1 -0
  243. package/dist/midi/voice.d.ts +148 -0
  244. package/dist/midi/voice.d.ts.map +1 -0
  245. package/dist/midi/voice.js +348 -0
  246. package/dist/midi/voice.js.map +1 -0
  247. package/dist/midi/wav.d.ts +14 -0
  248. package/dist/midi/wav.d.ts.map +1 -0
  249. package/dist/midi/wav.js +51 -0
  250. package/dist/midi/wav.js.map +1 -0
  251. package/dist/model3d.d.ts +41 -0
  252. package/dist/model3d.d.ts.map +1 -0
  253. package/dist/model3d.js +39 -0
  254. package/dist/model3d.js.map +1 -0
  255. package/dist/model3dBake.d.ts +80 -0
  256. package/dist/model3dBake.d.ts.map +1 -0
  257. package/dist/model3dBake.js +127 -0
  258. package/dist/model3dBake.js.map +1 -0
  259. package/dist/ops/apply.d.ts +32 -0
  260. package/dist/ops/apply.d.ts.map +1 -0
  261. package/dist/ops/apply.js +1595 -0
  262. package/dist/ops/apply.js.map +1 -0
  263. package/dist/ops/index.d.ts +13 -0
  264. package/dist/ops/index.d.ts.map +1 -0
  265. package/dist/ops/index.js +13 -0
  266. package/dist/ops/index.js.map +1 -0
  267. package/dist/ops/op.d.ts +407 -0
  268. package/dist/ops/op.d.ts.map +1 -0
  269. package/dist/ops/op.js +61 -0
  270. package/dist/ops/op.js.map +1 -0
  271. package/dist/ops/serialize.d.ts +77 -0
  272. package/dist/ops/serialize.d.ts.map +1 -0
  273. package/dist/ops/serialize.js +81 -0
  274. package/dist/ops/serialize.js.map +1 -0
  275. package/dist/ops/types.d.ts +150 -0
  276. package/dist/ops/types.d.ts.map +1 -0
  277. package/dist/ops/types.js +12 -0
  278. package/dist/ops/types.js.map +1 -0
  279. package/dist/pathSampling.d.ts +51 -0
  280. package/dist/pathSampling.d.ts.map +1 -0
  281. package/dist/pathSampling.js +111 -0
  282. package/dist/pathSampling.js.map +1 -0
  283. package/dist/placement/index.d.ts +2 -0
  284. package/dist/placement/index.d.ts.map +1 -0
  285. package/dist/placement/index.js +2 -0
  286. package/dist/placement/index.js.map +1 -0
  287. package/dist/placement/resolveTrackPlacement.d.ts +40 -0
  288. package/dist/placement/resolveTrackPlacement.d.ts.map +1 -0
  289. package/dist/placement/resolveTrackPlacement.js +71 -0
  290. package/dist/placement/resolveTrackPlacement.js.map +1 -0
  291. package/dist/production.d.ts +99 -0
  292. package/dist/production.d.ts.map +1 -0
  293. package/dist/production.js +328 -0
  294. package/dist/production.js.map +1 -0
  295. package/dist/reassemble.d.ts +68 -0
  296. package/dist/reassemble.d.ts.map +1 -0
  297. package/dist/reassemble.js +187 -0
  298. package/dist/reassemble.js.map +1 -0
  299. package/dist/recipe.d.ts +24 -0
  300. package/dist/recipe.d.ts.map +1 -0
  301. package/dist/recipe.js +89 -0
  302. package/dist/recipe.js.map +1 -0
  303. package/dist/recordedVoiceReplacement.d.ts +70 -0
  304. package/dist/recordedVoiceReplacement.d.ts.map +1 -0
  305. package/dist/recordedVoiceReplacement.js +82 -0
  306. package/dist/recordedVoiceReplacement.js.map +1 -0
  307. package/dist/reframe.d.ts +31 -0
  308. package/dist/reframe.d.ts.map +1 -0
  309. package/dist/reframe.js +227 -0
  310. package/dist/reframe.js.map +1 -0
  311. package/dist/render/canvas2d.d.ts +419 -0
  312. package/dist/render/canvas2d.d.ts.map +1 -0
  313. package/dist/render/canvas2d.js +1392 -0
  314. package/dist/render/canvas2d.js.map +1 -0
  315. package/dist/render/color.d.ts +26 -0
  316. package/dist/render/color.d.ts.map +1 -0
  317. package/dist/render/color.js +305 -0
  318. package/dist/render/color.js.map +1 -0
  319. package/dist/render/cpuLegacyEffects.d.ts +17 -0
  320. package/dist/render/cpuLegacyEffects.d.ts.map +1 -0
  321. package/dist/render/cpuLegacyEffects.js +347 -0
  322. package/dist/render/cpuLegacyEffects.js.map +1 -0
  323. package/dist/render/cpuVisualEffects.d.ts +13 -0
  324. package/dist/render/cpuVisualEffects.d.ts.map +1 -0
  325. package/dist/render/cpuVisualEffects.js +388 -0
  326. package/dist/render/cpuVisualEffects.js.map +1 -0
  327. package/dist/render/cubeLut.d.ts +12 -0
  328. package/dist/render/cubeLut.d.ts.map +1 -0
  329. package/dist/render/cubeLut.js +81 -0
  330. package/dist/render/cubeLut.js.map +1 -0
  331. package/dist/render/curveFitting.d.ts +28 -0
  332. package/dist/render/curveFitting.d.ts.map +1 -0
  333. package/dist/render/curveFitting.js +94 -0
  334. package/dist/render/curveFitting.js.map +1 -0
  335. package/dist/render/draw.d.ts +265 -0
  336. package/dist/render/draw.d.ts.map +1 -0
  337. package/dist/render/draw.js +929 -0
  338. package/dist/render/draw.js.map +1 -0
  339. package/dist/render/effects.d.ts +120 -0
  340. package/dist/render/effects.d.ts.map +1 -0
  341. package/dist/render/effects.js +804 -0
  342. package/dist/render/effects.js.map +1 -0
  343. package/dist/render/frameCompositor.d.ts +502 -0
  344. package/dist/render/frameCompositor.d.ts.map +1 -0
  345. package/dist/render/frameCompositor.js +1331 -0
  346. package/dist/render/frameCompositor.js.map +1 -0
  347. package/dist/render/index.d.ts +27 -0
  348. package/dist/render/index.d.ts.map +1 -0
  349. package/dist/render/index.js +27 -0
  350. package/dist/render/index.js.map +1 -0
  351. package/dist/render/layout.d.ts +17 -0
  352. package/dist/render/layout.d.ts.map +1 -0
  353. package/dist/render/layout.js +197 -0
  354. package/dist/render/layout.js.map +1 -0
  355. package/dist/render/model3dBakeSamples.d.ts +45 -0
  356. package/dist/render/model3dBakeSamples.d.ts.map +1 -0
  357. package/dist/render/model3dBakeSamples.js +68 -0
  358. package/dist/render/model3dBakeSamples.js.map +1 -0
  359. package/dist/render/motionBlur.d.ts +170 -0
  360. package/dist/render/motionBlur.d.ts.map +1 -0
  361. package/dist/render/motionBlur.js +193 -0
  362. package/dist/render/motionBlur.js.map +1 -0
  363. package/dist/render/sceneModel.d.ts +577 -0
  364. package/dist/render/sceneModel.d.ts.map +1 -0
  365. package/dist/render/sceneModel.js +1460 -0
  366. package/dist/render/sceneModel.js.map +1 -0
  367. package/dist/render/shapeGeometry.d.ts +81 -0
  368. package/dist/render/shapeGeometry.d.ts.map +1 -0
  369. package/dist/render/shapeGeometry.js +460 -0
  370. package/dist/render/shapeGeometry.js.map +1 -0
  371. package/dist/render/spatial.d.ts +9 -0
  372. package/dist/render/spatial.d.ts.map +1 -0
  373. package/dist/render/spatial.js +58 -0
  374. package/dist/render/spatial.js.map +1 -0
  375. package/dist/render/svgPath.d.ts +80 -0
  376. package/dist/render/svgPath.d.ts.map +1 -0
  377. package/dist/render/svgPath.js +199 -0
  378. package/dist/render/svgPath.js.map +1 -0
  379. package/dist/render/temporal.d.ts +6 -0
  380. package/dist/render/temporal.d.ts.map +1 -0
  381. package/dist/render/temporal.js +74 -0
  382. package/dist/render/temporal.js.map +1 -0
  383. package/dist/render/textLayout.d.ts +159 -0
  384. package/dist/render/textLayout.d.ts.map +1 -0
  385. package/dist/render/textLayout.js +301 -0
  386. package/dist/render/textLayout.js.map +1 -0
  387. package/dist/render/trackEffects.d.ts +23 -0
  388. package/dist/render/trackEffects.d.ts.map +1 -0
  389. package/dist/render/trackEffects.js +93 -0
  390. package/dist/render/trackEffects.js.map +1 -0
  391. package/dist/render/transform.d.ts +54 -0
  392. package/dist/render/transform.d.ts.map +1 -0
  393. package/dist/render/transform.js +222 -0
  394. package/dist/render/transform.js.map +1 -0
  395. package/dist/render/transition.d.ts +109 -0
  396. package/dist/render/transition.d.ts.map +1 -0
  397. package/dist/render/transition.js +351 -0
  398. package/dist/render/transition.js.map +1 -0
  399. package/dist/retarget.d.ts +73 -0
  400. package/dist/retarget.d.ts.map +1 -0
  401. package/dist/retarget.js +305 -0
  402. package/dist/retarget.js.map +1 -0
  403. package/dist/rippleEdit.d.ts +83 -0
  404. package/dist/rippleEdit.d.ts.map +1 -0
  405. package/dist/rippleEdit.js +184 -0
  406. package/dist/rippleEdit.js.map +1 -0
  407. package/dist/scene.d.ts +28 -0
  408. package/dist/scene.d.ts.map +1 -0
  409. package/dist/scene.js +28 -0
  410. package/dist/scene.js.map +1 -0
  411. package/dist/script-link.d.ts +52 -0
  412. package/dist/script-link.d.ts.map +1 -0
  413. package/dist/script-link.js +78 -0
  414. package/dist/script-link.js.map +1 -0
  415. package/dist/script.d.ts +52 -0
  416. package/dist/script.d.ts.map +1 -0
  417. package/dist/script.js +93 -0
  418. package/dist/script.js.map +1 -0
  419. package/dist/snap.d.ts +2 -0
  420. package/dist/snap.d.ts.map +1 -0
  421. package/dist/snap.js +21 -0
  422. package/dist/snap.js.map +1 -0
  423. package/dist/snapping/buildSnapPoints.d.ts +16 -0
  424. package/dist/snapping/buildSnapPoints.d.ts.map +1 -0
  425. package/dist/snapping/buildSnapPoints.js +39 -0
  426. package/dist/snapping/buildSnapPoints.js.map +1 -0
  427. package/dist/snapping/index.d.ts +3 -0
  428. package/dist/snapping/index.d.ts.map +1 -0
  429. package/dist/snapping/index.js +3 -0
  430. package/dist/snapping/index.js.map +1 -0
  431. package/dist/snapping/resolveSnap.d.ts +19 -0
  432. package/dist/snapping/resolveSnap.d.ts.map +1 -0
  433. package/dist/snapping/resolveSnap.js +39 -0
  434. package/dist/snapping/resolveSnap.js.map +1 -0
  435. package/dist/sourceRate.d.ts +12 -0
  436. package/dist/sourceRate.d.ts.map +1 -0
  437. package/dist/sourceRate.js +13 -0
  438. package/dist/sourceRate.js.map +1 -0
  439. package/dist/spatialVideoRequest.d.ts +91 -0
  440. package/dist/spatialVideoRequest.d.ts.map +1 -0
  441. package/dist/spatialVideoRequest.js +175 -0
  442. package/dist/spatialVideoRequest.js.map +1 -0
  443. package/dist/splitClip.d.ts +3 -0
  444. package/dist/splitClip.d.ts.map +1 -0
  445. package/dist/splitClip.js +190 -0
  446. package/dist/splitClip.js.map +1 -0
  447. package/dist/stableSerialize.d.ts +11 -0
  448. package/dist/stableSerialize.d.ts.map +1 -0
  449. package/dist/stableSerialize.js +31 -0
  450. package/dist/stableSerialize.js.map +1 -0
  451. package/dist/staleSet.d.ts +41 -0
  452. package/dist/staleSet.d.ts.map +1 -0
  453. package/dist/staleSet.js +106 -0
  454. package/dist/staleSet.js.map +1 -0
  455. package/dist/storyboard.d.ts +221 -0
  456. package/dist/storyboard.d.ts.map +1 -0
  457. package/dist/storyboard.js +417 -0
  458. package/dist/storyboard.js.map +1 -0
  459. package/dist/subtitles.d.ts +61 -0
  460. package/dist/subtitles.d.ts.map +1 -0
  461. package/dist/subtitles.js +92 -0
  462. package/dist/subtitles.js.map +1 -0
  463. package/dist/takes.d.ts +76 -0
  464. package/dist/takes.d.ts.map +1 -0
  465. package/dist/takes.js +238 -0
  466. package/dist/takes.js.map +1 -0
  467. package/dist/timeRemap.d.ts +101 -0
  468. package/dist/timeRemap.d.ts.map +1 -0
  469. package/dist/timeRemap.js +183 -0
  470. package/dist/timeRemap.js.map +1 -0
  471. package/dist/trackOrder.d.ts +38 -0
  472. package/dist/trackOrder.d.ts.map +1 -0
  473. package/dist/trackOrder.js +54 -0
  474. package/dist/trackOrder.js.map +1 -0
  475. package/dist/transitionAtCut.d.ts +89 -0
  476. package/dist/transitionAtCut.d.ts.map +1 -0
  477. package/dist/transitionAtCut.js +217 -0
  478. package/dist/transitionAtCut.js.map +1 -0
  479. package/dist/trimClip.d.ts +13 -0
  480. package/dist/trimClip.d.ts.map +1 -0
  481. package/dist/trimClip.js +60 -0
  482. package/dist/trimClip.js.map +1 -0
  483. package/dist/types.d.ts +1772 -0
  484. package/dist/types.d.ts.map +1 -0
  485. package/dist/types.js +84 -0
  486. package/dist/types.js.map +1 -0
  487. package/fonts/BebasNeue-Regular.ttf +0 -0
  488. package/fonts/Inter-ExtraBold.ttf +0 -0
  489. package/fonts/Inter-Italic-Variable.ttf +0 -0
  490. package/fonts/Inter-SemiBold.ttf +0 -0
  491. package/fonts/Inter-Variable.ttf +0 -0
  492. package/fonts/JetBrainsMono-Italic-Variable.ttf +0 -0
  493. package/fonts/JetBrainsMono-Variable.ttf +0 -0
  494. package/fonts/Lora-Italic-Variable.ttf +0 -0
  495. package/fonts/Lora-Variable.ttf +0 -0
  496. package/fonts/OFL-BebasNeue.txt +93 -0
  497. package/fonts/OFL-Inter.txt +93 -0
  498. package/fonts/OFL-JetBrainsMono.txt +93 -0
  499. package/fonts/OFL-Lora.txt +93 -0
  500. package/fonts/OFL-PlayfairDisplay.txt +93 -0
  501. package/fonts/OFL-SpaceGrotesk.txt +93 -0
  502. package/fonts/PlayfairDisplay-Italic-Variable.ttf +0 -0
  503. package/fonts/PlayfairDisplay-Variable.ttf +0 -0
  504. package/fonts/SpaceGrotesk-Variable.ttf +0 -0
  505. package/package.json +108 -0
@@ -0,0 +1,1392 @@
1
+ /**
2
+ * canvas2d — the Canvas 2D compositing rules shared by every non-GPU render
3
+ * surface.
4
+ *
5
+ * {@link HeadlessFrameCompositor} is the GPU path; this is the same placement,
6
+ * opacity, blend, wipe and rounded-corner math expressed against a Canvas 2D
7
+ * context, so the browser's WebGPU fallback and the server-side frame preview
8
+ * draw one frame the same way. Written against {@link CompositeContext2D} — the
9
+ * subset of the Canvas 2D API these drawings need — for the reason `draw.ts` is
10
+ * written against `RasterContext2D`: one implementation serves an
11
+ * `OffscreenCanvas`, a DOM canvas and `@napi-rs/canvas`.
12
+ *
13
+ * Pixel effects run on a scratch surface shared by browser and Node hosts.
14
+ * If a host cannot provide that surface, the frame reports the degradation.
15
+ *
16
+ * A group carrying effects, a blend mode, or a transition composites its
17
+ * children onto an intermediate surface first, so the effect chain and cut
18
+ * run on the composed picture and the blend meets the frame once. The host vends that surface through
19
+ * {@link CompositeSurfaceFactory}, because there is no way to make one that
20
+ * exists in both a browser and Node.
21
+ *
22
+ * An adjustment reuses that machinery from the other end: at its own z it
23
+ * copies the surface it sits on, runs its chain on the copy, and mixes the copy
24
+ * back into the untreated composite by its coverage — so it treats everything
25
+ * drawn below it and nothing above, and replaces what it covers rather than
26
+ * lying over it.
27
+ */
28
+ import { blendModeToCanvasOp } from "@nodetool-ai/gpu";
29
+ import { cropRectPx, hasCrop } from "../crop.js";
30
+ import { isClipBlurEffect, isClipChromaKeyEffect, isClipColorEffect, isClipDropShadowEffect, isClipSharpenEffect, isClipVignetteEffect } from "../types.js";
31
+ import { clipMask, drawMask, maskIsHard } from "./draw.js";
32
+ import { applyCpuDropShadows, applyCpuIris, applyCpuVisualEffects, isCpuVisualEffect } from "./cpuVisualEffects.js";
33
+ import { alphaBounds, applyCpuColorGrade, applyCpuGaussianBlur, applyCpuLegacyEffects, isCpuLegacyEffect } from "./cpuLegacyEffects.js";
34
+ import { aggregateBlurRadius } from "./effects.js";
35
+ import { trackEffectsAsClipEffects } from "./trackEffects.js";
36
+ import { IDENTITY_TRANSFORM, buildTransformMatrix, clipMatrixToCanvasAffine, containBaseScale } from "./transform.js";
37
+ import { transitionTransform } from "./transition.js";
38
+ /**
39
+ * Effect types handled by the Canvas pixel path or a native draw operation.
40
+ */
41
+ const CANVAS_EFFECT_TYPES = new Set(["color", "blur", "dropShadow", "glow", "vignette", "sharpen", "chromaKey", "curves", "levels", "liftGammaGain", "grain", "pixelate", "posterize", "directionalBlur", "lensDistortion", "stylize", "generator", "lut"]);
42
+ function applyCpuEffectChain(pixels, clipEffects, trackEffects = []) {
43
+ const trackKey = trackEffects.find((effect) => effect.enabled && isClipChromaKeyEffect(effect) && effect.tolerance > 0.001);
44
+ if (trackKey)
45
+ applyCpuLegacyEffects(pixels, [trackKey]);
46
+ for (const effect of clipEffects) {
47
+ if (!effect.enabled)
48
+ continue;
49
+ if (isClipDropShadowEffect(effect))
50
+ applyCpuDropShadows(pixels, [effect]);
51
+ else if (isCpuVisualEffect(effect))
52
+ applyCpuVisualEffects(pixels, [effect]);
53
+ else if (isCpuLegacyEffect(effect))
54
+ applyCpuLegacyEffects(pixels, [effect]);
55
+ }
56
+ const combinedEffects = [...clipEffects, ...trackEffects];
57
+ const blurRadius = aggregateBlurRadius(clipEffects.filter((effect) => effect.enabled), trackEffects.filter((effect) => effect.enabled));
58
+ const sharedBounds = blurRadius >= 0.5 && combinedEffects.some((effect) => effect.enabled && isClipColorEffect(effect))
59
+ && pixels.data.length === pixels.width * pixels.height * 4
60
+ ? alphaBounds(pixels)
61
+ : undefined;
62
+ applyCpuColorGrade(pixels, combinedEffects, sharedBounds);
63
+ applyCpuGaussianBlur(pixels, blurRadius, sharedBounds);
64
+ const trackSharpen = trackEffects.find((effect) => effect.enabled && isClipSharpenEffect(effect) && effect.amount > 0.001);
65
+ const trackVignette = trackEffects.find((effect) => effect.enabled && isClipVignetteEffect(effect) && effect.amount > 0.001);
66
+ if (trackSharpen)
67
+ applyCpuLegacyEffects(pixels, [trackSharpen]);
68
+ if (trackVignette)
69
+ applyCpuLegacyEffects(pixels, [trackVignette]);
70
+ }
71
+ /**
72
+ * The effect types present on these layers that Canvas 2D cannot draw. A
73
+ * caller reports these rather than letting the frame quietly differ from the
74
+ * GPU render (I7).
75
+ *
76
+ * A group's effects run on its composed surface, not on any one layer, so a
77
+ * caller with precomposites passes them in too — `Canvas2DPrecomposite` carries
78
+ * `effects` for exactly that. An adjustment is the same case: its chain runs on
79
+ * the composite beneath it and belongs to no layer, so a caller passes its
80
+ * adjustments in as well. Leaving either out is how a group blur, or a keyed
81
+ * adjustment, that this path never applied would go unreported.
82
+ *
83
+ * A missing scratch surface is reported by the frame draw, because support
84
+ * depends on the host rather than the effect document.
85
+ */
86
+ export function unsupportedEffectTypes(layers) {
87
+ const found = new Set();
88
+ const scan = (effects) => {
89
+ for (const e of effects) {
90
+ if (!e.enabled)
91
+ continue;
92
+ if (!CANVAS_EFFECT_TYPES.has(e.type))
93
+ found.add(e.type);
94
+ }
95
+ };
96
+ for (const layer of layers) {
97
+ scan(layer.effects ?? []);
98
+ scan(trackEffectsAsClipEffects(layer.trackEffects));
99
+ }
100
+ return [...found].sort();
101
+ }
102
+ /**
103
+ * The 2D affine that places a layer of the given source size on the canvas,
104
+ * matching the GPU compositor's placement.
105
+ */
106
+ export function layerCanvasAffine(transform, sourceWidth, sourceHeight, geometry, parentMatrix) {
107
+ const { canvasWidth, canvasHeight } = geometry;
108
+ const base = containBaseScale(sourceWidth, sourceHeight, canvasWidth, canvasHeight);
109
+ const matrix = buildTransformMatrix(transform ?? IDENTITY_TRANSFORM, base, geometry.refWidth || canvasWidth, geometry.refHeight || canvasHeight, parentMatrix);
110
+ return clipMatrixToCanvasAffine(matrix, sourceWidth, sourceHeight, canvasWidth, canvasHeight);
111
+ }
112
+ /** Project a source pixel through the same matrix the GPU compositor reads. */
113
+ export function projectSourcePoint(matrix, x, y, sourceWidth, sourceHeight, canvasWidth, canvasHeight) {
114
+ const u = 2 * x / sourceWidth - 1;
115
+ const v = 1 - 2 * y / sourceHeight;
116
+ const w = matrix[3] * u + matrix[7] * v + matrix[15];
117
+ return {
118
+ x: canvasWidth * ((matrix[0] * u + matrix[4] * v + matrix[12]) / w + 1) / 2,
119
+ y: canvasHeight * (1 - (matrix[1] * u + matrix[5] * v + matrix[13]) / w) / 2
120
+ };
121
+ }
122
+ function drawProjectiveTriangle(ctx, source, sourceWidth, sourceHeight, sourcePoints, destPoints) {
123
+ const [p0, p1, p2] = sourcePoints;
124
+ const [q0, q1, q2] = destPoints;
125
+ const dx1 = p1.x - p0.x;
126
+ const dy1 = p1.y - p0.y;
127
+ const dx2 = p2.x - p0.x;
128
+ const dy2 = p2.y - p0.y;
129
+ const det = dx1 * dy2 - dx2 * dy1;
130
+ if (Math.abs(det) < 1e-9)
131
+ return;
132
+ const a = ((q1.x - q0.x) * dy2 - (q2.x - q0.x) * dy1) / det;
133
+ const c = ((q2.x - q0.x) * dx1 - (q1.x - q0.x) * dx2) / det;
134
+ const b = ((q1.y - q0.y) * dy2 - (q2.y - q0.y) * dy1) / det;
135
+ const d = ((q2.y - q0.y) * dx1 - (q1.y - q0.y) * dx2) / det;
136
+ // Canvas antialiases each independently clipped triangle. Adjacent clips
137
+ // can both leave subpixel coverage at their shared edge, exposing a dark
138
+ // diagonal through a projected card. Two pixels of overlap cover that edge
139
+ // even with a skewed clip; the affine image mapping stays put. The caller
140
+ // assembles these overlaps with copy, preserving the source's own alpha.
141
+ const centroidX = (q0.x + q1.x + q2.x) / 3;
142
+ const centroidY = (q0.y + q1.y + q2.y) / 3;
143
+ const clipPoint = (point) => {
144
+ const dx = point.x - centroidX;
145
+ const dy = point.y - centroidY;
146
+ const length = Math.hypot(dx, dy) || 1;
147
+ return { x: point.x + 2 * dx / length, y: point.y + 2 * dy / length };
148
+ };
149
+ const c0 = clipPoint(q0);
150
+ const c1 = clipPoint(q1);
151
+ const c2 = clipPoint(q2);
152
+ ctx.save();
153
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
154
+ ctx.beginPath();
155
+ ctx.moveTo(c0.x, c0.y);
156
+ ctx.lineTo(c1.x, c1.y);
157
+ ctx.lineTo(c2.x, c2.y);
158
+ ctx.closePath();
159
+ ctx.clip();
160
+ ctx.setTransform(a, b, c, d, q0.x - a * p0.x - c * p0.y, q0.y - b * p0.x - d * p0.y);
161
+ ctx.drawImage(source, 0, 0, sourceWidth, sourceHeight);
162
+ ctx.restore();
163
+ }
164
+ function drawProjectiveImage(ctx, source, sourceWidth, sourceHeight, matrix, geometry) {
165
+ const columns = Math.ceil(sourceWidth / 120);
166
+ const rows = Math.ceil(sourceHeight / 120);
167
+ for (let row = 0; row < rows; row += 1) {
168
+ for (let col = 0; col < columns; col += 1) {
169
+ const x0 = col * sourceWidth / columns;
170
+ const x1 = (col + 1) * sourceWidth / columns;
171
+ const y0 = row * sourceHeight / rows;
172
+ const y1 = (row + 1) * sourceHeight / rows;
173
+ const sourceCorners = [
174
+ { x: x0, y: y0 }, { x: x1, y: y0 }, { x: x1, y: y1 }, { x: x0, y: y1 }
175
+ ];
176
+ const destCorners = sourceCorners.map((point) => projectSourcePoint(matrix, point.x, point.y, sourceWidth, sourceHeight, geometry.canvasWidth, geometry.canvasHeight));
177
+ drawProjectiveTriangle(ctx, source, sourceWidth, sourceHeight, [sourceCorners[0], sourceCorners[1], sourceCorners[2]], [destCorners[0], destCorners[1], destCorners[2]]);
178
+ drawProjectiveTriangle(ctx, source, sourceWidth, sourceHeight, [sourceCorners[0], sourceCorners[2], sourceCorners[3]], [destCorners[0], destCorners[2], destCorners[3]]);
179
+ }
180
+ }
181
+ }
182
+ /** Sample the prepared source once per destination pixel, without tile clips. */
183
+ function rasterizeProjectiveImage(sourceCtx, destinationCtx, sourceWidth, sourceHeight, matrix, geometry) {
184
+ let sourcePixels;
185
+ try {
186
+ sourcePixels = sourceCtx.getImageData(0, 0, sourceWidth, sourceHeight);
187
+ }
188
+ catch {
189
+ // A cross-origin canvas may still draw, but it cannot be read back.
190
+ return "unreadable";
191
+ }
192
+ const source = sourcePixels.data;
193
+ let left = sourceWidth;
194
+ let top = sourceHeight;
195
+ let right = -1;
196
+ let bottom = -1;
197
+ for (let y = 0; y < sourceHeight; y++) {
198
+ for (let x = 0; x < sourceWidth; x++) {
199
+ if (source[(y * sourceWidth + x) * 4 + 3] === 0)
200
+ continue;
201
+ left = Math.min(left, x);
202
+ top = Math.min(top, y);
203
+ right = Math.max(right, x);
204
+ bottom = Math.max(bottom, y);
205
+ }
206
+ }
207
+ if (right < left)
208
+ return "drawn";
209
+ // A rational projection is unbounded when its homogeneous denominator
210
+ // changes sign across the visible source rectangle. Four corners cannot
211
+ // bound that image, so use the tessellated near-plane fallback.
212
+ const g = matrix[3], h = matrix[7], i = matrix[15];
213
+ const u0 = 2 * left / sourceWidth - 1;
214
+ const u1 = 2 * (right + 1) / sourceWidth - 1;
215
+ const v0 = 1 - 2 * top / sourceHeight;
216
+ const v1 = 1 - 2 * (bottom + 1) / sourceHeight;
217
+ const cornerW = [i + g * u0 + h * v0, i + g * u1 + h * v0,
218
+ i + g * u1 + h * v1, i + g * u0 + h * v1];
219
+ if (Math.min(...cornerW) <= 1e-5 && Math.max(...cornerW) >= -1e-5) {
220
+ return "near_plane";
221
+ }
222
+ const corners = [
223
+ projectSourcePoint(matrix, left, top, sourceWidth, sourceHeight, geometry.canvasWidth, geometry.canvasHeight),
224
+ projectSourcePoint(matrix, right + 1, top, sourceWidth, sourceHeight, geometry.canvasWidth, geometry.canvasHeight),
225
+ projectSourcePoint(matrix, right + 1, bottom + 1, sourceWidth, sourceHeight, geometry.canvasWidth, geometry.canvasHeight),
226
+ projectSourcePoint(matrix, left, bottom + 1, sourceWidth, sourceHeight, geometry.canvasWidth, geometry.canvasHeight)
227
+ ];
228
+ if (corners.some((corner) => !Number.isFinite(corner.x) || !Number.isFinite(corner.y)))
229
+ return "unreadable";
230
+ const x0 = Math.max(0, Math.floor(Math.min(...corners.map((corner) => corner.x))) - 1);
231
+ const y0 = Math.max(0, Math.floor(Math.min(...corners.map((corner) => corner.y))) - 1);
232
+ const x1 = Math.min(geometry.canvasWidth, Math.ceil(Math.max(...corners.map((corner) => corner.x))) + 1);
233
+ const y1 = Math.min(geometry.canvasHeight, Math.ceil(Math.max(...corners.map((corner) => corner.y))) + 1);
234
+ if (x1 <= x0 || y1 <= y0)
235
+ return "drawn";
236
+ const pixels = destinationCtx.getImageData(x0, y0, x1 - x0, y1 - y0);
237
+ const output = pixels.data;
238
+ const a = matrix[0], b = matrix[4], c = matrix[12];
239
+ const d = matrix[1], e = matrix[5], f = matrix[13];
240
+ for (let y = y0; y < y1; y++) {
241
+ const normalizedY = 1 - 2 * (y + 0.5) / geometry.canvasHeight;
242
+ for (let x = x0; x < x1; x++) {
243
+ const normalizedX = 2 * (x + 0.5) / geometry.canvasWidth - 1;
244
+ const aa = a - normalizedX * g;
245
+ const bb = b - normalizedX * h;
246
+ const dd = d - normalizedY * g;
247
+ const ee = e - normalizedY * h;
248
+ const determinant = aa * ee - bb * dd;
249
+ if (Math.abs(determinant) < 1e-12)
250
+ continue;
251
+ const cc = normalizedX * i - c;
252
+ const ff = normalizedY * i - f;
253
+ const u = (cc * ee - bb * ff) / determinant;
254
+ const v = (aa * ff - cc * dd) / determinant;
255
+ const sourceX = (u + 1) * sourceWidth / 2 - 0.5;
256
+ const sourceY = (1 - v) * sourceHeight / 2 - 0.5;
257
+ const sampleX = Math.floor(sourceX);
258
+ const sampleY = Math.floor(sourceY);
259
+ const fractionX = sourceX - sampleX;
260
+ const fractionY = sourceY - sampleY;
261
+ let alpha = 0;
262
+ let red = 0;
263
+ let green = 0;
264
+ let blue = 0;
265
+ for (let row = 0; row < 2; row++) {
266
+ const sy = sampleY + row;
267
+ if (sy < 0 || sy >= sourceHeight)
268
+ continue;
269
+ for (let col = 0; col < 2; col++) {
270
+ const sx = sampleX + col;
271
+ if (sx < 0 || sx >= sourceWidth)
272
+ continue;
273
+ const weight = (col ? fractionX : 1 - fractionX) * (row ? fractionY : 1 - fractionY);
274
+ const sourceOffset = (sy * sourceWidth + sx) * 4;
275
+ const weightedAlpha = source[sourceOffset + 3] * weight;
276
+ alpha += weightedAlpha;
277
+ red += source[sourceOffset] * weightedAlpha;
278
+ green += source[sourceOffset + 1] * weightedAlpha;
279
+ blue += source[sourceOffset + 2] * weightedAlpha;
280
+ }
281
+ }
282
+ if (alpha <= 0)
283
+ continue;
284
+ const offset = ((y - y0) * pixels.width + x - x0) * 4;
285
+ output[offset] = red / alpha;
286
+ output[offset + 1] = green / alpha;
287
+ output[offset + 2] = blue / alpha;
288
+ output[offset + 3] = alpha;
289
+ }
290
+ }
291
+ destinationCtx.putImageData(pixels, x0, y0);
292
+ return "drawn";
293
+ }
294
+ /** Reset a context to the state each layer draw assumes. */
295
+ function resetContext(ctx) {
296
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
297
+ ctx.globalAlpha = 1;
298
+ ctx.globalCompositeOperation = "source-over";
299
+ ctx.filter = "none";
300
+ clearShadow(ctx);
301
+ }
302
+ /** Turn the shadow off. A left-on shadow follows every later draw. */
303
+ function clearShadow(ctx) {
304
+ ctx.shadowColor = "rgba(0, 0, 0, 0)";
305
+ ctx.shadowBlur = 0;
306
+ ctx.shadowOffsetX = 0;
307
+ ctx.shadowOffsetY = 0;
308
+ }
309
+ /**
310
+ * Composite `layers` onto `ctx`, bottom-up by `zIndex`, over an opaque black
311
+ * ground — the same clear the GPU compositor starts from, and with
312
+ * `options.alpha` the same transparent one. The context is left in the reset
313
+ * state. Returns the layers that drew nothing and every way this frame differs
314
+ * from the GPU render, both in composite order.
315
+ *
316
+ * A layer naming a precomposite in `options.precomposites` draws onto that
317
+ * group's own surface first, and the surface blends once at the group's z. With
318
+ * no precomposites the layers go straight onto `ctx` and no surface is asked
319
+ * for at all.
320
+ *
321
+ * An adjustment in `options.adjustments` runs at its own z on the surface it
322
+ * names — the frame, or the group's — treating what is already on it.
323
+ */
324
+ export function drawTimelineFrame(ctx, layers, geometry, options = {}) {
325
+ // A projective layer needs its prepared source and its warped result at the
326
+ // same time, but the next layer does not. Reuse that pair for every layer of
327
+ // the same size instead of retaining two full-frame surfaces per card.
328
+ const projectiveFactory = options.projectiveSurface;
329
+ const projectivePool = new Map();
330
+ const projectiveUses = new Map();
331
+ const frameOptions = projectiveFactory
332
+ ? {
333
+ ...options,
334
+ projectiveSurface: (width, height) => {
335
+ const key = `${width}x${height}`;
336
+ const slot = (projectiveUses.get(key) ?? 0) % 2;
337
+ projectiveUses.set(key, slot + 1);
338
+ const pair = projectivePool.get(key) ?? [];
339
+ const existing = pair[slot];
340
+ if (existing)
341
+ return existing;
342
+ const surface = projectiveFactory(width, height);
343
+ if (surface) {
344
+ pair[slot] = surface;
345
+ projectivePool.set(key, pair);
346
+ }
347
+ return surface;
348
+ }
349
+ }
350
+ : options;
351
+ resetContext(ctx);
352
+ if (options.alpha === true) {
353
+ ctx.clearRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
354
+ }
355
+ else {
356
+ ctx.fillStyle = "#000";
357
+ ctx.fillRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
358
+ }
359
+ const skipped = [];
360
+ const degraded = [];
361
+ const onFrame = [];
362
+ const groupIds = new Set((options.precomposites ?? []).map((g) => g.id));
363
+ for (const adjustment of options.adjustments ?? []) {
364
+ const groupId = adjustment.precomposeGroupId;
365
+ if (!groupId) {
366
+ onFrame.push(adjustment);
367
+ }
368
+ else if (!groupIds.has(groupId)) {
369
+ // Scoped to a surface this frame does not build. Running it on the frame
370
+ // instead would treat layers outside the group it belongs to.
371
+ degraded.push({ clipId: adjustment.clipId, reason: "adjustment_skipped" });
372
+ }
373
+ }
374
+ const stack = composePrecomposites(layers, geometry, frameOptions, skipped, degraded);
375
+ drawStack(ctx, stack, onFrame, geometry, frameOptions, skipped, degraded);
376
+ resetContext(ctx);
377
+ return { skipped, degraded };
378
+ }
379
+ /**
380
+ * Draw one surface's contents bottom-up: its layers and the adjustments that
381
+ * treat it, interleaved by `zIndex`.
382
+ *
383
+ * An adjustment at the same z as a layer runs *after* it — the layer is beneath
384
+ * it in draw order, so it is part of the composite the treatment reads. That
385
+ * falls out of a stable sort over layers-then-adjustments, which is why the two
386
+ * are concatenated in that order and not merged some other way.
387
+ */
388
+ function drawStack(ctx, layers, adjustments, geometry, options, skipped, degraded) {
389
+ const items = layers.map((layer) => ({
390
+ layer,
391
+ zIndex: layer.zIndex
392
+ }));
393
+ for (const adjustment of adjustments) {
394
+ items.push({ adjustment, zIndex: adjustment.zIndex });
395
+ }
396
+ for (const item of items.sort((a, b) => {
397
+ const z = a.zIndex - b.zIndex;
398
+ if (z !== 0)
399
+ return z;
400
+ const first = a.layer?.stackOrder;
401
+ const second = b.layer?.stackOrder;
402
+ if (first === second)
403
+ return 0;
404
+ return (first ?? Number.POSITIVE_INFINITY) - (second ?? Number.POSITIVE_INFINITY);
405
+ })) {
406
+ if (item.adjustment) {
407
+ applyAdjustment(ctx, item.adjustment, geometry, options, degraded);
408
+ continue;
409
+ }
410
+ if (!drawTimelineLayer(ctx, item.layer, geometry, options, degraded)) {
411
+ skipped.push(item.layer);
412
+ }
413
+ }
414
+ }
415
+ /**
416
+ * Run one adjustment on `ctx`: copy the composite so far, treat the copy, and
417
+ * mix the treated picture back into the untreated one by the adjustment's
418
+ * coverage (T24).
419
+ *
420
+ * The copy goes through `getImageData`/`putImageData` rather than a
421
+ * `drawImage`: a host hands over a context, not a drawable handle on the
422
+ * surface behind it, so the pixels are the only way to reach what has been
423
+ * drawn. Brightness is added on the copy for the reason it is added on a
424
+ * layer's scratch — the GPU grade adds where CSS `brightness()` multiplies —
425
+ * and the rest of the chain rides the filter of the draw back.
426
+ *
427
+ * **A treatment replaces the composite, it does not lie on top of it.** With
428
+ * `c` the coverage — the adjustment's opacity times its mask times its wipe —
429
+ * every premultiplied channel, alpha included, ends at
430
+ * `original * (1 - c) + treated * c`. The copy carries the accumulation's own
431
+ * alpha, so drawing it back `source-over` added that alpha to itself: a
432
+ * 50%-opaque pixel under a fully applied neutral chain came back at 75%, which
433
+ * thickened every softened edge inside a group surface and every alpha export
434
+ * (F3). So the composite is cleared where the treatment lands and the treated
435
+ * copy drawn onto the cleared ground, which replaces rather than adds; anything
436
+ * short of full coverage is then mixed back into the snapshot by
437
+ * {@link mixTreatment}. Full coverage skips the mix, and over an opaque frame
438
+ * that case is byte-for-byte the draw it was.
439
+ *
440
+ * Both draws are `source-over`, and the coverage is arithmetic rather than a
441
+ * `destination-out` + `lighter` pair, because `@napi-rs/canvas` applies both a
442
+ * source's alpha and `ctx.filter` twice under any other composite operation —
443
+ * `destination-out` at 0.5 erases a quarter, and `copy` with `contrast(2)`
444
+ * lands a 40% grey on white. A coverage or a grade carried by a composite
445
+ * operation would render differently on the server than in a browser.
446
+ *
447
+ * The clip is what keeps a hard mask or wipe out of both draws, and the mix
448
+ * needs no second opinion about it: outside the clip the surface still holds
449
+ * the snapshot, and mixing a pixel with itself returns it unchanged.
450
+ */
451
+ function applyAdjustment(ctx, adjustment, geometry, surfaces, degraded) {
452
+ const { canvasWidth: w, canvasHeight: h } = geometry;
453
+ const scratch = surfaces.adjustmentSurface?.(w, h);
454
+ if (!scratch) {
455
+ degraded.push({ clipId: adjustment.clipId, reason: "adjustment_skipped" });
456
+ return;
457
+ }
458
+ const original = ctx.getImageData(0, 0, w, h);
459
+ const sctx = scratch.ctx;
460
+ resetContext(sctx);
461
+ sctx.clearRect(0, 0, w, h);
462
+ sctx.putImageData(original, 0, 0);
463
+ const pixelEffects = (adjustment.effects ?? []).filter((effect) => effect.enabled);
464
+ if (pixelEffects.length > 0) {
465
+ const pixels = sctx.getImageData(0, 0, w, h);
466
+ applyCpuEffectChain(pixels, pixelEffects);
467
+ sctx.putImageData(pixels, 0, 0);
468
+ }
469
+ // A soft mask and a feathered wipe rasterize their coverage together on one
470
+ // surface, because the mix needs `mask * wipe` as one number per pixel. A
471
+ // hard edge is a path clip on the draws instead, which costs nothing. Same
472
+ // split as a layer's.
473
+ const shape = adjustment.mask;
474
+ const wipe = adjustment.wipe;
475
+ const softShape = shape !== undefined && !maskIsHard(shape);
476
+ const softWipe = wipe !== undefined && wipe.softness > 0;
477
+ let coverage = null;
478
+ if (softShape || softWipe) {
479
+ const surface = surfaces.maskSurface?.(w, h);
480
+ if (surface && surface.surface !== scratch.surface) {
481
+ const cctx = surface.ctx;
482
+ resetContext(cctx);
483
+ cctx.clearRect(0, 0, w, h);
484
+ let painted = true;
485
+ if (softShape) {
486
+ painted = drawMask(cctx, shape, w, h);
487
+ }
488
+ else {
489
+ cctx.fillStyle = "#fff";
490
+ cctx.fillRect(0, 0, w, h);
491
+ }
492
+ if (painted) {
493
+ if (softWipe)
494
+ applyWipeGradient(cctx, w, h, wipe);
495
+ coverage = cctx.getImageData(0, 0, w, h);
496
+ }
497
+ }
498
+ if (!coverage) {
499
+ // Both feathers fall back to the hard edge the clip draws, and both are
500
+ // reported: a caller cannot see which one it lost otherwise.
501
+ if (softShape) {
502
+ degraded.push({ clipId: adjustment.clipId, reason: "mask_hard_edge" });
503
+ }
504
+ if (softWipe) {
505
+ degraded.push({ clipId: adjustment.clipId, reason: "wipe_hard_edge" });
506
+ }
507
+ }
508
+ }
509
+ const maskRasterized = coverage !== null && softShape;
510
+ const wipeRasterized = coverage !== null && softWipe;
511
+ const opacity = Math.max(0, Math.min(1, adjustment.opacity));
512
+ ctx.save();
513
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
514
+ ctx.globalAlpha = 1;
515
+ if (shape && !maskRasterized)
516
+ clipMask(ctx, shape, w, h);
517
+ if (wipe && !wipeRasterized)
518
+ clipWipeRect(ctx, w, h, wipe);
519
+ ctx.globalCompositeOperation = "source-over";
520
+ let treated = true;
521
+ try {
522
+ // Cleared first: over transparency a source-over draw *is* the source, so
523
+ // what lands is the treated picture and not the treated picture over the
524
+ // one it was copied from. The chain is armed after the clear, so no host
525
+ // can read it as something to run on one.
526
+ ctx.clearRect(0, 0, w, h);
527
+ ctx.filter = "none";
528
+ ctx.drawImage(scratch.surface, 0, 0, w, h);
529
+ }
530
+ catch {
531
+ // The host's surface refused to draw. The snapshot the copy was made from
532
+ // puts the untreated composite back, which is the same outcome as vending
533
+ // no surface at all.
534
+ treated = false;
535
+ }
536
+ if (treated && (opacity < 1 || coverage)) {
537
+ const mixed = ctx.getImageData(0, 0, w, h);
538
+ mixTreatment(original, mixed, coverage, opacity);
539
+ ctx.putImageData(mixed, 0, 0);
540
+ }
541
+ ctx.restore();
542
+ resetContext(ctx);
543
+ if (!treated) {
544
+ ctx.putImageData(original, 0, 0);
545
+ degraded.push({ clipId: adjustment.clipId, reason: "adjustment_skipped" });
546
+ }
547
+ }
548
+ /**
549
+ * Mix the treated picture into the original by the treatment's coverage, in
550
+ * place in `treated`: `out = original * (1 - c) + treated * c` on every
551
+ * premultiplied channel, alpha included, where `c` is `opacity` times the
552
+ * coverage raster's alpha.
553
+ *
554
+ * Premultiplied, because that is the space a composite is a linear mix in —
555
+ * mixing straight colours would let a nearly transparent original drag the
556
+ * treated colour toward whatever it happens to carry under its zero alpha.
557
+ * `ImagePixels` is straight alpha at both ends, so the multiply in and the
558
+ * divide out are here.
559
+ *
560
+ * The two ends are byte-exact: `c >= 1` keeps the treated pixel and `c <= 0`
561
+ * restores the original one, rather than rounding through the arithmetic.
562
+ */
563
+ function mixTreatment(original, treated, coverage, opacity) {
564
+ const src = original.data;
565
+ const out = treated.data;
566
+ const cov = coverage?.data;
567
+ for (let i = 0; i < out.length; i += 4) {
568
+ const c = cov ? (opacity * cov[i + 3]) / 255 : opacity;
569
+ if (c >= 1)
570
+ continue;
571
+ if (c <= 0) {
572
+ out[i] = src[i];
573
+ out[i + 1] = src[i + 1];
574
+ out[i + 2] = src[i + 2];
575
+ out[i + 3] = src[i + 3];
576
+ continue;
577
+ }
578
+ const oa = src[i + 3] / 255;
579
+ const ta = out[i + 3] / 255;
580
+ const keep = oa * (1 - c);
581
+ const take = ta * c;
582
+ const alpha = keep + take;
583
+ if (alpha <= 0) {
584
+ out[i] = 0;
585
+ out[i + 1] = 0;
586
+ out[i + 2] = 0;
587
+ out[i + 3] = 0;
588
+ continue;
589
+ }
590
+ for (let k = 0; k < 3; k++) {
591
+ out[i + k] = Math.round((src[i + k] * keep + out[i + k] * take) / alpha);
592
+ }
593
+ out[i + 3] = Math.round(alpha * 255);
594
+ }
595
+ }
596
+ /**
597
+ * Draw each precompositing group onto its own surface and return the main
598
+ * stack: the layers that belong to no group, plus one layer per group whose
599
+ * surface blends onto the frame.
600
+ *
601
+ * `options.precomposites` arrives innermost first, so a nested group has
602
+ * already handed its composed surface to the group above by the time that one
603
+ * draws. With no groups this hands the layers straight back and never calls the
604
+ * surface factory — the whole point of gating the intermediate on a group
605
+ * actually carrying effects or a blend mode.
606
+ */
607
+ function composePrecomposites(layers, geometry, options, skipped, degraded) {
608
+ const groups = options.precomposites ?? [];
609
+ if (groups.length === 0)
610
+ return [...layers];
611
+ const stack = [];
612
+ const byGroup = new Map();
613
+ const assign = (groupId, layer) => {
614
+ if (!groupId) {
615
+ stack.push(layer);
616
+ return;
617
+ }
618
+ const bucket = byGroup.get(groupId);
619
+ if (bucket)
620
+ bucket.push(layer);
621
+ else
622
+ byGroup.set(groupId, [layer]);
623
+ };
624
+ for (const layer of layers)
625
+ assign(layer.precomposeGroupId, layer);
626
+ // An adjustment inside a group treats that group's own surface, so it runs
627
+ // with the group's children and reaches nothing outside them.
628
+ const adjustmentsByGroup = new Map();
629
+ for (const adjustment of options.adjustments ?? []) {
630
+ const groupId = adjustment.precomposeGroupId;
631
+ if (!groupId)
632
+ continue;
633
+ const bucket = adjustmentsByGroup.get(groupId);
634
+ if (bucket)
635
+ bucket.push(adjustment);
636
+ else
637
+ adjustmentsByGroup.set(groupId, [adjustment]);
638
+ }
639
+ for (const group of groups) {
640
+ const children = byGroup.get(group.id) ?? [];
641
+ const treatments = adjustmentsByGroup.get(group.id) ?? [];
642
+ const surface = children.length > 0
643
+ ? (options.precompositeSurface?.(geometry.canvasWidth, geometry.canvasHeight) ?? null)
644
+ : null;
645
+ if (!surface) {
646
+ // Nothing to compose, or no surface to compose it on. Either way the
647
+ // children draw where they would have without the group: the picture
648
+ // survives and the group's effects and blend mode do not. A group with
649
+ // nothing on screen lost nothing, so only the second case is reported.
650
+ if (children.length > 0) {
651
+ degraded.push({ clipId: group.id, reason: "group_blend_lost" });
652
+ }
653
+ // The treatments go with the surface they were scoped to. Running them on
654
+ // the stack beneath would treat layers outside the group.
655
+ for (const treatment of treatments) {
656
+ degraded.push({
657
+ clipId: treatment.clipId,
658
+ reason: "adjustment_skipped"
659
+ });
660
+ }
661
+ for (const child of children)
662
+ assign(group.precomposeGroupId, child);
663
+ continue;
664
+ }
665
+ const sctx = surface.ctx;
666
+ resetContext(sctx);
667
+ sctx.clearRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
668
+ drawStack(sctx, children, treatments, geometry, options, skipped, degraded);
669
+ // The surface is frame-sized, so it composites untransformed: the group's
670
+ // own matrix already rode into each child through `parentMatrix`.
671
+ assign(group.precomposeGroupId, {
672
+ source: surface.surface,
673
+ sourceWidth: geometry.canvasWidth,
674
+ sourceHeight: geometry.canvasHeight,
675
+ opacity: group.opacity,
676
+ blendMode: group.blendMode,
677
+ zIndex: group.zIndex,
678
+ stackOrder: group.stackOrder,
679
+ effects: group.effects,
680
+ transition: group.transition
681
+ });
682
+ }
683
+ return stack;
684
+ }
685
+ /**
686
+ * Draw one layer with its transform, opacity, blend mode, effect filter,
687
+ * rounded corners and wipe mask. Assumes the context is in the reset state and
688
+ * leaves it that way.
689
+ *
690
+ * Returns false when the layer contributed nothing — a degenerate source size,
691
+ * or a source the host handed over that turned out not to be drawable (a
692
+ * `<video>` that began seeking between the readiness check and this call).
693
+ * A live preview ignores that and re-draws next frame; a one-shot render
694
+ * reports it, because there a missing layer is a missing layer.
695
+ */
696
+ export function drawTimelineLayer(ctx, layer, geometry, surfaces = {}, degraded = []) {
697
+ const cropped = cropLayerSource(layer, surfaces, degraded);
698
+ let { source: layerSource } = cropped;
699
+ const { width, height } = cropped;
700
+ if (width <= 0 || height <= 0)
701
+ return false;
702
+ const clipEffects = [
703
+ ...(layer.effects ?? []),
704
+ ...(layer.transition?.effect ? [layer.transition.effect] : [])
705
+ ].filter((effect) => effect.enabled);
706
+ const trackEffects = trackEffectsAsClipEffects(layer.trackEffects).filter((effect) => effect.enabled);
707
+ const shadows = (layer.effects ?? []).filter((effect) => effect.enabled && isClipDropShadowEffect(effect));
708
+ let stackedShadows = false;
709
+ let cpuTreated = false;
710
+ const iris = layer.transition?.iris;
711
+ if (clipEffects.some((effect) => !isClipDropShadowEffect(effect)) || trackEffects.length > 0 || iris || shadows.length > 1) {
712
+ const surface = surfaces.effectSurface?.(width, height);
713
+ if (surface) {
714
+ const ectx = surface.ctx;
715
+ resetContext(ectx);
716
+ ectx.clearRect(0, 0, width, height);
717
+ ectx.drawImage(layerSource, 0, 0, width, height);
718
+ const pixels = ectx.getImageData(0, 0, width, height);
719
+ applyCpuEffectChain(pixels, clipEffects, trackEffects);
720
+ stackedShadows = shadows.length > 0;
721
+ if (iris)
722
+ applyCpuIris(pixels, iris.progress, iris.softness);
723
+ ectx.putImageData(pixels, 0, 0);
724
+ layerSource = surface.surface;
725
+ cpuTreated = true;
726
+ }
727
+ else {
728
+ degraded.push({ clipId: layer.clipId, reason: "effect_surface_missing" });
729
+ }
730
+ }
731
+ if (layer.matte) {
732
+ const matted = drawMattedLayer(ctx, layer, layer.matte, geometry, surfaces, degraded);
733
+ // Null means the host vended no surfaces to compose the matte on; the
734
+ // layer then draws unmatted rather than not at all.
735
+ if (matted !== null)
736
+ return matted;
737
+ degraded.push({ clipId: layer.clipId, reason: "matte_skipped" });
738
+ }
739
+ const transition = layer.transition;
740
+ const resolvedTransform = transitionTransform(layer.transform, transition, geometry.refWidth || geometry.canvasWidth, geometry.refHeight || geometry.canvasHeight);
741
+ const placement = buildTransformMatrix(resolvedTransform ?? IDENTITY_TRANSFORM, containBaseScale(width, height, geometry.canvasWidth, geometry.canvasHeight), geometry.refWidth || geometry.canvasWidth, geometry.refHeight || geometry.canvasHeight, layer.parentMatrix);
742
+ const projective = placement[3] !== 0 || placement[7] !== 0;
743
+ const t = clipMatrixToCanvasAffine(placement, width, height, geometry.canvasWidth, geometry.canvasHeight);
744
+ // A dip goes through the colour, so the solid covers the whole frame rather
745
+ // than the layer — drawn here, immediately under the incoming clip, so the
746
+ // outgoing clip beneath is what it hides.
747
+ const solid = transition?.solid;
748
+ if (solid && solid.opacity > 0) {
749
+ ctx.save();
750
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
751
+ ctx.globalAlpha = Math.min(1, solid.opacity);
752
+ ctx.globalCompositeOperation = "source-over";
753
+ ctx.filter = "none";
754
+ ctx.fillStyle = solid.color;
755
+ ctx.fillRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
756
+ ctx.restore();
757
+ }
758
+ ctx.save();
759
+ ctx.globalAlpha = Math.max(0, Math.min(1, layer.opacity));
760
+ ctx.globalCompositeOperation = blendModeToCanvasOp(layer.blendMode);
761
+ if (!projective)
762
+ ctx.setTransform(t.a, t.b, t.c, t.d, t.e, t.f);
763
+ const radiusPx = layer.borderRadius ?? 0;
764
+ if (radiusPx > 0 && !projective) {
765
+ clipRoundedRect(ctx, 0, 0, width, height, Math.min(radiusPx, width / 2, height / 2));
766
+ }
767
+ // Both masks live in the layer's own source-pixel space, so they rotate with
768
+ // the layer exactly as the GPU shader's quad-space mask does. Hard edges are
769
+ // path clips and cost nothing; soft ones pre-mask the source on a scratch
770
+ // surface with `destination-in`, which is also what lets a shape mask and a
771
+ // wipe compose without a second copy.
772
+ let source = layerSource;
773
+ // An animated wipe on the clip and a wipe transition both reduce to one
774
+ // reveal; the clip's own wins, because it is the motion the author put there.
775
+ const wipe = layer.mask ?? transition?.mask;
776
+ const shape = layer.shapeMask;
777
+ const softWipe = wipe !== undefined && wipe.softness > 0;
778
+ const softShape = shape !== undefined && !maskIsHard(shape);
779
+ const brightness = cpuTreated ? 0 : brightnessForEffects(layer.effects, layer.trackEffects);
780
+ const lifts = Math.abs(brightness) > 0.001;
781
+ let applied = { shape: false, wipe: false, brightness: false };
782
+ if (softWipe || softShape || lifts) {
783
+ const prepared = prepareSource(layerSource, width, height, wipe, shape, lifts ? brightness : 0, surfaces);
784
+ if (prepared) {
785
+ source = prepared.surface;
786
+ applied = prepared;
787
+ }
788
+ }
789
+ if (projective) {
790
+ const target = surfaces.projectiveSurface?.(width, height);
791
+ if (target) {
792
+ const pctx = target.ctx;
793
+ pctx.save();
794
+ pctx.setTransform(1, 0, 0, 1, 0, 0);
795
+ pctx.clearRect(0, 0, width, height);
796
+ if (radiusPx > 0)
797
+ clipRoundedRect(pctx, 0, 0, width, height, Math.min(radiusPx, width / 2, height / 2));
798
+ if (shape && !applied.shape)
799
+ clipMask(pctx, shape, width, height);
800
+ if (wipe && !applied.wipe)
801
+ clipWipeRect(pctx, width, height, wipe);
802
+ pctx.filter = cpuTreated ? "none" : filterForEffects(layer.effects, layer.trackEffects, applied.brightness);
803
+ pctx.drawImage(source, 0, 0, width, height);
804
+ pctx.restore();
805
+ if (countDropShadows(layer.effects) > 0 && !stackedShadows) {
806
+ const shadowSurface = surfaces.projectiveSurface?.(geometry.canvasWidth, geometry.canvasHeight);
807
+ if (shadowSurface) {
808
+ const sctx = shadowSurface.ctx;
809
+ sctx.save();
810
+ sctx.setTransform(1, 0, 0, 1, 0, 0);
811
+ sctx.clearRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
812
+ sctx.filter = "none";
813
+ sctx.globalAlpha = 1;
814
+ const rasterResult = rasterizeProjectiveImage(pctx, sctx, width, height, placement, geometry);
815
+ if (rasterResult !== "drawn") {
816
+ drawProjectiveImage(sctx, target.surface, width, height, placement, geometry);
817
+ if (rasterResult === "near_plane") {
818
+ degraded.push({ clipId: layer.clipId, reason: "perspective_near_plane_fallback" });
819
+ }
820
+ }
821
+ sctx.restore();
822
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
823
+ ctx.filter = "none";
824
+ applyDropShadow(ctx, layer.effects, t);
825
+ ctx.drawImage(shadowSurface.surface, 0, 0, geometry.canvasWidth, geometry.canvasHeight);
826
+ if (countDropShadows(layer.effects) > 1)
827
+ degraded.push({ clipId: layer.clipId, reason: "drop_shadow_extra_ignored" });
828
+ }
829
+ else {
830
+ drawProjectiveImage(ctx, target.surface, width, height, placement, geometry);
831
+ degraded.push({ clipId: layer.clipId, reason: "drop_shadow_skipped" });
832
+ }
833
+ }
834
+ else {
835
+ // Assemble the perspective image at full opacity, then blend it once
836
+ // at the layer's opacity. Canvas triangle clips leave seams in some
837
+ // browsers even when their paths overlap, so sample the inverse
838
+ // projective mapping directly when the prepared source is readable.
839
+ const projected = surfaces.projectiveSurface?.(geometry.canvasWidth, geometry.canvasHeight);
840
+ if (projected) {
841
+ const projectedCtx = projected.ctx;
842
+ projectedCtx.save();
843
+ projectedCtx.setTransform(1, 0, 0, 1, 0, 0);
844
+ projectedCtx.clearRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
845
+ projectedCtx.filter = "none";
846
+ projectedCtx.globalAlpha = 1;
847
+ const rasterResult = rasterizeProjectiveImage(pctx, projectedCtx, width, height, placement, geometry);
848
+ if (rasterResult !== "drawn") {
849
+ drawProjectiveImage(projectedCtx, target.surface, width, height, placement, geometry);
850
+ if (rasterResult === "near_plane") {
851
+ degraded.push({ clipId: layer.clipId, reason: "perspective_near_plane_fallback" });
852
+ }
853
+ }
854
+ projectedCtx.restore();
855
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
856
+ ctx.drawImage(projected.surface, 0, 0, geometry.canvasWidth, geometry.canvasHeight);
857
+ }
858
+ else {
859
+ drawProjectiveImage(ctx, target.surface, width, height, placement, geometry);
860
+ }
861
+ }
862
+ ctx.restore();
863
+ resetContext(ctx);
864
+ return true;
865
+ }
866
+ degraded.push({ clipId: layer.clipId, reason: "perspective_skipped" });
867
+ ctx.setTransform(t.a, t.b, t.c, t.d, t.e, t.f);
868
+ if (radiusPx > 0)
869
+ clipRoundedRect(ctx, 0, 0, width, height, Math.min(radiusPx, width / 2, height / 2));
870
+ }
871
+ // Whatever the scratch pass did not take is drawn as a hard edge at the same
872
+ // geometry, which is the honest fallback when the host vends no surface.
873
+ if (shape && !applied.shape)
874
+ clipMask(ctx, shape, width, height);
875
+ if (wipe && !applied.wipe)
876
+ clipWipeRect(ctx, width, height, wipe);
877
+ if (softShape && !applied.shape) {
878
+ degraded.push({ clipId: layer.clipId, reason: "mask_hard_edge" });
879
+ }
880
+ if (softWipe && !applied.wipe) {
881
+ degraded.push({ clipId: layer.clipId, reason: "wipe_hard_edge" });
882
+ }
883
+ if (lifts && !applied.brightness) {
884
+ degraded.push({ clipId: layer.clipId, reason: "brightness_multiplicative" });
885
+ }
886
+ ctx.filter = cpuTreated ? "none" : filterForEffects(layer.effects, layer.trackEffects, applied.brightness);
887
+ if (!stackedShadows)
888
+ applyDropShadow(ctx, layer.effects, t);
889
+ if (countDropShadows(layer.effects) > 1 && !stackedShadows) {
890
+ degraded.push({
891
+ clipId: layer.clipId,
892
+ reason: "drop_shadow_extra_ignored"
893
+ });
894
+ }
895
+ let drawn = true;
896
+ try {
897
+ ctx.drawImage(source, 0, 0, width, height);
898
+ }
899
+ catch {
900
+ drawn = false;
901
+ }
902
+ ctx.restore();
903
+ resetContext(ctx);
904
+ return drawn;
905
+ }
906
+ /**
907
+ * The picture a layer actually draws, and its size: the crop rectangle copied
908
+ * onto its own surface, or the layer's own source when there is nothing to crop.
909
+ *
910
+ * The copy is what makes a crop reframe rather than knock out — every caller
911
+ * downstream treats the returned size as the layer's source size, so the
912
+ * contain fit, the transform, the border radius and the masks all act on the
913
+ * cropped frame. Drawing the whole source at a negative offset onto a surface
914
+ * the size of the crop is the 5-argument `drawImage` spelling of a sub-rectangle
915
+ * blit, which is all {@link CompositeContext2D} vends.
916
+ *
917
+ * A host that vends no `cropSurface` gets the uncropped layer and a
918
+ * `crop_skipped` report, the same call {@link drawMattedLayer} makes: the
919
+ * picture is wrong in a way the caller is told about, rather than absent.
920
+ */
921
+ function cropLayerSource(layer, surfaces, degraded) {
922
+ const { source, sourceWidth: width, sourceHeight: height } = layer;
923
+ if (!hasCrop(layer.crop) || width <= 0 || height <= 0) {
924
+ return { source, width, height };
925
+ }
926
+ const rect = cropRectPx(layer.crop, width, height);
927
+ const surface = surfaces.cropSurface?.(rect.width, rect.height);
928
+ if (!surface) {
929
+ degraded.push({ clipId: layer.clipId, reason: "crop_skipped" });
930
+ return { source, width, height };
931
+ }
932
+ const cctx = surface.ctx;
933
+ cctx.setTransform(1, 0, 0, 1, 0, 0);
934
+ cctx.globalAlpha = 1;
935
+ cctx.filter = "none";
936
+ cctx.globalCompositeOperation = "source-over";
937
+ cctx.clearRect(0, 0, rect.width, rect.height);
938
+ try {
939
+ cctx.drawImage(source, -rect.x, -rect.y, width, height);
940
+ }
941
+ catch {
942
+ degraded.push({ clipId: layer.clipId, reason: "crop_skipped" });
943
+ return { source, width, height };
944
+ }
945
+ return { source: surface.surface, width: rect.width, height: rect.height };
946
+ }
947
+ /**
948
+ * Copy `source` onto a scratch surface, add the grade's brightness to it, and
949
+ * multiply the soft masks into its alpha — all in the layer's own source-pixel
950
+ * space. Null when the host vended no scratch; the three flags say what
951
+ * actually landed, so the caller can clip the masks hard and put the brightness
952
+ * back in the CSS filter.
953
+ *
954
+ * Both masks reduce to a `destination-in` on one copy, which is why they share
955
+ * a surface: a shape mask needs its coverage rasterized separately (it is a
956
+ * ring of disjoint fills, and `destination-in` would intersect them), but the
957
+ * wipe is a single gradient and multiplies straight in.
958
+ */
959
+ function prepareSource(source, width, height, wipe, shape, brightness, surfaces) {
960
+ const scratch = surfaces.maskScratch?.(width, height);
961
+ if (!scratch)
962
+ return null;
963
+ const sctx = scratch.ctx;
964
+ sctx.setTransform(1, 0, 0, 1, 0, 0);
965
+ sctx.globalAlpha = 1;
966
+ sctx.filter = "none";
967
+ sctx.globalCompositeOperation = "source-over";
968
+ sctx.clearRect(0, 0, width, height);
969
+ sctx.drawImage(source, 0, 0, width, height);
970
+ // Brightness runs first, as it does in `colorGradeV1`, and before the masks
971
+ // so it never reads back a pixel a mask has already knocked out.
972
+ let brightnessApplied = false;
973
+ if (Math.abs(brightness) > 0.001) {
974
+ addBrightness(sctx, width, height, brightness);
975
+ brightnessApplied = true;
976
+ }
977
+ let shapeApplied = false;
978
+ if (shape && !maskIsHard(shape)) {
979
+ const coverage = surfaces.maskSurface?.(width, height);
980
+ if (coverage && coverage.surface !== scratch.surface) {
981
+ shapeApplied = drawMask(coverage.ctx, shape, width, height);
982
+ if (shapeApplied) {
983
+ sctx.globalCompositeOperation = "destination-in";
984
+ sctx.drawImage(coverage.surface, 0, 0, width, height);
985
+ sctx.globalCompositeOperation = "source-over";
986
+ }
987
+ }
988
+ }
989
+ let wipeApplied = false;
990
+ if (wipe && wipe.softness > 0) {
991
+ applyWipeGradient(sctx, width, height, wipe);
992
+ wipeApplied = true;
993
+ }
994
+ if (!shapeApplied && !wipeApplied && !brightnessApplied)
995
+ return null;
996
+ return {
997
+ surface: scratch.surface,
998
+ shape: shapeApplied,
999
+ wipe: wipeApplied,
1000
+ brightness: brightnessApplied
1001
+ };
1002
+ }
1003
+ /**
1004
+ * Add `amount` to every channel of the surface, which is what the GPU grade
1005
+ * does (`rgb + brightness` in `color/grade/v1`) and what CSS `brightness()`
1006
+ * does not — that one multiplies, so a +0.25 lift lands on 160 rather than 192
1007
+ * from mid-grey.
1008
+ *
1009
+ * Shipped as a per-pixel pass rather than a `lighter` white draw keyed back to
1010
+ * the layer's alpha: the composite version is exact only for a positive
1011
+ * `amount`, needs a second surface to restrict the white to the layer's own
1012
+ * coverage, and would still need this pass for the negative half. One read and
1013
+ * one write on the scratch copy covers both signs at the same cost.
1014
+ *
1015
+ * Straight (un-premultiplied) alpha is what a canvas stores, so the channels
1016
+ * move and the coverage does not — the same pixels the shader reads.
1017
+ */
1018
+ function addBrightness(ctx, width, height, amount) {
1019
+ const pixels = ctx.getImageData(0, 0, width, height);
1020
+ const data = pixels.data;
1021
+ const delta = Math.round(amount * 255);
1022
+ for (let i = 0; i < data.length; i += 4) {
1023
+ data[i] = data[i] + delta;
1024
+ data[i + 1] = data[i + 1] + delta;
1025
+ data[i + 2] = data[i + 2] + delta;
1026
+ }
1027
+ ctx.putImageData(pixels, 0, 0);
1028
+ }
1029
+ /** How many drop shadows the chain asks for; `ctx.shadow*` casts one (D7). */
1030
+ function countDropShadows(effects) {
1031
+ let n = 0;
1032
+ for (const e of effects ?? []) {
1033
+ if (e.enabled && isClipDropShadowEffect(e))
1034
+ n += 1;
1035
+ }
1036
+ return n;
1037
+ }
1038
+ /**
1039
+ * Knock out the hidden side of a wipe with a `destination-in` linear gradient.
1040
+ * The stops sample the same `1 - smoothstep(e - s, e, c)` profile the WebGPU
1041
+ * shader evaluates per-fragment, at the same front position
1042
+ * `e = progress * (1 + s)`, so both backends show the same visible fraction at
1043
+ * the same progress.
1044
+ */
1045
+ function applyWipeGradient(sctx, width, height, mask) {
1046
+ const s = mask.softness;
1047
+ const e = mask.progress * (1 + s);
1048
+ // The gradient runs along the wipe axis from c = e - s (fully visible) to
1049
+ // c = e (fully hidden), where c is the normalized distance from the reveal
1050
+ // edge. Regions outside the band clamp to the nearest stop.
1051
+ const from = axisPoint(mask.direction, e - s, width, height);
1052
+ const to = axisPoint(mask.direction, e, width, height);
1053
+ const gradient = sctx.createLinearGradient(from.x, from.y, to.x, to.y);
1054
+ for (const f of FEATHER_STOPS) {
1055
+ gradient.addColorStop(f, `rgba(0,0,0,${1 - (3 * f * f - 2 * f * f * f)})`);
1056
+ }
1057
+ sctx.globalCompositeOperation = "destination-in";
1058
+ sctx.fillStyle = gradient;
1059
+ sctx.fillRect(0, 0, width, height);
1060
+ sctx.globalCompositeOperation = "source-over";
1061
+ }
1062
+ /**
1063
+ * Draw a matted layer: compose it on one frame-sized surface, compose its matte
1064
+ * source on another, multiply the matte into the first surface's alpha, and
1065
+ * blend that once (D6).
1066
+ *
1067
+ * Frame-sized rather than source-sized because a matte is positioned by its own
1068
+ * clip: the source's transform decides where its keyhole falls on the frame,
1069
+ * which is only expressible once both layers are placed.
1070
+ *
1071
+ * Null when the host vended no usable pair of surfaces — the caller then draws
1072
+ * the layer unmatted, which is a visible difference and not a lost layer.
1073
+ */
1074
+ function drawMattedLayer(ctx, layer, matte, geometry, surfaces, degraded) {
1075
+ const make = surfaces.matteSurface;
1076
+ if (!make)
1077
+ return null;
1078
+ const { canvasWidth: w, canvasHeight: h } = geometry;
1079
+ const composed = make(w, h);
1080
+ const keyhole = make(w, h);
1081
+ if (!composed || !keyhole || composed.surface === keyhole.surface)
1082
+ return null;
1083
+ // The layer's own blend mode meets the frame once, when the composed surface
1084
+ // is drawn back — on the surface it is an ordinary source-over draw over
1085
+ // transparency. Its opacity rides along in the surface's alpha.
1086
+ // A dip's solid covers the whole frame, so it belongs on the main stack
1087
+ // beside the layer, the way the GPU compositor pushes it. Left on the inner
1088
+ // draw, `destination-in` would key it by the keyhole and the frame would dip
1089
+ // only where the matte lets it through.
1090
+ const transition = layer.transition;
1091
+ const inner = transition?.solid
1092
+ ? { ...transition, solid: undefined }
1093
+ : transition;
1094
+ resetContext(composed.ctx);
1095
+ composed.ctx.clearRect(0, 0, w, h);
1096
+ const drawn = drawTimelineLayer(composed.ctx, {
1097
+ ...layer,
1098
+ matte: undefined,
1099
+ blendMode: "normal",
1100
+ transition: inner
1101
+ }, geometry, surfaces, degraded);
1102
+ resetContext(keyhole.ctx);
1103
+ keyhole.ctx.clearRect(0, 0, w, h);
1104
+ drawTimelineLayer(keyhole.ctx, { ...matte.layer, matte: undefined, blendMode: "normal" }, geometry, surfaces, degraded);
1105
+ if (matte.mode === "luma")
1106
+ lumaToAlpha(keyhole.ctx, w, h);
1107
+ if (matte.invert)
1108
+ invertAlpha(keyhole.ctx, w, h);
1109
+ const strength = matte.strength ?? 1;
1110
+ if (strength < 1)
1111
+ scaleAlpha(keyhole.ctx, w, h, Math.max(0, strength));
1112
+ // The GPU path blurs the keyhole before it is read; there is no separable
1113
+ // blur here, and `ctx.filter` would soften the *picture* rather than the
1114
+ // matte. Named rather than silently dropped (I7).
1115
+ if (matte.featherPx !== undefined && matte.featherPx > 0) {
1116
+ degraded.push({
1117
+ clipId: layer.clipId,
1118
+ reason: "generated_matte_feather_ignored"
1119
+ });
1120
+ }
1121
+ composed.ctx.globalCompositeOperation = "destination-in";
1122
+ composed.ctx.drawImage(keyhole.surface, 0, 0, w, h);
1123
+ resetContext(composed.ctx);
1124
+ const solid = transition?.solid;
1125
+ if (solid && solid.opacity > 0) {
1126
+ ctx.save();
1127
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
1128
+ ctx.globalAlpha = Math.min(1, solid.opacity);
1129
+ ctx.globalCompositeOperation = "source-over";
1130
+ ctx.filter = "none";
1131
+ ctx.fillStyle = solid.color;
1132
+ ctx.fillRect(0, 0, geometry.canvasWidth, geometry.canvasHeight);
1133
+ ctx.restore();
1134
+ }
1135
+ ctx.save();
1136
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
1137
+ ctx.globalAlpha = 1;
1138
+ ctx.globalCompositeOperation = blendModeToCanvasOp(layer.blendMode);
1139
+ ctx.filter = "none";
1140
+ let ok = drawn;
1141
+ try {
1142
+ ctx.drawImage(composed.surface, 0, 0, w, h);
1143
+ }
1144
+ catch {
1145
+ ok = false;
1146
+ }
1147
+ ctx.restore();
1148
+ resetContext(ctx);
1149
+ return ok;
1150
+ }
1151
+ /**
1152
+ * Move a surface's luminance into its alpha, which is what a luma matte means
1153
+ * and what no composite operation expresses.
1154
+ *
1155
+ * Canvas stores straight alpha, so a transparent pixel's colour says nothing
1156
+ * about the picture — the luminance is weighted by the coverage it was drawn
1157
+ * with, which is what makes a luma matte over an empty frame read as empty
1158
+ * rather than as whatever the surface happened to be cleared to.
1159
+ */
1160
+ function lumaToAlpha(ctx, width, height) {
1161
+ const pixels = ctx.getImageData(0, 0, width, height);
1162
+ const data = pixels.data;
1163
+ for (let i = 0; i < data.length; i += 4) {
1164
+ const luma = 0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2];
1165
+ data[i] = 255;
1166
+ data[i + 1] = 255;
1167
+ data[i + 2] = 255;
1168
+ data[i + 3] = Math.round((luma * data[i + 3]) / 255);
1169
+ }
1170
+ ctx.putImageData(pixels, 0, 0);
1171
+ }
1172
+ /**
1173
+ * `alpha *= scale`, which is what a matte's `strength` means: at 0.5 half of
1174
+ * what the matte hides comes back through. Run on the keyhole rather than on
1175
+ * the layer so the two compositors read one number the same way.
1176
+ */
1177
+ function scaleAlpha(ctx, width, height, scale) {
1178
+ const pixels = ctx.getImageData(0, 0, width, height);
1179
+ const data = pixels.data;
1180
+ for (let i = 3; i < data.length; i += 4) {
1181
+ data[i] = Math.round(data[i] * scale);
1182
+ }
1183
+ ctx.putImageData(pixels, 0, 0);
1184
+ }
1185
+ /** `alpha = 1 - alpha`, for a matte that keeps what its source hides. */
1186
+ function invertAlpha(ctx, width, height) {
1187
+ const pixels = ctx.getImageData(0, 0, width, height);
1188
+ const data = pixels.data;
1189
+ for (let i = 0; i < data.length; i += 4) {
1190
+ data[i] = 255;
1191
+ data[i + 1] = 255;
1192
+ data[i + 2] = 255;
1193
+ data[i + 3] = 255 - data[i + 3];
1194
+ }
1195
+ ctx.putImageData(pixels, 0, 0);
1196
+ }
1197
+ /** Five stops approximate the shader's smoothstep feather. */
1198
+ const FEATHER_STOPS = [0, 0.25, 0.5, 0.75, 1];
1199
+ /**
1200
+ * The source-pixel point at normalized distance `c` from a wipe's reveal edge,
1201
+ * along the wipe axis.
1202
+ */
1203
+ export function axisPoint(direction, c, width, height) {
1204
+ switch (direction) {
1205
+ case "left":
1206
+ return { x: c * width, y: 0 };
1207
+ case "right":
1208
+ return { x: (1 - c) * width, y: 0 };
1209
+ case "up":
1210
+ return { x: 0, y: c * height };
1211
+ case "down":
1212
+ return { x: 0, y: (1 - c) * height };
1213
+ }
1214
+ }
1215
+ /**
1216
+ * Clip to a hard-edged wipe's visible region: the rect within normalized
1217
+ * distance `progress` of the reveal edge, in source-pixel space (so it
1218
+ * composes with the active layer transform and any rounded-rect clip).
1219
+ */
1220
+ export function clipWipeRect(ctx, width, height, mask) {
1221
+ const p = Math.max(0, Math.min(1, mask.progress));
1222
+ ctx.beginPath();
1223
+ switch (mask.direction) {
1224
+ case "left":
1225
+ ctx.rect(0, 0, p * width, height);
1226
+ break;
1227
+ case "right":
1228
+ ctx.rect((1 - p) * width, 0, p * width, height);
1229
+ break;
1230
+ case "up":
1231
+ ctx.rect(0, 0, width, p * height);
1232
+ break;
1233
+ case "down":
1234
+ ctx.rect(0, (1 - p) * height, width, p * height);
1235
+ break;
1236
+ }
1237
+ ctx.clip();
1238
+ }
1239
+ /** Clip the current path to a rounded rectangle in the active transform space. */
1240
+ export function clipRoundedRect(ctx, x, y, w, h, r) {
1241
+ ctx.beginPath();
1242
+ ctx.moveTo(x + r, y);
1243
+ ctx.arcTo(x + w, y, x + w, y + h, r);
1244
+ ctx.arcTo(x + w, y + h, x, y + h, r);
1245
+ ctx.arcTo(x, y + h, x, y, r);
1246
+ ctx.arcTo(x, y, x + w, y, r);
1247
+ ctx.closePath();
1248
+ ctx.clip();
1249
+ }
1250
+ /**
1251
+ * Arm `ctx.shadow*` from the first enabled `dropShadow` in the chain, so the
1252
+ * next `drawImage` casts it (D7).
1253
+ *
1254
+ * Canvas 2D holds shadow offsets and blur in canvas units and leaves them out
1255
+ * of the current transform, while the document authors them in the layer's own
1256
+ * source pixels — the space the GPU recipe runs in, before placement. So the
1257
+ * offset goes through the affine's linear part and the blur through its scale,
1258
+ * which is what makes a shadow on a scaled-down layer the same size on both
1259
+ * paths. The blur itself is two thirds of the radius because `shadowBlur` is
1260
+ * twice the Gaussian sigma and `filters.blur.gaussian@1` derives sigma as a
1261
+ * third of its radius.
1262
+ */
1263
+ function applyDropShadow(ctx, effects, t) {
1264
+ const shadow = (effects ?? []).find((e) => e.enabled && isClipDropShadowEffect(e));
1265
+ if (!shadow)
1266
+ return;
1267
+ const scale = Math.sqrt(Math.abs(t.a * t.d - t.b * t.c)) || 1;
1268
+ ctx.shadowColor = shadowPaint(shadow.color, shadow.opacity ?? 1);
1269
+ ctx.shadowBlur = Math.max(0, shadow.blur) * (2 / 3) * scale;
1270
+ ctx.shadowOffsetX = t.a * shadow.offsetX + t.c * shadow.offsetY;
1271
+ ctx.shadowOffsetY = t.b * shadow.offsetX + t.d * shadow.offsetY;
1272
+ }
1273
+ /**
1274
+ * A shadow colour with its opacity folded in — Canvas 2D has no separate
1275
+ * shadow alpha. A colour that is not `#rgb`/`#rrggbb` is passed through, so a
1276
+ * named colour still casts at full strength rather than not at all.
1277
+ */
1278
+ function shadowPaint(color, opacity) {
1279
+ const alpha = Math.max(0, Math.min(1, opacity));
1280
+ const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim());
1281
+ if (!hex)
1282
+ return color;
1283
+ const digits = hex[1] ?? "";
1284
+ const wide = digits.length === 3
1285
+ ? digits
1286
+ .split("")
1287
+ .map((c) => c + c)
1288
+ .join("")
1289
+ : digits;
1290
+ const v = parseInt(wide, 16);
1291
+ const rgb = `${(v >> 16) & 0xff}, ${(v >> 8) & 0xff}, ${v & 0xff}`;
1292
+ return `rgba(${rgb}, ${alpha})`;
1293
+ }
1294
+ /**
1295
+ * Memoize the built filter string per `(clipEffects, trackEffects)` array
1296
+ * identity. Both arrays are stable references on the clip/track until edited,
1297
+ * so a clip sitting still reuses its string across every frame instead of
1298
+ * rebuilding it per layer per frame.
1299
+ */
1300
+ const FILTER_NONE_KEY = Object.freeze([]);
1301
+ const filterCache = new WeakMap();
1302
+ const gradedFilterCache = new WeakMap();
1303
+ /**
1304
+ * @param brightnessApplied The layer's brightness already landed as the GPU's
1305
+ * addition on a scratch copy, so the filter must leave it out rather than
1306
+ * apply the lift a second time.
1307
+ */
1308
+ export function filterForEffects(clipEffects, trackEffects, brightnessApplied = false) {
1309
+ // Normalize undefined to a shared sentinel so both keys are always objects
1310
+ // the WeakMaps can hold.
1311
+ const clipKey = (clipEffects ?? FILTER_NONE_KEY);
1312
+ const trackKey = (trackEffects ?? FILTER_NONE_KEY);
1313
+ const cache = brightnessApplied ? gradedFilterCache : filterCache;
1314
+ let inner = cache.get(clipKey);
1315
+ if (inner) {
1316
+ const hit = inner.get(trackKey);
1317
+ if (hit !== undefined)
1318
+ return hit;
1319
+ }
1320
+ else {
1321
+ inner = new WeakMap();
1322
+ cache.set(clipKey, inner);
1323
+ }
1324
+ const result = computeFilterForEffects(clipEffects, trackEffects, brightnessApplied);
1325
+ inner.set(trackKey, result);
1326
+ return result;
1327
+ }
1328
+ /**
1329
+ * The grade's total brightness, summed over the clip and track effects exactly
1330
+ * as the filter builder sums it — one accumulation, so the scratch pass and the
1331
+ * filter can never disagree about how much lift is left to apply.
1332
+ */
1333
+ export function brightnessForEffects(clipEffects, trackEffects) {
1334
+ let brightness = 0;
1335
+ for (const e of clipEffects ?? []) {
1336
+ if (e.enabled && isClipColorEffect(e))
1337
+ brightness += e.brightness ?? 0;
1338
+ }
1339
+ for (const e of trackEffects ?? []) {
1340
+ if (e.enabled && e.type === "colorCorrection")
1341
+ brightness += e.brightness;
1342
+ }
1343
+ return brightness;
1344
+ }
1345
+ /**
1346
+ * Approximate the clip + track color/blur effects with a CSS `filter` string.
1347
+ * Covers the brightness / contrast / saturation / hue / blur adjustments and
1348
+ * ignores the GPU-only effects — see {@link unsupportedEffectTypes}.
1349
+ */
1350
+ function computeFilterForEffects(clipEffects, trackEffects, brightnessApplied) {
1351
+ let brightness = 0;
1352
+ let contrast = 1;
1353
+ let saturation = 1;
1354
+ let hue = 0;
1355
+ let blur = 0;
1356
+ const accumulate = (effects) => {
1357
+ for (const e of effects) {
1358
+ if (!e.enabled)
1359
+ continue;
1360
+ if (isClipColorEffect(e)) {
1361
+ brightness += e.brightness ?? 0;
1362
+ contrast *= e.contrast ?? 1;
1363
+ saturation *= e.saturation ?? 1;
1364
+ hue += e.hue ?? 0;
1365
+ }
1366
+ else if (isClipBlurEffect(e)) {
1367
+ blur += e.radius;
1368
+ }
1369
+ }
1370
+ };
1371
+ accumulate(clipEffects ?? []);
1372
+ accumulate(trackEffectsAsClipEffects(trackEffects));
1373
+ const parts = [];
1374
+ if (!brightnessApplied && Math.abs(brightness) > 0.001) {
1375
+ parts.push(`brightness(${(1 + brightness).toFixed(3)})`);
1376
+ }
1377
+ if (Math.abs(contrast - 1) > 0.001) {
1378
+ parts.push(`contrast(${contrast.toFixed(3)})`);
1379
+ }
1380
+ if (Math.abs(saturation - 1) > 0.001) {
1381
+ parts.push(`saturate(${saturation.toFixed(3)})`);
1382
+ }
1383
+ if (Math.abs(hue) > 0.001) {
1384
+ parts.push(`hue-rotate(${hue.toFixed(2)}deg)`);
1385
+ }
1386
+ if (blur >= 0.5) {
1387
+ // CSS blur() takes Gaussian sigma; the GPU kernel derives sigma = radius/3.
1388
+ parts.push(`blur(${(blur / 3).toFixed(2)}px)`);
1389
+ }
1390
+ return parts.length > 0 ? parts.join(" ") : "none";
1391
+ }
1392
+ //# sourceMappingURL=canvas2d.js.map