@yuhere/js-jsonrpc2 2.1.3 → 2.1.5

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.
@@ -726,4 +726,17 @@ textarea:focus {
726
726
  .split-button {
727
727
  display: inline-flex;
728
728
  }
729
+ }
730
+
731
+ /* ---- 耗时徽章(TestPanel 结果区) ---- */
732
+ .elapsed-badge {
733
+ color: var(--syn-number);
734
+ font-size: 12px;
735
+ font-weight: normal;
736
+ letter-spacing: 0;
737
+ text-transform: none;
738
+ }
739
+
740
+ .elapsed-badge .hint {
741
+ font-size: 11px;
729
742
  }
@@ -9011,11 +9011,17 @@ var COPY_OPTIONS = [{
9011
9011
  value: "fetch",
9012
9012
  label: "复制 fetch"
9013
9013
  }];
9014
+ /** 格式化耗时:<1s 用 ms,否则用 s */
9015
+ function formatElapsed(ms) {
9016
+ if (ms < 1e3) return `${ms.toFixed(0)} ms`;
9017
+ return `${(ms / 1e3).toFixed(2)} s`;
9018
+ }
9014
9019
  function TestPanel({ method, detail, rpc, transport, endpoint }) {
9015
9020
  const paramSchemas = (0, import_react.useMemo)(() => detail.signature.slice(1), [detail.signature]);
9016
9021
  const isStreamReturn = detail.signature[0]?.kind === "stream";
9017
9022
  const [values, setValues] = (0, import_react.useState)([]);
9018
9023
  const [output, setOutput] = (0, import_react.useState)("");
9024
+ const [elapsed, setElapsed] = (0, import_react.useState)(null);
9019
9025
  const [running, setRunning] = (0, import_react.useState)(false);
9020
9026
  const [copyKind, setCopyKind] = (0, import_react.useState)("curl");
9021
9027
  const [copied, setCopied] = (0, import_react.useState)(false);
@@ -9027,6 +9033,7 @@ function TestPanel({ method, detail, rpc, transport, endpoint }) {
9027
9033
  if (!method) return;
9028
9034
  setValues(paramSchemas.map(sampleFromSchema));
9029
9035
  setOutput("");
9036
+ setElapsed(null);
9030
9037
  }, [method, paramSchemas]);
9031
9038
  (0, import_react.useEffect)(() => {
9032
9039
  setCopied(false);
@@ -9052,25 +9059,37 @@ function TestPanel({ method, detail, rpc, transport, endpoint }) {
9052
9059
  if (!method) return;
9053
9060
  setRunning(true);
9054
9061
  setOutput("");
9062
+ setElapsed(null);
9063
+ const startedAt = performance.now();
9055
9064
  try {
9056
9065
  const result = await rpc.call(method, ...values);
9066
+ const firstFrameAt = performance.now() - startedAt;
9057
9067
  if (isStreamResult(result)) {
9058
9068
  let idx = 0;
9059
9069
  const lines = [];
9060
9070
  for await (const value of result) {
9061
- lines.push(`[${idx}] ${JSON.stringify(value, null, 2)}`);
9071
+ const now = performance.now() - startedAt;
9072
+ lines.push(`[${idx}] (+${formatElapsed(now)}) ${JSON.stringify(value, null, 2)}`);
9062
9073
  idx++;
9063
9074
  setOutput(lines.join("\n"));
9064
9075
  }
9065
- if (idx === 0) setOutput("(流已结束,无数据)");
9066
- else lines.push(`(流已结束,共 ${idx} 帧)`), setOutput(lines.join("\n"));
9067
- } else setOutput(JSON.stringify(result, null, 2));
9068
- if (isStreamReturn) {} else {
9069
- const result = await rpc.call(method, ...values);
9076
+ const totalAt = performance.now() - startedAt;
9077
+ if (idx === 0) lines.push(`(流已结束,无数据,总耗时 ${formatElapsed(totalAt)})`);
9078
+ else lines.push(`(流已结束,共 ${idx} 帧,总耗时 ${formatElapsed(totalAt)})`);
9079
+ setOutput(lines.join("\n"));
9080
+ setElapsed({
9081
+ total: totalAt,
9082
+ firstFrame: firstFrameAt
9083
+ });
9084
+ } else {
9085
+ const totalAt = performance.now() - startedAt;
9070
9086
  setOutput(JSON.stringify(result, null, 2));
9087
+ setElapsed({ total: totalAt });
9071
9088
  }
9072
9089
  } catch (e) {
9090
+ const totalAt = performance.now() - startedAt;
9073
9091
  setOutput(formatError(e));
9092
+ setElapsed({ total: totalAt });
9074
9093
  } finally {
9075
9094
  setRunning(false);
9076
9095
  requestAnimationFrame(() => outRef.current?.scrollIntoView({ block: "nearest" }));
@@ -9182,16 +9201,38 @@ function TestPanel({ method, detail, rpc, transport, endpoint }) {
9182
9201
  children: "重置为示例"
9183
9202
  }),
9184
9203
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
9185
- onClick: () => setOutput(""),
9186
- disabled: !output,
9204
+ onClick: () => {
9205
+ setOutput("");
9206
+ setElapsed(null);
9207
+ },
9208
+ disabled: !output && !elapsed,
9187
9209
  children: "清空输出"
9188
9210
  })
9189
9211
  ]
9190
9212
  }),
9191
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h3", { children: ["结果", isStreamReturn && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9192
- className: "hint",
9193
- children: "(流式)"
9194
- })] }),
9213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h3", { children: [
9214
+ "结果",
9215
+ isStreamReturn && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
9216
+ className: "hint",
9217
+ children: "(流式)"
9218
+ }),
9219
+ elapsed && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
9220
+ className: "elapsed-badge",
9221
+ children: [
9222
+ " ",
9223
+ "⏱ ",
9224
+ formatElapsed(elapsed.total),
9225
+ elapsed.firstFrame !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
9226
+ className: "hint",
9227
+ children: [
9228
+ " ",
9229
+ "· 首帧 ",
9230
+ formatElapsed(elapsed.firstFrame)
9231
+ ]
9232
+ })
9233
+ ]
9234
+ })
9235
+ ] }),
9195
9236
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", {
9196
9237
  className: "output",
9197
9238
  ref: outRef,
@@ -9433,4 +9474,4 @@ function App() {
9433
9474
  import_client.createRoot(document.getElementById("root")).render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {}) }) }));
9434
9475
  //#endregion
9435
9476
 
9436
- //# sourceMappingURL=index-BEVUmX2-.js.map
9477
+ //# sourceMappingURL=index-sVQlhxjI.js.map