"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../../ccount@2.0.1/node_modules/ccount/index.cjs.js"),d=require("../../../../devlop@1.1.0/node_modules/devlop/lib/default.cjs.js"),k=require("../../../../micromark-util-character@2.1.1/node_modules/micromark-util-character/index.cjs.js"),g=require("../../../../mdast-util-find-and-replace@3.0.2/node_modules/mdast-util-find-and-replace/lib/index.cjs.js"),u="phrasing",a=["autolink","link","image","label"];function p(){return{transforms:[P],enter:{literalAutolink:x,literalAutolinkEmail:s,literalAutolinkHttp:s,literalAutolinkWww:s},exit:{literalAutolink:y,literalAutolinkEmail:L,literalAutolinkHttp:A,literalAutolinkWww:m}}}function w(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:u,notInConstruct:a},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:u,notInConstruct:a},{character:":",before:"[ps]",after:"\\/",inConstruct:u,notInConstruct:a}]}}function x(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function s(t){this.config.enter.autolinkProtocol.call(this,t)}function A(t){this.config.exit.autolinkProtocol.call(this,t)}function m(t){this.config.exit.data.call(this,t);const e=this.stack[this.stack.length-1];d.ok(e.type==="link"),e.url="http://"+this.sliceSerialize(t)}function L(t){this.config.exit.autolinkEmail.call(this,t)}function y(t){this.exit(t)}function P(t){g.findAndReplace(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,E],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),_]],{ignore:["link","linkReference"]})}function E(t,e,i,n,o){let l="";if(!h(o)||(/^w/i.test(e)&&(i=e+i,e="",l="http://"),!v(i)))return!1;const r=M(i+n);if(!r[0])return!1;const c={type:"link",title:null,url:l+e+r[0],children:[{type:"text",value:e+r[0]}]};return r[1]?[c,{type:"text",value:r[1]}]:c}function _(t,e,i,n){return!h(n,!0)||/[-\d_]$/.test(i)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+i,children:[{type:"text",value:e+"@"+i}]}}function v(t){const e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function M(t){const e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let i=e[0],n=i.indexOf(")");const o=f.ccount(t,"(");let l=f.ccount(t,")");for(;n!==-1&&o>l;)t+=i.slice(0,n+1),i=i.slice(n+1),n=i.indexOf(")"),l++;return[t,i]}function h(t,e){const i=t.input.charCodeAt(t.index-1);return(t.index===0||k.unicodeWhitespace(i)||k.unicodePunctuation(i))&&(!e||i!==47)}exports.gfmAutolinkLiteralFromMarkdown=p;exports.gfmAutolinkLiteralToMarkdown=w;
//# sourceMappingURL=index.cjs.js.map
