react-docxodus-viewer 0.4.1 → 0.6.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.
@@ -4,6 +4,14 @@
4
4
  export type CommentMode = 'disabled' | 'endnote' | 'inline' | 'margin';
5
5
  export type AnnotationMode = 'disabled' | 'above' | 'inline' | 'tooltip' | 'none';
6
6
  export type ViewMode = 'document' | 'revisions';
7
+ /**
8
+ * Automatic zoom-fit mode.
9
+ * - `manual` (default): user controls zoom via the toolbar.
10
+ * - `page-width`: scale so a page's width fills the viewer.
11
+ * - `page`: scale so an entire page fits in the viewer (width and height).
12
+ * Recomputes on initial render and on viewer resize.
13
+ */
14
+ export type FitMode = 'manual' | 'page-width' | 'page';
7
15
  export interface ViewerSettings {
8
16
  /** Zoom scale (0.3 - 2.0) */
9
17
  paginationScale: number;
@@ -35,6 +43,70 @@ export interface ViewerSettings {
35
43
  commentCssClassPrefix: string;
36
44
  /** CSS class prefix for annotations */
37
45
  annotationCssClassPrefix: string;
46
+ /**
47
+ * Show placeholders for unsupported content (WMF/EMF images, math equations, form fields, etc.)
48
+ * When enabled, unsupported content displays as styled placeholders instead of being silently dropped.
49
+ */
50
+ renderUnsupportedContentPlaceholders: boolean;
51
+ /**
52
+ * Override the document's default language for the HTML lang attribute.
53
+ * If empty, the language is auto-detected from document settings.
54
+ * Examples: "en-US", "fr-FR", "de-DE", "ja-JP"
55
+ */
56
+ documentLanguage: string;
57
+ /**
58
+ * Fixed width for the page container.
59
+ * Accepts a number (pixels) or CSS length string (e.g., "80vw", "100%", "50rem").
60
+ * When set, the viewer maintains this width regardless of content or zoom level,
61
+ * providing pdf.js-like stable sizing behavior. The pages will be centered within
62
+ * this container, and the container will scroll horizontally if content exceeds it.
63
+ * Set to undefined/null for flexible sizing that adapts to content.
64
+ * @example 816 // pixels
65
+ * @example "80vw" // viewport width
66
+ * @example "100%" // percentage of parent
67
+ */
68
+ stableWidth?: number | string;
69
+ /**
70
+ * Fixed minimum height for the page container.
71
+ * Accepts a number (pixels) or CSS length string (e.g., "60vh", "500px", "100%").
72
+ * When set, the viewer reserves this much vertical space regardless of content,
73
+ * preventing layout shifts during loading. Set to undefined/null for flexible sizing.
74
+ * @example 600 // pixels
75
+ * @example "70vh" // viewport height
76
+ * @example "100%" // percentage of parent
77
+ */
78
+ stableHeight?: number | string;
79
+ }
80
+ /**
81
+ * A custom action button that can be injected into the viewer's toolbar.
82
+ * Renders as an icon button on the right side of the toolbar (before the
83
+ * settings gear), styled to match the built-in toolbar buttons.
84
+ */
85
+ export interface ToolbarAction {
86
+ /** Stable React key for this action. */
87
+ key: string;
88
+ /**
89
+ * The icon to render inside the button. Accepts any React node — an inline
90
+ * SVG, an icon-library component, an emoji, or a single character. Sized
91
+ * via the parent button (~16px).
92
+ */
93
+ icon: React.ReactNode;
94
+ /**
95
+ * Accessible label, also shown as a tooltip on hover.
96
+ */
97
+ label: string;
98
+ /** Click handler. */
99
+ onClick: () => void;
100
+ /** Disable the button. */
101
+ disabled?: boolean;
102
+ /**
103
+ * Visual variant.
104
+ * - `default`: matches existing toolbar buttons.
105
+ * - `primary`: filled accent color, useful for the main action (e.g. Download).
106
+ */
107
+ variant?: 'default' | 'primary';
108
+ /** Optional extra className appended to the button. */
109
+ className?: string;
38
110
  }
39
111
  export interface DocumentViewerProps {
40
112
  /** File to display (controlled mode) */
@@ -57,6 +129,15 @@ export interface DocumentViewerProps {
57
129
  settings?: Partial<ViewerSettings>;
58
130
  /** Default settings (used for uncontrolled mode) */
59
131
  defaultSettings?: Partial<ViewerSettings>;
132
+ /**
133
+ * Convenience shortcut for the initial zoom level (uncontrolled mode).
134
+ * Equivalent to `defaultSettings.paginationScale`. Range 0.3 – 2.0.
135
+ * Ignored if `fitMode` is set to anything other than `'manual'`,
136
+ * since the auto-fit logic will override the initial scale.
137
+ * @example 1 // 100%
138
+ * @example 0.75 // 75%
139
+ */
140
+ defaultZoom?: number;
60
141
  /** Callback when settings change */
61
142
  onSettingsChange?: (settings: ViewerSettings) => void;
62
143
  /** Additional CSS class for the root element */
@@ -71,6 +152,13 @@ export interface DocumentViewerProps {
71
152
  showRevisionsTab?: boolean;
72
153
  /** Placeholder text when no document is loaded */
73
154
  placeholder?: string;
155
+ /**
156
+ * Custom icon-button actions to render in the toolbar's right section,
157
+ * just before the settings button. Useful for hosting apps that want to
158
+ * surface document-level actions (Download, Share, Print, Open Ticket, ...)
159
+ * inside the viewer's chrome rather than awkwardly above it.
160
+ */
161
+ toolbarActions?: ToolbarAction[];
74
162
  /**
75
163
  * Base path for WASM files.
76
164
  * Leave undefined for auto-detection (recommended for most setups).
@@ -82,6 +170,27 @@ export interface DocumentViewerProps {
82
170
  * Default: true
83
171
  */
84
172
  useWorker?: boolean;
173
+ /**
174
+ * Eagerly pre-warm the docxodus comparison code path as soon as the worker
175
+ * is ready, before any user action.
176
+ *
177
+ * Creating the worker only warms the conversion runtime; the .NET WASM
178
+ * comparison assemblies stay unloaded until the first compare, which then
179
+ * pays ~3s of assembly-load latency. When `warmup` is true the viewer calls
180
+ * docxodus's `prepare()` on mount so that cost is paid up front and the first
181
+ * comparison is instant. The call is idempotent and fire-and-forget.
182
+ *
183
+ * Only applies in worker mode (`useWorker` is true, the default); it is a
184
+ * no-op when `useWorker={false}`.
185
+ * Default: false
186
+ */
187
+ warmup?: boolean;
188
+ /**
189
+ * Automatic zoom-fit mode. When set to `page-width` or `page`, the viewer
190
+ * picks a zoom level that fits the rendered page in the viewer on initial
191
+ * render and on viewer resize. Defaults to `manual` (user-controlled zoom).
192
+ */
193
+ fitMode?: FitMode;
85
194
  }
86
195
  export declare const DEFAULT_SETTINGS: ViewerSettings;
87
196
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ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AAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAEtD,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,uBAAuB;IACvB,OAAO,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpC,sCAAsC;IACtC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IAEjC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,gBAAgB,EAAE,cAkB9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-docxodus-viewer",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "A React component for viewing DOCX documents in the browser, powered by Docxodus",
5
5
  "type": "module",
6
6
  "main": "./dist/react-docxodus-viewer.cjs.js",
@@ -52,7 +52,7 @@
52
52
  "author": "",
53
53
  "license": "MIT",
54
54
  "peerDependencies": {
55
- "docxodus": ">=4.0",
55
+ "docxodus": ">=6.2",
56
56
  "react": ">=18"
57
57
  },
58
58
  "devDependencies": {
@@ -60,16 +60,16 @@
60
60
  "@testing-library/jest-dom": "^6.9.1",
61
61
  "@testing-library/react": "^16.3.0",
62
62
  "@testing-library/user-event": "^14.6.1",
63
- "@types/node": "^24.10.1",
63
+ "@types/node": "^25.0.10",
64
64
  "@types/react": "^19.2.5",
65
65
  "@types/react-dom": "^19.2.3",
66
66
  "@vitejs/plugin-react": "^5.1.1",
67
67
  "@vitest/coverage-v8": "^4.0.14",
68
- "docxodus": "^5.0.1",
68
+ "docxodus": "^6.2.0",
69
69
  "eslint": "^9.39.1",
70
70
  "eslint-plugin-react-hooks": "^7.0.1",
71
71
  "eslint-plugin-react-refresh": "^0.4.24",
72
- "globals": "^16.5.0",
72
+ "globals": "^17.1.0",
73
73
  "jsdom": "^27.2.0",
74
74
  "react": "^19.2.0",
75
75
  "react-dom": "^19.2.0",