3 lines
22 KiB
JavaScript
Raw Permalink Normal View History

var S=class{static getCaretCoordinates(e,t,r){var p,x;if(!O)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");let n=(p=r==null?void 0:r.debug)!=null?p:!1;if(n){let h=document.querySelector("#input-textarea-caret-position-mirror-div");h&&((x=h.parentNode)==null||x.removeChild(h))}let i=document.createElement("div");i.id="input-textarea-caret-position-mirror-div",document.body.appendChild(i);let o=i.style,s=window.getComputedStyle?window.getComputedStyle(e):e.currentStyle,a=e.nodeName==="INPUT";o.whiteSpace="pre-wrap",a||(o.wordWrap="break-word"),o.position="absolute",n||(o.visibility="hidden"),F.forEach(h=>{if(a&&h==="lineHeight")if(s.boxSizing==="border-box"){let T=parseInt(s.height),W=parseInt(s.paddingTop)+parseInt(s.paddingBottom)+parseInt(s.borderTopWidth)+parseInt(s.borderBottomWidth),I=W+parseInt(s.lineHeight);T>I?o.lineHeight=`${T-W}px`:T===I?o.lineHeight=s.lineHeight:o.lineHeight="0"}else o.lineHeight=s.height;else o[h]=s[h]}),R?e.scrollHeight>parseInt(s.height)&&(o.overflowY="scroll"):o.overflow="hidden",i.textContent=e.value.substring(0,t),a&&(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 n?d.style.backgroundColor="#aaa":document.body.removeChild(i),u}},F=["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"],O=typeof window!="undefined",R=O&&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 G(){let c=await globalThis.getDotnetRuntime(0);if(c!=null)return l.resolvedExports=await c.getAssemblyExports("Avalonia.Browser.dll"),l.resolvedExports}l.exportsPromise=G();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,r)=>{this.clipboardState=2,this.resolveClipboard=t,this.rejectClipboard=r})}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 r=this.subscribeKeyEvents(e,t),n=this.subscribePointerEvents(e,t),i=this.subscribeTextEvents(e,t),o=this.subscribeDropEvents(e,t),s=this.subscribeKeyboardGeometryChange(e,t);return()=>{r(),n(),i(),o(),s()}}static subscribeKeyEvents(e,t){let r=i=>{l.InputHelper.OnKeyDown(t,i.code,i.key,this.getModifiers(i)),this.clipboardState!==2&&i.preventDefault()};e.addEventListener("keydown",r);let n=i=>{l.InputHelper.OnKeyUp(t,i.code,i.key,this.getModifiers(i)),i.preventDefault(),this.rejectClipboard&&this.rejectClipboard()};return e.addEventListener("keyup",n),()=>{e.removeEventListener("keydown",r),e.removeEventListener("keyup",n)}}static subscribeTextEvents(e,t){let r=s=>{l.InputHelper.OnCompositionStart(t)};e.addEventListener("compositionstart",r);let n=s=>{let a=s.getTargetRanges(),d=-1,u=-1;a.length>0&&(d=a[0].startOffset,u=a
//# sourceMappingURL=avalonia.js.map