@copio/sdk 0.1.2 → 0.1.3
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 +661 -0
- package/LICENSE-COMMERCIAL.md +43 -0
- package/README.md +6 -1
- package/THIRD_PARTY_NOTICES.md +416 -0
- package/dist/adapters/image/canvas2d-adapter.js +1 -1
- package/dist/adapters/image/index.js +1 -1
- package/dist/adapters/image/null-image-processor-adapter.js +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/indexeddb-adapter.js +1 -1
- package/dist/adapters/memory-adapter.js +1 -1
- package/dist/adapters/ocr/index.js +1 -1
- package/dist/adapters/ocr/null-ocr-adapter.js +1 -1
- package/dist/adapters/ocr/tesseract-wasm-adapter.js +1 -1
- package/dist/adapters/pdf/index.js +1 -1
- package/dist/adapters/pdf/null-pdf-adapter.js +1 -1
- package/dist/adapters/pdf/pdfkit-adapter.js +1 -1
- package/dist/adapters/storage/index.js +1 -1
- package/dist/adapters/storage/indexeddb-adapter.js +1 -1
- package/dist/adapters/storage/memory-adapter.js +1 -1
- package/dist/adapters/sync/index.js +1 -1
- package/dist/adapters/sync/null-sync-adapter.js +1 -1
- package/dist/adapters/sync/peerjs-adapter.js +1 -1
- package/dist/cdn.js +106 -249
- package/dist/{chunk-A5G52Q2W.js → chunk-2AB5L3Y2.js} +2 -2
- package/dist/{chunk-DGGK5KEX.js → chunk-4ICUYKSR.js} +2 -2
- package/dist/{chunk-IZOWC74B.js → chunk-4XWSVHFW.js} +69 -198
- package/dist/{chunk-IUBYFIV6.js → chunk-4YYY7PHH.js} +2 -2
- package/dist/{chunk-N7Q34F2P.js → chunk-534NMCRQ.js} +4 -4
- package/dist/{chunk-UCV3MQ6I.js → chunk-5KUKBKWL.js} +1 -1
- package/dist/{chunk-E7JYVRJA.js → chunk-5OTO5WFV.js} +2 -2
- package/dist/{chunk-N4R55VRR.js → chunk-6DSLE3AY.js} +1 -1
- package/dist/chunk-DIU5BGU5.js +2 -0
- package/dist/chunk-DOKG4LX2.js +2 -0
- package/dist/{chunk-B2EK6INF.js → chunk-DY5ZSP4Q.js} +2 -2
- package/dist/chunk-FAVTIE3M.js +8 -0
- package/dist/chunk-FQRADJY6.js +2 -0
- package/dist/chunk-IH2AI54D.js +2 -0
- package/dist/{chunk-PVNRK4OH.js → chunk-J7HWZNIP.js} +2 -2
- package/dist/{chunk-SH4P4XSZ.js → chunk-KH5JE65X.js} +2 -2
- package/dist/chunk-MEE2NNYB.js +2 -0
- package/dist/{chunk-KIMVF5UG.js → chunk-NEEWG3OP.js} +1 -1
- package/dist/{chunk-YHLOPPXM.js → chunk-O6FQFVKY.js} +1 -1
- package/dist/chunk-RDCHJL6F.js +2 -0
- package/dist/{chunk-B7HT2X67.js → chunk-U3V3VZGO.js} +2 -2
- package/dist/{chunk-HN3336JN.js → chunk-ULTSZWZO.js} +1 -1
- package/dist/{chunk-BKZEOOH4.js → chunk-WETG2JD7.js} +2 -2
- package/dist/{chunk-V2FP4EEH.js → chunk-YNY65JUJ.js} +1 -1
- package/dist/chunk-ZT72PD2C.js +2 -0
- package/dist/core.js +1 -1
- package/dist/custom-elements.json +264 -102
- package/dist/export.js +1 -1
- package/dist/index.js +11 -19
- package/dist/ocr.js +1 -1
- package/dist/scanner.js +88 -217
- package/dist/sync.js +1 -1
- package/dist/types/js/adapters/storage/blob-store.d.ts +48 -0
- package/dist/types/js/adapters/storage/index.d.ts +11 -4
- package/dist/types/js/adapters/storage/indexeddb-adapter.d.ts +46 -9
- package/dist/types/js/adapters/storage/memory-adapter.d.ts +7 -0
- package/dist/types/js/adapters/storage/opfs-adapter.d.ts +160 -0
- package/dist/types/js/adapters/storage/storage-port.d.ts +7 -0
- package/dist/types/js/components/copio-header.d.ts +4 -0
- package/dist/types/js/routes/doc/copio-carousel.d.ts +1 -2
- package/dist/types/js/routes/doc/copio-images.d.ts +0 -4
- package/dist/types/js/routes/home/copio-row.d.ts +2 -2
- package/dist/types/js/routes/ocr/copio-doc-ocr-dialog.d.ts +0 -2
- package/dist/types/js/services/doc-repository.d.ts +1 -0
- package/dist/types/js/services/export-utils.d.ts +8 -12
- package/dist/types/js/services/ocr-service.d.ts +2 -1
- package/dist/types/js/utils/module-loader.d.ts +0 -6
- package/dist/types/js/utils/utils.d.ts +5 -3
- package/dist/types/sdk/core.d.ts +13 -2
- package/dist/types/sdk/events.d.ts +4 -4
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/models.d.ts +66 -0
- package/dist/types/sdk/styles.d.ts +1 -1
- package/dist/types/sdk/version.d.ts +1 -1
- package/package.json +4 -3
- package/sdk/cdn.js +1 -0
- package/sdk/core.js +60 -0
- package/sdk/events.js +3 -2
- package/sdk/index.js +4 -3
- package/sdk/license.js +1 -0
- package/sdk/models.js +79 -3
- package/sdk/scanner.js +45 -7
- package/sdk/styles.js +12 -5
- package/sdk/sync.js +1 -0
- package/sdk/version.js +2 -1
- package/dist/chunk-36F637QU.js +0 -2
- package/dist/chunk-4JPEWIT4.js +0 -2
- package/dist/chunk-B5BEYYR2.js +0 -8
- package/dist/chunk-G65H4ZTJ.js +0 -2
- package/dist/chunk-HS6GDZIS.js +0 -2
- package/dist/chunk-K6YP7EET.js +0 -8
- package/dist/chunk-LI54F6PA.js +0 -2
- package/dist/chunk-OI4WCW7E.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Et}from"./chunk-HN3336JN.js";function d(s,t,e){return t in s?Object.defineProperty(s,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):s[t]=e,s}var At=typeof self<"u"?self:global,q=typeof navigator<"u",me=q&&typeof HTMLImageElement>"u",zt=!(typeof global>"u"||typeof process>"u"||!process.versions||!process.versions.node),It=At.Buffer,tt=At.BigInt,Ut=!!It,et=s=>Yt(s)?void 0:s,ye=s=>s!==void 0;function Yt(s){return s===void 0||(s instanceof Map?s.size===0:Object.values(s).filter(ye).length===0)}function m(s){let t=new Error(s);throw delete t.stack,t}function qt(s){return(s=(function(t){for(;t.endsWith("\0");)t=t.slice(0,-1);return t})(s).trim())===""?void 0:s}function Vt(s){let t=(function(e){let i=0;return e.ifd0.enabled&&(i+=1024),e.exif.enabled&&(i+=2048),e.makerNote&&(i+=2048),e.userComment&&(i+=1024),e.gps.enabled&&(i+=512),e.interop.enabled&&(i+=100),e.ifd1.enabled&&(i+=1024),i+2048})(s);return s.jfif.enabled&&(t+=50),s.xmp.enabled&&(t+=2e4),s.iptc.enabled&&(t+=14e3),s.icc.enabled&&(t+=6e3),t}var yt=s=>String.fromCharCode.apply(null,s),Nt=typeof TextDecoder<"u"?new TextDecoder("utf-8"):void 0;function Zt(s){return Nt?Nt.decode(s):Ut?Buffer.from(s).toString("utf8"):decodeURIComponent(escape(yt(s)))}var O=class s{static from(t,e){return t instanceof this&&t.le===e?t:new s(t,void 0,void 0,e)}constructor(t,e=0,i,n){if(typeof n=="boolean"&&(this.le=n),Array.isArray(t)&&(t=new Uint8Array(t)),t===0)this.byteOffset=0,this.byteLength=0;else if(t instanceof ArrayBuffer){i===void 0&&(i=t.byteLength-e);let r=new DataView(t,e,i);this._swapDataView(r)}else if(t instanceof Uint8Array||t instanceof DataView||t instanceof s){i===void 0&&(i=t.byteLength-e),(e+=t.byteOffset)+i>t.byteOffset+t.byteLength&&m("Creating view outside of available memory in ArrayBuffer");let r=new DataView(t.buffer,e,i);this._swapDataView(r)}else if(typeof t=="number"){let r=new DataView(new ArrayBuffer(t));this._swapDataView(r)}else m("Invalid input argument for BufferView: "+t)}_swapArrayBuffer(t){this._swapDataView(new DataView(t))}_swapBuffer(t){this._swapDataView(new DataView(t.buffer,t.byteOffset,t.byteLength))}_swapDataView(t){this.dataView=t,this.buffer=t.buffer,this.byteOffset=t.byteOffset,this.byteLength=t.byteLength}_lengthToEnd(t){return this.byteLength-t}set(t,e,i=s){return t instanceof DataView||t instanceof s?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer&&(t=new Uint8Array(t)),t instanceof Uint8Array||m("BufferView.set(): Invalid data argument."),this.toUint8().set(t,e),new i(this,e,t.byteLength)}subarray(t,e){return e=e||this._lengthToEnd(t),new s(this,t,e)}toUint8(){return new Uint8Array(this.buffer,this.byteOffset,this.byteLength)}getUint8Array(t,e){return new Uint8Array(this.buffer,this.byteOffset+t,e)}getString(t=0,e=this.byteLength){return Zt(this.getUint8Array(t,e))}getLatin1String(t=0,e=this.byteLength){let i=this.getUint8Array(t,e);return yt(i)}getUnicodeString(t=0,e=this.byteLength){let i=[];for(let n=0;n<e&&t+n<this.byteLength;n+=2)i.push(this.getUint16(t+n));return yt(i)}getInt8(t){return this.dataView.getInt8(t)}getUint8(t){return this.dataView.getUint8(t)}getInt16(t,e=this.le){return this.dataView.getInt16(t,e)}getInt32(t,e=this.le){return this.dataView.getInt32(t,e)}getUint16(t,e=this.le){return this.dataView.getUint16(t,e)}getUint32(t,e=this.le){return this.dataView.getUint32(t,e)}getFloat32(t,e=this.le){return this.dataView.getFloat32(t,e)}getFloat64(t,e=this.le){return this.dataView.getFloat64(t,e)}getFloat(t,e=this.le){return this.dataView.getFloat32(t,e)}getDouble(t,e=this.le){return this.dataView.getFloat64(t,e)}getUintBytes(t,e,i){switch(e){case 1:return this.getUint8(t,i);case 2:return this.getUint16(t,i);case 4:return this.getUint32(t,i);case 8:return this.getUint64&&this.getUint64(t,i)}}getUint(t,e,i){switch(e){case 8:return this.getUint8(t,i);case 16:return this.getUint16(t,i);case 32:return this.getUint32(t,i);case 64:return this.getUint64&&this.getUint64(t,i)}}toString(t){return this.dataView.toString(t,this.constructor.name)}ensureChunk(){}};function bt(s,t){m(`${s} '${t}' was not loaded, try using full build of exifr.`)}var Z=class extends Map{constructor(t){super(),this.kind=t}get(t,e){return this.has(t)||bt(this.kind,t),e&&(t in e||(function(i,n){m(`Unknown ${i} '${n}'.`)})(this.kind,t),e[t].enabled||bt(this.kind,t)),super.get(t)}keyList(){return Array.from(this.keys())}},V=new Z("file parser"),b=new Z("segment parser"),N=new Z("file reader"),Jt=At.fetch;function Rt(s,t){return(e=s).startsWith("data:")||e.length>1e4?St(s,t,"base64"):zt&&s.includes("://")?wt(s,t,"url",G):zt?St(s,t,"fs"):q?wt(s,t,"url",G):void m("Invalid input argument");var e}async function wt(s,t,e,i){return N.has(e)?St(s,t,e):i?(async function(n,r){let a=await r(n);return new O(a)})(s,i):void m(`Parser ${e} is not loaded`)}async function St(s,t,e){let i=new(N.get(e))(s,t);return await i.read(),i}var G=s=>Jt(s).then((t=>t.arrayBuffer())),H=s=>new Promise(((t,e)=>{let i=new FileReader;i.onloadend=()=>t(i.result||new ArrayBuffer),i.onerror=e,i.readAsArrayBuffer(s)})),kt=class extends Map{get tagKeys(){return this.allKeys||(this.allKeys=Array.from(this.keys())),this.allKeys}get tagValues(){return this.allValues||(this.allValues=Array.from(this.values())),this.allValues}};function k(s,t,e){let i=new kt;for(let[n,r]of e)i.set(n,r);if(Array.isArray(t))for(let n of t)s.set(n,i);else s.set(t,i);return i}function Bt(s,t,e){let i,n=s.get(t);for(i of e)n.set(i[0],i[1])}var C=new Map,$=new Map,z=new Map,F=["chunked","firstChunkSize","firstChunkSizeNode","firstChunkSizeBrowser","chunkSize","chunkLimit"],J=["jfif","xmp","icc","iptc","ihdr"],W=["tiff",...J],p=["ifd0","ifd1","exif","gps","interop"],M=[...W,...p],T=["makerNote","userComment"],Q=["translateKeys","translateValues","reviveValues","multiSegment"],E=[...Q,"sanitize","mergeOutput","silentErrors"],it=class{get translate(){return this.translateKeys||this.translateValues||this.reviveValues}},D=class extends it{get needed(){return this.enabled||this.deps.size>0}constructor(t,e,i,n){if(super(),d(this,"enabled",!1),d(this,"skip",new Set),d(this,"pick",new Set),d(this,"deps",new Set),d(this,"translateKeys",!1),d(this,"translateValues",!1),d(this,"reviveValues",!1),this.key=t,this.enabled=e,this.parse=this.enabled,this.applyInheritables(n),this.canBeFiltered=p.includes(t),this.canBeFiltered&&(this.dict=C.get(t)),i!==void 0)if(Array.isArray(i))this.parse=this.enabled=!0,this.canBeFiltered&&i.length>0&&this.translateTagSet(i,this.pick);else if(typeof i=="object"){if(this.enabled=!0,this.parse=i.parse!==!1,this.canBeFiltered){let{pick:r,skip:a}=i;r&&r.length>0&&this.translateTagSet(r,this.pick),a&&a.length>0&&this.translateTagSet(a,this.skip)}this.applyInheritables(i)}else i===!0||i===!1?this.parse=this.enabled=i:m(`Invalid options argument: ${i}`)}applyInheritables(t){let e,i;for(e of Q)i=t[e],i!==void 0&&(this[e]=i)}translateTagSet(t,e){if(this.dict){let i,n,{tagKeys:r,tagValues:a}=this.dict;for(i of t)typeof i=="string"?(n=a.indexOf(i),n===-1&&(n=r.indexOf(Number(i))),n!==-1&&e.add(Number(r[n]))):e.add(i)}else for(let i of t)e.add(i)}finalizeFilters(){!this.enabled&&this.deps.size>0?(this.enabled=!0,st(this.pick,this.deps)):this.enabled&&this.pick.size>0&&st(this.pick,this.deps)}},y={jfif:!1,tiff:!0,xmp:!1,icc:!1,iptc:!1,ifd0:!0,ifd1:!1,exif:!0,gps:!0,interop:!1,ihdr:void 0,makerNote:!1,userComment:!1,multiSegment:!1,skip:[],pick:[],translateKeys:!0,translateValues:!0,reviveValues:!0,sanitize:!0,mergeOutput:!0,silentErrors:!0,chunked:!0,firstChunkSize:void 0,firstChunkSizeNode:512,firstChunkSizeBrowser:65536,chunkSize:65536,chunkLimit:5},jt=new Map,I=class extends it{static useCached(t){let e=jt.get(t);return e!==void 0||(e=new this(t),jt.set(t,e)),e}constructor(t){super(),t===!0?this.setupFromTrue():t===void 0?this.setupFromUndefined():Array.isArray(t)?this.setupFromArray(t):typeof t=="object"?this.setupFromObject(t):m(`Invalid options argument ${t}`),this.firstChunkSize===void 0&&(this.firstChunkSize=q?this.firstChunkSizeBrowser:this.firstChunkSizeNode),this.mergeOutput&&(this.ifd1.enabled=!1),this.filterNestedSegmentTags(),this.traverseTiffDependencyTree(),this.checkLoadedPlugins()}setupFromUndefined(){let t;for(t of F)this[t]=y[t];for(t of E)this[t]=y[t];for(t of T)this[t]=y[t];for(t of M)this[t]=new D(t,y[t],void 0,this)}setupFromTrue(){let t;for(t of F)this[t]=y[t];for(t of E)this[t]=y[t];for(t of T)this[t]=!0;for(t of M)this[t]=new D(t,!0,void 0,this)}setupFromArray(t){let e;for(e of F)this[e]=y[e];for(e of E)this[e]=y[e];for(e of T)this[e]=y[e];for(e of M)this[e]=new D(e,!1,void 0,this);this.setupGlobalFilters(t,void 0,p)}setupFromObject(t){let e;for(e of(p.ifd0=p.ifd0||p.image,p.ifd1=p.ifd1||p.thumbnail,Object.assign(this,t),F))this[e]=gt(t[e],y[e]);for(e of E)this[e]=gt(t[e],y[e]);for(e of T)this[e]=gt(t[e],y[e]);for(e of W)this[e]=new D(e,y[e],t[e],this);for(e of p)this[e]=new D(e,y[e],t[e],this.tiff);this.setupGlobalFilters(t.pick,t.skip,p,M),t.tiff===!0?this.batchEnableWithBool(p,!0):t.tiff===!1?this.batchEnableWithUserValue(p,t):Array.isArray(t.tiff)?this.setupGlobalFilters(t.tiff,void 0,p):typeof t.tiff=="object"&&this.setupGlobalFilters(t.tiff.pick,t.tiff.skip,p)}batchEnableWithBool(t,e){for(let i of t)this[i].enabled=e}batchEnableWithUserValue(t,e){for(let i of t){let n=e[i];this[i].enabled=n!==!1&&n!==void 0}}setupGlobalFilters(t,e,i,n=i){if(t&&t.length){for(let a of n)this[a].enabled=!1;let r=Gt(t,i);for(let[a,o]of r)st(this[a].pick,o),this[a].enabled=!0}else if(e&&e.length){let r=Gt(e,i);for(let[a,o]of r)st(this[a].skip,o)}}filterNestedSegmentTags(){let{ifd0:t,exif:e,xmp:i,iptc:n,icc:r}=this;this.makerNote?e.deps.add(37500):e.skip.add(37500),this.userComment?e.deps.add(37510):e.skip.add(37510),i.enabled||t.skip.add(700),n.enabled||t.skip.add(33723),r.enabled||t.skip.add(34675)}traverseTiffDependencyTree(){let{ifd0:t,exif:e,gps:i,interop:n}=this;n.needed&&(e.deps.add(40965),t.deps.add(40965)),e.needed&&t.deps.add(34665),i.needed&&t.deps.add(34853),this.tiff.enabled=p.some((r=>this[r].enabled===!0))||this.makerNote||this.userComment;for(let r of p)this[r].finalizeFilters()}get onlyTiff(){return!J.map((t=>this[t].enabled)).some((t=>t===!0))&&this.tiff.enabled}checkLoadedPlugins(){for(let t of W)this[t].enabled&&!b.has(t)&&bt("segment parser",t)}};function Gt(s,t){let e,i,n,r,a=[];for(n of t){for(r of(e=C.get(n),i=[],e))(s.includes(r[0])||s.includes(r[1]))&&i.push(r[0]);i.length&&a.push([n,i])}return a}function gt(s,t){return s!==void 0?s:t!==void 0?t:void 0}function st(s,t){for(let e of t)s.add(e)}d(I,"default",y);var P=class{constructor(t){d(this,"parsers",{}),d(this,"output",{}),d(this,"errors",[]),d(this,"pushToErrors",(e=>this.errors.push(e))),this.options=I.useCached(t)}async read(t){this.file=await(function(e,i){return typeof e=="string"?Rt(e,i):q&&!me&&e instanceof HTMLImageElement?Rt(e.src,i):e instanceof Uint8Array||e instanceof ArrayBuffer||e instanceof DataView?new O(e):q&&e instanceof Blob?wt(e,i,"blob",H):void m("Invalid input argument")})(t,this.options)}setup(){if(this.fileParser)return;let{file:t}=this,e=t.getUint16(0);for(let[i,n]of V)if(n.canHandle(t,e))return this.fileParser=new n(this.options,this.file,this.parsers),t[i]=!0;this.file.close&&this.file.close(),m("Unknown file format")}async parse(){let{output:t,errors:e}=this;return this.setup(),this.options.silentErrors?(await this.executeParsers().catch(this.pushToErrors),e.push(...this.fileParser.errors)):await this.executeParsers(),this.file.close&&this.file.close(),this.options.silentErrors&&e.length>0&&(t.errors=e),et(t)}async executeParsers(){let{output:t}=this;await this.fileParser.parse();let e=Object.values(this.parsers).map((async i=>{let n=await i.parse();i.assignToOutput(t,n)}));this.options.silentErrors&&(e=e.map((i=>i.catch(this.pushToErrors)))),await Promise.all(e)}async extractThumbnail(){this.setup();let{options:t,file:e}=this,i=b.get("tiff",t);var n;if(e.tiff?n={start:0,type:"tiff"}:e.jpeg&&(n=await this.fileParser.getOrFindSegment("tiff")),n===void 0)return;let r=await this.fileParser.ensureSegmentChunk(n),a=this.parsers.tiff=new i(r,t,e),o=await a.extractThumbnail();return e.close&&e.close(),o}};async function Lt(s,t){let e=new P(t);return await e.read(s),e.parse()}var be=Object.freeze({__proto__:null,parse:Lt,Exifr:P,fileParsers:V,segmentParsers:b,fileReaders:N,tagKeys:C,tagValues:$,tagRevivers:z,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:F,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:M,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I}),nt=class{constructor(t,e,i){d(this,"errors",[]),d(this,"ensureSegmentChunk",(async n=>{let r=n.start,a=n.size||65536;if(this.file.chunked)if(this.file.available(r,a))n.chunk=this.file.subarray(r,a);else try{n.chunk=await this.file.readChunk(r,a)}catch(o){m(`Couldn't read segment: ${JSON.stringify(n)}. ${o.message}`)}else this.file.byteLength>r+a?n.chunk=this.file.subarray(r,a):n.size===void 0?n.chunk=this.file.subarray(r):m("Segment unreachable: "+JSON.stringify(n));return n.chunk})),this.extendOptions&&this.extendOptions(t),this.options=t,this.file=e,this.parsers=i}injectSegment(t,e){this.options[t].enabled&&this.createParser(t,e)}createParser(t,e){let i=new(b.get(t))(e,this.options,this.file);return this.parsers[t]=i}createParsers(t){for(let e of t){let{type:i,chunk:n}=e,r=this.options[i];if(r&&r.enabled){let a=this.parsers[i];a&&a.append||a||this.createParser(i,n)}}}async readSegments(t){let e=t.map(this.ensureSegmentChunk);await Promise.all(e)}},v=class{static findPosition(t,e){let i=t.getUint16(e+2)+2,n=typeof this.headerLength=="function"?this.headerLength(t,e,i):this.headerLength,r=e+n,a=i-n;return{offset:e,length:i,headerLength:n,start:r,size:a,end:r+a}}static parse(t,e={}){return new this(t,new I({[this.type]:e}),t).parse()}normalizeInput(t){return t instanceof O?t:new O(t)}constructor(t,e={},i){d(this,"errors",[]),d(this,"raw",new Map),d(this,"handleError",(n=>{if(!this.options.silentErrors)throw n;this.errors.push(n.message)})),this.chunk=this.normalizeInput(t),this.file=i,this.type=this.constructor.type,this.globalOptions=this.options=e,this.localOptions=e[this.type],this.canTranslate=this.localOptions&&this.localOptions.translate}translate(){this.canTranslate&&(this.translated=this.translateBlock(this.raw,this.type))}get output(){return this.translated?this.translated:this.raw?Object.fromEntries(this.raw):void 0}translateBlock(t,e){let i=z.get(e),n=$.get(e),r=C.get(e),a=this.options[e],o=a.reviveValues&&!!i,h=a.translateValues&&!!n,l=a.translateKeys&&!!r,f={};for(let[u,c]of t)o&&i.has(u)?c=i.get(u)(c):h&&n.has(u)&&(c=this.translateValue(c,n.get(u))),l&&r.has(u)&&(u=r.get(u)||u),f[u]=c;return f}translateValue(t,e){return e[t]||e.DEFAULT||t}assignToOutput(t,e){this.assignObjectToOutput(t,this.constructor.type,e)}assignObjectToOutput(t,e,i){if(this.globalOptions.mergeOutput)return Object.assign(t,i);t[e]?Object.assign(t[e],i):t[e]=i}};d(v,"headerLength",4),d(v,"type",void 0),d(v,"multiSegment",!1),d(v,"canHandle",(()=>!1));function we(s){return s===192||s===194||s===196||s===219||s===221||s===218||s===254}function Se(s){return s>=224&&s<=239}function ke(s,t,e){for(let[i,n]of b)if(n.canHandle(s,t,e))return i}var rt=class extends nt{constructor(...t){super(...t),d(this,"appSegments",[]),d(this,"jpegSegments",[]),d(this,"unknownSegments",[])}static canHandle(t,e){return e===65496}async parse(){await this.findAppSegments(),await this.readSegments(this.appSegments),this.mergeMultiSegments(),this.createParsers(this.mergedAppSegments||this.appSegments)}setupSegmentFinderArgs(t){t===!0?(this.findAll=!0,this.wanted=new Set(b.keyList())):(t=t===void 0?b.keyList().filter((e=>this.options[e].enabled)):t.filter((e=>this.options[e].enabled&&b.has(e))),this.findAll=!1,this.remaining=new Set(t),this.wanted=new Set(t)),this.unfinishedMultiSegment=!1}async findAppSegments(t=0,e){this.setupSegmentFinderArgs(e);let{file:i,findAll:n,wanted:r,remaining:a}=this;if(!n&&this.file.chunked&&(n=Array.from(r).some((o=>{let h=b.get(o),l=this.options[o];return h.multiSegment&&l.multiSegment})),n&&await this.file.readWhole()),t=this.findAppSegmentsInRange(t,i.byteLength),!this.options.onlyTiff&&i.chunked){let o=!1;for(;a.size>0&&!o&&(i.canReadNextChunk||this.unfinishedMultiSegment);){let{nextChunkOffset:h}=i,l=this.appSegments.some((f=>!this.file.available(f.offset||f.start,f.length||f.size)));if(o=t>h&&!l?!await i.readNextChunk(t):!await i.readNextChunk(h),(t=this.findAppSegmentsInRange(t,i.byteLength))===void 0)return}}}findAppSegmentsInRange(t,e){e-=2;let i,n,r,a,o,h,{file:l,findAll:f,wanted:u,remaining:c,options:g}=this;for(;t<e;t++)if(l.getUint8(t)===255){if(i=l.getUint8(t+1),Se(i)){if(n=l.getUint16(t+2),r=ke(l,t,n),r&&u.has(r)&&(a=b.get(r),o=a.findPosition(l,t),h=g[r],o.type=r,this.appSegments.push(o),!f&&(a.multiSegment&&h.multiSegment?(this.unfinishedMultiSegment=o.chunkNumber<o.chunkCount,this.unfinishedMultiSegment||c.delete(r)):c.delete(r),c.size===0)))break;g.recordUnknownSegments&&(o=v.findPosition(l,t),o.marker=i,this.unknownSegments.push(o)),t+=n+1}else if(we(i)){if(n=l.getUint16(t+2),i===218&&g.stopAfterSos!==!1)return;g.recordJpegSegments&&this.jpegSegments.push({offset:t,length:n,marker:i}),t+=n+1}}return t}mergeMultiSegments(){if(!this.appSegments.some((e=>e.multiSegment)))return;let t=(function(e,i){let n,r,a,o=new Map;for(let h=0;h<e.length;h++)n=e[h],r=n[i],o.has(r)?a=o.get(r):o.set(r,a=[]),a.push(n);return Array.from(o)})(this.appSegments,"type");this.mergedAppSegments=t.map((([e,i])=>{let n=b.get(e,this.options);return n.handleMultiSegments?{type:e,chunk:n.handleMultiSegments(i)}:i[0]}))}getSegment(t){return this.appSegments.find((e=>e.type===t))}async getOrFindSegment(t){let e=this.getSegment(t);return e===void 0&&(await this.findAppSegments(0,[t]),e=this.getSegment(t)),e}};d(rt,"type","jpeg"),V.set("jpeg",rt);var xe=[void 0,1,1,2,4,8,1,1,2,4,8,4,8,4],xt=class extends v{parseHeader(){var t=this.chunk.getUint16();t===18761?this.le=!0:t===19789&&(this.le=!1),this.chunk.le=this.le,this.headerParsed=!0}parseTags(t,e,i=new Map){let{pick:n,skip:r}=this.options[e];n=new Set(n);let a=n.size>0,o=r.size===0,h=this.chunk.getUint16(t);t+=2;for(let l=0;l<h;l++){let f=this.chunk.getUint16(t);if(a){if(n.has(f)&&(i.set(f,this.parseTag(t,f,e)),n.delete(f),n.size===0))break}else!o&&r.has(f)||i.set(f,this.parseTag(t,f,e));t+=12}return i}parseTag(t,e,i){let{chunk:n}=this,r=n.getUint16(t+2),a=n.getUint32(t+4),o=xe[r];if(o*a<=4?t+=8:t=n.getUint32(t+8),(r<1||r>13)&&m(`Invalid TIFF value type. block: ${i.toUpperCase()}, tag: ${e.toString(16)}, type: ${r}, offset ${t}`),t>n.byteLength&&m(`Invalid TIFF value offset. block: ${i.toUpperCase()}, tag: ${e.toString(16)}, type: ${r}, offset ${t} is outside of chunk size ${n.byteLength}`),r===1)return n.getUint8Array(t,a);if(r===2)return qt(n.getString(t,a));if(r===7)return n.getUint8Array(t,a);if(a===1)return this.parseTagValue(r,t);{let h=new((function(f){switch(f){case 1:return Uint8Array;case 3:return Uint16Array;case 4:return Uint32Array;case 5:return Array;case 6:return Int8Array;case 8:return Int16Array;case 9:return Int32Array;case 10:return Array;case 11:return Float32Array;case 12:return Float64Array;default:return Array}})(r))(a),l=o;for(let f=0;f<a;f++)h[f]=this.parseTagValue(r,t),t+=l;return h}}parseTagValue(t,e){let{chunk:i}=this;switch(t){case 1:return i.getUint8(e);case 3:return i.getUint16(e);case 4:return i.getUint32(e);case 5:return i.getUint32(e)/i.getUint32(e+4);case 6:return i.getInt8(e);case 8:return i.getInt16(e);case 9:return i.getInt32(e);case 10:return i.getInt32(e)/i.getInt32(e+4);case 11:return i.getFloat(e);case 12:return i.getDouble(e);case 13:return i.getUint32(e);default:m(`Invalid tiff type ${t}`)}}},X=class extends xt{static canHandle(t,e){return t.getUint8(e+1)===225&&t.getUint32(e+4)===1165519206&&t.getUint16(e+8)===0}async parse(){this.parseHeader();let{options:t}=this;return t.ifd0.enabled&&await this.parseIfd0Block(),t.exif.enabled&&await this.safeParse("parseExifBlock"),t.gps.enabled&&await this.safeParse("parseGpsBlock"),t.interop.enabled&&await this.safeParse("parseInteropBlock"),t.ifd1.enabled&&await this.safeParse("parseThumbnailBlock"),this.createOutput()}safeParse(t){let e=this[t]();return e.catch!==void 0&&(e=e.catch(this.handleError)),e}findIfd0Offset(){this.ifd0Offset===void 0&&(this.ifd0Offset=this.chunk.getUint32(4))}findIfd1Offset(){if(this.ifd1Offset===void 0){this.findIfd0Offset();let t=this.chunk.getUint16(this.ifd0Offset),e=this.ifd0Offset+2+12*t;this.ifd1Offset=this.chunk.getUint32(e)}}parseBlock(t,e){let i=new Map;return this[e]=i,this.parseTags(t,e,i),i}async parseIfd0Block(){if(this.ifd0)return;let{file:t}=this;this.findIfd0Offset(),this.ifd0Offset<8&&m("Malformed EXIF data"),!t.chunked&&this.ifd0Offset>t.byteLength&&m(`IFD0 offset points to outside of file.
|
|
2
|
-
this.ifd0Offset: ${this.ifd0Offset}, file.byteLength: ${t.byteLength}`),t.tiff&&await t.ensureChunk(this.ifd0Offset,Vt(this.options));let e=this.parseBlock(this.ifd0Offset,"ifd0");return e.size!==0?(this.exifOffset=e.get(34665),this.interopOffset=e.get(40965),this.gpsOffset=e.get(34853),this.xmp=e.get(700),this.iptc=e.get(33723),this.icc=e.get(34675),this.options.sanitize&&(e.delete(34665),e.delete(40965),e.delete(34853),e.delete(700),e.delete(33723),e.delete(34675)),e):void 0}async parseExifBlock(){if(this.exif||(this.ifd0||await this.parseIfd0Block(),this.exifOffset===void 0))return;this.file.tiff&&await this.file.ensureChunk(this.exifOffset,Vt(this.options));let t=this.parseBlock(this.exifOffset,"exif");return this.interopOffset||(this.interopOffset=t.get(40965)),this.makerNote=t.get(37500),this.userComment=t.get(37510),this.options.sanitize&&(t.delete(40965),t.delete(37500),t.delete(37510)),this.unpack(t,41728),this.unpack(t,41729),t}unpack(t,e){let i=t.get(e);i&&i.length===1&&t.set(e,i[0])}async parseGpsBlock(){if(this.gps||(this.ifd0||await this.parseIfd0Block(),this.gpsOffset===void 0))return;let t=this.parseBlock(this.gpsOffset,"gps");return t&&t.has(2)&&t.has(4)&&(t.set("latitude",Ht(...t.get(2),t.get(1))),t.set("longitude",Ht(...t.get(4),t.get(3)))),t}async parseInteropBlock(){if(!this.interop&&(this.ifd0||await this.parseIfd0Block(),this.interopOffset!==void 0||this.exif||await this.parseExifBlock(),this.interopOffset!==void 0))return this.parseBlock(this.interopOffset,"interop")}async parseThumbnailBlock(t=!1){if(!this.ifd1&&!this.ifd1Parsed&&(!this.options.mergeOutput||t))return this.findIfd1Offset(),this.ifd1Offset>0&&(this.parseBlock(this.ifd1Offset,"ifd1"),this.ifd1Parsed=!0),this.ifd1}async extractThumbnail(){if(this.headerParsed||this.parseHeader(),this.ifd1Parsed||await this.parseThumbnailBlock(!0),this.ifd1===void 0)return;let t=this.ifd1.get(513),e=this.ifd1.get(514);return this.chunk.getUint8Array(t,e)}get image(){return this.ifd0}get thumbnail(){return this.ifd1}createOutput(){let t,e,i,n={};for(e of p)if(t=this[e],!Yt(t))if(i=this.canTranslate?this.translateBlock(t,e):Object.fromEntries(t),this.options.mergeOutput){if(e==="ifd1")continue;Object.assign(n,i)}else n[e]=i;return this.makerNote&&(n.makerNote=this.makerNote),this.userComment&&(n.userComment=this.userComment),n}assignToOutput(t,e){if(this.globalOptions.mergeOutput)Object.assign(t,e);else for(let[i,n]of Object.entries(e))this.assignObjectToOutput(t,i,n)}};function Ht(s,t,e,i){var n=s+t/60+e/3600;return i!=="S"&&i!=="W"||(n*=-1),n}d(X,"type","tiff"),d(X,"headerLength",10),b.set("tiff",X);var ve=Object.freeze({__proto__:null,default:be,Exifr:P,fileParsers:V,segmentParsers:b,fileReaders:N,tagKeys:C,tagValues:$,tagRevivers:z,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:F,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:M,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I,parse:Lt}),Dt={ifd0:!1,ifd1:!1,exif:!1,gps:!1,interop:!1,sanitize:!1,reviveValues:!0,translateKeys:!1,translateValues:!1,mergeOutput:!1},Qt=Object.assign({},Dt,{firstChunkSize:4e4,gps:[1,2,3,4]});async function Ce(s){let t=new P(Qt);await t.read(s);let e=await t.parse();if(e&&e.gps){let{latitude:i,longitude:n}=e.gps;return{latitude:i,longitude:n}}}var te=Object.assign({},Dt,{tiff:!1,ifd1:!0,mergeOutput:!1});async function Oe(s){let t=new P(te);await t.read(s);let e=await t.extractThumbnail();return e&&Ut?It.from(e):e}async function Pe(s){let t=await this.thumbnail(s);if(t!==void 0){let e=new Blob([t]);return URL.createObjectURL(e)}}var ee=Object.assign({},Dt,{firstChunkSize:4e4,ifd0:[274]});async function ie(s){let t=new P(ee);await t.read(s);let e=await t.parse();if(e&&e.ifd0)return e.ifd0[274]}var se=Object.freeze({1:{dimensionSwapped:!1,scaleX:1,scaleY:1,deg:0,rad:0},2:{dimensionSwapped:!1,scaleX:-1,scaleY:1,deg:0,rad:0},3:{dimensionSwapped:!1,scaleX:1,scaleY:1,deg:180,rad:180*Math.PI/180},4:{dimensionSwapped:!1,scaleX:-1,scaleY:1,deg:180,rad:180*Math.PI/180},5:{dimensionSwapped:!0,scaleX:1,scaleY:-1,deg:90,rad:90*Math.PI/180},6:{dimensionSwapped:!0,scaleX:1,scaleY:1,deg:90,rad:90*Math.PI/180},7:{dimensionSwapped:!0,scaleX:1,scaleY:-1,deg:270,rad:270*Math.PI/180},8:{dimensionSwapped:!0,scaleX:1,scaleY:1,deg:270,rad:270*Math.PI/180}}),R=!0,j=!0;if(typeof navigator=="object"){let s=navigator.userAgent;if(s.includes("iPad")||s.includes("iPhone")){let t=s.match(/OS (\d+)_(\d+)/);if(t){let[,e,i]=t;R=Number(e)+.1*Number(i)<13.4,j=!1}}else if(s.includes("OS X 10")){let[,t]=s.match(/OS X 10[_.](\d+)/);R=j=Number(t)<15}if(s.includes("Chrome/")){let[,t]=s.match(/Chrome\/(\d+)/);R=j=Number(t)<81}else if(s.includes("Firefox/")){let[,t]=s.match(/Firefox\/(\d+)/);R=j=Number(t)<77}}async function Ae(s){let t=await ie(s);return Object.assign({canvas:R,css:j},se[t])}var vt=class extends O{constructor(...t){super(...t),d(this,"ranges",new Ct),this.byteLength!==0&&this.ranges.add(0,this.byteLength)}_tryExtend(t,e,i){if(t===0&&this.byteLength===0&&i){let n=new DataView(i.buffer||i,i.byteOffset,i.byteLength);this._swapDataView(n)}else{let n=t+e;if(n>this.byteLength){let{dataView:r}=this._extend(n);this._swapDataView(r)}}}_extend(t){let e;e=Ut?It.allocUnsafe(t):new Uint8Array(t);let i=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.set(new Uint8Array(this.buffer,this.byteOffset,this.byteLength),0),{uintView:e,dataView:i}}subarray(t,e,i=!1){return e=e||this._lengthToEnd(t),i&&this._tryExtend(t,e),this.ranges.add(t,e),super.subarray(t,e)}set(t,e,i=!1){i&&this._tryExtend(e,t.byteLength,t);let n=super.set(t,e);return this.ranges.add(e,n.byteLength),n}async ensureChunk(t,e){this.chunked&&(this.ranges.available(t,e)||await this.readChunk(t,e))}available(t,e){return this.ranges.available(t,e)}},Ct=class{constructor(){d(this,"list",[])}get length(){return this.list.length}add(t,e,i=0){let n=t+e,r=this.list.filter((a=>Wt(t,a.offset,n)||Wt(t,a.end,n)));if(r.length>0){t=Math.min(t,...r.map((o=>o.offset))),n=Math.max(n,...r.map((o=>o.end))),e=n-t;let a=r.shift();a.offset=t,a.length=e,a.end=n,this.list=this.list.filter((o=>!r.includes(o)))}else this.list.push({offset:t,length:e,end:n})}available(t,e){let i=t+e;return this.list.some((n=>n.offset<=t&&i<=n.end))}};function Wt(s,t,e){return s<=t&&t<=e}var at=class extends vt{constructor(t,e){super(0),d(this,"chunksRead",0),this.input=t,this.options=e}async readWhole(){this.chunked=!1,await this.readChunk(this.nextChunkOffset)}async readChunked(){this.chunked=!0,await this.readChunk(0,this.options.firstChunkSize)}async readNextChunk(t=this.nextChunkOffset){if(this.fullyRead)return this.chunksRead++,!1;let e=this.options.chunkSize,i=await this.readChunk(t,e);return!!i&&i.byteLength===e}async readChunk(t,e){if(this.chunksRead++,(e=this.safeWrapAddress(t,e))!==0)return this._readChunk(t,e)}safeWrapAddress(t,e){return this.size!==void 0&&t+e>this.size?Math.max(0,this.size-t):e}get nextChunkOffset(){if(this.ranges.list.length!==0)return this.ranges.list[0].length}get canReadNextChunk(){return this.chunksRead<this.options.chunkLimit}get fullyRead(){return this.size!==void 0&&this.nextChunkOffset===this.size}read(){return this.options.chunked?this.readChunked():this.readWhole()}close(){}};N.set("blob",class extends at{async readWhole(){this.chunked=!1;let s=await H(this.input);this._swapArrayBuffer(s)}readChunked(){return this.chunked=!0,this.size=this.input.size,super.readChunked()}async _readChunk(s,t){let e=t?s+t:void 0,i=this.input.slice(s,e),n=await H(i);return this.set(n,s,!0)}});var Ie=Object.freeze({__proto__:null,default:ve,Exifr:P,fileParsers:V,segmentParsers:b,fileReaders:N,tagKeys:C,tagValues:$,tagRevivers:z,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:F,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:M,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I,parse:Lt,gpsOnlyOptions:Qt,gps:Ce,thumbnailOnlyOptions:te,thumbnail:Oe,thumbnailUrl:Pe,orientationOnlyOptions:ee,orientation:ie,rotations:se,get rotateCanvas(){return R},get rotateCss(){return j},rotation:Ae});N.set("url",class extends at{async readWhole(){this.chunked=!1;let s=await G(this.input);s instanceof ArrayBuffer?this._swapArrayBuffer(s):s instanceof Uint8Array&&this._swapBuffer(s)}async _readChunk(s,t){let e=t?s+t-1:void 0,i=this.options.httpHeaders||{};(s||e)&&(i.range=`bytes=${[s,e].join("-")}`);let n=await Jt(this.input,{headers:i}),r=await n.arrayBuffer(),a=r.byteLength;if(n.status!==416)return a!==t&&(this.size=s+a),this.set(r,s,!0)}});O.prototype.getUint64=function(s){let t=this.getUint32(s),e=this.getUint32(s+4);return t<1048575?t<<32|e:typeof tt!==void 0?(console.warn("Using BigInt because of type 64uint but JS can only handle 53b numbers."),tt(t)<<tt(32)|tt(e)):void m("Trying to read 64b value but JS can only handle 53b numbers.")};var Ot=class extends nt{parseBoxes(t=0){let e=[];for(;t<this.file.byteLength-4;){let i=this.parseBoxHead(t);if(e.push(i),i.length===0)break;t+=i.length}return e}parseSubBoxes(t){t.boxes=this.parseBoxes(t.start)}findBox(t,e){return t.boxes===void 0&&this.parseSubBoxes(t),t.boxes.find((i=>i.kind===e))}parseBoxHead(t){let e=this.file.getUint32(t),i=this.file.getString(t+4,4),n=t+8;return e===1&&(e=this.file.getUint64(t+8),n+=8),{offset:t,length:e,kind:i,start:n}}parseBoxFullHead(t){if(t.version!==void 0)return;let e=this.file.getUint32(t.start);t.version=e>>24,t.start+=4}},ot=class extends Ot{static canHandle(t,e){if(e!==0)return!1;let i=t.getUint16(2);if(i>50)return!1;let n=16,r=[];for(;n<i;)r.push(t.getString(n,4)),n+=4;return r.includes(this.type)}async parse(){let t=this.file.getUint32(0),e=this.parseBoxHead(t);for(;e.kind!=="meta";)t+=e.length,await this.file.ensureChunk(t,16),e=this.parseBoxHead(t);await this.file.ensureChunk(e.offset,e.length),this.parseBoxFullHead(e),this.parseSubBoxes(e),this.options.icc.enabled&&await this.findIcc(e),this.options.tiff.enabled&&await this.findExif(e)}async registerSegment(t,e,i){await this.file.ensureChunk(e,i);let n=this.file.subarray(e,i);this.createParser(t,n)}async findIcc(t){let e=this.findBox(t,"iprp");if(e===void 0)return;let i=this.findBox(e,"ipco");if(i===void 0)return;let n=this.findBox(i,"colr");n!==void 0&&await this.registerSegment("icc",n.offset+12,n.length)}async findExif(t){let e=this.findBox(t,"iinf");if(e===void 0)return;let i=this.findBox(t,"iloc");if(i===void 0)return;let n=this.findExifLocIdInIinf(e),r=this.findExtentInIloc(i,n);if(r===void 0)return;let[a,o]=r;await this.file.ensureChunk(a,o);let h=4+this.file.getUint32(a);a+=h,o-=h,await this.registerSegment("tiff",a,o)}findExifLocIdInIinf(t){this.parseBoxFullHead(t);let e,i,n,r,a=t.start,o=this.file.getUint16(a);for(a+=2;o--;){if(e=this.parseBoxHead(a),this.parseBoxFullHead(e),i=e.start,e.version>=2&&(n=e.version===3?4:2,r=this.file.getString(i+n+2,4),r==="Exif"))return this.file.getUintBytes(i,n);a+=e.length}}get8bits(t){let e=this.file.getUint8(t);return[e>>4,15&e]}findExtentInIloc(t,e){this.parseBoxFullHead(t);let i=t.start,[n,r]=this.get8bits(i++),[a,o]=this.get8bits(i++),h=t.version===2?4:2,l=t.version===1||t.version===2?2:0,f=o+n+r,u=t.version===2?4:2,c=this.file.getUintBytes(i,u);for(i+=u;c--;){let g=this.file.getUintBytes(i,h);i+=h+l+2+a;let S=this.file.getUint16(i);if(i+=2,g===e)return S>1&&console.warn(`ILOC box has more than one extent but we're only processing one
|
|
3
|
-
Please create an issue at https://github.com/MikeKovarik/exifr with this file`),[this.file.getUintBytes(i+o,n),this.file.getUintBytes(i+o+n,r)];i+=S*f}}},ht=class extends ot{};d(ht,"type","heic");var lt=class extends ot{};d(lt,"type","avif"),V.set("heic",ht),V.set("avif",lt),k(C,["ifd0","ifd1"],[[256,"ImageWidth"],[257,"ImageHeight"],[258,"BitsPerSample"],[259,"Compression"],[262,"PhotometricInterpretation"],[270,"ImageDescription"],[271,"Make"],[272,"Model"],[273,"StripOffsets"],[274,"Orientation"],[277,"SamplesPerPixel"],[278,"RowsPerStrip"],[279,"StripByteCounts"],[282,"XResolution"],[283,"YResolution"],[284,"PlanarConfiguration"],[296,"ResolutionUnit"],[301,"TransferFunction"],[305,"Software"],[306,"ModifyDate"],[315,"Artist"],[316,"HostComputer"],[317,"Predictor"],[318,"WhitePoint"],[319,"PrimaryChromaticities"],[513,"ThumbnailOffset"],[514,"ThumbnailLength"],[529,"YCbCrCoefficients"],[530,"YCbCrSubSampling"],[531,"YCbCrPositioning"],[532,"ReferenceBlackWhite"],[700,"ApplicationNotes"],[33432,"Copyright"],[33723,"IPTC"],[34665,"ExifIFD"],[34675,"ICC"],[34853,"GpsIFD"],[330,"SubIFD"],[40965,"InteropIFD"],[40091,"XPTitle"],[40092,"XPComment"],[40093,"XPAuthor"],[40094,"XPKeywords"],[40095,"XPSubject"]]),k(C,"exif",[[33434,"ExposureTime"],[33437,"FNumber"],[34850,"ExposureProgram"],[34852,"SpectralSensitivity"],[34855,"ISO"],[34858,"TimeZoneOffset"],[34859,"SelfTimerMode"],[34864,"SensitivityType"],[34865,"StandardOutputSensitivity"],[34866,"RecommendedExposureIndex"],[34867,"ISOSpeed"],[34868,"ISOSpeedLatitudeyyy"],[34869,"ISOSpeedLatitudezzz"],[36864,"ExifVersion"],[36867,"DateTimeOriginal"],[36868,"CreateDate"],[36873,"GooglePlusUploadCode"],[36880,"OffsetTime"],[36881,"OffsetTimeOriginal"],[36882,"OffsetTimeDigitized"],[37121,"ComponentsConfiguration"],[37122,"CompressedBitsPerPixel"],[37377,"ShutterSpeedValue"],[37378,"ApertureValue"],[37379,"BrightnessValue"],[37380,"ExposureCompensation"],[37381,"MaxApertureValue"],[37382,"SubjectDistance"],[37383,"MeteringMode"],[37384,"LightSource"],[37385,"Flash"],[37386,"FocalLength"],[37393,"ImageNumber"],[37394,"SecurityClassification"],[37395,"ImageHistory"],[37396,"SubjectArea"],[37500,"MakerNote"],[37510,"UserComment"],[37520,"SubSecTime"],[37521,"SubSecTimeOriginal"],[37522,"SubSecTimeDigitized"],[37888,"AmbientTemperature"],[37889,"Humidity"],[37890,"Pressure"],[37891,"WaterDepth"],[37892,"Acceleration"],[37893,"CameraElevationAngle"],[40960,"FlashpixVersion"],[40961,"ColorSpace"],[40962,"ExifImageWidth"],[40963,"ExifImageHeight"],[40964,"RelatedSoundFile"],[41483,"FlashEnergy"],[41486,"FocalPlaneXResolution"],[41487,"FocalPlaneYResolution"],[41488,"FocalPlaneResolutionUnit"],[41492,"SubjectLocation"],[41493,"ExposureIndex"],[41495,"SensingMethod"],[41728,"FileSource"],[41729,"SceneType"],[41730,"CFAPattern"],[41985,"CustomRendered"],[41986,"ExposureMode"],[41987,"WhiteBalance"],[41988,"DigitalZoomRatio"],[41989,"FocalLengthIn35mmFormat"],[41990,"SceneCaptureType"],[41991,"GainControl"],[41992,"Contrast"],[41993,"Saturation"],[41994,"Sharpness"],[41996,"SubjectDistanceRange"],[42016,"ImageUniqueID"],[42032,"OwnerName"],[42033,"SerialNumber"],[42034,"LensInfo"],[42035,"LensMake"],[42036,"LensModel"],[42037,"LensSerialNumber"],[42080,"CompositeImage"],[42081,"CompositeImageCount"],[42082,"CompositeImageExposureTimes"],[42240,"Gamma"],[59932,"Padding"],[59933,"OffsetSchema"],[65e3,"OwnerName"],[65001,"SerialNumber"],[65002,"Lens"],[65100,"RawFile"],[65101,"Converter"],[65102,"WhiteBalance"],[65105,"Exposure"],[65106,"Shadows"],[65107,"Brightness"],[65108,"Contrast"],[65109,"Saturation"],[65110,"Sharpness"],[65111,"Smoothness"],[65112,"MoireFilter"],[40965,"InteropIFD"]]),k(C,"gps",[[0,"GPSVersionID"],[1,"GPSLatitudeRef"],[2,"GPSLatitude"],[3,"GPSLongitudeRef"],[4,"GPSLongitude"],[5,"GPSAltitudeRef"],[6,"GPSAltitude"],[7,"GPSTimeStamp"],[8,"GPSSatellites"],[9,"GPSStatus"],[10,"GPSMeasureMode"],[11,"GPSDOP"],[12,"GPSSpeedRef"],[13,"GPSSpeed"],[14,"GPSTrackRef"],[15,"GPSTrack"],[16,"GPSImgDirectionRef"],[17,"GPSImgDirection"],[18,"GPSMapDatum"],[19,"GPSDestLatitudeRef"],[20,"GPSDestLatitude"],[21,"GPSDestLongitudeRef"],[22,"GPSDestLongitude"],[23,"GPSDestBearingRef"],[24,"GPSDestBearing"],[25,"GPSDestDistanceRef"],[26,"GPSDestDistance"],[27,"GPSProcessingMethod"],[28,"GPSAreaInformation"],[29,"GPSDateStamp"],[30,"GPSDifferential"],[31,"GPSHPositioningError"]]),k($,["ifd0","ifd1"],[[274,{1:"Horizontal (normal)",2:"Mirror horizontal",3:"Rotate 180",4:"Mirror vertical",5:"Mirror horizontal and rotate 270 CW",6:"Rotate 90 CW",7:"Mirror horizontal and rotate 90 CW",8:"Rotate 270 CW"}],[296,{1:"None",2:"inches",3:"cm"}]]);var K=k($,"exif",[[34850,{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"}],[37121,{0:"-",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}],[37383,{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"}],[37384,{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"}],[37385,{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"}],[41495,{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"}],[41728,{1:"Film Scanner",2:"Reflection Print Scanner",3:"Digital Camera"}],[41729,{1:"Directly photographed"}],[41985,{0:"Normal",1:"Custom",2:"HDR (no original saved)",3:"HDR (original saved)",4:"Original (for HDR)",6:"Panorama",7:"Portrait HDR",8:"Portrait"}],[41986,{0:"Auto",1:"Manual",2:"Auto bracket"}],[41987,{0:"Auto",1:"Manual"}],[41990,{0:"Standard",1:"Landscape",2:"Portrait",3:"Night",4:"Other"}],[41991,{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"}],[41996,{0:"Unknown",1:"Macro",2:"Close",3:"Distant"}],[42080,{0:"Unknown",1:"Not a Composite Image",2:"General Composite Image",3:"Composite Image Captured While Shooting"}]]),$t={1:"No absolute unit of measurement",2:"Inch",3:"Centimeter"};K.set(37392,$t),K.set(41488,$t);var pt={0:"Normal",1:"Low",2:"High"};function _t(s){return typeof s=="object"&&s.length!==void 0?s[0]:s}function Xt(s){let t=Array.from(s).slice(1);return t[1]>15&&(t=t.map((e=>String.fromCharCode(e)))),t[2]!=="0"&&t[2]!==0||t.pop(),t.join(".")}function mt(s){if(typeof s=="string"){var[t,e,i,n,r,a]=s.trim().split(/[-: ]/g).map(Number),o=new Date(t,e-1,i);return Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(a)||(o.setHours(n),o.setMinutes(r),o.setSeconds(a)),Number.isNaN(+o)?s:o}}function _(s){if(typeof s=="string")return s;let t=[];if(s[1]===0&&s[s.length-1]===0)for(let e=0;e<s.length;e+=2)t.push(Kt(s[e+1],s[e]));else for(let e=0;e<s.length;e+=2)t.push(Kt(s[e],s[e+1]));return qt(String.fromCodePoint(...t))}function Kt(s,t){return s<<8|t}K.set(41992,pt),K.set(41993,pt),K.set(41994,pt),k(z,["ifd0","ifd1"],[[50827,function(s){return typeof s!="string"?Zt(s):s}],[306,mt],[40091,_],[40092,_],[40093,_],[40094,_],[40095,_]]),k(z,"exif",[[40960,Xt],[36864,Xt],[36867,mt],[36868,mt],[40962,_t],[40963,_t]]),k(z,"gps",[[0,s=>Array.from(s).join(".")],[7,s=>Array.from(s).join(":")]]);var Y=class extends v{static canHandle(t,e){return t.getUint8(e+1)===225&&t.getUint32(e+4)===1752462448&&t.getString(e+4,20)==="http://ns.adobe.com/"}static headerLength(t,e){return t.getString(e+4,34)==="http://ns.adobe.com/xmp/extension/"?79:33}static findPosition(t,e){let i=super.findPosition(t,e);return i.multiSegment=i.extended=i.headerLength===79,i.multiSegment?(i.chunkCount=t.getUint8(e+72),i.chunkNumber=t.getUint8(e+76),t.getUint8(e+77)!==0&&i.chunkNumber++):(i.chunkCount=1/0,i.chunkNumber=-1),i}static handleMultiSegments(t){return t.map((e=>e.chunk.getString())).join("")}normalizeInput(t){return typeof t=="string"?t:O.from(t).getString()}parse(t=this.chunk){if(!this.localOptions.parse)return t;t=(function(r){let a={},o={};for(let h of oe)a[h]=[],o[h]=0;return r.replace(De,((h,l,f)=>{if(l==="<"){let u=++o[f];return a[f].push(u),`${h}#${u}`}return`${h}#${a[f].pop()}`}))})(t);let e=ft.findAll(t,"rdf","Description");e.length===0&&e.push(new ft("rdf","Description",void 0,t));let i,n={};for(let r of e)for(let a of r.properties)i=Le(a.ns,n),ne(a,i);return(function(r){let a;for(let o in r)a=r[o]=et(r[o]),a===void 0&&delete r[o];return et(r)})(n)}assignToOutput(t,e){if(this.localOptions.parse)for(let[i,n]of Object.entries(e))switch(i){case"tiff":this.assignObjectToOutput(t,"ifd0",n);break;case"exif":this.assignObjectToOutput(t,"exif",n);break;case"xmlns":break;default:this.assignObjectToOutput(t,i,n)}else t.xmp=e}};d(Y,"type","xmp"),d(Y,"multiSegment",!0),b.set("xmp",Y);var Pt=class s{static findAll(t){return re(t,/([a-zA-Z0-9-]+):([a-zA-Z0-9-]+)=("[^"]*"|'[^']*')/gm).map(s.unpackMatch)}static unpackMatch(t){let e=t[1],i=t[2],n=t[3].slice(1,-1);return n=ae(n),new s(e,i,n)}constructor(t,e,i){this.ns=t,this.name=e,this.value=i}serialize(){return this.value}},ft=class s{static findAll(t,e,i){if(e!==void 0||i!==void 0){e=e||"[\\w\\d-]+",i=i||"[\\w\\d-]+";var n=new RegExp(`<(${e}):(${i})(#\\d+)?((\\s+?[\\w\\d-:]+=("[^"]*"|'[^']*'))*\\s*)(\\/>|>([\\s\\S]*?)<\\/\\1:\\2\\3>)`,"gm")}else n=/<([\w\d-]+):([\w\d-]+)(#\d+)?((\s+?[\w\d-:]+=("[^"]*"|'[^']*'))*\s*)(\/>|>([\s\S]*?)<\/\1:\2\3>)/gm;return re(t,n).map(s.unpackMatch)}static unpackMatch(t){let e=t[1],i=t[2],n=t[4],r=t[8];return new s(e,i,n,r)}constructor(t,e,i,n){this.ns=t,this.name=e,this.attrString=i,this.innerXml=n,this.attrs=Pt.findAll(i),this.children=s.findAll(n),this.value=this.children.length===0?ae(n):void 0,this.properties=[...this.attrs,...this.children]}get isPrimitive(){return this.value!==void 0&&this.attrs.length===0&&this.children.length===0}get isListContainer(){return this.children.length===1&&this.children[0].isList}get isList(){let{ns:t,name:e}=this;return t==="rdf"&&(e==="Seq"||e==="Bag"||e==="Alt")}get isListItem(){return this.ns==="rdf"&&this.name==="li"}serialize(){if(this.properties.length===0&&this.value===void 0)return;if(this.isPrimitive)return this.value;if(this.isListContainer)return this.children[0].serialize();if(this.isList)return Be(this.children.map(Ue));if(this.isListItem&&this.children.length===1&&this.attrs.length===0)return this.children[0].serialize();let t={};for(let e of this.properties)ne(e,t);return this.value!==void 0&&(t.value=this.value),et(t)}};function ne(s,t){let e=s.serialize();e!==void 0&&(t[s.name]=e)}var Ue=s=>s.serialize(),Be=s=>s.length===1?s[0]:s,Le=(s,t)=>t[s]?t[s]:t[s]={};function re(s,t){let e,i=[];if(!s)return i;for(;(e=t.exec(s))!==null;)i.push(e);return i}function ae(s){if((function(i){return i==null||i==="null"||i==="undefined"||i===""||i.trim()===""})(s))return;let t=Number(s);if(!Number.isNaN(t))return t;let e=s.toLowerCase();return e==="true"||e!=="false"&&s.trim()}var oe=["rdf:li","rdf:Seq","rdf:Bag","rdf:Alt","rdf:Description"],De=new RegExp(`(<|\\/)(${oe.join("|")})`,"g"),he=Ie;async function Ne(s){try{return await he.parse(s)||null}catch{return null}}function Re(){return Array.from(crypto.getRandomValues(new Uint8Array(16)),s=>s.toString(16).padStart(2,"0")).join("")}async function je(s){if(typeof createImageBitmap>"u"||typeof document>"u"){if(s&&typeof s.arrayBuffer=="function"){let o=await s.arrayBuffer(),h=globalThis.Buffer,l=typeof h<"u"?h.from(o).toString("base64"):btoa(String.fromCharCode(...new Uint8Array(o)));return`data:${s.type||"image/png"};base64,${l}`}if(typeof s=="string")return s}let t=await createImageBitmap(s),n=Math.min(1,1654/t.width,2339/t.height);if(n===1&&(s.type==="image/jpeg"||s.type==="image/jpg"||s.type==="image/png"||s.type==="image/webp"))return t.close(),new Promise((o,h)=>{let l=new FileReader;l.onload=()=>o(l.result),l.onerror=h,l.readAsDataURL(s)});let r=document.createElement("canvas");r.width=Math.round(t.width*n),r.height=Math.round(t.height*n),r.getContext("2d").drawImage(t,0,0,r.width,r.height),t.close();let a=s.type==="image/png"?"image/png":"image/jpeg";return r.toDataURL(a,a==="image/png"?void 0:.82)}function le(s,t=21,e=.2,i=128){let{data:n,width:r,height:a}=s,o=r+1,h=new Float64Array((r+1)*(a+1)),l=new Float64Array((r+1)*(a+1)),f=new Uint8Array(r*a);for(let c=0;c<a;c++){let g=0,S=0,U=c*r,B=(c+1)*o,A=c*o;for(let w=0;w<r;w++){let x=(U+w)*4,L=n[x]*77+n[x+1]*150+n[x+2]*29>>8;f[U+w]=L,g+=L,S+=L*L,h[B+w+1]=h[A+w+1]+g,l[B+w+1]=l[A+w+1]+S}}let u=Math.floor(t/2);for(let c=0;c<a;c++){let g=Math.max(0,c-u),S=Math.min(a-1,c+u),U=g*o,B=(S+1)*o;for(let A=0;A<r;A++){let w=Math.max(0,A-u),x=Math.min(r-1,A+u),L=(x-w+1)*(S-g+1),ue=h[B+x+1]-h[U+x+1]-h[B+w]+h[U+w],de=l[B+x+1]-l[U+x+1]-l[B+w]+l[U+w],ut=ue/L,ce=Math.max(0,de/L-ut*ut),ge=Math.sqrt(ce),pe=ut*(1+e*(ge/i-1)),Tt=c*r+A,dt=f[Tt]<pe?0:255,ct=Tt*4;n[ct]=dt,n[ct+1]=dt,n[ct+2]=dt}}return s}function Ge(s,t=21,e=.2,i=128){return new Promise(n=>{let r=new Image;r.onload=()=>{let a=document.createElement("canvas");a.width=r.width,a.height=r.height;let o=a.getContext("2d");o.drawImage(r,0,0);let h=o.getImageData(0,0,a.width,a.height);le(h,t,e,i),o.putImageData(h,0,0);let l=s.startsWith("data:image/png"),f=l?"image/png":"image/jpeg";n(a.toDataURL(f,l?void 0:.82))},r.src=s})}function He(s){return new Promise(t=>{let e=new Image;e.onload=()=>{let i=document.createElement("canvas");i.width=e.height,i.height=e.width;let n=i.getContext("2d");n.translate(i.width/2,i.height/2),n.rotate(Math.PI/2),n.drawImage(e,-e.width/2,-e.height/2);let r=s.startsWith("data:image/png"),a=r?"image/png":"image/jpeg";t(i.toDataURL(a,r?void 0:.82))},e.src=s})}function We(s,t=""){if(!s)return"";let e=s.getCroppedCanvas(),i=t.startsWith("data:image/png"),n=i?"image/png":"image/jpeg";return e.toDataURL(n,i?void 0:.82)}function Ft(s){if(!s||typeof s!="object")return{crop:null,rotation:0,filter:"none"};let t=s.crop&&typeof s.crop=="object"&&s.crop.width>0&&s.crop.height>0?{x:Math.round(s.crop.x||0),y:Math.round(s.crop.y||0),width:Math.round(s.crop.width),height:Math.round(s.crop.height)}:null,e=(Math.round(s.rotation||0)%360+360)%360,i=s.filter==="bw"?"bw":"none";return{crop:t,rotation:e,filter:i}}function Fe(s){if(!s)return!1;let t=Ft(s);return!!(t.crop||t.rotation!==0||t.filter!=="none")}function Mt(s,t){let e=Ft(t),i=s.naturalWidth||s.width||0,n=s.naturalHeight||s.height||0,r=document.createElement("canvas"),a=i,o=n,h=0,l=0;e.crop&&(h=Math.max(0,Math.min(e.crop.x,i)),l=Math.max(0,Math.min(e.crop.y,n)),a=Math.max(1,Math.min(e.crop.width,i-h)),o=Math.max(1,Math.min(e.crop.height,n-l))),r.width=a,r.height=o,r.getContext("2d").drawImage(s,h,l,a,o,0,0,a,o);let u=r;if(e.rotation!==0){let c=e.rotation,g=document.createElement("canvas");c===90||c===270?(g.width=u.height,g.height=u.width):(g.width=u.width,g.height=u.height);let S=g.getContext("2d");S.translate(g.width/2,g.height/2),S.rotate(c*Math.PI/180),S.drawImage(u,-u.width/2,-u.height/2),u=g}if(e.filter==="bw"){let c=u.getContext("2d"),g=c.getImageData(0,0,u.width,u.height);le(g),c.putImageData(g,0,0)}return u}function $e(s,t){if(!s)return Promise.resolve("");let e=Ft(t);return Fe(e)?new Promise((i,n)=>{let r=new Image;r.onload=()=>{try{let a=s.startsWith("data:image/png"),o=a?"image/png":"image/jpeg",h=Mt(r,e);i(h.toDataURL(o,a?void 0:.82))}catch(a){n(a)}},r.onerror=n,r.src=s}):Promise.resolve(s)}function Me(s){return new Promise((t,e)=>{let i=new Image;i.onload=()=>t(i),i.onerror=e,i.src=s})}var fe=class extends Et{async renderEdits(t,e={}){if(!t)return"";if(typeof document>"u")return t;try{let i=await Me(t),n={...e};return e?.crop&&"w"in e.crop&&(n.crop={x:Math.round((e.crop.x||0)*i.naturalWidth),y:Math.round((e.crop.y||0)*i.naturalHeight),width:Math.round((e.crop.w||1)*i.naturalWidth),height:Math.round((e.crop.h||1)*i.naturalHeight)}),e?.rotate!==void 0&&(n.rotation=e.rotate),Mt(i,n).toDataURL("image/jpeg",.92)}catch{return t}}async crop(t,e){return this.renderEdits(t,{crop:e})}async rotate(t,e){return this.renderEdits(t,{rotate:e})}async applyFilter(t,e){return this.renderEdits(t,{filter:e})}};export{Ne as a,Re as b,je as c,le as d,Ge as e,He as f,We as g,Ft as h,Fe as i,Mt as j,$e as k,fe as l};
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as Et}from"./chunk-ULTSZWZO.js";function c(s,t,e){return t in s?Object.defineProperty(s,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):s[t]=e,s}var At=typeof self<"u"?self:global,q=typeof navigator<"u",me=q&&typeof HTMLImageElement>"u",Nt=!(typeof global>"u"||typeof process>"u"||!process.versions||!process.versions.node),It=At.Buffer,tt=At.BigInt,Ut=!!It,et=s=>Yt(s)?void 0:s,ye=s=>s!==void 0;function Yt(s){return s===void 0||(s instanceof Map?s.size===0:Object.values(s).filter(ye).length===0)}function m(s){let t=new Error(s);throw delete t.stack,t}function qt(s){return(s=(function(t){for(;t.endsWith("\0");)t=t.slice(0,-1);return t})(s).trim())===""?void 0:s}function zt(s){let t=(function(e){let i=0;return e.ifd0.enabled&&(i+=1024),e.exif.enabled&&(i+=2048),e.makerNote&&(i+=2048),e.userComment&&(i+=1024),e.gps.enabled&&(i+=512),e.interop.enabled&&(i+=100),e.ifd1.enabled&&(i+=1024),i+2048})(s);return s.jfif.enabled&&(t+=50),s.xmp.enabled&&(t+=2e4),s.iptc.enabled&&(t+=14e3),s.icc.enabled&&(t+=6e3),t}var yt=s=>String.fromCharCode.apply(null,s),Vt=typeof TextDecoder<"u"?new TextDecoder("utf-8"):void 0;function Zt(s){return Vt?Vt.decode(s):Ut?Buffer.from(s).toString("utf8"):decodeURIComponent(escape(yt(s)))}var O=class s{static from(t,e){return t instanceof this&&t.le===e?t:new s(t,void 0,void 0,e)}constructor(t,e=0,i,n){if(typeof n=="boolean"&&(this.le=n),Array.isArray(t)&&(t=new Uint8Array(t)),t===0)this.byteOffset=0,this.byteLength=0;else if(t instanceof ArrayBuffer){i===void 0&&(i=t.byteLength-e);let r=new DataView(t,e,i);this._swapDataView(r)}else if(t instanceof Uint8Array||t instanceof DataView||t instanceof s){i===void 0&&(i=t.byteLength-e),(e+=t.byteOffset)+i>t.byteOffset+t.byteLength&&m("Creating view outside of available memory in ArrayBuffer");let r=new DataView(t.buffer,e,i);this._swapDataView(r)}else if(typeof t=="number"){let r=new DataView(new ArrayBuffer(t));this._swapDataView(r)}else m("Invalid input argument for BufferView: "+t)}_swapArrayBuffer(t){this._swapDataView(new DataView(t))}_swapBuffer(t){this._swapDataView(new DataView(t.buffer,t.byteOffset,t.byteLength))}_swapDataView(t){this.dataView=t,this.buffer=t.buffer,this.byteOffset=t.byteOffset,this.byteLength=t.byteLength}_lengthToEnd(t){return this.byteLength-t}set(t,e,i=s){return t instanceof DataView||t instanceof s?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer&&(t=new Uint8Array(t)),t instanceof Uint8Array||m("BufferView.set(): Invalid data argument."),this.toUint8().set(t,e),new i(this,e,t.byteLength)}subarray(t,e){return e=e||this._lengthToEnd(t),new s(this,t,e)}toUint8(){return new Uint8Array(this.buffer,this.byteOffset,this.byteLength)}getUint8Array(t,e){return new Uint8Array(this.buffer,this.byteOffset+t,e)}getString(t=0,e=this.byteLength){return Zt(this.getUint8Array(t,e))}getLatin1String(t=0,e=this.byteLength){let i=this.getUint8Array(t,e);return yt(i)}getUnicodeString(t=0,e=this.byteLength){let i=[];for(let n=0;n<e&&t+n<this.byteLength;n+=2)i.push(this.getUint16(t+n));return yt(i)}getInt8(t){return this.dataView.getInt8(t)}getUint8(t){return this.dataView.getUint8(t)}getInt16(t,e=this.le){return this.dataView.getInt16(t,e)}getInt32(t,e=this.le){return this.dataView.getInt32(t,e)}getUint16(t,e=this.le){return this.dataView.getUint16(t,e)}getUint32(t,e=this.le){return this.dataView.getUint32(t,e)}getFloat32(t,e=this.le){return this.dataView.getFloat32(t,e)}getFloat64(t,e=this.le){return this.dataView.getFloat64(t,e)}getFloat(t,e=this.le){return this.dataView.getFloat32(t,e)}getDouble(t,e=this.le){return this.dataView.getFloat64(t,e)}getUintBytes(t,e,i){switch(e){case 1:return this.getUint8(t,i);case 2:return this.getUint16(t,i);case 4:return this.getUint32(t,i);case 8:return this.getUint64&&this.getUint64(t,i)}}getUint(t,e,i){switch(e){case 8:return this.getUint8(t,i);case 16:return this.getUint16(t,i);case 32:return this.getUint32(t,i);case 64:return this.getUint64&&this.getUint64(t,i)}}toString(t){return this.dataView.toString(t,this.constructor.name)}ensureChunk(){}};function bt(s,t){m(`${s} '${t}' was not loaded, try using full build of exifr.`)}var Z=class extends Map{constructor(t){super(),this.kind=t}get(t,e){return this.has(t)||bt(this.kind,t),e&&(t in e||(function(i,n){m(`Unknown ${i} '${n}'.`)})(this.kind,t),e[t].enabled||bt(this.kind,t)),super.get(t)}keyList(){return Array.from(this.keys())}},z=new Z("file parser"),b=new Z("segment parser"),V=new Z("file reader"),Jt=At.fetch;function Rt(s,t){return(e=s).startsWith("data:")||e.length>1e4?St(s,t,"base64"):Nt&&s.includes("://")?wt(s,t,"url",G):Nt?St(s,t,"fs"):q?wt(s,t,"url",G):void m("Invalid input argument");var e}async function wt(s,t,e,i){return V.has(e)?St(s,t,e):i?(async function(n,r){let a=await r(n);return new O(a)})(s,i):void m(`Parser ${e} is not loaded`)}async function St(s,t,e){let i=new(V.get(e))(s,t);return await i.read(),i}var G=s=>Jt(s).then((t=>t.arrayBuffer())),H=s=>new Promise(((t,e)=>{let i=new FileReader;i.onloadend=()=>t(i.result||new ArrayBuffer),i.onerror=e,i.readAsArrayBuffer(s)})),kt=class extends Map{get tagKeys(){return this.allKeys||(this.allKeys=Array.from(this.keys())),this.allKeys}get tagValues(){return this.allValues||(this.allValues=Array.from(this.values())),this.allValues}};function k(s,t,e){let i=new kt;for(let[n,r]of e)i.set(n,r);if(Array.isArray(t))for(let n of t)s.set(n,i);else s.set(t,i);return i}function Bt(s,t,e){let i,n=s.get(t);for(i of e)n.set(i[0],i[1])}var C=new Map,$=new Map,N=new Map,D=["chunked","firstChunkSize","firstChunkSizeNode","firstChunkSizeBrowser","chunkSize","chunkLimit"],J=["jfif","xmp","icc","iptc","ihdr"],W=["tiff",...J],p=["ifd0","ifd1","exif","gps","interop"],F=[...W,...p],T=["makerNote","userComment"],Q=["translateKeys","translateValues","reviveValues","multiSegment"],E=[...Q,"sanitize","mergeOutput","silentErrors"],it=class{get translate(){return this.translateKeys||this.translateValues||this.reviveValues}},L=class extends it{get needed(){return this.enabled||this.deps.size>0}constructor(t,e,i,n){if(super(),c(this,"enabled",!1),c(this,"skip",new Set),c(this,"pick",new Set),c(this,"deps",new Set),c(this,"translateKeys",!1),c(this,"translateValues",!1),c(this,"reviveValues",!1),this.key=t,this.enabled=e,this.parse=this.enabled,this.applyInheritables(n),this.canBeFiltered=p.includes(t),this.canBeFiltered&&(this.dict=C.get(t)),i!==void 0)if(Array.isArray(i))this.parse=this.enabled=!0,this.canBeFiltered&&i.length>0&&this.translateTagSet(i,this.pick);else if(typeof i=="object"){if(this.enabled=!0,this.parse=i.parse!==!1,this.canBeFiltered){let{pick:r,skip:a}=i;r&&r.length>0&&this.translateTagSet(r,this.pick),a&&a.length>0&&this.translateTagSet(a,this.skip)}this.applyInheritables(i)}else i===!0||i===!1?this.parse=this.enabled=i:m(`Invalid options argument: ${i}`)}applyInheritables(t){let e,i;for(e of Q)i=t[e],i!==void 0&&(this[e]=i)}translateTagSet(t,e){if(this.dict){let i,n,{tagKeys:r,tagValues:a}=this.dict;for(i of t)typeof i=="string"?(n=a.indexOf(i),n===-1&&(n=r.indexOf(Number(i))),n!==-1&&e.add(Number(r[n]))):e.add(i)}else for(let i of t)e.add(i)}finalizeFilters(){!this.enabled&&this.deps.size>0?(this.enabled=!0,st(this.pick,this.deps)):this.enabled&&this.pick.size>0&&st(this.pick,this.deps)}},y={jfif:!1,tiff:!0,xmp:!1,icc:!1,iptc:!1,ifd0:!0,ifd1:!1,exif:!0,gps:!0,interop:!1,ihdr:void 0,makerNote:!1,userComment:!1,multiSegment:!1,skip:[],pick:[],translateKeys:!0,translateValues:!0,reviveValues:!0,sanitize:!0,mergeOutput:!0,silentErrors:!0,chunked:!0,firstChunkSize:void 0,firstChunkSizeNode:512,firstChunkSizeBrowser:65536,chunkSize:65536,chunkLimit:5},jt=new Map,I=class extends it{static useCached(t){let e=jt.get(t);return e!==void 0||(e=new this(t),jt.set(t,e)),e}constructor(t){super(),t===!0?this.setupFromTrue():t===void 0?this.setupFromUndefined():Array.isArray(t)?this.setupFromArray(t):typeof t=="object"?this.setupFromObject(t):m(`Invalid options argument ${t}`),this.firstChunkSize===void 0&&(this.firstChunkSize=q?this.firstChunkSizeBrowser:this.firstChunkSizeNode),this.mergeOutput&&(this.ifd1.enabled=!1),this.filterNestedSegmentTags(),this.traverseTiffDependencyTree(),this.checkLoadedPlugins()}setupFromUndefined(){let t;for(t of D)this[t]=y[t];for(t of E)this[t]=y[t];for(t of T)this[t]=y[t];for(t of F)this[t]=new L(t,y[t],void 0,this)}setupFromTrue(){let t;for(t of D)this[t]=y[t];for(t of E)this[t]=y[t];for(t of T)this[t]=!0;for(t of F)this[t]=new L(t,!0,void 0,this)}setupFromArray(t){let e;for(e of D)this[e]=y[e];for(e of E)this[e]=y[e];for(e of T)this[e]=y[e];for(e of F)this[e]=new L(e,!1,void 0,this);this.setupGlobalFilters(t,void 0,p)}setupFromObject(t){let e;for(e of(p.ifd0=p.ifd0||p.image,p.ifd1=p.ifd1||p.thumbnail,Object.assign(this,t),D))this[e]=gt(t[e],y[e]);for(e of E)this[e]=gt(t[e],y[e]);for(e of T)this[e]=gt(t[e],y[e]);for(e of W)this[e]=new L(e,y[e],t[e],this);for(e of p)this[e]=new L(e,y[e],t[e],this.tiff);this.setupGlobalFilters(t.pick,t.skip,p,F),t.tiff===!0?this.batchEnableWithBool(p,!0):t.tiff===!1?this.batchEnableWithUserValue(p,t):Array.isArray(t.tiff)?this.setupGlobalFilters(t.tiff,void 0,p):typeof t.tiff=="object"&&this.setupGlobalFilters(t.tiff.pick,t.tiff.skip,p)}batchEnableWithBool(t,e){for(let i of t)this[i].enabled=e}batchEnableWithUserValue(t,e){for(let i of t){let n=e[i];this[i].enabled=n!==!1&&n!==void 0}}setupGlobalFilters(t,e,i,n=i){if(t&&t.length){for(let a of n)this[a].enabled=!1;let r=Gt(t,i);for(let[a,o]of r)st(this[a].pick,o),this[a].enabled=!0}else if(e&&e.length){let r=Gt(e,i);for(let[a,o]of r)st(this[a].skip,o)}}filterNestedSegmentTags(){let{ifd0:t,exif:e,xmp:i,iptc:n,icc:r}=this;this.makerNote?e.deps.add(37500):e.skip.add(37500),this.userComment?e.deps.add(37510):e.skip.add(37510),i.enabled||t.skip.add(700),n.enabled||t.skip.add(33723),r.enabled||t.skip.add(34675)}traverseTiffDependencyTree(){let{ifd0:t,exif:e,gps:i,interop:n}=this;n.needed&&(e.deps.add(40965),t.deps.add(40965)),e.needed&&t.deps.add(34665),i.needed&&t.deps.add(34853),this.tiff.enabled=p.some((r=>this[r].enabled===!0))||this.makerNote||this.userComment;for(let r of p)this[r].finalizeFilters()}get onlyTiff(){return!J.map((t=>this[t].enabled)).some((t=>t===!0))&&this.tiff.enabled}checkLoadedPlugins(){for(let t of W)this[t].enabled&&!b.has(t)&&bt("segment parser",t)}};function Gt(s,t){let e,i,n,r,a=[];for(n of t){for(r of(e=C.get(n),i=[],e))(s.includes(r[0])||s.includes(r[1]))&&i.push(r[0]);i.length&&a.push([n,i])}return a}function gt(s,t){return s!==void 0?s:t!==void 0?t:void 0}function st(s,t){for(let e of t)s.add(e)}c(I,"default",y);var P=class{constructor(t){c(this,"parsers",{}),c(this,"output",{}),c(this,"errors",[]),c(this,"pushToErrors",(e=>this.errors.push(e))),this.options=I.useCached(t)}async read(t){this.file=await(function(e,i){return typeof e=="string"?Rt(e,i):q&&!me&&e instanceof HTMLImageElement?Rt(e.src,i):e instanceof Uint8Array||e instanceof ArrayBuffer||e instanceof DataView?new O(e):q&&e instanceof Blob?wt(e,i,"blob",H):void m("Invalid input argument")})(t,this.options)}setup(){if(this.fileParser)return;let{file:t}=this,e=t.getUint16(0);for(let[i,n]of z)if(n.canHandle(t,e))return this.fileParser=new n(this.options,this.file,this.parsers),t[i]=!0;this.file.close&&this.file.close(),m("Unknown file format")}async parse(){let{output:t,errors:e}=this;return this.setup(),this.options.silentErrors?(await this.executeParsers().catch(this.pushToErrors),e.push(...this.fileParser.errors)):await this.executeParsers(),this.file.close&&this.file.close(),this.options.silentErrors&&e.length>0&&(t.errors=e),et(t)}async executeParsers(){let{output:t}=this;await this.fileParser.parse();let e=Object.values(this.parsers).map((async i=>{let n=await i.parse();i.assignToOutput(t,n)}));this.options.silentErrors&&(e=e.map((i=>i.catch(this.pushToErrors)))),await Promise.all(e)}async extractThumbnail(){this.setup();let{options:t,file:e}=this,i=b.get("tiff",t);var n;if(e.tiff?n={start:0,type:"tiff"}:e.jpeg&&(n=await this.fileParser.getOrFindSegment("tiff")),n===void 0)return;let r=await this.fileParser.ensureSegmentChunk(n),a=this.parsers.tiff=new i(r,t,e),o=await a.extractThumbnail();return e.close&&e.close(),o}};async function Mt(s,t){let e=new P(t);return await e.read(s),e.parse()}var be=Object.freeze({__proto__:null,parse:Mt,Exifr:P,fileParsers:z,segmentParsers:b,fileReaders:V,tagKeys:C,tagValues:$,tagRevivers:N,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:D,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:F,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I}),nt=class{constructor(t,e,i){c(this,"errors",[]),c(this,"ensureSegmentChunk",(async n=>{let r=n.start,a=n.size||65536;if(this.file.chunked)if(this.file.available(r,a))n.chunk=this.file.subarray(r,a);else try{n.chunk=await this.file.readChunk(r,a)}catch(o){m(`Couldn't read segment: ${JSON.stringify(n)}. ${o.message}`)}else this.file.byteLength>r+a?n.chunk=this.file.subarray(r,a):n.size===void 0?n.chunk=this.file.subarray(r):m("Segment unreachable: "+JSON.stringify(n));return n.chunk})),this.extendOptions&&this.extendOptions(t),this.options=t,this.file=e,this.parsers=i}injectSegment(t,e){this.options[t].enabled&&this.createParser(t,e)}createParser(t,e){let i=new(b.get(t))(e,this.options,this.file);return this.parsers[t]=i}createParsers(t){for(let e of t){let{type:i,chunk:n}=e,r=this.options[i];if(r&&r.enabled){let a=this.parsers[i];a&&a.append||a||this.createParser(i,n)}}}async readSegments(t){let e=t.map(this.ensureSegmentChunk);await Promise.all(e)}},v=class{static findPosition(t,e){let i=t.getUint16(e+2)+2,n=typeof this.headerLength=="function"?this.headerLength(t,e,i):this.headerLength,r=e+n,a=i-n;return{offset:e,length:i,headerLength:n,start:r,size:a,end:r+a}}static parse(t,e={}){return new this(t,new I({[this.type]:e}),t).parse()}normalizeInput(t){return t instanceof O?t:new O(t)}constructor(t,e={},i){c(this,"errors",[]),c(this,"raw",new Map),c(this,"handleError",(n=>{if(!this.options.silentErrors)throw n;this.errors.push(n.message)})),this.chunk=this.normalizeInput(t),this.file=i,this.type=this.constructor.type,this.globalOptions=this.options=e,this.localOptions=e[this.type],this.canTranslate=this.localOptions&&this.localOptions.translate}translate(){this.canTranslate&&(this.translated=this.translateBlock(this.raw,this.type))}get output(){return this.translated?this.translated:this.raw?Object.fromEntries(this.raw):void 0}translateBlock(t,e){let i=N.get(e),n=$.get(e),r=C.get(e),a=this.options[e],o=a.reviveValues&&!!i,h=a.translateValues&&!!n,l=a.translateKeys&&!!r,u={};for(let[d,f]of t)o&&i.has(d)?f=i.get(d)(f):h&&n.has(d)&&(f=this.translateValue(f,n.get(d))),l&&r.has(d)&&(d=r.get(d)||d),u[d]=f;return u}translateValue(t,e){return e[t]||e.DEFAULT||t}assignToOutput(t,e){this.assignObjectToOutput(t,this.constructor.type,e)}assignObjectToOutput(t,e,i){if(this.globalOptions.mergeOutput)return Object.assign(t,i);t[e]?Object.assign(t[e],i):t[e]=i}};c(v,"headerLength",4),c(v,"type",void 0),c(v,"multiSegment",!1),c(v,"canHandle",(()=>!1));function we(s){return s===192||s===194||s===196||s===219||s===221||s===218||s===254}function Se(s){return s>=224&&s<=239}function ke(s,t,e){for(let[i,n]of b)if(n.canHandle(s,t,e))return i}var rt=class extends nt{constructor(...t){super(...t),c(this,"appSegments",[]),c(this,"jpegSegments",[]),c(this,"unknownSegments",[])}static canHandle(t,e){return e===65496}async parse(){await this.findAppSegments(),await this.readSegments(this.appSegments),this.mergeMultiSegments(),this.createParsers(this.mergedAppSegments||this.appSegments)}setupSegmentFinderArgs(t){t===!0?(this.findAll=!0,this.wanted=new Set(b.keyList())):(t=t===void 0?b.keyList().filter((e=>this.options[e].enabled)):t.filter((e=>this.options[e].enabled&&b.has(e))),this.findAll=!1,this.remaining=new Set(t),this.wanted=new Set(t)),this.unfinishedMultiSegment=!1}async findAppSegments(t=0,e){this.setupSegmentFinderArgs(e);let{file:i,findAll:n,wanted:r,remaining:a}=this;if(!n&&this.file.chunked&&(n=Array.from(r).some((o=>{let h=b.get(o),l=this.options[o];return h.multiSegment&&l.multiSegment})),n&&await this.file.readWhole()),t=this.findAppSegmentsInRange(t,i.byteLength),!this.options.onlyTiff&&i.chunked){let o=!1;for(;a.size>0&&!o&&(i.canReadNextChunk||this.unfinishedMultiSegment);){let{nextChunkOffset:h}=i,l=this.appSegments.some((u=>!this.file.available(u.offset||u.start,u.length||u.size)));if(o=t>h&&!l?!await i.readNextChunk(t):!await i.readNextChunk(h),(t=this.findAppSegmentsInRange(t,i.byteLength))===void 0)return}}}findAppSegmentsInRange(t,e){e-=2;let i,n,r,a,o,h,{file:l,findAll:u,wanted:d,remaining:f,options:g}=this;for(;t<e;t++)if(l.getUint8(t)===255){if(i=l.getUint8(t+1),Se(i)){if(n=l.getUint16(t+2),r=ke(l,t,n),r&&d.has(r)&&(a=b.get(r),o=a.findPosition(l,t),h=g[r],o.type=r,this.appSegments.push(o),!u&&(a.multiSegment&&h.multiSegment?(this.unfinishedMultiSegment=o.chunkNumber<o.chunkCount,this.unfinishedMultiSegment||f.delete(r)):f.delete(r),f.size===0)))break;g.recordUnknownSegments&&(o=v.findPosition(l,t),o.marker=i,this.unknownSegments.push(o)),t+=n+1}else if(we(i)){if(n=l.getUint16(t+2),i===218&&g.stopAfterSos!==!1)return;g.recordJpegSegments&&this.jpegSegments.push({offset:t,length:n,marker:i}),t+=n+1}}return t}mergeMultiSegments(){if(!this.appSegments.some((e=>e.multiSegment)))return;let t=(function(e,i){let n,r,a,o=new Map;for(let h=0;h<e.length;h++)n=e[h],r=n[i],o.has(r)?a=o.get(r):o.set(r,a=[]),a.push(n);return Array.from(o)})(this.appSegments,"type");this.mergedAppSegments=t.map((([e,i])=>{let n=b.get(e,this.options);return n.handleMultiSegments?{type:e,chunk:n.handleMultiSegments(i)}:i[0]}))}getSegment(t){return this.appSegments.find((e=>e.type===t))}async getOrFindSegment(t){let e=this.getSegment(t);return e===void 0&&(await this.findAppSegments(0,[t]),e=this.getSegment(t)),e}};c(rt,"type","jpeg"),z.set("jpeg",rt);var xe=[void 0,1,1,2,4,8,1,1,2,4,8,4,8,4],xt=class extends v{parseHeader(){var t=this.chunk.getUint16();t===18761?this.le=!0:t===19789&&(this.le=!1),this.chunk.le=this.le,this.headerParsed=!0}parseTags(t,e,i=new Map){let{pick:n,skip:r}=this.options[e];n=new Set(n);let a=n.size>0,o=r.size===0,h=this.chunk.getUint16(t);t+=2;for(let l=0;l<h;l++){let u=this.chunk.getUint16(t);if(a){if(n.has(u)&&(i.set(u,this.parseTag(t,u,e)),n.delete(u),n.size===0))break}else!o&&r.has(u)||i.set(u,this.parseTag(t,u,e));t+=12}return i}parseTag(t,e,i){let{chunk:n}=this,r=n.getUint16(t+2),a=n.getUint32(t+4),o=xe[r];if(o*a<=4?t+=8:t=n.getUint32(t+8),(r<1||r>13)&&m(`Invalid TIFF value type. block: ${i.toUpperCase()}, tag: ${e.toString(16)}, type: ${r}, offset ${t}`),t>n.byteLength&&m(`Invalid TIFF value offset. block: ${i.toUpperCase()}, tag: ${e.toString(16)}, type: ${r}, offset ${t} is outside of chunk size ${n.byteLength}`),r===1)return n.getUint8Array(t,a);if(r===2)return qt(n.getString(t,a));if(r===7)return n.getUint8Array(t,a);if(a===1)return this.parseTagValue(r,t);{let h=new((function(u){switch(u){case 1:return Uint8Array;case 3:return Uint16Array;case 4:return Uint32Array;case 5:return Array;case 6:return Int8Array;case 8:return Int16Array;case 9:return Int32Array;case 10:return Array;case 11:return Float32Array;case 12:return Float64Array;default:return Array}})(r))(a),l=o;for(let u=0;u<a;u++)h[u]=this.parseTagValue(r,t),t+=l;return h}}parseTagValue(t,e){let{chunk:i}=this;switch(t){case 1:return i.getUint8(e);case 3:return i.getUint16(e);case 4:return i.getUint32(e);case 5:return i.getUint32(e)/i.getUint32(e+4);case 6:return i.getInt8(e);case 8:return i.getInt16(e);case 9:return i.getInt32(e);case 10:return i.getInt32(e)/i.getInt32(e+4);case 11:return i.getFloat(e);case 12:return i.getDouble(e);case 13:return i.getUint32(e);default:m(`Invalid tiff type ${t}`)}}},X=class extends xt{static canHandle(t,e){return t.getUint8(e+1)===225&&t.getUint32(e+4)===1165519206&&t.getUint16(e+8)===0}async parse(){this.parseHeader();let{options:t}=this;return t.ifd0.enabled&&await this.parseIfd0Block(),t.exif.enabled&&await this.safeParse("parseExifBlock"),t.gps.enabled&&await this.safeParse("parseGpsBlock"),t.interop.enabled&&await this.safeParse("parseInteropBlock"),t.ifd1.enabled&&await this.safeParse("parseThumbnailBlock"),this.createOutput()}safeParse(t){let e=this[t]();return e.catch!==void 0&&(e=e.catch(this.handleError)),e}findIfd0Offset(){this.ifd0Offset===void 0&&(this.ifd0Offset=this.chunk.getUint32(4))}findIfd1Offset(){if(this.ifd1Offset===void 0){this.findIfd0Offset();let t=this.chunk.getUint16(this.ifd0Offset),e=this.ifd0Offset+2+12*t;this.ifd1Offset=this.chunk.getUint32(e)}}parseBlock(t,e){let i=new Map;return this[e]=i,this.parseTags(t,e,i),i}async parseIfd0Block(){if(this.ifd0)return;let{file:t}=this;this.findIfd0Offset(),this.ifd0Offset<8&&m("Malformed EXIF data"),!t.chunked&&this.ifd0Offset>t.byteLength&&m(`IFD0 offset points to outside of file.
|
|
2
|
+
this.ifd0Offset: ${this.ifd0Offset}, file.byteLength: ${t.byteLength}`),t.tiff&&await t.ensureChunk(this.ifd0Offset,zt(this.options));let e=this.parseBlock(this.ifd0Offset,"ifd0");return e.size!==0?(this.exifOffset=e.get(34665),this.interopOffset=e.get(40965),this.gpsOffset=e.get(34853),this.xmp=e.get(700),this.iptc=e.get(33723),this.icc=e.get(34675),this.options.sanitize&&(e.delete(34665),e.delete(40965),e.delete(34853),e.delete(700),e.delete(33723),e.delete(34675)),e):void 0}async parseExifBlock(){if(this.exif||(this.ifd0||await this.parseIfd0Block(),this.exifOffset===void 0))return;this.file.tiff&&await this.file.ensureChunk(this.exifOffset,zt(this.options));let t=this.parseBlock(this.exifOffset,"exif");return this.interopOffset||(this.interopOffset=t.get(40965)),this.makerNote=t.get(37500),this.userComment=t.get(37510),this.options.sanitize&&(t.delete(40965),t.delete(37500),t.delete(37510)),this.unpack(t,41728),this.unpack(t,41729),t}unpack(t,e){let i=t.get(e);i&&i.length===1&&t.set(e,i[0])}async parseGpsBlock(){if(this.gps||(this.ifd0||await this.parseIfd0Block(),this.gpsOffset===void 0))return;let t=this.parseBlock(this.gpsOffset,"gps");return t&&t.has(2)&&t.has(4)&&(t.set("latitude",Ht(...t.get(2),t.get(1))),t.set("longitude",Ht(...t.get(4),t.get(3)))),t}async parseInteropBlock(){if(!this.interop&&(this.ifd0||await this.parseIfd0Block(),this.interopOffset!==void 0||this.exif||await this.parseExifBlock(),this.interopOffset!==void 0))return this.parseBlock(this.interopOffset,"interop")}async parseThumbnailBlock(t=!1){if(!this.ifd1&&!this.ifd1Parsed&&(!this.options.mergeOutput||t))return this.findIfd1Offset(),this.ifd1Offset>0&&(this.parseBlock(this.ifd1Offset,"ifd1"),this.ifd1Parsed=!0),this.ifd1}async extractThumbnail(){if(this.headerParsed||this.parseHeader(),this.ifd1Parsed||await this.parseThumbnailBlock(!0),this.ifd1===void 0)return;let t=this.ifd1.get(513),e=this.ifd1.get(514);return this.chunk.getUint8Array(t,e)}get image(){return this.ifd0}get thumbnail(){return this.ifd1}createOutput(){let t,e,i,n={};for(e of p)if(t=this[e],!Yt(t))if(i=this.canTranslate?this.translateBlock(t,e):Object.fromEntries(t),this.options.mergeOutput){if(e==="ifd1")continue;Object.assign(n,i)}else n[e]=i;return this.makerNote&&(n.makerNote=this.makerNote),this.userComment&&(n.userComment=this.userComment),n}assignToOutput(t,e){if(this.globalOptions.mergeOutput)Object.assign(t,e);else for(let[i,n]of Object.entries(e))this.assignObjectToOutput(t,i,n)}};function Ht(s,t,e,i){var n=s+t/60+e/3600;return i!=="S"&&i!=="W"||(n*=-1),n}c(X,"type","tiff"),c(X,"headerLength",10),b.set("tiff",X);var ve=Object.freeze({__proto__:null,default:be,Exifr:P,fileParsers:z,segmentParsers:b,fileReaders:V,tagKeys:C,tagValues:$,tagRevivers:N,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:D,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:F,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I,parse:Mt}),Lt={ifd0:!1,ifd1:!1,exif:!1,gps:!1,interop:!1,sanitize:!1,reviveValues:!0,translateKeys:!1,translateValues:!1,mergeOutput:!1},Qt=Object.assign({},Lt,{firstChunkSize:4e4,gps:[1,2,3,4]});async function Ce(s){let t=new P(Qt);await t.read(s);let e=await t.parse();if(e&&e.gps){let{latitude:i,longitude:n}=e.gps;return{latitude:i,longitude:n}}}var te=Object.assign({},Lt,{tiff:!1,ifd1:!0,mergeOutput:!1});async function Oe(s){let t=new P(te);await t.read(s);let e=await t.extractThumbnail();return e&&Ut?It.from(e):e}async function Pe(s){let t=await this.thumbnail(s);if(t!==void 0){let e=new Blob([t]);return URL.createObjectURL(e)}}var ee=Object.assign({},Lt,{firstChunkSize:4e4,ifd0:[274]});async function ie(s){let t=new P(ee);await t.read(s);let e=await t.parse();if(e&&e.ifd0)return e.ifd0[274]}var se=Object.freeze({1:{dimensionSwapped:!1,scaleX:1,scaleY:1,deg:0,rad:0},2:{dimensionSwapped:!1,scaleX:-1,scaleY:1,deg:0,rad:0},3:{dimensionSwapped:!1,scaleX:1,scaleY:1,deg:180,rad:180*Math.PI/180},4:{dimensionSwapped:!1,scaleX:-1,scaleY:1,deg:180,rad:180*Math.PI/180},5:{dimensionSwapped:!0,scaleX:1,scaleY:-1,deg:90,rad:90*Math.PI/180},6:{dimensionSwapped:!0,scaleX:1,scaleY:1,deg:90,rad:90*Math.PI/180},7:{dimensionSwapped:!0,scaleX:1,scaleY:-1,deg:270,rad:270*Math.PI/180},8:{dimensionSwapped:!0,scaleX:1,scaleY:1,deg:270,rad:270*Math.PI/180}}),R=!0,j=!0;if(typeof navigator=="object"){let s=navigator.userAgent;if(s.includes("iPad")||s.includes("iPhone")){let t=s.match(/OS (\d+)_(\d+)/);if(t){let[,e,i]=t;R=Number(e)+.1*Number(i)<13.4,j=!1}}else if(s.includes("OS X 10")){let[,t]=s.match(/OS X 10[_.](\d+)/);R=j=Number(t)<15}if(s.includes("Chrome/")){let[,t]=s.match(/Chrome\/(\d+)/);R=j=Number(t)<81}else if(s.includes("Firefox/")){let[,t]=s.match(/Firefox\/(\d+)/);R=j=Number(t)<77}}async function Ae(s){let t=await ie(s);return Object.assign({canvas:R,css:j},se[t])}var vt=class extends O{constructor(...t){super(...t),c(this,"ranges",new Ct),this.byteLength!==0&&this.ranges.add(0,this.byteLength)}_tryExtend(t,e,i){if(t===0&&this.byteLength===0&&i){let n=new DataView(i.buffer||i,i.byteOffset,i.byteLength);this._swapDataView(n)}else{let n=t+e;if(n>this.byteLength){let{dataView:r}=this._extend(n);this._swapDataView(r)}}}_extend(t){let e;e=Ut?It.allocUnsafe(t):new Uint8Array(t);let i=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.set(new Uint8Array(this.buffer,this.byteOffset,this.byteLength),0),{uintView:e,dataView:i}}subarray(t,e,i=!1){return e=e||this._lengthToEnd(t),i&&this._tryExtend(t,e),this.ranges.add(t,e),super.subarray(t,e)}set(t,e,i=!1){i&&this._tryExtend(e,t.byteLength,t);let n=super.set(t,e);return this.ranges.add(e,n.byteLength),n}async ensureChunk(t,e){this.chunked&&(this.ranges.available(t,e)||await this.readChunk(t,e))}available(t,e){return this.ranges.available(t,e)}},Ct=class{constructor(){c(this,"list",[])}get length(){return this.list.length}add(t,e,i=0){let n=t+e,r=this.list.filter((a=>Wt(t,a.offset,n)||Wt(t,a.end,n)));if(r.length>0){t=Math.min(t,...r.map((o=>o.offset))),n=Math.max(n,...r.map((o=>o.end))),e=n-t;let a=r.shift();a.offset=t,a.length=e,a.end=n,this.list=this.list.filter((o=>!r.includes(o)))}else this.list.push({offset:t,length:e,end:n})}available(t,e){let i=t+e;return this.list.some((n=>n.offset<=t&&i<=n.end))}};function Wt(s,t,e){return s<=t&&t<=e}var at=class extends vt{constructor(t,e){super(0),c(this,"chunksRead",0),this.input=t,this.options=e}async readWhole(){this.chunked=!1,await this.readChunk(this.nextChunkOffset)}async readChunked(){this.chunked=!0,await this.readChunk(0,this.options.firstChunkSize)}async readNextChunk(t=this.nextChunkOffset){if(this.fullyRead)return this.chunksRead++,!1;let e=this.options.chunkSize,i=await this.readChunk(t,e);return!!i&&i.byteLength===e}async readChunk(t,e){if(this.chunksRead++,(e=this.safeWrapAddress(t,e))!==0)return this._readChunk(t,e)}safeWrapAddress(t,e){return this.size!==void 0&&t+e>this.size?Math.max(0,this.size-t):e}get nextChunkOffset(){if(this.ranges.list.length!==0)return this.ranges.list[0].length}get canReadNextChunk(){return this.chunksRead<this.options.chunkLimit}get fullyRead(){return this.size!==void 0&&this.nextChunkOffset===this.size}read(){return this.options.chunked?this.readChunked():this.readWhole()}close(){}};V.set("blob",class extends at{async readWhole(){this.chunked=!1;let s=await H(this.input);this._swapArrayBuffer(s)}readChunked(){return this.chunked=!0,this.size=this.input.size,super.readChunked()}async _readChunk(s,t){let e=t?s+t:void 0,i=this.input.slice(s,e),n=await H(i);return this.set(n,s,!0)}});var Ie=Object.freeze({__proto__:null,default:ve,Exifr:P,fileParsers:z,segmentParsers:b,fileReaders:V,tagKeys:C,tagValues:$,tagRevivers:N,createDictionary:k,extendDictionary:Bt,fetchUrlAsArrayBuffer:G,readBlobAsArrayBuffer:H,chunkedProps:D,otherSegments:J,segments:W,tiffBlocks:p,segmentsAndBlocks:F,tiffExtractables:T,inheritables:Q,allFormatters:E,Options:I,parse:Mt,gpsOnlyOptions:Qt,gps:Ce,thumbnailOnlyOptions:te,thumbnail:Oe,thumbnailUrl:Pe,orientationOnlyOptions:ee,orientation:ie,rotations:se,get rotateCanvas(){return R},get rotateCss(){return j},rotation:Ae});V.set("url",class extends at{async readWhole(){this.chunked=!1;let s=await G(this.input);s instanceof ArrayBuffer?this._swapArrayBuffer(s):s instanceof Uint8Array&&this._swapBuffer(s)}async _readChunk(s,t){let e=t?s+t-1:void 0,i=this.options.httpHeaders||{};(s||e)&&(i.range=`bytes=${[s,e].join("-")}`);let n=await Jt(this.input,{headers:i}),r=await n.arrayBuffer(),a=r.byteLength;if(n.status!==416)return a!==t&&(this.size=s+a),this.set(r,s,!0)}});O.prototype.getUint64=function(s){let t=this.getUint32(s),e=this.getUint32(s+4);return t<1048575?t<<32|e:typeof tt!==void 0?(console.warn("Using BigInt because of type 64uint but JS can only handle 53b numbers."),tt(t)<<tt(32)|tt(e)):void m("Trying to read 64b value but JS can only handle 53b numbers.")};var Ot=class extends nt{parseBoxes(t=0){let e=[];for(;t<this.file.byteLength-4;){let i=this.parseBoxHead(t);if(e.push(i),i.length===0)break;t+=i.length}return e}parseSubBoxes(t){t.boxes=this.parseBoxes(t.start)}findBox(t,e){return t.boxes===void 0&&this.parseSubBoxes(t),t.boxes.find((i=>i.kind===e))}parseBoxHead(t){let e=this.file.getUint32(t),i=this.file.getString(t+4,4),n=t+8;return e===1&&(e=this.file.getUint64(t+8),n+=8),{offset:t,length:e,kind:i,start:n}}parseBoxFullHead(t){if(t.version!==void 0)return;let e=this.file.getUint32(t.start);t.version=e>>24,t.start+=4}},ot=class extends Ot{static canHandle(t,e){if(e!==0)return!1;let i=t.getUint16(2);if(i>50)return!1;let n=16,r=[];for(;n<i;)r.push(t.getString(n,4)),n+=4;return r.includes(this.type)}async parse(){let t=this.file.getUint32(0),e=this.parseBoxHead(t);for(;e.kind!=="meta";)t+=e.length,await this.file.ensureChunk(t,16),e=this.parseBoxHead(t);await this.file.ensureChunk(e.offset,e.length),this.parseBoxFullHead(e),this.parseSubBoxes(e),this.options.icc.enabled&&await this.findIcc(e),this.options.tiff.enabled&&await this.findExif(e)}async registerSegment(t,e,i){await this.file.ensureChunk(e,i);let n=this.file.subarray(e,i);this.createParser(t,n)}async findIcc(t){let e=this.findBox(t,"iprp");if(e===void 0)return;let i=this.findBox(e,"ipco");if(i===void 0)return;let n=this.findBox(i,"colr");n!==void 0&&await this.registerSegment("icc",n.offset+12,n.length)}async findExif(t){let e=this.findBox(t,"iinf");if(e===void 0)return;let i=this.findBox(t,"iloc");if(i===void 0)return;let n=this.findExifLocIdInIinf(e),r=this.findExtentInIloc(i,n);if(r===void 0)return;let[a,o]=r;await this.file.ensureChunk(a,o);let h=4+this.file.getUint32(a);a+=h,o-=h,await this.registerSegment("tiff",a,o)}findExifLocIdInIinf(t){this.parseBoxFullHead(t);let e,i,n,r,a=t.start,o=this.file.getUint16(a);for(a+=2;o--;){if(e=this.parseBoxHead(a),this.parseBoxFullHead(e),i=e.start,e.version>=2&&(n=e.version===3?4:2,r=this.file.getString(i+n+2,4),r==="Exif"))return this.file.getUintBytes(i,n);a+=e.length}}get8bits(t){let e=this.file.getUint8(t);return[e>>4,15&e]}findExtentInIloc(t,e){this.parseBoxFullHead(t);let i=t.start,[n,r]=this.get8bits(i++),[a,o]=this.get8bits(i++),h=t.version===2?4:2,l=t.version===1||t.version===2?2:0,u=o+n+r,d=t.version===2?4:2,f=this.file.getUintBytes(i,d);for(i+=d;f--;){let g=this.file.getUintBytes(i,h);i+=h+l+2+a;let S=this.file.getUint16(i);if(i+=2,g===e)return S>1&&console.warn(`ILOC box has more than one extent but we're only processing one
|
|
3
|
+
Please create an issue at https://github.com/MikeKovarik/exifr with this file`),[this.file.getUintBytes(i+o,n),this.file.getUintBytes(i+o+n,r)];i+=S*u}}},ht=class extends ot{};c(ht,"type","heic");var lt=class extends ot{};c(lt,"type","avif"),z.set("heic",ht),z.set("avif",lt),k(C,["ifd0","ifd1"],[[256,"ImageWidth"],[257,"ImageHeight"],[258,"BitsPerSample"],[259,"Compression"],[262,"PhotometricInterpretation"],[270,"ImageDescription"],[271,"Make"],[272,"Model"],[273,"StripOffsets"],[274,"Orientation"],[277,"SamplesPerPixel"],[278,"RowsPerStrip"],[279,"StripByteCounts"],[282,"XResolution"],[283,"YResolution"],[284,"PlanarConfiguration"],[296,"ResolutionUnit"],[301,"TransferFunction"],[305,"Software"],[306,"ModifyDate"],[315,"Artist"],[316,"HostComputer"],[317,"Predictor"],[318,"WhitePoint"],[319,"PrimaryChromaticities"],[513,"ThumbnailOffset"],[514,"ThumbnailLength"],[529,"YCbCrCoefficients"],[530,"YCbCrSubSampling"],[531,"YCbCrPositioning"],[532,"ReferenceBlackWhite"],[700,"ApplicationNotes"],[33432,"Copyright"],[33723,"IPTC"],[34665,"ExifIFD"],[34675,"ICC"],[34853,"GpsIFD"],[330,"SubIFD"],[40965,"InteropIFD"],[40091,"XPTitle"],[40092,"XPComment"],[40093,"XPAuthor"],[40094,"XPKeywords"],[40095,"XPSubject"]]),k(C,"exif",[[33434,"ExposureTime"],[33437,"FNumber"],[34850,"ExposureProgram"],[34852,"SpectralSensitivity"],[34855,"ISO"],[34858,"TimeZoneOffset"],[34859,"SelfTimerMode"],[34864,"SensitivityType"],[34865,"StandardOutputSensitivity"],[34866,"RecommendedExposureIndex"],[34867,"ISOSpeed"],[34868,"ISOSpeedLatitudeyyy"],[34869,"ISOSpeedLatitudezzz"],[36864,"ExifVersion"],[36867,"DateTimeOriginal"],[36868,"CreateDate"],[36873,"GooglePlusUploadCode"],[36880,"OffsetTime"],[36881,"OffsetTimeOriginal"],[36882,"OffsetTimeDigitized"],[37121,"ComponentsConfiguration"],[37122,"CompressedBitsPerPixel"],[37377,"ShutterSpeedValue"],[37378,"ApertureValue"],[37379,"BrightnessValue"],[37380,"ExposureCompensation"],[37381,"MaxApertureValue"],[37382,"SubjectDistance"],[37383,"MeteringMode"],[37384,"LightSource"],[37385,"Flash"],[37386,"FocalLength"],[37393,"ImageNumber"],[37394,"SecurityClassification"],[37395,"ImageHistory"],[37396,"SubjectArea"],[37500,"MakerNote"],[37510,"UserComment"],[37520,"SubSecTime"],[37521,"SubSecTimeOriginal"],[37522,"SubSecTimeDigitized"],[37888,"AmbientTemperature"],[37889,"Humidity"],[37890,"Pressure"],[37891,"WaterDepth"],[37892,"Acceleration"],[37893,"CameraElevationAngle"],[40960,"FlashpixVersion"],[40961,"ColorSpace"],[40962,"ExifImageWidth"],[40963,"ExifImageHeight"],[40964,"RelatedSoundFile"],[41483,"FlashEnergy"],[41486,"FocalPlaneXResolution"],[41487,"FocalPlaneYResolution"],[41488,"FocalPlaneResolutionUnit"],[41492,"SubjectLocation"],[41493,"ExposureIndex"],[41495,"SensingMethod"],[41728,"FileSource"],[41729,"SceneType"],[41730,"CFAPattern"],[41985,"CustomRendered"],[41986,"ExposureMode"],[41987,"WhiteBalance"],[41988,"DigitalZoomRatio"],[41989,"FocalLengthIn35mmFormat"],[41990,"SceneCaptureType"],[41991,"GainControl"],[41992,"Contrast"],[41993,"Saturation"],[41994,"Sharpness"],[41996,"SubjectDistanceRange"],[42016,"ImageUniqueID"],[42032,"OwnerName"],[42033,"SerialNumber"],[42034,"LensInfo"],[42035,"LensMake"],[42036,"LensModel"],[42037,"LensSerialNumber"],[42080,"CompositeImage"],[42081,"CompositeImageCount"],[42082,"CompositeImageExposureTimes"],[42240,"Gamma"],[59932,"Padding"],[59933,"OffsetSchema"],[65e3,"OwnerName"],[65001,"SerialNumber"],[65002,"Lens"],[65100,"RawFile"],[65101,"Converter"],[65102,"WhiteBalance"],[65105,"Exposure"],[65106,"Shadows"],[65107,"Brightness"],[65108,"Contrast"],[65109,"Saturation"],[65110,"Sharpness"],[65111,"Smoothness"],[65112,"MoireFilter"],[40965,"InteropIFD"]]),k(C,"gps",[[0,"GPSVersionID"],[1,"GPSLatitudeRef"],[2,"GPSLatitude"],[3,"GPSLongitudeRef"],[4,"GPSLongitude"],[5,"GPSAltitudeRef"],[6,"GPSAltitude"],[7,"GPSTimeStamp"],[8,"GPSSatellites"],[9,"GPSStatus"],[10,"GPSMeasureMode"],[11,"GPSDOP"],[12,"GPSSpeedRef"],[13,"GPSSpeed"],[14,"GPSTrackRef"],[15,"GPSTrack"],[16,"GPSImgDirectionRef"],[17,"GPSImgDirection"],[18,"GPSMapDatum"],[19,"GPSDestLatitudeRef"],[20,"GPSDestLatitude"],[21,"GPSDestLongitudeRef"],[22,"GPSDestLongitude"],[23,"GPSDestBearingRef"],[24,"GPSDestBearing"],[25,"GPSDestDistanceRef"],[26,"GPSDestDistance"],[27,"GPSProcessingMethod"],[28,"GPSAreaInformation"],[29,"GPSDateStamp"],[30,"GPSDifferential"],[31,"GPSHPositioningError"]]),k($,["ifd0","ifd1"],[[274,{1:"Horizontal (normal)",2:"Mirror horizontal",3:"Rotate 180",4:"Mirror vertical",5:"Mirror horizontal and rotate 270 CW",6:"Rotate 90 CW",7:"Mirror horizontal and rotate 90 CW",8:"Rotate 270 CW"}],[296,{1:"None",2:"inches",3:"cm"}]]);var K=k($,"exif",[[34850,{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"}],[37121,{0:"-",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}],[37383,{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"}],[37384,{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"}],[37385,{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"}],[41495,{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"}],[41728,{1:"Film Scanner",2:"Reflection Print Scanner",3:"Digital Camera"}],[41729,{1:"Directly photographed"}],[41985,{0:"Normal",1:"Custom",2:"HDR (no original saved)",3:"HDR (original saved)",4:"Original (for HDR)",6:"Panorama",7:"Portrait HDR",8:"Portrait"}],[41986,{0:"Auto",1:"Manual",2:"Auto bracket"}],[41987,{0:"Auto",1:"Manual"}],[41990,{0:"Standard",1:"Landscape",2:"Portrait",3:"Night",4:"Other"}],[41991,{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"}],[41996,{0:"Unknown",1:"Macro",2:"Close",3:"Distant"}],[42080,{0:"Unknown",1:"Not a Composite Image",2:"General Composite Image",3:"Composite Image Captured While Shooting"}]]),$t={1:"No absolute unit of measurement",2:"Inch",3:"Centimeter"};K.set(37392,$t),K.set(41488,$t);var pt={0:"Normal",1:"Low",2:"High"};function _t(s){return typeof s=="object"&&s.length!==void 0?s[0]:s}function Xt(s){let t=Array.from(s).slice(1);return t[1]>15&&(t=t.map((e=>String.fromCharCode(e)))),t[2]!=="0"&&t[2]!==0||t.pop(),t.join(".")}function mt(s){if(typeof s=="string"){var[t,e,i,n,r,a]=s.trim().split(/[-: ]/g).map(Number),o=new Date(t,e-1,i);return Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(a)||(o.setHours(n),o.setMinutes(r),o.setSeconds(a)),Number.isNaN(+o)?s:o}}function _(s){if(typeof s=="string")return s;let t=[];if(s[1]===0&&s[s.length-1]===0)for(let e=0;e<s.length;e+=2)t.push(Kt(s[e+1],s[e]));else for(let e=0;e<s.length;e+=2)t.push(Kt(s[e],s[e+1]));return qt(String.fromCodePoint(...t))}function Kt(s,t){return s<<8|t}K.set(41992,pt),K.set(41993,pt),K.set(41994,pt),k(N,["ifd0","ifd1"],[[50827,function(s){return typeof s!="string"?Zt(s):s}],[306,mt],[40091,_],[40092,_],[40093,_],[40094,_],[40095,_]]),k(N,"exif",[[40960,Xt],[36864,Xt],[36867,mt],[36868,mt],[40962,_t],[40963,_t]]),k(N,"gps",[[0,s=>Array.from(s).join(".")],[7,s=>Array.from(s).join(":")]]);var Y=class extends v{static canHandle(t,e){return t.getUint8(e+1)===225&&t.getUint32(e+4)===1752462448&&t.getString(e+4,20)==="http://ns.adobe.com/"}static headerLength(t,e){return t.getString(e+4,34)==="http://ns.adobe.com/xmp/extension/"?79:33}static findPosition(t,e){let i=super.findPosition(t,e);return i.multiSegment=i.extended=i.headerLength===79,i.multiSegment?(i.chunkCount=t.getUint8(e+72),i.chunkNumber=t.getUint8(e+76),t.getUint8(e+77)!==0&&i.chunkNumber++):(i.chunkCount=1/0,i.chunkNumber=-1),i}static handleMultiSegments(t){return t.map((e=>e.chunk.getString())).join("")}normalizeInput(t){return typeof t=="string"?t:O.from(t).getString()}parse(t=this.chunk){if(!this.localOptions.parse)return t;t=(function(r){let a={},o={};for(let h of oe)a[h]=[],o[h]=0;return r.replace(Le,((h,l,u)=>{if(l==="<"){let d=++o[u];return a[u].push(d),`${h}#${d}`}return`${h}#${a[u].pop()}`}))})(t);let e=ft.findAll(t,"rdf","Description");e.length===0&&e.push(new ft("rdf","Description",void 0,t));let i,n={};for(let r of e)for(let a of r.properties)i=Me(a.ns,n),ne(a,i);return(function(r){let a;for(let o in r)a=r[o]=et(r[o]),a===void 0&&delete r[o];return et(r)})(n)}assignToOutput(t,e){if(this.localOptions.parse)for(let[i,n]of Object.entries(e))switch(i){case"tiff":this.assignObjectToOutput(t,"ifd0",n);break;case"exif":this.assignObjectToOutput(t,"exif",n);break;case"xmlns":break;default:this.assignObjectToOutput(t,i,n)}else t.xmp=e}};c(Y,"type","xmp"),c(Y,"multiSegment",!0),b.set("xmp",Y);var Pt=class s{static findAll(t){return re(t,/([a-zA-Z0-9-]+):([a-zA-Z0-9-]+)=("[^"]*"|'[^']*')/gm).map(s.unpackMatch)}static unpackMatch(t){let e=t[1],i=t[2],n=t[3].slice(1,-1);return n=ae(n),new s(e,i,n)}constructor(t,e,i){this.ns=t,this.name=e,this.value=i}serialize(){return this.value}},ft=class s{static findAll(t,e,i){if(e!==void 0||i!==void 0){e=e||"[\\w\\d-]+",i=i||"[\\w\\d-]+";var n=new RegExp(`<(${e}):(${i})(#\\d+)?((\\s+?[\\w\\d-:]+=("[^"]*"|'[^']*'))*\\s*)(\\/>|>([\\s\\S]*?)<\\/\\1:\\2\\3>)`,"gm")}else n=/<([\w\d-]+):([\w\d-]+)(#\d+)?((\s+?[\w\d-:]+=("[^"]*"|'[^']*'))*\s*)(\/>|>([\s\S]*?)<\/\1:\2\3>)/gm;return re(t,n).map(s.unpackMatch)}static unpackMatch(t){let e=t[1],i=t[2],n=t[4],r=t[8];return new s(e,i,n,r)}constructor(t,e,i,n){this.ns=t,this.name=e,this.attrString=i,this.innerXml=n,this.attrs=Pt.findAll(i),this.children=s.findAll(n),this.value=this.children.length===0?ae(n):void 0,this.properties=[...this.attrs,...this.children]}get isPrimitive(){return this.value!==void 0&&this.attrs.length===0&&this.children.length===0}get isListContainer(){return this.children.length===1&&this.children[0].isList}get isList(){let{ns:t,name:e}=this;return t==="rdf"&&(e==="Seq"||e==="Bag"||e==="Alt")}get isListItem(){return this.ns==="rdf"&&this.name==="li"}serialize(){if(this.properties.length===0&&this.value===void 0)return;if(this.isPrimitive)return this.value;if(this.isListContainer)return this.children[0].serialize();if(this.isList)return Be(this.children.map(Ue));if(this.isListItem&&this.children.length===1&&this.attrs.length===0)return this.children[0].serialize();let t={};for(let e of this.properties)ne(e,t);return this.value!==void 0&&(t.value=this.value),et(t)}};function ne(s,t){let e=s.serialize();e!==void 0&&(t[s.name]=e)}var Ue=s=>s.serialize(),Be=s=>s.length===1?s[0]:s,Me=(s,t)=>t[s]?t[s]:t[s]={};function re(s,t){let e,i=[];if(!s)return i;for(;(e=t.exec(s))!==null;)i.push(e);return i}function ae(s){if((function(i){return i==null||i==="null"||i==="undefined"||i===""||i.trim()===""})(s))return;let t=Number(s);if(!Number.isNaN(t))return t;let e=s.toLowerCase();return e==="true"||e!=="false"&&s.trim()}var oe=["rdf:li","rdf:Seq","rdf:Bag","rdf:Alt","rdf:Description"],Le=new RegExp(`(<|\\/)(${oe.join("|")})`,"g"),he=Ie;async function Ve(s){try{return await he.parse(s)||null}catch{return null}}function Re(){return Array.from(crypto.getRandomValues(new Uint8Array(16)),s=>s.toString(16).padStart(2,"0")).join("")}async function je(s){if(typeof createImageBitmap>"u"||typeof document>"u"){if(s&&typeof s.arrayBuffer=="function"){let o=await s.arrayBuffer(),h=globalThis.Buffer,l=typeof h<"u"?h.from(o).toString("base64"):btoa(String.fromCharCode(...new Uint8Array(o)));return`data:${s.type||"image/png"};base64,${l}`}if(typeof s=="string")return s}let t=await createImageBitmap(s),n=Math.min(1,1654/t.width,2339/t.height);if(n===1&&(s.type==="image/jpeg"||s.type==="image/jpg"||s.type==="image/png"||s.type==="image/webp"))return t.close(),new Promise((o,h)=>{let l=new FileReader;l.onload=()=>o(l.result),l.onerror=h,l.readAsDataURL(s)});let r=document.createElement("canvas");r.width=Math.round(t.width*n),r.height=Math.round(t.height*n),r.getContext("2d").drawImage(t,0,0,r.width,r.height),t.close();let a=s.type==="image/png"?"image/png":"image/jpeg";return r.toDataURL(a,a==="image/png"?void 0:.82)}function le(s,t=21,e=.2,i=128){let{data:n,width:r,height:a}=s,o=r+1,h=new Float64Array((r+1)*(a+1)),l=new Float64Array((r+1)*(a+1)),u=new Uint8Array(r*a);for(let f=0;f<a;f++){let g=0,S=0,U=f*r,B=(f+1)*o,A=f*o;for(let w=0;w<r;w++){let x=(U+w)*4,M=n[x]*77+n[x+1]*150+n[x+2]*29>>8;u[U+w]=M,g+=M,S+=M*M,h[B+w+1]=h[A+w+1]+g,l[B+w+1]=l[A+w+1]+S}}let d=Math.floor(t/2);for(let f=0;f<a;f++){let g=Math.max(0,f-d),S=Math.min(a-1,f+d),U=g*o,B=(S+1)*o;for(let A=0;A<r;A++){let w=Math.max(0,A-d),x=Math.min(r-1,A+d),M=(x-w+1)*(S-g+1),ue=h[B+x+1]-h[U+x+1]-h[B+w]+h[U+w],de=l[B+x+1]-l[U+x+1]-l[B+w]+l[U+w],ut=ue/M,ce=Math.max(0,de/M-ut*ut),ge=Math.sqrt(ce),pe=ut*(1+e*(ge/i-1)),Tt=f*r+A,dt=u[Tt]<pe?0:255,ct=Tt*4;n[ct]=dt,n[ct+1]=dt,n[ct+2]=dt}}return s}function Ge(s,t=21,e=.2,i=128){return new Promise(n=>{let r=new Image;r.onload=()=>{let a=document.createElement("canvas");a.width=r.width,a.height=r.height;let o=a.getContext("2d");o.drawImage(r,0,0);let h=o.getImageData(0,0,a.width,a.height);le(h,t,e,i),o.putImageData(h,0,0);let l=s.startsWith("data:image/png"),u=l?"image/png":"image/jpeg";n(a.toDataURL(u,l?void 0:.82))},r.src=s})}function He(s){return new Promise(t=>{let e=new Image;e.onload=()=>{let i=document.createElement("canvas");i.width=e.height,i.height=e.width;let n=i.getContext("2d");n.translate(i.width/2,i.height/2),n.rotate(Math.PI/2),n.drawImage(e,-e.width/2,-e.height/2);let r=s.startsWith("data:image/png"),a=r?"image/png":"image/jpeg";t(i.toDataURL(a,r?void 0:.82))},e.src=s})}function We(s,t=""){if(!s)return"";let e=s.getCroppedCanvas(),i=t.startsWith("data:image/png"),n=i?"image/png":"image/jpeg";return e.toDataURL(n,i?void 0:.82)}function Dt(s){if(!s||typeof s!="object")return{crop:null,rotation:0,filter:"none"};let t=null;s.crop&&typeof s.crop=="object"&&(s.crop.width>0&&s.crop.height>0?t={x:Math.round(s.crop.x||0),y:Math.round(s.crop.y||0),width:Math.round(s.crop.width),height:Math.round(s.crop.height)}:s.crop.w>0&&s.crop.h>0&&(t={x:Number(s.crop.x)||0,y:Number(s.crop.y)||0,w:Number(s.crop.w)||1,h:Number(s.crop.h)||1}));let e=s.rotation!==void 0?s.rotation:s.rotate,i=(Math.round(Number(e)||0)%360+360)%360,n=s.filter==="bw"?"bw":"none";return{crop:t,rotation:i,filter:n}}function De(s){if(!s)return!1;let t=Dt(s);return!!(t.crop||t.rotation!==0||t.filter!=="none")}function Ft(s,t){let e=Dt(t),i=s.naturalWidth||s.width||0,n=s.naturalHeight||s.height||0,r=document.createElement("canvas"),a=i,o=n,h=0,l=0;if(e.crop){let f=e.crop;"w"in f&&!("width"in f)?(h=Math.max(0,Math.min(Math.round(f.x*i),i)),l=Math.max(0,Math.min(Math.round(f.y*n),n)),a=Math.max(1,Math.min(Math.round(f.w*i),i-h)),o=Math.max(1,Math.min(Math.round(f.h*n),n-l))):(h=Math.max(0,Math.min(f.x,i)),l=Math.max(0,Math.min(f.y,n)),a=Math.max(1,Math.min(f.width,i-h)),o=Math.max(1,Math.min(f.height,n-l)))}r.width=a,r.height=o,r.getContext("2d").drawImage(s,h,l,a,o,0,0,a,o);let d=r;if(e.rotation!==0){let f=e.rotation,g=document.createElement("canvas");f===90||f===270?(g.width=d.height,g.height=d.width):(g.width=d.width,g.height=d.height);let S=g.getContext("2d");S.translate(g.width/2,g.height/2),S.rotate(f*Math.PI/180),S.drawImage(d,-d.width/2,-d.height/2),d=g}if(e.filter==="bw"){let f=d.getContext("2d"),g=f.getImageData(0,0,d.width,d.height);le(g),f.putImageData(g,0,0)}return d}function $e(s,t){if(!s)return Promise.resolve("");let e=Dt(t);return De(e)?new Promise((i,n)=>{let r=new Image;r.onload=()=>{try{let a=s.startsWith("data:image/png"),o=a?"image/png":"image/jpeg",h=Ft(r,e);i(h.toDataURL(o,a?void 0:.82))}catch(a){n(a)}},r.onerror=n,r.src=s}):Promise.resolve(s)}function Fe(s){return new Promise((t,e)=>{let i=new Image;i.onload=()=>t(i),i.onerror=e,i.src=s})}var fe=class extends Et{async renderEdits(t,e={}){if(!t)return"";if(typeof document>"u")return t;try{let i=await Fe(t),n={...e};return e?.crop&&"w"in e.crop&&(n.crop={x:Math.round((e.crop.x||0)*i.naturalWidth),y:Math.round((e.crop.y||0)*i.naturalHeight),width:Math.round((e.crop.w||1)*i.naturalWidth),height:Math.round((e.crop.h||1)*i.naturalHeight)}),e?.rotate!==void 0&&(n.rotation=e.rotate),Ft(i,n).toDataURL("image/jpeg",.92)}catch{return t}}async crop(t,e){return this.renderEdits(t,{crop:e})}async rotate(t,e){return this.renderEdits(t,{rotate:e})}async applyFilter(t,e){return this.renderEdits(t,{filter:e})}};export{Ve as a,Re as b,je as c,le as d,Ge as e,He as f,We as g,Dt as h,De as i,Ft as j,$e as k,fe as l};
|
|
4
|
+
//# sourceMappingURL=chunk-534NMCRQ.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as r}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as r}from"./chunk-O6FQFVKY.js";var o=class extends r{async exportDocumentAsPdf(s,n,d={}){let e=new Error('Feature "pdf" is disabled or PDF module not opted in');throw e.code="FEATURE_DISABLED",e}async renderPdfPagesToDataUrls(s){return[]}};export{o as a};
|
|
2
|
+
//# sourceMappingURL=chunk-5OTO5WFV.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var t=class{async recognizeImageText(e,r={}){throw new Error("OcrPort.recognizeImageText() must be implemented by adapter")}async recognizeDocumentPages(e,r={}){throw new Error("OcrPort.recognizeDocumentPages() must be implemented by adapter")}async getOcrWorker(e="eng",r=null){throw new Error("OcrPort.getOcrWorker() must be implemented by adapter")}async terminateOcrWorker(){throw new Error("OcrPort.terminateOcrWorker() must be implemented by adapter")}};export{t as a};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-6DSLE3AY.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=class{async init(){throw new Error("StoragePort.init() must be implemented by adapter")}async listDocs(){throw new Error("StoragePort.listDocs() must be implemented by adapter")}async getDoc(e){throw new Error("StoragePort.getDoc() must be implemented by adapter")}async saveDoc(e,t){throw new Error("StoragePort.saveDoc() must be implemented by adapter")}async renameDoc(e,t){let r=await this.getDoc(e);if(!r)throw new Error(`Document "${e}" not found`);r.name=t,await this.saveDoc(e,r)}async deleteDoc(e){throw new Error("StoragePort.deleteDoc() must be implemented by adapter")}async savePage(e,t,r){throw new Error("StoragePort.savePage() must be implemented by adapter")}async getPage(e,t){throw new Error("StoragePort.getPage() must be implemented by adapter")}async deletePage(e,t){throw new Error("StoragePort.deletePage() must be implemented by adapter")}subscribe(e){return()=>{}}};export{a};
|
|
2
|
+
//# sourceMappingURL=chunk-DIU5BGU5.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as F,b as m,c as O,k as R,l as L}from"./chunk-534NMCRQ.js";import{a as N}from"./chunk-KH5JE65X.js";import{c as D}from"./chunk-RDCHJL6F.js";import{d as P}from"./chunk-IH2AI54D.js";import{a as f}from"./chunk-U3V3VZGO.js";import{a as w}from"./chunk-5OTO5WFV.js";import{a as B,b as v}from"./chunk-ZT72PD2C.js";var g=class{#e=null;#t=new Map;#i=new Map;constructor(e=D()){this.#e=e}get adapter(){return this.#e}get store(){return this.#e?.store??null}async init(){return this.#e.init()}listDocsSync(){return typeof this.#e.listDocsSync=="function"?this.#e.listDocsSync().map(t=>{let s=this.#r(t.pages);return{id:t.id,name:t.name||"",pageCount:s.length,pages:s}}):[]}async listDocs(){return(await this.#e.listDocs()).map(t=>{let s=this.#r(t.pages);return{id:t.id,name:t.name||"",pageCount:s.length,pages:s}})}getDocSync(e){if(!e)return null;if(typeof this.#e.getDocSync=="function"){let r=this.#e.getDocSync(e);return r?{id:r.id,name:r.name||"",pages:this.#r(r.pages)}:null}let s=this.listDocsSync().find(r=>r.id===e);return s?{id:s.id,name:s.name,pages:s.pages||[]}:null}async getDoc(e){if(!e)return null;if(typeof this.#e.getDoc=="function"){let t=await this.#e.getDoc(e);return t?{id:t.id,name:t.name||"",pages:this.#r(t.pages)}:null}return this.getDocSync(e)}async createDoc(e="Untitled Document",t=[]){let s=m(),r=this.#r(t),o={id:s,name:e||"Untitled Document",pages:r};return await this.#e.saveDoc(s,o),o}async saveDoc(e,t){if(!e)throw new Error("Cannot save document without an ID");let s=this.#r(t.pages);await this.#e.saveDoc(e,{id:e,name:t.name||"",pages:s})}async renameDoc(e,t){if(typeof this.#e.renameDoc=="function")return this.#e.renameDoc(e,t);let s=await this.getDoc(e);if(!s)throw new Error(`Document "${e}" not found`);s.name=t,await this.saveDoc(e,s)}async deleteDoc(e,{soft:t=!0,timeoutMs:s=5e3}={}){if(!e)return;let r=this.getDocSync(e);if(r){if(this.#n(e),await this.#e.deleteDoc(e),t&&s>0){let o=setTimeout(async()=>{this.#t.delete(e)},s);this.#t.set(e,{doc:r,timerId:o})}return{id:e,name:r.name,undo:()=>this.undoDeleteDoc(e)}}}#n(e){if(this.#t.has(e)){let t=this.#t.get(e);clearTimeout(t.timerId),this.#t.delete(e)}}async undoDeleteDoc(e){let t=this.#t.get(e);return t?(clearTimeout(t.timerId),this.#t.delete(e),await this.#e.saveDoc(e,t.doc),t.doc):null}isSoftDeletedDoc(e){return this.#t.has(e)}async addPages(e,t){let s=await this.getDoc(e);if(!s)throw new Error(`Document "${e}" not found`);let r=Array.isArray(t)?t:[t];s.pages.push(...r),await this.saveDoc(e,s)}async updatePage(e,t,s){let r=await this.getDoc(e);if(!r)throw new Error(`Document "${e}" not found`);let o=r.pages.findIndex(i=>i.id===t);if(o===-1)throw new Error(`Page "${t}" not found in document "${e}"`);r.pages[o]={...r.pages[o],...s},await this.saveDoc(e,r)}async reorderPages(e,t){let s=await this.getDoc(e);if(!s)throw new Error(`Document "${e}" not found`);let r=new Map(s.pages.map(i=>[i.id,i])),o=[];for(let i of t)r.has(i)&&(o.push(r.get(i)),r.delete(i));for(let i of r.values())o.push(i);s.pages=o,await this.saveDoc(e,s)}async deletePage(e,t,{soft:s=!0,timeoutMs:r=5e3}={}){let o=await this.getDoc(e);if(!o)throw new Error(`Document "${e}" not found`);let i=o.pages.findIndex(h=>h.id===t);if(i===-1)return;let[a]=o.pages.splice(i,1);await this.saveDoc(e,o);let u=`${e}:${t}`;if(this.#d(u),!s||r<=0){if(typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(h){console.warn("[DocRepository] Adapter deletePage error:",h)}return}let c=setTimeout(async()=>{if(this.#i.delete(u),typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(h){console.warn("[DocRepository] Adapter deletePage error:",h)}},r);return this.#i.set(u,{docId:e,pageId:t,page:a,index:i,timerId:c}),{docId:e,pageId:t,undo:()=>this.undoDeletePage(e,t)}}#d(e){if(this.#i.has(e)){let t=this.#i.get(e);clearTimeout(t.timerId),this.#i.delete(e)}}async undoDeletePage(e,t){let s=`${e}:${t}`,r=this.#i.get(s);if(!r)return null;clearTimeout(r.timerId),this.#i.delete(s);let o=await this.getDoc(e);if(!o)return null;let i=Math.min(r.index,o.pages.length);return o.pages.splice(i,0,r.page),await this.saveDoc(e,o),r.page}isSoftDeletedPage(e,t){return this.#i.has(`${e}:${t}`)}subscribe(e){return this.#e.subscribe(e)}async getAllDocs(){let e=await this.listDocs(),t={};for(let s of e)t[s.id]=s;return t}async exportAll(){let e=await this.listDocs(),t={};for(let s of e){let r=await this.getDoc(s.id),o=[];for(let i of r?.pages||[]){if(!i){o.push(i);continue}let a={...i},u=a.blob instanceof Blob?a.blob:null;if(!u&&typeof a.src=="string"&&a.src.startsWith("blob:"))try{u=await(await fetch(a.src)).blob()}catch{}u&&(a.src=await P(u));let c=a.originalBlob instanceof Blob?a.originalBlob:null;if(!c&&typeof a.originalSrc=="string"&&a.originalSrc.startsWith("blob:"))try{c=await(await fetch(a.originalSrc)).blob()}catch{}c&&(a.originalSrc=await P(c)),delete a.blob,delete a.originalBlob,o.push(a)}t[s.id]={name:s.name,pages:JSON.stringify(o)}}return t}async importDocs(e){let t=0;for(let[s,r]of Object.entries(e||{})){await this.getDoc(s)||t++;let i=this.#r(r.pages);await this.saveDoc(s,{name:r.name||"",pages:i})}return t}#r(e){if(Array.isArray(e))return[...e];if(typeof e=="string")try{return JSON.parse(e)}catch{return[]}return[]}},W=new g;var k="2026-11-06T11:31:52.811Z",z="0.1.3";function S(n={}){let e=n&&n.crop&&typeof n.crop=="object"?{x:Math.max(0,Math.min(1,Number(n.crop.x)||0)),y:Math.max(0,Math.min(1,Number(n.crop.y)||0)),w:Math.max(0,Math.min(1,Number(n.crop.w)||1)),h:Math.max(0,Math.min(1,Number(n.crop.h)||1))}:null,t=0,s=n?.rotate!==void 0?n.rotate:n?.rotation;if(s!==void 0){let o=(Math.round(Number(s)/90)*90%360+360)%360;(o===90||o===180||o===270)&&(t=o)}let r=n&&n.filter==="bw"?"bw":"none";return{crop:e,rotate:t,filter:r}}function U(n){if(!n)return!1;let e=n.rotate!==void 0?n.rotate:n.rotation;return!!(n.crop||e&&e!==0||n.filter&&n.filter!=="none")}var d=n=>Math.round(n*1e6)/1e6;function M(n,e=0){if(!n)return null;let t=(Math.round(Number(e)/90)*90%360+360)%360,{x:s,y:r,w:o,h:i}=n;return t===90?{x:d(Math.max(0,Math.min(1,1-r-i))),y:d(Math.max(0,Math.min(1,s))),w:d(Math.max(.01,Math.min(1,i))),h:d(Math.max(.01,Math.min(1,o)))}:t===180?{x:d(Math.max(0,Math.min(1,1-s-o))),y:d(Math.max(0,Math.min(1,1-r-i))),w:d(Math.max(.01,Math.min(1,o))),h:d(Math.max(.01,Math.min(1,i)))}:t===270?{x:d(Math.max(0,Math.min(1,r))),y:d(Math.max(0,Math.min(1,1-s-o))),w:d(Math.max(.01,Math.min(1,i))),h:d(Math.max(.01,Math.min(1,o)))}:{x:d(Math.max(0,Math.min(1,s))),y:d(Math.max(0,Math.min(1,r))),w:d(Math.max(.01,Math.min(1,o))),h:d(Math.max(.01,Math.min(1,i)))}}function j(n,e=0){return M(n,e)}function G(n,e=0){return M(n,-e)}var y=class{constructor(e){this.id=e.id,this.src=e.src,this.originalSrc=e.originalSrc||e.src,this.edits=S(e.edits),this.name=e.name||"Page",this.type=e.type||"image",this.orientation=e.orientation||1,this.ocrText=e.ocrText||null,this.ocrConfidence=e.ocrConfidence??null,this.ocrWords=Array.isArray(e.ocrWords)?e.ocrWords:null,this.ocrWidth=typeof e.ocrWidth=="number"?e.ocrWidth:null,this.ocrHeight=typeof e.ocrHeight=="number"?e.ocrHeight:null}get isModified(){return U(this.edits)}toJSON(){return{id:this.id,src:this.src,originalSrc:this.originalSrc,edits:this.edits,name:this.name,type:this.type,orientation:this.orientation,ocrText:this.ocrText,ocrConfidence:this.ocrConfidence,ocrWords:this.ocrWords,ocrWidth:this.ocrWidth,ocrHeight:this.ocrHeight}}},A=class{constructor(e){this.id=e.id,this.name=e.name||"Untitled Document",this.pages=Array.isArray(e.pages)?e.pages.map(t=>t instanceof y?t:new y(t)):[],this.createdAt=e.createdAt||Date.now(),this.updatedAt=e.updatedAt||Date.now()}get pageCount(){return this.pages.length}toJSON(){return{id:this.id,name:this.name,pages:this.pages.map(e=>e.toJSON()),createdAt:this.createdAt,updatedAt:this.updatedAt}}},b=class{constructor(e={}){this.mode=e.mode==="single"?"single":"batch",this.aspect=e.aspect||"auto",this.docId=e.docId||null,this.maxPages=Math.max(0,Number(e.maxPages)||0),this.stage="viewfinder",this.activePageIndex=0,this.history=[],this.future=[]}pushHistory(e){this.history.push(e),this.future=[],this.history.length>50&&this.history.shift()}undo(){if(this.history.length===0)return null;let e=this.history.pop();return this.future.push(e),e}redo(){if(this.future.length===0)return null;let e=this.future.pop();return this.history.push(e),e}};var H={PAGE_ADDED:"copio:page-added",PAGE_REMOVED:"copio:page-removed",PAGES_CHANGED:"copio:pages-changed",SCAN_COMPLETE:"copio:scan-complete",EXPORT_PROGRESS:"copio:export-progress",EXPORT_COMPLETE:"copio:export-complete",OCR_COMPLETE:"copio:ocr-complete",SYNC_CONNECTED:"copio:sync-connected",ERROR:"copio:error"};function J(n,e,t={}){let s=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:!0,detail:t});return n&&typeof n.dispatchEvent=="function"&&n.dispatchEvent(s),s}var I=["crop","rotate","filter","ocr","export","sync"],_=["pdf","zip","png","jpg"],T=["eng"],C={};function Se(n,e){!n||!e||(C[n]=e,typeof globalThis<"u"&&(globalThis.__copio_services__=globalThis.__copio_services__||{},globalThis.__copio_services__[n]=e))}function p(n){return C[n]?C[n]:typeof globalThis<"u"&&globalThis.__copio_services__?.[n]?globalThis.__copio_services__[n]:null}function K(n){return n?n instanceof Set?new Set(n):Array.isArray(n)?new Set(n.map(e=>String(e).trim().toLowerCase()).filter(Boolean)):typeof n=="string"?new Set(n.split(/[\s,]+/).map(e=>e.trim().toLowerCase()).filter(Boolean)):new Set(I):new Set(I)}function x(n,e){return n?Array.isArray(n)?n.map(t=>String(t).trim().toLowerCase()).filter(Boolean):typeof n=="string"?n.split(/[\s,]+/).map(t=>t.trim().toLowerCase()).filter(Boolean):[...e]:[...e]}var $=class{#e=new Set(I);#t=[..._];#i=[...T];#n=0;#d="";#r=null;#s=null;#l={};#a=!0;#h=!0;#o=null;#c=new Map;#u=new Map;constructor(e={}){this.#r=e.storage||D(e),this.#s=e.repository||new g(this.#r),e.services&&(this.#l={...e.services}),e.imageProcessor?(this.#o=e.imageProcessor,this.#l.imageProcessor=e.imageProcessor):this.getService("imageProcessor")?this.#o=this.getService("imageProcessor"):typeof document<"u"?this.#o=new L:this.#o=new N,e.features!==void 0&&this.setFeatures(e.features),e.exportFormats!==void 0&&(this.#t=x(e.exportFormats,_)),e.ocrLanguages!==void 0&&(this.#i=x(e.ocrLanguages,T)),e.maxPages!==void 0&&(this.#n=Math.max(0,Number(e.maxPages)||0)),e.assetBase!==void 0&&v(e.assetBase),e.licenseKey!==void 0&&(this.#d=String(e.licenseKey||"")),e.ocr!==void 0?this.ocr=!!e.ocr:e.features!==void 0&&!this.hasFeature("ocr")&&(this.ocr=!1),e.pdf!==void 0?this.pdf=!!e.pdf:e.exportFormats!==void 0&&!this.#t.includes("pdf")&&(this.pdf=!1)}async init(){return this.#r.init()}setService(e,t){this.#l[e]=t}getService(e){return this.#l[e]||p(e)}hasFeature(e){return e?this.#e.has(String(e).trim().toLowerCase()):!1}get features(){return Array.from(this.#e)}setFeatures(e){this.#e=K(e),this.hasFeature("ocr")?(this.#a=!0,this.getService("ocr")instanceof f&&this.setService("ocr",p("ocr"))):(this.#a=!1,this.setService("ocr",new f))}enableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.add(t),t==="ocr"&&(this.#a=!0,this.getService("ocr")instanceof f&&this.setService("ocr",p("ocr")))}}disableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.delete(t),t==="ocr"&&(this.#a=!1,this.setService("ocr",new f))}}get ocr(){return this.#a&&this.hasFeature("ocr")}set ocr(e){this.#a=!!e,this.#a?(this.enableFeature("ocr"),this.getService("ocr")instanceof f&&this.setService("ocr",p("ocr"))):(this.disableFeature("ocr"),this.setService("ocr",new f))}get pdf(){return this.#h&&this.#t.includes("pdf")}set pdf(e){this.#h=!!e,this.#h?(this.#t.includes("pdf")||this.#t.push("pdf"),this.getService("pdf")instanceof w&&this.setService("pdf",p("pdf"))):(this.#t=this.#t.filter(t=>t!=="pdf"),this.setService("pdf",new w))}get exportFormats(){return[...this.#t]}set exportFormats(e){this.#t=x(e,_),this.#t.includes("pdf")?(this.#h=!0,this.getService("pdf")instanceof w&&this.setService("pdf",p("pdf"))):(this.#h=!1,this.setService("pdf",new w))}get ocrLanguages(){return[...this.#i]}set ocrLanguages(e){this.#i=x(e,T)}get maxPages(){return this.#n}set maxPages(e){this.#n=Math.max(0,Number(e)||0)}get assetBase(){return B()}set assetBase(e){v(e)}get licenseKey(){return this.#d}set licenseKey(e){this.#d=String(e||"")}get storage(){return this.#r}setStorage(e){e&&(this.#r=e,this.#s=new g(this.#r))}#f(e,t){this.#c.has(e)||this.#c.set(e,[]);let s=this.#c.get(e);s.push(t),s.length>50&&s.shift(),this.#u.has(e)&&(this.#u.get(e).length=0)}get imageProcessor(){return this.#o}setImageProcessor(e){e&&(this.#o=e,this.setService("imageProcessor",e))}async renderEdits(e,t){if(!e)return"";let s=S(t);return this.#o?this.#o.renderEdits(e,s):R(e,s)}get docs(){return this.#s}async listDocuments(){return this.#s.listDocs()}async getDocument(e){return this.#s.getDoc(e)}async createDocument(e,t){return this.#s.createDoc(e,t)}async deleteDocument(e,t={}){return this.#s.deleteDoc(e,t)}async undoDeleteDocument(e){return this.#s.undoDeleteDoc(e)}async renameDocument(e,t){return this.#s.renameDoc(e,t)}async addPages(e,t){return this.#s.addPages(e,t)}async deletePage(e,t,s={}){return this.#f(e,{type:"delete",pageId:t}),this.#s.deletePage(e,t,s)}async undoDeletePage(e,t){return this.#s.undoDeletePage(e,t)}async updatePage(e,t,s){return this.#s.updatePage(e,t,s)}async reorderPages(e,t){let s=await this.getDocument(e),r=s?.pages?s.pages.map(o=>o.id):[];return this.#f(e,{type:"reorder",priorOrder:r,newOrder:[...t]}),this.#s.reorderPages(e,t)}async#g(e){if(e)return e;let t=await this.listDocuments();return t.length>0?t[0].id:null}async applyEdit(e,t,s){let r=await this.#g(e),o=r?await this.getDocument(r):null;if(!o||!o.pages)throw new Error(`Document with ID "${r||e}" not found`);let i=o.pages.find(E=>E.id===t);if(!i)throw new Error(`Page with ID "${t}" not found in document "${r}"`);let a={...i.edits||{crop:null,rotate:0,filter:"none"}},u=i.src,c=S({...a,...s}),h=i.originalSrc||i.src,l=h;return this.#o&&(l=await this.#o.renderEdits(h,c)),await this.updatePage(r,t,{originalSrc:h,src:l,edits:c}),this.#f(r,{type:"edit",pageId:t,priorEdits:a,priorSrc:u,newEdits:c,newSrc:l}),{...i,originalSrc:h,src:l,edits:c}}async undo(e){let t=await this.#g(e),s=t?this.#c.get(t):null;if(!s||s.length===0)return null;let r=s.pop();return this.#u.has(t)||this.#u.set(t,[]),this.#u.get(t).push(r),r.type==="edit"?(await this.updatePage(t,r.pageId,{edits:r.priorEdits,src:r.priorSrc}),{type:"edit",pageId:r.pageId,restoredEdits:r.priorEdits}):r.type==="delete"?(await this.undoDeletePage(t,r.pageId),{type:"delete",pageId:r.pageId}):r.type==="reorder"?(await this.#s.reorderPages(t,r.priorOrder),{type:"reorder",priorOrder:r.priorOrder}):r}async redo(e){let t=await this.#g(e),s=t?this.#u.get(t):null;if(!s||s.length===0)return null;let r=s.pop();return this.#c.has(t)||this.#c.set(t,[]),this.#c.get(t).push(r),r.type==="edit"?(await this.updatePage(t,r.pageId,{edits:r.newEdits,src:r.newSrc}),{type:"edit",pageId:r.pageId,appliedEdits:r.newEdits}):r.type==="delete"?(await this.deletePage(t,r.pageId),{type:"delete",pageId:r.pageId}):r.type==="reorder"?(await this.reorderPages(t,r.newOrder),{type:"reorder",newOrder:r.newOrder}):r}subscribe(e){return this.#s.subscribe(e)}async addFiles(e,t=null){if(!e||e.length===0)return[];let s=Array.from(e),r=[];for(let i of s)if(i.type==="application/pdf"){let a=this.getService("pdf");if(a&&typeof a.renderPdfPagesToDataUrls=="function"){let u=await a.renderPdfPagesToDataUrls(i);for(let c of u)r.push({id:m(),src:c,originalSrc:c,edits:{crop:null,rotation:0,filter:"none"},type:"image",name:i.name||"PDF Page"})}else console.warn("PDF import service (PdfPort) not registered. Skipping PDF file.")}else if(i.type&&i.type.startsWith("image/")){let a=await O(i),u=null;try{u=await F(i)}catch{}r.push({id:m(),src:a,originalSrc:a,edits:{crop:null,rotation:0,filter:"none"},type:"image",name:i.name||"Captured Image",orientation:u})}if(r.length===0)return[];await this.init();let o=t;if(o)await this.getDocument(o)||await this.#s.saveDoc(o,{name:"Scanned Document",pages:[]});else{let i=await this.listDocuments();i.length>0?o=i[0].id:o=(await this.createDocument("Scanned Document",[])).id}if(this.#n>0){let i=(await this.getDocument(o))?.pages||[],a=Math.max(0,this.#n-i.length);if(a<=0)throw new Error(`Maximum page limit (${this.#n}) reached`);r.splice(a)}return await this.addPages(o,r),r}async getPages(e=null){let t=e;if(!t){let r=await this.listDocuments();if(r.length===0)return[];t=r[0].id}return(await this.getDocument(t))?.pages||[]}async clear(e=null){let t=e;if(!t){let r=await this.listDocuments();if(r.length===0)return;t=r[0].id}let s=await this.getDocument(t);if(!(!s||!s.pages))for(let r of s.pages)await this.deletePage(t,r.id)}async#p(e){if(Array.isArray(e))return{docName:"document",pages:e,docId:null};if(typeof e=="string"){let s=await this.getDocument(e);return{docName:s?.name||"document",pages:s?.pages||[],docId:e}}let t=await this.listDocuments();if(t.length>0){let s=await this.getDocument(t[0].id);return{docName:s?.name||"document",pages:s?.pages||[],docId:t[0].id}}return{docName:"document",pages:[],docId:null}}async exportPdf(e,t={}){if(!this.hasFeature("export")){let i=new Error('Feature "export" is disabled');throw Object.assign(i,{code:"FEATURE_DISABLED"}),i}if(!this.#h||!this.#t.includes("pdf")){let i=new Error('Feature "pdf" is disabled');throw Object.assign(i,{code:"FEATURE_DISABLED"}),i}let{docName:s,pages:r}=await this.#p(e),o=this.getService("pdf")||this.getService("export");if(!o||typeof o.exportDocumentAsPdf!="function")throw new Error("Export service (PdfPort) is not registered. Import @copio/sdk or register an exportService.");return o.exportDocumentAsPdf(s,r,{download:!1,showProgress:!1,onOcrComplete:async()=>{if(typeof e=="string"){let i=await this.#r.getDoc(e);i&&(i.pages=r,await this.#r.saveDoc(e,i))}},...t})}async exportZip(e,t={}){if(!this.hasFeature("export")){let i=new Error('Feature "export" is disabled');throw Object.assign(i,{code:"FEATURE_DISABLED"}),i}let{docName:s,pages:r}=await this.#p(e),o=this.getService("export");if(!o||typeof o.exportDocumentAsImages!="function")throw new Error("Export service is not registered. Import @copio/sdk or register an exportService.");return o.exportDocumentAsImages(s,r,{download:!1,showProgress:!1,...t})}async runOcr(e,t=null,s={}){if(!this.#a||!this.hasFeature("ocr")){let c=new Error('Feature "ocr" is disabled');throw Object.assign(c,{code:"FEATURE_DISABLED"}),c}let{pages:r}=await this.#p(e),o=r;t&&(o=r.filter(c=>c.id===t));let i=this.getService("ocr");if(!i||typeof i.recognizeDocumentPages!="function")throw new Error("OCR service (OcrPort) is not registered. Import @copio/sdk or register an ocrService.");let a=s.lang||this.#i[0]||"eng",u=await i.recognizeDocumentPages(o,{lang:a,...s});if(Array.isArray(u.pagesResults)){for(let c of u.pagesResults){let h=o.find(l=>l.id===c.pageId)||o[c.pageIndex];h&&(h.ocrText=c.text,h.ocrConfidence=c.confidence,h.ocrWords=c.words)}if(typeof e=="string"){let c=await this.#r.getDoc(e);if(c&&Array.isArray(c.pages)){for(let h of u.pagesResults){let l=c.pages.find(E=>E.id===h.pageId)||c.pages[h.pageIndex];l&&(l.ocrText=h.text,l.ocrConfidence=h.confidence,l.ocrWords=h.words)}await this.#r.saveDoc(e,c)}}}return{text:u.combinedText,...u}}async sync(e={}){if(!this.hasFeature("sync")){let s=new Error('Feature "sync" is disabled');throw Object.assign(s,{code:"FEATURE_DISABLED"}),s}let t=this.getService("sync");if(!t)throw new Error("Sync service (SyncPort) is not registered. Import @copio/sdk or register a syncService.");return new t(this.#s,e.onStateChange)}};export{g as a,W as b,k as c,z as d,S as e,U as f,M as g,j as h,G as i,y as j,A as k,b as l,H as m,J as n,I as o,_ as p,T as q,Se as r,p as s,$ as t};
|
|
2
|
+
//# sourceMappingURL=chunk-DOKG4LX2.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a}from"./chunk-4YYY7PHH.js";import{a as t}from"./chunk-O6FQFVKY.js";import{a as e}from"./chunk-MEE2NNYB.js";var s=class extends t{async exportDocumentAsPdf(r,o,n={}){return e(r,o,n)}async renderPdfPagesToDataUrls(r){let o=r instanceof ArrayBuffer?r:await r.arrayBuffer();return a(o)}};export{s as a};
|
|
2
|
+
//# sourceMappingURL=chunk-DY5ZSP4Q.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{d as P}from"./chunk-YNY65JUJ.js";import{c as h,j as w}from"./chunk-ZT72PD2C.js";var A=[{code:"eng",label:"English",flag:"\u{1F1EC}\u{1F1E7}"},{code:"spa",label:"Spanish (Espa\xF1ol)",flag:"\u{1F1EA}\u{1F1F8}"},{code:"fra",label:"French (Fran\xE7ais)",flag:"\u{1F1EB}\u{1F1F7}"},{code:"deu",label:"German (Deutsch)",flag:"\u{1F1E9}\u{1F1EA}"},{code:"ita",label:"Italian (Italiano)",flag:"\u{1F1EE}\u{1F1F9}"},{code:"por",label:"Portuguese (Portugu\xEAs)",flag:"\u{1F1F5}\u{1F1F9}"},{code:"nld",label:"Dutch (Nederlands)",flag:"\u{1F1F3}\u{1F1F1}"},{code:"pol",label:"Polish (Polski)",flag:"\u{1F1F5}\u{1F1F1}"},{code:"rus",label:"Russian (\u0420\u0443\u0441\u0441\u043A\u0438\u0439)",flag:"\u{1F1F7}\u{1F1FA}"},{code:"chi_sim",label:"Chinese Simplified (\u7B80\u4F53\u4E2D\u6587)",flag:"\u{1F1E8}\u{1F1F3}"},{code:"chi_tra",label:"Chinese Traditional (\u7E41\u9AD4\u4E2D\u6587)",flag:"\u{1F1F9}\u{1F1FC}"},{code:"jpn",label:"Japanese (\u65E5\u672C\u8A9E)",flag:"\u{1F1EF}\u{1F1F5}"},{code:"kor",label:"Korean (\uD55C\uAD6D\uC5B4)",flag:"\u{1F1F0}\u{1F1F7}"},{code:"ara",label:"Arabic (\u0627\u0644\u0639\u0631\u0628\u064A\u0629)",flag:"\u{1F1F8}\u{1F1E6}"},{code:"hin",label:"Hindi (\u0939\u093F\u0928\u094D\u0926\u0940)",flag:"\u{1F1EE}\u{1F1F3}"},{code:"tur",label:"Turkish (T\xFCrk\xE7e)",flag:"\u{1F1F9}\u{1F1F7}"},{code:"vie",label:"Vietnamese (Ti\u1EBFng Vi\u1EC7t)",flag:"\u{1F1FB}\u{1F1F3}"}],g=null,x=null,u=null;function C(e){return e==="eng"?h("assets/tessdata"):"https://tessdata.projectnaptha.com/4.0.0_fast"}function k(e,f=0){let t=Math.round((f||0)*100);switch(e){case"loading tesseract core":return`Downloading OCR engine... ${t>0?t+"%":""}`.trim();case"initializing tesseract":return"Initializing OCR engine...";case"loading language traineddata":case"loaded language traineddata":return`Loading language data... ${t>0?t+"%":""}`.trim();case"initializing api":return"Preparing text recognition...";case"recognizing text":return`Recognizing text... ${t}%`;default:return e&&e.includes("recognizing")?`Recognizing text... ${t}%`:e?`${e.charAt(0).toUpperCase()+e.slice(1)}...`:"Processing..."}}async function E(e="eng",f=null){if(u=f,g&&x===e)return g;if(g){try{await g.terminate()}catch(o){console.warn("Error terminating old OCR worker:",o)}g=null,x=null}let t=null;if(typeof window<"u"&&!window.Tesseract){u&&typeof u=="function"&&u({status:"downloading-engine",progress:.05,message:"Downloading OCR engine..."});try{t=await P.progress({message:"Downloading OCR engine...",total:100,done:0})}catch{}}let i,d;try{i=await w();let o=C(e);d=await i.createWorker(e,1,{workerPath:h("js/lib/tesseract-worker.min.js"),corePath:h("js/lib/tesseract-core"),langPath:o,logger:s=>{if(t&&s.status==="loading tesseract core"){let a=Math.round((s.progress||0)*100);t.update(a,100,`Downloading OCR engine... ${a>0?a+"%":""}`.trim())}if(u&&typeof u=="function"){let a=k(s.status,s.progress);u({status:s.status,progress:typeof s.progress=="number"?s.progress:0,message:a,raw:s})}}})}finally{t?.close()}return g=d,x=e,g}async function O(e,f={}){let{lang:t="eng",onProgress:l=null,abortSignal:i=null}=f;if(i?.aborted){let a=new Error("OCR operation cancelled by user");throw a.name="AbortError",a}l&&l({status:"starting",progress:.05,message:"Starting OCR engine..."});let d=await E(t,l);if(i?.aborted){let a=new Error("OCR operation cancelled by user");throw a.name="AbortError",a}l&&l({status:"recognizing text",progress:.2,message:"Recognizing text..."});let o=null,s=new Promise((a,c)=>{i&&(o=()=>{T();let r=new Error("OCR operation cancelled by user");r.name="AbortError",c(r)},i.addEventListener("abort",o,{once:!0}))});try{let c=(await Promise.race([d.recognize(e),s]))?.data||{},r=(c.text||"").trim(),p=Math.round(c.confidence||0);l&&l({status:"done",progress:1,message:"Text recognition complete!"});let m=(c.words||[]).map(n=>({text:(n.text||"").trim(),confidence:Math.round(n.confidence||0),bbox:{x0:n.bbox?.x0??0,y0:n.bbox?.y0??0,x1:n.bbox?.x1??0,y1:n.bbox?.y1??0},baseline:n.baseline?{x0:n.baseline.x0??0,y0:n.baseline.y0??0,x1:n.baseline.x1??0,y1:n.baseline.y1??0}:null})).filter(n=>n.text.length>0);return{text:r,confidence:p,words:m,lines:c.lines||[],paragraphs:c.paragraphs||[],hocr:c.hocr||""}}finally{i&&o&&i.removeEventListener("abort",o)}}async function v(e,f={}){let{lang:t="eng",onPageProgress:l=null,abortSignal:i=null}=f,d=(e||[]).filter(r=>r.blob||r.src);if(d.length===0)return{pagesResults:[],combinedText:"",averageConfidence:0,empty:!0};let o=[],s=0;for(let r=0;r<d.length;r++){if(i?.aborted){let b=new Error("OCR operation cancelled by user");throw b.name="AbortError",b}let p=d[r],m=r+1,n=d.length,y=await O(p.blob||p.src,{lang:t,abortSignal:i,onProgress:b=>{if(l){let R=(r+(b.progress||0))/n;l({pageIndex:r,pageNumber:m,totalPages:n,pageProgress:b.progress||0,overallProgress:R,message:`Page ${m} of ${n}: ${b.message}`})}}});o.push({pageId:p.id,pageIndex:r,pageNumber:m,...y}),s+=y.confidence}let a=o.map(r=>o.length>1?`## Page ${r.pageNumber}
|
|
2
|
+
|
|
3
|
+
${r.text}`:r.text).join(`
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`),c=Math.round(s/o.length);return{pagesResults:o,combinedText:a,averageConfidence:c}}async function T(){if(g){try{await g.terminate()}catch(e){console.warn("Error during OCR worker termination:",e)}g=null,x=null,u=null}}export{A as a,E as b,O as c,v as d,T as e};
|
|
8
|
+
//# sourceMappingURL=chunk-FAVTIE3M.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as c}from"./chunk-DIU5BGU5.js";var a=class extends c{#e=new Map;#s=new Map;#n=new Set;constructor(){super()}async init(){return{kind:"memory",persistent:!1}}listDocsSync(){return Array.from(this.#e.values()).map(e=>({id:e.id,name:e.name,pages:Array.isArray(e.pages)?[...e.pages]:[]}))}async listDocs(){return this.listDocsSync()}getDocSync(e){let s=this.#e.get(e);return s?{id:s.id,name:s.name,pages:Array.isArray(s.pages)?[...s.pages]:[]}:null}async getDoc(e){return this.getDocSync(e)}async saveDoc(e,s){if(!e)throw new Error("Cannot save document without an ID");let t=[];if(Array.isArray(s.pages))t=[...s.pages];else if(typeof s.pages=="string")try{t=JSON.parse(s.pages)}catch{t=[]}this.#e.set(e,{id:e,name:s.name||"",pages:t}),this.#t()}async deleteDoc(e){this.#e.delete(e);let s=`${e}/`;for(let t of this.#s.keys())t.startsWith(s)&&this.#s.delete(t);this.#t()}async renameDoc(e,s){let t=this.#e.get(e);if(!t)throw new Error(`Document "${e}" not found`);t.name=s,this.#t()}async savePage(e,s,t){this.#s.set(`${e}/${s}`,t);let n=this.#e.get(e);if(n){let r=n.pages.findIndex(i=>i.id===s);if(r>=0)typeof t=="object"&&t!==null&&!(t instanceof Blob)?n.pages[r]={...n.pages[r],...t}:n.pages[r]={...n.pages[r],src:t};else{let i=typeof t=="object"&&t!==null&&!(t instanceof Blob)?{id:s,...t}:{id:s,src:t};n.pages.push(i)}}this.#t()}async getPage(e,s){if(this.#s.has(`${e}/${s}`))return this.#s.get(`${e}/${s}`);let t=this.#e.get(e);if(t){let n=t.pages.find(r=>r.id===s);if(n)return n.src??n}return null}async deletePage(e,s){this.#s.delete(`${e}/${s}`);let t=this.#e.get(e);t&&(t.pages=t.pages.filter(n=>n.id!==s)),this.#t()}subscribe(e){return this.#n.add(e),()=>{this.#n.delete(e)}}clear(){this.#e.clear(),this.#s.clear(),this.#t()}#t(){for(let e of this.#n)try{e()}catch(s){console.error("Error in MemoryStorageAdapter subscriber:",s)}}};export{a};
|
|
2
|
+
//# sourceMappingURL=chunk-FQRADJY6.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as jr}from"./chunk-DIU5BGU5.js";var Ft=t=>typeof t;var Or=Ft(""),bn=Ft(!0),Wr=Ft(0),pn=Ft(Ft),Ke="type",Qt="default",xs="Listener",Vr="Result",ks="add",zt="Has",Re="Ids",Jt="Table",$r=Jt+"s",wn=Jt+Re,ae="Row",Nr=ae+"Count",Jr=ae+Re,yn="Sorted"+ae+Re,Se="Cell",_e=Se+Re,Ge="Value",Pr=Ge+"s",Sn=Ge+Re,at=t=>""+t;var mn=(t,e="",r)=>t.split(e,r),Ms=globalThis,es=Math,Ls=es.max,Rs=es.min,Ln=es.floor,Fr=isFinite,B=t=>t==null,it=(t,e,r)=>B(t)?r?.():e(t),Kr=t=>t==Or||t==bn,Rn=t=>Ft(t)==Or,Dt=t=>Ft(t)==pn,ie=t=>Array.isArray(t),Ds=(t,e,r)=>t.slice(e,r),kt=t=>t.length,qr=()=>{};var vs=async(t,e,r)=>{try{return await t()}catch(o){e?.(o)}},js=(t,e)=>t.includes(e),Ye=(t,e)=>t.every(e),Qr=(t,e)=>kt(t)===kt(e)&&Ye(t,((r,o)=>e[o]===r)),Ur=(t,e)=>Ye(t,((r,o)=>o==0||e(t[o-1],r)<=0)),Vs=(t,e)=>t.sort(e),Tt=(t,e)=>t.forEach(e),Yt=(t,e)=>t.map(e),Br=t=>zr(t,((e,r)=>e+r),0),me=t=>kt(t)==0,zr=(t,e,r)=>t.reduce(e,r),Ct=(t,...e)=>t.push(...e),Er=t=>t.pop(),_r=t=>t.shift(),ne=t=>{let e=Ft(t);return Kr(e)||e==Wr&&Fr(t)?e:void 0};var Xe=(t,e,r,o,l)=>B(l)?t.delCell(e,r,o,!0):t.setCell(e,r,o,l),$s=(t,e,r)=>B(r)?t.delValue(e):t.setValue(e,r),Es=t=>e=>zr(le(e),((r,o)=>r+t(o)),0),ce=t=>t?.size??0,Xt=Es(ce),Bt=Es(Xt),Cs=Es(Bt),dt=(t,e)=>t?.has(e)??!1,$=t=>B(t)||ce(t)==0,le=t=>[...t?.values()??[]],oe=t=>t.clear(),V=(t,e)=>t?.forEach(e),Vt=(t,e)=>t?.delete(e),Kt=Object,Hr=t=>Kt.getPrototypeOf(t),vn=Kt.isFrozen,Gr=Kt.entries,Ze=t=>!B(t)&&it(Hr(t),(e=>e==Kt.prototype||B(Hr(e))),(()=>!0)),Cn=Kt.keys,de=Kt.freeze,Tn=(t=[])=>Kt.fromEntries(t),ye=(t,e)=>e in t,Yr=(t,e)=>(delete t[e],t),In=(t,e)=>Tt(Gr(t),(([r,o])=>e(o,r))),Ut=(t,e)=>Tn(((r,o)=>Yt(Gr(r),(([l,c])=>o(c,l))))(t,((r,o)=>[o,e(r,o)]))),jt=t=>Ze(t)&&(e=>kt(Cn(e)))(t)==0;var Wt=(t,e,r,o=0)=>B(t)||!Ze(t)||!o&&jt(t)||vn(t)?(r?.(),!1):(In(t,((l,c)=>{e(l,c)||Yr(t,c)})),!!o||!jt(t)),p=t=>new Map(t),Gt=t=>[...t?.keys()??[]],g=(t,e)=>t?.get(e),pt=(t,e)=>V(t,((r,o)=>e(o,r))),x=(t,e,r)=>B(r)?(Vt(t,e),t):t?.set(e,r),ct=(t,e,r,o)=>(dt(t,e)?o?.(g(t,e)):x(t,e,r()),g(t,e)),_t=(t,e,r,o=x)=>(Ut(e,((l,c)=>r(t,c,l))),pt(t,(l=>ye(e,l)?0:o(t,l))),t),vt=(t,e,r,o)=>{let l={};return V(t,((c,u)=>{if(!r?.(c,u)){let i=e?e(c,u):c;o?.(i)||(l[u]=i)}})),l},Ps=(t,e,r)=>vt(t,(o=>vt(o,e,r)),$,jt),qe=(t,e,r)=>vt(t,(o=>Ps(o,e,r)),$,jt),Nt=(t,e)=>{let r=p();return V(t,((o,l)=>r.set(l,e?.(o)??o))),r},Us=t=>Nt(t,Nt),Ts=t=>Nt(t,Us),Le=(t,e,r,o,l=0)=>it((r?ct:g)(t,e[l],l>kt(e)-2?r:p),(c=>{if(l>kt(e)-2)return o?.(c)&&x(t,e[l]),c;let u=Le(c,e,r,o,l+1);return $(c)&&x(t,e[l]),u})),wt=t=>new Set(ie(t)||B(t)?t:[t]),ut=(t,e)=>t?.add(e),ss=(t,e,r,o,l)=>{let c=t.hasRow,u=p(),i=p(),w=p(),S=p(),R=p(),b=p(),E=(m,k,..._)=>{let I=ct(b,m,wt);return Tt(_,(A=>ut(I,A)&&k&&t.callListener(A))),_},T=(m,...k)=>it(g(b,m),(_=>{Tt(me(k)?le(_):k,(I=>{t.delListener(I),Vt(_,I)})),$(_)&&x(b,m)})),F=(m,k)=>{x(u,m,k),dt(i,m)||(x(i,m,e()),x(S,m,p()),x(R,m,p()),l(w))},Z=m=>{x(u,m),x(i,m),x(S,m),x(R,m),T(m),l(w)};return[()=>t,()=>Gt(u),m=>pt(i,m),m=>dt(i,m),m=>g(u,m),m=>g(i,m),(m,k)=>x(i,m,k),F,(m,k,_,I,A)=>{F(m,k);let st=p(),y=p(),h=g(S,m),C=g(R,m),W=U=>{let q=lt=>t.getCell(k,U,lt),nt=g(h,U),ot=c(k,U)?r(I(q,U)):void 0;if(nt===ot||ie(nt)&&ie(ot)&&Qr(nt,ot)||x(st,U,[nt,ot]),!B(A)){let lt=g(C,U),N=c(k,U)?A(q,U):void 0;lt!=N&&x(y,U,N)}},K=U=>{_((()=>{V(st,(([,q],nt)=>x(h,nt,q))),V(y,((q,nt)=>x(C,nt,q)))}),st,y,h,C,U),oe(st),oe(y)};pt(h,W),t.hasTable(k)&&Tt(t.getRowIds(k),(U=>{dt(h,U)||W(U)})),K(!0),T(m),E(m,0,t.addRowListener(k,null,((U,q,nt)=>W(nt))),t.addTableListener(k,(()=>K())))},Z,m=>o(m,w),()=>pt(b,Z),E,T]},ts=(t,e)=>Rn(t)?r=>r(t):t??(()=>e??""),ve=(t,e)=>{let r=new WeakMap;return o=>{r.has(o)||r.set(o,t(o));let l=r.get(o);return e?.(l),l}},xn=/^\d+$/,Xr=()=>{let t=[],e=0;return[r=>(r?_r(t):null)??""+e++,r=>{xn.test(r)&&kt(t)<1e3&&Ct(t,r)}]},Ce=t=>{let e,[r,o]=Xr(),l=p();return[(c,u,i,w=[],S=()=>[])=>{e??=t();let R=r(1);return x(l,R,[c,u,i,w,S]),ut(Le(u,i??[""],wt),R),R},(c,u,...i)=>Tt(((w,S=[""])=>{let R=[],b=(E,T)=>T==kt(S)?Ct(R,E):S[T]===null?V(E,(F=>b(F,T+1))):Tt([S[T],null],(F=>b(g(E,F),T+1)));return b(w,0),R})(c,u),(w=>V(w,(S=>g(l,S)[0](e,...u??[],...i))))),c=>it(g(l,c),(([,u,i])=>(Le(u,i??[""],void 0,(w=>(Vt(w,c),$(w)?1:0))),x(l,c),o(c),i))),c=>it(g(l,c),(([u,,i=[],w,S])=>{let R=(...b)=>{let E=kt(b);E==kt(i)?u(e,...b,...S(b)):B(i[E])?Tt(w[E]?.(...b)??[],(T=>R(...b,T))):R(...b,i[E])};R()}))]},so=ve((t=>{let e,r,o,l=100,c=p(),u=p(),i=1,w=p(),S=p(),[R,b,E]=Ce((()=>N)),T=p(),F=p(),Z=[],m=[],k=(L,j)=>{i=0,t.transaction((()=>{let[et,G]=g(T,j);V(et,((D,H)=>V(D,((J,Y)=>V(J,((O,Q)=>Xe(t,H,Y,Q,O[L]))))))),V(G,((D,H)=>$s(t,H,D[L])))})),i=1},_=L=>{x(T,L),x(F,L),b(S,[L])},I=(L,j)=>Tt(((et,G)=>et.splice(0,G))(L,j??kt(L)),_),A=()=>I(Z,kt(Z)-l),st=()=>it(e,(()=>{Ct(Z,e),A(),I(m),e=void 0,o=1})),y=()=>{e=Er(Z),o=1},h,C,W=(L="")=>(B(e)&&(e=""+r++,x(T,e,[c,u]),ot(e,L),c=p(),u=p(),o=1),e),K=()=>{me(Z)||(((L,...j)=>{L.unshift(...j)})(m,W()),k(0,e),e=Er(Z),o=1)},U=()=>{me(m)||(Ct(Z,e),e=_r(m),k(1,e),o=1)},q=()=>{o&&(b(w),o=0)},nt=L=>{let j=W(L);return q(),j},ot=(L,j)=>(lt(L)&&g(F,L)!==j&&(x(F,L,j),b(S,[L])),N),lt=L=>dt(T,L),N={setSize:L=>(l=L,A(),N),addCheckpoint:nt,setCheckpoint:ot,getStore:()=>t,getCheckpointIds:()=>[[...Z],e,[...m]],forEachCheckpoint:L=>pt(F,L),hasCheckpoint:lt,getCheckpoint:L=>g(F,L),goBackward:()=>(K(),q(),N),goForward:()=>(U(),q(),N),goTo:L=>{let j=js(Z,L)?K:js(m,L)?U:null;for(;!B(j)&&L!=e;)j();return q(),N},addCheckpointIdsListener:L=>R(L,w),addCheckpointListener:(L,j)=>R(j,S,[L]),delListener:L=>(E(L),N),clear:()=>(I(Z),I(m),B(e)||_(e),e=void 0,r=0,nt(),N),clearForward:()=>(me(m)||(I(m),b(w)),N),destroy:()=>{t.delListener(h),t.delListener(C)},getListenerStats:()=>({checkpointIds:Xt(w),checkpoint:Xt(S)}),_registerListeners:()=>{h=t.addCellListener(null,null,null,((L,j,et,G,D,H)=>{if(i){st();let J=ct(c,j,p),Y=ct(J,et,p),O=ct(Y,G,(()=>[H,void 0]));O[1]=D,O[0]===D&&$(x(Y,G))&&$(x(J,et))&&$(x(c,j))&&y(),q()}})),C=t.addValueListener(null,((L,j,et,G)=>{if(i){st();let D=ct(u,j,(()=>[G,void 0]));D[1]=et,D[0]===et&&$(x(u,j))&&y(),q()}}))}};return de(N.clear())}),(t=>t._registerListeners())),kn=mn("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),ro=p(Yt(kn,((t,e)=>[t,e])));var no=Ms.crypto?t=>Ms.crypto.getRandomValues(t):t=>Yt(t,(()=>Ln(256*es.random())));var Mn=JSON.stringify,Is=JSON.parse,re=t=>Mn(t,((e,r)=>{return o=Map,r instanceof o?Kt.fromEntries([...r]):r;var o})),oo=new Ms.TextEncoder;var ao=2**36,io=2**30,lo=2**24,co=2**18;var Zr=(t,e)=>(t??0)<(e??0)?-1:1,ho=ve((t=>{let e=p(),r=p(),[o,l,c]=Ce((()=>_)),[u,i,w,S,R,b,E,,T,F,Z,m]=ss(t,p,(I=>B(I)?"":ie(I)?Yt(I,at):at(I)),o,l),k=(I,A,st)=>{let y=R(I);V(st,((h,C)=>A(C,(W=>V(h,(K=>W(K,(U=>t.forEachCell(y,K,U)))))))))},_={setIndexDefinition:(I,A,st,y,h,C=Zr)=>{let W=B(h)?void 0:([K],[U])=>h(K,U);return T(I,A,((K,U,q,nt,ot,lt)=>{let N=0,L=wt(),j=wt(),et=b(I);if(V(U,(([G,D],H)=>{let J=wt(G),Y=wt(D);V(J,(O=>Vt(Y,O)?Vt(J,O):0)),V(J,(O=>{ut(L,O),it(g(et,O),(Q=>{Vt(Q,H),$(Q)&&(x(et,O),N=1)}))})),V(Y,(O=>{ut(L,O),dt(et,O)||(x(et,O,wt()),N=1),ut(g(et,O),H),B(y)||ut(j,O)}))})),K(),$(ot)||(lt?pt(et,(G=>ut(j,G))):pt(q,(G=>it(g(nt,G),(D=>Tt(ie(D)?D:[D],(H=>ut(j,H))))))),V(j,(G=>{let D=(J,Y)=>C(g(ot,J),g(ot,Y),G),H=[...g(et,G)];Ur(H,D)||(x(et,G,wt(Vs(H,D))),ut(L,G))}))),(N||lt)&&!B(W)){let G=[...et];Ur(G,W)||(E(I,p(Vs(G,W))),N=1)}N&&l(e,[I]),V(L,(G=>l(r,[I,G])))}),ts(st),it(y,ts)),_},delIndexDefinition:I=>(F(I),_),getStore:u,getIndexIds:i,forEachIndex:I=>w(((A,st)=>I(A,(y=>k(A,y,st))))),forEachSlice:(I,A)=>k(I,A,b(I)),hasIndex:S,hasSlice:(I,A)=>dt(b(I),A),getTableId:R,getSliceIds:I=>Gt(b(I)),getSliceRowIds:(I,A)=>le(g(b(I),A)),addIndexIdsListener:Z,addSliceIdsListener:(I,A)=>o(A,e,[I]),addSliceRowIdsListener:(I,A,st)=>o(st,r,[I,A]),delListener:I=>(c(I),_),destroy:m,getListenerStats:()=>({sliceIds:Xt(e),sliceRowIds:Bt(r)})};return de(_)}));var Qe=t=>[t,t],ft=(t,e=Xt)=>e(t[0])+e(t[1]),bt=()=>[p(),p()],Ar=t=>[...t],ze=([t,e])=>t===e,we=(t,e,r)=>x(t,e,g(t,e)==-r?void 0:r),Te=()=>{let t,e,r=!1,o=!1,l=0,c=[],u=p(),i=p(),w=p(),S=p(),R=p(),b=p(),E=p(),T=p(),F=p(),Z=p(),m=p(),k=p(),_=p(),I=p(),A=wt(),st=p(),y=p(),h=p(),C=p(),W=bt(),K=bt(),U=bt(),q=bt(),nt=bt(),ot=bt(),lt=bt(),N=bt(),L=bt(),j=bt(),et=bt(),G=bt(),D=bt(),H=bt(),J=bt(),Y=bt(),O=bt(),Q=bt(),M=bt(),rt=bt(),ht=bt(),Rt=bt(),St=p(),mt=bt(),[yt,tt,It,Et]=Ce((()=>Lt)),Ht=s=>{if(!Wt(s,((a,d)=>js([Ke,Qt],d))))return!1;let n=s[Ke];return!(!Kr(n)&&n!=Wr)&&(ne(s[Qt])!=n&&Yr(s,Qt),!0)},gs=ie,ke=(s,n)=>(!t||dt(m,n)||At(n))&&Wt(s,((a,d)=>qt(n,d,a)),(()=>At(n))),qt=(s,n,a,d)=>Wt(d?a:Ks(a,s,n),((f,v)=>it(Me(s,n,v,f),(P=>(a[v]=P,!0)),(()=>!1))),(()=>At(s,n))),Me=(s,n,a,d)=>t?it(g(g(m,s),a),(f=>ne(d)!=f[Ke]?At(s,n,a,d,f[Qt]):d),(()=>At(s,n,a,d))):B(ne(d))?At(s,n,a,d):d,ue=(s,n)=>Wt(n?s:gn(s),((a,d)=>it(Fs(d,a),(f=>(s[d]=f,!0)),(()=>!1))),(()=>fe())),Fs=(s,n)=>e?it(g(_,s),(a=>ne(n)!=a[Ke]?fe(s,n,a[Qt]):n),(()=>fe(s,n))):B(ne(n))?fe(s,n):n,Ks=(s,n,a)=>(it(g(k,n),(([d,f])=>{V(d,((v,P)=>{ye(s,P)||(s[P]=v)})),V(f,(v=>{ye(s,v)||At(n,a,v)}))})),s),gn=s=>(e&&(V(I,((n,a)=>{ye(s,a)||(s[a]=n)})),V(A,(n=>{ye(s,n)||fe(n)}))),s),qs=s=>_t(m,s,((n,a,d)=>{let f=p(),v=wt();_t(ct(m,a,p),d,((P,z,X)=>{x(P,z,X),it(X[Qt],(Pt=>x(f,z,Pt)),(()=>ut(v,z)))})),x(k,a,[f,v])}),((n,a)=>{x(m,a),x(k,a)})),Qs=s=>_t(_,s,((n,a,d)=>{x(_,a,d),it(d[Qt],(f=>x(I,a,f)),(()=>ut(A,a)))}),((n,a)=>{x(_,a),x(I,a),Vt(A,a)})),zs=s=>jt(s)?We():Ae(s),_s=s=>_t(h,s,((n,a,d)=>De(a,d)),((n,a)=>Zs(a))),De=(s,n)=>_t(ct(h,s,(()=>(rr(s,1),x(st,s,Xr()),x(y,s,p()),p()))),n,((a,d,f)=>ge(s,a,d,f)),((a,d)=>tr(s,a,d))),ge=(s,n,a,d,f)=>_t(ct(n,a,(()=>(nr(s,a,1),p()))),d,((v,P,z)=>fs(s,a,v,P,z)),((v,P)=>er(s,n,a,v,P,f))),fs=(s,n,a,d,f)=>{dt(a,d)||or(s,n,d,1);let v=g(a,d);f!==v&&(ar(s,n,d,v,f),x(a,d,f))},Gs=(s,n,a,d,f)=>it(g(n,a),(v=>fs(s,a,v,d,f)),(()=>ge(s,n,a,Ks({[d]:f},s,a)))),Ys=s=>jt(s)?Ne():Oe(s),Xs=s=>_t(C,s,((n,a,d)=>je(a,d)),((n,a)=>sr(a))),je=(s,n)=>{dt(C,s)||ir(s,1);let a=g(C,s);n!==a&&(lr(s,a,n),x(C,s,n))},Ve=s=>g(h,s)??De(s,{}),Zs=s=>De(s,{}),tr=(s,n,a)=>{let[,d]=g(st,s);d(a),ge(s,n,a,{},!0)},er=(s,n,a,d,f,v)=>{let P=g(g(k,s)?.[0],f);if(!B(P)&&!v)return fs(s,a,d,f,P);let z=X=>{ar(s,a,X,g(d,X)),or(s,a,X,-1),x(d,X)};B(P)?z(f):pt(d,z),$(d)&&(nr(s,a,-1),$(x(n,a))&&(rr(s,-1),x(h,s),x(st,s),x(y,s)))},sr=s=>{let n=g(I,s);if(!B(n))return je(s,n);lr(s,g(C,s)),ir(s,-1),x(C,s)},rr=(s,n)=>we(u,s,n),nr=(s,n,a)=>we(ct(S,s,p),n,a)&&x(w,s,ct(w,s,(()=>0))+a),or=(s,n,a,d)=>{let f=g(y,s),v=g(f,a)??0;(v==0&&d==1||v==1&&d==-1)&&we(ct(i,s,p),a,d),x(f,a,v!=-d?v+d:null),we(ct(ct(R,s,p),n,p),a,d)},ar=(s,n,a,d,f)=>{ct(ct(ct(b,s,p),n,p),a,(()=>[d,0]))[1]=f,c[3]?.(s,n,a,f)},ir=(s,n)=>we(E,s,n),lr=(s,n,a)=>{ct(T,s,(()=>[n,0]))[1]=a,c[4]?.(s,a)},At=(s,n,a,d,f)=>(Ct(ct(ct(ct(F,s,p),n,p),a,(()=>[])),d),f),fe=(s,n,a)=>(Ct(ct(Z,s,(()=>[])),n),a),$e=(s,n,a)=>it(g(g(g(b,s),n),a),(([d,f])=>[!0,d,f]),(()=>[!1,...Qe(Ue(s,n,a))])),cr=s=>it(g(T,s),(([n,a])=>[!0,n,a]),(()=>[!1,...Qe(Be(s))])),dr=s=>$(F)||$(Y[s])?0:V(s?Ts(F):F,((n,a)=>V(n,((d,f)=>V(d,((v,P)=>tt(Y[s],[a,f,P],v))))))),hr=s=>$(Z)||$(O[s])?0:V(s?Nt(Z):Z,((n,a)=>tt(O[s],[a],n))),be=(s,n,a,d)=>{if(!$(s))return tt(n,d,(()=>vt(s))),pt(s,((f,v)=>tt(a,[...d??[],f],v==1))),1},ur=s=>{let n=Ee();n!=r&&tt(W[s],void 0,n);let a=$(j[s]),d=$(D[s])&&$(H[s])&&$(L[s])&&$(et[s])&&$(ot[s])&&$(lt[s])&&$(N[s])&&a&&$(U[s])&&$(q[s]),f=$(J[s])&&$(G[s])&&$(nt[s])&&$(K[s]);if(!d||!f){let v=s?[Nt(u),Us(i),Nt(w),Us(S),Ts(R),Ts(b)]:[u,i,w,S,R,b];if(!d){be(v[0],U[s],q[s]),V(v[1],((z,X)=>be(z,ot[s],lt[s],[X]))),V(v[2],((z,X)=>{z!=0&&tt(N[s],[X],pr(X))}));let P=wt();V(v[3],((z,X)=>{be(z,L[s],et[s],[X])&&!a&&(tt(j[s],[X,null]),ut(P,X))})),a||V(v[5],((z,X)=>{if(!dt(P,X)){let Pt=wt();V(z,(Ot=>V(Ot,(([Je,Fe],pe)=>Fe!==Je?ut(Pt,pe):Vt(Ot,pe))))),V(Pt,(Ot=>tt(j[s],[X,Ot])))}})),V(v[4],((z,X)=>V(z,((Pt,Ot)=>be(Pt,D[s],H[s],[X,Ot])))))}if(!f){let P;V(v[5],((z,X)=>{let Pt;V(z,((Ot,Je)=>{let Fe;V(Ot,(([pe,Dr],fn)=>{Dr!==pe&&(tt(J[s],[X,Je,fn],Dr,pe,$e),P=Pt=Fe=1)})),Fe&&tt(G[s],[X,Je],$e)})),Pt&&tt(nt[s],[X],$e)})),P&&tt(K[s],void 0,$e)}}},gr=s=>{let n=He();n!=o&&tt(Q[s],void 0,n);let a=$(rt[s])&&$(ht[s]),d=$(Rt[s])&&$(M[s]);if(!a||!d){let f=s?[Nt(E),Nt(T)]:[E,T];if(a||be(f[0],rt[s],ht[s]),!d){let v;V(f[1],(([P,z],X)=>{z!==P&&(tt(Rt[s],[X],z,P,cr),v=1)})),v&&tt(M[s],void 0,cr)}}},gt=(s,...n)=>(ms((()=>s(...Yt(n,at)))),Lt),fr=(s,n,a,d,f)=>{let v=Pe(s,n,...a);return yt((()=>{let P=Pe(s,n,...a);Qr(P,v)||(v=P,d(Lt,s,n,...a,v))}),j[f?1:0],[s,n],[xt])},bs=()=>qe(h),xt=()=>Gt(h),br=s=>Gt(g(y,at(s))),pr=s=>ce(g(h,at(s))),se=s=>Gt(g(h,at(s))),Pe=(s,n,a,d=0,f)=>{return Ze(s)?Pe(s.tableId,s.cellId,s.descending,s.offset,s.limit):Yt(Ds(Vs((v=g(h,at(s)),P=(z,X)=>[B(n)?X:g(z,at(n)),X],Yt([...v?.entries()??[]],(([z,X])=>P(X,z)))),(([z],[X])=>Zr(z,X)*(a?-1:1))),d,B(f)?f:d+f),(([,z])=>z));var v,P},ps=(s,n)=>Gt(g(g(h,at(s)),at(n))),Ue=(s,n,a)=>g(g(g(h,at(s)),at(n)),at(a)),ws=()=>vt(C),ys=()=>Gt(C),Be=s=>g(C,at(s)),Ee=()=>!$(h),wr=s=>dt(h,at(s)),yr=(s,n)=>dt(g(y,at(s)),at(n)),Sr=(s,n)=>dt(g(h,at(s)),at(n)),mr=(s,n,a)=>dt(g(g(h,at(s)),at(n)),at(a)),He=()=>!$(C),Lr=s=>dt(C,at(s)),Ae=s=>gt((()=>(n=>Wt(n,ke,At))(s)?_s(s):0)),Oe=s=>gt((()=>ue(s)?Xs(s):0)),Rr=s=>(vs((()=>zs(Is(s)))),Lt),vr=s=>gt((()=>{if((t=Wt(s,(n=>Wt(n,Ht))))&&(qs(s),!$(h))){let n=bs();We(),Ae(n)}})),Cr=s=>gt((()=>{if(e=(n=>Wt(n,Ht))(s)){let n=ws();Ss(),Ne(),e=!0,Qs(s),Oe(n)}})),We=()=>gt((()=>_s({}))),Tr=s=>gt((n=>dt(h,n)?Zs(n):0),s),Ir=(s,n)=>gt(((a,d)=>it(g(h,a),(f=>dt(f,d)?tr(a,f,d):0))),s,n),Ne=()=>gt((()=>Xs({}))),xr=()=>gt((()=>{qs({}),t=!1})),Ss=()=>gt((()=>{Qs({}),e=!1})),ms=(s,n)=>{if(l!=-1){kr();let a=s();return Mr(n),a}},kr=()=>(l!=-1&&l++,l==1&&(c[0]?.(),tt(St)),Lt),Mr=s=>(l>0&&(l--,l==0&&(l=1,dr(1),$(b)||ur(1),hr(1),$(T)||gr(1),s?.(Lt)&&(V(b,((n,a)=>V(n,((d,f)=>V(d,(([v],P)=>Xe(Lt,a,f,P,v))))))),oe(b),V(T,(([n],a)=>$s(Lt,a,n))),oe(T)),tt(mt[0],void 0),l=-1,dr(0),$(b)||ur(0),hr(0),$(T)||gr(0),c[1]?.(),tt(mt[1],void 0),c[2]?.(),l=0,r=Ee(),o=He(),Tt([u,i,w,S,R,b,F,E,T,Z],oe))),Lt),Lt={getContent:()=>[bs(),ws()],getTables:bs,getTableIds:xt,getTable:s=>Ps(g(h,at(s))),getTableCellIds:br,getRowCount:pr,getRowIds:se,getSortedRowIds:Pe,getRow:(s,n)=>vt(g(g(h,at(s)),at(n))),getCellIds:ps,getCell:Ue,getValues:ws,getValueIds:ys,getValue:Be,hasTables:Ee,hasTable:wr,hasTableCell:yr,hasRow:Sr,hasCell:mr,hasValues:He,hasValue:Lr,getTablesJson:()=>re(h),getValuesJson:()=>re(C),getJson:()=>re([h,C]),getTablesSchemaJson:()=>re(m),getValuesSchemaJson:()=>re(_),getSchemaJson:()=>re([m,_]),hasTablesSchema:()=>t,hasValuesSchema:()=>e,setContent:s=>gt((()=>{let n=Dt(s)?s():s;gs(n)&&(([a,d])=>{(jt(a)?We:Ae)(a),(jt(d)?Ne:Oe)(d)})(n)})),setTables:Ae,setTable:(s,n)=>gt((a=>ke(n,a)?De(a,n):0),s),setRow:(s,n,a)=>gt(((d,f)=>qt(d,f,a)?ge(d,Ve(d),f,a):0),s,n),addRow:(s,n,a=!0)=>ms((()=>{let d;return qt(s,d,n)&&(s=at(s),ge(s,Ve(s),d=((f,v)=>{let[P]=g(st,f),z;do z=P(v);while(dt(g(h,f),z));return z})(s,a?1:0),n)),d})),setPartialRow:(s,n,a)=>gt(((d,f)=>{if(qt(d,f,a,1)){let v=Ve(d);Ut(a,((P,z)=>Gs(d,v,f,z,P)))}}),s,n),setCell:(s,n,a,d)=>gt(((f,v,P)=>it(Me(f,v,P,Dt(d)?d(Ue(f,v,P)):d),(z=>Gs(f,Ve(f),v,P,z)))),s,n,a),setValues:Oe,setPartialValues:s=>gt((()=>ue(s,1)?Ut(s,((n,a)=>je(a,n))):0)),setValue:(s,n)=>gt((a=>it(Fs(a,Dt(n)?n(Be(a)):n),(d=>je(a,d)))),s),applyChanges:s=>gt((()=>{Ut(s[0],((n,a)=>B(n)?Tr(a):Ut(n,((d,f)=>B(d)?Ir(a,f):Ut(d,((v,P)=>Xe(Lt,a,f,P,v))))))),Ut(s[1],((n,a)=>$s(Lt,a,n)))})),setTablesJson:Rr,setValuesJson:s=>(vs((()=>Ys(Is(s)))),Lt),setJson:s=>gt((()=>vs((()=>{let[n,a]=Is(s);zs(n),Ys(a)}),(()=>Rr(s))))),setTablesSchema:vr,setValuesSchema:Cr,setSchema:(s,n)=>gt((()=>{vr(s),Cr(n)})),delTables:We,delTable:Tr,delRow:Ir,delCell:(s,n,a,d)=>gt(((f,v,P)=>it(g(h,f),(z=>it(g(z,v),(X=>dt(X,P)?er(f,z,v,X,P,d):0))))),s,n,a),delValues:Ne,delValue:s=>gt((n=>dt(C,n)?sr(n):0),s),delTablesSchema:xr,delValuesSchema:Ss,delSchema:()=>gt((()=>{xr(),Ss()})),transaction:ms,startTransaction:kr,getTransactionChanges:()=>[vt(b,((s,n)=>g(u,n)===-1?void 0:vt(s,((a,d)=>g(g(S,n),d)===-1?void 0:vt(a,(([,f])=>f),(f=>ze(f)))),$,jt)),$,jt),vt(T,(([,s])=>s),(s=>ze(s))),1],getTransactionLog:()=>[!$(b),!$(T),qe(b,Ar,ze),qe(F),vt(T,Ar,ze),vt(Z),vt(u),Ps(S),qe(R),vt(E)],finishTransaction:Mr,forEachTable:s=>V(h,((n,a)=>s(a,(d=>V(n,((f,v)=>d(v,(P=>pt(f,P))))))))),forEachTableCell:(s,n)=>pt(g(y,at(s)),n),forEachRow:(s,n)=>V(g(h,at(s)),((a,d)=>n(d,(f=>pt(a,f))))),forEachCell:(s,n,a)=>pt(g(g(h,at(s)),at(n)),a),forEachValue:s=>pt(C,s),addSortedRowIdsListener:(s,n,a,d,f,v,P)=>Ze(s)?fr(s.tableId,s.cellId,[s.descending??!1,s.offset??0,s.limit],n,a):fr(s,n,[a,d,f],v,P),addStartTransactionListener:s=>yt(s,St),addWillFinishTransactionListener:s=>yt(s,mt[0]),addDidFinishTransactionListener:s=>yt(s,mt[1]),callListener:s=>(Et(s),Lt),delListener:s=>(It(s),Lt),getListenerStats:()=>({hasTables:ft(W),tables:ft(K),tableIds:ft(U),hasTable:ft(q),table:ft(nt),tableCellIds:ft(ot),hasTableCell:ft(lt,Bt),rowCount:ft(N),rowIds:ft(L),sortedRowIds:ft(j),hasRow:ft(et,Bt),row:ft(G,Bt),cellIds:ft(D,Bt),hasCell:ft(H,Cs),cell:ft(J,Cs),invalidCell:ft(Y,Cs),hasValues:ft(Q),values:ft(M),valueIds:ft(rt),hasValue:ft(ht),value:ft(Rt),invalidValue:ft(O),transaction:Xt(St)+ft(mt)}),isMergeable:()=>!1,createStore:Te,addListener:yt,callListeners:tt,setInternalListeners:(s,n,a,d,f)=>c=[s,n,a,d,f]};return Ut({[zt+$r]:[0,W,[],()=>[Ee()]],[$r]:[0,K],[wn]:[0,U],[zt+Jt]:[1,q,[xt],s=>[wr(...s)]],[Jt]:[1,nt,[xt]],[Jt+_e]:[1,ot,[xt]],[zt+Jt+Se]:[2,lt,[xt,br],s=>[yr(...s)]],[Nr]:[1,N,[xt]],[Jr]:[1,L,[xt]],[zt+ae]:[2,et,[xt,se],s=>[Sr(...s)]],[ae]:[2,G,[xt,se]],[_e]:[2,D,[xt,se]],[zt+Se]:[3,H,[xt,se,ps],s=>[mr(...s)]],[Se]:[3,J,[xt,se,ps],s=>Qe(Ue(...s))],InvalidCell:[3,Y],[zt+Pr]:[0,Q,[],()=>[He()]],[Pr]:[0,M],[Sn]:[0,rt],[zt+Ge]:[1,ht,[ys],s=>[Lr(...s)]],[Ge]:[1,Rt,[ys],s=>Qe(Be(s[0]))],InvalidValue:[1,O]},(([s,n,a,d],f)=>{Lt[ks+f+xs]=(...v)=>yt(v[s],n[v[s+1]?1:0],s>0?Ds(v,0,s):void 0,a,d)})),de(Lt)};var Bs=p([["avg",[(t,e)=>Br(t)/e,(t,e,r)=>t+(e-t)/(r+1),(t,e,r)=>t+(t-e)/(r-1),(t,e,r,o)=>t+(e-r)/o]],["max",[t=>Ls(...t),(t,e)=>Ls(e,t),(t,e)=>e==t?void 0:t,(t,e,r)=>r==t?void 0:Ls(e,t)]],["min",[t=>Rs(...t),(t,e)=>Rs(e,t),(t,e)=>e==t?void 0:t,(t,e,r)=>r==t?void 0:Rs(e,t)]],["sum",[t=>Br(t),(t,e)=>t+e,(t,e)=>t-e,(t,e,r)=>t-r+e]]]),tn=(t,e,r,o,l,c=!1)=>{if($(r))return;let[u,i,w,S]=l;return c||=B(t),V(o,(([R,b])=>{c||(t=B(R)?i?.(t,b,e++):B(b)?w?.(t,R,e--):S?.(t,b,R,e),c||=B(t))})),c?u(le(r),ce(r)):t},uo=ve((t=>{let e=p(),[r,o,l]=Ce((()=>m)),[c,u,i,w,S,R,b,,E,T,F,Z]=ss(t,qr,(k=>isNaN(k)||B(k)||k===!0||k===!1||k===""?void 0:1*k),r,o),m={setMetricDefinition:(k,_,I,A,st,y,h)=>{let C=Dt(I)?[I,st,y,h]:g(Bs,I)??g(Bs,"sum");return E(k,_,((W,K,U,q,nt,ot)=>{let lt=R(k),N=ce(q);ot||=B(lt),W();let L=tn(lt,N,q,K,C,ot);Fr(L)||(L=void 0),L!=lt&&(b(k,L),o(e,[k],L,lt))}),ts(A,1)),m},delMetricDefinition:k=>(T(k),m),getStore:c,getMetricIds:u,forEachMetric:i,hasMetric:w,getTableId:S,getMetric:R,addMetricIdsListener:F,addMetricListener:(k,_)=>r(_,e,[k]),delListener:k=>(l(k),m),destroy:Z,getListenerStats:()=>({metric:Xt(e)})};return de(m)})),go=ve((t=>{let e=t.createStore,r=e(),o=e(),l=p(),{addListener:c,callListeners:u,delListener:i}=o,[w,S,R,b,E,,,T,,F,Z,m,k,_]=ss(t,(()=>!0),qr,c,u),I=(h,C,...W)=>Tt(W,(K=>ut(ct(ct(l,C,p),h,wt),K))),A=h=>{it(g(l,h),(C=>{pt(C,((W,K)=>V(K,(U=>W.delListener(U))))),oe(C)})),Tt([o,r],(C=>C.delTable(h)))},st=(h,C,W)=>I(C,h,C.addStartTransactionListener(W.startTransaction),C.addDidFinishTransactionListener((()=>W.finishTransaction()))),y={setQueryDefinition:(h,C,W)=>{T(h,C),A(h);let K=[],U=[[null,[C,null,null,[],p()]]],q=[],nt=[],ot=[];W({select:(D,H)=>{let J=Dt(D)?[kt(K)+"",D]:[B(H)?D:H,Y=>Y(D,H)];return Ct(K,J),{as:Y=>J[0]=Y}},join:(D,H,J)=>{let Y=B(J)||Dt(H)?null:H,O=B(Y)?H:J,Q=[D,[D,Y,Dt(O)?O:M=>M(O),[],p()]];return Ct(U,Q),{as:M=>Q[0]=M}},where:(D,H,J)=>Ct(q,Dt(D)?D:B(J)?Y=>Y(D)===H:Y=>Y(D,H)===J),group:(D,H,J,Y,O)=>{let Q=[D,[D,Dt(H)?[H,J,Y,O]:g(Bs,H)??[(M,rt)=>rt]]];return Ct(nt,Q),{as:M=>Q[0]=M}},having:(D,H)=>Ct(ot,Dt(D)?D:J=>J(D)===H)});let lt=p(K);if($(lt))return y;let N=p(U);pt(N,((D,[,H])=>it(g(N,H),(({3:J})=>B(D)?0:Ct(J,D)))));let L=p(nt),j=r;if($(L)&&me(ot))j=o;else{st(h,j,o);let D=p();pt(L,((O,[Q,M])=>ut(ct(D,Q,wt),[O,M])));let H=wt();pt(lt,(O=>dt(D,O)?0:ut(H,O)));let J=p(),Y=(O,Q,M,rt)=>it(O,(([ht,Rt,St,mt])=>{pt(Q,((yt,[tt])=>{let It=ct(ht,yt,p),Et=g(It,M),Ht=rt?void 0:tt;if(Et!==Ht){let gs=wt([[Et,Ht]]),ke=ce(It);x(It,M,Ht),V(g(D,yt),(([qt,Me])=>{let ue=tn(mt[qt],ke,It,gs,Me);mt[qt]=B(ne(ue))?null:ue}))}})),$(Rt)||!Ye(ot,(yt=>yt((tt=>mt[tt]))))?o.delRow(h,St):B(St)?O[2]=o.addRow(h,mt):o.setRow(h,St,mt)}));I(j,h,j.addRowListener(h,null,((O,Q,M,rt)=>{let ht=[],Rt=[],St=p(),mt=j.hasRow(h,M),yt=!mt;V(H,(tt=>{let[It,Et,Ht]=rt(h,M,tt);Ct(ht,Et),Ct(Rt,Ht),yt||=It})),pt(D,(tt=>{let[It,,Et]=rt(h,M,tt);(yt||It)&&x(St,tt,[Et])})),yt&&Y(Le(J,ht,void 0,(([,tt])=>(Vt(tt,M),$(tt)))),St,M,1),mt&&Y(Le(J,Rt,(()=>{let tt={};return V(H,(It=>tt[It]=j.getCell(h,M,It))),[p(),wt(),void 0,tt]}),(([,tt])=>{ut(tt,M)})),St,M)})))}st(h,t,j);let et=(D,H,J,Y)=>{let O=Q=>t.getCell(H,J,Q);Tt(Y,(Q=>{let[M,,rt,ht,Rt]=g(N,Q),St=rt?.(O,D),[mt,yt]=g(Rt,D)??[];St!=mt&&(B(yt)||_(h,yt),x(Rt,D,B(St)?null:[St,...k(h,1,t.addRowListener(M,St,(()=>et(D,M,St,ht))))]))})),(Q=>{let M=(rt,ht)=>t.getCell(...B(ht)?[C,Q,rt]:rt===C?[C,Q,ht]:[g(N,rt)?.[0],g(g(N,rt)?.[4],Q)?.[0],ht]);j.transaction((()=>Ye(q,(rt=>rt(M)))?pt(lt,((rt,ht)=>Xe(j,h,Q,rt,ht(M,Q)))):j.delRow(h,Q)))})(D)},{3:G}=g(N,null);return j.transaction((()=>k(h,1,t.addRowListener(C,null,((D,H,J)=>{t.hasRow(C,J)?et(J,C,J,G):(j.delRow(h,J),V(N,(({4:Y})=>it(g(Y,J),(([,O])=>{_(h,O),x(Y,J)})))))}))))),y},delQueryDefinition:h=>(A(h),F(h),y),getStore:w,getQueryIds:S,forEachQuery:R,hasQuery:b,getTableId:E,addQueryIdsListener:h=>Z((()=>h(y))),delListener:h=>(i(h),y),destroy:m,getListenerStats:()=>{let{tables:h,tableIds:C,transaction:W,...K}=o.getListenerStats();return K}};return Ut({[Jt]:[1,1],[Jt+_e]:[0,1],[Nr]:[0,1],[Jr]:[0,1],[yn]:[0,5],[ae]:[1,2],[_e]:[0,2],[Se]:[1,3]},(([h,C],W)=>{Tt(h?["get","has","forEach"]:["get"],(K=>y[K+Vr+W]=(...U)=>o[K+W](...U))),y[ks+Vr+W+xs]=(...K)=>o[ks+W+xs](...Ds(K,0,C),((U,...q)=>K[C](y,...q)),!0)})),de(y)})),fo=ve((t=>{let e=p(),r=p(),o=p(),l=p(),[c,u,i]=Ce((()=>st)),[w,S,R,b,E,T,,,F,Z,m,k]=ss(t,(()=>[p(),p(),p(),p()]),(y=>B(y)?void 0:y+""),c,u),_=(y,h,C)=>it(T(y),(([W,,K])=>{if(!dt(K,h)){let U=wt();if(E(y)!=A(y))ut(U,h);else{let q=h;for(;!B(q)&&!dt(U,q);)ut(U,q),q=g(W,q)}if(C)return U;x(K,h,U)}return g(K,h)})),I=(y,h)=>it(T(y),(([,,C])=>x(C,h))),A=y=>g(e,y),st={setRelationshipDefinition:(y,h,C,W)=>(x(e,y,C),F(y,h,((K,U)=>{let q=wt(),nt=wt(),ot=wt(),[lt,N]=T(y);V(U,(([L,j],et)=>{B(L)||(ut(nt,L),it(g(N,L),(G=>{Vt(G,et),$(G)&&x(N,L)}))),B(j)||(ut(nt,j),dt(N,j)||x(N,j,wt()),ut(g(N,j),et)),ut(q,et),x(lt,et,j),pt(g(l,y),(G=>{dt(_(y,G),et)&&ut(ot,G)}))})),K(),V(q,(L=>u(r,[y,L]))),V(nt,(L=>u(o,[y,L]))),V(ot,(L=>{I(y,L),u(l,[y,L])}))}),ts(W)),st),delRelationshipDefinition:y=>(x(e,y),Z(y),st),getStore:w,getRelationshipIds:S,forEachRelationship:y=>R((h=>y(h,(C=>t.forEachRow(E(h),C))))),hasRelationship:b,getLocalTableId:E,getRemoteTableId:A,getRemoteRowId:(y,h)=>g(T(y)?.[0],h),getLocalRowIds:(y,h)=>le(g(T(y)?.[1],h)),getLinkedRowIds:(y,h)=>B(T(y))?[h]:le(_(y,h,!0)),addRelationshipIdsListener:m,addRemoteRowIdListener:(y,h,C)=>c(C,r,[y,h]),addLocalRowIdsListener:(y,h,C)=>c(C,o,[y,h]),addLinkedRowIdsListener:(y,h,C)=>(_(y,h),c(C,l,[y,h])),delListener:y=>(I(...i(y)??[]),st),destroy:k,getListenerStats:()=>({remoteRowId:Bt(r),localRowIds:Bt(o),linkedRowIds:Bt(l)})};return de(st)}));var rn=Promise,Dn=globalThis,en=Dn.window,jn=1e3,Vn=(t,e,r)=>setInterval(t,e*jn),$n=clearInterval,$t=t=>t==null,is=(t,e,r)=>$t(t)?r?.():e(t),As=t=>Array.isArray(t),te=t=>t.length,Pn=(t,e)=>t.test(e),nn=t=>new rn(t),on=async t=>rn.all(t),an=t=>{throw new Error(t)},Zt=async(t,e,r)=>{try{return await t()}catch(o){e?.(o)}},Os=(t,e)=>t.forEach(e),Ie=(t,e)=>t.map(e),Un=(t,e)=>t.splice(0,e),ls=(t,...e)=>t.push(...e),ln=t=>t.shift(),he=Object,sn=t=>he.getPrototypeOf(t),Bn=he.entries,En=t=>!$t(t)&&is(sn(t),e=>e==he.prototype||$t(sn(e)),()=>!0),Hn=he.keys,An=he.freeze,On=(t=[])=>he.fromEntries(t),Wn=(t,e)=>e in t,Nn=(t,e)=>Ie(Bn(t),([r,o])=>e(o,r)),Jn=t=>te(Hn(t)),rs=t=>En(t)&&Jn(t)==0,Fn=t=>t?.size??0,Kn=(t,e)=>t?.has(e)??!1,cn=t=>$t(t)||Fn(t)==0,dn=(t,e)=>t?.forEach(e),hn=(t,e)=>t?.delete(e),xe=t=>new Map(t),Mt=(t,e)=>t?.get(e),ee=(t,e,r)=>$t(r)?(hn(t,e),t):t?.set(e,r),Ws=(t,e,r,o)=>(Kn(t,e)?o?.(Mt(t,e)):ee(t,e,r()),Mt(t,e)),Ns=(t,e,r,o,l=0)=>is((r?Ws:Mt)(t,e[l],l>te(e)-2?r:xe),c=>{if(l>te(e)-2)return o?.(c)&&ee(t,e[l]),c;let u=Ns(c,e,r,o,l+1);return cn(c)&&ee(t,e[l]),u}),qn=/^\d+$/,Qn=()=>{let t=[],e=0;return[r=>(r?ln(t):null)??""+e++,r=>{Pn(qn,r)&&te(t)<1e3&&ls(t,r)}]},zn=t=>new Set(As(t)||$t(t)?t:[t]),_n=(t,e)=>t?.add(e),Gn=(t,e=[""])=>{let r=[],o=(l,c)=>c==te(e)?ls(r,l):e[c]===null?dn(l,u=>o(u,c+1)):Os([e[c],null],u=>o(Mt(l,u),c+1));return o(t,0),r},Yn=t=>{let e,[r,o]=Qn(),l=xe();return[(c,u,i,w=[],S=()=>[])=>{e??=t();let R=r(1);return ee(l,R,[c,u,i,w,S]),_n(Ns(u,i??[""],zn),R),R},(c,u,...i)=>Os(Gn(c,u),w=>dn(w,S=>Mt(l,S)[0](e,...u??[],...i))),c=>is(Mt(l,c),([,u,i])=>(Ns(u,i??[""],void 0,w=>(hn(w,c),cn(w)?1:0)),ee(l,c),o(c),i)),c=>is(Mt(l,c),([u,,i=[],w,S])=>{let R=(...b)=>{let E=te(b);E==te(i)?u(e,...b,...S(b)):$t(i[E])?Os(w[E]?.(...b)??[],T=>R(...b,T)):R(...b,i[E])};R()})]},ns=xe(),os=xe(),Xn=(t=1,e,r)=>t!=1&&e.isMergeable()?[1,e.getMergeableContent,()=>e.getTransactionMergeableChanges(!r),([[o],[l]])=>!rs(o)||!rs(l),e.setDefaultContent]:t!=2?[0,e.getContent,e.getTransactionChanges,([o,l])=>!rs(o)||!rs(l),e.setContent]:an("Store type not supported by this Persister"),Zn=(t,e,r,o,l,c,u,i={},w=0,S=[])=>{let R=0,b=0,E=0,T,F,Z;Ws(ns,S,()=>0),Ws(os,S,()=>[]);let m=xe(),[k,_,I,A,st]=Xn(u,t,w),[y,h,C]=Yn(()=>Q),W=M=>{M!=R&&(R=M,h(m,void 0,R))},K=async()=>{if(!Mt(ns,S)){for(ee(ns,S,1);!$t(T=ln(Mt(os,S)));)await Zt(T,c);ee(ns,S,0)}},U=M=>{(k&&As(M?.[0])?M?.[2]===1?t.applyMergeableChanges:t.setMergeableContent:M?.[2]===1?t.applyChanges:t.setContent)(M)},q=async M=>(R!=2&&(W(1),b++,await O(async()=>{await Zt(async()=>{let rt=await e();As(rt)?U(rt):M?st(M):an(`Content is not an array: ${rt}`)},()=>{M&&st(M)}),W(0)})),Q),nt=async M=>(ot(),await q(M),await Zt(async()=>F=await o(async(rt,ht)=>{ht||rt?R!=2&&(W(1),b++,U(ht??rt),W(0)):await q()}),c),Q),ot=async()=>(F&&(await Zt(()=>l(F),c),F=void 0),Q),lt=()=>!$t(F),N=async M=>(R!=1&&(W(2),E++,await O(async()=>{await Zt(()=>r(_,M),c),W(0)})),Q),L=async()=>(j(),await N(),Z=t.addDidFinishTransactionListener(()=>{let M=I();A(M)&&N(M)}),Q),j=async()=>(Z&&(t.delListener(Z),Z=void 0),Q),et=()=>!$t(Z),G=async(M,rt=!1)=>{let[ht,Rt]=rt?[L,nt]:[nt,L];return await ht(M),await Rt(M),Q},D=async(M=!1)=>{let[rt,ht]=M?[j,ot]:[ot,j];return await rt(),await ht(),Q},H=()=>R,J=M=>y(M,m),Y=M=>(C(M),t),O=async(...M)=>(ls(Mt(os,S),...M),await K(),Q),Q={load:q,startAutoLoad:nt,stopAutoLoad:ot,isAutoLoading:lt,save:N,startAutoSave:L,stopAutoSave:j,isAutoSaving:et,startAutoPersisting:G,stopAutoPersisting:D,getStatus:H,addStatusListener:J,delListener:Y,schedule:O,getStore:()=>t,destroy:()=>(Un(Mt(os,S)),D()),getStats:()=>({loads:b,saves:E}),...i};return An(Q)},Hs=["t","v"],to={keyPath:"k"},eo=async(t,e)=>{let r=Nn(e,(o,l)=>as(t,"put",{k:l,v:o}));Ie(await as(t,"getAllKeys"),o=>Wn(e,o)?0:ls(r,as(t,"delete",o))),await on(r)},as=async(t,e,r)=>nn((o,l)=>{let c=t[e](r);c.onsuccess=()=>o(c.result),c.onerror=()=>l(`objectStore.${e} error`)}),cs=(t,e,r=1,o)=>{let l=async(c,u=[],i=0)=>nn((w,S)=>{let R=(en?en.indexedDB:indexedDB).open(e,i?2:void 0);R.onupgradeneeded=()=>i&&Ie(Hs,b=>Zt(()=>R.result.createObjectStore(b,to))),R.onsuccess=()=>Zt(async()=>{let b=R.result.transaction(Hs,"readwrite"),E=await on(Ie(Hs,(T,F)=>c(b.objectStore(T),u[F])));R.result.close(),w(E)},b=>{R.result.close(),S(b)}),R.onerror=()=>S("indexedDB.open error")});return Zn(t,async()=>await l(async c=>On(Ie(await as(c,"getAll"),({k:u,v:i})=>[u,i]))),c=>l((u,i)=>eo(u,i),c(),1),c=>Vn(c,r),c=>$n(c),o,1,{getDbName:()=>e})};var ds=Te();ds.setTable("docs",{});var hs=cs(ds,"copio-db");hs.startAutoLoad();hs.startAutoSave();var us=class{#t;#e="blobs";#s=null;constructor(e="copio-blobs"){this.#t=e}async#o(){return this.#s?this.#s:(this.#s=new Promise((e,r)=>{if(typeof indexedDB>"u"){r(new Error("IndexedDB is not available"));return}let o=indexedDB.open(this.#t,1);o.onupgradeneeded=()=>{let l=o.result;l.objectStoreNames.contains(this.#e)||l.createObjectStore(this.#e)},o.onsuccess=()=>e(o.result),o.onerror=()=>r(o.error||new Error("Failed to open blob db"))}),this.#s)}async put(e,r){let o=await this.#o();return new Promise((l,c)=>{let w=o.transaction(this.#e,"readwrite").objectStore(this.#e).put(r,e);w.onsuccess=()=>l(),w.onerror=()=>c(w.error)})}async get(e){let r=await this.#o();return new Promise((o,l)=>{let i=r.transaction(this.#e,"readonly").objectStore(this.#e).get(e);i.onsuccess=()=>o(i.result||null),i.onerror=()=>l(i.error)})}async delete(e){let r=await this.#o();return new Promise((o,l)=>{let i=r.transaction(this.#e,"readwrite").objectStore(this.#e).delete(e);i.onsuccess=()=>o(),i.onerror=()=>l(i.error)})}async deleteByPrefix(e){let r=await this.#o();return new Promise((o,l)=>{let u=r.transaction(this.#e,"readwrite").objectStore(this.#e),i=u.openKeyCursor();i.onsuccess=w=>{let S=w.target.result;S?(typeof S.key=="string"&&S.key.startsWith(e)&&u.delete(S.key),S.continue()):o()},i.onerror=()=>l(i.error)})}async sweepOrphans(e){let r=new Set(e),o=await this.#o(),l=0;return new Promise((c,u)=>{let w=o.transaction(this.#e,"readwrite").objectStore(this.#e),S=w.openKeyCursor();S.onsuccess=R=>{let b=R.target.result;if(b){if(typeof b.key=="string"){let E=b.key.split(":")[0];r.has(E)||(w.delete(b.key),l++)}b.continue()}else c(l)},S.onerror=()=>u(S.error)})}async close(){if(this.#s){try{(await this.#s).close()}catch{}this.#s=null}}};function Js(t,e="image/jpeg"){if(t instanceof Blob)return t;if(typeof t!="string"||!t.startsWith("data:"))return null;let r=t.match(/^data:([^;]+);base64,(.*)$/),o=r?r[1]:e,l=r?r[2]:t.split(",")[1],c=atob(l),u=new Uint8Array(c.length);for(let i=0;i<c.length;i++)u[i]=c.charCodeAt(i);return new Blob([u],{type:o})}async function Io(t){return new Promise((e,r)=>{let o=new FileReader;o.onloadend=()=>e(o.result),o.onerror=r,o.readAsDataURL(t)})}var un=class extends jr{#t=null;#e=null;#s=null;#o="copio-db";#u=!1;#i=new Set;#l=new Map;#r=new Map;#n=new Map;#a=new Map;#c=null;constructor(e={}){super(),e.dbName&&e.dbName!=="copio-db"?(this.#o=e.dbName,this.#t=e.store||Te(),this.#t.setTable("docs",{}),this.#e=e.persister||cs(this.#t,this.#o),this.#u=!0):(this.#t=e.store||ds,this.#e=e.persister||hs,this.#o="copio-db"),this.#s=new us(`${this.#o}-blobs`)}get store(){return this.#t}get persister(){return this.#e}get blobStore(){return this.#s}#d(e,r){return typeof r=="string"&&r.startsWith("blob:")&&(this.#i.add(r),this.#l.has(e)||this.#l.set(e,[]),this.#l.get(e).push(r)),r}revokeDocUrls(e){let r=this.#l.get(e);if(r){for(let o of r){try{URL.revokeObjectURL(o)}catch{}this.#i.delete(o)}this.#l.delete(e)}for(let[o,l]of this.#r.entries())if(o.startsWith(`${e}:`)){try{URL.revokeObjectURL(l)}catch{}this.#r.delete(o)}for(let[o,l]of this.#n.entries())if(o.startsWith(`${e}:`)){try{URL.revokeObjectURL(l)}catch{}this.#n.delete(o)}this.#a.delete(e)}revokeAllUrls(){for(let e of this.#i)try{URL.revokeObjectURL(e)}catch{}this.#i.clear(),this.#l.clear(),this.#r.clear(),this.#n.clear(),this.#a.clear()}async init(){return this.#c?this.#c:(this.#c=(async()=>{this.#u?(await this.#e.load(),this.#e.startAutoLoad(),this.#e.startAutoSave()):await this.#e.load(),await this.sweepOrphans();let e=!0;if(typeof navigator<"u"&&navigator.storage&&navigator.storage.persisted)try{e=await navigator.storage.persisted()}catch{}return{kind:"indexeddb",persistent:e}})(),this.#c)}async sweepOrphans(){let e=Object.keys(this.#t.getTable("docs")||{});return this.#s.sweepOrphans(e)}listDocsSync(){let e=this.#t.getTable("docs");return Object.entries(e||{}).map(([r,o])=>({id:r,name:o.name||"",pages:this.#h(o.pages)}))}async listDocs(){return this.listDocsSync()}getDocSync(e){if(this.#a.has(e))return this.#a.get(e);if(!this.#t.hasRow("docs",e))return null;let r=this.#t.getRow("docs",e);return{id:e,name:r.name||"",pages:this.#h(r.pages)}}async getDoc(e){if(!this.#t.hasRow("docs",e))return null;let r=this.#t.getRow("docs",e),o=this.#h(r.pages),l=await Promise.all(o.map(async u=>{if(!u)return u;let i={...u},w=`${e}:${u.id}`,S=await this.#s.get(`${e}:${u.id}`);S&&(i.blob=S,this.#r.has(w)?i.src=this.#r.get(w):(i.src=this.#d(e,URL.createObjectURL(S)),this.#r.set(w,i.src)));let R=`${e}:${u.id}:orig`,b=await this.#s.get(`${e}:${u.id}:original`);return b?(i.originalBlob=b,this.#n.has(R)?i.originalSrc=this.#n.get(R):(i.originalSrc=this.#d(e,URL.createObjectURL(b)),this.#n.set(R,i.originalSrc))):i.blob&&(i.originalBlob=i.blob,i.originalSrc=i.src),i})),c={id:e,name:r.name||"",pages:l};return this.#a.set(e,c),c}async saveDoc(e,r){if(!e)throw new Error("Cannot save document without an ID");let o=Array.isArray(r.pages)?r.pages:this.#h(r.pages),l=[],c=[],u=[];for(let i of o){if(!i)continue;let w=Js(i.src)||(i.src instanceof Blob?i.src:null)||(i.blob instanceof Blob?i.blob:null),S=w?.type||"image/jpeg",R={id:i.id,name:i.name||"",type:i.type||"image",hasBlob:!0,mimeType:S,edits:i.edits,exif:i.exif,content:i.content,ocrText:i.ocrText??null,ocrConfidence:i.ocrConfidence??null,ocrWords:Array.isArray(i.ocrWords)?i.ocrWords:null,ocrWidth:i.ocrWidth??null,ocrHeight:i.ocrHeight??null};l.push(R);let b=`${e}:${i.id}`,E=`${e}:${i.id}:orig`,T={...i},F=this.#r.get(b),Z=typeof i.src=="string"&&i.src.startsWith("data:")||i.src instanceof Blob||i.src&&F&&i.src!==F;if(w)if(T.blob=w,Z||!F){if(F){try{URL.revokeObjectURL(F)}catch{}this.#i.delete(F)}let A=this.#d(e,URL.createObjectURL(w));this.#r.set(b,A),T.src=A}else T.src=F;let m=Js(i.originalSrc)||(i.originalSrc instanceof Blob?i.originalSrc:null)||(i.originalBlob instanceof Blob?i.originalBlob:null),k=this.#n.get(E),_=!k&&!m&&(!i.originalSrc||i.originalSrc===i.src);_&&w&&(m=w);let I=typeof i.originalSrc=="string"&&i.originalSrc.startsWith("data:")||i.originalSrc instanceof Blob||_&&!!m;if(m)if(T.originalBlob=m,I||!k){if(k&&I){try{URL.revokeObjectURL(k)}catch{}this.#i.delete(k)}let A=this.#d(e,URL.createObjectURL(m));this.#n.set(E,A),T.originalSrc=A}else T.originalSrc=k;else k?T.originalSrc=k:i.originalSrc?T.originalSrc=i.originalSrc:(T.originalSrc=T.src,T.blob&&(T.originalBlob=T.blob));c.push(T),u.push({pageId:i.id,page:i,srcBlob:w,origBlob:m})}this.#t.setRow("docs",e,{name:r.name||"",pages:JSON.stringify(l)}),this.#a.set(e,{id:e,name:r.name||"",pages:c});for(let i of u){let{pageId:w,page:S,srcBlob:R,origBlob:b}=i;if(!R&&typeof S.src=="string"&&S.src.startsWith("blob:"))try{R=await(await fetch(S.src)).blob()}catch{}if(R&&await this.#s.put(`${e}:${w}`,R),!b&&typeof S.originalSrc=="string"&&S.originalSrc.startsWith("blob:"))try{b=await(await fetch(S.originalSrc)).blob()}catch{}b&&await this.#s.put(`${e}:${w}:original`,b)}}async deleteDoc(e){this.#t.delRow("docs",e),await this.#s.deleteByPrefix(`${e}:`),this.revokeDocUrls(e),this.#a.delete(e)}async renameDoc(e,r){if(!this.#t.hasRow("docs",e))throw new Error(`Document "${e}" not found`);this.#t.setCell("docs",e,"name",r),this.#a.has(e)&&(this.#a.get(e).name=r)}async savePage(e,r,o){let l=await this.getDoc(e);if(!l)throw new Error(`Document ${e} not found`);let c=l.pages.findIndex(w=>w.id===r),u;if(c>=0)typeof o=="object"&&o!==null&&!(o instanceof Blob)?l.pages[c]={...l.pages[c],...o}:l.pages[c]={...l.pages[c],src:o,blob:o instanceof Blob?o:void 0},u=l.pages[c];else{let w=typeof o=="object"&&o!==null&&!(o instanceof Blob)?{id:r,...o}:{id:r,src:o,blob:o instanceof Blob?o:void 0};l.pages.push(w),u=w}let i=Js(u.src)||(u.src instanceof Blob?u.src:null)||(u.blob instanceof Blob?u.blob:null);if(!i&&typeof u.src=="string"&&u.src.startsWith("blob:"))try{i=await(await fetch(u.src)).blob()}catch{}i&&await this.#s.put(`${e}:${r}`,i),await this.saveDoc(e,l)}async getPage(e,r){let o=await this.#s.get(`${e}:${r}`);if(o)return o;let l=this.getDocSync(e);if(!l)return null;let c=l.pages.find(u=>u.id===r);return c?c.content??c.src??c:null}async deletePage(e,r){let o=this.getDocSync(e);if(!o)return;o.pages=o.pages.filter(u=>u.id!==r),this.#t.setRow("docs",e,{name:o.name||"",pages:JSON.stringify(o.pages)}),await this.#s.delete(`${e}:${r}`),await this.#s.delete(`${e}:${r}:original`);let l=`${e}:${r}`;if(this.#r.has(l)){try{URL.revokeObjectURL(this.#r.get(l))}catch{}this.#r.delete(l)}let c=`${e}:${r}:orig`;if(this.#n.has(c)){try{URL.revokeObjectURL(this.#n.get(c))}catch{}this.#n.delete(c)}this.#a.delete(e)}subscribe(e){let r=this.#t.addTableListener("docs",e);return()=>{this.#t.delListener(r)}}#h(e){if(Array.isArray(e))return e;if(typeof e=="string")try{return JSON.parse(e)}catch{return[]}return[]}};export{Te as a,ds as b,Js as c,Io as d,un as e};
|
|
2
|
+
//# sourceMappingURL=chunk-IH2AI54D.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as s}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as s}from"./chunk-NEEWG3OP.js";import{b as o}from"./chunk-WETG2JD7.js";var e=class extends s{#t=null;#n=null;#o=null;constructor(t=null,n=null){super(),this.#n=t,this.#o=n}async connect(t={}){let n=t.repo||this.#n,r=t.onStateChange||this.#o;return this.#t=new o(n,r),this.#t}async disconnect(){this.#t&&typeof this.#t.destroy=="function"&&(this.#t.destroy(),this.#t=null)}};export{e as a};
|
|
2
|
+
//# sourceMappingURL=chunk-J7HWZNIP.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as t}from"./chunk-ULTSZWZO.js";var n=class extends t{async renderEdits(r,e){return r}async crop(r,e){return r}async rotate(r,e){return r}async applyFilter(r,e){return r}};export{n as a};
|
|
2
|
+
//# sourceMappingURL=chunk-KH5JE65X.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as w}from"./chunk-YNY65JUJ.js";import{f as Y,g as _}from"./chunk-ZT72PD2C.js";import{a as te}from"./chunk-4C666HHU.js";var re={};te(re,{exportDocumentAsImages:()=>ne,exportDocumentAsPdf:()=>oe});async function oe(b,s,z={}){let{onProgress:u,showProgress:j=!0,download:B=!0,searchable:d=!1,lang:R="eng",onOcrComplete:C=null}=z;if(!s||s.length===0){w.warning("No images to export");return}let c=null,a=s.length;try{j&&a>1&&(c=await w.progress({message:`Exporting "${b||"document"}.pdf"...`,total:a,done:0}));let x=null;if(typeof window<"u"&&!window.PDFDocument){typeof u=="function"&&u(0,a,"Downloading PDF engine...");try{x=await w.progress({message:"Downloading PDF engine...",total:100,done:0})}catch{}}let m;try{m=await Y()}finally{x?.close()}let E=595.28,o=841.89,n=new m({autoFirstPage:!1}),p=[];n.on("data",t=>p.push(t));let h=new Promise((t,e)=>{n.on("end",()=>{try{let r=new Blob(p,{type:"application/pdf"});if(B!==!1){let i=URL.createObjectURL(r),g=document.createElement("a");g.href=i,g.download=`${b||"document"}.pdf`,g.click(),URL.revokeObjectURL(i),w.success(`Exported "${b||"document"}.pdf"`)}c?.close(),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-complete",{bubbles:!0,composed:!0,detail:{type:"pdf",format:"pdf",blob:r,docName:b||"document",searchable:!!d}})),t(r)}catch(r){e(r)}}),n.on("error",e)});for(let t=0;t<s.length;t++){let e=s[t],r=t+1;if(e.src||e.blob){let i=new Image,g=null,l=e.src;if(e.blob instanceof Blob&&(!l||l instanceof Blob)?(l=URL.createObjectURL(e.blob),g=l):e.src instanceof Blob&&(l=URL.createObjectURL(e.src),g=l),await new Promise(f=>{i.onload=f,i.onerror=$=>{console.warn("Page image failed to load for PDF:",$),f(void 0)},i.src=l}),i.width&&i.height){n.addPage({size:"A4"});let f=E/i.width,$=o/i.height,O=Math.min(f,$),W=i.width*O,F=i.height*O,k=(E-W)/2,A=(o-F)/2,v=null;if(e.blob instanceof Blob)v=await e.blob.arrayBuffer();else if(e.src instanceof Blob)v=await e.src.arrayBuffer();else if(typeof e.src=="string"&&e.src.startsWith("blob:"))try{v=await(await(await fetch(e.src)).blob()).arrayBuffer()}catch{}if(v?n.image(v,k,A,{width:W,height:F}):n.image(l,k,A,{width:W,height:F}),d){let y=Array.isArray(e.ocrWords)&&e.ocrWords.length>0?e.ocrWords:null;if(!y&&(e.src||e.blob)){typeof u=="function"&&u(r,a,`Recognizing text for page ${r} of ${a}...`),c&&c.update({done:r,total:a,message:`Recognizing text for page ${r} of ${a}...`});try{let L=await(z.recognizeImageText||(await import("./ocr.js")).recognizeImageText)(e.blob||e.src,{lang:R});y=L?.words||[],e.ocrText=L?.text||"",e.ocrConfidence=L?.confidence??0,e.ocrWords=y,e.ocrWidth=i.width,e.ocrHeight=i.height}catch(P){console.warn(`On-demand OCR failed for page ${r}:`,P)}}if(y&&y.length>0){n.save(),n.font("Helvetica");let P=e.ocrWidth||i.width,L=e.ocrHeight||i.height,H=W/P,I=F/L;for(let N of y){let U=(N.text||"").trim();if(!U)continue;let S=N.bbox||{},T=S.x0??0,M=S.y0??0,J=Math.max(1,(S.x1??0)-T),G=Math.max(1,(S.y1??0)-M),K=k+T*H,q=A+M*I,Q=J*H,V=G*I,ee=Math.max(1,V);n.fontSize(ee);let Z=n.widthOfString(U),X=0;Z>0&&U.length>1&&(X=(Q-Z)/(U.length-1)),n.text(U,K,q,{renderingMode:3,lineBreak:!1,characterSpacing:X})}n.restore()}}}if(g)try{URL.revokeObjectURL(g)}catch{}}typeof u=="function"&&u(r,a),c&&c.update({done:r,total:a,message:`Exporting PDF: page ${r} of ${a}...`}),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-progress",{detail:{type:"pdf",done:r,total:a,docName:b||"document"}})),await new Promise(i=>setTimeout(i,0))}if(d&&typeof C=="function")try{await C(s)}catch(t){console.warn("onOcrComplete error:",t)}return n.end(),await h}catch(x){c?.close(),console.error("Error generating PDF:",x),w.error("Failed to generate PDF")}}async function ne(b,s,z={}){let{onProgress:u,showProgress:j=!0,download:B=!0}=z;if(!s||s.length===0){w.warning("No images to export");return}let d=null;try{let R=(b||"document").trim(),c=(o=>o.replace(/[/\\?%*:|"<>]/g,"_"))(R)||"document";if(s.length===1){let o=s[0],n="jpg",p="",h=!1,t=null;if(o.blob instanceof Blob)t=o.blob,t.type&&t.type.includes("png")&&(n="png"),p=URL.createObjectURL(t),h=!0;else if(o.src instanceof Blob)t=o.src,t.type&&t.type.includes("png")&&(n="png"),p=URL.createObjectURL(t),h=!0;else if(typeof o.src=="string")if(p=o.src,o.src.startsWith("data:")){let e=o.src.match(/^data:(image\/[a-zA-Z+]+);base64,/);e&&e[1].includes("png")&&(n="png");try{t=await(await fetch(o.src)).blob()}catch{t=new Blob([o.src],{type:`image/${n}`})}}else if(o.src.startsWith("blob:"))try{t=await(await fetch(o.src)).blob(),t.type&&t.type.includes("png")&&(n="png")}catch{}else try{t=await(await fetch(o.src)).blob(),p=URL.createObjectURL(t),h=!0}catch{}if(typeof u=="function"&&u(1,1),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-progress",{detail:{type:"image",done:1,total:1,docName:c}})),B!==!1){let e=document.createElement("a");e.href=p,e.download=`${c}.${n}`,e.click(),w.success(`Exported "${c}.${n}"`)}return h&&URL.revokeObjectURL(p),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-complete",{bubbles:!0,composed:!0,detail:{type:"image",format:n,blob:t,docName:c}})),t}let a=s.length;j&&a>1&&(d=await w.progress({message:`Exporting "${c}.zip"...`,total:a,done:0}));let x=await _(),D=new x,m=0;for(let o=0;o<s.length;o++){let n=s[o],p=[n.blob||n.src],h=Math.max(2,String(s.length*p.length).length);for(let e=0;e<p.length;e++){let r=p[e],i="jpg",g=null;if(r instanceof Blob)r.type&&r.type.includes("png")&&(i="png"),g=await r.arrayBuffer();else if(typeof r=="string"&&r.startsWith("data:")){let l=r.match(/^data:(image\/[a-zA-Z+]+);base64,(.*)$/),f="";l?(l[1].includes("png")&&(i="png"),f=l[2]):f=r.replace(/^data:[^;]+;base64,/,"");let $=String(m+1).padStart(h,"0"),O=`${c}-${$}.${i}`;D.file(O,f,{base64:!0}),m++;continue}else if(typeof r=="string")try{let f=await(await fetch(r)).blob();f.type&&f.type.includes("png")&&(i="png"),g=await f.arrayBuffer()}catch{}if(g){let l=String(m+1).padStart(h,"0"),f=`${c}-${l}.${i}`;D.file(f,g),m++}}let t=o+1;typeof u=="function"&&u(t,a),d&&d.update({done:t,total:a,message:`Exporting ZIP: page ${t} of ${a}...`}),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-progress",{detail:{type:"zip",done:t,total:a,docName:c}})),await new Promise(e=>setTimeout(e,0))}d&&d.update({message:"Compressing archive..."});let E=await D.generateAsync({type:"blob"},o=>{d&&o.percent&&d.update({value:Math.round(o.percent),message:`Compressing ZIP: ${Math.round(o.percent)}%...`})});if(B!==!1){let o=URL.createObjectURL(E),n=document.createElement("a");n.href=o,n.download=`${c}.zip`,n.click(),URL.revokeObjectURL(o),w.success(`Exported "${c}.zip"`)}return d?.close(),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-complete",{bubbles:!0,composed:!0,detail:{type:"zip",format:"zip",blob:E,docName:c}})),E}catch(R){d?.close(),console.error("Error downloading images:",R),w.error("Failed to download images")}}export{oe as a,ne as b,re as c};
|
|
2
|
+
//# sourceMappingURL=chunk-MEE2NNYB.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var e=class{async connect(t={}){throw new Error("SyncPort.connect() must be implemented by adapter")}async disconnect(){throw new Error("SyncPort.disconnect() must be implemented by adapter")}};export{e as a};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-NEEWG3OP.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var e=class{async exportDocumentAsPdf(r,a,o={}){throw new Error("PdfPort.exportDocumentAsPdf() must be implemented by adapter")}async renderPdfPagesToDataUrls(r){throw new Error("PdfPort.renderPdfPagesToDataUrls() must be implemented by adapter")}};export{e as a};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-O6FQFVKY.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as L,b as O,c as S,e as m}from"./chunk-IH2AI54D.js";import{a as U}from"./chunk-FQRADJY6.js";import{a as D}from"./chunk-DIU5BGU5.js";async function k(){if(typeof location<"u"&&location.search&&(new URLSearchParams(location.search).has("no-opfs")||new URLSearchParams(location.search).get("storage")==="indexeddb")||typeof navigator>"u"||!navigator.storage||typeof navigator.storage.getDirectory!="function")return!1;try{let l=await navigator.storage.getDirectory();if(!l)return!1;let t=`.copio-probe-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`,r=await l.getFileHandle(t,{create:!0}),i=await r.createWritable();if(await i.write(new Uint8Array([1,2,3,4])),await i.close(),(await r.getFile()).size!==4)throw new Error("OPFS probe size mismatch");return await l.removeEntry(t),!0}catch{return!1}}function F(l,t,r="store.json"){let i=0,s=null,n=Promise.resolve(),a=0,o=()=>typeof t=="function"?t():t,e=async()=>{await n;let f=o();if(f){i=1;try{let u=await(await(await f.getFileHandle(r)).getFile()).text();u&&u.trim().length>0&&l.setJson(u)}catch{}finally{i=0}}},c=()=>{let f=o();return f?(a++,i=2,n=n.catch(()=>{}).then(async()=>{try{let w=l.getJson(),u=await(await f.getFileHandle(r,{create:!0})).createWritable();await u.write(w),await u.close()}catch(w){console.warn("[OpfsPersister] Failed to save store.json:",w)}finally{a--,a<=0&&(a=0,i=0)}}),n):Promise.resolve()};return{load:e,save:c,startAutoSave:()=>{s||(s=l.addDidFinishTransactionListener(()=>{c()}))},stopAutoSave:()=>{s&&(l.delListener(s),s=null)},getStatus:()=>i,getStore:()=>l}}async function $(l){let t=[];try{if(typeof l.entries=="function")for await(let r of l.entries())t.push(r);else if(typeof l.values=="function")for await(let r of l.values())t.push([r.name,r])}catch(r){console.warn("[OpfsAdapter] Error reading directory entries:",r)}return t}var v=class extends D{#p;#d="copio";#b=null;#g=null;#i=null;#r=null;#u=null;#t=!1;#e=null;#c=new Set;#l=new Map;#s=new Map;#a=new Map;#n=new Map;#w=null;constructor(t={}){super(),this.#p=t,this.#d=t.dirName||"copio",t.store?this.#r=t.store:t.dirName&&t.dirName!=="copio"?(this.#r=L(),this.#r.setTable("docs",{})):this.#r=O,this.#u=t.persister||F(this.#r,()=>this.#g,"store.json")}get store(){return this.#t?this.#e?.store:this.#r}get persister(){return this.#t?this.#e?.persister:this.#u}get isFallback(){return this.#t}get fallbackAdapter(){return this.#e}async#o(){if(this.#t)return!1;if(this.#i&&this.#g)return!0;if(typeof navigator<"u"&&navigator.storage&&typeof navigator.storage.getDirectory=="function")try{return this.#b=await navigator.storage.getDirectory(),this.#g=await this.#b.getDirectoryHandle(this.#d,{create:!0}),this.#i=await this.#g.getDirectoryHandle("docs",{create:!0}),!0}catch(t){return console.warn("[OpfsAdapter] OPFS directory access failed, switching to fallback:",t),await this.#h(),!1}else return await this.#h(),!1}#y(t,r){return typeof r=="string"&&r.startsWith("blob:")&&(this.#c.add(r),this.#l.has(t)||this.#l.set(t,[]),this.#l.get(t).push(r)),r}revokeDocUrls(t){if(this.#t){this.#e?.revokeDocUrls(t);return}let r=this.#l.get(t);if(r){for(let i of r){try{URL.revokeObjectURL(i)}catch{}this.#c.delete(i)}this.#l.delete(t)}for(let[i,s]of this.#s.entries())if(i.startsWith(`${t}:`)){try{URL.revokeObjectURL(s)}catch{}this.#s.delete(i)}for(let[i,s]of this.#a.entries())if(i.startsWith(`${t}:`)){try{URL.revokeObjectURL(s)}catch{}this.#a.delete(i)}this.#n.delete(t)}revokeAllUrls(){if(this.#t){this.#e?.revokeAllUrls();return}for(let t of this.#c)try{URL.revokeObjectURL(t)}catch{}this.#c.clear(),this.#l.clear(),this.#s.clear(),this.#a.clear(),this.#n.clear()}async init(){return this.#w?this.#w:(this.#w=(async()=>{if(this.#p.forceFallback)return this.#h();if(!await k())return this.#h();try{await this.#o(),await this.#u.load(),this.#u.startAutoSave(),await this.sweepOrphans();let r=!1;if(typeof navigator<"u"&&navigator.storage&&navigator.storage.persisted)try{r=await navigator.storage.persisted()}catch{}return{kind:"opfs",persistent:r}}catch(r){return console.warn("[OpfsAdapter] OPFS initialization failed, switching to IndexedDB fallback:",r),this.#h()}})(),this.#w)}async#h(){return this.#t=!0,this.#e=new m(this.#p),{kind:"indexeddb",persistent:(await this.#e.init()).persistent}}async sweepOrphans(){if(this.#t)return this.#e?.sweepOrphans();if(await this.#o(),!this.#i)return 0;let t=0,r=this.#r.getTable("docs")||{},i=new Set(Object.keys(r)),s=new Map;for(let[a,o]of Object.entries(r)){let e=this.#f(o.pages);s.set(a,new Set(e.map(c=>c.id)))}let n=await $(this.#i);for(let[a,o]of n)if(o.kind==="directory")if(i.has(a)){let e=s.get(a)||new Set,c=o,g=await $(c);for(let[y]of g){let f=y.replace(/-original\.bin$/,"").replace(/\.bin$/,"");if(!e.has(f))try{await c.removeEntry(y),t++}catch{}}}else try{await this.#i.removeEntry(a,{recursive:!0}),t++}catch{}return t}listDocsSync(){if(this.#t)return this.#e?.listDocsSync();let t=this.#r.getTable("docs");return Object.entries(t||{}).map(([r,i])=>({id:r,name:i.name||"",pages:this.#f(i.pages)}))}async listDocs(){return this.#t?this.#e?.listDocs():this.listDocsSync()}getDocSync(t){if(this.#t)return this.#e?.getDocSync(t);if(this.#n.has(t))return this.#n.get(t);if(!this.#r.hasRow("docs",t))return null;let r=this.#r.getRow("docs",t);return{id:t,name:r.name||"",pages:this.#f(r.pages)}}async getDoc(t){if(this.#t)return this.#e?.getDoc(t);if(await this.#o(),!this.#r.hasRow("docs",t))return null;let r=this.#r.getRow("docs",t),i=this.#f(r.pages),s=null;if(this.#i)try{s=await this.#i.getDirectoryHandle(t)}catch{}let n=await Promise.all(i.map(async o=>{if(!o||!s)return o;let e={...o},c=`${t}:${o.id}`;try{let f=await(await s.getFileHandle(`${o.id}.bin`)).getFile();e.blob=f,this.#s.has(c)?e.src=this.#s.get(c):(e.src=this.#y(t,URL.createObjectURL(f)),this.#s.set(c,e.src))}catch{}let g=`${t}:${o.id}:orig`;try{let f=await(await s.getFileHandle(`${o.id}-original.bin`)).getFile();e.originalBlob=f,this.#a.has(g)?e.originalSrc=this.#a.get(g):(e.originalSrc=this.#y(t,URL.createObjectURL(f)),this.#a.set(g,e.originalSrc))}catch{e.blob&&(e.originalBlob=e.blob,e.originalSrc=e.src)}return e})),a={id:t,name:r.name||"",pages:n};return this.#n.set(t,a),a}async saveDoc(t,r){if(this.#t)return this.#e?.saveDoc(t,r);if(!t)throw new Error("Cannot save document without an ID");let i=Array.isArray(r.pages)?r.pages:this.#f(r.pages),s=[],n=[],a=[];for(let e of i){if(!e)continue;let c=S(e.src)||(e.src instanceof Blob?e.src:null)||(e.blob instanceof Blob?e.blob:null),g=c?.type||"image/jpeg",y={id:e.id,name:e.name||"",type:e.type||"image",hasBlob:!0,mimeType:g,edits:e.edits,exif:e.exif,content:e.content,ocrText:e.ocrText??null,ocrConfidence:e.ocrConfidence??null,ocrWords:Array.isArray(e.ocrWords)?e.ocrWords:null,ocrWidth:e.ocrWidth??null,ocrHeight:e.ocrHeight??null};s.push(y);let f=`${t}:${e.id}`,w=`${t}:${e.id}:orig`,h={...e},u=this.#s.get(f),j=typeof e.src=="string"&&e.src.startsWith("data:")||e.src instanceof Blob||e.src&&u&&e.src!==u;if(c)if(h.blob=c,j||!u){if(u){try{URL.revokeObjectURL(u)}catch{}this.#c.delete(u)}let b=this.#y(t,URL.createObjectURL(c));this.#s.set(f,b),h.src=b}else h.src=u;let d=S(e.originalSrc)||(e.originalSrc instanceof Blob?e.originalSrc:null)||(e.originalBlob instanceof Blob?e.originalBlob:null),p=this.#a.get(w),R=!p&&!d&&(!e.originalSrc||e.originalSrc===e.src);R&&c&&(d=c);let H=typeof e.originalSrc=="string"&&e.originalSrc.startsWith("data:")||e.originalSrc instanceof Blob||R&&!!d;if(d)if(h.originalBlob=d,H||!p){if(p&&H){try{URL.revokeObjectURL(p)}catch{}this.#c.delete(p)}let b=this.#y(t,URL.createObjectURL(d));this.#a.set(w,b),h.originalSrc=b}else h.originalSrc=p;else p?h.originalSrc=p:e.originalSrc?h.originalSrc=e.originalSrc:(h.originalSrc=h.src,h.blob&&(h.originalBlob=h.blob));n.push(h),a.push({pageId:e.id,page:e,srcBlob:c,origBlob:d})}if(this.#r.setRow("docs",t,{name:r.name||"",pages:JSON.stringify(s)}),this.#n.set(t,{id:t,name:r.name||"",pages:n}),await this.#o(),this.#t)return this.#e?.saveDoc(t,r);let o=null;if(this.#i)try{o=await this.#i.getDirectoryHandle(t,{create:!0})}catch(e){console.warn(`[OpfsAdapter] Failed to get doc directory "${t}":`,e)}if(o)for(let e of a){let{pageId:c,page:g,srcBlob:y,origBlob:f}=e;if(!y&&typeof g.src=="string"&&g.src.startsWith("blob:"))try{y=await(await fetch(g.src)).blob()}catch{}if(y)try{let h=await(await o.getFileHandle(`${c}.bin`,{create:!0})).createWritable();await h.write(y),await h.close()}catch(w){console.warn(`[OpfsAdapter] Failed writing page file "${c}.bin":`,w)}if(!f&&typeof g.originalSrc=="string"&&g.originalSrc.startsWith("blob:"))try{f=await(await fetch(g.originalSrc)).blob()}catch{}if(f)try{let h=await(await o.getFileHandle(`${c}-original.bin`,{create:!0})).createWritable();await h.write(f),await h.close()}catch{}}}async deleteDoc(t){if(this.#t)return this.#e?.deleteDoc(t);if(this.#r.delRow("docs",t),this.#n.delete(t),this.revokeDocUrls(t),await this.#o(),this.#i)try{await this.#i.removeEntry(t,{recursive:!0})}catch{}}async renameDoc(t,r){if(this.#t)return this.#e?.renameDoc(t,r);if(!this.#r.hasRow("docs",t))throw new Error(`Document "${t}" not found`);this.#r.setCell("docs",t,"name",r),this.#n.has(t)&&(this.#n.get(t).name=r)}async savePage(t,r,i){if(this.#t)return this.#e?.savePage(t,r,i);await this.#o();let s=await this.getDoc(t);if(!s)throw new Error(`Document ${t} not found`);let n=s.pages.findIndex(e=>e.id===r),a;if(n>=0)typeof i=="object"&&i!==null&&!(i instanceof Blob)?s.pages[n]={...s.pages[n],...i}:s.pages[n]={...s.pages[n],src:i,blob:i instanceof Blob?i:void 0},a=s.pages[n];else{let e=typeof i=="object"&&i!==null&&!(i instanceof Blob)?{id:r,...i}:{id:r,src:i,blob:i instanceof Blob?i:void 0};s.pages.push(e),a=e}let o=S(a.src)||(a.src instanceof Blob?a.src:null)||(a.blob instanceof Blob?a.blob:null);if(!o&&typeof a.src=="string"&&a.src.startsWith("blob:"))try{o=await(await fetch(a.src)).blob()}catch{}if(o&&this.#i)try{let g=await(await(await this.#i.getDirectoryHandle(t,{create:!0})).getFileHandle(`${r}.bin`,{create:!0})).createWritable();await g.write(o),await g.close()}catch(e){console.warn(`[OpfsAdapter] Failed writing page file "${r}.bin":`,e)}await this.saveDoc(t,s)}async getPage(t,r){if(this.#t)return this.#e?.getPage(t,r);if(await this.#o(),this.#i)try{return await(await(await this.#i.getDirectoryHandle(t)).getFileHandle(`${r}.bin`)).getFile()}catch{}let i=this.getDocSync(t);if(!i)return null;let s=i.pages.find(n=>n.id===r);return s?s.content??s.src??s:null}async deletePage(t,r){if(this.#t)return this.#e?.deletePage(t,r);await this.#o();let i=this.getDocSync(t);if(!i)return;if(i.pages=i.pages.filter(a=>a.id!==r),this.#r.setRow("docs",t,{name:i.name||"",pages:JSON.stringify(i.pages)}),this.#i){try{await(await this.#i.getDirectoryHandle(t)).removeEntry(`${r}.bin`)}catch{}try{await(await this.#i.getDirectoryHandle(t)).removeEntry(`${r}-original.bin`)}catch{}}let s=`${t}:${r}`;if(this.#s.has(s)){try{URL.revokeObjectURL(this.#s.get(s))}catch{}this.#s.delete(s)}let n=`${t}:${r}:orig`;if(this.#a.has(n)){try{URL.revokeObjectURL(this.#a.get(n))}catch{}this.#a.delete(n)}this.#n.delete(t)}subscribe(t){if(this.#t)return this.#e?.subscribe(t);let r=this.#r.addTableListener("docs",t);return()=>{this.#r.delListener(r)}}#f(t){if(Array.isArray(t))return t;if(typeof t=="string")try{return JSON.parse(t)}catch{return[]}return[]}};function K(l={}){return l.forceMemory?new U:l.forceIndexedDb?new m(l):l.forceOpfs?new v(l):typeof navigator<"u"&&navigator.storage&&typeof navigator.storage.getDirectory=="function"?new v(l):typeof indexedDB<"u"?new m(l):new U}export{k as a,v as b,K as c};
|
|
2
|
+
//# sourceMappingURL=chunk-RDCHJL6F.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as r}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as r}from"./chunk-6DSLE3AY.js";var o=class extends r{async recognizeImageText(n,t={}){let e=new Error('Feature "ocr" is disabled or OCR module not opted in');throw e.code="FEATURE_DISABLED",e}async recognizeDocumentPages(n,t={}){let e=new Error('Feature "ocr" is disabled or OCR module not opted in');throw e.code="FEATURE_DISABLED",e}async getOcrWorker(){return null}async terminateOcrWorker(){}};export{o as a};
|
|
2
|
+
//# sourceMappingURL=chunk-U3V3VZGO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var t=class{async renderEdits(r,e){throw new Error("ImageProcessorPort.renderEdits() must be implemented by adapter")}async crop(r,e){throw new Error("ImageProcessorPort.crop() must be implemented by adapter")}async rotate(r,e){throw new Error("ImageProcessorPort.rotate() must be implemented by adapter")}async applyFilter(r,e){throw new Error("ImageProcessorPort.applyFilter() must be implemented by adapter")}};export{t as a};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-ULTSZWZO.js.map
|