/* esm.sh - micromark-extension-math@3.1.0 */
import{factorySpace as y}from"../../micromark-factory-space@^2.0.0?target=es2022";import{markdownLineEnding as T}from"../../micromark-util-character@^2.0.0?target=es2022";var D={tokenize:P,concrete:!0,name:"mathFlow"},k={tokenize:I,partial:!0};function P(t,u,a){let r=this,e=r.events[r.events.length-1],m=e&&e[1].type==="linePrefix"?e[2].sliceSerialize(e[1],!0).length:0,l=0;return z;function z(n){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),p(n)}function p(n){return n===36?(t.consume(n),l++,p):l<2?a(n):(t.exit("mathFlowFenceSequence"),y(t,x,"whitespace")(n))}function x(n){return n===null||T(n)?S(n):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),F(n))}function F(n){return n===null||T(n)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),S(n)):n===36?a(n):(t.consume(n),F)}function S(n){return t.exit("mathFlowFence"),r.interrupt?u(n):t.attempt(k,w,i)(n)}function w(n){return t.attempt({tokenize:f,partial:!0},i,s)(n)}function s(n){return(m?y(t,o,"linePrefix",m+1):o)(n)}function o(n){return n===null?i(n):T(n)?t.attempt(k,w,i)(n):(t.enter("mathFlowValue"),g(n))}function g(n){return n===null||T(n)?(t.exit("mathFlowValue"),o(n)):(t.consume(n),g)}function i(n){return t.exit("mathFlow"),u(n)}function f(n,O,c){let E=0;return y(n,M,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function M(h){return n.enter("mathFlowFence"),n.enter("mathFlowFenceSequence"),q(h)}function q(h){return h===36?(E++,n.consume(h),q):E<l?c(h):(n.exit("mathFlowFenceSequence"),y(n,L,"whitespace")(h))}function L(h){return h===null||T(h)?(n.exit("mathFlowFence"),O(h)):c(h)}}}function I(t,u,a){let r=this;return e;function e(l){return l===null?u(l):(t.enter("lineEnding"),t.consume(l),t.exit("lineEnding"),m)}function m(l){return r.parser.lazy[r.now().line]?a(l):u(l)}}import{markdownLineEnding as C}from"../../micromark-util-character@^2.0.0?target=es2022";function b(t){let a=(t||{}).singleDollarTextMath;return a==null&&(a=!0),{tokenize:r,resolve:N,previous:V,name:"mathText"};function r(e,m,l){let z=this,p=0,x,F;return S;function S(i){return e.enter("mathText"),e.enter("mathTextSequence"),w(i)}function w(i){return i===36?(e.consume(i),p++,w):p<2&&!a?l(i):(e.exit("mathTextSequence"),s(i))}function s(i){return i===null?l(i):i===36?(F=e.enter("mathTextSequence"),x=0,g(i)):i===32?(e.enter("space"),e.consume(i),e.exit("space"),s):C(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),s):(e.enter("mathTextData"),o(i))}function o(i){return i===null||i===32||i===36||C(i)?(e.exit("mathTextData"),s(i)):(e.consume(i),o)}function g(i){return i===36?(e.consume(i),x++,g):x===p?(e.exit("mathTextSequence"),e.exit("mathText"),m(i)):(F.type="mathTextData",o(i))}}}function N(t){let u=t.length-4,a=3,r,e;if((t[a][1].type==="lineEnding"||t[a][1].type==="space")&&(t[u][1].type==="lineEnding"||t[u][1].type==="space")){for(r=a;++r<u;)if(t[r][1].type==="mathTextData"){t[u][1].type="mathTextPadding",t[a][1].type="mathTextPadding",a+=2,u-=2;break}}for(r=a-1,u++;++r<=u;)e===void 0?r!==u&&t[r][1].type!=="lineEnding"&&(e=r):(r===u||t[r][1].type==="lineEnding")&&(t[e][1].type="mathTextData",r!==e+2&&(t[e][1].end=t[r-1][1].end,t.splice(e+2,r-e-2),u-=r-e-2,r=e+2),e=void 0);return t}function V(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function H(t){return{flow:{36:D},text:{36:b(t)}}}import _ from"../../katex@^0.16.0?target=es2022";var A=_.renderToString;function B(t){return{enter:{mathFlow(){this.lineEndingIfNeeded(),this.tag('<div class="math math-display">')},mathFlowFenceMeta(){this.buffer()},mathText(){this.tag('<span class="math math-inline">'),this.buffer()}},exit:{mathFlow(){let a=this.resume();this.tag(u(a.replace(/(?:\r?\n|\r)$/,""),!0)),this.tag("</div>"),this.setData("mathFlowOpen"),this.setData("slurpOneLineEnding")},mathFlowFence(){this.getData("mathFlowOpen")||(this.setData("mathFlowOpen",!0),this.setData("slurpOneLineEnding",!0),this.buffer())},mathFlowFenceMeta(){this.resume()},mathFlowValue(a){this.raw(this.sliceSerialize(a))},mathText(){let a=this.resume();this.tag(u(a,!1)),this.tag("</span>")},mathTextData(a){this.raw(this.sliceSerialize(a))}}};function u(a,r){return A(a,{...t,displayMode:r})}}export{H as math,B as mathHtml};
//# sourceMappingURL=micromark-extension-math.mjs.map