visio-react-viewer 0.2.0 → 0.3.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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VISIO_RASTER_IMAGE_LIMITS, VISIO_VISIBILITY_LIMITS, getVisioPageLayers, inspectVisioRasterImage,
|
|
1
|
+
import { VISIO_RASTER_IMAGE_LIMITS, VISIO_VISIBILITY_LIMITS, getVisioPageLayers, inspectVisioRasterImage, loadVisio, resolveVisioPageVisibility, validateVisioForeignVector } from "ooxml-core/visio";
|
|
2
2
|
import { registerControls } from "ooxml-ui/controls";
|
|
3
3
|
import { getIcon, registerIcon } from "ooxml-ui/icons";
|
|
4
4
|
import { createElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useSyncExternalStore } from "react";
|
|
@@ -272,7 +272,7 @@ function member(value, choices, label) {
|
|
|
272
272
|
}
|
|
273
273
|
/** Defensive display limits also protect callers supplying their own typed scenes. */
|
|
274
274
|
function assertViewableDocument(model) {
|
|
275
|
-
if (model.format !== "vsdx" || !Array.isArray(model.pages) || model.pages.length > 256 || !Array.isArray(model.diagnostics) || model.diagnostics.length > 2e3) throw new Error("The scene has an invalid page list.");
|
|
275
|
+
if (model.format !== "vsdx" && model.format !== "vsd" || !Array.isArray(model.pages) || model.pages.length > 256 || !Array.isArray(model.diagnostics) || model.diagnostics.length > 2e3) throw new Error("The scene has an invalid page list.");
|
|
276
276
|
const seen = /* @__PURE__ */ new Set();
|
|
277
277
|
let pathBytes = 0, textBytes = 0, runCount = 0, imageBytes = 0, geometryCount = 0, uniquePixels = 0, drawnPixels = 0, layerCount = 0, paragraphCount = 0, gradientStops = 0;
|
|
278
278
|
const imageResources = /* @__PURE__ */ new Map();
|
|
@@ -534,7 +534,7 @@ function createWorkerEditor(factory, timeoutMs = 2e4) {
|
|
|
534
534
|
if (typeof Worker === "undefined") throw new Error("Editing requires browser worker support.");
|
|
535
535
|
return new Worker(new URL(
|
|
536
536
|
/* @vite-ignore */
|
|
537
|
-
new URL("assets/edit-worker-
|
|
537
|
+
new URL("assets/edit-worker-CZbtTOr4.js", import.meta.url).href,
|
|
538
538
|
"" + import.meta.url
|
|
539
539
|
), { type: "module" });
|
|
540
540
|
});
|
|
@@ -790,9 +790,10 @@ var ViewerController = class {
|
|
|
790
790
|
#sourceGeneration = 0;
|
|
791
791
|
#searchIndex = null;
|
|
792
792
|
#history = null;
|
|
793
|
+
#sourceFormat = null;
|
|
793
794
|
#editId = 0;
|
|
794
795
|
#visible = documentVisibility(null);
|
|
795
|
-
constructor(parser =
|
|
796
|
+
constructor(parser = loadVisio, listenerError = (error) => {
|
|
796
797
|
if (typeof globalThis.reportError === "function") globalThis.reportError(error);
|
|
797
798
|
else console.error("Visio viewer listener failed:", error);
|
|
798
799
|
}, editor = createWorkerEditor()) {
|
|
@@ -832,6 +833,7 @@ var ViewerController = class {
|
|
|
832
833
|
++this.#sourceGeneration;
|
|
833
834
|
this.#invalidateEdit();
|
|
834
835
|
this.#history = null;
|
|
836
|
+
this.#sourceFormat = null;
|
|
835
837
|
this.#loadId++;
|
|
836
838
|
this.parser.cancel?.();
|
|
837
839
|
this.#searchIndex = null;
|
|
@@ -974,7 +976,7 @@ var ViewerController = class {
|
|
|
974
976
|
this.#change({
|
|
975
977
|
loading: true,
|
|
976
978
|
error: null,
|
|
977
|
-
edit: this.#
|
|
979
|
+
edit: this.#sourceEditState()
|
|
978
980
|
});
|
|
979
981
|
if (this.#destroyed || id !== this.#loadId) return;
|
|
980
982
|
let document;
|
|
@@ -985,10 +987,10 @@ var ViewerController = class {
|
|
|
985
987
|
if (this.#destroyed || id !== this.#loadId) return;
|
|
986
988
|
if (bytes.byteLength > 33554432) throw new Error("This viewer accepts files up to 32 MiB.");
|
|
987
989
|
const owned = bytes instanceof Uint8Array ? Uint8Array.from(bytes) : new Uint8Array(bytes.slice(0));
|
|
988
|
-
history = new DocumentHistory(owned);
|
|
989
990
|
document = await this.parser(Uint8Array.from(owned));
|
|
990
991
|
if (this.#destroyed || id !== this.#loadId) return;
|
|
991
992
|
assertViewableDocument(document);
|
|
993
|
+
history = new DocumentHistory(owned);
|
|
992
994
|
visible = documentVisibility(document);
|
|
993
995
|
} catch (cause) {
|
|
994
996
|
if (this.#destroyed || id !== this.#loadId) return;
|
|
@@ -1001,13 +1003,14 @@ var ViewerController = class {
|
|
|
1001
1003
|
throw error;
|
|
1002
1004
|
}
|
|
1003
1005
|
this.#history = history;
|
|
1006
|
+
this.#sourceFormat = document.format;
|
|
1004
1007
|
this.#searchIndex = null;
|
|
1005
1008
|
this.#visible = visible;
|
|
1006
1009
|
++this.#documentGeneration;
|
|
1007
1010
|
++this.#sourceGeneration;
|
|
1008
1011
|
this.#change({
|
|
1009
1012
|
document,
|
|
1010
|
-
edit: history.state,
|
|
1013
|
+
edit: document.format === "vsdx" ? history.state : EMPTY_EDIT_STATE,
|
|
1011
1014
|
pageIndex: 0,
|
|
1012
1015
|
loading: false,
|
|
1013
1016
|
error: null,
|
|
@@ -1024,7 +1027,7 @@ var ViewerController = class {
|
|
|
1024
1027
|
this.#invalidateEdit();
|
|
1025
1028
|
this.#change({
|
|
1026
1029
|
loading: false,
|
|
1027
|
-
edit: this.#
|
|
1030
|
+
edit: this.#sourceEditState()
|
|
1028
1031
|
});
|
|
1029
1032
|
}
|
|
1030
1033
|
destroy() {
|
|
@@ -1032,6 +1035,7 @@ var ViewerController = class {
|
|
|
1032
1035
|
this.#destroyed = true;
|
|
1033
1036
|
this.#invalidateEdit();
|
|
1034
1037
|
this.#history = null;
|
|
1038
|
+
this.#sourceFormat = null;
|
|
1035
1039
|
++this.#documentGeneration;
|
|
1036
1040
|
++this.#sourceGeneration;
|
|
1037
1041
|
++this.#loadId;
|
|
@@ -1076,11 +1080,11 @@ var ViewerController = class {
|
|
|
1076
1080
|
if (!this.#state.edit.busy) return;
|
|
1077
1081
|
this.#invalidateEdit();
|
|
1078
1082
|
this.parser.cancel?.();
|
|
1079
|
-
this.#change({ edit: this.#
|
|
1083
|
+
this.#change({ edit: this.#sourceEditState() });
|
|
1080
1084
|
}
|
|
1081
1085
|
exportVsdx() {
|
|
1082
1086
|
this.#assertAlive();
|
|
1083
|
-
if (!this.#history) throw new Error("Load a VSDX file before downloading a source-backed copy.");
|
|
1087
|
+
if (!this.#history || this.#sourceFormat !== "vsdx" || this.#state.document?.format !== "vsdx") throw new Error("Load a VSDX file before downloading a source-backed copy.");
|
|
1084
1088
|
if (this.#state.edit.busy || this.#state.loading) throw new Error("Wait for the current document operation before downloading.");
|
|
1085
1089
|
return this.#history.export();
|
|
1086
1090
|
}
|
|
@@ -1088,10 +1092,13 @@ var ViewerController = class {
|
|
|
1088
1092
|
++this.#editId;
|
|
1089
1093
|
this.editor.cancel?.();
|
|
1090
1094
|
}
|
|
1095
|
+
#sourceEditState() {
|
|
1096
|
+
return this.#sourceFormat === "vsdx" && this.#state.document?.format === "vsdx" ? this.#history?.state ?? EMPTY_EDIT_STATE : EMPTY_EDIT_STATE;
|
|
1097
|
+
}
|
|
1091
1098
|
async #mutate(kind, commands) {
|
|
1092
1099
|
this.#assertAlive();
|
|
1093
1100
|
const history = this.#history;
|
|
1094
|
-
if (!history) throw new Error("Load a VSDX file before editing. Model-only documents are read only.");
|
|
1101
|
+
if (!history || this.#sourceFormat !== "vsdx" || this.#state.document?.format !== "vsdx") throw new Error("Load a VSDX file before editing. Model-only documents are read only.");
|
|
1095
1102
|
if (this.#state.loading || this.#state.edit.busy) throw new Error("Another document operation is in progress.");
|
|
1096
1103
|
const target = kind === "undo" ? history.undoTarget : kind === "redo" ? history.redoTarget : void 0;
|
|
1097
1104
|
if (kind !== "edit" && !target) return;
|
|
@@ -1117,6 +1124,7 @@ var ViewerController = class {
|
|
|
1117
1124
|
} else document = await this.parser(Uint8Array.from(target.bytes));
|
|
1118
1125
|
assertCurrent();
|
|
1119
1126
|
assertViewableDocument(document);
|
|
1127
|
+
if (document.format !== "vsdx") throw new Error("A VSDX edit or history operation cannot change the source format.");
|
|
1120
1128
|
if (edited && !edited.changedParts.length) {
|
|
1121
1129
|
this.#change({ edit: history.state });
|
|
1122
1130
|
return;
|
|
@@ -1206,10 +1214,10 @@ var eventKeys = [
|
|
|
1206
1214
|
//#region src/worker-parser.ts
|
|
1207
1215
|
/** One disposable worker per document prevents old parses and long CPU tasks from occupying the UI. */
|
|
1208
1216
|
function createWorkerParser(factory, timeoutMs = 15e3) {
|
|
1209
|
-
if (!factory && typeof Worker === "undefined") return
|
|
1217
|
+
if (!factory && typeof Worker === "undefined") return loadVisio;
|
|
1210
1218
|
const create = factory ?? (() => new Worker(new URL(
|
|
1211
1219
|
/* @vite-ignore */
|
|
1212
|
-
new URL("assets/parse-worker-
|
|
1220
|
+
new URL("assets/parse-worker-BEaLqUCJ.js", import.meta.url).href,
|
|
1213
1221
|
"" + import.meta.url
|
|
1214
1222
|
), { type: "module" }));
|
|
1215
1223
|
let cancel;
|
|
@@ -4621,7 +4629,7 @@ var VisioViewerElement = class extends BaseElement {
|
|
|
4621
4629
|
empty.className = "empty";
|
|
4622
4630
|
const heading = document.createElement("strong");
|
|
4623
4631
|
heading.textContent = "Open a Visio drawing";
|
|
4624
|
-
empty.append(heading, "Open a .vsdx file to start. Files stay in this browser.");
|
|
4632
|
+
empty.append(heading, "Open a .vsdx or supported .vsd file to start. Files stay in this browser.");
|
|
4625
4633
|
this.#viewport.replaceChildren(empty);
|
|
4626
4634
|
}
|
|
4627
4635
|
const notes = compatibilityNotes(state.document?.diagnostics ?? [], this.#renderWarnings);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "visio-react-viewer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Local-first Visio viewer for react",
|
|
5
5
|
"homepage": "https://christophervr.github.io/visio-viewer/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"emf-converter": "4.8.9",
|
|
31
|
-
"ooxml-core": "^0.
|
|
32
|
-
"ooxml-ui": "^0.
|
|
33
|
-
"visio-core": "^0.2.
|
|
31
|
+
"ooxml-core": "^0.13.0",
|
|
32
|
+
"ooxml-ui": "^0.4.1",
|
|
33
|
+
"visio-core": "^0.2.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18"
|