{"version":3,"file":"use-resolved-url.mjs","names":["coreStore"],"sources":["../../src/utils/use-resolved-url.ts"],"sourcesContent":["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Resolves a link against a base URL, the way a browser resolves an `href`.\n *\n * @param url     The link, as stored in a block's attributes.\n * @param baseUrl The URL that relative links and hash links resolve against.\n * @return The absolute URL, or `undefined` when the link can't be resolved,\n *         such as a relative link with no base URL.\n */\nexport function getResolvedUrl( url?: string, baseUrl?: string ) {\n\tif ( ! url ) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn new URL( url, baseUrl ).href;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves a link against the site's home URL. A page-relative link, such as\n * `#faq` or `./about`, depends on the page it's rendered on, which a block\n * doesn't know, so the home page stands in for it.\n *\n * @param url The link, as stored in a block's attributes.\n * @return The absolute URL, or `undefined` when the link can't be resolved.\n */\nexport function useResolvedUrl( url?: string ) {\n\t// An absolute URL resolves on its own. Only a relative link needs the\n\t// home URL, so only then does the hook subscribe to the site data.\n\tconst needsBaseUrl = !! url && getResolvedUrl( url ) === undefined;\n\tconst homeUrl = useSelect(\n\t\t( select ) =>\n\t\t\tneedsBaseUrl\n\t\t\t\t? select( coreStore ).getEntityRecord< { home?: string } >(\n\t\t\t\t\t\t'root',\n\t\t\t\t\t\t'__unstableBase'\n\t\t\t\t\t)?.home\n\t\t\t\t: undefined,\n\t\t[ needsBaseUrl ]\n\t);\n\t// The home URL has no trailing slash, but the front end serves the home\n\t// page as a directory (`/blog/`), so a page-relative link such as\n\t// `./about` must resolve inside it.\n\treturn getResolvedUrl( url, homeUrl && homeUrl.replace( /\\/?$/, '/' ) );\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,eAAgB,KAAc,SAAmB;CAChE,IAAK,CAAE,KACN;CAED,IAAI;EACH,OAAO,IAAI,IAAK,KAAK,OAAQ,CAAC,CAAC;CAChC,QAAQ;EACP;CACD;AACD;;;;;;;;;AAUA,SAAgB,eAAgB,KAAe;CAG9C,MAAM,eAAe,CAAC,CAAE,OAAO,eAAgB,GAAI,MAAM,KAAA;CACzD,MAAM,UAAU,WACb,WACD,eACG,OAAQA,KAAU,CAAC,CAAC,gBACpB,QACA,gBACD,CAAC,EAAE,OACF,KAAA,GACJ,CAAE,YAAa,CAChB;CAIA,OAAO,eAAgB,KAAK,WAAW,QAAQ,QAAS,QAAQ,GAAI,CAAE;AACvE"}