@nodaro/shared 3.61.0 → 3.63.0

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 (313) hide show
  1. package/dist/{chunk-4KYLNTR7.cjs → chunk-2PU3AGGS.cjs} +27 -4
  2. package/dist/chunk-2PU3AGGS.cjs.map +1 -0
  3. package/dist/{chunk-43TGSZRJ.js → chunk-2QKF7M2Z.js} +3 -3
  4. package/dist/{chunk-43TGSZRJ.js.map → chunk-2QKF7M2Z.js.map} +1 -1
  5. package/dist/{chunk-B6BG3LV2.js → chunk-34QLPTSA.js} +3 -3
  6. package/dist/{chunk-B6BG3LV2.js.map → chunk-34QLPTSA.js.map} +1 -1
  7. package/dist/chunk-3K24DWOH.js +453 -0
  8. package/dist/chunk-3K24DWOH.js.map +1 -0
  9. package/dist/{chunk-IRQ3SPX7.js → chunk-4DVWXEB6.js} +23 -4
  10. package/dist/chunk-4DVWXEB6.js.map +1 -0
  11. package/dist/{chunk-ZES6EZC4.js → chunk-4MMZD63H.js} +3 -3
  12. package/dist/{chunk-ZES6EZC4.js.map → chunk-4MMZD63H.js.map} +1 -1
  13. package/dist/{chunk-MQZRQ5LM.cjs → chunk-63H4C56Q.cjs} +8 -8
  14. package/dist/{chunk-MQZRQ5LM.cjs.map → chunk-63H4C56Q.cjs.map} +1 -1
  15. package/dist/{chunk-IVXSNW2B.cjs → chunk-6BZC2ZHC.cjs} +18 -332
  16. package/dist/chunk-6BZC2ZHC.cjs.map +1 -0
  17. package/dist/{chunk-M3SXUUWC.cjs → chunk-6FQBKI2A.cjs} +4 -11
  18. package/dist/chunk-6FQBKI2A.cjs.map +1 -0
  19. package/dist/{chunk-673E4KYC.js → chunk-6M563QE6.js} +134 -8
  20. package/dist/chunk-6M563QE6.js.map +1 -0
  21. package/dist/chunk-6TGB7ECA.cjs +48 -0
  22. package/dist/chunk-6TGB7ECA.cjs.map +1 -0
  23. package/dist/{chunk-XUJC6GHE.cjs → chunk-6XUG4L7X.cjs} +6 -6
  24. package/dist/{chunk-XUJC6GHE.cjs.map → chunk-6XUG4L7X.cjs.map} +1 -1
  25. package/dist/{chunk-XZKFZMRT.cjs → chunk-77WU3V3J.cjs} +6 -6
  26. package/dist/{chunk-XZKFZMRT.cjs.map → chunk-77WU3V3J.cjs.map} +1 -1
  27. package/dist/{chunk-ZFJN23V4.cjs → chunk-A2PX5IRC.cjs} +4 -4
  28. package/dist/{chunk-ZFJN23V4.cjs.map → chunk-A2PX5IRC.cjs.map} +1 -1
  29. package/dist/{chunk-ZDBPQBAA.js → chunk-AE3AAJ4O.js} +3 -3
  30. package/dist/{chunk-ZDBPQBAA.js.map → chunk-AE3AAJ4O.js.map} +1 -1
  31. package/dist/chunk-ALRXY4QH.cjs +13 -0
  32. package/dist/chunk-ALRXY4QH.cjs.map +1 -0
  33. package/dist/{chunk-UARGJ5IZ.js → chunk-BMJVKYVB.js} +56 -12
  34. package/dist/chunk-BMJVKYVB.js.map +1 -0
  35. package/dist/{chunk-6XVHYD5R.js → chunk-CLAKSLXF.js} +4 -9
  36. package/dist/chunk-CLAKSLXF.js.map +1 -0
  37. package/dist/chunk-CTANEPMY.js +61 -0
  38. package/dist/chunk-CTANEPMY.js.map +1 -0
  39. package/dist/chunk-CZ5IQB3L.js +42 -0
  40. package/dist/chunk-CZ5IQB3L.js.map +1 -0
  41. package/dist/{chunk-WGKAOUEQ.cjs → chunk-D34K455O.cjs} +3 -2
  42. package/dist/chunk-D34K455O.cjs.map +1 -0
  43. package/dist/chunk-EPXGG27L.js +331 -0
  44. package/dist/chunk-EPXGG27L.js.map +1 -0
  45. package/dist/{chunk-3M4BNKFJ.cjs → chunk-F6WGGYQW.cjs} +167 -3
  46. package/dist/chunk-F6WGGYQW.cjs.map +1 -0
  47. package/dist/{chunk-7FCTCWHD.js → chunk-FXGNRYQQ.js} +3 -3
  48. package/dist/{chunk-7FCTCWHD.js.map → chunk-FXGNRYQQ.js.map} +1 -1
  49. package/dist/{chunk-ZNM2LW3D.cjs → chunk-GMBDLNLD.cjs} +105 -56
  50. package/dist/chunk-GMBDLNLD.cjs.map +1 -0
  51. package/dist/{chunk-NJVOJXBS.cjs → chunk-GSKLPI3J.cjs} +104 -49
  52. package/dist/chunk-GSKLPI3J.cjs.map +1 -0
  53. package/dist/{chunk-EWS2VFO4.js → chunk-HBXF6RUU.js} +4 -4
  54. package/dist/{chunk-EWS2VFO4.js.map → chunk-HBXF6RUU.js.map} +1 -1
  55. package/dist/{chunk-MOMFX32D.js → chunk-HWQ2SYNA.js} +194 -325
  56. package/dist/chunk-HWQ2SYNA.js.map +1 -0
  57. package/dist/{chunk-SCMTN57Y.js → chunk-IY3Y462W.js} +3 -3
  58. package/dist/{chunk-SCMTN57Y.js.map → chunk-IY3Y462W.js.map} +1 -1
  59. package/dist/{chunk-ZZGQRRN7.js → chunk-KCZHQH2O.js} +6 -306
  60. package/dist/chunk-KCZHQH2O.js.map +1 -0
  61. package/dist/{chunk-XROE3CAS.cjs → chunk-KHH54GRP.cjs} +120 -79
  62. package/dist/chunk-KHH54GRP.cjs.map +1 -0
  63. package/dist/{chunk-FVVD6XY2.js → chunk-KL6GAYTT.js} +13 -4
  64. package/dist/chunk-KL6GAYTT.js.map +1 -0
  65. package/dist/{chunk-FVII3KHN.js → chunk-KMGCHV6O.js} +163 -4
  66. package/dist/chunk-KMGCHV6O.js.map +1 -0
  67. package/dist/{chunk-FMXFHJWX.cjs → chunk-L2TVY6XN.cjs} +4 -4
  68. package/dist/{chunk-FMXFHJWX.cjs.map → chunk-L2TVY6XN.cjs.map} +1 -1
  69. package/dist/{chunk-FQXRYPCX.cjs → chunk-LH72PQO2.cjs} +505 -68
  70. package/dist/chunk-LH72PQO2.cjs.map +1 -0
  71. package/dist/chunk-LMAQUR55.cjs +506 -0
  72. package/dist/chunk-LMAQUR55.cjs.map +1 -0
  73. package/dist/{chunk-F5YEMSNK.cjs → chunk-M5OCFGHF.cjs} +571 -30
  74. package/dist/chunk-M5OCFGHF.cjs.map +1 -0
  75. package/dist/{chunk-VOWJCUMR.js → chunk-MD4XHED4.js} +3 -3
  76. package/dist/{chunk-VOWJCUMR.js.map → chunk-MD4XHED4.js.map} +1 -1
  77. package/dist/chunk-N5HH46JF.cjs +68 -0
  78. package/dist/chunk-N5HH46JF.cjs.map +1 -0
  79. package/dist/{chunk-G4XWVWRI.js → chunk-NIAFR5EE.js} +5 -4
  80. package/dist/chunk-NIAFR5EE.js.map +1 -0
  81. package/dist/{chunk-CF4S4N5X.js → chunk-O2QOBA6Q.js} +2 -2
  82. package/dist/{chunk-CF4S4N5X.js.map → chunk-O2QOBA6Q.js.map} +1 -1
  83. package/dist/{chunk-4GGLKRYI.cjs → chunk-O6TBB4IF.cjs} +2 -2
  84. package/dist/{chunk-4GGLKRYI.cjs.map → chunk-O6TBB4IF.cjs.map} +1 -1
  85. package/dist/{chunk-SWVGHAYO.js → chunk-O7RZRUMZ.js} +110 -74
  86. package/dist/chunk-O7RZRUMZ.js.map +1 -0
  87. package/dist/{chunk-LLOIAGFB.js → chunk-OV3JTKBY.js} +449 -51
  88. package/dist/chunk-OV3JTKBY.js.map +1 -0
  89. package/dist/{chunk-A3FHTSLB.js → chunk-PSKZKLDG.js} +550 -31
  90. package/dist/chunk-PSKZKLDG.js.map +1 -0
  91. package/dist/{chunk-VB2ARGQ6.js → chunk-RGNHHIMN.js} +3 -3
  92. package/dist/chunk-RGNHHIMN.js.map +1 -0
  93. package/dist/chunk-SMOO5FAH.js +10 -0
  94. package/dist/chunk-SMOO5FAH.js.map +1 -0
  95. package/dist/{chunk-5XRRENHD.cjs → chunk-TM5JYSJF.cjs} +170 -17
  96. package/dist/chunk-TM5JYSJF.cjs.map +1 -0
  97. package/dist/{chunk-PONP5J5E.cjs → chunk-V24EPI5N.cjs} +13 -3
  98. package/dist/chunk-V24EPI5N.cjs.map +1 -0
  99. package/dist/{chunk-RQ4F3AJH.cjs → chunk-V5EEQR2U.cjs} +21 -21
  100. package/dist/{chunk-RQ4F3AJH.cjs.map → chunk-V5EEQR2U.cjs.map} +1 -1
  101. package/dist/chunk-WZVIBAKN.cjs +351 -0
  102. package/dist/chunk-WZVIBAKN.cjs.map +1 -0
  103. package/dist/{chunk-5M43XMRB.cjs → chunk-X5BAFW3Q.cjs} +8 -8
  104. package/dist/{chunk-5M43XMRB.cjs.map → chunk-X5BAFW3Q.cjs.map} +1 -1
  105. package/dist/{chunk-RUHKBEFF.js → chunk-XBTYGQ6Z.js} +63 -10
  106. package/dist/chunk-XBTYGQ6Z.js.map +1 -0
  107. package/dist/{chunk-JHTT2V4A.cjs → chunk-XGGZWA4A.cjs} +118 -52
  108. package/dist/chunk-XGGZWA4A.cjs.map +1 -0
  109. package/dist/{chunk-5I4T4QR5.cjs → chunk-XGVJGNZW.cjs} +5 -5
  110. package/dist/{chunk-5I4T4QR5.cjs.map → chunk-XGVJGNZW.cjs.map} +1 -1
  111. package/dist/{chunk-7ARKVJTN.cjs → chunk-Y35JQPT6.cjs} +228 -383
  112. package/dist/chunk-Y35JQPT6.cjs.map +1 -0
  113. package/dist/{chunk-AFQFGZN7.cjs → chunk-Y4GCJJPF.cjs} +8 -6
  114. package/dist/chunk-Y4GCJJPF.cjs.map +1 -0
  115. package/dist/{chunk-C77F4ZTL.js → chunk-YUER7TJG.js} +3 -3
  116. package/dist/{chunk-C77F4ZTL.js.map → chunk-YUER7TJG.js.map} +1 -1
  117. package/dist/{chunk-HGI2VKIV.js → chunk-YX6TFX7H.js} +67 -14
  118. package/dist/chunk-YX6TFX7H.js.map +1 -0
  119. package/dist/{chunk-TWF2OSH4.cjs → chunk-ZPE2ZTJ4.cjs} +4 -4
  120. package/dist/{chunk-TWF2OSH4.cjs.map → chunk-ZPE2ZTJ4.cjs.map} +1 -1
  121. package/dist/entries/apps.cjs +44 -44
  122. package/dist/entries/apps.js +9 -9
  123. package/dist/entries/credits.cjs +286 -153
  124. package/dist/entries/credits.d.cts +254 -5
  125. package/dist/entries/credits.d.ts +254 -5
  126. package/dist/entries/credits.js +14 -9
  127. package/dist/entries/entities.cjs +188 -143
  128. package/dist/entries/entities.d.cts +122 -1
  129. package/dist/entries/entities.d.ts +122 -1
  130. package/dist/entries/entities.js +2 -1
  131. package/dist/entries/llm-models.cjs +77 -57
  132. package/dist/entries/llm-models.d.cts +85 -5
  133. package/dist/entries/llm-models.d.ts +85 -5
  134. package/dist/entries/llm-models.js +2 -2
  135. package/dist/entries/media.cjs +92 -87
  136. package/dist/entries/media.d.cts +19 -1
  137. package/dist/entries/media.d.ts +19 -1
  138. package/dist/entries/media.js +3 -2
  139. package/dist/entries/model-catalog.cjs +211 -103
  140. package/dist/entries/model-catalog.d.cts +135 -19
  141. package/dist/entries/model-catalog.d.ts +135 -19
  142. package/dist/entries/model-catalog.js +5 -5
  143. package/dist/entries/models.cjs +504 -295
  144. package/dist/entries/models.d.cts +71 -4
  145. package/dist/entries/models.d.ts +71 -4
  146. package/dist/entries/models.js +7 -6
  147. package/dist/entries/nodes.cjs +249 -233
  148. package/dist/entries/nodes.d.cts +35 -6
  149. package/dist/entries/nodes.d.ts +35 -6
  150. package/dist/entries/nodes.js +10 -10
  151. package/dist/entries/pipeline.cjs +152 -152
  152. package/dist/entries/pipeline.d.cts +3 -2
  153. package/dist/entries/pipeline.d.ts +3 -2
  154. package/dist/entries/pipeline.js +3 -3
  155. package/dist/entries/runtime-config.cjs +29 -29
  156. package/dist/entries/runtime-config.d.cts +10 -7
  157. package/dist/entries/runtime-config.d.ts +10 -7
  158. package/dist/entries/runtime-config.js +1 -1
  159. package/dist/entries/social.cjs +177 -177
  160. package/dist/entries/social.js +2 -2
  161. package/dist/entries/types.d.cts +8 -0
  162. package/dist/entries/types.d.ts +8 -0
  163. package/dist/entries/ugc.cjs +71 -71
  164. package/dist/entries/ugc.js +4 -4
  165. package/dist/entries/video.cjs +316 -208
  166. package/dist/entries/video.d.cts +490 -99
  167. package/dist/entries/video.d.ts +490 -99
  168. package/dist/entries/video.js +8 -4
  169. package/dist/entries/workflow.cjs +102 -102
  170. package/dist/entries/workflow.d.cts +5 -4
  171. package/dist/entries/workflow.d.ts +5 -4
  172. package/dist/entries/workflow.js +2 -2
  173. package/dist/{gpt-image-2-6-BeZdT-pW.d.cts → gpt-image-2-6-jIRQBRag.d.cts} +6 -0
  174. package/dist/{gpt-image-2-6-BeZdT-pW.d.ts → gpt-image-2-6-jIRQBRag.d.ts} +6 -0
  175. package/dist/index.cjs +2727 -2092
  176. package/dist/index.d.cts +11 -11
  177. package/dist/index.d.ts +11 -11
  178. package/dist/index.js +30 -27
  179. package/dist/{model-catalog-BgSvskgY.d.ts → model-catalog-C_Eo35tL.d.cts} +158 -14
  180. package/dist/{model-catalog-BgSvskgY.d.cts → model-catalog-C_Eo35tL.d.ts} +158 -14
  181. package/dist/{model-constants-DHd9jwQ7.d.cts → model-constants-Bg4ccSQb.d.ts} +427 -34
  182. package/dist/{model-constants-DHd9jwQ7.d.ts → model-constants-DWcxOmaY.d.cts} +427 -34
  183. package/package.json +1 -1
  184. package/src/__tests__/credit-identifiers.test.ts +29 -0
  185. package/src/__tests__/extend-providers.test.ts +194 -0
  186. package/src/__tests__/fixtures/mask-composite-quote-parity.json +118 -0
  187. package/src/__tests__/fixtures/root-exports.baseline.json +68 -0
  188. package/src/__tests__/gpt-image-2-6-formats.test.ts +4 -1
  189. package/src/__tests__/grok-video-15-catalog.test.ts +189 -0
  190. package/src/__tests__/gvp-supported-providers.test.ts +32 -4
  191. package/src/__tests__/lip-sync-audio-rate.test.ts +74 -0
  192. package/src/__tests__/lip-sync-levers.test.ts +31 -0
  193. package/src/__tests__/llm-models.test.ts +132 -3
  194. package/src/__tests__/llm-price-key.test.ts +152 -1
  195. package/src/__tests__/minimax-h3-image.test.ts +140 -0
  196. package/src/__tests__/model-makers.test.ts +49 -11
  197. package/src/__tests__/model-tree.test.ts +13 -0
  198. package/src/__tests__/nemotron-transcribe-pricing.test.ts +61 -0
  199. package/src/__tests__/normalize-node-params.test.ts +25 -0
  200. package/src/__tests__/pixverse-v6-max-catalog.test.ts +271 -0
  201. package/src/__tests__/prompt-length-limits.test.ts +4 -0
  202. package/src/__tests__/retired-video-provider.test.ts +15 -5
  203. package/src/__tests__/seedance-25-catalog-modes.test.ts +1 -1
  204. package/src/__tests__/seedance-task-type.test.ts +188 -0
  205. package/src/__tests__/seedream-5-5.test.ts +117 -0
  206. package/src/__tests__/transcribe-capabilities.test.ts +39 -2
  207. package/src/__tests__/transcribe-preflight.test.ts +50 -1
  208. package/src/__tests__/unit-contract-compose.test.ts +27 -1
  209. package/src/__tests__/unit-contracts.test.ts +20 -6
  210. package/src/__tests__/upscale-factors.test.ts +107 -0
  211. package/src/__tests__/video-audio-capability.test.ts +35 -6
  212. package/src/__tests__/video-character-refs.test.ts +20 -2
  213. package/src/__tests__/video-collapse-parity.test.ts +19 -0
  214. package/src/__tests__/video-overlay-geometry.test.ts +68 -0
  215. package/src/__tests__/video-overlay-layer-plan.test.ts +3 -4
  216. package/src/__tests__/video-overlay-layouts.test.ts +529 -0
  217. package/src/__tests__/video-overlay-pricing.test.ts +61 -0
  218. package/src/__tests__/video-overlay-validate.test.ts +128 -0
  219. package/src/__tests__/video-overlay-wired-kind.test.ts +207 -0
  220. package/src/__tests__/video-overlay.test.ts +280 -194
  221. package/src/__tests__/video-ref-limits.test.ts +2 -1
  222. package/src/__tests__/video-reference-only.test.ts +6 -2
  223. package/src/__tests__/video-resolution-billed-as-named.test.ts +30 -0
  224. package/src/__tests__/video-start-frame-only.test.ts +98 -0
  225. package/src/__tests__/video-upscale-params.test.ts +62 -0
  226. package/src/__tests__/wired-character-names.test.ts +220 -0
  227. package/src/catalog-projection.ts +8 -0
  228. package/src/credit-estimators/index.ts +18 -0
  229. package/src/credit-estimators/nemotron-transcribe.ts +87 -0
  230. package/src/credit-estimators/video-overlay.ts +70 -0
  231. package/src/credit-identifiers.ts +183 -16
  232. package/src/entity-image-url.ts +21 -0
  233. package/src/entries/credits.ts +26 -1
  234. package/src/entries/entities.ts +14 -0
  235. package/src/entries/llm-models.ts +6 -0
  236. package/src/entries/model-catalog.ts +44 -1
  237. package/src/entries/models.ts +69 -0
  238. package/src/entries/nodes.ts +4 -0
  239. package/src/entries/video.ts +7 -1
  240. package/src/freecut-protocol.ts +8 -0
  241. package/src/generated/unit-contracts.ts +8 -1
  242. package/src/gpt-image-2-6.ts +6 -0
  243. package/src/input-image-pricing.ts +76 -0
  244. package/src/lip-sync-levers.ts +56 -0
  245. package/src/lip-sync-pricing.ts +91 -1
  246. package/src/llm-models.ts +249 -4
  247. package/src/mask-composite.ts +11 -0
  248. package/src/minimax-h3-image.ts +61 -0
  249. package/src/model-catalog.ts +604 -40
  250. package/src/model-constants.ts +860 -55
  251. package/src/model-tree.ts +2 -1
  252. package/src/nodaro-video-upscale.ts +48 -0
  253. package/src/node-default-mappings.ts +15 -2
  254. package/src/node-execution-state.ts +4 -3
  255. package/src/normalize-node-params.ts +49 -1
  256. package/src/producer-types.ts +23 -1
  257. package/src/runtime-config/contract.ts +10 -7
  258. package/src/seedance-draft.ts +2 -1
  259. package/src/seedance-task-type.ts +37 -0
  260. package/src/seedream-5-5.ts +45 -0
  261. package/src/transcribe-preflight.ts +58 -7
  262. package/src/unit-contract-compose.ts +4 -1
  263. package/src/upscale-factors.ts +111 -0
  264. package/src/video-character-refs.ts +7 -4
  265. package/src/video-duration.ts +9 -0
  266. package/src/video-overlay-geometry.ts +99 -0
  267. package/src/video-overlay-input.ts +25 -0
  268. package/src/video-overlay-layout-ids.ts +48 -0
  269. package/src/video-overlay-layouts.ts +315 -0
  270. package/src/video-overlay-validate.ts +223 -0
  271. package/src/video-overlay-video-layers.ts +304 -0
  272. package/src/video-overlay.ts +165 -297
  273. package/src/video-ui-defaults.ts +11 -7
  274. package/src/video-upscale-params.ts +67 -0
  275. package/src/wired-character-names.ts +202 -0
  276. package/dist/chunk-3M4BNKFJ.cjs.map +0 -1
  277. package/dist/chunk-4KYLNTR7.cjs.map +0 -1
  278. package/dist/chunk-5XRRENHD.cjs.map +0 -1
  279. package/dist/chunk-673E4KYC.js.map +0 -1
  280. package/dist/chunk-6XVHYD5R.js.map +0 -1
  281. package/dist/chunk-7ARKVJTN.cjs.map +0 -1
  282. package/dist/chunk-7WGKP3EU.js +0 -23
  283. package/dist/chunk-7WGKP3EU.js.map +0 -1
  284. package/dist/chunk-A3FHTSLB.js.map +0 -1
  285. package/dist/chunk-AFQFGZN7.cjs.map +0 -1
  286. package/dist/chunk-F5YEMSNK.cjs.map +0 -1
  287. package/dist/chunk-FQXRYPCX.cjs.map +0 -1
  288. package/dist/chunk-FVII3KHN.js.map +0 -1
  289. package/dist/chunk-FVVD6XY2.js.map +0 -1
  290. package/dist/chunk-G4XWVWRI.js.map +0 -1
  291. package/dist/chunk-HGI2VKIV.js.map +0 -1
  292. package/dist/chunk-IRQ3SPX7.js.map +0 -1
  293. package/dist/chunk-IVXSNW2B.cjs.map +0 -1
  294. package/dist/chunk-JHTT2V4A.cjs.map +0 -1
  295. package/dist/chunk-KHZAQGRP.js +0 -17
  296. package/dist/chunk-KHZAQGRP.js.map +0 -1
  297. package/dist/chunk-LLOIAGFB.js.map +0 -1
  298. package/dist/chunk-M3SXUUWC.cjs.map +0 -1
  299. package/dist/chunk-MOMFX32D.js.map +0 -1
  300. package/dist/chunk-NCOGGRRP.cjs +0 -27
  301. package/dist/chunk-NCOGGRRP.cjs.map +0 -1
  302. package/dist/chunk-NJVOJXBS.cjs.map +0 -1
  303. package/dist/chunk-PONP5J5E.cjs.map +0 -1
  304. package/dist/chunk-RUHKBEFF.js.map +0 -1
  305. package/dist/chunk-SWVGHAYO.js.map +0 -1
  306. package/dist/chunk-UARGJ5IZ.js.map +0 -1
  307. package/dist/chunk-VB2ARGQ6.js.map +0 -1
  308. package/dist/chunk-WGKAOUEQ.cjs.map +0 -1
  309. package/dist/chunk-XROE3CAS.cjs.map +0 -1
  310. package/dist/chunk-ZLDFPVVI.cjs +0 -19
  311. package/dist/chunk-ZLDFPVVI.cjs.map +0 -1
  312. package/dist/chunk-ZNM2LW3D.cjs.map +0 -1
  313. package/dist/chunk-ZZGQRRN7.js.map +0 -1
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Video Overlay — placement: the output canvas and where a layer's box lands
3
+ * on it. `resolveVideoOverlayGeometry` is the one placement function the
4
+ * canvas preview and the ffmpeg worker both call. A sibling of
5
+ * `video-overlay.ts`, which it imports from; nothing there imports this file.
6
+ * Wire contract only — no I/O.
7
+ */
8
+ import type { OverlayAnchor } from "./image-overlay-layers.js"
9
+ import { ASPECT_RATIO_DIMENSIONS } from "./model-constants.js"
10
+ import { isVideoOverlayOutputAspect, type VideoOverlayLayer } from "./video-overlay.js"
11
+
12
+ export interface VideoOverlayRect {
13
+ readonly left: number
14
+ readonly top: number
15
+ readonly width: number
16
+ readonly height: number
17
+ }
18
+ export interface VideoOverlayCanvas {
19
+ readonly w: number
20
+ readonly h: number
21
+ }
22
+ export interface VideoOverlayGeometry {
23
+ readonly box: VideoOverlayRect
24
+ readonly drawn: VideoOverlayRect
25
+ }
26
+
27
+ const evenFloor = (n: number): number => Math.max(2, Math.floor(n / 2) * 2)
28
+
29
+ /**
30
+ * The output canvas: `ASPECT_RATIO_DIMENSIONS[outputAspect]` when a target
31
+ * aspect is set; otherwise the base's DISPLAY size (rotation already applied by
32
+ * the caller's probe) with the sample aspect ratio resolved and both sides
33
+ * rounded down to even — `trunc(iw*sar/2)*2 × trunc(ih/2)*2`, what the ffmpeg
34
+ * base chain produces. null when neither is known.
35
+ */
36
+ export function videoOverlayCanvas(
37
+ display: { readonly width: number; readonly height: number; readonly sar?: number } | null | undefined,
38
+ outputAspect?: string | null,
39
+ ): VideoOverlayCanvas | null {
40
+ if (isVideoOverlayOutputAspect(outputAspect)) {
41
+ const d = ASPECT_RATIO_DIMENSIONS[outputAspect]!
42
+ return { w: d.width, h: d.height }
43
+ }
44
+ if (!display || !(display.width > 0) || !(display.height > 0)) return null
45
+ const sar = typeof display.sar === "number" && Number.isFinite(display.sar) && display.sar > 0 ? display.sar : 1
46
+ return { w: evenFloor(display.width * sar), h: evenFloor(display.height) }
47
+ }
48
+
49
+ function anchorFactors(anchor: OverlayAnchor): readonly [number, number] {
50
+ const h = anchor.endsWith("left") ? 0 : anchor.endsWith("right") ? 1 : 0.5
51
+ const v = anchor.startsWith("top") ? 0 : anchor.startsWith("bottom") ? 1 : 0.5
52
+ return [h, v]
53
+ }
54
+
55
+ /**
56
+ * Spec §3.4. `width%` → px of the canvas width; height follows the image's
57
+ * aspect unless `height%` is set; nine anchors; x/y are additive offsets in %
58
+ * of the canvas. An aspect-following box taller than the canvas is fitted
59
+ * inside it (both sides scaled, aspect kept) — so `drawn` never exceeds the
60
+ * canvas, which is what bounds the sharp pre-fit at one canvas of RGBA. `fit`:
61
+ * contain → the image scaled inside the box, centred; cover → the box itself.
62
+ * The only post-processing is rounding `drawn` DOWN to even, floored at 2 × 2.
63
+ * Differences from Image Overlay's copies (on purpose): no 8192 edge shrink,
64
+ * the canvas clamp, the even rounding.
65
+ */
66
+ export function resolveVideoOverlayGeometry(
67
+ canvas: VideoOverlayCanvas,
68
+ layer: Pick<VideoOverlayLayer, "anchor" | "x" | "y" | "width" | "height" | "fit">,
69
+ imageAspect: number,
70
+ ): VideoOverlayGeometry {
71
+ const aspect = Number.isFinite(imageAspect) && imageAspect > 0 ? imageAspect : 1
72
+ let bw = Math.max(1, Math.round((layer.width / 100) * canvas.w))
73
+ let bh = layer.height !== undefined ? Math.max(1, Math.round((layer.height / 100) * canvas.h)) : Math.max(1, Math.round(bw / aspect))
74
+ if (layer.height === undefined && bh > canvas.h) {
75
+ bw = Math.max(1, Math.round(bw * (canvas.h / bh)))
76
+ bh = canvas.h
77
+ }
78
+ const [ax, ay] = anchorFactors(layer.anchor)
79
+ const left = Math.round(ax * (canvas.w - bw) + (layer.x / 100) * canvas.w)
80
+ const top = Math.round(ay * (canvas.h - bh) + (layer.y / 100) * canvas.h)
81
+ let dw: number
82
+ let dh: number
83
+ if (layer.fit === "cover") {
84
+ dw = bw
85
+ dh = bh
86
+ } else if (bw / bh > aspect) {
87
+ dh = bh
88
+ dw = bh * aspect
89
+ } else {
90
+ dw = bw
91
+ dh = bw / aspect
92
+ }
93
+ const width = evenFloor(dw)
94
+ const height = evenFloor(dh)
95
+ return {
96
+ box: { left, top, width: bw, height: bh },
97
+ drawn: { left: left + Math.floor((bw - width) / 2), top: top + Math.floor((bh - height) / 2), width, height },
98
+ }
99
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Video Overlay — internal readers of a value as a writer sent it, shared by
3
+ * `video-overlay.ts` and `video-overlay-validate.ts`. Not exported from any
4
+ * entry, so they add no public names; this file imports types only, so
5
+ * importing it creates no runtime cycle.
6
+ */
7
+ import type { VideoOverlayFit, VideoOverlayLayerInput } from "./video-overlay.js"
8
+
9
+ export function isFit(v: unknown): v is VideoOverlayFit {
10
+ return v === "contain" || v === "cover"
11
+ }
12
+
13
+ /**
14
+ * A `layers[]` entry as a layer, or null when it is not a plain object. Layer
15
+ * arrays reach this module from untrusted workflow JSON (the MCP write sites
16
+ * type nodes as `record<string, unknown>`), so a bare string / number / array
17
+ * entry is read as an ABSENT layer — never spread, never `in`-probed.
18
+ */
19
+ export function asLayer(v: unknown): VideoOverlayLayerInput | null {
20
+ return v !== null && typeof v === "object" && !Array.isArray(v) ? (v as VideoOverlayLayerInput) : null
21
+ }
22
+
23
+ export const nonEmpty = (v: unknown): v is string => typeof v === "string" && v.length > 0
24
+ /** A stored `layout`, `""` read as absent like `null` (a cleared layout never refuses a run); anything else as stored, for the validator to judge. */
25
+ export const storedLayout = (v: string | null | undefined): string | undefined => (v == null || v === "" ? undefined : v)
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Video Overlay layouts — the ids, and what each one needs. A layout is a
3
+ * named shortcut that writes the boxes (`expandVideoOverlayLayout` in
4
+ * `video-overlay-layouts.ts`); like a placement preset, it is a TAG and the
5
+ * boxes are the truth, except for the two stacks, whose boxes depend on the
6
+ * sources' shapes and are resolved where those are known.
7
+ *
8
+ * Dependency-free on purpose: the validator in `video-overlay-validate.ts`
9
+ * reads these, and `video-overlay-layouts.ts` imports the contract in
10
+ * `video-overlay.ts`, so they cannot live in either without a cycle. Wire contract only — no I/O.
11
+ */
12
+
13
+ /**
14
+ * - `video-bottom` / `video-top`: the base whole, full width, against that edge.
15
+ * - `stack-whole`: the base directly above the first video layer, both whole,
16
+ * the same width, the pair centred.
17
+ * - `stack-filled`: the base fills the top half, the first video layer the
18
+ * bottom half, both cropped (`cover`).
19
+ * - `pip`: the base fills the frame, the first video layer sits in a corner.
20
+ */
21
+ export const VIDEO_OVERLAY_LAYOUT_IDS = ["video-bottom", "video-top", "stack-whole", "stack-filled", "pip"] as const
22
+ export type VideoOverlayLayoutId = (typeof VIDEO_OVERLAY_LAYOUT_IDS)[number]
23
+
24
+ export function isVideoOverlayLayoutId(v: unknown): v is VideoOverlayLayoutId {
25
+ return typeof v === "string" && (VIDEO_OVERLAY_LAYOUT_IDS as readonly string[]).includes(v)
26
+ }
27
+
28
+ /** Layouts placed against the output canvas's edges or halves: every one but `pip`. */
29
+ const NEEDS_ASPECT: ReadonlySet<VideoOverlayLayoutId> = new Set(["video-bottom", "video-top", "stack-whole", "stack-filled"])
30
+ /** Layouts that place the first video layer. */
31
+ const NEEDS_VIDEO_LAYER: ReadonlySet<VideoOverlayLayoutId> = new Set(["stack-whole", "stack-filled", "pip"])
32
+ /** Layouts that place the base themselves, so take no `baseBox`. */
33
+ const PLACES_BASE: ReadonlySet<VideoOverlayLayoutId> = new Set(["stack-whole", "stack-filled"])
34
+
35
+ /** True when the layout is refused without an `outputAspect` (`layout_needs_aspect`). */
36
+ export function videoOverlayLayoutNeedsAspect(id: VideoOverlayLayoutId): boolean {
37
+ return NEEDS_ASPECT.has(id)
38
+ }
39
+
40
+ /** True when the layout is refused without a video layer (`layout_needs_video_layer`). */
41
+ export function videoOverlayLayoutNeedsVideoLayer(id: VideoOverlayLayoutId): boolean {
42
+ return NEEDS_VIDEO_LAYER.has(id)
43
+ }
44
+
45
+ /** True when the layout places the base itself and is refused with a `baseBox` (`layout_conflicts_base_box`): the two stacks. */
46
+ export function videoOverlayLayoutPlacesBase(id: VideoOverlayLayoutId): boolean {
47
+ return PLACES_BASE.has(id)
48
+ }
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Video Overlay layouts and the placed base — the request-level normaliser
3
+ * (`expandVideoOverlayLayout`) and the geometry the canvas preview and the
4
+ * ffmpeg worker both call, so the preview and the render cannot disagree.
5
+ * A sibling of `video-overlay.ts`: it imports from there, nothing there imports
6
+ * from here, and the layout ids live in the dependency-free
7
+ * `video-overlay-layout-ids.ts`.
8
+ *
9
+ * - `video-bottom` / `video-top` write a base box; an explicit one wins.
10
+ * - `pip` writes the first video layer's box in its corner.
11
+ * - The two stacks write no box: their rects depend on the sources' shapes,
12
+ * known only after probing, so the worker and the preview call
13
+ * `resolveVideoOverlayStackRects` with them. A stack places the base
14
+ * itself, so the validator refuses one with a `baseBox` (`layout_conflicts_base_box`).
15
+ * `pip` and the two stacks turn the first video layer's fade off;
16
+ * `video-bottom` / `video-top` touch no layer. "First video layer" is the
17
+ * lowest one (`firstVideoLayerIndex`); image layers are left where they are.
18
+ * A probed video's aspect goes through `clampVideoOverlayAspect` before any of
19
+ * this geometry, and a video's rect through `evenVideoOverlayRect` after it —
20
+ * in the worker and the preview alike.
21
+ * Wire contract only — no I/O.
22
+ */
23
+ import {
24
+ VIDEO_OVERLAY_BOX_FIELDS,
25
+ expandVideoOverlayLayer,
26
+ isVideoOverlayCorner,
27
+ videoOverlayRenderOrder,
28
+ type VideoOverlayBox,
29
+ type VideoOverlayBoxInput,
30
+ type VideoOverlayCorner,
31
+ type VideoOverlayFit,
32
+ type VideoOverlayLayer,
33
+ type VideoOverlayLayerInput,
34
+ type VideoOverlayOrderable,
35
+ } from "./video-overlay.js"
36
+ import { resolveVideoOverlayGeometry, type VideoOverlayCanvas, type VideoOverlayRect } from "./video-overlay-geometry.js"
37
+ import { validateVideoOverlayRequest } from "./video-overlay-validate.js"
38
+ import { isVideoOverlayVideoLayer } from "./video-overlay-video-layers.js"
39
+
40
+ /** Picture in picture: the inset's width and its margin from the corner, % of the output canvas (Speaker View's inset). */
41
+ export const VIDEO_OVERLAY_PIP_WIDTH = 30
42
+ export const VIDEO_OVERLAY_PIP_INSET = 4
43
+
44
+ /** What a layout reads and writes — a request, an assembled request, or node data. */
45
+ export interface VideoOverlayLayoutFields {
46
+ readonly layout?: string | null
47
+ readonly baseBox?: VideoOverlayBoxInput | null
48
+ readonly layers?: ReadonlyArray<VideoOverlayLayerInput | null | undefined> | null
49
+ }
50
+
51
+ /** The base box each edge layout writes: the base whole, full width, flush on that edge. */
52
+ const EDGE_BASE_BOXES: { readonly [L in "video-bottom" | "video-top"]: VideoOverlayBox } = {
53
+ "video-bottom": { anchor: "bottom", x: 0, y: 0, width: 100, fit: "contain" },
54
+ "video-top": { anchor: "top", x: 0, y: 0, width: 100, fit: "contain" },
55
+ }
56
+
57
+ /** A base box's trailing defaults, as a layer's (`expandVideoOverlayLayer`). */
58
+ const BOX_DEFAULTS = { x: 0, y: 0, fit: "contain" } as const
59
+
60
+ /**
61
+ * The narrowest and widest aspect a probed video is placed at. A video's
62
+ * shape is only known from its probe, and nothing bounds a probe, so a stack
63
+ * of a 1:1000 sliver could otherwise place a rect off the canvas. Inside these
64
+ * bounds every stack, base and layer rect stays on it.
65
+ */
66
+ export const VIDEO_OVERLAY_ASPECT_BOUNDS = [1 / 8, 8] as const
67
+
68
+ /** Rounded down to even, floored at 2; the epsilon absorbs float error at an exact even size (960.0000 read as 959.9999). */
69
+ const evenFloor = (n: number): number => Math.max(2, Math.floor(n / 2 + 1e-9) * 2)
70
+ const usableAspect = (a: number): number => (Number.isFinite(a) && a > 0 ? a : 1)
71
+
72
+ /**
73
+ * A probed video's display aspect (width ÷ height), held inside
74
+ * `VIDEO_OVERLAY_ASPECT_BOUNDS`; one that is not a positive finite number
75
+ * reads as square, as in the layer geometry. The worker and the preview pass
76
+ * every video's aspect (the base's and each video layer's) through this before
77
+ * any placement, so they place the same rects.
78
+ */
79
+ export function clampVideoOverlayAspect(aspect: number): number {
80
+ const [min, max] = VIDEO_OVERLAY_ASPECT_BOUNDS
81
+ return Number.isFinite(aspect) && aspect > 0 ? Math.min(max, Math.max(min, aspect)) : 1
82
+ }
83
+
84
+ /** Rounded down to an even integer, negatives included (−61 → −62). */
85
+ const floorEven = (n: number): number => Math.floor(n / 2) * 2
86
+
87
+ /**
88
+ * A video's rect as the render draws it: left and top rounded DOWN to even,
89
+ * and the size down to even. ffmpeg's overlay on yuv420 clears the low bit of
90
+ * an odd x or y (a base placed at top 371 is drawn at 370), so this is where
91
+ * the picture lands anyway; the worker hands the graph these numbers and the
92
+ * preview draws them, so the two agree to the pixel. A stack's two rects move
93
+ * by the same pixel (its heights are even), so its join stays exact. Applied
94
+ * to the base's rect and to video layers only — an image layer's geometry is
95
+ * unchanged. By reference when the rect is already even.
96
+ */
97
+ export function evenVideoOverlayRect(rect: VideoOverlayRect): VideoOverlayRect {
98
+ const even = { left: floorEven(rect.left), top: floorEven(rect.top), width: evenFloor(rect.width), height: evenFloor(rect.height) }
99
+ return sameShallow(even, rect) ? rect : even
100
+ }
101
+
102
+ function sameShallow(a: object, b: object): boolean {
103
+ const ka = Object.keys(a)
104
+ return ka.length === Object.keys(b).length && ka.every((k) => (a as Record<string, unknown>)[k] === (b as Record<string, unknown>)[k])
105
+ }
106
+
107
+ /** The lowest video layer by `videoOverlayRenderOrder`, as its index in `layers`; -1 when there is none. */
108
+ export function firstVideoLayerIndex(
109
+ layers: ReadonlyArray<(VideoOverlayOrderable & { readonly videoUrl?: string | null }) | null | undefined> | null | undefined,
110
+ ): number {
111
+ if (!Array.isArray(layers)) return -1
112
+ return videoOverlayRenderOrder(layers).find((i) => isVideoOverlayVideoLayer(layers[i])) ?? -1
113
+ }
114
+
115
+ /**
116
+ * An explicit base box with `anchor` and `width` gets the layer's trailing
117
+ * defaults (x 0, y 0, fit contain) and loses its `null` fields; anything else
118
+ * (a partial box, a non-object) is returned untouched for the validator. By
119
+ * reference when nothing changes.
120
+ */
121
+ function expandBaseBox(raw: VideoOverlayBoxInput): VideoOverlayBoxInput {
122
+ if (typeof raw !== "object" || Array.isArray(raw) || raw.anchor == null || raw.width == null) return raw
123
+ const out: Record<string, unknown> = { ...BOX_DEFAULTS }
124
+ for (const [k, v] of Object.entries(raw)) if (v != null) out[k] = v
125
+ return sameShallow(out, raw) ? raw : (out as VideoOverlayBoxInput)
126
+ }
127
+
128
+ function pipBox(corner: VideoOverlayCorner): VideoOverlayBox {
129
+ const sx = corner.endsWith("left") ? 1 : -1
130
+ const sy = corner.startsWith("top") ? 1 : -1
131
+ return { anchor: corner, x: sx * VIDEO_OVERLAY_PIP_INSET, y: sy * VIDEO_OVERLAY_PIP_INSET, width: VIDEO_OVERLAY_PIP_WIDTH, fit: "contain" }
132
+ }
133
+
134
+ /**
135
+ * The validator's per-layer verdict on this layer alone (a one-layer request
136
+ * meets no request-level check). A layout never repairs a layer it refuses — a
137
+ * bad or partial box, a non-boolean `animate`, two sources, a bad time or
138
+ * volume — so the verdict is the same before and after the expansion, as
139
+ * `expandBaseBox` leaves a partial base box for the validator.
140
+ */
141
+ const acceptedAlone = (layer: VideoOverlayLayerInput): boolean => validateVideoOverlayRequest({ layers: [layer] }).ok
142
+
143
+ /**
144
+ * The first video layer under `pip` or a stack, the layouts that place it:
145
+ * `pip` replaces its box (as a preset click does: height and tag go), and each
146
+ * of them turns its fade off. A layer the validator would refuse is returned
147
+ * untouched.
148
+ */
149
+ function placeFirstVideoLayer(layout: string, layer: VideoOverlayLayerInput): VideoOverlayLayerInput {
150
+ if (!acceptedAlone(layer)) return layer
151
+ if (layout !== "pip") return layer.animate === false ? layer : { ...layer, animate: false }
152
+ const rest: Record<string, unknown> = { ...layer }
153
+ for (const f of VIDEO_OVERLAY_BOX_FIELDS) delete rest[f]
154
+ delete rest.preset
155
+ const corner = isVideoOverlayCorner(layer.corner) ? layer.corner : "bottom-right"
156
+ const next = expandVideoOverlayLayer({ ...rest, ...pipBox(corner), animate: false } as VideoOverlayLayerInput)
157
+ return sameShallow(next, layer) ? layer : next
158
+ }
159
+
160
+ /**
161
+ * The request-level normaliser: what a `layout` writes, and an explicit base
162
+ * box's defaults. Called at the write boundaries and by the worker after the
163
+ * validator. An explicit `baseBox` wins over `video-bottom` / `video-top`;
164
+ * `pip` places the first video layer; the stacks write no box. An unknown
165
+ * layout writes nothing (the validator refuses it), and neither does any
166
+ * layout to a first video layer the validator refuses, so the verdict is the
167
+ * same before and after. Never mutates; the request BY REFERENCE when nothing
168
+ * changes; idempotent.
169
+ */
170
+ export function expandVideoOverlayLayout<T extends VideoOverlayLayoutFields>(req: T): T & { readonly baseBox?: VideoOverlayBox } {
171
+ const { layout } = req
172
+ const baseBox =
173
+ req.baseBox != null ? expandBaseBox(req.baseBox) : layout === "video-bottom" || layout === "video-top" ? EDGE_BASE_BOXES[layout] : req.baseBox
174
+ let layers = req.layers
175
+ const first = layout === "pip" || layout === "stack-whole" || layout === "stack-filled" ? firstVideoLayerIndex(req.layers) : -1
176
+ if (first >= 0 && Array.isArray(req.layers)) {
177
+ const layer = req.layers[first] as VideoOverlayLayerInput
178
+ const placed = placeFirstVideoLayer(layout as string, layer)
179
+ if (placed !== layer) layers = req.layers.map((l, i) => (i === first ? placed : l))
180
+ }
181
+ if (baseBox === req.baseBox && layers === req.layers) return req as T & { readonly baseBox?: VideoOverlayBox }
182
+ // Only the changed fields: an unset one never becomes an `undefined` key.
183
+ return {
184
+ ...req,
185
+ ...(baseBox !== req.baseBox ? { baseBox } : {}),
186
+ ...(layers !== req.layers ? { layers } : {}),
187
+ } as T & { readonly baseBox?: VideoOverlayBox }
188
+ }
189
+
190
+ /**
191
+ * The two stacked rects, `top` for the base and `bottom` for the first video
192
+ * layer, in output pixels.
193
+ * - `stack-whole`: both whole, the same even width, touching, the pair centred
194
+ * with equal spare room above and below (±1 px). They shrink together only
195
+ * when both together are taller than the canvas. The join is pixel-exact.
196
+ * - `stack-filled`: the top half (rounded down to even) and the rest, full
197
+ * width; the aspects are not read — both are cropped (`cover`).
198
+ * An aspect that is not a positive finite number reads as square.
199
+ */
200
+ export function resolveVideoOverlayStackRects(
201
+ layout: "stack-whole" | "stack-filled",
202
+ canvas: VideoOverlayCanvas,
203
+ topAspect: number,
204
+ bottomAspect: number,
205
+ ): { top: VideoOverlayRect; bottom: VideoOverlayRect } {
206
+ if (layout === "stack-filled") {
207
+ const half = evenFloor(canvas.h / 2)
208
+ return {
209
+ top: { left: 0, top: 0, width: canvas.w, height: half },
210
+ bottom: { left: 0, top: half, width: canvas.w, height: canvas.h - half },
211
+ }
212
+ }
213
+ const a = usableAspect(topAspect)
214
+ const b = usableAspect(bottomAspect)
215
+ const total = canvas.w / a + canvas.w / b
216
+ const width = evenFloor(total > canvas.h ? (canvas.w * canvas.h) / total : canvas.w)
217
+ const th = evenFloor(width / a)
218
+ const bh = evenFloor(width / b)
219
+ const top = Math.floor((canvas.h - th - bh) / 2)
220
+ const left = Math.floor((canvas.w - width) / 2)
221
+ return {
222
+ top: { left, top, width, height: th },
223
+ bottom: { left, top: top + th, width, height: bh },
224
+ }
225
+ }
226
+
227
+ /** A picture placed on the output canvas: its even rect and how it fills it (contain = scaled to the rect, cover = cropped to it). */
228
+ export interface VideoOverlayPlacedRect {
229
+ readonly drawn: VideoOverlayRect
230
+ readonly fit: VideoOverlayFit
231
+ }
232
+
233
+ /** A video layer to place. */
234
+ export interface PlacedVideoOverlayVideoInput {
235
+ /** 0-based index in the request's layers[] (what `firstVideo` names). */
236
+ readonly index: number
237
+ readonly layer: Pick<VideoOverlayLayer, "anchor" | "x" | "y" | "width" | "height" | "fit">
238
+ /** Its display aspect (width ÷ height, rotation and sample aspect resolved); held inside the bounds here. */
239
+ readonly aspect: number
240
+ }
241
+
242
+ export interface VideoOverlayVideoPlacement {
243
+ /** Present when the base is placed (a stack or a base box); absent = the base as before (its own size, or `outputAspect` with `baseFit`). */
244
+ readonly basePlacement?: VideoOverlayPlacedRect
245
+ /** Each video layer's even drawn rect and fit, by request index. */
246
+ readonly layers: ReadonlyMap<number, VideoOverlayPlacedRect>
247
+ }
248
+
249
+ /**
250
+ * Where the base and every video layer draw, on the output canvas — the ONE
251
+ * placement the worker renders with and the canvas preview draws with. Every
252
+ * aspect goes through `clampVideoOverlayAspect` and every rect through
253
+ * `evenVideoOverlayRect` here, so neither caller can skip them.
254
+ * - A stack (`stack-whole` / `stack-filled`): both rects from
255
+ * `resolveVideoOverlayStackRects` with the base's and the first video
256
+ * layer's aspects; that layer's stored box is not read. `stack-filled` draws
257
+ * both `cover`, `stack-whole` both `contain`, whatever fit is stored.
258
+ * - Otherwise a base box (written by `video-bottom` / `video-top`, or explicit)
259
+ * places the base with `resolveVideoOverlayBaseRect` at its own fit.
260
+ * - Every other video layer: its box, `resolveVideoOverlayGeometry`, at its
261
+ * aspect (`pip` has already written its box).
262
+ * An image layer is not placed here: its geometry is unchanged. The caller
263
+ * passes a stack's first video layer among `videos` (the worker refuses a
264
+ * stack whose first video layer it does not keep). Pure.
265
+ */
266
+ export function placeVideoOverlayVideos(input: {
267
+ readonly canvas: VideoOverlayCanvas
268
+ readonly layout?: string | null
269
+ readonly baseBox?: VideoOverlayBox
270
+ readonly baseAspect: number
271
+ /** `firstVideoLayerIndex` of the request's layers: what a stack places under the base. */
272
+ readonly firstVideo: number
273
+ readonly videos: ReadonlyArray<PlacedVideoOverlayVideoInput>
274
+ }): VideoOverlayVideoPlacement {
275
+ const { canvas, layout } = input
276
+ const baseAspect = clampVideoOverlayAspect(input.baseAspect)
277
+ const layers = new Map<number, VideoOverlayPlacedRect>()
278
+ let basePlacement: VideoOverlayPlacedRect | undefined
279
+ if (layout === "stack-whole" || layout === "stack-filled") {
280
+ const first = input.videos.find((v) => v.index === input.firstVideo)
281
+ if (!first) throw new Error(`placeVideoOverlayVideos: the stacked layer ${input.firstVideo} was not kept`)
282
+ const rects = resolveVideoOverlayStackRects(layout, canvas, baseAspect, clampVideoOverlayAspect(first.aspect))
283
+ const fit: VideoOverlayFit = layout === "stack-filled" ? "cover" : "contain"
284
+ basePlacement = { drawn: evenVideoOverlayRect(rects.top), fit }
285
+ layers.set(first.index, { drawn: evenVideoOverlayRect(rects.bottom), fit })
286
+ } else if (input.baseBox) {
287
+ basePlacement = { drawn: evenVideoOverlayRect(resolveVideoOverlayBaseRect(canvas, input.baseBox, baseAspect)), fit: input.baseBox.fit }
288
+ }
289
+ for (const v of input.videos) {
290
+ if (layers.has(v.index)) continue
291
+ const { drawn } = resolveVideoOverlayGeometry(canvas, v.layer, clampVideoOverlayAspect(v.aspect))
292
+ layers.set(v.index, { drawn: evenVideoOverlayRect(drawn), fit: v.layer.fit })
293
+ }
294
+ return { ...(basePlacement ? { basePlacement } : {}), layers }
295
+ }
296
+
297
+ /**
298
+ * Where a placed base draws, in output pixels. Its SIZE is the layer
299
+ * geometry's drawn size (`resolveVideoOverlayGeometry`: the same clamp and even
300
+ * rounding as an image layer); it is then placed by that drawn size against the
301
+ * anchor, plus the x / y offsets — so a contained base sits flush on its
302
+ * anchored edge rather than centred in a box rounded to other numbers (a 16:9
303
+ * base at the bottom of 1080x1920 draws at y 1314–1920, with no strip under it).
304
+ */
305
+ export function resolveVideoOverlayBaseRect(canvas: VideoOverlayCanvas, box: VideoOverlayBox, baseAspect: number): VideoOverlayRect {
306
+ const { drawn } = resolveVideoOverlayGeometry(canvas, box, baseAspect)
307
+ const ax = box.anchor.endsWith("left") ? 0 : box.anchor.endsWith("right") ? 1 : 0.5
308
+ const ay = box.anchor.startsWith("top") ? 0 : box.anchor.startsWith("bottom") ? 1 : 0.5
309
+ return {
310
+ left: Math.round(ax * (canvas.w - drawn.width) + (box.x / 100) * canvas.w),
311
+ top: Math.round(ay * (canvas.h - drawn.height) + (box.y / 100) * canvas.h),
312
+ width: drawn.width,
313
+ height: drawn.height,
314
+ }
315
+ }