diff --git a/manifest.json b/manifest.json index 4cc2c7a0..bd601159 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "pdf-plus", "name": "PDF++", - "version": "0.1.0", + "version": "0.2.0", "minAppVersion": "1.3.5", "description": "Enhance PDF viewer & embeds.", "author": "Ryota Ushio", diff --git a/package-lock.json b/package-lock.json index 42b3a663..e62246b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-pdf-plus", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-pdf-plus", - "version": "0.1.0", + "version": "0.2.0", "license": "MIT", "dependencies": { "@codemirror/language": "^6.9.1", diff --git a/package.json b/package.json index 47e22b90..9ab907c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-pdf-plus", - "version": "0.1.0", + "version": "0.2.0", "description": "An Obsidian.md plugin to enhance PDF viewer & embeds.", "scripts": { "dev": "node esbuild.config.mjs", diff --git a/src/patch.ts b/src/patch.ts index 69e89608..6e4c06bf 100644 --- a/src/patch.ts +++ b/src/patch.ts @@ -33,18 +33,23 @@ export const patchPDF = (plugin: PDFPlus): boolean => { if (beginSelectionEl && endSelectionEl) { height = endSelectionEl.getBoundingClientRect().bottom - beginSelectionEl.getBoundingClientRect().top; height += plugin.settings.padding; - console.log({ height }); } } + if (self.isEmbed && !self._zoomedIn) { + self._zoomedIn = true; + setTimeout(async () => { + for (let i = 0; i < plugin.settings.zoomInEmbed; i++) { + self.zoomIn(); + await new Promise((resolve) => { + setTimeout(resolve, 50); + }) + } + }, 100); + } + old.call(this, height); } - }, - applySubpath(old) { - return function (subpath: string) { - console.log({ subpath }); - return old.call(this, subpath); - } } })); diff --git a/src/settings.ts b/src/settings.ts index 7962670e..b13107b5 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -7,6 +7,7 @@ export interface PDFPlusSettings { trimSelectionEmbed: boolean; padding: number; embedUnscrollable: boolean; + zoomInEmbed: number; } export const DEFAULT_SETTINGS: PDFPlusSettings = { @@ -14,6 +15,7 @@ export const DEFAULT_SETTINGS: PDFPlusSettings = { trimSelectionEmbed: true, padding: 80, embedUnscrollable: false, + zoomInEmbed: 1 }; // Inspired by https://stackoverflow.com/a/50851710/13613783 @@ -120,6 +122,8 @@ export class PDFPlusSettingTab extends PluginSettingTab { .setName('Trim selection embeds'); this.addToggleSetting('embedUnscrollable') .setName('Make PDF embeds unscrollable'); + this.addSliderSetting('zoomInEmbed', 0, 5, 1) + .setName('Zoom level for PDF embeds'); this.addDesc('You can find more options in Style Settings.') .addButton((button) => { diff --git a/src/typings.d.ts b/src/typings.d.ts index c7852ef4..e33c2907 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -46,6 +46,8 @@ interface ObsidianViewer { isEmbed: boolean; setHeight(height?: number | "page" | "auto"): void; applySubpath(subpath: string): void; + zoomIn(): void; + _zoomedIn?: boolean; } interface AppSetting extends Modal { diff --git a/styles.css b/styles.css index ce19834c..42626e2a 100644 --- a/styles.css +++ b/styles.css @@ -7,9 +7,24 @@ settings: id: hide-pdf-embed-toolbar title: Hide toolbar in PDF embeds with a page specified type: class-toggle - + default: true + - + id: pdf-embed-width + title: PDF embed width + type: variable-number-slider + min: 10 + max: 200 + step: 1 + default: 100 */ .hide-pdf-embed-toolbar .pdf-embed[src*="#"] .pdf-toolbar { display: none; +} + +.markdown-preview-view .pdf-embed, +.markdown-source-view.mod-cm6 .cm-content .pdf-embed { + margin-left: auto !important; + margin-right: auto !important; + width: calc(var(--pdf-embed-width) / 100 * 100%) !important; } \ No newline at end of file