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,CAAE,UAAU,CAAE,CAAC;QAE3C,OAAO,UAAU,CAAC;IACnB,CAAC;IAGD;;;;;;;;;;OAUG;IACK,qCAAU,GAAlB,UAAoB,UAAkB;QACrC,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC7B,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAG,OAAO,UAAU,CAAC;QAEtD,IAAI,cAAc,GAAG,QAAQ,CAAC,MAAM,EACnC,gBAAgB,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAEtC,IAAI,gBAAgB,KAAK,OAAO,EAAG;YAClC,OAAO,aAAa,CAAE,UAAU,EAAE,cAAc,CAAE,CAAC;SAEnD;aAAM,IAAI,gBAAgB,KAAK,QAAQ,EAAG;YAC1C,OAAO,cAAc,CAAE,UAAU,EAAE,cAAc,CAAE,CAAC;SAEpD;aAAM;YACN,OAAO,WAAW,CAAE,UAAU,EAAE,cAAc,CAAE,CAAC;SACjD;IACF,CAAC;IACF,uBAAC;AAAD,CApKA,AAoKC,IAAA","file":"anchor-tag-builder.js","sourcesContent":["import { Match } from \"./match/match\";\nimport { HtmlTag } from \"./html-tag\";\nimport { TruncateConfigObj } from \"./autolinker\";\nimport { truncateSmart } from \"./truncate/truncate-smart\";\nimport { truncateMiddle } from \"./truncate/truncate-middle\";\nimport { truncateEnd } from \"./truncate/truncate-end\";\n\n/**\n * @protected\n * @class Autolinker.AnchorTagBuilder\n * @extends Object\n *\n * Builds anchor (&lt;a&gt;) tags for the Autolinker utility when a match is\n * found.\n *\n * Normally this class is instantiated, configured, and used internally by an\n * {@link Autolinker} instance, but may actually be used indirectly in a\n * {@link Autolinker#replaceFn replaceFn} to create {@link Autolinker.HtmlTag HtmlTag}\n * instances which may be modified before returning from the\n * {@link Autolinker#replaceFn replaceFn}. For example:\n *\n * var html = Autolinker.link( \"Test google.com\", {\n * replaceFn : function( match ) {\n * var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance\n * tag.setAttr( 'rel', 'nofollow' );\n *\n * return tag;\n * }\n * } );\n *\n * // generated html:\n * // Test <a href=\"http://google.com\" target=\"_blank\" rel=\"nofollow\">google.com</a>\n */\nexport class AnchorTagBuilder {\n\n\t/**\n\t * @cfg {Boolean} newWindow\n\t * @inheritdoc Autolinker#newWindow\n\t */\n\tprivate readonly newWindow: boolean = false; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {Object} truncate\n\t * @inheritdoc Autolinker#truncate\n\t */\n\tprivate readonly truncate: TruncateConfigObj = {}; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\t/**\n\t * @cfg {String} className\n\t * @inheritdoc Autolinker#className\n\t */\n\tprivate readonly className: string = ''; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n\n\t/**\n\t * @method constructor\n\t * @param {Object} [cfg] The configuration options for the AnchorTagBuilder instance, specified in an Object (map).\n\t */\n\tconstructor( cfg: AnchorTagBuilderCfg = {} ) {\n\t\tthis.newWindow = cfg.newWindow || false;\n\t\tthis.truncate = cfg.truncate || {};\n\t\tthis.className = cfg.className || '';\n\t}\n\n\n\t/**\n\t * Generates the actual anchor (&lt;a&gt;) tag to use in place of the\n\t * matched text, via its `match` object.\n\t *\n\t * @param {Autolinker.match.Match} match The Match instance to generate an\n\t * anchor tag from.\n\t * @return {Autolinker.HtmlTag} The HtmlTag instance for the anchor tag.\n\t */\n\tbuild( match: Match ) {\n\t\treturn new HtmlTag( {\n\t\t\ttagName : 'a',\n\t\t\tattrs : this.createAttrs( match ),\n\t\t\tinnerHtml : this.processAnchorText( match.getAnchorText() )\n\t\t} );\n\t}\n\n\n\t/**\n\t * Creates the Object (map) of the HTML attributes for the anchor (&lt;a&gt;)\n\t * tag being generated.\n\t *\n\t * @protected\n\t * @param {Autolinker.match.Match} match The Match instance to generate an\n\t * anchor tag from.\n\t * @return {Object} A key/value Object (map) of the anchor tag's attributes.\n\t */\n\tprotected createAttrs( match: Match ) {\n\t\tlet attrs: {[attrName: string]: string} = {\n\t\t\t'href' : match.getAnchorHref() // we'll always have the `href` attribute\n\t\t};\n\n\t\tlet cssClass = this.createCssClass( match );\n\t\tif( cssClass ) {\n\t\t\tattrs[ 'class' ] = cssClass;\n\t\t}\n\t\tif( this.newWindow ) {\n\t\t\tattrs[ 'target' ] = \"_blank\";\n\t\t\tattrs[ 'rel' ] = \"noopener noreferrer\"; // Issue #149. See https://mathiasbynens.github.io/rel-noopener/\n\t\t}\n\n\t\tif( this.truncate ) {\n\t\t\tif( this.truncate.length && this.truncate.length < match.getAnchorText().length ) {\n\t\t\t\tattrs[ 'title' ] = match.getAnchorHref();\n\t\t\t}\n\t\t}\n\n\t\treturn attrs;\n\t}\n\n\n\t/**\n\t * Creates the CSS class that will be used for a given anchor tag, based on\n\t * the `matchType` and the {@link #className} config.\n\t *\n\t * Example returns:\n\t *\n\t * - \"\" // no {@link #className}\n\t * - \"myLink myLink-url\" // url match\n\t * - \"myLink myLink-email\" // email match\n\t * - \"myLink myLink-phone\" // phone match\n\t * - \"myLink myLink-hashtag\" // hashtag match\n\t * - \"myLink myLink-mention myLink-twitter\" // mention match with Twitter service\n\t *\n\t * @protected\n\t * @param {Autolinker.match.Match} match The Match instance to generate an\n\t * anchor tag from.\n\t * @return {String} The CSS class string for the link. Example return:\n\t * \"myLink myLink-url\". If no {@link #className} was configured, returns\n\t * an empty string.\n\t */\n\tprotected createCssClass( match: Match ) {\n\t\tlet className = this.className;\n\n\t\tif( !className ) {\n\t\t\treturn \"\";\n\n\t\t} else {\n\t\t\tlet returnClasses = [ className ],\n\t\t\t\tcssClassSuffixes = match.getCssClassSuffixes();\n\n\t\t\tfor( let i = 0, len = cssClassSuffixes.length; i < len; i++ ) {\n\t\t\t\treturnClasses.push( className + '-' + cssClassSuffixes[ i ] );\n\t\t\t}\n\t\t\treturn returnClasses.join( ' ' );\n\t\t}\n\t}\n\n\n\t/**\n\t * Processes the `anchorText` by truncating the text according to the\n\t * {@link #truncate} config.\n\t *\n\t * @private\n\t * @param {String} anchorText The anchor tag's text (i.e. what will be\n\t * displayed).\n\t * @return {String} The processed `anchorText`.\n\t */\n\tprivate processAnchorText( anchorText: string ) {\n\t\tanchorText = this.doTruncate( anchorText );\n\n\t\treturn anchorText;\n\t}\n\n\n\t/**\n\t * Performs the truncation of the `anchorText` based on the {@link #truncate}\n\t * option. If the `anchorText` is longer than the length specified by the\n\t * {@link #truncate} option, the truncation is performed based on the\n\t * `location` property. See {@link #truncate} for details.\n\t *\n\t * @private\n\t * @param {String} anchorText The anchor tag's text (i.e. what will be\n\t * displayed).\n\t * @return {String} The truncated anchor text.\n\t */\n\tprivate doTruncate( anchorText: string ) {\n\t\tlet truncate = this.truncate;\n\t\tif( !truncate || !truncate.length ) return anchorText;\n\n\t\tlet truncateLength = truncate.length,\n\t\t\ttruncateLocation = truncate.location;\n\n\t\tif( truncateLocation === 'smart' ) {\n\t\t\treturn truncateSmart( anchorText, truncateLength );\n\n\t\t} else if( truncateLocation === 'middle' ) {\n\t\t\treturn truncateMiddle( anchorText, truncateLength );\n\n\t\t} else {\n\t\t\treturn truncateEnd( anchorText, truncateLength );\n\t\t}\n\t}\n}\n\n\nexport interface AnchorTagBuilderCfg {\n\tnewWindow?: boolean;\n\ttruncate?: TruncateConfigObj;\n\tclassName?: string\n}"]}