{"version":3,"file":"get-updated-link-attributes.mjs","names":[],"sources":["../../src/button/get-updated-link-attributes.js"],"sourcesContent":["import { prependHTTPS } from '@wordpress/url';\nimport { NEW_TAB_REL, NEW_TAB_TARGET, NOFOLLOW_REL } from './constants';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object}  attributes               The current block attributes.\n * @param {string}  attributes.rel           The current link rel attribute.\n * @param {string}  attributes.url           The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow      Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTPS( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,yBAA0B,EACzC,MAAM,IACN,MAAM,IACN,eACA,YACG;CACH,IAAI;CAEJ,IAAI,aAAa;CAEjB,IAAK,eACJ,gBAAgB;MACV;EACN,MAAM,WAAW,IAAI,OAAQ,MAAO,YAAa,OAAO,GAAI;EAC5D,aAAa,YAAY,QAAS,UAAU,EAAG,CAAC,CAAC,KAAK;CACvD;CAEA,IAAK,UACJ,aAAa,YAAY,SAAU,YAAa,IAC7C,cACE,aAAa,IAAK,eAAA,CAAkB,KAAK;MACxC;EACN,MAAM,WAAW,IAAI,OAAQ,MAAO,aAAc,OAAO,GAAI;EAC7D,aAAa,YAAY,QAAS,UAAU,EAAG,CAAC,CAAC,KAAK;CACvD;CAEA,OAAO;EACN,KAAK,aAAc,GAAI;EACvB,YAAY;EACZ,KAAK,cAAc,KAAA;CACpB;AACD"}