import {Constants} from "../constants"; /// #if !MOBILE import {getAllModels} from "../layout/getAll"; /// #endif import {pathPosix} from "../util/pathName"; import * as dayjs from "dayjs"; export const renderAssetsPreview = (pathString: string) => { if (!pathString) { return ""; } const type = pathPosix().extname(pathString).toLowerCase(); if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) { return ``; } else if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) { return ``; } else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) { return ``; } else { return pathString; } }; export const pdfResize = () => { /// #if !MOBILE getAllModels().asset.forEach(item => { const pdfInstance = item.pdfObject; if (!pdfInstance) { return; } const {pdfDocument, pdfViewer} = pdfInstance; if (!pdfDocument) { return; } // https://github.com/siyuan-note/siyuan/issues/8097 const pdfViewerElement = item.element.querySelector("#viewerContainer"); if (pdfViewerElement.clientHeight === 0) { return; } if (pdfViewerElement) { // https://github.com/siyuan-note/siyuan/issues/6890 const scrollTop = pdfViewerElement.getAttribute("data-scrolltop"); if (scrollTop) { pdfViewerElement.scrollTo(0, parseInt(scrollTop)); pdfViewerElement.removeAttribute("data-scrolltop"); } } const currentScaleValue = pdfViewer.currentScaleValue; if ( currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width" ) { // Note: the scale is constant for 'page-actual'. pdfViewer.currentScaleValue = currentScaleValue; } pdfViewer.update(); }); /// #endif }; export const genAssetHTML = (type: string, pathString: string, imgName: string, linkName: string) => { let html = ""; if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) { html = `
${Constants.ZWSP}
${Constants.ZWSP}
`; } else if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) { let netHTML = ""; if (!pathString.startsWith("assets/")) { netHTML = ''; } html = ` ${imgName}${netHTML} `; } else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) { html = `
${Constants.ZWSP}
${Constants.ZWSP}
`; } else { html = `${linkName}`; } return html; };