import{c as e}from"./unist-util-is-C5Jwnfs7.js";import{v as t}from"./unist-util-visit-parents-DrBR4cjY.js";function n(n,l,o){const s=e((o||{}).ignore||[]),u=function(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let l=-1;for(;++l<n.length;){const e=n[l];t.push([r(e[0]),i(e[1])])}return t}(l);let c=-1;for(;++c<u.length;)t(n,"text",f);function f(e,t){let n,r=-1;for(;++r<t.length;){const e=t[r],i=n?n.children:void 0;if(s(e,i?i.indexOf(e):void 0,n))return;n=e}if(n)return function(e,t){const n=t[t.length-1],r=u[c][0],i=u[c][1];let l=0;const o=n.children.indexOf(e);let s=!1,f=[];r.lastIndex=0;let p=r.exec(e.value);for(;p;){const n=p.index,o={index:p.index,input:p.input,stack:[...t,e]};let u=i(...p,o);if("string"==typeof u&&(u=u.length>0?{type:"text",value:u}:void 0),!1===u?r.lastIndex=n+1:(l!==n&&f.push({type:"text",value:e.value.slice(l,n)}),Array.isArray(u)?f.push(...u):u&&f.push(u),l=n+p[0].length,s=!0),!r.global)break;p=r.exec(e.value)}s?(l<e.value.length&&f.push({type:"text",value:e.value.slice(l)}),n.children.splice(o,1,...f)):f=[e];return o+f.length}(e,t)}}function r(e){return"string"==typeof e?new RegExp(function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(e),"g"):e}function i(e){return"function"==typeof e?e:function(){return e}}export{n as f};
