repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
hatchet
github_2023
hatchet-dev
typescript
Api.userUpdateGithubAppOauthCallback
metadataGet = (params: RequestParams = {}) => this.request<APICloudMetadata, APIErrors>({ path: `/api/v1/cloud/metadata`, method: "GET", format: "json", ...params, })
/** * @description List Github App branches * * @tags Github * @name GithubAppListBranches * @summary List Github App branches * @request GET:/api/v1/cloud/github-app/installations/{gh-installation}/repos/{gh-repo-owner}/{gh-repo-name}/branches * @secure */
https://github.com/hatchet-dev/hatchet/blob/b6bff6ba2dbbdac4ef5d7cafe8aa6d41bb52eb0a/frontend/app/src/lib/api/generated/cloud/Api.ts
b6bff6ba2dbbdac4ef5d7cafe8aa6d41bb52eb0a
hatchet
github_2023
hatchet-dev
typescript
MyApp
function MyApp({ Component, pageProps }: AppProps) { return ( <LanguageProvider> <PostHogProvider client={posthog}> <main> <Component {...pageProps} /> </main> </PostHogProvider> </LanguageProvider> ); }
// const inter = Inter({ subsets: ["latin"] });
https://github.com/hatchet-dev/hatchet/blob/b6bff6ba2dbbdac4ef5d7cafe8aa6d41bb52eb0a/frontend/docs/pages/_app.tsx#L24-L34
b6bff6ba2dbbdac4ef5d7cafe8aa6d41bb52eb0a
PandoraHelper
github_2023
nianhua99
typescript
onOpenChange
const onOpenChange: MenuProps['onOpenChange'] = (keys) => { const latestOpenKey = keys.find((key) => openKeys.indexOf(key) === -1); if (latestOpenKey) { setOpenKeys(keys); } else { setOpenKeys([]); } };
/** * events */
https://github.com/nianhua99/PandoraHelper/blob/1186fa9869d06e79a491da06e7bf320aa5cad24d/frontend/src/layouts/dashboard/nav-horizontal.tsx#L42-L49
1186fa9869d06e79a491da06e7bf320aa5cad24d
PandoraHelper
github_2023
nianhua99
typescript
setLocale
const setLocale = (locale: Locale) => { i18n.changeLanguage(locale); };
/** * localstorage -> i18nextLng change */
https://github.com/nianhua99/PandoraHelper/blob/1186fa9869d06e79a491da06e7bf320aa5cad24d/frontend/src/locales/useLocale.ts#L37-L39
1186fa9869d06e79a491da06e7bf320aa5cad24d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
listener
const listener = (event: MouseEvent) => { if (isMouseEventExternal(event, backlinkItemEl)) { backlinkItemEl.removeClass('hovered-backlink'); el.removeEventListener('mouseout', listener); } ...
// clear highlights in backlink pane
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/backlink-visualizer.ts#L160-L165
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
RectangleCache.getRectsForSelection
getRectsForSelection(pageNumber: number, id: string) { const idToRects = this.getIdToRectsMap(pageNumber); let rects = idToRects.get(id) ?? null; if (rects) return rects; rects = this.computeRectsForSelection(pageNumber, id); if (rects) { idToRects.set(id, rects); ...
/** * Get the rectangles for the given selection id. * If the rectangles have already been computed, return the cached value. * Otherwise, newly compute and cache them. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/backlink-visualizer.ts#L276-L286
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
RectangleCache.computeRectsForSelection
computeRectsForSelection(pageNumber: number, id: string) { const pageView = this.child.getPage(pageNumber); const { beginIndex, beginOffset, endIndex, endOffset } = PDFPageBacklinkIndex.selectionIdToParams(id); const textLayer = pageView.textLayer; if (!textLayer) return null; c...
/** * Newly compute the rectangles for the given selection id. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/backlink-visualizer.ts#L291-L302
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
BibliographyManager.parseBibliographyText
async parseBibliographyText(text: string): Promise<AnystyleJson[] | null> { const { app, plugin, settings } = this; const anystylePath = settings.anystylePath; if (!anystylePath) return null; const anystyleDirPath = plugin.getAnyStyleInputDir(); // Node.js is available only in ...
/** Parse a bibliography text using Anystyle. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/bib.ts#L125-L201
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
BibliographyTextExtractor.getTextContentItemsFromPageRef
async getTextContentItemsFromPageRef(pageRef: PDFJsDestArray[0]) { const refStr = JSON.stringify(pageRef); return this.pageRefToTextContentItemsPromise[refStr] ?? ( this.pageRefToTextContentItemsPromise[refStr] = (async () => { const pageNumber = await this.doc.getPageIndex(...
/** Get `TextContentItem`s contained in the specified page. This method avoids fetching the same info multiple times. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/bib.ts#L250-L261
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusContextMenu.addItems
async addItems(evt?: MouseEvent) { const { child, plugin, lib, app } = this; const pdfViewer = child.pdfViewer.pdfViewer; // const canvas = lib.workspace.getActiveCanvasView()?.canvas; const selectionObj = this.win.getSelection(); const pageAndSelection = lib.copyLink.getPageAnd...
// TODO: divide into smaller methods
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/context-menu.ts#L474-L788
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlus.cleanUpResources
async cleanUpResources() { await this.cleanUpAnystyleFiles(); }
/** Perform clean-ups not registered explicitly. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/main.ts#L126-L128
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlus.cleanUpAnystyleFiles
async cleanUpAnystyleFiles() { const adapter = this.app.vault.adapter; if (Platform.isDesktopApp && adapter instanceof FileSystemAdapter) { const anyStyleInputDir = this.getAnyStyleInputDir(); if (anyStyleInputDir) { try { await adapter.rmdir(anyStyleInputDir, true); } catch (err) { if (err....
/** Clean up the AnyStyle input files and their directory (.obsidian/plugins/pdf-plus/anystyle) */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/main.ts#L131-L143
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlus.registerStyleSettings
private registerStyleSettings() { // See https://github.com/mgmeyers/obsidian-style-settings?tab=readme-ov-file#plugin-support this.app.workspace.trigger('parse-style-settings'); this.register(() => this.app.workspace.trigger('parse-style-settings')); }
/** * Tell the Style Settings plugin to parse styles.css on load and unload * so that the Style Settings pane can be updated. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/main.ts#L314-L318
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlus.registerEl
registerEl<HTMLElementType extends HTMLElement>(el: HTMLElementType) { this.register(() => el.remove()); return el; }
/** * Registers an HTML element that will be refreshed when a style setting is updated * and will be removed when the plugin gets unloaded. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/main.ts#L453-L456
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusSettingTab.redisplay
redisplay() { const scrollTop = this.contentEl.scrollTop; this.display(); this.contentEl.scroll({ top: scrollTop }); this.events.trigger('update'); }
/** Refresh the setting tab and then scroll back to the original position. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/settings.ts#L1560-L1566
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusCommands.writeHighlightAnnotationToSelectionIntoFileAndCopyLink
writeHighlightAnnotationToSelectionIntoFileAndCopyLink(checking: boolean, autoPaste: boolean = false) { const palette = this.lib.getColorPaletteAssociatedWithSelection(); if (!palette) return false; if (!palette.writeFile) return false; const template = this.settings.copyCommands[palet...
// TODO: A better, more concise function name 😅
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/commands.ts#L270-L282
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusCommands._insertPage
_insertPage(file: TFile, page: number, basePage: number) { new PDFComposerModal( this.plugin, this.settings.askPageLabelUpdateWhenInsertPage, this.settings.pageLabelUpdateWhenInsertPage, false, false ) .ask() .then((answ...
/** * @param file The PDF file to insert a page into * @param page The index of the new page to be inserted * @param basePage The page number to reference for the new page size */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/commands.ts#L552-L564
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFComposer.mergeFiles
async mergeFiles(file1: TFile, file2: TFile, keepLabels: boolean) { const pageCount = (await this.fileOperator.read(file1)).getPageCount(); return await this.linkUpdater.updateLinks( () => this.fileOperator.mergeFiles(file1, file2, keepLabels), [file1, file2], (f, n) ...
/** Merge file2 into file1 by appending all pages from file2 to file1. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L55-L65
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFFileOperator.write
async write(path: string, pdfDoc: PDFDocument, existOk: boolean): Promise<TFile | null> { const buffer = await pdfDoc.save(); const file = this.app.vault.getAbstractFileByPath(path); if (file instanceof TFile) { if (!existOk) { new Notice(`${this.plugin.manifest.name...
/** Write the content of `pdfDoc` into the specified file. If the file does not exist, it will be created. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L114-L134
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFFileOperator.insertPage
async insertPage(file: TFile, pageNumber: number, basePageNumber: number, keepLabels: boolean) { const doc = await this.read(file); this.pageLabelUpdater.insertPage(doc, pageNumber, keepLabels); const basePage = doc.getPage(basePageNumber - 1); const { width, height } = basePage.getSiz...
/** * @param file The PDF file to insert a page into. * @param pageNumber The index of the new page to be inserted. * @param basePageNumber The page number to reference for the new page size. * @param keepLabels Whether to keep the page labels unchanged. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L150-L161
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFFileOperator.mergeFiles
async mergeFiles(file1: TFile, file2: TFile, keepLabels: boolean): Promise<TFile | null> { const [doc1, doc2] = await Promise.all([ this.read(file1), this.read(file2) ]); // TODO: implement this this.pageLabelUpdater.mergeFiles(doc1, doc2, keepLabels); c...
/** Merge file2 into file1 by appending all pages from file2 to file1. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L176-L197
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFFileOperator.extractPagesAsNewFile
async extractPagesAsNewFile(srcFile: TFile, pages: number[], dstPath: string, existOk: boolean, keepLabels: boolean) { // Create a copy of the source file const doc = await this.read(srcFile); // Get the pages not to include in the resulting document (pages not in the `pages` array) con...
/** * Extract pages from the source file and save it as a new file. The original file is not modified. * We do this by making a copy of the source file and then removing the pages not to include in the resulting document. * * @param pages 1-based page numbers to extract */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L255-L278
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFLinkUpdater.updateLinks
async updateLinks(operator: () => Promise<TFile | null>, files: TFile[], updater: LinkInfoUpdater): Promise<TFile | null> { await this.lib.metadataCacheUpdatePromise; const updateQueue = new Map<string, { position: Pos, newLink: string }[]>(); for (const file of files) { const back...
// TODO: rewrite using PDFBacklinkIndex
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L290-L343
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFLinkUpdater.updateLinkColor
async updateLinkColor( refCache: LinkCache | EmbedCache | FrontmatterLinkCache, sourcePath: string, newColor: { type: 'name', name: string } | { type: 'rgb', rgb: RGB } | null, options?: { linktext?: boolean, callout?: boolean } ) { options = Object.assign({ linktext: true, c...
/** * @param options Options for updating the link color: * - `linktext`: Whether the color should appear in the link text. * - `callout`: Whether the color should be updated in the PDF++ callout that contains the link if any. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/composer.ts#L411-L470
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
copyLinkLib.getTextSelectionRange
getTextSelectionRange(pageEl: HTMLElement, range: Range) { if (range && !range.collapsed) { const startTextLayerNode = getTextLayerNode(pageEl, range.startContainer); const endTextLayerNode = getTextLayerNode(pageEl, range.endContainer); if (startTextLayerNode && endTextLayer...
// The same as getTextSelectionRangeStr in Obsidian's app.js, but returns an object instead of a string.
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/copy-link.ts#L42-L61
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
copyLinkLib.getTextToCopy
getTextToCopy(child: PDFViewerChild, template: string, displayTextFormat: string | undefined, file: TFile, page: number, subpath: string, text: string, colorName: string, sourcePath?: string, comment?: string) { const pageView = child.getPage(page); // need refactor if (typeof comment !== 'stri...
/** * @param child * @param template * @param displayTextFormat * @param file * @param page * @param subpath * @param text * @param colorName * @param sourcePath * @param comment This will be used as the `comment` template variable. * Assuming the subpath ...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/copy-link.ts#L173-L198
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
copyLinkLib.writeHighlightAnnotationToSelectionIntoFileAndCopyLink
writeHighlightAnnotationToSelectionIntoFileAndCopyLink(checking: boolean, templates: { copyFormat: string, displayTextFormat?: string }, colorName?: string, autoPaste?: boolean): boolean { // Get and store the selected text before writing file because // the file modification will cause the PDF viewer t...
// TODO: A better, more concise function name 😅
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/copy-link.ts#L368-L411
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
copyLinkLib.prepareMarkdownLeafForPaste
async prepareMarkdownLeafForPaste(file: TFile) { let leaf = this.lib.workspace.getExistingLeafForMarkdownFile(file); const isExistingLeaf = !!leaf; if (!leaf && this.settings.openAutoFocusTargetIfNotOpened) { const paneType = this.settings.howToOpenAutoFocusTargetIfNotOpened; ...
/** * Note that if this method returns a workspace leaf, its view IS guaranteed to be loaded * (i.e. the view is not a detached view). */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/copy-link.ts#L695-L735
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
copyLinkLib.autoFocusOrAutoPaste
async autoFocusOrAutoPaste(evaluated: string, autoPaste?: boolean, palette?: ColorPalette) { if (autoPaste || this.settings.autoPaste) { const success = await this.autoPaste(evaluated); if (success) { palette?.setStatus('Link copied & pasted', this.statusDurationMs); ...
/** * Performs auto-focus or auto-paste as a post-processing according to the user's preferences and the executed commands. * If `this.settings.autoPaste` is `true` or this method is called via the auto-paste commands, perform auto-paste. * Otherwise, perform auto-focus if `this.settings.autoFocus` is `t...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/copy-link.ts#L876-L894
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.registerPDFEvent
registerPDFEvent<K extends keyof PDFJsEventMap>(name: K, eventBus: EventBus, component: Component | null, callback: (data: PDFJsEventMap[K]) => any) { const listener = async (data: any) => { await callback(data); if (!component) eventBus.off(name, listener); }; component?...
/** * @param component A component such that the callback is unregistered when the component is unloaded, or `null` if the callback should be called only once. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L66-L73
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.onPageReady
onPageReady(viewer: ObsidianViewer, component: Component | null, cb: (pageNumber: number, pageView: PDFPageView, newlyRendered: boolean) => any) { viewer.pdfViewer?._pages .forEach((pageView, pageIndex) => { cb(pageIndex + 1, pageView, false); // page number is 1-based })...
/** * Register a callback executed when the PDFPageView for a page is ready. * This happens before the text layer and the annotation layer are ready. * Note that PDF rendering is "lazy"; a page view is not prepared until the page is scrolled into view. * * @param component A component such th...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L82-L90
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.onTextLayerReady
onTextLayerReady(viewer: ObsidianViewer, component: Component | null, cb: (pageNumber: number, pageView: PDFPageView, newlyRendered: boolean) => any) { viewer.pdfViewer?._pages .forEach((pageView, pageIndex) => { if (pageView.textLayer) { cb(pageIndex + 1, pageVie...
/** * Register a callback executed when the text layer for a page gets rendered. * * @param component A component such that the callback is unregistered when the component is unloaded, or `null` if the callback should be called only once. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L97-L107
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.onAnnotationLayerReady
onAnnotationLayerReady(viewer: ObsidianViewer, component: Component | null, cb: (pageNumber: number, pageView: PDFPageView, newlyRendered: boolean) => any) { viewer.pdfViewer?._pages .forEach((pageView, pageIndex) => { if (pageView.annotationLayer) { cb(pageIndex ...
/** * Register a callback executed when the annotation layer for a page gets rendered. * * @param component A component such that the callback is unregistered when the component is unloaded, or `null` if the callback should be called only once. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L114-L124
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.destIdToSubpath
async destIdToSubpath(destId: string, doc: PDFDocumentProxy) { const dest = await doc.getDestination(destId) as PDFJsDestArray; if (!dest) return null; return this.pdfJsDestArrayToSubpath(dest, doc); }
/** * Convert a destination name (see the PDF spec (PDF 32000-1:2008), 12.3.2.3 "Named Destinations") * into a subpath of the form `#page=<pageNumber>&offset=<left>,<top>,<zoom>`. * * For how Obsidian handles the "offset" parameter, see the PDFViewerChild.prototype.applySubpath method * in O...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L290-L294
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.normalizePDFJsDestArray
normalizePDFJsDestArray(dest: PDFJsDestArray, pageNumber: number): DestArray { return [ pageNumber - 1, dest[1].name, ...dest .slice(2) as (number | null)[] // .filter((param: number | null): param is number => typeof param === 'number') ];...
/** * * @param dest * @param pageNumber 1-based page number */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L306-L314
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.destArrayToSubpath
destArrayToSubpath(destArray: DestArray) { const pageNumber = destArray[0]; let top = ''; let left = ''; let zoom = ''; if (destArray[1] === 'XYZ') { if (typeof destArray[2] === 'number') left += Math.round(destArray[2]); if (typeof destArray[3] === 'num...
/** * page: a 0-based page number * destType.name: Obsidian only supports "XYZ" and "FitBH" */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L361-L381
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.generateMarkdownLink
generateMarkdownLink(file: TFile, sourcePath: string, subpath?: string, alias?: string) { const app = this.app; const useMarkdownLinks = app.vault.getConfig('useMarkdownLinks'); const useWikilinks = !useMarkdownLinks; const linkpath = app.metadataCache.fileToLinktext(file, sourcePath, us...
/** * The same as `app.fileManager.generateMarkdownLink()`, but before Obsidian 1.7, it did not respect * the `alias` parameter for non-markdown files. * This function fixes that issue. Other than that, it is the same as the original function. * * Note that this problem has been fixed in Obsid...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L466-L488
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.isBacklinked
isBacklinked(file: TFile, subpathParams?: { page: number, selection?: [number, number, number, number], annotation?: string }): boolean { // validate parameters if (subpathParams) { const { page, selection, annotation } = subpathParams; if (isNaN(page) || page < 1) throw new Erro...
// TODO: rewrite using PDFBacklinkIndex
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L507-L553
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.getPDFEmbed
getPDFEmbed(activeOnly: boolean = false): PDFEmbed | null { const activeEmbed = this.getPDFEmbedInActiveView(); if (activeEmbed) return activeEmbed; if (!activeOnly) { let pdfEmbed: PDFEmbed | null = null; this.app.workspace.iterateAllLeaves((leaf) => { if...
/** Get an instance of Obsidian's built-in PDFEmbed. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L629-L649
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.getExternalPDFUrl
async getExternalPDFUrl(file: TFile): Promise<string | null> { if (file.stat.size > 300) return null; const content = (await this.app.vault.read(file)).trim(); // A PDF file must start with a header of the form "%PDF-x.y" // so it's safe to assume that a file starting with "https://", ...
/** * If the given PDF file is a "dummy" file containing only a URL (https://, http://, file:///), * return the URL. Otherwise, return null. * For the exact usage, refer to the comment in the patcher for `PDFViewerChild.prototype.loadFile`. * * @param file * @returns */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L738-L756
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.pdfPageToImageDataUrl
async pdfPageToImageDataUrl(page: PDFPageProxy, options?: { type?: string, encoderOptions?: number, resolution?: number, cropRect?: Rect }): Promise<string> { const [left, bottom, right, top] = page.view; const pageWidth = right - left; const pageHeight = top - bottom; const type = opti...
/** * @param options The following options are supported: * - type: The image format passed to HTMLCanvasElement.toDataURL(). The default is 'image/png'. * - encoderOptions: The quality of the image format passed to HTMLCanvasElement.toDataURL(). * - resolution: The resolution of the PDF page render...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L912-L943
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.pdfPageToImageArrayBuffer
async pdfPageToImageArrayBuffer(page: PDFPageProxy, options?: { type?: string, encoderOptions?: number, resolution?: number, cropRect?: Rect }): Promise<ArrayBuffer> { const dataUrl = await this.pdfPageToImageDataUrl(page, options); const base64 = dataUrl.match(/^data:image\/\w+;base64,(.*)/)?.[1]; ...
/** * @param options Supports the same options as pdfPageToImageDataUrl. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L948-L953
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.toSingleLine
toSingleLine(str: string): string { return toSingleLine(str, this.plugin.settings.removeWhitespaceBetweenCJChars); }
/** Process (possibly) multiline strings cleverly to convert it into a single line string. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L1001-L1003
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPlusLib.write
async write(path: string, data: string | ArrayBuffer, existOk: boolean): Promise<TFile | null> { const file = this.app.vault.getAbstractFileByPath(path); if (file instanceof TFile) { if (!existOk) { new Notice(`${this.plugin.manifest.name}: File already exists: ${path}`); ...
/** Write data to the file at path. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/index.ts#L1006-L1033
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFOutlines.lib
get lib() { return this.plugin.lib; }
// }
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/outlines.ts#L37-L39
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFOutlines.findPDFjsOutlineTreeNode
async findPDFjsOutlineTreeNode(node: PDFOutlineTreeNode): Promise<PDFOutlineItem | null> { let found: PDFOutlineItem | null = null; await this.iterAsync({ enter: async (outlineItem) => { if (found || outlineItem.isRoot()) return; if (node.item.title === outl...
/** Iterate over the outline items and find the matching one from the tree. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/outlines.ts#L135-L160
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFOutlineItem.name
get name(): string { if (this.isRoot()) return '(Root)'; let name = this.title; this.iterAncestors((ancestor) => { if (!ancestor.isRoot()) name = `${ancestor.title}/${name}`; }); return name; }
/** A human-readable name for this item. This is not a part of the PDF spec. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/outlines.ts#L325-L333
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFOutlineItem.countVisibleDescendants
countVisibleDescendants(): number { let count = 0; this.iterChildren(() => count++); this.iterChildren((child) => { if (typeof child.count === 'number' && child.count > 0) { count += child.countVisibleDescendants(); } }); return count; ...
/** Compute the value of the "Count" entry following the algirithm described in Table 153 of the PDF spec. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/outlines.ts#L582-L591
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPageLabelDict.fromPDFDict
static fromPDFDict(dict: PDFDict) { const instance = new PDFPageLabelDict(); const start = dict.get(PDFName.of('St')); if (start instanceof PDFNumber) { instance.start = start.asNumber(); } const style = dict.get(PDFName.of('S')); if (style instanceof PDFNam...
// "P" entry
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/page-labels.ts#L35-L57
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPageLabels.constructor
constructor(public doc: PDFDocument, public ranges: { pageFrom: number, dict: PDFPageLabelDict }[]) { this.normalize(); }
// pageFrom: converted into a 1-based page index for easier use; it's 0-based in the original PDF document
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/page-labels.ts#L63-L65
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPageLabels.divideRangeAtPage
divideRangeAtPage(page: number, keepLabels: boolean, processDict?: (newDict: PDFPageLabelDict) => void) { const index = this.getRangeIndexAtPage(page); if (index === -1) return this; if (page === this.getStartOfRange(index)) return this; const range = this.ranges[index]; const ...
/** * * @param page The 1-based index of the page the new range should start from * @param keepLabels If the original page labels should be kept after the split * @returns */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/page-labels.ts#L175-L192
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getExistingLeafForPDFFile
getExistingLeafForPDFFile(file: TFile): WorkspaceLeaf | null { return this.getExistingLeafForFile(file); }
/** * Get an existing leaf that holds the given PDF file, if any. * If the leaf has been already loaded, `leaf.view` will be an instance of `PDFView`. * If not, `leaf.view` will be an instance of `DeferredView`. If you want to ensure that * the view is `PDFView`, do `await leaf.loadIfDeferred()` fol...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L119-L121
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getMarkdownLeafInSidebar
getMarkdownLeafInSidebar(sidebarType: SidebarType) { if (this.settings.singleMDLeafInSidebar) { return this.lib.workspace.getExistingMarkdownLeafInSidebar(sidebarType) ?? this.lib.workspace.getNewLeafInSidebar(sidebarType); } else { return this.lib.workspace.getNe...
/** * Get a leaf to open a markdown file in. The leaf can be an existing one or a new one, * depending on the user preference and the current state of the workspace. * * Note that the returned leaf might contain a deferred view, so it is not guaranteed * that `leaf.view` is an instance of `Mar...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L186-L193
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getMarkdownLeafForLinkFromPDF
getMarkdownLeafForLinkFromPDF(linktext: string, sourcePath: string): WorkspaceLeaf { const { path: linkpath } = parseLinktext(linktext); const file = this.app.metadataCache.getFirstLinkpathDest(linkpath, sourcePath); // 1. If the target markdown file is already opened, open the link in the same...
/** * Given a link from a PDF file to a markdown file, return a leaf to open the link in. * The returned leaf can be an existing one or a new one. * Note that the leaf might contain a deferred view, so you need to call `await leaf.loadIfDeferred()` * before accessing any properties specific to the v...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L204-L265
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getExistingMarkdownLeafInSidebar
getExistingMarkdownLeafInSidebar(sidebarType: SidebarType): WorkspaceLeaf | null { let sidebarLeaf: WorkspaceLeaf | undefined; const root = sidebarType === 'right-sidebar' ? this.app.workspace.rightSplit : this.app.workspace.leftSplit; this.app.workspace.iterateAllLeaves...
/** * Get an existing leaf that is opened a markdown file in the sidebar * specified by `sidebarType`, if any. * Note that the returned leaf can contain a deferred view, so it is not guaranteed * that `leaf.view` is an instance of `MarkdownView`. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L305-L319
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.revealLeaf
async revealLeaf(leaf: WorkspaceLeaf) { if (requireApiVersion('1.5.11')) { await this.app.workspace.revealLeaf(leaf); return; } if (!Platform.isDesktopApp) { // on mobile, we don't need to care about new windows so just use the original method thi...
/** * Almost the same as Workspace.prototype.revealLeaf, but this version * properly reveals a leaf even when it is contained in a secondary window. * * Update: The upstream bug of Obsidian has been fixed in v1.5.11: https://obsidian.md/changelog/2024-03-13-desktop-v1.5.11/ * * Update 2:...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L337-L363
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.openPDFLinkTextInExistingLeafForTargetPDF
openPDFLinkTextInExistingLeafForTargetPDF(linktext: string, sourcePath: string, openViewState?: OpenViewState, targetFile?: TFile): { exists: boolean, promise: Promise<void> } { if (!targetFile) { const { path } = parseLinktext(linktext); targetFile = this.app.metadataCache.getFirstLinkp...
/** * If the target PDF file is already opened in a tab, open the link in that tab. * * @param linktext A link text to a PDF file. * @param sourcePath * @param openViewState `active` will be overwritten acccording to `this.plugin.settings.dontActivateAfterOpenPDF`. * @param targetFile If...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L394-L419
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getExistingLeafForFile
getExistingLeafForFile(file: TFile): WorkspaceLeaf | null { // Get the view type that corresponds to the file extension. // e.g. 'markdown' for '.md', 'pdf' for '.pdf' const viewType = this.app.viewRegistry.getTypeByExtension(file.extension); if (!viewType) return null; let leaf...
/** * Get an existing leaf that holds the given file, if any. * If the leaf has been already loaded, `leaf.view` will be an instance of a subclass of `FileView`, * e.g., `PDFView` for a PDF file, `MarkdownView` for a markdown file. * If not, `leaf.view` will be an instance of `DeferredView`. If you ...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L429-L456
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getExistingLeafForMarkdownFile
getExistingLeafForMarkdownFile(file: TFile): WorkspaceLeaf | null { return this.getExistingLeafForFile(file); }
/** * Returns a leaf that holds the given markdown file, if any. * `leaf.view` can be an instance of `MarkdownView` or `DeferredView`. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L462-L464
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.getFilePathFromView
getFilePathFromView(view: View): string | null { // `view.file?.path` will fail if the view is a `DeferredView`. const path = view.getState().file; return typeof path === 'string' ? path : null; }
/** * Returns the path of the file opened in the given view. * This method ensures that it works even if the view is a `DeferredView`. * @param view An actual `FileView` or a `DefferedView` for a `FileView`. * @returns */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L492-L496
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
WorkspaceLib.ensureViewLoaded
async ensureViewLoaded(leaf: WorkspaceLeaf): Promise<void> { if (requireApiVersion('1.7.2')) { await leaf.loadIfDeferred(); } }
/** * Ensuress that the view in the given leaf is fully loaded (not deferred) * after the returned promise is resolved. Never forget to await it when you call this method. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/workspace-lib.ts#L502-L506
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
HighlightExtractor.getTextByRect
getTextByRect(items: TextContentItem[], rect: Rect): PDFTextRange { const [left, bottom, right, top] = rect; let text = ''; let from: { index: number, offset: number } = { index: -1, offset: -1 }; let to: { index: number, offset: number } = { index: -1, offset: -1 }; for (let i...
/** Inspired by PDFViewerChild.prototype.getTextByRect in Obsidian's app.js */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/extract.ts#L72-L99
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
HighlightGeometryLib.computeMergedHighlightRects
computeMergedHighlightRects(textLayer: { textDivs: HTMLElement[], textContentItems: TextContentItem[] }, beginIndex: number, beginOffset: number, endIndex: number, endOffset: number): MergedRect[] { const { textContentItems, textDivs } = textLayer; const results: MergedRect[] = []; let mergedR...
/** * Returns an array of rectangles that cover the background of the text selection speficied by the given parameters. * Each rectangle is obtained by merging the rectangles of the text content items contained in the selection, when possible (typically when the text selection is within a single line). *...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/geometry.ts#L15-L60
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
ViewerHighlightLib.highlightSubpath
highlightSubpath(child: PDFViewerChild, duration: number) { if (child.subpathHighlight?.type === 'text') { const component = new Component(); component.load(); this.lib.onTextLayerReady(child.pdfViewer, component, (pageNumber) => { if (child.subpathHighlight?...
/** * Render highlighting DOM elements for `subpathHighlight` of the given `child`. * `subpathHighlight` must be set by `child.applySubpath` before calling this method. * * @param child * @param duration The duration in seconds to highlight the subpath. If it's 0, the highlight will not be re...
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/viewer.ts#L44-L97
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
ViewerHighlightLib.highlightRect
highlightRect(child: PDFViewerChild, page: number, rect: Rect) { this.clearRectHighlight(child); if (1 <= page && page <= child.pdfViewer.pagesCount) { const pageView = child.getPage(page); if (pageView?.div.dataset.loaded) { child.rectHighlight = this.placeRectI...
/** * The counterpart of `PDFViewerChild.prototype.highlightText` and `PDFViewerChild.prototype.highlightAnnotation` * for rectangular selections. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/viewer.ts#L103-L122
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
ViewerHighlightLib.clearRectHighlight
clearRectHighlight(child: PDFViewerChild) { if (child.rectHighlight) { child.rectHighlight.detach(); child.rectHighlight = null; } }
/** * The counterpart of `PDFViewerChild.prototype.clearTextHighlight` and `PDFViewerChild.prototype.clearAnnotationHighlight` * for rectangular selections. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/viewer.ts#L128-L133
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
AnnotationWriteFileLib.addLinkAnnotationToSelection
async addLinkAnnotationToSelection(dest: DestArray | string) { return this.addAnnotationToSelection(async (file, page, rects) => { const io = this.getPdfIo(); return await io.addLinkAnnotation(file, page, rects, dest); }); }
/** * @param dest A destination, represented either by its name (named destination) or as a DestArray (explicit destination). */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/write-file/index.ts#L34-L39
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
AnnotationWriteFileLib.addAnnotationToTextRange
async addAnnotationToTextRange(annotator: Annotator, child: PDFViewerChild, pageNumber: number, beginIndex: number, beginOffset: number, endIndex: number, endOffset: number) { if (!child.file) return; if (1 <= pageNumber && pageNumber <= child.pdfViewer.pagesCount) { const pageView = child....
/** Add a highlight annotation to a text selection specified by a subpath of the form `#page=<pageNumber>&selection=<beginIndex>,<beginOffset>,<endIndex>,<endOffset>`. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/lib/highlights/write-file/index.ts#L60-L81
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFOutlineTitleModal.constructor
constructor(plugin: PDFPlus, modalTitle: string) { super(plugin); this.modalTitle = modalTitle; // Don't use `Scope` or `keydown` because they will cause the modal to be closed // when hitting Enter with IME on this.component.registerDomEvent(this.modalEl.doc, 'keypress', (evt) ...
// the title of an outline item
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/modals/outline-modals.ts#L19-L30
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
patchObsidianViewer
const patchObsidianViewer = (plugin: PDFPlus, pdfViewer: ObsidianViewer) => { // What this prototype actually is will change depending on the Obsidian version. // // In Obsidian v1.7.7 or earlier, `pdfViewer` is an instance of the `ObsidianViewer` (which is a class). // Therefore, `prototype` is the pr...
/** Monkey-patch ObsidianViewer so that it can open external PDF files. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/patchers/pdf-internals.ts#L1003-L1050
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
onKeyDown
const onKeyDown = (e: KeyboardEvent) => { if (removed) return; if (doc.body.contains(targetEl)) { if (Keymap.isModifier(e, 'Mod')) { removeHandlers(); callback(); } } else removeHandlers(); };
// Watch for the mod key press
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/utils/events.ts#L109-L117
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
onMouseOver
const onMouseOver = (e: MouseEvent) => { if (removed) return; if (isTargetNode(e, e.target) && !targetEl.contains(e.target)) removeHandlers(); };
// Stop watching for the mod key press when the mouse escapes away from the target element
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/utils/events.ts#L119-L122
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
onMouseLeave
const onMouseLeave = (e: MouseEvent) => { if (removed) return; if (e.target === doc) removeHandlers(); };
// Stop watching for the mod key press when the mouse leaves the document
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/utils/events.ts#L124-L127
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
knuth_mod
function knuth_mod(dividend: number, divisor: number) { return dividend - divisor * Math.floor(dividend / divisor); }
/** * Takes sign of divisor -- incl. returning -0 * * Taken from https://github.com/tridactyl/tridactyl/blob/4a4c9c7306b436611088b6ff2dceff77e7ccbfd6/src/lib/number.mod.ts#L9-L12 */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/vim/hintnames.ts#L300-L302
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
ScrollController.scrollVerticallyByVisualPage
scrollVerticallyByVisualPage(times: number) { if (!this.viewerContainerEl) return; let offset = this.viewerContainerEl.clientHeight; offset *= times; this.viewerContainerEl.scrollBy({ top: offset, behavior: (this.settings.vimSmoothScroll ? 'smooth' : 'instant') as ScrollBehavior }); ...
/** Here "page" does not mean the PDF page but the "visual page", i.e. the region of the screen that is currently visible. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/vim/scroll.ts#L91-L98
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
ScrollController.scrollHorizontallyByVisualPage
scrollHorizontallyByVisualPage(times: number) { if (!this.viewerContainerEl) return; let offset = this.viewerContainerEl.clientWidth; offset *= times; this.viewerContainerEl.scrollBy({ left: offset, behavior: (this.settings.vimSmoothScroll ? 'smooth' : 'instant') as ScrollBehavior }); ...
/** Here "page" does not mean the PDF page but the "visual page", i.e. the region of the screen that is currently visible. */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/vim/scroll.ts#L101-L108
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPageTextStructureParser.getBoundIndicesOfLine
getBoundIndicesOfLine(itemIndex: number, lineOffset: number) { const lineStart = this._getIndexWithinLineStartIndicesForLineContainingItem(itemIndex); const lineStartIndex = this.lineStartIndices![lineStart + lineOffset] ?? null; if (lineStartIndex === null) return null; const nextLineSt...
/** * Get the indices of the text content items that start and end a line. * The line is specified by the index of the text content item that belongs to the line and the offset of the line from the item. * @param itemIndex * @param lineOffset */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/vim/text-structure-parser.ts#L74-L83
6744d590cb22a5171d2f5168d7a1c9e87775941d
obsidian-pdf-plus
github_2023
RyotaUshio
typescript
PDFPageTextStructureParser._getIndexWithinLineStartIndicesForLineContainingItem
_getIndexWithinLineStartIndicesForLineContainingItem(itemIndex: number) { if (!this.lineStartIndices) { this.parse(); } const { found, index: lineStartIndex } = binarySearch(this.lineStartIndices!, (i) => itemIndex - i); return found ? lineStartIndex : lineStartIndex - 1; ...
/** * The name says it all, but to give some example: * * If `index`-th text content item belongs to the 5th line, and the 5th line starts from the 10th item, * then this function returns 10. * * @param itemIndex * @returns */
https://github.com/RyotaUshio/obsidian-pdf-plus/blob/6744d590cb22a5171d2f5168d7a1c9e87775941d/src/vim/text-structure-parser.ts#L130-L137
6744d590cb22a5171d2f5168d7a1c9e87775941d
inkdrop-visualizer
github_2023
inkdrop-org
typescript
isEmptyValue
const isEmptyValue = (value: any): boolean => { return ( value === null || value === undefined || (Array.isArray(value) && value.length === 0) || (typeof value === 'object' && value !== null && Object.keys(value).length === 0) ); };
// Checks if the value is considered empty (null, undefined, empty array, or empty object)
https://github.com/inkdrop-org/inkdrop-visualizer/blob/17a387d1afada68b7a1e96b3dea9262dee4f7aa1/tldraw-renderer/src/jsonPlanManager/jsonPlanManager.ts#L27-L34
17a387d1afada68b7a1e96b3dea9262dee4f7aa1
inkdrop-visualizer
github_2023
inkdrop-org
typescript
getValueString
const getValueString = (value: any) => stringify(value);
// Updated getValueString function to use stringify utility
https://github.com/inkdrop-org/inkdrop-visualizer/blob/17a387d1afada68b7a1e96b3dea9262dee4f7aa1/tldraw-renderer/src/jsonPlanManager/jsonPlanManager.ts#L38-L38
17a387d1afada68b7a1e96b3dea9262dee4f7aa1
inkdrop-visualizer
github_2023
inkdrop-org
typescript
isValid
const isValid = (value: any) => { return value !== undefined && value !== null && value !== '' && !isEmptyArray(value) && !isEmptyObject(value); };
// Updated isValid function to check for objects
https://github.com/inkdrop-org/inkdrop-visualizer/blob/17a387d1afada68b7a1e96b3dea9262dee4f7aa1/tldraw-renderer/src/jsonPlanManager/jsonPlanManager.ts#L46-L48
17a387d1afada68b7a1e96b3dea9262dee4f7aa1
inkdrop-visualizer
github_2023
inkdrop-org
typescript
isEmptyObject
const isEmptyObject = (value: any) => { return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.keys(value).length === 0; };
// Check if value is an empty object
https://github.com/inkdrop-org/inkdrop-visualizer/blob/17a387d1afada68b7a1e96b3dea9262dee4f7aa1/tldraw-renderer/src/jsonPlanManager/jsonPlanManager.ts#L51-L53
17a387d1afada68b7a1e96b3dea9262dee4f7aa1
mitex
github_2023
mitex-rs
typescript
Preview
const Preview = (output: State<string>) => { const svgData = van.state(""); van.derive(async () => { if (fontLoaded.val) { svgData.val = await $typst.svg({ mainContent: `#import "@preview/mitex:0.2.5": * #set page(width: auto, height: auto, margin: 1em); #set text(size: 2...
/// The preview component
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/main.ts#L56-L87
5fc83b64ab5e0b91918528ef2987037866e24086
mitex
github_2023
mitex-rs
typescript
CopyButton
const CopyButton = (title: string, content: State<string>) => button({ onclick: () => navigator.clipboard.writeText(content.val), textContent: title, });
/// Copy a a derived string to clipboard
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/main.ts#L90-L94
5fc83b64ab5e0b91918528ef2987037866e24086
mitex
github_2023
mitex-rs
typescript
bufferToBase64Url
const bufferToBase64Url = async (data: Uint8Array) => { // Use a FileReader to generate a base64 data URI const base64url = await new Promise<string | null>((r, reject) => { const reader = new FileReader(); reader.onload = () => { const result = reader.result; if (typeof result === "string" || r...
/// https://stackoverflow.com/questions/21797299/convert-base64-string-to-arraybuffer
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/tools/underleaf-fs.ts#L10-L28
5fc83b64ab5e0b91918528ef2987037866e24086
mitex
github_2023
mitex-rs
typescript
reloadAll
const reloadAll = async (state: FsState) => { const $typst = window.$typst; await Promise.all( (fsState.val?.fsList || []).map(async (f) => { return await $typst.mapShadow(f.path, f.data.val); }) ); focusFile.val = state.fsList.find( (t) => t.path === "/repo/fixtures/underleaf...
/// Reload all files to compiler and application
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/tools/underleaf-fs.ts#L153-L165
5fc83b64ab5e0b91918528ef2987037866e24086
mitex
github_2023
mitex-rs
typescript
isDarkMode
const isDarkMode = () => window.matchMedia?.("(prefers-color-scheme: dark)").matches;
/// Checks if the browser is in dark mode
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/tools/underleaf.ts#L17-L18
5fc83b64ab5e0b91918528ef2987037866e24086
mitex
github_2023
mitex-rs
typescript
ExportButton
const ExportButton = (title: string, onclick: () => void) => button({ onclick, textContent: title, });
/// Exports the document
https://github.com/mitex-rs/mitex/blob/5fc83b64ab5e0b91918528ef2987037866e24086/packages/mitex-web/src/tools/underleaf.ts#L21-L25
5fc83b64ab5e0b91918528ef2987037866e24086
ngrx-toolkit
github_2023
angular-architects
typescript
SignalReduxStore.connectFeatureStore
connectFeatureStore(mappers: MapperTypes<ActionCreator<any, any>[]>[]): void { mappers.forEach( mapper => mapper.types.forEach( action => this.mapperDict[action] = { storeMethod: mapper.storeMethod, resultMethod: mapper.resultMethod } ) ); }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/angular-architects/ngrx-toolkit/blob/eda4138f4208f75f9ef890d4588007e1541c6f26/libs/ngrx-toolkit/redux-connector/src/lib/signal-redux-store.ts#L40-L49
eda4138f4208f75f9ef890d4588007e1541c6f26
ngrx-toolkit
github_2023
angular-architects
typescript
DevtoolsSyncer.addStore
addStore( id: string, name: string, store: StateSource<object>, options: DevtoolsInnerOptions ) { let storeName = name; const names = Object.values(this.#stores).map((store) => store.name); if (names.includes(storeName)) { // const { options } = throwIfNull( // Object.values...
/** * Consumer provides the id. That is because we can only start * tracking the store in the init hook. * Unfortunately, methods for renaming having the final id * need to be defined already before. * That's why `withDevtools` requests first the id and * then registers itself later. */
https://github.com/angular-architects/ngrx-toolkit/blob/eda4138f4208f75f9ef890d4588007e1541c6f26/libs/ngrx-toolkit/src/lib/devtools/internal/devtools-syncer.service.ts#L109-L140
eda4138f4208f75f9ef890d4588007e1541c6f26
rpc-anywhere
github_2023
DaniGuardiola
typescript
el
function el<Element extends HTMLElement>(id: string) { const element = document.getElementById(id); if (!element) throw new Error(`Element with id ${id} not found`); return element as Element; }
// non-demo stuff - you can ignore this :)
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/demo/parent.ts#L111-L115
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
_setDebugHooks
function _setDebugHooks(newDebugHooks: DebugHooks) { debugHooks = newDebugHooks; }
/** * Sets the debug hooks that will be used to debug the RPC instance. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L89-L91
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
setTransport
function setTransport(newTransport: RPCTransport) { if (transport.unregisterHandler) transport.unregisterHandler(); transport = newTransport; transport.registerHandler?.(handler); }
/** * Sets the transport that will be used to send and receive requests, * responses and messages. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L99-L103
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
setRequestHandler
function setRequestHandler( /** * The function that will be set as the "request handler" function. */ handler: RPCRequestHandler<Schema["requests"]>, ) { if (typeof handler === "function") { requestHandler = handler; return; } requestHandler = (method: keyof Schema["requests"...
/** * Sets the function that will be used to handle requests from the * remote RPC instance. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L112-L132
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
requestFn
function requestFn<Method extends keyof RemoteSchema["requests"]>( method: Method, ...args: "params" extends keyof RemoteSchema["requests"][Method] ? undefined extends RemoteSchema["requests"][Method]["params"] ? [params?: RemoteSchema["requests"][Method]["params"]] : [params: RemoteSchema...
/** * Sends a request to the remote RPC endpoint and returns a promise * with the response. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L160-L191
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
sendFn
function sendFn<Message extends keyof Schema["messages"]>( /** * The name of the message to send. */ message: Message, ...args: void extends RPCMessagePayload<Schema["messages"], Message> ? [] : undefined extends RPCMessagePayload<Schema["messages"], Message> ? [payload?: RPCMe...
// messages
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L221-L242
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
addMessageListener
function addMessageListener<Message extends keyof RemoteSchema["messages"]>( /** * The name of the message to listen to. Use "*" to listen to all * messages. */ message: "*" | Message, /** * The function that will be called when a message is received. */ listener: | Wildca...
/** * Adds a listener for a message (or all if "*" is used) from the * remote RPC endpoint. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L307-L332
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
removeMessageListener
function removeMessageListener< Message extends keyof RemoteSchema["messages"], >( /** * The name of the message to remove the listener for. Use "*" to * remove a listener for all messages. */ message: "*" | Message, /** * The listener function that will be removed. */ lis...
/** * Removes a listener for a message (or all if "*" is used) from the * remote RPC endpoint. */
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L370-L392
7ec394656c63e92eff1cbb3976f46da6df526ff7
rpc-anywhere
github_2023
DaniGuardiola
typescript
handler
async function handler( message: | _RPCRequestPacketFromSchema<Schema["requests"]> | _RPCResponsePacketFromSchema<RemoteSchema["requests"]> | _RPCMessagePacketFromSchema<RemoteSchema["messages"]>, ) { debugHooks.onReceive?.(message); if (!("type" in message)) throw new Error("Messa...
// message handling
https://github.com/DaniGuardiola/rpc-anywhere/blob/7ec394656c63e92eff1cbb3976f46da6df526ff7/src/rpc.ts#L397-L451
7ec394656c63e92eff1cbb3976f46da6df526ff7
stan-js
github_2023
codemask-labs
typescript
getAction
const getAction = <K extends TKey>(key: K) => store.actions[getActionKey(key)] as (value: unknown) => void
// @ts-expect-error - TS doesn't know that all keys are in actions object
https://github.com/codemask-labs/stan-js/blob/2bee695bc462a15d4fc5f4fe610ddabbe81ae3b2/src/createStore.ts#L94-L94
2bee695bc462a15d4fc5f4fe610ddabbe81ae3b2