@copio/sdk 0.1.5 → 0.1.6

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 (116) hide show
  1. package/THIRD_PARTY_NOTICES.md +34 -0
  2. package/dist/adapters/edge/index.js +2 -0
  3. package/dist/adapters/edge/index.js.map +7 -0
  4. package/dist/adapters/edge/null-edge-detector-adapter.js +2 -0
  5. package/dist/adapters/edge/null-edge-detector-adapter.js.map +7 -0
  6. package/dist/adapters/edge/scanic-wasm-adapter.js +2 -0
  7. package/dist/adapters/edge/scanic-wasm-adapter.js.map +7 -0
  8. package/dist/adapters/image/canvas2d-adapter.js +1 -1
  9. package/dist/adapters/image/index.js +1 -1
  10. package/dist/adapters/image/null-image-processor-adapter.js +1 -1
  11. package/dist/adapters/index.js +1 -1
  12. package/dist/adapters/indexeddb-adapter.js +1 -1
  13. package/dist/adapters/memory-adapter.js +1 -1
  14. package/dist/adapters/ocr/index.js +1 -1
  15. package/dist/adapters/ocr/null-ocr-adapter.js +1 -1
  16. package/dist/adapters/ocr/tesseract-wasm-adapter.js +1 -1
  17. package/dist/adapters/pdf/index.js +1 -1
  18. package/dist/adapters/pdf/null-pdf-adapter.js +1 -1
  19. package/dist/adapters/pdf/pdfkit-adapter.js +1 -1
  20. package/dist/adapters/storage/index.js +1 -1
  21. package/dist/adapters/storage/indexeddb-adapter.js +1 -1
  22. package/dist/adapters/storage/memory-adapter.js +1 -1
  23. package/dist/adapters/sync/index.js +1 -1
  24. package/dist/adapters/sync/null-sync-adapter.js +1 -1
  25. package/dist/adapters/sync/peerjs-adapter.js +1 -1
  26. package/dist/canvas-GKLGWNAJ.js +2 -0
  27. package/dist/cdn.js +189 -1409
  28. package/dist/chunk-25WAHT3G.js +2 -0
  29. package/dist/chunk-2VH2NPXW.js +175 -0
  30. package/dist/{chunk-DIU5BGU5.js → chunk-4D6GC55I.js} +2 -2
  31. package/dist/chunk-6QK7337A.js +2 -0
  32. package/dist/chunk-GLY5CGCY.js +2 -0
  33. package/dist/chunk-GU6OQMYK.js +4 -0
  34. package/dist/chunk-HCCNUPKB.js +2 -0
  35. package/dist/chunk-JIPKWRBK.js +2 -0
  36. package/dist/{chunk-GGERQ3CJ.js → chunk-NM4YYZYB.js} +3 -3
  37. package/dist/chunk-NNSM2I5L.js +2 -0
  38. package/dist/chunk-PBF7V4Z6.js +2 -0
  39. package/dist/chunk-PSGIWIRH.js +2 -0
  40. package/dist/chunk-Q3AWHANC.js +2 -0
  41. package/dist/chunk-R6Q4OXDG.js +2 -0
  42. package/dist/chunk-SZHKZARU.js +2 -0
  43. package/dist/{chunk-J7HWZNIP.js → chunk-T5CPA7B2.js} +2 -2
  44. package/dist/chunk-TK5N67RB.js +2 -0
  45. package/dist/chunk-V2D55DVU.js +1 -0
  46. package/dist/chunk-VPSUKD6F.js +2 -0
  47. package/dist/chunk-ZILTJGT2.js +2 -0
  48. package/dist/core.js +1 -1
  49. package/dist/custom-elements.json +2316 -135
  50. package/dist/export.js +1 -1
  51. package/dist/fs-Y7NMZRBK.js +2 -0
  52. package/dist/handoff-transport-7YFK4RYL.js +2 -0
  53. package/dist/handoff.js +2 -0
  54. package/dist/http-CYZIMVXQ.js +2 -0
  55. package/dist/https-OLG7KUSR.js +2 -0
  56. package/dist/index.js +11 -11
  57. package/dist/ocr.js +1 -1
  58. package/dist/path2d-HD3LU76S.js +2 -0
  59. package/dist/scanic-mlDetector-BCSVQYFV.js +2 -0
  60. package/dist/scanic-ort.wasm.min-MU4NYSP2.js +2 -0
  61. package/dist/scanner.js +3 -1396
  62. package/dist/sync.js +1 -1
  63. package/dist/types/js/adapters/edge/edge-detector-port.d.ts +183 -0
  64. package/dist/types/js/adapters/edge/index.d.ts +3 -0
  65. package/dist/types/js/adapters/edge/null-edge-detector-adapter.d.ts +35 -0
  66. package/dist/types/js/adapters/edge/scanic-wasm-adapter.d.ts +54 -0
  67. package/dist/types/js/adapters/storage/indexeddb-adapter.d.ts +11 -0
  68. package/dist/types/js/adapters/storage/memory-adapter.d.ts +11 -0
  69. package/dist/types/js/adapters/storage/opfs-adapter.d.ts +11 -0
  70. package/dist/types/js/adapters/storage/storage-port.d.ts +27 -0
  71. package/dist/types/js/services/doc-repository.d.ts +6 -1
  72. package/dist/types/js/services/handoff-crypto.d.ts +84 -0
  73. package/dist/types/js/services/handoff-session.d.ts +257 -0
  74. package/dist/types/js/services/handoff-transport.d.ts +51 -0
  75. package/dist/types/js/services/ice-servers.d.ts +33 -1
  76. package/dist/types/js/services/migration-runner.d.ts +100 -0
  77. package/dist/types/js/utils/perspective.d.ts +70 -0
  78. package/dist/types/js/utils/utils.d.ts +19 -1
  79. package/dist/types/sdk/core.d.ts +52 -6
  80. package/dist/types/sdk/elements.d.ts +2 -0
  81. package/dist/types/sdk/events.d.ts +42 -0
  82. package/dist/types/sdk/handoff-session.d.ts +4 -0
  83. package/dist/types/sdk/handoff-styles.d.ts +9 -0
  84. package/dist/types/sdk/handoff.d.ts +108 -0
  85. package/dist/types/sdk/index.d.ts +5 -1
  86. package/dist/types/sdk/models.d.ts +248 -1
  87. package/dist/types/sdk/scanner.d.ts +94 -1
  88. package/dist/types/sdk/styles.d.ts +1 -1
  89. package/dist/types/sdk/version.d.ts +1 -1
  90. package/dist/url-NYR4TEJV.js +2 -0
  91. package/package.json +10 -3
  92. package/sdk/core.js +219 -12
  93. package/sdk/events.js +14 -0
  94. package/sdk/handoff-session.js +26 -0
  95. package/sdk/handoff-styles.js +531 -0
  96. package/sdk/handoff.js +1079 -0
  97. package/sdk/index.js +38 -1
  98. package/sdk/models.js +116 -4
  99. package/sdk/scanner.js +1517 -151
  100. package/sdk/styles.js +297 -17
  101. package/sdk/version.js +1 -1
  102. package/dist/canvas-FAXPLPXN.js +0 -2
  103. package/dist/chunk-4C666HHU.js +0 -2
  104. package/dist/chunk-FQRADJY6.js +0 -2
  105. package/dist/chunk-G5EUMLYT.js +0 -4
  106. package/dist/chunk-K4NR6OAC.js +0 -2
  107. package/dist/chunk-L4OVZN23.js +0 -2
  108. package/dist/chunk-MEE2NNYB.js +0 -2
  109. package/dist/chunk-O7IV7A6O.js +0 -2
  110. package/dist/chunk-Q7XPZMZA.js +0 -1395
  111. package/dist/chunk-WETG2JD7.js +0 -2
  112. package/dist/fs-HJ6WWW73.js +0 -2
  113. package/dist/http-FKJJMT2N.js +0 -2
  114. package/dist/https-MUBFLDZM.js +0 -2
  115. package/dist/path2d-QWN6DFCC.js +0 -2
  116. package/dist/url-ABJ6S2Y6.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{a as c}from"./chunk-4D6GC55I.js";var a=class extends c{#e=new Map;#s=new Map;#n=new Set;#r=null;constructor(){super()}async init(){return{kind:"memory",persistent:!1}}listDocsSync(){return Array.from(this.#e.values()).map(e=>({...e,id:e.id,name:e.name,pages:Array.isArray(e.pages)?[...e.pages]:[]}))}async listDocs(){return this.listDocsSync()}getDocSync(e){let s=this.#e.get(e);return s?{...s,id:s.id,name:s.name,pages:Array.isArray(s.pages)?[...s.pages]:[]}:null}async getDoc(e){return this.getDocSync(e)}async saveDoc(e,s){if(!e)throw new Error("Cannot save document without an ID");let t=[];if(Array.isArray(s.pages))t=[...s.pages];else if(typeof s.pages=="string")try{t=JSON.parse(s.pages)}catch{t=[]}this.#e.set(e,{...s,id:e,name:s.name||"",pages:t}),this.#t()}async deleteDoc(e){this.#e.delete(e);let s=`${e}/`;for(let t of this.#s.keys())t.startsWith(s)&&this.#s.delete(t);this.#t()}async renameDoc(e,s){let t=this.#e.get(e);if(!t)throw new Error(`Document "${e}" not found`);t.name=s,this.#t()}async savePage(e,s,t){this.#s.set(`${e}/${s}`,t);let n=this.#e.get(e);if(n){let r=n.pages.findIndex(i=>i.id===s);if(r>=0)typeof t=="object"&&t!==null&&!(t instanceof Blob)?n.pages[r]={...n.pages[r],...t}:n.pages[r]={...n.pages[r],src:t};else{let i=typeof t=="object"&&t!==null&&!(t instanceof Blob)?{id:s,...t}:{id:s,src:t};n.pages.push(i)}}this.#t()}async getPage(e,s){if(this.#s.has(`${e}/${s}`))return this.#s.get(`${e}/${s}`);let t=this.#e.get(e);if(t){let n=t.pages.find(r=>r.id===s);if(n)return n.src??n}return null}async deletePage(e,s){this.#s.delete(`${e}/${s}`);let t=this.#e.get(e);t&&(t.pages=t.pages.filter(n=>n.id!==s)),this.#t()}subscribe(e){return this.#n.add(e),()=>{this.#n.delete(e)}}async getSchemaVersion(){return this.#r}async setSchemaVersion(e){this.#r=typeof e=="number"?e:null}clear(){this.#e.clear(),this.#s.clear(),this.#r=null,this.#t()}#t(){for(let e of this.#n)try{e()}catch(s){console.error("Error in MemoryStorageAdapter subscriber:",s)}}};export{a};
2
+ //# sourceMappingURL=chunk-NNSM2I5L.js.map
@@ -0,0 +1,2 @@
1
+ import{d as m}from"./chunk-YNY65JUJ.js";import{f as X,g as Y}from"./chunk-ZT72PD2C.js";import{b as te}from"./chunk-25WAHT3G.js";var ie={};te(ie,{exportDocumentAsImages:()=>ne,exportDocumentAsPdf:()=>oe});async function oe(y,l,j={}){let{onProgress:u,showProgress:I=!0,download:S=!0,searchable:p=!1,lang:L="eng",onOcrComplete:N=null}=j;if(!l||l.length===0){m.warning("No images to export");return}let a=null,c=l.length;try{I&&c>1&&(a=await m.progress({message:`Exporting "${y||"document"}.pdf"...`,total:c,done:0}));let v=null;if(typeof window<"u"&&!window.PDFDocument){typeof u=="function"&&u(0,c,"Downloading PDF engine...");try{v=await m.progress({message:"Downloading PDF engine...",total:100,done:0})}catch{}}let x;try{x=await X()}finally{v?.close()}let $=595.28,n=841.89,t=new x({autoFirstPage:!1}),g=[];t.on("data",o=>g.push(o));let b=new Promise((o,e)=>{t.on("end",()=>{try{let r=new Blob(g,{type:"application/pdf"});if(S!==!1){let i=URL.createObjectURL(r),h=document.createElement("a");h.href=i,h.download=`${y||"document"}.pdf`,h.click(),URL.revokeObjectURL(i),m.success(`Exported "${y||"document"}.pdf"`)}a?.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:y||"document",searchable:!!p}})),o(r)}catch(r){e(r)}}),t.on("error",e)});for(let o=0;o<l.length;o++){let e=l[o],r=o+1;if(e.src||e.blob){let i=new Image,h=null,f=e.src;if(e.blob instanceof Blob&&(!f||f instanceof Blob)?(f=URL.createObjectURL(e.blob),h=f):e.src instanceof Blob&&(f=URL.createObjectURL(e.src),h=f),await new Promise(d=>{i.onload=d,i.onerror=B=>{console.warn("Page image failed to load for PDF:",B),d(void 0)},i.src=f}),i.width&&i.height){t.addPage({size:"A4"});let d=$/i.width,B=n/i.height,F=Math.min(d,B),D=i.width*F,z=i.height*F,A=($-D)/2,C=(n-z)/2,P=null;if(!(typeof e.src=="string"&&e.src.startsWith("data:"))){if(e.blob instanceof Blob)P=await e.blob.arrayBuffer();else if(e.src instanceof Blob)P=await e.src.arrayBuffer();else if(typeof e.src=="string"&&e.src.startsWith("blob:"))try{P=await(await(await fetch(e.src)).blob()).arrayBuffer()}catch{}}if(P){let s=new Uint8Array(P),R=s.length>2&&s[0]===255&&s[1]===216,E=s.length>4&&s[0]===137&&s[1]===80&&s[2]===78&&s[3]===71;if(!R&&!E&&typeof document<"u"){let w=document.createElement("canvas");w.width=i.naturalWidth||i.width,w.height=i.naturalHeight||i.height;let U=w.getContext("2d");if(U){U.fillStyle="#ffffff",U.fillRect(0,0,w.width,w.height),U.drawImage(i,0,0,w.width,w.height);let k=w.toDataURL("image/jpeg",.92);t.image(k,A,C,{width:D,height:z})}w.width=0,w.height=0}else t._imageRegistry&&delete t._imageRegistry["[object ArrayBuffer]"],t.image(P,A,C,{width:D,height:z}),t._imageRegistry&&delete t._imageRegistry["[object ArrayBuffer]"]}else t.image(f,A,C,{width:D,height:z});if(p){let s=Array.isArray(e.ocrWords)&&e.ocrWords.length>0?e.ocrWords:null;if(!s&&(e.src||e.blob)){typeof u=="function"&&u(r,c,`Recognizing text for page ${r} of ${c}...`),a&&a.update({done:r,total:c,message:`Recognizing text for page ${r} of ${c}...`});try{let E=await(j.recognizeImageText||(await import("./ocr.js")).recognizeImageText)(e.blob||e.src,{lang:L});s=E?.words||[],e.ocrText=E?.text||"",e.ocrConfidence=E?.confidence??0,e.ocrWords=s,e.ocrWidth=i.width,e.ocrHeight=i.height}catch(R){console.warn(`On-demand OCR failed for page ${r}:`,R)}}if(s&&s.length>0){t.save(),t.font("Helvetica");let R=e.ocrWidth||i.width,E=e.ocrHeight||i.height,w=D/R,U=z/E;for(let k of s){let W=(k.text||"").trim();if(!W)continue;let H=k.bbox||{},T=H.x0??0,M=H.y0??0,J=Math.max(1,(H.x1??0)-T),G=Math.max(1,(H.y1??0)-M),K=A+T*w,q=C+M*U,Q=J*w,V=G*U,ee=Math.max(1,V);t.fontSize(ee);let _=t.widthOfString(W),Z=0;_>0&&W.length>1&&(Z=(Q-_)/(W.length-1)),t.text(W,K,q,{renderingMode:3,lineBreak:!1,characterSpacing:Z})}t.restore()}}}if(h)try{URL.revokeObjectURL(h)}catch{}}typeof u=="function"&&u(r,c),a&&a.update({done:r,total:c,message:`Exporting PDF: page ${r} of ${c}...`}),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-progress",{detail:{type:"pdf",done:r,total:c,docName:y||"document"}})),await new Promise(i=>setTimeout(i,0))}if(p&&typeof N=="function")try{await N(l)}catch(o){console.warn("onOcrComplete error:",o)}return t.end(),await b}catch(v){a?.close(),console.error("Error generating PDF:",v),m.error("Failed to generate PDF")}}async function ne(y,l,j={}){let{onProgress:u,showProgress:I=!0,download:S=!0}=j;if(!l||l.length===0){m.warning("No images to export");return}let p=null;try{let L=(y||"document").trim(),a=(n=>n.replace(/[/\\?%*:|"<>]/g,"_"))(L)||"document";if(l.length===1){let n=l[0],t="jpg",g="",b=!1,o=null;if(n.blob instanceof Blob)o=n.blob,o.type&&o.type.includes("png")&&(t="png"),g=URL.createObjectURL(o),b=!0;else if(n.src instanceof Blob)o=n.src,o.type&&o.type.includes("png")&&(t="png"),g=URL.createObjectURL(o),b=!0;else if(typeof n.src=="string")if(g=n.src,n.src.startsWith("data:")){let e=n.src.match(/^data:(image\/[a-zA-Z+]+);base64,/);e&&e[1].includes("png")&&(t="png");try{o=await(await fetch(n.src)).blob()}catch{o=new Blob([n.src],{type:`image/${t}`})}}else if(n.src.startsWith("blob:"))try{o=await(await fetch(n.src)).blob(),o.type&&o.type.includes("png")&&(t="png")}catch{}else try{o=await(await fetch(n.src)).blob(),g=URL.createObjectURL(o),b=!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:a}})),S!==!1){let e=document.createElement("a");e.href=g,e.download=`${a}.${t}`,e.click(),m.success(`Exported "${a}.${t}"`)}return b&&URL.revokeObjectURL(g),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-complete",{bubbles:!0,composed:!0,detail:{type:"image",format:t,blob:o,docName:a}})),o}let c=l.length;I&&c>1&&(p=await m.progress({message:`Exporting "${a}.zip"...`,total:c,done:0}));let v=await Y(),O=new v,x=0;for(let n=0;n<l.length;n++){let t=l[n],g=[t.blob||t.src],b=Math.max(2,String(l.length*g.length).length);for(let e=0;e<g.length;e++){let r=g[e],i="jpg",h=null;if(r instanceof Blob)r.type&&r.type.includes("png")&&(i="png"),h=await r.arrayBuffer();else if(typeof r=="string"&&r.startsWith("data:")){let f=r.match(/^data:(image\/[a-zA-Z+]+);base64,(.*)$/),d="";f?(f[1].includes("png")&&(i="png"),d=f[2]):d=r.replace(/^data:[^;]+;base64,/,"");let B=String(x+1).padStart(b,"0"),F=`${a}-${B}.${i}`;O.file(F,d,{base64:!0}),x++;continue}else if(typeof r=="string")try{let d=await(await fetch(r)).blob();d.type&&d.type.includes("png")&&(i="png"),h=await d.arrayBuffer()}catch{}if(h){let f=String(x+1).padStart(b,"0"),d=`${a}-${f}.${i}`;O.file(d,h),x++}}let o=n+1;typeof u=="function"&&u(o,c),p&&p.update({done:o,total:c,message:`Exporting ZIP: page ${o} of ${c}...`}),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent("copio:export-progress",{detail:{type:"zip",done:o,total:c,docName:a}})),await new Promise(e=>setTimeout(e,0))}p&&p.update({message:"Compressing archive..."});let $=await O.generateAsync({type:"blob"},n=>{p&&n.percent&&p.update({value:Math.round(n.percent),message:`Compressing ZIP: ${Math.round(n.percent)}%...`})});if(S!==!1){let n=URL.createObjectURL($),t=document.createElement("a");t.href=n,t.download=`${a}.zip`,t.click(),URL.revokeObjectURL(n),m.success(`Exported "${a}.zip"`)}return p?.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:$,docName:a}})),$}catch(L){p?.close(),console.error("Error downloading images:",L),m.error("Failed to download images")}}export{oe as a,ne as b,ie as c};
2
+ //# sourceMappingURL=chunk-PBF7V4Z6.js.map
@@ -0,0 +1,2 @@
1
+ import{d as r}from"./chunk-ZILTJGT2.js";var o=class extends r{#e=!1;constructor(e={}){super(),this.#e=!!e.throwOnDetect}async detect(e,s={}){if(this.#e){let t=new Error('Feature "edge" is disabled or EdgeDetector module not opted in');throw t.code="FEATURE_DISABLED",t}return null}async getEdgeWorker(){return null}async terminateEdgeWorker(){}};export{o as a};
2
+ //# sourceMappingURL=chunk-PSGIWIRH.js.map
@@ -0,0 +1,2 @@
1
+ import{l as T,m as z}from"./chunk-TK5N67RB.js";import{k as W,m as Q,n as R,o as G}from"./chunk-VPSUKD6F.js";import{a as g,b as _}from"./chunk-HCCNUPKB.js";import{b as C,c as U}from"./chunk-ZILTJGT2.js";import{b as O,i as $,j as N}from"./chunk-GU6OQMYK.js";import{a as P,b as D,d as B}from"./chunk-YNY65JUJ.js";import{b as j}from"./chunk-ZT72PD2C.js";var H=`:host{all:initial;display:block;position:relative;width:100%;height:100%;min-height:200px;container-type:size;container-name:copio-scanner;overflow:hidden;contain:layout;box-sizing:border-box;text-align:left;direction:ltr;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;--copio-font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;--copio-font-mono:'JetBrains Mono','SFMono-Regular',Consolas,'Liberation Mono',monospace;--copio-color-bg:#0b0f17;--copio-color-surface:#131b26;--copio-color-surface-elevated:#1c2736;--copio-color-surface-overlay:rgba(15,22,32,0.88);--copio-color-stage-bg:#070a0f;--copio-color-text:#f1f5f9;--copio-color-text-muted:#94a3b8;--copio-color-text-inverse:#090d14;--copio-color-primary:#38bdf8;--copio-color-primary-hover:#7dd3fc;--copio-color-primary-contrast:#06131f;--copio-color-success:#22c55e;--copio-color-warning:#f59e0b;--copio-color-danger:#ef4444;--copio-color-border:rgba(148,163,184,0.18);--copio-color-border-strong:rgba(148,163,184,0.34);--copio-focus-ring:0 0 2px #0b0f17,0 0 0 4px #38bdf8;--copio-radius-sm:6px;--copio-radius-md:10px;--copio-radius-lg:14px;--copio-radius-pill:9999px;--copio-spacing-xs:4px;--copio-spacing-sm:8px;--copio-spacing-md:12px;--copio-spacing-lg:16px;--copio-spacing-xl:24px;--copio-touch-target-min:44px;--copio-crop-handle-hit:48px;--copio-crop-handle-visual:16px;--copio-shadow-elevated:0 12px 32px -4px rgba(0,0,0,0.55);--copio-transition-fast:150ms cubic-bezier(0.22,1,0.36,1);--copio-transition-normal:240ms cubic-bezier(0.22,1,0.36,1);font-family:var(--copio-font-family);font-size:14px;line-height:1.5;color:var(--copio-color-text);background-color:var(--copio-color-bg);color-scheme:dark}:host([theme="dark"]),:host(.copio-theme-dark),:host-context([data-theme="dark"]),:host-context(.sl-theme-dark),:host-context(.theme-dark){color-scheme:dark}:host([theme="light"]),:host(.copio-theme-light),:host-context([data-theme="light"]),:host-context(.sl-theme-light),:host-context(.theme-light){--copio-color-bg:#f8fafc;--copio-color-surface:#ffffff;--copio-color-surface-elevated:#f1f5f9;--copio-color-surface-overlay:rgba(255,255,255,0.92);--copio-color-stage-bg:#1e293b;--copio-color-text:#0f172a;--copio-color-text-muted:#475569;--copio-color-text-inverse:#ffffff;--copio-color-primary:#0284c7;--copio-color-primary-hover:#0369a1;--copio-color-primary-contrast:#ffffff;--copio-color-success:#16a34a;--copio-color-warning:#d97706;--copio-color-danger:#dc2626;--copio-color-border:rgba(15,23,42,0.12);--copio-color-border-strong:rgba(15,23,42,0.26);--copio-focus-ring:0 0 2px #ffffff,0 0 0 4px #0284c7;--copio-radius-sm:6px;--copio-radius-md:10px;--copio-radius-lg:14px;--copio-shadow-elevated:0 12px 28px -4px rgba(15,23,42,0.18);color-scheme:light}:host([theme="brand"]),:host(.copio-theme-brand),:host-context([data-theme="brand"]),:host-context(.theme-brand){--copio-color-bg:#0f111a;--copio-color-surface:#181b28;--copio-color-surface-elevated:#23273a;--copio-color-surface-overlay:rgba(24,27,40,0.90);--copio-color-stage-bg:#090a10;--copio-color-text:#f8fafc;--copio-color-text-muted:#9ca3af;--copio-color-text-inverse:#ffffff;--copio-color-primary:#10b981;--copio-color-primary-hover:#34d399;--copio-color-primary-contrast:#042f2e;--copio-color-success:#10b981;--copio-color-warning:#f59e0b;--copio-color-danger:#ef4444;--copio-color-border:rgba(16,185,129,0.22);--copio-color-border-strong:rgba(16,185,129,0.42);--copio-focus-ring:0 0 2px #0f111a,0 0 0 4px #10b981;--copio-radius-sm:4px;--copio-radius-md:8px;--copio-radius-lg:12px;--copio-shadow-elevated:0 12px 32px -4px rgba(0,0,0,0.65);color-scheme:dark}@media (prefers-color-scheme:light){:host([theme="auto"]),:host(.copio-theme-auto){--copio-color-bg:#f8fafc;--copio-color-surface:#ffffff;--copio-color-surface-elevated:#f1f5f9;--copio-color-surface-overlay:rgba(255,255,255,0.92);--copio-color-stage-bg:#1e293b;--copio-color-text:#0f172a;--copio-color-text-muted:#475569;--copio-color-text-inverse:#ffffff;--copio-color-primary:#0284c7;--copio-color-primary-hover:#0369a1;--copio-color-primary-contrast:#ffffff;--copio-color-success:#16a34a;--copio-color-warning:#d97706;--copio-color-danger:#dc2626;--copio-color-border:rgba(15,23,42,0.12);--copio-color-border-strong:rgba(15,23,42,0.26);--copio-focus-ring:0 0 2px #ffffff,0 0 0 4px #0284c7;--copio-radius-sm:6px;--copio-radius-md:10px;--copio-radius-lg:14px;--copio-shadow-elevated:0 12px 28px -4px rgba(15,23,42,0.18);color-scheme:light}}*,*::before,*::after{box-sizing:border-box}::slotted(*){box-sizing:border-box}.copio-scanner-container{width:100%;height:100%;position:relative;display:flex;flex-direction:column;overflow:hidden;box-sizing:border-box;container-type:size;container-name:copio-scanner;contain:layout;background:var(--copio-color-bg);color:var(--copio-color-text);font-family:var(--copio-font-family);font-size:14px;line-height:1.5;text-align:left;direction:ltr;user-select:none}.copio-header{display:flex;align-items:center;justify-content:space-between;gap:var(--copio-spacing-sm);padding:var(--copio-spacing-sm) var(--copio-spacing-md);background:var(--copio-color-surface);border-bottom:1px solid var(--copio-color-border);min-height:52px;flex-shrink:0;z-index:5;box-sizing:border-box}.copio-header-left{display:flex;align-items:center;gap:var(--copio-spacing-sm);min-width:0}.copio-mode-badge{display:inline-flex;align-items:center;gap:5px;font-size:11px;font-weight:600;padding:4px 8px;border-radius:var(--copio-radius-pill);background:var(--copio-color-surface-elevated);color:var(--copio-color-primary);border:1px solid var(--copio-color-border);white-space:nowrap}.copio-title-group{display:flex;flex-direction:column;min-width:0}.copio-title{font-size:13px;font-weight:600;color:var(--copio-color-text);margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.copio-subtitle{font-size:11px;color:var(--copio-color-text-muted);margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.copio-header-actions{display:flex;align-items:center;gap:6px;flex-shrink:0}.copio-stage-tabs{display:inline-flex;background:var(--copio-color-bg);padding:2px;border-radius:var(--copio-radius-md);border:1px solid var(--copio-color-border)}.copio-stage-tab{appearance:none;border:none;background:transparent;color:var(--copio-color-text-muted);font-family:inherit;font-size:11px;font-weight:600;padding:6px 10px;min-height:var(--copio-touch-target-min);min-width:var(--copio-touch-target-min);border-radius:var(--copio-radius-sm);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;transition:background var(--copio-transition-fast),color var(--copio-transition-fast)}.copio-stage-tab[aria-selected="true"]{background:var(--copio-color-surface-elevated);color:var(--copio-color-text);box-shadow:0 1px 3px rgba(0,0,0,0.25)}.copio-btn{appearance:none;border:1px solid var(--copio-color-border);background:var(--copio-color-surface-elevated);color:var(--copio-color-text);font-family:inherit;font-size:13px;font-weight:600;min-height:var(--copio-touch-target-min);min-width:var(--copio-touch-target-min);padding:0 12px;border-radius:var(--copio-radius-md);display:inline-flex;align-items:center;justify-content:center;gap:7px;cursor:pointer;transition:all var(--copio-transition-fast);white-space:nowrap;text-decoration:none;box-sizing:border-box}.copio-btn:hover{background:var(--copio-color-primary-hover);color:var(--copio-color-primary-contrast);border-color:var(--copio-color-primary)}.copio-btn-primary{background:var(--copio-color-primary);color:var(--copio-color-primary-contrast);border-color:var(--copio-color-primary)}.copio-btn-danger{background:rgba(239,68,68,0.15);color:var(--copio-color-danger);border-color:rgba(239,68,68,0.35)}.copio-btn-danger:hover{background:var(--copio-color-danger);color:#fff}.copio-viewfinder,.copio-viewfinder-stage{position:relative;flex:1 1 auto;display:flex;flex-direction:column;justify-content:space-between;background:var(--copio-color-stage-bg);overflow:hidden;min-height:0;width:100%}.copio-viewfinder-feed,.copio-camera-feed{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:56px 20px 104px 20px;background:radial-gradient(circle at 50% 45%,#1e293b 0%,#090d14 75%)}.copio-camera-feed.is-shutter-flash::after{content:'';position:absolute;inset:0;background:#ffffff;opacity:0.75;pointer-events:none;z-index:5;animation:copio-shutter-flash 150ms ease-out forwards}@keyframes copio-shutter-flash{0%{opacity:0.75}100%{opacity:0}}.copio-framing-guide{position:relative;display:flex;align-items:center;justify-content:center;max-width:100%;max-height:100%;border:1.5px dashed rgba(56,189,248,0.55);border-radius:12px;box-shadow:0 0 9999px rgba(4,7,12,0.52);transition:all var(--copio-transition-normal);overflow:hidden}.copio-framing-guide[data-aspect="receipt"]{aspect-ratio:1 / 2.1;height:100%}.copio-framing-guide[data-aspect="card"]{aspect-ratio:1.586 / 1;width:92%;max-height:82%}.copio-framing-guide[data-aspect="a4"]{aspect-ratio:1 / 1.414;height:96%}.copio-framing-guide[data-aspect="auto"]{width:94%;height:94%}.copio-corner{position:absolute;width:22px;height:22px;border-color:var(--copio-color-primary);border-style:solid;border-width:0;pointer-events:none;z-index:2}.copio-corner.tl{top:6px;left:6px;border-top-width:3px;border-left-width:3px;border-top-left-radius:6px}.copio-corner.tr{top:6px;right:6px;border-top-width:3px;border-right-width:3px;border-top-right-radius:6px}.copio-corner.bl{bottom:6px;left:6px;border-bottom-width:3px;border-left-width:3px;border-bottom-left-radius:6px}.copio-corner.br{bottom:6px;right:6px;border-bottom-width:3px;border-right-width:3px;border-bottom-right-radius:6px}.copio-edge-quad{position:absolute;inset:12px;border:1px solid rgba(56,189,248,0.28);border-radius:8px;background:rgba(56,189,248,0.04);pointer-events:none;z-index:1}.copio-live-quad-overlay{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:10;overflow:visible}.copio-live-quad-polygon{fill:rgba(56,189,248,0.18);stroke:var(--copio-color-primary,#38bdf8);stroke-width:3;vector-effect:non-scaling-stroke;stroke-linecap:round;stroke-linejoin:round;filter:drop-shadow(0 0 6px rgba(56,189,248,0.45))}.copio-live-quad-corner{fill:#ffffff;stroke:var(--copio-color-primary,#38bdf8);stroke-width:2.5;filter:drop-shadow(0 0 4px rgba(0,0,0,0.4))}.copio-camera-feed.is-detected .copio-live-quad-polygon{fill:rgba(34,197,94,0.22);stroke:#22c55e;filter:drop-shadow(0 0 8px rgba(34,197,94,0.6))}.copio-camera-feed.is-detected .copio-live-quad-corner{stroke:#22c55e}.copio-camera-feed.is-tracking .copio-edge-quad{opacity:0.1;transition:opacity var(--copio-transition-fast)}.copio-camera-placeholder{position:relative;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;padding:16px;text-align:center;color:var(--copio-color-text-muted);font-size:12px;font-weight:500;cursor:pointer;user-select:none;transition:color var(--copio-transition-fast),transform var(--copio-transition-fast)}.copio-camera-placeholder:hover{color:var(--copio-color-text);transform:scale(1.02)}.copio-status-dot{width:7px;height:7px;border-radius:50%;background:var(--copio-color-primary);box-shadow:0 8px var(--copio-color-primary);flex-shrink:0}.copio-viewfinder-hud-top{position:relative;z-index:3;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 14px;background:linear-gradient(to bottom,rgba(7,10,15,0.85),transparent)}.copio-step-pill{display:inline-flex;align-items:center;gap:6px;padding:5px 12px;border-radius:var(--copio-radius-pill);background:rgba(15,23,42,0.88);border:1px solid rgba(56,189,248,0.45);color:#f8fafc;font-size:12px;font-weight:600;box-shadow:0 4px 12px rgba(0,0,0,0.35)}.copio-privacy-pill{display:inline-flex;align-items:center;gap:5px;padding:4px 9px;border-radius:var(--copio-radius-pill);background:rgba(22,101,52,0.35);border:1px solid rgba(34,197,94,0.4);color:#86efac;font-size:11px;font-weight:500}.copio-shutter-dock{position:relative;z-index:3;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px calc(12px + env(safe-area-inset-bottom,0)) 16px;background:var(--copio-color-surface);border-top:1px solid var(--copio-color-border);min-height:84px;flex-shrink:0}.copio-shutter-side{flex:1;display:flex;align-items:center}.copio-shutter-side.right{justify-content:flex-end}.copio-shutter-btn{appearance:none;width:64px;height:64px;border-radius:var(--copio-radius-pill);border:4px solid var(--copio-color-primary);background:transparent;padding:4px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;transition:transform var(--copio-transition-fast),border-color 150ms ease;flex-shrink:0}.copio-shutter-btn:hover{transform:scale(1.04)}.copio-shutter-btn:active{transform:scale(0.94)}.copio-shutter-btn-inner,.copio-shutter-inner{width:100%;height:100%;border-radius:var(--copio-radius-pill);background:var(--copio-color-primary);display:flex;align-items:center;justify-content:center;color:var(--copio-color-primary-contrast);transition:transform var(--copio-transition-fast)}.copio-shutter-btn:active .copio-shutter-btn-inner,.copio-shutter-btn:active .copio-shutter-inner{transform:scale(0.88)}.copio-stack-pill{display:inline-flex;align-items:center;gap:8px;min-height:var(--copio-touch-target-min);padding:4px 12px 4px 6px;border-radius:var(--copio-radius-md);background:var(--copio-color-surface-elevated);border:1px solid var(--copio-color-primary);color:var(--copio-color-text);font-size:12px;font-weight:600;cursor:pointer}.copio-stack-thumb{width:30px;height:36px;border-radius:4px;object-fit:cover;border:1px solid rgba(255,255,255,0.35);background:#000}.copio-workbench,.copio-workbench-stage{position:relative;flex:1 1 auto;display:flex;flex-direction:column;background:var(--copio-color-bg);overflow:hidden;min-height:0;width:100%}.copio-workbench-main{flex:1;display:flex;flex-direction:column;min-height:0;width:100%;overflow:hidden}.copio-stage-canvas,.copio-canvas-viewport{position:relative;flex:1 1 auto;display:flex;flex-direction:column;align-items:center;justify-content:center;overflow:hidden;padding:16px 20px 44px 20px;background:var(--copio-color-stage-bg);min-height:180px}.copio-canvas-viewport.has-card-switcher{padding-top:66px}.copio-canvas-viewport.is-cropping{padding:74px 26px 26px 26px}.copio-card-side-switcher{position:absolute;top:8px;left:50%;transform:translateX(-50%);z-index:6;display:inline-flex;gap:4px;padding:3px;background:var(--copio-color-surface-overlay,rgba(15,22,32,0.88));border:1px solid var(--copio-color-border-strong);border-radius:var(--copio-radius-pill);backdrop-filter:blur(8px)}.copio-side-pill{appearance:none;border:none;background:transparent;color:var(--copio-color-text-muted);font-family:inherit;font-size:11px;font-weight:600;padding:6px 12px;min-height:var(--copio-touch-target-min);min-width:var(--copio-touch-target-min);border-radius:var(--copio-radius-pill);cursor:pointer;display:inline-flex;align-items:center;justify-content:center}.copio-side-pill[aria-selected="true"]{background:var(--copio-color-primary);color:var(--copio-color-primary-contrast)}.copio-stage-figure,.copio-canvas-wrapper{position:relative;display:flex;align-items:center;justify-content:center;max-width:100%;max-height:100%}.copio-stage-canvas img,.copio-stage-img,.copio-stage-image{display:block;max-width:100%;max-height:100%;width:auto;height:auto;object-fit:contain;box-shadow:var(--copio-shadow-elevated);border-radius:var(--copio-radius-sm);user-select:none}.copio-crop-layer{position:absolute;inset:0;width:100%;height:100%;overflow:hidden;z-index:8;touch-action:none}.copio-crop-box{position:absolute;border:2px solid var(--copio-color-primary);box-shadow:0 0 9999px rgba(5,8,14,0.68);cursor:move;touch-action:none;box-sizing:border-box}.copio-crop-grid{position:absolute;inset:0;pointer-events:none;background-image:linear-gradient(to right,rgba(56,189,248,0.28) 1px,transparent 1px),linear-gradient(to bottom,rgba(56,189,248,0.28) 1px,transparent 1px);background-size:33.333% 33.333%}.copio-crop-handle{position:absolute;width:var(--copio-crop-handle-hit);height:var(--copio-crop-handle-hit);min-width:44px;min-height:44px;display:flex;align-items:center;justify-content:center;z-index:10;touch-action:none;box-sizing:border-box}.copio-crop-handle::after{content:'';width:var(--copio-crop-handle-visual);height:var(--copio-crop-handle-visual);border-radius:50%;background:var(--copio-color-primary);border:2.5px solid #ffffff;box-shadow:0 2px 6px rgba(0,0,0,0.5);transition:transform 120ms ease;box-sizing:border-box}.copio-crop-handle:hover::after,.copio-crop-handle:active::after{transform:scale(1.25);background:var(--copio-color-success,#22c55e)}.copio-crop-handle.nw{top:-24px;left:-24px;cursor:nwse-resize}.copio-crop-handle.ne{top:-24px;right:-24px;cursor:nesw-resize}.copio-crop-handle.sw{bottom:-24px;left:-24px;cursor:nesw-resize}.copio-crop-handle.se{bottom:-24px;right:-24px;cursor:nwse-resize}.copio-crop-handle.n,.copio-crop-handle.edge-n{top:-24px;left:calc(50% - 24px);cursor:ns-resize}.copio-crop-handle.s,.copio-crop-handle.edge-s{bottom:-24px;left:calc(50% - 24px);cursor:ns-resize}.copio-crop-handle.w,.copio-crop-handle.edge-w{left:-24px;top:calc(50% - 24px);cursor:ew-resize}.copio-crop-handle.e,.copio-crop-handle.edge-e{right:-24px;top:calc(50% - 24px);cursor:ew-resize}.copio-crop-quad-svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible}.copio-crop-mask{fill:rgba(5,8,14,0.68)}.copio-crop-quad-outline{fill:rgba(56,189,248,0.06);stroke:var(--copio-color-primary);stroke-width:2;vector-effect:non-scaling-stroke;pointer-events:auto;cursor:move}.copio-crop-quad-grid{stroke:rgba(56,189,248,0.35);stroke-width:1;vector-effect:non-scaling-stroke;pointer-events:none}.copio-quad-handle{transform:translate(-50%,-50%);cursor:grab}.copio-quad-handle:active{cursor:grabbing}.copio-crop-magnifier{position:absolute;width:96px;height:96px;border-radius:50%;border:2.5px solid var(--copio-color-primary);box-shadow:0 4px 16px rgba(0,0,0,0.55);pointer-events:none;z-index:20;display:none;background:#0b0f17;transform:translate(-50%,-125%)}.copio-filmstrip,.copio-filmstrip-bar{display:flex;align-items:center;gap:8px;padding:8px 12px;background:var(--copio-color-surface);border-top:1px solid var(--copio-color-border);overflow-x:auto;min-height:80px;flex-shrink:0;scrollbar-width:thin}.copio-filmstrip-scroll{display:flex;align-items:center;gap:8px}.copio-filmstrip-item{display:flex;flex-direction:column;align-items:center;gap:4px;flex-shrink:0}.copio-thumb-container{position:relative;width:56px;height:70px;border-radius:var(--copio-radius-sm);overflow:hidden;background:var(--copio-color-surface-elevated,#1c2736);border:2px solid var(--copio-color-border);cursor:pointer;transition:all var(--copio-transition-fast);display:flex;align-items:center;justify-content:center}.copio-filmstrip-item.is-active .copio-thumb-container{border-color:var(--copio-color-primary);box-shadow:0 0 2px rgba(56,189,248,0.25)}.copio-thumb-num{position:absolute;bottom:3px;right:3px;min-width:16px;height:16px;padding:0 4px;border-radius:999px;background:rgba(15,23,42,0.85);color:#f8fafc;font-size:10px;font-weight:700;display:inline-flex;align-items:center;justify-content:center}.copio-thumb-reorder{display:flex;align-items:center;gap:4px}.copio-reorder-btn{appearance:none;border:1px solid var(--copio-color-border);background:var(--copio-color-surface-elevated);color:var(--copio-color-text-muted);border-radius:4px;font-size:9px;padding:2px 5px;cursor:pointer}.copio-reorder-btn:disabled{opacity:0.35;cursor:not-allowed}.copio-thumb-img{max-width:100%;max-height:100%;width:auto;height:auto;object-fit:contain}.copio-toolbar,.copio-controls-dock{display:flex;flex-direction:column;gap:8px;padding:10px 12px calc(10px + env(safe-area-inset-bottom,0)) 12px;background:var(--copio-color-surface);border-top:1px solid var(--copio-color-border);min-height:56px;flex-shrink:0;z-index:6}.copio-edit-toolbar,.copio-toolbar-tools{display:flex;flex-wrap:wrap;align-items:center;gap:4px;width:100%}.copio-toolbar-tools .copio-tool-btn{flex:1 1 0;min-width:0}.copio-toolbar-actions{display:flex;align-items:center;gap:8px;width:100%;flex-shrink:0}.copio-toolbar-actions .copio-btn-primary{width:100%}.copio-tool-btn{appearance:none;border:1px solid var(--copio-color-border);background:var(--copio-color-surface-elevated);color:var(--copio-color-text);font-family:inherit;font-size:11px;font-weight:600;min-height:var(--copio-touch-target-min);min-width:var(--copio-touch-target-min);padding:4px 6px;border-radius:var(--copio-radius-md);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;cursor:pointer;transition:all var(--copio-transition-fast)}.copio-tool-btn:hover:not(:disabled){border-color:var(--copio-color-border-strong);background:rgba(255,255,255,0.06)}.copio-tool-btn[aria-pressed="true"]{background:rgba(56,189,248,0.16);color:var(--copio-color-primary);border-color:var(--copio-color-primary)}.copio-tool-btn.danger{color:#fca5a5}.copio-tool-btn.danger:hover:not(:disabled){background:rgba(239,68,68,0.16);border-color:rgba(239,68,68,0.45)}.copio-toast-region{position:absolute;bottom:124px;left:12px;right:12px;z-index:30;display:flex;flex-direction:column;gap:8px;pointer-events:none}.copio-toast{pointer-events:auto;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 12px;border-radius:var(--copio-radius-md);background:#0f172a;color:#f8fafc;border:1px solid var(--copio-color-primary);box-shadow:var(--copio-shadow-elevated);font-size:12px;font-weight:500;position:relative;overflow:hidden;transition:opacity 200ms ease-out}.copio-toast-warning{border-color:#f59e0b;background:#1c1917;color:#fef3c7}.copio-toast-info{border-color:var(--copio-color-primary);background:#0f172a;color:#f8fafc}.copio-toast-fade-out{opacity:0}.copio-toast-progress{position:absolute;bottom:0;left:0;height:3px;background:var(--copio-color-primary);transition:width 100ms linear}.copio-toast-undo-btn,.copio-btn-toast-undo{appearance:none;border:1px solid rgba(56,189,248,0.45);background:rgba(56,189,248,0.16);color:#38bdf8;font-family:inherit;font-size:12px;font-weight:700;min-height:var(--copio-touch-target-min);min-width:var(--copio-touch-target-min);padding:0 12px;border-radius:var(--copio-radius-sm);cursor:pointer;flex-shrink:0}.copio-ocr-content{display:flex;flex-direction:column;gap:8px}.copio-ocr-text{margin:0;padding:10px;max-height:180px;overflow:auto;background:var(--copio-color-bg);color:var(--copio-color-text);border:1px solid var(--copio-color-border);border-radius:var(--copio-radius-sm);font-family:var(--copio-font-mono);font-size:11px;line-height:1.5;white-space:pre-wrap}.copio-ocr-meta{font-size:11px;color:var(--copio-color-text-muted)}.copio-ocr-sheet{position:absolute;inset:auto 0 0 0;max-height:78%;background:var(--copio-color-surface);border-top:1px solid var(--copio-color-primary);border-radius:16px 16px 0 0;box-shadow:0 -16px 40px rgba(0,0,0,0.65);z-index:25;display:flex;flex-direction:column;padding:14px;gap:10px}.copio-ocr-header{display:flex;align-items:center;justify-content:space-between;gap:8px}.copio-ocr-textarea{width:100%;min-height:130px;flex:1;resize:none;background:var(--copio-color-bg);color:var(--copio-color-text);border:1px solid var(--copio-color-border);border-radius:var(--copio-radius-sm);padding:10px;font-family:var(--copio-font-mono);font-size:11px;line-height:1.5}.sl-toast-stack,.copio-toast-stack-scoped{position:absolute !important;top:auto !important;bottom:0 !important;left:0 !important;right:0 !important;width:100% !important;max-width:100% !important;padding:var(--copio-spacing-md) !important;box-sizing:border-box !important;z-index:1000 !important;pointer-events:none}.sl-toast-stack sl-alert,.copio-toast-stack-scoped sl-alert{pointer-events:auto;margin-top:var(--copio-spacing-sm)}@container copio-scanner (max-width:400px){.copio-header{padding:6px 10px;min-height:52px}.copio-header-left{flex-direction:column;align-items:flex-start;gap:2px}.copio-mode-badge{font-size:10px;padding:2px 6px}.copio-subtitle{display:none}.copio-stage-canvas,.copio-canvas-viewport{min-height:120px;padding:10px 12px 24px 12px}.copio-filmstrip,.copio-filmstrip-bar{gap:6px;padding:6px 8px;min-height:64px}.copio-toolbar,.copio-controls-dock{gap:6px;padding:8px 10px calc(8px + env(safe-area-inset-bottom,0)) 10px}.copio-tool-btn{font-size:10px;padding:3px 4px}.copio-btn{padding:0 8px;font-size:12px}}@container copio-scanner (min-width:401px) and (max-width:767px){.copio-header{padding:var(--copio-spacing-sm) var(--copio-spacing-md)}.copio-tool-btn{flex-direction:row;font-size:12px;gap:6px}}@container copio-scanner (min-width:768px){.copio-header{padding:var(--copio-spacing-md) var(--copio-spacing-lg)}.copio-workbench-main{flex-direction:row}.copio-filmstrip,.copio-filmstrip-bar{order:-1;flex-direction:column;width:168px;height:100%;border-top:none;border-right:1px solid var(--copio-color-border);overflow-y:auto;overflow-x:hidden;padding:12px}.copio-filmstrip-scroll{flex-direction:column;width:100%}.copio-thumb-container{width:112px;height:140px}.copio-toolbar,.copio-controls-dock{flex-direction:row;align-items:center;justify-content:space-between}.copio-toolbar-tools{width:auto;flex:1;gap:6px}.copio-toolbar-tools .copio-tool-btn{flex:1 1 56px;min-width:var(--copio-touch-target-min)}.copio-toolbar-actions{width:auto;min-width:200px}}.copio-handoff-pill{display:inline-flex;align-items:center;gap:6px;padding:4px 10px;background:rgba(2,132,199,0.16);border:1px solid rgba(56,189,248,0.35);border-radius:var(--copio-radius-pill);font-size:11px;font-weight:600;color:var(--copio-color-text);backdrop-filter:blur(8px)}.copio-handoff-dot{width:8px;height:8px;border-radius:50%;background:var(--copio-color-warning);display:inline-block;flex-shrink:0}.copio-handoff-dot.connected{background:var(--copio-color-success);box-shadow:0 8px rgba(34,197,94,0.6)}.copio-handoff-dot.connecting,.copio-handoff-dot.reconnecting{background:var(--copio-color-warning);animation:copio-pulse 1.4s ease-in-out infinite}.copio-handoff-dot.disconnected,.copio-handoff-dot.error{background:var(--copio-color-danger)}.copio-handoff-retry-btn{appearance:none;border:none;background:var(--copio-color-surface-elevated);color:var(--copio-color-text);font-size:10px;font-weight:600;padding:2px 6px;border-radius:var(--copio-radius-sm);cursor:pointer}.copio-handoff-progress-view,.copio-handoff-confirm{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:var(--copio-spacing-xl)}.copio-handoff-progress-view{z-index:50;background:var(--copio-color-surface-overlay,rgba(15,22,32,0.92));backdrop-filter:blur(12px)}.copio-handoff-confirm{z-index:60;background:var(--copio-color-bg)}.copio-handoff-progress-card,.copio-handoff-confirm-card{width:100%;max-width:340px;background:var(--copio-color-surface);border:1px solid var(--copio-color-border-strong);border-radius:var(--copio-radius-lg);padding:var(--copio-spacing-xl);display:flex;flex-direction:column;align-items:center;text-align:center;gap:var(--copio-spacing-md);box-shadow:var(--copio-shadow-elevated)}.copio-handoff-spinner{width:32px;height:32px;border:3px solid rgba(148,163,184,0.2);border-top-color:var(--copio-color-primary);border-radius:50%;animation:copio-spin 0.8s linear infinite}.copio-handoff-progress-title,.copio-handoff-confirm-title{font-size:16px;font-weight:700;color:var(--copio-color-text);margin:0}.copio-handoff-progress-track{width:100%;height:8px;background:var(--copio-color-surface-elevated);border-radius:var(--copio-radius-pill);overflow:hidden;border:1px solid var(--copio-color-border)}.copio-handoff-progress-bar{height:100%;background:linear-gradient(90deg,var(--copio-color-primary),#0284c7);border-radius:var(--copio-radius-pill);transition:width var(--copio-transition-fast)}.copio-handoff-progress-desc,.copio-handoff-confirm-subtitle{font-size:12px;color:var(--copio-color-text-muted);margin:0}.copio-handoff-confirm-icon{width:56px;height:56px;border-radius:50%;background:rgba(34,197,94,0.15);color:var(--copio-color-success);border:1px solid rgba(34,197,94,0.35);display:flex;align-items:center;justify-content:center}.copio-handoff-confirm-badge{display:inline-flex;align-items:center;padding:4px 12px;background:var(--copio-color-surface-elevated);border:1px solid var(--copio-color-border);border-radius:var(--copio-radius-pill);font-size:12px;font-weight:600;color:var(--copio-color-primary)}.copio-handoff-confirm-actions{width:100%;display:flex;flex-direction:column;gap:8px;margin-top:8px}`,L=null;function K(){if(L)return L;if(typeof CSSStyleSheet<"u"&&typeof Document<"u"&&"adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype)try{return L=new CSSStyleSheet,L.replaceSync(H),L}catch{return null}return null}function X(S){if(!S)return;let t=K();if(t&&"adoptedStyleSheets"in S){let e=S.adoptedStyleSheets||[];e.includes(t)||(S.adoptedStyleSheets=[...e,t])}else if(!S.querySelector("style[data-copio-encapsulated-styles]")){let e=document.createElement("style");e.setAttribute("data-copio-encapsulated-styles",""),e.textContent=H,S.appendChild(e)}}var J=typeof HTMLElement<"u"?HTMLElement:class{},q=class extends J{#t=null;#D=null;#R=null;#H=!1;#i="viewfinder";#e=0;#x=0;#P=!1;#n=!1;#g=null;#u=null;#L=0;#I=null;#q=null;#s=null;#O=!1;#h=null;#m=!0;#y="ml";#C=!0;#S=!1;#A=null;#M=!1;#Q=0;#l=null;#b=null;#T=0;#$=0;#w=0;#k=null;#r=null;#v=null;#o="idle";#N=[];#F=null;#j=0;onShutter=null;get#d(){return this.docId?this.docId:(this.#q||(this.#q=`doc_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`),this.#q)}static get observedAttributes(){return["mode","aspect","stage","doc-id","features","export-formats","ocr-languages","max-pages","asset-base","license-key","theme","ocr","pdf","handoff","relay-url","ice-servers","signaling-url","ice-transport-policy","edge-detection","edge-model","auto-crop","auto-capture"]}constructor(){super(),typeof this.attachShadow=="function"&&this.attachShadow({mode:"open"}),this.#ct()}#ct(){let t={storage:this.#D};if(typeof this.getAttribute=="function"){this.hasAttribute("features")&&(t.features=this.getAttribute("features")),this.hasAttribute("export-formats")&&(t.exportFormats=this.getAttribute("export-formats")),this.hasAttribute("ocr-languages")&&(t.ocrLanguages=this.getAttribute("ocr-languages")),this.hasAttribute("max-pages")&&(t.maxPages=this.getAttribute("max-pages")),this.hasAttribute("asset-base")&&(t.assetBase=this.getAttribute("asset-base")),this.hasAttribute("license-key")&&(t.licenseKey=this.getAttribute("license-key")),this.hasAttribute("ocr")&&(t.ocr=this.getAttribute("ocr")!=="false"),this.hasAttribute("pdf")&&(t.pdf=this.getAttribute("pdf")!=="false"),this.hasAttribute("edge-detection")&&(this.#m=this.getAttribute("edge-detection")!=="false"),this.hasAttribute("edge-model")&&(this.#y=this.getAttribute("edge-model")==="classical"?"classical":"ml"),this.hasAttribute("auto-crop")&&(this.#C=this.getAttribute("auto-crop")!=="false"),this.hasAttribute("auto-capture")&&(this.#S=this.getAttribute("auto-capture")!=="false"&&this.getAttribute("auto-capture")!==null);for(let e of["relay-url","signaling-url","ice-transport-policy"])this.hasAttribute(e)&&(t[e.replace(/-([a-z])/g,(o,i)=>i.toUpperCase())]=this.getAttribute(e));if(this.hasAttribute("ice-servers"))try{t.iceServers=JSON.parse(this.getAttribute("ice-servers"))}catch{t.iceServers=[{urls:this.getAttribute("ice-servers")}]}}this.#t=new z(t),this.#t.addEventListener(g.MIGRATION,e=>{this.dispatch(g.MIGRATION,e.detail)})}connectedCallback(){this.shadowRoot&&(X(this.shadowRoot),this.#dt()),typeof P=="function"&&typeof document<"u"&&D()===document.body&&P(this.shadowRoot?.querySelector(".copio-scanner-container")||this),typeof document<"u"&&document.addEventListener("visibilitychange",this.#G),typeof window<"u"&&window.addEventListener("pagehide",this.#K),this.#t&&(this.#t.init().catch(t=>{console.error("[CopioScanner] Engine initialization failed:",t)}),this.#R=this.#t.subscribe(async()=>{let t=await this.getPages();this.dispatch(g.PAGES_CHANGED,{pages:t,docId:this.docId}),this.#a()})),this.hasAttribute&&this.hasAttribute("asset-base")&&j(this.getAttribute("asset-base")),this.#B()&&this.#st().catch(t=>{console.warn("[CopioScanner] Handoff init error:",t)}),this.#E(),this.#a()}disconnectedCallback(){if(typeof document<"u"&&document.removeEventListener("visibilitychange",this.#G),typeof window<"u"&&window.removeEventListener("pagehide",this.#K),this.#W(),this.#f(),this.#h&&(this.#h.width=0,this.#h.height=0,this.#h=null),typeof this.#R=="function"&&(this.#R(),this.#R=null),this.#u&&(clearInterval(this.#u),this.#u=null),typeof P=="function"&&typeof document<"u"){let t=this.shadowRoot?.querySelector(".copio-scanner-container")||this;D()===t&&P(null)}}#G=()=>{typeof document<"u"&&document.visibilityState==="hidden"?this.#s&&(this.#O=!0,this.#f()):typeof document<"u"&&document.visibilityState==="visible"&&(this.#O&&this.#i==="viewfinder"&&(this.#O=!1,this.startCamera().catch(()=>{})),this.#B()&&this.#r&&!this.#r.isConnected&&this.#o!=="complete"&&this.reconnectHandoff().catch(()=>{}))};#K=()=>{this.#f()};attributeChangedCallback(t,e,o){if(!(e===o||!this.#t))switch(t){case"features":this.#t.setFeatures(o),this.#E();break;case"export-formats":this.#t.exportFormats=o,this.#E();break;case"ocr-languages":this.#t.ocrLanguages=o;break;case"asset-base":this.#t.assetBase=o;break;case"license-key":this.#t.licenseKey=o;break;case"ocr":this.#t.ocr=o!=="false",this.#E();break;case"pdf":this.#t.pdf=o!=="false",this.#E();break;case"relay-url":case"signaling-url":case"ice-transport-policy":this.#t&&(this.#t[t.replace(/-([a-z])/g,(i,r)=>r.toUpperCase())]=o);break;case"ice-servers":if(this.#t)try{this.#t.iceServers=JSON.parse(o)}catch{this.#t.iceServers=o?[{urls:o}]:null}break;case"stage":if(o==="viewfinder"||o==="workbench"){this.#i=o,o==="workbench"&&this.#f();let i=this.shadowRoot;if(i){let r=i.getElementById("viewfinder-section"),s=i.getElementById("workbench-section");r&&s&&(r.style.display=o==="viewfinder"?"flex":"none",s.style.display=o==="workbench"?"flex":"none")}this.#a()}break;case"max-pages":this.#t.maxPages=o,this.#a();break;case"mode":case"aspect":case"theme":this.#a();break;case"handoff":o&&o!=="false"?this.#st().catch(()=>{}):o==="false"&&this.#W();break;case"edge-detection":this.edgeDetection=o!=="false";break;case"edge-model":this.edgeModel=o==="classical"?"classical":"ml";break;case"auto-crop":this.autoCrop=o!=="false";break;case"auto-capture":this.autoCapture=o!=="false"&&o!==null;break}}#E(){if(typeof this.querySelectorAll!="function")return;let t=[];this.shadowRoot&&t.push(this.shadowRoot),t.push(this);for(let e of t){let o=e.querySelectorAll("copio-carousel, copio-row, copio-images");for(let i of o)"ocr"in i&&(i.ocr=this.ocrEnabled),"pdf"in i&&(i.pdf=this.pdf)}}#dt(){if(!this.shadowRoot||this.shadowRoot.innerHTML)return;let t="Align Document Inside Frame";this.aspect==="card"?t="Step 1 of 2: Capture Front of ID Card":this.mode==="batch"&&(t="Batch Capture \xB7 Page 1"),this.shadowRoot.innerHTML=`<div class="copio-scanner-container copio-scanner-host" part="scanner-root"><header class="copio-header" part="header"><div class="copio-header-left"><span class="copio-mode-badge" id="mode-badge">${(this.mode||"single").toUpperCase()}</span><div class="copio-title-group"><h2 class="copio-title" id="header-title">Copio Scanner</h2><p class="copio-subtitle" id="header-subtitle">Non-destructive mobile document scanner</p></div></div><div class="copio-header-actions" part="header-actions"><div class="copio-stage-tabs" role="tablist" aria-label="Scanner Stage"><button type="button" class="copio-stage-tab" id="tab-viewfinder" role="tab" aria-selected="true">Camera</button><button type="button" class="copio-stage-tab" id="tab-workbench" role="tab" aria-selected="false">Workbench</button></div><slot name="header-actions"></slot></div></header><div class="copio-viewfinder copio-viewfinder-stage" part="viewfinder" id="viewfinder-section"><div class="copio-viewfinder-hud-top"><div class="copio-step-pill" id="step-pill"><span class="copio-status-dot"></span><span id="step-pill-text">${t}</span></div><div class="copio-handoff-pill" id="handoff-pill" style="display:none;" title="Phone-to-Desktop Handoff"><span class="copio-handoff-dot" id="handoff-dot"></span><span class="copio-handoff-status-text" id="handoff-status-text">Paired with computer</span><button type="button" class="copio-handoff-retry-btn" id="btn-handoff-retry" style="display:none;" title="Retry connection">Retry</button></div><div class="copio-privacy-pill" title="100% Local On-Device Processing"><span>\u{1F512} 100% Local</span></div></div><div class="copio-camera-feed" id="camera-feed"><video id="camera-video" autoplay playsinline webkit-playsinline muted style="display:none; position:absolute; inset:0; width:100%; height:100%; object-fit:cover; z-index:0;"></video><svg class="copio-live-quad-overlay" id="live-quad-overlay" style="display:none;" aria-hidden="true"><polygon class="copio-live-quad-polygon" id="live-quad-polygon" points=""></polygon><circle class="copio-live-quad-corner" id="live-quad-c0" r="5"></circle><circle class="copio-live-quad-corner" id="live-quad-c1" r="5"></circle><circle class="copio-live-quad-corner" id="live-quad-c2" r="5"></circle><circle class="copio-live-quad-corner" id="live-quad-c3" r="5"></circle></svg><slot name="viewfinder"><div class="copio-framing-guide" id="framing-guide" data-aspect="${this.aspect}"><span class="copio-corner tl"></span><span class="copio-corner tr"></span><span class="copio-corner bl"></span><span class="copio-corner br"></span><div class="copio-edge-quad"></div><div class="copio-camera-placeholder"><svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg><span>Position document within guide lines</span></div></div></slot></div><div class="copio-shutter-dock" part="shutter-dock"><div class="copio-shutter-side left"><button type="button" class="copio-btn copio-btn-secondary" id="btn-import-file" title="Import image from file"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg><span>Import</span></button></div><slot name="shutter-dock"><button type="button" class="copio-shutter-btn" id="btn-shutter" aria-label="Capture page"><span class="copio-shutter-btn-inner"></span></button></slot><div class="copio-shutter-side right"><button type="button" class="copio-stack-pill" id="btn-review" title="Review pages" style="display:none;"><span id="review-pill-text">Review (0) \u2192</span></button></div></div></div><div class="copio-workbench copio-workbench-stage" part="workbench" id="workbench-section" style="display: none;"><div class="copio-workbench-main"><div class="copio-canvas-viewport" id="canvas-viewport"><div class="copio-card-side-switcher" id="card-side-switcher" style="display:none;" role="tablist" aria-label="Card side switcher"><button type="button" role="tab" class="copio-side-pill active" id="btn-card-front" aria-selected="true">1. Front Side</button><button type="button" role="tab" class="copio-side-pill" id="btn-card-back" aria-selected="false">2. Back Side</button></div><div class="copio-canvas-wrapper" id="canvas-wrapper"><img id="stage-img" class="copio-stage-image" alt="Active document page" /></div></div><div class="copio-filmstrip" id="filmstrip-tray" part="filmstrip"><div class="copio-filmstrip-scroll" id="filmstrip-scroll"><slot name="filmstrip"></slot></div></div></div><footer class="copio-toolbar" part="toolbar" id="workbench-toolbar"><div class="copio-toolbar-tools"><button type="button" class="copio-tool-btn" id="btn-retake" title="Retake page"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg><span>Retake</span></button><button type="button" class="copio-tool-btn" id="btn-crop" title="Adjust crop"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></svg><span id="crop-btn-label">Crop</span></button><button type="button" class="copio-tool-btn" id="btn-rotate" title="Rotate 90\xB0"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg><span>Rotate</span></button><button type="button" class="copio-tool-btn" id="btn-filter-bw" title="Toggle B&W filter"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 2a10 10 0 0 1 0 20z" fill="currentColor"/></svg><span>B&W</span></button><button type="button" class="copio-tool-btn" id="btn-ocr" title="Recognize text"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 7V4h16v3M9 20h6M12 4v16"/></svg><span>OCR</span></button><button type="button" class="copio-tool-btn copio-btn-danger" id="btn-delete" title="Delete active page"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg><span>Delete</span></button></div><div class="copio-toolbar-actions"><slot name="toolbar"><button type="button" class="copio-btn copio-btn-primary" id="btn-primary-complete"> \u2713 Use Photo </button></slot></div></footer><div class="copio-ocr-sheet" id="ocr-sheet" style="display:none;" part="ocr-sheet"><div class="copio-ocr-header"><strong class="copio-ocr-title">Text Recognition (OCR)</strong><button type="button" class="copio-btn copio-btn-secondary" id="btn-close-ocr">\u2715</button></div><div class="copio-ocr-body" id="ocr-body"><p class="copio-ocr-placeholder">Select text or extract full page data...</p></div></div><div class="copio-toast-region" id="toast-region" aria-live="polite"></div></div><div class="copio-handoff-progress-view" id="handoff-progress-view" style="display: none;" part="handoff-progress"><div class="copio-handoff-progress-card"><div class="copio-handoff-spinner"></div><h4 class="copio-handoff-progress-title" id="handoff-progress-title">Sending to your computer\u2026</h4><div class="copio-handoff-progress-track"><div class="copio-handoff-progress-bar" id="handoff-progress-bar" style="width: 0%;"></div></div><p class="copio-handoff-progress-desc" id="handoff-progress-desc">Encrypting and streaming pages\u2026</p></div></div><div class="copio-handoff-confirm" id="handoff-confirm-view" style="display: none;" part="handoff-confirm"><div class="copio-handoff-confirm-card"><div class="copio-handoff-confirm-icon"><svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M20 6L9 17l-5-5"/></svg></div><h3 class="copio-handoff-confirm-title">Sent to your computer</h3><p class="copio-handoff-confirm-subtitle">You can close this tab now.</p><div class="copio-handoff-confirm-badge" id="handoff-confirm-count">1 page transferred</div><div class="copio-handoff-confirm-actions"><button type="button" class="copio-btn copio-btn-secondary" id="btn-handoff-scan-more"> Scan More Documents </button></div></div></div><input type="file" id="internal-file-input" accept="image/*" style="display: none;" /><slot></slot></div>`,this.#lt()}#lt(){let t=this.shadowRoot;if(!t)return;t.getElementById("tab-viewfinder")?.addEventListener("click",()=>{this.stage="viewfinder"}),t.getElementById("tab-workbench")?.addEventListener("click",()=>{this.stage="workbench"});let e=t.getElementById("internal-file-input");t.getElementById("btn-import-file")?.addEventListener("click",()=>{e?.click()}),e?.addEventListener("change",async o=>{let i=o.target;i.files&&i.files.length>0&&(await this.addFiles(i.files),i.value="")}),t.getElementById("btn-shutter")?.addEventListener("click",async()=>{await this.#tt()}),t.getElementById("camera-feed")?.addEventListener("click",async o=>{o.target&&o.target.closest("button, input, a, select")||!this.#s&&this.#i==="viewfinder"&&await this.startCamera().catch(()=>{})}),t.getElementById("btn-review")?.addEventListener("click",()=>{this.stage="workbench"}),t.getElementById("btn-retake")?.addEventListener("click",()=>{this.#P=!0,this.#n=!1,this.stage="viewfinder"}),t.getElementById("btn-rotate")?.addEventListener("click",async()=>{await this.#et()}),t.getElementById("btn-filter-bw")?.addEventListener("click",async()=>{await this.#ot()}),t.getElementById("btn-crop")?.addEventListener("click",async()=>{await this.#U()}),t.getElementById("btn-delete")?.addEventListener("click",async()=>{await this.#it()}),t.getElementById("btn-ocr")?.addEventListener("click",async()=>{await this.#xt()}),t.getElementById("btn-close-ocr")?.addEventListener("click",()=>{this.#yt()}),t.getElementById("btn-primary-complete")?.addEventListener("click",async()=>{await this.#rt()}),t.getElementById("btn-handoff-retry")?.addEventListener("click",()=>{this.reconnectHandoff().catch(()=>{})}),t.getElementById("btn-handoff-scan-more")?.addEventListener("click",async()=>{await this.resetHandoff()}),t.getElementById("btn-card-front")?.addEventListener("click",()=>{this.#n=!1,this.#e=0,this.#a()}),t.getElementById("btn-card-back")?.addEventListener("click",()=>{this.#n=!1,this.#e=1,this.#a()}),this.#X()}#X(){let t=this.shadowRoot;if(!t)return;let e=t.getElementById("crop-quad-outline"),o=t.querySelectorAll(".copio-crop-handle");if(!e||o.length===0)return;let i=null,r=!1,s=0,n=0,a=null,c=(d,m)=>{let u=t.getElementById("crop-magnifier"),y=t.getElementById("stage-img");if(!u||!y||!y.complete||!y.naturalWidth)return;u.style.display="block",u.style.left=`${(d*100).toFixed(2)}%`,u.style.top=`${(m*100).toFixed(2)}%`,u.style.transform=m<.25?"translate(-50%, 35%)":"translate(-50%, -125%)";let f=u.getContext("2d");if(!f)return;let x=2,w=u.width,b=u.height,v=y.naturalWidth,I=y.naturalHeight,A=w/x,M=b/x,F=d*v,E=m*I;f.clearRect(0,0,w,b),f.fillStyle="#0b0f17",f.fillRect(0,0,w,b),f.drawImage(y,F-A/2,E-M/2,A,M,0,0,w,b),f.strokeStyle="rgba(56, 189, 248, 0.9)",f.lineWidth=1.5,f.beginPath(),f.moveTo(w/2-10,b/2),f.lineTo(w/2+10,b/2),f.moveTo(w/2,b/2-10),f.lineTo(w/2,b/2+10),f.stroke()},l=()=>{let d=t.getElementById("crop-magnifier");d&&(d.style.display="none")},p=d=>{let m=d.target.closest(".copio-crop-handle");if(m)i=m.getAttribute("data-corner"),r=!1;else if(d.target===e)i=null,r=!0;else return;d.preventDefault(),d.stopPropagation(),s=d.clientX,n=d.clientY,a=this.#g?C(this.#g):{topLeft:{x:.05,y:.05},topRight:{x:.95,y:.05},bottomRight:{x:.95,y:.95},bottomLeft:{x:.05,y:.95}},i&&a[i]&&c(a[i].x,a[i].y),window.addEventListener("pointermove",k),window.addEventListener("pointerup",h)},k=d=>{if(!i&&!r||!a)return;let u=(t.getElementById("canvas-wrapper")||t.getElementById("canvas-viewport"))?.getBoundingClientRect()||{width:300,height:400},y=(d.clientX-s)/Math.max(u.width,1),f=(d.clientY-n)/Math.max(u.height,1),x=C(a),w=["topLeft","topRight","bottomRight","bottomLeft"];if(r){let b=-1/0,v=1/0,I=-1/0,A=1/0;for(let E of w)b=Math.max(b,-a[E].x),v=Math.min(v,1-a[E].x),I=Math.max(I,-a[E].y),A=Math.min(A,1-a[E].y);let M=Math.min(Math.max(y,b),v),F=Math.min(Math.max(f,I),A);for(let E of w)x[E].x=a[E].x+M,x[E].y=a[E].y+F}else if(i&&x[i]){let b=Math.min(Math.max(0,a[i].x+y),1),v=Math.min(Math.max(0,a[i].y+f),1);x[i].x=b,x[i].y=v,c(b,v)}this.#g=x,this.#J()},h=()=>{i=null,r=!1,a=null,l(),window.removeEventListener("pointermove",k),window.removeEventListener("pointerup",h)};e.addEventListener("pointerdown",p),o.forEach(d=>{d.addEventListener("pointerdown",p)})}#J(){let t=this.shadowRoot;if(!t||!this.#g)return;let{topLeft:e,topRight:o,bottomRight:i,bottomLeft:r}=this.#g,s=h=>`${(h.x*100).toFixed(2)},${(h.y*100).toFixed(2)}`,n=`${s(e)} ${s(o)} ${s(i)} ${s(r)}`,a=t.getElementById("crop-quad-mask");a&&a.setAttribute("d",`M0,0 H100 V100 H0 Z M${(e.x*100).toFixed(2)},${(e.y*100).toFixed(2)} L${(o.x*100).toFixed(2)},${(o.y*100).toFixed(2)} L${(i.x*100).toFixed(2)},${(i.y*100).toFixed(2)} L${(r.x*100).toFixed(2)},${(r.y*100).toFixed(2)} Z`);let c=t.getElementById("crop-quad-outline");c&&c.setAttribute("points",n);let l=(h,d,m)=>({x:h.x+(d.x-h.x)*m,y:h.y+(d.y-h.y)*m}),p=(h,d,m)=>{let u=t.getElementById(h);u&&(u.setAttribute("x1",(d.x*100).toFixed(2)),u.setAttribute("y1",(d.y*100).toFixed(2)),u.setAttribute("x2",(m.x*100).toFixed(2)),u.setAttribute("y2",(m.y*100).toFixed(2)))};p("crop-grid-v1",l(e,o,1/3),l(r,i,1/3)),p("crop-grid-v2",l(e,o,2/3),l(r,i,2/3)),p("crop-grid-h1",l(e,r,1/3),l(o,i,1/3)),p("crop-grid-h2",l(e,r,2/3),l(o,i,2/3));let k={topLeft:e,topRight:o,bottomRight:i,bottomLeft:r};for(let[h,d]of Object.entries(k)){let m=t.querySelector(`.copio-quad-handle[data-corner="${h}"]`);m&&(m.style.left=`${(d.x*100).toFixed(2)}%`,m.style.top=`${(d.y*100).toFixed(2)}%`)}}async#a(){if(this.shadowRoot)return this.#I?this.#I:(this.#I=(async()=>{try{await Promise.resolve(),await this.#pt()}finally{this.#I=null}})(),this.#I)}async#pt(){if(this.shadowRoot)try{let t=await this.getPages();this.#x=t.length;let e=this.shadowRoot,o=e.getElementById("mode-badge");o&&(o.textContent=(this.mode||"single").toUpperCase());let i=e.getElementById("tab-viewfinder"),r=e.getElementById("tab-workbench");i&&i.setAttribute("aria-selected",String(this.#i==="viewfinder")),r&&r.setAttribute("aria-selected",String(this.#i==="workbench"));let s=e.getElementById("viewfinder-section"),n=e.getElementById("workbench-section");s&&n&&(this.#i==="viewfinder"?(s.style.display="flex",n.style.display="none"):(s.style.display="none",n.style.display="flex"));let a=e.getElementById("framing-guide");a&&a.setAttribute("data-aspect",this.aspect||"auto");let c=e.getElementById("step-pill-text");c&&(this.#s?c.textContent=this.mode==="batch"?`Batch Capture \xB7 Page ${t.length+1}`:"Camera Active \xB7 Tap Shutter to Snap":this.aspect==="card"&&this.maxPages===2?c.textContent=t.length===0?"Step 1 of 2: Capture Front of ID Card":"Step 2 of 2: Capture Back of ID Card":this.aspect==="card"?c.textContent="Align Card Inside Frame":this.mode==="batch"?c.textContent=`Batch Capture \xB7 Page ${t.length+1}`:c.textContent="Align Document Inside Frame");let l=e.getElementById("btn-ocr");l&&(l.style.display=this.ocrEnabled&&this.hasFeature("ocr")?"":"none");let p=e.getElementById("btn-review"),k=e.getElementById("review-pill-text");if(p&&k&&(t.length>0?(p.style.display="inline-flex",k.textContent=`Review (${t.length}) \u2192`):p.style.display="none"),t.length===0){this.#i==="workbench"&&(this.stage="viewfinder");return}this.#e>=t.length&&(this.#e=Math.max(0,t.length-1));let h=t[this.#e],d=e.getElementById("card-side-switcher");if(d){let w=this.aspect==="card"&&this.maxPages===2;d.style.display=w?"flex":"none";let b=e.getElementById("btn-card-front"),v=e.getElementById("btn-card-back");b&&(b.classList.toggle("active",this.#e===0),b.setAttribute("aria-selected",String(this.#e===0))),v&&(v.classList.toggle("active",this.#e===1),v.setAttribute("aria-selected",String(this.#e===1)))}let m=e.getElementById("canvas-viewport");m&&m.classList.toggle("is-cropping",this.#n);let u=e.getElementById("stage-img");if(u)if(this.#n){let w=h.edits?.rotate||0,b=h.edits?.filter||"none",v=h.originalSrc||h.src||"";if(w!==0||b!=="none"){let I=this.#t?await this.#t.renderEdits(v,{rotate:w,filter:b}):v;u.src=I||v}else u.src=v}else u.src=h.src||h.originalSrc||"";let y=e.getElementById("crop-layer");if(this.#n){if(!y){let v=e.getElementById("canvas-wrapper");y=document.createElement("div"),y.className="copio-crop-layer",y.id="crop-layer",y.innerHTML='<svg class="copio-crop-quad-svg" id="crop-quad-svg" viewBox="0 0 100 100" preserveAspectRatio="none"><path class="copio-crop-mask" id="crop-quad-mask" fill-rule="evenodd" d=""></path><line class="copio-crop-quad-grid" id="crop-grid-v1"></line><line class="copio-crop-quad-grid" id="crop-grid-v2"></line><line class="copio-crop-quad-grid" id="crop-grid-h1"></line><line class="copio-crop-quad-grid" id="crop-grid-h2"></line><polygon class="copio-crop-quad-outline" id="crop-quad-outline" points=""></polygon></svg><span class="copio-crop-handle copio-quad-handle" data-corner="topLeft" data-handle="nw"></span><span class="copio-crop-handle copio-quad-handle" data-corner="topRight" data-handle="ne"></span><span class="copio-crop-handle copio-quad-handle" data-corner="bottomRight" data-handle="se"></span><span class="copio-crop-handle copio-quad-handle" data-corner="bottomLeft" data-handle="sw"></span><canvas class="copio-crop-magnifier" id="crop-magnifier" width="96" height="96"></canvas>',v?.appendChild(y),this.#X()}y.style.display="block";let w=h.edits?.rotate||0,b=h.edits?.quad||(h.edits?.crop?O(h.edits.crop):null)||{topLeft:{x:.05,y:.05},topRight:{x:.95,y:.05},bottomRight:{x:.95,y:.95},bottomLeft:{x:.05,y:.95}};this.#g=$(b,w),this.#J()}else y&&y.remove();let f=e.getElementById("crop-btn-label");f&&(f.textContent=this.#n?"Apply":"Crop");let x=e.getElementById("btn-primary-complete");x&&(this.isHandoff?this.aspect==="card"&&this.maxPages===2&&t.length===1?x.textContent="Next: Capture Back (Step 2/2) \u2192":this.aspect==="card"&&t.length>=2?x.textContent="\u2191 Send ID Card to Computer (2 Sides)":this.mode==="batch"?x.textContent=`\u2191 Send ${t.length} Pages to Computer`:x.textContent="\u2191 Send to Computer":this.aspect==="card"&&this.maxPages===2&&t.length===1?x.textContent="Next: Capture Back (Step 2/2) \u2192":this.aspect==="card"&&t.length>=2?x.textContent="\u2713 Complete ID Scan (2 Sides)":this.mode==="batch"?x.textContent=`\u2713 Complete Scan (${t.length} Pages)`:x.textContent="\u2713 Use Photo"),this.#p(),this.#ht(t)}catch{}}#ht(t){let e=this.shadowRoot;if(!e)return;let o=e.getElementById("filmstrip-scroll");o&&(o.innerHTML="",t.forEach((i,r)=>{let s=document.createElement("div");s.className=`copio-filmstrip-item ${r===this.#e?"is-active":""}`,s.setAttribute("data-index",String(r)),s.innerHTML=`<div class="copio-thumb-container"><img src="${i.src||i.originalSrc}" alt="Page ${r+1}" class="copio-thumb-img" /><span class="copio-thumb-num">${r+1}</span></div> ${this.mode==="batch"?` <div class="copio-thumb-reorder"><button type="button" class="copio-reorder-btn move-left" title="Move Left" ${r===0?"disabled":""}>\u25C0</button><button type="button" class="copio-reorder-btn move-right" title="Move Right" ${r===t.length-1?"disabled":""}>\u25B6</button></div> `:""}`,s.querySelector(".copio-thumb-container")?.addEventListener("click",()=>{this.#e=r,this.#n=!1,this.#a()}),this.mode==="batch"&&(s.querySelector(".move-left")?.addEventListener("click",async n=>{n.stopPropagation(),await this.#Y(r,r-1)}),s.querySelector(".move-right")?.addEventListener("click",async n=>{n.stopPropagation(),await this.#Y(r,r+1)})),o.appendChild(s)}))}async#Y(t,e){let o=await this.getPages();if(e<0||e>=o.length||t===e)return;let i=o.map(s=>s.id),[r]=i.splice(t,1);i.splice(e,0,r),await this.#t.reorderPages(this.#d,i),this.#e=e,this.#a()}#ft(t,e="warning",o=4e3){try{if(typeof B<"u"){let n=this.shadowRoot?.querySelector(".copio-scanner-container")||this;e==="warning"&&typeof B.warning=="function"?B.warning(t,{container:n}):typeof B.info=="function"&&B.info(t,{container:n})}}catch{}let r=this.shadowRoot?.getElementById("toast-region");if(!r)return;let s=document.createElement("div");s.className=`copio-toast copio-toast-${e}`,s.setAttribute("role","alert"),s.innerHTML=`<span class="copio-toast-msg">${t}</span>`,r.appendChild(s),setTimeout(()=>{s.classList.add("copio-toast-fade-out"),setTimeout(()=>{s.remove()},250)},o)}#Z(t,e){let i=t?.name==="NotAllowedError"||t?.name==="PermissionDeniedError"?"CAMERA_PERMISSION_DENIED":"CAMERA_UNAVAILABLE";this.#ft(e,"warning");let r=this.shadowRoot?.getElementById("step-pill-text");r&&(r.textContent="Camera Unavailable \xB7 Select File"),this.dispatch(g.ERROR,{code:i,message:e,error:t});let s=this.shadowRoot?.getElementById("internal-file-input");s&&typeof s.click=="function"&&s.click()}#f(){if(this.#z(),this.#_(),this.#s){try{let r=this.#s.getTracks();for(let s of r)s.stop()}catch{}this.#s=null}let t=this.shadowRoot,e=t?.getElementById("camera-video");if(e){try{e.pause()}catch{}e.srcObject=null,e.style.display="none"}let o=t?.querySelector(".copio-camera-placeholder");o&&(o.style.display="");let i=t?.getElementById("step-pill-text");i&&this.#i==="viewfinder"&&(i.textContent=this.mode==="batch"?`Batch Capture \xB7 Page ${this.#x+1}`:"Align Document Inside Frame")}async startCamera(t={}){if(!this.shadowRoot?.getElementById("camera-video"))return null;if(this.#s)return this.#s;if(typeof window<"u"&&window.__WTR_CONFIG__!==void 0&&typeof navigator<"u"&&navigator.webdriver===!0&&!t.force)return null;if(typeof navigator>"u"||!navigator.mediaDevices?.getUserMedia)return this.#Z(new Error("NO_CAMERA_SUPPORT"),"No camera found. Choose a photo from your files instead."),null;let r=[{video:{facingMode:{ideal:"environment"},width:{ideal:1280},height:{ideal:720}},audio:!1},{video:{facingMode:{ideal:"environment"}},audio:!1},{video:{width:{ideal:1280}},audio:!1},{video:!0,audio:!1}],s=null,n=null;for(let a of r)try{if(s=await navigator.mediaDevices.getUserMedia(a),s)break}catch(c){if(n=c,c.name==="NotAllowedError"||c.name==="PermissionDeniedError")break}if(!s){let c=n?.name==="NotAllowedError"||n?.name==="PermissionDeniedError"?"Camera permission denied. Choose a photo from your files instead.":"Camera unavailable. Choose a photo from your files instead.";return this.#Z(n||new Error("CAMERA_UNAVAILABLE"),c),null}return this.setCameraStream(s),s}stopCamera(){this.#f()}_grabFrame(t={}){let o=this.shadowRoot?.getElementById("camera-video");if(!this.#s||!o)return null;let i=o.videoWidth||640,r=o.videoHeight||480;if(i===0||r===0)return null;let s=t.maxWidth||640,n=t.maxHeight||480,a=Math.min(1,s/i,n/r),c=Math.max(1,Math.round(i*a)),l=Math.max(1,Math.round(r*a));if(!this.#h&&typeof document<"u"&&(this.#h=document.createElement("canvas")),!this.#h)return null;this.#h.width=c,this.#h.height=l;let p=this.#h.getContext("2d",{willReadFrequently:!0});if(!p)return null;try{p.drawImage(o,0,0,c,l)}catch{p.fillStyle="#334155",p.fillRect(0,0,c,l)}return t.format==="canvas"?this.#h:p.getImageData(0,0,c,l)}_isCameraActive(){return!!this.#s}#V(){if(this.#z(),!this.#m||!this.#s||this.#i!=="viewfinder")return;let t=async e=>{if(!this.#s||this.#i!=="viewfinder"||!this.#m){this.#z();return}let o=e-this.#Q;!this.#M&&o>=100&&(this.#Q=e,await this.#ut(e)),this.#s&&this.#i==="viewfinder"&&this.#m&&(this.#A=requestAnimationFrame(t))};this.#A=requestAnimationFrame(t)}#z(){this.#A!==null&&(cancelAnimationFrame(this.#A),this.#A=null),this.#M=!1}#_(){let t=this.shadowRoot,e=t?.getElementById("live-quad-overlay");e&&(e.style.display="none");let o=t?.getElementById("camera-feed");o&&o.classList.remove("is-detected","is-tracking");let i=t?.getElementById("live-quad-polygon");i&&i.setAttribute("points","");for(let r=0;r<4;r++){let s=t?.getElementById(`live-quad-c${r}`);s&&(s.removeAttribute("cx"),s.removeAttribute("cy"))}this.#l=null,this.#b=null,this.#T=0,this.#$=0,this.#w=0,this.#k=null}#gt(t,e){let o=this.shadowRoot,i=o?.getElementById("live-quad-overlay"),r=o?.getElementById("camera-feed"),s=o?.getElementById("camera-video");if(!i||!r||!t)return;let n=r.clientWidth,a=r.clientHeight;if(n<=0||a<=0)return;let c=s?.videoWidth||640,l=s?.videoHeight||480,p=Math.max(n/c,a/l),k=c*p,h=l*p,d=(n-k)/2,m=(a-h)/2,u=[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft],y=u.map(f=>`${(d+f.x*k).toFixed(1)},${(m+f.y*h).toFixed(1)}`);i.setAttribute("viewBox",`0 0 ${n} ${a}`),i.style.display="block",o.getElementById("live-quad-polygon")?.setAttribute("points",y.join(" "));for(let f=0;f<4;f++){let x=o.getElementById(`live-quad-c${f}`);x&&(x.setAttribute("cx",(d+u[f].x*k).toFixed(1)),x.setAttribute("cy",(m+u[f].y*h).toFixed(1)))}r.classList.add("is-tracking"),r.classList.toggle("is-detected",e>=.7)}async#ut(t){let o=this.shadowRoot?.getElementById("camera-video");if(!o||o.videoWidth===0||o.videoHeight===0)return;let i=this._grabFrame({maxWidth:480,maxHeight:480});if(i){this.#M=!0;try{let r=this.#t?.getService("edge")||T("edge");if(!r||typeof r.detect!="function")return;let s=this.#y==="ml"?.4:.45,n=await r.detect(i,{maxProcessingDimension:480,enableDetectionCascade:!1,minConfidence:s,fallbackOnLowConfidence:!1,detector:this.#y,ml:{minScore:s}});if(!this.#s||this.#i!=="viewfinder"||!this.#m)return;if(n&&n.quad&&n.confidence>=s&&!n.isFallback){this.#T=0,this.#$=t;let a=.35;if(!this.#l)this.#l=C(n.quad);else for(let c of["topLeft","topRight","bottomRight","bottomLeft"])this.#l[c].x=a*n.quad[c].x+(1-a)*this.#l[c].x,this.#l[c].y=a*n.quad[c].y+(1-a)*this.#l[c].y;this.#b={quad:C(this.#l),confidence:n.confidence,durationMs:n.durationMs,isFallback:!1},this.#gt(this.#l,n.confidence),this.dispatch(g.EDGE_DETECTED,{quad:C(this.#l),confidence:n.confidence,durationMs:n.durationMs}),this.#S&&n.confidence>=.65&&this.#mt(this.#l,t)}else this.#T++,this.#T>4&&t-this.#$>1200&&(this.#l=null,this.#b=null,this.#w=0,this.#_())}catch(r){typeof console<"u"&&console.warn&&console.warn("[CopioScanner] Live edge detection error:",r)}finally{this.#M=!1}}}#mt(t,e){if(!this.#S||!t)return;let o=[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft],i=0;for(let n=0;n<4;n++){let a=(n+1)%4;i+=o[n].x*o[a].y-o[a].x*o[n].y}if(i=Math.abs(i)/2,i<.15){this.#w=0,this.#k=null;return}if(!this.#k){this.#k=C(t),this.#w=e;return}let r=0;for(let n of["topLeft","topRight","bottomRight","bottomLeft"]){let a=t[n].x-this.#k[n].x,c=t[n].y-this.#k[n].y;r+=a*a+c*c}let s=Math.sqrt(r/4);this.#k=C(t),s<.015?e-this.#w>=600&&(this.#w=e+1e4,this.#tt()):this.#w=e}async#tt(){if(typeof this.onShutter=="function"&&await this.onShutter()!==!1)return;let t=this.shadowRoot,e=t?.getElementById("camera-video");if(this.#s&&e){let r=t?.getElementById("camera-feed");r&&(r.classList.remove("is-shutter-flash"),r.offsetWidth,r.classList.add("is-shutter-flash"));let s=this.#y==="ml"?.4:.45,n=this.#b?.confidence>=s?C(this.#b.quad):null,a=document.createElement("canvas");a.width=e.videoWidth||1280,a.height=e.videoHeight||720;let c=a.getContext("2d");if(c){try{c.drawImage(e,0,0,a.width,a.height)}catch{c.fillStyle="#334155",c.fillRect(0,0,a.width,a.height)}let l=await new Promise(p=>a.toBlob(p,"image/jpeg",.92));if(a.width=0,a.height=0,l){let p=this.mode==="batch";p||this.#f();let k=new File([l],`capture_${Date.now()}.jpg`,{type:"image/jpeg"});await this.addFiles([k],{prefilledQuad:n}),!p&&n&&this.#C&&this.features.includes("crop")&&(this.#n=!0,await this.#a()),p&&this.maxPages>0&&this.#x>=this.maxPages&&(this.#f(),this.stage="workbench");return}}}if(await this.startCamera())return;let i=t?.getElementById("internal-file-input");i&&typeof i.click=="function"&&i.click()}async#et(){let e=(await this.getPages())[this.#e];if(!e)return;this.#n&&(this.#n=!1,this.#g=null);let i=((e.edits?.rotate||0)+90)%360;await this.#t.applyEdit(this.#d,e.id,{rotate:i}),await this.#a()}async#ot(){let e=(await this.getPages())[this.#e];if(!e)return;this.#n&&(this.#n=!1,this.#g=null);let i=(e.edits?.filter||"none")==="bw"?"none":"bw";await this.#t.applyEdit(this.#d,e.id,{filter:i}),await this.#a()}async#U(){let e=(await this.getPages())[this.#e];if(e){if(this.#n){this.#n=!1;let o=this.#g;if(this.#g=null,o){let i=e.edits?.rotate||0,r=N(o,i),s=U(r);await this.#t.applyEdit(this.#d,e.id,{quad:r,crop:s})}}else this.#n=!0;await this.#a()}}async#it(){let t=await this.getPages(),e=t[this.#e];if(!e)return;let o=e.id;await this.#t.deletePage(this.#d,o),this.dispatch(g.PAGE_REMOVED,{pageId:o,docId:this.docId}),this.#e>=t.length-1&&(this.#e=Math.max(0,t.length-2)),this.#bt(),await this.#a()}#bt(){let t=this.shadowRoot;if(!t)return;let e=t.getElementById("toast-region");if(!e)return;this.#u&&clearInterval(this.#u),this.#L=5;let o=()=>{e.innerHTML=`<div class="copio-toast copio-toast-undo"><span>Page deleted</span><button type="button" class="copio-btn-toast-undo" id="btn-toast-undo"> Undo (${this.#L}s) </button></div>`,t.getElementById("btn-toast-undo")?.addEventListener("click",async()=>{clearInterval(this.#u),this.#u=null,e.innerHTML="",await this.#t.undo(this.#d),await this.#a()})};o(),this.#u=setInterval(()=>{this.#L-=1,this.#L<=0?(clearInterval(this.#u),this.#u=null,e.innerHTML=""):o()},1e3)}async#xt(){let t=this.shadowRoot;if(!t)return;let e=t.getElementById("ocr-sheet"),o=t.getElementById("ocr-body");if(!(!e||!o)){e.style.display="block",o.innerHTML='<p class="copio-ocr-loading">Recognizing text...</p>';try{let r=(await this.getPages())[this.#e],s=await this.ocr(r?.id||null),n=s.averageConfidence||0,a=n<=1&&n>0?Math.round(n*100):Math.round(n);o.innerHTML=`<div class="copio-ocr-content"><pre class="copio-ocr-text">${s.text||"No text detected."}</pre><div class="copio-ocr-meta"><span>Confidence: ${a}%</span></div></div>`}catch(i){o.innerHTML=`<p class="copio-ocr-error">OCR recognition failed: ${i.message}</p>`}}}#yt(){let t=this.shadowRoot;if(!t)return;let e=t.getElementById("ocr-sheet");e&&(e.style.display="none")}async#rt(){if(this.#n&&await this.#U(),this.aspect==="card"&&this.maxPages===2&&this.#x===1){this.stage="viewfinder";return}let t=await this.getPages();if(this.aspect==="card"&&this.maxPages===2&&t.length===1){this.stage="viewfinder";return}let e=t.map((i,r)=>({id:i.id,pageNumber:r+1,label:i.label||`Page ${r+1}`,originalSrc:i.originalSrc,src:i.src,originalPreserved:!0,dimensions:{width:i.width||0,height:i.height||0},edits:i.edits||{crop:{x:0,y:0,w:1,h:1},rotate:0,filter:"none"},ocrText:i.ocrText||null,blob:i.blob||null})),o={mode:this.mode,aspect:this.aspect,docId:this.docId,pageCount:e.length,pages:e};if(this.mode==="single"&&(o.page=e[0]||null,this.maxPages>1&&(o.maxPages=this.maxPages)),this.isHandoff&&this.#r){await this.#wt(e,o);return}this.dispatch(g.SCAN_COMPLETE,o)}async completeScan(){return this.#rt()}get handoff(){return typeof this.getAttribute=="function"?this.getAttribute("handoff"):null}set handoff(t){typeof this.setAttribute=="function"&&(t!=null&&(typeof t!="boolean"||t===!0)?this.setAttribute("handoff",typeof t=="string"?t:""):this.removeAttribute("handoff"))}get isHandoff(){return this.#B()}get handoffSession(){return this.#r}get handoffState(){return this.#o}get handoffProgress(){return this.#F}get handoffRetryCount(){return this.#j}attachHandoffSession(t,e=null){this.#W(),this.#r=t,this.#v=e||t?.token||null,this.#nt(t),this.#o=t.isConnected?"connected":t.state==="idle"?"connecting":t.state,this.#p()}async reconnectHandoff(){if(!(!this.#r||!this.#v)&&!(this.#o==="complete"||this.#o==="connecting")){this.#j++,this.#o="reconnecting",this.#p();try{if(R.has(this.#v.peerId)){let t=R.createLinkedSender(this.#v.peerId);await this.#r.reconnect(t)}else await this.#r.reconnect()}catch(t){console.warn("[CopioScanner] Handoff reconnect failed:",t),this.#o="disconnected",this.#p(t?.message||"Reconnection failed")}}}async resetHandoff(){this.#o=this.#r?.isConnected?"connected":"idle",this.#F=null;let t=this.shadowRoot;if(t){let e=t.getElementById("handoff-confirm-view");e&&(e.style.display="none");let o=t.getElementById("handoff-progress-view");o&&(o.style.display="none")}await this.clear(),this.stage="viewfinder",this.#p()}#B(){return this.#r?!0:typeof this.hasAttribute=="function"&&this.hasAttribute("handoff")?this.getAttribute("handoff")!=="false":typeof window<"u"&&window.location?.hash?/(?:copio-)?handoff=/.test(window.location.hash):!1}async#st(){if(this.#r||!this.#B())return;let t=typeof this.getAttribute=="function"?this.getAttribute("handoff"):null;if(!t&&typeof window<"u"&&window.location?.hash&&(t=window.location.hash),!!t)try{let e=typeof t=="string"&&t.includes("#")?Q(t):W(t);this.#v=e,this.#o="connecting",this.#p();let o=null;if(R.has(e.peerId))o=R.createLinkedSender(e.peerId);else try{let{HandoffPeerTransport:r}=await import("./handoff-transport-7YFK4RYL.js");o=new r({role:"sender",targetPeerId:e.peerId,relayUrl:e.relayUrl||this.relayUrl,signalingUrl:e.signalingUrl||this.signalingUrl,iceServers:e.iceServers||this.iceServers,iceTransportPolicy:this.iceTransportPolicy})}catch{o=new R}let i=new G({role:"sender",transport:o});this.#r=i,this.#nt(i),await i.startSender(e)}catch(e){console.warn("[CopioScanner] Handoff sender init failed:",e),this.#o="error",this.#p(e?.message||"Connection error")}}#nt(t){this.#N.push(t.on("stateChange",e=>{e==="closed"?this.#o="disconnected":this.#o=e,e==="connected"&&(this.#j=0,this.dispatch(g.HANDOFF_CONNECTED,{sessionId:this.#v?.sessionId||"",peerId:this.#v?.peerId||""})),this.#p()}),t.on("connectionInfo",e=>{this.dispatch(g.CONNECTION_INFO,e)}),t.on("progress",e=>{this.#F=e,this.#vt(e)}),t.on("complete",()=>{this.#o="complete",this.#p()}),t.on("error",e=>{console.warn("[CopioScanner] Handoff session error:",e),this.#o="error",this.#p(e?.message||"Connection error")}))}#W(){for(let t of this.#N)try{t()}catch{}if(this.#N=[],this.#r){try{this.#r.close()}catch{}this.#r=null}this.#v=null,this.#o="idle",this.#F=null}#p(t=""){let e=this.shadowRoot;if(!e)return;let o=e.getElementById("handoff-pill"),i=e.getElementById("handoff-dot"),r=e.getElementById("handoff-status-text"),s=e.getElementById("btn-handoff-retry");if(!o||!i||!r)return;if(!this.#B()){o.style.display="none";return}o.style.display="inline-flex",i.className=`copio-handoff-dot ${this.#o}`;let n={connecting:"Connecting to computer\u2026",connected:"Paired with computer",reconnecting:"Reconnecting to computer\u2026",disconnected:"Disconnected",sending:"Sending to computer\u2026",complete:"Sent to computer \u2713",error:t||"Connection error"};r.textContent=n[this.#o]||"Desktop Handoff",s&&(s.style.display=this.#o==="disconnected"||this.#o==="error"?"inline-block":"none")}#vt(t){let e=this.shadowRoot;if(!e||!t)return;let o=e.getElementById("handoff-progress-bar"),i=e.getElementById("handoff-progress-desc");if(o&&typeof t.percent=="number"&&(o.style.width=`${t.percent}%`),i&&t.bytesSent&&t.totalBytes){let r=Math.round(t.bytesSent/1024),s=Math.round(t.totalBytes/1024);i.textContent=`Streaming chunks: ${r} KB / ${s} KB (${t.percent}%)`}}async#wt(t,e){let o=this.shadowRoot,i=o?.getElementById("handoff-progress-view"),r=o?.getElementById("handoff-progress-bar"),s=o?.getElementById("handoff-progress-title"),n=o?.getElementById("handoff-progress-desc");i&&(i.style.display="flex"),this.#o="sending",this.#p();try{for(let l=0;l<t.length;l++){let p=t[l];s&&(s.textContent=t.length>1?`Sending page ${l+1} of ${t.length}\u2026`:"Sending page to computer\u2026"),n&&(n.textContent="Encrypting with AES-GCM-256\u2026");let k=await this.#kt(p),h=!1,d=0;for(;!h&&d<3;)try{this.#r.isConnected||(await this.reconnectHandoff(),await this.#at(6e3)),await this.#r.sendPage({id:p.id,pageIndex:l,mimeType:k.type||"image/jpeg",blob:k,metadata:{width:p.dimensions?.width,height:p.dimensions?.height,label:p.label}}),h=!0}catch(m){if(d++,d>=3)throw m;await this.reconnectHandoff(),await this.#at(6e3)}}s&&(s.textContent="Finalizing scan session\u2026"),r&&(r.style.width="100%"),await this.#r.complete({docId:e.docId,summary:{mode:e.mode,aspect:e.aspect,pageCount:t.length}}),this.#o="complete",i&&(i.style.display="none");let a=o?.getElementById("handoff-confirm-view"),c=o?.getElementById("handoff-confirm-count");a&&(a.style.display="flex"),c&&(c.textContent=`${t.length} page${t.length===1?"":"s"} transferred to desktop`),this.#p(),this.dispatch(g.SCAN_COMPLETE,e)}catch(a){console.error("[CopioScanner] Handoff streaming error:",a),i&&(i.style.display="none"),this.#o="error",this.#p(a.message),this.dispatch(g.ERROR,{code:"HANDOFF_STREAMING_FAILED",message:a.message,error:a})}}async#at(t=6e3){if(!this.#r?.isConnected)return new Promise((e,o)=>{let i=setTimeout(()=>{r(),o(new Error("Timeout waiting for handoff connection"))},t),r=this.#r.on("stateChange",s=>{s==="connected"&&(clearTimeout(i),r(),e(void 0))})})}async#kt(t){if(t.blob instanceof Blob)return t.blob;let e=t.src||t.originalSrc;if(e&&typeof fetch=="function"&&(e.startsWith("data:")||e.startsWith("blob:")||e.startsWith("http")))try{let i=await(await fetch(e)).blob();if(i&&i.size>0)return i}catch{}if(typeof document<"u"){let o=document.createElement("canvas");o.width=t.dimensions?.width||120,o.height=t.dimensions?.height||160;let i=o.getContext("2d");return i&&(i.fillStyle="#f1f5f9",i.fillRect(0,0,o.width,o.height)),new Promise(r=>{o.toBlob(s=>r(s||new Blob),"image/jpeg")})}return new Blob([],{type:"image/jpeg"})}get theme(){return typeof this.getAttribute=="function"&&this.getAttribute("theme")||"dark"}set theme(t){typeof this.setAttribute=="function"&&(t?this.setAttribute("theme",t):this.removeAttribute("theme"))}get mode(){return typeof this.getAttribute=="function"&&this.getAttribute("mode")||"document"}set mode(t){typeof this.setAttribute=="function"&&this.setAttribute("mode",t)}get aspect(){return typeof this.getAttribute=="function"&&this.getAttribute("aspect")||"auto"}set aspect(t){typeof this.setAttribute=="function"&&this.setAttribute("aspect",t)}get stage(){return this.#i}set stage(t){if(t==="viewfinder"||t==="workbench"){this.#i=t,t==="workbench"&&this.#f(),typeof this.setAttribute=="function"&&this.getAttribute("stage")!==t&&this.setAttribute("stage",t);let e=this.shadowRoot;if(e){let o=e.getElementById("viewfinder-section"),i=e.getElementById("workbench-section");o&&i&&(o.style.display=t==="viewfinder"?"flex":"none",i.style.display=t==="workbench"?"flex":"none")}this.#a()}}get docId(){return typeof this.getAttribute=="function"?this.getAttribute("doc-id"):null}set docId(t){typeof this.setAttribute=="function"&&(t?this.setAttribute("doc-id",t):this.removeAttribute("doc-id"))}async rotateActivePage(){return this.#et()}async toggleActivePageBw(){return this.#ot()}async toggleCropMode(){return this.#U()}async deleteActivePageWithUndo(){return this.#it()}setCameraStream(t){this.#f(),this.#s=t;let e=this.shadowRoot,o=e?.getElementById("camera-video");if(o){o.muted=!0,o.volume=0,o.playsInline=!0,o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline",""),o.setAttribute("muted","");try{o.srcObject=typeof MediaStream<"u"&&t instanceof MediaStream?t:null}catch{}o.style.display=t?"block":"none",t&&o.srcObject&&o.play().catch(s=>{console.warn("[CopioScanner] Live video element play() error:",s)})}let i=e?.querySelector(".copio-camera-placeholder");i&&(i.style.display=t?"none":"");let r=e?.getElementById("step-pill-text");r&&t&&(r.textContent=this.mode==="batch"?`Batch Capture \xB7 Page ${this.#x+1}`:"Camera Active \xB7 Tap Shutter to Snap"),t&&this.#i==="viewfinder"&&this.#m&&this.#V()}get features(){return this.#t?this.#t.features:[]}set features(t){this.#c("features",Array.isArray(t)?t.join(" "):String(t||"")),this.#t&&this.#t.setFeatures(t)}hasFeature(t){return this.#t?this.#t.hasFeature(t):!1}get ocrEnabled(){return this.#t?this.#t.ocr:!0}set ocrEnabled(t){let e=!!t;this.#c("ocr",e?"true":"false"),this.#t&&(this.#t.ocr=e),this.#E()}get pdf(){return this.#t?this.#t.pdf:!0}set pdf(t){let e=!!t;this.#c("pdf",e?"true":"false"),this.#t&&(this.#t.pdf=e),this.#E()}get exportFormats(){return this.#t?this.#t.exportFormats:[]}set exportFormats(t){this.#c("export-formats",Array.isArray(t)?t.join(","):String(t||"")),this.#t&&(this.#t.exportFormats=t)}get ocrLanguages(){return this.#t?this.#t.ocrLanguages:[]}set ocrLanguages(t){this.#c("ocr-languages",Array.isArray(t)?t.join(","):String(t||"")),this.#t&&(this.#t.ocrLanguages=t)}get maxPages(){return this.#t?this.#t.maxPages:0}set maxPages(t){this.#c("max-pages",String(t)),this.#t&&(this.#t.maxPages=t)}get assetBase(){return this.#t?this.#t.assetBase:""}set assetBase(t){this.#c("asset-base",String(t||"")),this.#t&&(this.#t.assetBase=t)}get licenseKey(){return this.#t?this.#t.licenseKey:""}set licenseKey(t){this.#c("license-key",String(t||"")),this.#t&&(this.#t.licenseKey=t)}#c(t,e){typeof this.setAttribute=="function"&&(e?this.setAttribute(t,typeof e=="object"?JSON.stringify(e):String(e)):this.removeAttribute(t))}get relayUrl(){return this.#t?.relayUrl||""}set relayUrl(t){this.#t&&(this.#t.relayUrl=t),this.#c("relay-url",t)}get signalingUrl(){return this.#t?.signalingUrl||""}set signalingUrl(t){this.#t&&(this.#t.signalingUrl=t),this.#c("signaling-url",t)}get iceServers(){return this.#t?.iceServers||null}set iceServers(t){this.#t&&(this.#t.iceServers=t),this.#c("ice-servers",t)}get iceTransportPolicy(){return this.#t?.iceTransportPolicy||"all"}set iceTransportPolicy(t){this.#t&&(this.#t.iceTransportPolicy=t),this.#c("ice-transport-policy",t)}get storage(){return this.#D}set storage(t){this.#D=t,this.#t&&this.#t.setStorage(t)}get engine(){return this.#t}set engine(t){t instanceof z&&(this.#t=t,this.#t.addEventListener(g.MIGRATION,e=>{this.dispatch(g.MIGRATION,e.detail)}))}dispatch(t,e={}){return _(this,t,e)}async open(){this.#H=!0,typeof this.focus=="function"&&this.focus()}async close(){this.#H=!1,this.#f()}get isOpen(){return this.#H}async capture(){return new Promise(t=>{let e=document.createElement("input");e.type="file",e.accept="image/*",e.capture="environment",e.style.display="none",e.onchange=async()=>{try{if(e.files&&e.files.length>0){let o=await this.addFiles([e.files[0]]);t(o[0]||null)}else t(null)}catch(o){this.dispatch(g.ERROR,{code:"CAPTURE_FAILED",message:o.message,error:o}),t(null)}finally{e.remove()}},e.onerror=()=>{e.remove(),t(null)},document.body.appendChild(e),e.click()})}async addFiles(t,e={}){try{let o=await this.getPages(),i=null;if(o.length>0){if(this.mode==="single"&&this.maxPages<=1)await this.#t.clear(this.#d);else if(this.#P||this.maxPages>0&&o.length>=this.maxPages){let a=Math.min(this.#e,o.length-1),c=o[a];c&&(i=a,await this.#t.deletePage(this.#d,c.id))}}this.#P=!1;let r={autoCrop:this.#C,prefilledQuad:e?.prefilledQuad||null,...e},s=await this.#t.addFiles(t,this.#d,r);for(let a=0;a<s.length;a++)this.dispatch(g.PAGE_ADDED,{page:s[a],pageNumber:a+1,docId:this.docId,source:"file"});let n=await this.getPages();if(i!==null&&s.length===1&&i<n.length-1){let a=n.map(l=>l.id),c=a.pop();c&&(a.splice(i,0,c),await this.#t.reorderPages(this.#d,a),n=await this.getPages())}return this.#x=n.length,s.length>0&&(this.#e=i!==null?Math.min(i,Math.max(0,n.length-1)):Math.max(0,n.length-1),this.mode==="single"&&(this.#i="workbench",typeof this.setAttribute=="function"&&this.getAttribute("stage")!=="workbench"&&this.setAttribute("stage","workbench"))),this.dispatch(g.PAGES_CHANGED,{pages:n,docId:this.docId}),this.mode==="single"&&s.length>0&&this.maxPages<=1&&this.dispatch(g.SCAN_COMPLETE,{mode:this.mode,aspect:this.aspect,docId:this.docId,pages:n,page:n[n.length-1]||null,pageCount:n.length}),await this.#a(),s}catch(o){throw this.dispatch(g.ERROR,{code:o.code||"ADD_FILES_FAILED",message:o.message,error:o}),o}}async getPages(){return this.#t.getPages(this.#d)}async clear(){this.#f(),this.#e=0,this.#x=0,this.#P=!1,this.#n=!1,await this.#t.clear(this.#d),this.dispatch(g.PAGES_CHANGED,{pages:[],docId:this.docId}),await this.#a()}async exportPdf(t={}){try{let e=await this.#t.exportPdf(this.#d,t);return this.dispatch(g.EXPORT_COMPLETE,{type:"pdf",format:"pdf",blob:e,searchable:!!t.searchable,docId:this.docId}),e}catch(e){throw this.dispatch(g.ERROR,{code:e.code||"EXPORT_FAILED",message:e.message,error:e}),e}}async exportZip(t={}){try{let e=await this.#t.exportZip(this.#d,t);return this.dispatch(g.EXPORT_COMPLETE,{type:"zip",format:"zip",blob:e,docId:this.docId}),e}catch(e){throw this.dispatch(g.ERROR,{code:e.code||"EXPORT_FAILED",message:e.message,error:e}),e}}async ocr(t=null,e={}){try{let o=await this.#t.runOcr(this.#d,t,e);return this.dispatch(g.OCR_COMPLETE,{text:o.text,pages:o.pagesResults,averageConfidence:o.averageConfidence,docId:this.docId,pageId:t}),o}catch(o){throw this.dispatch(g.ERROR,{code:o.code||"OCR_FAILED",message:o.message,error:o}),o}}async runOcr(t=null,e={}){return this.ocr(t,e)}async sync(t={}){try{return await this.#t.sync({onStateChange:o=>{o&&(o.step==="connected"||o.step==="syncing")&&this.dispatch(g.SYNC_CONNECTED,{peerId:o.peerId,mode:o.mode}),t.onStateChange&&t.onStateChange(o)}})}catch(e){throw this.dispatch(g.ERROR,{code:e.code||"SYNC_FAILED",message:e.message,error:e}),e}}get edgeDetection(){return this.#m}set edgeDetection(t){let e=t!==!1&&t!=="false"&&t!==null&&t!==void 0;this.#m!==e&&(this.#m=e,this.#c("edge-detection",String(e)),this.#m?this.#s&&this.#i==="viewfinder"&&this.#V():(this.#z(),this.#_()))}get edgeModel(){return this.#y}set edgeModel(t){let e=t==="classical"?"classical":"ml";if(this.#y!==e){this.#y=e,this.#c("edge-model",e);let o=this.#t?.getService("edge")||T("edge");if(o&&"detector"in o&&(o.detector=e),e==="ml"&&o&&typeof o.preloadMl=="function"){let i=this.shadowRoot?.getElementById("step-pill-text"),r=i?.textContent;i&&this.#s&&this.#i==="viewfinder"&&(i.textContent="Loading ML Neural model\u2026"),o.preloadMl().then(()=>{i&&this.#s&&this.#i==="viewfinder"&&this.#y==="ml"&&(i.textContent=this.mode==="batch"?`Batch Capture \xB7 Page ${this.#x+1}`:"Camera Active \xB7 Tap Shutter to Snap")}).catch(s=>{console.warn("[CopioScanner] Failed to load ML Neural edge detector:",s),i&&r&&this.#i==="viewfinder"&&(i.textContent=r)})}}}get autoCrop(){return this.#C}set autoCrop(t){let e=t!==!1&&t!=="false"&&t!==null&&t!==void 0;this.#C!==e&&(this.#C=e,this.#c("auto-crop",String(e)))}get autoCapture(){return this.#S}set autoCapture(t){let e=!!(t&&t!=="false");this.#S!==e&&(this.#S=e,this.#c("auto-capture",String(e)))}getLiveQuad(){return this.#l?C(this.#l):null}getLatestDetection(){return this.#b?{quad:C(this.#b.quad),confidence:this.#b.confidence,durationMs:this.#b.durationMs,isFallback:this.#b.isFallback}:null}async detectCurrentFrame(t={}){let e=this._grabFrame({maxWidth:t.maxProcessingDimension||480,maxHeight:t.maxProcessingDimension||480});if(!e)return null;let o=this.#t?.getService("edge")||T("edge");return!o||typeof o.detect!="function"?null:o.detect(e,t)}};typeof customElements<"u"&&!customElements.get("copio-scanner")&&customElements.define("copio-scanner",q);export{H as a,K as b,X as c,q as d};
2
+ //# sourceMappingURL=chunk-Q3AWHANC.js.map
@@ -0,0 +1,2 @@
1
+ import{b as c}from"./chunk-SZHKZARU.js";import{d as n}from"./chunk-YNY65JUJ.js";import{h as r,i as a}from"./chunk-ZT72PD2C.js";var d=3e4,h=class{#n=null;#t=null;#r=null;#e=null;#a=0;#o=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)}#i(e){clearTimeout(this.#o),this.#e&&this.#s({...this.#e,step:"error",message:e})}async#c(){let e=++this.#a,[t,s]=await Promise.all([c(),r()]);return e!==this.#a?null:new s({config:{iceServers:t}})}#h(e){e.on("error",s=>this.#i(s.message));let t=e.peerConnection;t&&t.addEventListener("iceconnectionstatechange",()=>{console.log("[Sync] ICE state:",t.iceConnectionState),t.iceConnectionState==="failed"&&this.#i("Could not connect to the other device. Check both are online and try again.")})}#l(){clearTimeout(this.#o),this.#o=setTimeout(()=>{let e=this.#e?.step;e&&e!=="done"&&e!=="error"&&this.#i("Connection timed out. Try again.")},d)}#d(e){let t=()=>{clearTimeout(this.#o),this.#s({...this.#e,step:"syncing"}),this.#m(e)};e.open?t():e.on("open",t)}startHost(){if(this.#e?.mode!=="host"){if(!navigator.onLine){n.warning("An internet connection is needed to link devices.",{icon:"wifi-off",duration:4e3});return}this.#s({mode:"host",step:"init"}),this.#p().catch(e=>{this.#s({mode:"host",step:"error",message:e.message})})}}async#p(){let e=await this.#c();e&&(this.#n=e,e.on("error",t=>this.#i(t.message)),e.on("open",async t=>{let s=`${location.origin}${location.pathname}?peer=${t}`,i=(await a())(0,"M");i.addData(s),i.make(),this.#s({mode:"host",step:"waiting",qrSvg:i.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.#c();t&&(this.#n=t,t.on("error",s=>this.#i(s.message)),t.on("open",()=>{let s=t.connect(e);this.#h(s),this.#d(s)}))}#m(e){e.on("data",async t=>{let s;try{s=typeof t=="string"?JSON.parse(t):t}catch(i){console.error("Failed to parse sync data:",i);return}let o=0;typeof this.#t?.importDocs=="function"?o=await this.#t.importDocs(s):typeof this.#t?.transaction=="function"&&this.#t.transaction(()=>{for(let[i,l]of Object.entries(s||{}))this.#t.hasRow("docs",i)||o++,this.#t.setRow("docs",i,l)}),this.#s({...this.#e,step:"done",added:o}),n.success(`Sync complete \u2014 ${o} doc${o!==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.#i(t.message)}})()}close(){this.#a++,clearTimeout(this.#o),this.#n?.destroy(),this.#n=null,this.#s(null)}};export{h as a};
2
+ //# sourceMappingURL=chunk-R6Q4OXDG.js.map
@@ -0,0 +1,2 @@
1
+ var l="https://copio.metered.live/api/v1/turn/credentials?apiKey=d90f0b0b6bdf180ea68238f5c2185074ce37",i=[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.relay.metered.ca:80"}],u=5e3;function y(e){if(!e||typeof e!="string")return null;try{let t=new URL(e),a=t.protocol==="https:"||t.protocol==="wss:",r=a?443:80,n=t.port?parseInt(t.port,10):r,s=t.pathname||"/";return s.endsWith("/")||(s+="/"),{host:t.hostname,port:n,path:s,secure:a,origin:t.origin}}catch{return null}}async function f(e={}){if(Array.isArray(e))return e;if(Array.isArray(e?.iceServers)&&e.iceServers.length>0)return e.iceServers;let t=new AbortController,a=setTimeout(()=>t.abort(),u);if(e?.relayUrl&&typeof e.relayUrl=="string")try{let r=e.relayUrl.replace(/\/$/,""),n=r.endsWith("/ice")?r:`${r}/ice`,s=await fetch(n,{signal:t.signal,cache:"no-store"});if(s.ok){let o=await s.json(),c=Array.isArray(o)?o:o?.iceServers;if(Array.isArray(c)&&c.length>0)return c}}catch(r){console.warn("[Relay] Failed to fetch ICE credentials from custom relayUrl, trying managed relay:",r)}try{let r=await fetch(l,{signal:t.signal,cache:"no-store"});if(!r.ok)throw new Error(`HTTP ${r.status}`);let n=await r.json();if(!Array.isArray(n)||n.length===0)throw new Error("Empty ICE server list");return[{urls:"stun:stun.l.google.com:19302"},...n]}catch(r){return console.warn("[Sync] Failed to fetch TURN credentials, using STUN only:",r),i}finally{clearTimeout(a)}}export{y as a,f as b};
2
+ //# sourceMappingURL=chunk-SZHKZARU.js.map
@@ -1,2 +1,2 @@
1
- import{a as s}from"./chunk-NEEWG3OP.js";import{b as o}from"./chunk-WETG2JD7.js";var e=class extends s{#t=null;#n=null;#o=null;constructor(t=null,n=null){super(),this.#n=t,this.#o=n}async connect(t={}){let n=t.repo||this.#n,r=t.onStateChange||this.#o;return this.#t=new o(n,r),this.#t}async disconnect(){this.#t&&typeof this.#t.destroy=="function"&&(this.#t.destroy(),this.#t=null)}};export{e as a};
2
- //# sourceMappingURL=chunk-J7HWZNIP.js.map
1
+ import{a as s}from"./chunk-NEEWG3OP.js";import{a as o}from"./chunk-R6Q4OXDG.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-T5CPA7B2.js.map
@@ -0,0 +1,2 @@
1
+ import{a as v}from"./chunk-HCCNUPKB.js";import{a as B}from"./chunk-PSGIWIRH.js";import{b,c as T}from"./chunk-ZILTJGT2.js";import{a as y}from"./chunk-5OTO5WFV.js";import{c as S,n as C,o as w,p as U,w as N,x as V}from"./chunk-GU6OQMYK.js";import{a as M}from"./chunk-KH5JE65X.js";import{c as D}from"./chunk-6QK7337A.js";import{c as A}from"./chunk-JIPKWRBK.js";import{a as f}from"./chunk-U3V3VZGO.js";import{a as L,b as x}from"./chunk-ZT72PD2C.js";var $=3,E=[{version:2,name:"v1-to-v2-noop",description:"Establishes baseline schema versioning and verifies stored document integrity.",async up(u){let e=await u.listDocs();for(let t of e)if(!(!t||!t.id)&&typeof t.pages=="string")try{JSON.parse(t.pages)}catch{t.pages="[]",await u.saveDoc(t.id,t)}}},{version:3,name:"v2-to-v3-quad-edits",description:"Normalizes page edit stacks to include edits.quad for perspective correction (CPO-075).",async up(u){let e=await u.listDocs();for(let t of e){if(!t||!t.id)continue;let r=t.pages,s=!1;if(typeof r=="string"){s=!0;try{r=JSON.parse(r)}catch{continue}}if(!Array.isArray(r))continue;let n=!1;for(let i of r)!i||typeof i!="object"||(!i.edits||typeof i.edits!="object"?(i.edits={crop:null,quad:null,rotate:0,filter:"none"},n=!0):"quad"in i.edits||(i.edits={...i.edits,quad:null},n=!0));n&&(t.pages=s?JSON.stringify(r):r,await u.saveDoc(t.id,t))}}}],p=class{static get CURRENT_VERSION(){return 3}static get DEFAULT_MIGRATIONS(){return[...E]}static async run({storage:e,migrations:t=E,targetVersion:r=3,onEvent:s,signal:n}){if(!e)throw new Error("MigrationRunner.run requires a valid storage adapter");if(n?.aborted)throw new Error("Migration aborted before execution");let i=await e.getSchemaVersion(),o=i;if(i==null){let d=await e.listDocs();if(!d||d.length===0){await e.setSchemaVersion(r);let h={fresh:!0,fromVersion:null,toVersion:r,applied:[]};return s?.({stage:"complete",...h}),h}o=1}if(o===r)return{fresh:!1,fromVersion:o,toVersion:r,applied:[]};if(o>r)return console.warn(`[CopioMigration] Storage schema version (${o}) is newer than target version (${r}).`),{fresh:!1,fromVersion:o,toVersion:r,applied:[]};let l=t.filter(d=>d.version>o&&d.version<=r).sort((d,h)=>d.version-h.version);if(l.length===0)return await e.setSchemaVersion(r),{fresh:!1,fromVersion:o,toVersion:r,applied:[]};s?.({stage:"start",fromVersion:o,toVersion:r,totalPending:l.length});let a=[];for(let d of l){if(n?.aborted){let h=new Error(`Migration aborted before version ${d.version}`);throw s?.({stage:"error",fromVersion:o,toVersion:r,failedVersion:d.version,error:h}),h}s?.({stage:"progress",version:d.version,name:d.name,fromVersion:o,toVersion:r});try{await d.up(e,{fromVersion:o,toVersion:d.version,signal:n}),await e.setSchemaVersion(d.version),o=d.version,a.push(d.version)}catch(h){throw s?.({stage:"error",fromVersion:o,toVersion:r,failedVersion:d.version,error:h}),h}}let c={fresh:!1,fromVersion:i??1,toVersion:o,applied:a};return s?.({stage:"complete",...c}),c}};var m=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(){let e=await this.#e.init();return await p.run({storage:this.#e}),e}async getSchemaVersion(){return this.#e.getSchemaVersion()}listDocsSync(){return typeof this.#e.listDocsSync=="function"?this.#e.listDocsSync().map(t=>{let r=this.#r(t.pages);return{id:t.id,name:t.name||"",pageCount:r.length,pages:r}}):[]}async listDocs(){return(await this.#e.listDocs()).map(t=>{let r=this.#r(t.pages);return{id:t.id,name:t.name||"",pageCount:r.length,pages:r}})}getDocSync(e){if(!e)return null;if(typeof this.#e.getDocSync=="function"){let s=this.#e.getDocSync(e);return s?{id:s.id,name:s.name||"",pages:this.#r(s.pages)}:null}let r=this.listDocsSync().find(s=>s.id===e);return r?{id:r.id,name:r.name,pages:r.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 r=w(),s=this.#r(t),n={id:r,name:e||"Untitled Document",pages:s};return await this.#e.saveDoc(r,n),n}async saveDoc(e,t){if(!e)throw new Error("Cannot save document without an ID");let r=this.#r(t.pages);await this.#e.saveDoc(e,{id:e,name:t.name||"",pages:r})}async renameDoc(e,t){if(typeof this.#e.renameDoc=="function")return this.#e.renameDoc(e,t);let r=await this.getDoc(e);if(!r)throw new Error(`Document "${e}" not found`);r.name=t,await this.saveDoc(e,r)}async deleteDoc(e,{soft:t=!0,timeoutMs:r=5e3}={}){if(!e)return;let s=this.getDocSync(e);if(s){if(this.#a(e),await this.#e.deleteDoc(e),t&&r>0){let n=setTimeout(async()=>{this.#t.delete(e)},r);this.#t.set(e,{doc:s,timerId:n})}return{id:e,name:s.name,undo:()=>this.undoDeleteDoc(e)}}}#a(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 r=await this.getDoc(e);if(!r)throw new Error(`Document "${e}" not found`);let s=Array.isArray(t)?t:[t];r.pages.push(...s),await this.saveDoc(e,r)}async updatePage(e,t,r){let s=await this.getDoc(e);if(!s)throw new Error(`Document "${e}" not found`);let n=s.pages.findIndex(i=>i.id===t);if(n===-1)throw new Error(`Page "${t}" not found in document "${e}"`);s.pages[n]={...s.pages[n],...r},await this.saveDoc(e,s)}async reorderPages(e,t){let r=await this.getDoc(e);if(!r)throw new Error(`Document "${e}" not found`);let s=new Map(r.pages.map(i=>[i.id,i])),n=[];for(let i of t)s.has(i)&&(n.push(s.get(i)),s.delete(i));for(let i of s.values())n.push(i);r.pages=n,await this.saveDoc(e,r)}async deletePage(e,t,{soft:r=!0,timeoutMs:s=5e3}={}){let n=await this.getDoc(e);if(!n)throw new Error(`Document "${e}" not found`);let i=n.pages.findIndex(c=>c.id===t);if(i===-1)return;let[o]=n.pages.splice(i,1);await this.saveDoc(e,n);let l=`${e}:${t}`;if(this.#f(l),!r||s<=0){if(typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(c){console.warn("[DocRepository] Adapter deletePage error:",c)}return}let a=setTimeout(async()=>{if(this.#i.delete(l),typeof this.#e.deletePage=="function")try{await this.#e.deletePage(e,t)}catch(c){console.warn("[DocRepository] Adapter deletePage error:",c)}},s);return this.#i.set(l,{docId:e,pageId:t,page:o,index:i,timerId:a}),{docId:e,pageId:t,undo:()=>this.undoDeletePage(e,t)}}#f(e){if(this.#i.has(e)){let t=this.#i.get(e);clearTimeout(t.timerId),this.#i.delete(e)}}async undoDeletePage(e,t){let r=`${e}:${t}`,s=this.#i.get(r);if(!s)return null;clearTimeout(s.timerId),this.#i.delete(r);let n=await this.getDoc(e);if(!n)return null;let i=Math.min(s.index,n.pages.length);return n.pages.splice(i,0,s.page),await this.saveDoc(e,n),s.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 r of e)t[r.id]=r;return t}async exportAll(){let e=await this.listDocs(),t={};for(let r of e){let s=await this.getDoc(r.id),n=[];for(let i of s?.pages||[]){if(!i){n.push(i);continue}let o={...i},l=o.blob instanceof Blob?o.blob:null;if(!l&&typeof o.src=="string"&&o.src.startsWith("blob:"))try{l=await(await fetch(o.src)).blob()}catch{}l&&(o.src=await A(l));let a=o.originalBlob instanceof Blob?o.originalBlob:null;if(!a&&typeof o.originalSrc=="string"&&o.originalSrc.startsWith("blob:"))try{a=await(await fetch(o.originalSrc)).blob()}catch{}a&&(o.originalSrc=await A(a)),delete o.blob,delete o.originalBlob,n.push(o)}t[r.id]={name:r.name,pages:JSON.stringify(n)}}return t}async importDocs(e){let t=0;for(let[r,s]of Object.entries(e||{})){await this.getDoc(r)||t++;let i=this.#r(s.pages);await this.saveDoc(r,{name:s.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[]}},z=new m;var j="2026-11-14T09:54:39.755Z",J="0.1.6";var R=["crop","rotate","filter","ocr","export","sync"],_=["pdf","zip","png","jpg"],I=["eng"],F={};function Ve(u,e){!u||!e||(F[u]=e,typeof globalThis<"u"&&(globalThis.__copio_services__=globalThis.__copio_services__||{},globalThis.__copio_services__[u]=e))}function g(u){return F[u]?F[u]:typeof globalThis<"u"&&globalThis.__copio_services__?.[u]?globalThis.__copio_services__[u]:null}function Q(u){return u?u instanceof Set?new Set(u):Array.isArray(u)?new Set(u.map(e=>String(e).trim().toLowerCase()).filter(Boolean)):typeof u=="string"?new Set(u.split(/[\s,]+/).map(e=>e.trim().toLowerCase()).filter(Boolean)):new Set(R):new Set(R)}function P(u,e){return u?Array.isArray(u)?u.map(t=>String(t).trim().toLowerCase()).filter(Boolean):typeof u=="string"?u.split(/[\s,]+/).map(t=>t.trim().toLowerCase()).filter(Boolean):[...e]:[...e]}var q=class extends EventTarget{#e=new Set(R);#t=[..._];#i=[...I];#a=0;#f="";#r=null;#s=null;#g={};#c=!0;#u=!0;#n=null;#d=new Map;#h=new Map;#E=[...E];#P=3;#p="";#m="";#w=null;#y="all";#l=null;constructor(e={}){super(),this.#r=e.storage||D(e),this.#s=e.repository||new m(this.#r),e.migrations&&(this.#E=[...e.migrations]),e.schemaVersion!==void 0&&(this.#P=e.schemaVersion),e.services&&(this.#g={...e.services}),e.imageProcessor?(this.#n=e.imageProcessor,this.#g.imageProcessor=e.imageProcessor):this.getService("imageProcessor")?this.#n=this.getService("imageProcessor"):typeof document<"u"?this.#n=new V:this.#n=new M,e.features!==void 0&&this.setFeatures(e.features),e.exportFormats!==void 0&&(this.#t=P(e.exportFormats,_)),e.ocrLanguages!==void 0&&(this.#i=P(e.ocrLanguages,I)),e.maxPages!==void 0&&(this.#a=Math.max(0,Number(e.maxPages)||0)),e.assetBase!==void 0&&x(e.assetBase),e.licenseKey!==void 0&&(this.#f=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),e.relayUrl!==void 0&&(this.#p=String(e.relayUrl||"")),e.signalingUrl!==void 0&&(this.#m=String(e.signalingUrl||"")),e.iceServers!==void 0&&(this.#w=Array.isArray(e.iceServers)?e.iceServers:null),e.iceTransportPolicy!==void 0&&(this.#y=e.iceTransportPolicy||"all")}async init(){return this.#l?this.#l:(this.#l=(async()=>{try{let e=await this.#r.init(),t=await this.#A();return{...e,migration:t}}catch(e){throw this.#l=null,e}})(),this.#l)}async#A(){let e=t=>{let r={...t,engine:this};this.dispatchEvent(new CustomEvent(v.MIGRATION,{detail:r})),typeof window<"u"&&typeof window.dispatchEvent=="function"&&window.dispatchEvent(new CustomEvent(v.MIGRATION,{detail:r}))};return p.run({storage:this.#r,migrations:this.#E,targetVersion:this.#P,onEvent:e})}async#o(){this.#l?await this.#l:await this.init()}async getSchemaVersion(){return this.#r.getSchemaVersion()}setService(e,t){this.#g[e]=t}getService(e){return this.#g[e]||g(e)}hasFeature(e){return e?this.#e.has(String(e).trim().toLowerCase()):!1}get features(){return Array.from(this.#e)}setFeatures(e){this.#e=Q(e),this.hasFeature("ocr")?(this.#c=!0,this.getService("ocr")instanceof f&&this.setService("ocr",g("ocr"))):(this.#c=!1,this.setService("ocr",new f))}enableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.add(t),t==="ocr"&&(this.#c=!0,this.getService("ocr")instanceof f&&this.setService("ocr",g("ocr")))}}disableFeature(e){if(e){let t=String(e).trim().toLowerCase();this.#e.delete(t),t==="ocr"&&(this.#c=!1,this.setService("ocr",new f))}}get ocr(){return this.#c&&this.hasFeature("ocr")}set ocr(e){this.#c=!!e,this.#c?(this.enableFeature("ocr"),this.getService("ocr")instanceof f&&this.setService("ocr",g("ocr"))):(this.disableFeature("ocr"),this.setService("ocr",new f))}get pdf(){return this.#u&&this.#t.includes("pdf")}set pdf(e){this.#u=!!e,this.#u?(this.#t.includes("pdf")||this.#t.push("pdf"),this.getService("pdf")instanceof y&&this.setService("pdf",g("pdf"))):(this.#t=this.#t.filter(t=>t!=="pdf"),this.setService("pdf",new y))}get exportFormats(){return[...this.#t]}set exportFormats(e){this.#t=P(e,_),this.#t.includes("pdf")?(this.#u=!0,this.getService("pdf")instanceof y&&this.setService("pdf",g("pdf"))):(this.#u=!1,this.setService("pdf",new y))}get ocrLanguages(){return[...this.#i]}set ocrLanguages(e){this.#i=P(e,I)}get maxPages(){return this.#a}set maxPages(e){this.#a=Math.max(0,Number(e)||0)}get assetBase(){return L()}set assetBase(e){x(e)}get licenseKey(){return this.#f}set licenseKey(e){this.#f=String(e||"")}get relayUrl(){return this.#p}set relayUrl(e){this.#p=String(e||"")}get signalingUrl(){return this.#m}set signalingUrl(e){this.#m=String(e||"")}get iceServers(){return this.#w}set iceServers(e){this.#w=Array.isArray(e)?e:null}get iceTransportPolicy(){return this.#y}set iceTransportPolicy(e){this.#y=e||"all"}get edgeDetector(){return this.getService("edge")||g("edge")||new B}async detectEdges(e,t={}){let r=this.edgeDetector;return!r||typeof r.detect!="function"?null:r.detect(e,t)}get storage(){return this.#r}setStorage(e){e&&(this.#r=e,this.#s=new m(this.#r))}#D(e,t){this.#d.has(e)||this.#d.set(e,[]);let r=this.#d.get(e);r.push(t),r.length>50&&r.shift(),this.#h.has(e)&&(this.#h.get(e).length=0)}get imageProcessor(){return this.#n}setImageProcessor(e){e&&(this.#n=e,this.setService("imageProcessor",e))}async renderEdits(e,t){if(!e)return"";let r=S(t);return this.#n?this.#n.renderEdits(e,r):N(e,r)}get docs(){return this.#s}async listDocuments(){return await this.#o(),this.#s.listDocs()}async getDocument(e){return await this.#o(),this.#s.getDoc(e)}async createDocument(e,t){return await this.#o(),this.#s.createDoc(e,t)}async deleteDocument(e,t={}){return await this.#o(),this.#s.deleteDoc(e,t)}async undoDeleteDocument(e){return await this.#o(),this.#s.undoDeleteDoc(e)}async renameDocument(e,t){return await this.#o(),this.#s.renameDoc(e,t)}async addPages(e,t){return await this.#o(),this.#s.addPages(e,t)}async deletePage(e,t,r={}){return await this.#o(),this.#D(e,{type:"delete",pageId:t}),this.#s.deletePage(e,t,r)}async undoDeletePage(e,t){return await this.#o(),this.#s.undoDeletePage(e,t)}async updatePage(e,t,r){return await this.#o(),this.#s.updatePage(e,t,r)}async reorderPages(e,t){let r=await this.getDocument(e),s=r?.pages?r.pages.map(n=>n.id):[];return this.#D(e,{type:"reorder",priorOrder:s,newOrder:[...t]}),this.#s.reorderPages(e,t)}async#S(e){if(e)return e;let t=await this.listDocuments();return t.length>0?t[0].id:null}async applyEdit(e,t,r){let s=await this.#S(e),n=s?await this.getDocument(s):null;if(!n||!n.pages)throw new Error(`Document with ID "${s||e}" not found`);let i=n.pages.find(k=>k.id===t);if(!i)throw new Error(`Page with ID "${t}" not found in document "${s}"`);let o=S(i.edits||{crop:null,quad:null,rotate:0,filter:"none"}),l=i.src,a=S({...o,...r}),c=i.originalSrc||i.src,d=c;this.#n&&(d=await this.#n.renderEdits(c,a));let h=o.rotate!==a.rotate||JSON.stringify(o.crop)!==JSON.stringify(a.crop)||JSON.stringify(o.quad)!==JSON.stringify(a.quad),O={originalSrc:c,src:d,edits:a,...h?{ocrText:null,ocrConfidence:null,ocrWords:null,ocrWidth:null,ocrHeight:null}:{}};return await this.updatePage(s,t,O),this.#D(s,{type:"edit",pageId:t,priorEdits:o,priorSrc:l,newEdits:a,newSrc:d}),{...i,...O}}async undo(e){let t=await this.#S(e),r=t?this.#d.get(t):null;if(!r||r.length===0)return null;let s=r.pop();return this.#h.has(t)||this.#h.set(t,[]),this.#h.get(t).push(s),s.type==="edit"?(await this.updatePage(t,s.pageId,{edits:s.priorEdits,src:s.priorSrc}),{type:"edit",pageId:s.pageId,restoredEdits:s.priorEdits}):s.type==="delete"?(await this.undoDeletePage(t,s.pageId),{type:"delete",pageId:s.pageId}):s.type==="reorder"?(await this.#s.reorderPages(t,s.priorOrder),{type:"reorder",priorOrder:s.priorOrder}):s}async redo(e){let t=await this.#S(e),r=t?this.#h.get(t):null;if(!r||r.length===0)return null;let s=r.pop();return this.#d.has(t)||this.#d.set(t,[]),this.#d.get(t).push(s),s.type==="edit"?(await this.updatePage(t,s.pageId,{edits:s.newEdits,src:s.newSrc}),{type:"edit",pageId:s.pageId,appliedEdits:s.newEdits}):s.type==="delete"?(await this.deletePage(t,s.pageId),{type:"delete",pageId:s.pageId}):s.type==="reorder"?(await this.reorderPages(t,s.newOrder),{type:"reorder",newOrder:s.newOrder}):s}subscribe(e){return this.#s.subscribe(e)}async addFiles(e,t=null,r={}){if(!e||e.length===0)return[];let s=Array.from(e),n=[];for(let o of s)if(o.type==="application/pdf"){let l=this.getService("pdf");if(l&&typeof l.renderPdfPagesToDataUrls=="function"){let a=await l.renderPdfPagesToDataUrls(o);for(let c of a)n.push({id:w(),src:c,originalSrc:c,edits:{crop:null,rotation:0,filter:"none"},type:"image",name:o.name||"PDF Page"})}else console.warn("PDF import service (PdfPort) not registered. Skipping PDF file.")}else if(o.type&&o.type.startsWith("image/")){let l=await U(o),a=null;try{a=await C(o)}catch{}let c={crop:null,rotation:0,filter:"none"};if(r.prefilledQuad)c.quad=b(r.prefilledQuad),c.crop=T(r.prefilledQuad);else if(r.autoCrop)try{let d=this.getService("edge");if(d&&typeof d.detect=="function"){let h=await d.detect(l);h&&h.quad&&h.confidence>=.45&&!h.isFallback&&(c.quad=b(h.quad),c.crop=T(h.quad))}}catch{}n.push({id:w(),src:l,originalSrc:l,edits:c,type:"image",name:o.name||"Captured Image",orientation:a})}if(n.length===0)return[];await this.init();let i=t;if(i)await this.getDocument(i)||await this.#s.saveDoc(i,{name:"Scanned Document",pages:[]});else{let o=await this.listDocuments();o.length>0?i=o[0].id:i=(await this.createDocument("Scanned Document",[])).id}if(this.#a>0){let o=(await this.getDocument(i))?.pages||[],l=Math.max(0,this.#a-o.length);if(l<=0)throw new Error(`Maximum page limit (${this.#a}) reached`);n.splice(l)}return await this.addPages(i,n),n}async getPages(e=null){let t=e;if(!t){let s=await this.listDocuments();if(s.length===0)return[];t=s[0].id}return(await this.getDocument(t))?.pages||[]}async clear(e=null){let t=e;if(!t){let s=await this.listDocuments();if(s.length===0)return;t=s[0].id}let r=await this.getDocument(t);if(!(!r||!r.pages))for(let s of r.pages)await this.deletePage(t,s.id)}async#v(e){if(Array.isArray(e))return{docName:"document",pages:e,docId:null};if(typeof e=="string"){let r=await this.getDocument(e);return{docName:r?.name||"document",pages:r?.pages||[],docId:e}}let t=await this.listDocuments();if(t.length>0){let r=await this.getDocument(t[0].id);return{docName:r?.name||"document",pages:r?.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.#u||!this.#t.includes("pdf")){let i=new Error('Feature "pdf" is disabled');throw Object.assign(i,{code:"FEATURE_DISABLED"}),i}let{docName:r,pages:s}=await this.#v(e),n=this.getService("pdf")||this.getService("export");if(!n||typeof n.exportDocumentAsPdf!="function")throw new Error("Export service (PdfPort) is not registered. Import @copio/sdk or register an exportService.");return n.exportDocumentAsPdf(r,s,{download:!1,showProgress:!1,onOcrComplete:async()=>{if(typeof e=="string"){let i=await this.#r.getDoc(e);i&&(i.pages=s,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:r,pages:s}=await this.#v(e),n=this.getService("export");if(!n||typeof n.exportDocumentAsImages!="function")throw new Error("Export service is not registered. Import @copio/sdk or register an exportService.");return n.exportDocumentAsImages(r,s,{download:!1,showProgress:!1,...t})}async runOcr(e,t=null,r={}){if(!this.#c||!this.hasFeature("ocr")){let a=new Error('Feature "ocr" is disabled');throw Object.assign(a,{code:"FEATURE_DISABLED"}),a}let{pages:s}=await this.#v(e),n=s;t&&(n=s.filter(a=>a.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 o=r.lang||this.#i[0]||"eng",l=await i.recognizeDocumentPages(n,{lang:o,...r});if(Array.isArray(l.pagesResults)){for(let a of l.pagesResults){let c=n.find(d=>d.id===a.pageId)||n[a.pageIndex];c&&(c.ocrText=a.text,c.ocrConfidence=a.confidence,c.ocrWords=a.words)}if(typeof e=="string"){let a=await this.#r.getDoc(e);if(a&&Array.isArray(a.pages)){for(let c of l.pagesResults){let d=a.pages.find(h=>h.id===c.pageId)||a.pages[c.pageIndex];d&&(d.ocrText=c.text,d.ocrConfidence=c.confidence,d.ocrWords=c.words)}await this.#r.saveDoc(e,a)}}}return{text:l.combinedText,...l}}async sync(e={}){if(!this.hasFeature("sync")){let r=new Error('Feature "sync" is disabled');throw Object.assign(r,{code:"FEATURE_DISABLED"}),r}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{$ as a,E as b,p as c,m as d,z as e,j as f,J as g,R as h,_ as i,I as j,Ve as k,g as l,q as m};
2
+ //# sourceMappingURL=chunk-TK5N67RB.js.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-V2D55DVU.js.map
@@ -0,0 +1,2 @@
1
+ var R="P-256",A={name:"ECDH",namedCurve:R},H={name:"AES-GCM",length:256},$=12;function y(n){let e=n instanceof Uint8Array?n:new Uint8Array(n),t="",r=32768;for(let o=0;o<e.length;o+=r){let i=e.subarray(o,o+r);t+=String.fromCharCode.apply(null,i)}return globalThis.btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function u(n){if(typeof n!="string")throw new TypeError("Expected string for base64url decoding");let e=n.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4!==0;)e+="=";let t=globalThis.atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r}function P(n){let e=new TextEncoder().encode(n);return y(e)}function K(n){let e=u(n);return new TextDecoder().decode(e)}async function w(){let n=globalThis.crypto?.subtle;if(!n)throw new Error("WebCrypto API (crypto.subtle) is not available");return await n.generateKey(A,!0,["deriveKey","deriveBits"])}async function g(n){let t=await globalThis.crypto.subtle.exportKey("raw",n);return y(new Uint8Array(t))}async function b(n){let e=globalThis.crypto.subtle,t=u(n);return await e.importKey("raw",t,A,!1,[])}async function x(n,e){return await globalThis.crypto.subtle.deriveKey({name:"ECDH",public:e},n,H,!1,["encrypt","decrypt"])}async function l(n,e){let t=globalThis.crypto.subtle,r;typeof e=="string"?r=new TextEncoder().encode(e):e instanceof Uint8Array?r=e:e instanceof ArrayBuffer?r=new Uint8Array(e):r=new TextEncoder().encode(JSON.stringify(e));let s=globalThis.crypto.getRandomValues(new Uint8Array($)),o=await t.encrypt({name:"AES-GCM",iv:s},n,r);return{iv:y(s),ciphertext:y(new Uint8Array(o))}}async function E(n,e,t){let r=globalThis.crypto.subtle,s=typeof e=="string"?u(e):e,o=typeof t=="string"?u(t):t,i=await r.decrypt({name:"AES-GCM",iv:s},n,o);return new Uint8Array(i)}async function T(n,e,t){let r=await E(n,e,t),s=new TextDecoder().decode(r);try{return JSON.parse(s)}catch{return s}}var L=64*1024,N=600*1e3;function f(n="hnd_"){let e=globalThis.crypto.getRandomValues(new Uint8Array(8)),t="";for(let r=0;r<e.length;r++)t+=e[r].toString(16).padStart(2,"0");return`${n}${t}`}function B(n){let e={v:n.v||1,sessionId:n.sessionId,peerId:n.peerId,pubKey:n.pubKey,expiresAt:n.expiresAt};return P(JSON.stringify(e))}function M(n){if(!n||typeof n!="string")throw new Error("Invalid handoff token string");let e;try{let t=n.trim();t.startsWith("{")&&t.endsWith("}")?e=JSON.parse(t):e=JSON.parse(K(n))}catch(t){throw new Error(`Failed to decode handoff token: ${t.message}`)}if(!e.sessionId||!e.peerId||!e.pubKey||!e.expiresAt)throw new Error("Malformed handoff token: missing required fields");if(Date.now()>e.expiresAt)throw new Error(`Handoff session token has expired at ${new Date(e.expiresAt).toISOString()}`);return e}function z(n,e){let t=B(e);return`${n?n.split("#")[0]:""}#handoff=${t}`}function F(n){if(!n||typeof n!="string")throw new Error("Invalid URL or hash string for handoff");let e=n.indexOf("#"),r=(e!==-1?n.slice(e+1):n).match(/(?:copio-)?handoff=([^&]+)/);if(!r||!r[1])throw new Error("No handoff parameter found in hash");return M(r[1])}var m=class n{#e=null;#t=new Set;#i=new Set;#n=!1;#r=!1;#s="all";static#a=new Map;static register(e,t){return n.#a.set(e,t),()=>n.#a.delete(e)}static has(e){return n.#a.has(e)}static get(e){return n.#a.get(e)}static clearRegistry(){n.#a.clear()}static createLinkedSender(e){let t=n.#a.get(e);if(!t)throw new Error(`No registered loopback host for peerId: ${e}`);let r=new n;return t.#e=r,r.#e=t,t.#n=!1,r.#n=!1,r}static createPair(){let e=new n,t=new n;return e.#e=t,t.#e=e,[e,t]}send(e){if(this.#n)throw new Error("Cannot send on closed LoopbackTransport");if(!this.#e||this.#e.#n)throw new Error("Remote peer disconnected");let t=this.#e;queueMicrotask(()=>{t.#n||t.#h(e)})}#h(e){for(let t of this.#t)try{t(e)}catch(r){console.error("[LoopbackTransport] message handler error:",r)}}onMessage(e){return this.#t.add(e),()=>this.#t.delete(e)}onClose(e){return this.#i.add(e),()=>this.#i.delete(e)}interrupt(){this.#n=!0;for(let e of this.#i)try{e()}catch(t){console.error("[LoopbackTransport] close handler error:",t)}this.#e&&!this.#e.#n&&this.#e.interrupt()}reconnect(e=null){this.#n=!1,e?(this.#e=e,e.#e=this,e.#n=!1):this.#e&&(this.#e.#n=!1)}get forceRelay(){return this.#r}set forceRelay(e){this.#r=!!e}get iceTransportPolicy(){return this.#s}set iceTransportPolicy(e){this.#s=e}async getConnectionInfo(){let e=this.#r||this.#s==="relay";return{transport:e?"turn":"direct",rttMs:e?15:0}}close(){if(!this.#n){this.#n=!0;for(let e of this.#i)try{e()}catch(t){console.error("[LoopbackTransport] close handler error:",t)}if(this.#e&&!this.#e.#n){let e=this.#e;this.#e=null,e.close()}}}get isClosed(){return this.#n}};async function J(n){if(n instanceof Uint8Array)return n;if(n instanceof ArrayBuffer)return new Uint8Array(n);if(n&&typeof n.arrayBuffer=="function"){let e=await n.arrayBuffer();return new Uint8Array(e)}throw new TypeError("Payload must be a Uint8Array, ArrayBuffer, or Blob")}var U=class n{#e;#t=null;#i="idle";#n=null;#r=null;#s=null;#a;#h;#p=null;#y=Promise.resolve();#l=new Map;#f=[];#d={stateChange:new Set,connectionInfo:new Set,progress:new Set,page:new Set,complete:new Set,error:new Set};constructor(e={}){if(!e.role||e.role!=="host"&&e.role!=="sender")throw new Error("HandoffSession requires role to be 'host' or 'sender'");this.#e=e.role,this.#a=e.chunkSize||L,this.#h=e.ttlMs||N,e.transport&&this.setTransport(e.transport),e.onStateChange&&this.on("stateChange",e.onStateChange),e.onProgress&&this.on("progress",e.onProgress),e.onPage&&this.on("page",e.onPage),e.onComplete&&this.on("complete",e.onComplete),e.onError&&this.on("error",e.onError)}get role(){return this.#e}get state(){return this.#i}get token(){return this.#s}get isConnected(){return this.#i==="connected"||this.#i==="receiving"||this.#i==="sending"||this.#i==="complete"&&!!this.#r&&!!this.#t&&!this.#t.isClosed}on(e,t){return this.#d[e]?(this.#d[e].add(t),()=>this.#d[e].delete(t)):()=>{}}#c(e,t){if(this.#d[e])for(let r of this.#d[e])try{r(t)}catch(s){console.error(`[HandoffSession] error in ${e} listener:`,s)}}#o(e){this.#i!==e&&(this.#i=e,this.#c("stateChange",e),e==="connected"&&this.getConnectionInfo().then(t=>{this.#c("connectionInfo",t)}).catch(()=>{}))}#u(e){let t=e instanceof Error?e:new Error(String(e));this.#o("error"),this.#c("error",t)}setTransport(e){this.#t=e,e.onMessage(t=>{this.#y=this.#y.then(async()=>{await this.#w(t)}).catch(r=>{this.#u(r)})}),e.onClose(()=>{this.#i!=="closed"&&this.#i!=="complete"&&this.#o("disconnected")})}static async createLoopbackPair(e={}){let[t,r]=m.createPair(),s=new n({role:"host",transport:t,chunkSize:e.chunkSize,ttlMs:e.ttlMs}),o=new n({role:"sender",transport:r,chunkSize:e.chunkSize,ttlMs:e.ttlMs}),{token:i,url:a}=await s.startHost({baseUrl:e.baseUrl||"https://copio.netlify.app/scan",peerId:e.peerId||f("peer_")});return await o.startSender(i),{host:s,sender:o,token:i,url:a}}async startHost(e={}){if(this.#e!=="host")throw new Error("startHost() can only be called on a host session");this.#n=await w();let t=await g(this.#n.publicKey),r=f("hnd_"),s=e.peerId||f("peer_"),o=Date.now()+this.#h;this.#s={v:1,sessionId:r,peerId:s,pubKey:t,expiresAt:o},e.relayUrl&&(this.#s.relayUrl=e.relayUrl),e.signalingUrl&&(this.#s.signalingUrl=e.signalingUrl),e.iceServers&&(this.#s.iceServers=e.iceServers);let i=e.baseUrl||(typeof location<"u"?`${location.origin}${location.pathname}`:""),a=z(i,this.#s),h=B(this.#s);return clearTimeout(this.#p),this.#p=setTimeout(()=>{(this.#i==="waiting"||this.#i==="idle")&&this.#o("expired")},this.#h),this.#o("waiting"),{token:this.#s,url:a,rawToken:h}}async startSender(e){if(this.#e!=="sender")throw new Error("startSender() can only be called on a sender session");let t;if(typeof e=="string"?t=e.includes("#")?F(e):M(e):t=e,!t||!t.sessionId||!t.pubKey)throw new Error("Invalid handoff token");if(Date.now()>t.expiresAt)throw this.#o("expired"),new Error("Handoff session has expired");this.#s=t,this.#o("connecting"),this.#n=await w();let r=await g(this.#n.publicKey),s=await b(t.pubKey);if(this.#r=await x(this.#n.privateKey,s),!this.#t)throw new Error("Transport must be set before starting sender");this.#t.send({type:"handshake_init",sessionId:t.sessionId,senderPubKey:r})}async reconnect(e=null){if(this.#e!=="sender")throw new Error("reconnect() can only be called on a sender session");if(!this.#s)throw new Error("Cannot reconnect: no session token");if(Date.now()>this.#s.expiresAt)throw this.#o("expired"),new Error("Handoff session has expired");e?this.setTransport(e):this.#t&&typeof this.#t.reconnect=="function"&&this.#t.reconnect(),this.#o("connecting"),this.#n||(this.#n=await w());let t=await g(this.#n.publicKey),r=await b(this.#s.pubKey);if(this.#r=await x(this.#n.privateKey,r),!this.#t||this.#t.isClosed)throw new Error("Cannot reconnect without active transport");this.#t.send({type:"handshake_init",sessionId:this.#s.sessionId,senderPubKey:t})}async sendPage(e){if(this.#e!=="sender")throw new Error("sendPage() can only be called by sender");if(!this.isConnected||!this.#r)throw new Error(`Cannot send page in state "${this.#i}" (not connected)`);let t=e.id||f("page_"),r=typeof e.pageIndex=="number"?e.pageIndex:0,s=e.mimeType||"image/jpeg",o=await J(e.blob),i=o.byteLength,a=Math.max(1,Math.ceil(i/this.#a));this.#o("sending");let h={type:"page_start",pageId:t,pageIndex:r,mimeType:s,totalBytes:i,totalChunks:a,metadata:e.metadata||{}},d=await l(this.#r,h);this.#t.send({type:"envelope",iv:d.iv,ciphertext:d.ciphertext});let c=0;for(let p=0;p<a;p++){let k=p*this.#a,_=Math.min(k+this.#a,i),S=o.subarray(k,_),C=await l(this.#r,S);this.#t.send({type:"chunk_envelope",pageId:t,chunkIndex:p,totalChunks:a,iv:C.iv,ciphertext:C.ciphertext}),c+=S.length;let D={role:"sender",pageId:t,pageIndex:r,chunkIndex:p,totalChunks:a,bytesSent:c,totalBytes:i,percent:Math.round(c/i*100)};this.#c("progress",D)}let I={type:"page_end",pageId:t,totalBytes:i},v=await l(this.#r,I);this.#t.send({type:"envelope",iv:v.iv,ciphertext:v.ciphertext}),this.#o("connected")}async complete(e={}){if(this.#e!=="sender")throw new Error("complete() can only be called by sender");if(!this.#r)throw new Error("Session is not authenticated");let t={type:"session_complete",docId:e.docId||f("doc_"),summary:e.summary||{},completedAt:Date.now()},r=await l(this.#r,t);this.#t.send({type:"envelope",iv:r.iv,ciphertext:r.ciphertext}),this.#o("complete"),this.#c("complete",t)}async#w(e){if(!(!e||typeof e!="object"))try{this.#e==="host"?await this.#g(e):await this.#b(e)}catch(t){this.#u(t)}}async#g(e){if(e.type==="handshake_init"){if(!this.#s)throw new Error("Host session not initialized");if(e.sessionId!==this.#s.sessionId)throw new Error("Session ID mismatch in handshake");if(Date.now()>this.#s.expiresAt)throw this.#o("expired"),new Error("Handoff session token expired");let t=await b(e.senderPubKey);this.#r=await x(this.#n.privateKey,t);let r=await l(this.#r,{type:"handshake_ack",sessionId:this.#s.sessionId,status:"ready"});this.#t.send({type:"envelope",iv:r.iv,ciphertext:r.ciphertext}),clearTimeout(this.#p),this.#o("connected");return}if(e.type==="chunk_envelope"){if(!this.#r)throw new Error("Received chunk before handshake completion");let t=this.#l.get(e.pageId);if(!t)throw new Error(`Received chunk for unknown page: ${e.pageId}`);let r=await E(this.#r,e.iv,e.ciphertext);t.chunks[e.chunkIndex]=r,t.receivedBytes+=r.length;let s={role:"host",pageId:e.pageId,pageIndex:t.start.pageIndex,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,bytesReceived:t.receivedBytes,totalBytes:t.start.totalBytes,percent:Math.round(t.receivedBytes/t.start.totalBytes*100)};this.#c("progress",s);return}if(e.type==="envelope"){if(!this.#r)throw new Error("Received envelope before handshake completion");let t=await T(this.#r,e.iv,e.ciphertext);if(t.type==="page_start"){this.#l.set(t.pageId,{start:t,chunks:Array.from({length:t.totalChunks}),receivedBytes:0}),this.#o("receiving");return}if(t.type==="page_end"){let r=this.#l.get(t.pageId);if(!r)throw new Error(`Received page_end for unknown page: ${t.pageId}`);let s=r.start.mimeType||"image/jpeg",o;if(typeof globalThis.Blob=="function")o=new globalThis.Blob(r.chunks,{type:s});else{let a=r.chunks.reduce((c,I)=>c+I.length,0),h=new Uint8Array(a),d=0;for(let c of r.chunks)h.set(c,d),d+=c.length;o=h}let i={id:t.pageId,pageIndex:r.start.pageIndex,mimeType:s,blob:o,metadata:r.start.metadata};this.#f.push(i),this.#l.delete(t.pageId),this.#c("page",i),this.#o("connected");return}if(t.type==="session_complete"){let r={docId:t.docId,pageCount:this.#f.length,pages:[...this.#f],summary:t.summary};this.#o("complete"),this.#c("complete",r);return}}}async#b(e){if(e.type==="envelope"){if(!this.#r)throw new Error("Received envelope without shared key");(await T(this.#r,e.iv,e.ciphertext)).type==="handshake_ack"&&this.#o("connected")}}async getConnectionInfo(){return this.#t&&typeof this.#t.getConnectionInfo=="function"?await this.#t.getConnectionInfo():{transport:"direct",rttMs:0}}close(){if(clearTimeout(this.#p),this.#t){try{this.#t.close()}catch{}this.#t=null}this.#n=null,this.#r=null,this.#l.clear(),this.#f=[],this.#o("closed")}};export{w as a,g as b,b as c,x as d,l as e,E as f,L as g,N as h,f as i,B as j,M as k,z as l,F as m,m as n,U as o};
2
+ //# sourceMappingURL=chunk-VPSUKD6F.js.map
@@ -0,0 +1,2 @@
1
+ var x=Object.freeze({topLeft:Object.freeze({x:.05,y:.05}),topRight:Object.freeze({x:.95,y:.05}),bottomRight:Object.freeze({x:.95,y:.95}),bottomLeft:Object.freeze({x:.05,y:.95})});function p(t=x){return{topLeft:{x:Number(t.topLeft?.x??.05),y:Number(t.topLeft?.y??.05)},topRight:{x:Number(t.topRight?.x??.95),y:Number(t.topRight?.y??.05)},bottomRight:{x:Number(t.bottomRight?.x??.95),y:Number(t.bottomRight?.y??.95)},bottomLeft:{x:Number(t.bottomLeft?.x??.05),y:Number(t.bottomLeft?.y??.95)}}}function c(t){if(!t)return{x:.05,y:.05,w:.9,h:.9};let o=[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft],r=Math.max(0,Math.min(...o.map(e=>Number(e?.x??0)))),b=Math.min(1,Math.max(...o.map(e=>Number(e?.x??1)))),m=Math.max(0,Math.min(...o.map(e=>Number(e?.y??0)))),a=Math.min(1,Math.max(...o.map(e=>Number(e?.y??1)))),h=Math.max(.01,Math.min(1-r,b-r)),i=Math.max(.01,Math.min(1-m,a-m));return{x:Math.round(r*1e3)/1e3,y:Math.round(m*1e3)/1e3,w:Math.round(h*1e3)/1e3,h:Math.round(i*1e3)/1e3}}var n=class{async detect(o,r={}){throw new Error("EdgeDetectorPort.detect() must be implemented by adapter")}async getEdgeWorker(){throw new Error("EdgeDetectorPort.getEdgeWorker() must be implemented by adapter")}async terminateEdgeWorker(){throw new Error("EdgeDetectorPort.terminateEdgeWorker() must be implemented by adapter")}};export{x as a,p as b,c,n as d};
2
+ //# sourceMappingURL=chunk-ZILTJGT2.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,r as K,s as L,t as M}from"./chunk-O7IV7A6O.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};
1
+ import{a as B,b as C,c as D,d as E,e as F,f as G,g as H,h as U,i as V,j as W,k as X,l as Y,m as Z}from"./chunk-TK5N67RB.js";import{a as I,b as J}from"./chunk-HCCNUPKB.js";import{a as Q}from"./chunk-PSGIWIRH.js";import{a as M,b as N,c as O,d as P}from"./chunk-ZILTJGT2.js";import{a as L}from"./chunk-5OTO5WFV.js";import"./chunk-O6FQFVKY.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 o,l as p,m as q,n as r,o as s,p as t,q as u,r as v,s as w,t as x,u as y,v as z,w as A,x as S}from"./chunk-GU6OQMYK.js";import{a as T}from"./chunk-KH5JE65X.js";import{a as R}from"./chunk-ULTSZWZO.js";import{c as d}from"./chunk-6QK7337A.js";import{a as b}from"./chunk-NNSM2I5L.js";import{d as c}from"./chunk-JIPKWRBK.js";import{a}from"./chunk-4D6GC55I.js";import{a as K}from"./chunk-U3V3VZGO.js";import"./chunk-6DSLE3AY.js";import"./chunk-ZT72PD2C.js";import"./chunk-25WAHT3G.js";export{G as BUILD_DATE,I as COPIO_EVENTS,B as CURRENT_SCHEMA_VERSION,S as Canvas2DAdapter,Z as CopioEngine,V as DEFAULT_EXPORT_FORMATS,M as DEFAULT_FALLBACK_QUAD,U as DEFAULT_FEATURES,C as DEFAULT_MIGRATIONS,W as DEFAULT_OCR_LANGUAGES,E as DocRepository,p as Document,P as EdgeDetectorPort,R as ImageProcessorPort,c as IndexedDbStorageAdapter,b as MemoryStorageAdapter,D as MigrationRunner,Q as NullEdgeDetectorAdapter,T as NullImageProcessorAdapter,K as NullOcrAdapter,L as NullPdfAdapter,o as Page,q as ScanSession,a as StoragePort,H as VERSION,A as applyEdits,u as applySauvolaToImageData,N as cloneQuad,d as createDefaultAdapter,j as cropOriginalToRotated,f as cropRectToQuad,k as cropRotatedToOriginal,J as dispatchCopioEvent,F as docRepository,r as extractExif,t as fileToBase64,x as getCroppedSrc,Y as getRegisteredService,h as hasActiveEdits,g as normalizeEditStack,y as normalizeEdits,e as normalizeQuad,m as quadOriginalToRotated,n as quadRotatedToOriginal,O as quadToCropRect,s as randomId,X as registerService,z as renderEditsToCanvas,i as rotateCrop,l as rotateQuad,w as rotateSrc,v as thresholdSrc};
2
2
  //# sourceMappingURL=core.js.map