11 lines
49 KiB
JavaScript
11 lines
49 KiB
JavaScript
/*!
|
|||
|
|
* Autolinker.js
|
||
|
|
* v4.1.5
|
||
|
|
*
|
||
|
|
* Copyright(c) 2025 Gregory Jacobs <greg@greg-jacobs.com>
|
||
|
|
* 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";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function a(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(a.prototype=n.prototype,new a)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,a=arguments.length;n<a;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var a=Object.prototype.hasOwnProperty;function r(t){return"boolean"==typeof t}function i(t,e){for(var n=t.length-1;n>=0;n--)!0===e(t[n])&&t.splice(n,1)}function s(t){throw new Error("Unhandled case for value: '".concat(t,"'"))}var c=/\s+/,o=function(){function t(t){void 0===t&&(t={}),this.tagName="",this.attrs={},this.innerHTML="",this.tagName=t.tagName||"",this.attrs=t.attrs||{},this.innerHTML=t.innerHtml||t.innerHTML||""}return t.prototype.setTagName=function(t){return this.tagName=t,this},t.prototype.getTagName=function(){return this.tagName},t.prototype.setAttr=function(t,e){return this.getAttrs()[t]=e,this},t.prototype.getAttr=function(t){return this.getAttrs()[t]},t.prototype.setAttrs=function(t){return Object.assign(this.getAttrs(),t),this},t.prototype.getAttrs=function(){return this.attrs},t.prototype.setClass=function(t){return this.setAttr("class",t)},t.prototype.addClass=function(t){for(var e,n=this.getClass(),a=n?n.split(c):[],r=t.split(c);e=r.shift();)-1===a.indexOf(e)&&a.push(e);return this.getAttrs().class=a.join(" "),this},t.prototype.removeClass=function(t){for(var e,n=this.getClass(),a=n?n.split(c):[],r=t.split(c);a.length&&(e=r.shift());){var i=a.indexOf(e);-1!==i&&a.splice(i,1)}return this.getAttrs().class=a.join(" "),this},t.prototype.getClass=function(){return this.getAttrs().class||""},t.prototype.hasClass=function(t){return-1!==(" "+this.getClass()+" ").indexOf(" "+t+" ")},t.prototype.setInnerHTML=function(t){return this.innerHTML=t,this},t.prototype.setInnerHtml=function(t){return this.setInnerHTML(t)},t.prototype.getInnerHTML=function(){return this.innerHTML||""},t.prototype.getInnerHtml=function(){return this.getInnerHTML()},t.prototype.toAnchorString=function(){var t=this.getTagName(),e=this.buildAttrsStr();return["<",t,e=e?" "+e:"",">",this.getInnerHtml(),"</",t,">"].join("")},t.prototype.buildAttrsStr=function(){var t=this.getAttrs(),e=[];for(var n in t)a.call(t,n)&&e.push(n+'="'+t[n]+'"');return e.join(" ")},t}();function h(t){var e="";return t.scheme&&t.host&&(e+=t.scheme+"://"),t.host&&(e+=t.host),t.path&&(e+="/"+t.path),t.query&&(e+="?"+t.query),t.fragment&&(e+="#"+t.fragment),e}function u(t,e,n){var a=e/2,r=Math.ceil(a),i=-1*Math.floor(a),s="";return i<0&&(s=t.substr(i)),t.substr(0,r)+n+s}var l=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 o({tagName:"a",attrs:this.createAttrs(t),innerHtml:this.processAnchorText(t.getAnchorText())})},t.prototype.createAttrs=function(t){var e={href:t.getAnchorHref()},n=this.createCssClass(t);return n&&(e.class=n),this.newWindow&&(e.target="_blank",e.rel="noopener noreferrer"),this.truncate.length&&this.truncate.length<t.getAnchorText().length&&(e.title=t.getAnchorHref()),e},t.prototype.createCssClass=function(t){var e=this.className;if(e){for(var n=[e],a=t.getCssClassSuffixes(),r=0,i=a.length;r<i;r++)n.push(e+"-"+a[r]);return n.join(" ")}return""},t.prototype.processAnchorText=function(t){return t=this.doTruncate(t)},t.prototype.doTru
|
||
|
|
//# sourceMappingURL=autolinker.min.js.map
|