Skip to content

Commit

Permalink
release: 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Dec 26, 2023
1 parent 2bd7a05 commit 24b2b99
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ These features enrich Obsidian as a stand-alone PDF annotation tool.

- **Click PDF embeds to open links**: Clicking a PDF embed will open the embedded file.
- **Trim selection embeds**: When embedding a selection from a PDF file, only the selection and its surroundings are displayed rather than the entire page.
- **Hide toolbar in PDF embeds with a page specified**: Requires the [Style Settings](https://github.com/mgmeyers/obsidian-style-settings) plugin.
- **Never show sidebar in PDF embeds**
- **Do not clear highlights in a selection/annotation embeds**
- **Make PDF embeds unscrollable**
- **Zoom in PDF embeds (experimental)**
- **Hide toolbar in PDF embeds with a page specified**: Requires the [Style Settings](https://github.com/mgmeyers/obsidian-style-settings) plugin.
- **PDF embed width**: Requires the [Style Settings](https://github.com/mgmeyers/obsidian-style-settings) plugin.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.10.8",
"version": "0.11.0",
"minAppVersion": "1.4.16",
"description": "Transform backlinks to PDF files into highlighted annotations, establishing Obsidian as a stand-alone PDF annotation tool. It also adds quality-of-life improvements to Obsidian's built-in PDF viewer and PDF embeds.",
"author": "Ryota Ushio",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-pdf-plus",
"version": "0.10.8",
"version": "0.11.0",
"description": "An Obsidian.md plugin to transform backlinks to PDF files into highlighted annotations, establishing Obsidian as a stand-alone PDF annotation tool. It also adds quality-of-life improvements to Obsidian's built-in PDF viewer and PDF embeds.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BacklinkHighlighter } from 'highlight';
import { ColorPalette } from 'color-palette';
import { DEFAULT_SETTINGS, PDFPlusSettings, PDFPlusSettingTab } from 'settings';
import { copyLinkToSelection, isHexString, iterateBacklinkViews, iteratePDFViews } from 'utils';
import { PDFView, PDFViewerChild } from 'typings';
import { PDFEmbed, PDFView, PDFViewerChild } from 'typings';
import { BacklinkPanePDFManager } from 'backlink';


Expand Down Expand Up @@ -89,6 +89,20 @@ export default class PDFPlus extends Plugin {
});
});

const originalPDFEmbedCreator = this.app.embedRegistry.embedByExtension['pdf'];
this.app.embedRegistry.unregisterExtension('pdf');
this.app.embedRegistry.registerExtension('pdf', (info, file, subpath) => {
const embed = originalPDFEmbedCreator(info, file, subpath) as PDFEmbed;
embed.viewer.then((child) => {
if (this.settings.noSidebarInEmbed) {
child.pdfViewer.pdfSidebar.open = function () {
this.close();
};
}
});
return embed;
});

this.registerHoverLinkSource('pdf-plus', {
defaultMod: true,
display: 'PDF++ hover action'
Expand Down Expand Up @@ -149,7 +163,7 @@ export default class PDFPlus extends Plugin {

styleEl.textContent = Object.entries(this.settings.colors).map(([name, color]) => {
return isHexString(color) ? (
`.textLayer .mod-focused.pdf-plus-backlink[data-highlight-color="${name.toLowerCase()}"] {
`.textLayer .mod-focused.pdf-plus-backlink[data-highlight-color="${name.toLowerCase()}"] {
background-color: ${color};
}`
) : '';
Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const COLOR_PALETTE_ACTIONS = {
export interface PDFPlusSettings {
alias: boolean;
trimSelectionEmbed: boolean;
noSidebarInEmbed: boolean;
embedUnscrollable: boolean;
zoomInEmbed: number;
openLinkCleverly: boolean;
Expand All @@ -49,11 +50,13 @@ export interface PDFPlusSettings {
hoverPDFLinkToOpen: boolean;
ignoreHeightParamInPopoverPreview: boolean;
filterBacklinksByPageDefault: boolean;

}

export const DEFAULT_SETTINGS: PDFPlusSettings = {
alias: true,
trimSelectionEmbed: true,
noSidebarInEmbed: true,
embedUnscrollable: false,
zoomInEmbed: 0,
openLinkCleverly: true,
Expand Down Expand Up @@ -399,6 +402,8 @@ export class PDFPlusSettingTab extends PluginSettingTab {
this.addToggleSetting('trimSelectionEmbed')
.setName('Trim selection/annotation embeds')
.setDesc('When embedding a selection or an annotation from a PDF file, only the target selection/annotation and its surroundings are displayed rather than the entire page.');
this.addToggleSetting('noSidebarInEmbed')
.setName('Never show sidebar in PDF embeds');
this.addToggleSetting('persistentHighlightsInEmbed')
.setName('Do not clear highlights in a selection/annotation embeds');
this.addToggleSetting('embedUnscrollable')
Expand Down
21 changes: 20 additions & 1 deletion src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,23 @@ interface ObsidianViewer {
isEmbed: boolean;
eventBus: EventBus;
pdfViewer: RawPDFViewer;
pdfLoadingTask: { promise: Promise<PDFDocumentProxy> };
pdfSidebar: PDFSidebar;
toolbar?: PDFToolbar;
pdfLoadingTask: { promise: Promise<PDFDocumentProxy> };
setHeight(height?: number | "page" | "auto"): void;
applySubpath(subpath: string): void;
zoomIn(): void;
/** Added by this plugin */
_zoomedIn?: number;
}

interface PDFSidebar {
isOpen: boolean;
open(): void;
close(): void;
toggle(open: boolean): void;
}

interface PDFToolbar {
pdfViewer: ObsidianViewer;
pageNumber: number;
Expand Down Expand Up @@ -151,6 +159,17 @@ interface TextContentItem {
interface EventBus {
on(name: string, callback: Function): void;
off(name: string, callback: Function): void;
dispatch(name: string, data: { source?: any }): void;
dispatch(name: 'togglesidebar', data: { open: boolean, source?: any }): void;
}

interface PDFEmbed extends Component {
app: App;
file: TFile;
subpath?: string;
containerEl: HTMLElement;
viewer: PDFViewer;
loadFile(file: TFile, subpath?: string): Promise<void>;
}

/** Backlink view */
Expand Down

0 comments on commit 24b2b99

Please sign in to comment.