@sdata/web-vue 3.9.0 → 3.11.0
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/dist/sd.css +257 -5
- package/dist/sd.min.css +1 -1
- package/es/components.d.ts +1 -0
- package/es/file-previewer/file-previewer.vue.d.ts +5 -1
- package/es/file-previewer/file-previewer.vue_vue_type_script_setup_true_lang.js +117 -21
- package/es/file-previewer/index.d.ts +33 -3
- package/es/file-previewer/pdfjs-worker-url.d.ts +2 -0
- package/es/file-previewer/pdfjs-worker-url.js +4 -0
- package/es/file-previewer/pdfjs-worker.min.mjs +29 -0
- package/es/file-previewer/style/index.css +53 -5
- package/es/file-previewer/style/index.scss +58 -6
- package/es/file-previewer/style/token.scss +13 -0
- package/es/file-previewer/types.d.ts +55 -1
- package/es/file-previewer/use-pdf-js.d.ts +20 -0
- package/es/file-previewer/use-pdf-js.js +197 -0
- package/es/index.css +257 -5
- package/es/index.d.ts +3 -1
- package/es/index.js +2 -1
- package/es/index.scss +1 -0
- package/es/sd-vue.js +2 -0
- package/es/selectable-card/index.d.ts +88 -0
- package/es/selectable-card/index.js +10 -0
- package/es/selectable-card/selectable-card.js +5 -0
- package/es/selectable-card/selectable-card.vue.d.ts +39 -0
- package/es/selectable-card/selectable-card.vue_vue_type_script_setup_true_lang.js +115 -0
- package/es/selectable-card/style/css.js +2 -0
- package/es/selectable-card/style/index.css +220 -0
- package/es/selectable-card/style/index.d.ts +2 -0
- package/es/selectable-card/style/index.js +2 -0
- package/es/selectable-card/style/index.scss +202 -0
- package/es/selectable-card/style/token.scss +27 -0
- package/es/selectable-card/types.d.ts +7 -0
- package/es/tree/base-node.vue_vue_type_script_setup_true_lang.js +17 -10
- package/es/tree/interface.d.ts +1 -0
- package/es/tree/tree.vue.d.ts +9 -0
- package/es/tree/tree.vue_vue_type_script_setup_true_lang.js +8 -0
- package/json/vetur-attributes.json +4 -0
- package/json/vetur-tags.json +4 -0
- package/json/web-types.json +15 -1
- package/package.json +3 -1
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
min-width: 0;
|
|
80
80
|
min-height: 0;
|
|
81
81
|
}
|
|
82
|
-
.sd-file-previewer-image, .sd-file-previewer-video-player, .sd-file-previewer-audio-player, .sd-file-previewer-video
|
|
82
|
+
.sd-file-previewer-image, .sd-file-previewer-video-player, .sd-file-previewer-audio-player, .sd-file-previewer-video {
|
|
83
83
|
display: block;
|
|
84
84
|
width: 100%;
|
|
85
85
|
height: 100%;
|
|
@@ -122,12 +122,60 @@
|
|
|
122
122
|
width: 100%;
|
|
123
123
|
}
|
|
124
124
|
.sd-file-previewer-pdf {
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-direction: column;
|
|
127
|
+
gap: 6px;
|
|
128
|
+
width: 100%;
|
|
129
|
+
height: 100%;
|
|
130
|
+
}
|
|
131
|
+
.sd-file-previewer-pdf-canvas-wrap {
|
|
132
|
+
display: flex;
|
|
133
|
+
flex: 1;
|
|
134
|
+
align-items: center;
|
|
135
|
+
justify-content: center;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
overflow: auto;
|
|
139
|
+
background: var(--sd-color-bg-1);
|
|
140
|
+
border-radius: var(--sd-border-radius-medium);
|
|
141
|
+
}
|
|
142
|
+
.sd-file-previewer-pdf-canvas {
|
|
143
|
+
display: block;
|
|
144
|
+
}
|
|
145
|
+
.sd-file-previewer-pdf-toolbar {
|
|
146
|
+
display: flex;
|
|
147
|
+
flex-shrink: 0;
|
|
148
|
+
gap: 6px;
|
|
149
|
+
align-items: center;
|
|
150
|
+
justify-content: center;
|
|
151
|
+
padding: 4px;
|
|
152
|
+
color: var(--sd-color-white);
|
|
153
|
+
background: rgba(0, 0, 0, 0.5);
|
|
127
154
|
border-radius: var(--sd-border-radius-medium);
|
|
128
155
|
}
|
|
129
|
-
.sd-file-previewer-
|
|
130
|
-
|
|
156
|
+
.sd-file-previewer-pdf-btn {
|
|
157
|
+
display: inline-flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
min-width: 28px;
|
|
161
|
+
height: 28px;
|
|
162
|
+
padding: 0 6px;
|
|
163
|
+
color: inherit;
|
|
164
|
+
font-size: 16px;
|
|
165
|
+
line-height: 1;
|
|
166
|
+
background: transparent;
|
|
167
|
+
border: 0;
|
|
168
|
+
border-radius: var(--sd-border-radius-small);
|
|
169
|
+
cursor: pointer;
|
|
170
|
+
}
|
|
171
|
+
.sd-file-previewer-pdf-btn:disabled {
|
|
172
|
+
color: var(--sd-color-fill-3);
|
|
173
|
+
cursor: not-allowed;
|
|
174
|
+
}
|
|
175
|
+
.sd-file-previewer-pdf-page {
|
|
176
|
+
min-width: 64px;
|
|
177
|
+
font-size: 14px;
|
|
178
|
+
text-align: center;
|
|
131
179
|
}
|
|
132
180
|
.sd-file-previewer-close-btn {
|
|
133
181
|
position: absolute;
|
|
@@ -93,8 +93,7 @@ $image-prefix-cls: string.unquote('#{theme.$prefix}-image');
|
|
|
93
93
|
&-image,
|
|
94
94
|
&-video-player,
|
|
95
95
|
&-audio-player,
|
|
96
|
-
&-video
|
|
97
|
-
&-pdf {
|
|
96
|
+
&-video {
|
|
98
97
|
display: block;
|
|
99
98
|
width: 100%;
|
|
100
99
|
height: 100%;
|
|
@@ -149,13 +148,66 @@ $image-prefix-cls: string.unquote('#{theme.$prefix}-image');
|
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
&-pdf {
|
|
152
|
-
|
|
151
|
+
display: flex;
|
|
152
|
+
flex-direction: column;
|
|
153
|
+
gap: $file-previewer-spacing-pdf-gap;
|
|
154
|
+
width: 100%;
|
|
155
|
+
height: 100%;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
&-pdf-canvas-wrap {
|
|
159
|
+
display: flex;
|
|
160
|
+
flex: 1;
|
|
161
|
+
align-items: center;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
min-width: 0;
|
|
164
|
+
min-height: 0;
|
|
165
|
+
overflow: auto;
|
|
166
|
+
background: $file-previewer-color-pdf-canvas-bg;
|
|
167
|
+
border-radius: $file-previewer-radius-pdf-canvas;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
&-pdf-canvas {
|
|
171
|
+
display: block;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
&-pdf-toolbar {
|
|
175
|
+
display: flex;
|
|
176
|
+
flex-shrink: 0;
|
|
177
|
+
gap: $file-previewer-spacing-pdf-toolbar-gap;
|
|
178
|
+
align-items: center;
|
|
179
|
+
justify-content: center;
|
|
180
|
+
padding: $file-previewer-spacing-pdf-toolbar-padding;
|
|
181
|
+
color: $file-previewer-color-pdf-toolbar-text;
|
|
182
|
+
background: $file-previewer-color-pdf-toolbar-bg;
|
|
183
|
+
border-radius: $file-previewer-radius-pdf-canvas;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
&-pdf-btn {
|
|
187
|
+
display: inline-flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
justify-content: center;
|
|
190
|
+
min-width: $file-previewer-size-pdf-btn-min-width;
|
|
191
|
+
height: $file-previewer-size-pdf-btn;
|
|
192
|
+
padding: 0 $file-previewer-spacing-pdf-toolbar-gap;
|
|
193
|
+
color: inherit;
|
|
194
|
+
font-size: $file-previewer-font-size-pdf-btn;
|
|
195
|
+
line-height: 1;
|
|
196
|
+
background: transparent;
|
|
153
197
|
border: 0;
|
|
154
|
-
border-radius: $file-previewer-radius-
|
|
198
|
+
border-radius: $file-previewer-radius-pdf-btn;
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
|
|
201
|
+
&:disabled {
|
|
202
|
+
color: $file-previewer-color-pdf-btn-disabled;
|
|
203
|
+
cursor: not-allowed;
|
|
204
|
+
}
|
|
155
205
|
}
|
|
156
206
|
|
|
157
|
-
&-
|
|
158
|
-
|
|
207
|
+
&-pdf-page {
|
|
208
|
+
min-width: 64px;
|
|
209
|
+
font-size: $file-previewer-font-size-pdf-page;
|
|
210
|
+
text-align: center;
|
|
159
211
|
}
|
|
160
212
|
|
|
161
213
|
&-close-btn {
|
|
@@ -29,3 +29,16 @@ $file-previewer-font-size-title: $font-size-title-1;
|
|
|
29
29
|
$file-previewer-size-audio-width: 560px;
|
|
30
30
|
$file-previewer-size-media-width: 1180px;
|
|
31
31
|
$file-previewer-size-media-height: 78vh;
|
|
32
|
+
$file-previewer-color-pdf-canvas-bg: var(string.unquote('#{$sd-cssvars-prefix}-color-bg-1'));
|
|
33
|
+
$file-previewer-color-pdf-toolbar-bg: rgb(0 0 0 / 50%);
|
|
34
|
+
$file-previewer-color-pdf-toolbar-text: var(string.unquote('#{$sd-cssvars-prefix}-color-white'));
|
|
35
|
+
$file-previewer-color-pdf-btn-disabled: var(string.unquote('#{$sd-cssvars-prefix}-color-fill-3'));
|
|
36
|
+
$file-previewer-spacing-pdf-gap: $spacing-3;
|
|
37
|
+
$file-previewer-spacing-pdf-toolbar-padding: $spacing-2;
|
|
38
|
+
$file-previewer-spacing-pdf-toolbar-gap: $spacing-3;
|
|
39
|
+
$file-previewer-radius-pdf-canvas: $radius-medium;
|
|
40
|
+
$file-previewer-radius-pdf-btn: $radius-small;
|
|
41
|
+
$file-previewer-size-pdf-btn: 28px;
|
|
42
|
+
$file-previewer-size-pdf-btn-min-width: 28px;
|
|
43
|
+
$file-previewer-font-size-pdf-btn: 16px;
|
|
44
|
+
$file-previewer-font-size-pdf-page: $font-size-body-3;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
1
2
|
import type { Except, Simplify, UnknownRecord } from 'type-fest';
|
|
2
3
|
import type { ImageProps } from '../image/interface';
|
|
3
4
|
export type FilePreviewerType = 'image' | 'video' | 'audio' | 'pdf';
|
|
@@ -12,7 +13,18 @@ export type FilePreviewerMediaProps = Simplify<UnknownRecord & {
|
|
|
12
13
|
playerProps?: UnknownRecord;
|
|
13
14
|
skinProps?: UnknownRecord;
|
|
14
15
|
}>;
|
|
15
|
-
export type
|
|
16
|
+
export type FilePreviewerPdfRotation = 0 | 90 | 180 | 270;
|
|
17
|
+
export type FilePreviewerPdfProps = Simplify<UnknownRecord & {
|
|
18
|
+
worker?: boolean;
|
|
19
|
+
workerSrc?: string;
|
|
20
|
+
workerPort?: Worker;
|
|
21
|
+
scale?: number;
|
|
22
|
+
rotation?: FilePreviewerPdfRotation;
|
|
23
|
+
page?: number;
|
|
24
|
+
documentParams?: UnknownRecord;
|
|
25
|
+
renderParams?: UnknownRecord;
|
|
26
|
+
onDocumentLoad?: (doc: PDFDocumentProxy) => void;
|
|
27
|
+
}>;
|
|
16
28
|
export interface FilePreviewerContentSlotProps {
|
|
17
29
|
src: string;
|
|
18
30
|
type: FilePreviewerType;
|
|
@@ -27,6 +39,48 @@ export interface FilePreviewerContentSlotProps {
|
|
|
27
39
|
onLoad: () => void;
|
|
28
40
|
onError: () => void;
|
|
29
41
|
}
|
|
42
|
+
export interface FilePreviewerPdfSlotProps {
|
|
43
|
+
src: string;
|
|
44
|
+
status: FilePreviewerStatus;
|
|
45
|
+
loading: boolean;
|
|
46
|
+
loaded: boolean;
|
|
47
|
+
error: boolean;
|
|
48
|
+
doc: PDFDocumentProxy | null;
|
|
49
|
+
page: number;
|
|
50
|
+
numPages: number;
|
|
51
|
+
goto: (page: number) => void;
|
|
52
|
+
prev: () => void;
|
|
53
|
+
next: () => void;
|
|
54
|
+
render: (canvas: HTMLCanvasElement, page?: number) => Promise<void>;
|
|
55
|
+
close: () => void;
|
|
56
|
+
onLoad: () => void;
|
|
57
|
+
onError: (error?: unknown) => void;
|
|
58
|
+
}
|
|
59
|
+
export interface FilePreviewerMediaSlotProps {
|
|
60
|
+
src: string;
|
|
61
|
+
status: FilePreviewerStatus;
|
|
62
|
+
loading: boolean;
|
|
63
|
+
loaded: boolean;
|
|
64
|
+
error: boolean;
|
|
65
|
+
skin: FilePreviewerMediaSkin;
|
|
66
|
+
useVideoJs: boolean;
|
|
67
|
+
playerProps: UnknownRecord;
|
|
68
|
+
skinProps: UnknownRecord;
|
|
69
|
+
close: () => void;
|
|
70
|
+
onLoad: () => void;
|
|
71
|
+
onError: (error?: unknown) => void;
|
|
72
|
+
}
|
|
73
|
+
export interface FilePreviewerImageSlotProps {
|
|
74
|
+
src: string;
|
|
75
|
+
status: FilePreviewerStatus;
|
|
76
|
+
loading: boolean;
|
|
77
|
+
loaded: boolean;
|
|
78
|
+
error: boolean;
|
|
79
|
+
imageProps: FilePreviewerImageProps;
|
|
80
|
+
close: () => void;
|
|
81
|
+
onLoad: () => void;
|
|
82
|
+
onError: (error?: unknown) => void;
|
|
83
|
+
}
|
|
30
84
|
export interface FilePreviewerProps {
|
|
31
85
|
src?: string;
|
|
32
86
|
type?: FilePreviewerType;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
2
|
+
import type { ShallowRef } from 'vue';
|
|
3
|
+
import type { FilePreviewerPdfProps, FilePreviewerStatus } from './types';
|
|
4
|
+
export interface UsePdfJsContext {
|
|
5
|
+
src: () => string;
|
|
6
|
+
pdfProps: () => FilePreviewerPdfProps | undefined;
|
|
7
|
+
onStatus: (status: FilePreviewerStatus) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface UsePdfJsReturn {
|
|
10
|
+
doc: ShallowRef<PDFDocumentProxy | null>;
|
|
11
|
+
numPages: ShallowRef<number>;
|
|
12
|
+
page: ShallowRef<number>;
|
|
13
|
+
goto: (page: number) => void;
|
|
14
|
+
prev: () => void;
|
|
15
|
+
next: () => void;
|
|
16
|
+
render: (canvas: HTMLCanvasElement, page?: number) => Promise<void>;
|
|
17
|
+
load: () => Promise<void>;
|
|
18
|
+
destroy: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function usePdfJs(context: UsePdfJsContext): UsePdfJsReturn;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { _objectSpread2 } from "../_virtual/_@oxc-project_runtime@0.133.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import { isServerRendering } from "../_utils/dom.js";
|
|
3
|
+
import { _asyncToGenerator } from "../_virtual/_@oxc-project_runtime@0.133.0/helpers/esm/asyncToGenerator.js";
|
|
4
|
+
import { shallowRef } from "vue";
|
|
5
|
+
//#region components/file-previewer/use-pdf-js.ts
|
|
6
|
+
var pdfModulePromise;
|
|
7
|
+
function loadPdfModule() {
|
|
8
|
+
if (!pdfModulePromise) pdfModulePromise = import("pdfjs-dist");
|
|
9
|
+
return pdfModulePromise;
|
|
10
|
+
}
|
|
11
|
+
var mainThreadWorkerPromise;
|
|
12
|
+
function ensureMainThreadWorker() {
|
|
13
|
+
if (!mainThreadWorkerPromise) mainThreadWorkerPromise = import("pdfjs-dist/build/pdf.worker.min.mjs").then(() => void 0);
|
|
14
|
+
return mainThreadWorkerPromise;
|
|
15
|
+
}
|
|
16
|
+
var bundledWorkerSrcPromise;
|
|
17
|
+
function defaultWorkerSrc() {
|
|
18
|
+
if (!bundledWorkerSrcPromise) bundledWorkerSrcPromise = import("./pdfjs-worker-url.js").then((module) => module.default);
|
|
19
|
+
return bundledWorkerSrcPromise;
|
|
20
|
+
}
|
|
21
|
+
function resolveWorker(_x, _x2) {
|
|
22
|
+
return _resolveWorker.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
function _resolveWorker() {
|
|
25
|
+
_resolveWorker = _asyncToGenerator(function* (props, pdfjs) {
|
|
26
|
+
if (props.worker === false) {
|
|
27
|
+
yield ensureMainThreadWorker();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (props.workerPort) {
|
|
31
|
+
pdfjs.GlobalWorkerOptions.workerPort = props.workerPort;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (props.workerSrc) {
|
|
35
|
+
pdfjs.GlobalWorkerOptions.workerSrc = props.workerSrc;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
pdfjs.GlobalWorkerOptions.workerSrc = yield defaultWorkerSrc();
|
|
39
|
+
});
|
|
40
|
+
return _resolveWorker.apply(this, arguments);
|
|
41
|
+
}
|
|
42
|
+
function isCancelledError(error) {
|
|
43
|
+
return error !== null && typeof error === "object" && "name" in error && error.name === "RenderingCancelledException";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @zh 管理 pdf.js 文档加载、分页与画布渲染的生命周期,内部按请求 id 防竞态。
|
|
47
|
+
* @en Manages the pdf.js document loading, pagination and canvas rendering lifecycle, with internal request-id based race protection.
|
|
48
|
+
*/
|
|
49
|
+
function usePdfJs(context) {
|
|
50
|
+
const doc = shallowRef(null);
|
|
51
|
+
const numPages = shallowRef(0);
|
|
52
|
+
const page = shallowRef(1);
|
|
53
|
+
let loadingTask = null;
|
|
54
|
+
let renderTask = null;
|
|
55
|
+
let activePage = null;
|
|
56
|
+
let loadId = 0;
|
|
57
|
+
function load() {
|
|
58
|
+
return _load.apply(this, arguments);
|
|
59
|
+
}
|
|
60
|
+
function _load() {
|
|
61
|
+
_load = _asyncToGenerator(function* () {
|
|
62
|
+
const url = context.src();
|
|
63
|
+
if (!url || isServerRendering) return;
|
|
64
|
+
const currentId = ++loadId;
|
|
65
|
+
context.onStatus("loading");
|
|
66
|
+
try {
|
|
67
|
+
var _context$pdfProps, _props$page, _props$onDocumentLoad;
|
|
68
|
+
const pdfjs = yield loadPdfModule();
|
|
69
|
+
if (currentId !== loadId) return;
|
|
70
|
+
const props = (_context$pdfProps = context.pdfProps()) !== null && _context$pdfProps !== void 0 ? _context$pdfProps : {};
|
|
71
|
+
yield resolveWorker(props, pdfjs);
|
|
72
|
+
yield destroy();
|
|
73
|
+
if (currentId !== loadId) return;
|
|
74
|
+
loadingTask = pdfjs.getDocument(_objectSpread2({ url }, props.documentParams));
|
|
75
|
+
const pdfDoc = yield loadingTask.promise;
|
|
76
|
+
if (currentId !== loadId) {
|
|
77
|
+
loadingTask = null;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
doc.value = pdfDoc;
|
|
81
|
+
numPages.value = pdfDoc.numPages;
|
|
82
|
+
page.value = Math.min(Math.max((_props$page = props.page) !== null && _props$page !== void 0 ? _props$page : 1, 1), pdfDoc.numPages);
|
|
83
|
+
context.onStatus("loaded");
|
|
84
|
+
(_props$onDocumentLoad = props.onDocumentLoad) === null || _props$onDocumentLoad === void 0 || _props$onDocumentLoad.call(props, pdfDoc);
|
|
85
|
+
} catch (_unused) {
|
|
86
|
+
if (currentId !== loadId) return;
|
|
87
|
+
context.onStatus("error");
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return _load.apply(this, arguments);
|
|
91
|
+
}
|
|
92
|
+
function render(_x3) {
|
|
93
|
+
return _render.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
function _render() {
|
|
96
|
+
_render = _asyncToGenerator(function* (canvas, pageNumber = page.value) {
|
|
97
|
+
var _context$pdfProps2, _props$scale, _props$rotation;
|
|
98
|
+
const pdfDoc = doc.value;
|
|
99
|
+
if (!pdfDoc) return;
|
|
100
|
+
const props = (_context$pdfProps2 = context.pdfProps()) !== null && _context$pdfProps2 !== void 0 ? _context$pdfProps2 : {};
|
|
101
|
+
const scale = (_props$scale = props.scale) !== null && _props$scale !== void 0 ? _props$scale : 1;
|
|
102
|
+
const rotation = (_props$rotation = props.rotation) !== null && _props$rotation !== void 0 ? _props$rotation : 0;
|
|
103
|
+
const target = Math.min(Math.max(pageNumber, 1), numPages.value || 1);
|
|
104
|
+
if (target !== page.value) page.value = target;
|
|
105
|
+
if (renderTask) try {
|
|
106
|
+
renderTask.cancel();
|
|
107
|
+
} catch (_unused2) {}
|
|
108
|
+
if (activePage) try {
|
|
109
|
+
activePage.cleanup();
|
|
110
|
+
} catch (_unused3) {}
|
|
111
|
+
const pdfPage = yield pdfDoc.getPage(target);
|
|
112
|
+
activePage = pdfPage;
|
|
113
|
+
const viewport = pdfPage.getViewport({
|
|
114
|
+
scale,
|
|
115
|
+
rotation
|
|
116
|
+
});
|
|
117
|
+
if (!canvas.getContext("2d")) return;
|
|
118
|
+
const dpr = window.devicePixelRatio || 1;
|
|
119
|
+
canvas.width = Math.floor(viewport.width * dpr);
|
|
120
|
+
canvas.height = Math.floor(viewport.height * dpr);
|
|
121
|
+
canvas.style.width = `${Math.floor(viewport.width)}px`;
|
|
122
|
+
canvas.style.height = `${Math.floor(viewport.height)}px`;
|
|
123
|
+
const renderParams = _objectSpread2(_objectSpread2({
|
|
124
|
+
canvas,
|
|
125
|
+
viewport
|
|
126
|
+
}, dpr !== 1 ? { transform: [
|
|
127
|
+
dpr,
|
|
128
|
+
0,
|
|
129
|
+
0,
|
|
130
|
+
dpr,
|
|
131
|
+
0,
|
|
132
|
+
0
|
|
133
|
+
] } : {}), props.renderParams);
|
|
134
|
+
const task = pdfPage.render(renderParams);
|
|
135
|
+
renderTask = task;
|
|
136
|
+
try {
|
|
137
|
+
yield task.promise;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (!isCancelledError(error)) throw error;
|
|
140
|
+
} finally {
|
|
141
|
+
if (renderTask === task) renderTask = null;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return _render.apply(this, arguments);
|
|
145
|
+
}
|
|
146
|
+
function goto(next) {
|
|
147
|
+
if (!doc.value || numPages.value === 0) return;
|
|
148
|
+
page.value = Math.min(Math.max(next, 1), numPages.value);
|
|
149
|
+
}
|
|
150
|
+
function prev() {
|
|
151
|
+
goto(page.value - 1);
|
|
152
|
+
}
|
|
153
|
+
function next() {
|
|
154
|
+
goto(page.value + 1);
|
|
155
|
+
}
|
|
156
|
+
function destroy() {
|
|
157
|
+
return _destroy.apply(this, arguments);
|
|
158
|
+
}
|
|
159
|
+
function _destroy() {
|
|
160
|
+
_destroy = _asyncToGenerator(function* () {
|
|
161
|
+
if (renderTask) {
|
|
162
|
+
try {
|
|
163
|
+
renderTask.cancel();
|
|
164
|
+
} catch (_unused4) {}
|
|
165
|
+
renderTask = null;
|
|
166
|
+
}
|
|
167
|
+
if (activePage) {
|
|
168
|
+
try {
|
|
169
|
+
activePage.cleanup();
|
|
170
|
+
} catch (_unused5) {}
|
|
171
|
+
activePage = null;
|
|
172
|
+
}
|
|
173
|
+
const task = loadingTask;
|
|
174
|
+
loadingTask = null;
|
|
175
|
+
doc.value = null;
|
|
176
|
+
numPages.value = 0;
|
|
177
|
+
page.value = 1;
|
|
178
|
+
if (task) try {
|
|
179
|
+
yield task.destroy();
|
|
180
|
+
} catch (_unused6) {}
|
|
181
|
+
});
|
|
182
|
+
return _destroy.apply(this, arguments);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
doc,
|
|
186
|
+
numPages,
|
|
187
|
+
page,
|
|
188
|
+
goto,
|
|
189
|
+
prev,
|
|
190
|
+
next,
|
|
191
|
+
render,
|
|
192
|
+
load,
|
|
193
|
+
destroy
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
export { usePdfJs };
|