UNPKG

dynamsoft-document-normalizer

Version:

Dynamsoft Document Normalizer (DDN) is an SDK designed to detect quadrilaterals (quads for short) such as document/table boundaries and more from images, then perform document normalization on the images in the detected quads.

12 lines (11 loc) 3 kB
/*! * Dynamsoft JavaScript Library * @product Dynamsoft Document Normalizer JS Edition * @website http://www.dynamsoft.com * @copyright Copyright 2024, Dynamsoft Corporation * @author Dynamsoft * @version 2.6.11 * @fileoverview Dynamsoft JavaScript Library for Document Normalizer * More info on ddn JS: https://www.dynamsoft.com/document-normalizer/docs/web/programming/javascript/ */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("dynamsoft-core")):"function"==typeof define&&define.amd?define(["exports","dynamsoft-core"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).Dynamsoft=e.Dynamsoft||{},e.Dynamsoft.DDN={}),e.Dynamsoft.Core)}(this,(function(e,n){"use strict";const t="undefined"==typeof self,o="function"==typeof importScripts,s=(()=>{if(!o){if(!t&&document.currentScript){let e=document.currentScript.src,n=e.indexOf("?");if(-1!=n)e=e.substring(0,n);else{let n=e.indexOf("#");-1!=n&&(e=e.substring(0,n))}return e.substring(0,e.lastIndexOf("/")+1)}return"./"}})(),r=e=>{if(null==e&&(e="./"),t||o);else{let n=document.createElement("a");n.href=e,e=n.href}return e.endsWith("/")||(e+="/"),e};n.CoreModule.engineResourcePaths.ddn={version:"2.6.11",path:s,isInternal:!0},n.workerAutoResources.ddn={js:!0,wasm:!0,deps:["license","dip"]},n.mapPackageRegister.ddn={handleNormalizedImageResultItem:function(e){let t=e,o=n._getNorImageData(t.imageData);t.toCanvas=()=>n._toCanvas(o),t.toImage=e=>n._toImage(e,o),t.toBlob=e=>n._toBlob(e,o),t.saveToFile=async(e,t)=>{if(!e)return null;if("string"!=typeof e)throw new TypeError("FileName must be of type string.");return n._saveToFile(o,e,t)}}};const i="1.4.21";"string"!=typeof n.CoreModule.engineResourcePaths.std&&n.compareVersion(n.CoreModule.engineResourcePaths.std.version,i)<0&&(n.CoreModule.engineResourcePaths.std={version:i,path:r(s+`../../dynamsoft-capture-vision-std@${i}/dist/`),isInternal:!0});const a="2.4.31";(!n.CoreModule.engineResourcePaths.dip||"string"!=typeof n.CoreModule.engineResourcePaths.dip&&n.compareVersion(n.CoreModule.engineResourcePaths.dip.version,a)<0)&&(n.CoreModule.engineResourcePaths.dip={version:a,path:r(s+`../../dynamsoft-image-processing@${a}/dist/`),isInternal:!0});var d;e.EnumImageColourMode=void 0,(d=e.EnumImageColourMode||(e.EnumImageColourMode={}))[d.ICM_COLOUR=0]="ICM_COLOUR",d[d.ICM_GRAYSCALE=1]="ICM_GRAYSCALE",d[d.ICM_BINARY=2]="ICM_BINARY",e.DocumentNormalizerModule=class{static getVersion(){const e=n.innerVersions.ddn&&n.innerVersions.ddn.wasm,t=n.innerVersions.ddn&&n.innerVersions.ddn.worker;return`2.6.11(Worker: ${t||"Not Loaded"}, Wasm: ${e||"Not Loaded"})`}async setThresholdValue(e,t,o,s){return await n.loadWasm("ddn"),await new Promise(((r,i)=>{let a=n.getNextTaskID();n.mapTaskCallBack[a]=async e=>{if(e.success)return r();{let n=new Error(e.message);return n.stack=e.stack+"\n"+n.stack,i(n)}},n.worker.postMessage({type:"ddn_setThresholdValue",id:a,instanceID:e._instanceID,body:{threshold:t,leftLimit:o,rightLimit:s}})}))}}}));