UNPKG

@bradycorporation/brady-web-sdk

Version:

The Brady Web SDK allows users to communicate with Brady Printers using a web browser.

1 lines 405 kB
export const __webpack_esm_id__=100;export const __webpack_esm_ids__=[100];export const __webpack_esm_modules__={100(t,e,i){i.r(e),i.d(e,{AbortException:()=>B,AnnotationEditorLayer:()=>vn,AnnotationEditorParamsType:()=>h,AnnotationEditorType:()=>l,AnnotationEditorUIManager:()=>Ot,AnnotationLayer:()=>qs,AnnotationMode:()=>r,AnnotationType:()=>u,CSSConstants:()=>vt,ColorPicker:()=>cs,DOMSVGFactory:()=>bs,DrawLayer:()=>yn,FeatureTest:()=>R,GlobalWorkerOptions:()=>vi,ImageKind:()=>c,InvalidPDFException:()=>P,MathClamp:()=>W,OPS:()=>g,OutputScale:()=>mt,PDFDataRangeTransport:()=>is,PDFDateString:()=>ht,PDFWorker:()=>as,PasswordResponses:()=>m,PermissionFlag:()=>d,PixelsPerInch:()=>Y,RenderingCancelledException:()=>Z,ResponseException:()=>k,SignatureExtractor:()=>pn,SupportedImageMimeTypes:()=>ft,TextLayer:()=>Zi,TouchManager:()=>zt,Util:()=>N,VerbosityLevel:()=>p,XfaLayer:()=>q,applyOpacity:()=>yt,build:()=>ds,createValidAbsoluteUrl:()=>C,fetchData:()=>Q,findContrastColor:()=>St,getDocument:()=>ts,getFilenameFromUrl:()=>it,getPdfFilenameFromUrl:()=>st,getRGB:()=>ct,getUuid:()=>z,getXfaPageViewport:()=>dt,isDataScheme:()=>tt,isPdfFile:()=>et,isValidExplicitDest:()=>re,makeArr:()=>j,makeMap:()=>$,makeObj:()=>V,noContextMenu:()=>rt,normalizeUnicode:()=>H,renderRichText:()=>Tt,setLayerDimensions:()=>gt,shadow:()=>T,stopEvent:()=>ot,updateUrlHash:()=>_,version:()=>hs});const s=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),n=[.001,0,0,.001,0,0],a=1.35,r={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},o="pdfjs_internal_editor_",l={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},h={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_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},d={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},c={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},u={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26},p={ERRORS:0,WARNINGS:1,INFOS:5},g={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,rawFillPath:94},m={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let f=p.WARNINGS;function b(t){Number.isInteger(t)&&(f=t)}function v(){return f}function y(t){f>=p.INFOS&&console.info(`Info: ${t}`)}function w(t){f>=p.WARNINGS&&console.warn(`Warning: ${t}`)}function A(t){throw new Error(t)}function x(t,e){t||A(e)}function C(t,e=null,i=null){if(!t)return null;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?URL.parse(t,e):URL.parse(t);return function(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(s)?s:null}function _(t,e,i=!1){const s=URL.parse(t);return s?(s.hash=e,s.href):i&&C(t,"http://example.com")?t.split("#",1)[0]+""+(e?`#${e}`:""):""}function S(t){return t.substring(t.lastIndexOf("/")+1)}function T(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}const E=function(){function t(t,e){this.message=t,this.name=e}return t.prototype=new Error,t.constructor=t,t}();class M extends E{constructor(t,e){super(t,"PasswordException"),this.code=e}}class D extends E{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class P extends E{constructor(t){super(t,"InvalidPDFException")}}class k extends E{constructor(t,e,i){super(t,"ResponseException"),this.status=e,this.missing=i}}class I extends E{constructor(t){super(t,"FormatError")}}class B extends E{constructor(t){super(t,"AbortException")}}function F(t){"string"!=typeof t&&A("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}class R{static get isLittleEndian(){return T(this,"isLittleEndian",function(){const t=new Uint8Array(4);return t[0]=1,1===new Uint32Array(t.buffer,0,1)[0]}())}static get isEvalSupported(){return T(this,"isEvalSupported",function(){try{return new Function(""),!0}catch{return!1}}())}static get isOffscreenCanvasSupported(){return T(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return T(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isFloat16ArraySupported(){return T(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return T(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return T(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCSSRoundSupported(){return T(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const L=Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0"));class N{static makeHexColor(t,e,i){return`#${L[t]}${L[e]}${L[i]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}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 multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,i=0){const s=t[i],n=t[i+1];t[i]=s*e[0]+n*e[2]+e[4],t[i+1]=s*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,i=0){const s=e[0],n=e[1],a=e[2],r=e[3],o=e[4],l=e[5];for(let e=0;e<6;e+=2){const h=t[i+e],d=t[i+e+1];t[i+e]=h*s+d*a+o,t[i+e+1]=h*n+d*r+l}}static applyInverseTransform(t,e){const i=t[0],s=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(i*e[3]-s*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-i*e[1]+s*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,i){const s=e[0],n=e[1],a=e[2],r=e[3],o=e[4],l=e[5],h=t[0],d=t[1],c=t[2],u=t[3];let p=s*h+o,g=p,m=s*c+o,f=m,b=r*d+l,v=b,y=r*u+l,w=y;if(0!==n||0!==a){const t=n*h,e=n*c,i=a*d,s=a*u;p+=i,f+=i,m+=s,g+=s,b+=t,w+=t,y+=e,v+=e}i[0]=Math.min(i[0],p,m,g,f),i[1]=Math.min(i[1],b,y,v,w),i[2]=Math.max(i[2],p,m,g,f),i[3]=Math.max(i[3],b,y,v,w)}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,e){const i=t[0],s=t[1],n=t[2],a=t[3],r=i**2+s**2,o=i*n+s*a,l=n**2+a**2,h=(r+l)/2,d=Math.sqrt(h**2-(r*l-o**2));e[0]=Math.sqrt(h+d||1),e[1]=Math.sqrt(h-d||1)}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 pointBoundingBox(t,e,i){i[0]=Math.min(i[0],t),i[1]=Math.min(i[1],e),i[2]=Math.max(i[2],t),i[3]=Math.max(i[3],e)}static rectBoundingBox(t,e,i,s,n){n[0]=Math.min(n[0],t,i),n[1]=Math.min(n[1],e,s),n[2]=Math.max(n[2],t,i),n[3]=Math.max(n[3],e,s)}static#t(t,e,i,s,n,a,r,o,l,h){if(l<=0||l>=1)return;const d=1-l,c=l*l,u=c*l,p=d*(d*(d*t+3*l*e)+3*c*i)+u*s,g=d*(d*(d*n+3*l*a)+3*c*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,d,c){if(Math.abs(l)<1e-12)return void(Math.abs(h)>=1e-12&&this.#t(t,e,i,s,n,a,r,o,-d/h,c));const u=h**2-4*d*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,c),this.#t(t,e,i,s,n,a,r,o,(-h-p)/g,c)}static bezierBoundingBox(t,e,i,s,n,a,r,o,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),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)}}let O=null,U=null;function H(t){return O||(O=/([\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,U=new Map([["ſt","ſt"]])),t.replaceAll(O,(t,e,i)=>e?e.normalize("NFKC"):U.get(i))}function z(){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=new Uint8Array(32);return crypto.getRandomValues(t),function(t){"object"==typeof t&&void 0!==t?.length||A("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("")}(t)}const G="pdfjs_internal_id_",j=()=>[],$=()=>new Map,V=()=>Object.create(null);function W(t,e,i){return Math.min(Math.max(t,e),i)}"function"!=typeof Math.sumPrecise&&(Math.sumPrecise=function(t){return t.reduce((t,e)=>t+e,0)});class X{static textContent(t){const e=[],i={items:e,styles:Object.create(null)};return function t(i){if(!i)return;let s=null;const n=i.name;if("#text"===n)s=i.value;else{if(!X.shouldBuildText(n))return;i?.attributes?.textContent?s=i.attributes.textContent:i.value&&(s=i.value)}if(null!==s&&e.push({str:s}),i.children)for(const e of i.children)t(e)}(t),i}static shouldBuildText(t){return!("textarea"===t||"input"===t||"option"===t||"select"===t)}}class q{static setupStorage(t,e,i,s,n){const a=s.getValue(e,{value:null});switch(i.name){case"textarea":if(null!==a.value&&(t.textContent=a.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})});break;case"input":if("radio"===i.attributes.type||"checkbox"===i.attributes.type){if(a.value===i.attributes.xfaOn?t.setAttribute("checked",!0):a.value===i.attributes.xfaOff&&t.removeAttribute("checked"),"print"===n)break;t.addEventListener("change",t=>{s.setValue(e,{value:t.target.checked?t.target.getAttribute("xfaOn"):t.target.getAttribute("xfaOff")})})}else{if(null!==a.value&&t.setAttribute("value",a.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})})}break;case"select":if(null!==a.value){t.setAttribute("value",a.value);for(const t of i.children)t.attributes.value===a.value?t.attributes.selected=!0:t.attributes.hasOwnProperty("selected")&&delete t.attributes.selected}t.addEventListener("input",t=>{const i=t.target.options,n=-1===i.selectedIndex?"":i[i.selectedIndex].value;s.setValue(e,{value:n})})}}static setAttributes({html:t,element:e,storage:i=null,intent:s,linkService:n}){const{attributes:a}=e,r=t instanceof HTMLAnchorElement;"radio"===a.type&&(a.name=`${a.name}-${s}`);for(const[e,i]of Object.entries(a))if(null!=i)switch(e){case"class":i.length&&t.setAttribute(e,i.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",i);break;case"style":Object.assign(t.style,i);break;case"textContent":t.textContent=i;break;default:(!r||"href"!==e&&"newWindow"!==e)&&t.setAttribute(e,i)}r&&n.addLinkAttributes(t,a.href,a.newWindow),i&&a.dataId&&this.setupStorage(t,a.dataId,e,i)}static render(t){const e=t.annotationStorage,i=t.linkService,s=t.xfaHtml,n=t.intent||"display",a=document.createElement(s.name);s.attributes&&this.setAttributes({html:a,element:s,intent:n,linkService:i});const r="richText"!==n,o=t.div;if(o.append(a),t.viewport){const e=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=e}r&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(0===s.children.length){if(s.value){const t=document.createTextNode(s.value);a.append(t),r&&X.shouldBuildText(s.name)&&l.push(t)}return{textDivs:l}}const h=[[s,-1,a]];for(;h.length>0;){const[t,s,a]=h.at(-1);if(s+1===t.children.length){h.pop();continue}const o=t.children[++h.at(-1)[1]];if(null===o)continue;const{name:d}=o;if("#text"===d){const t=document.createTextNode(o.value);l.push(t),a.append(t);continue}const c=o?.attributes?.xmlns?document.createElementNS(o.attributes.xmlns,d):document.createElement(d);if(a.append(c),o.attributes&&this.setAttributes({html:c,element:o,storage:e,intent:n,linkService:i}),o.children?.length>0)h.push([o,-1,c]);else if(o.value){const t=document.createTextNode(o.value);r&&X.shouldBuildText(d)&&l.push(t),c.append(t)}}for(const t of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))t.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const K="http://www.w3.org/2000/svg";class Y{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function Q(t,e="text"){if(at(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"blob":return i.blob();case"bytes":return i.bytes();case"json":return i.json()}return i.text()}return new Promise((i,s)=>{const n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="bytes"===e?"arraybuffer":e,n.onreadystatechange=()=>{if(n.readyState===XMLHttpRequest.DONE)if(200!==n.status&&0!==n.status)s(new Error(n.statusText));else{switch(e){case"bytes":return void i(new Uint8Array(n.response));case"blob":case"json":return void i(n.response)}i(n.responseText)}},n.send(null)})}class J{constructor({viewBox:t,userUnit:e,scale:i,rotation:s,offsetX:n=0,offsetY:a=0,dontFlip:r=!1}){this.viewBox=t,this.userUnit=e,this.scale=i,this.rotation=s,this.offsetX=n,this.offsetY=a,i*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,d,c,u,p,g,m,f;switch((s%=360)<0&&(s+=360),s){case 180:h=-1,d=0,c=0,u=1;break;case 90:h=0,d=1,c=1,u=0;break;case 270:h=0,d=-1,c=-1,u=0;break;case 0:h=1,d=0,c=0,u=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}r&&(c=-c,u=-u),0===h?(p=Math.abs(l-t[1])*i+n,g=Math.abs(o-t[0])*i+a,m=(t[3]-t[1])*i,f=(t[2]-t[0])*i):(p=Math.abs(o-t[0])*i+n,g=Math.abs(l-t[1])*i+a,m=(t[2]-t[0])*i,f=(t[3]-t[1])*i),this.transform=[h*i,d*i,c*i,u*i,p-h*i*o-c*i*l,g-d*i*o-u*i*l],this.width=m,this.height=f}get rawDims(){const t=this.viewBox;return T(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 J({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}convertToViewportPoint(t,e){const i=[t,e];return N.applyTransform(i,this.transform),i}convertToViewportRectangle(t){const e=[t[0],t[1]];N.applyTransform(e,this.transform);const i=[t[2],t[3]];return N.applyTransform(i,this.transform),[e[0],e[1],i[0],i[1]]}convertToPdfPoint(t,e){const i=[t,e];return N.applyInverseTransform(i,this.transform),i}}class Z extends E{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function tt(t){const e=t.length;let i=0;for(;i<e&&""===t[i].trim();)i++;return"data:"===t.substring(i,i+5).toLowerCase()}function et(t){return"string"==typeof t&&/\.pdf$/i.test(t)}function it(t){return[t]=t.split(/[#?]/,1),S(t)}function st(t,e="document.pdf"){if("string"!=typeof t)return e;if(tt(t))return w('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),e;const i=(t=>{try{return new URL(t)}catch{try{return new URL(decodeURIComponent(t))}catch{try{return new URL(t,"https://foo.bar")}catch{try{return new URL(decodeURIComponent(t),"https://foo.bar")}catch{return null}}}}})(t);if(!i)return e;const s=t=>{try{let e=decodeURIComponent(t);return e.includes("/")&&(e=S(e),/^\.pdf$/i.test(e))?t:e}catch{return t}},n=/\.pdf$/i,a=S(i.pathname);if(n.test(a))return s(a);if(i.searchParams.size>0){const t=t=>[...t].findLast(t=>n.test(t)),e=t(i.searchParams.values())??t(i.searchParams.keys());if(e)return s(e)}if(i.hash){const t=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(i.hash);if(t)return s(t[0])}return e}class nt{started=Object.create(null);times=[];time(t){t in this.started&&w(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||w(`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 at(t,e){const i=e?URL.parse(t,e):URL.parse(t);return/https?:/.test(i?.protocol??"")}function rt(t){t.preventDefault()}function ot(t){t.preventDefault(),t.stopPropagation()}function lt(t){console.log("Deprecated API usage: "+t)}class ht{static#i;static toDateObject(t){if(t instanceof Date)return 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 d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,"-"===l?(a+=h,r+=d):"+"===l&&(a-=h,r-=d),new Date(Date.UTC(i,s,n,a,r,o))}}function dt(t,{scale:e=1,rotation:i=0}){const{width:s,height:n}=t.attributes.style,a=[0,0,parseInt(s),parseInt(n)];return new J({viewBox:a,userUnit:1,scale:e,rotation:i})}function ct(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):(w(`Not a valid color format: "${t}"`),[0,0,0])}function ut(t){const{a:e,b:i,c:s,d:n,e:a,f:r}=t.getTransform();return[e,i,s,n,a,r]}function pt(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 gt(t,e,i=!1,s=!0){if(e instanceof J){const{pageWidth:s,pageHeight:n}=e.rawDims,{style:a}=t,r=R.isCSSRoundSupported,o=`var(--total-scale-factor) * ${s}px`,l=`var(--total-scale-factor) * ${n}px`,h=r?`round(down, ${o}, var(--scale-round-x))`:`calc(${o})`,d=r?`round(down, ${l}, var(--scale-round-y))`:`calc(${l})`;i&&e.rotation%180!=0?(a.width=d,a.height=h):(a.width=h,a.height=d)}s&&t.setAttribute("data-main-rotation",e.rotation)}class mt{constructor(){const{pixelRatio:t}=mt;this.sx=t,this.sy=t}get scaled(){return 1!==this.sx||1!==this.sy}get symmetric(){return this.sx===this.sy}limitCanvas(t,e,i,s,n=-1){let a=1/0,r=1/0,o=1/0;(i=mt.capPixels(i,n))>0&&(a=Math.sqrt(i/(t*e))),-1!==s&&(r=s/t,o=s/e);const l=Math.min(a,r,o);return(this.sx>l||this.sy>l)&&(this.sx=l,this.sy=l,!0)}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(t,e){if(e>=0){const i=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+e/100));return t>0?Math.min(t,i):i}return t}}const ft=["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"];class bt{static get isDarkMode(){return T(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}}class vt{static get commentForegroundColor(){const t=document.createElement("span");t.classList.add("comment","sidebar");const{style:e}=t;e.width=e.height="0",e.display="none",e.color="var(--comment-fg-color)",document.body.append(t);const{color:i}=window.getComputedStyle(t);return t.remove(),T(this,"commentForegroundColor",ct(i))}}function yt(t,e,i,s){const n=255*(1-(s=W(s??1,0,1)));return[t=Math.round(t*s+n),e=Math.round(e*s+n),i=Math.round(i*s+n)]}function wt(t,e){const i=t[0]/255,s=t[1]/255,n=t[2]/255,a=Math.max(i,s,n),r=Math.min(i,s,n),o=(a+r)/2;if(a===r)e[0]=e[1]=0;else{const t=a-r;switch(e[1]=o<.5?t/(a+r):t/(2-a-r),a){case i:e[0]=60*((s-n)/t+(s<n?6:0));break;case s:e[0]=60*((n-i)/t+2);break;case n:e[0]=60*((i-s)/t+4)}}e[2]=o}function At(t,e){const i=t[0],s=t[1],n=t[2],a=(1-Math.abs(2*n-1))*s,r=a*(1-Math.abs(i/60%2-1)),o=n-a/2;switch(Math.floor(i/60)){case 0:e[0]=a+o,e[1]=r+o,e[2]=o;break;case 1:e[0]=r+o,e[1]=a+o,e[2]=o;break;case 2:e[0]=o,e[1]=a+o,e[2]=r+o;break;case 3:e[0]=o,e[1]=r+o,e[2]=a+o;break;case 4:e[0]=r+o,e[1]=o,e[2]=a+o;break;case 5:case 6:e[0]=a+o,e[1]=o,e[2]=r+o}}function xt(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Ct(t,e,i){At(t,i),i.map(xt);const s=.2126*i[0]+.7152*i[1]+.0722*i[2];At(e,i),i.map(xt);const n=.2126*i[0]+.7152*i[1]+.0722*i[2];return s>n?(s+.05)/(n+.05):(n+.05)/(s+.05)}const _t=new Map;function St(t,e){const i=t[0]+256*t[1]+65536*t[2]+16777216*e[0]+4294967296*e[1]+1099511627776*e[2];let s=_t.get(i);if(s)return s;const n=new Float32Array(9),a=n.subarray(0,3),r=n.subarray(3,6);wt(t,r);const o=n.subarray(6,9);wt(e,o);const l=o[2]<.5,h=l?12:4.5;if(r[2]=l?Math.sqrt(r[2]):1-Math.sqrt(1-r[2]),Ct(r,o,a)<h){let t,e;l?(t=r[2],e=1):(t=0,e=r[2]);const i=.005;for(;e-t>i;){const i=r[2]=(t+e)/2;l===Ct(r,o,a)<h?t=i:e=i}r[2]=l?e:t}return At(r,a),s=N.makeHexColor(Math.round(255*a[0]),Math.round(255*a[1]),Math.round(255*a[2])),_t.set(i,s),s}function Tt({html:t,dir:e,className:i},s){const n=document.createDocumentFragment();if("string"==typeof t){const i=document.createElement("p");i.dir=e||"auto";const s=t.split(/(?:\r\n?|\n)/);for(let t=0,e=s.length;t<e;++t){const n=s[t];i.append(document.createTextNode(n)),t<e-1&&i.append(document.createElement("br"))}n.append(i)}else q.render({xfaHtml:t,div:n,intent:"richText"});n.firstElementChild.classList.add("richText",i),s.append(n)}function Et(t){const e=new Path2D;if(!t)return e;for(let i=0,s=t.length;i<s;)switch(t[i++]){case 0:e.moveTo(t[i++],t[i++]);break;case 1:e.lineTo(t[i++],t[i++]);break;case 2:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case 3:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case 4:e.closePath();break;default:w(`Unrecognized drawing path operator: ${t[i-1]}`)}return e}class Mt{#s=null;#n=null;#a=null;#r=0;#o=[];#l=null;#h=null;get pagesNumber(){return this.#r}set pagesNumber(t){this.#r!==t&&(this.#r=t,this.#d())}#d(){this.#n=null,this.#s=null}addListener(t){this.#o.push(t)}removeListener(t){const e=this.#o.indexOf(t);e>=0&&this.#o.splice(e,1)}#c(t){for(const e of this.#o)e(t)}#u(t){if(this.#n)return;const e=this.#r,i=this.#n=new Uint32Array(e);this.#a=new Int32Array(i);const s=this.#s=new Map;if(t)for(let t=1;t<=e;t++)i[t-1]=t,s.set(t,[t])}#p(){const t=this.#s,e=this.#n;t.clear();for(let i=0,s=this.#r;i<s;i++){const s=e[i],n=t.get(s);n?n.push(i+1):t.set(s,[i+1])}}movePages(t,e,i){this.#u(!0);const s=this.#n,n=this.#s,a=e.length,r=new Uint32Array(a);let o=0;for(let t=0;t<a;t++){const n=e[t]-1;r[t]=s[n],n<i&&(o+=1)}const l=this.#r;let h=i-o;const d=l-a;h=W(h,0,d);for(let e=0,i=0;e<l;e++)t.has(e+1)||(s[i++]=s[e]);s.copyWithin(h+a,h,d),s.set(r,h),this.#g(n,null),this.#p(),this.#c({type:"move"}),s.every((t,e)=>t===e+1)&&this.#d()}deletePages(t){this.#u(!0);const e=this.#n,i=this.#s;this.pagesNumber-=t.length,this.#u(!1);const s=this.#n;let n=0,a=0;for(const i of t){const t=i-1;t!==n&&(s.set(e.subarray(n,t),a),a+=t-n),n=t+1}n<e.length&&s.set(e.subarray(n),a),this.#g(i,null),this.#p(),this.#c({type:"delete",pageNumbers:t})}copyPages(t){this.#u(!0),this.#h=t,this.#l=t.map(t=>this.#n[t-1]),this.#c({type:"copy",pageNumbers:t})}pastePages(t){this.#u(!0);const e=this.#n,i=this.#s,s=this.#h,n=new Map;let a=t;for(const t of s)n.set(++a,t);this.pagesNumber+=s.length,this.#u(!1);const r=this.#n;r.set(e.subarray(0,t),0),r.set(this.#l,t),r.set(e.subarray(t),t+s.length),this.#g(i,n),this.#p(),this.#c({type:"paste"}),this.#l=null}#g(t,e){const i=this.#a,s=this.#n,n=new Map;for(let a=0,r=this.#r;a<r;a++){const r=e?.get(a+1);if(r){i[a]=-r;continue}const o=s[a],l=n.get(o)||0;i[a]=t.get(o)?.[l],n.set(o,l+1)}}hasBeenAltered(){return null!==this.#n}getPageMappingForSaving(){const t=this.#s;let e=0;for(const i of t.values())e=Math.max(e,i.length);const i=new Array(e);for(let t=0;t<e;t++)i[t]={document:null,pageIndices:[],includePages:[]};for(const[e,s]of t)for(let t=0,n=s.length;t<n;t++)i[t].includePages.push([e-1,s[t]-1]);for(const{includePages:t,pageIndices:e}of i){t.sort((t,e)=>t[0]-e[0]);for(let i=0,s=t.length;i<s;i++)e.push(t[i][1]),t[i]=t[i][0]}return i}getPrevPageNumber(t){return this.#a[t-1]??0}getPageNumber(t){return this.#s?this.#s.get(t)?.[0]??0:t}getPageId(t){return this.#n?.[t-1]??t}getMapping(){return this.#n.subarray(0,this.pagesNumber)}}class Dt{#m=null;#f=null;#b;#v=null;#y=null;#w=null;#A=null;#x=null;static#C=null;constructor(t){this.#b=t,Dt.#C||=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",signature:"pdfjs-editor-remove-signature-button"})}render(){const t=this.#m=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=this.#b._uiManager._signal;e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("contextmenu",rt,{signal:e}),t.addEventListener("pointerdown",Dt.#_,{signal:e}));const i=this.#v=document.createElement("div");i.className="buttons",t.append(i);const s=this.#b.toolbarPosition;if(s){const{style:e}=t,i="ltr"===this.#b._uiManager.direction?1-s[0]:s[0];e.insetInlineEnd=100*i+"%",e.top=`calc(${100*s[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#m}static#_(t){t.stopPropagation()}#S(t){this.#b._focusEventsAllowed=!1,ot(t)}#T(t){this.#b._focusEventsAllowed=!0,ot(t)}#E(t){const e=this.#b._uiManager._signal;return e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("focusin",this.#S.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#T.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",rt,{signal:e}),!0)}hide(){this.#m.classList.add("hidden"),this.#f?.hideDropdown()}show(){this.#m.classList.remove("hidden"),this.#y?.shown(),this.#w?.shown()}addDeleteButton(){const{editorType:t,_uiManager:e}=this.#b,i=document.createElement("button");i.classList.add("basic","deleteButton"),i.tabIndex=0,i.setAttribute("data-l10n-id",Dt.#C[t]),this.#E(i)&&i.addEventListener("click",t=>{e.delete()},{signal:e._signal}),this.#v.append(i)}get#M(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#E(e),this.#v.append(e,this.#M),this.#y=t}addComment(t,e=null){if(this.#w)return;const i=t.renderForToolbar();if(!i)return;this.#E(i);const s=this.#A=this.#M;e?(this.#v.insertBefore(i,e),this.#v.insertBefore(s,e)):this.#v.append(i,s),this.#w=t,t.toolbar=this}addColorPicker(t){if(this.#f)return;this.#f=t;const e=t.renderButton();this.#E(e),this.#v.append(e,this.#M)}async addEditSignatureButton(t){const e=this.#x=await t.renderEditButton(this.#b);this.#E(e),this.#v.append(e,this.#M)}removeButton(t){"comment"===t&&(this.#w?.removeToolbarCommentButton(),this.#w=null,this.#A?.remove(),this.#A=null)}async addButton(t,e){switch(t){case"colorPicker":e&&this.addColorPicker(e);break;case"altText":e&&await this.addAltText(e);break;case"editSignature":e&&await this.addEditSignatureButton(e);break;case"delete":this.addDeleteButton();break;case"comment":e&&this.addComment(e)}}async addButtonBefore(t,e,i){if(!e&&"comment"===t)return;const s=this.#v.querySelector(i);s&&"comment"===t&&this.addComment(e,s)}updateEditSignatureButton(t){this.#x&&(this.#x.title=t)}remove(){this.#m.remove(),this.#f?.destroy(),this.#f=null}}class Pt{#v=null;#m=null;#D;constructor(t){this.#D=t}#P(){const t=this.#m=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar");const e=this.#D._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",rt,{signal:e});const i=this.#v=document.createElement("div");return i.className="buttons",t.append(i),this.#D.hasCommentManager()&&this.#k("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#D.commentSelection("floating_button")}),this.#k("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#D.highlightSelection("floating_button")}),t}#I(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.#I(e,i),{style:a}=this.#m||=this.#P();t.append(this.#m),a.insetInlineEnd=100*s+"%",a.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#m.remove()}#k(t,e,i,s){const n=document.createElement("button");n.classList.add("basic",t),n.tabIndex=0,n.setAttribute("data-l10n-id",e);const a=document.createElement("span");n.append(a),a.className="visuallyHidden",a.setAttribute("data-l10n-id",i);const r=this.#D._signal;r instanceof AbortSignal&&!r.aborted&&(n.addEventListener("contextmenu",rt,{signal:r}),n.addEventListener("click",s,{signal:r})),this.#v.append(n)}}function kt(t,e,i){for(const s of i)e.addEventListener(s,t[s].bind(t))}class It{static#B=NaN;static#F=null;static#R=NaN;static#L=null;static initializeAndAddPointerId(t){(It.#F||=new Set).add(t)}static setPointer(t,e){It.#B||=e,It.#L??=t}static setTimeStamp(t){It.#R=t}static isSamePointerId(t){return It.#B===t}static isSamePointerIdOrRemove(t){return It.#B===t||(It.#F?.delete(t),!1)}static isSamePointerType(t){return It.#L===t}static isInitializedAndDifferentPointerType(t){return null!==It.#L&&!It.isSamePointerType(t)}static isSameTimeStamp(t){return It.#R===t}static isUsingMultiplePointers(){return It.#F?.size>=1}static clearPointerType(){It.#L=null}static clearPointerIds(){It.#B=NaN,It.#F=null}static clearTimeStamp(){It.#R=NaN}}class Bt{#N=0;get id(){return`${o}${this.#N++}`}}class Ft{#O=z();#N=0;#U=null;static get _isSVGFittingCanvas(){const t=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),e=new Image;return 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>',T(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#H(t,e){this.#U||=new Map;let i=this.#U.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.#O}_${this.#N++}`,refCounter:0,isSvg:!1},"string"==typeof e?(i.url=e,t=await Q(e,"blob")):e instanceof File?t=i.file=e:e instanceof Blob&&(t=e),"image/svg+xml"===t.type){const e=Ft._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){w(t),i=null}return this.#U.set(t,i),i&&this.#U.set(i.id,i),i}async getFromFile(t){const{lastModified:e,name:i,size:s,type:n}=t;return this.#H(`${e}_${i}_${s}_${n}`,t)}async getFromUrl(t){return this.#H(t,t)}async getFromBlob(t,e){const i=await e;return this.#H(t,i)}async getFromId(t){this.#U||=new Map;const e=this.#U.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.#U||=new Map;let i=this.#U.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.#O}_${this.#N++}`,refCounter:1,isSvg:!1},this.#U.set(t,i),this.#U.set(i.id,i),i}getSvgUrl(t){const e=this.#U.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#U||=new Map;const e=this.#U.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.#O}_`)}}class Rt{#z=[];#G=!1;#j;#$=-1;constructor(t=128){this.#j=t}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:a=!1,keepUndo:r=!1}){if(s&&t(),this.#G)return;const o={cmd:t,undo:e,post:i,type:n};if(-1===this.#$)return this.#z.length>0&&(this.#z.length=0),this.#$=0,void this.#z.push(o);if(a&&this.#z[this.#$].type===n)return r&&(o.undo=this.#z[this.#$].undo),void(this.#z[this.#$]=o);const l=this.#$+1;l===this.#j?this.#z.splice(0,1):(this.#$=l,l<this.#z.length&&this.#z.splice(l)),this.#z.push(o)}undo(){if(-1===this.#$)return;this.#G=!0;const{undo:t,post:e}=this.#z[this.#$];t(),e?.(),this.#G=!1,this.#$-=1}redo(){if(this.#$<this.#z.length-1){this.#$+=1,this.#G=!0;const{cmd:t,post:e}=this.#z[this.#$];t(),e?.(),this.#G=!1}}hasSomethingToUndo(){return-1!==this.#$}hasSomethingToRedo(){return this.#$<this.#z.length-1}cleanType(t){if(-1!==this.#$){for(let e=this.#$;e>=0;e--)if(this.#z[e].type!==t)return this.#z.splice(e+1,this.#$-e),void(this.#$=e);this.#z.length=0,this.#$=-1}}destroy(){this.#z=null}}class Lt{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=R.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)))}}#V(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.#V(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||ot(e))}}class Nt{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",e.style.colorScheme="only light",document.body.append(e);for(const i of t.keys()){e.style.color=i;const s=window.getComputedStyle(e).color;t.set(i,ct(s))}e.remove()}(t),T(this,"_colors",t)}convert(t){const e=ct(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 Nt._colorsMapping.get(t);return e}getHexCode(t){const e=this._colors.get(t);return e?N.makeHexColor(...e):t}}class Ot{#W=new AbortController;#X=null;#q=null;#K=new Map;#Y=new Map;#Q=null;#J=null;#Z=null;#tt=new Rt;#et=null;#it=null;#st=null;#nt=0;#at=new Set;#rt=null;#ot=null;#lt=new Set;_editorUndoBar=null;#ht=!1;#dt=!1;#ct=!1;#ut=null;#pt=null;#gt=null;#mt=null;#ft=!1;#bt=null;#vt=new Bt;#yt=!1;#wt=!1;#At=!1;#xt=null;#Ct=null;#_t=null;#St=null;#Tt=null;#Et=l.NONE;#Mt=new Set;#Dt=null;#Pt=null;#kt=null;#It=null;#Bt=null;#Ft={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#Rt=[0,0];#Lt=null;#Nt=null;#Ot=null;#Ut=null;#Ht=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=Ot.prototype,e=t=>t.#Nt.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 T(this,"_keyboardManager",new Lt([[["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.#Nt.contains(e)&&!t.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Nt.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,d,c,u,p,g,m){const f=this._signal=this.#W.signal;this.#Nt=t,this.#Ot=e,this.#Ut=i,this.#Q=s,this.#et=n,this.#Pt=a,this.#Bt=o,this._eventBus=r,r._on("editingaction",this.onEditingAction.bind(this),{signal:f}),r._on("pagechanging",this.onPageChanging.bind(this),{signal:f}),r._on("scalechanging",this.onScaleChanging.bind(this),{signal:f}),r._on("rotationchanging",this.onRotationChanging.bind(this),{signal:f}),r._on("setpreference",this.onSetPreference.bind(this),{signal:f}),r._on("switchannotationeditorparams",t=>this.updateParams(t.type,t.value),{signal:f}),window.addEventListener("pointerdown",()=>{this.#wt=!0},{capture:!0,signal:f}),window.addEventListener("pointerup",()=>{this.#wt=!1},{capture:!0,signal:f}),window.addEventListener("beforeunload",this.#zt.bind(this),{capture:!0,signal:f}),this.#Gt(),this.#jt(),this.#$t(),this.#J=o.annotationStorage,this.#ut=o.filterFactory,this.#kt=l,this.#mt=h||null,this.#ht=d,this.#dt=c,this.#ct=u,this.#Tt=p||null,this.viewParameters={realScale:Y.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=g||null,this._supportsPinchToZoom=!1!==m,n?.setSidebarUiManager(this)}destroy(){this.#Ht?.resolve(),this.#Ht=null,this.#W?.abort(),this.#W=null,this._signal=null;for(const t of this.#Y.values())t.destroy();this.#Y.clear(),this.#K.clear(),this.#lt.clear(),this.#St?.clear(),this.#X=null,this.#Mt.clear(),this.#tt.destroy(),this.#Q?.destroy(),this.#et?.destroy(),this.#Pt?.destroy(),this.#bt?.hide(),this.#bt=null,this.#_t?.destroy(),this.#_t=null,this.#q=null,this.#pt&&(clearTimeout(this.#pt),this.#pt=null),this.#Lt&&(clearTimeout(this.#Lt),this.#Lt=null),this._editorUndoBar?.destroy(),this.#Bt=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#Tt}get useNewAltTextFlow(){return this.#dt}get useNewAltTextWhenAddingImage(){return this.#ct}get hcmFilter(){return T(this,"hcmFilter",this.#kt?this.#ut.addHCMFilter(this.#kt.foreground,this.#kt.background):"none")}get direction(){return T(this,"direction",getComputedStyle(this.#Nt).direction)}get _highlightColors(){return T(this,"_highlightColors",this.#mt?new Map(this.#mt.split(",").map(t=>((t=t.split("=").map(t=>t.trim()))[1]=t[1].toUpperCase(),t))):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return T(this,"highlightColors",null);const e=new Map,i=!!this.#kt;for(const[s,n]of t){const t=s.endsWith("_HCM");i&&t?e.set(s.replace("_HCM",""),n):i||t||e.set(s,n)}return T(this,"highlightColors",e)}get highlightColorNames(){return T(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}getNonHCMColor(t){if(!this._highlightColors)return t;const e=this.highlightColorNames.get(t);return this._highlightColors.get(e)||t}getNonHCMColorName(t){return this.highlightColorNames.get(t)||t}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#st=t}setMainHighlightColorPicker(t){this.#_t=t}editAltText(t,e=!1){this.#Q?.editAltText(this,t,e)}hasCommentManager(){return!!this.#et}editComment(t,e,i,s){this.#et?.showDialog(this,t,e,i,s)}selectComment(t,e){const i=this.#Y.get(t),s=i?.getEditorByUID(e);s?.toggleComment(!0,!0)}updateComment(t){this.#et?.updateComment(t.getData())}updatePopupColor(t){this.#et?.updatePopupColor(t)}removeComment(t){this.#et?.removeComments([t.uid])}deleteComment(t,e){const i=()=>{t.comment=e};this.addCommands({cmd:()=>{this._editorUndoBar?.show(i,"comment"),this.toggleComment(null),t.comment=null},undo:i,mustExec:!0})}toggleComment(t,e,i=void 0){this.#et?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#et?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#et?.dialogElement||null}async waitForEditorsRendered(t){if(this.#Y.has(t-1))return;const{resolve:e,promise:i}=Promise.withResolvers(),s=i=>{i.pageNumber===t&&(this._eventBus._off("editorsrendered",s),e())};this._eventBus.on("editorsrendered",s),await i}getSignature(t){this.#Pt?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#Pt}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}){"enableNewAltTextWhenAddingImage"===t&&(this.#ct=e)}onPageChanging({pageNumber:t}){this.#nt=t-1}deletePage(t){for(const e of this.getEditors(t))e.remove();this.#Y.delete(t),this.#nt===t&&(this.#nt=0)}focusMainContainer(){this.#Nt.focus()}findParent(t,e){for(const i of this.#Y.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.#Ot.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#lt.add(t)}removeShouldRescale(t){this.#lt.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*Y.PDF_TO_CSS_UNITS;for(const t of this.#lt)t.onScaleChanging();this.#st?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#Vt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Wt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const e of this.#Y.values())if(e.hasTextLayer(t))return e;return null}highlightSelection(t="",e=!1){const i=document.getSelection();if(!i||i.isCollapsed)return;const{anchorNode:s,anchorOffset:n,focusNode:a,focusOffset:r}=i,o=i.toString(),h=this.#Vt(i).closest(".textLayer"),d=this.getSelectionBoxes(h);if(!d)return;i.empty();const c=this.#Wt(h),u=this.#Et===l.NONE,p=()=>{const i=c?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:d,anchorNode:s,anchorOffset:n,focusNode:a,focusOffset:r,text:o});u&&this.showAllEditors("highlight",!0,!0),e&&i?.editComment()};u?this.switchToMode(l.HIGHLIGHT,p):p()}commentSelection(t=""){this.highlightSelection(t,!0)}#zt(t){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#Xt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#Vt(t).closest(".textLayer"),i=this.getSelectionBoxes(e);i&&(this.#bt||=new Pt(this),this.#bt.show(e,i,"ltr"===this.direction))}getAndRemoveDataFromAnnotationStorage(t){if(!this.#J)return null;const e=`${o}${t}`,i=this.#J.getRawValue(e);return i&&this.#J.remove(e),i}addToAnnotationStorage(t){t.isEmpty()||!this.#J||this.#J.has(t.id)||this.#J.setValue(t.id,t)}a11yAlert(t,e=null){const i=this.#Ut;i&&(i.setAttribute("data-l10n-id",t),e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args"))}#qt(){const t=document.getSelection();if(!t||t.isCollapsed)return void(this.#Dt&&(this.#bt?.hide(),this.#Dt=null,this.#Kt({hasSelectedText:!1})));const{anchorNode:e}=t;if(e===this.#Dt)return;const i=this.#Vt(t).closest(".textLayer");if(i){if(this.#bt?.hide(),this.#Dt=e,this.#Kt({hasSelectedText:!0}),(this.#Et===l.HIGHLIGHT||this.#Et===l.NONE)&&(this.#Et===l.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#ft=this.isShiftKeyDown,!this.isShiftKeyDown)){const t=this.#Et===l.HIGHLIGHT?this.#Wt(i):null;if(t?.toggleDrawing(),this.#wt){const e=new AbortController,i=this.combinedSignal(e),s=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),t?.toggleDrawing(!0),"pointerup"===i.type&&this.#Yt("main_toolbar"))};window.addEventListener("pointerup",s,{signal:i}),window.addEventListener("blur",s,{signal:i})}else t?.toggleDrawing(!0),this.#Yt("main_toolbar")}}else this.#Dt&&(this.#bt?.hide(),this.#Dt=null,this.#Kt({hasSelectedText:!1}))}#Yt(t=""){this.#Et===l.HIGHLIGHT?this.highlightSelection(t):this.#ht&&this.#Xt()}#Gt(){document.addEventListener("selectionchange",this.#qt.bind(this),{signal:this._signal})}#Qt(){if(this.#gt)return;this.#gt=new AbortController;const t=this.combinedSignal(this.#gt);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#Jt(){this.#gt?.abort(),this.#gt=null}blur(){if(this.isShiftKeyDown=!1,this.#ft&&(this.#ft=!1,this.#Yt("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#Mt)if(e.div.contains(t)){this.#Ct=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#Ct)return;const[t,e]=this.#Ct;this.#Ct=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#$t(){if(this.#xt)return;this.#xt=new AbortController;const t=this.combinedSignal(this.#xt);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#Zt(){this.#xt?.abort(),this.#xt=null}#te(){if(this.#it)return;this.#it=new AbortController;const t=this.combinedSignal(this.#it);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})}#ee(){this.#it?.abort(),this.#it=null}#jt(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#$t(),this.setEditingState(!0)}removeEditListeners(){this.#Zt(),this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#ot)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.#ot)if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){if(t.preventDefault(),this.#X?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const t of this.#Mt){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.#ot)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 w(`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.#ie(e);this.#se(t)},n=()=>{for(const e of t)e.remove()};this.addC