{
  "version": 3,
  "sources": ["urls.js"],
  "sourcesContent": ["import { config } from \"./config.js\";\n\nconst PLACEHOLDER_PATTERN = /:([a-z_]+)/g;\n\n/**\n * Fill the `:name` placeholders of a URL template produced by\n * `src/www/frontend/placeholders.py`.\n */\nfunction interpolate(template, params = {}) {\n    return template.replace(PLACEHOLDER_PATTERN, (_match, name) => {\n        if (!(name in params)) {\n            throw new Error(`Missing URL parameter \"${name}\" for \"${template}\"`);\n        }\n        return encodeURIComponent(params[name]);\n    });\n}\n\n/** Absolute URL of a registered API endpoint, e.g. `apiUrl(\"galleries.photos\", ...)`. */\nexport function apiUrl(name, params = {}) {\n    const template = config.endpoints[name];\n    if (!template) {\n        throw new Error(`Unknown API endpoint: \"${name}\"`);\n    }\n    return config.apiBaseUrl + interpolate(template, params);\n}\n\n/** Absolute URL of a platform page, e.g. `pageUrl(\"panelGallery\", { gallery_uuid })`. */\nexport function pageUrl(name, params = {}) {\n    const template = config.urls[name];\n    if (!template) {\n        throw new Error(`Unknown page URL: \"${name}\"`);\n    }\n    return interpolate(template, params);\n}\n\n/**\n * Absolute API URL for a path the API itself handed back.\n *\n * NOTE: `finalize_url` from the upload-initialize endpoint is host-relative\n *       (`//api/...`, reversed without a parent host), so only its path is usable.\n */\nexport function apiUrlFromPath(pathOrUrl) {\n    const { pathname, search } = new URL(pathOrUrl, config.apiBaseUrl);\n    return config.apiBaseUrl + pathname + search;\n}\n\n/**\n * Whether a URL is served by the API host, i.e. whether our request hooks\n * apply - the auth token among them. Its origin is compared whole, so that\n * `https://api.example.com.elsewhere.net/` or `https://api.example.com@elsewhere.net/`\n * is not taken for it.\n */\nexport function isApiUrl(url) {\n    if (typeof url !== \"string\") {\n        return false;\n    }\n    try {\n        return (\n            new URL(url, window.location.href).origin ===\n            new URL(config.apiBaseUrl).origin\n        );\n    } catch {\n        return false;\n    }\n}\n"],
  "mappings": "AAAA,OAAS,UAAAA,MAAc,cAEvB,MAAMC,EAAsB,cAM5B,SAASC,EAAYC,EAAUC,EAAS,CAAC,EAAG,CACxC,OAAOD,EAAS,QAAQF,EAAqB,CAACI,EAAQC,IAAS,CAC3D,GAAI,EAAEA,KAAQF,GACV,MAAM,IAAI,MAAM,0BAA0BE,CAAI,UAAUH,CAAQ,GAAG,EAEvE,OAAO,mBAAmBC,EAAOE,CAAI,CAAC,CAC1C,CAAC,CACL,CAGO,gBAAS,OAAOA,EAAMF,EAAS,CAAC,EAAG,CACtC,MAAMD,EAAWH,EAAO,UAAUM,CAAI,EACtC,GAAI,CAACH,EACD,MAAM,IAAI,MAAM,0BAA0BG,CAAI,GAAG,EAErD,OAAON,EAAO,WAAaE,EAAYC,EAAUC,CAAM,CAC3D,CAGO,gBAAS,QAAQE,EAAMF,EAAS,CAAC,EAAG,CACvC,MAAMD,EAAWH,EAAO,KAAKM,CAAI,EACjC,GAAI,CAACH,EACD,MAAM,IAAI,MAAM,sBAAsBG,CAAI,GAAG,EAEjD,OAAOJ,EAAYC,EAAUC,CAAM,CACvC,CAQO,gBAAS,eAAeG,EAAW,CACtC,KAAM,CAAE,SAAAC,EAAU,OAAAC,CAAO,EAAI,IAAI,IAAIF,EAAWP,EAAO,UAAU,EACjE,OAAOA,EAAO,WAAaQ,EAAWC,CAC1C,CAQO,gBAAS,SAASC,EAAK,CAC1B,GAAI,OAAOA,GAAQ,SACf,MAAO,GAEX,GAAI,CACA,OACI,IAAI,IAAIA,EAAK,OAAO,SAAS,IAAI,EAAE,SACnC,IAAI,IAAIV,EAAO,UAAU,EAAE,MAEnC,MAAQ,CACJ,MAAO,EACX,CACJ",
  "names": ["config", "PLACEHOLDER_PATTERN", "interpolate", "template", "params", "_match", "name", "pathOrUrl", "pathname", "search", "url"]
}
