@copio/sdk 0.1.2 → 0.1.4

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.
Files changed (105) hide show
  1. package/LICENSE +661 -0
  2. package/LICENSE-COMMERCIAL.md +43 -0
  3. package/README.md +155 -147
  4. package/THIRD_PARTY_NOTICES.md +416 -0
  5. package/dist/adapters/image/canvas2d-adapter.js +1 -1
  6. package/dist/adapters/image/index.js +1 -1
  7. package/dist/adapters/image/null-image-processor-adapter.js +1 -1
  8. package/dist/adapters/index.js +1 -1
  9. package/dist/adapters/indexeddb-adapter.js +1 -1
  10. package/dist/adapters/memory-adapter.js +1 -1
  11. package/dist/adapters/ocr/index.js +1 -1
  12. package/dist/adapters/ocr/null-ocr-adapter.js +1 -1
  13. package/dist/adapters/ocr/tesseract-wasm-adapter.js +1 -1
  14. package/dist/adapters/pdf/index.js +1 -1
  15. package/dist/adapters/pdf/null-pdf-adapter.js +1 -1
  16. package/dist/adapters/pdf/pdfkit-adapter.js +1 -1
  17. package/dist/adapters/storage/index.js +1 -1
  18. package/dist/adapters/storage/indexeddb-adapter.js +1 -1
  19. package/dist/adapters/storage/memory-adapter.js +1 -1
  20. package/dist/adapters/sync/index.js +1 -1
  21. package/dist/adapters/sync/null-sync-adapter.js +1 -1
  22. package/dist/adapters/sync/peerjs-adapter.js +1 -1
  23. package/dist/cdn.js +56 -1276
  24. package/dist/{chunk-A5G52Q2W.js → chunk-2AB5L3Y2.js} +2 -2
  25. package/dist/{chunk-DGGK5KEX.js → chunk-4ICUYKSR.js} +2 -2
  26. package/dist/{chunk-E7JYVRJA.js → chunk-5OTO5WFV.js} +2 -2
  27. package/dist/{chunk-N4R55VRR.js → chunk-6DSLE3AY.js} +1 -1
  28. package/dist/chunk-DIU5BGU5.js +2 -0
  29. package/dist/chunk-FAVTIE3M.js +8 -0
  30. package/dist/chunk-FFRDPFTS.js +1395 -0
  31. package/dist/chunk-FQRADJY6.js +2 -0
  32. package/dist/{chunk-N7Q34F2P.js → chunk-G5EUMLYT.js} +4 -4
  33. package/dist/{chunk-IUBYFIV6.js → chunk-GGERQ3CJ.js} +11 -11
  34. package/dist/chunk-IBF5HCYT.js +2 -0
  35. package/dist/{chunk-PVNRK4OH.js → chunk-J7HWZNIP.js} +2 -2
  36. package/dist/chunk-K4NR6OAC.js +2 -0
  37. package/dist/{chunk-SH4P4XSZ.js → chunk-KH5JE65X.js} +2 -2
  38. package/dist/chunk-L4OVZN23.js +2 -0
  39. package/dist/chunk-MEE2NNYB.js +2 -0
  40. package/dist/{chunk-KIMVF5UG.js → chunk-NEEWG3OP.js} +1 -1
  41. package/dist/chunk-NQW6FFN7.js +50 -0
  42. package/dist/{chunk-YHLOPPXM.js → chunk-O6FQFVKY.js} +1 -1
  43. package/dist/{chunk-B7HT2X67.js → chunk-U3V3VZGO.js} +2 -2
  44. package/dist/{chunk-HN3336JN.js → chunk-ULTSZWZO.js} +1 -1
  45. package/dist/{chunk-BKZEOOH4.js → chunk-WETG2JD7.js} +2 -2
  46. package/dist/{chunk-V2FP4EEH.js → chunk-YNY65JUJ.js} +1 -1
  47. package/dist/chunk-ZT72PD2C.js +2 -0
  48. package/dist/core.js +1 -1
  49. package/dist/custom-elements.json +464 -1812
  50. package/dist/export.js +1 -1
  51. package/dist/index.js +11 -19
  52. package/dist/ocr.js +1 -1
  53. package/dist/scanner.js +24 -1257
  54. package/dist/sync.js +1 -1
  55. package/dist/types/js/adapters/storage/blob-store.d.ts +48 -0
  56. package/dist/types/js/adapters/storage/index.d.ts +11 -4
  57. package/dist/types/js/adapters/storage/indexeddb-adapter.d.ts +46 -9
  58. package/dist/types/js/adapters/storage/memory-adapter.d.ts +7 -0
  59. package/dist/types/js/adapters/storage/opfs-adapter.d.ts +160 -0
  60. package/dist/types/js/adapters/storage/storage-port.d.ts +7 -0
  61. package/dist/types/js/routes/ocr/copio-doc-ocr-dialog.d.ts +0 -2
  62. package/dist/types/js/services/doc-repository.d.ts +1 -0
  63. package/dist/types/js/services/export-utils.d.ts +8 -12
  64. package/dist/types/js/services/ocr-service.d.ts +2 -1
  65. package/dist/types/js/utils/module-loader.d.ts +0 -6
  66. package/dist/types/js/utils/utils.d.ts +5 -3
  67. package/dist/types/sdk/core.d.ts +13 -2
  68. package/dist/types/sdk/elements.d.ts +0 -12
  69. package/dist/types/sdk/events.d.ts +4 -4
  70. package/dist/types/sdk/index.d.ts +3 -9
  71. package/dist/types/sdk/models.d.ts +66 -0
  72. package/dist/types/sdk/scanner.d.ts +2 -7
  73. package/dist/types/sdk/styles.d.ts +1 -1
  74. package/dist/types/sdk/version.d.ts +1 -1
  75. package/package.json +4 -3
  76. package/sdk/cdn.js +1 -0
  77. package/sdk/core.js +60 -0
  78. package/sdk/events.js +3 -2
  79. package/sdk/index.js +4 -9
  80. package/sdk/license.js +1 -0
  81. package/sdk/models.js +79 -3
  82. package/sdk/scanner.js +50 -19
  83. package/sdk/styles.js +12 -5
  84. package/sdk/sync.js +1 -0
  85. package/sdk/version.js +2 -1
  86. package/dist/chunk-36F637QU.js +0 -2
  87. package/dist/chunk-4JPEWIT4.js +0 -2
  88. package/dist/chunk-B2EK6INF.js +0 -2
  89. package/dist/chunk-B5BEYYR2.js +0 -8
  90. package/dist/chunk-G65H4ZTJ.js +0 -2
  91. package/dist/chunk-HS6GDZIS.js +0 -2
  92. package/dist/chunk-IZOWC74B.js +0 -2601
  93. package/dist/chunk-K6YP7EET.js +0 -8
  94. package/dist/chunk-LI54F6PA.js +0 -2
  95. package/dist/chunk-OI4WCW7E.js +0 -2
  96. package/dist/chunk-UCV3MQ6I.js +0 -33
  97. package/dist/chunk-XEN5VKAV.js +0 -19
  98. package/dist/types/js/components/copio-header.d.ts +0 -19
  99. package/dist/types/js/components/copio-loader.d.ts +0 -6
  100. package/dist/types/js/core/store.d.ts +0 -2
  101. package/dist/types/js/routes/add-edit/copio-add-edit-dialog.d.ts +0 -9
  102. package/dist/types/js/routes/doc/copio-carousel.d.ts +0 -43
  103. package/dist/types/js/routes/doc/copio-images.d.ts +0 -37
  104. package/dist/types/js/routes/home/copio-row.d.ts +0 -49
  105. package/dist/types/js/styles/cropper-styles.d.ts +0 -5
