{
  "version": 3,
  "sources": ["reset_data_summary_core.js"],
  "sourcesContent": ["/*\n * static/js/reset_data_summary_core.js \u2014 what \"Reset local data\" is about\n * to delete, grouped by what it costs to lose (SNOW-860).\n *\n * `/offline/`'s Reset local data row asks the user to approve a\n * deletion whose contents they could not see: `pwa_reset.js` unregisters\n * every service worker, deletes every Cache Storage bucket, drops every\n * IndexedDB database and clears both web-storage areas, and the only\n * thing between the user and that was a `window.confirm` quoting three\n * words. This module is the arithmetic behind the breakdown that replaced\n * them; `reset_data_summary.js` is the DOM half and does nothing this one\n * could do instead.\n *\n * ## Grouped by cost, not by storage API\n *\n * The four categories are not `caches` / `indexedDB` / `localStorage` /\n * service workers. A user does not know or care which API holds what;\n * they care whether losing it costs them a re-download over mobile data,\n * a piece of work that never reached the server, a page reload, or a\n * preference they will re-set in five seconds. So:\n *\n *   - **Downloaded maps** \u2014 the areas the user chose. Expensive:\n *     re-downloading needs a connection, and the whole point of them is\n *     being somewhere without one. Its figure is the SAME total the\n *     Manage downloads sheet states (\"Using X of Y\" \u2014 `budgetSummary`\n *     over the same rows), because both exclude the shared tiles below.\n *   - **Shared basemap tiles** \u2014 the zoomed-out ground the app fetched\n *     for itself, shared by every download of a basemap. A line of its\n *     own (SNOW-1138), not folded into the figure above: folded in, the\n *     two surfaces stated two different \"downloads\" totals for one\n *     device.\n *   - **Unsent changes** \u2014 rows still in `queue:mutations`. Not bytes, a\n *     COUNT, and the only category where a non-zero figure is a warning:\n *     these have not reached the server, so the reset is the last thing\n *     that will ever happen to them.\n *   - **Cached pages and tiles** \u2014 everything else the origin is holding.\n *     Cheap: losing it costs a reload, not data.\n *   - **Preferences** \u2014 basemap choice, camera, panel states, telemetry\n *     opt-in. No size worth stating; the list itself is the disclosure.\n *\n * ## Two figures that need explaining\n *\n * **Downloaded-map bytes are the RECORDED figure**, the one each\n * completed download run wrote \u2014 never a live measurement of the bucket.\n * `pwaBasemapAreas.measureBucketBytes` sums `Content-Length`, and the\n * tile origin sends none under gzip, so it reads ~0 in production for a\n * bucket full of real tiles. Using it for every area would have shipped a\n * breakdown claiming 0 MB of maps on a device holding 400 of them \u2014 and\n * passed a test suite whose fixture Responses carry no `Content-Length`\n * either. It IS used for an ORPHANED bucket, which has no record to read\n * a figure off (SNOW-1138): that is the measurement the Manage downloads\n * sheet sizes the same row by, so the two state the same size for it.\n *\n * **Cached bytes are a subtraction, and approximate.**\n * `navigator.storage.estimate()` reports one figure for the whole origin,\n * so the honest attribution is \"everything the browser says we are using,\n * minus what we can account for as downloaded maps and shared tiles\".\n * Floored at zero,\n * because the two numbers come from different places and a browser that\n * reports less than we recorded must not produce a negative row. Where\n * `estimate()` is unavailable the category still renders \u2014 with no\n * figure, and the \"costs you a reload\" framing, which is the part that\n * matters.\n *\n * Pure: no DOM, no fetch, no storage. Everything arrives as an argument.\n */\n\n(function () {\n  'use strict';\n\n  /**\n   * A finite, non-negative byte count from an untrusted value.\n   *\n   * @param {*} value\n   * @returns {number}\n   */\n  function bytesOf(value) {\n    var n = Number(value);\n    return Number.isFinite(n) && n > 0 ? n : 0;\n  }\n\n  /**\n   * The downloaded-map items: the user's own areas, in the order the\n   * Manage downloads sheet's `manageRows` put them.\n   *\n   * SNOW-1138: the shared overview maps are no longer an item here. They\n   * were appended as one \"Shared basemap tiles\" row and summed into this\n   * category's figure, so \"Downloaded maps\" read a larger number than the\n   * sheet's own downloads total for the same device. They are their own\n   * category now (`sharedTiles`).\n   *\n   * @param {Array<{id: string, label?: string, bytes?: number,\n   *   onDevice?: boolean}>} rows `pwaBasemapManageCore.manageRows` output.\n   *   A row with `onDevice === false` exists on the ACCOUNT only \u2014 another\n   *   device's download, or one evicted here \u2014 so this reset cannot delete\n   *   it and it must not be counted.\n   * @returns {Array<{id: string, label: string, bytes: number}>}\n   */\n  function mapItems(rows) {\n    var items = [];\n    (Array.isArray(rows) ? rows : []).forEach(function (row) {\n      if (!row || !row.id || row.onDevice === false) return;\n      items.push({\n        id: String(row.id),\n        label: String(row.label || row.id),\n        bytes: bytesOf(row.bytes),\n      });\n    });\n    return items;\n  }\n\n  /**\n   * The shared overview maps, as one summed figure.\n   *\n   * Collapsed rather than listed one per basemap: repeated \"Overview map\"\n   * rows differing only in size name the app's internals and answer no\n   * question the user has. The reset takes all of them or none, and there\n   * is no per-basemap control anywhere to pair a split with.\n   *\n   * @param {Array<{id: string, bytes?: number}>} baseLayers The shared\n   *   overview maps, as `basemapDownloadedAreas()` returns them. `bytes`\n   *   is 0 when the record has not landed yet (SNOW-863); they still\n   *   count as present, because the tiles are on the device whether or\n   *   not their size was recorded.\n   * @returns {{bytes: number, present: boolean}}\n   */\n  function sharedTiles(baseLayers) {\n    var bytes = 0;\n    var count = 0;\n    (Array.isArray(baseLayers) ? baseLayers : []).forEach(function (layer) {\n      if (!layer || !layer.id) return;\n      bytes += bytesOf(layer.bytes);\n      count += 1;\n    });\n    return { bytes: bytes, present: count > 0 };\n  }\n\n  /**\n   * The whole breakdown, from what the page managed to read.\n   *\n   * Every input is optional and every missing one degrades to a stated\n   * absence rather than a thrown error: this panel sits beside a recovery\n   * control, and a device broken enough to fail these reads is exactly\n   * the device whose user is reaching for it.\n   *\n   * @param {{rows?: Array<Object>, baseLayers?: Array<Object>,\n   *   mutationCount?: number, storageEstimate?: {usage?: number}|null}}\n   *   input `rows` is described on `mapItems` and `baseLayers` on\n   *   `sharedTiles` above.\n   *   `mutationCount` is the depth of the `queue:mutations` store \u2014\n   *   SNOW-376's pending mutations, NOT `queue:events`, which is the\n   *   SNOW-385 telemetry buffer and would put a count of analytics\n   *   payloads under a heading reading \"unsent changes\".\n   *   `storageEstimate` is `navigator.storage.estimate()`'s result, or\n   *   null where the browser has no such method.\n   * @returns {{maps: {items: Array<Object>, bytes: number},\n   *   shared: {bytes: number, present: boolean},\n   *   unsent: {count: number, warn: boolean},\n   *   cached: {bytes: number|null, known: boolean},\n   *   totalBytes: number, totalIsPartial: boolean}}\n   *   `maps.bytes` is the user's downloads alone \u2014 the figure the Manage\n   *   downloads sheet's `budgetSummary` states for the same rows.\n   *   `shared` is the overview maps, on their own line. `cached.known` is\n   *   false when the origin's usage could not be read; `totalIsPartial`\n   *   says the same thing about the total, which is then the maps and the\n   *   shared tiles alone and is understating.\n   */\n  function summarise(input) {\n    var source = input || {};\n    var items = mapItems(source.rows);\n    var mapBytes = items.reduce(function (sum, item) {\n      return sum + item.bytes;\n    }, 0);\n    var shared = sharedTiles(source.baseLayers);\n    // Everything this page can account for as map data, which is what the\n    // origin's usage is reduced by to leave the cached remainder.\n    var accounted = mapBytes + shared.bytes;\n\n    var usage = source.storageEstimate ? Number(source.storageEstimate.usage) : NaN;\n    var usageKnown = Number.isFinite(usage) && usage >= 0;\n    // Floored at 0: the recorded download figure and the browser's own\n    // accounting are two different measurements of overlapping ground, and\n    // a \"-12 MB of cached pages\" row would be worse than saying nothing.\n    var cachedBytes = usageKnown ? Math.max(0, usage - accounted) : null;\n\n    var count = Number(source.mutationCount);\n    if (!Number.isFinite(count) || count < 0) count = 0;\n\n    return {\n      maps: { items: items, bytes: mapBytes },\n      shared: shared,\n      unsent: { count: count, warn: count > 0 },\n      cached: { bytes: cachedBytes, known: usageKnown },\n      totalBytes: accounted + (cachedBytes || 0),\n      totalIsPartial: !usageKnown,\n    };\n  }\n\n  window.pwaResetDataSummaryCore = Object.freeze({\n    summarise: summarise,\n  });\n})();\n"],
  "mappings": "CAmEC,UAAY,CACX,aAQA,SAASA,EAAQC,EAAO,CACtB,IAAIC,EAAI,OAAOD,CAAK,EACpB,OAAO,OAAO,SAASC,CAAC,GAAKA,EAAI,EAAIA,EAAI,CAC3C,CAmBA,SAASC,EAASC,EAAM,CACtB,IAAIC,EAAQ,CAAC,EACb,OAAC,MAAM,QAAQD,CAAI,EAAIA,EAAO,CAAC,GAAG,QAAQ,SAAUE,EAAK,CACnD,CAACA,GAAO,CAACA,EAAI,IAAMA,EAAI,WAAa,IACxCD,EAAM,KAAK,CACT,GAAI,OAAOC,EAAI,EAAE,EACjB,MAAO,OAAOA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ytes", "count", "layer", "summarise", "input", "source", "mapBytes", "sum", "item", "shared", "accounted", "usage", "usageKnown", "cachedBytes"]
}
