2022-07-16 23:20:50 +08:00
|
|
|
import {Constants} from "../constants";
|
2022-09-09 20:40:35 +08:00
|
|
|
/// #if !MOBILE
|
2022-09-07 21:51:17 +08:00
|
|
|
import {getAllModels} from "../layout/getAll";
|
2022-09-09 20:40:35 +08:00
|
|
|
/// #endif
|
|
|
|
|
import {pathPosix} from "../util/pathName";
|
2022-07-16 23:20:50 +08:00
|
|
|
|
|
|
|
|
export const renderAssetsPreview = (pathString: string) => {
|
2022-08-18 23:47:22 +08:00
|
|
|
if (!pathString) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2022-07-17 11:06:57 +08:00
|
|
|
const type = pathPosix().extname(pathString).toLowerCase();
|
2022-07-16 23:20:50 +08:00
|
|
|
if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
|
|
|
|
|
return `<img style="max-height: 100%" src="${pathString}">`;
|
|
|
|
|
} else if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) {
|
|
|
|
|
return `<audio style="max-width: 100%" controls="controls" src="${pathString}"></audio>`;
|
|
|
|
|
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) {
|
|
|
|
|
return `<video style="max-width: 100%" controls="controls" src="${pathString}"></video>`;
|
|
|
|
|
} else {
|
2022-08-30 17:58:28 +08:00
|
|
|
return pathString;
|
2022-07-16 23:20:50 +08:00
|
|
|
}
|
2022-07-17 11:06:57 +08:00
|
|
|
};
|
2022-09-07 21:51:17 +08:00
|
|
|
|
|
|
|
|
export const pdfResize = () => {
|
2022-09-09 20:40:35 +08:00
|
|
|
/// #if !MOBILE
|
2022-09-07 22:19:58 +08:00
|
|
|
getAllModels().asset.forEach(item => {
|
|
|
|
|
const pdfInstance = item.pdfObject;
|
|
|
|
|
if (!pdfInstance) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const {pdfDocument, pdfViewer} = pdfInstance;
|
2022-09-07 21:51:17 +08:00
|
|
|
if (!pdfDocument) {
|
2022-09-07 22:19:58 +08:00
|
|
|
return;
|
2022-09-07 21:51:17 +08:00
|
|
|
}
|
2022-09-07 22:19:58 +08:00
|
|
|
const currentScaleValue = pdfViewer.currentScaleValue;
|
2022-09-07 21:51:17 +08:00
|
|
|
if (
|
2022-09-07 22:19:58 +08:00
|
|
|
currentScaleValue === "auto" ||
|
|
|
|
|
currentScaleValue === "page-fit" ||
|
|
|
|
|
currentScaleValue === "page-width"
|
2022-09-07 21:51:17 +08:00
|
|
|
) {
|
|
|
|
|
// Note: the scale is constant for 'page-actual'.
|
2022-09-07 22:19:58 +08:00
|
|
|
pdfViewer.currentScaleValue = currentScaleValue;
|
2022-09-07 21:51:17 +08:00
|
|
|
}
|
2022-09-07 22:19:58 +08:00
|
|
|
pdfViewer.update();
|
|
|
|
|
});
|
2022-09-09 20:40:35 +08:00
|
|
|
/// #endif
|
2022-09-07 22:19:58 +08:00
|
|
|
};
|