@@ -0,0 +1,2 @@
1
+ import{a as F,b as m,c as O,j as R,k as L}from"./chunk-G5EUMLYT.js";import{a as N}from"./chunk-KH5JE65X.js";import{c as D}from"./chunk-K4NR6OAC.js";import{c as P}from"./chunk-L4OVZN23.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-06T14:30:44.258Z",z="0.1.4";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-IBF5HCYT.js.map
@@ -1,2 +1,2 @@
1
- import{a as s}from"./chunk-KIMVF5UG.js";import{b as o}from"./chunk-BKZEOOH4.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-PVNRK4OH.js.map
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
@@ -0,0 +1,2 @@
1
+ import{a as L,b as S,d as m}from"./chunk-L4OVZN23.js";import{a as U}from"./chunk-FQRADJY6.js";import{a as D}from"./chunk-DIU5BGU5.js";async function $(){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 j(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 O(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;#r=null;#i=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.#i=t.store:(this.#i=L(),this.#i.setTable("docs",{})),this.#u=t.persister||j(this.#i,()=>this.#g,"store.json")}get store(){return this.#t?this.#e?.store:this.#i}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.#r&&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.#r=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 $())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.#r)return 0;let t=0,r=this.#i.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 O(this.#r);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 O(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.#r.removeEntry(a,{recursive:!0}),t++}catch{}return t}listDocsSync(){if(this.#t)return this.#e?.listDocsSync();let t=this.#i.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.#i.hasRow("docs",t))return null;let r=this.#i.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.#i.hasRow("docs",t))return null;let r=this.#i.getRow("docs",t),i=this.#f(r.pages),s=null;if(this.#r)try{s=await this.#r.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),k=typeof e.src=="string"&&e.src.startsWith("data:")||e.src instanceof Blob||e.src&&u&&e.src!==u;if(c)if(h.blob=c,k||!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.#i.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.#r)try{o=await this.#r.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.#i.delRow("docs",t),this.#n.delete(t),this.revokeDocUrls(t),await this.#o(),this.#r)try{await this.#r.removeEntry(t,{recursive:!0})}catch{}}async renameDoc(t,r){if(this.#t)return this.#e?.renameDoc(t,r);if(!this.#i.hasRow("docs",t))throw new Error(`Document "${t}" not found`);this.#i.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.#r)try{let g=await(await(await this.#r.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.#r)try{return await(await(await this.#r.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.#i.setRow("docs",t,{name:i.name||"",pages:JSON.stringify(i.pages)}),this.#r){try{await(await this.#r.getDirectoryHandle(t)).removeEntry(`${r}.bin`)}catch{}try{await(await this.#r.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.#i.addTableListener("docs",t);return()=>{this.#i.delListener(r)}}#f(t){if(Array.isArray(t))return t;if(typeof t=="string")try{return JSON.parse(t)}catch{return[]}return[]}};function M(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{$ as a,v as b,M as c};
2
+ //# sourceMappingURL=chunk-K4NR6OAC.js.map
@@ -1,2 +1,2 @@
1
- import{a as t}from"./chunk-HN3336JN.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-SH4P4XSZ.js.map
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{a as xr}from"./chunk-DIU5BGU5.js";var Ft=t=>typeof t;var Er=Ft(""),gn=Ft(!0),Hr=Ft(0),fn=Ft(Ft),Fe="type",Qt="default",vs="Listener",Mr="Result",Cs="add",zt="Has",me="Ids",Jt="Table",jr=Jt+"s",bn=Jt+me,ae="Row",Ar=ae+"Count",Or=ae+me,wn="Sorted"+ae+me,Se="Cell",ze=Se+me,_e="Value",Dr=_e+"s",pn=_e+me,at=t=>""+t;var yn=(t,e="",r)=>t.split(e,r),Ts=globalThis,ts=Math,ps=ts.max,ys=ts.min,Sn=ts.floor,Wr=isFinite,B=t=>t==null,it=(t,e,r)=>B(t)?r?.():e(t),Nr=t=>t==Er||t==gn,Ln=t=>Ft(t)==Er,jt=t=>Ft(t)==fn,ie=t=>Array.isArray(t),Is=(t,e,r)=>t.slice(e,r),xt=t=>t.length,Jr=()=>{};var Ss=async(t,e,r)=>{try{return await t()}catch(o){e?.(o)}},ks=(t,e)=>t.includes(e),Ge=(t,e)=>t.every(e),Fr=(t,e)=>xt(t)===xt(e)&&Ge(t,((r,o)=>e[o]===r)),Vr=(t,e)=>Ge(t,((r,o)=>o==0||e(t[o-1],r)<=0)),xs=(t,e)=>t.sort(e),Tt=(t,e)=>t.forEach(e),Yt=(t,e)=>t.map(e),$r=t=>Kr(t,((e,r)=>e+r),0),Le=t=>xt(t)==0,Kr=(t,e,r)=>t.reduce(e,r),Ct=(t,...e)=>t.push(...e),Ur=t=>t.pop(),qr=t=>t.shift(),ne=t=>{let e=Ft(t);return Nr(e)||e==Hr&&Wr(t)?e:void 0};var Ye=(t,e,r,o,l)=>B(l)?t.delCell(e,r,o,!0):t.setCell(e,r,o,l),Ms=(t,e,r)=>B(r)?t.delValue(e):t.setValue(e,r),$s=t=>e=>Kr(le(e),((r,o)=>r+t(o)),0),ce=t=>t?.size??0,Xt=$s(ce),Bt=$s(Xt),Ls=$s(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,Pr=t=>Kt.getPrototypeOf(t),Rn=Kt.isFrozen,Qr=Kt.entries,Xe=t=>!B(t)&&it(Pr(t),(e=>e==Kt.prototype||B(Pr(e))),(()=>!0)),mn=Kt.keys,de=Kt.freeze,vn=(t=[])=>Kt.fromEntries(t),ye=(t,e)=>e in t,zr=(t,e)=>(delete t[e],t),Cn=(t,e)=>Tt(Qr(t),(([r,o])=>e(o,r))),Pt=(t,e)=>vn(((r,o)=>Yt(Qr(r),(([l,c])=>o(c,l))))(t,((r,o)=>[o,e(r,o)]))),Dt=t=>Xe(t)&&(e=>xt(mn(e)))(t)==0;var Wt=(t,e,r,o=0)=>B(t)||!Xe(t)||!o&&Dt(t)||Rn(t)?(r?.(),!1):(Cn(t,((l,c)=>{e(l,c)||zr(t,c)})),!!o||!Dt(t)),w=t=>new Map(t),Gt=t=>[...t?.keys()??[]],g=(t,e)=>t?.get(e),wt=(t,e)=>V(t,((r,o)=>e(o,r))),k=(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)):k(t,e,r()),g(t,e)),_t=(t,e,r,o=k)=>(Pt(e,((l,c)=>r(t,c,l))),wt(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},js=(t,e,r)=>vt(t,(o=>vt(o,e,r)),$,Dt),Ke=(t,e,r)=>vt(t,(o=>js(o,e,r)),$,Dt),Nt=(t,e)=>{let r=w();return V(t,((o,l)=>r.set(l,e?.(o)??o))),r},Ds=t=>Nt(t,Nt),Rs=t=>Nt(t,Ds),Re=(t,e,r,o,l=0)=>it((r?ct:g)(t,e[l],l>xt(e)-2?r:w),(c=>{if(l>xt(e)-2)return o?.(c)&&k(t,e[l]),c;let u=Re(c,e,r,o,l+1);return $(c)&&k(t,e[l]),u})),pt=t=>new Set(ie(t)||B(t)?t:[t]),ut=(t,e)=>t?.add(e),es=(t,e,r,o,l)=>{let c=t.hasRow,u=w(),i=w(),p=w(),S=w(),m=w(),b=w(),E=(L,x,..._)=>{let I=ct(b,L,pt);return Tt(_,(A=>ut(I,A)&&x&&t.callListener(A))),_},T=(L,...x)=>it(g(b,L),(_=>{Tt(Le(x)?le(_):x,(I=>{t.delListener(I),Vt(_,I)})),$(_)&&k(b,L)})),F=(L,x)=>{k(u,L,x),dt(i,L)||(k(i,L,e()),k(S,L,w()),k(m,L,w()),l(p))},Z=L=>{k(u,L),k(i,L),k(S,L),k(m,L),T(L),l(p)};return[()=>t,()=>Gt(u),L=>wt(i,L),L=>dt(i,L),L=>g(u,L),L=>g(i,L),(L,x)=>k(i,L,x),F,(L,x,_,I,A)=>{F(L,x);let st=w(),y=w(),h=g(S,L),C=g(m,L),W=P=>{let q=lt=>t.getCell(x,P,lt),nt=g(h,P),ot=c(x,P)?r(I(q,P)):void 0;if(nt===ot||ie(nt)&&ie(ot)&&Fr(nt,ot)||k(st,P,[nt,ot]),!B(A)){let lt=g(C,P),N=c(x,P)?A(q,P):void 0;lt!=N&&k(y,P,N)}},K=P=>{_((()=>{V(st,(([,q],nt)=>k(h,nt,q))),V(y,((q,nt)=>k(C,nt,q)))}),st,y,h,C,P),oe(st),oe(y)};wt(h,W),t.hasTable(x)&&Tt(t.getRowIds(x),(P=>{dt(h,P)||W(P)})),K(!0),T(L),E(L,0,t.addRowListener(x,null,((P,q,nt)=>W(nt))),t.addTableListener(x,(()=>K())))},Z,L=>o(L,p),()=>wt(b,Z),E,T]},Ze=(t,e)=>Ln(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}},Tn=/^\d+$/,_r=()=>{let t=[],e=0;return[r=>(r?qr(t):null)??""+e++,r=>{Tn.test(r)&&xt(t)<1e3&&Ct(t,r)}]},Ce=t=>{let e,[r,o]=_r(),l=w();return[(c,u,i,p=[],S=()=>[])=>{e??=t();let m=r(1);return k(l,m,[c,u,i,p,S]),ut(Re(u,i??[""],pt),m),m},(c,u,...i)=>Tt(((p,S=[""])=>{let m=[],b=(E,T)=>T==xt(S)?Ct(m,E):S[T]===null?V(E,(F=>b(F,T+1))):Tt([S[T],null],(F=>b(g(E,F),T+1)));return b(p,0),m})(c,u),(p=>V(p,(S=>g(l,S)[0](e,...u??[],...i))))),c=>it(g(l,c),(([,u,i])=>(Re(u,i??[""],void 0,(p=>(Vt(p,c),$(p)?1:0))),k(l,c),o(c),i))),c=>it(g(l,c),(([u,,i=[],p,S])=>{let m=(...b)=>{let E=xt(b);E==xt(i)?u(e,...b,...S(b)):B(i[E])?Tt(p[E]?.(...b)??[],(T=>m(...b,T))):m(...b,i[E])};m()}))]},to=ve((t=>{let e,r,o,l=100,c=w(),u=w(),i=1,p=w(),S=w(),[m,b,E]=Ce((()=>N)),T=w(),F=w(),Z=[],L=[],x=(R,D)=>{i=0,t.transaction((()=>{let[et,G]=g(T,D);V(et,((j,H)=>V(j,((J,Y)=>V(J,((O,Q)=>Ye(t,H,Y,Q,O[R]))))))),V(G,((j,H)=>Ms(t,H,j[R])))})),i=1},_=R=>{k(T,R),k(F,R),b(S,[R])},I=(R,D)=>Tt(((et,G)=>et.splice(0,G))(R,D??xt(R)),_),A=()=>I(Z,xt(Z)-l),st=()=>it(e,(()=>{Ct(Z,e),A(),I(L),e=void 0,o=1})),y=()=>{e=Ur(Z),o=1},h,C,W=(R="")=>(B(e)&&(e=""+r++,k(T,e,[c,u]),ot(e,R),c=w(),u=w(),o=1),e),K=()=>{Le(Z)||(((R,...D)=>{R.unshift(...D)})(L,W()),x(0,e),e=Ur(Z),o=1)},P=()=>{Le(L)||(Ct(Z,e),e=qr(L),x(1,e),o=1)},q=()=>{o&&(b(p),o=0)},nt=R=>{let D=W(R);return q(),D},ot=(R,D)=>(lt(R)&&g(F,R)!==D&&(k(F,R,D),b(S,[R])),N),lt=R=>dt(T,R),N={setSize:R=>(l=R,A(),N),addCheckpoint:nt,setCheckpoint:ot,getStore:()=>t,getCheckpointIds:()=>[[...Z],e,[...L]],forEachCheckpoint:R=>wt(F,R),hasCheckpoint:lt,getCheckpoint:R=>g(F,R),goBackward:()=>(K(),q(),N),goForward:()=>(P(),q(),N),goTo:R=>{let D=ks(Z,R)?K:ks(L,R)?P:null;for(;!B(D)&&R!=e;)D();return q(),N},addCheckpointIdsListener:R=>m(R,p),addCheckpointListener:(R,D)=>m(D,S,[R]),delListener:R=>(E(R),N),clear:()=>(I(Z),I(L),B(e)||_(e),e=void 0,r=0,nt(),N),clearForward:()=>(Le(L)||(I(L),b(p)),N),destroy:()=>{t.delListener(h),t.delListener(C)},getListenerStats:()=>({checkpointIds:Xt(p),checkpoint:Xt(S)}),_registerListeners:()=>{h=t.addCellListener(null,null,null,((R,D,et,G,j,H)=>{if(i){st();let J=ct(c,D,w),Y=ct(J,et,w),O=ct(Y,G,(()=>[H,void 0]));O[1]=j,O[0]===j&&$(k(Y,G))&&$(k(J,et))&&$(k(c,D))&&y(),q()}})),C=t.addValueListener(null,((R,D,et,G)=>{if(i){st();let j=ct(u,D,(()=>[G,void 0]));j[1]=et,j[0]===et&&$(k(u,D))&&y(),q()}}))}};return de(N.clear())}),(t=>t._registerListeners())),In=yn("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),eo=w(Yt(In,((t,e)=>[t,e])));var so=Ts.crypto?t=>Ts.crypto.getRandomValues(t):t=>Yt(t,(()=>Sn(256*ts.random())));var kn=JSON.stringify,ms=JSON.parse,re=t=>kn(t,((e,r)=>{return o=Map,r instanceof o?Kt.fromEntries([...r]):r;var o})),ro=new Ts.TextEncoder;var no=2**36,oo=2**30,ao=2**24,io=2**18;var Gr=(t,e)=>(t??0)<(e??0)?-1:1,lo=ve((t=>{let e=w(),r=w(),[o,l,c]=Ce((()=>_)),[u,i,p,S,m,b,E,,T,F,Z,L]=es(t,w,(I=>B(I)?"":ie(I)?Yt(I,at):at(I)),o,l),x=(I,A,st)=>{let y=m(I);V(st,((h,C)=>A(C,(W=>V(h,(K=>W(K,(P=>t.forEachCell(y,K,P)))))))))},_={setIndexDefinition:(I,A,st,y,h,C=Gr)=>{let W=B(h)?void 0:([K],[P])=>h(K,P);return T(I,A,((K,P,q,nt,ot,lt)=>{let N=0,R=pt(),D=pt(),et=b(I);if(V(P,(([G,j],H)=>{let J=pt(G),Y=pt(j);V(J,(O=>Vt(Y,O)?Vt(J,O):0)),V(J,(O=>{ut(R,O),it(g(et,O),(Q=>{Vt(Q,H),$(Q)&&(k(et,O),N=1)}))})),V(Y,(O=>{ut(R,O),dt(et,O)||(k(et,O,pt()),N=1),ut(g(et,O),H),B(y)||ut(D,O)}))})),K(),$(ot)||(lt?wt(et,(G=>ut(D,G))):wt(q,(G=>it(g(nt,G),(j=>Tt(ie(j)?j:[j],(H=>ut(D,H))))))),V(D,(G=>{let j=(J,Y)=>C(g(ot,J),g(ot,Y),G),H=[...g(et,G)];Vr(H,j)||(k(et,G,pt(xs(H,j))),ut(R,G))}))),(N||lt)&&!B(W)){let G=[...et];Vr(G,W)||(E(I,w(xs(G,W))),N=1)}N&&l(e,[I]),V(R,(G=>l(r,[I,G])))}),Ze(st),it(y,Ze)),_},delIndexDefinition:I=>(F(I),_),getStore:u,getIndexIds:i,forEachIndex:I=>p(((A,st)=>I(A,(y=>x(A,y,st))))),forEachSlice:(I,A)=>x(I,A,b(I)),hasIndex:S,hasSlice:(I,A)=>dt(b(I),A),getTableId:m,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:L,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=()=>[w(),w()],Br=t=>[...t],Qe=([t,e])=>t===e,pe=(t,e,r)=>k(t,e,g(t,e)==-r?void 0:r),Us=()=>{let t,e,r=!1,o=!1,l=0,c=[],u=w(),i=w(),p=w(),S=w(),m=w(),b=w(),E=w(),T=w(),F=w(),Z=w(),L=w(),x=w(),_=w(),I=w(),A=pt(),st=w(),y=w(),h=w(),C=w(),W=bt(),K=bt(),P=bt(),q=bt(),nt=bt(),ot=bt(),lt=bt(),N=bt(),R=bt(),D=bt(),et=bt(),G=bt(),j=bt(),H=bt(),J=bt(),Y=bt(),O=bt(),Q=bt(),M=bt(),rt=bt(),ht=bt(),mt=bt(),St=w(),Lt=bt(),[yt,tt,It,Et]=Ce((()=>Rt)),Ht=s=>{if(!Wt(s,((a,d)=>ks([Fe,Qt],d))))return!1;let n=s[Fe];return!(!Nr(n)&&n!=Hr)&&(ne(s[Qt])!=n&&zr(s,Qt),!0)},cs=ie,ke=(s,n)=>(!t||dt(L,n)||At(n))&&Wt(s,((a,d)=>qt(n,d,a)),(()=>At(n))),qt=(s,n,a,d)=>Wt(d?a:Ns(a,s,n),((f,v)=>it(xe(s,n,v,f),(U=>(a[v]=U,!0)),(()=>!1))),(()=>At(s,n))),xe=(s,n,a,d)=>t?it(g(g(L,s),a),(f=>ne(d)!=f[Fe]?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:hn(s),((a,d)=>it(Ws(d,a),(f=>(s[d]=f,!0)),(()=>!1))),(()=>fe())),Ws=(s,n)=>e?it(g(_,s),(a=>ne(n)!=a[Fe]?fe(s,n,a[Qt]):n),(()=>fe(s,n))):B(ne(n))?fe(s,n):n,Ns=(s,n,a)=>(it(g(x,n),(([d,f])=>{V(d,((v,U)=>{ye(s,U)||(s[U]=v)})),V(f,(v=>{ye(s,v)||At(n,a,v)}))})),s),hn=s=>(e&&(V(I,((n,a)=>{ye(s,a)||(s[a]=n)})),V(A,(n=>{ye(s,n)||fe(n)}))),s),Js=s=>_t(L,s,((n,a,d)=>{let f=w(),v=pt();_t(ct(L,a,w),d,((U,z,X)=>{k(U,z,X),it(X[Qt],(Ut=>k(f,z,Ut)),(()=>ut(v,z)))})),k(x,a,[f,v])}),((n,a)=>{k(L,a),k(x,a)})),Fs=s=>_t(_,s,((n,a,d)=>{k(_,a,d),it(d[Qt],(f=>k(I,a,f)),(()=>ut(A,a)))}),((n,a)=>{k(_,a),k(I,a),Vt(A,a)})),Ks=s=>Dt(s)?Oe():He(s),qs=s=>_t(h,s,((n,a,d)=>Me(a,d)),((n,a)=>Gs(a))),Me=(s,n)=>_t(ct(h,s,(()=>(tr(s,1),k(st,s,_r()),k(y,s,w()),w()))),n,((a,d,f)=>ge(s,a,d,f)),((a,d)=>Ys(s,a,d))),ge=(s,n,a,d,f)=>_t(ct(n,a,(()=>(er(s,a,1),w()))),d,((v,U,z)=>ds(s,a,v,U,z)),((v,U)=>Xs(s,n,a,v,U,f))),ds=(s,n,a,d,f)=>{dt(a,d)||sr(s,n,d,1);let v=g(a,d);f!==v&&(rr(s,n,d,v,f),k(a,d,f))},Qs=(s,n,a,d,f)=>it(g(n,a),(v=>ds(s,a,v,d,f)),(()=>ge(s,n,a,Ns({[d]:f},s,a)))),zs=s=>Dt(s)?We():Ae(s),_s=s=>_t(C,s,((n,a,d)=>je(a,d)),((n,a)=>Zs(a))),je=(s,n)=>{dt(C,s)||nr(s,1);let a=g(C,s);n!==a&&(or(s,a,n),k(C,s,n))},De=s=>g(h,s)??Me(s,{}),Gs=s=>Me(s,{}),Ys=(s,n,a)=>{let[,d]=g(st,s);d(a),ge(s,n,a,{},!0)},Xs=(s,n,a,d,f,v)=>{let U=g(g(x,s)?.[0],f);if(!B(U)&&!v)return ds(s,a,d,f,U);let z=X=>{rr(s,a,X,g(d,X)),sr(s,a,X,-1),k(d,X)};B(U)?z(f):wt(d,z),$(d)&&(er(s,a,-1),$(k(n,a))&&(tr(s,-1),k(h,s),k(st,s),k(y,s)))},Zs=s=>{let n=g(I,s);if(!B(n))return je(s,n);or(s,g(C,s)),nr(s,-1),k(C,s)},tr=(s,n)=>pe(u,s,n),er=(s,n,a)=>pe(ct(S,s,w),n,a)&&k(p,s,ct(p,s,(()=>0))+a),sr=(s,n,a,d)=>{let f=g(y,s),v=g(f,a)??0;(v==0&&d==1||v==1&&d==-1)&&pe(ct(i,s,w),a,d),k(f,a,v!=-d?v+d:null),pe(ct(ct(m,s,w),n,w),a,d)},rr=(s,n,a,d,f)=>{ct(ct(ct(b,s,w),n,w),a,(()=>[d,0]))[1]=f,c[3]?.(s,n,a,f)},nr=(s,n)=>pe(E,s,n),or=(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,w),n,w),a,(()=>[])),d),f),fe=(s,n,a)=>(Ct(ct(Z,s,(()=>[])),n),a),Ve=(s,n,a)=>it(g(g(g(b,s),n),a),(([d,f])=>[!0,d,f]),(()=>[!1,...qe(Ue(s,n,a))])),ar=s=>it(g(T,s),(([n,a])=>[!0,n,a]),(()=>[!1,...qe(Pe(s))])),ir=s=>$(F)||$(Y[s])?0:V(s?Rs(F):F,((n,a)=>V(n,((d,f)=>V(d,((v,U)=>tt(Y[s],[a,f,U],v))))))),lr=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))),wt(s,((f,v)=>tt(a,[...d??[],f],v==1))),1},cr=s=>{let n=Be();n!=r&&tt(W[s],void 0,n);let a=$(D[s]),d=$(j[s])&&$(H[s])&&$(R[s])&&$(et[s])&&$(ot[s])&&$(lt[s])&&$(N[s])&&a&&$(P[s])&&$(q[s]),f=$(J[s])&&$(G[s])&&$(nt[s])&&$(K[s]);if(!d||!f){let v=s?[Nt(u),Ds(i),Nt(p),Ds(S),Rs(m),Rs(b)]:[u,i,p,S,m,b];if(!d){be(v[0],P[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],gr(X))}));let U=pt();V(v[3],((z,X)=>{be(z,R[s],et[s],[X])&&!a&&(tt(D[s],[X,null]),ut(U,X))})),a||V(v[5],((z,X)=>{if(!dt(U,X)){let Ut=pt();V(z,(Ot=>V(Ot,(([Ne,Je],we)=>Je!==Ne?ut(Ut,we):Vt(Ot,we))))),V(Ut,(Ot=>tt(D[s],[X,Ot])))}})),V(v[4],((z,X)=>V(z,((Ut,Ot)=>be(Ut,j[s],H[s],[X,Ot])))))}if(!f){let U;V(v[5],((z,X)=>{let Ut;V(z,((Ot,Ne)=>{let Je;V(Ot,(([we,kr],un)=>{kr!==we&&(tt(J[s],[X,Ne,un],kr,we,Ve),U=Ut=Je=1)})),Je&&tt(G[s],[X,Ne],Ve)})),Ut&&tt(nt[s],[X],Ve)})),U&&tt(K[s],void 0,Ve)}}},dr=s=>{let n=Ee();n!=o&&tt(Q[s],void 0,n);let a=$(rt[s])&&$(ht[s]),d=$(mt[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],(([U,z],X)=>{z!==U&&(tt(mt[s],[X],z,U,ar),v=1)})),v&&tt(M[s],void 0,ar)}}},gt=(s,...n)=>(ws((()=>s(...Yt(n,at)))),Rt),hr=(s,n,a,d,f)=>{let v=$e(s,n,...a);return yt((()=>{let U=$e(s,n,...a);Fr(U,v)||(v=U,d(Rt,s,n,...a,v))}),D[f?1:0],[s,n],[kt])},hs=()=>Ke(h),kt=()=>Gt(h),ur=s=>Gt(g(y,at(s))),gr=s=>ce(g(h,at(s))),se=s=>Gt(g(h,at(s))),$e=(s,n,a,d=0,f)=>{return Xe(s)?$e(s.tableId,s.cellId,s.descending,s.offset,s.limit):Yt(Is(xs((v=g(h,at(s)),U=(z,X)=>[B(n)?X:g(z,at(n)),X],Yt([...v?.entries()??[]],(([z,X])=>U(X,z)))),(([z],[X])=>Gr(z,X)*(a?-1:1))),d,B(f)?f:d+f),(([,z])=>z));var v,U},us=(s,n)=>Gt(g(g(h,at(s)),at(n))),Ue=(s,n,a)=>g(g(g(h,at(s)),at(n)),at(a)),gs=()=>vt(C),fs=()=>Gt(C),Pe=s=>g(C,at(s)),Be=()=>!$(h),fr=s=>dt(h,at(s)),br=(s,n)=>dt(g(y,at(s)),at(n)),wr=(s,n)=>dt(g(h,at(s)),at(n)),pr=(s,n,a)=>dt(g(g(h,at(s)),at(n)),at(a)),Ee=()=>!$(C),yr=s=>dt(C,at(s)),He=s=>gt((()=>(n=>Wt(n,ke,At))(s)?qs(s):0)),Ae=s=>gt((()=>ue(s)?_s(s):0)),Sr=s=>(Ss((()=>Ks(ms(s)))),Rt),Lr=s=>gt((()=>{if((t=Wt(s,(n=>Wt(n,Ht))))&&(Js(s),!$(h))){let n=hs();Oe(),He(n)}})),Rr=s=>gt((()=>{if(e=(n=>Wt(n,Ht))(s)){let n=gs();bs(),We(),e=!0,Fs(s),Ae(n)}})),Oe=()=>gt((()=>qs({}))),mr=s=>gt((n=>dt(h,n)?Gs(n):0),s),vr=(s,n)=>gt(((a,d)=>it(g(h,a),(f=>dt(f,d)?Ys(a,f,d):0))),s,n),We=()=>gt((()=>_s({}))),Cr=()=>gt((()=>{Js({}),t=!1})),bs=()=>gt((()=>{Fs({}),e=!1})),ws=(s,n)=>{if(l!=-1){Tr();let a=s();return Ir(n),a}},Tr=()=>(l!=-1&&l++,l==1&&(c[0]?.(),tt(St)),Rt),Ir=s=>(l>0&&(l--,l==0&&(l=1,ir(1),$(b)||cr(1),lr(1),$(T)||dr(1),s?.(Rt)&&(V(b,((n,a)=>V(n,((d,f)=>V(d,(([v],U)=>Ye(Rt,a,f,U,v))))))),oe(b),V(T,(([n],a)=>Ms(Rt,a,n))),oe(T)),tt(Lt[0],void 0),l=-1,ir(0),$(b)||cr(0),lr(0),$(T)||dr(0),c[1]?.(),tt(Lt[1],void 0),c[2]?.(),l=0,r=Be(),o=Ee(),Tt([u,i,p,S,m,b,F,E,T,Z],oe))),Rt),Rt={getContent:()=>[hs(),gs()],getTables:hs,getTableIds:kt,getTable:s=>js(g(h,at(s))),getTableCellIds:ur,getRowCount:gr,getRowIds:se,getSortedRowIds:$e,getRow:(s,n)=>vt(g(g(h,at(s)),at(n))),getCellIds:us,getCell:Ue,getValues:gs,getValueIds:fs,getValue:Pe,hasTables:Be,hasTable:fr,hasTableCell:br,hasRow:wr,hasCell:pr,hasValues:Ee,hasValue:yr,getTablesJson:()=>re(h),getValuesJson:()=>re(C),getJson:()=>re([h,C]),getTablesSchemaJson:()=>re(L),getValuesSchemaJson:()=>re(_),getSchemaJson:()=>re([L,_]),hasTablesSchema:()=>t,hasValuesSchema:()=>e,setContent:s=>gt((()=>{let n=jt(s)?s():s;cs(n)&&(([a,d])=>{(Dt(a)?Oe:He)(a),(Dt(d)?We:Ae)(d)})(n)})),setTables:He,setTable:(s,n)=>gt((a=>ke(n,a)?Me(a,n):0),s),setRow:(s,n,a)=>gt(((d,f)=>qt(d,f,a)?ge(d,De(d),f,a):0),s,n),addRow:(s,n,a=!0)=>ws((()=>{let d;return qt(s,d,n)&&(s=at(s),ge(s,De(s),d=((f,v)=>{let[U]=g(st,f),z;do z=U(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=De(d);Pt(a,((U,z)=>Qs(d,v,f,z,U)))}}),s,n),setCell:(s,n,a,d)=>gt(((f,v,U)=>it(xe(f,v,U,jt(d)?d(Ue(f,v,U)):d),(z=>Qs(f,De(f),v,U,z)))),s,n,a),setValues:Ae,setPartialValues:s=>gt((()=>ue(s,1)?Pt(s,((n,a)=>je(a,n))):0)),setValue:(s,n)=>gt((a=>it(Ws(a,jt(n)?n(Pe(a)):n),(d=>je(a,d)))),s),applyChanges:s=>gt((()=>{Pt(s[0],((n,a)=>B(n)?mr(a):Pt(n,((d,f)=>B(d)?vr(a,f):Pt(d,((v,U)=>Ye(Rt,a,f,U,v))))))),Pt(s[1],((n,a)=>Ms(Rt,a,n)))})),setTablesJson:Sr,setValuesJson:s=>(Ss((()=>zs(ms(s)))),Rt),setJson:s=>gt((()=>Ss((()=>{let[n,a]=ms(s);Ks(n),zs(a)}),(()=>Sr(s))))),setTablesSchema:Lr,setValuesSchema:Rr,setSchema:(s,n)=>gt((()=>{Lr(s),Rr(n)})),delTables:Oe,delTable:mr,delRow:vr,delCell:(s,n,a,d)=>gt(((f,v,U)=>it(g(h,f),(z=>it(g(z,v),(X=>dt(X,U)?Xs(f,z,v,X,U,d):0))))),s,n,a),delValues:We,delValue:s=>gt((n=>dt(C,n)?Zs(n):0),s),delTablesSchema:Cr,delValuesSchema:bs,delSchema:()=>gt((()=>{Cr(),bs()})),transaction:ws,startTransaction:Tr,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=>Qe(f)))),$,Dt)),$,Dt),vt(T,(([,s])=>s),(s=>Qe(s))),1],getTransactionLog:()=>[!$(b),!$(T),Ke(b,Br,Qe),Ke(F),vt(T,Br,Qe),vt(Z),vt(u),js(S),Ke(m),vt(E)],finishTransaction:Ir,forEachTable:s=>V(h,((n,a)=>s(a,(d=>V(n,((f,v)=>d(v,(U=>wt(f,U))))))))),forEachTableCell:(s,n)=>wt(g(y,at(s)),n),forEachRow:(s,n)=>V(g(h,at(s)),((a,d)=>n(d,(f=>wt(a,f))))),forEachCell:(s,n,a)=>wt(g(g(h,at(s)),at(n)),a),forEachValue:s=>wt(C,s),addSortedRowIdsListener:(s,n,a,d,f,v,U)=>Xe(s)?hr(s.tableId,s.cellId,[s.descending??!1,s.offset??0,s.limit],n,a):hr(s,n,[a,d,f],v,U),addStartTransactionListener:s=>yt(s,St),addWillFinishTransactionListener:s=>yt(s,Lt[0]),addDidFinishTransactionListener:s=>yt(s,Lt[1]),callListener:s=>(Et(s),Rt),delListener:s=>(It(s),Rt),getListenerStats:()=>({hasTables:ft(W),tables:ft(K),tableIds:ft(P),hasTable:ft(q),table:ft(nt),tableCellIds:ft(ot),hasTableCell:ft(lt,Bt),rowCount:ft(N),rowIds:ft(R),sortedRowIds:ft(D),hasRow:ft(et,Bt),row:ft(G,Bt),cellIds:ft(j,Bt),hasCell:ft(H,Ls),cell:ft(J,Ls),invalidCell:ft(Y,Ls),hasValues:ft(Q),values:ft(M),valueIds:ft(rt),hasValue:ft(ht),value:ft(mt),invalidValue:ft(O),transaction:Xt(St)+ft(Lt)}),isMergeable:()=>!1,createStore:Us,addListener:yt,callListeners:tt,setInternalListeners:(s,n,a,d,f)=>c=[s,n,a,d,f]};return Pt({[zt+jr]:[0,W,[],()=>[Be()]],[jr]:[0,K],[bn]:[0,P],[zt+Jt]:[1,q,[kt],s=>[fr(...s)]],[Jt]:[1,nt,[kt]],[Jt+ze]:[1,ot,[kt]],[zt+Jt+Se]:[2,lt,[kt,ur],s=>[br(...s)]],[Ar]:[1,N,[kt]],[Or]:[1,R,[kt]],[zt+ae]:[2,et,[kt,se],s=>[wr(...s)]],[ae]:[2,G,[kt,se]],[ze]:[2,j,[kt,se]],[zt+Se]:[3,H,[kt,se,us],s=>[pr(...s)]],[Se]:[3,J,[kt,se,us],s=>qe(Ue(...s))],InvalidCell:[3,Y],[zt+Dr]:[0,Q,[],()=>[Ee()]],[Dr]:[0,M],[pn]:[0,rt],[zt+_e]:[1,ht,[fs],s=>[yr(...s)]],[_e]:[1,mt,[fs],s=>qe(Pe(s[0]))],InvalidValue:[1,O]},(([s,n,a,d],f)=>{Rt[Cs+f+vs]=(...v)=>yt(v[s],n[v[s+1]?1:0],s>0?Is(v,0,s):void 0,a,d)})),de(Rt)};var Vs=w([["avg",[(t,e)=>$r(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=>ps(...t),(t,e)=>ps(e,t),(t,e)=>e==t?void 0:t,(t,e,r)=>r==t?void 0:ps(e,t)]],["min",[t=>ys(...t),(t,e)=>ys(e,t),(t,e)=>e==t?void 0:t,(t,e,r)=>r==t?void 0:ys(e,t)]],["sum",[t=>$r(t),(t,e)=>t+e,(t,e)=>t-e,(t,e,r)=>t-r+e]]]),Yr=(t,e,r,o,l,c=!1)=>{if($(r))return;let[u,i,p,S]=l;return c||=B(t),V(o,(([m,b])=>{c||(t=B(m)?i?.(t,b,e++):B(b)?p?.(t,m,e--):S?.(t,b,m,e),c||=B(t))})),c?u(le(r),ce(r)):t},co=ve((t=>{let e=w(),[r,o,l]=Ce((()=>L)),[c,u,i,p,S,m,b,,E,T,F,Z]=es(t,Jr,(x=>isNaN(x)||B(x)||x===!0||x===!1||x===""?void 0:1*x),r,o),L={setMetricDefinition:(x,_,I,A,st,y,h)=>{let C=jt(I)?[I,st,y,h]:g(Vs,I)??g(Vs,"sum");return E(x,_,((W,K,P,q,nt,ot)=>{let lt=m(x),N=ce(q);ot||=B(lt),W();let R=Yr(lt,N,q,K,C,ot);Wr(R)||(R=void 0),R!=lt&&(b(x,R),o(e,[x],R,lt))}),Ze(A,1)),L},delMetricDefinition:x=>(T(x),L),getStore:c,getMetricIds:u,forEachMetric:i,hasMetric:p,getTableId:S,getMetric:m,addMetricIdsListener:F,addMetricListener:(x,_)=>r(_,e,[x]),delListener:x=>(l(x),L),destroy:Z,getListenerStats:()=>({metric:Xt(e)})};return de(L)})),ho=ve((t=>{let e=t.createStore,r=e(),o=e(),l=w(),{addListener:c,callListeners:u,delListener:i}=o,[p,S,m,b,E,,,T,,F,Z,L,x,_]=es(t,(()=>!0),Jr,c,u),I=(h,C,...W)=>Tt(W,(K=>ut(ct(ct(l,C,w),h,pt),K))),A=h=>{it(g(l,h),(C=>{wt(C,((W,K)=>V(K,(P=>W.delListener(P))))),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=[],P=[[null,[C,null,null,[],w()]]],q=[],nt=[],ot=[];W({select:(j,H)=>{let J=jt(j)?[xt(K)+"",j]:[B(H)?j:H,Y=>Y(j,H)];return Ct(K,J),{as:Y=>J[0]=Y}},join:(j,H,J)=>{let Y=B(J)||jt(H)?null:H,O=B(Y)?H:J,Q=[j,[j,Y,jt(O)?O:M=>M(O),[],w()]];return Ct(P,Q),{as:M=>Q[0]=M}},where:(j,H,J)=>Ct(q,jt(j)?j:B(J)?Y=>Y(j)===H:Y=>Y(j,H)===J),group:(j,H,J,Y,O)=>{let Q=[j,[j,jt(H)?[H,J,Y,O]:g(Vs,H)??[(M,rt)=>rt]]];return Ct(nt,Q),{as:M=>Q[0]=M}},having:(j,H)=>Ct(ot,jt(j)?j:J=>J(j)===H)});let lt=w(K);if($(lt))return y;let N=w(P);wt(N,((j,[,H])=>it(g(N,H),(({3:J})=>B(j)?0:Ct(J,j)))));let R=w(nt),D=r;if($(R)&&Le(ot))D=o;else{st(h,D,o);let j=w();wt(R,((O,[Q,M])=>ut(ct(j,Q,pt),[O,M])));let H=pt();wt(lt,(O=>dt(j,O)?0:ut(H,O)));let J=w(),Y=(O,Q,M,rt)=>it(O,(([ht,mt,St,Lt])=>{wt(Q,((yt,[tt])=>{let It=ct(ht,yt,w),Et=g(It,M),Ht=rt?void 0:tt;if(Et!==Ht){let cs=pt([[Et,Ht]]),ke=ce(It);k(It,M,Ht),V(g(j,yt),(([qt,xe])=>{let ue=Yr(Lt[qt],ke,It,cs,xe);Lt[qt]=B(ne(ue))?null:ue}))}})),$(mt)||!Ge(ot,(yt=>yt((tt=>Lt[tt]))))?o.delRow(h,St):B(St)?O[2]=o.addRow(h,Lt):o.setRow(h,St,Lt)}));I(D,h,D.addRowListener(h,null,((O,Q,M,rt)=>{let ht=[],mt=[],St=w(),Lt=D.hasRow(h,M),yt=!Lt;V(H,(tt=>{let[It,Et,Ht]=rt(h,M,tt);Ct(ht,Et),Ct(mt,Ht),yt||=It})),wt(j,(tt=>{let[It,,Et]=rt(h,M,tt);(yt||It)&&k(St,tt,[Et])})),yt&&Y(Re(J,ht,void 0,(([,tt])=>(Vt(tt,M),$(tt)))),St,M,1),Lt&&Y(Re(J,mt,(()=>{let tt={};return V(H,(It=>tt[It]=D.getCell(h,M,It))),[w(),pt(),void 0,tt]}),(([,tt])=>{ut(tt,M)})),St,M)})))}st(h,t,D);let et=(j,H,J,Y)=>{let O=Q=>t.getCell(H,J,Q);Tt(Y,(Q=>{let[M,,rt,ht,mt]=g(N,Q),St=rt?.(O,j),[Lt,yt]=g(mt,j)??[];St!=Lt&&(B(yt)||_(h,yt),k(mt,j,B(St)?null:[St,...x(h,1,t.addRowListener(M,St,(()=>et(j,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]);D.transaction((()=>Ge(q,(rt=>rt(M)))?wt(lt,((rt,ht)=>Ye(D,h,Q,rt,ht(M,Q)))):D.delRow(h,Q)))})(j)},{3:G}=g(N,null);return D.transaction((()=>x(h,1,t.addRowListener(C,null,((j,H,J)=>{t.hasRow(C,J)?et(J,C,J,G):(D.delRow(h,J),V(N,(({4:Y})=>it(g(Y,J),(([,O])=>{_(h,O),k(Y,J)})))))}))))),y},delQueryDefinition:h=>(A(h),F(h),y),getStore:p,getQueryIds:S,forEachQuery:m,hasQuery:b,getTableId:E,addQueryIdsListener:h=>Z((()=>h(y))),delListener:h=>(i(h),y),destroy:L,getListenerStats:()=>{let{tables:h,tableIds:C,transaction:W,...K}=o.getListenerStats();return K}};return Pt({[Jt]:[1,1],[Jt+ze]:[0,1],[Ar]:[0,1],[Or]:[0,1],[wn]:[0,5],[ae]:[1,2],[ze]:[0,2],[Se]:[1,3]},(([h,C],W)=>{Tt(h?["get","has","forEach"]:["get"],(K=>y[K+Mr+W]=(...P)=>o[K+W](...P))),y[Cs+Mr+W+vs]=(...K)=>o[Cs+W+vs](...Is(K,0,C),((P,...q)=>K[C](y,...q)),!0)})),de(y)})),uo=ve((t=>{let e=w(),r=w(),o=w(),l=w(),[c,u,i]=Ce((()=>st)),[p,S,m,b,E,T,,,F,Z,L,x]=es(t,(()=>[w(),w(),w(),w()]),(y=>B(y)?void 0:y+""),c,u),_=(y,h,C)=>it(T(y),(([W,,K])=>{if(!dt(K,h)){let P=pt();if(E(y)!=A(y))ut(P,h);else{let q=h;for(;!B(q)&&!dt(P,q);)ut(P,q),q=g(W,q)}if(C)return P;k(K,h,P)}return g(K,h)})),I=(y,h)=>it(T(y),(([,,C])=>k(C,h))),A=y=>g(e,y),st={setRelationshipDefinition:(y,h,C,W)=>(k(e,y,C),F(y,h,((K,P)=>{let q=pt(),nt=pt(),ot=pt(),[lt,N]=T(y);V(P,(([R,D],et)=>{B(R)||(ut(nt,R),it(g(N,R),(G=>{Vt(G,et),$(G)&&k(N,R)}))),B(D)||(ut(nt,D),dt(N,D)||k(N,D,pt()),ut(g(N,D),et)),ut(q,et),k(lt,et,D),wt(g(l,y),(G=>{dt(_(y,G),et)&&ut(ot,G)}))})),K(),V(q,(R=>u(r,[y,R]))),V(nt,(R=>u(o,[y,R]))),V(ot,(R=>{I(y,R),u(l,[y,R])}))}),Ze(W)),st),delRelationshipDefinition:y=>(k(e,y),Z(y),st),getStore:p,getRelationshipIds:S,forEachRelationship:y=>m((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:L,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:x,getListenerStats:()=>({remoteRowId:Bt(r),localRowIds:Bt(o),linkedRowIds:Bt(l)})};return de(st)}));var tn=Promise,xn=globalThis,Xr=xn.window,Mn=1e3,jn=(t,e,r)=>setInterval(t,e*Mn),Dn=clearInterval,$t=t=>t==null,as=(t,e,r)=>$t(t)?r?.():e(t),Bs=t=>Array.isArray(t),te=t=>t.length,Vn=(t,e)=>t.test(e),en=t=>new tn(t),sn=async t=>tn.all(t),rn=t=>{throw new Error(t)},Zt=async(t,e,r)=>{try{return await t()}catch(o){e?.(o)}},Es=(t,e)=>t.forEach(e),Te=(t,e)=>t.map(e),$n=(t,e)=>t.splice(0,e),is=(t,...e)=>t.push(...e),nn=t=>t.shift(),he=Object,Zr=t=>he.getPrototypeOf(t),Un=he.entries,Pn=t=>!$t(t)&&as(Zr(t),e=>e==he.prototype||$t(Zr(e)),()=>!0),Bn=he.keys,En=he.freeze,Hn=(t=[])=>he.fromEntries(t),An=(t,e)=>e in t,On=(t,e)=>Te(Un(t),([r,o])=>e(o,r)),Wn=t=>te(Bn(t)),ss=t=>Pn(t)&&Wn(t)==0,Nn=t=>t?.size??0,Jn=(t,e)=>t?.has(e)??!1,on=t=>$t(t)||Nn(t)==0,an=(t,e)=>t?.forEach(e),ln=(t,e)=>t?.delete(e),Ie=t=>new Map(t),Mt=(t,e)=>t?.get(e),ee=(t,e,r)=>$t(r)?(ln(t,e),t):t?.set(e,r),Hs=(t,e,r,o)=>(Jn(t,e)?o?.(Mt(t,e)):ee(t,e,r()),Mt(t,e)),As=(t,e,r,o,l=0)=>as((r?Hs:Mt)(t,e[l],l>te(e)-2?r:Ie),c=>{if(l>te(e)-2)return o?.(c)&&ee(t,e[l]),c;let u=As(c,e,r,o,l+1);return on(c)&&ee(t,e[l]),u}),Fn=/^\d+$/,Kn=()=>{let t=[],e=0;return[r=>(r?nn(t):null)??""+e++,r=>{Vn(Fn,r)&&te(t)<1e3&&is(t,r)}]},qn=t=>new Set(Bs(t)||$t(t)?t:[t]),Qn=(t,e)=>t?.add(e),zn=(t,e=[""])=>{let r=[],o=(l,c)=>c==te(e)?is(r,l):e[c]===null?an(l,u=>o(u,c+1)):Es([e[c],null],u=>o(Mt(l,u),c+1));return o(t,0),r},_n=t=>{let e,[r,o]=Kn(),l=Ie();return[(c,u,i,p=[],S=()=>[])=>{e??=t();let m=r(1);return ee(l,m,[c,u,i,p,S]),Qn(As(u,i??[""],qn),m),m},(c,u,...i)=>Es(zn(c,u),p=>an(p,S=>Mt(l,S)[0](e,...u??[],...i))),c=>as(Mt(l,c),([,u,i])=>(As(u,i??[""],void 0,p=>(ln(p,c),on(p)?1:0)),ee(l,c),o(c),i)),c=>as(Mt(l,c),([u,,i=[],p,S])=>{let m=(...b)=>{let E=te(b);E==te(i)?u(e,...b,...S(b)):$t(i[E])?Es(p[E]?.(...b)??[],T=>m(...b,T)):m(...b,i[E])};m()})]},rs=Ie(),ns=Ie(),Gn=(t=1,e,r)=>t!=1&&e.isMergeable()?[1,e.getMergeableContent,()=>e.getTransactionMergeableChanges(!r),([[o],[l]])=>!ss(o)||!ss(l),e.setDefaultContent]:t!=2?[0,e.getContent,e.getTransactionChanges,([o,l])=>!ss(o)||!ss(l),e.setContent]:rn("Store type not supported by this Persister"),Yn=(t,e,r,o,l,c,u,i={},p=0,S=[])=>{let m=0,b=0,E=0,T,F,Z;Hs(rs,S,()=>0),Hs(ns,S,()=>[]);let L=Ie(),[x,_,I,A,st]=Gn(u,t,p),[y,h,C]=_n(()=>Q),W=M=>{M!=m&&(m=M,h(L,void 0,m))},K=async()=>{if(!Mt(rs,S)){for(ee(rs,S,1);!$t(T=nn(Mt(ns,S)));)await Zt(T,c);ee(rs,S,0)}},P=M=>{(x&&Bs(M?.[0])?M?.[2]===1?t.applyMergeableChanges:t.setMergeableContent:M?.[2]===1?t.applyChanges:t.setContent)(M)},q=async M=>(m!=2&&(W(1),b++,await O(async()=>{await Zt(async()=>{let rt=await e();Bs(rt)?P(rt):M?st(M):rn(`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?m!=2&&(W(1),b++,P(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=>(m!=1&&(W(2),E++,await O(async()=>{await Zt(()=>r(_,M),c),W(0)})),Q),R=async()=>(D(),await N(),Z=t.addDidFinishTransactionListener(()=>{let M=I();A(M)&&N(M)}),Q),D=async()=>(Z&&(t.delListener(Z),Z=void 0),Q),et=()=>!$t(Z),G=async(M,rt=!1)=>{let[ht,mt]=rt?[R,nt]:[nt,R];return await ht(M),await mt(M),Q},j=async(M=!1)=>{let[rt,ht]=M?[D,ot]:[ot,D];return await rt(),await ht(),Q},H=()=>m,J=M=>y(M,L),Y=M=>(C(M),t),O=async(...M)=>(is(Mt(ns,S),...M),await K(),Q),Q={load:q,startAutoLoad:nt,stopAutoLoad:ot,isAutoLoading:lt,save:N,startAutoSave:R,stopAutoSave:D,isAutoSaving:et,startAutoPersisting:G,stopAutoPersisting:j,getStatus:H,addStatusListener:J,delListener:Y,schedule:O,getStore:()=>t,destroy:()=>($n(Mt(ns,S)),j()),getStats:()=>({loads:b,saves:E}),...i};return En(Q)},Ps=["t","v"],Xn={keyPath:"k"},Zn=async(t,e)=>{let r=On(e,(o,l)=>os(t,"put",{k:l,v:o}));Te(await os(t,"getAllKeys"),o=>An(e,o)?0:is(r,os(t,"delete",o))),await sn(r)},os=async(t,e,r)=>en((o,l)=>{let c=t[e](r);c.onsuccess=()=>o(c.result),c.onerror=()=>l(`objectStore.${e} error`)}),cn=(t,e,r=1,o)=>{let l=async(c,u=[],i=0)=>en((p,S)=>{let m=(Xr?Xr.indexedDB:indexedDB).open(e,i?2:void 0);m.onupgradeneeded=()=>i&&Te(Ps,b=>Zt(()=>m.result.createObjectStore(b,Xn))),m.onsuccess=()=>Zt(async()=>{let b=m.result.transaction(Ps,"readwrite"),E=await sn(Te(Ps,(T,F)=>c(b.objectStore(T),u[F])));m.result.close(),p(E)},b=>{m.result.close(),S(b)}),m.onerror=()=>S("indexedDB.open error")});return Yn(t,async()=>await l(async c=>Hn(Te(await os(c,"getAll"),({k:u,v:i})=>[u,i]))),c=>l((u,i)=>Zn(u,i),c(),1),c=>jn(c,r),c=>Dn(c),o,1,{getDbName:()=>e})};var ls=class{#t;#s="blobs";#e=null;constructor(e="copio-blobs"){this.#t=e}async#a(){return this.#e?this.#e:(this.#e=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.#s)||l.createObjectStore(this.#s)},o.onsuccess=()=>e(o.result),o.onerror=()=>r(o.error||new Error("Failed to open blob db"))}),this.#e)}async put(e,r){let o=await this.#a();return new Promise((l,c)=>{let p=o.transaction(this.#s,"readwrite").objectStore(this.#s).put(r,e);p.onsuccess=()=>l(),p.onerror=()=>c(p.error)})}async get(e){let r=await this.#a();return new Promise((o,l)=>{let i=r.transaction(this.#s,"readonly").objectStore(this.#s).get(e);i.onsuccess=()=>o(i.result||null),i.onerror=()=>l(i.error)})}async delete(e){let r=await this.#a();return new Promise((o,l)=>{let i=r.transaction(this.#s,"readwrite").objectStore(this.#s).delete(e);i.onsuccess=()=>o(),i.onerror=()=>l(i.error)})}async deleteByPrefix(e){let r=await this.#a();return new Promise((o,l)=>{let u=r.transaction(this.#s,"readwrite").objectStore(this.#s),i=u.openKeyCursor();i.onsuccess=p=>{let S=p.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.#a(),l=0;return new Promise((c,u)=>{let p=o.transaction(this.#s,"readwrite").objectStore(this.#s),S=p.openKeyCursor();S.onsuccess=m=>{let b=m.target.result;if(b){if(typeof b.key=="string"){let E=b.key.split(":")[0];r.has(E)||(p.delete(b.key),l++)}b.continue()}else c(l)},S.onerror=()=>u(S.error)})}async close(){if(this.#e){try{(await this.#e).close()}catch{}this.#e=null}}};function Os(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 Lo(t){return new Promise((e,r)=>{let o=new FileReader;o.onloadend=()=>e(o.result),o.onerror=r,o.readAsDataURL(t)})}var dn=class extends xr{#t=null;#s=null;#e=null;#a="copio-db";#u=!1;#i=new Set;#l=new Map;#r=new Map;#n=new Map;#o=new Map;#c=null;constructor(e={}){super(),this.#a=e.dbName||"copio-db",e.dbName&&e.dbName!=="copio-db"&&(this.#u=!0),this.#t=e.store||Us(),this.#t.hasTable("docs")||this.#t.setTable("docs",{}),this.#s=e.persister||cn(this.#t,this.#a),this.#e=new ls(`${this.#a}-blobs`)}get store(){return this.#t}get persister(){return this.#s}get blobStore(){return this.#e}#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.#o.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.#o.clear()}async init(){return this.#c?this.#c:(this.#c=(async()=>{this.#u?(await this.#s.load(),this.#s.startAutoLoad(),this.#s.startAutoSave()):await this.#s.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.#e.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.#o.has(e))return this.#o.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},p=`${e}:${u.id}`,S=await this.#e.get(`${e}:${u.id}`);S&&(i.blob=S,this.#r.has(p)?i.src=this.#r.get(p):(i.src=this.#d(e,URL.createObjectURL(S)),this.#r.set(p,i.src)));let m=`${e}:${u.id}:orig`,b=await this.#e.get(`${e}:${u.id}:original`);return b?(i.originalBlob=b,this.#n.has(m)?i.originalSrc=this.#n.get(m):(i.originalSrc=this.#d(e,URL.createObjectURL(b)),this.#n.set(m,i.originalSrc))):i.blob&&(i.originalBlob=i.blob,i.originalSrc=i.src),i})),c={id:e,name:r.name||"",pages:l};return this.#o.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 p=Os(i.src)||(i.src instanceof Blob?i.src:null)||(i.blob instanceof Blob?i.blob:null),S=p?.type||"image/jpeg",m={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(m);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(p)if(T.blob=p,Z||!F){if(F){try{URL.revokeObjectURL(F)}catch{}this.#i.delete(F)}let A=this.#d(e,URL.createObjectURL(p));this.#r.set(b,A),T.src=A}else T.src=F;let L=Os(i.originalSrc)||(i.originalSrc instanceof Blob?i.originalSrc:null)||(i.originalBlob instanceof Blob?i.originalBlob:null),x=this.#n.get(E),_=!x&&!L&&(!i.originalSrc||i.originalSrc===i.src);_&&p&&(L=p);let I=typeof i.originalSrc=="string"&&i.originalSrc.startsWith("data:")||i.originalSrc instanceof Blob||_&&!!L;if(L)if(T.originalBlob=L,I||!x){if(x&&I){try{URL.revokeObjectURL(x)}catch{}this.#i.delete(x)}let A=this.#d(e,URL.createObjectURL(L));this.#n.set(E,A),T.originalSrc=A}else T.originalSrc=x;else x?T.originalSrc=x: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:p,origBlob:L})}this.#t.setRow("docs",e,{name:r.name||"",pages:JSON.stringify(l)}),this.#o.set(e,{id:e,name:r.name||"",pages:c});for(let i of u){let{pageId:p,page:S,srcBlob:m,origBlob:b}=i;if(!m&&typeof S.src=="string"&&S.src.startsWith("blob:"))try{m=await(await fetch(S.src)).blob()}catch{}if(m&&await this.#e.put(`${e}:${p}`,m),!b&&typeof S.originalSrc=="string"&&S.originalSrc.startsWith("blob:"))try{b=await(await fetch(S.originalSrc)).blob()}catch{}b&&await this.#e.put(`${e}:${p}:original`,b)}}async deleteDoc(e){this.#t.delRow("docs",e),await this.#e.deleteByPrefix(`${e}:`),this.revokeDocUrls(e),this.#o.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.#o.has(e)&&(this.#o.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(p=>p.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 p=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(p),u=p}let i=Os(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.#e.put(`${e}:${r}`,i),await this.saveDoc(e,l)}async getPage(e,r){let o=await this.#e.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.#e.delete(`${e}:${r}`),await this.#e.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.#o.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{Us as a,Os as b,Lo as c,dn as d};
2
+ //# sourceMappingURL=chunk-L4OVZN23.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-KIMVF5UG.js.map
2
+ //# sourceMappingURL=chunk-NEEWG3OP.js.map
@@ -0,0 +1,50 @@
1
+ var N=globalThis,V=N.ShadowRoot&&(N.ShadyCSS===void 0||N.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,rt=Symbol(),F=new WeakMap,k=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==rt)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.i,e=this.t;if(V&&t===void 0){let s=e!==void 0&&e.length===1;s&&(t=F.get(e)),t===void 0&&((this.i=t=new CSSStyleSheet).replaceSync(this.cssText),s&&F.set(e,t))}return t}toString(){return this.cssText}},dt=n=>new k(typeof n=="string"?n:n+"",void 0,rt);var pt=(n,t)=>{if(V)n.adoptedStyleSheets=t.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet));else for(let e of t){let s=document.createElement("style"),i=N.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,n.appendChild(s)}},G=V?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(let s of t.cssRules)e+=s.cssText;return dt(e)})(n):n,{is:ut,defineProperty:ft,getOwnPropertyDescriptor:$t,getOwnPropertyNames:gt,getOwnPropertySymbols:mt,getPrototypeOf:At}=Object,T=globalThis,X=T.trustedTypes,yt=X?X.emptyScript:"",_t=T.reactiveElementPolyfillSupport,P=(n,t)=>n,L={toAttribute(n,t){switch(t){case Boolean:n=n?yt:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},ot=(n,t)=>!ut(n,t),Y={attribute:!0,type:String,converter:L,reflect:!1,useDefault:!1,hasChanged:ot};Symbol.metadata??=Symbol("metadata"),T.litPropertyMetadata??=new WeakMap;var g=class extends HTMLElement{static addInitializer(t){this.o(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this.u&&[...this.u.keys()]}static createProperty(t,e=Y){if(e.state&&(e.attribute=!1),this.o(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){let s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&ft(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){let{get:i,set:r}=$t(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o}};return{get:i,set(o){let l=i?.call(this);r?.call(this,o),this.requestUpdate(t,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Y}static o(){if(this.hasOwnProperty(P("elementProperties")))return;let t=At(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(P("finalized")))return;if(this.finalized=!0,this.o(),this.hasOwnProperty(P("properties"))){let e=this.properties,s=[...gt(e),...mt(e)];for(let i of s)this.createProperty(i,e[i])}let t=this[Symbol.metadata];if(t!==null){let e=litPropertyMetadata.get(t);if(e!==void 0)for(let[s,i]of e)this.elementProperties.set(s,i)}this.u=new Map;for(let[e,s]of this.elementProperties){let i=this.p(e,s);i!==void 0&&this.u.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){let e=[];if(Array.isArray(t)){let s=new Set(t.flat(1/0).reverse());for(let i of s)e.unshift(G(i))}else t!==void 0&&e.push(G(t));return e}static p(t,e){let s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this.v=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this.m=null,this._()}_(){this.S=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this.$(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this.P??=new Set).add(t),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.()}removeController(t){this.P?.delete(t)}$(){let t=new Map,e=this.constructor.elementProperties;for(let s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this.v=t)}createRenderRoot(){let t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return pt(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this.P?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this.P?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,e,s){this._$AK(t,s)}C(t,e){let s=this.constructor.elementProperties.get(t),i=this.constructor.p(t,s);if(i!==void 0&&s.reflect===!0){let r=(s.converter?.toAttribute!==void 0?s.converter:L).toAttribute(e,s.type);this.m=t,r==null?this.removeAttribute(i):this.setAttribute(i,r),this.m=null}}_$AK(t,e){let s=this.constructor,i=s.u.get(t);if(i!==void 0&&this.m!==i){let r=s.getPropertyOptions(i),o=typeof r.converter=="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:L;this.m=i;let l=o.fromAttribute(e,r.type);this[i]=l??this.T?.get(i)??l,this.m=null}}requestUpdate(t,e,s){if(t!==void 0){let i=this.constructor,r=this[t];if(s??=i.getPropertyOptions(t),!((s.hasChanged??ot)(r,e)||s.useDefault&&s.reflect&&r===this.T?.get(t)&&!this.hasAttribute(i.p(t,s))))return;this.M(t,e,s)}this.isUpdatePending===!1&&(this.S=this.k())}M(t,e,{useDefault:s,reflect:i,wrapped:r},o){s&&!(this.T??=new Map).has(t)&&(this.T.set(t,o??e??this[t]),r!==!0||o!==void 0)||(this._$AL.has(t)||(this.hasUpdated||s||(e=void 0),this._$AL.set(t,e)),i===!0&&this.m!==t&&(this.A??=new Set).add(t))}async k(){this.isUpdatePending=!0;try{await this.S}catch(e){Promise.reject(e)}let t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this.v){for(let[i,r]of this.v)this[i]=r;this.v=void 0}let s=this.constructor.elementProperties;if(s.size>0)for(let[i,r]of s){let{wrapped:o}=r,l=this[i];o!==!0||this._$AL.has(i)||l===void 0||this.M(i,void 0,r,l)}}let t=!1,e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this.P?.forEach((s=>s.hostUpdate?.())),this.update(e)):this.U()}catch(s){throw t=!1,this.U(),s}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this.P?.forEach((e=>e.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}U(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this.S}shouldUpdate(t){return!0}update(t){this.A&&=this.A.forEach((e=>this.C(e,this[e]))),this.U()}updated(t){}firstUpdated(t){}};g.elementStyles=[],g.shadowRootOptions={mode:"open"},g[P("elementProperties")]=new Map,g[P("finalized")]=new Map,_t?.({ReactiveElement:g}),(T.reactiveElementVersions??=[]).push("2.1.1");var j=globalThis,M=j.trustedTypes,Q=M?M.createPolicy("lit-html",{createHTML:n=>n}):void 0,ht="$lit$",m=`lit$${Math.random().toFixed(9).slice(2)}$`,at="?"+m,vt=`<${at}>`,v=document,x=()=>v.createComment(""),U=n=>n===null||typeof n!="object"&&typeof n!="function",q=Array.isArray,St=n=>q(n)||typeof n?.[Symbol.iterator]=="function",O=`[
2
+ \f\r]`,C=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,tt=/-->/g,et=/>/g,y=RegExp(`>|${O}(?:([^\\s"'>=/]+)(${O}*=${O}*(?:[^
3
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),st=/'/g,it=/"/g,lt=/^(?:script|style|textarea|title)$/i,K=n=>(t,...e)=>({_$litType$:n,strings:t,values:e}),f=K(1),xt=K(2),Ut=K(3),S=Symbol.for("lit-noChange"),d=Symbol.for("lit-nothing"),nt=new WeakMap,_=v.createTreeWalker(v,129);function ct(n,t){if(!q(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return Q!==void 0?Q.createHTML(t):t}var bt=(n,t)=>{let e=n.length-1,s=[],i,r=t===2?"<svg>":t===3?"<math>":"",o=C;for(let l=0;l<e;l++){let h=n[l],c,p,a=-1,u=0;for(;u<h.length&&(o.lastIndex=u,p=o.exec(h),p!==null);)u=o.lastIndex,o===C?p[1]==="!--"?o=tt:p[1]!==void 0?o=et:p[2]!==void 0?(lt.test(p[2])&&(i=RegExp("</"+p[2],"g")),o=y):p[3]!==void 0&&(o=y):o===y?p[0]===">"?(o=i??C,a=-1):p[1]===void 0?a=-2:(a=o.lastIndex-p[2].length,c=p[1],o=p[3]===void 0?y:p[3]==='"'?it:st):o===it||o===st?o=y:o===tt||o===et?o=C:(o=y,i=void 0);let $=o===y&&n[l+1].startsWith("/>")?" ":"";r+=o===C?h+vt:a>=0?(s.push(c),h.slice(0,a)+ht+h.slice(a)+m+$):h+m+(a===-2?l:$)}return[ct(n,r+(n[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]},E=class n{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let r=0,o=0,l=t.length-1,h=this.parts,[c,p]=bt(t,e);if(this.el=n.createElement(c,s),_.currentNode=this.el.content,e===2||e===3){let a=this.el.content.firstChild;a.replaceWith(...a.childNodes)}for(;(i=_.nextNode())!==null&&h.length<l;){if(i.nodeType===1){if(i.hasAttributes())for(let a of i.getAttributeNames())if(a.endsWith(ht)){let u=p[o++],$=i.getAttribute(a).split(m),R=/([.?@])?(.*)/.exec(u);h.push({type:1,index:r,name:R[2],strings:$,ctor:R[1]==="."?z:R[1]==="?"?B:R[1]==="@"?I:w}),i.removeAttribute(a)}else a.startsWith(m)&&(h.push({type:6,index:r}),i.removeAttribute(a));if(lt.test(i.tagName)){let a=i.textContent.split(m),u=a.length-1;if(u>0){i.textContent=M?M.emptyScript:"";for(let $=0;$<u;$++)i.append(a[$],x()),_.nextNode(),h.push({type:2,index:++r});i.append(a[u],x())}}}else if(i.nodeType===8)if(i.data===at)h.push({type:2,index:r});else{let a=-1;for(;(a=i.data.indexOf(m,a+1))!==-1;)h.push({type:7,index:r}),a+=m.length-1}r++}}static createElement(t,e){let s=v.createElement("template");return s.innerHTML=t,s}};function b(n,t,e=n,s){if(t===S)return t;let i=s!==void 0?e.N?.[s]:e.O,r=U(t)?void 0:t._$litDirective$;return i?.constructor!==r&&(i?._$AO?.(!1),r===void 0?i=void 0:(i=new r(n),i._$AT(n,e,s)),s!==void 0?(e.N??=[])[s]=i:e.O=i),i!==void 0&&(t=b(n,i._$AS(n,t.values),i,s)),t}var D=class{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}R(t){let{el:{content:e},parts:s}=this._$AD,i=(t?.creationScope??v).importNode(e,!0);_.currentNode=i;let r=_.nextNode(),o=0,l=0,h=s[0];for(;h!==void 0;){if(o===h.index){let c;h.type===2?c=new H(r,r.nextSibling,this,t):h.type===1?c=new h.ctor(r,h.name,h.strings,this,t):h.type===6&&(c=new W(r,this,t)),this._$AV.push(c),h=s[++l]}o!==h?.index&&(r=_.nextNode(),o++)}return _.currentNode=v,i}V(t){let e=0;for(let s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}},H=class n{get _$AU(){return this._$AM?._$AU??this.D}constructor(t,e,s,i){this.type=2,this._$AH=d,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this.D=i?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode,e=this._$AM;return e!==void 0&&t?.nodeType===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=b(this,t,e),U(t)?t===d||t==null||t===""?(this._$AH!==d&&this._$AR(),this._$AH=d):t!==this._$AH&&t!==S&&this.L(t):t._$litType$!==void 0?this.j(t):t.nodeType!==void 0?this.I(t):St(t)?this.H(t):this.L(t)}B(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}I(t){this._$AH!==t&&(this._$AR(),this._$AH=this.B(t))}L(t){this._$AH!==d&&U(this._$AH)?this._$AA.nextSibling.data=t:this.I(v.createTextNode(t)),this._$AH=t}j(t){let{values:e,_$litType$:s}=t,i=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=E.createElement(ct(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===i)this._$AH.V(e);else{let r=new D(i,this),o=r.R(this.options);r.V(e),this.I(o),this._$AH=r}}_$AC(t){let e=nt.get(t.strings);return e===void 0&&nt.set(t.strings,e=new E(t)),e}H(t){q(this._$AH)||(this._$AH=[],this._$AR());let e=this._$AH,s,i=0;for(let r of t)i===e.length?e.push(s=new n(this.B(x()),this.B(x()),this,this.options)):s=e[i],s._$AI(r),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){let s=t.nextSibling;t.remove(),t=s}}setConnected(t){this._$AM===void 0&&(this.D=t,this._$AP?.(t))}},w=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,r){this.type=1,this._$AH=d,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=r,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=d}_$AI(t,e=this,s,i){let r=this.strings,o=!1;if(r===void 0)t=b(this,t,e,0),o=!U(t)||t!==this._$AH&&t!==S,o&&(this._$AH=t);else{let l=t,h,c;for(t=r[0],h=0;h<r.length-1;h++)c=b(this,l[s+h],e,h),c===S&&(c=this._$AH[h]),o||=!U(c)||c!==this._$AH[h],c===d?t=d:t!==d&&(t+=(c??"")+r[h+1]),this._$AH[h]=c}o&&!i&&this.W(t)}W(t){t===d?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}},z=class extends w{constructor(){super(...arguments),this.type=3}W(t){this.element[this.name]=t===d?void 0:t}},B=class extends w{constructor(){super(...arguments),this.type=4}W(t){this.element.toggleAttribute(this.name,!!t&&t!==d)}},I=class extends w{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5}_$AI(t,e=this){if((t=b(this,t,e,0)??d)===S)return;let s=this._$AH,i=t===d&&s!==d||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==d&&(s===d||i);i&&this.element.removeEventListener(this.name,this,s),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}},W=class{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){b(this,t)}};var wt=j.litHtmlPolyfillSupport;wt?.(E,H),(j.litHtmlVersions??=[]).push("3.3.1");var Ct=(n,t,e)=>{let s=e?.renderBefore??t,i=s._$litPart$;if(i===void 0){let r=e?.renderBefore??null;s._$litPart$=i=new H(t.insertBefore(x(),r),r,void 0,e??{})}return i._$AI(n),i},J=globalThis;var A=class extends g{constructor(){super(...arguments),this.renderOptions={host:this},this.rt=void 0}createRenderRoot(){let t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){let e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this.rt=Ct(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this.rt?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this.rt?.setConnected(!1)}render(){return S}};A._$litElement$=!0,A.finalized=!0,J.litElementHydrateSupport?.({LitElement:A});var Pt=J.litElementPolyfillSupport;Pt?.({LitElement:A});(J.litElementVersions??=[]).push("4.2.1");var Z=class extends A{static properties={syncState:{type:Object}};createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.closeSyncDialog()}handleCloseClick=()=>{let t=this.querySelector("sl-dialog");t&&typeof t.hide=="function"?t.hide():this.closeSyncDialog()};closeSyncDialog=()=>{this.dispatchEvent(new CustomEvent("dialog:close",{bubbles:!0,composed:!1}))};render(){if(!this.syncState)return"";let{step:t,qrSvg:e,url:s,added:i,message:r}=this.syncState,o;return t==="init"?o=f`<sl-spinner></sl-spinner> Setting up…`:t==="waiting"?o=f`
4
+ <div .innerHTML=${e}></div>
5
+ ${s?f`
6
+ <div style="margin: 0.75rem 0; word-break: break-all;">
7
+ <a
8
+ class="sync-link"
9
+ href=${s}
10
+ target="_blank"
11
+ rel="noopener noreferrer"
12
+ style="color: var(--sl-color-primary-600, #0284c7); text-decoration: underline; font-size: 0.85rem;"
13
+ >
14
+ ${s}
15
+ </a>
16
+ </div>
17
+ `:""}
18
+ <p style="margin-top: 0.5rem; color: #6b7280; font-size: 0.9rem;">Waiting for other device…</p>
19
+ `:t==="connecting"?o=f`<sl-spinner></sl-spinner> Connecting…`:t==="syncing"?o=f`<sl-spinner></sl-spinner> Syncing…`:t==="done"?o=f`<p>
20
+ Sync complete — ${i} doc${i!==1?"s":""} added.
21
+ </p>`:t==="error"&&(o=f`<p style="color:var(--sl-color-danger-600)">
22
+ Error: ${r}
23
+ </p>`),f`
24
+ <sl-dialog
25
+ label="Link Device"
26
+ open
27
+ @sl-after-hide=${this.closeSyncDialog}
28
+ >
29
+ <div style="text-align:center;padding:1rem">${o}</div>
30
+ <sl-button slot="footer" class="sync-close-btn" @click=${this.handleCloseClick}
31
+ >Close</sl-button
32
+ >
33
+ </sl-dialog>
34
+ `}};customElements.define("copio-sync-dialog",Z);export{f as a,A as b,Z as c};
35
+ /**
36
+ * @license
37
+ * Copyright 2019 Google LLC
38
+ * SPDX-License-Identifier: BSD-3-Clause
39
+ */
40
+ /**
41
+ * @license
42
+ * Copyright 2017 Google LLC
43
+ * SPDX-License-Identifier: BSD-3-Clause
44
+ */
45
+ /**
46
+ * @license
47
+ * Copyright 2022 Google LLC
48
+ * SPDX-License-Identifier: BSD-3-Clause
49
+ */
50
+ //# sourceMappingURL=chunk-NQW6FFN7.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-YHLOPPXM.js.map
2
+ //# sourceMappingURL=chunk-O6FQFVKY.js.map
@@ -1,2 +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
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-HN3336JN.js.map
2
+ //# sourceMappingURL=chunk-ULTSZWZO.js.map
@@ -1,2 +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
1
+ import{d as r}from"./chunk-YNY65JUJ.js";import{h as c,i as a}from"./chunk-ZT72PD2C.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-WETG2JD7.js.map
@@ -1,2 +1,2 @@
1
1
  var v=null,C={success:{slVariant:"success",defaultIcon:"check-circle",defaultDuration:3e3},error:{slVariant:"danger",defaultIcon:"exclamation-octagon",defaultDuration:5e3},danger:{slVariant:"danger",defaultIcon:"exclamation-octagon",defaultDuration:5e3},warning:{slVariant:"warning",defaultIcon:"exclamation-triangle",defaultDuration:4e3},info:{slVariant:"primary",defaultIcon:"info-circle",defaultDuration:4e3},primary:{slVariant:"primary",defaultIcon:"info-circle",defaultDuration:4e3},neutral:{slVariant:"neutral",defaultIcon:"info-circle",defaultDuration:4e3}};function I(n){v=n||null}function g(){return v||(typeof document<"u"?document.body:null)}function k(){let a=customElements.get("sl-alert")?.toastStack;a&&a.querySelectorAll("sl-alert").forEach(u=>{typeof u.hide=="function"&&u.hide()})}async function w(n,a={}){let e={};if(typeof n=="string"||n instanceof HTMLElement?e={message:n,...a}:n&&typeof n=="object"&&(e={...n,...a}),typeof customElements<"u"&&!customElements.get("sl-alert")&&await Promise.race([customElements.whenDefined("sl-alert"),new Promise(t=>setTimeout(t,200))]),typeof customElements>"u"||!customElements.get("sl-alert"))return null;let u=customElements.get("sl-alert"),s=e.variant||"info",f=C[s]||C.info,r=e.container||g();if(u?.toastStack&&r){let t=u.toastStack;t.parentElement!==r&&r.appendChild(t),r!==document.body?(t.style.position="absolute",t.style.width="auto",t.style.maxWidth="calc(100% - 24px)",t.style.left="12px",t.style.right="12px",t.style.insetInlineStart="12px",t.style.insetInlineEnd="12px",e.position==="top"?(t.style.top="12px",t.style.bottom="auto"):(t.style.top="auto",t.style.bottom="16px"),t.style.maxHeight="100%",t.style.overflow="auto"):(t.style.position="",t.style.width="",t.style.left="",t.style.right="",t.style.top="",t.style.bottom="",t.style.insetInlineStart="",t.style.insetInlineEnd="",t.style.maxHeight="",t.style.maxWidth="",t.style.overflow="")}let o=document.createElement("sl-alert");o.variant=f.slVariant,o.closable=e.closable!==!1,o.duration=e.duration!==void 0?e.duration:f.defaultDuration;let d=e.icon!==void 0?e.icon:f.defaultIcon;if(d){let t=document.createElement("sl-icon");t.slot="icon",t.name=d,o.appendChild(t)}let i=document.createElement("span");if(e.message instanceof HTMLElement?i.appendChild(e.message):e.html?i.innerHTML=e.message||"":i.textContent=e.message||"",e.action){let t=document.createElement("div");t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="space-between",t.style.gap="0.75rem",t.style.width="100%",i.style.flex="1",t.appendChild(i);let l=document.createElement("sl-button");l.size="small",l.variant=e.action.variant||"text",l.textContent=e.action.text||"Action",l.style.color="inherit",l.style.fontWeight="600",l.style.padding="0",l.addEventListener("click",m=>{m.preventDefault(),m.stopPropagation(),typeof e.action.onClick=="function"&&e.action.onClick(m,o),e.action.autoClose!==!1&&o.hide()}),t.appendChild(l),o.appendChild(t)}else o.appendChild(i);let y=o.toast();return o.toastPromise=y,o}function D(n,a={}){return p.show({message:n,variant:"success",...a})}function S(n,a={}){return p.show({message:n,variant:"error",...a})}function M(n,a={}){return p.show({message:n,variant:"warning",...a})}function N(n,a={}){return p.show({message:n,variant:"info",...a})}function V(n,a,e={}){return p.show({message:n,variant:e?.variant||"primary",icon:e?.icon!==void 0?e.icon:"arrow-counterclockwise",duration:e?.duration!==void 0?e.duration:5e3,closable:e?.closable!==!1,action:{text:e?.actionText||"Undo",onClick:(u,s)=>{typeof a=="function"&&a(u,s)},autoClose:!0},...e})}async function P(n,a={}){let e={};if(typeof n=="string"?e={message:n,...a}:n&&typeof n=="object"&&(e={...n,...a}),typeof customElements<"u"&&(!customElements.get("sl-alert")||!customElements.get("sl-progress-bar"))&&await Promise.race([Promise.all([customElements.whenDefined("sl-alert"),customElements.whenDefined("sl-progress-bar")]),new Promise(c=>setTimeout(c,200))]),typeof customElements>"u"||!customElements.get("sl-alert"))return{alert:null,progressBar:null,update(){},close(){}};let u=e.container||g(),s=document.createElement("sl-alert");s.variant=e.variant||"primary",s.closable=e.closable===!0,s.duration=1/0;let f=e.icon!==void 0?e.icon:"arrow-down-circle";if(f){let c=document.createElement("sl-icon");c.slot="icon",c.name=f,s.appendChild(c)}let r=document.createElement("div");r.className="notify-progress-wrapper",r.style.display="flex",r.style.flexDirection="column",r.style.gap="0.35rem",r.style.minWidth="220px";let o=document.createElement("div");o.style.display="flex",o.style.justifyContent="space-between",o.style.alignItems="center",o.style.gap="0.5rem";let d=document.createElement("span");d.className="notify-progress-message",d.style.fontWeight="500",d.style.fontSize="0.9rem",d.textContent=e.message||"Processing...",o.appendChild(d);let i=document.createElement("span");i.className="notify-progress-status",i.style.fontSize="0.78rem",i.style.color="#64748b",i.style.fontWeight="600";let y=e.done!==void 0?e.done:0,t=e.total!==void 0?e.total:0;t>0?i.textContent=`${y} / ${t}`:e.value!==void 0&&(i.textContent=`${e.value}%`),o.appendChild(i),r.appendChild(o);let l=document.createElement("sl-progress-bar");t>0?l.value=Math.round(y/t*100):e.value!==void 0?l.value=e.value:l.indeterminate=!0,r.appendChild(l),s.appendChild(r);let m=customElements.get("sl-alert");if(m?.toastStack&&u){let c=m.toastStack;c.parentElement!==u&&u.appendChild(c)}return s.toast(),{alert:s,progressBar:l,update({done:c,total:h,value:x,message:E}={}){if(E!==void 0&&(d.textContent=E),h!==void 0&&c!==void 0){l.indeterminate=!1;let b=Math.min(100,Math.max(0,Math.round(c/Math.max(h,1)*100)));l.value=b,i.textContent=`${c} / ${h}`}else x!==void 0&&(l.indeterminate=!1,l.value=Math.min(100,Math.max(0,x)),i.textContent=`${Math.round(l.value)}%`)},close(){typeof s.hide=="function"&&s.hide()}}}var p=Object.assign(function(n,a){return w(n,a)},{show:w,success:D,error:S,warning:M,info:N,undo:V,progress:P,clear:k,setContainer:I,getContainer:g});export{I as a,g as b,k as c,p as d};
2
- //# sourceMappingURL=chunk-V2FP4EEH.js.map
2
+ //# sourceMappingURL=chunk-YNY65JUJ.js.map
@@ -0,0 +1,2 @@
1
+ var c=".";function l(){return c}function m(e){typeof e=="string"&&(c=e.replace(/\/+$/,"")||".")}function w(e){if(!e)return"";if(/^(https?:|\/\/|data:|blob:)/i.test(e))return e;let n=e.replace(/^\/+/,""),r=c;return!r||r==="."?n:`${r}/${n}`}var s=new Map;function o(e,n){let r=n();if(r)return Promise.resolve(r);if(s.has(e))return s.get(e);let p=new Promise((i,d)=>{if(typeof document>"u"){d(new Error(`Cannot load script "${e}" in an environment without DOM document.`));return}let a=w(e),u=document.querySelector(`script[src="${a}"], script[src="${e}"]`);if(u){if(n()){i(n());return}u.addEventListener("load",()=>i(n()),{once:!0}),u.addEventListener("error",()=>d(new Error(`Failed to load "${e}": Network error`)),{once:!0});return}let t=document.createElement("script");t.src=a,t.async=!0,t.onload=()=>{let f=n();i(f)},t.onerror=()=>{s.delete(e),t.remove(),d(new Error(`Failed to load script "${e}": Network error`))},document.head.appendChild(t)});return s.set(e,p),p}async function j(){return o("js/lib/cropper.js",()=>window.Cropper)}async function x(){return o("js/lib/pdfkit.js",()=>window.PDFDocument)}async function y(){return o("js/lib/jszip.min.js",()=>window.JSZip)}async function P(){return o("js/lib/peerjs.min.js",()=>window.Peer)}async function $(){return o("js/lib/qrcode.js",()=>window.qrcode)}async function g(){return o("js/lib/tesseract.min.js",()=>window.Tesseract)}export{l as a,m as b,w as c,o as d,j as e,x as f,y as g,P as h,$ as i,g as j};
2
+ //# sourceMappingURL=chunk-ZT72PD2C.js.map
package/dist/core.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o,b as p,c as q,d as r,e as x,f as y,g as z,h as A,i as B,j as C,k as D,l as E,m as F,n as G,o as H,p as I,q as J}from"./chunk-HS6GDZIS.js";import"./chunk-4GEMGDRU.js";import{a as e,b as f,c as g,d as h,e as i,f as j,g as k,h as l,j as m,k as n,l as v}from"./chunk-N7Q34F2P.js";import{a as w}from"./chunk-SH4P4XSZ.js";import{a as u}from"./chunk-HN3336JN.js";import{a as d}from"./chunk-36F637QU.js";import{a as c}from"./chunk-4JPEWIT4.js";import{a as s}from"./chunk-B7HT2X67.js";import"./chunk-N4R55VRR.js";import{a as t}from"./chunk-E7JYVRJA.js";import"./chunk-YHLOPPXM.js";import"./chunk-G65H4ZTJ.js";import{a as b}from"./chunk-OI4WCW7E.js";import{a}from"./chunk-LI54F6PA.js";import"./chunk-4C666HHU.js";export{q as BUILD_DATE,C as COPIO_EVENTS,v as Canvas2DAdapter,J as CopioEngine,F as DEFAULT_EXPORT_FORMATS,E as DEFAULT_FEATURES,G as DEFAULT_OCR_LANGUAGES,o as DocRepository,A as Document,u as ImageProcessorPort,c as IndexedDbStorageAdapter,b as MemoryStorageAdapter,w as NullImageProcessorAdapter,s as NullOcrAdapter,t as NullPdfAdapter,z as Page,B as ScanSession,a as StoragePort,r as VERSION,n as applyEdits,h as applySauvolaToImageData,d as createDefaultAdapter,D as dispatchCopioEvent,p as docRepository,e as extractExif,g as fileToBase64,k as getCroppedSrc,I as getRegisteredService,y as hasActiveEdits,x as normalizeEditStack,l as normalizeEdits,f as randomId,H as registerService,m as renderEditsToCanvas,j as rotateSrc,i as thresholdSrc};
1
+ import{a as o,b as p,c as q,d as r,e as x,f as y,g as z,h as A,i as B,j as C,k as D,l as E,m as F,n as G,o as H,p as I,q as J,r as K,s as L,t as M}from"./chunk-IBF5HCYT.js";import"./chunk-4GEMGDRU.js";import{a as e,b as f,c as g,d as h,e as i,f as j,g as k,h as l,i as m,j as n,k as v}from"./chunk-G5EUMLYT.js";import{a as w}from"./chunk-KH5JE65X.js";import{a as u}from"./chunk-ULTSZWZO.js";import{c as d}from"./chunk-K4NR6OAC.js";import{d as c}from"./chunk-L4OVZN23.js";import{a as s}from"./chunk-U3V3VZGO.js";import"./chunk-6DSLE3AY.js";import{a as t}from"./chunk-5OTO5WFV.js";import"./chunk-O6FQFVKY.js";import"./chunk-ZT72PD2C.js";import{a as b}from"./chunk-FQRADJY6.js";import{a}from"./chunk-DIU5BGU5.js";import"./chunk-4C666HHU.js";export{q as BUILD_DATE,F as COPIO_EVENTS,v as Canvas2DAdapter,M as CopioEngine,I as DEFAULT_EXPORT_FORMATS,H as DEFAULT_FEATURES,J as DEFAULT_OCR_LANGUAGES,o as DocRepository,D as Document,u as ImageProcessorPort,c as IndexedDbStorageAdapter,b as MemoryStorageAdapter,w as NullImageProcessorAdapter,s as NullOcrAdapter,t as NullPdfAdapter,C as Page,E as ScanSession,a as StoragePort,r as VERSION,n as applyEdits,h as applySauvolaToImageData,d as createDefaultAdapter,A as cropOriginalToRotated,B as cropRotatedToOriginal,G as dispatchCopioEvent,p as docRepository,e as extractExif,g as fileToBase64,k as getCroppedSrc,L as getRegisteredService,y as hasActiveEdits,x as normalizeEditStack,l as normalizeEdits,f as randomId,K as registerService,m as renderEditsToCanvas,z as rotateCrop,j as rotateSrc,i as thresholdSrc};
2
2
  //# sourceMappingURL=core.js.map