/*! * Autolinker.js * v3.16.2 * * Copyright(c) 2022 Gregory Jacobs * MIT License * * https://github.com/gregjacobs/Autolinker.js */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Autolinker=e()}(this,(function(){"use strict";function t(t,e){if(Array.prototype.indexOf)return t.indexOf(e);for(var u=0,n=t.length;u=0;u--)!0===e(t[u])&&t.splice(u,1)}function u(t){throw new Error("Unhandled case for value: '".concat(t,"'"))}var n=function(){function e(t){void 0===t&&(t={}),this.tagName="",this.attrs={},this.innerHTML="",this.whitespaceRegex=/\s+/,this.tagName=t.tagName||"",this.attrs=t.attrs||{},this.innerHTML=t.innerHtml||t.innerHTML||""}return e.prototype.setTagName=function(t){return this.tagName=t,this},e.prototype.getTagName=function(){return this.tagName||""},e.prototype.setAttr=function(t,e){return this.getAttrs()[t]=e,this},e.prototype.getAttr=function(t){return this.getAttrs()[t]},e.prototype.setAttrs=function(t){return Object.assign(this.getAttrs(),t),this},e.prototype.getAttrs=function(){return this.attrs||(this.attrs={})},e.prototype.setClass=function(t){return this.setAttr("class",t)},e.prototype.addClass=function(e){for(var u,n=this.getClass(),r=this.whitespaceRegex,a=n?n.split(r):[],i=e.split(r);u=i.shift();)-1===t(a,u)&&a.push(u);return this.getAttrs().class=a.join(" "),this},e.prototype.removeClass=function(e){for(var u,n=this.getClass(),r=this.whitespaceRegex,a=n?n.split(r):[],i=e.split(r);a.length&&(u=i.shift());){var s=t(a,u);-1!==s&&a.splice(s,1)}return this.getAttrs().class=a.join(" "),this},e.prototype.getClass=function(){return this.getAttrs().class||""},e.prototype.hasClass=function(t){return-1!==(" "+this.getClass()+" ").indexOf(" "+t+" ")},e.prototype.setInnerHTML=function(t){return this.innerHTML=t,this},e.prototype.setInnerHtml=function(t){return this.setInnerHTML(t)},e.prototype.getInnerHTML=function(){return this.innerHTML||""},e.prototype.getInnerHtml=function(){return this.getInnerHTML()},e.prototype.toAnchorString=function(){var t=this.getTagName(),e=this.buildAttrsStr();return["<",t,e=e?" "+e:"",">",this.getInnerHtml(),""].join("")},e.prototype.buildAttrsStr=function(){if(!this.attrs)return"";var t=this.getAttrs(),e=[];for(var u in t)t.hasOwnProperty(u)&&e.push(u+'="'+t[u]+'"');return e.join(" ")},e}();var r=function(){function t(t){void 0===t&&(t={}),this.newWindow=!1,this.truncate={},this.className="",this.newWindow=t.newWindow||!1,this.truncate=t.truncate||{},this.className=t.className||""}return t.prototype.build=function(t){return new n({tagName:"a",attrs:this.createAttrs(t),innerHtml:this.processAnchorText(t.getAnchorText())})},t.prototype.createAttrs=function(t){var e={href:t.getAnchorHref()},u=this.createCssClass(t);return u&&(e.class=u),this.newWindow&&(e.target="_blank",e.rel="noopener noreferrer"),this.truncate&&this.truncate.length&&this.truncate.length=s)return o.host.length==e?(o.host.substr(0,e-r)+u).substr(0,s+n):i(h,s).substr(0,s+n);var l="";if(o.path&&(l+="/"+o.path),o.query&&(l+="?"+o.query),l){if((h+l).length>=s)return(h+l).length==e?(h+l).substr(0,e):(h+i(l,s-h.length)).substr(0,s+n);h+=l}if(o.fragment){var p="#"+o.fragment;if((h+p).length>=s)return(h+p).length==e?(h+p).substr(0,e):(h+i(p,s-h.length)).substr(0,s+n);h+=p}if(o.scheme&&o.host){var g=o.scheme+"://";if((h+g).length0&&(f=h.substr(-1*Math.floor(s/2))),(h.substr(0,Math.ceil(s/2))+u+f).substr(0,s+n)}(t,u):"middle"===n?function(t,e,u){if(t.length<=e)return t;var n,r;null==u?(u="…",n=8,r=3):(n=u.length,r=u.length);var a=e-r,i="";return a>0&&(i=t.substr(-1*Math.floor(a/2))),(t.substr(0,Math.ceil(a/2))+u+i).substr(0,a+n)}(t,u):function(t,e,u){return function(t,e,u){var n;return t.length>e&&(null==u?(u="…",n=3):n=u.length,t=t.substring(0,e-n)+u),t}(t,e,u)}(t,u)},t}(),a=function(){function t(t){this.__jsduckDummyDocProp=null,this.matchedText="",this.offset=0,this.tagBuilder=t.tagBuilder,this.matchedText=t.matchedText,this.offset=t.offset}return t.prototype.getMatchedText=function(){return this.matchedText},t.prototype.setOffset=function(t){this.offset=t},t.prototype.getOffset=function(){return this.offset},t.prototype.getCssClassSuffixes=function(){return[this.getType()]},t.prototype.buildTag=function(){return this.tagBuilder.build(this)},t}(),i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var u in e)Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u])},i(t,e)};function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function u(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(u.prototype=e.prototype,new u)}var o,c=function(){return c=Object.assign||function(t){for(var e,u=1,n=arguments.length;u-1},t.isValidUriScheme=function(t){var e=t.match(this.uriSchemeRegex),u=e&&e[0].toLowerCase();return"javascript:"!==u&&"vbscript:"!==u},t.urlMatchDoesNotHaveProtocolOrDot=function(t,e){return!(!t||e&&this.hasFullProtocolRegex.test(e)||-1!==t.indexOf("."))},t.urlMatchDoesNotHaveAtLeastOneWordChar=function(t,e){return!(!t||!e)&&(!this.hasFullProtocolRegex.test(e)&&!this.hasWordCharAfterProtocolRegex.test(t))},t.hasFullProtocolRegex=/^[A-Za-z][-.+A-Za-z0-9]*:\/\//,t.uriSchemeRegex=/^[A-Za-z][-.+A-Za-z0-9]*:/,t.hasWordCharAfterProtocolRegex=new RegExp(":[^\\s]*?["+w+"]"),t.ipRegex=/[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?(:[0-9]*)?\/?$/,t}(),H=(o=new RegExp("[/?#](?:["+D+"\\-+&@#/%=~_()|'$*\\[\\]{}?!:,.;^✓]*["+D+"\\-+&@#/%=~_()|'$*\\[\\]{}✓])?"),new RegExp(["(?:","(",/(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/.source,P(2),")","|","(","(//)?",/(?:www\.)/.source,P(6),")","|","(","(//)?",P(10)+"\\.",z.source,"(?![-"+C+"])",")",")","(?::[0-9]+)?","(?:"+o.source+")?"].join(""),"gi")),_=new RegExp("["+D+"]"),U=function(t){function e(e){var u=t.call(this,e)||this;return u.stripPrefix={scheme:!0,www:!0},u.stripTrailingSlash=!0,u.decodePercentEncoding=!0,u.matcherRegex=H,u.wordCharRegExp=_,u.stripPrefix=e.stripPrefix,u.stripTrailingSlash=e.stripTrailingSlash,u.decodePercentEncoding=e.decodePercentEncoding,u}return s(e,t),e.prototype.parseMatches=function(t){for(var e,u=this.matcherRegex,n=this.stripPrefix,r=this.stripTrailingSlash,a=this.decodePercentEncoding,i=this.tagBuilder,s=[],o=function(){var u=e[0],o=e[1],h=e[4],l=e[5],p=e[9],g=e.index,d=l||p,m=t.charAt(g-1);if(!S.isValid(u,o))return"continue";if(g>0&&"@"===m)return"continue";if(g>0&&d&&c.wordCharRegExp.test(m))return"continue";if(/\?$/.test(u)&&(u=u.substr(0,u.length-1)),c.matchHasUnbalancedClosingParen(u))u=u.substr(0,u.length-1);else{var A=c.matchHasInvalidCharAfterTld(u,o);A>-1&&(u=u.substr(0,A))}var b=["http://","https://"].find((function(t){return!!o&&-1!==o.indexOf(t)}));if(b){var x=u.indexOf(b);u=u.substr(x),o=o.substr(x),g+=x}var y=o?"scheme":h?"www":"tld",F=!!o;s.push(new f({tagBuilder:i,matchedText:u,offset:g,urlMatchType:y,url:u,protocolUrlMatch:F,protocolRelativeMatch:!!d,stripPrefix:n,stripTrailingSlash:r,decodePercentEncoding:a}))},c=this;null!==(e=u.exec(t));)o();return s},e.prototype.matchHasUnbalancedClosingParen=function(t){var e,u=t.charAt(t.length-1);if(")"===u)e="(";else if("]"===u)e="[";else{if("}"!==u)return!1;e="{"}for(var n=0,r=0,a=t.length-1;r-1&&i-s<=140){var u=t.slice(s,i),a=new l({tagBuilder:e,matchedText:u,offset:s,serviceName:n,hashtag:u.slice(1)});r.push(a)}}},e}(d),L=["twitter","facebook","instagram","tiktok"],$=new RegExp("".concat(/(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/.source,"|").concat(/(0([1-9]{1}-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})/.source),"g"),Z=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.matcherRegex=$,e}return s(e,t),e.prototype.parseMatches=function(t){for(var e,u=this.matcherRegex,n=this.tagBuilder,r=[];null!==(e=u.exec(t));){var a=e[0],i=a.replace(/[^0-9,;#]/g,""),s=!(!e[1]&&!e[2]),o=0==e.index?"":t.substr(e.index-1,1),c=t.substr(e.index+a.length,1),h=!o.match(/\d/)&&!c.match(/\d/);this.testMatch(e[3])&&this.testMatch(a)&&h&&r.push(new g({tagBuilder:n,matchedText:a,offset:e.index,number:i,plusSign:s}))}return r},e.prototype.testMatch=function(t){return b.test(t)},e}(d),V=new RegExp("@[_".concat(D,"]{1,50}(?![_").concat(D,"])"),"g"),Y=new RegExp("@[_.".concat(D,"]{1,30}(?![_").concat(D,"])"),"g"),G=new RegExp("@[-_.".concat(D,"]{1,50}(?![-_").concat(D,"])"),"g"),J=new RegExp("@[_.".concat(D,"]{1,23}[_").concat(D,"](?![_").concat(D,"])"),"g"),K=new RegExp("[^"+D+"]"),Q=function(t){function e(e){var u=t.call(this,e)||this;return u.serviceName="twitter",u.matcherRegexes={twitter:V,instagram:Y,soundcloud:G,tiktok:J},u.nonWordCharRegex=K,u.serviceName=e.serviceName,u}return s(e,t),e.prototype.parseMatches=function(t){var e,u=this.serviceName,n=this.matcherRegexes[this.serviceName],r=this.nonWordCharRegex,a=this.tagBuilder,i=[];if(!n)return i;for(;null!==(e=n.exec(t));){var s=e.index,o=t.charAt(s-1);if(0===s||r.test(o)){var c=e[0].replace(/\.+$/g,""),h=c.slice(1);i.push(new p({tagBuilder:a,matchedText:c,offset:s,serviceName:u,mention:h}))}}return i},e}(d);function X(t,e){for(var n,r=e.onOpenTag,a=e.onCloseTag,i=e.onText,s=e.onComment,o=e.onDoctype,h=new tt,l=0,p=t.length,g=0,f=0,d=h;l"===t?(d=new tt(c(c({},d),{name:Z()})),$()):m.test(t)||A.test(t)||":"===t||I()}function C(t){">"===t?I():m.test(t)?g=3:I()}function D(t){x.test(t)||("/"===t?g=12:">"===t?$():"<"===t?L():"="===t||y.test(t)||F.test(t)?I():g=5)}function E(t){x.test(t)?g=6:"/"===t?g=12:"="===t?g=7:">"===t?$():"<"===t?L():y.test(t)&&I()}function k(t){x.test(t)||("/"===t?g=12:"="===t?g=7:">"===t?$():"<"===t?L():y.test(t)?I():g=5)}function T(t){x.test(t)||('"'===t?g=8:"'"===t?g=9:/[>=`]/.test(t)?I():"<"===t?L():g=10)}function M(t){'"'===t&&(g=11)}function P(t){"'"===t&&(g=11)}function j(t){x.test(t)?g=4:">"===t?$():"<"===t&&L()}function z(t){x.test(t)?g=4:"/"===t?g=12:">"===t?$():"<"===t?L():(g=4,l--)}function R(t){">"===t?(d=new tt(c(c({},d),{isClosing:!0})),$()):g=4}function q(e){"--"===t.substr(l,2)?(l+=2,d=new tt(c(c({},d),{type:"comment"})),g=14):"DOCTYPE"===t.substr(l,7).toUpperCase()?(l+=7,d=new tt(c(c({},d),{type:"doctype"})),g=20):I()}function N(t){"-"===t?g=15:">"===t?I():g=16}function O(t){"-"===t?g=18:">"===t?I():g=16}function S(t){"-"===t&&(g=17)}function H(t){g="-"===t?18:16}function _(t){">"===t?$():"!"===t?g=19:"-"===t||(g=16)}function U(t){"-"===t?g=17:">"===t?$():g=16}function W(t){">"===t?$():"<"===t&&L()}function I(){g=0,d=h}function L(){g=1,d=new tt({idx:l})}function $(){var e=t.slice(f,d.idx);e&&i(e,f),"comment"===d.type?s(d.idx):"doctype"===d.type?o(d.idx):(d.isOpening&&r(d.name,d.idx),d.isClosing&&a(d.name,d.idx)),I(),f=l+1}function Z(){var e=d.idx+(d.isClosing?2:1);return t.slice(e,l).toLowerCase()}f=0&&n++},onText:function(t,u){if(0===n){var a=function(t,e){if(!e.global)throw new Error("`splitRegex` must have the 'g' flag set");for(var u,n=[],r=0;u=e.exec(t);)n.push(t.substring(r,u.index)),n.push(u[0]),r=u.index+u[0].length;return n.push(t.substring(r)),n}(t,/( | |<|<|>|>|"|"|')/gi),i=u;a.forEach((function(t,u){if(u%2==0){var n=e.parseText(t,i);r.push.apply(r,n)}i+=t.length}))}},onCloseTag:function(t){u.indexOf(t)>=0&&(n=Math.max(n-1,0))},onComment:function(t){},onDoctype:function(t){}}),r=this.compactMatches(r),r=this.removeUnwantedMatches(r)},t.prototype.compactMatches=function(t){t.sort((function(t,e){return t.getOffset()-e.getOffset()}));for(var e=0;er?e:e+1;t.splice(i,1);continue}if(t[e+1].getOffset()/g,">"));for(var e=this.parse(t),u=[],n=0,r=0,a=e.length;r