/*! 20251201182703
* Dynamsoft JavaScript Library
* Product: Dynamic Web TWAIN
* Web Site: https://www.dynamsoft.com
*
* Copyright 2025, Dynamsoft Corporation
* Author: Dynamsoft Support Team
*
* Module: OCR
* Version: 19.3
* 
*/
var Dynamsoft=self.Dynamsoft||{};Dynamsoft.DWT=Dynamsoft.DWT||{},Dynamsoft.aryAddonReadyFun=Dynamsoft.aryAddonReadyFun||[],Dynamsoft.AddonReady=Dynamsoft.AddonReady||function(e){Dynamsoft.aryAddonReadyFun.push(e)},Dynamsoft.DWT.OCRKitVerInName="11.0.0.1028",function(){for(var e=[Dynamsoft.DWT],r=0;r<1;r++){var n=e[r];n.EnumDWT_OCRKitOutputFormat={TEXT:0,PDF_PLAIN_TEXT:1,PDF_WITH_EXTRA_TEXTLAYER:2},n.EnumDWT_PageOrientation={AUTO:-1,ANGLE_0:0,ANGLE_90:90,ANGLE_180:180,ANGLE_270:270},n.EnumDWT_PageOrientationDetectionMode={FAST:0,BALANCE:1,PRECISION:2}}}(),Dynamsoft.AddonReady(function(c,e){function t(e,r){return"code"in r&&"message"in r&&0!=r.code&&""!=r.message&&(e._errorCode=r.code,e._errorString=r.message,{code:r.code,message:r.message})}c.product.bHTML5Edition&&c.DynamicLoadAddonFuns&&c.DynamicLoadAddonFuns.push(function(s){var e,i,a,d=c.html5.Funs;i=s,a=c.html5.Funs,i.__innerOCRReadFunction=function(e,r){var n=i,e=n._ImgManager.convertClientIndexToServerId(e),e=c.stringify({index:e,options:r});return n._innerFunV2("OCROnnx",["[",e,"]"].join("")).then(function(e){var r=t(n,e);return r?c.Promise.reject(r):e})},i.__innerGetOCRInfo=function(){var n=i;return n._innerFunV2("GetOCROnnxEnv",a.makeParams(Dynamsoft.DWT.OCRKitVerInName)).then(function(e){var r=t(n,e);return r?c.Promise.reject(r):e})},i.__innerDetectPageOrientation=function(e,r){var n=i,e=n._ImgManager.convertClientIndexToServerId(e),e=c.stringify({index:e,settings:r});return n._innerFunV2("DetectPageOrientation",["[",e,"]"].join("")).then(function(e){var r=t(n,e);return r?c.Promise.reject(r):{angle:e.angle||0,confidence:e.confidence||0}})},i.__innerSaveToPath=function(e,r,n){var t=i,o=[];return c.isArray(e)&&c.each(e,function(e){e=i._ImgManager.convertClientIndexToServerId(e);o.push(e)}),t._innerFunV2("SaveOCRResult",a.makeParams(0,o.join(","),r,n))},i.__innerSaveAsBlob=function(e,n){var r=i,t=[],e=(c.isArray(e)&&c.each(e,function(e){e=i._ImgManager.convertClientIndexToServerId(e);t.push(e)}),["[",1,',"',t.join(","),'",',n,"]"].join(""));return r._sendDataByHttpAsync("SaveOCRResult",e,"arraybuffer",!0).then(function(e){var r="application/pdf";return n==Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.TEXT&&(r="text/plain"),new Blob([e],{type:r})})},i.__innerSaveAsBase64=function(e,r){var n=i,t=[];return c.isArray(e)&&c.each(e,function(e){e=i._ImgManager.convertClientIndexToServerId(e);t.push(e)}),n._innerFunV2("SaveOCRResult",a.makeParams(2,t.join(","),r))},e={OCRKit:{GetInstalledOCRInfo:function(){var e=s,r="GetInstalledOCRInfo";return e._resetErr(),d.showMask(r),c.env.bWin&&Dynamsoft.dcp.b64bit?c.License.checkProductKey(e,{OCRKit:!0},!0)?e.__innerGetOCRInfo().finally(function(){d.hideMask(r)}):(d.hideMask(r),c.Promise.reject({code:e._errorCode,message:e._errorString})):(c.Errors.OCR_InvalidSupportedPlatforms(e),d.hideMask(r),c.Promise.reject({code:e._errorCode,message:e._errorString}))},DetectPageOrientation:function(e,r){var n=s,t="DetectPageOrientation";if(n._resetErr(),d.showMask(t),!c.env.bWin||!Dynamsoft.dcp.b64bit)return c.Errors.OCR_InvalidSupportedPlatforms(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(!c.License.checkProductKey(n,{OCRKit:!0},!0))return d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});e=parseInt(e);if(isNaN(e))return c.Errors.InvalidIndex(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(e<0||e>=n.HowManyImagesInBuffer)return c.Errors.IndexOutOfRange(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(null==r)r={};else if(!c.isObject(r))return c.Errors.InvalidParameter(s),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});return isNaN(r.detectionMode)&&(r.detectionMode=1),n.__innerDetectPageOrientation(e,r).finally(function(){d.hideMask(t)})},Recognize:function(e,r){var n=s,t="Recognize";if(n._resetErr(),d.showMask(t),!c.env.bWin||!Dynamsoft.dcp.b64bit)return c.Errors.OCR_InvalidSupportedPlatforms(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(!c.License.checkProductKey(n,{OCRKit:!0},!0))return d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});e=parseInt(e);if(isNaN(e)||e<0||e>=n.HowManyImagesInBuffer)return c.Errors.IndexOutOfRange(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(null==r)r={settings:{}};else if(null==r.settings)r.settings={};else if(!c.isObject(r.settings))return c.Errors.InvalidParameter(s),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});if(isNaN(r.settings.pageOrientation)&&(r.settings.pageOrientation=1),isNaN(r.settings.binarizationThreshold)&&(r.settings.binarizationThreshold=.3),isNaN(r.settings.boxThreshold)&&(r.settings.boxThreshold=.1),null==r.rects)r.rects=[];else if(!c.isArray(r.rects))return c.Errors.IndicesNotArray(s),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString});return n.__innerOCRReadFunction(e,r).finally(function(){d.hideMask(t)})},SaveToPath:function(e,r,n){var t,o=s,i="SaveToPath";return o._resetErr(),d.showMask(i),c.env.bWin&&Dynamsoft.dcp.b64bit?c.License.checkProductKey(o,{OCRKit:!0},!0)&&o._checkIndices(e)?c.isString(n)&&""!=n&&"/"!=n?(t=parseInt(r),!(isNaN(t)||t<Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.TEXT||t>Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.PDF_WITH_EXTRA_TEXTLAYER)&&(o.IfShowFileDialog||c.isString(n)&&""!==n)?(n=n,r==Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.TEXT&&".txt"!==(n=0<=(r=n.lastIndexOf("/"))?n.slice(r+1):n).slice(-4).toLowerCase()&&(n+=".txt"),r=c.html5.Funs.replaceLocalFilename(n),o.__innerSaveToPath(e,t,r).finally(function(){d.hideMask(i)})):(c.Errors.InvalidValue(o),d.hideMask(i),c.Promise.reject({code:o._errorCode,message:o._errorString}))):(c.Errors.OCRKit_InvalidFilename(o),d.hideMask(i),c.Promise.reject({code:o._errorCode,message:o._errorString})):(d.hideMask(i),c.Promise.reject({code:o._errorCode,message:o._errorString})):(c.Errors.OCR_InvalidSupportedPlatforms(o),d.hideMask(i),c.Promise.reject({code:o._errorCode,message:o._errorString}))},SaveAsBlob:function(e,r){var n=s,t="SaveAsBlob";return n._resetErr(),d.showMask(t),c.env.bWin&&Dynamsoft.dcp.b64bit?c.License.checkProductKey(n,{OCRKit:!0},!0)&&n._checkIndices(e)?(r=parseInt(r),isNaN(r)||r<Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.TEXT||r>Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.PDF_WITH_EXTRA_TEXTLAYER?(c.Errors.InvalidValue(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString})):n.__innerSaveAsBlob(e,r).finally(function(){d.hideMask(t)})):(d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString})):(c.Errors.OCR_InvalidSupportedPlatforms(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString}))},SaveAsBase64:function(e,r){var n=s,t="SaveAsBase64";return n._resetErr(),d.showMask(t),c.env.bWin&&Dynamsoft.dcp.b64bit?c.License.checkProductKey(n,{OCRKit:!0},!0)&&n._checkIndices(e)?(r=parseInt(r),isNaN(r)||r<Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.TEXT||r>Dynamsoft.DWT.EnumDWT_OCRKitOutputFormat.PDF_WITH_EXTRA_TEXTLAYER?(c.Errors.InvalidValue(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString})):n.__innerSaveAsBase64(e,r).finally(function(){d.hideMask(t)})):(d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString})):(c.Errors.OCR_InvalidSupportedPlatforms(n),d.hideMask(t),c.Promise.reject({code:n._errorCode,message:n._errorString}))}}},s.__addon=s.__addon||{},c.mix(s.__addon,e)})});