@extend-ai/react-docx 0.3.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 +50 -81
- 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 +49 -81
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
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);
|
|
@@ -6611,7 +6612,6 @@ function resolveDocumentLayout(model) {
|
|
|
6611
6612
|
}
|
|
6612
6613
|
|
|
6613
6614
|
// src/image-render.ts
|
|
6614
|
-
var import_emf_converter = require("emf-converter");
|
|
6615
6615
|
var import_fast_png = require("fast-png");
|
|
6616
6616
|
var import_utif = __toESM(require("utif"), 1);
|
|
6617
6617
|
var TIFF_CONTENT_TYPES = /* @__PURE__ */ new Set(["image/tiff", "image/tif"]);
|
|
@@ -6626,9 +6626,6 @@ var EMF_DATA_URI_PREFIXES = ["data:image/emf", "data:image/x-emf"];
|
|
|
6626
6626
|
var WMF_DATA_URI_PREFIXES = ["data:image/wmf", "data:image/x-wmf"];
|
|
6627
6627
|
var UTIF = import_utif.default;
|
|
6628
6628
|
var convertedTiffSrcCache = /* @__PURE__ */ new Map();
|
|
6629
|
-
var convertedMetafileSrcCache = /* @__PURE__ */ new Map();
|
|
6630
|
-
var pendingMetafileConversions = /* @__PURE__ */ new Map();
|
|
6631
|
-
var renderableImageSourceListeners = /* @__PURE__ */ new Set();
|
|
6632
6629
|
function normalizeImageContentType(image) {
|
|
6633
6630
|
return image.contentType?.trim().toLowerCase();
|
|
6634
6631
|
}
|
|
@@ -6669,45 +6666,15 @@ function imageUsesWmfContent(image) {
|
|
|
6669
6666
|
const src = normalizeImageSrc(image)?.toLowerCase();
|
|
6670
6667
|
return Boolean(src && WMF_DATA_URI_PREFIXES.some((prefix) => src.startsWith(prefix)));
|
|
6671
6668
|
}
|
|
6672
|
-
function metafileCacheKey(image) {
|
|
6673
|
-
const src = normalizeImageSrc(image);
|
|
6674
|
-
if (src) {
|
|
6675
|
-
return src;
|
|
6676
|
-
}
|
|
6677
|
-
const bytes = image.data;
|
|
6678
|
-
if (!bytes?.byteLength) {
|
|
6679
|
-
return void 0;
|
|
6680
|
-
}
|
|
6681
|
-
const base64 = bytesToBase642(bytes);
|
|
6682
|
-
const contentType = normalizeImageContentType(image) ?? "application/octet-stream";
|
|
6683
|
-
return base64 ? `data:${contentType};base64,${base64}` : void 0;
|
|
6684
|
-
}
|
|
6685
|
-
function notifyRenderableImageSourceListeners() {
|
|
6686
|
-
renderableImageSourceListeners.forEach((listener) => {
|
|
6687
|
-
try {
|
|
6688
|
-
listener();
|
|
6689
|
-
} catch {
|
|
6690
|
-
}
|
|
6691
|
-
});
|
|
6692
|
-
}
|
|
6693
6669
|
function imageUsesPlaceholderFallback(image) {
|
|
6694
|
-
|
|
6695
|
-
if (!contentType || !PLACEHOLDER_FALLBACK_CONTENT_TYPES.has(contentType)) {
|
|
6696
|
-
return false;
|
|
6697
|
-
}
|
|
6698
|
-
const cacheKey = metafileCacheKey(image);
|
|
6699
|
-
if (!cacheKey) {
|
|
6700
|
-
return true;
|
|
6701
|
-
}
|
|
6702
|
-
return convertedMetafileSrcCache.get(cacheKey) == null;
|
|
6670
|
+
return imageHasMetafileContent(image);
|
|
6703
6671
|
}
|
|
6704
6672
|
function unsupportedImageFallbackLabel(image, widthPx, heightPx) {
|
|
6705
6673
|
const isSmallIcon = (widthPx ?? 0) <= 56 && (heightPx ?? 0) <= 56;
|
|
6706
|
-
|
|
6707
|
-
if (contentType === "image/x-emf" || contentType === "image/emf") {
|
|
6674
|
+
if (imageUsesEmfContent(image)) {
|
|
6708
6675
|
return isSmallIcon ? "e" : "EMF";
|
|
6709
6676
|
}
|
|
6710
|
-
if (
|
|
6677
|
+
if (imageUsesWmfContent(image)) {
|
|
6711
6678
|
return isSmallIcon ? "w" : "WMF";
|
|
6712
6679
|
}
|
|
6713
6680
|
return isSmallIcon ? "e" : "TIFF";
|
|
@@ -6753,13 +6720,6 @@ function toArrayBuffer(bytes) {
|
|
|
6753
6720
|
}
|
|
6754
6721
|
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
6755
6722
|
}
|
|
6756
|
-
function toStrictArrayBuffer(bytes) {
|
|
6757
|
-
const arrayBuffer = toArrayBuffer(bytes);
|
|
6758
|
-
if (arrayBuffer instanceof ArrayBuffer) {
|
|
6759
|
-
return arrayBuffer;
|
|
6760
|
-
}
|
|
6761
|
-
return Uint8Array.from(bytes).buffer;
|
|
6762
|
-
}
|
|
6763
6723
|
function resolveTiffBytes(image) {
|
|
6764
6724
|
if (image.data?.byteLength) {
|
|
6765
6725
|
return image.data;
|
|
@@ -6821,37 +6781,6 @@ function resolveRenderableImageSource(image) {
|
|
|
6821
6781
|
return void 0;
|
|
6822
6782
|
}
|
|
6823
6783
|
if (imageHasMetafileContent(image)) {
|
|
6824
|
-
const cacheKey = metafileCacheKey(image);
|
|
6825
|
-
if (!cacheKey) {
|
|
6826
|
-
return void 0;
|
|
6827
|
-
}
|
|
6828
|
-
if (convertedMetafileSrcCache.has(cacheKey)) {
|
|
6829
|
-
return convertedMetafileSrcCache.get(cacheKey) ?? void 0;
|
|
6830
|
-
}
|
|
6831
|
-
if (!pendingMetafileConversions.has(cacheKey)) {
|
|
6832
|
-
const bytes = resolveTiffBytes(image);
|
|
6833
|
-
if (bytes) {
|
|
6834
|
-
const conversionPromise = (async () => {
|
|
6835
|
-
try {
|
|
6836
|
-
const arrayBuffer = toStrictArrayBuffer(bytes);
|
|
6837
|
-
const converted2 = imageUsesEmfContent(image) ? await (0, import_emf_converter.convertEmfToDataUrl)(arrayBuffer, void 0, void 0, { dpiScale: 1 }) : imageUsesWmfContent(image) ? await (0, import_emf_converter.convertWmfToDataUrl)(arrayBuffer, void 0, void 0, { dpiScale: 1 }) : null;
|
|
6838
|
-
const normalized = converted2 ?? void 0;
|
|
6839
|
-
convertedMetafileSrcCache.set(cacheKey, normalized ?? null);
|
|
6840
|
-
notifyRenderableImageSourceListeners();
|
|
6841
|
-
return normalized;
|
|
6842
|
-
} catch {
|
|
6843
|
-
convertedMetafileSrcCache.set(cacheKey, null);
|
|
6844
|
-
notifyRenderableImageSourceListeners();
|
|
6845
|
-
return void 0;
|
|
6846
|
-
} finally {
|
|
6847
|
-
pendingMetafileConversions.delete(cacheKey);
|
|
6848
|
-
}
|
|
6849
|
-
})();
|
|
6850
|
-
pendingMetafileConversions.set(cacheKey, conversionPromise);
|
|
6851
|
-
} else {
|
|
6852
|
-
convertedMetafileSrcCache.set(cacheKey, null);
|
|
6853
|
-
}
|
|
6854
|
-
}
|
|
6855
6784
|
return void 0;
|
|
6856
6785
|
}
|
|
6857
6786
|
if (!imageHasTiffContent(image)) {
|
|
@@ -6874,9 +6803,8 @@ function resolveRenderableImageSource(image) {
|
|
|
6874
6803
|
return converted;
|
|
6875
6804
|
}
|
|
6876
6805
|
function subscribeRenderableImageSourceUpdates(listener) {
|
|
6877
|
-
|
|
6806
|
+
void listener;
|
|
6878
6807
|
return () => {
|
|
6879
|
-
renderableImageSourceListeners.delete(listener);
|
|
6880
6808
|
};
|
|
6881
6809
|
}
|
|
6882
6810
|
|
|
@@ -10654,7 +10582,7 @@ var DOC_SURFACE_STYLE_BY_THEME = {
|
|
|
10654
10582
|
boxShadow: "0 2px 10px rgba(2, 6, 23, 0.55), 0 1px 2px rgba(2, 6, 23, 0.45)"
|
|
10655
10583
|
}
|
|
10656
10584
|
};
|
|
10657
|
-
var NIGHT_READER_INVERSION_FILTER = "invert(
|
|
10585
|
+
var NIGHT_READER_INVERSION_FILTER = "invert(0.95) hue-rotate(180deg) saturate(0.9) brightness(0.9) contrast(0.94)";
|
|
10658
10586
|
function appendCssFilters(...filters) {
|
|
10659
10587
|
const resolvedFilters = filters.map((filter) => filter?.trim()).filter((filter) => Boolean(filter));
|
|
10660
10588
|
return resolvedFilters.length > 0 ? resolvedFilters.join(" ") : void 0;
|
|
@@ -27079,8 +27007,15 @@ async function rasterizeDocxViewerPageSurfaceToCanvas(params) {
|
|
|
27079
27007
|
function resolveDocxPageThumbnailResolution(options) {
|
|
27080
27008
|
const safeSourceWidthPx = Math.max(1, Math.round(options.sourceWidthPx));
|
|
27081
27009
|
const safeSourceHeightPx = Math.max(1, Math.round(options.sourceHeightPx));
|
|
27082
|
-
const
|
|
27083
|
-
|
|
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;
|
|
27084
27019
|
const scale = Math.min(
|
|
27085
27020
|
1,
|
|
27086
27021
|
widthBoundPx / safeSourceWidthPx,
|
|
@@ -27167,6 +27102,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27167
27102
|
const resolution = resolveDocxPageThumbnailResolution({
|
|
27168
27103
|
sourceWidthPx: sourceSize.widthPx,
|
|
27169
27104
|
sourceHeightPx: sourceSize.heightPx,
|
|
27105
|
+
resolution: options.resolution,
|
|
27170
27106
|
maxWidthPx: options.maxWidthPx,
|
|
27171
27107
|
maxHeightPx: options.maxHeightPx,
|
|
27172
27108
|
pixelRatio: options.pixelRatio
|
|
@@ -27197,6 +27133,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27197
27133
|
fallbackLayout.pageWidthPx,
|
|
27198
27134
|
mountedPageElements,
|
|
27199
27135
|
options.disabled,
|
|
27136
|
+
options.resolution,
|
|
27200
27137
|
options.maxHeightPx,
|
|
27201
27138
|
options.maxWidthPx,
|
|
27202
27139
|
options.pixelRatio,
|
|
@@ -27225,6 +27162,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27225
27162
|
editor.model,
|
|
27226
27163
|
mountedPageElements,
|
|
27227
27164
|
options.disabled,
|
|
27165
|
+
options.resolution,
|
|
27228
27166
|
options.maxHeightPx,
|
|
27229
27167
|
options.maxWidthPx,
|
|
27230
27168
|
options.pixelRatio,
|
|
@@ -27242,6 +27180,7 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27242
27180
|
const resolution = resolveDocxPageThumbnailResolution({
|
|
27243
27181
|
sourceWidthPx: sourceSize.widthPx,
|
|
27244
27182
|
sourceHeightPx: sourceSize.heightPx,
|
|
27183
|
+
resolution: options.resolution,
|
|
27245
27184
|
maxWidthPx: options.maxWidthPx,
|
|
27246
27185
|
maxHeightPx: options.maxHeightPx,
|
|
27247
27186
|
pixelRatio: options.pixelRatio
|
|
@@ -27255,6 +27194,13 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27255
27194
|
isMounted: Boolean(pageElement && pageElement.isConnected),
|
|
27256
27195
|
status: state?.status ?? (pageElement ? "idle" : "unavailable"),
|
|
27257
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
|
+
},
|
|
27258
27204
|
canvasRef: canvasRefCallbacksRef.current.get(pageIndex) ?? (() => {
|
|
27259
27205
|
const nextCanvasRef = (canvas) => {
|
|
27260
27206
|
if (canvas) {
|
|
@@ -27277,6 +27223,11 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27277
27223
|
);
|
|
27278
27224
|
return nextRenderToCanvas;
|
|
27279
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,
|
|
27280
27231
|
...resolution
|
|
27281
27232
|
};
|
|
27282
27233
|
});
|
|
@@ -27285,19 +27236,36 @@ function useDocxPageThumbnails(editor, options = {}) {
|
|
|
27285
27236
|
fallbackLayout.pageHeightPx,
|
|
27286
27237
|
fallbackLayout.pageWidthPx,
|
|
27287
27238
|
mountedPageElements,
|
|
27239
|
+
options.disabled,
|
|
27240
|
+
options.resolution,
|
|
27288
27241
|
options.maxHeightPx,
|
|
27289
27242
|
options.maxWidthPx,
|
|
27290
27243
|
options.pixelRatio,
|
|
27291
27244
|
pageThumbnailStates
|
|
27292
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
|
+
);
|
|
27293
27259
|
return React.useMemo(
|
|
27294
27260
|
() => ({
|
|
27261
|
+
paintThumbnail,
|
|
27295
27262
|
thumbnails,
|
|
27296
27263
|
rerenderAttachedThumbnails
|
|
27297
27264
|
}),
|
|
27298
|
-
[rerenderAttachedThumbnails, thumbnails]
|
|
27265
|
+
[paintThumbnail, rerenderAttachedThumbnails, thumbnails]
|
|
27299
27266
|
);
|
|
27300
27267
|
}
|
|
27268
|
+
var useDocxViewerThumbnails = useDocxPageThumbnails;
|
|
27301
27269
|
function useDocxDocumentTheme(editor) {
|
|
27302
27270
|
const setDocumentTheme = React.useCallback(
|
|
27303
27271
|
(theme) => {
|
|
@@ -46205,6 +46173,7 @@ function ReactDocxViewer({
|
|
|
46205
46173
|
useDocxPagination,
|
|
46206
46174
|
useDocxParagraphStyles,
|
|
46207
46175
|
useDocxTrackChanges,
|
|
46176
|
+
useDocxViewerThumbnails,
|
|
46208
46177
|
withPart
|
|
46209
46178
|
});
|
|
46210
46179
|
//# sourceMappingURL=index.cjs.map
|