superdoc 2.4.0-next.9 → 2.5.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/README.md +12 -90
- package/dist/chunks/{FindReplaceSurface-9VkPw_-X.cjs → FindReplaceSurface-0p7EtMZh.cjs} +4 -3
- package/dist/chunks/{FindReplaceSurface-BuvaIrQ5.es.js → FindReplaceSurface-40AnrqWk.es.js} +4 -2
- package/dist/chunks/{PasswordPromptSurface-Bu5xHm91.cjs → PasswordPromptSurface-31lYPcCK.cjs} +4 -3
- package/dist/chunks/{PasswordPromptSurface-Bz9_sKhX.es.js → PasswordPromptSurface-CwYeO3iQ.es.js} +4 -2
- package/dist/chunks/{PdfViewer-CdVGB6Fe.es.js → PdfViewer-D8h7LRZy.es.js} +103 -19
- package/dist/chunks/{PdfViewer-D4eD2dV1.cjs → PdfViewer-Dug6yDRC.cjs} +105 -20
- package/dist/chunks/_plugin-vue_export-helper-BOaGB7Aw.es.js +8 -0
- package/dist/chunks/_plugin-vue_export-helper-SDR04tiH.cjs +13 -0
- package/dist/chunks/{blank-docx-DP8RUPW-.cjs → blank-docx-BuFAbRjs.cjs} +2 -0
- package/dist/chunks/{blank-docx-XRX6Ker2.es.js → blank-docx-DzQccOlW.es.js} +2 -0
- package/dist/chunks/constants-B6VBlmKp.es.js +4 -0
- package/dist/chunks/constants-DpXuDx_g.cjs +9 -0
- package/dist/chunks/{create-super-doc-ui-ByvmsAAG.cjs → create-super-doc-ui-Bom7oDPv.cjs} +2027 -1158
- package/dist/chunks/{create-super-doc-ui-DBXOhHdW.es.js → create-super-doc-ui-DbzVC0rr.es.js} +2216 -1107
- package/dist/chunks/{eventemitter3-Bt2s0X0a.es.js → eventemitter3-CMOjDs74.es.js} +124 -16
- package/dist/chunks/{eventemitter3-DqY4aSMf.cjs → eventemitter3-D38u8ta_.cjs} +125 -16
- package/dist/chunks/jszip-RC64TPzL.cjs +4758 -0
- package/dist/chunks/jszip-VxCFV9YS.es.js +4717 -0
- package/dist/chunks/{rolldown-runtime-D7PMmH3s.es.js → rolldown-runtime-B5TtN50X.es.js} +13 -4
- package/dist/chunks/{rolldown-runtime-1Y-nnZJ3.cjs → rolldown-runtime-DtsSbkrh.cjs} +12 -3
- package/dist/chunks/{uuid-CFp0WGVU.cjs → uuid-BhG0ngwk.cjs} +10 -6
- package/dist/chunks/{uuid-B2Sqk-3p.es.js → uuid-H0Xcmmhy.es.js} +8 -3
- package/dist/collaboration-upgrade-engine.cjs +34 -9
- package/dist/collaboration-upgrade-engine.es.js +30 -5
- package/dist/document-api/src/citations/citations.types.d.ts +9 -0
- package/dist/document-api/src/comments/comments.types.d.ts +7 -0
- package/dist/document-api/src/types/receipt.d.ts +9 -5
- package/dist/document-api/src/types/track-changes.types.d.ts +17 -0
- package/dist/layout-engine/contracts/src/graphic-placement.d.ts +35 -6
- package/dist/layout-engine/contracts/src/incremental-dependency.d.ts +22 -2
- package/dist/layout-engine/contracts/src/index.d.ts +370 -15
- package/dist/layout-engine/contracts/src/inline-box.d.ts +19 -0
- package/dist/layout-engine/contracts/src/paragraph-visible-text.d.ts +19 -0
- package/dist/layout-engine/contracts/src/resolved-layout.d.ts +5 -0
- package/dist/layout-engine/dom-contract/src/class-names.d.ts +2 -0
- package/dist/layout-engine/layout-bridge/src/footnote-scorer.d.ts +1 -1
- package/dist/layout-engine/layout-bridge/src/hydrateTableTextboxMeasures.d.ts +9 -0
- package/dist/layout-engine/layout-bridge/src/incrementalLayout.d.ts +42 -11
- package/dist/layout-engine/layout-bridge/src/index.d.ts +4 -2
- package/dist/layout-engine/layout-bridge/src/inline-box-key.d.ts +3 -0
- package/dist/layout-engine/layout-bridge/src/layoutHeaderFooter.d.ts +11 -4
- package/dist/layout-engine/layout-bridge/src/remeasure.d.ts +2 -2
- package/dist/layout-engine/layout-bridge/src/run-visual-marks.d.ts +2 -0
- package/dist/layout-engine/layout-bridge/src/text-measurement.d.ts +0 -12
- package/dist/layout-engine/layout-engine/src/anchors.d.ts +4 -0
- package/dist/layout-engine/layout-engine/src/execution.d.ts +21 -0
- package/dist/layout-engine/layout-engine/src/floating-objects.d.ts +15 -2
- package/dist/layout-engine/layout-engine/src/floating-table-anchor.d.ts +2 -0
- package/dist/layout-engine/layout-engine/src/footnote-anchor-index.d.ts +17 -0
- package/dist/layout-engine/layout-engine/src/index.d.ts +13 -10
- package/dist/layout-engine/layout-engine/src/inline-drawing-alignment.d.ts +9 -0
- package/dist/layout-engine/layout-engine/src/layout-drawing.d.ts +3 -3
- package/dist/layout-engine/layout-engine/src/layout-paragraph.d.ts +2 -2
- package/dist/layout-engine/layout-engine/src/layout-textbox.d.ts +3 -3
- package/dist/layout-engine/layout-engine/src/pageNumbering.d.ts +3 -41
- package/dist/layout-engine/layout-engine/src/paginator.d.ts +7 -2
- package/dist/layout-engine/layout-engine/src/resolvePageTokens.d.ts +2 -0
- package/dist/layout-engine/layout-engine/src/section-breaks.d.ts +1 -0
- package/dist/layout-engine/layout-engine/src/section-props.d.ts +5 -0
- package/dist/layout-engine/painters/dom/src/chart-renderer.d.ts +3 -3
- package/dist/layout-engine/painters/dom/src/images/image-outline.d.ts +7 -0
- package/dist/layout-engine/painters/dom/src/images/render-placeholder.d.ts +12 -0
- package/dist/layout-engine/painters/dom/src/renderer.d.ts +54 -0
- package/dist/layout-engine/painters/dom/src/runs/inline-box.d.ts +8 -0
- package/dist/layout-engine/painters/dom/src/runs/text-effects.d.ts +30 -0
- package/dist/layout-engine/painters/dom/src/runs/text-run.d.ts +6 -4
- package/dist/layout-engine/painters/dom/src/shapes/preset-text-warp-data.d.ts +32 -0
- package/dist/layout-engine/painters/dom/src/shapes/wordart-warp.d.ts +39 -0
- package/dist/layout-engine/painters/dom/src/table/border-utils.d.ts +20 -27
- package/dist/layout-engine/painters/dom/src/table/renderTableFragment.d.ts +1 -1
- package/dist/layout-engine/style-engine/src/ooxml/word-style-model/parse-theme.d.ts +7 -0
- package/dist/public/ui-react.cjs +66 -2
- package/dist/public/ui-react.es.js +66 -1
- package/dist/public/ui.cjs +1 -1
- package/dist/public/ui.es.js +1 -1
- package/dist/style.css +134 -98
- package/dist/style.layered.css +134 -98
- package/dist/superdoc/src/components/CommentsLayer/CommentDialog.vue.d.ts +2 -0
- package/dist/superdoc/src/components/CommentsLayer/commentsList/ReviewDirectoryListItem.vue.d.ts +16 -0
- package/dist/superdoc/src/components/CommentsLayer/commentsList/commentsList.vue.d.ts +3 -1
- package/dist/superdoc/src/components/CommentsLayer/commentsList/super-comments-list.d.ts +12 -0
- package/dist/superdoc/src/core/SuperDoc.d.ts +10 -7
- package/dist/superdoc/src/core/config/normalize-ui-config.d.ts +5 -0
- package/dist/superdoc/src/core/extensions/index.d.ts +1 -1
- package/dist/superdoc/src/core/extensions/types.d.ts +63 -5
- package/dist/superdoc/src/core/types/index.d.ts +423 -37
- package/dist/superdoc/src/core/v2-integration/v2-integration.d.ts +3 -3
- package/dist/superdoc/src/helpers/comment-small-screen.d.ts +10 -0
- package/dist/superdoc/src/helpers/v2-review-mutation-impact.d.ts +3 -5
- package/dist/superdoc/src/internal/toolbar/built-in/ToolbarButton.vue.d.ts +4 -4
- package/dist/superdoc/src/internal/toolbar/built-in-toolbar.d.ts +11 -0
- package/dist/superdoc/src/internal/toolbar/compatibility-catalog.d.ts +1 -1
- package/dist/superdoc/src/public/index.d.cts +20 -0
- package/dist/superdoc/src/public/index.d.ts +10 -0
- package/dist/superdoc/src/public/ui/types.d.ts +5 -5
- package/dist/superdoc/src/stores/comments-store.d.ts +81 -78
- package/dist/superdoc/src/stores/superdoc-store.d.ts +243 -234
- package/dist/superdoc.cjs +6748 -2162
- package/dist/superdoc.es.js +6621 -2035
- package/dist-cdn/style.layered.css +1 -1
- package/dist-cdn/superdoc.min.css +1 -1
- package/dist-cdn/superdoc.min.js +37 -37
- package/package.json +14 -18
- package/AGENTS.md +0 -337
- package/dist/chunks/_plugin-vue_export-helper-CZ1Nl59K.cjs +0 -11
- package/dist/chunks/_plugin-vue_export-helper-DSMAhhwD.es.js +0 -6
- package/dist/chunks/constants-BfH0br5u.es.js +0 -3
- package/dist/chunks/constants-D7TNtyJd.cjs +0 -14
- package/dist/chunks/jszip-C8srOKAO.es.js +0 -4650
- package/dist/chunks/jszip-Cs9JBLlJ.cjs +0 -4691
- package/dist/superdoc/src/helpers/v2-remote-review-hydration.d.ts +0 -12
- package/dist/superdoc/src/helpers/v2-review-mutation-reconciler.d.ts +0 -19
package/README.md
CHANGED
|
@@ -1,106 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# superdoc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser editor for opening, editing, and rendering DOCX files.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://www.gnu.org/licenses/agpl-3.0)
|
|
7
|
-
[](https://www.npmjs.com/package/superdoc)
|
|
8
|
-
[](https://codecov.io/gh/superdoc/docx-editor)
|
|
9
|
-
[](https://discord.com/invite/b9UuaZRyaB)
|
|
10
|
-
|
|
11
|
-
SuperDoc renders and edits DOCX files in the browser. Built on OOXML — not bolted onto HTML. As you type, you write directly to the XML. Import a document, edit it, export it. Nothing lost.
|
|
12
|
-
|
|
13
|
-
## Features
|
|
14
|
-
|
|
15
|
-
- **Real DOCX, not rich text** — Built on OOXML. Real pagination, section breaks, headers/footers, complex tables. Not a contenteditable wrapper with export bolted on.
|
|
16
|
-
- **Self-hosted** — Runs entirely in the browser. Your documents never leave your servers.
|
|
17
|
-
- **Any framework** — React, Vue, Angular, Svelte, vanilla JS. One component, zero lock-in.
|
|
18
|
-
- **Real-time collaboration** — Yjs-based CRDT. Multiplayer editing with comments, tracked changes, and automatic conflict resolution.
|
|
19
|
-
- **Built for agents** — [SDK](https://www.npmjs.com/package/@superdoc-dev/sdk), [CLI](https://www.npmjs.com/package/@superdoc-dev/cli), and [MCP server](https://www.npmjs.com/package/@superdoc-dev/mcp) let LLMs read, edit, and save .docx files programmatically.
|
|
20
|
-
- **Dual licensed** — AGPLv3 for community use. [Commercial license](https://www.superdocportal.dev/get-in-touch) for proprietary deployments.
|
|
21
|
-
|
|
22
|
-
## Quick start
|
|
5
|
+
## Install
|
|
23
6
|
|
|
24
7
|
```bash
|
|
25
8
|
npm install superdoc
|
|
26
9
|
```
|
|
27
10
|
|
|
28
|
-
|
|
29
|
-
import 'superdoc/style.css';
|
|
30
|
-
import { SuperDoc } from 'superdoc';
|
|
31
|
-
|
|
32
|
-
const superdoc = new SuperDoc({
|
|
33
|
-
selector: '#superdoc',
|
|
34
|
-
documentMode: 'editing',
|
|
35
|
-
documents: [
|
|
36
|
-
{
|
|
37
|
-
id: 'my-doc-id',
|
|
38
|
-
type: 'docx',
|
|
39
|
-
data: fileObject,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Supported document modes are `editing`, `viewing`, and `suggesting`. Do not use `edit`, `view`, or `suggest`.
|
|
46
|
-
|
|
47
|
-
### Browser Document API contract
|
|
48
|
-
|
|
49
|
-
`superdoc.activeEditor.doc` is the browser-facing v2 Document API facade. In the
|
|
50
|
-
browser it is intentionally async-capable, so custom UI code must tolerate
|
|
51
|
-
promise-returning reads and writes, including the default worker-backed runtime.
|
|
52
|
-
SDK/headless document-automation surfaces remain synchronous; this async
|
|
53
|
-
contract is specific to the browser `superdoc` package.
|
|
54
|
-
|
|
55
|
-
### Vanilla wrapper for a DOCX file
|
|
56
|
-
|
|
57
|
-
When an agent needs to create a small vanilla JS wrapper around a DOCX `File`, use this shape:
|
|
11
|
+
## Quick start
|
|
58
12
|
|
|
59
|
-
```
|
|
13
|
+
```js
|
|
60
14
|
import { SuperDoc } from 'superdoc';
|
|
61
15
|
import 'superdoc/style.css';
|
|
62
16
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
documents: [
|
|
68
|
-
{
|
|
69
|
-
id: 'contract',
|
|
70
|
-
type: 'docx',
|
|
71
|
-
data: file,
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
For React, Vue, and other frameworks, see the [documentation](https://docs.superdoc.dev).
|
|
79
|
-
|
|
80
|
-
### Using an AI coding agent?
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
claude mcp add superdoc -- npx @superdoc-dev/mcp # connect agent to DOCX files
|
|
17
|
+
const editor = new SuperDoc({
|
|
18
|
+
selector: '#editor',
|
|
19
|
+
document: '/document.docx',
|
|
20
|
+
});
|
|
84
21
|
```
|
|
85
22
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[docs.superdoc.dev](https://docs.superdoc.dev) — installation, integration guides, collaboration setup, API reference, and more.
|
|
89
|
-
|
|
90
|
-
## Contributing
|
|
91
|
-
|
|
92
|
-
Check the [issue tracker](https://github.com/superdoc/docx-editor/issues) for open issues, or read the [Contributing Guide](../../CONTRIBUTING.md) to get started. Bug reports with reproduction .docx files are especially valuable.
|
|
93
|
-
|
|
94
|
-
## Community
|
|
95
|
-
|
|
96
|
-
- [Discord](https://discord.com/invite/b9UuaZRyaB) — Chat with the team and other contributors
|
|
97
|
-
- [Email](mailto:q@superdoc.dev) — Reach the team directly
|
|
23
|
+
See the [editor quick start](https://docs.superdoc.dev/editor/quickstart) for a complete example and the
|
|
24
|
+
[SuperDoc documentation](https://docs.superdoc.dev) for configuration and APIs.
|
|
98
25
|
|
|
99
26
|
## License
|
|
100
27
|
|
|
101
|
-
-
|
|
102
|
-
- Commercial: [Enterprise License](https://www.superdocportal.dev/get-in-touch)
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
Created and maintained by [Harbour](https://www.superdoc.dev) and the SuperDoc community.
|
|
28
|
+
AGPL-3.0. Commercial licenses are available from [SuperDoc](https://www.superdoc.dev).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require__plugin_vue_export_helper = require("./_plugin-vue_export-helper-CZ1Nl59K.cjs");
|
|
1
|
+
const require__plugin_vue_export_helper = require("./_plugin-vue_export-helper-SDR04tiH.cjs");
|
|
3
2
|
let vue = require("vue");
|
|
3
|
+
//#region src/components/surfaces/FindReplaceSurface.vue
|
|
4
4
|
var _hoisted_1 = ["onKeydown"];
|
|
5
5
|
var _hoisted_2 = { class: "sd-find-replace__row" };
|
|
6
6
|
var _hoisted_3 = [
|
|
@@ -341,5 +341,6 @@ var _sfc_main = {
|
|
|
341
341
|
};
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
|
-
var FindReplaceSurface_default =
|
|
344
|
+
var FindReplaceSurface_default = /*#__PURE__*/ require__plugin_vue_export_helper._plugin_vue_export_helper_default(_sfc_main, [["__scopeId", "data-v-41f37c29"]]);
|
|
345
|
+
//#endregion
|
|
345
346
|
exports.default = FindReplaceSurface_default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BOaGB7Aw.es.js";
|
|
2
2
|
import { computed, createCommentVNode, createElementBlock, createElementVNode, normalizeClass, onMounted, openBlock, ref, toDisplayString, withKeys, withModifiers } from "vue";
|
|
3
|
+
//#region src/components/surfaces/FindReplaceSurface.vue
|
|
3
4
|
var _hoisted_1 = ["onKeydown"];
|
|
4
5
|
var _hoisted_2 = { class: "sd-find-replace__row" };
|
|
5
6
|
var _hoisted_3 = [
|
|
@@ -67,7 +68,7 @@ var _hoisted_20 = {
|
|
|
67
68
|
"aria-hidden": "true"
|
|
68
69
|
};
|
|
69
70
|
var _hoisted_21 = { class: "sd-find-replace__error-text" };
|
|
70
|
-
var FindReplaceSurface_default =
|
|
71
|
+
var FindReplaceSurface_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
|
|
71
72
|
__name: "FindReplaceSurface",
|
|
72
73
|
props: {
|
|
73
74
|
surfaceId: {
|
|
@@ -340,4 +341,5 @@ var FindReplaceSurface_default = /* @__PURE__ */ __plugin_vue_export_helper_defa
|
|
|
340
341
|
};
|
|
341
342
|
}
|
|
342
343
|
}, [["__scopeId", "data-v-41f37c29"]]);
|
|
344
|
+
//#endregion
|
|
343
345
|
export { FindReplaceSurface_default as default };
|
package/dist/chunks/{PasswordPromptSurface-Bu5xHm91.cjs → PasswordPromptSurface-31lYPcCK.cjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require__plugin_vue_export_helper = require("./_plugin-vue_export-helper-CZ1Nl59K.cjs");
|
|
1
|
+
const require__plugin_vue_export_helper = require("./_plugin-vue_export-helper-SDR04tiH.cjs");
|
|
3
2
|
let vue = require("vue");
|
|
3
|
+
//#region src/components/surfaces/PasswordPromptSurface.vue
|
|
4
4
|
var _hoisted_1 = ["onKeydown"];
|
|
5
5
|
var _hoisted_2 = ["id"];
|
|
6
6
|
var _hoisted_3 = { class: "sd-password-prompt__description" };
|
|
@@ -109,5 +109,6 @@ var _sfc_main = {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
-
var PasswordPromptSurface_default =
|
|
112
|
+
var PasswordPromptSurface_default = /*#__PURE__*/ require__plugin_vue_export_helper._plugin_vue_export_helper_default(_sfc_main, [["__scopeId", "data-v-ecf7f6fb"]]);
|
|
113
|
+
//#endregion
|
|
113
114
|
exports.default = PasswordPromptSurface_default;
|
package/dist/chunks/{PasswordPromptSurface-Bz9_sKhX.es.js → PasswordPromptSurface-CwYeO3iQ.es.js}
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BOaGB7Aw.es.js";
|
|
2
2
|
import { computed, createCommentVNode, createElementBlock, createElementVNode, openBlock, ref, toDisplayString, vModelText, withDirectives, withKeys, withModifiers } from "vue";
|
|
3
|
+
//#region src/components/surfaces/PasswordPromptSurface.vue
|
|
3
4
|
var _hoisted_1 = ["onKeydown"];
|
|
4
5
|
var _hoisted_2 = ["id"];
|
|
5
6
|
var _hoisted_3 = { class: "sd-password-prompt__description" };
|
|
@@ -17,7 +18,7 @@ var _hoisted_6 = {
|
|
|
17
18
|
var _hoisted_7 = { class: "sd-password-prompt__actions" };
|
|
18
19
|
var _hoisted_8 = ["disabled"];
|
|
19
20
|
var _hoisted_9 = ["disabled"];
|
|
20
|
-
var PasswordPromptSurface_default =
|
|
21
|
+
var PasswordPromptSurface_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
|
|
21
22
|
__name: "PasswordPromptSurface",
|
|
22
23
|
props: {
|
|
23
24
|
surfaceId: {
|
|
@@ -108,4 +109,5 @@ var PasswordPromptSurface_default = /* @__PURE__ */ __plugin_vue_export_helper_d
|
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
}, [["__scopeId", "data-v-ecf7f6fb"]]);
|
|
112
|
+
//#endregion
|
|
111
113
|
export { PasswordPromptSurface_default as default };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BOaGB7Aw.es.js";
|
|
2
|
+
import { t as PDF_TO_CSS_UNITS } from "./constants-B6VBlmKp.es.js";
|
|
3
3
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, markRaw, mergeProps, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, renderList, shallowRef, watch } from "vue";
|
|
4
|
-
|
|
4
|
+
//#region src/core/pdf/helpers/floor.js
|
|
5
|
+
var floor = (val, precision) => {
|
|
5
6
|
const multiplier = 10 ** (precision || 0);
|
|
6
7
|
return Math.floor(val * multiplier) / multiplier;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/core/pdf/helpers/read-file.js
|
|
11
|
+
var readFileAsArrayBuffer = (blob) => {
|
|
9
12
|
return new Promise((resolve, reject) => {
|
|
10
13
|
const reader = new FileReader();
|
|
11
14
|
reader.onload = (event) => resolve(event.target.result);
|
|
@@ -13,22 +16,71 @@ const readFileAsArrayBuffer = (blob) => {
|
|
|
13
16
|
reader.readAsDataURL(blob);
|
|
14
17
|
});
|
|
15
18
|
};
|
|
16
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/core/pdf/helpers/range.js
|
|
21
|
+
var range = (start, end) => {
|
|
17
22
|
const length = end - start;
|
|
18
23
|
return Array.from({ length }, (_, i) => start + i);
|
|
19
24
|
};
|
|
20
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/pdf/pdf-adapter.js
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {import('pdfjs-dist').PDFDocumentProxy} PDFDocumentProxy
|
|
29
|
+
* @typedef {import('pdfjs-dist').PDFPageProxy} PDFPageProxy
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {'pdfjs'} AdapterType
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} PDFConfig
|
|
36
|
+
* @property {AdapterType} adapter
|
|
37
|
+
* @property {any} [pdfLib]
|
|
38
|
+
* @property {string} [workerSrc]
|
|
39
|
+
* @property {boolean} [setWorker]
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {Object} PDFJSConfig
|
|
43
|
+
* @property {any} pdfLib
|
|
44
|
+
* @property {string} [workerSrc]
|
|
45
|
+
* @property {boolean} [setWorker]
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {Object} RenderPagesOptions
|
|
49
|
+
* @property {string} documentId
|
|
50
|
+
* @property {PDFDocumentProxy} pdfDocument
|
|
51
|
+
* @property {HTMLElement} viewerContainer
|
|
52
|
+
* @property {function(string, ...any): void} [emit]
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {Object} PageSize
|
|
56
|
+
* @property {number} width
|
|
57
|
+
* @property {number} height
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* @param {Partial<PDFConfig>} [config]
|
|
61
|
+
* @returns {PDFConfig}
|
|
62
|
+
*/
|
|
63
|
+
var createPDFConfig = (config) => {
|
|
21
64
|
return {
|
|
22
65
|
adapter: "pdfjs",
|
|
23
66
|
...config
|
|
24
67
|
};
|
|
25
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* @abstract
|
|
71
|
+
*/
|
|
26
72
|
var PDFAdapter = class PDFAdapter {
|
|
73
|
+
/**
|
|
74
|
+
* @throws {Error}
|
|
75
|
+
*/
|
|
27
76
|
constructor() {
|
|
28
77
|
if (Object.getPrototypeOf(this).constructor === PDFAdapter) throw new Error("Abstract class should not be instantiated");
|
|
29
78
|
}
|
|
30
79
|
};
|
|
31
80
|
var PDFJSAdapter = class extends PDFAdapter {
|
|
81
|
+
/**
|
|
82
|
+
* @param {PDFJSConfig} config
|
|
83
|
+
*/
|
|
32
84
|
constructor(config) {
|
|
33
85
|
super();
|
|
34
86
|
this.pdfLib = config.pdfLib;
|
|
@@ -36,15 +88,30 @@ var PDFJSAdapter = class extends PDFAdapter {
|
|
|
36
88
|
if (config.setWorker) if (this.workerSrc) this.pdfLib.GlobalWorkerOptions.workerSrc = config.workerSrc;
|
|
37
89
|
else this.pdfLib.GlobalWorkerOptions.workerSrc = getWorkerSrcFromCDN(this.pdfLib.version);
|
|
38
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* @param {string | ArrayBuffer | Uint8Array} file
|
|
93
|
+
* @returns {Promise<PDFDocumentProxy>}
|
|
94
|
+
*/
|
|
39
95
|
async getDocument(file) {
|
|
40
96
|
return await this.pdfLib.getDocument(file).promise;
|
|
41
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* @param {PDFDocumentProxy} pdf
|
|
100
|
+
* @param {number} firstPage
|
|
101
|
+
* @param {number} lastPage
|
|
102
|
+
* @returns {Promise<PDFPageProxy[]>}
|
|
103
|
+
*/
|
|
42
104
|
async getPages(pdf, firstPage, lastPage) {
|
|
43
105
|
const pagesPromises = range(firstPage, lastPage + 1).map((num) => pdf.getPage(num));
|
|
44
106
|
return await Promise.all(pagesPromises);
|
|
45
107
|
}
|
|
46
108
|
};
|
|
47
109
|
var PDFAdapterFactory = class {
|
|
110
|
+
/**
|
|
111
|
+
* @param {PDFJSConfig & {adapter: AdapterType}} config
|
|
112
|
+
* @returns {PDFAdapter}
|
|
113
|
+
* @throws {Error}
|
|
114
|
+
*/
|
|
48
115
|
static create(config) {
|
|
49
116
|
const adapters = {
|
|
50
117
|
pdfjs: () => {
|
|
@@ -57,12 +124,18 @@ var PDFAdapterFactory = class {
|
|
|
57
124
|
return (adapters[config.adapter] ?? adapters.default)();
|
|
58
125
|
}
|
|
59
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* @param {number} version
|
|
129
|
+
* @returns {string}
|
|
130
|
+
*/
|
|
60
131
|
function getWorkerSrcFromCDN(version) {
|
|
61
132
|
return `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${version}/pdf.worker.min.mjs`;
|
|
62
133
|
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/components/PdfViewer/PdfViewerPage.vue
|
|
63
136
|
var _hoisted_1$1 = ["data-page-id", "data-page-number"];
|
|
64
137
|
var _hoisted_2 = { class: "sd-pdf-viewer-page__canvas-wrapper" };
|
|
65
|
-
var PdfViewerPage_default =
|
|
138
|
+
var PdfViewerPage_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
|
|
66
139
|
__name: "PdfViewerPage",
|
|
67
140
|
props: {
|
|
68
141
|
config: {
|
|
@@ -161,9 +234,8 @@ var PdfViewerPage_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
161
234
|
});
|
|
162
235
|
const pageStyle = computed(() => {
|
|
163
236
|
const { width: widthPt, height: heightPt } = getPagePtSize();
|
|
164
|
-
const scaleFactor = getScaleFactor();
|
|
165
237
|
return {
|
|
166
|
-
"--scale-factor": `${
|
|
238
|
+
"--scale-factor": `${getScaleFactor()}`,
|
|
167
239
|
width: `calc(var(--scale-factor) * ${widthPt}px)`,
|
|
168
240
|
height: `calc(var(--scale-factor) * ${heightPt}px)`
|
|
169
241
|
};
|
|
@@ -224,7 +296,7 @@ var PdfViewerPage_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
224
296
|
await renderTask.promise;
|
|
225
297
|
const size = getPageSize();
|
|
226
298
|
const originalPt = getPagePtSize();
|
|
227
|
-
|
|
299
|
+
const payload = {
|
|
228
300
|
page: props.page,
|
|
229
301
|
documentId: props.page.documentId,
|
|
230
302
|
pageIndex: pageIdx.value,
|
|
@@ -233,7 +305,8 @@ var PdfViewerPage_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
233
305
|
height: size.height,
|
|
234
306
|
originalWidth: originalPt.width * PDF_TO_CSS_UNITS,
|
|
235
307
|
originalHeight: originalPt.height * PDF_TO_CSS_UNITS
|
|
236
|
-
}
|
|
308
|
+
};
|
|
309
|
+
emit("page-rendered", payload);
|
|
237
310
|
} catch (e) {
|
|
238
311
|
destroyRenderTask();
|
|
239
312
|
emit("page-error", props.page);
|
|
@@ -306,7 +379,7 @@ var PdfViewerPage_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
306
379
|
};
|
|
307
380
|
}
|
|
308
381
|
}, [["__scopeId", "data-v-d7a9857d"]]);
|
|
309
|
-
var PdfViewerDocument_default =
|
|
382
|
+
var PdfViewerDocument_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
|
|
310
383
|
__name: "PdfViewerDocument",
|
|
311
384
|
props: {
|
|
312
385
|
config: {
|
|
@@ -376,8 +449,10 @@ var PdfViewerDocument_default = /* @__PURE__ */ __plugin_vue_export_helper_defau
|
|
|
376
449
|
};
|
|
377
450
|
}
|
|
378
451
|
}, [["__scopeId", "data-v-2152178b"]]);
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/components/PdfViewer/PdfViewer.vue
|
|
379
454
|
var _hoisted_1 = { class: "sd-pdf-viewer__main" };
|
|
380
|
-
var PdfViewer_default =
|
|
455
|
+
var PdfViewer_default = /*#__PURE__*/ _plugin_vue_export_helper_default({
|
|
381
456
|
__name: "PdfViewer",
|
|
382
457
|
props: {
|
|
383
458
|
config: {
|
|
@@ -389,6 +464,11 @@ var PdfViewer_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
389
464
|
required: true
|
|
390
465
|
},
|
|
391
466
|
fileId: { type: String },
|
|
467
|
+
/**
|
|
468
|
+
* Zoom scale to render the first paint at (1 = 100%). The host seeds
|
|
469
|
+
* this from `config.zoom.initial` so a PDF never flashes 100% before
|
|
470
|
+
* a watcher catches up; later changes still arrive via updateScale().
|
|
471
|
+
*/
|
|
392
472
|
initialScale: {
|
|
393
473
|
type: Number,
|
|
394
474
|
default: 1
|
|
@@ -447,16 +527,19 @@ var PdfViewer_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
447
527
|
renderedPages.value = 0;
|
|
448
528
|
}
|
|
449
529
|
function updateScale(nextScale) {
|
|
450
|
-
|
|
530
|
+
const roundedScale = floor(nextScale, 2);
|
|
531
|
+
scale.value = roundedScale;
|
|
451
532
|
}
|
|
452
533
|
__expose({ updateScale });
|
|
453
534
|
async function getDocument(file) {
|
|
454
535
|
if (!file) return;
|
|
455
536
|
try {
|
|
456
537
|
const result = await readFileAsArrayBuffer(file);
|
|
538
|
+
const documentId = props.fileId || generateDocumentId("document");
|
|
539
|
+
const pdfjsDocument = await pdfAdapter.getDocument(result);
|
|
457
540
|
pdf.value = {
|
|
458
|
-
documentId
|
|
459
|
-
pdfjsDocument: markRaw(
|
|
541
|
+
documentId,
|
|
542
|
+
pdfjsDocument: markRaw(pdfjsDocument)
|
|
460
543
|
};
|
|
461
544
|
emit("document-loaded", file);
|
|
462
545
|
} catch (e) {
|
|
@@ -480,9 +563,9 @@ var PdfViewer_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
480
563
|
pdfjsPage: markRaw(pdfjsPage)
|
|
481
564
|
};
|
|
482
565
|
};
|
|
483
|
-
const pages
|
|
484
|
-
updatePages(pages
|
|
485
|
-
emit("pages-loaded", pages
|
|
566
|
+
const pages = pdfjsPages.map(mapPages);
|
|
567
|
+
updatePages(pages);
|
|
568
|
+
emit("pages-loaded", pages);
|
|
486
569
|
} catch (e) {
|
|
487
570
|
emit("document-error", e);
|
|
488
571
|
console.error(e);
|
|
@@ -528,4 +611,5 @@ var PdfViewer_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
|
|
|
528
611
|
};
|
|
529
612
|
}
|
|
530
613
|
}, [["__scopeId", "data-v-05c9d9b5"]]);
|
|
614
|
+
//#endregion
|
|
531
615
|
export { PdfViewer_default as default };
|