Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tato30/vue-pdf

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tato30/vue-pdf - npm Package Compare versions

Comparing version 1.7.4 to 1.8.0

10

dist/types/components/types.d.ts
import type { PageViewport } from 'pdfjs-dist';
import type { OnProgressParameters } from 'pdfjs-dist/types/src/display/api';
import type { DocumentInitParameters, OnProgressParameters, PDFDataRangeTransport, TypedArray } from 'pdfjs-dist/types/src/display/api';
import type { Metadata } from 'pdfjs-dist/types/src/display/metadata';

@@ -9,2 +9,9 @@ export type LoadedEventPayload = PageViewport;

}
export interface WatermarkOptions {
columns?: number;
rows?: number;
rotation?: number;
fontSize?: number;
color?: string;
}
export type OnProgressCallback = (progressData: OnProgressParameters) => void;

@@ -14,2 +21,3 @@ export type UpdatePasswordFn = (newPassword: string) => void;

export type OnErrorCallback = (error: any) => void;
export type UsePDFSrc = string | URL | TypedArray | PDFDataRangeTransport | DocumentInitParameters;
export interface UsePDFOptions {

@@ -16,0 +24,0 @@ onProgress?: OnProgressCallback;

6

dist/types/components/usePDF.d.ts

@@ -1,3 +0,3 @@

import type { DocumentInitParameters, PDFDataRangeTransport, TypedArray } from 'pdfjs-dist/types/src/display/api';
import type { UsePDFInfo, UsePDFOptions } from './types';
import type { Ref } from 'vue';
import type { UsePDFInfo, UsePDFOptions, UsePDFSrc } from './types';
/**

@@ -21,3 +21,3 @@ * @typedef {Object} UsePDFParameters

*/
export declare function usePDF(src: string | URL | TypedArray | PDFDataRangeTransport | DocumentInitParameters, options?: UsePDFOptions): {
export declare function usePDF(src: UsePDFSrc | Ref<UsePDFSrc>, options?: UsePDFOptions): {
pdf: import("vue").ShallowRef<import("pdfjs-dist/types/src/display/api").PDFDocumentLoadingTask | undefined>;

@@ -24,0 +24,0 @@ pages: import("vue").ShallowRef<number>;

import 'pdfjs-dist/web/pdf_viewer.css';
import type { AnnotationEventPayload } from './types';
import type { AnnotationEventPayload, WatermarkOptions } from './types';
declare function reload(): void;

@@ -19,2 +19,3 @@ declare function cancel(): void;

watermarkText?: string | undefined;
watermarkOptions?: WatermarkOptions | undefined;
}>, {

@@ -43,2 +44,3 @@ page: number;

watermarkText?: string | undefined;
watermarkOptions?: WatermarkOptions | undefined;
}>, {

@@ -45,0 +47,0 @@ page: number;

{
"name": "@tato30/vue-pdf",
"version": "1.7.4",
"version": "1.8.0",
"description": "PDF viewer for Vue 3",

@@ -5,0 +5,0 @@ "author": {

import type { PageViewport } from 'pdfjs-dist'
import type { OnProgressParameters } from 'pdfjs-dist/types/src/display/api'
import type {
DocumentInitParameters,
OnProgressParameters,
PDFDataRangeTransport,
TypedArray,
} from 'pdfjs-dist/types/src/display/api'
import type { Metadata } from 'pdfjs-dist/types/src/display/metadata'

@@ -12,2 +17,10 @@

export interface WatermarkOptions {
columns?: number
rows?: number
rotation?: number
fontSize?: number
color?: string
}
export type OnProgressCallback = (progressData: OnProgressParameters) => void

@@ -18,2 +31,9 @@ export type UpdatePasswordFn = (newPassword: string) => void

export type UsePDFSrc =
| string
| URL
| TypedArray
| PDFDataRangeTransport
| DocumentInitParameters
export interface UsePDFOptions {

@@ -20,0 +40,0 @@ onProgress?: OnProgressCallback

import * as PDFJS from 'pdfjs-dist'
import PDFWorker from 'pdfjs-dist/build/pdf.worker.min?url'
import { shallowRef } from 'vue'
import { isRef, shallowRef, watch } from 'vue'
import type { PDFDocumentLoadingTask } from 'pdfjs-dist'
import type { DocumentInitParameters, PDFDataRangeTransport, TypedArray } from 'pdfjs-dist/types/src/display/api'
import type { OnPasswordCallback, UsePDFInfo, UsePDFOptions } from './types'
import type { Ref } from 'vue'
import type { OnPasswordCallback, UsePDFInfo, UsePDFOptions, UsePDFSrc } from './types'

@@ -35,8 +35,10 @@ // Could not find a way to make this work with vite, importing the worker entry bundle the whole worker to the the final output

*/
export function usePDF(src: string | URL | TypedArray | PDFDataRangeTransport | DocumentInitParameters, options: UsePDFOptions = {
onProgress: undefined,
onPassword: undefined,
onError: undefined,
password: '',
}) {
export function usePDF(src: UsePDFSrc | Ref<UsePDFSrc>,
options: UsePDFOptions = {
onProgress: undefined,
onPassword: undefined,
onError: undefined,
password: '',
},
) {
if (!PDFJS.GlobalWorkerOptions?.workerSrc)

@@ -49,35 +51,48 @@ configWorker(PDFWorker)

const loadingTask = PDFJS.getDocument(src)
if (options.onProgress)
loadingTask.onProgress = options.onProgress
function processLoadingTask(source: UsePDFSrc) {
const loadingTask = PDFJS.getDocument(source)
if (options.onProgress)
loadingTask.onProgress = options.onProgress
if (options.onPassword) {
loadingTask.onPassword = options.onPassword
}
else if (options.password) {
const onPassword: OnPasswordCallback = (updatePassword, _) => {
updatePassword(options.password ?? '')
if (options.onPassword) {
loadingTask.onPassword = options.onPassword
}
loadingTask.onPassword = onPassword
}
else if (options.password) {
const onPassword: OnPasswordCallback = (updatePassword, _) => {
updatePassword(options.password ?? '')
}
loadingTask.onPassword = onPassword
}
loadingTask.promise.then(async (doc) => {
pdf.value = doc.loadingTask
pages.value = doc.numPages
loadingTask.promise.then(
async (doc) => {
pdf.value = doc.loadingTask
pages.value = doc.numPages
const metadata = await doc.getMetadata()
const attachments = (await doc.getAttachments()) as Record<string, unknown>
const javascript = await doc.getJavaScript()
const metadata = await doc.getMetadata()
const attachments = (await doc.getAttachments()) as Record<string, unknown>
const javascript = await doc.getJavaScript()
info.value = {
metadata,
attachments,
javascript,
}
}, (error) => {
// PDF loading error
if (typeof options.onError === 'function')
options.onError(error)
})
info.value = {
metadata,
attachments,
javascript,
}
},
(error) => {
// PDF loading error
if (typeof options.onError === 'function')
options.onError(error)
},
)
}
if (isRef(src)) {
processLoadingTask(src.value)
watch(src, () => processLoadingTask(src.value))
}
else {
processLoadingTask(src)
}
return {

@@ -84,0 +99,0 @@ pdf,

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc