Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
986588ad
Commit
986588ad
authored
Jan 24, 2023
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert PDF.js types to TypeScript
parent
d674e11b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
178 additions
and
0 deletions
+178
-0
pdfjs.ts
src/types/pdfjs.ts
+178
-0
No files found.
src/types/pdfjs.
j
s
→
src/types/pdfjs.
t
s
View file @
986588ad
...
...
@@ -16,20 +16,20 @@
* Document metadata parsed from the PDF's _metadata stream_.
*
* See `Metadata` class from `display/metadata.js` in PDF.js.
*
* @typedef Metadata
* @prop {(name: string) => string} get
* @prop {(name: string) => boolean} has
*/
export
type
Metadata
=
{
get
(
name
:
string
):
string
;
has
(
name
:
string
):
boolean
;
};
/**
* Document metadata parsed from the PDF's _document info dictionary_.
*
* See `PDFDocument#documentInfo` in PDF.js.
*
* @typedef PDFDocumentInfo
* @prop {string} [Title]
*/
export
type
PDFDocumentInfo
=
{
Title
?:
string
;
};
/**
* An object containing metadata about the PDF. This includes information from:
...
...
@@ -41,113 +41,138 @@
*
* See the "Metadata" section (14.3) in the PDF 1.7 reference for details of
* the _metadata stream_ and _document info dictionary_.
*
* @typedef PDFDocumentMetadata
* @prop {Metadata|null} metadata
* @prop {PDFDocumentInfo} [info]
* @prop {string|null} contentDispositionFilename - The `filename` directive from
* the `Content-Disposition` header
*/
export
type
PDFDocumentMetadata
=
{
metadata
:
Metadata
|
null
;
info
?:
PDFDocumentInfo
;
/**
* The `filename` directive from the `Content-Disposition` header
*/
contentDispositionFilename
:
string
|
null
;
};
/**
* @typedef PDFDocument
* @prop {string} [fingerprint] -
PDF fingerprint in PDF.js before v2.10.377.
export
type
PDFDocument
=
{
/**
*
PDF fingerprint in PDF.js before v2.10.377.
* May exist in later versions depending on the PDF.js build.
* @prop {[string, string|null]} [fingerprints] - PDF fingerprints in PDF.js after
* v2.10.377. See https://github.com/mozilla/pdf.js/pull/13661. The first
* entry of this array is the "original" fingerprint and the same as the
* `fingerprint` property in older versions. The second entry is the "modified"
*/
fingerprint
?:
string
;
/**
* PDF fingerprints in PDF.js after v2.10.377. See
* https://github.com/mozilla/pdf.js/pull/13661. The first entry of this
* array is the "original" fingerprint and the same as the `fingerprint`
* property in older versions. The second entry is the "modified"
* fingerprint. See "File Identifiers" section in the PDF spec.
* @prop {() => Promise<PDFDocumentMetadata>} getMetadata
*/
fingerprints
?:
[
string
,
string
|
null
];
getMetadata
():
Promise
<
PDFDocumentMetadata
>
;
};
/**
* @typedef GetTextContentParameters
* @prop {boolean} normalizeWhitespace - Whether to convert all whitespace to
* an ASCII space char.
Obsolete since https://github.com/mozilla/pdf.js/pull/14527.
export
type
GetTextContentParameters
=
{
/**
* Whether to convert all whitespace to an ASCII space char.
*
Obsolete since https://github.com/mozilla/pdf.js/pull/14527.
*/
normalizeWhitespace
:
boolean
;
};
/**
* @typedef TextContentItem
* @prop {string} str
*/
export
type
TextContentItem
=
{
str
:
string
;
};
/**
* @typedef TextContent
* @prop {TextContentItem[]} items
*/
export
type
TextContent
=
{
items
:
TextContentItem
[];
};
/**
* @typedef PDFPageProxy
* @prop {(o?: GetTextContentParameters) => Promise<TextContent>} getTextContent
*/
export
type
PDFPageProxy
=
{
getTextContent
(
o
?:
GetTextContentParameters
):
Promise
<
TextContent
>
;
};
/**
* @typedef PDFPageView
* @prop {HTMLElement} div - Container element for the PDF page
* @prop {PDFPageProxy} pdfPage
* @prop {TextLayer|null} textLayer
* @prop {number} renderingState - See `RenderingStates` enum in src/annotator/anchoring/pdf.js
*/
export
type
PDFPageView
=
{
/** Container element for the PDF page. */
div
:
HTMLElement
;
pdfPage
:
PDFPageProxy
;
textLayer
:
TextLayer
|
null
;
/** See `RenderingStates` enum in src/annotator/anchoring/pdf.js */
renderingState
:
number
;
};
/**
* @typedef PDFViewer
*
* Defined in `web/pdf_viewer.js` in the PDF.js source.
*
* @prop {string} currentScaleValue - Zoom level/mode. This can be a string representation
* of a float or a special constant ("auto", "page-fit", "page-width" and more)
* @prop {number} pagesCount
* @prop {EventBus} eventBus -
*/
export
type
PDFViewer
=
{
/**
* Zoom level/mode. This can be a string representation of a float or a special constant
* ("auto", "page-fit", "page-width" and more)
*/
currentScaleValue
:
string
;
pagesCount
:
number
;
/**
* Reference to the global event bus. Added in PDF.js v1.6.210.
* @prop {(page: number) => PDFPageView|null} getPageView
* @prop {HTMLElement} viewer - DOM element containing the main content of the document
* @prop {() => void} update - Re-render the current view
*/
eventBus
:
EventBus
;
getPageView
(
page
:
number
):
PDFPageView
|
null
;
/** DOM element containing the main content of the document. */
viewer
:
HTMLElement
;
/** Re-render the current view. */
update
():
void
;
};
/**
* Defined in `web/ui_utils.js` in the PDF.js source.
*
* @typedef EventBus
* @prop {(event: string, listener: Function) => void} on
* @prop {(event: string, listener: Function) => void} off
*/
export
type
EventBus
=
{
on
(
event
:
string
,
listener
:
()
=>
void
):
void
;
off
(
event
:
string
,
listener
:
()
=>
void
):
void
;
};
/**
* Object containing references to various DOM elements that make up the PDF.js viewer UI,
* as well as a few other global objects used by the viewer.
*
* @typedef AppConfig
* @prop {HTMLElement} appContainer
* Object containing references to various DOM elements that make up the PDF.js
* viewer UI, as well as a few other global objects used by the viewer.
*/
export
type
AppConfig
=
{
appContainer
:
HTMLElement
;
};
/**
* The `PDFViewerApplication` global which is the entry-point for accessing PDF.js.
*
* Defined in `web/app.js` in the PDF.js source.
*
* @typedef PDFViewerApplication
* @prop {AppConfig} [appConfig] - Viewer DOM elements. Since v1.5.188.
* @prop {EventBus} [eventBus] -
*/
export
type
PDFViewerApplication
=
{
/**
* Viewer DOM elements. Since v1.5.188.
*/
appConfig
?:
AppConfig
;
/**
* Global event bus. Since v1.6.210. This is not available until the PDF viewer
* has been initialized. See `initialized` and `initializedPromise` properties.
* @prop {PDFDocument} pdfDocument
* @prop {PDFViewer} pdfViewer
* @prop {boolean} downloadComplete
* @prop {PDFDocumentInfo} documentInfo
* @prop {Metadata} metadata
* @prop {boolean} initialized - Indicates that the PDF viewer is initialized.
* @prop {Promise<void>} [initializedPromise] -
*/
eventBus
?:
EventBus
;
pdfDocument
:
PDFDocument
;
pdfViewer
:
PDFViewer
;
downloadComplete
:
boolean
;
documentInfo
:
PDFDocumentInfo
;
metadata
:
Metadata
;
/**
* Indicates that the PDF viewer is initialized.
*/
initialized
:
boolean
;
/**
* Promise that resolves when PDF.js is initialized. Since v2.4.456.
* See https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage#initialization-promise.
* @prop {string} url - The URL of the loaded PDF file
*/
initializedPromise
?:
Promise
<
void
>
;
/** The URL of the loaded PDF file. */
url
:
string
;
};
/**
* @typedef TextLayer
* @prop {boolean} renderingDone
* @prop {HTMLElement} [div] - New name for root element of text layer in PDF.js >= v3.2.146
* @prop {HTMLElement} [textLayerDiv] - Old name for root element of text layer
export
type
TextLayer
=
{
renderingDone
:
boolean
;
/**
* New name for root element of text layer in PDF.js >= v3.2.146
*/
export
{};
div
?:
HTMLElement
;
/** Old name for root element of text layer. */
textLayerDiv
?:
HTMLElement
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment