nano-ai-pdf
Version:
This package helps you summarize pdfs using Gemini nano on edge or on browser, making it compliant safe, faster and free
1 lines • 374 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),e=require("react");function i(t,e,i,s){return new(i||(i=Promise))(function(n,a){function r(t){try{l(s.next(t))}catch(t){a(t)}}function o(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,o)}l((s=s.apply(t,e||[])).next())})}function s(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],s=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(t){return this instanceof n?(this.v=t,this):new n(t)}function a(t,e,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s,a=i.apply(t,e||[]),r=[];return s=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",function(t){return function(e){return Promise.resolve(e).then(t,c)}}),s[Symbol.asyncIterator]=function(){return this},s;function o(t,e){a[t]&&(s[t]=function(e){return new Promise(function(i,s){r.push([t,e,i,s])>1||l(t,e)})},e&&(s[t]=e(s[t])))}function l(t,e){try{(i=a[t](e)).value instanceof n?Promise.resolve(i.value.v).then(h,c):d(r[0][2],i)}catch(t){d(r[0][3],t)}var i}function h(t){l("next",t)}function c(t){l("throw",t)}function d(t,e){t(e),r.shift(),r.length&&l(r[0][0],r[0][1])}}function r(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,i=t[Symbol.asyncIterator];return i?i.call(t):(t=s(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(i){e[i]=t[i]&&function(e){return new Promise(function(s,n){(function(t,e,i,s){Promise.resolve(s).then(function(e){t({value:e,done:i})},e)})(s,n,(e=t[i](e)).done,e.value)})}}}function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function l(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var i=function t(){var i=!1;try{i=this instanceof t}catch{}return i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})}),i}"function"==typeof SuppressedError&&SuppressedError;var h={},c={},d={d:(t,e)=>{for(var i in e)d.o(e,i)&&!d.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},u=globalThis.pdfjsLib={};d.d(u,{AbortException:()=>Et,AnnotationEditorLayer:()=>En,AnnotationEditorParamsType:()=>T,AnnotationEditorType:()=>C,AnnotationEditorUIManager:()=>ve,AnnotationLayer:()=>cn,AnnotationMode:()=>S,ColorPicker:()=>An,DOMSVGFactory:()=>Rs,DrawLayer:()=>Sn,FeatureTest:()=>Mt,GlobalWorkerOptions:()=>fi,ImageKind:()=>F,InvalidPDFException:()=>At,MissingPDFException:()=>wt,OPS:()=>rt,OutputScale:()=>he,PDFDataRangeTransport:()=>fs,PDFDateString:()=>se,PDFWorker:()=>ys,PasswordResponses:()=>ot,PermissionFlag:()=>M,PixelsPerInch:()=>Vt,RenderingCancelledException:()=>Xt,TextLayer:()=>as,UnexpectedResponseException:()=>_t,Util:()=>Pt,VerbosityLevel:()=>at,XfaLayer:()=>Is,build:()=>Cs,createValidAbsoluteUrl:()=>ft,fetchData:()=>Wt,getDocument:()=>us,getFilenameFromUrl:()=>Jt,getPdfFilenameFromUrl:()=>Qt,getXfaPageViewport:()=>ne,isDataScheme:()=>Kt,isPdfFile:()=>Yt,noContextMenu:()=>ee,normalizeUnicode:()=>Dt,setLayerDimensions:()=>le,shadow:()=>mt,version:()=>Ss});const p=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),g=[1,0,0,1,0,0],f=[.001,0,0,.001,0,0],m=1.35,b=1,v=2,y=4,A=16,w=32,_=64,x=128,E=256,S={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},C={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},T={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35},M={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},k=0,P=1,R=2,I=3,D=3,L=4,F={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},O=1,N=2,j=3,B=4,z=5,H=6,U=7,$=8,G=9,V=10,W=11,q=12,X=13,K=14,Y=15,J=16,Q=17,Z=20,tt=1,et=2,it=3,st=4,nt=5,at={ERRORS:0,WARNINGS:1,INFOS:5},rt={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},ot={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let lt=at.WARNINGS;function ht(t){Number.isInteger(t)&&(lt=t)}function ct(){return lt}function dt(t){lt>=at.INFOS&&console.log(`Info: ${t}`)}function ut(t){lt>=at.WARNINGS&&console.log(`Warning: ${t}`)}function pt(t){throw new Error(t)}function gt(t,e){t||pt(e)}function ft(t,e=null,i=null){if(!t)return null;try{if(i&&"string"==typeof t){if(i.addDefaultProtocol&&t.startsWith("www.")){const e=t.match(/\./g);e?.length>=2&&(t=`http://${t}`)}if(i.tryConvertEncoding)try{t=decodeURIComponent(escape(t))}catch{}}const s=e?new URL(t,e):new URL(t);if(function(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(s))return s}catch{}return null}function mt(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}const bt=function(){function t(t,e){this.message=t,this.name=e}return t.prototype=new Error,t.constructor=t,t}();class vt extends bt{constructor(t,e){super(t,"PasswordException"),this.code=e}}class yt extends bt{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class At extends bt{constructor(t){super(t,"InvalidPDFException")}}class wt extends bt{constructor(t){super(t,"MissingPDFException")}}class _t extends bt{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class xt extends bt{constructor(t){super(t,"FormatError")}}class Et extends bt{constructor(t){super(t,"AbortException")}}function St(t){"object"==typeof t&&void 0!==t?.length||pt("Invalid argument for bytesToString");const e=t.length,i=8192;if(e<i)return String.fromCharCode.apply(null,t);const s=[];for(let n=0;n<e;n+=i){const a=Math.min(n+i,e),r=t.subarray(n,a);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Ct(t){"string"!=typeof t&&pt("Invalid argument for stringToBytes");const e=t.length,i=new Uint8Array(e);for(let s=0;s<e;++s)i[s]=255&t.charCodeAt(s);return i}function Tt(t){const e=Object.create(null);for(const[i,s]of t)e[i]=s;return e}class Mt{static get isLittleEndian(){return mt(this,"isLittleEndian",function(){const t=new Uint8Array(4);return t[0]=1,1===new Uint32Array(t.buffer,0,1)[0]}())}static get isEvalSupported(){return mt(this,"isEvalSupported",function(){try{return new Function(""),!0}catch{return!1}}())}static get isOffscreenCanvasSupported(){return mt(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get platform(){return"undefined"!=typeof navigator&&"string"==typeof navigator?.platform?mt(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:"string"==typeof navigator?.userAgent&&navigator.userAgent.includes("Firefox")}):mt(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){return mt(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const kt=Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0"));class Pt{static makeHexColor(t,e,i){return`#${kt[t]}${kt[e]}${kt[i]}`}static scaleMinMax(t,e){let i;t[0]?(t[0]<0&&(i=e[0],e[0]=e[2],e[2]=i),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[3],e[3]*=t[3]):(i=e[0],e[0]=e[1],e[1]=i,i=e[2],e[2]=e[3],e[3]=i,t[1]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(i=e[0],e[0]=e[2],e[2]=i),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){return[t[0]*e[0]+t[1]*e[2]+e[4],t[0]*e[1]+t[1]*e[3]+e[5]]}static applyInverseTransform(t,e){const i=e[0]*e[3]-e[1]*e[2];return[(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/i,(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/i]}static getAxialAlignedBoundingBox(t,e){const i=this.applyTransform(t,e),s=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),a=this.applyTransform([t[2],t[1]],e);return[Math.min(i[0],s[0],n[0],a[0]),Math.min(i[1],s[1],n[1],a[1]),Math.max(i[0],s[0],n[0],a[0]),Math.max(i[1],s[1],n[1],a[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],i=t[0]*e[0]+t[1]*e[2],s=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],a=t[2]*e[1]+t[3]*e[3],r=(i+a)/2,o=Math.sqrt((i+a)**2-4*(i*a-n*s))/2,l=r+o||1,h=r-o||1;return[Math.sqrt(l),Math.sqrt(h)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const i=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),s=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(i>s)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),a=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>a?null:[i,n,s,a]}static#t(t,e,i,s,n,a,r,o,l,h){if(l<=0||l>=1)return;const c=1-l,d=l*l,u=d*l,p=c*(c*(c*t+3*l*e)+3*d*i)+u*s,g=c*(c*(c*n+3*l*a)+3*d*r)+u*o;h[0]=Math.min(h[0],p),h[1]=Math.min(h[1],g),h[2]=Math.max(h[2],p),h[3]=Math.max(h[3],g)}static#e(t,e,i,s,n,a,r,o,l,h,c,d){if(Math.abs(l)<1e-12)return void(Math.abs(h)>=1e-12&&this.#t(t,e,i,s,n,a,r,o,-c/h,d));const u=h**2-4*c*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,s,n,a,r,o,(-h+p)/g,d),this.#t(t,e,i,s,n,a,r,o,(-h-p)/g,d)}static bezierBoundingBox(t,e,i,s,n,a,r,o,l){return l?(l[0]=Math.min(l[0],t,r),l[1]=Math.min(l[1],e,o),l[2]=Math.max(l[2],t,r),l[3]=Math.max(l[3],e,o)):l=[Math.min(t,r),Math.min(e,o),Math.max(t,r),Math.max(e,o)],this.#e(t,i,n,r,e,s,a,o,3*(3*(i-n)-t+r),6*(t-2*i+n),3*(i-t),l),this.#e(t,i,n,r,e,s,a,o,3*(3*(s-a)-e+o),6*(e-2*s+a),3*(s-e),l),l}}let Rt=null,It=null;function Dt(t){return Rt||(Rt=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,It=new Map([["ſt","ſt"]])),t.replaceAll(Rt,(t,e,i)=>e?e.normalize("NFKC"):It.get(i))}const Lt="pdfjs_internal_id_",Ft=0,Ot=1,Nt=2,jt=3,Bt=4,zt=5,Ht=6,Ut=7,$t=8;const Gt="http://www.w3.org/2000/svg";class Vt{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function Wt(t,e="text"){if(te(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"arraybuffer":return i.arrayBuffer();case"blob":return i.blob();case"json":return i.json()}return i.text()}return new Promise((i,s)=>{const n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType=e,n.onreadystatechange=()=>{if(n.readyState===XMLHttpRequest.DONE)if(200!==n.status&&0!==n.status)s(new Error(n.statusText));else{switch(e){case"arraybuffer":case"blob":case"json":return void i(n.response)}i(n.responseText)}},n.send(null)})}class qt{constructor({viewBox:t,scale:e,rotation:i,offsetX:s=0,offsetY:n=0,dontFlip:a=!1}){this.viewBox=t,this.scale=e,this.rotation=i,this.offsetX=s,this.offsetY=n;const r=(t[2]+t[0])/2,o=(t[3]+t[1])/2;let l,h,c,d,u,p,g,f;switch((i%=360)<0&&(i+=360),i){case 180:l=-1,h=0,c=0,d=1;break;case 90:l=0,h=1,c=1,d=0;break;case 270:l=0,h=-1,c=-1,d=0;break;case 0:l=1,h=0,c=0,d=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(c=-c,d=-d),0===l?(u=Math.abs(o-t[1])*e+s,p=Math.abs(r-t[0])*e+n,g=(t[3]-t[1])*e,f=(t[2]-t[0])*e):(u=Math.abs(r-t[0])*e+s,p=Math.abs(o-t[1])*e+n,g=(t[2]-t[0])*e,f=(t[3]-t[1])*e),this.transform=[l*e,h*e,c*e,d*e,u-l*e*r-c*e*o,p-h*e*r-d*e*o],this.width=g,this.height=f}get rawDims(){const{viewBox:t}=this;return mt(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:i=this.offsetX,offsetY:s=this.offsetY,dontFlip:n=!1}={}){return new qt({viewBox:this.viewBox.slice(),scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}convertToViewportPoint(t,e){return Pt.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=Pt.applyTransform([t[0],t[1]],this.transform),i=Pt.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],i[0],i[1]]}convertToPdfPoint(t,e){return Pt.applyInverseTransform([t,e],this.transform)}}class Xt extends bt{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Kt(t){const e=t.length;let i=0;for(;i<e&&""===t[i].trim();)i++;return"data:"===t.substring(i,i+5).toLowerCase()}function Yt(t){return"string"==typeof t&&/\.pdf$/i.test(t)}function Jt(t){return[t]=t.split(/[#?]/,1),t.substring(t.lastIndexOf("/")+1)}function Qt(t,e="document.pdf"){if("string"!=typeof t)return e;if(Kt(t))return ut('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),e;const i=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,s=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/.exec(t);let n=i.exec(s[1])||i.exec(s[2])||i.exec(s[3]);if(n&&(n=n[0],n.includes("%")))try{n=i.exec(decodeURIComponent(n))[0]}catch{}return n||e}class Zt{started=Object.create(null);times=[];time(t){t in this.started&&ut(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||ut(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:t}of this.times)e=Math.max(t.length,e);for(const{name:i,start:s,end:n}of this.times)t.push(`${i.padEnd(e)} ${n-s}ms\n`);return t.join("")}}function te(t,e){try{const{protocol:i}=e?new URL(t,e):new URL(t);return"http:"===i||"https:"===i}catch{return!1}}function ee(t){t.preventDefault()}function ie(t){console.log("Deprecated API usage: "+t)}class se{static#i;static toDateObject(t){if(!t||"string"!=typeof t)return null;this.#i||=new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#i.exec(t);if(!e)return null;const i=parseInt(e[1],10);let s=parseInt(e[2],10);s=s>=1&&s<=12?s-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let a=parseInt(e[4],10);a=a>=0&&a<=23?a:0;let r=parseInt(e[5],10);r=r>=0&&r<=59?r:0;let o=parseInt(e[6],10);o=o>=0&&o<=59?o:0;const l=e[7]||"Z";let h=parseInt(e[8],10);h=h>=0&&h<=23?h:0;let c=parseInt(e[9],10)||0;return c=c>=0&&c<=59?c:0,"-"===l?(a+=h,r+=c):"+"===l&&(a-=h,r-=c),new Date(Date.UTC(i,s,n,a,r,o))}}function ne(t,{scale:e=1,rotation:i=0}){const{width:s,height:n}=t.attributes.style,a=[0,0,parseInt(s),parseInt(n)];return new qt({viewBox:a,scale:e,rotation:i})}function ae(t){if(t.startsWith("#")){const e=parseInt(t.slice(1),16);return[(16711680&e)>>16,(65280&e)>>8,255&e]}return t.startsWith("rgb(")?t.slice(4,-1).split(",").map(t=>parseInt(t)):t.startsWith("rgba(")?t.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(ut(`Not a valid color format: "${t}"`),[0,0,0])}function re(t){const{a:e,b:i,c:s,d:n,e:a,f:r}=t.getTransform();return[e,i,s,n,a,r]}function oe(t){const{a:e,b:i,c:s,d:n,e:a,f:r}=t.getTransform().invertSelf();return[e,i,s,n,a,r]}function le(t,e,i=!1,s=!0){if(e instanceof qt){const{pageWidth:s,pageHeight:n}=e.rawDims,{style:a}=t,r=Mt.isCSSRoundSupported,o=`var(--scale-factor) * ${s}px`,l=`var(--scale-factor) * ${n}px`,h=r?`round(down, ${o}, var(--scale-round-x, 1px))`:`calc(${o})`,c=r?`round(down, ${l}, var(--scale-round-y, 1px))`:`calc(${l})`;i&&e.rotation%180!=0?(a.width=c,a.height=h):(a.width=h,a.height=c)}s&&t.setAttribute("data-main-rotation",e.rotation)}class he{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return 1!==this.sx||1!==this.sy}get symmetric(){return this.sx===this.sy}}class ce{#s=null;#n=null;#a;#r=null;#o=null;static#l=null;constructor(t){this.#a=t,ce.#l||=Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"})}render(){const t=this.#s=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=this.#a._uiManager._signal;t.addEventListener("contextmenu",ee,{signal:e}),t.addEventListener("pointerdown",ce.#h,{signal:e});const i=this.#r=document.createElement("div");i.className="buttons",t.append(i);const s=this.#a.toolbarPosition;if(s){const{style:e}=t,i="ltr"===this.#a._uiManager.direction?1-s[0]:s[0];e.insetInlineEnd=100*i+"%",e.top=`calc(${100*s[1]}% + var(--editor-toolbar-vert-offset))`}return this.#c(),t}get div(){return this.#s}static#h(t){t.stopPropagation()}#d(t){this.#a._focusEventsAllowed=!1,t.preventDefault(),t.stopPropagation()}#u(t){this.#a._focusEventsAllowed=!0,t.preventDefault(),t.stopPropagation()}#p(t){const e=this.#a._uiManager._signal;t.addEventListener("focusin",this.#d.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#u.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ee,{signal:e})}hide(){this.#s.classList.add("hidden"),this.#n?.hideDropdown()}show(){this.#s.classList.remove("hidden"),this.#o?.shown()}#c(){const{editorType:t,_uiManager:e}=this.#a,i=document.createElement("button");i.className="delete",i.tabIndex=0,i.setAttribute("data-l10n-id",ce.#l[t]),this.#p(i),i.addEventListener("click",t=>{e.delete()},{signal:e._signal}),this.#r.append(i)}get#g(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#p(e),this.#r.prepend(e,this.#g),this.#o=t}addColorPicker(t){this.#n=t;const e=t.renderButton();this.#p(e),this.#r.prepend(e,this.#g)}remove(){this.#s.remove(),this.#n?.destroy(),this.#n=null}}class de{#r=null;#s=null;#f;constructor(t){this.#f=t}#m(){const t=this.#s=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ee,{signal:this.#f._signal});const e=this.#r=document.createElement("div");return e.className="buttons",t.append(e),this.#b(),t}#v(t,e){let i=0,s=0;for(const n of t){const t=n.y+n.height;if(t<i)continue;const a=n.x+(e?n.width:0);t>i?(s=a,i=t):e?a>s&&(s=a):a<s&&(s=a)}return[e?1-s:s,i]}show(t,e,i){const[s,n]=this.#v(e,i),{style:a}=this.#s||=this.#m();t.append(this.#s),a.insetInlineEnd=100*s+"%",a.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#s.remove()}#b(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const i=this.#f._signal;t.addEventListener("contextmenu",ee,{signal:i}),t.addEventListener("click",()=>{this.#f.highlightSelection("floating_button")},{signal:i}),this.#r.append(t)}}function ue(t,e,i){for(const s of i)e.addEventListener(s,t[s].bind(t))}class pe{#y=0;get id(){return"pdfjs_internal_editor_"+this.#y++}}class ge{#A=function(){if("undefined"!=typeof crypto&&"function"==typeof crypto?.randomUUID)return crypto.randomUUID();const t=new Uint8Array(32);if("undefined"!=typeof crypto&&"function"==typeof crypto?.getRandomValues)crypto.getRandomValues(t);else for(let e=0;e<32;e++)t[e]=Math.floor(255*Math.random());return St(t)}();#y=0;#w=null;static get _isSVGFittingCanvas(){const t=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),e=new Image;e.src='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>';return mt(this,"_isSVGFittingCanvas",e.decode().then(()=>(t.drawImage(e,0,0,1,1,0,0,1,3),0===new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0])))}async#_(t,e){this.#w||=new Map;let i=this.#w.get(t);if(null===i)return null;if(i?.bitmap)return i.refCounter+=1,i;try{let t;if(i||={bitmap:null,id:`image_${this.#A}_${this.#y++}`,refCounter:0,isSvg:!1},"string"==typeof e?(i.url=e,t=await Wt(e,"blob")):e instanceof File?t=i.file=e:e instanceof Blob&&(t=e),"image/svg+xml"===t.type){const e=ge._isSVGFittingCanvas,s=new FileReader,n=new Image,a=new Promise((t,a)=>{n.onload=()=>{i.bitmap=n,i.isSvg=!0,t()},s.onload=async()=>{const t=i.svgUrl=s.result;n.src=await e?`${t}#svgView(preserveAspectRatio(none))`:t},n.onerror=s.onerror=a});s.readAsDataURL(t),await a}else i.bitmap=await createImageBitmap(t);i.refCounter=1}catch(t){console.error(t),i=null}return this.#w.set(t,i),i&&this.#w.set(i.id,i),i}async getFromFile(t){const{lastModified:e,name:i,size:s,type:n}=t;return this.#_(`${e}_${i}_${s}_${n}`,t)}async getFromUrl(t){return this.#_(t,t)}async getFromBlob(t,e){const i=await e;return this.#_(t,i)}async getFromId(t){this.#w||=new Map;const e=this.#w.get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:t}=e;return delete e.blobPromise,this.getFromBlob(e.id,t)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#w||=new Map;let i=this.#w.get(t);if(i?.bitmap)return i.refCounter+=1,i;const s=new OffscreenCanvas(e.width,e.height);return s.getContext("2d").drawImage(e,0,0),i={bitmap:s.transferToImageBitmap(),id:`image_${this.#A}_${this.#y++}`,refCounter:1,isSvg:!1},this.#w.set(t,i),this.#w.set(i.id,i),i}getSvgUrl(t){const e=this.#w.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#w||=new Map;const e=this.#w.get(t);if(!e)return;if(e.refCounter-=1,0!==e.refCounter)return;const{bitmap:i}=e;if(!e.url&&!e.file){const t=new OffscreenCanvas(i.width,i.height);t.getContext("bitmaprenderer").transferFromImageBitmap(i),e.blobPromise=t.convertToBlob()}i.close?.(),e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#A}_`)}}class fe{#x=[];#E=!1;#S;#C=-1;constructor(t=128){this.#S=t}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:a=!1,keepUndo:r=!1}){if(s&&t(),this.#E)return;const o={cmd:t,undo:e,post:i,type:n};if(-1===this.#C)return this.#x.length>0&&(this.#x.length=0),this.#C=0,void this.#x.push(o);if(a&&this.#x[this.#C].type===n)return r&&(o.undo=this.#x[this.#C].undo),void(this.#x[this.#C]=o);const l=this.#C+1;l===this.#S?this.#x.splice(0,1):(this.#C=l,l<this.#x.length&&this.#x.splice(l)),this.#x.push(o)}undo(){if(-1===this.#C)return;this.#E=!0;const{undo:t,post:e}=this.#x[this.#C];t(),e?.(),this.#E=!1,this.#C-=1}redo(){if(this.#C<this.#x.length-1){this.#C+=1,this.#E=!0;const{cmd:t,post:e}=this.#x[this.#C];t(),e?.(),this.#E=!1}}hasSomethingToUndo(){return-1!==this.#C}hasSomethingToRedo(){return this.#C<this.#x.length-1}destroy(){this.#x=null}}class me{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Mt.platform;for(const[i,s,n={}]of t)for(const t of i){const i=t.startsWith("mac+");e&&i?(this.callbacks.set(t.slice(4),{callback:s,options:n}),this.allKeys.add(t.split("+").at(-1))):e||i||(this.callbacks.set(t,{callback:s,options:n}),this.allKeys.add(t.split("+").at(-1)))}}#T(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;const i=this.callbacks.get(this.#T(e));if(!i)return;const{callback:s,options:{bubbles:n=!1,args:a=[],checker:r=null}}=i;r&&!r(t,e)||(s.bind(t,...a,e)(),n||(e.stopPropagation(),e.preventDefault()))}}class be{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return function(t){const e=document.createElement("span");e.style.visibility="hidden",document.body.append(e);for(const i of t.keys()){e.style.color=i;const s=window.getComputedStyle(e).color;t.set(i,ae(s))}e.remove()}(t),mt(this,"_colors",t)}convert(t){const e=ae(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[t,i]of this._colors)if(i.every((t,i)=>t===e[i]))return be._colorsMapping.get(t);return e}getHexCode(t){const e=this._colors.get(t);return e?Pt.makeHexColor(...e):t}}class ve{#M=new AbortController;#k=null;#P=new Map;#R=new Map;#I=null;#D=null;#L=null;#F=new fe;#O=null;#N=0;#j=new Set;#B=null;#z=null;#H=new Set;#U=!1;#$=!1;#G=!1;#V=null;#W=null;#q=null;#X=null;#K=!1;#Y=null;#J=new pe;#Q=!1;#Z=!1;#tt=null;#et=null;#it=null;#st=null;#nt=C.NONE;#at=new Set;#rt=null;#ot=null;#lt=null;#ht={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#ct=[0,0];#dt=null;#ut=null;#pt=null;#gt=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=ve.prototype,e=t=>t.#ut.contains(document.activeElement)&&"BUTTON"!==document.activeElement.tagName&&t.hasSomethingToControl(),i=(t,{target:e})=>{if(e instanceof HTMLInputElement){const{type:t}=e;return"text"!==t&&"number"!==t}return!0},s=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return mt(this,"_keyboardManager",new me([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:i}],[["ctrl+z","mac+meta+z"],t.undo,{checker:i}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:i}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:i}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#ut.contains(e)&&!t.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#ut.contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-s,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[s,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-s],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,s],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}constructor(t,e,i,s,n,a,r,o,l,h,c){const d=this._signal=this.#M.signal;this.#ut=t,this.#pt=e,this.#I=i,this._eventBus=s,s._on("editingaction",this.onEditingAction.bind(this),{signal:d}),s._on("pagechanging",this.onPageChanging.bind(this),{signal:d}),s._on("scalechanging",this.onScaleChanging.bind(this),{signal:d}),s._on("rotationchanging",this.onRotationChanging.bind(this),{signal:d}),s._on("setpreference",this.onSetPreference.bind(this),{signal:d}),s._on("switchannotationeditorparams",t=>this.updateParams(t.type,t.value),{signal:d}),this.#ft(),this.#mt(),this.#bt(),this.#D=n.annotationStorage,this.#V=n.filterFactory,this.#ot=a,this.#X=r||null,this.#U=o,this.#$=l,this.#G=h,this.#st=c||null,this.viewParameters={realScale:Vt.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1}destroy(){this.#gt?.resolve(),this.#gt=null,this.#M?.abort(),this.#M=null,this._signal=null;for(const t of this.#R.values())t.destroy();this.#R.clear(),this.#P.clear(),this.#H.clear(),this.#k=null,this.#at.clear(),this.#F.destroy(),this.#I?.destroy(),this.#Y?.hide(),this.#Y=null,this.#W&&(clearTimeout(this.#W),this.#W=null),this.#dt&&(clearTimeout(this.#dt),this.#dt=null)}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#st}get useNewAltTextFlow(){return this.#$}get useNewAltTextWhenAddingImage(){return this.#G}get hcmFilter(){return mt(this,"hcmFilter",this.#ot?this.#V.addHCMFilter(this.#ot.foreground,this.#ot.background):"none")}get direction(){return mt(this,"direction",getComputedStyle(this.#ut).direction)}get highlightColors(){return mt(this,"highlightColors",this.#X?new Map(this.#X.split(",").map(t=>t.split("=").map(t=>t.trim()))):null)}get highlightColorNames(){return mt(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setMainHighlightColorPicker(t){this.#it=t}editAltText(t,e=!1){this.#I?.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){if("enableNewAltTextWhenAddingImage"===t)this.#G=e}onPageChanging({pageNumber:t}){this.#N=t-1}focusMainContainer(){this.#ut.focus()}findParent(t,e){for(const i of this.#R.values()){const{x:s,y:n,width:a,height:r}=i.div.getBoundingClientRect();if(t>=s&&t<=s+a&&e>=n&&e<=n+r)return i}return null}disableUserSelect(t=!1){this.#pt.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#H.add(t)}removeShouldRescale(t){this.#H.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*Vt.PDF_TO_CSS_UNITS;for(const t of this.#H)t.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#vt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#yt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const e of this.#R.values())if(e.hasTextLayer(t))return e;return null}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:i,anchorOffset:s,focusNode:n,focusOffset:a}=e,r=e.toString(),o=this.#vt(e).closest(".textLayer"),l=this.getSelectionBoxes(o);if(!l)return;e.empty();const h=this.#yt(o),c=this.#nt===C.NONE,d=()=>{h?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:l,anchorNode:i,anchorOffset:s,focusNode:n,focusOffset:a,text:r}),c&&this.showAllEditors("highlight",!0,!0)};c?this.switchToMode(C.HIGHLIGHT,d):d()}#At(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#vt(t).closest(".textLayer"),i=this.getSelectionBoxes(e);i&&(this.#Y||=new de(this),this.#Y.show(e,i,"ltr"===this.direction))}addToAnnotationStorage(t){t.isEmpty()||!this.#D||this.#D.has(t.id)||this.#D.setValue(t.id,t)}#wt(){const t=document.getSelection();if(!t||t.isCollapsed)return void(this.#rt&&(this.#Y?.hide(),this.#rt=null,this.#_t({hasSelectedText:!1})));const{anchorNode:e}=t;if(e===this.#rt)return;const i=this.#vt(t).closest(".textLayer");if(i){if(this.#Y?.hide(),this.#rt=e,this.#_t({hasSelectedText:!0}),(this.#nt===C.HIGHLIGHT||this.#nt===C.NONE)&&(this.#nt===C.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#K=this.isShiftKeyDown,!this.isShiftKeyDown)){const t=this.#nt===C.HIGHLIGHT?this.#yt(i):null;t?.toggleDrawing();const e=new AbortController,s=this.combinedSignal(e),n=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),t?.toggleDrawing(!0),"pointerup"===i.type&&this.#xt("main_toolbar"))};window.addEventListener("pointerup",n,{signal:s}),window.addEventListener("blur",n,{signal:s})}}else this.#rt&&(this.#Y?.hide(),this.#rt=null,this.#_t({hasSelectedText:!1}))}#xt(t=""){this.#nt===C.HIGHLIGHT?this.highlightSelection(t):this.#U&&this.#At()}#ft(){document.addEventListener("selectionchange",this.#wt.bind(this),{signal:this._signal})}#Et(){if(this.#q)return;this.#q=new AbortController;const t=this.combinedSignal(this.#q);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#St(){this.#q?.abort(),this.#q=null}blur(){if(this.isShiftKeyDown=!1,this.#K&&(this.#K=!1,this.#xt("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#at)if(e.div.contains(t)){this.#et=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#et)return;const[t,e]=this.#et;this.#et=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#bt(){if(this.#tt)return;this.#tt=new AbortController;const t=this.combinedSignal(this.#tt);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#Ct(){this.#tt?.abort(),this.#tt=null}#Tt(){if(this.#O)return;this.#O=new AbortController;const t=this.combinedSignal(this.#O);document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})}#Mt(){this.#O?.abort(),this.#O=null}#mt(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#bt(),this.#Tt()}removeEditListeners(){this.#Ct(),this.#Mt()}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#z)if(i.isHandlingMimeForPasting(e))return t.dataTransfer.dropEffect="copy",void t.preventDefault()}drop(t){for(const e of t.dataTransfer.items)for(const i of this.#z)if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){if(t.preventDefault(),this.#k?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const t of this.#at){const i=t.serialize(!0);i&&e.push(i)}0!==e.length&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const t of e.items)for(const e of this.#z)if(e.isHandlingMimeForPasting(t.type))return void e.paste(t,this.currentLayer);let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(t){return void ut(`paste: "${t.message}".`)}if(!Array.isArray(i))return;this.unselectAll();const s=this.currentLayer;try{const t=[];for(const e of i){const i=await s.deserialize(e);if(!i)return;t.push(i)}const e=()=>{for(const e of t)this.#kt(e);this.#Pt(t)},n=()=>{for(const e of t)e.remove()};this.addCommands({cmd:e,undo:n,mustExec:!0})}catch(t){ut(`paste: "${t.message}".`)}}keydown(t){this.isShiftKeyDown||"Shift"!==t.key||(this.isShiftKeyDown=!0),this.#nt===C.NONE||this.isEditorHandlingKeyboard||ve._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&"Shift"===t.key&&(this.isShiftKeyDown=!1,this.#K&&(this.#K=!1,this.#xt("main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu")}}#_t(t){Object.entries(t).some(([t,e])=>this.#ht[t]!==e)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#ht,t)}),this.#nt===C.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Rt([[T.HIGHLIGHT_FREE,!0]]))}#Rt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#Et(),this.#Tt(),this.#_t({isEditing:this.#nt!==C.NONE,isEmpty:this.#It(),hasSomethingToUndo:this.#F.hasSomethingToUndo(),hasSomethingToRedo:this.#F.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#St(),this.#Mt(),this.#_t({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#z){this.#z=t;for(const t of this.#z)this.#Rt(t.defaultPropertiesToUpdate)}}getId(){return this.#J.id}get currentLayer(){return this.#R.get(this.#N)}getLayer(t){return this.#R.get(t)}get currentPageIndex(){return this.#N}addLayer(t){this.#R.set(t.pageIndex,t),this.#Q?t.enable():t.disable()}removeLayer(t){this.#R.delete(t.pageIndex)}async updateMode(t,e=null,i=!1){if(this.#nt!==t&&(!this.#gt||(await this.#gt.promise,this.#gt))){if(this.#gt=Promise.withResolvers(),this.#nt=t,t===C.NONE)return this.setEditingState(!1),this.#Dt(),void this.#gt.resolve();this.setEditingState(!0),await this.#Lt(),this.unselectAll();for(const e of this.#R.values())e.updateMode(t);if(!e)return i&&this.addNewEditorFromKeyboard(),void this.#gt.resolve();for(const t of this.#P.values())t.annotationElementId===e?(this.setSelected(t),t.enterInEditMode()):t.unselect();this.#gt.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==this.#nt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){if(this.#z){switch(t){case T.CREATE:return void this.currentLayer.addNewEditor();case T.HIGHLIGHT_DEFAULT_COLOR:this.#it?.updateColor(e);break;case T.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#lt||=new Map).set(t,e),this.showAllEditors("highlight",e)}for(const i of this.#at)i.updateParams(t,e);for(const i of this.#z)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const i of this.#P.values())i.editorType===t&&i.show(e);(this.#lt?.get(T.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#Rt([[T.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#Z!==t){this.#Z=t;for(const e of this.#R.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#Lt(){if(!this.#Q){this.#Q=!0;const t=[];for(const e of this.#R.values())t.push(e.enable());await Promise.all(t);for(const t of this.#P.values())t.enable()}}#Dt(){if(this.unselectAll(),this.#Q){this.#Q=!1;for(const t of this.#R.values())t.disable();for(const t of this.#P.values())t.disable()}}getEditors(t){const e=[];for(const i of this.#P.values())i.pageIndex===t&&e.push(i);return e}getEditor(t){return this.#P.get(t)}addEditor(t){this.#P.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#W&&clearTimeout(this.#W),this.#W=setTimeout(()=>{this.focusMainContainer(),this.#W=null},0)),this.#P.delete(t.id),this.unselect(t),t.annotationElementId&&this.#j.has(t.annotationElementId)||this.#D?.remove(t.id)}addDeletedAnnotationElement(t){this.#j.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#j.has(t)}removeDeletedAnnotationElement(t){this.#j.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#kt(t){const e=this.#R.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#k!==t&&(this.#k=t,t&&this.#Rt(t.propertiesToUpdate))}get#Ft(){let t=null;for(t of this.#at);return t}updateUI(t){this.#Ft===t&&this.#Rt(t.propertiesToUpdate)}toggleSelected(t){if(this.#at.has(t))return this.#at.delete(t),t.unselect(),void this.#_t({hasSelectedEditor:this.hasSelection});this.#at.add(t),t.select(),this.#Rt(t.propertiesToUpdate),this.#_t({hasSelectedEditor:!0})}setSelected(t){for(const e of this.#at)e!==t&&e.unselect();this.#at.clear(),this.#at.add(t),t.select(),this.#Rt(t.propertiesToUpdate),this.#_t({hasSelectedEditor:!0})}isSelected(t){return this.#at.has(t)}get firstSelectedEditor(){return this.#at.values().next().value}unselect(t){t.unselect(),this.#at.delete(t),this.#_t({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#at.size}get isEnterHandled(){return 1===this.#at.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#F.undo(),this.#_t({hasSomethingToUndo:this.#F.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#It()})}redo(){this.#F.redo(),this.#_t({hasSomethingToUndo:!0,hasSomethingToRedo:this.#F.hasSomethingToRedo(),isEmpty:this.#It()})}addCommands(t){this.#F.add(t),this.#_t({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#It()})}#It(){if(0===this.#P.size)return!0;if(1===this.#P.size)for(const t of this.#P.values())return t.isEmpty();return!1}delete(){if(this.commitOrRemove(),!this.hasSelection)return;const t=[...this.#at];this.addCommands({cmd:()=>{for(const e of t)e.remove()},undo:()=>{for(const e of t)this.#kt(e)},mustExec:!0})}commitOrRemove(){this.#k?.commitOrRemove()}hasSomethingToControl(){return this.#k||this.hasSelection}#Pt(t){for(const t of this.#at)t.unselect();this.#at.clear();for(const e of t)e.isEmpty()||(this.#at.add(e),e.select());this.#_t({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#at)t.commit();this.#Pt(this.#P.values())}unselectAll(){if((!this.#k||(this.#k.commitOrRemove(),this.#nt===C.NONE))&&this.hasSelection){for(const t of this.#at)t.unselect();this.#at.clear(),this.#_t({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,i=!1){if(i||this.commitOrRemove(),!this.hasSelection)return;this.#ct[0]+=t,this.#ct[1]+=e;const[s,n]=this.#ct,a=[...this.#at];this.#dt&&clearTimeout(this.#dt),this.#dt=setTimeout(()=>{this.#dt=null,this.#ct[0]=this.#ct[1]=0,this.addCommands({cmd:()=>{for(const t of a)this.#P.has(t.id)&&t.translateInPage(s,n)},undo:()=>{for(const t of a)this.#P.has(t.id)&&t.translateInPage(-s,-n)},mustExec:!1})},1e3);for(const i of a)i.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#B=new Map;for(const t of this.#at)this.#B.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#B)return!1;this.disableUserSelect(!1);const t=this.#B;this.#B=null;let e=!1;for(const[{x:i,y:s,pageIndex:n},a]of t)a.newX=i,a.newY=s,a.newPageIndex=n,e||=i!==a.savedX||s!==a.savedY||n!==a.savedPageIndex;if(!e)return!1;const i=(t,e,i,s)=>{if(this.#P.has(t.id)){const n=this.#R.get(s);n?t._setParentAndPosition(n,e,i):(t.pageIndex=s,t.x=e,t.y=i)}};return this.addCommands({cmd:()=>{for(const[e,{newX:s,newY:n,newPageIndex:a}]of t)i(e,s,n,a)},undo:()=>{for(const[e,{savedX:s,savedY:n,savedPageIndex:a}]of t)i(e,s,n,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#B)for(const i of this.#B.keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||1===this.#at.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#k===t}getActive(){return this.#k}getMode(){return this.#nt}get imageManager(){return mt(this,"imageManager",new ge)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let i=0,s=e.rangeCount;i<s;i++)if(!t.contains(e.getRangeAt(i).commonAncestorContainer))return null;const{x:i,y:s,width:n,height:a}=t.getBoundingClientRect();let r;switch(t.getAttribute("data-main-rotation")){case"90":r=(t,e,r,o)=>({x:(e-s)/a,y:1-(t+r-i)/n,width:o/a,height:r/n});break;case"180":r=(t,e,r,o)=>({x:1-(t+r-i)/n,y:1-(e+o-s)/a,width:r/n,height:o/a});break;case"270":r=(t,e,r,o)=>({x:1-(e+o-s)/a,y:(t-i)/n,width:o/a,height:r/n});break;default:r=(t,e,r,o)=>({x:(t-i)/n,y:(e-s)/a,width:r/n,height:o/a})}const o=[];for(let t=0,i=e.rangeCount;t<i;t++){const i=e.getRangeAt(t);if(!i.collapsed)for(const{x:t,y:e,width:s,height:n}of i.getClientRects())0!==s&&0!==n&&o.push(r(t,e,s,n))}return 0===o.length?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#L||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#L?.delete(t)}renderAnnotationElement(t){const e=this.#L?.get(t.data.id);if(!e)return;const i=this.#D.getRawValue(e);i&&(this.#nt!==C.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}}class ye{#o=null;#Ot=!1;#Nt=null;#jt=null;#Bt=null;#zt=null;#Ht=!1;#Ut=null;#a=null;#$t=null;#Gt=null;#Vt=!1;static#Wt=null;static _l10n=null;constructor(t){this.#a=t,this.#Vt=t._uiManager.useNewAltTextFlow,ye.#Wt||=Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"})}static initialize(t){ye._l10n??=t}async render(){const t=this.#Nt=document.createElement("button");t.className="altText",t.tabIndex="0";const e=this.#jt=document.createElement("span");t.append(e),this.#Vt?(t.classList.add("new"),t.setAttribute("data-l10n-id",ye.#Wt.missing),e.setAttribute("data-l10n-id",ye.#Wt["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const i=this.#a._uiManager._signal;t.addEventListener("contextmenu",ee,{signal:i}),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=t=>{t.preventDefault(),this.#a._uiManager.editAltText(this.#a),this.#Vt&&this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#qt}})};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#Ht=!0,s(e))},{signal:i}),await this.#Xt(),t}get#qt(){return(this.#o?"added":null===this.#o&&this.guessedText&&"review")||"missing"}finish(){this.#Nt&&(this.#Nt.focus({focusVisible:this.#Ht}),this.#Ht=!1)}isEmpty(){return this.#Vt?null===this.#o:!this.#o&&!this.#Ot}hasData(){return this.#Vt?null!==this.#o||!!this.#$t:this.isEmpty()}get guessedText(){return this.#$t}async setGuessedText(t){null===this.#o&&(this.#$t=t,this.#Gt=await ye._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#Xt())}toggleAltTextBadge(t=!1){if(!this.#Vt||this.#o)return this.#Ut?.remove(),void(this.#Ut=null);if(!this.#Ut){const t=this.#Ut=document.createElement("div");t.className="noAltTextBadge",this.#a.div.append(t)}this.#Ut.classList.toggle("hidden",!t)}serialize(t){let e=this.#o;return t||this.#$t!==e||(e=this.#Gt),{altText:e,decorative:this.#Ot,guessedText:this.#$t,textWithDisclaimer:this.#Gt}}get data(){return{altText:this.#o,decorative:this.#Ot}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:s,cancel:n=!1}){i&&(this.#$t=i,this.#Gt=s),this.#o===t&&this.#Ot===e||(n||(this.#o=t,this.#Ot=e),this.#Xt())}toggle(t=!1){this.#Nt&&(!t&&this.#zt&&(clearTimeout(this.#zt),this.#zt=null),this.#Nt.disabled=!t)}shown(){this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#qt}})}destroy(){this.#Nt?.remove(),this.#Nt=null,this.#jt=null,this.#Bt=null,this.#Ut?.remove(),this.#Ut=null}async#Xt(){const t=this.#Nt;if(!t)return;if(this.#Vt){if(t.classList.toggle("done",!!this.#o),t.setAttribute("data-l10n-id",ye.#Wt[this.#qt]),this.#jt?.setAttribute("data-l10n-id",ye.#Wt[`${this.#qt}-label`]),!this.#o)return void this.#Bt?.remove()}else{if(!this.#o&&!this.#Ot)return t.classList.remove("done"),void this.#Bt?.remove();t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#Bt;if(!e){this.#Bt=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#a.id}`;const i=100,s=this.#a._uiManager._signal;s.addEventListener("abort",()=>{clearTimeout(this.#zt),this.#zt=null},{once:!0}),t.addEventListener("mouseenter",()=>{this.#zt=setTimeout(()=>{this.#zt=null,this.#Bt.classList.add("show"),this.#a._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:s}),t.addEventListener("mouseleave",()=>{this.#zt&&(clearTimeout(this.#zt),this.#zt=null),this.#Bt?.classList.remove("show")},{signal:s})}this.#Ot?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=this.#o),e.parentNode||t.append(e);const i=this.#a.getImageForAltText();i?.setAttribute("aria-describedby",e.id)}}class Ae{#Kt=null;#Yt=null;#o=null;#Jt=!1;#Qt=!1;#Zt=null;#te=null;#ee=null;#ie="";#se=!1;#ne=null;#ae=!1;#re=!1;#oe=!1;#le=null;#he=0;#ce=0;#de=null;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_