@mha/scan-edit-lib 1.3.0 → 1.4.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.
@@ -0,0 +1,8 @@
1
+ var o = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function l(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ export {
6
+ o as c,
7
+ l as g
8
+ };
@@ -1,4 +1,5 @@
1
1
  import { default as React } from 'react';
2
+ import { DocumentProcessingConfigProp } from '../../hooks/useBridgeDocumentOps';
2
3
  export interface PageData {
3
4
  pageIndex: number;
4
5
  annotations: any;
@@ -12,6 +13,16 @@ export interface DocumentViewerProps {
12
13
  onSave?: (data: DocumentSaveData) => void;
13
14
  onPageDeleted?: (pageIndex: number, pageId: string) => void;
14
15
  onAnnotationsChange?: (pageId: string, annotations: Record<string, unknown>) => void;
16
+ /**
17
+ * Remote document-processing service. Supplied by the host app so this library stays
18
+ * environment-agnostic. Omit to use Bridge-native OCR only.
19
+ */
20
+ documentProcessing?: DocumentProcessingConfigProp;
21
+ /**
22
+ * Location of the original document. Supplying it lets a whole-document search run as a
23
+ * single request instead of one per page.
24
+ */
25
+ documentUrl?: string;
15
26
  }
16
27
  export declare const DocumentViewer: React.FC<DocumentViewerProps>;
17
28
  export default DocumentViewer;
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentViewer.d.ts","sourceRoot":"","sources":["../../../src/components/documentViewer/DocumentViewer.tsx"],"names":[],"mappings":"AACA,OAAO,KAA+C,MAAM,OAAO,CAAC;AA0EpE,MAAM,WAAW,QAAQ;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,UAAU,E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G;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAolHD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAMxD,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -3,9 +3,20 @@ import { ScannerCanvas as BaseScannerCanvas } from '../scanner/ScannerCanvas';
3
3
  import { ScannerCanvasWithTools as BaseScannerCanvasWithTools } from '../scanner/ScannerCanvasWithTools';
4
4
  import { UploadCanvas as BaseUploadCanvas } from '../upload/UploadCanvas';
5
5
  import { default as DocumentViewer } from '../documentViewer/DocumentViewer';
6
- export declare const ScannerCanvas: React.FC<React.ComponentProps<typeof BaseScannerCanvas>>;
7
- export declare const ScannerCanvasWithTools: React.FC<React.ComponentProps<typeof BaseScannerCanvasWithTools>>;
8
- export declare const UploadCanvas: React.FC<React.ComponentProps<typeof BaseUploadCanvas>>;
9
- declare const WrappedDocumentViewer: React.FC<React.ComponentProps<typeof DocumentViewer>>;
6
+ /**
7
+ * Host-supplied Scanner Bridge endpoint. Omit to use the SDK default
8
+ * (ws://127.0.0.1:8080) so existing consumers keep working unchanged.
9
+ */
10
+ export interface BridgeConnectionProps {
11
+ bridgeUrl?: string;
12
+ }
13
+ type ScannerCanvasProps = React.ComponentProps<typeof BaseScannerCanvas> & BridgeConnectionProps;
14
+ type ScannerCanvasWithToolsProps = React.ComponentProps<typeof BaseScannerCanvasWithTools> & BridgeConnectionProps;
15
+ type UploadCanvasProps = React.ComponentProps<typeof BaseUploadCanvas> & BridgeConnectionProps;
16
+ type DocumentViewerProps = React.ComponentProps<typeof DocumentViewer> & BridgeConnectionProps;
17
+ export declare const ScannerCanvas: React.FC<ScannerCanvasProps>;
18
+ export declare const ScannerCanvasWithTools: React.FC<ScannerCanvasWithToolsProps>;
19
+ export declare const UploadCanvas: React.FC<UploadCanvasProps>;
20
+ declare const WrappedDocumentViewer: React.FC<DocumentViewerProps>;
10
21
  export { WrappedDocumentViewer as DocumentViewer };
11
22
  //# sourceMappingURL=WrappedComponents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WrappedComponents.d.ts","sourceRoot":"","sources":["../../../src/components/wrapped/WrappedComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,sBAAsB,IAAI,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AACzG,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAG9D,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,iBAAiB,CAAC,CAIlF,CAAC;AAGF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,0BAA0B,CAAC,CAIpG,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAIhF,CAAC;AAGF,QAAA,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,cAAc,CAAC,CAIhF,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"WrappedComponents.d.ts","sourceRoot":"","sources":["../../../src/components/wrapped/WrappedComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,sBAAsB,IAAI,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AACzG,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,KAAK,kBAAkB,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,iBAAiB,CAAC,GAAG,qBAAqB,CAAC;AACjG,KAAK,2BAA2B,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,0BAA0B,CAAC,GAAG,qBAAqB,CAAC;AACnH,KAAK,iBAAiB,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,gBAAgB,CAAC,GAAG,qBAAqB,CAAC;AAC/F,KAAK,mBAAmB,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,cAAc,CAAC,GAAG,qBAAqB,CAAC;AAI/F,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAItD,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAIxE,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAIpD,CAAC;AAEF,QAAA,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAIxD,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { OcrResult, OcrOptions, OcrRect } from '@mha/scanner-bridge-sdk';
2
+ import * as fabric from "fabric";
3
+ /**
4
+ * Supplied by the host application, never read from the environment — this library is
5
+ * published, so build-time config would leak the library's environment into consumers.
6
+ * Omit entirely to use Bridge-native OCR only.
7
+ */
8
+ export interface DocumentProcessingConfigProp {
9
+ baseUrl: string;
10
+ /** Called per request so the host owns token minting and refresh. */
11
+ getToken?: () => Promise<string | null> | string | null;
12
+ /** Longest edge of the JPEG sent to the service. */
13
+ maxDimension?: number;
14
+ }
15
+ interface UseBridgeDocumentOpsProps {
16
+ canvas: fabric.Canvas | null;
17
+ client: {
18
+ runLocalOcr: (sessionId: string, pageIndex: number, options?: OcrOptions) => Promise<OcrResult & {
19
+ pageIndex: number;
20
+ }>;
21
+ denoisePage: (sessionId: string, pageIndex: number, options?: {
22
+ despeckle?: boolean;
23
+ bilateralBlur?: boolean;
24
+ applyToSession?: boolean;
25
+ }) => Promise<{
26
+ preview: string;
27
+ width: number;
28
+ height: number;
29
+ }>;
30
+ getPageForOcr: (sessionId: string, pageIndex: number, options?: {
31
+ maxDimension?: number;
32
+ quality?: number;
33
+ redactions?: OcrRect[];
34
+ }) => Promise<{
35
+ image: string;
36
+ sourceWidth: number;
37
+ sourceHeight: number;
38
+ }>;
39
+ } | null;
40
+ sessionId: string;
41
+ pageIndex: number;
42
+ documentProcessing?: DocumentProcessingConfigProp;
43
+ /**
44
+ * Location of the original document. When supplied alongside documentProcessing, a
45
+ * whole-document search is one request instead of one per page, and the original
46
+ * encoding is preserved rather than re-encoding every page as JPEG.
47
+ */
48
+ documentUrl?: string;
49
+ /**
50
+ * Redactions for every page, keyed by page index, as fractions (0-1) of the page.
51
+ * Needed for whole-document recognition because only the open page has live canvas
52
+ * objects to read.
53
+ */
54
+ redactionsByPage?: Record<number, OcrRect[]>;
55
+ /** Total pages in the document, for cross-page search. */
56
+ pageCount?: number;
57
+ /**
58
+ * Page indices known to contain redactions. Only the page currently on the canvas can
59
+ * have its redactions mapped reliably, so other redacted pages are skipped rather than
60
+ * recognized with a possibly misplaced mask.
61
+ */
62
+ redactedPageIndices?: number[];
63
+ /**
64
+ * Text carried by each page's annotations, indexed by page. OCR reads the page image,
65
+ * which never contains typed notes, so they are searched from here instead.
66
+ */
67
+ annotationTextsByPage?: string[][];
68
+ onNavigateToPage?: (pageIndex: number) => void;
69
+ }
70
+ export interface SearchHit {
71
+ pageIndex: number;
72
+ snippet: string;
73
+ wordIndices: number[];
74
+ /** Set when the hit came from a text annotation rather than the page image. */
75
+ isAnnotation?: boolean;
76
+ }
77
+ /**
78
+ * OCR and denoise routed through the Scanner Bridge, which runs native Tesseract and
79
+ * Magick.NET on the full-resolution page. Replaces the browser tesseract.js + opencv.js
80
+ * path in DocumentViewer.
81
+ */
82
+ export declare const useBridgeDocumentOps: ({ canvas, client, sessionId, pageIndex, documentProcessing, documentUrl, redactionsByPage, pageCount, redactedPageIndices, annotationTextsByPage, onNavigateToPage, }: UseBridgeDocumentOpsProps) => {
83
+ ocrText: string;
84
+ runOCR: (options?: OcrOptions) => Promise<void>;
85
+ isProcessing: boolean;
86
+ error: string;
87
+ lastResult: OcrResult;
88
+ highlightWords: (minConfidence?: number) => void;
89
+ clearText: () => void;
90
+ showText: boolean;
91
+ setShowText: import('react').Dispatch<import('react').SetStateAction<boolean>>;
92
+ denoise: () => Promise<void>;
93
+ isDenoising: boolean;
94
+ search: (query: string) => number;
95
+ searchQuery: string;
96
+ matchCount: number;
97
+ activeMatchIndex: number;
98
+ nextMatch: () => void;
99
+ prevMatch: () => void;
100
+ clearSearch: () => void;
101
+ searchDocument: (query: string) => Promise<void>;
102
+ searchHits: SearchHit[];
103
+ isSearching: boolean;
104
+ searchProgress: {
105
+ done: number;
106
+ total: number;
107
+ };
108
+ skippedPages: number[];
109
+ goToHit: (hit: SearchHit) => Promise<void>;
110
+ };
111
+ export {};
112
+ //# sourceMappingURL=useBridgeDocumentOps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBridgeDocumentOps.d.ts","sourceRoot":"","sources":["../../src/hooks/useBridgeDocumentOps.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE9E;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,C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AC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACnC,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,SAAS;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AA6BD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,uKAYlC,yBAAyB;;uBA8LmB,UAAU;;;;qCAgFF,MAAM;;;;;;oBA6MtB,MAAM,KAAG,MAAM;;;;;;;4BApID,MAAM;;;;;;;;mBA+Ff,SAAS;CA2PpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useImageProcessing.d.ts","sourceRoot":"","sources":["../../src/hooks/useImageProcessing.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAcjC,UAAU,uBAAuB;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,kBAAkB,GAAI,0BAA0B,uBAAuB;;;;wBA+PhD,MAAM;;kCA4QI,MAAM;gCAqBR,MAAM;;;;;;;;;;;CAsRjD,CAAC"}
1
+ {"version":3,"file":"useImageProcessing.d.ts","sourceRoot":"","sources":["../../src/hooks/useImageProcessing.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAcjC,UAAU,uBAAuB;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,kBAAkB,GAAI,0BAA0B,uBAAuB;;;;wBAgRhD,MAAM;;kCA4QI,MAAM;gCAqBR,MAAM;;;;;;;;;;;CAsRjD,CAAC"}
@@ -1,5 +1,5 @@
1
- import { a as Va, g as il } from "./index-aSQgDQaI.js";
2
- import { _ as La } from "./jspdf.es.min--d75u2wp.js";
1
+ import { c as Va, g as il } from "./_commonjsHelpers-DaMA6jEr.js";
2
+ import { _ as La } from "./jspdf.es.min-DCkEMHjy.js";
3
3
  var fn = {}, cn = {}, cr, vn;
4
4
  function Q() {
5
5
  if (vn) return cr;
@@ -9098,7 +9098,7 @@ endobj\r
9098
9098
  var d = h.getContext("2d");
9099
9099
  d.fillStyle = "#fff", d.fillRect(0, 0, h.width, h.height);
9100
9100
  var m = { ignoreMouse: !0, ignoreAnimation: !0, ignoreDimensions: !0 }, _ = this;
9101
- return (Kt.canvg ? Promise.resolve(Kt.canvg) : import("./index.es-R5n8ZWt3.js")).catch(function(k) {
9101
+ return (Kt.canvg ? Promise.resolve(Kt.canvg) : import("./index.es-Xt2A3ZNU.js")).catch(function(k) {
9102
9102
  return Promise.reject(new Error("Could not load canvg: " + k));
9103
9103
  }).then(function(k) {
9104
9104
  return k.default ? k.default : k;