/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
'use strict';var e=require("prismjs");require("prismjs/components/prism-clike");require("prismjs/components/prism-javascript");require("prismjs/components/prism-markup");require("prismjs/components/prism-markdown");require("prismjs/components/prism-c");require("prismjs/components/prism-css");require("prismjs/components/prism-objectivec");require("prismjs/components/prism-sql");require("prismjs/components/prism-python");require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");
require("prismjs/components/prism-typescript");var n=require("@lexical/utils"),u=require("lexical");let v={c:"C",clike:"C-like",css:"CSS",html:"HTML",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},x={javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function y(a){return x[a]||a}
class z extends u.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new z(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}createDOM(a){let b=super.createDOM(a);a=A(a.theme,this.__highlightType);n.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let d=super.updateDOM(a,b,c);a=A(c.theme,a.__highlightType);c=A(c.theme,this.__highlightType);a!==c&&(a&&n.removeClassNamesFromElement(b,
a),c&&n.addClassNamesToElement(b,c));return d}static importJSON(a){let b=B(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(){return this}}function A(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}function B(a,b){return u.$applyNodeReplacement(new z(a,b))}function C(a){return a instanceof z}
function D(a){let b=null,c=a.getPreviousSiblings();for(c.push(a);0<c.length&&(a=c.pop(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}function E(a){let b=null,c=a.getNextSiblings();for(c.unshift(a);0<c.length&&(a=c.shift(),C(a)&&(b=a),!u.$isLineBreakNode(a)););return b}let F=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;function G(a,b){for(let c of a.childNodes){if(c instanceof HTMLElement&&c.tagName===b)return!0;G(c,b)}return!1}
class H extends u.ElementNode{static getType(){return"code"}static clone(a){return new H(a.__language,a.__key)}constructor(a,b){super(b);this.__language=F(a)}createDOM(a){let b=document.createElement("code");n.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");(a=this.getLanguage())&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language;a=a.__language;c?c!==a&&b.setAttribute("data-highlight-language",c):a&&b.removeAttribute("data-highlight-language");
return!1}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||G(a,"BR"))?{conversion:I,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:I,priority:0}),table:a=>J(a)?{conversion:ba,priority:4}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")?{conversion:ca,priority:4}:b&&J(b)?{conversion:K,priority:4}:null},tr:a=>(a=a.closest("table"))&&J(a)?{conversion:K,priority:4}:null}}static importJSON(a){let b=L(a.language);
b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(a,b=!0){var c=this.getChildren(),d=c.length;if(2<=d&&"\n"===c[d-1].getTextContent()&&"\n"===c[d-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===d)return c[d-1].remove(),c[d-2].remove(),a=u.$createParagraphNode(),this.insertAfter(a,b),a;b=a.anchor.getNode();d=D(b);if(null!=d){c=
0;for(d=d.getTextContent();c<d.length&&/[\t ]/.test(d[c]);)c+=1;if(0<c)return c=d.substring(0,c),c=B(c),b.insertAfter(c),a.insertNodes([u.$createLineBreakNode()]),c.select(),c}return null}canInsertTab(){let a=u.$getSelection();return u.$isRangeSelection(a)&&a.isCollapsed()?!0:!1}canIndent(){return!1}collapseAtStart(){let a=u.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=F(a)}getLanguage(){return this.getLatest().__language}}
function L(a){return u.$applyNodeReplacement(new H(a))}function M(a){return a instanceof H}function I(){return{node:L(),preformatted:!0}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");return b||da(a)?{after:c=>{let d=a.parentNode;null!=d&&a!==d.lastChild&&c.push(u.$createLineBreakNode());return c},node:b?L():null,preformatted:b}:{node:null}}function ba(){return{node:L(),preformatted:!0}}function K(){return{node:null}}
function ca(a){return{after:b=>{a.parentNode&&a.parentNode.nextSibling&&b.push(u.$createLineBreakNode());return b},node:null}}function da(a){for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace"))return!0;a=a.parentElement}return!1}function J(a){return a.classList.contains("js-file-line-container")}let N={defaultLanguage:"javascript",tokenize(a,b){return e.tokenize(a,e.languages[b||""]||e.languages[this.defaultLanguage])}};
function O(a,b){var c=a.length;let d=-1;if(b)for(b=0;b<c;b++){let f=a[b];if(" "!==f&&"\t"!==f){d=b;break}}else for(--c;-1<c;c--)if(b=a[c]," "!==b&&"\t"!==b){d=c;break}return d}
function P(a){let b=null,c=-1;var d=a.getPreviousSiblings();for(d.push(a);0<d.length;){var f=d.pop();if(C(f)){var g=f.getTextContent();g=O(g,!0);-1!==g&&(b=f,c=g)}if(u.$isLineBreakNode(f))break}if(null===b)for(a=a.getNextSiblings();0<a.length;){d=a.shift();if(C(d)&&(f=d.getTextContent(),f=O(f,!0),-1!==f)){b=d;c=f;break}if(u.$isLineBreakNode(d))break}return{node:b,offset:c}}
function Q(a){let b=null,c=-1;var d=a.getNextSiblings();for(d.unshift(a);0<d.length;){var f=d.shift();if(C(f)){var g=f.getTextContent();g=O(g,!1);-1!==g&&(b=f,c=g+1)}if(u.$isLineBreakNode(f))break}if(null===b)for(a=a.getPreviousSiblings();0<a.length;){d=a.pop();if(C(d)&&(f=d.getTextContent(),f=O(f,!1),-1!==f)){b=d;c=f+1;break}if(u.$isLineBreakNode(d))break}return{node:b,offset:c}}function R(a,b,c){let d=a.getParent();M(d)?S(d,b,c):C(a)&&a.replace(u.$createTextNode(a.__text))}let T=new Set;
function S(a,b,c){let d=a.getKey();T.has(d)||(T.add(d),void 0===a.getLanguage()&&a.setLanguage(c.defaultLanguage),b.update(()=>{ea(d,()=>{var f=u.$getNodeByKey(d);if(!M(f)||!f.isAttached())return!1;var g=f.getTextContent();g=c.tokenize(g,f.getLanguage()||c.defaultLanguage);g=U(g);var k=f.getChildren();for(f=0;f<k.length&&V(k[f],g[f]);)f++;var h=k.length;let l=g.length,p=Math.min(h,l)-f,m=0;for(;m<p;)if(m++,!V(k[h-m],g[l-m])){m--;break}k=f;h-=m;g=g.slice(f,l-m);let {from:w,to:t,nodesForReplacement:r}=
{from:k,nodesForReplacement:g,to:h};return w!==t||r.length?(a.splice(w,t-w,r),!0):!1})},{onUpdate:()=>{T.delete(d)},skipTransforms:!0}))}
function U(a){let b=[];a.forEach(c=>{if("string"===typeof c){c=c.split("\n");for(var d=0;d<c.length;d++){let f=c[d];f.length&&b.push(B(f));d<c.length-1&&b.push(u.$createLineBreakNode())}}else({content:d}=c),"string"===typeof d?b.push(B(d,c.type)):Array.isArray(d)&&1===d.length&&"string"===typeof d[0]?b.push(B(d[0],c.type)):Array.isArray(d)&&b.push(...U(d))});return b}
function ea(a,b){a=u.$getNodeByKey(a);if(M(a)&&a.isAttached()){var c=u.$getSelection();if(u.$isRangeSelection(c)){c=c.anchor;var d=c.offset,f="element"===c.type&&u.$isLineBreakNode(a.getChildAtIndex(c.offset-1)),g=0;if(!f){let k=c.getNode();g=d+k.getPreviousSiblings().reduce((h,l)=>h+l.getTextContentSize(),0)}b()&&(f?c.getNode().select(d,d):a.getChildren().some(k=>{let h=u.$isTextNode(k);if(h||u.$isLineBreakNode(k)){let l=k.getTextContentSize();if(h&&l>=g)return k.select(g,g),!0;g-=l}return!1}))}else b()}}
function V(a,b){return C(a)&&C(b)?a.__text===b.__text&&a.__highlightType===b.__highlightType:u.$isLineBreakNode(a)&&u.$isLineBreakNode(b)?!0:!1}function W(a){var b=u.$getSelection();if(!u.$isRangeSelection(b)||b.isCollapsed())return!1;b=b.getNodes();for(var c=0;c<b.length;c++){var d=b[c];if(!C(d)&&!u.$isLineBreakNode(d))return!1}c=D(b[0]);null!=c&&X(c,a);for(c=1;c<b.length;c++)d=b[c],u.$isLineBreakNode(b[c-1])&&C(d)&&X(d,a);return!0}
function X(a,b){let c=a.getTextContent();b===u.INDENT_CONTENT_COMMAND?0<c.length&&/\s/.test(c[0])?a.setTextContent("\t"+c):(b=B("\t"),a.insertBefore(b)):0===c.indexOf("\t")&&(1===c.length?a.remove():a.setTextContent(c.substring(1)))}
function Y(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.offset,k=f.offset,h=d.getNode(),l=f.getNode();var p=a===u.KEY_ARROW_UP_COMMAND;if(!C(h)||!C(l))return!1;if(!b.altKey){if(c.isCollapsed())if(a=h.getParentOrThrow(),p&&0===g&&null===h.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!p&&g===h.getTextContentSize()&&null===h.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
b.preventDefault(),!0;return!1}var m=D(h);let w=E(l);if(null==m||null==w)return!1;let t=m.getNodesBetween(w);for(let q=0;q<t.length;q++){let Z=t[q];if(!C(Z)&&!u.$isLineBreakNode(Z))return!1}b.preventDefault();b.stopPropagation();b=p?m.getPreviousSibling():w.getNextSibling();if(!u.$isLineBreakNode(b))return!0;m=p?b.getPreviousSibling():b.getNextSibling();if(null==m)return!0;p=p?D(m):E(m);let r=null!=p?p:m;b.remove();t.forEach(q=>q.remove());a===u.KEY_ARROW_UP_COMMAND?(t.forEach(q=>r.insertBefore(q)),
r.insertBefore(b)):(r.insertAfter(b),r=b,t.forEach(q=>{r.insertAfter(q);r=q}));c.setTextNodeRange(h,g,l,k);return!0}function fa(a,b){let c=u.$getSelection();if(!u.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.getNode(),k=f.getNode();a=a===u.MOVE_TO_START;if(!C(g)||!C(k))return!1;let h,l;a?{node:h,offset:l}=P(k):{node:h,offset:l}=Q(k);null!==h&&-1!==l&&c.setTextNodeRange(h,l,h,l);b.preventDefault();b.stopPropagation();return!0}exports.$createCodeHighlightNode=B;
exports.$createCodeNode=L;exports.$isCodeHighlightNode=C;exports.$isCodeNode=M;exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=v;exports.CODE_LANGUAGE_MAP=x;exports.CodeHighlightNode=z;exports.CodeNode=H;exports.DEFAULT_CODE_LANGUAGE="javascript";exports.PrismTokenizer=N;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=Q;exports.getFirstCodeHighlightNodeOfLine=D;
exports.getLanguageFriendlyName=function(a){a=y(a);return v[a]||a};exports.getLastCodeHighlightNodeOfLine=E;exports.getStartOfCodeInLine=P;exports.normalizeCodeLang=y;
exports.registerCodeHighlighting=function(a,b){if(!a.hasNodes([H,z]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==b&&(b=N);return n.mergeRegister(a.registerMutationListener(H,c=>{a.update(()=>{for(let [g,k]of c)if("destroyed"!==k){var d=u.$getNodeByKey(g);if(null!==d)a:{var f=d;d=a.getElementByKey(f.getKey());if(null===d)break a;f=f.getChildren();let h=f.length;if(h===d.__cachedChildrenLength)break a;d.__cachedChildrenLength=h;let l="1",p=1;for(let m=
0;m<h;m++)u.$isLineBreakNode(f[m])&&(l+="\n"+ ++p);d.setAttribute("data-gutter",l)}}})}),a.registerNodeTransform(H,c=>S(c,a,b)),a.registerNodeTransform(u.TextNode,c=>R(c,a,b)),a.registerNodeTransform(z,c=>R(c,a,b)),a.registerCommand(u.INDENT_CONTENT_COMMAND,()=>W(u.INDENT_CONTENT_COMMAND),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.OUTDENT_CONTENT_COMMAND,()=>W(u.OUTDENT_CONTENT_COMMAND),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.KEY_ARROW_UP_COMMAND,c=>Y(u.KEY_ARROW_UP_COMMAND,c),u.COMMAND_PRIORITY_LOW),
a.registerCommand(u.KEY_ARROW_DOWN_COMMAND,c=>Y(u.KEY_ARROW_DOWN_COMMAND,c),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.MOVE_TO_END,c=>fa(u.MOVE_TO_END,c),u.COMMAND_PRIORITY_LOW),a.registerCommand(u.MOVE_TO_START,c=>fa(u.MOVE_TO_START,c),u.COMMAND_PRIORITY_LOW))}
