Module 2368

5,743 characters · in no known chunk
Dependencies
Required by (2)
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{Ay:()=>p,eF:()=>T,lE:()=>S}),n(321073);var i=n(284009),r=n.n(i),a=n(155718),s=n(861382),l=n(224868),o=n(186306),d=n(22098),c=n(323350),u=n(35277),_=n(820066);let E=/(@[^@#]+(?:#0|#\d{4}))|(@[^\s\t@#:]+)(?=[\s\t@:])|(:[a-zA-Z0-9_~]+:)|(#"(?:\ |\\\\|\\"|(?!")\w)+")|(#[^\s\t@#:]+(?=[\s\t@#:]))/g,A=new Set(["emoji","customEmoji","textMention","userMention","roleMention","channelMention","staticRouteLink","soundboard","timestamp","gameMention"]),h=new Set(["gameMentionInput","timestampMentionInput"]),I=new Set(["line","blockQuote"]),f=new Set(["applicationCommandOption"]);function p(e,t,n){let{isInline:i,isVoid:r,onChange:a}=e;e.isVoid=e=>!!A.has(e.type)||r(e),e.isInline=e=>!!(A.has(e.type)||h.has(e.type))||i(e);let s=null,l=!0;return e.onChange=()=>{let i=_.VW.richValue(e);(i!==s||e.previewMarkdown!==l)&&(o.o.withMergedEntry(e,()=>{_.VW.withoutNormalizing(e,()=>T(e,t,n))}),s=i,l=e.previewMarkdown),a()},e}function T(e,t,n){let i=_.VW.areStylesDisabled(e);for(let r of _.VW.blocks(e))if(I.has(r[0].type))i?g(e,r,!0,null):m(e,r,t,n);else{let[a,s]=r;for(let r=a.children.length-1;r>=0;r--){let l=a.children[r];if(!_.l5.isText(l)&&f.has(l.type)){let a=[l,_.PW.child(s,r)];i?g(e,a,!0,null):m(e,a,t,n)}}}}function m(e,t,n,i){let a="line"===t[0].type&&t[0].codeBlockState?.isInCodeBlock===!0,s=_.cv.markdown(t[0],n);g(e,t,a,s)&&(t=_.cv.updateElement(e,t),s=_.cv.markdown(t[0],n)),a||(S(e,t,i,s)&&(t=_.cv.updateElement(e,t),s=_.cv.markdown(t[0],n)),function(e,t,n,i,a){let[s,o]=t,d=C(e,o);for(let c=s.children.length-1;c>=0;c--){let A,h=s.children[c];if(!_.l5.isText(h))continue;let I=_.PW.child(o,c),f=[];for(E.lastIndex=0;null!=(A=E.exec(h.text));){if(0!==A.index&&null==h.text.charAt(A.index-1).match(/(\t|\s)/)){E.lastIndex=A.index+1;continue}if(R(d,{path:I,offset:A.index},a))continue;let e=(0,l.p)(A[0],n,i);null!=e&&O(i,t[0],e)?f.push({index:A.index,length:A[0].length,node:e}):E.lastIndex=A.index+1}for(let t of f.reverse())(function(e,t,n,i,a){let[s,l]=t,o={path:l,offset:n},d={path:l,offset:n+i};r()(o.offset>=0&&o.offset<=s.text.length,"Failed to find valid start position for raw mention replace"),r()(d.offset>=0&&d.offset<=s.text.length,"Failed to find valid end position for raw mention replace"),u.b.textToVoid(e,a,{anchor:o,focus:d})})(e,[h,_.PW.child(o,c)],t.index,t.length,t.node)}}(e,t,n,i,s))}function g(e,t,n,i){let[r,a]=t,s=!1,l=n||null==i?null:C(e,a);for(let t=r.children.length-1;t>=0;t--){let o=r.children[t];if(_.l5.isText(o)&&!n){let n=t<r.children.length-1?r.children[t+1]:null;if(null==n||!_.cv.isElement(n)||!e.isVoid(n))continue;let i=!1,l=0;for(;;){let e=o.text.indexOf("\\",l);if(-1===e)break;if(e===o.text.length-1){i=!0;break}l=e+2}if(i){let i=_.PW.child(a,t+1);u.b.voidToText(e,(0,c.IQ)(n,{mode:"plain",preventEmojiSurrogates:!0}),i),s=!0}}else if(_.cv.isElement(o)&&e.isVoid(o)){let r=_.PW.child(a,t),d={path:_.PW.child(r,0),offset:0};(n||null!=i&&R(l,d,i))&&(u.b.voidToText(e,(0,c.IQ)(o,{mode:"plain",preventEmojiSurrogates:!0}),r),s=!0)}}return s}function S(e,t,n,i){let r=t[1],a=!1,s=[...i.entries].reverse();for(let l=0;l<s.length;l++){let o,c=s[l],_=s[l+1];if(null!=_&&_.text.endsWith("\\")&&c.start===_.start+_.text.length)continue;switch(c.attributes[0]){case"emoji":o={type:"emoji",emoji:{name:c.data.name,src:c.data.src,surrogate:c.data.surrogate,jumboable:!0===c.data.jumboable},children:[{text:""}]};break;case"customEmoji":o={type:"customEmoji",emoji:{emojiId:c.data.emojiId,name:c.data.name,animated:c.data.animated,jumboable:!0===c.data.jumboable},children:[{text:""}]};break;case"textMention":o={type:"textMention",name:c.data.text,children:[{text:""}]};break;case"mention":o={type:"userMention",userId:c.data.id,children:[{text:""}]};break;case"roleMention":o={type:"roleMention",roleId:c.data.id,children:[{text:""}]};break;case"channelMention":o={type:"channelMention",channelId:c.data.id,children:[{text:""}]};break;case"staticRouteLink":o={type:"staticRouteLink",id:c.data.id,itemId:c.data.itemId,children:[{text:""}]};break;case"soundboard":o={type:"soundboard",guildId:c.data.guildId,soundId:c.data.soundId,children:[{text:""}]};break;case"timestamp":o={type:"timestamp",parsed:c.data,children:[{text:""}]};break;case"gameMention":{let t=c.data.id,n=e.mentionGames.get(t);o={type:"gameMention",gameId:t,gameName:n?.name,gameIcon:n?.icon,children:[{text:""}]};break}case"timestampMentionInput":o={type:"timestampMentionInput",children:[{text:c.data.content}]};break;default:continue}if(!O(n,t[0],o))continue;let E=(0,d.Q)(e,r,i.serializedChildren,c.start),A=(0,d.Q)(e,r,i.serializedChildren,c.start+c.text.length);u.b.textToVoid(e,o,{anchor:E,focus:A}),a=!0}return a}function N(e){return e.join(",")}function C(e,t){let n=new Map,i=_.VW.nodes(e,{at:{anchor:_.VW.start(e,t),focus:_.VW.end(e,t)},mode:"lowest"}),r=0;for(let[e,t]of i)n.set(N(t),r),r+=_.l5.isText(e)?e.text.length:1;return n}function R(e,t,n){if(null==e)return!1;let i=e.get(N(t.path));if(null!=i)i+=t.offset;else{let n=e.get(N(_.PW.parent(t.path)));if(null==n)return!1;i=n+1}for(let e of n.entries){if(!e.attributes.includes("codeBlockText")&&!e.attributes.includes("inlineCode"))continue;let t=e.start,n=e.start+e.text.length;if(t<=i&&n>=i)return!0}return!1}function O(e,t,n){if("applicationCommandOption"!==t.type)return!0;switch(t.optionType){case a.n4.CHANNEL:return"channelMention"===n.type;case a.n4.ROLE:return"roleMention"===n.type||"textMention"===n.type&&"@everyone"===n.name;case a.n4.USER:return"userMention"===n.type;case a.n4.MENTIONABLE:return"roleMention"===n.type||"userMention"===n.type||"textMention"===n.type&&"@everyone"===n.name;case a.n4.STRING:{let n=null!=e?s.A.getOption(e,t.optionName):null;return n?.choices==null&&n?.autocomplete!==!0}default:return!1}}}