{"version":3,"file":"wire.js","names":[],"sources":["esm/dom/wire.js"],"sourcesContent":["const graphEventKinds = [\n  \"ready\",\n  \"commit\",\n  \"selection\",\n  \"viewport\",\n  \"nodeActivate\",\n  \"connectRefused\",\n  \"haptic\",\n  \"metrics\",\n  \"paint\",\n  \"layoutResult\",\n  \"perfReport\",\n  \"lasso\",\n  \"error\"\n];\nconst graphEventEmission = {\n  ready: { firesOn: \"the canvas mounted and painted once\", throttle: { mode: \"none\" } },\n  commit: {\n    firesOn: \"drag stop, connect, delete, paste, layout commit\",\n    throttle: { mode: \"none\" }\n  },\n  selection: { firesOn: \"selection commit, lasso release\", throttle: { mode: \"none\" } },\n  viewport: {\n    firesOn: \"pan/zoom, only when `reportViewport` is on\",\n    throttle: { mode: \"trailing\", ms: 125 }\n  },\n  nodeActivate: { firesOn: \"tap on a field, double-tap on a node\", throttle: { mode: \"none\" } },\n  connectRefused: { firesOn: \"illegal drop\", throttle: { mode: \"none\" } },\n  haptic: {\n    firesOn: \"snap acquisition, lasso arm, connect\",\n    throttle: { mode: \"floor\", ms: 120 }\n  },\n  metrics: { firesOn: \"bench only\", throttle: { mode: \"onDemand\" } },\n  /**\n   * Unthrottled and fired ONCE per mount. It is what the watchdog is measured\n   * against, so a coalescing window here would be a window added to the budget.\n   */\n  paint: { firesOn: \"the frame after React Flow's first render\", throttle: { mode: \"none\" } },\n  layoutResult: { firesOn: \"a relayout resolved\", throttle: { mode: \"none\" } },\n  perfReport: { firesOn: \"perfStop\", throttle: { mode: \"onDemand\" } },\n  /**\n   * `none`, not `floor`: the three phases are different facts and coalescing\n   * `arm` into `select` would lose the buzz. The gesture itself fires at most\n   * three of these, so there is nothing to throttle.\n   */\n  lasso: {\n    firesOn: \"the hold firing, the finger lifting, or any cancel\",\n    throttle: { mode: \"none\" }\n  },\n  error: {\n    firesOn: \"a caught throw in boot, module eval, render or runtime\",\n    throttle: { mode: \"none\" }\n  }\n};\nfunction isGraphEventKind(value) {\n  return typeof value === \"string\" && graphEventKinds.includes(value);\n}\nfunction encodeGraphEvent(event) {\n  return JSON.stringify(event);\n}\nfunction decodeGraphEvent(json) {\n  const parsed = JSON.parse(json);\n  if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n    throw new Error(`graph event payload is not an object: ${json.slice(0, 120)}`);\n  }\n  const tag = parsed.t;\n  if (!isGraphEventKind(tag)) {\n    throw new Error(\n      `graph event tag ${JSON.stringify(tag)} is not one of ${graphEventKinds.join(\", \")} \\u2014 the DOM bundle and its native host are out of step; rebuild the app.`\n    );\n  }\n  return parsed;\n}\nconst resizeObserverLoopNotice = /^(?:uncaught\\s+)?(?:[a-z]*error:\\s*)?resizeobserver loop\\b/i;\nfunction isBenignCanvasError(message) {\n  return typeof message === \"string\" && resizeObserverLoopNotice.test(message);\n}\nfunction createRevEchoGate() {\n  let highWater = Number.NEGATIVE_INFINITY;\n  return {\n    markEmitted(rev) {\n      if (rev > highWater) highWater = rev;\n    },\n    acceptInbound(rev) {\n      if (rev <= highWater) return false;\n      highWater = rev;\n      return true;\n    },\n    highWater: () => highWater\n  };\n}\nfunction createGraphEventEmitter(options) {\n  const now = options.now ?? (() => Date.now());\n  const schedule = options.schedule ?? ((fn, ms) => globalThis.setTimeout(fn, ms));\n  const cancel = options.cancel ?? ((handle) => globalThis.clearTimeout(handle));\n  const pending = /* @__PURE__ */ new Map();\n  const timers = /* @__PURE__ */ new Map();\n  const lastSentAt = /* @__PURE__ */ new Map();\n  let disposed = false;\n  function send(event) {\n    lastSentAt.set(event.t, now());\n    options.send(encodeGraphEvent(event));\n  }\n  function fire(kind) {\n    timers.delete(kind);\n    const event = pending.get(kind);\n    if (!event) return;\n    pending.delete(kind);\n    send(event);\n  }\n  return {\n    emit(event) {\n      if (disposed) return;\n      const { throttle } = graphEventEmission[event.t];\n      if (throttle.mode === \"none\" || throttle.mode === \"onDemand\") {\n        send(event);\n        return;\n      }\n      if (throttle.mode === \"floor\") {\n        const last = lastSentAt.get(event.t);\n        if (last !== void 0 && now() - last < throttle.ms) return;\n        send(event);\n        return;\n      }\n      pending.set(event.t, event);\n      if (timers.has(event.t)) return;\n      timers.set(\n        event.t,\n        schedule(() => fire(event.t), throttle.ms)\n      );\n    },\n    flush() {\n      for (const kind of Array.from(pending.keys())) {\n        const handle = timers.get(kind);\n        if (handle !== void 0) cancel(handle);\n        fire(kind);\n      }\n    },\n    dispose() {\n      disposed = true;\n      for (const handle of timers.values()) cancel(handle);\n      timers.clear();\n      pending.clear();\n    }\n  };\n}\nexport {\n  createGraphEventEmitter,\n  createRevEchoGate,\n  decodeGraphEvent,\n  encodeGraphEvent,\n  graphEventEmission,\n  graphEventKinds,\n  isBenignCanvasError,\n  isGraphEventKind\n};\n//# sourceMappingURL=wire.js.map\n"],"mappings":";AAAA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,qBAAqB;CACzB,OAAO;EAAE,SAAS;EAAuC,UAAU,EAAE,MAAM,OAAO;CAAE;CACpF,QAAQ;EACN,SAAS;EACT,UAAU,EAAE,MAAM,OAAO;CAC3B;CACA,WAAW;EAAE,SAAS;EAAmC,UAAU,EAAE,MAAM,OAAO;CAAE;CACpF,UAAU;EACR,SAAS;EACT,UAAU;GAAE,MAAM;GAAY,IAAI;EAAI;CACxC;CACA,cAAc;EAAE,SAAS;EAAwC,UAAU,EAAE,MAAM,OAAO;CAAE;CAC5F,gBAAgB;EAAE,SAAS;EAAgB,UAAU,EAAE,MAAM,OAAO;CAAE;CACtE,QAAQ;EACN,SAAS;EACT,UAAU;GAAE,MAAM;GAAS,IAAI;EAAI;CACrC;CACA,SAAS;EAAE,SAAS;EAAc,UAAU,EAAE,MAAM,WAAW;CAAE;;;;;CAKjE,OAAO;EAAE,SAAS;EAA6C,UAAU,EAAE,MAAM,OAAO;CAAE;CAC1F,cAAc;EAAE,SAAS;EAAuB,UAAU,EAAE,MAAM,OAAO;CAAE;CAC3E,YAAY;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