@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.
- package/dist/{chunk-4KYLNTR7.cjs → chunk-2PU3AGGS.cjs} +27 -4
- package/dist/chunk-2PU3AGGS.cjs.map +1 -0
- package/dist/{chunk-43TGSZRJ.js → chunk-2QKF7M2Z.js} +3 -3
- package/dist/{chunk-43TGSZRJ.js.map → chunk-2QKF7M2Z.js.map} +1 -1
- package/dist/{chunk-B6BG3LV2.js → chunk-34QLPTSA.js} +3 -3
- package/dist/{chunk-B6BG3LV2.js.map → chunk-34QLPTSA.js.map} +1 -1
- package/dist/chunk-3K24DWOH.js +453 -0
- package/dist/chunk-3K24DWOH.js.map +1 -0
- package/dist/{chunk-IRQ3SPX7.js → chunk-4DVWXEB6.js} +23 -4
- package/dist/chunk-4DVWXEB6.js.map +1 -0
- package/dist/{chunk-ZES6EZC4.js → chunk-4MMZD63H.js} +3 -3
- package/dist/{chunk-ZES6EZC4.js.map → chunk-4MMZD63H.js.map} +1 -1
- package/dist/{chunk-MQZRQ5LM.cjs → chunk-63H4C56Q.cjs} +8 -8
- package/dist/{chunk-MQZRQ5LM.cjs.map → chunk-63H4C56Q.cjs.map} +1 -1
- package/dist/{chunk-IVXSNW2B.cjs → chunk-6BZC2ZHC.cjs} +18 -332
- package/dist/chunk-6BZC2ZHC.cjs.map +1 -0
- package/dist/{chunk-M3SXUUWC.cjs → chunk-6FQBKI2A.cjs} +4 -11
- package/dist/chunk-6FQBKI2A.cjs.map +1 -0
- package/dist/{chunk-673E4KYC.js → chunk-6M563QE6.js} +134 -8
- package/dist/chunk-6M563QE6.js.map +1 -0
- package/dist/chunk-6TGB7ECA.cjs +48 -0
- package/dist/chunk-6TGB7ECA.cjs.map +1 -0
- package/dist/{chunk-XUJC6GHE.cjs → chunk-6XUG4L7X.cjs} +6 -6
- package/dist/{chunk-XUJC6GHE.cjs.map → chunk-6XUG4L7X.cjs.map} +1 -1
- package/dist/{chunk-XZKFZMRT.cjs → chunk-77WU3V3J.cjs} +6 -6
- package/dist/{chunk-XZKFZMRT.cjs.map → chunk-77WU3V3J.cjs.map} +1 -1
- package/dist/{chunk-ZFJN23V4.cjs → chunk-A2PX5IRC.cjs} +4 -4
- package/dist/{chunk-ZFJN23V4.cjs.map → chunk-A2PX5IRC.cjs.map} +1 -1
- package/dist/{chunk-ZDBPQBAA.js → chunk-AE3AAJ4O.js} +3 -3
- package/dist/{chunk-ZDBPQBAA.js.map → chunk-AE3AAJ4O.js.map} +1 -1
- package/dist/chunk-ALRXY4QH.cjs +13 -0
- package/dist/chunk-ALRXY4QH.cjs.map +1 -0
- package/dist/{chunk-UARGJ5IZ.js → chunk-BMJVKYVB.js} +56 -12
- package/dist/chunk-BMJVKYVB.js.map +1 -0
- package/dist/{chunk-6XVHYD5R.js → chunk-CLAKSLXF.js} +4 -9
- package/dist/chunk-CLAKSLXF.js.map +1 -0
- package/dist/chunk-CTANEPMY.js +61 -0
- package/dist/chunk-CTANEPMY.js.map +1 -0
- package/dist/chunk-CZ5IQB3L.js +42 -0
- package/dist/chunk-CZ5IQB3L.js.map +1 -0
- package/dist/{chunk-WGKAOUEQ.cjs → chunk-D34K455O.cjs} +3 -2
- package/dist/chunk-D34K455O.cjs.map +1 -0
- package/dist/chunk-EPXGG27L.js +331 -0
- package/dist/chunk-EPXGG27L.js.map +1 -0
- package/dist/{chunk-3M4BNKFJ.cjs → chunk-F6WGGYQW.cjs} +167 -3
- package/dist/chunk-F6WGGYQW.cjs.map +1 -0
- package/dist/{chunk-7FCTCWHD.js → chunk-FXGNRYQQ.js} +3 -3
- package/dist/{chunk-7FCTCWHD.js.map → chunk-FXGNRYQQ.js.map} +1 -1
- package/dist/{chunk-ZNM2LW3D.cjs → chunk-GMBDLNLD.cjs} +105 -56
- package/dist/chunk-GMBDLNLD.cjs.map +1 -0
- package/dist/{chunk-NJVOJXBS.cjs → chunk-GSKLPI3J.cjs} +104 -49
- package/dist/chunk-GSKLPI3J.cjs.map +1 -0
- package/dist/{chunk-EWS2VFO4.js → chunk-HBXF6RUU.js} +4 -4
- package/dist/{chunk-EWS2VFO4.js.map → chunk-HBXF6RUU.js.map} +1 -1
- package/dist/{chunk-MOMFX32D.js → chunk-HWQ2SYNA.js} +194 -325
- package/dist/chunk-HWQ2SYNA.js.map +1 -0
- package/dist/{chunk-SCMTN57Y.js → chunk-IY3Y462W.js} +3 -3
- package/dist/{chunk-SCMTN57Y.js.map → chunk-IY3Y462W.js.map} +1 -1
- package/dist/{chunk-ZZGQRRN7.js → chunk-KCZHQH2O.js} +6 -306
- package/dist/chunk-KCZHQH2O.js.map +1 -0
- package/dist/{chunk-XROE3CAS.cjs → chunk-KHH54GRP.cjs} +120 -79
- package/dist/chunk-KHH54GRP.cjs.map +1 -0
- package/dist/{chunk-FVVD6XY2.js → chunk-KL6GAYTT.js} +13 -4
- package/dist/chunk-KL6GAYTT.js.map +1 -0
- package/dist/{chunk-FVII3KHN.js → chunk-KMGCHV6O.js} +163 -4
- package/dist/chunk-KMGCHV6O.js.map +1 -0
- package/dist/{chunk-FMXFHJWX.cjs → chunk-L2TVY6XN.cjs} +4 -4
- package/dist/{chunk-FMXFHJWX.cjs.map → chunk-L2TVY6XN.cjs.map} +1 -1
- package/dist/{chunk-FQXRYPCX.cjs → chunk-LH72PQO2.cjs} +505 -68
- package/dist/chunk-LH72PQO2.cjs.map +1 -0
- package/dist/chunk-LMAQUR55.cjs +506 -0
- package/dist/chunk-LMAQUR55.cjs.map +1 -0
- package/dist/{chunk-F5YEMSNK.cjs → chunk-M5OCFGHF.cjs} +571 -30
- package/dist/chunk-M5OCFGHF.cjs.map +1 -0
- package/dist/{chunk-VOWJCUMR.js → chunk-MD4XHED4.js} +3 -3
- package/dist/{chunk-VOWJCUMR.js.map → chunk-MD4XHED4.js.map} +1 -1
- package/dist/chunk-N5HH46JF.cjs +68 -0
- package/dist/chunk-N5HH46JF.cjs.map +1 -0
- package/dist/{chunk-G4XWVWRI.js → chunk-NIAFR5EE.js} +5 -4
- package/dist/chunk-NIAFR5EE.js.map +1 -0
- package/dist/{chunk-CF4S4N5X.js → chunk-O2QOBA6Q.js} +2 -2
- package/dist/{chunk-CF4S4N5X.js.map → chunk-O2QOBA6Q.js.map} +1 -1
- package/dist/{chunk-4GGLKRYI.cjs → chunk-O6TBB4IF.cjs} +2 -2
- package/dist/{chunk-4GGLKRYI.cjs.map → chunk-O6TBB4IF.cjs.map} +1 -1
- package/dist/{chunk-SWVGHAYO.js → chunk-O7RZRUMZ.js} +110 -74
- package/dist/chunk-O7RZRUMZ.js.map +1 -0
- package/dist/{chunk-LLOIAGFB.js → chunk-OV3JTKBY.js} +449 -51
- package/dist/chunk-OV3JTKBY.js.map +1 -0
- package/dist/{chunk-A3FHTSLB.js → chunk-PSKZKLDG.js} +550 -31
- package/dist/chunk-PSKZKLDG.js.map +1 -0
- package/dist/{chunk-VB2ARGQ6.js → chunk-RGNHHIMN.js} +3 -3
- package/dist/chunk-RGNHHIMN.js.map +1 -0
- package/dist/chunk-SMOO5FAH.js +10 -0
- package/dist/chunk-SMOO5FAH.js.map +1 -0
- package/dist/{chunk-5XRRENHD.cjs → chunk-TM5JYSJF.cjs} +170 -17
- package/dist/chunk-TM5JYSJF.cjs.map +1 -0
- package/dist/{chunk-PONP5J5E.cjs → chunk-V24EPI5N.cjs} +13 -3
- package/dist/chunk-V24EPI5N.cjs.map +1 -0
- package/dist/{chunk-RQ4F3AJH.cjs → chunk-V5EEQR2U.cjs} +21 -21
- package/dist/{chunk-RQ4F3AJH.cjs.map → chunk-V5EEQR2U.cjs.map} +1 -1
- package/dist/chunk-WZVIBAKN.cjs +351 -0
- package/dist/chunk-WZVIBAKN.cjs.map +1 -0
- package/dist/{chunk-5M43XMRB.cjs → chunk-X5BAFW3Q.cjs} +8 -8
- package/dist/{chunk-5M43XMRB.cjs.map → chunk-X5BAFW3Q.cjs.map} +1 -1
- package/dist/{chunk-RUHKBEFF.js → chunk-XBTYGQ6Z.js} +63 -10
- package/dist/chunk-XBTYGQ6Z.js.map +1 -0
- package/dist/{chunk-JHTT2V4A.cjs → chunk-XGGZWA4A.cjs} +118 -52
- package/dist/chunk-XGGZWA4A.cjs.map +1 -0
- package/dist/{chunk-5I4T4QR5.cjs → chunk-XGVJGNZW.cjs} +5 -5
- package/dist/{chunk-5I4T4QR5.cjs.map → chunk-XGVJGNZW.cjs.map} +1 -1
- package/dist/{chunk-7ARKVJTN.cjs → chunk-Y35JQPT6.cjs} +228 -383
- package/dist/chunk-Y35JQPT6.cjs.map +1 -0
- package/dist/{chunk-AFQFGZN7.cjs → chunk-Y4GCJJPF.cjs} +8 -6
- package/dist/chunk-Y4GCJJPF.cjs.map +1 -0
- package/dist/{chunk-C77F4ZTL.js → chunk-YUER7TJG.js} +3 -3
- package/dist/{chunk-C77F4ZTL.js.map → chunk-YUER7TJG.js.map} +1 -1
- package/dist/{chunk-HGI2VKIV.js → chunk-YX6TFX7H.js} +67 -14
- package/dist/chunk-YX6TFX7H.js.map +1 -0
- package/dist/{chunk-TWF2OSH4.cjs → chunk-ZPE2ZTJ4.cjs} +4 -4
- package/dist/{chunk-TWF2OSH4.cjs.map → chunk-ZPE2ZTJ4.cjs.map} +1 -1
- package/dist/entries/apps.cjs +44 -44
- package/dist/entries/apps.js +9 -9
- package/dist/entries/credits.cjs +286 -153
- package/dist/entries/credits.d.cts +254 -5
- package/dist/entries/credits.d.ts +254 -5
- package/dist/entries/credits.js +14 -9
- package/dist/entries/entities.cjs +188 -143
- package/dist/entries/entities.d.cts +122 -1
- package/dist/entries/entities.d.ts +122 -1
- package/dist/entries/entities.js +2 -1
- package/dist/entries/llm-models.cjs +77 -57
- package/dist/entries/llm-models.d.cts +85 -5
- package/dist/entries/llm-models.d.ts +85 -5
- package/dist/entries/llm-models.js +2 -2
- package/dist/entries/media.cjs +92 -87
- package/dist/entries/media.d.cts +19 -1
- package/dist/entries/media.d.ts +19 -1
- package/dist/entries/media.js +3 -2
- package/dist/entries/model-catalog.cjs +211 -103
- package/dist/entries/model-catalog.d.cts +135 -19
- package/dist/entries/model-catalog.d.ts +135 -19
- package/dist/entries/model-catalog.js +5 -5
- package/dist/entries/models.cjs +504 -295
- package/dist/entries/models.d.cts +71 -4
- package/dist/entries/models.d.ts +71 -4
- package/dist/entries/models.js +7 -6
- package/dist/entries/nodes.cjs +249 -233
- package/dist/entries/nodes.d.cts +35 -6
- package/dist/entries/nodes.d.ts +35 -6
- package/dist/entries/nodes.js +10 -10
- package/dist/entries/pipeline.cjs +152 -152
- package/dist/entries/pipeline.d.cts +3 -2
- package/dist/entries/pipeline.d.ts +3 -2
- package/dist/entries/pipeline.js +3 -3
- package/dist/entries/runtime-config.cjs +29 -29
- package/dist/entries/runtime-config.d.cts +10 -7
- package/dist/entries/runtime-config.d.ts +10 -7
- package/dist/entries/runtime-config.js +1 -1
- package/dist/entries/social.cjs +177 -177
- package/dist/entries/social.js +2 -2
- package/dist/entries/types.d.cts +8 -0
- package/dist/entries/types.d.ts +8 -0
- package/dist/entries/ugc.cjs +71 -71
- package/dist/entries/ugc.js +4 -4
- package/dist/entries/video.cjs +316 -208
- package/dist/entries/video.d.cts +490 -99
- package/dist/entries/video.d.ts +490 -99
- package/dist/entries/video.js +8 -4
- package/dist/entries/workflow.cjs +102 -102
- package/dist/entries/workflow.d.cts +5 -4
- package/dist/entries/workflow.d.ts +5 -4
- package/dist/entries/workflow.js +2 -2
- package/dist/{gpt-image-2-6-BeZdT-pW.d.cts → gpt-image-2-6-jIRQBRag.d.cts} +6 -0
- package/dist/{gpt-image-2-6-BeZdT-pW.d.ts → gpt-image-2-6-jIRQBRag.d.ts} +6 -0
- package/dist/index.cjs +2727 -2092
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +30 -27
- package/dist/{model-catalog-BgSvskgY.d.ts → model-catalog-C_Eo35tL.d.cts} +158 -14
- package/dist/{model-catalog-BgSvskgY.d.cts → model-catalog-C_Eo35tL.d.ts} +158 -14
- package/dist/{model-constants-DHd9jwQ7.d.cts → model-constants-Bg4ccSQb.d.ts} +427 -34
- package/dist/{model-constants-DHd9jwQ7.d.ts → model-constants-DWcxOmaY.d.cts} +427 -34
- package/package.json +1 -1
- package/src/__tests__/credit-identifiers.test.ts +29 -0
- package/src/__tests__/extend-providers.test.ts +194 -0
- package/src/__tests__/fixtures/mask-composite-quote-parity.json +118 -0
- package/src/__tests__/fixtures/root-exports.baseline.json +68 -0
- package/src/__tests__/gpt-image-2-6-formats.test.ts +4 -1
- package/src/__tests__/grok-video-15-catalog.test.ts +189 -0
- package/src/__tests__/gvp-supported-providers.test.ts +32 -4
- package/src/__tests__/lip-sync-audio-rate.test.ts +74 -0
- package/src/__tests__/lip-sync-levers.test.ts +31 -0
- package/src/__tests__/llm-models.test.ts +132 -3
- package/src/__tests__/llm-price-key.test.ts +152 -1
- package/src/__tests__/minimax-h3-image.test.ts +140 -0
- package/src/__tests__/model-makers.test.ts +49 -11
- package/src/__tests__/model-tree.test.ts +13 -0
- package/src/__tests__/nemotron-transcribe-pricing.test.ts +61 -0
- package/src/__tests__/normalize-node-params.test.ts +25 -0
- package/src/__tests__/pixverse-v6-max-catalog.test.ts +271 -0
- package/src/__tests__/prompt-length-limits.test.ts +4 -0
- package/src/__tests__/retired-video-provider.test.ts +15 -5
- package/src/__tests__/seedance-25-catalog-modes.test.ts +1 -1
- package/src/__tests__/seedance-task-type.test.ts +188 -0
- package/src/__tests__/seedream-5-5.test.ts +117 -0
- package/src/__tests__/transcribe-capabilities.test.ts +39 -2
- package/src/__tests__/transcribe-preflight.test.ts +50 -1
- package/src/__tests__/unit-contract-compose.test.ts +27 -1
- package/src/__tests__/unit-contracts.test.ts +20 -6
- package/src/__tests__/upscale-factors.test.ts +107 -0
- package/src/__tests__/video-audio-capability.test.ts +35 -6
- package/src/__tests__/video-character-refs.test.ts +20 -2
- package/src/__tests__/video-collapse-parity.test.ts +19 -0
- package/src/__tests__/video-overlay-geometry.test.ts +68 -0
- package/src/__tests__/video-overlay-layer-plan.test.ts +3 -4
- package/src/__tests__/video-overlay-layouts.test.ts +529 -0
- package/src/__tests__/video-overlay-pricing.test.ts +61 -0
- package/src/__tests__/video-overlay-validate.test.ts +128 -0
- package/src/__tests__/video-overlay-wired-kind.test.ts +207 -0
- package/src/__tests__/video-overlay.test.ts +280 -194
- package/src/__tests__/video-ref-limits.test.ts +2 -1
- package/src/__tests__/video-reference-only.test.ts +6 -2
- package/src/__tests__/video-resolution-billed-as-named.test.ts +30 -0
- package/src/__tests__/video-start-frame-only.test.ts +98 -0
- package/src/__tests__/video-upscale-params.test.ts +62 -0
- package/src/__tests__/wired-character-names.test.ts +220 -0
- package/src/catalog-projection.ts +8 -0
- package/src/credit-estimators/index.ts +18 -0
- package/src/credit-estimators/nemotron-transcribe.ts +87 -0
- package/src/credit-estimators/video-overlay.ts +70 -0
- package/src/credit-identifiers.ts +183 -16
- package/src/entity-image-url.ts +21 -0
- package/src/entries/credits.ts +26 -1
- package/src/entries/entities.ts +14 -0
- package/src/entries/llm-models.ts +6 -0
- package/src/entries/model-catalog.ts +44 -1
- package/src/entries/models.ts +69 -0
- package/src/entries/nodes.ts +4 -0
- package/src/entries/video.ts +7 -1
- package/src/freecut-protocol.ts +8 -0
- package/src/generated/unit-contracts.ts +8 -1
- package/src/gpt-image-2-6.ts +6 -0
- package/src/input-image-pricing.ts +76 -0
- package/src/lip-sync-levers.ts +56 -0
- package/src/lip-sync-pricing.ts +91 -1
- package/src/llm-models.ts +249 -4
- package/src/mask-composite.ts +11 -0
- package/src/minimax-h3-image.ts +61 -0
- package/src/model-catalog.ts +604 -40
- package/src/model-constants.ts +860 -55
- package/src/model-tree.ts +2 -1
- package/src/nodaro-video-upscale.ts +48 -0
- package/src/node-default-mappings.ts +15 -2
- package/src/node-execution-state.ts +4 -3
- package/src/normalize-node-params.ts +49 -1
- package/src/producer-types.ts +23 -1
- package/src/runtime-config/contract.ts +10 -7
- package/src/seedance-draft.ts +2 -1
- package/src/seedance-task-type.ts +37 -0
- package/src/seedream-5-5.ts +45 -0
- package/src/transcribe-preflight.ts +58 -7
- package/src/unit-contract-compose.ts +4 -1
- package/src/upscale-factors.ts +111 -0
- package/src/video-character-refs.ts +7 -4
- package/src/video-duration.ts +9 -0
- package/src/video-overlay-geometry.ts +99 -0
- package/src/video-overlay-input.ts +25 -0
- package/src/video-overlay-layout-ids.ts +48 -0
- package/src/video-overlay-layouts.ts +315 -0
- package/src/video-overlay-validate.ts +223 -0
- package/src/video-overlay-video-layers.ts +304 -0
- package/src/video-overlay.ts +165 -297
- package/src/video-ui-defaults.ts +11 -7
- package/src/video-upscale-params.ts +67 -0
- package/src/wired-character-names.ts +202 -0
- package/dist/chunk-3M4BNKFJ.cjs.map +0 -1
- package/dist/chunk-4KYLNTR7.cjs.map +0 -1
- package/dist/chunk-5XRRENHD.cjs.map +0 -1
- package/dist/chunk-673E4KYC.js.map +0 -1
- package/dist/chunk-6XVHYD5R.js.map +0 -1
- package/dist/chunk-7ARKVJTN.cjs.map +0 -1
- package/dist/chunk-7WGKP3EU.js +0 -23
- package/dist/chunk-7WGKP3EU.js.map +0 -1
- package/dist/chunk-A3FHTSLB.js.map +0 -1
- package/dist/chunk-AFQFGZN7.cjs.map +0 -1
- package/dist/chunk-F5YEMSNK.cjs.map +0 -1
- package/dist/chunk-FQXRYPCX.cjs.map +0 -1
- package/dist/chunk-FVII3KHN.js.map +0 -1
- package/dist/chunk-FVVD6XY2.js.map +0 -1
- package/dist/chunk-G4XWVWRI.js.map +0 -1
- package/dist/chunk-HGI2VKIV.js.map +0 -1
- package/dist/chunk-IRQ3SPX7.js.map +0 -1
- package/dist/chunk-IVXSNW2B.cjs.map +0 -1
- package/dist/chunk-JHTT2V4A.cjs.map +0 -1
- package/dist/chunk-KHZAQGRP.js +0 -17
- package/dist/chunk-KHZAQGRP.js.map +0 -1
- package/dist/chunk-LLOIAGFB.js.map +0 -1
- package/dist/chunk-M3SXUUWC.cjs.map +0 -1
- package/dist/chunk-MOMFX32D.js.map +0 -1
- package/dist/chunk-NCOGGRRP.cjs +0 -27
- package/dist/chunk-NCOGGRRP.cjs.map +0 -1
- package/dist/chunk-NJVOJXBS.cjs.map +0 -1
- package/dist/chunk-PONP5J5E.cjs.map +0 -1
- package/dist/chunk-RUHKBEFF.js.map +0 -1
- package/dist/chunk-SWVGHAYO.js.map +0 -1
- package/dist/chunk-UARGJ5IZ.js.map +0 -1
- package/dist/chunk-VB2ARGQ6.js.map +0 -1
- package/dist/chunk-WGKAOUEQ.cjs.map +0 -1
- package/dist/chunk-XROE3CAS.cjs.map +0 -1
- package/dist/chunk-ZLDFPVVI.cjs +0 -19
- package/dist/chunk-ZLDFPVVI.cjs.map +0 -1
- package/dist/chunk-ZNM2LW3D.cjs.map +0 -1
- 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
|
+
}
|