@octanejs/pdf 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +54 -0
- package/THIRD_PARTY_NOTICES.md +12 -0
- package/UPSTREAM.md +30 -0
- package/dist/Page/AnnotationLayer.css +333 -0
- package/dist/Page/TextLayer.css +119 -0
- package/package.json +80 -0
- package/src/LinkService.ts +128 -0
- package/src/PasswordResponses.ts +6 -0
- package/src/Ref.ts +15 -0
- package/src/components.tsrx +887 -0
- package/src/contexts.ts +19 -0
- package/src/index.server.ts +18 -0
- package/src/index.ts +20 -0
- package/src/refs.ts +14 -0
- package/src/types.ts +205 -0
- package/src/utils.ts +27 -0
- package/src/vite-env.d.ts +4 -0
- package/upstream-public-surface.json +65 -0
package/src/contexts.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContext, useContext } from 'octane';
|
|
2
|
+
|
|
3
|
+
import type { DocumentContextValue, OutlineContextValue, PageContextValue } from './types.js';
|
|
4
|
+
|
|
5
|
+
export const DocumentContext = createContext<DocumentContextValue | null>(null);
|
|
6
|
+
export const OutlineContext = createContext<OutlineContextValue | null>(null);
|
|
7
|
+
export const PageContext = createContext<PageContextValue | null>(null);
|
|
8
|
+
|
|
9
|
+
export function useDocumentContext(): DocumentContextValue | null {
|
|
10
|
+
return useContext(DocumentContext);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useOutlineContext(): OutlineContextValue | null {
|
|
14
|
+
return useContext(OutlineContext);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function usePageContext(): PageContextValue | null {
|
|
18
|
+
return useContext(PageContext);
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as pdfjs from 'pdfjs-dist/legacy/build/pdf.mjs';
|
|
2
|
+
|
|
3
|
+
export { Document, Outline, Page, Thumbnail } from './components.tsrx';
|
|
4
|
+
export { useDocumentContext, useOutlineContext, usePageContext } from './contexts.js';
|
|
5
|
+
export { default as PasswordResponses } from './PasswordResponses.js';
|
|
6
|
+
export { pdfjs };
|
|
7
|
+
export type { default as LinkService } from './LinkService.js';
|
|
8
|
+
export type {
|
|
9
|
+
DocumentProps,
|
|
10
|
+
OutlineProps,
|
|
11
|
+
PageProps,
|
|
12
|
+
PasswordResponsesType,
|
|
13
|
+
StructTreeNode,
|
|
14
|
+
TextContent,
|
|
15
|
+
TextItem,
|
|
16
|
+
TextMarkedContent,
|
|
17
|
+
ThumbnailProps,
|
|
18
|
+
} from './types.js';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as pdfjs from 'pdfjs-dist';
|
|
2
|
+
|
|
3
|
+
// OCTANE DIVERGENCE[pdf-octane-node-ref-event-types][differential:react-pdf-document-shells]
|
|
4
|
+
// OCTANE DIVERGENCE[pdf-star-export-surface][types:pdf-adapted]
|
|
5
|
+
export { Document, Outline, Page, Thumbnail } from './components.tsrx';
|
|
6
|
+
export { useDocumentContext, useOutlineContext, usePageContext } from './contexts.js';
|
|
7
|
+
export { default as PasswordResponses } from './PasswordResponses.js';
|
|
8
|
+
export { pdfjs };
|
|
9
|
+
export type { default as LinkService } from './LinkService.js';
|
|
10
|
+
export type {
|
|
11
|
+
DocumentProps,
|
|
12
|
+
OutlineProps,
|
|
13
|
+
PageProps,
|
|
14
|
+
PasswordResponsesType,
|
|
15
|
+
StructTreeNode,
|
|
16
|
+
TextContent,
|
|
17
|
+
TextItem,
|
|
18
|
+
TextMarkedContent,
|
|
19
|
+
ThumbnailProps,
|
|
20
|
+
} from './types.js';
|
package/src/refs.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OctaneRef } from './types.js';
|
|
2
|
+
|
|
3
|
+
export function setRef<T>(ref: OctaneRef<T> | undefined, value: T | null): void {
|
|
4
|
+
if (!ref) return;
|
|
5
|
+
if (Array.isArray(ref)) {
|
|
6
|
+
for (const child of ref) setRef(child, value);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (typeof ref === 'function') {
|
|
10
|
+
ref(value);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
(ref as { current: T | null }).current = value;
|
|
14
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
|
|
2
|
+
import type { AnnotationLayerParameters } from 'pdfjs-dist/types/src/display/annotation_layer.js';
|
|
3
|
+
import type {
|
|
4
|
+
DocumentInitParameters,
|
|
5
|
+
RefProxy,
|
|
6
|
+
StructTreeNode,
|
|
7
|
+
TextContent,
|
|
8
|
+
TextItem,
|
|
9
|
+
TextMarkedContent,
|
|
10
|
+
TypedArray,
|
|
11
|
+
} from 'pdfjs-dist/types/src/display/api.js';
|
|
12
|
+
import type { ClassValue, JSX } from 'octane/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
import type LinkService from './LinkService.js';
|
|
15
|
+
|
|
16
|
+
export type { StructTreeNode, TextContent, TextItem, TextMarkedContent };
|
|
17
|
+
export type PasswordResponsesType = typeof import('pdfjs-dist').PasswordResponses;
|
|
18
|
+
|
|
19
|
+
export type OctaneNode = unknown;
|
|
20
|
+
export type OctaneRef<T> =
|
|
21
|
+
{ current: T | null } | ((value: T | null) => void) | readonly OctaneRef<T>[] | null;
|
|
22
|
+
export type ClassName = ClassValue;
|
|
23
|
+
export type Annotations = NonNullable<AnnotationLayerParameters['annotations']>;
|
|
24
|
+
export type ResolvedDest = (RefProxy | number)[];
|
|
25
|
+
export type Dest = Promise<ResolvedDest> | ResolvedDest | string | null;
|
|
26
|
+
export type ExternalLinkRel = string;
|
|
27
|
+
export type ExternalLinkTarget = '_blank' | '_parent' | '_self' | '_top';
|
|
28
|
+
export type OnItemClickArgs = {
|
|
29
|
+
dest?: Dest;
|
|
30
|
+
pageIndex: number;
|
|
31
|
+
pageNumber: number;
|
|
32
|
+
};
|
|
33
|
+
export type ScrollPageIntoViewArgs = {
|
|
34
|
+
dest?: ResolvedDest;
|
|
35
|
+
pageIndex?: number;
|
|
36
|
+
pageNumber: number;
|
|
37
|
+
};
|
|
38
|
+
export type RenderMode = 'canvas' | 'custom' | 'none';
|
|
39
|
+
type BinaryData = TypedArray | ArrayBuffer | number[] | string;
|
|
40
|
+
export type Source =
|
|
41
|
+
{ data: BinaryData | undefined } | { range: PDFDataRangeTransport } | { url: string };
|
|
42
|
+
export type File = string | ArrayBuffer | Blob | Source | null;
|
|
43
|
+
type SourceKey = keyof { data: unknown } | keyof { range: unknown } | keyof { url: unknown };
|
|
44
|
+
export type Options = {
|
|
45
|
+
[K in keyof Omit<DocumentInitParameters, SourceKey>]: DocumentInitParameters[K] | null;
|
|
46
|
+
};
|
|
47
|
+
export type NodeOrRenderer = OctaneNode | (() => OctaneNode);
|
|
48
|
+
export type PageColors = { background: string; foreground: string };
|
|
49
|
+
export type PageCallback = PDFPageProxy & {
|
|
50
|
+
height: number;
|
|
51
|
+
originalHeight: number;
|
|
52
|
+
originalWidth: number;
|
|
53
|
+
width: number;
|
|
54
|
+
};
|
|
55
|
+
export type CustomRenderer = (props?: Record<string, never>) => OctaneNode;
|
|
56
|
+
export type CustomTextRenderer = (
|
|
57
|
+
props: { itemIndex: number; pageIndex: number; pageNumber: number } & TextItem,
|
|
58
|
+
) => string;
|
|
59
|
+
export type FilterAnnotations = (args: { annotations: Annotations }) => Annotations;
|
|
60
|
+
|
|
61
|
+
export interface DocumentContextValue {
|
|
62
|
+
imageResourcesPath?: string;
|
|
63
|
+
linkService: LinkService;
|
|
64
|
+
onItemClick?: (args: OnItemClickArgs) => void;
|
|
65
|
+
pdf?: PDFDocumentProxy | false;
|
|
66
|
+
registerPage: (pageIndex: number, ref: HTMLDivElement) => void;
|
|
67
|
+
renderMode?: RenderMode;
|
|
68
|
+
rotate?: number | null;
|
|
69
|
+
scale?: number;
|
|
70
|
+
unregisterPage: (pageIndex: number) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface PageContextValue {
|
|
74
|
+
page: PDFPageProxy | false | undefined;
|
|
75
|
+
pageIndex: number;
|
|
76
|
+
pageNumber: number;
|
|
77
|
+
rotate: number;
|
|
78
|
+
scale: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface OutlineContextValue {
|
|
82
|
+
onItemClick?: (args: OnItemClickArgs) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type DocumentRenderProps = Omit<DocumentContextValue, 'pdf'> & { pdf: PDFDocumentProxy };
|
|
86
|
+
export type PageRenderProps = Omit<PageContextValue, 'page'> & { page: PDFPageProxy };
|
|
87
|
+
|
|
88
|
+
type DivProps = JSX.IntrinsicElements['div'];
|
|
89
|
+
type EventKey = NonNullable<
|
|
90
|
+
{
|
|
91
|
+
[Key in keyof DivProps]: Key extends `on${string}` ? Key : never;
|
|
92
|
+
}[keyof DivProps]
|
|
93
|
+
>;
|
|
94
|
+
type EventProps<Value> = {
|
|
95
|
+
[Key in EventKey]?: NonNullable<DivProps[Key]> extends (
|
|
96
|
+
event: infer Event,
|
|
97
|
+
...args: never[]
|
|
98
|
+
) => unknown
|
|
99
|
+
? (event: Event, value: Value) => void
|
|
100
|
+
: never;
|
|
101
|
+
};
|
|
102
|
+
export type HostProps<Value> = EventProps<Value> & {
|
|
103
|
+
children?: OctaneNode;
|
|
104
|
+
class?: ClassName;
|
|
105
|
+
className?: ClassName;
|
|
106
|
+
ref?: OctaneRef<unknown>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type DocumentProps = HostProps<PDFDocumentProxy | false | undefined> & {
|
|
110
|
+
children?: OctaneNode | ((props: DocumentRenderProps) => OctaneNode);
|
|
111
|
+
error?: NodeOrRenderer;
|
|
112
|
+
externalLinkRel?: ExternalLinkRel;
|
|
113
|
+
externalLinkTarget?: ExternalLinkTarget;
|
|
114
|
+
file?: File;
|
|
115
|
+
imageResourcesPath?: string;
|
|
116
|
+
inputRef?: OctaneRef<HTMLDivElement>;
|
|
117
|
+
loading?: NodeOrRenderer;
|
|
118
|
+
noData?: NodeOrRenderer;
|
|
119
|
+
onItemClick?: (args: OnItemClickArgs) => void;
|
|
120
|
+
onLoadError?: (error: Error) => void;
|
|
121
|
+
onLoadProgress?: (args: { loaded: number; total: number }) => void;
|
|
122
|
+
onLoadSuccess?: (document: PDFDocumentProxy) => void;
|
|
123
|
+
onPassword?: (callback: (password: string | null) => void, reason: number) => void;
|
|
124
|
+
onSourceError?: (error: Error) => void;
|
|
125
|
+
onSourceSuccess?: () => void;
|
|
126
|
+
options?: Options;
|
|
127
|
+
renderMode?: RenderMode;
|
|
128
|
+
rotate?: number | null;
|
|
129
|
+
scale?: number;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type PageProps = HostProps<PageCallback | false | undefined> & {
|
|
133
|
+
_className?: string;
|
|
134
|
+
_enableRegisterUnregisterPage?: boolean;
|
|
135
|
+
canvasBackground?: string;
|
|
136
|
+
canvasRef?: OctaneRef<HTMLCanvasElement>;
|
|
137
|
+
children?: OctaneNode | ((props: PageRenderProps) => OctaneNode);
|
|
138
|
+
customRenderer?: CustomRenderer;
|
|
139
|
+
customTextRenderer?: CustomTextRenderer;
|
|
140
|
+
devicePixelRatio?: number;
|
|
141
|
+
error?: NodeOrRenderer;
|
|
142
|
+
filterAnnotations?: FilterAnnotations;
|
|
143
|
+
height?: number;
|
|
144
|
+
imageResourcesPath?: string;
|
|
145
|
+
inputRef?: OctaneRef<HTMLDivElement>;
|
|
146
|
+
loading?: NodeOrRenderer;
|
|
147
|
+
noData?: NodeOrRenderer;
|
|
148
|
+
onGetAnnotationsError?: (error: Error) => void;
|
|
149
|
+
onGetAnnotationsSuccess?: (annotations: Annotations) => void;
|
|
150
|
+
onGetStructTreeError?: (error: Error) => void;
|
|
151
|
+
onGetStructTreeSuccess?: (tree: StructTreeNode) => void;
|
|
152
|
+
onGetTextError?: (error: Error) => void;
|
|
153
|
+
onGetTextSuccess?: (content: TextContent) => void;
|
|
154
|
+
onLoadError?: (error: Error) => void;
|
|
155
|
+
onLoadSuccess?: (page: PageCallback) => void;
|
|
156
|
+
onRenderAnnotationLayerError?: (error: unknown) => void;
|
|
157
|
+
onRenderAnnotationLayerSuccess?: () => void;
|
|
158
|
+
onRenderError?: (error: Error) => void;
|
|
159
|
+
onRenderSuccess?: (page: PageCallback) => void;
|
|
160
|
+
onRenderTextLayerError?: (error: Error) => void;
|
|
161
|
+
onRenderTextLayerSuccess?: () => void;
|
|
162
|
+
pageColors?: PageColors;
|
|
163
|
+
pageIndex?: number;
|
|
164
|
+
pageNumber?: number;
|
|
165
|
+
pdf?: PDFDocumentProxy | false;
|
|
166
|
+
registerPage?: (pageIndex: number, ref: HTMLDivElement) => void;
|
|
167
|
+
renderAnnotationLayer?: boolean;
|
|
168
|
+
renderForms?: boolean;
|
|
169
|
+
renderMode?: RenderMode;
|
|
170
|
+
renderTextLayer?: boolean;
|
|
171
|
+
rotate?: number | null;
|
|
172
|
+
scale?: number;
|
|
173
|
+
unregisterPage?: (pageIndex: number) => void;
|
|
174
|
+
width?: number;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export type ThumbnailProps = Omit<
|
|
178
|
+
PageProps,
|
|
179
|
+
| 'className'
|
|
180
|
+
| 'customTextRenderer'
|
|
181
|
+
| 'onGetAnnotationsError'
|
|
182
|
+
| 'onGetAnnotationsSuccess'
|
|
183
|
+
| 'onGetTextError'
|
|
184
|
+
| 'onGetTextSuccess'
|
|
185
|
+
| 'onRenderAnnotationLayerError'
|
|
186
|
+
| 'onRenderAnnotationLayerSuccess'
|
|
187
|
+
| 'onRenderTextLayerError'
|
|
188
|
+
| 'onRenderTextLayerSuccess'
|
|
189
|
+
| 'renderAnnotationLayer'
|
|
190
|
+
| 'renderForms'
|
|
191
|
+
| 'renderTextLayer'
|
|
192
|
+
> & {
|
|
193
|
+
className?: ClassName;
|
|
194
|
+
onItemClick?: (args: OnItemClickArgs) => void;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type OutlineProps = HostProps<
|
|
198
|
+
Awaited<ReturnType<PDFDocumentProxy['getOutline']>> | false | undefined
|
|
199
|
+
> & {
|
|
200
|
+
inputRef?: OctaneRef<HTMLDivElement>;
|
|
201
|
+
onItemClick?: (args: OnItemClickArgs) => void;
|
|
202
|
+
onLoadError?: (error: Error) => void;
|
|
203
|
+
onLoadSuccess?: (outline: Awaited<ReturnType<PDFDocumentProxy['getOutline']>>) => void;
|
|
204
|
+
pdf?: PDFDocumentProxy | false;
|
|
205
|
+
};
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function isDataURI(value: unknown): value is string {
|
|
2
|
+
return typeof value === 'string' && /^data:/.test(value);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function dataURItoByteString(uri: string): string {
|
|
6
|
+
if (!isDataURI(uri)) throw new Error('Invalid data URI.');
|
|
7
|
+
const comma = uri.indexOf(',');
|
|
8
|
+
if (comma < 0) throw new Error('Invalid data URI.');
|
|
9
|
+
const metadata = uri.slice(0, comma);
|
|
10
|
+
const payload = uri.slice(comma + 1);
|
|
11
|
+
return metadata.includes(';base64') ? atob(payload) : decodeURIComponent(payload);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function dataURItoBytes(uri: string): Uint8Array {
|
|
15
|
+
return Uint8Array.from(dataURItoByteString(uri), (character) => character.charCodeAt(0));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function convertDataUriParameterObject<T extends { url: string }>(
|
|
19
|
+
file: T,
|
|
20
|
+
): Omit<T, 'url'> & { data: Uint8Array } {
|
|
21
|
+
const { url, ...otherParams } = file;
|
|
22
|
+
return { data: dataURItoBytes(url), ...otherParams };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isProvided<T>(value: T | null | undefined): value is T {
|
|
26
|
+
return value !== null && value !== undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"authority": {
|
|
3
|
+
"package": "react-pdf",
|
|
4
|
+
"version": "10.4.1",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"rootRuntimeExports": [
|
|
11
|
+
"Document",
|
|
12
|
+
"Outline",
|
|
13
|
+
"Page",
|
|
14
|
+
"PasswordResponses",
|
|
15
|
+
"Thumbnail",
|
|
16
|
+
"pdfjs",
|
|
17
|
+
"useDocumentContext",
|
|
18
|
+
"useOutlineContext",
|
|
19
|
+
"usePageContext"
|
|
20
|
+
],
|
|
21
|
+
"rootTypeExports": [
|
|
22
|
+
"DocumentProps",
|
|
23
|
+
"LinkService",
|
|
24
|
+
"OutlineProps",
|
|
25
|
+
"PageProps",
|
|
26
|
+
"PasswordResponsesType",
|
|
27
|
+
"StructTreeNode",
|
|
28
|
+
"TextContent",
|
|
29
|
+
"TextItem",
|
|
30
|
+
"TextMarkedContent",
|
|
31
|
+
"ThumbnailProps"
|
|
32
|
+
],
|
|
33
|
+
"documentedSubpaths": [
|
|
34
|
+
{
|
|
35
|
+
"upstream": "react-pdf/dist/Page/AnnotationLayer.css",
|
|
36
|
+
"octane": "@octanejs/pdf/dist/Page/AnnotationLayer.css",
|
|
37
|
+
"classification": "exact-public-support"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"upstream": "react-pdf/dist/Page/TextLayer.css",
|
|
41
|
+
"octane": "@octanejs/pdf/dist/Page/TextLayer.css",
|
|
42
|
+
"classification": "exact-public-support"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"upstream": "pdfjs-dist/build/pdf.worker.min.mjs",
|
|
46
|
+
"octane": "pdfjs-dist/build/pdf.worker.min.mjs",
|
|
47
|
+
"classification": "unchanged-framework-neutral-dependency"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"wildcardPolicy": {
|
|
51
|
+
"classification": "framework-private-evidence-only",
|
|
52
|
+
"reason": "The permissive ./* export exposes React implementation, declarations, tests, and source artifacts that are not documented component entry points. They remain pinned parity evidence. Root exports and the two documented CSS imports are the Octane compatibility contract; direct imports of React implementation files are not remapped.",
|
|
53
|
+
"artifactRules": [
|
|
54
|
+
"LICENSE",
|
|
55
|
+
"README.md",
|
|
56
|
+
"package.json",
|
|
57
|
+
"dist/**/*.d.ts",
|
|
58
|
+
"dist/**/*.js",
|
|
59
|
+
"src/**/*.css",
|
|
60
|
+
"src/**/*.ts",
|
|
61
|
+
"src/**/*.tsx"
|
|
62
|
+
],
|
|
63
|
+
"exactPublicExceptions": ["dist/Page/AnnotationLayer.css", "dist/Page/TextLayer.css"]
|
|
64
|
+
}
|
|
65
|
+
}
|