{
  "version": 3,
  "sources": ["format.js"],
  "sourcesContent": ["import { config } from \"./config.js\";\n\nconst UNITS = [\"byte\", \"kilobyte\", \"megabyte\", \"gigabyte\", \"terabyte\"];\n\n/** A size in bytes the way a person reads it: \"84.2 MB\", \"1.3 GB\". */\nexport function formatBytes(bytes) {\n    let value = bytes;\n    let unit = 0;\n    while (value >= 1024 && unit < UNITS.length - 1) {\n        value /= 1024;\n        unit += 1;\n    }\n    return new Intl.NumberFormat(config.language, {\n        style: \"unit\",\n        unit: UNITS[unit],\n        unitDisplay: \"short\",\n        maximumFractionDigits: unit < 2 ? 0 : 1,\n    }).format(value);\n}\n\n/** A photo's renditions as an `<img srcset>` lists them: \"url 320w, url 640w\". */\nexport function srcsetOf(renditions) {\n    return renditions.map(({ url, width }) => `${url} ${width}w`).join(\", \");\n}\n\n/**\n * An amount in a currency's minor unit (grosze, cents - as the API reports\n * every amount) the way a person reads it: \"49,00 zł\", \"€12.00\" - or, with\n * nothing in the minor unit, \"49 zł\", \"€12\", since the grosze/cents add\n * nothing to look at.\n */\nexport function formatMoney(amount, currency) {\n    return new Intl.NumberFormat(config.language, {\n        style: \"currency\",\n        currency,\n        minimumFractionDigits: amount % 100 === 0 ? 0 : 2,\n    }).format(amount / 100);\n}\n\nconst unitFormats = new Map();\n\nfunction formatUnit(value, unit) {\n    if (!unitFormats.has(unit)) {\n        unitFormats.set(\n            unit,\n            new Intl.NumberFormat(config.language, {\n                style: \"unit\",\n                unit,\n                unitDisplay: \"long\",\n            }),\n        );\n    }\n    return unitFormats.get(unit).format(value);\n}\n\n/**\n * A length of time the way a person says it, in its two largest units: \"45\n * seconds\", \"3 minutes, 30 seconds\", \"1 hour, 5 minutes\". Rounded as an\n * estimate is - to 5 seconds under a minute, to 10 under ten minutes and to a\n * minute beyond - and never down to nothing.\n */\nexport function formatDuration(totalSeconds) {\n    const step = totalSeconds < 60 ? 5 : totalSeconds < 600 ? 10 : 60;\n    const seconds = Math.max(Math.ceil(totalSeconds / step) * step, step);\n    const hours = Math.floor(seconds / 3600);\n    const minutes = Math.floor((seconds % 3600) / 60);\n    const rest = seconds % 60;\n    const parts =\n        hours > 0\n            ? [\n                  [hours, \"hour\"],\n                  [minutes, \"minute\"],\n              ]\n            : [\n                  [minutes, \"minute\"],\n                  [rest, \"second\"],\n              ];\n    return new Intl.ListFormat(config.language, { type: \"unit\", style: \"long\" }).format(\n        parts\n            .filter(([value]) => value > 0)\n            .map(([value, unit]) => formatUnit(value, unit)),\n    );\n}\n"],
  "mappings": "AAAA,OAAS,UAAAA,MAAc,cAEvB,MAAMC,EAAQ,CAAC,OAAQ,WAAY,WAAY,WAAY,UAAU,EAG9D,gBAAS,YAAYC,EAAO,CAC/B,IAAIC,EAAQD,EACRE,EAAO,EACX,KAAOD,GAAS,MAAQC,EAAOH,EAAM,OAAS,GAC1CE,GAAS,KACTC,GAAQ,EAEZ,OAAO,IAAI,KAAK,aAAaJ,EAAO,SAAU,CAC1C,MAAO,OACP,KAAMC,EAAMG,CAAI,EAChB,YAAa,QACb,sBAAuBA,EAAO,EAAI,EAAI,CAC1C,CAAC,EAAE,OAAOD,CAAK,CACnB,CAGO,gBAAS,SAASE,EAAY,CACjC,OAAOA,EAAW,IAAI,CAAC,CAAE,IAAAC,EAAK,MAAAC,CAAM,IAAM,GAAGD,CAAG,IAAIC,CAAK,GAAG,EAAE,KAAK,IAAI,CAC3E,CAQO,gBAAS,YAAYC,EAAQC,EAAU,CAC1C,OAAO,IAAI,KAAK,aAAaT,EAAO,SAAU,CAC1C,MAAO,WACP,SAAAS,EACA,sBAAuBD,EAAS,MAAQ,EAAI,EAAI,CACpD,CAAC,EAAE,OAAOA,EAAS,GAAG,CAC1B,CAEA,MAAME,EAAc,IAAI,IAExB,SAASC,EAAWR,EAAOC,EAAM,CAC7B,OAAKM,EAAY,IAAIN,CAAI,GACrBM,EAAY,IACRN,EACA,IAAI,KAAK,aAAaJ,EAAO,SAAU,CACnC,MAAO,OACP,KAAAI,EACA,YAAa,MACjB,CAAC,CACL,EAEGM,EAAY,IAAIN,CAAI,EAAE,OAAOD,CAAK,CAC7C,CAQO,gBAAS,eAAeS,EAAc,CACzC,MAAMC,EAAOD,EAAe,GAAK,EAAIA,EAAe,IAAM,GAAK,GACzDE,EAAU,KAAK,IAAI,KAAK,KAAKF,EAAeC,CAAI,EAAIA,EAAMA,CAAI,EAC9DE,EAAQ,KAAK,MAAMD,EAAU,IAAI,EACjCE,EAAU,KAAK,MAAOF,EAAU,KAAQ,EAAE,EAC1CG,EAAOH,EAAU,GACjBI,EACFH,EAAQ,EACF,CACI,CAACA,EAAO,MAAM,EACd,CAACC,EAAS,QAAQ,CACtB,EACA,CACI,CAACA,EAAS,QAAQ,EAClB,CAACC,EAAM,QAAQ,CACnB,EACV,OAAO,IAAI,KAAK,WAAWjB,EAAO,SAAU,CAAE,KAAM,OAAQ,MAAO,MAAO,CAAC,EAAE,OACzEkB,EACK,OAAO,CAAC,CAACf,CAAK,IAAMA,EAAQ,CAAC,EAC7B,IAAI,CAAC,CAACA,EAAOC,CAAI,IAAMO,EAAWR,EAAOC,CAAI,CAAC,CACvD,CACJ",
  "names": ["config", "UNITS", "bytes", "value", "unit", "renditions", "url", "width", "amount", "currency", "unitFormats", "formatUnit", "totalSeconds", "step", "seconds", "hours", "minutes", "rest", "parts"]
}
