@extend-ai/react-docx 0.4.0 → 0.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/dist/index.cjs +45 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -109,6 +109,7 @@ __export(index_exports, {
|
|
|
109
109
|
useDocxPagination: () => useDocxPagination,
|
|
110
110
|
useDocxParagraphStyles: () => useDocxParagraphStyles,
|
|
111
111
|
useDocxTrackChanges: () => useDocxTrackChanges,
|
|
112
|
+
useDocxViewerThumbnails: () => useDocxViewerThumbnails,
|
|
112
113
|
withPart: () => withPart
|
|
113
114
|
});
|
|
114
115
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -27006,8 +27007,15 @@ async function rasterizeDocxViewerPageSurfaceToCanvas(params) {
|
|
|
27006
27007
|
function resolveDocxPageThumbnailResolution(options) {
|
|
27007
27008
|
const safeSourceWidthPx = Math.max(1, Math.round(options.sourceWidthPx));
|
|
27008
27009
|
const safeSourceHeightPx = Math.max(1, Math.round(options.sourceHeightPx));
|
|
27009
|
-
const
|
|
27010
|
-
|
|
27010
|
+
const resolutionBounds = typeof options.resolution === "number" && Number.isFinite(options.resolution) && options.resolution > 0 ? {
|
|
27011
|
+
maxWidthPx: Number(options.resolution),
|
|
27012
|
+
maxHeightPx: Number(options.resolution)
|
|
27013
|
+
} : typeof options.resolution === "object" && options.resolution ? {
|
|
27014
|
+
maxWidthPx: Number.isFinite(options.resolution.maxWidth) && Number(options.resolution.maxWidth) > 0 ? Number(options.resolution.maxWidth) : void 0,
|
|
27015
|
+
maxHeightPx: Number.isFinite(options.resolution.maxHeight) && Number(options.resolution.maxHeight) > 0 ? Number(options.resolution.maxHeight) : void 0
|
|
27016
|
+
} : void 0;
|
|
27017
|
+
const widthBoundPx = Number.isFinite(options.maxWidthPx) ? Math.max(1, Math.round(options.maxWidthPx)) : Number.isFinite(resolutionBounds?.maxWidthPx) ? Math.max(1, Math.round(resolutionBounds?.maxWidthPx)) : 180;
|
|
27018
|
+
const heightBoundPx = Number.isFinite(options.maxHeightPx) ? Math.max(1, Math.round(options.maxHeightPx)) : Number.isFinite(resolutionBounds?.maxHeightPx) ? Math.max(1, Math.round(resolutionBounds?.maxHeightPx)) : Number.POSITIVE_INFINITY;
|
|
27011
27019
|
const scale = Math.min(
|
|
27012
27020
|
1,
|
|
27013
27021
|
widthBoundPx / safeSourceWidthPx,
|
|
@@ -27094,6 +27102,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27094
27102
|
const resolution = resolveDocxPageThumbnailResolution({
|
|
27095
27103
|
sourceWidthPx: sourceSize.widthPx,
|
|
27096
27104
|
sourceHeightPx: sourceSize.heightPx,
|
|
27105
|
+
resolution: options.resolution,
|
|
27097
27106
|
maxWidthPx: options.maxWidthPx,
|
|
27098
27107
|
maxHeightPx: options.maxHeightPx,
|
|
27099
27108
|
pixelRatio: options.pixelRatio
|
|
@@ -27124,6 +27133,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27124
27133
|
fallbackLayout.pageWidthPx,
|
|
27125
27134
|
mountedPageElements,
|
|
27126
27135
|
options.disabled,
|
|
27136
|
+
options.resolution,
|
|
27127
27137
|
options.maxHeightPx,
|
|
27128
27138
|
options.maxWidthPx,
|
|
27129
27139
|
options.pixelRatio,
|
|
@@ -27152,6 +27162,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27152
27162
|
editor.model,
|
|
27153
27163
|
mountedPageElements,
|
|
27154
27164
|
options.disabled,
|
|
27165
|
+
options.resolution,
|
|
27155
27166
|
options.maxHeightPx,
|
|
27156
27167
|
options.maxWidthPx,
|
|
27157
27168
|
options.pixelRatio,
|
|
@@ -27169,6 +27180,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27169
27180
|
const resolution = resolveDocxPageThumbnailResolution({
|
|
27170
27181
|
sourceWidthPx: sourceSize.widthPx,
|
|
27171
27182
|
sourceHeightPx: sourceSize.heightPx,
|
|
27183
|
+
resolution: options.resolution,
|
|
27172
27184
|
maxWidthPx: options.maxWidthPx,
|
|
27173
27185
|
maxHeightPx: options.maxHeightPx,
|
|
27174
27186
|
pixelRatio: options.pixelRatio
|
|
@@ -27182,6 +27194,13 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27182
27194
|
isMounted: Boolean(pageElement && pageElement.isConnected),
|
|
27183
27195
|
status: state?.status ?? (pageElement ? "idle" : "unavailable"),
|
|
27184
27196
|
error: state?.error,
|
|
27197
|
+
paint: (canvas) => {
|
|
27198
|
+
if (!canvas || options.disabled) {
|
|
27199
|
+
return false;
|
|
27200
|
+
}
|
|
27201
|
+
void renderPageThumbnailToCanvasRef.current(pageIndex, canvas);
|
|
27202
|
+
return true;
|
|
27203
|
+
},
|
|
27185
27204
|
canvasRef: canvasRefCallbacksRef.current.get(pageIndex) ?? (() => {
|
|
27186
27205
|
const nextCanvasRef = (canvas) => {
|
|
27187
27206
|
if (canvas) {
|
|
@@ -27204,6 +27223,11 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27204
27223
|
);
|
|
27205
27224
|
return nextRenderToCanvas;
|
|
27206
27225
|
})(),
|
|
27226
|
+
aspectRatio: sourceSize.widthPx / Math.max(1, sourceSize.heightPx),
|
|
27227
|
+
contentWidth: sourceSize.widthPx,
|
|
27228
|
+
contentHeight: sourceSize.heightPx,
|
|
27229
|
+
width: resolution.widthPx,
|
|
27230
|
+
height: resolution.heightPx,
|
|
27207
27231
|
...resolution
|
|
27208
27232
|
};
|
|
27209
27233
|
});
|
|
@@ -27212,19 +27236,36 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27212
27236
|
fallbackLayout.pageHeightPx,
|
|
27213
27237
|
fallbackLayout.pageWidthPx,
|
|
27214
27238
|
mountedPageElements,
|
|
27239
|
+
options.disabled,
|
|
27240
|
+
options.resolution,
|
|
27215
27241
|
options.maxHeightPx,
|
|
27216
27242
|
options.maxWidthPx,
|
|
27217
27243
|
options.pixelRatio,
|
|
27218
27244
|
pageThumbnailStates
|
|
27219
27245
|
]);
|
|
27246
|
+
const paintThumbnail = React.useCallback(
|
|
27247
|
+
(pageIndex, canvas) => {
|
|
27248
|
+
if (!canvas || options.disabled) {
|
|
27249
|
+
return false;
|
|
27250
|
+
}
|
|
27251
|
+
const thumbnail = thumbnails[pageIndex];
|
|
27252
|
+
if (!thumbnail) {
|
|
27253
|
+
return false;
|
|
27254
|
+
}
|
|
27255
|
+
return thumbnail.paint(canvas);
|
|
27256
|
+
},
|
|
27257
|
+
[options.disabled, thumbnails]
|
|
27258
|
+
);
|
|
27220
27259
|
return React.useMemo(
|
|
27221
27260
|
() => ({
|
|
27261
|
+
paintThumbnail,
|
|
27222
27262
|
thumbnails,
|
|
27223
27263
|
rerenderAttachedThumbnails
|
|
27224
27264
|
}),
|
|
27225
|
-
[rerenderAttachedThumbnails, thumbnails]
|
|
27265
|
+
[paintThumbnail, rerenderAttachedThumbnails, thumbnails]
|
|
27226
27266
|
);
|
|
27227
27267
|
}
|
|
27268
|
+
var useDocxViewerThumbnails = useDocxPageThumbnails;
|
|
27228
27269
|
function useDocxDocumentTheme(editor) {
|
|
27229
27270
|
const setDocumentTheme = React.useCallback(
|
|
27230
27271
|
(theme) => {
|
|
@@ -46132,6 +46173,7 @@ function ReactDocxViewer({
|
|
|
46132
46173
|
useDocxPagination,
|
|
46133
46174
|
useDocxParagraphStyles,
|
|
46134
46175
|
useDocxTrackChanges,
|
|
46176
|
+
useDocxViewerThumbnails,
|
|
46135
46177
|
withPart
|
|
46136
46178
|
});
|
|
46137
46179
|
//# sourceMappingURL=index.cjs.map
|