@tato30/vue-pdf
Advanced tools
Comparing version 1.9.6 to 1.9.7
@@ -5,3 +5,3 @@ import type { HighlightEventPayload, HighlightOptions, TextLayerLoadedEventPayload } from '../types'; | ||
viewport?: import("pdfjs-dist/types/src/display/display_utils").PageViewport | undefined; | ||
highlightText?: string | undefined; | ||
highlightText?: string | string[] | undefined; | ||
highlightOptions?: HighlightOptions | undefined; | ||
@@ -14,3 +14,3 @@ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, { | ||
viewport?: import("pdfjs-dist/types/src/display/display_utils").PageViewport | undefined; | ||
highlightText?: string | undefined; | ||
highlightText?: string | string[] | undefined; | ||
highlightOptions?: HighlightOptions | undefined; | ||
@@ -17,0 +17,0 @@ }>>> & { |
@@ -5,3 +5,3 @@ import type { TextContent } from 'pdfjs-dist/types/src/display/text_layer'; | ||
declare function resetDivs(textContent: TextContent, textDivs: HTMLElement[]): void; | ||
declare function findMatches(query: string, textContent: TextContent, options: HighlightOptions): Match[]; | ||
declare function findMatches(queries: string[], textContent: TextContent, options: HighlightOptions): Match[]; | ||
export { findMatches, highlightMatches, resetDivs }; |
@@ -22,3 +22,3 @@ import 'pdfjs-dist/web/pdf_viewer.css'; | ||
watermarkOptions?: WatermarkOptions | undefined; | ||
highlightText?: string | undefined; | ||
highlightText?: string | string[] | undefined; | ||
highlightOptions?: HighlightOptions | undefined; | ||
@@ -56,3 +56,3 @@ }>, { | ||
watermarkOptions?: WatermarkOptions | undefined; | ||
highlightText?: string | undefined; | ||
highlightText?: string | string[] | undefined; | ||
highlightOptions?: HighlightOptions | undefined; | ||
@@ -59,0 +59,0 @@ }>, { |
{ | ||
"name": "@tato30/vue-pdf", | ||
"version": "1.9.6", | ||
"version": "1.9.7", | ||
"description": "PDF component for Vue 3", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -5,3 +5,3 @@ import * as PDFJS from 'pdfjs-dist' | ||
import type { PDFDocumentLoadingTask } from 'pdfjs-dist' | ||
import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist' | ||
import type { Ref } from 'vue' | ||
@@ -49,2 +49,3 @@ import type { OnPasswordCallback, PDFDestination, PDFInfo, PDFOptions, PDFSrc } from './types' | ||
const pdf = shallowRef<PDFDocumentLoadingTask>() | ||
const pdfDoc = shallowRef<PDFDocumentProxy>() | ||
const pages = shallowRef(0) | ||
@@ -54,2 +55,5 @@ const info = shallowRef<PDFInfo | {}>({}) | ||
function processLoadingTask(source: PDFSrc) { | ||
if (pdfDoc.value) | ||
void pdfDoc.value.destroy() | ||
const loadingTask = PDFJS.getDocument(source!) | ||
@@ -71,2 +75,4 @@ if (options.onProgress) | ||
async (doc) => { | ||
pdfDoc.value = doc | ||
pdf.value = doc.loadingTask | ||
@@ -73,0 +79,0 @@ pages.value = doc.numPages |
@@ -5,8 +5,13 @@ import type { TextItem } from 'pdfjs-dist/types/src/display/api' | ||
function getTextItems(textContent: TextContent) { | ||
return textContent.items.map(val => (val as TextItem).str) | ||
} | ||
function searchQuery(textContent: TextContent, query: string, options: HighlightOptions) { | ||
const strs = [] | ||
for (const textItem of textContent.items as TextItem[]) { | ||
strs.push(textItem.str) | ||
if (textItem.hasEOL) | ||
strs.push('\n') | ||
} | ||
function searchQuery(textItems: string[], query: string, options: HighlightOptions) { | ||
const textJoined = textItems.join(' ') | ||
// Join the text as is presented in textlayer and then replace newlines (/n) with whitespaces | ||
const textJoined = strs.join('').replace(/\n/g, ' ') | ||
const regexFlags = ['g'] | ||
@@ -32,5 +37,6 @@ if (options.ignoreCase) | ||
function convertMatches(matches: (number | string)[][], textItems: string[]): Match[] { | ||
function convertMatches(matches: (number | string)[][], textContent: TextContent): Match[] { | ||
let index = 0 | ||
let tindex = 0 | ||
const textItems = textContent.items as TextItem[] | ||
const end = textItems.length - 1 | ||
@@ -44,4 +50,4 @@ | ||
while (index !== end && mindex >= tindex + textItems[index].length) { | ||
tindex += textItems[index].length + 1 | ||
while (index !== end && mindex >= tindex + textItems[index].str.length) { | ||
tindex += textItems[index].str.length + (textItems[index].hasEOL ? 1 : 0) | ||
index++ | ||
@@ -57,4 +63,4 @@ } | ||
while (index !== end && mindex > tindex + textItems[index].length) { | ||
tindex += textItems[index].length + 1 | ||
while (index !== end && mindex > tindex + textItems[index].str.length) { | ||
tindex += textItems[index].str.length + (textItems[index].hasEOL ? 1 : 0) | ||
index++ | ||
@@ -165,3 +171,3 @@ } | ||
function resetDivs(textContent: TextContent, textDivs: HTMLElement[]) { | ||
const textItems = getTextItems(textContent) | ||
const textItems = textContent.items.map(val => (val as TextItem).str) | ||
for (let idx = 0; idx < textDivs.length; idx++) { | ||
@@ -177,9 +183,11 @@ const div = textDivs[idx] | ||
function findMatches(query: string, textContent: TextContent, options: HighlightOptions) { | ||
const textItems = getTextItems(textContent) | ||
const matches = searchQuery(textItems, query, options) | ||
return convertMatches(matches, textItems) | ||
function findMatches(queries: string[], textContent: TextContent, options: HighlightOptions) { | ||
const convertedMatches = [] | ||
for (const query of queries) { | ||
const matches = searchQuery(textContent, query, options) | ||
convertedMatches.push(...convertMatches(matches, textContent)) | ||
} | ||
return convertedMatches | ||
} | ||
export { findMatches, highlightMatches, resetDivs } | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3056034
13534