performance.mark("js-parse-end:97232-49462d987e3cc4b7.js"); "use strict";(globalThis.webpackChunk_github_ui_github_ui=globalThis.webpackChunk_github_ui_github_ui||[]).push([["97232"],{77683(e,t,r){r.r(t),r.d(t,{onUploadCompleted:()=>$,getPlaceholder:()=>v,cachePlaceholder:()=>w});var n=r(51729),i=r(71215),a=r(80795),l=r(54489),o=r(21403),s=r(21744),c=r(95754);let u=new WeakMap;class d{index;coords;textArea;constructor(e,t,r){this.index=e,this.coords=t,this.textArea=r}get top(){return this.coords.top}get left(){return this.coords.left}get height(){return this.coords.height}currentChar(e=1){return this.textArea.value.substring(this.index-e,this.index)}checkLine(e){return ethis.coords.top+this.coords.height)}xDistance(e){return Math.abs(this.left-e)}}function h(e,t){let r;if(u.has(e)?r=u.get(e):(r=new Map,u.set(e,r)),r.has(t))return r.get(t);{let n=new d(t,(0,c.A)(e,t),e);return r.set(t,n),n}}let g=(e,t,r,n,i,a)=>{if(r===t)return r;let l=e=>{let t=e.filter(e=>0===e.checkLine(i)).sort((e,t)=>e.xDistance(n)>t.xDistance(n)?1:-1);return 0===t.length?r:t[0].index};if(r-t==1)return l([h(e,t),h(e,r)]);if(r-t==2)return l([h(e,t),h(e,r-1),h(e,r)]);let o=Math.floor((r+t)/2);if(o===t||o===r)return o;let s=h(e,o);return i>s.top+s.height?g(e,o+1,r,n,i,a+1):is.xDistance(n)?o:s.leftn?0!==h(e,o-1).checkLine(i)?o:g(e,t,o-1,n,i,a+1):o};var p=r(56736);let f=new Map;(0,o.lB)(".js-paste-markdown",{initialize(e){let t,r=e.hasAttribute("data-paste-url-links-as-plain-text");return{add(){t=(0,i.B1)(e,{defaultPlainTextPaste:{urlLinks:r}}).unsubscribe},remove(){t()}}}});let m=new WeakMap;function w(e,t){m.set(e,t)}function v(e){return m.get(e)||T(e)}function b(e){return["video/mp4","video/quicktime"].includes(e.file.type)}function y(e){if(b(e))return` Uploading ${e.file.name}\u{2026} `;let t=e.isImage()||"image/webp"===e.file.type?"!":"";return`${t}[Uploading ${e.file.name}\u{2026}]()`}function x(e){let t=e.target.closest("form");if(t){let e=t.querySelector(".btn-primary");e&&(e.disabled=!0)}}function E(e){let t=e.target.closest("form");if(t){let e=t.querySelector(".btn-primary");e&&(e.disabled=!1)}}async function $(e){var t,r;let{attachment:i}=e.detail,a=e.currentTarget;A("",i.isImage()||"image/webp"===i.file.type?await k(i):b(i)?(t=i,` ${t.href} `):(r=i,`[${r.file.name}](${r.href})`),e,a),f.size>0&&function(){for(let e of document.querySelectorAll(".issue-form-textarea"))for(let[t,r]of f)e.value.includes(t)&&((0,n.ee)(e,t,r,document.activeElement===e),f.delete(t))}()}async function k(e){let t=await S(e.file),r=e.file.name.replace(/[[\]\\"<>&]/g,".").replace(/\.{2,}/g,".").replace(/^\.|\.$/gi,"").replace(/\.[^.]+$/,"").replace(/\./g," "),n=e.href||"";return(0,l.TG)(t,n,r)}async function S(e){let t=null;try{t=await (0,l.pF)(e)}catch{return{width:0,height:0,ppi:0}}return t||{width:0,height:0,ppi:0}}function T(e){let t=y(e);return b(e)?` ${t} `:`${t} `}function C(e){let t=e.currentTarget.querySelector(".js-comment-field"),r=v(e.detail.attachment);if(t)t.setCustomValidity(""),(0,n.ee)(t,r,"");else{let t=I(e.currentTarget);if(!t)return void(0,p.R)("upload:editor:change",e.currentTarget,{state:"failed",placeholder:r,replacementText:""});let n=t.getSearchCursor(r);n.findNext(),n.replace("")}}function A(e,t,r,i){let a=(i||r.currentTarget).querySelector(".js-comment-field"),l=(i||r.currentTarget).querySelector(".js-file-upload-loading-text"),o=y(r.detail.attachment),{batch:s}=r.detail;if(a){let i=a.value.substring(a.selectionStart,a.selectionEnd);if("uploading"===e){let e;e=i.length?(0,n.tJ)(a,i,o):(0,n.bc)(a,o,{appendNewline:!0}),m.set(r.detail.attachment,e)}else a.value.includes(o)||f.set(o,t),(0,n.ee)(a,o,t,document.activeElement===a);s.isFinished()?E(r):x(r)}else{let n=I(i||r.currentTarget);if(n)if("uploading"===e)if(n.getSelection().length)n.replaceSelection(o);else{let e=n.getCursor(),t=T(r.detail.attachment);n.replaceRange(t,e)}else{let e=n.getSearchCursor(o);e.findNext(),e.replace(t)}else(0,p.R)("upload:editor:change",i||r.currentTarget,{state:""===e?"uploaded":"uploading",placeholder:o,replacementText:""===e?t:T(r.detail.attachment)});s.isFinished()?E(r):x(r)}if(l){let e=l.getAttribute("data-file-upload-message");l.textContent=`${e} (${s.uploaded()+1}/${s.size})`}}function I(e){let t=e.querySelector(".js-code-editor");if(!t)return;let r=(0,a.j)(t);if(r)return r.editor}function j(e){e.stopPropagation();let t=e.currentTarget;if(!t)return;let r=t.querySelector(".js-comment-field");if(r){let t,n,i,a,l;t=r.getBoundingClientRect(),"dragenter"===e.type&&u.delete(r),n=e.clientX-t.left,i=e.clientY-t.top+r.scrollTop,a=r.value.length,l=g(r,0,a,n,i,0),r.setSelectionRange(l,l)}else{let r=I(t);if((0,p.R)("upload:editor:cursor",t,{left:e.clientX,top:e.clientY}),r){let t=r.coordsChar({left:e.pageX,top:e.pageY});r.setCursor(t),r.focus()}}}(0,s.on)("upload:setup",".js-upload-markdown-image",function(e){A("uploading","",e)}),(0,s.on)("upload:complete",".js-upload-markdown-image",$),(0,s.on)("upload:error",".js-upload-markdown-image",function(e){C(e);let{batch:t}=e.detail;t.isFinished()?E(e):x(e)}),(0,s.on)("dragenter","file-attachment",j),(0,s.on)("dragover","file-attachment",j),(0,s.on)("upload:invalid",".js-upload-markdown-image",function(e){C(e);let{batch:t}=e.detail;t.isFinished()?E(e):x(e)})},80795(e,t,r){r.d(t,{B:()=>l,j:()=>a});var n=r(21744);let i=new WeakMap;function a(e){return i.get(e)}async function l(e){var t,r;return i.get(e)||o(await (t=e,r="codeEditor:ready",new Promise(e=>{t.addEventListener(r,e,{once:!0})})))}function o(e){if(!(e instanceof CustomEvent))throw Error("assert: event is not a CustomEvent");let t=e.detail.editor;if(!e.target)throw Error("assert: event.target is null");return i.set(e.target,t),t}(0,n.on)("codeEditor:ready",".js-code-editor",o)},56736(e,t,r){r.d(t,{R:()=>n});function n(e,t,r){if(!t)return;let n=t.className.includes("cm-content")?t:t.querySelector(".cm-content");n&&n.dispatchEvent(new CustomEvent(e,{detail:r}))}},68396(e,t,r){r.d(t,{p:()=>i});class n{dataview;pos;constructor(e){this.dataview=new DataView(e),this.pos=0}advance(e){this.pos+=e}readInt(e){let t=(()=>{switch(e){case 1:return this.dataview.getUint8(this.pos);case 2:return this.dataview.getUint16(this.pos);case 4:return this.dataview.getUint32(this.pos);default:throw Error("bytes parameter must be 1, 2 or 4")}})();return this.advance(e),t}readChar(){return this.readInt(1)}readShort(){return this.readInt(2)}readLong(){return this.readInt(4)}readString(e){let t=new Uint8Array(this.dataview.buffer,this.pos,e);return this.advance(e),new TextDecoder("ascii").decode(t)}scan(e){let t=[137,80,78,71,13,10,26,10];for(let e=0;e{let t,r,i=await new Promise((t,r)=>{let n=new FileReader;n.onload=()=>t(n.result),n.onerror=()=>r(n.error),n.readAsArrayBuffer(e)});return i?(t=new n(i),r={width:0,height:0,pixelsPerInch:72},t.scan(function(e){switch(e){case"IHDR":r.width=this.readLong(),r.height=this.readLong();break;case"pHYs":{let e=this.readLong(),t=this.readLong();return 1===this.readChar()&&(r.pixelsPerInch=Math.round((e+t)/2*.0254)),!1}case"IDAT":return!1}return!0}),r):null}},54489(e,t,r){r.d(t,{TG:()=>d,VL:()=>s,iQ:()=>o,nf:()=>l,pF:()=>c,ty:()=>a});var n=r(63429),i=r(68396);let a=e=>{let t=e.value.lastIndexOf("\n",e.selectionStart-1)+1,r=e.value.indexOf("\n",e.selectionEnd);return -1===r&&(r=e.value.length),[t,r]},l=e=>``,o=(e,t)=>`[${e.replaceAll("[","\\[").replaceAll("]","\\]")}](${t.replaceAll("(","\\(").replaceAll(")","\\)")})`,s=e=>(0,n.U0)()?e.metaKey:e.ctrlKey,c=async e=>{let t=await (0,i.p)(e);return t?{width:t.width,height:t.height,ppi:t.pixelsPerInch}:null},u=e=>e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),d=(e,t,r="Image")=>{let n=u(r),i=u(t);if(144===e.ppi){let t=Math.round(e.width/2),r=Math.round(e.height/2);return`${n}`}return e&&e.width>0&&e.height>0?`${n}`:`![${n}](${i})`}},51729(e,t,r){function n(e){let t=e.split("\u200D"),r=0;for(let e of t)r+=Array.from(e.split(/[\ufe00-\ufe0f]/).join("")).length;return r/t.length}function i(e,t,r,n=!0){let a=e.value.substring(0,e.selectionEnd||0),l=e.value.substring(e.selectionEnd||0);return o(e,(a=a.replace(t,r))+(l=l.replace(t,r)),a.length,n),r}function a(e,t,r){if(null===e.selectionStart||null===e.selectionEnd)return i(e,t,r);let n=e.value.substring(0,e.selectionStart),a=e.value.substring(e.selectionEnd);return o(e,n+r+a,n.length),r}function l(e,t,r={}){let n=e.selectionEnd||0,i=e.value.substring(0,n),a=e.value.substring(n),o=(""===e.value||i.match(/\n$/)?"":"\n")+t+(r.appendNewline?"\n":"");e.value=i+o+a;let s=n+o.length;return e.selectionStart=s,e.selectionEnd=s,e.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1})),e.focus(),o}function o(e,t,r,n=!0){e.value=t,n&&(e.selectionStart=r,e.selectionEnd=r),e.dispatchEvent(new CustomEvent("change",{bubbles:!0,cancelable:!1}))}function s(e,t){let r=[...e],n=new TextEncoder,i=new Uint8Array(4);for(let e=0;e=t))break}return t}r.d(t,{bV:()=>n,bc:()=>l,ee:()=>i,kN:()=>s,tJ:()=>a})}}]); //# sourceMappingURL=97232-49462d987e3cc4b7-e43b86e5b77417fd.js.map