mirror of
https://github.com/youfoundjk/TeXcore.git
synced 2026-07-22 07:33:31 +00:00
fix: obsidian-export-better-pdf updated syntax to match latest version of node libs
This commit is contained in:
parent
e4d60f4d65
commit
47b7ad4639
5 changed files with 22 additions and 17 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import merge from "deepmerge";
|
||||
import * as merge from "deepmerge";
|
||||
import en from "./en";
|
||||
import zh from "./zh";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { ExportConfigModal, type TConfig } from "./modal";
|
|||
import ConfigSettingTab from "./setting";
|
||||
import { traverseFolder } from "./utils";
|
||||
import * as fs from "fs/promises";
|
||||
import path from "path";
|
||||
import * as path from "path";
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as electron from "electron";
|
||||
import * as fs from "fs/promises";
|
||||
import { ButtonComponent, type FrontMatterCache, Modal, Setting, TFile, TFolder, debounce } from "obsidian";
|
||||
import path from "path";
|
||||
import * as path from "path";
|
||||
import { PageSize } from "./constant";
|
||||
import i18n, { type Lang } from "./i18n";
|
||||
import BetterExportPdfPlugin from "./main";
|
||||
|
|
@ -11,10 +11,10 @@ import { isNumber, mm2px, px2mm, safeParseFloat, safeParseInt, traverseFolder }
|
|||
import Progress from "./Progress.svelte";
|
||||
import { mount, unmount } from "svelte";
|
||||
import pLimit from "p-limit";
|
||||
export type PageSizeType = electron.PrintToPDFOptions["pageSize"];
|
||||
export type PageSizeType = Electron.PrintToPDFOptions["pageSize"];
|
||||
|
||||
export interface TConfig {
|
||||
pageSize: PageSizeType | "Custom";
|
||||
pageSize: string;
|
||||
pageWidth?: string;
|
||||
pageHeight?: string;
|
||||
|
||||
|
|
@ -55,8 +55,8 @@ export class ExportConfigModal extends Modal {
|
|||
callback: Callback;
|
||||
plugin: BetterExportPdfPlugin;
|
||||
file: TFile | TFolder;
|
||||
preview: electron.WebviewTag;
|
||||
webviews: electron.WebviewTag[];
|
||||
preview: Electron.WebViewElement;
|
||||
webviews: Electron.WebViewElement[];
|
||||
previewDiv: HTMLDivElement;
|
||||
completed: boolean;
|
||||
docs: DocType[];
|
||||
|
|
@ -430,7 +430,7 @@ export class ExportConfigModal extends Modal {
|
|||
});
|
||||
}),
|
||||
);
|
||||
const pageSizes: (PageSizeType | "Custom")[] = [
|
||||
const pageSizes: string[] = [
|
||||
"A0",
|
||||
"A1",
|
||||
"A2",
|
||||
|
|
@ -449,7 +449,7 @@ export class ExportConfigModal extends Modal {
|
|||
.addOptions(Object.fromEntries(pageSizes.map((size) => [size, size])))
|
||||
.setValue(this.config.pageSize as string)
|
||||
.onChange(async (value: string) => {
|
||||
this.config["pageSize"] = value as PageSizeType;
|
||||
this.config["pageSize"] = value;
|
||||
if (value == "Custom") {
|
||||
sizeEl.settingEl.hidden = false;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import electron, { type WebviewTag } from "electron";
|
||||
import * as electron from "electron";
|
||||
import * as fs from "fs/promises";
|
||||
import { type FrontMatterCache } from "obsidian";
|
||||
import { PDFArray, PDFDict, PDFDocument, PDFHexString, PDFName, PDFRef, StandardFonts } from "pdf-lib";
|
||||
|
|
@ -368,7 +368,7 @@ export function setMetadata(
|
|||
export async function exportToPDF(
|
||||
outputFile: string,
|
||||
config: TConfig & BetterExportPdfPluginSettings,
|
||||
w: WebviewTag,
|
||||
w: Electron.WebViewElement,
|
||||
{ doc, frontMatter }: DocType,
|
||||
) {
|
||||
console.log("output pdf:", outputFile);
|
||||
|
|
@ -384,7 +384,7 @@ export async function exportToPDF(
|
|||
if (scale > 200 || scale < 10) {
|
||||
scale = 100;
|
||||
}
|
||||
const printOptions: electron.PrintToPDFOptions = {
|
||||
const printOptions: any = {
|
||||
landscape: config?.["landscape"],
|
||||
printBackground: config?.["printBackground"],
|
||||
generateTaggedPDF: config?.["generateTaggedPDF"],
|
||||
|
|
@ -434,7 +434,12 @@ export async function exportToPDF(
|
|||
}
|
||||
|
||||
try {
|
||||
let data = await w.printToPDF(printOptions);
|
||||
let data: Uint8Array = await new Promise<Buffer>((resolve, reject) => {
|
||||
(w as any).printToPDF(printOptions, (error: any, data: Buffer) => {
|
||||
if (error) return reject(error);
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
|
||||
data = await editPDF(data, {
|
||||
headings: getHeadingTree(doc),
|
||||
|
|
@ -456,7 +461,7 @@ export async function exportToPDF(
|
|||
|
||||
export async function getOutputFile(filename: string, isTimestamp?: boolean) {
|
||||
// @ts-ignore
|
||||
const result = await electron.remote.dialog.showSaveDialog({
|
||||
const result: Electron.SaveDialogReturnValue = await electron.remote.dialog.showSaveDialog({
|
||||
title: "Export to PDF",
|
||||
defaultPath: filename + (isTimestamp ? "-" + Date.now() : "") + ".pdf",
|
||||
filters: [
|
||||
|
|
@ -464,7 +469,7 @@ export async function getOutputFile(filename: string, isTimestamp?: boolean) {
|
|||
{ name: "PDF", extensions: ["pdf"] },
|
||||
],
|
||||
properties: ["showOverwriteConfirmation", "createDirectory"],
|
||||
});
|
||||
} as any);
|
||||
|
||||
if (result.canceled) {
|
||||
return;
|
||||
|
|
@ -474,7 +479,7 @@ export async function getOutputFile(filename: string, isTimestamp?: boolean) {
|
|||
|
||||
export async function getOutputPath(filename: string, isTimestamp?: boolean) {
|
||||
// @ts-ignore
|
||||
const result = await electron.remote.dialog.showOpenDialog({
|
||||
const result: Electron.OpenDialogReturnValue = await electron.remote.dialog.showOpenDialog({
|
||||
title: "Export to PDF",
|
||||
defaultPath: filename,
|
||||
properties: ["openDirectory"],
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ export function createWebview(scale = 1.25) {
|
|||
border: 1px solid #f2f2f2;
|
||||
`,
|
||||
);
|
||||
webview.nodeintegration = true;
|
||||
webview.setAttribute("nodeintegration", "true");
|
||||
return webview;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue