hyperframes 0.8.210 → 0.8.212
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/{add-36M7YRR4.js → add-JSM7YBQX.js} +28 -24
- package/dist/{agentPromptGenerator-4NJ252MR.js → agentPromptGenerator-NTPYCKOI.js} +30 -1
- package/dist/{animatedGifPrep-RZLTC77F.js → animatedGifPrep-XTK7UWXF.js} +11 -10
- package/dist/api.js +26 -25
- package/dist/{appHistory-OHYU5ZBQ.js → appHistory-BCWH6XYH.js} +3 -3
- package/dist/{asset-HRGZ7ZCB.js → asset-SMY2EGPH.js} +11 -5
- package/dist/{assetCataloger-LN7RI2IC.js → assetCataloger-CVPWY34W.js} +12 -11
- package/dist/{audio-ULOHC2KL.js → audio-Y4OYLTWN.js} +37 -33
- package/dist/{auth-K4ZULHQY.js → auth-MDEHZR7R.js} +11 -6
- package/dist/{autoUpdate-MUJ4WPP6.js → autoUpdate-3FL6EDPM.js} +12 -5
- package/dist/{backgroundChecks-O6JST752.js → backgroundChecks-A6TG2BT3.js} +10 -5
- package/dist/backgroundChecksWorker.js +11 -5
- package/dist/{batchRender-U742UVOD.js → batchRender-K2PBRRTQ.js} +14 -9
- package/dist/{beats-2CSE5WJD.js → beats-RA6XK6J5.js} +25 -21
- package/dist/{benchmark-YJB2YKOE.js → benchmark-EHU5O4PP.js} +32 -27
- package/dist/{browser-WJ5E7RYS.js → browser-7RUIZT2H.js} +27 -22
- package/dist/{bundleWithLocalizedFonts-F5VQMFHZ.js → bundleWithLocalizedFonts-O2U2FYY2.js} +7 -3
- package/dist/{capture-6OJDKKEZ.js → capture-77KDKKNK.js} +25 -24
- package/dist/{capture-IYV3OS5W.js → capture-JGYBORAG.js} +19 -14
- package/dist/{captureCompositionFrame-7357PUMG.js → captureCompositionFrame-DZ7EHPZV.js} +23 -18
- package/dist/{catalog-CZBK33QH.js → catalog-CUP3SYAI.js} +43 -39
- package/dist/{catch-up-7IJQ7AUR.js → catch-up-ZGUCWH5Q.js} +21 -17
- package/dist/{check-ISUFX4DK.js → check-ITGFVBT6.js} +60 -56
- package/dist/{checkAudio-GAA2SY5E.js → checkAudio-CTLPD6YT.js} +19 -15
- package/dist/{checkBrowser-JRADOMED.js → checkBrowser-G2N4JI6N.js} +52 -48
- package/dist/{chunk-J7A73K2B.js → chunk-24F7TOW2.js} +99 -44
- package/dist/{chunk-W3V5EOFA.js → chunk-25MKZTRT.js} +1 -1
- package/dist/chunk-26AQTUU4.js +1103 -0
- package/dist/{chunk-ZTZA4UWZ.js → chunk-2GICKZ3I.js} +4 -1
- package/dist/{chunk-U7CZBDMV.js → chunk-2P5DTXUN.js} +1 -1
- package/dist/{chunk-7BOGLQFM.js → chunk-2YDIEZSF.js} +4 -4
- package/dist/{chunk-UIOZIIB7.js → chunk-32NEJ553.js} +1 -73
- package/dist/{chunk-DHTWYTSV.js → chunk-3JQ2YOKL.js} +2 -2
- package/dist/{chunk-BKXC5XHB.js → chunk-3YBXKWAF.js} +1 -1
- package/dist/{chunk-5IWRGVAX.js → chunk-45JN2GIZ.js} +2 -2
- package/dist/chunk-5766TK7Q.js +145 -0
- package/dist/{chunk-MMJAHBH2.js → chunk-5SKC4G26.js} +4 -1
- package/dist/{chunk-MNNK7RV5.js → chunk-5SWWIT7K.js} +2 -1
- package/dist/{chunk-FCIO4WSW.js → chunk-5TQ4AEPF.js} +3 -3
- package/dist/{chunk-KCLBO65Y.js → chunk-5YPMCCCA.js} +1 -1
- package/dist/{chunk-K2FLNJVB.js → chunk-5ZBMHUY2.js} +5 -1
- package/dist/{chunk-NEKKA2DA.js → chunk-64XQS7AP.js} +2 -2
- package/dist/chunk-6LDHXB4Z.js +36 -0
- package/dist/{chunk-FCXEVKFQ.js → chunk-6SG3RRAQ.js} +4 -4
- package/dist/{chunk-JLCAHJUO.js → chunk-6ZLDIMPL.js} +2 -2
- package/dist/{chunk-DGECWPTL.js → chunk-7KBS6ZLB.js} +2 -2
- package/dist/chunk-7KDQAD2W.js +81 -0
- package/dist/{chunk-AZGVCQGO.js → chunk-7Q5TBUC2.js} +2 -2
- package/dist/{chunk-JHNBF2HD.js → chunk-7TWX4Y7I.js} +4 -4
- package/dist/{chunk-ZRSQNF4A.js → chunk-7W7ANGR4.js} +55 -40
- package/dist/{chunk-WOFTAZSZ.js → chunk-7ZAVTGGT.js} +12 -11
- package/dist/{chunk-BYZPLQSX.js → chunk-A2WPZE2R.js} +1 -1
- package/dist/{chunk-NQ2INEHX.js → chunk-A4ZTSQLW.js} +1 -1
- package/dist/{chunk-ERVBXEPZ.js → chunk-AJAXP4HF.js} +10 -6
- package/dist/{chunk-PCPMSUW6.js → chunk-BLVHVXRU.js} +3 -3
- package/dist/{chunk-5ZJGEQGS.js → chunk-BYRXSKIY.js} +2 -2
- package/dist/{chunk-AF3L5JJX.js → chunk-CCLBOLYU.js} +1 -1
- package/dist/{chunk-4A27M7CJ.js → chunk-CODPTVC2.js} +1 -1
- package/dist/{chunk-VQB7G5BM.js → chunk-CTZJSMGU.js} +1 -1
- package/dist/chunk-DL4OD7IA.js +21 -0
- package/dist/{chunk-JVBRJMOP.js → chunk-DP5LF7GF.js} +8 -2
- package/dist/{chunk-EVTBRL37.js → chunk-DS7ANFBV.js} +5 -5
- package/dist/{chunk-35HSGF46.js → chunk-DVVTBVKA.js} +11 -16
- package/dist/{chunk-6CSYCFQV.js → chunk-DW35FX4I.js} +1 -1
- package/dist/{chunk-WWQJYYAB.js → chunk-DXPC7Z6L.js} +4 -4
- package/dist/{chunk-X2T5EOI7.js → chunk-EC77ZBCP.js} +5 -5
- package/dist/{chunk-VWG7OQKU.js → chunk-EQGKUPBJ.js} +4 -1
- package/dist/{chunk-IMKBZEGT.js → chunk-F5XADOGC.js} +2 -2
- package/dist/chunk-FJ646TIT.js +201 -0
- package/dist/{chunk-GDZA4ALG.js → chunk-FKFGGAXN.js} +52 -7
- package/dist/{chunk-2R5ZKWSV.js → chunk-FLXZ4GZI.js} +1 -1
- package/dist/{chunk-FHIBBIEZ.js → chunk-FW6CYA5D.js} +3 -3
- package/dist/{chunk-QXUFQSSK.js → chunk-G6HUXX3L.js} +1 -1
- package/dist/{chunk-5YHQBCWH.js → chunk-G6OKQMJI.js} +12 -2
- package/dist/{chunk-QSFWGZG6.js → chunk-G7VEYUZ2.js} +16 -132
- package/dist/{chunk-KGG2PUZN.js → chunk-GQ724553.js} +5 -5
- package/dist/{chunk-F7IWJMIO.js → chunk-GVE6I5EL.js} +6 -6
- package/dist/{chunk-66LREXGS.js → chunk-HXZNCXQX.js} +1 -1
- package/dist/{chunk-WERLJGIC.js → chunk-J3RXEDR2.js} +17 -2
- package/dist/{chunk-DKJAK6JW.js → chunk-J7GPSY5N.js} +7 -7
- package/dist/{chunk-5PCT5DDF.js → chunk-JZNQQI5M.js} +5 -5
- package/dist/{chunk-3PTZ2TD4.js → chunk-KUXOAS4Z.js} +1 -1
- package/dist/{chunk-32BLIKEV.js → chunk-KZZWYIEB.js} +3 -3
- package/dist/{chunk-AHPGAESX.js → chunk-L72RQ45A.js} +1 -1
- package/dist/{chunk-FBIWJ3A4.js → chunk-MJCIAZSK.js} +3 -3
- package/dist/{chunk-BW5WYF4N.js → chunk-MX2GMAAW.js} +106 -62
- package/dist/{chunk-JLBJRJO6.js → chunk-N3J2MLXC.js} +3 -3
- package/dist/{chunk-KGAPL42S.js → chunk-N7XJHZ35.js} +1 -1
- package/dist/{chunk-UA3YNZK6.js → chunk-NGSENR4J.js} +16 -6
- package/dist/{chunk-QIDN4ML5.js → chunk-NO6F7CLR.js} +1 -1
- package/dist/{chunk-EQPXSSNG.js → chunk-NXDKBFEO.js} +15 -15
- package/dist/{chunk-I3PNZDKR.js → chunk-OL5E4Y4L.js} +2226 -2081
- package/dist/{chunk-XNFDDVJS.js → chunk-ONMTNYGR.js} +4 -1
- package/dist/{chunk-P2L7NNHT.js → chunk-ORJY6Z6G.js} +3 -3
- package/dist/{chunk-GKNTPIFD.js → chunk-OSCWTA2O.js} +10 -10
- package/dist/{chunk-ZA5TNF4R.js → chunk-OWV36OJP.js} +5 -2
- package/dist/{chunk-YBY2WVLC.js → chunk-P2VGMOX7.js} +5 -5
- package/dist/{chunk-QPX7FJP3.js → chunk-PW7FCVHR.js} +1 -1
- package/dist/{chunk-RUW65P3N.js → chunk-Q55JNFDV.js} +3 -3
- package/dist/{chunk-GNESG4XA.js → chunk-QUXWS5UG.js} +3 -3
- package/dist/{chunk-I4H5JWND.js → chunk-R5B6GXQM.js} +1 -1
- package/dist/{chunk-TGFDRZTM.js → chunk-RDZKBIEB.js} +5 -5
- package/dist/{chunk-OMLVCHNN.js → chunk-RJILJ4OR.js} +3 -3
- package/dist/{chunk-36EOFTVG.js → chunk-RQC4PHO3.js} +1 -1
- package/dist/{chunk-RIJHDTM5.js → chunk-S2HWGG5O.js} +1 -1
- package/dist/chunk-SJGE5I5F.js +131 -0
- package/dist/{chunk-A45HCDG7.js → chunk-SPDSRBIN.js} +31 -5
- package/dist/{chunk-HKCIRH26.js → chunk-SXTWQ7CH.js} +5 -5
- package/dist/{chunk-K4FVGVA6.js → chunk-T2WJO4XM.js} +1 -1
- package/dist/{chunk-EYGWMHXV.js → chunk-T7KNW7PE.js} +4 -4
- package/dist/{chunk-DROFHVQD.js → chunk-TPO32Z65.js} +4 -4
- package/dist/{chunk-P327BIJR.js → chunk-U46JEU26.js} +1 -1
- package/dist/{chunk-HP7BXJFZ.js → chunk-UBUKKTNW.js} +2 -2
- package/dist/{chunk-TDEORHFN.js → chunk-UE4CXHMF.js} +7 -7
- package/dist/{chunk-BN22WCAF.js → chunk-UULZKCBI.js} +2 -2
- package/dist/{chunk-AG566TRI.js → chunk-UXH6E5HC.js} +2 -2
- package/dist/{chunk-W4E3ZOWH.js → chunk-V6OSE6VT.js} +2 -2
- package/dist/{chunk-DST7GU2Y.js → chunk-VKD23SIO.js} +1 -1
- package/dist/{chunk-57QUPSP2.js → chunk-VVDHSRKD.js} +1 -1
- package/dist/{chunk-QI5TLQNW.js → chunk-W2VJTKIW.js} +17 -20
- package/dist/{chunk-HD4KXG5U.js → chunk-W55BW7KA.js} +15 -14
- package/dist/chunk-W5OBRMZ6.js +4870 -0
- package/dist/{chunk-ERUQ3S6D.js → chunk-WE42NVH7.js} +6 -1
- package/dist/{chunk-QRWTVCGH.js → chunk-WVIH5BBZ.js} +30 -23
- package/dist/{chunk-SE2MXV2N.js → chunk-X4SBDDLS.js} +2 -1
- package/dist/{chunk-A2H5EJZM.js → chunk-XEWMJWNW.js} +2 -2
- package/dist/{chunk-LRE4GDFA.js → chunk-XGXTZNES.js} +4 -4
- package/dist/{chunk-YIFEK3UD.js → chunk-XQ26I3PL.js} +1 -1
- package/dist/{chunk-UWEGMKKU.js → chunk-Y3U7ECBH.js} +1 -1
- package/dist/{chunk-MV3J6ZOP.js → chunk-YACECUHX.js} +9 -9
- package/dist/{chunk-MA447PNF.js → chunk-YVT5IU6J.js} +22 -23
- package/dist/{chunk-XCIHCPJK.js → chunk-YWRUQ7XZ.js} +3 -2
- package/dist/{chunk-XIUHHEBS.js → chunk-YX5ELTKV.js} +3 -3
- package/dist/{chunk-P6EXMN5D.js → chunk-ZCHULPJZ.js} +3 -3
- package/dist/{chunk-QFXF5GXE.js → chunk-ZCYSQ3NQ.js} +3 -3
- package/dist/{chunk-RIAWW4G2.js → chunk-ZE57TSS6.js} +2 -2
- package/dist/{clean-NVBEXXIS.js → clean-FBZ7GHRY.js} +39 -35
- package/dist/cli.js +161 -80
- package/dist/{cloud-3T6HF7DT.js → cloud-VYSWJ7UO.js} +11 -6
- package/dist/{cloudrun-TXEEZGJ7.js → cloudrun-U6LI7KLV.js} +39 -30
- package/dist/{colors-HKWSZCGK.js → colors-HRL7QSVG.js} +5 -1
- package/dist/commands/layout-audit.browser.js +1 -1
- package/dist/commands/motion-signature.browser.js +11 -2
- package/dist/{compare-Q42Z56P7.js → compare-YR7BMEHJ.js} +63 -61
- package/dist/{compiler-IL2PZJFH.js → compiler-6YCAUK7Z.js} +4 -4
- package/dist/{component-2IWQZYCZ.js → component-HVSM6FJV.js} +13 -7
- package/dist/{compositions-3EZ3GBK2.js → compositions-QTFL2VNL.js} +27 -23
- package/dist/{delete-2UBY2JTM.js → delete-2FHCQ72T.js} +28 -20
- package/dist/{deploy-QTS2OM2H.js → deploy-6S45QWG6.js} +11 -7
- package/dist/{destroy-CGAZIL2C.js → destroy-BQ5R7LUF.js} +8 -4
- package/dist/{dist-XF53LCKD.js → dist-B4KLCLZ5.js} +3 -3
- package/dist/{dist-73YTUT3W.js → dist-NCI6JOJZ.js} +2 -2
- package/dist/{docs-UEWLIP6D.js → docs-6EM6FDNI.js} +12 -6
- package/dist/{doctor-FIXMXWE6.js → doctor-4MRS6RED.js} +25 -20
- package/dist/{events-7WYSDXTE.js → events-4VBBY7PP.js} +15 -10
- package/dist/{events-NTZSSMBR.js → events-FN45HVPM.js} +14 -11
- package/dist/{feedback-7SOB5GZC.js → feedback-T67P2CDA.js} +41 -35
- package/dist/{ffmpeg-PYY5FSIX.js → ffmpeg-ED7ZK6XH.js} +12 -11
- package/dist/{figma-DTWA3G22.js → figma-UXAWKPOY.js} +10 -5
- package/dist/fontLocalizeCli.js +16 -14
- package/dist/{get-DMGUJPLP.js → get-EFH3PPJA.js} +20 -15
- package/dist/{gpuPolicy-KVYO4OU4.js → gpuPolicy-ZADQMXQT.js} +11 -10
- package/dist/{grade-compare-NCYPJFLI.js → grade-compare-425BFHSF.js} +65 -60
- package/dist/hangReport.js +1 -0
- package/dist/{heifImagePrep-F7LFUYGC.js → heifImagePrep-ZJM7N2XY.js} +12 -11
- package/dist/{help-I4RRBHCW.js → help-23PPB2BD.js} +16 -8
- package/dist/{history-GVBBXZKQ.js → history-CHJV33M5.js} +28 -22
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +64 -64
- package/dist/hyperframes-player.global.js +1 -1
- package/dist/{info-UE2PY5AF.js → info-36YPISVA.js} +22 -18
- package/dist/{init-4UGFGJQK.js → init-U6EE2EIU.js} +73 -65
- package/dist/{inspect-ZRREAUCB.js → inspect-NI2RMUFR.js} +50 -46
- package/dist/{installer-ABXPRFIJ.js → installer-K3HIZ5CF.js} +7 -7
- package/dist/{keyframes-MFR4TYVR.js → keyframes-I6T2IT6I.js} +20 -16
- package/dist/{lambda-E3Z6JCIB.js → lambda-WL64Z2F3.js} +50 -42
- package/dist/{layout-IO7T5SSU.js → layout-R2YZ4N6P.js} +50 -46
- package/dist/{lint-WYPQK5XA.js → lint-IAAG6Z65.js} +30 -24
- package/dist/{lintProject-KCN7MRBN.js → lintProject-EM7Y2ZRB.js} +2 -2
- package/dist/{list-7F2LXWOZ.js → list-3O6743DJ.js} +23 -18
- package/dist/{live-LAHBXVK2.js → live-WWPFZQ74.js} +33 -7
- package/dist/localPage-L5FRBCNP.js +56 -0
- package/dist/{login-TTMYCXN2.js → login-27TRFTYB.js} +17 -13
- package/dist/{logout-QRSB4CNH.js → logout-C6P6ERZ3.js} +12 -7
- package/dist/{manager-OQ5J26ST.js → manager-D6TE4ENP.js} +14 -13
- package/dist/{manager-LQXZTUTJ.js → manager-IZIK7BHN.js} +7 -5
- package/dist/{media-treatment-ELB6WRA5.js → media-treatment-E3YLZVXC.js} +58 -45
- package/dist/{media-use-JBN57JE3.js → media-use-ZRHFRO46.js} +3 -2
- package/dist/{models-D2FNIGNZ.js → models-2Q3TGNH5.js} +40 -28
- package/dist/{motionShot-53VDDRIC.js → motionShot-XYW2HMVI.js} +27 -22
- package/dist/{normalize-audio-QHNCFWR2.js → normalize-audio-D5WNUNDM.js} +42 -28
- package/dist/{open-3KMTT3AV.js → open-3KO7UUPC.js} +33 -29
- package/dist/{parakeetRunner-T65S6FW3.js → parakeetRunner-WX6L6MW5.js} +20 -19
- package/dist/{pipeline-DUVRZGIM.js → pipeline-WYIO4KGN.js} +17 -16
- package/dist/{play-27R6RBSK.js → play-ZM3ZUJSZ.js} +53 -52
- package/dist/{policies-NWIEUGGW.js → policies-J5BWAZHM.js} +18 -12
- package/dist/{preflight-QB6NKBBL.js → preflight-7OMCIXNM.js} +16 -14
- package/dist/{present-RHV3FKI5.js → present-E2PLH2GJ.js} +47 -46
- package/dist/{preview-IAKIXYLN.js → preview-TVRM75FN.js} +52 -48
- package/dist/{producer-F6PHB4M4.js → producer-M5F6KZEF.js} +1 -1
- package/dist/{progress-PX3PVAIM.js → progress-X3QFO3FE.js} +9 -5
- package/dist/{projectConfig-MPHWYY5D.js → projectConfig-VFKGY3XE.js} +11 -11
- package/dist/prompts-VAO7RDKX.js +40 -0
- package/dist/{publication-CBAEINEG.js → publication-AF33R7LF.js} +5 -5
- package/dist/{publish-4A2A6V7Z.js → publish-Z7HGDQ5R.js} +41 -30
- package/dist/{refresh-F7FUCXLX.js → refresh-IYRGLHG5.js} +12 -7
- package/dist/{remove-background-3I7RZGVG.js → remove-background-PN3KCBT4.js} +39 -30
- package/dist/{render-BSKLHCZ4.js → render-I3HBIJX3.js} +82 -77
- package/dist/{render-BGPUHBFC.js → render-IZNPEXMU.js} +17 -12
- package/dist/{render-2HYATL32.js → render-SEODWRRR.js} +46 -41
- package/dist/{render-batch-JD6C3BDD.js → render-batch-MQSORY55.js} +18 -13
- package/dist/renderSetupWorker.js +10 -7
- package/dist/{resolver-SQYR7LII.js → resolver-HXE4F2G4.js} +7 -7
- package/dist/{sam-FHJ7IL7T.js → sam-QA7JT7IM.js} +2 -1
- package/dist/{sherpa-VXD3DAH4.js → sherpa-NPT6S3RP.js} +19 -18
- package/dist/sherpaWorker.js +1 -0
- package/dist/{sites-Q2S3DZY4.js → sites-MTLVMYJ6.js} +7 -3
- package/dist/{skills-B2SHEHWL.js → skills-P3BI55YP.js} +27 -20
- package/dist/{skillsUpdateCheck-ST43UUPK.js → skillsUpdateCheck-43Q4ZHWN.js} +10 -5
- package/dist/{snapshot-USJYNKDM.js → snapshot-YLT64YQS.js} +93 -71
- package/dist/{src-5OX35WPG.js → src-7S7K4QUN.js} +14 -13
- package/dist/{src-PX3VIS7K.js → src-OHJ7USRX.js} +20 -9
- package/dist/{state-JPNCCXAV.js → state-6QHNNHDA.js} +2 -2
- package/dist/{staticProjectServer-ET7H5LMV.js → staticProjectServer-RP3MW2EW.js} +31 -24
- package/dist/{status-QVDRHXW2.js → status-SLILCDBZ.js} +21 -12
- package/dist/studio/assets/{hyperframes-player-DUpxahTX.js → hyperframes-player-DHfuW7Lt.js} +1 -1
- package/dist/studio/assets/{index-CtrcjpbM.js → index-CWgIsKzV.js} +123 -123
- package/dist/studio/assets/{index-B4dcZZAm.js → index-CkjUY33q.js} +1 -1
- package/dist/studio/index.html +1 -1
- package/dist/{studio-api-PLKYSG2X.js → studio-api-BZPZCJL6.js} +17 -15
- package/dist/{studioServer-CNUXGRFS.js → studioServer-QLRIXNYM.js} +74 -70
- package/dist/{synthesize-RVE7IUOJ.js → synthesize-FQML2LN2.js} +5 -5
- package/dist/{system-YD4AW5ZX.js → system-MVRF5UM2.js} +5 -3
- package/dist/{telemetry-EJS5PXH2.js → telemetry-NTO4FJFN.js} +13 -8
- package/dist/{telemetry-DGDEJLGL.js → telemetry-QOBPRUWF.js} +14 -11
- package/dist/templates/blank/index.html +1 -1
- package/dist/{timeline-VCQC4TLM.js → timeline-OLQFVWVU.js} +47 -40
- package/dist/{tokens-AEOBCDW5.js → tokens-BAHLVGEC.js} +12 -6
- package/dist/{transcribe-COFCB3ZB.js → transcribe-3NHUWW4J.js} +45 -39
- package/dist/{transcribe-X6O5ZSGQ.js → transcribe-HR6BFDUR.js} +16 -15
- package/dist/{tts-AGMCPQXE.js → tts-K5HRN6NQ.js} +26 -17
- package/dist/{updateCheck-BW7MDUXZ.js → updateCheck-BGHPCA7J.js} +9 -4
- package/dist/{upgrade-QXOGA54H.js → upgrade-NFI6JOME.js} +28 -14
- package/dist/{urlDownloader-QB3TBIQ5.js → urlDownloader-P35K74RS.js} +10 -9
- package/dist/{usage-HG4WMM7A.js → usage-772JV45U.js} +2 -1
- package/dist/{validate-AU2BZ7D7.js → validate-Q57ZCI4Q.js} +42 -38
- package/dist/{video-GNNYAL5T.js → video-OO2M2AKD.js} +19 -15
- package/dist/warmCheck.js +63 -58
- package/dist/warmCheckClient.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-QRC7IVBC.js +0 -4870
- package/dist/chunk-WMQNIQDJ.js +0 -2057
- package/dist/chunk-WQ6ZXHFQ.js +0 -133
- package/dist/dist-EWXJGN63.js +0 -129
- package/dist/localPage-V3HBGM3Z.js +0 -27
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
removeScratch,
|
|
20
20
|
renameWithRetry,
|
|
21
21
|
renameWithRetryAsync
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-YWRUQ7XZ.js";
|
|
23
23
|
import {
|
|
24
24
|
DISTRIBUTED_FPS,
|
|
25
25
|
MEDIA_VISUAL_STYLE_PROPERTIES,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
renderFrameIdForRenderId,
|
|
41
41
|
resolveAuthoredTimingWindow,
|
|
42
42
|
toFps
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-BYRXSKIY.js";
|
|
44
44
|
import {
|
|
45
45
|
AUDIO_GROUP_RENDER_ID_ATTR,
|
|
46
46
|
AUTHORED_SOURCE_BEGIN,
|
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
sourceTimeAt,
|
|
84
84
|
timeAtSourceTime,
|
|
85
85
|
volumeSegmentSampleCount
|
|
86
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-W5OBRMZ6.js";
|
|
87
87
|
import {
|
|
88
88
|
redactTelemetryString,
|
|
89
89
|
redactUrlQueryStrings
|
|
@@ -98,10 +98,10 @@ import {
|
|
|
98
98
|
exceedsChromeCeiling,
|
|
99
99
|
isManagedChromeDir,
|
|
100
100
|
pickSharedShell
|
|
101
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-WE42NVH7.js";
|
|
102
102
|
import {
|
|
103
103
|
resolveReferencedStart
|
|
104
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-U46JEU26.js";
|
|
105
105
|
import {
|
|
106
106
|
FFMPEG_PATH_ENV,
|
|
107
107
|
FFPROBE_PATH_ENV,
|
|
@@ -113,18 +113,20 @@ import {
|
|
|
113
113
|
} from "./chunk-PBNWRWKA.js";
|
|
114
114
|
import {
|
|
115
115
|
isPathInside
|
|
116
|
-
} from "./chunk-
|
|
116
|
+
} from "./chunk-X4SBDDLS.js";
|
|
117
117
|
import {
|
|
118
118
|
parseHTML
|
|
119
119
|
} from "./chunk-GWTIFRF5.js";
|
|
120
120
|
import {
|
|
121
121
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
122
|
-
describeWslGpuAccess,
|
|
123
|
-
detectWsl,
|
|
124
122
|
getAvailableMemoryMb,
|
|
125
123
|
getSystemTotalMb,
|
|
126
124
|
isLowMemorySystem
|
|
127
|
-
} from "./chunk-
|
|
125
|
+
} from "./chunk-32NEJ553.js";
|
|
126
|
+
import {
|
|
127
|
+
describeWslGpuAccess,
|
|
128
|
+
detectWsl
|
|
129
|
+
} from "./chunk-7KDQAD2W.js";
|
|
128
130
|
|
|
129
131
|
// ../engine/src/config.ts
|
|
130
132
|
import { tmpdir } from "os";
|
|
@@ -675,7 +677,14 @@ ${lines}`].filter(Boolean).join("\n")
|
|
|
675
677
|
}
|
|
676
678
|
}
|
|
677
679
|
async function explainChromeLaunchFailure(error, executablePath, args, signal) {
|
|
678
|
-
if (!
|
|
680
|
+
if (!(error instanceof Error)) return error;
|
|
681
|
+
const { code, errno, syscall } = error;
|
|
682
|
+
if (code === "UNKNOWN" && syscall === "spawn")
|
|
683
|
+
return new Error(
|
|
684
|
+
`Windows refused to start the browser${executablePath ? ` at ${executablePath}` : ""} (error ${errno ?? "unknown"}, spawn UNKNOWN). Security software may be blocking it, or the computer may be out of memory. Close other apps and retry; if it persists, run \`hyperframes browser ensure --force\` to download it again.`,
|
|
685
|
+
{ cause: error }
|
|
686
|
+
);
|
|
687
|
+
if (!executablePath) return error;
|
|
679
688
|
const diagnosis = await diagnoseChromeStartup(executablePath, args ?? [], { signal });
|
|
680
689
|
return new Error(`${error.message}
|
|
681
690
|
${diagnosis}`, { cause: error });
|
|
@@ -1899,2187 +1908,2192 @@ identically under Docker. Consider:
|
|
|
1899
1908
|
`;
|
|
1900
1909
|
}
|
|
1901
1910
|
|
|
1902
|
-
// ../engine/src/services/
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
const held = new Set(ids);
|
|
1909
|
-
window.__HF_RENDER_FRAME_VIDEO_IDS = ids;
|
|
1910
|
-
const hold = (el) => {
|
|
1911
|
-
if (el instanceof HTMLVideoElement && held.has(el.getAttribute(renderIdAttr) || el.id))
|
|
1912
|
-
el.preload = "none";
|
|
1913
|
-
};
|
|
1914
|
-
new MutationObserver((records) => {
|
|
1915
|
-
for (const record2 of records)
|
|
1916
|
-
for (const node of record2.addedNodes) {
|
|
1917
|
-
if (node.nodeType !== 1) continue;
|
|
1918
|
-
hold(node);
|
|
1919
|
-
for (const video of node.querySelectorAll("video")) hold(video);
|
|
1920
|
-
}
|
|
1921
|
-
}).observe(document, { childList: true, subtree: true });
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
// ../engine/src/services/drawElementCaptureError.ts
|
|
1925
|
-
var DrawElementCaptureError = class extends Error {
|
|
1926
|
-
frameIndex;
|
|
1927
|
-
constructor(frameIndex, reason, cause) {
|
|
1928
|
-
super(
|
|
1929
|
-
`drawElement capture failed at frame ${frameIndex}: ${reason}; fresh screenshot capture required`,
|
|
1930
|
-
{ cause }
|
|
1931
|
-
);
|
|
1932
|
-
this.name = "DrawElementCaptureError";
|
|
1933
|
-
Object.defineProperty(this, "deCaptureFailure", { value: true, enumerable: true });
|
|
1934
|
-
this.frameIndex = frameIndex;
|
|
1935
|
-
}
|
|
1936
|
-
};
|
|
1937
|
-
function markRejectionHandled(promise) {
|
|
1938
|
-
promise.catch(() => {
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
function asDrawElementCaptureFailure(frameIndex, encodeResult) {
|
|
1942
|
-
const wrapped = encodeResult.catch((cause) => {
|
|
1943
|
-
if (isDrawElementCaptureError(cause)) throw cause;
|
|
1944
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
1945
|
-
throw new DrawElementCaptureError(frameIndex, reason, cause);
|
|
1946
|
-
});
|
|
1947
|
-
markRejectionHandled(wrapped);
|
|
1948
|
-
return wrapped;
|
|
1949
|
-
}
|
|
1950
|
-
function isDrawElementCaptureError(error) {
|
|
1951
|
-
let current = error;
|
|
1952
|
-
for (let depth = 0; depth < 5 && typeof current === "object" && current !== null; depth++) {
|
|
1953
|
-
if ("deCaptureFailure" in current && current.deCaptureFailure === true) return true;
|
|
1954
|
-
current = "cause" in current ? current.cause : void 0;
|
|
1955
|
-
}
|
|
1956
|
-
return false;
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
// ../engine/src/utils/alphaBlit.ts
|
|
1960
|
-
import { deflateSync, inflateSync } from "zlib";
|
|
1961
|
-
|
|
1962
|
-
// ../engine/src/utils/crc32.ts
|
|
1963
|
-
import * as zlib from "zlib";
|
|
1964
|
-
var nativeCrc32 = typeof zlib.crc32 === "function" ? zlib.crc32 : void 0;
|
|
1965
|
-
function crc32Fallback(data, seed) {
|
|
1966
|
-
let crc = seed ^ 4294967295;
|
|
1967
|
-
for (let i = 0; i < data.length; i++) {
|
|
1968
|
-
crc ^= data[i] ?? 0;
|
|
1969
|
-
for (let bit = 0; bit < 8; bit++) {
|
|
1970
|
-
const mask = -(crc & 1);
|
|
1971
|
-
crc = crc >>> 1 ^ 3988292384 & mask;
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
return (crc ^ 4294967295) >>> 0;
|
|
1975
|
-
}
|
|
1976
|
-
function chunkCrc32(chunkType, chunkData) {
|
|
1977
|
-
const typeBytes = Buffer.from(chunkType, "ascii");
|
|
1978
|
-
if (nativeCrc32) return nativeCrc32(chunkData, nativeCrc32(typeBytes));
|
|
1979
|
-
return crc32Fallback(chunkData, crc32Fallback(typeBytes, 0));
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
// ../engine/src/utils/alphaBlit.ts
|
|
1983
|
-
function paeth(a, b, c) {
|
|
1984
|
-
const p = a + b - c;
|
|
1985
|
-
const pa = Math.abs(p - a);
|
|
1986
|
-
const pb = Math.abs(p - b);
|
|
1987
|
-
const pc = Math.abs(p - c);
|
|
1988
|
-
if (pa <= pb && pa <= pc) return a;
|
|
1989
|
-
if (pb <= pc) return b;
|
|
1990
|
-
return c;
|
|
1911
|
+
// ../engine/src/services/drawElementService.ts
|
|
1912
|
+
var DE_CANVAS_NOT_INITIALIZED_CODE = "HF_DE_CANVAS_NOT_INITIALIZED";
|
|
1913
|
+
function resolveDrawElementCaptureMode(isSwiftShader, transparent) {
|
|
1914
|
+
void transparent;
|
|
1915
|
+
if (isSwiftShader) return "screenshot";
|
|
1916
|
+
return "drawelement";
|
|
1991
1917
|
}
|
|
1992
|
-
function
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
while (pos + 12 <= buf.length) {
|
|
2005
|
-
const chunkLen = buf.readUInt32BE(pos);
|
|
2006
|
-
const chunkType = buf.toString("ascii", pos + 4, pos + 8);
|
|
2007
|
-
const chunkData = buf.subarray(pos + 8, pos + 8 + chunkLen);
|
|
2008
|
-
if (chunkType === "IHDR") {
|
|
2009
|
-
width = chunkData.readUInt32BE(0);
|
|
2010
|
-
height = chunkData.readUInt32BE(4);
|
|
2011
|
-
bitDepth = chunkData[8] ?? 0;
|
|
2012
|
-
colorType = chunkData[9] ?? 0;
|
|
2013
|
-
interlace = chunkData[12] ?? 0;
|
|
2014
|
-
sawIhdr = true;
|
|
2015
|
-
} else if (chunkType === "IDAT") {
|
|
2016
|
-
idatChunks.push(Buffer.from(chunkData));
|
|
2017
|
-
} else if (chunkType === "IEND") {
|
|
2018
|
-
break;
|
|
1918
|
+
function instrumentAcceleratedCanvases() {
|
|
1919
|
+
const w = window;
|
|
1920
|
+
w.__hf_accel_canvases = [];
|
|
1921
|
+
w.__hf_canvas_2d = [];
|
|
1922
|
+
const orig = HTMLCanvasElement.prototype.getContext;
|
|
1923
|
+
HTMLCanvasElement.prototype.getContext = function(type, attrs) {
|
|
1924
|
+
const isAccel = type === "webgl" || type === "webgl2" || type === "experimental-webgl" || type === "webgpu";
|
|
1925
|
+
const ctx = orig.call(this, type, attrs);
|
|
1926
|
+
if (ctx && isAccel) {
|
|
1927
|
+
const list = w.__hf_accel_canvases ?? [];
|
|
1928
|
+
if (!list.includes(this)) list.push(this);
|
|
1929
|
+
w.__hf_accel_canvases = list;
|
|
2019
1930
|
}
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
}
|
|
2025
|
-
if (colorType !== 2 && colorType !== 6) {
|
|
2026
|
-
throw new Error(`${caller}: unsupported color type ${colorType} (expected 2=RGB or 6=RGBA)`);
|
|
2027
|
-
}
|
|
2028
|
-
if (interlace !== 0) {
|
|
2029
|
-
throw new Error(
|
|
2030
|
-
`${caller}: Adam7-interlaced PNGs are not supported (interlace method ${interlace})`
|
|
2031
|
-
);
|
|
2032
|
-
}
|
|
2033
|
-
const channels = colorType === 6 ? 4 : 3;
|
|
2034
|
-
const bpp = channels * (bitDepth / 8);
|
|
2035
|
-
const stride = width * bpp;
|
|
2036
|
-
const compressed = Buffer.concat(idatChunks);
|
|
2037
|
-
const decompressed = inflateSync(compressed);
|
|
2038
|
-
const rawPixels = Buffer.allocUnsafe(height * stride);
|
|
2039
|
-
const prevRow = new Uint8Array(stride);
|
|
2040
|
-
const currRow = new Uint8Array(stride);
|
|
2041
|
-
let srcPos = 0;
|
|
2042
|
-
for (let y = 0; y < height; y++) {
|
|
2043
|
-
const filterType = decompressed[srcPos++] ?? 0;
|
|
2044
|
-
const rawRow = decompressed.subarray(srcPos, srcPos + stride);
|
|
2045
|
-
srcPos += stride;
|
|
2046
|
-
switch (filterType) {
|
|
2047
|
-
case 0:
|
|
2048
|
-
currRow.set(rawRow);
|
|
2049
|
-
break;
|
|
2050
|
-
case 1:
|
|
2051
|
-
for (let x = 0; x < stride; x++) {
|
|
2052
|
-
currRow[x] = (rawRow[x] ?? 0) + (x >= bpp ? currRow[x - bpp] ?? 0 : 0) & 255;
|
|
2053
|
-
}
|
|
2054
|
-
break;
|
|
2055
|
-
case 2:
|
|
2056
|
-
for (let x = 0; x < stride; x++) {
|
|
2057
|
-
currRow[x] = (rawRow[x] ?? 0) + (prevRow[x] ?? 0) & 255;
|
|
2058
|
-
}
|
|
2059
|
-
break;
|
|
2060
|
-
case 3:
|
|
2061
|
-
for (let x = 0; x < stride; x++) {
|
|
2062
|
-
const left = x >= bpp ? currRow[x - bpp] ?? 0 : 0;
|
|
2063
|
-
const up = prevRow[x] ?? 0;
|
|
2064
|
-
currRow[x] = (rawRow[x] ?? 0) + Math.floor((left + up) / 2) & 255;
|
|
2065
|
-
}
|
|
2066
|
-
break;
|
|
2067
|
-
case 4:
|
|
2068
|
-
for (let x = 0; x < stride; x++) {
|
|
2069
|
-
const left = x >= bpp ? currRow[x - bpp] ?? 0 : 0;
|
|
2070
|
-
const up = prevRow[x] ?? 0;
|
|
2071
|
-
const upLeft = x >= bpp ? prevRow[x - bpp] ?? 0 : 0;
|
|
2072
|
-
currRow[x] = (rawRow[x] ?? 0) + paeth(left, up, upLeft) & 255;
|
|
2073
|
-
}
|
|
2074
|
-
break;
|
|
2075
|
-
default:
|
|
2076
|
-
throw new Error(`${caller}: unknown filter type ${filterType} at row ${y}`);
|
|
1931
|
+
if (ctx && type === "2d") {
|
|
1932
|
+
const list2d = w.__hf_canvas_2d ?? [];
|
|
1933
|
+
if (!list2d.includes(this)) list2d.push(this);
|
|
1934
|
+
w.__hf_canvas_2d = list2d;
|
|
2077
1935
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
return { width, height, bitDepth, colorType, rawPixels };
|
|
1936
|
+
return ctx;
|
|
1937
|
+
};
|
|
2082
1938
|
}
|
|
2083
|
-
function
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
if (colorType === 6) {
|
|
2090
|
-
output.set(rawPixels);
|
|
2091
|
-
} else {
|
|
2092
|
-
for (let i = 0; i < width * height; i++) {
|
|
2093
|
-
output[i * 4 + 0] = rawPixels[i * 3 + 0] ?? 0;
|
|
2094
|
-
output[i * 4 + 1] = rawPixels[i * 3 + 1] ?? 0;
|
|
2095
|
-
output[i * 4 + 2] = rawPixels[i * 3 + 2] ?? 0;
|
|
2096
|
-
output[i * 4 + 3] = 255;
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
return { width, height, data: output };
|
|
1939
|
+
function forcePreservedDrawingBuffer() {
|
|
1940
|
+
const orig = HTMLCanvasElement.prototype.getContext;
|
|
1941
|
+
HTMLCanvasElement.prototype.getContext = function(type, attrs) {
|
|
1942
|
+
const isGl = type === "webgl" || type === "webgl2" || type === "experimental-webgl";
|
|
1943
|
+
return orig.call(this, type, isGl ? { ...attrs, preserveDrawingBuffer: true } : attrs);
|
|
1944
|
+
};
|
|
2100
1945
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
const
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
trailer.writeUInt32BE(chunkCrc32(type, body), 0);
|
|
2108
|
-
return Buffer.concat([header, body, trailer]);
|
|
1946
|
+
function classifyGpuRenderer(renderer) {
|
|
1947
|
+
if (!renderer) return void 0;
|
|
1948
|
+
const r = renderer.toLowerCase();
|
|
1949
|
+
const backend = r.includes("swiftshader") ? "swiftshader" : r.includes("metal") ? "metal" : r.includes("direct3d11") || r.includes("d3d11") ? "d3d11" : r.includes("direct3d9") || r.includes("d3d9") ? "d3d9" : r.includes("vulkan") ? "vulkan" : r.includes("opengl") || r.includes("angle") ? "opengl" : "other";
|
|
1950
|
+
const vendor = r.includes("apple") ? "apple" : r.includes("nvidia") ? "nvidia" : r.includes("amd") || r.includes("radeon") ? "amd" : r.includes("intel") ? "intel" : r.includes("microsoft") ? "microsoft" : "other";
|
|
1951
|
+
return `${backend}/${vendor}`;
|
|
2109
1952
|
}
|
|
2110
|
-
function
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
);
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
filtered[y * (stride + 1)] = 0;
|
|
2121
|
-
filtered.set(rgba.subarray(y * stride, (y + 1) * stride), y * (stride + 1) + 1);
|
|
2122
|
-
}
|
|
2123
|
-
const ihdr = Buffer.alloc(13);
|
|
2124
|
-
ihdr.writeUInt32BE(width, 0);
|
|
2125
|
-
ihdr.writeUInt32BE(height, 4);
|
|
2126
|
-
ihdr[8] = 8;
|
|
2127
|
-
ihdr[9] = 6;
|
|
2128
|
-
return Buffer.concat([
|
|
2129
|
-
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
2130
|
-
pngChunk("IHDR", ihdr),
|
|
2131
|
-
pngChunk("IDAT", deflateSync(filtered, { level: PNG_DEFLATE_LEVEL })),
|
|
2132
|
-
pngChunk("IEND", Buffer.alloc(0))
|
|
2133
|
-
]);
|
|
2134
|
-
}
|
|
2135
|
-
function decodePngToRgb48le(buf) {
|
|
2136
|
-
const { width, height, bitDepth, colorType, rawPixels } = decodePngRaw(buf, "decodePngToRgb48le");
|
|
2137
|
-
if (bitDepth !== 16) {
|
|
2138
|
-
throw new Error(`decodePngToRgb48le: unsupported bit depth ${bitDepth} (expected 16)`);
|
|
2139
|
-
}
|
|
2140
|
-
const bpp = colorType === 6 ? 8 : 6;
|
|
2141
|
-
const output = Buffer.allocUnsafe(width * height * 6);
|
|
2142
|
-
for (let y = 0; y < height; y++) {
|
|
2143
|
-
const dstBase = y * width * 6;
|
|
2144
|
-
const srcRowBase = y * width * bpp;
|
|
2145
|
-
for (let x = 0; x < width; x++) {
|
|
2146
|
-
const srcBase = srcRowBase + x * bpp;
|
|
2147
|
-
output[dstBase + x * 6 + 0] = rawPixels[srcBase + 1] ?? 0;
|
|
2148
|
-
output[dstBase + x * 6 + 1] = rawPixels[srcBase + 0] ?? 0;
|
|
2149
|
-
output[dstBase + x * 6 + 2] = rawPixels[srcBase + 3] ?? 0;
|
|
2150
|
-
output[dstBase + x * 6 + 3] = rawPixels[srcBase + 2] ?? 0;
|
|
2151
|
-
output[dstBase + x * 6 + 4] = rawPixels[srcBase + 5] ?? 0;
|
|
2152
|
-
output[dstBase + x * 6 + 5] = rawPixels[srcBase + 4] ?? 0;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
return { width, height, data: output };
|
|
2156
|
-
}
|
|
2157
|
-
function srgbByteToLinear(value) {
|
|
2158
|
-
const v = value / 255;
|
|
2159
|
-
return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
2160
|
-
}
|
|
2161
|
-
function buildSrgbToSignalLut(transfer) {
|
|
2162
|
-
const lut = new Uint16Array(256);
|
|
2163
|
-
const hlgA = 0.17883277;
|
|
2164
|
-
const hlgB = 1 - 4 * hlgA;
|
|
2165
|
-
const hlgC = 0.5 - hlgA * Math.log(4 * hlgA);
|
|
2166
|
-
const hlgSdrWhite = (Math.exp((0.75 - hlgC) / hlgA) + hlgB) / 12;
|
|
2167
|
-
const pqM1 = 0.1593017578125;
|
|
2168
|
-
const pqM2 = 78.84375;
|
|
2169
|
-
const pqC1 = 0.8359375;
|
|
2170
|
-
const pqC2 = 18.8515625;
|
|
2171
|
-
const pqC3 = 18.6875;
|
|
2172
|
-
const pqMaxNits = 1e4;
|
|
2173
|
-
const sdrNits = 203;
|
|
2174
|
-
for (let i = 0; i < 256; i++) {
|
|
2175
|
-
if (transfer === "srgb") {
|
|
2176
|
-
lut[i] = i * 257;
|
|
2177
|
-
continue;
|
|
2178
|
-
}
|
|
2179
|
-
const linear = srgbByteToLinear(i);
|
|
2180
|
-
let signal;
|
|
2181
|
-
if (transfer === "hlg") {
|
|
2182
|
-
const scene = linear * hlgSdrWhite;
|
|
2183
|
-
signal = scene <= 1 / 12 ? Math.sqrt(3 * scene) : hlgA * Math.log(12 * scene - hlgB) + hlgC;
|
|
2184
|
-
} else {
|
|
2185
|
-
const Lp = Math.max(0, linear * sdrNits / pqMaxNits);
|
|
2186
|
-
const Lm1 = Math.pow(Lp, pqM1);
|
|
2187
|
-
signal = Math.pow((pqC1 + pqC2 * Lm1) / (1 + pqC3 * Lm1), pqM2);
|
|
2188
|
-
}
|
|
2189
|
-
lut[i] = Math.min(65535, Math.round(signal * 65535));
|
|
2190
|
-
}
|
|
2191
|
-
return lut;
|
|
2192
|
-
}
|
|
2193
|
-
var SRGB_TO_SRGB_16 = buildSrgbToSignalLut("srgb");
|
|
2194
|
-
var SRGB_TO_HLG = buildSrgbToSignalLut("hlg");
|
|
2195
|
-
var SRGB_TO_PQ = buildSrgbToSignalLut("pq");
|
|
2196
|
-
function getSrgbToSignalLut(transfer) {
|
|
2197
|
-
if (transfer === "pq") return SRGB_TO_PQ;
|
|
2198
|
-
if (transfer === "hlg") return SRGB_TO_HLG;
|
|
2199
|
-
return SRGB_TO_SRGB_16;
|
|
2200
|
-
}
|
|
2201
|
-
function blitRgba8OverRgb48le(domRgba, canvas, width, height, transfer = "hlg") {
|
|
2202
|
-
const pixelCount = width * height;
|
|
2203
|
-
const lut = getSrgbToSignalLut(transfer);
|
|
2204
|
-
for (let i = 0; i < pixelCount; i++) {
|
|
2205
|
-
const da = domRgba[i * 4 + 3] ?? 0;
|
|
2206
|
-
if (da === 0) {
|
|
2207
|
-
continue;
|
|
2208
|
-
} else if (da === 255) {
|
|
2209
|
-
const r16 = lut[domRgba[i * 4 + 0] ?? 0] ?? 0;
|
|
2210
|
-
const g16 = lut[domRgba[i * 4 + 1] ?? 0] ?? 0;
|
|
2211
|
-
const b16 = lut[domRgba[i * 4 + 2] ?? 0] ?? 0;
|
|
2212
|
-
canvas.writeUInt16LE(r16, i * 6);
|
|
2213
|
-
canvas.writeUInt16LE(g16, i * 6 + 2);
|
|
2214
|
-
canvas.writeUInt16LE(b16, i * 6 + 4);
|
|
2215
|
-
} else {
|
|
2216
|
-
const alpha = da / 255;
|
|
2217
|
-
const invAlpha = 1 - alpha;
|
|
2218
|
-
const hdrR = (canvas[i * 6 + 0] ?? 0) | (canvas[i * 6 + 1] ?? 0) << 8;
|
|
2219
|
-
const hdrG = (canvas[i * 6 + 2] ?? 0) | (canvas[i * 6 + 3] ?? 0) << 8;
|
|
2220
|
-
const hdrB = (canvas[i * 6 + 4] ?? 0) | (canvas[i * 6 + 5] ?? 0) << 8;
|
|
2221
|
-
const domR = lut[domRgba[i * 4 + 0] ?? 0] ?? 0;
|
|
2222
|
-
const domG = lut[domRgba[i * 4 + 1] ?? 0] ?? 0;
|
|
2223
|
-
const domB = lut[domRgba[i * 4 + 2] ?? 0] ?? 0;
|
|
2224
|
-
canvas.writeUInt16LE(Math.round(domR * alpha + hdrR * invAlpha), i * 6);
|
|
2225
|
-
canvas.writeUInt16LE(Math.round(domG * alpha + hdrG * invAlpha), i * 6 + 2);
|
|
2226
|
-
canvas.writeUInt16LE(Math.round(domB * alpha + hdrB * invAlpha), i * 6 + 4);
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
function cornerAlpha(px, py, cx, cy, r) {
|
|
2231
|
-
const dx = px - cx;
|
|
2232
|
-
const dy = py - cy;
|
|
2233
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
2234
|
-
if (dist > r + 0.5) return 0;
|
|
2235
|
-
if (dist > r - 0.5) return r + 0.5 - dist;
|
|
2236
|
-
return 1;
|
|
2237
|
-
}
|
|
2238
|
-
function roundedRectAlpha(px, py, w, h, radii) {
|
|
2239
|
-
const [tl, tr, br, bl] = radii;
|
|
2240
|
-
if (px < tl && py < tl) return cornerAlpha(px, py, tl, tl, tl);
|
|
2241
|
-
if (px >= w - tr && py < tr) return cornerAlpha(px, py, w - tr, tr, tr);
|
|
2242
|
-
if (px >= w - br && py >= h - br) return cornerAlpha(px, py, w - br, h - br, br);
|
|
2243
|
-
if (px < bl && py >= h - bl) return cornerAlpha(px, py, bl, h - bl, bl);
|
|
2244
|
-
return 1;
|
|
1953
|
+
async function detectGpuBackend(page) {
|
|
1954
|
+
return page.evaluate(() => {
|
|
1955
|
+
const canvas = document.createElement("canvas");
|
|
1956
|
+
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
1957
|
+
if (!gl) return { isSwiftShader: false, renderer: null };
|
|
1958
|
+
const ext = gl.getExtension("WEBGL_debug_renderer_info");
|
|
1959
|
+
if (!ext) return { isSwiftShader: false, renderer: null };
|
|
1960
|
+
const renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
|
|
1961
|
+
return { isSwiftShader: renderer.toLowerCase().includes("swiftshader"), renderer };
|
|
1962
|
+
});
|
|
2245
1963
|
}
|
|
2246
|
-
function
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
if (x0 >= x1 || y0 >= y1) return;
|
|
2255
|
-
const clippedW = x1 - x0;
|
|
2256
|
-
const srcOffsetX = x0 - dx;
|
|
2257
|
-
const srcOffsetY = y0 - dy;
|
|
2258
|
-
const hasMask = borderRadius !== void 0;
|
|
2259
|
-
if (op >= 0.999 && !hasMask) {
|
|
2260
|
-
for (let y = 0; y < y1 - y0; y++) {
|
|
2261
|
-
const srcRowOff = ((srcOffsetY + y) * sw + srcOffsetX) * 6;
|
|
2262
|
-
const dstRowOff = ((y0 + y) * canvasWidth + x0) * 6;
|
|
2263
|
-
source.copy(canvas, dstRowOff, srcRowOff, srcRowOff + clippedW * 6);
|
|
2264
|
-
}
|
|
2265
|
-
} else if (!hasMask) {
|
|
2266
|
-
const invOp = 1 - op;
|
|
2267
|
-
for (let y = 0; y < y1 - y0; y++) {
|
|
2268
|
-
let srcOff = ((srcOffsetY + y) * sw + srcOffsetX) * 6;
|
|
2269
|
-
let dstOff = ((y0 + y) * canvasWidth + x0) * 6;
|
|
2270
|
-
for (let x = 0; x < clippedW; x++) {
|
|
2271
|
-
const sr = source[srcOff] | source[srcOff + 1] << 8;
|
|
2272
|
-
const sg = source[srcOff + 2] | source[srcOff + 3] << 8;
|
|
2273
|
-
const sb = source[srcOff + 4] | source[srcOff + 5] << 8;
|
|
2274
|
-
const dr = canvas[dstOff] | canvas[dstOff + 1] << 8;
|
|
2275
|
-
const dg = canvas[dstOff + 2] | canvas[dstOff + 3] << 8;
|
|
2276
|
-
const db = canvas[dstOff + 4] | canvas[dstOff + 5] << 8;
|
|
2277
|
-
const r = sr * op + dr * invOp + 0.5 | 0;
|
|
2278
|
-
const g = sg * op + dg * invOp + 0.5 | 0;
|
|
2279
|
-
const b = sb * op + db * invOp + 0.5 | 0;
|
|
2280
|
-
canvas[dstOff] = r & 255;
|
|
2281
|
-
canvas[dstOff + 1] = r >>> 8;
|
|
2282
|
-
canvas[dstOff + 2] = g & 255;
|
|
2283
|
-
canvas[dstOff + 3] = g >>> 8;
|
|
2284
|
-
canvas[dstOff + 4] = b & 255;
|
|
2285
|
-
canvas[dstOff + 5] = b >>> 8;
|
|
2286
|
-
srcOff += 6;
|
|
2287
|
-
dstOff += 6;
|
|
1964
|
+
async function injectDrawElementCanvas(page, width, height) {
|
|
1965
|
+
await page.evaluate(
|
|
1966
|
+
({ w, h }) => {
|
|
1967
|
+
const root = document.querySelector("[data-composition-id]");
|
|
1968
|
+
if (!root || document.getElementById("__hf_de_canvas")) return;
|
|
1969
|
+
try {
|
|
1970
|
+
window.__HF_ROOT_BASE_OPACITY__ = parseFloat(getComputedStyle(root).opacity) || 1;
|
|
1971
|
+
} catch {
|
|
2288
1972
|
}
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
canvas.writeUInt16LE(Math.round(sg * effectiveOp + dg * invEff), dstOff + 2);
|
|
2313
|
-
canvas.writeUInt16LE(Math.round(sb * effectiveOp + db * invEff), dstOff + 4);
|
|
1973
|
+
const parent = root.parentNode;
|
|
1974
|
+
if (!parent) throw new Error("drawElement: composition root has no parent node");
|
|
1975
|
+
const canvas = document.createElement("canvas");
|
|
1976
|
+
canvas.id = "__hf_de_canvas";
|
|
1977
|
+
canvas.setAttribute("layoutsubtree", "");
|
|
1978
|
+
canvas.width = w;
|
|
1979
|
+
canvas.height = h;
|
|
1980
|
+
canvas.style.cssText = "display:block;position:absolute;top:0;left:0;z-index:0";
|
|
1981
|
+
parent.insertBefore(canvas, root);
|
|
1982
|
+
canvas.appendChild(root);
|
|
1983
|
+
const tick = document.createElement("div");
|
|
1984
|
+
tick.id = "__hf_de_tick";
|
|
1985
|
+
tick.style.cssText = "position:absolute;left:0px;top:0;width:1px;height:1px;background:#000;opacity:0.01;pointer-events:none";
|
|
1986
|
+
canvas.appendChild(tick);
|
|
1987
|
+
window.__hfDeInvalidate = () => {
|
|
1988
|
+
tick.style.backgroundColor = tick.style.backgroundColor === "rgb(0, 0, 0)" ? "rgb(1, 1, 1)" : "rgb(0, 0, 0)";
|
|
1989
|
+
const cvp = canvas;
|
|
1990
|
+
if (typeof cvp.requestPaint === "function") {
|
|
1991
|
+
try {
|
|
1992
|
+
cvp.requestPaint();
|
|
1993
|
+
return true;
|
|
1994
|
+
} catch {
|
|
1995
|
+
}
|
|
2314
1996
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
1997
|
+
return false;
|
|
1998
|
+
};
|
|
1999
|
+
},
|
|
2000
|
+
{ w: width, h: height }
|
|
2001
|
+
);
|
|
2318
2002
|
}
|
|
2319
|
-
function
|
|
2320
|
-
const
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
const invC = -c / det;
|
|
2333
|
-
const invD = a / det;
|
|
2334
|
-
const invTx = -(invA * tx + invC * ty);
|
|
2335
|
-
const invTy = -(invB * tx + invD * ty);
|
|
2336
|
-
const op = opacity ?? 1;
|
|
2337
|
-
if (op <= 0) return;
|
|
2338
|
-
const hasMask = borderRadius !== void 0;
|
|
2339
|
-
const corners = [
|
|
2340
|
-
[tx, ty],
|
|
2341
|
-
[a * srcW + tx, b * srcW + ty],
|
|
2342
|
-
[c * srcH + tx, d * srcH + ty],
|
|
2343
|
-
[a * srcW + c * srcH + tx, b * srcW + d * srcH + ty]
|
|
2344
|
-
];
|
|
2345
|
-
let minX = canvasW, maxX = 0, minY = canvasH, maxY = 0;
|
|
2346
|
-
for (const corner of corners) {
|
|
2347
|
-
const cx = corner[0] ?? 0;
|
|
2348
|
-
const cy = corner[1] ?? 0;
|
|
2349
|
-
if (cx < minX) minX = cx;
|
|
2350
|
-
if (cx > maxX) maxX = cx;
|
|
2351
|
-
if (cy < minY) minY = cy;
|
|
2352
|
-
if (cy > maxY) maxY = cy;
|
|
2353
|
-
}
|
|
2354
|
-
const startX = Math.max(0, Math.floor(minX));
|
|
2355
|
-
const endX = Math.min(canvasW, Math.ceil(maxX));
|
|
2356
|
-
const startY = Math.max(0, Math.floor(minY));
|
|
2357
|
-
const endY = Math.min(canvasH, Math.ceil(maxY));
|
|
2358
|
-
for (let dy = startY; dy < endY; dy++) {
|
|
2359
|
-
for (let dx = startX; dx < endX; dx++) {
|
|
2360
|
-
const sx = invA * dx + invC * dy + invTx;
|
|
2361
|
-
const sy = invB * dx + invD * dy + invTy;
|
|
2362
|
-
if (sx < 0 || sy < 0 || sx >= srcW || sy >= srcH) continue;
|
|
2363
|
-
let effectiveOp = op;
|
|
2364
|
-
if (hasMask) {
|
|
2365
|
-
const ma = roundedRectAlpha(sx, sy, srcW, srcH, borderRadius);
|
|
2366
|
-
if (ma <= 0) continue;
|
|
2367
|
-
effectiveOp *= ma;
|
|
2003
|
+
async function captureDrawElementFrame(page, width, height, format = "jpeg", quality = 80, syncToPaintEvent = true) {
|
|
2004
|
+
const dataUrl = await page.evaluate(
|
|
2005
|
+
({
|
|
2006
|
+
w,
|
|
2007
|
+
h,
|
|
2008
|
+
fmt,
|
|
2009
|
+
q,
|
|
2010
|
+
sync
|
|
2011
|
+
}) => {
|
|
2012
|
+
const canvas = document.getElementById("__hf_de_canvas");
|
|
2013
|
+
const root = document.querySelector("[data-composition-id]");
|
|
2014
|
+
if (!root) {
|
|
2015
|
+
throw new Error("HF_DE_COMPOSITION_ROOT_MISSING: drawElement composition root not found");
|
|
2368
2016
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
const fx = sx - x0;
|
|
2372
|
-
const fy = sy - y0;
|
|
2373
|
-
const x1 = Math.min(x0 + 1, srcW - 1);
|
|
2374
|
-
const y1 = Math.min(y0 + 1, srcH - 1);
|
|
2375
|
-
const off00 = (y0 * srcW + x0) * 6;
|
|
2376
|
-
const off10 = (y0 * srcW + x1) * 6;
|
|
2377
|
-
const off01 = (y1 * srcW + x0) * 6;
|
|
2378
|
-
const off11 = (y1 * srcW + x1) * 6;
|
|
2379
|
-
const w00 = (1 - fx) * (1 - fy);
|
|
2380
|
-
const w10 = fx * (1 - fy);
|
|
2381
|
-
const w01 = (1 - fx) * fy;
|
|
2382
|
-
const w11 = fx * fy;
|
|
2383
|
-
const sr = source.readUInt16LE(off00) * w00 + source.readUInt16LE(off10) * w10 + source.readUInt16LE(off01) * w01 + source.readUInt16LE(off11) * w11;
|
|
2384
|
-
const sg = source.readUInt16LE(off00 + 2) * w00 + source.readUInt16LE(off10 + 2) * w10 + source.readUInt16LE(off01 + 2) * w01 + source.readUInt16LE(off11 + 2) * w11;
|
|
2385
|
-
const sb = source.readUInt16LE(off00 + 4) * w00 + source.readUInt16LE(off10 + 4) * w10 + source.readUInt16LE(off01 + 4) * w01 + source.readUInt16LE(off11 + 4) * w11;
|
|
2386
|
-
const dstOff = (dy * canvasW + dx) * 6;
|
|
2387
|
-
if (effectiveOp >= 0.999) {
|
|
2388
|
-
canvas.writeUInt16LE(Math.round(sr), dstOff);
|
|
2389
|
-
canvas.writeUInt16LE(Math.round(sg), dstOff + 2);
|
|
2390
|
-
canvas.writeUInt16LE(Math.round(sb), dstOff + 4);
|
|
2391
|
-
} else {
|
|
2392
|
-
const invEff = 1 - effectiveOp;
|
|
2393
|
-
const dr = canvas.readUInt16LE(dstOff);
|
|
2394
|
-
const dg = canvas.readUInt16LE(dstOff + 2);
|
|
2395
|
-
const db = canvas.readUInt16LE(dstOff + 4);
|
|
2396
|
-
canvas.writeUInt16LE(Math.round(sr * effectiveOp + dr * invEff), dstOff);
|
|
2397
|
-
canvas.writeUInt16LE(Math.round(sg * effectiveOp + dg * invEff), dstOff + 2);
|
|
2398
|
-
canvas.writeUInt16LE(Math.round(sb * effectiveOp + db * invEff), dstOff + 4);
|
|
2017
|
+
if (!canvas) {
|
|
2018
|
+
throw new Error("HF_DE_CANVAS_NOT_INITIALIZED: drawElement canvas not initialized");
|
|
2399
2019
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2020
|
+
const ctx = canvas.getContext("2d");
|
|
2021
|
+
if (!ctx) throw new Error("drawElement: 2d context unavailable");
|
|
2022
|
+
const aw = window;
|
|
2023
|
+
let usedRequestPaint = false;
|
|
2024
|
+
aw.__hf3d?.update();
|
|
2025
|
+
const accel = (aw.__hf_accel_canvases ?? []).filter((c) => root.contains(c));
|
|
2026
|
+
if (!sync) {
|
|
2027
|
+
for (const c of (aw.__hf_canvas_2d ?? []).filter((c2) => root.contains(c2))) {
|
|
2028
|
+
if (!accel.includes(c)) accel.push(c);
|
|
2029
|
+
}
|
|
2030
|
+
accel.sort(
|
|
2031
|
+
(a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
|
|
2032
|
+
);
|
|
2033
|
+
}
|
|
2034
|
+
for (const c of accel) {
|
|
2035
|
+
if (c.style.visibility !== "hidden") c.style.visibility = "hidden";
|
|
2036
|
+
}
|
|
2037
|
+
return new Promise((resolveCapture, rejectCapture) => {
|
|
2038
|
+
let settled = false;
|
|
2039
|
+
const drawAndEncode = () => {
|
|
2040
|
+
if (settled) return;
|
|
2041
|
+
settled = true;
|
|
2042
|
+
try {
|
|
2043
|
+
ctx.clearRect(0, 0, w, h);
|
|
2044
|
+
let bg = "";
|
|
2045
|
+
for (let el = root.parentElement; el; el = el.parentElement) {
|
|
2046
|
+
const c = getComputedStyle(el).backgroundColor;
|
|
2047
|
+
if (c && c !== "transparent" && c !== "rgba(0, 0, 0, 0)") {
|
|
2048
|
+
bg = c;
|
|
2049
|
+
break;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
if (!bg && fmt === "jpeg") bg = "#fff";
|
|
2053
|
+
if (bg) {
|
|
2054
|
+
ctx.fillStyle = bg;
|
|
2055
|
+
ctx.fillRect(0, 0, w, h);
|
|
2056
|
+
}
|
|
2057
|
+
const rootRect = root.getBoundingClientRect();
|
|
2058
|
+
for (const c of accel) {
|
|
2059
|
+
if (c.hasAttribute("data-hf-3d")) continue;
|
|
2060
|
+
const r = c.getBoundingClientRect();
|
|
2061
|
+
try {
|
|
2062
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2063
|
+
} catch {
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
let __appliedTransform = false;
|
|
2067
|
+
let __appliedAlpha = false;
|
|
2068
|
+
if (aw.__HF_ROOT_PROPS__) {
|
|
2069
|
+
try {
|
|
2070
|
+
const rcs = getComputedStyle(root);
|
|
2071
|
+
if (!usedRequestPaint) {
|
|
2072
|
+
const baseOp = aw.__HF_ROOT_BASE_OPACITY__ ?? 1;
|
|
2073
|
+
const curOp = parseFloat(rcs.opacity);
|
|
2074
|
+
if (baseOp > 1e-3 && Number.isFinite(curOp)) {
|
|
2075
|
+
const ratio = curOp / baseOp;
|
|
2076
|
+
if (Math.abs(ratio - 1) > 2e-3) {
|
|
2077
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, ratio));
|
|
2078
|
+
__appliedAlpha = true;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
const curTransform = rcs.transform;
|
|
2083
|
+
if (curTransform && curTransform !== "none") {
|
|
2084
|
+
const m = new DOMMatrix(curTransform);
|
|
2085
|
+
const origin = rcs.transformOrigin.split(" ");
|
|
2086
|
+
const ox = parseFloat(origin[0] ?? "0") || 0;
|
|
2087
|
+
const oy = parseFloat(origin[1] ?? "0") || 0;
|
|
2088
|
+
ctx.translate(ox, oy);
|
|
2089
|
+
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
2090
|
+
ctx.translate(-ox, -oy);
|
|
2091
|
+
__appliedTransform = true;
|
|
2092
|
+
}
|
|
2093
|
+
} catch {
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
ctx.drawElementImage(root, 0, 0);
|
|
2097
|
+
if (__appliedAlpha) ctx.globalAlpha = 1;
|
|
2098
|
+
if (__appliedTransform) ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
2099
|
+
for (const c of accel) {
|
|
2100
|
+
if (!c.hasAttribute("data-hf-3d")) continue;
|
|
2101
|
+
const r = c.getBoundingClientRect();
|
|
2102
|
+
try {
|
|
2103
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2104
|
+
} catch {
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
} catch (e) {
|
|
2108
|
+
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
setTimeout(() => {
|
|
2112
|
+
try {
|
|
2113
|
+
resolveCapture(
|
|
2114
|
+
fmt === "png" ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", q / 100)
|
|
2115
|
+
);
|
|
2116
|
+
} catch (e) {
|
|
2117
|
+
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
2118
|
+
}
|
|
2119
|
+
}, 0);
|
|
2120
|
+
};
|
|
2121
|
+
if (!sync) {
|
|
2122
|
+
drawAndEncode();
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
const onPaint = () => {
|
|
2126
|
+
canvas.removeEventListener("paint", onPaint);
|
|
2127
|
+
drawAndEncode();
|
|
2128
|
+
};
|
|
2129
|
+
canvas.addEventListener("paint", onPaint);
|
|
2130
|
+
usedRequestPaint = aw.__hfDeInvalidate?.() === true;
|
|
2131
|
+
setTimeout(() => {
|
|
2132
|
+
canvas.removeEventListener("paint", onPaint);
|
|
2133
|
+
drawAndEncode();
|
|
2134
|
+
}, 250);
|
|
2135
|
+
});
|
|
2136
|
+
},
|
|
2137
|
+
{ w: width, h: height, fmt: format, q: quality, sync: syncToPaintEvent }
|
|
2138
|
+
);
|
|
2139
|
+
const base64 = dataUrl.split(",")[1];
|
|
2140
|
+
if (!base64) throw new Error("drawElement: toDataURL returned no base64 payload");
|
|
2141
|
+
return Buffer.from(base64, "base64");
|
|
2453
2142
|
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
if (
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
const pos = parseObjectPosition(objectPosition);
|
|
2462
|
-
const rect = computeObjectFitRect(srcW, srcH, dstW, dstH, fit, pos);
|
|
2463
|
-
const dst = Buffer.alloc(dstW * dstH * 6);
|
|
2464
|
-
const stride = dstW * 6;
|
|
2465
|
-
const xMin = Math.max(0, Math.floor(rect.dx));
|
|
2466
|
-
const yMin = Math.max(0, Math.floor(rect.dy));
|
|
2467
|
-
const xMax = Math.min(dstW, Math.ceil(rect.dx + rect.dw));
|
|
2468
|
-
const yMax = Math.min(dstH, Math.ceil(rect.dy + rect.dh));
|
|
2469
|
-
if (rect.dw <= 0 || rect.dh <= 0) {
|
|
2470
|
-
return dst;
|
|
2471
|
-
}
|
|
2472
|
-
const invScaleX = srcW / rect.dw;
|
|
2473
|
-
const invScaleY = srcH / rect.dh;
|
|
2474
|
-
for (let dy = yMin; dy < yMax; dy++) {
|
|
2475
|
-
const rowOff = dy * stride;
|
|
2476
|
-
const sy = (dy + 0.5 - rect.dy) * invScaleY - 0.5;
|
|
2477
|
-
const syc = Math.max(0, Math.min(srcH - 1, sy));
|
|
2478
|
-
const y0 = Math.floor(syc);
|
|
2479
|
-
const y1 = Math.min(y0 + 1, srcH - 1);
|
|
2480
|
-
const fy = syc - y0;
|
|
2481
|
-
const ify = 1 - fy;
|
|
2482
|
-
for (let dx = xMin; dx < xMax; dx++) {
|
|
2483
|
-
const sx = (dx + 0.5 - rect.dx) * invScaleX - 0.5;
|
|
2484
|
-
const sxc = Math.max(0, Math.min(srcW - 1, sx));
|
|
2485
|
-
const x0 = Math.floor(sxc);
|
|
2486
|
-
const x1 = Math.min(x0 + 1, srcW - 1);
|
|
2487
|
-
const fx = sxc - x0;
|
|
2488
|
-
const ifx = 1 - fx;
|
|
2489
|
-
const off00 = (y0 * srcW + x0) * 6;
|
|
2490
|
-
const off10 = (y0 * srcW + x1) * 6;
|
|
2491
|
-
const off01 = (y1 * srcW + x0) * 6;
|
|
2492
|
-
const off11 = (y1 * srcW + x1) * 6;
|
|
2493
|
-
const w00 = ifx * ify;
|
|
2494
|
-
const w10 = fx * ify;
|
|
2495
|
-
const w01 = ifx * fy;
|
|
2496
|
-
const w11 = fx * fy;
|
|
2497
|
-
const r = source.readUInt16LE(off00) * w00 + source.readUInt16LE(off10) * w10 + source.readUInt16LE(off01) * w01 + source.readUInt16LE(off11) * w11;
|
|
2498
|
-
const g = source.readUInt16LE(off00 + 2) * w00 + source.readUInt16LE(off10 + 2) * w10 + source.readUInt16LE(off01 + 2) * w01 + source.readUInt16LE(off11 + 2) * w11;
|
|
2499
|
-
const b = source.readUInt16LE(off00 + 4) * w00 + source.readUInt16LE(off10 + 4) * w10 + source.readUInt16LE(off01 + 4) * w01 + source.readUInt16LE(off11 + 4) * w11;
|
|
2500
|
-
const dstOff = rowOff + dx * 6;
|
|
2501
|
-
dst.writeUInt16LE(Math.round(r), dstOff);
|
|
2502
|
-
dst.writeUInt16LE(Math.round(g), dstOff + 2);
|
|
2503
|
-
dst.writeUInt16LE(Math.round(b), dstOff + 4);
|
|
2143
|
+
var workerEncodeStates = /* @__PURE__ */ new WeakMap();
|
|
2144
|
+
var workerEncodeBoundPages = /* @__PURE__ */ new WeakSet();
|
|
2145
|
+
async function initDrawElementWorkerEncode(page) {
|
|
2146
|
+
const existing = workerEncodeStates.get(page);
|
|
2147
|
+
if (existing) {
|
|
2148
|
+
for (const entry of existing.pending.values()) {
|
|
2149
|
+
entry.reject(new Error("drawElement worker encode: session reused, frame dropped"));
|
|
2504
2150
|
}
|
|
2151
|
+
existing.pending.clear();
|
|
2152
|
+
existing.nextId = 0;
|
|
2153
|
+
} else {
|
|
2154
|
+
const state = { nextId: 0, pending: /* @__PURE__ */ new Map() };
|
|
2155
|
+
workerEncodeStates.set(page, state);
|
|
2505
2156
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
return
|
|
2157
|
+
if (!workerEncodeBoundPages.has(page)) {
|
|
2158
|
+
workerEncodeBoundPages.add(page);
|
|
2159
|
+
await page.exposeFunction("__hfFrameReady", (id, b64, error) => {
|
|
2160
|
+
const s = workerEncodeStates.get(page);
|
|
2161
|
+
if (!s) return;
|
|
2162
|
+
if (id < 0) {
|
|
2163
|
+
for (const entry2 of s.pending.values()) {
|
|
2164
|
+
entry2.reject(new Error(`drawElement worker encode failed: ${error ?? "worker error"}`));
|
|
2165
|
+
}
|
|
2166
|
+
s.pending.clear();
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
const entry = s.pending.get(id);
|
|
2170
|
+
if (!entry) return;
|
|
2171
|
+
s.pending.delete(id);
|
|
2172
|
+
if (error) {
|
|
2173
|
+
entry.reject(new Error(`drawElement worker encode failed: ${error}`));
|
|
2174
|
+
} else if (!b64) {
|
|
2175
|
+
entry.reject(new Error(`drawElement worker encode returned empty frame (frame ${id})`));
|
|
2176
|
+
} else {
|
|
2177
|
+
entry.resolve(Buffer.from(b64, "base64"));
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2520
2180
|
}
|
|
2181
|
+
await page.evaluate(() => {
|
|
2182
|
+
const ew = window;
|
|
2183
|
+
if (ew.__hfEncWorker) {
|
|
2184
|
+
ew.__hfEncWorker.terminate();
|
|
2185
|
+
ew.__hfEncWorker = void 0;
|
|
2186
|
+
}
|
|
2187
|
+
const workerSrc = `
|
|
2188
|
+
// Reuse one OffscreenCanvas across frames (dimensions are constant for a
|
|
2189
|
+
// render): a fresh canvas per frame churns ~w*h*4 bytes of backing store
|
|
2190
|
+
// every frame and pressures GC on the encode hot path.
|
|
2191
|
+
let oc = null, c = null;
|
|
2192
|
+
self.onmessage = async (e) => {
|
|
2193
|
+
const { bmp, id, w, h, q } = e.data;
|
|
2194
|
+
try {
|
|
2195
|
+
if (!oc || oc.width !== w || oc.height !== h) {
|
|
2196
|
+
oc = new OffscreenCanvas(w, h);
|
|
2197
|
+
c = oc.getContext('2d');
|
|
2198
|
+
}
|
|
2199
|
+
if (!c) throw new Error('OffscreenCanvas 2d context unavailable');
|
|
2200
|
+
c.drawImage(bmp, 0, 0);
|
|
2201
|
+
bmp.close();
|
|
2202
|
+
const blob = await oc.convertToBlob({ type: 'image/jpeg', quality: q });
|
|
2203
|
+
const ab = await blob.arrayBuffer();
|
|
2204
|
+
const u = new Uint8Array(ab);
|
|
2205
|
+
let s = ''; const CH = 0x8000;
|
|
2206
|
+
for (let i = 0; i < u.length; i += CH)
|
|
2207
|
+
s += String.fromCharCode.apply(null, u.subarray(i, i + CH));
|
|
2208
|
+
self.postMessage({ id, b64: btoa(s) });
|
|
2209
|
+
} catch (err) {
|
|
2210
|
+
try { if (bmp) bmp.close(); } catch (_) {}
|
|
2211
|
+
self.postMessage({ id, error: (err && err.message) || String(err) });
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
`;
|
|
2215
|
+
const url = URL.createObjectURL(new Blob([workerSrc], { type: "text/javascript" }));
|
|
2216
|
+
const worker = new Worker(url);
|
|
2217
|
+
URL.revokeObjectURL(url);
|
|
2218
|
+
ew.__hfEncWorker = worker;
|
|
2219
|
+
worker.onmessage = (ev) => {
|
|
2220
|
+
const d = ev.data;
|
|
2221
|
+
ew.__hfFrameReady?.(d.id, d.b64 ?? "", d.error);
|
|
2222
|
+
};
|
|
2223
|
+
worker.onerror = (err) => {
|
|
2224
|
+
ew.__hfFrameReady?.(-1, "", err.message || "worker fatal error");
|
|
2225
|
+
};
|
|
2226
|
+
});
|
|
2521
2227
|
}
|
|
2522
|
-
function
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
if (!values.every(Number.isFinite)) return null;
|
|
2528
|
-
return values;
|
|
2228
|
+
function cleanupDrawElementWorkerEncode(page) {
|
|
2229
|
+
const state = workerEncodeStates.get(page);
|
|
2230
|
+
if (!state) return;
|
|
2231
|
+
for (const entry of state.pending.values()) {
|
|
2232
|
+
entry.reject(new Error("drawElement worker encode: session closed"));
|
|
2529
2233
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
parts[1],
|
|
2540
|
-
parts[4],
|
|
2541
|
-
parts[5],
|
|
2542
|
-
parts[12],
|
|
2543
|
-
parts[13]
|
|
2544
|
-
];
|
|
2234
|
+
state.pending.clear();
|
|
2235
|
+
workerEncodeStates.delete(page);
|
|
2236
|
+
}
|
|
2237
|
+
async function produceDrawElementFrame(page, width, height, quality = 80, syncToPaintEvent = true) {
|
|
2238
|
+
const state = workerEncodeStates.get(page);
|
|
2239
|
+
if (!state) {
|
|
2240
|
+
throw new Error(
|
|
2241
|
+
"drawElement worker encode not initialized; call initDrawElementWorkerEncode first"
|
|
2242
|
+
);
|
|
2545
2243
|
}
|
|
2546
|
-
|
|
2244
|
+
const frameId = ++state.nextId;
|
|
2245
|
+
const encodeResult = new Promise((resolve2, reject) => {
|
|
2246
|
+
const timer = setTimeout(() => {
|
|
2247
|
+
if (state.pending.delete(frameId)) {
|
|
2248
|
+
reject(new Error(`drawElement worker encode timed out (frame ${frameId})`));
|
|
2249
|
+
}
|
|
2250
|
+
}, 3e4);
|
|
2251
|
+
state.pending.set(frameId, {
|
|
2252
|
+
resolve: (b) => {
|
|
2253
|
+
clearTimeout(timer);
|
|
2254
|
+
resolve2(b);
|
|
2255
|
+
},
|
|
2256
|
+
reject: (e) => {
|
|
2257
|
+
clearTimeout(timer);
|
|
2258
|
+
reject(e);
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
});
|
|
2262
|
+
void encodeResult.catch(() => {
|
|
2263
|
+
});
|
|
2264
|
+
await page.evaluate(
|
|
2265
|
+
({ w, h, q, sync, fid }) => {
|
|
2266
|
+
const canvas = document.getElementById("__hf_de_canvas");
|
|
2267
|
+
const root = document.querySelector("[data-composition-id]");
|
|
2268
|
+
if (!root) {
|
|
2269
|
+
throw new Error("HF_DE_COMPOSITION_ROOT_MISSING: drawElement composition root not found");
|
|
2270
|
+
}
|
|
2271
|
+
if (!canvas) {
|
|
2272
|
+
throw new Error("HF_DE_CANVAS_NOT_INITIALIZED: drawElement canvas not initialized");
|
|
2273
|
+
}
|
|
2274
|
+
const ctx = canvas.getContext("2d");
|
|
2275
|
+
if (!ctx) throw new Error("drawElement: 2d context unavailable");
|
|
2276
|
+
const aw = window;
|
|
2277
|
+
aw.__hf3d?.update();
|
|
2278
|
+
const accel = (aw.__hf_accel_canvases ?? []).filter((c) => root.contains(c));
|
|
2279
|
+
if (!sync) {
|
|
2280
|
+
for (const c of (aw.__hf_canvas_2d ?? []).filter((c2) => root.contains(c2))) {
|
|
2281
|
+
if (!accel.includes(c)) accel.push(c);
|
|
2282
|
+
}
|
|
2283
|
+
accel.sort(
|
|
2284
|
+
(a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
for (const c of accel) {
|
|
2288
|
+
if (c.style.visibility !== "hidden") c.style.visibility = "hidden";
|
|
2289
|
+
}
|
|
2290
|
+
return new Promise((resolveCapture, rejectCapture) => {
|
|
2291
|
+
let settled = false;
|
|
2292
|
+
let usedRequestPaint = false;
|
|
2293
|
+
const drawAndKick = () => {
|
|
2294
|
+
if (settled) return;
|
|
2295
|
+
settled = true;
|
|
2296
|
+
try {
|
|
2297
|
+
ctx.clearRect(0, 0, w, h);
|
|
2298
|
+
let bg = "";
|
|
2299
|
+
for (let el = root.parentElement; el; el = el.parentElement) {
|
|
2300
|
+
const c = getComputedStyle(el).backgroundColor;
|
|
2301
|
+
if (c && c !== "transparent" && c !== "rgba(0, 0, 0, 0)") {
|
|
2302
|
+
bg = c;
|
|
2303
|
+
break;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
if (!bg) bg = "#fff";
|
|
2307
|
+
if (bg) {
|
|
2308
|
+
ctx.fillStyle = bg;
|
|
2309
|
+
ctx.fillRect(0, 0, w, h);
|
|
2310
|
+
}
|
|
2311
|
+
const rootRect = root.getBoundingClientRect();
|
|
2312
|
+
for (const c of accel) {
|
|
2313
|
+
if (c.hasAttribute("data-hf-3d")) continue;
|
|
2314
|
+
const r = c.getBoundingClientRect();
|
|
2315
|
+
try {
|
|
2316
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2317
|
+
} catch {
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
let __appliedTransform = false;
|
|
2321
|
+
let __appliedAlpha = false;
|
|
2322
|
+
if (aw.__HF_ROOT_PROPS__) {
|
|
2323
|
+
try {
|
|
2324
|
+
const rcs = getComputedStyle(root);
|
|
2325
|
+
if (!usedRequestPaint) {
|
|
2326
|
+
const baseOp = aw.__HF_ROOT_BASE_OPACITY__ ?? 1;
|
|
2327
|
+
const curOp = parseFloat(rcs.opacity);
|
|
2328
|
+
if (baseOp > 1e-3 && Number.isFinite(curOp)) {
|
|
2329
|
+
const ratio = curOp / baseOp;
|
|
2330
|
+
if (Math.abs(ratio - 1) > 2e-3) {
|
|
2331
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, ratio));
|
|
2332
|
+
__appliedAlpha = true;
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
const curTransform = rcs.transform;
|
|
2337
|
+
if (curTransform && curTransform !== "none") {
|
|
2338
|
+
const m = new DOMMatrix(curTransform);
|
|
2339
|
+
const origin = rcs.transformOrigin.split(" ");
|
|
2340
|
+
const ox = parseFloat(origin[0] ?? "0") || 0;
|
|
2341
|
+
const oy = parseFloat(origin[1] ?? "0") || 0;
|
|
2342
|
+
ctx.translate(ox, oy);
|
|
2343
|
+
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
2344
|
+
ctx.translate(-ox, -oy);
|
|
2345
|
+
__appliedTransform = true;
|
|
2346
|
+
}
|
|
2347
|
+
} catch {
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
ctx.drawElementImage(root, 0, 0);
|
|
2351
|
+
if (__appliedAlpha) ctx.globalAlpha = 1;
|
|
2352
|
+
if (__appliedTransform) ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
2353
|
+
for (const c of accel) {
|
|
2354
|
+
if (!c.hasAttribute("data-hf-3d")) continue;
|
|
2355
|
+
const r = c.getBoundingClientRect();
|
|
2356
|
+
try {
|
|
2357
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2358
|
+
} catch {
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
} catch (e) {
|
|
2362
|
+
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
2363
|
+
return;
|
|
2364
|
+
}
|
|
2365
|
+
createImageBitmap(canvas).then((bmp) => {
|
|
2366
|
+
const ew = window;
|
|
2367
|
+
if (!ew.__hfEncWorker) {
|
|
2368
|
+
bmp.close();
|
|
2369
|
+
rejectCapture(new Error("drawElement: encode worker not initialized"));
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
ew.__hfEncWorker.postMessage({ bmp, id: fid, w, h, q: q / 100 }, [bmp]);
|
|
2373
|
+
resolveCapture();
|
|
2374
|
+
}).catch((e) => {
|
|
2375
|
+
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
2376
|
+
});
|
|
2377
|
+
};
|
|
2378
|
+
if (!sync) {
|
|
2379
|
+
drawAndKick();
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
const onPaint = () => {
|
|
2383
|
+
canvas.removeEventListener("paint", onPaint);
|
|
2384
|
+
drawAndKick();
|
|
2385
|
+
};
|
|
2386
|
+
canvas.addEventListener("paint", onPaint);
|
|
2387
|
+
usedRequestPaint = aw.__hfDeInvalidate?.() === true;
|
|
2388
|
+
setTimeout(() => {
|
|
2389
|
+
canvas.removeEventListener("paint", onPaint);
|
|
2390
|
+
drawAndKick();
|
|
2391
|
+
}, 250);
|
|
2392
|
+
});
|
|
2393
|
+
},
|
|
2394
|
+
{ w: width, h: height, q: quality, sync: syncToPaintEvent, fid: frameId }
|
|
2395
|
+
);
|
|
2396
|
+
return { encodeResult };
|
|
2547
2397
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
const b3 = parts[9] ?? 0;
|
|
2554
|
-
const c1 = parts[2] ?? 0;
|
|
2555
|
-
const c2 = parts[6] ?? 0;
|
|
2556
|
-
const c3 = parts[10] ?? 1;
|
|
2557
|
-
const d1 = parts[3] ?? 0;
|
|
2558
|
-
const d2 = parts[7] ?? 0;
|
|
2559
|
-
const d3 = parts[11] ?? 0;
|
|
2560
|
-
const d4 = parts[15] ?? 1;
|
|
2561
|
-
if (Math.abs(a3) > Z_EPSILON || Math.abs(b3) > Z_EPSILON || Math.abs(c1) > Z_EPSILON || Math.abs(c2) > Z_EPSILON || Math.abs(c3 - 1) > Z_EPSILON || Math.abs(d1) > Z_EPSILON || Math.abs(d2) > Z_EPSILON || Math.abs(d3) > Z_EPSILON || Math.abs(d4 - 1) > Z_EPSILON) {
|
|
2562
|
-
warnedZSignificant = true;
|
|
2563
|
-
console.warn(
|
|
2564
|
-
`[alphaBlit] parseTransformMatrix received a matrix3d with non-trivial 3D components (a3=${a3}, b3=${b3}, c1=${c1}, c2=${c2}, c3=${c3}, d1=${d1}, d2=${d2}, d3=${d3}, d4=${d4}). The engine projects 3D transforms to 2D (m11, m12, m21, m22, m41, m42) and silently discards perspective and out-of-plane rotation. If your composition uses real 3D (rotateX/Y, perspective), the rendered output will not match the studio preview. Z translation (translateZ) is dropped by design and does not trigger this warning. This warning is emitted once per process.`
|
|
2398
|
+
async function produceDrawElementFrameBatch(page, times, width, height, quality = 80) {
|
|
2399
|
+
const state = workerEncodeStates.get(page);
|
|
2400
|
+
if (!state) {
|
|
2401
|
+
throw new Error(
|
|
2402
|
+
"drawElement worker encode not initialized; call initDrawElementWorkerEncode first"
|
|
2565
2403
|
);
|
|
2566
2404
|
}
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
fixedSamplesPerFrame
|
|
2593
|
-
};
|
|
2594
|
-
}
|
|
2595
|
-
function sampleTickOffsets(plan, samplesPerFrame) {
|
|
2596
|
-
const offsets = [];
|
|
2597
|
-
for (let k = 0; k < samplesPerFrame; k++) {
|
|
2598
|
-
const offsetFrames = plan.windowStartFrames + (k + 0.5) / samplesPerFrame * plan.shutterFrames;
|
|
2599
|
-
offsets.push(Math.round(offsetFrames * plan.subFrameDivisions));
|
|
2405
|
+
const fids = [];
|
|
2406
|
+
const encodeResults = [];
|
|
2407
|
+
for (let i = 0; i < times.length; i++) {
|
|
2408
|
+
const frameId = ++state.nextId;
|
|
2409
|
+
fids.push(frameId);
|
|
2410
|
+
const p = new Promise((resolve2, reject) => {
|
|
2411
|
+
const timer = setTimeout(() => {
|
|
2412
|
+
if (state.pending.delete(frameId)) {
|
|
2413
|
+
reject(new Error(`drawElement worker encode timed out (frame ${frameId})`));
|
|
2414
|
+
}
|
|
2415
|
+
}, 3e4);
|
|
2416
|
+
state.pending.set(frameId, {
|
|
2417
|
+
resolve: (b) => {
|
|
2418
|
+
clearTimeout(timer);
|
|
2419
|
+
resolve2(b);
|
|
2420
|
+
},
|
|
2421
|
+
reject: (e) => {
|
|
2422
|
+
clearTimeout(timer);
|
|
2423
|
+
reject(e);
|
|
2424
|
+
}
|
|
2425
|
+
});
|
|
2426
|
+
});
|
|
2427
|
+
void p.catch(() => {
|
|
2428
|
+
});
|
|
2429
|
+
encodeResults.push(p);
|
|
2600
2430
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2431
|
+
const outcome = await page.evaluate(
|
|
2432
|
+
async ({
|
|
2433
|
+
frames,
|
|
2434
|
+
w,
|
|
2435
|
+
h,
|
|
2436
|
+
q
|
|
2437
|
+
}) => {
|
|
2438
|
+
const canvas = document.getElementById("__hf_de_canvas");
|
|
2439
|
+
const root = document.querySelector("[data-composition-id]");
|
|
2440
|
+
if (!root) {
|
|
2441
|
+
return {
|
|
2442
|
+
failedAt: 0,
|
|
2443
|
+
error: "HF_DE_COMPOSITION_ROOT_MISSING: drawElement composition root not found"
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
if (!canvas) {
|
|
2447
|
+
return {
|
|
2448
|
+
failedAt: 0,
|
|
2449
|
+
error: "HF_DE_CANVAS_NOT_INITIALIZED: drawElement canvas not initialized"
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
const ctx = canvas.getContext("2d");
|
|
2453
|
+
if (!ctx) return { failedAt: 0, error: "drawElement: 2d context unavailable" };
|
|
2454
|
+
const aw = window;
|
|
2455
|
+
let usedRequestPaint = false;
|
|
2456
|
+
const waitPaint = () => new Promise((res) => {
|
|
2457
|
+
let done = false;
|
|
2458
|
+
const settle = () => {
|
|
2459
|
+
if (done) return;
|
|
2460
|
+
done = true;
|
|
2461
|
+
canvas.removeEventListener("paint", settle);
|
|
2462
|
+
res();
|
|
2463
|
+
};
|
|
2464
|
+
canvas.addEventListener("paint", settle);
|
|
2465
|
+
usedRequestPaint = aw.__hfDeInvalidate?.() === true;
|
|
2466
|
+
setTimeout(settle, 250);
|
|
2467
|
+
});
|
|
2468
|
+
let prevBitmap = Promise.resolve();
|
|
2469
|
+
let prevBitmapIdx = -1;
|
|
2470
|
+
const errMsg = (e) => e instanceof Error ? e.message : String(e);
|
|
2471
|
+
for (let i = 0; i < frames.length; i++) {
|
|
2472
|
+
const frame = frames[i];
|
|
2473
|
+
if (!frame) return { failedAt: i, error: "batch frame missing" };
|
|
2474
|
+
const { t, fid } = frame;
|
|
2475
|
+
try {
|
|
2476
|
+
if (aw.__hf && typeof aw.__hf.seek === "function") aw.__hf.seek(t);
|
|
2477
|
+
await aw.__hfWaitForSeekCompletion?.();
|
|
2478
|
+
await aw.__hfDecodeDynamicCssBackgroundImages?.();
|
|
2479
|
+
aw.__hf3d?.update();
|
|
2480
|
+
const accel = (aw.__hf_accel_canvases ?? []).filter((c) => root.contains(c));
|
|
2481
|
+
for (const c of accel) {
|
|
2482
|
+
if (c.style.visibility !== "hidden") c.style.visibility = "hidden";
|
|
2483
|
+
}
|
|
2484
|
+
await waitPaint();
|
|
2485
|
+
try {
|
|
2486
|
+
await prevBitmap;
|
|
2487
|
+
} catch (e) {
|
|
2488
|
+
return { failedAt: prevBitmapIdx, error: errMsg(e) };
|
|
2489
|
+
}
|
|
2490
|
+
ctx.clearRect(0, 0, w, h);
|
|
2491
|
+
let bg = "";
|
|
2492
|
+
for (let el = root.parentElement; el; el = el.parentElement) {
|
|
2493
|
+
const c = getComputedStyle(el).backgroundColor;
|
|
2494
|
+
if (c && c !== "transparent" && c !== "rgba(0, 0, 0, 0)") {
|
|
2495
|
+
bg = c;
|
|
2496
|
+
break;
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
ctx.fillStyle = bg || "#fff";
|
|
2500
|
+
ctx.fillRect(0, 0, w, h);
|
|
2501
|
+
const rootRect = root.getBoundingClientRect();
|
|
2502
|
+
for (const c of accel) {
|
|
2503
|
+
if (c.hasAttribute("data-hf-3d")) continue;
|
|
2504
|
+
const r = c.getBoundingClientRect();
|
|
2505
|
+
try {
|
|
2506
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2507
|
+
} catch {
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
let appliedTransform = false;
|
|
2511
|
+
let appliedAlpha = false;
|
|
2512
|
+
if (aw.__HF_ROOT_PROPS__) {
|
|
2513
|
+
try {
|
|
2514
|
+
const rcs = getComputedStyle(root);
|
|
2515
|
+
if (!usedRequestPaint) {
|
|
2516
|
+
const baseOp = aw.__HF_ROOT_BASE_OPACITY__ ?? 1;
|
|
2517
|
+
const curOp = parseFloat(rcs.opacity);
|
|
2518
|
+
if (baseOp > 1e-3 && Number.isFinite(curOp)) {
|
|
2519
|
+
const ratio = curOp / baseOp;
|
|
2520
|
+
if (Math.abs(ratio - 1) > 2e-3) {
|
|
2521
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, ratio));
|
|
2522
|
+
appliedAlpha = true;
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
const curTransform = rcs.transform;
|
|
2527
|
+
if (curTransform && curTransform !== "none") {
|
|
2528
|
+
const m = new DOMMatrix(curTransform);
|
|
2529
|
+
const origin = rcs.transformOrigin.split(" ");
|
|
2530
|
+
const ox = parseFloat(origin[0] ?? "0") || 0;
|
|
2531
|
+
const oy = parseFloat(origin[1] ?? "0") || 0;
|
|
2532
|
+
ctx.translate(ox, oy);
|
|
2533
|
+
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
2534
|
+
ctx.translate(-ox, -oy);
|
|
2535
|
+
appliedTransform = true;
|
|
2536
|
+
}
|
|
2537
|
+
} catch {
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
ctx.drawElementImage(root, 0, 0);
|
|
2541
|
+
if (appliedAlpha) ctx.globalAlpha = 1;
|
|
2542
|
+
if (appliedTransform) ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
2543
|
+
for (const c of accel) {
|
|
2544
|
+
if (!c.hasAttribute("data-hf-3d")) continue;
|
|
2545
|
+
const r = c.getBoundingClientRect();
|
|
2546
|
+
try {
|
|
2547
|
+
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
2548
|
+
} catch {
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
prevBitmapIdx = i;
|
|
2552
|
+
prevBitmap = createImageBitmap(canvas).then((bmp) => {
|
|
2553
|
+
if (!aw.__hfEncWorker) {
|
|
2554
|
+
bmp.close();
|
|
2555
|
+
throw new Error("drawElement: encode worker not initialized");
|
|
2556
|
+
}
|
|
2557
|
+
aw.__hfEncWorker.postMessage({ bmp, id: fid, w, h, q: q / 100 }, [bmp]);
|
|
2558
|
+
});
|
|
2559
|
+
} catch (e) {
|
|
2560
|
+
try {
|
|
2561
|
+
await prevBitmap;
|
|
2562
|
+
} catch {
|
|
2563
|
+
}
|
|
2564
|
+
return { failedAt: i, error: errMsg(e) };
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
try {
|
|
2568
|
+
await prevBitmap;
|
|
2569
|
+
} catch (e) {
|
|
2570
|
+
return { failedAt: prevBitmapIdx, error: errMsg(e) };
|
|
2571
|
+
}
|
|
2572
|
+
return { failedAt: null };
|
|
2573
|
+
},
|
|
2574
|
+
{ frames: times.map((t, i) => ({ t, fid: fids[i] ?? 0 })), w: width, h: height, q: quality }
|
|
2608
2575
|
);
|
|
2576
|
+
if (outcome.failedAt !== null) {
|
|
2577
|
+
for (let k = outcome.failedAt; k < fids.length; k++) {
|
|
2578
|
+
const fid = fids[k];
|
|
2579
|
+
if (fid === void 0) continue;
|
|
2580
|
+
const entry = state.pending.get(fid);
|
|
2581
|
+
if (entry) {
|
|
2582
|
+
state.pending.delete(fid);
|
|
2583
|
+
entry.reject(
|
|
2584
|
+
new Error(`drawElement batch produce failed at frame ${k}: ${outcome.error ?? "?"}`)
|
|
2585
|
+
);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
return { encodeResults, failedAt: outcome.failedAt, error: outcome.error };
|
|
2609
2590
|
}
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2591
|
+
|
|
2592
|
+
// ../engine/src/services/frameCapture.ts
|
|
2593
|
+
import { existsSync as existsSync3, mkdirSync, writeFileSync } from "fs";
|
|
2594
|
+
import { join as join4 } from "path";
|
|
2595
|
+
|
|
2596
|
+
// ../engine/src/services/renderFrameVideoHold.ts
|
|
2597
|
+
function holdRenderFrameVideos(ids, renderIdAttr) {
|
|
2598
|
+
const held = new Set(ids);
|
|
2599
|
+
window.__HF_RENDER_FRAME_VIDEO_IDS = ids;
|
|
2600
|
+
const hold = (el) => {
|
|
2601
|
+
if (el instanceof HTMLVideoElement && held.has(el.getAttribute(renderIdAttr) || el.id))
|
|
2602
|
+
el.preload = "none";
|
|
2620
2603
|
};
|
|
2604
|
+
new MutationObserver((records) => {
|
|
2605
|
+
for (const record2 of records)
|
|
2606
|
+
for (const node of record2.addedNodes) {
|
|
2607
|
+
if (node.nodeType !== 1) continue;
|
|
2608
|
+
hold(node);
|
|
2609
|
+
for (const video of node.querySelectorAll("video")) hold(video);
|
|
2610
|
+
}
|
|
2611
|
+
}).observe(document, { childList: true, subtree: true });
|
|
2621
2612
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2613
|
+
|
|
2614
|
+
// ../engine/src/services/drawElementCaptureError.ts
|
|
2615
|
+
var DrawElementCaptureError = class extends Error {
|
|
2616
|
+
frameIndex;
|
|
2617
|
+
constructor(frameIndex, reason, cause) {
|
|
2618
|
+
super(
|
|
2619
|
+
`drawElement capture failed at frame ${frameIndex}: ${reason}; fresh screenshot capture required`,
|
|
2620
|
+
{ cause }
|
|
2621
|
+
);
|
|
2622
|
+
this.name = "DrawElementCaptureError";
|
|
2623
|
+
Object.defineProperty(this, "deCaptureFailure", { value: true, enumerable: true });
|
|
2624
|
+
this.frameIndex = frameIndex;
|
|
2631
2625
|
}
|
|
2632
|
-
|
|
2626
|
+
};
|
|
2627
|
+
function markRejectionHandled(promise) {
|
|
2628
|
+
promise.catch(() => {
|
|
2629
|
+
});
|
|
2633
2630
|
}
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
}
|
|
2643
|
-
return MAX_SAMPLES_PER_FRAME;
|
|
2631
|
+
function asDrawElementCaptureFailure(frameIndex, encodeResult) {
|
|
2632
|
+
const wrapped = encodeResult.catch((cause) => {
|
|
2633
|
+
if (isDrawElementCaptureError(cause)) throw cause;
|
|
2634
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
2635
|
+
throw new DrawElementCaptureError(frameIndex, reason, cause);
|
|
2636
|
+
});
|
|
2637
|
+
markRejectionHandled(wrapped);
|
|
2638
|
+
return wrapped;
|
|
2644
2639
|
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
"
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
"yPercent",
|
|
2651
|
-
"rotation",
|
|
2652
|
-
"rotate",
|
|
2653
|
-
"rotationX",
|
|
2654
|
-
"rotationY",
|
|
2655
|
-
"rotationZ",
|
|
2656
|
-
"scale",
|
|
2657
|
-
"scaleX",
|
|
2658
|
-
"scaleY",
|
|
2659
|
-
"scaleZ",
|
|
2660
|
-
"skewX",
|
|
2661
|
-
"skewY",
|
|
2662
|
-
"perspective",
|
|
2663
|
-
"transformPerspective",
|
|
2664
|
-
"top",
|
|
2665
|
-
"left",
|
|
2666
|
-
"right",
|
|
2667
|
-
"bottom",
|
|
2668
|
-
"width",
|
|
2669
|
-
"height",
|
|
2670
|
-
"translate",
|
|
2671
|
-
"translateX",
|
|
2672
|
-
"translateY",
|
|
2673
|
-
"translateZ",
|
|
2674
|
-
"transform"
|
|
2675
|
-
];
|
|
2676
|
-
function probeDiffMagnitude(a, b) {
|
|
2677
|
-
const decodedA = decodePng(a);
|
|
2678
|
-
const decodedB = decodePng(b);
|
|
2679
|
-
if (decodedA.width !== decodedB.width || decodedA.height !== decodedB.height) {
|
|
2680
|
-
throw new Error(
|
|
2681
|
-
`probeDiffMagnitude: sample geometry mismatch (${decodedA.width}x${decodedA.height} vs ${decodedB.width}x${decodedB.height})`
|
|
2682
|
-
);
|
|
2640
|
+
function isDrawElementCaptureError(error) {
|
|
2641
|
+
let current = error;
|
|
2642
|
+
for (let depth = 0; depth < 5 && typeof current === "object" && current !== null; depth++) {
|
|
2643
|
+
if ("deCaptureFailure" in current && current.deCaptureFailure === true) return true;
|
|
2644
|
+
current = "cause" in current ? current.cause : void 0;
|
|
2683
2645
|
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2646
|
+
return false;
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
// ../engine/src/utils/alphaBlit.ts
|
|
2650
|
+
import { deflateSync, inflateSync } from "zlib";
|
|
2651
|
+
|
|
2652
|
+
// ../engine/src/utils/crc32.ts
|
|
2653
|
+
import * as zlib from "zlib";
|
|
2654
|
+
var nativeCrc32 = typeof zlib.crc32 === "function" ? zlib.crc32 : void 0;
|
|
2655
|
+
function crc32Fallback(data, seed) {
|
|
2656
|
+
let crc = seed ^ 4294967295;
|
|
2657
|
+
for (let i = 0; i < data.length; i++) {
|
|
2658
|
+
crc ^= data[i] ?? 0;
|
|
2659
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
2660
|
+
const mask = -(crc & 1);
|
|
2661
|
+
crc = crc >>> 1 ^ 3988292384 & mask;
|
|
2662
|
+
}
|
|
2687
2663
|
}
|
|
2688
|
-
return
|
|
2664
|
+
return (crc ^ 4294967295) >>> 0;
|
|
2689
2665
|
}
|
|
2690
|
-
|
|
2691
|
-
const
|
|
2692
|
-
|
|
2693
|
-
return
|
|
2694
|
-
})();
|
|
2695
|
-
var SRGB_PASSTHROUGH = (() => {
|
|
2696
|
-
const lut = new Float64Array(256);
|
|
2697
|
-
for (let i = 0; i < 256; i++) lut[i] = i;
|
|
2698
|
-
return lut;
|
|
2699
|
-
})();
|
|
2700
|
-
function linearToByte(value) {
|
|
2701
|
-
const c = value <= 31308e-7 ? value * 12.92 : 1.055 * Math.pow(value, 1 / 2.4) - 0.055;
|
|
2702
|
-
return clampByte(c * 255);
|
|
2666
|
+
function chunkCrc32(chunkType, chunkData) {
|
|
2667
|
+
const typeBytes = Buffer.from(chunkType, "ascii");
|
|
2668
|
+
if (nativeCrc32) return nativeCrc32(chunkData, nativeCrc32(typeBytes));
|
|
2669
|
+
return crc32Fallback(chunkData, crc32Fallback(typeBytes, 0));
|
|
2703
2670
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2671
|
+
|
|
2672
|
+
// ../engine/src/utils/alphaBlit.ts
|
|
2673
|
+
function paeth(a, b, c) {
|
|
2674
|
+
const p = a + b - c;
|
|
2675
|
+
const pa = Math.abs(p - a);
|
|
2676
|
+
const pb = Math.abs(p - b);
|
|
2677
|
+
const pc = Math.abs(p - c);
|
|
2678
|
+
if (pa <= pb && pa <= pc) return a;
|
|
2679
|
+
if (pb <= pc) return b;
|
|
2680
|
+
return c;
|
|
2706
2681
|
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
/** Premultiplied r, g, b and alpha sums per pixel. Null until the first sample sets the size. */
|
|
2711
|
-
sums = null;
|
|
2712
|
-
width = 0;
|
|
2713
|
-
height = 0;
|
|
2714
|
-
count = 0;
|
|
2715
|
-
constructor(blend) {
|
|
2716
|
-
this.toWorking = blend === "linear" ? SRGB_TO_LINEAR : SRGB_PASSTHROUGH;
|
|
2717
|
-
this.fromWorking = blend === "linear" ? linearToByte : clampByte;
|
|
2718
|
-
}
|
|
2719
|
-
/** Fold one captured sample PNG into the running average. */
|
|
2720
|
-
add(png) {
|
|
2721
|
-
const { width, height, data } = decodePng(png);
|
|
2722
|
-
if (!this.sums) {
|
|
2723
|
-
this.width = width;
|
|
2724
|
-
this.height = height;
|
|
2725
|
-
this.sums = new Float32Array(width * height * 4);
|
|
2726
|
-
} else if (width !== this.width || height !== this.height) {
|
|
2727
|
-
throw new Error(
|
|
2728
|
-
`MotionBlurAccumulator: sample geometry mismatch (${width}x${height} vs ${this.width}x${this.height})`
|
|
2729
|
-
);
|
|
2730
|
-
}
|
|
2731
|
-
const sums = this.sums;
|
|
2732
|
-
const toWorking = this.toWorking;
|
|
2733
|
-
for (let i = 0; i < sums.length; i += 4) {
|
|
2734
|
-
const alpha = data[i + 3] / 255;
|
|
2735
|
-
sums[i] = sums[i] + toWorking[data[i]] * alpha;
|
|
2736
|
-
sums[i + 1] = sums[i + 1] + toWorking[data[i + 1]] * alpha;
|
|
2737
|
-
sums[i + 2] = sums[i + 2] + toWorking[data[i + 2]] * alpha;
|
|
2738
|
-
sums[i + 3] = sums[i + 3] + alpha;
|
|
2739
|
-
}
|
|
2740
|
-
this.count += 1;
|
|
2682
|
+
function decodePngRaw(buf, caller) {
|
|
2683
|
+
if (buf[0] !== 137 || buf[1] !== 80 || buf[2] !== 78 || buf[3] !== 71 || buf[4] !== 13 || buf[5] !== 10 || buf[6] !== 26 || buf[7] !== 10) {
|
|
2684
|
+
throw new Error(`${caller}: not a PNG file`);
|
|
2741
2685
|
}
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2686
|
+
let pos = 8;
|
|
2687
|
+
let width = 0;
|
|
2688
|
+
let height = 0;
|
|
2689
|
+
let bitDepth = 0;
|
|
2690
|
+
let colorType = 0;
|
|
2691
|
+
let interlace = 0;
|
|
2692
|
+
let sawIhdr = false;
|
|
2693
|
+
const idatChunks = [];
|
|
2694
|
+
while (pos + 12 <= buf.length) {
|
|
2695
|
+
const chunkLen = buf.readUInt32BE(pos);
|
|
2696
|
+
const chunkType = buf.toString("ascii", pos + 4, pos + 8);
|
|
2697
|
+
const chunkData = buf.subarray(pos + 8, pos + 8 + chunkLen);
|
|
2698
|
+
if (chunkType === "IHDR") {
|
|
2699
|
+
width = chunkData.readUInt32BE(0);
|
|
2700
|
+
height = chunkData.readUInt32BE(4);
|
|
2701
|
+
bitDepth = chunkData[8] ?? 0;
|
|
2702
|
+
colorType = chunkData[9] ?? 0;
|
|
2703
|
+
interlace = chunkData[12] ?? 0;
|
|
2704
|
+
sawIhdr = true;
|
|
2705
|
+
} else if (chunkType === "IDAT") {
|
|
2706
|
+
idatChunks.push(Buffer.from(chunkData));
|
|
2707
|
+
} else if (chunkType === "IEND") {
|
|
2708
|
+
break;
|
|
2755
2709
|
}
|
|
2756
|
-
|
|
2710
|
+
pos += 12 + chunkLen;
|
|
2757
2711
|
}
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
await page.evaluateOnNewDocument(acceleratedCanvasTrackerSource());
|
|
2768
|
-
const scale = options.deviceScaleFactor ?? 1;
|
|
2769
|
-
if (scale > 1) {
|
|
2770
|
-
await page.evaluateOnNewDocument(
|
|
2771
|
-
(key, v) => {
|
|
2772
|
-
window[key] = v;
|
|
2773
|
-
},
|
|
2774
|
-
PAGE_DEVICE_SCALE_GLOBAL,
|
|
2775
|
-
scale
|
|
2712
|
+
if (!sawIhdr) {
|
|
2713
|
+
throw new Error(`${caller}: PNG missing IHDR chunk`);
|
|
2714
|
+
}
|
|
2715
|
+
if (colorType !== 2 && colorType !== 6) {
|
|
2716
|
+
throw new Error(`${caller}: unsupported color type ${colorType} (expected 2=RGB or 6=RGBA)`);
|
|
2717
|
+
}
|
|
2718
|
+
if (interlace !== 0) {
|
|
2719
|
+
throw new Error(
|
|
2720
|
+
`${caller}: Adam7-interlaced PNGs are not supported (interlace method ${interlace})`
|
|
2776
2721
|
);
|
|
2777
2722
|
}
|
|
2778
|
-
const
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2723
|
+
const channels = colorType === 6 ? 4 : 3;
|
|
2724
|
+
const bpp = channels * (bitDepth / 8);
|
|
2725
|
+
const stride = width * bpp;
|
|
2726
|
+
const compressed = Buffer.concat(idatChunks);
|
|
2727
|
+
const decompressed = inflateSync(compressed);
|
|
2728
|
+
const rawPixels = Buffer.allocUnsafe(height * stride);
|
|
2729
|
+
const prevRow = new Uint8Array(stride);
|
|
2730
|
+
const currRow = new Uint8Array(stride);
|
|
2731
|
+
let srcPos = 0;
|
|
2732
|
+
for (let y = 0; y < height; y++) {
|
|
2733
|
+
const filterType = decompressed[srcPos++] ?? 0;
|
|
2734
|
+
const rawRow = decompressed.subarray(srcPos, srcPos + stride);
|
|
2735
|
+
srcPos += stride;
|
|
2736
|
+
switch (filterType) {
|
|
2737
|
+
case 0:
|
|
2738
|
+
currRow.set(rawRow);
|
|
2739
|
+
break;
|
|
2740
|
+
case 1:
|
|
2741
|
+
for (let x = 0; x < stride; x++) {
|
|
2742
|
+
currRow[x] = (rawRow[x] ?? 0) + (x >= bpp ? currRow[x - bpp] ?? 0 : 0) & 255;
|
|
2743
|
+
}
|
|
2744
|
+
break;
|
|
2745
|
+
case 2:
|
|
2746
|
+
for (let x = 0; x < stride; x++) {
|
|
2747
|
+
currRow[x] = (rawRow[x] ?? 0) + (prevRow[x] ?? 0) & 255;
|
|
2748
|
+
}
|
|
2749
|
+
break;
|
|
2750
|
+
case 3:
|
|
2751
|
+
for (let x = 0; x < stride; x++) {
|
|
2752
|
+
const left = x >= bpp ? currRow[x - bpp] ?? 0 : 0;
|
|
2753
|
+
const up = prevRow[x] ?? 0;
|
|
2754
|
+
currRow[x] = (rawRow[x] ?? 0) + Math.floor((left + up) / 2) & 255;
|
|
2755
|
+
}
|
|
2756
|
+
break;
|
|
2757
|
+
case 4:
|
|
2758
|
+
for (let x = 0; x < stride; x++) {
|
|
2759
|
+
const left = x >= bpp ? currRow[x - bpp] ?? 0 : 0;
|
|
2760
|
+
const up = prevRow[x] ?? 0;
|
|
2761
|
+
const upLeft = x >= bpp ? prevRow[x - bpp] ?? 0 : 0;
|
|
2762
|
+
currRow[x] = (rawRow[x] ?? 0) + paeth(left, up, upLeft) & 255;
|
|
2763
|
+
}
|
|
2764
|
+
break;
|
|
2765
|
+
default:
|
|
2766
|
+
throw new Error(`${caller}: unknown filter type ${filterType} at row ${y}`);
|
|
2767
|
+
}
|
|
2768
|
+
rawPixels.set(currRow, y * stride);
|
|
2769
|
+
prevRow.set(currRow);
|
|
2821
2770
|
}
|
|
2771
|
+
return { width, height, bitDepth, colorType, rawPixels };
|
|
2822
2772
|
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
var transports = /* @__PURE__ */ new WeakMap();
|
|
2828
|
-
async function createTransport(page) {
|
|
2829
|
-
const pageUrl = new URL(page.url());
|
|
2830
|
-
const origin = /^https?:$/.test(pageUrl.protocol) ? pageUrl.origin : "https://hyperframes-render.invalid";
|
|
2831
|
-
const prefix = `${origin}/__hyperframes_video_frames__/${randomUUID()}/`;
|
|
2832
|
-
const responses = /* @__PURE__ */ new Map();
|
|
2833
|
-
const client = await page.createCDPSession();
|
|
2834
|
-
client.on("Fetch.requestPaused", (event) => {
|
|
2835
|
-
const frame = responses.get(event.request.url);
|
|
2836
|
-
void fulfillFrame(client, event.requestId, frame);
|
|
2837
|
-
});
|
|
2838
|
-
try {
|
|
2839
|
-
await client.send("Fetch.enable", {
|
|
2840
|
-
patterns: [{ urlPattern: `${prefix}*`, requestStage: "Request" }]
|
|
2841
|
-
});
|
|
2842
|
-
} catch (error) {
|
|
2843
|
-
await client.detach().catch(() => {
|
|
2844
|
-
});
|
|
2845
|
-
throw error;
|
|
2773
|
+
function decodePng(buf) {
|
|
2774
|
+
const { width, height, bitDepth, colorType, rawPixels } = decodePngRaw(buf, "decodePng");
|
|
2775
|
+
if (bitDepth !== 8) {
|
|
2776
|
+
throw new Error(`decodePng: unsupported bit depth ${bitDepth} (expected 8)`);
|
|
2846
2777
|
}
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
{ name: "Cache-Control", value: "no-store" },
|
|
2858
|
-
{ name: "Access-Control-Allow-Origin", value: "*" }
|
|
2859
|
-
],
|
|
2860
|
-
body: frame?.body ?? ""
|
|
2861
|
-
});
|
|
2862
|
-
} catch (error) {
|
|
2863
|
-
if (frame) frame.error = error;
|
|
2864
|
-
await client.send("Fetch.failRequest", { requestId, errorReason: "Failed" }).catch(() => {
|
|
2865
|
-
});
|
|
2778
|
+
const output = new Uint8Array(width * height * 4);
|
|
2779
|
+
if (colorType === 6) {
|
|
2780
|
+
output.set(rawPixels);
|
|
2781
|
+
} else {
|
|
2782
|
+
for (let i = 0; i < width * height; i++) {
|
|
2783
|
+
output[i * 4 + 0] = rawPixels[i * 3 + 0] ?? 0;
|
|
2784
|
+
output[i * 4 + 1] = rawPixels[i * 3 + 1] ?? 0;
|
|
2785
|
+
output[i * 4 + 2] = rawPixels[i * 3 + 2] ?? 0;
|
|
2786
|
+
output[i * 4 + 3] = 255;
|
|
2787
|
+
}
|
|
2866
2788
|
}
|
|
2789
|
+
return { width, height, data: output };
|
|
2867
2790
|
}
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2791
|
+
var PNG_DEFLATE_LEVEL = 1;
|
|
2792
|
+
function pngChunk(type, body) {
|
|
2793
|
+
const header = Buffer.alloc(8);
|
|
2794
|
+
header.writeUInt32BE(body.length, 0);
|
|
2795
|
+
header.write(type, 4, "ascii");
|
|
2796
|
+
const trailer = Buffer.alloc(4);
|
|
2797
|
+
trailer.writeUInt32BE(chunkCrc32(type, body), 0);
|
|
2798
|
+
return Buffer.concat([header, body, trailer]);
|
|
2799
|
+
}
|
|
2800
|
+
function encodePng(width, height, rgba) {
|
|
2801
|
+
const expected = width * height * 4;
|
|
2802
|
+
if (rgba.length !== expected) {
|
|
2803
|
+
throw new Error(
|
|
2804
|
+
`encodePng: expected ${expected} bytes for ${width}x${height}, got ${rgba.length}`
|
|
2805
|
+
);
|
|
2874
2806
|
}
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
throw error;
|
|
2807
|
+
const stride = width * 4;
|
|
2808
|
+
const filtered = Buffer.alloc((stride + 1) * height);
|
|
2809
|
+
for (let y = 0; y < height; y++) {
|
|
2810
|
+
filtered[y * (stride + 1)] = 0;
|
|
2811
|
+
filtered.set(rgba.subarray(y * stride, (y + 1) * stride), y * (stride + 1) + 1);
|
|
2881
2812
|
}
|
|
2882
|
-
const
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2813
|
+
const ihdr = Buffer.alloc(13);
|
|
2814
|
+
ihdr.writeUInt32BE(width, 0);
|
|
2815
|
+
ihdr.writeUInt32BE(height, 4);
|
|
2816
|
+
ihdr[8] = 8;
|
|
2817
|
+
ihdr[9] = 6;
|
|
2818
|
+
return Buffer.concat([
|
|
2819
|
+
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
2820
|
+
pngChunk("IHDR", ihdr),
|
|
2821
|
+
pngChunk("IDAT", deflateSync(filtered, { level: PNG_DEFLATE_LEVEL })),
|
|
2822
|
+
pngChunk("IEND", Buffer.alloc(0))
|
|
2823
|
+
]);
|
|
2824
|
+
}
|
|
2825
|
+
function decodePngToRgb48le(buf) {
|
|
2826
|
+
const { width, height, bitDepth, colorType, rawPixels } = decodePngRaw(buf, "decodePngToRgb48le");
|
|
2827
|
+
if (bitDepth !== 16) {
|
|
2828
|
+
throw new Error(`decodePngToRgb48le: unsupported bit depth ${bitDepth} (expected 16)`);
|
|
2829
|
+
}
|
|
2830
|
+
const bpp = colorType === 6 ? 8 : 6;
|
|
2831
|
+
const output = Buffer.allocUnsafe(width * height * 6);
|
|
2832
|
+
for (let y = 0; y < height; y++) {
|
|
2833
|
+
const dstBase = y * width * 6;
|
|
2834
|
+
const srcRowBase = y * width * bpp;
|
|
2835
|
+
for (let x = 0; x < width; x++) {
|
|
2836
|
+
const srcBase = srcRowBase + x * bpp;
|
|
2837
|
+
output[dstBase + x * 6 + 0] = rawPixels[srcBase + 1] ?? 0;
|
|
2838
|
+
output[dstBase + x * 6 + 1] = rawPixels[srcBase + 0] ?? 0;
|
|
2839
|
+
output[dstBase + x * 6 + 2] = rawPixels[srcBase + 3] ?? 0;
|
|
2840
|
+
output[dstBase + x * 6 + 3] = rawPixels[srcBase + 2] ?? 0;
|
|
2841
|
+
output[dstBase + x * 6 + 4] = rawPixels[srcBase + 5] ?? 0;
|
|
2842
|
+
output[dstBase + x * 6 + 5] = rawPixels[srcBase + 4] ?? 0;
|
|
2843
|
+
}
|
|
2906
2844
|
}
|
|
2845
|
+
return { width, height, data: output };
|
|
2907
2846
|
}
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2847
|
+
function srgbByteToLinear(value) {
|
|
2848
|
+
const v = value / 255;
|
|
2849
|
+
return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
2850
|
+
}
|
|
2851
|
+
function buildSrgbToSignalLut(transfer) {
|
|
2852
|
+
const lut = new Uint16Array(256);
|
|
2853
|
+
const hlgA = 0.17883277;
|
|
2854
|
+
const hlgB = 1 - 4 * hlgA;
|
|
2855
|
+
const hlgC = 0.5 - hlgA * Math.log(4 * hlgA);
|
|
2856
|
+
const hlgSdrWhite = (Math.exp((0.75 - hlgC) / hlgA) + hlgB) / 12;
|
|
2857
|
+
const pqM1 = 0.1593017578125;
|
|
2858
|
+
const pqM2 = 78.84375;
|
|
2859
|
+
const pqC1 = 0.8359375;
|
|
2860
|
+
const pqC2 = 18.8515625;
|
|
2861
|
+
const pqC3 = 18.6875;
|
|
2862
|
+
const pqMaxNits = 1e4;
|
|
2863
|
+
const sdrNits = 203;
|
|
2864
|
+
for (let i = 0; i < 256; i++) {
|
|
2865
|
+
if (transfer === "srgb") {
|
|
2866
|
+
lut[i] = i * 257;
|
|
2867
|
+
continue;
|
|
2868
|
+
}
|
|
2869
|
+
const linear = srgbByteToLinear(i);
|
|
2870
|
+
let signal;
|
|
2871
|
+
if (transfer === "hlg") {
|
|
2872
|
+
const scene = linear * hlgSdrWhite;
|
|
2873
|
+
signal = scene <= 1 / 12 ? Math.sqrt(3 * scene) : hlgA * Math.log(12 * scene - hlgB) + hlgC;
|
|
2874
|
+
} else {
|
|
2875
|
+
const Lp = Math.max(0, linear * sdrNits / pqMaxNits);
|
|
2876
|
+
const Lm1 = Math.pow(Lp, pqM1);
|
|
2877
|
+
signal = Math.pow((pqC1 + pqC2 * Lm1) / (1 + pqC3 * Lm1), pqM2);
|
|
2878
|
+
}
|
|
2879
|
+
lut[i] = Math.min(65535, Math.round(signal * 65535));
|
|
2916
2880
|
}
|
|
2917
|
-
return
|
|
2881
|
+
return lut;
|
|
2918
2882
|
}
|
|
2919
|
-
|
|
2920
|
-
|
|
2883
|
+
var SRGB_TO_SRGB_16 = buildSrgbToSignalLut("srgb");
|
|
2884
|
+
var SRGB_TO_HLG = buildSrgbToSignalLut("hlg");
|
|
2885
|
+
var SRGB_TO_PQ = buildSrgbToSignalLut("pq");
|
|
2886
|
+
function getSrgbToSignalLut(transfer) {
|
|
2887
|
+
if (transfer === "pq") return SRGB_TO_PQ;
|
|
2888
|
+
if (transfer === "hlg") return SRGB_TO_HLG;
|
|
2889
|
+
return SRGB_TO_SRGB_16;
|
|
2921
2890
|
}
|
|
2922
|
-
|
|
2923
|
-
const
|
|
2924
|
-
const
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2891
|
+
function blitRgba8OverRgb48le(domRgba, canvas, width, height, transfer = "hlg") {
|
|
2892
|
+
const pixelCount = width * height;
|
|
2893
|
+
const lut = getSrgbToSignalLut(transfer);
|
|
2894
|
+
for (let i = 0; i < pixelCount; i++) {
|
|
2895
|
+
const da = domRgba[i * 4 + 3] ?? 0;
|
|
2896
|
+
if (da === 0) {
|
|
2897
|
+
continue;
|
|
2898
|
+
} else if (da === 255) {
|
|
2899
|
+
const r16 = lut[domRgba[i * 4 + 0] ?? 0] ?? 0;
|
|
2900
|
+
const g16 = lut[domRgba[i * 4 + 1] ?? 0] ?? 0;
|
|
2901
|
+
const b16 = lut[domRgba[i * 4 + 2] ?? 0] ?? 0;
|
|
2902
|
+
canvas.writeUInt16LE(r16, i * 6);
|
|
2903
|
+
canvas.writeUInt16LE(g16, i * 6 + 2);
|
|
2904
|
+
canvas.writeUInt16LE(b16, i * 6 + 4);
|
|
2905
|
+
} else {
|
|
2906
|
+
const alpha = da / 255;
|
|
2907
|
+
const invAlpha = 1 - alpha;
|
|
2908
|
+
const hdrR = (canvas[i * 6 + 0] ?? 0) | (canvas[i * 6 + 1] ?? 0) << 8;
|
|
2909
|
+
const hdrG = (canvas[i * 6 + 2] ?? 0) | (canvas[i * 6 + 3] ?? 0) << 8;
|
|
2910
|
+
const hdrB = (canvas[i * 6 + 4] ?? 0) | (canvas[i * 6 + 5] ?? 0) << 8;
|
|
2911
|
+
const domR = lut[domRgba[i * 4 + 0] ?? 0] ?? 0;
|
|
2912
|
+
const domG = lut[domRgba[i * 4 + 1] ?? 0] ?? 0;
|
|
2913
|
+
const domB = lut[domRgba[i * 4 + 2] ?? 0] ?? 0;
|
|
2914
|
+
canvas.writeUInt16LE(Math.round(domR * alpha + hdrR * invAlpha), i * 6);
|
|
2915
|
+
canvas.writeUInt16LE(Math.round(domG * alpha + hdrG * invAlpha), i * 6 + 2);
|
|
2916
|
+
canvas.writeUInt16LE(Math.round(domB * alpha + hdrB * invAlpha), i * 6 + 4);
|
|
2917
|
+
}
|
|
2937
2918
|
}
|
|
2938
2919
|
}
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2920
|
+
function cornerAlpha(px, py, cx, cy, r) {
|
|
2921
|
+
const dx = px - cx;
|
|
2922
|
+
const dy = py - cy;
|
|
2923
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
2924
|
+
if (dist > r + 0.5) return 0;
|
|
2925
|
+
if (dist > r - 0.5) return r + 0.5 - dist;
|
|
2926
|
+
return 1;
|
|
2927
|
+
}
|
|
2928
|
+
function roundedRectAlpha(px, py, w, h, radii) {
|
|
2929
|
+
const [tl, tr, br, bl] = radii;
|
|
2930
|
+
if (px < tl && py < tl) return cornerAlpha(px, py, tl, tl, tl);
|
|
2931
|
+
if (px >= w - tr && py < tr) return cornerAlpha(px, py, w - tr, tr, tr);
|
|
2932
|
+
if (px >= w - br && py >= h - br) return cornerAlpha(px, py, w - br, h - br, br);
|
|
2933
|
+
if (px < bl && py >= h - bl) return cornerAlpha(px, py, bl, h - bl, bl);
|
|
2934
|
+
return 1;
|
|
2935
|
+
}
|
|
2936
|
+
function blitRgb48leRegion(canvas, source, dx, dy, sw, sh, canvasWidth, canvasHeight, opacity, borderRadius) {
|
|
2937
|
+
if (sw <= 0 || sh <= 0) return;
|
|
2938
|
+
const op = opacity ?? 1;
|
|
2939
|
+
if (op <= 0) return;
|
|
2940
|
+
const x0 = Math.max(0, dx);
|
|
2941
|
+
const y0 = Math.max(0, dy);
|
|
2942
|
+
const x1 = Math.min(canvasWidth, dx + sw);
|
|
2943
|
+
const y1 = Math.min(canvasHeight, dy + sh);
|
|
2944
|
+
if (x0 >= x1 || y0 >= y1) return;
|
|
2945
|
+
const clippedW = x1 - x0;
|
|
2946
|
+
const srcOffsetX = x0 - dx;
|
|
2947
|
+
const srcOffsetY = y0 - dy;
|
|
2948
|
+
const hasMask = borderRadius !== void 0;
|
|
2949
|
+
if (op >= 0.999 && !hasMask) {
|
|
2950
|
+
for (let y = 0; y < y1 - y0; y++) {
|
|
2951
|
+
const srcRowOff = ((srcOffsetY + y) * sw + srcOffsetX) * 6;
|
|
2952
|
+
const dstRowOff = ((y0 + y) * canvasWidth + x0) * 6;
|
|
2953
|
+
source.copy(canvas, dstRowOff, srcRowOff, srcRowOff + clippedW * 6);
|
|
2954
|
+
}
|
|
2955
|
+
} else if (!hasMask) {
|
|
2956
|
+
const invOp = 1 - op;
|
|
2957
|
+
for (let y = 0; y < y1 - y0; y++) {
|
|
2958
|
+
let srcOff = ((srcOffsetY + y) * sw + srcOffsetX) * 6;
|
|
2959
|
+
let dstOff = ((y0 + y) * canvasWidth + x0) * 6;
|
|
2960
|
+
for (let x = 0; x < clippedW; x++) {
|
|
2961
|
+
const sr = source[srcOff] | source[srcOff + 1] << 8;
|
|
2962
|
+
const sg = source[srcOff + 2] | source[srcOff + 3] << 8;
|
|
2963
|
+
const sb = source[srcOff + 4] | source[srcOff + 5] << 8;
|
|
2964
|
+
const dr = canvas[dstOff] | canvas[dstOff + 1] << 8;
|
|
2965
|
+
const dg = canvas[dstOff + 2] | canvas[dstOff + 3] << 8;
|
|
2966
|
+
const db = canvas[dstOff + 4] | canvas[dstOff + 5] << 8;
|
|
2967
|
+
const r = sr * op + dr * invOp + 0.5 | 0;
|
|
2968
|
+
const g = sg * op + dg * invOp + 0.5 | 0;
|
|
2969
|
+
const b = sb * op + db * invOp + 0.5 | 0;
|
|
2970
|
+
canvas[dstOff] = r & 255;
|
|
2971
|
+
canvas[dstOff + 1] = r >>> 8;
|
|
2972
|
+
canvas[dstOff + 2] = g & 255;
|
|
2973
|
+
canvas[dstOff + 3] = g >>> 8;
|
|
2974
|
+
canvas[dstOff + 4] = b & 255;
|
|
2975
|
+
canvas[dstOff + 5] = b >>> 8;
|
|
2976
|
+
srcOff += 6;
|
|
2977
|
+
dstOff += 6;
|
|
2951
2978
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2979
|
+
}
|
|
2980
|
+
} else {
|
|
2981
|
+
for (let y = 0; y < y1 - y0; y++) {
|
|
2982
|
+
for (let x = 0; x < clippedW; x++) {
|
|
2983
|
+
let effectiveOp = op;
|
|
2984
|
+
if (hasMask) {
|
|
2985
|
+
const ma = roundedRectAlpha(srcOffsetX + x, srcOffsetY + y, sw, sh, borderRadius);
|
|
2986
|
+
if (ma <= 0) continue;
|
|
2987
|
+
effectiveOp *= ma;
|
|
2988
|
+
}
|
|
2989
|
+
const srcOff = ((srcOffsetY + y) * sw + srcOffsetX + x) * 6;
|
|
2990
|
+
const dstOff = ((y0 + y) * canvasWidth + x0 + x) * 6;
|
|
2991
|
+
if (effectiveOp >= 0.999) {
|
|
2992
|
+
source.copy(canvas, dstOff, srcOff, srcOff + 6);
|
|
2993
|
+
} else {
|
|
2994
|
+
const invEff = 1 - effectiveOp;
|
|
2995
|
+
const sr = source.readUInt16LE(srcOff);
|
|
2996
|
+
const sg = source.readUInt16LE(srcOff + 2);
|
|
2997
|
+
const sb = source.readUInt16LE(srcOff + 4);
|
|
2998
|
+
const dr = canvas.readUInt16LE(dstOff);
|
|
2999
|
+
const dg = canvas.readUInt16LE(dstOff + 2);
|
|
3000
|
+
const db = canvas.readUInt16LE(dstOff + 4);
|
|
3001
|
+
canvas.writeUInt16LE(Math.round(sr * effectiveOp + dr * invEff), dstOff);
|
|
3002
|
+
canvas.writeUInt16LE(Math.round(sg * effectiveOp + dg * invEff), dstOff + 2);
|
|
3003
|
+
canvas.writeUInt16LE(Math.round(sb * effectiveOp + db * invEff), dstOff + 4);
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
function blitRgb48leAffine(canvas, source, matrix, srcW, srcH, canvasW, canvasH, opacity, borderRadius) {
|
|
3010
|
+
const a = matrix[0];
|
|
3011
|
+
const b = matrix[1];
|
|
3012
|
+
const c = matrix[2];
|
|
3013
|
+
const d = matrix[3];
|
|
3014
|
+
const tx = matrix[4];
|
|
3015
|
+
const ty = matrix[5];
|
|
3016
|
+
if (a === void 0 || b === void 0 || c === void 0 || d === void 0 || tx === void 0 || ty === void 0)
|
|
3017
|
+
return;
|
|
3018
|
+
const det = a * d - b * c;
|
|
3019
|
+
if (Math.abs(det) < 1e-10) return;
|
|
3020
|
+
const invA = d / det;
|
|
3021
|
+
const invB = -b / det;
|
|
3022
|
+
const invC = -c / det;
|
|
3023
|
+
const invD = a / det;
|
|
3024
|
+
const invTx = -(invA * tx + invC * ty);
|
|
3025
|
+
const invTy = -(invB * tx + invD * ty);
|
|
3026
|
+
const op = opacity ?? 1;
|
|
3027
|
+
if (op <= 0) return;
|
|
3028
|
+
const hasMask = borderRadius !== void 0;
|
|
3029
|
+
const corners = [
|
|
3030
|
+
[tx, ty],
|
|
3031
|
+
[a * srcW + tx, b * srcW + ty],
|
|
3032
|
+
[c * srcH + tx, d * srcH + ty],
|
|
3033
|
+
[a * srcW + c * srcH + tx, b * srcW + d * srcH + ty]
|
|
3034
|
+
];
|
|
3035
|
+
let minX = canvasW, maxX = 0, minY = canvasH, maxY = 0;
|
|
3036
|
+
for (const corner of corners) {
|
|
3037
|
+
const cx = corner[0] ?? 0;
|
|
3038
|
+
const cy = corner[1] ?? 0;
|
|
3039
|
+
if (cx < minX) minX = cx;
|
|
3040
|
+
if (cx > maxX) maxX = cx;
|
|
3041
|
+
if (cy < minY) minY = cy;
|
|
3042
|
+
if (cy > maxY) maxY = cy;
|
|
3043
|
+
}
|
|
3044
|
+
const startX = Math.max(0, Math.floor(minX));
|
|
3045
|
+
const endX = Math.min(canvasW, Math.ceil(maxX));
|
|
3046
|
+
const startY = Math.max(0, Math.floor(minY));
|
|
3047
|
+
const endY = Math.min(canvasH, Math.ceil(maxY));
|
|
3048
|
+
for (let dy = startY; dy < endY; dy++) {
|
|
3049
|
+
for (let dx = startX; dx < endX; dx++) {
|
|
3050
|
+
const sx = invA * dx + invC * dy + invTx;
|
|
3051
|
+
const sy = invB * dx + invD * dy + invTy;
|
|
3052
|
+
if (sx < 0 || sy < 0 || sx >= srcW || sy >= srcH) continue;
|
|
3053
|
+
let effectiveOp = op;
|
|
3054
|
+
if (hasMask) {
|
|
3055
|
+
const ma = roundedRectAlpha(sx, sy, srcW, srcH, borderRadius);
|
|
3056
|
+
if (ma <= 0) continue;
|
|
3057
|
+
effectiveOp *= ma;
|
|
3058
|
+
}
|
|
3059
|
+
const x0 = Math.floor(sx);
|
|
3060
|
+
const y0 = Math.floor(sy);
|
|
3061
|
+
const fx = sx - x0;
|
|
3062
|
+
const fy = sy - y0;
|
|
3063
|
+
const x1 = Math.min(x0 + 1, srcW - 1);
|
|
3064
|
+
const y1 = Math.min(y0 + 1, srcH - 1);
|
|
3065
|
+
const off00 = (y0 * srcW + x0) * 6;
|
|
3066
|
+
const off10 = (y0 * srcW + x1) * 6;
|
|
3067
|
+
const off01 = (y1 * srcW + x0) * 6;
|
|
3068
|
+
const off11 = (y1 * srcW + x1) * 6;
|
|
3069
|
+
const w00 = (1 - fx) * (1 - fy);
|
|
3070
|
+
const w10 = fx * (1 - fy);
|
|
3071
|
+
const w01 = (1 - fx) * fy;
|
|
3072
|
+
const w11 = fx * fy;
|
|
3073
|
+
const sr = source.readUInt16LE(off00) * w00 + source.readUInt16LE(off10) * w10 + source.readUInt16LE(off01) * w01 + source.readUInt16LE(off11) * w11;
|
|
3074
|
+
const sg = source.readUInt16LE(off00 + 2) * w00 + source.readUInt16LE(off10 + 2) * w10 + source.readUInt16LE(off01 + 2) * w01 + source.readUInt16LE(off11 + 2) * w11;
|
|
3075
|
+
const sb = source.readUInt16LE(off00 + 4) * w00 + source.readUInt16LE(off10 + 4) * w10 + source.readUInt16LE(off01 + 4) * w01 + source.readUInt16LE(off11 + 4) * w11;
|
|
3076
|
+
const dstOff = (dy * canvasW + dx) * 6;
|
|
3077
|
+
if (effectiveOp >= 0.999) {
|
|
3078
|
+
canvas.writeUInt16LE(Math.round(sr), dstOff);
|
|
3079
|
+
canvas.writeUInt16LE(Math.round(sg), dstOff + 2);
|
|
3080
|
+
canvas.writeUInt16LE(Math.round(sb), dstOff + 4);
|
|
3081
|
+
} else {
|
|
3082
|
+
const invEff = 1 - effectiveOp;
|
|
3083
|
+
const dr = canvas.readUInt16LE(dstOff);
|
|
3084
|
+
const dg = canvas.readUInt16LE(dstOff + 2);
|
|
3085
|
+
const db = canvas.readUInt16LE(dstOff + 4);
|
|
3086
|
+
canvas.writeUInt16LE(Math.round(sr * effectiveOp + dr * invEff), dstOff);
|
|
3087
|
+
canvas.writeUInt16LE(Math.round(sg * effectiveOp + dg * invEff), dstOff + 2);
|
|
3088
|
+
canvas.writeUInt16LE(Math.round(sb * effectiveOp + db * invEff), dstOff + 4);
|
|
2956
3089
|
}
|
|
2957
|
-
throw err;
|
|
2958
3090
|
}
|
|
2959
3091
|
}
|
|
2960
3092
|
}
|
|
2961
|
-
|
|
2962
|
-
const
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
3093
|
+
function parseObjectPositionAxis(value, axis) {
|
|
3094
|
+
const lower = value.trim().toLowerCase();
|
|
3095
|
+
if (lower === "left" || lower === "top") return 0;
|
|
3096
|
+
if (lower === "right" || lower === "bottom") return 1;
|
|
3097
|
+
if (lower === "center" || lower === "") return 0.5;
|
|
3098
|
+
if (lower.endsWith("%")) {
|
|
3099
|
+
const pct = parseFloat(lower) / 100;
|
|
3100
|
+
return Number.isFinite(pct) ? pct : 0.5;
|
|
3101
|
+
}
|
|
3102
|
+
if (axis === "x" || axis === "y") return 0.5;
|
|
3103
|
+
return 0.5;
|
|
3104
|
+
}
|
|
3105
|
+
function parseObjectPosition(css) {
|
|
3106
|
+
if (!css || !css.trim()) return { x: 0.5, y: 0.5 };
|
|
3107
|
+
const tokens = css.trim().split(/\s+/);
|
|
3108
|
+
if (tokens.length === 1) {
|
|
3109
|
+
const single = tokens[0] ?? "";
|
|
3110
|
+
const v = parseObjectPositionAxis(single, "x");
|
|
3111
|
+
return { x: v, y: 0.5 };
|
|
3112
|
+
}
|
|
3113
|
+
return {
|
|
3114
|
+
x: parseObjectPositionAxis(tokens[0] ?? "", "x"),
|
|
3115
|
+
y: parseObjectPositionAxis(tokens[1] ?? "", "y")
|
|
2968
3116
|
};
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
3117
|
+
}
|
|
3118
|
+
function computeObjectFitRect(srcW, srcH, dstW, dstH, fit, pos) {
|
|
3119
|
+
let renderedW = dstW;
|
|
3120
|
+
let renderedH = dstH;
|
|
3121
|
+
if (fit === "fill") {
|
|
3122
|
+
return { dx: 0, dy: 0, dw: dstW, dh: dstH };
|
|
3123
|
+
}
|
|
3124
|
+
if (fit === "none") {
|
|
3125
|
+
renderedW = srcW;
|
|
3126
|
+
renderedH = srcH;
|
|
3127
|
+
} else if (fit === "scale-down") {
|
|
3128
|
+
const scale = Math.min(dstW / srcW, dstH / srcH, 1);
|
|
3129
|
+
renderedW = srcW * scale;
|
|
3130
|
+
renderedH = srcH * scale;
|
|
3131
|
+
} else if (fit === "cover") {
|
|
3132
|
+
const scale = Math.max(dstW / srcW, dstH / srcH);
|
|
3133
|
+
renderedW = srcW * scale;
|
|
3134
|
+
renderedH = srcH * scale;
|
|
2974
3135
|
} else {
|
|
2975
|
-
const
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
3136
|
+
const scale = Math.min(dstW / srcW, dstH / srcH);
|
|
3137
|
+
renderedW = srcW * scale;
|
|
3138
|
+
renderedH = srcH * scale;
|
|
3139
|
+
}
|
|
3140
|
+
const dx = (dstW - renderedW) * pos.x;
|
|
3141
|
+
const dy = (dstH - renderedH) * pos.y;
|
|
3142
|
+
return { dx, dy, dw: renderedW, dh: renderedH };
|
|
3143
|
+
}
|
|
3144
|
+
function resampleRgb48leObjectFit(source, srcW, srcH, dstW, dstH, fit = "fill", objectPosition) {
|
|
3145
|
+
if (srcW <= 0 || srcH <= 0 || dstW <= 0 || dstH <= 0) {
|
|
3146
|
+
return source;
|
|
3147
|
+
}
|
|
3148
|
+
if (fit === "fill" && srcW === dstW && srcH === dstH) {
|
|
3149
|
+
return source;
|
|
3150
|
+
}
|
|
3151
|
+
const pos = parseObjectPosition(objectPosition);
|
|
3152
|
+
const rect = computeObjectFitRect(srcW, srcH, dstW, dstH, fit, pos);
|
|
3153
|
+
const dst = Buffer.alloc(dstW * dstH * 6);
|
|
3154
|
+
const stride = dstW * 6;
|
|
3155
|
+
const xMin = Math.max(0, Math.floor(rect.dx));
|
|
3156
|
+
const yMin = Math.max(0, Math.floor(rect.dy));
|
|
3157
|
+
const xMax = Math.min(dstW, Math.ceil(rect.dx + rect.dw));
|
|
3158
|
+
const yMax = Math.min(dstH, Math.ceil(rect.dy + rect.dh));
|
|
3159
|
+
if (rect.dw <= 0 || rect.dh <= 0) {
|
|
3160
|
+
return dst;
|
|
3161
|
+
}
|
|
3162
|
+
const invScaleX = srcW / rect.dw;
|
|
3163
|
+
const invScaleY = srcH / rect.dh;
|
|
3164
|
+
for (let dy = yMin; dy < yMax; dy++) {
|
|
3165
|
+
const rowOff = dy * stride;
|
|
3166
|
+
const sy = (dy + 0.5 - rect.dy) * invScaleY - 0.5;
|
|
3167
|
+
const syc = Math.max(0, Math.min(srcH - 1, sy));
|
|
3168
|
+
const y0 = Math.floor(syc);
|
|
3169
|
+
const y1 = Math.min(y0 + 1, srcH - 1);
|
|
3170
|
+
const fy = syc - y0;
|
|
3171
|
+
const ify = 1 - fy;
|
|
3172
|
+
for (let dx = xMin; dx < xMax; dx++) {
|
|
3173
|
+
const sx = (dx + 0.5 - rect.dx) * invScaleX - 0.5;
|
|
3174
|
+
const sxc = Math.max(0, Math.min(srcW - 1, sx));
|
|
3175
|
+
const x0 = Math.floor(sxc);
|
|
3176
|
+
const x1 = Math.min(x0 + 1, srcW - 1);
|
|
3177
|
+
const fx = sxc - x0;
|
|
3178
|
+
const ifx = 1 - fx;
|
|
3179
|
+
const off00 = (y0 * srcW + x0) * 6;
|
|
3180
|
+
const off10 = (y0 * srcW + x1) * 6;
|
|
3181
|
+
const off01 = (y1 * srcW + x0) * 6;
|
|
3182
|
+
const off11 = (y1 * srcW + x1) * 6;
|
|
3183
|
+
const w00 = ifx * ify;
|
|
3184
|
+
const w10 = fx * ify;
|
|
3185
|
+
const w01 = ifx * fy;
|
|
3186
|
+
const w11 = fx * fy;
|
|
3187
|
+
const r = source.readUInt16LE(off00) * w00 + source.readUInt16LE(off10) * w10 + source.readUInt16LE(off01) * w01 + source.readUInt16LE(off11) * w11;
|
|
3188
|
+
const g = source.readUInt16LE(off00 + 2) * w00 + source.readUInt16LE(off10 + 2) * w10 + source.readUInt16LE(off01 + 2) * w01 + source.readUInt16LE(off11 + 2) * w11;
|
|
3189
|
+
const b = source.readUInt16LE(off00 + 4) * w00 + source.readUInt16LE(off10 + 4) * w10 + source.readUInt16LE(off01 + 4) * w01 + source.readUInt16LE(off11 + 4) * w11;
|
|
3190
|
+
const dstOff = rowOff + dx * 6;
|
|
3191
|
+
dst.writeUInt16LE(Math.round(r), dstOff);
|
|
3192
|
+
dst.writeUInt16LE(Math.round(g), dstOff + 2);
|
|
3193
|
+
dst.writeUInt16LE(Math.round(b), dstOff + 4);
|
|
2986
3194
|
}
|
|
2987
3195
|
}
|
|
2988
|
-
return
|
|
2989
|
-
buffer,
|
|
2990
|
-
hasDamage: result.hasDamage
|
|
2991
|
-
};
|
|
3196
|
+
return dst;
|
|
2992
3197
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
3198
|
+
function normalizeObjectFit(value) {
|
|
3199
|
+
switch ((value ?? "").trim().toLowerCase()) {
|
|
3200
|
+
case "cover":
|
|
3201
|
+
return "cover";
|
|
3202
|
+
case "contain":
|
|
3203
|
+
return "contain";
|
|
3204
|
+
case "none":
|
|
3205
|
+
return "none";
|
|
3206
|
+
case "scale-down":
|
|
3207
|
+
return "scale-down";
|
|
3208
|
+
default:
|
|
3209
|
+
return "fill";
|
|
3210
|
+
}
|
|
2996
3211
|
}
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
const
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3212
|
+
function parseTransformMatrix(css) {
|
|
3213
|
+
if (!css || css === "none") return null;
|
|
3214
|
+
const match2d = css.match(/^matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,)]+)\)$/);
|
|
3215
|
+
if (match2d) {
|
|
3216
|
+
const values = match2d.slice(1, 7).map(Number);
|
|
3217
|
+
if (!values.every(Number.isFinite)) return null;
|
|
3218
|
+
return values;
|
|
3219
|
+
}
|
|
3220
|
+
const match3d = css.match(/^matrix3d\(([^)]+)\)$/);
|
|
3221
|
+
if (match3d) {
|
|
3222
|
+
const raw = match3d[1];
|
|
3223
|
+
if (!raw) return null;
|
|
3224
|
+
const parts = raw.split(",").map((s) => Number(s.trim()));
|
|
3225
|
+
if (parts.length !== 16 || !parts.every(Number.isFinite)) return null;
|
|
3226
|
+
warnIfZSignificant(parts);
|
|
3227
|
+
return [
|
|
3228
|
+
parts[0],
|
|
3229
|
+
parts[1],
|
|
3230
|
+
parts[4],
|
|
3231
|
+
parts[5],
|
|
3232
|
+
parts[12],
|
|
3233
|
+
parts[13]
|
|
3234
|
+
];
|
|
3235
|
+
}
|
|
3236
|
+
return null;
|
|
3014
3237
|
}
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
});
|
|
3238
|
+
var warnedZSignificant = false;
|
|
3239
|
+
var Z_EPSILON = 1e-6;
|
|
3240
|
+
function warnIfZSignificant(parts) {
|
|
3241
|
+
if (warnedZSignificant) return;
|
|
3242
|
+
const a3 = parts[8] ?? 0;
|
|
3243
|
+
const b3 = parts[9] ?? 0;
|
|
3244
|
+
const c1 = parts[2] ?? 0;
|
|
3245
|
+
const c2 = parts[6] ?? 0;
|
|
3246
|
+
const c3 = parts[10] ?? 1;
|
|
3247
|
+
const d1 = parts[3] ?? 0;
|
|
3248
|
+
const d2 = parts[7] ?? 0;
|
|
3249
|
+
const d3 = parts[11] ?? 0;
|
|
3250
|
+
const d4 = parts[15] ?? 1;
|
|
3251
|
+
if (Math.abs(a3) > Z_EPSILON || Math.abs(b3) > Z_EPSILON || Math.abs(c1) > Z_EPSILON || Math.abs(c2) > Z_EPSILON || Math.abs(c3 - 1) > Z_EPSILON || Math.abs(d1) > Z_EPSILON || Math.abs(d2) > Z_EPSILON || Math.abs(d3) > Z_EPSILON || Math.abs(d4 - 1) > Z_EPSILON) {
|
|
3252
|
+
warnedZSignificant = true;
|
|
3253
|
+
console.warn(
|
|
3254
|
+
`[alphaBlit] parseTransformMatrix received a matrix3d with non-trivial 3D components (a3=${a3}, b3=${b3}, c1=${c1}, c2=${c2}, c3=${c3}, d1=${d1}, d2=${d2}, d3=${d3}, d4=${d4}). The engine projects 3D transforms to 2D (m11, m12, m21, m22, m41, m42) and silently discards perspective and out-of-plane rotation. If your composition uses real 3D (rotateX/Y, perspective), the rendered output will not match the studio preview. Z translation (translateZ) is dropped by design and does not trigger this warning. This warning is emitted once per process.`
|
|
3255
|
+
);
|
|
3034
3256
|
}
|
|
3035
3257
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
3258
|
+
|
|
3259
|
+
// ../engine/src/services/motionBlur.ts
|
|
3260
|
+
var MAX_SAMPLES_PER_FRAME = 64;
|
|
3261
|
+
var DEFAULT_SAMPLES_PER_FRAME = 16;
|
|
3262
|
+
var DEFAULT_SHUTTER_ANGLE = 180;
|
|
3263
|
+
var DEFAULT_SHUTTER_PHASE = -90;
|
|
3264
|
+
var SUB_FRAME_DIVISIONS = 4096;
|
|
3265
|
+
function finiteOr(value, fallback) {
|
|
3266
|
+
return Number.isFinite(value) ? value : fallback;
|
|
3038
3267
|
}
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
const
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
});
|
|
3045
|
-
await page.evaluate(
|
|
3046
|
-
(styleId, clearCompositionRoot2) => {
|
|
3047
|
-
const selector = clearCompositionRoot2 ? "html,body,[data-composition-id]" : "html,body";
|
|
3048
|
-
let style = document.getElementById(styleId);
|
|
3049
|
-
if (!style) {
|
|
3050
|
-
style = document.createElement("style");
|
|
3051
|
-
style.id = styleId;
|
|
3052
|
-
document.head.appendChild(style);
|
|
3053
|
-
}
|
|
3054
|
-
style.textContent = `${selector}{background:transparent !important;background-color:transparent !important;background-image:none !important;}`;
|
|
3055
|
-
},
|
|
3056
|
-
TRANSPARENT_BG_STYLE_ID,
|
|
3057
|
-
clearCompositionRoot
|
|
3268
|
+
function resolveMotionBlurPlan(options) {
|
|
3269
|
+
if (!options) return null;
|
|
3270
|
+
const fixedSamplesPerFrame = options.samplesPerFrame === void 0 ? null : Math.min(
|
|
3271
|
+
MAX_SAMPLES_PER_FRAME,
|
|
3272
|
+
Math.max(1, Math.round(finiteOr(options.samplesPerFrame, DEFAULT_SAMPLES_PER_FRAME)))
|
|
3058
3273
|
);
|
|
3274
|
+
const shutterAngle = finiteOr(options.shutterAngle, DEFAULT_SHUTTER_ANGLE);
|
|
3275
|
+
const shutterPhase = finiteOr(options.shutterPhase, DEFAULT_SHUTTER_PHASE);
|
|
3276
|
+
const blend = options.blend === "linear" ? "linear" : "srgb";
|
|
3277
|
+
return {
|
|
3278
|
+
blend,
|
|
3279
|
+
subFrameDivisions: SUB_FRAME_DIVISIONS,
|
|
3280
|
+
windowStartFrames: shutterPhase / 360,
|
|
3281
|
+
shutterFrames: shutterAngle / 360,
|
|
3282
|
+
fixedSamplesPerFrame
|
|
3283
|
+
};
|
|
3059
3284
|
}
|
|
3060
|
-
|
|
3061
|
-
const
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
optimizeForSpeed: false,
|
|
3068
|
-
// must be false to preserve alpha
|
|
3069
|
-
clip: { x: 0, y: 0, width, height, scale: 1 }
|
|
3070
|
-
});
|
|
3071
|
-
return Buffer.from(result.data, "base64");
|
|
3285
|
+
function sampleTickOffsets(plan, samplesPerFrame) {
|
|
3286
|
+
const offsets = [];
|
|
3287
|
+
for (let k = 0; k < samplesPerFrame; k++) {
|
|
3288
|
+
const offsetFrames = plan.windowStartFrames + (k + 0.5) / samplesPerFrame * plan.shutterFrames;
|
|
3289
|
+
offsets.push(Math.round(offsetFrames * plan.subFrameDivisions));
|
|
3290
|
+
}
|
|
3291
|
+
return offsets;
|
|
3072
3292
|
}
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
await page.evaluate(
|
|
3079
|
-
// fallow-ignore-next-line complexity
|
|
3080
|
-
(args) => {
|
|
3081
|
-
const existing = document.getElementById(args.styleId);
|
|
3082
|
-
if (existing) existing.remove();
|
|
3083
|
-
const renderFrameId = (id) => `${args.renderFramePrefix}${id}${args.renderFrameSuffix}`;
|
|
3084
|
-
const restoreMaskedElements = () => {
|
|
3085
|
-
const masked = document.querySelectorAll(`[${args.hiddenAttr}="1"]`);
|
|
3086
|
-
for (const node of masked) {
|
|
3087
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
3088
|
-
const prevVisibility = node.getAttribute(args.prevVisibilityAttr);
|
|
3089
|
-
const prevPriority = node.getAttribute(args.prevPriorityAttr);
|
|
3090
|
-
if (prevVisibility === null) {
|
|
3091
|
-
node.style.removeProperty("visibility");
|
|
3092
|
-
} else {
|
|
3093
|
-
node.style.setProperty("visibility", prevVisibility, prevPriority ?? "");
|
|
3094
|
-
}
|
|
3095
|
-
node.removeAttribute(args.hiddenAttr);
|
|
3096
|
-
node.removeAttribute(args.prevVisibilityAttr);
|
|
3097
|
-
node.removeAttribute(args.prevPriorityAttr);
|
|
3098
|
-
}
|
|
3099
|
-
};
|
|
3100
|
-
restoreMaskedElements();
|
|
3101
|
-
const rememberAndHideElement = (el) => {
|
|
3102
|
-
if (el.getAttribute(args.hiddenAttr) !== "1") {
|
|
3103
|
-
const prevVisibility = el.style.getPropertyValue("visibility");
|
|
3104
|
-
const prevPriority = typeof el.style.getPropertyPriority === "function" ? el.style.getPropertyPriority("visibility") : "";
|
|
3105
|
-
if (prevVisibility) {
|
|
3106
|
-
el.setAttribute(args.prevVisibilityAttr, prevVisibility);
|
|
3107
|
-
} else {
|
|
3108
|
-
el.removeAttribute(args.prevVisibilityAttr);
|
|
3109
|
-
}
|
|
3110
|
-
if (prevPriority) {
|
|
3111
|
-
el.setAttribute(args.prevPriorityAttr, prevPriority);
|
|
3112
|
-
} else {
|
|
3113
|
-
el.removeAttribute(args.prevPriorityAttr);
|
|
3114
|
-
}
|
|
3115
|
-
el.setAttribute(args.hiddenAttr, "1");
|
|
3116
|
-
}
|
|
3117
|
-
el.style.setProperty("visibility", "hidden", "important");
|
|
3118
|
-
};
|
|
3119
|
-
const hiddenTimedDescendants = [];
|
|
3120
|
-
const rememberHiddenTimedDescendants = (root) => {
|
|
3121
|
-
for (const node of root.querySelectorAll("[data-start]")) {
|
|
3122
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
3123
|
-
const computed = window.getComputedStyle(node);
|
|
3124
|
-
if (computed.visibility !== "hidden" && computed.display !== "none") continue;
|
|
3125
|
-
hiddenTimedDescendants.push(node);
|
|
3126
|
-
}
|
|
3127
|
-
};
|
|
3128
|
-
const showSelectors = [];
|
|
3129
|
-
for (const id of args.show) {
|
|
3130
|
-
const el = window.__hfMediaEl?.(id) ?? document.getElementById(id);
|
|
3131
|
-
if (el) rememberHiddenTimedDescendants(el);
|
|
3132
|
-
if (el?.hasAttribute(args.renderIdAttr)) {
|
|
3133
|
-
const attrEscaped = id.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
3134
|
-
const byRenderId = `[${args.renderIdAttr}="${attrEscaped}"]`;
|
|
3135
|
-
showSelectors.push(byRenderId, `${byRenderId} *`);
|
|
3136
|
-
} else {
|
|
3137
|
-
const escaped = CSS.escape(id);
|
|
3138
|
-
showSelectors.push(`#${escaped}`, `#${escaped} *`);
|
|
3139
|
-
}
|
|
3140
|
-
const renderEscaped = CSS.escape(renderFrameId(id));
|
|
3141
|
-
showSelectors.push(`#${renderEscaped}`, `#${renderEscaped} *`);
|
|
3142
|
-
const colorGradingEscaped = CSS.escape(`${args.canvasIdPrefix}${id}`);
|
|
3143
|
-
showSelectors.push(`#${colorGradingEscaped}`, `#${colorGradingEscaped} *`);
|
|
3144
|
-
}
|
|
3145
|
-
const massHideRule = "body *{visibility:hidden !important;}";
|
|
3146
|
-
const showRule = showSelectors.length === 0 ? "" : `${showSelectors.join(",")}{visibility:visible !important;}`;
|
|
3147
|
-
const style = document.createElement("style");
|
|
3148
|
-
style.id = args.styleId;
|
|
3149
|
-
style.textContent = `${massHideRule}
|
|
3150
|
-
${showRule}`;
|
|
3151
|
-
document.head.appendChild(style);
|
|
3152
|
-
for (const el of hiddenTimedDescendants) {
|
|
3153
|
-
rememberAndHideElement(el);
|
|
3154
|
-
}
|
|
3155
|
-
for (const id of args.hide) {
|
|
3156
|
-
const el = window.__hfMediaEl?.(id) ?? document.getElementById(id);
|
|
3157
|
-
if (el instanceof HTMLElement) {
|
|
3158
|
-
rememberAndHideElement(el);
|
|
3159
|
-
}
|
|
3160
|
-
const img = document.getElementById(renderFrameId(id));
|
|
3161
|
-
if (img) {
|
|
3162
|
-
rememberAndHideElement(img);
|
|
3163
|
-
}
|
|
3164
|
-
const colorGradingCanvas = document.getElementById(`${args.canvasIdPrefix}${id}`);
|
|
3165
|
-
if (colorGradingCanvas instanceof HTMLElement) {
|
|
3166
|
-
rememberAndHideElement(colorGradingCanvas);
|
|
3167
|
-
}
|
|
3168
|
-
}
|
|
3169
|
-
},
|
|
3170
|
-
{
|
|
3171
|
-
show: showIds,
|
|
3172
|
-
hide: extraHideIds,
|
|
3173
|
-
renderIdAttr: MEDIA_RENDER_ID_ATTR,
|
|
3174
|
-
renderFramePrefix: RENDER_FRAME_ID_PREFIX,
|
|
3175
|
-
renderFrameSuffix: RENDER_FRAME_ID_SUFFIX,
|
|
3176
|
-
styleId: DOM_LAYER_MASK_STYLE_ID,
|
|
3177
|
-
hiddenAttr: DOM_LAYER_MASK_HIDDEN_ATTR,
|
|
3178
|
-
prevVisibilityAttr: DOM_LAYER_MASK_PREV_VISIBILITY_ATTR,
|
|
3179
|
-
prevPriorityAttr: DOM_LAYER_MASK_PREV_PRIORITY_ATTR,
|
|
3180
|
-
canvasIdPrefix: HF_COLOR_GRADING_CANVAS_ID_PREFIX
|
|
3181
|
-
}
|
|
3293
|
+
function motionBlurSampleTimes(plan, frameIndex, fps, samplesPerFrame) {
|
|
3294
|
+
const grid = fps * plan.subFrameDivisions;
|
|
3295
|
+
const frameTicks = frameIndex * plan.subFrameDivisions;
|
|
3296
|
+
return sampleTickOffsets(plan, samplesPerFrame).map(
|
|
3297
|
+
(offset) => Math.max(0, frameTicks + offset) / grid
|
|
3182
3298
|
);
|
|
3183
3299
|
}
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
for (const node of masked) {
|
|
3191
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
3192
|
-
const prevVisibility = node.getAttribute(args.prevVisibilityAttr);
|
|
3193
|
-
const prevPriority = node.getAttribute(args.prevPriorityAttr);
|
|
3194
|
-
if (prevVisibility === null) {
|
|
3195
|
-
node.style.removeProperty("visibility");
|
|
3196
|
-
} else {
|
|
3197
|
-
node.style.setProperty("visibility", prevVisibility, prevPriority ?? "");
|
|
3198
|
-
}
|
|
3199
|
-
node.removeAttribute(args.hiddenAttr);
|
|
3200
|
-
node.removeAttribute(args.prevVisibilityAttr);
|
|
3201
|
-
node.removeAttribute(args.prevPriorityAttr);
|
|
3202
|
-
}
|
|
3203
|
-
},
|
|
3204
|
-
{
|
|
3205
|
-
styleId: DOM_LAYER_MASK_STYLE_ID,
|
|
3206
|
-
hiddenAttr: DOM_LAYER_MASK_HIDDEN_ATTR,
|
|
3207
|
-
prevVisibilityAttr: DOM_LAYER_MASK_PREV_VISIBILITY_ATTR,
|
|
3208
|
-
prevPriorityAttr: DOM_LAYER_MASK_PREV_PRIORITY_ATTR
|
|
3209
|
-
}
|
|
3300
|
+
function motionBlurProbeTimes(plan, frameIndex, fps) {
|
|
3301
|
+
const grid = fps * plan.subFrameDivisions;
|
|
3302
|
+
const frameTicks = frameIndex * plan.subFrameDivisions;
|
|
3303
|
+
const startTick = Math.round(plan.windowStartFrames * plan.subFrameDivisions);
|
|
3304
|
+
const endTick = Math.round(
|
|
3305
|
+
(plan.windowStartFrames + plan.shutterFrames) * plan.subFrameDivisions
|
|
3210
3306
|
);
|
|
3307
|
+
return {
|
|
3308
|
+
windowStart: Math.max(0, frameTicks + startTick) / grid,
|
|
3309
|
+
windowEnd: Math.max(0, frameTicks + endTick) / grid
|
|
3310
|
+
};
|
|
3211
3311
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3312
|
+
function motionBlurWindowIsStatic(plan, frameIndex, staticFrames) {
|
|
3313
|
+
const worstCaseSamples = plan.fixedSamplesPerFrame ?? MAX_SAMPLES_PER_FRAME;
|
|
3314
|
+
const inset = plan.shutterFrames / (2 * worstCaseSamples);
|
|
3315
|
+
const minOffsetFrames = plan.windowStartFrames + inset;
|
|
3316
|
+
const maxOffsetFrames = plan.windowStartFrames + plan.shutterFrames - inset;
|
|
3317
|
+
const first = Math.floor(frameIndex - 1 + Math.min(0, minOffsetFrames));
|
|
3318
|
+
const last = Math.floor(frameIndex + Math.max(0, maxOffsetFrames)) + 1;
|
|
3319
|
+
for (let frame = first; frame <= last; frame++) {
|
|
3320
|
+
if (!staticFrames.has(frame)) return false;
|
|
3321
|
+
}
|
|
3322
|
+
return true;
|
|
3323
|
+
}
|
|
3324
|
+
var ADAPTIVE_SAMPLE_STEPS = [
|
|
3325
|
+
{ maxDiff: 3, samples: DEFAULT_SAMPLES_PER_FRAME },
|
|
3326
|
+
{ maxDiff: 6, samples: 32 },
|
|
3327
|
+
{ maxDiff: Infinity, samples: MAX_SAMPLES_PER_FRAME }
|
|
3328
|
+
];
|
|
3329
|
+
function adaptiveSampleCount(diff) {
|
|
3330
|
+
for (const step of ADAPTIVE_SAMPLE_STEPS) {
|
|
3331
|
+
if (diff <= step.maxDiff) return step.samples;
|
|
3332
|
+
}
|
|
3333
|
+
return MAX_SAMPLES_PER_FRAME;
|
|
3334
|
+
}
|
|
3335
|
+
var SPATIAL_TWEEN_PROPERTIES = [
|
|
3336
|
+
"x",
|
|
3337
|
+
"y",
|
|
3338
|
+
"z",
|
|
3339
|
+
"xPercent",
|
|
3340
|
+
"yPercent",
|
|
3341
|
+
"rotation",
|
|
3342
|
+
"rotate",
|
|
3343
|
+
"rotationX",
|
|
3344
|
+
"rotationY",
|
|
3345
|
+
"rotationZ",
|
|
3346
|
+
"scale",
|
|
3347
|
+
"scaleX",
|
|
3348
|
+
"scaleY",
|
|
3349
|
+
"scaleZ",
|
|
3350
|
+
"skewX",
|
|
3351
|
+
"skewY",
|
|
3352
|
+
"perspective",
|
|
3353
|
+
"transformPerspective",
|
|
3354
|
+
"top",
|
|
3355
|
+
"left",
|
|
3356
|
+
"right",
|
|
3357
|
+
"bottom",
|
|
3358
|
+
"width",
|
|
3359
|
+
"height",
|
|
3360
|
+
"translate",
|
|
3361
|
+
"translateX",
|
|
3362
|
+
"translateY",
|
|
3363
|
+
"translateZ",
|
|
3364
|
+
"transform"
|
|
3365
|
+
];
|
|
3366
|
+
function probeDiffMagnitude(a, b) {
|
|
3367
|
+
const decodedA = decodePng(a);
|
|
3368
|
+
const decodedB = decodePng(b);
|
|
3369
|
+
if (decodedA.width !== decodedB.width || decodedA.height !== decodedB.height) {
|
|
3370
|
+
throw new Error(
|
|
3371
|
+
`probeDiffMagnitude: sample geometry mismatch (${decodedA.width}x${decodedA.height} vs ${decodedB.width}x${decodedB.height})`
|
|
3372
|
+
);
|
|
3373
|
+
}
|
|
3374
|
+
let sum = 0;
|
|
3375
|
+
for (let i = 0; i < decodedA.data.length; i++) {
|
|
3376
|
+
sum += Math.abs(decodedA.data[i] - decodedB.data[i]);
|
|
3377
|
+
}
|
|
3378
|
+
return sum / decodedA.data.length;
|
|
3232
3379
|
}
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
);
|
|
3380
|
+
var SRGB_TO_LINEAR = (() => {
|
|
3381
|
+
const lut = new Float64Array(256);
|
|
3382
|
+
for (let i = 0; i < 256; i++) lut[i] = srgbByteToLinear(i);
|
|
3383
|
+
return lut;
|
|
3384
|
+
})();
|
|
3385
|
+
var SRGB_PASSTHROUGH = (() => {
|
|
3386
|
+
const lut = new Float64Array(256);
|
|
3387
|
+
for (let i = 0; i < 256; i++) lut[i] = i;
|
|
3388
|
+
return lut;
|
|
3389
|
+
})();
|
|
3390
|
+
function linearToByte(value) {
|
|
3391
|
+
const c = value <= 31308e-7 ? value * 12.92 : 1.055 * Math.pow(value, 1 / 2.4) - 0.055;
|
|
3392
|
+
return clampByte(c * 255);
|
|
3240
3393
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
...updates,
|
|
3244
|
-
...restyleIds.map((videoId) => ({ videoId }))
|
|
3245
|
-
].map((item) => ({ ...item, frameId: renderFrameIdForRenderId(item.videoId) }));
|
|
3246
|
-
return await page.evaluate(
|
|
3247
|
-
// fallow-ignore-next-line complexity
|
|
3248
|
-
async (items2, visualProperties, colorGradingSourceHiddenAttr) => {
|
|
3249
|
-
const injectedIds = [];
|
|
3250
|
-
const pendingDecodes = [];
|
|
3251
|
-
const imagesToPublish = [];
|
|
3252
|
-
const replacementLayoutProperties = /* @__PURE__ */ new Set([
|
|
3253
|
-
"width",
|
|
3254
|
-
"height",
|
|
3255
|
-
"top",
|
|
3256
|
-
"left",
|
|
3257
|
-
"right",
|
|
3258
|
-
"bottom",
|
|
3259
|
-
"inset"
|
|
3260
|
-
]);
|
|
3261
|
-
const isVisualAncestorHidden = (el) => {
|
|
3262
|
-
let parent = el.parentElement;
|
|
3263
|
-
while (parent !== null && parent !== document.documentElement) {
|
|
3264
|
-
const computed = window.getComputedStyle(parent);
|
|
3265
|
-
if (computed.display === "none") return true;
|
|
3266
|
-
if (computed.visibility === "hidden" && (parent.hasAttribute("data-composition-src") || parent.hasAttribute("data-composition-file"))) {
|
|
3267
|
-
return true;
|
|
3268
|
-
}
|
|
3269
|
-
parent = parent.parentElement;
|
|
3270
|
-
}
|
|
3271
|
-
return false;
|
|
3272
|
-
};
|
|
3273
|
-
for (const item of items2) {
|
|
3274
|
-
const video = window.__hfMediaEl?.(item.videoId) ?? document.getElementById(item.videoId);
|
|
3275
|
-
if (!video) continue;
|
|
3276
|
-
let img = video.nextElementSibling;
|
|
3277
|
-
const hasImg = img !== null && img.classList.contains("__render_frame__");
|
|
3278
|
-
const restyleOnly = item.dataUri === void 0;
|
|
3279
|
-
if (restyleOnly && !hasImg) continue;
|
|
3280
|
-
if (isVisualAncestorHidden(video)) {
|
|
3281
|
-
if (hasImg && img) img.style.setProperty("visibility", "hidden", "important");
|
|
3282
|
-
continue;
|
|
3283
|
-
}
|
|
3284
|
-
const isNewImage = !hasImg;
|
|
3285
|
-
const computedStyle = window.getComputedStyle(video);
|
|
3286
|
-
const opacityParsed = parseFloat(computedStyle.opacity);
|
|
3287
|
-
const computedOpacity = video.hasAttribute(colorGradingSourceHiddenAttr) ? 1 : Number.isNaN(opacityParsed) ? 1 : opacityParsed;
|
|
3288
|
-
const videoRect = video.getBoundingClientRect();
|
|
3289
|
-
const videoBox = {
|
|
3290
|
-
left: Number.isFinite(video.offsetLeft) ? video.offsetLeft : 0,
|
|
3291
|
-
top: Number.isFinite(video.offsetTop) ? video.offsetTop : 0,
|
|
3292
|
-
width: video.offsetWidth > 0 ? video.offsetWidth : videoRect.width,
|
|
3293
|
-
height: video.offsetHeight > 0 ? video.offsetHeight : videoRect.height
|
|
3294
|
-
};
|
|
3295
|
-
if (isNewImage) {
|
|
3296
|
-
img = document.createElement("img");
|
|
3297
|
-
img.classList.add("__render_frame__");
|
|
3298
|
-
img.id = item.frameId;
|
|
3299
|
-
img.style.pointerEvents = "none";
|
|
3300
|
-
video.parentNode?.insertBefore(img, video.nextSibling);
|
|
3301
|
-
}
|
|
3302
|
-
if (!img) continue;
|
|
3303
|
-
for (const property of visualProperties) {
|
|
3304
|
-
if (property === "opacity") continue;
|
|
3305
|
-
if (replacementLayoutProperties.has(property)) {
|
|
3306
|
-
continue;
|
|
3307
|
-
}
|
|
3308
|
-
const value = computedStyle.getPropertyValue(property);
|
|
3309
|
-
if (value) {
|
|
3310
|
-
img.style.setProperty(property, value);
|
|
3311
|
-
}
|
|
3312
|
-
}
|
|
3313
|
-
img.style.position = "absolute";
|
|
3314
|
-
img.style.inset = "auto";
|
|
3315
|
-
img.style.left = `${videoBox.left}px`;
|
|
3316
|
-
img.style.top = `${videoBox.top}px`;
|
|
3317
|
-
img.style.right = "auto";
|
|
3318
|
-
img.style.bottom = "auto";
|
|
3319
|
-
img.style.width = `${videoBox.width}px`;
|
|
3320
|
-
img.style.height = `${videoBox.height}px`;
|
|
3321
|
-
img.style.boxSizing = "border-box";
|
|
3322
|
-
img.style.objectFit = computedStyle.objectFit;
|
|
3323
|
-
img.style.objectPosition = computedStyle.objectPosition;
|
|
3324
|
-
img.style.zIndex = computedStyle.zIndex;
|
|
3325
|
-
img.style.setProperty("visibility", "hidden", "important");
|
|
3326
|
-
img.decoding = "sync";
|
|
3327
|
-
if (item.dataUri !== void 0 && img.getAttribute("src") !== item.dataUri) {
|
|
3328
|
-
if (item.crossOrigin) img.crossOrigin = item.crossOrigin;
|
|
3329
|
-
else img.removeAttribute("crossorigin");
|
|
3330
|
-
img.src = item.dataUri;
|
|
3331
|
-
const source = item.sourceLabel ?? (item.dataUri.startsWith("data:") ? "inline frame" : item.dataUri);
|
|
3332
|
-
pendingDecodes.push(
|
|
3333
|
-
img.decode().catch((error) => {
|
|
3334
|
-
throw new Error(
|
|
3335
|
-
`Video frame for "${item.videoId}" failed to load (${source}): ${error instanceof Error ? error.message : String(error)}`
|
|
3336
|
-
);
|
|
3337
|
-
})
|
|
3338
|
-
);
|
|
3339
|
-
}
|
|
3340
|
-
img.style.opacity = String(computedOpacity);
|
|
3341
|
-
imagesToPublish.push(img);
|
|
3342
|
-
video.style.setProperty("visibility", "hidden", "important");
|
|
3343
|
-
video.style.setProperty("pointer-events", "none", "important");
|
|
3344
|
-
if (!restyleOnly) injectedIds.push(item.videoId);
|
|
3345
|
-
}
|
|
3346
|
-
if (pendingDecodes.length > 0) {
|
|
3347
|
-
await Promise.all(pendingDecodes);
|
|
3348
|
-
}
|
|
3349
|
-
for (const img of imagesToPublish) img.style.visibility = "visible";
|
|
3350
|
-
if (imagesToPublish.length > 0) {
|
|
3351
|
-
const redraw = window.__hf?.colorGrading?.redraw;
|
|
3352
|
-
redraw?.();
|
|
3353
|
-
}
|
|
3354
|
-
return injectedIds;
|
|
3355
|
-
},
|
|
3356
|
-
items,
|
|
3357
|
-
[...MEDIA_VISUAL_STYLE_PROPERTIES],
|
|
3358
|
-
COLOR_GRADING_SOURCE_HIDDEN_ATTR
|
|
3359
|
-
);
|
|
3394
|
+
function clampByte(value) {
|
|
3395
|
+
return Math.min(255, Math.max(0, Math.round(value)));
|
|
3360
3396
|
}
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3397
|
+
var MotionBlurAccumulator = class {
|
|
3398
|
+
toWorking;
|
|
3399
|
+
fromWorking;
|
|
3400
|
+
/** Premultiplied r, g, b and alpha sums per pixel. Null until the first sample sets the size. */
|
|
3401
|
+
sums = null;
|
|
3402
|
+
width = 0;
|
|
3403
|
+
height = 0;
|
|
3404
|
+
count = 0;
|
|
3405
|
+
constructor(blend) {
|
|
3406
|
+
this.toWorking = blend === "linear" ? SRGB_TO_LINEAR : SRGB_PASSTHROUGH;
|
|
3407
|
+
this.fromWorking = blend === "linear" ? linearToByte : clampByte;
|
|
3408
|
+
}
|
|
3409
|
+
/** Fold one captured sample PNG into the running average. */
|
|
3410
|
+
add(png) {
|
|
3411
|
+
const { width, height, data } = decodePng(png);
|
|
3412
|
+
if (!this.sums) {
|
|
3413
|
+
this.width = width;
|
|
3414
|
+
this.height = height;
|
|
3415
|
+
this.sums = new Float32Array(width * height * 4);
|
|
3416
|
+
} else if (width !== this.width || height !== this.height) {
|
|
3417
|
+
throw new Error(
|
|
3418
|
+
`MotionBlurAccumulator: sample geometry mismatch (${width}x${height} vs ${this.width}x${this.height})`
|
|
3381
3419
|
);
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3420
|
+
}
|
|
3421
|
+
const sums = this.sums;
|
|
3422
|
+
const toWorking = this.toWorking;
|
|
3423
|
+
for (let i = 0; i < sums.length; i += 4) {
|
|
3424
|
+
const alpha = data[i + 3] / 255;
|
|
3425
|
+
sums[i] = sums[i] + toWorking[data[i]] * alpha;
|
|
3426
|
+
sums[i + 1] = sums[i + 1] + toWorking[data[i + 1]] * alpha;
|
|
3427
|
+
sums[i + 2] = sums[i + 2] + toWorking[data[i + 2]] * alpha;
|
|
3428
|
+
sums[i + 3] = sums[i + 3] + alpha;
|
|
3429
|
+
}
|
|
3430
|
+
this.count += 1;
|
|
3431
|
+
}
|
|
3432
|
+
/** Un-premultiply and encode the average. Throws if no sample was ever added. */
|
|
3433
|
+
finish() {
|
|
3434
|
+
const sums = this.sums;
|
|
3435
|
+
if (!sums) throw new Error("MotionBlurAccumulator: no samples");
|
|
3436
|
+
const out = new Uint8Array(sums.length);
|
|
3437
|
+
for (let i = 0; i < sums.length; i += 4) {
|
|
3438
|
+
const alphaSum = sums[i + 3];
|
|
3439
|
+
out[i + 3] = clampByte(alphaSum / this.count * 255);
|
|
3440
|
+
if (alphaSum === 0) continue;
|
|
3441
|
+
const scale = 1 / alphaSum;
|
|
3442
|
+
out[i] = this.fromWorking(sums[i] * scale);
|
|
3443
|
+
out[i + 1] = this.fromWorking(sums[i + 1] * scale);
|
|
3444
|
+
out[i + 2] = this.fromWorking(sums[i + 2] * scale);
|
|
3445
|
+
}
|
|
3446
|
+
return { width: this.width, height: this.height, data: out };
|
|
3447
|
+
}
|
|
3448
|
+
};
|
|
3449
|
+
|
|
3450
|
+
// ../engine/src/services/pageMotionBlur.ts
|
|
3451
|
+
function pageOffReason(options) {
|
|
3452
|
+
if (options.motionBlur) return "engine-motion-blur";
|
|
3453
|
+
if (options.pageMotionBlur === "off") return "preview-unsupported";
|
|
3454
|
+
return options.pageMotionBlur ?? null;
|
|
3455
|
+
}
|
|
3456
|
+
async function installPageMotionBlur(page, options) {
|
|
3457
|
+
await page.evaluateOnNewDocument(acceleratedCanvasTrackerSource());
|
|
3458
|
+
const scale = options.deviceScaleFactor ?? 1;
|
|
3459
|
+
if (scale > 1) {
|
|
3460
|
+
await page.evaluateOnNewDocument(
|
|
3461
|
+
(key, v) => {
|
|
3462
|
+
window[key] = v;
|
|
3463
|
+
},
|
|
3464
|
+
PAGE_DEVICE_SCALE_GLOBAL,
|
|
3465
|
+
scale
|
|
3466
|
+
);
|
|
3467
|
+
}
|
|
3468
|
+
const off = pageOffReason(options);
|
|
3469
|
+
if (!off) return;
|
|
3470
|
+
await page.evaluateOnNewDocument(
|
|
3471
|
+
(key, v) => {
|
|
3472
|
+
window[key] = v;
|
|
3403
3473
|
},
|
|
3404
|
-
|
|
3405
|
-
|
|
3474
|
+
PAGE_MOTION_BLUR_OFF_GLOBAL,
|
|
3475
|
+
off
|
|
3406
3476
|
);
|
|
3407
3477
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3478
|
+
async function readPageMotionBlur(page) {
|
|
3479
|
+
return page.evaluate(() => {
|
|
3480
|
+
const api = Reflect.get(window, "__hfMotionBlur");
|
|
3481
|
+
const report = api && typeof api === "object" ? Reflect.get(api, "report") : null;
|
|
3482
|
+
const got = typeof report === "function" ? report() : null;
|
|
3483
|
+
if (!got || typeof got !== "object") return null;
|
|
3484
|
+
const tier = Reflect.get(got, "tier");
|
|
3485
|
+
return {
|
|
3486
|
+
state: String(Reflect.get(got, "state")),
|
|
3487
|
+
code: String(Reflect.get(got, "reasonCode")),
|
|
3488
|
+
movers: Number(Reflect.get(got, "movers")),
|
|
3489
|
+
failedFrames: Number(Reflect.get(got, "failedFrames")) || 0,
|
|
3490
|
+
tier: typeof tier === "string" ? tier : null
|
|
3491
|
+
};
|
|
3492
|
+
});
|
|
3415
3493
|
}
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
const orig = HTMLCanvasElement.prototype.getContext;
|
|
3421
|
-
HTMLCanvasElement.prototype.getContext = function(type, attrs) {
|
|
3422
|
-
const isGl = type === "webgl" || type === "webgl2" || type === "experimental-webgl";
|
|
3423
|
-
const isAccel = isGl || type === "webgpu";
|
|
3424
|
-
const finalAttrs = isGl ? { ...attrs, preserveDrawingBuffer: true } : attrs;
|
|
3425
|
-
const ctx = orig.call(this, type, finalAttrs);
|
|
3426
|
-
if (ctx && isAccel) {
|
|
3427
|
-
const list = w.__hf_accel_canvases ?? [];
|
|
3428
|
-
if (!list.includes(this)) list.push(this);
|
|
3429
|
-
w.__hf_accel_canvases = list;
|
|
3430
|
-
}
|
|
3431
|
-
if (ctx && type === "2d") {
|
|
3432
|
-
const list2d = w.__hf_canvas_2d ?? [];
|
|
3433
|
-
if (!list2d.includes(this)) list2d.push(this);
|
|
3434
|
-
w.__hf_canvas_2d = list2d;
|
|
3435
|
-
}
|
|
3436
|
-
return ctx;
|
|
3437
|
-
};
|
|
3494
|
+
var formatPageMotionBlur = (r) => `[motion-blur] ${r.state} reasonCode=${r.code} movers=${r.movers} failedFrames=${r.failedFrames}${r.tier ? ` tier=${r.tier}` : ""}`;
|
|
3495
|
+
async function describePageMotionBlur(page) {
|
|
3496
|
+
const r = await readPageMotionBlur(page);
|
|
3497
|
+
return r && formatPageMotionBlur(r);
|
|
3438
3498
|
}
|
|
3439
|
-
function
|
|
3440
|
-
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3499
|
+
async function describePageMotionBlurAtEnd(page, timeoutMs = 1500) {
|
|
3500
|
+
let timer;
|
|
3501
|
+
const stuck = new Promise((resolve2) => {
|
|
3502
|
+
timer = setTimeout(() => resolve2(null), timeoutMs);
|
|
3503
|
+
});
|
|
3504
|
+
try {
|
|
3505
|
+
const r = await Promise.race([readPageMotionBlur(page), stuck]);
|
|
3506
|
+
return r && r.failedFrames > 0 ? `${formatPageMotionBlur(r)} (session end)` : null;
|
|
3507
|
+
} catch {
|
|
3508
|
+
return null;
|
|
3509
|
+
} finally {
|
|
3510
|
+
clearTimeout(timer);
|
|
3511
|
+
}
|
|
3445
3512
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3513
|
+
|
|
3514
|
+
// ../engine/src/services/videoFrameTransport.ts
|
|
3515
|
+
import { randomUUID } from "crypto";
|
|
3516
|
+
var base64ImagePrefix = /^data:(image\/[\w.+-]+);base64,/;
|
|
3517
|
+
var transports = /* @__PURE__ */ new WeakMap();
|
|
3518
|
+
async function createTransport(page) {
|
|
3519
|
+
const pageUrl = new URL(page.url());
|
|
3520
|
+
const origin = /^https?:$/.test(pageUrl.protocol) ? pageUrl.origin : "https://hyperframes-render.invalid";
|
|
3521
|
+
const prefix = `${origin}/__hyperframes_video_frames__/${randomUUID()}/`;
|
|
3522
|
+
const responses = /* @__PURE__ */ new Map();
|
|
3523
|
+
const client = await page.createCDPSession();
|
|
3524
|
+
client.on("Fetch.requestPaused", (event) => {
|
|
3525
|
+
const frame = responses.get(event.request.url);
|
|
3526
|
+
void fulfillFrame(client, event.requestId, frame);
|
|
3455
3527
|
});
|
|
3528
|
+
try {
|
|
3529
|
+
await client.send("Fetch.enable", {
|
|
3530
|
+
patterns: [{ urlPattern: `${prefix}*`, requestStage: "Request" }]
|
|
3531
|
+
});
|
|
3532
|
+
} catch (error) {
|
|
3533
|
+
await client.detach().catch(() => {
|
|
3534
|
+
});
|
|
3535
|
+
throw error;
|
|
3536
|
+
}
|
|
3537
|
+
page.once("close", () => responses.clear());
|
|
3538
|
+
return { prefix, nextId: 0, responses };
|
|
3456
3539
|
}
|
|
3457
|
-
async function
|
|
3458
|
-
|
|
3459
|
-
(
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3540
|
+
async function fulfillFrame(client, requestId, frame) {
|
|
3541
|
+
try {
|
|
3542
|
+
await client.send("Fetch.fulfillRequest", {
|
|
3543
|
+
requestId,
|
|
3544
|
+
responseCode: frame ? 200 : 404,
|
|
3545
|
+
responseHeaders: [
|
|
3546
|
+
{ name: "Content-Type", value: frame?.contentType ?? "text/plain" },
|
|
3547
|
+
{ name: "Cache-Control", value: "no-store" },
|
|
3548
|
+
{ name: "Access-Control-Allow-Origin", value: "*" }
|
|
3549
|
+
],
|
|
3550
|
+
body: frame?.body ?? ""
|
|
3551
|
+
});
|
|
3552
|
+
} catch (error) {
|
|
3553
|
+
if (frame) frame.error = error;
|
|
3554
|
+
await client.send("Fetch.failRequest", { requestId, errorReason: "Failed" }).catch(() => {
|
|
3555
|
+
});
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
async function withVideoFrameSources(page, updates, inject) {
|
|
3559
|
+
if (!updates.some((update) => base64ImagePrefix.test(update.dataUri))) return inject(updates);
|
|
3560
|
+
let pending = transports.get(page);
|
|
3561
|
+
if (!pending) {
|
|
3562
|
+
pending = createTransport(page);
|
|
3563
|
+
transports.set(page, pending);
|
|
3564
|
+
}
|
|
3565
|
+
let transport;
|
|
3566
|
+
try {
|
|
3567
|
+
transport = await pending;
|
|
3568
|
+
} catch (error) {
|
|
3569
|
+
transports.delete(page);
|
|
3570
|
+
throw error;
|
|
3571
|
+
}
|
|
3572
|
+
const registered = [];
|
|
3573
|
+
try {
|
|
3574
|
+
const resolved = updates.map((update) => {
|
|
3575
|
+
const match = base64ImagePrefix.exec(update.dataUri);
|
|
3576
|
+
if (!match) return update;
|
|
3577
|
+
const frame = {
|
|
3578
|
+
contentType: match[1] ?? "image/png",
|
|
3579
|
+
body: update.dataUri.slice(match[0].length)
|
|
3491
3580
|
};
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3581
|
+
const url = `${transport.prefix}${transport.nextId++}`;
|
|
3582
|
+
transport.responses.set(url, frame);
|
|
3583
|
+
registered.push({ url, frame });
|
|
3584
|
+
return {
|
|
3585
|
+
...update,
|
|
3586
|
+
dataUri: url,
|
|
3587
|
+
crossOrigin: "anonymous",
|
|
3588
|
+
sourceLabel: "inline frame"
|
|
3589
|
+
};
|
|
3590
|
+
});
|
|
3591
|
+
return await inject(resolved);
|
|
3592
|
+
} catch (error) {
|
|
3593
|
+
throw registered.find(({ frame }) => frame.error !== void 0)?.frame.error ?? error;
|
|
3594
|
+
} finally {
|
|
3595
|
+
for (const { url } of registered) transport.responses.delete(url);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
// ../engine/src/services/screenshotService.ts
|
|
3600
|
+
var cdpSessionCache = /* @__PURE__ */ new WeakMap();
|
|
3601
|
+
async function getCdpSession(page) {
|
|
3602
|
+
let client = cdpSessionCache.get(page);
|
|
3603
|
+
if (!client) {
|
|
3604
|
+
client = await page.createCDPSession();
|
|
3605
|
+
cdpSessionCache.set(page, client);
|
|
3606
|
+
}
|
|
3607
|
+
return client;
|
|
3608
|
+
}
|
|
3609
|
+
function shouldDefaultCaptureBeyondViewport(browserVersion, platform = process.platform) {
|
|
3610
|
+
return platform === "darwin" && browserVersion.startsWith("Chrome/");
|
|
3611
|
+
}
|
|
3612
|
+
async function probeBeginFrameLiveness(page, timeoutMs, frameTimeTicks, intervalMs) {
|
|
3613
|
+
const client = await getCdpSession(page);
|
|
3614
|
+
const params = {};
|
|
3615
|
+
if (typeof frameTimeTicks === "number") params.frameTimeTicks = frameTimeTicks;
|
|
3616
|
+
if (typeof intervalMs === "number") params.interval = intervalMs;
|
|
3617
|
+
let timer;
|
|
3618
|
+
try {
|
|
3619
|
+
return await Promise.race([
|
|
3620
|
+
client.send("HeadlessExperimental.beginFrame", params).then(() => true).catch(() => false),
|
|
3621
|
+
new Promise((resolve2) => {
|
|
3622
|
+
timer = setTimeout(() => resolve2(false), timeoutMs);
|
|
3623
|
+
})
|
|
3624
|
+
]);
|
|
3625
|
+
} finally {
|
|
3626
|
+
if (timer) clearTimeout(timer);
|
|
3627
|
+
}
|
|
3495
3628
|
}
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
throw new Error("HF_DE_COMPOSITION_ROOT_MISSING: drawElement composition root not found");
|
|
3509
|
-
}
|
|
3510
|
-
if (!canvas) {
|
|
3511
|
-
throw new Error("HF_DE_CANVAS_NOT_INITIALIZED: drawElement canvas not initialized");
|
|
3629
|
+
var lastFrameCache = /* @__PURE__ */ new WeakMap();
|
|
3630
|
+
var PENDING_FRAME_RETRIES = 5;
|
|
3631
|
+
async function sendBeginFrame(client, params) {
|
|
3632
|
+
for (let attempt = 0; ; attempt++) {
|
|
3633
|
+
try {
|
|
3634
|
+
return await client.send("HeadlessExperimental.beginFrame", params);
|
|
3635
|
+
} catch (err) {
|
|
3636
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3637
|
+
const isPending = msg.includes("Another frame is pending");
|
|
3638
|
+
if (isPending && attempt < PENDING_FRAME_RETRIES) {
|
|
3639
|
+
await new Promise((r) => setTimeout(r, 50 * 2 ** attempt));
|
|
3640
|
+
continue;
|
|
3512
3641
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
let usedRequestPaint = false;
|
|
3517
|
-
aw.__hf3d?.update();
|
|
3518
|
-
const accel = (aw.__hf_accel_canvases ?? []).filter((c) => root.contains(c));
|
|
3519
|
-
if (!sync) {
|
|
3520
|
-
for (const c of (aw.__hf_canvas_2d ?? []).filter((c2) => root.contains(c2))) {
|
|
3521
|
-
if (!accel.includes(c)) accel.push(c);
|
|
3522
|
-
}
|
|
3523
|
-
accel.sort(
|
|
3524
|
-
(a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
|
|
3642
|
+
if (isPending) {
|
|
3643
|
+
throw new Error(
|
|
3644
|
+
`[BeginFrame] Frame still pending after ${PENDING_FRAME_RETRIES} retries: CPU overloaded by parallel renders. Reduce concurrent renders or use --docker for isolation.`
|
|
3525
3645
|
);
|
|
3526
3646
|
}
|
|
3527
|
-
|
|
3528
|
-
if (c.style.visibility !== "hidden") c.style.visibility = "hidden";
|
|
3529
|
-
}
|
|
3530
|
-
return new Promise((resolveCapture, rejectCapture) => {
|
|
3531
|
-
let settled = false;
|
|
3532
|
-
const drawAndEncode = () => {
|
|
3533
|
-
if (settled) return;
|
|
3534
|
-
settled = true;
|
|
3535
|
-
try {
|
|
3536
|
-
ctx.clearRect(0, 0, w, h);
|
|
3537
|
-
let bg = "";
|
|
3538
|
-
for (let el = root.parentElement; el; el = el.parentElement) {
|
|
3539
|
-
const c = getComputedStyle(el).backgroundColor;
|
|
3540
|
-
if (c && c !== "transparent" && c !== "rgba(0, 0, 0, 0)") {
|
|
3541
|
-
bg = c;
|
|
3542
|
-
break;
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
if (!bg && fmt === "jpeg") bg = "#fff";
|
|
3546
|
-
if (bg) {
|
|
3547
|
-
ctx.fillStyle = bg;
|
|
3548
|
-
ctx.fillRect(0, 0, w, h);
|
|
3549
|
-
}
|
|
3550
|
-
const rootRect = root.getBoundingClientRect();
|
|
3551
|
-
for (const c of accel) {
|
|
3552
|
-
if (c.hasAttribute("data-hf-3d")) continue;
|
|
3553
|
-
const r = c.getBoundingClientRect();
|
|
3554
|
-
try {
|
|
3555
|
-
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
3556
|
-
} catch {
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
3559
|
-
let __appliedTransform = false;
|
|
3560
|
-
let __appliedAlpha = false;
|
|
3561
|
-
if (aw.__HF_ROOT_PROPS__) {
|
|
3562
|
-
try {
|
|
3563
|
-
const rcs = getComputedStyle(root);
|
|
3564
|
-
if (!usedRequestPaint) {
|
|
3565
|
-
const baseOp = aw.__HF_ROOT_BASE_OPACITY__ ?? 1;
|
|
3566
|
-
const curOp = parseFloat(rcs.opacity);
|
|
3567
|
-
if (baseOp > 1e-3 && Number.isFinite(curOp)) {
|
|
3568
|
-
const ratio = curOp / baseOp;
|
|
3569
|
-
if (Math.abs(ratio - 1) > 2e-3) {
|
|
3570
|
-
ctx.globalAlpha = Math.max(0, Math.min(1, ratio));
|
|
3571
|
-
__appliedAlpha = true;
|
|
3572
|
-
}
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
const curTransform = rcs.transform;
|
|
3576
|
-
if (curTransform && curTransform !== "none") {
|
|
3577
|
-
const m = new DOMMatrix(curTransform);
|
|
3578
|
-
const origin = rcs.transformOrigin.split(" ");
|
|
3579
|
-
const ox = parseFloat(origin[0] ?? "0") || 0;
|
|
3580
|
-
const oy = parseFloat(origin[1] ?? "0") || 0;
|
|
3581
|
-
ctx.translate(ox, oy);
|
|
3582
|
-
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
3583
|
-
ctx.translate(-ox, -oy);
|
|
3584
|
-
__appliedTransform = true;
|
|
3585
|
-
}
|
|
3586
|
-
} catch {
|
|
3587
|
-
}
|
|
3588
|
-
}
|
|
3589
|
-
ctx.drawElementImage(root, 0, 0);
|
|
3590
|
-
if (__appliedAlpha) ctx.globalAlpha = 1;
|
|
3591
|
-
if (__appliedTransform) ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
3592
|
-
for (const c of accel) {
|
|
3593
|
-
if (!c.hasAttribute("data-hf-3d")) continue;
|
|
3594
|
-
const r = c.getBoundingClientRect();
|
|
3595
|
-
try {
|
|
3596
|
-
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
3597
|
-
} catch {
|
|
3598
|
-
}
|
|
3599
|
-
}
|
|
3600
|
-
} catch (e) {
|
|
3601
|
-
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
3602
|
-
return;
|
|
3603
|
-
}
|
|
3604
|
-
setTimeout(() => {
|
|
3605
|
-
try {
|
|
3606
|
-
resolveCapture(
|
|
3607
|
-
fmt === "png" ? canvas.toDataURL("image/png") : canvas.toDataURL("image/jpeg", q / 100)
|
|
3608
|
-
);
|
|
3609
|
-
} catch (e) {
|
|
3610
|
-
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
3611
|
-
}
|
|
3612
|
-
}, 0);
|
|
3613
|
-
};
|
|
3614
|
-
if (!sync) {
|
|
3615
|
-
drawAndEncode();
|
|
3616
|
-
return;
|
|
3617
|
-
}
|
|
3618
|
-
const onPaint = () => {
|
|
3619
|
-
canvas.removeEventListener("paint", onPaint);
|
|
3620
|
-
drawAndEncode();
|
|
3621
|
-
};
|
|
3622
|
-
canvas.addEventListener("paint", onPaint);
|
|
3623
|
-
usedRequestPaint = aw.__hfDeInvalidate?.() === true;
|
|
3624
|
-
setTimeout(() => {
|
|
3625
|
-
canvas.removeEventListener("paint", onPaint);
|
|
3626
|
-
drawAndEncode();
|
|
3627
|
-
}, 250);
|
|
3628
|
-
});
|
|
3629
|
-
},
|
|
3630
|
-
{ w: width, h: height, fmt: format, q: quality, sync: syncToPaintEvent }
|
|
3631
|
-
);
|
|
3632
|
-
const base64 = dataUrl.split(",")[1];
|
|
3633
|
-
if (!base64) throw new Error("drawElement: toDataURL returned no base64 payload");
|
|
3634
|
-
return Buffer.from(base64, "base64");
|
|
3635
|
-
}
|
|
3636
|
-
var workerEncodeStates = /* @__PURE__ */ new WeakMap();
|
|
3637
|
-
var workerEncodeBoundPages = /* @__PURE__ */ new WeakSet();
|
|
3638
|
-
async function initDrawElementWorkerEncode(page) {
|
|
3639
|
-
const existing = workerEncodeStates.get(page);
|
|
3640
|
-
if (existing) {
|
|
3641
|
-
for (const entry of existing.pending.values()) {
|
|
3642
|
-
entry.reject(new Error("drawElement worker encode: session reused, frame dropped"));
|
|
3647
|
+
throw err;
|
|
3643
3648
|
}
|
|
3644
|
-
existing.pending.clear();
|
|
3645
|
-
existing.nextId = 0;
|
|
3646
|
-
} else {
|
|
3647
|
-
const state = { nextId: 0, pending: /* @__PURE__ */ new Map() };
|
|
3648
|
-
workerEncodeStates.set(page, state);
|
|
3649
|
-
}
|
|
3650
|
-
if (!workerEncodeBoundPages.has(page)) {
|
|
3651
|
-
workerEncodeBoundPages.add(page);
|
|
3652
|
-
await page.exposeFunction("__hfFrameReady", (id, b64, error) => {
|
|
3653
|
-
const s = workerEncodeStates.get(page);
|
|
3654
|
-
if (!s) return;
|
|
3655
|
-
if (id < 0) {
|
|
3656
|
-
for (const entry2 of s.pending.values()) {
|
|
3657
|
-
entry2.reject(new Error(`drawElement worker encode failed: ${error ?? "worker error"}`));
|
|
3658
|
-
}
|
|
3659
|
-
s.pending.clear();
|
|
3660
|
-
return;
|
|
3661
|
-
}
|
|
3662
|
-
const entry = s.pending.get(id);
|
|
3663
|
-
if (!entry) return;
|
|
3664
|
-
s.pending.delete(id);
|
|
3665
|
-
if (error) {
|
|
3666
|
-
entry.reject(new Error(`drawElement worker encode failed: ${error}`));
|
|
3667
|
-
} else if (!b64) {
|
|
3668
|
-
entry.reject(new Error(`drawElement worker encode returned empty frame (frame ${id})`));
|
|
3669
|
-
} else {
|
|
3670
|
-
entry.resolve(Buffer.from(b64, "base64"));
|
|
3671
|
-
}
|
|
3672
|
-
});
|
|
3673
3649
|
}
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3650
|
+
}
|
|
3651
|
+
async function beginFrameCapture(page, options, frameTimeTicks, interval) {
|
|
3652
|
+
const client = await getCdpSession(page);
|
|
3653
|
+
const isPng = options.format === "png";
|
|
3654
|
+
const screenshot = {
|
|
3655
|
+
format: isPng ? "png" : "jpeg",
|
|
3656
|
+
quality: isPng ? void 0 : options.quality ?? 80,
|
|
3657
|
+
optimizeForSpeed: true
|
|
3658
|
+
};
|
|
3659
|
+
const result = await sendBeginFrame(client, { frameTimeTicks, interval, screenshot });
|
|
3660
|
+
let buffer;
|
|
3661
|
+
if (result.screenshotData) {
|
|
3662
|
+
buffer = Buffer.from(result.screenshotData, "base64");
|
|
3663
|
+
lastFrameCache.set(page, buffer);
|
|
3664
|
+
} else {
|
|
3665
|
+
const cached = lastFrameCache.get(page);
|
|
3666
|
+
if (cached) {
|
|
3667
|
+
buffer = cached;
|
|
3668
|
+
} else {
|
|
3669
|
+
const fallback = await sendBeginFrame(client, {
|
|
3670
|
+
frameTimeTicks: frameTimeTicks + 1e-3,
|
|
3671
|
+
interval,
|
|
3672
|
+
screenshot
|
|
3673
|
+
});
|
|
3674
|
+
buffer = fallback.screenshotData ? Buffer.from(fallback.screenshotData, "base64") : Buffer.alloc(0);
|
|
3675
|
+
if (buffer.length > 0) lastFrameCache.set(page, buffer);
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
return {
|
|
3679
|
+
buffer,
|
|
3680
|
+
hasDamage: result.hasDamage
|
|
3681
|
+
};
|
|
3682
|
+
}
|
|
3683
|
+
async function pageContentExceedsCaptureHeight(page, requestedHeight) {
|
|
3684
|
+
const scrollHeight = await page.evaluate(() => document.documentElement.scrollHeight);
|
|
3685
|
+
return scrollHeight > requestedHeight + 1;
|
|
3686
|
+
}
|
|
3687
|
+
async function pageScreenshotCapture(page, options) {
|
|
3688
|
+
const client = await getCdpSession(page);
|
|
3689
|
+
const isPng = options.format === "png";
|
|
3690
|
+
const dpr = options.deviceScaleFactor ?? 1;
|
|
3691
|
+
const clip = { x: 0, y: 0, width: options.width, height: options.height, scale: dpr };
|
|
3692
|
+
const result = await client.send("Page.captureScreenshot", {
|
|
3693
|
+
format: isPng ? "png" : "jpeg",
|
|
3694
|
+
quality: isPng ? void 0 : options.quality ?? 80,
|
|
3695
|
+
fromSurface: true,
|
|
3696
|
+
// Use Chrome's faster viewport-bound screenshot path by default. Callers
|
|
3697
|
+
// opt into the beyond-viewport path only for known compositor edge cases,
|
|
3698
|
+
// such as native video surfaces in tall portrait renders.
|
|
3699
|
+
captureBeyondViewport: options.captureBeyondViewport ?? false,
|
|
3700
|
+
optimizeForSpeed: !isPng,
|
|
3701
|
+
clip
|
|
3719
3702
|
});
|
|
3703
|
+
return Buffer.from(result.data, "base64");
|
|
3720
3704
|
}
|
|
3721
|
-
function
|
|
3722
|
-
const
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3705
|
+
async function captureScreenshotWithAlpha(page, width, height) {
|
|
3706
|
+
const client = await getCdpSession(page);
|
|
3707
|
+
await client.send("Emulation.setDefaultBackgroundColorOverride", {
|
|
3708
|
+
color: { r: 0, g: 0, b: 0, a: 0 }
|
|
3709
|
+
});
|
|
3710
|
+
try {
|
|
3711
|
+
const result = await client.send("Page.captureScreenshot", {
|
|
3712
|
+
format: "png",
|
|
3713
|
+
fromSurface: true,
|
|
3714
|
+
// Preserve the #1094 tall-portrait edge-clipping guard on HDR alpha captures.
|
|
3715
|
+
captureBeyondViewport: true,
|
|
3716
|
+
optimizeForSpeed: false,
|
|
3717
|
+
// `true` uses a zero-alpha-aware fast path that crushes real alpha values — observed empirically, CDP docs don't spell it out
|
|
3718
|
+
clip: { x: 0, y: 0, width, height, scale: 1 }
|
|
3719
|
+
});
|
|
3720
|
+
return Buffer.from(result.data, "base64");
|
|
3721
|
+
} finally {
|
|
3722
|
+
await client.send("Emulation.setDefaultBackgroundColorOverride", {}).catch(() => {
|
|
3723
|
+
});
|
|
3726
3724
|
}
|
|
3727
|
-
state.pending.clear();
|
|
3728
|
-
workerEncodeStates.delete(page);
|
|
3729
3725
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
const encodeResult = new Promise((resolve2, reject) => {
|
|
3739
|
-
const timer = setTimeout(() => {
|
|
3740
|
-
if (state.pending.delete(frameId)) {
|
|
3741
|
-
reject(new Error(`drawElement worker encode timed out (frame ${frameId})`));
|
|
3742
|
-
}
|
|
3743
|
-
}, 3e4);
|
|
3744
|
-
state.pending.set(frameId, {
|
|
3745
|
-
resolve: (b) => {
|
|
3746
|
-
clearTimeout(timer);
|
|
3747
|
-
resolve2(b);
|
|
3748
|
-
},
|
|
3749
|
-
reject: (e) => {
|
|
3750
|
-
clearTimeout(timer);
|
|
3751
|
-
reject(e);
|
|
3752
|
-
}
|
|
3753
|
-
});
|
|
3754
|
-
});
|
|
3755
|
-
void encodeResult.catch(() => {
|
|
3726
|
+
function capturesAlpha(options) {
|
|
3727
|
+
return options.transparent ?? options.format === "png";
|
|
3728
|
+
}
|
|
3729
|
+
var TRANSPARENT_BG_STYLE_ID = "__hf_transparent_bg__";
|
|
3730
|
+
async function initTransparentBackground(page, { clearCompositionRoot = false } = {}) {
|
|
3731
|
+
const client = await getCdpSession(page);
|
|
3732
|
+
await client.send("Emulation.setDefaultBackgroundColorOverride", {
|
|
3733
|
+
color: { r: 0, g: 0, b: 0, a: 0 }
|
|
3756
3734
|
});
|
|
3757
3735
|
await page.evaluate(
|
|
3758
|
-
(
|
|
3759
|
-
const
|
|
3760
|
-
|
|
3761
|
-
if (!
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
throw new Error("HF_DE_CANVAS_NOT_INITIALIZED: drawElement canvas not initialized");
|
|
3736
|
+
(styleId, clearCompositionRoot2) => {
|
|
3737
|
+
const selector = clearCompositionRoot2 ? "html,body,[data-composition-id]" : "html,body";
|
|
3738
|
+
let style = document.getElementById(styleId);
|
|
3739
|
+
if (!style) {
|
|
3740
|
+
style = document.createElement("style");
|
|
3741
|
+
style.id = styleId;
|
|
3742
|
+
document.head.appendChild(style);
|
|
3766
3743
|
}
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3744
|
+
style.textContent = `${selector}{background:transparent !important;background-color:transparent !important;background-image:none !important;}`;
|
|
3745
|
+
},
|
|
3746
|
+
TRANSPARENT_BG_STYLE_ID,
|
|
3747
|
+
clearCompositionRoot
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
async function captureAlphaPng(page, width, height) {
|
|
3751
|
+
const client = await getCdpSession(page);
|
|
3752
|
+
const result = await client.send("Page.captureScreenshot", {
|
|
3753
|
+
format: "png",
|
|
3754
|
+
fromSurface: true,
|
|
3755
|
+
// Preserve the #1094 tall-portrait edge-clipping guard on HDR alpha captures.
|
|
3756
|
+
captureBeyondViewport: true,
|
|
3757
|
+
optimizeForSpeed: false,
|
|
3758
|
+
// must be false to preserve alpha
|
|
3759
|
+
clip: { x: 0, y: 0, width, height, scale: 1 }
|
|
3760
|
+
});
|
|
3761
|
+
return Buffer.from(result.data, "base64");
|
|
3762
|
+
}
|
|
3763
|
+
var DOM_LAYER_MASK_STYLE_ID = "__hf_dom_layer_mask__";
|
|
3764
|
+
var DOM_LAYER_MASK_HIDDEN_ATTR = "data-hf-dom-layer-mask-hidden";
|
|
3765
|
+
var DOM_LAYER_MASK_PREV_VISIBILITY_ATTR = "data-hf-dom-layer-mask-prev-visibility";
|
|
3766
|
+
var DOM_LAYER_MASK_PREV_PRIORITY_ATTR = "data-hf-dom-layer-mask-prev-priority";
|
|
3767
|
+
async function applyDomLayerMask(page, showIds, extraHideIds) {
|
|
3768
|
+
await page.evaluate(
|
|
3769
|
+
// fallow-ignore-next-line complexity
|
|
3770
|
+
(args) => {
|
|
3771
|
+
const existing = document.getElementById(args.styleId);
|
|
3772
|
+
if (existing) existing.remove();
|
|
3773
|
+
const renderFrameId = (id) => `${args.renderFramePrefix}${id}${args.renderFrameSuffix}`;
|
|
3774
|
+
const restoreMaskedElements = () => {
|
|
3775
|
+
const masked = document.querySelectorAll(`[${args.hiddenAttr}="1"]`);
|
|
3776
|
+
for (const node of masked) {
|
|
3777
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
3778
|
+
const prevVisibility = node.getAttribute(args.prevVisibilityAttr);
|
|
3779
|
+
const prevPriority = node.getAttribute(args.prevPriorityAttr);
|
|
3780
|
+
if (prevVisibility === null) {
|
|
3781
|
+
node.style.removeProperty("visibility");
|
|
3782
|
+
} else {
|
|
3783
|
+
node.style.setProperty("visibility", prevVisibility, prevPriority ?? "");
|
|
3784
|
+
}
|
|
3785
|
+
node.removeAttribute(args.hiddenAttr);
|
|
3786
|
+
node.removeAttribute(args.prevVisibilityAttr);
|
|
3787
|
+
node.removeAttribute(args.prevPriorityAttr);
|
|
3775
3788
|
}
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
const drawAndKick = () => {
|
|
3787
|
-
if (settled) return;
|
|
3788
|
-
settled = true;
|
|
3789
|
-
try {
|
|
3790
|
-
ctx.clearRect(0, 0, w, h);
|
|
3791
|
-
let bg = "";
|
|
3792
|
-
for (let el = root.parentElement; el; el = el.parentElement) {
|
|
3793
|
-
const c = getComputedStyle(el).backgroundColor;
|
|
3794
|
-
if (c && c !== "transparent" && c !== "rgba(0, 0, 0, 0)") {
|
|
3795
|
-
bg = c;
|
|
3796
|
-
break;
|
|
3797
|
-
}
|
|
3798
|
-
}
|
|
3799
|
-
if (!bg) bg = "#fff";
|
|
3800
|
-
if (bg) {
|
|
3801
|
-
ctx.fillStyle = bg;
|
|
3802
|
-
ctx.fillRect(0, 0, w, h);
|
|
3803
|
-
}
|
|
3804
|
-
const rootRect = root.getBoundingClientRect();
|
|
3805
|
-
for (const c of accel) {
|
|
3806
|
-
if (c.hasAttribute("data-hf-3d")) continue;
|
|
3807
|
-
const r = c.getBoundingClientRect();
|
|
3808
|
-
try {
|
|
3809
|
-
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
3810
|
-
} catch {
|
|
3811
|
-
}
|
|
3812
|
-
}
|
|
3813
|
-
let __appliedTransform = false;
|
|
3814
|
-
let __appliedAlpha = false;
|
|
3815
|
-
if (aw.__HF_ROOT_PROPS__) {
|
|
3816
|
-
try {
|
|
3817
|
-
const rcs = getComputedStyle(root);
|
|
3818
|
-
if (!usedRequestPaint) {
|
|
3819
|
-
const baseOp = aw.__HF_ROOT_BASE_OPACITY__ ?? 1;
|
|
3820
|
-
const curOp = parseFloat(rcs.opacity);
|
|
3821
|
-
if (baseOp > 1e-3 && Number.isFinite(curOp)) {
|
|
3822
|
-
const ratio = curOp / baseOp;
|
|
3823
|
-
if (Math.abs(ratio - 1) > 2e-3) {
|
|
3824
|
-
ctx.globalAlpha = Math.max(0, Math.min(1, ratio));
|
|
3825
|
-
__appliedAlpha = true;
|
|
3826
|
-
}
|
|
3827
|
-
}
|
|
3828
|
-
}
|
|
3829
|
-
const curTransform = rcs.transform;
|
|
3830
|
-
if (curTransform && curTransform !== "none") {
|
|
3831
|
-
const m = new DOMMatrix(curTransform);
|
|
3832
|
-
const origin = rcs.transformOrigin.split(" ");
|
|
3833
|
-
const ox = parseFloat(origin[0] ?? "0") || 0;
|
|
3834
|
-
const oy = parseFloat(origin[1] ?? "0") || 0;
|
|
3835
|
-
ctx.translate(ox, oy);
|
|
3836
|
-
ctx.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
3837
|
-
ctx.translate(-ox, -oy);
|
|
3838
|
-
__appliedTransform = true;
|
|
3839
|
-
}
|
|
3840
|
-
} catch {
|
|
3841
|
-
}
|
|
3842
|
-
}
|
|
3843
|
-
ctx.drawElementImage(root, 0, 0);
|
|
3844
|
-
if (__appliedAlpha) ctx.globalAlpha = 1;
|
|
3845
|
-
if (__appliedTransform) ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
3846
|
-
for (const c of accel) {
|
|
3847
|
-
if (!c.hasAttribute("data-hf-3d")) continue;
|
|
3848
|
-
const r = c.getBoundingClientRect();
|
|
3849
|
-
try {
|
|
3850
|
-
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
3851
|
-
} catch {
|
|
3852
|
-
}
|
|
3853
|
-
}
|
|
3854
|
-
} catch (e) {
|
|
3855
|
-
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
3856
|
-
return;
|
|
3789
|
+
};
|
|
3790
|
+
restoreMaskedElements();
|
|
3791
|
+
const rememberAndHideElement = (el) => {
|
|
3792
|
+
if (el.getAttribute(args.hiddenAttr) !== "1") {
|
|
3793
|
+
const prevVisibility = el.style.getPropertyValue("visibility");
|
|
3794
|
+
const prevPriority = typeof el.style.getPropertyPriority === "function" ? el.style.getPropertyPriority("visibility") : "";
|
|
3795
|
+
if (prevVisibility) {
|
|
3796
|
+
el.setAttribute(args.prevVisibilityAttr, prevVisibility);
|
|
3797
|
+
} else {
|
|
3798
|
+
el.removeAttribute(args.prevVisibilityAttr);
|
|
3857
3799
|
}
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
}
|
|
3865
|
-
ew.__hfEncWorker.postMessage({ bmp, id: fid, w, h, q: q / 100 }, [bmp]);
|
|
3866
|
-
resolveCapture();
|
|
3867
|
-
}).catch((e) => {
|
|
3868
|
-
rejectCapture(e instanceof Error ? e : new Error(String(e)));
|
|
3869
|
-
});
|
|
3870
|
-
};
|
|
3871
|
-
if (!sync) {
|
|
3872
|
-
drawAndKick();
|
|
3873
|
-
return;
|
|
3800
|
+
if (prevPriority) {
|
|
3801
|
+
el.setAttribute(args.prevPriorityAttr, prevPriority);
|
|
3802
|
+
} else {
|
|
3803
|
+
el.removeAttribute(args.prevPriorityAttr);
|
|
3804
|
+
}
|
|
3805
|
+
el.setAttribute(args.hiddenAttr, "1");
|
|
3874
3806
|
}
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
}
|
|
3885
|
-
}
|
|
3807
|
+
el.style.setProperty("visibility", "hidden", "important");
|
|
3808
|
+
};
|
|
3809
|
+
const hiddenTimedDescendants = [];
|
|
3810
|
+
const rememberHiddenTimedDescendants = (root) => {
|
|
3811
|
+
for (const node of root.querySelectorAll("[data-start]")) {
|
|
3812
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
3813
|
+
const computed = window.getComputedStyle(node);
|
|
3814
|
+
if (computed.visibility !== "hidden" && computed.display !== "none") continue;
|
|
3815
|
+
hiddenTimedDescendants.push(node);
|
|
3816
|
+
}
|
|
3817
|
+
};
|
|
3818
|
+
const showSelectors = [];
|
|
3819
|
+
for (const id of args.show) {
|
|
3820
|
+
const el = window.__hfMediaEl?.(id) ?? document.getElementById(id);
|
|
3821
|
+
if (el) rememberHiddenTimedDescendants(el);
|
|
3822
|
+
if (el?.hasAttribute(args.renderIdAttr)) {
|
|
3823
|
+
const attrEscaped = id.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
3824
|
+
const byRenderId = `[${args.renderIdAttr}="${attrEscaped}"]`;
|
|
3825
|
+
showSelectors.push(byRenderId, `${byRenderId} *`);
|
|
3826
|
+
} else {
|
|
3827
|
+
const escaped = CSS.escape(id);
|
|
3828
|
+
showSelectors.push(`#${escaped}`, `#${escaped} *`);
|
|
3829
|
+
}
|
|
3830
|
+
const renderEscaped = CSS.escape(renderFrameId(id));
|
|
3831
|
+
showSelectors.push(`#${renderEscaped}`, `#${renderEscaped} *`);
|
|
3832
|
+
const colorGradingEscaped = CSS.escape(`${args.canvasIdPrefix}${id}`);
|
|
3833
|
+
showSelectors.push(`#${colorGradingEscaped}`, `#${colorGradingEscaped} *`);
|
|
3834
|
+
}
|
|
3835
|
+
const massHideRule = "body *{visibility:hidden !important;}";
|
|
3836
|
+
const showRule = showSelectors.length === 0 ? "" : `${showSelectors.join(",")}{visibility:visible !important;}`;
|
|
3837
|
+
const style = document.createElement("style");
|
|
3838
|
+
style.id = args.styleId;
|
|
3839
|
+
style.textContent = `${massHideRule}
|
|
3840
|
+
${showRule}`;
|
|
3841
|
+
document.head.appendChild(style);
|
|
3842
|
+
for (const el of hiddenTimedDescendants) {
|
|
3843
|
+
rememberAndHideElement(el);
|
|
3844
|
+
}
|
|
3845
|
+
for (const id of args.hide) {
|
|
3846
|
+
const el = window.__hfMediaEl?.(id) ?? document.getElementById(id);
|
|
3847
|
+
if (el instanceof HTMLElement) {
|
|
3848
|
+
rememberAndHideElement(el);
|
|
3849
|
+
}
|
|
3850
|
+
const img = document.getElementById(renderFrameId(id));
|
|
3851
|
+
if (img) {
|
|
3852
|
+
rememberAndHideElement(img);
|
|
3853
|
+
}
|
|
3854
|
+
const colorGradingCanvas = document.getElementById(`${args.canvasIdPrefix}${id}`);
|
|
3855
|
+
if (colorGradingCanvas instanceof HTMLElement) {
|
|
3856
|
+
rememberAndHideElement(colorGradingCanvas);
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3886
3859
|
},
|
|
3887
|
-
{
|
|
3860
|
+
{
|
|
3861
|
+
show: showIds,
|
|
3862
|
+
hide: extraHideIds,
|
|
3863
|
+
renderIdAttr: MEDIA_RENDER_ID_ATTR,
|
|
3864
|
+
renderFramePrefix: RENDER_FRAME_ID_PREFIX,
|
|
3865
|
+
renderFrameSuffix: RENDER_FRAME_ID_SUFFIX,
|
|
3866
|
+
styleId: DOM_LAYER_MASK_STYLE_ID,
|
|
3867
|
+
hiddenAttr: DOM_LAYER_MASK_HIDDEN_ATTR,
|
|
3868
|
+
prevVisibilityAttr: DOM_LAYER_MASK_PREV_VISIBILITY_ATTR,
|
|
3869
|
+
prevPriorityAttr: DOM_LAYER_MASK_PREV_PRIORITY_ATTR,
|
|
3870
|
+
canvasIdPrefix: HF_COLOR_GRADING_CANVAS_ID_PREFIX
|
|
3871
|
+
}
|
|
3888
3872
|
);
|
|
3889
|
-
return { encodeResult };
|
|
3890
3873
|
}
|
|
3891
|
-
async function
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
if (state.pending.delete(frameId)) {
|
|
3906
|
-
reject(new Error(`drawElement worker encode timed out (frame ${frameId})`));
|
|
3907
|
-
}
|
|
3908
|
-
}, 3e4);
|
|
3909
|
-
state.pending.set(frameId, {
|
|
3910
|
-
resolve: (b) => {
|
|
3911
|
-
clearTimeout(timer);
|
|
3912
|
-
resolve2(b);
|
|
3913
|
-
},
|
|
3914
|
-
reject: (e) => {
|
|
3915
|
-
clearTimeout(timer);
|
|
3916
|
-
reject(e);
|
|
3874
|
+
async function removeDomLayerMask(page, _extraHideIds) {
|
|
3875
|
+
await page.evaluate(
|
|
3876
|
+
(args) => {
|
|
3877
|
+
const style = document.getElementById(args.styleId);
|
|
3878
|
+
if (style) style.remove();
|
|
3879
|
+
const masked = document.querySelectorAll(`[${args.hiddenAttr}="1"]`);
|
|
3880
|
+
for (const node of masked) {
|
|
3881
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
3882
|
+
const prevVisibility = node.getAttribute(args.prevVisibilityAttr);
|
|
3883
|
+
const prevPriority = node.getAttribute(args.prevPriorityAttr);
|
|
3884
|
+
if (prevVisibility === null) {
|
|
3885
|
+
node.style.removeProperty("visibility");
|
|
3886
|
+
} else {
|
|
3887
|
+
node.style.setProperty("visibility", prevVisibility, prevPriority ?? "");
|
|
3917
3888
|
}
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
});
|
|
3922
|
-
encodeResults.push(p);
|
|
3923
|
-
}
|
|
3924
|
-
const outcome = await page.evaluate(
|
|
3925
|
-
async ({
|
|
3926
|
-
frames,
|
|
3927
|
-
w,
|
|
3928
|
-
h,
|
|
3929
|
-
q
|
|
3930
|
-
}) => {
|
|
3931
|
-
const canvas = document.getElementById("__hf_de_canvas");
|
|
3932
|
-
const root = document.querySelector("[data-composition-id]");
|
|
3933
|
-
if (!root) {
|
|
3934
|
-
return {
|
|
3935
|
-
failedAt: 0,
|
|
3936
|
-
error: "HF_DE_COMPOSITION_ROOT_MISSING: drawElement composition root not found"
|
|
3937
|
-
};
|
|
3889
|
+
node.removeAttribute(args.hiddenAttr);
|
|
3890
|
+
node.removeAttribute(args.prevVisibilityAttr);
|
|
3891
|
+
node.removeAttribute(args.prevPriorityAttr);
|
|
3938
3892
|
}
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3893
|
+
},
|
|
3894
|
+
{
|
|
3895
|
+
styleId: DOM_LAYER_MASK_STYLE_ID,
|
|
3896
|
+
hiddenAttr: DOM_LAYER_MASK_HIDDEN_ATTR,
|
|
3897
|
+
prevVisibilityAttr: DOM_LAYER_MASK_PREV_VISIBILITY_ATTR,
|
|
3898
|
+
prevPriorityAttr: DOM_LAYER_MASK_PREV_PRIORITY_ATTR
|
|
3899
|
+
}
|
|
3900
|
+
);
|
|
3901
|
+
}
|
|
3902
|
+
async function ensureRenderFrameSiblings(page) {
|
|
3903
|
+
await page.evaluate(
|
|
3904
|
+
(prefix, suffix) => {
|
|
3905
|
+
for (const video of Array.from(
|
|
3906
|
+
document.querySelectorAll("video[data-start]")
|
|
3907
|
+
)) {
|
|
3908
|
+
const next = video.nextElementSibling;
|
|
3909
|
+
if (next !== null && next.classList.contains("__render_frame__")) continue;
|
|
3910
|
+
const img = document.createElement("img");
|
|
3911
|
+
img.classList.add("__render_frame__");
|
|
3912
|
+
img.id = `${prefix}${window.__hfMediaId?.(video) || video.id}${suffix}`;
|
|
3913
|
+
img.style.pointerEvents = "none";
|
|
3914
|
+
img.style.position = "absolute";
|
|
3915
|
+
img.style.visibility = "hidden";
|
|
3916
|
+
video.parentNode?.insertBefore(img, video.nextSibling);
|
|
3944
3917
|
}
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3918
|
+
},
|
|
3919
|
+
RENDER_FRAME_ID_PREFIX,
|
|
3920
|
+
RENDER_FRAME_ID_SUFFIX
|
|
3921
|
+
);
|
|
3922
|
+
}
|
|
3923
|
+
async function injectVideoFramesBatch(page, updates, restyleIds = []) {
|
|
3924
|
+
if (updates.length === 0 && restyleIds.length === 0) return [];
|
|
3925
|
+
return withVideoFrameSources(
|
|
3926
|
+
page,
|
|
3927
|
+
updates,
|
|
3928
|
+
(resolved) => injectResolvedVideoFramesBatch(page, resolved, restyleIds)
|
|
3929
|
+
);
|
|
3930
|
+
}
|
|
3931
|
+
async function injectResolvedVideoFramesBatch(page, updates, restyleIds) {
|
|
3932
|
+
const items = [
|
|
3933
|
+
...updates,
|
|
3934
|
+
...restyleIds.map((videoId) => ({ videoId }))
|
|
3935
|
+
].map((item) => ({ ...item, frameId: renderFrameIdForRenderId(item.videoId) }));
|
|
3936
|
+
return await page.evaluate(
|
|
3937
|
+
// fallow-ignore-next-line complexity
|
|
3938
|
+
async (items2, visualProperties, colorGradingSourceHiddenAttr) => {
|
|
3939
|
+
const injectedIds = [];
|
|
3940
|
+
const pendingDecodes = [];
|
|
3941
|
+
const imagesToPublish = [];
|
|
3942
|
+
const replacementLayoutProperties = /* @__PURE__ */ new Set([
|
|
3943
|
+
"width",
|
|
3944
|
+
"height",
|
|
3945
|
+
"top",
|
|
3946
|
+
"left",
|
|
3947
|
+
"right",
|
|
3948
|
+
"bottom",
|
|
3949
|
+
"inset"
|
|
3950
|
+
]);
|
|
3951
|
+
const isVisualAncestorHidden = (el) => {
|
|
3952
|
+
let parent = el.parentElement;
|
|
3953
|
+
while (parent !== null && parent !== document.documentElement) {
|
|
3954
|
+
const computed = window.getComputedStyle(parent);
|
|
3955
|
+
if (computed.display === "none") return true;
|
|
3956
|
+
if (computed.visibility === "hidden" && (parent.hasAttribute("data-composition-src") || parent.hasAttribute("data-composition-file"))) {
|
|
3957
|
+
return true;
|
|
3982
3958
|
}
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3959
|
+
parent = parent.parentElement;
|
|
3960
|
+
}
|
|
3961
|
+
return false;
|
|
3962
|
+
};
|
|
3963
|
+
for (const item of items2) {
|
|
3964
|
+
const video = window.__hfMediaEl?.(item.videoId) ?? document.getElementById(item.videoId);
|
|
3965
|
+
if (!video) continue;
|
|
3966
|
+
let img = video.nextElementSibling;
|
|
3967
|
+
const hasImg = img !== null && img.classList.contains("__render_frame__");
|
|
3968
|
+
const restyleOnly = item.dataUri === void 0;
|
|
3969
|
+
if (restyleOnly && !hasImg) continue;
|
|
3970
|
+
if (isVisualAncestorHidden(video)) {
|
|
3971
|
+
if (hasImg && img) img.style.setProperty("visibility", "hidden", "important");
|
|
3972
|
+
continue;
|
|
3973
|
+
}
|
|
3974
|
+
const isNewImage = !hasImg;
|
|
3975
|
+
const computedStyle = window.getComputedStyle(video);
|
|
3976
|
+
const opacityParsed = parseFloat(computedStyle.opacity);
|
|
3977
|
+
const computedOpacity = video.hasAttribute(colorGradingSourceHiddenAttr) ? 1 : Number.isNaN(opacityParsed) ? 1 : opacityParsed;
|
|
3978
|
+
const videoRect = video.getBoundingClientRect();
|
|
3979
|
+
const videoBox = {
|
|
3980
|
+
left: Number.isFinite(video.offsetLeft) ? video.offsetLeft : 0,
|
|
3981
|
+
top: Number.isFinite(video.offsetTop) ? video.offsetTop : 0,
|
|
3982
|
+
width: video.offsetWidth > 0 ? video.offsetWidth : videoRect.width,
|
|
3983
|
+
height: video.offsetHeight > 0 ? video.offsetHeight : videoRect.height
|
|
3984
|
+
};
|
|
3985
|
+
if (isNewImage) {
|
|
3986
|
+
img = document.createElement("img");
|
|
3987
|
+
img.classList.add("__render_frame__");
|
|
3988
|
+
img.id = item.frameId;
|
|
3989
|
+
img.style.pointerEvents = "none";
|
|
3990
|
+
video.parentNode?.insertBefore(img, video.nextSibling);
|
|
3991
|
+
}
|
|
3992
|
+
if (!img) continue;
|
|
3993
|
+
for (const property of visualProperties) {
|
|
3994
|
+
if (property === "opacity") continue;
|
|
3995
|
+
if (replacementLayoutProperties.has(property)) {
|
|
3996
|
+
continue;
|
|
3991
3997
|
}
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
for (const c of accel) {
|
|
3996
|
-
if (c.hasAttribute("data-hf-3d")) continue;
|
|
3997
|
-
const r = c.getBoundingClientRect();
|
|
3998
|
-
try {
|
|
3999
|
-
ctx.drawImage(c, r.left - rootRect.left, r.top - rootRect.top, r.width, r.height);
|
|
4000
|
-
} catch {
|
|
4001
|
-
}
|
|
3998
|
+
const value = computedStyle.getPropertyValue(property);
|
|
3999
|
+
if (value) {
|
|
4000
|
+
img.style.setProperty(property, value);
|
|
4002
4001
|
}
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4002
|
+
}
|
|
4003
|
+
img.style.position = "absolute";
|
|
4004
|
+
img.style.inset = "auto";
|
|
4005
|
+
img.style.left = `${videoBox.left}px`;
|
|
4006
|
+
img.style.top = `${videoBox.top}px`;
|
|
4007
|
+
img.style.right = "auto";
|
|
4008
|
+
img.style.bottom = "auto";
|
|
4009
|
+
img.style.width = `${videoBox.width}px`;
|
|
4010
|
+
img.style.height = `${videoBox.height}px`;
|
|
4011
|
+
img.style.boxSizing = "border-box";
|
|
4012
|
+
img.style.objectFit = computedStyle.objectFit;
|
|
4013
|
+
img.style.objectPosition = computedStyle.objectPosition;
|
|
4014
|
+
img.style.zIndex = computedStyle.zIndex;
|
|
4015
|
+
img.style.setProperty("visibility", "hidden", "important");
|
|
4016
|
+
img.decoding = "sync";
|
|
4017
|
+
if (item.dataUri !== void 0 && img.getAttribute("src") !== item.dataUri) {
|
|
4018
|
+
if (item.crossOrigin) img.crossOrigin = item.crossOrigin;
|
|
4019
|
+
else img.removeAttribute("crossorigin");
|
|
4020
|
+
img.src = item.dataUri;
|
|
4021
|
+
const source = item.sourceLabel ?? (item.dataUri.startsWith("data:") ? "inline frame" : item.dataUri);
|
|
4022
|
+
pendingDecodes.push(
|
|
4023
|
+
img.decode().catch((error) => {
|
|
4024
|
+
throw new Error(
|
|
4025
|
+
`Video frame for "${item.videoId}" failed to load (${source}): ${error instanceof Error ? error.message : String(error)}`
|
|
4026
|
+
);
|
|
4027
|
+
})
|
|
4028
|
+
);
|
|
4029
|
+
}
|
|
4030
|
+
img.style.opacity = String(computedOpacity);
|
|
4031
|
+
imagesToPublish.push(img);
|
|
4032
|
+
video.style.setProperty("visibility", "hidden", "important");
|
|
4033
|
+
video.style.setProperty("pointer-events", "none", "important");
|
|
4034
|
+
if (!restyleOnly) injectedIds.push(item.videoId);
|
|
4035
|
+
}
|
|
4036
|
+
if (pendingDecodes.length > 0) {
|
|
4037
|
+
await Promise.all(pendingDecodes);
|
|
4038
|
+
}
|
|
4039
|
+
for (const img of imagesToPublish) img.style.visibility = "visible";
|
|
4040
|
+
if (imagesToPublish.length > 0) {
|
|
4041
|
+
const redraw = window.__hf?.colorGrading?.redraw;
|
|
4042
|
+
redraw?.();
|
|
4043
|
+
}
|
|
4044
|
+
return injectedIds;
|
|
4045
|
+
},
|
|
4046
|
+
items,
|
|
4047
|
+
[...MEDIA_VISUAL_STYLE_PROPERTIES],
|
|
4048
|
+
COLOR_GRADING_SOURCE_HIDDEN_ATTR
|
|
4049
|
+
);
|
|
4050
|
+
}
|
|
4051
|
+
async function syncVideoFrameVisibility(page, activeVideoIds) {
|
|
4052
|
+
await page.evaluate(
|
|
4053
|
+
// fallow-ignore-next-line complexity
|
|
4054
|
+
(ids, colorGradingSourceHiddenAttr) => {
|
|
4055
|
+
const isVisualAncestorHidden = (el) => {
|
|
4056
|
+
let parent = el.parentElement;
|
|
4057
|
+
while (parent !== null && parent !== document.documentElement) {
|
|
4058
|
+
const computed = window.getComputedStyle(parent);
|
|
4059
|
+
if (computed.display === "none") return true;
|
|
4060
|
+
if (computed.visibility === "hidden" && (parent.hasAttribute("data-composition-src") || parent.hasAttribute("data-composition-file"))) {
|
|
4061
|
+
return true;
|
|
4032
4062
|
}
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4063
|
+
parent = parent.parentElement;
|
|
4064
|
+
}
|
|
4065
|
+
return false;
|
|
4066
|
+
};
|
|
4067
|
+
const active = new Set(ids);
|
|
4068
|
+
const setColorGradingVisibility = window.__hf?.colorGrading?.setSourceVisibility;
|
|
4069
|
+
const videos = Array.from(
|
|
4070
|
+
document.querySelectorAll("video[data-start]")
|
|
4071
|
+
);
|
|
4072
|
+
for (const video of videos) {
|
|
4073
|
+
const img = video.nextElementSibling;
|
|
4074
|
+
const hasImg = img && img.classList.contains("__render_frame__");
|
|
4075
|
+
const ancestorHidden = isVisualAncestorHidden(video);
|
|
4076
|
+
const visible = active.has(window.__hfMediaId?.(video) || video.id) && !ancestorHidden;
|
|
4077
|
+
if (visible) {
|
|
4078
|
+
video.style.setProperty("visibility", "hidden", "important");
|
|
4079
|
+
video.style.setProperty("pointer-events", "none", "important");
|
|
4080
|
+
if (hasImg) {
|
|
4081
|
+
if (video.hasAttribute(colorGradingSourceHiddenAttr)) img.style.opacity = "1";
|
|
4082
|
+
img.style.visibility = "visible";
|
|
4043
4083
|
}
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
}
|
|
4050
|
-
aw.__hfEncWorker.postMessage({ bmp, id: fid, w, h, q: q / 100 }, [bmp]);
|
|
4051
|
-
});
|
|
4052
|
-
} catch (e) {
|
|
4053
|
-
try {
|
|
4054
|
-
await prevBitmap;
|
|
4055
|
-
} catch {
|
|
4084
|
+
} else {
|
|
4085
|
+
video.style.setProperty("visibility", "hidden", "important");
|
|
4086
|
+
video.style.setProperty("pointer-events", "none", "important");
|
|
4087
|
+
if (hasImg) {
|
|
4088
|
+
img.style.setProperty("visibility", "hidden", "important");
|
|
4056
4089
|
}
|
|
4057
|
-
return { failedAt: i, error: errMsg(e) };
|
|
4058
4090
|
}
|
|
4091
|
+
setColorGradingVisibility?.(video, visible);
|
|
4059
4092
|
}
|
|
4060
|
-
try {
|
|
4061
|
-
await prevBitmap;
|
|
4062
|
-
} catch (e) {
|
|
4063
|
-
return { failedAt: prevBitmapIdx, error: errMsg(e) };
|
|
4064
|
-
}
|
|
4065
|
-
return { failedAt: null };
|
|
4066
4093
|
},
|
|
4067
|
-
|
|
4094
|
+
activeVideoIds,
|
|
4095
|
+
COLOR_GRADING_SOURCE_HIDDEN_ATTR
|
|
4068
4096
|
);
|
|
4069
|
-
if (outcome.failedAt !== null) {
|
|
4070
|
-
for (let k = outcome.failedAt; k < fids.length; k++) {
|
|
4071
|
-
const fid = fids[k];
|
|
4072
|
-
if (fid === void 0) continue;
|
|
4073
|
-
const entry = state.pending.get(fid);
|
|
4074
|
-
if (entry) {
|
|
4075
|
-
state.pending.delete(fid);
|
|
4076
|
-
entry.reject(
|
|
4077
|
-
new Error(`drawElement batch produce failed at frame ${k}: ${outcome.error ?? "?"}`)
|
|
4078
|
-
);
|
|
4079
|
-
}
|
|
4080
|
-
}
|
|
4081
|
-
}
|
|
4082
|
-
return { encodeResults, failedAt: outcome.failedAt, error: outcome.error };
|
|
4083
4097
|
}
|
|
4084
4098
|
|
|
4085
4099
|
// ../engine/src/services/threeDProjection.ts
|
|
@@ -5992,6 +6006,7 @@ async function constructCaptureSession(input) {
|
|
|
5992
6006
|
});
|
|
5993
6007
|
await installMediaPageHooks(page, options);
|
|
5994
6008
|
if (useDrawElement) {
|
|
6009
|
+
await page.evaluateOnNewDocument(forcePreservedDrawingBuffer);
|
|
5995
6010
|
await page.evaluateOnNewDocument(instrumentAcceleratedCanvases);
|
|
5996
6011
|
}
|
|
5997
6012
|
if (process.env.HF_FAST_CAPTURE_AUTOALPHA !== void 0) {
|
|
@@ -8671,10 +8686,8 @@ async function detectGpuEncoder() {
|
|
|
8671
8686
|
return selectUsableGpuEncoder(candidates, canUseGpuEncoder).catch(() => null);
|
|
8672
8687
|
}
|
|
8673
8688
|
var cachedGpuEncoder = void 0;
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
cachedGpuEncoder = await detectGpuEncoder();
|
|
8677
|
-
}
|
|
8689
|
+
function getCachedGpuEncoder() {
|
|
8690
|
+
cachedGpuEncoder ??= detectGpuEncoder();
|
|
8678
8691
|
return cachedGpuEncoder;
|
|
8679
8692
|
}
|
|
8680
8693
|
function getGpuEncoderName(encoder, codec) {
|
|
@@ -9261,7 +9274,10 @@ function ffprobeMajor() {
|
|
|
9261
9274
|
runtimeFfprobeMajor ??= new Promise((resolve2) => {
|
|
9262
9275
|
let out = "";
|
|
9263
9276
|
const binary = getFfprobeBinary();
|
|
9264
|
-
const proc = spawn4(binary, ["-version"], {
|
|
9277
|
+
const proc = spawn4(binary, ["-version"], {
|
|
9278
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
9279
|
+
windowsHide: true
|
|
9280
|
+
});
|
|
9265
9281
|
proc.stdout.on("data", (chunk) => out += String(chunk));
|
|
9266
9282
|
proc.on("error", () => resolve2(void 0));
|
|
9267
9283
|
proc.on("close", () => resolve2(Number(/version n?(\d+)/.exec(out)?.[1]) || void 0));
|
|
@@ -15107,9 +15123,14 @@ function supportsSettsDuration(binary = getFfmpegBinary()) {
|
|
|
15107
15123
|
let supported = settsDurationSupport.get(binary);
|
|
15108
15124
|
if (!supported) {
|
|
15109
15125
|
supported = new Promise((resolve2) => {
|
|
15110
|
-
execFile3(
|
|
15111
|
-
|
|
15112
|
-
|
|
15126
|
+
execFile3(
|
|
15127
|
+
binary,
|
|
15128
|
+
["-hide_banner", "-h", "bsf=setts"],
|
|
15129
|
+
{ windowsHide: true },
|
|
15130
|
+
(error, stdout) => {
|
|
15131
|
+
resolve2(error !== null || stdout.includes("duration"));
|
|
15132
|
+
}
|
|
15133
|
+
);
|
|
15113
15134
|
});
|
|
15114
15135
|
settsDurationSupport.set(binary, supported);
|
|
15115
15136
|
}
|
|
@@ -17556,6 +17577,9 @@ async function readWebGlVendorInfoFromCanvas(page) {
|
|
|
17556
17577
|
var MEMORY_PER_WORKER_MB = 1536;
|
|
17557
17578
|
var HEAP_RESERVED_MB = 1024;
|
|
17558
17579
|
var HEAP_PER_WORKER_MB = 640;
|
|
17580
|
+
var APPLE_DISK_HEAP_PER_WORKER_MB = 128;
|
|
17581
|
+
var APPLE_DISK_CORES_PER_WORKER = 1.75;
|
|
17582
|
+
var APPLE_DISK_MAX_WORKERS = 8;
|
|
17559
17583
|
var MIN_WORKERS = 1;
|
|
17560
17584
|
var MAX_WORKER_DIAGNOSTIC_LINES = 8;
|
|
17561
17585
|
var ABSOLUTE_MAX_WORKERS = 24;
|
|
@@ -17603,9 +17627,12 @@ function computeWorkerSizing(totalFrames, requested, config) {
|
|
|
17603
17627
|
const cpuCount = cpus3().length;
|
|
17604
17628
|
const totalMemoryMb = getSystemTotalMb();
|
|
17605
17629
|
const heapLimitMb = Math.round(getHeapStatistics().heap_size_limit / (1024 * 1024));
|
|
17630
|
+
const appleDisk = config?.appleGpuDiskCapture === true;
|
|
17606
17631
|
const heapBasedWorkers = Math.max(
|
|
17607
17632
|
1,
|
|
17608
|
-
Math.floor(
|
|
17633
|
+
Math.floor(
|
|
17634
|
+
(heapLimitMb - HEAP_RESERVED_MB) / (appleDisk ? APPLE_DISK_HEAP_PER_WORKER_MB : HEAP_PER_WORKER_MB)
|
|
17635
|
+
)
|
|
17609
17636
|
);
|
|
17610
17637
|
const cpuBasedWorkers = Math.max(1, cpuCount - 2);
|
|
17611
17638
|
const memoryBasedWorkers = Math.max(1, Math.floor(totalMemoryMb * 0.5 / MEMORY_PER_WORKER_MB));
|
|
@@ -17640,9 +17667,10 @@ function computeWorkerSizing(totalFrames, requested, config) {
|
|
|
17640
17667
|
if (concurrency !== "auto") {
|
|
17641
17668
|
return Math.max(MIN_WORKERS, Math.min(ABSOLUTE_MAX_WORKERS, Math.floor(concurrency)));
|
|
17642
17669
|
}
|
|
17643
|
-
return defaultSafeMaxWorkers();
|
|
17670
|
+
return appleDisk ? Math.max(defaultSafeMaxWorkers(), APPLE_DISK_MAX_WORKERS) : defaultSafeMaxWorkers();
|
|
17644
17671
|
})();
|
|
17645
|
-
const
|
|
17672
|
+
const configuredCoresPerWorker = config?.coresPerWorker ?? DEFAULT_CONFIG.coresPerWorker;
|
|
17673
|
+
const effectiveCoresPerWorker = appleDisk && configuredCoresPerWorker === DEFAULT_CONFIG.coresPerWorker ? APPLE_DISK_CORES_PER_WORKER : configuredCoresPerWorker;
|
|
17646
17674
|
const effectiveMinParallelFrames = config?.minParallelFrames ?? DEFAULT_CONFIG.minParallelFrames;
|
|
17647
17675
|
const effectiveLargeRenderThreshold = config?.largeRenderThreshold ?? DEFAULT_CONFIG.largeRenderThreshold;
|
|
17648
17676
|
if (totalFrames < MIN_FRAMES_PER_WORKER * 2) {
|
|
@@ -18297,6 +18325,118 @@ function createFileServer(options) {
|
|
|
18297
18325
|
});
|
|
18298
18326
|
}
|
|
18299
18327
|
|
|
18328
|
+
// ../engine/src/utils/browserSafePort.ts
|
|
18329
|
+
var RESTRICTED_PORTS = /* @__PURE__ */ new Set([
|
|
18330
|
+
1,
|
|
18331
|
+
7,
|
|
18332
|
+
9,
|
|
18333
|
+
11,
|
|
18334
|
+
13,
|
|
18335
|
+
15,
|
|
18336
|
+
17,
|
|
18337
|
+
19,
|
|
18338
|
+
20,
|
|
18339
|
+
21,
|
|
18340
|
+
22,
|
|
18341
|
+
23,
|
|
18342
|
+
25,
|
|
18343
|
+
37,
|
|
18344
|
+
42,
|
|
18345
|
+
43,
|
|
18346
|
+
53,
|
|
18347
|
+
69,
|
|
18348
|
+
77,
|
|
18349
|
+
79,
|
|
18350
|
+
87,
|
|
18351
|
+
95,
|
|
18352
|
+
101,
|
|
18353
|
+
102,
|
|
18354
|
+
103,
|
|
18355
|
+
104,
|
|
18356
|
+
109,
|
|
18357
|
+
110,
|
|
18358
|
+
111,
|
|
18359
|
+
113,
|
|
18360
|
+
115,
|
|
18361
|
+
117,
|
|
18362
|
+
119,
|
|
18363
|
+
123,
|
|
18364
|
+
135,
|
|
18365
|
+
137,
|
|
18366
|
+
139,
|
|
18367
|
+
143,
|
|
18368
|
+
161,
|
|
18369
|
+
179,
|
|
18370
|
+
389,
|
|
18371
|
+
427,
|
|
18372
|
+
465,
|
|
18373
|
+
512,
|
|
18374
|
+
513,
|
|
18375
|
+
514,
|
|
18376
|
+
515,
|
|
18377
|
+
526,
|
|
18378
|
+
530,
|
|
18379
|
+
531,
|
|
18380
|
+
532,
|
|
18381
|
+
540,
|
|
18382
|
+
548,
|
|
18383
|
+
554,
|
|
18384
|
+
556,
|
|
18385
|
+
563,
|
|
18386
|
+
587,
|
|
18387
|
+
601,
|
|
18388
|
+
636,
|
|
18389
|
+
989,
|
|
18390
|
+
990,
|
|
18391
|
+
993,
|
|
18392
|
+
995,
|
|
18393
|
+
1719,
|
|
18394
|
+
1720,
|
|
18395
|
+
1723,
|
|
18396
|
+
2049,
|
|
18397
|
+
3659,
|
|
18398
|
+
4045,
|
|
18399
|
+
5060,
|
|
18400
|
+
5061,
|
|
18401
|
+
6e3,
|
|
18402
|
+
6566,
|
|
18403
|
+
6665,
|
|
18404
|
+
6666,
|
|
18405
|
+
6667,
|
|
18406
|
+
6668,
|
|
18407
|
+
6669,
|
|
18408
|
+
6697,
|
|
18409
|
+
10080
|
|
18410
|
+
]);
|
|
18411
|
+
var MAX_ATTEMPTS = 32;
|
|
18412
|
+
var isBrowserSafePort = (port) => !RESTRICTED_PORTS.has(port);
|
|
18413
|
+
function listenOnce(server, host) {
|
|
18414
|
+
return new Promise((resolve2, reject) => {
|
|
18415
|
+
server.once("error", reject);
|
|
18416
|
+
server.listen(0, host, () => {
|
|
18417
|
+
server.off("error", reject);
|
|
18418
|
+
resolve2(server.address().port);
|
|
18419
|
+
});
|
|
18420
|
+
});
|
|
18421
|
+
}
|
|
18422
|
+
function closeServer(server) {
|
|
18423
|
+
return new Promise((resolve2) => server.close(() => resolve2()));
|
|
18424
|
+
}
|
|
18425
|
+
async function settleOnBrowserSafePort(server, host) {
|
|
18426
|
+
let port = server.address().port;
|
|
18427
|
+
for (let attempt = 1; !isBrowserSafePort(port); attempt++) {
|
|
18428
|
+
if (attempt >= MAX_ATTEMPTS)
|
|
18429
|
+
throw new Error(`The OS kept offering browser-restricted ports (last: ${port}).`);
|
|
18430
|
+
await closeServer(server);
|
|
18431
|
+
port = await listenOnce(server, host);
|
|
18432
|
+
}
|
|
18433
|
+
return port;
|
|
18434
|
+
}
|
|
18435
|
+
async function listenOnBrowserSafePort(server, host) {
|
|
18436
|
+
await listenOnce(server, host);
|
|
18437
|
+
return settleOnBrowserSafePort(server, host);
|
|
18438
|
+
}
|
|
18439
|
+
|
|
18300
18440
|
// ../engine/src/utils/layerCompositor.ts
|
|
18301
18441
|
function groupIntoLayers(elements) {
|
|
18302
18442
|
const sorted = [...elements].sort((a, b) => a.zIndex - b.zIndex);
|
|
@@ -18661,6 +18801,7 @@ export {
|
|
|
18661
18801
|
isProtocolTimeoutError,
|
|
18662
18802
|
augmentPageNavigationTimeoutError,
|
|
18663
18803
|
isPageNavigationTimeoutError,
|
|
18804
|
+
forcePreservedDrawingBuffer,
|
|
18664
18805
|
DrawElementCaptureError,
|
|
18665
18806
|
isDrawElementCaptureError,
|
|
18666
18807
|
decodePng,
|
|
@@ -18727,6 +18868,7 @@ export {
|
|
|
18727
18868
|
trackChildProcess,
|
|
18728
18869
|
killTrackedProcesses,
|
|
18729
18870
|
detectGpuEncoder,
|
|
18871
|
+
getCachedGpuEncoder,
|
|
18730
18872
|
isHdrColorSpace,
|
|
18731
18873
|
detectTransfer,
|
|
18732
18874
|
DEFAULT_HDR10_MASTERING,
|
|
@@ -18855,6 +18997,9 @@ export {
|
|
|
18855
18997
|
mergeWorkerFrames,
|
|
18856
18998
|
getSystemResources,
|
|
18857
18999
|
createFileServer,
|
|
19000
|
+
isBrowserSafePort,
|
|
19001
|
+
settleOnBrowserSafePort,
|
|
19002
|
+
listenOnBrowserSafePort,
|
|
18858
19003
|
groupIntoLayers,
|
|
18859
19004
|
diffGpuParityFrames,
|
|
18860
19005
|
diffGpuParityPngs,
|