{
  "version": 3,
  "sources": ["../src/modules/net.js"],
  "sourcesContent": ["// zelvior-runtime/net -- reducing redundant network work, not \"speeding up\n// the internet.\" ESM source of truth; bundled by build.mjs.\n//\n// Read this before using this module: nothing running in a page or\n// extension can increase your bandwidth, reduce your ISP's latency, or\n// make a slow connection fast. Anything claiming to \"boost your internet\n// speed\" from JavaScript is not telling the truth. What this module\n// actually does, and why each piece is a real, well-established technique\n// rather than a guess:\n//\n// - dedupeFetch: if the same request is already in flight (or was just\n//   completed, within a short TTL), reuse it instead of firing a second\n//   one. This is a request-count reduction, not a per-request speedup --\n//   the well-known pattern behind libraries like SWR/React Query's\n//   request deduplication.\n// - preconnect: emits real <link rel=\"preconnect\">/\"dns-prefetch\"> hints,\n//   which lets the browser do DNS/TLS/TCP setup for a host before you\n//   actually need it -- a real browser feature, not a JS trick. Only\n//   removes *connection setup* latency for a request you're about to\n//   make; does nothing for a request you're not.\n// - getConnectionInfo/onConnectionChange: a thin, honestly-null-safe\n//   wrapper around the real Network Information API (Chromium only --\n//   Firefox and Safari have never implemented it; every caller must\n//   handle `null`).\n\nvar hasConnection = typeof window !== 'undefined' && typeof window.navigator === 'object' && window.navigator && 'connection' in window.navigator;\n\n/** Real Network Information API data, or null if unsupported (Firefox/Safari, or no navigator). Never guesses a value. */\nexport function getConnectionInfo() {\n  if (!hasConnection) return null;\n  var c = window.navigator.connection;\n  if (!c) return null;\n  return { effectiveType: c.effectiveType || null, saveData: !!c.saveData, downlink: typeof c.downlink === 'number' ? c.downlink : null, rtt: typeof c.rtt === 'number' ? c.rtt : null };\n}\n\n/**\n * Subscribe to real connection-quality changes (network type change, Wi-Fi\n * to cellular, Data Saver toggled, etc.). No-ops safely (returns a no-op\n * unsubscribe) on browsers without the Network Information API, rather\n * than throwing or pretending to fire.\n */\nexport function onConnectionChange(fn) {\n  if (!hasConnection || !window.navigator.connection || !window.navigator.connection.addEventListener) {\n    return function unsubscribe() {};\n  }\n  function handler() { fn(getConnectionInfo()); }\n  window.navigator.connection.addEventListener('change', handler);\n  return function unsubscribe() { window.navigator.connection.removeEventListener('change', handler); };\n}\n\nvar inFlight = new Map();   // key -> Promise\nvar completed = new Map();  // key -> { value, expiresAt }\n\nfunction keyFor(url, opts) {\n  var method = (opts && opts.method) || 'GET';\n  // Only GET/HEAD are deduped/cached by default -- anything else (POST,\n  // PUT, DELETE, ...) is assumed to have side effects and is never safe to\n  // silently coalesce or replay without the caller explicitly asking for\n  // it (see the `dedupeKey` option below for that opt-in case).\n  return method.toUpperCase() + ' ' + url;\n}\n\n/**\n * A drop-in-shaped wrapper around fetch() that:\n * 1. Reuses an identical in-flight GET/HEAD request instead of firing a\n *    second one (multiple parts of a page asking for the same resource at\n *    once collapse into one real network request).\n * 2. Optionally caches the resolved response for `ttl` ms, serving repeat\n *    calls from memory with zero network round-trip.\n *\n * opts.ttl        - ms to cache a successful response after it resolves\n *                    (default 0 -- dedupe in-flight requests only, no\n *                    post-completion cache)\n * opts.dedupeKey  - explicit cache key, to opt a non-GET request into\n *                    deduping/caching (use with care -- only for requests\n *                    you know are safe to coalesce/replay)\n * All other opts are passed through to fetch() unchanged.\n *\n * Returns a Promise<Response> -- note that a cached/deduped call returns\n * the *same* Response object to every caller; call `.clone()` yourself if\n * more than one caller needs to read the body independently (standard\n * fetch Response semantics, not something this module changes).\n */\nexport function dedupeFetch(url, opts) {\n  opts = opts || {};\n  var ttl = opts.ttl || 0;\n  var key = opts.dedupeKey || keyFor(url, opts);\n  var method = (opts.method || 'GET').toUpperCase();\n  var cacheable = opts.dedupeKey || method === 'GET' || method === 'HEAD';\n\n  if (cacheable) {\n    var cached = completed.get(key);\n    if (cached && cached.expiresAt > Date.now()) return Promise.resolve(cached.value);\n    var pending = inFlight.get(key);\n    if (pending) return pending;\n  }\n\n  var fetchOpts = {};\n  for (var k in opts) { if (Object.prototype.hasOwnProperty.call(opts, k) && k !== 'ttl' && k !== 'dedupeKey') fetchOpts[k] = opts[k]; }\n\n  var promise = fetch(url, fetchOpts).then(\n    function (response) {\n      if (cacheable) {\n        inFlight.delete(key);\n        if (ttl > 0) completed.set(key, { value: response, expiresAt: Date.now() + ttl });\n      }\n      return response;\n    },\n    function (err) {\n      if (cacheable) inFlight.delete(key);\n      throw err;\n    }\n  );\n\n  if (cacheable) inFlight.set(key, promise);\n  return promise;\n}\n\n/** Clear the dedupe/cache state -- mainly useful in tests, or after something like a logout. */\nexport function clearDedupeCache() {\n  inFlight.clear();\n  completed.clear();\n}\n\nvar preconnected = new Set();\n\n/**\n * Add a <link rel=\"preconnect\"> (and rel=\"dns-prefetch\" as a fallback for\n * browsers that don't support preconnect) for `origin`, so the browser can\n * do DNS/TLS/TCP setup before you actually request something from it.\n * Idempotent -- calling this twice for the same origin is a no-op, not two\n * link tags.\n */\nexport function preconnect(origin, opts) {\n  if (preconnected.has(origin)) return;\n  preconnected.add(origin);\n  var crossorigin = opts && opts.crossorigin;\n  var l1 = document.createElement('link');\n  l1.rel = 'preconnect';\n  l1.href = origin;\n  if (crossorigin) l1.crossOrigin = 'anonymous';\n  document.head.appendChild(l1);\n  var l2 = document.createElement('link');\n  l2.rel = 'dns-prefetch';\n  l2.href = origin;\n  document.head.appendChild(l2);\n}\n"],
  "mappings": ";4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,gBAAAC,EAAA,sBAAAC,EAAA,uBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAyBA,IAAIQ,EAAgB,OAAO,QAAW,aAAe,OAAO,OAAO,WAAc,UAAY,OAAO,WAAa,eAAgB,OAAO,UAGjI,SAASJ,GAAoB,CAClC,GAAI,CAACI,EAAe,OAAO,KAC3B,IAAIC,EAAI,OAAO,UAAU,WACzB,OAAKA,EACE,CAAE,cAAeA,EAAE,eAAiB,KAAM,SAAU,CAAC,CAACA,EAAE,SAAU,SAAU,OAAOA,EAAE,UAAa,SAAWA,EAAE,SAAW,KAAM,IAAK,OAAOA,EAAE,KAAQ,SAAWA,EAAE,IAAM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MAAOO,EAAU,UAAW,KAAK,IAAI,EAAIR,CAAI,CAAC,GAE3EQ,CACT,EACA,SAAUC,EAAK,CACb,MAAIP,GAAWR,EAAS,OAAOO,CAAG,EAC5BQ,CACR,CACF,EAEA,OAAIP,GAAWR,EAAS,IAAIO,EAAKM,CAAO,EACjCA,CACT,CAGO,SAASvB,GAAmB,CACjCU,EAAS,MAAM,EACfC,EAAU,MAAM,CAClB,CAEA,IAAIe,EAAe,IAAI,IAShB,SAAStB,EAAWuB,EAAQb,EAAM,CACvC,GAAI,CAAAY,EAAa,IAAIC,CAAM,EAC3B,CAAAD,EAAa,IAAIC,CAAM,EACvB,IAAIC,EAAcd,GAAQA,EAAK,YAC3Be,EAAK,SAAS,cAAc,MAAM,EACtCA,EAAG,IAAM,aACTA,EAAG,KAAOF,EACNC,IAAaC,EAAG,YAAc,aAClC,SAAS,KAAK,YAAYA,CAAE,EAC5B,IAAIC,EAAK,SAAS,cAAc,MAAM,EACtCA,EAAG,IAAM,eACTA,EAAG,KAAOH,EACV,SAAS,KAAK,YAAYG,CAAE,EAC9B",
  "names": ["net_exports", "__export", "clearDedupeCache", "dedupeFetch", "getConnectionInfo", "onConnectionChange", "preconnect", "__toCommonJS", "hasConnection", "c", "fn", "handler", "inFlight", "completed", "keyFor", "url", "opts", "method", "ttl", "key", "cacheable", "cached", "pending", "fetchOpts", "k", "promise", "response", "err", "preconnected", "origin", "crossorigin", "l1", "l2"]
}
