UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1 lines 183 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("kendo.draggable.cmn.chunk.js"),require("kendo.file-saver.cmn.chunk.js"),require("kendo.common.cmn.chunk.js"),require("kendo.pdfjs.loader.js")):"function"==typeof define&&define.amd?define(["exports","kendo.draggable.cmn.chunk","kendo.file-saver.cmn.chunk","kendo.common.cmn.chunk","kendo.pdfjs.loader"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.PdfviewerCommonCmnChunk={}),t.kendo._globals.DraggableCmnChunk,t.kendo._globals.FileSaverCmnChunk,t.kendo._globals.CommonCmnChunk,t.kendo._globals.PdfjsLoader)}(this,(function(t,e,i,s,n){const a=(...t)=>Object.assign(...t),o=t=>t&&"object"==typeof t&&!Array.isArray(t),r=(t,...e)=>{if(!e.length)return t;const i=e.shift();if(o(t)&&o(i))for(const e in i)"__proto__"!==e&&"constructor"!==e&&(i[e]instanceof p?t[e]=i[e]:i[e]instanceof HTMLElement||"dotNetInstance"===e||(s=i[e])&&window&&window.DotNet&&window.DotNet.DotNetObject&&s instanceof DotNet.DotNetObject||i[e]&&i[e].buffer&&i[e].buffer instanceof ArrayBuffer||o(i[e])&&Object.getPrototypeOf(i[e])!==Object.prototype?t[e]=i[e]:o(i[e])?(t[e]&&o(t[e])||a(t,{[e]:{}}),r(t[e],i[e])):a(t,{[e]:i[e]}));var s;return r(t,...e)},h=t=>"string"==typeof t,l=t=>(t=>void 0!==t)(t)&&(t=>null!==t)(t),d=function(){},c=(t,e)=>{const i=(e||document).createElement("template");i.innerHTML=t.trim();const s=i.content;return s.childNodes.length>1?s.childNodes:s.firstChild},u=t=>(null==t?void 0:t.startsWith("."))?t:`.${t}`,f=()=>{let t,e;const i=new Promise((function(i,s){t=i,e=s}));return i.resolve=t,i.reject=e,i};class p{constructor(t,e){this.options={events:{}},this.element=t,this.options=e}destroy(){this.element=null}extendOptions(t){this.options=r(this.options,t)}setOptions(t){this.options=t}trigger(t,e={}){const i={defaultPrevented:!1,preventDefault:()=>{i.defaultPrevented=!0}};return"function"==typeof this.options.events[t]&&this.options.events[t](a(i,e,{sender:this})),i.defaultPrevented}}const g=function(t,e,i={}){let s,n,a,o,r=0;const h=function(){r=!1===i.leading?0:(new Date).getTime(),s=void 0,o=t.apply(n,a),s||(n=a=null)};return function(){const l=(new Date).getTime();r||!1!==i.leading||(r=l);const d=e-(l-r);return n=void 0,a=arguments,d<=0||d>e?(s&&(clearTimeout(s),s=void 0),r=l,o=t.apply(n,a),s||(n=a=null)):s||!1===i.trailing||(s=window.setTimeout(h,d)),o}},m=1e3/60,v="scroll";class y extends p{constructor(t,e){super(t,e),this.options={events:{[v]:d},filter:"",panScrollThrottleDelay:m,scrollDirectionModifier:-1,scrollThrottleDelay:m},this.onElementScroll=t=>{const e=this.element;this.shouldTrackScrollEvents()&&(this.state.trackNextElementScroll?this.scrollTo(e.scrollLeft,e.scrollTop):this.state.trackNextElementScroll=!0,this.trigger(v,{originalEvent:t}))},this.onDragStart=t=>{if(this.state.dragStarted=!1,!this.shouldTrackPanEvents())return;const e=t.target||(t.originalEvent||{}).target;this.options.filter&&!((t,e)=>!(!t||!e)&&t.closest(e))(e,this.options.filter)||((t=>{t.preventDefault&&t.preventDefault(),t.originalEvent&&t.originalEvent.preventDefault()})(t),this.setState({dragStarted:!0,location:{pageX:t.pageX,pageY:t.pageY},locationDelta:{x:0,y:0}}))},this.onDrag=t=>{if(!this.shouldTrackPanEvents()||!this.state.dragStarted)return;this.calculateEventLocationDelta(t),this.setState({location:{pageX:t.pageX,pageY:t.pageY}});const e=this.options.scrollDirectionModifier,i=this.element.scrollLeft+e*this.state.locationDelta.x,s=this.element.scrollTop+e*this.state.locationDelta.y;this.scrollTo(i,s)},this.onDragEnd=()=>{},this.extendOptions(e),this.resetState(),this.bindEvents()}destroy(){this.unbindEvents()}initDraggable(){this.destroyDraggable(),this.options.panScrollThrottleDelay>0?this.throttledOnDrag=g(this.onDrag,this.options.panScrollThrottleDelay):this.throttledOnDrag=this.onDrag,this.draggable=new e.D({mouseOnly:!1,press:this.onDragStart,drag:this.throttledOnDrag,release:this.onDragEnd}),this.draggable.bindTo(this.element)}destroyDraggable(){this.draggable&&this.draggable.destroy&&(this.draggable.destroy(),this.throttledOnDrag&&this.throttledOnDrag.cancel&&(this.throttledOnDrag.cancel(),this.throttledOnDrag=null))}bindEvents(){this.bindDraggableEvents(),this.bindElementScroll()}bindDraggableEvents(){this.initDraggable()}bindElementScroll(){this.options.scrollThrottleDelay>0?this.throttledOnElementScroll=g(this.onElementScroll,this.options.scrollThrottleDelay):this.throttledOnElementScroll=this.onElementScroll,this.element.addEventListener(v,this.throttledOnElementScroll)}unbindEvents(){this.unbindElementScroll(),this.unbindDraggableEvents()}unbindDraggableEvents(){this.destroyDraggable()}unbindElementScroll(){this.throttledOnElementScroll&&this.throttledOnElementScroll.cancel&&(this.throttledOnElementScroll.cancel(),this.throttledOnElementScroll=null),this.element.removeEventListener(v,this.throttledOnElementScroll)}setState(t){this.state=Object.assign({},this.state||{},t)}resetState(){this.setState({trackPanEvents:!1,trackScrollEvents:!1,trackNextElementScroll:!1,location:{pageX:0,pageY:0},locationDelta:{x:0,y:0}})}enablePanEventsTracking(){this.state.trackPanEvents=!0,this.bindDraggableEvents()}disablePanEventsTracking(){this.unbindDraggableEvents(),this.state.trackPanEvents=!1}shouldTrackPanEvents(){return this.state.trackPanEvents}enableScrollEventsTracking(){this.state.trackScrollEvents=!0,this.unbindElementScroll(),this.bindElementScroll()}disableScrollEventsTracking(){this.unbindElementScroll(),this.state.trackScrollEvents=!1}shouldTrackScrollEvents(){return this.state.trackScrollEvents}calculateEventLocationDelta(t){this.state.locationDelta={x:t.pageX-this.state.location.pageX,y:t.pageY-this.state.location.pageY}}scrollTo(t,e,i={trackScrollEvent:!0}){i.trackScrollEvent||(this.state.trackNextElementScroll=!1),this.element.scrollLeft=t,this.element.scrollTop=e}}const E=t=>{const e=t.parentElement;t&&e&&e.replaceWith(...Array.from(e.childNodes))},w=t=>`.${t}`,b="data-char-index",S="data-match-index";class M{constructor(t){this.options={highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char",textContainers:[]},this.extendOptions(t),this.resetState()}destroy(){this.clearSearch()}extendOptions(t){this.options=Object.assign({},this.options,t)}setState(t){this.state=Object.assign({},this.state||{},t)}resetState(){this.setState({text:"",textNodes:[],charIndex:0,activeMatchIndex:0,matches:[]})}escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}search({text:t,matchCase:e}){const i=this.escapeRegExp(t),s=new RegExp(i,e?"g":"ig");let n;if(this.shouldTransformText()&&this.transformTextForSearch(),this.state.matches=[],this.state.activeMatchIndex=0,this.removeIndicators(),""===i)return[];for(n=s.exec(this.state.text);n;)this.state.matches.push({startOffset:n.index,endOffset:n.index+n[0].length}),n=s.exec(this.state.text);return this.highlightAllMatches(),this.addActiveMatchMark(),this.state.matches}clearSearch(){this.removeIndicators(),this.restoreOriginalText()}restoreOriginalText(){this.forEachTextContainer((t=>{Array.from(t.querySelectorAll("span:not(."+this.options.charClass+")")).forEach((t=>{t.innerHTML=t.textContent}))}))}shouldTransformText(){return!this.state.text}transformTextForSearch(){this.state.textNodes=[],this.state.charIndex=0,this.state.text="",this.forEachTextContainer((t=>{this.extractTextNodes(t)})),this.transformTextNodesForSearch(this.state.textNodes)}extractTextNodes(t){if(t.nodeType===Node.TEXT_NODE)this.state.textNodes.push(t);else for(let e=0;e<t.childNodes.length;e++)this.extractTextNodes(t.childNodes[e])}transformTextNodesForSearch(t){for(let e=0;e<t.length;e++)this.transformTextNodeForSearch(t[e])}transformTextNodeForSearch(t){const e=t.textContent;if(e.length<=0)return;this.state.text=this.state.text+e;const i=document.createElement("span");var s,n;n=i,(s=t).parentNode&&(s.parentNode.insertBefore(n,s),n.appendChild(s));const a=this.splitTextByChars(e);i.innerHTML=a,E(i.childNodes[0])}splitTextByChars(t){let e="";for(let i=0;i<t.length;i++)e+=`<span class='${this.options.charClass}' ${b}=${this.state.charIndex}>${t[i]}</span>`,this.state.charIndex++;return e}forEachTextContainer(t){for(let e=0;e<this.options.textContainers.length;e++){t(this.options.textContainers[e],e)}}highlightAllMatches(){this.state.matches.forEach(((t,e)=>{this.addMatchHighlight(t.startOffset,t.endOffset,e)}))}addMatchHighlight(t,e,i){for(let s=t;s<e;s++)this.forEachTextContainer((t=>{Array.from(t.querySelectorAll(w(`${this.options.charClass}[${b}='${s}']`))).forEach((t=>{var e;e=this.options.highlightClass,t.classList.add(e),t.setAttribute(S,i)}))}))}removeMatchHighlights(){this.forEachTextContainer((t=>{Array.from(t.querySelectorAll(w(this.options.highlightClass))).forEach((t=>{var e;e=this.options.highlightClass,t.classList.remove(e),t.removeAttribute(S)}))}))}addActiveMatchMark(){this.state.activeMatchIndex||0===this.state.activeMatchIndex?this.state.activeMatchIndex>this.state.matches.length?this.state.activeMatchIndex=this.state.matches.length:this.removeActiveMatchMark():this.state.activeMatchIndex=0;const t=document.createElement("span");t.classList.add(this.options.highlightMarkClass),this.forEachTextContainer((e=>{Array.from(e.querySelectorAll(w(this.options.charClass+"["+S+"='"+this.state.activeMatchIndex+"']"))).forEach((e=>{((t,e)=>{if(t&&t.parentNode&&e)for(t.appendChild(e);t.firstChild&&t.firstChild!==e;)e.appendChild(t.firstChild)})(e,t.cloneNode(!0))}))}))}removeActiveMatchMark(){this.forEachTextContainer((t=>{(t=>{if(t&&t.length&&!(t.length<=0))for(let e=0;e<t.length;e++)E(t[e])})(Array.from(t.querySelectorAll(w(this.options.highlightMarkClass))).flatMap((t=>Array.from(t.childNodes))))}))}removeIndicators(){this.removeActiveMatchMark(),this.removeMatchHighlights()}markNextMatch(){this.markNextMatchIndex(),this.addActiveMatchMark()}markPreviousMatch(){this.markPreviousMatchIndex(),this.addActiveMatchMark()}markNextMatchIndex(){this.moveActiveMatchIndex(1)}markPreviousMatchIndex(){this.moveActiveMatchIndex(-1)}moveActiveMatchIndex(t){this.state.activeMatchIndex+=t,this.state.activeMatchIndex<0?this.state.activeMatchIndex=Math.max(this.state.matches.length-1,0):this.state.activeMatchIndex>this.state.matches.length-1&&(this.state.activeMatchIndex=0)}getActiveMatchElement(){let t;return this.forEachTextContainer((e=>{const i=e.querySelector(w(this.options.highlightMarkClass));i&&(t=i)})),t}}const x=268435456,k=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/Macintosh/i.test(navigator.userAgent)?devicePixelRatio:3*devicePixelRatio,T=t=>atob(t.replace(/^(data:application\/pdf;base64,)/gi,"")),A=function(t,e,i){const s=document.createElement(t);return e&&(s.className=e),Object.keys(i).forEach((t=>s.style[t]=i[t])),s},P=(t,e)=>{const i=t.querySelectorAll(".k-page"),s=i[0];if(s instanceof HTMLDivElement){const t=(s.offsetHeight+s.offsetTop)*Math.max(0,Math.min(e,i.length-1)),n=s.closest(".k-pdf-viewer-canvas");n&&n.scrollTo({top:t,behavior:"auto"})}},L=t=>{const e=t.querySelector(".k-pdf-viewer-canvas"),i=t.querySelector(".k-page");return e&&i?Math.floor(Math.round(e.scrollTop)/(i.offsetHeight+i.offsetTop)+.01):0},_=(t,e)=>{const{maxWidth:i,maxHeight:n,maxArea:a}=(t=>{const e=s.d(t),i=s.a(t);return e&&e.mozilla||i&&"firefox"===i.browser})(navigator.userAgent)?{maxWidth:32767,maxHeight:32767,maxArea:124992400}:(o=navigator.userAgent,s.d(o).safari||s.a(o)&&"mobilesafari"===s.a(o).browser?{maxWidth:4194303,maxHeight:8388607,maxArea:x}:{maxWidth:65535,maxHeight:65535,maxArea:x});var o;let r=t,h=e;const l=t/e;if(t>i){r=i;h=e-(t-i)/l}if(h>n){const t=h-n;h=n,r-=t*l}const d=r*h;if(d>a){const t=Math.sqrt(a/d);r*=t,h*=t}const c=r/t;return{adjustedWidth:r!==t?Math.floor(r/2):t,adjustedHeight:h!==e?Math.floor(h/2):e,adjustRatio:1!==c?c/2:1}};function C(t,e,i,s){return new(i||(i=Promise))((function(n,a){function o(t){try{h(s.next(t))}catch(t){a(t)}}function r(t){try{h(s.throw(t))}catch(t){a(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,r)}h((s=s.apply(t,e||[])).next())}))}Object.create;Object.create;function D(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}function I(t,e,i,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(t,i):n?n.value=i:e.set(t,i),i}"function"==typeof SuppressedError&&SuppressedError;const N=(t,e)=>{e.classList.add(t)},O=(t,e)=>{e.classList.remove(t)},W=(t,e,i)=>Math.min(i,Math.max(e,t)),H=1.35,B=1,R="pdfjs_internal_editor_",F=3,z=9,$=2,V=3,U=9,j=16,G=1,X=2,K=3,Z=4,q=5;function Y(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}const J=Array.from(Array(256).keys(),(t=>t.toString(16).padStart(2,"0")));class Q{static makeHexColor(t,e,i){return`${J[t]}${J[e]}${J[i]}`}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}}const tt="pdfjs_internal_id_";var et,it,st,nt,at,ot,rt,ht,lt,dt,ct,ut,ft,pt,gt,mt,vt,yt,Et,wt,bt,St,Mt,xt,kt,Tt,At,Pt,Lt,_t,Ct,Dt,It,Nt,Ot,Wt,Ht,Bt,Rt,Ft,zt,$t,Vt,Ut,jt,Gt,Xt,Kt,Zt,qt,Yt,Jt,Qt,te,ee,ie,se,ne,ae;class oe{constructor(t=R){et.set(this,0),this.idPrefix=R,Object.defineProperty(this,"reset",{value:()=>I(this,et,0,"f")}),this.idPrefix=t}get id(){var t,e;return`${this.idPrefix}${I(this,et,(e=D(this,et,"f"),t=e++,e),"f"),t}`}}et=new WeakMap;class re{constructor(t=128){it.set(this,[]),st.set(this,!1),nt.set(this,void 0),at.set(this,-1),I(this,nt,t,"f")}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){if(s&&t(),D(this,st,"f"))return;const r={cmd:t,undo:e,post:i,type:n};if(-1===D(this,at,"f"))return D(this,it,"f").length>0&&(D(this,it,"f").length=0),I(this,at,0,"f"),void D(this,it,"f").push(r);if(a&&D(this,it,"f")[D(this,at,"f")].type===n)return o&&(r.undo=D(this,it,"f")[D(this,at,"f")].undo),void(D(this,it,"f")[D(this,at,"f")]=r);const h=D(this,at,"f")+1;h===D(this,nt,"f")?D(this,it,"f").splice(0,1):(I(this,at,h,"f"),h<D(this,it,"f").length&&D(this,it,"f").splice(h)),D(this,it,"f").push(r)}undo(){if(-1===D(this,at,"f"))return;I(this,st,!0,"f");const{undo:t,post:e}=D(this,it,"f")[D(this,at,"f")];t(),null==e||e(),I(this,st,!1,"f"),I(this,at,D(this,at,"f")-1,"f")}redo(){if(D(this,at,"f")<D(this,it,"f").length-1){I(this,at,D(this,at,"f")+1,"f"),I(this,st,!0,"f");const{cmd:t,post:e}=D(this,it,"f")[D(this,at,"f")];t(),null==e||e(),I(this,st,!1,"f")}}hasSomethingToUndo(){return-1!==D(this,at,"f")}hasSomethingToRedo(){return D(this,at,"f")<D(this,it,"f").length-1}destroy(){I(this,it,null,"f")}}it=new WeakMap,st=new WeakMap,nt=new WeakMap,at=new WeakMap;class he{constructor({container:t=null,viewer:e,pdfViewer:i,eventBus:s,pdfDocument:a,highlightColors:o=""}){ot.add(this),this.pdfViewer=null,this.annotationEditorMode=n.AnnotationEditorType.NONE,this.viewParameters={},this.isShiftKeyDown=!1,this._eventBus=null,rt.set(this,new AbortController),ht.set(this,null),lt.set(this,new Map),dt.set(this,new Map),ct.set(this,null),ut.set(this,null),ft.set(this,new re),pt.set(this,0),gt.set(this,new Set),mt.set(this,null),vt.set(this,null),yt.set(this,new Set),Et.set(this,!0),wt.set(this,null),bt.set(this,null),St.set(this,""),Mt.set(this,!1),xt.set(this,null),kt.set(this,new oe),Tt.set(this,!1),At.set(this,!1),Pt.set(this,null),Lt.set(this,n.AnnotationEditorType.NONE),_t.set(this,new Set),Ct.set(this,null),Dt.set(this,null),It.set(this,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1}),Nt.set(this,[0,0]),Ot.set(this,null),Wt.set(this,null),Ht.set(this,null);const r=this._signal=D(this,rt,"f").signal;I(this,Wt,t,"f"),I(this,Ht,e,"f"),this.pdfViewer=i,this._eventBus=s,this._eventBus._on("editingaction",this.onEditingAction.bind(this),{signal:r}),this._eventBus._on("pagechanging",this.onPageChanging.bind(this),{signal:r}),this._eventBus._on("scalechanging",this.onScaleChanging.bind(this),{signal:r}),this._eventBus._on("rotationchanging",this.onRotationChanging.bind(this),{signal:r}),this._eventBus._on("setpreference",this.onSetPreference.bind(this),{signal:r}),D(this,ot,"m",Vt).call(this),D(this,ot,"m",qt).call(this),D(this,ot,"m",Gt).call(this),I(this,ct,a.annotationStorage,"f"),I(this,St,o||"","f"),this.viewParameters={realScale:n.PixelsPerInch.PDF_TO_CSS_UNITS,rotation:0}}destroy(){var t;null===(t=D(this,rt,"f"))||void 0===t||t.abort(),I(this,rt,null,"f"),this._signal=null;for(const t of D(this,dt,"f").values())t.destroy();D(this,dt,"f").clear(),D(this,lt,"f").clear(),D(this,yt,"f").clear(),I(this,ht,null,"f"),D(this,_t,"f").clear(),D(this,ft,"f").destroy(),D(this,wt,"f")&&(clearTimeout(D(this,wt,"f")),I(this,wt,null,"f")),D(this,Ot,"f")&&(clearTimeout(D(this,Ot,"f")),I(this,Ot,null,"f"))}getTextLayerForAnchor(t){return t?t.closest(".textLayer")||t.closest(".k-text-layer"):null}combinedSignal(t){return AbortSignal&&AbortSignal.any?AbortSignal.any([this._signal,t.signal]):this._signal||t.signal}get direction(){return n.shadow(this,"direction",getComputedStyle(D(this,Wt,"f")).direction)}get highlightColors(){return n.shadow(this,"highlightColors",D(this,St,"f")?new Map:null)}get highlightColorNames(){return n.shadow(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,(t=>t.reverse()))):null)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal,mode:t}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t}){t}onPageChanging({pageNumber:t}){I(this,pt,t-1,"f")}focusMainContainer(){var t;null===(t=D(this,Wt,"f"))||void 0===t||t.focus()}findParent(t,e){for(const i of D(this,dt,"f").values()){const{x:s,y:n,width:a,height:o}=i.div.getBoundingClientRect();if(t>=s&&t<=s+a&&e>=n&&e<=n+o)return i}return null}disableUserSelect(t=!1){var e;null===(e=D(this,Ht,"f"))||void 0===e||e.classList.toggle("noUserSelect",t)}addShouldRescale(t){D(this,yt,"f").add(t)}removeShouldRescale(t){D(this,yt,"f").delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*n.PixelsPerInch.PDF_TO_CSS_UNITS;for(const t of D(this,yt,"f"))t.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:i,anchorOffset:s,focusNode:a,focusOffset:o}=e,r=e.toString(),h=D(this,ot,"m",Bt).call(this,e),l=this.getTextLayerForAnchor(h),d=this.getSelectionBoxes(l);if(!d)return;e.empty();const c=D(this,ot,"m",Rt).call(this,l),u=D(this,Lt,"f")===n.AnnotationEditorType.NONE,f=()=>{null==c||c.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:d,anchorNode:i,anchorOffset:s,focusNode:a,focusOffset:o,text:r}),u&&this.showAllEditors("highlight",!0)};u?this.switchToMode(n.AnnotationEditorType.HIGHLIGHT,f):f()}showEditorToolBar(t){if(!t)return;const e=this.getMode();e!==n.AnnotationEditorType.HIGHLIGHT&&e!==n.AnnotationEditorType.FREETEXT||this._eventBus.dispatch("kendoAnnotationEditorToolBarShow",{source:this,anchor:t})}hideEditorToolBar(){this._eventBus.dispatch("kendoAnnotationEditorToolBarHide",{source:this})}addToAnnotationStorage(t){t.isEmpty()||!D(this,ct,"f")||D(this,ct,"f").has(t.id)||D(this,ct,"f").setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,D(this,Mt,"f")&&(I(this,Mt,!1,"f"),D(this,ot,"m",$t).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of D(this,_t,"f"))if(e.div.contains(t)){I(this,Pt,[e,t],"f"),e._focusEventsAllowed=!1;break}}focus(){if(!D(this,Pt,"f"))return;const[t,e]=D(this,Pt,"f");I(this,Pt,null,"f"),e.addEventListener("focusin",(()=>{t._focusEventsAllowed=!0}),{once:!0,signal:this._signal}),e.focus()}addEditListeners(){D(this,ot,"m",Gt).call(this),D(this,ot,"m",Kt).call(this)}removeEditListeners(){D(this,ot,"m",Xt).call(this),D(this,ot,"m",Zt).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of D(this,vt,"f"))if(i.isHandlingMimeForPasting(e))return t.dataTransfer.dropEffect="copy",void t.preventDefault()}drop(t){for(const e of t.dataTransfer.items)for(const i of D(this,vt,"f"))if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){var e;if(t.preventDefault(),null===(e=D(this,ht,"f"))||void 0===e||e.commitOrRemove(),!this.hasSelection)return;const i=[];for(const t of D(this,_t,"f")){const e=t.serialize(!0);e&&i.push(e)}0!==i.length&&t.clipboardData.setData("application/pdfjs",JSON.stringify(i))}cut(t){this.copy(t),this.delete()}paste(t){t.preventDefault();const{clipboardData:e}=t;for(const t of e.items)for(const e of D(this,vt,"f"))if(e.isHandlingMimeForPasting(t.type))return void e.paste(t,this.currentLayer);let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(t){return}if(!Array.isArray(i))return;this.unselectAll();const s=this.currentLayer;try{const t=[];for(const e of i){const i=s.deserialize(e);if(!i)return;t.push(i)}const e=()=>{for(const e of t)D(this,ot,"m",ee).call(this,e);D(this,ot,"m",ne).call(this,t)},n=()=>{for(const e of t)e.remove()};this.addCommands({cmd:e,undo:n,mustExec:!0})}catch(t){}}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu")}}setEditingState(t){t?(D(this,ot,"m",Ut).call(this),D(this,ot,"m",Kt).call(this),D(this,ot,"m",Yt).call(this,{isEditing:D(this,Lt,"f")!==n.AnnotationEditorType.NONE,isEmpty:D(this,ot,"m",se).call(this),hasSomethingToUndo:D(this,ft,"f").hasSomethingToUndo(),hasSomethingToRedo:D(this,ft,"f").hasSomethingToRedo(),hasSelectedEditor:!1})):(D(this,ot,"m",jt).call(this),D(this,ot,"m",Zt).call(this),D(this,ot,"m",Yt).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!D(this,vt,"f")){I(this,vt,t,"f");for(const t of D(this,vt,"f"))D(this,ot,"m",Jt).call(this,t.defaultPropertiesToUpdate)}}getId(){return D(this,kt,"f").id}get currentLayer(){return D(this,dt,"f").get(D(this,pt,"f"))}getLayer(t){return D(this,dt,"f").get(t)}get currentPageIndex(){return D(this,pt,"f")}addLayer(t){D(this,dt,"f").set(t.pageIndex,t),D(this,Tt,"f")?t.enable():t.disable()}removeLayer(t){D(this,dt,"f").delete(t.pageIndex)}updateMode(t,e=null,i=!1){if(D(this,Lt,"f")!==t){if(I(this,Lt,t,"f"),t===n.AnnotationEditorType.NONE)return this.setEditingState(!1),void D(this,ot,"m",te).call(this);this.setEditingState(!0),D(this,ot,"m",Qt).call(this),this.unselectAll();for(const e of D(this,dt,"f").values())e.updateMode(t);if(e||!i){if(e)for(const t of D(this,lt,"f").values())if(t.annotationElementId===e){this.setSelected(t),t.enterInEditMode();break}}else this.addNewEditorFromKeyboard()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==D(this,Lt,"f")&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){if(D(this,vt,"f")){switch(t){case n.AnnotationEditorParamsType.CREATE:return void this.currentLayer.addNewEditor();case n.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:break;case n.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:I(this,Dt,D(this,Dt,"f")||new Map,"f").set(t,e),this.showAllEditors("highlight",e)}for(const i of D(this,_t,"f"))i.updateParams(t,e);for(const i of D(this,vt,"f"))i.updateDefaultParams(t,e)}}showAllEditors(t,e){var i,s;for(const i of D(this,lt,"f").values())i.editorType===t&&i.show(e);(null===(s=null===(i=D(this,Dt,"f"))||void 0===i?void 0:i.get(n.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL))||void 0===s||s)!==e&&D(this,ot,"m",Jt).call(this,[[n.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(D(this,At,"f")!==t){I(this,At,t,"f");for(const e of D(this,dt,"f").values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const i of D(this,lt,"f").values())i.pageIndex===t&&e.push(i);return e}getEditor(t){return D(this,lt,"f").get(t)}addEditor(t){D(this,lt,"f").set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(D(this,wt,"f")&&clearTimeout(D(this,wt,"f")),I(this,wt,setTimeout((()=>{this.focusMainContainer(),I(this,wt,null,"f")}),0),"f")),D(this,lt,"f").delete(t.id),this.unselect(t),t.annotationElementId&&D(this,gt,"f").has(t.annotationElementId)||null===(e=D(this,ct,"f"))||void 0===e||e.remove(t.id)}addDeletedAnnotationElement(t){D(this,gt,"f").add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return D(this,gt,"f").has(t)}removeDeletedAnnotationElement(t){D(this,gt,"f").delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){D(this,ht,"f")!==t&&(I(this,ht,t,"f"),t&&D(this,ot,"m",Jt).call(this,t.propertiesToUpdate))}updateUI(t){D(this,ot,"a",ie)===t&&D(this,ot,"m",Jt).call(this,t.propertiesToUpdate)}toggleSelected(t){if(D(this,_t,"f").has(t))return D(this,_t,"f").delete(t),t.unselect(),void D(this,ot,"m",Yt).call(this,{hasSelectedEditor:this.hasSelection});D(this,_t,"f").add(t),t.select(),D(this,ot,"m",Jt).call(this,t.propertiesToUpdate),D(this,ot,"m",Yt).call(this,{hasSelectedEditor:!0})}setSelected(t){for(const e of D(this,_t,"f"))e!==t&&e.unselect();D(this,_t,"f").clear(),D(this,_t,"f").add(t),t.select(),D(this,ot,"m",Jt).call(this,t.propertiesToUpdate),D(this,ot,"m",Yt).call(this,{hasSelectedEditor:!0})}isSelected(t){return D(this,_t,"f").has(t)}get firstSelectedEditor(){return D(this,_t,"f").values().next().value}unselect(t){t.unselect(),D(this,_t,"f").delete(t),D(this,ot,"m",Yt).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==D(this,_t,"f").size}get isEnterHandled(){return 1===D(this,_t,"f").size&&this.firstSelectedEditor.isEnterHandled}undo(){D(this,ft,"f").undo(),D(this,ot,"m",Yt).call(this,{hasSomethingToUndo:D(this,ft,"f").hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:D(this,ot,"m",se).call(this)})}redo(){D(this,ft,"f").redo(),D(this,ot,"m",Yt).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:D(this,ft,"f").hasSomethingToRedo(),isEmpty:D(this,ot,"m",se).call(this)})}addCommands(t){D(this,ft,"f").add(t),D(this,ot,"m",Yt).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:D(this,ot,"m",se).call(this)})}delete(){if(this.commitOrRemove(),!this.hasSelection)return;const t=[...D(this,_t,"f")];this.addCommands({cmd:()=>{for(const e of t)e.remove()},undo:()=>{for(const e of t)D(this,ot,"m",ee).call(this,e)},mustExec:!0})}commitOrRemove(){var t;null===(t=D(this,ht,"f"))||void 0===t||t.commitOrRemove()}hasSomethingToControl(){return D(this,ht,"f")||this.hasSelection}selectAll(){for(const t of D(this,_t,"f"))t.commit();D(this,ot,"m",ne).call(this,D(this,lt,"f").values())}unselectAll(){if((!D(this,ht,"f")||(D(this,ht,"f").commitOrRemove(),D(this,Lt,"f")===n.AnnotationEditorType.NONE))&&this.hasSelection){for(const t of D(this,_t,"f"))t.unselect();D(this,_t,"f").clear(),D(this,ot,"m",Yt).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,i=!1){if(i||this.commitOrRemove(),!this.hasSelection)return;D(this,Nt,"f")[0]+=t,D(this,Nt,"f")[1]+=e;const[s,n]=D(this,Nt,"f"),a=[...D(this,_t,"f")];D(this,Ot,"f")&&clearTimeout(D(this,Ot,"f")),I(this,Ot,setTimeout((()=>{I(this,Ot,null,"f"),D(this,Nt,"f")[0]=D(this,Nt,"f")[1]=0,this.addCommands({cmd:()=>{for(const t of a)D(this,lt,"f").has(t.id)&&t.translateInPage(s,n)},undo:()=>{for(const t of a)D(this,lt,"f").has(t.id)&&t.translateInPage(-s,-n)},mustExec:!1})}),1e3),"f");for(const i of a)i.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),I(this,mt,new Map,"f");for(const t of D(this,_t,"f"))D(this,mt,"f").set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!D(this,mt,"f"))return!1;this.disableUserSelect(!1);const t=D(this,mt,"f");I(this,mt,null,"f");let e=!1;for(const[{x:i,y:s,pageIndex:n},a]of t)a.newX=i,a.newY=s,a.newPageIndex=n,e||(e=i!==a.savedX||s!==a.savedY||n!==a.savedPageIndex);if(!e)return!1;const i=(t,e,i,s)=>{if(D(this,lt,"f").has(t.id)){const n=D(this,dt,"f").get(s);n?t._setParentAndPosition(n,e,i):(t.pageIndex=s,t.x=e,t.y=i)}};return this.addCommands({cmd:()=>{for(const[e,{newX:s,newY:n,newPageIndex:a}]of t)i(e,s,n,a)},undo:()=>{for(const[e,{savedX:s,savedY:n,savedPageIndex:a}]of t)i(e,s,n,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(D(this,mt,"f"))for(const i of D(this,mt,"f").keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}isActive(t){return D(this,ht,"f")===t}getActive(){return D(this,ht,"f")}getActiveEditor(){return D(this,ht,"f")}getMode(){return D(this,Lt,"f")}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let i=0,s=e.rangeCount;i<s;i++)if(!t.contains(e.getRangeAt(i).commonAncestorContainer))return null;const{x:i,y:s,width:n,height:a}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(t,e,o,r)=>({x:(e-s)/a,y:1-(t+o-i)/n,width:r/a,height:o/n});break;case"180":o=(t,e,o,r)=>({x:1-(t+o-i)/n,y:1-(e+r-s)/a,width:o/n,height:r/a});break;case"270":o=(t,e,o,r)=>({x:1-(e+r-s)/a,y:(t-i)/n,width:r/a,height:o/n});break;default:o=(t,e,o,r)=>({x:(t-i)/n,y:(e-s)/a,width:o/n,height:r/a})}const r=[];for(let t=0,i=e.rangeCount;t<i;t++){const i=e.getRangeAt(t);if(!i.collapsed)for(const{x:t,y:e,width:s,height:n}of i.getClientRects())0!==s&&0!==n&&r.push(o(t,e,s,n))}return 0===r.length?null:r}addChangedExistingAnnotation({annotationElementId:t,id:e}){I(this,ut,D(this,ut,"f")||new Map,"f").set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;null===(e=D(this,ut,"f"))||void 0===e||e.delete(t)}renderAnnotationElement(t){var e;const i=null===(e=D(this,ut,"f"))||void 0===e?void 0:e.get(t.data.id);if(!i)return;const s=D(this,ct,"f").getRawValue(i);s&&(D(this,Lt,"f")!==n.AnnotationEditorType.NONE||s.hasBeenModified)&&s.renderAnnotationElement(t)}}rt=new WeakMap,ht=new WeakMap,lt=new WeakMap,dt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ft=new WeakMap,pt=new WeakMap,gt=new WeakMap,mt=new WeakMap,vt=new WeakMap,yt=new WeakMap,Et=new WeakMap,wt=new WeakMap,bt=new WeakMap,St=new WeakMap,Mt=new WeakMap,xt=new WeakMap,kt=new WeakMap,Tt=new WeakMap,At=new WeakMap,Pt=new WeakMap,Lt=new WeakMap,_t=new WeakMap,Ct=new WeakMap,Dt=new WeakMap,It=new WeakMap,Nt=new WeakMap,Ot=new WeakMap,Wt=new WeakMap,Ht=new WeakMap,ot=new WeakSet,Bt=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Rt=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const e of D(this,dt,"f").values())if(e.hasTextLayer(t))return e;return null},Ft=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=D(this,ot,"m",Bt).call(this,t),i=this.getTextLayerForAnchor(e);this.getSelectionBoxes(i)&&this.showEditorToolBar(e)},zt=function(){var t,e;const i=document.getSelection();if(!i||i.isCollapsed)return void(D(this,Ct,"f")&&(I(this,Ct,null,"f"),D(this,ot,"m",Yt).call(this,{hasSelectedText:!1})));const{anchorNode:s}=i;if(s===D(this,Ct,"f"))return;const a=D(this,ot,"m",Bt).call(this,i),o=this.getTextLayerForAnchor(a);if(o){if(null===(e=D(this,xt,"f"))||void 0===e||e.hide(),I(this,Ct,s,"f"),D(this,ot,"m",Yt).call(this,{hasSelectedText:!0}),(D(this,Lt,"f")===n.AnnotationEditorType.HIGHLIGHT||D(this,Lt,"f")===n.AnnotationEditorType.NONE)&&(D(this,Lt,"f")===n.AnnotationEditorType.HIGHLIGHT&&this.showAllEditors("highlight",!0),!this.isShiftKeyDown)){const t=D(this,Lt,"f")===n.AnnotationEditorType.HIGHLIGHT?D(this,ot,"m",Rt).call(this,o):null;null==t||t.toggleDrawing();const e=new AbortController,i=this.combinedSignal(e),s=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),null==t||t.toggleDrawing(!0),"pointerup"===i.type&&D(this,ot,"m",$t).call(this,"main_toolbar"))};window.removeEventListener("pointerup",s),window.addEventListener("pointerup",s,{signal:i}),window.removeEventListener("blur",s),window.addEventListener("blur",s,{signal:i})}}else D(this,Ct,"f")&&(null===(t=D(this,xt,"f"))||void 0===t||t.hide(),I(this,Ct,null,"f"),D(this,ot,"m",Yt).call(this,{hasSelectedText:!1}))},$t=function(t=""){D(this,Lt,"f")===n.AnnotationEditorType.HIGHLIGHT?this.highlightSelection(t):D(this,Et,"f")&&D(this,ot,"m",Ft).call(this)},Vt=function(){document.addEventListener("selectionchange",D(this,ot,"m",zt).bind(this),{signal:this._signal})},Ut=function(){if(D(this,bt,"f"))return;I(this,bt,new AbortController,"f");const t=this.combinedSignal(D(this,bt,"f"));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},jt=function(){var t;null===(t=D(this,bt,"f"))||void 0===t||t.abort(),I(this,bt,null,"f")},Gt=function(){},Xt=function(){},Kt=function(){},Zt=function(){},qt=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Yt=function(t){if(!t)return;Object.entries(t).some((([t,e])=>D(this,It,"f")[t]!==e))&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(D(this,It,"f"),t)}),D(this,Lt,"f")===n.AnnotationEditorType.HIGHLIGHT&&!1===t.hasSelectedEditor&&D(this,ot,"m",Jt).call(this,[[n.AnnotationEditorParamsType.HIGHLIGHT_FREE,!0]]))},Jt=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},Qt=function(){if(!D(this,Tt,"f")){I(this,Tt,!0,"f");for(const t of D(this,dt,"f").values())t.enable();for(const t of D(this,lt,"f").values())t.enable()}},te=function(){if(this.unselectAll(),D(this,Tt,"f")){I(this,Tt,!1,"f");for(const t of D(this,dt,"f").values())t.disable();for(const t of D(this,lt,"f").values())t.disable()}},ee=function(t){const e=D(this,dt,"f").get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},ie=function(){let t=null;for(t of D(this,_t,"f"));return t},se=function(){if(0===D(this,lt,"f").size)return!0;if(1===D(this,lt,"f").size)for(const t of D(this,lt,"f").values())return t.isEmpty();return!1},ne=function(t){for(const t of D(this,_t,"f"))t.unselect();D(this,_t,"f").clear();for(const e of t)e.isEmpty()||(D(this,_t,"f").add(e),e.select());D(this,ot,"m",Yt).call(this,{hasSelectedEditor:this.hasSelection})},he.TRANSLATE_SMALL=1,he.TRANSLATE_BIG=10;class le{constructor(){ae.set(this,Object.create(null))}on(t,e,i=null){this._on(t,e,{external:!0,once:null==i?void 0:i.once,signal:null==i?void 0:i.signal})}off(t,e){this._off(t,e)}dispatch(t,e){const i=D(this,ae,"f")[t];if(!i||0===i.length)return;let s;for(const{listener:n,external:a,once:o}of i.slice(0))o&&this._off(t,n),a?(s||(s=[])).push(n):n(e);if(s){for(const t of s)t(e);s=null}}_on(t,e,i=null){var s;let n=null;if((null==i?void 0:i.signal)instanceof AbortSignal){const{signal:s}=i;if(s.aborted)return;const a=()=>this._off(t,e);n=()=>s.removeEventListener("abort",a),s.addEventListener("abort",a)}((s=D(this,ae,"f"))[t]||(s[t]=[])).push({listener:e,external:!0===(null==i?void 0:i.external),once:!0===(null==i?void 0:i.once),rmAbort:n})}_off(t,e){var i;const s=D(this,ae,"f")[t];if(s)for(let t=0,n=s.length;t<n;t++){const n=s[t];if(n.listener===e)return null===(i=n.rmAbort)||void 0===i||i.call(n),void s.splice(t,1)}}}ae=new WeakMap;const de=0,ce=1,ue=3,fe=0,pe=1,ge=1,me=3;function ve(t,e,i=0){let s=i,n=t.length-1;if(n<0||!e(t[n]))return t.length;if(e(t[s]))return s;for(;s<n;){const i=s+n>>1;e(t[i])?n=i:s=i+1}return s}var ye,Ee,we,be,Se,Me,xe,ke,Te,Ae,Pe,Le,_e,Ce,De,Ie,Ne,Oe,We,He,Be,Re,Fe,ze,$e,Ve,Ue,je,Ge,Xe,Ke,Ze,qe,Ye,Je,Qe,ti,ei,ii,si,ni,ai,oi,ri,hi,li,di,ci,ui,fi,pi,gi,mi,vi,yi,Ei,wi,bi,Si,Mi,xi;class ki{constructor(){ye.add(this),we.set(this,!1),be.set(this,null),Se.set(this,new Map),Me.set(this,new Map)}setTextMapping(t){I(this,be,t,"f")}enable(){if(D(this,we,"f"),!D(this,be,"f"))throw new Error("Text divs and strings have not been set.");if(I(this,we,!0,"f"),I(this,be,D(this,be,"f").slice(),"f"),D(this,be,"f").sort(D(Ee,Ee,"m",xe)),D(this,Se,"f").size>0){const t=D(this,be,"f");for(const[e,i]of D(this,Se,"f")){document.getElementById(e)?D(this,ye,"m",ke).call(this,e,t[i]):D(this,Se,"f").delete(e)}}for(const[t,e]of D(this,Me,"f"))this.addPointerInTextLayer(t,e);D(this,Me,"f").clear()}disable(){D(this,we,"f")&&(D(this,Me,"f").clear(),I(this,be,null,"f"),I(this,we,!1,"f"))}removePointerInTextLayer(t){if(!D(this,we,"f"))return void D(this,Me,"f").delete(t);const e=D(this,be,"f");if(!e||0===e.length)return;const{id:i}=t,s=D(this,Se,"f").get(i);if(void 0===s)return;const n=e[s];D(this,Se,"f").delete(i);let a=n.getAttribute("aria-owns");(null==a?void 0:a.includes(i))&&(a=a.split(" ").filter((t=>t!==i)).join(" "),a?n.setAttribute("aria-owns",a):(n.removeAttribute("aria-owns"),n.setAttribute("role","presentation")))}addPointerInTextLayer(t,e){if(!t)return void console.warn("no element");const{id:i}=t;if(!i)return null;if(!D(this,we,"f"))return D(this,Me,"f").set(t,e),null;e&&this.removePointerInTextLayer(t);const s=D(this,be,"f");if(!s||0===s.length)return null;const n=ve(s,(e=>D(Ee,Ee,"m",xe).call(Ee,t,e)<0)),a=Math.max(0,n-1),o=s[a];D(this,ye,"m",ke).call(this,i,o),D(this,Se,"f").set(i,a);const r=o.parentNode;return(null==r?void 0:r.classList.contains("markedContent"))||(null==r?void 0:r.classList.contains("k-marked-content"))?r.id:null}moveElementInDOM(t,e,i,s){const n=this.addPointerInTextLayer(i,s);if(!t.hasChildNodes())return t.append(e),n;const a=Array.from(t.children).filter((t=>t!==e));if(0===a.length)return n;const o=i||e,r=ve(a,(t=>D(Ee,Ee,"m",xe).call(Ee,o,t)<0));return 0===r?a[0].before(e):a[r-1].after(e),n}}Ee=ki,we=new WeakMap,be=new WeakMap,Se=new WeakMap,Me=new WeakMap,ye=new WeakSet,xe=function(t,e){const i=t.getBoundingClientRect(),s=e.getBoundingClientRect();if(0===i.width&&0===i.height)return 1;if(0===s.width&&0===s.height)return-1;const n=i.y,a=i.y+i.height,o=i.y+i.height/2,r=s.y,h=s.y+s.height,l=s.y+s.height/2;if(o<=r&&l>=a)return-1;if(l<=n&&o>=h)return 1;return i.x+i.width/2-(s.x+s.width/2)},ke=function(t,e){const i=e.getAttribute("aria-owns");(null==i?void 0:i.includes(t))||e.setAttribute("aria-owns",i?`${i} ${t}`:t),e.removeAttribute("role")};class Ti{constructor({pdfPage:t,accessibilityManager:e,styles:i,onAppend:s=null}){Te.add(this),this.pdfPage=null,this.div=null,this.accessibilityManager=null,Pe.set(this,null),Le.set(this,null),this.pdfPage=t,this.accessibilityManager=e,I(this,Pe,s,"f"),this.div=document.createElement("div"),this.div.tabIndex=0,this.div.classList.add("k-text-layer"),Object.keys(i).forEach((t=>this.div.style[t]=i[t]))}render(t){return C(this,arguments,void 0,(function*(t,e=null){var i,s,a;if(D(this,Le,"f"))return D(this,Le,"f").update({viewport:t,onBefore:this.hide.bind(this)}),void this.show();this.cancel(),I(this,Le,new n.TextLayer({textContentSource:this.pdfPage.streamTextContent(e||{includeMarkedContent:!1,disableNormalization:!0}),container:this.div,viewport:t}),"f");const{textDivs:o}=D(this,Le,"f");null===(i=this.accessibilityManager)||void 0===i||i.setTextMapping(o),yield D(this,Le,"f").render();const r=Array.from(this.div.querySelectorAll(".markedContent")||[])||[];if(r.forEach((t=>N("k-marked-content",t))),r&&r.length>0){const t=document.createElement("div");t.className="endOfContent",this.div.append(t),D(this,Te,"m",De).call(this,t)}null===(s=D(this,Pe,"f"))||void 0===s||s.call(this,this.div),null===(a=this.accessibilityManager)||void 0===a||a.enable()}))}hide(){this.div.hidden||(this.div.hidden=!0)}show(){this.div.hidden&&(this.div.hidden=!1)}cancel(){var t,e;null===(t=D(this,Le,"f"))||void 0===t||t.cancel(),I(this,Le,null,"f"),null===(e=this.accessibilityManager)||void 0===e||e.disable(),D(Ae,Ae,"m",Ie).call(Ae,this.div)}}function Ai(t){return Math.floor(255*Math.max(0,Math.min(1,t))).toString(16).padStart(2,"0")}function Pi(t){return Math.max(0,Math.min(255,255*t))}Ae=Ti,Pe=new WeakMap,Le=new WeakMap,Te=new WeakSet,De=function(t){const{div:e}=this;D(Ae,Ae,"f",_e).set(e,t),D(Ae,Ae,"m",Ne).call(Ae)},Ie=function(t){var e;D(this,Ae,"f",_e).delete(t),0===D(this,Ae,"f",_e).size&&(null===(e=D(this,Ae,"f",Ce))||void 0===e||e.abort(),I(this,Ae,null,"f",Ce))},Ne=function(){},_e={value:new Map},Ce={value:null};class Li{static CMYK_G([t,e,i,s]){return["G",1-Math.min(1,.3*t+.59*i+.11*e+s)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return[t=Pi(t),t,t]}static G_HTML([t]){const e=Ai(t);return`#${e}${e}${e}`}static RGB_G([t,e,i]){return["G",.3*t+.59*e+.11*i]}static RGB_rgb(t){return t.map(Pi)}static RGB_HTML(t){return`#${t.map(Ai).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,i,s]){return["RGB",1-Math.min(1,t+s),1-Math.min(1,i+s),1-Math.min(1,e+s)]}static CMYK_rgb([t,e,i,s]){return[Pi(1-Math.min(1,t+s)),Pi(1-Math.min(1,i+s)),Pi(1-Math.min(1,e+s))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,i]){const s=1-t,n=1-e,a=1-i;return["CMYK",s,n,a,Math.min(s,n,a)]}}const _i=new WeakSet;function Ci(t){return{width:t[2]-t[0],height:t[3]-t[1]}}class Di{static create(t){switch(t.data.annotationType){case $:return new Ni(t);case V:return new Ri(t);case U:return new Fi(t);default:return new Ii(t)}}}class Ii{constructor(t,{isRenderable:e=!1,ignoreBorder:i=!1,createQuadrilaterals:s=!1}={}){Oe.add(this),this.isRenderable=null,this.data=null,this.layer=null,this.linkService=null,this.downloadManager=null,this.imageResourcesPath=null,this.renderForms=null,this.svgFactory=null,this.annotationStorage=null,this.enableScripting=null,this.hasJSActions=null,this._fieldObjects=null,this.parent=null,this.container=null,this.popup=null,this.annotationEditorType=null,We.set(this,null),He.set(this,!1),Be.set(this,null),this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(i)),s&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:i}){return!!((null==t?void 0:t.str)||(null==e?void 0:e.str)||(null==i?void 0:i.str))}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Ii._hasPopupData(this.data)}updateEdited(t){var e;if(!this.container)return;I(this,We,D(this,We,"f")||{rect:this.data.rect.slice(0)},"f");const{rect:i}=t;i&&D(this,Oe,"m",Re).call(this,i),null===(e=D(this,Be,"f"))||void 0===e||e.popup.updateEdited(t)}resetEdited(){var t;D(this,We,"f")&&(D(this,Oe,"m",Re).call(this,D(this,We,"f").rect),null===(t=D(this,Be,"f"))||void 0===t||t.popup.resetEdited(),I(this,We,null,"f"))}_createContainer(t){const{data:e,parent:{page:i,viewport:s}}=this,a=document.createElement("section");a.setAttribute("data-annotation-id",e.id),this instanceof Oi||(a.tabIndex=0);const{style:o}=a;if(o.zIndex=(this.parent.zIndex++).toString(),e.popupRef&&a.setAttribute("aria-haspopup","dialog"),e.alternativeText&&(a.title=e.alternativeText),e.noRotate,!e.rect||this instanceof Hi){const{rotation:t}=e;return e.hasOwnCanvas||0===t||this.setRotation(t,a),a}const{width:r,height:h}=Ci(e.rect);if(!t&&e.borderStyle.width>0){o.borderWidth=`${e.borderStyle.width}px`;const t=e.borderStyle.horizontalCornerRadius,i=e.borderStyle.verticalCornerRadius;if(t>0||i>0){const e=`calc(${t}px * var(--scale-factor)) / calc(${i}px * var(--scale-factor))`;o.borderRadius=e}else if(this instanceof Wi){const t=`calc(${r}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;o.borderRadius=t}switch(e.borderStyle.style){case G:o.borderStyle="solid";break;case X:o.borderStyle="dashed";break;case K:case Z:break;case q:o.borderBottomStyle="solid"}const s=e.borderColor||null;s?(I(this,He,!0,"f"),o.borderColor=n.Util.makeHexColor(0|s[0],0|s[1],0|s[2])):o.borderWidth=(0).toString()}const l=n.Util.normalizeRect([e.rect[0],i.view[3]-e.rect[1]+i.view[1],e.rect[2],i.view[3]-e.rect[3]+i.view[1]]),{pageWidth:d,pageHeight:c,pageX:u,pageY:f}=s.rawDims;o.left=100*(l[0]-u)/d+"%",o.top=100*(l[1]-f)/c+"%";const{rotation:p}=e;return e.hasOwnCanvas||0===p?(o.width=100*r/d+"%",o.height=100*h/c+"%"):this.setRotation(p,a),a}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:i,pageHeight:s}=this.parent.viewport.rawDims,{width:n,height:a}=Ci(this.data.rect);let o,r;t%180==0?(o=100*n/i,r=100*a/s):(o=100*a/i,r=100*n/s),e.style.width=`${o}%`,e.style.height=`${r}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(t,e,i)=>{const s=i.detail[t],n=s[0],a=s.slice(1);i.target.style[e]=Li[`${n}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[e]:Li[`${n}_rgb`](a)})};return n.shadow(this,"_commonActions",{display:t=>{const{display:e}=t.detail,i=e%2==1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:1===e||2===e})},print:t=>{this.annotationStorage.setValue(this.data.id,{noPrint:!t.detail.print})},hidden:t=>{const{hidden:e}=t.detail;this.container.style.visibility=e?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:e,noView:e})},focus:t=>{setTimeout((()=>t.target.focus({preventScroll:!1})),0)},userName:t=>{t.target.title=t.detail.userName},readonly:t=>{t.target.disabled=t.detail.readonly},required:t=>{this._setRequired(t.target,t.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:t=>{const e=t.detail.rotation;this.setRotation(e),this.annotationStorage.setValue(this.data.id,{rotation:e})}})}_dispatchEventFromSandbox(t,e){const i=this._commonActions;for(const s of Object.keys(e.detail)){const n=t[s]||i[s];null==n||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const i=this._commonActions;for(const[s,n]of Object.entries(e)){const a=i[s];if(a){a({detail:{[s]:n},target:t}),delete e[s]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,i,s,n]=this.data.rect.map((t=>Math.fround(t)));if(8===t.length){const[a,o,r,h]=t.subarray(2,6);if(s===a&&n===o&&e===r&&i===h)return}const{style:a}=this.container;let o;if(D(this,He,"f")){const{borderColor:t,borderWidth:e}=a;a.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${t}" stroke-width="${e}">`]}const r=s-e,h=n-i,{svgFactory:l}=this,d=l.createElement("svg");d.setAttribute("width",0),d.setAttribute("height",0);const c=l.createElement("defs");d.append(c);const u=l.createElement("clipPath"),f=`clippath_${this.data.id}`;u.setAttribute("id",f),u.setAttribute("clipPathUnits","objectBoundingBox"),c.append(u);for(let i=2,s=t.length;i<s;i+=8){const s=t[i],a=t[i+1],d=t[i+2],c=t[i+3],f=l.createElement("rect"),p=(d-e)/r,g=(n-a)/h,m=(s-d)/r,v=(a-c)/h;f.setAttribute("x",p),f.setAttribute("y",g),f.setAttribute("width",m),f.setAttribute("height",v),u.append(f),null==o||o.push(`<rect vector-effect="non-scaling-stroke" x="${p}" y="${g}" width="${m}" height="${v}"/>`)}D(this,He,"f")&&(o.push("</g></svg>')"),a.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${f})`}_createPopup(){}render(){}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const s=this._fieldObjects[t];if(s)for(const{page:t,id:n,exportValues:a}of s){if(-1===t)continue;if(n===e)continue;const s="string"==typeof a?a:null,o=document.querySelector(`[data-element-id="${n}"]`);o&&!_i.has(o)||i.push({id:n,exportValue:s,domElement:o})}return i}for(const s of document.getElementsByName(t)){const{exportValue:t}=s,n=s.getAttribute("data-element-id");n!==e&&(_i.has(s)&&i.push({id:n,exportValue:t,domElement:s}))}return i}show(){var t;this.container&&(this.container.hidden=!1),null===(t=this.popup)||void 0===t||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),null===(t=this.popup)||void 0===t||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();Array.isArray(t)}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",(()=>{var i,s;null===(s=null===(i=this.linkService)||void 0===i?void 0:i.eventBus)||void 0===s||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})}))}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}We=new WeakMap,He=new WeakMap,Be=new WeakMap,Oe=new WeakSet,Re=function(t){const{container:{style:e},data:{rect:i,rotation:s},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:a,pageX:o,pag