@spotpatch/runtime 1.15.2 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,29 +60,29 @@ function createButton(document, label, className = "") {
60
60
  // src/ui/data-flow-panel.ts
61
61
  var LABELS = Object.freeze({
62
62
  "zh-CN": Object.freeze({
63
- server: "\u670D\u52A1\u7AEF\uFF08\u9759\u6001\u8BC1\u636E\uFF09",
64
- client: "\u6D4F\u89C8\u5668",
65
- bindings: "\u6570\u636E\u53BB\u5411",
66
- changes: "\u4FEE\u6539\u8BF4\u660E",
67
- componentEmpty: "\u5F53\u524D\u7EC4\u4EF6\u6CA1\u6709\u627E\u5230\u53EF\u8BC1\u660E\u7684\u63A5\u53E3\u3002\u672A\u627E\u5230\u4E0D\u7B49\u4E8E\u6CA1\u6709\u8BF7\u6C42\u3002",
68
- componentTab: "\u6570\u636E\u94FE\u8DEF",
69
- componentTitle: "\u7EC4\u4EF6\u6570\u636E\u94FE\u8DEF",
70
- consumed: "\u8BFB\u53D6\u5B57\u6BB5",
71
- declared: "\u4EE3\u7801\u58F0\u660E\uFF0C\u5C1A\u672A\u5728\u672C\u6B21\u9875\u9762\u4F1A\u8BDD\u4E2D\u89C2\u6D4B",
72
- diagnostics: "\u8BCA\u65AD",
73
- disabled: "\u6570\u636E\u94FE\u8DEF\u80FD\u529B\u672A\u542F\u7528\uFF0C\u8BF7\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u8BBE\u7F6E dataFlow: {}\u3002",
74
- error: "\u6570\u636E\u94FE\u8DEF\u62A5\u544A\u52A0\u8F7D\u5931\u8D25",
75
- evidence: "\u8BC1\u636E",
76
- loading: "\u6B63\u5728\u5206\u6790\u6E90\u7801\u5E76\u5408\u5E76\u8FD0\u884C\u65F6\u8BC1\u636E\u2026",
77
- logicalObserved: "\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u5165 tRPC \u8C03\u7528\u94FE",
78
- noParameters: "\u672A\u63D0\u53D6\u5230\u53EF\u8BC1\u660E\u7684\u53C2\u6570\u952E",
79
- observed: "\u672C\u6B21\u4F1A\u8BDD\u5DF2\u5B9E\u9645\u8BF7\u6C42",
80
- pageEmpty: "\u5F53\u524D\u5DF2\u9009\u9875\u9762\u8303\u56F4\u5185\u6CA1\u6709\u9759\u6001\u63A5\u53E3\u6216\u8FD0\u884C\u65F6\u7F51\u7EDC\u8BB0\u5F55\u3002",
81
- pageTab: "\u9875\u9762\u63A5\u53E3",
82
- pageTitle: "\u9875\u9762\u63A5\u53E3",
83
- parameters: "\u8BF7\u6C42\u53C2\u6570",
84
- refresh: "\u5237\u65B0\u8BC1\u636E",
85
- unknown: "\u672A\u77E5"
63
+ server: "服务端(静态证据)",
64
+ client: "浏览器",
65
+ bindings: "数据去向",
66
+ changes: "修改说明",
67
+ componentEmpty: "当前组件没有找到可证明的接口。未找到不等于没有请求。",
68
+ componentTab: "数据链路",
69
+ componentTitle: "组件数据链路",
70
+ consumed: "读取字段",
71
+ declared: "代码声明,尚未在本次页面会话中观测",
72
+ diagnostics: "诊断",
73
+ disabled: "数据链路能力未启用,请在插件配置中设置 dataFlow: {}。",
74
+ error: "数据链路报告加载失败",
75
+ evidence: "证据",
76
+ loading: "正在分析源码并合并运行时证据…",
77
+ logicalObserved: "本次会话已进入 tRPC 调用链",
78
+ noParameters: "未提取到可证明的参数键",
79
+ observed: "本次会话已实际请求",
80
+ pageEmpty: "当前已选页面范围内没有静态接口或运行时网络记录。",
81
+ pageTab: "页面接口",
82
+ pageTitle: "页面接口",
83
+ parameters: "请求参数",
84
+ refresh: "刷新证据",
85
+ unknown: "未知"
86
86
  }),
87
87
  "en-US": Object.freeze({
88
88
  server: "Server (static evidence)",
@@ -98,7 +98,7 @@ var LABELS = Object.freeze({
98
98
  disabled: "Data flow is disabled. Set dataFlow: {} in the plugin options.",
99
99
  error: "Failed to load the data-flow report",
100
100
  evidence: "Evidence",
101
- loading: "Analyzing source and merging runtime evidence\u2026",
101
+ loading: "Analyzing source and merging runtime evidence…",
102
102
  logicalObserved: "Dispatched through the tRPC link in this session",
103
103
  noParameters: "No proven parameter keys were extracted",
104
104
  observed: "Actually requested in this session",
@@ -175,7 +175,7 @@ function renderDependency(document, dependency, labels) {
175
175
  detailRow(
176
176
  document,
177
177
  labels.evidence,
178
- `${String(staticEvidenceCount)} static \xB7 ${String(dependency.observationIds.length)} runtime`
178
+ `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`
179
179
  )
180
180
  );
181
181
  card.append(header, body);
@@ -266,12 +266,12 @@ function createDataFlowPanel(document, enabled, locale, changesRoot, diagnostics
266
266
  }
267
267
  const report = snapshot.report;
268
268
  const diagnosticCodes = report === void 0 ? "" : [...new Set(report.diagnostics.map(({ code }) => code))].join(", ");
269
- const diagnosticSuffix = diagnosticCodes.length === 0 ? "" : ` \xB7 ${labels.diagnostics}: ${diagnosticCodes}`;
269
+ const diagnosticSuffix = diagnosticCodes.length === 0 ? "" : ` · ${labels.diagnostics}: ${diagnosticCodes}`;
270
270
  if (report === void 0 || report.dependencies.length === 0) {
271
271
  target.status.textContent = `${empty}${diagnosticSuffix}`;
272
272
  return;
273
273
  }
274
- target.status.textContent = `${String(report.dependencies.length)} \xB7 ${report.completeness.complete ? "complete" : "partial"}${diagnosticSuffix}`;
274
+ target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? "complete" : "partial"}${diagnosticSuffix}`;
275
275
  target.list.append(
276
276
  ...report.dependencies.map(
277
277
  (dependency) => renderDependency(document, dependency, labels)
@@ -296,7 +296,7 @@ function createDataFlowPanel(document, enabled, locale, changesRoot, diagnostics
296
296
  [...tabButtons.values()].forEach((button, index) => {
297
297
  button.textContent = tabLabels[index] ?? "";
298
298
  });
299
- refreshButton.textContent = `${labels.refresh} \xB7 ${String(state.observationCount)}`;
299
+ refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;
300
300
  refreshButton.disabled = !enabled || state.component.status === "loading";
301
301
  renderSnapshot(component, state.component, labels.componentEmpty);
302
302
  renderSnapshot(page, state.page, labels.pageEmpty);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/data-flow-panel-entry.ts","../src/ui/ui-constants.ts","../src/ui/dom.ts","../src/ui/data-flow-panel.ts","../src/ui/data-flow-panel-contract.ts","../src/data-flow/data-flow-runtime.ts","../src/data-flow/report-merger.ts"],"sourcesContent":["export { createDataFlowPanel } from \"./ui/data-flow-panel.js\";\nexport {\n getDataFlowExtension,\n registerDataFlowExtension,\n type DataFlowExtension,\n type DataFlowPanel,\n type DataFlowPanelFactory,\n type DataFlowPanelSnapshot,\n type DataFlowPanelStatus,\n type DataFlowViewState,\n} from \"./ui/data-flow-panel-contract.js\";\n\nimport {\n getDataFlowRuntime,\n mergeComponentDataFlowReport,\n mergePageDataFlowReport,\n} from \"./data-flow-entry.js\";\nimport { createDataFlowPanel } from \"./ui/data-flow-panel.js\";\nimport { registerDataFlowExtension } from \"./ui/data-flow-panel-contract.js\";\n\nexport function installDataFlowPanelExtension(): void {\n registerDataFlowExtension(\n Object.freeze({\n createPanel: createDataFlowPanel,\n getComponentRegistration(component: object) {\n return getDataFlowRuntime()?.getComponentRegistration(component);\n },\n observations(routeKey: string) {\n const runtime = getDataFlowRuntime();\n runtime?.updateRoute(routeKey);\n return runtime?.observations() ?? Object.freeze([]);\n },\n mergeComponentReport: mergeComponentDataFlowReport,\n mergePageReport: mergePageDataFlowReport,\n }),\n );\n}\n","export const UI_MARKER_ATTRIBUTE = \"data-spotpatch-ui\" as const;\n\nexport const UI_Z_INDEX = Object.freeze({\n highlight: 2_147_483_646,\n controls: 2_147_483_647,\n});\n\nexport const FLOATING_SURFACE_LAYOUT = Object.freeze({\n compactInset: 8,\n compactViewportWidth: 520,\n desktopInset: 24,\n dragActivationDistance: 6,\n edgeSnapDistance: 20,\n workbenchMaxHeight: 620,\n workbenchMaxWidth: 460,\n});\n","import { UI_MARKER_ATTRIBUTE } from \"./ui-constants.js\";\n\nexport function createMarkedElement<K extends keyof HTMLElementTagNameMap>(\n document: Document,\n tagName: K,\n): HTMLElementTagNameMap[K] {\n const element = document.createElement(tagName);\n element.setAttribute(UI_MARKER_ATTRIBUTE, \"\");\n return element;\n}\n\nexport function createButton(\n document: Document,\n label: string,\n className = \"\",\n): HTMLButtonElement {\n const button = createMarkedElement(document, \"button\");\n button.type = \"button\";\n button.className = className;\n button.textContent = label;\n return button;\n}\n","import type { DataDependency, SpotPatchLocale } from \"@spotpatch/shared\";\n\nimport { createButton, createMarkedElement } from \"./dom.js\";\nimport type {\n DataFlowPanel,\n DataFlowPanelSnapshot,\n DataFlowViewState,\n} from \"./data-flow-panel-contract.js\";\n\ninterface Labels {\n readonly server: string;\n readonly client: string;\n readonly bindings: string;\n readonly changes: string;\n readonly componentEmpty: string;\n readonly componentTab: string;\n readonly componentTitle: string;\n readonly consumed: string;\n readonly declared: string;\n readonly diagnostics: string;\n readonly disabled: string;\n readonly error: string;\n readonly evidence: string;\n readonly loading: string;\n readonly logicalObserved: string;\n readonly noParameters: string;\n readonly observed: string;\n readonly pageEmpty: string;\n readonly pageTab: string;\n readonly pageTitle: string;\n readonly parameters: string;\n readonly refresh: string;\n readonly unknown: string;\n}\n\nconst LABELS = Object.freeze({\n \"zh-CN\": Object.freeze({\n server: \"服务端(静态证据)\",\n client: \"浏览器\",\n bindings: \"数据去向\",\n changes: \"修改说明\",\n componentEmpty: \"当前组件没有找到可证明的接口。未找到不等于没有请求。\",\n componentTab: \"数据链路\",\n componentTitle: \"组件数据链路\",\n consumed: \"读取字段\",\n declared: \"代码声明,尚未在本次页面会话中观测\",\n diagnostics: \"诊断\",\n disabled: \"数据链路能力未启用,请在插件配置中设置 dataFlow: {}。\",\n error: \"数据链路报告加载失败\",\n evidence: \"证据\",\n loading: \"正在分析源码并合并运行时证据…\",\n logicalObserved: \"本次会话已进入 tRPC 调用链\",\n noParameters: \"未提取到可证明的参数键\",\n observed: \"本次会话已实际请求\",\n pageEmpty: \"当前已选页面范围内没有静态接口或运行时网络记录。\",\n pageTab: \"页面接口\",\n pageTitle: \"页面接口\",\n parameters: \"请求参数\",\n refresh: \"刷新证据\",\n unknown: \"未知\",\n }),\n \"en-US\": Object.freeze({\n server: \"Server (static evidence)\",\n client: \"Browser\",\n bindings: \"Data destinations\",\n changes: \"Changes\",\n componentEmpty:\n \"No proven interface was found for this component. This does not prove that no request exists.\",\n componentTab: \"Data flow\",\n componentTitle: \"Component data flow\",\n consumed: \"Consumed fields\",\n declared: \"Declared in code, not observed in this page session\",\n diagnostics: \"Diagnostics\",\n disabled: \"Data flow is disabled. Set dataFlow: {} in the plugin options.\",\n error: \"Failed to load the data-flow report\",\n evidence: \"Evidence\",\n loading: \"Analyzing source and merging runtime evidence…\",\n logicalObserved: \"Dispatched through the tRPC link in this session\",\n noParameters: \"No proven parameter keys were extracted\",\n observed: \"Actually requested in this session\",\n pageEmpty:\n \"No static interface or runtime traffic is available for the selected page scope.\",\n pageTab: \"Page APIs\",\n pageTitle: \"Page interfaces\",\n parameters: \"Request parameters\",\n refresh: \"Refresh evidence\",\n unknown: \"Unknown\",\n }),\n}) satisfies Readonly<Record<SpotPatchLocale, Labels>>;\n\nfunction badge(document: Document, text: string, tone: string): HTMLElement {\n const element = createMarkedElement(document, \"span\");\n element.className = \"spotpatch-data-flow-badge\";\n element.dataset.tone = tone;\n element.textContent = text;\n return element;\n}\n\nfunction detailRow(document: Document, label: string, value: string): HTMLElement {\n const row = createMarkedElement(document, \"div\");\n row.className = \"spotpatch-data-flow-detail\";\n const key = createMarkedElement(document, \"span\");\n key.textContent = label;\n const content = createMarkedElement(document, \"code\");\n content.textContent = value;\n row.append(key, content);\n return row;\n}\n\nfunction renderDependency(\n document: Document,\n dependency: DataDependency,\n labels: Labels,\n): HTMLElement {\n const card = createMarkedElement(document, \"article\");\n card.className = \"spotpatch-data-flow-card\";\n const header = createMarkedElement(document, \"div\");\n header.className = \"spotpatch-data-flow-card-head\";\n const endpoint = createMarkedElement(document, \"div\");\n endpoint.className = \"spotpatch-data-flow-endpoint\";\n const method = createMarkedElement(document, \"strong\");\n method.textContent = dependency.method ?? labels.unknown;\n const path = createMarkedElement(document, \"code\");\n path.textContent =\n dependency.url === undefined\n ? (dependency.operation ?? labels.unknown)\n : `${dependency.url.origin ?? \"\"}${dependency.url.pathname}`;\n endpoint.append(method, path);\n const states = createMarkedElement(document, \"div\");\n states.className = \"spotpatch-data-flow-badges\";\n states.append(\n badge(\n document,\n dependency.execution === \"observed\"\n ? dependency.kind === \"rpc\"\n ? labels.logicalObserved\n : labels.observed\n : labels.declared,\n dependency.execution === \"observed\" ? \"success\" : \"neutral\",\n ),\n badge(\n document,\n dependency.proof,\n dependency.proof === \"proven\" ? \"proof\" : \"warning\",\n ),\n badge(document, dependency.association, \"neutral\"),\n );\n header.append(endpoint, states);\n if (dependency.environment !== undefined)\n states.append(badge(document, labels[dependency.environment], \"neutral\"));\n\n const parameters =\n dependency.parameters.length === 0\n ? labels.noParameters\n : dependency.parameters\n .map(\n (parameter) =>\n `${parameter.position}.${parameter.path}${parameter.type === undefined ? \"\" : `: ${parameter.type}`}${parameter.sensitive ? \" [sensitive]\" : \"\"}${parameter.condition === undefined ? \"\" : ` [when ${parameter.condition}]`}`,\n )\n .join(\"\\n\");\n const consumed =\n dependency.response.consumedFields.length === 0\n ? labels.unknown\n : dependency.response.consumedFields.join(\", \");\n const bindings =\n dependency.suppliedBindings.length === 0\n ? labels.unknown\n : dependency.suppliedBindings.join(\", \");\n const body = createMarkedElement(document, \"div\");\n body.className = \"spotpatch-data-flow-card-body\";\n const observationIds = new Set(dependency.observationIds);\n const staticEvidenceCount = dependency.evidenceIds.filter(\n (id) => !observationIds.has(id),\n ).length;\n body.append(\n detailRow(document, labels.parameters, parameters),\n detailRow(document, labels.consumed, consumed),\n detailRow(document, labels.bindings, bindings),\n detailRow(\n document,\n labels.evidence,\n `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`,\n ),\n );\n card.append(header, body);\n return card;\n}\n\nfunction createReportRoot(\n document: Document,\n titleText: string,\n): Readonly<{ root: HTMLElement; status: HTMLElement; list: HTMLElement }> {\n const root = createMarkedElement(document, \"section\");\n root.className = \"spotpatch-data-flow-panel\";\n const title = createMarkedElement(document, \"h3\");\n title.textContent = titleText;\n const status = createMarkedElement(document, \"p\");\n status.className = \"spotpatch-data-flow-status\";\n const list = createMarkedElement(document, \"div\");\n list.className = \"spotpatch-data-flow-list\";\n root.append(title, status, list);\n return Object.freeze({ root, status, list });\n}\n\nexport function createDataFlowPanel(\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n): DataFlowPanel {\n let labels = LABELS[locale()];\n const component = createReportRoot(document, labels.componentTitle);\n const page = createReportRoot(document, labels.pageTitle);\n const refreshButton = createButton(document, labels.refresh);\n const styles = document.createElement(\"style\");\n styles.textContent = DATA_FLOW_PANEL_STYLES;\n refreshButton.classList.add(\"spotpatch-data-flow-refresh\");\n component.root.prepend(refreshButton);\n const root = createMarkedElement(document, \"div\");\n const tabs = createMarkedElement(document, \"nav\");\n tabs.className = \"spotpatch-view-tabs\";\n tabs.setAttribute(\"aria-label\", \"SpotPatch views\");\n tabs.setAttribute(\"role\", \"tablist\");\n const views = new Map([\n [\"changes\", changesRoot],\n [\"component-data\", component.root],\n [\"page-data\", page.root],\n [\"diagnostics\", diagnosticsRoot],\n ]);\n const tabButtons = new Map<string, HTMLButtonElement>();\n let activeView = \"changes\";\n for (const id of views.keys()) {\n const button = createButton(document, \"\");\n button.dataset.viewId = id;\n button.id = `spotpatch-view-${id}-tab`;\n button.setAttribute(\"role\", \"tab\");\n button.setAttribute(\"aria-selected\", String(id === activeView));\n const view = views.get(id);\n view?.setAttribute(\"aria-labelledby\", button.id);\n view?.setAttribute(\"role\", \"tabpanel\");\n if (!enabled && (id === \"component-data\" || id === \"page-data\")) {\n button.hidden = true;\n }\n tabButtons.set(id, button);\n tabs.append(button);\n }\n root.append(tabs, ...views.values());\n\n function selectView(viewId: string): void {\n if (!views.has(viewId)) return;\n activeView = viewId;\n for (const [id, view] of views) {\n view.hidden = id !== viewId;\n const button = tabButtons.get(id);\n button?.setAttribute(\"aria-selected\", String(id === viewId));\n if (button !== undefined) button.tabIndex = id === viewId ? 0 : -1;\n }\n onViewChange();\n }\n\n function handleTabClick(event: Event): void {\n if (!(event.target instanceof HTMLButtonElement)) return;\n const viewId = event.target.dataset.viewId;\n if (viewId !== undefined) selectView(viewId);\n }\n\n tabs.addEventListener(\"click\", handleTabClick);\n selectView(activeView);\n\n function renderSnapshot(\n target: ReturnType<typeof createReportRoot>,\n snapshot: DataFlowPanelSnapshot,\n empty: string,\n ): void {\n target.list.replaceChildren();\n target.status.dataset.state = snapshot.status;\n if (!enabled || snapshot.status === \"disabled\") {\n target.status.textContent = labels.disabled;\n return;\n }\n if (snapshot.status === \"loading\") {\n target.status.textContent = labels.loading;\n return;\n }\n if (snapshot.status === \"error\") {\n target.status.textContent = snapshot.message ?? labels.error;\n return;\n }\n const report = snapshot.report;\n const diagnosticCodes =\n report === undefined\n ? \"\"\n : [...new Set(report.diagnostics.map(({ code }) => code))].join(\", \");\n const diagnosticSuffix =\n diagnosticCodes.length === 0\n ? \"\"\n : ` · ${labels.diagnostics}: ${diagnosticCodes}`;\n if (report === undefined || report.dependencies.length === 0) {\n target.status.textContent = `${empty}${diagnosticSuffix}`;\n return;\n }\n target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? \"complete\" : \"partial\"}${diagnosticSuffix}`;\n target.list.append(\n ...report.dependencies.map((dependency) =>\n renderDependency(document, dependency, labels),\n ),\n );\n }\n\n return Object.freeze({\n root,\n refreshButton,\n styles,\n dispose(): void {\n tabs.removeEventListener(\"click\", handleTabClick);\n },\n render(state: DataFlowViewState): void {\n labels = LABELS[locale()];\n const tabLabels = [\n labels.changes,\n labels.componentTab,\n labels.pageTab,\n labels.diagnostics,\n ];\n [...tabButtons.values()].forEach((button, index) => {\n button.textContent = tabLabels[index] ?? \"\";\n });\n refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;\n refreshButton.disabled = !enabled || state.component.status === \"loading\";\n renderSnapshot(component, state.component, labels.componentEmpty);\n renderSnapshot(page, state.page, labels.pageEmpty);\n },\n resetView(): void {\n selectView(\"changes\");\n },\n });\n}\n\nconst DATA_FLOW_PANEL_STYLES = `\n .spotpatch-view-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; padding: 3px; border: 1px solid rgb(255 255 255 / 7%); border-radius: 9px; background: rgb(3 7 18 / 42%); }\n .spotpatch-view-tabs button { min-width: 0; border: 0; border-radius: 7px; padding: 7px 5px; color: var(--spotpatch-text-muted); background: transparent; cursor: pointer; font-size: 10.5px; }\n .spotpatch-view-tabs button[aria-selected=\"true\"] { color: #f8fafc; background: rgb(139 124 247 / 18%); }\n .spotpatch-data-flow-panel { position: relative; }\n .spotpatch-data-flow-panel > h3 { margin: 0 0 3px; color: #f3f4f6; font-size: 13px; }\n .spotpatch-data-flow-refresh { position: absolute; top: -4px; right: 0; border: 1px solid rgb(139 124 247 / 30%); border-radius: 7px; padding: 4px 8px; color: #c4baff; background: rgb(139 124 247 / 8%); cursor: pointer; font-size: 10.5px; }\n .spotpatch-data-flow-refresh:disabled { cursor: not-allowed; opacity: .45; }\n .spotpatch-data-flow-status { margin: 0 0 10px; color: var(--spotpatch-text-muted); font-size: 10.5px; line-height: 1.5; }\n .spotpatch-data-flow-list { display: grid; gap: 8px; }\n .spotpatch-data-flow-card { overflow: hidden; border: 1px solid rgb(255 255 255 / 8%); border-radius: 9px; background: rgb(255 255 255 / 2.5%); }\n .spotpatch-data-flow-card-head { display: grid; gap: 7px; padding: 10px; border-bottom: 1px solid rgb(255 255 255 / 7%); }\n .spotpatch-data-flow-endpoint { display: flex; min-width: 0; align-items: center; gap: 8px; }\n .spotpatch-data-flow-endpoint strong { color: #79d9e7; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }\n .spotpatch-data-flow-endpoint code { min-width: 0; overflow: hidden; color: #f8fafc; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }\n .spotpatch-data-flow-badges { display: flex; flex-wrap: wrap; gap: 4px; }\n .spotpatch-data-flow-badge { border-radius: 999px; padding: 2px 6px; color: #9ca3af; background: rgb(255 255 255 / 5%); font-size: 9px; }\n .spotpatch-data-flow-badge[data-tone=\"success\"] { color: #6ee7b7; background: rgb(16 185 129 / 10%); }\n .spotpatch-data-flow-badge[data-tone=\"proof\"] { color: #c4b5fd; background: rgb(139 92 246 / 11%); }\n .spotpatch-data-flow-badge[data-tone=\"warning\"] { color: #fcd34d; background: rgb(245 158 11 / 10%); }\n .spotpatch-data-flow-card-body { display: grid; gap: 7px; padding: 10px; }\n .spotpatch-data-flow-detail { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; align-items: start; }\n .spotpatch-data-flow-detail > span { color: var(--spotpatch-text-muted); font-size: 10px; }\n .spotpatch-data-flow-detail > code { overflow-wrap: anywhere; color: #cbd5e1; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }\n`;\n","import type {\n ComponentDataFlowReport,\n NetworkObservation,\n PageDataFlowReport,\n SpotPatchLocale,\n} from \"@spotpatch/shared\";\n\nimport type { DataFlowComponentRegistration } from \"../data-flow/data-flow-runtime.js\";\n\nexport type DataFlowPanelStatus = \"disabled\" | \"idle\" | \"loading\" | \"ready\" | \"error\";\n\nexport interface DataFlowPanelSnapshot {\n readonly status: DataFlowPanelStatus;\n readonly report?: ComponentDataFlowReport | PageDataFlowReport;\n readonly message?: string;\n}\n\nexport interface DataFlowViewState {\n readonly component: DataFlowPanelSnapshot;\n readonly page: DataFlowPanelSnapshot;\n readonly observationCount: number;\n}\n\nexport interface DataFlowPanel {\n readonly root: HTMLElement;\n readonly refreshButton: HTMLButtonElement;\n readonly styles: HTMLStyleElement;\n readonly dispose: () => void;\n readonly render: (state: DataFlowViewState) => void;\n readonly resetView: () => void;\n}\n\nexport type DataFlowPanelFactory = (\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n) => DataFlowPanel;\n\nexport interface DataFlowExtension {\n readonly createPanel: DataFlowPanelFactory;\n readonly getComponentRegistration: (\n component: object,\n ) => DataFlowComponentRegistration | undefined;\n readonly observations: (routeKey: string) => readonly NetworkObservation[];\n readonly mergeComponentReport: (\n report: ComponentDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => ComponentDataFlowReport;\n readonly mergePageReport: (\n report: PageDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => PageDataFlowReport;\n}\n\nconst DATA_FLOW_EXTENSION_KEY = Symbol.for(\"spotpatch.data-flow.extension.v1\");\ntype ExtensionStore = Partial<Record<symbol, DataFlowExtension>>;\n\nexport function registerDataFlowExtension(\n extension: DataFlowExtension,\n target: ExtensionStore = globalThis,\n): void {\n target[DATA_FLOW_EXTENSION_KEY] = extension;\n}\n\nexport function getDataFlowExtension(\n target: ExtensionStore = globalThis,\n): DataFlowExtension | undefined {\n return target[DATA_FLOW_EXTENSION_KEY];\n}\n","import {\n DATA_FLOW_SCHEMA_VERSION,\n DATA_FLOW_URL_QUERY_KEY_LIMIT,\n SPOTPATCH_API_BASE,\n type NetworkObservation,\n type RuntimeDataFlowConfig,\n type RuntimeDataFlowLimits,\n type SanitizedObservedUrl,\n} from \"@spotpatch/shared/data-flow-runtime\";\n\nexport interface DataFlowComponentRegistration {\n readonly componentSourceId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowInvocationToken {\n readonly invocationId: string;\n readonly componentSourceId: string;\n readonly triggerCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRequestFrame {\n readonly requestCallsiteId: string;\n readonly sourceVersion: string;\n readonly invocationToken?: DataFlowInvocationToken;\n}\n\nexport interface DataFlowTriggerMetadata {\n readonly componentSourceId: string;\n readonly triggerCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRequestMetadata {\n readonly requestCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRuntime {\n readonly beginInvocation: (\n metadata: DataFlowTriggerMetadata,\n ) => DataFlowInvocationToken;\n readonly bindInvocation: <Arguments extends readonly unknown[], Result>(\n token: DataFlowInvocationToken | undefined,\n callback: (...args: Arguments) => Result,\n ) => (...args: Arguments) => Result;\n readonly bindTrigger: <Callback>(\n metadata: DataFlowTriggerMetadata,\n callback: Callback,\n ) => Callback;\n readonly captureInvocation: () => DataFlowInvocationToken | undefined;\n readonly clear: () => void;\n readonly createTrpcLink: () => DataFlowTrpcLink;\n readonly dispose: () => void;\n readonly getComponentRegistration: (\n component: object,\n ) => DataFlowComponentRegistration | undefined;\n readonly getCurrentRequestFrame: () => DataFlowRequestFrame | undefined;\n readonly observations: () => readonly NetworkObservation[];\n readonly updateRoute: (routeKey: string) => void;\n readonly registerComponent: (\n component: object,\n componentSourceId: string,\n sourceVersion: string,\n ) => void;\n readonly withInvocation: <Result>(\n token: DataFlowInvocationToken | undefined,\n callback: () => Result,\n ) => Result;\n readonly withRequestFrame: <Result>(\n token: DataFlowInvocationToken | undefined,\n metadata: DataFlowRequestMetadata,\n callback: () => Result,\n ) => Result;\n}\n\nexport interface DataFlowObservationPolicy {\n readonly shouldObserveFetch?: (\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n baseUrl: string,\n ) => boolean;\n readonly shouldObserveXhr?: (url: string, baseUrl: string) => boolean;\n}\n\nexport interface DataFlowTrpcOperation {\n readonly path: unknown;\n readonly type: unknown;\n}\n\nexport interface DataFlowTrpcLinkOptions<\n Operation extends DataFlowTrpcOperation,\n Result,\n> {\n readonly next: (operation: Operation) => Result;\n readonly op: Operation;\n}\n\nexport type DataFlowTrpcLink = (\n runtime: unknown,\n) => <Operation extends DataFlowTrpcOperation, Result>(\n options: DataFlowTrpcLinkOptions<Operation, Result>,\n) => Result;\n\ninterface DataFlowGlobal {\n readonly fetch?: typeof globalThis.fetch;\n readonly location?: Location;\n readonly performance?: Performance;\n readonly XMLHttpRequest?: typeof globalThis.XMLHttpRequest;\n}\n\ninterface MutableDataFlowGlobal extends DataFlowGlobal {\n fetch?: typeof globalThis.fetch;\n}\n\ninterface XhrMetadata {\n readonly method: string;\n readonly url: string;\n}\n\ninterface RingEntry {\n readonly bytes: number;\n readonly observation: NetworkObservation;\n readonly recordedAt: number;\n}\n\nconst RUNTIME_KEY: unique symbol = Symbol.for(\n \"spotpatch.data-flow.runtime.v1\",\n) as never;\nconst REACT_MEMO_TYPE = Symbol.for(\"react.memo\");\nconst REACT_FORWARD_REF_TYPE = Symbol.for(\"react.forward_ref\");\n\ntype DataFlowRuntimeStore = Partial<Record<symbol, DataFlowRuntime>>;\ntype GlobalWithDataFlow = MutableDataFlowGlobal & DataFlowRuntimeStore;\n\nfunction positiveNow(target: DataFlowGlobal): number {\n return target.performance?.now() ?? Date.now();\n}\n\nfunction createOpaqueSequence(prefix: string): () => string {\n let sequence = 0;\n const randomPrefix = (() => {\n try {\n const bytes = new Uint8Array(8);\n globalThis.crypto.getRandomValues(bytes);\n return Array.from(bytes, (value) => value.toString(36).padStart(2, \"0\")).join(\"\");\n } catch {\n return \"local\";\n }\n })();\n\n return () => {\n sequence += 1;\n return `${prefix}_${randomPrefix}_${sequence.toString(36)}`;\n };\n}\n\nfunction freezeUrl(value: string, baseUrl: string): SanitizedObservedUrl {\n try {\n const url = new URL(value, baseUrl);\n return Object.freeze({\n origin: url.origin,\n pathname: url.pathname,\n queryKeys: Object.freeze(\n [...new Set(url.searchParams.keys())]\n .sort()\n .slice(0, DATA_FLOW_URL_QUERY_KEY_LIMIT),\n ),\n });\n } catch {\n return Object.freeze({\n pathname: value.split(/[?#]/u, 1)[0] ?? \"{invalid}\",\n queryKeys: Object.freeze([]),\n });\n }\n}\n\nfunction readFetchUrl(input: RequestInfo | URL): string {\n if (typeof input === \"string\") return input;\n if (input instanceof URL) return input.toString();\n return input.url;\n}\n\nfunction readFetchMethod(input: RequestInfo | URL, init?: RequestInit): string {\n if (init?.method !== undefined) return init.method.toUpperCase();\n return typeof Request !== \"undefined\" && input instanceof Request\n ? input.method.toUpperCase()\n : \"GET\";\n}\n\nfunction isSpotPatchInternalUrl(value: string, baseUrl: string): boolean {\n try {\n const pathname = new URL(value, baseUrl).pathname;\n return (\n pathname === SPOTPATCH_API_BASE || pathname.startsWith(`${SPOTPATCH_API_BASE}/`)\n );\n } catch {\n return false;\n }\n}\n\nfunction approximateBytes(value: unknown): number {\n return new TextEncoder().encode(JSON.stringify(value)).byteLength;\n}\n\nfunction createRingStore(\n limits: RuntimeDataFlowLimits,\n target: DataFlowGlobal,\n): Readonly<{\n add: (observation: NetworkObservation) => void;\n clear: () => void;\n values: () => readonly NetworkObservation[];\n}> {\n const entries: RingEntry[] = [];\n let totalBytes = 0;\n\n function removeExpired(now: number): void {\n while (\n entries[0] !== undefined &&\n now - entries[0].recordedAt > limits.observationTtlMs\n ) {\n const removed = entries.shift();\n if (removed !== undefined) totalBytes -= removed.bytes;\n }\n }\n\n return Object.freeze({\n add(observation): void {\n const now = positiveNow(target);\n removeExpired(now);\n const bytes = approximateBytes(observation);\n if (bytes > limits.observationMaxBytes) return;\n entries.push(Object.freeze({ bytes, observation, recordedAt: now }));\n totalBytes += bytes;\n\n while (\n entries.length > limits.observationMaxEntries ||\n totalBytes > limits.observationMaxBytes\n ) {\n const removed = entries.shift();\n if (removed !== undefined) totalBytes -= removed.bytes;\n }\n },\n clear(): void {\n entries.length = 0;\n totalBytes = 0;\n },\n values(): readonly NetworkObservation[] {\n removeExpired(positiveNow(target));\n return Object.freeze(entries.map(({ observation }) => observation));\n },\n });\n}\n\nfunction ownPropertyDescriptor(\n target: object,\n key: PropertyKey,\n): PropertyDescriptor | undefined {\n try {\n return Object.getOwnPropertyDescriptor(target, key);\n } catch {\n return undefined;\n }\n}\n\nfunction nestedReactWrapperComponent(candidate: object): object | undefined {\n const marker: unknown = ownPropertyDescriptor(candidate, \"$$typeof\")?.value;\n const key =\n marker === REACT_MEMO_TYPE\n ? \"type\"\n : marker === REACT_FORWARD_REF_TYPE\n ? \"render\"\n : undefined;\n if (key === undefined) return undefined;\n const nested: unknown = ownPropertyDescriptor(candidate, key)?.value;\n return (typeof nested === \"object\" && nested !== null) || typeof nested === \"function\"\n ? nested\n : undefined;\n}\n\nfunction installWritableDataProperty(\n target: object,\n key: PropertyKey,\n replacement: object,\n original: PropertyDescriptor | undefined = ownPropertyDescriptor(target, key),\n): (() => void) | undefined {\n if (original === undefined || !(\"value\" in original) || !original.writable) {\n return undefined;\n }\n\n try {\n Object.defineProperty(target, key, { ...original, value: replacement });\n } catch {\n return undefined;\n }\n\n return (): void => {\n try {\n if (ownPropertyDescriptor(target, key)?.value === replacement) {\n Object.defineProperty(target, key, original);\n }\n } catch {\n // A host or later wrapper can make the property non-configurable.\n }\n };\n}\n\nfunction recordWithoutAffectingHost(record: () => void): void {\n try {\n record();\n } catch {\n // Observation is optional; the host transport result is authoritative.\n }\n}\n\nexport function createDataFlowRuntime(\n config: RuntimeDataFlowConfig,\n target: MutableDataFlowGlobal = globalThis,\n policy: DataFlowObservationPolicy = {},\n): DataFlowRuntime {\n const componentRegistry = new WeakMap<object, DataFlowComponentRegistration>();\n const xhrMetadata = new WeakMap<object, XhrMetadata>();\n const store = createRingStore(config.limits, target);\n const nextInvocationId = createOpaqueSequence(\"invocation\");\n const nextObservationId = createOpaqueSequence(\"observation\");\n const pageEpoch = createOpaqueSequence(\"page\")();\n const nextRouteEpoch = createOpaqueSequence(\"route\");\n let routeEpoch = nextRouteEpoch();\n let routeKey: string | undefined;\n let currentInvocation: DataFlowInvocationToken | undefined;\n let currentRequestFrame: DataFlowRequestFrame | undefined;\n let disposed = false;\n\n const originalFetch = (() => {\n try {\n return target.fetch;\n } catch {\n return undefined;\n }\n })();\n function spotPatchFetch(\n this: typeof globalThis,\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> {\n if (originalFetch === undefined) {\n throw new TypeError(\"Fetch is unavailable.\");\n }\n const result = Reflect.apply(originalFetch, this, [input, init]);\n recordWithoutAffectingHost(() => {\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n const rawUrl = readFetchUrl(input);\n if (\n isSpotPatchInternalUrl(\n rawUrl,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) ||\n policy.shouldObserveFetch?.(\n input,\n init,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) === false\n ) {\n return;\n }\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"fetch\",\n method: readFetchMethod(input, init),\n url: freezeUrl(rawUrl, target.location?.href ?? \"http://spotpatch.invalid/\"),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n return result;\n }\n\n const restoreFetch =\n originalFetch === undefined\n ? undefined\n : installWritableDataProperty(target, \"fetch\", spotPatchFetch);\n\n const xhrPrototype = (() => {\n try {\n return target.XMLHttpRequest?.prototype;\n } catch {\n return undefined;\n }\n })();\n const originalOpenDescriptor =\n xhrPrototype === undefined\n ? undefined\n : ownPropertyDescriptor(xhrPrototype, \"open\");\n const originalSendDescriptor =\n xhrPrototype === undefined\n ? undefined\n : ownPropertyDescriptor(xhrPrototype, \"send\");\n\n function spotPatchOpen(\n this: XMLHttpRequest,\n method: string,\n url: string | URL,\n ...rest: readonly unknown[]\n ): void {\n const original: unknown = originalOpenDescriptor?.value;\n if (typeof original === \"function\") {\n Reflect.apply(original, this, [method, url, ...rest]);\n }\n recordWithoutAffectingHost(() => {\n xhrMetadata.set(this, Object.freeze({ method, url: String(url) }));\n });\n }\n\n function spotPatchSend(\n this: XMLHttpRequest,\n body?: Document | XMLHttpRequestBodyInit | null,\n ): void {\n const original: unknown = originalSendDescriptor?.value;\n if (typeof original === \"function\") Reflect.apply(original, this, [body]);\n recordWithoutAffectingHost(() => {\n const metadata = xhrMetadata.get(this);\n if (\n metadata === undefined ||\n isSpotPatchInternalUrl(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) ||\n policy.shouldObserveXhr?.(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) === false\n ) {\n return;\n }\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"xhr\",\n method: metadata.method.toUpperCase(),\n url: freezeUrl(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n }\n\n const restoreXhrOpen =\n xhrPrototype === undefined || typeof originalOpenDescriptor?.value !== \"function\"\n ? undefined\n : installWritableDataProperty(\n xhrPrototype,\n \"open\",\n spotPatchOpen,\n originalOpenDescriptor,\n );\n const restoreXhrSend =\n xhrPrototype === undefined || typeof originalSendDescriptor?.value !== \"function\"\n ? undefined\n : installWritableDataProperty(\n xhrPrototype,\n \"send\",\n spotPatchSend,\n originalSendDescriptor,\n );\n\n const runtime: DataFlowRuntime = Object.freeze({\n beginInvocation(metadata: DataFlowTriggerMetadata): DataFlowInvocationToken {\n return Object.freeze({\n invocationId: nextInvocationId(),\n componentSourceId: metadata.componentSourceId,\n triggerCallsiteId: metadata.triggerCallsiteId,\n sourceVersion: metadata.sourceVersion,\n });\n },\n bindInvocation<Arguments extends readonly unknown[], Result>(\n token: DataFlowInvocationToken | undefined,\n callback: (...args: Arguments) => Result,\n ): (...args: Arguments) => Result {\n return function boundInvocation(this: unknown, ...args: Arguments): Result {\n return runtime.withInvocation(token, () => Reflect.apply(callback, this, args));\n };\n },\n bindTrigger<Callback>(\n metadata: DataFlowTriggerMetadata,\n callback: Callback,\n ): Callback {\n if (typeof callback !== \"function\") return callback;\n const callable = callback as (...args: readonly unknown[]) => unknown;\n return function boundTrigger(this: unknown, ...args: readonly unknown[]) {\n const token = runtime.beginInvocation(metadata);\n return runtime.withInvocation(token, () => Reflect.apply(callable, this, args));\n } as Callback;\n },\n captureInvocation: () => currentInvocation,\n clear: store.clear,\n createTrpcLink(): DataFlowTrpcLink {\n return () =>\n <Operation extends DataFlowTrpcOperation, Result>(\n options: DataFlowTrpcLinkOptions<Operation, Result>,\n ): Result => {\n recordWithoutAffectingHost(() => {\n const operation = options.op.path;\n const operationType = options.op.type;\n if (\n typeof operation !== \"string\" ||\n operation.length === 0 ||\n operation.length > 512 ||\n (operationType !== \"query\" &&\n operationType !== \"mutation\" &&\n operationType !== \"subscription\")\n ) {\n return;\n }\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"trpc\",\n method: operationType.toUpperCase(),\n operation,\n url: Object.freeze({\n pathname: operation,\n queryKeys: Object.freeze([]),\n }),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n return options.next(options.op);\n };\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n store.clear();\n restoreFetch?.();\n restoreXhrOpen?.();\n restoreXhrSend?.();\n },\n getComponentRegistration: (component: object) => componentRegistry.get(component),\n getCurrentRequestFrame: () => currentRequestFrame,\n observations: () =>\n Object.freeze(\n store\n .values()\n .map((observation) =>\n observation.routeEpoch === routeEpoch\n ? observation\n : Object.freeze({ ...observation, freshness: \"stale-route\" as const }),\n ),\n ),\n registerComponent(\n component: object,\n componentSourceId: string,\n registeredSourceVersion: string,\n ): void {\n const registration = Object.freeze({\n componentSourceId,\n sourceVersion: registeredSourceVersion,\n });\n const pending = [component];\n const registered = new Set<object>();\n while (pending.length > 0) {\n const candidate = pending.pop();\n if (candidate === undefined || registered.has(candidate)) continue;\n registered.add(candidate);\n componentRegistry.set(candidate, registration);\n\n const nested = nestedReactWrapperComponent(candidate);\n if (nested !== undefined) pending.push(nested);\n }\n },\n updateRoute(nextRouteKey: string): void {\n if (routeKey === undefined) {\n routeKey = nextRouteKey;\n } else if (routeKey !== nextRouteKey) {\n routeKey = nextRouteKey;\n routeEpoch = nextRouteEpoch();\n }\n },\n withInvocation<Result>(\n token: DataFlowInvocationToken | undefined,\n callback: () => Result,\n ): Result {\n const parent = currentInvocation;\n currentInvocation = token;\n try {\n return callback();\n } finally {\n currentInvocation = parent;\n }\n },\n withRequestFrame<Result>(\n token: DataFlowInvocationToken | undefined,\n metadata: DataFlowRequestMetadata,\n callback: () => Result,\n ): Result {\n const parent = currentRequestFrame;\n currentRequestFrame = Object.freeze({\n requestCallsiteId: metadata.requestCallsiteId,\n sourceVersion: metadata.sourceVersion,\n ...(token === undefined ? {} : { invocationToken: token }),\n });\n try {\n return callback();\n } finally {\n currentRequestFrame = parent;\n }\n },\n });\n\n return runtime;\n}\n\nexport function installDataFlowPrelude(\n config: RuntimeDataFlowConfig,\n target: GlobalWithDataFlow = globalThis,\n policy: DataFlowObservationPolicy = {},\n): DataFlowRuntime | undefined {\n if (!config.enabled) return undefined;\n const runtime = target[RUNTIME_KEY] ?? createDataFlowRuntime(config, target, policy);\n target[RUNTIME_KEY] = runtime;\n return runtime;\n}\n\nexport function getDataFlowRuntime(\n target: GlobalWithDataFlow = globalThis,\n): DataFlowRuntime | undefined {\n return target[RUNTIME_KEY];\n}\n\nexport function disposeDataFlowPrelude(\n runtime: DataFlowRuntime,\n target: GlobalWithDataFlow = globalThis,\n): void {\n if (target[RUNTIME_KEY] !== runtime) return;\n runtime.dispose();\n Reflect.deleteProperty(target, RUNTIME_KEY);\n}\n","import {\n isSensitiveName,\n limitDataFlowReportCollections,\n type ComponentDataFlowReport,\n type DataDependency,\n type EvidenceRef,\n type NetworkObservation,\n type PageDataFlowReport,\n} from \"@spotpatch/shared\";\n\nfunction observationMatchesDependency(\n observation: NetworkObservation,\n dependency: DataDependency,\n): boolean {\n const origin = dependency.origin;\n const transportMatches =\n dependency.kind === \"rpc\"\n ? observation.transport === \"trpc\" &&\n dependency.operation !== undefined &&\n observation.operation === dependency.operation\n : dependency.kind === \"http\"\n ? observation.transport === \"fetch\" || observation.transport === \"xhr\"\n : false;\n if (\n dependency.environment === \"server\" ||\n !transportMatches ||\n observation.freshness !== \"current\" ||\n origin === undefined ||\n observation.requestCallsiteId !== origin.requestCallsiteId ||\n observation.sourceVersion !== origin.sourceVersion ||\n (dependency.method !== undefined &&\n observation.method.toUpperCase() !== dependency.method.toUpperCase()) ||\n (dependency.url !== undefined &&\n observation.url.pathname !== dependency.url.pathname) ||\n (dependency.url?.origin !== undefined &&\n observation.url.origin !== dependency.url.origin) ||\n (origin.componentSourceId !== undefined &&\n observation.componentSourceId !== undefined &&\n observation.componentSourceId !== origin.componentSourceId) ||\n (origin.triggerCallsiteId !== undefined &&\n observation.triggerCallsiteId !== undefined &&\n observation.triggerCallsiteId !== origin.triggerCallsiteId)\n ) {\n return false;\n }\n\n return (\n dependency.association !== \"transitive\" ||\n (observation.componentSourceId === origin.componentSourceId &&\n observation.triggerCallsiteId === origin.triggerCallsiteId)\n );\n}\n\nfunction runtimeEvidence(observation: NetworkObservation): EvidenceRef {\n return Object.freeze({\n id: observation.id,\n kind: \"runtime-observation\",\n summaryKey: \"dataFlow.evidence.runtimeDispatch\",\n });\n}\n\nfunction mergeDependencies(\n dependencies: readonly DataDependency[],\n observations: readonly NetworkObservation[],\n): Readonly<{\n dependencies: readonly DataDependency[];\n matchedObservationIds: ReadonlySet<string>;\n}> {\n const matchedObservationIds = new Set<string>();\n const merged = dependencies.map((dependency) => {\n const matches = observations.filter((observation) =>\n observationMatchesDependency(observation, dependency),\n );\n for (const observation of matches) matchedObservationIds.add(observation.id);\n if (matches.length === 0) return dependency;\n const observedOrigins = [\n ...new Set(\n matches.flatMap(({ url }) => (url.origin === undefined ? [] : [url.origin])),\n ),\n ];\n const observedOrigin =\n observedOrigins.length === 1 ? observedOrigins[0] : undefined;\n return Object.freeze({\n ...dependency,\n ...(dependency.url === undefined ||\n dependency.url.origin !== undefined ||\n observedOrigin === undefined\n ? {}\n : {\n url: Object.freeze({\n ...dependency.url,\n origin: observedOrigin,\n }),\n }),\n execution: \"observed\" as const,\n observationIds: Object.freeze([\n ...new Set([...dependency.observationIds, ...matches.map(({ id }) => id)]),\n ]),\n evidenceIds: Object.freeze([\n ...new Set([...dependency.evidenceIds, ...matches.map(({ id }) => id)]),\n ]),\n });\n });\n return Object.freeze({\n dependencies: Object.freeze(merged),\n matchedObservationIds,\n });\n}\n\nfunction appendRuntimeEvidence(\n evidence: readonly EvidenceRef[],\n observations: readonly NetworkObservation[],\n matchedIds: ReadonlySet<string>,\n): readonly EvidenceRef[] {\n const existing = new Set(evidence.map(({ id }) => id));\n return Object.freeze([\n ...evidence,\n ...observations.flatMap((observation) =>\n matchedIds.has(observation.id) && !existing.has(observation.id)\n ? [runtimeEvidence(observation)]\n : [],\n ),\n ]);\n}\n\nexport function mergeComponentDataFlowReport(\n report: ComponentDataFlowReport,\n observations: readonly NetworkObservation[],\n): ComponentDataFlowReport {\n // A source-document report may contain several independently compiled browser\n // scopes. Accept only owners already proven by that authorized static report.\n const owners = new Set([\n report.component.componentSourceId,\n ...report.dependencies\n .filter((dependency) => dependency.environment !== \"server\")\n .map((dependency) => dependency.origin?.componentSourceId),\n ]);\n const componentObservations = observations.filter(\n (observation) =>\n observation.componentSourceId === undefined ||\n owners.has(observation.componentSourceId),\n );\n const merged = mergeDependencies(report.dependencies, componentObservations);\n return limitDataFlowReportCollections(\n Object.freeze({\n ...report,\n dependencies: merged.dependencies,\n evidence: appendRuntimeEvidence(\n report.evidence,\n componentObservations,\n merged.matchedObservationIds,\n ),\n }),\n { mode: \"observation\" },\n );\n}\n\nfunction unassignedDependency(observation: NetworkObservation): DataDependency {\n const isRpc = observation.transport === \"trpc\";\n return Object.freeze({\n id: observation.id,\n kind: isRpc ? \"rpc\" : \"http\",\n direction:\n observation.method === \"GET\" ||\n observation.method === \"HEAD\" ||\n observation.method === \"QUERY\" ||\n observation.method === \"SUBSCRIPTION\"\n ? \"read\"\n : \"write\",\n execution: \"observed\",\n proof: \"unavailable\",\n association: \"unassigned\",\n method: observation.method,\n ...(isRpc\n ? observation.operation === undefined\n ? {}\n : { operation: observation.operation }\n : { url: observation.url }),\n parameters: Object.freeze(\n (isRpc ? [] : observation.url.queryKeys).map((path) =>\n Object.freeze({\n path,\n position: \"query\" as const,\n sensitive: isSensitiveName(path),\n valueState: \"not-collected\" as const,\n evidenceIds: Object.freeze([observation.id]),\n }),\n ),\n ),\n response: Object.freeze({\n consumedFields: Object.freeze([]),\n }),\n suppliedBindings: Object.freeze([]),\n locationIds: Object.freeze([]),\n evidenceIds: Object.freeze([observation.id]),\n observationIds: Object.freeze([observation.id]),\n });\n}\n\nexport function mergePageDataFlowReport(\n report: PageDataFlowReport,\n observations: readonly NetworkObservation[],\n): PageDataFlowReport {\n const currentObservations = observations.filter(\n ({ freshness }) => freshness === \"current\",\n );\n const merged = mergeDependencies(report.dependencies, currentObservations);\n const unassigned = currentObservations\n .filter(({ id }) => !merged.matchedObservationIds.has(id))\n .map(unassignedDependency);\n const allObservationIds = new Set(currentObservations.map(({ id }) => id));\n return limitDataFlowReportCollections(\n Object.freeze({\n ...report,\n dependencies: Object.freeze([...merged.dependencies, ...unassigned]),\n evidence: appendRuntimeEvidence(\n report.evidence,\n currentObservations,\n allObservationIds,\n ),\n }),\n { mode: \"observation\" },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,sBAAsB;AAE5B,IAAM,aAAa,OAAO,OAAO;AAAA,EACtC,WAAW;AAAA,EACX,UAAU;AACZ,CAAC;AAEM,IAAM,0BAA0B,OAAO,OAAO;AAAA,EACnD,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,mBAAmB;AACrB,CAAC;;;ACbM,SAAS,oBACd,UACA,SAC0B;AAC1B,QAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,UAAQ,aAAa,qBAAqB,EAAE;AAC5C,SAAO;AACT;AAEO,SAAS,aACd,UACA,OACA,YAAY,IACO;AACnB,QAAM,SAAS,oBAAoB,UAAU,QAAQ;AACrD,SAAO,OAAO;AACd,SAAO,YAAY;AACnB,SAAO,cAAc;AACrB,SAAO;AACT;;;ACcA,IAAM,SAAS,OAAO,OAAO;AAAA,EAC3B,SAAS,OAAO,OAAO;AAAA,IACrB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,aAAa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AC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/data-flow-panel-entry.ts","../src/ui/ui-constants.ts","../src/ui/dom.ts","../src/ui/data-flow-panel.ts","../src/ui/data-flow-panel-contract.ts","../src/data-flow/data-flow-runtime.ts","../src/data-flow/report-merger.ts"],"sourcesContent":["export { createDataFlowPanel } from \"./ui/data-flow-panel.js\";\nexport {\n getDataFlowExtension,\n registerDataFlowExtension,\n type DataFlowExtension,\n type DataFlowPanel,\n type DataFlowPanelFactory,\n type DataFlowPanelSnapshot,\n type DataFlowPanelStatus,\n type DataFlowViewState,\n} from \"./ui/data-flow-panel-contract.js\";\n\nimport {\n getDataFlowRuntime,\n mergeComponentDataFlowReport,\n mergePageDataFlowReport,\n} from \"./data-flow-entry.js\";\nimport { createDataFlowPanel } from \"./ui/data-flow-panel.js\";\nimport { registerDataFlowExtension } from \"./ui/data-flow-panel-contract.js\";\n\nexport function installDataFlowPanelExtension(): void {\n registerDataFlowExtension(\n Object.freeze({\n createPanel: createDataFlowPanel,\n getComponentRegistration(component: object) {\n return getDataFlowRuntime()?.getComponentRegistration(component);\n },\n observations(routeKey: string) {\n const runtime = getDataFlowRuntime();\n runtime?.updateRoute(routeKey);\n return runtime?.observations() ?? Object.freeze([]);\n },\n mergeComponentReport: mergeComponentDataFlowReport,\n mergePageReport: mergePageDataFlowReport,\n }),\n );\n}\n","export const UI_MARKER_ATTRIBUTE = \"data-spotpatch-ui\" as const;\n\nexport const UI_Z_INDEX = Object.freeze({\n highlight: 2_147_483_646,\n controls: 2_147_483_647,\n});\n\nexport const FLOATING_SURFACE_LAYOUT = Object.freeze({\n compactInset: 8,\n compactViewportWidth: 520,\n desktopInset: 24,\n dragActivationDistance: 6,\n edgeSnapDistance: 20,\n workbenchMaxHeight: 620,\n workbenchMaxWidth: 460,\n});\n","import { UI_MARKER_ATTRIBUTE } from \"./ui-constants.js\";\n\nexport function createMarkedElement<K extends keyof HTMLElementTagNameMap>(\n document: Document,\n tagName: K,\n): HTMLElementTagNameMap[K] {\n const element = document.createElement(tagName);\n element.setAttribute(UI_MARKER_ATTRIBUTE, \"\");\n return element;\n}\n\nexport function createButton(\n document: Document,\n label: string,\n className = \"\",\n): HTMLButtonElement {\n const button = createMarkedElement(document, \"button\");\n button.type = \"button\";\n button.className = className;\n button.textContent = label;\n return button;\n}\n","import type { DataDependency, SpotPatchLocale } from \"@spotpatch/shared\";\n\nimport { createButton, createMarkedElement } from \"./dom.js\";\nimport type {\n DataFlowPanel,\n DataFlowPanelSnapshot,\n DataFlowViewState,\n} from \"./data-flow-panel-contract.js\";\n\ninterface Labels {\n readonly server: string;\n readonly client: string;\n readonly bindings: string;\n readonly changes: string;\n readonly componentEmpty: string;\n readonly componentTab: string;\n readonly componentTitle: string;\n readonly consumed: string;\n readonly declared: string;\n readonly diagnostics: string;\n readonly disabled: string;\n readonly error: string;\n readonly evidence: string;\n readonly loading: string;\n readonly logicalObserved: string;\n readonly noParameters: string;\n readonly observed: string;\n readonly pageEmpty: string;\n readonly pageTab: string;\n readonly pageTitle: string;\n readonly parameters: string;\n readonly refresh: string;\n readonly unknown: string;\n}\n\nconst LABELS = Object.freeze({\n \"zh-CN\": Object.freeze({\n server: \"服务端(静态证据)\",\n client: \"浏览器\",\n bindings: \"数据去向\",\n changes: \"修改说明\",\n componentEmpty: \"当前组件没有找到可证明的接口。未找到不等于没有请求。\",\n componentTab: \"数据链路\",\n componentTitle: \"组件数据链路\",\n consumed: \"读取字段\",\n declared: \"代码声明,尚未在本次页面会话中观测\",\n diagnostics: \"诊断\",\n disabled: \"数据链路能力未启用,请在插件配置中设置 dataFlow: {}。\",\n error: \"数据链路报告加载失败\",\n evidence: \"证据\",\n loading: \"正在分析源码并合并运行时证据…\",\n logicalObserved: \"本次会话已进入 tRPC 调用链\",\n noParameters: \"未提取到可证明的参数键\",\n observed: \"本次会话已实际请求\",\n pageEmpty: \"当前已选页面范围内没有静态接口或运行时网络记录。\",\n pageTab: \"页面接口\",\n pageTitle: \"页面接口\",\n parameters: \"请求参数\",\n refresh: \"刷新证据\",\n unknown: \"未知\",\n }),\n \"en-US\": Object.freeze({\n server: \"Server (static evidence)\",\n client: \"Browser\",\n bindings: \"Data destinations\",\n changes: \"Changes\",\n componentEmpty:\n \"No proven interface was found for this component. This does not prove that no request exists.\",\n componentTab: \"Data flow\",\n componentTitle: \"Component data flow\",\n consumed: \"Consumed fields\",\n declared: \"Declared in code, not observed in this page session\",\n diagnostics: \"Diagnostics\",\n disabled: \"Data flow is disabled. Set dataFlow: {} in the plugin options.\",\n error: \"Failed to load the data-flow report\",\n evidence: \"Evidence\",\n loading: \"Analyzing source and merging runtime evidence…\",\n logicalObserved: \"Dispatched through the tRPC link in this session\",\n noParameters: \"No proven parameter keys were extracted\",\n observed: \"Actually requested in this session\",\n pageEmpty:\n \"No static interface or runtime traffic is available for the selected page scope.\",\n pageTab: \"Page APIs\",\n pageTitle: \"Page interfaces\",\n parameters: \"Request parameters\",\n refresh: \"Refresh evidence\",\n unknown: \"Unknown\",\n }),\n}) satisfies Readonly<Record<SpotPatchLocale, Labels>>;\n\nfunction badge(document: Document, text: string, tone: string): HTMLElement {\n const element = createMarkedElement(document, \"span\");\n element.className = \"spotpatch-data-flow-badge\";\n element.dataset.tone = tone;\n element.textContent = text;\n return element;\n}\n\nfunction detailRow(document: Document, label: string, value: string): HTMLElement {\n const row = createMarkedElement(document, \"div\");\n row.className = \"spotpatch-data-flow-detail\";\n const key = createMarkedElement(document, \"span\");\n key.textContent = label;\n const content = createMarkedElement(document, \"code\");\n content.textContent = value;\n row.append(key, content);\n return row;\n}\n\nfunction renderDependency(\n document: Document,\n dependency: DataDependency,\n labels: Labels,\n): HTMLElement {\n const card = createMarkedElement(document, \"article\");\n card.className = \"spotpatch-data-flow-card\";\n const header = createMarkedElement(document, \"div\");\n header.className = \"spotpatch-data-flow-card-head\";\n const endpoint = createMarkedElement(document, \"div\");\n endpoint.className = \"spotpatch-data-flow-endpoint\";\n const method = createMarkedElement(document, \"strong\");\n method.textContent = dependency.method ?? labels.unknown;\n const path = createMarkedElement(document, \"code\");\n path.textContent =\n dependency.url === undefined\n ? (dependency.operation ?? labels.unknown)\n : `${dependency.url.origin ?? \"\"}${dependency.url.pathname}`;\n endpoint.append(method, path);\n const states = createMarkedElement(document, \"div\");\n states.className = \"spotpatch-data-flow-badges\";\n states.append(\n badge(\n document,\n dependency.execution === \"observed\"\n ? dependency.kind === \"rpc\"\n ? labels.logicalObserved\n : labels.observed\n : labels.declared,\n dependency.execution === \"observed\" ? \"success\" : \"neutral\",\n ),\n badge(\n document,\n dependency.proof,\n dependency.proof === \"proven\" ? \"proof\" : \"warning\",\n ),\n badge(document, dependency.association, \"neutral\"),\n );\n header.append(endpoint, states);\n if (dependency.environment !== undefined)\n states.append(badge(document, labels[dependency.environment], \"neutral\"));\n\n const parameters =\n dependency.parameters.length === 0\n ? labels.noParameters\n : dependency.parameters\n .map(\n (parameter) =>\n `${parameter.position}.${parameter.path}${parameter.type === undefined ? \"\" : `: ${parameter.type}`}${parameter.sensitive ? \" [sensitive]\" : \"\"}${parameter.condition === undefined ? \"\" : ` [when ${parameter.condition}]`}`,\n )\n .join(\"\\n\");\n const consumed =\n dependency.response.consumedFields.length === 0\n ? labels.unknown\n : dependency.response.consumedFields.join(\", \");\n const bindings =\n dependency.suppliedBindings.length === 0\n ? labels.unknown\n : dependency.suppliedBindings.join(\", \");\n const body = createMarkedElement(document, \"div\");\n body.className = \"spotpatch-data-flow-card-body\";\n const observationIds = new Set(dependency.observationIds);\n const staticEvidenceCount = dependency.evidenceIds.filter(\n (id) => !observationIds.has(id),\n ).length;\n body.append(\n detailRow(document, labels.parameters, parameters),\n detailRow(document, labels.consumed, consumed),\n detailRow(document, labels.bindings, bindings),\n detailRow(\n document,\n labels.evidence,\n `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`,\n ),\n );\n card.append(header, body);\n return card;\n}\n\nfunction createReportRoot(\n document: Document,\n titleText: string,\n): Readonly<{ root: HTMLElement; status: HTMLElement; list: HTMLElement }> {\n const root = createMarkedElement(document, \"section\");\n root.className = \"spotpatch-data-flow-panel\";\n const title = createMarkedElement(document, \"h3\");\n title.textContent = titleText;\n const status = createMarkedElement(document, \"p\");\n status.className = \"spotpatch-data-flow-status\";\n const list = createMarkedElement(document, \"div\");\n list.className = \"spotpatch-data-flow-list\";\n root.append(title, status, list);\n return Object.freeze({ root, status, list });\n}\n\nexport function createDataFlowPanel(\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n): DataFlowPanel {\n let labels = LABELS[locale()];\n const component = createReportRoot(document, labels.componentTitle);\n const page = createReportRoot(document, labels.pageTitle);\n const refreshButton = createButton(document, labels.refresh);\n const styles = document.createElement(\"style\");\n styles.textContent = DATA_FLOW_PANEL_STYLES;\n refreshButton.classList.add(\"spotpatch-data-flow-refresh\");\n component.root.prepend(refreshButton);\n const root = createMarkedElement(document, \"div\");\n const tabs = createMarkedElement(document, \"nav\");\n tabs.className = \"spotpatch-view-tabs\";\n tabs.setAttribute(\"aria-label\", \"SpotPatch views\");\n tabs.setAttribute(\"role\", \"tablist\");\n const views = new Map([\n [\"changes\", changesRoot],\n [\"component-data\", component.root],\n [\"page-data\", page.root],\n [\"diagnostics\", diagnosticsRoot],\n ]);\n const tabButtons = new Map<string, HTMLButtonElement>();\n let activeView = \"changes\";\n for (const id of views.keys()) {\n const button = createButton(document, \"\");\n button.dataset.viewId = id;\n button.id = `spotpatch-view-${id}-tab`;\n button.setAttribute(\"role\", \"tab\");\n button.setAttribute(\"aria-selected\", String(id === activeView));\n const view = views.get(id);\n view?.setAttribute(\"aria-labelledby\", button.id);\n view?.setAttribute(\"role\", \"tabpanel\");\n if (!enabled && (id === \"component-data\" || id === \"page-data\")) {\n button.hidden = true;\n }\n tabButtons.set(id, button);\n tabs.append(button);\n }\n root.append(tabs, ...views.values());\n\n function selectView(viewId: string): void {\n if (!views.has(viewId)) return;\n activeView = viewId;\n for (const [id, view] of views) {\n view.hidden = id !== viewId;\n const button = tabButtons.get(id);\n button?.setAttribute(\"aria-selected\", String(id === viewId));\n if (button !== undefined) button.tabIndex = id === viewId ? 0 : -1;\n }\n onViewChange();\n }\n\n function handleTabClick(event: Event): void {\n if (!(event.target instanceof HTMLButtonElement)) return;\n const viewId = event.target.dataset.viewId;\n if (viewId !== undefined) selectView(viewId);\n }\n\n tabs.addEventListener(\"click\", handleTabClick);\n selectView(activeView);\n\n function renderSnapshot(\n target: ReturnType<typeof createReportRoot>,\n snapshot: DataFlowPanelSnapshot,\n empty: string,\n ): void {\n target.list.replaceChildren();\n target.status.dataset.state = snapshot.status;\n if (!enabled || snapshot.status === \"disabled\") {\n target.status.textContent = labels.disabled;\n return;\n }\n if (snapshot.status === \"loading\") {\n target.status.textContent = labels.loading;\n return;\n }\n if (snapshot.status === \"error\") {\n target.status.textContent = snapshot.message ?? labels.error;\n return;\n }\n const report = snapshot.report;\n const diagnosticCodes =\n report === undefined\n ? \"\"\n : [...new Set(report.diagnostics.map(({ code }) => code))].join(\", \");\n const diagnosticSuffix =\n diagnosticCodes.length === 0\n ? \"\"\n : ` · ${labels.diagnostics}: ${diagnosticCodes}`;\n if (report === undefined || report.dependencies.length === 0) {\n target.status.textContent = `${empty}${diagnosticSuffix}`;\n return;\n }\n target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? \"complete\" : \"partial\"}${diagnosticSuffix}`;\n target.list.append(\n ...report.dependencies.map((dependency) =>\n renderDependency(document, dependency, labels),\n ),\n );\n }\n\n return Object.freeze({\n root,\n refreshButton,\n styles,\n dispose(): void {\n tabs.removeEventListener(\"click\", handleTabClick);\n },\n render(state: DataFlowViewState): void {\n labels = LABELS[locale()];\n const tabLabels = [\n labels.changes,\n labels.componentTab,\n labels.pageTab,\n labels.diagnostics,\n ];\n [...tabButtons.values()].forEach((button, index) => {\n button.textContent = tabLabels[index] ?? \"\";\n });\n refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;\n refreshButton.disabled = !enabled || state.component.status === \"loading\";\n renderSnapshot(component, state.component, labels.componentEmpty);\n renderSnapshot(page, state.page, labels.pageEmpty);\n },\n resetView(): void {\n selectView(\"changes\");\n },\n });\n}\n\nconst DATA_FLOW_PANEL_STYLES = `\n .spotpatch-view-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; padding: 3px; border: 1px solid rgb(255 255 255 / 7%); border-radius: 9px; background: rgb(3 7 18 / 42%); }\n .spotpatch-view-tabs button { min-width: 0; border: 0; border-radius: 7px; padding: 7px 5px; color: var(--spotpatch-text-muted); background: transparent; cursor: pointer; font-size: 10.5px; }\n .spotpatch-view-tabs button[aria-selected=\"true\"] { color: #f8fafc; background: rgb(139 124 247 / 18%); }\n .spotpatch-data-flow-panel { position: relative; }\n .spotpatch-data-flow-panel > h3 { margin: 0 0 3px; color: #f3f4f6; font-size: 13px; }\n .spotpatch-data-flow-refresh { position: absolute; top: -4px; right: 0; border: 1px solid rgb(139 124 247 / 30%); border-radius: 7px; padding: 4px 8px; color: #c4baff; background: rgb(139 124 247 / 8%); cursor: pointer; font-size: 10.5px; }\n .spotpatch-data-flow-refresh:disabled { cursor: not-allowed; opacity: .45; }\n .spotpatch-data-flow-status { margin: 0 0 10px; color: var(--spotpatch-text-muted); font-size: 10.5px; line-height: 1.5; }\n .spotpatch-data-flow-list { display: grid; gap: 8px; }\n .spotpatch-data-flow-card { overflow: hidden; border: 1px solid rgb(255 255 255 / 8%); border-radius: 9px; background: rgb(255 255 255 / 2.5%); }\n .spotpatch-data-flow-card-head { display: grid; gap: 7px; padding: 10px; border-bottom: 1px solid rgb(255 255 255 / 7%); }\n .spotpatch-data-flow-endpoint { display: flex; min-width: 0; align-items: center; gap: 8px; }\n .spotpatch-data-flow-endpoint strong { color: #79d9e7; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }\n .spotpatch-data-flow-endpoint code { min-width: 0; overflow: hidden; color: #f8fafc; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }\n .spotpatch-data-flow-badges { display: flex; flex-wrap: wrap; gap: 4px; }\n .spotpatch-data-flow-badge { border-radius: 999px; padding: 2px 6px; color: #9ca3af; background: rgb(255 255 255 / 5%); font-size: 9px; }\n .spotpatch-data-flow-badge[data-tone=\"success\"] { color: #6ee7b7; background: rgb(16 185 129 / 10%); }\n .spotpatch-data-flow-badge[data-tone=\"proof\"] { color: #c4b5fd; background: rgb(139 92 246 / 11%); }\n .spotpatch-data-flow-badge[data-tone=\"warning\"] { color: #fcd34d; background: rgb(245 158 11 / 10%); }\n .spotpatch-data-flow-card-body { display: grid; gap: 7px; padding: 10px; }\n .spotpatch-data-flow-detail { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px; align-items: start; }\n .spotpatch-data-flow-detail > span { color: var(--spotpatch-text-muted); font-size: 10px; }\n .spotpatch-data-flow-detail > code { overflow-wrap: anywhere; color: #cbd5e1; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }\n`;\n","import type {\n ComponentDataFlowReport,\n NetworkObservation,\n PageDataFlowReport,\n SpotPatchLocale,\n} from \"@spotpatch/shared\";\n\nimport type { DataFlowComponentRegistration } from \"../data-flow/data-flow-runtime.js\";\n\nexport type DataFlowPanelStatus = \"disabled\" | \"idle\" | \"loading\" | \"ready\" | \"error\";\n\nexport interface DataFlowPanelSnapshot {\n readonly status: DataFlowPanelStatus;\n readonly report?: ComponentDataFlowReport | PageDataFlowReport;\n readonly message?: string;\n}\n\nexport interface DataFlowViewState {\n readonly component: DataFlowPanelSnapshot;\n readonly page: DataFlowPanelSnapshot;\n readonly observationCount: number;\n}\n\nexport interface DataFlowPanel {\n readonly root: HTMLElement;\n readonly refreshButton: HTMLButtonElement;\n readonly styles: HTMLStyleElement;\n readonly dispose: () => void;\n readonly render: (state: DataFlowViewState) => void;\n readonly resetView: () => void;\n}\n\nexport type DataFlowPanelFactory = (\n document: Document,\n enabled: boolean,\n locale: () => SpotPatchLocale,\n changesRoot: HTMLElement,\n diagnosticsRoot: HTMLElement,\n onViewChange: () => void,\n) => DataFlowPanel;\n\nexport interface DataFlowExtension {\n readonly createPanel: DataFlowPanelFactory;\n readonly getComponentRegistration: (\n component: object,\n ) => DataFlowComponentRegistration | undefined;\n readonly observations: (routeKey: string) => readonly NetworkObservation[];\n readonly mergeComponentReport: (\n report: ComponentDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => ComponentDataFlowReport;\n readonly mergePageReport: (\n report: PageDataFlowReport,\n observations: readonly NetworkObservation[],\n ) => PageDataFlowReport;\n}\n\nconst DATA_FLOW_EXTENSION_KEY = Symbol.for(\"spotpatch.data-flow.extension.v1\");\ntype ExtensionStore = Partial<Record<symbol, DataFlowExtension>>;\n\nexport function registerDataFlowExtension(\n extension: DataFlowExtension,\n target: ExtensionStore = globalThis,\n): void {\n target[DATA_FLOW_EXTENSION_KEY] = extension;\n}\n\nexport function getDataFlowExtension(\n target: ExtensionStore = globalThis,\n): DataFlowExtension | undefined {\n return target[DATA_FLOW_EXTENSION_KEY];\n}\n","import {\n DATA_FLOW_SCHEMA_VERSION,\n DATA_FLOW_URL_QUERY_KEY_LIMIT,\n SPOTPATCH_API_BASE,\n type NetworkObservation,\n type RuntimeDataFlowConfig,\n type RuntimeDataFlowLimits,\n type SanitizedObservedUrl,\n} from \"@spotpatch/shared/data-flow-runtime\";\n\nexport interface DataFlowComponentRegistration {\n readonly componentSourceId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowInvocationToken {\n readonly invocationId: string;\n readonly componentSourceId: string;\n readonly triggerCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRequestFrame {\n readonly requestCallsiteId: string;\n readonly sourceVersion: string;\n readonly invocationToken?: DataFlowInvocationToken;\n}\n\nexport interface DataFlowTriggerMetadata {\n readonly componentSourceId: string;\n readonly triggerCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRequestMetadata {\n readonly requestCallsiteId: string;\n readonly sourceVersion: string;\n}\n\nexport interface DataFlowRuntime {\n readonly beginInvocation: (\n metadata: DataFlowTriggerMetadata,\n ) => DataFlowInvocationToken;\n readonly bindInvocation: <Arguments extends readonly unknown[], Result>(\n token: DataFlowInvocationToken | undefined,\n callback: (...args: Arguments) => Result,\n ) => (...args: Arguments) => Result;\n readonly bindTrigger: <Callback>(\n metadata: DataFlowTriggerMetadata,\n callback: Callback,\n ) => Callback;\n readonly captureInvocation: () => DataFlowInvocationToken | undefined;\n readonly clear: () => void;\n readonly createTrpcLink: () => DataFlowTrpcLink;\n readonly dispose: () => void;\n readonly getComponentRegistration: (\n component: object,\n ) => DataFlowComponentRegistration | undefined;\n readonly getCurrentRequestFrame: () => DataFlowRequestFrame | undefined;\n readonly observations: () => readonly NetworkObservation[];\n readonly updateRoute: (routeKey: string) => void;\n readonly registerComponent: (\n component: object,\n componentSourceId: string,\n sourceVersion: string,\n ) => void;\n readonly withInvocation: <Result>(\n token: DataFlowInvocationToken | undefined,\n callback: () => Result,\n ) => Result;\n readonly withRequestFrame: <Result>(\n token: DataFlowInvocationToken | undefined,\n metadata: DataFlowRequestMetadata,\n callback: () => Result,\n ) => Result;\n}\n\nexport interface DataFlowObservationPolicy {\n readonly shouldObserveFetch?: (\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n baseUrl: string,\n ) => boolean;\n readonly shouldObserveXhr?: (url: string, baseUrl: string) => boolean;\n}\n\nexport interface DataFlowTrpcOperation {\n readonly path: unknown;\n readonly type: unknown;\n}\n\nexport interface DataFlowTrpcLinkOptions<\n Operation extends DataFlowTrpcOperation,\n Result,\n> {\n readonly next: (operation: Operation) => Result;\n readonly op: Operation;\n}\n\nexport type DataFlowTrpcLink = (\n runtime: unknown,\n) => <Operation extends DataFlowTrpcOperation, Result>(\n options: DataFlowTrpcLinkOptions<Operation, Result>,\n) => Result;\n\ninterface DataFlowGlobal {\n readonly fetch?: typeof globalThis.fetch;\n readonly location?: Location;\n readonly performance?: Performance;\n readonly XMLHttpRequest?: typeof globalThis.XMLHttpRequest;\n}\n\ninterface MutableDataFlowGlobal extends DataFlowGlobal {\n fetch?: typeof globalThis.fetch;\n}\n\ninterface XhrMetadata {\n readonly method: string;\n readonly url: string;\n}\n\ninterface RingEntry {\n readonly bytes: number;\n readonly observation: NetworkObservation;\n readonly recordedAt: number;\n}\n\nconst RUNTIME_KEY: unique symbol = Symbol.for(\n \"spotpatch.data-flow.runtime.v1\",\n) as never;\nconst REACT_MEMO_TYPE = Symbol.for(\"react.memo\");\nconst REACT_FORWARD_REF_TYPE = Symbol.for(\"react.forward_ref\");\n\ntype DataFlowRuntimeStore = Partial<Record<symbol, DataFlowRuntime>>;\ntype GlobalWithDataFlow = MutableDataFlowGlobal & DataFlowRuntimeStore;\n\nfunction positiveNow(target: DataFlowGlobal): number {\n return target.performance?.now() ?? Date.now();\n}\n\nfunction createOpaqueSequence(prefix: string): () => string {\n let sequence = 0;\n const randomPrefix = (() => {\n try {\n const bytes = new Uint8Array(8);\n globalThis.crypto.getRandomValues(bytes);\n return Array.from(bytes, (value) => value.toString(36).padStart(2, \"0\")).join(\"\");\n } catch {\n return \"local\";\n }\n })();\n\n return () => {\n sequence += 1;\n return `${prefix}_${randomPrefix}_${sequence.toString(36)}`;\n };\n}\n\nfunction freezeUrl(value: string, baseUrl: string): SanitizedObservedUrl {\n try {\n const url = new URL(value, baseUrl);\n return Object.freeze({\n origin: url.origin,\n pathname: url.pathname,\n queryKeys: Object.freeze(\n [...new Set(url.searchParams.keys())]\n .sort()\n .slice(0, DATA_FLOW_URL_QUERY_KEY_LIMIT),\n ),\n });\n } catch {\n return Object.freeze({\n pathname: value.split(/[?#]/u, 1)[0] ?? \"{invalid}\",\n queryKeys: Object.freeze([]),\n });\n }\n}\n\nfunction readFetchUrl(input: RequestInfo | URL): string {\n if (typeof input === \"string\") return input;\n if (input instanceof URL) return input.toString();\n return input.url;\n}\n\nfunction readFetchMethod(input: RequestInfo | URL, init?: RequestInit): string {\n if (init?.method !== undefined) return init.method.toUpperCase();\n return typeof Request !== \"undefined\" && input instanceof Request\n ? input.method.toUpperCase()\n : \"GET\";\n}\n\nfunction isSpotPatchInternalUrl(value: string, baseUrl: string): boolean {\n try {\n const pathname = new URL(value, baseUrl).pathname;\n return (\n pathname === SPOTPATCH_API_BASE || pathname.startsWith(`${SPOTPATCH_API_BASE}/`)\n );\n } catch {\n return false;\n }\n}\n\nfunction approximateBytes(value: unknown): number {\n return new TextEncoder().encode(JSON.stringify(value)).byteLength;\n}\n\nfunction createRingStore(\n limits: RuntimeDataFlowLimits,\n target: DataFlowGlobal,\n): Readonly<{\n add: (observation: NetworkObservation) => void;\n clear: () => void;\n values: () => readonly NetworkObservation[];\n}> {\n const entries: RingEntry[] = [];\n let totalBytes = 0;\n\n function removeExpired(now: number): void {\n while (\n entries[0] !== undefined &&\n now - entries[0].recordedAt > limits.observationTtlMs\n ) {\n const removed = entries.shift();\n if (removed !== undefined) totalBytes -= removed.bytes;\n }\n }\n\n return Object.freeze({\n add(observation): void {\n const now = positiveNow(target);\n removeExpired(now);\n const bytes = approximateBytes(observation);\n if (bytes > limits.observationMaxBytes) return;\n entries.push(Object.freeze({ bytes, observation, recordedAt: now }));\n totalBytes += bytes;\n\n while (\n entries.length > limits.observationMaxEntries ||\n totalBytes > limits.observationMaxBytes\n ) {\n const removed = entries.shift();\n if (removed !== undefined) totalBytes -= removed.bytes;\n }\n },\n clear(): void {\n entries.length = 0;\n totalBytes = 0;\n },\n values(): readonly NetworkObservation[] {\n removeExpired(positiveNow(target));\n return Object.freeze(entries.map(({ observation }) => observation));\n },\n });\n}\n\nfunction ownPropertyDescriptor(\n target: object,\n key: PropertyKey,\n): PropertyDescriptor | undefined {\n try {\n return Object.getOwnPropertyDescriptor(target, key);\n } catch {\n return undefined;\n }\n}\n\nfunction nestedReactWrapperComponent(candidate: object): object | undefined {\n const marker: unknown = ownPropertyDescriptor(candidate, \"$$typeof\")?.value;\n const key =\n marker === REACT_MEMO_TYPE\n ? \"type\"\n : marker === REACT_FORWARD_REF_TYPE\n ? \"render\"\n : undefined;\n if (key === undefined) return undefined;\n const nested: unknown = ownPropertyDescriptor(candidate, key)?.value;\n return (typeof nested === \"object\" && nested !== null) || typeof nested === \"function\"\n ? nested\n : undefined;\n}\n\nfunction installWritableDataProperty(\n target: object,\n key: PropertyKey,\n replacement: object,\n original: PropertyDescriptor | undefined = ownPropertyDescriptor(target, key),\n): (() => void) | undefined {\n if (original === undefined || !(\"value\" in original) || !original.writable) {\n return undefined;\n }\n\n try {\n Object.defineProperty(target, key, { ...original, value: replacement });\n } catch {\n return undefined;\n }\n\n return (): void => {\n try {\n if (ownPropertyDescriptor(target, key)?.value === replacement) {\n Object.defineProperty(target, key, original);\n }\n } catch {\n // A host or later wrapper can make the property non-configurable.\n }\n };\n}\n\nfunction recordWithoutAffectingHost(record: () => void): void {\n try {\n record();\n } catch {\n // Observation is optional; the host transport result is authoritative.\n }\n}\n\nexport function createDataFlowRuntime(\n config: RuntimeDataFlowConfig,\n target: MutableDataFlowGlobal = globalThis,\n policy: DataFlowObservationPolicy = {},\n): DataFlowRuntime {\n const componentRegistry = new WeakMap<object, DataFlowComponentRegistration>();\n const xhrMetadata = new WeakMap<object, XhrMetadata>();\n const store = createRingStore(config.limits, target);\n const nextInvocationId = createOpaqueSequence(\"invocation\");\n const nextObservationId = createOpaqueSequence(\"observation\");\n const pageEpoch = createOpaqueSequence(\"page\")();\n const nextRouteEpoch = createOpaqueSequence(\"route\");\n let routeEpoch = nextRouteEpoch();\n let routeKey: string | undefined;\n let currentInvocation: DataFlowInvocationToken | undefined;\n let currentRequestFrame: DataFlowRequestFrame | undefined;\n let disposed = false;\n\n const originalFetch = (() => {\n try {\n return target.fetch;\n } catch {\n return undefined;\n }\n })();\n function spotPatchFetch(\n this: typeof globalThis,\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> {\n if (originalFetch === undefined) {\n throw new TypeError(\"Fetch is unavailable.\");\n }\n const result = Reflect.apply(originalFetch, this, [input, init]);\n recordWithoutAffectingHost(() => {\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n const rawUrl = readFetchUrl(input);\n if (\n isSpotPatchInternalUrl(\n rawUrl,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) ||\n policy.shouldObserveFetch?.(\n input,\n init,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) === false\n ) {\n return;\n }\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"fetch\",\n method: readFetchMethod(input, init),\n url: freezeUrl(rawUrl, target.location?.href ?? \"http://spotpatch.invalid/\"),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n return result;\n }\n\n const restoreFetch =\n originalFetch === undefined\n ? undefined\n : installWritableDataProperty(target, \"fetch\", spotPatchFetch);\n\n const xhrPrototype = (() => {\n try {\n return target.XMLHttpRequest?.prototype;\n } catch {\n return undefined;\n }\n })();\n const originalOpenDescriptor =\n xhrPrototype === undefined\n ? undefined\n : ownPropertyDescriptor(xhrPrototype, \"open\");\n const originalSendDescriptor =\n xhrPrototype === undefined\n ? undefined\n : ownPropertyDescriptor(xhrPrototype, \"send\");\n\n function spotPatchOpen(\n this: XMLHttpRequest,\n method: string,\n url: string | URL,\n ...rest: readonly unknown[]\n ): void {\n const original: unknown = originalOpenDescriptor?.value;\n if (typeof original === \"function\") {\n Reflect.apply(original, this, [method, url, ...rest]);\n }\n recordWithoutAffectingHost(() => {\n xhrMetadata.set(this, Object.freeze({ method, url: String(url) }));\n });\n }\n\n function spotPatchSend(\n this: XMLHttpRequest,\n body?: Document | XMLHttpRequestBodyInit | null,\n ): void {\n const original: unknown = originalSendDescriptor?.value;\n if (typeof original === \"function\") Reflect.apply(original, this, [body]);\n recordWithoutAffectingHost(() => {\n const metadata = xhrMetadata.get(this);\n if (\n metadata === undefined ||\n isSpotPatchInternalUrl(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) ||\n policy.shouldObserveXhr?.(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ) === false\n ) {\n return;\n }\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"xhr\",\n method: metadata.method.toUpperCase(),\n url: freezeUrl(\n metadata.url,\n target.location?.href ?? \"http://spotpatch.invalid/\",\n ),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n }\n\n const restoreXhrOpen =\n xhrPrototype === undefined || typeof originalOpenDescriptor?.value !== \"function\"\n ? undefined\n : installWritableDataProperty(\n xhrPrototype,\n \"open\",\n spotPatchOpen,\n originalOpenDescriptor,\n );\n const restoreXhrSend =\n xhrPrototype === undefined || typeof originalSendDescriptor?.value !== \"function\"\n ? undefined\n : installWritableDataProperty(\n xhrPrototype,\n \"send\",\n spotPatchSend,\n originalSendDescriptor,\n );\n\n const runtime: DataFlowRuntime = Object.freeze({\n beginInvocation(metadata: DataFlowTriggerMetadata): DataFlowInvocationToken {\n return Object.freeze({\n invocationId: nextInvocationId(),\n componentSourceId: metadata.componentSourceId,\n triggerCallsiteId: metadata.triggerCallsiteId,\n sourceVersion: metadata.sourceVersion,\n });\n },\n bindInvocation<Arguments extends readonly unknown[], Result>(\n token: DataFlowInvocationToken | undefined,\n callback: (...args: Arguments) => Result,\n ): (...args: Arguments) => Result {\n return function boundInvocation(this: unknown, ...args: Arguments): Result {\n return runtime.withInvocation(token, () => Reflect.apply(callback, this, args));\n };\n },\n bindTrigger<Callback>(\n metadata: DataFlowTriggerMetadata,\n callback: Callback,\n ): Callback {\n if (typeof callback !== \"function\") return callback;\n const callable = callback as (...args: readonly unknown[]) => unknown;\n return function boundTrigger(this: unknown, ...args: readonly unknown[]) {\n const token = runtime.beginInvocation(metadata);\n return runtime.withInvocation(token, () => Reflect.apply(callable, this, args));\n } as Callback;\n },\n captureInvocation: () => currentInvocation,\n clear: store.clear,\n createTrpcLink(): DataFlowTrpcLink {\n return () =>\n <Operation extends DataFlowTrpcOperation, Result>(\n options: DataFlowTrpcLinkOptions<Operation, Result>,\n ): Result => {\n recordWithoutAffectingHost(() => {\n const operation = options.op.path;\n const operationType = options.op.type;\n if (\n typeof operation !== \"string\" ||\n operation.length === 0 ||\n operation.length > 512 ||\n (operationType !== \"query\" &&\n operationType !== \"mutation\" &&\n operationType !== \"subscription\")\n ) {\n return;\n }\n const frame = currentRequestFrame;\n const token = frame?.invocationToken;\n store.add(\n Object.freeze({\n schemaVersion: DATA_FLOW_SCHEMA_VERSION,\n id: nextObservationId(),\n pageEpoch,\n routeEpoch,\n ...(frame === undefined\n ? {}\n : {\n requestCallsiteId: frame.requestCallsiteId,\n sourceVersion: frame.sourceVersion,\n }),\n ...(token === undefined\n ? {}\n : {\n invocationId: token.invocationId,\n componentSourceId: token.componentSourceId,\n triggerCallsiteId: token.triggerCallsiteId,\n }),\n transport: \"trpc\",\n method: operationType.toUpperCase(),\n operation,\n url: Object.freeze({\n pathname: operation,\n queryKeys: Object.freeze([]),\n }),\n outcome: \"dispatched\",\n freshness: \"current\",\n diagnosticIds: Object.freeze([]),\n }),\n );\n });\n return options.next(options.op);\n };\n },\n dispose(): void {\n if (disposed) return;\n disposed = true;\n store.clear();\n restoreFetch?.();\n restoreXhrOpen?.();\n restoreXhrSend?.();\n },\n getComponentRegistration: (component: object) => componentRegistry.get(component),\n getCurrentRequestFrame: () => currentRequestFrame,\n observations: () =>\n Object.freeze(\n store\n .values()\n .map((observation) =>\n observation.routeEpoch === routeEpoch\n ? observation\n : Object.freeze({ ...observation, freshness: \"stale-route\" as const }),\n ),\n ),\n registerComponent(\n component: object,\n componentSourceId: string,\n registeredSourceVersion: string,\n ): void {\n const registration = Object.freeze({\n componentSourceId,\n sourceVersion: registeredSourceVersion,\n });\n const pending = [component];\n const registered = new Set<object>();\n while (pending.length > 0) {\n const candidate = pending.pop();\n if (candidate === undefined || registered.has(candidate)) continue;\n registered.add(candidate);\n componentRegistry.set(candidate, registration);\n\n const nested = nestedReactWrapperComponent(candidate);\n if (nested !== undefined) pending.push(nested);\n }\n },\n updateRoute(nextRouteKey: string): void {\n if (routeKey === undefined) {\n routeKey = nextRouteKey;\n } else if (routeKey !== nextRouteKey) {\n routeKey = nextRouteKey;\n routeEpoch = nextRouteEpoch();\n }\n },\n withInvocation<Result>(\n token: DataFlowInvocationToken | undefined,\n callback: () => Result,\n ): Result {\n const parent = currentInvocation;\n currentInvocation = token;\n try {\n return callback();\n } finally {\n currentInvocation = parent;\n }\n },\n withRequestFrame<Result>(\n token: DataFlowInvocationToken | undefined,\n metadata: DataFlowRequestMetadata,\n callback: () => Result,\n ): Result {\n const parent = currentRequestFrame;\n currentRequestFrame = Object.freeze({\n requestCallsiteId: metadata.requestCallsiteId,\n sourceVersion: metadata.sourceVersion,\n ...(token === undefined ? {} : { invocationToken: token }),\n });\n try {\n return callback();\n } finally {\n currentRequestFrame = parent;\n }\n },\n });\n\n return runtime;\n}\n\nexport function installDataFlowPrelude(\n config: RuntimeDataFlowConfig,\n target: GlobalWithDataFlow = globalThis,\n policy: DataFlowObservationPolicy = {},\n): DataFlowRuntime | undefined {\n if (!config.enabled) return undefined;\n const runtime = target[RUNTIME_KEY] ?? createDataFlowRuntime(config, target, policy);\n target[RUNTIME_KEY] = runtime;\n return runtime;\n}\n\nexport function getDataFlowRuntime(\n target: GlobalWithDataFlow = globalThis,\n): DataFlowRuntime | undefined {\n return target[RUNTIME_KEY];\n}\n\nexport function disposeDataFlowPrelude(\n runtime: DataFlowRuntime,\n target: GlobalWithDataFlow = globalThis,\n): void {\n if (target[RUNTIME_KEY] !== runtime) return;\n runtime.dispose();\n Reflect.deleteProperty(target, RUNTIME_KEY);\n}\n","import {\n isSensitiveName,\n limitDataFlowReportCollections,\n type ComponentDataFlowReport,\n type DataDependency,\n type EvidenceRef,\n type NetworkObservation,\n type PageDataFlowReport,\n} from \"@spotpatch/shared\";\n\nfunction observationMatchesDependency(\n observation: NetworkObservation,\n dependency: DataDependency,\n): boolean {\n const origin = dependency.origin;\n const transportMatches =\n dependency.kind === \"rpc\"\n ? observation.transport === \"trpc\" &&\n dependency.operation !== undefined &&\n observation.operation === dependency.operation\n : dependency.kind === \"http\"\n ? observation.transport === \"fetch\" || observation.transport === \"xhr\"\n : false;\n if (\n dependency.environment === \"server\" ||\n !transportMatches ||\n observation.freshness !== \"current\" ||\n origin === undefined ||\n observation.requestCallsiteId !== origin.requestCallsiteId ||\n observation.sourceVersion !== origin.sourceVersion ||\n (dependency.method !== undefined &&\n observation.method.toUpperCase() !== dependency.method.toUpperCase()) ||\n (dependency.url !== undefined &&\n observation.url.pathname !== dependency.url.pathname) ||\n (dependency.url?.origin !== undefined &&\n observation.url.origin !== dependency.url.origin) ||\n (origin.componentSourceId !== undefined &&\n observation.componentSourceId !== undefined &&\n observation.componentSourceId !== origin.componentSourceId) ||\n (origin.triggerCallsiteId !== undefined &&\n observation.triggerCallsiteId !== undefined &&\n observation.triggerCallsiteId !== origin.triggerCallsiteId)\n ) {\n return false;\n }\n\n return (\n dependency.association !== \"transitive\" ||\n (observation.componentSourceId === origin.componentSourceId &&\n observation.triggerCallsiteId === origin.triggerCallsiteId)\n );\n}\n\nfunction runtimeEvidence(observation: NetworkObservation): EvidenceRef {\n return Object.freeze({\n id: observation.id,\n kind: \"runtime-observation\",\n summaryKey: \"dataFlow.evidence.runtimeDispatch\",\n });\n}\n\nfunction mergeDependencies(\n dependencies: readonly DataDependency[],\n observations: readonly NetworkObservation[],\n): Readonly<{\n dependencies: readonly DataDependency[];\n matchedObservationIds: ReadonlySet<string>;\n}> {\n const matchedObservationIds = new Set<string>();\n const merged = dependencies.map((dependency) => {\n const matches = observations.filter((observation) =>\n observationMatchesDependency(observation, dependency),\n );\n for (const observation of matches) matchedObservationIds.add(observation.id);\n if (matches.length === 0) return dependency;\n const observedOrigins = [\n ...new Set(\n matches.flatMap(({ url }) => (url.origin === undefined ? [] : [url.origin])),\n ),\n ];\n const observedOrigin =\n observedOrigins.length === 1 ? observedOrigins[0] : undefined;\n return Object.freeze({\n ...dependency,\n ...(dependency.url === undefined ||\n dependency.url.origin !== undefined ||\n observedOrigin === undefined\n ? {}\n : {\n url: Object.freeze({\n ...dependency.url,\n origin: observedOrigin,\n }),\n }),\n execution: \"observed\" as const,\n observationIds: Object.freeze([\n ...new Set([...dependency.observationIds, ...matches.map(({ id }) => id)]),\n ]),\n evidenceIds: Object.freeze([\n ...new Set([...dependency.evidenceIds, ...matches.map(({ id }) => id)]),\n ]),\n });\n });\n return Object.freeze({\n dependencies: Object.freeze(merged),\n matchedObservationIds,\n });\n}\n\nfunction appendRuntimeEvidence(\n evidence: readonly EvidenceRef[],\n observations: readonly NetworkObservation[],\n matchedIds: ReadonlySet<string>,\n): readonly EvidenceRef[] {\n const existing = new Set(evidence.map(({ id }) => id));\n return Object.freeze([\n ...evidence,\n ...observations.flatMap((observation) =>\n matchedIds.has(observation.id) && !existing.has(observation.id)\n ? [runtimeEvidence(observation)]\n : [],\n ),\n ]);\n}\n\nexport function mergeComponentDataFlowReport(\n report: ComponentDataFlowReport,\n observations: readonly NetworkObservation[],\n): ComponentDataFlowReport {\n // A source-document report may contain several independently compiled browser\n // scopes. Accept only owners already proven by that authorized static report.\n const owners = new Set([\n report.component.componentSourceId,\n ...report.dependencies\n .filter((dependency) => dependency.environment !== \"server\")\n .map((dependency) => dependency.origin?.componentSourceId),\n ]);\n const componentObservations = observations.filter(\n (observation) =>\n observation.componentSourceId === undefined ||\n owners.has(observation.componentSourceId),\n );\n const merged = mergeDependencies(report.dependencies, componentObservations);\n return limitDataFlowReportCollections(\n Object.freeze({\n ...report,\n dependencies: merged.dependencies,\n evidence: appendRuntimeEvidence(\n report.evidence,\n componentObservations,\n merged.matchedObservationIds,\n ),\n }),\n { mode: \"observation\" },\n );\n}\n\nfunction unassignedDependency(observation: NetworkObservation): DataDependency {\n const isRpc = observation.transport === \"trpc\";\n return Object.freeze({\n id: observation.id,\n kind: isRpc ? \"rpc\" : \"http\",\n direction:\n observation.method === \"GET\" ||\n observation.method === \"HEAD\" ||\n observation.method === \"QUERY\" ||\n observation.method === \"SUBSCRIPTION\"\n ? \"read\"\n : \"write\",\n execution: \"observed\",\n proof: \"unavailable\",\n association: \"unassigned\",\n method: observation.method,\n ...(isRpc\n ? observation.operation === undefined\n ? {}\n : { operation: observation.operation }\n : { url: observation.url }),\n parameters: Object.freeze(\n (isRpc ? [] : observation.url.queryKeys).map((path) =>\n Object.freeze({\n path,\n position: \"query\" as const,\n sensitive: isSensitiveName(path),\n valueState: \"not-collected\" as const,\n evidenceIds: Object.freeze([observation.id]),\n }),\n ),\n ),\n response: Object.freeze({\n consumedFields: Object.freeze([]),\n }),\n suppliedBindings: Object.freeze([]),\n locationIds: Object.freeze([]),\n evidenceIds: Object.freeze([observation.id]),\n observationIds: Object.freeze([observation.id]),\n });\n}\n\nexport function mergePageDataFlowReport(\n report: PageDataFlowReport,\n observations: readonly NetworkObservation[],\n): PageDataFlowReport {\n const currentObservations = observations.filter(\n ({ freshness }) => freshness === \"current\",\n );\n const merged = mergeDependencies(report.dependencies, currentObservations);\n const unassigned = currentObservations\n .filter(({ id }) => !merged.matchedObservationIds.has(id))\n .map(unassignedDependency);\n const allObservationIds = new Set(currentObservations.map(({ id }) => id));\n return limitDataFlowReportCollections(\n Object.freeze({\n ...report,\n dependencies: Object.freeze([...merged.dependencies, ...unassigned]),\n evidence: appendRuntimeEvidence(\n report.evidence,\n currentObservations,\n allObservationIds,\n ),\n }),\n { mode: \"observation\" },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,sBAAsB;AAE5B,IAAM,aAAa,OAAO,OAAO;AAAA,EACtC,WAAW;AAAA,EACX,UAAU;AACZ,CAAC;AAEM,IAAM,0BAA0B,OAAO,OAAO;AAAA,EACnD,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,mBAAmB;AACrB,CAAC;;;ACbM,SAAS,oBACd,UACA,SAC0B;AAC1B,QAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,UAAQ,aAAa,qBAAqB,EAAE;AAC5C,SAAO;AACT;AAEO,SAAS,aACd,UACA,OACA,YAAY,IACO;AACnB,QAAM,SAAS,oBAAoB,UAAU,QAAQ;AACrD,SAAO,OAAO;AACd,SAAO,YAAY;AACnB,SAAO,cAAc;AACrB,SAAO;AACT;;;ACcA,IAAM,SAAS,OAAO,OAAO;AAAA,EAC3B,SAAS,OAAO,OAAO;AAAA,IACrB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,gBAAgB;AAAA,IAChB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,aAAa;AAAA,IACb,UAAU;AAAA,IACV,OAAO;AAAA,IACP,UAAU;AAA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// src/ui/data-flow-panel.ts
17
17
  var LABELS = Object.freeze({
18
18
  "zh-CN": Object.freeze({
19
- server: "\u670D\u52A1\u7AEF\uFF08\u9759\u6001\u8BC1\u636E\uFF09",
20
- client: "\u6D4F\u89C8\u5668",
21
- bindings: "\u6570\u636E\u53BB\u5411",
22
- changes: "\u4FEE\u6539\u8BF4\u660E",
23
- componentEmpty: "\u5F53\u524D\u7EC4\u4EF6\u6CA1\u6709\u627E\u5230\u53EF\u8BC1\u660E\u7684\u63A5\u53E3\u3002\u672A\u627E\u5230\u4E0D\u7B49\u4E8E\u6CA1\u6709\u8BF7\u6C42\u3002",
24
- componentTab: "\u6570\u636E\u94FE\u8DEF",
25
- componentTitle: "\u7EC4\u4EF6\u6570\u636E\u94FE\u8DEF",
26
- consumed: "\u8BFB\u53D6\u5B57\u6BB5",
27
- declared: "\u4EE3\u7801\u58F0\u660E\uFF0C\u5C1A\u672A\u5728\u672C\u6B21\u9875\u9762\u4F1A\u8BDD\u4E2D\u89C2\u6D4B",
28
- diagnostics: "\u8BCA\u65AD",
29
- disabled: "\u6570\u636E\u94FE\u8DEF\u80FD\u529B\u672A\u542F\u7528\uFF0C\u8BF7\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u8BBE\u7F6E dataFlow: {}\u3002",
30
- error: "\u6570\u636E\u94FE\u8DEF\u62A5\u544A\u52A0\u8F7D\u5931\u8D25",
31
- evidence: "\u8BC1\u636E",
32
- loading: "\u6B63\u5728\u5206\u6790\u6E90\u7801\u5E76\u5408\u5E76\u8FD0\u884C\u65F6\u8BC1\u636E\u2026",
33
- logicalObserved: "\u672C\u6B21\u4F1A\u8BDD\u5DF2\u8FDB\u5165 tRPC \u8C03\u7528\u94FE",
34
- noParameters: "\u672A\u63D0\u53D6\u5230\u53EF\u8BC1\u660E\u7684\u53C2\u6570\u952E",
35
- observed: "\u672C\u6B21\u4F1A\u8BDD\u5DF2\u5B9E\u9645\u8BF7\u6C42",
36
- pageEmpty: "\u5F53\u524D\u5DF2\u9009\u9875\u9762\u8303\u56F4\u5185\u6CA1\u6709\u9759\u6001\u63A5\u53E3\u6216\u8FD0\u884C\u65F6\u7F51\u7EDC\u8BB0\u5F55\u3002",
37
- pageTab: "\u9875\u9762\u63A5\u53E3",
38
- pageTitle: "\u9875\u9762\u63A5\u53E3",
39
- parameters: "\u8BF7\u6C42\u53C2\u6570",
40
- refresh: "\u5237\u65B0\u8BC1\u636E",
41
- unknown: "\u672A\u77E5"
19
+ server: "服务端(静态证据)",
20
+ client: "浏览器",
21
+ bindings: "数据去向",
22
+ changes: "修改说明",
23
+ componentEmpty: "当前组件没有找到可证明的接口。未找到不等于没有请求。",
24
+ componentTab: "数据链路",
25
+ componentTitle: "组件数据链路",
26
+ consumed: "读取字段",
27
+ declared: "代码声明,尚未在本次页面会话中观测",
28
+ diagnostics: "诊断",
29
+ disabled: "数据链路能力未启用,请在插件配置中设置 dataFlow: {}。",
30
+ error: "数据链路报告加载失败",
31
+ evidence: "证据",
32
+ loading: "正在分析源码并合并运行时证据…",
33
+ logicalObserved: "本次会话已进入 tRPC 调用链",
34
+ noParameters: "未提取到可证明的参数键",
35
+ observed: "本次会话已实际请求",
36
+ pageEmpty: "当前已选页面范围内没有静态接口或运行时网络记录。",
37
+ pageTab: "页面接口",
38
+ pageTitle: "页面接口",
39
+ parameters: "请求参数",
40
+ refresh: "刷新证据",
41
+ unknown: "未知"
42
42
  }),
43
43
  "en-US": Object.freeze({
44
44
  server: "Server (static evidence)",
@@ -54,7 +54,7 @@ var LABELS = Object.freeze({
54
54
  disabled: "Data flow is disabled. Set dataFlow: {} in the plugin options.",
55
55
  error: "Failed to load the data-flow report",
56
56
  evidence: "Evidence",
57
- loading: "Analyzing source and merging runtime evidence\u2026",
57
+ loading: "Analyzing source and merging runtime evidence…",
58
58
  logicalObserved: "Dispatched through the tRPC link in this session",
59
59
  noParameters: "No proven parameter keys were extracted",
60
60
  observed: "Actually requested in this session",
@@ -131,7 +131,7 @@ function renderDependency(document, dependency, labels) {
131
131
  detailRow(
132
132
  document,
133
133
  labels.evidence,
134
- `${String(staticEvidenceCount)} static \xB7 ${String(dependency.observationIds.length)} runtime`
134
+ `${String(staticEvidenceCount)} static · ${String(dependency.observationIds.length)} runtime`
135
135
  )
136
136
  );
137
137
  card.append(header, body);
@@ -222,12 +222,12 @@ function createDataFlowPanel(document, enabled, locale, changesRoot, diagnostics
222
222
  }
223
223
  const report = snapshot.report;
224
224
  const diagnosticCodes = report === void 0 ? "" : [...new Set(report.diagnostics.map(({ code }) => code))].join(", ");
225
- const diagnosticSuffix = diagnosticCodes.length === 0 ? "" : ` \xB7 ${labels.diagnostics}: ${diagnosticCodes}`;
225
+ const diagnosticSuffix = diagnosticCodes.length === 0 ? "" : ` · ${labels.diagnostics}: ${diagnosticCodes}`;
226
226
  if (report === void 0 || report.dependencies.length === 0) {
227
227
  target.status.textContent = `${empty}${diagnosticSuffix}`;
228
228
  return;
229
229
  }
230
- target.status.textContent = `${String(report.dependencies.length)} \xB7 ${report.completeness.complete ? "complete" : "partial"}${diagnosticSuffix}`;
230
+ target.status.textContent = `${String(report.dependencies.length)} · ${report.completeness.complete ? "complete" : "partial"}${diagnosticSuffix}`;
231
231
  target.list.append(
232
232
  ...report.dependencies.map(
233
233
  (dependency) => renderDependency(document, dependency, labels)
@@ -252,7 +252,7 @@ function createDataFlowPanel(document, enabled, locale, changesRoot, diagnostics
252
252
  [...tabButtons.values()].forEach((button, index) => {
253
253
  button.textContent = tabLabels[index] ?? "";
254
254
  });
255
- refreshButton.textContent = `${labels.refresh} \xB7 ${String(state.observationCount)}`;
255
+ refreshButton.textContent = `${labels.refresh} · ${String(state.observationCount)}`;
256
256
  refreshButton.disabled = !enabled || state.component.status === "loading";
257
257
  renderSnapshot(component, state.component, labels.componentEmpty);
258
258
  renderSnapshot(page, state.page, labels.pageEmpty);