visio-react-viewer 0.0.1 → 0.1.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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +5 -3
- package/dist/assets/edit-worker-DRgXgRud.js +55992 -0
- package/dist/assets/parse-worker-B8EBQQpD.js +53971 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4131 -0
- package/dist/types/packages/bindings/src/common.d.ts +29 -0
- package/dist/types/packages/bindings/src/react.d.ts +10 -0
- package/dist/types/packages/react/src/index.d.ts +3 -0
- package/dist/types/src/arrowheads.d.ts +3 -0
- package/dist/types/src/binding.d.ts +27 -0
- package/dist/types/src/contract.d.ts +32 -0
- package/dist/types/src/controller.d.ts +66 -0
- package/dist/types/src/demo-document.d.ts +3 -0
- package/dist/types/src/diagnostics.d.ts +9 -0
- package/dist/types/src/document-history.d.ts +42 -0
- package/dist/types/src/document-text-search.d.ts +44 -0
- package/dist/types/src/edit-commands.d.ts +3 -0
- package/dist/types/src/edit-error.d.ts +4 -0
- package/dist/types/src/edit-worker.d.ts +1 -0
- package/dist/types/src/export-svg.d.ts +25 -0
- package/dist/types/src/foreign-vector-budget.d.ts +24 -0
- package/dist/types/src/index.d.ts +14 -0
- package/dist/types/src/paragraph-layout.d.ts +18 -0
- package/dist/types/src/parse-worker.d.ts +1 -0
- package/dist/types/src/print-snapshot.d.ts +87 -0
- package/dist/types/src/render-fill.d.ts +2 -0
- package/dist/types/src/render-foreign-vector-shape.d.ts +4 -0
- package/dist/types/src/render-foreign-vector.d.ts +3 -0
- package/dist/types/src/render-image.d.ts +4 -0
- package/dist/types/src/render-resources.d.ts +10 -0
- package/dist/types/src/render-svg.d.ts +17 -0
- package/dist/types/src/render-text.d.ts +4 -0
- package/dist/types/src/scene-details.d.ts +7 -0
- package/dist/types/src/scene-validation.d.ts +4 -0
- package/dist/types/src/shape-inspector.d.ts +5 -0
- package/dist/types/src/snapshot-scene.d.ts +8 -0
- package/dist/types/src/styles.d.ts +2 -0
- package/dist/types/src/text-layout.d.ts +45 -0
- package/dist/types/src/viewer-chrome.d.ts +10 -0
- package/dist/types/src/viewer-edit-controls.d.ts +12 -0
- package/dist/types/src/viewer-element.d.ts +44 -0
- package/dist/types/src/viewer-geometry-controls.d.ts +14 -0
- package/dist/types/src/viewer-input.d.ts +10 -0
- package/dist/types/src/viewer-layer-controls.d.ts +5 -0
- package/dist/types/src/viewer-layers.d.ts +22 -0
- package/dist/types/src/viewer-search.d.ts +10 -0
- package/dist/types/src/worker-editor.d.ts +23 -0
- package/dist/types/src/worker-parser.d.ts +13 -0
- package/package.json +22 -7
- package/index.js +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { VisioTextRun } from 'ooxml-core/visio';
|
|
2
|
+
export interface TextLine {
|
|
3
|
+
runs: VisioTextRun[];
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export type MeasureText = (text: string, run: VisioTextRun) => number;
|
|
8
|
+
export interface TextLayoutLimits {
|
|
9
|
+
maxCharacters: number;
|
|
10
|
+
maxMeasurements: number;
|
|
11
|
+
maxLines: number;
|
|
12
|
+
maxFragments: number;
|
|
13
|
+
maxShapeCharacters: number;
|
|
14
|
+
maxShapeMeasurements: number;
|
|
15
|
+
maxShapeLines: number;
|
|
16
|
+
maxShapeFragments: number;
|
|
17
|
+
maxCacheEntries: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class TextLayoutBudgetError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/** One bounded measurement cache and work budget per render; shape scopes share both. */
|
|
23
|
+
export declare class TextLayoutBudget {
|
|
24
|
+
#private;
|
|
25
|
+
readonly limits: Readonly<TextLayoutLimits>;
|
|
26
|
+
private readonly cache;
|
|
27
|
+
private readonly parent?;
|
|
28
|
+
private constructor();
|
|
29
|
+
static create(options?: Partial<TextLayoutLimits>): TextLayoutBudget;
|
|
30
|
+
get characters(): number;
|
|
31
|
+
get measurements(): number;
|
|
32
|
+
get lines(): number;
|
|
33
|
+
get fragments(): number;
|
|
34
|
+
/** A shape may be omitted without consuming the rest of the page's budget. */
|
|
35
|
+
forShape(): TextLayoutBudget;
|
|
36
|
+
reserveCharacters(count: number): void;
|
|
37
|
+
reserveLine(): void;
|
|
38
|
+
reserveFragment(): void;
|
|
39
|
+
private reserveMeasurement;
|
|
40
|
+
measure(text: string, run: VisioTextRun, measure: MeasureText): number;
|
|
41
|
+
}
|
|
42
|
+
export declare const createTextLayoutBudget: (options?: Partial<TextLayoutLimits>) => TextLayoutBudget;
|
|
43
|
+
export declare const measureBrowserText: MeasureText;
|
|
44
|
+
/** Rendering-only greedy wrapping. Inject one budget across shapes to bound total UI-thread work. */
|
|
45
|
+
export declare function wrapText(runs: VisioTextRun[], width: number, measure?: MeasureText, firstLineIndent?: number, budget?: TextLayoutBudget): TextLine[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ViewerController, ViewerState } from './controller.js';
|
|
2
|
+
/** Only static application markup belongs here. All document labels are inserted as text. */
|
|
3
|
+
export declare const viewerChromeTemplate: string;
|
|
4
|
+
/** Presentation state stays local; page navigation uses the same controller as every binding. */
|
|
5
|
+
export declare class ViewerChrome {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(root: ShadowRoot, controller: ViewerController);
|
|
8
|
+
wire(): () => void;
|
|
9
|
+
render(state: ViewerState, noteCount: number): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ViewerController, ViewerState } from './controller.js';
|
|
2
|
+
/** Static markup only. Document text is assigned exclusively through value/textContent. */
|
|
3
|
+
export declare const editControlsTemplate = "<details class=\"edit-controls\"><summary>Edit diagram (experimental)</summary><p id=\"edit-warning\">Experimental source-backed editing. Unsupported targets are rejected. Native Visio compatibility is not verified. Keep your original file.</p><p data-edit-target></p><label for=\"edit-text\">Selected shape text</label><textarea id=\"edit-text\" rows=\"3\" aria-describedby=\"edit-warning edit-target edit-status\"></textarea><div class=\"edit-actions\"><button type=\"button\" data-edit=\"apply\">Apply text</button><button type=\"button\" data-edit=\"cancel\">Cancel</button><button type=\"button\" data-edit=\"undo\">Undo</button><button type=\"button\" data-edit=\"redo\">Redo</button></div><p id=\"edit-status\" role=\"status\" aria-live=\"polite\"></p><p data-edit-error role=\"alert\" hidden></p><ul data-edit-diagnostics></ul><fieldset data-geometry><legend>Geometry (experimental)</legend><p>Pin X/Y use drawing inches, bottom-left origin, Y up. Resize holds the rotation pin fixed. Core rejects unsupported formulas, protected cells, unsafe group/master dependencies and referenced deletion. Native Visio reopen fidelity is unverified.</p><label>New rectangle ID <input data-geometry-field=\"id\" type=\"text\" maxlength=\"256\"></label><label>Rectangle text (optional) <input data-geometry-field=\"text\" type=\"text\" maxlength=\"1000000\"></label><label>Pin X (inches) <input data-geometry-field=\"x\" type=\"number\" step=\"any\"></label><label>Pin Y (inches) <input data-geometry-field=\"y\" type=\"number\" step=\"any\"></label><label>Width (inches) <input data-geometry-field=\"width\" type=\"number\" min=\"0\" step=\"any\"></label><label>Height (inches) <input data-geometry-field=\"height\" type=\"number\" min=\"0\" step=\"any\"></label><div class=\"edit-actions\"><button type=\"button\" data-geometry-action=\"create-rectangle\">Create rectangle</button><button type=\"button\" data-geometry-action=\"move-shape\">Move selected</button><button type=\"button\" data-geometry-action=\"resize-shape\">Resize selected</button><button type=\"button\" data-geometry-action=\"delete-shape\">Delete selected</button></div><p data-geometry-error role=\"alert\" hidden></p></fieldset></details>";
|
|
4
|
+
export declare class ViewerEditControls {
|
|
5
|
+
#private;
|
|
6
|
+
readonly panel: HTMLDetailsElement;
|
|
7
|
+
readonly input: HTMLTextAreaElement;
|
|
8
|
+
constructor(root: ShadowRoot, controller: ViewerController);
|
|
9
|
+
wire(): () => void;
|
|
10
|
+
reset(focus?: boolean): void;
|
|
11
|
+
render(state: ViewerState): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { VisioDocument, VisioEdit } from 'ooxml-core/visio';
|
|
2
|
+
import type { VsdxSource } from './contract.js';
|
|
3
|
+
import { ViewerController } from './controller.js';
|
|
4
|
+
import { type SvgExportOptions, type SvgExportResult } from './export-svg.js';
|
|
5
|
+
import { type CurrentPagePrintSnapshotOptions, type PrintSnapshot } from './print-snapshot.js';
|
|
6
|
+
declare const BaseElement: typeof HTMLElement;
|
|
7
|
+
export declare class VisioViewerElement extends BaseElement {
|
|
8
|
+
#private;
|
|
9
|
+
readonly controller: ViewerController;
|
|
10
|
+
constructor();
|
|
11
|
+
get document(): VisioDocument | null;
|
|
12
|
+
set document(value: VisioDocument | null);
|
|
13
|
+
get pageIndex(): number;
|
|
14
|
+
set pageIndex(value: number);
|
|
15
|
+
get zoom(): number;
|
|
16
|
+
set zoom(value: number);
|
|
17
|
+
get showToolbar(): boolean;
|
|
18
|
+
set showToolbar(value: boolean);
|
|
19
|
+
get renderWarnings(): readonly string[];
|
|
20
|
+
load(source: VsdxSource): Promise<void>;
|
|
21
|
+
applyEdits(edits: readonly VisioEdit[]): Promise<void>;
|
|
22
|
+
replacePlainText(pageId: string, shapeId: string, text: string): Promise<void>;
|
|
23
|
+
undo(): Promise<void>;
|
|
24
|
+
redo(): Promise<void>;
|
|
25
|
+
cancelEdit(): void;
|
|
26
|
+
exportVsdx(): ReturnType<ViewerController['exportVsdx']>;
|
|
27
|
+
fit(): void;
|
|
28
|
+
setLayerVisibility(pageId: string, layerId: string, visible: boolean | null): void;
|
|
29
|
+
resetLayerVisibility(pageId?: string): void;
|
|
30
|
+
/** Return a portable saved-display current-page snapshot without changing selection or downloading a file. */
|
|
31
|
+
exportSvg(options?: SvgExportOptions): SvgExportResult;
|
|
32
|
+
/** Prepare only the captured current drawing with saved display visibility. No frame, download, print dialog or state change. */
|
|
33
|
+
createPrintSnapshot(options?: CurrentPagePrintSnapshotOptions): PrintSnapshot;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
connectedCallback(): void;
|
|
36
|
+
disconnectedCallback(): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function registerVisioViewer(): void;
|
|
39
|
+
declare global {
|
|
40
|
+
interface HTMLElementTagNameMap {
|
|
41
|
+
'visio-viewer': VisioViewerElement;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ViewerController, ViewerState } from './controller.js';
|
|
2
|
+
export declare const geometryControlsTemplate = "<fieldset data-geometry><legend>Geometry (experimental)</legend><p>Pin X/Y use drawing inches, bottom-left origin, Y up. Resize holds the rotation pin fixed. Core rejects unsupported formulas, protected cells, unsafe group/master dependencies and referenced deletion. Native Visio reopen fidelity is unverified.</p><label>New rectangle ID <input data-geometry-field=\"id\" type=\"text\" maxlength=\"256\"></label><label>Rectangle text (optional) <input data-geometry-field=\"text\" type=\"text\" maxlength=\"1000000\"></label><label>Pin X (inches) <input data-geometry-field=\"x\" type=\"number\" step=\"any\"></label><label>Pin Y (inches) <input data-geometry-field=\"y\" type=\"number\" step=\"any\"></label><label>Width (inches) <input data-geometry-field=\"width\" type=\"number\" min=\"0\" step=\"any\"></label><label>Height (inches) <input data-geometry-field=\"height\" type=\"number\" min=\"0\" step=\"any\"></label><div class=\"edit-actions\"><button type=\"button\" data-geometry-action=\"create-rectangle\">Create rectangle</button><button type=\"button\" data-geometry-action=\"move-shape\">Move selected</button><button type=\"button\" data-geometry-action=\"resize-shape\">Resize selected</button><button type=\"button\" data-geometry-action=\"delete-shape\">Delete selected</button></div><p data-geometry-error role=\"alert\" hidden></p></fieldset>";
|
|
3
|
+
/** Collect explicit coordinates; never infer a Visio pin from rendered SVG transforms. */
|
|
4
|
+
export declare class ViewerGeometryControls {
|
|
5
|
+
#private;
|
|
6
|
+
private readonly panel;
|
|
7
|
+
private readonly controller;
|
|
8
|
+
private readonly draftChanged;
|
|
9
|
+
constructor(panel: HTMLElement, controller: ViewerController, draftChanged?: () => void);
|
|
10
|
+
wire(): () => void;
|
|
11
|
+
get hasDraft(): boolean;
|
|
12
|
+
reset(): void;
|
|
13
|
+
render(state: ViewerState): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ViewerController } from './controller.js';
|
|
2
|
+
interface Controls {
|
|
3
|
+
viewport: HTMLDivElement;
|
|
4
|
+
commandRoot: ShadowRoot;
|
|
5
|
+
pageSelect: HTMLSelectElement;
|
|
6
|
+
searchInput: HTMLInputElement;
|
|
7
|
+
}
|
|
8
|
+
/** Own every DOM listener and abort them together when the surface is disposed. */
|
|
9
|
+
export declare function wireViewerInputs(controls: Controls, controller: ViewerController, fit: () => void): () => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ViewerController, ViewerState } from './controller.js';
|
|
2
|
+
export declare const layerControlsTemplate = "<details class=\"layer-controls\" hidden><summary>Layers</summary><p>Display changes only. SVG and print snapshots use saved visibility. Guides, NoShow and unknown hidden reasons remain hidden.</p><div data-layer-list></div><p data-layer-status role=\"status\"></p><button type=\"button\" data-layer-reset=\"all\">Reset all layers</button></details>";
|
|
3
|
+
/** Static controls and text-only labels. Document strings never become selectors or markup. */
|
|
4
|
+
export declare function renderLayerControls(panel: HTMLDetailsElement, state: ViewerState): void;
|
|
5
|
+
export declare function wireLayerControls(panel: HTMLDetailsElement, controller: ViewerController): () => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type VisioDocument, type VisioShape } from 'ooxml-core/visio';
|
|
2
|
+
/** UI limits. Visibility semantics and shape traversal remain in ooxml-core. */
|
|
3
|
+
export declare const VIEWER_LAYER_LIMITS: Readonly<{
|
|
4
|
+
overrides: 25000;
|
|
5
|
+
controls: 200;
|
|
6
|
+
}>;
|
|
7
|
+
export interface LayerVisibilityOverride {
|
|
8
|
+
/** The source page owning the layer, including background pages. */
|
|
9
|
+
readonly pageId: string;
|
|
10
|
+
readonly layerId: string;
|
|
11
|
+
readonly visible: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const EMPTY_LAYER_OVERRIDES: readonly LayerVisibilityOverride[];
|
|
14
|
+
/** Validate before allocating indexes; never expose mutable maps as viewer state. */
|
|
15
|
+
export declare function layerOverrideMaps(model: VisioDocument | null, overrides: readonly LayerVisibilityOverride[]): Map<string, Map<string, boolean>>;
|
|
16
|
+
export declare function documentVisibility(model: VisioDocument | null, overrides?: readonly LayerVisibilityOverride[]): WeakMap<VisioShape, boolean>;
|
|
17
|
+
export declare function visibleSelection(model: VisioDocument | null, pageIndex: number, selection: {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly pageId?: string;
|
|
20
|
+
} | null, visible: WeakMap<VisioShape, boolean>): boolean;
|
|
21
|
+
/** Rendering eligibility shared by selection and SVG containers; no format interpretation. */
|
|
22
|
+
export declare function hasVisibleShapeContent(shape: VisioShape, visible: WeakMap<VisioShape, boolean> | undefined, cache?: WeakMap<VisioShape, boolean>): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ViewerState } from './controller.js';
|
|
2
|
+
export declare const searchTemplate: string;
|
|
3
|
+
export interface SearchControls {
|
|
4
|
+
input: HTMLInputElement;
|
|
5
|
+
status: HTMLSpanElement;
|
|
6
|
+
previous: HTMLButtonElement;
|
|
7
|
+
next: HTMLButtonElement;
|
|
8
|
+
}
|
|
9
|
+
export declare function searchControls(root: ShadowRoot): SearchControls;
|
|
10
|
+
export declare function renderSearchControls(controls: SearchControls, state: ViewerState): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { snapshotEdits } from './edit-commands.js';
|
|
2
|
+
import type { VisioDocument, VisioEdit } from 'ooxml-core/visio';
|
|
3
|
+
import type { EditDiagnostic } from './document-history.js';
|
|
4
|
+
export interface EditWorkerRequest {
|
|
5
|
+
bytes: ArrayBuffer;
|
|
6
|
+
edits: readonly VisioEdit[];
|
|
7
|
+
}
|
|
8
|
+
export interface EditTransactionResult {
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
document: VisioDocument;
|
|
11
|
+
changedParts: readonly string[];
|
|
12
|
+
diagnostics: readonly EditDiagnostic[];
|
|
13
|
+
}
|
|
14
|
+
export type CancellableEditor = ((bytes: Uint8Array, edits: readonly VisioEdit[]) => Promise<EditTransactionResult>) & {
|
|
15
|
+
cancel?: () => void;
|
|
16
|
+
};
|
|
17
|
+
export interface EditWorkerLike {
|
|
18
|
+
onmessage: ((event: MessageEvent) => void) | null;
|
|
19
|
+
onerror: ((event: ErrorEvent) => void) | null;
|
|
20
|
+
postMessage(message: EditWorkerRequest, transfer: Transferable[]): void;
|
|
21
|
+
terminate(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createWorkerEditor(factory?: () => EditWorkerLike, timeoutMs?: number): CancellableEditor;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type VisioDocument } from 'ooxml-core/visio';
|
|
2
|
+
export type CancellableParser = ((bytes: Uint8Array | ArrayBuffer) => Promise<VisioDocument>) & {
|
|
3
|
+
cancel?: () => void;
|
|
4
|
+
};
|
|
5
|
+
export interface WorkerLike {
|
|
6
|
+
onmessage: ((event: MessageEvent) => void) | null;
|
|
7
|
+
onerror: ((event: ErrorEvent) => void) | null;
|
|
8
|
+
postMessage(message: ArrayBuffer, transfer: Transferable[]): void;
|
|
9
|
+
terminate(): void;
|
|
10
|
+
}
|
|
11
|
+
export type WorkerFactory = () => WorkerLike;
|
|
12
|
+
/** One disposable worker per document prevents old parses and long CPU tasks from occupying the UI. */
|
|
13
|
+
export declare function createWorkerParser(factory?: WorkerFactory, timeoutMs?: number): CancellableParser;
|
package/package.json
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "visio-react-viewer",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first Visio viewer for react",
|
|
5
5
|
"homepage": "https://christophervr.github.io/visio-viewer/",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"author": "ChristopherVR",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/ChristopherVR/visio-viewer.git",
|
|
11
|
-
"directory": "
|
|
11
|
+
"directory": "packages/react"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
16
17
|
],
|
|
17
18
|
"type": "module",
|
|
18
|
-
"exports":
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
19
26
|
"publishConfig": {
|
|
20
27
|
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"emf-converter": "4.8.9",
|
|
31
|
+
"ooxml-core": "^0.10.0",
|
|
32
|
+
"visio-core": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=18"
|
|
21
36
|
}
|
|
22
37
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const status = 'placeholder';
|