"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../../../devlop@1.1.0/node_modules/devlop/lib/default.cjs.js"),x=require("../../../../longest-streak@3.1.0/node_modules/longest-streak/index.cjs.js");function M(){return{enter:{mathFlow:d,mathFlowFenceMeta:o,mathText:h},exit:{mathFlow:p,mathFlowFence:l,mathFlowFenceMeta:f,mathFlowValue:n,mathText:w,mathTextData:n}};function d(t){const e={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[e]}},t)}function o(){this.buffer()}function f(){const t=this.resume(),e=this.stack[this.stack.length-1];s.ok(e.type==="math"),e.meta=t}function l(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function p(t){const e=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),a=this.stack[this.stack.length-1];s.ok(a.type==="math"),this.exit(t),a.value=e;const i=a.data.hChildren[0];s.ok(i.type==="element"),s.ok(i.tagName==="code"),i.children.push({type:"text",value:e}),this.data.mathFlowInside=void 0}function h(t){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},t),this.buffer()}function w(t){const e=this.resume(),a=this.stack[this.stack.length-1];s.ok(a.type==="inlineMath"),this.exit(t),a.value=e,a.data.hChildren.push({type:"text",value:e})}function n(t){this.config.enter.data.call(this,t),this.config.exit.data.call(this,t)}}function F(d){let o=(d||{}).singleDollarTextMath;return o==null&&(o=!0),l.peek=p,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
`,inConstruct:"mathFlowMeta"},{character:"$",after:o?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:f,inlineMath:l}};function f(h,w,n,t){const e=h.value||"",a=n.createTracker(t),i="$".repeat(Math.max(x.longestStreak(e,"$")+1,2)),u=n.enter("mathFlow");let r=a.move(i);if(h.meta){const c=n.enter("mathFlowMeta");r+=a.move(n.safe(h.meta,{after:`
`,before:r,encode:["$"],...a.current()})),c()}return r+=a.move(`
`),e&&(r+=a.move(e+`
`)),r+=a.move(i),u(),r}function l(h,w,n){let t=h.value||"",e=1;for(o||e++;new RegExp("(^|[^$])"+"\\$".repeat(e)+"([^$]|$)").test(t);)e++;const a="$".repeat(e);/[^ \r\n]/.test(t)&&(/^[ \r\n]/.test(t)&&/[ \r\n]$/.test(t)||/^\$|\$$/.test(t))&&(t=" "+t+" ");let i=-1;for(;++i<n.unsafe.length;){const u=n.unsafe[i];if(!u.atBreak)continue;const r=n.compilePattern(u);let c;for(;c=r.exec(t);){let m=c.index;t.codePointAt(m)===10&&t.codePointAt(m-1)===13&&m--,t=t.slice(0,m)+" "+t.slice(c.index+1)}}return a+t+a}function p(){return"$"}}exports.mathFromMarkdown=M;exports.mathToMarkdown=F;
//# sourceMappingURL=index.cjs.js.map
