react-edit-to-html 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require("react");l=c(l,1);let u=require("react/jsx-runtime");var d=o({AbortException:()=>me,AnnotationEditorLayer:()=>aa,AnnotationEditorParamsType:()=>C,AnnotationEditorType:()=>S,AnnotationEditorUIManager:()=>ut,AnnotationLayer:()=>Fi,AnnotationMode:()=>y,AnnotationType:()=>D,CSSConstants:()=>Ge,ColorPicker:()=>Zr,DOMSVGFactory:()=>ri,DrawLayer:()=>ua,FeatureTest:()=>L,GlobalWorkerOptions:()=>Dr,ImageKind:()=>E,InvalidPDFException:()=>de,MathClamp:()=>B,OPS:()=>A,OutputScale:()=>He,PDFDataRangeTransport:()=>Hr,PDFDateString:()=>Ie,PDFWorker:()=>Gr,PasswordException:()=>le,PasswordResponses:()=>M,PermissionFlag:()=>w,PixelsPerInch:()=>Oe,RenderingCancelledException:()=>Ae,ResponseException:()=>fe,SignatureExtractor:()=>ea,SupportedImageMimeTypes:()=>Ue,TextLayer:()=>Rr,TextLayerImages:()=>fa,TouchManager:()=>pt,Util:()=>R,VerbosityLevel:()=>k,XfaLayer:()=>De,applyOpacity:()=>Ke,build:()=>Xr,createValidAbsoluteUrl:()=>ae,fetchData:()=>ke,findContrastColor:()=>Qe,getDocument:()=>Br,getFilenameFromUrl:()=>Me,getPdfFilenameFromUrl:()=>Ne,getRGB:()=>Re,getRGBA:()=>Le,getUuid:()=>be,isDataScheme:()=>je,isPdfFile:()=>V,isValidExplicitDest:()=>Xt,makeArr:()=>Se,makeMap:()=>Ce,makeObj:()=>we,noContextMenu:()=>H,normalizeUnicode:()=>ye,renderRichText:()=>$e,setLayerDimensions:()=>Ve,shadow:()=>I,stopEvent:()=>U,updateUrlHash:()=>oe,version:()=>Yr}),f=typeof process==`object`&&process+``==`[object process]`&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!==`browser`),p=[1/0,1/0,-1/0,-1/0],m=new Float32Array(p),h=[.001,0,0,.001,0,0],g=1.35,_=`http://www.w3.org/2000/svg`,v={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},y={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},b=`pdfjs_internal_id_`,x=`pdfjs_internal_editor_`,S={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},C={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},w={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},T={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},E={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},D={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,RICHMEDIA:27},O={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},k={ERRORS:0,WARNINGS:1,INFOS:5},A={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},j={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},M={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},ee=k.WARNINGS;function te(e){Number.isInteger(e)&&(ee=e)}function ne(){return ee}function re(e){ee>=k.INFOS&&console.info(`Info: ${e}`)}function N(e){ee>=k.WARNINGS&&console.warn(`Warning: ${e}`)}function P(e){throw Error(e)}function F(e,t){e||P(t)}function ie(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}function ae(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`&&(n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`),n.tryConvertEncoding))try{e=_e(e)}catch{}let r=t?URL.parse(e,t):URL.parse(e);return ie(r)?r:null}function oe(e,t,n=!1){let r=URL.parse(e);return r?(r.hash=t,r.href):n&&ae(e,`http://example.com`)?e.split(`#`,1)[0]+`${t?`#${t}`:``}`:``}function se(e){return e.substring(e.lastIndexOf(`/`)+1)}function I(e,t,n,r=!1){return Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1}),n}var ce=function(){function e(e,t){this.message=e,this.name=t}return e.prototype=Error(),e.constructor=e,e}(),le=class extends ce{constructor(e,t){super(e,`PasswordException`),this.code=t}},ue=class extends ce{constructor(e,t){super(e,`UnknownErrorException`),this.details=t}},de=class extends ce{constructor(e){super(e,`InvalidPDFException`)}},fe=class extends ce{constructor(e,t,n){super(e,`ResponseException`),this.status=t,this.missing=n}},pe=class extends ce{constructor(e){super(e,`FormatError`)}},me=class extends ce{constructor(e){super(e,`AbortException`)}};function he(e){(typeof e!=`object`||e?.length===void 0)&&P(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);let r=[];for(let i=0;i<t;i+=n){let a=Math.min(i+n,t),o=e.subarray(i,a);r.push(String.fromCharCode.apply(null,o))}return r.join(``)}function ge(e){typeof e!=`string`&&P(`Invalid argument for stringToBytes`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;++r)n[r]=e.charCodeAt(r)&255;return n}var L=class{static get isLittleEndian(){let e=new Uint8Array(4);e[0]=1;let t=new Uint32Array(e.buffer,0,1);return I(this,`isLittleEndian`,t[0]===1)}static get isOffscreenCanvasSupported(){return I(this,`isOffscreenCanvasSupported`,typeof OffscreenCanvas<`u`)}static get isImageDecoderSupported(){return I(this,`isImageDecoderSupported`,typeof ImageDecoder<`u`)}static get isFloat16ArraySupported(){return I(this,`isFloat16ArraySupported`,typeof Float16Array<`u`)}static get isSanitizerSupported(){return I(this,`isSanitizerSupported`,typeof Sanitizer<`u`)}static get platform(){let{platform:e,userAgent:t}=navigator;return I(this,`platform`,{isAndroid:t.includes(`Android`),isLinux:e.includes(`Linux`),isMac:e.includes(`Mac`),isWindows:e.includes(`Win`),isFirefox:t.includes(`Firefox`)})}static get isCanvasFilterSupported(){let e;return this.isOffscreenCanvasSupported?e=new OffscreenCanvas(1,1).getContext(`2d`):typeof document<`u`&&(e=document.createElement(`canvas`).getContext(`2d`)),I(this,`isCanvasFilterSupported`,e?.filter!==void 0)}static get isAlphaColorInputSupported(){if(typeof document>`u`)return I(this,`isAlphaColorInputSupported`,!1);let e=document.createElement(`input`);return e.type=`color`,e.setAttribute(`alpha`,``),e.value=`#ff000080`,I(this,`isAlphaColorInputSupported`,e.value!==`#ff0000`)}static get isBackdropFilterSupported(){return I(this,`isBackdropFilterSupported`,typeof CSS<`u`&&CSS.supports(`backdrop-filter`,`blur(1px)`))}},R=class{static get hexNums(){return I(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4],e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s,e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i,e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n,g+=n,h+=r,m+=r,_+=e,b+=e,y+=t,v+=t}n[0]=Math.min(n[0],p,h,m,g),n[1]=Math.min(n[1],_,y,v,b),n[2]=Math.max(n[2],p,h,m,g),n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1),t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e),n[1]=Math.min(n[1],t),n[2]=Math.max(n[2],e),n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n),i[1]=Math.min(i[1],t,r),i[2]=Math.max(i[2],e,n),i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p),l[1]=Math.min(l[1],m),l[2]=Math.max(l[2],p),l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d),this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o),c[1]=Math.min(c[1],t,s),c[2]=Math.max(c[2],e,o),c[3]=Math.max(c[3],t,s),this.#t(e,n,i,o,t,r,a,s,3*(-e+3*(n-i)+o),6*(e-2*n+i),3*(n-e),c),this.#t(e,n,i,o,t,r,a,s,3*(-t+3*(r-a)+s),6*(t-2*r+a),3*(r-t),c)}};function _e(e){return decodeURIComponent(escape(e))}var ve=null,z=null;function ye(e){return ve||(ve=/([\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,z=new Map([[`ſt`,`ſt`]])),e.replaceAll(ve,(e,t,n)=>t?t.normalize(`NFKC`):z.get(n))}function be(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),he(e)}function xe(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r)||!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}var Se=()=>[],Ce=()=>new Map,we=()=>Object.create(null);function B(e,t,n){return Math.min(Math.max(e,t),n)}var Te=class e{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e,this.userUnit=t,this.scale=n,this.rotation=r,this.offsetX=i,this.offsetY=a,n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f;switch(r%=360,r<0&&(r+=360),r){case 180:l=-1,u=0,d=0,f=1;break;case 90:l=0,u=1,d=1,f=0;break;case 270:l=0,u=-1,d=-1,f=0;break;case 0:l=1,u=0,d=0,f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}o&&(d=-d,f=-f);let p,m,h,g;l===0?(p=Math.abs(c-e[1])*n+i,m=Math.abs(s-e[0])*n+a,h=(e[3]-e[1])*n,g=(e[2]-e[0])*n):(p=Math.abs(s-e[0])*n+i,m=Math.abs(c-e[1])*n+a,h=(e[2]-e[0])*n,g=(e[3]-e[1])*n),this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c],this.width=h,this.height=g}get rawDims(){let e=this.viewBox;return I(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:t=this.scale,rotation:n=this.rotation,offsetX:r=this.offsetX,offsetY:i=this.offsetY,dontFlip:a=!1}={}){return new e({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:n,offsetX:r,offsetY:i,dontFlip:a})}convertToViewportPoint(e,t){let n=[e,t];return R.applyTransform(n,this.transform),n}convertToPdfPoint(e,t){let n=[e,t];return R.applyInverseTransform(n,this.transform),n}},Ee=class e{static textContent(t){let n=[],r={items:n,styles:Object.create(null)};function i(t){if(!t)return;let r=null,a=t.name;if(a===`#text`)r=t.value;else if(e.shouldBuildText(a))t?.attributes?.textContent?r=t.attributes.textContent:t.value&&(r=t.value);else return;if(r!==null&&n.push({str:r}),t.children)for(let e of t.children)i(e)}return i(t),r}static shouldBuildText(e){return!(e===`textarea`||e===`input`||e===`option`||e===`select`)}},De=class{static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:if(a.value!==null&&(e.textContent=a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){if(a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`),i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{if(a.value!==null&&e.setAttribute(`value`,a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})});break}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null)switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i.addLinkAttributes(e,a.href,a.newWindow),n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=document.createElement(r.name);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;if(s.append(a),e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e),o&&Ee.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e),a.append(e);continue}let d=s?.attributes?.xmlns?document.createElementNS(s.attributes.xmlns,u):document.createElement(u);if(a.append(d),s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n}),s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&Ee.shouldBuildText(u)&&c.push(e),d.append(e)}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t,e.div.hidden=!1}static getPageViewport(e,{scale:t=1,rotation:n=0}){let{width:r,height:i}=e.attributes.style;return new Te({viewBox:[0,0,parseInt(r,10),parseInt(i,10)],userUnit:1,scale:t,rotation:n})}},Oe=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function ke(e,t=`text`){if(Fe(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0),i.responseType=t===`bytes`?`arraybuffer`:t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText);return}r(Error(i.statusText))}},i.send(null)})}var Ae=class extends ce{constructor(e,t=0){super(e,`RenderingCancelledException`),this.extraDelay=t}};function je(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function V(e){return typeof e==`string`&&/\.pdf$/i.test(e)}function Me(e){return[e]=e.split(/[#?]/,1),se(e)}function Ne(e,t=`document.pdf`){if(typeof e!=`string`)return t;if(je(e))return N(`getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.`),t;let n=(e=>{try{return new URL(e)}catch{}try{return new URL(decodeURIComponent(e))}catch{}try{return new URL(e,`https://foo.bar`)}catch{}try{return new URL(decodeURIComponent(e),`https://foo.bar`)}catch{}return null})(e);if(!n)return t;let r=e=>{try{let t=decodeURIComponent(e);return t.includes(`/`)&&(t=se(t),t.length===4&&i.test(t))?e:t}catch{return e}},i=/\.pdf$/i,a=se(n.pathname);if(i.test(a))return r(a);if(n.searchParams.size>0){let e=e=>[...e].findLast(e=>i.test(e)),t=e(n.searchParams.values())??e(n.searchParams.keys());if(t)return r(t)}if(n.hash){let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(n.hash);if(e)return r(e[0])}return t}var Pe=class{#e=new Map;times=[];time(e){this.#e.has(e)&&N(`Timer is already running for ${e}`),this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||N(`Timer has not been started for ${e}`),this.times.push({name:e,start:this.#e.get(e),end:Date.now()}),this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}};function Fe(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function H(e){e.preventDefault()}function U(e){e.preventDefault(),e.stopPropagation()}var Ie=class{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;return u=u>=0&&u<=59?u:0,c===`-`?(a+=l,o+=u):c===`+`&&(a-=l,o-=u),new Date(Date.UTC(n,r,i,a,o,s))}};function Le(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(parseFloat(t[1])*255),Math.round(parseFloat(t[2])*255),Math.round(parseFloat(t[3])*255),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Re(e){let t=Le(e);return t?t.slice(0,3):(N(`Not a valid color format: "${e}"`),[0,0,0])}function ze(e){let t=document.createElement(`span`);t.style.visibility=`hidden`,t.style.colorScheme=`only light`,document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Re(r))}t.remove()}function W(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function Be(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function Ve(e,t,n=!1,r=!0){if(t instanceof Te){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;!n||t.rotation%180==0?(a.width=o,a.height=s):(a.width=s,a.height=o)}r&&e.setAttribute(`data-main-rotation`,t.rotation)}var He=class e{constructor(){let{pixelRatio:t}=e;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(t,n,r,i,a=-1){let o=1/0,s=1/0,c=1/0;r=e.capPixels(r,a),r>0&&(o=Math.sqrt(r/(t*n))),i!==-1&&(s=i/t,c=i/n);let l=Math.min(o,s,c);return this.sx>l||this.sy>l?(this.sx=l,this.sy=l,!0):!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}},Ue=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`],We=class{static get isDarkMode(){return I(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}},Ge=class{static get commentForegroundColor(){let e=document.createElement(`span`);e.classList.add(`comment`,`sidebar`);let{style:t}=e;t.width=t.height=`0`,t.display=`none`,t.color=`var(--comment-fg-color)`,document.body.append(e);let{color:n}=window.getComputedStyle(e);return e.remove(),I(this,`commentForegroundColor`,Re(n))}};function Ke(e,t){t=B(t??1,0,1);let n=255*(1-t);return e.map(e=>Math.round(e*t+n))}function qe(e,t){let n=e[0]/255,r=e[1]/255,i=e[2]/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)t[0]=t[1]=0;else{let e=a-o;switch(t[1]=s<.5?e/(a+o):e/(2-a-o),a){case n:t[0]=((r-i)/e+(r<i?6:0))*60;break;case r:t[0]=((i-n)/e+2)*60;break;case i:t[0]=((n-r)/e+4)*60;break}}t[2]=s}function Je(e,t){let n=e[0],r=e[1],i=e[2],a=(1-Math.abs(2*i-1))*r,o=a*(1-Math.abs(n/60%2-1)),s=i-a/2;switch(Math.floor(n/60)){case 0:t[0]=a+s,t[1]=o+s,t[2]=s;break;case 1:t[0]=o+s,t[1]=a+s,t[2]=s;break;case 2:t[0]=s,t[1]=a+s,t[2]=o+s;break;case 3:t[0]=s,t[1]=o+s,t[2]=a+s;break;case 4:t[0]=o+s,t[1]=s,t[2]=a+s;break;case 5:case 6:t[0]=a+s,t[1]=s,t[2]=o+s;break}}function Ye(e){return e<=.03928?e/12.92:((e+.055)/1.055)**2.4}function Xe(e,t,n){Je(e,n),n.map(Ye);let r=.2126*n[0]+.7152*n[1]+.0722*n[2];Je(t,n),n.map(Ye);let i=.2126*n[0]+.7152*n[1]+.0722*n[2];return r>i?(r+.05)/(i+.05):(i+.05)/(r+.05)}var Ze=new Map;function Qe(e,t){let n=e[0]+e[1]*256+e[2]*65536+t[0]*16777216+t[1]*4294967296+t[2]*1099511627776,r=Ze.get(n);if(r)return r;let i=new Float32Array(9),a=i.subarray(0,3),o=i.subarray(3,6);qe(e,o);let s=i.subarray(6,9);qe(t,s);let c=s[2]<.5,l=c?12:4.5;if(o[2]=c?Math.sqrt(o[2]):1-Math.sqrt(1-o[2]),Xe(o,s,a)<l){let e,t;for(c?(e=o[2],t=1):(e=0,t=o[2]);t-e>.005;){let n=o[2]=(e+t)/2;c===Xe(o,s,a)<l?e=n:t=n}o[2]=c?t:e}return Je(o,a),r=R.makeHexColor(Math.round(a[0]*255),Math.round(a[1]*255),Math.round(a[2]*255)),Ze.set(n,r),r}function $e({html:e,dir:t,className:n},r){let i=document.createDocumentFragment();if(typeof e==`string`){let n=document.createElement(`p`);n.dir=t||`auto`;let r=e.split(/\r\n?|\n/);for(let e=0,t=r.length;e<t;++e){let i=r[e];n.append(document.createTextNode(i)),e<t-1&&n.append(document.createElement(`br`))}i.append(n)}else De.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n),r.append(i)}function et(e){let t=new Path2D;if(!e)return t;for(let n=0,r=e.length;n<r;)switch(e[n++]){case j.moveTo:t.moveTo(e[n++],e[n++]);break;case j.lineTo:t.lineTo(e[n++],e[n++]);break;case j.curveTo:t.bezierCurveTo(e[n++],e[n++],e[n++],e[n++],e[n++],e[n++]);break;case j.quadraticCurveTo:t.quadraticCurveTo(e[n++],e[n++],e[n++],e[n++]);break;case j.closePath:t.closePath();break;default:N(`Unrecognized drawing path operator: ${e[n-1]}`);break}return t}var tt=class e{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(t){this.#n=t,e.#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(){let t=this.#e=document.createElement(`div`);t.classList.add(`editToolbar`,`hidden`),t.setAttribute(`role`,`toolbar`);let n=this.#n._uiManager._signal;n instanceof AbortSignal&&!n.aborted&&(t.addEventListener(`contextmenu`,H,{signal:n}),t.addEventListener(`pointerdown`,e.#l,{signal:n}));let r=this.#r=document.createElement(`div`);r.className=`buttons`,t.append(r);let i=this.#n.toolbarPosition;if(i){let{style:e}=t;e.insetInlineEnd=`${100*(this.#n._uiManager.direction===`ltr`?1-i[0]:i[0])}%`,e.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#e}static#l(e){e.stopPropagation()}#u(e){this.#n._focusEventsAllowed=!1,U(e)}#d(e){this.#n._focusEventsAllowed=!0,U(e)}#f(e){let t=this.#n._uiManager._signal;return!(t instanceof AbortSignal)||t.aborted?!1:(e.addEventListener(`focusin`,this.#u.bind(this),{capture:!0,signal:t}),e.addEventListener(`focusout`,this.#d.bind(this),{capture:!0,signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),!0)}hide(){this.#e.classList.add(`hidden`),this.#t?.hideDropdown()}show(){this.#e.classList.remove(`hidden`),this.#i?.shown(),this.#a?.shown()}addDeleteButton(){let{editorType:t,_uiManager:n}=this.#n,r=document.createElement(`button`);r.classList.add(`basic`,`deleteButton`),r.tabIndex=0,r.setAttribute(`data-l10n-id`,e.#c[t]),this.#f(r)&&r.addEventListener(`click`,e=>{n.delete()},{signal:n._signal}),this.#r.append(r)}get#p(){let e=document.createElement(`div`);return e.className=`divider`,e}async addAltText(e){let t=await e.render();this.#f(t),this.#r.append(t,this.#p),this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;t?(this.#r.insertBefore(n,t),this.#r.insertBefore(r,t)):this.#r.append(n,r),this.#a=e,e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t),this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t),this.#r.append(t,this.#p)}removeButton(e){switch(e){case`comment`:this.#a?.removeToolbarCommentButton(),this.#a=null,this.#o?.remove(),this.#o=null;break}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t);break}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove(),this.#t?.destroy(),this.#t=null}},nt=class{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`,e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,H,{signal:t});let n=this.#e=document.createElement(`div`);return n.className=`buttons`,e.append(n),this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)}),this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)}),e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(e<n)continue;let a=i.x+(t?i.width:0);if(e>n){r=a,n=e;continue}t?a>r&&(r=a):a<r&&(r=a)}return[t?1-r:r,n]}show(e,t,n){let[r,i]=this.#i(t,n),{style:a}=this.#t||=this.#r();e.append(this.#t),a.insetInlineEnd=`${100*r}%`,a.top=`calc(${100*i}% + var(--editor-toolbar-vert-offset))`}hide(){this.#t.remove()}#a(e,t,n,r){let i=document.createElement(`button`);i.classList.add(`basic`,e),i.tabIndex=0,i.setAttribute(`data-l10n-id`,t);let a=document.createElement(`span`);i.append(a),a.className=`visuallyHidden`,a.setAttribute(`data-l10n-id`,n);let o=this.#n._signal;o instanceof AbortSignal&&!o.aborted&&(i.addEventListener(`contextmenu`,H,{signal:o}),i.addEventListener(`click`,r,{signal:o})),this.#e.append(i)}},rt=Object.freeze({internal:`068f09d6-5b37-4f77-a97a-f8ff4f253b68`});function it(e,t,n){for(let r of n)t.addEventListener(r,e[r].bind(e))}var G=class e{static#e=NaN;static#t=null;static#n=NaN;static#r=null;static initializeAndAddPointerId(t){(e.#t||=new Set).add(t)}static setPointer(t,n){e.#e||=n,e.#r??=t}static setTimeStamp(t){e.#n=t}static isSamePointerId(t){return e.#e===t}static isSamePointerIdOrRemove(t){return e.#e===t?!0:(e.#t?.delete(t),!1)}static isSamePointerType(t){return e.#r===t}static isInitializedAndDifferentPointerType(t){return e.#r!==null&&!e.isSamePointerType(t)}static isSameTimeStamp(t){return e.#n===t}static isUsingMultiplePointers(){return e.#t?.size>=1}static clearPointerType(){e.#r=null}static clearPointerIds(){e.#e=NaN,e.#t=null}static clearTimeStamp(){e.#n=NaN}},at=class{#e=0;get id(){return`${x}${this.#e++}`}},ot=class e{#e=be();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="${_}"><rect width="1" height="1" style="fill:red;"/></svg>`,t=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),n=new Image;n.src=e;let r=n.decode().then(()=>(t.drawImage(n,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0));return I(this,`_isSVGFittingCanvas`,r)}async#r(t,n){this.#n||=new Map;let r=this.#n.get(t);if(r===null)return null;if(r?.bitmap)return r.refCounter+=1,r;try{r||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let t;if(typeof n==`string`?(r.url=n,t=await ke(n,`blob`)):n instanceof File?t=r.file=n:n instanceof Blob&&(t=n),t.type===`image/svg+xml`){let n=e._isSVGFittingCanvas,i=new FileReader,a=new Image,o=new Promise((e,t)=>{a.onload=()=>{r.bitmap=a,r.isSvg=!0,e()},i.onload=async()=>{let e=r.svgUrl=i.result;a.src=await n?`${e}#svgView(preserveAspectRatio(none))`:e},a.onerror=i.onerror=t});i.readAsDataURL(t),await o}else r.bitmap=await createImageBitmap(t);r.refCounter=1}catch(e){N(e),r=null}return this.#n.set(t,r),r&&this.#n.set(r.id,r),r}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap)return t.refCounter+=1,t;if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;return delete t.blobPromise,this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap)return n.refCounter+=1,n;let r=new OffscreenCanvas(t.width,t.height);return r.getContext(`2d`).drawImage(t,0,0),n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1},this.#n.set(e,n),this.#n.set(n.id,n),n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t||(--t.refCounter,t.refCounter!==0))return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n),t.blobPromise=e.convertToBlob()}n.close?.(),t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}},st=class{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){if(r&&e(),this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0),this.#r=0,this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo),this.#e[this.#r]=s;return}let c=this.#r+1;c===this.#n?this.#e.splice(0,1):(this.#r=c,c<this.#e.length&&this.#e.splice(c)),this.#e.push(s)}undo(){if(this.#r===-1)return;this.#t=!0;let{undo:e,post:t}=this.#e[this.#r];e(),t?.(),this.#t=!1,--this.#r}redo(){if(this.#r<this.#e.length-1){this.#r+=1,this.#t=!0;let{cmd:e,post:t}=this.#e[this.#r];e(),t?.(),this.#t=!1}}hasSomethingToUndo(){return this.#r!==-1}hasSomethingToRedo(){return this.#r<this.#e.length-1}cleanType(e){if(this.#r!==-1){for(let t=this.#r;t>=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t),this.#r=t;return}this.#e.length=0,this.#r=-1}}destroy(){this.#e=null}},ct=class e{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(t){this.callbacks=new Map;let{isMac:n}=L.platform;for(let[r,i,a={}]of t){let t=r.some(e=>e.startsWith(`mac+`));for(let o of r){let r=o;if(t){let e=o.startsWith(`mac+`);if(n!==e)continue;e&&(r=o.slice(4))}let[s,c]=e.#e(r);s!==null&&this.callbacks.getOrInsertComputed(s,Se).push({callback:i,options:a,modifiers:c})}}}static#e(t){let n=null,r=0;for(let i of t.split(`+`)){if(i=i.trim(),!i)continue;let a=i.toUpperCase(),o=e[a];if(o){r|=o;continue}if(n!==null){N(`KeyboardManager: multiple keys in shortcut "${t}"`);break}n=a===`SPACE`?` `:i}return n===null&&N(`KeyboardManager: no key found in shortcut "${t}"`),[n,r]}static#t(e){let t=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(e);return t?t[1]?.toLowerCase()??t[2]:null}exec(t,n){let r=this.callbacks.get(n.key);if(!r){if(/^[a-z]$/i.test(n.key))return;let t=e.#t(n.code);if(t===null||t===n.key||(r=this.callbacks.get(t),!r))return}let i=(n.altKey?e.ALT:0)|(n.ctrlKey?e.CTRL:0)|(n.metaKey?e.META:0)|(n.shiftKey?e.SHIFT:0),a=r.find(e=>e.modifiers===i);if(!a)return;let{callback:o,options:{bubbles:s=!1,args:c=[],checker:l=null}}=a;l&&!l(t,n)||(o.bind(t,...c,n)(),s||U(n))}},lt=class e{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);return ze(e),I(this,`_colors`,e)}convert(t){let n=Re(t);if(!window.matchMedia(`(forced-colors: active)`).matches)return n;for(let[t,r]of this._colors)if(r.every((e,t)=>e===n[t]))return e._colorsMapping.get(t);return n}getHexCode(e){let t=this._colors.get(e);return t?R.makeHexColor(...t):e}},ut=class e{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new st;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new at;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=S.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),r=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},i=this.TRANSLATE_SMALL,a=this.TRANSLATE_BIG;return I(this,`_keyboardManager`,new ct([[[`ctrl+a`,`mac+meta+a`],t.selectAll,{checker:r}],[[`ctrl+z`,`mac+meta+z`],t.undo,{checker:r}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],t.redo,{checker:r}],[[`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:r}],[[`Enter`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[`Space`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`],t.unselectAll],[[`ArrowLeft`],t.translateSelectedEditors,{args:[-i,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t.translateSelectedEditors,{args:[-a,0],checker:n}],[[`ArrowRight`],t.translateSelectedEditors,{args:[i,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t.translateSelectedEditors,{args:[a,0],checker:n}],[[`ArrowUp`],t.translateSelectedEditors,{args:[0,-i],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t.translateSelectedEditors,{args:[0,-a],checker:n}],[[`ArrowDown`],t.translateSelectedEditors,{args:[0,i],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t.translateSelectedEditors,{args:[0,a],checker:n}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e,this.#q=t,this.#J=n,this.#o=r,this.#u=i,this.#z=a,this.#H=s,this._eventBus=o;let _={signal:g,...rt};o.on(`editingaction`,this.onEditingAction.bind(this),_),o.on(`pagechanging`,this.onPageChanging.bind(this),_),o.on(`scalechanging`,this.onScaleChanging.bind(this),_),o.on(`rotationchanging`,this.onRotationChanging.bind(this),_),o.on(`setpreference`,this.onSetPreference.bind(this),_),o.on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),_),window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g}),window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g}),window.addEventListener(`beforeunload`,this.#Q.bind(this),{capture:!0,signal:g}),this.#ne(),this.#le(),this.#ae(),this.#s=s.annotationStorage,this.#x=s.filterFactory,this.#B=c,this.#w=l||null,this.#v=u,this.#y=d,this.#b=f,this.#F=p||null,this.viewParameters={realScale:Oe.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=m||null,this._supportsPinchToZoom=h!==!1,i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve(),this.#Y=null,this.#e?.abort(),this.#e=null,this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear(),this.#r.clear(),this.#_.clear(),this.#P?.clear(),this.#t=null,this.#L.clear(),this.#l.destroy(),this.#o?.destroy(),this.#u?.destroy(),this.#z?.destroy(),this.#E?.hide(),this.#E=null,this.#N?.destroy(),this.#N=null,this.#n=null,this.#S&&=(clearTimeout(this.#S),null),this.#G&&=(clearTimeout(this.#G),null),this._editorUndoBar?.destroy(),this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return I(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return I(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return I(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>(e=e.split(`=`).map(e=>e.trim()),e[1]=e[1].toUpperCase(),e))):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return I(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);if(n&&e){t.set(r.replace(`_HCM`,``),i);continue}!n&&!e&&t.set(r,i)}return I(this,`highlightColors`,t)}get highlightColorNames(){return I(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){e?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`),this.toggleComment(null),e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{n.pageNumber===e&&(this._eventBus.off(`editorsrendered`,r),t())};this._eventBus.on(`editorsrendered`,r,rt),await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal,...rt}),this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){switch(e){case`enableNewAltTextWhenAddingImage`:this.#b=t;break}}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e),this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove(),this.viewParameters.realScale=e*Oe.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove(),this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===S.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0),t&&n?.editComment()};if(d){this.switchToMode(S.HIGHLIGHT,f);return}f()}commentSelection(e=``){this.highlightSelection(e,!0)}#Q(e){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#$(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);n&&(this.#E||=new nt(this),this.#E.show(t,n,this.direction===`ltr`))}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${x}${e}`,n=this.#s.getRawValue(t);return n&&this.#s.remove(t),n}addToAnnotationStorage(e){!e.isEmpty()&&this.#s&&!this.#s.has(e.id)&&this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;n&&(n.setAttribute(`data-l10n-id`,e),t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`))}#ee(){let e=document.getSelection();if(!e||e.isCollapsed){this.#R&&(this.#E?.hide(),this.#R=null,this.#ue({hasSelectedText:!1}));return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(!n){this.#R&&(this.#E?.hide(),this.#R=null,this.#ue({hasSelectedText:!1}));return}if(this.#E?.hide(),this.#R=t,this.#ue({hasSelectedText:!0}),!(this.#I!==S.HIGHLIGHT&&this.#I!==S.NONE)&&(this.#I===S.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0),this.#T=this.isShiftKeyDown,!this.isShiftKeyDown)){let e=this.#I===S.HIGHLIGHT?this.#Z(n):null;if(e?.toggleDrawing(),this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{n.type===`pointerup`&&n.button!==0||(t.abort(),e?.toggleDrawing(!0),n.type===`pointerup`&&this.#te(`main_toolbar`))};window.addEventListener(`pointerup`,r,{signal:n}),window.addEventListener(`blur`,r,{signal:n})}else e?.toggleDrawing(!0),this.#te(`main_toolbar`)}}#te(e=``){this.#I===S.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#$()}#ne(){document.addEventListener(`selectionchange`,this.#ee.bind(this),{signal:this._signal})}#re(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e}),window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#ie(){this.#C?.abort(),this.#C=null}blur(){if(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#te(`main_toolbar`)),!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e],t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null,t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal}),t.focus()}#ae(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e}),window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#oe(){this.#j?.abort(),this.#j=null}#se(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e}),document.addEventListener(`cut`,this.cut.bind(this),{signal:e}),document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#ce(){this.#d?.abort(),this.#d=null}#le(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e}),document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ae(),this.setEditingState(!0)}removeEditListeners(){this.#oe(),this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`,e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer),e.preventDefault();return}}copy(e){if(e.preventDefault(),this.#t?.commitOrRemove(),!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e),this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){N(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#me(t);this.#_e(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){N(`paste: "${e.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key===`Shift`&&(this.isShiftKeyDown=!0),this.#I!==S.NONE&&!this.isEditorHandlingKeyboard&&e._keyboardManager.exec(this,t)}keyup(e){this.isShiftKeyDown&&e.key===`Shift`&&(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#te(`main_toolbar`)))}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`);break}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);n&&(n.pageIndex=t,this.#i.set(t,n),this.#O?n.enable():n.disable())}startUpdatePages(){this.#a=new Map(this.#i),this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==S.HIGHLIGHT);e&&(e.pageIndex=t,e.id=this.getId(),e.isClone=!0,delete e.popupRef,this.#s.setValue(e.id,e))}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)i.pageIndex===n&&i.isClone&&(this.#s.remove(r),t.push(e.deserialize(i).then(t=>{t&&(t.isClone=!0,e.addOrRebuild(t))})));return Promise.all(t)}#ue(e){Object.entries(e).some(([e,t])=>this.#U[e]!==t)&&(this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)}),this.#I===S.HIGHLIGHT&&e.hasSelectedEditor===!1&&this.#de([[C.HIGHLIGHT_FREE,!0]]))}#de(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){e?(this.#re(),this.#se(),this.#ue({isEditing:this.#I!==S.NONE,isEmpty:this.#ge(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#ie(),this.#ce(),this.#ue({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#de(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e),this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e&&!(this.#Y&&(await this.#Y.promise,!this.#Y))){if(this.#Y=Promise.withResolvers(),this.#f?.commitOrRemove(),this.#I===S.POPUP&&this.#u?.hideSidebar(),this.#u?.destroyPopup(),this.#I=e,e===S.NONE){this.setEditingState(!1),this.#pe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide(),this.toggleComment(null),this.#Y.resolve();return}for(let e of this.#r.values())e.addStandaloneCommentButton();e===S.SIGNATURE&&await this.#z?.loadSignatures(),n&&G.clearPointerType(),this.setEditingState(!0),await this.#fe(),this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===S.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r),i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(!t){r&&this.addNewEditorFromKeyboard(),this.#Y.resolve();return}for(let e of this.#r.values())e.uid===t?(this.setSelected(e),a?e.editComment():i?e.enterInEditMode():e.focus()):e.unselect();this.#Y.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case C.CREATE:this.currentLayer.addNewEditor(t);return;case C.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}}),(this.#V||=new Map).set(e,t),this.showAllEditors(`highlight`,t);break}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(C.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[C.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values())e?t.disableClick():t.enableClick(),t.div.classList.toggle(`waiting`,e)}}async#fe(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#pe(){if(this.unselectAll(),this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){e.div.contains(document.activeElement)&&(this.#S&&clearTimeout(this.#S),this.#S=setTimeout(()=>{this.focusMainContainer(),this.#S=null},0)),this.#r.delete(e.id),e.annotationElementId&&this.#P?.delete(e.annotationElementId),this.unselect(e),(!e.annotationElementId||!this.#m.has(e.annotationElementId))&&this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId),this.addChangedExistingAnnotation(e),e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId),this.removeChangedExistingAnnotation(e),e.deleted=!1}#me(e){let t=this.#i.get(e.pageIndex);t?t.addOrRebuild(e):(this.addEditor(e),this.addToAnnotationStorage(e))}setActiveEditor(e){this.#t!==e&&(this.#t=e,e&&this.#de(e.propertiesToUpdate))}get#he(){let e=null;for(e of this.#L);return e}updateUI(e){this.#he===e&&this.#de(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#de(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e),e.unselect(),this.#ue({hasSelectedEditor:this.hasSelection});return}this.#L.add(e),e.select(),this.#de(e.propertiesToUpdate),this.#ue({hasSelectedEditor:!0})}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid}),this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup(),this.#L.clear(),this.#L.add(e),e.select(),this.#de(e.propertiesToUpdate),this.#ue({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect(),this.#L.delete(e),this.#ue({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo(),this.#ue({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#ge()}),this._editorUndoBar?.hide()}redo(){this.#l.redo(),this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#ge()})}addCommands(e){this.#l.add(e),this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#ge()})}cleanUndoStack(e){this.#l.cleanType(e)}#ge(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{this._editorUndoBar?.show(r,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},r=()=>{for(let e of t)this.#me(e)};this.addCommands({cmd:n,undo:r,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#_e(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)t.isEmpty()||(this.#L.add(t),t.select());this.#ue({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#_e(this.#r.values())}unselectAll(){if(!(this.#t&&(this.#t.commitOrRemove(),this.#I!==S.NONE))&&!this.#f?.commitOrRemove()&&(this.#u?.destroyPopup(),this.hasSelection)){for(let e of this.#L)e.unselect();this.#L.clear(),this.#ue({hasSelectedEditor:!1})}}translateSelectedEditors(e,t,n=!1){if(n||this.commitOrRemove(),!this.hasSelection)return;this.#W[0]+=e,this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G),this.#G=setTimeout(()=>{this.#G=null,this.#W[0]=this.#W[1]=0,this.addCommands({cmd:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(r,i),e.translationDone())},undo:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(-r,-i),e.translationDone())},mustExec:!1})},1e3);for(let n of a)n.translateInPage(e,t),n.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e)a.newX=n,a.newY=r,a.newPageIndex=i,t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex;if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);i?e._setParentAndPosition(i,t,n):(e.pageIndex=r,e.x=t,e.y=n)}};return this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0}),!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);t?(t.changeParent(e),t.addOrRebuild(e)):(this.addEditor(e),this.addToAnnotationStorage(e),e.rebuild())}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==S.NONE}get imageManager(){return I(this,`imageManager`,new ot)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n<r;n++)if(!e.contains(t.getRangeAt(n).commonAncestorContainer))return null;let{x:n,y:r,width:i,height:a}=e.getBoundingClientRect(),o;switch(e.getAttribute(`data-main-rotation`)){case`90`:o=(e,t,o,s)=>({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a});break}let s=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(!n.collapsed)for(let{x:e,y:t,width:r,height:i}of n.getClientRects())r===0||i===0||s.push(o(e,t,r,i))}return s.length===0?null:s}addChangedExistingAnnotation({annotationElementId:e,id:t}){(this.#c||=new Map).set(e,t)}removeChangedExistingAnnotation({annotationElementId:e}){this.#c?.delete(e)}renderAnnotationElement(e){let t=this.#c?.get(e.data.id);if(!t)return;let n=this.#s.getRawValue(t);n&&(this.#I===S.NONE&&!n.hasBeenModified||n.renderAnnotationElement(e))}setMissingCanvas(e,t,n){let r=this.#P?.get(e);r&&(r.setCanvas(t,n),this.#P.delete(e))}addMissingCanvas(e,t){(this.#P||=new Map).set(e,t)}},dt=class e{#e=null;#t=!1;#n=null;#r=null;#i=null;#a=null;#o=!1;#s=null;#c=null;#l=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(t){this.#c=t,this.#d=t._uiManager.useNewAltTextFlow,e.#f||=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){e._l10n??=t}async render(){let t=this.#n=document.createElement(`button`);t.className=`altText`,t.tabIndex=`0`;let n=this.#r=document.createElement(`span`);t.append(n),this.#d?(t.classList.add(`new`),t.setAttribute(`data-l10n-id`,e.#f.missing),n.setAttribute(`data-l10n-id`,e.#f[`missing-label`])):(t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button`),n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button-label`));let r=this.#c._uiManager._signal;t.addEventListener(`contextmenu`,H,{signal:r}),t.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:r});let i=e=>{e.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};return t.addEventListener(`click`,i,{capture:!0,signal:r}),t.addEventListener(`keydown`,e=>{e.target===t&&e.key===`Enter`&&(this.#o=!0,i(e))},{signal:r}),await this.#m(),t}get#p(){return this.#e&&`added`||this.#e===null&&this.guessedText&&`review`||`missing`}finish(){this.#n&&(this.#n.focus({focusVisible:this.#o}),this.#o=!1)}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(t){this.#e===null&&(this.#l=t,this.#u=await e._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:t}),this.#m())}toggleAltTextBadge(e=!1){if(!this.#d||this.#e){this.#s?.remove(),this.#s=null;return}if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`,this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}serialize(e){let t=this.#e;return!e&&this.#l===t&&(t=this.#u),{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){n&&(this.#l=n,this.#u=r),!(this.#e===e&&this.#t===t)&&(i||(this.#e=e,this.#t=t),this.#m())}toggle(e=!1){this.#n&&(!e&&this.#a&&(clearTimeout(this.#a),this.#a=null),this.#n.disabled=!e)}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove(),this.#n=null,this.#r=null,this.#i=null,this.#s?.remove(),this.#s=null}async#m(){let t=this.#n;if(!t)return;if(this.#d){if(t.classList.toggle(`done`,!!this.#e),t.setAttribute(`data-l10n-id`,e.#f[this.#p]),this.#r?.setAttribute(`data-l10n-id`,e.#f[`${this.#p}-label`]),!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){t.classList.remove(`done`),this.#i?.remove();return}t.classList.add(`done`),t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let n=this.#i;if(!n){this.#i=n=document.createElement(`span`),n.className=`tooltip`,n.setAttribute(`role`,`tooltip`),n.id=`alt-text-tooltip-${this.#c.id}`;let e=this.#c._uiManager._signal;e.addEventListener(`abort`,()=>{clearTimeout(this.#a),this.#a=null},{once:!0}),t.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null,this.#i.classList.add(`show`),this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:e}),t.addEventListener(`mouseleave`,()=>{this.#a&&=(clearTimeout(this.#a),null),this.#i?.classList.remove(`show`)},{signal:e})}this.#t?n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`):(n.removeAttribute(`data-l10n-id`),n.textContent=this.#e),n.parentNode||t.append(n),this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,n.id)}},ft=class{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);return e.className=`comment`,this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`,n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove(),this.#e=null}removeToolbarCommentButton(){this.#t?.remove(),this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){this.#e&&(this.#e.classList.toggle(`selected`,e),this.#e.ariaExpanded=t)}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`,e.ariaHasPopup=`dialog`,t?(e.ariaControls=`commentPopup`,e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)):(e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`));let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,H,{signal:n}),t&&(e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1,U(e)},{capture:!0,signal:n}),e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0,U(e)},{capture:!0,signal:n})),e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault(),e===this.#t?this.edit():this.#r.toggleComment(!0)};return e.addEventListener(`click`,r,{capture:!0,signal:n}),e.addEventListener(`keydown`,t=>{t.target===e&&t.key===`Enter`&&(this.#n=!0,r(t))},{signal:n}),e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n}),e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n}),e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e,r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){this.#t&&(this.#t.focus({focusVisible:this.#n}),this.#n=!1)}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){if(e!==this.#o&&(this.#a=null),e===null){this.#o=``,this.#c=!0;return}this.#o=e,this.#s=new Date,this.#c=!1}restoreData({text:e,richText:t,date:n}){this.#o=e,this.#a=t,this.#s=n,this.#c=!1}setInitialText(e,t=null){this.#i=e,this.data=e,this.#s=null,this.#a=t}shown(){}destroy(){this.#t?.remove(),this.#t=null,this.#e?.remove(),this.#e=null,this.#o=``,this.#a=null,this.#s=null,this.#r=null,this.#n=!1,this.#c=!1}},pt=class e{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e,this.#n=n,this.#r=t,this.#i=r,this.#a=i,this.#o=a,this.#u=new AbortController,this.#c=AbortSignal.any([o,this.#u.signal]),e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/He.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{e.pointerType===`touch`&&(this.#s?.abort(),this.#s=null)};n.addEventListener(`pointerdown`,e=>{e.pointerType===`touch`&&(U(e),i(e))},r),n.addEventListener(`pointerup`,i,r),n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n),t.addEventListener(`touchcancel`,r,n),n.capture=!0,t.addEventListener(`pointerdown`,U,n),t.addEventListener(`pointermove`,U,n),t.addEventListener(`pointercancel`,U,n),t.addEventListener(`pointerup`,U,n),this.#i?.()}if(U(e),e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]),this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(t){if(!this.#l||t.touches.length!==2)return;U(t);let[n,r]=t.touches;n.identifier>r.identifier&&([n,r]=[r,n]);let{screenX:i,screenY:a}=n,{screenX:o,screenY:s}=r,c=this.#l,{touch0X:l,touch0Y:u,touch1X:d,touch1Y:f}=c,p=d-l,m=f-u,h=o-i,g=s-a,_=Math.hypot(h,g)||1,v=Math.hypot(p,m)||1;if(!this.#t&&Math.abs(v-_)<=e.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(c.touch0X=i,c.touch0Y=a,c.touch1X=o,c.touch1Y=s,!this.#t){this.#t=!0;return}let y=[(i+o)/2,(a+s)/2];this.#a?.(y,v,_)}#m(e){e.touches.length>=2||(this.#d&&(this.#d.abort(),this.#d=null,this.#o?.()),this.#l&&(U(e),this.#l=null,this.#t=!1))}destroy(){this.#u?.abort(),this.#u=null,this.#s?.abort(),this.#s=null}},K=class e{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=e._zIndex++;static _borderLineWidth=-1;static _colorManager=new lt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=e.prototype._resizeWithKeyboard,n=ut.TRANSLATE_SMALL,r=ut.TRANSLATE_BIG;return I(this,`_resizerKeyboardManager`,new ct([[[`ArrowLeft`],t,{args:[-n,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t,{args:[-r,0]}],[[`ArrowRight`],t,{args:[n,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t,{args:[r,0]}],[[`ArrowUp`],t,{args:[0,-n]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t,{args:[0,-r]}],[[`ArrowDown`],t,{args:[0,n]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t,{args:[0,r]}],[[`Escape`],e.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent,this.id=e.id,this.width=this.height=null,this.pageIndex=e.parent.pageIndex,this.name=e.name,this.div=null,this._uiManager=e.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=e.isCentered,this._structTreeParentId=null,this.annotationElementId=e.annotationElementId||null,this.creationDate=e.creationDate||new Date,this.modificationDate=e.modificationDate||null,this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t,this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[n,r],this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o,this.y=e.y/s,this.isAttachedToDOM=!1,this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return I(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new mt({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId,t.deleted=!0,t._uiManager.addToAnnotationStorage(t)}static initialize(t,n){if(e._l10n??=t,e._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`}),e._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`}),e._borderLineWidth!==-1)return;let r=getComputedStyle(document.documentElement);e._borderLineWidth=parseFloat(r.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){P(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e,this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(e*2),this.y+=this.width*e/(t*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*t/(e*2),this.y-=this.width*e/(t*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){e===null?(this.#W(),this.#d?.remove(),this.#d=null):(this.pageIndex=e.pageIndex,this.pageDimensions=e.pageDimensions),this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){this._focusEventsAllowed&&this.isAttachedToDOM&&(e.relatedTarget?.closest(`#${this.id}`)||(e.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove()))}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r),this.x=(e+n)/i,this.y=(t+r)/a,this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r),this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r),this.x+=n/e,this.y+=r/t,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height],this.#E(this.pageDimensions,e,t),this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;if(this.x+=e/r,this.y+=t/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();this.parent.findNewParent(this,e,t)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s,o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`,l.top=`${(100*o).toFixed(2)}%`,this._onTranslating(a,o),n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[t,n]=this.parentDimensions,{_borderLineWidth:r}=e,i=r/t,a=r/n;switch(this.rotation){case 90:return[-i,a];case 180:return[i,a];case 270:return[i,-a];default:return[-i,-a]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;if(o*=n,s*=r,i*=n,a*=r,this._mustFixPosition)switch(e){case 0:i=B(i,0,n-o),a=B(a,0,r-s);break;case 90:i=B(i,0,n-s),a=B(a,o,r);break;case 180:i=B(i,o,n),a=B(a,s,r);break;case 270:i=B(i,s,n),a=B(a,0,r-o);break}this.x=i/=n,this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c,a+=l,t.left=`${(100*i).toFixed(2)}%`,t.top=`${(100*a).toFixed(2)}%`,this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(t,n){return e.#D(t,n,this.parentRotation)}pageTranslationToScreen(t,n){return e.#D(t,n,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`,e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`),this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e),e.classList.add(`resizer`,n),e.setAttribute(`data-resizer-name`,n),e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=L.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1,this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1),window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a}),window.addEventListener(`touchmove`,U,{passive:!1,signal:a}),window.addEventListener(`contextmenu`,H,{signal:a}),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort(),this.parent.togglePointerEvents(!0),this.#n?.toggle(!0),this._isDraggable=r,this.parent.div.style.cursor=o,this.div.style.cursor=s,this.#M()};window.addEventListener(`pointerup`,c,{signal:a}),window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n,this.height=r,this.x=e,this.y=t,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(e*1e4)/1e4}#N(t,n){let[r,i]=this.parentDimensions,a=this.x,o=this.y,s=this.width,c=this.height,l=e.MIN_SIZE/r,u=e.MIN_SIZE/i,d=this.#O(this.rotation),f=(e,t)=>[d[0]*e+d[2]*t,d[1]*e+d[3]*t],p=this.#O(360-this.rotation),m=(e,t)=>[p[0]*e+p[2]*t,p[1]*e+p[3]*t],h,g,_=!1,v=!1;switch(t){case`topLeft`:_=!0,h=(e,t)=>[0,0],g=(e,t)=>[e,t];break;case`topMiddle`:h=(e,t)=>[e/2,0],g=(e,t)=>[e/2,t];break;case`topRight`:_=!0,h=(e,t)=>[e,0],g=(e,t)=>[0,t];break;case`middleRight`:v=!0,h=(e,t)=>[e,t/2],g=(e,t)=>[0,t/2];break;case`bottomRight`:_=!0,h=(e,t)=>[e,t],g=(e,t)=>[0,0];break;case`bottomMiddle`:h=(e,t)=>[e/2,t],g=(e,t)=>[e/2,0];break;case`bottomLeft`:_=!0,h=(e,t)=>[0,t],g=(e,t)=>[e,0];break;case`middleLeft`:v=!0,h=(e,t)=>[0,t/2],g=(e,t)=>[e,t/2];break}let y=h(s,c),b=g(s,c),x=f(...b),S=e._round(a+x[0]),C=e._round(o+x[1]),w=1,T=1,E,D;if(n.fromKeyboard)({deltaX:E,deltaY:D}=n);else{let{screenX:e,screenY:t}=n,[r,i]=this.#l;[E,D]=this.screenToPageTranslation(e-r,t-i),this.#l[0]=e,this.#l[1]=t}if([E,D]=m(E/r,D/i),_){let e=Math.hypot(s,c);w=T=Math.max(Math.min(Math.hypot(b[0]-y[0]-E,b[1]-y[1]-D)/e,1/s,1/c),l/s,u/c)}else v?w=B(Math.abs(b[0]-y[0]-E),l,1)/s:T=B(Math.abs(b[1]-y[1]-D),u,1)/c;let O=e._round(s*w),k=e._round(c*T);x=f(...g(O,k));let A=S-x[0],j=C-x[1];this.#h||=[this.x,this.y,this.width,this.height],this.width=O,this.height=k,this.x=A,this.y=j,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new tt(this),this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);return this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton()),this._editToolbar.addButton(`delete`),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#n||(dt.initialize(e._l10n),this.#n=new dt(this),this.#e&&=(this.#n.data=this.#e,null)),this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new ft(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i){this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);return}this.hasComment&&(this.#i=this.#r.renderForStandalone(),this.div.append(this.#i))}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton(),this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new ft(this),typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:e,popupRef:t,richText:n}){if(!t||(this.#r||=new ft(this),this.#r.setInitialText(e,n),!this.annotationElementId))return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new ft(this),this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360),e.className=this.name,e.setAttribute(`id`,this.id),e.tabIndex=this.#a?-1:0,e.setAttribute(`role`,`application`),this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId),this._isVisible||e.classList.add(`hidden`),this.setInForeground(),this.#z();let[t,n]=this.parentDimensions;this.parentRotation%180!=0&&(e.style.maxWidth=`${(100*n/t).toFixed(2)}%`,e.style.maxHeight=`${(100*t/n).toFixed(2)}%`);let[r,i]=this.getInitialTranslation();return this.translate(r,i),it(this,e,[`keydown`,`pointerdown`,`dblclick`]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new pt({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#n?.toggle(!1),this.parent.togglePointerEvents(!1)}#F(t,n,r){let i=.7,a=r/n*i+1-i;if(a===1)return;let o=this.#O(this.rotation),s=(e,t)=>[o[0]*e+o[2]*t,o[1]*e+o[3]*t],[c,l]=this.parentDimensions,u=this.x,d=this.y,f=this.width,p=this.height,m=e.MIN_SIZE/c,h=e.MIN_SIZE/l;a=Math.max(Math.min(a,1/f,1/p),m/f,h/p);let g=e._round(f*a),_=e._round(p*a);if(g===f&&_===p)return;this.#h||=[u,d,f,p];let v=s(f/2,p/2),y=e._round(u+v[0]),b=e._round(d+v[1]),x=s(g/2,_/2);this.x=y-x[0],this.y=b-x[1],this.width=g,this.height=_,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#I(){this.#n?.toggle(!0),this.parent.togglePointerEvents(!0),this.#M()}pointerdown(e){let{isMac:t}=L.platform;if(e.button!==0||e.ctrlKey&&t){e.preventDefault();return}if(this.#m=!0,this._isDraggable){this.#R(e);return}this.#L(e)}#L(e){let{isMac:t}=L.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort(),this.#o=null,this.#m=!1,this._uiManager.endDragSession()||this.#L(e),n&&this._onStopDragging()};t&&(this.#b=e.clientX,this.#x=e.clientY,this.#o=e.pointerId,this.#s=e.pointerType,window.addEventListener(`pointermove`,e=>{n||(n=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){U(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t,this.#x=r,this._uiManager.dragSelectedEditors(a,o)},a),window.addEventListener(`touchmove`,U,a),window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e),U(e)},a));let s=e=>{if(!this.#o||this.#o===e.pointerId){o(e);return}U(e)};window.addEventListener(`pointerup`,s,{signal:i}),window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this),this.x=t,this.y=n,this.fixAndSetPosition(),this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&e._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){return this.isInEditMode()?!1:(this.parent.setEditingState(!1),this.#_=!0,!0)}disableEditMode(){return this.isInEditMode()?(this.parent.setEditingState(!0),this.#_=!1,!0):!1}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t<a&&r>0&&e<i&&n>0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e}),this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation,r.#e=e.accessibilityData,r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);return r.x=o/i,r.y=s/a,r.width=c/i,r.height=l/a,r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#f?.abort(),this.#f=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#y&&=(clearTimeout(this.#y),null),this.#W(),this.removeEditToolbar(),this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null,this.#C?.destroy(),this.#C=null,this.#d?.remove(),this.#d=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#k(),this.#c.classList.remove(`hidden`))}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[t,n]}=this,[r,i,a,o]=this.getPDFRect();return[e._round(r+(a-r)*t),e._round(i+(o-i)*(1-n))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!==`Enter`)return;this._uiManager.setSelected(this),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let n=this.#c.children;if(!this.#t){this.#t=Array.from(n);let t=this.#B.bind(this),r=this.#V.bind(this),i=this._uiManager._signal;for(let n of this.#t){let a=n.getAttribute(`data-resizer-name`);n.setAttribute(`role`,`spinbutton`),n.addEventListener(`keydown`,t,{signal:i}),n.addEventListener(`blur`,r,{signal:i}),n.addEventListener(`focus`,this.#H.bind(this,a),{signal:i}),n.setAttribute(`data-l10n-id`,e._l10nResizer[a])}}let r=this.#t[0],i=0;for(let e of n){if(e===r)break;i++}let a=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(a!==i){if(a<i)for(let e=0;e<i-a;e++)this.#c.append(this.#c.firstElementChild);else if(a>i)for(let e=0;e<a-i;e++)this.#c.firstElementChild.before(this.#c.lastElementChild);let t=0;for(let r of n){let n=this.#t[t++].getAttribute(`data-resizer-name`);r.setAttribute(`data-l10n-id`,e._l10nResizer[n])}}this.#U(0),this.#v=!0,this.#c.firstElementChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#B(t){e._resizerKeyboardManager.exec(this,t)}#V(e){this.#v&&e.relatedTarget?.parentNode!==this.#c&&this.#W()}#H(e){this.#p=this.#v?e:``}#U(e){if(this.#t)for(let t of this.#t)t.tabIndex=e}_resizeWithKeyboard(e,t){this.#v&&this.#N(this.#p,{deltaX:e,deltaY:t,fromKeyboard:!0})}#W(){this.#v=!1,this.#U(-1),this.#M()}_stopResizingWithKeyboard(){this.#W(),this.div.focus()}select(){if(this.isSelected&&this._editToolbar){this._editToolbar.show();return}if(this.isSelected=!0,this.makeResizable(),this.div?.classList.add(`selectedEditor`),!this._editToolbar){this.addEditToolbar().then(()=>{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()});return}this._editToolbar?.show(),this.#n?.toggleAltTextBadge(!1)}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#c?.classList.add(`hidden`),this.div?.classList.remove(`selectedEditor`),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#n?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(e){e.target.nodeName!==`BUTTON`&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e,this.parent&&(e?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(t,n=!1){if(n){this.#S||=new Map;let{action:n}=t,r=this.#S.get(n);r&&clearTimeout(r),r=setTimeout(()=>{this._reportTelemetry(t),this.#S.delete(n),this.#S.size===0&&(this.#S=null)},e._telemetryTimeout),this.#S.set(n,r);return}t.type||=this.editorType,this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:t}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e),this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0),this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#a=!0}updateFakeAnnotationElement(e){if(!this.#d&&!this.deleted){this.#d=e.addFakeAnnotation(this);return}if(this.deleted){this.#d.remove(),this.#d=null;return}(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let t=e.container.querySelector(`.annotationContent`);if(!t)t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.container.prepend(t);else if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.before(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}},mt=class extends K{constructor(e){super(e),this.annotationElementId=e.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},ht=3285377520,gt=4294901760,_t=65535,vt=class{constructor(e){this.h1=e?e&4294967295:ht,this.h2=e?e&4294967295:ht}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(e.length*2),n=0;for(let r=0,i=e.length;r<i;r++){let i=e.charCodeAt(r);i<=255?t[n++]=i:(t[n++]=i>>>8,t[n++]=i&255)}}else if(ArrayBuffer.isView(e))t=e.slice(),n=t.byteLength;else throw Error(`Invalid data format, must be a string or TypedArray.`);let r=n>>2,i=n-r*4,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e<r;e++)e&1?(o=a[e],o=o*u&gt|o*f&_t,o=o<<15|o>>>17,o=o*d&gt|o*p&_t,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(s=a[e],s=s*u&gt|s*f&_t,s=s<<15|s>>>17,s=s*d&gt|s*p&_t,l^=s,l=l<<13|l>>>19,l=l*5+3864292196);switch(o=0,i){case 3:o^=t[r*4+2]<<16;case 2:o^=t[r*4+1]<<8;case 1:o^=t[r*4],o=o*u&gt|o*f&_t,o=o<<15|o>>>17,o=o*d&gt|o*p&_t,r&1?c^=o:l^=o}this.h1=c,this.h2=l}hexdigest(){let e=this.h1,t=this.h2;return e^=t>>>1,e=e*3981806797&gt|e*36045&_t,t=t*4283543511&gt|((t<<16|e>>>16)*2950163797&gt)>>>16,e^=t>>>1,e=e*444984403&gt|e*60499&_t,t=t*3301882366&gt|((t<<16|e>>>16)*3120437893&gt)>>>16,e^=t>>>1,(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}},yt=Object.freeze({map:null,hash:``,transfer:void 0}),bt=class{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);t!==void 0&&(t instanceof K&&this.#n.delete(t.annotationElementId),this.#r.delete(e),this.#r.size===0&&this.resetModified(),!this.#r.values().some(e=>e instanceof K)&&this.onAnnotationEditor?.(null))}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0)for(let[e,i]of Object.entries(t))n[e]!==i&&(r=!0,n[e]=i);else r=!0,this.#r.set(e,t);r&&this.#i(),t instanceof K&&((this.#n||=new Map).set(t.annotationElementId,t),this.onAnnotationEditor?.(t.constructor._type))}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){this.#e||(this.#e=!0,this.onSetModified?.())}resetModified(){this.#e&&(this.#e=!1,this.onResetModified?.())}get print(){return new xt(this)}get serializable(){if(this.#r.size===0)return yt;let e=new Map,t=new vt,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof K?a.serialize(!1,r):a;a.page&&(a.pageIndex=a.page._pageIndex,delete a.page),o&&(e.set(n,o),t.update(`${n}:${JSON.stringify(o)}`),i||=!!o.bitmap)}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:yt}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof K)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.getOrInsertComputed(o,()=>Object.getPrototypeOf(i).constructor),e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,Ce);n.set(t,(n.get(t)??0)+1)}}if((r>0||n>0)&&(e||=Object.create(null),e.comments={deleted:r,edited:n}),!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);return n?(n.updateFromAnnotationLayer(t),!0):!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new vt;n.update(e.join(`,`)),t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}},xt=class extends bt{#e=yt;constructor(e){super();let{serializable:t}=e;if(t===yt)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){P(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return I(this,`modifiedIds`,{ids:new Set,hash:``})}},St=`__forcedDependency`,{floor:Ct,ceil:wt}=Math;function Tt(e,t,n,r,i,a){e[t*4+0]=Math.min(e[t*4+0],n),e[t*4+1]=Math.min(e[t*4+1],r),e[t*4+2]=Math.max(e[t*4+2],i),e[t*4+3]=Math.max(e[t*4+3],a)}function Et(e,t,n,r,i){let a;e?(e<0&&(a=i[0],i[0]=i[2],i[2]=a),i[0]*=e,i[2]*=e,t<0&&(a=i[1],i[1]=i[3],i[3]=a),i[1]*=t,i[3]*=t):i.fill(0),i[0]+=n,i[1]+=r,i[2]+=n,i[3]+=r}var Dt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0],Ot=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===Dt}minX(e){return this.#t[e*4+0]/256}minY(e){return this.#t[e*4+1]/256}maxX(e){return(this.#t[e*4+2]+1)/256}maxY(e){return(this.#t[e*4+3]+1)/256}},kt=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1})),At=class{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(p);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width,this.#i=e.height,this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(e*4);this.#a=new Uint8ClampedArray(n),this.#o=new Uint32Array(n),t&&t.length>0?(this.#o.set(t),this.#o.fill(Dt,t.length)):this.#o.fill(Dt)}get clipBox(){return this.#t}save(e){return this.#t={__proto__:this.#t},this._savesStack.push(e),this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();return r!==void 0&&(t?.(r,e),this.#o[e]=this.#o[r]),this}recordOpenMarker(e){return this._savesStack.push(e),this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}beginMarkedContent(e){return this._markedContentStack.push(e),this}endMarkedContent(e,t){let n=this._markedContentStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}pushBaseTransform(e){return this.#e.push(R.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform())),this}popBaseTransform(){return this.#e.length>1&&this.#e.pop(),this}resetBBox(e){return this._pendingBBoxIdx!==e&&(this._pendingBBoxIdx=e,this.#n.set(p,0)),this}recordClipBox(e,t,n,r,i,a){let o=R.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=p.slice();R.axialAlignedBoundingBox([n,i,r,a],o,s);let c=R.intersect(this.#t,s);return c?(this.#t[0]=c[0],this.#t[1]=c[1],this.#t[2]=c[2],this.#t[3]=c[3]):(this.#t[0]=this.#t[1]=1/0,this.#t[2]=this.#t[3]=-1/0),this}recordBBox(e,t,n,r,i,a){let o=this.#t;if(o[0]===1/0)return this;let s=R.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(o[0]===-1/0)return R.axialAlignedBoundingBox([n,i,r,a],s,this.#n),this;let c=p.slice();return R.axialAlignedBoundingBox([n,i,r,a],s,c),this.#n[0]=B(c[0],o[0],this.#n[0]),this.#n[1]=B(c[1],o[1],this.#n[1]),this.#n[2]=B(c[2],this.#n[2],o[2]),this.#n[3]=B(c[3],this.#n[3],o[3]),this}recordFullPageBBox(e){return this.#n[0]=Math.max(0,this.#t[0]),this.#n[1]=Math.max(0,this.#t[1]),this.#n[2]=Math.min(this.#r,this.#t[2]),this.#n[3]=Math.min(this.#i,this.#t[3]),this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=Ct(this.#n[0]*256/this.#r),i=Ct(this.#n[1]*256/this.#i),a=wt(this.#n[2]*256/this.#r),o=wt(this.#n[3]*256/this.#i);if(Tt(this.#a,e,r,i,a,o),n)for(let t of n)for(let n of t)n!==e&&Tt(this.#a,n,r,i,a,o);return t||(this._pendingBBoxIdx=-1),this}bboxToClipBoxDropOperation(e){return this._pendingBBoxIdx===e&&(this._pendingBBoxIdx=-1,this.#t[0]=Math.max(this.#t[0],this.#n[0]),this.#t[1]=Math.max(this.#t[1],this.#n[1]),this.#t[2]=Math.min(this.#t[2],this.#n[2]),this.#t[3]=Math.min(this.#t[3],this.#n[3])),this}take(){return new Ot(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}},jt=class{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[St]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e,t&&(this.#a=new Map,this.#o=(e,t)=>{kt(this.#a,t).dependencies.add(e)})}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){return this.#e={__proto__:this.#e},this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[St]:{__proto__:this.#t[St]}},this.#s.save(e),this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);return t===null?this:(this.#e=t,this.#t=Object.getPrototypeOf(this.#t),this)}recordOpenMarker(e){return this.#s.recordOpenMarker(e,this.#o),this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){return this.#s.recordCloseMarker(e,this.#o),this}beginMarkedContent(e){return this.#s.beginMarkedContent(e),this}endMarkedContent(e){return this.#s.endMarkedContent(e,this.#o),this}pushBaseTransform(e){return this.#s.pushBaseTransform(e),this}popBaseTransform(){return this.#s.popBaseTransform(),this}recordSimpleData(e,t){return this.#e[e]=t,this}recordIncrementalData(e,t){return this.#t[e].push(t),this}resetIncrementalData(e,t){return this.#t[e].length=0,this}recordNamedData(e,t){return this.#n.set(e,t),this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){return this.recordIncrementalData(St,t),this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(St,e);return this}resetBBox(e){return this.#s.resetBBox(e),this}recordClipBox(e,t,n,r,i,a){return this.#s.recordClipBox(e,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#s.recordBBox(e,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s&&(c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n),c!==!1&&(l=[0,0,0,0],R.axialAlignedBoundingBox(s,n.fontMatrix,l),(r!==1||i!==0||a!==0)&&Et(r,-r,i,a,l),c)))return this.recordBBox(e,t,l[0],l[2],l[1],l[3]);if(!o)return this.recordFullPageBBox(e);let u=o();return s&&l&&c===void 0&&(c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent,this.#i.set(n,c),c)?this.recordBBox(e,t,l[0],l[2],l[1],l[3]):this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){return this.#s.recordFullPageBBox(e),this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){return this.#n.has(t)&&this.#r.add(this.#n.get(t)),this}recordOperation(e,t=!1){if(this.recordDependencies(e,[St]),this.#a){let t=kt(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n),this.#s._savesStack.forEach(n.add,n),this.#s._markedContentStack.forEach(n.add,n),n.delete(e),t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]),n&&this.#r.clear(),this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t),this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.bboxToClipBoxDropOperation(e),n&&this.#r.clear(),this}take(){return this.#i.clear(),this.#s.take()}takeDebugMetadata(){return this.#a}},Mt=class e{#e;#t;#n;#r=0;#i=0;constructor(t,n,r){if(t instanceof e&&t.#n===!!r)return t;this.#e=t,this.#t=n,this.#n=!!r}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){return this.#i++,this.#e.save(this.#t),this}restore(e){return this.#i>0&&(this.#e.restore(this.#t),this.#i--),this}recordOpenMarker(e){return this.#r++,this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){return this.#r--,this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){return this.#e.pushBaseTransform(e),this}popBaseTransform(){return this.#e.popBaseTransform(),this}recordSimpleData(e,t){return this.#e.recordSimpleData(e,this.#t),this}recordIncrementalData(e,t){return this.#e.recordIncrementalData(e,this.#t),this}resetIncrementalData(e,t){return this.#e.resetIncrementalData(e,this.#t),this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this.#e.recordSimpleDataFromNamed(e,t,this.#t),this}recordFutureForcedDependency(e,t){return this.#e.recordFutureForcedDependency(e,this.#t),this}inheritSimpleDataAsFutureForcedDependencies(e){return this.#e.inheritSimpleDataAsFutureForcedDependencies(e),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#e.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(e){return this.#n||this.#e.resetBBox(this.#t),this}recordClipBox(e,t,n,r,i,a){return this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r,i,a,o){return this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o),this}recordFullPageBBox(e){return this.#n||this.#e.recordFullPageBBox(this.#t),this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){return this.#e.recordDependencies(this.#t,t),this}recordNamedDependency(e,t){return this.#e.recordNamedDependency(this.#t,t),this}recordOperation(e){return this.#e.recordOperation(this.#t,!0),this}recordShowTextOperation(e){return this.#e.recordShowTextOperation(this.#t,!0),this}bboxToClipBoxDropOperation(e){return this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0),this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}},Nt={stroke:[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],fill:[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],imageXObject:[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],rawFillPath:[`filter`,`fillColor`,`fillAlpha`],showText:[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],transform:[`transform`],transformAndFill:[`transform`,`fillColor`]},Pt=class e{#e;#t;#n=4;#r=0;#i=new e.#a(this.#n*6);static#a=L.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width,this.#t=e.height}record(t,n,r,i){if(this.#r===this.#n){this.#n*=2;let t=new e.#a(this.#n*6);t.set(this.#i),this.#i=t}let a=W(t),o;if(i[0]!==1/0){let e=p.slice();R.axialAlignedBoundingBox([0,-r,n,0],a,e);let t=R.intersect(i,e);if(!t)return;let[s,c,l,u]=t;if(s!==e[0]||c!==e[1]||l!==e[2]||u!==e[3]){let e=Math.atan2(a[1],a[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)o=[s,c,s,u,l,c];else{let e=l-s,r=u-c,i=t*t,a=n*n,d=n*t,f=a-i,p=(r*a-e*d)/f;o=[s+(r*d-e*i)/f,c,s,c+p,l,u-p]}}}o||(o=[0,-r,0,0,n,-r],R.applyTransform(o,a,0),R.applyTransform(o,a,2),R.applyTransform(o,a,4)),o[0]/=this.#e,o[1]/=this.#t,o[2]/=this.#e,o[3]/=this.#t,o[4]/=this.#e,o[5]/=this.#t,this.#i.set(o,this.#r*6),this.#r++}take(){return this.#i.subarray(0,this.#r*6)}},Ft=class{#e=new Set;#t=null;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e),this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e),this._document.fonts.delete(e)}insertRule(e){let t=this.#n();t.insertRule(e,t.cssRules.length)}#n(){if(this.#t)return this.#t;let e=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&e){let{adoptedStyleSheets:t}=this._document;if(t){let n=new e;return t.push(n),this.#t=n}}return this.styleElement||(this.styleElement=this._document.createElement(`style`),this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)),this.#t=this.styleElement.sheet}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);if(this.nativeFontFaces.clear(),this.#e.clear(),this.#t){let{adoptedStyleSheets:e}=this._document;e?.includes(this.#t)&&(this._document.adoptedStyleSheets=e.filter(e=>e!==this.#t)),this.#t=null}this.styleElement&&=(this.styleElement.remove(),null)}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(!(!e||this.#e.has(e.loadedName))){if(F(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load(),this.#e.add(t),n?.(e)}catch{N(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(a)}return}P(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;if(e.attached=!0,e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){throw N(`Failed to load font '${t.family}': '${n}'.`),e.disableFontFace=!0,n}}return}let t=e.createFontFaceRule();if(t){if(this.insertRule(t),this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){let e=!!this._document?.fonts;return I(this,`isFontLoadingAPISupported`,e)}get isSyncFontLoadingSupported(){return I(this,`isSyncFontLoadingSupported`,f||L.platform.isFirefox)}_queueLoadingCallback(e){function t(){for(F(!r.done,`completeRequest() cannot be called twice.`),r.done=!0;n.length>0&&n[0].done;){let e=n.shift();setTimeout(e.callback,0)}}let{loadingRequests:n}=this,r={done:!1,complete:t,callback:e};return n.push(r),r}get _loadTestFont(){let e=atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`);return I(this,`_loadTestFont`,e)}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|e.charCodeAt(t+3)&255}function r(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,e&255)}function i(e,t,n,r){let i=e.substring(0,t),a=e.substring(t+n);return i+r+a}let a,o,s=this._document.createElement(`canvas`);s.width=1,s.height=1;let c=s.getContext(`2d`),l=0;function u(e,t){if(++l>30){N(`Load test font never loaded.`),t();return}if(c.font=`30px `+e,c.fillText(`.`,0,20),c.getImageData(0,0,1,1).data[3]>0){t();return}setTimeout(u.bind(null,e,t))}let d=`lt${Date.now()}${this.loadTestFontId++}`,f=this._loadTestFont;f=i(f,976,d.length,d);let p=1482184792,m=n(f,16);for(a=0,o=d.length-3;a<o;a+=4)m=m-p+n(d,a)|0;a<d.length&&(m=m-p+n(d+`XXX`,a)|0),f=i(f,16,4,r(m));let h=`@font-face {font-family:"${d}";src:${`url(data:font/opentype;base64,${btoa(f)});`}}`;this.insertRule(h);let g=this._document.createElement(`div`);g.style.visibility=`hidden`,g.style.width=g.style.height=`10px`,g.style.position=`absolute`,g.style.top=g.style.left=`0px`;for(let t of[e.loadedName,d]){let e=this._document.createElement(`span`);e.textContent=`Hi`,e.style.fontFamily=t,g.append(e)}this._document.body.append(g),u(d,()=>{g.remove(),t.complete()})}},It=class{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e,this._inspectFont=t,n&&(this.charProcOperatorList=n),r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(!this.cssFontInfo)e=new FontFace(this.loadedName,this.data,{});else{let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`),e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}return this._inspectFont?.(this),e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(!this.cssFontInfo)t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;else{let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}return this._inspectFont?.(this,e),t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){N(`getPathGenerator - ignoring character: "${e}".`)}let i=et(r?.path);return this.fontExtraProperties||e.delete(n),this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){I(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}},Lt=class{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]},Rt=class{static strings=[`css`,`loadedName`,`baseFontName`,`src`]},zt=class{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(this.bools.length*2/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+this.numbers.length*8;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6},Bt=class{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16},Vt=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}#r(e){F(e<Lt.strings.length,`Invalid string index`);let t=0;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fontFamily(){return this.#r(0)}get fontWeight(){return this.#r(1)}get italicAngle(){return this.#r(2)}},Ht=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}get guessFallback(){return this.#n.getUint8(0)!==0}#r(e){F(e<Rt.strings.length,`Invalid string index`);let t=5;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get css(){return this.#r(0)}get loadedName(){return this.#r(1)}get baseFontName(){return this.#r(2)}get src(){return this.#r(3)}get style(){let e=1;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e),n=this.#t.decode(new Uint8Array(this.#e,e+4,t));e+=4+t;let r=this.#n.getUint32(e);return{style:n,weight:this.#t.decode(new Uint8Array(this.#e,e+4,r))}}},Ut=class{#e;#t=new TextDecoder;#n;constructor({buffer:e,extra:t}){this.#e=e,this.#n=new DataView(e),t&&Object.assign(this,t)}#r(e){F(e<zt.bools.length,`Invalid boolean index`);let t=Math.floor(e/4),n=e*2%8,r=this.#n.getUint8(t)>>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){return F(e<zt.numbers.length,`Invalid number index`),this.#n.getFloat64(zt.OFFSET_NUMBERS+e*8)}get ascent(){return this.#i(0)}get defaultWidth(){return this.#i(1)}get descent(){return this.#i(2)}#a(e,t,n,r){let i=this.#n.getUint8(e);if(i===0)return;F(i===t,`Invalid array length.`),e+=1;let a=Array(i);for(let t=0;t<i;t++)a[t]=this.#n[n](e,!0),e+=r;return a}get bbox(){return this.#a(zt.OFFSET_BBOX,4,`getInt16`,2)}get fontMatrix(){return this.#a(zt.OFFSET_FONT_MATRIX,6,`getFloat64`,8)}get defaultVMetrics(){return this.#a(zt.OFFSET_DEFAULT_VMETRICS,3,`getInt16`,2)}#o(e){F(e<zt.strings.length,`Invalid string index`);let t=zt.OFFSET_STRINGS+4;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fallbackName(){return this.#o(0)}get loadedName(){return this.#o(1)}get mimetype(){return this.#o(2)}get name(){return this.#o(3)}#s(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);e+=4+n;let r=this.#n.getUint32(e);e+=4+r;let i=this.#n.getUint32(e);return{offset:e,length:i}}get data(){let{offset:e,length:t}=this.#s();return t===0?void 0:new Uint8Array(this.#e,e+4,t)}clearData(){let{offset:e,length:t}=this.#s();t!==0&&(this.#n.setUint32(e,0),this.#e=new Uint8Array(this.#e,0,e+4).slice().buffer,this.#n=new DataView(this.#e))}get cssFontInfo(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);e+=4+n;let r=this.#n.getUint32(e);if(r===0)return null;let i=new Uint8Array(r);return i.set(new Uint8Array(this.#e,e+4,r)),new Vt(i.buffer)}get systemFontInfo(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);if(n===0)return null;let r=new Uint8Array(n);return r.set(new Uint8Array(this.#e,e+4,n)),new Ht(r.buffer)}},Wt=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[Bt.KIND],n=!!this.data[Bt.HAS_BBOX],r=!!this.data[Bt.HAS_BACKGROUND],i=e.getUint32(Bt.N_COORD,!0),a=e.getUint32(Bt.N_COLOR,!0),o=e.getUint32(Bt.N_STOP,!0),s=20,c=new Float32Array(this.buffer,s,i*2);s+=i*8;let l=new Uint8Array(this.buffer,s,a*4);s+=a*4;let u=[];for(let t=0;t<o;++t){let t=e.getFloat32(s,!0);s+=4;let n=e.getUint32(s,!0);s+=4,u.push([t,`#${n.toString(16).padStart(6,`0`)}`])}let d=null;if(n){d=[];for(let t=0;t<4;++t)d.push(e.getFloat32(s,!0)),s+=4}let f=null;if(r&&(f=new Uint8Array(this.buffer,s,3),s+=3),t===1)return[`RadialAxial`,`axial`,d,u,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,d,u,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[Bt.SHADING_TYPE],t=null;if(c.length>0){t=p.slice();for(let e=0,n=c.length;e<n;e+=2)R.pointBoundingBox(c[e],c[e+1],t)}return[`Mesh`,e,c,l,i,t,d,f]}throw Error(`Unsupported pattern kind: ${t}`)}},Gt=class{#e;constructor(e){this.#e=e}get path(){return L.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}};function Kt(e){if(e instanceof URL)return e;if(typeof e==`string`){if(f){if(/^[a-z][a-z0-9\-+.]+:/i.test(e))return new URL(e);let t=process.getBuiltinModule(`url`);return new URL(t.pathToFileURL(e))}let t=URL.parse(e,window.location);if(t)return t}throw Error(`Invalid PDF url data: either string or URL-object is expected in the url property.`)}function qt(e){if(f&&typeof Buffer<`u`&&e instanceof Buffer)throw Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength)return e;if(typeof e==`string`)return ge(e);if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof e==`object`&&!isNaN(e?.length))return new Uint8Array(e);throw Error(`Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.`)}function Jt(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}var Yt=e=>typeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0,Xt=xe.bind(null,Yt,e=>typeof e==`object`&&typeof e?.name==`string`),Zt=class{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){N("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a),i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.(),this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}},Qt={DATA:1,ERROR:2},q={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function $t(){}function J(e){if(e instanceof me||e instanceof de||e instanceof le||e instanceof fe||e instanceof ue)return e;switch(e instanceof Error||typeof e==`object`&&e||P(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`),e.name){case`AbortException`:return new me(e.message);case`InvalidPDFException`:return new de(e.message);case`PasswordException`:return new le(e.message,e.code);case`ResponseException`:return new fe(e.message,e.status,e.missing);case`UnknownErrorException`:return new ue(e.message,e.details)}return new ue(e.message,e.toString())}var en=class{#e=new AbortController;constructor(e,t,n){this.sourceName=e,this.targetName=t,this.comObj=n,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);if(delete this.callbackCapabilities[t],e.callback===Qt.DATA)n.resolve(e.data);else if(e.callback===Qt.ERROR)n.reject(J(e.reason));else throw Error(`Unexpected callback case`);return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:Qt.DATA,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:Qt.ERROR,callbackId:e.callbackId,reason:J(t)})});return}if(e.streamId){this.#n(e);return}t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();return this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1},s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r),c.promise},pull:e=>{let t=Promise.withResolvers();return this.streamControllers[i].pullCall=t,s.postMessage({sourceName:a,targetName:o,stream:q.PULL,streamId:i,desiredSize:e.desiredSize}),t.promise},cancel:e=>{F(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();return this.streamControllers[i].cancelCall=t,this.streamControllers[i].isClosed=!0,s.postMessage({sourceName:a,targetName:o,stream:q.CANCEL,streamId:i,reason:J(e)}),t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a,s>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),i.postMessage({sourceName:n,targetName:r,stream:q.ENQUEUE,streamId:t,chunk:e},o)},close(){this.isCancelled||(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.CLOSE,streamId:t}),delete a.streamSinks[t])},error(e){F(e instanceof Error,`error must have a valid reason`),!this.isCancelled&&(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.ERROR,streamId:t,reason:J(e)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve(),s.ready=s.sinkCapability.promise,this.streamSinks[t]=s,Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,reason:J(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case q.START_COMPLETE:e.success?a.startCall.resolve():a.startCall.reject(J(e.reason));break;case q.PULL_COMPLETE:e.success?a.pullCall.resolve():a.pullCall.reject(J(e.reason));break;case q.PULL:if(!o){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=e.desiredSize,Promise.try(o.onPull||$t).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,reason:J(e)})});break;case q.ENQUEUE:if(F(a,`enqueue should have stream controller`),a.isClosed)break;a.controller.enqueue(e.chunk);break;case q.CLOSE:if(F(a,`close should have stream controller`),a.isClosed)break;a.isClosed=!0,a.controller.close(),this.#i(a,t);break;case q.ERROR:F(a,`error should have stream controller`),a.controller.error(J(e.reason)),this.#i(a,t);break;case q.CANCEL_COMPLETE:e.success?a.cancelCall.resolve():a.cancelCall.reject(J(e.reason)),this.#i(a,t);break;case q.CANCEL:if(!o)break;let s=J(e.reason);Promise.try(o.onCancel||$t,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,reason:J(e)})}),o.sinkCapability.reject(s),o.isCancelled=!0,delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]),delete this.streamControllers[t]}destroy(){this.#e?.abort(),this.#e=null}},tn=class{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e,this.standardFontDataUrl=t,this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:P(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){P("Abstract method `_fetch` called.")}},nn=class extends tn{async _fetch(e,t){let n=await ke(e,t===`cMapUrl`&&!e.endsWith(`.bcmap`)?`text`:`bytes`);return n instanceof Uint8Array?n:ge(n)}},rn=class{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t,e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0,e.canvas=null,e.context=null}_createCanvas(e,t){P("Abstract method `_createCanvas` called.")}},an=class extends rn{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t}),this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);return n.width=e,n.height=t,n}},on=class{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}addSelectionHCMFilter(e,t){return`none`}addSelectionFilter(){return`none`}createSelectionStyle(e=null){return null}destroy(e=!1){}},sn=class extends on{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super(),this.#r=e,this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.colorScheme=`only light`,t.visibility=`hidden`,t.contain=`strict`,t.width=t.height=0,t.position=`absolute`,t.top=t.left=0,t.zIndex=-1;let n=this.#i.createElementNS(_,`svg`);n.setAttribute(`width`,0),n.setAttribute(`height`,0),this.#n=this.#i.createElementNS(_,`defs`),e.append(n),n.append(this.#n),this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++)i[e]=t[e]/255,a[e]=n[e]/255,o[e]=r[e]/255;return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(je(e)?N(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=oe(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;if(t=this.#s.get(a),t)return this.#s.set(e,t),t;let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s),this.#s.set(a,s);let c=this.#m(o);return this.#g(n,r,i,c),s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n||(i?(i.filter?.remove(),i.key=n,i.url=`none`,i.filter=null):(i={key:n,url:`none`,filter:null},this.#c.set(r,i)),!e||!t))return i.url;let a=this.#v(e);e=R.makeHexColor(...a);let o=this.#v(t);if(t=R.makeHexColor(...o),this.#l.style.color=``,e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u),this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};return this.#g(d(0,5),d(1,5),d(2,5),u),i.url=this.#d(l),i.url}addSelectionHCMFilter(e,t){return this.addHighlightHCMFilter(`selection`,e,t,`HighlightText`,`Highlight`)}addSelectionFilter(){return this.addHighlightHCMFilter(`selection_default`,`black`,`white`,`HighlightText`,`Highlight`)}createSelectionStyle(e=null){let t=e?this.addSelectionHCMFilter(e.foreground,e.background):this.addSelectionFilter();return t===`none`||!L.platform.isFirefox?null:{"backdrop-filter":t,"background-color":`transparent`}}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;if(t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#_(n,o),a}addLuminosityFilter(e){let t=this.#s.get(e||`luminosity`);if(t)return t;let n,r;if(e?([n]=this.#u([e]),r=`luminosity_${n}`):r=`luminosity`,t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#f(o),e&&this.#_(n,o),a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(_,`feComponentTransfer`);o.append(s);let c=this.#i.createElementNS(_,`feFuncA`);return c.setAttribute(`type`,`linear`),c.setAttribute(`slope`,`${t}`),c.setAttribute(`intercept`,`0`),s.append(c),a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a||(o?(o.filter?.remove(),o.key=a,o.url=`none`,o.filter=null):(o={key:a,url:`none`,filter:null},this.#c.set(e,o)),!t||!n))return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#b.bind(this));u<l&&([l,u,d,f]=[u,l,f,d]),this.#l.style.color=``;let p=(e,t,n)=>{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);return this.#p(h),this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h),o.url=this.#d(m),o.url}destroy(e=!1){e&&this.#a?.size||(this.#n?.parentNode.parentNode.remove(),this.#n=null,this.#t?.clear(),this.#t=null,this.#a?.clear(),this.#a=null,this.#o=0)}#f(e){let t=this.#i.createElementNS(_,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`),e.append(t)}#p(e){let t=this.#i.createElementNS(_,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`),e.append(t)}#m(e){let t=this.#i.createElementNS(_,`filter`);return t.setAttribute(`color-interpolation-filters`,`sRGB`),t.setAttribute(`id`,e),this.#l.append(t),t}#h(e,t,n){let r=this.#i.createElementNS(_,t);r.setAttribute(`type`,`discrete`),r.setAttribute(`tableValues`,n),e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(_,`feComponentTransfer`);r.append(i),this.#h(i,`feFuncR`,e),this.#h(i,`feFuncG`,t),this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(_,`feComponentTransfer`);t.append(n),this.#h(n,`feFuncA`,e)}#v(e){return this.#l.style.color=e,Re(getComputedStyle(this.#l).getPropertyValue(`color`))}#y(e){return this.#l.style.color=e,Le(getComputedStyle(this.#l).getPropertyValue(`color`))}#b(e){let[t,n,r,i]=this.#y(e);if(i===1)return[t,n,r];let[a,o,s]=this.#v(`Canvas`);return[cn(t,a,i),cn(n,o,i),cn(r,s,i)]}};function cn(e,t,n){return Math.round(n*e+(1-n)*t)}f&&N("Please use the `legacy` build in Node.js environments.");async function ln(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}var un=class extends on{},dn=class extends rn{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire({}.url)(`@napi-rs/canvas`).createCanvas(e,t)}},fn=class extends tn{async _fetch(e,t){return ln(e)}};function pn({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=L.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=r&7,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r<i;++r){for(let r=t+u;t<r;++t,m+=8){let r=e[t];n[m]=c^-(r>>7&1)&f,n[m+1]=c^-(r>>6&1)&f,n[m+2]=c^-(r>>5&1)&f,n[m+3]=c^-(r>>4&1)&f,n[m+4]=c^-(r>>3&1)&f,n[m+5]=c^-(r>>2&1)&f,n[m+6]=c^-(r>>1&1)&f,n[m+7]=c^-(r&1)&f}if(d===0)continue;let r=t<p?e[t++]:255;for(let e=0;e<d;++e,++m)n[m]=c^-(r>>7-e&1)&f}return{srcPos:t,destPos:m}}function mn({src:e,srcPos:t=0,dest:n,destPos:r=0,width:i,height:a}){let o=0,s=i*a*3,c=s>>2,l=new Uint32Array(e.buffer,t,c),u=L.isLittleEndian?4278190080:255;if(L.isLittleEndian){for(;o<c-2;o+=3,r+=4){let e=l[o],t=l[o+1],i=l[o+2];n[r]=e|u,n[r+1]=e>>>24|t<<8|u,n[r+2]=t>>>16|i<<16|u,n[r+3]=i>>>8|u}for(let i=o*4,a=t+s;i<a;i+=3)n[r++]=e[i]|e[i+1]<<8|e[i+2]<<16|u}else{for(;o<c-2;o+=3,r+=4){let e=l[o],t=l[o+1],i=l[o+2];n[r]=e|u,n[r+1]=e<<24|t>>>8|u,n[r+2]=t<<16|i>>>16|u,n[r+3]=i<<8|u}for(let i=o*4,a=t+s;i<a;i+=3)n[r++]=e[i]<<24|e[i+1]<<16|e[i+2]<<8|u}return{srcPos:t+s,destPos:r}}var hn=`
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require("react");l=c(l,1);let u=require("react/jsx-runtime");var d=o({AbortException:()=>pe,AnnotationEditorLayer:()=>aa,AnnotationEditorParamsType:()=>C,AnnotationEditorType:()=>S,AnnotationEditorUIManager:()=>ut,AnnotationLayer:()=>Fi,AnnotationMode:()=>y,AnnotationType:()=>D,CSSConstants:()=>Ge,ColorPicker:()=>Zr,DOMSVGFactory:()=>ri,DrawLayer:()=>ua,FeatureTest:()=>R,GlobalWorkerOptions:()=>Dr,ImageKind:()=>E,InvalidPDFException:()=>ue,MathClamp:()=>V,OPS:()=>A,OutputScale:()=>He,PDFDataRangeTransport:()=>Hr,PDFDateString:()=>Ie,PDFWorker:()=>Gr,PasswordException:()=>ce,PasswordResponses:()=>ee,PermissionFlag:()=>w,PixelsPerInch:()=>De,RenderingCancelledException:()=>ke,ResponseException:()=>de,SignatureExtractor:()=>ea,SupportedImageMimeTypes:()=>Ue,TextLayer:()=>Rr,TextLayerImages:()=>fa,TouchManager:()=>pt,Util:()=>z,VerbosityLevel:()=>k,XfaLayer:()=>Ee,applyOpacity:()=>Ke,build:()=>Xr,createValidAbsoluteUrl:()=>ie,fetchData:()=>Oe,findContrastColor:()=>Qe,getDocument:()=>Br,getFilenameFromUrl:()=>Me,getPdfFilenameFromUrl:()=>Ne,getRGB:()=>Re,getRGBA:()=>Le,getUuid:()=>ye,isDataScheme:()=>Ae,isPdfFile:()=>je,isValidExplicitDest:()=>Xt,makeArr:()=>xe,makeMap:()=>Se,makeObj:()=>Ce,noContextMenu:()=>H,normalizeUnicode:()=>ve,renderRichText:()=>$e,setLayerDimensions:()=>Ve,shadow:()=>L,stopEvent:()=>U,updateUrlHash:()=>ae,version:()=>Yr}),f=typeof process==`object`&&process+``==`[object process]`&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!==`browser`),p=[1/0,1/0,-1/0,-1/0],m=new Float32Array(p),h=[.001,0,0,.001,0,0],g=1.35,_=`http://www.w3.org/2000/svg`,v={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},y={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},b=`pdfjs_internal_id_`,x=`pdfjs_internal_editor_`,S={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},C={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},w={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},T={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},E={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},D={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,RICHMEDIA:27},O={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},k={ERRORS:0,WARNINGS:1,INFOS:5},A={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},j={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},ee={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},M=k.WARNINGS;function N(e){Number.isInteger(e)&&(M=e)}function te(){return M}function ne(e){M>=k.INFOS&&console.info(`Info: ${e}`)}function P(e){M>=k.WARNINGS&&console.warn(`Warning: ${e}`)}function F(e){throw Error(e)}function I(e,t){e||F(t)}function re(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}function ie(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`&&(n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`),n.tryConvertEncoding))try{e=ge(e)}catch{}let r=t?URL.parse(e,t):URL.parse(e);return re(r)?r:null}function ae(e,t,n=!1){let r=URL.parse(e);return r?(r.hash=t,r.href):n&&ie(e,`http://example.com`)?e.split(`#`,1)[0]+`${t?`#${t}`:``}`:``}function oe(e){return e.substring(e.lastIndexOf(`/`)+1)}function L(e,t,n,r=!1){return Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1}),n}var se=function(){function e(e,t){this.message=e,this.name=t}return e.prototype=Error(),e.constructor=e,e}(),ce=class extends se{constructor(e,t){super(e,`PasswordException`),this.code=t}},le=class extends se{constructor(e,t){super(e,`UnknownErrorException`),this.details=t}},ue=class extends se{constructor(e){super(e,`InvalidPDFException`)}},de=class extends se{constructor(e,t,n){super(e,`ResponseException`),this.status=t,this.missing=n}},fe=class extends se{constructor(e){super(e,`FormatError`)}},pe=class extends se{constructor(e){super(e,`AbortException`)}};function me(e){(typeof e!=`object`||e?.length===void 0)&&F(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);let r=[];for(let i=0;i<t;i+=n){let a=Math.min(i+n,t),o=e.subarray(i,a);r.push(String.fromCharCode.apply(null,o))}return r.join(``)}function he(e){typeof e!=`string`&&F(`Invalid argument for stringToBytes`);let t=e.length,n=new Uint8Array(t);for(let r=0;r<t;++r)n[r]=e.charCodeAt(r)&255;return n}var R=class{static get isLittleEndian(){let e=new Uint8Array(4);e[0]=1;let t=new Uint32Array(e.buffer,0,1);return L(this,`isLittleEndian`,t[0]===1)}static get isOffscreenCanvasSupported(){return L(this,`isOffscreenCanvasSupported`,typeof OffscreenCanvas<`u`)}static get isImageDecoderSupported(){return L(this,`isImageDecoderSupported`,typeof ImageDecoder<`u`)}static get isFloat16ArraySupported(){return L(this,`isFloat16ArraySupported`,typeof Float16Array<`u`)}static get isSanitizerSupported(){return L(this,`isSanitizerSupported`,typeof Sanitizer<`u`)}static get platform(){let{platform:e,userAgent:t}=navigator;return L(this,`platform`,{isAndroid:t.includes(`Android`),isLinux:e.includes(`Linux`),isMac:e.includes(`Mac`),isWindows:e.includes(`Win`),isFirefox:t.includes(`Firefox`)})}static get isCanvasFilterSupported(){let e;return this.isOffscreenCanvasSupported?e=new OffscreenCanvas(1,1).getContext(`2d`):typeof document<`u`&&(e=document.createElement(`canvas`).getContext(`2d`)),L(this,`isCanvasFilterSupported`,e?.filter!==void 0)}static get isAlphaColorInputSupported(){if(typeof document>`u`)return L(this,`isAlphaColorInputSupported`,!1);let e=document.createElement(`input`);return e.type=`color`,e.setAttribute(`alpha`,``),e.value=`#ff000080`,L(this,`isAlphaColorInputSupported`,e.value!==`#ff0000`)}static get isBackdropFilterSupported(){return L(this,`isBackdropFilterSupported`,typeof CSS<`u`&&CSS.supports(`backdrop-filter`,`blur(1px)`))}},z=class{static get hexNums(){return L(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4],e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s,e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i,e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n,g+=n,h+=r,m+=r,_+=e,b+=e,y+=t,v+=t}n[0]=Math.min(n[0],p,h,m,g),n[1]=Math.min(n[1],_,y,v,b),n[2]=Math.max(n[2],p,h,m,g),n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1),t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e),n[1]=Math.min(n[1],t),n[2]=Math.max(n[2],e),n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n),i[1]=Math.min(i[1],t,r),i[2]=Math.max(i[2],e,n),i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p),l[1]=Math.min(l[1],m),l[2]=Math.max(l[2],p),l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d),this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o),c[1]=Math.min(c[1],t,s),c[2]=Math.max(c[2],e,o),c[3]=Math.max(c[3],t,s),this.#t(e,n,i,o,t,r,a,s,3*(-e+3*(n-i)+o),6*(e-2*n+i),3*(n-e),c),this.#t(e,n,i,o,t,r,a,s,3*(-t+3*(r-a)+s),6*(t-2*r+a),3*(r-t),c)}};function ge(e){return decodeURIComponent(escape(e))}var _e=null,B=null;function ve(e){return _e||(_e=/([\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,B=new Map([[`ſt`,`ſt`]])),e.replaceAll(_e,(e,t,n)=>t?t.normalize(`NFKC`):B.get(n))}function ye(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),me(e)}function be(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r)||!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}var xe=()=>[],Se=()=>new Map,Ce=()=>Object.create(null);function V(e,t,n){return Math.min(Math.max(e,t),n)}var we=class e{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e,this.userUnit=t,this.scale=n,this.rotation=r,this.offsetX=i,this.offsetY=a,n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f;switch(r%=360,r<0&&(r+=360),r){case 180:l=-1,u=0,d=0,f=1;break;case 90:l=0,u=1,d=1,f=0;break;case 270:l=0,u=-1,d=-1,f=0;break;case 0:l=1,u=0,d=0,f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}o&&(d=-d,f=-f);let p,m,h,g;l===0?(p=Math.abs(c-e[1])*n+i,m=Math.abs(s-e[0])*n+a,h=(e[3]-e[1])*n,g=(e[2]-e[0])*n):(p=Math.abs(s-e[0])*n+i,m=Math.abs(c-e[1])*n+a,h=(e[2]-e[0])*n,g=(e[3]-e[1])*n),this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c],this.width=h,this.height=g}get rawDims(){let e=this.viewBox;return L(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:t=this.scale,rotation:n=this.rotation,offsetX:r=this.offsetX,offsetY:i=this.offsetY,dontFlip:a=!1}={}){return new e({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:n,offsetX:r,offsetY:i,dontFlip:a})}convertToViewportPoint(e,t){let n=[e,t];return z.applyTransform(n,this.transform),n}convertToPdfPoint(e,t){let n=[e,t];return z.applyInverseTransform(n,this.transform),n}},Te=class e{static textContent(t){let n=[],r={items:n,styles:Object.create(null)};function i(t){if(!t)return;let r=null,a=t.name;if(a===`#text`)r=t.value;else if(e.shouldBuildText(a))t?.attributes?.textContent?r=t.attributes.textContent:t.value&&(r=t.value);else return;if(r!==null&&n.push({str:r}),t.children)for(let e of t.children)i(e)}return i(t),r}static shouldBuildText(e){return!(e===`textarea`||e===`input`||e===`option`||e===`select`)}},Ee=class{static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:if(a.value!==null&&(e.textContent=a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){if(a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`),i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{if(a.value!==null&&e.setAttribute(`value`,a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})});break}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null)switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i.addLinkAttributes(e,a.href,a.newWindow),n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=document.createElement(r.name);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;if(s.append(a),e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e),o&&Te.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e),a.append(e);continue}let d=s?.attributes?.xmlns?document.createElementNS(s.attributes.xmlns,u):document.createElement(u);if(a.append(d),s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n}),s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&Te.shouldBuildText(u)&&c.push(e),d.append(e)}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t,e.div.hidden=!1}static getPageViewport(e,{scale:t=1,rotation:n=0}){let{width:r,height:i}=e.attributes.style;return new we({viewBox:[0,0,parseInt(r,10),parseInt(i,10)],userUnit:1,scale:t,rotation:n})}},De=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function Oe(e,t=`text`){if(Fe(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0),i.responseType=t===`bytes`?`arraybuffer`:t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText);return}r(Error(i.statusText))}},i.send(null)})}var ke=class extends se{constructor(e,t=0){super(e,`RenderingCancelledException`),this.extraDelay=t}};function Ae(e){let t=e.length,n=0;for(;n<t&&e[n].trim()===``;)n++;return e.substring(n,n+5).toLowerCase()===`data:`}function je(e){return typeof e==`string`&&/\.pdf$/i.test(e)}function Me(e){return[e]=e.split(/[#?]/,1),oe(e)}function Ne(e,t=`document.pdf`){if(typeof e!=`string`)return t;if(Ae(e))return P(`getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.`),t;let n=(e=>{try{return new URL(e)}catch{}try{return new URL(decodeURIComponent(e))}catch{}try{return new URL(e,`https://foo.bar`)}catch{}try{return new URL(decodeURIComponent(e),`https://foo.bar`)}catch{}return null})(e);if(!n)return t;let r=e=>{try{let t=decodeURIComponent(e);return t.includes(`/`)&&(t=oe(t),t.length===4&&i.test(t))?e:t}catch{return e}},i=/\.pdf$/i,a=oe(n.pathname);if(i.test(a))return r(a);if(n.searchParams.size>0){let e=e=>[...e].findLast(e=>i.test(e)),t=e(n.searchParams.values())??e(n.searchParams.keys());if(t)return r(t)}if(n.hash){let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(n.hash);if(e)return r(e[0])}return t}var Pe=class{#e=new Map;times=[];time(e){this.#e.has(e)&&P(`Timer is already running for ${e}`),this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||P(`Timer has not been started for ${e}`),this.times.push({name:e,start:this.#e.get(e),end:Date.now()}),this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}};function Fe(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function H(e){e.preventDefault()}function U(e){e.preventDefault(),e.stopPropagation()}var Ie=class{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;return u=u>=0&&u<=59?u:0,c===`-`?(a+=l,o+=u):c===`+`&&(a-=l,o-=u),new Date(Date.UTC(n,r,i,a,o,s))}};function Le(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(parseFloat(t[1])*255),Math.round(parseFloat(t[2])*255),Math.round(parseFloat(t[3])*255),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Re(e){let t=Le(e);return t?t.slice(0,3):(P(`Not a valid color format: "${e}"`),[0,0,0])}function ze(e){let t=document.createElement(`span`);t.style.visibility=`hidden`,t.style.colorScheme=`only light`,document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Re(r))}t.remove()}function W(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function Be(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function Ve(e,t,n=!1,r=!0){if(t instanceof we){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;!n||t.rotation%180==0?(a.width=o,a.height=s):(a.width=s,a.height=o)}r&&e.setAttribute(`data-main-rotation`,t.rotation)}var He=class e{constructor(){let{pixelRatio:t}=e;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(t,n,r,i,a=-1){let o=1/0,s=1/0,c=1/0;r=e.capPixels(r,a),r>0&&(o=Math.sqrt(r/(t*n))),i!==-1&&(s=i/t,c=i/n);let l=Math.min(o,s,c);return this.sx>l||this.sy>l?(this.sx=l,this.sy=l,!0):!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}},Ue=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`],We=class{static get isDarkMode(){return L(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}},Ge=class{static get commentForegroundColor(){let e=document.createElement(`span`);e.classList.add(`comment`,`sidebar`);let{style:t}=e;t.width=t.height=`0`,t.display=`none`,t.color=`var(--comment-fg-color)`,document.body.append(e);let{color:n}=window.getComputedStyle(e);return e.remove(),L(this,`commentForegroundColor`,Re(n))}};function Ke(e,t){t=V(t??1,0,1);let n=255*(1-t);return e.map(e=>Math.round(e*t+n))}function qe(e,t){let n=e[0]/255,r=e[1]/255,i=e[2]/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)t[0]=t[1]=0;else{let e=a-o;switch(t[1]=s<.5?e/(a+o):e/(2-a-o),a){case n:t[0]=((r-i)/e+(r<i?6:0))*60;break;case r:t[0]=((i-n)/e+2)*60;break;case i:t[0]=((n-r)/e+4)*60;break}}t[2]=s}function Je(e,t){let n=e[0],r=e[1],i=e[2],a=(1-Math.abs(2*i-1))*r,o=a*(1-Math.abs(n/60%2-1)),s=i-a/2;switch(Math.floor(n/60)){case 0:t[0]=a+s,t[1]=o+s,t[2]=s;break;case 1:t[0]=o+s,t[1]=a+s,t[2]=s;break;case 2:t[0]=s,t[1]=a+s,t[2]=o+s;break;case 3:t[0]=s,t[1]=o+s,t[2]=a+s;break;case 4:t[0]=o+s,t[1]=s,t[2]=a+s;break;case 5:case 6:t[0]=a+s,t[1]=s,t[2]=o+s;break}}function Ye(e){return e<=.03928?e/12.92:((e+.055)/1.055)**2.4}function Xe(e,t,n){Je(e,n),n.map(Ye);let r=.2126*n[0]+.7152*n[1]+.0722*n[2];Je(t,n),n.map(Ye);let i=.2126*n[0]+.7152*n[1]+.0722*n[2];return r>i?(r+.05)/(i+.05):(i+.05)/(r+.05)}var Ze=new Map;function Qe(e,t){let n=e[0]+e[1]*256+e[2]*65536+t[0]*16777216+t[1]*4294967296+t[2]*1099511627776,r=Ze.get(n);if(r)return r;let i=new Float32Array(9),a=i.subarray(0,3),o=i.subarray(3,6);qe(e,o);let s=i.subarray(6,9);qe(t,s);let c=s[2]<.5,l=c?12:4.5;if(o[2]=c?Math.sqrt(o[2]):1-Math.sqrt(1-o[2]),Xe(o,s,a)<l){let e,t;for(c?(e=o[2],t=1):(e=0,t=o[2]);t-e>.005;){let n=o[2]=(e+t)/2;c===Xe(o,s,a)<l?e=n:t=n}o[2]=c?t:e}return Je(o,a),r=z.makeHexColor(Math.round(a[0]*255),Math.round(a[1]*255),Math.round(a[2]*255)),Ze.set(n,r),r}function $e({html:e,dir:t,className:n},r){let i=document.createDocumentFragment();if(typeof e==`string`){let n=document.createElement(`p`);n.dir=t||`auto`;let r=e.split(/\r\n?|\n/);for(let e=0,t=r.length;e<t;++e){let i=r[e];n.append(document.createTextNode(i)),e<t-1&&n.append(document.createElement(`br`))}i.append(n)}else Ee.render({xfaHtml:e,div:i,intent:`richText`});i.firstElementChild.classList.add(`richText`,n),r.append(i)}function et(e){let t=new Path2D;if(!e)return t;for(let n=0,r=e.length;n<r;)switch(e[n++]){case j.moveTo:t.moveTo(e[n++],e[n++]);break;case j.lineTo:t.lineTo(e[n++],e[n++]);break;case j.curveTo:t.bezierCurveTo(e[n++],e[n++],e[n++],e[n++],e[n++],e[n++]);break;case j.quadraticCurveTo:t.quadraticCurveTo(e[n++],e[n++],e[n++],e[n++]);break;case j.closePath:t.closePath();break;default:P(`Unrecognized drawing path operator: ${e[n-1]}`);break}return t}var tt=class e{#e=null;#t=null;#n;#r=null;#i=null;#a=null;#o=null;#s=null;static#c=null;constructor(t){this.#n=t,e.#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(){let t=this.#e=document.createElement(`div`);t.classList.add(`editToolbar`,`hidden`),t.setAttribute(`role`,`toolbar`);let n=this.#n._uiManager._signal;n instanceof AbortSignal&&!n.aborted&&(t.addEventListener(`contextmenu`,H,{signal:n}),t.addEventListener(`pointerdown`,e.#l,{signal:n}));let r=this.#r=document.createElement(`div`);r.className=`buttons`,t.append(r);let i=this.#n.toolbarPosition;if(i){let{style:e}=t;e.insetInlineEnd=`${100*(this.#n._uiManager.direction===`ltr`?1-i[0]:i[0])}%`,e.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#e}static#l(e){e.stopPropagation()}#u(e){this.#n._focusEventsAllowed=!1,U(e)}#d(e){this.#n._focusEventsAllowed=!0,U(e)}#f(e){let t=this.#n._uiManager._signal;return!(t instanceof AbortSignal)||t.aborted?!1:(e.addEventListener(`focusin`,this.#u.bind(this),{capture:!0,signal:t}),e.addEventListener(`focusout`,this.#d.bind(this),{capture:!0,signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),!0)}hide(){this.#e.classList.add(`hidden`),this.#t?.hideDropdown()}show(){this.#e.classList.remove(`hidden`),this.#i?.shown(),this.#a?.shown()}addDeleteButton(){let{editorType:t,_uiManager:n}=this.#n,r=document.createElement(`button`);r.classList.add(`basic`,`deleteButton`),r.tabIndex=0,r.setAttribute(`data-l10n-id`,e.#c[t]),this.#f(r)&&r.addEventListener(`click`,e=>{n.delete()},{signal:n._signal}),this.#r.append(r)}get#p(){let e=document.createElement(`div`);return e.className=`divider`,e}async addAltText(e){let t=await e.render();this.#f(t),this.#r.append(t,this.#p),this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;t?(this.#r.insertBefore(n,t),this.#r.insertBefore(r,t)):this.#r.append(n,r),this.#a=e,e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t),this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t),this.#r.append(t,this.#p)}removeButton(e){switch(e){case`comment`:this.#a?.removeToolbarCommentButton(),this.#a=null,this.#o?.remove(),this.#o=null;break}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t);break}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove(),this.#t?.destroy(),this.#t=null}},nt=class{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`,e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,H,{signal:t});let n=this.#e=document.createElement(`div`);return n.className=`buttons`,e.append(n),this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)}),this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)}),e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(e<n)continue;let a=i.x+(t?i.width:0);if(e>n){r=a,n=e;continue}t?a>r&&(r=a):a<r&&(r=a)}return[t?1-r:r,n]}show(e,t,n){let[r,i]=this.#i(t,n),{style:a}=this.#t||=this.#r();e.append(this.#t),a.insetInlineEnd=`${100*r}%`,a.top=`calc(${100*i}% + var(--editor-toolbar-vert-offset))`}hide(){this.#t.remove()}#a(e,t,n,r){let i=document.createElement(`button`);i.classList.add(`basic`,e),i.tabIndex=0,i.setAttribute(`data-l10n-id`,t);let a=document.createElement(`span`);i.append(a),a.className=`visuallyHidden`,a.setAttribute(`data-l10n-id`,n);let o=this.#n._signal;o instanceof AbortSignal&&!o.aborted&&(i.addEventListener(`contextmenu`,H,{signal:o}),i.addEventListener(`click`,r,{signal:o})),this.#e.append(i)}},rt=Object.freeze({internal:`068f09d6-5b37-4f77-a97a-f8ff4f253b68`});function it(e,t,n){for(let r of n)t.addEventListener(r,e[r].bind(e))}var G=class e{static#e=NaN;static#t=null;static#n=NaN;static#r=null;static initializeAndAddPointerId(t){(e.#t||=new Set).add(t)}static setPointer(t,n){e.#e||=n,e.#r??=t}static setTimeStamp(t){e.#n=t}static isSamePointerId(t){return e.#e===t}static isSamePointerIdOrRemove(t){return e.#e===t?!0:(e.#t?.delete(t),!1)}static isSamePointerType(t){return e.#r===t}static isInitializedAndDifferentPointerType(t){return e.#r!==null&&!e.isSamePointerType(t)}static isSameTimeStamp(t){return e.#n===t}static isUsingMultiplePointers(){return e.#t?.size>=1}static clearPointerType(){e.#r=null}static clearPointerIds(){e.#e=NaN,e.#t=null}static clearTimeStamp(){e.#n=NaN}},at=class{#e=0;get id(){return`${x}${this.#e++}`}},ot=class e{#e=ye();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="${_}"><rect width="1" height="1" style="fill:red;"/></svg>`,t=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),n=new Image;n.src=e;let r=n.decode().then(()=>(t.drawImage(n,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0));return L(this,`_isSVGFittingCanvas`,r)}async#r(t,n){this.#n||=new Map;let r=this.#n.get(t);if(r===null)return null;if(r?.bitmap)return r.refCounter+=1,r;try{r||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let t;if(typeof n==`string`?(r.url=n,t=await Oe(n,`blob`)):n instanceof File?t=r.file=n:n instanceof Blob&&(t=n),t.type===`image/svg+xml`){let n=e._isSVGFittingCanvas,i=new FileReader,a=new Image,o=new Promise((e,t)=>{a.onload=()=>{r.bitmap=a,r.isSvg=!0,e()},i.onload=async()=>{let e=r.svgUrl=i.result;a.src=await n?`${e}#svgView(preserveAspectRatio(none))`:e},a.onerror=i.onerror=t});i.readAsDataURL(t),await o}else r.bitmap=await createImageBitmap(t);r.refCounter=1}catch(e){P(e),r=null}return this.#n.set(t,r),r&&this.#n.set(r.id,r),r}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap)return t.refCounter+=1,t;if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;return delete t.blobPromise,this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap)return n.refCounter+=1,n;let r=new OffscreenCanvas(t.width,t.height);return r.getContext(`2d`).drawImage(t,0,0),n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1},this.#n.set(e,n),this.#n.set(n.id,n),n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t||(--t.refCounter,t.refCounter!==0))return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n),t.blobPromise=e.convertToBlob()}n.close?.(),t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}},st=class{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){if(r&&e(),this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0),this.#r=0,this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo),this.#e[this.#r]=s;return}let c=this.#r+1;c===this.#n?this.#e.splice(0,1):(this.#r=c,c<this.#e.length&&this.#e.splice(c)),this.#e.push(s)}undo(){if(this.#r===-1)return;this.#t=!0;let{undo:e,post:t}=this.#e[this.#r];e(),t?.(),this.#t=!1,--this.#r}redo(){if(this.#r<this.#e.length-1){this.#r+=1,this.#t=!0;let{cmd:e,post:t}=this.#e[this.#r];e(),t?.(),this.#t=!1}}hasSomethingToUndo(){return this.#r!==-1}hasSomethingToRedo(){return this.#r<this.#e.length-1}cleanType(e){if(this.#r!==-1){for(let t=this.#r;t>=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t),this.#r=t;return}this.#e.length=0,this.#r=-1}}destroy(){this.#e=null}},ct=class e{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(t){this.callbacks=new Map;let{isMac:n}=R.platform;for(let[r,i,a={}]of t){let t=r.some(e=>e.startsWith(`mac+`));for(let o of r){let r=o;if(t){let e=o.startsWith(`mac+`);if(n!==e)continue;e&&(r=o.slice(4))}let[s,c]=e.#e(r);s!==null&&this.callbacks.getOrInsertComputed(s,xe).push({callback:i,options:a,modifiers:c})}}}static#e(t){let n=null,r=0;for(let i of t.split(`+`)){if(i=i.trim(),!i)continue;let a=i.toUpperCase(),o=e[a];if(o){r|=o;continue}if(n!==null){P(`KeyboardManager: multiple keys in shortcut "${t}"`);break}n=a===`SPACE`?` `:i}return n===null&&P(`KeyboardManager: no key found in shortcut "${t}"`),[n,r]}static#t(e){let t=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(e);return t?t[1]?.toLowerCase()??t[2]:null}exec(t,n){let r=this.callbacks.get(n.key);if(!r){if(/^[a-z]$/i.test(n.key))return;let t=e.#t(n.code);if(t===null||t===n.key||(r=this.callbacks.get(t),!r))return}let i=(n.altKey?e.ALT:0)|(n.ctrlKey?e.CTRL:0)|(n.metaKey?e.META:0)|(n.shiftKey?e.SHIFT:0),a=r.find(e=>e.modifiers===i);if(!a)return;let{callback:o,options:{bubbles:s=!1,args:c=[],checker:l=null}}=a;l&&!l(t,n)||(o.bind(t,...c,n)(),s||U(n))}},lt=class e{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);return ze(e),L(this,`_colors`,e)}convert(t){let n=Re(t);if(!window.matchMedia(`(forced-colors: active)`).matches)return n;for(let[t,r]of this._colors)if(r.every((e,t)=>e===n[t]))return e._colorsMapping.get(t);return n}getHexCode(e){let t=this._colors.get(e);return t?z.makeHexColor(...t):e}},ut=class e{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new st;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new at;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=S.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),r=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},i=this.TRANSLATE_SMALL,a=this.TRANSLATE_BIG;return L(this,`_keyboardManager`,new ct([[[`ctrl+a`,`mac+meta+a`],t.selectAll,{checker:r}],[[`ctrl+z`,`mac+meta+z`],t.undo,{checker:r}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],t.redo,{checker:r}],[[`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:r}],[[`Enter`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[`Space`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`],t.unselectAll],[[`ArrowLeft`],t.translateSelectedEditors,{args:[-i,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t.translateSelectedEditors,{args:[-a,0],checker:n}],[[`ArrowRight`],t.translateSelectedEditors,{args:[i,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t.translateSelectedEditors,{args:[a,0],checker:n}],[[`ArrowUp`],t.translateSelectedEditors,{args:[0,-i],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t.translateSelectedEditors,{args:[0,-a],checker:n}],[[`ArrowDown`],t.translateSelectedEditors,{args:[0,i],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t.translateSelectedEditors,{args:[0,a],checker:n}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e,this.#q=t,this.#J=n,this.#o=r,this.#u=i,this.#z=a,this.#H=s,this._eventBus=o;let _={signal:g,...rt};o.on(`editingaction`,this.onEditingAction.bind(this),_),o.on(`pagechanging`,this.onPageChanging.bind(this),_),o.on(`scalechanging`,this.onScaleChanging.bind(this),_),o.on(`rotationchanging`,this.onRotationChanging.bind(this),_),o.on(`setpreference`,this.onSetPreference.bind(this),_),o.on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),_),window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g}),window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g}),window.addEventListener(`beforeunload`,this.#Q.bind(this),{capture:!0,signal:g}),this.#ne(),this.#le(),this.#ae(),this.#s=s.annotationStorage,this.#x=s.filterFactory,this.#B=c,this.#w=l||null,this.#v=u,this.#y=d,this.#b=f,this.#F=p||null,this.viewParameters={realScale:De.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=m||null,this._supportsPinchToZoom=h!==!1,i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve(),this.#Y=null,this.#e?.abort(),this.#e=null,this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear(),this.#r.clear(),this.#_.clear(),this.#P?.clear(),this.#t=null,this.#L.clear(),this.#l.destroy(),this.#o?.destroy(),this.#u?.destroy(),this.#z?.destroy(),this.#E?.hide(),this.#E=null,this.#N?.destroy(),this.#N=null,this.#n=null,this.#S&&=(clearTimeout(this.#S),null),this.#G&&=(clearTimeout(this.#G),null),this._editorUndoBar?.destroy(),this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return L(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return L(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return L(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>(e=e.split(`=`).map(e=>e.trim()),e[1]=e[1].toUpperCase(),e))):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return L(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);if(n&&e){t.set(r.replace(`_HCM`,``),i);continue}!n&&!e&&t.set(r,i)}return L(this,`highlightColors`,t)}get highlightColorNames(){return L(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){e?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`),this.toggleComment(null),e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{n.pageNumber===e&&(this._eventBus.off(`editorsrendered`,r),t())};this._eventBus.on(`editorsrendered`,r,rt),await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal,...rt}),this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){switch(e){case`enableNewAltTextWhenAddingImage`:this.#b=t;break}}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e),this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove(),this.viewParameters.realScale=e*De.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove(),this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===S.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0),t&&n?.editComment()};if(d){this.switchToMode(S.HIGHLIGHT,f);return}f()}commentSelection(e=``){this.highlightSelection(e,!0)}#Q(e){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#$(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);n&&(this.#E||=new nt(this),this.#E.show(t,n,this.direction===`ltr`))}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${x}${e}`,n=this.#s.getRawValue(t);return n&&this.#s.remove(t),n}addToAnnotationStorage(e){!e.isEmpty()&&this.#s&&!this.#s.has(e.id)&&this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;n&&(n.setAttribute(`data-l10n-id`,e),t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`))}#ee(){let e=document.getSelection();if(!e||e.isCollapsed){this.#R&&(this.#E?.hide(),this.#R=null,this.#ue({hasSelectedText:!1}));return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(!n){this.#R&&(this.#E?.hide(),this.#R=null,this.#ue({hasSelectedText:!1}));return}if(this.#E?.hide(),this.#R=t,this.#ue({hasSelectedText:!0}),!(this.#I!==S.HIGHLIGHT&&this.#I!==S.NONE)&&(this.#I===S.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0),this.#T=this.isShiftKeyDown,!this.isShiftKeyDown)){let e=this.#I===S.HIGHLIGHT?this.#Z(n):null;if(e?.toggleDrawing(),this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{n.type===`pointerup`&&n.button!==0||(t.abort(),e?.toggleDrawing(!0),n.type===`pointerup`&&this.#te(`main_toolbar`))};window.addEventListener(`pointerup`,r,{signal:n}),window.addEventListener(`blur`,r,{signal:n})}else e?.toggleDrawing(!0),this.#te(`main_toolbar`)}}#te(e=``){this.#I===S.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#$()}#ne(){document.addEventListener(`selectionchange`,this.#ee.bind(this),{signal:this._signal})}#re(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e}),window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#ie(){this.#C?.abort(),this.#C=null}blur(){if(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#te(`main_toolbar`)),!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e],t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null,t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal}),t.focus()}#ae(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e}),window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#oe(){this.#j?.abort(),this.#j=null}#se(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e}),document.addEventListener(`cut`,this.cut.bind(this),{signal:e}),document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#ce(){this.#d?.abort(),this.#d=null}#le(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e}),document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ae(),this.setEditingState(!0)}removeEditListeners(){this.#oe(),this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`,e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer),e.preventDefault();return}}copy(e){if(e.preventDefault(),this.#t?.commitOrRemove(),!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e),this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){P(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#me(t);this.#_e(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){P(`paste: "${e.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key===`Shift`&&(this.isShiftKeyDown=!0),this.#I!==S.NONE&&!this.isEditorHandlingKeyboard&&e._keyboardManager.exec(this,t)}keyup(e){this.isShiftKeyDown&&e.key===`Shift`&&(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#te(`main_toolbar`)))}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`);break}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);n&&(n.pageIndex=t,this.#i.set(t,n),this.#O?n.enable():n.disable())}startUpdatePages(){this.#a=new Map(this.#i),this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==S.HIGHLIGHT);e&&(e.pageIndex=t,e.id=this.getId(),e.isClone=!0,delete e.popupRef,this.#s.setValue(e.id,e))}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)i.pageIndex===n&&i.isClone&&(this.#s.remove(r),t.push(e.deserialize(i).then(t=>{t&&(t.isClone=!0,e.addOrRebuild(t))})));return Promise.all(t)}#ue(e){Object.entries(e).some(([e,t])=>this.#U[e]!==t)&&(this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)}),this.#I===S.HIGHLIGHT&&e.hasSelectedEditor===!1&&this.#de([[C.HIGHLIGHT_FREE,!0]]))}#de(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){e?(this.#re(),this.#se(),this.#ue({isEditing:this.#I!==S.NONE,isEmpty:this.#ge(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#ie(),this.#ce(),this.#ue({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#de(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e),this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e&&!(this.#Y&&(await this.#Y.promise,!this.#Y))){if(this.#Y=Promise.withResolvers(),this.#f?.commitOrRemove(),this.#I===S.POPUP&&this.#u?.hideSidebar(),this.#u?.destroyPopup(),this.#I=e,e===S.NONE){this.setEditingState(!1),this.#pe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide(),this.toggleComment(null),this.#Y.resolve();return}for(let e of this.#r.values())e.addStandaloneCommentButton();e===S.SIGNATURE&&await this.#z?.loadSignatures(),n&&G.clearPointerType(),this.setEditingState(!0),await this.#fe(),this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===S.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r),i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(!t){r&&this.addNewEditorFromKeyboard(),this.#Y.resolve();return}for(let e of this.#r.values())e.uid===t?(this.setSelected(e),a?e.editComment():i?e.enterInEditMode():e.focus()):e.unselect();this.#Y.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case C.CREATE:this.currentLayer.addNewEditor(t);return;case C.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}}),(this.#V||=new Map).set(e,t),this.showAllEditors(`highlight`,t);break}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(C.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#de([[C.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values())e?t.disableClick():t.enableClick(),t.div.classList.toggle(`waiting`,e)}}async#fe(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#pe(){if(this.unselectAll(),this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){e.div.contains(document.activeElement)&&(this.#S&&clearTimeout(this.#S),this.#S=setTimeout(()=>{this.focusMainContainer(),this.#S=null},0)),this.#r.delete(e.id),e.annotationElementId&&this.#P?.delete(e.annotationElementId),this.unselect(e),(!e.annotationElementId||!this.#m.has(e.annotationElementId))&&this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId),this.addChangedExistingAnnotation(e),e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId),this.removeChangedExistingAnnotation(e),e.deleted=!1}#me(e){let t=this.#i.get(e.pageIndex);t?t.addOrRebuild(e):(this.addEditor(e),this.addToAnnotationStorage(e))}setActiveEditor(e){this.#t!==e&&(this.#t=e,e&&this.#de(e.propertiesToUpdate))}get#he(){let e=null;for(e of this.#L);return e}updateUI(e){this.#he===e&&this.#de(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#de(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e),e.unselect(),this.#ue({hasSelectedEditor:this.hasSelection});return}this.#L.add(e),e.select(),this.#de(e.propertiesToUpdate),this.#ue({hasSelectedEditor:!0})}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid}),this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup(),this.#L.clear(),this.#L.add(e),e.select(),this.#de(e.propertiesToUpdate),this.#ue({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect(),this.#L.delete(e),this.#ue({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo(),this.#ue({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#ge()}),this._editorUndoBar?.hide()}redo(){this.#l.redo(),this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#ge()})}addCommands(e){this.#l.add(e),this.#ue({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#ge()})}cleanUndoStack(e){this.#l.cleanType(e)}#ge(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{this._editorUndoBar?.show(r,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},r=()=>{for(let e of t)this.#me(e)};this.addCommands({cmd:n,undo:r,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#_e(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)t.isEmpty()||(this.#L.add(t),t.select());this.#ue({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#_e(this.#r.values())}unselectAll(){if(!(this.#t&&(this.#t.commitOrRemove(),this.#I!==S.NONE))&&!this.#f?.commitOrRemove()&&(this.#u?.destroyPopup(),this.hasSelection)){for(let e of this.#L)e.unselect();this.#L.clear(),this.#ue({hasSelectedEditor:!1})}}translateSelectedEditors(e,t,n=!1){if(n||this.commitOrRemove(),!this.hasSelection)return;this.#W[0]+=e,this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G),this.#G=setTimeout(()=>{this.#G=null,this.#W[0]=this.#W[1]=0,this.addCommands({cmd:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(r,i),e.translationDone())},undo:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(-r,-i),e.translationDone())},mustExec:!1})},1e3);for(let n of a)n.translateInPage(e,t),n.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e)a.newX=n,a.newY=r,a.newPageIndex=i,t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex;if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);i?e._setParentAndPosition(i,t,n):(e.pageIndex=r,e.x=t,e.y=n)}};return this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0}),!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);t?(t.changeParent(e),t.addOrRebuild(e)):(this.addEditor(e),this.addToAnnotationStorage(e),e.rebuild())}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==S.NONE}get imageManager(){return L(this,`imageManager`,new ot)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n<r;n++)if(!e.contains(t.getRangeAt(n).commonAncestorContainer))return null;let{x:n,y:r,width:i,height:a}=e.getBoundingClientRect(),o;switch(e.getAttribute(`data-main-rotation`)){case`90`:o=(e,t,o,s)=>({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a});break}let s=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(!n.collapsed)for(let{x:e,y:t,width:r,height:i}of n.getClientRects())r===0||i===0||s.push(o(e,t,r,i))}return s.length===0?null:s}addChangedExistingAnnotation({annotationElementId:e,id:t}){(this.#c||=new Map).set(e,t)}removeChangedExistingAnnotation({annotationElementId:e}){this.#c?.delete(e)}renderAnnotationElement(e){let t=this.#c?.get(e.data.id);if(!t)return;let n=this.#s.getRawValue(t);n&&(this.#I===S.NONE&&!n.hasBeenModified||n.renderAnnotationElement(e))}setMissingCanvas(e,t,n){let r=this.#P?.get(e);r&&(r.setCanvas(t,n),this.#P.delete(e))}addMissingCanvas(e,t){(this.#P||=new Map).set(e,t)}},dt=class e{#e=null;#t=!1;#n=null;#r=null;#i=null;#a=null;#o=!1;#s=null;#c=null;#l=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(t){this.#c=t,this.#d=t._uiManager.useNewAltTextFlow,e.#f||=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){e._l10n??=t}async render(){let t=this.#n=document.createElement(`button`);t.className=`altText`,t.tabIndex=`0`;let n=this.#r=document.createElement(`span`);t.append(n),this.#d?(t.classList.add(`new`),t.setAttribute(`data-l10n-id`,e.#f.missing),n.setAttribute(`data-l10n-id`,e.#f[`missing-label`])):(t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button`),n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-button-label`));let r=this.#c._uiManager._signal;t.addEventListener(`contextmenu`,H,{signal:r}),t.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:r});let i=e=>{e.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};return t.addEventListener(`click`,i,{capture:!0,signal:r}),t.addEventListener(`keydown`,e=>{e.target===t&&e.key===`Enter`&&(this.#o=!0,i(e))},{signal:r}),await this.#m(),t}get#p(){return this.#e&&`added`||this.#e===null&&this.guessedText&&`review`||`missing`}finish(){this.#n&&(this.#n.focus({focusVisible:this.#o}),this.#o=!1)}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(t){this.#e===null&&(this.#l=t,this.#u=await e._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:t}),this.#m())}toggleAltTextBadge(e=!1){if(!this.#d||this.#e){this.#s?.remove(),this.#s=null;return}if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`,this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}serialize(e){let t=this.#e;return!e&&this.#l===t&&(t=this.#u),{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){n&&(this.#l=n,this.#u=r),!(this.#e===e&&this.#t===t)&&(i||(this.#e=e,this.#t=t),this.#m())}toggle(e=!1){this.#n&&(!e&&this.#a&&(clearTimeout(this.#a),this.#a=null),this.#n.disabled=!e)}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove(),this.#n=null,this.#r=null,this.#i=null,this.#s?.remove(),this.#s=null}async#m(){let t=this.#n;if(!t)return;if(this.#d){if(t.classList.toggle(`done`,!!this.#e),t.setAttribute(`data-l10n-id`,e.#f[this.#p]),this.#r?.setAttribute(`data-l10n-id`,e.#f[`${this.#p}-label`]),!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){t.classList.remove(`done`),this.#i?.remove();return}t.classList.add(`done`),t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let n=this.#i;if(!n){this.#i=n=document.createElement(`span`),n.className=`tooltip`,n.setAttribute(`role`,`tooltip`),n.id=`alt-text-tooltip-${this.#c.id}`;let e=this.#c._uiManager._signal;e.addEventListener(`abort`,()=>{clearTimeout(this.#a),this.#a=null},{once:!0}),t.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null,this.#i.classList.add(`show`),this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:e}),t.addEventListener(`mouseleave`,()=>{this.#a&&=(clearTimeout(this.#a),null),this.#i?.classList.remove(`show`)},{signal:e})}this.#t?n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`):(n.removeAttribute(`data-l10n-id`),n.textContent=this.#e),n.parentNode||t.append(n),this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,n.id)}},ft=class{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);return e.className=`comment`,this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`,n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove(),this.#e=null}removeToolbarCommentButton(){this.#t?.remove(),this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){this.#e&&(this.#e.classList.toggle(`selected`,e),this.#e.ariaExpanded=t)}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`,e.ariaHasPopup=`dialog`,t?(e.ariaControls=`commentPopup`,e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)):(e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`));let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,H,{signal:n}),t&&(e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1,U(e)},{capture:!0,signal:n}),e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0,U(e)},{capture:!0,signal:n})),e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault(),e===this.#t?this.edit():this.#r.toggleComment(!0)};return e.addEventListener(`click`,r,{capture:!0,signal:n}),e.addEventListener(`keydown`,t=>{t.target===e&&t.key===`Enter`&&(this.#n=!0,r(t))},{signal:n}),e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n}),e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n}),e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e,r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){this.#t&&(this.#t.focus({focusVisible:this.#n}),this.#n=!1)}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){if(e!==this.#o&&(this.#a=null),e===null){this.#o=``,this.#c=!0;return}this.#o=e,this.#s=new Date,this.#c=!1}restoreData({text:e,richText:t,date:n}){this.#o=e,this.#a=t,this.#s=n,this.#c=!1}setInitialText(e,t=null){this.#i=e,this.data=e,this.#s=null,this.#a=t}shown(){}destroy(){this.#t?.remove(),this.#t=null,this.#e?.remove(),this.#e=null,this.#o=``,this.#a=null,this.#s=null,this.#r=null,this.#n=!1,this.#c=!1}},pt=class e{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e,this.#n=n,this.#r=t,this.#i=r,this.#a=i,this.#o=a,this.#u=new AbortController,this.#c=AbortSignal.any([o,this.#u.signal]),e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/He.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{e.pointerType===`touch`&&(this.#s?.abort(),this.#s=null)};n.addEventListener(`pointerdown`,e=>{e.pointerType===`touch`&&(U(e),i(e))},r),n.addEventListener(`pointerup`,i,r),n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n),t.addEventListener(`touchcancel`,r,n),n.capture=!0,t.addEventListener(`pointerdown`,U,n),t.addEventListener(`pointermove`,U,n),t.addEventListener(`pointercancel`,U,n),t.addEventListener(`pointerup`,U,n),this.#i?.()}if(U(e),e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]),this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(t){if(!this.#l||t.touches.length!==2)return;U(t);let[n,r]=t.touches;n.identifier>r.identifier&&([n,r]=[r,n]);let{screenX:i,screenY:a}=n,{screenX:o,screenY:s}=r,c=this.#l,{touch0X:l,touch0Y:u,touch1X:d,touch1Y:f}=c,p=d-l,m=f-u,h=o-i,g=s-a,_=Math.hypot(h,g)||1,v=Math.hypot(p,m)||1;if(!this.#t&&Math.abs(v-_)<=e.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(c.touch0X=i,c.touch0Y=a,c.touch1X=o,c.touch1Y=s,!this.#t){this.#t=!0;return}let y=[(i+o)/2,(a+s)/2];this.#a?.(y,v,_)}#m(e){e.touches.length>=2||(this.#d&&(this.#d.abort(),this.#d=null,this.#o?.()),this.#l&&(U(e),this.#l=null,this.#t=!1))}destroy(){this.#u?.abort(),this.#u=null,this.#s?.abort(),this.#s=null}},K=class e{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=e._zIndex++;static _borderLineWidth=-1;static _colorManager=new lt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=e.prototype._resizeWithKeyboard,n=ut.TRANSLATE_SMALL,r=ut.TRANSLATE_BIG;return L(this,`_resizerKeyboardManager`,new ct([[[`ArrowLeft`],t,{args:[-n,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t,{args:[-r,0]}],[[`ArrowRight`],t,{args:[n,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t,{args:[r,0]}],[[`ArrowUp`],t,{args:[0,-n]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t,{args:[0,-r]}],[[`ArrowDown`],t,{args:[0,n]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t,{args:[0,r]}],[[`Escape`],e.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent,this.id=e.id,this.width=this.height=null,this.pageIndex=e.parent.pageIndex,this.name=e.name,this.div=null,this._uiManager=e.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=e.isCentered,this._structTreeParentId=null,this.annotationElementId=e.annotationElementId||null,this.creationDate=e.creationDate||new Date,this.modificationDate=e.modificationDate||null,this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t,this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[n,r],this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o,this.y=e.y/s,this.isAttachedToDOM=!1,this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return L(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new mt({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId,t.deleted=!0,t._uiManager.addToAnnotationStorage(t)}static initialize(t,n){if(e._l10n??=t,e._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`}),e._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`}),e._borderLineWidth!==-1)return;let r=getComputedStyle(document.documentElement);e._borderLineWidth=parseFloat(r.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){F(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e,this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(e*2),this.y+=this.width*e/(t*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*t/(e*2),this.y-=this.width*e/(t*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){e===null?(this.#W(),this.#d?.remove(),this.#d=null):(this.pageIndex=e.pageIndex,this.pageDimensions=e.pageDimensions),this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){this._focusEventsAllowed&&this.isAttachedToDOM&&(e.relatedTarget?.closest(`#${this.id}`)||(e.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove()))}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r),this.x=(e+n)/i,this.y=(t+r)/a,this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r),this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r),this.x+=n/e,this.y+=r/t,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height],this.#E(this.pageDimensions,e,t),this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;if(this.x+=e/r,this.y+=t/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();this.parent.findNewParent(this,e,t)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s,o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`,l.top=`${(100*o).toFixed(2)}%`,this._onTranslating(a,o),n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[t,n]=this.parentDimensions,{_borderLineWidth:r}=e,i=r/t,a=r/n;switch(this.rotation){case 90:return[-i,a];case 180:return[i,a];case 270:return[i,-a];default:return[-i,-a]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;if(o*=n,s*=r,i*=n,a*=r,this._mustFixPosition)switch(e){case 0:i=V(i,0,n-o),a=V(a,0,r-s);break;case 90:i=V(i,0,n-s),a=V(a,o,r);break;case 180:i=V(i,o,n),a=V(a,s,r);break;case 270:i=V(i,s,n),a=V(a,0,r-o);break}this.x=i/=n,this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c,a+=l,t.left=`${(100*i).toFixed(2)}%`,t.top=`${(100*a).toFixed(2)}%`,this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(t,n){return e.#D(t,n,this.parentRotation)}pageTranslationToScreen(t,n){return e.#D(t,n,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`,e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`),this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e),e.classList.add(`resizer`,n),e.setAttribute(`data-resizer-name`,n),e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=R.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1,this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1),window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a}),window.addEventListener(`touchmove`,U,{passive:!1,signal:a}),window.addEventListener(`contextmenu`,H,{signal:a}),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort(),this.parent.togglePointerEvents(!0),this.#n?.toggle(!0),this._isDraggable=r,this.parent.div.style.cursor=o,this.div.style.cursor=s,this.#M()};window.addEventListener(`pointerup`,c,{signal:a}),window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n,this.height=r,this.x=e,this.y=t,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(e*1e4)/1e4}#N(t,n){let[r,i]=this.parentDimensions,a=this.x,o=this.y,s=this.width,c=this.height,l=e.MIN_SIZE/r,u=e.MIN_SIZE/i,d=this.#O(this.rotation),f=(e,t)=>[d[0]*e+d[2]*t,d[1]*e+d[3]*t],p=this.#O(360-this.rotation),m=(e,t)=>[p[0]*e+p[2]*t,p[1]*e+p[3]*t],h,g,_=!1,v=!1;switch(t){case`topLeft`:_=!0,h=(e,t)=>[0,0],g=(e,t)=>[e,t];break;case`topMiddle`:h=(e,t)=>[e/2,0],g=(e,t)=>[e/2,t];break;case`topRight`:_=!0,h=(e,t)=>[e,0],g=(e,t)=>[0,t];break;case`middleRight`:v=!0,h=(e,t)=>[e,t/2],g=(e,t)=>[0,t/2];break;case`bottomRight`:_=!0,h=(e,t)=>[e,t],g=(e,t)=>[0,0];break;case`bottomMiddle`:h=(e,t)=>[e/2,t],g=(e,t)=>[e/2,0];break;case`bottomLeft`:_=!0,h=(e,t)=>[0,t],g=(e,t)=>[e,0];break;case`middleLeft`:v=!0,h=(e,t)=>[0,t/2],g=(e,t)=>[e,t/2];break}let y=h(s,c),b=g(s,c),x=f(...b),S=e._round(a+x[0]),C=e._round(o+x[1]),w=1,T=1,E,D;if(n.fromKeyboard)({deltaX:E,deltaY:D}=n);else{let{screenX:e,screenY:t}=n,[r,i]=this.#l;[E,D]=this.screenToPageTranslation(e-r,t-i),this.#l[0]=e,this.#l[1]=t}if([E,D]=m(E/r,D/i),_){let e=Math.hypot(s,c);w=T=Math.max(Math.min(Math.hypot(b[0]-y[0]-E,b[1]-y[1]-D)/e,1/s,1/c),l/s,u/c)}else v?w=V(Math.abs(b[0]-y[0]-E),l,1)/s:T=V(Math.abs(b[1]-y[1]-D),u,1)/c;let O=e._round(s*w),k=e._round(c*T);x=f(...g(O,k));let A=S-x[0],j=C-x[1];this.#h||=[this.x,this.y,this.width,this.height],this.width=O,this.height=k,this.x=A,this.y=j,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new tt(this),this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);return this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton()),this._editToolbar.addButton(`delete`),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#n||(dt.initialize(e._l10n),this.#n=new dt(this),this.#e&&=(this.#n.data=this.#e,null)),this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new ft(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i){this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);return}this.hasComment&&(this.#i=this.#r.renderForStandalone(),this.div.append(this.#i))}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton(),this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new ft(this),typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:e,popupRef:t,richText:n}){if(!t||(this.#r||=new ft(this),this.#r.setInitialText(e,n),!this.annotationElementId))return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new ft(this),this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360),e.className=this.name,e.setAttribute(`id`,this.id),e.tabIndex=this.#a?-1:0,e.setAttribute(`role`,`application`),this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId),this._isVisible||e.classList.add(`hidden`),this.setInForeground(),this.#z();let[t,n]=this.parentDimensions;this.parentRotation%180!=0&&(e.style.maxWidth=`${(100*n/t).toFixed(2)}%`,e.style.maxHeight=`${(100*t/n).toFixed(2)}%`);let[r,i]=this.getInitialTranslation();return this.translate(r,i),it(this,e,[`keydown`,`pointerdown`,`dblclick`]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new pt({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#n?.toggle(!1),this.parent.togglePointerEvents(!1)}#F(t,n,r){let i=.7,a=r/n*i+1-i;if(a===1)return;let o=this.#O(this.rotation),s=(e,t)=>[o[0]*e+o[2]*t,o[1]*e+o[3]*t],[c,l]=this.parentDimensions,u=this.x,d=this.y,f=this.width,p=this.height,m=e.MIN_SIZE/c,h=e.MIN_SIZE/l;a=Math.max(Math.min(a,1/f,1/p),m/f,h/p);let g=e._round(f*a),_=e._round(p*a);if(g===f&&_===p)return;this.#h||=[u,d,f,p];let v=s(f/2,p/2),y=e._round(u+v[0]),b=e._round(d+v[1]),x=s(g/2,_/2);this.x=y-x[0],this.y=b-x[1],this.width=g,this.height=_,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#I(){this.#n?.toggle(!0),this.parent.togglePointerEvents(!0),this.#M()}pointerdown(e){let{isMac:t}=R.platform;if(e.button!==0||e.ctrlKey&&t){e.preventDefault();return}if(this.#m=!0,this._isDraggable){this.#R(e);return}this.#L(e)}#L(e){let{isMac:t}=R.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort(),this.#o=null,this.#m=!1,this._uiManager.endDragSession()||this.#L(e),n&&this._onStopDragging()};t&&(this.#b=e.clientX,this.#x=e.clientY,this.#o=e.pointerId,this.#s=e.pointerType,window.addEventListener(`pointermove`,e=>{n||(n=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){U(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t,this.#x=r,this._uiManager.dragSelectedEditors(a,o)},a),window.addEventListener(`touchmove`,U,a),window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e),U(e)},a));let s=e=>{if(!this.#o||this.#o===e.pointerId){o(e);return}U(e)};window.addEventListener(`pointerup`,s,{signal:i}),window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this),this.x=t,this.y=n,this.fixAndSetPosition(),this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&e._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){return this.isInEditMode()?!1:(this.parent.setEditingState(!1),this.#_=!0,!0)}disableEditMode(){return this.isInEditMode()?(this.parent.setEditingState(!0),this.#_=!1,!0):!1}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t<a&&r>0&&e<i&&n>0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e}),this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation,r.#e=e.accessibilityData,r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);return r.x=o/i,r.y=s/a,r.width=c/i,r.height=l/a,r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#f?.abort(),this.#f=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#y&&=(clearTimeout(this.#y),null),this.#W(),this.removeEditToolbar(),this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null,this.#C?.destroy(),this.#C=null,this.#d?.remove(),this.#d=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#k(),this.#c.classList.remove(`hidden`))}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[t,n]}=this,[r,i,a,o]=this.getPDFRect();return[e._round(r+(a-r)*t),e._round(i+(o-i)*(1-n))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!==`Enter`)return;this._uiManager.setSelected(this),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let n=this.#c.children;if(!this.#t){this.#t=Array.from(n);let t=this.#B.bind(this),r=this.#V.bind(this),i=this._uiManager._signal;for(let n of this.#t){let a=n.getAttribute(`data-resizer-name`);n.setAttribute(`role`,`spinbutton`),n.addEventListener(`keydown`,t,{signal:i}),n.addEventListener(`blur`,r,{signal:i}),n.addEventListener(`focus`,this.#H.bind(this,a),{signal:i}),n.setAttribute(`data-l10n-id`,e._l10nResizer[a])}}let r=this.#t[0],i=0;for(let e of n){if(e===r)break;i++}let a=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(a!==i){if(a<i)for(let e=0;e<i-a;e++)this.#c.append(this.#c.firstElementChild);else if(a>i)for(let e=0;e<a-i;e++)this.#c.firstElementChild.before(this.#c.lastElementChild);let t=0;for(let r of n){let n=this.#t[t++].getAttribute(`data-resizer-name`);r.setAttribute(`data-l10n-id`,e._l10nResizer[n])}}this.#U(0),this.#v=!0,this.#c.firstElementChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#B(t){e._resizerKeyboardManager.exec(this,t)}#V(e){this.#v&&e.relatedTarget?.parentNode!==this.#c&&this.#W()}#H(e){this.#p=this.#v?e:``}#U(e){if(this.#t)for(let t of this.#t)t.tabIndex=e}_resizeWithKeyboard(e,t){this.#v&&this.#N(this.#p,{deltaX:e,deltaY:t,fromKeyboard:!0})}#W(){this.#v=!1,this.#U(-1),this.#M()}_stopResizingWithKeyboard(){this.#W(),this.div.focus()}select(){if(this.isSelected&&this._editToolbar){this._editToolbar.show();return}if(this.isSelected=!0,this.makeResizable(),this.div?.classList.add(`selectedEditor`),!this._editToolbar){this.addEditToolbar().then(()=>{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()});return}this._editToolbar?.show(),this.#n?.toggleAltTextBadge(!1)}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#c?.classList.add(`hidden`),this.div?.classList.remove(`selectedEditor`),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#n?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(e){e.target.nodeName!==`BUTTON`&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e,this.parent&&(e?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(t,n=!1){if(n){this.#S||=new Map;let{action:n}=t,r=this.#S.get(n);r&&clearTimeout(r),r=setTimeout(()=>{this._reportTelemetry(t),this.#S.delete(n),this.#S.size===0&&(this.#S=null)},e._telemetryTimeout),this.#S.set(n,r);return}t.type||=this.editorType,this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:t}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e),this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0),this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#a=!0}updateFakeAnnotationElement(e){if(!this.#d&&!this.deleted){this.#d=e.addFakeAnnotation(this);return}if(this.deleted){this.#d.remove(),this.#d=null;return}(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let t=e.container.querySelector(`.annotationContent`);if(!t)t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.container.prepend(t);else if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.before(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}},mt=class extends K{constructor(e){super(e),this.annotationElementId=e.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},ht=3285377520,gt=4294901760,_t=65535,vt=class{constructor(e){this.h1=e?e&4294967295:ht,this.h2=e?e&4294967295:ht}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(e.length*2),n=0;for(let r=0,i=e.length;r<i;r++){let i=e.charCodeAt(r);i<=255?t[n++]=i:(t[n++]=i>>>8,t[n++]=i&255)}}else if(ArrayBuffer.isView(e))t=e.slice(),n=t.byteLength;else throw Error(`Invalid data format, must be a string or TypedArray.`);let r=n>>2,i=n-r*4,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e<r;e++)e&1?(o=a[e],o=o*u&gt|o*f&_t,o=o<<15|o>>>17,o=o*d&gt|o*p&_t,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(s=a[e],s=s*u&gt|s*f&_t,s=s<<15|s>>>17,s=s*d&gt|s*p&_t,l^=s,l=l<<13|l>>>19,l=l*5+3864292196);switch(o=0,i){case 3:o^=t[r*4+2]<<16;case 2:o^=t[r*4+1]<<8;case 1:o^=t[r*4],o=o*u&gt|o*f&_t,o=o<<15|o>>>17,o=o*d&gt|o*p&_t,r&1?c^=o:l^=o}this.h1=c,this.h2=l}hexdigest(){let e=this.h1,t=this.h2;return e^=t>>>1,e=e*3981806797&gt|e*36045&_t,t=t*4283543511&gt|((t<<16|e>>>16)*2950163797&gt)>>>16,e^=t>>>1,e=e*444984403&gt|e*60499&_t,t=t*3301882366&gt|((t<<16|e>>>16)*3120437893&gt)>>>16,e^=t>>>1,(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}},yt=Object.freeze({map:null,hash:``,transfer:void 0}),bt=class{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);t!==void 0&&(t instanceof K&&this.#n.delete(t.annotationElementId),this.#r.delete(e),this.#r.size===0&&this.resetModified(),!this.#r.values().some(e=>e instanceof K)&&this.onAnnotationEditor?.(null))}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0)for(let[e,i]of Object.entries(t))n[e]!==i&&(r=!0,n[e]=i);else r=!0,this.#r.set(e,t);r&&this.#i(),t instanceof K&&((this.#n||=new Map).set(t.annotationElementId,t),this.onAnnotationEditor?.(t.constructor._type))}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){this.#e||(this.#e=!0,this.onSetModified?.())}resetModified(){this.#e&&(this.#e=!1,this.onResetModified?.())}get print(){return new xt(this)}get serializable(){if(this.#r.size===0)return yt;let e=new Map,t=new vt,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof K?a.serialize(!1,r):a;a.page&&(a.pageIndex=a.page._pageIndex,delete a.page),o&&(e.set(n,o),t.update(`${n}:${JSON.stringify(o)}`),i||=!!o.bitmap)}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:yt}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof K)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.getOrInsertComputed(o,()=>Object.getPrototypeOf(i).constructor),e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,Se);n.set(t,(n.get(t)??0)+1)}}if((r>0||n>0)&&(e||=Object.create(null),e.comments={deleted:r,edited:n}),!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);return n?(n.updateFromAnnotationLayer(t),!0):!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new vt;n.update(e.join(`,`)),t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}},xt=class extends bt{#e=yt;constructor(e){super();let{serializable:t}=e;if(t===yt)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){F(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return L(this,`modifiedIds`,{ids:new Set,hash:``})}},St=`__forcedDependency`,{floor:Ct,ceil:wt}=Math;function Tt(e,t,n,r,i,a){e[t*4+0]=Math.min(e[t*4+0],n),e[t*4+1]=Math.min(e[t*4+1],r),e[t*4+2]=Math.max(e[t*4+2],i),e[t*4+3]=Math.max(e[t*4+3],a)}function Et(e,t,n,r,i){let a;e?(e<0&&(a=i[0],i[0]=i[2],i[2]=a),i[0]*=e,i[2]*=e,t<0&&(a=i[1],i[1]=i[3],i[3]=a),i[1]*=t,i[3]*=t):i.fill(0),i[0]+=n,i[1]+=r,i[2]+=n,i[3]+=r}var Dt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0],Ot=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===Dt}minX(e){return this.#t[e*4+0]/256}minY(e){return this.#t[e*4+1]/256}maxX(e){return(this.#t[e*4+2]+1)/256}maxY(e){return(this.#t[e*4+3]+1)/256}},kt=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1})),At=class{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(p);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width,this.#i=e.height,this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(e*4);this.#a=new Uint8ClampedArray(n),this.#o=new Uint32Array(n),t&&t.length>0?(this.#o.set(t),this.#o.fill(Dt,t.length)):this.#o.fill(Dt)}get clipBox(){return this.#t}save(e){return this.#t={__proto__:this.#t},this._savesStack.push(e),this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();return r!==void 0&&(t?.(r,e),this.#o[e]=this.#o[r]),this}recordOpenMarker(e){return this._savesStack.push(e),this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}beginMarkedContent(e){return this._markedContentStack.push(e),this}endMarkedContent(e,t){let n=this._markedContentStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}pushBaseTransform(e){return this.#e.push(z.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform())),this}popBaseTransform(){return this.#e.length>1&&this.#e.pop(),this}resetBBox(e){return this._pendingBBoxIdx!==e&&(this._pendingBBoxIdx=e,this.#n.set(p,0)),this}recordClipBox(e,t,n,r,i,a){let o=z.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),s=p.slice();z.axialAlignedBoundingBox([n,i,r,a],o,s);let c=z.intersect(this.#t,s);return c?(this.#t[0]=c[0],this.#t[1]=c[1],this.#t[2]=c[2],this.#t[3]=c[3]):(this.#t[0]=this.#t[1]=1/0,this.#t[2]=this.#t[3]=-1/0),this}recordBBox(e,t,n,r,i,a){let o=this.#t;if(o[0]===1/0)return this;let s=z.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(o[0]===-1/0)return z.axialAlignedBoundingBox([n,i,r,a],s,this.#n),this;let c=p.slice();return z.axialAlignedBoundingBox([n,i,r,a],s,c),this.#n[0]=V(c[0],o[0],this.#n[0]),this.#n[1]=V(c[1],o[1],this.#n[1]),this.#n[2]=V(c[2],this.#n[2],o[2]),this.#n[3]=V(c[3],this.#n[3],o[3]),this}recordFullPageBBox(e){return this.#n[0]=Math.max(0,this.#t[0]),this.#n[1]=Math.max(0,this.#t[1]),this.#n[2]=Math.min(this.#r,this.#t[2]),this.#n[3]=Math.min(this.#i,this.#t[3]),this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=Ct(this.#n[0]*256/this.#r),i=Ct(this.#n[1]*256/this.#i),a=wt(this.#n[2]*256/this.#r),o=wt(this.#n[3]*256/this.#i);if(Tt(this.#a,e,r,i,a,o),n)for(let t of n)for(let n of t)n!==e&&Tt(this.#a,n,r,i,a,o);return t||(this._pendingBBoxIdx=-1),this}bboxToClipBoxDropOperation(e){return this._pendingBBoxIdx===e&&(this._pendingBBoxIdx=-1,this.#t[0]=Math.max(this.#t[0],this.#n[0]),this.#t[1]=Math.max(this.#t[1],this.#n[1]),this.#t[2]=Math.min(this.#t[2],this.#n[2]),this.#t[3]=Math.min(this.#t[3],this.#n[3])),this}take(){return new Ot(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}},jt=class{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[St]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e,t&&(this.#a=new Map,this.#o=(e,t)=>{kt(this.#a,t).dependencies.add(e)})}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){return this.#e={__proto__:this.#e},this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[St]:{__proto__:this.#t[St]}},this.#s.save(e),this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);return t===null?this:(this.#e=t,this.#t=Object.getPrototypeOf(this.#t),this)}recordOpenMarker(e){return this.#s.recordOpenMarker(e,this.#o),this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){return this.#s.recordCloseMarker(e,this.#o),this}beginMarkedContent(e){return this.#s.beginMarkedContent(e),this}endMarkedContent(e){return this.#s.endMarkedContent(e,this.#o),this}pushBaseTransform(e){return this.#s.pushBaseTransform(e),this}popBaseTransform(){return this.#s.popBaseTransform(),this}recordSimpleData(e,t){return this.#e[e]=t,this}recordIncrementalData(e,t){return this.#t[e].push(t),this}resetIncrementalData(e,t){return this.#t[e].length=0,this}recordNamedData(e,t){return this.#n.set(e,t),this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){return this.recordIncrementalData(St,t),this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(St,e);return this}resetBBox(e){return this.#s.resetBBox(e),this}recordClipBox(e,t,n,r,i,a){return this.#s.recordClipBox(e,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#s.recordBBox(e,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s&&(c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n),c!==!1&&(l=[0,0,0,0],z.axialAlignedBoundingBox(s,n.fontMatrix,l),(r!==1||i!==0||a!==0)&&Et(r,-r,i,a,l),c)))return this.recordBBox(e,t,l[0],l[2],l[1],l[3]);if(!o)return this.recordFullPageBBox(e);let u=o();return s&&l&&c===void 0&&(c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent,this.#i.set(n,c),c)?this.recordBBox(e,t,l[0],l[2],l[1],l[3]):this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){return this.#s.recordFullPageBBox(e),this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){return this.#n.has(t)&&this.#r.add(this.#n.get(t)),this}recordOperation(e,t=!1){if(this.recordDependencies(e,[St]),this.#a){let t=kt(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n),this.#s._savesStack.forEach(n.add,n),this.#s._markedContentStack.forEach(n.add,n),n.delete(e),t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]),n&&this.#r.clear(),this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t),this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.bboxToClipBoxDropOperation(e),n&&this.#r.clear(),this}take(){return this.#i.clear(),this.#s.take()}takeDebugMetadata(){return this.#a}},Mt=class e{#e;#t;#n;#r=0;#i=0;constructor(t,n,r){if(t instanceof e&&t.#n===!!r)return t;this.#e=t,this.#t=n,this.#n=!!r}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){return this.#i++,this.#e.save(this.#t),this}restore(e){return this.#i>0&&(this.#e.restore(this.#t),this.#i--),this}recordOpenMarker(e){return this.#r++,this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){return this.#r--,this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){return this.#e.pushBaseTransform(e),this}popBaseTransform(){return this.#e.popBaseTransform(),this}recordSimpleData(e,t){return this.#e.recordSimpleData(e,this.#t),this}recordIncrementalData(e,t){return this.#e.recordIncrementalData(e,this.#t),this}resetIncrementalData(e,t){return this.#e.resetIncrementalData(e,this.#t),this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this.#e.recordSimpleDataFromNamed(e,t,this.#t),this}recordFutureForcedDependency(e,t){return this.#e.recordFutureForcedDependency(e,this.#t),this}inheritSimpleDataAsFutureForcedDependencies(e){return this.#e.inheritSimpleDataAsFutureForcedDependencies(e),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#e.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(e){return this.#n||this.#e.resetBBox(this.#t),this}recordClipBox(e,t,n,r,i,a){return this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r,i,a,o){return this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o),this}recordFullPageBBox(e){return this.#n||this.#e.recordFullPageBBox(this.#t),this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){return this.#e.recordDependencies(this.#t,t),this}recordNamedDependency(e,t){return this.#e.recordNamedDependency(this.#t,t),this}recordOperation(e){return this.#e.recordOperation(this.#t,!0),this}recordShowTextOperation(e){return this.#e.recordShowTextOperation(this.#t,!0),this}bboxToClipBoxDropOperation(e){return this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0),this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}},Nt={stroke:[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],fill:[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],imageXObject:[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],rawFillPath:[`filter`,`fillColor`,`fillAlpha`],showText:[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],transform:[`transform`],transformAndFill:[`transform`,`fillColor`]},Pt=class e{#e;#t;#n=4;#r=0;#i=new e.#a(this.#n*6);static#a=R.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width,this.#t=e.height}record(t,n,r,i){if(this.#r===this.#n){this.#n*=2;let t=new e.#a(this.#n*6);t.set(this.#i),this.#i=t}let a=W(t),o;if(i[0]!==1/0){let e=p.slice();z.axialAlignedBoundingBox([0,-r,n,0],a,e);let t=z.intersect(i,e);if(!t)return;let[s,c,l,u]=t;if(s!==e[0]||c!==e[1]||l!==e[2]||u!==e[3]){let e=Math.atan2(a[1],a[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)o=[s,c,s,u,l,c];else{let e=l-s,r=u-c,i=t*t,a=n*n,d=n*t,f=a-i,p=(r*a-e*d)/f;o=[s+(r*d-e*i)/f,c,s,c+p,l,u-p]}}}o||(o=[0,-r,0,0,n,-r],z.applyTransform(o,a,0),z.applyTransform(o,a,2),z.applyTransform(o,a,4)),o[0]/=this.#e,o[1]/=this.#t,o[2]/=this.#e,o[3]/=this.#t,o[4]/=this.#e,o[5]/=this.#t,this.#i.set(o,this.#r*6),this.#r++}take(){return this.#i.subarray(0,this.#r*6)}},Ft=class{#e=new Set;#t=null;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e),this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e),this._document.fonts.delete(e)}insertRule(e){let t=this.#n();t.insertRule(e,t.cssRules.length)}#n(){if(this.#t)return this.#t;let e=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&e){let{adoptedStyleSheets:t}=this._document;if(t){let n=new e;return t.push(n),this.#t=n}}return this.styleElement||(this.styleElement=this._document.createElement(`style`),this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)),this.#t=this.styleElement.sheet}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);if(this.nativeFontFaces.clear(),this.#e.clear(),this.#t){let{adoptedStyleSheets:e}=this._document;e?.includes(this.#t)&&(this._document.adoptedStyleSheets=e.filter(e=>e!==this.#t)),this.#t=null}this.styleElement&&=(this.styleElement.remove(),null)}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(!(!e||this.#e.has(e.loadedName))){if(I(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load(),this.#e.add(t),n?.(e)}catch{P(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(a)}return}F(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;if(e.attached=!0,e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){throw P(`Failed to load font '${t.family}': '${n}'.`),e.disableFontFace=!0,n}}return}let t=e.createFontFaceRule();if(t){if(this.insertRule(t),this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){let e=!!this._document?.fonts;return L(this,`isFontLoadingAPISupported`,e)}get isSyncFontLoadingSupported(){return L(this,`isSyncFontLoadingSupported`,f||R.platform.isFirefox)}_queueLoadingCallback(e){function t(){for(I(!r.done,`completeRequest() cannot be called twice.`),r.done=!0;n.length>0&&n[0].done;){let e=n.shift();setTimeout(e.callback,0)}}let{loadingRequests:n}=this,r={done:!1,complete:t,callback:e};return n.push(r),r}get _loadTestFont(){let e=atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`);return L(this,`_loadTestFont`,e)}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|e.charCodeAt(t+3)&255}function r(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,e&255)}function i(e,t,n,r){let i=e.substring(0,t),a=e.substring(t+n);return i+r+a}let a,o,s=this._document.createElement(`canvas`);s.width=1,s.height=1;let c=s.getContext(`2d`),l=0;function u(e,t){if(++l>30){P(`Load test font never loaded.`),t();return}if(c.font=`30px `+e,c.fillText(`.`,0,20),c.getImageData(0,0,1,1).data[3]>0){t();return}setTimeout(u.bind(null,e,t))}let d=`lt${Date.now()}${this.loadTestFontId++}`,f=this._loadTestFont;f=i(f,976,d.length,d);let p=1482184792,m=n(f,16);for(a=0,o=d.length-3;a<o;a+=4)m=m-p+n(d,a)|0;a<d.length&&(m=m-p+n(d+`XXX`,a)|0),f=i(f,16,4,r(m));let h=`@font-face {font-family:"${d}";src:${`url(data:font/opentype;base64,${btoa(f)});`}}`;this.insertRule(h);let g=this._document.createElement(`div`);g.style.visibility=`hidden`,g.style.width=g.style.height=`10px`,g.style.position=`absolute`,g.style.top=g.style.left=`0px`;for(let t of[e.loadedName,d]){let e=this._document.createElement(`span`);e.textContent=`Hi`,e.style.fontFamily=t,g.append(e)}this._document.body.append(g),u(d,()=>{g.remove(),t.complete()})}},It=class{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e,this._inspectFont=t,n&&(this.charProcOperatorList=n),r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(!this.cssFontInfo)e=new FontFace(this.loadedName,this.data,{});else{let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`),e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}return this._inspectFont?.(this),e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(!this.cssFontInfo)t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;else{let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}return this._inspectFont?.(this,e),t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){P(`getPathGenerator - ignoring character: "${e}".`)}let i=et(r?.path);return this.fontExtraProperties||e.delete(n),this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){L(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}},Lt=class{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]},Rt=class{static strings=[`css`,`loadedName`,`baseFontName`,`src`]},zt=class{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(this.bools.length*2/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+this.numbers.length*8;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6},Bt=class{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16},Vt=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}#r(e){I(e<Lt.strings.length,`Invalid string index`);let t=0;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fontFamily(){return this.#r(0)}get fontWeight(){return this.#r(1)}get italicAngle(){return this.#r(2)}},Ht=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}get guessFallback(){return this.#n.getUint8(0)!==0}#r(e){I(e<Rt.strings.length,`Invalid string index`);let t=5;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get css(){return this.#r(0)}get loadedName(){return this.#r(1)}get baseFontName(){return this.#r(2)}get src(){return this.#r(3)}get style(){let e=1;e+=4+this.#n.getUint32(e);let t=this.#n.getUint32(e),n=this.#t.decode(new Uint8Array(this.#e,e+4,t));e+=4+t;let r=this.#n.getUint32(e);return{style:n,weight:this.#t.decode(new Uint8Array(this.#e,e+4,r))}}},Ut=class{#e;#t=new TextDecoder;#n;constructor({buffer:e,extra:t}){this.#e=e,this.#n=new DataView(e),t&&Object.assign(this,t)}#r(e){I(e<zt.bools.length,`Invalid boolean index`);let t=Math.floor(e/4),n=e*2%8,r=this.#n.getUint8(t)>>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){return I(e<zt.numbers.length,`Invalid number index`),this.#n.getFloat64(zt.OFFSET_NUMBERS+e*8)}get ascent(){return this.#i(0)}get defaultWidth(){return this.#i(1)}get descent(){return this.#i(2)}#a(e,t,n,r){let i=this.#n.getUint8(e);if(i===0)return;I(i===t,`Invalid array length.`),e+=1;let a=Array(i);for(let t=0;t<i;t++)a[t]=this.#n[n](e,!0),e+=r;return a}get bbox(){return this.#a(zt.OFFSET_BBOX,4,`getInt16`,2)}get fontMatrix(){return this.#a(zt.OFFSET_FONT_MATRIX,6,`getFloat64`,8)}get defaultVMetrics(){return this.#a(zt.OFFSET_DEFAULT_VMETRICS,3,`getInt16`,2)}#o(e){I(e<zt.strings.length,`Invalid string index`);let t=zt.OFFSET_STRINGS+4;for(let n=0;n<e;n++)t+=this.#n.getUint32(t)+4;let n=this.#n.getUint32(t);return this.#t.decode(new Uint8Array(this.#e,t+4,n))}get fallbackName(){return this.#o(0)}get loadedName(){return this.#o(1)}get mimetype(){return this.#o(2)}get name(){return this.#o(3)}#s(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);e+=4+n;let r=this.#n.getUint32(e);e+=4+r;let i=this.#n.getUint32(e);return{offset:e,length:i}}get data(){let{offset:e,length:t}=this.#s();return t===0?void 0:new Uint8Array(this.#e,e+4,t)}clearData(){let{offset:e,length:t}=this.#s();t!==0&&(this.#n.setUint32(e,0),this.#e=new Uint8Array(this.#e,0,e+4).slice().buffer,this.#n=new DataView(this.#e))}get cssFontInfo(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);e+=4+n;let r=this.#n.getUint32(e);if(r===0)return null;let i=new Uint8Array(r);return i.set(new Uint8Array(this.#e,e+4,r)),new Vt(i.buffer)}get systemFontInfo(){let e=zt.OFFSET_STRINGS,t=this.#n.getUint32(e);e+=4+t;let n=this.#n.getUint32(e);if(n===0)return null;let r=new Uint8Array(n);return r.set(new Uint8Array(this.#e,e+4,n)),new Ht(r.buffer)}},Wt=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.data=new Uint8Array(e)}getIR(){let e=this.view,t=this.data[Bt.KIND],n=!!this.data[Bt.HAS_BBOX],r=!!this.data[Bt.HAS_BACKGROUND],i=e.getUint32(Bt.N_COORD,!0),a=e.getUint32(Bt.N_COLOR,!0),o=e.getUint32(Bt.N_STOP,!0),s=20,c=new Float32Array(this.buffer,s,i*2);s+=i*8;let l=new Uint8Array(this.buffer,s,a*4);s+=a*4;let u=[];for(let t=0;t<o;++t){let t=e.getFloat32(s,!0);s+=4;let n=e.getUint32(s,!0);s+=4,u.push([t,`#${n.toString(16).padStart(6,`0`)}`])}let d=null;if(n){d=[];for(let t=0;t<4;++t)d.push(e.getFloat32(s,!0)),s+=4}let f=null;if(r&&(f=new Uint8Array(this.buffer,s,3),s+=3),t===1)return[`RadialAxial`,`axial`,d,u,Array.from(c.slice(0,2)),Array.from(c.slice(2,4)),null,null];if(t===2)return[`RadialAxial`,`radial`,d,u,[c[0],c[1]],[c[3],c[4]],c[2],c[5]];if(t===3){let e=this.data[Bt.SHADING_TYPE],t=null;if(c.length>0){t=p.slice();for(let e=0,n=c.length;e<n;e+=2)z.pointBoundingBox(c[e],c[e+1],t)}return[`Mesh`,e,c,l,i,t,d,f]}throw Error(`Unsupported pattern kind: ${t}`)}},Gt=class{#e;constructor(e){this.#e=e}get path(){return R.isFloat16ArraySupported?new Float16Array(this.#e):new Float32Array(this.#e)}};function Kt(e){if(e instanceof URL)return e;if(typeof e==`string`){if(f){if(/^[a-z][a-z0-9\-+.]+:/i.test(e))return new URL(e);let t=process.getBuiltinModule(`url`);return new URL(t.pathToFileURL(e))}let t=URL.parse(e,window.location);if(t)return t}throw Error(`Invalid PDF url data: either string or URL-object is expected in the url property.`)}function qt(e){if(f&&typeof Buffer<`u`&&e instanceof Buffer)throw Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength)return e;if(typeof e==`string`)return he(e);if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof e==`object`&&!isNaN(e?.length))return new Uint8Array(e);throw Error(`Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.`)}function Jt(e){if(typeof e!=`string`)return null;if(e.endsWith(`/`))return e;throw Error(`Invalid factory url: "${e}" must include trailing slash.`)}var Yt=e=>typeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0,Xt=be.bind(null,Yt,e=>typeof e==`object`&&typeof e?.name==`string`),Zt=class{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){P("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a),i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.(),this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}},Qt={DATA:1,ERROR:2},q={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function $t(){}function J(e){if(e instanceof pe||e instanceof ue||e instanceof ce||e instanceof de||e instanceof le)return e;switch(e instanceof Error||typeof e==`object`&&e||F(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`),e.name){case`AbortException`:return new pe(e.message);case`InvalidPDFException`:return new ue(e.message);case`PasswordException`:return new ce(e.message,e.code);case`ResponseException`:return new de(e.message,e.status,e.missing);case`UnknownErrorException`:return new le(e.message,e.details)}return new le(e.message,e.toString())}var en=class{#e=new AbortController;constructor(e,t,n){this.sourceName=e,this.targetName=t,this.comObj=n,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);if(delete this.callbackCapabilities[t],e.callback===Qt.DATA)n.resolve(e.data);else if(e.callback===Qt.ERROR)n.reject(J(e.reason));else throw Error(`Unexpected callback case`);return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:Qt.DATA,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:Qt.ERROR,callbackId:e.callbackId,reason:J(t)})});return}if(e.streamId){this.#n(e);return}t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();return this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1},s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r),c.promise},pull:e=>{let t=Promise.withResolvers();return this.streamControllers[i].pullCall=t,s.postMessage({sourceName:a,targetName:o,stream:q.PULL,streamId:i,desiredSize:e.desiredSize}),t.promise},cancel:e=>{I(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();return this.streamControllers[i].cancelCall=t,this.streamControllers[i].isClosed=!0,s.postMessage({sourceName:a,targetName:o,stream:q.CANCEL,streamId:i,reason:J(e)}),t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a,s>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),i.postMessage({sourceName:n,targetName:r,stream:q.ENQUEUE,streamId:t,chunk:e},o)},close(){this.isCancelled||(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.CLOSE,streamId:t}),delete a.streamSinks[t])},error(e){I(e instanceof Error,`error must have a valid reason`),!this.isCancelled&&(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.ERROR,streamId:t,reason:J(e)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve(),s.ready=s.sinkCapability.promise,this.streamSinks[t]=s,Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,reason:J(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case q.START_COMPLETE:e.success?a.startCall.resolve():a.startCall.reject(J(e.reason));break;case q.PULL_COMPLETE:e.success?a.pullCall.resolve():a.pullCall.reject(J(e.reason));break;case q.PULL:if(!o){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=e.desiredSize,Promise.try(o.onPull||$t).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,reason:J(e)})});break;case q.ENQUEUE:if(I(a,`enqueue should have stream controller`),a.isClosed)break;a.controller.enqueue(e.chunk);break;case q.CLOSE:if(I(a,`close should have stream controller`),a.isClosed)break;a.isClosed=!0,a.controller.close(),this.#i(a,t);break;case q.ERROR:I(a,`error should have stream controller`),a.controller.error(J(e.reason)),this.#i(a,t);break;case q.CANCEL_COMPLETE:e.success?a.cancelCall.resolve():a.cancelCall.reject(J(e.reason)),this.#i(a,t);break;case q.CANCEL:if(!o)break;let s=J(e.reason);Promise.try(o.onCancel||$t,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,reason:J(e)})}),o.sinkCapability.reject(s),o.isCancelled=!0,delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]),delete this.streamControllers[t]}destroy(){this.#e?.abort(),this.#e=null}},tn=class{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e,this.standardFontDataUrl=t,this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:F(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){F("Abstract method `_fetch` called.")}},nn=class extends tn{async _fetch(e,t){let n=await Oe(e,t===`cMapUrl`&&!e.endsWith(`.bcmap`)?`text`:`bytes`);return n instanceof Uint8Array?n:he(n)}},rn=class{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t,e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0,e.canvas=null,e.context=null}_createCanvas(e,t){F("Abstract method `_createCanvas` called.")}},an=class extends rn{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t}),this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);return n.width=e,n.height=t,n}},on=class{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}addSelectionHCMFilter(e,t){return`none`}addSelectionFilter(){return`none`}createSelectionStyle(e=null){return null}destroy(e=!1){}},sn=class extends on{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super(),this.#r=e,this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.colorScheme=`only light`,t.visibility=`hidden`,t.contain=`strict`,t.width=t.height=0,t.position=`absolute`,t.top=t.left=0,t.zIndex=-1;let n=this.#i.createElementNS(_,`svg`);n.setAttribute(`width`,0),n.setAttribute(`height`,0),this.#n=this.#i.createElementNS(_,`defs`),e.append(n),n.append(this.#n),this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++)i[e]=t[e]/255,a[e]=n[e]/255,o[e]=r[e]/255;return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(Ae(e)?P(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=ae(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;if(t=this.#s.get(a),t)return this.#s.set(e,t),t;let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s),this.#s.set(a,s);let c=this.#m(o);return this.#g(n,r,i,c),s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n||(i?(i.filter?.remove(),i.key=n,i.url=`none`,i.filter=null):(i={key:n,url:`none`,filter:null},this.#c.set(r,i)),!e||!t))return i.url;let a=this.#v(e);e=z.makeHexColor(...a);let o=this.#v(t);if(t=z.makeHexColor(...o),this.#l.style.color=``,e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u),this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};return this.#g(d(0,5),d(1,5),d(2,5),u),i.url=this.#d(l),i.url}addSelectionHCMFilter(e,t){return this.addHighlightHCMFilter(`selection`,e,t,`HighlightText`,`Highlight`)}addSelectionFilter(){return this.addHighlightHCMFilter(`selection_default`,`black`,`white`,`HighlightText`,`Highlight`)}createSelectionStyle(e=null){let t=e?this.addSelectionHCMFilter(e.foreground,e.background):this.addSelectionFilter();return t===`none`||!R.platform.isFirefox?null:{"backdrop-filter":t,"background-color":`transparent`}}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;if(t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#_(n,o),a}addLuminosityFilter(e){let t=this.#s.get(e||`luminosity`);if(t)return t;let n,r;if(e?([n]=this.#u([e]),r=`luminosity_${n}`):r=`luminosity`,t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#f(o),e&&this.#_(n,o),a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(_,`feComponentTransfer`);o.append(s);let c=this.#i.createElementNS(_,`feFuncA`);return c.setAttribute(`type`,`linear`),c.setAttribute(`slope`,`${t}`),c.setAttribute(`intercept`,`0`),s.append(c),a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a||(o?(o.filter?.remove(),o.key=a,o.url=`none`,o.filter=null):(o={key:a,url:`none`,filter:null},this.#c.set(e,o)),!t||!n))return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#b.bind(this));u<l&&([l,u,d,f]=[u,l,f,d]),this.#l.style.color=``;let p=(e,t,n)=>{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);return this.#p(h),this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h),o.url=this.#d(m),o.url}destroy(e=!1){e&&this.#a?.size||(this.#n?.parentNode.parentNode.remove(),this.#n=null,this.#t?.clear(),this.#t=null,this.#a?.clear(),this.#a=null,this.#o=0)}#f(e){let t=this.#i.createElementNS(_,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`),e.append(t)}#p(e){let t=this.#i.createElementNS(_,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`),e.append(t)}#m(e){let t=this.#i.createElementNS(_,`filter`);return t.setAttribute(`color-interpolation-filters`,`sRGB`),t.setAttribute(`id`,e),this.#l.append(t),t}#h(e,t,n){let r=this.#i.createElementNS(_,t);r.setAttribute(`type`,`discrete`),r.setAttribute(`tableValues`,n),e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(_,`feComponentTransfer`);r.append(i),this.#h(i,`feFuncR`,e),this.#h(i,`feFuncG`,t),this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(_,`feComponentTransfer`);t.append(n),this.#h(n,`feFuncA`,e)}#v(e){return this.#l.style.color=e,Re(getComputedStyle(this.#l).getPropertyValue(`color`))}#y(e){return this.#l.style.color=e,Le(getComputedStyle(this.#l).getPropertyValue(`color`))}#b(e){let[t,n,r,i]=this.#y(e);if(i===1)return[t,n,r];let[a,o,s]=this.#v(`Canvas`);return[cn(t,a,i),cn(n,o,i),cn(r,s,i)]}};function cn(e,t,n){return Math.round(n*e+(1-n)*t)}f&&P("Please use the `legacy` build in Node.js environments.");async function ln(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}var un=class extends on{},dn=class extends rn{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire({}.url)(`@napi-rs/canvas`).createCanvas(e,t)}},fn=class extends tn{async _fetch(e,t){return ln(e)}};function pn({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=R.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=r&7,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r<i;++r){for(let r=t+u;t<r;++t,m+=8){let r=e[t];n[m]=c^-(r>>7&1)&f,n[m+1]=c^-(r>>6&1)&f,n[m+2]=c^-(r>>5&1)&f,n[m+3]=c^-(r>>4&1)&f,n[m+4]=c^-(r>>3&1)&f,n[m+5]=c^-(r>>2&1)&f,n[m+6]=c^-(r>>1&1)&f,n[m+7]=c^-(r&1)&f}if(d===0)continue;let r=t<p?e[t++]:255;for(let e=0;e<d;++e,++m)n[m]=c^-(r>>7-e&1)&f}return{srcPos:t,destPos:m}}function mn({src:e,srcPos:t=0,dest:n,destPos:r=0,width:i,height:a}){let o=0,s=i*a*3,c=s>>2,l=new Uint32Array(e.buffer,t,c),u=R.isLittleEndian?4278190080:255;if(R.isLittleEndian){for(;o<c-2;o+=3,r+=4){let e=l[o],t=l[o+1],i=l[o+2];n[r]=e|u,n[r+1]=e>>>24|t<<8|u,n[r+2]=t>>>16|i<<16|u,n[r+3]=i>>>8|u}for(let i=o*4,a=t+s;i<a;i+=3)n[r++]=e[i]|e[i+1]<<8|e[i+2]<<16|u}else{for(;o<c-2;o+=3,r+=4){let e=l[o],t=l[o+1],i=l[o+2];n[r]=e|u,n[r+1]=e<<24|t>>>8|u,n[r+2]=t<<16|i>>>16|u,n[r+3]=i<<8|u}for(let i=o*4,a=t+s;i<a;i+=3)n[r++]=e[i]<<24|e[i+1]<<16|e[i+2]<<8|u}return{srcPos:t+s,destPos:r}}var hn=`
2
2
  struct Uniforms {
3
3
  offsetX : f32,
4
4
  offsetY : f32,
@@ -41,28 +41,28 @@ fn vs_main(in : VertexInput) -> VertexOutput {
41
41
  fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
42
42
  return vec4<f32>(in.color, 1.0);
43
43
  }
44
- `,gn=new class{#e=null;#t=null;#n=null;#r=null;async#i(){if(!globalThis.navigator?.gpu)return!1;try{let e=await navigator.gpu.requestAdapter();return e?(this.#r=navigator.gpu.getPreferredCanvasFormat(),this.#t=await e.requestDevice(),!0):!1}catch{return!1}}init(){return this.#e||=this.#i()}get isReady(){return this.#t!==null}loadMeshShader(){if(!this.#t||this.#n)return;let e=this.#t.createShaderModule({code:hn});this.#n=this.#t.createRenderPipeline({layout:`auto`,vertex:{module:e,entryPoint:`vs_main`,buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:`unorm8x4`}]}]},fragment:{module:e,entryPoint:`fs_main`,targets:[{format:this.#r}]},primitive:{topology:`triangle-list`}})}draw(e,t,n,r,i,a,o,s){this.loadMeshShader();let c=this.#t,{offsetX:l,offsetY:u,scaleX:d,scaleY:f}=r,p=c.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&c.queue.writeBuffer(p,0,e);let m=c.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&c.queue.writeBuffer(m,0,t);let h=c.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});c.queue.writeBuffer(h,0,new Float32Array([l,u,d,f,a,o,s,0]));let g=c.createBindGroup({layout:this.#n.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:h}}]}),_=new OffscreenCanvas(a,o),v=_.getContext(`webgpu`);v.configure({device:c,format:this.#r,alphaMode:i?`opaque`:`premultiplied`});let y=i?{r:i[0]/255,g:i[1]/255,b:i[2]/255,a:1}:{r:0,g:0,b:0,a:0},b=c.createCommandEncoder(),x=b.beginRenderPass({colorAttachments:[{view:v.getCurrentTexture().createView(),clearValue:y,loadOp:`clear`,storeOp:`store`}]});return n>0&&(x.setPipeline(this.#n),x.setBindGroup(0,g),x.setVertexBuffer(0,p),x.setVertexBuffer(1,m),x.draw(n)),x.end(),c.queue.submit([b.finish()]),p.destroy(),m.destroy(),h.destroy(),_.transferToImageBitmap()}};function _n(){return gn.init()}function vn(){return gn.isReady}function yn(){gn.loadMeshShader()}function bn(e,t,n,r,i,a,o,s){return gn.draw(e,t,n,r,i,a,o,s)}var Y={FILL:`Fill`,STROKE:`Stroke`,SHADING:`Shading`};function xn(e,t){if(!t)return;let n=t[2]-t[0],r=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],n,r),e.clip(i)}var Sn=class{isModifyingCurrentTransform(){return!1}getPattern(){P("Abstract method `getPattern` called.")}},Cn=class extends Sn{constructor(e){super(),this._type=e[1],this._bbox=e[2],this._colorStops=e[3],this._p0=e[4],this._p1=e[5],this._r0=e[6],this._r1=e[7],this.matrix=null}isOriginBased(){return this._p0[0]===0&&this._p0[1]===0&&(!this.isRadial()||this._p1[0]===0&&this._p1[1]===0)}isRadial(){return this._type===`radial`}areConic(){if(!this.isRadial())return!1;let e=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return e+this._r1>this._r0&&e+this._r0>this._r1}_createGradient(e,t=null){let n,r=this._p0,i=this._p1;if(t&&(r=r.slice(),i=i.slice(),R.applyTransform(r,t),R.applyTransform(i,t)),this._type===`axial`)n=e.createLinearGradient(r[0],r[1],i[0],i[1]);else if(this._type===`radial`){let a=this._r0,o=this._r1;if(t){let e=new Float32Array(2);R.singularValueDecompose2dScale(t,e),a*=e[0],o*=e[0]}n=e.createRadialGradient(r[0],r[1],a,i[0],i[1],o)}for(let e of this._colorStops)n.addColorStop(e[0],e[1]);return n}_createReversedGradient(e,t=null){let n=this._p1,r=this._p0;t&&(n=n.slice(),r=r.slice(),R.applyTransform(n,t),R.applyTransform(r,t));let i=this._r1,a=this._r0;if(t){let e=new Float32Array(2);R.singularValueDecompose2dScale(t,e),i*=e[0],a*=e[0]}let o=e.createRadialGradient(n[0],n[1],i,r[0],r[1],a),s=this._colorStops.map(([e,t])=>[1-e,t]).reverse();for(let[e,t]of s)o.addColorStop(e,t);return o}getPattern(e,t,n,r){let i;if(r===Y.STROKE||r===Y.FILL){if(this.isOriginBased()){let r=R.transform(n,t.baseTransform);this.matrix&&(r=R.transform(r,this.matrix));let i=.001,a=Math.hypot(r[0],r[1]),o=Math.hypot(r[2],r[3]),s=(r[0]*r[2]+r[1]*r[3])/(a*o);if(Math.abs(s)<i)if(this.isRadial()){if(Math.abs(a-o)<i)return this._createGradient(e,r)}else return this._createGradient(e,r)}let a=t.current.getClippedPathBoundingBox(r,W(e))||[0,0,0,0],o=Math.ceil(a[2]-a[0])||1,s=Math.ceil(a[3]-a[1])||1,c=t.canvasFactory.create(o,s),l=c.context;l.clearRect(0,0,l.canvas.width,l.canvas.height),l.beginPath(),l.rect(0,0,l.canvas.width,l.canvas.height),l.translate(-a[0],-a[1]),n=R.transform(n,[1,0,0,1,a[0],a[1]]),l.transform(...t.baseTransform),this.matrix&&l.transform(...this.matrix),xn(l,this._bbox),this.areConic()&&(l.fillStyle=this._createReversedGradient(l),l.fill()),l.fillStyle=this._createGradient(l),l.fill(),i=e.createPattern(c.canvas,`no-repeat`),t.canvasFactory.destroy(c);let u=new DOMMatrix(n);i.setTransform(u)}else this.areConic()&&(e.save(),xn(e,this._bbox),e.fillStyle=this._createReversedGradient(e),e.fillRect(-1e10,-1e10,2e10,2e10),e.restore()),xn(e,this._bbox),i=this._createGradient(e);return i}};function wn(e,t,n,r,i,a,o,s){let c=t.coords,l=t.colors,u=e.data,d=e.width*4,f;c[n*2+1]>c[r*2+1]&&(f=n,n=r,r=f,f=a,a=o,o=f),c[r*2+1]>c[i*2+1]&&(f=r,r=i,i=f,f=o,o=s,s=f),c[n*2+1]>c[r*2+1]&&(f=n,n=r,r=f,f=a,a=o,o=f);let p=(c[n*2]+t.offsetX)*t.scaleX,m=(c[n*2+1]+t.offsetY)*t.scaleY,h=(c[r*2]+t.offsetX)*t.scaleX,g=(c[r*2+1]+t.offsetY)*t.scaleY,_=(c[i*2]+t.offsetX)*t.scaleX,v=(c[i*2+1]+t.offsetY)*t.scaleY;if(m>=v)return;let y=l[a*4],b=l[a*4+1],x=l[a*4+2],S=l[o*4],C=l[o*4+1],w=l[o*4+2],T=l[s*4],E=l[s*4+1],D=l[s*4+2],O=Math.round(m),k=Math.round(v),A,j,M,ee,te,ne,re,N;for(let e=O;e<=k;e++){if(e<g){let t=e<m?0:(m-e)/(m-g);A=p-(p-h)*t,j=y-(y-S)*t,M=b-(b-C)*t,ee=x-(x-w)*t}else{let t;t=e>v?1:g===v?0:(g-e)/(g-v),A=h-(h-_)*t,j=S-(S-T)*t,M=C-(C-E)*t,ee=w-(w-D)*t}let t;t=e<m?0:e>v?1:(m-e)/(m-v),te=p-(p-_)*t,ne=y-(y-T)*t,re=b-(b-E)*t,N=x-(x-D)*t;let n=Math.round(Math.min(A,te)),r=Math.round(Math.max(A,te)),i=d*e+n*4;for(let e=n;e<=r;e++)t=(A-e)/(A-te),t<0?t=0:t>1&&(t=1),u[i++]=j-(j-ne)*t|0,u[i++]=M-(M-re)*t|0,u[i++]=ee-(ee-N)*t|0,u[i++]=255}}var Tn=class extends Sn{constructor(e){super(),this._posData=e[2],this._colData=e[3],this._vertexCount=e[4],this._bounds=e[5],this._bbox=e[6],this._background=e[7],this.matrix=null,yn()}_createMeshCanvas(e,t,n){let r=1.1,i=3e3,a=Math.floor(this._bounds[0]),o=Math.floor(this._bounds[1]),s=Math.ceil(this._bounds[2])-a,c=Math.ceil(this._bounds[3])-o,l=Math.min(Math.ceil(Math.abs(s*e[0]*r)),i)||1,u=Math.min(Math.ceil(Math.abs(c*e[1]*r)),i)||1,d=s?s/l:1,f=c?c/u:1,p={coords:this._posData,colors:this._colData,offsetX:-a,offsetY:-o,scaleX:1/d,scaleY:1/f},m=l+4,h=u+4,g=n.create(m,h);if(vn()&&this._vertexCount>48)g.context.drawImage(bn(this._posData,this._colData,this._vertexCount,p,t,m,h,2),0,0);else{let e=g.context.createImageData(l,u);if(t){let n=e.data;for(let e=0,r=n.length;e<r;e+=4)n[e]=t[0],n[e+1]=t[1],n[e+2]=t[2],n[e+3]=255}for(let t=0,n=this._vertexCount;t<n;t+=3)wn(e,p,t,t+1,t+2,t,t+1,t+2);g.context.putImageData(e,2,2)}return{canvas:g.canvas,offsetX:a-2*d,offsetY:o-2*f,scaleX:d,scaleY:f}}isModifyingCurrentTransform(){return!0}getPattern(e,t,n,r){xn(e,this._bbox);let i=new Float32Array(2);if(r===Y.SHADING)R.singularValueDecompose2dScale(W(e),i);else if(this.matrix){R.singularValueDecompose2dScale(this.matrix,i);let[e,n]=i;R.singularValueDecompose2dScale(t.baseTransform,i),i[0]*=e,i[1]*=n}else R.singularValueDecompose2dScale(t.baseTransform,i);let a=this._createMeshCanvas(i,r===Y.SHADING?null:this._background,t.canvasFactory);r!==Y.SHADING&&(e.setTransform(...t.baseTransform),this.matrix&&e.transform(...this.matrix)),e.translate(a.offsetX,a.offsetY),e.scale(a.scaleX,a.scaleY);let o=e.createPattern(a.canvas,`no-repeat`);return t.canvasFactory.destroy(a),o}},En=class extends Sn{getPattern(){return`hotpink`}};function Dn(e){switch(e[0]){case`RadialAxial`:return new Cn(e);case`Mesh`:return new Tn(e);case`Dummy`:return new En}throw Error(`Unknown IR type: ${e[0]}`)}var On={COLORED:1,UNCOLORED:2},kn=class e{static MAX_PATTERN_SIZE=3e3;constructor(e,t,n,r){this.color=e[1],this.operatorList=e[2],this.matrix=e[3],this.bbox=e[4],this.xstep=e[5],this.ystep=e[6],this.paintType=e[7],this.tilingType=e[8],this.needsIsolation=e[9]??!0,this.ctx=t,this.canvasGraphicsFactory=n,this.baseTransform=r,this.patternBaseMatrix=this.matrix?R.transform(r,this.matrix):r}canSkipPatternCanvas([e,t,n,r]){let[i,a,o,s]=this.bbox,c=Math.abs(this.xstep),l=Math.abs(this.ystep);if(e>c+1e-6||t>l+1e-6)return null;let u=Math.floor((n-o)/c)+1,d=Math.ceil((n+e-i)/c)-1,f=Math.floor((r-s)/l)+1,p=Math.ceil((r+t-a)/l)-1;return d<=u&&p<=f?[u,f]:null}updatePatternDims(e,t){let n=R.inverseTransform(this.patternBaseMatrix),r=[e[0],e[1]],i=[e[2],e[3]];R.applyTransform(r,n),R.applyTransform(i,n),t[0]=Math.abs(i[0]-r[0]),t[1]=Math.abs(i[1]-r[1]),t[2]=Math.min(r[0],i[0]),t[3]=Math.min(r[1],i[1])}_renderTileCanvas(e,t,n,r){let[i,a,o,s]=this.bbox,c=e.canvasFactory.create(n.size,r.size),l=c.context,u=this.canvasGraphicsFactory.createCanvasGraphics(l,t);return u.groupLevel=e.groupLevel,this.setFillAndStrokeStyleToContext(u,this.paintType,this.color),l.translate(-n.scale*i,-r.scale*a),u.transform(0,n.scale,0,0,r.scale,0,0),l.save(),u.dependencyTracker?.save(),this.clipBbox(u,i,a,o,s),u.baseTransform=W(u.ctx),u.executeOperatorList(this.operatorList),u.endDrawing(),u.dependencyTracker?.restore(),l.restore(),c}_getCombinedScales(){let e=new Float32Array(2);R.singularValueDecompose2dScale(this.matrix,e);let[t,n]=e;return R.singularValueDecompose2dScale(this.baseTransform,e),[t*e[0],n*e[1]]}drawPattern(e,t,n=!1,[r,i],a){let[o,s,c,l]=this.bbox,u=e.dependencyTracker;if(u&&(e.dependencyTracker=new Mt(u,a)),e.save(),n?e.ctx.clip(t,`evenodd`):e.ctx.clip(t),e.ctx.setTransform(...this.patternBaseMatrix),e.ctx.translate(r*this.xstep,i*this.ystep),this.needsIsolation||e.ctx.globalAlpha!==1||e.ctx.globalCompositeOperation!==`source-over`||e.inSMaskMode){let t=c-o,n=l-s,[r,i]=this._getCombinedScales(),u=this.getSizeAndScale(t,this.ctx.canvas.width,r),d=this.getSizeAndScale(n,this.ctx.canvas.height,i),f=this._renderTileCanvas(e,a,u,d);e.ctx.drawImage(f.canvas,o,s,t,n),e.canvasFactory.destroy(f)}else this.setFillAndStrokeStyleToContext(e,this.paintType,this.color),this.clipBbox(e,o,s,c,l),e.baseTransformStack.push(e.baseTransform),e.baseTransform=W(e.ctx),e.executeOperatorList(this.operatorList),e.baseTransform=e.baseTransformStack.pop();e.restore(),u&&(e.dependencyTracker=u)}createPatternCanvas(e,t){let[n,r,i,a]=this.bbox,o=i-n,s=a-r,{xstep:c,ystep:l}=this;c=Math.abs(c),l=Math.abs(l),re(`TilingType: `+this.tilingType);let[u,d]=this._getCombinedScales(),f=o,p=s,m=!1,h=!1;Math.ceil(c*u)>=Math.ceil(o*u)?f=c:m=!0,Math.ceil(l*d)>=Math.ceil(s*d)?p=l:h=!0;let g=this.getSizeAndScale(f,this.ctx.canvas.width,u),_=this.getSizeAndScale(p,this.ctx.canvas.height,d),v=this._renderTileCanvas(e,t,g,_);if(m||h){let t=v.canvas;m&&(f=c),h&&(p=l);let i=this.getSizeAndScale(f,this.ctx.canvas.width,u),a=this.getSizeAndScale(p,this.ctx.canvas.height,d),g=i.size,_=a.size,y=e.canvasFactory.create(g,_),b=y.context,x=m?Math.floor(o/c):0,S=h?Math.floor(s/l):0;for(let e=0;e<=x;e++)for(let n=0;n<=S;n++)b.drawImage(t,g*e,_*n,g,_,0,0,g,_);return e.canvasFactory.destroy(v),{canvas:y.canvas,canvasEntry:y,scaleX:i.scale,scaleY:a.scale,offsetX:n,offsetY:r}}return{canvas:v.canvas,canvasEntry:v,scaleX:g.scale,scaleY:_.scale,offsetX:n,offsetY:r}}getSizeAndScale(t,n,r){let i=Math.max(e.MAX_PATTERN_SIZE,n),a=Math.ceil(t*r);return a>=i?a=i:r=a/t,{scale:r,size:a}}clipBbox(e,t,n,r,i){let a=r-t,o=i-n,s=new Path2D;s.rect(t,n,a,o),R.axialAlignedBoundingBox([t,n,r,i],W(e.ctx),e.current.minMax),e.ctx.clip(s),e.current.updateClipFromPath()}setFillAndStrokeStyleToContext(e,t,n){let r=e.ctx,i=e.current;switch(i.patternFill=i.patternStroke=!1,t){case On.COLORED:let{fillStyle:e,strokeStyle:a}=this.ctx;r.fillStyle=i.fillColor=e,r.strokeStyle=i.strokeColor=a;break;case On.UNCOLORED:r.fillStyle=r.strokeStyle=n,i.fillColor=i.strokeColor=n;break;default:throw new pe(`Unsupported paint type: ${t}`)}}isModifyingCurrentTransform(){return!1}getPattern(e,t,n,r,i){let a=r===Y.SHADING?n:R.transform(n,this.patternBaseMatrix),o=this.createPatternCanvas(t,i),s=new DOMMatrix(a);s=s.translate(o.offsetX,o.offsetY),s=s.scale(1/o.scaleX,1/o.scaleY);let c=e.createPattern(o.canvas,`repeat`);return t.canvasFactory.destroy(o.canvasEntry),c.setTransform(s),c}},An=16,jn=100,Mn=15,Nn=10,X=16,Pn=new DOMMatrix,Fn=new Float32Array(2);function In(e,t){if(e._removeMirroring)throw Error(`Context is already forwarding operations.`);let n=new Map;for(let r of[`save`,`restore`,`rotate`,`scale`,`translate`,`transform`,`setTransform`,`resetTransform`,`clip`,`moveTo`,`lineTo`,`bezierCurveTo`,`quadraticCurveTo`,`arc`,`arcTo`,`ellipse`,`rect`,`roundRect`,`closePath`,`beginPath`]){let i=e[r];typeof i!=`function`||typeof t[r]!=`function`||(n.set(r,i),e[r]=function(...e){return t[r](...e),i.apply(this,e)})}e._removeMirroring=()=>{for(let[t,r]of n)e[t]=r;delete e._removeMirroring}}function Ln(e,t,n,r,i,a,o,s,c,l){let[u,d,f,p,m,h]=W(e);if(d===0&&f===0){let g=o*u+m,_=Math.round(g),v=s*p+h,y=Math.round(v),b=(o+c)*u+m,x=Math.abs(Math.round(b)-_)||1,S=(s+l)*p+h,C=Math.abs(Math.round(S)-y)||1;return e.setTransform(Math.sign(u),0,0,Math.sign(p),_,y),e.drawImage(t,n,r,i,a,0,0,x,C),e.setTransform(u,d,f,p,m,h),[x,C]}if(u===0&&p===0){let g=s*f+m,_=Math.round(g),v=o*d+h,y=Math.round(v),b=(s+l)*f+m,x=Math.abs(Math.round(b)-_)||1,S=(o+c)*d+h,C=Math.abs(Math.round(S)-y)||1;return e.setTransform(0,Math.sign(d),Math.sign(f),0,_,y),e.drawImage(t,n,r,i,a,0,0,C,x),e.setTransform(u,d,f,p,m,h),[C,x]}e.drawImage(t,n,r,i,a,o,s,c,l);let g=Math.hypot(u,d),_=Math.hypot(f,p);return[g*c,_*l]}var Rn=class{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=h;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=T.FILL;textRise=0;fillColor=`#000000`;strokeColor=`#000000`;tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps=`none`;minMax=m.slice();constructor(e,t){this.clipBox=new Float32Array([0,0,e,t])}clone(){let e=Object.create(this);return e.clipBox=this.clipBox.slice(),e.minMax=this.minMax.slice(),e.tilingPatternDims=this.tilingPatternDims?.slice(),e}getPathBoundingBox(e=Y.FILL,t=null){let n=this.minMax.slice();if(e===Y.STROKE){t||P(`Stroke bounding box must include transform.`),R.singularValueDecompose2dScale(t,Fn);let e=Fn[0]*this.lineWidth/2,r=Fn[1]*this.lineWidth/2;n[0]-=e,n[1]-=r,n[2]+=e,n[3]+=r}return n}updateClipFromPath(){let e=R.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(e||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(e){this.clipBox.set(e,0),this.minMax.set(m,0)}getClippedPathBoundingBox(e=Y.FILL,t=null){return R.intersect(this.clipBox,this.getPathBoundingBox(e,t))}};function zn(e,t){let{width:n,height:r,kind:i}=t,a=r%X,o=(r-a)/X,s=a===0?o:o+1,c=e.createImageData(n,X),l=0,u=t.data,d=c.data,f;if(i===E.GRAYSCALE_1BPP)for(f=0;f<s;f++)({srcPos:l}=pn({src:u,srcPos:l,dest:d,width:n,height:f<o?X:a})),e.putImageData(c,0,f*X);else if(i===E.RGBA_32BPP){let t=0,r=n*X*4;for(f=0;f<o;f++)d.set(u.subarray(l,l+r)),l+=r,e.putImageData(c,0,t),t+=X;f<s&&(r=n*a*4,d.set(u.subarray(l,l+r)),e.putImageData(c,0,t))}else if(i===E.RGB_24BPP)for(f=0;f<s;f++)({srcPos:l}=mn({src:u,srcPos:l,dest:new Uint32Array(d.buffer),width:n,height:f<o?X:a})),e.putImageData(c,0,f*X);else throw Error(`bad image kind: ${i}`)}function Bn(e,t){if(t.bitmap){e.drawImage(t.bitmap,0,0);return}let{width:n,height:r}=t,i=r%X,a=(r-i)/X,o=i===0?a:a+1,s=e.createImageData(n,X),c=0,l=t.data,u=s.data;for(let t=0;t<o;t++)({srcPos:c}=pn({src:l,srcPos:c,dest:u,width:n,height:t<a?X:i,nonBlackColor:0})),e.putImageData(s,0,t*X)}function Vn(e,t){for(let n of[`strokeStyle`,`fillStyle`,`fillRule`,`globalAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`globalCompositeOperation`,`font`,`filter`])e[n]!==void 0&&(t[n]=e[n]);e.setLineDash!==void 0&&(t.setLineDash(e.getLineDash()),t.lineDashOffset=e.lineDashOffset)}function Hn(e){e.strokeStyle=e.fillStyle=`#000000`,e.fillRule=`nonzero`,e.globalAlpha=1,e.lineWidth=1,e.lineCap=`butt`,e.lineJoin=`miter`,e.miterLimit=10,e.globalCompositeOperation=`source-over`,e.font=`10px sans-serif`,e.setLineDash!==void 0&&(e.setLineDash([]),e.lineDashOffset=0);let{filter:t}=e;t!==`none`&&t!==``&&(e.filter=`none`)}function Un(e,t){if(t)return!0;R.singularValueDecompose2dScale(e,Fn);let n=Math.fround(He.pixelRatio*Oe.PDF_TO_CSS_UNITS);return Fn[0]<=n&&Fn[1]<=n}var Wn=[`butt`,`round`,`square`],Gn=[`miter`,`round`,`bevel`],Kn={},qn={},Jn=class e{#e=0;#t=0;#n=null;#r=null;#i=null;#a=null;#o=1;#s;#c=null;#l=[];constructor(e,t,n,r,i,{optionalContentConfig:a,markedContentStack:o=null},s,c,l,u){this.ctx=e,this.current=new Rn(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.commonObjs=t,this.objs=n,this.canvasFactory=r,this.filterFactory=i,this.groupStack=[],this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.tempSMask=null,this.smaskGroupCanvases=[],this.smaskPreparedEntry=null,this.smaskPreparedFor=null,this.smaskPreparedOffsetX=0,this.smaskPreparedOffsetY=0,this.smaskPreparedOOBAlpha=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=a,this.cachedPatterns=new Map,this.annotationCanvasMap=s,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map,this.dependencyTracker=l??null,this.imagesTracker=u??null}getObject(e,t,n=null){return typeof t==`string`?(this.dependencyTracker?.recordNamedDependency(e,t),t.startsWith(`g_`)?this.commonObjs.get(t):this.objs.get(t)):n}beginDrawing({transform:e,viewport:t,transparency:n=!1,background:r=null}){let i=this.ctx.canvas.width,a=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=r||`#ffffff`,this.ctx.fillRect(0,0,i,a),this.ctx.fillStyle=o,n){let e=this.transparentCanvasEntry=this.canvasFactory.create(i,a);this.compositeCtx=this.ctx,{canvas:this.transparentCanvas,context:this.ctx}=e,this.ctx.save(),this.ctx.transform(...W(this.compositeCtx))}this.ctx.save(),Hn(this.ctx),e&&(this.ctx.transform(...e),this.outputScaleX=e[0],this.outputScaleY=e[3]),this.ctx.transform(...t.transform),this.viewportScale=t.scale,this.baseTransform=W(this.ctx)}executeOperatorList(e,t,n,r,i){let a=e.argsArray,o=e.fnArray,s=t||0,c=a.length;if(c===s)return s;let l=c-s>Nn&&typeof n==`function`,u=l?Date.now()+Mn:0,d=0,f=this.commonObjs,p=this.objs,m,h;for(;;){if(r!==void 0){if(s===r.nextBreakPoint)return r.breakIt(s,n),s;if(r.shouldSkip(s)){if(++s===c)return s;continue}}if(!i||i(s))if(m=o[s],h=a[s]??null,m!==A.dependency)h===null?this[m](s):this[m](s,...h);else for(let e of h){this.dependencyTracker?.recordNamedData(e,s);let t=e.startsWith(`g_`)?f:p;if(!t.has(e))return t.get(e,n),s}if(s++,s===c)return s;if(l&&++d>Nn){if(Date.now()>u)return n(),s;d=0}}}#u(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.canvasFactory.destroy(this.transparentCanvasEntry),this.transparentCanvas=null,this.transparentCanvasEntry=null)}endDrawing(){this.#u();for(let e of this.smaskGroupCanvases)this.canvasFactory.destroy(e);this.smaskGroupCanvases.length=0,this._clearPreparedSMask(),this.tempSMask=null,this.smaskStack.length=0;for(let e of this.#l)this.#y(e);this.#l.length=0,this.#n=null,this.#r=null,this.#i=null,this.#a=null,this.#o=1,this.#c=null,this.#t=0,this.#e=0,this.cachedPatterns.clear();for(let e of this._cachedBitmapsMap.values()){for(let t of e.values())typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement&&(t.width=t.height=0);e.clear()}this._cachedBitmapsMap.clear(),this.#d()}#d(){if(this.pageColors){let e=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(e!==`none`){let t=this.ctx.filter;this.ctx.filter=e,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=t}}}_scaleImage(e,t){let n=e.width??e.displayWidth,r=e.height??e.displayHeight,i=Math.max(Math.hypot(t[0],t[1]),1),a=Math.max(Math.hypot(t[2],t[3]),1),o=[],s=i,c=a,l=n,u=r;for(;s>2&&l>1||c>2&&u>1;){let e=l,t=u;s>2&&l>1&&(e=Math.ceil(l/2),s/=l/e),c>2&&u>1&&(t=Math.ceil(u/2),c/=u/t),o.push({newWidth:e,newHeight:t}),l=e,u=t}if(o.length===0)return{img:e,paintWidth:n,paintHeight:r,tmpCanvas:null};if(o.length===1){let{newWidth:t,newHeight:i}=o[0],a=this.canvasFactory.create(t,i);return a.context.drawImage(e,0,0,n,r,0,0,t,i),{img:a.canvas,paintWidth:t,paintHeight:i,tmpCanvas:a}}let d=this.canvasFactory.create(1,1),f=this.canvasFactory.create(1,1),p=n,m=r,h=e;for(let{newWidth:e,newHeight:t}of o)this.canvasFactory.reset(f,e,t),f.context.drawImage(h,0,0,p,m,0,0,e,t),[d,f]=[f,d],h=d.canvas,p=e,m=t;return this.canvasFactory.destroy(f),{img:d.canvas,paintWidth:p,paintHeight:m,tmpCanvas:d}}_createMaskCanvas(e,t){let n=this.ctx,{width:r,height:i}=t,a=this.current.fillColor,o=this.current.patternFill,s=W(n),c,l,u,d;if((t.bitmap||t.data)&&t.count>1){let n=t.bitmap||t.data.buffer;l=JSON.stringify(o?s:[s.slice(0,4),a]),c=this._cachedBitmapsMap.getOrInsertComputed(n,Ce);let r=c.get(l);if(r&&!o){let t=Math.round(Math.min(s[0],s[2])+s[4]),n=Math.round(Math.min(s[1],s[3])+s[5]);return this.dependencyTracker?.recordDependencies(e,Nt.transformAndFill),{canvas:r,offsetX:t,offsetY:n}}u=r}u||(d=this.canvasFactory.create(r,i),Bn(d.context,t));let f=R.transform(s,[1/r,0,0,-1/i,0,0]);f=R.transform(f,[1,0,0,1,0,-i]);let p=m.slice();R.axialAlignedBoundingBox([0,0,r,i],f,p);let[h,g,_,v]=p,y=Math.round(_-h)||1,b=Math.round(v-g)||1,x=this.canvasFactory.create(y,b),S=x.context,C=h,w=g;S.translate(-C,-w),S.transform(...f);let T=null;if(!u){let e=this._scaleImage(d.canvas,Be(S));u=e.img,T=e.tmpCanvas,u!==d.canvas&&(this.canvasFactory.destroy(d),d=null),c&&o&&(c.set(l,u),T=null,d=null)}S.imageSmoothingEnabled=Un(W(S),t.interpolate),Ln(S,u,0,0,u.width,u.height,0,0,r,i),T&&this.canvasFactory.destroy(T),d&&this.canvasFactory.destroy(d),S.globalCompositeOperation=`source-in`;let E=R.transform(Be(S),[1,0,0,1,-C,-w]);return S.fillStyle=o?a.getPattern(n,this,E,Y.FILL,e):a,S.fillRect(0,0,r,i),c&&!o&&c.set(l,x.canvas),this.dependencyTracker?.recordDependencies(e,Nt.transformAndFill),{canvas:x.canvas,canvasEntry:c&&!o?null:x,offsetX:Math.round(C),offsetY:Math.round(w)}}setLineWidth(e,t){this.dependencyTracker?.recordSimpleData(`lineWidth`,e),t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(e,t){this.dependencyTracker?.recordSimpleData(`lineCap`,e),this.ctx.lineCap=Wn[t]}setLineJoin(e,t){this.dependencyTracker?.recordSimpleData(`lineJoin`,e),this.ctx.lineJoin=Gn[t]}setMiterLimit(e,t){this.dependencyTracker?.recordSimpleData(`miterLimit`,e),this.ctx.miterLimit=t}setDash(e,t,n){this.dependencyTracker?.recordSimpleData(`dash`,e);let r=this.ctx;r.setLineDash!==void 0&&(r.setLineDash(t),r.lineDashOffset=n)}setRenderingIntent(e,t){}setFlatness(e,t){}setGState(e,t){for(let[n,r]of t)switch(n){case`LW`:this.setLineWidth(e,r);break;case`LC`:this.setLineCap(e,r);break;case`LJ`:this.setLineJoin(e,r);break;case`ML`:this.setMiterLimit(e,r);break;case`D`:this.setDash(e,r[0],r[1]);break;case`RI`:this.setRenderingIntent(e,r);break;case`FL`:this.setFlatness(e,r);break;case`Font`:this.setFont(e,r[0],r[1]);break;case`CA`:this.dependencyTracker?.recordSimpleData(`strokeAlpha`,e),this.current.strokeAlpha=r;break;case`ca`:this.dependencyTracker?.recordSimpleData(`fillAlpha`,e),this.ctx.globalAlpha=this.current.fillAlpha=r;break;case`BM`:this.dependencyTracker?.recordSimpleData(`globalCompositeOperation`,e),this.ctx.globalCompositeOperation=r;break;case`SMask`:this.dependencyTracker?.recordSimpleData(`SMask`,e),this.current.activeSMask=r?this.tempSMask:null,this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation),this.tempSMask=null,this.checkSMaskState(e);break;case`TR`:this.dependencyTracker?.recordSimpleData(`filter`,e),this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(r);break}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){this.smaskPreparedEntry&&=(this.canvasFactory.destroy(this.smaskPreparedEntry),null),this.smaskPreparedFor=null,this.smaskPreparedOffsetX=0,this.smaskPreparedOffsetY=0,this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(e){e!==this.smaskPreparedFor&&(this._clearPreparedSMask(),this._prepareSMaskCanvas(e))}checkSMaskState(e){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode(e):!this.current.activeSMask&&t?this.endSMaskMode():this.current.activeSMask&&t&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(e){let{canvas:t,subtype:n,backdrop:r,transferMap:i}=e,a=n===`Luminosity`||n===`Alpha`&&i;if(!a&&!(n===`Luminosity`&&r)){this.smaskPreparedFor=e;return}let o;if(n===`Luminosity`&&r){let[e,t,n]=Le(r),a=Math.round(.3*e+.59*t+.11*n);o=i?.[a]??a}else o=i?.[0]??0;let{width:s,height:c}=this.ctx.canvas,l=t.width*t.height,u=s*c<4*l,d=a?{url:n===`Alpha`?this.filterFactory.addAlphaFilter(i):this.filterFactory.addLuminosityFilter(i),subtype:n,transferMap:i}:null,f=n===`Luminosity`?r:null,p,m,h;u?(p=this._bakeSMaskCanvas(t,e.offsetX,e.offsetY,s,c,f,d),m=0,h=0):(p=this._bakeSMaskCanvas(t,0,0,t.width,t.height,f,d),m=e.offsetX,h=e.offsetY),this.smaskPreparedEntry=p,this.smaskPreparedFor=e,this.smaskPreparedOffsetX=m,this.smaskPreparedOffsetY=h,this.smaskPreparedOOBAlpha=!u&&o!==0?o:null}_bakeSMaskCanvas(e,t,n,r,i,a,o){!a&&!o&&P(`_bakeSMaskCanvas with neither backdrop nor filter`);let s=this.canvasFactory.create(r,i),c=s.context;if(c.drawImage(e,t,n),a&&(c.globalCompositeOperation=`destination-atop`,c.fillStyle=a,c.fillRect(0,0,r,i)),!o)return s;let l=this.canvasFactory.create(r,i),u=l.context;u.filter=o.url;let d=L.isCanvasFilterSupported&&u.filter!==`none`&&u.filter!==``;if(u.drawImage(s.canvas,0,0),L.isCanvasFilterSupported&&(u.filter=`none`),!d){let e=u.getImageData(0,0,r,i),{data:t}=e,{transferMap:n}=o;if(o.subtype===`Luminosity`)for(let e=0,r=t.length;e<r;e+=4){let r=.3*t[e]+.59*t[e+1]+.11*t[e+2]+.5|0;t[e]=t[e+1]=t[e+2]=0,t[e+3]=n?.[r]??r}else for(let e=3,r=t.length;e<r;e+=4)t[e]=n[t[e]];u.putImageData(e,0,0)}return this.canvasFactory.destroy(s),l}beginSMaskMode(e){if(this.inSMaskMode)throw Error(`beginSMaskMode called while already in smask mode`);let{width:t,height:n}=this.ctx.canvas,r=this.canvasFactory.create(t,n);this.smaskScratchCanvas=r,this.suspendedCtx=this.ctx;let i=this.ctx=r.context;i.setTransform(this.suspendedCtx.getTransform()),Vn(this.suspendedCtx,i),In(i,this.suspendedCtx),this._ensurePreparedSMask(this.current.activeSMask),this.setGState(e,[[`BM`,`source-over`]])}endSMaskMode(){if(!this.inSMaskMode)throw Error(`endSMaskMode called while not in smask mode`);this.ctx._removeMirroring(),Vn(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null,this.canvasFactory.destroy(this.smaskScratchCanvas),this.smaskScratchCanvas=null,this._clearPreparedSMask()}#f(e,t=null,n=1){let{width:r,height:i}=e,a=t??this.canvasFactory.create(r,i),o=a.context;n=Math.round(n*255)/255;let s=n<1;s&&this.#s===void 0&&(this.#s=L.isCanvasFilterSupported?new Map:`none`);let c=`none`;if(s&&this.#s instanceof Map&&(c=this.#s.getOrInsertComputed(n,()=>this.filterFactory.addKnockoutFilter(n))),!s||c!==`none`)return t&&(o.save(),o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,r,i),o.restore()),o.filter=c,o.drawImage(e,0,0),o.filter=`none`,a;let l=e.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,r,i),u=o.createImageData(r,i),d=l.data,f=u.data,p=n>0?1/n:1e6;for(let e=3,t=d.length;e<t;e+=4)f[e]=Math.min(Math.round(d[e]*p),255);return o.putImageData(u,0,0),a}#p(e,t,n,r){let i=e?.[t]??null;if(i&&(i.canvas.width!==n||i.canvas.height!==r)&&(this.canvasFactory.destroy(i),i=null),!i)return i=this.canvasFactory.create(n,r),e&&(e[t]=i),i;let a=i.context;return a.save(),a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,n,r),a.restore(),i}#m(e,t,n={}){let{backdropCanvas:r=null,destTransform:i=[1,0,0,1,0,0],backdropOffset:a=[0,0],reuseMaskEntry:o=null,poolMeta:s=null,sourceAlpha:c=1,sourceFilter:l=`none`,knockoutAlpha:u=1}=n,{width:d,height:f}=t,p=this.#f(t,o,u),m=e.globalCompositeOperation;if(e.save(),e.setTransform(...i),e.globalAlpha=1,L.isCanvasFilterSupported&&(e.filter=`none`),e.globalCompositeOperation=`destination-out`,e.drawImage(p.canvas,0,0),r){let[t,n]=a,i=this.#p(s,`knockoutBackdropEntry`,d,f),o=i.context;o.drawImage(r,t,n,d,f,0,0,d,f),o.globalCompositeOperation=`destination-in`,o.drawImage(p.canvas,0,0),o.globalCompositeOperation=`source-over`,e.globalCompositeOperation=`destination-over`,e.drawImage(i.canvas,0,0),s||this.canvasFactory.destroy(i)}e.globalCompositeOperation=m,e.globalAlpha=c,L.isCanvasFilterSupported&&(e.filter=l??`none`),e.drawImage(t,0,0),e.restore(),o||this.canvasFactory.destroy(p)}#h(e=1){if(this.#e===0||this.#t>0||!this.contentVisible)return!1;this.#t++,this.#o=e;let t=this.#l.at(-1),{canvas:n}=this.ctx,r=this.#p(t,`knockoutTempEntry`,n.width,n.height);this.#n=r;let i=r.context;return i.save(),i.setTransform(this.ctx.getTransform()),Vn(this.ctx,i),this.#a=i.globalCompositeOperation,i.globalCompositeOperation=`source-over`,In(i,this.ctx),this.#c=t,this.#r=this.ctx,this.#i=this.suspendedCtx,this.ctx=i,this.inSMaskMode&&(this.suspendedCtx=i),!0}#g(e){if(!e)return;let t=this.#n,n=this.#r,r=this.#i,i=t.context;this.#n=null,this.#r=null,this.#i=null,this.inSMaskMode&&this.suspendedCtx===i&&this.ctx!==i&&this.endSMaskMode(),this.inSMaskMode&&(this.suspendedCtx=r),this.ctx._removeMirroring(),this.ctx.globalCompositeOperation=this.#a,this.#a=null,Vn(this.ctx,n),this.ctx=n;let a=this.#c;this.#c=null;let o=this.#o;this.#o=1;try{this.#m(r??n,t.canvas,{backdropCanvas:a?.backdropCtx?.canvas??null,backdropOffset:a?.backdropCtx?[a.offsetX,a.offsetY]:[0,0],reuseMaskEntry:a?.knockoutMaskEntry??null,poolMeta:a,knockoutAlpha:o})}finally{i.restore(),this.#t--,a||this.canvasFactory.destroy(t)}}compose(e){if(!this.current.activeSMask)return;e=e?[Math.floor(e[0]),Math.floor(e[1]),Math.ceil(e[2]),Math.ceil(e[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];let t=this.current.activeSMask,n=this.suspendedCtx,r=this.#t>0&&n===this.ctx;this.composeSMask(r?null:n,t,this.ctx,e),!r&&(this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore())}composeSMask(e,t,n,r){let i=r[0],a=r[1],o=r[2]-i,s=r[3]-a;if(o===0||s===0)return;let c=this.smaskPreparedEntry;if(c){let e=i,r=a,l=o,u=s,d=this.smaskPreparedOOBAlpha,f=d!==null;if(f){e=Math.max(i,t.offsetX),r=Math.max(a,t.offsetY);let n=Math.min(i+o,t.offsetX+t.canvas.width),c=Math.min(a+s,t.offsetY+t.canvas.height);l=n-e,u=c-r}if(l>0&&u>0){let t=e-this.smaskPreparedOffsetX,i=r-this.smaskPreparedOffsetY;n.save(),n.globalAlpha=1,n.setTransform(1,0,0,1,0,0);let a=new Path2D;a.rect(e,r,l,u),n.clip(a),n.globalCompositeOperation=`destination-in`,n.drawImage(c.canvas,t,i,l,u,e,r,l,u),n.restore()}f&&d<255&&this._applySMaskOOBAlpha(n,i,a,o,s,e,r,e+l,r+u,d)}else this.genericComposeSMask(t,n,o,s,i,a);e&&(e.save(),e.globalAlpha=1,e.globalCompositeOperation=t.blendMode||`source-over`,e.setTransform(1,0,0,1,0,0),e.drawImage(n.canvas,i,a,o,s,i,a,o,s),e.restore())}_applySMaskOOBAlpha(e,t,n,r,i,a,o,s,c,l){let u=a<s&&o<c;if(u&&a===t&&o===n&&s===t+r&&c===n+i)return;let d=new Path2D;d.rect(t,n,r,i),u&&d.rect(a,o,s-a,c-o),e.save(),e.globalAlpha=l/255,e.setTransform(1,0,0,1,0,0),e.clip(d,`evenodd`),e.globalCompositeOperation=`destination-in`,e.fillStyle=`#000000`,e.fillRect(t,n,r,i),e.restore()}genericComposeSMask(e,t,n,r,i,a){let{context:o,offsetX:s,offsetY:c}=e;t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);let l=new Path2D;l.rect(i,a,n,r),t.clip(l),t.globalCompositeOperation=`destination-in`,t.drawImage(o.canvas,i-s,a-c,n,r,i,a,n,r),t.restore()}save(e){this.inSMaskMode&&Vn(this.ctx,this.suspendedCtx),this.ctx.save();let t=this.current;this.stateStack.push(t),this.current=t.clone(),this.dependencyTracker?.save(e)}restore(e){if(this.dependencyTracker?.restore(e),this.stateStack.length===0){this.inSMaskMode&&this.endSMaskMode();return}this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&(Vn(this.suspendedCtx,this.ctx),this.ctx.setTransform(this.suspendedCtx.getTransform())),this.checkSMaskState(e),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}transform(e,t,n,r,i,a,o){this.dependencyTracker?.recordIncrementalData(`transform`,e),this.ctx.transform(t,n,r,i,a,o),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(e,t,n,r){let[i]=n;if(!r){i||=n[0]=new Path2D,t!==A.stroke&&t!==A.closeStroke&&(this.current.tilingPatternDims=null),this[t](e,i);return}if(this.dependencyTracker!==null){let n=t===A.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(e).recordBBox(e,this.ctx,r[0]-n,r[2]+n,r[1]-n,r[3]+n).recordDependencies(e,[`transform`])}i instanceof Path2D||(i=n[0]=et(i)),R.axialAlignedBoundingBox(r,W(this.ctx),this.current.minMax);let a=this.current.tilingPatternDims;if(a&&t!==A.stroke&&t!==A.closeStroke&&this.current.fillColor instanceof kn){let e=R.intersect(this.current.clipBox,this.current.minMax);e?this.current.fillColor.updatePatternDims(e,a):this.current.tilingPatternDims=null}this[t](e,i),this._pathStartIdx=e}closePath(e){this.ctx.closePath()}stroke(e,t,n=!0){let r=n&&this.#h(this.current.strokeAlpha),i=this.ctx,a=this.current.strokeColor;if(i.globalAlpha=this.current.strokeAlpha,this.contentVisible)if(typeof a==`object`&&a?.getPattern){let n=a.isModifyingCurrentTransform()?i.getTransform():null;if(i.save(),i.strokeStyle=a.getPattern(i,this,Be(i),Y.STROKE,e),n){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(n)),t=e}this.rescaleAndStroke(t,!1),i.restore()}else this.rescaleAndStroke(t,!0);this.dependencyTracker?.recordDependencies(e,Nt.stroke),n&&this.consumePath(e,t,this.current.getClippedPathBoundingBox(Y.STROKE,W(this.ctx))),i.globalAlpha=this.current.fillAlpha,this.#g(r)}closeStroke(e,t){this.stroke(e,t)}fill(e,t,n=!0){let r=n&&this.#h(this.current.fillAlpha),i=this.ctx,a=this.current.fillColor,o=this.current.patternFill,s=!1,c=this.current.getClippedPathBoundingBox();if(this.dependencyTracker?.recordDependencies(e,Nt.fill),o){let o=this.current.tilingPatternDims,l=o&&a.canSkipPatternCanvas(o);if(l){a.drawPattern(this,t,this.pendingEOFill,l,e),this.pendingEOFill=!1,n&&this.consumePath(e,t,c),this.current.tilingPatternDims=null,this.#g(r);return}let u=a.isModifyingCurrentTransform()?i.getTransform():null;if(this.dependencyTracker?.save(e),i.save(),i.fillStyle=a.getPattern(i,this,Be(i),Y.FILL,e),u){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(u)),t=e}s=!0}this.contentVisible&&c!==null&&(this.pendingEOFill?(i.fill(t,`evenodd`),this.pendingEOFill=!1):i.fill(t)),s&&(i.restore(),this.dependencyTracker?.restore(e)),n&&this.consumePath(e,t,c),this.#g(r)}eoFill(e,t){this.pendingEOFill=!0,this.fill(e,t)}fillStroke(e,t){let n=this.#h(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(e,t,!1),this.stroke(e,t,!1),this.consumePath(e,t),this.#g(n)}eoFillStroke(e,t){this.pendingEOFill=!0,this.fillStroke(e,t)}closeFillStroke(e,t){this.fillStroke(e,t)}closeEOFillStroke(e,t){this.pendingEOFill=!0,this.fillStroke(e,t)}endPath(e,t){this.consumePath(e,t)}rawFillPath(e,t){let n=this.#h(this.current.fillAlpha);this.ctx.fill(t),this.dependencyTracker?.recordDependencies(e,Nt.rawFillPath).recordOperation(e),this.#g(n)}clip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e),this.pendingClip=Kn}eoClip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e),this.pendingClip=qn}beginText(e){this.current.textMatrix=null,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0,this.dependencyTracker?.recordOpenMarker(e).resetIncrementalData(`sameLineText`).resetIncrementalData(`moveText`,e)}endText(e){let t=this.pendingTextPaths,n=this.ctx;if(this.dependencyTracker){let{dependencyTracker:n}=this;t!==void 0&&n.recordFutureForcedDependency(`textClip`,n.getOpenMarker()).recordFutureForcedDependency(`textClip`,e),n.recordCloseMarker(e)}if(t!==void 0){let e=new Path2D,r=n.getTransform().invertSelf();for(let{transform:n,x:i,y:a,fontSize:o,path:s}of t)s&&e.addPath(s,new DOMMatrix(n).preMultiplySelf(r).translate(i,a).scale(o,-o));n.clip(e)}delete this.pendingTextPaths}setCharSpacing(e,t){this.dependencyTracker?.recordSimpleData(`charSpacing`,e),this.current.charSpacing=t}setWordSpacing(e,t){this.dependencyTracker?.recordSimpleData(`wordSpacing`,e),this.current.wordSpacing=t}setHScale(e,t){this.dependencyTracker?.recordSimpleData(`hScale`,e),this.current.textHScale=t/100}setLeading(e,t){this.dependencyTracker?.recordSimpleData(`leading`,e),this.current.leading=-t}setFont(e,t,n){this.dependencyTracker?.recordSimpleData(`font`,e).recordSimpleDataFromNamed(`fontObj`,t,e);let r=this.commonObjs.get(t),i=this.current;if(!r)throw Error(`Can't find font for ${t}`);if(i.fontMatrix=r.fontMatrix||h,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&N(`Invalid font matrix for font `+t),n<0?(n=-n,i.fontDirection=-1):i.fontDirection=1,this.current.font=r,this.current.fontSize=n,r.isType3Font)return;let a=r.loadedName||`sans-serif`,o=r.systemFontInfo?.css||`"${a}", ${r.fallbackName}`,s=`normal`;r.black?s=`900`:r.bold&&(s=`bold`);let c=r.italic?`italic`:`normal`,l=B(n,An,jn);this.current.fontSizeScale=n/l,this.ctx.font=`${c} ${s} ${l}px ${o}`}setTextRenderingMode(e,t){this.dependencyTracker?.recordSimpleData(`textRenderingMode`,e),this.current.textRenderingMode=t}setTextRise(e,t){this.dependencyTracker?.recordSimpleData(`textRise`,e),this.current.textRise=t}moveText(e,t,n){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordIncrementalData(`moveText`,e),this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=n}setLeadingMoveText(e,t,n){this.setLeading(e,-n),this.moveText(e,t,n)}setTextMatrix(e,t){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordSimpleData(`textMatrix`,e);let{current:n}=this;n.textMatrix=t,n.textMatrixScale=Math.hypot(t[0],t[1]),n.x=n.lineX=0,n.y=n.lineY=0}nextLine(e){this.moveText(e,0,this.current.leading),this.dependencyTracker?.recordIncrementalData(`moveText`,this.dependencyTracker.getSimpleIndex(`leading`)??e)}#_(e,t,n){let r=new Path2D;return r.addPath(e,new DOMMatrix(n).invertSelf().multiplySelf(t)),r}paintChar(e,t,n,r,i,a){let o=this.ctx,s=this.current,c=s.font,l=s.textRenderingMode,u=s.fontSize/s.fontSizeScale,d=l&T.FILL_STROKE_MASK,f=!!(l&T.ADD_TO_PATH_FLAG),p=s.patternFill&&!c.missingFile,m=s.patternStroke&&!c.missingFile,h;if((c.disableFontFace||f||p||m)&&!c.missingFile&&(h=c.getPathGenerator(this.commonObjs,t)),h&&(c.disableFontFace||p||m)){o.save(),o.translate(n,r),o.scale(u,-u),this.dependencyTracker?.recordCharacterBBox(e,o,c);let t;if(d===T.FILL||d===T.FILL_STROKE)if(i){t=o.getTransform(),o.setTransform(...i);let e=this.#_(h,t,i);o.fill(e)}else o.fill(h);if(d===T.STROKE||d===T.FILL_STROKE)if(a){t||=o.getTransform(),o.setTransform(...a);let{a:e,b:n,c:r,d:i}=t,s=R.inverseTransform(a),c=R.transform([e,n,r,i,0,0],s);R.singularValueDecompose2dScale(c,Fn),o.lineWidth*=Math.max(Fn[0],Fn[1])/u,o.stroke(this.#_(h,t,a))}else o.lineWidth/=u,o.stroke(h);o.restore()}else(d===T.FILL||d===T.FILL_STROKE)&&(o.fillText(t,n,r),this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t))),(d===T.STROKE||d===T.FILL_STROKE)&&(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t)).recordDependencies(e,Nt.stroke),o.strokeText(t,n,r));f&&((this.pendingTextPaths||=[]).push({transform:W(o),x:n,y:r,fontSize:u,path:h}),this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r))}get isFontSubpixelAAEnabled(){let e=this.canvasFactory.create(10,10),t=e.context;t.scale(1.5,1),t.fillText(`I`,0,10);let n=t.getImageData(0,0,10,10).data;this.canvasFactory.destroy(e);let r=!1;for(let e=3;e<n.length;e+=4)if(n[e]>0&&n[e]<255){r=!0;break}return I(this,`isFontSubpixelAAEnabled`,r)}showText(e,t){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(e,Nt.showText).resetBBox(e),this.current.textRenderingMode&T.ADD_TO_PATH_FLAG&&this.dependencyTracker.recordFutureForcedDependency(`textClip`,e).inheritPendingDependenciesAsFutureForcedDependencies());let n=this.current,r=n.font;if(r.isType3Font){let r=this.#h(n.fillAlpha);this.showType3Text(e,t),this.dependencyTracker?.recordShowTextOperation(e),this.#g(r);return}let i=n.fontSize;if(i===0){this.dependencyTracker?.recordOperation(e);return}let a=this.#h(n.fillAlpha),o=this.ctx,s=n.fontSizeScale,c=n.charSpacing,l=n.wordSpacing,u=n.fontDirection,d=n.textHScale*u,f=t.length,p=r.vertical,m=p?1:-1,h=r.defaultVMetrics,g=i*n.fontMatrix[0],_=n.textRenderingMode===T.FILL&&!r.disableFontFace&&!n.patternFill;o.save(),n.textMatrix&&o.transform(...n.textMatrix),o.translate(n.x,n.y+n.textRise),u>0?o.scale(d,-1):o.scale(d,1);let v,y,b=n.textRenderingMode&T.FILL_STROKE_MASK,x=b===T.FILL||b===T.FILL_STROKE,S=b===T.STROKE||b===T.FILL_STROKE,C=n.lineWidth,w=n.textMatrixScale;if(w===0||C===0?S&&(C=this.getSinglePixelWidth()):C/=w,s!==1&&(o.scale(s,s),C/=s),o.lineWidth=C,x&&n.patternFill){o.save();let t=n.fillColor.getPattern(o,this,Be(o),Y.FILL,e);v=W(o),o.restore(),o.fillStyle=t}if(S&&n.patternStroke){o.save();let t=n.strokeColor.getPattern(o,this,Be(o),Y.STROKE,e);y=W(o),o.restore(),o.strokeStyle=t}if(r.isInvalidPDFjsFont){let r=[],i=0;for(let e of t)r.push(e.unicode),i+=e.width;let s=r.join(``);if(o.fillText(s,0,0),this.dependencyTracker!==null){let t=o.measureText(s);this.dependencyTracker.recordBBox(e,this.ctx,-t.actualBoundingBoxLeft,t.actualBoundingBoxRight,-t.actualBoundingBoxAscent,t.actualBoundingBoxDescent).recordShowTextOperation(e)}n.x+=i*g*d,o.restore(),this.compose(),this.#g(a);return}let E=0,D;for(D=0;D<f;++D){let n=t[D];if(typeof n==`number`){E+=m*n*i/1e3;continue}let a=!1,d=(n.isSpace?l:0)+c,f=n.fontChar,b=n.accent,x,S,C=n.width;if(p){let e=n.vmetric||h,t=-(n.vmetric?e[1]:C*.5)*g,r=e[2]*g;C=e?-e[0]:C,x=t/s,S=(E+r)/s}else x=E/s,S=0;let w;if(r.remeasure&&C>0){w=o.measureText(f);let e=w.width*1e3/i*s;if(C<e&&this.isFontSubpixelAAEnabled){let t=C/e;a=!0,o.save(),o.scale(t,1),x/=t}else C!==e&&(x+=(C-e)/2e3*i/s)}if(this.contentVisible&&(n.isInFont||r.missingFile)){if(_&&!b)o.fillText(f,x,S),this.dependencyTracker?.recordCharacterBBox(e,o,w?{bbox:null}:r,i/s,x,S,()=>w??o.measureText(f));else if(this.paintChar(e,f,x,S,v,y),b){let t=x+i*b.offset.x/s,n=S-i*b.offset.y/s;this.paintChar(e,b.fontChar,t,n,v,y)}}let T=p?C*g-d*u:C*g+d*u;E+=T,a&&o.restore()}p?n.y-=E:n.x+=E*d,o.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(e),this.#g(a)}showType3Text(e,t){let n=this.ctx,r=this.current,i=r.font,a=r.fontSize,o=r.fontDirection,s=i.vertical?1:-1,c=r.charSpacing,l=r.wordSpacing,u=r.textHScale*o,d=r.fontMatrix||h,f=t.length,p=r.textRenderingMode===T.INVISIBLE,m,g,_,v;if(p||a===0)return;this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,n.save(),r.textMatrix&&n.transform(...r.textMatrix),n.translate(r.x,r.y+r.textRise),n.scale(u,o);let y=this.dependencyTracker;for(this.dependencyTracker=y?new Mt(y,e):null,m=0;m<f;++m){if(g=t[m],typeof g==`number`){v=s*g*a/1e3,this.ctx.translate(v,0),r.x+=v*u;continue}let e=(g.isSpace?l:0)+c,o=i.charProcOperatorList[g.operatorListId];o?this.contentVisible&&(this.save(),o.fnArray[0]===A.setCharWidth&&(r.fillAlpha=r.strokeAlpha=1,n.globalAlpha=1),n.scale(a,a),n.transform(...d),this.executeOperatorList(o),this.restore()):N(`Type3 character "${g.operatorListId}" is not available.`);let f=[g.width,0];R.applyTransform(f,d),_=f[0]*a+e,n.translate(_,0),r.x+=_*u}n.restore(),y&&(this.dependencyTracker=y)}setCharWidth(e,t,n){}setCharWidthAndBounds(e,t,n,r,i,a,o){let s=new Path2D;s.rect(r,i,a-r,o-i),this.ctx.clip(s),this.dependencyTracker?.recordBBox(e,this.ctx,r,a,i,o).recordClipBox(e,this.ctx,r,a,i,o),this.endPath(e)}getColorN_Pattern(t,n){let r;if(n[0]===`TilingPattern`){let t=this.baseTransform||W(this.ctx);r=new kn(n,this.ctx,{createCanvasGraphics:(t,n)=>new e(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new Mt(this.dependencyTracker,n,!0):null)},t)}else r=this._getPattern(t,n[1],n[2]);return r}setStrokeColorN(e,...t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.current.strokeColor=this.getColorN_Pattern(e,t),this.current.patternStroke=!0}setFillColorN(e,...t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);let n=this.current.fillColor=this.getColorN_Pattern(e,t);this.current.patternFill=!0,this.current.tilingPatternDims=n instanceof kn?[0,0,0,0]:null}setStrokeRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.ctx.strokeStyle=this.current.strokeColor=t,this.current.patternStroke=!1}setStrokeTransparent(e){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.ctx.strokeStyle=this.current.strokeColor=`transparent`,this.current.patternStroke=!1}setFillRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`fillColor`,e),this.ctx.fillStyle=this.current.fillColor=t,this.current.patternFill=!1,this.current.tilingPatternDims=null}setFillTransparent(e){this.dependencyTracker?.recordSimpleData(`fillColor`,e),this.ctx.fillStyle=this.current.fillColor=`transparent`,this.current.patternFill=!1,this.current.tilingPatternDims=null}_getPattern(e,t,n=null){let r;return this.cachedPatterns.has(t)?r=this.cachedPatterns.get(t):(r=Dn(this.getObject(e,t)),this.cachedPatterns.set(t,r)),n&&(r.matrix=n),r}shadingFill(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx;this.save(e),r.fillStyle=this._getPattern(e,t).getPattern(r,this,Be(r),Y.SHADING,e);let i=Be(r);if(i){let{width:e,height:t}=r.canvas,n=m.slice();R.axialAlignedBoundingBox([0,0,e,t],i,n);let[a,o,s,c]=n;this.ctx.fillRect(a,o,s-a,c-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(e).recordFullPageBBox(e).recordDependencies(e,Nt.transform).recordDependencies(e,Nt.fill).recordOperation(e),this.compose(this.current.getClippedPathBoundingBox()),this.restore(e),this.#g(n)}beginInlineImage(){P(`Should not call beginInlineImage`)}beginImageData(){P(`Should not call beginImageData`)}paintFormXObjectBegin(e,t,n){if(this.contentVisible&&(this.save(e),this.baseTransformStack.push(this.baseTransform),t&&this.transform(e,...t),this.baseTransform=W(this.ctx),n)){R.axialAlignedBoundingBox(n,this.baseTransform,this.current.minMax);let[t,r,i,a]=n,o=new Path2D;o.rect(t,r,i-t,a-r),this.ctx.clip(o),this.dependencyTracker?.recordClipBox(e,this.ctx,t,i,r,a),this.endPath(e)}}paintFormXObjectEnd(e){this.contentVisible&&(this.restore(e),this.baseTransform=this.baseTransformStack.pop())}beginGroup(e,t){if(!this.contentVisible)return;this.save(e);let{inSMaskMode:n}=this;n&&(this.endSMaskMode(),this.current.activeSMask=null);let r=this.ctx;if((!t.needsIsolation||!t.isolated&&!t.hasSoftMask)&&!t.knockout&&!t.isGray&&this.#e===0&&r.globalAlpha===1&&r.globalCompositeOperation===`source-over`&&!n){if(t.bbox){let e=new Path2D,[n,i,a,o]=t.bbox;if(e.rect(n,i,a-n,o-i),t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix)),e=n}r.clip(e)}this.groupStack.push(null),this.#l.push(null),this.groupLevel++;return}!t.isolated&&!t.knockout&&this.#e===0&&re(`TODO: Fully support non-isolated non-knockout groups.`);let i=W(r);t.matrix&&r.transform(...t.matrix);let a=[0,0,r.canvas.width,r.canvas.height],o;t.bbox?(o=m.slice(),R.axialAlignedBoundingBox(t.bbox,W(r),o),o=R.intersect(o,a)||[0,0,0,0]):o=a;let s=Math.floor(o[0]),c=Math.floor(o[1]),l=Math.max(Math.ceil(o[2])-s,1),u=Math.max(Math.ceil(o[3])-c,1);this.current.startNewPathAndClipBox([0,0,l,u]);let d=this.canvasFactory.create(l,u);t.smask&&this.smaskGroupCanvases.push(d);let f=d.context,p=t.knockout&&!t.isolated?r:null,h=!t.isolated&&!t.knockout&&!t.smask&&t.needsIsolation&&this.#e>0,g=t.knockout?this.canvasFactory.create(l,u):null,_=this.#e;if(t.knockout?this.#e++:this.#e=0,f.translate(-s,-c),f.transform(...i),!t.isolated&&!t.smask&&n&&t.needsIsolation&&(f.save(),f.setTransform(1,0,0,1,0,0),f.drawImage(r.canvas,-s,-c),f.restore()),t.bbox){let e=new Path2D,[n,r,i,a]=t.bbox;if(e.rect(n,r,i-n,a-r),t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix)),e=n}f.clip(e)}t.smask&&this.smaskStack.push({canvas:d.canvas,context:f,offsetX:s,offsetY:c,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null}),(!t.smask||this.dependencyTracker)&&(r.setTransform(1,0,0,1,0,0),r.translate(s,c),r.save()),Vn(r,f),this.ctx=f,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies([`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`]).pushBaseTransform(r),this.setGState(e,[[`BM`,`source-over`],[`ca`,1],[`CA`,1],[`TR`,null]]),this.groupStack.push(r),this.#l.push({backdropCtx:p,savedKnockoutLevel:_,offsetX:s,offsetY:c,hasInnerBackdrop:h,knockoutMaskEntry:g,knockoutTempEntry:null,knockoutBackdropEntry:null}),this.groupLevel++}endGroup(e,t){if(!this.contentVisible)return;this.groupLevel--;let n=this.ctx,r=this.groupStack.pop(),i=this.#l.pop();if(i&&(this.#e=i.savedKnockoutLevel),r===null){this.restore(e);return}if(t.isGray&&this.#v(n),this.ctx=r,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),t.smask)this.tempSMask=this.smaskStack.pop(),this.restore(e),this.dependencyTracker&&(this.ctx.restore(),this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())),this.#y(i);else{this.ctx.restore();let t=W(this.ctx);this.restore(e),this.ctx.save(),this.ctx.setTransform(...t);let a=m.slice();R.axialAlignedBoundingBox([0,0,n.canvas.width,n.canvas.height],t,a);let o=this.#l.at(-1);if(this.#e>0)if(i.hasInnerBackdrop){let{width:e,height:a}=n.canvas,o=this.canvasFactory.create(e,a),s=o.context;s.drawImage(r.canvas,i.offsetX,i.offsetY,e,a,0,0,e,a),s.globalCompositeOperation=`source-over`,s.drawImage(n.canvas,0,0);let c=this.#f(n.canvas);s.globalCompositeOperation=`destination-in`,s.drawImage(c.canvas,0,0);let l=this.ctx.globalCompositeOperation,u=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save(),this.ctx.setTransform(...t),this.ctx.globalAlpha=1,L.isCanvasFilterSupported&&(this.ctx.filter=`none`),this.ctx.globalCompositeOperation=`destination-out`,this.ctx.drawImage(c.canvas,0,0),this.ctx.globalCompositeOperation=l,this.ctx.globalAlpha=u,L.isCanvasFilterSupported&&(this.ctx.filter=d??`none`),this.ctx.drawImage(o.canvas,0,0),this.ctx.restore(),this.canvasFactory.destroy(c),this.canvasFactory.destroy(o)}else{let e=o?.backdropCtx??null;this.#m(this.ctx,n.canvas,{backdropCanvas:e?.canvas??null,destTransform:t,backdropOffset:e?[o.offsetX+i.offsetX,o.offsetY+i.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}else this.ctx.drawImage(n.canvas,0,0);this.ctx.restore(),this.canvasFactory.destroy({canvas:n.canvas,context:n}),this.#y(i),this.compose(a)}}#v(e){let{canvas:t}=e,{width:n,height:r}=t;if(L.isCanvasFilterSupported){e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`grayscale(1)`,e.globalAlpha=1,e.globalCompositeOperation=`copy`,e.drawImage(t,0,0),e.restore();return}let i=e.getImageData(0,0,n,r),{data:a}=i;for(let e=0,t=a.length;e<t;e+=4){let t=a[e]*.2126+a[e+1]*.7152+a[e+2]*.0722+.5|0;a[e]=a[e+1]=a[e+2]=t}e.putImageData(i,0,0)}#y(e){e&&(e.knockoutMaskEntry&&=(this.canvasFactory.destroy(e.knockoutMaskEntry),null),e.knockoutTempEntry&&=(this.canvasFactory.destroy(e.knockoutTempEntry),null),e.knockoutBackdropEntry&&=(this.canvasFactory.destroy(e.knockoutBackdropEntry),null))}beginAnnotation(e,t,n,r,i,a,o){if(this.#u(),Hn(this.ctx),this.ctx.save(),this.save(e),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),n){let i=n[2]-n[0],s=n[3]-n[1];if(a&&this.annotationCanvasMap){r=r.slice(),r[4]-=n[0],r[5]-=n[1],n=n.slice(),n[0]=n[1]=0,n[2]=i,n[3]=s,R.singularValueDecompose2dScale(W(this.ctx),Fn);let{viewportScale:e}=this,a=Math.ceil(i*this.outputScaleX*e),c=Math.ceil(s*this.outputScaleY*e);this.annotationCanvas=this.canvasFactory.create(a,c);let{canvas:l,context:u}=this.annotationCanvas;if(o){let e=this.annotationCanvasMap.getOrInsertComputed(t,Se);l.setAttribute(`data-canvas-name`,o);let n=e.findIndex(e=>e.getAttribute(`data-canvas-name`)===o);n===-1?e.push(l):e[n]=l}else this.annotationCanvasMap.set(t,l);this.annotationCanvas.savedCtx=this.ctx,this.ctx=u,this.ctx.save(),this.ctx.setTransform(Fn[0],0,0,-Fn[1],0,s*Fn[1]),Hn(this.ctx)}else{Hn(this.ctx),this.endPath(e);let t=new Path2D;t.rect(n[0],n[1],i,s),this.ctx.clip(t)}}this.current=new Rn(this.ctx.canvas.width,this.ctx.canvas.height),this.baseTransformStack.push(this.baseTransform),this.transform(e,...r),this.transform(e,...i),this.baseTransform=W(this.ctx)}endAnnotation(e){this.annotationCanvas&&(this.ctx.restore(),this.#d(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas),this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(e,t){if(!this.contentVisible)return;let n=t.count;t=this.getObject(e,t.data,t),t.count=n;let r=this.#h(this.current.fillAlpha),i=this.ctx,a=this._createMaskCanvas(e,t),o=a.canvas;i.save(),i.setTransform(1,0,0,1,0,0),i.drawImage(o,a.offsetX,a.offsetY),this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,a.offsetX,a.offsetX+o.width,a.offsetY,a.offsetY+o.height).recordOperation(e),i.restore(),a.canvasEntry&&this.canvasFactory.destroy(a.canvasEntry),this.compose(),this.#g(r)}paintImageMaskXObjectRepeat(e,t,n,r=0,i=0,a,o){if(!this.contentVisible)return;t=this.getObject(e,t.data,t);let s=this.#h(this.current.fillAlpha),c=this.ctx;c.save();let l=W(c);c.transform(n,r,i,a,0,0);let u=this._createMaskCanvas(e,t);c.setTransform(1,0,0,1,u.offsetX-l[4],u.offsetY-l[5]),this.dependencyTracker?.resetBBox(e);for(let t=0,s=o.length;t<s;t+=2){let s=R.transform(l,[n,r,i,a,o[t],o[t+1]]);c.drawImage(u.canvas,s[4],s[5]),this.dependencyTracker?.recordBBox(e,this.ctx,s[4],s[4]+u.canvas.width,s[5],s[5]+u.canvas.height)}c.restore(),u.canvasEntry&&this.canvasFactory.destroy(u.canvasEntry),this.compose(),this.dependencyTracker?.recordOperation(e),this.#g(s)}paintImageMaskXObjectGroup(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx,i=this.current.fillColor,a=this.current.patternFill;this.dependencyTracker?.resetBBox(e).recordDependencies(e,Nt.transformAndFill);for(let n of t){let{data:t,width:o,height:s,transform:c}=n,l=this.canvasFactory.create(o,s),u=l.context;u.save(),Bn(u,this.getObject(e,t,n)),u.globalCompositeOperation=`source-in`,u.fillStyle=a?i.getPattern(u,this,Be(r),Y.FILL,e):i,u.fillRect(0,0,o,s),u.restore(),r.save(),r.transform(...c),r.scale(1,-1),Ln(r,l.canvas,0,0,o,s,0,-1,1,1),this.canvasFactory.destroy(l),this.dependencyTracker?.recordBBox(e,r,0,o,0,s),r.restore()}this.compose(),this.dependencyTracker?.recordOperation(e),this.#g(n)}paintImageXObject(e,t){if(!this.contentVisible)return;let n=this.getObject(e,t);if(!n){N(`Dependent image isn't ready yet`);return}this.paintInlineImageXObject(e,n)}paintImageXObjectRepeat(e,t,n,r,i){if(!this.contentVisible)return;let a=this.getObject(e,t);if(!a){N(`Dependent image isn't ready yet`);return}let o=a.width,s=a.height,c=[];for(let e=0,t=i.length;e<t;e+=2)c.push({transform:[n,0,0,r,i[e],i[e+1]],x:0,y:0,w:o,h:s});this.paintInlineImageXObjectGroup(e,a,c)}applyTransferMapsToCanvas(e){return this.current.transferMaps!==`none`&&(e.filter=this.current.transferMaps,e.drawImage(e.canvas,0,0),e.filter=`none`),e.canvas}applyTransferMapsToBitmap(e){if(this.current.transferMaps===`none`)return{img:e.bitmap,canvasEntry:null};let{bitmap:t,width:n,height:r}=e,i=this.canvasFactory.create(n,r),a=i.context;return a.filter=this.current.transferMaps,a.drawImage(t,0,0),a.filter=`none`,{img:i.canvas,canvasEntry:i}}paintInlineImageXObject(e,t){if(!this.contentVisible)return;let n=t.width,r=t.height,i=this.#h(this.current.fillAlpha),a=this.ctx;this.save(e);let{filter:o}=a;o!==`none`&&o!==``&&(a.filter=`none`),a.scale(1/n,-1/r);let s,c=null;if(t.bitmap){let e=this.applyTransferMapsToBitmap(t);s=e.img,c=e.canvasEntry}else{let e=this.canvasFactory.create(n,r);zn(e.context,t),s=this.applyTransferMapsToCanvas(e.context),c=e}let l=this._scaleImage(s,Be(a));a.imageSmoothingEnabled=Un(W(a),t.interpolate),this.dependencyTracker&&(this.dependencyTracker.resetBBox(e).recordBBox(e,a,0,n,-r,0).recordDependencies(e,Nt.imageXObject).recordOperation(e),this.imagesTracker?.record(a,n,r,this.dependencyTracker.clipBox)),Ln(a,l.img,0,0,l.paintWidth,l.paintHeight,0,-r,n,r),l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas),c&&this.canvasFactory.destroy(c),this.compose(),this.restore(e),this.#g(i)}paintInlineImageXObjectGroup(e,t,n){if(!this.contentVisible)return;let r=this.#h(this.current.fillAlpha),i=this.ctx,a,o=null;if(t.bitmap)a=t.bitmap;else{let e=t.width,n=t.height,r=this.canvasFactory.create(e,n);zn(r.context,t),a=this.applyTransferMapsToCanvas(r.context),o=r}this.dependencyTracker?.resetBBox(e);for(let t of n)i.save(),i.transform(...t.transform),i.scale(1,-1),Ln(i,a,t.x,t.y,t.w,t.h,0,-1,1,1),this.dependencyTracker?.recordBBox(e,i,0,1,-1,0),i.restore();o&&this.canvasFactory.destroy(o),this.dependencyTracker?.recordOperation(e),this.compose(),this.#g(r)}paintSolidColorImageMask(e){if(!this.contentVisible)return;let t=this.#h(this.current.fillAlpha);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,0,1,0,1).recordDependencies(e,Nt.fill).recordOperation(e),this.ctx.fillRect(0,0,1,1),this.compose(),this.#g(t)}markPoint(e,t){}markPointProps(e,t,n){}beginMarkedContent(e,t){this.dependencyTracker?.beginMarkedContent(e),this.markedContentStack.push({visible:!0})}beginMarkedContentProps(e,t,n){this.dependencyTracker?.beginMarkedContent(e),t===`OC`?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(n)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(e){this.dependencyTracker?.endMarkedContent(e),this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(e){}endCompat(e){}consumePath(e,t,n){let r=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(n);let i=this.ctx;this.pendingClip?(r||(this.pendingClip===qn?i.clip(t,`evenodd`):i.clip(t)),this.pendingClip=null,this.dependencyTracker?.bboxToClipBoxDropOperation(e).recordFutureForcedDependency(`clipPath`,e)):this.dependencyTracker?.recordOperation(e),this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let e=W(this.ctx);if(e[1]===0&&e[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(e[0]),Math.abs(e[3]));else{let t=Math.abs(e[0]*e[3]-e[2]*e[1]),n=Math.hypot(e[0],e[2]),r=Math.hypot(e[1],e[3]);this._cachedGetSinglePixelWidth=Math.max(n,r)/t}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){let{lineWidth:e}=this.current,{a:t,b:n,c:r,d:i}=this.ctx.getTransform(),a,o;if(n===0&&r===0){let n=Math.abs(t),r=Math.abs(i);if(n===r)if(e===0)a=o=1/n;else{let t=n*e;a=o=t<1?1/t:1}else if(e===0)a=1/n,o=1/r;else{let t=n*e,i=r*e;a=t<1?1/t:1,o=i<1?1/i:1}}else{let s=Math.abs(t*i-n*r),c=Math.hypot(t,n),l=Math.hypot(r,i);if(e===0)a=l/s,o=c/s;else{let t=e*s;a=l>t?l/t:1,o=c>t?c/t:1}}this._cachedScaleForStroking[0]=a,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(e,t){let{ctx:n,current:{lineWidth:r}}=this,[i,a]=this.getScaleForStroking();if(i===a){n.lineWidth=(r||1)*i,n.stroke(e);return}let o=n.getLineDash();t&&n.save(),n.scale(i,a),Pn.a=1/i,Pn.d=1/a;let s=new Path2D;if(s.addPath(e,Pn),o.length>0){let e=Math.max(i,a);n.setLineDash(o.map(t=>t/e)),n.lineDashOffset/=e}n.lineWidth=r||1,n.stroke(s),t&&n.restore()}isContentVisible(){for(let e=this.markedContentStack.length-1;e>=0;e--)if(!this.markedContentStack[e].visible)return!1;return!0}};for(let e in A)Jn.prototype[e]!==void 0&&(Jn.prototype[A[e]]=Jn.prototype[e]);var Yn=class{#e=null;#t=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(e,t,n){this._source=e,this.#e=t,this.#t=n}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){return F(!this._fullReader,`BasePDFStream.getFullReader can only be called once.`),this._fullReader=new this.#e(this)}getRangeReader(e,t){if(t<=this._progressiveDataLength)return null;let n=new this.#t(this,e,t);return this._rangeReaders.add(n),n}cancelAllRequests(e){this._fullReader?.cancel(e);for(let t of new Set(this._rangeReaders))t.cancel(e)}},Xn=class{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(e){this._stream=e}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){P("Abstract method `read` called")}cancel(e){P("Abstract method `cancel` called")}},Zn=class{_stream=null;constructor(e,t,n){this._stream=e}async read(){P("Abstract method `read` called")}cancel(e){P("Abstract method `cancel` called")}};function Qn(e){let t=!0,n=r(`filename\\*`,`i`).exec(e);if(n){n=n[1];let e=s(n);return e=unescape(e),e=c(e),e=l(e),a(e)}if(n=o(e),n)return a(l(n));if(n=r(`filename`,`i`).exec(e),n){n=n[1];let e=s(n);return e=l(e),a(e)}function r(e,t){return RegExp(`(?:^|;)\\s*`+e+`\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)`,t)}function i(e,n){if(e){if(!/^[\x00-\xFF]+$/.test(n))return n;try{let r=new TextDecoder(e,{fatal:!0}),i=ge(n);n=r.decode(i),t=!1}catch{}}return n}function a(e){return t&&/[\x80-\xff]/.test(e)&&(e=i(`utf-8`,e),t&&(e=i(`iso-8859-1`,e))),e}function o(e){let t=[],n,i=r(`filename\\*((?!0\\d)\\d+)(\\*?)`,`ig`);for(;(n=i.exec(e))!==null;){let[,e,r,i]=n;if(e=parseInt(e,10),e in t){if(e===0)break;continue}t[e]=[r,i]}let a=[];for(let e=0;e<t.length&&e in t;++e){let[n,r]=t[e];r=s(r),n&&(r=unescape(r),e===0&&(r=c(r))),a.push(r)}return a.join(``)}function s(e){if(e.startsWith(`"`)){let t=e.slice(1).split(`\\"`);for(let e=0;e<t.length;++e){let n=t[e].indexOf(`"`);n!==-1&&(t[e]=t[e].slice(0,n),t.length=e+1),t[e]=t[e].replaceAll(/\\(.)/g,`$1`)}e=t.join(`"`)}return e}function c(e){let t=e.indexOf(`'`);return t===-1?e:i(e.slice(0,t),e.slice(t+1).replace(/^[^']*'/,``))}function l(e){return!e.startsWith(`=?`)||/[\x00-\x19\x80-\xff]/.test(e)?e:e.replaceAll(/=\?([\w-]*)\?([QB])\?((?:[^?]|\?(?!=))*)\?=/gi,function(e,t,n,r){if(n===`q`||n===`Q`)return r=r.replaceAll(`_`,` `),r=r.replaceAll(/=([0-9a-f]{2})/gi,function(e,t){return String.fromCharCode(parseInt(t,16))}),i(t,r);try{r=atob(r)}catch{}return i(t,r)})}return``}function $n(e,t){let n=new Headers;if(!e||!t||typeof t!=`object`)return n;for(let e in t){let r=t[e];r!==void 0&&n.append(e,r)}return n}function er(e){return URL.parse(e)?.origin??null}function tr({responseHeaders:e,isHttp:t,rangeChunkSize:n,disableRange:r}){let i={contentLength:0,isRangeSupported:!1},a=parseInt(e.get(`Content-Length`),10);return!Number.isInteger(a)||(i.contentLength=a,a<=2*n)||r||!t||e.get(`Accept-Ranges`)!==`bytes`||(e.get(`Content-Encoding`)||`identity`)===`identity`&&(i.isRangeSupported=!0),i}function nr(e){let t=e.get(`Content-Disposition`);if(t){let e=Qn(t);if(e.includes(`%`))try{e=decodeURIComponent(e)}catch{}if(V(e))return e}return null}function rr(e,t){return new fe(`Unexpected server response (${e}) while retrieving PDF "${t.href}".`,e,e===404||e===0&&t.protocol===`file:`)}function ir(e,t){if(e!==t)throw Error(`Expected range response-origin "${e}" to match "${t}".`)}function ar(e,t,n,r){return fetch(e,{method:`GET`,headers:t,signal:r.signal,mode:`cors`,credentials:n?`include`:`same-origin`,redirect:`follow`})}function or(e,t){if(e!==200&&e!==206)throw rr(e,t)}function sr(e){if(e instanceof Uint8Array)return e.buffer;if(e instanceof ArrayBuffer)return e;throw Error(`getArrayBuffer - unexpected data: ${e}`)}var cr=class extends Yn{_responseOrigin=null;constructor(e){super(e,lr,ur);let{httpHeaders:t,url:n}=e;F(/https?:/.test(n.protocol),`PDFFetchStream only supports http(s):// URLs.`),this.headers=$n(!0,t)}},lr=class extends Xn{_abortController=new AbortController;_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i,withCredentials:a}=e._source;this._isStreamingSupported=!n,ar(i,new Headers(e.headers),a,this._abortController).then(n=>{e._responseOrigin=er(n.url),or(n.status,i),this._reader=n.body.getReader();let a=n.headers,{contentLength:o,isRangeSupported:s}=tr({responseHeaders:a,isHttp:!0,rangeChunkSize:r,disableRange:t});this._contentLength=o,this._isRangeSupported=s,this._filename=nr(a),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new me(`Streaming is disabled.`)),this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:(this._loaded+=e.byteLength,this._callOnProgress(),{value:sr(e),done:!1})}cancel(e){this._reader?.cancel(e),this._abortController.abort()}},ur=class extends Zn{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r,withCredentials:i}=e._source,a=new Headers(e.headers);a.append(`Range`,`bytes=${t}-${n-1}`),ar(r,a,i,this._abortController).then(t=>{ir(er(t.url),e._responseOrigin),or(t.status,r),this._reader=t.body.getReader(),this._readCapability.resolve()}).catch(this._readCapability.reject)}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:sr(e),done:!1}}cancel(e){this._reader?.cancel(e),this._abortController.abort()}};function dr(e){return e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}function fr(){for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}var pr=class extends Yn{_progressiveDone=!1;_queuedChunks=[];constructor(e){super(e,mr,hr);let{pdfDataRangeTransport:t}=e,{initialData:n,progressiveDone:r}=t;if(n?.length>0){let e=dr(n);this._queuedChunks.push(e)}this._progressiveDone=r,t.transportReady(e=>{switch(e.type){case`range`:case`progressiveRead`:this.#e(e.begin,e.chunk);break;case`progressiveDone`:this._fullReader?.progressiveDone(),this._progressiveDone=!0;break}})}#e(e,t){let n=dr(t);if(e===void 0)this._fullReader?this._fullReader._enqueue(n):this._queuedChunks.push(n);else{let t=this._rangeReaders.keys().find(t=>t._begin===e);F(t,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found."),t._enqueue(n)}}getFullReader(){let e=super.getFullReader();return this._queuedChunks=null,e}getRangeReader(e,t){let n=super.getRangeReader(e,t);return n&&(n.onDone=()=>this._rangeReaders.delete(n),this._source.pdfDataRangeTransport.requestDataRange(e,t)),n}cancelAllRequests(e){super.cancelAllRequests(e),this._source.pdfDataRangeTransport.abort()}},mr=class extends Xn{#e=fr.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(e){super(e);let{pdfDataRangeTransport:t,disableRange:n,disableStream:r}=e._source,{length:i,contentDispositionFilename:a}=t;this._queuedChunks=e._queuedChunks||[];for(let e of this._queuedChunks)this._loaded+=e.byteLength;this._done=e._progressiveDone,this._contentLength=i,this._isStreamingSupported=!r,this._isRangeSupported=!n,V(a)&&(this._filename=a),this._headersCapability.resolve();let o=this._loaded;Promise.resolve().then(()=>{o>0&&this._loaded===o&&this._callOnProgress()})}_enqueue(e){this._done||(this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunks.push(e),this._loaded+=e.byteLength,this._callOnProgress())}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e()}progressiveDone(){this._done||=!0,this._queuedChunks.length===0&&this.#e()}},hr=class extends Zn{#e=fr.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(e,t,n){super(e,t,n),this._begin=t}_enqueue(e){this._done||(this._requests.length===0?this._queuedChunk=e:(this._requests.shift().resolve({value:e,done:!1}),this.#e()),this._done=!0,this.onDone?.())}async read(){if(this._queuedChunk){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e(),this.onDone?.()}},gr=200,_r=206;function vr(e){return typeof e==`string`?ge(e).buffer:e}var yr=class extends Yn{#e=new WeakMap;_responseOrigin=null;constructor(e){super(e,br,xr);let{httpHeaders:t,url:n}=e;this.url=n,this.isHttp=/https?:/.test(n.protocol),this.headers=$n(this.isHttp,t)}_request(e){let t=new XMLHttpRequest,n={validateStatus:null,onHeadersReceived:e.onHeadersReceived,onDone:e.onDone,onError:e.onError,onProgress:e.onProgress};this.#e.set(t,n),t.open(`GET`,this.url),t.withCredentials=this._source.withCredentials;for(let[e,n]of this.headers)t.setRequestHeader(e,n);return this.isHttp&&`begin`in e&&`end`in e?(t.setRequestHeader(`Range`,`bytes=${e.begin}-${e.end-1}`),n.validateStatus=e=>e===_r||e===gr):n.validateStatus=e=>e===gr,t.responseType=`arraybuffer`,F(e.onError,"Expected `onError` callback to be provided."),t.onerror=()=>e.onError(t.status),t.onreadystatechange=this.#n.bind(this,t),t.onprogress=this.#t.bind(this,t),t.send(null),t}#t(e,t){this.#e.get(e)?.onProgress?.(t)}#n(e,t){let n=this.#e.get(e);if(!n||(e.readyState>=2&&n.onHeadersReceived&&(n.onHeadersReceived(),delete n.onHeadersReceived),e.readyState!==4)||!this.#e.has(e))return;if(this.#e.delete(e),e.status===0&&this.isHttp){n.onError(e.status);return}let r=e.status||gr;if(!n.validateStatus(r)){n.onError(e.status);return}let i=vr(e.response);if(r===_r){let t=e.getResponseHeader(`Content-Range`);/bytes \d+-\d+\/\d+/.test(t)?n.onDone(i):(N(`Missing or invalid "Content-Range" header.`),n.onError(0))}else i?n.onDone(i):n.onError(e.status)}_abortRequest(e){this.#e.has(e)&&(this.#e.delete(e),e.abort())}getRangeReader(e,t){let n=super.getRangeReader(e,t);return n&&(n.onClosed=()=>this._rangeReaders.delete(n)),n}},br=class extends Xn{#e=fr.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(e){super(e),this._fullRequestXhr=e._request({onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:this.#i.bind(this)})}#t(){let e=this._stream,{disableRange:t,rangeChunkSize:n}=e._source,r=this._fullRequestXhr;e._responseOrigin=er(r.responseURL);let i=r.getAllResponseHeaders(),a=new Headers(i?i.trimStart().replace(/[^\S ]+$/,``).split(/[\r\n]+/).map(e=>{let[t,...n]=e.split(`: `);return[t,n.join(`: `)]}):[]),{contentLength:o,isRangeSupported:s}=tr({responseHeaders:a,isHttp:e.isHttp,rangeChunkSize:n,disableRange:t});this._contentLength=o,this._isRangeSupported=s,this._filename=nr(a),this._isRangeSupported&&e._abortRequest(r),this._headersCapability.resolve()}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._cachedChunks.push(e),this._done=!0,this._cachedChunks.length===0&&this.#e()}#r(e){this._storedError=rr(e,this._stream.url),this._headersCapability.reject(this._storedError);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}#i(e){this.onProgress?.({loaded:e.loaded,total:e.lengthComputable?e.total:this._contentLength})}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this._headersCapability.reject(e),this.#e(),this._stream._abortRequest(this._fullRequestXhr),this._fullRequestXhr=null}},xr=class extends Zn{#e=fr.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(e,t,n){super(e,t,n),this._requestXhr=e._request({begin:t,end:n,onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:null})}#t(){let e=er(this._requestXhr?.responseURL);try{ir(e,this._stream._responseOrigin)}catch(e){this._storedError=e,this.#r(0)}}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0,this.#e(),this.onClosed?.()}#r(e){this._storedError??=rr(e,this._stream.url);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e(),this._stream._abortRequest(this._requestXhr),this.onClosed?.()}};function Sr(e,t=null){let n=process.getBuiltinModule(`fs`),{Readable:r}=process.getBuiltinModule(`stream`),i=n.createReadStream(e,t);return r.toWeb(i)}var Cr=class extends Yn{constructor(e){super(e,wr,Tr);let{url:t}=e;F(t.protocol===`file:`,`PDFNodeStream only supports file:// URLs.`)}},wr=class extends Xn{_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i}=e._source;this._isStreamingSupported=!n,process.getBuiltinModule(`fs/promises`).lstat(i).then(e=>{let n=Sr(i);this._reader=n.getReader();let{size:a}=e;this._contentLength=a,this._isRangeSupported=!t&&a>2*r,!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new me(`Streaming is disabled.`)),this._headersCapability.resolve()}).catch(e=>{e.code===`ENOENT`&&(e=rr(0,i)),this._headersCapability.reject(e)})}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:(this._loaded+=e.byteLength,this._callOnProgress(),{value:sr(e),done:!1})}cancel(e){this._reader?.cancel(e)}},Tr=class extends Zn{_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r}=e._source;try{let e=Sr(r,{start:t,end:n-1});this._reader=e.getReader(),this._readCapability.resolve()}catch(e){this._readCapability.reject(e)}}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:sr(e),done:!1}}cancel(e){this._reader?.cancel(e)}};function Er(e){return Fe(e)?cr:f?Cr:yr}var Dr=class{static#e=null;static#t=``;static get workerPort(){return this.#e}static set workerPort(e){if(!(typeof Worker<`u`&&e instanceof Worker)&&e!==null)throw Error("Invalid `workerPort` type.");this.#e=e}static get workerSrc(){return this.#t}static set workerSrc(e){if(typeof e!=`string`)throw Error("Invalid `workerSrc` type.");this.#t=e}},Or=class{#e;#t;constructor({parsedData:e,rawData:t}){this.#e=e,this.#t=t}getRaw(){return this.#t}get(e){return this.#e.get(e)??null}[Symbol.iterator](){return this.#e.entries()}},kr=Symbol(`INTERNAL`),Ar=class{#e=!1;#t=!1;#n=!1;#r=!0;constructor(e,{name:t,intent:n,usage:r,rbGroups:i}){this.#e=!!(e&v.DISPLAY),this.#t=!!(e&v.PRINT),this.name=t,this.intent=n,this.usage=r,this.rbGroups=i}get visible(){if(this.#n)return this.#r;if(!this.#r)return!1;let{print:e,view:t}=this.usage;return this.#e?t?.viewState!==`OFF`:!this.#t||e?.printState!==`OFF`}_setVisible(e,t,n=!1){e!==kr&&P("Internal method `_setVisible` called."),this.#n=n,this.#r=t}get serializable(){return{userSet:this.#n,visible:this.#r}}},jr=class e{#e=null;#t=new Map;#n=null;#r=null;#i;creator=null;name=null;constructor(e,t=v.DISPLAY,n=null){if(this.#i=e,this.renderingIntent=t,e!==null){this.name=e.name,this.creator=e.creator,this.#r=e.order;for(let n of e.groups)this.#t.set(n.id,new Ar(t,n));if(n){n.size!==this.#t.size&&P(`Incorrect serialized groupState.`);for(let[e,t]of n)this.#t.get(e)._setVisible(kr,t.visible,t.userSet)}else{if(e.baseState===`OFF`)for(let e of this.#t.values())e._setVisible(kr,!1);for(let t of e.on)this.#t.get(t)._setVisible(kr,!0);for(let t of e.off)this.#t.get(t)._setVisible(kr,!1)}this.#n=this.getHash()}}#a(e){let t=e.length;if(t<2)return!0;let n=e[0];for(let r=1;r<t;r++){let t=e[r],i;if(Array.isArray(t))i=this.#a(t);else if(this.#t.has(t))i=this.#t.get(t).visible;else return N(`Optional content group not found: ${t}`),!0;switch(n){case`And`:if(!i)return!1;break;case`Or`:if(i)return!0;break;case`Not`:return!i;default:return!0}}return n===`And`}isVisible(e){if(this.#t.size===0)return!0;if(!e)return re(`Optional content group not defined.`),!0;if(e.type===`OCG`)return this.#t.has(e.id)?this.#t.get(e.id).visible:(N(`Optional content group not found: ${e.id}`),!0);if(e.type===`OCMD`){if(e.expression)return this.#a(e.expression);if(!e.policy||e.policy===`AnyOn`){for(let t of e.ids){if(!this.#t.has(t))return N(`Optional content group not found: ${t}`),!0;if(this.#t.get(t).visible)return!0}return!1}else if(e.policy===`AllOn`){for(let t of e.ids){if(!this.#t.has(t))return N(`Optional content group not found: ${t}`),!0;if(!this.#t.get(t).visible)return!1}return!0}else if(e.policy===`AnyOff`){for(let t of e.ids){if(!this.#t.has(t))return N(`Optional content group not found: ${t}`),!0;if(!this.#t.get(t).visible)return!0}return!1}else if(e.policy===`AllOff`){for(let t of e.ids){if(!this.#t.has(t))return N(`Optional content group not found: ${t}`),!0;if(this.#t.get(t).visible)return!1}return!0}return N(`Unknown optional content policy ${e.policy}.`),!0}return N(`Unknown group type ${e.type}.`),!0}setVisibility(e,t=!0,n=!0){let r=this.#t.get(e);if(!r){N(`Optional content group not found: ${e}`);return}if(n&&t&&r.rbGroups.length)for(let t of r.rbGroups)for(let n of t)n!==e&&this.#t.get(n)?._setVisible(kr,!1,!0);r._setVisible(kr,!!t,!0),this.#e=null}setOCGState({state:e,preserveRB:t}){let n;for(let r of e){switch(r){case`ON`:case`OFF`:case`Toggle`:n=r;continue}let e=this.#t.get(r);if(e)switch(n){case`ON`:this.setVisibility(r,!0,t);break;case`OFF`:this.setVisibility(r,!1,t);break;case`Toggle`:this.setVisibility(r,!e.visible,t);break}}this.#e=null}get hasInitialVisibility(){return this.#n===null||this.getHash()===this.#n}getOrder(){return this.#t.size?this.#r?this.#r.slice():[...this.#t.keys()]:null}getGroup(e){return this.#t.get(e)||null}getHash(){if(this.#e!==null)return this.#e;let e=new vt;for(let[t,n]of this.#t)e.update(`${t}:${n.visible}`);return this.#e=e.hexdigest()}[Symbol.iterator](){return this.#t.entries()}get serializable(){let e=new Map;for(let[t,n]of this.#t)e.set(t,n.serializable);return{data:this.#i,renderingIntent:this.renderingIntent,groupState:e}}static fromSerializable({data:t,renderingIntent:n,groupState:r}){return new e(t,n,r)}},Mr=class{#e=null;#t=null;#n=0;#r=null;#i=null;get pagesNumber(){return this.#n}set pagesNumber(e){this.#n!==e&&(this.#n=e,this.#e=null,this.#t=null)}#a(){if(this.#e)return;let e=this.#n,t=this.#e=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n+1;this.#t=new Int32Array(t)}#o(){let e=new Map,t=this.#e;for(let n=0,r=this.#n;n<r;n++){let r=t[n],i=e.get(r);i?i.push(n+1):e.set(r,[n+1])}return e}movePages(e,t,n){this.#a();let r=this.#e,i=this.#o(),a=t.length,o=new Uint32Array(a),s=0;for(let e=0;e<a;e++){let i=t[e]-1;o[e]=r[i],i<n&&s++}let c=this.#n,l=c-a,u=B(n-s,0,l);for(let t=0,n=0;t<c;t++)e.has(t+1)||(r[n++]=r[t]);r.copyWithin(u+a,u,l),r.set(o,u),this.#s(i),r.every((e,t)=>e===t+1)&&(this.#e=null)}deletePages(e){this.#a();let t=this.#e,n=this.#o();this.#i={pageNumberToId:t.slice(),pagesNumber:this.#n,prevPageNumbers:this.#t.slice()};let r=this.#n-e.length;this.#n=r;let i=this.#e=new Uint32Array(r);this.#t=new Int32Array(r);let a=0,o=0;for(let n of e){let e=n-1;e!==a&&(i.set(t.subarray(a,e),o),o+=e-a),a=e+1}a<t.length&&i.set(t.subarray(a),o),this.#s(n,new Set(e))}cancelDelete(){this.#i&&=(this.#e=this.#i.pageNumberToId,this.#n=this.#i.pagesNumber,this.#t=this.#i.prevPageNumbers,null)}cleanSavedData(){this.#i=null}copyPages(e){this.#a(),this.#r={pageNumbers:e,pageIds:e.map(e=>this.#e[e-1])}}cancelCopy(){this.#r=null}pastePages(e){this.#a();let t=this.#e,n=this.#o(),{pageNumbers:r,pageIds:i}=this.#r,a=this.#n+r.length;this.#n=a;let o=this.#e=new Uint32Array(a);this.#t=new Int32Array(a),o.set(t.subarray(0,e),0),o.set(i,e),o.set(t.subarray(e),e+r.length),this.#s(n,null,e,r),this.#r=null}#s(e,t=null,n=-1,r=null){let i=this.#t,a=this.#e,o=n+(r?.length??0),s=new Map;for(let c=0,l=this.#n;c<l;c++){if(c>=n&&c<o){i[c]=-r[c-n];continue}let l=a[c],u=e.get(l),d=s.get(l)||0;if(t&&u)for(;d<u.length&&t.has(u[d]);)d++;i[c]=u?.[d],s.set(l,d+1)}}hasBeenAltered(){return this.#e!==null}getPageMappingForSaving(e=null){e??=this.#o();let t=0;for(let n of e.values())t=Math.max(t,n.length);let n=Array(t);for(let e=0;e<t;e++)n[e]={document:null,pageIndices:[],includePages:[]};for(let[t,r]of e)for(let e=0,i=r.length;e<i;e++)n[e].includePages.push([t-1,r[e]-1]);for(let{includePages:e,pageIndices:t}of n){e.sort((e,t)=>e[0]-t[0]);for(let n=0,r=e.length;n<r;n++)t.push(e[n][1]),e[n]=e[n][0]}return n}extractPages(e){e=Array.from(e).sort((e,t)=>e-t);let t=new Map;for(let n=0,r=e.length;n<r;n++){let r=this.getPageId(e[n]);t.getOrInsertComputed(r,Se).push(n+1)}return this.getPageMappingForSaving(t)}getPrevPageNumber(e){return this.#t?.[e-1]??0}getPageNumber(e){if(!this.#e)return e;let t=this.#e;for(let n=0,r=this.#n;n<r;n++)if(t[n]===e)return n+1;return 0}getPageId(e){return this.#e?.[e-1]??e}getMapping(){return this.#e?.subarray(0,this.pagesNumber)}},Nr=Symbol(`INITIAL_DATA`),Pr=()=>({...Promise.withResolvers(),data:Nr}),Fr=class{#e=new Map;get(e,t=null){if(t){let n=this.#e.getOrInsertComputed(e,Pr);return n.promise.then(()=>t(n.data)),null}let n=this.#e.get(e);if(!n||n.data===Nr)throw Error(`Requesting object that isn't resolved yet ${e}.`);return n.data}has(e){let t=this.#e.get(e);return!!t&&t.data!==Nr}delete(e){let t=this.#e.get(e);return!t||t.data===Nr?!1:(this.#e.delete(e),!0)}resolve(e,t=null){let n=this.#e.getOrInsertComputed(e,Pr);if(n.data!==Nr)throw Error(`Object already resolved ${e}.`);n.data=t,n.resolve()}clear(){for(let{data:e}of this.#e.values())e?.bitmap?.close();this.#e.clear()}*[Symbol.iterator](){for(let[e,{data:t}]of this.#e)t!==Nr&&(yield[e,t])}},Ir=1e5,Lr=30,Rr=class e{#e=Promise.withResolvers();#t=null;#n=!1;#r=!!globalThis.FontInspector?.enabled;#i=null;#a=null;#o=null;#s=0;#c=0;#l=null;#u=null;#d=0;#f=0;#p=Object.create(null);#m=[];#h=null;#g=[];#_=new WeakMap;#v=null;static#y=new Map;static#b=new Map;static#x=new WeakMap;static#S=null;static#C=new Set;constructor({textContentSource:t,images:n,container:r,viewport:i}){if(t instanceof ReadableStream)this.#h=t;else if(typeof t==`object`)this.#h=new ReadableStream({start(e){e.enqueue(t),e.close()}});else throw Error(`No "textContentSource" parameter specified.`);this.#t=this.#u=r,this.#i=n,this.#f=i.scale*He.pixelRatio,this.#d=i.rotation,this.#o={div:null,properties:null,ctx:null};let{pageWidth:a,pageHeight:o,pageX:s,pageY:c}=i.rawDims;this.#v=[1,0,0,-1,-s,c+o],this.#c=a,this.#s=o,e.#k(),r.style.setProperty(`--min-font-size`,e.#S),Ve(r,i),this.#e.promise.finally(()=>{e.#C.delete(this),this.#o=null,this.#p=null}).catch(()=>{})}static get fontFamilyMap(){let{isWindows:e,isFirefox:t}=L.platform;return I(this,`fontFamilyMap`,new Map([[`sans-serif`,`${e&&t?`Calibri, `:``}sans-serif`],[`monospace`,`${e&&t?`Lucida Console, `:``}monospace`]]))}render(){this.#i&&this.#t.append(this.#i.render());let t=()=>{this.#l.read().then(({value:e,done:n})=>{if(n){this.#e.resolve();return}this.#a??=e.lang,Object.assign(this.#p,e.styles),this.#w(e.items),t()},this.#e.reject)};return this.#l=this.#h.getReader(),e.#C.add(this),t(),this.#e.promise}update({viewport:t,onBefore:n=null}){let r=t.scale*He.pixelRatio,i=t.rotation;if(i!==this.#d&&(n?.(),this.#d=i,Ve(this.#u,{rotation:i})),r!==this.#f){n?.(),this.#f=r;let t={div:null,properties:null,ctx:e.#D(this.#a)};for(let e of this.#g)t.properties=this.#_.get(e),t.div=e,this.#E(t)}}cancel(){let e=new me(`TextLayer task cancelled.`);this.#l?.cancel(e).catch(()=>{}),this.#l=null,this.#e.reject(e)}get textDivs(){return this.#g}get textContentItemsStr(){return this.#m}#w(t){if(this.#n)return;this.#o.ctx??=e.#D(this.#a);let n=this.#g,r=this.#m;for(let e of t){if(n.length>Ir){N(`Ignoring additional textDivs for performance reasons.`),this.#n=!0;return}if(e.str===void 0){if(e.type===`beginMarkedContentProps`||e.type===`beginMarkedContent`){let t=this.#t;this.#t=document.createElement(`span`),this.#t.classList.add(`markedContent`),e.id&&this.#t.setAttribute(`id`,`${e.id}`),e.tag===`Artifact`&&(this.#t.ariaHidden=!0),t.append(this.#t)}else e.type===`endMarkedContent`&&(this.#t=this.#t.parentNode);continue}r.push(e.str),this.#T(e)}}#T(t){let n=document.createElement(`span`),r={angle:0,canvasWidth:0,hasText:t.str!==``,hasEOL:t.hasEOL,fontSize:0};this.#g.push(n);let i=R.transform(this.#v,t.transform),a=Math.atan2(i[1],i[0]),o=this.#p[t.fontName];o.vertical&&(a+=Math.PI/2);let s=this.#r&&o.fontSubstitution||o.fontFamily;s=e.fontFamilyMap.get(s)||s;let c=Math.hypot(i[2],i[3]),l=c*e.#A(s,o,this.#a),u,d;a===0?(u=i[4],d=i[5]-l):(u=i[4]+l*Math.sin(a),d=i[5]-l*Math.cos(a));let f=n.style;f.left=`${(100*u/this.#c).toFixed(2)}%`,f.top=`${(100*d/this.#s).toFixed(2)}%`,f.setProperty(`--font-height`,`${c.toFixed(2)}px`),f.fontFamily=s,r.fontSize=c,n.setAttribute(`role`,`presentation`),n.textContent=t.str,n.dir=t.dir,this.#r&&(n.dataset.fontName=o.fontSubstitutionLoadedName||t.fontName),a!==0&&(r.angle=180/Math.PI*a);let p=!1;if(t.str.length>1)p=!0;else if(t.str!==` `&&t.transform[0]!==t.transform[3]){let e=Math.abs(t.transform[0]),n=Math.abs(t.transform[3]);e!==n&&Math.max(e,n)/Math.min(e,n)>1.5&&(p=!0)}if(p&&(r.canvasWidth=o.vertical?t.height:t.width),this.#_.set(n,r),this.#o.div=n,this.#o.properties=r,this.#E(this.#o),r.hasText&&this.#t.append(n),r.hasEOL){let e=document.createElement(`br`);e.setAttribute(`role`,`presentation`),this.#t.append(e)}}#E(t){let{div:n,properties:r,ctx:i}=t,{style:a}=n;if(r.canvasWidth!==0&&r.hasText){let{fontFamily:t}=a,{canvasWidth:o,fontSize:s}=r;e.#O(i,s*this.#f,t);let{width:c}=i.measureText(n.textContent);c>0&&a.setProperty(`--scale-x`,o*this.#f/c)}r.angle!==0&&a.setProperty(`--rotate`,`${r.angle}deg`)}static cleanup(){if(!(this.#C.size>0)){this.#y.clear();for(let{canvas:e}of this.#b.values())e.remove();this.#b.clear()}}static#D(e=null){let t=this.#b.get(e||=``);if(!t){let n=document.createElement(`canvas`);n.style.cssText=`position:absolute;top:0;left:0;width:0;height:0;display:none;letter-spacing:normal;word-spacing:normal`,n.lang=e,document.body.append(n),t=n.getContext(`2d`,{alpha:!1,willReadFrequently:!0}),this.#b.set(e,t),this.#x.set(t,{size:0,family:``})}return t}static#O(e,t,n){let r=this.#x.get(e);t===r.size&&n===r.family||(e.font=`${t}px ${n}`,r.size=t,r.family=n)}static#k(){if(this.#S!==null)return;let e=document.createElement(`div`);e.style.opacity=0,e.style.lineHeight=1,e.style.fontSize=`1px`,e.style.position=`absolute`,e.textContent=`X`,document.body.append(e),this.#S=e.getBoundingClientRect().height,e.remove()}static#A(e,t,n){let r=this.#y.get(e);if(r)return r;let i=this.#D(n);i.canvas.width=i.canvas.height=Lr,this.#O(i,Lr,e);let a=i.measureText(``),o=a.fontBoundingBoxAscent,s=Math.abs(a.fontBoundingBoxDescent);i.canvas.width=i.canvas.height=0;let c=.8;return o?c=o/(o+s):(L.platform.isFirefox&&N("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering."),t.ascent?c=t.ascent:t.descent&&(c=1+t.descent)),this.#y.set(e,c),c}},zr=100;function Br(e={}){let t=new Vr,{docId:n}=t,r=e.url?Kt(e.url):null,i=e.data?qt(e.data):null,a=e.httpHeaders||null,o=e.withCredentials===!0,s=e.password??null,c=e.range instanceof Hr?e.range:null,l=Number.isInteger(e.rangeChunkSize)&&e.rangeChunkSize>0?e.rangeChunkSize:2**16,u=e.worker instanceof Gr?e.worker:null,d=e.verbosity,p=typeof e.docBaseUrl==`string`&&!je(e.docBaseUrl)?e.docBaseUrl:null,m=Jt(e.cMapUrl),h=e.cMapPacked!==!1,g=Jt(e.iccUrl),_=Jt(e.standardFontDataUrl),v=Jt(e.wasmUrl),y=e.stopAtErrors!==!0,b=Number.isInteger(e.maxImageSize)&&e.maxImageSize>-1?e.maxImageSize:-1,x=typeof e.isOffscreenCanvasSupported==`boolean`?e.isOffscreenCanvasSupported:!f,S=typeof e.isImageDecoderSupported==`boolean`?e.isImageDecoderSupported:!f,C=Number.isInteger(e.canvasMaxAreaInBytes)?e.canvasMaxAreaInBytes:-1,w=typeof e.disableFontFace==`boolean`?e.disableFontFace:f,T=e.fontExtraProperties===!0,E=e.enableXfa===!0,D=e.ownerDocument||globalThis.document,O=e.disableRange===!0,k=e.disableStream===!0,A=e.disableAutoFetch===!0,j=e.pdfBug===!0,M=e.CanvasFactory||(f?dn:an),ee=e.FilterFactory||(f?un:sn),ne=e.BinaryDataFactory||(f?fn:nn),re=e.enableHWA===!0,N=e.enableWebGPU===!0?_n():Promise.resolve(!1),P=e.useWasm!==!1,F=e.pagesMapper||new Mr,ie=typeof e.useSystemFonts==`boolean`?e.useSystemFonts:!f&&!w,ae=typeof e.useWorkerFetch==`boolean`?e.useWorkerFetch:!!(ne===nn&&m&&h&&_&&v&&Fe(m,document.baseURI)&&Fe(_,document.baseURI)&&Fe(v,document.baseURI));te(d);let oe={canvasFactory:new M({ownerDocument:D,enableHWA:re}),filterFactory:new ee({docId:n,ownerDocument:D}),binaryDataFactory:ae?null:new ne({cMapUrl:m,standardFontDataUrl:_,wasmUrl:v})};u||(u=Gr.create({verbosity:d,port:Dr.workerPort}),t._worker=u);let se={docId:n,apiVersion:`6.1.200`,data:i,password:s,disableAutoFetch:A,rangeChunkSize:l,docBaseUrl:p,enableXfa:E,evaluatorOptions:{maxImageSize:b,disableFontFace:w,ignoreErrors:y,isOffscreenCanvasSupported:x,isImageDecoderSupported:S,canvasMaxAreaInBytes:C,fontExtraProperties:T,useSystemFonts:ie,useWasm:P,useWorkerFetch:ae,cMapUrl:m,cMapPacked:h,iccUrl:g,standardFontDataUrl:_,wasmUrl:v,hasGPU:!1}},I={ownerDocument:D,pdfBug:j,styleElement:null,enableHWA:re,loadingParams:{disableAutoFetch:A,enableXfa:E}};return Promise.all([u.promise,N]).then(function([,e]){if(u.destroyed)throw Error(`Worker was destroyed`);se.evaluatorOptions.hasGPU=e;let s=u.messageHandler.sendWithPromise(`GetDocRequest`,se,i?[i.buffer]:null),d;if(!i)if(c)d=new pr({pdfDataRangeTransport:c,disableRange:O,disableStream:k});else if(r)d=new(Er(r))({url:r,httpHeaders:a,withCredentials:o,rangeChunkSize:l,disableRange:O,disableStream:k});else throw Error("getDocument - expected either `data`, `range`, or `url` parameter.");return s.then(e=>{if(u.destroyed)throw Error(`Worker was destroyed`);let r=new en(n,e,u.port),i=new Kr(r,t,d,I,oe,F);if(t._transport=i,t.destroyed)throw Error(`Loading aborted`);r.send(`Ready`,null)})}).catch(t._capability.reject).finally(t._setupCapability.resolve),t}var Vr=class e{static#e=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;docId=`d${e.#e++}`;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0,this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0),await this._setupCapability.promise,await this._transport?.destroy()}catch(e){throw this._worker?.port&&delete this._worker._pendingDestroy,e}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}},Hr=class{#e=Promise.withResolvers();#t=null;constructor(e,t,n=!1,r=null){this.length=e,this.initialData=t,this.progressiveDone=n,this.contentDispositionFilename=r}onDataRange(e,t){this.#t({type:`range`,begin:e,chunk:t})}onDataProgressiveRead(e){this.#e.promise.then(()=>{this.#t({type:`progressiveRead`,chunk:e})})}onDataProgressiveDone(){this.#e.promise.then(()=>{this.#t({type:`progressiveDone`})})}transportReady(e){this.#t=e,this.#e.resolve()}requestDataRange(e,t){P(`Abstract method PDFDataRangeTransport.requestDataRange`)}abort(){}},Ur=class{constructor(e,t){this._pdfInfo=e,this._transport=t}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return I(this,`isPureXfa`,!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(e){return this._transport.getPage(e)}getPageIndex(e){return this._transport.getPageIndex(e)}getDestinations(){return this._transport.getDestinations()}getDestination(e){return this._transport.getDestination(e)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAttachmentContent(e){return this._transport.getAttachmentContent(e)}getAnnotationsByType(e,t){return this._transport.getAnnotationsByType(e,t)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getOptionalContentConfig(t)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}extractPages(e){return this._transport.extractPages(e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}getRawData(e){return this._transport.getRawData(e)}cleanup(e=!1){return this._transport.startCleanup(e||this.isPureXfa)}cachedPageNumber(e){return this._transport.cachedPageNumber(e)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}},Wr=class e{#e=!1;#t=null;constructor(e,t,n,r,i=!1){this._pageIndex=e,this._pageInfo=t,this._transport=n,this._stats=i?new Pe:null,this._pdfBug=i,this.commonObjs=n.commonObjs,this.objs=new Fr,this._intentStates=new Map,this.destroyed=!1,this.recordedBBoxes=null,this.#t=r,this.imageCoordinates=null}clone(t){let n=new e(t,this._pageInfo,this._transport,this.#t,this._pdfBug);return n.clonedFromIndex=this.clonedFromIndex??this._pageIndex,this._transport.updatePage(n),n}get pageNumber(){return this._pageIndex+1}set pageNumber(e){this._pageIndex=e-1,this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:e,rotation:t=this.rotate,offsetX:n=0,offsetY:r=0,dontFlip:i=!1}={}){return new Te({viewBox:this.view,userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}getAnnotations({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getAnnotations(this._pageIndex,t)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return I(this,`isPureXfa`,!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:e,canvas:t=e.canvas,viewport:n,intent:r=`display`,annotationMode:i=y.ENABLE,transform:a=null,background:o=null,optionalContentConfigPromise:s=null,annotationCanvasMap:c=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1,recordImages:f=!1,recordOperations:p=!1,operationsFilter:m=null}){this._stats?.time(`Overall`);let h=this._transport.getRenderingIntent(r,i,u,d),{renderingIntent:g,cacheKey:_}=h;this.#e=!1,s||=this._transport.getOptionalContentConfig(g);let b=this._intentStates.getOrInsertComputed(_,we);b.streamReaderCancelTimeout&&=(clearTimeout(b.streamReaderCancelTimeout),null);let x=!!(g&v.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time(`Page Request`),this._pumpOperatorList(h));let S=!!(this._pdfBug&&globalThis.StepperManager?.enabled),C=!!t&&!this.recordedBBoxes&&(p||S),w=!!t&&!this.imageCoordinates&&f,T=e=>{if(b.renderTasks.delete(O),C){let e=O.gfx?.dependencyTracker.take();e&&(O.stepper?.setOperatorBBoxes(e,O.gfx.dependencyTracker.takeDebugMetadata()),p&&(this.recordedBBoxes=e))}w&&!e&&(this.imageCoordinates=O.gfx?.imagesTracker.take()),x&&(this.#e=!0),this.#n(),e?(O.capability.reject(e),this._abortOperatorList({intentState:b,reason:e instanceof Error?e:Error(e)})):O.capability.resolve(),this._stats&&(this._stats.timeEnd(`Rendering`),this._stats.timeEnd(`Overall`),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},E=null,D=null;(C||w)&&(D=new At(t,b.operatorList.length)),C&&(E=new jt(D,S));let O=new Jr({callback:T,params:{canvas:t,canvasContext:e,dependencyTracker:E??D,imagesTracker:w?new Pt(t):null,viewport:n,transform:a,background:o},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:c,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!x,pdfBug:this._pdfBug,pageColors:l,enableHWA:this._transport.enableHWA,operationsFilter:m});(b.renderTasks||=new Set).add(O);let k=O.task;return Promise.all([b.displayReadyCapability.promise,s]).then(([e,t])=>{if(this.destroyed){T();return}if(this._stats?.time(`Rendering`),!(t.renderingIntent&g))throw Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");O.initializeGraphics({transparency:e,optionalContentConfig:t}),O.operatorListChanged()}).catch(T),k}getOperatorList({intent:e=`display`,annotationMode:t=y.ENABLE,printAnnotationStorage:n=null,isEditing:r=!1}={}){function i(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(s))}let a=this._transport.getRenderingIntent(e,t,n,r,!0),o=this._intentStates.getOrInsertComputed(a.cacheKey,we),s;return o.opListReadCapability||(s=Object.create(null),s.operatorListChanged=i,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||=new Set).add(s),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time(`Page Request`),this._pumpOperatorList(a)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:e=!1,disableNormalization:t=!1}={}){return this._transport.messageHandler.sendWithStream(`GetTextContent`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:e===!0,disableNormalization:t===!0},{highWaterMark:100,size(e){return e.items.length}})}async getTextContent(e={}){if(this._transport._htmlForXfa)return this.getXfa().then(e=>Ee.textContent(e));let t=this.streamTextContent(e),n={items:[],styles:Object.create(null),lang:null};for await(let e of t)n.lang??=e.lang,Object.assign(n.styles,e.styles),n.items.push(...e.items);return n}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;let e=[];for(let t of this._intentStates.values())if(this._abortOperatorList({intentState:t,reason:Error(`Page was destroyed.`),force:!0}),!t.opListReadCapability)for(let n of t.renderTasks)e.push(n.completed),n.cancel();return this.objs.clear(),this.#e=!1,Promise.all(e)}cleanup(e=!1){this.#e=!0;let t=this.#n();return e&&t&&(this._stats&&=new Pe),t}#n(){if(!this.#e||this.destroyed)return!1;for(let{renderTasks:e,operatorList:t}of this._intentStates.values())if(e.size>0||!t.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#e=!1,!0}_startRenderPage(e,t){let n=this._intentStates.get(t);n&&(this._stats?.timeEnd(`Page Request`),n.displayReadyCapability?.resolve(e))}_renderPageChunk(e,t){for(let n=0,r=e.length;n<r;n++)t.operatorList.fnArray.push(e.fnArray[n]),t.operatorList.argsArray.push(e.argsArray[n]);t.operatorList.lastChunk=e.lastChunk,t.operatorList.separateAnnots=e.separateAnnots;for(let e of t.renderTasks)e.operatorListChanged();e.lastChunk&&this.#n()}_pumpOperatorList({renderingIntent:e,cacheKey:t,annotationStorageSerializable:n,modifiedIds:r}){let{map:i,transfer:a}=n,o=this._transport.messageHandler.sendWithStream(`GetOperatorList`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,intent:e,cacheKey:t,annotationStorage:i,modifiedIds:r},void 0,a).getReader(),s=this._intentStates.get(t);s.streamReader=o;let c=()=>{o.read().then(({value:e,done:t})=>{if(t){s.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(e,s),c())},e=>{if(s.streamReader=null,!this._transport.destroyed){if(s.operatorList){s.operatorList.lastChunk=!0;for(let e of s.renderTasks)e.operatorListChanged();this.#n()}if(s.displayReadyCapability)s.displayReadyCapability.reject(e);else if(s.opListReadCapability)s.opListReadCapability.reject(e);else throw e}})};c()}_abortOperatorList({intentState:e,reason:t,force:n=!1}){if(e.streamReader){if(e.streamReaderCancelTimeout&&=(clearTimeout(e.streamReaderCancelTimeout),null),!n){if(e.renderTasks.size>0)return;if(t instanceof Ae){let n=zr;t.extraDelay>0&&t.extraDelay<1e3&&(n+=t.extraDelay),e.streamReaderCancelTimeout=setTimeout(()=>{e.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:e,reason:t,force:!0})},n);return}}if(e.streamReader.cancel(new me(t.message)).catch(()=>{}),e.streamReader=null,!this._transport.destroyed){for(let[t,n]of this._intentStates)if(n===e){this._intentStates.delete(t);break}this.cleanup()}}}get stats(){return this._stats}},Gr=class e{#e=Promise.withResolvers();#t=null;#n=null;#r=null;static#i=0;static#a=!1;static#o=new WeakMap;static{f&&(this.#a=!0,Dr.workerSrc||=`./pdf.worker.mjs`),this._isSameOrigin=(e,t)=>{let n=URL.parse(e);if(!n?.origin||n.origin===`null`)return!1;let r=new URL(t,n);return n.origin===r.origin},this._createCDNWrapper=e=>{let t=`await import("${e}");`;return URL.createObjectURL(new Blob([t],{type:`text/javascript`}))}}constructor({name:t=null,port:n=null,verbosity:r=ne()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=r,n){if(e.#o.has(n))throw Error(`Cannot use more than one PDFWorker per port.`);e.#o.set(n,this),this.#c(n)}else this.#l()}get promise(){return this.#e.promise}#s(){this.#e.resolve(),this.#t.send(`configure`,{verbosity:this.verbosity})}get port(){return this.#n}get messageHandler(){return this.#t}#c(e){this.#n=e,this.#t=new en(`main`,`worker`,e),this.#t.on(`ready`,()=>{}),this.#s()}#l(){if(e.#a||e.#d){this.#u();return}let{workerSrc:t}=e;try{e._isSameOrigin(window.location,t)||(t=e._createCDNWrapper(new URL(t,window.location).href));let n=new Worker(t,{type:`module`}),r=new en(`main`,`worker`,n),i=()=>{a.abort(),r.destroy(),n.terminate(),this.destroyed?this.#e.reject(Error(`Worker was destroyed`)):this.#u()},a=new AbortController;n.addEventListener(`error`,()=>{this.#r||i()},{signal:a.signal}),r.on(`test`,e=>{if(a.abort(),this.destroyed||!e){i();return}this.#t=r,this.#n=n,this.#r=n,this.#s()}),r.on(`ready`,e=>{if(a.abort(),this.destroyed){i();return}try{o()}catch{this.#u()}});let o=()=>{let e=new Uint8Array;r.send(`test`,e,[e.buffer])};o();return}catch{re(`The worker has been disabled.`)}this.#u()}#u(){e.#a||=(N(`Setting up fake worker.`),!0),e._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this.#e.reject(Error(`Worker was destroyed`));return}let n=new Zt;this.#n=n;let r=`fake${e.#i++}`,i=new en(r+`_worker`,r,n);t.setup(i,n),this.#t=new en(r,r+`_worker`,n),this.#s()}).catch(e=>{this.#e.reject(Error(`Setting up fake worker failed: "${e.message}".`))})}destroy(){this.destroyed=!0,this.#r?.terminate(),this.#r=null,e.#o.delete(this.#n),this.#n=null,this.#t?.destroy(),this.#t=null}static create(t){let n=this.#o.get(t?.port);if(n){if(n._pendingDestroy)throw Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return n}return new e(t)}static get workerSrc(){if(Dr.workerSrc)return Dr.workerSrc;throw Error(`No "GlobalWorkerOptions.workerSrc" specified.`)}static get#d(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return I(this,`_setupFakeWorkerGlobal`,(async()=>this.#d?this.#d:(await import(this.workerSrc)).WorkerMessageHandler)())}},Kr=class{downloadInfoCapability=Promise.withResolvers();#e=null;#t=new Map;#n=null;#r=new Map;#i=new Map;#a=new Map;#o=null;constructor(e,t,n,r,i,a){this.messageHandler=e,this.loadingTask=t,this.#n=n,this.commonObjs=new Fr,this.fontLoader=new Ft({ownerDocument:r.ownerDocument,styleElement:r.styleElement}),this.enableHWA=r.enableHWA,this.loadingParams=r.loadingParams,this._params=r,this.canvasFactory=i.canvasFactory,this.filterFactory=i.filterFactory,this.binaryDataFactory=i.binaryDataFactory,this.pagesMapper=a,this.destroyed=!1,this.destroyCapability=null,this.setupMessageHandler()}updatePage(e){let{_pageIndex:t}=e;this.#r.set(t,e),this.#i.set(t,Promise.resolve(e))}#s(e,t=null){return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,t))}#c({loaded:e,total:t}){this.loadingTask.onProgress?.({loaded:e,total:t,percent:t?B(Math.round(e/t*100),0,100):NaN})}get annotationStorage(){return I(this,`annotationStorage`,new bt)}getRenderingIntent(e,t=y.ENABLE,n=null,r=!1,i=!1){let a=v.DISPLAY,o=yt;switch(e){case`any`:a=v.ANY;break;case`display`:break;case`print`:a=v.PRINT;break;default:N(`getRenderingIntent - invalid intent: ${e}`)}let s=a&v.PRINT&&n instanceof xt?n:this.annotationStorage;switch(t){case y.DISABLE:a+=v.ANNOTATIONS_DISABLE;break;case y.ENABLE:break;case y.ENABLE_FORMS:a+=v.ANNOTATIONS_FORMS;break;case y.ENABLE_STORAGE:a+=v.ANNOTATIONS_STORAGE,o=s.serializable;break;default:N(`getRenderingIntent - invalid annotationMode: ${t}`)}r&&(a+=v.IS_EDITING),i&&(a+=v.OPLIST);let{ids:c,hash:l}=s.modifiedIds,u=[a,o.hash,l];return{renderingIntent:a,cacheKey:u.join(`_`),annotationStorageSerializable:o,modifiedIds:c}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#o?.reject(Error(`Worker was destroyed during onPassword callback`));let e=[];for(let t of this.#r.values())e.push(t._destroy());this.#r.clear(),this.#i.clear(),this.#a.clear(),Object.hasOwn(this,`annotationStorage`)&&this.annotationStorage.resetModified();let t=this.messageHandler.sendWithPromise(`Terminate`,null);return e.push(t),Promise.all(e).then(()=>{this.commonObjs.clear(),this.fontLoader.clear(),this.#t.clear(),this.filterFactory.destroy(),Rr.cleanup(),this.#n?.cancelAllRequests(new me(`Worker was terminated.`)),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:e,loadingTask:t}=this;e.on(`GetReader`,(e,t)=>{F(this.#n,"GetReader - no `BasePDFStream` instance available."),this.#e=this.#n.getFullReader(),this.#e.onProgress=e=>this.#c(e),t.onPull=()=>{this.#e.read().then(function({value:e,done:n}){if(n){t.close();return}F(e instanceof ArrayBuffer,`GetReader - expected an ArrayBuffer.`),t.enqueue(new Uint8Array(e),1,[e])}).catch(e=>{t.error(e)})},t.onCancel=e=>{this.#e.cancel(e),t.ready.catch(e=>{if(!this.destroyed)throw e})}}),e.on(`ReaderHeadersReady`,async e=>{await this.#e.headersReady;let{isStreamingSupported:t,isRangeSupported:n,contentLength:r}=this.#e;return t&&n&&(this.#e.onProgress=null),{isStreamingSupported:t,isRangeSupported:n,contentLength:r}}),e.on(`GetRangeReader`,(e,t)=>{F(this.#n,"GetRangeReader - no `BasePDFStream` instance available.");let n=this.#n.getRangeReader(e.begin,e.end);if(!n){t.close();return}t.onPull=()=>{n.read().then(function({value:e,done:n}){if(n){t.close();return}F(e instanceof ArrayBuffer,`GetRangeReader - expected an ArrayBuffer.`),t.enqueue(new Uint8Array(e),1,[e])}).catch(e=>{t.error(e)})},t.onCancel=e=>{n.cancel(e),t.ready.catch(e=>{if(!this.destroyed)throw e})}}),e.on(`GetDoc`,({pdfInfo:e})=>{this.pagesMapper.pagesNumber=e.numPages,this._numPages=e.numPages,this._htmlForXfa=e.htmlForXfa,delete e.htmlForXfa,t._capability.resolve(new Ur(e,this))}),e.on(`DocException`,e=>{t._capability.reject(J(e))}),e.on(`PasswordRequest`,e=>{this.#o=Promise.withResolvers();try{if(!t.onPassword)throw J(e);t.onPassword(e=>{e instanceof Error?this.#o.reject(e):this.#o.resolve({password:e})},e.code)}catch(e){this.#o.reject(e)}return this.#o.promise}),e.on(`DataLoaded`,e=>{this.#c({loaded:e.length,total:e.length}),this.downloadInfoCapability.resolve(e)}),e.on(`StartRenderPage`,e=>{this.destroyed||this.#r.get(e.pageIndex)._startRenderPage(e.transparency,e.cacheKey)}),e.on(`commonobj`,([t,n,r])=>{if(this.destroyed||this.commonObjs.has(t))return null;switch(n){case`Font`:if(`error`in r){let e=r.error;N(`Error during font loading: ${e}`),this.commonObjs.resolve(t,e);break}let i=new It(new Ut(r),this._params.pdfBug&&globalThis.FontInspector?.enabled?(e,t)=>globalThis.FontInspector.fontAdded(e,t):null,r.charProcOperatorList,r.extra);this.fontLoader.bind(i).catch(()=>e.sendWithPromise(`FontFallback`,{id:t})).finally(()=>{i.fontExtraProperties||i.clearData(),this.commonObjs.resolve(t,i)});break;case`CopyLocalImage`:let{imageRef:a}=r;F(a,`The imageRef must be defined.`);for(let e of this.#r.values())for(let[,n]of e.objs){if(n?.ref!==a)continue;if(!n.dataLen)return null;let e=structuredClone(n);return this.commonObjs.resolve(t,e),n.dataLen}break;case`FontPath`:this.commonObjs.resolve(t,new Gt(r));break;case`Image`:this.commonObjs.resolve(t,r);break;case`Pattern`:let o=new Wt(r);this.commonObjs.resolve(t,o.getIR());break;default:throw Error(`Got unknown common object type ${n}`)}return null}),e.on(`obj`,([e,t,n,r])=>{if(this.destroyed)return;let i=this.#r.get(t);if(!i.objs.has(e)){if(i._intentStates.size===0){r?.bitmap?.close();return}switch(n){case`Image`:case`Pattern`:i.objs.resolve(e,r);break;default:throw Error(`Got unknown object type ${n}`)}}}),e.on(`DocProgress`,e=>{this.destroyed||this.#c(e)}),e.on(`FetchBinaryData`,async e=>{if(this.destroyed)throw Error(`Worker was destroyed.`);if(!this.binaryDataFactory)throw Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(e)})}getData(){return this.messageHandler.sendWithPromise(`GetData`,null)}saveDocument(){this.annotationStorage.size<=0&&N("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{map:e,transfer:t}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise(`SaveDocument`,{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,filename:this.#e?.filename??null},t).finally(()=>{this.annotationStorage.resetModified()})}extractPages(e){let t={pageInfos:e},n,r=globalThis.ImageBitmap;if(typeof r==`function`){let t=Array.isArray(e)?e:[e];for(let e of t)e?.image instanceof r&&(n||=[]).push(e.image)}if(this.annotationStorage.size>0){let e=this.annotationStorage.serializable,{map:r}=e;e.transfer?.length&&(n?n.push(...e.transfer):n=e.transfer);let i=this.pagesMapper.getMapping();if(i){let e=new Map;for(let[t,n]of r){if(n?.pageIndex!==void 0&&n.pageIndex>=0&&n.pageIndex<i.length){let r=i[n.pageIndex]-1;if(r!==n.pageIndex){e.set(t,{...n,pageIndex:r});continue}}e.set(t,n)}r=e}t.annotationStorage=r}return this.messageHandler.sendWithPromise(`ExtractPages`,t,n).finally(()=>{this.annotationStorage.resetModified()})}getPage(e){if(!Number.isInteger(e)||e<=0||e>this.pagesMapper.pagesNumber)return Promise.reject(Error(`Invalid page request.`));let t=e-1,n=this.pagesMapper.getPageId(e)-1,r=this.#i.get(t);if(r)return r;let i=this.messageHandler.sendWithPromise(`GetPage`,{pageIndex:n}).then(e=>{if(this.destroyed)throw Error(`Transport destroyed`);e.refStr&&this.#a.set(e.refStr,n);let r=new Wr(t,e,this,this.pagesMapper,this._params.pdfBug);return this.#r.set(t,r),r});return this.#i.set(t,i),i}async getPageIndex(e){if(!Yt(e))throw Error(`Invalid pageIndex request.`);let t=await this.messageHandler.sendWithPromise(`GetPageIndex`,{num:e.num,gen:e.gen}),n=this.pagesMapper.getPageNumber(t+1);if(n===0)throw Error(`GetPageIndex: page has been removed.`);return n-1}getAnnotations(e,t){return this.messageHandler.sendWithPromise(`GetAnnotations`,{pageIndex:this.pagesMapper.getPageId(e+1)-1,intent:t})}getFieldObjects(){return this.#s(`GetFieldObjects`)}hasJSActions(){return this.#s(`HasJSActions`)}getCalculationOrderIds(){return this.messageHandler.sendWithPromise(`GetCalculationOrderIds`,null)}getDestinations(){return this.messageHandler.sendWithPromise(`GetDestinations`,null)}getDestination(e){return typeof e==`string`?this.messageHandler.sendWithPromise(`GetDestination`,{id:e}):Promise.reject(Error(`Invalid destination request.`))}getPageLabels(){return this.messageHandler.sendWithPromise(`GetPageLabels`,null)}getPageLayout(){return this.messageHandler.sendWithPromise(`GetPageLayout`,null)}getPageMode(){return this.messageHandler.sendWithPromise(`GetPageMode`,null)}getViewerPreferences(){return this.messageHandler.sendWithPromise(`GetViewerPreferences`,null)}getOpenAction(){return this.messageHandler.sendWithPromise(`GetOpenAction`,null)}getAttachments(){return this.messageHandler.sendWithPromise(`GetAttachments`,null)}getAttachmentContent(e){return this.messageHandler.sendWithPromise(`GetAttachmentContent`,e)}getAnnotationsByType(e,t){return this.messageHandler.sendWithPromise(`GetAnnotationsByType`,{types:e,pageIndexesToSkip:t})}getDocJSActions(){return this.#s(`GetDocJSActions`)}getPageJSActions(e){return this.messageHandler.sendWithPromise(`GetPageJSActions`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getStructTree(e){return this.messageHandler.sendWithPromise(`GetStructTree`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getOutline(){return this.messageHandler.sendWithPromise(`GetOutline`,null)}getOptionalContentConfig(e){return this.#s(`GetOptionalContentConfig`).then(t=>new jr(t,e))}getPermissions(){return this.messageHandler.sendWithPromise(`GetPermissions`,null)}getMetadata(){let e=`GetMetadata`;return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).then(e=>({info:e[0],metadata:e[1]?new Or(e[1]):null,contentDispositionFilename:this.#e?.filename??null,contentLength:this.#e?.contentLength??null,hasStructTree:e[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise(`GetMarkInfo`,null)}getRawData(e){return this.messageHandler.sendWithPromise(`GetRawData`,e)}async startCleanup(e=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise(`Cleanup`,null);for(let e of this.#r.values())if(!e.cleanup())throw Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),e||this.fontLoader.clear(),this.#t.clear(),this.filterFactory.destroy(!0),Rr.cleanup()}}cachedPageNumber(e){if(!Yt(e))return null;let t=e.gen===0?`${e.num}R`:`${e.num}R${e.gen}`,n=this.#a.get(t);if(n>=0){let e=this.pagesMapper.getPageNumber(n+1);if(e!==0)return e}return null}},qr=class{_internalRenderTask=null;onContinue=null;onError=null;constructor(e){this._internalRenderTask=e}get promise(){return this._internalRenderTask.capability.promise}cancel(e=0){this._internalRenderTask.cancel(null,e)}get separateAnnots(){let{separateAnnots:e}=this._internalRenderTask.operatorList;if(!e)return!1;let{annotationCanvasMap:t}=this._internalRenderTask;return e.form||e.canvas&&t?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}},Jr=class e{#e=null;static#t=new WeakSet;constructor({callback:e,params:t,objs:n,commonObjs:r,annotationCanvasMap:i,operatorList:a,pageIndex:o,canvasFactory:s,filterFactory:c,useRequestAnimationFrame:l=!1,pdfBug:u=!1,pageColors:d=null,enableHWA:f=!1,operationsFilter:p=null}){this.callback=e,this.params=t,this.objs=n,this.commonObjs=r,this.annotationCanvasMap=i,this.operatorListIdx=null,this.operatorList=a,this._pageIndex=o,this.canvasFactory=s,this.filterFactory=c,this._pdfBug=u,this.pageColors=d,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=l===!0&&typeof window<`u`,this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new qr(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=t.canvas,this._canvasContext=t.canvas?null:t.canvasContext,this._enableHWA=f,this._dependencyTracker=t.dependencyTracker,this._imagesTracker=t.imagesTracker,this._operationsFilter=p}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:n}){if(this.cancelled)return;if(this._canvas){if(e.#t.has(this._canvas))throw Error(`Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.`);e.#t.add(this._canvas)}this._pdfBug&&globalThis.StepperManager?.enabled&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());let{viewport:r,transform:i,background:a,dependencyTracker:o,imagesTracker:s}=this.params,c=this._canvasContext||this._canvas.getContext(`2d`,{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new Jn(c,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:n},this.annotationCanvasMap,this.pageColors,o,s),this.gfx.beginDrawing({transform:i,viewport:r,transparency:t,background:a}),this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}cancel(t=null,n=0){this.running=!1,this.cancelled=!0,this.gfx?.endDrawing(),this.#e&&=(window.cancelAnimationFrame(this.#e),null),e.#t.delete(this._canvas),t||=new Ae(`Rendering cancelled, page ${this._pageIndex+1}`,n),this.callback(t),this.task.onError?.(t)}operatorListChanged(){if(!this.graphicsReady){this.graphicsReadyCallback||=this._continueBound;return}this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#e=window.requestAnimationFrame(()=>{this.#e=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),e.#t.delete(this._canvas),this.callback())))}},Yr=`6.1.200`,Xr=`6353acefe`,Zr=class e{#e=null;#t=null;#n;#r=null;#i=!1;#a=!1;#o=null;#s;#c=null;#l=null;static#u=null;static get _keyboardManager(){return I(this,`_keyboardManager`,new ct([[[`Escape`],e.prototype._hideDropdownFromKeyboard],[[`Space`],e.prototype._colorSelectFromKeyboard],[[`ArrowDown`,`ArrowRight`],e.prototype._moveToNext],[[`ArrowUp`,`ArrowLeft`],e.prototype._moveToPrevious],[[`Home`],e.prototype._moveToBeginning],[[`End`],e.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:n=null}){t?(this.#a=!1,this.#o=t):this.#a=!0,this.#l=t?._uiManager||n,this.#s=this.#l._eventBus,this.#n=t?.color?.toUpperCase()||this.#l?.highlightColors.values().next().value||`#FFFF98`,e.#u||=Object.freeze({blue:`pdfjs-editor-colorpicker-blue`,green:`pdfjs-editor-colorpicker-green`,pink:`pdfjs-editor-colorpicker-pink`,red:`pdfjs-editor-colorpicker-red`,yellow:`pdfjs-editor-colorpicker-yellow`})}renderButton(){let e=this.#e=document.createElement(`button`);e.className=`colorPicker`,e.tabIndex=`0`,e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-button`),e.ariaHasPopup=`true`,this.#o&&(e.ariaControls=`${this.#o.id}_colorpicker_dropdown`);let t=this.#l._signal;e.addEventListener(`click`,this.#m.bind(this),{signal:t}),e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});let n=this.#t=document.createElement(`span`);return n.className=`swatch`,n.ariaHidden=`true`,n.style.backgroundColor=this.#n,e.append(n),e}renderMainDropdown(){let e=this.#r=this.#d();return e.ariaOrientation=`horizontal`,e.ariaLabelledBy=`highlightColorPickerLabel`,e}#d(){let t=document.createElement(`div`),n=this.#l._signal;t.addEventListener(`contextmenu`,H,{signal:n}),t.className=`dropdown`,t.role=`listbox`,t.ariaMultiSelectable=`false`,t.ariaOrientation=`vertical`,t.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-dropdown`),this.#o&&(t.id=`${this.#o.id}_colorpicker_dropdown`);for(let[r,i]of this.#l.highlightColors){let a=document.createElement(`button`);a.tabIndex=`0`,a.role=`option`,a.setAttribute(`data-color`,i),a.title=r,a.setAttribute(`data-l10n-id`,e.#u[r]);let o=document.createElement(`span`);a.append(o),o.className=`swatch`,o.style.backgroundColor=i,a.ariaSelected=i===this.#n,a.addEventListener(`click`,this.#f.bind(this,i),{signal:n}),t.append(a)}return t.addEventListener(`keydown`,this.#p.bind(this),{signal:n}),t}#f(e,t){t.stopPropagation(),this.#s.dispatch(`switchannotationeditorparams`,{source:this,type:C.HIGHLIGHT_COLOR,value:e}),this.updateColor(e)}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}let t=e.target.getAttribute(`data-color`);t&&this.#f(t,e)}_moveToNext(e){if(!this.#g){this.#m(e);return}if(e.target===this.#e){this.#r.firstElementChild?.focus();return}e.target.nextSibling?.focus()}_moveToPrevious(e){if(e.target===this.#r?.firstElementChild||e.target===this.#e){this.#g&&this._hideDropdownFromKeyboard();return}this.#g||this.#m(e),e.target.previousSibling?.focus()}_moveToBeginning(e){if(!this.#g){this.#m(e);return}this.#r.firstElementChild?.focus()}_moveToEnd(e){if(!this.#g){this.#m(e);return}this.#r.lastElementChild?.focus()}#p(t){e._keyboardManager.exec(this,t)}#m(e){if(this.#g){this.hideDropdown();return}if(this.#i=e.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener(`pointerdown`,this.#h.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#e.ariaExpanded=`true`,this.#r){this.#r.classList.remove(`hidden`);return}let t=this.#r=this.#d();this.#e.append(t)}#h(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add(`hidden`),this.#e.ariaExpanded=`false`,this.#c?.abort(),this.#c=null}get#g(){return this.#r&&!this.#r.classList.contains(`hidden`)}_hideDropdownFromKeyboard(){if(!this.#a){if(!this.#g){this.#o?.unselect();return}this.hideDropdown(),this.#e.focus({preventScroll:!0,focusVisible:this.#i})}}updateColor(e){if(this.#t&&(this.#t.style.backgroundColor=e),!this.#r)return;let t=this.#l.highlightColors.values();for(let n of this.#r.children)n.ariaSelected=t.next().value===e.toUpperCase()}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#r?.remove(),this.#r=null}},Qr=class e{#e=null;#t=!1;#n=null;#r=null;static#i=null;constructor(t){this.#n=t,this.#r=t._uiManager,e.#i||=Object.freeze({freetext:`pdfjs-editor-color-picker-free-text-input`,ink:`pdfjs-editor-color-picker-ink-input`})}renderButton(){if(this.#e)return this.#e;let{editorType:t,colorType:n,colorAndOpacityType:r,opacityType:i,color:a,opacity:o}=this.#n,s=this.#t=L.isAlphaColorInputSupported&&i!==void 0,c=this.#e=document.createElement(`input`);if(c.type=`color`,s){c.setAttribute(`alpha`,``);let e=R.hexNums[Math.round((o??1)*255)];c.value=(a||`#000000`)+e}else c.value=a||`#000000`;return c.className=`basicColorPicker`,c.tabIndex=0,c.setAttribute(`data-l10n-id`,e.#i[t]),c.addEventListener(`input`,()=>{if(s){let e=Le(c.value);if(!e)return;let[t,a,o,s]=e,l=R.makeHexColor(t,a,o);r===void 0?(this.#r.updateParams(n,l),this.#r.updateParams(i,s)):this.#r.updateParams(r,{color:l,opacity:s})}else this.#r.updateParams(n,c.value)},{signal:this.#r._signal}),c}update(e){if(this.#e)if(this.#t){let t=R.hexNums[Math.round(this.#n.opacity*255)];this.#e.value=e+t}else this.#e.value=e}updateOpacity(e){if(!this.#e||!this.#t)return;let t=R.hexNums[Math.round(e*255)];this.#e.value=this.#n.color+t}destroy(){this.#e?.remove(),this.#e=null}hideDropdown(){}};function $r(e){return Math.floor(B(e,0,1)*255).toString(16).padStart(2,`0`)}function ei(e){return B(e,0,1)*255}var ti=class{static CMYK_G([e,t,n,r]){return[`G`,1-Math.min(1,.3*e+.59*n+.11*t+r)]}static G_CMYK([e]){return[`CMYK`,0,0,0,1-e]}static G_RGB([e]){return[`RGB`,e,e,e]}static G_rgb([e]){return e=ei(e),[e,e,e]}static G_HTML([e]){let t=$r(e);return`#${t}${t}${t}`}static RGB_G([e,t,n]){return[`G`,.3*e+.59*t+.11*n]}static RGB_rgb(e){return e.map(ei)}static RGB_HTML(e){return`#${e.map($r).join(``)}`}static T_HTML(){return`#00000000`}static T_rgb(){return[null]}static CMYK_RGB([e,t,n,r]){return[`RGB`,1-Math.min(1,e+r),1-Math.min(1,n+r),1-Math.min(1,t+r)]}static CMYK_rgb([e,t,n,r]){return[ei(1-Math.min(1,e+r)),ei(1-Math.min(1,n+r)),ei(1-Math.min(1,t+r))]}static CMYK_HTML(e){let t=this.CMYK_RGB(e).slice(1);return this.RGB_HTML(t)}static RGB_CMYK([e,t,n]){let r=1-e,i=1-t,a=1-n;return[`CMYK`,r,i,a,Math.min(r,i,a)]}},ni=class{create(e,t,n=!1){if(e<=0||t<=0)throw Error(`Invalid SVG dimensions`);let r=this._createSVG(`svg:svg`);return r.setAttribute(`version`,`1.1`),n||(r.setAttribute(`width`,`${e}px`),r.setAttribute(`height`,`${t}px`)),r.setAttribute(`preserveAspectRatio`,`none`),r.setAttribute(`viewBox`,`0 0 ${e} ${t}`),r}createElement(e){if(typeof e!=`string`)throw Error(`Invalid SVG element type`);return this._createSVG(e)}_createSVG(e){P("Abstract method `_createSVG` called.")}},ri=class extends ni{_createSVG(e){return document.createElementNS(_,e)}},ii=9,ai=new WeakSet,oi=new Date().getTimezoneOffset()*60*1e3,si=class{static create(e){switch(e.data.annotationType){case D.LINK:return new li(e);case D.TEXT:return new ui(e);case D.WIDGET:switch(e.data.fieldType){case`Tx`:return new fi(e);case`Btn`:return e.data.radioButton?new hi(e):e.data.checkBox?new mi(e):new gi(e);case`Ch`:return new _i(e);case`Sig`:return new pi(e)}return new di(e);case D.POPUP:return new vi(e);case D.FREETEXT:return new bi(e);case D.LINE:return new xi(e);case D.SQUARE:return new Si(e);case D.CIRCLE:return new Ci(e);case D.POLYLINE:return new wi(e);case D.CARET:return new Ei(e);case D.INK:return new Di(e);case D.POLYGON:return new Ti(e);case D.HIGHLIGHT:return new Oi(e);case D.UNDERLINE:return new ki(e);case D.SQUIGGLY:return new Ai(e);case D.STRIKEOUT:return new ji(e);case D.STAMP:return new Mi(e);case D.FILEATTACHMENT:return new Ni(e);case D.RICHMEDIA:case D.SCREEN:return new Pi(e);default:return new Z(e)}}},Z=class e{#e=null;#t=!1;#n=null;constructor(e,{isRenderable:t=!1,ignoreBorder:n=!1,createQuadrilaterals:r=!1}={}){this.isRenderable=t,this.data=e.data,this.layer=e.layer,this.linkService=e.linkService,this.downloadManager=e.downloadManager,this.imageResourcesPath=e.imageResourcesPath,this.renderForms=e.renderForms,this.svgFactory=e.svgFactory,this.annotationStorage=e.annotationStorage,this.enableComment=e.enableComment,this.enableScripting=e.enableScripting,this.hasJSActions=e.hasJSActions,this._fieldObjects=e.fieldObjects,this.parent=e.parent,this.hasOwnCommentButton=!1,t&&(this.contentElement=this.container=this._createContainer(n)),r&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:e,richText:t}){return!!(e?.str||t?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return e._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){let{data:e}=this,t=this.annotationStorage?.getEditor(e.id);return t?t.getData():e}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){let e=this.annotationStorage?.getEditor(this.data.id);if(e)return e.commentButtonPositionInPage;let{quadPoints:t,inkLists:n,rect:r}=this.data,i=-1/0,a=-1/0;if(t?.length>=8){for(let e=0;e<t.length;e+=8)t[e+1]>a?(a=t[e+1],i=t[e+2]):t[e+1]===a&&(i=Math.max(i,t[e+2]));return[i,a]}if(n?.length>=1){for(let e of n)for(let t=0,n=e.length;t<n;t+=2)e[t+1]>a?(a=e[t+1],i=e[t]):e[t+1]===a&&(i=Math.max(i,e[t]));if(i!==1/0)return[i,a]}return r?[r[2],r[3]]:null}_normalizePoint(e){let{page:{view:t},viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}}=this.parent;return e[1]=t[3]-e[1]+t[1],e[0]=100*(e[0]-i)/n,e[1]=100*(e[1]-a)/r,e}get commentText(){let{data:e}=this;return this.annotationStorage.getRawValue(`${x}${e.id}`)?.popup?.contents||e.contentsObj?.str||``}set commentText(e){let{data:t}=this,n={deleted:!e,contents:e||``};this.annotationStorage.updateEditor(t.id,{popup:n})||this.annotationStorage.setValue(`${x}${t.id}`,{id:t.id,annotationType:t.annotationType,page:this.parent.page,popup:n,popupRef:t.popupRef,modificationDate:new Date}),e||this.removePopup()}removePopup(){(this.#n?.popup||this.popup)?.remove(),this.#n=this.popup=null}updateEdited(e){if(!this.container)return;e.rect&&(this.#e||={rect:this.data.rect.slice(0)});let{rect:t,popup:n}=e;t&&this.#r(t);let r=this.#n?.popup||this.popup;!r&&n?.text&&(this._createPopup(n),r=this.#n.popup),r&&(r.updateEdited(e),n?.deleted&&(r.remove(),this.#n=null,this.popup=null))}resetEdited(){this.#e&&=(this.#r(this.#e.rect),this.#n?.popup.resetEdited(),null)}#r(e){let{container:{style:t},data:{rect:n,rotation:r},parent:{viewport:{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:s}}}}=this;n?.splice(0,4,...e),t.left=`${100*(e[0]-o)/i}%`,t.top=`${100*(a-e[3]+s)/a}%`,r===0?(t.width=`${100*(e[2]-e[0])/i}%`,t.height=`${100*(e[3]-e[1])/a}%`):this.setRotation(r)}_createContainer(e){let{data:t,parent:{page:n,viewport:r}}=this,i=document.createElement(`section`);i.setAttribute(`data-annotation-id`,t.id),!(this instanceof di)&&!(this instanceof li)&&!(this instanceof Pi)&&(i.tabIndex=0);let{style:a}=i;if(a.zIndex=this.parent.zIndex,this.parent.zIndex+=2,t.alternativeText&&(i.title=t.alternativeText),t.noRotate&&i.classList.add(`norotate`),!t.rect||this instanceof vi){let{rotation:e}=t;return!t.hasOwnCanvas&&e!==0&&this.setRotation(e,i),i}let{width:o,height:s}=this;if(!e&&t.borderStyle.width>0){a.borderWidth=`${t.borderStyle.width}px`;let e=t.borderStyle.horizontalCornerRadius,n=t.borderStyle.verticalCornerRadius;switch((e>0||n>0)&&(a.borderRadius=`calc(${e}px * var(--total-scale-factor)) / calc(${n}px * var(--total-scale-factor))`),t.borderStyle.style){case O.SOLID:a.borderStyle=`solid`;break;case O.DASHED:a.borderStyle=`dashed`;break;case O.BEVELED:N(`Unimplemented border style: beveled`);break;case O.INSET:N(`Unimplemented border style: inset`);break;case O.UNDERLINE:a.borderBottomStyle=`solid`;break;default:break}let r=t.borderColor||null;r?(this.#t=!0,a.borderColor=R.makeHexColor(...r)):a.borderWidth=0}let c=R.normalizeRect([t.rect[0],n.view[3]-t.rect[1]+n.view[1],t.rect[2],n.view[3]-t.rect[3]+n.view[1]]),{pageWidth:l,pageHeight:u,pageX:d,pageY:f}=r.rawDims;a.left=`${100*(c[0]-d)/l}%`,a.top=`${100*(c[1]-f)/u}%`;let{rotation:p}=t;return t.hasOwnCanvas||p===0?(a.width=`${100*o/l}%`,a.height=`${100*s/u}%`):this.setRotation(p,i),i}setRotation(e,t=this.container){if(!this.data.rect)return;let{pageWidth:n,pageHeight:r}=this.parent.viewport.rawDims,{width:i,height:a}=this;e%180!=0&&([i,a]=[a,i]),t.style.width=`${100*i/n}%`,t.style.height=`${100*a/r}%`,t.setAttribute(`data-main-rotation`,(360-e)%360)}get _commonActions(){let e=(e,t,n)=>{let r=n.detail[e],i=r[0],a=r.slice(1);n.target.style[t]=ti[`${i}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[t]:ti[`${i}_rgb`](a)})};return I(this,`_commonActions`,{display:e=>{let{display:t}=e.detail,n=t%2==1;this.container.style.visibility=n?`hidden`:`visible`,this.annotationStorage.setValue(this.data.id,{noView:n,noPrint:t===1||t===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{let{hidden:t}=e.detail;this.container.style.visibility=t?`hidden`:`visible`,this.annotationStorage.setValue(this.data.id,{noPrint:t,noView:t})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:t=>{e(`bgColor`,`backgroundColor`,t)},fillColor:t=>{e(`fillColor`,`backgroundColor`,t)},fgColor:t=>{e(`fgColor`,`color`,t)},textColor:t=>{e(`textColor`,`color`,t)},borderColor:t=>{e(`borderColor`,`borderColor`,t)},strokeColor:t=>{e(`strokeColor`,`borderColor`,t)},rotation:e=>{let t=e.detail.rotation;this.setRotation(t),this.annotationStorage.setValue(this.data.id,{rotation:t})}})}_dispatchEventFromSandbox(e,t){let n=this._commonActions;for(let r of Object.keys(t.detail))(e[r]||n[r])?.(t)}_setDefaultPropertiesFromJS(e){if(!this.enableScripting)return;let t=this.annotationStorage.getRawValue(this.data.id);if(!t)return;let n=this._commonActions;for(let[r,i]of Object.entries(t)){let a=n[r];a&&(a({detail:{[r]:i},target:e}),delete t[r])}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:e}=this.data;if(!e)return;let[t,n,r,i]=this.data.rect.map(e=>Math.fround(e));if(e.length===8){let[a,o,s,c]=e.subarray(2,6);if(r===a&&i===o&&t===s&&n===c)return}let{style:a}=this.container,o;if(this.#t){let{borderColor:e,borderWidth:t}=a;a.borderWidth=0,o=[`url('data:image/svg+xml;utf8,`,`<svg xmlns="${_}" preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${e}" stroke-width="${t}">`],this.container.classList.add(`hasBorder`)}let s=r-t,c=i-n,{svgFactory:l}=this,u=l.createElement(`svg`);u.classList.add(`quadrilateralsContainer`),u.setAttribute(`width`,0),u.setAttribute(`height`,0),u.role=`none`;let d=l.createElement(`defs`);u.append(d);let f=l.createElement(`clipPath`),p=`clippath_${this.data.id}`;f.setAttribute(`id`,p),f.setAttribute(`clipPathUnits`,`objectBoundingBox`),d.append(f);for(let n=2,r=e.length;n<r;n+=8){let r=e[n],a=e[n+1],u=e[n+2],d=e[n+3],p=l.createElement(`rect`),m=(u-t)/s,h=(i-a)/c,g=(r-u)/s,_=(a-d)/c;p.setAttribute(`x`,m),p.setAttribute(`y`,h),p.setAttribute(`width`,g),p.setAttribute(`height`,_),f.append(p),o?.push(`<rect vector-effect="non-scaling-stroke" x="${m}" y="${h}" width="${g}" height="${_}"/>`)}this.#t&&(o.push(`</g></svg>')`),a.backgroundImage=o.join(``)),this.container.append(u),this.container.style.clipPath=`url(#${p})`}_createPopup(e=null){let{data:t}=this,n,r;e?(n={str:e.text},r=e.date):(n=t.contentsObj,r=t.modificationDate),this.#n=new vi({data:{color:t.color,titleObj:t.titleObj,modificationDate:r,contentsObj:n,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#n||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#n}render(){P("Abstract method `AnnotationElement.render` called")}_getElementsByName(e,t=null){let n=[];if(this._fieldObjects){let r=this._fieldObjects[e];if(r)for(let{page:e,id:i,exportValues:a}of r){if(e===-1||i===t)continue;let r=typeof a==`string`?a:null,o=document.querySelector(`[data-element-id="${i}"]`);if(o&&!ai.has(o)){N(`_getElementsByName - element not allowed: ${i}`);continue}n.push({id:i,exportValue:r,domElement:o})}return n}for(let r of document.getElementsByName(e)){let{exportValue:e}=r,i=r.getAttribute(`data-element-id`);i!==t&&ai.has(r)&&n.push({id:i,exportValue:e,domElement:r})}return n}show(){this.container&&(this.container.hidden=!1),this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0),this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){let e=this.getElementsToTriggerPopup();if(Array.isArray(e))for(let t of e)t.classList.add(`highlightArea`);else e.classList.add(`highlightArea`)}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:e,data:{id:t}}=this;this.container.addEventListener(`dblclick`,()=>{this.linkService.eventBus?.dispatch(`switchannotationeditormode`,{source:this,mode:e,editId:t,mustEnterInEditMode:!0})})}updateOC(e){!this.data.oc||!e||(e.isVisible(this.data.oc)?this.show():this.hide())}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}_setBackgroundColor(e){let t=this.data.backgroundColor||null;e.style.backgroundColor=t===null?`transparent`:R.makeHexColor(...t)}},ci=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.editor=e.editor}render(){return this.container.className=`editorAnnotation`,this.container}createOrUpdatePopup(){let{editor:e}=this;e.hasComment&&this._createPopup(e.comment)}get hasCommentButton(){return this.enableComment&&this.editor.hasComment}get commentButtonPosition(){return this.editor.commentButtonPositionInPage}get commentText(){return this.editor.comment.text}set commentText(e){this.editor.comment=e,e||this.removePopup()}get commentData(){return this.editor.getData()}remove(){this.parent.removeAnnotation(this.data.id),this.container.remove(),this.container=null,this.removePopup()}},li=class extends Z{constructor(e,t=null){super(e,{isRenderable:!0,ignoreBorder:!!t?.ignoreBorder,createQuadrilaterals:!0}),this.isTooltipOnly=e.data.isTooltipOnly}render(){let{data:e,linkService:t}=this,n=document.createElement(`a`);n.setAttribute(`data-element-id`,e.id);let r=!1;return e.url?(t.addLinkAttributes(n,e.url,e.newWindow),r=!0):e.action?(this._bindNamedAction(n,e.action,e.overlaidText),r=!0):e.attachment?(this.#t(n,e.attachmentId,e.attachment,e.overlaidText,e.attachmentDest),r=!0):e.setOCGState?(this.#n(n,e.setOCGState,e.overlaidText),r=!0):e.dest?(this._bindLink(n,e.dest,e.overlaidText),r=!0):(e.actions&&(e.actions.Action||e.actions[`Mouse Up`]||e.actions[`Mouse Down`])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(n,e),r=!0),e.resetForm?(this._bindResetFormAction(n,e.resetForm),r=!0):this.isTooltipOnly&&!r&&(this._bindLink(n,``),r=!0)),this.container.classList.add(`linkAnnotation`),r&&(this.contentElement=n,this.container.append(n)),this.container}#e(){this.container.setAttribute(`data-internal-link`,``)}_bindLink(e,t,n=``){e.href=this.linkService.getDestinationHash(t),e.onclick=()=>(t&&this.linkService.goToDestination(t),!1),(t||t===``)&&this.#e(),n&&(e.title=n)}_bindNamedAction(e,t,n=``){e.href=this.linkService.getAnchorUrl(``),e.onclick=()=>(this.linkService.executeNamedAction(t),!1),n&&(e.title=n),this.#e()}#t(e,t,n,r=``,i=null){e.href=this.linkService.getAnchorUrl(``),n.description?e.title=n.description:r&&(e.title=r);let a=async()=>{let e=await this.linkService.getAttachmentContent(t);e&&this.downloadManager?.openOrDownloadData(e,n.filename,i)};e.onclick=()=>(a(),!1),this.#e()}#n(e,t,n=``){e.href=this.linkService.getAnchorUrl(``),e.onclick=()=>(this.linkService.executeSetOCGState(t),!1),n&&(e.title=n),this.#e()}_bindJSAction(e,t){e.href=this.linkService.getAnchorUrl(``);let n=new Map([[`Action`,`onclick`],[`Mouse Up`,`onmouseup`],[`Mouse Down`,`onmousedown`]]);for(let r of Object.keys(t.actions)){let i=n.get(r);i&&(e[i]=()=>(this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t.id,name:r}}),!1))}t.overlaidText&&(e.title=t.overlaidText),e.onclick||=()=>!1,this.#e()}_bindResetFormAction(e,t){let n=e.onclick;if(n||(e.href=this.linkService.getAnchorUrl(``)),this.#e(),!this._fieldObjects){N('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),n||(e.onclick=()=>!1);return}e.onclick=()=>{n?.();let{fields:e,refs:r,include:i}=t,a=[];if(e.length!==0||r.length!==0){let t=new Set(r);for(let n of e){let e=this._fieldObjects[n]||[];for(let{id:n}of e)t.add(n)}for(let e of Object.values(this._fieldObjects))for(let n of e)t.has(n.id)===i&&a.push(n)}else for(let e of Object.values(this._fieldObjects))a.push(...e);let o=this.annotationStorage,s=[];for(let e of a){let{id:t}=e;switch(s.push(t),e.type){case`text`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}case`checkbox`:case`radiobutton`:{let n=e.defaultValue===e.exportValues;o.setValue(t,{value:n});break}case`combobox`:case`listbox`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}default:continue}let n=document.querySelector(`[data-element-id="${t}"]`);if(n){if(!ai.has(n)){N(`_bindResetFormAction - element not allowed: ${t}`);continue}n.dispatchEvent(new Event(`resetform`))}}return this.enableScripting&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:`app`,ids:s,name:`ResetForm`}}),!1}}},ui=class extends Z{constructor(e){super(e,{isRenderable:!0})}render(){this.container.classList.add(`textAnnotation`);let e=document.createElement(`img`);return e.src=this.imageResourcesPath+`annotation-`+this.data.name.toLowerCase()+`.svg`,e.setAttribute(`data-l10n-id`,`pdfjs-text-annotation-type`),e.setAttribute(`data-l10n-args`,JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(e),this.container}},di=class extends Z{render(){return this.container}_getKeyModifier(e){return L.platform.isMac?e.metaKey:e.ctrlKey}_setEventListener(e,t,n,r,i){n.includes(`mouse`)?e.addEventListener(n,e=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e),shift:e.shiftKey,modifier:this._getKeyModifier(e)}})}):e.addEventListener(n,e=>{if(n===`blur`){if(!t.focused||!e.relatedTarget)return;t.focused=!1}else if(n===`focus`){if(t.focused)return;t.focused=!0}i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e)}})})}_setEventListeners(e,t,n,r){for(let[i,a]of n)(a===`Action`||this.data.actions?.[a])&&((a===`Focus`||a===`Blur`)&&(t||={focused:!1}),this._setEventListener(e,t,i,a,r),a===`Focus`&&!this.data.actions?.Blur?this._setEventListener(e,t,`blur`,`Blur`,null):a===`Blur`&&!this.data.actions?.Focus&&this._setEventListener(e,t,`focus`,`Focus`,null))}_setTextStyle(e){let t=[`left`,`center`,`right`],{fontColor:n}=this.data.defaultAppearanceData,r=this.data.defaultAppearanceData.fontSize||ii,i=e.style,a,o=e=>Math.round(10*e)/10;if(this.data.multiLine){let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2),t=e/(Math.round(e/(g*r))||1);a=Math.min(r,o(t/g))}else{let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2);a=Math.min(r,o(e/g))}i.fontSize=`calc(${a}px * var(--total-scale-factor))`,i.color=R.makeHexColor(...n),this.data.textAlignment!==null&&!this.data.comb&&(i.textAlign=t[this.data.textAlignment])}_setRequired(e,t){t?e.setAttribute(`required`,!0):e.removeAttribute(`required`),e.setAttribute(`aria-required`,t)}},fi=class extends di{constructor(e){let t=e.renderForms||e.data.hasOwnCanvas||!e.data.hasAppearance&&!!e.data.fieldValue;super(e,{isRenderable:t})}setPropertyOnSiblings(e,t,n,r){let i=this.annotationStorage;for(let a of this._getElementsByName(e.name,e.id))a.domElement&&(a.domElement[t]=n),i.setValue(a.id,{[r]:n})}render(){let e=this.annotationStorage,t=this.data.id;this.container.classList.add(`textWidgetAnnotation`);let n=null;if(this.renderForms){let r=e.getValue(t,{value:this.data.fieldValue}),i=r.value||``,a=e.getValue(t,{charLimit:this.data.maxLen}).charLimit;a&&i.length>a&&(i=i.slice(0,a));let o=r.formattedValue||this.data.textContent?.join(`
45
- `)||null;o&&this.data.comb&&(o=o.replaceAll(/\s+/g,``));let s={userValue:i,formattedValue:o,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(n=document.createElement(`textarea`),n.textContent=o??i,this.data.doNotScroll&&(n.style.overflowY=`hidden`)):(n=document.createElement(`input`),n.type=this.data.password?`password`:`text`,n.setAttribute(`value`,o??i),this.data.doNotScroll&&(n.style.overflowX=`hidden`)),this.data.hasOwnCanvas&&(this.container.classList.add(`hasOwnCanvas`),e.has(t)&&this.container.classList.add(`sandboxModified`)),ai.add(n),this.contentElement=n,n.setAttribute(`data-element-id`,t),n.disabled=this.data.readOnly,n.name=this.data.fieldName,n.tabIndex=0;let{datetimeFormat:c,datetimeType:l,timeStep:u}=this.data,d=!!l&&this.enableScripting;c&&(n.title=c),this._setRequired(n,this.data.required),a&&(n.maxLength=a),n.addEventListener(`input`,r=>{e.setValue(t,{value:r.target.value}),this.setPropertyOnSiblings(n,`value`,r.target.value,`value`),s.formattedValue=null}),n.addEventListener(`resetform`,e=>{let t=this.data.defaultFieldValue??``;n.value=s.userValue=t,s.formattedValue=null});let f=e=>{let{formattedValue:t}=s;t!=null&&(e.target.value=t),e.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){n.addEventListener(`focus`,e=>{if(s.focused)return;let{target:t}=e;if(d&&(t.type=l,u&&(t.step=u)),s.userValue){let e=s.userValue;if(d)if(l===`time`){let n=new Date(e);t.value=[n.getHours(),n.getMinutes(),n.getSeconds()].map(e=>e.toString().padStart(2,`0`)).join(`:`)}else t.value=new Date(e-oi).toISOString().split(l===`date`?`T`:`.`,1)[0];else t.value=e}s.lastCommittedValue=t.value,s.commitKey=1,this.data.actions?.Focus||(s.focused=!0)}),n.addEventListener(`updatefromsandbox`,n=>{this.container.classList.add(`sandboxModified`),this._dispatchEventFromSandbox({value(n){s.userValue=n.detail.value??``,d||e.setValue(t,{value:s.userValue.toString()}),n.target.value=s.userValue},formattedValue(n){let{formattedValue:r}=n.detail;s.formattedValue=r,r!=null&&n.target!==document.activeElement&&(n.target.value=r);let i={formattedValue:r};d&&(i.value=r),e.setValue(t,i)},selRange(e){e.target.setSelectionRange(...e.detail.selRange)},charLimit:n=>{let{charLimit:r}=n.detail,{target:i}=n;if(r===0){i.removeAttribute(`maxLength`);return}i.setAttribute(`maxLength`,r);let a=s.userValue;!a||a.length<=r||(a=a.slice(0,r),i.value=s.userValue=a,e.setValue(t,{value:a}),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:a,willCommit:!0,commitKey:1,selStart:i.selectionStart,selEnd:i.selectionEnd}}))}},n)}),n.addEventListener(`keydown`,e=>{s.commitKey=1;let n=-1;if(e.key===`Escape`?n=0:e.key===`Enter`&&!this.data.multiLine?n=2:e.key===`Tab`&&(s.commitKey=3),n===-1)return;let{value:r}=e.target;s.lastCommittedValue!==r&&(s.lastCommittedValue=r,s.userValue=r,this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:r,willCommit:!0,commitKey:n,selStart:e.target.selectionStart,selEnd:e.target.selectionEnd}}))});let r=f;f=null,n.addEventListener(`blur`,e=>{if(!s.focused||!e.relatedTarget)return;this.data.actions?.Blur||(s.focused=!1);let{target:n}=e,{value:i}=n;if(d){if(i&&l===`time`){let e=i.split(`:`).map(e=>parseInt(e,10));i=new Date(2e3,0,1,e[0],e[1],e[2]||0).valueOf(),n.step=``}else i.includes(`T`)||(i=`${i}T00:00`),i=new Date(i).valueOf();n.type=`text`}s.userValue=i,s.lastCommittedValue!==i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:i,willCommit:!0,commitKey:s.commitKey,selStart:e.target.selectionStart,selEnd:e.target.selectionEnd}}),r(e)}),this.data.actions?.Keystroke&&n.addEventListener(`beforeinput`,e=>{s.lastCommittedValue=null;let{data:n,target:r}=e,{value:i,selectionStart:a,selectionEnd:o}=r,c=a,l=o;switch(e.inputType){case`deleteWordBackward`:{let e=i.substring(0,a).match(/\w*\W*$/);e&&(c-=e[0].length);break}case`deleteWordForward`:{let e=i.substring(a).match(/^\W*\w*/);e&&(l+=e[0].length);break}case`deleteContentBackward`:a===o&&--c;break;case`deleteContentForward`:a===o&&(l+=1);break}e.preventDefault(),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:i,change:n||``,willCommit:!1,selStart:c,selEnd:l}})}),this._setEventListeners(n,s,[[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.value)}if(f&&n.addEventListener(`blur`,f),this.data.comb){let e=(this.data.rect[2]-this.data.rect[0])/a;n.classList.add(`comb`),n.style.setProperty(`--comb-width`,`calc(${e}px * var(--total-scale-factor))`);let t=this.data.textAlignment;if(t===1||t===2){let e=()=>{let e=a-n.value.length;n.style.setProperty(`--comb-offset`,`${t===1?e>>1:e}`)};e();for(let t of[`input`,`blur`,`resetform`,`updatefromsandbox`])n.addEventListener(t,e)}}}else n=document.createElement(`div`),n.textContent=this.data.fieldValue,n.style.verticalAlign=`middle`,n.style.display=`table-cell`,this.data.hasOwnCanvas&&(n.hidden=!0);return this._setTextStyle(n),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}},pi=class extends di{constructor(e){super(e,{isRenderable:!!e.data.hasOwnCanvas})}},mi=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.exportValue===t.fieldValue}).value;typeof r==`string`&&(r=r!==`Off`,e.setValue(n,{value:r})),this.container.classList.add(`buttonWidgetAnnotation`,`checkBox`);let i=document.createElement(`input`);return ai.add(i),i.setAttribute(`data-element-id`,n),i.disabled=t.readOnly,this._setRequired(i,this.data.required),i.type=`checkbox`,i.name=t.fieldName,r&&i.setAttribute(`checked`,!0),i.setAttribute(`exportValue`,t.exportValue),i.tabIndex=0,i.addEventListener(`change`,r=>{let{name:i,checked:a}=r.target;for(let r of this._getElementsByName(i,n)){let n=a&&r.exportValue===t.exportValue;r.domElement&&(r.domElement.checked=n),e.setValue(r.id,{value:n})}e.setValue(n,{value:a})}),i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue||`Off`;e.target.checked=n===t.exportValue}),this.enableScripting&&this.hasJSActions&&(i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value(t){t.target.checked=t.detail.value!==`Off`,e.setValue(n,{value:t.target.checked})}},t)}),this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},hi=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`buttonWidgetAnnotation`,`radioButton`);let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.buttonValue!==null&&t.fieldValue===t.buttonValue}).value;if(typeof r==`string`&&(r=r!==t.buttonValue,e.setValue(n,{value:r})),r)for(let r of this._getElementsByName(t.fieldName,n))e.setValue(r.id,{value:!1});let i=document.createElement(`input`);if(ai.add(i),i.setAttribute(`data-element-id`,n),i.disabled=t.readOnly,this._setRequired(i,this.data.required),i.type=`radio`,i.name=t.fieldName,r&&i.setAttribute(`checked`,!0),i.tabIndex=0,i.addEventListener(`change`,t=>{let{name:r,checked:i}=t.target;for(let t of this._getElementsByName(r,n))e.setValue(t.id,{value:!1});e.setValue(n,{value:i})}),i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue;e.target.checked=n!=null&&n===t.buttonValue}),this.enableScripting&&this.hasJSActions){let r=t.buttonValue;i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value:t=>{let i=r===t.detail.value;for(let r of this._getElementsByName(t.target.name)){let t=i&&r.id===n;r.domElement&&(r.domElement.checked=t),e.setValue(r.id,{value:t})}}},t)}),this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)}return this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},gi=class extends li{constructor(e){super(e,{ignoreBorder:e.data.hasAppearance})}render(){let e=super.render();e.classList.add(`buttonWidgetAnnotation`,`pushButton`);let t=e.lastChild;return this.enableScripting&&this.hasJSActions&&t&&(this._setDefaultPropertiesFromJS(t),t.addEventListener(`updatefromsandbox`,e=>{this._dispatchEventFromSandbox({},e)})),e}},_i=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`choiceWidgetAnnotation`);let e=this.annotationStorage,t=this.data.id,n=e.getValue(t,{value:this.data.fieldValue}),r=document.createElement(`select`);ai.add(r),r.setAttribute(`data-element-id`,t),r.disabled=this.data.readOnly,this._setRequired(r,this.data.required),r.name=this.data.fieldName,r.tabIndex=0;let i=this.data.combo&&this.data.options.length>0;this.data.combo||(r.size=this.data.options.length,this.data.multiSelect&&(r.multiple=!0)),r.addEventListener(`resetform`,e=>{let t=this.data.defaultFieldValue;for(let e of r.options)e.selected=e.value===t});let a=(e,t)=>{let n=t.replaceAll(` `,`\xA0`);e.textContent=n,n!==t&&e.setAttribute(`display-value`,t)};for(let e of this.data.options){let t=document.createElement(`option`);a(t,e.displayValue),t.value=e.exportValue,n.value.includes(e.exportValue)&&(t.setAttribute(`selected`,!0),i=!1),r.append(t)}let o=null;if(i){let e=document.createElement(`option`);e.value=` `,e.setAttribute(`hidden`,!0),e.setAttribute(`selected`,!0),r.prepend(e),o=()=>{e.remove(),r.removeEventListener(`input`,o),o=null},r.addEventListener(`input`,o)}let s=e=>{let t=e?`value`:`textContent`,{options:n,multiple:i}=r;return i?Array.prototype.filter.call(n,e=>e.selected).map(e=>e[t]):n.selectedIndex===-1?null:n[n.selectedIndex][t]},c=s(!1),l=e=>{let t=e.target.options;return Array.prototype.map.call(t,e=>({displayValue:e.getAttribute(`display-value`)||e.textContent,exportValue:e.value}))};return this.enableScripting&&this.hasJSActions?(r.addEventListener(`updatefromsandbox`,n=>{this._dispatchEventFromSandbox({value(n){o?.();let i=n.detail.value,a=new Set(Array.isArray(i)?i:[i]);for(let e of r.options)e.selected=a.has(e.value);e.setValue(t,{value:s(!0)}),c=s(!1)},multipleSelection(e){r.multiple=!0},remove(n){let i=r.options,a=n.detail.remove;i[a].selected=!1,r.remove(a),i.length>0&&Array.prototype.findIndex.call(i,e=>e.selected)===-1&&(i[0].selected=!0),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},clear(n){for(;r.length!==0;)r.remove(0);e.setValue(t,{value:null,items:[]}),c=s(!1)},insert(n){let{index:i,displayValue:o,exportValue:u}=n.detail.insert,d=r.children[i],f=document.createElement(`option`);a(f,o),f.value=u,d?d.before(f):r.append(f),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},items(n){let{items:i}=n.detail;for(;r.length!==0;)r.remove(0);for(let e of i){let{displayValue:t,exportValue:n}=e,i=document.createElement(`option`);a(i,t),i.value=n,r.append(i)}r.options.length>0&&(r.options[0].selected=!0),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},indices(n){let r=new Set(n.detail.indices);for(let e of n.target.options)e.selected=r.has(e.index);e.setValue(t,{value:s(!0)}),c=s(!1)},editable(e){e.target.disabled=!e.detail.editable}},n)}),r.addEventListener(`input`,n=>{let r=s(!0),i=s(!1);e.setValue(t,{value:r}),n.preventDefault(),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:c,change:i,changeEx:r,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(r,null,[[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`],[`input`,`Action`],[`input`,`Validate`]],e=>e.target.value)):r.addEventListener(`input`,function(n){e.setValue(t,{value:s(!0)})}),this.data.combo&&this._setTextStyle(r),this._setBackgroundColor(r),this._setDefaultPropertiesFromJS(r),this.container.append(r),this.container}},vi=class extends Z{constructor(e){let{data:t,elements:n,parent:r}=e,i=!!r._commentManager;if(super(e,{isRenderable:!i&&Z._hasPopupData(t)}),this.elements=n,i&&Z._hasPopupData(t)){let e=this.popup=this.#e();for(let t of n)t.popup=e}else this.popup=null}#e(){return new yi({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){let{container:e}=this;e.classList.add(`popupAnnotation`),e.role=`comment`;let t=this.popup=this.#e(),n=[];for(let e of this.elements)e.popup=t,e.container.ariaHasPopup=`dialog`,n.push(e.data.id),e.addHighlightArea();return this.container.setAttribute(`aria-controls`,n.map(e=>`${b}${e}`).join(`,`)),this.container}},yi=class{#e=null;#t=this.#P.bind(this);#n=this.#R.bind(this);#r=this.#L.bind(this);#i=this.#I.bind(this);#a=null;#o=null;#s=null;#c=null;#l=null;#u=null;#d=null;#f=!1;#p=null;#m=null;#h=null;#g=null;#_=null;#v=null;#y=null;#b=null;#x=null;#S=null;#C=!1;#w=null;#T=null;constructor({container:e,color:t,elements:n,titleObj:r,modificationDate:i,contentsObj:a,richText:o,parent:s,rect:c,parentRect:l,open:u,commentManager:d=null}){this.#o=e,this.#x=r,this.#s=a,this.#b=o,this.#u=s,this.#a=t,this.#y=c,this.#d=l,this.#l=n,this.#e=d,this.#w=n[0],this.#c=Ie.toDateObject(i),this.trigger=n.flatMap(e=>e.getElementsToTriggerPopup()),d||(this.#E(),this.#o.hidden=!0,u&&this.#I())}#E(){if(this.#m)return;this.#m=new AbortController;let{signal:e}=this.#m;for(let t of this.trigger)t.addEventListener(`click`,this.#i,{signal:e}),t.addEventListener(`pointerenter`,this.#r,{signal:e}),t.addEventListener(`pointerleave`,this.#n,{signal:e}),t.classList.add(`popupTriggerArea`);for(let t of this.#l)t.container?.addEventListener(`keydown`,this.#t,{signal:e})}#D(){let e=this.#l.find(e=>e.hasCommentButton);e&&(this.#_=e._normalizePoint(e.commentButtonPosition))}renderCommentButton(){if(this.#g){this.#g.parentNode||this.#w.container.after(this.#g);return}if(this.#_||this.#D(),!this.#_)return;let{signal:e}=this.#m=new AbortController,t=this.#w.hasOwnCommentButton,n=()=>{this.#e.toggleCommentPopup(this,!0,void 0,!t)},r=()=>{this.#e.toggleCommentPopup(this,!1,!0,!t)},i=()=>{this.#e.toggleCommentPopup(this,!1,!1)};if(t){this.#g=this.#w.container;for(let t of this.trigger)t.ariaHasPopup=`dialog`,t.ariaControls=`commentPopup`,t.addEventListener(`keydown`,this.#t,{signal:e}),t.addEventListener(`click`,n,{signal:e}),t.addEventListener(`pointerenter`,r,{signal:e}),t.addEventListener(`pointerleave`,i,{signal:e}),t.classList.add(`popupTriggerArea`)}else{let t=this.#g=document.createElement(`button`);t.className=`annotationCommentButton`;let a=this.#w.container;t.style.zIndex=parseInt(a.style.zIndex,10)+1,t.tabIndex=0,t.ariaHasPopup=`dialog`,t.ariaControls=`commentPopup`,t.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`),this.#k(),this.#O(),t.addEventListener(`keydown`,this.#t,{signal:e}),t.addEventListener(`click`,n,{signal:e}),t.addEventListener(`pointerenter`,r,{signal:e}),t.addEventListener(`pointerleave`,i,{signal:e}),a.after(t)}}#O(){if(this.#w.extraPopupElement&&!this.#w.editor)return;this.#g||this.renderCommentButton();let[e,t]=this.#_,{style:n}=this.#g;n.left=`calc(${e}%)`,n.top=`calc(${t}% - var(--comment-button-dim))`}#k(){this.#w.extraPopupElement||(this.#g||this.renderCommentButton(),this.#g.style.backgroundColor=this.commentButtonColor||``)}get commentButtonColor(){let{color:e,opacity:t}=this.#w.commentData;return e?this.#u._commentManager.makeCommentColor(e,t):null}focusCommentButton(){setTimeout(()=>{this.#g?.focus()},0)}getData(){let{richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}=this.#w.commentData;return{contentsObj:{str:this.comment},richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}}get elementBeforePopup(){return this.#g}get comment(){return this.#T||=this.#w.commentText,this.#T}set comment(e){e!==this.comment&&(this.#w.commentText=this.#T=e)}focus(){this.#w.container?.focus()}get parentBoundingClientRect(){return this.#w.layer.getBoundingClientRect()}setCommentButtonStates({selected:e,hasPopup:t}){this.#g&&(this.#g.classList.toggle(`selected`,e),this.#g.ariaExpanded=t)}setSelectedCommentButton(e){this.#g.classList.toggle(`selected`,e)}get commentPopupPosition(){if(this.#v)return this.#v;let{x:e,y:t,height:n}=this.#g.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#w.layer.getBoundingClientRect();return[(e-r)/a,(t+n-i)/o]}set commentPopupPosition(e){this.#v=e}hasDefaultPopupPosition(){return this.#v===null}get commentButtonPosition(){return this.#_}get commentButtonWidth(){return this.#g.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(e){let[t,n]=this.#v||this.commentButtonPosition.map(e=>e/100),r=this.parentBoundingClientRect,{x:i,y:a,width:o,height:s}=r;this.#e.showDialog(null,this,i+t*o,a+n*s,{...e,parentDimensions:r})}render(){if(this.#p)return;let e=this.#p=document.createElement(`div`);if(e.className=`popup`,this.#a){let t=e.style.outlineColor=R.makeHexColor(...this.#a);e.style.backgroundColor=`color-mix(in srgb, ${t} 30%, white)`}let t=document.createElement(`span`);if(t.className=`header`,this.#x?.str){let e=document.createElement(`span`);e.className=`title`,t.append(e),{dir:e.dir,str:e.textContent}=this.#x}if(e.append(t),this.#c){let e=document.createElement(`time`);e.className=`popupDate`,e.setAttribute(`data-l10n-id`,`pdfjs-annotation-date-time-string`),e.setAttribute(`data-l10n-args`,JSON.stringify({dateObj:this.#c.valueOf()})),e.dateTime=this.#c.toISOString(),t.append(e)}$e({html:this.#A||this.#s.str,dir:this.#s?.dir,className:`popupContent`},e),this.#o.append(e)}get#A(){let e=this.#b,t=this.#s;return e?.str&&(!t?.str||t.str===e.str)&&this.#b.html||null}get#j(){return this.#A?.attributes?.style?.fontSize||0}get#M(){return this.#A?.attributes?.style?.color||null}#N(e){let t=[],n={str:e,html:{name:`div`,attributes:{dir:`auto`},children:[{name:`p`,children:t}]}},r={style:{color:this.#M,fontSize:this.#j?`calc(${this.#j}px * var(--total-scale-factor))`:``}};for(let n of e.split(`
46
- `))t.push({name:`span`,value:n,attributes:r});return n}#P(e){e.altKey||e.shiftKey||e.ctrlKey||e.metaKey||(e.key===`Enter`||e.key===`Escape`&&this.#f)&&this.#I()}updateEdited({rect:e,popup:t,deleted:n}){if(this.#e){n?(this.remove(),this.#T=null):t&&(t.deleted?this.remove():(this.#k(),this.#T=t.text)),e&&(this.#_=null,this.#D(),this.#O());return}if(n||t?.deleted){this.remove();return}this.#E(),this.#S||={contentsObj:this.#s,richText:this.#b},e&&(this.#h=null),t&&t.text&&(this.#b=this.#N(t.text),this.#c=Ie.toDateObject(t.date),this.#s=null),this.#p?.remove(),this.#p=null}resetEdited(){this.#S&&({contentsObj:this.#s,richText:this.#b}=this.#S,this.#S=null,this.#p?.remove(),this.#p=null,this.#h=null)}remove(){if(this.#m?.abort(),this.#m=null,this.#p?.remove(),this.#p=null,this.#C=!1,this.#f=!1,this.#g?.remove(),this.#g=null,this.trigger)for(let e of this.trigger)e.classList.remove(`popupTriggerArea`)}#F(){if(this.#h!==null)return;let{page:{view:e},viewport:{rawDims:{pageWidth:t,pageHeight:n,pageX:r,pageY:i}}}=this.#u,a=!!this.#d,o=a?this.#d:this.#y;for(let e of this.#l)if(!o||R.intersect(e.data.rect,o)!==null){o=e.data.rect,a=!0;break}let s=R.normalizeRect([o[0],e[3]-o[1]+e[1],o[2],e[3]-o[3]+e[1]]),c=a?o[2]-o[0]+5:0,l=s[0]+c,u=s[1];this.#h=[100*(l-r)/t,100*(u-i)/n];let{style:d}=this.#o;d.left=`${this.#h[0]}%`,d.top=`${this.#h[1]}%`}#I(){if(this.#e){this.#e.toggleCommentPopup(this,!1);return}this.#f=!this.#f,this.#f?(this.#L(),this.#o.addEventListener(`click`,this.#i),this.#o.addEventListener(`keydown`,this.#t)):(this.#R(),this.#o.removeEventListener(`click`,this.#i),this.#o.removeEventListener(`keydown`,this.#t))}#L(){this.#p||this.render(),this.isVisible?this.#f&&this.#o.classList.add(`focused`):(this.#F(),this.#o.hidden=!1,this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)+1e3)}#R(){this.#o.classList.remove(`focused`),!(this.#f||!this.isVisible)&&(this.#o.hidden=!0,this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)-1e3)}forceHide(){this.#C=this.isVisible,this.#C&&(this.#o.hidden=!0)}maybeShow(){this.#e||(this.#E(),this.#C&&(this.#p||this.#L(),this.#C=!1,this.#o.hidden=!1))}get isVisible(){return!this.#e&&this.#o.hidden===!1}},bi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.textContent=e.data.textContent,this.textPosition=e.data.textPosition,this.annotationEditorType=S.FREETEXT}render(){if(this.container.classList.add(`freeTextAnnotation`),this.textContent){let e=this.contentElement=document.createElement(`div`);e.classList.add(`annotationTextContent`),e.setAttribute(`role`,`comment`);for(let t of this.textContent){let n=document.createElement(`span`);n.textContent=t,e.append(n)}this.container.append(e)}return!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},xi=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`lineAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=this.#e=this.svgFactory.createElement(`svg:line`);return i.setAttribute(`x1`,e.rect[2]-e.lineCoordinates[0]),i.setAttribute(`y1`,e.rect[3]-e.lineCoordinates[1]),i.setAttribute(`x2`,e.rect[2]-e.lineCoordinates[2]),i.setAttribute(`y2`,e.rect[3]-e.lineCoordinates[3]),i.setAttribute(`stroke-width`,e.borderStyle.width||1),i.setAttribute(`stroke`,`transparent`),i.setAttribute(`fill`,`transparent`),r.append(i),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Si=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`squareAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=e.borderStyle.width,a=this.#e=this.svgFactory.createElement(`svg:rect`);return a.setAttribute(`x`,i/2),a.setAttribute(`y`,i/2),a.setAttribute(`width`,t-i),a.setAttribute(`height`,n-i),a.setAttribute(`stroke-width`,i||1),a.setAttribute(`stroke`,`transparent`),a.setAttribute(`fill`,`transparent`),r.append(a),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Ci=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`circleAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=e.borderStyle.width,a=this.#e=this.svgFactory.createElement(`svg:ellipse`);return a.setAttribute(`cx`,t/2),a.setAttribute(`cy`,n/2),a.setAttribute(`rx`,t/2-i/2),a.setAttribute(`ry`,n/2-i/2),a.setAttribute(`stroke-width`,i||1),a.setAttribute(`stroke`,`transparent`),a.setAttribute(`fill`,`transparent`),r.append(a),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},wi=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName=`polylineAnnotation`,this.svgElementName=`svg:polyline`}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,vertices:t,borderStyle:n,popupRef:r},width:i,height:a}=this;if(!t)return this.container;let o=this.svgFactory.create(i,a,!0),s=[];for(let n=0,r=t.length;n<r;n+=2){let r=t[n]-e[0],i=e[3]-t[n+1];s.push(`${r},${i}`)}s=s.join(` `);let c=this.#e=this.svgFactory.createElement(this.svgElementName);return c.setAttribute(`points`,s),c.setAttribute(`stroke-width`,n.width||1),c.setAttribute(`stroke`,`transparent`),c.setAttribute(`fill`,`transparent`),o.append(c),this.container.append(o),!r&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Ti=class extends wi{constructor(e){super(e),this.containerClassName=`polygonAnnotation`,this.svgElementName=`svg:polygon`}},Ei=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add(`caretAnnotation`),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}},Di=class extends Z{#e=null;#t=[];constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName=`inkAnnotation`,this.svgElementName=`svg:polyline`,this.annotationEditorType=this.data.it===`InkHighlight`?S.HIGHLIGHT:S.INK}#n(e,t){switch(e){case 90:return{transform:`rotate(90) translate(${-t[0]},${t[1]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};case 180:return{transform:`rotate(180) translate(${-t[2]},${t[1]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]};case 270:return{transform:`rotate(270) translate(${-t[2]},${t[3]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};default:return{transform:`translate(${-t[0]},${t[3]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]}}}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,rotation:t,inkLists:n,borderStyle:r,popupRef:i}}=this,{transform:a,width:o,height:s}=this.#n(t,e),c=this.svgFactory.create(o,s,!0),l=this.#e=this.svgFactory.createElement(`svg:g`);c.append(l),l.setAttribute(`stroke-width`,r.width||1),l.setAttribute(`stroke-linecap`,`round`),l.setAttribute(`stroke-linejoin`,`round`),l.setAttribute(`stroke-miterlimit`,10),l.setAttribute(`stroke`,`transparent`),l.setAttribute(`fill`,`transparent`),l.setAttribute(`transform`,a);for(let e=0,t=n.length;e<t;e++){let t=this.svgFactory.createElement(this.svgElementName);this.#t.push(t),t.setAttribute(`points`,n[e].join(`,`)),l.append(t)}return!i&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(c),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);let{thickness:t,points:n,rect:r}=e,i=this.#e;if(t>=0&&i.setAttribute(`stroke-width`,t||1),n)for(let e=0,t=this.#t.length;e<t;e++)this.#t[e].setAttribute(`points`,n[e].join(`,`));if(r){let{transform:e,width:t,height:n}=this.#n(this.data.rotation,r);i.parentElement.setAttribute(`viewBox`,`0 0 ${t} ${n}`),i.setAttribute(`transform`,e)}}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Oi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=S.HIGHLIGHT}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`highlightAnnotation`),this._editOnDoubleClick(),e){let t=document.createElement(`mark`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},ki=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`underlineAnnotation`),e){let t=document.createElement(`u`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},Ai=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`squigglyAnnotation`),e){let t=document.createElement(`u`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},ji=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`strikeoutAnnotation`),e){let t=document.createElement(`s`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},Mi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=S.STAMP}render(){return this.container.classList.add(`stampAnnotation`),this.container.setAttribute(`role`,`img`),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},Ni=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0});let{fileId:t,file:n}=this.data;this.filename=n.filename,this.content=n.content,this.fileId=t,this.linkService.eventBus?.dispatch(`fileattachmentannotation`,{source:this,attachmentId:this.fileId,...n})}render(){this.container.classList.add(`fileAttachmentAnnotation`);let{container:e,data:t}=this,n;t.hasAppearance||t.fillAlpha===0?n=document.createElement(`div`):(n=document.createElement(`img`),n.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(t.name)?`paperclip`:`pushpin`}.svg`,t.fillAlpha&&t.fillAlpha<1&&(n.style=`filter: opacity(${Math.round(t.fillAlpha*100)}%);`)),n.addEventListener(`dblclick`,this.#t.bind(this)),this.#e=n;let{isMac:r}=L.platform;return e.addEventListener(`keydown`,e=>{e.key===`Enter`&&(r?e.metaKey:e.ctrlKey)&&this.#t()}),!t.popupRef&&this.hasPopupData?(this.hasOwnCommentButton=!0,this._createPopup()):n.classList.add(`popupTriggerArea`),e.append(n),e}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}async#t(){let{fileId:e,filename:t,content:n}=this,r=await this.linkService.getAttachmentContent(e)||n;r&&this.downloadManager?.openOrDownloadData(r,t)}},Pi=class extends Z{#e=new AbortController;#t=null;#n=null;constructor(e){super(e,{isRenderable:!!e.data.richMedia})}render(){this.container.classList.add(`mediaAnnotation`);let{filename:e}=this.data.richMedia,t=document.createElement(`button`);return t.className=`mediaPlayButton`,t.type=`button`,t.title=t.ariaLabel=e,t.addEventListener(`click`,()=>this.#r(t),{signal:this.#e.signal}),this.container.append(t),this.container}async#r(e){let{fileId:t,filename:n,contentType:r}=this.data.richMedia;e.disabled=!0;let i;try{i=await this.linkService.getAttachmentContent(t)}catch{return}finally{e.disabled=!1}if(!i||!e.isConnected)return;let{signal:a}=this.#e,o=URL.createObjectURL(new Blob([i],{type:r}));this.#t=o;let s=r.startsWith(`audio/`),c=document.createElement(s?`audio`:`video`);if(this.#n=c,c.className=`mediaContent`,this._setBackgroundColor(c),c.src=o,c.title=n,c.controls=!0,c.autoplay=!0,c.tabIndex=0,s){let e=!1,t=!1,n=()=>{c.controls=e||t};this.container.addEventListener(`pointerenter`,()=>{e=!0,n()},{signal:a}),this.container.addEventListener(`pointerleave`,()=>{e=!1,n()},{signal:a}),this.container.addEventListener(`focusin`,()=>{t=!0,n()},{signal:a}),this.container.addEventListener(`focusout`,()=>{t=!1,n()},{signal:a})}c.addEventListener(`emptied`,()=>this.#i(o),{once:!0,signal:a}),e.replaceWith(c),c.play().catch(()=>{})}#i(e=this.#t){e&&e===this.#t&&(URL.revokeObjectURL(e),this.#t=null)}destroy(){this.#e.abort(),this.#n&&=(this.#n.pause(),this.#n.removeAttribute(`src`),this.#n.load(),null),this.#i()}},Fi=class e{#e=null;#t=null;#n=null;#r=new Map;#i=null;#a=null;#o=[];#s=!1;zIndex=0;constructor({div:e,accessibilityManager:t,annotationCanvasMap:n,annotationEditorUIManager:r,page:i,viewport:a,structTreeLayer:o,commentManager:s,linkService:c,annotationStorage:l}){this.div=e,this.#e=t,this.#t=n,this.#i=o||null,this.#a=c||null,this.#n=l||new bt,this.page=i,this.viewport=a,this._annotationEditorUIManager=r,this._commentManager=s||null}hasEditableAnnotations(){return this.#r.size>0}async render(e){let{annotations:t,optionalContentConfig:n}=e,r=this.div;Ve(r,this.viewport);let i=new Map,a=[],o={data:null,layer:r,linkService:this.#a,downloadManager:e.downloadManager,imageResourcesPath:e.imageResourcesPath||``,renderForms:e.renderForms!==!1,svgFactory:new ri,annotationStorage:this.#n,enableComment:e.enableComment===!0,enableScripting:e.enableScripting===!0,hasJSActions:e.hasJSActions,fieldObjects:e.fieldObjects,parent:this,elements:null};for(let e of t){if(e.noHTML)continue;let t=e.annotationType===D.POPUP;if(t){let t=i.get(e.id);if(!t)continue;if(!this._commentManager){a.push(e);continue}o.elements=t}else if(e.rect[2]===e.rect[0]||e.rect[3]===e.rect[1])continue;o.data=e;let r=si.create(o);if(!r.isRenderable)continue;t||(this.#o.push(r),e.popupRef&&i.getOrInsertComputed(e.popupRef,Se).push(r));let s=r.render();e.hidden&&(s.style.visibility=`hidden`),r.updateOC(n),r._isEditable&&(this.#r.set(r.data.id,r),this._annotationEditorUIManager?.renderAnnotationElement(r))}await this.#c();for(let e of a){let t=o.elements=i.get(e.id);o.data=e;let n=si.create(o);if(!n.isRenderable)continue;let r=n.render();n.contentElement.id=`${b}${e.id}`,e.hidden&&(r.style.visibility=`hidden`),t.at(-1).container.after(r)}this.#l()}async#c(){if(this.#o.length===0)return;this.div.replaceChildren();let e=[];if(!this.#s){this.#s=!0;for(let{contentElement:t,data:{id:n}}of this.#o){let r=t.id=`${b}${n}`;e.push(this.#i?.getAriaAttributes(r).then(e=>{if(e)for(let[n,r]of e)t.setAttribute(n,r)}))}}this.#o.sort(({data:{rect:[e,t,n,r]}},{data:{rect:[i,a,o,s]}})=>{if(e===n&&t===r)return 1;if(i===o&&a===s)return-1;let c=r,l=t,u=(t+r)/2,d=s,f=a,p=(a+s)/2;return u>=d&&p<=l?-1:p>=c&&u<=f?1:(e+n)/2-(i+o)/2});let t=document.createDocumentFragment();for(let e of this.#o)t.append(e.container),this._commentManager?(e.extraPopupElement?.popup||e.popup)?.renderCommentButton():e.extraPopupElement&&t.append(e.extraPopupElement.render());if(this.div.append(t),await Promise.all(e),this.#e)for(let e of this.#o)this.#e.addPointerInTextLayer(e.contentElement,!1)}async addLinkAnnotations(t){let n={data:null,layer:this.div,linkService:this.#a,svgFactory:new ri,parent:this};for(let r of t){r.borderStyle||=e._defaultBorderStyle,n.data=r;let t=si.create(n);t.isRenderable&&(t.render(),t.contentElement.id=`${b}${r.id}`,this.#o.push(t))}await this.#c()}update({viewport:e,optionalContentConfig:t}){let n=this.div;this.viewport=e,Ve(n,{rotation:e.rotation});for(let e of this.#o)e.updateOC(t);this.#l(),n.hidden=!1}destroy(){for(let e of this.#o)e.destroy?.(),this.#e?.removePointerInTextLayer(e.contentElement);this.#o.length=0,this.#r.clear(),this.div.replaceChildren()}#l(){if(!this.#t)return;let e=this.div;for(let[t,n]of this.#t){let r=e.querySelector(`[data-annotation-id="${t}"]`);if(!r)continue;if(Array.isArray(n))for(let e of n)e.className=`annotationContent`,e.ariaHidden=!0;else n.className=`annotationContent`,n.ariaHidden=!0;let i=[];for(let e of r.children)e.nodeName===`CANVAS`&&i.push(e);for(let e of i)e.remove();let a=Array.isArray(n)?n[0]:n,{firstChild:o}=r;if(o?o.classList.contains(`annotationContent`)?o.after(a):o.before(a):r.append(a),Array.isArray(n)){let e=a;for(let t=1,r=n.length;t<r;t++)e.after(n[t]),e=n[t]}this.#t.delete(t);let s=this.#r.get(t);s&&(s._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(t,r.id,n),s._hasNoCanvas=!1):s.canvas=n)}}refreshCanvases(){this.#l()}getEditableAnnotations(){return this.#r.values()}getEditableAnnotation(e){return this.#r.get(e)}addFakeAnnotation(e){let{div:t}=this,{id:n,rotation:r}=e,i=new ci({data:{id:n,rect:e.getPDFRect(),rotation:r},editor:e,layer:t,parent:this,enableComment:!!this._commentManager,linkService:this.#a,annotationStorage:this.#n});return i.render(),i.contentElement.id=`${b}${n}`,i.createOrUpdatePopup(),this.#o.push(i),i}removeAnnotation(e){let t=this.#o.findIndex(t=>t.data.id===e);if(t<0)return;let[n]=this.#o.splice(t,1);this.#e?.removePointerInTextLayer(n.contentElement)}updateFakeAnnotations(e){if(e.length!==0){for(let t of e)t.updateFakeAnnotationElement(this);this.#c()}}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}static get _defaultBorderStyle(){return I(this,`_defaultBorderStyle`,Object.freeze({width:1,rawWidth:1,style:O.SOLID,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}},Ii=/\r\n?|\n/g,Li=class e extends K{#e=``;#t=`${this.id}-editor`;#n=null;#r;_colorPicker=null;static _freeTextDefaultContent=``;static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.isEmpty(),r=ut.TRANSLATE_SMALL,i=ut.TRANSLATE_BIG;return I(this,`_keyboardManager`,new ct([[[`ctrl+s`,`mac+meta+s`,`ctrl+p`,`mac+meta+p`],t.commitOrRemove,{bubbles:!0}],[[`ctrl+Enter`,`mac+meta+Enter`],t.commitOrRemove],[[`Escape`],t.commitOrRemove],[[`ArrowLeft`],t._translateEmpty,{args:[-r,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t._translateEmpty,{args:[-i,0],checker:n}],[[`ArrowRight`],t._translateEmpty,{args:[r,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t._translateEmpty,{args:[i,0],checker:n}],[[`ArrowUp`],t._translateEmpty,{args:[0,-r],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t._translateEmpty,{args:[0,-i],checker:n}],[[`ArrowDown`],t._translateEmpty,{args:[0,r],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t._translateEmpty,{args:[0,i],checker:n}]]))}static _type=`freetext`;static _editorType=S.FREETEXT;constructor(t){super({...t,name:`freeTextEditor`}),this.color=t.color||e._defaultColor||K._defaultLineColor,this.#r=t.fontSize||e._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.freetext),this.canAddComment=!1}static initialize(e,t){K.initialize(e,t);let n=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(n.getPropertyValue(`--freetext-padding`))}static updateDefaultParams(t,n){switch(t){case C.FREETEXT_SIZE:e._defaultFontSize=n;break;case C.FREETEXT_COLOR:e._defaultColor=n;break}}updateParams(e,t){switch(e){case C.FREETEXT_SIZE:this.#i(t);break;case C.FREETEXT_COLOR:this.#a(t);break}}static get defaultPropertiesToUpdate(){return[[C.FREETEXT_SIZE,e._defaultFontSize],[C.FREETEXT_COLOR,e._defaultColor||K._defaultLineColor]]}get propertiesToUpdate(){return[[C.FREETEXT_SIZE,this.#r],[C.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new Qr(this),[[`colorPicker`,this._colorPicker]]}get colorType(){return C.FREETEXT_COLOR}#i(e){let t=e=>{this.editorDiv.style.fontSize=`calc(${e}px * var(--total-scale-factor))`,this.translate(0,-(e-this.#r)*this.parentScale),this.#r=e,this.#s()},n=this.#r;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#a(e){let t=e=>{this.color=e,this.onUpdatedColor()},n=this.color;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(e,t){this._uiManager.translateSelectedEditors(e,t,!0)}getInitialTranslation(){let t=this.parentScale;return[-e._internalPadding*t,-(e._internalPadding+this.#r)*t]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove(`enabled`),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute(`aria-activedescendant`),this.#n=new AbortController;let e=this._uiManager.combinedSignal(this.#n);return this.editorDiv.addEventListener(`keydown`,this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener(`focus`,this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener(`blur`,this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener(`input`,this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener(`paste`,this.editorDivPaste.bind(this),{signal:e}),!0}disableEditMode(){return super.disableEditMode()?(this.overlayDiv.classList.add(`enabled`),this.editorDiv.contentEditable=!1,this.div.setAttribute(`aria-activedescendant`,this.#t),this._isDraggable=!0,this.#n?.abort(),this.#n=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add(`freetextEditing`),!0):!1}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),this._initialOptions?.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===``}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add(`freetextEditing`)),super.remove()}#o(){let t=[];this.editorDiv.normalize();let n=null;for(let r of this.editorDiv.childNodes)n?.nodeType===Node.TEXT_NODE&&r.nodeName===`BR`||(t.push(e.#c(r)),n=r);return t.join(`
44
+ `,gn=new class{#e=null;#t=null;#n=null;#r=null;async#i(){if(!globalThis.navigator?.gpu)return!1;try{let e=await navigator.gpu.requestAdapter();return e?(this.#r=navigator.gpu.getPreferredCanvasFormat(),this.#t=await e.requestDevice(),!0):!1}catch{return!1}}init(){return this.#e||=this.#i()}get isReady(){return this.#t!==null}loadMeshShader(){if(!this.#t||this.#n)return;let e=this.#t.createShaderModule({code:hn});this.#n=this.#t.createRenderPipeline({layout:`auto`,vertex:{module:e,entryPoint:`vs_main`,buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:`unorm8x4`}]}]},fragment:{module:e,entryPoint:`fs_main`,targets:[{format:this.#r}]},primitive:{topology:`triangle-list`}})}draw(e,t,n,r,i,a,o,s){this.loadMeshShader();let c=this.#t,{offsetX:l,offsetY:u,scaleX:d,scaleY:f}=r,p=c.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&c.queue.writeBuffer(p,0,e);let m=c.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&c.queue.writeBuffer(m,0,t);let h=c.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});c.queue.writeBuffer(h,0,new Float32Array([l,u,d,f,a,o,s,0]));let g=c.createBindGroup({layout:this.#n.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:h}}]}),_=new OffscreenCanvas(a,o),v=_.getContext(`webgpu`);v.configure({device:c,format:this.#r,alphaMode:i?`opaque`:`premultiplied`});let y=i?{r:i[0]/255,g:i[1]/255,b:i[2]/255,a:1}:{r:0,g:0,b:0,a:0},b=c.createCommandEncoder(),x=b.beginRenderPass({colorAttachments:[{view:v.getCurrentTexture().createView(),clearValue:y,loadOp:`clear`,storeOp:`store`}]});return n>0&&(x.setPipeline(this.#n),x.setBindGroup(0,g),x.setVertexBuffer(0,p),x.setVertexBuffer(1,m),x.draw(n)),x.end(),c.queue.submit([b.finish()]),p.destroy(),m.destroy(),h.destroy(),_.transferToImageBitmap()}};function _n(){return gn.init()}function vn(){return gn.isReady}function yn(){gn.loadMeshShader()}function bn(e,t,n,r,i,a,o,s){return gn.draw(e,t,n,r,i,a,o,s)}var Y={FILL:`Fill`,STROKE:`Stroke`,SHADING:`Shading`};function xn(e,t){if(!t)return;let n=t[2]-t[0],r=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],n,r),e.clip(i)}var Sn=class{isModifyingCurrentTransform(){return!1}getPattern(){F("Abstract method `getPattern` called.")}},Cn=class extends Sn{constructor(e){super(),this._type=e[1],this._bbox=e[2],this._colorStops=e[3],this._p0=e[4],this._p1=e[5],this._r0=e[6],this._r1=e[7],this.matrix=null}isOriginBased(){return this._p0[0]===0&&this._p0[1]===0&&(!this.isRadial()||this._p1[0]===0&&this._p1[1]===0)}isRadial(){return this._type===`radial`}areConic(){if(!this.isRadial())return!1;let e=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return e+this._r1>this._r0&&e+this._r0>this._r1}_createGradient(e,t=null){let n,r=this._p0,i=this._p1;if(t&&(r=r.slice(),i=i.slice(),z.applyTransform(r,t),z.applyTransform(i,t)),this._type===`axial`)n=e.createLinearGradient(r[0],r[1],i[0],i[1]);else if(this._type===`radial`){let a=this._r0,o=this._r1;if(t){let e=new Float32Array(2);z.singularValueDecompose2dScale(t,e),a*=e[0],o*=e[0]}n=e.createRadialGradient(r[0],r[1],a,i[0],i[1],o)}for(let e of this._colorStops)n.addColorStop(e[0],e[1]);return n}_createReversedGradient(e,t=null){let n=this._p1,r=this._p0;t&&(n=n.slice(),r=r.slice(),z.applyTransform(n,t),z.applyTransform(r,t));let i=this._r1,a=this._r0;if(t){let e=new Float32Array(2);z.singularValueDecompose2dScale(t,e),i*=e[0],a*=e[0]}let o=e.createRadialGradient(n[0],n[1],i,r[0],r[1],a),s=this._colorStops.map(([e,t])=>[1-e,t]).reverse();for(let[e,t]of s)o.addColorStop(e,t);return o}getPattern(e,t,n,r){let i;if(r===Y.STROKE||r===Y.FILL){if(this.isOriginBased()){let r=z.transform(n,t.baseTransform);this.matrix&&(r=z.transform(r,this.matrix));let i=.001,a=Math.hypot(r[0],r[1]),o=Math.hypot(r[2],r[3]),s=(r[0]*r[2]+r[1]*r[3])/(a*o);if(Math.abs(s)<i)if(this.isRadial()){if(Math.abs(a-o)<i)return this._createGradient(e,r)}else return this._createGradient(e,r)}let a=t.current.getClippedPathBoundingBox(r,W(e))||[0,0,0,0],o=Math.ceil(a[2]-a[0])||1,s=Math.ceil(a[3]-a[1])||1,c=t.canvasFactory.create(o,s),l=c.context;l.clearRect(0,0,l.canvas.width,l.canvas.height),l.beginPath(),l.rect(0,0,l.canvas.width,l.canvas.height),l.translate(-a[0],-a[1]),n=z.transform(n,[1,0,0,1,a[0],a[1]]),l.transform(...t.baseTransform),this.matrix&&l.transform(...this.matrix),xn(l,this._bbox),this.areConic()&&(l.fillStyle=this._createReversedGradient(l),l.fill()),l.fillStyle=this._createGradient(l),l.fill(),i=e.createPattern(c.canvas,`no-repeat`),t.canvasFactory.destroy(c);let u=new DOMMatrix(n);i.setTransform(u)}else this.areConic()&&(e.save(),xn(e,this._bbox),e.fillStyle=this._createReversedGradient(e),e.fillRect(-1e10,-1e10,2e10,2e10),e.restore()),xn(e,this._bbox),i=this._createGradient(e);return i}};function wn(e,t,n,r,i,a,o,s){let c=t.coords,l=t.colors,u=e.data,d=e.width*4,f;c[n*2+1]>c[r*2+1]&&(f=n,n=r,r=f,f=a,a=o,o=f),c[r*2+1]>c[i*2+1]&&(f=r,r=i,i=f,f=o,o=s,s=f),c[n*2+1]>c[r*2+1]&&(f=n,n=r,r=f,f=a,a=o,o=f);let p=(c[n*2]+t.offsetX)*t.scaleX,m=(c[n*2+1]+t.offsetY)*t.scaleY,h=(c[r*2]+t.offsetX)*t.scaleX,g=(c[r*2+1]+t.offsetY)*t.scaleY,_=(c[i*2]+t.offsetX)*t.scaleX,v=(c[i*2+1]+t.offsetY)*t.scaleY;if(m>=v)return;let y=l[a*4],b=l[a*4+1],x=l[a*4+2],S=l[o*4],C=l[o*4+1],w=l[o*4+2],T=l[s*4],E=l[s*4+1],D=l[s*4+2],O=Math.round(m),k=Math.round(v),A,j,ee,M,N,te,ne,P;for(let e=O;e<=k;e++){if(e<g){let t=e<m?0:(m-e)/(m-g);A=p-(p-h)*t,j=y-(y-S)*t,ee=b-(b-C)*t,M=x-(x-w)*t}else{let t;t=e>v?1:g===v?0:(g-e)/(g-v),A=h-(h-_)*t,j=S-(S-T)*t,ee=C-(C-E)*t,M=w-(w-D)*t}let t;t=e<m?0:e>v?1:(m-e)/(m-v),N=p-(p-_)*t,te=y-(y-T)*t,ne=b-(b-E)*t,P=x-(x-D)*t;let n=Math.round(Math.min(A,N)),r=Math.round(Math.max(A,N)),i=d*e+n*4;for(let e=n;e<=r;e++)t=(A-e)/(A-N),t<0?t=0:t>1&&(t=1),u[i++]=j-(j-te)*t|0,u[i++]=ee-(ee-ne)*t|0,u[i++]=M-(M-P)*t|0,u[i++]=255}}var Tn=class extends Sn{constructor(e){super(),this._posData=e[2],this._colData=e[3],this._vertexCount=e[4],this._bounds=e[5],this._bbox=e[6],this._background=e[7],this.matrix=null,yn()}_createMeshCanvas(e,t,n){let r=1.1,i=3e3,a=Math.floor(this._bounds[0]),o=Math.floor(this._bounds[1]),s=Math.ceil(this._bounds[2])-a,c=Math.ceil(this._bounds[3])-o,l=Math.min(Math.ceil(Math.abs(s*e[0]*r)),i)||1,u=Math.min(Math.ceil(Math.abs(c*e[1]*r)),i)||1,d=s?s/l:1,f=c?c/u:1,p={coords:this._posData,colors:this._colData,offsetX:-a,offsetY:-o,scaleX:1/d,scaleY:1/f},m=l+4,h=u+4,g=n.create(m,h);if(vn()&&this._vertexCount>48)g.context.drawImage(bn(this._posData,this._colData,this._vertexCount,p,t,m,h,2),0,0);else{let e=g.context.createImageData(l,u);if(t){let n=e.data;for(let e=0,r=n.length;e<r;e+=4)n[e]=t[0],n[e+1]=t[1],n[e+2]=t[2],n[e+3]=255}for(let t=0,n=this._vertexCount;t<n;t+=3)wn(e,p,t,t+1,t+2,t,t+1,t+2);g.context.putImageData(e,2,2)}return{canvas:g.canvas,offsetX:a-2*d,offsetY:o-2*f,scaleX:d,scaleY:f}}isModifyingCurrentTransform(){return!0}getPattern(e,t,n,r){xn(e,this._bbox);let i=new Float32Array(2);if(r===Y.SHADING)z.singularValueDecompose2dScale(W(e),i);else if(this.matrix){z.singularValueDecompose2dScale(this.matrix,i);let[e,n]=i;z.singularValueDecompose2dScale(t.baseTransform,i),i[0]*=e,i[1]*=n}else z.singularValueDecompose2dScale(t.baseTransform,i);let a=this._createMeshCanvas(i,r===Y.SHADING?null:this._background,t.canvasFactory);r!==Y.SHADING&&(e.setTransform(...t.baseTransform),this.matrix&&e.transform(...this.matrix)),e.translate(a.offsetX,a.offsetY),e.scale(a.scaleX,a.scaleY);let o=e.createPattern(a.canvas,`no-repeat`);return t.canvasFactory.destroy(a),o}},En=class extends Sn{getPattern(){return`hotpink`}};function Dn(e){switch(e[0]){case`RadialAxial`:return new Cn(e);case`Mesh`:return new Tn(e);case`Dummy`:return new En}throw Error(`Unknown IR type: ${e[0]}`)}var On={COLORED:1,UNCOLORED:2},kn=class e{static MAX_PATTERN_SIZE=3e3;constructor(e,t,n,r){this.color=e[1],this.operatorList=e[2],this.matrix=e[3],this.bbox=e[4],this.xstep=e[5],this.ystep=e[6],this.paintType=e[7],this.tilingType=e[8],this.needsIsolation=e[9]??!0,this.ctx=t,this.canvasGraphicsFactory=n,this.baseTransform=r,this.patternBaseMatrix=this.matrix?z.transform(r,this.matrix):r}canSkipPatternCanvas([e,t,n,r]){let[i,a,o,s]=this.bbox,c=Math.abs(this.xstep),l=Math.abs(this.ystep);if(e>c+1e-6||t>l+1e-6)return null;let u=Math.floor((n-o)/c)+1,d=Math.ceil((n+e-i)/c)-1,f=Math.floor((r-s)/l)+1,p=Math.ceil((r+t-a)/l)-1;return d<=u&&p<=f?[u,f]:null}updatePatternDims(e,t){let n=z.inverseTransform(this.patternBaseMatrix),r=[e[0],e[1]],i=[e[2],e[3]];z.applyTransform(r,n),z.applyTransform(i,n),t[0]=Math.abs(i[0]-r[0]),t[1]=Math.abs(i[1]-r[1]),t[2]=Math.min(r[0],i[0]),t[3]=Math.min(r[1],i[1])}_renderTileCanvas(e,t,n,r){let[i,a,o,s]=this.bbox,c=e.canvasFactory.create(n.size,r.size),l=c.context,u=this.canvasGraphicsFactory.createCanvasGraphics(l,t);return u.groupLevel=e.groupLevel,this.setFillAndStrokeStyleToContext(u,this.paintType,this.color),l.translate(-n.scale*i,-r.scale*a),u.transform(0,n.scale,0,0,r.scale,0,0),l.save(),u.dependencyTracker?.save(),this.clipBbox(u,i,a,o,s),u.baseTransform=W(u.ctx),u.executeOperatorList(this.operatorList),u.endDrawing(),u.dependencyTracker?.restore(),l.restore(),c}_getCombinedScales(){let e=new Float32Array(2);z.singularValueDecompose2dScale(this.matrix,e);let[t,n]=e;return z.singularValueDecompose2dScale(this.baseTransform,e),[t*e[0],n*e[1]]}drawPattern(e,t,n=!1,[r,i],a){let[o,s,c,l]=this.bbox,u=e.dependencyTracker;if(u&&(e.dependencyTracker=new Mt(u,a)),e.save(),n?e.ctx.clip(t,`evenodd`):e.ctx.clip(t),e.ctx.setTransform(...this.patternBaseMatrix),e.ctx.translate(r*this.xstep,i*this.ystep),this.needsIsolation||e.ctx.globalAlpha!==1||e.ctx.globalCompositeOperation!==`source-over`||e.inSMaskMode){let t=c-o,n=l-s,[r,i]=this._getCombinedScales(),u=this.getSizeAndScale(t,this.ctx.canvas.width,r),d=this.getSizeAndScale(n,this.ctx.canvas.height,i),f=this._renderTileCanvas(e,a,u,d);e.ctx.drawImage(f.canvas,o,s,t,n),e.canvasFactory.destroy(f)}else this.setFillAndStrokeStyleToContext(e,this.paintType,this.color),this.clipBbox(e,o,s,c,l),e.baseTransformStack.push(e.baseTransform),e.baseTransform=W(e.ctx),e.executeOperatorList(this.operatorList),e.baseTransform=e.baseTransformStack.pop();e.restore(),u&&(e.dependencyTracker=u)}createPatternCanvas(e,t){let[n,r,i,a]=this.bbox,o=i-n,s=a-r,{xstep:c,ystep:l}=this;c=Math.abs(c),l=Math.abs(l),ne(`TilingType: `+this.tilingType);let[u,d]=this._getCombinedScales(),f=o,p=s,m=!1,h=!1;Math.ceil(c*u)>=Math.ceil(o*u)?f=c:m=!0,Math.ceil(l*d)>=Math.ceil(s*d)?p=l:h=!0;let g=this.getSizeAndScale(f,this.ctx.canvas.width,u),_=this.getSizeAndScale(p,this.ctx.canvas.height,d),v=this._renderTileCanvas(e,t,g,_);if(m||h){let t=v.canvas;m&&(f=c),h&&(p=l);let i=this.getSizeAndScale(f,this.ctx.canvas.width,u),a=this.getSizeAndScale(p,this.ctx.canvas.height,d),g=i.size,_=a.size,y=e.canvasFactory.create(g,_),b=y.context,x=m?Math.floor(o/c):0,S=h?Math.floor(s/l):0;for(let e=0;e<=x;e++)for(let n=0;n<=S;n++)b.drawImage(t,g*e,_*n,g,_,0,0,g,_);return e.canvasFactory.destroy(v),{canvas:y.canvas,canvasEntry:y,scaleX:i.scale,scaleY:a.scale,offsetX:n,offsetY:r}}return{canvas:v.canvas,canvasEntry:v,scaleX:g.scale,scaleY:_.scale,offsetX:n,offsetY:r}}getSizeAndScale(t,n,r){let i=Math.max(e.MAX_PATTERN_SIZE,n),a=Math.ceil(t*r);return a>=i?a=i:r=a/t,{scale:r,size:a}}clipBbox(e,t,n,r,i){let a=r-t,o=i-n,s=new Path2D;s.rect(t,n,a,o),z.axialAlignedBoundingBox([t,n,r,i],W(e.ctx),e.current.minMax),e.ctx.clip(s),e.current.updateClipFromPath()}setFillAndStrokeStyleToContext(e,t,n){let r=e.ctx,i=e.current;switch(i.patternFill=i.patternStroke=!1,t){case On.COLORED:let{fillStyle:e,strokeStyle:a}=this.ctx;r.fillStyle=i.fillColor=e,r.strokeStyle=i.strokeColor=a;break;case On.UNCOLORED:r.fillStyle=r.strokeStyle=n,i.fillColor=i.strokeColor=n;break;default:throw new fe(`Unsupported paint type: ${t}`)}}isModifyingCurrentTransform(){return!1}getPattern(e,t,n,r,i){let a=r===Y.SHADING?n:z.transform(n,this.patternBaseMatrix),o=this.createPatternCanvas(t,i),s=new DOMMatrix(a);s=s.translate(o.offsetX,o.offsetY),s=s.scale(1/o.scaleX,1/o.scaleY);let c=e.createPattern(o.canvas,`repeat`);return t.canvasFactory.destroy(o.canvasEntry),c.setTransform(s),c}},An=16,jn=100,Mn=15,Nn=10,X=16,Pn=new DOMMatrix,Fn=new Float32Array(2);function In(e,t){if(e._removeMirroring)throw Error(`Context is already forwarding operations.`);let n=new Map;for(let r of[`save`,`restore`,`rotate`,`scale`,`translate`,`transform`,`setTransform`,`resetTransform`,`clip`,`moveTo`,`lineTo`,`bezierCurveTo`,`quadraticCurveTo`,`arc`,`arcTo`,`ellipse`,`rect`,`roundRect`,`closePath`,`beginPath`]){let i=e[r];typeof i!=`function`||typeof t[r]!=`function`||(n.set(r,i),e[r]=function(...e){return t[r](...e),i.apply(this,e)})}e._removeMirroring=()=>{for(let[t,r]of n)e[t]=r;delete e._removeMirroring}}function Ln(e,t,n,r,i,a,o,s,c,l){let[u,d,f,p,m,h]=W(e);if(d===0&&f===0){let g=o*u+m,_=Math.round(g),v=s*p+h,y=Math.round(v),b=(o+c)*u+m,x=Math.abs(Math.round(b)-_)||1,S=(s+l)*p+h,C=Math.abs(Math.round(S)-y)||1;return e.setTransform(Math.sign(u),0,0,Math.sign(p),_,y),e.drawImage(t,n,r,i,a,0,0,x,C),e.setTransform(u,d,f,p,m,h),[x,C]}if(u===0&&p===0){let g=s*f+m,_=Math.round(g),v=o*d+h,y=Math.round(v),b=(s+l)*f+m,x=Math.abs(Math.round(b)-_)||1,S=(o+c)*d+h,C=Math.abs(Math.round(S)-y)||1;return e.setTransform(0,Math.sign(d),Math.sign(f),0,_,y),e.drawImage(t,n,r,i,a,0,0,C,x),e.setTransform(u,d,f,p,m,h),[C,x]}e.drawImage(t,n,r,i,a,o,s,c,l);let g=Math.hypot(u,d),_=Math.hypot(f,p);return[g*c,_*l]}var Rn=class{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=h;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=T.FILL;textRise=0;fillColor=`#000000`;strokeColor=`#000000`;tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps=`none`;minMax=m.slice();constructor(e,t){this.clipBox=new Float32Array([0,0,e,t])}clone(){let e=Object.create(this);return e.clipBox=this.clipBox.slice(),e.minMax=this.minMax.slice(),e.tilingPatternDims=this.tilingPatternDims?.slice(),e}getPathBoundingBox(e=Y.FILL,t=null){let n=this.minMax.slice();if(e===Y.STROKE){t||F(`Stroke bounding box must include transform.`),z.singularValueDecompose2dScale(t,Fn);let e=Fn[0]*this.lineWidth/2,r=Fn[1]*this.lineWidth/2;n[0]-=e,n[1]-=r,n[2]+=e,n[3]+=r}return n}updateClipFromPath(){let e=z.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(e||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(e){this.clipBox.set(e,0),this.minMax.set(m,0)}getClippedPathBoundingBox(e=Y.FILL,t=null){return z.intersect(this.clipBox,this.getPathBoundingBox(e,t))}};function zn(e,t){let{width:n,height:r,kind:i}=t,a=r%X,o=(r-a)/X,s=a===0?o:o+1,c=e.createImageData(n,X),l=0,u=t.data,d=c.data,f;if(i===E.GRAYSCALE_1BPP)for(f=0;f<s;f++)({srcPos:l}=pn({src:u,srcPos:l,dest:d,width:n,height:f<o?X:a})),e.putImageData(c,0,f*X);else if(i===E.RGBA_32BPP){let t=0,r=n*X*4;for(f=0;f<o;f++)d.set(u.subarray(l,l+r)),l+=r,e.putImageData(c,0,t),t+=X;f<s&&(r=n*a*4,d.set(u.subarray(l,l+r)),e.putImageData(c,0,t))}else if(i===E.RGB_24BPP)for(f=0;f<s;f++)({srcPos:l}=mn({src:u,srcPos:l,dest:new Uint32Array(d.buffer),width:n,height:f<o?X:a})),e.putImageData(c,0,f*X);else throw Error(`bad image kind: ${i}`)}function Bn(e,t){if(t.bitmap){e.drawImage(t.bitmap,0,0);return}let{width:n,height:r}=t,i=r%X,a=(r-i)/X,o=i===0?a:a+1,s=e.createImageData(n,X),c=0,l=t.data,u=s.data;for(let t=0;t<o;t++)({srcPos:c}=pn({src:l,srcPos:c,dest:u,width:n,height:t<a?X:i,nonBlackColor:0})),e.putImageData(s,0,t*X)}function Vn(e,t){for(let n of[`strokeStyle`,`fillStyle`,`fillRule`,`globalAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`globalCompositeOperation`,`font`,`filter`])e[n]!==void 0&&(t[n]=e[n]);e.setLineDash!==void 0&&(t.setLineDash(e.getLineDash()),t.lineDashOffset=e.lineDashOffset)}function Hn(e){e.strokeStyle=e.fillStyle=`#000000`,e.fillRule=`nonzero`,e.globalAlpha=1,e.lineWidth=1,e.lineCap=`butt`,e.lineJoin=`miter`,e.miterLimit=10,e.globalCompositeOperation=`source-over`,e.font=`10px sans-serif`,e.setLineDash!==void 0&&(e.setLineDash([]),e.lineDashOffset=0);let{filter:t}=e;t!==`none`&&t!==``&&(e.filter=`none`)}function Un(e,t){if(t)return!0;z.singularValueDecompose2dScale(e,Fn);let n=Math.fround(He.pixelRatio*De.PDF_TO_CSS_UNITS);return Fn[0]<=n&&Fn[1]<=n}var Wn=[`butt`,`round`,`square`],Gn=[`miter`,`round`,`bevel`],Kn={},qn={},Jn=class e{#e=0;#t=0;#n=null;#r=null;#i=null;#a=null;#o=1;#s;#c=null;#l=[];constructor(e,t,n,r,i,{optionalContentConfig:a,markedContentStack:o=null},s,c,l,u){this.ctx=e,this.current=new Rn(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.commonObjs=t,this.objs=n,this.canvasFactory=r,this.filterFactory=i,this.groupStack=[],this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.tempSMask=null,this.smaskGroupCanvases=[],this.smaskPreparedEntry=null,this.smaskPreparedFor=null,this.smaskPreparedOffsetX=0,this.smaskPreparedOffsetY=0,this.smaskPreparedOOBAlpha=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=a,this.cachedPatterns=new Map,this.annotationCanvasMap=s,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map,this.dependencyTracker=l??null,this.imagesTracker=u??null}getObject(e,t,n=null){return typeof t==`string`?(this.dependencyTracker?.recordNamedDependency(e,t),t.startsWith(`g_`)?this.commonObjs.get(t):this.objs.get(t)):n}beginDrawing({transform:e,viewport:t,transparency:n=!1,background:r=null}){let i=this.ctx.canvas.width,a=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=r||`#ffffff`,this.ctx.fillRect(0,0,i,a),this.ctx.fillStyle=o,n){let e=this.transparentCanvasEntry=this.canvasFactory.create(i,a);this.compositeCtx=this.ctx,{canvas:this.transparentCanvas,context:this.ctx}=e,this.ctx.save(),this.ctx.transform(...W(this.compositeCtx))}this.ctx.save(),Hn(this.ctx),e&&(this.ctx.transform(...e),this.outputScaleX=e[0],this.outputScaleY=e[3]),this.ctx.transform(...t.transform),this.viewportScale=t.scale,this.baseTransform=W(this.ctx)}executeOperatorList(e,t,n,r,i){let a=e.argsArray,o=e.fnArray,s=t||0,c=a.length;if(c===s)return s;let l=c-s>Nn&&typeof n==`function`,u=l?Date.now()+Mn:0,d=0,f=this.commonObjs,p=this.objs,m,h;for(;;){if(r!==void 0){if(s===r.nextBreakPoint)return r.breakIt(s,n),s;if(r.shouldSkip(s)){if(++s===c)return s;continue}}if(!i||i(s))if(m=o[s],h=a[s]??null,m!==A.dependency)h===null?this[m](s):this[m](s,...h);else for(let e of h){this.dependencyTracker?.recordNamedData(e,s);let t=e.startsWith(`g_`)?f:p;if(!t.has(e))return t.get(e,n),s}if(s++,s===c)return s;if(l&&++d>Nn){if(Date.now()>u)return n(),s;d=0}}}#u(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.canvasFactory.destroy(this.transparentCanvasEntry),this.transparentCanvas=null,this.transparentCanvasEntry=null)}endDrawing(){this.#u();for(let e of this.smaskGroupCanvases)this.canvasFactory.destroy(e);this.smaskGroupCanvases.length=0,this._clearPreparedSMask(),this.tempSMask=null,this.smaskStack.length=0;for(let e of this.#l)this.#y(e);this.#l.length=0,this.#n=null,this.#r=null,this.#i=null,this.#a=null,this.#o=1,this.#c=null,this.#t=0,this.#e=0,this.cachedPatterns.clear();for(let e of this._cachedBitmapsMap.values()){for(let t of e.values())typeof HTMLCanvasElement<`u`&&t instanceof HTMLCanvasElement&&(t.width=t.height=0);e.clear()}this._cachedBitmapsMap.clear(),this.#d()}#d(){if(this.pageColors){let e=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(e!==`none`){let t=this.ctx.filter;this.ctx.filter=e,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=t}}}_scaleImage(e,t){let n=e.width??e.displayWidth,r=e.height??e.displayHeight,i=Math.max(Math.hypot(t[0],t[1]),1),a=Math.max(Math.hypot(t[2],t[3]),1),o=[],s=i,c=a,l=n,u=r;for(;s>2&&l>1||c>2&&u>1;){let e=l,t=u;s>2&&l>1&&(e=Math.ceil(l/2),s/=l/e),c>2&&u>1&&(t=Math.ceil(u/2),c/=u/t),o.push({newWidth:e,newHeight:t}),l=e,u=t}if(o.length===0)return{img:e,paintWidth:n,paintHeight:r,tmpCanvas:null};if(o.length===1){let{newWidth:t,newHeight:i}=o[0],a=this.canvasFactory.create(t,i);return a.context.drawImage(e,0,0,n,r,0,0,t,i),{img:a.canvas,paintWidth:t,paintHeight:i,tmpCanvas:a}}let d=this.canvasFactory.create(1,1),f=this.canvasFactory.create(1,1),p=n,m=r,h=e;for(let{newWidth:e,newHeight:t}of o)this.canvasFactory.reset(f,e,t),f.context.drawImage(h,0,0,p,m,0,0,e,t),[d,f]=[f,d],h=d.canvas,p=e,m=t;return this.canvasFactory.destroy(f),{img:d.canvas,paintWidth:p,paintHeight:m,tmpCanvas:d}}_createMaskCanvas(e,t){let n=this.ctx,{width:r,height:i}=t,a=this.current.fillColor,o=this.current.patternFill,s=W(n),c,l,u,d;if((t.bitmap||t.data)&&t.count>1){let n=t.bitmap||t.data.buffer;l=JSON.stringify(o?s:[s.slice(0,4),a]),c=this._cachedBitmapsMap.getOrInsertComputed(n,Se);let r=c.get(l);if(r&&!o){let t=Math.round(Math.min(s[0],s[2])+s[4]),n=Math.round(Math.min(s[1],s[3])+s[5]);return this.dependencyTracker?.recordDependencies(e,Nt.transformAndFill),{canvas:r,offsetX:t,offsetY:n}}u=r}u||(d=this.canvasFactory.create(r,i),Bn(d.context,t));let f=z.transform(s,[1/r,0,0,-1/i,0,0]);f=z.transform(f,[1,0,0,1,0,-i]);let p=m.slice();z.axialAlignedBoundingBox([0,0,r,i],f,p);let[h,g,_,v]=p,y=Math.round(_-h)||1,b=Math.round(v-g)||1,x=this.canvasFactory.create(y,b),S=x.context,C=h,w=g;S.translate(-C,-w),S.transform(...f);let T=null;if(!u){let e=this._scaleImage(d.canvas,Be(S));u=e.img,T=e.tmpCanvas,u!==d.canvas&&(this.canvasFactory.destroy(d),d=null),c&&o&&(c.set(l,u),T=null,d=null)}S.imageSmoothingEnabled=Un(W(S),t.interpolate),Ln(S,u,0,0,u.width,u.height,0,0,r,i),T&&this.canvasFactory.destroy(T),d&&this.canvasFactory.destroy(d),S.globalCompositeOperation=`source-in`;let E=z.transform(Be(S),[1,0,0,1,-C,-w]);return S.fillStyle=o?a.getPattern(n,this,E,Y.FILL,e):a,S.fillRect(0,0,r,i),c&&!o&&c.set(l,x.canvas),this.dependencyTracker?.recordDependencies(e,Nt.transformAndFill),{canvas:x.canvas,canvasEntry:c&&!o?null:x,offsetX:Math.round(C),offsetY:Math.round(w)}}setLineWidth(e,t){this.dependencyTracker?.recordSimpleData(`lineWidth`,e),t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(e,t){this.dependencyTracker?.recordSimpleData(`lineCap`,e),this.ctx.lineCap=Wn[t]}setLineJoin(e,t){this.dependencyTracker?.recordSimpleData(`lineJoin`,e),this.ctx.lineJoin=Gn[t]}setMiterLimit(e,t){this.dependencyTracker?.recordSimpleData(`miterLimit`,e),this.ctx.miterLimit=t}setDash(e,t,n){this.dependencyTracker?.recordSimpleData(`dash`,e);let r=this.ctx;r.setLineDash!==void 0&&(r.setLineDash(t),r.lineDashOffset=n)}setRenderingIntent(e,t){}setFlatness(e,t){}setGState(e,t){for(let[n,r]of t)switch(n){case`LW`:this.setLineWidth(e,r);break;case`LC`:this.setLineCap(e,r);break;case`LJ`:this.setLineJoin(e,r);break;case`ML`:this.setMiterLimit(e,r);break;case`D`:this.setDash(e,r[0],r[1]);break;case`RI`:this.setRenderingIntent(e,r);break;case`FL`:this.setFlatness(e,r);break;case`Font`:this.setFont(e,r[0],r[1]);break;case`CA`:this.dependencyTracker?.recordSimpleData(`strokeAlpha`,e),this.current.strokeAlpha=r;break;case`ca`:this.dependencyTracker?.recordSimpleData(`fillAlpha`,e),this.ctx.globalAlpha=this.current.fillAlpha=r;break;case`BM`:this.dependencyTracker?.recordSimpleData(`globalCompositeOperation`,e),this.ctx.globalCompositeOperation=r;break;case`SMask`:this.dependencyTracker?.recordSimpleData(`SMask`,e),this.current.activeSMask=r?this.tempSMask:null,this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation),this.tempSMask=null,this.checkSMaskState(e);break;case`TR`:this.dependencyTracker?.recordSimpleData(`filter`,e),this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(r);break}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){this.smaskPreparedEntry&&=(this.canvasFactory.destroy(this.smaskPreparedEntry),null),this.smaskPreparedFor=null,this.smaskPreparedOffsetX=0,this.smaskPreparedOffsetY=0,this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(e){e!==this.smaskPreparedFor&&(this._clearPreparedSMask(),this._prepareSMaskCanvas(e))}checkSMaskState(e){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode(e):!this.current.activeSMask&&t?this.endSMaskMode():this.current.activeSMask&&t&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(e){let{canvas:t,subtype:n,backdrop:r,transferMap:i}=e,a=n===`Luminosity`||n===`Alpha`&&i;if(!a&&!(n===`Luminosity`&&r)){this.smaskPreparedFor=e;return}let o;if(n===`Luminosity`&&r){let[e,t,n]=Le(r),a=Math.round(.3*e+.59*t+.11*n);o=i?.[a]??a}else o=i?.[0]??0;let{width:s,height:c}=this.ctx.canvas,l=t.width*t.height,u=s*c<4*l,d=a?{url:n===`Alpha`?this.filterFactory.addAlphaFilter(i):this.filterFactory.addLuminosityFilter(i),subtype:n,transferMap:i}:null,f=n===`Luminosity`?r:null,p,m,h;u?(p=this._bakeSMaskCanvas(t,e.offsetX,e.offsetY,s,c,f,d),m=0,h=0):(p=this._bakeSMaskCanvas(t,0,0,t.width,t.height,f,d),m=e.offsetX,h=e.offsetY),this.smaskPreparedEntry=p,this.smaskPreparedFor=e,this.smaskPreparedOffsetX=m,this.smaskPreparedOffsetY=h,this.smaskPreparedOOBAlpha=!u&&o!==0?o:null}_bakeSMaskCanvas(e,t,n,r,i,a,o){!a&&!o&&F(`_bakeSMaskCanvas with neither backdrop nor filter`);let s=this.canvasFactory.create(r,i),c=s.context;if(c.drawImage(e,t,n),a&&(c.globalCompositeOperation=`destination-atop`,c.fillStyle=a,c.fillRect(0,0,r,i)),!o)return s;let l=this.canvasFactory.create(r,i),u=l.context;u.filter=o.url;let d=R.isCanvasFilterSupported&&u.filter!==`none`&&u.filter!==``;if(u.drawImage(s.canvas,0,0),R.isCanvasFilterSupported&&(u.filter=`none`),!d){let e=u.getImageData(0,0,r,i),{data:t}=e,{transferMap:n}=o;if(o.subtype===`Luminosity`)for(let e=0,r=t.length;e<r;e+=4){let r=.3*t[e]+.59*t[e+1]+.11*t[e+2]+.5|0;t[e]=t[e+1]=t[e+2]=0,t[e+3]=n?.[r]??r}else for(let e=3,r=t.length;e<r;e+=4)t[e]=n[t[e]];u.putImageData(e,0,0)}return this.canvasFactory.destroy(s),l}beginSMaskMode(e){if(this.inSMaskMode)throw Error(`beginSMaskMode called while already in smask mode`);let{width:t,height:n}=this.ctx.canvas,r=this.canvasFactory.create(t,n);this.smaskScratchCanvas=r,this.suspendedCtx=this.ctx;let i=this.ctx=r.context;i.setTransform(this.suspendedCtx.getTransform()),Vn(this.suspendedCtx,i),In(i,this.suspendedCtx),this._ensurePreparedSMask(this.current.activeSMask),this.setGState(e,[[`BM`,`source-over`]])}endSMaskMode(){if(!this.inSMaskMode)throw Error(`endSMaskMode called while not in smask mode`);this.ctx._removeMirroring(),Vn(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null,this.canvasFactory.destroy(this.smaskScratchCanvas),this.smaskScratchCanvas=null,this._clearPreparedSMask()}#f(e,t=null,n=1){let{width:r,height:i}=e,a=t??this.canvasFactory.create(r,i),o=a.context;n=Math.round(n*255)/255;let s=n<1;s&&this.#s===void 0&&(this.#s=R.isCanvasFilterSupported?new Map:`none`);let c=`none`;if(s&&this.#s instanceof Map&&(c=this.#s.getOrInsertComputed(n,()=>this.filterFactory.addKnockoutFilter(n))),!s||c!==`none`)return t&&(o.save(),o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,r,i),o.restore()),o.filter=c,o.drawImage(e,0,0),o.filter=`none`,a;let l=e.getContext(`2d`,{willReadFrequently:!0}).getImageData(0,0,r,i),u=o.createImageData(r,i),d=l.data,f=u.data,p=n>0?1/n:1e6;for(let e=3,t=d.length;e<t;e+=4)f[e]=Math.min(Math.round(d[e]*p),255);return o.putImageData(u,0,0),a}#p(e,t,n,r){let i=e?.[t]??null;if(i&&(i.canvas.width!==n||i.canvas.height!==r)&&(this.canvasFactory.destroy(i),i=null),!i)return i=this.canvasFactory.create(n,r),e&&(e[t]=i),i;let a=i.context;return a.save(),a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,n,r),a.restore(),i}#m(e,t,n={}){let{backdropCanvas:r=null,destTransform:i=[1,0,0,1,0,0],backdropOffset:a=[0,0],reuseMaskEntry:o=null,poolMeta:s=null,sourceAlpha:c=1,sourceFilter:l=`none`,knockoutAlpha:u=1}=n,{width:d,height:f}=t,p=this.#f(t,o,u),m=e.globalCompositeOperation;if(e.save(),e.setTransform(...i),e.globalAlpha=1,R.isCanvasFilterSupported&&(e.filter=`none`),e.globalCompositeOperation=`destination-out`,e.drawImage(p.canvas,0,0),r){let[t,n]=a,i=this.#p(s,`knockoutBackdropEntry`,d,f),o=i.context;o.drawImage(r,t,n,d,f,0,0,d,f),o.globalCompositeOperation=`destination-in`,o.drawImage(p.canvas,0,0),o.globalCompositeOperation=`source-over`,e.globalCompositeOperation=`destination-over`,e.drawImage(i.canvas,0,0),s||this.canvasFactory.destroy(i)}e.globalCompositeOperation=m,e.globalAlpha=c,R.isCanvasFilterSupported&&(e.filter=l??`none`),e.drawImage(t,0,0),e.restore(),o||this.canvasFactory.destroy(p)}#h(e=1){if(this.#e===0||this.#t>0||!this.contentVisible)return!1;this.#t++,this.#o=e;let t=this.#l.at(-1),{canvas:n}=this.ctx,r=this.#p(t,`knockoutTempEntry`,n.width,n.height);this.#n=r;let i=r.context;return i.save(),i.setTransform(this.ctx.getTransform()),Vn(this.ctx,i),this.#a=i.globalCompositeOperation,i.globalCompositeOperation=`source-over`,In(i,this.ctx),this.#c=t,this.#r=this.ctx,this.#i=this.suspendedCtx,this.ctx=i,this.inSMaskMode&&(this.suspendedCtx=i),!0}#g(e){if(!e)return;let t=this.#n,n=this.#r,r=this.#i,i=t.context;this.#n=null,this.#r=null,this.#i=null,this.inSMaskMode&&this.suspendedCtx===i&&this.ctx!==i&&this.endSMaskMode(),this.inSMaskMode&&(this.suspendedCtx=r),this.ctx._removeMirroring(),this.ctx.globalCompositeOperation=this.#a,this.#a=null,Vn(this.ctx,n),this.ctx=n;let a=this.#c;this.#c=null;let o=this.#o;this.#o=1;try{this.#m(r??n,t.canvas,{backdropCanvas:a?.backdropCtx?.canvas??null,backdropOffset:a?.backdropCtx?[a.offsetX,a.offsetY]:[0,0],reuseMaskEntry:a?.knockoutMaskEntry??null,poolMeta:a,knockoutAlpha:o})}finally{i.restore(),this.#t--,a||this.canvasFactory.destroy(t)}}compose(e){if(!this.current.activeSMask)return;e=e?[Math.floor(e[0]),Math.floor(e[1]),Math.ceil(e[2]),Math.ceil(e[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];let t=this.current.activeSMask,n=this.suspendedCtx,r=this.#t>0&&n===this.ctx;this.composeSMask(r?null:n,t,this.ctx,e),!r&&(this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore())}composeSMask(e,t,n,r){let i=r[0],a=r[1],o=r[2]-i,s=r[3]-a;if(o===0||s===0)return;let c=this.smaskPreparedEntry;if(c){let e=i,r=a,l=o,u=s,d=this.smaskPreparedOOBAlpha,f=d!==null;if(f){e=Math.max(i,t.offsetX),r=Math.max(a,t.offsetY);let n=Math.min(i+o,t.offsetX+t.canvas.width),c=Math.min(a+s,t.offsetY+t.canvas.height);l=n-e,u=c-r}if(l>0&&u>0){let t=e-this.smaskPreparedOffsetX,i=r-this.smaskPreparedOffsetY;n.save(),n.globalAlpha=1,n.setTransform(1,0,0,1,0,0);let a=new Path2D;a.rect(e,r,l,u),n.clip(a),n.globalCompositeOperation=`destination-in`,n.drawImage(c.canvas,t,i,l,u,e,r,l,u),n.restore()}f&&d<255&&this._applySMaskOOBAlpha(n,i,a,o,s,e,r,e+l,r+u,d)}else this.genericComposeSMask(t,n,o,s,i,a);e&&(e.save(),e.globalAlpha=1,e.globalCompositeOperation=t.blendMode||`source-over`,e.setTransform(1,0,0,1,0,0),e.drawImage(n.canvas,i,a,o,s,i,a,o,s),e.restore())}_applySMaskOOBAlpha(e,t,n,r,i,a,o,s,c,l){let u=a<s&&o<c;if(u&&a===t&&o===n&&s===t+r&&c===n+i)return;let d=new Path2D;d.rect(t,n,r,i),u&&d.rect(a,o,s-a,c-o),e.save(),e.globalAlpha=l/255,e.setTransform(1,0,0,1,0,0),e.clip(d,`evenodd`),e.globalCompositeOperation=`destination-in`,e.fillStyle=`#000000`,e.fillRect(t,n,r,i),e.restore()}genericComposeSMask(e,t,n,r,i,a){let{context:o,offsetX:s,offsetY:c}=e;t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);let l=new Path2D;l.rect(i,a,n,r),t.clip(l),t.globalCompositeOperation=`destination-in`,t.drawImage(o.canvas,i-s,a-c,n,r,i,a,n,r),t.restore()}save(e){this.inSMaskMode&&Vn(this.ctx,this.suspendedCtx),this.ctx.save();let t=this.current;this.stateStack.push(t),this.current=t.clone(),this.dependencyTracker?.save(e)}restore(e){if(this.dependencyTracker?.restore(e),this.stateStack.length===0){this.inSMaskMode&&this.endSMaskMode();return}this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&(Vn(this.suspendedCtx,this.ctx),this.ctx.setTransform(this.suspendedCtx.getTransform())),this.checkSMaskState(e),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}transform(e,t,n,r,i,a,o){this.dependencyTracker?.recordIncrementalData(`transform`,e),this.ctx.transform(t,n,r,i,a,o),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(e,t,n,r){let[i]=n;if(!r){i||=n[0]=new Path2D,t!==A.stroke&&t!==A.closeStroke&&(this.current.tilingPatternDims=null),this[t](e,i);return}if(this.dependencyTracker!==null){let n=t===A.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(e).recordBBox(e,this.ctx,r[0]-n,r[2]+n,r[1]-n,r[3]+n).recordDependencies(e,[`transform`])}i instanceof Path2D||(i=n[0]=et(i)),z.axialAlignedBoundingBox(r,W(this.ctx),this.current.minMax);let a=this.current.tilingPatternDims;if(a&&t!==A.stroke&&t!==A.closeStroke&&this.current.fillColor instanceof kn){let e=z.intersect(this.current.clipBox,this.current.minMax);e?this.current.fillColor.updatePatternDims(e,a):this.current.tilingPatternDims=null}this[t](e,i),this._pathStartIdx=e}closePath(e){this.ctx.closePath()}stroke(e,t,n=!0){let r=n&&this.#h(this.current.strokeAlpha),i=this.ctx,a=this.current.strokeColor;if(i.globalAlpha=this.current.strokeAlpha,this.contentVisible)if(typeof a==`object`&&a?.getPattern){let n=a.isModifyingCurrentTransform()?i.getTransform():null;if(i.save(),i.strokeStyle=a.getPattern(i,this,Be(i),Y.STROKE,e),n){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(n)),t=e}this.rescaleAndStroke(t,!1),i.restore()}else this.rescaleAndStroke(t,!0);this.dependencyTracker?.recordDependencies(e,Nt.stroke),n&&this.consumePath(e,t,this.current.getClippedPathBoundingBox(Y.STROKE,W(this.ctx))),i.globalAlpha=this.current.fillAlpha,this.#g(r)}closeStroke(e,t){this.stroke(e,t)}fill(e,t,n=!0){let r=n&&this.#h(this.current.fillAlpha),i=this.ctx,a=this.current.fillColor,o=this.current.patternFill,s=!1,c=this.current.getClippedPathBoundingBox();if(this.dependencyTracker?.recordDependencies(e,Nt.fill),o){let o=this.current.tilingPatternDims,l=o&&a.canSkipPatternCanvas(o);if(l){a.drawPattern(this,t,this.pendingEOFill,l,e),this.pendingEOFill=!1,n&&this.consumePath(e,t,c),this.current.tilingPatternDims=null,this.#g(r);return}let u=a.isModifyingCurrentTransform()?i.getTransform():null;if(this.dependencyTracker?.save(e),i.save(),i.fillStyle=a.getPattern(i,this,Be(i),Y.FILL,e),u){let e=new Path2D;e.addPath(t,i.getTransform().invertSelf().multiplySelf(u)),t=e}s=!0}this.contentVisible&&c!==null&&(this.pendingEOFill?(i.fill(t,`evenodd`),this.pendingEOFill=!1):i.fill(t)),s&&(i.restore(),this.dependencyTracker?.restore(e)),n&&this.consumePath(e,t,c),this.#g(r)}eoFill(e,t){this.pendingEOFill=!0,this.fill(e,t)}fillStroke(e,t){let n=this.#h(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(e,t,!1),this.stroke(e,t,!1),this.consumePath(e,t),this.#g(n)}eoFillStroke(e,t){this.pendingEOFill=!0,this.fillStroke(e,t)}closeFillStroke(e,t){this.fillStroke(e,t)}closeEOFillStroke(e,t){this.pendingEOFill=!0,this.fillStroke(e,t)}endPath(e,t){this.consumePath(e,t)}rawFillPath(e,t){let n=this.#h(this.current.fillAlpha);this.ctx.fill(t),this.dependencyTracker?.recordDependencies(e,Nt.rawFillPath).recordOperation(e),this.#g(n)}clip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e),this.pendingClip=Kn}eoClip(e){this.dependencyTracker?.recordFutureForcedDependency(`clipMode`,e),this.pendingClip=qn}beginText(e){this.current.textMatrix=null,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0,this.dependencyTracker?.recordOpenMarker(e).resetIncrementalData(`sameLineText`).resetIncrementalData(`moveText`,e)}endText(e){let t=this.pendingTextPaths,n=this.ctx;if(this.dependencyTracker){let{dependencyTracker:n}=this;t!==void 0&&n.recordFutureForcedDependency(`textClip`,n.getOpenMarker()).recordFutureForcedDependency(`textClip`,e),n.recordCloseMarker(e)}if(t!==void 0){let e=new Path2D,r=n.getTransform().invertSelf();for(let{transform:n,x:i,y:a,fontSize:o,path:s}of t)s&&e.addPath(s,new DOMMatrix(n).preMultiplySelf(r).translate(i,a).scale(o,-o));n.clip(e)}delete this.pendingTextPaths}setCharSpacing(e,t){this.dependencyTracker?.recordSimpleData(`charSpacing`,e),this.current.charSpacing=t}setWordSpacing(e,t){this.dependencyTracker?.recordSimpleData(`wordSpacing`,e),this.current.wordSpacing=t}setHScale(e,t){this.dependencyTracker?.recordSimpleData(`hScale`,e),this.current.textHScale=t/100}setLeading(e,t){this.dependencyTracker?.recordSimpleData(`leading`,e),this.current.leading=-t}setFont(e,t,n){this.dependencyTracker?.recordSimpleData(`font`,e).recordSimpleDataFromNamed(`fontObj`,t,e);let r=this.commonObjs.get(t),i=this.current;if(!r)throw Error(`Can't find font for ${t}`);if(i.fontMatrix=r.fontMatrix||h,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&P(`Invalid font matrix for font `+t),n<0?(n=-n,i.fontDirection=-1):i.fontDirection=1,this.current.font=r,this.current.fontSize=n,r.isType3Font)return;let a=r.loadedName||`sans-serif`,o=r.systemFontInfo?.css||`"${a}", ${r.fallbackName}`,s=`normal`;r.black?s=`900`:r.bold&&(s=`bold`);let c=r.italic?`italic`:`normal`,l=V(n,An,jn);this.current.fontSizeScale=n/l,this.ctx.font=`${c} ${s} ${l}px ${o}`}setTextRenderingMode(e,t){this.dependencyTracker?.recordSimpleData(`textRenderingMode`,e),this.current.textRenderingMode=t}setTextRise(e,t){this.dependencyTracker?.recordSimpleData(`textRise`,e),this.current.textRise=t}moveText(e,t,n){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordIncrementalData(`moveText`,e),this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=n}setLeadingMoveText(e,t,n){this.setLeading(e,-n),this.moveText(e,t,n)}setTextMatrix(e,t){this.dependencyTracker?.resetIncrementalData(`sameLineText`).recordSimpleData(`textMatrix`,e);let{current:n}=this;n.textMatrix=t,n.textMatrixScale=Math.hypot(t[0],t[1]),n.x=n.lineX=0,n.y=n.lineY=0}nextLine(e){this.moveText(e,0,this.current.leading),this.dependencyTracker?.recordIncrementalData(`moveText`,this.dependencyTracker.getSimpleIndex(`leading`)??e)}#_(e,t,n){let r=new Path2D;return r.addPath(e,new DOMMatrix(n).invertSelf().multiplySelf(t)),r}paintChar(e,t,n,r,i,a){let o=this.ctx,s=this.current,c=s.font,l=s.textRenderingMode,u=s.fontSize/s.fontSizeScale,d=l&T.FILL_STROKE_MASK,f=!!(l&T.ADD_TO_PATH_FLAG),p=s.patternFill&&!c.missingFile,m=s.patternStroke&&!c.missingFile,h;if((c.disableFontFace||f||p||m)&&!c.missingFile&&(h=c.getPathGenerator(this.commonObjs,t)),h&&(c.disableFontFace||p||m)){o.save(),o.translate(n,r),o.scale(u,-u),this.dependencyTracker?.recordCharacterBBox(e,o,c);let t;if(d===T.FILL||d===T.FILL_STROKE)if(i){t=o.getTransform(),o.setTransform(...i);let e=this.#_(h,t,i);o.fill(e)}else o.fill(h);if(d===T.STROKE||d===T.FILL_STROKE)if(a){t||=o.getTransform(),o.setTransform(...a);let{a:e,b:n,c:r,d:i}=t,s=z.inverseTransform(a),c=z.transform([e,n,r,i,0,0],s);z.singularValueDecompose2dScale(c,Fn),o.lineWidth*=Math.max(Fn[0],Fn[1])/u,o.stroke(this.#_(h,t,a))}else o.lineWidth/=u,o.stroke(h);o.restore()}else(d===T.FILL||d===T.FILL_STROKE)&&(o.fillText(t,n,r),this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t))),(d===T.STROKE||d===T.FILL_STROKE)&&(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r,()=>o.measureText(t)).recordDependencies(e,Nt.stroke),o.strokeText(t,n,r));f&&((this.pendingTextPaths||=[]).push({transform:W(o),x:n,y:r,fontSize:u,path:h}),this.dependencyTracker?.recordCharacterBBox(e,o,c,u,n,r))}get isFontSubpixelAAEnabled(){let e=this.canvasFactory.create(10,10),t=e.context;t.scale(1.5,1),t.fillText(`I`,0,10);let n=t.getImageData(0,0,10,10).data;this.canvasFactory.destroy(e);let r=!1;for(let e=3;e<n.length;e+=4)if(n[e]>0&&n[e]<255){r=!0;break}return L(this,`isFontSubpixelAAEnabled`,r)}showText(e,t){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(e,Nt.showText).resetBBox(e),this.current.textRenderingMode&T.ADD_TO_PATH_FLAG&&this.dependencyTracker.recordFutureForcedDependency(`textClip`,e).inheritPendingDependenciesAsFutureForcedDependencies());let n=this.current,r=n.font;if(r.isType3Font){let r=this.#h(n.fillAlpha);this.showType3Text(e,t),this.dependencyTracker?.recordShowTextOperation(e),this.#g(r);return}let i=n.fontSize;if(i===0){this.dependencyTracker?.recordOperation(e);return}let a=this.#h(n.fillAlpha),o=this.ctx,s=n.fontSizeScale,c=n.charSpacing,l=n.wordSpacing,u=n.fontDirection,d=n.textHScale*u,f=t.length,p=r.vertical,m=p?1:-1,h=r.defaultVMetrics,g=i*n.fontMatrix[0],_=n.textRenderingMode===T.FILL&&!r.disableFontFace&&!n.patternFill;o.save(),n.textMatrix&&o.transform(...n.textMatrix),o.translate(n.x,n.y+n.textRise),u>0?o.scale(d,-1):o.scale(d,1);let v,y,b=n.textRenderingMode&T.FILL_STROKE_MASK,x=b===T.FILL||b===T.FILL_STROKE,S=b===T.STROKE||b===T.FILL_STROKE,C=n.lineWidth,w=n.textMatrixScale;if(w===0||C===0?S&&(C=this.getSinglePixelWidth()):C/=w,s!==1&&(o.scale(s,s),C/=s),o.lineWidth=C,x&&n.patternFill){o.save();let t=n.fillColor.getPattern(o,this,Be(o),Y.FILL,e);v=W(o),o.restore(),o.fillStyle=t}if(S&&n.patternStroke){o.save();let t=n.strokeColor.getPattern(o,this,Be(o),Y.STROKE,e);y=W(o),o.restore(),o.strokeStyle=t}if(r.isInvalidPDFjsFont){let r=[],i=0;for(let e of t)r.push(e.unicode),i+=e.width;let s=r.join(``);if(o.fillText(s,0,0),this.dependencyTracker!==null){let t=o.measureText(s);this.dependencyTracker.recordBBox(e,this.ctx,-t.actualBoundingBoxLeft,t.actualBoundingBoxRight,-t.actualBoundingBoxAscent,t.actualBoundingBoxDescent).recordShowTextOperation(e)}n.x+=i*g*d,o.restore(),this.compose(),this.#g(a);return}let E=0,D;for(D=0;D<f;++D){let n=t[D];if(typeof n==`number`){E+=m*n*i/1e3;continue}let a=!1,d=(n.isSpace?l:0)+c,f=n.fontChar,b=n.accent,x,S,C=n.width;if(p){let e=n.vmetric||h,t=-(n.vmetric?e[1]:C*.5)*g,r=e[2]*g;C=e?-e[0]:C,x=t/s,S=(E+r)/s}else x=E/s,S=0;let w;if(r.remeasure&&C>0){w=o.measureText(f);let e=w.width*1e3/i*s;if(C<e&&this.isFontSubpixelAAEnabled){let t=C/e;a=!0,o.save(),o.scale(t,1),x/=t}else C!==e&&(x+=(C-e)/2e3*i/s)}if(this.contentVisible&&(n.isInFont||r.missingFile)){if(_&&!b)o.fillText(f,x,S),this.dependencyTracker?.recordCharacterBBox(e,o,w?{bbox:null}:r,i/s,x,S,()=>w??o.measureText(f));else if(this.paintChar(e,f,x,S,v,y),b){let t=x+i*b.offset.x/s,n=S-i*b.offset.y/s;this.paintChar(e,b.fontChar,t,n,v,y)}}let T=p?C*g-d*u:C*g+d*u;E+=T,a&&o.restore()}p?n.y-=E:n.x+=E*d,o.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(e),this.#g(a)}showType3Text(e,t){let n=this.ctx,r=this.current,i=r.font,a=r.fontSize,o=r.fontDirection,s=i.vertical?1:-1,c=r.charSpacing,l=r.wordSpacing,u=r.textHScale*o,d=r.fontMatrix||h,f=t.length,p=r.textRenderingMode===T.INVISIBLE,m,g,_,v;if(p||a===0)return;this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,n.save(),r.textMatrix&&n.transform(...r.textMatrix),n.translate(r.x,r.y+r.textRise),n.scale(u,o);let y=this.dependencyTracker;for(this.dependencyTracker=y?new Mt(y,e):null,m=0;m<f;++m){if(g=t[m],typeof g==`number`){v=s*g*a/1e3,this.ctx.translate(v,0),r.x+=v*u;continue}let e=(g.isSpace?l:0)+c,o=i.charProcOperatorList[g.operatorListId];o?this.contentVisible&&(this.save(),o.fnArray[0]===A.setCharWidth&&(r.fillAlpha=r.strokeAlpha=1,n.globalAlpha=1),n.scale(a,a),n.transform(...d),this.executeOperatorList(o),this.restore()):P(`Type3 character "${g.operatorListId}" is not available.`);let f=[g.width,0];z.applyTransform(f,d),_=f[0]*a+e,n.translate(_,0),r.x+=_*u}n.restore(),y&&(this.dependencyTracker=y)}setCharWidth(e,t,n){}setCharWidthAndBounds(e,t,n,r,i,a,o){let s=new Path2D;s.rect(r,i,a-r,o-i),this.ctx.clip(s),this.dependencyTracker?.recordBBox(e,this.ctx,r,a,i,o).recordClipBox(e,this.ctx,r,a,i,o),this.endPath(e)}getColorN_Pattern(t,n){let r;if(n[0]===`TilingPattern`){let t=this.baseTransform||W(this.ctx);r=new kn(n,this.ctx,{createCanvasGraphics:(t,n)=>new e(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new Mt(this.dependencyTracker,n,!0):null)},t)}else r=this._getPattern(t,n[1],n[2]);return r}setStrokeColorN(e,...t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.current.strokeColor=this.getColorN_Pattern(e,t),this.current.patternStroke=!0}setFillColorN(e,...t){this.dependencyTracker?.recordSimpleData(`fillColor`,e);let n=this.current.fillColor=this.getColorN_Pattern(e,t);this.current.patternFill=!0,this.current.tilingPatternDims=n instanceof kn?[0,0,0,0]:null}setStrokeRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.ctx.strokeStyle=this.current.strokeColor=t,this.current.patternStroke=!1}setStrokeTransparent(e){this.dependencyTracker?.recordSimpleData(`strokeColor`,e),this.ctx.strokeStyle=this.current.strokeColor=`transparent`,this.current.patternStroke=!1}setFillRGBColor(e,t){this.dependencyTracker?.recordSimpleData(`fillColor`,e),this.ctx.fillStyle=this.current.fillColor=t,this.current.patternFill=!1,this.current.tilingPatternDims=null}setFillTransparent(e){this.dependencyTracker?.recordSimpleData(`fillColor`,e),this.ctx.fillStyle=this.current.fillColor=`transparent`,this.current.patternFill=!1,this.current.tilingPatternDims=null}_getPattern(e,t,n=null){let r;return this.cachedPatterns.has(t)?r=this.cachedPatterns.get(t):(r=Dn(this.getObject(e,t)),this.cachedPatterns.set(t,r)),n&&(r.matrix=n),r}shadingFill(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx;this.save(e),r.fillStyle=this._getPattern(e,t).getPattern(r,this,Be(r),Y.SHADING,e);let i=Be(r);if(i){let{width:e,height:t}=r.canvas,n=m.slice();z.axialAlignedBoundingBox([0,0,e,t],i,n);let[a,o,s,c]=n;this.ctx.fillRect(a,o,s-a,c-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(e).recordFullPageBBox(e).recordDependencies(e,Nt.transform).recordDependencies(e,Nt.fill).recordOperation(e),this.compose(this.current.getClippedPathBoundingBox()),this.restore(e),this.#g(n)}beginInlineImage(){F(`Should not call beginInlineImage`)}beginImageData(){F(`Should not call beginImageData`)}paintFormXObjectBegin(e,t,n){if(this.contentVisible&&(this.save(e),this.baseTransformStack.push(this.baseTransform),t&&this.transform(e,...t),this.baseTransform=W(this.ctx),n)){z.axialAlignedBoundingBox(n,this.baseTransform,this.current.minMax);let[t,r,i,a]=n,o=new Path2D;o.rect(t,r,i-t,a-r),this.ctx.clip(o),this.dependencyTracker?.recordClipBox(e,this.ctx,t,i,r,a),this.endPath(e)}}paintFormXObjectEnd(e){this.contentVisible&&(this.restore(e),this.baseTransform=this.baseTransformStack.pop())}beginGroup(e,t){if(!this.contentVisible)return;this.save(e);let{inSMaskMode:n}=this;n&&(this.endSMaskMode(),this.current.activeSMask=null);let r=this.ctx;if((!t.needsIsolation||!t.isolated&&!t.hasSoftMask)&&!t.knockout&&!t.isGray&&this.#e===0&&r.globalAlpha===1&&r.globalCompositeOperation===`source-over`&&!n){if(t.bbox){let e=new Path2D,[n,i,a,o]=t.bbox;if(e.rect(n,i,a-n,o-i),t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix)),e=n}r.clip(e)}this.groupStack.push(null),this.#l.push(null),this.groupLevel++;return}!t.isolated&&!t.knockout&&this.#e===0&&ne(`TODO: Fully support non-isolated non-knockout groups.`);let i=W(r);t.matrix&&r.transform(...t.matrix);let a=[0,0,r.canvas.width,r.canvas.height],o;t.bbox?(o=m.slice(),z.axialAlignedBoundingBox(t.bbox,W(r),o),o=z.intersect(o,a)||[0,0,0,0]):o=a;let s=Math.floor(o[0]),c=Math.floor(o[1]),l=Math.max(Math.ceil(o[2])-s,1),u=Math.max(Math.ceil(o[3])-c,1);this.current.startNewPathAndClipBox([0,0,l,u]);let d=this.canvasFactory.create(l,u);t.smask&&this.smaskGroupCanvases.push(d);let f=d.context,p=t.knockout&&!t.isolated?r:null,h=!t.isolated&&!t.knockout&&!t.smask&&t.needsIsolation&&this.#e>0,g=t.knockout?this.canvasFactory.create(l,u):null,_=this.#e;if(t.knockout?this.#e++:this.#e=0,f.translate(-s,-c),f.transform(...i),!t.isolated&&!t.smask&&n&&t.needsIsolation&&(f.save(),f.setTransform(1,0,0,1,0,0),f.drawImage(r.canvas,-s,-c),f.restore()),t.bbox){let e=new Path2D,[n,r,i,a]=t.bbox;if(e.rect(n,r,i-n,a-r),t.matrix){let n=new Path2D;n.addPath(e,new DOMMatrix(t.matrix)),e=n}f.clip(e)}t.smask&&this.smaskStack.push({canvas:d.canvas,context:f,offsetX:s,offsetY:c,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null}),(!t.smask||this.dependencyTracker)&&(r.setTransform(1,0,0,1,0,0),r.translate(s,c),r.save()),Vn(r,f),this.ctx=f,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies([`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`]).pushBaseTransform(r),this.setGState(e,[[`BM`,`source-over`],[`ca`,1],[`CA`,1],[`TR`,null]]),this.groupStack.push(r),this.#l.push({backdropCtx:p,savedKnockoutLevel:_,offsetX:s,offsetY:c,hasInnerBackdrop:h,knockoutMaskEntry:g,knockoutTempEntry:null,knockoutBackdropEntry:null}),this.groupLevel++}endGroup(e,t){if(!this.contentVisible)return;this.groupLevel--;let n=this.ctx,r=this.groupStack.pop(),i=this.#l.pop();if(i&&(this.#e=i.savedKnockoutLevel),r===null){this.restore(e);return}if(t.isGray&&this.#v(n),this.ctx=r,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),t.smask)this.tempSMask=this.smaskStack.pop(),this.restore(e),this.dependencyTracker&&(this.ctx.restore(),this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())),this.#y(i);else{this.ctx.restore();let t=W(this.ctx);this.restore(e),this.ctx.save(),this.ctx.setTransform(...t);let a=m.slice();z.axialAlignedBoundingBox([0,0,n.canvas.width,n.canvas.height],t,a);let o=this.#l.at(-1);if(this.#e>0)if(i.hasInnerBackdrop){let{width:e,height:a}=n.canvas,o=this.canvasFactory.create(e,a),s=o.context;s.drawImage(r.canvas,i.offsetX,i.offsetY,e,a,0,0,e,a),s.globalCompositeOperation=`source-over`,s.drawImage(n.canvas,0,0);let c=this.#f(n.canvas);s.globalCompositeOperation=`destination-in`,s.drawImage(c.canvas,0,0);let l=this.ctx.globalCompositeOperation,u=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save(),this.ctx.setTransform(...t),this.ctx.globalAlpha=1,R.isCanvasFilterSupported&&(this.ctx.filter=`none`),this.ctx.globalCompositeOperation=`destination-out`,this.ctx.drawImage(c.canvas,0,0),this.ctx.globalCompositeOperation=l,this.ctx.globalAlpha=u,R.isCanvasFilterSupported&&(this.ctx.filter=d??`none`),this.ctx.drawImage(o.canvas,0,0),this.ctx.restore(),this.canvasFactory.destroy(c),this.canvasFactory.destroy(o)}else{let e=o?.backdropCtx??null;this.#m(this.ctx,n.canvas,{backdropCanvas:e?.canvas??null,destTransform:t,backdropOffset:e?[o.offsetX+i.offsetX,o.offsetY+i.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}else this.ctx.drawImage(n.canvas,0,0);this.ctx.restore(),this.canvasFactory.destroy({canvas:n.canvas,context:n}),this.#y(i),this.compose(a)}}#v(e){let{canvas:t}=e,{width:n,height:r}=t;if(R.isCanvasFilterSupported){e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`grayscale(1)`,e.globalAlpha=1,e.globalCompositeOperation=`copy`,e.drawImage(t,0,0),e.restore();return}let i=e.getImageData(0,0,n,r),{data:a}=i;for(let e=0,t=a.length;e<t;e+=4){let t=a[e]*.2126+a[e+1]*.7152+a[e+2]*.0722+.5|0;a[e]=a[e+1]=a[e+2]=t}e.putImageData(i,0,0)}#y(e){e&&(e.knockoutMaskEntry&&=(this.canvasFactory.destroy(e.knockoutMaskEntry),null),e.knockoutTempEntry&&=(this.canvasFactory.destroy(e.knockoutTempEntry),null),e.knockoutBackdropEntry&&=(this.canvasFactory.destroy(e.knockoutBackdropEntry),null))}beginAnnotation(e,t,n,r,i,a,o){if(this.#u(),Hn(this.ctx),this.ctx.save(),this.save(e),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),n){let i=n[2]-n[0],s=n[3]-n[1];if(a&&this.annotationCanvasMap){r=r.slice(),r[4]-=n[0],r[5]-=n[1],n=n.slice(),n[0]=n[1]=0,n[2]=i,n[3]=s,z.singularValueDecompose2dScale(W(this.ctx),Fn);let{viewportScale:e}=this,a=Math.ceil(i*this.outputScaleX*e),c=Math.ceil(s*this.outputScaleY*e);this.annotationCanvas=this.canvasFactory.create(a,c);let{canvas:l,context:u}=this.annotationCanvas;if(o){let e=this.annotationCanvasMap.getOrInsertComputed(t,xe);l.setAttribute(`data-canvas-name`,o);let n=e.findIndex(e=>e.getAttribute(`data-canvas-name`)===o);n===-1?e.push(l):e[n]=l}else this.annotationCanvasMap.set(t,l);this.annotationCanvas.savedCtx=this.ctx,this.ctx=u,this.ctx.save(),this.ctx.setTransform(Fn[0],0,0,-Fn[1],0,s*Fn[1]),Hn(this.ctx)}else{Hn(this.ctx),this.endPath(e);let t=new Path2D;t.rect(n[0],n[1],i,s),this.ctx.clip(t)}}this.current=new Rn(this.ctx.canvas.width,this.ctx.canvas.height),this.baseTransformStack.push(this.baseTransform),this.transform(e,...r),this.transform(e,...i),this.baseTransform=W(this.ctx)}endAnnotation(e){this.annotationCanvas&&(this.ctx.restore(),this.#d(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas),this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(e,t){if(!this.contentVisible)return;let n=t.count;t=this.getObject(e,t.data,t),t.count=n;let r=this.#h(this.current.fillAlpha),i=this.ctx,a=this._createMaskCanvas(e,t),o=a.canvas;i.save(),i.setTransform(1,0,0,1,0,0),i.drawImage(o,a.offsetX,a.offsetY),this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,a.offsetX,a.offsetX+o.width,a.offsetY,a.offsetY+o.height).recordOperation(e),i.restore(),a.canvasEntry&&this.canvasFactory.destroy(a.canvasEntry),this.compose(),this.#g(r)}paintImageMaskXObjectRepeat(e,t,n,r=0,i=0,a,o){if(!this.contentVisible)return;t=this.getObject(e,t.data,t);let s=this.#h(this.current.fillAlpha),c=this.ctx;c.save();let l=W(c);c.transform(n,r,i,a,0,0);let u=this._createMaskCanvas(e,t);c.setTransform(1,0,0,1,u.offsetX-l[4],u.offsetY-l[5]),this.dependencyTracker?.resetBBox(e);for(let t=0,s=o.length;t<s;t+=2){let s=z.transform(l,[n,r,i,a,o[t],o[t+1]]);c.drawImage(u.canvas,s[4],s[5]),this.dependencyTracker?.recordBBox(e,this.ctx,s[4],s[4]+u.canvas.width,s[5],s[5]+u.canvas.height)}c.restore(),u.canvasEntry&&this.canvasFactory.destroy(u.canvasEntry),this.compose(),this.dependencyTracker?.recordOperation(e),this.#g(s)}paintImageMaskXObjectGroup(e,t){if(!this.contentVisible)return;let n=this.#h(this.current.fillAlpha),r=this.ctx,i=this.current.fillColor,a=this.current.patternFill;this.dependencyTracker?.resetBBox(e).recordDependencies(e,Nt.transformAndFill);for(let n of t){let{data:t,width:o,height:s,transform:c}=n,l=this.canvasFactory.create(o,s),u=l.context;u.save(),Bn(u,this.getObject(e,t,n)),u.globalCompositeOperation=`source-in`,u.fillStyle=a?i.getPattern(u,this,Be(r),Y.FILL,e):i,u.fillRect(0,0,o,s),u.restore(),r.save(),r.transform(...c),r.scale(1,-1),Ln(r,l.canvas,0,0,o,s,0,-1,1,1),this.canvasFactory.destroy(l),this.dependencyTracker?.recordBBox(e,r,0,o,0,s),r.restore()}this.compose(),this.dependencyTracker?.recordOperation(e),this.#g(n)}paintImageXObject(e,t){if(!this.contentVisible)return;let n=this.getObject(e,t);if(!n){P(`Dependent image isn't ready yet`);return}this.paintInlineImageXObject(e,n)}paintImageXObjectRepeat(e,t,n,r,i){if(!this.contentVisible)return;let a=this.getObject(e,t);if(!a){P(`Dependent image isn't ready yet`);return}let o=a.width,s=a.height,c=[];for(let e=0,t=i.length;e<t;e+=2)c.push({transform:[n,0,0,r,i[e],i[e+1]],x:0,y:0,w:o,h:s});this.paintInlineImageXObjectGroup(e,a,c)}applyTransferMapsToCanvas(e){return this.current.transferMaps!==`none`&&(e.filter=this.current.transferMaps,e.drawImage(e.canvas,0,0),e.filter=`none`),e.canvas}applyTransferMapsToBitmap(e){if(this.current.transferMaps===`none`)return{img:e.bitmap,canvasEntry:null};let{bitmap:t,width:n,height:r}=e,i=this.canvasFactory.create(n,r),a=i.context;return a.filter=this.current.transferMaps,a.drawImage(t,0,0),a.filter=`none`,{img:i.canvas,canvasEntry:i}}paintInlineImageXObject(e,t){if(!this.contentVisible)return;let n=t.width,r=t.height,i=this.#h(this.current.fillAlpha),a=this.ctx;this.save(e);let{filter:o}=a;o!==`none`&&o!==``&&(a.filter=`none`),a.scale(1/n,-1/r);let s,c=null;if(t.bitmap){let e=this.applyTransferMapsToBitmap(t);s=e.img,c=e.canvasEntry}else{let e=this.canvasFactory.create(n,r);zn(e.context,t),s=this.applyTransferMapsToCanvas(e.context),c=e}let l=this._scaleImage(s,Be(a));a.imageSmoothingEnabled=Un(W(a),t.interpolate),this.dependencyTracker&&(this.dependencyTracker.resetBBox(e).recordBBox(e,a,0,n,-r,0).recordDependencies(e,Nt.imageXObject).recordOperation(e),this.imagesTracker?.record(a,n,r,this.dependencyTracker.clipBox)),Ln(a,l.img,0,0,l.paintWidth,l.paintHeight,0,-r,n,r),l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas),c&&this.canvasFactory.destroy(c),this.compose(),this.restore(e),this.#g(i)}paintInlineImageXObjectGroup(e,t,n){if(!this.contentVisible)return;let r=this.#h(this.current.fillAlpha),i=this.ctx,a,o=null;if(t.bitmap)a=t.bitmap;else{let e=t.width,n=t.height,r=this.canvasFactory.create(e,n);zn(r.context,t),a=this.applyTransferMapsToCanvas(r.context),o=r}this.dependencyTracker?.resetBBox(e);for(let t of n)i.save(),i.transform(...t.transform),i.scale(1,-1),Ln(i,a,t.x,t.y,t.w,t.h,0,-1,1,1),this.dependencyTracker?.recordBBox(e,i,0,1,-1,0),i.restore();o&&this.canvasFactory.destroy(o),this.dependencyTracker?.recordOperation(e),this.compose(),this.#g(r)}paintSolidColorImageMask(e){if(!this.contentVisible)return;let t=this.#h(this.current.fillAlpha);this.dependencyTracker?.resetBBox(e).recordBBox(e,this.ctx,0,1,0,1).recordDependencies(e,Nt.fill).recordOperation(e),this.ctx.fillRect(0,0,1,1),this.compose(),this.#g(t)}markPoint(e,t){}markPointProps(e,t,n){}beginMarkedContent(e,t){this.dependencyTracker?.beginMarkedContent(e),this.markedContentStack.push({visible:!0})}beginMarkedContentProps(e,t,n){this.dependencyTracker?.beginMarkedContent(e),t===`OC`?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(n)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(e){this.dependencyTracker?.endMarkedContent(e),this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(e){}endCompat(e){}consumePath(e,t,n){let r=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(n);let i=this.ctx;this.pendingClip?(r||(this.pendingClip===qn?i.clip(t,`evenodd`):i.clip(t)),this.pendingClip=null,this.dependencyTracker?.bboxToClipBoxDropOperation(e).recordFutureForcedDependency(`clipPath`,e)):this.dependencyTracker?.recordOperation(e),this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let e=W(this.ctx);if(e[1]===0&&e[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(e[0]),Math.abs(e[3]));else{let t=Math.abs(e[0]*e[3]-e[2]*e[1]),n=Math.hypot(e[0],e[2]),r=Math.hypot(e[1],e[3]);this._cachedGetSinglePixelWidth=Math.max(n,r)/t}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){let{lineWidth:e}=this.current,{a:t,b:n,c:r,d:i}=this.ctx.getTransform(),a,o;if(n===0&&r===0){let n=Math.abs(t),r=Math.abs(i);if(n===r)if(e===0)a=o=1/n;else{let t=n*e;a=o=t<1?1/t:1}else if(e===0)a=1/n,o=1/r;else{let t=n*e,i=r*e;a=t<1?1/t:1,o=i<1?1/i:1}}else{let s=Math.abs(t*i-n*r),c=Math.hypot(t,n),l=Math.hypot(r,i);if(e===0)a=l/s,o=c/s;else{let t=e*s;a=l>t?l/t:1,o=c>t?c/t:1}}this._cachedScaleForStroking[0]=a,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(e,t){let{ctx:n,current:{lineWidth:r}}=this,[i,a]=this.getScaleForStroking();if(i===a){n.lineWidth=(r||1)*i,n.stroke(e);return}let o=n.getLineDash();t&&n.save(),n.scale(i,a),Pn.a=1/i,Pn.d=1/a;let s=new Path2D;if(s.addPath(e,Pn),o.length>0){let e=Math.max(i,a);n.setLineDash(o.map(t=>t/e)),n.lineDashOffset/=e}n.lineWidth=r||1,n.stroke(s),t&&n.restore()}isContentVisible(){for(let e=this.markedContentStack.length-1;e>=0;e--)if(!this.markedContentStack[e].visible)return!1;return!0}};for(let e in A)Jn.prototype[e]!==void 0&&(Jn.prototype[A[e]]=Jn.prototype[e]);var Yn=class{#e=null;#t=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(e,t,n){this._source=e,this.#e=t,this.#t=n}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){return I(!this._fullReader,`BasePDFStream.getFullReader can only be called once.`),this._fullReader=new this.#e(this)}getRangeReader(e,t){if(t<=this._progressiveDataLength)return null;let n=new this.#t(this,e,t);return this._rangeReaders.add(n),n}cancelAllRequests(e){this._fullReader?.cancel(e);for(let t of new Set(this._rangeReaders))t.cancel(e)}},Xn=class{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(e){this._stream=e}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){F("Abstract method `read` called")}cancel(e){F("Abstract method `cancel` called")}},Zn=class{_stream=null;constructor(e,t,n){this._stream=e}async read(){F("Abstract method `read` called")}cancel(e){F("Abstract method `cancel` called")}};function Qn(e){let t=!0,n=r(`filename\\*`,`i`).exec(e);if(n){n=n[1];let e=s(n);return e=unescape(e),e=c(e),e=l(e),a(e)}if(n=o(e),n)return a(l(n));if(n=r(`filename`,`i`).exec(e),n){n=n[1];let e=s(n);return e=l(e),a(e)}function r(e,t){return RegExp(`(?:^|;)\\s*`+e+`\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)`,t)}function i(e,n){if(e){if(!/^[\x00-\xFF]+$/.test(n))return n;try{let r=new TextDecoder(e,{fatal:!0}),i=he(n);n=r.decode(i),t=!1}catch{}}return n}function a(e){return t&&/[\x80-\xff]/.test(e)&&(e=i(`utf-8`,e),t&&(e=i(`iso-8859-1`,e))),e}function o(e){let t=[],n,i=r(`filename\\*((?!0\\d)\\d+)(\\*?)`,`ig`);for(;(n=i.exec(e))!==null;){let[,e,r,i]=n;if(e=parseInt(e,10),e in t){if(e===0)break;continue}t[e]=[r,i]}let a=[];for(let e=0;e<t.length&&e in t;++e){let[n,r]=t[e];r=s(r),n&&(r=unescape(r),e===0&&(r=c(r))),a.push(r)}return a.join(``)}function s(e){if(e.startsWith(`"`)){let t=e.slice(1).split(`\\"`);for(let e=0;e<t.length;++e){let n=t[e].indexOf(`"`);n!==-1&&(t[e]=t[e].slice(0,n),t.length=e+1),t[e]=t[e].replaceAll(/\\(.)/g,`$1`)}e=t.join(`"`)}return e}function c(e){let t=e.indexOf(`'`);return t===-1?e:i(e.slice(0,t),e.slice(t+1).replace(/^[^']*'/,``))}function l(e){return!e.startsWith(`=?`)||/[\x00-\x19\x80-\xff]/.test(e)?e:e.replaceAll(/=\?([\w-]*)\?([QB])\?((?:[^?]|\?(?!=))*)\?=/gi,function(e,t,n,r){if(n===`q`||n===`Q`)return r=r.replaceAll(`_`,` `),r=r.replaceAll(/=([0-9a-f]{2})/gi,function(e,t){return String.fromCharCode(parseInt(t,16))}),i(t,r);try{r=atob(r)}catch{}return i(t,r)})}return``}function $n(e,t){let n=new Headers;if(!e||!t||typeof t!=`object`)return n;for(let e in t){let r=t[e];r!==void 0&&n.append(e,r)}return n}function er(e){return URL.parse(e)?.origin??null}function tr({responseHeaders:e,isHttp:t,rangeChunkSize:n,disableRange:r}){let i={contentLength:0,isRangeSupported:!1},a=parseInt(e.get(`Content-Length`),10);return!Number.isInteger(a)||(i.contentLength=a,a<=2*n)||r||!t||e.get(`Accept-Ranges`)!==`bytes`||(e.get(`Content-Encoding`)||`identity`)===`identity`&&(i.isRangeSupported=!0),i}function nr(e){let t=e.get(`Content-Disposition`);if(t){let e=Qn(t);if(e.includes(`%`))try{e=decodeURIComponent(e)}catch{}if(je(e))return e}return null}function rr(e,t){return new de(`Unexpected server response (${e}) while retrieving PDF "${t.href}".`,e,e===404||e===0&&t.protocol===`file:`)}function ir(e,t){if(e!==t)throw Error(`Expected range response-origin "${e}" to match "${t}".`)}function ar(e,t,n,r){return fetch(e,{method:`GET`,headers:t,signal:r.signal,mode:`cors`,credentials:n?`include`:`same-origin`,redirect:`follow`})}function or(e,t){if(e!==200&&e!==206)throw rr(e,t)}function sr(e){if(e instanceof Uint8Array)return e.buffer;if(e instanceof ArrayBuffer)return e;throw Error(`getArrayBuffer - unexpected data: ${e}`)}var cr=class extends Yn{_responseOrigin=null;constructor(e){super(e,lr,ur);let{httpHeaders:t,url:n}=e;I(/https?:/.test(n.protocol),`PDFFetchStream only supports http(s):// URLs.`),this.headers=$n(!0,t)}},lr=class extends Xn{_abortController=new AbortController;_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i,withCredentials:a}=e._source;this._isStreamingSupported=!n,ar(i,new Headers(e.headers),a,this._abortController).then(n=>{e._responseOrigin=er(n.url),or(n.status,i),this._reader=n.body.getReader();let a=n.headers,{contentLength:o,isRangeSupported:s}=tr({responseHeaders:a,isHttp:!0,rangeChunkSize:r,disableRange:t});this._contentLength=o,this._isRangeSupported=s,this._filename=nr(a),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new pe(`Streaming is disabled.`)),this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:(this._loaded+=e.byteLength,this._callOnProgress(),{value:sr(e),done:!1})}cancel(e){this._reader?.cancel(e),this._abortController.abort()}},ur=class extends Zn{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r,withCredentials:i}=e._source,a=new Headers(e.headers);a.append(`Range`,`bytes=${t}-${n-1}`),ar(r,a,i,this._abortController).then(t=>{ir(er(t.url),e._responseOrigin),or(t.status,r),this._reader=t.body.getReader(),this._readCapability.resolve()}).catch(this._readCapability.reject)}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:sr(e),done:!1}}cancel(e){this._reader?.cancel(e),this._abortController.abort()}};function dr(e){return e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}function fr(){for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}var pr=class extends Yn{_progressiveDone=!1;_queuedChunks=[];constructor(e){super(e,mr,hr);let{pdfDataRangeTransport:t}=e,{initialData:n,progressiveDone:r}=t;if(n?.length>0){let e=dr(n);this._queuedChunks.push(e)}this._progressiveDone=r,t.transportReady(e=>{switch(e.type){case`range`:case`progressiveRead`:this.#e(e.begin,e.chunk);break;case`progressiveDone`:this._fullReader?.progressiveDone(),this._progressiveDone=!0;break}})}#e(e,t){let n=dr(t);if(e===void 0)this._fullReader?this._fullReader._enqueue(n):this._queuedChunks.push(n);else{let t=this._rangeReaders.keys().find(t=>t._begin===e);I(t,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found."),t._enqueue(n)}}getFullReader(){let e=super.getFullReader();return this._queuedChunks=null,e}getRangeReader(e,t){let n=super.getRangeReader(e,t);return n&&(n.onDone=()=>this._rangeReaders.delete(n),this._source.pdfDataRangeTransport.requestDataRange(e,t)),n}cancelAllRequests(e){super.cancelAllRequests(e),this._source.pdfDataRangeTransport.abort()}},mr=class extends Xn{#e=fr.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(e){super(e);let{pdfDataRangeTransport:t,disableRange:n,disableStream:r}=e._source,{length:i,contentDispositionFilename:a}=t;this._queuedChunks=e._queuedChunks||[];for(let e of this._queuedChunks)this._loaded+=e.byteLength;this._done=e._progressiveDone,this._contentLength=i,this._isStreamingSupported=!r,this._isRangeSupported=!n,je(a)&&(this._filename=a),this._headersCapability.resolve();let o=this._loaded;Promise.resolve().then(()=>{o>0&&this._loaded===o&&this._callOnProgress()})}_enqueue(e){this._done||(this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunks.push(e),this._loaded+=e.byteLength,this._callOnProgress())}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e()}progressiveDone(){this._done||=!0,this._queuedChunks.length===0&&this.#e()}},hr=class extends Zn{#e=fr.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(e,t,n){super(e,t,n),this._begin=t}_enqueue(e){this._done||(this._requests.length===0?this._queuedChunk=e:(this._requests.shift().resolve({value:e,done:!1}),this.#e()),this._done=!0,this.onDone?.())}async read(){if(this._queuedChunk){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e(),this.onDone?.()}},gr=200,_r=206;function vr(e){return typeof e==`string`?he(e).buffer:e}var yr=class extends Yn{#e=new WeakMap;_responseOrigin=null;constructor(e){super(e,br,xr);let{httpHeaders:t,url:n}=e;this.url=n,this.isHttp=/https?:/.test(n.protocol),this.headers=$n(this.isHttp,t)}_request(e){let t=new XMLHttpRequest,n={validateStatus:null,onHeadersReceived:e.onHeadersReceived,onDone:e.onDone,onError:e.onError,onProgress:e.onProgress};this.#e.set(t,n),t.open(`GET`,this.url),t.withCredentials=this._source.withCredentials;for(let[e,n]of this.headers)t.setRequestHeader(e,n);return this.isHttp&&`begin`in e&&`end`in e?(t.setRequestHeader(`Range`,`bytes=${e.begin}-${e.end-1}`),n.validateStatus=e=>e===_r||e===gr):n.validateStatus=e=>e===gr,t.responseType=`arraybuffer`,I(e.onError,"Expected `onError` callback to be provided."),t.onerror=()=>e.onError(t.status),t.onreadystatechange=this.#n.bind(this,t),t.onprogress=this.#t.bind(this,t),t.send(null),t}#t(e,t){this.#e.get(e)?.onProgress?.(t)}#n(e,t){let n=this.#e.get(e);if(!n||(e.readyState>=2&&n.onHeadersReceived&&(n.onHeadersReceived(),delete n.onHeadersReceived),e.readyState!==4)||!this.#e.has(e))return;if(this.#e.delete(e),e.status===0&&this.isHttp){n.onError(e.status);return}let r=e.status||gr;if(!n.validateStatus(r)){n.onError(e.status);return}let i=vr(e.response);if(r===_r){let t=e.getResponseHeader(`Content-Range`);/bytes \d+-\d+\/\d+/.test(t)?n.onDone(i):(P(`Missing or invalid "Content-Range" header.`),n.onError(0))}else i?n.onDone(i):n.onError(e.status)}_abortRequest(e){this.#e.has(e)&&(this.#e.delete(e),e.abort())}getRangeReader(e,t){let n=super.getRangeReader(e,t);return n&&(n.onClosed=()=>this._rangeReaders.delete(n)),n}},br=class extends Xn{#e=fr.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(e){super(e),this._fullRequestXhr=e._request({onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:this.#i.bind(this)})}#t(){let e=this._stream,{disableRange:t,rangeChunkSize:n}=e._source,r=this._fullRequestXhr;e._responseOrigin=er(r.responseURL);let i=r.getAllResponseHeaders(),a=new Headers(i?i.trimStart().replace(/[^\S ]+$/,``).split(/[\r\n]+/).map(e=>{let[t,...n]=e.split(`: `);return[t,n.join(`: `)]}):[]),{contentLength:o,isRangeSupported:s}=tr({responseHeaders:a,isHttp:e.isHttp,rangeChunkSize:n,disableRange:t});this._contentLength=o,this._isRangeSupported=s,this._filename=nr(a),this._isRangeSupported&&e._abortRequest(r),this._headersCapability.resolve()}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._cachedChunks.push(e),this._done=!0,this._cachedChunks.length===0&&this.#e()}#r(e){this._storedError=rr(e,this._stream.url),this._headersCapability.reject(this._storedError);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}#i(e){this.onProgress?.({loaded:e.loaded,total:e.lengthComputable?e.total:this._contentLength})}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this._headersCapability.reject(e),this.#e(),this._stream._abortRequest(this._fullRequestXhr),this._fullRequestXhr=null}},xr=class extends Zn{#e=fr.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(e,t,n){super(e,t,n),this._requestXhr=e._request({begin:t,end:n,onHeadersReceived:this.#t.bind(this),onDone:this.#n.bind(this),onError:this.#r.bind(this),onProgress:null})}#t(){let e=er(this._requestXhr?.responseURL);try{ir(e,this._stream._responseOrigin)}catch(e){this._storedError=e,this.#r(0)}}#n(e){this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0,this.#e(),this.onClosed?.()}#r(e){this._storedError??=rr(e,this._stream.url);for(let e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let e=Promise.withResolvers();return this._requests.push(e),e.promise}cancel(e){this._done=!0,this.#e(),this._stream._abortRequest(this._requestXhr),this.onClosed?.()}};function Sr(e,t=null){let n=process.getBuiltinModule(`fs`),{Readable:r}=process.getBuiltinModule(`stream`),i=n.createReadStream(e,t);return r.toWeb(i)}var Cr=class extends Yn{constructor(e){super(e,wr,Tr);let{url:t}=e;I(t.protocol===`file:`,`PDFNodeStream only supports file:// URLs.`)}},wr=class extends Xn{_reader=null;constructor(e){super(e);let{disableRange:t,disableStream:n,rangeChunkSize:r,url:i}=e._source;this._isStreamingSupported=!n,process.getBuiltinModule(`fs/promises`).lstat(i).then(e=>{let n=Sr(i);this._reader=n.getReader();let{size:a}=e;this._contentLength=a,this._isRangeSupported=!t&&a>2*r,!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new pe(`Streaming is disabled.`)),this._headersCapability.resolve()}).catch(e=>{e.code===`ENOENT`&&(e=rr(0,i)),this._headersCapability.reject(e)})}async read(){await this._headersCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:(this._loaded+=e.byteLength,this._callOnProgress(),{value:sr(e),done:!1})}cancel(e){this._reader?.cancel(e)}},Tr=class extends Zn{_readCapability=Promise.withResolvers();_reader=null;constructor(e,t,n){super(e,t,n);let{url:r}=e._source;try{let e=Sr(r,{start:t,end:n-1});this._reader=e.getReader(),this._readCapability.resolve()}catch(e){this._readCapability.reject(e)}}async read(){await this._readCapability.promise;let{value:e,done:t}=await this._reader.read();return t?{value:e,done:t}:{value:sr(e),done:!1}}cancel(e){this._reader?.cancel(e)}};function Er(e){return Fe(e)?cr:f?Cr:yr}var Dr=class{static#e=null;static#t=``;static get workerPort(){return this.#e}static set workerPort(e){if(!(typeof Worker<`u`&&e instanceof Worker)&&e!==null)throw Error("Invalid `workerPort` type.");this.#e=e}static get workerSrc(){return this.#t}static set workerSrc(e){if(typeof e!=`string`)throw Error("Invalid `workerSrc` type.");this.#t=e}},Or=class{#e;#t;constructor({parsedData:e,rawData:t}){this.#e=e,this.#t=t}getRaw(){return this.#t}get(e){return this.#e.get(e)??null}[Symbol.iterator](){return this.#e.entries()}},kr=Symbol(`INTERNAL`),Ar=class{#e=!1;#t=!1;#n=!1;#r=!0;constructor(e,{name:t,intent:n,usage:r,rbGroups:i}){this.#e=!!(e&v.DISPLAY),this.#t=!!(e&v.PRINT),this.name=t,this.intent=n,this.usage=r,this.rbGroups=i}get visible(){if(this.#n)return this.#r;if(!this.#r)return!1;let{print:e,view:t}=this.usage;return this.#e?t?.viewState!==`OFF`:!this.#t||e?.printState!==`OFF`}_setVisible(e,t,n=!1){e!==kr&&F("Internal method `_setVisible` called."),this.#n=n,this.#r=t}get serializable(){return{userSet:this.#n,visible:this.#r}}},jr=class e{#e=null;#t=new Map;#n=null;#r=null;#i;creator=null;name=null;constructor(e,t=v.DISPLAY,n=null){if(this.#i=e,this.renderingIntent=t,e!==null){this.name=e.name,this.creator=e.creator,this.#r=e.order;for(let n of e.groups)this.#t.set(n.id,new Ar(t,n));if(n){n.size!==this.#t.size&&F(`Incorrect serialized groupState.`);for(let[e,t]of n)this.#t.get(e)._setVisible(kr,t.visible,t.userSet)}else{if(e.baseState===`OFF`)for(let e of this.#t.values())e._setVisible(kr,!1);for(let t of e.on)this.#t.get(t)._setVisible(kr,!0);for(let t of e.off)this.#t.get(t)._setVisible(kr,!1)}this.#n=this.getHash()}}#a(e){let t=e.length;if(t<2)return!0;let n=e[0];for(let r=1;r<t;r++){let t=e[r],i;if(Array.isArray(t))i=this.#a(t);else if(this.#t.has(t))i=this.#t.get(t).visible;else return P(`Optional content group not found: ${t}`),!0;switch(n){case`And`:if(!i)return!1;break;case`Or`:if(i)return!0;break;case`Not`:return!i;default:return!0}}return n===`And`}isVisible(e){if(this.#t.size===0)return!0;if(!e)return ne(`Optional content group not defined.`),!0;if(e.type===`OCG`)return this.#t.has(e.id)?this.#t.get(e.id).visible:(P(`Optional content group not found: ${e.id}`),!0);if(e.type===`OCMD`){if(e.expression)return this.#a(e.expression);if(!e.policy||e.policy===`AnyOn`){for(let t of e.ids){if(!this.#t.has(t))return P(`Optional content group not found: ${t}`),!0;if(this.#t.get(t).visible)return!0}return!1}else if(e.policy===`AllOn`){for(let t of e.ids){if(!this.#t.has(t))return P(`Optional content group not found: ${t}`),!0;if(!this.#t.get(t).visible)return!1}return!0}else if(e.policy===`AnyOff`){for(let t of e.ids){if(!this.#t.has(t))return P(`Optional content group not found: ${t}`),!0;if(!this.#t.get(t).visible)return!0}return!1}else if(e.policy===`AllOff`){for(let t of e.ids){if(!this.#t.has(t))return P(`Optional content group not found: ${t}`),!0;if(this.#t.get(t).visible)return!1}return!0}return P(`Unknown optional content policy ${e.policy}.`),!0}return P(`Unknown group type ${e.type}.`),!0}setVisibility(e,t=!0,n=!0){let r=this.#t.get(e);if(!r){P(`Optional content group not found: ${e}`);return}if(n&&t&&r.rbGroups.length)for(let t of r.rbGroups)for(let n of t)n!==e&&this.#t.get(n)?._setVisible(kr,!1,!0);r._setVisible(kr,!!t,!0),this.#e=null}setOCGState({state:e,preserveRB:t}){let n;for(let r of e){switch(r){case`ON`:case`OFF`:case`Toggle`:n=r;continue}let e=this.#t.get(r);if(e)switch(n){case`ON`:this.setVisibility(r,!0,t);break;case`OFF`:this.setVisibility(r,!1,t);break;case`Toggle`:this.setVisibility(r,!e.visible,t);break}}this.#e=null}get hasInitialVisibility(){return this.#n===null||this.getHash()===this.#n}getOrder(){return this.#t.size?this.#r?this.#r.slice():[...this.#t.keys()]:null}getGroup(e){return this.#t.get(e)||null}getHash(){if(this.#e!==null)return this.#e;let e=new vt;for(let[t,n]of this.#t)e.update(`${t}:${n.visible}`);return this.#e=e.hexdigest()}[Symbol.iterator](){return this.#t.entries()}get serializable(){let e=new Map;for(let[t,n]of this.#t)e.set(t,n.serializable);return{data:this.#i,renderingIntent:this.renderingIntent,groupState:e}}static fromSerializable({data:t,renderingIntent:n,groupState:r}){return new e(t,n,r)}},Mr=class{#e=null;#t=null;#n=0;#r=null;#i=null;get pagesNumber(){return this.#n}set pagesNumber(e){this.#n!==e&&(this.#n=e,this.#e=null,this.#t=null)}#a(){if(this.#e)return;let e=this.#n,t=this.#e=new Uint32Array(e);for(let n=0;n<e;n++)t[n]=n+1;this.#t=new Int32Array(t)}#o(){let e=new Map,t=this.#e;for(let n=0,r=this.#n;n<r;n++){let r=t[n],i=e.get(r);i?i.push(n+1):e.set(r,[n+1])}return e}movePages(e,t,n){this.#a();let r=this.#e,i=this.#o(),a=t.length,o=new Uint32Array(a),s=0;for(let e=0;e<a;e++){let i=t[e]-1;o[e]=r[i],i<n&&s++}let c=this.#n,l=c-a,u=V(n-s,0,l);for(let t=0,n=0;t<c;t++)e.has(t+1)||(r[n++]=r[t]);r.copyWithin(u+a,u,l),r.set(o,u),this.#s(i),r.every((e,t)=>e===t+1)&&(this.#e=null)}deletePages(e){this.#a();let t=this.#e,n=this.#o();this.#i={pageNumberToId:t.slice(),pagesNumber:this.#n,prevPageNumbers:this.#t.slice()};let r=this.#n-e.length;this.#n=r;let i=this.#e=new Uint32Array(r);this.#t=new Int32Array(r);let a=0,o=0;for(let n of e){let e=n-1;e!==a&&(i.set(t.subarray(a,e),o),o+=e-a),a=e+1}a<t.length&&i.set(t.subarray(a),o),this.#s(n,new Set(e))}cancelDelete(){this.#i&&=(this.#e=this.#i.pageNumberToId,this.#n=this.#i.pagesNumber,this.#t=this.#i.prevPageNumbers,null)}cleanSavedData(){this.#i=null}copyPages(e){this.#a(),this.#r={pageNumbers:e,pageIds:e.map(e=>this.#e[e-1])}}cancelCopy(){this.#r=null}pastePages(e){this.#a();let t=this.#e,n=this.#o(),{pageNumbers:r,pageIds:i}=this.#r,a=this.#n+r.length;this.#n=a;let o=this.#e=new Uint32Array(a);this.#t=new Int32Array(a),o.set(t.subarray(0,e),0),o.set(i,e),o.set(t.subarray(e),e+r.length),this.#s(n,null,e,r),this.#r=null}#s(e,t=null,n=-1,r=null){let i=this.#t,a=this.#e,o=n+(r?.length??0),s=new Map;for(let c=0,l=this.#n;c<l;c++){if(c>=n&&c<o){i[c]=-r[c-n];continue}let l=a[c],u=e.get(l),d=s.get(l)||0;if(t&&u)for(;d<u.length&&t.has(u[d]);)d++;i[c]=u?.[d],s.set(l,d+1)}}hasBeenAltered(){return this.#e!==null}getPageMappingForSaving(e=null){e??=this.#o();let t=0;for(let n of e.values())t=Math.max(t,n.length);let n=Array(t);for(let e=0;e<t;e++)n[e]={document:null,pageIndices:[],includePages:[]};for(let[t,r]of e)for(let e=0,i=r.length;e<i;e++)n[e].includePages.push([t-1,r[e]-1]);for(let{includePages:e,pageIndices:t}of n){e.sort((e,t)=>e[0]-t[0]);for(let n=0,r=e.length;n<r;n++)t.push(e[n][1]),e[n]=e[n][0]}return n}extractPages(e){e=Array.from(e).sort((e,t)=>e-t);let t=new Map;for(let n=0,r=e.length;n<r;n++){let r=this.getPageId(e[n]);t.getOrInsertComputed(r,xe).push(n+1)}return this.getPageMappingForSaving(t)}getPrevPageNumber(e){return this.#t?.[e-1]??0}getPageNumber(e){if(!this.#e)return e;let t=this.#e;for(let n=0,r=this.#n;n<r;n++)if(t[n]===e)return n+1;return 0}getPageId(e){return this.#e?.[e-1]??e}getMapping(){return this.#e?.subarray(0,this.pagesNumber)}},Nr=Symbol(`INITIAL_DATA`),Pr=()=>({...Promise.withResolvers(),data:Nr}),Fr=class{#e=new Map;get(e,t=null){if(t){let n=this.#e.getOrInsertComputed(e,Pr);return n.promise.then(()=>t(n.data)),null}let n=this.#e.get(e);if(!n||n.data===Nr)throw Error(`Requesting object that isn't resolved yet ${e}.`);return n.data}has(e){let t=this.#e.get(e);return!!t&&t.data!==Nr}delete(e){let t=this.#e.get(e);return!t||t.data===Nr?!1:(this.#e.delete(e),!0)}resolve(e,t=null){let n=this.#e.getOrInsertComputed(e,Pr);if(n.data!==Nr)throw Error(`Object already resolved ${e}.`);n.data=t,n.resolve()}clear(){for(let{data:e}of this.#e.values())e?.bitmap?.close();this.#e.clear()}*[Symbol.iterator](){for(let[e,{data:t}]of this.#e)t!==Nr&&(yield[e,t])}},Ir=1e5,Lr=30,Rr=class e{#e=Promise.withResolvers();#t=null;#n=!1;#r=!!globalThis.FontInspector?.enabled;#i=null;#a=null;#o=null;#s=0;#c=0;#l=null;#u=null;#d=0;#f=0;#p=Object.create(null);#m=[];#h=null;#g=[];#_=new WeakMap;#v=null;static#y=new Map;static#b=new Map;static#x=new WeakMap;static#S=null;static#C=new Set;constructor({textContentSource:t,images:n,container:r,viewport:i}){if(t instanceof ReadableStream)this.#h=t;else if(typeof t==`object`)this.#h=new ReadableStream({start(e){e.enqueue(t),e.close()}});else throw Error(`No "textContentSource" parameter specified.`);this.#t=this.#u=r,this.#i=n,this.#f=i.scale*He.pixelRatio,this.#d=i.rotation,this.#o={div:null,properties:null,ctx:null};let{pageWidth:a,pageHeight:o,pageX:s,pageY:c}=i.rawDims;this.#v=[1,0,0,-1,-s,c+o],this.#c=a,this.#s=o,e.#k(),r.style.setProperty(`--min-font-size`,e.#S),Ve(r,i),this.#e.promise.finally(()=>{e.#C.delete(this),this.#o=null,this.#p=null}).catch(()=>{})}static get fontFamilyMap(){let{isWindows:e,isFirefox:t}=R.platform;return L(this,`fontFamilyMap`,new Map([[`sans-serif`,`${e&&t?`Calibri, `:``}sans-serif`],[`monospace`,`${e&&t?`Lucida Console, `:``}monospace`]]))}render(){this.#i&&this.#t.append(this.#i.render());let t=()=>{this.#l.read().then(({value:e,done:n})=>{if(n){this.#e.resolve();return}this.#a??=e.lang,Object.assign(this.#p,e.styles),this.#w(e.items),t()},this.#e.reject)};return this.#l=this.#h.getReader(),e.#C.add(this),t(),this.#e.promise}update({viewport:t,onBefore:n=null}){let r=t.scale*He.pixelRatio,i=t.rotation;if(i!==this.#d&&(n?.(),this.#d=i,Ve(this.#u,{rotation:i})),r!==this.#f){n?.(),this.#f=r;let t={div:null,properties:null,ctx:e.#D(this.#a)};for(let e of this.#g)t.properties=this.#_.get(e),t.div=e,this.#E(t)}}cancel(){let e=new pe(`TextLayer task cancelled.`);this.#l?.cancel(e).catch(()=>{}),this.#l=null,this.#e.reject(e)}get textDivs(){return this.#g}get textContentItemsStr(){return this.#m}#w(t){if(this.#n)return;this.#o.ctx??=e.#D(this.#a);let n=this.#g,r=this.#m;for(let e of t){if(n.length>Ir){P(`Ignoring additional textDivs for performance reasons.`),this.#n=!0;return}if(e.str===void 0){if(e.type===`beginMarkedContentProps`||e.type===`beginMarkedContent`){let t=this.#t;this.#t=document.createElement(`span`),this.#t.classList.add(`markedContent`),e.id&&this.#t.setAttribute(`id`,`${e.id}`),e.tag===`Artifact`&&(this.#t.ariaHidden=!0),t.append(this.#t)}else e.type===`endMarkedContent`&&(this.#t=this.#t.parentNode);continue}r.push(e.str),this.#T(e)}}#T(t){let n=document.createElement(`span`),r={angle:0,canvasWidth:0,hasText:t.str!==``,hasEOL:t.hasEOL,fontSize:0};this.#g.push(n);let i=z.transform(this.#v,t.transform),a=Math.atan2(i[1],i[0]),o=this.#p[t.fontName];o.vertical&&(a+=Math.PI/2);let s=this.#r&&o.fontSubstitution||o.fontFamily;s=e.fontFamilyMap.get(s)||s;let c=Math.hypot(i[2],i[3]),l=c*e.#A(s,o,this.#a),u,d;a===0?(u=i[4],d=i[5]-l):(u=i[4]+l*Math.sin(a),d=i[5]-l*Math.cos(a));let f=n.style;f.left=`${(100*u/this.#c).toFixed(2)}%`,f.top=`${(100*d/this.#s).toFixed(2)}%`,f.setProperty(`--font-height`,`${c.toFixed(2)}px`),f.fontFamily=s,r.fontSize=c,n.setAttribute(`role`,`presentation`),n.textContent=t.str,n.dir=t.dir,this.#r&&(n.dataset.fontName=o.fontSubstitutionLoadedName||t.fontName),a!==0&&(r.angle=180/Math.PI*a);let p=!1;if(t.str.length>1)p=!0;else if(t.str!==` `&&t.transform[0]!==t.transform[3]){let e=Math.abs(t.transform[0]),n=Math.abs(t.transform[3]);e!==n&&Math.max(e,n)/Math.min(e,n)>1.5&&(p=!0)}if(p&&(r.canvasWidth=o.vertical?t.height:t.width),this.#_.set(n,r),this.#o.div=n,this.#o.properties=r,this.#E(this.#o),r.hasText&&this.#t.append(n),r.hasEOL){let e=document.createElement(`br`);e.setAttribute(`role`,`presentation`),this.#t.append(e)}}#E(t){let{div:n,properties:r,ctx:i}=t,{style:a}=n;if(r.canvasWidth!==0&&r.hasText){let{fontFamily:t}=a,{canvasWidth:o,fontSize:s}=r;e.#O(i,s*this.#f,t);let{width:c}=i.measureText(n.textContent);c>0&&a.setProperty(`--scale-x`,o*this.#f/c)}r.angle!==0&&a.setProperty(`--rotate`,`${r.angle}deg`)}static cleanup(){if(!(this.#C.size>0)){this.#y.clear();for(let{canvas:e}of this.#b.values())e.remove();this.#b.clear()}}static#D(e=null){let t=this.#b.get(e||=``);if(!t){let n=document.createElement(`canvas`);n.style.cssText=`position:absolute;top:0;left:0;width:0;height:0;display:none;letter-spacing:normal;word-spacing:normal`,n.lang=e,document.body.append(n),t=n.getContext(`2d`,{alpha:!1,willReadFrequently:!0}),this.#b.set(e,t),this.#x.set(t,{size:0,family:``})}return t}static#O(e,t,n){let r=this.#x.get(e);t===r.size&&n===r.family||(e.font=`${t}px ${n}`,r.size=t,r.family=n)}static#k(){if(this.#S!==null)return;let e=document.createElement(`div`);e.style.opacity=0,e.style.lineHeight=1,e.style.fontSize=`1px`,e.style.position=`absolute`,e.textContent=`X`,document.body.append(e),this.#S=e.getBoundingClientRect().height,e.remove()}static#A(e,t,n){let r=this.#y.get(e);if(r)return r;let i=this.#D(n);i.canvas.width=i.canvas.height=Lr,this.#O(i,Lr,e);let a=i.measureText(``),o=a.fontBoundingBoxAscent,s=Math.abs(a.fontBoundingBoxDescent);i.canvas.width=i.canvas.height=0;let c=.8;return o?c=o/(o+s):(R.platform.isFirefox&&P("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering."),t.ascent?c=t.ascent:t.descent&&(c=1+t.descent)),this.#y.set(e,c),c}},zr=100;function Br(e={}){let t=new Vr,{docId:n}=t,r=e.url?Kt(e.url):null,i=e.data?qt(e.data):null,a=e.httpHeaders||null,o=e.withCredentials===!0,s=e.password??null,c=e.range instanceof Hr?e.range:null,l=Number.isInteger(e.rangeChunkSize)&&e.rangeChunkSize>0?e.rangeChunkSize:2**16,u=e.worker instanceof Gr?e.worker:null,d=e.verbosity,p=typeof e.docBaseUrl==`string`&&!Ae(e.docBaseUrl)?e.docBaseUrl:null,m=Jt(e.cMapUrl),h=e.cMapPacked!==!1,g=Jt(e.iccUrl),_=Jt(e.standardFontDataUrl),v=Jt(e.wasmUrl),y=e.stopAtErrors!==!0,b=Number.isInteger(e.maxImageSize)&&e.maxImageSize>-1?e.maxImageSize:-1,x=typeof e.isOffscreenCanvasSupported==`boolean`?e.isOffscreenCanvasSupported:!f,S=typeof e.isImageDecoderSupported==`boolean`?e.isImageDecoderSupported:!f,C=Number.isInteger(e.canvasMaxAreaInBytes)?e.canvasMaxAreaInBytes:-1,w=typeof e.disableFontFace==`boolean`?e.disableFontFace:f,T=e.fontExtraProperties===!0,E=e.enableXfa===!0,D=e.ownerDocument||globalThis.document,O=e.disableRange===!0,k=e.disableStream===!0,A=e.disableAutoFetch===!0,j=e.pdfBug===!0,ee=e.CanvasFactory||(f?dn:an),M=e.FilterFactory||(f?un:sn),te=e.BinaryDataFactory||(f?fn:nn),ne=e.enableHWA===!0,P=e.enableWebGPU===!0?_n():Promise.resolve(!1),F=e.useWasm!==!1,I=e.pagesMapper||new Mr,re=typeof e.useSystemFonts==`boolean`?e.useSystemFonts:!f&&!w,ie=typeof e.useWorkerFetch==`boolean`?e.useWorkerFetch:!!(te===nn&&m&&h&&_&&v&&Fe(m,document.baseURI)&&Fe(_,document.baseURI)&&Fe(v,document.baseURI));N(d);let ae={canvasFactory:new ee({ownerDocument:D,enableHWA:ne}),filterFactory:new M({docId:n,ownerDocument:D}),binaryDataFactory:ie?null:new te({cMapUrl:m,standardFontDataUrl:_,wasmUrl:v})};u||(u=Gr.create({verbosity:d,port:Dr.workerPort}),t._worker=u);let oe={docId:n,apiVersion:`6.1.200`,data:i,password:s,disableAutoFetch:A,rangeChunkSize:l,docBaseUrl:p,enableXfa:E,evaluatorOptions:{maxImageSize:b,disableFontFace:w,ignoreErrors:y,isOffscreenCanvasSupported:x,isImageDecoderSupported:S,canvasMaxAreaInBytes:C,fontExtraProperties:T,useSystemFonts:re,useWasm:F,useWorkerFetch:ie,cMapUrl:m,cMapPacked:h,iccUrl:g,standardFontDataUrl:_,wasmUrl:v,hasGPU:!1}},L={ownerDocument:D,pdfBug:j,styleElement:null,enableHWA:ne,loadingParams:{disableAutoFetch:A,enableXfa:E}};return Promise.all([u.promise,P]).then(function([,e]){if(u.destroyed)throw Error(`Worker was destroyed`);oe.evaluatorOptions.hasGPU=e;let s=u.messageHandler.sendWithPromise(`GetDocRequest`,oe,i?[i.buffer]:null),d;if(!i)if(c)d=new pr({pdfDataRangeTransport:c,disableRange:O,disableStream:k});else if(r)d=new(Er(r))({url:r,httpHeaders:a,withCredentials:o,rangeChunkSize:l,disableRange:O,disableStream:k});else throw Error("getDocument - expected either `data`, `range`, or `url` parameter.");return s.then(e=>{if(u.destroyed)throw Error(`Worker was destroyed`);let r=new en(n,e,u.port),i=new Kr(r,t,d,L,ae,I);if(t._transport=i,t.destroyed)throw Error(`Loading aborted`);r.send(`Ready`,null)})}).catch(t._capability.reject).finally(t._setupCapability.resolve),t}var Vr=class e{static#e=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;docId=`d${e.#e++}`;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0,this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0),await this._setupCapability.promise,await this._transport?.destroy()}catch(e){throw this._worker?.port&&delete this._worker._pendingDestroy,e}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}},Hr=class{#e=Promise.withResolvers();#t=null;constructor(e,t,n=!1,r=null){this.length=e,this.initialData=t,this.progressiveDone=n,this.contentDispositionFilename=r}onDataRange(e,t){this.#t({type:`range`,begin:e,chunk:t})}onDataProgressiveRead(e){this.#e.promise.then(()=>{this.#t({type:`progressiveRead`,chunk:e})})}onDataProgressiveDone(){this.#e.promise.then(()=>{this.#t({type:`progressiveDone`})})}transportReady(e){this.#t=e,this.#e.resolve()}requestDataRange(e,t){F(`Abstract method PDFDataRangeTransport.requestDataRange`)}abort(){}},Ur=class{constructor(e,t){this._pdfInfo=e,this._transport=t}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return L(this,`isPureXfa`,!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(e){return this._transport.getPage(e)}getPageIndex(e){return this._transport.getPageIndex(e)}getDestinations(){return this._transport.getDestinations()}getDestination(e){return this._transport.getDestination(e)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAttachmentContent(e){return this._transport.getAttachmentContent(e)}getAnnotationsByType(e,t){return this._transport.getAnnotationsByType(e,t)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getOptionalContentConfig(t)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}extractPages(e){return this._transport.extractPages(e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}getRawData(e){return this._transport.getRawData(e)}cleanup(e=!1){return this._transport.startCleanup(e||this.isPureXfa)}cachedPageNumber(e){return this._transport.cachedPageNumber(e)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}},Wr=class e{#e=!1;#t=null;constructor(e,t,n,r,i=!1){this._pageIndex=e,this._pageInfo=t,this._transport=n,this._stats=i?new Pe:null,this._pdfBug=i,this.commonObjs=n.commonObjs,this.objs=new Fr,this._intentStates=new Map,this.destroyed=!1,this.recordedBBoxes=null,this.#t=r,this.imageCoordinates=null}clone(t){let n=new e(t,this._pageInfo,this._transport,this.#t,this._pdfBug);return n.clonedFromIndex=this.clonedFromIndex??this._pageIndex,this._transport.updatePage(n),n}get pageNumber(){return this._pageIndex+1}set pageNumber(e){this._pageIndex=e-1,this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:e,rotation:t=this.rotate,offsetX:n=0,offsetY:r=0,dontFlip:i=!1}={}){return new we({viewBox:this.view,userUnit:this.userUnit,scale:e,rotation:t,offsetX:n,offsetY:r,dontFlip:i})}getAnnotations({intent:e=`display`}={}){let{renderingIntent:t}=this._transport.getRenderingIntent(e);return this._transport.getAnnotations(this._pageIndex,t)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return L(this,`isPureXfa`,!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:e,canvas:t=e.canvas,viewport:n,intent:r=`display`,annotationMode:i=y.ENABLE,transform:a=null,background:o=null,optionalContentConfigPromise:s=null,annotationCanvasMap:c=null,pageColors:l=null,printAnnotationStorage:u=null,isEditing:d=!1,recordImages:f=!1,recordOperations:p=!1,operationsFilter:m=null}){this._stats?.time(`Overall`);let h=this._transport.getRenderingIntent(r,i,u,d),{renderingIntent:g,cacheKey:_}=h;this.#e=!1,s||=this._transport.getOptionalContentConfig(g);let b=this._intentStates.getOrInsertComputed(_,Ce);b.streamReaderCancelTimeout&&=(clearTimeout(b.streamReaderCancelTimeout),null);let x=!!(g&v.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time(`Page Request`),this._pumpOperatorList(h));let S=!!(this._pdfBug&&globalThis.StepperManager?.enabled),C=!!t&&!this.recordedBBoxes&&(p||S),w=!!t&&!this.imageCoordinates&&f,T=e=>{if(b.renderTasks.delete(O),C){let e=O.gfx?.dependencyTracker.take();e&&(O.stepper?.setOperatorBBoxes(e,O.gfx.dependencyTracker.takeDebugMetadata()),p&&(this.recordedBBoxes=e))}w&&!e&&(this.imageCoordinates=O.gfx?.imagesTracker.take()),x&&(this.#e=!0),this.#n(),e?(O.capability.reject(e),this._abortOperatorList({intentState:b,reason:e instanceof Error?e:Error(e)})):O.capability.resolve(),this._stats&&(this._stats.timeEnd(`Rendering`),this._stats.timeEnd(`Overall`),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},E=null,D=null;(C||w)&&(D=new At(t,b.operatorList.length)),C&&(E=new jt(D,S));let O=new Jr({callback:T,params:{canvas:t,canvasContext:e,dependencyTracker:E??D,imagesTracker:w?new Pt(t):null,viewport:n,transform:a,background:o},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:c,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!x,pdfBug:this._pdfBug,pageColors:l,enableHWA:this._transport.enableHWA,operationsFilter:m});(b.renderTasks||=new Set).add(O);let k=O.task;return Promise.all([b.displayReadyCapability.promise,s]).then(([e,t])=>{if(this.destroyed){T();return}if(this._stats?.time(`Rendering`),!(t.renderingIntent&g))throw Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");O.initializeGraphics({transparency:e,optionalContentConfig:t}),O.operatorListChanged()}).catch(T),k}getOperatorList({intent:e=`display`,annotationMode:t=y.ENABLE,printAnnotationStorage:n=null,isEditing:r=!1}={}){function i(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(s))}let a=this._transport.getRenderingIntent(e,t,n,r,!0),o=this._intentStates.getOrInsertComputed(a.cacheKey,Ce),s;return o.opListReadCapability||(s=Object.create(null),s.operatorListChanged=i,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||=new Set).add(s),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time(`Page Request`),this._pumpOperatorList(a)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:e=!1,disableNormalization:t=!1}={}){return this._transport.messageHandler.sendWithStream(`GetTextContent`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:e===!0,disableNormalization:t===!0},{highWaterMark:100,size(e){return e.items.length}})}async getTextContent(e={}){if(this._transport._htmlForXfa)return this.getXfa().then(e=>Te.textContent(e));let t=this.streamTextContent(e),n={items:[],styles:Object.create(null),lang:null};for await(let e of t)n.lang??=e.lang,Object.assign(n.styles,e.styles),n.items.push(...e.items);return n}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;let e=[];for(let t of this._intentStates.values())if(this._abortOperatorList({intentState:t,reason:Error(`Page was destroyed.`),force:!0}),!t.opListReadCapability)for(let n of t.renderTasks)e.push(n.completed),n.cancel();return this.objs.clear(),this.#e=!1,Promise.all(e)}cleanup(e=!1){this.#e=!0;let t=this.#n();return e&&t&&(this._stats&&=new Pe),t}#n(){if(!this.#e||this.destroyed)return!1;for(let{renderTasks:e,operatorList:t}of this._intentStates.values())if(e.size>0||!t.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#e=!1,!0}_startRenderPage(e,t){let n=this._intentStates.get(t);n&&(this._stats?.timeEnd(`Page Request`),n.displayReadyCapability?.resolve(e))}_renderPageChunk(e,t){for(let n=0,r=e.length;n<r;n++)t.operatorList.fnArray.push(e.fnArray[n]),t.operatorList.argsArray.push(e.argsArray[n]);t.operatorList.lastChunk=e.lastChunk,t.operatorList.separateAnnots=e.separateAnnots;for(let e of t.renderTasks)e.operatorListChanged();e.lastChunk&&this.#n()}_pumpOperatorList({renderingIntent:e,cacheKey:t,annotationStorageSerializable:n,modifiedIds:r}){let{map:i,transfer:a}=n,o=this._transport.messageHandler.sendWithStream(`GetOperatorList`,{pageId:this.#t.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,intent:e,cacheKey:t,annotationStorage:i,modifiedIds:r},void 0,a).getReader(),s=this._intentStates.get(t);s.streamReader=o;let c=()=>{o.read().then(({value:e,done:t})=>{if(t){s.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(e,s),c())},e=>{if(s.streamReader=null,!this._transport.destroyed){if(s.operatorList){s.operatorList.lastChunk=!0;for(let e of s.renderTasks)e.operatorListChanged();this.#n()}if(s.displayReadyCapability)s.displayReadyCapability.reject(e);else if(s.opListReadCapability)s.opListReadCapability.reject(e);else throw e}})};c()}_abortOperatorList({intentState:e,reason:t,force:n=!1}){if(e.streamReader){if(e.streamReaderCancelTimeout&&=(clearTimeout(e.streamReaderCancelTimeout),null),!n){if(e.renderTasks.size>0)return;if(t instanceof ke){let n=zr;t.extraDelay>0&&t.extraDelay<1e3&&(n+=t.extraDelay),e.streamReaderCancelTimeout=setTimeout(()=>{e.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:e,reason:t,force:!0})},n);return}}if(e.streamReader.cancel(new pe(t.message)).catch(()=>{}),e.streamReader=null,!this._transport.destroyed){for(let[t,n]of this._intentStates)if(n===e){this._intentStates.delete(t);break}this.cleanup()}}}get stats(){return this._stats}},Gr=class e{#e=Promise.withResolvers();#t=null;#n=null;#r=null;static#i=0;static#a=!1;static#o=new WeakMap;static{f&&(this.#a=!0,Dr.workerSrc||=`./pdf.worker.mjs`),this._isSameOrigin=(e,t)=>{let n=URL.parse(e);if(!n?.origin||n.origin===`null`)return!1;let r=new URL(t,n);return n.origin===r.origin},this._createCDNWrapper=e=>{let t=`await import("${e}");`;return URL.createObjectURL(new Blob([t],{type:`text/javascript`}))}}constructor({name:t=null,port:n=null,verbosity:r=te()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=r,n){if(e.#o.has(n))throw Error(`Cannot use more than one PDFWorker per port.`);e.#o.set(n,this),this.#c(n)}else this.#l()}get promise(){return this.#e.promise}#s(){this.#e.resolve(),this.#t.send(`configure`,{verbosity:this.verbosity})}get port(){return this.#n}get messageHandler(){return this.#t}#c(e){this.#n=e,this.#t=new en(`main`,`worker`,e),this.#t.on(`ready`,()=>{}),this.#s()}#l(){if(e.#a||e.#d){this.#u();return}let{workerSrc:t}=e;try{e._isSameOrigin(window.location,t)||(t=e._createCDNWrapper(new URL(t,window.location).href));let n=new Worker(t,{type:`module`}),r=new en(`main`,`worker`,n),i=()=>{a.abort(),r.destroy(),n.terminate(),this.destroyed?this.#e.reject(Error(`Worker was destroyed`)):this.#u()},a=new AbortController;n.addEventListener(`error`,()=>{this.#r||i()},{signal:a.signal}),r.on(`test`,e=>{if(a.abort(),this.destroyed||!e){i();return}this.#t=r,this.#n=n,this.#r=n,this.#s()}),r.on(`ready`,e=>{if(a.abort(),this.destroyed){i();return}try{o()}catch{this.#u()}});let o=()=>{let e=new Uint8Array;r.send(`test`,e,[e.buffer])};o();return}catch{ne(`The worker has been disabled.`)}this.#u()}#u(){e.#a||=(P(`Setting up fake worker.`),!0),e._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this.#e.reject(Error(`Worker was destroyed`));return}let n=new Zt;this.#n=n;let r=`fake${e.#i++}`,i=new en(r+`_worker`,r,n);t.setup(i,n),this.#t=new en(r,r+`_worker`,n),this.#s()}).catch(e=>{this.#e.reject(Error(`Setting up fake worker failed: "${e.message}".`))})}destroy(){this.destroyed=!0,this.#r?.terminate(),this.#r=null,e.#o.delete(this.#n),this.#n=null,this.#t?.destroy(),this.#t=null}static create(t){let n=this.#o.get(t?.port);if(n){if(n._pendingDestroy)throw Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return n}return new e(t)}static get workerSrc(){if(Dr.workerSrc)return Dr.workerSrc;throw Error(`No "GlobalWorkerOptions.workerSrc" specified.`)}static get#d(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return L(this,`_setupFakeWorkerGlobal`,(async()=>this.#d?this.#d:(await import(this.workerSrc)).WorkerMessageHandler)())}},Kr=class{downloadInfoCapability=Promise.withResolvers();#e=null;#t=new Map;#n=null;#r=new Map;#i=new Map;#a=new Map;#o=null;constructor(e,t,n,r,i,a){this.messageHandler=e,this.loadingTask=t,this.#n=n,this.commonObjs=new Fr,this.fontLoader=new Ft({ownerDocument:r.ownerDocument,styleElement:r.styleElement}),this.enableHWA=r.enableHWA,this.loadingParams=r.loadingParams,this._params=r,this.canvasFactory=i.canvasFactory,this.filterFactory=i.filterFactory,this.binaryDataFactory=i.binaryDataFactory,this.pagesMapper=a,this.destroyed=!1,this.destroyCapability=null,this.setupMessageHandler()}updatePage(e){let{_pageIndex:t}=e;this.#r.set(t,e),this.#i.set(t,Promise.resolve(e))}#s(e,t=null){return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,t))}#c({loaded:e,total:t}){this.loadingTask.onProgress?.({loaded:e,total:t,percent:t?V(Math.round(e/t*100),0,100):NaN})}get annotationStorage(){return L(this,`annotationStorage`,new bt)}getRenderingIntent(e,t=y.ENABLE,n=null,r=!1,i=!1){let a=v.DISPLAY,o=yt;switch(e){case`any`:a=v.ANY;break;case`display`:break;case`print`:a=v.PRINT;break;default:P(`getRenderingIntent - invalid intent: ${e}`)}let s=a&v.PRINT&&n instanceof xt?n:this.annotationStorage;switch(t){case y.DISABLE:a+=v.ANNOTATIONS_DISABLE;break;case y.ENABLE:break;case y.ENABLE_FORMS:a+=v.ANNOTATIONS_FORMS;break;case y.ENABLE_STORAGE:a+=v.ANNOTATIONS_STORAGE,o=s.serializable;break;default:P(`getRenderingIntent - invalid annotationMode: ${t}`)}r&&(a+=v.IS_EDITING),i&&(a+=v.OPLIST);let{ids:c,hash:l}=s.modifiedIds,u=[a,o.hash,l];return{renderingIntent:a,cacheKey:u.join(`_`),annotationStorageSerializable:o,modifiedIds:c}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#o?.reject(Error(`Worker was destroyed during onPassword callback`));let e=[];for(let t of this.#r.values())e.push(t._destroy());this.#r.clear(),this.#i.clear(),this.#a.clear(),Object.hasOwn(this,`annotationStorage`)&&this.annotationStorage.resetModified();let t=this.messageHandler.sendWithPromise(`Terminate`,null);return e.push(t),Promise.all(e).then(()=>{this.commonObjs.clear(),this.fontLoader.clear(),this.#t.clear(),this.filterFactory.destroy(),Rr.cleanup(),this.#n?.cancelAllRequests(new pe(`Worker was terminated.`)),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:e,loadingTask:t}=this;e.on(`GetReader`,(e,t)=>{I(this.#n,"GetReader - no `BasePDFStream` instance available."),this.#e=this.#n.getFullReader(),this.#e.onProgress=e=>this.#c(e),t.onPull=()=>{this.#e.read().then(function({value:e,done:n}){if(n){t.close();return}I(e instanceof ArrayBuffer,`GetReader - expected an ArrayBuffer.`),t.enqueue(new Uint8Array(e),1,[e])}).catch(e=>{t.error(e)})},t.onCancel=e=>{this.#e.cancel(e),t.ready.catch(e=>{if(!this.destroyed)throw e})}}),e.on(`ReaderHeadersReady`,async e=>{await this.#e.headersReady;let{isStreamingSupported:t,isRangeSupported:n,contentLength:r}=this.#e;return t&&n&&(this.#e.onProgress=null),{isStreamingSupported:t,isRangeSupported:n,contentLength:r}}),e.on(`GetRangeReader`,(e,t)=>{I(this.#n,"GetRangeReader - no `BasePDFStream` instance available.");let n=this.#n.getRangeReader(e.begin,e.end);if(!n){t.close();return}t.onPull=()=>{n.read().then(function({value:e,done:n}){if(n){t.close();return}I(e instanceof ArrayBuffer,`GetRangeReader - expected an ArrayBuffer.`),t.enqueue(new Uint8Array(e),1,[e])}).catch(e=>{t.error(e)})},t.onCancel=e=>{n.cancel(e),t.ready.catch(e=>{if(!this.destroyed)throw e})}}),e.on(`GetDoc`,({pdfInfo:e})=>{this.pagesMapper.pagesNumber=e.numPages,this._numPages=e.numPages,this._htmlForXfa=e.htmlForXfa,delete e.htmlForXfa,t._capability.resolve(new Ur(e,this))}),e.on(`DocException`,e=>{t._capability.reject(J(e))}),e.on(`PasswordRequest`,e=>{this.#o=Promise.withResolvers();try{if(!t.onPassword)throw J(e);t.onPassword(e=>{e instanceof Error?this.#o.reject(e):this.#o.resolve({password:e})},e.code)}catch(e){this.#o.reject(e)}return this.#o.promise}),e.on(`DataLoaded`,e=>{this.#c({loaded:e.length,total:e.length}),this.downloadInfoCapability.resolve(e)}),e.on(`StartRenderPage`,e=>{this.destroyed||this.#r.get(e.pageIndex)._startRenderPage(e.transparency,e.cacheKey)}),e.on(`commonobj`,([t,n,r])=>{if(this.destroyed||this.commonObjs.has(t))return null;switch(n){case`Font`:if(`error`in r){let e=r.error;P(`Error during font loading: ${e}`),this.commonObjs.resolve(t,e);break}let i=new It(new Ut(r),this._params.pdfBug&&globalThis.FontInspector?.enabled?(e,t)=>globalThis.FontInspector.fontAdded(e,t):null,r.charProcOperatorList,r.extra);this.fontLoader.bind(i).catch(()=>e.sendWithPromise(`FontFallback`,{id:t})).finally(()=>{i.fontExtraProperties||i.clearData(),this.commonObjs.resolve(t,i)});break;case`CopyLocalImage`:let{imageRef:a}=r;I(a,`The imageRef must be defined.`);for(let e of this.#r.values())for(let[,n]of e.objs){if(n?.ref!==a)continue;if(!n.dataLen)return null;let e=structuredClone(n);return this.commonObjs.resolve(t,e),n.dataLen}break;case`FontPath`:this.commonObjs.resolve(t,new Gt(r));break;case`Image`:this.commonObjs.resolve(t,r);break;case`Pattern`:let o=new Wt(r);this.commonObjs.resolve(t,o.getIR());break;default:throw Error(`Got unknown common object type ${n}`)}return null}),e.on(`obj`,([e,t,n,r])=>{if(this.destroyed)return;let i=this.#r.get(t);if(!i.objs.has(e)){if(i._intentStates.size===0){r?.bitmap?.close();return}switch(n){case`Image`:case`Pattern`:i.objs.resolve(e,r);break;default:throw Error(`Got unknown object type ${n}`)}}}),e.on(`DocProgress`,e=>{this.destroyed||this.#c(e)}),e.on(`FetchBinaryData`,async e=>{if(this.destroyed)throw Error(`Worker was destroyed.`);if(!this.binaryDataFactory)throw Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(e)})}getData(){return this.messageHandler.sendWithPromise(`GetData`,null)}saveDocument(){this.annotationStorage.size<=0&&P("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{map:e,transfer:t}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise(`SaveDocument`,{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,filename:this.#e?.filename??null},t).finally(()=>{this.annotationStorage.resetModified()})}extractPages(e){let t={pageInfos:e},n,r=globalThis.ImageBitmap;if(typeof r==`function`){let t=Array.isArray(e)?e:[e];for(let e of t)e?.image instanceof r&&(n||=[]).push(e.image)}if(this.annotationStorage.size>0){let e=this.annotationStorage.serializable,{map:r}=e;e.transfer?.length&&(n?n.push(...e.transfer):n=e.transfer);let i=this.pagesMapper.getMapping();if(i){let e=new Map;for(let[t,n]of r){if(n?.pageIndex!==void 0&&n.pageIndex>=0&&n.pageIndex<i.length){let r=i[n.pageIndex]-1;if(r!==n.pageIndex){e.set(t,{...n,pageIndex:r});continue}}e.set(t,n)}r=e}t.annotationStorage=r}return this.messageHandler.sendWithPromise(`ExtractPages`,t,n).finally(()=>{this.annotationStorage.resetModified()})}getPage(e){if(!Number.isInteger(e)||e<=0||e>this.pagesMapper.pagesNumber)return Promise.reject(Error(`Invalid page request.`));let t=e-1,n=this.pagesMapper.getPageId(e)-1,r=this.#i.get(t);if(r)return r;let i=this.messageHandler.sendWithPromise(`GetPage`,{pageIndex:n}).then(e=>{if(this.destroyed)throw Error(`Transport destroyed`);e.refStr&&this.#a.set(e.refStr,n);let r=new Wr(t,e,this,this.pagesMapper,this._params.pdfBug);return this.#r.set(t,r),r});return this.#i.set(t,i),i}async getPageIndex(e){if(!Yt(e))throw Error(`Invalid pageIndex request.`);let t=await this.messageHandler.sendWithPromise(`GetPageIndex`,{num:e.num,gen:e.gen}),n=this.pagesMapper.getPageNumber(t+1);if(n===0)throw Error(`GetPageIndex: page has been removed.`);return n-1}getAnnotations(e,t){return this.messageHandler.sendWithPromise(`GetAnnotations`,{pageIndex:this.pagesMapper.getPageId(e+1)-1,intent:t})}getFieldObjects(){return this.#s(`GetFieldObjects`)}hasJSActions(){return this.#s(`HasJSActions`)}getCalculationOrderIds(){return this.messageHandler.sendWithPromise(`GetCalculationOrderIds`,null)}getDestinations(){return this.messageHandler.sendWithPromise(`GetDestinations`,null)}getDestination(e){return typeof e==`string`?this.messageHandler.sendWithPromise(`GetDestination`,{id:e}):Promise.reject(Error(`Invalid destination request.`))}getPageLabels(){return this.messageHandler.sendWithPromise(`GetPageLabels`,null)}getPageLayout(){return this.messageHandler.sendWithPromise(`GetPageLayout`,null)}getPageMode(){return this.messageHandler.sendWithPromise(`GetPageMode`,null)}getViewerPreferences(){return this.messageHandler.sendWithPromise(`GetViewerPreferences`,null)}getOpenAction(){return this.messageHandler.sendWithPromise(`GetOpenAction`,null)}getAttachments(){return this.messageHandler.sendWithPromise(`GetAttachments`,null)}getAttachmentContent(e){return this.messageHandler.sendWithPromise(`GetAttachmentContent`,e)}getAnnotationsByType(e,t){return this.messageHandler.sendWithPromise(`GetAnnotationsByType`,{types:e,pageIndexesToSkip:t})}getDocJSActions(){return this.#s(`GetDocJSActions`)}getPageJSActions(e){return this.messageHandler.sendWithPromise(`GetPageJSActions`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getStructTree(e){return this.messageHandler.sendWithPromise(`GetStructTree`,{pageIndex:this.pagesMapper.getPageId(e+1)-1})}getOutline(){return this.messageHandler.sendWithPromise(`GetOutline`,null)}getOptionalContentConfig(e){return this.#s(`GetOptionalContentConfig`).then(t=>new jr(t,e))}getPermissions(){return this.messageHandler.sendWithPromise(`GetPermissions`,null)}getMetadata(){let e=`GetMetadata`;return this.#t.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).then(e=>({info:e[0],metadata:e[1]?new Or(e[1]):null,contentDispositionFilename:this.#e?.filename??null,contentLength:this.#e?.contentLength??null,hasStructTree:e[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise(`GetMarkInfo`,null)}getRawData(e){return this.messageHandler.sendWithPromise(`GetRawData`,e)}async startCleanup(e=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise(`Cleanup`,null);for(let e of this.#r.values())if(!e.cleanup())throw Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),e||this.fontLoader.clear(),this.#t.clear(),this.filterFactory.destroy(!0),Rr.cleanup()}}cachedPageNumber(e){if(!Yt(e))return null;let t=e.gen===0?`${e.num}R`:`${e.num}R${e.gen}`,n=this.#a.get(t);if(n>=0){let e=this.pagesMapper.getPageNumber(n+1);if(e!==0)return e}return null}},qr=class{_internalRenderTask=null;onContinue=null;onError=null;constructor(e){this._internalRenderTask=e}get promise(){return this._internalRenderTask.capability.promise}cancel(e=0){this._internalRenderTask.cancel(null,e)}get separateAnnots(){let{separateAnnots:e}=this._internalRenderTask.operatorList;if(!e)return!1;let{annotationCanvasMap:t}=this._internalRenderTask;return e.form||e.canvas&&t?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}},Jr=class e{#e=null;static#t=new WeakSet;constructor({callback:e,params:t,objs:n,commonObjs:r,annotationCanvasMap:i,operatorList:a,pageIndex:o,canvasFactory:s,filterFactory:c,useRequestAnimationFrame:l=!1,pdfBug:u=!1,pageColors:d=null,enableHWA:f=!1,operationsFilter:p=null}){this.callback=e,this.params=t,this.objs=n,this.commonObjs=r,this.annotationCanvasMap=i,this.operatorListIdx=null,this.operatorList=a,this._pageIndex=o,this.canvasFactory=s,this.filterFactory=c,this._pdfBug=u,this.pageColors=d,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=l===!0&&typeof window<`u`,this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new qr(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=t.canvas,this._canvasContext=t.canvas?null:t.canvasContext,this._enableHWA=f,this._dependencyTracker=t.dependencyTracker,this._imagesTracker=t.imagesTracker,this._operationsFilter=p}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:n}){if(this.cancelled)return;if(this._canvas){if(e.#t.has(this._canvas))throw Error(`Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.`);e.#t.add(this._canvas)}this._pdfBug&&globalThis.StepperManager?.enabled&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());let{viewport:r,transform:i,background:a,dependencyTracker:o,imagesTracker:s}=this.params,c=this._canvasContext||this._canvas.getContext(`2d`,{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new Jn(c,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:n},this.annotationCanvasMap,this.pageColors,o,s),this.gfx.beginDrawing({transform:i,viewport:r,transparency:t,background:a}),this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}cancel(t=null,n=0){this.running=!1,this.cancelled=!0,this.gfx?.endDrawing(),this.#e&&=(window.cancelAnimationFrame(this.#e),null),e.#t.delete(this._canvas),t||=new ke(`Rendering cancelled, page ${this._pageIndex+1}`,n),this.callback(t),this.task.onError?.(t)}operatorListChanged(){if(!this.graphicsReady){this.graphicsReadyCallback||=this._continueBound;return}this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#e=window.requestAnimationFrame(()=>{this.#e=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),e.#t.delete(this._canvas),this.callback())))}},Yr=`6.1.200`,Xr=`6353acefe`,Zr=class e{#e=null;#t=null;#n;#r=null;#i=!1;#a=!1;#o=null;#s;#c=null;#l=null;static#u=null;static get _keyboardManager(){return L(this,`_keyboardManager`,new ct([[[`Escape`],e.prototype._hideDropdownFromKeyboard],[[`Space`],e.prototype._colorSelectFromKeyboard],[[`ArrowDown`,`ArrowRight`],e.prototype._moveToNext],[[`ArrowUp`,`ArrowLeft`],e.prototype._moveToPrevious],[[`Home`],e.prototype._moveToBeginning],[[`End`],e.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:n=null}){t?(this.#a=!1,this.#o=t):this.#a=!0,this.#l=t?._uiManager||n,this.#s=this.#l._eventBus,this.#n=t?.color?.toUpperCase()||this.#l?.highlightColors.values().next().value||`#FFFF98`,e.#u||=Object.freeze({blue:`pdfjs-editor-colorpicker-blue`,green:`pdfjs-editor-colorpicker-green`,pink:`pdfjs-editor-colorpicker-pink`,red:`pdfjs-editor-colorpicker-red`,yellow:`pdfjs-editor-colorpicker-yellow`})}renderButton(){let e=this.#e=document.createElement(`button`);e.className=`colorPicker`,e.tabIndex=`0`,e.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-button`),e.ariaHasPopup=`true`,this.#o&&(e.ariaControls=`${this.#o.id}_colorpicker_dropdown`);let t=this.#l._signal;e.addEventListener(`click`,this.#m.bind(this),{signal:t}),e.addEventListener(`keydown`,this.#p.bind(this),{signal:t});let n=this.#t=document.createElement(`span`);return n.className=`swatch`,n.ariaHidden=`true`,n.style.backgroundColor=this.#n,e.append(n),e}renderMainDropdown(){let e=this.#r=this.#d();return e.ariaOrientation=`horizontal`,e.ariaLabelledBy=`highlightColorPickerLabel`,e}#d(){let t=document.createElement(`div`),n=this.#l._signal;t.addEventListener(`contextmenu`,H,{signal:n}),t.className=`dropdown`,t.role=`listbox`,t.ariaMultiSelectable=`false`,t.ariaOrientation=`vertical`,t.setAttribute(`data-l10n-id`,`pdfjs-editor-colorpicker-dropdown`),this.#o&&(t.id=`${this.#o.id}_colorpicker_dropdown`);for(let[r,i]of this.#l.highlightColors){let a=document.createElement(`button`);a.tabIndex=`0`,a.role=`option`,a.setAttribute(`data-color`,i),a.title=r,a.setAttribute(`data-l10n-id`,e.#u[r]);let o=document.createElement(`span`);a.append(o),o.className=`swatch`,o.style.backgroundColor=i,a.ariaSelected=i===this.#n,a.addEventListener(`click`,this.#f.bind(this,i),{signal:n}),t.append(a)}return t.addEventListener(`keydown`,this.#p.bind(this),{signal:n}),t}#f(e,t){t.stopPropagation(),this.#s.dispatch(`switchannotationeditorparams`,{source:this,type:C.HIGHLIGHT_COLOR,value:e}),this.updateColor(e)}_colorSelectFromKeyboard(e){if(e.target===this.#e){this.#m(e);return}let t=e.target.getAttribute(`data-color`);t&&this.#f(t,e)}_moveToNext(e){if(!this.#g){this.#m(e);return}if(e.target===this.#e){this.#r.firstElementChild?.focus();return}e.target.nextSibling?.focus()}_moveToPrevious(e){if(e.target===this.#r?.firstElementChild||e.target===this.#e){this.#g&&this._hideDropdownFromKeyboard();return}this.#g||this.#m(e),e.target.previousSibling?.focus()}_moveToBeginning(e){if(!this.#g){this.#m(e);return}this.#r.firstElementChild?.focus()}_moveToEnd(e){if(!this.#g){this.#m(e);return}this.#r.lastElementChild?.focus()}#p(t){e._keyboardManager.exec(this,t)}#m(e){if(this.#g){this.hideDropdown();return}if(this.#i=e.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener(`pointerdown`,this.#h.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#e.ariaExpanded=`true`,this.#r){this.#r.classList.remove(`hidden`);return}let t=this.#r=this.#d();this.#e.append(t)}#h(e){this.#r?.contains(e.target)||this.hideDropdown()}hideDropdown(){this.#r?.classList.add(`hidden`),this.#e.ariaExpanded=`false`,this.#c?.abort(),this.#c=null}get#g(){return this.#r&&!this.#r.classList.contains(`hidden`)}_hideDropdownFromKeyboard(){if(!this.#a){if(!this.#g){this.#o?.unselect();return}this.hideDropdown(),this.#e.focus({preventScroll:!0,focusVisible:this.#i})}}updateColor(e){if(this.#t&&(this.#t.style.backgroundColor=e),!this.#r)return;let t=this.#l.highlightColors.values();for(let n of this.#r.children)n.ariaSelected=t.next().value===e.toUpperCase()}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#r?.remove(),this.#r=null}},Qr=class e{#e=null;#t=!1;#n=null;#r=null;static#i=null;constructor(t){this.#n=t,this.#r=t._uiManager,e.#i||=Object.freeze({freetext:`pdfjs-editor-color-picker-free-text-input`,ink:`pdfjs-editor-color-picker-ink-input`})}renderButton(){if(this.#e)return this.#e;let{editorType:t,colorType:n,colorAndOpacityType:r,opacityType:i,color:a,opacity:o}=this.#n,s=this.#t=R.isAlphaColorInputSupported&&i!==void 0,c=this.#e=document.createElement(`input`);if(c.type=`color`,s){c.setAttribute(`alpha`,``);let e=z.hexNums[Math.round((o??1)*255)];c.value=(a||`#000000`)+e}else c.value=a||`#000000`;return c.className=`basicColorPicker`,c.tabIndex=0,c.setAttribute(`data-l10n-id`,e.#i[t]),c.addEventListener(`input`,()=>{if(s){let e=Le(c.value);if(!e)return;let[t,a,o,s]=e,l=z.makeHexColor(t,a,o);r===void 0?(this.#r.updateParams(n,l),this.#r.updateParams(i,s)):this.#r.updateParams(r,{color:l,opacity:s})}else this.#r.updateParams(n,c.value)},{signal:this.#r._signal}),c}update(e){if(this.#e)if(this.#t){let t=z.hexNums[Math.round(this.#n.opacity*255)];this.#e.value=e+t}else this.#e.value=e}updateOpacity(e){if(!this.#e||!this.#t)return;let t=z.hexNums[Math.round(e*255)];this.#e.value=this.#n.color+t}destroy(){this.#e?.remove(),this.#e=null}hideDropdown(){}};function $r(e){return Math.floor(V(e,0,1)*255).toString(16).padStart(2,`0`)}function ei(e){return V(e,0,1)*255}var ti=class{static CMYK_G([e,t,n,r]){return[`G`,1-Math.min(1,.3*e+.59*n+.11*t+r)]}static G_CMYK([e]){return[`CMYK`,0,0,0,1-e]}static G_RGB([e]){return[`RGB`,e,e,e]}static G_rgb([e]){return e=ei(e),[e,e,e]}static G_HTML([e]){let t=$r(e);return`#${t}${t}${t}`}static RGB_G([e,t,n]){return[`G`,.3*e+.59*t+.11*n]}static RGB_rgb(e){return e.map(ei)}static RGB_HTML(e){return`#${e.map($r).join(``)}`}static T_HTML(){return`#00000000`}static T_rgb(){return[null]}static CMYK_RGB([e,t,n,r]){return[`RGB`,1-Math.min(1,e+r),1-Math.min(1,n+r),1-Math.min(1,t+r)]}static CMYK_rgb([e,t,n,r]){return[ei(1-Math.min(1,e+r)),ei(1-Math.min(1,n+r)),ei(1-Math.min(1,t+r))]}static CMYK_HTML(e){let t=this.CMYK_RGB(e).slice(1);return this.RGB_HTML(t)}static RGB_CMYK([e,t,n]){let r=1-e,i=1-t,a=1-n;return[`CMYK`,r,i,a,Math.min(r,i,a)]}},ni=class{create(e,t,n=!1){if(e<=0||t<=0)throw Error(`Invalid SVG dimensions`);let r=this._createSVG(`svg:svg`);return r.setAttribute(`version`,`1.1`),n||(r.setAttribute(`width`,`${e}px`),r.setAttribute(`height`,`${t}px`)),r.setAttribute(`preserveAspectRatio`,`none`),r.setAttribute(`viewBox`,`0 0 ${e} ${t}`),r}createElement(e){if(typeof e!=`string`)throw Error(`Invalid SVG element type`);return this._createSVG(e)}_createSVG(e){F("Abstract method `_createSVG` called.")}},ri=class extends ni{_createSVG(e){return document.createElementNS(_,e)}},ii=9,ai=new WeakSet,oi=new Date().getTimezoneOffset()*60*1e3,si=class{static create(e){switch(e.data.annotationType){case D.LINK:return new li(e);case D.TEXT:return new ui(e);case D.WIDGET:switch(e.data.fieldType){case`Tx`:return new fi(e);case`Btn`:return e.data.radioButton?new hi(e):e.data.checkBox?new mi(e):new gi(e);case`Ch`:return new _i(e);case`Sig`:return new pi(e)}return new di(e);case D.POPUP:return new vi(e);case D.FREETEXT:return new bi(e);case D.LINE:return new xi(e);case D.SQUARE:return new Si(e);case D.CIRCLE:return new Ci(e);case D.POLYLINE:return new wi(e);case D.CARET:return new Ei(e);case D.INK:return new Di(e);case D.POLYGON:return new Ti(e);case D.HIGHLIGHT:return new Oi(e);case D.UNDERLINE:return new ki(e);case D.SQUIGGLY:return new Ai(e);case D.STRIKEOUT:return new ji(e);case D.STAMP:return new Mi(e);case D.FILEATTACHMENT:return new Ni(e);case D.RICHMEDIA:case D.SCREEN:return new Pi(e);default:return new Z(e)}}},Z=class e{#e=null;#t=!1;#n=null;constructor(e,{isRenderable:t=!1,ignoreBorder:n=!1,createQuadrilaterals:r=!1}={}){this.isRenderable=t,this.data=e.data,this.layer=e.layer,this.linkService=e.linkService,this.downloadManager=e.downloadManager,this.imageResourcesPath=e.imageResourcesPath,this.renderForms=e.renderForms,this.svgFactory=e.svgFactory,this.annotationStorage=e.annotationStorage,this.enableComment=e.enableComment,this.enableScripting=e.enableScripting,this.hasJSActions=e.hasJSActions,this._fieldObjects=e.fieldObjects,this.parent=e.parent,this.hasOwnCommentButton=!1,t&&(this.contentElement=this.container=this._createContainer(n)),r&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:e,richText:t}){return!!(e?.str||t?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return e._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){let{data:e}=this,t=this.annotationStorage?.getEditor(e.id);return t?t.getData():e}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){let e=this.annotationStorage?.getEditor(this.data.id);if(e)return e.commentButtonPositionInPage;let{quadPoints:t,inkLists:n,rect:r}=this.data,i=-1/0,a=-1/0;if(t?.length>=8){for(let e=0;e<t.length;e+=8)t[e+1]>a?(a=t[e+1],i=t[e+2]):t[e+1]===a&&(i=Math.max(i,t[e+2]));return[i,a]}if(n?.length>=1){for(let e of n)for(let t=0,n=e.length;t<n;t+=2)e[t+1]>a?(a=e[t+1],i=e[t]):e[t+1]===a&&(i=Math.max(i,e[t]));if(i!==1/0)return[i,a]}return r?[r[2],r[3]]:null}_normalizePoint(e){let{page:{view:t},viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}}=this.parent;return e[1]=t[3]-e[1]+t[1],e[0]=100*(e[0]-i)/n,e[1]=100*(e[1]-a)/r,e}get commentText(){let{data:e}=this;return this.annotationStorage.getRawValue(`${x}${e.id}`)?.popup?.contents||e.contentsObj?.str||``}set commentText(e){let{data:t}=this,n={deleted:!e,contents:e||``};this.annotationStorage.updateEditor(t.id,{popup:n})||this.annotationStorage.setValue(`${x}${t.id}`,{id:t.id,annotationType:t.annotationType,page:this.parent.page,popup:n,popupRef:t.popupRef,modificationDate:new Date}),e||this.removePopup()}removePopup(){(this.#n?.popup||this.popup)?.remove(),this.#n=this.popup=null}updateEdited(e){if(!this.container)return;e.rect&&(this.#e||={rect:this.data.rect.slice(0)});let{rect:t,popup:n}=e;t&&this.#r(t);let r=this.#n?.popup||this.popup;!r&&n?.text&&(this._createPopup(n),r=this.#n.popup),r&&(r.updateEdited(e),n?.deleted&&(r.remove(),this.#n=null,this.popup=null))}resetEdited(){this.#e&&=(this.#r(this.#e.rect),this.#n?.popup.resetEdited(),null)}#r(e){let{container:{style:t},data:{rect:n,rotation:r},parent:{viewport:{rawDims:{pageWidth:i,pageHeight:a,pageX:o,pageY:s}}}}=this;n?.splice(0,4,...e),t.left=`${100*(e[0]-o)/i}%`,t.top=`${100*(a-e[3]+s)/a}%`,r===0?(t.width=`${100*(e[2]-e[0])/i}%`,t.height=`${100*(e[3]-e[1])/a}%`):this.setRotation(r)}_createContainer(e){let{data:t,parent:{page:n,viewport:r}}=this,i=document.createElement(`section`);i.setAttribute(`data-annotation-id`,t.id),!(this instanceof di)&&!(this instanceof li)&&!(this instanceof Pi)&&(i.tabIndex=0);let{style:a}=i;if(a.zIndex=this.parent.zIndex,this.parent.zIndex+=2,t.alternativeText&&(i.title=t.alternativeText),t.noRotate&&i.classList.add(`norotate`),!t.rect||this instanceof vi){let{rotation:e}=t;return!t.hasOwnCanvas&&e!==0&&this.setRotation(e,i),i}let{width:o,height:s}=this;if(!e&&t.borderStyle.width>0){a.borderWidth=`${t.borderStyle.width}px`;let e=t.borderStyle.horizontalCornerRadius,n=t.borderStyle.verticalCornerRadius;switch((e>0||n>0)&&(a.borderRadius=`calc(${e}px * var(--total-scale-factor)) / calc(${n}px * var(--total-scale-factor))`),t.borderStyle.style){case O.SOLID:a.borderStyle=`solid`;break;case O.DASHED:a.borderStyle=`dashed`;break;case O.BEVELED:P(`Unimplemented border style: beveled`);break;case O.INSET:P(`Unimplemented border style: inset`);break;case O.UNDERLINE:a.borderBottomStyle=`solid`;break;default:break}let r=t.borderColor||null;r?(this.#t=!0,a.borderColor=z.makeHexColor(...r)):a.borderWidth=0}let c=z.normalizeRect([t.rect[0],n.view[3]-t.rect[1]+n.view[1],t.rect[2],n.view[3]-t.rect[3]+n.view[1]]),{pageWidth:l,pageHeight:u,pageX:d,pageY:f}=r.rawDims;a.left=`${100*(c[0]-d)/l}%`,a.top=`${100*(c[1]-f)/u}%`;let{rotation:p}=t;return t.hasOwnCanvas||p===0?(a.width=`${100*o/l}%`,a.height=`${100*s/u}%`):this.setRotation(p,i),i}setRotation(e,t=this.container){if(!this.data.rect)return;let{pageWidth:n,pageHeight:r}=this.parent.viewport.rawDims,{width:i,height:a}=this;e%180!=0&&([i,a]=[a,i]),t.style.width=`${100*i/n}%`,t.style.height=`${100*a/r}%`,t.setAttribute(`data-main-rotation`,(360-e)%360)}get _commonActions(){let e=(e,t,n)=>{let r=n.detail[e],i=r[0],a=r.slice(1);n.target.style[t]=ti[`${i}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[t]:ti[`${i}_rgb`](a)})};return L(this,`_commonActions`,{display:e=>{let{display:t}=e.detail,n=t%2==1;this.container.style.visibility=n?`hidden`:`visible`,this.annotationStorage.setValue(this.data.id,{noView:n,noPrint:t===1||t===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{let{hidden:t}=e.detail;this.container.style.visibility=t?`hidden`:`visible`,this.annotationStorage.setValue(this.data.id,{noPrint:t,noView:t})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:t=>{e(`bgColor`,`backgroundColor`,t)},fillColor:t=>{e(`fillColor`,`backgroundColor`,t)},fgColor:t=>{e(`fgColor`,`color`,t)},textColor:t=>{e(`textColor`,`color`,t)},borderColor:t=>{e(`borderColor`,`borderColor`,t)},strokeColor:t=>{e(`strokeColor`,`borderColor`,t)},rotation:e=>{let t=e.detail.rotation;this.setRotation(t),this.annotationStorage.setValue(this.data.id,{rotation:t})}})}_dispatchEventFromSandbox(e,t){let n=this._commonActions;for(let r of Object.keys(t.detail))(e[r]||n[r])?.(t)}_setDefaultPropertiesFromJS(e){if(!this.enableScripting)return;let t=this.annotationStorage.getRawValue(this.data.id);if(!t)return;let n=this._commonActions;for(let[r,i]of Object.entries(t)){let a=n[r];a&&(a({detail:{[r]:i},target:e}),delete t[r])}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:e}=this.data;if(!e)return;let[t,n,r,i]=this.data.rect.map(e=>Math.fround(e));if(e.length===8){let[a,o,s,c]=e.subarray(2,6);if(r===a&&i===o&&t===s&&n===c)return}let{style:a}=this.container,o;if(this.#t){let{borderColor:e,borderWidth:t}=a;a.borderWidth=0,o=[`url('data:image/svg+xml;utf8,`,`<svg xmlns="${_}" preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${e}" stroke-width="${t}">`],this.container.classList.add(`hasBorder`)}let s=r-t,c=i-n,{svgFactory:l}=this,u=l.createElement(`svg`);u.classList.add(`quadrilateralsContainer`),u.setAttribute(`width`,0),u.setAttribute(`height`,0),u.role=`none`;let d=l.createElement(`defs`);u.append(d);let f=l.createElement(`clipPath`),p=`clippath_${this.data.id}`;f.setAttribute(`id`,p),f.setAttribute(`clipPathUnits`,`objectBoundingBox`),d.append(f);for(let n=2,r=e.length;n<r;n+=8){let r=e[n],a=e[n+1],u=e[n+2],d=e[n+3],p=l.createElement(`rect`),m=(u-t)/s,h=(i-a)/c,g=(r-u)/s,_=(a-d)/c;p.setAttribute(`x`,m),p.setAttribute(`y`,h),p.setAttribute(`width`,g),p.setAttribute(`height`,_),f.append(p),o?.push(`<rect vector-effect="non-scaling-stroke" x="${m}" y="${h}" width="${g}" height="${_}"/>`)}this.#t&&(o.push(`</g></svg>')`),a.backgroundImage=o.join(``)),this.container.append(u),this.container.style.clipPath=`url(#${p})`}_createPopup(e=null){let{data:t}=this,n,r;e?(n={str:e.text},r=e.date):(n=t.contentsObj,r=t.modificationDate),this.#n=new vi({data:{color:t.color,titleObj:t.titleObj,modificationDate:r,contentsObj:n,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#n||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#n}render(){F("Abstract method `AnnotationElement.render` called")}_getElementsByName(e,t=null){let n=[];if(this._fieldObjects){let r=this._fieldObjects[e];if(r)for(let{page:e,id:i,exportValues:a}of r){if(e===-1||i===t)continue;let r=typeof a==`string`?a:null,o=document.querySelector(`[data-element-id="${i}"]`);if(o&&!ai.has(o)){P(`_getElementsByName - element not allowed: ${i}`);continue}n.push({id:i,exportValue:r,domElement:o})}return n}for(let r of document.getElementsByName(e)){let{exportValue:e}=r,i=r.getAttribute(`data-element-id`);i!==t&&ai.has(r)&&n.push({id:i,exportValue:e,domElement:r})}return n}show(){this.container&&(this.container.hidden=!1),this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0),this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){let e=this.getElementsToTriggerPopup();if(Array.isArray(e))for(let t of e)t.classList.add(`highlightArea`);else e.classList.add(`highlightArea`)}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:e,data:{id:t}}=this;this.container.addEventListener(`dblclick`,()=>{this.linkService.eventBus?.dispatch(`switchannotationeditormode`,{source:this,mode:e,editId:t,mustEnterInEditMode:!0})})}updateOC(e){!this.data.oc||!e||(e.isVisible(this.data.oc)?this.show():this.hide())}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}_setBackgroundColor(e){let t=this.data.backgroundColor||null;e.style.backgroundColor=t===null?`transparent`:z.makeHexColor(...t)}},ci=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.editor=e.editor}render(){return this.container.className=`editorAnnotation`,this.container}createOrUpdatePopup(){let{editor:e}=this;e.hasComment&&this._createPopup(e.comment)}get hasCommentButton(){return this.enableComment&&this.editor.hasComment}get commentButtonPosition(){return this.editor.commentButtonPositionInPage}get commentText(){return this.editor.comment.text}set commentText(e){this.editor.comment=e,e||this.removePopup()}get commentData(){return this.editor.getData()}remove(){this.parent.removeAnnotation(this.data.id),this.container.remove(),this.container=null,this.removePopup()}},li=class extends Z{constructor(e,t=null){super(e,{isRenderable:!0,ignoreBorder:!!t?.ignoreBorder,createQuadrilaterals:!0}),this.isTooltipOnly=e.data.isTooltipOnly}render(){let{data:e,linkService:t}=this,n=document.createElement(`a`);n.setAttribute(`data-element-id`,e.id);let r=!1;return e.url?(t.addLinkAttributes(n,e.url,e.newWindow),r=!0):e.action?(this._bindNamedAction(n,e.action,e.overlaidText),r=!0):e.attachment?(this.#t(n,e.attachmentId,e.attachment,e.overlaidText,e.attachmentDest),r=!0):e.setOCGState?(this.#n(n,e.setOCGState,e.overlaidText),r=!0):e.dest?(this._bindLink(n,e.dest,e.overlaidText),r=!0):(e.actions&&(e.actions.Action||e.actions[`Mouse Up`]||e.actions[`Mouse Down`])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(n,e),r=!0),e.resetForm?(this._bindResetFormAction(n,e.resetForm),r=!0):this.isTooltipOnly&&!r&&(this._bindLink(n,``),r=!0)),this.container.classList.add(`linkAnnotation`),r&&(this.contentElement=n,this.container.append(n)),this.container}#e(){this.container.setAttribute(`data-internal-link`,``)}_bindLink(e,t,n=``){e.href=this.linkService.getDestinationHash(t),e.onclick=()=>(t&&this.linkService.goToDestination(t),!1),(t||t===``)&&this.#e(),n&&(e.title=n)}_bindNamedAction(e,t,n=``){e.href=this.linkService.getAnchorUrl(``),e.onclick=()=>(this.linkService.executeNamedAction(t),!1),n&&(e.title=n),this.#e()}#t(e,t,n,r=``,i=null){e.href=this.linkService.getAnchorUrl(``),n.description?e.title=n.description:r&&(e.title=r);let a=async()=>{let e=await this.linkService.getAttachmentContent(t);e&&this.downloadManager?.openOrDownloadData(e,n.filename,i)};e.onclick=()=>(a(),!1),this.#e()}#n(e,t,n=``){e.href=this.linkService.getAnchorUrl(``),e.onclick=()=>(this.linkService.executeSetOCGState(t),!1),n&&(e.title=n),this.#e()}_bindJSAction(e,t){e.href=this.linkService.getAnchorUrl(``);let n=new Map([[`Action`,`onclick`],[`Mouse Up`,`onmouseup`],[`Mouse Down`,`onmousedown`]]);for(let r of Object.keys(t.actions)){let i=n.get(r);i&&(e[i]=()=>(this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t.id,name:r}}),!1))}t.overlaidText&&(e.title=t.overlaidText),e.onclick||=()=>!1,this.#e()}_bindResetFormAction(e,t){let n=e.onclick;if(n||(e.href=this.linkService.getAnchorUrl(``)),this.#e(),!this._fieldObjects){P('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),n||(e.onclick=()=>!1);return}e.onclick=()=>{n?.();let{fields:e,refs:r,include:i}=t,a=[];if(e.length!==0||r.length!==0){let t=new Set(r);for(let n of e){let e=this._fieldObjects[n]||[];for(let{id:n}of e)t.add(n)}for(let e of Object.values(this._fieldObjects))for(let n of e)t.has(n.id)===i&&a.push(n)}else for(let e of Object.values(this._fieldObjects))a.push(...e);let o=this.annotationStorage,s=[];for(let e of a){let{id:t}=e;switch(s.push(t),e.type){case`text`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}case`checkbox`:case`radiobutton`:{let n=e.defaultValue===e.exportValues;o.setValue(t,{value:n});break}case`combobox`:case`listbox`:{let n=e.defaultValue||``;o.setValue(t,{value:n});break}default:continue}let n=document.querySelector(`[data-element-id="${t}"]`);if(n){if(!ai.has(n)){P(`_bindResetFormAction - element not allowed: ${t}`);continue}n.dispatchEvent(new Event(`resetform`))}}return this.enableScripting&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:`app`,ids:s,name:`ResetForm`}}),!1}}},ui=class extends Z{constructor(e){super(e,{isRenderable:!0})}render(){this.container.classList.add(`textAnnotation`);let e=document.createElement(`img`);return e.src=this.imageResourcesPath+`annotation-`+this.data.name.toLowerCase()+`.svg`,e.setAttribute(`data-l10n-id`,`pdfjs-text-annotation-type`),e.setAttribute(`data-l10n-args`,JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(e),this.container}},di=class extends Z{render(){return this.container}_getKeyModifier(e){return R.platform.isMac?e.metaKey:e.ctrlKey}_setEventListener(e,t,n,r,i){n.includes(`mouse`)?e.addEventListener(n,e=>{this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e),shift:e.shiftKey,modifier:this._getKeyModifier(e)}})}):e.addEventListener(n,e=>{if(n===`blur`){if(!t.focused||!e.relatedTarget)return;t.focused=!1}else if(n===`focus`){if(t.focused)return;t.focused=!0}i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:this.data.id,name:r,value:i(e)}})})}_setEventListeners(e,t,n,r){for(let[i,a]of n)(a===`Action`||this.data.actions?.[a])&&((a===`Focus`||a===`Blur`)&&(t||={focused:!1}),this._setEventListener(e,t,i,a,r),a===`Focus`&&!this.data.actions?.Blur?this._setEventListener(e,t,`blur`,`Blur`,null):a===`Blur`&&!this.data.actions?.Focus&&this._setEventListener(e,t,`focus`,`Focus`,null))}_setTextStyle(e){let t=[`left`,`center`,`right`],{fontColor:n}=this.data.defaultAppearanceData,r=this.data.defaultAppearanceData.fontSize||ii,i=e.style,a,o=e=>Math.round(10*e)/10;if(this.data.multiLine){let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2),t=e/(Math.round(e/(g*r))||1);a=Math.min(r,o(t/g))}else{let e=Math.abs(this.data.rect[3]-this.data.rect[1]-2);a=Math.min(r,o(e/g))}i.fontSize=`calc(${a}px * var(--total-scale-factor))`,i.color=z.makeHexColor(...n),this.data.textAlignment!==null&&!this.data.comb&&(i.textAlign=t[this.data.textAlignment])}_setRequired(e,t){t?e.setAttribute(`required`,!0):e.removeAttribute(`required`),e.setAttribute(`aria-required`,t)}},fi=class extends di{constructor(e){let t=e.renderForms||e.data.hasOwnCanvas||!e.data.hasAppearance&&!!e.data.fieldValue;super(e,{isRenderable:t})}setPropertyOnSiblings(e,t,n,r){let i=this.annotationStorage;for(let a of this._getElementsByName(e.name,e.id))a.domElement&&(a.domElement[t]=n),i.setValue(a.id,{[r]:n})}render(){let e=this.annotationStorage,t=this.data.id;this.container.classList.add(`textWidgetAnnotation`);let n=null;if(this.renderForms){let r=e.getValue(t,{value:this.data.fieldValue}),i=r.value||``,a=e.getValue(t,{charLimit:this.data.maxLen}).charLimit;a&&i.length>a&&(i=i.slice(0,a));let o=r.formattedValue||this.data.textContent?.join(`
45
+ `)||null;o&&this.data.comb&&(o=o.replaceAll(/\s+/g,``));let s={userValue:i,formattedValue:o,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(n=document.createElement(`textarea`),n.textContent=o??i,this.data.doNotScroll&&(n.style.overflowY=`hidden`)):(n=document.createElement(`input`),n.type=this.data.password?`password`:`text`,n.setAttribute(`value`,o??i),this.data.doNotScroll&&(n.style.overflowX=`hidden`)),this.data.hasOwnCanvas&&(this.container.classList.add(`hasOwnCanvas`),e.has(t)&&this.container.classList.add(`sandboxModified`)),ai.add(n),this.contentElement=n,n.setAttribute(`data-element-id`,t),n.disabled=this.data.readOnly,n.name=this.data.fieldName,n.tabIndex=0;let{datetimeFormat:c,datetimeType:l,timeStep:u}=this.data,d=!!l&&this.enableScripting;c&&(n.title=c),this._setRequired(n,this.data.required),a&&(n.maxLength=a),n.addEventListener(`input`,r=>{e.setValue(t,{value:r.target.value}),this.setPropertyOnSiblings(n,`value`,r.target.value,`value`),s.formattedValue=null}),n.addEventListener(`resetform`,e=>{let t=this.data.defaultFieldValue??``;n.value=s.userValue=t,s.formattedValue=null});let f=e=>{let{formattedValue:t}=s;t!=null&&(e.target.value=t),e.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){n.addEventListener(`focus`,e=>{if(s.focused)return;let{target:t}=e;if(d&&(t.type=l,u&&(t.step=u)),s.userValue){let e=s.userValue;if(d)if(l===`time`){let n=new Date(e);t.value=[n.getHours(),n.getMinutes(),n.getSeconds()].map(e=>e.toString().padStart(2,`0`)).join(`:`)}else t.value=new Date(e-oi).toISOString().split(l===`date`?`T`:`.`,1)[0];else t.value=e}s.lastCommittedValue=t.value,s.commitKey=1,this.data.actions?.Focus||(s.focused=!0)}),n.addEventListener(`updatefromsandbox`,n=>{this.container.classList.add(`sandboxModified`),this._dispatchEventFromSandbox({value(n){s.userValue=n.detail.value??``,d||e.setValue(t,{value:s.userValue.toString()}),n.target.value=s.userValue},formattedValue(n){let{formattedValue:r}=n.detail;s.formattedValue=r,r!=null&&n.target!==document.activeElement&&(n.target.value=r);let i={formattedValue:r};d&&(i.value=r),e.setValue(t,i)},selRange(e){e.target.setSelectionRange(...e.detail.selRange)},charLimit:n=>{let{charLimit:r}=n.detail,{target:i}=n;if(r===0){i.removeAttribute(`maxLength`);return}i.setAttribute(`maxLength`,r);let a=s.userValue;!a||a.length<=r||(a=a.slice(0,r),i.value=s.userValue=a,e.setValue(t,{value:a}),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:a,willCommit:!0,commitKey:1,selStart:i.selectionStart,selEnd:i.selectionEnd}}))}},n)}),n.addEventListener(`keydown`,e=>{s.commitKey=1;let n=-1;if(e.key===`Escape`?n=0:e.key===`Enter`&&!this.data.multiLine?n=2:e.key===`Tab`&&(s.commitKey=3),n===-1)return;let{value:r}=e.target;s.lastCommittedValue!==r&&(s.lastCommittedValue=r,s.userValue=r,this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:r,willCommit:!0,commitKey:n,selStart:e.target.selectionStart,selEnd:e.target.selectionEnd}}))});let r=f;f=null,n.addEventListener(`blur`,e=>{if(!s.focused||!e.relatedTarget)return;this.data.actions?.Blur||(s.focused=!1);let{target:n}=e,{value:i}=n;if(d){if(i&&l===`time`){let e=i.split(`:`).map(e=>parseInt(e,10));i=new Date(2e3,0,1,e[0],e[1],e[2]||0).valueOf(),n.step=``}else i.includes(`T`)||(i=`${i}T00:00`),i=new Date(i).valueOf();n.type=`text`}s.userValue=i,s.lastCommittedValue!==i&&this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:i,willCommit:!0,commitKey:s.commitKey,selStart:e.target.selectionStart,selEnd:e.target.selectionEnd}}),r(e)}),this.data.actions?.Keystroke&&n.addEventListener(`beforeinput`,e=>{s.lastCommittedValue=null;let{data:n,target:r}=e,{value:i,selectionStart:a,selectionEnd:o}=r,c=a,l=o;switch(e.inputType){case`deleteWordBackward`:{let e=i.substring(0,a).match(/\w*\W*$/);e&&(c-=e[0].length);break}case`deleteWordForward`:{let e=i.substring(a).match(/^\W*\w*/);e&&(l+=e[0].length);break}case`deleteContentBackward`:a===o&&--c;break;case`deleteContentForward`:a===o&&(l+=1);break}e.preventDefault(),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:i,change:n||``,willCommit:!1,selStart:c,selEnd:l}})}),this._setEventListeners(n,s,[[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.value)}if(f&&n.addEventListener(`blur`,f),this.data.comb){let e=(this.data.rect[2]-this.data.rect[0])/a;n.classList.add(`comb`),n.style.setProperty(`--comb-width`,`calc(${e}px * var(--total-scale-factor))`);let t=this.data.textAlignment;if(t===1||t===2){let e=()=>{let e=a-n.value.length;n.style.setProperty(`--comb-offset`,`${t===1?e>>1:e}`)};e();for(let t of[`input`,`blur`,`resetform`,`updatefromsandbox`])n.addEventListener(t,e)}}}else n=document.createElement(`div`),n.textContent=this.data.fieldValue,n.style.verticalAlign=`middle`,n.style.display=`table-cell`,this.data.hasOwnCanvas&&(n.hidden=!0);return this._setTextStyle(n),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}},pi=class extends di{constructor(e){super(e,{isRenderable:!!e.data.hasOwnCanvas})}},mi=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.exportValue===t.fieldValue}).value;typeof r==`string`&&(r=r!==`Off`,e.setValue(n,{value:r})),this.container.classList.add(`buttonWidgetAnnotation`,`checkBox`);let i=document.createElement(`input`);return ai.add(i),i.setAttribute(`data-element-id`,n),i.disabled=t.readOnly,this._setRequired(i,this.data.required),i.type=`checkbox`,i.name=t.fieldName,r&&i.setAttribute(`checked`,!0),i.setAttribute(`exportValue`,t.exportValue),i.tabIndex=0,i.addEventListener(`change`,r=>{let{name:i,checked:a}=r.target;for(let r of this._getElementsByName(i,n)){let n=a&&r.exportValue===t.exportValue;r.domElement&&(r.domElement.checked=n),e.setValue(r.id,{value:n})}e.setValue(n,{value:a})}),i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue||`Off`;e.target.checked=n===t.exportValue}),this.enableScripting&&this.hasJSActions&&(i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value(t){t.target.checked=t.detail.value!==`Off`,e.setValue(n,{value:t.target.checked})}},t)}),this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},hi=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`buttonWidgetAnnotation`,`radioButton`);let e=this.annotationStorage,t=this.data,n=t.id,r=e.getValue(n,{value:t.buttonValue!==null&&t.fieldValue===t.buttonValue}).value;if(typeof r==`string`&&(r=r!==t.buttonValue,e.setValue(n,{value:r})),r)for(let r of this._getElementsByName(t.fieldName,n))e.setValue(r.id,{value:!1});let i=document.createElement(`input`);if(ai.add(i),i.setAttribute(`data-element-id`,n),i.disabled=t.readOnly,this._setRequired(i,this.data.required),i.type=`radio`,i.name=t.fieldName,r&&i.setAttribute(`checked`,!0),i.tabIndex=0,i.addEventListener(`change`,t=>{let{name:r,checked:i}=t.target;for(let t of this._getElementsByName(r,n))e.setValue(t.id,{value:!1});e.setValue(n,{value:i})}),i.addEventListener(`resetform`,e=>{let n=t.defaultFieldValue;e.target.checked=n!=null&&n===t.buttonValue}),this.enableScripting&&this.hasJSActions){let r=t.buttonValue;i.addEventListener(`updatefromsandbox`,t=>{this._dispatchEventFromSandbox({value:t=>{let i=r===t.detail.value;for(let r of this._getElementsByName(t.target.name)){let t=i&&r.id===n;r.domElement&&(r.domElement.checked=t),e.setValue(r.id,{value:t})}}},t)}),this._setEventListeners(i,null,[[`change`,`Validate`],[`change`,`Action`],[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`]],e=>e.target.checked)}return this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},gi=class extends li{constructor(e){super(e,{ignoreBorder:e.data.hasAppearance})}render(){let e=super.render();e.classList.add(`buttonWidgetAnnotation`,`pushButton`);let t=e.lastChild;return this.enableScripting&&this.hasJSActions&&t&&(this._setDefaultPropertiesFromJS(t),t.addEventListener(`updatefromsandbox`,e=>{this._dispatchEventFromSandbox({},e)})),e}},_i=class extends di{constructor(e){super(e,{isRenderable:e.renderForms})}render(){this.container.classList.add(`choiceWidgetAnnotation`);let e=this.annotationStorage,t=this.data.id,n=e.getValue(t,{value:this.data.fieldValue}),r=document.createElement(`select`);ai.add(r),r.setAttribute(`data-element-id`,t),r.disabled=this.data.readOnly,this._setRequired(r,this.data.required),r.name=this.data.fieldName,r.tabIndex=0;let i=this.data.combo&&this.data.options.length>0;this.data.combo||(r.size=this.data.options.length,this.data.multiSelect&&(r.multiple=!0)),r.addEventListener(`resetform`,e=>{let t=this.data.defaultFieldValue;for(let e of r.options)e.selected=e.value===t});let a=(e,t)=>{let n=t.replaceAll(` `,`\xA0`);e.textContent=n,n!==t&&e.setAttribute(`display-value`,t)};for(let e of this.data.options){let t=document.createElement(`option`);a(t,e.displayValue),t.value=e.exportValue,n.value.includes(e.exportValue)&&(t.setAttribute(`selected`,!0),i=!1),r.append(t)}let o=null;if(i){let e=document.createElement(`option`);e.value=` `,e.setAttribute(`hidden`,!0),e.setAttribute(`selected`,!0),r.prepend(e),o=()=>{e.remove(),r.removeEventListener(`input`,o),o=null},r.addEventListener(`input`,o)}let s=e=>{let t=e?`value`:`textContent`,{options:n,multiple:i}=r;return i?Array.prototype.filter.call(n,e=>e.selected).map(e=>e[t]):n.selectedIndex===-1?null:n[n.selectedIndex][t]},c=s(!1),l=e=>{let t=e.target.options;return Array.prototype.map.call(t,e=>({displayValue:e.getAttribute(`display-value`)||e.textContent,exportValue:e.value}))};return this.enableScripting&&this.hasJSActions?(r.addEventListener(`updatefromsandbox`,n=>{this._dispatchEventFromSandbox({value(n){o?.();let i=n.detail.value,a=new Set(Array.isArray(i)?i:[i]);for(let e of r.options)e.selected=a.has(e.value);e.setValue(t,{value:s(!0)}),c=s(!1)},multipleSelection(e){r.multiple=!0},remove(n){let i=r.options,a=n.detail.remove;i[a].selected=!1,r.remove(a),i.length>0&&Array.prototype.findIndex.call(i,e=>e.selected)===-1&&(i[0].selected=!0),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},clear(n){for(;r.length!==0;)r.remove(0);e.setValue(t,{value:null,items:[]}),c=s(!1)},insert(n){let{index:i,displayValue:o,exportValue:u}=n.detail.insert,d=r.children[i],f=document.createElement(`option`);a(f,o),f.value=u,d?d.before(f):r.append(f),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},items(n){let{items:i}=n.detail;for(;r.length!==0;)r.remove(0);for(let e of i){let{displayValue:t,exportValue:n}=e,i=document.createElement(`option`);a(i,t),i.value=n,r.append(i)}r.options.length>0&&(r.options[0].selected=!0),e.setValue(t,{value:s(!0),items:l(n)}),c=s(!1)},indices(n){let r=new Set(n.detail.indices);for(let e of n.target.options)e.selected=r.has(e.index);e.setValue(t,{value:s(!0)}),c=s(!1)},editable(e){e.target.disabled=!e.detail.editable}},n)}),r.addEventListener(`input`,n=>{let r=s(!0),i=s(!1);e.setValue(t,{value:r}),n.preventDefault(),this.linkService.eventBus?.dispatch(`dispatcheventinsandbox`,{source:this,detail:{id:t,name:`Keystroke`,value:c,change:i,changeEx:r,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(r,null,[[`focus`,`Focus`],[`blur`,`Blur`],[`mousedown`,`Mouse Down`],[`mouseenter`,`Mouse Enter`],[`mouseleave`,`Mouse Exit`],[`mouseup`,`Mouse Up`],[`input`,`Action`],[`input`,`Validate`]],e=>e.target.value)):r.addEventListener(`input`,function(n){e.setValue(t,{value:s(!0)})}),this.data.combo&&this._setTextStyle(r),this._setBackgroundColor(r),this._setDefaultPropertiesFromJS(r),this.container.append(r),this.container}},vi=class extends Z{constructor(e){let{data:t,elements:n,parent:r}=e,i=!!r._commentManager;if(super(e,{isRenderable:!i&&Z._hasPopupData(t)}),this.elements=n,i&&Z._hasPopupData(t)){let e=this.popup=this.#e();for(let t of n)t.popup=e}else this.popup=null}#e(){return new yi({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){let{container:e}=this;e.classList.add(`popupAnnotation`),e.role=`comment`;let t=this.popup=this.#e(),n=[];for(let e of this.elements)e.popup=t,e.container.ariaHasPopup=`dialog`,n.push(e.data.id),e.addHighlightArea();return this.container.setAttribute(`aria-controls`,n.map(e=>`${b}${e}`).join(`,`)),this.container}},yi=class{#e=null;#t=this.#P.bind(this);#n=this.#R.bind(this);#r=this.#L.bind(this);#i=this.#I.bind(this);#a=null;#o=null;#s=null;#c=null;#l=null;#u=null;#d=null;#f=!1;#p=null;#m=null;#h=null;#g=null;#_=null;#v=null;#y=null;#b=null;#x=null;#S=null;#C=!1;#w=null;#T=null;constructor({container:e,color:t,elements:n,titleObj:r,modificationDate:i,contentsObj:a,richText:o,parent:s,rect:c,parentRect:l,open:u,commentManager:d=null}){this.#o=e,this.#x=r,this.#s=a,this.#b=o,this.#u=s,this.#a=t,this.#y=c,this.#d=l,this.#l=n,this.#e=d,this.#w=n[0],this.#c=Ie.toDateObject(i),this.trigger=n.flatMap(e=>e.getElementsToTriggerPopup()),d||(this.#E(),this.#o.hidden=!0,u&&this.#I())}#E(){if(this.#m)return;this.#m=new AbortController;let{signal:e}=this.#m;for(let t of this.trigger)t.addEventListener(`click`,this.#i,{signal:e}),t.addEventListener(`pointerenter`,this.#r,{signal:e}),t.addEventListener(`pointerleave`,this.#n,{signal:e}),t.classList.add(`popupTriggerArea`);for(let t of this.#l)t.container?.addEventListener(`keydown`,this.#t,{signal:e})}#D(){let e=this.#l.find(e=>e.hasCommentButton);e&&(this.#_=e._normalizePoint(e.commentButtonPosition))}renderCommentButton(){if(this.#g){this.#g.parentNode||this.#w.container.after(this.#g);return}if(this.#_||this.#D(),!this.#_)return;let{signal:e}=this.#m=new AbortController,t=this.#w.hasOwnCommentButton,n=()=>{this.#e.toggleCommentPopup(this,!0,void 0,!t)},r=()=>{this.#e.toggleCommentPopup(this,!1,!0,!t)},i=()=>{this.#e.toggleCommentPopup(this,!1,!1)};if(t){this.#g=this.#w.container;for(let t of this.trigger)t.ariaHasPopup=`dialog`,t.ariaControls=`commentPopup`,t.addEventListener(`keydown`,this.#t,{signal:e}),t.addEventListener(`click`,n,{signal:e}),t.addEventListener(`pointerenter`,r,{signal:e}),t.addEventListener(`pointerleave`,i,{signal:e}),t.classList.add(`popupTriggerArea`)}else{let t=this.#g=document.createElement(`button`);t.className=`annotationCommentButton`;let a=this.#w.container;t.style.zIndex=parseInt(a.style.zIndex,10)+1,t.tabIndex=0,t.ariaHasPopup=`dialog`,t.ariaControls=`commentPopup`,t.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`),this.#k(),this.#O(),t.addEventListener(`keydown`,this.#t,{signal:e}),t.addEventListener(`click`,n,{signal:e}),t.addEventListener(`pointerenter`,r,{signal:e}),t.addEventListener(`pointerleave`,i,{signal:e}),a.after(t)}}#O(){if(this.#w.extraPopupElement&&!this.#w.editor)return;this.#g||this.renderCommentButton();let[e,t]=this.#_,{style:n}=this.#g;n.left=`calc(${e}%)`,n.top=`calc(${t}% - var(--comment-button-dim))`}#k(){this.#w.extraPopupElement||(this.#g||this.renderCommentButton(),this.#g.style.backgroundColor=this.commentButtonColor||``)}get commentButtonColor(){let{color:e,opacity:t}=this.#w.commentData;return e?this.#u._commentManager.makeCommentColor(e,t):null}focusCommentButton(){setTimeout(()=>{this.#g?.focus()},0)}getData(){let{richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}=this.#w.commentData;return{contentsObj:{str:this.comment},richText:e,color:t,opacity:n,creationDate:r,modificationDate:i}}get elementBeforePopup(){return this.#g}get comment(){return this.#T||=this.#w.commentText,this.#T}set comment(e){e!==this.comment&&(this.#w.commentText=this.#T=e)}focus(){this.#w.container?.focus()}get parentBoundingClientRect(){return this.#w.layer.getBoundingClientRect()}setCommentButtonStates({selected:e,hasPopup:t}){this.#g&&(this.#g.classList.toggle(`selected`,e),this.#g.ariaExpanded=t)}setSelectedCommentButton(e){this.#g.classList.toggle(`selected`,e)}get commentPopupPosition(){if(this.#v)return this.#v;let{x:e,y:t,height:n}=this.#g.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#w.layer.getBoundingClientRect();return[(e-r)/a,(t+n-i)/o]}set commentPopupPosition(e){this.#v=e}hasDefaultPopupPosition(){return this.#v===null}get commentButtonPosition(){return this.#_}get commentButtonWidth(){return this.#g.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(e){let[t,n]=this.#v||this.commentButtonPosition.map(e=>e/100),r=this.parentBoundingClientRect,{x:i,y:a,width:o,height:s}=r;this.#e.showDialog(null,this,i+t*o,a+n*s,{...e,parentDimensions:r})}render(){if(this.#p)return;let e=this.#p=document.createElement(`div`);if(e.className=`popup`,this.#a){let t=e.style.outlineColor=z.makeHexColor(...this.#a);e.style.backgroundColor=`color-mix(in srgb, ${t} 30%, white)`}let t=document.createElement(`span`);if(t.className=`header`,this.#x?.str){let e=document.createElement(`span`);e.className=`title`,t.append(e),{dir:e.dir,str:e.textContent}=this.#x}if(e.append(t),this.#c){let e=document.createElement(`time`);e.className=`popupDate`,e.setAttribute(`data-l10n-id`,`pdfjs-annotation-date-time-string`),e.setAttribute(`data-l10n-args`,JSON.stringify({dateObj:this.#c.valueOf()})),e.dateTime=this.#c.toISOString(),t.append(e)}$e({html:this.#A||this.#s.str,dir:this.#s?.dir,className:`popupContent`},e),this.#o.append(e)}get#A(){let e=this.#b,t=this.#s;return e?.str&&(!t?.str||t.str===e.str)&&this.#b.html||null}get#j(){return this.#A?.attributes?.style?.fontSize||0}get#M(){return this.#A?.attributes?.style?.color||null}#N(e){let t=[],n={str:e,html:{name:`div`,attributes:{dir:`auto`},children:[{name:`p`,children:t}]}},r={style:{color:this.#M,fontSize:this.#j?`calc(${this.#j}px * var(--total-scale-factor))`:``}};for(let n of e.split(`
46
+ `))t.push({name:`span`,value:n,attributes:r});return n}#P(e){e.altKey||e.shiftKey||e.ctrlKey||e.metaKey||(e.key===`Enter`||e.key===`Escape`&&this.#f)&&this.#I()}updateEdited({rect:e,popup:t,deleted:n}){if(this.#e){n?(this.remove(),this.#T=null):t&&(t.deleted?this.remove():(this.#k(),this.#T=t.text)),e&&(this.#_=null,this.#D(),this.#O());return}if(n||t?.deleted){this.remove();return}this.#E(),this.#S||={contentsObj:this.#s,richText:this.#b},e&&(this.#h=null),t&&t.text&&(this.#b=this.#N(t.text),this.#c=Ie.toDateObject(t.date),this.#s=null),this.#p?.remove(),this.#p=null}resetEdited(){this.#S&&({contentsObj:this.#s,richText:this.#b}=this.#S,this.#S=null,this.#p?.remove(),this.#p=null,this.#h=null)}remove(){if(this.#m?.abort(),this.#m=null,this.#p?.remove(),this.#p=null,this.#C=!1,this.#f=!1,this.#g?.remove(),this.#g=null,this.trigger)for(let e of this.trigger)e.classList.remove(`popupTriggerArea`)}#F(){if(this.#h!==null)return;let{page:{view:e},viewport:{rawDims:{pageWidth:t,pageHeight:n,pageX:r,pageY:i}}}=this.#u,a=!!this.#d,o=a?this.#d:this.#y;for(let e of this.#l)if(!o||z.intersect(e.data.rect,o)!==null){o=e.data.rect,a=!0;break}let s=z.normalizeRect([o[0],e[3]-o[1]+e[1],o[2],e[3]-o[3]+e[1]]),c=a?o[2]-o[0]+5:0,l=s[0]+c,u=s[1];this.#h=[100*(l-r)/t,100*(u-i)/n];let{style:d}=this.#o;d.left=`${this.#h[0]}%`,d.top=`${this.#h[1]}%`}#I(){if(this.#e){this.#e.toggleCommentPopup(this,!1);return}this.#f=!this.#f,this.#f?(this.#L(),this.#o.addEventListener(`click`,this.#i),this.#o.addEventListener(`keydown`,this.#t)):(this.#R(),this.#o.removeEventListener(`click`,this.#i),this.#o.removeEventListener(`keydown`,this.#t))}#L(){this.#p||this.render(),this.isVisible?this.#f&&this.#o.classList.add(`focused`):(this.#F(),this.#o.hidden=!1,this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)+1e3)}#R(){this.#o.classList.remove(`focused`),!(this.#f||!this.isVisible)&&(this.#o.hidden=!0,this.#o.style.zIndex=parseInt(this.#o.style.zIndex,10)-1e3)}forceHide(){this.#C=this.isVisible,this.#C&&(this.#o.hidden=!0)}maybeShow(){this.#e||(this.#E(),this.#C&&(this.#p||this.#L(),this.#C=!1,this.#o.hidden=!1))}get isVisible(){return!this.#e&&this.#o.hidden===!1}},bi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.textContent=e.data.textContent,this.textPosition=e.data.textPosition,this.annotationEditorType=S.FREETEXT}render(){if(this.container.classList.add(`freeTextAnnotation`),this.textContent){let e=this.contentElement=document.createElement(`div`);e.classList.add(`annotationTextContent`),e.setAttribute(`role`,`comment`);for(let t of this.textContent){let n=document.createElement(`span`);n.textContent=t,e.append(n)}this.container.append(e)}return!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},xi=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`lineAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=this.#e=this.svgFactory.createElement(`svg:line`);return i.setAttribute(`x1`,e.rect[2]-e.lineCoordinates[0]),i.setAttribute(`y1`,e.rect[3]-e.lineCoordinates[1]),i.setAttribute(`x2`,e.rect[2]-e.lineCoordinates[2]),i.setAttribute(`y2`,e.rect[3]-e.lineCoordinates[3]),i.setAttribute(`stroke-width`,e.borderStyle.width||1),i.setAttribute(`stroke`,`transparent`),i.setAttribute(`fill`,`transparent`),r.append(i),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Si=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`squareAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=e.borderStyle.width,a=this.#e=this.svgFactory.createElement(`svg:rect`);return a.setAttribute(`x`,i/2),a.setAttribute(`y`,i/2),a.setAttribute(`width`,t-i),a.setAttribute(`height`,n-i),a.setAttribute(`stroke-width`,i||1),a.setAttribute(`stroke`,`transparent`),a.setAttribute(`fill`,`transparent`),r.append(a),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Ci=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add(`circleAnnotation`);let{data:e,width:t,height:n}=this,r=this.svgFactory.create(t,n,!0),i=e.borderStyle.width,a=this.#e=this.svgFactory.createElement(`svg:ellipse`);return a.setAttribute(`cx`,t/2),a.setAttribute(`cy`,n/2),a.setAttribute(`rx`,t/2-i/2),a.setAttribute(`ry`,n/2-i/2),a.setAttribute(`stroke-width`,i||1),a.setAttribute(`stroke`,`transparent`),a.setAttribute(`fill`,`transparent`),r.append(a),this.container.append(r),!e.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},wi=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName=`polylineAnnotation`,this.svgElementName=`svg:polyline`}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,vertices:t,borderStyle:n,popupRef:r},width:i,height:a}=this;if(!t)return this.container;let o=this.svgFactory.create(i,a,!0),s=[];for(let n=0,r=t.length;n<r;n+=2){let r=t[n]-e[0],i=e[3]-t[n+1];s.push(`${r},${i}`)}s=s.join(` `);let c=this.#e=this.svgFactory.createElement(this.svgElementName);return c.setAttribute(`points`,s),c.setAttribute(`stroke-width`,n.width||1),c.setAttribute(`stroke`,`transparent`),c.setAttribute(`fill`,`transparent`),o.append(c),this.container.append(o),!r&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Ti=class extends wi{constructor(e){super(e),this.containerClassName=`polygonAnnotation`,this.svgElementName=`svg:polygon`}},Ei=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add(`caretAnnotation`),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}},Di=class extends Z{#e=null;#t=[];constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName=`inkAnnotation`,this.svgElementName=`svg:polyline`,this.annotationEditorType=this.data.it===`InkHighlight`?S.HIGHLIGHT:S.INK}#n(e,t){switch(e){case 90:return{transform:`rotate(90) translate(${-t[0]},${t[1]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};case 180:return{transform:`rotate(180) translate(${-t[2]},${t[1]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]};case 270:return{transform:`rotate(270) translate(${-t[2]},${t[3]}) scale(1,-1)`,width:t[3]-t[1],height:t[2]-t[0]};default:return{transform:`translate(${-t[0]},${t[3]}) scale(1,-1)`,width:t[2]-t[0],height:t[3]-t[1]}}}render(){this.container.classList.add(this.containerClassName);let{data:{rect:e,rotation:t,inkLists:n,borderStyle:r,popupRef:i}}=this,{transform:a,width:o,height:s}=this.#n(t,e),c=this.svgFactory.create(o,s,!0),l=this.#e=this.svgFactory.createElement(`svg:g`);c.append(l),l.setAttribute(`stroke-width`,r.width||1),l.setAttribute(`stroke-linecap`,`round`),l.setAttribute(`stroke-linejoin`,`round`),l.setAttribute(`stroke-miterlimit`,10),l.setAttribute(`stroke`,`transparent`),l.setAttribute(`fill`,`transparent`),l.setAttribute(`transform`,a);for(let e=0,t=n.length;e<t;e++){let t=this.svgFactory.createElement(this.svgElementName);this.#t.push(t),t.setAttribute(`points`,n[e].join(`,`)),l.append(t)}return!i&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(c),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);let{thickness:t,points:n,rect:r}=e,i=this.#e;if(t>=0&&i.setAttribute(`stroke-width`,t||1),n)for(let e=0,t=this.#t.length;e<t;e++)this.#t[e].setAttribute(`points`,n[e].join(`,`));if(r){let{transform:e,width:t,height:n}=this.#n(this.data.rotation,r);i.parentElement.setAttribute(`viewBox`,`0 0 ${t} ${n}`),i.setAttribute(`transform`,e)}}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add(`highlightArea`)}},Oi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=S.HIGHLIGHT}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`highlightAnnotation`),this._editOnDoubleClick(),e){let t=document.createElement(`mark`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},ki=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`underlineAnnotation`),e){let t=document.createElement(`u`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},Ai=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`squigglyAnnotation`),e){let t=document.createElement(`u`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},ji=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){let{data:{overlaidText:e,popupRef:t}}=this;if(!t&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add(`strikeoutAnnotation`),e){let t=document.createElement(`s`);t.classList.add(`overlaidText`),t.textContent=e,this.container.append(t)}return this.container}},Mi=class extends Z{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=S.STAMP}render(){return this.container.classList.add(`stampAnnotation`),this.container.setAttribute(`role`,`img`),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},Ni=class extends Z{#e=null;constructor(e){super(e,{isRenderable:!0});let{fileId:t,file:n}=this.data;this.filename=n.filename,this.content=n.content,this.fileId=t,this.linkService.eventBus?.dispatch(`fileattachmentannotation`,{source:this,attachmentId:this.fileId,...n})}render(){this.container.classList.add(`fileAttachmentAnnotation`);let{container:e,data:t}=this,n;t.hasAppearance||t.fillAlpha===0?n=document.createElement(`div`):(n=document.createElement(`img`),n.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(t.name)?`paperclip`:`pushpin`}.svg`,t.fillAlpha&&t.fillAlpha<1&&(n.style=`filter: opacity(${Math.round(t.fillAlpha*100)}%);`)),n.addEventListener(`dblclick`,this.#t.bind(this)),this.#e=n;let{isMac:r}=R.platform;return e.addEventListener(`keydown`,e=>{e.key===`Enter`&&(r?e.metaKey:e.ctrlKey)&&this.#t()}),!t.popupRef&&this.hasPopupData?(this.hasOwnCommentButton=!0,this._createPopup()):n.classList.add(`popupTriggerArea`),e.append(n),e}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add(`highlightArea`)}async#t(){let{fileId:e,filename:t,content:n}=this,r=await this.linkService.getAttachmentContent(e)||n;r&&this.downloadManager?.openOrDownloadData(r,t)}},Pi=class extends Z{#e=new AbortController;#t=null;#n=null;constructor(e){super(e,{isRenderable:!!e.data.richMedia})}render(){this.container.classList.add(`mediaAnnotation`);let{filename:e}=this.data.richMedia,t=document.createElement(`button`);return t.className=`mediaPlayButton`,t.type=`button`,t.title=t.ariaLabel=e,t.addEventListener(`click`,()=>this.#r(t),{signal:this.#e.signal}),this.container.append(t),this.container}async#r(e){let{fileId:t,filename:n,contentType:r}=this.data.richMedia;e.disabled=!0;let i;try{i=await this.linkService.getAttachmentContent(t)}catch{return}finally{e.disabled=!1}if(!i||!e.isConnected)return;let{signal:a}=this.#e,o=URL.createObjectURL(new Blob([i],{type:r}));this.#t=o;let s=r.startsWith(`audio/`),c=document.createElement(s?`audio`:`video`);if(this.#n=c,c.className=`mediaContent`,this._setBackgroundColor(c),c.src=o,c.title=n,c.controls=!0,c.autoplay=!0,c.tabIndex=0,s){let e=!1,t=!1,n=()=>{c.controls=e||t};this.container.addEventListener(`pointerenter`,()=>{e=!0,n()},{signal:a}),this.container.addEventListener(`pointerleave`,()=>{e=!1,n()},{signal:a}),this.container.addEventListener(`focusin`,()=>{t=!0,n()},{signal:a}),this.container.addEventListener(`focusout`,()=>{t=!1,n()},{signal:a})}c.addEventListener(`emptied`,()=>this.#i(o),{once:!0,signal:a}),e.replaceWith(c),c.play().catch(()=>{})}#i(e=this.#t){e&&e===this.#t&&(URL.revokeObjectURL(e),this.#t=null)}destroy(){this.#e.abort(),this.#n&&=(this.#n.pause(),this.#n.removeAttribute(`src`),this.#n.load(),null),this.#i()}},Fi=class e{#e=null;#t=null;#n=null;#r=new Map;#i=null;#a=null;#o=[];#s=!1;zIndex=0;constructor({div:e,accessibilityManager:t,annotationCanvasMap:n,annotationEditorUIManager:r,page:i,viewport:a,structTreeLayer:o,commentManager:s,linkService:c,annotationStorage:l}){this.div=e,this.#e=t,this.#t=n,this.#i=o||null,this.#a=c||null,this.#n=l||new bt,this.page=i,this.viewport=a,this._annotationEditorUIManager=r,this._commentManager=s||null}hasEditableAnnotations(){return this.#r.size>0}async render(e){let{annotations:t,optionalContentConfig:n}=e,r=this.div;Ve(r,this.viewport);let i=new Map,a=[],o={data:null,layer:r,linkService:this.#a,downloadManager:e.downloadManager,imageResourcesPath:e.imageResourcesPath||``,renderForms:e.renderForms!==!1,svgFactory:new ri,annotationStorage:this.#n,enableComment:e.enableComment===!0,enableScripting:e.enableScripting===!0,hasJSActions:e.hasJSActions,fieldObjects:e.fieldObjects,parent:this,elements:null};for(let e of t){if(e.noHTML)continue;let t=e.annotationType===D.POPUP;if(t){let t=i.get(e.id);if(!t)continue;if(!this._commentManager){a.push(e);continue}o.elements=t}else if(e.rect[2]===e.rect[0]||e.rect[3]===e.rect[1])continue;o.data=e;let r=si.create(o);if(!r.isRenderable)continue;t||(this.#o.push(r),e.popupRef&&i.getOrInsertComputed(e.popupRef,xe).push(r));let s=r.render();e.hidden&&(s.style.visibility=`hidden`),r.updateOC(n),r._isEditable&&(this.#r.set(r.data.id,r),this._annotationEditorUIManager?.renderAnnotationElement(r))}await this.#c();for(let e of a){let t=o.elements=i.get(e.id);o.data=e;let n=si.create(o);if(!n.isRenderable)continue;let r=n.render();n.contentElement.id=`${b}${e.id}`,e.hidden&&(r.style.visibility=`hidden`),t.at(-1).container.after(r)}this.#l()}async#c(){if(this.#o.length===0)return;this.div.replaceChildren();let e=[];if(!this.#s){this.#s=!0;for(let{contentElement:t,data:{id:n}}of this.#o){let r=t.id=`${b}${n}`;e.push(this.#i?.getAriaAttributes(r).then(e=>{if(e)for(let[n,r]of e)t.setAttribute(n,r)}))}}this.#o.sort(({data:{rect:[e,t,n,r]}},{data:{rect:[i,a,o,s]}})=>{if(e===n&&t===r)return 1;if(i===o&&a===s)return-1;let c=r,l=t,u=(t+r)/2,d=s,f=a,p=(a+s)/2;return u>=d&&p<=l?-1:p>=c&&u<=f?1:(e+n)/2-(i+o)/2});let t=document.createDocumentFragment();for(let e of this.#o)t.append(e.container),this._commentManager?(e.extraPopupElement?.popup||e.popup)?.renderCommentButton():e.extraPopupElement&&t.append(e.extraPopupElement.render());if(this.div.append(t),await Promise.all(e),this.#e)for(let e of this.#o)this.#e.addPointerInTextLayer(e.contentElement,!1)}async addLinkAnnotations(t){let n={data:null,layer:this.div,linkService:this.#a,svgFactory:new ri,parent:this};for(let r of t){r.borderStyle||=e._defaultBorderStyle,n.data=r;let t=si.create(n);t.isRenderable&&(t.render(),t.contentElement.id=`${b}${r.id}`,this.#o.push(t))}await this.#c()}update({viewport:e,optionalContentConfig:t}){let n=this.div;this.viewport=e,Ve(n,{rotation:e.rotation});for(let e of this.#o)e.updateOC(t);this.#l(),n.hidden=!1}destroy(){for(let e of this.#o)e.destroy?.(),this.#e?.removePointerInTextLayer(e.contentElement);this.#o.length=0,this.#r.clear(),this.div.replaceChildren()}#l(){if(!this.#t)return;let e=this.div;for(let[t,n]of this.#t){let r=e.querySelector(`[data-annotation-id="${t}"]`);if(!r)continue;if(Array.isArray(n))for(let e of n)e.className=`annotationContent`,e.ariaHidden=!0;else n.className=`annotationContent`,n.ariaHidden=!0;let i=[];for(let e of r.children)e.nodeName===`CANVAS`&&i.push(e);for(let e of i)e.remove();let a=Array.isArray(n)?n[0]:n,{firstChild:o}=r;if(o?o.classList.contains(`annotationContent`)?o.after(a):o.before(a):r.append(a),Array.isArray(n)){let e=a;for(let t=1,r=n.length;t<r;t++)e.after(n[t]),e=n[t]}this.#t.delete(t);let s=this.#r.get(t);s&&(s._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(t,r.id,n),s._hasNoCanvas=!1):s.canvas=n)}}refreshCanvases(){this.#l()}getEditableAnnotations(){return this.#r.values()}getEditableAnnotation(e){return this.#r.get(e)}addFakeAnnotation(e){let{div:t}=this,{id:n,rotation:r}=e,i=new ci({data:{id:n,rect:e.getPDFRect(),rotation:r},editor:e,layer:t,parent:this,enableComment:!!this._commentManager,linkService:this.#a,annotationStorage:this.#n});return i.render(),i.contentElement.id=`${b}${n}`,i.createOrUpdatePopup(),this.#o.push(i),i}removeAnnotation(e){let t=this.#o.findIndex(t=>t.data.id===e);if(t<0)return;let[n]=this.#o.splice(t,1);this.#e?.removePointerInTextLayer(n.contentElement)}updateFakeAnnotations(e){if(e.length!==0){for(let t of e)t.updateFakeAnnotationElement(this);this.#c()}}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}static get _defaultBorderStyle(){return L(this,`_defaultBorderStyle`,Object.freeze({width:1,rawWidth:1,style:O.SOLID,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}},Ii=/\r\n?|\n/g,Li=class e extends K{#e=``;#t=`${this.id}-editor`;#n=null;#r;_colorPicker=null;static _freeTextDefaultContent=``;static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.isEmpty(),r=ut.TRANSLATE_SMALL,i=ut.TRANSLATE_BIG;return L(this,`_keyboardManager`,new ct([[[`ctrl+s`,`mac+meta+s`,`ctrl+p`,`mac+meta+p`],t.commitOrRemove,{bubbles:!0}],[[`ctrl+Enter`,`mac+meta+Enter`],t.commitOrRemove],[[`Escape`],t.commitOrRemove],[[`ArrowLeft`],t._translateEmpty,{args:[-r,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t._translateEmpty,{args:[-i,0],checker:n}],[[`ArrowRight`],t._translateEmpty,{args:[r,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t._translateEmpty,{args:[i,0],checker:n}],[[`ArrowUp`],t._translateEmpty,{args:[0,-r],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t._translateEmpty,{args:[0,-i],checker:n}],[[`ArrowDown`],t._translateEmpty,{args:[0,r],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t._translateEmpty,{args:[0,i],checker:n}]]))}static _type=`freetext`;static _editorType=S.FREETEXT;constructor(t){super({...t,name:`freeTextEditor`}),this.color=t.color||e._defaultColor||K._defaultLineColor,this.#r=t.fontSize||e._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.freetext),this.canAddComment=!1}static initialize(e,t){K.initialize(e,t);let n=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(n.getPropertyValue(`--freetext-padding`))}static updateDefaultParams(t,n){switch(t){case C.FREETEXT_SIZE:e._defaultFontSize=n;break;case C.FREETEXT_COLOR:e._defaultColor=n;break}}updateParams(e,t){switch(e){case C.FREETEXT_SIZE:this.#i(t);break;case C.FREETEXT_COLOR:this.#a(t);break}}static get defaultPropertiesToUpdate(){return[[C.FREETEXT_SIZE,e._defaultFontSize],[C.FREETEXT_COLOR,e._defaultColor||K._defaultLineColor]]}get propertiesToUpdate(){return[[C.FREETEXT_SIZE,this.#r],[C.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new Qr(this),[[`colorPicker`,this._colorPicker]]}get colorType(){return C.FREETEXT_COLOR}#i(e){let t=e=>{this.editorDiv.style.fontSize=`calc(${e}px * var(--total-scale-factor))`,this.translate(0,-(e-this.#r)*this.parentScale),this.#r=e,this.#s()},n=this.#r;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#a(e){let t=e=>{this.color=e,this.onUpdatedColor()},n=this.color;this.addCommands({cmd:t.bind(this,e),undo:t.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(e,t){this._uiManager.translateSelectedEditors(e,t,!0)}getInitialTranslation(){let t=this.parentScale;return[-e._internalPadding*t,-(e._internalPadding+this.#r)*t]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove(`enabled`),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute(`aria-activedescendant`),this.#n=new AbortController;let e=this._uiManager.combinedSignal(this.#n);return this.editorDiv.addEventListener(`keydown`,this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener(`focus`,this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener(`blur`,this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener(`input`,this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener(`paste`,this.editorDivPaste.bind(this),{signal:e}),!0}disableEditMode(){return super.disableEditMode()?(this.overlayDiv.classList.add(`enabled`),this.editorDiv.contentEditable=!1,this.div.setAttribute(`aria-activedescendant`,this.#t),this._isDraggable=!0,this.#n?.abort(),this.#n=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add(`freetextEditing`),!0):!1}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),this._initialOptions?.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===``}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add(`freetextEditing`)),super.remove()}#o(){let t=[];this.editorDiv.normalize();let n=null;for(let r of this.editorDiv.childNodes)n?.nodeType===Node.TEXT_NODE&&r.nodeName===`BR`||(t.push(e.#c(r)),n=r);return t.join(`
47
47
  `)}#s(){let[e,t]=this.parentDimensions,n;if(this.isAttachedToDOM)n=this.div.getBoundingClientRect();else{let{currentLayer:e,div:t}=this,r=t.style.display,i=t.classList.contains(`hidden`);t.classList.remove(`hidden`),t.style.display=`hidden`,e.div.append(this.div),n=t.getBoundingClientRect(),t.remove(),t.style.display=r,t.classList.toggle(`hidden`,i)}this.rotation%180==this.parentRotation%180?(this.width=n.width/e,this.height=n.height/t):(this.width=n.height/e,this.height=n.width/t),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();let e=this.#e,t=this.#e=this.#o().trimEnd();if(e===t)return;let n=e=>{if(this.#e=e,!e){this.remove();return}this.#l(),this._uiManager.rebuild(this),this.#s()};this.addCommands({cmd:()=>{n(t)},undo:()=>{n(e)},mustExec:!1}),this.#s()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}keydown(e){e.target===this.div&&e.key===`Enter`&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(t){e._keyboardManager.exec(this,t)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle(`freetextEditing`,this.isEmpty())}disableEditing(){this.editorDiv.setAttribute(`role`,`comment`),this.editorDiv.removeAttribute(`aria-multiline`)}enableEditing(){this.editorDiv.setAttribute(`role`,`textbox`),this.editorDiv.setAttribute(`aria-multiline`,!0)}get canChangeContent(){return!0}render(){if(this.div)return this.div;let e,t;(this._isCopy||this.annotationElementId)&&(e=this.x,t=this.y),super.render(),this.editorDiv=document.createElement(`div`),this.editorDiv.className=`internal`,this.editorDiv.setAttribute(`id`,this.#t),this.editorDiv.setAttribute(`data-l10n-id`,`pdfjs-free-text2`),this.editorDiv.setAttribute(`data-l10n-attrs`,`default-content`),this.enableEditing(),this.editorDiv.contentEditable=!0;let{style:n}=this.editorDiv;if(n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`,n.color=this.color,this.div.append(this.editorDiv),this.overlayDiv=document.createElement(`div`),this.overlayDiv.classList.add(`overlay`,`enabled`),this.div.append(this.overlayDiv),this._isCopy||this.annotationElementId){let[n,r]=this.parentDimensions;if(this.annotationElementId){let{position:i}=this._initialData,[a,o]=this.getInitialTranslation();[a,o]=this.pageTranslationToScreen(a,o);let[s,c]=this.pageDimensions,[l,u]=this.pageTranslation,d,f;switch(this.rotation){case 0:d=e+(i[0]-l)/s,f=t+this.height-(i[1]-u)/c;break;case 90:d=e+(i[0]-l)/s,f=t-(i[1]-u)/c,[a,o]=[o,-a];break;case 180:d=e-this.width+(i[0]-l)/s,f=t-(i[1]-u)/c,[a,o]=[-a,-o];break;case 270:d=e+(i[0]-l-this.height*c)/s,f=t+(i[1]-u-this.width*s)/c,[a,o]=[-o,a];break}this.setAt(d*n,f*r,a,o)}else this._moveAfterPaste(e,t);this.#l(),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}static#c(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(Ii,``)}editorDivPaste(t){let n=t.clipboardData||window.clipboardData,{types:r}=n;if(r.length===1&&r[0]===`text/plain`)return;t.preventDefault();let i=e.#d(n.getData(`text`)||``).replaceAll(Ii,`
48
48
  `);if(!i)return;let a=window.getSelection();if(!a.rangeCount)return;this.editorDiv.normalize(),a.deleteFromDocument();let o=a.getRangeAt(0);if(!i.includes(`
49
49
  `)){o.insertNode(document.createTextNode(i)),this.editorDiv.normalize(),a.collapseToStart();return}let{startContainer:s,startOffset:c}=o,l=[],u=[];if(s.nodeType===Node.TEXT_NODE){let t=s.parentElement;if(u.push(s.nodeValue.slice(c).replaceAll(Ii,``)),t!==this.editorDiv){let n=l;for(let r of this.editorDiv.childNodes){if(r===t){n=u;continue}n.push(e.#c(r))}}l.push(s.nodeValue.slice(0,c).replaceAll(Ii,``))}else if(s===this.editorDiv){let t=l,n=0;for(let r of this.editorDiv.childNodes)n++===c&&(t=u),t.push(e.#c(r))}this.#e=`${l.join(`
50
50
  `)}${i}${u.join(`
51
51
  `)}`,this.#l();let d=new Range,f=Math.sumPrecise(l.map(e=>e.length));for(let{firstChild:e}of this.editorDiv.childNodes)if(e.nodeType===Node.TEXT_NODE){let t=e.nodeValue.length;if(f<=t){d.setStart(e,f),d.setEnd(e,f);break}f-=t}a.removeAllRanges(),a.addRange(d)}#l(){if(this.editorDiv.replaceChildren(),this.#e)for(let e of this.#e.split(`
52
52
  `)){let t=document.createElement(`div`);t.append(e?document.createTextNode(e):document.createElement(`br`)),this.editorDiv.append(t)}}#u(){return this.#e.replaceAll(`\xA0`,` `)}static#d(e){return e.replaceAll(` `,`\xA0`)}get contentDiv(){return this.editorDiv}getPDFRect(){let t=e._internalPadding*this.parentScale;return this.getRect(t,t)}static async deserialize(t,n,r){let i=null;if(t instanceof bi){let{data:{defaultAppearanceData:{fontSize:e,fontColor:n},rect:r,rotation:a,id:o,popupRef:s,richText:c,contentsObj:l,creationDate:u,modificationDate:d},textContent:f,textPosition:p,parent:{page:{pageNumber:m}}}=t;if(!f?.length)return null;i=t={annotationType:S.FREETEXT,color:Array.from(n),fontSize:e,value:f.join(`
53
- `),position:p,pageIndex:m-1,rect:r.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let a=await super.deserialize(t,n,r);return a.#r=t.fontSize,a.color=R.makeHexColor(...t.color),a.#e=e.#d(t.value),a._initialData=i,t.comment&&a.setCommentData(t),a}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=K._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#r,value:this.#u()});return this.addComment(n),e?(n.isCopy=!0,n):this.annotationElementId&&!this.#f(n)?null:(n.id=this.annotationElementId,n)}#f(e){let{value:t,fontSize:n,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((e,t)=>e!==r[t])||e.pageIndex!==i}renderAnnotationElement(e){let t=super.renderAnnotationElement(e);if(!t)return null;let{style:n}=t;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`,n.color=this.color,t.replaceChildren();for(let e of this.#e.split(`
54
- `)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`)),t.append(n)}return e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}}),t}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}},Q=class{static PRECISION=1e-4;toSVGPath(){P("Abstract method `toSVGPath` must be implemented.")}get box(){P("Abstract getter `box` must be implemented.")}serialize(e,t){P("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2)a[o]=t+e[o]*r,a[o+1]=n+e[o+1]*i;return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2)a[o]=t+e[o+1]*r,a[o+1]=n+e[o]*i;return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2)r[i]=t+e[i],r[i+1]=n+e[i+1];return r}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}},Ri=class e{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=e.#p+e.#m;constructor({x:t,y:n},r,i,a,o,s=0){this.#e=r,this.#d=a*i,this.#r=o,this.#a.set([NaN,NaN,NaN,NaN,t,n],6),this.#n=s,this.#l=e.#p*i,this.#c=e.#h*i,this.#u=i,this.#f.push(t,n)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e,this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c,s=l,c+=h,l+=g,this.#f?.push(e,t);let y=-g/p,b=h/p,x=y*this.#d,S=b*this.#d;return this.#a.set(this.#a.subarray(2,8),0),this.#a.set([c+x,l+S],4),this.#a.set(this.#a.subarray(14,18),12),this.#a.set([c-x,l-S],16),isNaN(this.#a[6])?(this.#i.length===0&&(this.#a.set([o+x,s+S],2),this.#i.push(NaN,NaN,NaN,NaN,(o+x-n)/i,(s+S-r)/a),this.#a.set([o-x,s-S],14),this.#t.push(NaN,NaN,NaN,NaN,(o-x-n)/i,(s-S-r)/a)),this.#a.set([_,v,o,s,c,l],6),!this.isEmpty()):(this.#a.set([_,v,o,s,c,l],6),Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2?([o,s,c,l]=this.#a.subarray(2,6),this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a),[o,s,_,v]=this.#a.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a),!0):([_,v,o,s,c,l]=this.#a.subarray(0,6),this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a),[c,l,o,s,_,v]=this.#a.subarray(12,18),this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a),!0))}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);return this.#v(n),n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new zi(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2)s[e]=(this.#f[e]-r)/a,s[e+1]=(this.#f[e+1]-i)/o;if(s[s.length-2]=(this.#o-r)/a,s[s.length-1]=(this.#s-i)/o,isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2){if(isNaN(e[t])){c[t]=c[t+1]=NaN;continue}c[t]=e[t],c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2){if(isNaN(t[e+n])){c[l]=c[l+1]=NaN,l+=2;continue}c[l]=t[e+n],c[l+1]=t[e+n+1],l+=2}return this.#x(c,l),this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0),this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;return e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t),t+=6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();return e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t),t+=24}},zi=class extends Q{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super(),this.#o=e,this.#i=t,this.#e=n,this.#a=r,this.#n=i,this.#r=a,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2)e[t]=(e[t]-o)/c,e[t+1]=(e[t+1]-s)/l;for(let e=0,n=t.length;e<n;e+=2)t[e]=(t[e]-o)/c,t[e+1]=(t[e+1]-s)/l}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6){if(isNaN(this.#o[t])){e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`);continue}e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`)}return e.push(`Z`),e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Q._rescale(this.#o,e,r,a,-o),c=Q._rescale(this.#i,e,r,a,-o);break;case 90:s=Q._rescaleAndSwap(this.#o,e,t,a,o),c=Q._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Q._rescale(this.#o,n,t,-a,o),c=Q._rescale(this.#i,n,t,-a,o);break;case 270:s=Q._rescaleAndSwap(this.#o,n,r,-a,-o),c=Q._rescaleAndSwap(this.#i,n,r,-a,-o);break}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],f=t[e+5];isNaN(t[e])?(R.pointBoundingBox(d,f,i),o>f?(a=d,o=f):o===f&&(a=l(a,d)),c<f?(s=d,c=f):c===f&&(s=l(s,d))):(u.set(p,0),R.bezierBoundingBox(n,r,...t.slice(e,e+6),u),R.rectBoundingBox(...u,i),o>u[1]?(a=u[0],o=u[1]):o===u[1]&&(a=l(a,u[0])),c<u[3]?(s=u[2],c=u[3]):c===u[3]&&(s=l(s,u[2]))),n=d,r=f}let d=this.#t;d[0]=i[0]-this.#n,d[1]=i[1]-this.#n,d[2]=i[2]-i[0]+2*this.#n,d[3]=i[3]-i[1]+2*this.#n,this.firstPoint=[a,o],this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new Ri(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}},Bi=class{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=p.slice(),a=10**-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f),R.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,f=this.#r.at(r?-1:-2),m=[f[0],f[2]];for(let e of this.#r){let[t,n,i,a]=e;!a&&r?n<d?(d=n,u=t):n===d&&(u=Math.max(u,t)):a&&!r&&(n<d?(d=n,u=t):n===d&&(u=Math.min(u,t))),e[0]=(t-c)/o,e[1]=(n-l)/s,e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]),this.#t=[u,d],this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)t[3]?(e.push(...this.#l(t)),this.#s(t)):(this.#c(t),e.push(...this.#l(t)));return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i),i.push(r),n.add(r),n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;for(i=[t,o],r.push(i);;){let e;if(n.has(s))e=s;else if(n.has(c))e=c;else break;n.delete(e),[t,a,o,s,c]=e,l!==t&&(i.push(l,u,t,u===a?a:o),l=t),u=u===a?o:a}i.push(l,u)}return new Vi(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1),e--,a--}continue}i[e][2]=n,s>r&&i.push([t,r,s])}}}return i}},Vi=class extends Q{#e;#t;constructor(e,t,n,r){super(),this.#t=e,this.#e=t,this.firstPoint=n,this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];a===n?(e.push(`V${o}`),r=o):o===r&&(e.push(`H${a}`),n=a)}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2)n[i]=e+t[i]*o,n[i+1]=r-t[i+1]*s;a.push(n)}return a}get box(){return this.#e}},Hi=class extends Ri{newFreeDrawOutline(e,t,n,r,i,a){return new Ui(e,t,n,r,i,a)}},Ui=class extends zi{newOutliner(e,t,n,r,i,a=0){return new Hi(e,t,n,r,i,a)}},Wi=class e extends K{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=S.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let t=e.prototype;return I(this,`_keyboardManager`,new ct([[[`ArrowLeft`],t._moveCaret,{args:[0]}],[[`ArrowRight`],t._moveCaret,{args:[1]}],[[`ArrowUp`],t._moveCaret,{args:[2]}],[[`ArrowDown`],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:`highlightEditor`}),this.color=t.color||e._defaultColor,this.#g=t.thickness||e._defaultThickness,this.opacity=t.opacity||e._defaultOpacity,this.#n=t.boxes||null,this.#_=t.methodOfCreation||``,this.#h=t.text||``,this._isDraggable=!1,this.defaultL10nId=`pdfjs-editor-highlight-editor`,t.highlightId>-1?(this.#d=!0,this.#y(t),this.#w()):this.#n&&(this.#e=t.anchorNode,this.#t=t.anchorOffset,this.#o=t.focusNode,this.#s=t.focusOffset,this.#v(),this.#w(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new Bi(this.#n,.001);this.#l=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;let t=new Bi(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:t,highlightId:n,clipPathId:r}){if(this.#l=t,this.#a=t.getNewOutline(this.#g/2+1.5,.0025),n>=0)this.#u=n,this.#r=r,this.parent.drawLayer.finalizeDraw(n,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0);else if(this.parent){let n=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:e.#T(this.#l.box,(n-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#m,{bbox:e.#T(this.#a.box,n),path:{d:this.#a.toSVGPath()}})}let[i,a,o,s]=t.box;switch(this.rotation){case 0:this.x=i,this.y=a,this.width=o,this.height=s;break;case 90:{let[e,t]=this.parentDimensions;this.x=a,this.y=1-i,this.width=o*t/e,this.height=s*e/t;break}case 180:this.x=1-i,this.y=1-a,this.width=o,this.height=s;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-a,this.y=i,this.width=o*t/e,this.height=s*e/t;break}}let{firstPoint:c}=t;this.#f=[(c[0]-i)/o,(c[1]-a)/s];let{lastPoint:l}=this.#a;this.#p=[(l[0]-i)/o,(l[1]-a)/s]}static initialize(t,n){K.initialize(t,n),e._defaultColor||=n.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(t,n){switch(t){case C.HIGHLIGHT_COLOR:e._defaultColor=n;break;case C.HIGHLIGHT_THICKNESS:e._defaultThickness=n;break}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case C.HIGHLIGHT_COLOR:this.#b(t);break;case C.HIGHLIGHT_THICKNESS:this.#x(t);break}}static get defaultPropertiesToUpdate(){return[[C.HIGHLIGHT_COLOR,e._defaultColor],[C.HIGHLIGHT_THICKNESS,e._defaultThickness]]}get propertiesToUpdate(){return[[C.HIGHLIGHT_COLOR,this.color||e._defaultColor],[C.HIGHLIGHT_THICKNESS,this.#g||e._defaultThickness],[C.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#i?.updateColor(this.color),super.onUpdatedColor()}#b(t){let n=(e,t)=>{this.color=e,this.opacity=t,this.onUpdatedColor()},r=this.color,i=this.opacity;this.addCommands({cmd:n.bind(this,t,e._defaultOpacity),undo:n.bind(this,r,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(t)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e,this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[[`colorPicker`,this.#i=new Zr({editor:this})]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#C(),this._reportTelemetry({action:`deleted`}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#w(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#C():e&&(this.#w(e),t=!this.parent&&this.div?.classList.contains(`selectedEditor`)),super.setParent(e),this.show(this._isVisible),t&&this.select()}#S(e){this.#d&&(this.#y({highlightOutlines:this.#l.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims())}#C(){this.#u===null||!this.parent||(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#m),this.#m=null)}#w(e=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0),this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#r))}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(t){let{drawLayer:n}=this.parent,r;this.#d?(t=(t-this.rotation+360)%360,r=e.#T(this.#l.box,t)):r=e.#T([this.x,this.y,this.width,this.height],t),n.updateProperties(this.#u,{bbox:r,root:{"data-main-rotation":t}}),n.updateProperties(this.#m,{bbox:e.#T(this.#a.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let e=super.render();this.#h&&(e.setAttribute(`aria-label`,this.#h),e.setAttribute(`role`,`mark`)),this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);return e.append(t),t.setAttribute(`aria-hidden`,`true`),t.className=`internal`,t.style.clipPath=this.#r,this.setDims(),it(this,this.#c,[`pointerover`,`pointerleave`]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(t){e._keyboardManager.exec(this,t)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1);break}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select(),this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#m&&(this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}}),this.#d||this.#D(!1))}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}}))}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(i.length*8),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i,a[o+1]=a[o+3]=d,a[o+2]=a[o+6]=i+l*e,a[o+5]=a[o+7]=d-u*t,o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort(),this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u}),window.addEventListener(`pointerup`,d,{signal:u}),window.addEventListener(`pointerdown`,U,{capture:!0,passive:!1,signal:u}),window.addEventListener(`contextmenu`,H,{signal:u}),n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u}),this._freeHighlight=new Hi({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof Oi){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:S.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof Di){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:S.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=R.makeHexColor(...i),l.opacity=c||1,o&&(l.#g=e.thickness),l._initialData=r,e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v(),l.#w(),l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Hi(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2)n.x=e[t]-f,n.y=d-(e[t+1]-p),r.add(n);let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a}),l.#w(),l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=K._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);return Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)}),this.addComment(n),this.annotationElementId&&!this.#N(n)?null:(n.id=this.annotationElementId,n)}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}},Gi=class{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){P(`Not implemented`)}},Ki=class e extends K{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){e.drawOutlines&&(this.#a(e),this.#c())}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e,this._drawingOptions||=n,this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert[this.editorType]),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)):this._drawId=this.#o(e,this.parent),this.#d(e.box)}#o(t,n){let{id:r}=n.drawLayer.draw(e._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return r}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){P(`Not implemented`)}static get typesMap(){P(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,n){let r=this.typesMap.get(t);r&&this._defaultDrawingOptions.updateProperty(r,n),this._currentParent&&(e.#n.updateProperty(r,n),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i),this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties()),e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e),i.updateProperty(r,t),this.#e.updateProperty(n,e),this.#e.updateProperty(r,t),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#s(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#c(),this.#d(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#s()):e&&(this._uiManager.addShouldRescale(this),this.#c(e),t=!this.parent&&this.div?.classList.contains(`selectedEditor`)),super.setParent(e),t&&this.select()}#s(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#c(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#o(this.#e,e)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((i*4+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;this._isCopy&&(e=this.x,t=this.y);let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);return n.append(r),r.setAttribute(`aria-hidden`,`true`),r.className=`internal`,this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),n}static createDrawerInstance(e,t,n,r,i){P(`Not implemented`)}static startDrawing(t,n,r,i){let{target:a,offsetX:o,offsetY:s,pointerId:c,pointerType:l}=i;if(G.isInitializedAndDifferentPointerType(l))return;let{viewport:{rotation:u}}=t,{width:d,height:f}=a.getBoundingClientRect(),p=e.#r=new AbortController,m=t.combinedSignal(p);if(G.setPointer(l,c),window.addEventListener(`pointerup`,e=>{G.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:m}),window.addEventListener(`pointercancel`,e=>{G.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:m}),window.addEventListener(`pointerdown`,t=>{G.isSamePointerType(t.pointerType)&&(G.initializeAndAddPointerId(t.pointerId),e.#n.isCancellable()&&(e.#n.removeLastElement(),e.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener(`contextmenu`,H,{signal:m}),a.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:m}),a.addEventListener(`touchmove`,e=>{G.isSameTimeStamp(e.timeStamp)&&U(e)},{signal:m}),t.toggleDrawing(),n._editorUndoBar?.hide(),e.#n){t.drawLayer.updateProperties(this._currentDrawId,e.#n.startNew(o,s,d,f,u));return}n.updateUIForDefaultProperties(this),e.#n=this.createDrawerInstance(o,s,d,f,u),e.#i=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(e.#i.toSVGProperties(),e.#n.defaultSVGProperties),!0,!1)}static _drawMove(t){if(G.isSameTimeStamp(t.timeStamp),!e.#n)return;let{offsetX:n,offsetY:r,pointerId:i}=t;if(G.isSamePointerId(i)){if(G.isUsingMultiplePointers()){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,e.#n.add(n,r)),G.setTimeStamp(t.timeStamp),U(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,e.#n=null,e.#i=null,G.clearTimeStamp()),e.#r&&(e.#r.abort(),e.#r=null,G.clearPointerIds())}static _endDraw(t){let n=this._currentParent;if(n){if(n.toggleDrawing(!0),this._cleanup(!1),t?.target===n.div&&n.drawLayer.updateProperties(this._currentDrawId,e.#n.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let t=e.#n,r=this._currentDrawId,i=t.getLastElement();n.addCommands({cmd:()=>{n.drawLayer.updateProperties(r,t.setLastElement(i))},undo:()=>{n.drawLayer.updateProperties(r,t.removeLastElement())},mustExec:!1,type:C.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){let n=this._currentParent;if(!n)return null;if(n.toggleDrawing(!0),n.cleanUndoStack(C.DRAW_STEP),!e.#n.isEmpty()){let{pageDimensions:[r,i],scale:a}=n,o=n.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:e.#n.getOutlines(r*a,i*a,a,this._INNER_MARGIN),drawingOptions:e.#i,mustBeCommitted:!t});return this._cleanup(!0),o}return n.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){P(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);return c.createDrawingOptions(e),c.#a({drawOutlines:s}),c.#c(),c.onScaleChanging(),c.rotate(),c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}},qi=class{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Ji;#l;#u;constructor(e,t,n,r,i,a){this.#l=n,this.#u=r,this.#r=i,this.#i=a,[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t],this.#n=[{line:o,points:this.#a}],this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Q._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n?.length}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;return Math.hypot(this.#l*o,this.#u*s)<=2?null:(this.#a.push(e,t),isNaN(n)?(this.#e.set([i,a,e,t],2),this.#t.push(NaN,NaN,NaN,NaN,e,t),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([n,r,i,a,e,t],0),this.#t.push(...Q.createBezierPoints(n,r,i,a,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n,this.#u=r,this.#r=i,[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#n.push({line:a,points:this.#a}),this.#e.set(a,0),this.#s=0,this.toSVGPath(),null}getLastElement(){return this.#n.at(-1)}setLastElement(e){return this.#n?(this.#n.push(e),this.#t=e.line,this.#a=e.points,this.#s=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(e)}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop(),this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t,this.#a=n,this.#s=0,this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Q.svgRound(this.#t[4]),t=Q.svgRound(this.#t[5]);if(this.#a.length===2)return this.#o=`${this.#o} M ${e} ${t} Z`,this.#o;if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`,this.#s=6}if(this.#a.length===4){let e=Q.svgRound(this.#t[10]),t=Q.svgRound(this.#t[11]);return this.#o=`${this.#o} L ${e} ${t}`,this.#s=12,this.#o}let n=[];this.#s===0&&(n.push(`M ${e} ${t}`),this.#s=6);for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Q.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}return this.#o+=n.join(` `),this.#s=this.#t.length,this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);return i.line=new Float32Array(i.line),i.points=new Float32Array(i.points),this.#c.build(this.#n,e,t,n,this.#r,this.#i,r),this.#e=null,this.#t=null,this.#n=null,this.#o=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Ji=class extends Q{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t,this.#a=n,this.#o=r,this.#s=i,this.#c=a,this.#n=o??0,this.#r=e,this.#d()}get thickness(){return this.#c}setLastElement(e){return this.#r.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#r.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){if(e.push(`M${Q.svgRound(t[4])} ${Q.svgRound(t[5])}`),t.length===6){e.push(`Z`);continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Q.svgRound(t[10])} ${Q.svgRound(t[11])}`);continue}for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Q.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Q._rescale,d=e,f=t+r,p=n,m=-r,h=e+s*n,g=t+(1-c-u)*r,_=e+(s+l)*n,v=t+(1-c)*r;break;case 90:y=Q._rescaleAndSwap,d=e,f=t,p=n,m=r,h=e+c*n,g=t+s*r,_=e+(c+u)*n,v=t+(s+l)*r;break;case 180:y=Q._rescale,d=e+n,f=t,p=-n,m=r,h=e+(1-s-l)*n,g=t+c*r,_=e+(1-s)*n,v=t+(c+u)*r;break;case 270:y=Q._rescaleAndSwap,d=e+n,f=t+r,p=-n,m=-r,h=e+(1-c-u)*n,g=t+(1-s-l)*r,_=e+(1-c)*n,v=t+(1-s)*r;break}for(let{line:e,points:t}of this.#r)a.push(y(e,d,f,p,m,i?Array(e.length):null)),o.push(y(t,d,f,p,m,i?Array(t.length):null));return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Q._rescale,u=-e/n,d=t/r+1,f=1/n,p=-1/r;break;case 90:m=Q._rescaleAndSwap,u=-t/r,d=-e/n,f=1/r,p=1/n;break;case 180:m=Q._rescale,u=e/n+1,d=-t/r,f=-1/n,p=1/r;break;case 270:m=Q._rescaleAndSwap,u=t/r+1,d=e/n+1,f=-1/r,p=-1/n;break}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Q.createBezierPoints(r,i,o,s,t,c),(a-2)*3),[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;return h.build(l,n,r,1,s,c,i),h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=m.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)R.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);R.bezierBoundingBox(n,r,a,o,s,c,l,u,e),n=l,r=u}}let[t,n]=this.#l();e[0]=B(e[0]-t,0,1),e[1]=B(e[1]-n,0,1),e[2]=B(e[2]+t,0,1),e[3]=B(e[3]+n,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;return s[0]-=a,s[1]-=o,s[2]+=2*a,s[3]+=2*o,s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e,this.#a=t,this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;return l[0]-=s,l[1]-=c,l[2]+=2*s,l[3]+=2*c,l}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Q.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e,i=-e/t,o=e;break;case 180:n=-1,a=-1,o=e,s=t;break;case 270:r=-t/e,i=e/t,s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Q.svgRound(o)} ${Q.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Q.PRECISION||Math.abs(l-a)<=Q.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Q.svgRound(o)} ${Q.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Q.svgRound(i)} ${Q.svgRound(a)}) scale(${u} ${d}) translate(${Q.svgRound(-i)} ${Q.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;if(o[0]=e,o[1]=t,o[2]=n,o[3]=r,Math.abs(l-i)<=Q.PRECISION||Math.abs(u-a)<=Q.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r)Q._translate(e,i,a,e),Q._translate(t,i,a,t);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r)Q._rescale(e,p,m,d,f,e),Q._rescale(t,p,m,d,f,t);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r)Q._translate(e,o,s,e),Q._translate(t,o,s,t);else{let e=this.#i/r,t=this.#a/i;this.#i=r,this.#a=i;for(let{line:n,points:r}of this.#r)Q._rescale(n,o,s,e,t,n),Q._rescale(r,o,s,e,t,r);a[2]*=e,a[3]*=t}return a[0]=e,a[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Q.svgRound(e[0])} ${Q.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}},Yi=class e extends Gi{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:`none`,stroke:K._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){e===`stroke-width`&&(t??=this[`stroke-width`],t*=this._viewParameters.realScale),super.updateSVGProperty(e,t)}clone(){let t=new e(this._viewParameters);return t.updateAll(this),t}},Xi=class e extends Ki{static _type=`ink`;static _editorType=S.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`}),this._willKeepAspectRatio=!0,this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){K.initialize(e,t),this._defaultDrawingOptions=new Yi(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return I(this,`typesMap`,new Map([[C.INK_THICKNESS,`stroke-width`],[C.INK_COLOR,`stroke`],[C.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new qi(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Ji.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof Di){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:S.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);return i._initialData=r,e.comment&&i.setCommentData(e),i}get toolbarButtons(){return this._colorPicker||=new Qr(this),[[`colorPicker`,this._colorPicker]]}get colorType(){return C.INK_COLOR}get colorAndOpacityType(){return C.INK_COLOR_AND_OPACITY}get opacityType(){return C.INK_OPACITY}updateParams(e,t){if(e===C.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(t.color,t.opacity);return}super.updateParams(e,t)}static updateDefaultParams(e,t){if(e===C.INK_COLOR_AND_OPACITY){super.updateDefaultParams(C.INK_COLOR,t.color),super.updateDefaultParams(C.INK_OPACITY,t.opacity);return}super.updateDefaultParams(e,t)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`),n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty(`stroke-width`),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:n,opacity:r}){this._drawingOptions=e.getDefaultDrawingOptions({stroke:R.makeHexColor(...t),"stroke-width":n,"stroke-opacity":r})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:K._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});return this.addComment(o),e?(o.isCopy=!0,o):this.annotationElementId&&!this.#e(o)?null:(o.id=this.annotationElementId,o)}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let{points:t,rect:n}=this.serializeDraw(!1);return e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment}),null}},Zi=class extends Ji{toSVGPath(){let e=super.toSVGPath();return e.endsWith(`Z`)||(e+=`Z`),e}},Qi=8,$i=3,ea=class{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){return n-=e,r-=t,n===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8,c=this.#n[2*a],l=this.#n[2*a+1];if(e[(n+c)*t+(r+l)]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8,c=this.#n[2*a],l=this.#n[2*a+1];if(e[(n+c)*t+(r+l)]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o=1,s,c=[];for(let e=1;e<n-1;e++){s=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0)o+=1,--u;else if(i>=1&&a[r+1]===0)o+=1,u+=1,i>1&&(s=i);else{i!==1&&(s=Math.abs(i));continue}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:o,parent:0};c.push(p);let m;for(let e of c)if(e.id===s){m=e;break}m?m.isHole?p.parent=f?m.parent:s:p.parent=f?s:m.parent:p.parent=f?s:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-o,a[r]!==1&&(s=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v,u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i],_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;if(a[p+1]===0?a[p]=-o:a[p]===1&&(a[p]=o),c===e&&f===n&&b===v&&x===y){a[r]!==1&&(s=Math.abs(a[r]));break}else l=b,u=x,b=c,x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);t>b&&(x=r,b=t)}b>(c*y)**2?(this.#o(e,t,x+2,r),this.#o(e,x,n,r)):r.push(i,a)}static#s(e){let t=[],n=e.length;return this.#o(e,0,n,t),t.push(e[n-2],e[n-1]),t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h,m+=h}}let h=f[s]=Math.round(d/m);p[h]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a),i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];i>n&&(t-a>r&&(r=t-a,o=t-1),n=i,a=t)}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2),o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o),s=a,c=o,e!==t&&e.close(),e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d),o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`,s.fillRect(0,0,a,o),s.filter=`grayscale(1)`,s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b),l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0}),l.font=u,l.filter=`grayscale(1)`,l.fillStyle=`white`,l.fillRect(0,0,y,b),l.fillStyle=`black`,l.fillText(e,y*(v-1)/2,b*(3-v)/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));if(d.push({line:i,points:r}),n===2){r[0]=t[0]*p,r[1]=t[1]*m,i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p,s*=m,c*=p,l*=m,r.set([o,s,c,l],0),i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Q.createBezierPoints(o,s,c,l,n,a),(e-2)*3),[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new Zi:new Ji;return g.build(d,t,n,1,r,o?0:u,i),{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a=1/0,o=-1/0,s=0;for(let t of e){s+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];a=Math.min(a,n),o=Math.max(o,n)}}let c;c=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;let l=e.length,u=Qi+$i*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(s-2*l)*c.BYTES_PER_ELEMENT,d[f++]=0,d[f++]=r,d[f++]=i,d[f++]=+!t,d[f++]=Math.max(0,Math.floor(n??0)),d[f++]=l,d[f++]=c.BYTES_PER_ELEMENT;for(let t of e)d[f++]=t.length-2,d[f++]=t[0],d[f++]=t[1];let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready,m.write(d);let h=c.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}return m.close(),(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready,i.write(t).then(async()=>{await i.ready,await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n)a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]),a.set(e,o),o+=e.length;let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(Qi+$i*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g);break}o=0;for(let e=0;e<p;e++){let t=s[$i*e+Qi],n=new Float32Array(t+2);h.push(n);for(let t=0;t<$i-1;t++)n[t]=s[$i*e+Qi+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){return N(`decompressSignature: ${e}`),null}}},ta=class e extends Gi{constructor(){super(),super.updateProperties({fill:K._defaultLineColor,"stroke-width":0})}clone(){let t=new e;return t.updateAll(this),t}},na=class e extends Yi{constructor(e){super(e),super.updateProperties({stroke:K._defaultLineColor,"stroke-width":1})}clone(){let t=new e(this._viewParameters);return t.updateAll(this),t}},ra=class e extends Ki{#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=S.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`}),this._willKeepAspectRatio=!0,this.#n=e.signatureData||null,this.#t=null,this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){K.initialize(e,t),this._defaultDrawingOptions=new ta,this._defaultDrawnSignatureOptions=new na(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return I(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let t,n,{_isCopy:r}=this;if(r&&(this._isCopy=!1,t=this.x,n=this.y),super.render(),this._drawId===null)if(this.#n){let{lines:t,mustSmooth:n,areContours:r,description:i,uuid:a,heightInPage:o}=this.#n,{rawDims:{pageWidth:s,pageHeight:c},rotation:l}=this.parent.viewport,u=ea.processDrawnLines({lines:t,pageWidth:s,pageHeight:c,rotation:l,innerMargin:e._INNER_MARGIN,mustSmooth:n,areContours:r});this.addSignature(u,o,i,a)}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));return r&&(this._isCopy=!0,this._moveAfterPaste(t,n)),this.div}setUuid(e){this.#r=e,this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e,this.div&&(this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e})),super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)}))}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:ea.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,n,r,i){let{x:a,y:o}=this,{outline:s}=this.#n=t;this.#e=s instanceof Zi,this.description=r;let c;this.#e?c=e.getDefaultDrawingOptions():(c=e._defaultDrawnSignatureOptions.clone(),c.updateProperties({"stroke-width":s.thickness})),this._addOutlines({drawOutlines:s,drawingOptions:c});let[,l]=this.pageDimensions,u=n/l;u=u>=1?.5:u,this.width*=u/this.height,this.width>=1&&(u*=.9/this.width,this.width=.9),this.height=u,this.setDims(),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return ea.process(t,n,r,i,e._INNER_MARGIN)}getFromText(t,n){let{rawDims:{pageWidth:r,pageHeight:i},rotation:a}=this.parent.viewport;return ea.extractContoursFromText(t,n,r,i,a,e._INNER_MARGIN)}getDrawnSignature(t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return ea.processDrawnLines({lines:t,pageWidth:n,pageHeight:r,rotation:i,innerMargin:e._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:n}){t?this._drawingOptions=e.getDefaultDrawingOptions():(this._drawingOptions=e._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":n}))}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});return this.addComment(i),e?(i.paths={lines:t,points:n},i.uuid=this.#r,i.isCopy=!0):i.lines=t,this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t}),i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?Zi.deserialize(e,t,n,r,i,a):Ji.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);return r.#e=e.areContours,r.description=e.accessibilityData?.alt||``,r.#r=e.uuid,r}},ia=class extends K{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=S.STAMP;constructor(e){super({...e,name:`stampEditor`}),this.#r=e.bitmapUrl,this.#i=e.bitmapFile,this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){K.initialize(e,t)}static isHandlingMimeForPasting(e){return Ue.includes(e)}static paste(e,t){t.pasteEditor({mode:S.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#l=e.isSvg),e.file&&(this.#a=e.file.name),this.#m()}#f(){if(this.#n=null,this._uiManager.enableWaiting(!1),this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;return await this.setGuessedAltText(s),t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1}),s}#p(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`,e.accept=Ue.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(t)}n()},{signal:t}),e.addEventListener(`cancel`,()=>{this.remove(),n()},{signal:t})}).finally(()=>this.#f()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#o?.remove(),this.#o=null,this.#c&&=(clearTimeout(this.#c),null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#p();return}super.rebuild(),this.div!==null&&(this.#t&&this.#o===null&&this.#p(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;return this._isCopy&&(e=this.x,t=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#s||(this.#e?this.#m():this.#p()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),n&&this._uiManager.imageManager.isValidId(n)&&(this.#t=n,r&&(this.#e=r),this.#s=!1,this.#m())}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(this.#c!==null&&clearTimeout(this.#c),this.#c=setTimeout(()=>{this.#c=null,this.#g()},200))}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width)t=this.width*r,n=this.height*i;else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e,n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`),this.addContainer(o),this.width=t/r,this.height=n/i,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#g(),this.#u||=(this.parent.addUndoableEditor(this),!0),this._reportTelemetry({action:`inserted_image`}),this.#a&&this.div.setAttribute(`aria-description`,this.#a),this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new He,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e),c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;this._uiManager.hcmFilter===`none`?We.isDarkMode&&(d=`#8f8f9d`,f=`#42414d`):f=`black`;let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(p*2,m*2),g=h.getContext(`2d`);g.fillStyle=d,g.fillRect(0,0,p*2,m*2),g.fillStyle=f,g.fillRect(0,0,p,m),g.fillRect(p,m,p,m),u.fillStyle=u.createPattern(h,`repeat`),u.fillRect(0,0,e,n),u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e)t=o.width,n=o.height;else if(o=this.#e,r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a),n=Math.floor(i*a),this.#l||(o=this.#h(t,n))}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n),u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2)),a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a),o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new He,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a,s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter,l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);return{width:e.width,height:e.height}=this.#e,e.getContext(`2d`).drawImage(this.#e,0,0),e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*Oe.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*Oe.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);return i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r),i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof Mi){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,_,v;g?(delete e.canvas,{id:_,bitmap:v}=n.imageManager.getFromCanvas(m.id,g),g.remove()):(i=!0,e._hasNoCanvas=!0);let y=(await t._structTree.getAriaAttributes(`${b}${s}`))?.get(`aria-label`)||``;r=e={annotationType:S.STAMP,bitmapId:_,bitmap:v,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:y},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;i?(n.addMissingCanvas(e.id,a),a.#s=!0):l&&n.imageManager.isValidId(l)?(a.#t=l,s&&(a.#e=s)):a.#r=c,a.#l=u;let[f,p]=a.pageDimensions;return a.width=(o[2]-o[0])/f,a.height=(o[3]-o[1])/p,d&&(a.altTextData=d),a._initialData=r,e.comment&&a.setCommentData(e),a.#u=!!r,a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});if(this.addComment(n),e)return n.bitmapUrl=this.#_(!0),n.accessibilityData=this.serializeAltText(!0),n.isCopy=!0,n;let{decorative:r,altText:i}=this.serializeAltText(!1);if(!r&&i&&(n.accessibilityData={type:`Figure`,alt:i}),this.annotationElementId){let e=this.#v(n);return e.isSame?null:(e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1,n.id=this.annotationElementId,delete n.bitmapId,n)}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:a,serialized:n}),n.bitmap=this.#_(!1);else if(this.#l){let e=t.stamps.get(this.#t);a>e.area&&(e.area=a,e.serialized.bitmap.close(),e.serialized.bitmap=this.#_(!1))}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}},aa=class e{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([Li,Xi,ia,Wi,ra].map(e=>[e._editorType,e]));constructor({uiManager:t,pageIndex:n,div:r,structTreeLayer:i,accessibilityManager:a,annotationLayer:o,drawLayer:s,textLayer:c,viewport:l,l10n:u}){let d=[...e.#g.values()];if(!e._initialized){e._initialized=!0;for(let e of d)e.initialize(u,t)}t.registerEditorTypes(d),this.#h=t,this.pageIndex=n,this.div=r,this.#e=a,this.#n=o,this.viewport=l,this.#d=c,this.drawLayer=s,this._structTree=i,this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===S.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(t=this.#h.getMode()){switch(this.#S(),t){case S.NONE:this.div.classList.toggle(`nonEditing`,!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case S.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case S.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:n}=this.div;if(n.toggle(`nonEditing`,!1),t===S.POPUP)n.toggle(`commentEditing`,!0);else{n.toggle(`commentEditing`,!1);for(let r of e.#g.values())n.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle(`nonEditing`,!1),this.#p?.abort(),this.#p=null;let e=new Set;for(let t of this.#_)t.enableEditing(),t.show(!0),t.annotationElementId&&(this.#h.removeChangedExistingAnnotation(t),e.add(t.annotationElementId));let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){if(n.hide(),this.#h.isDeletedAnnotationElement(n.data.id)||e.has(n.data.id))continue;let t=await this.deserialize(n);t&&(this.addOrRebuild(t),t.enableEditing())}this.#c=!1,this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#s=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle(`nonEditing`,!0),this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);if(i.toggle(`getElements`,!1),!this.div.contains(a[0]))return;let o,s=RegExp(`^${x}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);c?.annotationElementId===null&&(U(e),c.dblclick(e))},{signal:e,capture:!0})}let t=this.#n,n=[];if(t){let e=new Map,r=new Map;for(let t of this.#_){if(t.disableEditing(),!t.annotationElementId){n.push(t);continue}if(t.serialize()!==null){e.set(t.annotationElementId,t);continue}else r.set(t.annotationElementId,t);this.getEditableAnnotation(t.annotationElementId)?.show(),t.remove()}for(let n of t.getEditableAnnotations()){let{id:t}=n.data;if(this.#h.isDeletedAnnotationElement(t)){n.updateEdited({deleted:!0});continue}let i=r.get(t);if(i){i.resetAnnotationElement(n),i.show(!1),n.show();continue}i=e.get(t),i&&(this.#h.addChangedExistingAnnotation(i),i.renderAnnotationElement(n)&&i.show(!1)),n.show()}}this.#S(),this.isEmpty&&(this.div.hidden=!0);let{classList:r}=this.div;for(let t of e.#g.values())r.remove(`${t._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(n),this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e}),this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#d.div.classList.remove(`highlighting`))}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=L.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0),this.#d.div.classList.add(`free`),this.toggleDrawing(),Wi.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y}),this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`),this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal}),e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e}),this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort(),this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#h.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#h.addDeletedAnnotationElement(e),K.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#h.addEditor(e),this.attach(e),!e.isAttachedToDOM){let t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#c),this.#h.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;e.div.contains(t)&&!this.#i&&(e._focusEventsAllowed=!1,this.#i=setTimeout(()=>{this.#i=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal}),t.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return e.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(t){return await e.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});return i&&this.add(i),i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=Math.min(window.innerWidth,e+n),s=Math.min(window.innerHeight,t+r),c=(i+o)/2-e,l=(a+s)/2-t,[u,d]=this.viewport.rotation%180==0?[c,l]:[l,c];return{offsetX:u,offsetY:d}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=L.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#o||(this.#o=!1,this.#y?.isDrawer&&this.#y.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();if(n===S.STAMP||n===S.POPUP||n===S.SIGNATURE){this.#h.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#h.getMode()===S.HIGHLIGHT&&this.enableTextSelection(),this.#o){this.#o=!1;return}let{isMac:t}=L.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#o=!0,this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this),this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{e&&!this.div.contains(e)&&(this.#u=null,this.commitOrRemove())},{signal:t}),this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(e=!1){return this.#l?(this.#h.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#u=null,this.#y.endDrawing(e)):null}findNewParent(e,t,n){let r=this.#h.findParent(t,n);return r===null||r===this?!1:(r.changeParent(e),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#h.getActive()?.parent===this&&(this.#h.commitOrRemove(),this.#h.setActiveEditor(null)),this.#i&&=(clearTimeout(this.#i),null);for(let e of this.#a.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#a.clear(),this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e,Ve(this.div,e);for(let e of this.#h.getEditors(this.pageIndex))this.add(e),e.rebuild();await this.#h.findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:e}){this.#h.commitOrRemove(),this.#S();let t=this.viewport.rotation,n=e.rotation;if(this.viewport=e,Ve(this.div,{rotation:n}),t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}};function oa(e,t){return e===t?0:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function sa(e){return e?e.nodeType===Node.ELEMENT_NODE?e.closest(`.textLayer`):e.parentElement?.closest(`.textLayer`)||null:null}function ca(e,t,n,r){if(e===n)return t<=r;let i=e.compareDocumentPosition(n);return i&Node.DOCUMENT_POSITION_FOLLOWING?!0:i&Node.DOCUMENT_POSITION_PRECEDING?!1:null}function la(e,t,n){if(e.nodeType!==Node.ELEMENT_NODE||!e.classList.contains(`textLayer`)||t!==e.childNodes.length)return{container:e,offset:t};let r=e.lastChild;return r?.nodeType===Node.ELEMENT_NODE&&r.classList.contains(`endOfContent`)&&(r=r.previousSibling),!r||!n.contains(r)?null:r.nodeType===Node.TEXT_NODE?{container:r,offset:r.textContent.length}:{container:r,offset:r.childNodes.length}}var ua=class e{#e=null;#t=new Map;#n=null;#r=null;#i=null;#a=null;#o=new Map;static#s=0;static#c=0;static#l=null;static#u=new Set;static#d=!1;static#f=new Set;static#p=new WeakMap;constructor({filterFactory:t=null,pageColors:n=null,pageIndex:r,textLayer:i=null}){if(this.pageIndex=r,this.#r=t,this.#i=n,i){let t=e.#p.get(i);if(t?.selectionDiv&&(t.selectionDiv.remove(),e.#u.delete(t.selectionDiv)),e.#p.set(i,{drawLayer:this}),e.#f.add(i),this.#n=i,this.#a=new MutationObserver(t=>{if(!(!this.#e||!this.#n?.isConnected||!e.#h())){for(let{addedNodes:n}of t)for(let t of n)if(t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(`endOfContent`)){e.#_();return}}}),this.#a.observe(i,{childList:!0}),e.#l===null){e.#l=new AbortController;let{signal:t}=e.#l;document.addEventListener(`selectionchange`,e.#_.bind(e),{signal:t}),document.addEventListener(`pointerdown`,()=>{e.#d=!0},{signal:t}),document.addEventListener(`pointerup`,()=>{e.#d=!1},{signal:t}),window.addEventListener(`blur`,()=>{e.#d=!1},{signal:t})}}}setParent(t){if(!this.#e){this.#e=t,this.#n?.isConnected&&e.#h()&&e.#_();return}if(this.#e!==t){if(this.#t.size>0)for(let e of this.#t.values())e.remove(),t.append(e);this.#e=t}}static#m(e){let t=this.#p.get(e);t?.selectionDiv&&(t.selectionDiv.remove(),this.#u.delete(t.selectionDiv),t.selectionDiv=null,t.path=null)}static#h(){let e=document.getSelection();return!!e&&!e.isCollapsed}static#g(){return[...this.#f].filter(e=>e.isConnected).sort(oa)}static#_(){let t=document.getSelection();if(!t||t.isCollapsed){for(let e of this.#u)e.remove();this.#u.clear();return}let n=new WeakMap,r=this.#g(),i=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(n.collapsed)continue;let{startContainer:a,startOffset:o,endContainer:s,endOffset:c}=n,l=sa(a),u=sa(s),d=l===null,f=u===null;if(this.#d&&d!==f)return;if(t.rangeCount===1){let{anchorNode:e,anchorOffset:n,focusNode:r,focusOffset:i}=t,d=sa(e),f=sa(r),p=ca(e,n,r,i);d&&f&&p!==null&&(p?(a=e,o=n,l=d,s=r,c=i,u=f):(a=r,o=i,l=f,s=e,c=n,u=d))}let p=r.filter(e=>n.intersectsNode(e));if(p.length===0)continue;let m=!1;if(l||(l=p[0],a=l,o=0,m=!0),u||(u=p.at(-1),s=u,c=u.childNodes.length,m=!0),s.nodeType===Node.ELEMENT_NODE){if(s.classList.contains(`endOfContent`)){let e=s.previousSibling;if(!e)continue;s=e,c=e.nodeType===Node.TEXT_NODE?e.textContent.length:e.childNodes.length}else if(s.classList.contains(`textLayer`)&&s.childNodes.length===c){let e=la(s,c,u);if(!e)continue;s=e.container,c=e.offset}}if(a.nodeType===Node.ELEMENT_NODE){let e=la(a,o,l);if(!e)continue;a=e.container,o=e.offset}if(l===u&&!m&&p.includes(l)){i.push([n,l]);continue}for(let e of p){let t=e.firstChild;if(!t)continue;let n=document.createRange();if(e===l?n.setStart(a,o):n.setStartBefore(t),e===u)n.setEnd(s,c);else{let t=e.lastChild;if(!t)continue;if(t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(`endOfContent`)){let e=t.previousSibling;if(!e)continue;n.setEndAfter(e)}else n.setEndAfter(t)}n.collapsed||i.push([n,e])}}let a=new Set(i.map(e=>e[1]));for(let e of this.#f)a.has(e)||this.#m(e);for(let[t,r]of i){let i=e.#p.get(r);if(!i)continue;let a=n.get(r);if(!a){let e=r.getBoundingClientRect();a=(t,n,r,i)=>({x:(t-e.x)/e.width,y:(n-e.y)/e.height,width:r/e.width,height:i/e.height}),n.set(r,a)}let o=[];for(let{x:e,y:n,width:r,height:i}of t.getClientRects())r===0||i===0||({x:e,y:n,width:r,height:i}=a(e,n,r,i),!(r===1&&i===1)&&o.push(`M${e} ${n} h${r} v${i} h-${r} Z`));if(o.length===0)continue;let s=i.drawLayer,c=i.selectionDiv,l=i.path;if(!c){let t=`clip_selection_${e.#c++}`;c=document.createElement(`div`),c.className=`selection`,c.style.clipPath=`url(#${t})`;let n=s.#r?.createSelectionStyle(s.#i);if(n)for(let[e,t]of Object.entries(n))c.style.setProperty(e,t);let r=e._svgFactory.create(1,1,!0);r.setAttribute(`aria-hidden`,`true`),r.setAttribute(`width`,`100%`),r.setAttribute(`height`,`100%`);let a=e._svgFactory.createElement(`clipPath`);a.setAttribute(`id`,t),a.setAttribute(`clipPathUnits`,`objectBoundingBox`),l=e._svgFactory.createElement(`path`),a.append(l),r.append(a),c.append(r),i.path=l,i.selectionDiv=c}!c.parentNode&&s.#e&&(s.#e.append(c),this.#u.add(c)),l.setAttribute(`d`,o.join(` `))}}static get _svgFactory(){return I(this,`_svgFactory`,new ri)}static#v(e,[t,n,r,i]){let{style:a}=e;a.top=`${100*n}%`,a.left=`${100*t}%`,a.width=`${100*r}%`,a.height=`${100*i}%`}#y(){let t=e._svgFactory.create(1,1,!0);return this.#e.append(t),t.setAttribute(`aria-hidden`,`true`),t}#b(t,n){let r=e._svgFactory.createElement(`clipPath`);t.append(r);let i=`clip_${n}`;r.setAttribute(`id`,i),r.setAttribute(`clipPathUnits`,`objectBoundingBox`);let a=e._svgFactory.createElement(`use`);return r.append(a),a.setAttribute(`href`,`#${n}`),a.classList.add(`clip`),i}#x(e,t){for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r)}draw(t,n=!1,r=!1){let i=e.#s++,a=this.#y(),o=e._svgFactory.createElement(`defs`);a.append(o);let s=e._svgFactory.createElement(`path`);o.append(s);let c=`path_${i}`;s.setAttribute(`id`,c),s.setAttribute(`vector-effect`,`non-scaling-stroke`),n&&this.#o.set(i,s);let l=r?this.#b(o,c):null,u=e._svgFactory.createElement(`use`);return a.append(u),u.setAttribute(`href`,`#${c}`),this.updateProperties(a,t),this.#t.set(i,a),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,n){let r=e.#s++,i=this.#y(),a=e._svgFactory.createElement(`defs`);i.append(a);let o=e._svgFactory.createElement(`path`);a.append(o);let s=`path_${r}`;o.setAttribute(`id`,s),o.setAttribute(`vector-effect`,`non-scaling-stroke`);let c;if(n){let t=e._svgFactory.createElement(`mask`);a.append(t),c=`mask_${r}`,t.setAttribute(`id`,c),t.setAttribute(`maskUnits`,`objectBoundingBox`);let n=e._svgFactory.createElement(`rect`);t.append(n),n.setAttribute(`width`,`1`),n.setAttribute(`height`,`1`),n.setAttribute(`fill`,`white`);let i=e._svgFactory.createElement(`use`);t.append(i),i.setAttribute(`href`,`#${s}`),i.setAttribute(`stroke`,`none`),i.setAttribute(`fill`,`black`),i.setAttribute(`fill-rule`,`nonzero`),i.classList.add(`mask`)}let l=e._svgFactory.createElement(`use`);i.append(l),l.setAttribute(`href`,`#${s}`),c&&l.setAttribute(`mask`,`url(#${c})`);let u=l.cloneNode();return i.append(u),l.classList.add(`mainOutline`),u.classList.add(`secondaryOutline`),this.updateProperties(i,t),this.#t.set(r,i),r}finalizeDraw(e,t){this.#o.delete(e),this.updateProperties(e,t)}updateProperties(t,n){if(!n)return;let{root:r,bbox:i,rootClass:a,path:o}=n,s=typeof t==`number`?this.#t.get(t):t;if(s){if(r&&this.#x(s,r),i&&e.#v(s,i),a){let{classList:e}=s;for(let[t,n]of Object.entries(a))e.toggle(t,n)}if(o){let e=s.firstElementChild.firstElementChild;this.#x(e,o)}}}updateParent(e,t){if(t===this)return;let n=this.#t.get(e);n&&(t.#e.append(n),this.#t.delete(e),t.#t.set(e,n))}remove(e){this.#o.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(let e of this.#t.values())e.remove();this.#t.clear(),this.#o.clear(),this.#a?.disconnect(),this.#a=null,this.#n&&=(e.#p.get(this.#n)?.drawLayer===this&&(e.#m(this.#n),e.#p.delete(this.#n),e.#f.delete(this.#n),e.#f.size===0&&(e.#l?.abort(),e.#l=null,e.#d=!1)),null)}};function da(e){return`${(e*100).toFixed(2)}%`}var fa=class e{#e=[];#t=new Map;#n=null;#r=0;#i=0;#a=0;static#o=null;constructor(e,t,n,r){this.#r=e,this.#e=t,this.#i=n.rawDims.pageWidth,this.#a=n.rawDims.pageHeight,this.#n=r}render(){let t=document.createElement(`div`);t.className=`textLayerImages`;for(let e=0;e<this.#e.length;e+=6){let n=this.#s(this.#e.subarray(e,e+6));n&&t.append(n)}return t.addEventListener(`contextmenu`,t=>{if(!(t.target instanceof HTMLCanvasElement))return;let n=t.target,r=this.#t.get(n);if(!r)return;let i=e.#o?.deref();if(i===n)return;i&&(i.width=0,i.height=0),e.#o=new WeakRef(n);let{inverseTransform:a,x1:o,y1:s,width:c,height:l}=r,u=this.#n(),d=Math.ceil(o*u.width),f=Math.ceil(s*u.height),p=Math.floor((o+c/this.#i)*u.width),m=Math.floor((s+l/this.#a)*u.height);n.width=p-d,n.height=m-f;let h=n.getContext(`2d`);h.setTransform(...a),h.translate(-d,-f),h.drawImage(u,0,0)}),t}#s([e,t,n,r,i,a]){let o=Math.hypot((i-e)*this.#i,(a-t)*this.#a),s=Math.hypot((n-e)*this.#i,(r-t)*this.#a);if(o<this.#r||s<this.#r)return null;let c=[(i-e)*this.#i/o,(a-t)*this.#a/o,(n-e)*this.#i/s,(r-t)*this.#a/s,0,0],l=R.inverseTransform(c),u=document.createElement(`canvas`);return u.className=`textLayerImagePlaceholder`,u.width=0,u.height=0,Object.assign(u.style,{opacity:0,position:`absolute`,left:da(e),top:da(t),width:da(o/this.#i),height:da(s/this.#a),transformOrigin:`0% 0%`,transform:`matrix(${c.join(`,`)})`}),this.#t.set(u,{inverseTransform:l,width:o,height:s,x1:e,y1:t}),u}};globalThis._pdfjsTestingUtils={HighlightOutliner:Bi},globalThis.pdfjsLib={AbortException:me,AnnotationEditorLayer:aa,AnnotationEditorParamsType:C,AnnotationEditorType:S,AnnotationEditorUIManager:ut,AnnotationLayer:Fi,AnnotationMode:y,AnnotationType:D,applyOpacity:Ke,build:Xr,ColorPicker:Zr,createValidAbsoluteUrl:ae,CSSConstants:Ge,DOMSVGFactory:ri,DrawLayer:ua,FeatureTest:L,fetchData:ke,findContrastColor:Qe,getDocument:Br,getFilenameFromUrl:Me,getPdfFilenameFromUrl:Ne,getRGB:Re,getRGBA:Le,getUuid:be,GlobalWorkerOptions:Dr,ImageKind:E,InvalidPDFException:de,isDataScheme:je,isPdfFile:V,isValidExplicitDest:Xt,makeArr:Se,makeMap:Ce,makeObj:we,MathClamp:B,noContextMenu:H,normalizeUnicode:ye,OPS:A,OutputScale:He,PasswordException:le,PasswordResponses:M,PDFDataRangeTransport:Hr,PDFDateString:Ie,PDFWorker:Gr,PermissionFlag:w,PixelsPerInch:Oe,RenderingCancelledException:Ae,renderRichText:$e,ResponseException:fe,setLayerDimensions:Ve,shadow:I,SignatureExtractor:ea,stopEvent:U,SupportedImageMimeTypes:Ue,TextLayer:Rr,TextLayerImages:fa,TouchManager:pt,updateUrlHash:oe,Util:R,VerbosityLevel:k,version:Yr,XfaLayer:De};var pa=`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`,ma=[`#000000`,`#475569`,`#dc2626`,`#f97316`,`#eab308`,`#16a34a`,`#2563eb`,`#7c3aed`,`#db2777`,`#ffffff`],ha=[`transparent`,`#f8fafc`,`#fee2e2`,`#ffedd5`,`#fef9c3`,`#dcfce7`,`#dbeafe`,`#f3e8ff`,`#fce7f3`,`#ffffff`],ga=e=>{let t=`font-size: ${e.fontSize}; color: ${e.color}; text-align: ${e.textAlign};`;e.fontFamily&&(t+=` font-family: ${e.fontFamily};`),t+=` font-weight: ${e.fontWeight};`,e.bold&&(t+=` font-weight: bold;`),e.italic&&(t+=` font-style: italic;`);let n=[];e.underline&&n.push(`underline`),e.strikethrough&&n.push(`line-through`),n.length>0&&(t+=` text-decoration: ${n.join(` `)};`);let r=[`fontSize`,`fontWeight`,`color`,`textAlign`,`fontFamily`,`bold`,`italic`,`underline`,`strikethrough`,`customCss`,`sameRow`];return Object.entries(e).forEach(([e,n])=>{if(r.includes(e)||n==null||n===``)return;let i=e.replace(/([A-Z])/g,`-$1`).toLowerCase();t+=` ${i}: ${n};`}),e.customCss&&(t+=` ${e.customCss}`),t},_a=e=>{if(!e||!e.trim())return{};let t={};return e.split(`;`).forEach(e=>{let n=e.split(`:`);if(n.length>=2){let e=n[0].trim().replace(/-([a-z])/g,e=>e[1].toUpperCase()),r=n.slice(1).join(`:`).trim();e&&r&&(t[e]=r)}}),t},va=e=>{let t={0:`1010011`,1:`1101001`,2:`1100101`,3:`1001101`,4:`1011001`,5:`1010011`,6:`1101011`,7:`1101101`,8:`1001111`,9:`1110011`,A:`1100010`,B:`1000110`,C:`1100011`,D:`1011100`,E:`1001110`,F:`1110100`,G:`1110010`,H:`1101110`,I:`1100111`,J:`1011000`,K:`1000111`,L:`1100011`,M:`1011110`,N:`1111010`,O:`1110110`,P:`1110011`,Q:`1110010`,R:`1101110`,S:`1100111`,T:`1011000`,U:`1000111`,V:`1100011`,W:`1011110`,X:`1111010`,Y:`1110110`,Z:`1110011`,"-":`1001011`,_:`1101001`,".":`1100101`," ":`1001101`},n=e||`BARCODE`,r=n.toUpperCase().replace(/[^0-9A-Z\-_\. ]/g,``),i=`1101001000`;for(let e=0;e<r.length;e++){let n=r[e];i+=t[n]||`1010011`}i+=`1100011101011`;let a=i.length*2,o=``;for(let e=0;e<i.length;e++)i[e]===`1`&&(o+=`<rect x="${e*2}" y="5" width="2" height="50" fill="black" />`);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} 70" width="100%" height="100%" style="display: block; margin: 0 auto;">
53
+ `),position:p,pageIndex:m-1,rect:r.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,popupRef:s,comment:l?.str||null,richText:c,creationDate:u,modificationDate:d}}let a=await super.deserialize(t,n,r);return a.#r=t.fontSize,a.color=z.makeHexColor(...t.color),a.#e=e.#d(t.value),a._initialData=i,t.comment&&a.setCommentData(t),a}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let t=K._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#r,value:this.#u()});return this.addComment(n),e?(n.isCopy=!0,n):this.annotationElementId&&!this.#f(n)?null:(n.id=this.annotationElementId,n)}#f(e){let{value:t,fontSize:n,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((e,t)=>e!==r[t])||e.pageIndex!==i}renderAnnotationElement(e){let t=super.renderAnnotationElement(e);if(!t)return null;let{style:n}=t;n.fontSize=`calc(${this.#r}px * var(--total-scale-factor))`,n.color=this.color,t.replaceChildren();for(let e of this.#e.split(`
54
+ `)){let n=document.createElement(`div`);n.append(e?document.createTextNode(e):document.createElement(`br`)),t.append(n)}return e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}}),t}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}},Q=class{static PRECISION=1e-4;toSVGPath(){F("Abstract method `toSVGPath` must be implemented.")}get box(){F("Abstract getter `box` must be implemented.")}serialize(e,t){F("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2)a[o]=t+e[o]*r,a[o+1]=n+e[o+1]*i;return a}static _rescaleAndSwap(e,t,n,r,i,a){a||=new Float32Array(e.length);for(let o=0,s=e.length;o<s;o+=2)a[o]=t+e[o+1]*r,a[o+1]=n+e[o]*i;return a}static _translate(e,t,n,r){r||=new Float32Array(e.length);for(let i=0,a=e.length;i<a;i+=2)r[i]=t+e[i],r[i+1]=n+e[i+1];return r}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,n,r,i){switch(i){case 90:return[1-t/n,e/r];case 180:return[1-e/n,1-t/r];case 270:return[t/n,1-e/r];default:return[e/n,t/r]}}static createBezierPoints(e,t,n,r,i,a){return[(e+5*n)/6,(t+5*r)/6,(5*n+i)/6,(5*r+a)/6,(n+i)/2,(r+a)/2]}},Ri=class e{#e;#t=[];#n;#r;#i=[];#a=new Float32Array(18);#o;#s;#c;#l;#u;#d;#f=[];static#p=8;static#m=2;static#h=e.#p+e.#m;constructor({x:t,y:n},r,i,a,o,s=0){this.#e=r,this.#d=a*i,this.#r=o,this.#a.set([NaN,NaN,NaN,NaN,t,n],6),this.#n=s,this.#l=e.#p*i,this.#c=e.#h*i,this.#u=i,this.#f.push(t,n)}isEmpty(){return isNaN(this.#a[8])}#g(){let e=this.#a.subarray(4,6),t=this.#a.subarray(16,18),[n,r,i,a]=this.#e;return[(this.#o+(e[0]-t[0])/2-n)/i,(this.#s+(e[1]-t[1])/2-r)/a,(this.#o+(t[0]-e[0])/2-n)/i,(this.#s+(t[1]-e[1])/2-r)/a]}add({x:e,y:t}){this.#o=e,this.#s=t;let[n,r,i,a]=this.#e,[o,s,c,l]=this.#a.subarray(8,12),u=e-c,d=t-l,f=Math.hypot(u,d);if(f<this.#c)return!1;let p=f-this.#l,m=p/f,h=m*u,g=m*d,_=o,v=s;o=c,s=l,c+=h,l+=g,this.#f?.push(e,t);let y=-g/p,b=h/p,x=y*this.#d,S=b*this.#d;return this.#a.set(this.#a.subarray(2,8),0),this.#a.set([c+x,l+S],4),this.#a.set(this.#a.subarray(14,18),12),this.#a.set([c-x,l-S],16),isNaN(this.#a[6])?(this.#i.length===0&&(this.#a.set([o+x,s+S],2),this.#i.push(NaN,NaN,NaN,NaN,(o+x-n)/i,(s+S-r)/a),this.#a.set([o-x,s-S],14),this.#t.push(NaN,NaN,NaN,NaN,(o-x-n)/i,(s-S-r)/a)),this.#a.set([_,v,o,s,c,l],6),!this.isEmpty()):(this.#a.set([_,v,o,s,c,l],6),Math.abs(Math.atan2(v-s,_-o)-Math.atan2(g,h))<Math.PI/2?([o,s,c,l]=this.#a.subarray(2,6),this.#i.push(NaN,NaN,NaN,NaN,((o+c)/2-n)/i,((s+l)/2-r)/a),[o,s,_,v]=this.#a.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((_+o)/2-n)/i,((v+s)/2-r)/a),!0):([_,v,o,s,c,l]=this.#a.subarray(0,6),this.#i.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a),[c,l,o,s,_,v]=this.#a.subarray(12,18),this.#t.push(((_+5*o)/6-n)/i,((v+5*s)/6-r)/a,((5*o+c)/6-n)/i,((5*s+l)/6-r)/a,((o+c)/2-n)/i,((s+l)/2-r)/a),!0))}toSVGPath(){if(this.isEmpty())return``;let e=this.#i,t=this.#t;if(isNaN(this.#a[6])&&!this.isEmpty())return this.#_();let n=[];n.push(`M${e[4]} ${e[5]}`);for(let t=6;t<e.length;t+=6)isNaN(e[t])?n.push(`L${e[t+4]} ${e[t+5]}`):n.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#y(n);for(let e=t.length-6;e>=6;e-=6)isNaN(t[e])?n.push(`L${t[e+4]} ${t[e+5]}`):n.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);return this.#v(n),n.join(` `)}#_(){let[e,t,n,r]=this.#e,[i,a,o,s]=this.#g();return`M${(this.#a[2]-e)/n} ${(this.#a[3]-t)/r} L${(this.#a[4]-e)/n} ${(this.#a[5]-t)/r} L${i} ${a} L${o} ${s} L${(this.#a[16]-e)/n} ${(this.#a[17]-t)/r} L${(this.#a[14]-e)/n} ${(this.#a[15]-t)/r} Z`}#v(e){let t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#y(e){let[t,n,r,i]=this.#e,a=this.#a.subarray(4,6),o=this.#a.subarray(16,18),[s,c,l,u]=this.#g();e.push(`L${(a[0]-t)/r} ${(a[1]-n)/i} L${s} ${c} L${l} ${u} L${(o[0]-t)/r} ${(o[1]-n)/i}`)}newFreeDrawOutline(e,t,n,r,i,a){return new zi(e,t,n,r,i,a)}getOutlines(){let e=this.#i,t=this.#t,n=this.#a,[r,i,a,o]=this.#e,s=new Float32Array((this.#f?.length??0)+2);for(let e=0,t=s.length-2;e<t;e+=2)s[e]=(this.#f[e]-r)/a,s[e+1]=(this.#f[e+1]-i)/o;if(s[s.length-2]=(this.#o-r)/a,s[s.length-1]=(this.#s-i)/o,isNaN(n[6])&&!this.isEmpty())return this.#b(s);let c=new Float32Array(this.#i.length+24+this.#t.length),l=e.length;for(let t=0;t<l;t+=2){if(isNaN(e[t])){c[t]=c[t+1]=NaN;continue}c[t]=e[t],c[t+1]=e[t+1]}l=this.#S(c,l);for(let e=t.length-6;e>=6;e-=6)for(let n=0;n<6;n+=2){if(isNaN(t[e+n])){c[l]=c[l+1]=NaN,l+=2;continue}c[l]=t[e+n],c[l+1]=t[e+n+1],l+=2}return this.#x(c,l),this.newFreeDrawOutline(c,s,this.#e,this.#u,this.#n,this.#r)}#b(e){let t=this.#a,[n,r,i,a]=this.#e,[o,s,c,l]=this.#g(),u=new Float32Array(36);return u.set([NaN,NaN,NaN,NaN,(t[2]-n)/i,(t[3]-r)/a,NaN,NaN,NaN,NaN,(t[4]-n)/i,(t[5]-r)/a,NaN,NaN,NaN,NaN,o,s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,(t[16]-n)/i,(t[17]-r)/a,NaN,NaN,NaN,NaN,(t[14]-n)/i,(t[15]-r)/a],0),this.newFreeDrawOutline(u,e,this.#e,this.#u,this.#n,this.#r)}#x(e,t){let n=this.#t;return e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t),t+=6}#S(e,t){let n=this.#a.subarray(4,6),r=this.#a.subarray(16,18),[i,a,o,s]=this.#e,[c,l,u,d]=this.#g();return e.set([NaN,NaN,NaN,NaN,(n[0]-i)/o,(n[1]-a)/s,NaN,NaN,NaN,NaN,c,l,NaN,NaN,NaN,NaN,u,d,NaN,NaN,NaN,NaN,(r[0]-i)/o,(r[1]-a)/s],t),t+=24}},zi=class extends Q{#e;#t=new Float32Array(4);#n;#r;#i;#a;#o;constructor(e,t,n,r,i,a){super(),this.#o=e,this.#i=t,this.#e=n,this.#a=r,this.#n=i,this.#r=a,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#s(a);let[o,s,c,l]=this.#t;for(let t=0,n=e.length;t<n;t+=2)e[t]=(e[t]-o)/c,e[t+1]=(e[t+1]-s)/l;for(let e=0,n=t.length;e<n;e+=2)t[e]=(t[e]-o)/c,t[e+1]=(t[e+1]-s)/l}toSVGPath(){let e=[`M${this.#o[4]} ${this.#o[5]}`];for(let t=6,n=this.#o.length;t<n;t+=6){if(isNaN(this.#o[t])){e.push(`L${this.#o[t+4]} ${this.#o[t+5]}`);continue}e.push(`C${this.#o[t]} ${this.#o[t+1]} ${this.#o[t+2]} ${this.#o[t+3]} ${this.#o[t+4]} ${this.#o[t+5]}`)}return e.push(`Z`),e.join(` `)}serialize([e,t,n,r],i){let a=n-e,o=r-t,s,c;switch(i){case 0:s=Q._rescale(this.#o,e,r,a,-o),c=Q._rescale(this.#i,e,r,a,-o);break;case 90:s=Q._rescaleAndSwap(this.#o,e,t,a,o),c=Q._rescaleAndSwap(this.#i,e,t,a,o);break;case 180:s=Q._rescale(this.#o,n,t,-a,o),c=Q._rescale(this.#i,n,t,-a,o);break;case 270:s=Q._rescaleAndSwap(this.#o,n,r,-a,-o),c=Q._rescaleAndSwap(this.#i,n,r,-a,-o);break}return{outline:Array.from(s),points:[Array.from(c)]}}#s(e){let t=this.#o,n=t[4],r=t[5],i=[n,r,n,r],a=n,o=r,s=n,c=r,l=e?Math.max:Math.min,u=new Float32Array(4);for(let e=6,d=t.length;e<d;e+=6){let d=t[e+4],f=t[e+5];isNaN(t[e])?(z.pointBoundingBox(d,f,i),o>f?(a=d,o=f):o===f&&(a=l(a,d)),c<f?(s=d,c=f):c===f&&(s=l(s,d))):(u.set(p,0),z.bezierBoundingBox(n,r,...t.slice(e,e+6),u),z.rectBoundingBox(...u,i),o>u[1]?(a=u[0],o=u[1]):o===u[1]&&(a=l(a,u[0])),c<u[3]?(s=u[2],c=u[3]):c===u[3]&&(s=l(s,u[2]))),n=d,r=f}let d=this.#t;d[0]=i[0]-this.#n,d[1]=i[1]-this.#n,d[2]=i[2]-i[0]+2*this.#n,d[3]=i[3]-i[1]+2*this.#n,this.firstPoint=[a,o],this.lastPoint=[s,c]}get box(){return this.#t}newOutliner(e,t,n,r,i,a=0){return new Ri(e,t,n,r,i,a)}getNewOutline(e,t){let[n,r,i,a]=this.#t,[o,s,c,l]=this.#e,u=i*c,d=a*l,f=n*c+o,p=r*l+s,m=this.newOutliner({x:this.#i[0]*u+f,y:this.#i[1]*d+p},this.#e,this.#a,e,this.#r,t??this.#n);for(let e=2;e<this.#i.length;e+=2)m.add({x:this.#i[e]*u+f,y:this.#i[e+1]*d+p});return m.getOutlines()}},Bi=class{#e;#t;#n;#r=[];#i=[];constructor(e,t=0,n=0,r=!0){let i=p.slice(),a=10**-4;for(let{x:n,y:r,width:o,height:s}of e){let e=Math.floor((n-t)/a)*a,c=Math.ceil((n+o+t)/a)*a,l=Math.floor((r-t)/a)*a,u=Math.ceil((r+s+t)/a)*a,d=[e,l,u,!0],f=[c,l,u,!1];this.#r.push(d,f),z.rectBoundingBox(e,l,c,u,i)}let o=i[2]-i[0]+2*n,s=i[3]-i[1]+2*n,c=i[0]-n,l=i[1]-n,u=r?-1/0:1/0,d=1/0,f=this.#r.at(r?-1:-2),m=[f[0],f[2]];for(let e of this.#r){let[t,n,i,a]=e;!a&&r?n<d?(d=n,u=t):n===d&&(u=Math.max(u,t)):a&&!r&&(n<d?(d=n,u=t):n===d&&(u=Math.min(u,t))),e[0]=(t-c)/o,e[1]=(n-l)/s,e[2]=(i-l)/s}this.#e=new Float32Array([c,l,o,s]),this.#t=[u,d],this.#n=m}getOutlines(){this.#r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2]);let e=[];for(let t of this.#r)t[3]?(e.push(...this.#l(t)),this.#s(t)):(this.#c(t),e.push(...this.#l(t)));return this.#a(e)}#a(e){let t=[],n=new Set;for(let n of e){let[e,r,i]=n;t.push([e,r,n],[e,i,n])}t.sort((e,t)=>e[1]-t[1]||e[0]-t[0]);for(let e=0,r=t.length;e<r;e+=2){let r=t[e][2],i=t[e+1][2];r.push(i),i.push(r),n.add(r),n.add(i)}let r=[],i;for(;n.size>0;){let e=n.values().next().value,[t,a,o,s,c]=e;n.delete(e);let l=t,u=a;for(i=[t,o],r.push(i);;){let e;if(n.has(s))e=s;else if(n.has(c))e=c;else break;n.delete(e),[t,a,o,s,c]=e,l!==t&&(i.push(l,u,t,u===a?a:o),l=t),u=u===a?o:a}i.push(l,u)}return new Vi(r,this.#e,this.#t,this.#n)}#o(e){let t=this.#i,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i][0];if(a===e)return i;a<e?n=i+1:r=i-1}return r+1}#s([,e,t]){let n=this.#o(e);this.#i.splice(n,0,[e,t])}#c([,e,t]){let n=this.#o(e);for(let r=n;r<this.#i.length;r++){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}for(let r=n-1;r>=0;r--){let[n,i]=this.#i[r];if(n!==e)break;if(n===e&&i===t){this.#i.splice(r,1);return}}}#l(e){let[t,n,r]=e,i=[[t,n,r]],a=this.#o(r);for(let e=0;e<a;e++){let[n,r]=this.#i[e];for(let e=0,a=i.length;e<a;e++){let[,o,s]=i[e];if(!(r<=o||s<=n)){if(o>=n){if(s>r)i[e][1]=r;else{if(a===1)return[];i.splice(e,1),e--,a--}continue}i[e][2]=n,s>r&&i.push([t,r,s])}}}return i}},Vi=class extends Q{#e;#t;constructor(e,t,n,r){super(),this.#t=e,this.#e=t,this.firstPoint=n,this.lastPoint=r}toSVGPath(){let e=[];for(let t of this.#t){let[n,r]=t;e.push(`M${n} ${r}`);for(let i=2;i<t.length;i+=2){let a=t[i],o=t[i+1];a===n?(e.push(`V${o}`),r=o):o===r&&(e.push(`H${a}`),n=a)}e.push(`Z`)}return e.join(` `)}serialize([e,t,n,r],i){let a=[],o=n-e,s=r-t;for(let t of this.#t){let n=Array(t.length);for(let i=0;i<t.length;i+=2)n[i]=e+t[i]*o,n[i+1]=r-t[i+1]*s;a.push(n)}return a}get box(){return this.#e}},Hi=class extends Ri{newFreeDrawOutline(e,t,n,r,i,a){return new Ui(e,t,n,r,i,a)}},Ui=class extends zi{newOutliner(e,t,n,r,i,a=0){return new Hi(e,t,n,r,i,a)}},Wi=class e extends K{#e=null;#t=0;#n;#r=null;#i=null;#a=null;#o=null;#s=0;#c=null;#l=null;#u=null;#d=!1;#f=null;#p=null;#m=null;#h=``;#g;#_=``;static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type=`highlight`;static _editorType=S.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId=``;static get _keyboardManager(){let t=e.prototype;return L(this,`_keyboardManager`,new ct([[[`ArrowLeft`],t._moveCaret,{args:[0]}],[[`ArrowRight`],t._moveCaret,{args:[1]}],[[`ArrowUp`],t._moveCaret,{args:[2]}],[[`ArrowDown`],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:`highlightEditor`}),this.color=t.color||e._defaultColor,this.#g=t.thickness||e._defaultThickness,this.opacity=t.opacity||e._defaultOpacity,this.#n=t.boxes||null,this.#_=t.methodOfCreation||``,this.#h=t.text||``,this._isDraggable=!1,this.defaultL10nId=`pdfjs-editor-highlight-editor`,t.highlightId>-1?(this.#d=!0,this.#y(t),this.#w()):this.#n&&(this.#e=t.anchorNode,this.#t=t.anchorOffset,this.#o=t.focusNode,this.#s=t.focusOffset,this.#v(),this.#w(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.highlight)}get telemetryInitialData(){return{action:`added`,type:this.#d?`free_highlight`:`highlight`,color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#g,methodOfCreation:this.#_}}get telemetryFinalData(){return{type:`highlight`,color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get(`color`).size}}#v(){let e=new Bi(this.#n,.001);this.#l=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;let t=new Bi(this.#n,.0025,.001,this._uiManager.direction===`ltr`);this.#a=t.getOutlines();let{firstPoint:n}=this.#l;this.#f=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];let{lastPoint:r}=this.#a;this.#p=[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height]}#y({highlightOutlines:t,highlightId:n,clipPathId:r}){if(this.#l=t,this.#a=t.getNewOutline(this.#g/2+1.5,.0025),n>=0)this.#u=n,this.#r=r,this.parent.drawLayer.finalizeDraw(n,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#m=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},!0);else if(this.parent){let n=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:e.#T(this.#l.box,(n-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#m,{bbox:e.#T(this.#a.box,n),path:{d:this.#a.toSVGPath()}})}let[i,a,o,s]=t.box;switch(this.rotation){case 0:this.x=i,this.y=a,this.width=o,this.height=s;break;case 90:{let[e,t]=this.parentDimensions;this.x=a,this.y=1-i,this.width=o*t/e,this.height=s*e/t;break}case 180:this.x=1-i,this.y=1-a,this.width=o,this.height=s;break;case 270:{let[e,t]=this.parentDimensions;this.x=1-a,this.y=i,this.width=o*t/e,this.height=s*e/t;break}}let{firstPoint:c}=t;this.#f=[(c[0]-i)/o,(c[1]-a)/s];let{lastPoint:l}=this.#a;this.#p=[(l[0]-i)/o,(l[1]-a)/s]}static initialize(t,n){K.initialize(t,n),e._defaultColor||=n.highlightColors?.values().next().value||`#fff066`}static updateDefaultParams(t,n){switch(t){case C.HIGHLIGHT_COLOR:e._defaultColor=n;break;case C.HIGHLIGHT_THICKNESS:e._defaultThickness=n;break}}translateInPage(e,t){}get toolbarPosition(){return this.#p}get commentButtonPosition(){return this.#f}updateParams(e,t){switch(e){case C.HIGHLIGHT_COLOR:this.#b(t);break;case C.HIGHLIGHT_THICKNESS:this.#x(t);break}}static get defaultPropertiesToUpdate(){return[[C.HIGHLIGHT_COLOR,e._defaultColor],[C.HIGHLIGHT_THICKNESS,e._defaultThickness]]}get propertiesToUpdate(){return[[C.HIGHLIGHT_COLOR,this.color||e._defaultColor],[C.HIGHLIGHT_THICKNESS,this.#g||e._defaultThickness],[C.HIGHLIGHT_FREE,this.#d]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#i?.updateColor(this.color),super.onUpdatedColor()}#b(t){let n=(e,t)=>{this.color=e,this.opacity=t,this.onUpdatedColor()},r=this.color,i=this.opacity;this.addCommands({cmd:n.bind(this,t,e._defaultOpacity),undo:n.bind(this,r,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:`color_changed`,color:this._uiManager.getNonHCMColorName(t)},!0)}#x(e){let t=this.#g,n=e=>{this.#g=e,this.#S(e)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:`thickness_changed`,thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[[`colorPicker`,this.#i=new Zr({editor:this})]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle(`disabled`,!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#O())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#O())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#C(),this._reportTelemetry({action:`deleted`}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#w(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#C():e&&(this.#w(e),t=!this.parent&&this.div?.classList.contains(`selectedEditor`)),super.setParent(e),this.show(this._isVisible),t&&this.select()}#S(e){this.#d&&(this.#y({highlightOutlines:this.#l.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims())}#C(){this.#u===null||!this.parent||(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#m),this.#m=null)}#w(e=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#r}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:`0 0 1 1`,fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0),this.#m=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#a.box,path:{d:this.#a.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#r))}static#T([e,t,n,r],i){switch(i){case 90:return[1-t-r,e,r,n];case 180:return[1-e-n,1-t-r,n,r];case 270:return[t,1-e-n,r,n]}return[e,t,n,r]}rotate(t){let{drawLayer:n}=this.parent,r;this.#d?(t=(t-this.rotation+360)%360,r=e.#T(this.#l.box,t)):r=e.#T([this.x,this.y,this.width,this.height],t),n.updateProperties(this.#u,{bbox:r,root:{"data-main-rotation":t}}),n.updateProperties(this.#m,{bbox:e.#T(this.#a.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let e=super.render();this.#h&&(e.setAttribute(`aria-label`,this.#h),e.setAttribute(`role`,`mark`)),this.#d?e.classList.add(`free`):this.div.addEventListener(`keydown`,this.#E.bind(this),{signal:this._uiManager._signal});let t=this.#c=document.createElement(`div`);return e.append(t),t.setAttribute(`aria-hidden`,`true`),t.className=`internal`,t.style.clipPath=this.#r,this.setDims(),it(this,this.#c,[`pointerover`,`pointerleave`]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1}})}#E(t){e._keyboardManager.exec(this,t)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#D(!0);break;case 1:case 3:this.#D(!1);break}}#D(e){if(!this.#e)return;let t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#o,this.#s)}select(){super.select(),this.#m&&this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#m&&(this.parent?.drawLayer.updateProperties(this.#m,{rootClass:{selected:!1}}),this.#d||this.#D(!1))}get _mustFixPosition(){return!this.#d}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#m,{rootClass:{hidden:!e}}))}#O(){return this.#d?this.rotation:0}#k(){if(this.#d)return null;let[e,t]=this.pageDimensions,[n,r]=this.pageTranslation,i=this.#n,a=new Float32Array(i.length*8),o=0;for(let{x:s,y:c,width:l,height:u}of i){let i=s*e+n,d=(1-c)*t+r;a[o]=a[o+4]=i,a[o+1]=a[o+3]=d,a[o+2]=a[o+6]=i+l*e,a[o+5]=a[o+7]=d-u*t,o+=8}return a}#A(e){return this.#l.serialize(e,this.#O())}static startHighlighting(e,t,{target:n,x:r,y:i}){let{x:a,y:o,width:s,height:c}=n.getBoundingClientRect(),l=new AbortController,u=e.combinedSignal(l),d=t=>{l.abort(),this.#M(e,t)};window.addEventListener(`blur`,d,{signal:u}),window.addEventListener(`pointerup`,d,{signal:u}),window.addEventListener(`pointerdown`,U,{capture:!0,passive:!1,signal:u}),window.addEventListener(`contextmenu`,H,{signal:u}),n.addEventListener(`pointermove`,this.#j.bind(this,e),{signal:u}),this._freeHighlight=new Hi({x:r,y:i},[a,o,s,c],e.scale,this._defaultThickness/2,t,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#M(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:`main_toolbar`}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=``}static async deserialize(e,t,n){let r=null;if(e instanceof Oi){let{data:{quadPoints:t,rect:n,rotation:i,id:a,color:o,opacity:s,popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:S.HIGHLIGHT,color:Array.from(o),opacity:s,quadPoints:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}else if(e instanceof Di){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,borderStyle:{rawWidth:s},popupRef:c,richText:l,contentsObj:u,creationDate:d,modificationDate:f},parent:{page:{pageNumber:p}}}=e;r=e={annotationType:S.HIGHLIGHT,color:Array.from(o),thickness:s,inkLists:t,boxes:null,pageIndex:p-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:c,richText:l,comment:u?.str||null,creationDate:d,modificationDate:f}}let{color:i,quadPoints:a,inkLists:o,outlines:s,opacity:c}=e,l=await super.deserialize(e,t,n);l.color=z.makeHexColor(...i),l.opacity=c||1,o&&(l.#g=e.thickness),l._initialData=r,e.comment&&l.setCommentData(e);let[u,d]=l.pageDimensions,[f,p]=l.pageTranslation;if(a){let e=l.#n=[];for(let t=0;t<a.length;t+=8)e.push({x:(a[t]-f)/u,y:1-(a[t+1]-p)/d,width:(a[t+2]-a[t])/u,height:(a[t+1]-a[t+5])/d});l.#v(),l.#w(),l.rotate(l.rotation)}else if(o||s){l.#d=!0;let e=(o||s.points)[0],n={x:e[0]-f,y:d-(e[1]-p)},r=new Hi(n,[0,0,u,d],1,l.#g/2,!0,.001);for(let t=0,i=e.length;t<i;t+=2)n.x=e[t]-f,n.y=d-(e[t+1]-p),r.add(n);let{id:i,clipPathId:a}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:`0 0 1 1`,fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:r.toSVGPath()}},!0,!0);l.#y({highlightOutlines:r.getOutlines(),highlightId:i,clipPathId:a}),l.#w(),l.rotate(l.parentRotation)}return l}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();let t=K._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);return Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#g,quadPoints:this.#k(),outlines:this.#A(n.rect)}),this.addComment(n),this.annotationElementId&&!this.#N(n)?null:(n.id=this.annotationElementId,n)}#N(e){let{color:t}=this._initialData;return this.hasEditedComment||e.color.some((e,n)=>e!==t[n])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}},Gi=class{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(let[t,n]of Object.entries(e))t.startsWith(`_`)||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){let e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){F(`Not implemented`)}},Ki=class e extends K{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#n=null;static#r=null;static#i=null;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(e){e.drawOutlines&&(this.#a(e),this.#c())}#a({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e,this._drawingOptions||=n,this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert[this.editorType]),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)):this._drawId=this.#o(e,this.parent),this.#d(e.box)}#o(t,n){let{id:r}=n.drawLayer.draw(e._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return r}static _mergeSVGProperties(e,t){let n=new Set(Object.keys(e));for(let[r,i]of Object.entries(t))n.has(r)?Object.assign(e[r],i):e[r]=i;return e}static getDefaultDrawingOptions(e){F(`Not implemented`)}static get typesMap(){F(`Not implemented`)}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,n){let r=this.typesMap.get(t);r&&this._defaultDrawingOptions.updateProperty(r,n),this._currentParent&&(e.#n.updateProperty(r,n),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){let n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){let e=[],t=this._defaultDrawingOptions;for(let[n,r]of this.typesMap)e.push([n,t[r]]);return e}get propertiesToUpdate(){let e=[],{_drawingOptions:t}=this;for(let[n,r]of this.constructor.typesMap)e.push([n,t[r]]);return e}_updateProperty(e,t,n){let r=this._drawingOptions,i=r[t],a=n=>{r.updateProperty(t,n);let i=this.#e.updateProperty(t,n);i&&this.#d(i),this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties()),e===this.colorType?this.onUpdatedColor():e===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,n),undo:a.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(e,t){let n=this.constructor.typesMap.get(this.colorType),r=this.constructor.typesMap.get(this.opacityType),i=this._drawingOptions,a=i[n],o=i[r],s=(e,t)=>{i.updateProperty(n,e),i.updateProperty(r,t),this.#e.updateProperty(n,e),this.#e.updateProperty(r,t),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:s.bind(this,e,t),undo:s.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:C.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#u()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#u()),{bbox:this.#f()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#u(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle(`disabled`,!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle(`disabled`,!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#s(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#c(),this.#d(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#s()):e&&(this._uiManager.addShouldRescale(this),this.#c(e),t=!this.parent&&this.div?.classList.contains(`selectedEditor`)),super.setParent(e),t&&this.select()}#s(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#c(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#o(this.#e,e)}}#l([e,t,n,r]){let{parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[t,1-e,a/i*n,i/a*r];case 180:return[1-e,1-t,n,r];case 270:return[1-t,e,a/i*n,i/a*r];default:return[e,t,n,r]}}#u(){let{x:e,y:t,width:n,height:r,parentDimensions:[i,a],rotation:o}=this;switch(o){case 90:return[1-t,e,i/a*n,a/i*r];case 180:return[1-e,1-t,n,r];case 270:return[t,1-e,i/a*n,a/i*r];default:return[e,t,n,r]}}#d(e){[this.x,this.y,this.width,this.height]=this.#l(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#f(){let{x:e,y:t,width:n,height:r,rotation:i,parentRotation:a,parentDimensions:[o,s]}=this;switch((i*4+a)/90){case 1:return[1-t-r,e,r,n];case 2:return[1-e-n,1-t-r,n,r];case 3:return[t,1-e-n,r,n];case 4:return[e,t-o/s*n,s/o*r,o/s*n];case 5:return[1-t,e,o/s*n,s/o*r];case 6:return[1-e-s/o*r,1-t,s/o*r,o/s*n];case 7:return[t-o/s*n,1-e-s/o*r,o/s*n,s/o*r];case 8:return[e-n,t-r,n,r];case 9:return[1-t,e-n,r,n];case 10:return[1-e,1-t,n,r];case 11:return[t-r,1-e,r,n];case 12:return[e-s/o*r,t,s/o*r,o/s*n];case 13:return[1-t-o/s*n,e-s/o*r,o/s*n,s/o*r];case 14:return[1-e,1-t-o/s*n,s/o*r,o/s*n];case 15:return[t,1-e,o/s*n,s/o*r];default:return[e,t,n,r]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,e._mergeSVGProperties({bbox:this.#f()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;this._isCopy&&(e=this.x,t=this.y);let n=super.render();n.classList.add(`draw`);let r=document.createElement(`div`);return n.append(r),r.setAttribute(`aria-hidden`,`true`),r.className=`internal`,this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),n}static createDrawerInstance(e,t,n,r,i){F(`Not implemented`)}static startDrawing(t,n,r,i){let{target:a,offsetX:o,offsetY:s,pointerId:c,pointerType:l}=i;if(G.isInitializedAndDifferentPointerType(l))return;let{viewport:{rotation:u}}=t,{width:d,height:f}=a.getBoundingClientRect(),p=e.#r=new AbortController,m=t.combinedSignal(p);if(G.setPointer(l,c),window.addEventListener(`pointerup`,e=>{G.isSamePointerIdOrRemove(e.pointerId)&&this._endDraw(e)},{signal:m}),window.addEventListener(`pointercancel`,e=>{G.isSamePointerIdOrRemove(e.pointerId)&&this._currentParent.endDrawingSession()},{signal:m}),window.addEventListener(`pointerdown`,t=>{G.isSamePointerType(t.pointerType)&&(G.initializeAndAddPointerId(t.pointerId),e.#n.isCancellable()&&(e.#n.removeLastElement(),e.#n.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:m}),window.addEventListener(`contextmenu`,H,{signal:m}),a.addEventListener(`pointermove`,this._drawMove.bind(this),{signal:m}),a.addEventListener(`touchmove`,e=>{G.isSameTimeStamp(e.timeStamp)&&U(e)},{signal:m}),t.toggleDrawing(),n._editorUndoBar?.hide(),e.#n){t.drawLayer.updateProperties(this._currentDrawId,e.#n.startNew(o,s,d,f,u));return}n.updateUIForDefaultProperties(this),e.#n=this.createDrawerInstance(o,s,d,f,u),e.#i=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(e.#i.toSVGProperties(),e.#n.defaultSVGProperties),!0,!1)}static _drawMove(t){if(G.isSameTimeStamp(t.timeStamp),!e.#n)return;let{offsetX:n,offsetY:r,pointerId:i}=t;if(G.isSamePointerId(i)){if(G.isUsingMultiplePointers()){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,e.#n.add(n,r)),G.setTimeStamp(t.timeStamp),U(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,e.#n=null,e.#i=null,G.clearTimeStamp()),e.#r&&(e.#r.abort(),e.#r=null,G.clearPointerIds())}static _endDraw(t){let n=this._currentParent;if(n){if(n.toggleDrawing(!0),this._cleanup(!1),t?.target===n.div&&n.drawLayer.updateProperties(this._currentDrawId,e.#n.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let t=e.#n,r=this._currentDrawId,i=t.getLastElement();n.addCommands({cmd:()=>{n.drawLayer.updateProperties(r,t.setLastElement(i))},undo:()=>{n.drawLayer.updateProperties(r,t.removeLastElement())},mustExec:!1,type:C.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){let n=this._currentParent;if(!n)return null;if(n.toggleDrawing(!0),n.cleanUndoStack(C.DRAW_STEP),!e.#n.isEmpty()){let{pageDimensions:[r,i],scale:a}=n,o=n.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:e.#n.getOutlines(r*a,i*a,a,this._INNER_MARGIN),drawingOptions:e.#i,mustBeCommitted:!t});return this._cleanup(!0),o}return n.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,n,r,i,a){F(`Not implemented`)}static async deserialize(e,t,n){let{rawDims:{pageWidth:r,pageHeight:i,pageX:a,pageY:o}}=t.viewport,s=this.deserializeDraw(a,o,r,i,this._INNER_MARGIN,e),c=await super.deserialize(e,t,n);return c.createDrawingOptions(e),c.#a({drawOutlines:s}),c.#c(),c.onScaleChanging(),c.rotate(),c}serializeDraw(e){let[t,n]=this.pageTranslation,[r,i]=this.pageDimensions;return this.#e.serialize([t,n,r,i],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}},qi=class{#e=new Float64Array(6);#t;#n;#r;#i;#a;#o=``;#s=0;#c=new Ji;#l;#u;constructor(e,t,n,r,i,a){this.#l=n,this.#u=r,this.#r=i,this.#i=a,[e,t]=this.#d(e,t);let o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t],this.#n=[{line:o,points:this.#a}],this.#e.set(o,0)}updateProperty(e,t){e===`stroke-width`&&(this.#i=t)}#d(e,t){return Q._normalizePoint(e,t,this.#l,this.#u,this.#r)}isEmpty(){return!this.#n?.length}isCancellable(){return this.#a.length<=10}add(e,t){[e,t]=this.#d(e,t);let[n,r,i,a]=this.#e.subarray(2,6),o=e-i,s=t-a;return Math.hypot(this.#l*o,this.#u*s)<=2?null:(this.#a.push(e,t),isNaN(n)?(this.#e.set([i,a,e,t],2),this.#t.push(NaN,NaN,NaN,NaN,e,t),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([n,r,i,a,e,t],0),this.#t.push(...Q.createBezierPoints(n,r,i,a,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){return this.add(e,t)||(this.#a.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,r,i){this.#l=n,this.#u=r,this.#r=i,[e,t]=this.#d(e,t);let a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#a=[e,t];let o=this.#n.at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),this.#n.push({line:a,points:this.#a}),this.#e.set(a,0),this.#s=0,this.toSVGPath(),null}getLastElement(){return this.#n.at(-1)}setLastElement(e){return this.#n?(this.#n.push(e),this.#t=e.line,this.#a=e.points,this.#s=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(e)}removeLastElement(){if(!this.#n)return this.#c.removeLastElement();this.#n.pop(),this.#o=``;for(let e=0,t=this.#n.length;e<t;e++){let{line:t,points:n}=this.#n[e];this.#t=t,this.#a=n,this.#s=0,this.toSVGPath()}return{path:{d:this.#o}}}toSVGPath(){let e=Q.svgRound(this.#t[4]),t=Q.svgRound(this.#t[5]);if(this.#a.length===2)return this.#o=`${this.#o} M ${e} ${t} Z`,this.#o;if(this.#a.length<=6){let n=this.#o.lastIndexOf(`M`);this.#o=`${this.#o.slice(0,n)} M ${e} ${t}`,this.#s=6}if(this.#a.length===4){let e=Q.svgRound(this.#t[10]),t=Q.svgRound(this.#t[11]);return this.#o=`${this.#o} L ${e} ${t}`,this.#s=12,this.#o}let n=[];this.#s===0&&(n.push(`M ${e} ${t}`),this.#s=6);for(let e=this.#s,t=this.#t.length;e<t;e+=6){let[t,r,i,a,o,s]=this.#t.slice(e,e+6).map(Q.svgRound);n.push(`C${t} ${r} ${i} ${a} ${o} ${s}`)}return this.#o+=n.join(` `),this.#s=this.#t.length,this.#o}getOutlines(e,t,n,r){let i=this.#n.at(-1);return i.line=new Float32Array(i.line),i.points=new Float32Array(i.points),this.#c.build(this.#n,e,t,n,this.#r,this.#i,r),this.#e=null,this.#t=null,this.#n=null,this.#o=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:`0 0 10000 10000`},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Ji=class extends Q{#e;#t=0;#n;#r;#i;#a;#o;#s;#c;build(e,t,n,r,i,a,o){this.#i=t,this.#a=n,this.#o=r,this.#s=i,this.#c=a,this.#n=o??0,this.#r=e,this.#d()}get thickness(){return this.#c}setLastElement(e){return this.#r.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#r.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){let e=[];for(let{line:t}of this.#r){if(e.push(`M${Q.svgRound(t[4])} ${Q.svgRound(t[5])}`),t.length===6){e.push(`Z`);continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Q.svgRound(t[10])} ${Q.svgRound(t[11])}`);continue}for(let n=6,r=t.length;n<r;n+=6){let[r,i,a,o,s,c]=t.subarray(n,n+6).map(Q.svgRound);e.push(`C${r} ${i} ${a} ${o} ${s} ${c}`)}}return e.join(``)}serialize([e,t,n,r],i){let a=[],o=[],[s,c,l,u]=this.#u(),d,f,p,m,h,g,_,v,y;switch(this.#s){case 0:y=Q._rescale,d=e,f=t+r,p=n,m=-r,h=e+s*n,g=t+(1-c-u)*r,_=e+(s+l)*n,v=t+(1-c)*r;break;case 90:y=Q._rescaleAndSwap,d=e,f=t,p=n,m=r,h=e+c*n,g=t+s*r,_=e+(c+u)*n,v=t+(s+l)*r;break;case 180:y=Q._rescale,d=e+n,f=t,p=-n,m=r,h=e+(1-s-l)*n,g=t+c*r,_=e+(1-s)*n,v=t+(c+u)*r;break;case 270:y=Q._rescaleAndSwap,d=e+n,f=t+r,p=-n,m=-r,h=e+(1-c-u)*n,g=t+(1-s-l)*r,_=e+(1-c)*n,v=t+(1-s)*r;break}for(let{line:e,points:t}of this.#r)a.push(y(e,d,f,p,m,i?Array(e.length):null)),o.push(y(t,d,f,p,m,i?Array(t.length):null));return{lines:a,points:o,rect:[h,g,_,v]}}static deserialize(e,t,n,r,i,{paths:{lines:a,points:o},rotation:s,thickness:c}){let l=[],u,d,f,p,m;switch(s){case 0:m=Q._rescale,u=-e/n,d=t/r+1,f=1/n,p=-1/r;break;case 90:m=Q._rescaleAndSwap,u=-t/r,d=-e/n,f=1/r,p=1/n;break;case 180:m=Q._rescale,u=e/n+1,d=-t/r,f=-1/n,p=1/r;break;case 270:m=Q._rescaleAndSwap,u=t/r+1,d=e/n+1,f=-1/r,p=-1/n;break}if(!a){a=[];for(let e of o){let t=e.length;if(t===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1]]));continue}if(t===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,e[0],e[1],NaN,NaN,NaN,NaN,e[2],e[3]]));continue}let n=new Float32Array(3*(t-2));a.push(n);let[r,i,o,s]=e.subarray(0,4);n.set([NaN,NaN,NaN,NaN,r,i],0);for(let a=4;a<t;a+=2){let t=e[a],c=e[a+1];n.set(Q.createBezierPoints(r,i,o,s,t,c),(a-2)*3),[r,i,o,s]=[o,s,t,c]}}}for(let e=0,t=a.length;e<t;e++)l.push({line:m(a[e].map(e=>e??NaN),u,d,f,p),points:m(o[e].map(e=>e??NaN),u,d,f,p)});let h=new this.prototype.constructor;return h.build(l,n,r,1,s,c,i),h}#l(e=this.#c){let t=this.#n+e/2*this.#o;return this.#s%180==0?[t/this.#i,t/this.#a]:[t/this.#a,t/this.#i]}#u(){let[e,t,n,r]=this.#e,[i,a]=this.#l(0);return[e+i,t+a,n-2*i,r-2*a]}#d(){let e=this.#e=m.slice();for(let{line:t}of this.#r){if(t.length<=12){for(let n=4,r=t.length;n<r;n+=6)z.pointBoundingBox(t[n],t[n+1],e);continue}let n=t[4],r=t[5];for(let i=6,a=t.length;i<a;i+=6){let[a,o,s,c,l,u]=t.subarray(i,i+6);z.bezierBoundingBox(n,r,a,o,s,c,l,u,e),n=l,r=u}}let[t,n]=this.#l();e[0]=V(e[0]-t,0,1),e[1]=V(e[1]-n,0,1),e[2]=V(e[2]+t,0,1),e[3]=V(e[3]+n,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e===`stroke-width`?this.#f(t):null}#f(e){let[t,n]=this.#l();this.#c=e;let[r,i]=this.#l(),[a,o]=[r-t,i-n],s=this.#e;return s[0]-=a,s[1]-=o,s[2]+=2*a,s[3]+=2*o,s}updateParentDimensions([e,t],n){let[r,i]=this.#l();this.#i=e,this.#a=t,this.#o=n;let[a,o]=this.#l(),s=a-r,c=o-i,l=this.#e;return l[0]-=s,l[1]-=c,l[2]+=2*s,l[3]+=2*c,l}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Q.svgRound).join(` `)}get defaultProperties(){let[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`}}}get rotationTransform(){let[,,e,t]=this.#e,n=0,r=0,i=0,a=0,o=0,s=0;switch(this.#t){case 90:r=t/e,i=-e/t,o=e;break;case 180:n=-1,a=-1,o=e,s=t;break;case 270:r=-t/e,i=e/t,s=t;break;default:return``}return`matrix(${n} ${r} ${i} ${a} ${Q.svgRound(o)} ${Q.svgRound(s)})`}getPathResizingSVGProperties([e,t,n,r]){let[i,a]=this.#l(),[o,s,c,l]=this.#e;if(Math.abs(c-i)<=Q.PRECISION||Math.abs(l-a)<=Q.PRECISION){let i=e+n/2-(o+c/2),a=t+r/2-(s+l/2);return{path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:`${this.rotationTransform} translate(${i} ${a})`}}}let u=(n-2*i)/(c-2*i),d=(r-2*a)/(l-2*a),f=c/n,p=l/r;return{path:{"transform-origin":`${Q.svgRound(o)} ${Q.svgRound(s)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${Q.svgRound(i)} ${Q.svgRound(a)}) scale(${u} ${d}) translate(${Q.svgRound(-i)} ${Q.svgRound(-a)})`}}}getPathResizedSVGProperties([e,t,n,r]){let[i,a]=this.#l(),o=this.#e,[s,c,l,u]=o;if(o[0]=e,o[1]=t,o[2]=n,o[3]=r,Math.abs(l-i)<=Q.PRECISION||Math.abs(u-a)<=Q.PRECISION){let i=e+n/2-(s+l/2),a=t+r/2-(c+u/2);for(let{line:e,points:t}of this.#r)Q._translate(e,i,a,e),Q._translate(t,i,a,t);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let d=(n-2*i)/(l-2*i),f=(r-2*a)/(u-2*a),p=-d*(s+i)+e+i,m=-f*(c+a)+t+a;if(d!==1||f!==1||p!==0||m!==0)for(let{line:e,points:t}of this.#r)Q._rescale(e,p,m,d,f,e),Q._rescale(t,p,m,d,f,t);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){let[r,i]=n,a=this.#e,o=e-a[0],s=t-a[1];if(this.#i===r&&this.#a===i)for(let{line:e,points:t}of this.#r)Q._translate(e,o,s,e),Q._translate(t,o,s,t);else{let e=this.#i/r,t=this.#a/i;this.#i=r,this.#a=i;for(let{line:n,points:r}of this.#r)Q._rescale(n,o,s,e,t,n),Q._rescale(r,o,s,e,t,r);a[2]*=e,a[3]*=t}return a[0]=e,a[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Q.svgRound(e)} ${Q.svgRound(t)}`}}}get defaultSVGProperties(){let e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Q.svgRound(e[0])} ${Q.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}},Yi=class e extends Gi{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:`none`,stroke:K._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-miterlimit":10})}updateSVGProperty(e,t){e===`stroke-width`&&(t??=this[`stroke-width`],t*=this._viewParameters.realScale),super.updateSVGProperty(e,t)}clone(){let t=new e(this._viewParameters);return t.updateAll(this),t}},Xi=class e extends Ki{static _type=`ink`;static _editorType=S.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:`inkEditor`}),this._willKeepAspectRatio=!0,this.defaultL10nId=`pdfjs-editor-ink-editor`}static initialize(e,t){K.initialize(e,t),this._defaultDrawingOptions=new Yi(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return L(this,`typesMap`,new Map([[C.INK_THICKNESS,`stroke-width`],[C.INK_COLOR,`stroke`],[C.INK_OPACITY,`stroke-opacity`]]))}static createDrawerInstance(e,t,n,r,i){return new qi(e,t,n,r,i,this._defaultDrawingOptions[`stroke-width`])}static deserializeDraw(e,t,n,r,i,a){return Ji.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=null;if(e instanceof Di){let{data:{inkLists:t,rect:n,rotation:i,id:a,color:o,opacity:s,borderStyle:{rawWidth:c},popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},parent:{page:{pageNumber:m}}}=e;r=e={annotationType:S.INK,color:Array.from(o),thickness:c,opacity:s,paths:{points:t},boxes:null,pageIndex:m-1,rect:n.slice(0),rotation:i,annotationElementId:a,id:a,deleted:!1,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let i=await super.deserialize(e,t,n);return i._initialData=r,e.comment&&i.setCommentData(e),i}get toolbarButtons(){return this._colorPicker||=new Qr(this),[[`colorPicker`,this._colorPicker]]}get colorType(){return C.INK_COLOR}get colorAndOpacityType(){return C.INK_COLOR_AND_OPACITY}get opacityType(){return C.INK_OPACITY}updateParams(e,t){if(e===C.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(t.color,t.opacity);return}super.updateParams(e,t)}static updateDefaultParams(e,t){if(e===C.INK_COLOR_AND_OPACITY){super.updateDefaultParams(C.INK_COLOR,t.color),super.updateDefaultParams(C.INK_OPACITY,t.opacity);return}super.updateDefaultParams(e,t)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions[`stroke-opacity`]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty(`stroke-width`),n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){let e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty(`stroke-width`),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:n,opacity:r}){this._drawingOptions=e.getDefaultDrawingOptions({stroke:z.makeHexColor(...t),"stroke-width":n,"stroke-opacity":r})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":i,"stroke-width":a}}=this,o=Object.assign(super.serialize(e),{color:K._colorManager.convert(r),opacity:i,thickness:a,paths:{lines:t,points:n}});return this.addComment(o),e?(o.isCopy=!0,o):this.annotationElementId&&!this.#e(o)?null:(o.id=this.annotationElementId,o)}#e(e){let{color:t,thickness:n,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((e,n)=>e!==t[n])||e.thickness!==n||e.opacity!==r||e.pageIndex!==i}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let{points:t,rect:n}=this.serializeDraw(!1);return e.updateEdited({rect:n,thickness:this._drawingOptions[`stroke-width`],points:t,popup:this.comment}),null}},Zi=class extends Ji{toSVGPath(){let e=super.toSVGPath();return e.endsWith(`Z`)||(e+=`Z`),e}},Qi=8,$i=3,ea=class{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,r){return n-=e,r-=t,n===0?r>0?0:4:n===1?r+6:2-r}static#n=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#r(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(-i+s-o+16)%8,c=this.#n[2*a],l=this.#n[2*a+1];if(e[(n+c)*t+(r+l)]!==0)return a}return-1}static#i(e,t,n,r,i,a,o){let s=this.#t(n,r,i,a);for(let i=0;i<8;i++){let a=(i+s+o+16)%8,c=this.#n[2*a],l=this.#n[2*a+1];if(e[(n+c)*t+(r+l)]!==0)return a}return-1}static#a(e,t,n,r){let i=e.length,a=new Int32Array(i);for(let t=0;t<i;t++)a[t]=+(e[t]<=r);for(let e=1;e<n-1;e++)a[e*t]=a[e*t+t-1]=0;for(let e=0;e<t;e++)a[e]=a[t*n-1-e]=0;let o=1,s,c=[];for(let e=1;e<n-1;e++){s=1;for(let n=1;n<t-1;n++){let r=e*t+n,i=a[r];if(i===0)continue;let l=e,u=n;if(i===1&&a[r-1]===0)o+=1,--u;else if(i>=1&&a[r+1]===0)o+=1,u+=1,i>1&&(s=i);else{i!==1&&(s=Math.abs(i));continue}let d=[n,e],f=u===n+1,p={isHole:f,points:d,id:o,parent:0};c.push(p);let m;for(let e of c)if(e.id===s){m=e;break}m?m.isHole?p.parent=f?m.parent:s:p.parent=f?s:m.parent:p.parent=f?s:0;let h=this.#r(a,t,e,n,l,u,0);if(h===-1){a[r]=-o,a[r]!==1&&(s=Math.abs(a[r]));continue}let g=this.#n[2*h],_=this.#n[2*h+1],v=e+g,y=n+_;l=v,u=y;let b=e,x=n;for(;;){let i=this.#i(a,t,b,x,l,u,1);g=this.#n[2*i],_=this.#n[2*i+1];let c=b+g,f=x+_;d.push(f,c);let p=b*t+x;if(a[p+1]===0?a[p]=-o:a[p]===1&&(a[p]=o),c===e&&f===n&&b===v&&x===y){a[r]!==1&&(s=Math.abs(a[r]));break}else l=b,u=x,b=c,x=f}}}return c}static#o(e,t,n,r){if(n-t<=4){for(let i=t;i<n-2;i+=2)r.push(e[i],e[i+1]);return}let i=e[t],a=e[t+1],o=e[n-4]-i,s=e[n-3]-a,c=Math.hypot(o,s),l=o/c,u=s/c,d=l*a-u*i,f=s/o,p=1/c,m=Math.atan(f),h=Math.cos(m),g=Math.sin(m),_=p*(Math.abs(h)+Math.abs(g)),v=p*(1-_+_**2),y=Math.max(Math.atan(Math.abs(g+h)*v),Math.atan(Math.abs(g-h)*v)),b=0,x=t;for(let r=t+2;r<n-2;r+=2){let t=Math.abs(d-l*e[r+1]+u*e[r]);t>b&&(x=r,b=t)}b>(c*y)**2?(this.#o(e,t,x+2,r),this.#o(e,x,n,r)):r.push(i,a)}static#s(e){let t=[],n=e.length;return this.#o(e,0,n,t),t.push(e[n-2],e[n-1]),t.length<=4?null:t}static#c(e,t,n,r,i,a){let o=new Float32Array(a**2),s=-2*r**2,c=a>>1;for(let e=0;e<a;e++){let t=(e-c)**2;for(let n=0;n<a;n++)o[e*a+n]=Math.exp((t+(n-c)**2)/s)}let l=new Float32Array(256),u=-2*i**2;for(let e=0;e<256;e++)l[e]=Math.exp(e**2/u);let d=e.length,f=new Uint8Array(d),p=new Uint32Array(256);for(let r=0;r<n;r++)for(let i=0;i<t;i++){let s=r*t+i,u=e[s],d=0,m=0;for(let s=0;s<a;s++){let f=r+s-c;if(!(f<0||f>=n))for(let n=0;n<a;n++){let r=i+n-c;if(r<0||r>=t)continue;let p=e[f*t+r],h=o[s*a+n]*l[Math.abs(p-u)];d+=p*h,m+=h}}let h=f[s]=Math.round(d/m);p[h]++}return[f,p]}static#l(e){let t=new Uint32Array(256);for(let n of e)t[n]++;return t}static#u(e){let t=e.length,n=new Uint8ClampedArray(t>>2),r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t]=e[t<<2];r=Math.max(r,a),i=Math.min(i,a)}let a=255/(r-i);for(let e=0,t=n.length;e<t;e++)n[e]=(n[e]-i)*a;return n}static#d(e){let t,n=-1/0,r=-1/0,i=e.findIndex(e=>e!==0),a=i,o=i;for(t=i;t<256;t++){let i=e[t];i>n&&(t-a>r&&(r=t-a,o=t-1),n=i,a=t)}for(t=o-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#f(e){let t=e,{width:n,height:r}=e,{maxDim:i}=this.#e,a=n,o=r;if(n>i||r>i){let s=n,c=r,l=Math.log2(Math.max(n,r)/i),u=Math.floor(l);l=l===u?u-1:u;for(let n=0;n<l;n++){a=Math.ceil(s/2),o=Math.ceil(c/2);let n=new OffscreenCanvas(a,o);n.getContext(`2d`).drawImage(e,0,0,s,c,0,0,a,o),s=a,c=o,e!==t&&e.close(),e=n.transferToImageBitmap()}let d=Math.min(i/a,i/o);a=Math.round(a*d),o=Math.round(o*d)}let s=new OffscreenCanvas(a,o).getContext(`2d`,{willReadFrequently:!0});s.fillStyle=`white`,s.fillRect(0,0,a,o),s.filter=`grayscale(1)`,s.drawImage(e,0,0,e.width,e.height,0,0,a,o);let c=s.getImageData(0,0,a,o).data;return[this.#u(c),a,o]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:r},i,a,o,s){let c=new OffscreenCanvas(1,1),l=c.getContext(`2d`,{alpha:!1}),u=l.font=`${n} ${r} 200px ${t}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:f,actualBoundingBoxAscent:p,actualBoundingBoxDescent:m,fontBoundingBoxAscent:h,fontBoundingBoxDescent:g,width:_}=l.measureText(e),v=1.5,y=Math.ceil(Math.max(Math.abs(d)+Math.abs(f)||0,_)*v),b=Math.ceil(Math.max(Math.abs(p)+Math.abs(m)||200,Math.abs(h)+Math.abs(g)||200)*v);c=new OffscreenCanvas(y,b),l=c.getContext(`2d`,{alpha:!0,willReadFrequently:!0}),l.font=u,l.filter=`grayscale(1)`,l.fillStyle=`white`,l.fillRect(0,0,y,b),l.fillStyle=`black`,l.fillText(e,y*(v-1)/2,b*(3-v)/2);let x=this.#u(l.getImageData(0,0,y,b).data),S=this.#l(x),C=this.#d(S),w=this.#a(x,y,b,C);return this.processDrawnLines({lines:{curves:w,width:y,height:b},pageWidth:i,pageHeight:a,rotation:o,innerMargin:s,mustSmooth:!0,areContours:!0})}static process(e,t,n,r,i){let[a,o,s]=this.#f(e),[c,l]=this.#c(a,o,s,Math.hypot(o,s)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),u=this.#d(l),d=this.#a(c,o,s,u);return this.processDrawnLines({lines:{curves:d,width:o,height:s},pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:r,innerMargin:i,mustSmooth:a,areContours:o}){r%180!=0&&([t,n]=[n,t]);let{curves:s,width:c,height:l}=e,u=e.thickness??0,d=[],f=Math.min(t/c,n/l),p=f/t,m=f/n,h=[];for(let{points:e}of s){let t=a?this.#s(e):e;if(!t)continue;h.push(t);let n=t.length,r=new Float32Array(n),i=new Float32Array(3*(n===2?2:n-2));if(d.push({line:i,points:r}),n===2){r[0]=t[0]*p,r[1]=t[1]*m,i.set([NaN,NaN,NaN,NaN,r[0],r[1]],0);continue}let[o,s,c,l]=t;o*=p,s*=m,c*=p,l*=m,r.set([o,s,c,l],0),i.set([NaN,NaN,NaN,NaN,o,s],0);for(let e=4;e<n;e+=2){let n=r[e]=t[e]*p,a=r[e+1]=t[e+1]*m;i.set(Q.createBezierPoints(o,s,c,l,n,a),(e-2)*3),[o,s,c,l]=[c,l,n,a]}}if(d.length===0)return null;let g=o?new Zi:new Ji;return g.build(d,t,n,1,r,o?0:u,i),{outline:g,newCurves:h,areContours:o,thickness:u,width:c,height:l}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:r,height:i}){let a=1/0,o=-1/0,s=0;for(let t of e){s+=t.length;for(let e=2,n=t.length;e<n;e++){let n=t[e]-t[e-2];a=Math.min(a,n),o=Math.max(o,n)}}let c;c=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;let l=e.length,u=Qi+$i*l,d=new Uint32Array(u),f=0;d[f++]=u*Uint32Array.BYTES_PER_ELEMENT+(s-2*l)*c.BYTES_PER_ELEMENT,d[f++]=0,d[f++]=r,d[f++]=i,d[f++]=+!t,d[f++]=Math.max(0,Math.floor(n??0)),d[f++]=l,d[f++]=c.BYTES_PER_ELEMENT;for(let t of e)d[f++]=t.length-2,d[f++]=t[0],d[f++]=t[1];let p=new CompressionStream(`deflate-raw`),m=p.writable.getWriter();await m.ready,m.write(d);let h=c.prototype.constructor;for(let t of e){let e=new h(t.length-2);for(let n=2,r=t.length;n<r;n++)e[n-2]=t[n]-t[n-2];m.write(e)}return m.close(),(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(e){try{let t=Uint8Array.fromBase64(e),{readable:n,writable:r}=new DecompressionStream(`deflate-raw`),i=r.getWriter();await i.ready,i.write(t).then(async()=>{await i.ready,await i.close()}).catch(()=>{});let a=null,o=0;for await(let e of n)a||=new Uint8Array(new Uint32Array(e.buffer,0,4)[0]),a.set(e,o),o+=e.length;let s=new Uint32Array(a.buffer,0,a.length>>2),c=s[1];if(c!==0)throw Error(`Invalid version: ${c}`);let l=s[2],u=s[3],d=s[4]===0,f=s[5],p=s[6],m=s[7],h=[],g=(Qi+$i*p)*Uint32Array.BYTES_PER_ELEMENT,_;switch(m){case Int8Array.BYTES_PER_ELEMENT:_=new Int8Array(a.buffer,g);break;case Int16Array.BYTES_PER_ELEMENT:_=new Int16Array(a.buffer,g);break;case Int32Array.BYTES_PER_ELEMENT:_=new Int32Array(a.buffer,g);break}o=0;for(let e=0;e<p;e++){let t=s[$i*e+Qi],n=new Float32Array(t+2);h.push(n);for(let t=0;t<$i-1;t++)n[t]=s[$i*e+Qi+t+1];for(let e=0;e<t;e++)n[e+2]=n[e]+_[o++]}return{areContours:d,thickness:f,outlines:h,width:l,height:u}}catch(e){return P(`decompressSignature: ${e}`),null}}},ta=class e extends Gi{constructor(){super(),super.updateProperties({fill:K._defaultLineColor,"stroke-width":0})}clone(){let t=new e;return t.updateAll(this),t}},na=class e extends Yi{constructor(e){super(e),super.updateProperties({stroke:K._defaultLineColor,"stroke-width":1})}clone(){let t=new e(this._viewParameters);return t.updateAll(this),t}},ra=class e extends Ki{#e=!1;#t=null;#n=null;#r=null;static _type=`signature`;static _editorType=S.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:`signatureEditor`}),this._willKeepAspectRatio=!0,this.#n=e.signatureData||null,this.#t=null,this.defaultL10nId=`pdfjs-editor-signature-editor1`}static initialize(e,t){K.initialize(e,t),this._defaultDrawingOptions=new ta,this._defaultDrawnSignatureOptions=new na(t.viewParameters)}static getDefaultDrawingOptions(e){let t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return L(this,`typesMap`,new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:`signature`,hasDescription:!!this.#t}}static computeTelemetryFinalData(e){let t=e.get(`hasDescription`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let t,n,{_isCopy:r}=this;if(r&&(this._isCopy=!1,t=this.x,n=this.y),super.render(),this._drawId===null)if(this.#n){let{lines:t,mustSmooth:n,areContours:r,description:i,uuid:a,heightInPage:o}=this.#n,{rawDims:{pageWidth:s,pageHeight:c},rotation:l}=this.parent.viewport,u=ea.processDrawnLines({lines:t,pageWidth:s,pageHeight:c,rotation:l,innerMargin:e._INNER_MARGIN,mustSmooth:n,areContours:r});this.addSignature(u,o,i,a)}else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:``})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:this.#t||``}));return r&&(this._isCopy=!0,this._moveAfterPaste(t,n)),this.div}setUuid(e){this.#r=e,this.addEditToolbar()}getUuid(){return this.#r}get description(){return this.#t}set description(e){this.#t=e,this.div&&(this.div.setAttribute(`data-l10n-args`,JSON.stringify({description:e})),super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)}))}getSignaturePreview(){let{newCurves:e,areContours:t,thickness:n,width:r,height:i}=this.#n,a=Math.max(r,i);return{areContours:t,outline:ea.processDrawnLines({lines:{curves:e.map(e=>({points:e})),thickness:n,width:r,height:i},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[[`editSignature`,this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,n,r,i){let{x:a,y:o}=this,{outline:s}=this.#n=t;this.#e=s instanceof Zi,this.description=r;let c;this.#e?c=e.getDefaultDrawingOptions():(c=e._defaultDrawnSignatureOptions.clone(),c.updateProperties({"stroke-width":s.thickness})),this._addOutlines({drawOutlines:s,drawingOptions:c});let[,l]=this.pageDimensions,u=n/l;u=u>=1?.5:u,this.width*=u/this.height,this.width>=1&&(u*=.9/this.width,this.width=.9),this.height=u,this.setDims(),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:`pdfjs.signature.inserted`,data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return ea.process(t,n,r,i,e._INNER_MARGIN)}getFromText(t,n){let{rawDims:{pageWidth:r,pageHeight:i},rotation:a}=this.parent.viewport;return ea.extractContoursFromText(t,n,r,i,a,e._INNER_MARGIN)}getDrawnSignature(t){let{rawDims:{pageWidth:n,pageHeight:r},rotation:i}=this.parent.viewport;return ea.processDrawnLines({lines:t,pageWidth:n,pageHeight:r,rotation:i,innerMargin:e._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:n}){t?this._drawingOptions=e.getDefaultDrawingOptions():(this._drawingOptions=e._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":n}))}serialize(e=!1){if(this.isEmpty())return null;let{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":r}}=this,i=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:r});return this.addComment(i),e?(i.paths={lines:t,points:n},i.uuid=this.#r,i.isCopy=!0):i.lines=t,this.#t&&(i.accessibilityData={type:`Figure`,alt:this.#t}),i}static deserializeDraw(e,t,n,r,i,a){return a.areContours?Zi.deserialize(e,t,n,r,i,a):Ji.deserialize(e,t,n,r,i,a)}static async deserialize(e,t,n){let r=await super.deserialize(e,t,n);return r.#e=e.areContours,r.description=e.accessibilityData?.alt||``,r.#r=e.uuid,r}},ia=class extends K{#e=null;#t=null;#n=null;#r=null;#i=null;#a=``;#o=null;#s=!1;#c=null;#l=!1;#u=!1;static _type=`stamp`;static _editorType=S.STAMP;constructor(e){super({...e,name:`stampEditor`}),this.#r=e.bitmapUrl,this.#i=e.bitmapFile,this.defaultL10nId=`pdfjs-editor-stamp-editor`}static initialize(e,t){K.initialize(e,t)}static isHandlingMimeForPasting(e){return Ue.includes(e)}static paste(e,t){t.pasteEditor({mode:S.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:`stamp`,hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){let t=e.get(`hasAltText`);return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#d(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#l=e.isSvg),e.file&&(this.#a=e.file.name),this.#m()}#f(){if(this.#n=null,this._uiManager.enableWaiting(!1),this.#o){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this._reportTelemetry({action:`pdfjs.image.image_added`,data:{alt_text_modal:!1,alt_text_type:`empty`}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(e=null,t=!0){if(this.hasAltTextData())return null;let{mlManager:n}=this._uiManager;if(!n)throw Error(`No ML.`);if(!await n.isEnabledFor(`altText`))throw Error(`ML isn't enabled for alt text.`);let{data:r,width:i,height:a}=e||this.copyCanvas(null,null,!0).imageData,o=await n.guess({name:`altText`,request:{data:r,width:i,height:a,channels:r.length/(i*a)}});if(!o)throw Error(`No response from the AI service.`);if(o.error)throw Error(`Error from the AI service.`);if(o.cancel)return null;if(!o.output)throw Error(`No valid response from the AI service.`);let s=o.output;return await this.setGuessedAltText(s),t&&!this.hasAltTextData()&&(this.altTextData={alt:s,decorative:!1}),s}#p(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(e=>this.#d(e,!0)).finally(()=>this.#f());return}if(this.#r){let e=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromUrl(e).then(e=>this.#d(e)).finally(()=>this.#f());return}if(this.#i){let e=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#n=this._uiManager.imageManager.getFromFile(e).then(e=>this.#d(e)).finally(()=>this.#f());return}let e=document.createElement(`input`);e.type=`file`,e.accept=Ue.join(`,`);let t=this._uiManager._signal;this.#n=new Promise(n=>{e.addEventListener(`change`,async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);let t=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:`pdfjs.image.image_selected`,data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#d(t)}n()},{signal:t}),e.addEventListener(`cancel`,()=>{this.remove(),n()},{signal:t})}).finally(()=>this.#f()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#o?.remove(),this.#o=null,this.#c&&=(clearTimeout(this.#c),null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#p();return}super.rebuild(),this.div!==null&&(this.#t&&this.#o===null&&this.#p(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#n||this.#e||this.#r||this.#i||this.#t||this.#s)}get toolbarButtons(){return[[`altText`,this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;return this._isCopy&&(e=this.x,t=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#s||(this.#e?this.#m():this.#p()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){let{id:n,bitmap:r}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),n&&this._uiManager.imageManager.isValidId(n)&&(this.#t=n,r&&(this.#e=r),this.#s=!1,this.#m())}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(this.#c!==null&&clearTimeout(this.#c),this.#c=setTimeout(()=>{this.#c=null,this.#g()},200))}#m(){let{div:e}=this,{width:t,height:n}=this.#e,[r,i]=this.pageDimensions,a=.75;if(this.width)t=this.width*r,n=this.height*i;else if(t>a*r||n>a*i){let e=Math.min(a*r/t,a*i/n);t*=e,n*=e}this._uiManager.enableWaiting(!1);let o=this.#o=document.createElement(`canvas`);o.setAttribute(`role`,`img`),this.addContainer(o),this.width=t/r,this.height=n/i,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#g(),this.#u||=(this.parent.addUndoableEditor(this),!0),this._reportTelemetry({action:`inserted_image`}),this.#a&&this.div.setAttribute(`aria-description`,this.#a),this.annotationElementId||this._uiManager.a11yAlert(K._l10nAlert.stamp)}copyCanvas(e,t,n=!1){e||=224;let{width:r,height:i}=this.#e,a=new He,o=this.#e,s=r,c=i,l=null;if(t){if(r>t||i>t){let e=Math.min(t/r,t/i);s=Math.floor(r*e),c=Math.floor(i*e)}l=document.createElement(`canvas`);let e=l.width=Math.ceil(s*a.sx),n=l.height=Math.ceil(c*a.sy);this.#l||(o=this.#h(e,n));let u=l.getContext(`2d`);u.filter=this._uiManager.hcmFilter;let d=`white`,f=`#cfcfd8`;this._uiManager.hcmFilter===`none`?We.isDarkMode&&(d=`#8f8f9d`,f=`#42414d`):f=`black`;let p=15*a.sx,m=15*a.sy,h=new OffscreenCanvas(p*2,m*2),g=h.getContext(`2d`);g.fillStyle=d,g.fillRect(0,0,p*2,m*2),g.fillStyle=f,g.fillRect(0,0,p,m),g.fillRect(p,m,p,m),u.fillStyle=u.createPattern(h,`repeat`),u.fillRect(0,0,e,n),u.drawImage(o,0,0,o.width,o.height,0,0,e,n)}let u=null;if(n){let t,n;if(a.symmetric&&o.width<e&&o.height<e)t=o.width,n=o.height;else if(o=this.#e,r>e||i>e){let a=Math.min(e/r,e/i);t=Math.floor(r*a),n=Math.floor(i*a),this.#l||(o=this.#h(t,n))}let s=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});s.drawImage(o,0,0,o.width,o.height,0,0,t,n),u={width:t,height:n,data:s.getImageData(0,0,t,n).data}}return{canvas:l,width:s,height:c,imageData:u}}#h(e,t){let{width:n,height:r}=this.#e,i=n,a=r,o=this.#e;for(;i>2*e||a>2*t;){let n=i,r=a;i>2*e&&(i=Math.ceil(i/2)),a>2*t&&(a=Math.ceil(a/2));let s=new OffscreenCanvas(i,a);s.getContext(`2d`).drawImage(o,0,0,n,r,0,0,i,a),o=s.transferToImageBitmap()}return o}#g(){let[e,t]=this.parentDimensions,{width:n,height:r}=this,i=new He,a=Math.ceil(n*e*i.sx),o=Math.ceil(r*t*i.sy),s=this.#o;if(!s||s.width===a&&s.height===o)return;s.width=a,s.height=o;let c=this.#l?this.#e:this.#h(a,o),l=s.getContext(`2d`);l.filter=this._uiManager.hcmFilter,l.drawImage(c,0,0,c.width,c.height,0,0,a,o)}#_(e){if(e){if(this.#l){let e=this._uiManager.imageManager.getSvgUrl(this.#t);if(e)return e}let e=document.createElement(`canvas`);return{width:e.width,height:e.height}=this.#e,e.getContext(`2d`).drawImage(this.#e,0,0),e.toDataURL()}if(this.#l){let[e,t]=this.pageDimensions,n=Math.round(this.width*e*De.PDF_TO_CSS_UNITS),r=Math.round(this.height*t*De.PDF_TO_CSS_UNITS),i=new OffscreenCanvas(n,r);return i.getContext(`2d`).drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,n,r),i.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let r=null,i=!1;if(e instanceof Mi){let{data:{rect:a,rotation:o,id:s,structParent:c,popupRef:l,richText:u,contentsObj:d,creationDate:f,modificationDate:p},container:m,parent:{page:{pageNumber:h}},canvas:g}=e,_,v;g?(delete e.canvas,{id:_,bitmap:v}=n.imageManager.getFromCanvas(m.id,g),g.remove()):(i=!0,e._hasNoCanvas=!0);let y=(await t._structTree.getAriaAttributes(`${b}${s}`))?.get(`aria-label`)||``;r=e={annotationType:S.STAMP,bitmapId:_,bitmap:v,pageIndex:h-1,rect:a.slice(0),rotation:o,annotationElementId:s,id:s,deleted:!1,accessibilityData:{decorative:!1,altText:y},isSvg:!1,structParent:c,popupRef:l,richText:u,comment:d?.str||null,creationDate:f,modificationDate:p}}let a=await super.deserialize(e,t,n),{rect:o,bitmap:s,bitmapUrl:c,bitmapId:l,isSvg:u,accessibilityData:d}=e;i?(n.addMissingCanvas(e.id,a),a.#s=!0):l&&n.imageManager.isValidId(l)?(a.#t=l,s&&(a.#e=s)):a.#r=c,a.#l=u;let[f,p]=a.pageDimensions;return a.width=(o[2]-o[0])/f,a.height=(o[3]-o[1])/p,d&&(a.altTextData=d),a._initialData=r,e.comment&&a.setCommentData(e),a.#u=!!r,a}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});if(this.addComment(n),e)return n.bitmapUrl=this.#_(!0),n.accessibilityData=this.serializeAltText(!0),n.isCopy=!0,n;let{decorative:r,altText:i}=this.serializeAltText(!1);if(!r&&i&&(n.accessibilityData={type:`Figure`,alt:i}),this.annotationElementId){let e=this.#v(n);return e.isSame?null:(e.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1,n.id=this.annotationElementId,delete n.bitmapId,n)}if(t===null)return n;t.stamps||=new Map;let a=this.#l?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:a,serialized:n}),n.bitmap=this.#_(!1);else if(this.#l){let e=t.stamps.get(this.#t);a>e.area&&(e.area=a,e.serialized.bitmap.close(),e.serialized.bitmap=this.#_(!1))}return n}#v(e){let{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,r=e.pageIndex===t,i=(e.accessibilityData?.alt||``)===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&r&&i,isSameAltText:i}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}},aa=class e{#e;#t=!1;#n=null;#r=null;#i=null;#a=new Map;#o=!1;#s=!1;#c=!1;#l=null;#u=null;#d=null;#f=null;#p=null;#m=-1;#h;static _initialized=!1;static#g=new Map([Li,Xi,ia,Wi,ra].map(e=>[e._editorType,e]));constructor({uiManager:t,pageIndex:n,div:r,structTreeLayer:i,accessibilityManager:a,annotationLayer:o,drawLayer:s,textLayer:c,viewport:l,l10n:u}){let d=[...e.#g.values()];if(!e._initialized){e._initialized=!0;for(let e of d)e.initialize(u,t)}t.registerEditorTypes(d),this.#h=t,this.pageIndex=n,this.div=r,this.#e=a,this.#n=o,this.viewport=l,this.#d=c,this.drawLayer=s,this._structTree=i,this.#h.addLayer(this)}get isEmpty(){return this.#a.size===0}get isInvisible(){return this.isEmpty&&this.#h.getMode()===S.NONE}updateToolbar(e){this.#h.updateToolbar(e)}updateMode(t=this.#h.getMode()){switch(this.#S(),t){case S.NONE:this.div.classList.toggle(`nonEditing`,!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case S.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case S.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:n}=this.div;if(n.toggle(`nonEditing`,!1),t===S.POPUP)n.toggle(`commentEditing`,!0);else{n.toggle(`commentEditing`,!1);for(let r of e.#g.values())n.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#d?.div}setEditingState(e){this.#h.setEditingState(e)}addCommands(e){this.#h.addCommands(e)}cleanUndoStack(e){this.#h.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle(`drawing`,!e)}togglePointerEvents(e=!1){this.div.classList.toggle(`disabled`,!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#n?.togglePointerEvents(e)}get#_(){return this.#a.size===0?this.#h.getEditors(this.pageIndex):this.#a.values()}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle(`nonEditing`,!1),this.#p?.abort(),this.#p=null;let e=new Set;for(let t of this.#_)t.enableEditing(),t.show(!0),t.annotationElementId&&(this.#h.removeChangedExistingAnnotation(t),e.add(t.annotationElementId));let t=this.#n;if(t)for(let n of t.getEditableAnnotations()){if(n.hide(),this.#h.isDeletedAnnotationElement(n.data.id)||e.has(n.data.id))continue;let t=await this.deserialize(n);t&&(this.addOrRebuild(t),t.enableEditing())}this.#c=!1,this.#h._eventBus.dispatch(`editorsrendered`,{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#s=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle(`nonEditing`,!0),this.#d&&!this.#p){this.#p=new AbortController;let e=this.#h.combinedSignal(this.#p);this.#d.div.addEventListener(`pointerdown`,e=>{let{clientX:t,clientY:n,timeStamp:r}=e;if(r-this.#m>500){this.#m=r;return}this.#m=-1;let{classList:i}=this.div;i.toggle(`getElements`,!0);let a=document.elementsFromPoint(t,n);if(i.toggle(`getElements`,!1),!this.div.contains(a[0]))return;let o,s=RegExp(`^${x}[0-9]+$`);for(let e of a)if(s.test(e.id)){o=e.id;break}if(!o)return;let c=this.#a.get(o);c?.annotationElementId===null&&(U(e),c.dblclick(e))},{signal:e,capture:!0})}let t=this.#n,n=[];if(t){let e=new Map,r=new Map;for(let t of this.#_){if(t.disableEditing(),!t.annotationElementId){n.push(t);continue}if(t.serialize()!==null){e.set(t.annotationElementId,t);continue}else r.set(t.annotationElementId,t);this.getEditableAnnotation(t.annotationElementId)?.show(),t.remove()}for(let n of t.getEditableAnnotations()){let{id:t}=n.data;if(this.#h.isDeletedAnnotationElement(t)){n.updateEdited({deleted:!0});continue}let i=r.get(t);if(i){i.resetAnnotationElement(n),i.show(!1),n.show();continue}i=e.get(t),i&&(this.#h.addChangedExistingAnnotation(i),i.renderAnnotationElement(n)&&i.show(!1)),n.show()}}this.#S(),this.isEmpty&&(this.div.hidden=!0);let{classList:r}=this.div;for(let t of e.#g.values())r.remove(`${t._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(n),this.#s=!1}getEditableAnnotation(e){return this.#n?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#h.getActive()!==e&&this.#h.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#f){this.#f=new AbortController;let e=this.#h.combinedSignal(this.#f);this.#d.div.addEventListener(`pointerdown`,this.#v.bind(this),{signal:e}),this.#d.div.classList.add(`highlighting`)}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#d.div.classList.remove(`highlighting`))}#v(e){this.#h.unselectAll();let{target:t}=e;if(t===this.#d.div||(t.getAttribute(`role`)===`img`||t.classList.contains(`endOfContent`)||t.classList.contains(`textLayerImages`)||t.classList.contains(`textLayerImagePlaceholder`))&&this.#d.div.contains(t)){let{isMac:t}=R.platform;if(e.button!==0||e.ctrlKey&&t)return;this.#h.showAllEditors(`highlight`,!0,!0),this.#d.div.classList.add(`free`),this.toggleDrawing(),Wi.startHighlighting(this,this.#h.direction===`ltr`,{target:this.#d.div,x:e.x,y:e.y}),this.#d.div.addEventListener(`pointerup`,()=>{this.#d.div.classList.remove(`free`),this.toggleDrawing(!0)},{once:!0,signal:this.#h._signal}),e.preventDefault()}}enableClick(){if(this.#r)return;this.#r=new AbortController;let e=this.#h.combinedSignal(this.#r);this.div.addEventListener(`pointerdown`,this.pointerdown.bind(this),{signal:e});let t=this.pointerup.bind(this);this.div.addEventListener(`pointerup`,t,{signal:e}),this.div.addEventListener(`pointercancel`,t,{signal:e})}disableClick(){this.#r?.abort(),this.#r=null}attach(e){this.#a.set(e.id,e);let{annotationElementId:t}=e;t&&this.#h.isDeletedAnnotationElement(t)&&this.#h.removeDeletedAnnotationElement(e)}detach(e){this.#a.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#s&&e.annotationElementId&&this.#h.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#h.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#h.addDeletedAnnotationElement(e),K.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#h.addEditor(e),this.attach(e),!e.isAttachedToDOM){let t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#c),this.#h.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;let{activeElement:t}=document;e.div.contains(t)&&!this.#i&&(e._focusEventsAllowed=!1,this.#i=setTimeout(()=>{this.#i=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#h._signal}),t.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){this.addCommands({cmd:()=>e._uiManager.rebuild(e),undo:()=>{e.remove()},mustExec:!1})}getEditorByUID(e){for(let t of this.#a.values())if(t.uid===e)return t;return null}get#y(){return e.#g.get(this.#h.getMode())}combinedSignal(e){return this.#h.combinedSignal(e)}#b(e){let t=this.#y;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#y?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#h.updateMode(e.mode);let{offsetX:n,offsetY:r}=this.#x(),i=this.#h.getId(),a=this.#b({parent:this,id:i,x:n,y:r,uiManager:this.#h,isCentered:!0,...t});a&&this.add(a)}async deserialize(t){return await e.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#h)||null}createAndAddNewEditor(e,t,n={}){let r=this.#h.getId(),i=this.#b({parent:this,id:r,x:e.offsetX,y:e.offsetY,uiManager:this.#h,isCentered:t,...n});return i&&this.add(i),i}get boundingClientRect(){return this.div.getBoundingClientRect()}#x(){let{x:e,y:t,width:n,height:r}=this.boundingClientRect,i=Math.max(0,e),a=Math.max(0,t),o=Math.min(window.innerWidth,e+n),s=Math.min(window.innerHeight,t+r),c=(i+o)/2-e,l=(a+s)/2-t,[u,d]=this.viewport.rotation%180==0?[c,l]:[l,c];return{offsetX:u,offsetY:d}}addNewEditor(e={}){this.createAndAddNewEditor(this.#x(),!0,e)}setSelected(e){this.#h.setSelected(e)}toggleSelected(e){this.#h.toggleSelected(e)}unselect(e){this.#h.unselect(e)}pointerup(e){let{isMac:t}=R.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#o||(this.#o=!1,this.#y?.isDrawer&&this.#y.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}let n=this.#h.getMode();if(n===S.STAMP||n===S.POPUP||n===S.SIGNATURE){this.#h.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#h.getMode()===S.HIGHLIGHT&&this.enableTextSelection(),this.#o){this.#o=!1;return}let{isMac:t}=R.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#o=!0,this.#y?.isDrawer){this.startDrawingSession(e);return}let n=this.#h.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#l){this.#y.startDrawing(this,this.#h,!1,e);return}this.#h.setCurrentDrawingSession(this),this.#l=new AbortController;let t=this.#h.combinedSignal(this.#l);this.div.addEventListener(`blur`,({relatedTarget:e})=>{e&&!this.div.contains(e)&&(this.#u=null,this.commitOrRemove())},{signal:t}),this.#y.startDrawing(this,this.#h,!1,e)}pause(e){if(e){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e);return}this.#u&&setTimeout(()=>{this.#u?.focus(),this.#u=null},0)}endDrawingSession(e=!1){return this.#l?(this.#h.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#u=null,this.#y.endDrawing(e)):null}findNewParent(e,t,n){let r=this.#h.findParent(t,n);return r===null||r===this?!1:(r.changeParent(e),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#y.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#h.getActive()?.parent===this&&(this.#h.commitOrRemove(),this.#h.setActiveEditor(null)),this.#i&&=(clearTimeout(this.#i),null);for(let e of this.#a.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#a.clear(),this.#h.removeLayer(this)}#S(){for(let e of this.#a.values())e.isEmpty()&&e.remove()}async render({viewport:e}){this.viewport=e,Ve(this.div,e);for(let e of this.#h.getEditors(this.pageIndex))this.add(e),e.rebuild();await this.#h.findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:e}){this.#h.commitOrRemove(),this.#S();let t=this.viewport.rotation,n=e.rotation;if(this.viewport=e,Ve(this.div,{rotation:n}),t!==n)for(let e of this.#a.values())e.rotate(n)}get pageDimensions(){let{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#h.viewParameters.realScale}};function oa(e,t){return e===t?0:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function sa(e){return e?e.nodeType===Node.ELEMENT_NODE?e.closest(`.textLayer`):e.parentElement?.closest(`.textLayer`)||null:null}function ca(e,t,n,r){if(e===n)return t<=r;let i=e.compareDocumentPosition(n);return i&Node.DOCUMENT_POSITION_FOLLOWING?!0:i&Node.DOCUMENT_POSITION_PRECEDING?!1:null}function la(e,t,n){if(e.nodeType!==Node.ELEMENT_NODE||!e.classList.contains(`textLayer`)||t!==e.childNodes.length)return{container:e,offset:t};let r=e.lastChild;return r?.nodeType===Node.ELEMENT_NODE&&r.classList.contains(`endOfContent`)&&(r=r.previousSibling),!r||!n.contains(r)?null:r.nodeType===Node.TEXT_NODE?{container:r,offset:r.textContent.length}:{container:r,offset:r.childNodes.length}}var ua=class e{#e=null;#t=new Map;#n=null;#r=null;#i=null;#a=null;#o=new Map;static#s=0;static#c=0;static#l=null;static#u=new Set;static#d=!1;static#f=new Set;static#p=new WeakMap;constructor({filterFactory:t=null,pageColors:n=null,pageIndex:r,textLayer:i=null}){if(this.pageIndex=r,this.#r=t,this.#i=n,i){let t=e.#p.get(i);if(t?.selectionDiv&&(t.selectionDiv.remove(),e.#u.delete(t.selectionDiv)),e.#p.set(i,{drawLayer:this}),e.#f.add(i),this.#n=i,this.#a=new MutationObserver(t=>{if(!(!this.#e||!this.#n?.isConnected||!e.#h())){for(let{addedNodes:n}of t)for(let t of n)if(t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(`endOfContent`)){e.#_();return}}}),this.#a.observe(i,{childList:!0}),e.#l===null){e.#l=new AbortController;let{signal:t}=e.#l;document.addEventListener(`selectionchange`,e.#_.bind(e),{signal:t}),document.addEventListener(`pointerdown`,()=>{e.#d=!0},{signal:t}),document.addEventListener(`pointerup`,()=>{e.#d=!1},{signal:t}),window.addEventListener(`blur`,()=>{e.#d=!1},{signal:t})}}}setParent(t){if(!this.#e){this.#e=t,this.#n?.isConnected&&e.#h()&&e.#_();return}if(this.#e!==t){if(this.#t.size>0)for(let e of this.#t.values())e.remove(),t.append(e);this.#e=t}}static#m(e){let t=this.#p.get(e);t?.selectionDiv&&(t.selectionDiv.remove(),this.#u.delete(t.selectionDiv),t.selectionDiv=null,t.path=null)}static#h(){let e=document.getSelection();return!!e&&!e.isCollapsed}static#g(){return[...this.#f].filter(e=>e.isConnected).sort(oa)}static#_(){let t=document.getSelection();if(!t||t.isCollapsed){for(let e of this.#u)e.remove();this.#u.clear();return}let n=new WeakMap,r=this.#g(),i=[];for(let e=0,n=t.rangeCount;e<n;e++){let n=t.getRangeAt(e);if(n.collapsed)continue;let{startContainer:a,startOffset:o,endContainer:s,endOffset:c}=n,l=sa(a),u=sa(s),d=l===null,f=u===null;if(this.#d&&d!==f)return;if(t.rangeCount===1){let{anchorNode:e,anchorOffset:n,focusNode:r,focusOffset:i}=t,d=sa(e),f=sa(r),p=ca(e,n,r,i);d&&f&&p!==null&&(p?(a=e,o=n,l=d,s=r,c=i,u=f):(a=r,o=i,l=f,s=e,c=n,u=d))}let p=r.filter(e=>n.intersectsNode(e));if(p.length===0)continue;let m=!1;if(l||(l=p[0],a=l,o=0,m=!0),u||(u=p.at(-1),s=u,c=u.childNodes.length,m=!0),s.nodeType===Node.ELEMENT_NODE){if(s.classList.contains(`endOfContent`)){let e=s.previousSibling;if(!e)continue;s=e,c=e.nodeType===Node.TEXT_NODE?e.textContent.length:e.childNodes.length}else if(s.classList.contains(`textLayer`)&&s.childNodes.length===c){let e=la(s,c,u);if(!e)continue;s=e.container,c=e.offset}}if(a.nodeType===Node.ELEMENT_NODE){let e=la(a,o,l);if(!e)continue;a=e.container,o=e.offset}if(l===u&&!m&&p.includes(l)){i.push([n,l]);continue}for(let e of p){let t=e.firstChild;if(!t)continue;let n=document.createRange();if(e===l?n.setStart(a,o):n.setStartBefore(t),e===u)n.setEnd(s,c);else{let t=e.lastChild;if(!t)continue;if(t.nodeType===Node.ELEMENT_NODE&&t.classList.contains(`endOfContent`)){let e=t.previousSibling;if(!e)continue;n.setEndAfter(e)}else n.setEndAfter(t)}n.collapsed||i.push([n,e])}}let a=new Set(i.map(e=>e[1]));for(let e of this.#f)a.has(e)||this.#m(e);for(let[t,r]of i){let i=e.#p.get(r);if(!i)continue;let a=n.get(r);if(!a){let e=r.getBoundingClientRect();a=(t,n,r,i)=>({x:(t-e.x)/e.width,y:(n-e.y)/e.height,width:r/e.width,height:i/e.height}),n.set(r,a)}let o=[];for(let{x:e,y:n,width:r,height:i}of t.getClientRects())r===0||i===0||({x:e,y:n,width:r,height:i}=a(e,n,r,i),!(r===1&&i===1)&&o.push(`M${e} ${n} h${r} v${i} h-${r} Z`));if(o.length===0)continue;let s=i.drawLayer,c=i.selectionDiv,l=i.path;if(!c){let t=`clip_selection_${e.#c++}`;c=document.createElement(`div`),c.className=`selection`,c.style.clipPath=`url(#${t})`;let n=s.#r?.createSelectionStyle(s.#i);if(n)for(let[e,t]of Object.entries(n))c.style.setProperty(e,t);let r=e._svgFactory.create(1,1,!0);r.setAttribute(`aria-hidden`,`true`),r.setAttribute(`width`,`100%`),r.setAttribute(`height`,`100%`);let a=e._svgFactory.createElement(`clipPath`);a.setAttribute(`id`,t),a.setAttribute(`clipPathUnits`,`objectBoundingBox`),l=e._svgFactory.createElement(`path`),a.append(l),r.append(a),c.append(r),i.path=l,i.selectionDiv=c}!c.parentNode&&s.#e&&(s.#e.append(c),this.#u.add(c)),l.setAttribute(`d`,o.join(` `))}}static get _svgFactory(){return L(this,`_svgFactory`,new ri)}static#v(e,[t,n,r,i]){let{style:a}=e;a.top=`${100*n}%`,a.left=`${100*t}%`,a.width=`${100*r}%`,a.height=`${100*i}%`}#y(){let t=e._svgFactory.create(1,1,!0);return this.#e.append(t),t.setAttribute(`aria-hidden`,`true`),t}#b(t,n){let r=e._svgFactory.createElement(`clipPath`);t.append(r);let i=`clip_${n}`;r.setAttribute(`id`,i),r.setAttribute(`clipPathUnits`,`objectBoundingBox`);let a=e._svgFactory.createElement(`use`);return r.append(a),a.setAttribute(`href`,`#${n}`),a.classList.add(`clip`),i}#x(e,t){for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r)}draw(t,n=!1,r=!1){let i=e.#s++,a=this.#y(),o=e._svgFactory.createElement(`defs`);a.append(o);let s=e._svgFactory.createElement(`path`);o.append(s);let c=`path_${i}`;s.setAttribute(`id`,c),s.setAttribute(`vector-effect`,`non-scaling-stroke`),n&&this.#o.set(i,s);let l=r?this.#b(o,c):null,u=e._svgFactory.createElement(`use`);return a.append(u),u.setAttribute(`href`,`#${c}`),this.updateProperties(a,t),this.#t.set(i,a),{id:i,clipPathId:`url(#${l})`}}drawOutline(t,n){let r=e.#s++,i=this.#y(),a=e._svgFactory.createElement(`defs`);i.append(a);let o=e._svgFactory.createElement(`path`);a.append(o);let s=`path_${r}`;o.setAttribute(`id`,s),o.setAttribute(`vector-effect`,`non-scaling-stroke`);let c;if(n){let t=e._svgFactory.createElement(`mask`);a.append(t),c=`mask_${r}`,t.setAttribute(`id`,c),t.setAttribute(`maskUnits`,`objectBoundingBox`);let n=e._svgFactory.createElement(`rect`);t.append(n),n.setAttribute(`width`,`1`),n.setAttribute(`height`,`1`),n.setAttribute(`fill`,`white`);let i=e._svgFactory.createElement(`use`);t.append(i),i.setAttribute(`href`,`#${s}`),i.setAttribute(`stroke`,`none`),i.setAttribute(`fill`,`black`),i.setAttribute(`fill-rule`,`nonzero`),i.classList.add(`mask`)}let l=e._svgFactory.createElement(`use`);i.append(l),l.setAttribute(`href`,`#${s}`),c&&l.setAttribute(`mask`,`url(#${c})`);let u=l.cloneNode();return i.append(u),l.classList.add(`mainOutline`),u.classList.add(`secondaryOutline`),this.updateProperties(i,t),this.#t.set(r,i),r}finalizeDraw(e,t){this.#o.delete(e),this.updateProperties(e,t)}updateProperties(t,n){if(!n)return;let{root:r,bbox:i,rootClass:a,path:o}=n,s=typeof t==`number`?this.#t.get(t):t;if(s){if(r&&this.#x(s,r),i&&e.#v(s,i),a){let{classList:e}=s;for(let[t,n]of Object.entries(a))e.toggle(t,n)}if(o){let e=s.firstElementChild.firstElementChild;this.#x(e,o)}}}updateParent(e,t){if(t===this)return;let n=this.#t.get(e);n&&(t.#e.append(n),this.#t.delete(e),t.#t.set(e,n))}remove(e){this.#o.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(let e of this.#t.values())e.remove();this.#t.clear(),this.#o.clear(),this.#a?.disconnect(),this.#a=null,this.#n&&=(e.#p.get(this.#n)?.drawLayer===this&&(e.#m(this.#n),e.#p.delete(this.#n),e.#f.delete(this.#n),e.#f.size===0&&(e.#l?.abort(),e.#l=null,e.#d=!1)),null)}};function da(e){return`${(e*100).toFixed(2)}%`}var fa=class e{#e=[];#t=new Map;#n=null;#r=0;#i=0;#a=0;static#o=null;constructor(e,t,n,r){this.#r=e,this.#e=t,this.#i=n.rawDims.pageWidth,this.#a=n.rawDims.pageHeight,this.#n=r}render(){let t=document.createElement(`div`);t.className=`textLayerImages`;for(let e=0;e<this.#e.length;e+=6){let n=this.#s(this.#e.subarray(e,e+6));n&&t.append(n)}return t.addEventListener(`contextmenu`,t=>{if(!(t.target instanceof HTMLCanvasElement))return;let n=t.target,r=this.#t.get(n);if(!r)return;let i=e.#o?.deref();if(i===n)return;i&&(i.width=0,i.height=0),e.#o=new WeakRef(n);let{inverseTransform:a,x1:o,y1:s,width:c,height:l}=r,u=this.#n(),d=Math.ceil(o*u.width),f=Math.ceil(s*u.height),p=Math.floor((o+c/this.#i)*u.width),m=Math.floor((s+l/this.#a)*u.height);n.width=p-d,n.height=m-f;let h=n.getContext(`2d`);h.setTransform(...a),h.translate(-d,-f),h.drawImage(u,0,0)}),t}#s([e,t,n,r,i,a]){let o=Math.hypot((i-e)*this.#i,(a-t)*this.#a),s=Math.hypot((n-e)*this.#i,(r-t)*this.#a);if(o<this.#r||s<this.#r)return null;let c=[(i-e)*this.#i/o,(a-t)*this.#a/o,(n-e)*this.#i/s,(r-t)*this.#a/s,0,0],l=z.inverseTransform(c),u=document.createElement(`canvas`);return u.className=`textLayerImagePlaceholder`,u.width=0,u.height=0,Object.assign(u.style,{opacity:0,position:`absolute`,left:da(e),top:da(t),width:da(o/this.#i),height:da(s/this.#a),transformOrigin:`0% 0%`,transform:`matrix(${c.join(`,`)})`}),this.#t.set(u,{inverseTransform:l,width:o,height:s,x1:e,y1:t}),u}};globalThis._pdfjsTestingUtils={HighlightOutliner:Bi},globalThis.pdfjsLib={AbortException:pe,AnnotationEditorLayer:aa,AnnotationEditorParamsType:C,AnnotationEditorType:S,AnnotationEditorUIManager:ut,AnnotationLayer:Fi,AnnotationMode:y,AnnotationType:D,applyOpacity:Ke,build:Xr,ColorPicker:Zr,createValidAbsoluteUrl:ie,CSSConstants:Ge,DOMSVGFactory:ri,DrawLayer:ua,FeatureTest:R,fetchData:Oe,findContrastColor:Qe,getDocument:Br,getFilenameFromUrl:Me,getPdfFilenameFromUrl:Ne,getRGB:Re,getRGBA:Le,getUuid:ye,GlobalWorkerOptions:Dr,ImageKind:E,InvalidPDFException:ue,isDataScheme:Ae,isPdfFile:je,isValidExplicitDest:Xt,makeArr:xe,makeMap:Se,makeObj:Ce,MathClamp:V,noContextMenu:H,normalizeUnicode:ve,OPS:A,OutputScale:He,PasswordException:ce,PasswordResponses:ee,PDFDataRangeTransport:Hr,PDFDateString:Ie,PDFWorker:Gr,PermissionFlag:w,PixelsPerInch:De,RenderingCancelledException:ke,renderRichText:$e,ResponseException:de,setLayerDimensions:Ve,shadow:L,SignatureExtractor:ea,stopEvent:U,SupportedImageMimeTypes:Ue,TextLayer:Rr,TextLayerImages:fa,TouchManager:pt,updateUrlHash:ae,Util:z,VerbosityLevel:k,version:Yr,XfaLayer:Ee};var pa=`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`,ma=[`#000000`,`#475569`,`#dc2626`,`#f97316`,`#eab308`,`#16a34a`,`#2563eb`,`#7c3aed`,`#db2777`,`#ffffff`],ha=[`transparent`,`#f8fafc`,`#fee2e2`,`#ffedd5`,`#fef9c3`,`#dcfce7`,`#dbeafe`,`#f3e8ff`,`#fce7f3`,`#ffffff`],ga=e=>{let t=`font-size: ${e.fontSize}; color: ${e.color}; text-align: ${e.textAlign};`;e.fontFamily&&(t+=` font-family: ${e.fontFamily};`),t+=` font-weight: ${e.fontWeight};`,e.bold&&(t+=` font-weight: bold;`),e.italic&&(t+=` font-style: italic;`);let n=[];e.underline&&n.push(`underline`),e.strikethrough&&n.push(`line-through`),n.length>0&&(t+=` text-decoration: ${n.join(` `)};`);let r=[`fontSize`,`fontWeight`,`color`,`textAlign`,`fontFamily`,`bold`,`italic`,`underline`,`strikethrough`,`customCss`,`sameRow`];return Object.entries(e).forEach(([e,n])=>{if(r.includes(e)||n==null||n===``)return;let i=e.replace(/([A-Z])/g,`-$1`).toLowerCase();t+=` ${i}: ${n};`}),e.customCss&&(t+=` ${e.customCss}`),t},_a=e=>{if(!e||!e.trim())return{};let t={};return e.split(`;`).forEach(e=>{let n=e.split(`:`);if(n.length>=2){let e=n[0].trim().replace(/-([a-z])/g,e=>e[1].toUpperCase()),r=n.slice(1).join(`:`).trim();e&&r&&(t[e]=r)}}),t},va=e=>{let t={0:`1010011`,1:`1101001`,2:`1100101`,3:`1001101`,4:`1011001`,5:`1010011`,6:`1101011`,7:`1101101`,8:`1001111`,9:`1110011`,A:`1100010`,B:`1000110`,C:`1100011`,D:`1011100`,E:`1001110`,F:`1110100`,G:`1110010`,H:`1101110`,I:`1100111`,J:`1011000`,K:`1000111`,L:`1100011`,M:`1011110`,N:`1111010`,O:`1110110`,P:`1110011`,Q:`1110010`,R:`1101110`,S:`1100111`,T:`1011000`,U:`1000111`,V:`1100011`,W:`1011110`,X:`1111010`,Y:`1110110`,Z:`1110011`,"-":`1001011`,_:`1101001`,".":`1100101`," ":`1001101`},n=e||`BARCODE`,r=n.toUpperCase().replace(/[^0-9A-Z\-_\. ]/g,``),i=`1101001000`;for(let e=0;e<r.length;e++){let n=r[e];i+=t[n]||`1010011`}i+=`1100011101011`;let a=i.length*2,o=``;for(let e=0;e<i.length;e++)i[e]===`1`&&(o+=`<rect x="${e*2}" y="5" width="2" height="50" fill="black" />`);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${a} 70" width="100%" height="100%" style="display: block; margin: 0 auto;">
55
55
  <rect width="100%" height="100%" fill="white" />
56
56
  <g>${o}</g>
57
57
  <text x="${a/2}" y="67" font-family="monospace" font-size="10" text-anchor="middle" fill="black">${n}</text>
58
- </svg>`},ya=(e,t)=>{let n=`11px`,r=`400`;return e===`h1`?(n=`24px`,r=`700`):e===`h2`?(n=`20px`,r=`700`):e===`h3`?(n=`16px`,r=`600`):e===`h4`?(n=`14px`,r=`600`):e===`h5`?(n=`12px`,r=`600`):e===`h6`?(n=`10px`,r=`600`):e===`title`?(n=`28px`,r=`800`):e===`subtitle`?(n=`14px`,r=`300`):e===`caption`&&(n=`9px`,r=`400`),{id:`block-${Math.random().toString(36).substr(2,9)}`,type:e,content:t,style:{fontSize:n,fontWeight:r,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`title`].includes(e),italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`8px`,padding:`8px`,minHeight:`auto`}}},ba=e=>{let t=new DOMParser().parseFromString(e,`text/html`),n=[],r=Array.from(t.body.children);if(r.length===0){let e=t.body.innerText||t.body.textContent||``;e.trim()&&n.push(ya(`p`,e.trim()))}else{let e=t.querySelectorAll(`style`),i=[];e.forEach(e=>{let t=e.textContent||``,n=/([^{]+)\{([^}]+)\}/g,r;for(;(r=n.exec(t))!==null;){let e=r[1].trim(),t=r[2].trim(),n={};t.split(`;`).forEach(e=>{let t=e.split(`:`);t.length===2&&(n[t[0].trim().toLowerCase()]=t[1].trim())}),i.push({selector:e,styles:n})}});let a=e=>{let t={fontSize:`11px`,fontWeight:`400`,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:!1,italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`8px`,padding:`8px`},n=e.style;return n.fontSize&&(t.fontSize=n.fontSize),n.fontWeight&&(t.fontWeight=n.fontWeight),n.color&&(t.color=n.color),n.backgroundColor&&(t.backgroundColor=n.backgroundColor),n.textAlign&&(t.textAlign=n.textAlign),n.padding&&(t.padding=n.padding),n.marginBottom&&(t.marginBottom=n.marginBottom),n.width&&(t.width=n.width),i.forEach(n=>{try{e.matches(n.selector)&&(n.styles[`font-size`]&&(t.fontSize=n.styles[`font-size`]),n.styles[`font-weight`]&&(t.fontWeight=n.styles[`font-weight`]),n.styles.color&&(t.color=n.styles.color),n.styles[`background-color`]&&(t.backgroundColor=n.styles[`background-color`]),n.styles[`text-align`]&&(t.textAlign=n.styles[`text-align`]),n.styles.padding&&(t.padding=n.styles.padding),n.styles[`margin-bottom`]&&(t.marginBottom=n.styles[`margin-bottom`]),n.styles.width&&(t.width=n.styles.width))}catch{}}),(t.fontWeight===`bold`||parseInt(t.fontWeight)>=600)&&(t.bold=!0),t};r.forEach(e=>{let t=e;if(t.tagName===`STYLE`)return;let r=t.querySelector(`table, img, h1, h2, h3, h4, h5, h6, p, span, div`)||t,i=r.tagName.toLowerCase(),o=a(r);if(i===`table`){let e=Array.from(r.querySelectorAll(`thead th`));e.length===0&&(e=Array.from(r.querySelectorAll(`tr:first-child th, tr:first-child td`)));let t=e.map(e=>({columnName:e.textContent?.trim()||`Header`,placeholder:`{{item.${e.textContent?.trim().toLowerCase().replace(/\s+/g,`_`)||`field`}}}`,enabled:!0}));n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`table`,content:``,style:o,tableInfo:{tableName:`imported_table`,columns:t,loop:!0,isNestable:!1,parentPath:`items`,maxNestingDepth:5,nestingPrefix:` `,showNestingLevel:!1}})}else if(i===`img`)n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`image`,content:``,style:o,imageInfo:{imageType:`logo`,url:r.getAttribute(`src`)||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}});else if(i===`svg`)n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`image`,content:``,style:o,imageInfo:{imageType:`barcode`,barcodeValue:`SHIP-99201`,barcodePlaceholder:`{{barcode}}`}});else{let e=`p`;[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`].includes(i)?e=i:i===`span`&&(e=`caption`),n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:e,content:r.innerHTML||r.textContent||``,style:o})}})}return n},xa=async(e,t)=>{let n=await t.getDocument({data:new Uint8Array(e)}).promise,r=[],i=Math.min(n.numPages,3);for(let e=1;e<=i;e++){let t=(await(await n.getPage(e)).getTextContent()).items.map(e=>({text:e.str,x:e.transform[4],y:e.transform[5],fontSize:e.transform[3]})).filter(e=>e.text.trim()!==``);if(t.length===0)continue;t.sort((e,t)=>Math.abs(e.y-t.y)<6?e.x-t.x:t.y-e.y);let i=[],a=[];if(t.forEach(e=>{if(a.length===0)a.push(e);else{let t=a[a.length-1];if(Math.abs(e.y-t.y)<6)a.push(e);else{let t=a.map(e=>e.text).join(` `),n=a.reduce((e,t)=>e+t.y,0)/a.length,r=Math.max(...a.map(e=>e.fontSize));i.push({y:n,fontSize:r,text:t}),a=[e]}}}),a.length>0){let e=a.map(e=>e.text).join(` `),t=a.reduce((e,t)=>e+t.y,0)/a.length,n=Math.max(...a.map(e=>e.fontSize));i.push({y:t,fontSize:n,text:e})}i.forEach(e=>{let t=`p`,n=e.fontSize>16;n?t=e.fontSize>26?`h1`:e.fontSize>20?`h2`:`h3`:e.fontSize<10&&(t=`caption`);let i=Math.round(e.fontSize*1.15)+`px`;r.push({id:`pdf-block-${Math.random().toString(36).substr(2,9)}`,type:t,content:e.text,style:{fontSize:i,fontWeight:n?`700`:`400`,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:n,italic:!1,underline:!1,strikethrough:!1}})})}return r};function Sa({initialBlocks:e,defaultStyles:t,defaultLogo:n,defaultBanner:r,onChange:i}={}){let[a,o]=(0,l.useState)(e||[]),[s,c]=(0,l.useState)(null);(0,l.useEffect)(()=>{i&&i(a)},[a,i]);let u=()=>a.find(e=>e.id===s)||null,d=(e,t,n)=>{let r={};return e===`title`?r={fontSize:`24px`,fontWeight:`800`}:e===`subtitle`?r={fontSize:`14px`,fontWeight:`700`,color:`#64748b`}:e===`h1`?r={fontSize:`20px`,fontWeight:`800`}:e===`h2`?r={fontSize:`18px`,fontWeight:`700`}:e===`h3`?r={fontSize:`16px`,fontWeight:`600`}:e===`caption`&&(r={fontSize:`10px`,color:`#94a3b8`}),{id:Math.random().toString(36).substring(2,11),type:e,content:t,style:{fontSize:`12px`,fontWeight:`normal`,textAlign:`left`,color:`#1e293b`,backgroundColor:`transparent`,marginBottom:`0px`,padding:`0px`,bold:!1,italic:!1,underline:!1,strikethrough:!1,...r,...n}}},f=e=>({...e,columns:e.columns?e.columns.map(f):void 0});return{blocks:a,setBlocks:o,selectedBlockId:s,setSelectedBlockId:c,getSelectedBlock:u,createTextBlock:d,createTableBlock:e=>({id:Math.random().toString(36).substring(2,11),type:`table`,content:``,style:{fontSize:`11px`,fontWeight:`normal`,textAlign:`left`,color:`#334155`,backgroundColor:`transparent`,marginBottom:`0px`,padding:`0px`,bold:!1,italic:!1,underline:!1,strikethrough:!1,...t?.table||{}},tableInfo:{...e,columns:e.columns.map(f),mockRows:[]}}),createImageBlock:e=>{let i=`100%`,a=`120px`;return e===`logo`?(i=`120px`,a=`60px`):e===`banner`?(i=`100%`,a=`150px`):e===`barcode`?(i=`200px`,a=`80px`):e===`watermark`&&(i=`300px`,a=`300px`),{id:Math.random().toString(36).substring(2,11),type:`image`,content:``,style:{fontSize:`12px`,fontWeight:`normal`,color:`#000055`,backgroundColor:`transparent`,textAlign:`center`,marginBottom:`0px`,padding:`0px`,width:i,height:a,minHeight:a,bold:!1,italic:!1,underline:!1,strikethrough:!1,...t?.image||{},...e===`watermark`?{opacity:`0.2`,position:`absolute`,top:`0`,left:`0`,zIndex:10,height:`100%`}:{}},imageInfo:{imageType:e,url:e===`logo`?n||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`:e===`banner`?r||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`:pa,barcodeValue:e===`barcode`?`SHIP-99201`:void 0,barcodePlaceholder:e===`barcode`?`{{barcode}}`:void 0}}},handleDeleteBlock:e=>{o(t=>t.filter(t=>t.id!==e)),s===e&&c(null)},handleDuplicateBlock:e=>{let t=a.find(t=>t.id===e);if(!t)return;let n={...t,id:Math.random().toString(36).substring(2,11),style:{...t.style},tableInfo:t.tableInfo?{...t.tableInfo,columns:t.tableInfo.columns.map(f),mockRows:t.tableInfo.mockRows?[...t.tableInfo.mockRows]:void 0}:void 0,imageInfo:t.imageInfo?{...t.imageInfo}:void 0},r=a.findIndex(t=>t.id===e);o(e=>{let t=[...e];return t.splice(r+1,0,n),t}),c(n.id)},handleMoveBlockUp:e=>{e!==0&&o(t=>{let n=[...t],r=n[e];return n[e]=n[e-1],n[e-1]=r,n})},handleMoveBlockDown:e=>{e!==a.length-1&&o(t=>{let n=[...t],r=n[e];return n[e]=n[e+1],n[e+1]=r,n})},updateSelectedStyle:(e,t)=>{s&&o(n=>n.map(n=>n.id===s?{...n,style:{...n.style,[e]:t}}:n))},updateSelectedImageInfo:(e,t)=>{s&&o(i=>i.map(i=>{if(i.id===s&&i.type===`image`){let a={};return e===`imageType`&&(a=t===`logo`?{url:n||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}:t===`banner`?{url:r||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}:t===`barcode`?{barcodeValue:`SHIP-99201`,barcodePlaceholder:`{{barcode}}`}:{url:pa}),{...i,imageInfo:{...i.imageInfo,[e]:t,...a}}}return i}))},handleRemoveTableColumn:(e,t)=>{s&&o(n=>n.map(n=>{if(n.id===s&&n.type===`table`&&n.tableInfo){let r=[...n.tableInfo.columns];if(t!==void 0&&r[e]?.columns){let n=r[e].columns.filter((e,n)=>n!==t);r[e]={...r[e],columns:n}}else r.splice(e,1);return{...n,tableInfo:{...n.tableInfo,columns:r}}}return n}))},handleAddTableColumn:(e,t,n,r)=>{!s||!e.trim()||o(i=>i.map(i=>{if(i.id===s&&i.type===`table`&&i.tableInfo){let a=[...i.tableInfo.columns];if(r!==void 0&&a[r]){let n=a[r].columns||[];a[r]={...a[r],loop:!0,columns:[...n,{columnName:e.trim(),placeholder:t.trim(),enabled:!0}]}}else n?a.push({columnName:e.trim(),placeholder:t.trim(),enabled:!0,loop:!0,columns:[{columnName:`Item Name`,placeholder:`{{item.name}}`,enabled:!0},{columnName:`Price`,placeholder:`{{item.price}}`,enabled:!0}]}):a.push({columnName:e.trim(),placeholder:t.trim(),enabled:!0});return{...i,tableInfo:{...i.tableInfo,columns:a}}}return i}))},handleUpdateTableColumn:(e,t,n,r)=>{s&&o(i=>i.map(i=>{if(i.id===s&&i.type===`table`&&i.tableInfo){let a=[...i.tableInfo.columns];if(r!==void 0&&a[e]?.columns){let i=[...a[e].columns];i[r]={...i[r],columnName:t.trim(),placeholder:n.trim()},a[e]={...a[e],columns:i}}else a[e]&&(a[e]={...a[e],columnName:t.trim(),placeholder:n.trim()});return{...i,tableInfo:{...i.tableInfo,columns:a}}}return i}))},handleReorderTableColumn:(e,t,n)=>{s&&o(r=>r.map(r=>{if(r.id===s&&r.type===`table`&&r.tableInfo){let i=[...r.tableInfo.columns];if(n!==void 0&&i[e]?.columns){let r=[...i[e].columns],a=t===`up`?n-1:n+1;if(a>=0&&a<r.length){let t=r[n];r[n]=r[a],r[a]=t,i[e]={...i[e],columns:r}}}else{let n=t===`up`?e-1:e+1;if(n>=0&&n<i.length){let t=i[e];i[e]=i[n],i[n]=t}}return{...r,tableInfo:{...r.tableInfo,columns:i}}}return r}))}}}function Ca(){let[e,t]=(0,l.useState)(1),[n,r]=(0,l.useState)({x:0,y:0}),[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(1123),d=(0,l.useRef)({x:0,y:0}),f=(0,l.useRef)(null),p=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{let t=document.activeElement,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.getAttribute(`contenteditable`)===`true`);e.code===`Space`&&!n&&(s(!0),e.preventDefault())},t=e=>{e.code===`Space`&&s(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]),(0,l.useEffect)(()=>{if(!p.current)return;let e=new ResizeObserver(e=>{for(let t of e)u(t.target.scrollHeight)});return e.observe(p.current),()=>e.disconnect()},[]),{zoom:e,setZoom:t,panOffset:n,setPanOffset:r,isPanning:i,setIsPanning:a,spacePressed:o,setSpacePressed:s,canvasHeight:c,setCanvasHeight:u,viewportRef:f,canvasContainerRef:p,handleMouseDown:e=>{o&&(a(!0),d.current={x:e.clientX-n.x,y:e.clientY-n.y})},handleMouseMove:e=>{i&&o&&r({x:e.clientX-d.current.x,y:e.clientY-d.current.y})},handleMouseUp:()=>{a(!1)},handleZoomIn:()=>t(e=>Math.min(e+.1,2)),handleZoomOut:()=>t(e=>Math.max(e-.1,.5)),handleZoomReset:()=>{t(1),r({x:0,y:0})}}}function wa({tableSchemas:e}={}){let[t,n]=(0,l.useState)(`invoice_items`),[r,i]=(0,l.useState)(`{% for item in invoice.items %}`),[a,o]=(0,l.useState)(`{% endfor %}`),[s,c]=(0,l.useState)(``),[u,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)([]),[g,_]=(0,l.useState)(!1),[v,y]=(0,l.useState)(``),[b,x]=(0,l.useState)(null),[S,C]=(0,l.useState)(``),[w,T]=(0,l.useState)(null),[E,D]=(0,l.useState)(null),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),M=e=>({columnName:e.columnName||e.columnNameEn||e.columnNameDe||``,placeholder:e.placeholder||``,enabled:e.enabled!==!1,loop:!!e.loop,columns:Array.isArray(e.columns)?e.columns.map(M):void 0});(0,l.useEffect)(()=>{e&&e.length>0?h(e.map(e=>({...e,columns:e.columns.map(M)}))):h([])},[e]);let ee=()=>{if(!t.trim())return;let e={tableName:t.trim().replace(/\s+/g,`_`).toLowerCase(),columns:[{columnName:`Description`,placeholder:`{{description}}`,enabled:!0},{columnName:`Qty`,placeholder:`{{quantity}}`,enabled:!0},{columnName:`Total Price`,placeholder:`{{total_price}}`,enabled:!0}],loop:!0,isNestable:!1,parentPath:`items`,maxNestingDepth:5,nestingPrefix:` `,showNestingLevel:!1,loopStartTag:r,loopEndTag:a};h(t=>[...t,e]),n(``)},te=()=>{if(!O.trim())return;let e=O.trim().toLowerCase().replace(/\s+/g,`_`);if(A.some(t=>t.imageType===e)){k(``);return}j(t=>[...t,{label:O.trim(),imageType:e,description:`Placeholder container for ${O.trim()}`}]),k(``)},ne=(e,t,n)=>{h(r=>r.map((r,i)=>{if(i===e){let e=[...r.columns];if(n!==void 0&&e[t]?.columns){let r=[...e[t].columns];r[n]={...r[n],enabled:r[n].enabled===!1},e[t]={...e[t],columns:r}}else e[t]={...e[t],enabled:e[t].enabled===!1};return{...r,columns:e}}return r}))},[re,N]=(0,l.useState)(null);return{customTableName:t,setCustomTableName:n,customLoopStart:r,setCustomLoopStart:i,customLoopEnd:a,setCustomLoopEnd:o,newColName:s,setNewColName:c,newColPlaceholder:u,setNewColPlaceholder:d,bubbleCoords:f,setBubbleCoords:p,schemas:m,setSchemas:h,isParsing:g,setIsParsing:_,parseStatusText:v,setParseStatusText:y,parseError:b,setParseError:x,draggedSidebarItem:w,setDraggedSidebarItem:T,dragOverIndex:E,setDragOverIndex:D,newImgTypeName:O,setNewImgTypeName:k,customImageTypes:A,setCustomImageTypes:j,searchPlaceholder:S,setSearchPlaceholder:C,handleAddCustomTable:ee,handleAddCustomImageType:te,toggleSchemaColumn:ne,applySelectionFormat:(e,t=``)=>{if(re){let e=window.getSelection();e?.removeAllRanges(),e?.addRange(re)}document.execCommand(e,!1,t),p(null)},setSavedRange:N}}var Ta=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),Ea=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),Da=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),Oa=e=>{let t=Da(e);return t.charAt(0).toUpperCase()+t.slice(1)},ka={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},Aa=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},ja=(0,l.createContext)({}),Ma=()=>(0,l.useContext)(ja),Na=(0,l.forwardRef)(({color:e,size:t,strokeWidth:n,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>{let{size:u=24,strokeWidth:d=2,absoluteStrokeWidth:f=!1,color:p=`currentColor`,className:m=``}=Ma()??{},h=r??f?Number(n??d)*24/Number(t??u):n??d;return(0,l.createElement)(`svg`,{ref:c,...ka,width:t??u??ka.width,height:t??u??ka.height,stroke:e??p,strokeWidth:h,className:Ta(`lucide`,m,i),...!a&&!Aa(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])}),$=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(Na,{ref:i,iconNode:t,className:Ta(`lucide-${Ea(Oa(e))}`,`lucide-${e}`,n),...r}));return n.displayName=Oa(e),n},Pa=$(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),Fa=$(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Ia=$(`barcode`,[[`path`,{d:`M3 5v14`,key:`1nt18q`}],[`path`,{d:`M8 5v14`,key:`1ybrkv`}],[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`M17 5v14`,key:`ycjyhj`}],[`path`,{d:`M21 5v14`,key:`nzette`}]]),La=$(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),Ra=$(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),za=$(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),Ba=$(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Va=$(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),Ha=$(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),Ua=$(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),Wa=$(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),Ga=$(`printer`,[[`path`,{d:`M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`143wyd`}],[`path`,{d:`M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6`,key:`1itne7`}],[`rect`,{x:`6`,y:`14`,width:`12`,height:`8`,rx:`1`,key:`1ue0tg`}]]),Ka=$(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),qa=$(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Ja=$(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Ya=$(`square-check-big`,[[`path`,{d:`M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344`,key:`2acyp4`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),Xa=$(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Za=$(`table`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}]]),Qa=$(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),$a=$(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),eo=$(`text-align-justify`,[[`path`,{d:`M3 5h18`,key:`1u36vt`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 19h18`,key:`awlh7x`}]]),to=$(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),no=$(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),ro=$(`type`,[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]),io=$(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),ao=$(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]);function oo({headerLogo:e,headerTitle:t,headerSubtitle:n,parseError:r,isParsing:i,parseStatusText:a,showImportHtml:o,showImportPdf:s,showPreview:c,showExport:d,showExportPdf:f=!0,customButtonStyles:p,customButtonClassNames:m,handleHtmlImport:h,handlePdfImport:g,setPreviewOpen:_,handleExport:v,handleExportPdf:y}){let b=(0,l.useRef)(null),x=(0,l.useRef)(null);return(0,u.jsxs)(`header`,{className:`bg-white border-b border-gray-200 px-6 py-4 flex flex-col sm:flex-row items-center justify-between sticky top-0 z-10 shadow-sm gap-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-3`,children:[e||(0,u.jsx)(`div`,{className:`h-10 w-10 bg-orange-600 rounded-xl flex items-center justify-center text-white shadow-md shadow-orange-600/20`,children:(0,u.jsx)(Ja,{className:`h-6 w-6`})}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h1`,{className:`text-xl font-bold tracking-tight text-slate-800`,children:t}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:n}),r&&(0,u.jsxs)(`span`,{className:`text-[10px] text-red-500 font-bold bg-red-50 px-2 py-0.5 rounded mt-1 inline-block border border-red-100`,children:[`Error: `,r]}),i&&(0,u.jsx)(`span`,{className:`text-[10px] text-orange-600 font-bold bg-orange-50 px-2 py-0.5 rounded mt-1 inline-block border border-orange-100 animate-pulse`,children:a||`Parsing...`})]})]}),(0,u.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(o||s)&&(0,u.jsxs)(`div`,{className:`flex space-x-2 border-r border-gray-200 pr-4`,children:[o&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`button`,{onClick:()=>b.current?.click(),style:p?.importHtml,className:m?.importHtml||`inline-flex items-center space-x-2 px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-semibold bg-white hover:bg-slate-50 text-slate-700 transition-colors shadow-sm`,title:`Import local HTML file`,children:[(0,u.jsx)(io,{className:`h-3.5 w-3.5 text-slate-500`}),(0,u.jsx)(`span`,{children:`Import HTML`})]}),(0,u.jsx)(`input`,{type:`file`,ref:b,onChange:h,accept:`.html`,className:`hidden`})]}),s&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`button`,{onClick:()=>x.current?.click(),style:p?.importPdf,className:m?.importPdf||`inline-flex items-center space-x-2 px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-semibold bg-white hover:bg-slate-50 text-slate-700 transition-colors shadow-sm`,title:`Import PDF layout structure`,children:[(0,u.jsx)(Va,{className:`h-3.5 w-3.5 text-slate-500`}),(0,u.jsx)(`span`,{children:`Import PDF`})]}),(0,u.jsx)(`input`,{type:`file`,ref:x,onChange:g,accept:`.pdf`,className:`hidden`})]})]}),c&&(0,u.jsxs)(`button`,{onClick:()=>_(!0),style:p?.preview,className:m?.preview||`inline-flex items-center space-x-2 px-4 py-2 border border-slate-200 rounded-lg text-sm font-semibold bg-slate-50 text-slate-700 hover:bg-slate-100 transition-colors shadow-sm`,children:[(0,u.jsx)(Ba,{className:`h-4 w-4 text-slate-500`}),(0,u.jsx)(`span`,{children:`Live Preview`})]}),f&&(0,u.jsxs)(`button`,{onClick:y,style:p?.exportPdf,className:m?.exportPdf||`inline-flex items-center space-x-2 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg text-sm font-semibold transition-colors shadow-sm shadow-indigo-600/10`,children:[(0,u.jsx)(Ga,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Download PDF`})]}),d&&(0,u.jsxs)(`button`,{onClick:v,style:p?.export,className:m?.export||`inline-flex items-center space-x-2 px-4 py-2 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-sm font-semibold transition-colors shadow-sm shadow-orange-600/10`,children:[(0,u.jsx)(za,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Export Template`})]})]})]})}function so({handleSidebarDragStart:e,createTextBlock:t,setBlocks:n,setSelectedBlockId:r,setActiveTab:i,defaultStyles:a}){return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Typography Elements`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Select standard headings or paragraphs to structure your page layout.`})]}),(0,u.jsx)(`div`,{className:`grid grid-cols-1 gap-3 select-none`,children:[{label:`Document Title`,type:`title`,style:`text-2xl font-extrabold text-slate-900 tracking-tight`},{label:`Document Subtitle`,type:`subtitle`,style:`text-sm font-bold text-slate-500`},{label:`Heading 1`,type:`h1`,style:`text-xl font-extrabold text-slate-850`},{label:`Heading 2`,type:`h2`,style:`text-lg font-bold text-slate-800`},{label:`Heading 3`,type:`h3`,style:`text-md font-semibold text-slate-750`},{label:`Normal Paragraph`,type:`p`,style:`text-xs text-slate-600 leading-relaxed`},{label:`Caption Note`,type:`caption`,style:`text-[10px] text-slate-400 font-mono italic`}].map(o=>(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>e(t,o.type),className:`border border-gray-200 rounded-xl p-3 bg-white hover:border-slate-350 transition-all flex flex-col space-y-2 cursor-grab shadow-xs group`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-400 uppercase tracking-wide`,children:o.type}),(0,u.jsx)(`div`,{className:`${o.style} truncate pr-4`,children:o.label}),(0,u.jsx)(`button`,{onClick:()=>{let e=t(o.type,o.label,a?.[o.type]);n(t=>[...t,e]),r(e.id),i(`styles`)},className:`w-full py-1 bg-slate-50 hover:bg-slate-200 text-slate-600 rounded-lg text-[9px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},o.type))})]})}function co({schemas:e,toggleSchemaColumn:t,customTableName:n,setCustomTableName:r,customLoopStart:i,setCustomLoopStart:a,customLoopEnd:o,setCustomLoopEnd:s,handleAddCustomTable:c,handleSidebarDragStart:l,setBlocks:d,setSelectedBlockId:f,setActiveTab:p,defaultStyles:m}){return(0,u.jsxs)(`div`,{className:`space-y-6`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Dynamic Tables`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Configure loop table templates and drag onto the canvas.`})]}),(0,u.jsx)(`div`,{className:`space-y-4`,children:e.map((e,n)=>(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-2xl p-4 bg-white space-y-3 shadow-xs`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(Za,{className:`h-4 w-4 text-slate-650`}),(0,u.jsx)(`h4`,{className:`font-bold text-xs uppercase text-slate-700 tracking-wider`,children:e.tableName})]}),(0,u.jsx)(`span`,{className:`px-1.5 py-0.5 bg-slate-100 text-[8px] font-bold text-slate-600 rounded`,children:`loop = true`})]}),(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>l(t,`table`,e),className:`bg-slate-50 border border-slate-200 hover:border-slate-400 rounded-lg p-2.5 flex items-center justify-between cursor-grab`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`div`,{className:`h-5 w-5 bg-slate-200 rounded flex items-center justify-center`,children:(0,u.jsx)(Wa,{className:`h-3 w-3 text-slate-600`})}),(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700`,children:`Drag to Canvas`})]}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 italic`,children:`Drag & Drop`})]}),(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 font-bold uppercase tracking-wider block`,children:`Columns:`}),(0,u.jsx)(`div`,{className:`max-h-[180px] overflow-y-auto border border-gray-150 rounded-lg p-2 space-y-1.5 bg-slate-50/50`,children:e.columns.map((e,r)=>{let i=e.loop&&e.columns&&e.columns.length>0;return(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`button`,{onClick:()=>t(n,r),className:`flex items-center space-x-2 w-full text-left py-0.5 text-xs text-slate-600 hover:text-slate-800 transition-colors font-medium`,children:[e.enabled===!1?(0,u.jsx)(Xa,{className:`h-3.5 w-3.5 text-slate-300 flex-shrink-0`}):(0,u.jsx)(Ya,{className:`h-3.5 w-3.5 text-slate-700 flex-shrink-0`}),(0,u.jsxs)(`span`,{className:`truncate flex items-center gap-1`,children:[(0,u.jsx)(`span`,{children:e.columnName}),i&&(0,u.jsx)(`span`,{className:`px-1 bg-slate-200 text-slate-600 rounded text-[8px] font-mono`,children:`(sub-table)`})]})]}),i&&e.enabled!==!1&&(0,u.jsxs)(`div`,{className:`ml-4 pl-2.5 border-l-2 border-slate-200 space-y-1 my-1`,children:[(0,u.jsx)(`span`,{className:`text-[8px] text-slate-400 font-bold uppercase tracking-wider block`,children:`Sub Columns:`}),e.columns.map((e,i)=>(0,u.jsxs)(`button`,{onClick:()=>t(n,r,i),className:`flex items-center space-x-2 w-full text-left py-0.5 text-[11px] text-slate-500 hover:text-slate-800 transition-colors`,children:[e.enabled===!1?(0,u.jsx)(Xa,{className:`h-3 w-3 text-slate-300 flex-shrink-0`}):(0,u.jsx)(Ya,{className:`h-3 w-3 text-slate-600 flex-shrink-0`}),(0,u.jsxs)(`span`,{className:`truncate`,children:[e.columnName,` `,(0,u.jsxs)(`span`,{className:`text-[8px] text-slate-400`,children:[`(`,e.placeholder,`)`]})]})]},i))]})]},r)})})]}),(0,u.jsx)(`button`,{onClick:()=>{let t={id:Math.random().toString(36).substring(2,11),type:`table`,content:``,style:{fontSize:`10px`,fontWeight:`400`,color:`#334155`,backgroundColor:`transparent`,textAlign:`left`,bold:!1,italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`12px`,padding:`8px`,...m?.table},tableInfo:{...e,columns:e.columns.map(e=>({...e}))}};d(e=>[...e,t]),f(t.id),p(`styles`)},className:`w-full py-1 bg-slate-50 hover:bg-slate-200 text-slate-600 rounded-lg text-[9px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},e.tableName))}),(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-2xl p-4 bg-slate-50/20 border-dashed space-y-4 mt-6`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-2 border-b border-gray-150`,children:[(0,u.jsx)(Ja,{className:`h-4 w-4 text-slate-655`}),(0,u.jsx)(`h4`,{className:`font-bold text-xs uppercase text-slate-800 tracking-wider`,children:`Custom Table Builder`})]}),(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Table Name`}),(0,u.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`invoice_items`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Loop Start tag`}),(0,u.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`{% for item in invoice.items %}`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 bg-white text-slate-600 font-bold`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Loop End tag`}),(0,u.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`{% endfor %}`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 bg-white text-slate-600 font-bold`})]}),(0,u.jsxs)(`button`,{onClick:c,className:`w-full py-2 bg-orange-600 hover:bg-orange-700 text-white rounded-xl text-xs font-bold transition-all shadow-sm flex items-center justify-center space-x-1.5 shadow-orange-600/10`,children:[(0,u.jsx)(Wa,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Add Custom Loop Table`})]})]})]})]})}function lo({customImageTypes:e,newImgTypeName:t,setNewImgTypeName:n,handleAddCustomImageType:r,handleSidebarDragStart:i,createImageBlock:a,setBlocks:o,setSelectedBlockId:s,setActiveTab:c}){let l=[{label:`Brand Logo`,imageType:`logo`,description:`Standard document vector logo`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},{label:`Campaign Banner`,imageType:`banner`,description:`Wide horizontal graphics banner`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},{label:`Dynamic Barcode`,imageType:`barcode`,description:`Barcode replaced dynamically`,icon:(0,u.jsx)(Ia,{className:`h-4 w-4 text-slate-550`})},{label:`Watermark`,imageType:`watermark`,description:`Background graphic with low opacity`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},...e.map(e=>({label:e.label,imageType:e.imageType,description:e.description,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})}))];return(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Image & Barcode Elements`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Drag elements onto the canvas, or insert below.`})]}),(0,u.jsx)(`div`,{className:`space-y-3`,children:l.map(e=>(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-xl p-3 bg-white space-y-3 shadow-xs`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[e.icon,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h4`,{className:`font-bold text-xs text-slate-700`,children:e.label}),(0,u.jsx)(`p`,{className:`text-[9px] text-slate-400`,children:e.description})]})]})}),(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>i(t,`image`,void 0,e.imageType),className:`bg-slate-50 border border-slate-200 hover:border-slate-450 rounded-lg p-2 flex items-center justify-between cursor-grab transition-all`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`div`,{className:`h-5 w-5 bg-slate-200 rounded flex items-center justify-center`,children:(0,u.jsx)(Wa,{className:`h-3 w-3 text-slate-750`})}),(0,u.jsx)(`span`,{className:`text-[11px] font-bold text-slate-700`,children:`Drag to Canvas`})]}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 italic`,children:`Drag`})]}),(0,u.jsx)(`button`,{onClick:()=>{let t=a(e.imageType);o(e=>[...e,t]),s(t.id),c(`styles`)},className:`w-full py-1 bg-slate-100 hover:bg-slate-200 text-slate-600 rounded-lg text-[10px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},e.imageType))}),(0,u.jsxs)(`div`,{className:`border border-dashed border-gray-200 rounded-xl p-3 space-y-2 bg-slate-50/50 mt-4`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Add Custom Image Type`}),(0,u.jsx)(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. Signature`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs focus:outline-none focus:border-slate-500 bg-white`}),(0,u.jsxs)(`button`,{onClick:r,className:`w-full py-1.5 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Add Custom Category`})]})]})]})}function uo({placeholders:e,schemas:t,searchPlaceholder:n,setSearchPlaceholder:r,placeholderMockData:i,setPlaceholderMockData:a,selectedBlockId:o,setBlocks:s}){let c=()=>{let r=[];return(e||[]).forEach(e=>{r.push({label:e.label,placeholder:e.placeholder,category:`General`})}),t.forEach(e=>{let t=e.tableName===`package`?`Package Fields`:`Article Fields`;e.columns.forEach(n=>{r.push({label:`${e.tableName.toUpperCase()} - ${n.columnName}`,placeholder:n.placeholder,category:t})})}),r.filter(e=>e.label.toLowerCase().includes(n.toLowerCase())||e.placeholder.toLowerCase().includes(n.toLowerCase()))},l=e=>{if(o){let t=e.replace(/[{}]/g,``),n=` <span contenteditable="false" data-placeholder="${t}" class="inline-flex items-center px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 text-[9px] font-bold mx-0.5 select-none align-middle border border-slate-200 cursor-default relative pr-4 group/chip"><span>{{${t}}}</span><span class="absolute right-0.5 top-1/2 -translate-y-1/2 cursor-pointer text-slate-400 hover:text-red-655 px-0.5 font-bold hover:bg-slate-200/50 rounded text-[9px] leading-none select-none" onmousedown="event.stopPropagation(); event.preventDefault(); const p = this.closest('span[data-placeholder]'); const editable = p.closest('[contenteditable=\\'true\\']'); if(p){ p.remove(); } if(editable){ window.updateContentFromRawDelete('${o}', editable.innerHTML); }">×</span></span>&nbsp;`;s(e=>e.map(e=>e.id===o&&e.type!==`table`?{...e,content:e.content+n}:e))}},d=c();return(0,u.jsxs)(`div`,{className:`space-y-4 flex-1 flex flex-col min-h-0`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Variables Palette`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Click to copy, or drag into text areas. Edit mock values below to visualize content.`})]}),(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(Ka,{className:`absolute left-3 top-2.5 h-4 w-4 text-slate-400`}),(0,u.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`Search variables...`,className:`w-full pl-9 pr-4 py-2 border border-gray-200 rounded-xl text-xs focus:outline-none focus:border-slate-500 transition-colors`})]}),(0,u.jsx)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-1`,children:d.length===0?(0,u.jsx)(`div`,{className:`text-xs text-slate-400 italic text-center py-4`,children:`No variables available.`}):d.map((e,t)=>{let n=e.placeholder.replace(/[{}]/g,``);return(0,u.jsxs)(`div`,{className:`w-full border border-gray-200 p-2.5 rounded-xl bg-white shadow-xs space-y-2`,children:[(0,u.jsxs)(`div`,{draggable:!0,onDragStart:e=>{e.dataTransfer.setData(`placeholder`,n),e.dataTransfer.effectAllowed=`copy`},onClick:()=>l(e.placeholder),className:`flex items-center justify-between cursor-grab active:cursor-grabbing hover:bg-slate-50 p-1 rounded`,title:`Drag into text or cells, or click to copy`,children:[(0,u.jsx)(`span`,{className:`text-xs font-semibold text-slate-700 truncate mr-2`,children:e.label}),(0,u.jsx)(`code`,{className:`text-[9px] bg-slate-100 px-1.5 py-0.5 rounded text-slate-800 font-bold shrink-0 border border-slate-200/50`,children:e.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between gap-1 pt-1.5 border-t border-gray-100`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-400 uppercase`,children:`Mock:`}),(0,u.jsx)(`input`,{type:`text`,value:i[n]||``,onChange:e=>{a(t=>({...t,[n]:e.target.value}))},className:`flex-1 max-w-[130px] px-1.5 py-0.5 border border-gray-200 rounded text-[10px] focus:outline-none focus:border-slate-500 bg-white`})]})]},t)})})]})}function fo({selectedBlockId:e,getSelectedBlock:t,updateSelectedStyle:n,updateSelectedImageInfo:r,fontSizesState:i,fontFamiliesState:a,fontWeightsState:o,handleDeleteBlock:s,newColName:c,setNewColName:d,newColPlaceholder:f,setNewColPlaceholder:p,handleAddTableColumn:m,handleRemoveTableColumn:h,handleUpdateTableColumn:g,handleReorderTableColumn:_,setBlocks:v}){let[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(``),[C,w]=(0,l.useState)(``),[T,E]=(0,l.useState)(null),[D,O]=(0,l.useState)(``),[k,A]=(0,l.useState)(``),j=t();if(!e||!j)return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`border border-dashed border-gray-200 rounded-xl p-6 text-center bg-slate-50/50`,children:[(0,u.jsx)(qa,{className:`h-8 w-8 text-slate-350 mx-auto mb-2`}),(0,u.jsx)(`span`,{className:`text-xs font-semibold text-slate-500 block`,children:`No block selected`}),(0,u.jsx)(`p`,{className:`text-[10px] text-slate-400 mt-1`,children:`Select any element inside the canvas to configure typography, sizing, colors, or templating loop engines.`})]})]});let M=j.type===`table`,ee=()=>{c.trim()&&(m(c,f),d(``),p(``))};if(j.type===`image`){let e=j.imageInfo||{imageType:`logo`};return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-3 border-b border-gray-100`,children:[(0,u.jsx)(`div`,{className:`h-6 w-6 bg-slate-100 rounded flex items-center justify-center text-slate-700`,children:(0,u.jsx)(Ha,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 capitalize`,children:`Editing Image Element`})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Alignment`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Display side-by-side`})]}),(0,u.jsx)(`button`,{onClick:()=>{let e=!j.style.sameRow;n(`sameRow`,e),e?(n(`width`,`48%`),v(e=>{let t=e.findIndex(e=>e.id===j.id);return t>0?e.map((e,n)=>n===t-1&&(!e.style.width||e.style.width===`100%`)?{...e,style:{...e.style,width:`48%`}}:e):e})):n(`width`,`100%`)},className:`w-10 h-6 flex items-center rounded-full p-1 transition-colors duration-150 ${j.style.sameRow?`bg-orange-600 justify-end`:`bg-slate-300 justify-start`}`,children:(0,u.jsx)(`span`,{className:`bg-white w-4 h-4 rounded-full shadow-md`})})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Image Category`}),(0,u.jsx)(`div`,{className:`grid grid-cols-4 gap-1 bg-slate-50 p-1 border border-gray-200 rounded-lg`,children:[`logo`,`banner`,`barcode`,`watermark`].map(t=>(0,u.jsx)(`button`,{onClick:()=>r(`imageType`,t),className:`py-1 text-[9px] font-bold rounded capitalize transition-all ${e.imageType===t?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:t},t))})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Alignment (Position)`}),(0,u.jsx)(`div`,{className:`flex items-center space-x-1 border border-gray-200 rounded-lg p-1 bg-slate-50 w-fit`,children:[{value:`left`,icon:(0,u.jsx)(to,{className:`h-3.5 w-3.5`})},{value:`center`,icon:(0,u.jsx)(Qa,{className:`h-3.5 w-3.5`})},{value:`right`,icon:(0,u.jsx)($a,{className:`h-3.5 w-3.5`})}].map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`textAlign`,e.value),type:`button`,className:`p-1.5 rounded transition-all ${j.style.textAlign===e.value?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e.icon},e.value))})]}),(0,u.jsxs)(`div`,{className:`space-y-1 pt-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Image Width`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:j.style.width||`100%`})]}),(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`input`,{type:`range`,min:`10`,max:`1000`,step:`5`,value:parseInt(j.style.width||`100`),onChange:e=>n(`width`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`}),(0,u.jsxs)(`span`,{className:`text-[10px] font-mono text-slate-500 w-10 text-right`,children:[parseInt(j.style.width||`100`),`px`]})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1 pt-1 mt-3`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1`,children:`Object Fit`}),(0,u.jsxs)(`select`,{value:j.style.objectFit||`contain`,onChange:e=>n(`objectFit`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:[(0,u.jsx)(`option`,{value:`contain`,children:`Contain`}),(0,u.jsx)(`option`,{value:`cover`,children:`Cover`}),(0,u.jsx)(`option`,{value:`fill`,children:`Fill`}),(0,u.jsx)(`option`,{value:`none`,children:`None`})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Image Height`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:j.style.height||j.style.minHeight||`auto`})]}),(0,u.jsx)(`div`,{className:`flex items-center space-x-2`,children:(0,u.jsx)(`input`,{type:`range`,min:`20`,max:`400`,step:`10`,value:parseInt(j.style.height||j.style.minHeight||`100`)||100,onChange:e=>{n(`height`,`${e.target.value}px`),n(`minHeight`,`${e.target.value}px`)},className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`})})]}),e.imageType===`barcode`?(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-150`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Barcode Configuration`}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500`,children:`Mock Barcode Value`}),(0,u.jsx)(`input`,{type:`text`,value:e.barcodeValue||``,onChange:e=>r(`barcodeValue`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500`,children:`Backend Variable`}),(0,u.jsx)(`input`,{type:`text`,value:e.barcodePlaceholder||``,onChange:e=>r(`barcodePlaceholder`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 text-slate-700 font-bold`})]})]}):(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-150`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Image Asset Upload`}),(0,u.jsxs)(`div`,{className:`flex flex-col items-center p-3 border border-dashed border-gray-200 rounded-lg bg-slate-50/50 hover:bg-slate-50 transition-all cursor-pointer relative`,children:[(0,u.jsx)(io,{className:`h-5 w-5 text-slate-400 mb-1`}),(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-650`,children:`Choose local image file`}),(0,u.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=e=>{let t=e.target?.result;r(`url`,t)},n.readAsDataURL(t)},className:`absolute inset-0 opacity-0 cursor-pointer`})]})]}),(0,u.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Bottom Margin`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(j.style.marginBottom||`0px`),onChange:e=>n(`marginBottom`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Padding`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(j.style.padding||`0px`),onChange:e=>n(`padding`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200`})]})]})}),(0,u.jsx)(`div`,{className:`pt-4 border-t border-red-100 flex items-center justify-between`,children:(0,u.jsxs)(`button`,{onClick:()=>s(j.id),className:`w-full py-2 bg-red-50 hover:bg-red-100 border border-red-200 text-red-650 rounded-xl text-xs font-bold transition-all flex items-center justify-center space-x-1 shadow-xs cursor-pointer`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Delete Element`})]})})]})]})}return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-3 border-b border-gray-100`,children:[(0,u.jsx)(`div`,{className:`h-6 w-6 bg-slate-100 rounded flex items-center justify-center text-slate-700 font-bold text-[10px] uppercase`,children:j.type}),(0,u.jsxs)(`span`,{className:`text-xs font-bold text-slate-700 capitalize`,children:[`Editing `,j.type===`table`?`Table Block`:`Typography Element`]})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Alignment`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Display side-by-side`})]}),(0,u.jsx)(`button`,{onClick:()=>{let e=!j.style.sameRow;n(`sameRow`,e),e?(n(`width`,`48%`),v(e=>{let t=e.findIndex(e=>e.id===j.id);return t>0?e.map((e,n)=>n===t-1&&(!e.style.width||e.style.width===`100%`)?{...e,style:{...e.style,width:`48%`}}:e):e})):n(`width`,`100%`)},className:`w-10 h-6 flex items-center rounded-full p-1 transition-colors duration-150 ${j.style.sameRow?`bg-orange-600 justify-end`:`bg-slate-300 justify-start`}`,children:(0,u.jsx)(`span`,{className:`bg-white w-4 h-4 rounded-full shadow-md`})})]}),j.style.sameRow&&(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Direction`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Layout stacked or side-by-side`})]}),(0,u.jsx)(`div`,{className:`grid grid-cols-2 gap-1 bg-slate-100 p-0.5 border border-gray-200 rounded-lg w-[180px]`,children:[`row`,`column`].map(e=>(0,u.jsx)(`button`,{type:`button`,onClick:()=>{n(`flexDirection`,e),v(t=>{let n=t.findIndex(e=>e.id===j.id);if(n===-1)return t;let r=n;for(;r>0&&t[r].style.sameRow;)r--;let i=[r],a=r+1;for(;a<t.length&&t[a].style.sameRow;)i.push(a),a++;return t.map((t,n)=>i.includes(n)?{...t,style:{...t.style,flexDirection:e}}:t)})},className:`px-2 py-1 text-[9px] font-bold rounded capitalize transition-all text-center ${j.style.flexDirection===e||e===`row`&&!j.style.flexDirection?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e===`row`?`Side-by-side`:`Stacked`},e))})]}),(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Font Size`}),(0,u.jsx)(`select`,{value:j.style.fontSize,onChange:e=>n(`fontSize`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:i.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),!M&&(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Weight`}),(0,u.jsx)(`select`,{value:j.style.fontWeight,onChange:e=>n(`fontWeight`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:o.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),!M&&(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Font Family`}),(0,u.jsxs)(`select`,{value:j.style.fontFamily||``,onChange:e=>n(`fontFamily`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:[(0,u.jsx)(`option`,{value:``,children:`Default Font (Global)`}),a.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),!M&&(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Alignment & Formatting`}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between gap-1 border border-gray-200 rounded-lg p-1 bg-slate-50`,children:[(0,u.jsx)(`div`,{className:`flex items-center space-x-0.5`,children:[{value:`left`,icon:(0,u.jsx)(to,{className:`h-3.5 w-3.5`})},{value:`center`,icon:(0,u.jsx)(Qa,{className:`h-3.5 w-3.5`})},{value:`right`,icon:(0,u.jsx)($a,{className:`h-3.5 w-3.5`})},{value:`justify`,icon:(0,u.jsx)(eo,{className:`h-3.5 w-3.5`})}].map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`textAlign`,e.value),className:`p-1.5 rounded transition-all ${j.style.textAlign===e.value?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e.icon},e.value))}),(0,u.jsx)(`div`,{className:`h-5 w-[1px] bg-slate-200 mx-1`}),(0,u.jsx)(`div`,{className:`flex items-center space-x-0.5`,children:[{key:`bold`,label:`B`,className:`font-bold`},{key:`italic`,label:`I`,className:`italic`},{key:`underline`,label:`U`,className:`underline`},{key:`strikethrough`,label:`S`,className:`line-through`}].map(e=>{let t=j.style[e.key]===!0;return(0,u.jsx)(`button`,{onClick:()=>n(e.key,!t),className:`h-7 w-7 rounded text-xs transition-all ${t?`bg-white text-slate-800 shadow-xs border border-gray-200 font-bold`:`text-slate-500 hover:text-slate-800`}`,children:(0,u.jsx)(`span`,{className:e.className,children:e.label})},e.key)})})]})]}),(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Text Color`}),(0,u.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ma.map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`color`,e),className:`h-5 w-5 rounded-full border border-gray-200 shadow-xs transition-transform ${j.style.color===e?`scale-120 ring-2 ring-slate-800`:`hover:scale-110`}`,style:{backgroundColor:e}},e)),(0,u.jsx)(`input`,{type:`color`,value:j.style.color,onChange:e=>n(`color`,e.target.value),className:`h-5 w-5 rounded-full border border-gray-200 cursor-pointer overflow-hidden p-0`})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Background Color`}),(0,u.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ha.map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`backgroundColor`,e),className:`h-5 w-5 rounded-full border border-gray-200 shadow-xs transition-transform ${j.style.backgroundColor===e?`scale-120 ring-2 ring-slate-800`:`hover:scale-110`}`,style:{backgroundColor:e===`transparent`?`#ffffff`:e},children:e===`transparent`&&(0,u.jsx)(`span`,{className:`text-[8px] text-slate-400 font-bold block leading-5 text-center`,children:`T`})},e)),(0,u.jsx)(`input`,{type:`color`,value:j.style.backgroundColor===`transparent`?`#ffffff`:j.style.backgroundColor,onChange:e=>n(`backgroundColor`,e.target.value),className:`h-5 w-5 rounded-full border border-gray-200 cursor-pointer overflow-hidden p-0`})]})]})]}),(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Block Width`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:j.style.width||`100%`})]}),(0,u.jsx)(`div`,{className:`flex items-center space-x-2`,children:(0,u.jsx)(`input`,{type:`range`,min:`10`,max:`100`,step:`5`,value:parseInt(j.style.width||`100%`),onChange:e=>n(`width`,`${e.target.value}%`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`})})]}),(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Bottom Margin`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(j.style.marginBottom||`0px`),onChange:e=>n(`marginBottom`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Padding`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(j.style.padding||`0px`),onChange:e=>n(`padding`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg`})]})]})]}),M&&j.tableInfo&&(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Table Columns`}),(0,u.jsx)(`div`,{className:`space-y-2 max-h-[300px] overflow-y-auto pr-1`,children:j.tableInfo.columns.map((e,t)=>{let n=e.loop&&e.columns&&e.columns.length>0;return(0,u.jsxs)(`div`,{className:`bg-slate-50 border border-gray-200 rounded-lg p-2 space-y-1.5 text-xs`,children:[y===String(t)?(0,u.jsxs)(`div`,{className:`space-y-1.5 p-1 bg-white border border-orange-300 rounded`,children:[(0,u.jsx)(`div`,{className:`text-[9px] font-bold text-orange-600 uppercase`,children:`Edit Column`}),(0,u.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-xs bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Value (e.g. {{item.sku}})`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-xs font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,u.jsxs)(`button`,{onClick:()=>{g&&g(t,x,C),b(null)},className:`p-1 px-2 bg-orange-600 text-white hover:bg-orange-700 rounded text-[10px] flex items-center gap-1 font-bold`,children:[(0,u.jsx)(La,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Save`})]}),(0,u.jsxs)(`button`,{onClick:()=>b(null),className:`p-1 px-2 bg-gray-200 text-slate-700 hover:bg-gray-300 rounded text-[10px] flex items-center gap-1`,children:[(0,u.jsx)(ao,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Cancel`})]})]})]}):(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`truncate mr-2`,children:[(0,u.jsxs)(`span`,{className:`font-bold text-slate-700 block truncate flex items-center gap-1`,children:[(0,u.jsx)(`span`,{children:e.columnName}),n&&(0,u.jsx)(`span`,{className:`px-1 bg-blue-100 text-blue-700 rounded text-[8px] font-mono`,children:`loop (sub-table)`})]}),(0,u.jsx)(`code`,{className:`text-[9px] font-mono text-slate-500 truncate block`,children:e.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`up`),disabled:t===0,className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 disabled:opacity-30 disabled:hover:bg-transparent rounded transition-colors`,title:`Move Up`,children:(0,u.jsx)(Fa,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`down`),disabled:t===(j.tableInfo?.columns.length||0)-1,className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 disabled:opacity-30 disabled:hover:bg-transparent rounded transition-colors`,title:`Move Down`,children:(0,u.jsx)(Pa,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>{b(String(t)),S(e.columnName),w(e.placeholder)},className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 rounded transition-colors`,title:`Edit column`,children:(0,u.jsx)(Ua,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>h(t),className:`p-1 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded transition-colors border border-transparent`,disabled:!j.tableInfo||j.tableInfo.columns.length<=1,title:`Delete column`,children:(0,u.jsx)(no,{className:`h-3.5 w-3.5`})})]})]}),n&&(0,u.jsxs)(`div`,{className:`ml-2 pl-2 border-l-2 border-blue-200 space-y-1.5 pt-1 mt-1`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,u.jsxs)(`span`,{className:`text-[8px] font-bold text-blue-600 uppercase tracking-wider block`,children:[`Sub-Table Columns (`,e.columns?.length||0,`):`]})}),e.columns.map((n,r)=>{let i=`${t}-${r}`;return y===i?(0,u.jsxs)(`div`,{className:`space-y-1 p-1.5 bg-white border border-blue-300 rounded`,children:[(0,u.jsx)(`div`,{className:`text-[8px] font-bold text-blue-600 uppercase`,children:`Edit Sub-Column`}),(0,u.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-[11px] bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Value`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-[11px] font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex justify-end gap-1 pt-0.5`,children:[(0,u.jsxs)(`button`,{onClick:()=>{g&&g(t,x,C,r),b(null)},className:`p-0.5 px-1.5 bg-blue-600 text-white hover:bg-blue-700 rounded text-[9px] flex items-center gap-1 font-bold`,children:[(0,u.jsx)(La,{className:`h-2.5 w-2.5`}),(0,u.jsx)(`span`,{children:`Save`})]}),(0,u.jsxs)(`button`,{onClick:()=>b(null),className:`p-0.5 px-1.5 bg-gray-200 text-slate-700 hover:bg-gray-300 rounded text-[9px] flex items-center gap-1`,children:[(0,u.jsx)(ao,{className:`h-2.5 w-2.5`}),(0,u.jsx)(`span`,{children:`Cancel`})]})]})]},r):(0,u.jsxs)(`div`,{className:`flex items-center justify-between bg-white border border-gray-150 rounded px-2 py-1 text-[11px]`,children:[(0,u.jsxs)(`div`,{className:`truncate mr-1`,children:[(0,u.jsx)(`span`,{className:`font-semibold text-slate-700 block truncate`,children:n.columnName}),(0,u.jsx)(`code`,{className:`text-[8px] font-mono text-slate-400 truncate block`,children:n.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`up`,r),disabled:r===0,className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 disabled:opacity-30 disabled:hover:bg-transparent rounded`,title:`Move Sub-Column Up`,children:(0,u.jsx)(Fa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`down`,r),disabled:r===e.columns.length-1,className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 disabled:opacity-30 disabled:hover:bg-transparent rounded`,title:`Move Sub-Column Down`,children:(0,u.jsx)(Pa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>{b(i),S(n.columnName),w(n.placeholder)},className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded`,title:`Edit sub-column`,children:(0,u.jsx)(Ua,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>h(t,r),className:`p-0.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded`,title:`Delete sub-column`,children:(0,u.jsx)(no,{className:`h-3 w-3`})})]})]},r)}),T===t?(0,u.jsxs)(`div`,{className:`bg-white border border-blue-200 rounded p-2 space-y-1.5 mt-1`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-blue-600 block`,children:`Add Sub-Column`}),(0,u.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),placeholder:`Header Name (e.g. Price)`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),placeholder:`Value (e.g. {{item.price}})`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex gap-1 pt-1`,children:[(0,u.jsx)(`button`,{onClick:()=>{D.trim()&&(m(D,k||`{{item.value}}`,!1,t),O(``),A(``),E(null))},className:`flex-1 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded text-[10px] font-bold`,children:`Add`}),(0,u.jsx)(`button`,{onClick:()=>{E(null),O(``),A(``)},className:`py-1 px-2 bg-gray-100 hover:bg-gray-200 text-slate-600 rounded text-[10px]`,children:`Cancel`})]})]}):(0,u.jsxs)(`button`,{onClick:()=>E(t),className:`w-full py-1 text-[10px] font-bold text-blue-600 hover:bg-blue-50 border border-dashed border-blue-200 rounded flex items-center justify-center space-x-1 transition-colors mt-1`,children:[(0,u.jsx)(Wa,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Add Sub-Column`})]})]})]},t)})}),(0,u.jsxs)(`div`,{className:`bg-slate-50 border border-gray-200 border-dashed rounded-xl p-3 space-y-3`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Add New Column`}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`input`,{type:`text`,value:c,onChange:e=>d(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs focus:outline-none focus:border-slate-500 bg-white`})}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Value (e.g. {{item.sku}})`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs font-mono focus:outline-none focus:border-orange-655 bg-white`})}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsxs)(`button`,{onClick:ee,className:`flex-1 py-1.5 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Column`})]}),(0,u.jsxs)(`button`,{onClick:()=>{c.trim()&&(m(c,f||`{{item.price}}`,!0),d(``),p(``))},className:`flex-1 py-1.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,title:`Add column as nested sub-table`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Sub-Table`})]})]})]})]}),(0,u.jsx)(`div`,{className:`pt-4 border-t border-red-100 flex items-center justify-between`,children:(0,u.jsxs)(`button`,{onClick:()=>s(j.id),className:`w-full py-2 bg-red-50 hover:bg-red-100 border border-red-200 text-red-650 rounded-xl text-xs font-bold transition-all flex items-center justify-center space-x-1 shadow-xs cursor-pointer`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Delete Element`})]})})]})]})}function po({activeTab:e,setActiveTab:t,setBlocks:n,selectedBlockId:r,setSelectedBlockId:i,getSelectedBlock:a,defaultStyles:o,createTextBlock:s,createImageBlock:c,updateSelectedStyle:l,updateSelectedImageInfo:d,handleDeleteBlock:f,handleRemoveTableColumn:p,handleAddTableColumn:m,handleUpdateTableColumn:h,handleReorderTableColumn:g,schemas:_,toggleSchemaColumn:v,customTableName:y,setCustomTableName:b,customLoopStart:x,setCustomLoopStart:S,customLoopEnd:C,setCustomLoopEnd:w,handleAddCustomTable:T,newColName:E,setNewColName:D,newColPlaceholder:O,setNewColPlaceholder:k,customImageTypes:A,newImgTypeName:j,setNewImgTypeName:M,handleAddCustomImageType:ee,placeholders:te,searchPlaceholder:ne,setSearchPlaceholder:re,placeholderMockData:N,setPlaceholderMockData:P,handleSidebarDragStart:F,fontSizesState:ie,fontFamiliesState:ae,fontWeightsState:oe}){return(0,u.jsxs)(`aside`,{className:`w-full lg:w-[30%] flex flex-col bg-white border-t lg:border-t-0 lg:border-l border-gray-200 overflow-y-auto shrink-0`,children:[(0,u.jsx)(`div`,{className:`grid grid-cols-5 gap-1 border-b border-gray-250 p-2 bg-slate-50`,children:[{value:`text`,icon:(0,u.jsx)(ro,{className:`h-4 w-4`})},{value:`tables`,icon:(0,u.jsx)(Za,{className:`h-4 w-4`})},{value:`images`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4`})},{value:`placeholders`,icon:(0,u.jsx)(Ja,{className:`h-4 w-4`})},{value:`styles`,icon:(0,u.jsx)(qa,{className:`h-4 w-4`})}].map(n=>(0,u.jsxs)(`button`,{onClick:()=>t(n.value),className:`py-2 px-0.5 flex flex-col items-center justify-center gap-1 font-bold text-[9px] rounded-lg uppercase tracking-wider transition-all duration-150 ${e===n.value?`bg-orange-600 text-white shadow-sm shadow-orange-600/10`:`text-slate-500 hover:text-orange-600 hover:bg-orange-50/50`}`,children:[n.icon,(0,u.jsx)(`span`,{children:n.value})]},n.value))}),(0,u.jsxs)(`div`,{className:`p-4 flex-1 flex flex-col min-h-0 overflow-y-auto`,children:[e===`text`&&(0,u.jsx)(so,{handleSidebarDragStart:F,createTextBlock:s,setBlocks:n,setSelectedBlockId:i,setActiveTab:t,defaultStyles:o}),e===`tables`&&(0,u.jsx)(co,{schemas:_,toggleSchemaColumn:v,customTableName:y,setCustomTableName:b,customLoopStart:x,setCustomLoopStart:S,customLoopEnd:C,setCustomLoopEnd:w,handleAddCustomTable:T,handleSidebarDragStart:F,setBlocks:n,setSelectedBlockId:i,setActiveTab:t,defaultStyles:o}),e===`images`&&(0,u.jsx)(lo,{customImageTypes:A,newImgTypeName:j,setNewImgTypeName:M,handleAddCustomImageType:ee,handleSidebarDragStart:F,createImageBlock:c,setBlocks:n,setSelectedBlockId:i,setActiveTab:t}),e===`placeholders`&&(0,u.jsx)(uo,{placeholders:te,schemas:_,searchPlaceholder:ne,setSearchPlaceholder:re,placeholderMockData:N,setPlaceholderMockData:P,selectedBlockId:r,setBlocks:n}),e===`styles`&&(0,u.jsx)(fo,{selectedBlockId:r,getSelectedBlock:a,updateSelectedStyle:l,updateSelectedImageInfo:d,fontSizesState:ie,fontFamiliesState:ae,fontWeightsState:oe,handleDeleteBlock:f,newColName:E,setNewColName:D,newColPlaceholder:O,setNewColPlaceholder:k,handleAddTableColumn:m,handleRemoveTableColumn:p,handleUpdateTableColumn:h,handleReorderTableColumn:g,setBlocks:n})]})]})}var mo=({block:e,onUpdate:t,onSelect:n,onDrop:r})=>{let i=(0,l.useRef)(null);(0,l.useEffect)(()=>{i.current&&i.current.innerHTML!==e.content&&document.activeElement!==i.current&&(i.current.innerHTML=e.content||`<br/>`)},[e.id,e.content]);let{bold:a,italic:o,underline:s,strikethrough:c,width:d,...f}=e.style,p={...f};a&&(p.fontWeight=`bold`),o&&(p.fontStyle=`italic`);let m=[];return s&&m.push(`underline`),c&&m.push(`line-through`),m.length>0&&(p.textDecoration=m.join(` `)),(0,u.jsx)(`div`,{ref:i,contentEditable:!0,suppressContentEditableWarning:!0,onFocus:n,onInput:e=>t(e.currentTarget.innerHTML),onBlur:e=>t(e.currentTarget.innerHTML),style:p,className:`min-h-[1.5em] w-full break-words outline-none`,onDrop:r,onDragOver:e=>e.preventDefault()})},ho=({blockId:e,colIdx:t,placeholder:n,onUpdate:r,onDrop:i})=>{let a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{a.current&&a.current.innerHTML!==n&&document.activeElement!==a.current&&(a.current.innerHTML=n)},[e,t,n]),(0,u.jsx)(`td`,{ref:a,contentEditable:!0,suppressContentEditableWarning:!0,onInput:e=>r(e.currentTarget.innerText||e.currentTarget.innerHTML),onBlur:e=>r(e.currentTarget.innerText||e.currentTarget.innerHTML),onDrop:i,onDragOver:e=>e.preventDefault(),className:`border border-slate-200 px-2.5 py-2.5 text-slate-500 bg-slate-50/20 font-sans outline-none focus:bg-slate-100/50 transition-colors`})},go=e=>{let t=[];return e.forEach(e=>{e.style.sameRow&&t.length>0?t[t.length-1].blocks.push(e):t.push({id:e.id,blocks:[e]})}),t};function _o({blocks:e,setBlocks:t,selectedBlockId:n,setSelectedBlockId:r,setActiveTab:i,showMockData:a,placeholderMockData:o,dragOverIndex:s,setDragOverIndex:c,draggedSidebarItem:l,defaultStyles:d,zoom:f,panOffset:p,spacePressed:m,canvasHeight:h,viewportRef:g,canvasContainerRef:_,handleMouseDown:v,handleMouseMove:y,handleMouseUp:b,createTextBlock:x,duplicateBlock:S,reorderBlock:C,handleDeleteBlock:w,handleSidebarDrop:T,handleTableCellDrop:E,updateTableCell:D,handleTextDrop:O}){let k=(e,t)=>{e.dataTransfer.setData(`blockIndex`,t.toString()),e.dataTransfer.setData(`source`,`canvas`),e.dataTransfer.effectAllowed=`move`},A=(n,r)=>{n.preventDefault(),n.stopPropagation();let i=n.dataTransfer.getData(`source`);if(i===`sidebar`)T(r);else if(i===`canvas`){let i=parseInt(n.dataTransfer.getData(`blockIndex`));if(isNaN(i)||i===r)return;let a=[...e],o=a.splice(i,1)[0],s=i<r?r-1:r;a.splice(s,0,o),t(a)}c(null)};return(0,u.jsx)(`div`,{ref:g,className:`flex-1 overflow-auto p-8 flex justify-center items-start outline-none transition-all ${m?`cursor-grab active:cursor-grabbing`:`cursor-default`}`,onMouseDown:v,onMouseMove:y,onMouseUp:b,onMouseLeave:b,children:(0,u.jsx)(`div`,{style:{transform:`translate(${p.x}px, ${p.y}px) scale(${f})`,transformOrigin:`top center`},className:`transition-transform duration-75 ease-out select-none`,children:(0,u.jsxs)(`div`,{ref:_,style:{height:`${h}px`},className:`w-[794px] min-h-[1123px] bg-white shadow-lg border border-gray-300/80 px-[60px] py-[60px] flex flex-col relative canvas-editor-area`,onDragOver:e=>e.preventDefault(),onDrop:n=>{if(n.preventDefault(),n.stopPropagation(),l)T(e.length);else{let e=n.dataTransfer.getData(`placeholder`);if(e){n.preventDefault();let a=x(`p`,`{{${e}}}`,d?.p);t(e=>[...e,a]),r(a.id),i(`styles`)}}},children:[e.length===0?(0,u.jsxs)(`div`,{className:`flex-1 border-2 border-dashed border-gray-200 rounded-2xl flex flex-col items-center justify-center p-8 text-center text-slate-400`,children:[(0,u.jsx)(qa,{className:`h-10 w-10 mb-3 animate-bounce text-slate-350`}),(0,u.jsx)(`span`,{className:`font-bold text-sm text-slate-600 block`,children:`Drag & Drop Editor Canvas`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-400 mt-1 max-w-sm`,children:`Select elements from the sidebar tabs (Text, Tables, Images) and drag them here to assemble your template structure.`})]}):go(e).map(a=>{let o=a.blocks.length>1;return(0,u.jsx)(`div`,{className:`group/row ${a.blocks.some(e=>e.style.position===`absolute`)?``:`relative`} border border-transparent rounded-lg hover:border-slate-200/60 p-1 mb-2 ${o?a.blocks[0]?.style?.flexDirection===`column`?`flex flex-col gap-2`:`flex flex-row gap-4`:``}`,children:a.blocks.map(a=>{let s=n===a.id,l={...a.style,..._a(a.style.customCss||``)};return(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>{let n=e.findIndex(e=>e.id===a.id);k(t,n)},onDragOver:t=>{t.preventDefault(),c(e.findIndex(e=>e.id===a.id))},onDrop:t=>{let n=e.findIndex(e=>e.id===a.id);A(t,n)},onClick:e=>{e.stopPropagation(),r(a.id),i(`styles`)},style:{width:o?a.style.width||`48%`:(a.style.position,`100%`),height:a.style.position===`absolute`?a.style.height||`100%`:void 0,position:a.style.position,top:a.style.top,left:a.style.left,zIndex:a.style.zIndex?parseInt(a.style.zIndex):void 0},className:`group/block relative p-2.5 rounded-xl border border-transparent transition-all duration-150 cursor-pointer ${s?`bg-orange-50/20 border-orange-500 shadow-sm ring-2 ring-orange-500/10`:`hover:bg-slate-50/30 hover:border-gray-200`} ${a.style.position===`absolute`?`!absolute !inset-0 !m-auto`:``}`,children:[s&&(0,u.jsxs)(`div`,{className:`absolute -top-3.5 right-3 bg-orange-600 text-white rounded-lg px-2 py-0.5 text-[10px] font-bold flex items-center space-x-1.5 shadow-md z-30 select-none`,children:[(0,u.jsx)(`button`,{onClick:()=>{C(e.findIndex(e=>e.id===a.id),`up`)},className:`hover:text-slate-350`,title:`Move Up`,children:(0,u.jsx)(Fa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>{C(e.findIndex(e=>e.id===a.id),`down`)},className:`hover:text-slate-350`,title:`Move Down`,children:(0,u.jsx)(Pa,{className:`h-3 w-3`})}),(0,u.jsx)(`div`,{className:`h-3 w-[1px] bg-slate-700`}),(0,u.jsx)(`button`,{onClick:e=>S(a.id,e),className:`hover:text-slate-350`,title:`Duplicate block`,children:(0,u.jsx)(Ra,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:e=>w(a.id,e),className:`hover:text-red-400 text-red-300`,title:`Delete block`,children:(0,u.jsx)(no,{className:`h-3 w-3`})})]}),a.type===`table`?(0,u.jsx)(`div`,{className:`overflow-x-auto w-full select-none`,children:(0,u.jsxs)(`table`,{style:l,className:`w-full border-collapse`,children:[(0,u.jsx)(`thead`,{children:(0,u.jsx)(`tr`,{children:a.tableInfo?.columns.filter(e=>e.enabled!==!1).map((e,t)=>(0,u.jsx)(`th`,{className:`border border-slate-200 px-2.5 py-1 text-slate-700 text-left bg-slate-50 font-sans`,children:e.columnName||``},t))})}),(0,u.jsx)(`tbody`,{children:(0,u.jsx)(`tr`,{className:`bg-slate-50/10 border-b border-slate-100 hover:bg-slate-50/20`,children:a.tableInfo?.columns.filter(e=>e.enabled!==!1).map((e,t)=>{if(e.loop&&e.columns&&e.columns.length>0){let n=e.columns.filter(e=>e.enabled!==!1);return(0,u.jsx)(`td`,{className:`border border-slate-200 p-2 align-top bg-slate-50/20`,children:(0,u.jsxs)(`div`,{className:`w-full overflow-x-auto space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] font-semibold text-slate-500`,children:[(0,u.jsxs)(`span`,{children:[`Sub-table: `,e.columnName]}),(0,u.jsx)(`span`,{className:`px-1.5 py-0.5 bg-slate-200 text-slate-600 rounded text-[8px]`,children:`loop = true`})]}),(0,u.jsxs)(`table`,{className:`w-full border-collapse border border-slate-200 rounded text-xs bg-white`,children:[(0,u.jsx)(`thead`,{children:(0,u.jsx)(`tr`,{children:n.map((e,t)=>(0,u.jsx)(`th`,{className:`border border-slate-200 px-2 py-1 text-slate-700 text-left bg-slate-100/80 font-sans font-semibold text-[10px]`,children:e.columnName},t))})}),(0,u.jsx)(`tbody`,{children:(0,u.jsx)(`tr`,{className:`bg-slate-50/30`,children:n.map((e,n)=>(0,u.jsx)(ho,{blockId:a.id,colIdx:n,placeholder:e.placeholder,onUpdate:e=>D(a.id,t,e,n),onDrop:e=>E(e,a.id,t,n)},n))})})]})]})},t)}return(0,u.jsx)(ho,{blockId:a.id,colIdx:t,placeholder:e.placeholder,onUpdate:e=>D(a.id,t,e),onDrop:e=>E(e,a.id,t)},t)})})})]})}):a.type===`image`?(0,u.jsx)(`div`,{style:{textAlign:l.textAlign||`left`,width:`100%`,marginBottom:l.marginBottom,padding:l.padding,backgroundColor:l.backgroundColor},className:`w-full select-none`,children:(0,u.jsx)(`div`,{style:{width:o?`100%`:a.style.width||`100%`,display:`inline-block`},children:a.imageInfo?.imageType===`barcode`?(0,u.jsx)(`div`,{style:{width:`100%`,height:a.style.height||a.style.minHeight||`70px`},className:`border border-dashed border-slate-200 p-2 bg-slate-50/5 rounded-lg flex items-center justify-center overflow-hidden`,dangerouslySetInnerHTML:{__html:va(a.imageInfo.barcodeValue||`SHIP-99201`)}}):(0,u.jsx)(`img`,{src:a.imageInfo?.url||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`,style:{width:`100%`,height:`auto`,maxHeight:a.style.height||`300px`,objectFit:a.style.objectFit||`contain`,opacity:a.style.opacity||`1`,display:`block`},alt:`graphic content`})})}):(0,u.jsx)(mo,{block:a,onUpdate:e=>{t(t=>t.map(t=>t.id===a.id?{...t,content:e}:t))},onSelect:()=>r(a.id),onDrop:e=>O(e,a.id)})]},a.id)})},a.id)}),s!==null&&(0,u.jsx)(`div`,{className:`h-[2px] bg-orange-500 rounded my-1 shadow-md animate-pulse`})]})})})}function vo({showClearCanvas:e,handleClearCanvas:t,customButtonStyles:n,customButtonClassNames:r,zoom:i,setZoom:a,setPanOffset:o}){return(0,u.jsxs)(`div`,{className:`bg-white border-b border-gray-200 px-6 py-3 flex items-center justify-between shadow-xs sticky top-0 z-20`,children:[(0,u.jsx)(`div`,{className:`flex items-center space-x-4`,children:e&&(0,u.jsxs)(`button`,{onClick:t,style:n?.clearCanvas,className:r?.clearCanvas||`inline-flex items-center space-x-1 px-2.5 py-1 text-xs font-semibold border border-red-200 text-red-650 bg-red-50 hover:bg-red-100 rounded-lg transition-colors`,title:`Clear all canvas elements`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Clear Canvas`})]})}),(0,u.jsxs)(`div`,{className:`flex items-center space-x-3 bg-slate-50 border border-gray-200 px-3 py-1 rounded-xl shadow-xs select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-1`,children:[(0,u.jsx)(`button`,{onClick:()=>a(e=>Math.max(e-.1,.5)),className:`h-6 w-6 rounded border border-gray-200 bg-white hover:bg-slate-50 flex items-center justify-center font-bold text-slate-650 hover:text-slate-900 transition-colors text-xs select-none`,title:`Zoom Out`,children:`−`}),(0,u.jsxs)(`div`,{className:`w-12 text-center text-xs font-bold text-slate-700`,children:[Math.round(i*100),`%`]}),(0,u.jsx)(`button`,{onClick:()=>a(e=>Math.min(e+.1,2)),className:`h-6 w-6 rounded border border-gray-200 bg-white hover:bg-slate-50 flex items-center justify-center font-bold text-slate-650 hover:text-slate-900 transition-colors text-xs select-none`,title:`Zoom In`,children:`+`})]}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-gray-200`}),(0,u.jsx)(`input`,{type:`range`,min:`0.5`,max:`2.0`,step:`0.05`,value:i,onChange:e=>a(parseFloat(e.target.value)),className:`w-20 accent-orange-600 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`}),(0,u.jsx)(`button`,{onClick:()=>{a(1),o({x:0,y:0})},className:`text-[10px] font-bold text-slate-500 hover:text-slate-800 hover:underline`,children:`Reset`})]})]})}function yo({previewOpen:e,setPreviewOpen:t,generateExportHtml:n}){return e?(0,u.jsx)(`div`,{className:`fixed inset-0 bg-slate-950/65 backdrop-blur-xs flex items-center justify-center z-50 p-6`,children:(0,u.jsxs)(`div`,{className:`bg-white rounded-2xl w-full max-w-[900px] h-[90%] flex flex-col shadow-2xl overflow-hidden border border-gray-200`,children:[(0,u.jsxs)(`div`,{className:`bg-slate-50 border-b border-gray-200 px-6 py-4 flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`h3`,{className:`text-sm font-bold text-slate-800 flex items-center space-x-2`,children:[(0,u.jsx)(Ba,{className:`h-4 w-4 text-slate-655`}),(0,u.jsx)(`span`,{children:`HTML Document Render Output`})]}),(0,u.jsx)(`p`,{className:`text-[10px] text-slate-400 mt-0.5`,children:`Sandboxed iframe preview of final template markup`})]}),(0,u.jsx)(`button`,{onClick:()=>t(!1),className:`p-1.5 bg-slate-100 hover:bg-slate-200 text-slate-500 hover:text-slate-800 rounded-lg transition-colors`,children:(0,u.jsx)(ao,{className:`h-4 w-4`})})]}),(0,u.jsx)(`div`,{className:`flex-1 bg-slate-100 p-6 overflow-hidden`,children:(0,u.jsx)(`iframe`,{title:`HTML Preview Sandbox`,srcDoc:n(!0),className:`w-full h-full bg-white border border-gray-200 rounded-xl shadow-xs`,sandbox:`allow-same-origin`})}),(0,u.jsxs)(`details`,{className:`bg-slate-50 border-t border-gray-200`,children:[(0,u.jsxs)(`summary`,{className:`px-6 py-3 text-xs font-bold text-slate-600 cursor-pointer select-none hover:text-slate-800 flex items-center justify-between`,children:[(0,u.jsx)(`span`,{children:`View Raw Output Markup (HTML)`}),(0,u.jsx)(`span`,{className:`text-[10px] text-slate-400 font-medium font-sans`,children:`Click to expand`})]}),(0,u.jsx)(`div`,{className:`px-6 pb-6 overflow-x-auto max-h-[250px]`,children:(0,u.jsx)(`pre`,{className:`bg-slate-900 text-slate-200 p-4 rounded-lg text-[10px] font-mono whitespace-pre-wrap select-all`,children:n(!1)})})]})]})}):null}function bo({bubbleCoords:e,applySelectionFormat:t}){return e?(0,u.jsxs)(`div`,{className:`fixed bg-slate-900 border border-slate-800 text-white rounded-xl shadow-xl py-1 px-1.5 flex items-center space-x-1.5 z-50 select-none -translate-x-1/2`,style:{left:`${e.x}px`,top:`${e.y}px`},children:[(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`bold`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center font-bold text-xs text-slate-200 hover:text-white transition-colors`,title:`Bold Selection`,children:`B`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`italic`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center italic text-xs text-slate-200 hover:text-white transition-colors`,title:`Italic Selection`,children:`I`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`underline`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center underline text-xs text-slate-200 hover:text-white transition-colors`,title:`Underline Selection`,children:`U`}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800 mx-1`}),(0,u.jsxs)(`select`,{value:e.format||``,onChange:e=>{e.preventDefault(),e.target.value&&(t(`formatBlock`,e.target.value),e.target.value===`P`&&t(`fontSize`,`3`))},className:`bg-slate-800 text-white text-[10px] rounded px-1 py-0.5 outline-none cursor-pointer border border-slate-700`,children:[(0,u.jsx)(`option`,{value:``,disabled:!0,children:`Format...`}),(0,u.jsx)(`option`,{value:`H1`,children:`Heading 1`}),(0,u.jsx)(`option`,{value:`H2`,children:`Heading 2`}),(0,u.jsx)(`option`,{value:`H3`,children:`Heading 3`}),(0,u.jsx)(`option`,{value:`P`,children:`Paragraph`}),(0,u.jsx)(`option`,{value:`BLOCKQUOTE`,children:`Quote`})]}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800 mx-1`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#3b82f6`)},className:`h-4 w-4 rounded-full bg-blue-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Blue`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#ef4444`)},className:`h-4 w-4 rounded-full bg-red-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Red`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#1e293b`)},className:`h-4 w-4 rounded-full bg-slate-700 hover:scale-110 transition-transform cursor-pointer border border-slate-850`,title:`Color Slate`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#22c55e`)},className:`h-4 w-4 rounded-full bg-green-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Green`}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`removeFormat`)},className:`hover:bg-slate-800 rounded text-[10px] px-1.5 h-6 flex items-center justify-center text-slate-400 hover:text-white font-semibold transition-colors`,title:`Clear Formatting`,children:`Clear`})]}):null}Dr.workerSrc=`https://cdn.jsdelivr.net/npm/pdfjs-dist@6.1.200/build/pdf.worker.min.mjs`;var xo=e=>{let t=[];return e.forEach(e=>{e.style.sameRow&&t.length>0?t[t.length-1].blocks.push(e):t.push({id:e.id,blocks:[e]})}),t},So=e=>e?e.replace(/contenteditable="[^"]*"/g,``).replace(/class="[^"]*"/g,``).replace(/data-placeholder="[^"]*"/g,``).replace(/&nbsp;/g,` `).trim():``;function Co({tableSchemas:e,placeholders:t,defaultLogo:n,defaultBanner:r,headerTitle:i=`HTML Template Builder`,headerSubtitle:a=`Design and export templates dynamically`,headerLogo:o,typographySizes:s,typographyWeights:c,typographyFonts:f,templatingLanguage:p=`csharp`,loopSyntax:m=`foreach`,onChange:h,onExport:g,onExportPdf:_,initialBlocks:v,defaultStyles:y,showImportHtml:b=!0,showImportPdf:x=!0,showClearCanvas:S=!0,showPreview:C=!0,showExport:w=!0,showExportPdf:T=!0,customButtonStyles:E,customButtonClassNames:D}={}){let{zoom:O,setZoom:k,panOffset:A,setPanOffset:j,spacePressed:M,canvasHeight:ee,viewportRef:te,canvasContainerRef:ne,handleMouseDown:re,handleMouseMove:N,handleMouseUp:P}=Ca(),{customTableName:F,setCustomTableName:ie,customLoopStart:ae,setCustomLoopStart:oe,customLoopEnd:se,setCustomLoopEnd:I,newColName:ce,setNewColName:le,newColPlaceholder:ue,setNewColPlaceholder:de,bubbleCoords:fe,setBubbleCoords:pe,schemas:me,isParsing:he,setIsParsing:ge,parseStatusText:L,setParseStatusText:R,parseError:_e,setParseError:ve,draggedSidebarItem:z,setDraggedSidebarItem:ye,dragOverIndex:be,setDragOverIndex:xe,newImgTypeName:Se,setNewImgTypeName:Ce,customImageTypes:we,searchPlaceholder:B,setSearchPlaceholder:Te,handleAddCustomTable:Ee,handleAddCustomImageType:De,toggleSchemaColumn:Oe,applySelectionFormat:ke,setSavedRange:Ae}=wa({tableSchemas:e}),{blocks:je,setBlocks:V,selectedBlockId:Me,setSelectedBlockId:Ne,getSelectedBlock:Pe,createTextBlock:Fe,createTableBlock:H,createImageBlock:U,handleDeleteBlock:Ie,handleDuplicateBlock:Le,handleMoveBlockUp:Re,handleMoveBlockDown:ze,updateSelectedStyle:W,updateSelectedImageInfo:Be,handleRemoveTableColumn:Ve,handleAddTableColumn:He,handleUpdateTableColumn:Ue,handleReorderTableColumn:We}=Sa({initialBlocks:v,defaultStyles:y,defaultLogo:n,defaultBanner:r,onChange:h}),[Ge,Ke]=(0,l.useState)(`text`),[qe,Je]=(0,l.useState)(!1),[Ye]=(0,l.useState)(!0),[Xe]=(0,l.useState)(s||[{label:`8px`,value:`8px`},{label:`9px`,value:`9px`},{label:`10px`,value:`10px`},{label:`11px`,value:`11px`},{label:`12px`,value:`12px`},{label:`14px`,value:`14px`},{label:`16px`,value:`16px`},{label:`18px`,value:`18px`},{label:`20px`,value:`20px`},{label:`24px`,value:`24px`},{label:`28px`,value:`28px`},{label:`32px`,value:`32px`},{label:`36px`,value:`36px`}]),[Ze]=(0,l.useState)(f||[{label:`Outfit (Default)`,value:`'Outfit', 'Inter', sans-serif`},{label:`Inter`,value:`'Inter', sans-serif`},{label:`Roboto`,value:`'Roboto', sans-serif`},{label:`System Sans`,value:`system-ui, -apple-system, sans-serif`},{label:`Georgia (Serif)`,value:`Georgia, serif`},{label:`Courier New (Mono)`,value:`'Courier New', monospace`}]),[Qe]=(0,l.useState)(c||[{label:`Light`,value:`300`},{label:`Regular`,value:`400`},{label:`Medium`,value:`500`},{label:`Semibold`,value:`600`},{label:`Bold`,value:`700`},{label:`Extra Bold`,value:`800`}]),[$e]=(0,l.useState)(p),[et]=(0,l.useState)(m),[tt]=(0,l.useState)(!0),[nt,rt]=(0,l.useState)({});(0,l.useEffect)(()=>{let e=()=>{let e=window.getSelection();if(!e||e.isCollapsed||e.toString().trim()===``){pe(null),Ae(null);return}let t=document.activeElement;if(!(t&&t.getAttribute(`contenteditable`)===`true`&&(t.closest(`.canvas-editor-area`)||t.closest(`td`)))){pe(null),Ae(null);return}try{let t=e.getRangeAt(0),n=t.getBoundingClientRect(),r=document.queryCommandValue(`formatBlock`)||``;r=r.toUpperCase(),pe({x:n.left+n.width/2,y:n.top-38,format:r}),Ae(t)}catch{pe(null),Ae(null)}};return document.addEventListener(`selectionchange`,e),()=>document.removeEventListener(`selectionchange`,e)},[pe]),(0,l.useEffect)(()=>{let e={};(t||[]).forEach(t=>{let n=t.placeholder.replace(/[{}]/g,``);e[n]=t.mockValue||``}),me.forEach(t=>{t.columns.forEach(t=>{let n=t.placeholder.replace(/[{}]/g,``).replace(/^(\.\.\/|package\.|item\.)/,``);e[n]||(e[n]=t.mockValue||``)})}),rt(e)},[t,me]),(0,l.useEffect)(()=>{let e=te.current;if(!e)return;let t=e=>{if(e.ctrlKey){e.preventDefault();let t=e.deltaY<0?1:-1;k(e=>Math.min(2,Math.max(.5,e+t*.05)))}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[te,k]),(0,l.useEffect)(()=>{window.updateContentFromRawDelete=(e,t)=>{V(n=>n.map(n=>n.id===e?{...n,content:t}:n))}},[V]);let it=e=>{let t=e.target.files?.[0];if(!t)return;ge(!0),R(`Parsing HTML...`),ve(null);let n=new FileReader;n.onload=t=>{try{let e=t.target?.result,n=ba(e);n.length>0&&V(n)}catch(e){console.error(e),ve(e.message||`Failed to parse HTML`)}finally{ge(!1),e.target&&(e.target.value=``)}},n.readAsText(t)},G=e=>{let t=e.target.files?.[0];if(!t)return;ge(!0),R(`Reading PDF text layers...`),ve(null);let n=new FileReader;n.onload=async()=>{try{let e=n.result,t=await xa(e,d);t.length>0&&V(e=>[...e,...t])}catch(e){console.error(e),ve(e.message||`Failed to read PDF`)}finally{ge(!1),e.target&&(e.target.value=``)}},n.readAsArrayBuffer(t)},at=e=>{let t=e||`items`;if($e===`handlebars`||$e===`mustache`){let e=et===`foreach`?`foreach`:`each`;return{start:`{{#${e} ${t}}}`,end:`{{/${e}}}`}}return $e===`liquid`||$e===`scriban`||$e===`dotnet`?{start:`{% for ${t.endsWith(`s`)?t.slice(0,-1):`item`} in ${t} %}`,end:`{% endfor %}`}:$e===`js`||$e===`ts`?{start:`\${${t}.map(${t.endsWith(`s`)?t.slice(0,-1):`item`} => \``,end:"`).join('')}"}:$e===`csharp`||$e===`razor`?{start:`@foreach (var ${t.endsWith(`s`)?t.slice(0,-1):`item`} in ${t}) {`,end:`}`}:{start:ae.replace(`items`,t),end:se}},ot=(e=!1)=>{let t=`<!DOCTYPE html>
58
+ </svg>`},ya=(e,t)=>{let n=`11px`,r=`400`;return e===`h1`?(n=`24px`,r=`700`):e===`h2`?(n=`20px`,r=`700`):e===`h3`?(n=`16px`,r=`600`):e===`h4`?(n=`14px`,r=`600`):e===`h5`?(n=`12px`,r=`600`):e===`h6`?(n=`10px`,r=`600`):e===`title`?(n=`28px`,r=`800`):e===`subtitle`?(n=`14px`,r=`300`):e===`caption`&&(n=`9px`,r=`400`),{id:`block-${Math.random().toString(36).substr(2,9)}`,type:e,content:t,style:{fontSize:n,fontWeight:r,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`title`].includes(e),italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`8px`,padding:`8px`,minHeight:`auto`}}},ba=e=>{let t=new DOMParser().parseFromString(e,`text/html`),n=[],r=Array.from(t.body.children);if(r.length===0){let e=t.body.innerText||t.body.textContent||``;e.trim()&&n.push(ya(`p`,e.trim()))}else{let e=t.querySelectorAll(`style`),i=[];e.forEach(e=>{let t=e.textContent||``,n=/([^{]+)\{([^}]+)\}/g,r;for(;(r=n.exec(t))!==null;){let e=r[1].trim(),t=r[2].trim(),n={};t.split(`;`).forEach(e=>{let t=e.split(`:`);t.length===2&&(n[t[0].trim().toLowerCase()]=t[1].trim())}),i.push({selector:e,styles:n})}});let a=e=>{let t={fontSize:`11px`,fontWeight:`400`,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:!1,italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`8px`,padding:`8px`},n=e.style;return n.fontSize&&(t.fontSize=n.fontSize),n.fontWeight&&(t.fontWeight=n.fontWeight),n.color&&(t.color=n.color),n.backgroundColor&&(t.backgroundColor=n.backgroundColor),n.textAlign&&(t.textAlign=n.textAlign),n.padding&&(t.padding=n.padding),n.marginBottom&&(t.marginBottom=n.marginBottom),n.width&&(t.width=n.width),i.forEach(n=>{try{e.matches(n.selector)&&(n.styles[`font-size`]&&(t.fontSize=n.styles[`font-size`]),n.styles[`font-weight`]&&(t.fontWeight=n.styles[`font-weight`]),n.styles.color&&(t.color=n.styles.color),n.styles[`background-color`]&&(t.backgroundColor=n.styles[`background-color`]),n.styles[`text-align`]&&(t.textAlign=n.styles[`text-align`]),n.styles.padding&&(t.padding=n.styles.padding),n.styles[`margin-bottom`]&&(t.marginBottom=n.styles[`margin-bottom`]),n.styles.width&&(t.width=n.styles.width))}catch{}}),(t.fontWeight===`bold`||parseInt(t.fontWeight)>=600)&&(t.bold=!0),t};r.forEach(e=>{let t=e;if(t.tagName===`STYLE`)return;let r=t.querySelector(`table, img, h1, h2, h3, h4, h5, h6, p, span, div`)||t,i=r.tagName.toLowerCase(),o=a(r);if(i===`table`){let e=Array.from(r.querySelectorAll(`thead th`));e.length===0&&(e=Array.from(r.querySelectorAll(`tr:first-child th, tr:first-child td`)));let t=e.map(e=>({columnName:e.textContent?.trim()||`Header`,placeholder:`{{item.${e.textContent?.trim().toLowerCase().replace(/\s+/g,`_`)||`field`}}}`,enabled:!0}));n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`table`,content:``,style:o,tableInfo:{tableName:`imported_table`,columns:t,loop:!0,isNestable:!1,parentPath:`items`,maxNestingDepth:5,nestingPrefix:` `,showNestingLevel:!1}})}else if(i===`img`)n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`image`,content:``,style:o,imageInfo:{imageType:`logo`,url:r.getAttribute(`src`)||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}});else if(i===`svg`)n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:`image`,content:``,style:o,imageInfo:{imageType:`barcode`,barcodeValue:`SHIP-99201`,barcodePlaceholder:`{{barcode}}`}});else{let e=`p`;[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`].includes(i)?e=i:i===`span`&&(e=`caption`),n.push({id:`block-${Math.random().toString(36).substr(2,9)}`,type:e,content:r.innerHTML||r.textContent||``,style:o})}})}return n},xa=async(e,t)=>{let n=await t.getDocument({data:new Uint8Array(e)}).promise,r=[],i=Math.min(n.numPages,3);for(let e=1;e<=i;e++){let t=(await(await n.getPage(e)).getTextContent()).items.map(e=>({text:e.str,x:e.transform[4],y:e.transform[5],fontSize:e.transform[3]})).filter(e=>e.text.trim()!==``);if(t.length===0)continue;t.sort((e,t)=>Math.abs(e.y-t.y)<6?e.x-t.x:t.y-e.y);let i=[],a=[];if(t.forEach(e=>{if(a.length===0)a.push(e);else{let t=a[a.length-1];if(Math.abs(e.y-t.y)<6)a.push(e);else{let t=a.map(e=>e.text).join(` `),n=a.reduce((e,t)=>e+t.y,0)/a.length,r=Math.max(...a.map(e=>e.fontSize));i.push({y:n,fontSize:r,text:t}),a=[e]}}}),a.length>0){let e=a.map(e=>e.text).join(` `),t=a.reduce((e,t)=>e+t.y,0)/a.length,n=Math.max(...a.map(e=>e.fontSize));i.push({y:t,fontSize:n,text:e})}i.forEach(e=>{let t=`p`,n=e.fontSize>16;n?t=e.fontSize>26?`h1`:e.fontSize>20?`h2`:`h3`:e.fontSize<10&&(t=`caption`);let i=Math.round(e.fontSize*1.15)+`px`;r.push({id:`pdf-block-${Math.random().toString(36).substr(2,9)}`,type:t,content:e.text,style:{fontSize:i,fontWeight:n?`700`:`400`,color:`#1e293b`,backgroundColor:`transparent`,textAlign:`left`,bold:n,italic:!1,underline:!1,strikethrough:!1}})})}return r};function Sa({initialBlocks:e,defaultStyles:t,defaultLogo:n,defaultBanner:r,onChange:i}={}){let[a,o]=(0,l.useState)(e||[]),[s,c]=(0,l.useState)(null);(0,l.useEffect)(()=>{i&&i(a)},[a,i]);let u=()=>a.find(e=>e.id===s)||null,d=(e,t,n)=>{let r={};return e===`title`?r={fontSize:`24px`,fontWeight:`800`}:e===`subtitle`?r={fontSize:`14px`,fontWeight:`700`,color:`#64748b`}:e===`h1`?r={fontSize:`20px`,fontWeight:`800`}:e===`h2`?r={fontSize:`18px`,fontWeight:`700`}:e===`h3`?r={fontSize:`16px`,fontWeight:`600`}:e===`caption`&&(r={fontSize:`10px`,color:`#94a3b8`}),{id:Math.random().toString(36).substring(2,11),type:e,content:t,style:{fontSize:`12px`,fontWeight:`normal`,textAlign:`left`,color:`#1e293b`,backgroundColor:`transparent`,marginBottom:`0px`,padding:`0px`,bold:!1,italic:!1,underline:!1,strikethrough:!1,...r,...n}}},f=e=>({...e,columns:e.columns?e.columns.map(f):void 0});return{blocks:a,setBlocks:o,selectedBlockId:s,setSelectedBlockId:c,getSelectedBlock:u,createTextBlock:d,createTableBlock:e=>({id:Math.random().toString(36).substring(2,11),type:`table`,content:``,style:{fontSize:`11px`,fontWeight:`normal`,textAlign:`left`,color:`#334155`,backgroundColor:`transparent`,marginBottom:`0px`,padding:`0px`,bold:!1,italic:!1,underline:!1,strikethrough:!1,...t?.table||{}},tableInfo:{...e,columns:e.columns.map(f),mockRows:[]}}),createImageBlock:e=>{let i=`100%`,a=`120px`;return e===`logo`?(i=`120px`,a=`60px`):e===`banner`?(i=`100%`,a=`150px`):e===`barcode`?(i=`200px`,a=`80px`):e===`watermark`&&(i=`300px`,a=`300px`),{id:Math.random().toString(36).substring(2,11),type:`image`,content:``,style:{fontSize:`12px`,fontWeight:`normal`,color:`#000055`,backgroundColor:`transparent`,textAlign:`center`,marginBottom:`0px`,padding:`0px`,width:i,height:a,minHeight:a,bold:!1,italic:!1,underline:!1,strikethrough:!1,...t?.image||{},...e===`watermark`?{opacity:`0.2`,position:`absolute`,top:`0`,left:`0`,zIndex:10,height:`100%`}:{}},imageInfo:{imageType:e,url:e===`logo`?n||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`:e===`banner`?r||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`:pa,barcodeValue:e===`barcode`?`SHIP-99201`:void 0,barcodePlaceholder:e===`barcode`?`{{barcode}}`:void 0}}},handleDeleteBlock:e=>{o(t=>t.filter(t=>t.id!==e)),s===e&&c(null)},handleDuplicateBlock:e=>{let t=a.find(t=>t.id===e);if(!t)return;let n={...t,id:Math.random().toString(36).substring(2,11),style:{...t.style},tableInfo:t.tableInfo?{...t.tableInfo,columns:t.tableInfo.columns.map(f),mockRows:t.tableInfo.mockRows?[...t.tableInfo.mockRows]:void 0}:void 0,imageInfo:t.imageInfo?{...t.imageInfo}:void 0},r=a.findIndex(t=>t.id===e);o(e=>{let t=[...e];return t.splice(r+1,0,n),t}),c(n.id)},handleMoveBlockUp:e=>{e!==0&&o(t=>{let n=[...t],r=n[e];return n[e]=n[e-1],n[e-1]=r,n})},handleMoveBlockDown:e=>{e!==a.length-1&&o(t=>{let n=[...t],r=n[e];return n[e]=n[e+1],n[e+1]=r,n})},updateSelectedStyle:(e,t)=>{s&&o(n=>n.map(n=>n.id===s?{...n,style:{...n.style,[e]:t}}:n))},updateSelectedImageInfo:(e,t)=>{s&&o(i=>i.map(i=>{if(i.id===s&&i.type===`image`){let a={};return e===`imageType`&&(a=t===`logo`?{url:n||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}:t===`banner`?{url:r||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}:t===`barcode`?{barcodeValue:`SHIP-99201`,barcodePlaceholder:`{{barcode}}`}:{url:pa}),{...i,imageInfo:{...i.imageInfo,[e]:t,...a}}}return i}))},handleRemoveTableColumn:(e,t)=>{s&&o(n=>n.map(n=>{if(n.id===s&&n.type===`table`&&n.tableInfo){let r=[...n.tableInfo.columns];if(t!==void 0&&r[e]?.columns){let n=r[e].columns.filter((e,n)=>n!==t);r[e]={...r[e],columns:n}}else r.splice(e,1);return{...n,tableInfo:{...n.tableInfo,columns:r}}}return n}))},handleAddTableColumn:(e,t,n,r)=>{!s||!e.trim()||o(i=>i.map(i=>{if(i.id===s&&i.type===`table`&&i.tableInfo){let a=[...i.tableInfo.columns];if(r!==void 0&&a[r]){let n=a[r].columns||[];a[r]={...a[r],loop:!0,columns:[...n,{columnName:e.trim(),placeholder:t.trim(),enabled:!0}]}}else n?a.push({columnName:e.trim(),placeholder:t.trim(),enabled:!0,loop:!0,columns:[{columnName:`Item Name`,placeholder:`{{item.name}}`,enabled:!0},{columnName:`Price`,placeholder:`{{item.price}}`,enabled:!0}]}):a.push({columnName:e.trim(),placeholder:t.trim(),enabled:!0});return{...i,tableInfo:{...i.tableInfo,columns:a}}}return i}))},handleUpdateTableColumn:(e,t,n,r)=>{s&&o(i=>i.map(i=>{if(i.id===s&&i.type===`table`&&i.tableInfo){let a=[...i.tableInfo.columns];if(r!==void 0&&a[e]?.columns){let i=[...a[e].columns];i[r]={...i[r],columnName:t.trim(),placeholder:n.trim()},a[e]={...a[e],columns:i}}else a[e]&&(a[e]={...a[e],columnName:t.trim(),placeholder:n.trim()});return{...i,tableInfo:{...i.tableInfo,columns:a}}}return i}))},handleReorderTableColumn:(e,t,n)=>{s&&o(r=>r.map(r=>{if(r.id===s&&r.type===`table`&&r.tableInfo){let i=[...r.tableInfo.columns];if(n!==void 0&&i[e]?.columns){let r=[...i[e].columns],a=t===`up`?n-1:n+1;if(a>=0&&a<r.length){let t=r[n];r[n]=r[a],r[a]=t,i[e]={...i[e],columns:r}}}else{let n=t===`up`?e-1:e+1;if(n>=0&&n<i.length){let t=i[e];i[e]=i[n],i[n]=t}}return{...r,tableInfo:{...r.tableInfo,columns:i}}}return r}))},handleAddTableRow:e=>{let t=e||s;t&&o(e=>e.map(e=>{if(e.id===t&&e.type===`table`&&e.tableInfo){let t=e.tableInfo.columns||[],n=e.tableInfo.mockRows&&e.tableInfo.mockRows.length>0?e.tableInfo.mockRows:[{}],r={};return t.forEach(e=>{e.columnName&&(r[e.columnName]=e.placeholder||``)}),{...e,tableInfo:{...e.tableInfo,mockRows:[...n,r]}}}return e}))},handleRemoveTableRow:(e,t)=>{let n=t||s;n&&o(t=>t.map(t=>{if(t.id===n&&t.type===`table`&&t.tableInfo){let n=t.tableInfo.mockRows&&t.tableInfo.mockRows.length>0?t.tableInfo.mockRows:[{}];if(n.length<=1)return{...t,tableInfo:{...t.tableInfo,mockRows:[{}]}};let r=n.filter((t,n)=>n!==e);return{...t,tableInfo:{...t.tableInfo,mockRows:r}}}return t}))}}}function Ca(){let[e,t]=(0,l.useState)(1),[n,r]=(0,l.useState)({x:0,y:0}),[i,a]=(0,l.useState)(!1),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(1123),d=(0,l.useRef)({x:0,y:0}),f=(0,l.useRef)(null),p=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{let t=document.activeElement,n=t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.getAttribute(`contenteditable`)===`true`);e.code===`Space`&&!n&&(s(!0),e.preventDefault())},t=e=>{e.code===`Space`&&s(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]),(0,l.useEffect)(()=>{if(!p.current)return;let e=new ResizeObserver(e=>{for(let t of e)u(t.target.scrollHeight)});return e.observe(p.current),()=>e.disconnect()},[]),{zoom:e,setZoom:t,panOffset:n,setPanOffset:r,isPanning:i,setIsPanning:a,spacePressed:o,setSpacePressed:s,canvasHeight:c,setCanvasHeight:u,viewportRef:f,canvasContainerRef:p,handleMouseDown:e=>{o&&(a(!0),d.current={x:e.clientX-n.x,y:e.clientY-n.y})},handleMouseMove:e=>{i&&o&&r({x:e.clientX-d.current.x,y:e.clientY-d.current.y})},handleMouseUp:()=>{a(!1)},handleZoomIn:()=>t(e=>Math.min(e+.1,2)),handleZoomOut:()=>t(e=>Math.max(e-.1,.5)),handleZoomReset:()=>{t(1),r({x:0,y:0})}}}function wa({tableSchemas:e}={}){let[t,n]=(0,l.useState)(`invoice_items`),[r,i]=(0,l.useState)(`{% for item in invoice.items %}`),[a,o]=(0,l.useState)(`{% endfor %}`),[s,c]=(0,l.useState)(``),[u,d]=(0,l.useState)(``),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)([]),[g,_]=(0,l.useState)(!1),[v,y]=(0,l.useState)(``),[b,x]=(0,l.useState)(null),[S,C]=(0,l.useState)(``),[w,T]=(0,l.useState)(null),[E,D]=(0,l.useState)(null),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),ee=e=>({columnName:e.columnName||e.columnNameEn||e.columnNameDe||``,placeholder:e.placeholder||``,enabled:e.enabled!==!1,loop:!!e.loop,columns:Array.isArray(e.columns)?e.columns.map(ee):void 0});(0,l.useEffect)(()=>{e&&e.length>0?h(e.map(e=>({...e,columns:e.columns.map(ee)}))):h([])},[e]);let M=()=>{if(!t.trim())return;let e={tableName:t.trim().replace(/\s+/g,`_`).toLowerCase(),columns:[{columnName:`Description`,placeholder:`{{description}}`,enabled:!0},{columnName:`Qty`,placeholder:`{{quantity}}`,enabled:!0},{columnName:`Total Price`,placeholder:`{{total_price}}`,enabled:!0}],loop:!0,isNestable:!1,parentPath:`items`,maxNestingDepth:5,nestingPrefix:` `,showNestingLevel:!1,loopStartTag:r,loopEndTag:a};h(t=>[...t,e]),n(``)},N=()=>{if(!O.trim())return;let e=O.trim().toLowerCase().replace(/\s+/g,`_`);if(A.some(t=>t.imageType===e)){k(``);return}j(t=>[...t,{label:O.trim(),imageType:e,description:`Placeholder container for ${O.trim()}`}]),k(``)},te=(e,t,n)=>{h(r=>r.map((r,i)=>{if(i===e){let e=[...r.columns];if(n!==void 0&&e[t]?.columns){let r=[...e[t].columns];r[n]={...r[n],enabled:r[n].enabled===!1},e[t]={...e[t],columns:r}}else e[t]={...e[t],enabled:e[t].enabled===!1};return{...r,columns:e}}return r}))},[ne,P]=(0,l.useState)(null);return{customTableName:t,setCustomTableName:n,customLoopStart:r,setCustomLoopStart:i,customLoopEnd:a,setCustomLoopEnd:o,newColName:s,setNewColName:c,newColPlaceholder:u,setNewColPlaceholder:d,bubbleCoords:f,setBubbleCoords:p,schemas:m,setSchemas:h,isParsing:g,setIsParsing:_,parseStatusText:v,setParseStatusText:y,parseError:b,setParseError:x,draggedSidebarItem:w,setDraggedSidebarItem:T,dragOverIndex:E,setDragOverIndex:D,newImgTypeName:O,setNewImgTypeName:k,customImageTypes:A,setCustomImageTypes:j,searchPlaceholder:S,setSearchPlaceholder:C,handleAddCustomTable:M,handleAddCustomImageType:N,toggleSchemaColumn:te,applySelectionFormat:(e,t=``)=>{if(ne){let e=window.getSelection();e?.removeAllRanges(),e?.addRange(ne)}document.execCommand(e,!1,t),p(null)},setSavedRange:P}}var Ta=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),Ea=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),Da=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),Oa=e=>{let t=Da(e);return t.charAt(0).toUpperCase()+t.slice(1)},ka={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},Aa=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},ja=(0,l.createContext)({}),Ma=()=>(0,l.useContext)(ja),Na=(0,l.forwardRef)(({color:e,size:t,strokeWidth:n,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>{let{size:u=24,strokeWidth:d=2,absoluteStrokeWidth:f=!1,color:p=`currentColor`,className:m=``}=Ma()??{},h=r??f?Number(n??d)*24/Number(t??u):n??d;return(0,l.createElement)(`svg`,{ref:c,...ka,width:t??u??ka.width,height:t??u??ka.height,stroke:e??p,strokeWidth:h,className:Ta(`lucide`,m,i),...!a&&!Aa(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>(0,l.createElement)(e,t)),...Array.isArray(a)?a:[a]])}),$=(e,t)=>{let n=(0,l.forwardRef)(({className:n,...r},i)=>(0,l.createElement)(Na,{ref:i,iconNode:t,className:Ta(`lucide-${Ea(Oa(e))}`,`lucide-${e}`,n),...r}));return n.displayName=Oa(e),n},Pa=$(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),Fa=$(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Ia=$(`barcode`,[[`path`,{d:`M3 5v14`,key:`1nt18q`}],[`path`,{d:`M8 5v14`,key:`1ybrkv`}],[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`M17 5v14`,key:`ycjyhj`}],[`path`,{d:`M21 5v14`,key:`nzette`}]]),La=$(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),Ra=$(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),za=$(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),Ba=$(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Va=$(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),Ha=$(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),Ua=$(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),Wa=$(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),Ga=$(`printer`,[[`path`,{d:`M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`143wyd`}],[`path`,{d:`M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6`,key:`1itne7`}],[`rect`,{x:`6`,y:`14`,width:`12`,height:`8`,rx:`1`,key:`1ue0tg`}]]),Ka=$(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),qa=$(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Ja=$(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Ya=$(`square-check-big`,[[`path`,{d:`M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344`,key:`2acyp4`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),Xa=$(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Za=$(`table`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}]]),Qa=$(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),$a=$(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),eo=$(`text-align-justify`,[[`path`,{d:`M3 5h18`,key:`1u36vt`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 19h18`,key:`awlh7x`}]]),to=$(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),no=$(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),ro=$(`type`,[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]),io=$(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),ao=$(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]);function oo({headerLogo:e,headerTitle:t,headerSubtitle:n,parseError:r,isParsing:i,parseStatusText:a,showImportHtml:o,showImportPdf:s,showPreview:c,showExport:d,showExportPdf:f=!0,customButtonStyles:p,customButtonClassNames:m,handleHtmlImport:h,handlePdfImport:g,setPreviewOpen:_,handleExport:v,handleExportPdf:y}){let b=(0,l.useRef)(null),x=(0,l.useRef)(null);return(0,u.jsxs)(`header`,{className:`bg-white border-b border-gray-200 px-6 py-4 flex flex-col sm:flex-row items-center justify-between sticky top-0 z-10 shadow-sm gap-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-3`,children:[e||(0,u.jsx)(`div`,{className:`h-10 w-10 bg-orange-600 rounded-xl flex items-center justify-center text-white shadow-md shadow-orange-600/20`,children:(0,u.jsx)(Ja,{className:`h-6 w-6`})}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h1`,{className:`text-xl font-bold tracking-tight text-slate-800`,children:t}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:n}),r&&(0,u.jsxs)(`span`,{className:`text-[10px] text-red-500 font-bold bg-red-50 px-2 py-0.5 rounded mt-1 inline-block border border-red-100`,children:[`Error: `,r]}),i&&(0,u.jsx)(`span`,{className:`text-[10px] text-orange-600 font-bold bg-orange-50 px-2 py-0.5 rounded mt-1 inline-block border border-orange-100 animate-pulse`,children:a||`Parsing...`})]})]}),(0,u.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(o||s)&&(0,u.jsxs)(`div`,{className:`flex space-x-2 border-r border-gray-200 pr-4`,children:[o&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`button`,{onClick:()=>b.current?.click(),style:p?.importHtml,className:m?.importHtml||`inline-flex items-center space-x-2 px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-semibold bg-white hover:bg-slate-50 text-slate-700 transition-colors shadow-sm`,title:`Import local HTML file`,children:[(0,u.jsx)(io,{className:`h-3.5 w-3.5 text-slate-500`}),(0,u.jsx)(`span`,{children:`Import HTML`})]}),(0,u.jsx)(`input`,{type:`file`,ref:b,onChange:h,accept:`.html`,className:`hidden`})]}),s&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`button`,{onClick:()=>x.current?.click(),style:p?.importPdf,className:m?.importPdf||`inline-flex items-center space-x-2 px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-semibold bg-white hover:bg-slate-50 text-slate-700 transition-colors shadow-sm`,title:`Import PDF layout structure`,children:[(0,u.jsx)(Va,{className:`h-3.5 w-3.5 text-slate-500`}),(0,u.jsx)(`span`,{children:`Import PDF`})]}),(0,u.jsx)(`input`,{type:`file`,ref:x,onChange:g,accept:`.pdf`,className:`hidden`})]})]}),c&&(0,u.jsxs)(`button`,{onClick:()=>_(!0),style:p?.preview,className:m?.preview||`inline-flex items-center space-x-2 px-4 py-2 border border-slate-200 rounded-lg text-sm font-semibold bg-slate-50 text-slate-700 hover:bg-slate-100 transition-colors shadow-sm`,children:[(0,u.jsx)(Ba,{className:`h-4 w-4 text-slate-500`}),(0,u.jsx)(`span`,{children:`Live Preview`})]}),f&&(0,u.jsxs)(`button`,{onClick:y,style:p?.exportPdf,className:m?.exportPdf||`inline-flex items-center space-x-2 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg text-sm font-semibold transition-colors shadow-sm shadow-indigo-600/10`,children:[(0,u.jsx)(Ga,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Download PDF`})]}),d&&(0,u.jsxs)(`button`,{onClick:v,style:p?.export,className:m?.export||`inline-flex items-center space-x-2 px-4 py-2 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-sm font-semibold transition-colors shadow-sm shadow-orange-600/10`,children:[(0,u.jsx)(za,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Export Template`})]})]})]})}function so({handleSidebarDragStart:e,createTextBlock:t,setBlocks:n,setSelectedBlockId:r,setActiveTab:i,defaultStyles:a}){return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Typography Elements`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Select standard headings or paragraphs to structure your page layout.`})]}),(0,u.jsx)(`div`,{className:`grid grid-cols-1 gap-3 select-none`,children:[{label:`Document Title`,type:`title`,style:`text-2xl font-extrabold text-slate-900 tracking-tight`},{label:`Document Subtitle`,type:`subtitle`,style:`text-sm font-bold text-slate-500`},{label:`Heading 1`,type:`h1`,style:`text-xl font-extrabold text-slate-850`},{label:`Heading 2`,type:`h2`,style:`text-lg font-bold text-slate-800`},{label:`Heading 3`,type:`h3`,style:`text-md font-semibold text-slate-750`},{label:`Normal Paragraph`,type:`p`,style:`text-xs text-slate-600 leading-relaxed`},{label:`Caption Note`,type:`caption`,style:`text-[10px] text-slate-400 font-mono italic`}].map(o=>(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>e(t,o.type),className:`border border-gray-200 rounded-xl p-3 bg-white hover:border-slate-350 transition-all flex flex-col space-y-2 cursor-grab shadow-xs group`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-400 uppercase tracking-wide`,children:o.type}),(0,u.jsx)(`div`,{className:`${o.style} truncate pr-4`,children:o.label}),(0,u.jsx)(`button`,{onClick:()=>{let e=t(o.type,o.label,a?.[o.type]);n(t=>[...t,e]),r(e.id),i(`styles`)},className:`w-full py-1 bg-slate-50 hover:bg-slate-200 text-slate-600 rounded-lg text-[9px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},o.type))})]})}function co({schemas:e,toggleSchemaColumn:t,customTableName:n,setCustomTableName:r,customLoopStart:i,setCustomLoopStart:a,customLoopEnd:o,setCustomLoopEnd:s,handleAddCustomTable:c,handleSidebarDragStart:l,setBlocks:d,setSelectedBlockId:f,setActiveTab:p,defaultStyles:m}){return(0,u.jsxs)(`div`,{className:`space-y-6`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Dynamic Tables`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Configure loop table templates and drag onto the canvas.`})]}),(0,u.jsx)(`div`,{className:`space-y-4`,children:e.map((e,n)=>(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-2xl p-4 bg-white space-y-3 shadow-xs`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(Za,{className:`h-4 w-4 text-slate-650`}),(0,u.jsx)(`h4`,{className:`font-bold text-xs uppercase text-slate-700 tracking-wider`,children:e.tableName})]}),(0,u.jsx)(`span`,{className:`px-1.5 py-0.5 bg-slate-100 text-[8px] font-bold text-slate-600 rounded`,children:`loop = true`})]}),(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>l(t,`table`,e),className:`bg-slate-50 border border-slate-200 hover:border-slate-400 rounded-lg p-2.5 flex items-center justify-between cursor-grab`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`div`,{className:`h-5 w-5 bg-slate-200 rounded flex items-center justify-center`,children:(0,u.jsx)(Wa,{className:`h-3 w-3 text-slate-600`})}),(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700`,children:`Drag to Canvas`})]}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 italic`,children:`Drag & Drop`})]}),(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 font-bold uppercase tracking-wider block`,children:`Columns:`}),(0,u.jsx)(`div`,{className:`max-h-[180px] overflow-y-auto border border-gray-150 rounded-lg p-2 space-y-1.5 bg-slate-50/50`,children:e.columns.map((e,r)=>{let i=e.loop&&e.columns&&e.columns.length>0;return(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`button`,{onClick:()=>t(n,r),className:`flex items-center space-x-2 w-full text-left py-0.5 text-xs text-slate-600 hover:text-slate-800 transition-colors font-medium`,children:[e.enabled===!1?(0,u.jsx)(Xa,{className:`h-3.5 w-3.5 text-slate-300 flex-shrink-0`}):(0,u.jsx)(Ya,{className:`h-3.5 w-3.5 text-slate-700 flex-shrink-0`}),(0,u.jsxs)(`span`,{className:`truncate flex items-center gap-1`,children:[(0,u.jsx)(`span`,{children:e.columnName}),i&&(0,u.jsx)(`span`,{className:`px-1 bg-slate-200 text-slate-600 rounded text-[8px] font-mono`,children:`(sub-table)`})]})]}),i&&e.enabled!==!1&&(0,u.jsxs)(`div`,{className:`ml-4 pl-2.5 border-l-2 border-slate-200 space-y-1 my-1`,children:[(0,u.jsx)(`span`,{className:`text-[8px] text-slate-400 font-bold uppercase tracking-wider block`,children:`Sub Columns:`}),e.columns.map((e,i)=>(0,u.jsxs)(`button`,{onClick:()=>t(n,r,i),className:`flex items-center space-x-2 w-full text-left py-0.5 text-[11px] text-slate-500 hover:text-slate-800 transition-colors`,children:[e.enabled===!1?(0,u.jsx)(Xa,{className:`h-3 w-3 text-slate-300 flex-shrink-0`}):(0,u.jsx)(Ya,{className:`h-3 w-3 text-slate-600 flex-shrink-0`}),(0,u.jsxs)(`span`,{className:`truncate`,children:[e.columnName,` `,(0,u.jsxs)(`span`,{className:`text-[8px] text-slate-400`,children:[`(`,e.placeholder,`)`]})]})]},i))]})]},r)})})]}),(0,u.jsx)(`button`,{onClick:()=>{let t={id:Math.random().toString(36).substring(2,11),type:`table`,content:``,style:{fontSize:`10px`,fontWeight:`400`,color:`#334155`,backgroundColor:`transparent`,textAlign:`left`,bold:!1,italic:!1,underline:!1,strikethrough:!1,width:`100%`,marginBottom:`12px`,padding:`8px`,...m?.table},tableInfo:{...e,columns:e.columns.map(e=>({...e}))}};d(e=>[...e,t]),f(t.id),p(`styles`)},className:`w-full py-1 bg-slate-50 hover:bg-slate-200 text-slate-600 rounded-lg text-[9px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},e.tableName))}),(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-2xl p-4 bg-slate-50/20 border-dashed space-y-4 mt-6`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-2 border-b border-gray-150`,children:[(0,u.jsx)(Ja,{className:`h-4 w-4 text-slate-655`}),(0,u.jsx)(`h4`,{className:`font-bold text-xs uppercase text-slate-800 tracking-wider`,children:`Custom Table Builder`})]}),(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Table Name`}),(0,u.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`invoice_items`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Loop Start tag`}),(0,u.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`{% for item in invoice.items %}`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 bg-white text-slate-600 font-bold`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block mb-1`,children:`Loop End tag`}),(0,u.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`{% endfor %}`,className:`w-full px-3 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 bg-white text-slate-600 font-bold`})]}),(0,u.jsxs)(`button`,{onClick:c,className:`w-full py-2 bg-orange-600 hover:bg-orange-700 text-white rounded-xl text-xs font-bold transition-all shadow-sm flex items-center justify-center space-x-1.5 shadow-orange-600/10`,children:[(0,u.jsx)(Wa,{className:`h-4 w-4`}),(0,u.jsx)(`span`,{children:`Add Custom Loop Table`})]})]})]})]})}function lo({customImageTypes:e,newImgTypeName:t,setNewImgTypeName:n,handleAddCustomImageType:r,handleSidebarDragStart:i,createImageBlock:a,setBlocks:o,setSelectedBlockId:s,setActiveTab:c}){let l=[{label:`Brand Logo`,imageType:`logo`,description:`Standard document vector logo`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},{label:`Campaign Banner`,imageType:`banner`,description:`Wide horizontal graphics banner`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},{label:`Dynamic Barcode`,imageType:`barcode`,description:`Barcode replaced dynamically`,icon:(0,u.jsx)(Ia,{className:`h-4 w-4 text-slate-550`})},{label:`Watermark`,imageType:`watermark`,description:`Background graphic with low opacity`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})},...e.map(e=>({label:e.label,imageType:e.imageType,description:e.description,icon:(0,u.jsx)(Ha,{className:`h-4 w-4 text-slate-550`})}))];return(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Image & Barcode Elements`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Drag elements onto the canvas, or insert below.`})]}),(0,u.jsx)(`div`,{className:`space-y-3`,children:l.map(e=>(0,u.jsxs)(`div`,{className:`border border-gray-200 rounded-xl p-3 bg-white space-y-3 shadow-xs`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[e.icon,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h4`,{className:`font-bold text-xs text-slate-700`,children:e.label}),(0,u.jsx)(`p`,{className:`text-[9px] text-slate-400`,children:e.description})]})]})}),(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>i(t,`image`,void 0,e.imageType),className:`bg-slate-50 border border-slate-200 hover:border-slate-450 rounded-lg p-2 flex items-center justify-between cursor-grab transition-all`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`div`,{className:`h-5 w-5 bg-slate-200 rounded flex items-center justify-center`,children:(0,u.jsx)(Wa,{className:`h-3 w-3 text-slate-750`})}),(0,u.jsx)(`span`,{className:`text-[11px] font-bold text-slate-700`,children:`Drag to Canvas`})]}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400 italic`,children:`Drag`})]}),(0,u.jsx)(`button`,{onClick:()=>{let t=a(e.imageType);o(e=>[...e,t]),s(t.id),c(`styles`)},className:`w-full py-1 bg-slate-100 hover:bg-slate-200 text-slate-600 rounded-lg text-[10px] font-semibold transition-all text-center border border-gray-150`,children:`Insert at End`})]},e.imageType))}),(0,u.jsxs)(`div`,{className:`border border-dashed border-gray-200 rounded-xl p-3 space-y-2 bg-slate-50/50 mt-4`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Add Custom Image Type`}),(0,u.jsx)(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. Signature`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs focus:outline-none focus:border-slate-500 bg-white`}),(0,u.jsxs)(`button`,{onClick:r,className:`w-full py-1.5 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Add Custom Category`})]})]})]})}function uo({placeholders:e,schemas:t,searchPlaceholder:n,setSearchPlaceholder:r,placeholderMockData:i,setPlaceholderMockData:a,selectedBlockId:o,setBlocks:s}){let c=()=>{let r=[];return(e||[]).forEach(e=>{r.push({label:e.label,placeholder:e.placeholder,category:`General`})}),t.forEach(e=>{let t=e.tableName===`package`?`Package Fields`:`Article Fields`;e.columns.forEach(n=>{r.push({label:`${e.tableName.toUpperCase()} - ${n.columnName}`,placeholder:n.placeholder,category:t})})}),r.filter(e=>e.label.toLowerCase().includes(n.toLowerCase())||e.placeholder.toLowerCase().includes(n.toLowerCase()))},l=e=>{if(o){let t=e.replace(/[{}]/g,``),n=` <span contenteditable="false" data-placeholder="${t}" class="inline-flex items-center px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 text-[9px] font-bold mx-0.5 select-none align-middle border border-slate-200 cursor-default relative pr-4 group/chip"><span>{{${t}}}</span><span class="absolute right-0.5 top-1/2 -translate-y-1/2 cursor-pointer text-slate-400 hover:text-red-655 px-0.5 font-bold hover:bg-slate-200/50 rounded text-[9px] leading-none select-none" onmousedown="event.stopPropagation(); event.preventDefault(); const p = this.closest('span[data-placeholder]'); const editable = p.closest('[contenteditable=\\'true\\']'); if(p){ p.remove(); } if(editable){ window.updateContentFromRawDelete('${o}', editable.innerHTML); }">×</span></span>&nbsp;`;s(e=>e.map(e=>e.id===o&&e.type!==`table`?{...e,content:e.content+n}:e))}},d=c();return(0,u.jsxs)(`div`,{className:`space-y-4 flex-1 flex flex-col min-h-0`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Variables Palette`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Click to copy, or drag into text areas. Edit mock values below to visualize content.`})]}),(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(Ka,{className:`absolute left-3 top-2.5 h-4 w-4 text-slate-400`}),(0,u.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`Search variables...`,className:`w-full pl-9 pr-4 py-2 border border-gray-200 rounded-xl text-xs focus:outline-none focus:border-slate-500 transition-colors`})]}),(0,u.jsx)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-1`,children:d.length===0?(0,u.jsx)(`div`,{className:`text-xs text-slate-400 italic text-center py-4`,children:`No variables available.`}):d.map((e,t)=>{let n=e.placeholder.replace(/[{}]/g,``);return(0,u.jsxs)(`div`,{className:`w-full border border-gray-200 p-2.5 rounded-xl bg-white shadow-xs space-y-2`,children:[(0,u.jsxs)(`div`,{draggable:!0,onDragStart:e=>{e.dataTransfer.setData(`placeholder`,n),e.dataTransfer.effectAllowed=`copy`},onClick:()=>l(e.placeholder),className:`flex items-center justify-between cursor-grab active:cursor-grabbing hover:bg-slate-50 p-1 rounded`,title:`Drag into text or cells, or click to copy`,children:[(0,u.jsx)(`span`,{className:`text-xs font-semibold text-slate-700 truncate mr-2`,children:e.label}),(0,u.jsx)(`code`,{className:`text-[9px] bg-slate-100 px-1.5 py-0.5 rounded text-slate-800 font-bold shrink-0 border border-slate-200/50`,children:e.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between gap-1 pt-1.5 border-t border-gray-100`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-400 uppercase`,children:`Mock:`}),(0,u.jsx)(`input`,{type:`text`,value:i[n]||``,onChange:e=>{a(t=>({...t,[n]:e.target.value}))},className:`flex-1 max-w-[130px] px-1.5 py-0.5 border border-gray-200 rounded text-[10px] focus:outline-none focus:border-slate-500 bg-white`})]})]},t)})})]})}function fo({selectedBlockId:e,getSelectedBlock:t,updateSelectedStyle:n,updateSelectedImageInfo:r,fontSizesState:i,fontFamiliesState:a,fontWeightsState:o,handleDeleteBlock:s,newColName:c,setNewColName:d,newColPlaceholder:f,setNewColPlaceholder:p,handleAddTableColumn:m,handleRemoveTableColumn:h,handleUpdateTableColumn:g,handleReorderTableColumn:_,handleAddTableRow:v,handleRemoveTableRow:y,setBlocks:b}){let[x,S]=(0,l.useState)(null),[C,w]=(0,l.useState)(``),[T,E]=(0,l.useState)(``),[D,O]=(0,l.useState)(null),[k,A]=(0,l.useState)(``),[j,ee]=(0,l.useState)(``),M=t();if(!e||!M)return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`border border-dashed border-gray-200 rounded-xl p-6 text-center bg-slate-50/50`,children:[(0,u.jsx)(qa,{className:`h-8 w-8 text-slate-350 mx-auto mb-2`}),(0,u.jsx)(`span`,{className:`text-xs font-semibold text-slate-500 block`,children:`No block selected`}),(0,u.jsx)(`p`,{className:`text-[10px] text-slate-400 mt-1`,children:`Select any element inside the canvas to configure typography, sizing, colors, or templating loop engines.`})]})]});let N=M.type===`table`,te=()=>{c.trim()&&(m(c,f),d(``),p(``))};if(M.type===`image`){let e=M.imageInfo||{imageType:`logo`};return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-3 border-b border-gray-100`,children:[(0,u.jsx)(`div`,{className:`h-6 w-6 bg-slate-100 rounded flex items-center justify-center text-slate-700`,children:(0,u.jsx)(Ha,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 capitalize`,children:`Editing Image Element`})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Alignment`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Display side-by-side`})]}),(0,u.jsx)(`button`,{onClick:()=>{let e=!M.style.sameRow;n(`sameRow`,e),e?(n(`width`,`48%`),b(e=>{let t=e.findIndex(e=>e.id===M.id);return t>0?e.map((e,n)=>n===t-1&&(!e.style.width||e.style.width===`100%`)?{...e,style:{...e.style,width:`48%`}}:e):e})):n(`width`,`100%`)},className:`w-10 h-6 flex items-center rounded-full p-1 transition-colors duration-150 ${M.style.sameRow?`bg-orange-600 justify-end`:`bg-slate-300 justify-start`}`,children:(0,u.jsx)(`span`,{className:`bg-white w-4 h-4 rounded-full shadow-md`})})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Image Category`}),(0,u.jsx)(`div`,{className:`grid grid-cols-4 gap-1 bg-slate-50 p-1 border border-gray-200 rounded-lg`,children:[`logo`,`banner`,`barcode`,`watermark`].map(t=>(0,u.jsx)(`button`,{onClick:()=>r(`imageType`,t),className:`py-1 text-[9px] font-bold rounded capitalize transition-all ${e.imageType===t?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:t},t))})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Alignment (Position)`}),(0,u.jsx)(`div`,{className:`flex items-center space-x-1 border border-gray-200 rounded-lg p-1 bg-slate-50 w-fit`,children:[{value:`left`,icon:(0,u.jsx)(to,{className:`h-3.5 w-3.5`})},{value:`center`,icon:(0,u.jsx)(Qa,{className:`h-3.5 w-3.5`})},{value:`right`,icon:(0,u.jsx)($a,{className:`h-3.5 w-3.5`})}].map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`textAlign`,e.value),type:`button`,className:`p-1.5 rounded transition-all ${M.style.textAlign===e.value?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e.icon},e.value))})]}),(0,u.jsxs)(`div`,{className:`space-y-1 pt-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Image Width`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:M.style.width||`100%`})]}),(0,u.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,u.jsx)(`input`,{type:`range`,min:`10`,max:`1000`,step:`5`,value:parseInt(M.style.width||`100`),onChange:e=>n(`width`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`}),(0,u.jsxs)(`span`,{className:`text-[10px] font-mono text-slate-500 w-10 text-right`,children:[parseInt(M.style.width||`100`),`px`]})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1 pt-1 mt-3`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1`,children:`Object Fit`}),(0,u.jsxs)(`select`,{value:M.style.objectFit||`contain`,onChange:e=>n(`objectFit`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:[(0,u.jsx)(`option`,{value:`contain`,children:`Contain`}),(0,u.jsx)(`option`,{value:`cover`,children:`Cover`}),(0,u.jsx)(`option`,{value:`fill`,children:`Fill`}),(0,u.jsx)(`option`,{value:`none`,children:`None`})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Image Height`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:M.style.height||M.style.minHeight||`auto`})]}),(0,u.jsx)(`div`,{className:`flex items-center space-x-2`,children:(0,u.jsx)(`input`,{type:`range`,min:`20`,max:`400`,step:`10`,value:parseInt(M.style.height||M.style.minHeight||`100`)||100,onChange:e=>{n(`height`,`${e.target.value}px`),n(`minHeight`,`${e.target.value}px`)},className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`})})]}),e.imageType===`barcode`?(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-150`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Barcode Configuration`}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500`,children:`Mock Barcode Value`}),(0,u.jsx)(`input`,{type:`text`,value:e.barcodeValue||``,onChange:e=>r(`barcodeValue`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-500`,children:`Backend Variable`}),(0,u.jsx)(`input`,{type:`text`,value:e.barcodePlaceholder||``,onChange:e=>r(`barcodePlaceholder`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs font-mono focus:outline-none focus:border-slate-500 text-slate-700 font-bold`})]})]}):(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-150`,children:[(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Image Asset Upload`}),(0,u.jsxs)(`div`,{className:`flex flex-col items-center p-3 border border-dashed border-gray-200 rounded-lg bg-slate-50/50 hover:bg-slate-50 transition-all cursor-pointer relative`,children:[(0,u.jsx)(io,{className:`h-5 w-5 text-slate-400 mb-1`}),(0,u.jsx)(`span`,{className:`text-[10px] font-bold text-slate-650`,children:`Choose local image file`}),(0,u.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=e=>{let t=e.target?.result;r(`url`,t)},n.readAsDataURL(t)},className:`absolute inset-0 opacity-0 cursor-pointer`})]})]}),(0,u.jsx)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Bottom Margin`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(M.style.marginBottom||`0px`),onChange:e=>n(`marginBottom`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Padding`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(M.style.padding||`0px`),onChange:e=>n(`padding`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200`})]})]})}),(0,u.jsx)(`div`,{className:`pt-4 border-t border-red-100 flex items-center justify-between`,children:(0,u.jsxs)(`button`,{onClick:()=>s(M.id),className:`w-full py-2 bg-red-50 hover:bg-red-100 border border-red-200 text-red-650 rounded-xl text-xs font-bold transition-all flex items-center justify-center space-x-1 shadow-xs cursor-pointer`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Delete Element`})]})})]})]})}return(0,u.jsxs)(`div`,{className:`space-y-5`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`h3`,{className:`text-sm font-bold text-slate-800`,children:`Formatting Panel`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Customize the styles of the selected block.`})]}),(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-2 pb-3 border-b border-gray-100`,children:[(0,u.jsx)(`div`,{className:`h-6 w-6 bg-slate-100 rounded flex items-center justify-center text-slate-700 font-bold text-[10px] uppercase`,children:M.type}),(0,u.jsxs)(`span`,{className:`text-xs font-bold text-slate-700 capitalize`,children:[`Editing `,M.type===`table`?`Table Block`:`Typography Element`]})]}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Alignment`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Display side-by-side`})]}),(0,u.jsx)(`button`,{onClick:()=>{let e=!M.style.sameRow;n(`sameRow`,e),e?(n(`width`,`48%`),b(e=>{let t=e.findIndex(e=>e.id===M.id);return t>0?e.map((e,n)=>n===t-1&&(!e.style.width||e.style.width===`100%`)?{...e,style:{...e.style,width:`48%`}}:e):e})):n(`width`,`100%`)},className:`w-10 h-6 flex items-center rounded-full p-1 transition-colors duration-150 ${M.style.sameRow?`bg-orange-600 justify-end`:`bg-slate-300 justify-start`}`,children:(0,u.jsx)(`span`,{className:`bg-white w-4 h-4 rounded-full shadow-md`})})]}),M.style.sameRow&&(0,u.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-slate-50 border border-gray-200 rounded-xl select-none`,children:[(0,u.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-bold text-slate-700 block`,children:`Row Direction`}),(0,u.jsx)(`span`,{className:`text-[9px] text-slate-400`,children:`Layout stacked or side-by-side`})]}),(0,u.jsx)(`div`,{className:`grid grid-cols-2 gap-1 bg-slate-100 p-0.5 border border-gray-200 rounded-lg w-[180px]`,children:[`row`,`column`].map(e=>(0,u.jsx)(`button`,{type:`button`,onClick:()=>{n(`flexDirection`,e),b(t=>{let n=t.findIndex(e=>e.id===M.id);if(n===-1)return t;let r=n;for(;r>0&&t[r].style.sameRow;)r--;let i=[r],a=r+1;for(;a<t.length&&t[a].style.sameRow;)i.push(a),a++;return t.map((t,n)=>i.includes(n)?{...t,style:{...t.style,flexDirection:e}}:t)})},className:`px-2 py-1 text-[9px] font-bold rounded capitalize transition-all text-center ${M.style.flexDirection===e||e===`row`&&!M.style.flexDirection?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e===`row`?`Side-by-side`:`Stacked`},e))})]}),(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Font Size`}),(0,u.jsx)(`select`,{value:M.style.fontSize,onChange:e=>n(`fontSize`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:i.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),!N&&(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Weight`}),(0,u.jsx)(`select`,{value:M.style.fontWeight,onChange:e=>n(`fontWeight`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:o.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),!N&&(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Font Family`}),(0,u.jsxs)(`select`,{value:M.style.fontFamily||``,onChange:e=>n(`fontFamily`,e.target.value),className:`w-full px-2 py-1.5 border border-gray-200 rounded-lg text-xs focus:outline-none focus:border-slate-500 bg-white font-medium`,children:[(0,u.jsx)(`option`,{value:``,children:`Default Font (Global)`}),a.map(e=>(0,u.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),!N&&(0,u.jsxs)(`div`,{className:`space-y-2`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Alignment & Formatting`}),(0,u.jsxs)(`div`,{className:`flex items-center justify-between gap-1 border border-gray-200 rounded-lg p-1 bg-slate-50`,children:[(0,u.jsx)(`div`,{className:`flex items-center space-x-0.5`,children:[{value:`left`,icon:(0,u.jsx)(to,{className:`h-3.5 w-3.5`})},{value:`center`,icon:(0,u.jsx)(Qa,{className:`h-3.5 w-3.5`})},{value:`right`,icon:(0,u.jsx)($a,{className:`h-3.5 w-3.5`})},{value:`justify`,icon:(0,u.jsx)(eo,{className:`h-3.5 w-3.5`})}].map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`textAlign`,e.value),className:`p-1.5 rounded transition-all ${M.style.textAlign===e.value?`bg-white text-slate-800 shadow-xs border border-gray-200`:`text-slate-500 hover:text-slate-800`}`,children:e.icon},e.value))}),(0,u.jsx)(`div`,{className:`h-5 w-[1px] bg-slate-200 mx-1`}),(0,u.jsx)(`div`,{className:`flex items-center space-x-0.5`,children:[{key:`bold`,label:`B`,className:`font-bold`},{key:`italic`,label:`I`,className:`italic`},{key:`underline`,label:`U`,className:`underline`},{key:`strikethrough`,label:`S`,className:`line-through`}].map(e=>{let t=M.style[e.key]===!0;return(0,u.jsx)(`button`,{onClick:()=>n(e.key,!t),className:`h-7 w-7 rounded text-xs transition-all ${t?`bg-white text-slate-800 shadow-xs border border-gray-200 font-bold`:`text-slate-500 hover:text-slate-800`}`,children:(0,u.jsx)(`span`,{className:e.className,children:e.label})},e.key)})})]})]}),(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Text Color`}),(0,u.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ma.map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`color`,e),className:`h-5 w-5 rounded-full border border-gray-200 shadow-xs transition-transform ${M.style.color===e?`scale-120 ring-2 ring-slate-800`:`hover:scale-110`}`,style:{backgroundColor:e}},e)),(0,u.jsx)(`input`,{type:`color`,value:M.style.color,onChange:e=>n(`color`,e.target.value),className:`h-5 w-5 rounded-full border border-gray-200 cursor-pointer overflow-hidden p-0`})]})]}),(0,u.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Background Color`}),(0,u.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ha.map(e=>(0,u.jsx)(`button`,{onClick:()=>n(`backgroundColor`,e),className:`h-5 w-5 rounded-full border border-gray-200 shadow-xs transition-transform ${M.style.backgroundColor===e?`scale-120 ring-2 ring-slate-800`:`hover:scale-110`}`,style:{backgroundColor:e===`transparent`?`#ffffff`:e},children:e===`transparent`&&(0,u.jsx)(`span`,{className:`text-[8px] text-slate-400 font-bold block leading-5 text-center`,children:`T`})},e)),(0,u.jsx)(`input`,{type:`color`,value:M.style.backgroundColor===`transparent`?`#ffffff`:M.style.backgroundColor,onChange:e=>n(`backgroundColor`,e.target.value),className:`h-5 w-5 rounded-full border border-gray-200 cursor-pointer overflow-hidden p-0`})]})]})]}),(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider`,children:`Block Width`}),(0,u.jsx)(`span`,{className:`text-[10px] font-mono text-slate-500 font-bold bg-slate-100 px-1.5 py-0.5 rounded`,children:M.style.width||`100%`})]}),(0,u.jsx)(`div`,{className:`flex items-center space-x-2`,children:(0,u.jsx)(`input`,{type:`range`,min:`10`,max:`100`,step:`5`,value:parseInt(M.style.width||`100%`),onChange:e=>n(`width`,`${e.target.value}%`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`})})]}),(0,u.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Bottom Margin`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(M.style.marginBottom||`0px`),onChange:e=>n(`marginBottom`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg`})]}),(0,u.jsxs)(`div`,{className:`space-y-1`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase block`,children:`Padding`}),(0,u.jsx)(`input`,{type:`range`,min:`0`,max:`40`,step:`2`,value:parseInt(M.style.padding||`0px`),onChange:e=>n(`padding`,`${e.target.value}px`),className:`w-full accent-slate-800 h-1 bg-gray-200 rounded-lg`})]})]})]}),N&&M.tableInfo&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Table Rows`}),(0,u.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-medium`,children:[M.tableInfo.mockRows?.length||1,` row(s) configured`]})]}),(0,u.jsxs)(`button`,{type:`button`,onClick:()=>v&&v(M.id),className:`px-3 py-1.5 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-xs font-bold transition-all flex items-center space-x-1 shadow-xs`,title:`Add a new row to table`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Add Row`})]})]}),(0,u.jsx)(`div`,{className:`space-y-1.5 max-h-[140px] overflow-y-auto pr-1`,children:(M.tableInfo.mockRows&&M.tableInfo.mockRows.length>0?M.tableInfo.mockRows:[{}]).map((e,t)=>(0,u.jsxs)(`div`,{className:`flex items-center justify-between bg-slate-50 border border-gray-200 rounded-lg p-2 text-xs`,children:[(0,u.jsxs)(`span`,{className:`font-semibold text-slate-700`,children:[`Row #`,t+1]}),(0,u.jsx)(`button`,{type:`button`,onClick:()=>y&&y(t,M.id),disabled:(M.tableInfo?.mockRows?.length||1)<=1,className:`p-1 text-slate-400 hover:text-red-600 hover:bg-red-50 disabled:opacity-30 disabled:hover:bg-transparent rounded transition-colors`,title:`Remove row`,children:(0,u.jsx)(no,{className:`h-3.5 w-3.5`})})]},t))})]}),(0,u.jsxs)(`div`,{className:`space-y-3 pt-3 border-t border-gray-100`,children:[(0,u.jsx)(`label`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-wider block`,children:`Table Columns`}),(0,u.jsx)(`div`,{className:`space-y-2 max-h-[300px] overflow-y-auto pr-1`,children:M.tableInfo.columns.map((e,t)=>{let n=e.loop&&e.columns&&e.columns.length>0;return(0,u.jsxs)(`div`,{className:`bg-slate-50 border border-gray-200 rounded-lg p-2 space-y-1.5 text-xs`,children:[x===String(t)?(0,u.jsxs)(`div`,{className:`space-y-1.5 p-1 bg-white border border-orange-300 rounded`,children:[(0,u.jsx)(`div`,{className:`text-[9px] font-bold text-orange-600 uppercase`,children:`Edit Column`}),(0,u.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-xs bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`Value (e.g. {{item.sku}})`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-xs font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,u.jsxs)(`button`,{onClick:()=>{g&&g(t,C,T),S(null)},className:`p-1 px-2 bg-orange-600 text-white hover:bg-orange-700 rounded text-[10px] flex items-center gap-1 font-bold`,children:[(0,u.jsx)(La,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Save`})]}),(0,u.jsxs)(`button`,{onClick:()=>S(null),className:`p-1 px-2 bg-gray-200 text-slate-700 hover:bg-gray-300 rounded text-[10px] flex items-center gap-1`,children:[(0,u.jsx)(ao,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Cancel`})]})]})]}):(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`truncate mr-2`,children:[(0,u.jsxs)(`span`,{className:`font-bold text-slate-700 block truncate flex items-center gap-1`,children:[(0,u.jsx)(`span`,{children:e.columnName}),n&&(0,u.jsx)(`span`,{className:`px-1 bg-blue-100 text-blue-700 rounded text-[8px] font-mono`,children:`loop (sub-table)`})]}),(0,u.jsx)(`code`,{className:`text-[9px] font-mono text-slate-500 truncate block`,children:e.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`up`),disabled:t===0,className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 disabled:opacity-30 disabled:hover:bg-transparent rounded transition-colors`,title:`Move Up`,children:(0,u.jsx)(Fa,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`down`),disabled:t===(M.tableInfo?.columns.length||0)-1,className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 disabled:opacity-30 disabled:hover:bg-transparent rounded transition-colors`,title:`Move Down`,children:(0,u.jsx)(Pa,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>{S(String(t)),w(e.columnName),E(e.placeholder)},className:`p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-200 rounded transition-colors`,title:`Edit column`,children:(0,u.jsx)(Ua,{className:`h-3.5 w-3.5`})}),(0,u.jsx)(`button`,{onClick:()=>h(t),className:`p-1 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded transition-colors border border-transparent`,disabled:!M.tableInfo||M.tableInfo.columns.length<=1,title:`Delete column`,children:(0,u.jsx)(no,{className:`h-3.5 w-3.5`})})]})]}),n&&(0,u.jsxs)(`div`,{className:`ml-2 pl-2 border-l-2 border-blue-200 space-y-1.5 pt-1 mt-1`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,u.jsxs)(`span`,{className:`text-[8px] font-bold text-blue-600 uppercase tracking-wider block`,children:[`Sub-Table Columns (`,e.columns?.length||0,`):`]})}),e.columns.map((n,r)=>{let i=`${t}-${r}`;return x===i?(0,u.jsxs)(`div`,{className:`space-y-1 p-1.5 bg-white border border-blue-300 rounded`,children:[(0,u.jsx)(`div`,{className:`text-[8px] font-bold text-blue-600 uppercase`,children:`Edit Sub-Column`}),(0,u.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-[11px] bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`Value`,className:`w-full px-2 py-0.5 border border-gray-200 rounded text-[11px] font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex justify-end gap-1 pt-0.5`,children:[(0,u.jsxs)(`button`,{onClick:()=>{g&&g(t,C,T,r),S(null)},className:`p-0.5 px-1.5 bg-blue-600 text-white hover:bg-blue-700 rounded text-[9px] flex items-center gap-1 font-bold`,children:[(0,u.jsx)(La,{className:`h-2.5 w-2.5`}),(0,u.jsx)(`span`,{children:`Save`})]}),(0,u.jsxs)(`button`,{onClick:()=>S(null),className:`p-0.5 px-1.5 bg-gray-200 text-slate-700 hover:bg-gray-300 rounded text-[9px] flex items-center gap-1`,children:[(0,u.jsx)(ao,{className:`h-2.5 w-2.5`}),(0,u.jsx)(`span`,{children:`Cancel`})]})]})]},r):(0,u.jsxs)(`div`,{className:`flex items-center justify-between bg-white border border-gray-150 rounded px-2 py-1 text-[11px]`,children:[(0,u.jsxs)(`div`,{className:`truncate mr-1`,children:[(0,u.jsx)(`span`,{className:`font-semibold text-slate-700 block truncate`,children:n.columnName}),(0,u.jsx)(`code`,{className:`text-[8px] font-mono text-slate-400 truncate block`,children:n.placeholder})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`up`,r),disabled:r===0,className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 disabled:opacity-30 disabled:hover:bg-transparent rounded`,title:`Move Sub-Column Up`,children:(0,u.jsx)(Fa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>_&&_(t,`down`,r),disabled:r===e.columns.length-1,className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 disabled:opacity-30 disabled:hover:bg-transparent rounded`,title:`Move Sub-Column Down`,children:(0,u.jsx)(Pa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>{S(i),w(n.columnName),E(n.placeholder)},className:`p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded`,title:`Edit sub-column`,children:(0,u.jsx)(Ua,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>h(t,r),className:`p-0.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded`,title:`Delete sub-column`,children:(0,u.jsx)(no,{className:`h-3 w-3`})})]})]},r)}),D===t?(0,u.jsxs)(`div`,{className:`bg-white border border-blue-200 rounded p-2 space-y-1.5 mt-1`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-blue-600 block`,children:`Add Sub-Column`}),(0,u.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),placeholder:`Header Name (e.g. Price)`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs bg-white`}),(0,u.jsx)(`input`,{type:`text`,value:j,onChange:e=>ee(e.target.value),placeholder:`Value (e.g. {{item.price}})`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs font-mono bg-white`}),(0,u.jsxs)(`div`,{className:`flex gap-1 pt-1`,children:[(0,u.jsx)(`button`,{onClick:()=>{k.trim()&&(m(k,j||`{{item.value}}`,!1,t),A(``),ee(``),O(null))},className:`flex-1 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded text-[10px] font-bold`,children:`Add`}),(0,u.jsx)(`button`,{onClick:()=>{O(null),A(``),ee(``)},className:`py-1 px-2 bg-gray-100 hover:bg-gray-200 text-slate-600 rounded text-[10px]`,children:`Cancel`})]})]}):(0,u.jsxs)(`button`,{onClick:()=>O(t),className:`w-full py-1 text-[10px] font-bold text-blue-600 hover:bg-blue-50 border border-dashed border-blue-200 rounded flex items-center justify-center space-x-1 transition-colors mt-1`,children:[(0,u.jsx)(Wa,{className:`h-3 w-3`}),(0,u.jsx)(`span`,{children:`Add Sub-Column`})]})]})]},t)})}),(0,u.jsxs)(`div`,{className:`bg-slate-50 border border-gray-200 border-dashed rounded-xl p-3 space-y-3`,children:[(0,u.jsx)(`span`,{className:`text-[9px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Add New Column`}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`input`,{type:`text`,value:c,onChange:e=>d(e.target.value),placeholder:`Header Name`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs focus:outline-none focus:border-slate-500 bg-white`})}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Value (e.g. {{item.sku}})`,className:`w-full px-2 py-1 border border-gray-200 rounded text-xs font-mono focus:outline-none focus:border-orange-655 bg-white`})}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsxs)(`button`,{onClick:te,className:`flex-1 py-1.5 bg-orange-600 hover:bg-orange-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Column`})]}),(0,u.jsxs)(`button`,{onClick:()=>{c.trim()&&(m(c,f||`{{item.price}}`,!0),d(``),p(``))},className:`flex-1 py-1.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-xs font-bold transition-all flex items-center justify-center space-x-1`,title:`Add column as nested sub-table`,children:[(0,u.jsx)(Wa,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Sub-Table`})]})]})]})]})]}),(0,u.jsx)(`div`,{className:`pt-4 border-t border-red-100 flex items-center justify-between`,children:(0,u.jsxs)(`button`,{onClick:()=>s(M.id),className:`w-full py-2 bg-red-50 hover:bg-red-100 border border-red-200 text-red-650 rounded-xl text-xs font-bold transition-all flex items-center justify-center space-x-1 shadow-xs cursor-pointer`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Delete Element`})]})})]})]})}function po({activeTab:e,setActiveTab:t,setBlocks:n,selectedBlockId:r,setSelectedBlockId:i,getSelectedBlock:a,defaultStyles:o,createTextBlock:s,createImageBlock:c,updateSelectedStyle:l,updateSelectedImageInfo:d,handleDeleteBlock:f,handleRemoveTableColumn:p,handleAddTableColumn:m,handleUpdateTableColumn:h,handleReorderTableColumn:g,handleAddTableRow:_,handleRemoveTableRow:v,schemas:y,toggleSchemaColumn:b,customTableName:x,setCustomTableName:S,customLoopStart:C,setCustomLoopStart:w,customLoopEnd:T,setCustomLoopEnd:E,handleAddCustomTable:D,newColName:O,setNewColName:k,newColPlaceholder:A,setNewColPlaceholder:j,customImageTypes:ee,newImgTypeName:M,setNewImgTypeName:N,handleAddCustomImageType:te,placeholders:ne,searchPlaceholder:P,setSearchPlaceholder:F,placeholderMockData:I,setPlaceholderMockData:re,handleSidebarDragStart:ie,fontSizesState:ae,fontFamiliesState:oe,fontWeightsState:L}){return(0,u.jsxs)(`aside`,{className:`w-full lg:w-[30%] flex flex-col bg-white border-t lg:border-t-0 lg:border-l border-gray-200 overflow-y-auto shrink-0`,children:[(0,u.jsx)(`div`,{className:`grid grid-cols-5 gap-1 border-b border-gray-250 p-2 bg-slate-50`,children:[{value:`text`,icon:(0,u.jsx)(ro,{className:`h-4 w-4`})},{value:`tables`,icon:(0,u.jsx)(Za,{className:`h-4 w-4`})},{value:`images`,icon:(0,u.jsx)(Ha,{className:`h-4 w-4`})},{value:`placeholders`,icon:(0,u.jsx)(Ja,{className:`h-4 w-4`})},{value:`styles`,icon:(0,u.jsx)(qa,{className:`h-4 w-4`})}].map(n=>(0,u.jsxs)(`button`,{onClick:()=>t(n.value),className:`py-2 px-0.5 flex flex-col items-center justify-center gap-1 font-bold text-[9px] rounded-lg uppercase tracking-wider transition-all duration-150 ${e===n.value?`bg-orange-600 text-white shadow-sm shadow-orange-600/10`:`text-slate-500 hover:text-orange-600 hover:bg-orange-50/50`}`,children:[n.icon,(0,u.jsx)(`span`,{children:n.value})]},n.value))}),(0,u.jsxs)(`div`,{className:`p-4 flex-1 flex flex-col min-h-0 overflow-y-auto`,children:[e===`text`&&(0,u.jsx)(so,{handleSidebarDragStart:ie,createTextBlock:s,setBlocks:n,setSelectedBlockId:i,setActiveTab:t,defaultStyles:o}),e===`tables`&&(0,u.jsx)(co,{schemas:y,toggleSchemaColumn:b,customTableName:x,setCustomTableName:S,customLoopStart:C,setCustomLoopStart:w,customLoopEnd:T,setCustomLoopEnd:E,handleAddCustomTable:D,handleSidebarDragStart:ie,setBlocks:n,setSelectedBlockId:i,setActiveTab:t,defaultStyles:o}),e===`images`&&(0,u.jsx)(lo,{customImageTypes:ee,newImgTypeName:M,setNewImgTypeName:N,handleAddCustomImageType:te,handleSidebarDragStart:ie,createImageBlock:c,setBlocks:n,setSelectedBlockId:i,setActiveTab:t}),e===`placeholders`&&(0,u.jsx)(uo,{placeholders:ne,schemas:y,searchPlaceholder:P,setSearchPlaceholder:F,placeholderMockData:I,setPlaceholderMockData:re,selectedBlockId:r,setBlocks:n}),e===`styles`&&(0,u.jsx)(fo,{selectedBlockId:r,getSelectedBlock:a,updateSelectedStyle:l,updateSelectedImageInfo:d,fontSizesState:ae,fontFamiliesState:oe,fontWeightsState:L,handleDeleteBlock:f,newColName:O,setNewColName:k,newColPlaceholder:A,setNewColPlaceholder:j,handleAddTableColumn:m,handleRemoveTableColumn:p,handleUpdateTableColumn:h,handleReorderTableColumn:g,handleAddTableRow:_,handleRemoveTableRow:v,setBlocks:n})]})]})}var mo=({block:e,onUpdate:t,onSelect:n,onDrop:r})=>{let i=(0,l.useRef)(null);(0,l.useEffect)(()=>{i.current&&i.current.innerHTML!==e.content&&document.activeElement!==i.current&&(i.current.innerHTML=e.content||`<br/>`)},[e.id,e.content]);let{bold:a,italic:o,underline:s,strikethrough:c,width:d,...f}=e.style,p={...f};a&&(p.fontWeight=`bold`),o&&(p.fontStyle=`italic`);let m=[];return s&&m.push(`underline`),c&&m.push(`line-through`),m.length>0&&(p.textDecoration=m.join(` `)),(0,u.jsx)(`div`,{ref:i,contentEditable:!0,suppressContentEditableWarning:!0,onFocus:n,onInput:e=>t(e.currentTarget.innerHTML),onBlur:e=>t(e.currentTarget.innerHTML),style:p,className:`h-fit w-full break-words outline-none`,onDrop:r,onDragOver:e=>e.preventDefault()})},ho=({blockId:e,colIdx:t,placeholder:n,onUpdate:r,onDrop:i})=>{let a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{a.current&&a.current.innerHTML!==n&&document.activeElement!==a.current&&(a.current.innerHTML=n)},[e,t,n]),(0,u.jsx)(`td`,{ref:a,contentEditable:!0,suppressContentEditableWarning:!0,onInput:e=>r(e.currentTarget.innerText||e.currentTarget.innerHTML),onBlur:e=>r(e.currentTarget.innerText||e.currentTarget.innerHTML),onDrop:i,onDragOver:e=>e.preventDefault(),className:`border border-slate-200 px-2.5 py-2.5 text-slate-500 bg-slate-50/20 font-sans outline-none focus:bg-slate-100/50 transition-colors`})},go=e=>{let t=[];return e.forEach(e=>{e.style.sameRow&&t.length>0?t[t.length-1].blocks.push(e):t.push({id:e.id,blocks:[e]})}),t};function _o({blocks:e,setBlocks:t,selectedBlockId:n,setSelectedBlockId:r,setActiveTab:i,showMockData:a,placeholderMockData:o,dragOverIndex:s,setDragOverIndex:c,draggedSidebarItem:l,defaultStyles:d,zoom:f,panOffset:p,spacePressed:m,canvasHeight:h,viewportRef:g,canvasContainerRef:_,handleMouseDown:v,handleMouseMove:y,handleMouseUp:b,createTextBlock:x,duplicateBlock:S,reorderBlock:C,handleDeleteBlock:w,handleSidebarDrop:T,handleTableCellDrop:E,updateTableCell:D,handleTextDrop:O}){let k=(e,t)=>{e.dataTransfer.setData(`blockIndex`,t.toString()),e.dataTransfer.setData(`source`,`canvas`),e.dataTransfer.effectAllowed=`move`},A=(n,r)=>{n.preventDefault(),n.stopPropagation();let i=n.dataTransfer.getData(`source`);if(i===`sidebar`)T(r);else if(i===`canvas`){let i=parseInt(n.dataTransfer.getData(`blockIndex`));if(isNaN(i)||i===r)return;let a=[...e],o=a.splice(i,1)[0],s=i<r?r-1:r;a.splice(s,0,o),t(a)}c(null)};return(0,u.jsx)(`div`,{ref:g,className:`flex-1 overflow-auto p-8 flex justify-center items-start outline-none transition-all ${m?`cursor-grab active:cursor-grabbing`:`cursor-default`}`,onMouseDown:v,onMouseMove:y,onMouseUp:b,onMouseLeave:b,children:(0,u.jsx)(`div`,{style:{transform:`translate(${p.x}px, ${p.y}px) scale(${f})`,transformOrigin:`top center`},className:`transition-transform duration-75 ease-out select-none`,children:(0,u.jsxs)(`div`,{ref:_,style:{height:`${h}px`},className:`w-[794px] min-h-[1123px] bg-white shadow-lg border border-gray-300/80 px-[60px] py-[60px] flex flex-col relative canvas-editor-area`,onDragOver:e=>e.preventDefault(),onDrop:n=>{if(n.preventDefault(),n.stopPropagation(),l)T(e.length);else{let e=n.dataTransfer.getData(`placeholder`);if(e){n.preventDefault();let a=x(`p`,`{{${e}}}`,d?.p);t(e=>[...e,a]),r(a.id),i(`styles`)}}},children:[e.length===0?(0,u.jsxs)(`div`,{className:`flex-1 border-2 border-dashed border-gray-200 rounded-2xl flex flex-col items-center justify-center p-8 text-center text-slate-400`,children:[(0,u.jsx)(qa,{className:`h-10 w-10 mb-3 animate-bounce text-slate-350`}),(0,u.jsx)(`span`,{className:`font-bold text-sm text-slate-600 block`,children:`Drag & Drop Editor Canvas`}),(0,u.jsx)(`p`,{className:`text-xs text-slate-400 mt-1 max-w-sm`,children:`Select elements from the sidebar tabs (Text, Tables, Images) and drag them here to assemble your template structure.`})]}):go(e).map(a=>{let o=a.blocks.length>1;return(0,u.jsx)(`div`,{className:`group/row ${a.blocks.some(e=>e.style.position===`absolute`)?``:`relative`} border border-transparent rounded-lg hover:border-slate-200/60 p-1 mb-2 ${o?a.blocks[0]?.style?.flexDirection===`column`?`flex flex-col gap-2`:`flex flex-row gap-4`:``}`,children:a.blocks.map(a=>{let s=n===a.id,l={...a.style,..._a(a.style.customCss||``)};return(0,u.jsxs)(`div`,{draggable:!0,onDragStart:t=>{let n=e.findIndex(e=>e.id===a.id);k(t,n)},onDragOver:t=>{t.preventDefault(),c(e.findIndex(e=>e.id===a.id))},onDrop:t=>{let n=e.findIndex(e=>e.id===a.id);A(t,n)},onClick:e=>{e.stopPropagation(),r(a.id),i(`styles`)},style:{width:o?a.style.width||`48%`:(a.style.position,`100%`),height:a.style.position===`absolute`?a.style.height||`100%`:void 0,position:a.style.position,top:a.style.top,left:a.style.left,zIndex:a.style.zIndex?parseInt(a.style.zIndex):void 0},className:`group/block relative p-0.5 rounded-xl border border-transparent transition-all duration-150 cursor-pointer ${s?`bg-orange-50/20 border-orange-500 shadow-sm ring-2 ring-orange-500/10`:`hover:bg-slate-50/30 hover:border-gray-200`} ${a.style.position===`absolute`?`!absolute !inset-0 !m-auto`:``}`,children:[s&&(0,u.jsxs)(`div`,{className:`absolute -top-3.5 right-3 bg-orange-600 text-white rounded-lg px-2 py-0.5 text-[10px] font-bold flex items-center space-x-1.5 shadow-md z-30 select-none`,children:[(0,u.jsx)(`button`,{onClick:()=>{C(e.findIndex(e=>e.id===a.id),`up`)},className:`hover:text-slate-350`,title:`Move Up`,children:(0,u.jsx)(Fa,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:()=>{C(e.findIndex(e=>e.id===a.id),`down`)},className:`hover:text-slate-350`,title:`Move Down`,children:(0,u.jsx)(Pa,{className:`h-3 w-3`})}),(0,u.jsx)(`div`,{className:`h-3 w-[1px] bg-slate-700`}),(0,u.jsx)(`button`,{onClick:e=>S(a.id,e),className:`hover:text-slate-350`,title:`Duplicate block`,children:(0,u.jsx)(Ra,{className:`h-3 w-3`})}),(0,u.jsx)(`button`,{onClick:e=>w(a.id,e),className:`hover:text-red-400 text-red-300`,title:`Delete block`,children:(0,u.jsx)(no,{className:`h-3 w-3`})})]}),a.type===`table`?(0,u.jsx)(`div`,{className:`overflow-x-auto w-full select-none`,children:(0,u.jsxs)(`table`,{style:l,className:`w-full border-collapse`,children:[(0,u.jsx)(`thead`,{children:(0,u.jsx)(`tr`,{children:a.tableInfo?.columns.filter(e=>e.enabled!==!1).map((e,t)=>(0,u.jsx)(`th`,{className:`border border-slate-200 px-2.5 py-1 text-slate-700 text-left bg-slate-50 font-sans`,children:e.columnName||``},t))})}),(0,u.jsx)(`tbody`,{children:(a.tableInfo?.mockRows&&a.tableInfo.mockRows.length>0?a.tableInfo.mockRows:[{}]).map((e,t)=>(0,u.jsx)(`tr`,{className:`bg-slate-50/10 border-b border-slate-100 hover:bg-slate-50/20`,children:a.tableInfo?.columns.filter(e=>e.enabled!==!1).map((t,n)=>{let r=e&&typeof e==`object`&&e[t.columnName]||t.placeholder;if(t.loop&&t.columns&&t.columns.length>0){let e=t.columns.filter(e=>e.enabled!==!1);return(0,u.jsx)(`td`,{className:`border border-slate-200 p-2 align-top bg-slate-50/20`,children:(0,u.jsxs)(`div`,{className:`w-full overflow-x-auto space-y-1`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] font-semibold text-slate-500`,children:[(0,u.jsxs)(`span`,{children:[`Sub-table: `,t.columnName]}),(0,u.jsx)(`span`,{className:`px-1.5 py-0.5 bg-slate-200 text-slate-600 rounded text-[8px]`,children:`loop = true`})]}),(0,u.jsxs)(`table`,{className:`w-full border-collapse border border-slate-200 rounded text-xs bg-white`,children:[(0,u.jsx)(`thead`,{children:(0,u.jsx)(`tr`,{children:e.map((e,t)=>(0,u.jsx)(`th`,{className:`border border-slate-200 px-2 py-1 text-slate-700 text-left bg-slate-100/80 font-sans font-semibold text-[10px]`,children:e.columnName},t))})}),(0,u.jsx)(`tbody`,{children:(0,u.jsx)(`tr`,{className:`bg-slate-50/30`,children:e.map((e,t)=>(0,u.jsx)(ho,{blockId:a.id,colIdx:t,placeholder:e.placeholder,onUpdate:e=>D(a.id,n,e,t),onDrop:e=>E(e,a.id,n,t)},t))})})]})]})},n)}return(0,u.jsx)(ho,{blockId:a.id,colIdx:n,placeholder:r,onUpdate:e=>D(a.id,n,e),onDrop:e=>E(e,a.id,n)},n)})},t))})]})}):a.type===`image`?(0,u.jsx)(`div`,{style:{textAlign:l.textAlign||`left`,width:`100%`,marginBottom:l.marginBottom,padding:l.padding,backgroundColor:l.backgroundColor},className:`w-full select-none`,children:(0,u.jsx)(`div`,{style:{width:o?`100%`:a.style.width||`100%`,display:`inline-block`},children:a.imageInfo?.imageType===`barcode`?(0,u.jsx)(`div`,{style:{width:`100%`,height:a.style.height||a.style.minHeight||`70px`},className:`border border-dashed border-slate-200 p-2 bg-slate-50/5 rounded-lg flex items-center justify-center overflow-hidden`,dangerouslySetInnerHTML:{__html:va(a.imageInfo.barcodeValue||`SHIP-99201`)}}):(0,u.jsx)(`img`,{src:a.imageInfo?.url||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`,style:{width:`100%`,height:`auto`,maxHeight:a.style.height||`300px`,objectFit:a.style.objectFit||`contain`,opacity:a.style.opacity||`1`,display:`block`},alt:`graphic content`})})}):(0,u.jsx)(mo,{block:a,onUpdate:e=>{t(t=>t.map(t=>t.id===a.id?{...t,content:e}:t))},onSelect:()=>r(a.id),onDrop:e=>O(e,a.id)})]},a.id)})},a.id)}),s!==null&&(0,u.jsx)(`div`,{className:`h-[2px] bg-orange-500 rounded my-1 shadow-md animate-pulse`})]})})})}function vo({showClearCanvas:e,handleClearCanvas:t,customButtonStyles:n,customButtonClassNames:r,zoom:i,setZoom:a,setPanOffset:o}){return(0,u.jsxs)(`div`,{className:`bg-white border-b border-gray-200 px-6 py-3 flex items-center justify-between shadow-xs sticky top-0 z-20`,children:[(0,u.jsx)(`div`,{className:`flex items-center space-x-4`,children:e&&(0,u.jsxs)(`button`,{onClick:t,style:n?.clearCanvas,className:r?.clearCanvas||`inline-flex items-center space-x-1 px-2.5 py-1 text-xs font-semibold border border-red-200 text-red-650 bg-red-50 hover:bg-red-100 rounded-lg transition-colors`,title:`Clear all canvas elements`,children:[(0,u.jsx)(no,{className:`h-3.5 w-3.5`}),(0,u.jsx)(`span`,{children:`Clear Canvas`})]})}),(0,u.jsxs)(`div`,{className:`flex items-center space-x-3 bg-slate-50 border border-gray-200 px-3 py-1 rounded-xl shadow-xs select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center space-x-1`,children:[(0,u.jsx)(`button`,{onClick:()=>a(e=>Math.max(e-.1,.5)),className:`h-6 w-6 rounded border border-gray-200 bg-white hover:bg-slate-50 flex items-center justify-center font-bold text-slate-650 hover:text-slate-900 transition-colors text-xs select-none`,title:`Zoom Out`,children:`−`}),(0,u.jsxs)(`div`,{className:`w-12 text-center text-xs font-bold text-slate-700`,children:[Math.round(i*100),`%`]}),(0,u.jsx)(`button`,{onClick:()=>a(e=>Math.min(e+.1,2)),className:`h-6 w-6 rounded border border-gray-200 bg-white hover:bg-slate-50 flex items-center justify-center font-bold text-slate-650 hover:text-slate-900 transition-colors text-xs select-none`,title:`Zoom In`,children:`+`})]}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-gray-200`}),(0,u.jsx)(`input`,{type:`range`,min:`0.5`,max:`2.0`,step:`0.05`,value:i,onChange:e=>a(parseFloat(e.target.value)),className:`w-20 accent-orange-600 h-1 bg-gray-200 rounded-lg appearance-none cursor-pointer`}),(0,u.jsx)(`button`,{onClick:()=>{a(1),o({x:0,y:0})},className:`text-[10px] font-bold text-slate-500 hover:text-slate-800 hover:underline`,children:`Reset`})]})]})}function yo({previewOpen:e,setPreviewOpen:t,generateExportHtml:n}){return e?(0,u.jsx)(`div`,{className:`fixed inset-0 bg-slate-950/65 backdrop-blur-xs flex items-center justify-center z-50 p-6`,children:(0,u.jsxs)(`div`,{className:`bg-white rounded-2xl w-full max-w-[900px] h-[90%] flex flex-col shadow-2xl overflow-hidden border border-gray-200`,children:[(0,u.jsxs)(`div`,{className:`bg-slate-50 border-b border-gray-200 px-6 py-4 flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`h3`,{className:`text-sm font-bold text-slate-800 flex items-center space-x-2`,children:[(0,u.jsx)(Ba,{className:`h-4 w-4 text-slate-655`}),(0,u.jsx)(`span`,{children:`HTML Document Render Output`})]}),(0,u.jsx)(`p`,{className:`text-[10px] text-slate-400 mt-0.5`,children:`Sandboxed iframe preview of final template markup`})]}),(0,u.jsx)(`button`,{onClick:()=>t(!1),className:`p-1.5 bg-slate-100 hover:bg-slate-200 text-slate-500 hover:text-slate-800 rounded-lg transition-colors`,children:(0,u.jsx)(ao,{className:`h-4 w-4`})})]}),(0,u.jsx)(`div`,{className:`flex-1 bg-slate-100 p-6 overflow-hidden`,children:(0,u.jsx)(`iframe`,{title:`HTML Preview Sandbox`,srcDoc:n(!0),className:`w-full h-full bg-white border border-gray-200 rounded-xl shadow-xs`,sandbox:`allow-same-origin`})}),(0,u.jsxs)(`details`,{className:`bg-slate-50 border-t border-gray-200`,children:[(0,u.jsxs)(`summary`,{className:`px-6 py-3 text-xs font-bold text-slate-600 cursor-pointer select-none hover:text-slate-800 flex items-center justify-between`,children:[(0,u.jsx)(`span`,{children:`View Raw Output Markup (HTML)`}),(0,u.jsx)(`span`,{className:`text-[10px] text-slate-400 font-medium font-sans`,children:`Click to expand`})]}),(0,u.jsx)(`div`,{className:`px-6 pb-6 overflow-x-auto max-h-[250px]`,children:(0,u.jsx)(`pre`,{className:`bg-slate-900 text-slate-200 p-4 rounded-lg text-[10px] font-mono whitespace-pre-wrap select-all`,children:n(!1)})})]})]})}):null}function bo({bubbleCoords:e,applySelectionFormat:t}){return e?(0,u.jsxs)(`div`,{className:`fixed bg-slate-900 border border-slate-800 text-white rounded-xl shadow-xl py-1 px-1.5 flex items-center space-x-1.5 z-50 select-none -translate-x-1/2`,style:{left:`${e.x}px`,top:`${e.y}px`},children:[(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`bold`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center font-bold text-xs text-slate-200 hover:text-white transition-colors`,title:`Bold Selection`,children:`B`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`italic`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center italic text-xs text-slate-200 hover:text-white transition-colors`,title:`Italic Selection`,children:`I`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`underline`)},className:`h-6 w-6 rounded hover:bg-slate-800 flex items-center justify-center underline text-xs text-slate-200 hover:text-white transition-colors`,title:`Underline Selection`,children:`U`}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800 mx-1`}),(0,u.jsxs)(`select`,{value:e.format||``,onChange:e=>{e.preventDefault(),e.target.value&&(t(`formatBlock`,e.target.value),e.target.value===`P`&&t(`fontSize`,`3`))},className:`bg-slate-800 text-white text-[10px] rounded px-1 py-0.5 outline-none cursor-pointer border border-slate-700`,children:[(0,u.jsx)(`option`,{value:``,disabled:!0,children:`Format...`}),(0,u.jsx)(`option`,{value:`H1`,children:`Heading 1`}),(0,u.jsx)(`option`,{value:`H2`,children:`Heading 2`}),(0,u.jsx)(`option`,{value:`H3`,children:`Heading 3`}),(0,u.jsx)(`option`,{value:`P`,children:`Paragraph`}),(0,u.jsx)(`option`,{value:`BLOCKQUOTE`,children:`Quote`})]}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800 mx-1`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#3b82f6`)},className:`h-4 w-4 rounded-full bg-blue-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Blue`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#ef4444`)},className:`h-4 w-4 rounded-full bg-red-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Red`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#1e293b`)},className:`h-4 w-4 rounded-full bg-slate-700 hover:scale-110 transition-transform cursor-pointer border border-slate-850`,title:`Color Slate`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`foreColor`,`#22c55e`)},className:`h-4 w-4 rounded-full bg-green-500 hover:scale-110 transition-transform cursor-pointer`,title:`Color Green`}),(0,u.jsx)(`div`,{className:`h-4 w-[1px] bg-slate-800`}),(0,u.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),t(`removeFormat`)},className:`hover:bg-slate-800 rounded text-[10px] px-1.5 h-6 flex items-center justify-center text-slate-400 hover:text-white font-semibold transition-colors`,title:`Clear Formatting`,children:`Clear`})]}):null}Dr.workerSrc=`https://cdn.jsdelivr.net/npm/pdfjs-dist@6.1.200/build/pdf.worker.min.mjs`;var xo=e=>{let t=[];return e.forEach(e=>{e.style.sameRow&&t.length>0?t[t.length-1].blocks.push(e):t.push({id:e.id,blocks:[e]})}),t},So=e=>e?e.replace(/contenteditable="[^"]*"/g,``).replace(/class="[^"]*"/g,``).replace(/data-placeholder="[^"]*"/g,``).replace(/&nbsp;/g,` `).trim():``;function Co({tableSchemas:e,placeholders:t,defaultLogo:n,defaultBanner:r,headerTitle:i=`HTML Template Builder`,headerSubtitle:a=`Design and export templates dynamically`,headerLogo:o,typographySizes:s,typographyWeights:c,typographyFonts:f,templatingLanguage:p=`csharp`,loopSyntax:m=`foreach`,onChange:h,onExport:g,onExportPdf:_,initialBlocks:v,defaultStyles:y,showImportHtml:b=!0,showImportPdf:x=!0,showClearCanvas:S=!0,showPreview:C=!0,showExport:w=!0,showExportPdf:T=!0,customButtonStyles:E,customButtonClassNames:D}={}){let{zoom:O,setZoom:k,panOffset:A,setPanOffset:j,spacePressed:ee,canvasHeight:M,viewportRef:N,canvasContainerRef:te,handleMouseDown:ne,handleMouseMove:P,handleMouseUp:F}=Ca(),{customTableName:I,setCustomTableName:re,customLoopStart:ie,setCustomLoopStart:ae,customLoopEnd:oe,setCustomLoopEnd:L,newColName:se,setNewColName:ce,newColPlaceholder:le,setNewColPlaceholder:ue,bubbleCoords:de,setBubbleCoords:fe,schemas:pe,isParsing:me,setIsParsing:he,parseStatusText:R,setParseStatusText:z,parseError:ge,setParseError:_e,draggedSidebarItem:B,setDraggedSidebarItem:ve,dragOverIndex:ye,setDragOverIndex:be,newImgTypeName:xe,setNewImgTypeName:Se,customImageTypes:Ce,searchPlaceholder:V,setSearchPlaceholder:we,handleAddCustomTable:Te,handleAddCustomImageType:Ee,toggleSchemaColumn:De,applySelectionFormat:Oe,setSavedRange:ke}=wa({tableSchemas:e}),{blocks:Ae,setBlocks:je,selectedBlockId:Me,setSelectedBlockId:Ne,getSelectedBlock:Pe,createTextBlock:Fe,createTableBlock:H,createImageBlock:U,handleDeleteBlock:Ie,handleDuplicateBlock:Le,handleMoveBlockUp:Re,handleMoveBlockDown:ze,updateSelectedStyle:W,updateSelectedImageInfo:Be,handleRemoveTableColumn:Ve,handleAddTableColumn:He,handleUpdateTableColumn:Ue,handleReorderTableColumn:We,handleAddTableRow:Ge,handleRemoveTableRow:Ke}=Sa({initialBlocks:v,defaultStyles:y,defaultLogo:n,defaultBanner:r,onChange:h}),[qe,Je]=(0,l.useState)(`text`),[Ye,Xe]=(0,l.useState)(!1),[Ze]=(0,l.useState)(!0),[Qe]=(0,l.useState)(s||[{label:`8px`,value:`8px`},{label:`9px`,value:`9px`},{label:`10px`,value:`10px`},{label:`11px`,value:`11px`},{label:`12px`,value:`12px`},{label:`14px`,value:`14px`},{label:`16px`,value:`16px`},{label:`18px`,value:`18px`},{label:`20px`,value:`20px`},{label:`24px`,value:`24px`},{label:`28px`,value:`28px`},{label:`32px`,value:`32px`},{label:`36px`,value:`36px`}]),[$e]=(0,l.useState)(f||[{label:`Outfit (Default)`,value:`'Outfit', 'Inter', sans-serif`},{label:`Inter`,value:`'Inter', sans-serif`},{label:`Roboto`,value:`'Roboto', sans-serif`},{label:`System Sans`,value:`system-ui, -apple-system, sans-serif`},{label:`Georgia (Serif)`,value:`Georgia, serif`},{label:`Courier New (Mono)`,value:`'Courier New', monospace`}]),[et]=(0,l.useState)(c||[{label:`Light`,value:`300`},{label:`Regular`,value:`400`},{label:`Medium`,value:`500`},{label:`Semibold`,value:`600`},{label:`Bold`,value:`700`},{label:`Extra Bold`,value:`800`}]),[tt]=(0,l.useState)(p),[nt]=(0,l.useState)(m),[rt]=(0,l.useState)(!0),[it,G]=(0,l.useState)({});(0,l.useEffect)(()=>{let e=()=>{let e=window.getSelection();if(!e||e.isCollapsed||e.toString().trim()===``){fe(null),ke(null);return}let t=document.activeElement;if(!(t&&t.getAttribute(`contenteditable`)===`true`&&(t.closest(`.canvas-editor-area`)||t.closest(`td`)))){fe(null),ke(null);return}try{let t=e.getRangeAt(0),n=t.getBoundingClientRect(),r=document.queryCommandValue(`formatBlock`)||``;r=r.toUpperCase(),fe({x:n.left+n.width/2,y:n.top-38,format:r}),ke(t)}catch{fe(null),ke(null)}};return document.addEventListener(`selectionchange`,e),()=>document.removeEventListener(`selectionchange`,e)},[fe]),(0,l.useEffect)(()=>{let e={};(t||[]).forEach(t=>{let n=t.placeholder.replace(/[{}]/g,``);e[n]=t.mockValue||``}),pe.forEach(t=>{t.columns.forEach(t=>{let n=t.placeholder.replace(/[{}]/g,``).replace(/^(\.\.\/|package\.|item\.)/,``);e[n]||(e[n]=t.mockValue||``)})}),G(e)},[t,pe]),(0,l.useEffect)(()=>{let e=N.current;if(!e)return;let t=e=>{if(e.ctrlKey){e.preventDefault();let t=e.deltaY<0?1:-1;k(e=>Math.min(2,Math.max(.5,e+t*.05)))}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[N,k]),(0,l.useEffect)(()=>{window.updateContentFromRawDelete=(e,t)=>{je(n=>n.map(n=>n.id===e?{...n,content:t}:n))}},[je]);let at=e=>{let t=e.target.files?.[0];if(!t)return;he(!0),z(`Parsing HTML...`),_e(null);let n=new FileReader;n.onload=t=>{try{let e=t.target?.result,n=ba(e);n.length>0&&je(n)}catch(e){console.error(e),_e(e.message||`Failed to parse HTML`)}finally{he(!1),e.target&&(e.target.value=``)}},n.readAsText(t)},ot=e=>{let t=e.target.files?.[0];if(!t)return;he(!0),z(`Reading PDF text layers...`),_e(null);let n=new FileReader;n.onload=async()=>{try{let e=n.result,t=await xa(e,d);t.length>0&&je(e=>[...e,...t])}catch(e){console.error(e),_e(e.message||`Failed to read PDF`)}finally{he(!1),e.target&&(e.target.value=``)}},n.readAsArrayBuffer(t)},st=e=>{let t=e||`items`;if(tt===`handlebars`||tt===`mustache`){let e=nt===`foreach`?`foreach`:`each`;return{start:`{{#${e} ${t}}}`,end:`{{/${e}}}`}}return tt===`liquid`||tt===`scriban`||tt===`dotnet`?{start:`{% for ${t.endsWith(`s`)?t.slice(0,-1):`item`} in ${t} %}`,end:`{% endfor %}`}:tt===`js`||tt===`ts`?{start:`\${${t}.map(${t.endsWith(`s`)?t.slice(0,-1):`item`} => \``,end:"`).join('')}"}:tt===`csharp`||tt===`razor`?{start:`@foreach (var ${t.endsWith(`s`)?t.slice(0,-1):`item`} in ${t}) {`,end:`}`}:{start:ie.replace(`items`,t),end:oe}},ct=(e=!1)=>{let t=`<!DOCTYPE html>
59
59
  <html>
60
60
  <head>
61
61
  <meta charset="utf-8">
62
62
  <title>Exported HTML Template</title>
63
63
  <style>
64
64
  body { font-family: 'Outfit', 'Inter', sans-serif; padding: 30px; background-color: #f8fafc; color: #1e293b; max-width: 800px; margin: 0 auto; line-height: 1.5; }
65
- .block-container { border-radius: 8px; border: 1px solid #e2e8f0; box-sizing: border-box; page-break-inside: avoid; break-inside: avoid; }
65
+ .block-container { box-sizing: border-box; page-break-inside: avoid; break-inside: avoid; }
66
66
  table { width: 100%; border-collapse: collapse; margin: 10px 0; }
67
67
  th { background-color: #f1f5f9; color: #334155; border: 1px solid #e2e8f0; padding: 6px 8px; font-weight: 600; text-align: left; }
68
68
  td { border: 1px solid #e2e8f0; padding: 6px 8px; color: #475569; }
@@ -72,7 +72,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
72
72
  </style>
73
73
  </head>
74
74
  <body>
75
- `;return xo(je).forEach(n=>{let r=n.blocks.length>1;if(r){let e=n.blocks[0]?.style?.flexDirection||`row`;t+=` <div class="row-container" style="display: flex; flex-direction: ${e}; flex-wrap: wrap; gap: 16px; width: 100%; align-items: stretch; margin-bottom: 8px;">\n`}n.blocks.forEach(n=>{let i=ga(n.style),a=n.style.textAlign===`center`?`margin-left: auto; margin-right: auto;`:n.style.textAlign===`right`?`margin-left: auto; margin-right: 0;`:`margin-left: 0; margin-right: auto;`,o=n.style.width||(r?`48%`:`100%`),s=r?`0px`:n.style.marginBottom||`8px`,c=n.style.height?`height: ${n.style.height};`:``,l=`margin-bottom: ${s}; padding: ${n.style.padding||`8px`}; width: ${o}; min-height: ${n.style.minHeight||`auto`}; ${c} ${a} background-color: ${n.style.backgroundColor||`transparent`};`;if(n.type===`table`){let r=n.tableInfo;if(!r)return;let a=r.columns.filter(e=>e.enabled!==!1);t+=` <div class="block-container" style="${l}">\n`;let o=i;i.includes(`font-size`)||(o+=` font-size: 10px;`),i.includes(`color`)||(o+=` color: #334155;`),i.includes(`text-align`)||(o+=` text-align: left;`),i.includes(`font-weight`)||(o+=` font-weight: 400;`),t+=` <table style="${o}">\n`,t+=` <thead>
75
+ `;return xo(Ae).forEach(n=>{let r=n.blocks.length>1;if(r){let e=n.blocks[0]?.style?.flexDirection||`row`;t+=` <div class="row-container" style="display: flex; flex-direction: ${e}; flex-wrap: wrap; gap: 16px; width: 100%; align-items: stretch; margin-bottom: 8px;">\n`}n.blocks.forEach(n=>{let i=ga(n.style),a=n.style.textAlign===`center`?`margin-left: auto; margin-right: auto;`:n.style.textAlign===`right`?`margin-left: auto; margin-right: 0;`:`margin-left: 0; margin-right: auto;`,o=n.style.width||(r?`48%`:`100%`),s=r?`0px`:n.style.marginBottom||`8px`,c=n.style.height?`height: ${n.style.height};`:``,l=`margin-bottom: ${s}; padding: ${n.style.padding||`8px`}; width: ${o}; min-height: ${n.style.minHeight||`auto`}; ${c} ${a} background-color: ${n.style.backgroundColor||`transparent`};`;if(n.type===`table`){let r=n.tableInfo;if(!r)return;let a=r.columns.filter(e=>e.enabled!==!1);t+=` <div class="block-container" style="${l}">\n`;let o=i;i.includes(`font-size`)||(o+=` font-size: 10px;`),i.includes(`color`)||(o+=` color: #334155;`),i.includes(`text-align`)||(o+=` text-align: left;`),i.includes(`font-weight`)||(o+=` font-weight: 400;`),t+=` <table style="${o}">\n`,t+=` <thead>
76
76
  `,t+=` <tr>
77
77
  `,a.forEach(e=>{let n=e.columnName||``;t+=` <th>${n}</th>\n`}),t+=` </tr>
78
78
  `,t+=` </thead>
@@ -83,17 +83,17 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
83
83
  `,r.forEach(e=>{i+=` <th>${e.columnName||``}</th>\n`}),i+=` </tr>
84
84
  `,i+=` </thead>
85
85
  `,i+=` <tbody>
86
- `,e&&Ye){let e=t.columnName;(n&&Array.isArray(n[e])?n[e]:[{}]).forEach(e=>{i+=` <tr>
87
- `,r.forEach(t=>{let n=So(t.placeholder);typeof e==`object`&&e&&Object.keys(e).forEach(t=>{let r=RegExp(`\\{\\{(item\\.|package\\.)?${t}\\}\\}`,`g`);n=n.replace(r,e[t])}),Object.keys(nt).forEach(e=>{let t=nt[e];n.includes(`{{${e}}}`)&&(n=n.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t))}),n=n.replace(/\{\{[^}]+\}\}/g,``),i+=` <td>${n}</td>\n`}),i+=` </tr>
88
- `})}else{let e=t.columnName||`items`,n=at(e);tt?i+=` <!-- ${n.start} --><tr>\n`:i+=` ${n.start}<tr>\n`,r.forEach(e=>{i+=` <td>${e.placeholder}</td>\n`}),tt?i+=` </tr><!-- ${n.end} -->\n`:i+=` </tr>${n.end}\n`}return i+=` </tbody>
86
+ `,e&&Ze){let e=t.columnName;(n&&Array.isArray(n[e])?n[e]:[{}]).forEach(e=>{i+=` <tr>
87
+ `,r.forEach(t=>{let n=So(t.placeholder);typeof e==`object`&&e&&Object.keys(e).forEach(t=>{let r=RegExp(`\\{\\{(item\\.|package\\.)?${t}\\}\\}`,`g`);n=n.replace(r,e[t])}),Object.keys(it).forEach(e=>{let t=it[e];n.includes(`{{${e}}}`)&&(n=n.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t))}),n=n.replace(/\{\{[^}]+\}\}/g,``),i+=` <td>${n}</td>\n`}),i+=` </tr>
88
+ `})}else{let e=t.columnName||`items`,n=st(e);rt?i+=` <!-- ${n.start} --><tr>\n`:i+=` ${n.start}<tr>\n`,r.forEach(e=>{i+=` <td>${e.placeholder}</td>\n`}),rt?i+=` </tr><!-- ${n.end} -->\n`:i+=` </tr>${n.end}\n`}return i+=` </tbody>
89
89
  `,i+=` </table>`,i},c=t=>{let n=` <tr>
90
- `;return a.forEach(r=>{if(r.loop&&r.columns&&r.columns.length>0)n+=` <td>\n${s(r,t)}\n </td>\n`;else{let i=So(r.placeholder);e&&Ye&&(Object.keys(t).forEach(e=>{i.includes(`{{${e}}}`)&&(i=i.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t[e])),i.includes(`{{item.${e}}}`)&&(i=i.replace(RegExp(`\\{\\{item\\.${e}\\}\\}`,`g`),t[e])),i.includes(`{{package.${e}}}`)&&(i=i.replace(RegExp(`\\{\\{package\\.${e}\\}\\}`,`g`),t[e]))}),Object.keys(nt).forEach(e=>{let t=nt[e];i.includes(`{{${e}}}`)&&(i=i.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t))}),i=i.replace(/\{\{[^}]+\}\}/g,``)),n+=` <td>${i}</td>\n`}}),n+=` </tr>
91
- `,n};if(e&&Ye){let e=[];e=r.mockRows&&r.mockRows.length>0?r.mockRows:[{}],e.forEach(e=>{t+=c(e)})}else{let e=r.tableName===`package`?`shipment.packages`:r.tableName===`article`?`package.articles`:r.tableName,n=at(e);tt?t+=` <!-- ${n.start} --><tr>\n`:t+=` ${n.start}<tr>\n`,a.forEach(e=>{e.loop&&e.columns&&e.columns.length>0?t+=` <td>\n${s(e)}\n </td>\n`:t+=` <td>${e.placeholder}</td>\n`}),tt?t+=` </tr><!-- ${n.end} -->\n`:t+=` </tr>${n.end}\n`}t+=` </tbody>
90
+ `;return a.forEach(r=>{if(r.loop&&r.columns&&r.columns.length>0)n+=` <td>\n${s(r,t)}\n </td>\n`;else{let i=So(r.placeholder);e&&Ze&&(Object.keys(t).forEach(e=>{i.includes(`{{${e}}}`)&&(i=i.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t[e])),i.includes(`{{item.${e}}}`)&&(i=i.replace(RegExp(`\\{\\{item\\.${e}\\}\\}`,`g`),t[e])),i.includes(`{{package.${e}}}`)&&(i=i.replace(RegExp(`\\{\\{package\\.${e}\\}\\}`,`g`),t[e]))}),Object.keys(it).forEach(e=>{let t=it[e];i.includes(`{{${e}}}`)&&(i=i.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t))}),i=i.replace(/\{\{[^}]+\}\}/g,``)),n+=` <td>${i}</td>\n`}}),n+=` </tr>
91
+ `,n};if(e&&Ze){let e=[];e=r.mockRows&&r.mockRows.length>0?r.mockRows:[{}],e.forEach(e=>{t+=c(e)})}else{let e=r.tableName===`package`?`shipment.packages`:r.tableName===`article`?`package.articles`:r.tableName,n=st(e);rt?t+=` <!-- ${n.start} --><tr>\n`:t+=` ${n.start}<tr>\n`,a.forEach(e=>{e.loop&&e.columns&&e.columns.length>0?t+=` <td>\n${s(e)}\n </td>\n`:t+=` <td>${e.placeholder}</td>\n`}),rt?t+=` </tr><!-- ${n.end} -->\n`:t+=` </tr>${n.end}\n`}t+=` </tbody>
92
92
  `,t+=` </table>
93
93
  `,t+=` </div>
94
- `}else if(n.type===`image`){let i=n.imageInfo||{imageType:`logo`},a=``,s=n.style.height||n.style.minHeight||`auto`;a=i.imageType===`barcode`?e&&Ye?va(i.barcodeValue||`SHIP-99201`):`<img src="${i.barcodePlaceholder||`{{barcode}}`}" style="width: 100%; height: ${s}; display: block;" alt="Barcode" />`:`<img src="${i.url||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}" style="width: 100%; height: auto; max-height: ${s===`auto`?`300px`:s}; object-fit: ${n.style.objectFit||`contain`}; ${n.style.opacity?`opacity: ${n.style.opacity};`:``} display: block;" alt="${i.imageType}" />`;let c=r?`100%`:n.style.width||`100%`;t+=` <div class="block-container" style="display: block; width: ${o}; text-align: ${n.style.textAlign||`left`}; border: none; background-color: transparent; ${n.style.marginBottom?`margin-bottom: ${n.style.marginBottom};`:``}">\n`,t+=` <div style="width: ${c}; display: inline-block;">\n`,t+=` ${a}\n`,t+=` </div>
94
+ `}else if(n.type===`image`){let i=n.imageInfo||{imageType:`logo`},a=``,s=n.style.height||n.style.minHeight||`auto`;a=i.imageType===`barcode`?e&&Ze?va(i.barcodeValue||`SHIP-99201`):`<img src="${i.barcodePlaceholder||`{{barcode}}`}" style="width: 100%; height: ${s}; display: block;" alt="Barcode" />`:`<img src="${i.url||`data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwIDAgODAwIDQwMCI+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iI2YxZjVmOSIvPjxyZWN0IHg9IjEwIiB5PSIxMCIgd2lkdGg9Ijc4MCIgaGVpZ2h0PSIzODAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2RiZTJmNiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtZGFzaGFycmF5PSI2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSInT3V0Zml0JywgJ0ludGVyJywgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIyNCIgZm9udC13ZWlnaHQ9IjYwMCIgZmlsbD0iIzk0YTNiOCIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U2VsZWN0IEltYWdlPC90ZXh0Pjwvc3ZnPg==`}" style="width: 100%; height: auto; max-height: ${s===`auto`?`300px`:s}; object-fit: ${n.style.objectFit||`contain`}; ${n.style.opacity?`opacity: ${n.style.opacity};`:``} display: block;" alt="${i.imageType}" />`;let c=r?`100%`:n.style.width||`100%`;t+=` <div class="block-container" style="display: block; width: ${o}; text-align: ${n.style.textAlign||`left`}; border: none; background-color: transparent; ${n.style.marginBottom?`margin-bottom: ${n.style.marginBottom};`:``}">\n`,t+=` <div style="width: ${c}; display: inline-block;">\n`,t+=` ${a}\n`,t+=` </div>
95
95
  `,t+=` </div>
96
- `}else{let r=`p`;[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`].includes(n.type)?r=n.type:n.type===`title`?r=`h1`:n.type===`subtitle`?r=`h2`:n.type===`caption`&&(r=`span`);let a=So(n.content);e&&Ye&&(Object.keys(nt).forEach(e=>{let t=nt[e];a=a.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t)}),a=a.replace(/\{\{[^}]+\}\}/g,``)),t+=` <div class="block-container" style="${l} text-align: ${n.style.textAlign};">\n`,t+=` <${r} style="${i}">${a}</${r}>\n`,t+=` </div>
96
+ `}else{let r=`p`;[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`].includes(n.type)?r=n.type:n.type===`title`?r=`h1`:n.type===`subtitle`?r=`h2`:n.type===`caption`&&(r=`span`);let a=So(n.content);e&&Ze&&(Object.keys(it).forEach(e=>{let t=it[e];a=a.replace(RegExp(`\\{\\{${e}\\}\\}`,`g`),t)}),a=a.replace(/\{\{[^}]+\}\}/g,``)),t+=` <div class="block-container" style="${l} text-align: ${n.style.textAlign};">\n`,t+=` <${r} style="${i}">${a}</${r}>\n`,t+=` </div>
97
97
  `}}),r&&(t+=` </div>
98
98
  `)}),t+=`</body>
99
- </html>`,t},st=()=>{let e=ot(!1);if(g)g(e);else{let t=new Blob([e],{type:`text/html;charset=utf-8;`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`exported_template.html`,n.click()}},ct=()=>{let e=ot(!0);if(_)_(e);else{let t=window.open(``,`_blank`);t&&(t.document.write(e),t.document.close(),t.focus(),setTimeout(()=>{t.print(),t.close()},500))}},lt=()=>{V([]),Ne(null)},ut=(e,t)=>{let n=e.dataTransfer.getData(`placeholder`);if(!n)return;e.preventDefault(),e.stopPropagation();let r=`{{${n.replace(/[{}]/g,``)}}}`;V(e=>e.map(e=>e.id===t?{...e,content:e.content+r}:e))},dt=(e,t,n,r)=>{let i=e.dataTransfer.getData(`placeholder`);if(!i)return;e.preventDefault(),e.stopPropagation();let a=i.startsWith(`{{`)?i:`{{${i}}}`;ft(t,n,a,r)},ft=(e,t,n,r)=>{V(i=>i.map(i=>{if(i.id===e&&i.type===`table`&&i.tableInfo){let e=[...i.tableInfo.columns];if(r!==void 0&&e[t]?.columns){let i=[...e[t].columns];i[r]={...i[r],placeholder:n},e[t]={...e[t],columns:i}}else e[t]={...e[t],placeholder:n};return{...i,tableInfo:{...i.tableInfo,columns:e}}}return i}))};return(0,u.jsxs)(`div`,{className:`min-h-screen bg-slate-50 flex flex-col font-sans`,children:[(0,u.jsx)(oo,{headerLogo:o,headerTitle:i,headerSubtitle:a,parseError:_e,isParsing:he,parseStatusText:L,showImportHtml:b,showImportPdf:x,showPreview:C,showExport:w,showExportPdf:T,customButtonStyles:E,customButtonClassNames:D,handleHtmlImport:it,handlePdfImport:G,setPreviewOpen:Je,handleExport:st,handleExportPdf:ct}),(0,u.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row overflow-hidden`,children:[(0,u.jsxs)(`main`,{className:`w-full lg:w-[70%] flex flex-col bg-slate-100 border-b lg:border-b-0 lg:border-r border-gray-200 overflow-hidden relative`,children:[(0,u.jsx)(vo,{showClearCanvas:S,handleClearCanvas:lt,customButtonStyles:E,customButtonClassNames:D,zoom:O,setZoom:k,setPanOffset:j}),(0,u.jsx)(_o,{blocks:je,setBlocks:V,selectedBlockId:Me,setSelectedBlockId:Ne,setActiveTab:Ke,showMockData:Ye,placeholderMockData:nt,dragOverIndex:be,setDragOverIndex:xe,draggedSidebarItem:z,defaultStyles:y,zoom:O,panOffset:A,spacePressed:M,canvasHeight:ee,viewportRef:te,canvasContainerRef:ne,handleMouseDown:re,handleMouseMove:N,handleMouseUp:P,createTextBlock:Fe,duplicateBlock:Le,reorderBlock:(e,t)=>{t===`up`?Re(e):ze(e)},handleDeleteBlock:Ie,handleSidebarDrop:e=>{if(!z)return;let t;if(z.type===`table`&&z.tableSchema)t=H(z.tableSchema);else if(z.type===`image`&&z.imageType)t=U(z.imageType);else{let e=`Enter text here...`;z.type===`h1`?e=`Heading 1`:z.type===`h2`?e=`Heading 2`:z.type===`h3`?e=`Heading 3`:z.type===`title`?e=`Document Title`:z.type===`subtitle`?e=`Document Subtitle`:z.type===`caption`&&(e=`Caption text...`),t=Fe(z.type,e,y?.[z.type])}V(n=>{let r=[...n];return r.splice(e,0,t),r}),Ne(t.id),Ke(`styles`)},handleTableCellDrop:dt,updateTableCell:ft,handleTextDrop:ut})]}),(0,u.jsx)(po,{activeTab:Ge,setActiveTab:Ke,setBlocks:V,selectedBlockId:Me,setSelectedBlockId:Ne,getSelectedBlock:Pe,defaultStyles:y,createTextBlock:Fe,createImageBlock:U,updateSelectedStyle:W,updateSelectedImageInfo:Be,handleDeleteBlock:Ie,handleRemoveTableColumn:Ve,handleAddTableColumn:He,handleUpdateTableColumn:Ue,handleReorderTableColumn:We,schemas:me,toggleSchemaColumn:Oe,customTableName:F,setCustomTableName:ie,customLoopStart:ae,setCustomLoopStart:oe,customLoopEnd:se,setCustomLoopEnd:I,handleAddCustomTable:Ee,newColName:ce,setNewColName:le,newColPlaceholder:ue,setNewColPlaceholder:de,customImageTypes:we,newImgTypeName:Se,setNewImgTypeName:Ce,handleAddCustomImageType:De,placeholders:t,searchPlaceholder:B,setSearchPlaceholder:Te,placeholderMockData:nt,setPlaceholderMockData:rt,handleSidebarDragStart:(e,t,n,r)=>{ye({type:t,tableSchema:n,imageType:r}),e.dataTransfer.setData(`source`,`sidebar`),e.dataTransfer.effectAllowed=`copy`},fontSizesState:Xe,fontFamiliesState:Ze,fontWeightsState:Qe})]}),(0,u.jsx)(bo,{bubbleCoords:fe,applySelectionFormat:ke}),(0,u.jsx)(yo,{previewOpen:qe,setPreviewOpen:Je,generateExportHtml:ot})]})}var wo=Co;exports.HtmlEditor=Co,exports.default=wo;
99
+ </html>`,t},lt=()=>{let e=ct(!1);if(g)g(e);else{let t=new Blob([e],{type:`text/html;charset=utf-8;`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`exported_template.html`,n.click()}},ut=()=>{let e=ct(!0);if(_)_(e);else{let t=window.open(``,`_blank`);t&&(t.document.write(e),t.document.close(),t.focus(),setTimeout(()=>{t.print(),t.close()},500))}},dt=()=>{je([]),Ne(null)},ft=(e,t)=>{let n=e.dataTransfer.getData(`placeholder`);if(!n)return;e.preventDefault(),e.stopPropagation();let r=`{{${n.replace(/[{}]/g,``)}}}`;je(e=>e.map(e=>e.id===t?{...e,content:e.content+r}:e))},pt=(e,t,n,r)=>{let i=e.dataTransfer.getData(`placeholder`);if(!i)return;e.preventDefault(),e.stopPropagation();let a=i.startsWith(`{{`)?i:`{{${i}}}`;K(t,n,a,r)},K=(e,t,n,r)=>{je(i=>i.map(i=>{if(i.id===e&&i.type===`table`&&i.tableInfo){let e=[...i.tableInfo.columns];if(r!==void 0&&e[t]?.columns){let i=[...e[t].columns];i[r]={...i[r],placeholder:n},e[t]={...e[t],columns:i}}else e[t]={...e[t],placeholder:n};return{...i,tableInfo:{...i.tableInfo,columns:e}}}return i}))};return(0,u.jsxs)(`div`,{className:`min-h-screen bg-slate-50 flex flex-col font-sans`,children:[(0,u.jsx)(oo,{headerLogo:o,headerTitle:i,headerSubtitle:a,parseError:ge,isParsing:me,parseStatusText:R,showImportHtml:b,showImportPdf:x,showPreview:C,showExport:w,showExportPdf:T,customButtonStyles:E,customButtonClassNames:D,handleHtmlImport:at,handlePdfImport:ot,setPreviewOpen:Xe,handleExport:lt,handleExportPdf:ut}),(0,u.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row overflow-hidden`,children:[(0,u.jsxs)(`main`,{className:`w-full lg:w-[70%] flex flex-col bg-slate-100 border-b lg:border-b-0 lg:border-r border-gray-200 overflow-hidden relative`,children:[(0,u.jsx)(vo,{showClearCanvas:S,handleClearCanvas:dt,customButtonStyles:E,customButtonClassNames:D,zoom:O,setZoom:k,setPanOffset:j}),(0,u.jsx)(_o,{blocks:Ae,setBlocks:je,selectedBlockId:Me,setSelectedBlockId:Ne,setActiveTab:Je,showMockData:Ze,placeholderMockData:it,dragOverIndex:ye,setDragOverIndex:be,draggedSidebarItem:B,defaultStyles:y,zoom:O,panOffset:A,spacePressed:ee,canvasHeight:M,viewportRef:N,canvasContainerRef:te,handleMouseDown:ne,handleMouseMove:P,handleMouseUp:F,createTextBlock:Fe,duplicateBlock:Le,reorderBlock:(e,t)=>{t===`up`?Re(e):ze(e)},handleDeleteBlock:Ie,handleSidebarDrop:e=>{if(!B)return;let t;if(B.type===`table`&&B.tableSchema)t=H(B.tableSchema);else if(B.type===`image`&&B.imageType)t=U(B.imageType);else{let e=`Enter text here...`;B.type===`h1`?e=`Heading 1`:B.type===`h2`?e=`Heading 2`:B.type===`h3`?e=`Heading 3`:B.type===`title`?e=`Document Title`:B.type===`subtitle`?e=`Document Subtitle`:B.type===`caption`&&(e=`Caption text...`),t=Fe(B.type,e,y?.[B.type])}je(n=>{let r=[...n];return r.splice(e,0,t),r}),Ne(t.id),Je(`styles`)},handleTableCellDrop:pt,updateTableCell:K,handleTextDrop:ft})]}),(0,u.jsx)(po,{activeTab:qe,setActiveTab:Je,setBlocks:je,selectedBlockId:Me,setSelectedBlockId:Ne,getSelectedBlock:Pe,defaultStyles:y,createTextBlock:Fe,createImageBlock:U,updateSelectedStyle:W,updateSelectedImageInfo:Be,handleDeleteBlock:Ie,handleRemoveTableColumn:Ve,handleAddTableColumn:He,handleUpdateTableColumn:Ue,handleReorderTableColumn:We,handleAddTableRow:Ge,handleRemoveTableRow:Ke,schemas:pe,toggleSchemaColumn:De,customTableName:I,setCustomTableName:re,customLoopStart:ie,setCustomLoopStart:ae,customLoopEnd:oe,setCustomLoopEnd:L,handleAddCustomTable:Te,newColName:se,setNewColName:ce,newColPlaceholder:le,setNewColPlaceholder:ue,customImageTypes:Ce,newImgTypeName:xe,setNewImgTypeName:Se,handleAddCustomImageType:Ee,placeholders:t,searchPlaceholder:V,setSearchPlaceholder:we,placeholderMockData:it,setPlaceholderMockData:G,handleSidebarDragStart:(e,t,n,r)=>{ve({type:t,tableSchema:n,imageType:r}),e.dataTransfer.setData(`source`,`sidebar`),e.dataTransfer.effectAllowed=`copy`},fontSizesState:Qe,fontFamiliesState:$e,fontWeightsState:et})]}),(0,u.jsx)(bo,{bubbleCoords:de,applySelectionFormat:Oe}),(0,u.jsx)(yo,{previewOpen:Ye,setPreviewOpen:Xe,generateExportHtml:ct})]})}var wo=Co;exports.HtmlEditor=Co,exports.default=wo;