allyhub 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/commands/frames.js +9 -11
- package/dist/node_modules/@allyhub/3d-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/browser/package.json +1 -1
- package/dist/node_modules/@allyhub/build/package.json +1 -1
- package/dist/node_modules/@allyhub/canvas-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/canvas-model/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/check/package.json +1 -1
- package/dist/node_modules/@allyhub/cloud/package.json +1 -1
- package/dist/node_modules/@allyhub/components/package.json +1 -1
- package/dist/node_modules/@allyhub/dev-server/dist/server.js +2 -2
- package/dist/node_modules/@allyhub/dev-server/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/doc/package.json +1 -1
- package/dist/node_modules/@allyhub/doc-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/doc-print/dist/drawn.js +4 -4
- package/dist/node_modules/@allyhub/doc-print/dist/fonts.js +3 -3
- package/dist/node_modules/@allyhub/doc-print/dist/layout.js +4 -4
- package/dist/node_modules/@allyhub/doc-print/dist/pdf.js +4 -4
- package/dist/node_modules/@allyhub/doc-print/package.json +1 -1
- package/dist/node_modules/@allyhub/export/package.json +1 -1
- package/dist/node_modules/@allyhub/extension-api/package.json +1 -1
- package/dist/node_modules/@allyhub/extension-host/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/package.json +1 -1
- package/dist/node_modules/@allyhub/i18n/package.json +1 -1
- package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
- package/dist/node_modules/@allyhub/image-extension/dist/cli.js +1 -1
- package/dist/node_modules/@allyhub/image-extension/dist/export.js +2 -2
- package/dist/node_modules/@allyhub/image-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/image-psd/dist/ag-psd.js +2 -0
- package/dist/node_modules/@allyhub/image-psd/dist/read.js +12 -12
- package/dist/node_modules/@allyhub/image-psd/dist/write.js +1 -1
- package/dist/node_modules/@allyhub/image-psd/package.json +1 -1
- package/dist/node_modules/@allyhub/image-render/dist/pdf.js +1 -1
- package/dist/node_modules/@allyhub/image-render/package.json +1 -1
- package/dist/node_modules/@allyhub/image-runtime/package.json +1 -1
- package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/jobs/package.json +1 -1
- package/dist/node_modules/@allyhub/linkedin-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/linkedin-model/package.json +1 -1
- package/dist/node_modules/@allyhub/linkedin-view/dist/stage.js +65 -1
- package/dist/node_modules/@allyhub/linkedin-view/package.json +1 -1
- package/dist/node_modules/@allyhub/measure/package.json +1 -1
- package/dist/node_modules/@allyhub/media/package.json +1 -1
- package/dist/node_modules/@allyhub/media-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/model/package.json +1 -1
- package/dist/node_modules/@allyhub/ooxml/package.json +1 -1
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/project/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/package.json +1 -1
- package/dist/node_modules/@allyhub/registry/package.json +1 -1
- package/dist/node_modules/@allyhub/render/dist/exports.js +2 -2
- package/dist/node_modules/@allyhub/render/package.json +1 -1
- package/dist/node_modules/@allyhub/runtime/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/dist/index.d.ts +1 -1
- package/dist/node_modules/@allyhub/runtimes/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/runtimes/dist/packages.d.ts +17 -0
- package/dist/node_modules/@allyhub/runtimes/dist/packages.js +3 -3
- package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/pins/ag-psd/package-lock.json +49 -0
- package/dist/node_modules/@allyhub/runtimes/pins/ag-psd/package.json +7 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-caladea/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-caladea/package.json +23 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-carlito/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-carlito/package.json +23 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-cousine/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-cousine/package.json +23 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-lxgw-wenkai/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-lxgw-wenkai/package.json +19 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-color-emoji/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-color-emoji/package.json +17 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-sans-sc/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-sans-sc/package.json +19 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-serif-sc/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-noto-serif-sc/package.json +19 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-tinos/package-lock.json +24 -0
- package/dist/node_modules/@allyhub/runtimes/pins/fontsource-tinos/package.json +23 -0
- package/dist/node_modules/@allyhub/runtimes/pins/mermaid/package-lock.json +19 -0
- package/dist/node_modules/@allyhub/runtimes/pins/mermaid/package.json +15 -0
- package/dist/node_modules/@allyhub/runtimes/pins/pdf-lib/package-lock.json +55 -0
- package/dist/node_modules/@allyhub/runtimes/pins/pdf-lib/package.json +7 -0
- package/dist/node_modules/@allyhub/runtimes/pins/pptxgenjs/package-lock.json +169 -0
- package/dist/node_modules/@allyhub/runtimes/pins/pptxgenjs/package.json +7 -0
- package/dist/node_modules/@allyhub/scaffold/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery-host/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-pptx/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-runtime/package.json +1 -1
- package/dist/node_modules/@allyhub/stage/package.json +1 -1
- package/dist/node_modules/@allyhub/stage-page/package.json +1 -1
- package/dist/node_modules/@allyhub/stage-runtime/package.json +1 -1
- package/dist/node_modules/@allyhub/telemetry/package.json +1 -1
- package/dist/node_modules/@allyhub/text-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/video-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/website/package.json +1 -1
- package/dist/node_modules/@allyhub/website-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/x-extension/package.json +1 -1
- package/dist/node_modules/@allyhub/x-model/package.json +1 -1
- package/dist/node_modules/@allyhub/x-view/dist/stage.js +325 -1
- package/dist/node_modules/@allyhub/x-view/package.json +1 -1
- package/dist/package.json +12 -13
- package/dist/works.js +1 -1
- package/editor-web/assets/{abnfDiagram-WEYOIA3C-8aObBFjX.js → abnfDiagram-WEYOIA3C-BHI0AbUY.js} +1 -1
- package/editor-web/assets/{architecture-WOLXFQ4H-CUdbx3Bt.js → architecture-WOLXFQ4H-BMQS-OKZ.js} +1 -1
- package/editor-web/assets/{architectureDiagram-ZHVYKT53-CMsMcKog.js → architectureDiagram-ZHVYKT53-DZp9CM6P.js} +1 -1
- package/editor-web/assets/{article-Cp3YwYpj.js → article-C_mBG5a1.js} +4 -4
- package/editor-web/assets/{article-DNZHN4zd.js → article-DWBxNvX0.js} +2 -2
- package/editor-web/assets/{blockDiagram-RJAE7QA3-DfIz96sD.js → blockDiagram-RJAE7QA3-h6LWaev4.js} +1 -1
- package/editor-web/assets/{c4Diagram-XDPPPE54-CNYzslEF.js → c4Diagram-XDPPPE54-BvSMs7J4.js} +1 -1
- package/editor-web/assets/channel-BFHB0S0f.js +1 -0
- package/editor-web/assets/{chunk-2E7WHVMD-HL6GVd-n.js → chunk-2E7WHVMD-0EJTAmDF.js} +1 -1
- package/editor-web/assets/{chunk-4EMNKR2T-H7j6JGIP.js → chunk-4EMNKR2T-BeYB4AEY.js} +1 -1
- package/editor-web/assets/{chunk-55XCU76K-CG-CNnUw.js → chunk-55XCU76K-BPFOPTBe.js} +1 -1
- package/editor-web/assets/{chunk-7S6XSTFO-DBjGjTwH.js → chunk-7S6XSTFO-CZ2C7ULu.js} +1 -1
- package/editor-web/assets/{chunk-AQDTSKZB-C_-ymsUC.js → chunk-AQDTSKZB-B5RtsZkj.js} +1 -1
- package/editor-web/assets/{chunk-DSNLSHJZ-CHNAY_-p.js → chunk-DSNLSHJZ-_3G4hddj.js} +1 -1
- package/editor-web/assets/{chunk-HAGFOTED-Crk51Pir.js → chunk-HAGFOTED-DO5b4ll2.js} +1 -1
- package/editor-web/assets/{chunk-HNE4Q36P-wRakUuQt.js → chunk-HNE4Q36P-C6XNI71Q.js} +1 -1
- package/editor-web/assets/{chunk-NQOKRVIF-vbSfGzYF.js → chunk-NQOKRVIF-nDCX29rQ.js} +1 -1
- package/editor-web/assets/{chunk-UHW7PFBP-CBB6AHxp.js → chunk-UHW7PFBP-CRCOiitq.js} +1 -1
- package/editor-web/assets/{chunk-VQ5W62QI-B4LA3hAv.js → chunk-VQ5W62QI-hNPKKjCN.js} +1 -1
- package/editor-web/assets/{chunk-WQQL4CDK-BlkMq03F.js → chunk-WQQL4CDK-KlnVtIDc.js} +1 -1
- package/editor-web/assets/{chunk-YZO67HFG-zZbW2WUw.js → chunk-YZO67HFG-B76hDUrM.js} +1 -1
- package/editor-web/assets/{chunk-ZAUX2LTX-CyhuRyRc.js → chunk-ZAUX2LTX-D9m1N0wI.js} +1 -1
- package/editor-web/assets/{chunk-ZCHMQSOR-Z4gsBK-s.js → chunk-ZCHMQSOR-443euxzo.js} +1 -1
- package/editor-web/assets/{classDiagram-v2-4MYWR3UA-BO3pSpA3.js → classDiagram-v2-4MYWR3UA-Bbw-8Ons.js} +1 -1
- package/editor-web/assets/{cynefin-EF2NZ3EQ-BeGktmde.js → cynefin-EF2NZ3EQ-C4E7TlUr.js} +1 -1
- package/editor-web/assets/{cynefinDiagram-WF24UDRP-D4slNgjw.js → cynefinDiagram-WF24UDRP-PBPGa_HS.js} +1 -1
- package/editor-web/assets/{dagre-NK4GIZVX-CHX5BABb.js → dagre-NK4GIZVX-DwXdEtQG.js} +1 -1
- package/editor-web/assets/{diagram-CBK3MWTC-B_DCSy7B.js → diagram-CBK3MWTC-BE3FwdX7.js} +1 -1
- package/editor-web/assets/{diagram-I5XIIV2D-C87ZLuZE.js → diagram-I5XIIV2D-BPl2ZY33.js} +1 -1
- package/editor-web/assets/{diagram-ODIL2UCW-qqQWBi5z.js → diagram-ODIL2UCW-BLVPYSzw.js} +1 -1
- package/editor-web/assets/{diagram-PFBEJUXE-51Kpu1XH.js → diagram-PFBEJUXE-BVZk62FO.js} +1 -1
- package/editor-web/assets/{diagram-RJA3I4VV-BYCd_UhW.js → diagram-RJA3I4VV-Z75LSbxH.js} +1 -1
- package/editor-web/assets/{diagram-TYUNFSNR-ti0bjc0a.js → diagram-TYUNFSNR-BynGqDAg.js} +1 -1
- package/editor-web/assets/{dist-m2WnTa2Z.js → dist--ijXGgvi.js} +3 -3
- package/editor-web/assets/{dist-DrnrJj5f.js → dist-C-yi9AAi.js} +14 -14
- package/editor-web/assets/dist-CIQUbiAd.js +38 -0
- package/editor-web/assets/{dist-CLraEmr5.js → dist-Ch34PllS.js} +1 -1
- package/editor-web/assets/dist-CxlIyluY.js +43 -0
- package/editor-web/assets/dist-DWKEqAou.js +6 -0
- package/editor-web/assets/{dist-BzZrQT5-.js → dist-DX0VLTRV.js} +3 -3
- package/editor-web/assets/dist-D_xVYGnk.js +45 -0
- package/editor-web/assets/{dist-DhGv_Zov.js → dist-Nc_h0Jye.js} +3 -3
- package/editor-web/assets/dist-UG2TIZxP.js +16 -0
- package/editor-web/assets/dist-VP4ECMOk.js +1 -0
- package/editor-web/assets/dist-cUeSwqws.js +1 -0
- package/editor-web/assets/dist-xpAaABxb.js +24 -0
- package/editor-web/assets/{ebnfDiagram-V4P3TTPT-47g4MzmE.js → ebnfDiagram-V4P3TTPT-SwhqbeK4.js} +1 -1
- package/editor-web/assets/{elk-QONTBCTQ-D-MJPm-u.js → elk-QONTBCTQ-Bb1GSt2Z.js} +1 -1
- package/editor-web/assets/{erDiagram-KYQIGQAA-Cf6zVz1i.js → erDiagram-KYQIGQAA-qUy0NDKn.js} +1 -1
- package/editor-web/assets/{eventmodeling-K75KTNOO-DfgBzRXB.js → eventmodeling-K75KTNOO-BYBYso_j.js} +1 -1
- package/editor-web/assets/file-exclamation-point-C_fX4fpI.js +1 -0
- package/editor-web/assets/flowDiagram-IUGLLWBU-BSCBBtP3.js +1 -0
- package/editor-web/assets/{ganttDiagram-R7GPNTJY-ChnlDXK8.js → ganttDiagram-R7GPNTJY-Cw-BkZT8.js} +1 -1
- package/editor-web/assets/{gitGraph-VSP46ZUC-CNvvzSaC.js → gitGraph-VSP46ZUC-CTXzWPq_.js} +1 -1
- package/editor-web/assets/{gitGraphDiagram-PDYL7XHY-C9UYgumu.js → gitGraphDiagram-PDYL7XHY-Jd9HU3WA.js} +1 -1
- package/editor-web/assets/index-Br4a-QEv.css +2 -0
- package/editor-web/assets/{index-DmztYiAy.js → index-CglHrLRS.js} +2 -2
- package/editor-web/assets/{info-OHQRW6UA-D61jDQBy.js → info-OHQRW6UA-C4oj5BpF.js} +1 -1
- package/editor-web/assets/{infoDiagram-MVDRKAX5-ChN_DTt7.js → infoDiagram-MVDRKAX5-D09aYJ28.js} +1 -1
- package/editor-web/assets/{ishikawaDiagram-HPEHV2GE-BYLy6pVq.js → ishikawaDiagram-HPEHV2GE-BEdXoXb2.js} +1 -1
- package/editor-web/assets/{journeyDiagram-BOSHW7O7-CPZ_qfLP.js → journeyDiagram-BOSHW7O7-DE-_0aww.js} +1 -1
- package/editor-web/assets/{kanban-definition-FNSA4HC5-CVwcgf4Q.js → kanban-definition-FNSA4HC5-Cn3_bvPS.js} +1 -1
- package/editor-web/assets/{mermaid-parser.core-C-N4DR9l.js → mermaid-parser.core-BK52JMZH.js} +3 -3
- package/editor-web/assets/{mermaid.core-DA4RESHs.js → mermaid.core-CmfBU89G.js} +4 -4
- package/editor-web/assets/{mindmap-definition-6OY57UG3-CYTwW2kr.js → mindmap-definition-6OY57UG3-CtUhkv9I.js} +1 -1
- package/editor-web/assets/{packet-JDAUHWVQ-ChMUmP4L.js → packet-JDAUHWVQ-C7nciBNp.js} +1 -1
- package/editor-web/assets/{pegDiagram-ECIUJNBX-BhEQqZjT.js → pegDiagram-ECIUJNBX-DUkbAcTs.js} +1 -1
- package/editor-web/assets/{pie-XZMESJXO-BNR0TC-m.js → pie-XZMESJXO-BIGyKhav.js} +1 -1
- package/editor-web/assets/{pieDiagram-GNMPY74T-Yp8QKrUl.js → pieDiagram-GNMPY74T-DrYj-JeG.js} +1 -1
- package/editor-web/assets/{props-form-DhAZXuUd.js → props-form-DrZYDmSM.js} +1 -1
- package/editor-web/assets/{quadrantDiagram-D57K4MC3-DWx6h-WX.js → quadrantDiagram-D57K4MC3-qkBoh1ep.js} +1 -1
- package/editor-web/assets/{radar-ABXABTNO-CTYk7YEu.js → radar-ABXABTNO-BkJmvR6a.js} +1 -1
- package/editor-web/assets/{railroad-I3PHUGI6-BlyTPvKD.js → railroad-I3PHUGI6-BFH-ip4B.js} +1 -1
- package/editor-web/assets/{railroad-abnf-LNEFI6M7-CZ2V2N02.js → railroad-abnf-LNEFI6M7-BBlzHL6Z.js} +1 -1
- package/editor-web/assets/{railroad-ebnf-DWYD2UWJ-CBgU-FLz.js → railroad-ebnf-DWYD2UWJ-CCVsG0ui.js} +1 -1
- package/editor-web/assets/{railroad-peg-JR7BVNR7-CflVoiT7.js → railroad-peg-JR7BVNR7-Puo7BFPl.js} +1 -1
- package/editor-web/assets/{railroadDiagram-Y72NRBL7-CYZ2kXNJ.js → railroadDiagram-Y72NRBL7-DCwfkv35.js} +1 -1
- package/editor-web/assets/{requirementDiagram-EQYSW5RA-D4eEJPbs.js → requirementDiagram-EQYSW5RA-DSTcDj32.js} +1 -1
- package/editor-web/assets/{sankeyDiagram-SY24JHO5-CSOvThfE.js → sankeyDiagram-SY24JHO5-Kqq4fCvG.js} +1 -1
- package/editor-web/assets/schemas-B89k2jEC.js +1 -0
- package/editor-web/assets/scissors-BURkYWPv.js +1 -0
- package/editor-web/assets/search-jKDvFIEU.js +1 -0
- package/editor-web/assets/{sequenceDiagram-BLEHNHQU-Daz5aJOq.js → sequenceDiagram-BLEHNHQU-B1uodEgL.js} +1 -1
- package/editor-web/assets/{split-BRdiwbHG.js → split-Cu0fidVK.js} +1 -1
- package/editor-web/assets/{stateDiagram-v2-A6IESKWZ-7fYxau3w.js → stateDiagram-v2-A6IESKWZ-B6gG3vUm.js} +1 -1
- package/editor-web/assets/surface-D9qJjJQL.js +1 -0
- package/editor-web/assets/swatch-S8YuBYyj.js +1 -0
- package/editor-web/assets/{swimlanes-B3ENRKFQ-PvWj6MaB.js → swimlanes-B3ENRKFQ-CZayRtvU.js} +1 -1
- package/editor-web/assets/swimlanesDiagram-AYQRV4AK-B9tLTrym.js +8 -0
- package/editor-web/assets/syntax-DSsHrzWF.js +1 -0
- package/editor-web/assets/tabs-B_K0Db1I.js +1 -0
- package/editor-web/assets/{timeline-definition-JXYKGLGB-DM74MMtl.js → timeline-definition-JXYKGLGB-5YoY8Xhw.js} +1 -1
- package/editor-web/assets/{treeView-D4JQ5SDB-CpxiEjIR.js → treeView-D4JQ5SDB-Brd_NUPx.js} +1 -1
- package/editor-web/assets/{treemap-SAJKECNS-qiS2PdWZ.js → treemap-SAJKECNS-DmfdnlWl.js} +1 -1
- package/editor-web/assets/{usecaseDiagram-WPOLBNNX-CtqoB1RY.js → usecaseDiagram-WPOLBNNX-lcAkMviI.js} +1 -1
- package/editor-web/assets/{vennDiagram-Q3Y3IDCW-CzTC1h8Z.js → vennDiagram-Q3Y3IDCW-DY_n48hQ.js} +1 -1
- package/editor-web/assets/{video-_FVN5Mu3.js → video-Bv3rETBU.js} +1 -1
- package/editor-web/assets/{wardley-7MLQ67FV-CzagHSqx.js → wardley-7MLQ67FV-DzIFSBQz.js} +1 -1
- package/editor-web/assets/{wardleyDiagram-IVAIDKWA-DHnCuUHn.js → wardleyDiagram-IVAIDKWA-CsXNajIg.js} +1 -1
- package/editor-web/assets/whole-word-6DliXke2.js +1 -0
- package/editor-web/assets/{words-Cn65rXEp.js → words-BTRrBFUo.js} +1 -1
- package/editor-web/assets/{words-4adjjnra.js → words-ll_94CD2.js} +1 -1
- package/editor-web/assets/{xychartDiagram-4URNHDU4-H8q7BDE8.js → xychartDiagram-4URNHDU4-DDpGFEum.js} +1 -1
- package/editor-web/index.html +2 -2
- package/package.json +2 -25
- package/dist/commands/frames/report.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/LICENSE +0 -241
- package/dist/node_modules/@allyhub/report-extension/dist/build.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/dist/check.js +0 -3
- package/dist/node_modules/@allyhub/report-extension/dist/cli/find.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/dist/cli/index.js +0 -5
- package/dist/node_modules/@allyhub/report-extension/dist/cli/picture.js +0 -30
- package/dist/node_modules/@allyhub/report-extension/dist/export.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/dist/inline.js +0 -58
- package/dist/node_modules/@allyhub/report-extension/dist/page.js +0 -21
- package/dist/node_modules/@allyhub/report-extension/dist/project-tools.js +0 -21
- package/dist/node_modules/@allyhub/report-extension/dist/styles.js +0 -5
- package/dist/node_modules/@allyhub/report-extension/dist/theme.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/dist/tools.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/dist/workspace.js +0 -2
- package/dist/node_modules/@allyhub/report-extension/package.json +0 -182
- package/dist/node_modules/@allyhub/report-extension/styles/allyhub/STYLE.md +0 -139
- package/dist/node_modules/@allyhub/report-extension/styles/allyhub/style.css +0 -109
- package/dist/node_modules/@allyhub/report-extension/styles/allyhub/style.json +0 -17
- package/dist/node_modules/@allyhub/report-extension/styles/allyhub/tokens.js +0 -40
- package/editor-web/assets/channel-DuEnPkZu.js +0 -1
- package/editor-web/assets/dist-4inJBAbI.js +0 -24
- package/editor-web/assets/dist-B11DCgsH.js +0 -38
- package/editor-web/assets/dist-C18O6_l8.js +0 -1
- package/editor-web/assets/dist-C69j8GuG.js +0 -1
- package/editor-web/assets/dist-CbaaskK_.js +0 -6
- package/editor-web/assets/dist-Cr8czubC.js +0 -1
- package/editor-web/assets/dist-CyFisBsr.js +0 -45
- package/editor-web/assets/dist-D75YCIy5.js +0 -16
- package/editor-web/assets/dist-R8wzgFQU.js +0 -43
- package/editor-web/assets/flowDiagram-IUGLLWBU-D-udv3hH.js +0 -1
- package/editor-web/assets/index-BVal6wRX.css +0 -2
- package/editor-web/assets/palette-INFK0Zsr.js +0 -1
- package/editor-web/assets/scissors-DhC0iSGF.js +0 -1
- package/editor-web/assets/swatch-xE61Svqb.js +0 -1
- package/editor-web/assets/swimlanesDiagram-AYQRV4AK-Ckm9Zo5K.js +0 -8
- package/editor-web/assets/syntax-9LD8MzGy.js +0 -1
- package/editor-web/assets/tabs-DaoN-PPw.js +0 -1
- package/editor-web/assets/trash-2-DrnRa91l.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{existsSync as x}from"node:fs";import{mkdir as O,readFile as S,stat as T,writeFile as v}from"node:fs/promises";import{basename as b,dirname as z,join as f,posix as C,resolve as F}from"node:path";import{PROJECT_DIR as I,defineCliCommand as E,listWork as P,projectRoot as R}from"@allyhub/build";import{itemIdOf as W}from"@allyhub/formats";import{importPsd as D,keyOf as M}from"@allyhub/image-psd";import{CommandError as g,EXIT as u}from"@allyhub/protocol";import{z as m}from"zod";const N=m.string().transform(o=>o.replace(/^\/+/gu,"")).refine(o=>o.endsWith(".ts")&&!o.split("/").some(a=>a===""||a==="."||a===".."),{message:"a .ts file from the project's root, such as launch/poster.ts"}),A={approximate:"approximate",pixels:"as pixels",omitted:"not carried over"};export const imageImport=E({input:m.strictObject({file:m.string().describe("The .psd or .psb to make an image of"),to:N.optional().describe("The image's module, from the project's root (default <the file's name>.ts); a person's changes are <name>.yaml beside it, its script <name>.<lang>.yaml, its pictures and the file as it was beside them under names no file there has"),lang:m.string().regex(/^[a-z]{2,3}(-[a-z0-9]+)*$/u).default("en").describe("The language of its words: its script is <name>.<lang>.yaml"),dir:I}),positional:["file"],output:m.looseObject({}),examples:["allyhub image import ~/Downloads/poster.psd --to launch/poster.ts","allyhub image import 海报.psd --to posters/spring.ts --lang zh-cn"],run:async(o,a)=>{const c=await R(a.cwd,o.dir),r=F(a.cwd,o.file),k=await S(r).catch(()=>{throw new g("not-found",`There is no file ${r}.`,{exit:u.notFound})}),n=o.to??`${M(b(r).replace(/\.ps[db]$/iu,""),"image",new Set)}.ts`,w=C.dirname(n),l=e=>w==="."?e:`${w}/${e}`,d=W(n);let t;try{t=D(new Uint8Array(k),{id:d,lang:o.lang,source:b(r),taken:e=>x(f(c,l(e)))})}catch(e){throw new g("bad-file",`${r} is not a Photoshop file this can read: ${e.message}`,{exit:u.usage})}const $=[...t.files.keys()].map(l);for(const e of $)if(await T(f(c,e)).catch(()=>{}))throw new g("place-taken",`${e} is already there.`,{exit:u.conflict,hint:"Name another module with --to."});for(const[e,s]of t.files){const i=f(c,l(e));await O(z(i),{recursive:!0}),await v(i,s,{flag:"wx"})}await P(c,{kind:"image",file:n});const h=new Map;for(const e of t.report){const s=`${e.how}|${e.what}`,i=h.get(s)??{line:` ${A[e.how]}: ${e.what}`,at:[]},p=[e.board,e.layer].filter(j=>j!==void 0).join("/");p!==""&&!i.at.includes(p)&&i.at.push(p),h.set(s,i)}const y=[...h.values()].map(e=>`${e.line}${e.at.length===0?"":` (${e.at.slice(0,4).join(", ")}${e.at.length>4?` and ${String(e.at.length-4)} more`:""})`}`);return{value:{file:n,id:d,source:l(t.source),boards:t.boards.map(e=>({key:e.key,name:e.name,width:e.width,height:e.height,kinds:e.kinds})),files:$,report:t.report},text:[`Made ${n}: ${t.boards.map(e=>`${e.key} (${String(e.width)}×${String(e.height)}: ${Object.entries(e.kinds).map(([s,i])=>`${String(i)} ${s}`).join(", ")||"no layers"})`).join("; ")}; listed in allyhub.yaml as ${d}.`,`The file as it was: ${l(t.source)}`,...y.length>0?[`Not carried over as it is (${String(t.report.length)}, grouped; all with --json):`,...y]:[],`allyhub check, then allyhub frames ${d}, to see it.`].join(`
|
|
2
|
+
import{existsSync as x}from"node:fs";import{mkdir as O,readFile as S,stat as T,writeFile as v}from"node:fs/promises";import{basename as b,dirname as z,join as f,posix as C,resolve as F}from"node:path";import{PROJECT_DIR as I,defineCliCommand as E,listWork as P,projectRoot as R}from"@allyhub/build";import{itemIdOf as W}from"@allyhub/formats";import{importPsd as D,keyOf as M}from"@allyhub/image-psd";import{CommandError as g,EXIT as u}from"@allyhub/protocol";import{z as m}from"zod";const N=m.string().transform(o=>o.replace(/^\/+/gu,"")).refine(o=>o.endsWith(".ts")&&!o.split("/").some(a=>a===""||a==="."||a===".."),{message:"a .ts file from the project's root, such as launch/poster.ts"}),A={approximate:"approximate",pixels:"as pixels",omitted:"not carried over"};export const imageImport=E({input:m.strictObject({file:m.string().describe("The .psd or .psb to make an image of"),to:N.optional().describe("The image's module, from the project's root (default <the file's name>.ts); a person's changes are <name>.yaml beside it, its script <name>.<lang>.yaml, its pictures and the file as it was beside them under names no file there has"),lang:m.string().regex(/^[a-z]{2,3}(-[a-z0-9]+)*$/u).default("en").describe("The language of its words: its script is <name>.<lang>.yaml"),dir:I}),positional:["file"],output:m.looseObject({}),examples:["allyhub image import ~/Downloads/poster.psd --to launch/poster.ts","allyhub image import 海报.psd --to posters/spring.ts --lang zh-cn"],run:async(o,a)=>{const c=await R(a.cwd,o.dir),r=F(a.cwd,o.file),k=await S(r).catch(()=>{throw new g("not-found",`There is no file ${r}.`,{exit:u.notFound})}),n=o.to??`${M(b(r).replace(/\.ps[db]$/iu,""),"image",new Set)}.ts`,w=C.dirname(n),l=e=>w==="."?e:`${w}/${e}`,d=W(n);let t;try{t=await D(new Uint8Array(k),{id:d,lang:o.lang,source:b(r),taken:e=>x(f(c,l(e)))})}catch(e){throw new g("bad-file",`${r} is not a Photoshop file this can read: ${e.message}`,{exit:u.usage})}const $=[...t.files.keys()].map(l);for(const e of $)if(await T(f(c,e)).catch(()=>{}))throw new g("place-taken",`${e} is already there.`,{exit:u.conflict,hint:"Name another module with --to."});for(const[e,s]of t.files){const i=f(c,l(e));await O(z(i),{recursive:!0}),await v(i,s,{flag:"wx"})}await P(c,{kind:"image",file:n});const h=new Map;for(const e of t.report){const s=`${e.how}|${e.what}`,i=h.get(s)??{line:` ${A[e.how]}: ${e.what}`,at:[]},p=[e.board,e.layer].filter(j=>j!==void 0).join("/");p!==""&&!i.at.includes(p)&&i.at.push(p),h.set(s,i)}const y=[...h.values()].map(e=>`${e.line}${e.at.length===0?"":` (${e.at.slice(0,4).join(", ")}${e.at.length>4?` and ${String(e.at.length-4)} more`:""})`}`);return{value:{file:n,id:d,source:l(t.source),boards:t.boards.map(e=>({key:e.key,name:e.name,width:e.width,height:e.height,kinds:e.kinds})),files:$,report:t.report},text:[`Made ${n}: ${t.boards.map(e=>`${e.key} (${String(e.width)}×${String(e.height)}: ${Object.entries(e.kinds).map(([s,i])=>`${String(i)} ${s}`).join(", ")||"no layers"})`).join("; ")}; listed in allyhub.yaml as ${d}.`,`The file as it was: ${l(t.source)}`,...y.length>0?[`Not carried over as it is (${String(t.report.length)}, grouped; all with --json):`,...y]:[],`allyhub check, then allyhub frames ${d}, to see it.`].join(`
|
|
3
3
|
`)}}});const H={"image import":imageImport};export default H;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{mkdir as B,readdir as A,rm as K,writeFile as j}from"node:fs/promises";import{dirname as
|
|
2
|
+
import{mkdir as B,readdir as A,rm as K,writeFile as j}from"node:fs/promises";import{dirname as U,join as P,parse as q}from"node:path";import{PSD_DEFAULTS as X,trimmed as T,writeBoardPsd as Q}from"@allyhub/image-psd";import{cropImage as J,readPng as V}from"@allyhub/measure";import{finishPdf as W,pdfLib as H}from"@allyhub/image-render/pdf";import{zipSync as Y}from"fflate";export const IMAGE_EXPORT_DEFAULTS={jpegQuality:90,scale:1};const v={min:.25,max:4},L=16384,Z=["png","jpeg","webp"],tt=t=>Z.includes(t),M={png:"png",jpeg:"jpg",webp:"webp"},et=t=>typeof t=="number"&&Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):void 0,E=t=>{const e=typeof t=="number"?t:typeof t=="string"?Number(t.trim().replace(/[x×]$/iu,"")):Number.NaN;return Number.isFinite(e)&&e>0?e:void 0};export function scaleOf(t,e){const r=["scale","width","height"].filter(i=>t[i]!==void 0);if(r.length>1)return{code:"bad-param",message:`${r.join(" and ")} both size a board's picture.`,hint:"Give one: scale (2), width or height (pixels)."};const[a]=r;if(a===void 0)return IMAGE_EXPORT_DEFAULTS.scale;const d=E(t[a]);if(d===void 0)return{code:"bad-param",message:`${a} is ${JSON.stringify(t[a])}, not a positive number.`};const s=a==="scale"?d:d/(a==="width"?e.width:e.height),l=Math.round(e.width*s),u=Math.round(e.height*s);return s<v.min||s>v.max?{code:"bad-param",message:`Board ${e.key} (${String(e.width)}×${String(e.height)}) at ${a} ${String(d)} is drawn at ${String(Math.round(s*1e3)/1e3)}×, not from ${String(v.min)}× to ${String(v.max)}×.`,hint:"Change the board's size in the code for a picture further from it."}:Math.max(l,u)>L?{code:"bad-param",message:`Board ${e.key} at ${String(Math.round(s*1e3)/1e3)}× is ${String(l)}×${String(u)}, over ${String(L)} pixels a side.`}:s}async function _(t,e,r,a){return t.stage.capture({format:e,alpha:a,...e==="jpeg"?{quality:r??IMAGE_EXPORT_DEFAULTS.jpegQuality}:e==="webp"&&r!==void 0?{quality:r}:{}})}const C=t=>Math.round(t/1024*10)/10;async function G(t,e,r,a){const d=scaleOf(a.params,e);if(typeof d!="number")return d;const s=E(a.params.maxKb),l=t.timeline.parts.find(u=>u.key===e.key);await t.stage.rescale(d);try{await t.seek(l?.still??0);const u=et(a.params.quality),i=a.transparent&&r!=="jpeg",n=await _(t,r,u,i);if(s===void 0||n.length<=s*1024)return{bytes:n};if(r==="png")return{code:"over-size",message:`Board ${e.key}'s PNG is ${String(C(n.length))} KB, over ${String(s)} KB, and a PNG keeps every pixel.`,hint:"Export it as jpeg or webp, which find a quality under the size, or at a smaller scale."};let m=0,$=u??100,o;for(;m<=$;){const f=Math.floor((m+$)/2),h=await _(t,r,f,i);h.length<=s*1024?(o={bytes:h,picked:f},m=f+1):$=f-1}return o??{code:"over-size",message:`Board ${e.key}'s ${r} is over ${String(s)} KB at every quality.`,hint:"Export it at a smaller scale, or as another type."}}finally{await t.stage.rescale(1)}}const nt=`[...document.querySelectorAll("*")].some((el) => {
|
|
3
3
|
const f = getComputedStyle(el).backdropFilter;
|
|
4
4
|
return f !== "" && f !== "none" && el.checkVisibility();
|
|
5
|
-
})`,D=.75;async function at(t,e,
|
|
5
|
+
})`,D=.75;async function at(t,e,r,a){const{PDFDocument:d}=await H(),s=await d.create({updateMetadata:!1}),l=[];for(const i of e){const n=await t.another();try{const $=n.timeline.parts.find(p=>p.key===i.key)?.still??0;if(await n.seek($),await n.stage.page.evaluate(nt)){await n.stage.rescale(2);const p=await n.stage.capture({format:"png",alpha:a});s.addPage([i.width*D,i.height*D]).drawImage(await s.embedPng(p),{x:0,y:0,width:i.width*D,height:i.height*D}),l.push(i.key);continue}const o=await n.stage.print([{still:$,title:i.key,background:a?"transparent":n.timeline.background??"white"}],`${String(i.width)}px ${String(i.height)}px`,{width:i.width,height:i.height}),f=await d.load(o,{updateMetadata:!1}),[h]=await s.copyPages(f,[0]);h&&s.addPage(h)}finally{await n.close()}}return{bytes:await W(await s.save(),{...r===void 0?{}:{title:r},outline:e.map(i=>i.key)}),pictured:l}}function it(t){const e=t.piece.title;return typeof e=="string"?e:e===void 0?void 0:e[t.target.combo.lang??""]??Object.values(e)[0]}async function N(t,e,r){const a=V(await t.stage.capture({format:"png",alpha:r}));return a.width===e.width&&a.height===e.height?a:J(a,[0,0,e.width,e.height])??a}const R=t=>t.flatMap(e=>[e,...R(e.layers??[])]);async function st(t,e,r,a){const d=t.timeline.parts.find(i=>i.key===e.key);await t.seek(d?.still??0);const s=await N(t,e,!0),l=new Map,u=new Map;try{for(const i of R(r.layers)){if(i.pixels){await t.stage.call("psdDraw",e.key,i.key,"pixels");const n=T(await N(t,e,!0));n&&l.set(i.key,n)}if(i.mask?.kind==="raster"){await t.stage.call("psdDraw",e.key,i.key,"mask");const n=T(await N(t,e,!1),0);n&&u.set(i.key,n)}}}finally{await t.stage.call("psdDraw",null)}return await Q(r,{composite:s,layers:l,masks:u},{format:a})}export async function renderImage(t){const e=t.version;if(!e)throw new Error("An image's files are made from a version.");const r=e.version,a=await r.stage.call("boards"),d=e.piece.options.transparent===!0,s=[];let l=0;const u=t.types.length*Math.max(1,a.length),i=()=>{l++,t.onProgress?.(Math.min(1,l/u))};for(const n of t.types){t.signal?.throwIfAborted();const m=t.out(n);await B(U(m),{recursive:!0});const $={transparent:d,params:t.params,...t.signal?{signal:t.signal}:{}};if(tt(n)){const{dir:o,name:f}=q(m),h=P(o,f);await B(h,{recursive:!0});const p=new Set(a.map(g=>`${g.key}.${M[n]}`));for(const g of await A(h))g.endsWith(`.${M[n]}`)&&!p.has(g)&&await K(P(h,g),{force:!0});const y=[],x=[],S={};let k;for(const g of a){const w=await G(r,g,n,$);if(i(),!("bytes"in w)){k=w;break}const c=P(h,`${g.key}.${M[n]}`);await j(c,w.bytes),y.push(c),S[g.key]=c,w.picked!==void 0&&x.push(`${f}/${g.key}.${M[n]} at quality ${String(w.picked)}, ${String(C(w.bytes.length))} KB, under the ${String(E(t.params.maxKb))} KB asked`)}s.push(k?{type:n,failure:k}:{type:n,files:y,partFiles:S,...x.length>0?{chosen:x}:{}});continue}if(n==="zip"){const o={};let f;for(const p of a){const y=await G(r,p,"png",{...$,params:{...$.params,maxKb:void 0}});if(i(),!("bytes"in y)){f=y;break}o[`${p.key}.${M.png}`]=y.bytes}if(f){s.push({type:n,failure:f});continue}const h=Y(Object.fromEntries(Object.entries(o).map(([p,y])=>[p,[y,{level:0,mtime:new Date(1980,0,1)}]])));await j(m,h),s.push({type:n,files:[m]});continue}if(n==="pdf"){const o=await at(e,a,it(e),d);await j(m,o.bytes),l+=a.length,t.onProgress?.(Math.min(1,l/u)),s.push({type:n,files:[m],...o.pictured.length>0?{notes:[`${o.pictured.join(", ")} ${o.pictured.length===1?"is a picture":"are pictures"} in the PDF, ${o.pictured.length===1?"its":"their"} text as pixels: an adjustment (a backdrop-filter) is left out where a PDF is printed.`]}:{}});continue}if(n==="psd"){const o=t.params.psd==="psb"?"psb":X.format,{dir:f,name:h}=q(m),p=P(f,h);await B(p,{recursive:!0});const y=new Set(a.map(c=>`${c.key}.${o}`));for(const c of await A(p))/\.ps[db]$/u.test(c)&&!y.has(c)&&await K(P(p,c),{force:!0});const x=await r.stage.call("psdBoards"),S=[],k=[],g=new Set,w=[];for(const c of a){const F=x.find(b=>b.key===c.key);if(!F){w.push(c.key);continue}const I=P(p,`${c.key}.${o}`),O=await st(r,c,F,o);await j(I,O.bytes),S.push(I);for(const b of O.fidelity){const z=`${b.how}|${b.what}|${b.layer??""}`;g.has(z)||(g.add(z),k.push({...b,...b.layer===void 0?{}:{layer:`${c.key}/${b.layer}`}}))}i()}if(S.length===0){s.push({type:n,failure:{code:"psd-unread",message:`No board's layers could be read for a PSD (${w.join(", ")}).`}});continue}s.push({type:n,files:S,...k.length>0?{fidelity:k}:{},...w.length>0?{notes:w.map(c=>`Board ${c} is not in a PSD: its layers could not be read.`)}:{}});continue}s.push({type:n,failure:{code:"bad-type",message:`An image is not made as ${n}.`,hint:"Its types: png, jpeg, webp, pdf, zip, psd."}})}return s}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
+
import{firstUse as e}from"@allyhub/runtimes";export const agPsd=e("ag-psd",async()=>await import("ag-psd"));let r=!1;export async function psdLib(){const a=await agPsd();if(!r){const i=(s,t)=>({width:s,height:t,data:new Uint8ClampedArray(s*t*4),colorSpace:"srgb"});a.initializeCanvas(()=>{throw new Error("ag-psd asked for a canvas: AllyHub gives it pixels as data.")},i),r=!0}return a}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{initializeCanvas as me,readPsd as Y}from"ag-psd";import{writePng as Q}from"@allyhub/measure";import{adjustmentRefusal as ge,refusalOf as be}from"@allyhub/piece";import{stringify as ye}from"yaml";import{blendOf as P,gradientOf as V,hexOf as X,justificationOf as we,pathOf as ee,pxOf as te,transformPath as ne}from"./map.js";const xe=e=>e.slice(e.lastIndexOf("/")+1);function ie(e,s,n){const t=o=>e.files.has(o)||(e.o.taken?.(o)??!1);let i=`${s}${n}`;for(let o=2;t(i);o++)i=`${s}-${String(o)}${n}`;return i}let se=!1;function oe(){if(se)return;me(()=>{throw new Error("ag-psd asked for a canvas: AllyHub reads pixels as data.")},(s,n)=>({width:s,height:n,data:new Uint8ClampedArray(s*n*4),colorSpace:"srgb"})),se=!0}export function keyOf(e,s,n){const t=e.normalize("NFKD").replace(/[̀-ͯ]/gu,"").toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,48).replace(/-+$/u,"")||s;let i=t;for(let o=2;n.has(i);o++)i=`${t}-${String(o)}`;return n.add(i),i}const T=e=>e===void 0?void 0:Math.round(e*1e3)/10,j=e=>Math.round(e*1e3)/1e3,L=(e,s)=>Math.round(e/s*1e6)/1e6;export function fontOf(e){const[s=e,n=""]=e.split("-"),t=/italic|oblique/iu.test(n),i=n.toLowerCase().replace(/italic|oblique/gu,""),o=/thin|hairline/u.test(i)?100:/extralight|ultralight/u.test(i)?200:/semibold|demibold/u.test(i)?600:/extrabold|ultrabold/u.test(i)?800:/black|heavy/u.test(i)?900:i.includes("light")?300:i.includes("medium")?500:i.includes("bold")?700:400;return{family:s.replace(/(PS)?MT$|PS$/u,"").replace(/([a-z])([A-Z])/gu,"$1 $2").trim()||s,weight:o,italic:t}}const g=(e,s,n,t)=>{e.notes.push({how:s,what:n,board:e.board,...t===void 0?{}:{layer:t}})};function ke(e,s){const n=e.imageData;if(!n||n.width===0||n.height===0)return;const t=(e.left??0)-s.frame.left,i=(e.top??0)-s.frame.top,o=Math.max(0,t),a=Math.max(0,i),d=Math.min(s.frame.width,t+n.width),c=Math.min(s.frame.height,i+n.height);if(d<=o||c<=a)return;const m=d-o,l=c-a,u=new Uint8Array(m*l*4);let f=!1;for(let b=0;b<l;b++)for(let $=0;$<m;$++){const p=((b+a-i)*n.width+($+o-t))*4,x=(b*m+$)*4;u[x]=n.data[p]??0,u[x+1]=n.data[p+1]??0,u[x+2]=n.data[p+2]??0,u[x+3]=n.data[p+3]??0,u[x+3]!==0&&(f=!0)}if(f)return{img:{width:m,height:l,data:u},box:[o,a,m,l]}}function ae(e,s,n,t){const i=ie(e,`${e.board}-${s}${n}`,".png");e.files.set(i,new Uint8Array(Q(t)));let a=`${e.board} ${s} ${n}`.split(/[^A-Za-z0-9]+/u).filter(c=>c!=="").map((c,m)=>m===0?c.toLowerCase():c.charAt(0).toUpperCase()+c.slice(1)).join("");/^[A-Za-z_]/u.test(a)||(a=`_${a}`);const d=a;for(let c=2;e.imports.some(m=>m.name===a);c++)a=`${d}${String(c)}`;return e.imports.push({name:a,path:`./${i}`}),a}class U{name;constructor(s){this.name=s}}const $e=(e,s,n)=>[L(s[0]??0,n.frame.width),L(s[1]??0,n.frame.height),L(e.width,n.frame.width),L(e.height,n.frame.height)];function C(e,s,n){const t=X(s);return t.converted&&g(e,"approximate",`a ${t.converted} colour converted to sRGB without its profile`,n),t.hex}function re(e,s,n,t={}){if(!s||!("colorStops"in s))return;const i=V(s);i.converted&&g(e,"approximate",`a gradient's ${i.converted} colours converted to sRGB without a profile`,n);const o=t.style;return{stops:i.stops.length>=2?i.stops:[...i.stops,...i.stops].slice(0,2),...o===void 0||o==="linear"?{}:{style:o},...t.angle===void 0||t.angle===90?{}:{angle:j(t.angle)},...t.scale===void 0||Math.abs(t.scale-1)<1e-6?{}:{scale:Math.max(10,Math.min(1e3,Math.round(t.scale*100)))},...t.reverse===!0?{reverse:!0}:{}}}function de(e,s,n){if(s){if(s.type==="color")return{color:C(e,s.color,n)};if(s.type==="solid"){const t=re(e,s,n,{...s.style===void 0?{}:{style:s.style},...s.angle===void 0?{}:{angle:s.angle},...s.scale===void 0?{}:{scale:s.scale},...s.reverse===void 0?{}:{reverse:s.reverse}});return t?{gradient:t}:void 0}}}const Me=e=>e===void 0||e.name==="Linear"||Array.isArray(e.curve)&&e.curve.length<=2;function ve(e,s,n){const t={},i=e.ppi,o=s.scale??1,a=r=>{const y=te(r,i);return y===void 0?void 0:Math.max(0,Math.min(1e3,j(y*o)))},d=r=>r?.present===!1?void 0:r,c=r=>({...r.enabled===!1?{enabled:!1}:{},...P(r.blendMode)===void 0?{}:{blendMode:P(r.blendMode)},...r.opacity===void 0?{}:{opacity:T(r.opacity)}}),m=(r,y)=>{const O=y?.filter(h=>h.present!==!1);return O&&O.length>1&&g(e,"omitted",`${String(O.length-1)} more ${r} effects: AllyHub's layer has one of each`,n),O?.[0]},l=(r,y)=>{Me(y)||g(e,"omitted",`the ${r}'s contour (${y?.name??"custom"}): drawn linear`,n)},u=m("drop shadow",s.dropShadow);u&&(l("drop shadow",u.contour),t.dropShadow={...c(u),...u.color?{color:C(e,u.color,n)}:{},...u.angle===void 0?{}:{angle:j(u.angle)},...a(u.distance)===void 0?{}:{distance:a(u.distance)},...u.choke?{spread:Math.min(100,j(u.choke.value))}:{},...a(u.size)===void 0?{}:{size:a(u.size)}});const f=m("inner shadow",s.innerShadow);f&&(l("inner shadow",f.contour),t.innerShadow={...c(f),...f.color?{color:C(e,f.color,n)}:{},...f.angle===void 0?{}:{angle:j(f.angle)},...a(f.distance)===void 0?{}:{distance:a(f.distance)},...f.choke?{choke:Math.min(100,j(f.choke.value))}:{},...a(f.size)===void 0?{}:{size:a(f.size)}});const b=d(s.outerGlow);if(b){const r=b;l("outer glow",r.contour),r.gradient&&g(e,"omitted","the outer glow's gradient: drawn in its colour",n),t.outerGlow={...c(r),...r.color?{color:C(e,r.color,n)}:{},...r.choke?{spread:Math.min(100,j(r.choke.value))}:{},...a(r.size)===void 0?{}:{size:a(r.size)}}}const $=d(s.innerGlow);if($){const r=$;l("inner glow",r.contour),r.gradient&&g(e,"omitted","the inner glow's gradient: drawn in its colour",n),t.innerGlow={...c(r),...r.color?{color:C(e,r.color,n)}:{},...r.choke?{choke:Math.min(100,j(r.choke.value))}:{},...a(r.size)===void 0?{}:{size:a(r.size)},...r.source?{source:r.source}:{}}}const p=m("stroke",s.stroke);p&&(p.fillType!==void 0&&p.fillType!=="color"&&g(e,"approximate",`the stroke's ${p.fillType} fill: drawn in its first colour`,n),t.stroke={...c(p),...p.color?{color:C(e,p.color,n)}:{},...a(p.size)===void 0?{}:{size:a(p.size)},...p.position?{position:p.position}:{}});const x=m("colour overlay",s.solidFill);x&&(t.colorOverlay={...c(x),...x.color?{color:C(e,x.color,n)}:{}});const w=m("gradient overlay",s.gradientOverlay);if(w){const r=re(e,w.gradient,n,{...w.type===void 0?{}:{style:w.type},...w.angle===void 0?{}:{angle:w.angle},...w.scale===void 0?{}:{scale:w.scale},...w.reverse===void 0?{}:{reverse:w.reverse}});r?t.gradientOverlay={...c(w),gradient:r}:g(e,"omitted","a gradient overlay of a noise gradient",n)}d(s.patternOverlay)&&g(e,"omitted","the pattern overlay: its pattern's pixels are the file's, which ag-psd does not read out",n);const S=d(s.satin);if(S){const r=S;l("satin",r.contour),t.satin={...c(r),...r.color?{color:C(e,r.color,n)}:{},...r.angle===void 0?{}:{angle:j(r.angle)},...a(r.distance)===void 0?{}:{distance:a(r.distance)},...a(r.size)===void 0?{}:{size:a(r.size)},...r.invert===void 0?{}:{invert:r.invert}}}const M=d(s.bevel);if(M){const r=M,y=r.style===void 0?void 0:{"inner bevel":"innerBevel","outer bevel":"outerBevel",emboss:"emboss","pillow emboss":"pillowEmboss","stroke emboss":"strokeEmboss"}[r.style],O=r.technique===void 0?void 0:{smooth:"smooth","chisel hard":"chiselHard","chisel soft":"chiselSoft"}[r.technique];t.bevelEmboss={...r.enabled===!1?{enabled:!1}:{},...y?{style:y}:{},...O?{technique:O}:{},...r.strength===void 0?{}:{depth:Math.max(1,Math.min(1e3,Math.round(r.strength*100)))},...r.direction?{direction:r.direction}:{},...a(r.size)===void 0?{}:{size:a(r.size)},...a(r.soften)===void 0?{}:{soften:a(r.soften)},...r.angle===void 0?{}:{angle:j(r.angle)},...r.altitude===void 0?{}:{altitude:j(r.altitude)},...P(r.highlightBlendMode)?{highlightMode:P(r.highlightBlendMode)}:{},...r.highlightColor?{highlightColor:C(e,r.highlightColor,n)}:{},...r.highlightOpacity===void 0?{}:{highlightOpacity:T(r.highlightOpacity)},...P(r.shadowBlendMode)?{shadowMode:P(r.shadowBlendMode)}:{},...r.shadowColor?{shadowColor:C(e,r.shadowColor,n)}:{},...r.shadowOpacity===void 0?{}:{shadowOpacity:T(r.shadowOpacity)}}}if(s.disabled===!0)for(const r of Object.values(t))r.enabled=!1;return Object.keys(t).length>0?t:void 0}function Oe(e,s,n,t){const i={...s};for(let o=0;o<24;o++){const a=be(i,n);if(a===void 0)break;const d=/effects\.(\w+)/u.exec(a)?.[1],c=i.effects,m=/^effects\.(dropShadow|outerGlow)\.blendMode/u.exec(a)?.[1],l=m===void 0?void 0:c?.[m];if(m&&c&&typeof l=="object"&&l!==null){c[m]={...l,blendMode:"normal"},g(e,"approximate",`the ${m}'s blend mode: AllyHub draws an effect under its layer as normal (a layer's filter cannot read what lies under it), so it is written normal`,t);continue}if(d&&c&&d in c){const u=Object.fromEntries(Object.entries(c).filter(([f])=>f!==d));Object.keys(u).length>0?i.effects=u:delete i.effects,g(e,"omitted",`the ${d} effect: ${a}`,t);continue}if(a.startsWith("an adjustment has no effects")||c&&a.includes("stroke")){if(c&&a.includes("stroke")){const u=Object.fromEntries(Object.entries(c).filter(([f])=>f!=="stroke"));Object.keys(u).length>0?i.effects=u:delete i.effects,g(e,"omitted",`the stroke effect: ${a}`,t)}else delete i.effects,g(e,"omitted",`its effects: ${a}`,t);continue}if(a.includes("fillOpacity")&&i.fillOpacity!==void 0){g(e,"approximate",`its fill opacity ${JSON.stringify(i.fillOpacity)}: ${a}; drawn at 100`,t),delete i.fillOpacity;continue}if(a.includes("blendMode")&&i.blendMode!==void 0){g(e,"approximate",`its blend mode: ${a}; drawn as normal`,t),i.blendMode=n==="group"?"passThrough":"normal",n!=="group"&&delete i.blendMode;continue}g(e,"omitted",`its style: ${a}`,t),delete i.effects,delete i.blendMode,delete i.fillOpacity}return i}function H(e,s,n,t){const i=s.mask??s.realMask,o=i?.imageData&&i.imageData.width>0&&i.imageData.height>0?i:void 0,a=s.vectorMask&&s.vectorMask.paths.length>0?s.vectorMask:void 0,[d,c,m,l]=t.box.map(Math.round),u=(f,b,$)=>({...f===void 0||Math.abs(f-1)<1e-6?{}:{density:T(f)},...b===void 0||b===0?{}:{feather:Math.min(1e3,j(b))},...$===!0?{enabled:!1}:{}});if(o?.imageData){const f=o.imageData,b=new Uint8Array(m*l*4),$=o.defaultColor??0,p=(o.left??0)-e.frame.left,x=(o.top??0)-e.frame.top;for(let w=0;w<l;w++)for(let S=0;S<m;S++){const M=S+d-p,r=w+c-x,y=M>=0&&r>=0&&M<f.width&&r<f.height?f.data[(r*f.width+M)*4]??0:$,O=(w*m+S)*4;b[O]=y,b[O+1]=y,b[O+2]=y,b[O+3]=255}return a&&g(e,"omitted","its vector mask, beside its raster mask: AllyHub's layer has one mask",n),(o.userMaskFeather??0)>0&&g(e,"approximate","its mask's feather: Photoshop's radius taken as a Gaussian's standard deviation",n),{src:new U(ae(e,n,".mask",{width:m,height:l,data:b})),mode:"luminance",...u(o.userMaskDensity,o.userMaskFeather,o.disabled)}}if(a){const f=ne(ee(a.paths),[1,0,0,1,-e.frame.left-d,-e.frame.top-c]);return a.paths.length>1&&a.paths.some(b=>b.fillRule==="even-odd"||b.operation!==void 0&&b.operation!=="combine")&&g(e,"approximate","its vector mask's subpaths subtract, intersect or exclude, or fill even-odd: drawn as one path, non-zero",n),(s.mask?.vectorMaskFeather??0)>0&&g(e,"approximate","its vector mask's feather: Photoshop's radius taken as a Gaussian's standard deviation",n),{path:f,...a.invert===!0?{invert:!0}:{},...u(s.mask?.vectorMaskDensity,s.mask?.vectorMaskFeather,a.disable)}}}function R(e,s,n,t){const i=P(s.blendMode);s.blendMode!==void 0&&i===void 0&&g(e,"approximate",`its blend mode ${s.blendMode} (Photoshop's 3D): drawn as normal`,t);const o=T(s.opacity),a=T(s.fillOpacity),d=s.effects?ve(e,s.effects,t):void 0;return Oe(e,{...i===void 0||i===(n==="group"?"passThrough":"normal")?{}:{blendMode:i},...o===void 0||o===100?{}:{opacity:o},...a===void 0||a===100?{}:{fillOpacity:a},...s.clipping===!0?{clipping:!0}:{},...d?{effects:d}:{},...s.hidden===!0?{visible:!1}:{}},n,t)}function Se(e,s,n){const t=s.adjustment;if(!t)return;const i=o=>{g(e,"omitted",o,n)};switch(t.type){case"levels":{const o=["rgb","red","green","blue"],a={kind:"levels"};return(t.channels??[]).slice(0,4).forEach((d,c)=>{const m=o[c];if(!m)return;const l={...d.shadowInput===0?{}:{inputBlack:d.shadowInput},...d.highlightInput===255?{}:{inputWhite:d.highlightInput},...d.midtoneInput===1?{}:{gamma:Math.max(.1,Math.min(9.99,d.midtoneInput))},...d.shadowOutput===0?{}:{outputBlack:d.shadowOutput},...d.highlightOutput===255?{}:{outputWhite:d.highlightOutput}};Object.keys(l).length>0&&(a[m]=l)}),a}case"curves":{if(t.values?.some(d=>d.length>0)){i("a Curves drawn with the pencil (a table, not points): AllyHub's curves take points");return}const o=["rgb","red","green","blue"],a={kind:"curves"};return(t.channels??[]).slice(0,4).forEach((d,c)=>{const m=o[c];!m||d.length<2||(a[m]=d.slice(0,16).map(l=>[Math.round(l.input),Math.round(l.output)]))}),a}case"brightness/contrast":return t.useLegacy===!1&&g(e,"approximate","Brightness/Contrast's current algorithm, which Photoshop does not publish: drawn by the legacy one",n),{kind:"brightnessContrast",...t.brightness?{brightness:Math.max(-150,Math.min(150,t.brightness))}:{},...t.contrast?{contrast:Math.max(-50,Math.min(100,t.contrast))}:{}};case"hue/saturation":{if(t.colorize===!0){i("a colorizing Hue/Saturation: AllyHub does not draw colorize yet");return}["reds","yellows","greens","cyans","blues","magentas"].some(d=>{const c=t[d];return c!==void 0&&(c.hue!==0||c.saturation!==0||c.lightness!==0)})&&g(e,"omitted","Hue/Saturation's colour ranges: their own hue, saturation and lightness",n);const a=t.master;return{kind:"hueSaturation",...a?.hue?{hue:a.hue}:{},...a?.saturation?{saturation:a.saturation}:{},...a?.lightness?{lightness:a.lightness}:{}}}case"vibrance":return{kind:"vibrance",...t.vibrance?{vibrance:t.vibrance}:{},...t.saturation?{saturation:t.saturation}:{}};case"color balance":{const o=a=>a?[a.cyanRed,a.magentaGreen,a.yellowBlue]:void 0;return{kind:"colorBalance",...t.shadows?{shadows:o(t.shadows)}:{},...t.midtones?{midtones:o(t.midtones)}:{},...t.highlights?{highlights:o(t.highlights)}:{},...t.preserveLuminosity===!1?{preserveLuminosity:!1}:{}}}case"black & white":return t.useTint===!0&&g(e,"omitted","Black & White's tint",n),{kind:"blackAndWhite",...Object.fromEntries(["reds","yellows","greens","cyans","blues","magentas"].filter(o=>t[o]!==void 0).map(o=>[o,t[o]]))};case"photo filter":return{kind:"photoFilter",...t.color?{color:C(e,t.color,n)}:{},...t.density===void 0?{}:{density:T(t.density)},...t.preserveLuminosity===void 0?{}:{preserveLuminosity:t.preserveLuminosity}};case"invert":return{kind:"invert"};case"threshold":return{kind:"threshold",...t.level===void 0?{}:{level:Math.max(1,Math.min(255,Math.round(t.level)))}};case"gradient map":{if(t.gradientType!=="solid"||!t.colorStops){i("a Gradient Map of a noise gradient");return}const o=V({type:"solid",name:t.name??"",colorStops:t.colorStops.map(a=>({...a,location:a.location/4096})),opacityStops:(t.opacityStops??[]).map(a=>({...a,location:a.location/4096}))});return{kind:"gradientMap",gradient:{stops:o.stops.length>=2?o.stops:[...o.stops,...o.stops].slice(0,2)},...t.reverse===!0?{reverse:!0}:{}}}case"exposure":return{kind:"exposure",...t.exposure?{exposure:t.exposure}:{},...t.offset?{offset:t.offset}:{},...t.gamma!==void 0&&t.gamma!==1?{gammaCorrection:t.gamma}:{}};default:{i(`a ${t.type} adjustment: AllyHub's adjustments do not hold it`);return}}}function je(e,s,n){const t=s.text;if(!t)return;const i=e.ppi,o=I=>j(I*i/72),[a=1,d=0,c=0,m=1,l=0,u=0]=t.transform??[],f=Math.sqrt(a*a+d*d),b=Math.atan2(d,a)*180/Math.PI;(Math.abs(f-Math.sqrt(c*c+m*m))>.001||Math.abs(a*c+d*m)>.001)&&g(e,"approximate","its text is skewed or stretched: drawn at its average scale",n);const $=t.style??{};(t.styleRuns?.length??0)>1&&g(e,"approximate",`its ${String(t.styleRuns?.length??0)} style runs: drawn in its first style`,n),(t.paragraphStyleRuns?.length??0)>1&&g(e,"approximate","its paragraphs' own styles: drawn in the first paragraph's",n),t.orientation==="vertical"&&g(e,"approximate","its vertical text: drawn horizontal",n),t.warp?.style!==void 0&&t.warp.style!=="none"&&g(e,"omitted",`its warp (${t.warp.style})`,n);const p={...$,...t.styleRuns?.[0]?.style??{}},x=p.font?.name?fontOf(p.font.name):void 0,w=p.fontSize===void 0?void 0:o(p.fontSize*f);p.fauxBold===!0&&g(e,"approximate","its faux bold: drawn at weight 700",n),p.fauxItalic===!0&&g(e,"approximate","its faux italic: drawn italic",n),p.horizontalScale!==void 0&&Math.abs(p.horizontalScale-1)>.001&&g(e,"omitted","its horizontal scale",n);const S={...x?{font:x.family}:{},...x&&(x.weight!==400||p.fauxBold===!0)?{weight:p.fauxBold===!0?700:x.weight}:{},...x?.italic===!0||p.fauxItalic===!0?{italic:!0}:{},...w===void 0?{}:{size:Math.max(1,Math.min(4096,w))},...p.fillColor?{color:C(e,p.fillColor,n)}:{},...p.tracking?{tracking:Math.max(-1e3,Math.min(1e4,p.tracking))}:{},...p.autoLeading===!1&&p.leading!==void 0?{leading:o(p.leading*f)}:{},...p.fontCaps===2?{capitalization:"allCaps"}:p.fontCaps===1?{capitalization:"smallCaps"}:{},...p.underline===!0?{underline:!0}:{},...p.strikethrough===!0?{strikeThrough:!0}:{}},M={...t.paragraphStyle??{},...t.paragraphStyleRuns?.[0]?.style??{}},r=we(M.justification),y=I=>I===void 0||I===0?void 0:o(I*f),O={...r===void 0||r==="left"?{}:{justification:r},...y(M.firstLineIndent)===void 0?{}:{firstLineIndent:y(M.firstLineIndent)},...y(M.startIndent)===void 0?{}:{leftIndent:Math.max(0,y(M.startIndent)??0)},...y(M.endIndent)===void 0?{}:{rightIndent:Math.max(0,y(M.endIndent)??0)},...y(M.spaceBefore)===void 0?{}:{spaceBefore:y(M.spaceBefore)},...y(M.spaceAfter)===void 0?{}:{spaceAfter:y(M.spaceAfter)}};t.text.includes("")&&g(e,"approximate","its line breaks inside a paragraph: each starts a paragraph, with the paragraph's spacing",n);const h=t.text.replace(/\r\n?/gu,`
|
|
2
|
+
import{writePng as Q}from"@allyhub/measure";import{adjustmentRefusal as fe,refusalOf as pe}from"@allyhub/piece";import{stringify as me}from"yaml";import{psdLib as V}from"./ag-psd.js";import{blendOf as R,gradientOf as X,hexOf as ee,justificationOf as ge,pathOf as te,pxOf as ne,transformPath as ie}from"./map.js";const be=e=>e.slice(e.lastIndexOf("/")+1);function se(e,i,s){const t=n=>e.files.has(n)||(e.o.taken?.(n)??!1);let a=`${i}${s}`;for(let n=2;t(a);n++)a=`${i}-${String(n)}${s}`;return a}export function keyOf(e,i,s){const t=e.normalize("NFKD").replace(/[̀-ͯ]/gu,"").toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,48).replace(/-+$/u,"")||i;let a=t;for(let n=2;s.has(a);n++)a=`${t}-${String(n)}`;return s.add(a),a}const T=e=>e===void 0?void 0:Math.round(e*1e3)/10,z=e=>Math.round(e*1e3)/1e3,L=(e,i)=>Math.round(e/i*1e6)/1e6;export function fontOf(e){const[i=e,s=""]=e.split("-"),t=/italic|oblique/iu.test(s),a=s.toLowerCase().replace(/italic|oblique/gu,""),n=/thin|hairline/u.test(a)?100:/extralight|ultralight/u.test(a)?200:/semibold|demibold/u.test(a)?600:/extrabold|ultrabold/u.test(a)?800:/black|heavy/u.test(a)?900:a.includes("light")?300:a.includes("medium")?500:a.includes("bold")?700:400;return{family:i.replace(/(PS)?MT$|PS$/u,"").replace(/([a-z])([A-Z])/gu,"$1 $2").trim()||i,weight:n,italic:t}}const g=(e,i,s,t)=>{e.notes.push({how:i,what:s,board:e.board,...t===void 0?{}:{layer:t}})};function ye(e,i){const s=e.imageData;if(!s||s.width===0||s.height===0)return;const t=(e.left??0)-i.frame.left,a=(e.top??0)-i.frame.top,n=Math.max(0,t),o=Math.max(0,a),d=Math.min(i.frame.width,t+s.width),c=Math.min(i.frame.height,a+s.height);if(d<=n||c<=o)return;const p=d-n,h=c-o,u=new Uint8Array(p*h*4);let l=!1;for(let b=0;b<h;b++)for(let v=0;v<p;v++){const f=((b+o-a)*s.width+(v+n-t))*4,x=(b*p+v)*4;u[x]=s.data[f]??0,u[x+1]=s.data[f+1]??0,u[x+2]=s.data[f+2]??0,u[x+3]=s.data[f+3]??0,u[x+3]!==0&&(l=!0)}if(l)return{img:{width:p,height:h,data:u},box:[n,o,p,h]}}function oe(e,i,s,t){const a=se(e,`${e.board}-${i}${s}`,".png");e.files.set(a,new Uint8Array(Q(t)));let o=`${e.board} ${i} ${s}`.split(/[^A-Za-z0-9]+/u).filter(c=>c!=="").map((c,p)=>p===0?c.toLowerCase():c.charAt(0).toUpperCase()+c.slice(1)).join("");/^[A-Za-z_]/u.test(o)||(o=`_${o}`);const d=o;for(let c=2;e.imports.some(p=>p.name===o);c++)o=`${d}${String(c)}`;return e.imports.push({name:o,path:`./${a}`}),o}class U{name;constructor(i){this.name=i}}const we=(e,i,s)=>[L(i[0]??0,s.frame.width),L(i[1]??0,s.frame.height),L(e.width,s.frame.width),L(e.height,s.frame.height)];function C(e,i,s){const t=ee(i);return t.converted&&g(e,"approximate",`a ${t.converted} colour converted to sRGB without its profile`,s),t.hex}function ae(e,i,s,t={}){if(!i||!("colorStops"in i))return;const a=X(i);a.converted&&g(e,"approximate",`a gradient's ${a.converted} colours converted to sRGB without a profile`,s);const n=t.style;return{stops:a.stops.length>=2?a.stops:[...a.stops,...a.stops].slice(0,2),...n===void 0||n==="linear"?{}:{style:n},...t.angle===void 0||t.angle===90?{}:{angle:z(t.angle)},...t.scale===void 0||Math.abs(t.scale-1)<1e-6?{}:{scale:Math.max(10,Math.min(1e3,Math.round(t.scale*100)))},...t.reverse===!0?{reverse:!0}:{}}}function re(e,i,s){if(i){if(i.type==="color")return{color:C(e,i.color,s)};if(i.type==="solid"){const t=ae(e,i,s,{...i.style===void 0?{}:{style:i.style},...i.angle===void 0?{}:{angle:i.angle},...i.scale===void 0?{}:{scale:i.scale},...i.reverse===void 0?{}:{reverse:i.reverse}});return t?{gradient:t}:void 0}}}const xe=e=>e===void 0||e.name==="Linear"||Array.isArray(e.curve)&&e.curve.length<=2;function ke(e,i,s){const t={},a=e.ppi,n=i.scale??1,o=r=>{const y=ne(r,a);return y===void 0?void 0:Math.max(0,Math.min(1e3,z(y*n)))},d=r=>r?.present===!1?void 0:r,c=r=>({...r.enabled===!1?{enabled:!1}:{},...R(r.blendMode)===void 0?{}:{blendMode:R(r.blendMode)},...r.opacity===void 0?{}:{opacity:T(r.opacity)}}),p=(r,y)=>{const O=y?.filter(B=>B.present!==!1);return O&&O.length>1&&g(e,"omitted",`${String(O.length-1)} more ${r} effects: AllyHub's layer has one of each`,s),O?.[0]},h=(r,y)=>{xe(y)||g(e,"omitted",`the ${r}'s contour (${y?.name??"custom"}): drawn linear`,s)},u=p("drop shadow",i.dropShadow);u&&(h("drop shadow",u.contour),t.dropShadow={...c(u),...u.color?{color:C(e,u.color,s)}:{},...u.angle===void 0?{}:{angle:z(u.angle)},...o(u.distance)===void 0?{}:{distance:o(u.distance)},...u.choke?{spread:Math.min(100,z(u.choke.value))}:{},...o(u.size)===void 0?{}:{size:o(u.size)}});const l=p("inner shadow",i.innerShadow);l&&(h("inner shadow",l.contour),t.innerShadow={...c(l),...l.color?{color:C(e,l.color,s)}:{},...l.angle===void 0?{}:{angle:z(l.angle)},...o(l.distance)===void 0?{}:{distance:o(l.distance)},...l.choke?{choke:Math.min(100,z(l.choke.value))}:{},...o(l.size)===void 0?{}:{size:o(l.size)}});const b=d(i.outerGlow);if(b){const r=b;h("outer glow",r.contour),r.gradient&&g(e,"omitted","the outer glow's gradient: drawn in its colour",s),t.outerGlow={...c(r),...r.color?{color:C(e,r.color,s)}:{},...r.choke?{spread:Math.min(100,z(r.choke.value))}:{},...o(r.size)===void 0?{}:{size:o(r.size)}}}const v=d(i.innerGlow);if(v){const r=v;h("inner glow",r.contour),r.gradient&&g(e,"omitted","the inner glow's gradient: drawn in its colour",s),t.innerGlow={...c(r),...r.color?{color:C(e,r.color,s)}:{},...r.choke?{choke:Math.min(100,z(r.choke.value))}:{},...o(r.size)===void 0?{}:{size:o(r.size)},...r.source?{source:r.source}:{}}}const f=p("stroke",i.stroke);f&&(f.fillType!==void 0&&f.fillType!=="color"&&g(e,"approximate",`the stroke's ${f.fillType} fill: drawn in its first colour`,s),t.stroke={...c(f),...f.color?{color:C(e,f.color,s)}:{},...o(f.size)===void 0?{}:{size:o(f.size)},...f.position?{position:f.position}:{}});const x=p("colour overlay",i.solidFill);x&&(t.colorOverlay={...c(x),...x.color?{color:C(e,x.color,s)}:{}});const k=p("gradient overlay",i.gradientOverlay);if(k){const r=ae(e,k.gradient,s,{...k.type===void 0?{}:{style:k.type},...k.angle===void 0?{}:{angle:k.angle},...k.scale===void 0?{}:{scale:k.scale},...k.reverse===void 0?{}:{reverse:k.reverse}});r?t.gradientOverlay={...c(k),gradient:r}:g(e,"omitted","a gradient overlay of a noise gradient",s)}d(i.patternOverlay)&&g(e,"omitted","the pattern overlay: its pattern's pixels are the file's, which ag-psd does not read out",s);const j=d(i.satin);if(j){const r=j;h("satin",r.contour),t.satin={...c(r),...r.color?{color:C(e,r.color,s)}:{},...r.angle===void 0?{}:{angle:z(r.angle)},...o(r.distance)===void 0?{}:{distance:o(r.distance)},...o(r.size)===void 0?{}:{size:o(r.size)},...r.invert===void 0?{}:{invert:r.invert}}}const $=d(i.bevel);if($){const r=$,y=r.style===void 0?void 0:{"inner bevel":"innerBevel","outer bevel":"outerBevel",emboss:"emboss","pillow emboss":"pillowEmboss","stroke emboss":"strokeEmboss"}[r.style],O=r.technique===void 0?void 0:{smooth:"smooth","chisel hard":"chiselHard","chisel soft":"chiselSoft"}[r.technique];t.bevelEmboss={...r.enabled===!1?{enabled:!1}:{},...y?{style:y}:{},...O?{technique:O}:{},...r.strength===void 0?{}:{depth:Math.max(1,Math.min(1e3,Math.round(r.strength*100)))},...r.direction?{direction:r.direction}:{},...o(r.size)===void 0?{}:{size:o(r.size)},...o(r.soften)===void 0?{}:{soften:o(r.soften)},...r.angle===void 0?{}:{angle:z(r.angle)},...r.altitude===void 0?{}:{altitude:z(r.altitude)},...R(r.highlightBlendMode)?{highlightMode:R(r.highlightBlendMode)}:{},...r.highlightColor?{highlightColor:C(e,r.highlightColor,s)}:{},...r.highlightOpacity===void 0?{}:{highlightOpacity:T(r.highlightOpacity)},...R(r.shadowBlendMode)?{shadowMode:R(r.shadowBlendMode)}:{},...r.shadowColor?{shadowColor:C(e,r.shadowColor,s)}:{},...r.shadowOpacity===void 0?{}:{shadowOpacity:T(r.shadowOpacity)}}}if(i.disabled===!0)for(const r of Object.values(t))r.enabled=!1;return Object.keys(t).length>0?t:void 0}function $e(e,i,s,t){const a={...i};for(let n=0;n<24;n++){const o=pe(a,s);if(o===void 0)break;const d=/effects\.(\w+)/u.exec(o)?.[1],c=a.effects,p=/^effects\.(dropShadow|outerGlow)\.blendMode/u.exec(o)?.[1],h=p===void 0?void 0:c?.[p];if(p&&c&&typeof h=="object"&&h!==null){c[p]={...h,blendMode:"normal"},g(e,"approximate",`the ${p}'s blend mode: AllyHub draws an effect under its layer as normal (a layer's filter cannot read what lies under it), so it is written normal`,t);continue}if(d&&c&&d in c){const u=Object.fromEntries(Object.entries(c).filter(([l])=>l!==d));Object.keys(u).length>0?a.effects=u:delete a.effects,g(e,"omitted",`the ${d} effect: ${o}`,t);continue}if(o.startsWith("an adjustment has no effects")||c&&o.includes("stroke")){if(c&&o.includes("stroke")){const u=Object.fromEntries(Object.entries(c).filter(([l])=>l!=="stroke"));Object.keys(u).length>0?a.effects=u:delete a.effects,g(e,"omitted",`the stroke effect: ${o}`,t)}else delete a.effects,g(e,"omitted",`its effects: ${o}`,t);continue}if(o.includes("fillOpacity")&&a.fillOpacity!==void 0){g(e,"approximate",`its fill opacity ${JSON.stringify(a.fillOpacity)}: ${o}; drawn at 100`,t),delete a.fillOpacity;continue}if(o.includes("blendMode")&&a.blendMode!==void 0){g(e,"approximate",`its blend mode: ${o}; drawn as normal`,t),a.blendMode=s==="group"?"passThrough":"normal",s!=="group"&&delete a.blendMode;continue}g(e,"omitted",`its style: ${o}`,t),delete a.effects,delete a.blendMode,delete a.fillOpacity}return a}function F(e,i,s,t){const a=i.mask??i.realMask,n=a?.imageData&&a.imageData.width>0&&a.imageData.height>0?a:void 0,o=i.vectorMask&&i.vectorMask.paths.length>0?i.vectorMask:void 0,[d,c,p,h]=t.box.map(Math.round),u=(l,b,v)=>({...l===void 0||Math.abs(l-1)<1e-6?{}:{density:T(l)},...b===void 0||b===0?{}:{feather:Math.min(1e3,z(b))},...v===!0?{enabled:!1}:{}});if(n?.imageData){const l=n.imageData,b=new Uint8Array(p*h*4),v=n.defaultColor??0,f=(n.left??0)-e.frame.left,x=(n.top??0)-e.frame.top;for(let k=0;k<h;k++)for(let j=0;j<p;j++){const $=j+d-f,r=k+c-x,y=$>=0&&r>=0&&$<l.width&&r<l.height?l.data[(r*l.width+$)*4]??0:v,O=(k*p+j)*4;b[O]=y,b[O+1]=y,b[O+2]=y,b[O+3]=255}return o&&g(e,"omitted","its vector mask, beside its raster mask: AllyHub's layer has one mask",s),(n.userMaskFeather??0)>0&&g(e,"approximate","its mask's feather: Photoshop's radius taken as a Gaussian's standard deviation",s),{src:new U(oe(e,s,".mask",{width:p,height:h,data:b})),mode:"luminance",...u(n.userMaskDensity,n.userMaskFeather,n.disabled)}}if(o){const l=ie(te(o.paths),[1,0,0,1,-e.frame.left-d,-e.frame.top-c]);return o.paths.length>1&&o.paths.some(b=>b.fillRule==="even-odd"||b.operation!==void 0&&b.operation!=="combine")&&g(e,"approximate","its vector mask's subpaths subtract, intersect or exclude, or fill even-odd: drawn as one path, non-zero",s),(i.mask?.vectorMaskFeather??0)>0&&g(e,"approximate","its vector mask's feather: Photoshop's radius taken as a Gaussian's standard deviation",s),{path:l,...o.invert===!0?{invert:!0}:{},...u(i.mask?.vectorMaskDensity,i.mask?.vectorMaskFeather,o.disable)}}}function G(e,i,s,t){const a=R(i.blendMode);i.blendMode!==void 0&&a===void 0&&g(e,"approximate",`its blend mode ${i.blendMode} (Photoshop's 3D): drawn as normal`,t);const n=T(i.opacity),o=T(i.fillOpacity),d=i.effects?ke(e,i.effects,t):void 0;return $e(e,{...a===void 0||a===(s==="group"?"passThrough":"normal")?{}:{blendMode:a},...n===void 0||n===100?{}:{opacity:n},...o===void 0||o===100?{}:{fillOpacity:o},...i.clipping===!0?{clipping:!0}:{},...d?{effects:d}:{},...i.hidden===!0?{visible:!1}:{}},s,t)}function Me(e,i,s){const t=i.adjustment;if(!t)return;const a=n=>{g(e,"omitted",n,s)};switch(t.type){case"levels":{const n=["rgb","red","green","blue"],o={kind:"levels"};return(t.channels??[]).slice(0,4).forEach((d,c)=>{const p=n[c];if(!p)return;const h={...d.shadowInput===0?{}:{inputBlack:d.shadowInput},...d.highlightInput===255?{}:{inputWhite:d.highlightInput},...d.midtoneInput===1?{}:{gamma:Math.max(.1,Math.min(9.99,d.midtoneInput))},...d.shadowOutput===0?{}:{outputBlack:d.shadowOutput},...d.highlightOutput===255?{}:{outputWhite:d.highlightOutput}};Object.keys(h).length>0&&(o[p]=h)}),o}case"curves":{if(t.values?.some(d=>d.length>0)){a("a Curves drawn with the pencil (a table, not points): AllyHub's curves take points");return}const n=["rgb","red","green","blue"],o={kind:"curves"};return(t.channels??[]).slice(0,4).forEach((d,c)=>{const p=n[c];!p||d.length<2||(o[p]=d.slice(0,16).map(h=>[Math.round(h.input),Math.round(h.output)]))}),o}case"brightness/contrast":return t.useLegacy===!1&&g(e,"approximate","Brightness/Contrast's current algorithm, which Photoshop does not publish: drawn by the legacy one",s),{kind:"brightnessContrast",...t.brightness?{brightness:Math.max(-150,Math.min(150,t.brightness))}:{},...t.contrast?{contrast:Math.max(-50,Math.min(100,t.contrast))}:{}};case"hue/saturation":{if(t.colorize===!0){a("a colorizing Hue/Saturation: AllyHub does not draw colorize yet");return}["reds","yellows","greens","cyans","blues","magentas"].some(d=>{const c=t[d];return c!==void 0&&(c.hue!==0||c.saturation!==0||c.lightness!==0)})&&g(e,"omitted","Hue/Saturation's colour ranges: their own hue, saturation and lightness",s);const o=t.master;return{kind:"hueSaturation",...o?.hue?{hue:o.hue}:{},...o?.saturation?{saturation:o.saturation}:{},...o?.lightness?{lightness:o.lightness}:{}}}case"vibrance":return{kind:"vibrance",...t.vibrance?{vibrance:t.vibrance}:{},...t.saturation?{saturation:t.saturation}:{}};case"color balance":{const n=o=>o?[o.cyanRed,o.magentaGreen,o.yellowBlue]:void 0;return{kind:"colorBalance",...t.shadows?{shadows:n(t.shadows)}:{},...t.midtones?{midtones:n(t.midtones)}:{},...t.highlights?{highlights:n(t.highlights)}:{},...t.preserveLuminosity===!1?{preserveLuminosity:!1}:{}}}case"black & white":return t.useTint===!0&&g(e,"omitted","Black & White's tint",s),{kind:"blackAndWhite",...Object.fromEntries(["reds","yellows","greens","cyans","blues","magentas"].filter(n=>t[n]!==void 0).map(n=>[n,t[n]]))};case"photo filter":return{kind:"photoFilter",...t.color?{color:C(e,t.color,s)}:{},...t.density===void 0?{}:{density:T(t.density)},...t.preserveLuminosity===void 0?{}:{preserveLuminosity:t.preserveLuminosity}};case"invert":return{kind:"invert"};case"threshold":return{kind:"threshold",...t.level===void 0?{}:{level:Math.max(1,Math.min(255,Math.round(t.level)))}};case"gradient map":{if(t.gradientType!=="solid"||!t.colorStops){a("a Gradient Map of a noise gradient");return}const n=X({type:"solid",name:t.name??"",colorStops:t.colorStops.map(o=>({...o,location:o.location/4096})),opacityStops:(t.opacityStops??[]).map(o=>({...o,location:o.location/4096}))});return{kind:"gradientMap",gradient:{stops:n.stops.length>=2?n.stops:[...n.stops,...n.stops].slice(0,2)},...t.reverse===!0?{reverse:!0}:{}}}case"exposure":return{kind:"exposure",...t.exposure?{exposure:t.exposure}:{},...t.offset?{offset:t.offset}:{},...t.gamma!==void 0&&t.gamma!==1?{gammaCorrection:t.gamma}:{}};default:{a(`a ${t.type} adjustment: AllyHub's adjustments do not hold it`);return}}}function ve(e,i,s){const t=i.text;if(!t)return;const a=e.ppi,n=S=>z(S*a/72),[o=1,d=0,c=0,p=1,h=0,u=0]=t.transform??[],l=Math.sqrt(o*o+d*d),b=Math.atan2(d,o)*180/Math.PI;(Math.abs(l-Math.sqrt(c*c+p*p))>.001||Math.abs(o*c+d*p)>.001)&&g(e,"approximate","its text is skewed or stretched: drawn at its average scale",s);const v=t.style??{};(t.styleRuns?.length??0)>1&&g(e,"approximate",`its ${String(t.styleRuns?.length??0)} style runs: drawn in its first style`,s),(t.paragraphStyleRuns?.length??0)>1&&g(e,"approximate","its paragraphs' own styles: drawn in the first paragraph's",s),t.orientation==="vertical"&&g(e,"approximate","its vertical text: drawn horizontal",s),t.warp?.style!==void 0&&t.warp.style!=="none"&&g(e,"omitted",`its warp (${t.warp.style})`,s);const f={...v,...t.styleRuns?.[0]?.style??{}},x=f.font?.name?fontOf(f.font.name):void 0,k=f.fontSize===void 0?void 0:n(f.fontSize*l);f.fauxBold===!0&&g(e,"approximate","its faux bold: drawn at weight 700",s),f.fauxItalic===!0&&g(e,"approximate","its faux italic: drawn italic",s),f.horizontalScale!==void 0&&Math.abs(f.horizontalScale-1)>.001&&g(e,"omitted","its horizontal scale",s);const j={...x?{font:x.family}:{},...x&&(x.weight!==400||f.fauxBold===!0)?{weight:f.fauxBold===!0?700:x.weight}:{},...x?.italic===!0||f.fauxItalic===!0?{italic:!0}:{},...k===void 0?{}:{size:Math.max(1,Math.min(4096,k))},...f.fillColor?{color:C(e,f.fillColor,s)}:{},...f.tracking?{tracking:Math.max(-1e3,Math.min(1e4,f.tracking))}:{},...f.autoLeading===!1&&f.leading!==void 0?{leading:n(f.leading*l)}:{},...f.fontCaps===2?{capitalization:"allCaps"}:f.fontCaps===1?{capitalization:"smallCaps"}:{},...f.underline===!0?{underline:!0}:{},...f.strikethrough===!0?{strikeThrough:!0}:{}},$={...t.paragraphStyle??{},...t.paragraphStyleRuns?.[0]?.style??{}},r=ge($.justification),y=S=>S===void 0||S===0?void 0:n(S*l),O={...r===void 0||r==="left"?{}:{justification:r},...y($.firstLineIndent)===void 0?{}:{firstLineIndent:y($.firstLineIndent)},...y($.startIndent)===void 0?{}:{leftIndent:Math.max(0,y($.startIndent)??0)},...y($.endIndent)===void 0?{}:{rightIndent:Math.max(0,y($.endIndent)??0)},...y($.spaceBefore)===void 0?{}:{spaceBefore:y($.spaceBefore)},...y($.spaceAfter)===void 0?{}:{spaceAfter:y($.spaceAfter)}};t.text.includes("")&&g(e,"approximate","its line breaks inside a paragraph: each starts a paragraph, with the paragraph's spacing",s);const B=t.text.replace(/\r\n?/gu,`
|
|
3
3
|
`).replaceAll("",`
|
|
4
|
-
`),
|
|
5
|
-
`)?
|
|
6
|
-
${t.map(d=>`${
|
|
4
|
+
`),m=`${e.o.id.replace(/\//gu,".")}.${e.board}.${s}`;(e.script[e.board]??={})[s]=B,g(e,"approximate","type: Chrome draws its words in the font of its name where the project has it, by CSS's line breaking: Photoshop's composer and its fallback fonts may set them otherwise",s);const w=(S,D)=>[o*S+c*D+h-e.frame.left,d*S+p*D+u-e.frame.top],M=e.frame.width,I=e.frame.height,A={};if(t.shapeType==="box"&&t.boxBounds&&t.boxBounds.length>=4){const[S=0,D=0,P=0,q=0]=t.boxBounds,[H,N]=w(S,D),K=(P-S)*l,Y=(q-D)*l,E=Math.max(0,H),J=Math.max(0,N),Z=Math.min(M,H+K),_=Math.min(I,N+Y);(E!==H||J!==N||Z!==H+K||_!==N+Y)&&g(e,"approximate","its text box reaches past the board: cut to it",s),Z>E&&_>J&&(A.box=[L(E,M),L(J,I),L(Z-E,M),L(_-J,I)])}else{const[S,D]=w(0,0),P=D-(k??12)*.9;g(e,"approximate","point text: its first baseline put 0.9 of its size under the top AllyHub places it from",s),A.position=[L(Math.max(0,Math.min(M,S)),M),L(Math.max(0,Math.min(I,P)),I)]}return Math.abs(b)>.001&&(A.transform={rotation:z(b)}),{textItem:{contents:new U(`ctx.s(${JSON.stringify(m)})`),...Object.keys(j).length>0?{characterStyle:j}:{},...Object.keys(O).length>0?{paragraphStyle:O}:{}},...A}}function Oe(e,i,s){const t=i.vectorMask?.paths??[];if(t.length===0)return;const a=i.vectorStroke,o=a?.fillEnabled!==!1?re(e,i.vectorFill,s):null;if(o===void 0||o&&"gradient"in o&&(o.gradient.style==="angle"||o.gradient.style==="diamond"))return;let d=null;if(a?.strokeEnabled===!0){const c=a.content?.type==="color"?C(e,a.content.color,s):void 0;a.content&&a.content.type!=="color"&&g(e,"approximate","its stroke's gradient or pattern: drawn black",s);const p=ne(a.lineWidth,e.ppi);d={...c===void 0?{}:{color:c},...p===void 0?{}:{width:Math.min(1e3,z(p))},...a.lineAlignment?{alignment:a.lineAlignment}:{},...a.lineDashSet&&a.lineDashSet.length>0?{dashes:a.lineDashSet.slice(0,8).map(h=>Math.min(1e3,z(h.value)))}:{},...a.lineCapType?{cap:a.lineCapType}:{},...a.lineJoinType?{join:a.lineJoinType}:{},...a.opacity===void 0||a.opacity===1?{}:{opacity:T(a.opacity)}}}return t.length>1&&t.some(c=>c.fillRule==="even-odd"||c.operation!==void 0&&c.operation!=="combine")&&g(e,"approximate","its path's subpaths subtract, intersect or exclude, or fill even-odd: drawn as one path, non-zero",s),{shape:"path",path:ie(te(t),[1,0,0,1,-e.frame.left,-e.frame.top]),fill:o,...d?{stroke:d}:{}}}function de(e){return e.children?"group":e.text?"type":e.placedLayer?"smartObject":e.adjustment?"adjustment":e.vectorFill&&(e.vectorStroke||e.vectorOrigination||e.vectorMask)?"shape":e.vectorFill?"fill":"pixel"}function ce(e,i,s){const t=Se(e,i,s),a=(i.name??"").replace(/\s+/gu," ").trim();return t&&a!==""&&a!==t.key?{...t,name:a}:t}function Se(e,i,s){const t=de(i),a=i.name??"",n=keyOf(a,`${t==="unknown"?"layer":t}-${String(s+1)}`,e.taken),o=h=>{e.kinds[h]=(e.kinds[h]??0)+1},d=ye(i,e),c=h=>{if(h!==void 0&&g(e,"pixels",h,n),!d){g(e,"omitted",h===void 0?"a layer with no pixels on the board: it draws nothing":"it has no pixels on the board to keep",n);return}o("pixel");const u=G(e,i,"pixel",n),l=F(e,i,n,{box:d.box});return{fn:"picture",key:n,kind:"pixel",pixels:d.img,opts:{key:n,src:new U(oe(e,n,"",d.img)),box:we(d.img,d.box,e),fit:"fill",...u,...l?{mask:l}:{}}}},p={box:[0,0,e.frame.width,e.frame.height]};switch(t){case"group":{o("group");const h=(i.children??[]).map((f,x)=>ce(e,f,x)).filter(f=>f!==void 0);let u=G(e,i,"group",n);const l=F(e,i,n,p),b=(u.opacity??100)<100||(u.fillOpacity??100)<100||u.effects!==void 0||l!==void 0,v=h.some(f=>f.kind==="adjustment"||f.opts.blendMode!==void 0&&f.opts.blendMode!=="normal");return(u.blendMode??"passThrough")==="passThrough"&&b&&v&&(g(e,"approximate","a pass-through group that fades, is masked or has effects over layers that blend through it: drawn as a normal group",n),u={...u,blendMode:"normal"}),{fn:"group",key:n,kind:"group",opts:{key:n,...u,...l?{mask:l}:{}},layers:le(e,h)}}case"type":{const h=ve(e,i,n);if(!h)return c("a type layer whose text could not be read");o("type");const u=G(e,i,"type",n),l=F(e,i,n,p);return{fn:"textLayer",key:n,kind:"type",...d?{pixels:d.img}:{},opts:{key:n,...h,...u,...l?{mask:l}:{}}}}case"smartObject":return c("a smart object: kept as its pixels; its embedded or linked file is not");case"adjustment":{const h=Me(e,i,n);if(!h)return;const u=fe(h);if(u){g(e,"omitted",`the adjustment: ${u}`,n);return}o("adjustment");const l=G(e,i,"adjustment",n),b=F(e,i,n,p);return{fn:"adjustment",key:n,kind:"adjustment",opts:{key:n,...h,...l,...b?{mask:b}:{}}}}case"shape":{const h=Oe(e,i,n);if(!h)return c("a shape whose fill AllyHub's shape does not draw (a pattern, a noise, angle or diamond gradient): kept as its pixels");o("shape");const u=G(e,i,"shape",n),l=i.mask?.imageData?F(e,Object.fromEntries(Object.entries(i).filter(([b])=>b!=="vectorMask")),n,p):void 0;return{fn:"shape",key:n,kind:"shape",...d?{pixels:d.img}:{},opts:{key:n,...h,...u,...l?{mask:l}:{}}}}case"fill":{const h=re(e,i.vectorFill,n);if(!h||"gradient"in h&&h.gradient.style==="diamond")return c("a fill layer of a pattern, a noise or diamond gradient: kept as its pixels");o("fill");const u=G(e,i,"fill",n),l=F(e,i,n,p);return{fn:"fill",key:n,kind:"fill",...d?{pixels:d.img}:{},opts:{key:n,fill:h,...u,...l?{mask:l}:{}}}}default:return c()}}function le(e,i){const s=[];let t;for(const a of i){if(!(a.opts.clipping===!0)){t=a,s.push(a);continue}if(t!==void 0&&(t.kind==="pixel"||t.kind==="shape"||t.kind==="fill")&&t.opts.mask===void 0&&t.opts.transform===void 0){s.push(a);continue}const d={...a.opts};if(delete d.clipping,a.fn==="picture"&&t?.pixels&&a.pixels){const c=d.src,p=d.box,h=e.frame.width,u=e.frame.height,l=Math.round((p[0]??0)*h),b=Math.round((p[1]??0)*u),v=t.pixels,f=t.opts.box,x=Math.round((f?.[0]??0)*h),k=Math.round((f?.[1]??0)*u),j=new Uint8Array(a.pixels.data);for(let r=0;r<a.pixels.height;r++)for(let y=0;y<a.pixels.width;y++){const O=y+l-x,B=r+b-k,m=O>=0&&B>=0&&O<v.width&&B<v.height?v.data[(B*v.width+O)*4+3]??0:0,w=(r*a.pixels.width+y)*4+3;j[w]=Math.round((j[w]??0)*m/255)}const $=e.imports.find(r=>r.name===c.name)?.path.replace(/^\.\//u,"");$&&e.files.set($,new Uint8Array(Q({...a.pixels,data:j}))),g(e,"pixels",`clipped to ${t.key}, which AllyHub cannot clip to (${t.kind==="type"?"a type layer's glyphs":"a masked, turned or component base"}): its pixels cut by the base's own`,a.key),s.push({...a,opts:d});continue}g(e,"approximate",`clipped to ${t?.key??"nothing"}, which AllyHub cannot clip to: drawn unclipped`,a.key),s.push({...a,opts:d})}return s}const ue=/^[A-Za-z_$][\w$]*$/u;function W(e,i){if(e instanceof U)return e.name;if(e===null||typeof e!="object")return JSON.stringify(e);const s=i+" ",t=Array.isArray(e)?e.map(d=>W(d,s)):Object.entries(e).filter(([,d])=>d!==void 0).map(([d,c])=>`${ue.test(d)?d:JSON.stringify(d)}: ${W(c,s)}`),[a,n]=Array.isArray(e)?["[","]"]:["{","}"];if(t.length===0)return`${a}${n}`;const o=`${a}${Array.isArray(e)?"":" "}${t.join(", ")}${Array.isArray(e)?"":" "}${n}`;return o.length+i.length<=80&&!o.includes(`
|
|
5
|
+
`)?o:`${a}
|
|
6
|
+
${t.map(d=>`${s}${d},`).join(`
|
|
7
7
|
`)}
|
|
8
|
-
${
|
|
9
|
-
${
|
|
8
|
+
${i}${n}`}function he(e,i){return(e.name===void 0?"":`// ${JSON.stringify(e.name).slice(1,-1)}
|
|
9
|
+
${i}`)+je(e,i)}function je(e,i){if(e.fn==="group"){const s=i+" ",t=Object.entries(e.opts).filter(([,n])=>n!==void 0).map(([n,o])=>`${s}${ue.test(n)?n:JSON.stringify(n)}: ${W(o,s)},`),a=(e.layers??[]).map(n=>`${s} ${he(n,s+" ")},`);return`group({
|
|
10
10
|
${t.join(`
|
|
11
11
|
`)}
|
|
12
|
-
${
|
|
13
|
-
${
|
|
12
|
+
${s}layers: [
|
|
13
|
+
${a.join(`
|
|
14
14
|
`)}
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
`))," ],","});",""],
|
|
18
|
-
`).replace("boards: (ctx) =>",
|
|
15
|
+
${s}],
|
|
16
|
+
${i}})`}return`${e.fn}(${W(e.opts,i)})`}export async function importPsd(e,i){const{readPsd:s}=await V(),t=s(e,{useImageData:!0,skipThumbnail:!0,skipLinkedFilesData:!0}),a=[],n=new Map,o={psd:t,ppi:t.imageResources?.resolutionInfo?.horizontalResolution??72,notes:a,files:n,script:{},imports:[],o:i,board:"",frame:{left:0,top:0,width:t.width,height:t.height},taken:new Set,kinds:{}};(t.bitsPerChannel??8)!==8&&a.push({how:"approximate",what:`its ${String(t.bitsPerChannel)} bits a channel: read as 8`});const d=t.colorMode??3;d!==3&&a.push({how:"approximate",what:`its colour mode (${["bitmap","grayscale","indexed","RGB","CMYK","","","multichannel","duotone","Lab"][d]??String(d)}): read as RGB without its profile`});const c=t.children??[],p=c.filter(m=>m.artboard),h=new Set,u=[],l=t.imageData?{width:t.imageData.width,height:t.imageData.height,data:new Uint8Array(t.imageData.data.buffer,t.imageData.data.byteOffset,t.imageData.data.byteLength)}:void 0;l||a.push({how:"omitted",what:"the file has no merged composite (saved without Maximize Compatibility): nothing to compare a render with"});const b=m=>{if(!l)return;const w=new Uint8Array(m.width*m.height*4);for(let M=0;M<m.height;M++)for(let I=0;I<m.width;I++){const A=I+m.left,S=M+m.top;A<0||S<0||A>=l.width||S>=l.height||w.set(l.data.subarray((S*l.width+A)*4,(S*l.width+A)*4+4),(M*m.width+I)*4)}return{width:m.width,height:m.height,data:w}},v=(m,w,M,I)=>{const A=keyOf(m,`board-${String(u.length+1)}`,h);o.board=A,o.frame=M,o.taken=new Set,o.kinds={};const S=le(o,w.map((P,q)=>ce(o,P,q)).filter(P=>P!==void 0)),D=b(M);u.push({key:A,name:m,width:M.width,height:M.height,background:I,layers:S,...D?{composite:D}:{},kinds:o.kinds})};if(p.length>0){for(const w of p){const M=w.artboard?.rect??{left:0,top:0,right:t.width,bottom:t.height},I=w.artboard?.backgroundType??1,A=I===3?"transparent":I===2?"#000000":I===4?ee(w.artboard?.color).hex:"#ffffff";v(w.name??"artboard",w.children??[],{left:Math.round(M.left),top:Math.round(M.top),width:Math.max(1,Math.round(M.right-M.left)),height:Math.max(1,Math.round(M.bottom-M.top))},A)}const m=c.filter(w=>!w.artboard);for(const w of m)a.push({how:"omitted",what:`${w.name??"a layer"} lies outside every artboard`,layer:w.name??""})}else v(i.source.replace(/\.(psd|psb)$/iu,"")||"canvas",c,{left:0,top:0,width:t.width,height:t.height},"transparent");for(const m of u)(m.width>16384||m.height>16384)&&a.push({how:"omitted",what:`board ${m.key} is ${String(m.width)}×${String(m.height)}: a board is at most 16384 a side`,board:m.key});const f=be(i.id),x=`${f}.ts`,k=/\.ps[db]$/iu.exec(i.source)?.[0]??"",j=se(o,i.source.slice(0,i.source.length-k.length),k);n.set(j,e);const $=new Set(["board","image"]),r=m=>{for(const w of m)$.add(w.fn),w.layers&&r(w.layers)};for(const m of u)r(m.layers);const y=o.ppi,O=[`import { ${[...$].sort().join(", ")} } from "@allyhub/sdk/image";`,"",...o.imports.map(m=>`import ${m.name} from ${JSON.stringify(m.path)};`),"",`// Imported from ${i.source} (kept beside it${j===i.source?"":` as ${j}`}): its layers by their names, a pixel`,"// layer's pixels beside it, a type layer's words in its script.","export default image({",` script: ${JSON.stringify(`./${f}.{locale}.yaml`)},`," transparent: true,"," boards: (ctx) => [",...u.map(m=>[" board({",...[` key: ${JSON.stringify(m.key)},`,...m.name!==m.key?[` title: ${JSON.stringify(m.name)},`]:[],` size: "${String(Math.min(16384,m.width))}x${String(Math.min(16384,m.height))}",`,` background: ${JSON.stringify(m.background)},`,...y!==72?[` resolution: ${String(z(y))},`]:[]]," layers: [",...m.layers.map(M=>` ${he(M," ")},`)," ],"," }),"].join(`
|
|
17
|
+
`))," ],","});",""],B=Object.keys(o.script).length>0;return n.set(x,O.join(`
|
|
18
|
+
`).replace("boards: (ctx) =>",B?"boards: (ctx) =>":"boards: () =>")),n.set(`${f}.${i.lang}.yaml`,me({title:i.source.replace(/\.(psd|psb)$/iu,""),...B?{boards:Object.entries(o.script).map(([m,w])=>({id:m,text:w}))}:{}})),{files:n,module:x,source:j,boards:u.map(m=>({key:m.key,name:m.name,width:m.width,height:m.height,...m.composite?{composite:m.composite}:{},kinds:m.kinds})),report:a}}export async function layerTree(e){const{readPsd:i}=await V(),s=i(e,{useImageData:!0,skipThumbnail:!0,skipLinkedFilesData:!0,skipCompositeImageData:!0,skipLayerImageData:!0}),t=a=>a.map(n=>{const o=n.effects?Object.entries(n.effects).filter(([c,p])=>c!=="scale"&&c!=="disabled"&&p!==void 0).map(([c])=>c):[],d=[...n.mask&&(n.mask.right??0)>(n.mask.left??0)?["mask"]:[],...n.vectorMask?["vectorMask"]:[],...o.map(c=>`effect:${c}`),...n.adjustment?[`adjustment:${n.adjustment.type}`]:[],...n.text?[`text:${n.text.text}`]:[],...n.vectorFill?[`fill:${n.vectorFill.type}`]:[],...n.vectorStroke?.strokeEnabled===!0?["stroke"]:[],...n.placedLayer?["placed"]:[],...n.artboard?["artboard"]:[]];return{name:n.name??"",kind:de(n),blendMode:n.blendMode??"normal",opacity:Math.round((n.opacity??1)*100),...n.fillOpacity===void 0?{}:{fillOpacity:Math.round(n.fillOpacity*100)},hidden:n.hidden===!0,clipping:n.clipping===!0,has:d,...n.children?{children:t(n.children)}:{}}});return t(s.children??[])}export function treeLines(e,i=""){return[...e].reverse().flatMap(s=>[`${i}${s.name} [${s.kind}] ${s.blendMode} ${String(s.opacity)}%${s.fillOpacity===void 0||s.fillOpacity===100?"":` fill ${String(s.fillOpacity)}%`}${s.hidden?" hidden":""}${s.clipping?" clipped":""}${s.has.length>0?` {${s.has.join(", ")}}`:""}`,...treeLines(s.children??[],`${i} `)])}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{createHash as F}from"node:crypto";import{initializeCanvas as U,writePsdUint8Array as $}from"ag-psd";import{writePng as R}from"@allyhub/measure";import{ADJUSTMENT_DEFAULTS as m,EFFECT_DEFAULTS as j,TEXT_DEFAULTS as S}from"@allyhub/piece";import{BLENDS as O,JUSTIFY as W,knotsOf as M,psdGradient as D,pxUnits as d,rgbOf as k}from"./map.js";export const PSD_DEFAULTS={format:"psd"};let G=!1;function N(){if(G)return;U(()=>{throw new Error("ag-psd asked for a canvas: AllyHub gives it pixels as data.")},(t,s)=>({width:t,height:s,data:new Uint8ClampedArray(t*s*4),colorSpace:"srgb"})),G=!0}const L=e=>({width:e.width,height:e.height,data:new Uint8ClampedArray(e.data.buffer,e.data.byteOffset,e.data.byteLength)}),u=e=>{const{r:t,g:s,b:i}=k(e);return{r:t,g:s,b:i}};function E(...e){const t=F("sha256");for(const i of e)t.update(i);const s=t.digest("hex");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20,32)}`}const H={100:"Thin",200:"ExtraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Black"};export function postScriptName(e,t,s){const i=H[Math.round(t/100)*100]??"Regular",r=s?i==="Regular"?"Italic":`${i}Italic`:i;return`${e.replace(/\s*Variable$/u,"").replace(/[^A-Za-z0-9]/gu,"")}-${r}`}const p=(e,t,s,i)=>{e.notes.push({how:t,what:s,...i===void 0?{}:{layer:i}})};function I(e){if("color"in e)return{type:"color",color:u(e.color)};if("gradient"in e){const t=e.gradient;return{...D(t),style:t.style??"linear",angle:t.angle??90,scale:(t.scale??100)/100,reverse:t.reverse===!0,align:!0}}}function q(e,t,s){const i={scale:1},r=o=>o.enabled!==!1,c=(o,a)=>({present:!0,showInDialog:!0,enabled:r(o),blendMode:O[o.blendMode??a.blendMode],opacity:(o.opacity??a.opacity??100)/100}),n=j;if(e.dropShadow){const o=e.dropShadow;i.dropShadow=[{...c(o,n.dropShadow),color:u(o.color??n.dropShadow.color),angle:o.angle??n.dropShadow.angle,useGlobalLight:!1,distance:d(o.distance??n.dropShadow.distance),choke:d(o.spread??n.dropShadow.spread),size:d(o.size??n.dropShadow.size),layerConceals:!0}]}if(e.innerShadow){const o=e.innerShadow;i.innerShadow=[{...c(o,n.innerShadow),color:u(o.color??n.innerShadow.color),angle:o.angle??n.innerShadow.angle,useGlobalLight:!1,distance:d(o.distance??n.innerShadow.distance),choke:d(o.choke??n.innerShadow.choke),size:d(o.size??n.innerShadow.size)}]}if(e.outerGlow){const o=e.outerGlow;i.outerGlow={...c(o,n.outerGlow),color:u(o.color??n.outerGlow.color),technique:"softer",choke:d(o.spread??n.outerGlow.spread),size:d(o.size??n.outerGlow.size),range:.5}}if(e.innerGlow){const o=e.innerGlow;i.innerGlow={...c(o,n.innerGlow),color:u(o.color??n.innerGlow.color),technique:"softer",source:o.source??n.innerGlow.source,choke:d(o.choke??n.innerGlow.choke),size:d(o.size??n.innerGlow.size),range:.5}}if(e.stroke){const o=e.stroke;i.stroke=[{...c(o,n.stroke),size:d(o.size??n.stroke.size),position:o.position??n.stroke.position,fillType:"color",color:u(o.color??n.stroke.color)}]}if(e.colorOverlay){const o=e.colorOverlay;i.solidFill=[{...c(o,n.colorOverlay),color:u(o.color??n.colorOverlay.color)}]}if(e.gradientOverlay){const o=e.gradientOverlay,a=o.gradient??n.gradientOverlay.gradient;i.gradientOverlay=[{...c(o,n.gradientOverlay),gradient:D({...a,stops:[...a.stops]}),type:a.style??"linear",angle:a.angle??90,scale:(a.scale??100)/100,reverse:a.reverse===!0,align:!0,offset:{x:0,y:0}}]}if(e.patternOverlay&&p(t,"omitted","the pattern overlay: ag-psd writes no pattern's pixels into the file",s),e.satin){const o=e.satin;i.satin={...c(o,n.satin),color:u(o.color??n.satin.color),angle:o.angle??n.satin.angle,distance:d(o.distance??n.satin.distance),size:d(o.size??n.satin.size),invert:o.invert??n.satin.invert}}if(e.bevelEmboss){const o=e.bevelEmboss,a=n.bevelEmboss;i.bevel={present:!0,showInDialog:!0,enabled:r(o),style:"inner bevel",technique:"smooth",strength:(o.depth??a.depth)/100,direction:o.direction??a.direction,size:d(o.size??a.size),soften:d(o.soften??a.soften),angle:o.angle??a.angle,altitude:o.altitude??a.altitude,useGlobalLight:!1,highlightBlendMode:O[o.highlightMode??a.highlightMode],highlightColor:u(o.highlightColor??a.highlightColor),highlightOpacity:(o.highlightOpacity??a.highlightOpacity)/100,shadowBlendMode:O[o.shadowMode??a.shadowMode],shadowColor:u(o.shadowColor??a.shadowColor),shadowOpacity:(o.shadowOpacity??a.shadowOpacity)/100}}const l=Object.keys(i).length>1;return l&&p(t,"approximate","layer styles: Photoshop draws its effects by its own engine (its blurs, its bevel's lighting), which AllyHub's SVG filters follow by its published dialog's numbers",s),l?i:void 0}const _=e=>{const t=m.levels;return{shadowInput:e?.inputBlack??t.inputBlack,highlightInput:e?.inputWhite??t.inputWhite,shadowOutput:e?.outputBlack??t.outputBlack,highlightOutput:e?.outputWhite??t.outputWhite,midtoneInput:e?.gamma??t.gamma}},V={reds:[315,345,15,45],yellows:[15,45,75,105],greens:[75,105,135,165],cyans:[135,165,195,225],blues:[195,225,255,285],magentas:[255,285,315,345]},J=new Set(["brightnessContrast","hueSaturation","vibrance","colorBalance","blackAndWhite","photoFilter"]);function X(e){switch(e.kind){case"levels":return{type:"levels",channels:[e.rgb,e.red,e.green,e.blue].map(_)};case"curves":{const t=s=>(s??[]).map(([i,r])=>({input:i,output:r}));return{type:"curves",channels:[t(e.rgb??m.curves.rgb),t(e.red),t(e.green),t(e.blue)]}}case"brightnessContrast":return{type:"brightness/contrast",brightness:e.brightness??0,contrast:e.contrast??0,meanValue:127,useLegacy:e.useLegacy??!0,labColorOnly:!1};case"hueSaturation":return{type:"hue/saturation",colorize:e.colorize===!0,colorization:{hue:0,saturation:25,lightness:0},master:{hue:e.hue??0,saturation:e.saturation??0,lightness:e.lightness??0},...Object.fromEntries(Object.entries(V).map(([t,[s,i,r,c]])=>[t,{a:s,b:i,c:r,d:c,hue:0,saturation:0,lightness:0}]))};case"vibrance":return{type:"vibrance",vibrance:e.vibrance??0,saturation:e.saturation??0};case"colorBalance":{const t=s=>({cyanRed:s?.[0]??0,magentaGreen:s?.[1]??0,yellowBlue:s?.[2]??0});return{type:"color balance",shadows:t(e.shadows),midtones:t(e.midtones),highlights:t(e.highlights),preserveLuminosity:e.preserveLuminosity??!0}}case"blackAndWhite":{const t=m.blackAndWhite;return{type:"black & white",reds:e.reds??t.reds,yellows:e.yellows??t.yellows,greens:e.greens??t.greens,cyans:e.cyans??t.cyans,blues:e.blues??t.blues,magentas:e.magentas??t.magentas,useTint:!1,tintColor:{r:225,g:211,b:179}}}case"photoFilter":{const t=m.photoFilter;return{type:"photo filter",color:u(e.color??t.color),density:(e.density??t.density)/100,preserveLuminosity:e.preserveLuminosity??t.preserveLuminosity}}case"invert":return{type:"invert"};case"threshold":return{type:"threshold",level:e.level??m.threshold.level};case"gradientMap":{const t=D({...e.gradient??m.gradientMap.gradient,stops:[...(e.gradient??m.gradientMap.gradient).stops]});return{type:"gradient map",name:"Custom",gradientType:"solid",reverse:e.reverse===!0,dither:!1,smoothness:1,colorStops:t.colorStops.map(s=>({...s,location:Math.round(s.location*4096)})),opacityStops:t.opacityStops.map(s=>({...s,location:Math.round(s.location*4096)}))}}case"exposure":return{type:"exposure",exposure:e.exposure??0,offset:e.offset??0,gamma:e.gammaCorrection??1}}}function Y(e,t){const s=e.text;if(!s)return;const i=t.board.resolution,r=b=>b*72/i,c=s.characterStyle,n=c.size??S.size,l=c.font??s.family??"Arial",o=postScriptName(l,c.weight??S.weight,c.italic===!0),a=k(c.color??S.color);a.a<1&&p(t,"approximate","a type layer's colour has an alpha, which Photoshop's text colour does not: written opaque",e.key),p(t,"approximate","type: Photoshop redraws the words (it asks to update the text layers when the file opens) by its own composer, so line breaks and baselines may move",e.key),p(t,"approximate",`the font is named ${o}: a PostScript name made from its family and weight by the usual convention; Photoshop shows another where it has none of that name`,e.key);const[h,g,f,w,z,T]=e.matrix,A=(b,x)=>[h*b+f*x+z,g*b+w*x+T],y=s.paragraphStyle;let v;if(s.box)v=A(s.box[0],s.box[1]);else{const[b,x]=s.position??[0,0];let C=s.baseline;C===void 0&&(C=x+n*.9,p(t,"approximate","a type layer's baseline was not drawn (it is hidden), so it is put 0.9 of its size under its top",e.key)),v=A(b,C)}const B={font:{name:o},fontSize:r(n),fillColor:{r:a.r,g:a.g,b:a.b},tracking:c.tracking??0,...c.leading===void 0||c.leading==="auto"?{autoLeading:!0}:{autoLeading:!1,leading:r(c.leading)},fontCaps:c.capitalization==="allCaps"?2:c.capitalization==="smallCaps"?1:0,underline:c.underline===!0,strikethrough:c.strikeThrough===!0};return{text:s.contents,transform:[h,g,f,w,v[0],v[1]],antiAlias:"smooth",style:B,paragraphStyle:{justification:W[y.justification??"left"],firstLineIndent:r(y.firstLineIndent??0),startIndent:r(y.leftIndent??0),endIndent:r(y.rightIndent??0),spaceBefore:r(y.spaceBefore??0),spaceAfter:r(y.spaceAfter??0),autoLeading:S.autoLeading},...s.box?{shapeType:"box",boxBounds:[0,0,s.box[2],s.box[3]]}:{shapeType:"point"}}}function P(e,t){const s=e.kind==="group",i={name:e.key,id:t.id++,blendMode:O[e.blendMode??(s?"passThrough":"normal")],opacity:(e.opacity??100)/100,hidden:e.hidden,blendClippendElements:!0,...e.clipping===!0?{clipping:!0}:{},...e.fillOpacity===void 0?{}:{fillOpacity:e.fillOpacity/100}},r=t.px.layers.get(e.key),c=()=>{r&&(i.left=r.left,i.top=r.top,i.right=r.left+r.img.width,i.bottom=r.top+r.img.height,i.imageData=L(r.img))};if(e.effects){const l=q(e.effects,t,e.key);l&&(i.effects=l)}const n=e.mask;if(n?.kind==="vector"){const[l,o]=n.at,[a,h,g,f,w,z]=e.matrix;i.vectorMask={paths:M(n.path,[a,h,g,f,a*l+g*o+w,h*l+f*o+z]),...n.invert?{invert:!0}:{},...n.enabled?{}:{disable:!0}},(n.density!==100||n.feather!==0)&&(i.mask={...n.density===100?{}:{vectorMaskDensity:n.density/100},...n.feather===0?{}:{vectorMaskFeather:n.feather},fromVectorData:!0})}else if(n?.kind==="raster"){const l=t.px.masks.get(e.key);l?i.mask={left:l.left,top:l.top,right:l.left+l.img.width,bottom:l.top+l.img.height,defaultColor:0,...n.enabled?{}:{disabled:!0},...n.density===100?{}:{userMaskDensity:n.density/100},...n.feather===0?{}:{userMaskFeather:n.feather},imageData:L(l.img)}:i.mask={left:0,top:0,right:1,bottom:1,defaultColor:0,...n.enabled?{}:{disabled:!0},imageData:{width:1,height:1,data:new Uint8ClampedArray([0,0,0,255])}}}switch(n&&n.feather>0&&p(t,"approximate","a mask's feather: AllyHub's is a Gaussian's standard deviation, Photoshop's its own blur of that radius",e.key),e.kind){case"group":i.children=(e.layers??[]).map(l=>P(l,t)),i.opened=!0;break;case"adjustment":e.adjustment&&(i.adjustment=X(e.adjustment),J.has(e.adjustment.kind)&&p(t,"approximate",`${e.adjustment.kind}: Photoshop publishes no formula for it, so it draws its own way the numbers AllyHub draws by its stated one`,e.key));break;case"type":{const l=Y(e,t);l&&(i.text=l),c();break}case"shape":{const l=e.shape,o=l?.fill?I(l.fill):{type:"color",color:u("#000000")};if(!l||!o){p(t,"pixels","a shape filled with a pattern: written as a pixel layer, its path as its vector mask (ag-psd writes no pattern's pixels)",e.key),c(),l&&(i.vectorMask={paths:M(l.path,e.matrix)});break}const a=l.stroke,h=a?k(a.color??"#000000"):void 0;i.vectorFill=o,i.vectorStroke={strokeEnabled:a!==null,fillEnabled:l.fill!==null,lineWidth:d(a?.width??1),lineDashOffset:d(0),miterLimit:100,lineCapType:a?.cap??"butt",lineJoinType:a?.join??"miter",lineAlignment:a?.alignment??"center",scaleLock:!1,strokeAdjust:!1,lineDashSet:(a?.dashes??[]).map(g=>({units:"None",value:g})),blendMode:"normal",opacity:(a?.opacity??100)/100*(h?.a??1),content:{type:"color",color:h?{r:h.r,g:h.g,b:h.b}:{r:0,g:0,b:0}},resolution:t.board.resolution},i.vectorMask={paths:M(l.path,e.matrix)},c();break}case"fill":{const l=e.fill?I(e.fill):void 0;l?i.vectorFill=l:p(t,"pixels","a pattern fill: written as a pixel layer (ag-psd writes no pattern's pixels)",e.key),c();break}case"smartObject":{if(c(),r){const l=new Uint8Array(R(r.img)),o=E("linked",t.board.key,e.key,l);t.linked.push({id:o,name:`${e.key}.png`,type:"png ",creator:"8BIM",data:l});const[a,h,g,f]=[r.left,r.top,r.left+r.img.width,r.top+r.img.height];i.placedLayer={id:o,placed:E("placed",t.board.key,e.key,l),type:"raster",transform:[a,h,g,h,g,f,a,f],width:r.img.width,height:r.img.height,resolution:{units:"Density",value:t.board.resolution}},p(t,"pixels","a component: a smart object holding its pixels as drawn (an embedded PNG); its code and props are not in the file",e.key)}break}default:c()}return i}function Z(e){const t=i=>i.replace(/&/gu,"&").replace(/"/gu,""").replace(/</gu,"<"),s=`${String(Math.round(e.resolution*1e4))}/10000`;return`<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" photoshop:ColorMode="3" photoshop:ICCProfile="${t(e.colorProfile)}" tiff:XResolution="${s}" tiff:YResolution="${s}" tiff:ResolutionUnit="2"><dc:title><rdf:Alt><rdf:li xml:lang="x-default">${t(e.title??e.key)}</rdf:li></rdf:Alt></dc:title></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="w"?>`}export function psdOf(e,t){const s={board:e,px:t,notes:[],linked:[],id:1},i=e.layers.map(h=>P(h,s)),r=e.background,c=r==="transparent"||k(r).a===0,n=c?void 0:k(r),l=c?3:n?.r===255&&n.g===255&&n.b===255?1:n?.r===0&&n.g===0&&n.b===0?2:4;n&&n.a<1&&p(s,"approximate",`the board's background ${r} has an alpha, which an artboard's colour does not: written opaque`);const o={name:e.title??e.key,id:s.id++,blendMode:"pass through",opacity:1,children:i,opened:!0,artboard:{rect:{top:0,left:0,bottom:e.height,right:e.width},presetName:"",...n?{color:{r:n.r,g:n.g,b:n.b}}:{},backgroundType:l}};return e.colorProfile!=="sRGB IEC61966-2.1"&&p(s,"approximate",`the board's colour profile ${e.colorProfile} is named in the file's metadata; its pixels are sRGB, as Chrome draws them`),p(s,"omitted","the colour profile's bytes: it is named in the file's metadata (XMP's photoshop:ICCProfile), and Photoshop gives an untagged file its working space"),{psd:{width:e.width,height:e.height,channels:4,bitsPerChannel:8,children:[o],imageData:L(t.composite),...s.linked.length>0?{linkedFiles:s.linked}:{},artboards:{count:1},imageResources:{resolutionInfo:{horizontalResolution:e.resolution,horizontalResolutionUnit:"PPI",widthUnit:"Inches",verticalResolution:e.resolution,verticalResolutionUnit:"PPI",heightUnit:"Inches"},xmpMetadata:Z(e)}},fidelity:s.notes}}export function writeBoardPsd(e,t,s={}){N();const{psd:i,fidelity:r}=psdOf(e,t);return{bytes:$(i,{invalidateTextLayers:!0,noBackground:!0,...(s.format??PSD_DEFAULTS.format)==="psb"?{psb:!0}:{}}),fidelity:r}}
|
|
2
|
+
import{createHash as E}from"node:crypto";import{writePng as F}from"@allyhub/measure";import{ADJUSTMENT_DEFAULTS as m,EFFECT_DEFAULTS as $,TEXT_DEFAULTS as S}from"@allyhub/piece";import{psdLib as R}from"./ag-psd.js";import{BLENDS as O,JUSTIFY as U,knotsOf as C,psdGradient as L,pxUnits as d,rgbOf as k}from"./map.js";export const PSD_DEFAULTS={format:"psd"};const D=e=>({width:e.width,height:e.height,data:new Uint8ClampedArray(e.data.buffer,e.data.byteOffset,e.data.byteLength)}),u=e=>{const{r:t,g:s,b:i}=k(e);return{r:t,g:s,b:i}};function A(...e){const t=E("sha256");for(const i of e)t.update(i);const s=t.digest("hex");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20,32)}`}const j={100:"Thin",200:"ExtraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Black"};export function postScriptName(e,t,s){const i=j[Math.round(t/100)*100]??"Regular",a=s?i==="Regular"?"Italic":`${i}Italic`:i;return`${e.replace(/\s*Variable$/u,"").replace(/[^A-Za-z0-9]/gu,"")}-${a}`}const p=(e,t,s,i)=>{e.notes.push({how:t,what:s,...i===void 0?{}:{layer:i}})};function I(e){if("color"in e)return{type:"color",color:u(e.color)};if("gradient"in e){const t=e.gradient;return{...L(t),style:t.style??"linear",angle:t.angle??90,scale:(t.scale??100)/100,reverse:t.reverse===!0,align:!0}}}function W(e,t,s){const i={scale:1},a=o=>o.enabled!==!1,c=(o,r)=>({present:!0,showInDialog:!0,enabled:a(o),blendMode:O[o.blendMode??r.blendMode],opacity:(o.opacity??r.opacity??100)/100}),n=$;if(e.dropShadow){const o=e.dropShadow;i.dropShadow=[{...c(o,n.dropShadow),color:u(o.color??n.dropShadow.color),angle:o.angle??n.dropShadow.angle,useGlobalLight:!1,distance:d(o.distance??n.dropShadow.distance),choke:d(o.spread??n.dropShadow.spread),size:d(o.size??n.dropShadow.size),layerConceals:!0}]}if(e.innerShadow){const o=e.innerShadow;i.innerShadow=[{...c(o,n.innerShadow),color:u(o.color??n.innerShadow.color),angle:o.angle??n.innerShadow.angle,useGlobalLight:!1,distance:d(o.distance??n.innerShadow.distance),choke:d(o.choke??n.innerShadow.choke),size:d(o.size??n.innerShadow.size)}]}if(e.outerGlow){const o=e.outerGlow;i.outerGlow={...c(o,n.outerGlow),color:u(o.color??n.outerGlow.color),technique:"softer",choke:d(o.spread??n.outerGlow.spread),size:d(o.size??n.outerGlow.size),range:.5}}if(e.innerGlow){const o=e.innerGlow;i.innerGlow={...c(o,n.innerGlow),color:u(o.color??n.innerGlow.color),technique:"softer",source:o.source??n.innerGlow.source,choke:d(o.choke??n.innerGlow.choke),size:d(o.size??n.innerGlow.size),range:.5}}if(e.stroke){const o=e.stroke;i.stroke=[{...c(o,n.stroke),size:d(o.size??n.stroke.size),position:o.position??n.stroke.position,fillType:"color",color:u(o.color??n.stroke.color)}]}if(e.colorOverlay){const o=e.colorOverlay;i.solidFill=[{...c(o,n.colorOverlay),color:u(o.color??n.colorOverlay.color)}]}if(e.gradientOverlay){const o=e.gradientOverlay,r=o.gradient??n.gradientOverlay.gradient;i.gradientOverlay=[{...c(o,n.gradientOverlay),gradient:L({...r,stops:[...r.stops]}),type:r.style??"linear",angle:r.angle??90,scale:(r.scale??100)/100,reverse:r.reverse===!0,align:!0,offset:{x:0,y:0}}]}if(e.patternOverlay&&p(t,"omitted","the pattern overlay: ag-psd writes no pattern's pixels into the file",s),e.satin){const o=e.satin;i.satin={...c(o,n.satin),color:u(o.color??n.satin.color),angle:o.angle??n.satin.angle,distance:d(o.distance??n.satin.distance),size:d(o.size??n.satin.size),invert:o.invert??n.satin.invert}}if(e.bevelEmboss){const o=e.bevelEmboss,r=n.bevelEmboss;i.bevel={present:!0,showInDialog:!0,enabled:a(o),style:"inner bevel",technique:"smooth",strength:(o.depth??r.depth)/100,direction:o.direction??r.direction,size:d(o.size??r.size),soften:d(o.soften??r.soften),angle:o.angle??r.angle,altitude:o.altitude??r.altitude,useGlobalLight:!1,highlightBlendMode:O[o.highlightMode??r.highlightMode],highlightColor:u(o.highlightColor??r.highlightColor),highlightOpacity:(o.highlightOpacity??r.highlightOpacity)/100,shadowBlendMode:O[o.shadowMode??r.shadowMode],shadowColor:u(o.shadowColor??r.shadowColor),shadowOpacity:(o.shadowOpacity??r.shadowOpacity)/100}}const l=Object.keys(i).length>1;return l&&p(t,"approximate","layer styles: Photoshop draws its effects by its own engine (its blurs, its bevel's lighting), which AllyHub's SVG filters follow by its published dialog's numbers",s),l?i:void 0}const N=e=>{const t=m.levels;return{shadowInput:e?.inputBlack??t.inputBlack,highlightInput:e?.inputWhite??t.inputWhite,shadowOutput:e?.outputBlack??t.outputBlack,highlightOutput:e?.outputWhite??t.outputWhite,midtoneInput:e?.gamma??t.gamma}},H={reds:[315,345,15,45],yellows:[15,45,75,105],greens:[75,105,135,165],cyans:[135,165,195,225],blues:[195,225,255,285],magentas:[255,285,315,345]},q=new Set(["brightnessContrast","hueSaturation","vibrance","colorBalance","blackAndWhite","photoFilter"]);function _(e){switch(e.kind){case"levels":return{type:"levels",channels:[e.rgb,e.red,e.green,e.blue].map(N)};case"curves":{const t=s=>(s??[]).map(([i,a])=>({input:i,output:a}));return{type:"curves",channels:[t(e.rgb??m.curves.rgb),t(e.red),t(e.green),t(e.blue)]}}case"brightnessContrast":return{type:"brightness/contrast",brightness:e.brightness??0,contrast:e.contrast??0,meanValue:127,useLegacy:e.useLegacy??!0,labColorOnly:!1};case"hueSaturation":return{type:"hue/saturation",colorize:e.colorize===!0,colorization:{hue:0,saturation:25,lightness:0},master:{hue:e.hue??0,saturation:e.saturation??0,lightness:e.lightness??0},...Object.fromEntries(Object.entries(H).map(([t,[s,i,a,c]])=>[t,{a:s,b:i,c:a,d:c,hue:0,saturation:0,lightness:0}]))};case"vibrance":return{type:"vibrance",vibrance:e.vibrance??0,saturation:e.saturation??0};case"colorBalance":{const t=s=>({cyanRed:s?.[0]??0,magentaGreen:s?.[1]??0,yellowBlue:s?.[2]??0});return{type:"color balance",shadows:t(e.shadows),midtones:t(e.midtones),highlights:t(e.highlights),preserveLuminosity:e.preserveLuminosity??!0}}case"blackAndWhite":{const t=m.blackAndWhite;return{type:"black & white",reds:e.reds??t.reds,yellows:e.yellows??t.yellows,greens:e.greens??t.greens,cyans:e.cyans??t.cyans,blues:e.blues??t.blues,magentas:e.magentas??t.magentas,useTint:!1,tintColor:{r:225,g:211,b:179}}}case"photoFilter":{const t=m.photoFilter;return{type:"photo filter",color:u(e.color??t.color),density:(e.density??t.density)/100,preserveLuminosity:e.preserveLuminosity??t.preserveLuminosity}}case"invert":return{type:"invert"};case"threshold":return{type:"threshold",level:e.level??m.threshold.level};case"gradientMap":{const t=L({...e.gradient??m.gradientMap.gradient,stops:[...(e.gradient??m.gradientMap.gradient).stops]});return{type:"gradient map",name:"Custom",gradientType:"solid",reverse:e.reverse===!0,dither:!1,smoothness:1,colorStops:t.colorStops.map(s=>({...s,location:Math.round(s.location*4096)})),opacityStops:t.opacityStops.map(s=>({...s,location:Math.round(s.location*4096)}))}}case"exposure":return{type:"exposure",exposure:e.exposure??0,offset:e.offset??0,gamma:e.gammaCorrection??1}}}function V(e,t){const s=e.text;if(!s)return;const i=t.board.resolution,a=b=>b*72/i,c=s.characterStyle,n=c.size??S.size,l=c.font??s.family??"Arial",o=postScriptName(l,c.weight??S.weight,c.italic===!0),r=k(c.color??S.color);r.a<1&&p(t,"approximate","a type layer's colour has an alpha, which Photoshop's text colour does not: written opaque",e.key),p(t,"approximate","type: Photoshop redraws the words (it asks to update the text layers when the file opens) by its own composer, so line breaks and baselines may move",e.key),p(t,"approximate",`the font is named ${o}: a PostScript name made from its family and weight by the usual convention; Photoshop shows another where it has none of that name`,e.key);const[h,g,f,w,z,T]=e.matrix,G=(b,x)=>[h*b+f*x+z,g*b+w*x+T],y=s.paragraphStyle;let v;if(s.box)v=G(s.box[0],s.box[1]);else{const[b,x]=s.position??[0,0];let M=s.baseline;M===void 0&&(M=x+n*.9,p(t,"approximate","a type layer's baseline was not drawn (it is hidden), so it is put 0.9 of its size under its top",e.key)),v=G(b,M)}const B={font:{name:o},fontSize:a(n),fillColor:{r:r.r,g:r.g,b:r.b},tracking:c.tracking??0,...c.leading===void 0||c.leading==="auto"?{autoLeading:!0}:{autoLeading:!1,leading:a(c.leading)},fontCaps:c.capitalization==="allCaps"?2:c.capitalization==="smallCaps"?1:0,underline:c.underline===!0,strikethrough:c.strikeThrough===!0};return{text:s.contents,transform:[h,g,f,w,v[0],v[1]],antiAlias:"smooth",style:B,paragraphStyle:{justification:U[y.justification??"left"],firstLineIndent:a(y.firstLineIndent??0),startIndent:a(y.leftIndent??0),endIndent:a(y.rightIndent??0),spaceBefore:a(y.spaceBefore??0),spaceAfter:a(y.spaceAfter??0),autoLeading:S.autoLeading},...s.box?{shapeType:"box",boxBounds:[0,0,s.box[2],s.box[3]]}:{shapeType:"point"}}}function P(e,t){const s=e.kind==="group",i={name:e.key,id:t.id++,blendMode:O[e.blendMode??(s?"passThrough":"normal")],opacity:(e.opacity??100)/100,hidden:e.hidden,blendClippendElements:!0,...e.clipping===!0?{clipping:!0}:{},...e.fillOpacity===void 0?{}:{fillOpacity:e.fillOpacity/100}},a=t.px.layers.get(e.key),c=()=>{a&&(i.left=a.left,i.top=a.top,i.right=a.left+a.img.width,i.bottom=a.top+a.img.height,i.imageData=D(a.img))};if(e.effects){const l=W(e.effects,t,e.key);l&&(i.effects=l)}const n=e.mask;if(n?.kind==="vector"){const[l,o]=n.at,[r,h,g,f,w,z]=e.matrix;i.vectorMask={paths:C(n.path,[r,h,g,f,r*l+g*o+w,h*l+f*o+z]),...n.invert?{invert:!0}:{},...n.enabled?{}:{disable:!0}},(n.density!==100||n.feather!==0)&&(i.mask={...n.density===100?{}:{vectorMaskDensity:n.density/100},...n.feather===0?{}:{vectorMaskFeather:n.feather},fromVectorData:!0})}else if(n?.kind==="raster"){const l=t.px.masks.get(e.key);l?i.mask={left:l.left,top:l.top,right:l.left+l.img.width,bottom:l.top+l.img.height,defaultColor:0,...n.enabled?{}:{disabled:!0},...n.density===100?{}:{userMaskDensity:n.density/100},...n.feather===0?{}:{userMaskFeather:n.feather},imageData:D(l.img)}:i.mask={left:0,top:0,right:1,bottom:1,defaultColor:0,...n.enabled?{}:{disabled:!0},imageData:{width:1,height:1,data:new Uint8ClampedArray([0,0,0,255])}}}switch(n&&n.feather>0&&p(t,"approximate","a mask's feather: AllyHub's is a Gaussian's standard deviation, Photoshop's its own blur of that radius",e.key),e.kind){case"group":i.children=(e.layers??[]).map(l=>P(l,t)),i.opened=!0;break;case"adjustment":e.adjustment&&(i.adjustment=_(e.adjustment),q.has(e.adjustment.kind)&&p(t,"approximate",`${e.adjustment.kind}: Photoshop publishes no formula for it, so it draws its own way the numbers AllyHub draws by its stated one`,e.key));break;case"type":{const l=V(e,t);l&&(i.text=l),c();break}case"shape":{const l=e.shape,o=l?.fill?I(l.fill):{type:"color",color:u("#000000")};if(!l||!o){p(t,"pixels","a shape filled with a pattern: written as a pixel layer, its path as its vector mask (ag-psd writes no pattern's pixels)",e.key),c(),l&&(i.vectorMask={paths:C(l.path,e.matrix)});break}const r=l.stroke,h=r?k(r.color??"#000000"):void 0;i.vectorFill=o,i.vectorStroke={strokeEnabled:r!==null,fillEnabled:l.fill!==null,lineWidth:d(r?.width??1),lineDashOffset:d(0),miterLimit:100,lineCapType:r?.cap??"butt",lineJoinType:r?.join??"miter",lineAlignment:r?.alignment??"center",scaleLock:!1,strokeAdjust:!1,lineDashSet:(r?.dashes??[]).map(g=>({units:"None",value:g})),blendMode:"normal",opacity:(r?.opacity??100)/100*(h?.a??1),content:{type:"color",color:h?{r:h.r,g:h.g,b:h.b}:{r:0,g:0,b:0}},resolution:t.board.resolution},i.vectorMask={paths:C(l.path,e.matrix)},c();break}case"fill":{const l=e.fill?I(e.fill):void 0;l?i.vectorFill=l:p(t,"pixels","a pattern fill: written as a pixel layer (ag-psd writes no pattern's pixels)",e.key),c();break}case"smartObject":{if(c(),a){const l=new Uint8Array(F(a.img)),o=A("linked",t.board.key,e.key,l);t.linked.push({id:o,name:`${e.key}.png`,type:"png ",creator:"8BIM",data:l});const[r,h,g,f]=[a.left,a.top,a.left+a.img.width,a.top+a.img.height];i.placedLayer={id:o,placed:A("placed",t.board.key,e.key,l),type:"raster",transform:[r,h,g,h,g,f,r,f],width:a.img.width,height:a.img.height,resolution:{units:"Density",value:t.board.resolution}},p(t,"pixels","a component: a smart object holding its pixels as drawn (an embedded PNG); its code and props are not in the file",e.key)}break}default:c()}return i}function J(e){const t=i=>i.replace(/&/gu,"&").replace(/"/gu,""").replace(/</gu,"<"),s=`${String(Math.round(e.resolution*1e4))}/10000`;return`<?xpacket begin="\uFEFF" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" photoshop:ColorMode="3" photoshop:ICCProfile="${t(e.colorProfile)}" tiff:XResolution="${s}" tiff:YResolution="${s}" tiff:ResolutionUnit="2"><dc:title><rdf:Alt><rdf:li xml:lang="x-default">${t(e.title??e.key)}</rdf:li></rdf:Alt></dc:title></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="w"?>`}export function psdOf(e,t){const s={board:e,px:t,notes:[],linked:[],id:1},i=e.layers.map(h=>P(h,s)),a=e.background,c=a==="transparent"||k(a).a===0,n=c?void 0:k(a),l=c?3:n?.r===255&&n.g===255&&n.b===255?1:n?.r===0&&n.g===0&&n.b===0?2:4;n&&n.a<1&&p(s,"approximate",`the board's background ${a} has an alpha, which an artboard's colour does not: written opaque`);const o={name:e.title??e.key,id:s.id++,blendMode:"pass through",opacity:1,children:i,opened:!0,artboard:{rect:{top:0,left:0,bottom:e.height,right:e.width},presetName:"",...n?{color:{r:n.r,g:n.g,b:n.b}}:{},backgroundType:l}};return e.colorProfile!=="sRGB IEC61966-2.1"&&p(s,"approximate",`the board's colour profile ${e.colorProfile} is named in the file's metadata; its pixels are sRGB, as Chrome draws them`),p(s,"omitted","the colour profile's bytes: it is named in the file's metadata (XMP's photoshop:ICCProfile), and Photoshop gives an untagged file its working space"),{psd:{width:e.width,height:e.height,channels:4,bitsPerChannel:8,children:[o],imageData:D(t.composite),...s.linked.length>0?{linkedFiles:s.linked}:{},artboards:{count:1},imageResources:{resolutionInfo:{horizontalResolution:e.resolution,horizontalResolutionUnit:"PPI",widthUnit:"Inches",verticalResolution:e.resolution,verticalResolutionUnit:"PPI",heightUnit:"Inches"},xmpMetadata:J(e)}},fidelity:s.notes}}export async function writeBoardPsd(e,t,s={}){const{writePsdUint8Array:i}=await R(),{psd:a,fidelity:c}=psdOf(e,t);return{bytes:i(a,{invalidateTextLayers:!0,noBackground:!0,...(s.format??PSD_DEFAULTS.format)==="psb"?{psb:!0}:{}}),fidelity:c}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{
|
|
2
|
+
import{firstUse as N}from"@allyhub/runtimes";export const pdfLib=N("pdf-lib",()=>import("pdf-lib"));const O=(n,o)=>/^[\x20-\x7e]*$/u.test(o)&&!/[()\\]/u.test(o)?n.PDFString.of(o):n.PDFHexString.fromText(o);function j(){const n=process.env.SOURCE_DATE_EPOCH;if(!(n===void 0||!/^\d+$/u.test(n)))return new Date(Number(n)*1e3)}export async function finishPdf(n,o){const d=await pdfLib(),{PDFDict:F,PDFDocument:b,PDFName:e,PDFNull:x,PDFNumber:w}=d,t=await b.load(n,{updateMetadata:!1}),a=t.context.lookup(t.context.trailerInfo.Info),r=j();r?(t.setCreationDate(r),t.setModificationDate(r)):a instanceof F&&(a.delete(e.of("CreationDate")),a.delete(e.of("ModDate"))),o.title!==void 0&&o.title!==""&&t.setTitle(o.title,{showInWindowTitleBar:!0});const D=t.getPages(),l=(o.outline??[]).slice(0,D.length);if(l.length>0){const u=t.context.nextRef(),s=l.map(()=>t.context.nextRef());l.forEach((C,i)=>{const p=D[i],g=s[i];if(!p||!g)return;const f=t.context.obj({});f.set(e.of("Title"),O(d,C)),f.set(e.of("Parent"),u),f.set(e.of("Dest"),t.context.obj([p.ref,e.of("Fit")]));const m=s[i-1],P=s[i+1];m&&f.set(e.of("Prev"),m),P&&f.set(e.of("Next"),P),t.context.assign(g,f)});const c=t.context.obj({});c.set(e.of("Type"),e.of("Outlines"));const T=s[0],h=s.at(-1);c.set(e.of("First"),T??x),c.set(e.of("Last"),h??x),c.set(e.of("Count"),w.of(s.length)),t.context.assign(u,c),t.catalog.set(e.of("Outlines"),u)}return Buffer.from(await t.save({useObjectStreams:!1}))}
|