{
  "version": 3,
  "sources": ["../../../src/components/link-control/is-url-like.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getProtocol, isValidProtocol, isValidFragment } from '@wordpress/url';\n\n/**\n * Checks if a value is a hash/anchor link (e.g., #section).\n *\n * @param {string} val The value to check.\n * @return {boolean} True if the value is a valid hash link.\n */\nexport function isHashLink( val ) {\n\treturn val?.startsWith( '#' ) && isValidFragment( val );\n}\n\n/**\n * Checks if a value is a relative path (e.g., /page, ./page, ../page).\n *\n * @param {string} val The value to check.\n * @return {boolean} True if the value is a relative path.\n */\nexport function isRelativePath( val ) {\n\treturn (\n\t\tval?.startsWith( '/' ) ||\n\t\tval?.startsWith( './' ) ||\n\t\tval?.startsWith( '../' )\n\t);\n}\n\n/**\n * Determines whether a given value could be a URL or valid href value (like\n * relative paths or hash links). Note this does not guarantee the value is a\n * URL only that it looks like something that should be treated as direct entry\n * rather than a search term. For example, just because a string has `www.` in\n * it doesn't make it a URL, but it does make it highly likely that it will be\n * so in the context of creating a link it makes sense to treat it like one.\n *\n * Examples of \"URL-like\" values:\n * - URLs with protocols: `https://wordpress.org`, `mailto:test@example.com`\n * - Domain-like strings: `www.wordpress.org`, `wordpress.org`\n * - Relative paths: `/handbook`, `./page`, `../parent`\n * - Hash links: `#section`\n *\n * @param {string} val the candidate for being URL-like (or not).\n *\n * @return {boolean} whether or not the value is potentially a URL.\n */\nexport default function isURLLike( val ) {\n\tconst hasSpaces = val.includes( ' ' );\n\n\tif ( hasSpaces ) {\n\t\treturn false;\n\t}\n\n\tconst protocol = getProtocol( val );\n\tconst protocolIsValid = isValidProtocol( protocol );\n\n\tconst mayBeTLD = hasPossibleTLD( val );\n\n\tconst isWWW = val?.startsWith( 'www.' );\n\n\treturn (\n\t\tprotocolIsValid ||\n\t\tisWWW ||\n\t\tisHashLink( val ) ||\n\t\tmayBeTLD ||\n\t\tisRelativePath( val )\n\t);\n}\n\n/**\n * Checks if a given URL has a valid Top-Level Domain (TLD).\n *\n * @param {string} url       - The URL to check.\n * @param {number} maxLength - The maximum length of the TLD.\n * @return {boolean} Returns true if the URL has a valid TLD, false otherwise.\n */\nfunction hasPossibleTLD( url, maxLength = 6 ) {\n\t// Clean the URL by removing anything after the first occurrence of \"?\" or \"#\".\n\tconst cleanedURL = url.split( /[?#]/ )[ 0 ];\n\n\t// Regular expression explanation:\n\t// - (?<=\\S)                  : Positive lookbehind assertion to ensure there is at least one non-whitespace character before the TLD\n\t// - \\.                       : Matches a literal dot (.)\n\t// - [a-zA-Z_]{2,maxLength}   : Matches 2 to maxLength letters or underscores, representing the TLD\n\t// - (?:\\/|$)                 : Non-capturing group that matches either a forward slash (/) or the end of the string\n\tconst regex = new RegExp(\n\t\t`(?<=\\\\S)\\\\.(?:[a-zA-Z_]{2,${ maxLength }})(?:\\\\/|$)`\n\t);\n\n\treturn regex.test( cleanedURL );\n}\n"],
  "mappings": ";AAGA,SAAS,aAAa,iBAAiB,uBAAuB;AAQvD,SAAS,WAAY,KAAM;AACjC,SAAO,KAAK,WAAY,GAAI,KAAK,gBAAiB,GAAI;AACvD;AAQO,SAAS,eAAgB,KAAM;AACrC,SACC,KAAK,WAAY,GAAI,KACrB,KAAK,WAAY,IAAK,KACtB,KAAK,WAAY,KAAM;AAEzB;AAoBe,SAAR,UAA4B,KAAM;AACxC,QAAM,YAAY,IAAI,SAAU,GAAI;AAEpC,MAAK,WAAY;AAChB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,YAAa,GAAI;AAClC,QAAM,kBAAkB,gBAAiB,QAAS;AAElD,QAAM,WAAW,eAAgB,GAAI;AAErC,QAAM,QAAQ,KAAK,WAAY,MAAO;AAEtC,SACC,mBACA,SACA,WAAY,GAAI,KAChB,YACA,eAAgB,GAAI;AAEtB;AASA,SAAS,eAAgB,KAAK,YAAY,GAAI;AAE7C,QAAM,aAAa,IAAI,MAAO,MAAO,EAAG,CAAE;AAO1C,QAAM,QAAQ,IAAI;AAAA,IACjB,6BAA8B,SAAU;AAAA,EACzC;AAEA,SAAO,MAAM,KAAM,UAAW;AAC/B;",
  "names": []
}
