3 lines
20 KiB
JavaScript
Raw Normal View History

var H=class{static getCaretCoordinates(e,t,n){var p,x;if(!I)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");let r=(p=n==null?void 0:n.debug)!=null?p:!1;if(r){let v=document.querySelector("#input-textarea-caret-position-mirror-div");v&&((x=v.parentNode)==null||x.removeChild(v))}let i=document.createElement("div");i.id="input-textarea-caret-position-mirror-div",document.body.appendChild(i);let a=i.style,s=window.getComputedStyle?window.getComputedStyle(e):e.currentStyle,o=e.nodeName==="INPUT";a.whiteSpace="pre-wrap",o||(a.wordWrap="break-word"),a.position="absolute",r||(a.visibility="hidden"),O.forEach(v=>{if(o&&v==="lineHeight")if(s.boxSizing==="border-box"){let S=parseInt(s.height),D=parseInt(s.paddingTop)+parseInt(s.paddingBottom)+parseInt(s.borderTopWidth)+parseInt(s.borderBottomWidth),W=D+parseInt(s.lineHeight);S>W?a.lineHeight=`${S-D}px`:S===W?a.lineHeight=s.lineHeight:a.lineHeight="0"}else a.lineHeight=s.height;else a[v]=s[v]}),F?e.scrollHeight>parseInt(s.height)&&(a.overflowY="scroll"):a.overflow="hidden",i.textContent=e.value.substring(0,t),o&&(i.textContent=i.textContent.replace(/\s/g,"\xA0"));let d=document.createElement("span");d.textContent=e.value.substring(t)||".",i.appendChild(d);let u={top:d.offsetTop+parseInt(s.borderTopWidth),left:d.offsetLeft+parseInt(s.borderLeftWidth),height:parseInt(s.lineHeight)};return r?d.style.backgroundColor="#aaa":document.body.removeChild(i),u}},O=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],I=typeof window!="undefined",F=I&&window.mozInnerScreenX!=null;var l=class{static get InputHelper(){var e;return(e=this.resolvedExports)==null?void 0:e.Avalonia.Browser.Interop.InputHelper}static get DomHelper(){var e;return(e=this.resolvedExports)==null?void 0:e.Avalonia.Browser.Interop.DomHelper}static get TimerHelper(){var e;return(e=this.resolvedExports)==null?void 0:e.Avalonia.Browser.Interop.TimerHelper}static get CanvasHelper(){var e;return(e=this.resolvedExports)==null?void 0:e.Avalonia.Browser.Interop.CanvasHelper}};async function R(){let c=await globalThis.getDotnetRuntime(0);if(c!=null)return l.resolvedExports=await c.getAssemblyExports("Avalonia.Browser.dll"),l.resolvedExports}l.exportsPromise=R();var L=class{static initializeBackgroundHandlers(){this.clipboardState===0&&(globalThis.addEventListener("paste",e=>{this.clipboardState===2&&this.resolveClipboard(e.clipboardData.getData("text"))}),this.clipboardState=1)}static async readClipboardText(e){if(e.navigator.clipboard.readText)return await e.navigator.clipboard.readText();try{return await new Promise((t,n)=>{this.clipboardState=2,this.resolveClipboard=t,this.rejectClipboard=n})}finally{this.clipboardState=1,this.resolveClipboard=null,this.rejectClipboard=null}}static async writeClipboardText(e,t){return await e.navigator.clipboard.writeText(t)}static subscribeInputEvents(e,t){let n=this.subscribeKeyEvents(e,t),r=this.subscribePointerEvents(e,t),i=this.subscribeTextEvents(e,t),a=this.subscribeDropEvents(e,t),s=this.subscribeKeyboardGeometryChange(e,t);return()=>{n(),r(),i(),a(),s()}}static subscribeKeyEvents(e,t){let n=i=>{l.InputHelper.OnKeyDown(t,i.code,i.key,this.getModifiers(i)),this.clipboardState!==2&&i.preventDefault()};e.addEventListener("keydown",n);let r=i=>{l.InputHelper.OnKeyUp(t,i.code,i.key,this.getModifiers(i)),i.preventDefault(),this.rejectClipboard&&this.rejectClipboard()};return e.addEventListener("keyup",r),()=>{e.removeEventListener("keydown",n),e.removeEventListener("keyup",r)}}static subscribeTextEvents(e,t){let n=s=>{l.InputHelper.OnCompositionStart(t)};e.addEventListener("compositionstart",n);let r=s=>{let o=s.getTargetRanges(),d=-1,u=-1;o.length>0&&(d=o[0].startOffset,u=o
//# sourceMappingURL=avalonia.js.map