import{c as t}from"./ccount-D181NsKZ.js";import{o as n}from"./devlop-Cl3hj7Sz.js";import{u as i,a as e}from"./micromark-util-character-DUwsRT9L.js";import{f as l}from"./mdast-util-find-and-replace-CCgQ2cpI.js";const r="phrasing",o=["autolink","link","image","label"];function c(){return{transforms:[d],enter:{literalAutolink:a,literalAutolinkEmail:s,literalAutolinkHttp:s,literalAutolinkWww:s},exit:{literalAutolink:k,literalAutolinkEmail:p,literalAutolinkHttp:f,literalAutolinkWww:h}}}function u(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:r,notInConstruct:o},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:r,notInConstruct:o},{character:":",before:"[ps]",after:"\\/",inConstruct:r,notInConstruct:o}]}}function a(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function s(t){this.config.enter.autolinkProtocol.call(this,t)}function f(t){this.config.exit.autolinkProtocol.call(this,t)}function h(t){this.config.exit.data.call(this,t);const i=this.stack[this.stack.length-1];n("link"===i.type),i.url="http://"+this.sliceSerialize(t)}function p(t){this.config.exit.autolinkEmail.call(this,t)}function k(t){this.exit(t)}function d(t){l(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,g],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,m]],{ignore:["link","linkReference"]})}function g(n,i,e,l,r){let o="";if(!w(r))return!1;if(/^w/i.test(i)&&(e=i+e,i="",o="http://"),!function(t){const n=t.split(".");if(n.length<2||n[n.length-1]&&(/_/.test(n[n.length-1])||!/[a-zA-Z\d]/.test(n[n.length-1]))||n[n.length-2]&&(/_/.test(n[n.length-2])||!/[a-zA-Z\d]/.test(n[n.length-2])))return!1;return!0}(e))return!1;const c=function(n){const i=/[!"&'),.:;<>?\]}]+$/.exec(n);if(!i)return[n,void 0];n=n.slice(0,i.index);let e=i[0],l=e.indexOf(")");const r=t(n,"(");let o=t(n,")");for(;-1!==l&&r>o;)n+=e.slice(0,l+1),e=e.slice(l+1),l=e.indexOf(")"),o++;return[n,e]}(e+l);if(!c[0])return!1;const u={type:"link",title:null,url:o+i+c[0],children:[{type:"text",value:i+c[0]}]};return c[1]?[u,{type:"text",value:c[1]}]:u}function m(t,n,i,e){return!(!w(e,!0)||/[-\d_]$/.test(i))&&{type:"link",title:null,url:"mailto:"+n+"@"+i,children:[{type:"text",value:n+"@"+i}]}}function w(t,n){const l=t.input.charCodeAt(t.index-1);return(0===t.index||i(l)||e(l))&&(!n||47!==l)}export{u as a,c as g};
