@harbour-enterprises/superdoc 0.16.0-next.2 → 0.16.0-next.4
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/chunks/PdfViewer-BNhcpnYm.cjs +507 -0
- package/dist/chunks/PdfViewer-CoAR6Ybv.es.js +507 -0
- package/dist/chunks/{eventemitter3-CvLTPZ4N.es.js → eventemitter3-Bvb0wURT.es.js} +1 -1
- package/dist/chunks/{eventemitter3-C0c7Qr6e.cjs → eventemitter3-DboF-RUw.cjs} +1 -1
- package/dist/chunks/index-BuvJI4FJ.cjs +18531 -0
- package/dist/chunks/index-QZlZe8Ks.es.js +18516 -0
- package/dist/chunks/{jszip-BideSqMm.es.js → jszip-DXHu60h9.es.js} +1 -28
- package/dist/chunks/{jszip-C--MbQHA.cjs → jszip-DmmUnPkH.cjs} +1 -28
- package/dist/chunks/{super-editor.es-G7yRUv7F.es.js → super-editor.es-B5pURzcN.es.js} +16 -16
- package/dist/chunks/{super-editor.es-tMRSSiTE.cjs → super-editor.es-CtMEuQFA.cjs} +16 -16
- package/dist/chunks/{vue-CnsmnfIs.cjs → vue-B6WOnFdF.cjs} +192 -0
- package/dist/chunks/{vue-DoNESMR9.es.js → vue-xvq3uP6K.es.js} +226 -34
- package/dist/chunks/xml-js-A6_UhjPs.cjs +3 -0
- package/dist/chunks/xml-js-DQugfHmw.es.js +2 -0
- package/dist/components/PdfViewer/helpers/read-file.d.ts +2 -0
- package/dist/components/PdfViewer/helpers/read-file.d.ts.map +1 -0
- package/dist/components/PdfViewer/pdf/pdf-adapter.d.ts +115 -0
- package/dist/components/PdfViewer/pdf/pdf-adapter.d.ts.map +1 -0
- package/dist/core/SuperDoc.d.ts +0 -5
- package/dist/core/SuperDoc.d.ts.map +1 -1
- package/dist/style.css +1131 -773
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-B2jTl17A.js → converter-B8Js_Yus.js} +7 -6
- package/dist/super-editor/chunks/{docx-zipper-BUiuaRvW.js → docx-zipper-s_-1g9Tl.js} +8 -9
- package/dist/super-editor/chunks/{editor-TR6deHwU.js → editor-C4SsZadf.js} +3 -3
- package/dist/super-editor/chunks/{toolbar-BaxBmHby.js → toolbar-Cu290InC.js} +2 -2
- package/dist/super-editor/converter.es.js +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/src/tests/export/export-helpers/export-helpers.d.ts +1 -0
- package/dist/super-editor/super-editor.es.js +6 -6
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +2 -2
- package/dist/super-editor.es.js +2 -2
- package/dist/superdoc.cjs +10 -49519
- package/dist/superdoc.es.js +16 -49510
- package/dist/superdoc.umd.js +522 -256
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunks/__vite-browser-external-CURh0WXD.es.js +0 -8
- package/dist/chunks/__vite-browser-external-DWbQq7bv.cjs +0 -7
- package/dist/chunks/empty-lth7LH78.cjs +0 -4
- package/dist/chunks/empty-smM22Y5N.es.js +0 -4
- package/dist/chunks/index-3c22ce95.cjs +0 -29
- package/dist/chunks/index-7RshfC-Q.es.js +0 -30
- package/dist/chunks/index-BMshQyVu.cjs +0 -517
- package/dist/chunks/index-BP9eTPPY.cjs +0 -64
- package/dist/chunks/index-Bzo3pfze.es.js +0 -727
- package/dist/chunks/index-CtZm79G_.es.js +0 -65
- package/dist/chunks/index-D74YY23b.cjs +0 -726
- package/dist/chunks/index-DmNqLvaa.es.js +0 -517
- package/dist/chunks/url-B59t4K9j.es.js +0 -2606
- package/dist/chunks/url-rtFlQJRE.cjs +0 -2605
- package/dist/chunks/xml-js-Bs8Kgrmu.es.js +0 -7070
- package/dist/chunks/xml-js-CW41Ssq2.cjs +0 -7069
- package/dist/components/PdfViewer/helpers/pdfjs-worker.d.ts +0 -3
- package/dist/components/PdfViewer/helpers/pdfjs-worker.d.ts.map +0 -1
- package/dist/components/PdfViewer/pdfjs.d.ts +0 -3
- package/dist/components/PdfViewer/pdfjs.d.ts.map +0 -1
- package/dist/components/PdfViewer/worker.d.ts +0 -3
- package/dist/components/PdfViewer/worker.d.ts.map +0 -1
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("./vue-B6WOnFdF.cjs");
|
|
4
|
+
const superdoc = require("./index-BuvJI4FJ.cjs");
|
|
5
|
+
function self(vars) {
|
|
6
|
+
const {
|
|
7
|
+
opacityDisabled,
|
|
8
|
+
heightTiny,
|
|
9
|
+
heightSmall,
|
|
10
|
+
heightMedium,
|
|
11
|
+
heightLarge,
|
|
12
|
+
heightHuge,
|
|
13
|
+
primaryColor,
|
|
14
|
+
fontSize
|
|
15
|
+
} = vars;
|
|
16
|
+
return {
|
|
17
|
+
fontSize,
|
|
18
|
+
textColor: primaryColor,
|
|
19
|
+
sizeTiny: heightTiny,
|
|
20
|
+
sizeSmall: heightSmall,
|
|
21
|
+
sizeMedium: heightMedium,
|
|
22
|
+
sizeLarge: heightLarge,
|
|
23
|
+
sizeHuge: heightHuge,
|
|
24
|
+
color: primaryColor,
|
|
25
|
+
opacitySpinning: opacityDisabled
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const spinLight = {
|
|
29
|
+
common: superdoc.derived,
|
|
30
|
+
self
|
|
31
|
+
};
|
|
32
|
+
const style = superdoc.c([superdoc.c("@keyframes spin-rotate", `
|
|
33
|
+
from {
|
|
34
|
+
transform: rotate(0);
|
|
35
|
+
}
|
|
36
|
+
to {
|
|
37
|
+
transform: rotate(360deg);
|
|
38
|
+
}
|
|
39
|
+
`), superdoc.cB("spin-container", `
|
|
40
|
+
position: relative;
|
|
41
|
+
`, [superdoc.cB("spin-body", `
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 50%;
|
|
44
|
+
left: 50%;
|
|
45
|
+
transform: translateX(-50%) translateY(-50%);
|
|
46
|
+
`, [superdoc.fadeInTransition()])]), superdoc.cB("spin-body", `
|
|
47
|
+
display: inline-flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
`), superdoc.cB("spin", `
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
height: var(--n-size);
|
|
54
|
+
width: var(--n-size);
|
|
55
|
+
font-size: var(--n-size);
|
|
56
|
+
color: var(--n-color);
|
|
57
|
+
`, [superdoc.cM("rotate", `
|
|
58
|
+
animation: spin-rotate 2s linear infinite;
|
|
59
|
+
`)]), superdoc.cB("spin-description", `
|
|
60
|
+
display: inline-block;
|
|
61
|
+
font-size: var(--n-font-size);
|
|
62
|
+
color: var(--n-text-color);
|
|
63
|
+
transition: color .3s var(--n-bezier);
|
|
64
|
+
margin-top: 8px;
|
|
65
|
+
`), superdoc.cB("spin-content", `
|
|
66
|
+
opacity: 1;
|
|
67
|
+
transition: opacity .3s var(--n-bezier);
|
|
68
|
+
pointer-events: all;
|
|
69
|
+
`, [superdoc.cM("spinning", `
|
|
70
|
+
user-select: none;
|
|
71
|
+
-webkit-user-select: none;
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
opacity: var(--n-opacity-spinning);
|
|
74
|
+
`)])]);
|
|
75
|
+
const STROKE_WIDTH = {
|
|
76
|
+
small: 20,
|
|
77
|
+
medium: 18,
|
|
78
|
+
large: 16
|
|
79
|
+
};
|
|
80
|
+
const spinProps = Object.assign(Object.assign({}, superdoc.useTheme.props), {
|
|
81
|
+
contentClass: String,
|
|
82
|
+
contentStyle: [Object, String],
|
|
83
|
+
description: String,
|
|
84
|
+
stroke: String,
|
|
85
|
+
size: {
|
|
86
|
+
type: [String, Number],
|
|
87
|
+
default: "medium"
|
|
88
|
+
},
|
|
89
|
+
show: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: true
|
|
92
|
+
},
|
|
93
|
+
strokeWidth: Number,
|
|
94
|
+
rotate: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: true
|
|
97
|
+
},
|
|
98
|
+
spinning: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
validator: () => {
|
|
101
|
+
return true;
|
|
102
|
+
},
|
|
103
|
+
default: void 0
|
|
104
|
+
},
|
|
105
|
+
delay: Number
|
|
106
|
+
});
|
|
107
|
+
const NSpin = vue.defineComponent({
|
|
108
|
+
name: "Spin",
|
|
109
|
+
props: spinProps,
|
|
110
|
+
slots: Object,
|
|
111
|
+
setup(props) {
|
|
112
|
+
if (vue.process$1.env.NODE_ENV !== "production") {
|
|
113
|
+
vue.watchEffect(() => {
|
|
114
|
+
if (props.spinning !== void 0) {
|
|
115
|
+
superdoc.warnOnce("spin", "`spinning` is deprecated, please use `show` instead.");
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const {
|
|
120
|
+
mergedClsPrefixRef,
|
|
121
|
+
inlineThemeDisabled
|
|
122
|
+
} = superdoc.useConfig(props);
|
|
123
|
+
const themeRef = superdoc.useTheme("Spin", "-spin", style, spinLight, props, mergedClsPrefixRef);
|
|
124
|
+
const cssVarsRef = vue.computed(() => {
|
|
125
|
+
const {
|
|
126
|
+
size: spinSize
|
|
127
|
+
} = props;
|
|
128
|
+
const {
|
|
129
|
+
common: {
|
|
130
|
+
cubicBezierEaseInOut
|
|
131
|
+
},
|
|
132
|
+
self: self2
|
|
133
|
+
} = themeRef.value;
|
|
134
|
+
const {
|
|
135
|
+
opacitySpinning,
|
|
136
|
+
color,
|
|
137
|
+
textColor
|
|
138
|
+
} = self2;
|
|
139
|
+
const size = typeof spinSize === "number" ? superdoc.pxfy(spinSize) : self2[superdoc.createKey("size", spinSize)];
|
|
140
|
+
return {
|
|
141
|
+
"--n-bezier": cubicBezierEaseInOut,
|
|
142
|
+
"--n-opacity-spinning": opacitySpinning,
|
|
143
|
+
"--n-size": size,
|
|
144
|
+
"--n-color": color,
|
|
145
|
+
"--n-text-color": textColor
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
const themeClassHandle = inlineThemeDisabled ? superdoc.useThemeClass("spin", vue.computed(() => {
|
|
149
|
+
const {
|
|
150
|
+
size
|
|
151
|
+
} = props;
|
|
152
|
+
return typeof size === "number" ? String(size) : size[0];
|
|
153
|
+
}), cssVarsRef, props) : void 0;
|
|
154
|
+
const compitableShow = superdoc.useCompitable(props, ["spinning", "show"]);
|
|
155
|
+
const activeRef = vue.ref(false);
|
|
156
|
+
vue.watchEffect((onCleanup) => {
|
|
157
|
+
let timerId;
|
|
158
|
+
if (compitableShow.value) {
|
|
159
|
+
const {
|
|
160
|
+
delay
|
|
161
|
+
} = props;
|
|
162
|
+
if (delay) {
|
|
163
|
+
timerId = window.setTimeout(() => {
|
|
164
|
+
activeRef.value = true;
|
|
165
|
+
}, delay);
|
|
166
|
+
onCleanup(() => {
|
|
167
|
+
clearTimeout(timerId);
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
activeRef.value = compitableShow.value;
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
mergedClsPrefix: mergedClsPrefixRef,
|
|
176
|
+
active: activeRef,
|
|
177
|
+
mergedStrokeWidth: vue.computed(() => {
|
|
178
|
+
const {
|
|
179
|
+
strokeWidth
|
|
180
|
+
} = props;
|
|
181
|
+
if (strokeWidth !== void 0) return strokeWidth;
|
|
182
|
+
const {
|
|
183
|
+
size
|
|
184
|
+
} = props;
|
|
185
|
+
return STROKE_WIDTH[typeof size === "number" ? "medium" : size];
|
|
186
|
+
}),
|
|
187
|
+
cssVars: inlineThemeDisabled ? void 0 : cssVarsRef,
|
|
188
|
+
themeClass: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.themeClass,
|
|
189
|
+
onRender: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.onRender
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
render() {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
const {
|
|
195
|
+
$slots,
|
|
196
|
+
mergedClsPrefix,
|
|
197
|
+
description
|
|
198
|
+
} = this;
|
|
199
|
+
const rotate = $slots.icon && this.rotate;
|
|
200
|
+
const descriptionNode = (description || $slots.description) && vue.h("div", {
|
|
201
|
+
class: `${mergedClsPrefix}-spin-description`
|
|
202
|
+
}, description || ((_a = $slots.description) === null || _a === void 0 ? void 0 : _a.call($slots)));
|
|
203
|
+
const icon = $slots.icon ? vue.h("div", {
|
|
204
|
+
class: [`${mergedClsPrefix}-spin-body`, this.themeClass]
|
|
205
|
+
}, vue.h("div", {
|
|
206
|
+
class: [`${mergedClsPrefix}-spin`, rotate && `${mergedClsPrefix}-spin--rotate`],
|
|
207
|
+
style: $slots.default ? "" : this.cssVars
|
|
208
|
+
}, $slots.icon()), descriptionNode) : vue.h("div", {
|
|
209
|
+
class: [`${mergedClsPrefix}-spin-body`, this.themeClass]
|
|
210
|
+
}, vue.h(superdoc.NBaseLoading, {
|
|
211
|
+
clsPrefix: mergedClsPrefix,
|
|
212
|
+
style: $slots.default ? "" : this.cssVars,
|
|
213
|
+
stroke: this.stroke,
|
|
214
|
+
"stroke-width": this.mergedStrokeWidth,
|
|
215
|
+
class: `${mergedClsPrefix}-spin`
|
|
216
|
+
}), descriptionNode);
|
|
217
|
+
(_b = this.onRender) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
218
|
+
return $slots.default ? vue.h("div", {
|
|
219
|
+
class: [`${mergedClsPrefix}-spin-container`, this.themeClass],
|
|
220
|
+
style: this.cssVars
|
|
221
|
+
}, vue.h("div", {
|
|
222
|
+
class: [`${mergedClsPrefix}-spin-content`, this.active && `${mergedClsPrefix}-spin-content--spinning`, this.contentClass],
|
|
223
|
+
style: this.contentStyle
|
|
224
|
+
}, $slots), vue.h(vue.Transition, {
|
|
225
|
+
name: "fade-in-transition"
|
|
226
|
+
}, {
|
|
227
|
+
default: () => this.active ? icon : null
|
|
228
|
+
})) : icon;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const range = (start, end) => {
|
|
232
|
+
const length = end - start;
|
|
233
|
+
return Array.from({ length }, (_, i) => start + i);
|
|
234
|
+
};
|
|
235
|
+
class PDFAdapter {
|
|
236
|
+
/**
|
|
237
|
+
* @throws {Error}
|
|
238
|
+
*/
|
|
239
|
+
constructor() {
|
|
240
|
+
const proto = Object.getPrototypeOf(this);
|
|
241
|
+
if (proto.constructor === PDFAdapter) {
|
|
242
|
+
throw new Error("Abstract class should not be instanciated");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
class PDFJSAdapter extends PDFAdapter {
|
|
247
|
+
/**
|
|
248
|
+
* @param {PDFJSConfig} config
|
|
249
|
+
*/
|
|
250
|
+
constructor(config) {
|
|
251
|
+
super();
|
|
252
|
+
this.pdfLib = config.pdfLib;
|
|
253
|
+
this.pdfViewer = config.pdfViewer;
|
|
254
|
+
this.workerSrc = config.workerSrc;
|
|
255
|
+
this.textLayerMode = config.textLayerMode ?? 0;
|
|
256
|
+
if (config.setWorker) {
|
|
257
|
+
if (this.workerSrc) {
|
|
258
|
+
this.pdfLib.GlobalWorkerOptions.workerSrc = config.workerSrc;
|
|
259
|
+
} else {
|
|
260
|
+
this.pdfLib.GlobalWorkerOptions.workerSrc = getWorkerSrcFromCDN(this.pdfLib.version);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this.pdfPageViews = [];
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @param {string | ArrayBuffer | Uint8Array} file
|
|
267
|
+
* @returns {Promise<PDFDocumentProxy>}
|
|
268
|
+
*/
|
|
269
|
+
async getDocument(file) {
|
|
270
|
+
const loadingTask = this.pdfLib.getDocument(file);
|
|
271
|
+
const document2 = await loadingTask.promise;
|
|
272
|
+
return document2;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* @param {RenderPagesOptions} options
|
|
276
|
+
* @returns {Promise<void>}
|
|
277
|
+
*/
|
|
278
|
+
async renderPages({ documentId, pdfDocument, viewerContainer, emit = () => {
|
|
279
|
+
} }) {
|
|
280
|
+
try {
|
|
281
|
+
this.pdfPageViews = [];
|
|
282
|
+
const numPages = pdfDocument.numPages;
|
|
283
|
+
const firstPage = 1;
|
|
284
|
+
const pdfjsPages = await getPdfjsPages(pdfDocument, firstPage, numPages);
|
|
285
|
+
const pageContainers = [];
|
|
286
|
+
for (const [index, page] of pdfjsPages.entries()) {
|
|
287
|
+
const container = document.createElement("div");
|
|
288
|
+
container.classList.add("pdf-page");
|
|
289
|
+
container.dataset.pageNumber = (index + 1).toString();
|
|
290
|
+
container.id = `${documentId}-page-${index + 1}`;
|
|
291
|
+
pageContainers.push(container);
|
|
292
|
+
const { width, height } = this.getOriginalPageSize(page);
|
|
293
|
+
const scale = 1;
|
|
294
|
+
const eventBus = new this.pdfViewer.EventBus();
|
|
295
|
+
const pdfPageView = new this.pdfViewer.PDFPageView({
|
|
296
|
+
container,
|
|
297
|
+
id: index + 1,
|
|
298
|
+
scale,
|
|
299
|
+
defaultViewport: page.getViewport({ scale }),
|
|
300
|
+
eventBus,
|
|
301
|
+
textLayerMode: this.textLayerMode
|
|
302
|
+
});
|
|
303
|
+
this.pdfPageViews.push(pdfPageView);
|
|
304
|
+
const containerBounds = container.getBoundingClientRect();
|
|
305
|
+
containerBounds.originalWidth = width;
|
|
306
|
+
containerBounds.originalHeight = height;
|
|
307
|
+
pdfPageView.setPdfPage(page);
|
|
308
|
+
await pdfPageView.draw();
|
|
309
|
+
emit("page-loaded", documentId, index, containerBounds);
|
|
310
|
+
}
|
|
311
|
+
viewerContainer.append(...pageContainers);
|
|
312
|
+
emit("ready", documentId, viewerContainer);
|
|
313
|
+
} catch (err) {
|
|
314
|
+
console.error("Error loading PDF:", err);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @param {PDFPageProxy} page
|
|
319
|
+
* @returns {object}
|
|
320
|
+
*/
|
|
321
|
+
getOriginalPageSize(page) {
|
|
322
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
323
|
+
const width = viewport.width;
|
|
324
|
+
const height = viewport.height;
|
|
325
|
+
return { width, height };
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* @return {void}
|
|
329
|
+
*/
|
|
330
|
+
destroy() {
|
|
331
|
+
this.pdfPageViews.forEach((view) => view.destroy());
|
|
332
|
+
this.pdfPageViews = [];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
class PDFAdapterFactory {
|
|
336
|
+
/**
|
|
337
|
+
* @param {PDFJSConfig & {adapter: AdapterType}} config
|
|
338
|
+
* @returns {PDFAdapter}
|
|
339
|
+
* @throws {Error}
|
|
340
|
+
*/
|
|
341
|
+
static create(config) {
|
|
342
|
+
const adapters = {
|
|
343
|
+
pdfjs: () => {
|
|
344
|
+
return new PDFJSAdapter(config);
|
|
345
|
+
},
|
|
346
|
+
default: () => {
|
|
347
|
+
throw new Error("Unsupported adapter");
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const adapter = adapters[config.adapter] ?? adapters.default;
|
|
351
|
+
return adapter();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const createPDFConfig = (config) => {
|
|
355
|
+
const defaultConfig = {
|
|
356
|
+
adapter: "pdfjs"
|
|
357
|
+
};
|
|
358
|
+
return {
|
|
359
|
+
...defaultConfig,
|
|
360
|
+
...config
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
async function getPdfjsPages(pdf, firstPage, lastPage) {
|
|
364
|
+
const pagesPromises = range(firstPage, lastPage + 1).map((num) => pdf.getPage(num));
|
|
365
|
+
return await Promise.all(pagesPromises);
|
|
366
|
+
}
|
|
367
|
+
function getWorkerSrcFromCDN(version) {
|
|
368
|
+
return `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${version}/pdf.worker.min.mjs`;
|
|
369
|
+
}
|
|
370
|
+
const readFileAsArrayBuffer = (blob) => {
|
|
371
|
+
return new Promise((resolve, reject) => {
|
|
372
|
+
const reader = new FileReader();
|
|
373
|
+
reader.onload = (event) => resolve(event.target.result);
|
|
374
|
+
reader.onerror = reject;
|
|
375
|
+
reader.readAsDataURL(blob);
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
const _hoisted_1 = {
|
|
379
|
+
key: 0,
|
|
380
|
+
class: "superdoc-pdf-viewer__loader"
|
|
381
|
+
};
|
|
382
|
+
const _sfc_main = {
|
|
383
|
+
__name: "PdfViewer",
|
|
384
|
+
props: {
|
|
385
|
+
documentData: {
|
|
386
|
+
type: Object,
|
|
387
|
+
required: true
|
|
388
|
+
},
|
|
389
|
+
config: {
|
|
390
|
+
type: Object,
|
|
391
|
+
required: true
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
emits: ["page-loaded", "ready", "selection-change", "bypass-selection"],
|
|
395
|
+
setup(__props, { emit: __emit }) {
|
|
396
|
+
const emit = __emit;
|
|
397
|
+
const props = __props;
|
|
398
|
+
const superdocStore = superdoc.useSuperdocStore();
|
|
399
|
+
const { activeZoom } = superdoc.storeToRefs(superdocStore);
|
|
400
|
+
const viewer = vue.ref(null);
|
|
401
|
+
const isReady = vue.ref(false);
|
|
402
|
+
const id = props.documentData.id;
|
|
403
|
+
const pdfData = props.documentData.data;
|
|
404
|
+
const pdfConfig = createPDFConfig({
|
|
405
|
+
pdfLib: props.config.pdfLib,
|
|
406
|
+
pdfViewer: props.config.pdfViewer,
|
|
407
|
+
workerSrc: props.config.workerSrc,
|
|
408
|
+
setWorker: props.config.setWorker,
|
|
409
|
+
textLayerMode: props.config.textLayerMode
|
|
410
|
+
});
|
|
411
|
+
const pdfAdapter = PDFAdapterFactory.create(pdfConfig);
|
|
412
|
+
const loadPDF = async (file) => {
|
|
413
|
+
try {
|
|
414
|
+
const result = await readFileAsArrayBuffer(file);
|
|
415
|
+
const document2 = await pdfAdapter.getDocument(result);
|
|
416
|
+
await pdfAdapter.renderPages({
|
|
417
|
+
documentId: id,
|
|
418
|
+
pdfDocument: document2,
|
|
419
|
+
viewerContainer: viewer.value,
|
|
420
|
+
emit
|
|
421
|
+
});
|
|
422
|
+
isReady.value = true;
|
|
423
|
+
} catch {
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
function getSelectedTextBoundingBox(container) {
|
|
427
|
+
const selection = window.getSelection();
|
|
428
|
+
if (selection.rangeCount === 0) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
const range2 = selection.getRangeAt(0);
|
|
432
|
+
const boundingRects = range2.getClientRects();
|
|
433
|
+
if (boundingRects.length === 0) {
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
const firstRect = boundingRects[0];
|
|
437
|
+
let boundingBox = {
|
|
438
|
+
top: firstRect.top,
|
|
439
|
+
left: firstRect.left,
|
|
440
|
+
bottom: firstRect.bottom,
|
|
441
|
+
right: firstRect.right
|
|
442
|
+
};
|
|
443
|
+
for (let i = 1; i < boundingRects.length; i++) {
|
|
444
|
+
const rect = boundingRects[i];
|
|
445
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
boundingBox.top = Math.min(boundingBox.top, rect.top);
|
|
449
|
+
boundingBox.left = Math.min(boundingBox.left, rect.left);
|
|
450
|
+
boundingBox.bottom = Math.max(boundingBox.bottom, rect.bottom);
|
|
451
|
+
boundingBox.right = Math.max(boundingBox.right, rect.right);
|
|
452
|
+
}
|
|
453
|
+
const containerRect = container.getBoundingClientRect();
|
|
454
|
+
viewer.value.getBoundingClientRect();
|
|
455
|
+
boundingBox.top = (boundingBox.top - containerRect.top) / (activeZoom.value / 100) + container.scrollTop;
|
|
456
|
+
boundingBox.left = (boundingBox.left - containerRect.left) / (activeZoom.value / 100) + container.scrollLeft;
|
|
457
|
+
boundingBox.bottom = (boundingBox.bottom - containerRect.top) / (activeZoom.value / 100) + container.scrollTop;
|
|
458
|
+
boundingBox.right = (boundingBox.right - containerRect.left) / (activeZoom.value / 100) + container.scrollLeft;
|
|
459
|
+
return boundingBox;
|
|
460
|
+
}
|
|
461
|
+
const handlePdfClick = (e) => {
|
|
462
|
+
const { target } = e;
|
|
463
|
+
if (target.tagName !== "SPAN") {
|
|
464
|
+
emit("bypass-selection", e);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
const handleMouseUp = (e) => {
|
|
468
|
+
const selection = window.getSelection();
|
|
469
|
+
if (selection.toString().length > 0) {
|
|
470
|
+
const selectionBounds = getSelectedTextBoundingBox(viewer.value);
|
|
471
|
+
const sel = superdoc.useSelection({
|
|
472
|
+
selectionBounds,
|
|
473
|
+
documentId: id
|
|
474
|
+
});
|
|
475
|
+
emit("selection-change", sel);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
vue.onMounted(async () => {
|
|
479
|
+
await loadPDF(pdfData);
|
|
480
|
+
});
|
|
481
|
+
vue.onUnmounted(() => {
|
|
482
|
+
pdfAdapter.destroy();
|
|
483
|
+
});
|
|
484
|
+
return (_ctx, _cache) => {
|
|
485
|
+
return vue.openBlock(), vue.createElementBlock("div", {
|
|
486
|
+
class: "superdoc-pdf-viewer-container",
|
|
487
|
+
onMousedown: handlePdfClick,
|
|
488
|
+
onMouseup: handleMouseUp
|
|
489
|
+
}, [
|
|
490
|
+
vue.createBaseVNode("div", {
|
|
491
|
+
class: "superdoc-pdf-viewer",
|
|
492
|
+
ref_key: "viewer",
|
|
493
|
+
ref: viewer,
|
|
494
|
+
id: "viewerId"
|
|
495
|
+
}, null, 512),
|
|
496
|
+
!isReady.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
|
|
497
|
+
vue.createVNode(vue.unref(NSpin), {
|
|
498
|
+
class: "superdoc-pdf-viewer__spin",
|
|
499
|
+
size: "large"
|
|
500
|
+
})
|
|
501
|
+
])) : vue.createCommentVNode("", true)
|
|
502
|
+
], 32);
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const PdfViewer = /* @__PURE__ */ superdoc._export_sfc(_sfc_main, [["__scopeId", "data-v-84719682"]]);
|
|
507
|
+
exports.default = PdfViewer;
|