@copio/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -2
- package/css/container.css +177 -0
- package/css/cropper.css +306 -0
- package/css/main.css +139 -0
- package/css/reset.css +204 -0
- package/css/shoelace.css +485 -0
- package/css/utils.css +689 -0
- package/dist/adapters/image/canvas2d-adapter.js +2 -0
- package/dist/adapters/image/canvas2d-adapter.js.map +7 -0
- package/dist/adapters/image/index.js +2 -0
- package/dist/adapters/image/index.js.map +7 -0
- package/dist/adapters/image/null-image-processor-adapter.js +2 -0
- package/dist/adapters/image/null-image-processor-adapter.js.map +7 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +7 -0
- package/dist/adapters/indexeddb-adapter.js +2 -0
- package/dist/adapters/indexeddb-adapter.js.map +7 -0
- package/dist/adapters/memory-adapter.js +2 -0
- package/dist/adapters/memory-adapter.js.map +7 -0
- package/dist/adapters/ocr/index.js +2 -0
- package/dist/adapters/ocr/index.js.map +7 -0
- package/dist/adapters/ocr/null-ocr-adapter.js +2 -0
- package/dist/adapters/ocr/null-ocr-adapter.js.map +7 -0
- package/dist/adapters/ocr/tesseract-wasm-adapter.js +2 -0
- package/dist/adapters/ocr/tesseract-wasm-adapter.js.map +7 -0
- package/dist/adapters/pdf/index.js +2 -0
- package/dist/adapters/pdf/index.js.map +7 -0
- package/dist/adapters/pdf/null-pdf-adapter.js +2 -0
- package/dist/adapters/pdf/null-pdf-adapter.js.map +7 -0
- package/dist/adapters/pdf/pdfkit-adapter.js +2 -0
- package/dist/adapters/pdf/pdfkit-adapter.js.map +7 -0
- package/dist/adapters/storage/index.js +2 -0
- package/dist/adapters/storage/index.js.map +7 -0
- package/dist/adapters/storage/indexeddb-adapter.js +2 -0
- package/dist/adapters/storage/indexeddb-adapter.js.map +7 -0
- package/dist/adapters/storage/memory-adapter.js +2 -0
- package/dist/adapters/storage/memory-adapter.js.map +7 -0
- package/dist/adapters/sync/index.js +2 -0
- package/dist/adapters/sync/index.js.map +7 -0
- package/dist/adapters/sync/null-sync-adapter.js +2 -0
- package/dist/adapters/sync/null-sync-adapter.js.map +7 -0
- package/dist/adapters/sync/peerjs-adapter.js +2 -0
- package/dist/adapters/sync/peerjs-adapter.js.map +7 -0
- package/dist/canvas-FAXPLPXN.js +2 -0
- package/dist/cdn.js +2770 -0
- package/dist/chunk-36F637QU.js +2 -0
- package/dist/chunk-4C666HHU.js +2 -0
- package/dist/chunk-4GEMGDRU.js +1 -0
- package/dist/chunk-4JPEWIT4.js +2 -0
- package/dist/chunk-6IBEH4EW.js +2601 -0
- package/dist/chunk-A5G52Q2W.js +2 -0
- package/dist/chunk-AU7NM25J.js +2 -0
- package/dist/chunk-B2EK6INF.js +2 -0
- package/dist/chunk-B5BEYYR2.js +8 -0
- package/dist/chunk-B7HT2X67.js +2 -0
- package/dist/chunk-BKZEOOH4.js +2 -0
- package/dist/chunk-CWCS22CQ.js +1 -0
- package/dist/chunk-DGGK5KEX.js +2 -0
- package/dist/chunk-E7JYVRJA.js +2 -0
- package/dist/chunk-G65H4ZTJ.js +2 -0
- package/dist/chunk-HN3336JN.js +2 -0
- package/dist/chunk-IUBYFIV6.js +12 -0
- package/dist/chunk-K6YP7EET.js +8 -0
- package/dist/chunk-KIMVF5UG.js +2 -0
- package/dist/chunk-LI54F6PA.js +2 -0
- package/dist/chunk-N4R55VRR.js +2 -0
- package/dist/chunk-N7Q34F2P.js +4 -0
- package/dist/chunk-OI4WCW7E.js +2 -0
- package/dist/chunk-PUJYN435.js +1 -0
- package/dist/chunk-PVNRK4OH.js +2 -0
- package/dist/chunk-SH4P4XSZ.js +2 -0
- package/dist/chunk-UCV3MQ6I.js +33 -0
- package/dist/chunk-V2FP4EEH.js +2 -0
- package/dist/chunk-V6E2SSSW.js +1 -0
- package/dist/chunk-XEN5VKAV.js +19 -0
- package/dist/chunk-YHLOPPXM.js +2 -0
- package/dist/core.js +2 -0
- package/dist/custom-elements.json +4779 -0
- package/dist/export.js +2 -0
- package/dist/fs-HJ6WWW73.js +2 -0
- package/dist/http-FKJJMT2N.js +2 -0
- package/dist/https-MUBFLDZM.js +2 -0
- package/dist/index.js +99 -0
- package/dist/ocr.js +2 -0
- package/dist/path2d-QWN6DFCC.js +2 -0
- package/dist/scanner.js +2631 -0
- package/dist/sync.js +2 -0
- package/dist/types/js/adapters/image/canvas2d-adapter.d.ts +42 -0
- package/dist/types/js/adapters/image/image-processor-port.d.ts +41 -0
- package/dist/types/js/adapters/image/index.d.ts +3 -0
- package/dist/types/js/adapters/image/null-image-processor-adapter.d.ts +13 -0
- package/dist/types/js/adapters/ocr/index.d.ts +3 -0
- package/dist/types/js/adapters/ocr/null-ocr-adapter.d.ts +39 -0
- package/dist/types/js/adapters/ocr/ocr-port.d.ts +139 -0
- package/dist/types/js/adapters/ocr/tesseract-wasm-adapter.d.ts +40 -0
- package/dist/types/js/adapters/pdf/index.d.ts +3 -0
- package/dist/types/js/adapters/pdf/null-pdf-adapter.d.ts +23 -0
- package/dist/types/js/adapters/pdf/pdf-port.d.ts +21 -0
- package/dist/types/js/adapters/pdf/pdfkit-adapter.d.ts +16 -0
- package/dist/types/js/adapters/storage/index.d.ts +22 -0
- package/dist/types/js/adapters/storage/indexeddb-adapter.d.ts +109 -0
- package/dist/types/js/adapters/storage/memory-adapter.d.ts +101 -0
- package/dist/types/js/adapters/storage/storage-port.d.ts +113 -0
- package/dist/types/js/adapters/sync/index.d.ts +3 -0
- package/dist/types/js/adapters/sync/null-sync-adapter.d.ts +14 -0
- package/dist/types/js/adapters/sync/peerjs-adapter.d.ts +16 -0
- package/dist/types/js/adapters/sync/sync-port.d.ts +18 -0
- package/dist/types/js/components/copio-header.d.ts +19 -0
- package/dist/types/js/components/copio-loader.d.ts +6 -0
- package/dist/types/js/core/store.d.ts +2 -0
- package/dist/types/js/routes/add-edit/copio-add-edit-dialog.d.ts +9 -0
- package/dist/types/js/routes/doc/copio-carousel.d.ts +43 -0
- package/dist/types/js/routes/doc/copio-images.d.ts +37 -0
- package/dist/types/js/routes/home/copio-row.d.ts +49 -0
- package/dist/types/js/routes/ocr/copio-doc-ocr-dialog.d.ts +97 -0
- package/dist/types/js/routes/sync/copio-sync-dialog.d.ts +13 -0
- package/dist/types/js/services/doc-repository.d.ts +233 -0
- package/dist/types/js/services/export-utils.d.ts +42 -0
- package/dist/types/js/services/ice-servers.d.ts +1 -0
- package/dist/types/js/services/notify.d.ts +82 -0
- package/dist/types/js/services/ocr-service.d.ts +64 -0
- package/dist/types/js/services/sync-service.d.ts +11 -0
- package/dist/types/js/styles/cropper-styles.d.ts +5 -0
- package/dist/types/js/utils/module-loader.d.ts +76 -0
- package/dist/types/js/utils/pdf-utils.d.ts +7 -0
- package/dist/types/js/utils/utils.d.ts +54 -0
- package/dist/types/sdk/cdn.d.ts +7 -0
- package/dist/types/sdk/core.d.ts +310 -0
- package/dist/types/sdk/elements.d.ts +25 -0
- package/dist/types/sdk/events.d.ts +227 -0
- package/dist/types/sdk/index.d.ts +37 -0
- package/dist/types/sdk/license.d.ts +12 -0
- package/dist/types/sdk/models.d.ts +174 -0
- package/dist/types/sdk/scanner.d.ts +68 -0
- package/dist/types/sdk/styles.d.ts +21 -0
- package/dist/types/sdk/sync.d.ts +7 -0
- package/dist/types/sdk/version.d.ts +2 -0
- package/dist/url-ABJ6S2Y6.js +2 -0
- package/package.json +72 -3
- package/sdk/cdn.js +13 -0
- package/sdk/core.js +961 -0
- package/sdk/events.js +99 -0
- package/sdk/index.js +137 -0
- package/sdk/license.js +28 -0
- package/sdk/models.js +177 -0
- package/sdk/scanner.js +1597 -0
- package/sdk/styles.js +1236 -0
- package/sdk/sync.js +12 -0
- package/sdk/version.js +7 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as I,b as p,c as T,l as O}from"./chunk-N7Q34F2P.js";import{a as C}from"./chunk-SH4P4XSZ.js";import{a as w}from"./chunk-36F637QU.js";import{a as d}from"./chunk-B7HT2X67.js";import{a as f}from"./chunk-E7JYVRJA.js";import{a as F,b as S}from"./chunk-G65H4ZTJ.js";var l=class{#e=null;#t=new Map;#s=new Map;constructor(e=w()){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.#i(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.#i(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.#i(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){return this.getDocSync(e)}async createDoc(e="Untitled Document",t=[]){let s=p(),r=this.#i(t),n={id:s,name:e||"Untitled Document",pages:r};return await this.#e.saveDoc(s,n),n}async saveDoc(e,t){if(!e)throw new Error("Cannot save document without an ID");let s=this.#i(t.pages);await this.#e.saveDoc(e,{id:e,name:t.name||"",pages:s})}async 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.#o(e),await this.#e.deleteDoc(e),t&&s>0){let n=setTimeout(async()=>{this.#t.delete(e)},s);this.#t.set(e,{doc:r,timerId:n})}return{id:e,name:r.name,undo:()=>this.undoDeleteDoc(e)}}}#o(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 n=r.pages.findIndex(i=>i.id===t);if(n===-1)throw new Error(`Page "${t}" not found in document "${e}"`);r.pages[n]={...r.pages[n],...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])),n=[];for(let i of t)r.has(i)&&(n.push(r.get(i)),r.delete(i));for(let i of r.values())n.push(i);s.pages=n,await this.saveDoc(e,s)}async deletePage(e,t,{soft:s=!0,timeoutMs:r=5e3}={}){let n=await this.getDoc(e);if(!n)throw new Error(`Document "${e}" not found`);let i=n.pages.findIndex(u=>u.id===t);if(i===-1)return;let[a]=n.pages.splice(i,1);await this.saveDoc(e,n);let h=`${e}:${t}`;if(this.#d(h),!s||r<=0){if(typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(u){console.warn("[DocRepository] Adapter deletePage error:",u)}return}let c=setTimeout(async()=>{if(this.#s.delete(h),typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(u){console.warn("[DocRepository] Adapter deletePage error:",u)}},r);return this.#s.set(h,{docId:e,pageId:t,page:a,index:i,timerId:c}),{docId:e,pageId:t,undo:()=>this.undoDeletePage(e,t)}}#d(e){if(this.#s.has(e)){let t=this.#s.get(e);clearTimeout(t.timerId),this.#s.delete(e)}}async undoDeletePage(e,t){let s=`${e}:${t}`,r=this.#s.get(s);if(!r)return null;clearTimeout(r.timerId),this.#s.delete(s);let n=await this.getDoc(e);if(!n)return null;let i=Math.min(r.index,n.pages.length);return n.pages.splice(i,0,r.page),await this.saveDoc(e,n),r.page}isSoftDeletedPage(e,t){return this.#s.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)t[s.id]={name:s.name,pages:JSON.stringify(s.pages)};return t}async importDocs(e){let t=0;for(let[s,r]of Object.entries(e||{})){await this.getDoc(s)||t++;let i=this.#i(r.pages);await this.saveDoc(s,{name:r.name||"",pages:i})}return t}#i(e){if(Array.isArray(e))return[...e];if(typeof e=="string")try{return JSON.parse(e)}catch{return[]}return[]}},R=new l;var B="2026-11-01T09:35:29.171Z",U="0.1.0";function x(o={}){let e=o&&o.crop&&typeof o.crop=="object"?{x:Math.max(0,Math.min(1,Number(o.crop.x)||0)),y:Math.max(0,Math.min(1,Number(o.crop.y)||0)),w:Math.max(0,Math.min(1,Number(o.crop.w)||1)),h:Math.max(0,Math.min(1,Number(o.crop.h)||1))}:null,t=0;if(o&&o.rotate!==void 0){let r=(Math.round(Number(o.rotate)/90)*90%360+360)%360;(r===90||r===180||r===270)&&(t=r)}let s=o&&o.filter==="bw"?"bw":"none";return{crop:e,rotate:t,filter:s}}function L(o){return o?!!(o.crop||o.rotate&&o.rotate!==0||o.filter&&o.filter!=="none"):!1}var m=class{constructor(e){this.id=e.id,this.src=e.src,this.originalSrc=e.originalSrc||e.src,this.edits=x(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}get isModified(){return L(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}}},E=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 m?t:new m(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}}},P=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 $={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 k(o,e,t={}){let s=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:!0,detail:t});return o&&typeof o.dispatchEvent=="function"&&o.dispatchEvent(s),s}var _=["crop","rotate","filter","ocr","export","sync"],v=["pdf","zip","png","jpg"],A=["eng"],b={};function pe(o,e){!o||!e||(b[o]=e,typeof globalThis<"u"&&(globalThis.__copio_services__=globalThis.__copio_services__||{},globalThis.__copio_services__[o]=e))}function g(o){return b[o]?b[o]:typeof globalThis<"u"&&globalThis.__copio_services__?.[o]?globalThis.__copio_services__[o]:null}function z(o){return o?o instanceof Set?new Set(o):Array.isArray(o)?new Set(o.map(e=>String(e).trim().toLowerCase()).filter(Boolean)):typeof o=="string"?new Set(o.split(/[\s,]+/).map(e=>e.trim().toLowerCase()).filter(Boolean)):new Set(_):new Set(_)}function y(o,e){return o?Array.isArray(o)?o.map(t=>String(t).trim().toLowerCase()).filter(Boolean):typeof o=="string"?o.split(/[\s,]+/).map(t=>t.trim().toLowerCase()).filter(Boolean):[...e]:[...e]}var N=class{#e=new Set(_);#t=[...v];#s=[...A];#o=0;#d="";#i=null;#r=null;#l={};#n=!0;#h=!0;#a=null;#c=new Map;#u=new Map;constructor(e={}){this.#i=e.storage||w(e),this.#r=e.repository||new l(this.#i),e.services&&(this.#l={...e.services}),e.imageProcessor?(this.#a=e.imageProcessor,this.#l.imageProcessor=e.imageProcessor):this.getService("imageProcessor")?this.#a=this.getService("imageProcessor"):typeof document<"u"?this.#a=new O:this.#a=new C,e.features!==void 0&&this.setFeatures(e.features),e.exportFormats!==void 0&&(this.#t=y(e.exportFormats,v)),e.ocrLanguages!==void 0&&(this.#s=y(e.ocrLanguages,A)),e.maxPages!==void 0&&(this.#o=Math.max(0,Number(e.maxPages)||0)),e.assetBase!==void 0&&S(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.#i.init()}setService(e,t){this.#l[e]=t}getService(e){return this.#l[e]||g(e)}hasFeature(e){return e?this.#e.has(String(e).trim().toLowerCase()):!1}get features(){return Array.from(this.#e)}setFeatures(e){this.#e=z(e),this.hasFeature("ocr")?(this.#n=!0,this.getService("ocr")instanceof d&&this.setService("ocr",g("ocr"))):(this.#n=!1,this.setService("ocr",new d))}enableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.add(t),t==="ocr"&&(this.#n=!0,this.getService("ocr")instanceof d&&this.setService("ocr",g("ocr")))}}disableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.delete(t),t==="ocr"&&(this.#n=!1,this.setService("ocr",new d))}}get ocr(){return this.#n&&this.hasFeature("ocr")}set ocr(e){this.#n=!!e,this.#n?(this.enableFeature("ocr"),this.getService("ocr")instanceof d&&this.setService("ocr",g("ocr"))):(this.disableFeature("ocr"),this.setService("ocr",new d))}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 f&&this.setService("pdf",g("pdf"))):(this.#t=this.#t.filter(t=>t!=="pdf"),this.setService("pdf",new f))}get exportFormats(){return[...this.#t]}set exportFormats(e){this.#t=y(e,v),this.#t.includes("pdf")?(this.#h=!0,this.getService("pdf")instanceof f&&this.setService("pdf",g("pdf"))):(this.#h=!1,this.setService("pdf",new f))}get ocrLanguages(){return[...this.#s]}set ocrLanguages(e){this.#s=y(e,A)}get maxPages(){return this.#o}set maxPages(e){this.#o=Math.max(0,Number(e)||0)}get assetBase(){return F()}set assetBase(e){S(e)}get licenseKey(){return this.#d}set licenseKey(e){this.#d=String(e||"")}get storage(){return this.#i}setStorage(e){e&&(this.#i=e,this.#r=new l(this.#i))}#g(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.#a}setImageProcessor(e){e&&(this.#a=e,this.setService("imageProcessor",e))}get docs(){return this.#r}async listDocuments(){return this.#r.listDocs()}async getDocument(e){return this.#r.getDoc(e)}async createDocument(e,t){return this.#r.createDoc(e,t)}async deleteDocument(e,t={}){return this.#r.deleteDoc(e,t)}async undoDeleteDocument(e){return this.#r.undoDeleteDoc(e)}async renameDocument(e,t){return this.#r.renameDoc(e,t)}async addPages(e,t){return this.#r.addPages(e,t)}async deletePage(e,t,s={}){return this.#g(e,{type:"delete",pageId:t}),this.#r.deletePage(e,t,s)}async undoDeletePage(e,t){return this.#r.undoDeletePage(e,t)}async updatePage(e,t,s){return this.#r.updatePage(e,t,s)}async reorderPages(e,t){let s=await this.getDocument(e),r=s?.pages?s.pages.map(n=>n.id):[];return this.#g(e,{type:"reorder",priorOrder:r,newOrder:[...t]}),this.#r.reorderPages(e,t)}async#p(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.#p(e),n=r?await this.getDocument(r):null;if(!n||!n.pages)throw new Error(`Document with ID "${r||e}" not found`);let i=n.pages.find(M=>M.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"}},h=i.src,c=x({...a,...s}),u=i.originalSrc||i.src,D=u;return this.#a&&(D=await this.#a.renderEdits(u,c)),await this.updatePage(r,t,{originalSrc:u,src:D,edits:c}),this.#g(r,{type:"edit",pageId:t,priorEdits:a,priorSrc:h,newEdits:c,newSrc:D}),{...i,originalSrc:u,src:D,edits:c}}async undo(e){let t=await this.#p(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.#r.reorderPages(t,r.priorOrder),{type:"reorder",priorOrder:r.priorOrder}):r}async redo(e){let t=await this.#p(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.#r.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 h=await a.renderPdfPagesToDataUrls(i);for(let c of h)r.push({id:p(),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 T(i),h=null;try{h=await I(i)}catch{}r.push({id:p(),src:a,originalSrc:a,edits:{crop:null,rotation:0,filter:"none"},type:"image",name:i.name||"Captured Image",orientation:h})}if(r.length===0)return[];let n=t;if(n)await this.getDocument(n)||await this.#r.saveDoc(n,{name:"Scanned Document",pages:[]});else{let i=await this.listDocuments();i.length>0?n=i[0].id:n=(await this.createDocument("Scanned Document",[])).id}if(this.#o>0){let i=(await this.getDocument(n))?.pages||[],a=Math.max(0,this.#o-i.length);if(a<=0)throw new Error(`Maximum page limit (${this.#o}) reached`);r.splice(a)}return await this.addPages(n,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#f(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.#f(e),n=this.getService("pdf")||this.getService("export");if(!n||typeof n.exportDocumentAsPdf!="function")throw new Error("Export service (PdfPort) is not registered. Import @copio/sdk or register an exportService.");return n.exportDocumentAsPdf(s,r,{download:!1,showProgress:!1,...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.#f(e),n=this.getService("export");if(!n||typeof n.exportDocumentAsImages!="function")throw new Error("Export service is not registered. Import @copio/sdk or register an exportService.");return n.exportDocumentAsImages(s,r,{download:!1,showProgress:!1,...t})}async runOcr(e,t=null,s={}){if(!this.#n||!this.hasFeature("ocr")){let c=new Error('Feature "ocr" is disabled');throw Object.assign(c,{code:"FEATURE_DISABLED"}),c}let{pages:r}=await this.#f(e),n=r;t&&(n=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.#s[0]||"eng",h=await i.recognizeDocumentPages(n,{lang:a,...s});return{text:h.combinedText,...h}}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.#r,e.onStateChange)}};export{l as a,R as b,B as c,U as d,x as e,L as f,m as g,E as h,P as i,$ as j,k,_ as l,v as m,A as n,pe as o,g as p,N as q};
|
|
2
|
+
//# sourceMappingURL=chunk-AU7NM25J.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as t}from"./chunk-YHLOPPXM.js";import{c as e}from"./chunk-K6YP7EET.js";import{a}from"./chunk-IUBYFIV6.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-B2EK6INF.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{d as y}from"./chunk-V2FP4EEH.js";import{c as b,k as x}from"./chunk-G65H4ZTJ.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}"}],c=null,m=null,d=null;function C(e){return e==="eng"?b("assets/tessdata"):"https://tessdata.projectnaptha.com/4.0.0_fast"}function k(e,u=0){let t=Math.round((u||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",u=null){if(d=u,c&&m===e)return c;if(c){try{await c.terminate()}catch(a){console.warn("Error terminating old OCR worker:",a)}c=null,m=null}let t=null;if(typeof window<"u"&&!window.Tesseract){d&&typeof d=="function"&&d({status:"downloading-engine",progress:.05,message:"Downloading OCR engine..."});try{t=await y.progress({message:"Downloading OCR engine...",total:100,done:0})}catch{}}let s,g;try{s=await x();let a=C(e);g=await s.createWorker(e,1,{workerPath:b("js/lib/tesseract-worker.min.js"),corePath:b("js/lib/tesseract-core"),langPath:a,logger:o=>{if(t&&o.status==="loading tesseract core"){let n=Math.round((o.progress||0)*100);t.update(n,100,`Downloading OCR engine... ${n>0?n+"%":""}`.trim())}if(d&&typeof d=="function"){let n=k(o.status,o.progress);d({status:o.status,progress:typeof o.progress=="number"?o.progress:0,message:n,raw:o})}}})}finally{t?.close()}return c=g,m=e,c}async function O(e,u={}){let{lang:t="eng",onProgress:i=null,abortSignal:s=null}=u;if(s?.aborted){let n=new Error("OCR operation cancelled by user");throw n.name="AbortError",n}i&&i({status:"starting",progress:.05,message:"Starting OCR engine..."});let g=await E(t,i);if(s?.aborted){let n=new Error("OCR operation cancelled by user");throw n.name="AbortError",n}i&&i({status:"recognizing text",progress:.2,message:"Recognizing text..."});let a=null,o=new Promise((n,l)=>{s&&(a=()=>{T();let r=new Error("OCR operation cancelled by user");r.name="AbortError",l(r)},s.addEventListener("abort",a,{once:!0}))});try{let l=(await Promise.race([g.recognize(e),o]))?.data||{},r=(l.text||"").trim(),p=Math.round(l.confidence||0);return i&&i({status:"done",progress:1,message:"Text recognition complete!"}),{text:r,confidence:p,words:l.words||[],lines:l.lines||[],paragraphs:l.paragraphs||[],hocr:l.hocr||""}}finally{s&&a&&s.removeEventListener("abort",a)}}async function v(e,u={}){let{lang:t="eng",onPageProgress:i=null,abortSignal:s=null}=u,g=(e||[]).filter(r=>r.type!=="markdown"&&r.src);if(g.length===0)return{pagesResults:[],combinedText:"",averageConfidence:0,empty:!0};let a=[],o=0;for(let r=0;r<g.length;r++){if(s?.aborted){let f=new Error("OCR operation cancelled by user");throw f.name="AbortError",f}let p=g[r],h=r+1,w=g.length,P=await O(p.src,{lang:t,abortSignal:s,onProgress:f=>{if(i){let R=(r+(f.progress||0))/w;i({pageIndex:r,pageNumber:h,totalPages:w,pageProgress:f.progress||0,overallProgress:R,message:`Page ${h} of ${w}: ${f.message}`})}}});a.push({pageId:p.id,pageIndex:r,pageNumber:h,...P}),o+=P.confidence}let n=a.map(r=>a.length>1?`## Page ${r.pageNumber}
|
|
2
|
+
|
|
3
|
+
${r.text}`:r.text).join(`
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`),l=Math.round(o/a.length);return{pagesResults:a,combinedText:n,averageConfidence:l}}async function T(){if(c){try{await c.terminate()}catch(e){console.warn("Error during OCR worker termination:",e)}c=null,m=null,d=null}}export{A as a,E as b,O as c,v as d,T as e};
|
|
8
|
+
//# sourceMappingURL=chunk-B5BEYYR2.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as r}from"./chunk-N4R55VRR.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-B7HT2X67.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as r}from"./chunk-V2FP4EEH.js";import{i as c,j as a}from"./chunk-G65H4ZTJ.js";var u="https://copio.metered.live/api/v1/turn/credentials?apiKey=d90f0b0b6bdf180ea68238f5c2185074ce37",f=[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.relay.metered.ca:80"}],p=5e3;async function h(){let i=new AbortController,e=setTimeout(()=>i.abort(),p);try{let t=await fetch(u,{signal:i.signal,cache:"no-store"});if(!t.ok)throw new Error(`HTTP ${t.status}`);let s=await t.json();if(!Array.isArray(s)||s.length===0)throw new Error("Empty ICE server list");return[{urls:"stun:stun.l.google.com:19302"},...s]}catch(t){return console.warn("[Sync] Failed to fetch TURN credentials, using STUN only:",t),f}finally{clearTimeout(e)}}var m=3e4,l=class{#i=null;#t=null;#r=null;#e=null;#c=0;#n=null;constructor(e,t){this.#t=e,this.#r=t}get state(){return this.#e}#s(e){this.#e=e,this.#r&&this.#r(this.#e)}#o(e){clearTimeout(this.#n),this.#e&&this.#s({...this.#e,step:"error",message:e})}async#a(){let e=++this.#c,[t,s]=await Promise.all([h(),c()]);return e!==this.#c?null:new s({config:{iceServers:t}})}#h(e){e.on("error",s=>this.#o(s.message));let t=e.peerConnection;t&&t.addEventListener("iceconnectionstatechange",()=>{console.log("[Sync] ICE state:",t.iceConnectionState),t.iceConnectionState==="failed"&&this.#o("Could not connect to the other device. Check both are online and try again.")})}#l(){clearTimeout(this.#n),this.#n=setTimeout(()=>{let e=this.#e?.step;e&&e!=="done"&&e!=="error"&&this.#o("Connection timed out. Try again.")},m)}#d(e){let t=()=>{clearTimeout(this.#n),this.#s({...this.#e,step:"syncing"}),this.#p(e)};e.open?t():e.on("open",t)}startHost(){if(this.#e?.mode!=="host"){if(!navigator.onLine){r.warning("An internet connection is needed to link devices.",{icon:"wifi-off",duration:4e3});return}this.#s({mode:"host",step:"init"}),this.#u().catch(e=>{this.#s({mode:"host",step:"error",message:e.message})})}}async#u(){let e=await this.#a();e&&(this.#i=e,e.on("error",t=>this.#o(t.message)),e.on("open",async t=>{let s=`${location.origin}${location.pathname}?peer=${t}`,o=(await a())(0,"M");o.addData(s),o.make(),this.#s({mode:"host",step:"waiting",qrSvg:o.createSvgTag(4,8),url:s,peerId:t})}),e.on("connection",t=>{this.#l(),this.#h(t),this.#d(t)}))}startJoiner(e){this.#e?.mode!=="joiner"&&(this.#s({mode:"joiner",step:"connecting"}),this.#l(),this.#f(e).catch(t=>{this.#s({mode:"joiner",step:"error",message:t.message})}))}async#f(e){let t=await this.#a();t&&(this.#i=t,t.on("error",s=>this.#o(s.message)),t.on("open",()=>{let s=t.connect(e);this.#h(s),this.#d(s)}))}#p(e){e.on("data",async t=>{let s;try{s=typeof t=="string"?JSON.parse(t):t}catch(o){console.error("Failed to parse sync data:",o);return}let n=0;typeof this.#t?.importDocs=="function"?n=await this.#t.importDocs(s):typeof this.#t?.transaction=="function"&&this.#t.transaction(()=>{for(let[o,d]of Object.entries(s||{}))this.#t.hasRow("docs",o)||n++,this.#t.setRow("docs",o,d)}),this.#s({...this.#e,step:"done",added:n}),r.success(`Sync complete \u2014 ${n} doc${n!==1?"s":""} added`)}),(async()=>{try{let t;typeof this.#t?.exportAll=="function"?t=await this.#t.exportAll():typeof this.#t?.getTable=="function"?t=this.#t.getTable("docs"):t={},e.send(JSON.stringify(t))}catch(t){console.error("Failed to send sync data:",t),this.#o(t.message)}})()}close(){this.#c++,clearTimeout(this.#n),this.#i?.destroy(),this.#i=null,this.#s(null)}};export{h as a,l as b};
|
|
2
|
+
//# sourceMappingURL=chunk-BKZEOOH4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-CWCS22CQ.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as n}from"./chunk-N4R55VRR.js";import{b as t,c as o,d as c,e as g}from"./chunk-B5BEYYR2.js";var m=class extends n{async recognizeImageText(e,r={}){return o(e,r)}async recognizeDocumentPages(e,r={}){return c(e,r)}async getOcrWorker(e="eng",r=null){return t(e,r)}async terminateOcrWorker(){return g()}};export{m as a};
|
|
2
|
+
//# sourceMappingURL=chunk-DGGK5KEX.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as r}from"./chunk-YHLOPPXM.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-E7JYVRJA.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=".";function l(){return c}function m(n){typeof n=="string"&&(c=n.replace(/\/+$/,"")||".")}function w(n){if(!n)return"";if(/^(https?:|\/\/|data:|blob:)/i.test(n))return n;let e=n.replace(/^\/+/,""),t=c;return!t||t==="."?e:`${t}/${e}`}var s=new Map;function r(n,e){let t=e();if(t)return Promise.resolve(t);if(s.has(n))return s.get(n);let p=new Promise((i,d)=>{if(typeof document>"u"){d(new Error(`Cannot load script "${n}" in an environment without DOM document.`));return}let a=w(n),u=document.querySelector(`script[src="${a}"], script[src="${n}"]`);if(u){if(e()){i(e());return}u.addEventListener("load",()=>i(e()),{once:!0}),u.addEventListener("error",()=>d(new Error(`Failed to load "${n}": Network error`)),{once:!0});return}let o=document.createElement("script");o.src=a,o.async=!0,o.onload=()=>{let f=e();i(f)},o.onerror=()=>{s.delete(n),o.remove(),d(new Error(`Failed to load script "${n}": Network error`))},document.head.appendChild(o)});return s.set(n,p),p}async function j(){return r("js/lib/cropper.js",()=>window.Cropper)}async function x(){return r("js/lib/pdfkit.js",()=>window.PDFDocument)}async function y(){return r("js/lib/jszip.min.js",()=>window.JSZip)}async function P(){return r("js/lib/marked.min.js",()=>window.marked)}async function $(){return r("js/lib/peerjs.min.js",()=>window.Peer)}async function g(){return r("js/lib/qrcode.js",()=>window.qrcode)}async function E(){return r("js/lib/tesseract.min.js",()=>window.Tesseract)}export{l as a,m as b,w as c,r as d,j as e,x as f,y as g,P as h,$ as i,g as j,E as k};
|
|
2
|
+
//# sourceMappingURL=chunk-G65H4ZTJ.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
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-HN3336JN.js.map
|