@copio/sdk 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as Ue,b as He,c as Me,d as ze}from"./chunk-Q3AWHANC.js";import{a as re,b as se,c as ie,d as ae,e as c,f as xe,g as ye,k as a,l as De,m as _e}from"./chunk-TK5N67RB.js";import{a as s,b as R,c as We}from"./chunk-NQW6FFN7.js";import{a as $,b as w,c as E,d as I}from"./chunk-2VH2NPXW.js";import{i as S,j as T,k as A,l as C,m as v,n as O,o as P}from"./chunk-VPSUKD6F.js";import{a as be,b as Se}from"./chunk-HCCNUPKB.js";import"./chunk-V2D55DVU.js";import{a as y}from"./chunk-GLY5CGCY.js";import"./chunk-CWCS22CQ.js";import{a as Ge,b as x}from"./chunk-NM4YYZYB.js";import"./chunk-V6E2SSSW.js";import{a as je}from"./chunk-T5CPA7B2.js";import{a as qe}from"./chunk-2AB5L3Y2.js";import{a as Ve}from"./chunk-NEEWG3OP.js";import"./chunk-PUJYN435.js";import{a as u}from"./chunk-4ICUYKSR.js";import{a as Ee}from"./chunk-PSGIWIRH.js";import{a as Oe,b as Pe,c as $e,d as we}from"./chunk-ZILTJGT2.js";import{a as ve}from"./chunk-5OTO5WFV.js";import{a as Ce}from"./chunk-O6FQFVKY.js";import"./chunk-4GEMGDRU.js";import{a as F,b as K,c as W,d as B,h as Q,i as G,j as V,k as j,l as q,m as J,n as Z,o as X,p as Y,r as ee,s as te,t as oe,x as p}from"./chunk-GU6OQMYK.js";import{a as Re}from"./chunk-KH5JE65X.js";import{a as Ie}from"./chunk-ULTSZWZO.js";import{a as H,b as M,c as z}from"./chunk-6QK7337A.js";import{a as L}from"./chunk-NNSM2I5L.js";import{d as U}from"./chunk-JIPKWRBK.js";import{a as N}from"./chunk-4D6GC55I.js";import{a as Ae}from"./chunk-U3V3VZGO.js";import{a as Te}from"./chunk-6DSLE3AY.js";import{a as m}from"./chunk-R6Q4OXDG.js";import"./chunk-SZHKZARU.js";import{a as g,b as Fe,c as Ke,d as f,e as h}from"./chunk-FAVTIE3M.js";import{a as Be,b as Qe,c as D}from"./chunk-PBF7V4Z6.js";import{a as ke,b as Ne,c as Le,d as n}from"./chunk-YNY65JUJ.js";import{a as ne,b as le,c as ce,d as de,e as pe,f as ge,g as fe,h as he,i as me,j as ue}from"./chunk-ZT72PD2C.js";import"./chunk-25WAHT3G.js";var d=class extends R{#e=null;static properties={isOpen:{type:Boolean,state:!0},docId:{type:String,state:!0},docName:{type:String,state:!0},pages:{type:Array,state:!0},lang:{type:String,state:!0},step:{type:String,state:!0},progress:{type:Number,state:!0},statusMessage:{type:String,state:!0},resultText:{type:String,state:!0},confidence:{type:Number,state:!0},copied:{type:Boolean,state:!0}};createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.#e&&(this.#e.abort(),this.#e=null),h(),this.isOpen=!1}constructor(){super(),this.isOpen=!1,this.docId="",this.docName="",this.pages=[],this.lang="eng",this.step="processing",this.progress=0,this.statusMessage="Starting OCR engine...",this.resultText="",this.confidence=0,this.copied=!1,this._pageIndex=null,this.#e=null}open(e,r,o,t="eng"){this._pageIndex=null,this._openInternal(e,r,o,t)}openPage(e,r,o,t,i="eng"){this._pageIndex=t,this._openInternal(e,r,[o],i)}_openInternal(e,r,o,t){if(this.#e&&(this.#e.abort(),this.#e=null),this.docId=e,this.docName=r||"Document",this.pages=o||[],this.lang=t,this.progress=0,this.resultText="",this.confidence=0,this.copied=!1,(this.pages||[]).filter(l=>l.src).length===0){this.step="empty",this.statusMessage="This document does not contain any image pages for text recognition.",this.isOpen=!0;return}this.step="processing",this.statusMessage=typeof window<"u"&&!window.Tesseract?"Downloading OCR engine...":"Starting OCR engine...",this.isOpen=!0,this.startOcr(t)}cancel=()=>{this.#e&&(this.#e.abort(),this.#e=null),this.close()};close=()=>{this.#e&&(this.#e.abort(),this.#e=null),this.isOpen=!1};async startOcr(e="eng"){this.#e&&(this.#e.abort(),this.#e=null),this.#e=new AbortController;let{signal:r}=this.#e;try{let o=await f(this.pages,{lang:e,abortSignal:r,onPageProgress:({overallProgress:t,message:i})=>{this.isOpen&&!r.aborted&&(this.progress=Math.round((t||0)*100),this.statusMessage=i)}});if(this.isOpen&&!r.aborted&&(this.step="done",this.resultText=o.combinedText||"",this.confidence=o.averageConfidence||0,n.success("Text recognition complete"),this.docId&&Array.isArray(o.pagesResults)))try{let t=await c.getDoc(this.docId);if(t&&Array.isArray(t.pages)){for(let i of o.pagesResults){let l=t.pages.find(k=>k.id===i.pageId)||t.pages[i.pageIndex];l&&(l.ocrText=i.text,l.ocrConfidence=i.confidence,l.ocrWords=i.words)}await c.saveDoc(this.docId,t)}}catch(t){console.warn("Could not persist OCR results to document:",t)}}catch(o){if(o.name==="AbortError"||r.aborted)return;console.error("Document OCR Error:",o),this.isOpen&&(this.step="error",this.statusMessage=o.message||"Text recognition failed",n.error(o.message||"Text recognition failed"))}finally{this.#e?.signal===r&&(this.#e=null)}}handleLangChange=e=>{let r=e.target.value;this.lang=r,this.step="processing",this.progress=0,this.statusMessage="Starting OCR engine with new language...",this.startOcr(r)};handleTextInput=e=>{this.resultText=e.target.value};copyText=async()=>{if(this.resultText)try{await navigator.clipboard.writeText(this.resultText),this.copied=!0,n.success("Copied text to clipboard"),setTimeout(()=>{this.copied=!1},2e3)}catch(e){console.error("Failed to copy text:",e),n.error("Failed to copy text to clipboard")}};downloadText=()=>{if(!this.resultText)return;let e=(this.docName||"document").replace(/[/\\?%*:|"<>]/g,"_"),r=new Blob([this.resultText],{type:"text/plain;charset=utf-8"}),o=URL.createObjectURL(r),t=document.createElement("a");t.href=o,t.download=`${e}-ocr.txt`,t.click(),URL.revokeObjectURL(o),n.success(`Exported OCR text (${e}-ocr.txt)`)};get _isSinglePage(){return this._pageIndex!==null}get _dialogLabel(){return this._isSinglePage?`Extract Text \u2014 ${this.docName} (Page ${this._pageIndex+1})`:`Extract All Text \u2014 ${this.docName}`}render(){return this.isOpen?s`
1
+ import{a as Ue,b as He,c as Me,d as ze}from"./chunk-Q7SOUI6D.js";import{a as re,b as se,c as ie,d as ae,e as c,f as xe,g as ye,k as a,l as De,m as _e}from"./chunk-WZZ7FNDX.js";import{a as s,b as R,c as We}from"./chunk-NQW6FFN7.js";import{a as $,b as w,c as E,d as I}from"./chunk-2VH2NPXW.js";import{i as S,j as T,k as A,l as C,m as v,n as O,o as P}from"./chunk-VPSUKD6F.js";import{a as be,b as Se}from"./chunk-HCCNUPKB.js";import"./chunk-V2D55DVU.js";import{a as y}from"./chunk-GLY5CGCY.js";import"./chunk-CWCS22CQ.js";import{a as Ge,b as x}from"./chunk-NM4YYZYB.js";import"./chunk-V6E2SSSW.js";import{a as je}from"./chunk-T5CPA7B2.js";import{a as qe}from"./chunk-2AB5L3Y2.js";import{a as Ve}from"./chunk-NEEWG3OP.js";import"./chunk-PUJYN435.js";import{a as u}from"./chunk-4ICUYKSR.js";import{a as Ee}from"./chunk-PSGIWIRH.js";import{a as Oe,b as Pe,c as $e,d as we}from"./chunk-ZILTJGT2.js";import{a as ve}from"./chunk-5OTO5WFV.js";import{a as Ce}from"./chunk-O6FQFVKY.js";import"./chunk-4GEMGDRU.js";import{a as F,b as K,c as W,d as B,h as Q,i as G,j as V,k as j,l as q,m as J,n as Z,o as X,p as Y,r as ee,s as te,t as oe,x as p}from"./chunk-GU6OQMYK.js";import{a as Re}from"./chunk-KH5JE65X.js";import{a as Ie}from"./chunk-ULTSZWZO.js";import{a as H,b as M,c as z}from"./chunk-6QK7337A.js";import{a as L}from"./chunk-NNSM2I5L.js";import{d as U}from"./chunk-JIPKWRBK.js";import{a as N}from"./chunk-4D6GC55I.js";import{a as Ae}from"./chunk-U3V3VZGO.js";import{a as Te}from"./chunk-6DSLE3AY.js";import{a as m}from"./chunk-R6Q4OXDG.js";import"./chunk-SZHKZARU.js";import{a as g,b as Fe,c as Ke,d as f,e as h}from"./chunk-FAVTIE3M.js";import{a as Be,b as Qe,c as D}from"./chunk-PBF7V4Z6.js";import{a as ke,b as Ne,c as Le,d as n}from"./chunk-YNY65JUJ.js";import{a as ne,b as le,c as ce,d as de,e as pe,f as ge,g as fe,h as he,i as me,j as ue}from"./chunk-ZT72PD2C.js";import"./chunk-25WAHT3G.js";var d=class extends R{#e=null;static properties={isOpen:{type:Boolean,state:!0},docId:{type:String,state:!0},docName:{type:String,state:!0},pages:{type:Array,state:!0},lang:{type:String,state:!0},step:{type:String,state:!0},progress:{type:Number,state:!0},statusMessage:{type:String,state:!0},resultText:{type:String,state:!0},confidence:{type:Number,state:!0},copied:{type:Boolean,state:!0}};createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback(),this.#e&&(this.#e.abort(),this.#e=null),h(),this.isOpen=!1}constructor(){super(),this.isOpen=!1,this.docId="",this.docName="",this.pages=[],this.lang="eng",this.step="processing",this.progress=0,this.statusMessage="Starting OCR engine...",this.resultText="",this.confidence=0,this.copied=!1,this._pageIndex=null,this.#e=null}open(e,r,o,t="eng"){this._pageIndex=null,this._openInternal(e,r,o,t)}openPage(e,r,o,t,i="eng"){this._pageIndex=t,this._openInternal(e,r,[o],i)}_openInternal(e,r,o,t){if(this.#e&&(this.#e.abort(),this.#e=null),this.docId=e,this.docName=r||"Document",this.pages=o||[],this.lang=t,this.progress=0,this.resultText="",this.confidence=0,this.copied=!1,(this.pages||[]).filter(l=>l.src).length===0){this.step="empty",this.statusMessage="This document does not contain any image pages for text recognition.",this.isOpen=!0;return}this.step="processing",this.statusMessage=typeof window<"u"&&!window.Tesseract?"Downloading OCR engine...":"Starting OCR engine...",this.isOpen=!0,this.startOcr(t)}cancel=()=>{this.#e&&(this.#e.abort(),this.#e=null),this.close()};close=()=>{this.#e&&(this.#e.abort(),this.#e=null),this.isOpen=!1};async startOcr(e="eng"){this.#e&&(this.#e.abort(),this.#e=null),this.#e=new AbortController;let{signal:r}=this.#e;try{let o=await f(this.pages,{lang:e,abortSignal:r,onPageProgress:({overallProgress:t,message:i})=>{this.isOpen&&!r.aborted&&(this.progress=Math.round((t||0)*100),this.statusMessage=i)}});if(this.isOpen&&!r.aborted&&(this.step="done",this.resultText=o.combinedText||"",this.confidence=o.averageConfidence||0,n.success("Text recognition complete"),this.docId&&Array.isArray(o.pagesResults)))try{let t=await c.getDoc(this.docId);if(t&&Array.isArray(t.pages)){for(let i of o.pagesResults){let l=t.pages.find(k=>k.id===i.pageId)||t.pages[i.pageIndex];l&&(l.ocrText=i.text,l.ocrConfidence=i.confidence,l.ocrWords=i.words)}await c.saveDoc(this.docId,t)}}catch(t){console.warn("Could not persist OCR results to document:",t)}}catch(o){if(o.name==="AbortError"||r.aborted)return;console.error("Document OCR Error:",o),this.isOpen&&(this.step="error",this.statusMessage=o.message||"Text recognition failed",n.error(o.message||"Text recognition failed"))}finally{this.#e?.signal===r&&(this.#e=null)}}handleLangChange=e=>{let r=e.target.value;this.lang=r,this.step="processing",this.progress=0,this.statusMessage="Starting OCR engine with new language...",this.startOcr(r)};handleTextInput=e=>{this.resultText=e.target.value};copyText=async()=>{if(this.resultText)try{await navigator.clipboard.writeText(this.resultText),this.copied=!0,n.success("Copied text to clipboard"),setTimeout(()=>{this.copied=!1},2e3)}catch(e){console.error("Failed to copy text:",e),n.error("Failed to copy text to clipboard")}};downloadText=()=>{if(!this.resultText)return;let e=(this.docName||"document").replace(/[/\\?%*:|"<>]/g,"_"),r=new Blob([this.resultText],{type:"text/plain;charset=utf-8"}),o=URL.createObjectURL(r),t=document.createElement("a");t.href=o,t.download=`${e}-ocr.txt`,t.click(),URL.revokeObjectURL(o),n.success(`Exported OCR text (${e}-ocr.txt)`)};get _isSinglePage(){return this._pageIndex!==null}get _dialogLabel(){return this._isSinglePage?`Extract Text \u2014 ${this.docName} (Page ${this._pageIndex+1})`:`Extract All Text \u2014 ${this.docName}`}render(){return this.isOpen?s`
2
2
  <sl-dialog
3
3
  label="${this._dialogLabel}"
4
4
  open